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
|
#ifndef DQMOFFLINE_TRIGGER_EGHLTDQMCUT
#define DQMOFFLINE_TRIGGER_EGHLTDQMCUT
//class: EgHLTDQMCut
//
//author: Sam Harper (June 2008)
//
//WARNING: interface is NOT final, please dont use this class for now without clearing it with me
// as I will change it and possibly break all your code
//
//aim: to allow the user to place a cut on the electron using it or the event
//
//implimentation:
#include "DQMOffline/Trigger/interface/EgHLTOffEvt.h"
#include "DQMOffline/Trigger/interface/EgHLTTrigCodes.h"
#include "DataFormats/Math/interface/deltaR.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
//this is a pure virtual struct which defines the interface to the cut objects
//it is also currently uncopyable
namespace egHLT {
template <class T>
struct EgHLTDQMCut {
private:
//disabling copy and assignment for all objects
EgHLTDQMCut& operator=(const EgHLTDQMCut& rhs) { return *this; }
protected:
//only derived classes can call the copy constructor (needed for clone...)
EgHLTDQMCut(const EgHLTDQMCut& rhs) = default;
public:
EgHLTDQMCut() = default;
virtual ~EgHLTDQMCut() = default;
virtual bool pass(const T& obj, const OffEvt& evt) const = 0;
virtual EgHLTDQMCut<T>* clone() const = 0; //caller owns the pointer
};
template <class T>
struct EgHLTDQMVarCut : public EgHLTDQMCut<T> {
private:
int cutsToPass_; //the cuts whose eff we are measuring
int (T::*cutCodeFunc_)() const;
public:
EgHLTDQMVarCut(int cutsToPass, int (T::*cutCodeFunc)() const)
: cutsToPass_(cutsToPass), cutCodeFunc_(cutCodeFunc) {}
~EgHLTDQMVarCut() override = default;
bool pass(const T& obj, const OffEvt& evt) const override;
EgHLTDQMCut<T>* clone() const override { return new EgHLTDQMVarCut(*this); } //default copy constructor is fine
};
//to understand this you need to know about
//1) templates
//2) inheritance (sort of)
//3) function pointers
//4) bitwise operations
//All it does is get the bitword corresponding to the cuts the electron failed and the mask the bits which correspond to cuts we dont care about and then see if any bits are still set
template <class T>
bool EgHLTDQMVarCut<T>::pass(const T& obj, const OffEvt& evt) const {
if (((obj.*cutCodeFunc_)() & cutsToPass_) == 0)
return true;
else
return false;
}
//now this is similar to EgHLTDQMVarCut except that it allows a key to specified to the cut code function
template <class T, class Key>
struct EgHLTDQMUserVarCut : public EgHLTDQMCut<T> {
private:
int (T::*cutCodeFunc_)(const Key&) const;
const Key key_;
int cutsNotToMask_;
public:
EgHLTDQMUserVarCut(int (T::*cutCodeFunc)(const Key&) const, const Key& key, int cutsNotToMask = ~0x0)
: cutCodeFunc_(cutCodeFunc), key_(key), cutsNotToMask_(cutsNotToMask) {}
~EgHLTDQMUserVarCut() override = default;
bool pass(const T& obj, const OffEvt& evt) const override;
EgHLTDQMCut<T>* clone() const override { return new EgHLTDQMUserVarCut(*this); } //default copy constructor is fine
};
template <class T, class Key>
bool EgHLTDQMUserVarCut<T, Key>::pass(const T& obj, const OffEvt& evt) const {
if (((obj.*cutCodeFunc_)(key_)&cutsNotToMask_) == 0)
return true;
else
return false;
}
template <class T, typename varType>
struct EgGreaterCut : public EgHLTDQMCut<T> {
private:
varType cutValue_;
varType (T::*varFunc_)() const;
public:
EgGreaterCut(varType cutValue, varType (T::*varFunc)() const) : cutValue_(cutValue), varFunc_(varFunc) {}
bool pass(const T& obj, const OffEvt& evt) const override { return (obj.*varFunc_)() > cutValue_; }
EgHLTDQMCut<T>* clone() const override { return new EgGreaterCut(*this); } //default copy constructor is fine
};
//this struct allows multiple cuts to be strung together
//now I could quite simply have a link to the next cut defined in the base class
//and the operator<< defined there also but I dont for the following reason
//1) I'm concerned about a circular chain of cuts (hence why you cant do a EgMultiCut << EgMultiCut)
//2) it requires all cuts to multi cut aware in the pass function
//in the future I may change it so this class isnt required
template <class T>
struct EgMultiCut : public EgHLTDQMCut<T> {
private:
std::vector<const EgHLTDQMCut<T>*> cuts_; //all the points to the cuts we own
public:
EgMultiCut() = default;
EgMultiCut(const EgMultiCut<T>& rhs);
~EgMultiCut() override {
for (size_t i = 0; i < cuts_.size(); i++)
delete cuts_[i];
}
//we own any cut given to use this way
EgMultiCut<T>& operator<<(const EgHLTDQMCut<T>* inputCut);
//basically an AND of all the cuts using short circuit evaluation, starting with the first cut
//if no cuts present, will default to true
bool pass(const T& obj, const OffEvt& evt) const override;
EgHLTDQMCut<T>* clone() const override { return new EgMultiCut(*this); }
};
template <class T>
EgMultiCut<T>::EgMultiCut(const EgMultiCut<T>& rhs) {
for (size_t cutNr = 0; cutNr < rhs.cuts_.size(); cutNr++) {
cuts_.push_back(rhs.cuts_[cutNr]->clone());
}
}
template <class T>
EgMultiCut<T>& EgMultiCut<T>::operator<<(const EgHLTDQMCut<T>* inputCut) {
if (typeid(*inputCut) == typeid(EgMultiCut)) {
edm::LogError("EgMultiCut") << " Error can not currently load an EgMultiCut inside a EgMultiCut, the practical "
"upshot is that the selection you think is being loaded isnt ";
} else if (inputCut == nullptr) {
edm::LogError("EgMultiCut") << "Error, cut being loaded is null, ignoring";
} else
cuts_.push_back(inputCut);
return *this;
}
template <class T>
bool EgMultiCut<T>::pass(const T& obj, const OffEvt& evt) const {
for (size_t i = 0; i < cuts_.size(); i++) {
if (!cuts_[i]->pass(obj, evt))
return false;
}
return true;
}
//pass in which bits you want the trigger to pass
//how this works
//1) you specify the trigger bits you want to pass
//2) you then specify whether you require all to be passed (AND) or just 1 (OR). It assumes OR by default
//3) optionally, you can then specify any trigger bits you want to ensure fail. If any of these trigger bits
// are passed (OR), then the cut fails, you can also specify only to fail if all are passed (AND)
template <class T>
struct EgObjTrigCut : public EgHLTDQMCut<T> {
public:
enum CutLogic { AND, OR };
private:
//currently fine for default copy construction
TrigCodes::TrigBitSet bitsToPass_;
CutLogic passLogic_;
TrigCodes::TrigBitSet bitsToFail_;
CutLogic failLogic_;
public:
EgObjTrigCut(TrigCodes::TrigBitSet bitsToPass,
CutLogic passLogic = OR,
TrigCodes::TrigBitSet bitsToFail = TrigCodes::TrigBitSet(),
CutLogic failLogic = AND)
: bitsToPass_(bitsToPass), passLogic_(passLogic), bitsToFail_(bitsToFail), failLogic_(failLogic) {}
~EgObjTrigCut() override = default;
bool pass(const T& obj, const OffEvt& evt) const override;
EgHLTDQMCut<T>* clone() const override { return new EgObjTrigCut(*this); }
};
template <class T>
bool EgObjTrigCut<T>::pass(const T& obj, const OffEvt& evt) const {
TrigCodes::TrigBitSet passMasked = bitsToPass_ & obj.trigBits();
TrigCodes::TrigBitSet failMasked = bitsToFail_ & obj.trigBits();
bool passResult = passLogic_ == AND ? passMasked == bitsToPass_ : passMasked != 0x0;
bool failResult = failLogic_ == AND ? failMasked == bitsToFail_ : failMasked != 0x0;
if (bitsToFail_ == 0x0)
failResult = false; //ensuring it has no effect if bits not specified
return passResult && !failResult;
}
//pass in which bits you want the trigger to pass
//can either specify to pass all of the bits (AND) or any of the bits (OR)
template <class T>
struct EgEvtTrigCut : public EgHLTDQMCut<T> {
public:
enum CutLogic { AND, OR };
private:
//currently default copy constructor is fine
TrigCodes::TrigBitSet bitsToPass_;
CutLogic passLogic_;
public:
EgEvtTrigCut(TrigCodes::TrigBitSet bitsToPass, CutLogic passLogic = OR)
: bitsToPass_(bitsToPass), passLogic_(passLogic) {}
~EgEvtTrigCut() = default;
bool pass(const T& obj, const OffEvt& evt) const;
EgHLTDQMCut<T>* clone() const { return new EgEvtTrigCut(*this); }
};
template <class T>
bool EgEvtTrigCut<T>::pass(const T& obj, const OffEvt& evt) const {
TrigCodes::TrigBitSet passMasked = bitsToPass_ & evt.evtTrigBits();
return passLogic_ == AND ? passMasked == bitsToPass_ : passMasked != 0x0;
}
//nots the cut, ie makes it return false instead of true
template <class T>
struct EgNotCut : public EgHLTDQMCut<T> {
private:
EgHLTDQMCut<T>* cut_; //we own it
public:
EgNotCut(EgHLTDQMCut<T>* cut) : cut_(cut) {}
EgNotCut(const EgNotCut<T>& rhs) : cut_(rhs.cut_->clone()) {}
~EgNotCut() { delete cut_; }
bool pass(const T& obj, const OffEvt& evt) const { return !cut_->pass(obj, evt); }
EgHLTDQMCut<T>* clone() const { return new EgNotCut(*this); }
};
//cut on the charge of the electron
template <class T>
struct ChargeCut : public EgHLTDQMCut<T> {
private:
int charge_;
public:
ChargeCut(int charge) : charge_(charge) {}
~ChargeCut() override = default;
bool pass(const T& obj, const OffEvt& evt) const override { return obj.charge() == charge_; }
EgHLTDQMCut<T>* clone() const override { return new ChargeCut(*this); }
};
//this askes if an object statifies the probe criteria and that another electron in the event statisfies the tag
//although templated, its hard to think of this working for anything else other then an electron
template <class T>
struct EgTagProbeCut : public EgHLTDQMCut<T> {
private:
int probeCutCode_;
int (T::*probeCutCodeFunc_)() const;
int tagCutCode_;
int (OffEle::*tagCutCodeFunc_)() const;
float minMass_;
float maxMass_;
public:
EgTagProbeCut(int probeCutCode,
int (T::*probeCutCodeFunc)() const,
int tagCutCode,
int (OffEle::*tagCutCodeFunc)() const,
float minMass = 81.,
float maxMass = 101.)
: probeCutCode_(probeCutCode),
probeCutCodeFunc_(probeCutCodeFunc),
tagCutCode_(tagCutCode),
tagCutCodeFunc_(tagCutCodeFunc),
minMass_(minMass),
maxMass_(maxMass) {}
~EgTagProbeCut() override = default;
bool pass(const T& obj, const OffEvt& evt) const override;
EgHLTDQMCut<T>* clone() const override { return new EgTagProbeCut(*this); }
};
template <class T>
bool EgTagProbeCut<T>::pass(const T& obj, const OffEvt& evt) const {
int nrTags = 0;
const OffEle* tagEle = nullptr;
const std::vector<OffEle>& eles = evt.eles();
//we are looking for an *additional* tag
for (const auto& ele : eles) {
if (((ele.*tagCutCodeFunc_)() & tagCutCode_) == 0x0) {
//now a check that the tag is not the same as the probe
if (reco::deltaR2(obj.eta(), obj.phi(), ele.eta(), ele.phi()) >
0.1 * 0.1) { //not in a cone of 0.1 of probe object
nrTags++;
tagEle = &ele;
}
}
}
if (nrTags ==
1) { //we are requiring one and only one additional tag (the obj is automatically excluded from the tag list)
if (((obj.*probeCutCodeFunc_)() & probeCutCode_) == 0x0) { //passes probe requirements, lets check the mass
float mass = (obj.p4() + tagEle->p4()).mag();
if (mass > minMass_ && mass < maxMass_)
return true; //mass requirements
}
}
return false;
}
template <class T>
struct EgJetTagProbeCut : public EgHLTDQMCut<T> {
private:
int probeCutCode_;
int (OffEle::*probeCutCodeFunc_)() const;
float minDPhi_;
float maxDPhi_;
public:
EgJetTagProbeCut(int probeCutCode, int (T::*probeCutCodeFunc)() const, float minDPhi = -M_PI, float maxDPhi = M_PI)
: probeCutCode_(probeCutCode), probeCutCodeFunc_(probeCutCodeFunc), minDPhi_(minDPhi), maxDPhi_(maxDPhi) {}
bool pass(const T& obj, const OffEvt& evt) const override;
EgHLTDQMCut<T>* clone() const override { return new EgJetTagProbeCut(*this); }
};
template <class T>
bool EgJetTagProbeCut<T>::pass(const T& obj, const OffEvt& evt) const {
int nrProbes = 0;
const std::vector<OffEle>& eles = evt.eles();
for (const auto& ele : eles) {
if (((ele.*probeCutCodeFunc_)() & probeCutCode_) == 0x0) {
nrProbes++;
}
}
bool b2bJet = false;
const std::vector<reco::CaloJet>& jets = evt.jets();
for (const auto& jet : jets) {
if (reco::deltaR2(obj.eta(), obj.phi(), jet.eta(), jet.phi()) >
0.1 * 0.1) { //not in a cone of 0.1 of probe object
float dPhi = reco::deltaPhi(obj.phi(), jet.phi());
if (dPhi > minDPhi_ && dPhi < maxDPhi_)
b2bJet = true;
}
}
return nrProbes == 1 && b2bJet;
}
template <class T>
struct EgJetB2BCut : public EgHLTDQMCut<T> {
private:
float minDPhi_;
float maxDPhi_;
float ptRelDiff_;
public:
EgJetB2BCut(float minDPhi = -M_PI, float maxDPhi = M_PI, float ptRelDiff = 999)
: minDPhi_(minDPhi), maxDPhi_(maxDPhi), ptRelDiff_(ptRelDiff) {}
bool pass(const T& obj, const OffEvt& evt) const;
EgHLTDQMCut<T>* clone() const { return new EgJetB2BCut(*this); }
};
template <class T>
bool EgJetB2BCut<T>::pass(const T& obj, const OffEvt& evt) const {
bool b2bJet = false;
const std::vector<reco::CaloJet>& jets = evt.jets();
for (const auto& jet : jets) {
if (reco::deltaR2(obj.eta(), obj.phi(), jet.eta(), jet.phi()) >
0.1 * 0.1) { //not in a cone of 0.1 of probe object
float dPhi = reco::deltaPhi(obj.phi(), jet.phi());
if (dPhi > minDPhi_ && dPhi < maxDPhi_ && fabs(1 - jet.pt() / obj.pt()) < ptRelDiff_)
b2bJet = true;
}
}
return b2bJet;
}
//requires the the passed in electron and another in the event passes the specified cuts
struct EgDiEleCut : public EgHLTDQMCut<OffEle> {
private:
int cutCode_;
int (OffEle::*cutCodeFunc_)() const;
public:
EgDiEleCut(int cutCode, int (OffEle::*cutCodeFunc)() const) : cutCode_(cutCode), cutCodeFunc_(cutCodeFunc) {}
bool pass(const OffEle& obj, const OffEvt& evt) const override;
EgHLTDQMCut<OffEle>* clone() const override { return new EgDiEleCut(*this); }
};
//requires the the passed in electron and another in the event passes the specified cuts
template <class Key>
struct EgDiEleUserCut : public EgHLTDQMCut<OffEle> {
private:
int (OffEle::*cutCodeFunc_)(const Key&) const;
const Key& key_;
int cutsNotToMask_;
public:
EgDiEleUserCut(int (OffEle::*cutCodeFunc)(const Key&) const, const Key& key, int cutsNotToMask = ~0x0)
: cutCodeFunc_(cutCodeFunc), key_(key), cutsNotToMask_(cutsNotToMask) {}
~EgDiEleUserCut() override = default;
bool pass(const OffEle& obj, const OffEvt& evt) const override;
EgHLTDQMCut<OffEle>* clone() const override {
return new EgDiEleUserCut(*this);
} //default copy constructor is fine
};
template <class Key>
bool EgDiEleUserCut<Key>::pass(const OffEle& obj, const OffEvt& evt) const {
const std::vector<OffEle>& eles = evt.eles();
for (const auto& ele : eles) {
if (&ele != &obj) { //different electrons
int diEleCutCode = (obj.*cutCodeFunc_)(key_) | (ele.*cutCodeFunc_)(key_);
if ((diEleCutCode & cutsNotToMask_) == 0x0)
return true;
}
}
return false;
}
//requires the the passed in photon and another in the event passes the specified cuts
struct EgDiPhoCut : public EgHLTDQMCut<OffPho> {
private:
int cutCode_;
int (OffPho::*cutCodeFunc_)() const;
public:
EgDiPhoCut(int cutCode, int (OffPho::*cutCodeFunc)() const) : cutCode_(cutCode), cutCodeFunc_(cutCodeFunc) {}
bool pass(const OffPho& obj, const OffEvt& evt) const override;
EgHLTDQMCut<OffPho>* clone() const override { return new EgDiPhoCut(*this); }
};
//requires passed photon and another in the event passes the specified cuts
template <class Key>
struct EgDiPhoUserCut : public EgHLTDQMCut<OffPho> {
private:
int (OffPho::*cutCodeFunc_)(const Key&) const;
const Key& key_;
int cutsNotToMask_;
public:
EgDiPhoUserCut(int (OffPho::*cutCodeFunc)(const Key&) const, const Key& key, int cutsNotToMask = ~0x0)
: cutCodeFunc_(cutCodeFunc), key_(key), cutsNotToMask_(cutsNotToMask) {}
~EgDiPhoUserCut() override = default;
bool pass(const OffPho& obj, const OffEvt& evt) const override;
EgHLTDQMCut<OffPho>* clone() const override {
return new EgDiPhoUserCut(*this);
} //default copy constructor is fine
};
template <class Key>
bool EgDiPhoUserCut<Key>::pass(const OffPho& obj, const OffEvt& evt) const {
const std::vector<OffPho>& phos = evt.phos();
for (const auto& pho : phos) {
if (&pho != &obj) { //different phoctrons
int diPhoCutCode = (obj.*cutCodeFunc_)(key_) | (pho.*cutCodeFunc_)(key_);
if ((diPhoCutCode & cutsNotToMask_) == 0x0)
return true;
}
}
return false;
}
//a trigger tag and probe cut
//basically we require the electron to pass some cuts
//and then do tag and probe on the trigger
//removing templates as it makes no sense
struct EgTrigTagProbeCut : public EgHLTDQMCut<OffEle> {
private:
TrigCodes::TrigBitSet bitsToPass_;
int cutCode_;
int (OffEle::*cutCodeFunc_)() const;
float minMass_;
float maxMass_;
public:
EgTrigTagProbeCut(TrigCodes::TrigBitSet bitsToPass,
int cutCode,
int (OffEle::*cutCodeFunc)() const,
float minMass = 81.,
float maxMass = 101.)
: bitsToPass_(bitsToPass), cutCode_(cutCode), cutCodeFunc_(cutCodeFunc), minMass_(minMass), maxMass_(maxMass) {}
~EgTrigTagProbeCut() override = default;
bool pass(const OffEle& ele, const OffEvt& evt) const override;
EgHLTDQMCut<OffEle>* clone() const override { return new EgTrigTagProbeCut(*this); }
};
//----Morse----
//new tag and probe cut
//require two wp80 electrons
struct EgTrigTagProbeCut_New : public EgHLTDQMCut<OffEle> {
private:
TrigCodes::TrigBitSet bit1ToPass_;
TrigCodes::TrigBitSet bit2ToPass_;
int cutCode_;
int (OffEle::*cutCodeFunc_)() const;
float minMass_;
float maxMass_;
public:
EgTrigTagProbeCut_New(TrigCodes::TrigBitSet bit1ToPass,
TrigCodes::TrigBitSet bit2ToPass,
int cutCode,
int (OffEle::*cutCodeFunc)() const,
float minMass = 81.,
float maxMass = 101.)
: bit1ToPass_(bit1ToPass),
bit2ToPass_(bit2ToPass),
cutCode_(cutCode),
cutCodeFunc_(cutCodeFunc),
minMass_(minMass),
maxMass_(maxMass) {}
~EgTrigTagProbeCut_New() override = default;
bool pass(const OffEle& ele, const OffEvt& evt) const override;
EgHLTDQMCut<OffEle>* clone() const override { return new EgTrigTagProbeCut_New(*this); }
};
//same for photons
struct EgTrigTagProbeCut_NewPho : public EgHLTDQMCut<OffPho> {
private:
TrigCodes::TrigBitSet bit1ToPass_;
TrigCodes::TrigBitSet bit2ToPass_;
int cutCode_;
int (OffPho::*cutCodeFunc_)() const;
float minMass_;
float maxMass_;
public:
EgTrigTagProbeCut_NewPho(TrigCodes::TrigBitSet bit1ToPass,
TrigCodes::TrigBitSet bit2ToPass,
int cutCode,
int (OffPho::*cutCodeFunc)() const,
float minMass = 81.,
float maxMass = 101.)
: bit1ToPass_(bit1ToPass),
bit2ToPass_(bit2ToPass),
cutCode_(cutCode),
cutCodeFunc_(cutCodeFunc),
minMass_(minMass),
maxMass_(maxMass) {}
~EgTrigTagProbeCut_NewPho() override = default;
bool pass(const OffPho& pho, const OffEvt& evt) const override;
EgHLTDQMCut<OffPho>* clone() const override { return new EgTrigTagProbeCut_NewPho(*this); }
};
} // namespace egHLT
#endif
|