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
|
/**
* @file L1TTauOffline.cc
* @authors Olivier Davignon (University of Bristol), Cécile Caillol (University of Wisconsin - Madison)
* @date 24/05/2017
* @version 1.1
*
*/
#include "DQMOffline/L1Trigger/interface/L1TTauOffline.h"
#include "DataFormats/MuonReco/interface/MuonSelectors.h"
#include "DataFormats/MuonReco/interface/MuonPFIsolation.h"
#include "DataFormats/Math/interface/deltaR.h"
#include "TLorentzVector.h"
#include <iomanip>
#include <cstdio>
#include <string>
#include <sstream>
#include <cmath>
#include <algorithm>
using namespace reco;
using namespace trigger;
using namespace edm;
using namespace std;
TauL1TPair::TauL1TPair(const TauL1TPair& tauL1tPair) {
m_tau = tauL1tPair.m_tau;
m_regTau = tauL1tPair.m_regTau;
m_eta = tauL1tPair.m_eta;
m_phi_bar = tauL1tPair.m_phi_bar;
m_phi_end = tauL1tPair.m_phi_end;
}
double TauL1TPair::dR() { return deltaR(m_regTau->eta(), m_regTau->phi(), eta(), phi()); }
const std::map<std::string, unsigned int> L1TTauOffline::PlotConfigNames = {
{"nVertex", PlotConfig::nVertex}, {"ETvsET", PlotConfig::ETvsET}, {"PHIvsPHI", PlotConfig::PHIvsPHI}};
//
// -------------------------------------- Constructor --------------------------------------------
//
L1TTauOffline::L1TTauOffline(const edm::ParameterSet& ps)
: theTauCollection_(consumes<reco::PFTauCollection>(ps.getUntrackedParameter<edm::InputTag>("tauInputTag"))),
AntiMuInputTag_(
consumes<reco::TauDiscriminatorContainer>(ps.getUntrackedParameter<edm::InputTag>("antiMuInputTag"))),
AntiMuWP_(ps.getUntrackedParameter<std::string>("antiMuWP")),
AntiEleInputTag_(
consumes<reco::TauDiscriminatorContainer>(ps.getUntrackedParameter<edm::InputTag>("antiEleInputTag"))),
AntiEleWP_(ps.getUntrackedParameter<std::string>("antiEleWP")),
DecayModeFindingInputTag_(
consumes<reco::PFTauDiscriminator>(ps.getUntrackedParameter<edm::InputTag>("decayModeFindingInputTag"))),
comb3TInputTag_(
consumes<reco::TauDiscriminatorContainer>(ps.getUntrackedParameter<edm::InputTag>("comb3TInputTag"))),
comb3TWP_(ps.getUntrackedParameter<std::string>("comb3TWP")),
MuonInputTag_(consumes<reco::MuonCollection>(ps.getUntrackedParameter<edm::InputTag>("muonInputTag"))),
MetInputTag_(consumes<reco::PFMETCollection>(ps.getUntrackedParameter<edm::InputTag>("metInputTag"))),
VtxInputTag_(consumes<reco::VertexCollection>(ps.getUntrackedParameter<edm::InputTag>("vtxInputTag"))),
BsInputTag_(consumes<reco::BeamSpot>(ps.getUntrackedParameter<edm::InputTag>("bsInputTag"))),
triggerEvent_(consumes<trigger::TriggerEvent>(ps.getUntrackedParameter<edm::InputTag>("trigInputTag"))),
trigProcess_(ps.getUntrackedParameter<string>("trigProcess")),
triggerResults_(consumes<edm::TriggerResults>(ps.getUntrackedParameter<edm::InputTag>("trigProcess_token"))),
triggerPath_(ps.getUntrackedParameter<vector<std::string>>("triggerNames")),
histFolder_(ps.getParameter<std::string>("histFolder")),
efficiencyFolder_(histFolder_ + "/efficiency_raw"),
stage2CaloLayer2TauToken_(consumes<l1t::TauBxCollection>(ps.getUntrackedParameter<edm::InputTag>("l1tInputTag"))),
tauEfficiencyThresholds_(ps.getParameter<std::vector<int>>("tauEfficiencyThresholds")),
tauEfficiencyBins_(ps.getParameter<std::vector<double>>("tauEfficiencyBins")),
histDefinitions_(dqmoffline::l1t::readHistDefinitions(ps.getParameterSet("histDefinitions"), PlotConfigNames)),
m_TightMuons(),
m_ProbeTaus(),
m_TauL1tPairs(),
m_RecoTaus(),
m_L1tTaus(),
m_RecoRecoTaus(),
m_L1tL1tTaus(),
m_L1tPtCuts(),
m_MaxTauEta(99999),
m_MaxL1tTauDR(99999),
m_MaxHltTauDR(99999),
m_trigIndices(),
h_nVertex_(),
h_tagAndProbeMass_(),
h_L1TauETvsTauET_EB_(),
h_L1TauETvsTauET_EE_(),
h_L1TauETvsTauET_EB_EE_(),
h_L1TauPhivsTauPhi_EB_(),
h_L1TauPhivsTauPhi_EE_(),
h_L1TauPhivsTauPhi_EB_EE_(),
h_L1TauEtavsTauEta_(),
h_resolutionTauET_EB_(),
h_resolutionTauET_EE_(),
h_resolutionTauET_EB_EE_(),
h_resolutionTauPhi_EB_(),
h_resolutionTauPhi_EE_(),
h_resolutionTauPhi_EB_EE_(),
h_resolutionTauEta_(),
h_efficiencyIsoTauET_EB_pass_(),
h_efficiencyIsoTauET_EE_pass_(),
h_efficiencyIsoTauET_EB_EE_pass_(),
h_efficiencyNonIsoTauET_EB_pass_(),
h_efficiencyNonIsoTauET_EE_pass_(),
h_efficiencyNonIsoTauET_EB_EE_pass_(),
h_efficiencyIsoTauET_EB_total_(),
h_efficiencyIsoTauET_EE_total_(),
h_efficiencyIsoTauET_EB_EE_total_(),
h_efficiencyNonIsoTauET_EB_total_(),
h_efficiencyNonIsoTauET_EE_total_(),
h_efficiencyNonIsoTauET_EB_EE_total_() {
edm::LogInfo("L1TTauOffline") << "Constructor "
<< "L1TTauOffline::L1TTauOffline " << std::endl;
mFieldToken_ = esConsumes();
}
//
// -- Destructor
//
L1TTauOffline::~L1TTauOffline() {
edm::LogInfo("L1TTauOffline") << "Destructor L1TTauOffline::~L1TTauOffline " << std::endl;
}
//
// -------------------------------------- beginRun --------------------------------------------
//
void L1TTauOffline::dqmBeginRun(const edm::Run& run, const edm::EventSetup& iSetup)
// void L1TTauOffline::dqmBeginRun(edm::Run const &, edm::EventSetup const &)
{
bool changed = true;
m_hltConfig.init(run, iSetup, trigProcess_, changed);
edm::LogInfo("L1TTauOffline") << "L1TTauOffline::beginRun" << std::endl;
}
//
// -------------------------------------- bookHistos --------------------------------------------
//
void L1TTauOffline::bookHistograms(DQMStore::IBooker& ibooker, edm::Run const&, edm::EventSetup const&) {
edm::LogInfo("L1TTauOffline") << "L1TTauOffline::bookHistograms" << std::endl;
// book at beginRun
bookTauHistos(ibooker);
for (auto trigNamesIt = triggerPath_.begin(); trigNamesIt != triggerPath_.end(); trigNamesIt++) {
std::string tNameTmp = (*trigNamesIt);
std::string tNamePattern = "";
std::size_t found0 = tNameTmp.find('*');
if (found0 != std::string::npos)
tNamePattern = tNameTmp.substr(0, tNameTmp.size() - 1);
else
tNamePattern = tNameTmp;
int tIndex = -1;
for (unsigned ipath = 0; ipath < m_hltConfig.size(); ++ipath) {
std::string tmpName = m_hltConfig.triggerName(ipath);
std::size_t found = tmpName.find(tNamePattern);
if (found != std::string::npos) {
tIndex = int(ipath);
m_trigIndices.push_back(tIndex);
}
}
}
}
//
// -------------------------------------- Analyze --------------------------------------------
//
void L1TTauOffline::analyze(edm::Event const& e, edm::EventSetup const& eSetup) {
m_MaxTauEta = 2.1;
m_MaxL1tTauDR = 0.5;
m_MaxHltTauDR = 0.5;
edm::Handle<reco::PFTauCollection> taus;
e.getByToken(theTauCollection_, taus);
if (!taus.isValid()) {
edm::LogWarning("L1TTauOffline") << "invalid collection: reco::PFTauCollection " << std::endl;
return;
}
edm::Handle<reco::MuonCollection> muons;
e.getByToken(MuonInputTag_, muons);
if (!muons.isValid()) {
edm::LogWarning("L1TTauOffline") << "invalid collection: reco::MuonCollection " << std::endl;
return;
}
edm::Handle<reco::BeamSpot> beamSpot;
e.getByToken(BsInputTag_, beamSpot);
if (!beamSpot.isValid()) {
edm::LogWarning("L1TTauOffline") << "invalid collection: reco::BeamSpot " << std::endl;
return;
}
edm::Handle<reco::VertexCollection> vertex;
e.getByToken(VtxInputTag_, vertex);
if (!vertex.isValid()) {
edm::LogWarning("L1TTauOffline") << "invalid collection: reco::VertexCollection " << std::endl;
return;
}
edm::Handle<l1t::TauBxCollection> l1tCands;
e.getByToken(stage2CaloLayer2TauToken_, l1tCands);
if (!l1tCands.isValid()) {
edm::LogWarning("L1TTauOffline") << "invalid collection: l1t::TauBxCollection " << std::endl;
return;
}
edm::Handle<edm::TriggerResults> trigResults;
e.getByToken(triggerResults_, trigResults);
if (!trigResults.isValid()) {
edm::LogWarning("L1TTauOffline") << "invalid collection: edm::TriggerResults " << std::endl;
return;
}
edm::Handle<trigger::TriggerEvent> trigEvent;
e.getByToken(triggerEvent_, trigEvent);
if (!trigEvent.isValid()) {
edm::LogWarning("L1TTauOffline") << "invalid collection: trigger::TriggerEvent " << std::endl;
return;
}
edm::Handle<reco::PFMETCollection> mets;
e.getByToken(MetInputTag_, mets);
if (!mets.isValid()) {
edm::LogWarning("L1TTauOffline") << "invalid collection: reco::PFMETCollection " << std::endl;
return;
}
m_BField = eSetup.getHandle(mFieldToken_);
const reco::Vertex primaryVertex = getPrimaryVertex(vertex, beamSpot);
getTightMuons(muons, mets, primaryVertex, trigEvent);
getProbeTaus(e, taus, muons, primaryVertex);
getTauL1tPairs(l1tCands);
vector<l1t::Tau> l1tContainer;
l1tContainer.reserve(l1tCands->size() + 1);
for (auto tau = l1tCands->begin(0); tau != l1tCands->end(0); ++tau) {
l1tContainer.push_back(*tau);
}
for (auto tauL1tPairsIt = m_TauL1tPairs.begin(); tauL1tPairsIt != m_TauL1tPairs.end(); ++tauL1tPairsIt) {
float eta = tauL1tPairsIt->eta();
float phi = tauL1tPairsIt->phi();
float pt = tauL1tPairsIt->pt();
// unmatched gmt cands have l1tPt = -1.
float l1tPt = tauL1tPairsIt->l1tPt();
int counter = 0;
for (auto threshold : tauEfficiencyThresholds_) {
std::string str_threshold = std::to_string(threshold);
int l1tPtCut = threshold;
bool l1tAboveCut = (l1tPt >= l1tPtCut);
stringstream ptCutToTag;
ptCutToTag << l1tPtCut;
string ptTag = ptCutToTag.str();
if (fabs(eta) < m_MaxTauEta) {
if (counter == 0) {
if (fabs(eta) < 1.5) {
h_L1TauETvsTauET_EB_->Fill(pt, l1tPt);
h_L1TauPhivsTauPhi_EB_->Fill(phi, tauL1tPairsIt->l1tPhi());
h_resolutionTauET_EB_->Fill((l1tPt - pt) / pt);
h_resolutionTauPhi_EB_->Fill(tauL1tPairsIt->l1tPhi() - phi);
} else {
h_L1TauETvsTauET_EE_->Fill(pt, l1tPt);
h_L1TauPhivsTauPhi_EE_->Fill(phi, tauL1tPairsIt->l1tPhi());
h_resolutionTauET_EE_->Fill((l1tPt - pt) / pt);
h_resolutionTauPhi_EE_->Fill(tauL1tPairsIt->l1tPhi() - phi);
}
h_L1TauETvsTauET_EB_EE_->Fill(pt, l1tPt);
h_L1TauPhivsTauPhi_EB_EE_->Fill(phi, tauL1tPairsIt->l1tPhi());
h_L1TauEtavsTauEta_->Fill(eta, tauL1tPairsIt->l1tEta());
h_resolutionTauET_EB_EE_->Fill((l1tPt - pt) / pt);
h_resolutionTauPhi_EB_EE_->Fill(tauL1tPairsIt->l1tPhi() - phi);
h_resolutionTauEta_->Fill(tauL1tPairsIt->l1tEta() - eta);
++counter;
}
if (fabs(eta) < 1.5) {
h_efficiencyNonIsoTauET_EB_total_[threshold]->Fill(pt);
h_efficiencyIsoTauET_EB_total_[threshold]->Fill(pt);
} else {
h_efficiencyNonIsoTauET_EE_total_[threshold]->Fill(pt);
h_efficiencyIsoTauET_EE_total_[threshold]->Fill(pt);
}
h_efficiencyNonIsoTauET_EB_EE_total_[threshold]->Fill(pt);
h_efficiencyIsoTauET_EB_EE_total_[threshold]->Fill(pt);
if (l1tAboveCut) {
if (fabs(eta) < 1.5)
h_efficiencyNonIsoTauET_EB_pass_[threshold]->Fill(pt);
else
h_efficiencyNonIsoTauET_EE_pass_[threshold]->Fill(pt);
h_efficiencyNonIsoTauET_EB_EE_pass_[threshold]->Fill(pt);
if (tauL1tPairsIt->l1tIso() > 0.5) {
if (fabs(eta) < 1.5)
h_efficiencyIsoTauET_EB_pass_[threshold]->Fill(pt);
else
h_efficiencyIsoTauET_EE_pass_[threshold]->Fill(pt);
h_efficiencyIsoTauET_EB_EE_pass_[threshold]->Fill(pt);
}
}
}
}
} // loop over tau-L1 pairs
}
//
// -------------------------------------- endRun --------------------------------------------
//
//
// -------------------------------------- book histograms --------------------------------------------
//
void L1TTauOffline::bookTauHistos(DQMStore::IBooker& ibooker) {
ibooker.cd();
ibooker.setCurrentFolder(histFolder_);
dqmoffline::l1t::HistDefinition nVertexDef = histDefinitions_[PlotConfig::nVertex];
h_nVertex_ = ibooker.book1D(nVertexDef.name, nVertexDef.title, nVertexDef.nbinsX, nVertexDef.xmin, nVertexDef.xmax);
h_tagAndProbeMass_ = ibooker.book1D("tagAndProbeMass", "Invariant mass of tag & probe pair", 100, 40, 140);
dqmoffline::l1t::HistDefinition templateETvsET = histDefinitions_[PlotConfig::ETvsET];
h_L1TauETvsTauET_EB_ = ibooker.book2D("L1TauETvsTauET_EB",
"L1 Tau E_{T} vs PFTau E_{T} (EB); PFTau E_{T} (GeV); L1 Tau E_{T} (GeV)",
templateETvsET.nbinsX,
&templateETvsET.binsX[0],
templateETvsET.nbinsY,
&templateETvsET.binsY[0]);
h_L1TauETvsTauET_EE_ = ibooker.book2D("L1TauETvsTauET_EE",
"L1 Tau E_{T} vs PFTau E_{T} (EE); PFTau E_{T} (GeV); L1 Tau E_{T} (GeV)",
templateETvsET.nbinsX,
&templateETvsET.binsX[0],
templateETvsET.nbinsY,
&templateETvsET.binsY[0]);
h_L1TauETvsTauET_EB_EE_ = ibooker.book2D("L1TauETvsTauET_EB_EE",
"L1 Tau E_{T} vs PFTau E_{T} (EB+EE); PFTau E_{T} (GeV); L1 Tau E_{T} (GeV)",
templateETvsET.nbinsX,
&templateETvsET.binsX[0],
templateETvsET.nbinsY,
&templateETvsET.binsY[0]);
dqmoffline::l1t::HistDefinition templatePHIvsPHI = histDefinitions_[PlotConfig::PHIvsPHI];
h_L1TauPhivsTauPhi_EB_ =
ibooker.book2D("L1TauPhivsTauPhi_EB",
"#phi_{tau}^{L1} vs #phi_{tau}^{offline} (EB); #phi_{tau}^{offline}; #phi_{tau}^{L1}",
templatePHIvsPHI.nbinsX,
templatePHIvsPHI.xmin,
templatePHIvsPHI.xmax,
templatePHIvsPHI.nbinsY,
templatePHIvsPHI.ymin,
templatePHIvsPHI.ymax);
h_L1TauPhivsTauPhi_EE_ =
ibooker.book2D("L1TauPhivsTauPhi_EE",
"#phi_{tau}^{L1} vs #phi_{tau}^{offline} (EE); #phi_{tau}^{offline}; #phi_{tau}^{L1}",
templatePHIvsPHI.nbinsX,
templatePHIvsPHI.xmin,
templatePHIvsPHI.xmax,
templatePHIvsPHI.nbinsY,
templatePHIvsPHI.ymin,
templatePHIvsPHI.ymax);
h_L1TauPhivsTauPhi_EB_EE_ =
ibooker.book2D("L1TauPhivsTauPhi_EB_EE",
"#phi_{tau}^{L1} vs #phi_{tau}^{offline} (EB+EE); #phi_{tau}^{offline}; #phi_{tau}^{L1}",
templatePHIvsPHI.nbinsX,
templatePHIvsPHI.xmin,
templatePHIvsPHI.xmax,
templatePHIvsPHI.nbinsY,
templatePHIvsPHI.ymin,
templatePHIvsPHI.ymax);
h_L1TauEtavsTauEta_ =
ibooker.book2D("L1TauEtavsTauEta", "L1 Tau #eta vs PFTau #eta; PFTau #eta; L1 Tau #eta", 100, -3, 3, 100, -3, 3);
// tau resolutions
h_resolutionTauET_EB_ = ibooker.book1D(
"resolutionTauET_EB", "tau ET resolution (EB); (L1 Tau E_{T} - PFTau E_{T})/PFTau E_{T}; events", 50, -1, 1.5);
h_resolutionTauET_EE_ = ibooker.book1D(
"resolutionTauET_EE", "tau ET resolution (EE); (L1 Tau E_{T} - PFTau E_{T})/PFTau E_{T}; events", 50, -1, 1.5);
h_resolutionTauET_EB_EE_ =
ibooker.book1D("resolutionTauET_EB_EE",
"tau ET resolution (EB+EE); (L1 Tau E_{T} - PFTau E_{T})/PFTau E_{T}; events",
50,
-1,
1.5);
h_resolutionTauPhi_EB_ = ibooker.book1D("resolutionTauPhi_EB",
"#phi_{tau} resolution (EB); #phi_{tau}^{L1} - #phi_{tau}^{offline}; events",
120,
-0.3,
0.3);
h_resolutionTauPhi_EE_ = ibooker.book1D(
"resolutionTauPhi_EE", "tau #phi resolution (EE); #phi_{tau}^{L1} - #phi_{tau}^{offline}; events", 120, -0.3, 0.3);
h_resolutionTauPhi_EB_EE_ =
ibooker.book1D("resolutionTauPhi_EB_EE",
"tau #phi resolution (EB+EE); #phi_{tau}^{L1} - #phi_{tau}^{offline}; events",
120,
-0.3,
0.3);
h_resolutionTauEta_ =
ibooker.book1D("resolutionTauEta", "tau #eta resolution (EB); L1 Tau #eta - PFTau #eta; events", 120, -0.3, 0.3);
// tau turn-ons
ibooker.setCurrentFolder(efficiencyFolder_);
std::vector<float> tauBins(tauEfficiencyBins_.begin(), tauEfficiencyBins_.end());
int nBins = tauBins.size() - 1;
float* tauBinArray = &(tauBins[0]);
for (auto threshold : tauEfficiencyThresholds_) {
std::string str_threshold = std::to_string(int(threshold));
h_efficiencyIsoTauET_EB_pass_[threshold] =
ibooker.book1D("efficiencyIsoTauET_EB_threshold_" + str_threshold + "_Num",
"iso tau efficiency (EB); PFTau E_{T} (GeV); events",
nBins,
tauBinArray);
h_efficiencyIsoTauET_EE_pass_[threshold] =
ibooker.book1D("efficiencyIsoTauET_EE_threshold_" + str_threshold + "_Num",
"iso tau efficiency (EE); PFTau E_{T} (GeV); events",
nBins,
tauBinArray);
h_efficiencyIsoTauET_EB_EE_pass_[threshold] =
ibooker.book1D("efficiencyIsoTauET_EB_EE_threshold_" + str_threshold + "_Num",
"iso tau efficiency (EB+EE); PFTau E_{T} (GeV); events",
nBins,
tauBinArray);
h_efficiencyIsoTauET_EB_total_[threshold] =
ibooker.book1D("efficiencyIsoTauET_EB_threshold_" + str_threshold + "_Den",
"iso tau efficiency (EB); PFTau E_{T} (GeV); events",
nBins,
tauBinArray);
h_efficiencyIsoTauET_EE_total_[threshold] =
ibooker.book1D("efficiencyIsoTauET_EE_threshold_" + str_threshold + "_Den",
"iso tau efficiency (EE); PFTau E_{T} (GeV); events",
nBins,
tauBinArray);
h_efficiencyIsoTauET_EB_EE_total_[threshold] =
ibooker.book1D("efficiencyIsoTauET_EB_EE_threshold_" + str_threshold + "_Den",
"iso tau efficiency (EB+EE); PFTau E_{T} (GeV); events",
nBins,
tauBinArray);
// non iso
h_efficiencyNonIsoTauET_EB_pass_[threshold] =
ibooker.book1D("efficiencyNonIsoTauET_EB_threshold_" + str_threshold + "_Num",
"inclusive tau efficiency (EB); PFTau E_{T} (GeV); events",
nBins,
tauBinArray);
h_efficiencyNonIsoTauET_EE_pass_[threshold] =
ibooker.book1D("efficiencyNonIsoTauET_EE_threshold_" + str_threshold + "_Num",
"inclusive tau efficiency (EE); PFTau E_{T} (GeV); events",
nBins,
tauBinArray);
h_efficiencyNonIsoTauET_EB_EE_pass_[threshold] =
ibooker.book1D("efficiencyNonIsoTauET_EB_EE_threshold_" + str_threshold + "_Num",
"inclusive tau efficiency (EB+EE); PFTau E_{T} (GeV); events",
nBins,
tauBinArray);
h_efficiencyNonIsoTauET_EB_total_[threshold] =
ibooker.book1D("efficiencyNonIsoTauET_EB_threshold_" + str_threshold + "_Den",
"inclusive tau efficiency (EB); PFTau E_{T} (GeV); events",
nBins,
tauBinArray);
h_efficiencyNonIsoTauET_EE_total_[threshold] =
ibooker.book1D("efficiencyNonIsoTauET_EE_threshold_" + str_threshold + "_Den",
"inclusive tau efficiency (EE); PFTau E_{T} (GeV); events",
nBins,
tauBinArray);
h_efficiencyNonIsoTauET_EB_EE_total_[threshold] =
ibooker.book1D("efficiencyNonIsoTauET_EB_EE_threshold_" + str_threshold + "_Den",
"inclusive tau efficiency (EB+EE); PFTau E_{T} (GeV); events",
nBins,
tauBinArray);
}
ibooker.cd();
return;
}
const reco::Vertex L1TTauOffline::getPrimaryVertex(edm::Handle<reco::VertexCollection> const& vertex,
edm::Handle<reco::BeamSpot> const& beamSpot) {
reco::Vertex::Point posVtx;
reco::Vertex::Error errVtx;
bool hasPrimaryVertex = false;
if (vertex.isValid()) {
for (auto vertexIt = vertex->begin(); vertexIt != vertex->end(); ++vertexIt) {
if (vertexIt->isValid() && !vertexIt->isFake()) {
posVtx = vertexIt->position();
errVtx = vertexIt->error();
hasPrimaryVertex = true;
break;
}
}
}
if (!hasPrimaryVertex) {
posVtx = beamSpot->position();
errVtx(0, 0) = beamSpot->BeamWidthX();
errVtx(1, 1) = beamSpot->BeamWidthY();
errVtx(2, 2) = beamSpot->sigmaZ();
}
const reco::Vertex primaryVertex(posVtx, errVtx);
return primaryVertex;
}
bool L1TTauOffline::matchHlt(edm::Handle<trigger::TriggerEvent> const& triggerEvent, const reco::Muon* muon) {
double matchDeltaR = 9999;
trigger::TriggerObjectCollection trigObjs = triggerEvent->getObjects();
for (auto& trigIndex : m_trigIndices) {
const vector<string> moduleLabels(m_hltConfig.moduleLabels(trigIndex));
// V.M. 2023.03.08 Same issue as in the L1TMuonDQMOffline.cc - some modules are behind hltBoolEnd, but we want the last one before the "hltBoolEnd"
int moduleIndex = 999999;
for (int ii = moduleLabels.size() - 1; ii > 0; ii--) {
if (moduleLabels[ii] == "hltBoolEnd") {
moduleIndex = ii - 1;
break;
}
}
if (moduleIndex == 999999) {
edm::LogError("L1TMuonDQMOffline") << "Found no module label in trigger " << trigIndex;
continue;
}
const unsigned hltFilterIndex = triggerEvent->filterIndex(InputTag(moduleLabels[moduleIndex], "", trigProcess_));
if (hltFilterIndex < triggerEvent->sizeFilters()) {
const Keys triggerKeys(triggerEvent->filterKeys(hltFilterIndex));
const Vids triggerVids(triggerEvent->filterIds(hltFilterIndex));
const unsigned nTriggers = triggerVids.size();
for (size_t iTrig = 0; iTrig < nTriggers; ++iTrig) {
const TriggerObject trigObject = trigObjs[triggerKeys[iTrig]];
double dRtmp = deltaR((*muon), trigObject);
if (dRtmp < matchDeltaR)
matchDeltaR = dRtmp;
}
}
}
return (matchDeltaR < m_MaxHltTauDR);
}
void L1TTauOffline::getTauL1tPairs(edm::Handle<l1t::TauBxCollection> const& l1tCands) {
m_TauL1tPairs.clear();
vector<l1t::Tau> l1tContainer;
l1tContainer.reserve(l1tCands->size() + 1);
for (auto tau = l1tCands->begin(0); tau != l1tCands->end(0); ++tau) {
l1tContainer.push_back(*tau);
}
for (auto probeTauIt = m_ProbeTaus.begin(); probeTauIt != m_ProbeTaus.end(); ++probeTauIt) {
TauL1TPair pairBestCand((*probeTauIt), nullptr);
for (auto l1tIt = l1tContainer.begin(); l1tIt != l1tContainer.end(); ++l1tIt) {
TauL1TPair pairTmpCand((*probeTauIt), &(*l1tIt));
if (pairTmpCand.dR() < m_MaxL1tTauDR && pairTmpCand.l1tPt() > pairBestCand.l1tPt())
pairBestCand = pairTmpCand;
}
m_TauL1tPairs.push_back(pairBestCand);
}
}
void L1TTauOffline::getTightMuons(edm::Handle<reco::MuonCollection> const& muons,
edm::Handle<reco::PFMETCollection> const& mets,
const reco::Vertex& vertex,
edm::Handle<trigger::TriggerEvent> const& trigEvent) {
m_TightMuons.clear();
const reco::PFMET* pfmet = nullptr;
pfmet = &(mets->front());
int nb_mu = 0;
for (auto muonIt2 = muons->begin(); muonIt2 != muons->end(); ++muonIt2) {
if (fabs(muonIt2->eta()) < 2.4 && muonIt2->pt() > 10 && muon::isLooseMuon((*muonIt2)) &&
(muonIt2->pfIsolationR04().sumChargedHadronPt +
max(muonIt2->pfIsolationR04().sumNeutralHadronEt + muonIt2->pfIsolationR04().sumPhotonEt -
0.5 * muonIt2->pfIsolationR04().sumPUPt,
0.0)) /
muonIt2->pt() <
0.3) {
++nb_mu;
}
}
bool foundTightMu = false;
for (auto muonIt = muons->begin(); muonIt != muons->end(); ++muonIt) {
if (!matchHlt(trigEvent, &(*muonIt)))
continue;
float muiso = (muonIt->pfIsolationR04().sumChargedHadronPt +
max(muonIt->pfIsolationR04().sumNeutralHadronEt + muonIt->pfIsolationR04().sumPhotonEt -
0.5 * muonIt->pfIsolationR04().sumPUPt,
0.0)) /
muonIt->pt();
if (muiso < 0.1 && nb_mu < 2 && !foundTightMu && fabs(muonIt->eta()) < 2.1 && muonIt->pt() > 24 &&
muon::isLooseMuon((*muonIt))) {
float mt = sqrt(pow(muonIt->pt() + pfmet->pt(), 2) - pow(muonIt->px() + pfmet->px(), 2) -
pow(muonIt->py() + pfmet->py(), 2));
if (mt < 30) {
m_TightMuons.push_back(&(*muonIt));
foundTightMu = true;
}
}
}
}
void L1TTauOffline::getProbeTaus(const edm::Event& iEvent,
edm::Handle<reco::PFTauCollection> const& taus,
edm::Handle<reco::MuonCollection> const& muons,
const reco::Vertex& vertex) {
m_ProbeTaus.clear();
edm::Handle<reco::TauDiscriminatorContainer> antimu;
iEvent.getByToken(AntiMuInputTag_, antimu);
if (!antimu.isValid()) {
edm::LogWarning("L1TTauOffline") << "invalid collection: reco::PFTauDiscriminator anti-mu";
return;
}
edm::Handle<reco::PFTauDiscriminator> dmf;
iEvent.getByToken(DecayModeFindingInputTag_, dmf);
if (!dmf.isValid()) {
edm::LogWarning("L1TTauOffline") << "invalid collection: reco::PFTauDiscriminator decay mode finding input";
return;
}
m_AntiEleExists = true;
edm::Handle<reco::TauDiscriminatorContainer> antiele;
iEvent.getByToken(AntiEleInputTag_, antiele);
if (!antiele.isValid()) {
//V.M. 16.3.2023. Bypassing the return option for now, as the anti-ele discr. is not available.
m_AntiEleExists = false;
}
edm::Handle<reco::TauDiscriminatorContainer> comb3T;
iEvent.getByToken(comb3TInputTag_, comb3T);
if (!comb3T.isValid()) {
edm::LogWarning("L1TTauOffline") << "invalid collection: reco::PFTauDiscriminator comb3T";
return;
}
if (!m_TightMuons.empty()) {
TLorentzVector mymu;
mymu.SetPtEtaPhiE(m_TightMuons[0]->pt(), m_TightMuons[0]->eta(), m_TightMuons[0]->phi(), m_TightMuons[0]->energy());
int iTau = 0;
// load indices from input provenance config if process history changed, in particular for the first event
if (iEvent.processHistoryID() != phID_) {
phID_ = iEvent.processHistoryID();
{
const edm::Provenance* prov = antimu.provenance();
const std::vector<edm::ParameterSet> psetsFromProvenance =
edm::parameterSet(prov->stable(), iEvent.processHistory())
.getParameter<std::vector<edm::ParameterSet>>("IDWPdefinitions");
for (uint i = 0; i < psetsFromProvenance.size(); i++) {
if (psetsFromProvenance[i].getParameter<std::string>("IDname") == AntiMuWP_)
AntiMuWPIndex_ = i;
}
}
{
if (m_AntiEleExists) {
const edm::Provenance* prov = antiele.provenance();
const std::vector<std::string> psetsFromProvenance =
edm::parameterSet(prov->stable(), iEvent.processHistory())
.getParameter<std::vector<std::string>>("workingPoints");
for (unsigned int i = 0; i < psetsFromProvenance.size(); i++) {
if (psetsFromProvenance[i] == AntiEleWP_)
AntiEleWPIndex_ = i;
}
}
}
{
const edm::Provenance* prov = comb3T.provenance();
const std::vector<edm::ParameterSet> psetsFromProvenance =
edm::parameterSet(prov->stable(), iEvent.processHistory())
.getParameter<std::vector<edm::ParameterSet>>("IDWPdefinitions");
for (uint i = 0; i < psetsFromProvenance.size(); i++) {
if (psetsFromProvenance[i].getParameter<std::string>("IDname") == comb3TWP_)
comb3TWPIndex_ = i;
}
}
}
for (auto tauIt = taus->begin(); tauIt != taus->end(); ++tauIt, ++iTau) {
reco::PFTauRef tauCandidate(taus, iTau);
TLorentzVector mytau;
mytau.SetPtEtaPhiE(tauIt->pt(), tauIt->eta(), tauIt->phi(), tauIt->energy());
if ((*antimu)[tauCandidate].workingPoints.empty()) {
edm::LogWarning("L1TTauOffline") << "This offline tau has no antimu discriminator, skipping";
continue;
}
if (m_AntiEleExists) {
if ((*antiele)[tauCandidate].workingPoints.empty()) {
edm::LogWarning("L1TTauOffline") << "This offline tau has no antiele discriminator, skipping";
continue;
}
}
if ((*comb3T)[tauCandidate].workingPoints.empty()) {
edm::LogWarning("L1TTauOffline") << "This offline tau has no comb3T discriminator, skipping";
continue;
}
bool antiele_condition = true;
if (m_AntiEleExists)
antiele_condition = (*antiele)[tauCandidate].workingPoints[AntiEleWPIndex_];
if (fabs(tauIt->charge()) == 1 && fabs(tauIt->eta()) < 2.1 && tauIt->pt() > 20 &&
(*antimu)[tauCandidate].workingPoints[AntiMuWPIndex_] && antiele_condition && (*dmf)[tauCandidate] > 0.5 &&
(*comb3T)[tauCandidate].workingPoints[comb3TWPIndex_]) {
if (mymu.DeltaR(mytau) > 0.5 && (mymu + mytau).M() > 40 && (mymu + mytau).M() < 80 &&
m_TightMuons[0]->charge() * tauIt->charge() < 0) {
m_ProbeTaus.push_back(&(*tauIt));
}
}
}
}
}
void L1TTauOffline::normalise2DHistogramsToBinArea() {
std::vector<MonitorElement*> monElementstoNormalize = {h_L1TauETvsTauET_EB_,
h_L1TauETvsTauET_EE_,
h_L1TauETvsTauET_EB_EE_,
h_L1TauPhivsTauPhi_EB_,
h_L1TauPhivsTauPhi_EE_,
h_L1TauPhivsTauPhi_EB_EE_,
h_L1TauEtavsTauEta_};
for (auto mon : monElementstoNormalize) {
if (mon != nullptr) {
auto h = mon->getTH2F();
if (h != nullptr) {
h->Scale(1, "width");
}
}
}
}
// define this as a plug-in
DEFINE_FWK_MODULE(L1TTauOffline);
|