CMS 3D CMS Logo

AnalysisRootpleProducerOnlyMC.cc
Go to the documentation of this file.
1 // Authors: F. Ambroglini, L. Fano'
3 
4 using namespace edm;
5 using namespace std;
6 using namespace reco;
7 
8 class GreaterPt {
9 public:
10  bool operator()(const math::XYZTLorentzVector& a, const math::XYZTLorentzVector& b) { return a.pt() > b.pt(); }
11 };
12 
13 class GenJetSort {
14 public:
15  bool operator()(const GenJet& a, const GenJet& b) { return a.pt() > b.pt(); }
16 };
17 
19  AnalysisTree->Fill();
20 
21  NumberMCParticles = 0;
22  NumberInclusiveJet = 0;
23  NumberChargedJet = 0;
24 }
25 
27 
28 void AnalysisRootpleProducerOnlyMC::fillMCParticles(float p, float pt, float eta, float phi) {
29  MomentumMC[NumberMCParticles] = p;
30  TransverseMomentumMC[NumberMCParticles] = pt;
31  EtaMC[NumberMCParticles] = eta;
32  PhiMC[NumberMCParticles] = phi;
33  NumberMCParticles++;
34 }
35 
36 void AnalysisRootpleProducerOnlyMC::fillInclusiveJet(float p, float pt, float eta, float phi) {
37  MomentumIJ[NumberInclusiveJet] = p;
38  TransverseMomentumIJ[NumberInclusiveJet] = pt;
39  EtaIJ[NumberInclusiveJet] = eta;
40  PhiIJ[NumberInclusiveJet] = phi;
41  NumberInclusiveJet++;
42 }
43 
44 void AnalysisRootpleProducerOnlyMC::fillChargedJet(float p, float pt, float eta, float phi) {
45  MomentumCJ[NumberChargedJet] = p;
46  TransverseMomentumCJ[NumberChargedJet] = pt;
47  EtaCJ[NumberChargedJet] = eta;
48  PhiCJ[NumberChargedJet] = phi;
49  NumberChargedJet++;
50 }
51 
53  mcEventToken = consumes<edm::HepMCProduct>(pset.getUntrackedParameter<InputTag>("MCEvent", std::string("")));
54  genJetCollToken =
55  consumes<reco::GenJetCollection>(pset.getUntrackedParameter<InputTag>("GenJetCollectionName", std::string("")));
56  chgJetCollToken = consumes<reco::GenJetCollection>(
57  pset.getUntrackedParameter<InputTag>("ChgGenJetCollectionName", std::string("")));
58  chgGenPartCollToken = consumes<std::vector<reco::GenParticle> >(
59  pset.getUntrackedParameter<InputTag>("ChgGenPartCollectionName", std::string("")));
60 
61  piG = acos(-1.);
62  NumberMCParticles = 0;
63  NumberInclusiveJet = 0;
64  NumberChargedJet = 0;
65 }
66 
68  // use TFileService for output to root file
69  AnalysisTree = fs->make<TTree>("AnalysisTree", "MBUE Analysis Tree ");
70 
71  // process type
72  AnalysisTree->Branch("EventKind", &EventKind, "EventKind/I");
73 
74  // store p, pt, eta, phi for particles and jets
75 
76  // GenParticles at hadron level
77  AnalysisTree->Branch("NumberMCParticles", &NumberMCParticles, "NumberMCParticles/I");
78  AnalysisTree->Branch("MomentumMC", MomentumMC, "MomentumMC[NumberMCParticles]/F");
79  AnalysisTree->Branch("TransverseMomentumMC", TransverseMomentumMC, "TransverseMomentumMC[NumberMCParticles]/F");
80  AnalysisTree->Branch("EtaMC", EtaMC, "EtaMC[NumberMCParticles]/F");
81  AnalysisTree->Branch("PhiMC", PhiMC, "PhiMC[NumberMCParticles]/F");
82 
83  // GenJets
84  AnalysisTree->Branch("NumberInclusiveJet", &NumberInclusiveJet, "NumberInclusiveJet/I");
85  AnalysisTree->Branch("MomentumIJ", MomentumIJ, "MomentumIJ[NumberInclusiveJet]/F");
86  AnalysisTree->Branch("TrasverseMomentumIJ", TransverseMomentumIJ, "TransverseMomentumIJ[NumberInclusiveJet]/F");
87  AnalysisTree->Branch("EtaIJ", EtaIJ, "EtaIJ[NumberInclusiveJet]/F");
88  AnalysisTree->Branch("PhiIJ", PhiIJ, "PhiIJ[NumberInclusiveJet]/F");
89 
90  // jets from charged GenParticles
91  AnalysisTree->Branch("NumberChargedJet", &NumberChargedJet, "NumberChargedJet/I");
92  AnalysisTree->Branch("MomentumCJ", MomentumCJ, "MomentumCJ[NumberChargedJet]/F");
93  AnalysisTree->Branch("TrasverseMomentumCJ", TransverseMomentumCJ, "TransverseMomentumCJ[NumberChargedJet]/F");
94  AnalysisTree->Branch("EtaCJ", EtaCJ, "EtaCJ[NumberChargedJet]/F");
95  AnalysisTree->Branch("PhiCJ", PhiCJ, "PhiCJ[NumberChargedJet]/F");
96 
97  // alternative storage method:
98  // save TClonesArrays of TLorentzVectors
99  // i.e. store 4-vectors of particles and jets
100 
101  MonteCarlo = new TClonesArray("TLorentzVector", 10000);
102  AnalysisTree->Branch("MonteCarlo", "TClonesArray", &MonteCarlo, 128000, 0);
103 
104  InclusiveJet = new TClonesArray("TLorentzVector", 10000);
105  AnalysisTree->Branch("InclusiveJet", "TClonesArray", &InclusiveJet, 128000, 0);
106 
107  ChargedJet = new TClonesArray("TLorentzVector", 10000);
108  AnalysisTree->Branch("ChargedJet", "TClonesArray", &ChargedJet, 128000, 0);
109 }
110 
112  e.getByToken(mcEventToken, EvtHandle);
113  e.getByToken(chgGenPartCollToken, CandHandleMC);
114  e.getByToken(chgJetCollToken, ChgGenJetsHandle);
115  e.getByToken(genJetCollToken, GenJetsHandle);
116 
117  const HepMC::GenEvent* Evt = EvtHandle->GetEvent();
118 
119  EventKind = Evt->signal_process_id();
120 
121  std::vector<math::XYZTLorentzVector> GenPart;
122  std::vector<GenJet> ChgGenJetContainer;
123  std::vector<GenJet> GenJetContainer;
124 
125  GenPart.clear();
126  ChgGenJetContainer.clear();
127  GenJetContainer.clear();
128 
129  ChargedJet->Clear();
130  InclusiveJet->Clear();
131  MonteCarlo->Clear();
132 
133  if (!ChgGenJetsHandle->empty()) {
134  for (GenJetCollection::const_iterator it(ChgGenJetsHandle->begin()), itEnd(ChgGenJetsHandle->end()); it != itEnd;
135  ++it) {
136  ChgGenJetContainer.push_back(*it);
137  }
138 
139  std::stable_sort(ChgGenJetContainer.begin(), ChgGenJetContainer.end(), GenJetSort());
140 
141  std::vector<GenJet>::const_iterator it(ChgGenJetContainer.begin()), itEnd(ChgGenJetContainer.end());
142  for (int iChargedJet(0); it != itEnd; ++it, ++iChargedJet) {
143  fillChargedJet(it->p(), it->pt(), it->eta(), it->phi());
144  new ((*ChargedJet)[iChargedJet]) TLorentzVector(it->px(), it->py(), it->pz(), it->energy());
145  }
146  }
147 
148  if (!GenJetsHandle->empty()) {
149  for (GenJetCollection::const_iterator it(GenJetsHandle->begin()), itEnd(GenJetsHandle->end()); it != itEnd; ++it) {
150  GenJetContainer.push_back(*it);
151  }
152 
153  std::stable_sort(GenJetContainer.begin(), GenJetContainer.end(), GenJetSort());
154 
155  std::vector<GenJet>::const_iterator it(GenJetContainer.begin()), itEnd(GenJetContainer.end());
156  for (int iInclusiveJet(0); it != itEnd; ++it, ++iInclusiveJet) {
157  fillInclusiveJet(it->p(), it->pt(), it->eta(), it->phi());
158  new ((*InclusiveJet)[iInclusiveJet]) TLorentzVector(it->px(), it->py(), it->pz(), it->energy());
159  }
160  }
161 
162  if (!CandHandleMC->empty()) {
163  for (vector<GenParticle>::const_iterator it(CandHandleMC->begin()), itEnd(CandHandleMC->end()); it != itEnd; it++) {
164  GenPart.push_back(it->p4());
165  }
166 
167  std::stable_sort(GenPart.begin(), GenPart.end(), GreaterPt());
168 
169  std::vector<math::XYZTLorentzVector>::const_iterator it(GenPart.begin()), itEnd(GenPart.end());
170  for (int iMonteCarlo(0); it != itEnd; ++it, ++iMonteCarlo) {
171  fillMCParticles(it->P(), it->Pt(), it->Eta(), it->Phi());
172  new ((*MonteCarlo)[iMonteCarlo]) TLorentzVector(it->Px(), it->Py(), it->Pz(), it->E());
173  }
174  }
175 
176  store();
177 }
178 
void fillMCParticles(float, float, float, float)
T getUntrackedParameter(std::string const &, T const &) const
void fillChargedJet(float, float, float, float)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
double pt() const final
transverse momentum
bool operator()(const math::XYZTLorentzVector &a, const math::XYZTLorentzVector &b)
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
AnalysisRootpleProducerOnlyMC(const edm::ParameterSet &)
Jets made from MC generator particles.
Definition: GenJet.h:23
double b
Definition: hdecay.h:118
fixed size matrix
HLT enums.
double a
Definition: hdecay.h:119
bool operator()(const GenJet &a, const GenJet &b)
void analyze(const edm::Event &, const edm::EventSetup &) override
void fillInclusiveJet(float, float, float, float)