forked from cms-hcal-trigger/Validation
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrates.cxx
790 lines (677 loc) · 31.1 KB
/
rates.cxx
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
// Script for calculating rate histograms
// Originally from Aaron Bundock
#include "TMath.h"
#include "TFile.h"
#include "TTree.h"
#include "TH1F.h"
#include "TChain.h"
#include <iostream>
#include <fstream>
#include <string>
#include "L1Trigger/L1TNtuples/interface/L1AnalysisEventDataFormat.h"
#include "L1Trigger/L1TNtuples/interface/L1AnalysisL1UpgradeDataFormat.h"
#include "L1Trigger/L1TNtuples/interface/L1AnalysisRecoVertexDataFormat.h"
#include "L1Trigger/L1TNtuples/interface/L1AnalysisCaloTPDataFormat.h"
#include "L1Trigger/L1TNtuples/interface/L1AnalysisL1CaloTowerDataFormat.h"
/* TODO: put errors in rates...
creates the the rates and distributions for l1 trigger objects
How to use:
1. input the number of bunches in the run (~line 35)
2. change the variables "newConditionsNtuples" and "oldConditionsNtuples" to ntuple paths
3. If good run JSON is not applied during ntuple production, modify isGoodLumiSection()
Optionally, if you want to rescale to a given instantaneous luminosity:
1. input the instantaneous luminosity of the run (~line 32) [only if we scale to 2016 nominal]
2. select whether you rescale to L=1.5e34 (~line606??...) generally have it setup to rescale
nb: for 2&3 I have provided the info in runInfoForRates.txt
*/
// configurable parameters
double numBunch = 1537; //the number of bunches colliding for the run of interest
double runLum = 0.02; // 0.44: 275783 0.58: 276363 //luminosity of the run of interest (*10^34)
double expectedLum = 1.15; //expected luminosity of 2016 runs (*10^34)
void rates(bool newConditions, const std::string& inputFileDirectory);
int main(int argc, char *argv[])
{
bool newConditions = true;
std::string ntuplePath("");
if (argc != 3) {
std::cout << "Usage: rates.exe [new/def] [path to ntuples]\n"
<< "[new/def] indicates new or default (existing) conditions" << std::endl;
exit(1);
}
else {
std::string par1(argv[1]);
std::transform(par1.begin(), par1.end(), par1.begin(), ::tolower);
if(par1.compare("new") == 0) newConditions = true;
else if(par1.compare("def") == 0) newConditions = false;
else {
std::cout << "First parameter must be \"new\" or \"def\"" << std::endl;
exit(1);
}
ntuplePath = argv[2];
}
rates(newConditions, ntuplePath);
return 0;
}
// only need to edit this section if good run JSON
// is not used during ntuple production
bool isGoodLumiSection(int lumiBlock)
{
if (lumiBlock >= 1
|| lumiBlock <= 10000) {
return true;
}
return false;
}
void rates(bool newConditions, const std::string& inputFileDirectory){
bool hwOn = true; //are we using data from hardware? (upgrade trigger had to be running!!!)
bool emuOn = true; //are we using data from emulator?
if (hwOn==false && emuOn==false){
std::cout << "exiting as neither hardware or emulator selected" << std::endl;
return;
}
std::string inputFile(inputFileDirectory);
inputFile += "/L1Ntuple_*.root";
std::string outputDirectory = "emu"; //***runNumber, triggerType, version, hw/emu/both***MAKE SURE IT EXISTS
std::string outputFilename = "rates_def.root";
if(newConditions) outputFilename = "rates_new_cond.root";
TFile* kk = TFile::Open( outputFilename.c_str() , "recreate");
// if (kk!=0){
// cout << "TERMINATE: not going to overwrite file " << outputFilename << endl;
// return;
// }
// make trees
std::cout << "Loading up the TChain..." << std::endl;
TChain * treeL1emu = new TChain("l1UpgradeEmuTree/L1UpgradeTree");
if (emuOn){
treeL1emu->Add(inputFile.c_str());
}
TChain * treeL1hw = new TChain("l1UpgradeTree/L1UpgradeTree");
if (hwOn){
treeL1hw->Add(inputFile.c_str());
}
TChain * treeL1Towemu = new TChain("l1CaloTowerEmuTree/L1CaloTowerTree");
if (emuOn){
treeL1Towemu->Add(inputFile.c_str());
}
TChain * eventTree = new TChain("l1EventTree/L1EventTree");
eventTree->Add(inputFile.c_str());
// In case you want to include PU info
// TChain * vtxTree = new TChain("l1RecoTree/RecoTree");
// if(binByPileUp){
// vtxTree->Add(inputFile.c_str());
// }
TChain * treeL1TPemu = new TChain("l1CaloTowerEmuTree/L1CaloTowerTree");
if (emuOn){
treeL1TPemu->Add(inputFile.c_str());
}
TChain * treeL1TPhw = new TChain("l1CaloTowerTree/L1CaloTowerTree");
if (hwOn){
treeL1TPhw->Add(inputFile.c_str());
}
L1Analysis::L1AnalysisL1UpgradeDataFormat *l1emu_ = new L1Analysis::L1AnalysisL1UpgradeDataFormat();
treeL1emu->SetBranchAddress("L1Upgrade", &l1emu_);
L1Analysis::L1AnalysisL1UpgradeDataFormat *l1hw_ = new L1Analysis::L1AnalysisL1UpgradeDataFormat();
treeL1hw->SetBranchAddress("L1Upgrade", &l1hw_);
L1Analysis::L1AnalysisEventDataFormat *event_ = new L1Analysis::L1AnalysisEventDataFormat();
eventTree->SetBranchAddress("Event", &event_);
L1Analysis::L1AnalysisL1CaloTowerDataFormat *l1Towemu_ = new L1Analysis::L1AnalysisL1CaloTowerDataFormat();
treeL1Towemu->SetBranchAddress("L1CaloTower", &l1Towemu_);
// L1Analysis::L1AnalysisRecoVertexDataFormat *vtx_ = new L1Analysis::L1AnalysisRecoVertexDataFormat();
// vtxTree->SetBranchAddress("Vertex", &vtx_);
L1Analysis::L1AnalysisCaloTPDataFormat *l1TPemu_ = new L1Analysis::L1AnalysisCaloTPDataFormat();
treeL1TPemu->SetBranchAddress("CaloTP", &l1TPemu_);
L1Analysis::L1AnalysisCaloTPDataFormat *l1TPhw_ = new L1Analysis::L1AnalysisCaloTPDataFormat();
treeL1TPhw->SetBranchAddress("CaloTP", &l1TPhw_);
// get number of entries
Long64_t nentries;
if (emuOn) nentries = treeL1emu->GetEntries();
else nentries = treeL1hw->GetEntries();
int goodLumiEventCount = 0;
std::string outputTxtFilename = "output_rates/" + outputDirectory + "/extraInfo.txt";
std::ofstream myfile; // save info about the run, including rates for a given lumi section, and number of events we used.
myfile.open(outputTxtFilename.c_str());
eventTree->GetEntry(0);
myfile << "run number = " << event_->run << std::endl;
// set parameters for histograms
// jet bins
int nJetBins = 400;
float jetLo = 0.;
float jetHi = 400.;
float jetBinWidth = (jetHi-jetLo)/nJetBins;
// EG bins
int nEgBins = 300;
float egLo = 0.;
float egHi = 300.;
float egBinWidth = (egHi-egLo)/nEgBins;
// tau bins
int nTauBins = 300;
float tauLo = 0.;
float tauHi = 300.;
float tauBinWidth = (tauHi-tauLo)/nTauBins;
// htSum bins
int nHtSumBins = 600;
float htSumLo = 0.;
float htSumHi = 600.;
float htSumBinWidth = (htSumHi-htSumLo)/nHtSumBins;
// mhtSum bins
int nMhtSumBins = 300;
float mhtSumLo = 0.;
float mhtSumHi = 300.;
float mhtSumBinWidth = (mhtSumHi-mhtSumLo)/nMhtSumBins;
// etSum bins
int nEtSumBins = 600;
float etSumLo = 0.;
float etSumHi = 600.;
float etSumBinWidth = (etSumHi-etSumLo)/nEtSumBins;
// metSum bins
int nMetSumBins = 300;
float metSumLo = 0.;
float metSumHi = 300.;
float metSumBinWidth = (metSumHi-metSumLo)/nMetSumBins;
// metHFSum bins
int nMetHFSumBins = 300;
float metHFSumLo = 0.;
float metHFSumHi = 300.;
float metHFSumBinWidth = (metHFSumHi-metHFSumLo)/nMetHFSumBins;
// tp bins
int nTpBins = 100;
float tpLo = 0.;
float tpHi = 100.;
std::string axR = ";Threshold E_{T} (GeV);rate (Hz)";
std::string axD = ";E_{T} (GeV);events/bin";
//make histos
TH1F* singleJetRates_emu = new TH1F("singleJetRates_emu", axR.c_str(), nJetBins, jetLo, jetHi);
TH1F* doubleJetRates_emu = new TH1F("doubleJetRates_emu", axR.c_str(), nJetBins, jetLo, jetHi);
TH1F* tripleJetRates_emu = new TH1F("tripleJetRates_emu", axR.c_str(), nJetBins, jetLo, jetHi);
TH1F* quadJetRates_emu = new TH1F("quadJetRates_emu", axR.c_str(), nJetBins, jetLo, jetHi);
TH1F* singleEgRates_emu = new TH1F("singleEgRates_emu", axR.c_str(), nEgBins, egLo, egHi);
TH1F* doubleEgRates_emu = new TH1F("doubleEgRates_emu", axR.c_str(), nEgBins, egLo, egHi);
TH1F* singleTauRates_emu = new TH1F("singleTauRates_emu", axR.c_str(), nTauBins, tauLo, tauHi);
TH1F* doubleTauRates_emu = new TH1F("doubleTauRates_emu", axR.c_str(), nTauBins, tauLo, tauHi);
TH1F* singleISOEgRates_emu = new TH1F("singleISOEgRates_emu", axR.c_str(), nEgBins, egLo, egHi);
TH1F* doubleISOEgRates_emu = new TH1F("doubleISOEgRates_emu", axR.c_str(), nEgBins, egLo, egHi);
TH1F* singleISOTauRates_emu = new TH1F("singleISOTauRates_emu", axR.c_str(), nTauBins, tauLo, tauHi);
TH1F* doubleISOTauRates_emu = new TH1F("doubleISOTauRates_emu", axR.c_str(), nTauBins, tauLo, tauHi);
TH1F* htSumRates_emu = new TH1F("htSumRates_emu",axR.c_str(), nHtSumBins, htSumLo, htSumHi);
TH1F* mhtSumRates_emu = new TH1F("mhtSumRates_emu",axR.c_str(), nMhtSumBins, mhtSumLo, mhtSumHi);
TH1F* etSumRates_emu = new TH1F("etSumRates_emu",axR.c_str(), nEtSumBins, etSumLo, etSumHi);
TH1F* metSumRates_emu = new TH1F("metSumRates_emu",axR.c_str(), nMetSumBins, metSumLo, metSumHi);
TH1F* metHFSumRates_emu = new TH1F("metHFSumRates_emu",axR.c_str(), nMetHFSumBins, metHFSumLo, metHFSumHi);
TH1F* singleJetRates_hw = new TH1F("singleJetRates_hw", axR.c_str(), nJetBins, jetLo, jetHi);
TH1F* doubleJetRates_hw = new TH1F("doubleJetRates_hw", axR.c_str(), nJetBins, jetLo, jetHi);
TH1F* tripleJetRates_hw = new TH1F("tripleJetRates_hw", axR.c_str(), nJetBins, jetLo, jetHi);
TH1F* quadJetRates_hw = new TH1F("quadJetRates_hw", axR.c_str(), nJetBins, jetLo, jetHi);
TH1F* singleEgRates_hw = new TH1F("singleEgRates_hw", axR.c_str(), nEgBins, egLo, egHi);
TH1F* doubleEgRates_hw = new TH1F("doubleEgRates_hw", axR.c_str(), nEgBins, egLo, egHi);
TH1F* singleTauRates_hw = new TH1F("singleTauRates_hw", axR.c_str(), nTauBins, tauLo, tauHi);
TH1F* doubleTauRates_hw = new TH1F("doubleTauRates_hw", axR.c_str(), nTauBins, tauLo, tauHi);
TH1F* singleISOEgRates_hw = new TH1F("singleISOEgRates_hw", axR.c_str(), nEgBins, egLo, egHi);
TH1F* doubleISOEgRates_hw = new TH1F("doubleISOEgRates_hw", axR.c_str(), nEgBins, egLo, egHi);
TH1F* singleISOTauRates_hw = new TH1F("singleISOTauRates_hw", axR.c_str(), nTauBins, tauLo, tauHi);
TH1F* doubleISOTauRates_hw = new TH1F("doubleISOTauRates_hw", axR.c_str(), nTauBins, tauLo, tauHi);
TH1F* htSumRates_hw = new TH1F("htSumRates_hw",axR.c_str(), nHtSumBins, htSumLo, htSumHi);
TH1F* mhtSumRates_hw = new TH1F("mhtSumRates_hw",axR.c_str(), nMhtSumBins, mhtSumLo, mhtSumHi);
TH1F* etSumRates_hw = new TH1F("etSumRates_hw",axR.c_str(), nEtSumBins, etSumLo, etSumHi);
TH1F* metSumRates_hw = new TH1F("metSumRates_hw",axR.c_str(), nMetHFSumBins, metHFSumLo, metHFSumHi);
TH1F* metHFSumRates_hw = new TH1F("metHFSumRates_hw",axR.c_str(), nMetHFSumBins, metHFSumLo, metHFSumHi);
TH1F* hcalTP_emu = new TH1F("hcalTP_emu", ";TP E_{T}; # Entries", nTpBins, tpLo, tpHi);
TH1F* ecalTP_emu = new TH1F("ecalTP_emu", ";TP E_{T}; # Entries", nTpBins, tpLo, tpHi);
TH1F* hcalTP_hw = new TH1F("hcalTP_hw", ";TP E_{T}; # Entries", nTpBins, tpLo, tpHi);
TH1F* ecalTP_hw = new TH1F("ecalTP_hw", ";TP E_{T}; # Entries", nTpBins, tpLo, tpHi);
TH1D * hJetEt = new TH1D("jetET",";ET;",100,0,1000);
std::vector<TString> ratioStrings = {"HOvE","HOvE3","HOvE9","H3OvE3","H9OvE9"};
TH1F* HovEtotal_1x1_emu = new TH1F("HovEtotal_1x1_emu", "HCAL energy / ECAL+HCAL energy for Jets (1x1);H/E;# Entries", 50,0,1);
TH1F* HovEtotal_3x3_emu = new TH1F("HovEtotal_3x3_emu", "HCAL energy / ECAL+HCAL energy for Jets (3x3);H/E;# Entries", 50,0,1);
/////////////////////////////////
// loop through all the entries//
/////////////////////////////////
for (Long64_t jentry=0; jentry<nentries; jentry++){
if((jentry%10000)==0) std::cout << "Done " << jentry << " events of " << nentries << std::endl;
//lumi break clause
eventTree->GetEntry(jentry);
//skip the corresponding event
if (!isGoodLumiSection(event_->lumi)) continue;
goodLumiEventCount++;
//do routine for L1 emulator quantites
if (emuOn){
treeL1TPemu->GetEntry(jentry);
treeL1Towemu->GetEntry(jentry);
double tpEt(0.);
for(int i=0; i < l1TPemu_->nHCALTP; i++){
tpEt = l1TPemu_->hcalTPet[i];
hcalTP_emu->Fill(tpEt);
}
for(int i=0; i < l1TPemu_->nECALTP; i++){
tpEt = l1TPemu_->ecalTPet[i];
ecalTP_emu->Fill(tpEt);
}
treeL1emu->GetEntry(jentry);
// get jetEt*, egEt*, tauEt, htSum, mhtSum, etSum, metSum
// ALL EMU OBJECTS HAVE BX=0...
double jetEt_1 = 0;
double jetEt_2 = 0;
double jetEt_3 = 0;
double jetEt_4 = 0;
if (l1emu_->nJets>0) jetEt_1 = l1emu_->jetEt[0];
if (l1emu_->nJets>1) jetEt_2 = l1emu_->jetEt[1];
if (l1emu_->nJets>2) jetEt_3 = l1emu_->jetEt[2];
if (l1emu_->nJets>3) jetEt_4 = l1emu_->jetEt[3];
double egEt_1 = 0;
double egEt_2 = 0;
//EG pt's are not given in descending order...bx?
for (UInt_t c=0; c<l1emu_->nEGs; c++){
if (l1emu_->egEt[c] > egEt_1){
egEt_2 = egEt_1;
egEt_1 = l1emu_->egEt[c];
}
else if (l1emu_->egEt[c] <= egEt_1 && l1emu_->egEt[c] > egEt_2){
egEt_2 = l1emu_->egEt[c];
}
}
double tauEt_1 = 0;
double tauEt_2 = 0;
//tau pt's are not given in descending order
for (UInt_t c=0; c<l1emu_->nTaus; c++){
if (l1emu_->tauEt[c] > tauEt_1){
tauEt_2 = tauEt_1;
tauEt_1 = l1emu_->tauEt[c];
}
else if (l1emu_->tauEt[c] <= tauEt_1 && l1emu_->tauEt[c] > tauEt_2){
tauEt_2 = l1emu_->tauEt[c];
}
}
double egISOEt_1 = 0;
double egISOEt_2 = 0;
//EG pt's are not given in descending order...bx?
for (UInt_t c=0; c<l1emu_->nEGs; c++){
if (l1emu_->egEt[c] > egISOEt_1 && l1emu_->egIso[c]==1){
egISOEt_2 = egISOEt_1;
egISOEt_1 = l1emu_->egEt[c];
}
else if (l1emu_->egEt[c] <= egISOEt_1 && l1emu_->egEt[c] > egISOEt_2 && l1emu_->egIso[c]==1){
egISOEt_2 = l1emu_->egEt[c];
}
}
double tauISOEt_1 = 0;
double tauISOEt_2 = 0;
//tau pt's are not given in descending order
for (UInt_t c=0; c<l1emu_->nTaus; c++){
if (l1emu_->tauEt[c] > tauISOEt_1 && l1emu_->tauIso[c]>0){
tauISOEt_2 = tauISOEt_1;
tauISOEt_1 = l1emu_->tauEt[c];
}
else if (l1emu_->tauEt[c] <= tauISOEt_1 && l1emu_->tauEt[c] > tauISOEt_2 && l1emu_->tauIso[c]>0){
tauISOEt_2 = l1emu_->tauEt[c];
}
}
double htSum(0.0);
double mhtSum(0.0);
double etSum(0.0);
double metSum(0.0);
double metHFSum(0.0);
for (unsigned int c=0; c<l1emu_->nSums; c++){
if( l1emu_->sumBx[c] != 0 ) continue;
if( l1emu_->sumType[c] == L1Analysis::kTotalEt ) etSum = l1emu_->sumEt[c];
if( l1emu_->sumType[c] == L1Analysis::kTotalHt ) htSum = l1emu_->sumEt[c];
if( l1emu_->sumType[c] == L1Analysis::kMissingEt ) metSum = l1emu_->sumEt[c];
if( l1emu_->sumType[c] == L1Analysis::kMissingEtHF ) metHFSum = l1emu_->sumEt[c];
if( l1emu_->sumType[c] == L1Analysis::kMissingHt ) mhtSum = l1emu_->sumEt[c];
}
// for each bin fill according to whether our object has a larger corresponding energy
int seedTowerIEta(-1);
int seedTowerIPhi(-1);
int maxTowerEndcap = 28;
int maxTowerBarrel = 16;
int minTowerForHOvE = maxTowerBarrel+1;
int maxTowerForHOvE = maxTowerEndcap;
uint nJetemu(0);
double towEtemu(0), towHademu(0), towEmemu(0), towEtaemu(0), towPhiemu(0), nTowemu(0);
nTowemu = l1Towemu_->nTower;
nJetemu = l1emu_->nJets;
//std::cout << "nTower emu = " << nTowemu << " and nJet emu = " << nJetemu << std::endl;
std::map<const TString, std::vector<double> > hadVariablesAllJets;
std::map<const TString, std::vector<double> > emVariablesAllJets;
for(uint jetIt=0; jetIt<nJetemu; jetIt++){
hJetEt->Fill(l1emu_->jetEt[jetIt]);
seedTowerIPhi = l1emu_->jetTowerIPhi[jetIt];
seedTowerIEta = l1emu_->jetTowerIEta[jetIt];
double seedTowerHad(0), seedTowerEm(0), seedTower3x3Em(0), seedTower3x3Had(0), seedTower9x9Em(0), seedTower9x9Had(0);
for (int towIt = 0; towIt < nTowemu; towIt++){
towEtemu = l1Towemu_->iet[towIt];
towHademu = l1Towemu_->ihad[towIt];
towEmemu = l1Towemu_->iem[towIt];
towEtaemu = l1Towemu_->ieta[towIt];
towPhiemu = l1Towemu_->iphi[towIt];
if (abs(towEtaemu) >= minTowerForHOvE && abs(towEtaemu) <= maxTowerForHOvE){
if (towEtaemu == seedTowerIEta && towPhiemu == seedTowerIPhi){
seedTowerHad = towHademu;
seedTowerEm = towEmemu;
}
for (int iSeedTowerIEta = -4; iSeedTowerIEta <= 4; ++iSeedTowerIEta){
for (int iSeedTowerIPhi = -4; iSeedTowerIPhi <= 4; ++iSeedTowerIPhi){
int wrappedIPhi = seedTowerIPhi+iSeedTowerIPhi;
if (wrappedIPhi > 72) wrappedIPhi -= 72;
if (wrappedIPhi < 0) wrappedIPhi += 72;
if (towEtaemu == seedTowerIEta+iSeedTowerIEta && towPhiemu == wrappedIPhi){
seedTower9x9Em += towEmemu;
seedTower9x9Had += towHademu;
if (abs(iSeedTowerIPhi) <= 1 && abs(iSeedTowerIEta) <= 1){
seedTower3x3Em += towEmemu;
seedTower3x3Had += towHademu;
}
}
}
}
} // closing min max tower statement
} // closing seed tower loop
hadVariablesAllJets["HOvE"].push_back(seedTowerHad);
hadVariablesAllJets["HOvE3"].push_back(seedTowerHad);
hadVariablesAllJets["HOvE9"].push_back(seedTowerHad);
hadVariablesAllJets["H3OvE3"].push_back(seedTower3x3Had);
hadVariablesAllJets["H9OvE9"].push_back(seedTower9x9Had);
emVariablesAllJets["HOvE"].push_back(seedTowerEm);
emVariablesAllJets["HOvE3"].push_back(seedTower3x3Em);
emVariablesAllJets["HOvE9"].push_back(seedTower9x9Em);
emVariablesAllJets["H3OvE3"].push_back(seedTower3x3Em);
emVariablesAllJets["H9OvE9"].push_back(seedTower9x9Em);
} // closing the jet loop
HovEtotal_1x1_emu->Fill((hadVariablesAllJets["HOvE"][0])/(hadVariablesAllJets["HOvE"][0]+emVariablesAllJets["HOvE"][0]));
HovEtotal_3x3_emu->Fill((hadVariablesAllJets["H3OvE3"][0])/(hadVariablesAllJets["H3OvE3"][0]+emVariablesAllJets["H3OvE3"][0]));
for(int bin=0; bin<nJetBins; bin++){
if( ((hadVariablesAllJets["H3OvE3"][0])/(hadVariablesAllJets["H3OvE3"][0]+emVariablesAllJets["H3OvE3"][0]) > 0.9) && ( (jetEt_1) >= jetLo + (bin*jetBinWidth) ) ) singleJetRates_emu->Fill(jetLo+(bin*jetBinWidth)); //GeV
}
for(int bin=0; bin<nJetBins; bin++){
if( ((hadVariablesAllJets["H3OvE3"][1])/(hadVariablesAllJets["H3OvE3"][1]+emVariablesAllJets["H3OvE3"][1]) > 0.9) && (jetEt_2) >= jetLo + (bin*jetBinWidth) ) doubleJetRates_emu->Fill(jetLo+(bin*jetBinWidth)); //GeV
}
for(int bin=0; bin<nJetBins; bin++){
if( ((hadVariablesAllJets["H3OvE3"][2])/(hadVariablesAllJets["H3OvE3"][2]+emVariablesAllJets["H3OvE3"][2]) > 0.9) && (jetEt_3) >= jetLo + (bin*jetBinWidth) ) tripleJetRates_emu->Fill(jetLo+(bin*jetBinWidth)); //GeV
}
for(int bin=0; bin<nJetBins; bin++){
if( ((hadVariablesAllJets["H3OvE3"][3])/(hadVariablesAllJets["H3OvE3"][3]+emVariablesAllJets["H3OvE3"][3]) > 0.9) && (jetEt_4) >= jetLo + (bin*jetBinWidth) ) quadJetRates_emu->Fill(jetLo+(bin*jetBinWidth)); //GeV
}
for(int bin=0; bin<nEgBins; bin++){
if( (egEt_1) >= egLo + (bin*egBinWidth) ) singleEgRates_emu->Fill(egLo+(bin*egBinWidth)); //GeV
}
for(int bin=0; bin<nEgBins; bin++){
if( (egEt_2) >= egLo + (bin*egBinWidth) ) doubleEgRates_emu->Fill(egLo+(bin*egBinWidth)); //GeV
}
for(int bin=0; bin<nTauBins; bin++){
if( (tauEt_1) >= tauLo + (bin*tauBinWidth) ) singleTauRates_emu->Fill(tauLo+(bin*tauBinWidth)); //GeV
}
for(int bin=0; bin<nTauBins; bin++){
if( (tauEt_2) >= tauLo + (bin*tauBinWidth) ) doubleTauRates_emu->Fill(tauLo+(bin*tauBinWidth)); //GeV
}
for(int bin=0; bin<nEgBins; bin++){
if( (egISOEt_1) >= egLo + (bin*egBinWidth) ) singleISOEgRates_emu->Fill(egLo+(bin*egBinWidth)); //GeV
}
for(int bin=0; bin<nEgBins; bin++){
if( (egISOEt_2) >= egLo + (bin*egBinWidth) ) doubleISOEgRates_emu->Fill(egLo+(bin*egBinWidth)); //GeV
}
for(int bin=0; bin<nTauBins; bin++){
if( (tauISOEt_1) >= tauLo + (bin*tauBinWidth) ) singleISOTauRates_emu->Fill(tauLo+(bin*tauBinWidth)); //GeV
}
for(int bin=0; bin<nTauBins; bin++){
if( (tauISOEt_2) >= tauLo + (bin*tauBinWidth) ) doubleISOTauRates_emu->Fill(tauLo+(bin*tauBinWidth)); //GeV
}
for(int bin=0; bin<nHtSumBins; bin++){
if( (htSum) >= htSumLo+(bin*htSumBinWidth) ) htSumRates_emu->Fill(htSumLo+(bin*htSumBinWidth)); //GeV
}
for(int bin=0; bin<nMhtSumBins; bin++){
if( (mhtSum) >= mhtSumLo+(bin*mhtSumBinWidth) ) mhtSumRates_emu->Fill(mhtSumLo+(bin*mhtSumBinWidth)); //GeV
}
for(int bin=0; bin<nEtSumBins; bin++){
if( (etSum) >= etSumLo+(bin*etSumBinWidth) ) etSumRates_emu->Fill(etSumLo+(bin*etSumBinWidth)); //GeV
}
for(int bin=0; bin<nMetSumBins; bin++){
if( (metSum) >= metSumLo+(bin*metSumBinWidth) ) metSumRates_emu->Fill(metSumLo+(bin*metSumBinWidth)); //GeV
}
for(int bin=0; bin<nMetHFSumBins; bin++){
if( (metHFSum) >= metHFSumLo+(bin*metHFSumBinWidth) ) metHFSumRates_emu->Fill(metHFSumLo+(bin*metHFSumBinWidth)); //GeV
}
}// closes if 'emuOn' is true
//do routine for L1 hardware quantities
if (hwOn){
treeL1TPhw->GetEntry(jentry);
double tpEt(0.);
for(int i=0; i < l1TPhw_->nHCALTP; i++){
tpEt = l1TPhw_->hcalTPet[i];
hcalTP_hw->Fill(tpEt);
}
for(int i=0; i < l1TPhw_->nECALTP; i++){
tpEt = l1TPhw_->ecalTPet[i];
ecalTP_hw->Fill(tpEt);
}
treeL1hw->GetEntry(jentry);
// get jetEt*, egEt*, tauEt, htSum, mhtSum, etSum, metSum
// ***INCLUDES NON_ZERO bx*** can't just read values off
double jetEt_1 = 0;
double jetEt_2 = 0;
double jetEt_3 = 0;
double jetEt_4 = 0;
for (UInt_t c=0; c<l1hw_->nJets; c++){
if (l1hw_->jetBx[c]==0 && l1hw_->jetEt[c] > jetEt_1){
jetEt_4 = jetEt_3;
jetEt_3 = jetEt_2;
jetEt_2 = jetEt_1;
jetEt_1 = l1hw_->jetEt[c];
}
else if (l1hw_->jetBx[c]==0 && l1hw_->jetEt[c] <= jetEt_1 && l1hw_->jetEt[c] > jetEt_2){
jetEt_4 = jetEt_3;
jetEt_3 = jetEt_2;
jetEt_2 = l1hw_->jetEt[c];
}
else if (l1hw_->jetBx[c]==0 && l1hw_->jetEt[c] <= jetEt_2 && l1hw_->jetEt[c] > jetEt_3){
jetEt_4 = jetEt_3;
jetEt_3 = l1hw_->jetEt[c];
}
else if (l1hw_->jetBx[c]==0 && l1hw_->jetEt[c] <= jetEt_3 && l1hw_->jetEt[c] > jetEt_4){
jetEt_4 = l1hw_->jetEt[c];
}
}
double egEt_1 = 0;
double egEt_2 = 0;
for (UInt_t c=0; c<l1hw_->nEGs; c++){
if (l1hw_->egBx[c]==0 && l1hw_->egEt[c] > egEt_1){
egEt_2 = egEt_1;
egEt_1 = l1hw_->egEt[c];
}
else if (l1hw_->egBx[c]==0 && l1hw_->egEt[c] <= egEt_1 && l1hw_->egEt[c] > egEt_2){
egEt_2 = l1hw_->egEt[c];
}
}
double tauEt_1 = 0;
double tauEt_2 = 0;
//tau pt's are not given in descending order
for (UInt_t c=0; c<l1hw_->nTaus; c++){
if (l1hw_->tauBx[c]==0 && l1hw_->tauEt[c] > tauEt_1){
tauEt_1 = l1hw_->tauEt[c];
}
else if (l1hw_->tauBx[c]==0 && l1hw_->tauEt[c] <= tauEt_1 && l1hw_->tauEt[c] > tauEt_2){
tauEt_2 = l1hw_->tauEt[c];
}
}
double egISOEt_1 = 0;
double egISOEt_2 = 0;
//EG pt's are not given in descending order...bx?
for (UInt_t c=0; c<l1hw_->nEGs; c++){
if (l1hw_->egBx[c]==0 && l1hw_->egEt[c] > egISOEt_1 && l1hw_->egIso[c]==1){
egISOEt_2 = egISOEt_1;
egISOEt_1 = l1hw_->egEt[c];
}
else if (l1hw_->egBx[c]==0 && l1hw_->egEt[c] <= egISOEt_1 && l1hw_->egEt[c] > egISOEt_2 && l1hw_->egIso[c]==1){
egISOEt_2 = l1hw_->egEt[c];
}
}
double tauISOEt_1 = 0;
double tauISOEt_2 = 0;
//tau pt's are not given in descending order
for (UInt_t c=0; c<l1hw_->nTaus; c++){
if (l1hw_->tauBx[c]==0 && l1hw_->tauEt[c] > tauISOEt_1 && l1hw_->tauIso[c]>0){
tauISOEt_2 = tauISOEt_1;
tauISOEt_1 = l1hw_->tauEt[c];
}
else if (l1hw_->tauBx[c]==0 && l1hw_->tauEt[c] <= tauISOEt_1 && l1hw_->tauEt[c] > tauISOEt_2 && l1hw_->tauIso[c]>0){
tauISOEt_2 = l1hw_->tauEt[c];
}
}
double htSum = 0;
double mhtSum = 0;
double etSum = 0;
double metSum = 0;
double metHFSum = 0;
// HW includes -2,-1,0,1,2 bx info (hence the different numbers, could cause a seg fault if this changes)
for (unsigned int c=0; c<l1hw_->nSums; c++){
if( l1hw_->sumBx[c] != 0 ) continue;
if( l1hw_->sumType[c] == L1Analysis::kTotalEt ) etSum = l1hw_->sumEt[c];
if( l1hw_->sumType[c] == L1Analysis::kTotalHt ) htSum = l1hw_->sumEt[c];
if( l1hw_->sumType[c] == L1Analysis::kMissingEt ) metSum = l1hw_->sumEt[c];
if( l1hw_->sumType[c] == L1Analysis::kMissingEtHF ) metHFSum = l1hw_->sumEt[c];
if( l1hw_->sumType[c] == L1Analysis::kMissingHt ) mhtSum = l1hw_->sumEt[c];
}
// for each bin fill according to whether our object has a larger corresponding energy
for(int bin=0; bin<nJetBins; bin++){
if( (jetEt_1) >= jetLo + (bin*jetBinWidth) ) singleJetRates_hw->Fill(jetLo+(bin*jetBinWidth)); //GeV
}
for(int bin=0; bin<nJetBins; bin++){
if( (jetEt_2) >= jetLo + (bin*jetBinWidth) ) doubleJetRates_hw->Fill(jetLo+(bin*jetBinWidth)); //GeV
}
for(int bin=0; bin<nJetBins; bin++){
if( (jetEt_3) >= jetLo + (bin*jetBinWidth) ) tripleJetRates_hw->Fill(jetLo+(bin*jetBinWidth)); //GeV
}
for(int bin=0; bin<nJetBins; bin++){
if( (jetEt_4) >= jetLo + (bin*jetBinWidth) ) quadJetRates_hw->Fill(jetLo+(bin*jetBinWidth)); //GeV
}
for(int bin=0; bin<nEgBins; bin++){
if( (egEt_1) >= egLo + (bin*egBinWidth) ) singleEgRates_hw->Fill(egLo+(bin*egBinWidth)); //GeV
}
for(int bin=0; bin<nEgBins; bin++){
if( (egEt_2) >= egLo + (bin*egBinWidth) ) doubleEgRates_hw->Fill(egLo+(bin*egBinWidth)); //GeV
}
for(int bin=0; bin<nTauBins; bin++){
if( (tauEt_1) >= tauLo + (bin*tauBinWidth) ) singleTauRates_hw->Fill(tauLo+(bin*tauBinWidth)); //GeV
}
for(int bin=0; bin<nTauBins; bin++){
if( (tauEt_2) >= tauLo + (bin*tauBinWidth) ) doubleTauRates_hw->Fill(tauLo+(bin*tauBinWidth)); //GeV
}
for(int bin=0; bin<nEgBins; bin++){
if( (egISOEt_1) >= egLo + (bin*egBinWidth) ) singleISOEgRates_hw->Fill(egLo+(bin*egBinWidth)); //GeV
}
for(int bin=0; bin<nEgBins; bin++){
if( (egISOEt_2) >= egLo + (bin*egBinWidth) ) doubleISOEgRates_hw->Fill(egLo+(bin*egBinWidth)); //GeV
}
for(int bin=0; bin<nTauBins; bin++){
if( (tauISOEt_1) >= tauLo + (bin*tauBinWidth) ) singleISOTauRates_hw->Fill(tauLo+(bin*tauBinWidth)); //GeV
}
for(int bin=0; bin<nTauBins; bin++){
if( (tauISOEt_2) >= tauLo + (bin*tauBinWidth) ) doubleISOTauRates_hw->Fill(tauLo+(bin*tauBinWidth)); //GeV
}
for(int bin=0; bin<nHtSumBins; bin++){
if( (htSum) >= htSumLo+(bin*htSumBinWidth) ) htSumRates_hw->Fill(htSumLo+(bin*htSumBinWidth)); //GeV
}
for(int bin=0; bin<nMhtSumBins; bin++){
if( (mhtSum) >= mhtSumLo+(bin*mhtSumBinWidth) ) mhtSumRates_hw->Fill(mhtSumLo+(bin*mhtSumBinWidth)); //GeV
}
for(int bin=0; bin<nEtSumBins; bin++){
if( (etSum) >= etSumLo+(bin*etSumBinWidth) ) etSumRates_hw->Fill(etSumLo+(bin*etSumBinWidth)); //GeV
}
for(int bin=0; bin<nMetSumBins; bin++){
if( (metSum) >= metSumLo+(bin*metSumBinWidth) ) metSumRates_hw->Fill(metSumLo+(bin*metSumBinWidth)); //GeV
}
for(int bin=0; bin<nMetHFSumBins; bin++){
if( (metHFSum) >= metHFSumLo+(bin*metHFSumBinWidth) ) metHFSumRates_hw->Fill(metHFSumLo+(bin*metHFSumBinWidth)); //GeV
}
}// closes if 'hwOn' is true
}// closes loop through events
// TFile g( outputFilename.c_str() , "new");
kk->cd();
// normalisation factor for rate histograms (11kHz is the orbit frequency)
double norm = 11246*(numBunch/goodLumiEventCount); // no lumi rescale
// double norm = 11246*(numBunch/goodLumiEventCount)*(expectedLum/runLum); //scale to nominal lumi
if (emuOn){
singleJetRates_emu->Scale(norm);
doubleJetRates_emu->Scale(norm);
tripleJetRates_emu->Scale(norm);
quadJetRates_emu->Scale(norm);
singleEgRates_emu->Scale(norm);
doubleEgRates_emu->Scale(norm);
singleTauRates_emu->Scale(norm);
doubleTauRates_emu->Scale(norm);
singleISOEgRates_emu->Scale(norm);
doubleISOEgRates_emu->Scale(norm);
singleISOTauRates_emu->Scale(norm);
doubleISOTauRates_emu->Scale(norm);
htSumRates_emu->Scale(norm);
mhtSumRates_emu->Scale(norm);
etSumRates_emu->Scale(norm);
metSumRates_emu->Scale(norm);
metHFSumRates_emu->Scale(norm);
//set the errors for the rates
//want error -> error * sqrt(norm) ?
hcalTP_emu->Write();
ecalTP_emu->Write();
singleJetRates_emu->Write();
doubleJetRates_emu->Write();
tripleJetRates_emu->Write();
quadJetRates_emu->Write();
singleEgRates_emu->Write();
doubleEgRates_emu->Write();
singleTauRates_emu->Write();
doubleTauRates_emu->Write();
singleISOEgRates_emu->Write();
doubleISOEgRates_emu->Write();
singleISOTauRates_emu->Write();
doubleISOTauRates_emu->Write();
htSumRates_emu->Write();
mhtSumRates_emu->Write();
etSumRates_emu->Write();
metSumRates_emu->Write();
metHFSumRates_emu->Write();
HovEtotal_1x1_emu->Write();
HovEtotal_3x3_emu->Write();
}
if (hwOn){
singleJetRates_hw->Scale(norm);
doubleJetRates_hw->Scale(norm);
tripleJetRates_hw->Scale(norm);
quadJetRates_hw->Scale(norm);
singleEgRates_hw->Scale(norm);
doubleEgRates_hw->Scale(norm);
singleTauRates_hw->Scale(norm);
doubleTauRates_hw->Scale(norm);
singleISOEgRates_hw->Scale(norm);
doubleISOEgRates_hw->Scale(norm);
singleISOTauRates_hw->Scale(norm);
doubleISOTauRates_hw->Scale(norm);
htSumRates_hw->Scale(norm);
mhtSumRates_hw->Scale(norm);
etSumRates_hw->Scale(norm);
metSumRates_hw->Scale(norm);
metHFSumRates_hw->Scale(norm);
hcalTP_hw->Write();
ecalTP_hw->Write();
singleJetRates_hw->Write();
doubleJetRates_hw->Write();
tripleJetRates_hw->Write();
quadJetRates_hw->Write();
singleEgRates_hw->Write();
doubleEgRates_hw->Write();
singleTauRates_hw->Write();
doubleTauRates_hw->Write();
singleISOEgRates_hw->Write();
doubleISOEgRates_hw->Write();
singleISOTauRates_hw->Write();
doubleISOTauRates_hw->Write();
htSumRates_hw->Write();
mhtSumRates_hw->Write();
etSumRates_hw->Write();
metSumRates_hw->Write();
metHFSumRates_hw->Write();
}
myfile << "using the following ntuple: " << inputFile << std::endl;
myfile << "number of colliding bunches = " << numBunch << std::endl;
myfile << "run luminosity = " << runLum << std::endl;
myfile << "expected luminosity = " << expectedLum << std::endl;
myfile << "norm factor used = " << norm << std::endl;
myfile << "number of good events = " << goodLumiEventCount << std::endl;
myfile.close();
}//closes the function 'rates'