-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMyAnalyzer_ZprimeAnalysis_DijetBBTag_2011.cc
More file actions
437 lines (355 loc) · 16.2 KB
/
Copy pathMyAnalyzer_ZprimeAnalysis_DijetBBTag_2011.cc
File metadata and controls
437 lines (355 loc) · 16.2 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
// -*- C++ -*-
//
// Package: MyAnalyzer
// Class: MyAnalyzer
//
/**\class MyAnalyzer MyAnalyzer.cc MyAnalysis/MyAnalyzer/src/MyAnalyzer.cc
Description: [one line class summary]
Implementation:
[Notes on implementation]
*/
//
// Original Author: Dinko Ferencek
// Created: Mon Sep 12 15:06:41 CDT 2011
// $Id: MyAnalyzer_ZprimeAnalysis_DijetBBTag_2011.cc,v 1.2 2011/12/15 02:16:55 ferencek Exp $
//
//
// system include files
#include <memory>
// user include files
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/EDFilter.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/LuminosityBlock.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Utilities/interface/InputTag.h"
#include "DataFormats/Common/interface/MergeableCounter.h"
// BaseClass
#include "MyAnalysis/MyAnalyzer/interface/BaseClass.h"
// TFileService
#include "FWCore/ServiceRegistry/interface/Service.h"
#include "CommonTools/UtilAlgos/interface/TFileService.h"
// ROOT
#include <TLorentzVector.h>
using namespace std;
//
// class declaration
//
class MyAnalyzer : public BaseClass, public edm::EDFilter {
public:
explicit MyAnalyzer(const edm::ParameterSet&);
~MyAnalyzer();
static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
private:
virtual void beginJob() ;
virtual bool filter(edm::Event&, const edm::EventSetup&);
virtual void endJob() ;
virtual bool beginRun(edm::Run&, edm::EventSetup const&);
virtual bool endRun(edm::Run&, edm::EventSetup const&);
virtual bool beginLuminosityBlock(edm::LuminosityBlock&, edm::EventSetup const&);
virtual bool endLuminosityBlock(edm::LuminosityBlock&, edm::EventSetup const&);
// ----------member data ---------------------------
int bQuark_0_counter, bQuark_st2_1_counter, bQuark_st2_0_bcHadron_2_counter, bQuark_st2_2_bcHadron_0_counter, bQuark_st2_0_st3_2_counter;
};
//
// constructors and destructor
//
MyAnalyzer::MyAnalyzer(const edm::ParameterSet& iConfig) :
BaseClass(iConfig)
{
//now do whatever initialization is needed
}
MyAnalyzer::~MyAnalyzer()
{
// do anything here that needs to be done at desctruction time
// (e.g. close files, deallocate resources etc.)
}
//
// constants, enums and typedefs
//
//
// static data member definitions
//
//
// member functions
//
// ------------ method called once each job just before starting event loop ------------
void
MyAnalyzer::beginJob()
{
//#####################################################################################
//########################### User's code starts here #################################/
// book your histograms here
CreateUserTH1D("h1_J1J2PartonFlavor;Parton Flavor (PDG ID);Entries", 51, -0.5, 50.5);
CreateUserTH1D("h1_minDeltaR_bQuark_status2;min#DeltaR;Entries", 100, 0., 10.);
CreateUserTH1D("h1_minDeltaR_bQuark_status3;min#DeltaR;Entries", 100, 0., 10.);
CreateUserTH1D("h1_minDeltaR_bQuark;min#DeltaR;Entries", 100, 0., 10.);
CreateUserTH1D("h1_minDeltaR_bHadron;min#DeltaR;Entries", 100, 0., 10.);
CreateUserTH1D("h1_minDeltaR_cHadron;min#DeltaR;Entries", 100, 0., 10.);
CreateUserTH1D("h1_minDeltaR_bcHadron;min#DeltaR;Entries", 100, 0., 10.);
// initialize your variables here
bQuark_0_counter = 0;
bQuark_st2_1_counter = 0;
bQuark_st2_0_bcHadron_2_counter = 0;
bQuark_st2_2_bcHadron_0_counter = 0;
bQuark_st2_0_st3_2_counter = 0;
//############################# User's code ends here #################################
//#####################################################################################
}
// ------------ method called when starting to processes a run ------------
bool
MyAnalyzer::beginRun(edm::Run& iRun, const edm::EventSetup& iSetup)
{
return true;
}
// ------------ method called when starting to processes a luminosity block ------------
bool
MyAnalyzer::beginLuminosityBlock(edm::LuminosityBlock&, edm::EventSetup const&)
{
return true;
}
// ------------ method called on each new Event ------------
bool
MyAnalyzer::filter(edm::Event& iEvent, const edm::EventSetup& iSetup)
{
bool ret = false;
// event weight (by default set to 1)
double eventWeight = 1;
//#####################################################################################
//########################### User's code starts here #################################
double matchingRadius = getPreCutValue1("matchingRadius");
int matchingType = int(getPreCutValue1("matchingType"));
int eventPrintout = int(getPreCutValue1("eventPrintout"));
// grab necessary objects from the event
edm::Handle<vector<unsigned int> > NPU;
iEvent.getByLabel(edm::InputTag("GenEventInfo:PileUpNumberOfInteractions"), NPU);
edm::Handle<vector<int> > BX;
iEvent.getByLabel(edm::InputTag("GenEventInfo:PileUpBunchCrossing"), BX);
edm::Handle<bool> passPrimaryVertex;
iEvent.getByLabel(edm::InputTag("EventSelection:PassPrimaryVertex"), passPrimaryVertex);
edm::Handle<bool> passBeamScraping;
iEvent.getByLabel(edm::InputTag("EventSelection:PassBeamScraping"), passBeamScraping);
edm::Handle<vector<double> > PFJetPt;
iEvent.getByLabel(edm::InputTag("AK7PFJets:Pt"), PFJetPt);
edm::Handle<vector<double> > PFJetEta;
iEvent.getByLabel(edm::InputTag("AK7PFJets:Eta"), PFJetEta);
edm::Handle<vector<double> > PFJetPhi;
iEvent.getByLabel(edm::InputTag("AK7PFJets:Phi"), PFJetPhi);
edm::Handle<vector<double> > PFJetE;
iEvent.getByLabel(edm::InputTag("AK7PFJets:Energy"), PFJetE);
edm::Handle<vector<int> > PFJetPassJetID;
iEvent.getByLabel(edm::InputTag("AK7PFJets:PassTightID"), PFJetPassJetID);
edm::Handle<vector<int> > PFJetPartonFlavor;
iEvent.getByLabel(edm::InputTag("AK7PFJets:PartonFlavor"), PFJetPartonFlavor);
edm::Handle<vector<double> > GenParticlePt;
iEvent.getByLabel(edm::InputTag("GenParticles:Pt"), GenParticlePt);
edm::Handle<vector<double> > GenParticleEta;
iEvent.getByLabel(edm::InputTag("GenParticles:Eta"), GenParticleEta);
edm::Handle<vector<double> > GenParticlePhi;
iEvent.getByLabel(edm::InputTag("GenParticles:Phi"), GenParticlePhi);
edm::Handle<vector<double> > GenParticleE;
iEvent.getByLabel(edm::InputTag("GenParticles:Energy"), GenParticleE);
edm::Handle<vector<int> > GenParticlePdgId;
iEvent.getByLabel(edm::InputTag("GenParticles:PdgId"), GenParticlePdgId);
edm::Handle<vector<int> > GenParticleStatus;
iEvent.getByLabel(edm::InputTag("GenParticles:Status"), GenParticleStatus);
int case1_counter = 0, case2_counter = 0, case3_counter = 0, case4_counter = 0, case5_counter = 0;
// Set the evaluation of the cuts to false and clear the variable values and filled status
resetCuts();
fillVariableWithValue("PassPrimaryVertex", ( *passPrimaryVertex ? 1 : 0 ), eventWeight );
fillVariableWithValue("PassBeamScraping", ( *passBeamScraping ? 1 : 0 ), eventWeight );
fillVariableWithValue( "nJets", PFJetPt->size(), eventWeight );
if( PFJetPt->size() >= 1 )
{
fillVariableWithValue( "passJetIdJ1", ( PFJetPassJetID->at(0) ? 1 : 0 ), eventWeight );
fillVariableWithValue( "absEtaJ1", fabs( PFJetEta->at(0) ), eventWeight );
}
if( PFJetPt->size() >= 2 )
{
fillVariableWithValue( "passJetIdJ2", ( PFJetPassJetID->at(1) ? 1 : 0 ), eventWeight );
fillVariableWithValue( "absEtaJ2", fabs( PFJetEta->at(1) ), eventWeight );
// calculate |DeltaEta(j1,j2)|
fillVariableWithValue( "absDeltaEtaJ1J2", fabs( PFJetEta->at(0) - PFJetEta->at(1) ), eventWeight );
int nJets_HeavyFlavor = 0;
TLorentzVector v_j, v_gp;
// loop over two leading jets
for(size_t i=0; i<2; ++i)
{
FillUserTH1D("h1_J1J2PartonFlavor", abs( PFJetPartonFlavor->at(i) ), eventWeight );
if( matchingType==0 && abs(PFJetPartonFlavor->at(i))==5)
++nJets_HeavyFlavor;
else if( matchingType!=0 )
{
double minDeltaR_bQuark_status2 = 999.;
double minDeltaR_bQuark_status3 = 999.;
double minDeltaR_bHadron = 999.;
double minDeltaR_cHadron = 999.;
// initialize jet 4-vector
v_j.SetPtEtaPhiE(PFJetPt->at(i),PFJetEta->at(i),PFJetPhi->at(i),PFJetE->at(i));
// loop over GenParticles
for(size_t j=0; j<GenParticlePt->size(); ++j)
{
if( GenParticlePt->at(j)==0 ) continue;
int pdgID = abs(GenParticlePdgId->at(j));
int status = abs(GenParticleStatus->at(j));
bool shouldBeMatched_bQuark_status2 = false;
bool shouldBeMatched_bQuark_status3 = false;
bool shouldBeMatched_bHadron = false;
bool shouldBeMatched_cHadron = false;
if( pdgID==5
&& status==2
) shouldBeMatched_bQuark_status2 = true;
if( pdgID==5
&& status==3
) shouldBeMatched_bQuark_status3 = true;
if( pdgID==511 || pdgID==521 || pdgID==531 || pdgID==541 || pdgID==5122 || pdgID==5132 || pdgID==5232 || pdgID==5332
) shouldBeMatched_bHadron = true;
if( pdgID==411 || pdgID==421 || pdgID==431 || pdgID==4122 || pdgID==4132 || pdgID==4232 || pdgID==4332
) shouldBeMatched_cHadron = true;
if( shouldBeMatched_bQuark_status2 )
{
v_gp.SetPtEtaPhiE(GenParticlePt->at(j),GenParticleEta->at(j),GenParticlePhi->at(j),GenParticleE->at(j));
double deltaR = v_j.DeltaR(v_gp);
if( deltaR < minDeltaR_bQuark_status2 ) minDeltaR_bQuark_status2 = deltaR;
}
if( shouldBeMatched_bQuark_status3 )
{
v_gp.SetPtEtaPhiE(GenParticlePt->at(j),GenParticleEta->at(j),GenParticlePhi->at(j),GenParticleE->at(j));
double deltaR = v_j.DeltaR(v_gp);
if( deltaR < minDeltaR_bQuark_status3 ) minDeltaR_bQuark_status3 = deltaR;
}
if( shouldBeMatched_bHadron )
{
v_gp.SetPtEtaPhiE(GenParticlePt->at(j),GenParticleEta->at(j),GenParticlePhi->at(j),GenParticleE->at(j));
double deltaR = v_j.DeltaR(v_gp);
if( deltaR < minDeltaR_bHadron ) minDeltaR_bHadron = deltaR;
}
if( shouldBeMatched_cHadron )
{
v_gp.SetPtEtaPhiE(GenParticlePt->at(j),GenParticleEta->at(j),GenParticlePhi->at(j),GenParticleE->at(j));
double deltaR = v_j.DeltaR(v_gp);
if( deltaR < minDeltaR_cHadron ) minDeltaR_cHadron = deltaR;
}
}
FillUserTH1D("h1_minDeltaR_bQuark_status2", minDeltaR_bQuark_status2, eventWeight);
FillUserTH1D("h1_minDeltaR_bQuark_status3", minDeltaR_bQuark_status3, eventWeight);
FillUserTH1D("h1_minDeltaR_bQuark", min(minDeltaR_bQuark_status2,minDeltaR_bQuark_status3), eventWeight);
FillUserTH1D("h1_minDeltaR_bHadron", minDeltaR_bHadron, eventWeight);
FillUserTH1D("h1_minDeltaR_cHadron", minDeltaR_cHadron, eventWeight);
FillUserTH1D("h1_minDeltaR_bcHadron", min(minDeltaR_bHadron,minDeltaR_cHadron), eventWeight);
if( minDeltaR_bQuark_status2 < matchingRadius ) ++case1_counter;
if( minDeltaR_bQuark_status3 < matchingRadius ) ++case2_counter;
if( minDeltaR_bQuark_status2 < matchingRadius || minDeltaR_bQuark_status3 < matchingRadius ) ++case3_counter;
if( minDeltaR_bHadron < matchingRadius ) ++case4_counter;
if( minDeltaR_bHadron < matchingRadius || minDeltaR_cHadron < matchingRadius ) ++case5_counter;
switch( matchingType )
{
case 1:
if( minDeltaR_bQuark_status2 < matchingRadius ) ++nJets_HeavyFlavor;
break;
case 2:
if( minDeltaR_bQuark_status3 < matchingRadius ) ++nJets_HeavyFlavor;
break;
case 3:
if( minDeltaR_bQuark_status2 < matchingRadius || minDeltaR_bQuark_status3 < matchingRadius ) ++nJets_HeavyFlavor;
break;
case 4:
if( minDeltaR_bHadron < matchingRadius ) ++nJets_HeavyFlavor;
break;
case 5:
if( minDeltaR_bHadron < matchingRadius || minDeltaR_cHadron < matchingRadius ) ++nJets_HeavyFlavor;
break;
}
}
}
fillVariableWithValue( "nJets_HeavyFlavor", nJets_HeavyFlavor, eventWeight );
}
// Evaluate cuts (but do not apply them)
evaluateCuts();
// select only those events that pass the full selection
if( passedCut("all") ) ret = true;
if( eventPrintout )
{
if( case3_counter==0 )
{
++bQuark_0_counter;
if( bQuark_0_counter<11 ) cout << ">> bQuark_0 --> Run:LS:Event = " << iEvent.id().run() << ":" << iEvent.luminosityBlock() << ":" << iEvent.id().event() << endl;
}
if( case1_counter==1 )
{
++bQuark_st2_1_counter;
if( bQuark_st2_1_counter<11 ) cout << ">> bQuark_st2_1 --> Run:LS:Event = " << iEvent.id().run() << ":" << iEvent.luminosityBlock() << ":" << iEvent.id().event() << endl;
}
if( case1_counter==0 && case5_counter==2 )
{
++bQuark_st2_0_bcHadron_2_counter;
if( bQuark_st2_0_bcHadron_2_counter<11 ) cout << ">> bQuark_st2_0_bcHadron_2 --> Run:LS:Event = " << iEvent.id().run() << ":" << iEvent.luminosityBlock() << ":" << iEvent.id().event() << endl;
}
if( case1_counter==2 && case5_counter==0 )
{
++bQuark_st2_2_bcHadron_0_counter;
if( bQuark_st2_2_bcHadron_0_counter<11 ) cout << ">> bQuark_st2_2_bcHadron_0 --> Run:LS:Event = " << iEvent.id().run() << ":" << iEvent.luminosityBlock() << ":" << iEvent.id().event() << endl;
}
if( case1_counter==0 && case2_counter==2 )
{
++bQuark_st2_0_st3_2_counter;
if( bQuark_st2_0_st3_2_counter<11 ) cout << ">> bQuark_st2_0_st3_2 --> Run:LS:Event = " << iEvent.id().run() << ":" << iEvent.luminosityBlock() << ":" << iEvent.id().event() << endl;
}
}
//############################# User's code ends here #################################
//#####################################################################################
// increment event counters
eventCountBeforeWeight++;
eventCount += eventWeight;
return ret;
}
// ------------ method called when ending the processing of a luminosity block ------------
bool
MyAnalyzer::endLuminosityBlock(edm::LuminosityBlock& iLumi, edm::EventSetup const& iSetup)
{
if ( skimWasMade_ )
{
edm::Handle<edm::MergeableCounter> eventCounter;
if (iLumi.getByLabel(eventCounterInputTag_, eventCounter) && eventCounter.isValid())
{
NEvtTotBeforeWeight_ += (double) eventCounter->value;
}
else
{
edm::LogError("MyAnalyzer::endLuminosityBlock") << "Can't get the product " << eventCounterInputTag_ <<". Please make sure the skimWasMade and eventCounterInputTag parameters were set correctly.";
exit(1);
}
}
return true;
}
// ------------ method called when ending the processing of a run ------------
bool
MyAnalyzer::endRun(edm::Run&, edm::EventSetup const&)
{
return true;
}
// ------------ method called once each job just after ending the event loop ------------
void
MyAnalyzer::endJob()
{
int eventPrintout = int(getPreCutValue1("eventPrintout"));
if( eventPrintout )
{
cout << ">> bQuark_0: " << bQuark_0_counter << " events in total" << endl
<< ">> bQuark_st2_1: " << bQuark_st2_1_counter << " events in total" << endl
<< ">> bQuark_st2_0_bcHadron_2: " << bQuark_st2_0_bcHadron_2_counter << " events in total" << endl
<< ">> bQuark_st2_2_bcHadron_0: " << bQuark_st2_2_bcHadron_0_counter << " events in total" << endl
<< ">> bQuark_st2_0_st3_2: " << bQuark_st2_0_st3_2_counter << " events in total" << endl;
}
}
// ------------ method fills 'descriptions' with the allowed parameters for the module ------------
void
MyAnalyzer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
//The following says we do not know what parameters are allowed so do no validation
// Please change this to state exactly what you do use, even if it is no parameters
edm::ParameterSetDescription desc;
desc.setUnknown();
descriptions.addDefault(desc);
}
DEFINE_FWK_MODULE(MyAnalyzer);