-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnalysis.cc
More file actions
1742 lines (1535 loc) · 79.4 KB
/
Analysis.cc
File metadata and controls
1742 lines (1535 loc) · 79.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#define Analysis_cxx
#include "Analysis.h"
//C or C++ header files
#include <stdio.h>
#include <stdlib.h>
#include <cstdlib> //as stdlib.h
#include <cstdio>
#include <cmath>
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <iomanip> //for input/output manipulators
//ROOT header files
#include <TStyle.h>
#include <TPad.h>
#include <TH1.h>
#include <TH1D.h>
#include <TCanvas.h>
#include <TLegend.h>
#include <TAxis.h>
#include <TPaveText.h>
#include <TMath.h>
#include <TLorentzVector.h>
#include <TFitResult.h>
#include <TMatrixDSym.h>
#include <TF1.h>
#include <TGraphErrors.h>
#include <TPaveText.h>
#include <TPaveStats.h>
#include <TVirtualFitter.h>
//my headers
#include "functionsForAnalysis.h"
using namespace std;
//path of directory where saved canvases are stored
#define MY_PDF_PATH "./pdfsFromAnalysis/"
#define MY_TEX_DIR "texsFromAnalysis/"
#define LUMI 5. //this number refers to the integrated luminosity used in multiple of 1fb^-1
#define K_FACTOR 1.27 //the weight wgt happens to be 1.27 times smaller than what it should be, it's just a k-factor
#define NVTXS 23 // # of points for study of mumetX and mumetY vs # of reconstructed vertices nvtx
#define FIRST_NVTX 6 // starting number of vertices for met study
#define NCUTS 11 //number of cuts for the analysis (see CUTS FLOW table below)
#define ENABLE_TRIGGER_CUTS false //when "true", trigger cuts are enabled for analysis: this means that the initial number of entries is the number of entries surviving trigger cuts. These cuts are described in the CUT FLOW table below
//with the following lines, when the ENABLE_TRIGGER_CUTS directive is set to "true", trigger thresholds are defined properly (one can change them to desired values), otherwise, if it's set to "false", thresholds are set to -1, which means no thresholds at all (positive quantities by definition).
#if ENABLE_TRIGGER_CUTS
#define JET_TRIGGER 80 //trigger threshold for centraljet
#define PFMET_TRIGGER 130 //trigger threshold for particle flow met (pfmet)
#define MHT_TRIGGER 130 //trigger threshold for mht (met computed from sum of jets)
#else
#define JET_TRIGGER (-1)
#define PFMET_TRIGGER (-1)
#define MHT_TRIGGER (-1)
#endif
//thesholds for cuts
#define NJETS 2
#define J1PT 110
#define J1ETA 2.4
#define J1NHEF 0.7
#define J1CHEF 0.2
#define J1NEEF 0.7
#define J2PT 30
#define J2ETA 4.5
#define J2NHEF 0.7
#define J2NEEF 0.9
#define J1J2DPHI 2.4
#define NMUONS 0
#define NELECTRS 0
#define NTAUS 0
#define MUMET 200
//----------------------------------------------------------------------------------
//implementation of methods of class cut declared at the end of Analysis.h
//static data members
Int_t cut::nCuts_ = 0;
vector<cut*> cut::listOfCuts;
void cut::printCutFlow(ostream & myOutStream, const Int_t cutSteps, const UInt_t *singleCutMask) {
//this function prints the cut flow on the appropriate ofstream (can be a file or cout). Since it's a member function of class cut, it only needs to get the number of cut steps. For now it needs the array of masks which is not a class data member yet
myOutStream<<"**************************"<<endl;
myOutStream<<"* CUTS FLOW *"<<endl;
myOutStream<<"**************************"<<endl;
myOutStream<<"-----------------------------------------------------------------------------------"<<endl;
myOutStream<<"Printing list of cuts applied at each step"<<endl;
for (Int_t i = 0; i < cutSteps; i++) {
myOutStream<<"-----------------------------------"<<endl;
myOutStream<<setw(2)<<(i+1)<<endl;
for (Int_t j = 0; j < cut::getNCuts(); j++) {
if ((singleCutMask[i] >> j) & 1) {
myOutStream<<" ";
cut::listOfCuts[j]->print(myOutStream,1);
}
}
}
myOutStream<<"-----------------------------------"<<endl;
}
void cut::printActiveCuts(ostream & myOutStream) {
myOutStream<<"------------------------------------------------------------------------------------------"<<endl;
myOutStream<<"Printing list of activated cuts"<<endl;
myOutStream<<"------------------------------------------------------------------------------------------"<<endl;
for (Int_t i = 0; i < cut::getNCuts(); i++ ) {
if ( cut::listOfCuts[i]->isActive() ) {
cut::listOfCuts[i]->printAllInfo(myOutStream);
}
}
myOutStream<<"------------------------------------------------------------------------------------------"<<endl;
}
cut::cut(Bool_t flag, const char *cut_name, const char *var_name, const char *condition, const Double_t threshold, const string comment) {
flag_ = flag;
cut_ =cut_name;
var_ = var_name;
cond_ = condition;
thr_ = threshold;
comment_ = comment;
id_ = nCuts_;
twoToId_ = (UInt_t) TMath::Power(2.,id_);
nCuts_++;
listOfCuts.push_back(this);
}
cut::cut(Bool_t flag, const char *cut_name, const char *var_name, const char *condition, const Double_t threshold) {
flag_ = flag;
cut_ =cut_name;
var_ = var_name;
cond_ = condition;
thr_ = threshold;
comment_ = "";
id_ = nCuts_;
twoToId_ = (UInt_t) TMath::Power(2.,id_);
nCuts_++;
listOfCuts.push_back(this);
}
cut::cut(Bool_t flag, const char *cut_name, const char *var_name, const char *condition) {
flag_ =flag;
cut_ =cut_name;
var_ = var_name;
cond_ = condition;
thr_ = 0.;
comment_ = "";
id_ = nCuts_;
twoToId_ = (UInt_t) TMath::Power(2.,id_);
nCuts_++;
listOfCuts.push_back(this);
}
cut::cut(Bool_t flag, const char *cut_name, const char *var_name) {
flag_ =flag;
cut_ =cut_name;
var_ = var_name;
cond_ = " ";
thr_ = 0.;
comment_ = "";
id_ = nCuts_;
twoToId_ = (UInt_t) TMath::Power(2.,id_);
nCuts_++;
listOfCuts.push_back(this);
}
cut::~cut() {
cout<<"~cut() called for "<<cut_<<endl;
nCuts_--;
}
void cut::printAllInfo(ostream & myOutStream) const {
myOutStream<<setw(18)<<left<<cut_<<": id = "<<setw(2)<<right<<id_<<" | "<<setw(18)<<left<<var_<<" "<<setw(2)<<cond_<<" ";
myOutStream<<setw(4)<<right<<thr_<<" "<<left<<comment_<<endl;
}
void cut::print(ostream & myOutStream = cout, Bool_t addComment = 0) const {
//print cut definition on the right ofstream (cout is default), if addComment = 1, cut comment is printed if any
if (addComment) {
myOutStream<<setw(18)<<left<<var_<<" "<<setw(2)<<cond_<<" "<<setw(4)<<right<<thr_<<" "<<left<<comment_<<endl;
} else {
myOutStream<<setw(18)<<left<<var_<<" "<<setw(2)<<cond_<<" "<<setw(4)<<right<<thr_<<endl;
}
}
Bool_t cut::isPassed(Double_t input) {
if (cond_ == "<") return (input < thr_) ? true : false;
else if (cond_== ">") return (input > thr_) ? true : false;
else if (cond_== "=") return (input == thr_) ? true : false;
else if (cond_ == "<=") return (input <= thr_) ? true : false;
else if (cond_ == ">=") return (input >= thr_) ? true : false;
else {
cout<<"Error in cut::isPassed()! No condition fulfilled."<<endl;
cout<<"End of programme"<<endl;
exit(EXIT_FAILURE);
}
}
//----------------------------------------------------------------------------------
void Analysis::Loop()
{
// In a ROOT session, you can do:
// Root > .L Analysis.C
// Root > Analysis t
// Root > t.GetEntry(12); // Fill t data members with entry number 12
// Root > t.Show(); // Show values of entry 12
// Root > t.Show(16); // Read and show values of entry 16
// Root > t.Loop(); // Loop on all entries
//
// This is the loop skeleton where:
// jentry is the global entry number in the chain
// ientry is the entry number in the current Tree
// Note that the argument to GetEntry must be:
// jentry for TChain::GetEntry
// ientry for TTree::GetEntry and TBranch::GetEntry
//
// To read only selected branches, Insert statements like:
// METHOD1:
// fChain->SetBranchStatus("*",0); // disable all branches
// fChain->SetBranchStatus("branchname",1); // activate branchname
// METHOD2: replace line
// fChain->GetEntry(jentry); //read all branches
//by b_branchname->GetEntry(ientry); //read only this branch
if (fChain == 0) return;
fChain->SetBranchStatus("*",0);
fChain->SetBranchStatus("nvtx",1);
fChain->SetBranchStatus("njets",1); // # of jets with pt>30GeV
fChain->SetBranchStatus("nmuons",1); //for muon veto, # of muons passing loose cuts
fChain->SetBranchStatus("nelectronsnew",1); //for electron veto, # of electrons passing loose cuts
fChain->SetBranchStatus("ntaus",1); //for tau veto, # of taus (I guess they are taus passing veto but Adish didn't specify
fChain->SetBranchStatus("wgt",1); //weight for the event: it has to be multiplied by a k-factor which is equal to 1.27 (look at the "define" above)
fChain->SetBranchStatus("signaljetCHfrac",1); //charged H fraction
fChain->SetBranchStatus("signaljetNHfrac",1); //neutral H fraction
fChain->SetBranchStatus("signaljetEMfrac",1); //neutral EM fraction
fChain->SetBranchStatus("secondjetNHfrac",1); //neutral H fraction
fChain->SetBranchStatus("secondjetEMfrac",1); //neutral EM fraction
fChain->SetBranchStatus("signaljetpt",1);
fChain->SetBranchStatus("signaljetphi",1);
fChain->SetBranchStatus("signaljeteta",1);
fChain->SetBranchStatus("secondjetpt",1);
fChain->SetBranchStatus("secondjetphi",1);
fChain->SetBranchStatus("secondjeteta",1);
fChain->SetBranchStatus("thirdjetpt",1);
fChain->SetBranchStatus("thirdjetphi",1);
fChain->SetBranchStatus("thirdjeteta",1);
fChain->SetBranchStatus("jetjetdphi",1); //delta phi in [-PI,PI] between first and second leading jet
fChain->SetBranchStatus("l1pt",1);
fChain->SetBranchStatus("l1phi",1);
fChain->SetBranchStatus("l1eta",1);
fChain->SetBranchStatus("l2pt",1);
fChain->SetBranchStatus("l2phi",1);
fChain->SetBranchStatus("l2eta",1);
fChain->SetBranchStatus("mht",1); // necessary for trigger cuts
fChain->SetBranchStatus("pfmet",1); // necessary for trigger cuts
fChain->SetBranchStatus("mumet",1);
fChain->SetBranchStatus("mumetphi",1);
fChain->SetBranchStatus("t1pfmet",1);
fChain->SetBranchStatus("t1pfmetphi",1);
fChain->SetBranchStatus("wzmass",1);
fChain->SetBranchStatus("wzpt",1);
fChain->SetBranchStatus("wzeta",1);
fChain->SetBranchStatus("wzphi",1);
/*
*******************************
* GENERAL COMMENTS *
*******************************
In the following, cuts due to trigger are not considered, that is, I assumed that the ntuple was made out of data passing the trigger selection: this assumption is corroborated by the evidence of a sharp cut at 200 GeV in the mumet variable stored in the tree. However their contribution can reduce the initial number of entries and it would be useful to have the possibility to take them into account.
---------------- TRIGGER CUTS ------------------- taken from Nadir's slides-> https://indico.cern.ch/event/368971/contribution/6/material/slides/0.pdf
1)signaljetpt>140 GeV & pfmet>100 GeV & mht>140 GeV (variables are stored in tree.root)
2)signaljetpt>80 GeV & pfmet>130 GeV & mht>130 GeV
Use one or the other trigger, the second should provide bigger acceptance (mainly more events)
-------------- CUTS FLOW ----------------------- the number of cuts is equal to NCUTS defined above.
cuts are cumulative ( e.g.: 3) also includes 1) and 2) ).
Note that the cut flow can change depending on the analysis, the following is just a guideline: refer to globalCutMask[]
1) MET > 250 GeV (I use mumet)
2) signaljetpt>110 GeV; |signaljeteta|<2.5; Noise cleaning on first jet ( NHEF<0.7; CHEF>0.2; NEEF<0.7 )
3) secondjetpt>30 GeV; |secondjeteta|<4.5, NHEF<0.7; NEEF<0.9 (only for events with 2 jets)
4) dphi(jet1,jet2)<2.5;
5) njets<= 2 (njets is the # of jets with pt>30)
6) muon veto: reject if pt>10GeV and |eta|<2.4
7) electron veto: reject if pt>10GeV and |eta|<2.5
8) tau veto: reject if pt>20GeV and |eta|<2.3 (in this analysis I reject events with taus because i don't have any variable for taus but their number)
9) MET > 300
10) MET > 400
11) MET > 500
--------------------------------------------------------------
Cuts are applied using a mask. I built a class cut (see bottom of Analysis.h) which will be represented by a specific bit in a mask. Each bit says if the selection based on its related variable was passed or not.
In these way, there will be a mask for each event recording which selections will be passed in that event. Then, I will be free to fill histograms with the desired variable according to a specific step of the cut flow. As an example, if my mask for variables A, B, C, D is M=1011 (in binary representation) for a given event, than all selections except for C (starts from the rightest bit) were passed. If I'm interested in the histogram of variable x after cuts A and D, the corresponding mask is m=1001.
I will fill the histogram if ((M & m) == m). that is to say, only if bit equal to 1 in m are also 1 in M (independently of the fact that M as other bits equal to 1).
The biggest advantage is that I don't need nested "if" to implement the selection: I' m just labeling the event, and the labels merely categorize events depending on the selections that would be passed by those events.
The following is the list of variables, reflecting in the bits numbering (if Mask is UInt_t, I can have only 32 variables). I added variables that seemed reasonable to be used in the future (names taken from Adish's file). Actually the masks will be updated each time the programme run, so the numbering is more a guideline than an actual rule (it will depend on the order that cuts are declared, which is absolutely arbitrary).
1) njets
2) signaljetpt
3) signaljeteta
4) signaljetphi
5) signaljetCHfrac
6) signaljetNHfrac
7) signaljetEMfrac
8) signaljetCEMfrac
9) secondjetpt
10) secondjeteta
11) secondjetphi
12) secondjetCHfrac
13) secondjetNHfrac
14) secondjetEMfrac
15) secondjetCEMfrac
16) jetjetdphi
17) mumet
18) nmuons
19) nelectronsnew
20) ntaus
21) thirdjetpt
22) thirdjeteta
23) thirdjetphi
24) mumet300
25) mumet400
26) mumet500
*/
//I use the following convention: all classes of type cut are named with a final C (C stands for "Cut")
cut njetsC(true,"njetsC","njets","<=",NJETS);
cut jet1ptC(true,"jet1ptC","signaljetpt",">",J1PT);
cut jet1etaC(true,"jet1etaC","|signaljeteta|","<",J1ETA);
//cut jet1phiC(false,"jet1phiC","signaljetphi");
cut jet1CHfracC(true,"jet1CHfracC","signaljetCHfrac",">",J1CHEF);
cut jet1NHfracC(true,"jet1NHfracC","signaljetNHfrac","<",J1NHEF);
cut jet1EMfracC(true,"jet1EMfracC","signaljetEMfrac","<",J1NEEF);
//cut jet1CEMfracC(false,"jet1CEMfracC","signaljetCEMfrac");
//cut jet2ptC(true,"jet2ptC","secondjetpt",">",J2PT,"only if njets = 2");
cut jet2etaC(true,"jet2etaC","|secondjeteta|","<",J2ETA,"only if njets = 2");
//cut jet2phiC(false,"jet2phiC","secondjetphi");
//cut jet2CHfracC(false,"jet2CHfracC","secondjetCHfrac");
cut jet2NHfracC(true,"jet2NHfracC","secondjetNHfrac","<",J2NHEF,"only if njets = 2");
cut jet2EMfracC(true,"jet2EMfracC","secondjetEMfrac","<",J2NEEF,"only if njets = 2");
//cut jet2CEMfracC(false,"jet2CEMfracC","secondjetCEMfrac");
cut jet1jet2dphiC(true,"jet1jet2dphiC","|jetjetdphi|","<",J1J2DPHI,"only if njets = 2");
//cut mumetC(true,"mumetC","mumet",">",MUMET);
cut nmuonsC(true,"nmuonsC","nmuons","=",NMUONS);
cut nelectronsnewC(true,"nelectronsnewC","nelectronsnew","=",NELECTRS);
cut ntausC(true,"ntausC","ntaus","=",NTAUS);
cut mumet250C(true,"mumet250C","mumet",">",250);
cut mumet300C(true,"mumet300C","mumet",">",300);
//cut mumet350C(true,"mumet350C","mumet",">",350);
cut mumet400C(true,"mumet400C","mumet",">",400);
//cut mumet450C(true,"mumet450C","mumet",">",450);
cut mumet500C(true,"mumet500C","mumet",">",500);
//cut mumet550C(true,"mumet550C","mumet",">",550);
if (cut::getNCuts() > 8*sizeof(UInt_t)) {
cout<<"Warning: not enough bits in the mask to accomodate all "<<cut::getNCuts()<<" cuts (max is "<<8*sizeof(UInt_t)<<").\n End of programme."<<endl;
exit(EXIT_FAILURE);
}
cut::printActiveCuts(cout);
//building masks for our analysis. If a different cut flow is needed, changes must be done here
UInt_t singleCutMask[NCUTS] = {}; //mask with cuts in a specific step
singleCutMask[0] = mumet250C.get2ToId();
singleCutMask[1] = njetsC.get2ToId();
singleCutMask[2] = jet1CHfracC.get2ToId() + jet1NHfracC.get2ToId() + jet1EMfracC.get2ToId();
singleCutMask[3] = jet1ptC.get2ToId() + jet1etaC.get2ToId();
singleCutMask[4] = jet1jet2dphiC.get2ToId() + /*jet2ptC.get2ToId() +*/ jet2etaC.get2ToId() + jet2NHfracC.get2ToId() + jet2EMfracC.get2ToId();
singleCutMask[5] = nmuonsC.get2ToId();
singleCutMask[6] = nelectronsnewC.get2ToId();
singleCutMask[7] = ntausC.get2ToId();
singleCutMask[8] = mumet300C.get2ToId();
singleCutMask[9] = mumet400C.get2ToId();
singleCutMask[10] = mumet500C.get2ToId();
// singleCutMask[0] = mumetC.get2ToId();
// singleCutMask[1] = njetsC.get2ToId();
// singleCutMask[2] = jet1ptC.get2ToId() + jet1etaC.get2ToId() + jet1CHfracC.get2ToId() + jet1NHfracC.get2ToId() + jet1EMfracC.get2ToId();
// singleCutMask[3] = jet2ptC.get2ToId() + jet2etaC.get2ToId() + jet2NHfracC.get2ToId() + jet2EMfracC.get2ToId();
// singleCutMask[4] = jet1jet2dphiC.get2ToId();
// singleCutMask[5] = nmuonsC.get2ToId();
// singleCutMask[6] = nelectronsnewC.get2ToId();
// singleCutMask[7] = ntausC.get2ToId();
// singleCutMask[8] = mumet300C.get2ToId();
// singleCutMask[9] = mumet400C.get2ToId();
// singleCutMask[10] = mumet500C.get2ToId();
cut::printCutFlow(cout,NCUTS,singleCutMask);
UInt_t globalCutMask[NCUTS] ; //mask adding to a specific step all previous cuts
for (Int_t i = 0; i < NCUTS; i++ ) {
globalCutMask[i] = 0.0;
}
//the following loop' s aim is to have incapsulated conditions (globalMask of step i-th must include all previous steps)
for (Int_t i = 1; i < NCUTS; i++) {
if (i == 0) globalCutMask[0] = singleCutMask[0];
else globalCutMask[i] = singleCutMask[i] + globalCutMask[i-1];
}
cout<<endl;
Double_t nWeightedEvents[NCUTS+1]; // number of weighted events (it's a Double_t because weights are non-integer numbers)
for (Int_t i = 0; i <= NCUTS; i++ ) {
nWeightedEvents[i] = 0.0;
}
TH1::SetDefaultSumw2(); //all the following histograms will automatically call TH1::Sumw2()
TH1::StatOverflows(); //enable use of underflows and overflows for statistics computation
TVirtualFitter::SetDefaultFitter("Minuit");
TH1D *Hjet1ptTriggerC = new TH1D("Hjet1ptTriggerC","",30,0,1500); //this is jet1 pt after trigger cuts (alternative to Hjet1pt[0] defined just after it)
TH1D *Hjet1pt[NCUTS+1];
Int_t Hcolor[] = {1,2,3,4,5,6,7,8,9,12,18,30,38,41,42,46,47,49}; //Hjet1pt[0] is the histogram without any cut
for (Int_t i=0; i<=NCUTS; i++) {
Hjet1pt[i] = new TH1D(Form("Hjet1pt[%i]",i),"",30,0,1500);
Hjet1pt[i]->SetLineColor(Hcolor[i]);
Hjet1pt[i]->SetFillColor(Hcolor[i]);
}
//Int_t ncut; //index for the cut considered: it goes from 0 (no cuts) to NCUTS (see the CUTS FLOW table above) and changes in the loop
TH1D *Hjet1etanoC = new TH1D("Hjet1etanoC","",100,-5.,5.);
TH1D *Hjet1etaallCMet250 = new TH1D("Hjet1etaallCMet250","",50,-2.5,2.5);
TH1D *Hjet1etaallCMet500 = new TH1D("Hjet1etaallCMet500","",50,-2.5,2.5); //events in this histogram must have passed the cut |eta|<J1ETA
TH1D *Hjet2ptnoC = new TH1D("Hjet2ptnoC","",30,0,1500);
TH1D *Hjet2ptallCMet250 = new TH1D("Hjet2ptallCMet250","",30,0,1500);
TH1D *Hjet2ptallCMet300 = new TH1D("Hjet2ptallCMet300","",30,0,1500);
TH1D *Hjet2ptallCMet400 = new TH1D("Hjet2ptallCMet400","",30,0,1500);
TH1D *Hjet2ptallCMet500 = new TH1D("Hjet2ptallCMet500","",30,0,1500);
TH1D *Hjet2etanoC = new TH1D("Hjet2etanoC","",100,-5.,5.);
TH1D *Hjet2etaallCMet250 = new TH1D("Hjet2etaallCMet250","",100,-5.,5.);
TH1D *Hjet2etaallCMet500 = new TH1D("Hjet2etaallCMet500","",100,-5.,5.); //events in this histogram must have passed the cut |eta|<J2ETA
TH1D *Hjet1jet2dphinoC = new TH1D("Hjet1jet2dphinoC","",80,-4.,4.);
TH1D *Hjet1jet2dphiallCMet250 = new TH1D("Hjet1jet2dphiallCMet250","",80,-4.,4.);
TH1D *Hjet1jet2dphiallCMet500 = new TH1D("Hjet1jet2dphiallCMet500","",80,-4.,4.);
TH1D *HnjetsnoC = new TH1D("HnjetsnoC","",11,-0.5,10.5);
TH1D *HnjetsallCMet250 = new TH1D("HnjetsallCMet250","",11,-0.5,10.5);
TH1D *HnjetsallCMet500 = new TH1D("HnjetsallCMet500","",11,-0.5,10.5);
TH1D *HmumetnoC = new TH1D("HmumetnoC","",30,0,1500);
TH1D *HmumetallCMet250 = new TH1D("HmumetallCMet250","",30,0,1500);
//when dealing with leptons, allC refers to all cuts including those on leptons for background estimation
TH1D *HlepptnoC = new TH1D("HlepptnoC","",150,0,1500);
TH1D *HlepptallCnoIso = new TH1D("HlepptallCnoIso","",150,0,1500);
TH1D *HlepptallC = new TH1D("HlepptallC","",150,0,1500);
TH1D *HlepmassnoC = new TH1D("HlepmassnoC","",350,0.,700);
TH1D *HlepmassallC = new TH1D("HlepmassallC","",30,60,120);
TH1D *HZptnoC = new TH1D("HZptnoC","",150,0,1500);
TH1D *HZptallC = new TH1D("HZptallC","",150,0,1500);
TH1D *HZmassnoC = new TH1D("HZmassnoC","",350,0.,700);
TH1D *HZmassallC = new TH1D("HZmassallC","",30,60,120);
// TH1D *HtestNevents = new TH1D("HtestNevents","",1,0,1);
// TH1D *HtestNeventsBis = new TH1D("HtestNeventsBis","",1,0,6000);
TH1D *HmumetOrtZvsNvtx[NVTXS];
TH1D *HmumetParZvsNvtx[NVTXS];
TH1D *HmumetX[NVTXS];
TH1D *HmumetY[NVTXS];
for (Int_t i = 0; i < NVTXS; i++) {
Int_t color = i+1;
HmumetOrtZvsNvtx[i] = new TH1D(Form("HmumetOrtZvsNvtx[%i]",i),"",80,-200,200); // 5 GeV bins (was 10 before)
//HmumetOrtZvsNvtx[i]->SetLineColor(i);
HmumetParZvsNvtx[i] = new TH1D(Form("HmumetParZvsNvtx[%i]",i),"",80,-200,200); // 5 GeV bins (was 10 before)
//HmumetParZvsNvtx[i]->SetLineColor(i);
HmumetX[i] = new TH1D(Form("HmumetX[%i]",i),"",500,-1250,1250);
HmumetY[i] = new TH1D(Form("HmumetY[%i]",i),"",500,-1250,1250);
}
//in a older version I used t1pfmet as well to compare with mumet and (as expected) there was no difference except at first and last bin
// TH1D *Ht1pfmetOrtZvsNvtx[NVTXS];
// TH1D *Ht1pfmetParZvsNvtx[NVTXS];
// for (Int_t i = 0; i < NVTXS; i++) {
// Ht1pfmetOrtZvsNvtx[i] = new TH1D(Form("Ht1pfmetOrtZvsNvtx[%i]",i),"",40,-200,200); // 10 GeV bins
// Ht1pfmetOrtZvsNvtx[i]->SetLineColor(i);
// Ht1pfmetParZvsNvtx[i] = new TH1D(Form("Ht1pfmetParZvsNvtx[%i]",i),"",40,-200,200); // 10 GeV bins
// Ht1pfmetParZvsNvtx[i]->SetLineColor(i);
// }
Double_t ZptBinEdges[] = {250., 260., 270., 280., 290., 310., 330., 350., 370., 390., 410., 430., 450., 470., 500., 530., 560, 600., 640., 700., 800.};
Int_t nBinsForResponse = sizeof(ZptBinEdges)/sizeof(Double_t) - 1; //number of bins is n-1 where n is the number of ZptBinEdges's elements
TH1D *HZptBinned[nBinsForResponse];
//the following histograms will give the distribution of met|| / wzpt. The mean value will be used to create the response curve, that is (<met|| / wzpt>) vs wzpt
// for each point, wzpt will be taken as the average wzpt in the range considered
TH1D *HmumetParZratio[nBinsForResponse];
TH1D *HmumetOrtZvsZpt[nBinsForResponse];
TH1D *HmumetParZvsZpt[nBinsForResponse];
//cout<<"nbins = "<<nBinsForResponse<<endl;
for (Int_t i = 0; i < nBinsForResponse; i++) {
//HZptBinned[i] are histograms with 5 bins in the range given by ZptBinEdges[i] and ZptBinEdges[i+1]
// the mean wzpt in each bin will be computed as the histogram's mean
HZptBinned[i] = new TH1D(Form("HZptBinned[%i]",i),"",5,ZptBinEdges[i],ZptBinEdges[i+1]);
HmumetParZratio[i] = new TH1D(Form("HmumetParZratio[%i]",i),"",100,0.0,2.0);
HmumetOrtZvsZpt[i] = new TH1D(Form("HmumetOrtZvsZpt[%i]",i),"",80,-200,200);
HmumetParZvsZpt[i] = new TH1D(Form("HmumetParZvsZpt[%i]",i),"",80,-200,200);
}
Double_t nev1j=0, nev2j=0, nev3j=0; //# of events with 1,2,3 jets
Double_t nev1jmore30=0, nev2jmore30=0, nev3jmore30=0; //# of events with jet 1,2,3 with pt >30 GeV
Double_t nevj1pteq0=0, nevj2pteq0=0, nevj3pteq0=0; //# of events with jet 1,2,3 with pt = 30 GeV
Long64_t nentries = fChain->GetEntriesFast();
cout<<"nentries = "<<nentries<<endl;
Long64_t nbytes = 0, nb = 0;
for (Int_t jentry=0; jentry<nentries; jentry++) {
Long64_t ientry = LoadTree(jentry);
if (ientry < 0) break;
nb = fChain->GetEntry(jentry); nbytes += nb;
// if (Cut(ientry) < 0) continue;
/**************************************************/
// variables used in the loop or in the following
/**************************************************/
// Double_t wgtTest = wgt*K_FACTOR;
// HtestNevents->Fill(wgtTest);
// HtestNeventsBis->Fill(signaljetpt,wgtTest);
UInt_t eventMask = 0; //mask that characterize the event. It's initialized to 0 for each event and is built inside the cut loop
Double_t newwgt = wgt*K_FACTOR*LUMI; //the correct weight to use is newwgt, LUMI is useful to compare to Adish's data
//Double_t newwgt = 1.;
nWeightedEvents[0] += newwgt; // this element will represent the total number of weighted events (no selection applied so far)
TLorentzVector jet1, jet2, jet3;
TLorentzVector nu1, nu2, nu1plusnu2, Z;
TLorentzVector LVt1pfmet, LVmumet;
Double_t lepInvariantMass=0, leppt=0;
jet1.SetPtEtaPhiM(signaljetpt,signaljeteta,signaljetphi,0);
jet2.SetPtEtaPhiM(secondjetpt,secondjeteta,secondjetphi,0);
jet3.SetPtEtaPhiM(thirdjetpt,thirdjeteta,thirdjetphi,0);
LVt1pfmet.SetPtEtaPhiM(t1pfmet,0,t1pfmetphi,0);
LVmumet.SetPtEtaPhiM(mumet,0,mumetphi,0);
Z.SetPtEtaPhiM(wzpt,wzeta,wzphi,wzmass);
nu1.SetPtEtaPhiM(l1pt,l1eta,l1phi,0);
nu2.SetPtEtaPhiM(l2pt,l2eta,l2phi,0);
nu1plusnu2 = nu1+nu2;
// it's useful to store the following quantities so that there's no need to recompute them every time I need them
lepInvariantMass = nu1plusnu2.Mag();
leppt = nu1plusnu2.Pt();
/**************************************************/
// computing met resolutions
/**************************************************/
Double_t dphiZmumet_pi_pi = LVmumet.DeltaPhi(Z);
Double_t mumetPar = mumet*TMath::Cos(dphiZmumet_pi_pi);
//cout<<"mumetPar = "<<mumetPar<<endl;
Double_t mumetOrt = mumet*TMath::Sin(dphiZmumet_pi_pi);
// Double_t dphiZt1pfmet_pi_pi = LVt1pfmet.DeltaPhi(Z);
// Double_t t1pfmetPar = t1pfmet*TMath::Cos(dphiZt1pfmet_pi_pi);
// Double_t t1pfmetOrt = t1pfmet*TMath::Sin(dphiZt1pfmet_pi_pi);
if (wzpt > 250) { //this corresponds to trigger efficiency plateaux (actually it would be mumet, but mumet recoils against wzpt so their pt should be of the same order of magnitude). In any case, note that in our tree is always mumet > 200
Int_t nvtxBin = nvtx-FIRST_NVTX;
if ((nvtxBin >= 0) && (nvtx < (NVTXS + FIRST_NVTX))) {
if (wzpt < 500) { // (met||-wzpt) distribution's width depends on pt, thus I use this range
HmumetParZvsNvtx[nvtxBin]->Fill(mumetPar-wzpt,newwgt);
//Ht1pfmetParZvsNvtx[nvtxBin]->Fill(t1pfmetPar-wzpt,newwgt);
}
HmumetOrtZvsNvtx[nvtxBin]->Fill(mumetOrt,newwgt);
//Ht1pfmetOrtZvsNvtx[nvtxBin]->Fill(t1pfmetOrt,newwgt);
HmumetX[nvtxBin]->Fill(mumet*TMath::Cos(mumetphi),newwgt);
HmumetY[nvtxBin]->Fill(mumet*TMath::Sin(mumetphi),newwgt);
}
}
/**************************************************/
// computing met responses
/**************************************************/
// first of all I make sure that wzpt is in the appropriate range
if ((wzpt > ZptBinEdges[0]) && (wzpt < ZptBinEdges[nBinsForResponse])) {
Int_t bin = myGetBin(wzpt,ZptBinEdges,nBinsForResponse);
//cout<<"bin = "<<bin<<endl;
HZptBinned[bin]->Fill(wzpt,newwgt);
HmumetParZratio[bin]->Fill(mumetPar/wzpt,newwgt); //the mean value of this histogram is the response
HmumetOrtZvsZpt[bin]->Fill(mumetOrt,newwgt);
HmumetParZvsZpt[bin]->Fill(mumetPar-wzpt,newwgt);
}
/**************************************************/
// counting number of events with exactly 1, 2 ,3
/**************************************************/
if (njets == 1) nev1j += newwgt;
if (njets == 2) nev2j += newwgt;
if (njets == 3) nev3j += newwgt;
if (signaljetpt >30) nev1jmore30 += newwgt;
if (signaljetpt == 0) nevj1pteq0 += newwgt;
if (secondjetpt >30) nev2jmore30 += newwgt;
if (secondjetpt == 0) nevj2pteq0 += newwgt;
if (thirdjetpt >30) nev3jmore30 += newwgt;
if (thirdjetpt == 0) nevj3pteq0 += newwgt;
/**************************************************/
// filling histograms without any cut applied
/**************************************************/
/*---------------------------------- jets ---------------------------------------*/
//ncut = 0 means no cuts for filling the histogram
HnjetsnoC->Fill(njets,newwgt);
Hjet1pt[0]->Fill(signaljetpt,newwgt);
Hjet1etanoC->Fill(signaljeteta,newwgt);
Hjet2ptnoC->Fill(secondjetpt,newwgt);
if (secondjetpt != 0) {
Hjet2etanoC->Fill(secondjeteta,newwgt);
Hjet1jet2dphinoC->Fill(jetjetdphi,newwgt);
}
/*---------------------------------- Z boson ---------------------------------------*/
HZptnoC->Fill(wzpt,newwgt);
HZmassnoC->Fill(wzmass,newwgt);
/*---------------------------------- leptons ---------------------------------------*/
HlepptnoC->Fill(leppt,newwgt);
HlepmassnoC->Fill(lepInvariantMass,newwgt);
/*---------------------------------- mumet ---------------------------------------*/
HmumetnoC->Fill(mumet,newwgt);
//***********************************
// STARTING WITH CUTS
//***********************************
//cuts on 2nd jet must be applied only for 2 jet events (I could have 1 jet but the current implementation would apply a cut on the 2nd jet nonetheless): thus, if njets == 2 cuts are actually applied and the corresponding bits of eventMask are set to 1 or 0 depending on the selection being passed or not respectively, otherwise those bits are automatically set to 1 (which is like saying that that selection is irrelevant). The problem and the reason for doing so is that the globalCutMask is defined before the cut loop and I cannot choose whether to set its 2nd jet bits to 0 or 1 according to the effective number of jets before looping on events: I must set them to 1 in advance, thus declaring that those cuts will be applied when I have to
eventMask += njetsC.addToMask(njets);
eventMask += jet1ptC.addToMask(signaljetpt);
eventMask += jet1etaC.addToMask(fabs(signaljeteta));
eventMask += jet1CHfracC.addToMask(signaljetCHfrac);
eventMask += jet1NHfracC.addToMask(signaljetNHfrac);
eventMask += jet1EMfracC.addToMask(signaljetEMfrac);
if (njets == 2) {
//eventMask += jet2ptC.addToMask(secondjetpt);
eventMask += jet2etaC.addToMask(fabs(secondjeteta));
eventMask += jet2NHfracC.addToMask(secondjetNHfrac);
eventMask += jet2EMfracC.addToMask(secondjetEMfrac);
eventMask += jet1jet2dphiC.addToMask(fabs(jetjetdphi));
} else if (njets == 1) {
//eventMask += jet2ptC.get2ToId();
eventMask += jet2etaC.get2ToId();
eventMask += jet2NHfracC.get2ToId();
eventMask += jet2EMfracC.get2ToId();
eventMask += jet1jet2dphiC.get2ToId();
}
eventMask += nmuonsC.addToMask(nmuons);
eventMask += nelectronsnewC.addToMask(nelectronsnew);
eventMask += ntausC.addToMask(ntaus);
eventMask += mumet250C.addToMask(mumet);
eventMask += mumet300C.addToMask(mumet);
eventMask += mumet400C.addToMask(mumet);
eventMask += mumet500C.addToMask(mumet);
//cout<<"event = "<<jentry<<" eventMask = "<<eventMask<<endl;
//warning: mask's index starts from 0 (first cut) while Hjet1pt[] starts with index 1 because 0 stands for no cuts. Maybe I should change definition of histogram...
if ( (eventMask & globalCutMask[0]) == globalCutMask[0]) {
nWeightedEvents[1] += newwgt;
Hjet1pt[1]->Fill(signaljetpt, newwgt);
}
if ( (eventMask & globalCutMask[1]) == globalCutMask[1]) {
nWeightedEvents[2] += newwgt;
Hjet1pt[2]->Fill(signaljetpt, newwgt);
}
if ( (eventMask & globalCutMask[2]) == globalCutMask[2]) {
nWeightedEvents[3] += newwgt;
Hjet1pt[3]->Fill(signaljetpt, newwgt);
}
if ( (eventMask & globalCutMask[3]) == globalCutMask[3]) {
nWeightedEvents[4] += newwgt;
Hjet1pt[4]->Fill(signaljetpt, newwgt);
}
if ( (eventMask & globalCutMask[4]) == globalCutMask[4]) {
nWeightedEvents[5] += newwgt;
Hjet1pt[5]->Fill(signaljetpt, newwgt);
}
if ( (eventMask & globalCutMask[5]) == globalCutMask[5]) {
nWeightedEvents[6] += newwgt;
Hjet1pt[6]->Fill(signaljetpt, newwgt);
}
if ( (eventMask & globalCutMask[6]) == globalCutMask[6]) {
nWeightedEvents[7] += newwgt;
Hjet1pt[7]->Fill(signaljetpt, newwgt);
}
if ( (eventMask & globalCutMask[7]) == globalCutMask[7]) {
//here tau veto is fulfilled
nWeightedEvents[8] += newwgt;
Hjet1pt[8]->Fill(signaljetpt, newwgt);
//cut on mumet > 250 is the first cut: "allCMet250" means all cut flow with cut on met >250 (the following cuts are met> 300 and so on)
HnjetsallCMet250->Fill(njets,newwgt);
Hjet1etaallCMet250->Fill(signaljeteta,newwgt);
Hjet2ptallCMet250->Fill(secondjetpt,newwgt);
if (secondjetpt != 0) {
Hjet2etaallCMet250->Fill(secondjeteta,newwgt);
Hjet1jet2dphiallCMet250->Fill(jetjetdphi,newwgt);
}
HmumetallCMet250->Fill(mumet,newwgt);
}
if ( (eventMask & globalCutMask[8]) == globalCutMask[8]) {
nWeightedEvents[9] += newwgt;
Hjet1pt[9]->Fill(signaljetpt, newwgt);
Hjet2ptallCMet300->Fill(secondjetpt,newwgt);
}
if ( (eventMask & globalCutMask[9]) == globalCutMask[9]) {
nWeightedEvents[10] += newwgt;
Hjet1pt[10]->Fill(signaljetpt, newwgt);
Hjet2ptallCMet400->Fill(secondjetpt,newwgt);
}
if ( (eventMask & globalCutMask[10]) == globalCutMask[10]) {
nWeightedEvents[11] += newwgt;
Hjet1pt[11]->Fill(signaljetpt, newwgt);
HnjetsallCMet500->Fill(njets,newwgt);
Hjet1etaallCMet500->Fill(signaljeteta,newwgt);
Hjet2ptallCMet500->Fill(secondjetpt,newwgt);
if (secondjetpt != 0) {
Hjet2etaallCMet500->Fill(secondjeteta,newwgt);
Hjet1jet2dphiallCMet500->Fill(jetjetdphi,newwgt);
}
}
///***********************************
// END OF CUTS
//***********************************
//--------------------------------------------------------------------------------//
// END OF LOOP
//--------------------------------------------------------------------------------//
}
Double_t nwentries = nWeightedEvents[0]; //storage for clearer code in the following
Double_t nwentriesCut1 = nWeightedEvents[1];
Double_t nevmore1j = nwentries-nev1j;
Double_t nevmore2j = nevmore1j-nev2j;
Double_t nevmore3j = nevmore2j-nev3j;
Double_t nevj1ptneq0 = nwentries-nevj1pteq0;
Double_t nevj2ptneq0 = nwentries-nevj2pteq0;
Double_t nevj3ptneq0 = nwentries-nevj3pteq0;
cout<<endl;
cout<<"-----------------------------------------------------------------------------------------------"<<endl;
cout<<"total # of weighted events: "<<nwentries<<" Hjet1pt[0]->GetSumOfWeights = "<<Hjet1pt[0]->GetSumOfWeights()<<endl;
cout<<"-----------------------------------------------------------------------------------------------"<<endl;
for (Int_t i = 1; i <= NCUTS; i++) {
cout<<"cut "<<setw(2)<<i<<" : nWeightedEvents = "<<nWeightedEvents[i]<<" Hjet1pt->GetSumOfWeights = "<<Hjet1pt[i]->GetSumOfWeights()<<endl;
}
cout<<endl;
myPrintEventYields(cout,LUMI,NCUTS,nWeightedEvents);
cout<<"Following numbers concerning jets refers to jets with pt>30 GeV"<<endl;
cout<<setw(25)<<left<<"event type"<<"fraction"<<endl;
cout<<setprecision(4)<<setw(25)<<left<<"exactly 1 jet "<<nev1j/nwentries<<endl;
cout<<setprecision(4)<<setw(25)<<left<<"exactly 2 jets "<<nev2j/nwentries<<endl;
cout<<setprecision(4)<<setw(25)<<left<<"exactly 3 jets "<<nev3j/nwentries<<endl;
cout<<setprecision(4)<<setw(25)<<left<<"more than 1 jet "<<nevmore1j/nwentries<<endl;
cout<<setprecision(4)<<setw(25)<<left<<"more than 2 jet "<<nevmore2j/nwentries<<endl;
cout<<setprecision(4)<<setw(25)<<left<<"more than 3 jet "<<nevmore3j/nwentries<<endl;
cout<<"--------------------------------------------------------"<<endl;
cout<<setprecision(4)<<setw(25)<<left<<"signaljetpt>30GeV "<<nev1jmore30/nwentries<<endl;
cout<<setprecision(4)<<setw(25)<<left<<"secondjetpt>30GeV "<<nev2jmore30/nwentries<<endl;
cout<<setprecision(4)<<setw(25)<<left<<"thirdjetpt>30GeV "<<nev3jmore30/nwentries<<endl;
cout<<setprecision(4)<<setw(25)<<left<<"signaljetpt = 0 "<<nevj1pteq0/nwentries<<endl;
cout<<setprecision(4)<<setw(25)<<left<<"secondjetpt = 0 "<<nevj2pteq0/nwentries<<endl;
cout<<setprecision(4)<<setw(25)<<left<<"thirdjetpt = 0 "<<nevj3pteq0/nwentries<<endl;
cout<<setprecision(4)<<setw(25)<<left<<"signaljetpt != 0 "<<nevj1ptneq0/nwentries<<endl;
cout<<setprecision(4)<<setw(25)<<left<<"secondjetpt != 0 "<<nevj2ptneq0/nwentries<<endl;
cout<<setprecision(4)<<setw(25)<<left<<"thirdjetpt != 0 "<<nevj3ptneq0/nwentries<<endl;
cout<<"--------------------------------------------------------"<<endl;
cout<<"-----------------------------------------------------------------------------------"<<endl;
cout<<endl;
//------------------------------------------------
// beginning of file
//------------------------------------------------
//the following file is to record the last sequence of cuts used
ofstream recoFile("lastCuts.txt",ios::out);
if ( !recoFile.is_open() ) {
cout<<"Error: unable to open file "<<"lastCuts.txt"<<" !"<<endl;
} else {
cout<<"Saving latest results of cut based analysis in file lastCuts.txt ..."<<endl;
//when writing on file, the date is printed as well unless an error occurs
if ( system("date>>lastCuts.txt") != 0) cout<<"Error during \"system(\"date>>lastCuts.txt\")\" call"<<endl;
cut::printCutFlow(recoFile, NCUTS, singleCutMask);
myPrintEventYields(recoFile,LUMI,NCUTS,nWeightedEvents);
recoFile.close();
}
char answer = '\0';
const char* filename = "cutFlowData.txt"; //this file is like a logbook
answer = myAskToSaveFile(filename);
if (answer == 'y') {
ofstream myfile(filename,ios::app);
if ( !myfile.is_open() ) {
cout<<"Error: unable to open file "<<filename<<" !"<<endl;
} else {
//when writing on file, the date is printed as well unless an error occurs
if ( system("date>>cutFlowData.txt") != 0) cout<<"Error during \"system(\"date>>cutFlowData.txt\")\" call"<<endl;
cut::printCutFlow(myfile, NCUTS, singleCutMask);
myPrintEventYields(myfile,LUMI,NCUTS,nWeightedEvents);
myfile.close();
}
}
//------------------------------------------------
//end of file
//------------------------------------------------
const char *texfname = "table.tex";
answer = myAskToSaveFile(texfname);
if (answer == 'y') {
//creating a .tex file to build tables with data
FILE *fp;
//cout<<"name given to file: "<<texfname<<endl;
if ( (fp=fopen(texfname,"w")) == NULL) {
cout<<"Error: '"<<texfname<<"' not opened"<<endl;
} else {
cout<<"creating file '"<<texfname<<"' ..."<<endl;
myAddDefaultPackages(fp,texfname);
fprintf(fp,"\\begin{document}\n");
fprintf(fp,"\n");
//building table
fprintf(fp,"\\begin{table}\n");
fprintf(fp,"\\caption{\\emph{Entries after each cut, normalised to %4.2lf $fb^{-1}$; n is the number of entries; aA is the ratio between n and entries of first cut;"
" aR is the ratio between n and n-1 (for n = 1, it's set to 1.0). Note that cuts on second jet are applied only if a second jet exists with $p_t$ > 30\\,GeV. "
"}}\n",(Double_t)LUMI);
fprintf(fp,"\\[\n");
fprintf(fp,"\\begin{array}{rrrrr}\n");
fprintf(fp,"\\toprule\n");
fprintf(fp,"\\ \\textbf{cut}& \\textbf{definition} & n & aA & aR \\\\ \n");
fprintf(fp,"\\midrule\n");
for (Int_t i = 1; i <= NCUTS; i++) {
if (i == 1) {
fprintf(fp," %i & & %6.0lf & %1.4lf & %1.4lf \\\\\n",i,nWeightedEvents[i],1.0,1.0);
} else {
fprintf(fp," %i & & %6.0lf & %1.4lf & %1.4lf \\\\\n",i,nWeightedEvents[i],nWeightedEvents[i]/nwentriesCut1,nWeightedEvents[i]/nWeightedEvents[i-1]);
}
for (Int_t j = 0; j < cut::getNCuts(); j++) {
if ((singleCutMask[i-1] >> j) & 1) {
string str = cut::listOfCuts[j]->getCutDefinition();
fprintf(fp,"& %s & & & \\\\\n",str.c_str());
}
}
fprintf(fp,"\\midrule\n");
}
fprintf(fp,"\\bottomrule\n");
fprintf(fp,"\\end{array}\n");
fprintf(fp,"\\]\n");
fprintf(fp,"\\end{table}\n");
//end of table
fprintf(fp,"\n");
fprintf(fp,"\\end{document}\n");
fclose(fp);
}
}
//saving histograms on file .root
const char *rootFileName = "histograms.root";
cout<<"Saving histograms in file \""<<rootFileName<<"\" ..."<<endl;
TFile *rootFile = new TFile(rootFileName,"RECREATE");
if (!rootFile->IsOpen()) {
cout<<"Error: file \""<<rootFileName<<"\" was not opened."<<endl;
} else {
for (Int_t i = 0; i <= NCUTS; i++) {
Hjet1pt[i]->Write();
}
Hjet1etanoC->Write();
Hjet1etaallCMet250->Write();
Hjet1etaallCMet500->Write();
Hjet2ptnoC->Write();
Hjet2ptallCMet250->Write();
Hjet2ptallCMet300->Write();
Hjet2ptallCMet400->Write();
Hjet2ptallCMet500->Write();
Hjet2etanoC->Write();
Hjet2etaallCMet250->Write();
Hjet2etaallCMet500->Write();
Hjet1jet2dphinoC->Write();
Hjet1jet2dphiallCMet250->Write();
Hjet1jet2dphiallCMet500->Write();
HnjetsnoC->Write();
HnjetsallCMet250->Write();
HnjetsallCMet500->Write();
HmumetnoC->Write();
HmumetallCMet250->Write();
for (Int_t i = 0; i < NVTXS; i++) {
HmumetOrtZvsNvtx[i]->Write();
HmumetParZvsNvtx[i]->Write();
HmumetX[i]->Write();
HmumetY[i]->Write();
}
for (Int_t i = 0; i < nBinsForResponse; i++) {
HZptBinned[i]->Write();
HmumetParZratio[i]->Write();
HmumetOrtZvsZpt[i]->Write();
HmumetParZvsZpt[i]->Write();
}
rootFile->Close();
}
delete rootFile;
/*
GetEffectiveEntries() returns ((Sum w)^2)/(Sum(w^2)) where w means weight and Sum is the sum over the arguments. This number is the number of events that would be needed by an unweighted histogram to have the same statistical power as the weighted one
As an example, if I have 5 events with weight 1 and other 5 with weight 0.2, I get 6.9 effective events instead of 10.
To get the number of entries taking weights into account (that is to say, the bin content or integral of the histogram) I must use GetSumOfWeights()
*/
/********************************************************/
// |||||||||||||||||||||||||| CANVASES ||||||||||||||||||||||||
/********************************************************/
/************************************/
// JET1 PT, TEST FOR MASKS
/************************************/
// TCanvas *Cjet1pt = new TCanvas("Cjet1pt","signaljet pt");
// Cjet1pt->SetLogy();
// Cjet1pt->SetGridx();
// Cjet1pt->SetGridy();
// Hjet1pt[1]->Draw("HE");
// Hjet1pt[1]->SetStats(kFALSE);
// Cjet1pt->SaveAs(MY_PDF_PATH"jet1ptMaskTest.pdf");
/************************************/
// JET1 PT
/************************************/
TCanvas *Cjet1pt = new TCanvas("Cjet1pt","signaljet pt");
TLegend *LegCjet1pt = new TLegend(0.7,0.5,0.9,0.9);
Cjet1pt->SetLogy();
Cjet1pt->SetGridy();
Cjet1pt->SetGridx();
myAddOverflowInLastBin(Hjet1pt[0]);
Hjet1pt[0]->Draw("HE");
//myDrawOverflow(Hjet1pt[0],"HE",0);
Hjet1pt[0]->SetStats(kFALSE);
LegCjet1pt->AddEntry(Hjet1pt[0],"no cuts","lf");
Hjet1pt[0]->GetXaxis()->SetTitle("signaljet pt [GeV]");
Hjet1pt[0]->GetYaxis()->SetTitle("events / 50 GeV");
Hjet1pt[0]->GetYaxis()->SetTitleOffset(1.4);
if (ENABLE_TRIGGER_CUTS) {