CMS 3D CMS Logo

AnalysisRootpleProducer.cc
Go to the documentation of this file.
1 // Authors: F. Ambroglini, L. Fano'
4 
5 using namespace edm;
6 using namespace std;
7 using namespace reco;
8 
9 class GreaterPt {
10 public:
11  bool operator()(const math::XYZTLorentzVector& a, const math::XYZTLorentzVector& b) { return a.pt() > b.pt(); }
12 };
13 
14 class GenJetSort {
15 public:
16  bool operator()(const GenJet& a, const GenJet& b) { return a.pt() > b.pt(); }
17 };
18 
19 class BasicJetSort {
20 public:
21  bool operator()(const BasicJet& a, const BasicJet& b) { return a.pt() > b.pt(); }
22 };
23 
24 class CaloJetSort {
25 public:
26  bool operator()(const CaloJet& a, const CaloJet& b) { return a.pt() > b.pt(); }
27 };
28 
30  AnalysisTree->Fill();
31 
32  NumberMCParticles = 0;
33  NumberTracks = 0;
34  NumberInclusiveJet = 0;
35  NumberChargedJet = 0;
36  NumberTracksJet = 0;
37  NumberCaloJet = 0;
38 }
39 
40 void AnalysisRootpleProducer::fillEventInfo(int e) { EventKind = e; }
41 
42 void AnalysisRootpleProducer::fillMCParticles(float p, float pt, float eta, float phi) {
43  MomentumMC[NumberMCParticles] = p;
44  TransverseMomentumMC[NumberMCParticles] = pt;
45  EtaMC[NumberMCParticles] = eta;
46  PhiMC[NumberMCParticles] = phi;
47  NumberMCParticles++;
48 }
49 
50 void AnalysisRootpleProducer::fillTracks(float p, float pt, float eta, float phi) {
51  MomentumTK[NumberTracks] = p;
52  TransverseMomentumTK[NumberTracks] = pt;
53  EtaTK[NumberTracks] = eta;
54  PhiTK[NumberTracks] = phi;
55  NumberTracks++;
56 }
57 
58 void AnalysisRootpleProducer::fillInclusiveJet(float p, float pt, float eta, float phi) {
59  MomentumIJ[NumberInclusiveJet] = p;
60  TransverseMomentumIJ[NumberInclusiveJet] = pt;
61  EtaIJ[NumberInclusiveJet] = eta;
62  PhiIJ[NumberInclusiveJet] = phi;
63  NumberInclusiveJet++;
64 }
65 
66 void AnalysisRootpleProducer::fillChargedJet(float p, float pt, float eta, float phi) {
67  MomentumCJ[NumberChargedJet] = p;
68  TransverseMomentumCJ[NumberChargedJet] = pt;
69  EtaCJ[NumberChargedJet] = eta;
70  PhiCJ[NumberChargedJet] = phi;
71  NumberChargedJet++;
72 }
73 
74 void AnalysisRootpleProducer::fillTracksJet(float p, float pt, float eta, float phi) {
75  MomentumTJ[NumberTracksJet] = p;
76  TransverseMomentumTJ[NumberTracksJet] = pt;
77  EtaTJ[NumberTracksJet] = eta;
78  PhiTJ[NumberTracksJet] = phi;
79  NumberTracksJet++;
80 }
81 
82 void AnalysisRootpleProducer::fillCaloJet(float p, float pt, float eta, float phi) {
83  MomentumEHJ[NumberCaloJet] = p;
84  TransverseMomentumEHJ[NumberCaloJet] = pt;
85  EtaEHJ[NumberCaloJet] = eta;
86  PhiEHJ[NumberCaloJet] = phi;
87  NumberCaloJet++;
88 }
89 
91  // flag to ignore gen-level analysis
92  onlyRECO = pset.getUntrackedParameter<bool>("OnlyRECO", false);
93 
94  // particle, track and jet collections
95  mcEventToken = mayConsume<edm::HepMCProduct>(pset.getUntrackedParameter<InputTag>("MCEvent", std::string("")));
96  genJetCollToken =
97  mayConsume<reco::GenJetCollection>(pset.getUntrackedParameter<InputTag>("GenJetCollectionName", std::string("")));
98  chgJetCollToken = mayConsume<reco::GenJetCollection>(
99  pset.getUntrackedParameter<InputTag>("ChgGenJetCollectionName", std::string("")));
100  tracksJetCollToken = consumes<reco::BasicJetCollection>(
101  pset.getUntrackedParameter<InputTag>("TracksJetCollectionName", std::string("")));
102  recoCaloJetCollToken = consumes<reco::CaloJetCollection>(
103  pset.getUntrackedParameter<InputTag>("RecoCaloJetCollectionName", std::string("")));
104  chgGenPartCollToken = mayConsume<std::vector<reco::GenParticle> >(
105  pset.getUntrackedParameter<InputTag>("ChgGenPartCollectionName", std::string("")));
106  tracksCollToken = consumes<reco::CandidateCollection>(
107  pset.getUntrackedParameter<InputTag>("TracksCollectionName", std::string("")));
108 
109  // trigger results
110  triggerResultsToken = consumes<edm::TriggerResults>(pset.getParameter<InputTag>("triggerResults"));
111  // hltFilterTag = pset.getParameter<InputTag>("hltFilter");
112  // triggerName = pset.getParameter<InputTag>("triggerName");
113 
114  piG = acos(-1.);
115  NumberMCParticles = 0;
116  NumberTracks = 0;
117  NumberInclusiveJet = 0;
118  NumberChargedJet = 0;
119  NumberTracksJet = 0;
120  NumberCaloJet = 0;
121 }
122 
124  // use TFileService for output to root file
125  AnalysisTree = fs->make<TTree>("AnalysisTree", "MBUE Analysis Tree ");
126 
127  AnalysisTree->Branch("EventKind", &EventKind, "EventKind/I");
128 
129  // store p, pt, eta, phi for particles and jets
130 
131  // GenParticles at hadron level
132  AnalysisTree->Branch("NumberMCParticles", &NumberMCParticles, "NumberMCParticles/I");
133  AnalysisTree->Branch("MomentumMC", MomentumMC, "MomentumMC[NumberMCParticles]/F");
134  AnalysisTree->Branch("TransverseMomentumMC", TransverseMomentumMC, "TransverseMomentumMC[NumberMCParticles]/F");
135  AnalysisTree->Branch("EtaMC", EtaMC, "EtaMC[NumberMCParticles]/F");
136  AnalysisTree->Branch("PhiMC", PhiMC, "PhiMC[NumberMCParticles]/F");
137 
138  // tracks
139  AnalysisTree->Branch("NumberTracks", &NumberTracks, "NumberTracks/I");
140  AnalysisTree->Branch("MomentumTK", MomentumTK, "MomentumTK[NumberTracks]/F");
141  AnalysisTree->Branch("TrasverseMomentumTK", TransverseMomentumTK, "TransverseMomentumTK[NumberTracks]/F");
142  AnalysisTree->Branch("EtaTK", EtaTK, "EtaTK[NumberTracks]/F");
143  AnalysisTree->Branch("PhiTK", PhiTK, "PhiTK[NumberTracks]/F");
144 
145  // GenJets
146  AnalysisTree->Branch("NumberInclusiveJet", &NumberInclusiveJet, "NumberInclusiveJet/I");
147  AnalysisTree->Branch("MomentumIJ", MomentumIJ, "MomentumIJ[NumberInclusiveJet]/F");
148  AnalysisTree->Branch("TrasverseMomentumIJ", TransverseMomentumIJ, "TransverseMomentumIJ[NumberInclusiveJet]/F");
149  AnalysisTree->Branch("EtaIJ", EtaIJ, "EtaIJ[NumberInclusiveJet]/F");
150  AnalysisTree->Branch("PhiIJ", PhiIJ, "PhiIJ[NumberInclusiveJet]/F");
151 
152  // jets from charged GenParticles
153  AnalysisTree->Branch("NumberChargedJet", &NumberChargedJet, "NumberChargedJet/I");
154  AnalysisTree->Branch("MomentumCJ", MomentumCJ, "MomentumCJ[NumberChargedJet]/F");
155  AnalysisTree->Branch("TrasverseMomentumCJ", TransverseMomentumCJ, "TransverseMomentumCJ[NumberChargedJet]/F");
156  AnalysisTree->Branch("EtaCJ", EtaCJ, "EtaCJ[NumberChargedJet]/F");
157  AnalysisTree->Branch("PhiCJ", PhiCJ, "PhiCJ[NumberChargedJet]/F");
158 
159  // jets from tracks
160  AnalysisTree->Branch("NumberTracksJet", &NumberTracksJet, "NumberTracksJet/I");
161  AnalysisTree->Branch("MomentumTJ", MomentumTJ, "MomentumTJ[NumberTracksJet]/F");
162  AnalysisTree->Branch("TrasverseMomentumTJ", TransverseMomentumTJ, "TransverseMomentumTJ[NumberTracksJet]/F");
163  AnalysisTree->Branch("EtaTJ", EtaTJ, "EtaTJ[NumberTracksJet]/F");
164  AnalysisTree->Branch("PhiTJ", PhiTJ, "PhiTJ[NumberTracksJet]/F");
165 
166  // jets from calorimeter towers
167  AnalysisTree->Branch("NumberCaloJet", &NumberCaloJet, "NumberCaloJet/I");
168  AnalysisTree->Branch("MomentumEHJ", MomentumEHJ, "MomentumEHJ[NumberCaloJet]/F");
169  AnalysisTree->Branch("TrasverseMomentumEHJ", TransverseMomentumEHJ, "TransverseMomentumEHJ[NumberCaloJet]/F");
170  AnalysisTree->Branch("EtaEHJ", EtaEHJ, "EtaEHJ[NumberCaloJet]/F");
171  AnalysisTree->Branch("PhiEHJ", PhiEHJ, "PhiEHJ[NumberCaloJet]/F");
172 
173  // alternative storage method:
174  // save TClonesArrays of TLorentzVectors
175  // i.e. store 4-vectors of particles and jets
176 
177  MonteCarlo = new TClonesArray("TLorentzVector", 10000);
178  AnalysisTree->Branch("MonteCarlo", "TClonesArray", &MonteCarlo, 128000, 0);
179 
180  Track = new TClonesArray("TLorentzVector", 10000);
181  AnalysisTree->Branch("Track", "TClonesArray", &Track, 128000, 0);
182 
183  InclusiveJet = new TClonesArray("TLorentzVector", 10000);
184  AnalysisTree->Branch("InclusiveJet", "TClonesArray", &InclusiveJet, 128000, 0);
185 
186  ChargedJet = new TClonesArray("TLorentzVector", 10000);
187  AnalysisTree->Branch("ChargedJet", "TClonesArray", &ChargedJet, 128000, 0);
188 
189  TracksJet = new TClonesArray("TLorentzVector", 10000);
190  AnalysisTree->Branch("TracksJet", "TClonesArray", &TracksJet, 128000, 0);
191 
192  CalorimeterJet = new TClonesArray("TLorentzVector", 10000);
193  AnalysisTree->Branch("CalorimeterJet", "TClonesArray", &CalorimeterJet, 128000, 0);
194 
195  acceptedTriggers = new TClonesArray("TObjString", 10000);
196  AnalysisTree->Branch("acceptedTriggers", "TClonesArray", &acceptedTriggers, 128000, 0);
197 }
198 
200  e.getByToken(triggerResultsToken, triggerResults);
201  const edm::TriggerNames& triggerNames = e.triggerNames(*triggerResults);
202 
203  acceptedTriggers->Clear();
204  unsigned int iAcceptedTriggers(0);
205  if (triggerResults.product()->wasrun()) {
206  //cout << "at least one path out of " << triggerResults.product()->size() << " ran? " << triggerResults.product()->wasrun() << endl;
207 
208  if (triggerResults.product()->accept()) {
209  //cout << endl << "at least one path accepted? " << triggerResults.product()->accept() << endl;
210 
211  const unsigned int n_TriggerResults(triggerResults.product()->size());
212  for (unsigned int itrig(0); itrig < n_TriggerResults; ++itrig) {
213  if (triggerResults.product()->accept(itrig)) {
214  //cout << "path " << triggerNames.triggerName( itrig );
215  //cout << ", module index " << triggerResults.product()->index( itrig );
216  //cout << ", state (Ready = 0, Pass = 1, Fail = 2, Exception = 3) " << triggerResults.product()->state( itrig );
217  //cout << ", accept " << triggerResults.product()->accept( itrig );
218  //cout << endl;
219 
220  // save name of accepted trigger path
221  new ((*acceptedTriggers)[iAcceptedTriggers]) TObjString((triggerNames.triggerName(itrig)).c_str());
222  ++iAcceptedTriggers;
223  }
224  }
225  }
226  }
227 
228  // gen level analysis
229  // skipped, if onlyRECO flag set to true
230 
231  if (!onlyRECO) {
232  e.getByToken(mcEventToken, EvtHandle);
233  e.getByToken(chgGenPartCollToken, CandHandleMC);
234  e.getByToken(chgJetCollToken, ChgGenJetsHandle);
235  e.getByToken(genJetCollToken, GenJetsHandle);
236 
237  const HepMC::GenEvent* Evt = EvtHandle->GetEvent();
238 
239  EventKind = Evt->signal_process_id();
240 
241  std::vector<math::XYZTLorentzVector> GenPart;
242  std::vector<GenJet> ChgGenJetContainer;
243  std::vector<GenJet> GenJetContainer;
244 
245  GenPart.clear();
246  ChgGenJetContainer.clear();
247  GenJetContainer.clear();
248  MonteCarlo->Clear();
249  InclusiveJet->Clear();
250  ChargedJet->Clear();
251 
252  // jets from charged particles at hadron level
253  if (!ChgGenJetsHandle->empty()) {
254  for (GenJetCollection::const_iterator it(ChgGenJetsHandle->begin()), itEnd(ChgGenJetsHandle->end()); it != itEnd;
255  ++it) {
256  ChgGenJetContainer.push_back(*it);
257  }
258 
259  std::stable_sort(ChgGenJetContainer.begin(), ChgGenJetContainer.end(), GenJetSort());
260 
261  std::vector<GenJet>::const_iterator it(ChgGenJetContainer.begin()), itEnd(ChgGenJetContainer.end());
262  for (int iChargedJet(0); it != itEnd; ++it, ++iChargedJet) {
263  fillChargedJet(it->p(), it->pt(), it->eta(), it->phi());
264  new ((*ChargedJet)[iChargedJet]) TLorentzVector(it->px(), it->py(), it->pz(), it->energy());
265  }
266  }
267 
268  // GenJets
269  if (!GenJetsHandle->empty()) {
270  for (GenJetCollection::const_iterator it(GenJetsHandle->begin()), itEnd(GenJetsHandle->end()); it != itEnd;
271  ++it) {
272  GenJetContainer.push_back(*it);
273  }
274 
275  std::stable_sort(GenJetContainer.begin(), GenJetContainer.end(), GenJetSort());
276 
277  std::vector<GenJet>::const_iterator it(GenJetContainer.begin()), itEnd(GenJetContainer.end());
278  for (int iInclusiveJet(0); it != itEnd; ++it, ++iInclusiveJet) {
279  fillInclusiveJet(it->p(), it->pt(), it->eta(), it->phi());
280  new ((*InclusiveJet)[iInclusiveJet]) TLorentzVector(it->px(), it->py(), it->pz(), it->energy());
281  }
282  }
283 
284  // hadron level particles
285  if (!CandHandleMC->empty()) {
286  for (vector<GenParticle>::const_iterator it(CandHandleMC->begin()), itEnd(CandHandleMC->end()); it != itEnd;
287  it++) {
288  GenPart.push_back(it->p4());
289  }
290 
291  std::stable_sort(GenPart.begin(), GenPart.end(), GreaterPt());
292 
293  std::vector<math::XYZTLorentzVector>::const_iterator it(GenPart.begin()), itEnd(GenPart.end());
294  for (int iMonteCarlo(0); it != itEnd; ++it, ++iMonteCarlo) {
295  fillMCParticles(it->P(), it->Pt(), it->Eta(), it->Phi());
296  new ((*MonteCarlo)[iMonteCarlo]) TLorentzVector(it->Px(), it->Py(), it->Pz(), it->E());
297  }
298  }
299  }
300 
301  // reco level analysis
302 
303  e.getByToken(tracksCollToken, CandHandleRECO);
304  e.getByToken(recoCaloJetCollToken, RecoCaloJetsHandle);
305  e.getByToken(tracksJetCollToken, TracksJetsHandle);
306 
307  std::vector<math::XYZTLorentzVector> Tracks;
308  std::vector<BasicJet> TracksJetContainer;
309  std::vector<CaloJet> RecoCaloJetContainer;
310 
311  Tracks.clear();
312  TracksJetContainer.clear();
313  RecoCaloJetContainer.clear();
314 
315  Track->Clear();
316  TracksJet->Clear();
317  CalorimeterJet->Clear();
318 
319  if (!RecoCaloJetsHandle->empty()) {
320  for (CaloJetCollection::const_iterator it(RecoCaloJetsHandle->begin()), itEnd(RecoCaloJetsHandle->end());
321  it != itEnd;
322  ++it) {
323  RecoCaloJetContainer.push_back(*it);
324  }
325  std::stable_sort(RecoCaloJetContainer.begin(), RecoCaloJetContainer.end(), CaloJetSort());
326 
327  std::vector<CaloJet>::const_iterator it(RecoCaloJetContainer.begin()), itEnd(RecoCaloJetContainer.end());
328  for (int iCalorimeterJet(0); it != itEnd; ++it, ++iCalorimeterJet) {
329  fillCaloJet(it->p(), it->pt(), it->eta(), it->phi());
330  new ((*CalorimeterJet)[iCalorimeterJet]) TLorentzVector(it->px(), it->py(), it->pz(), it->energy());
331  }
332  }
333 
334  if (!TracksJetsHandle->empty()) {
335  for (BasicJetCollection::const_iterator it(TracksJetsHandle->begin()), itEnd(TracksJetsHandle->end()); it != itEnd;
336  ++it) {
337  TracksJetContainer.push_back(*it);
338  }
339  std::stable_sort(TracksJetContainer.begin(), TracksJetContainer.end(), BasicJetSort());
340 
341  std::vector<BasicJet>::const_iterator it(TracksJetContainer.begin()), itEnd(TracksJetContainer.end());
342  for (int iTracksJet(0); it != itEnd; ++it, ++iTracksJet) {
343  fillTracksJet(it->p(), it->pt(), it->eta(), it->phi());
344  new ((*TracksJet)[iTracksJet]) TLorentzVector(it->px(), it->py(), it->pz(), it->energy());
345  }
346  }
347 
348  if (!CandHandleRECO->empty()) {
349  for (CandidateCollection::const_iterator it(CandHandleRECO->begin()), itEnd(CandHandleRECO->end()); it != itEnd;
350  ++it) {
351  Tracks.push_back(it->p4());
352  }
353  std::stable_sort(Tracks.begin(), Tracks.end(), GreaterPt());
354 
355  std::vector<math::XYZTLorentzVector>::const_iterator it(Tracks.begin()), itEnd(Tracks.end());
356  for (int iTracks(0); it != itEnd; ++it, ++iTracks) {
357  fillTracks(it->P(), it->Pt(), it->Eta(), it->Phi());
358  new ((*Track)[iTracks]) TLorentzVector(it->Px(), it->Py(), it->Pz(), it->E());
359  }
360  }
361 
362  store();
363 }
364 
reco::CaloJet
Jets made from CaloTowers.
Definition: CaloJet.h:27
reco::GenJet
Jets made from MC generator particles.
Definition: GenJet.h:23
AnalysisRootpleProducer::fillMCParticles
void fillMCParticles(float, float, float, float)
Definition: AnalysisRootpleProducer.cc:42
BasicJetSort
Definition: AnalysisRootpleProducer.cc:19
AnalysisRootpleProducer::endJob
void endJob() override
Definition: AnalysisRootpleProducer.cc:365
DiDispStaMuonMonitor_cfi.pt
pt
Definition: DiDispStaMuonMonitor_cfi.py:39
GreaterPt::operator()
bool operator()(const math::XYZTLorentzVector &a, const math::XYZTLorentzVector &b)
Definition: AnalysisRootpleProducer.cc:11
AnalysisRootpleProducer::fillInclusiveJet
void fillInclusiveJet(float, float, float, float)
Definition: AnalysisRootpleProducer.cc:58
edm
HLT enums.
Definition: AlignableModifier.h:19
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
AnalysisRootpleProducer::fillChargedJet
void fillChargedJet(float, float, float, float)
Definition: AnalysisRootpleProducer.cc:66
AnalysisRootpleProducer::fillTracksJet
void fillTracksJet(float, float, float, float)
Definition: AnalysisRootpleProducer.cc:74
GenJetSort::operator()
bool operator()(const GenJet &a, const GenJet &b)
Definition: AnalysisRootpleProducer.cc:16
BasicJetSort::operator()
bool operator()(const BasicJet &a, const BasicJet &b)
Definition: AnalysisRootpleProducer.cc:21
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
HepMC::GenEvent
Definition: hepmc_rootio.cc:9
CaloJetSort::operator()
bool operator()(const CaloJet &a, const CaloJet &b)
Definition: AnalysisRootpleProducer.cc:26
RecoMET_Cosmics_cff.fillTracks
fillTracks
Definition: RecoMET_Cosmics_cff.py:7
AnalysisRootpleProducer::store
void store()
Definition: AnalysisRootpleProducer.cc:29
reco::BasicJet
Jets made from CaloTowers.
Definition: BasicJet.h:19
L1TEGammaOffline_cfi.triggerNames
triggerNames
Definition: L1TEGammaOffline_cfi.py:40
PVValHelper::eta
Definition: PVValidationHelpers.h:69
reco::Track
Definition: Track.h:27
nanoDQM_cfi.GenPart
GenPart
Definition: nanoDQM_cfi.py:289
b
double b
Definition: hdecay.h:118
edm::OwnVector::const_iterator
Definition: OwnVector.h:41
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::ParameterSet
Definition: ParameterSet.h:47
a
double a
Definition: hdecay.h:119
TriggerNames.h
gather_cfg.Tracks
Tracks
Definition: gather_cfg.py:251
CaloJetSort
Definition: AnalysisRootpleProducer.cc:24
GreaterPt
Definition: AnalysisRootpleProducer.cc:9
edm::EventSetup
Definition: EventSetup.h:57
HLT_FULL_cff.MonteCarlo
MonteCarlo
Definition: HLT_FULL_cff.py:4990
AnalysisRootpleProducer::fillEventInfo
void fillEventInfo(int)
Definition: AnalysisRootpleProducer.cc:40
AnalysisRootpleProducer::fillCaloJet
void fillCaloJet(float, float, float, float)
Definition: AnalysisRootpleProducer.cc:82
std
Definition: JetResolutionObject.h:76
math::XYZTLorentzVector
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
edm::TriggerNames
Definition: TriggerNames.h:55
edm::triggerResults
static const std::string triggerResults("TriggerResults")
AnalysisRootpleProducer::analyze
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: AnalysisRootpleProducer.cc:199
AnalysisRootpleProducer::AnalysisRootpleProducer
AnalysisRootpleProducer(const edm::ParameterSet &)
Definition: AnalysisRootpleProducer.cc:90
AnalysisRootpleProducer::beginJob
void beginJob() override
Definition: AnalysisRootpleProducer.cc:123
GenJetSort
Definition: AnalysisRootpleProducer.cc:14
AnalysisRootpleProducer::fillTracks
void fillTracks(float, float, float, float)
Definition: AnalysisRootpleProducer.cc:50
edm::Event
Definition: Event.h:73
edm::InputTag
Definition: InputTag.h:15
HigPhotonJetHLTOfflineSource_cfi.triggerResultsToken
triggerResultsToken
Definition: HigPhotonJetHLTOfflineSource_cfi.py:33
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
AnalysisRootpleProducer.h