test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 {
10 public:
12  {
13  return a.pt() > b.pt();
14  }
15 };
16 
17 class GenJetSort
18 {
19 public:
20  bool operator()(const GenJet& a, const GenJet& b)
21  {
22  return a.pt() > b.pt();
23  }
24 };
25 
26 
28 {
29  AnalysisTree->Fill();
30 
31  NumberMCParticles=0;
32  NumberInclusiveJet=0;
33  NumberChargedJet=0;
34 }
35 
37 {
38  EventKind = e;
39 }
40 
41 void AnalysisRootpleProducerOnlyMC::fillMCParticles(float p, float pt, float eta, float phi)
42 {
43  MomentumMC[NumberMCParticles]=p;
44  TransverseMomentumMC[NumberMCParticles]=pt;
45  EtaMC[NumberMCParticles]=eta;
46  PhiMC[NumberMCParticles]=phi;
47  NumberMCParticles++;
48 }
49 
50 void AnalysisRootpleProducerOnlyMC::fillInclusiveJet(float p, float pt, float eta, float phi)
51 {
52  MomentumIJ[NumberInclusiveJet]=p;
53  TransverseMomentumIJ[NumberInclusiveJet]=pt;
54  EtaIJ[NumberInclusiveJet]=eta;
55  PhiIJ[NumberInclusiveJet]=phi;
56  NumberInclusiveJet++;
57 }
58 
59 void AnalysisRootpleProducerOnlyMC::fillChargedJet(float p, float pt, float eta, float phi)
60 {
61  MomentumCJ[NumberChargedJet]=p;
62  TransverseMomentumCJ[NumberChargedJet]=pt;
63  EtaCJ[NumberChargedJet]=eta;
64  PhiCJ[NumberChargedJet]=phi;
65  NumberChargedJet++;
66 }
67 
69 {
70  mcEventToken = consumes<edm::HepMCProduct>(pset.getUntrackedParameter<InputTag>("MCEvent",std::string("")));
71  genJetCollToken = consumes<reco::GenJetCollection>(pset.getUntrackedParameter<InputTag>("GenJetCollectionName",std::string("")));
72  chgJetCollToken = consumes<reco::GenJetCollection>(pset.getUntrackedParameter<InputTag>("ChgGenJetCollectionName",std::string("")));
73  chgGenPartCollToken = consumes<std::vector<reco::GenParticle> >(pset.getUntrackedParameter<InputTag>("ChgGenPartCollectionName",std::string("")));
74 
75  piG = acos(-1.);
76  NumberMCParticles=0;
77  NumberInclusiveJet=0;
78  NumberChargedJet=0;
79 }
80 
81 
83 {
84  // use TFileService for output to root file
85  AnalysisTree = fs->make<TTree>("AnalysisTree","MBUE Analysis Tree ");
86 
87  // process type
88  AnalysisTree->Branch("EventKind",&EventKind,"EventKind/I");
89 
90  // store p, pt, eta, phi for particles and jets
91 
92  // GenParticles at hadron level
93  AnalysisTree->Branch("NumberMCParticles",&NumberMCParticles,"NumberMCParticles/I");
94  AnalysisTree->Branch("MomentumMC",MomentumMC,"MomentumMC[NumberMCParticles]/F");
95  AnalysisTree->Branch("TransverseMomentumMC",TransverseMomentumMC,"TransverseMomentumMC[NumberMCParticles]/F");
96  AnalysisTree->Branch("EtaMC",EtaMC,"EtaMC[NumberMCParticles]/F");
97  AnalysisTree->Branch("PhiMC",PhiMC,"PhiMC[NumberMCParticles]/F");
98 
99  // GenJets
100  AnalysisTree->Branch("NumberInclusiveJet",&NumberInclusiveJet,"NumberInclusiveJet/I");
101  AnalysisTree->Branch("MomentumIJ",MomentumIJ,"MomentumIJ[NumberInclusiveJet]/F");
102  AnalysisTree->Branch("TrasverseMomentumIJ",TransverseMomentumIJ,"TransverseMomentumIJ[NumberInclusiveJet]/F");
103  AnalysisTree->Branch("EtaIJ",EtaIJ,"EtaIJ[NumberInclusiveJet]/F");
104  AnalysisTree->Branch("PhiIJ",PhiIJ,"PhiIJ[NumberInclusiveJet]/F");
105 
106  // jets from charged GenParticles
107  AnalysisTree->Branch("NumberChargedJet",&NumberChargedJet,"NumberChargedJet/I");
108  AnalysisTree->Branch("MomentumCJ",MomentumCJ,"MomentumCJ[NumberChargedJet]/F");
109  AnalysisTree->Branch("TrasverseMomentumCJ",TransverseMomentumCJ,"TransverseMomentumCJ[NumberChargedJet]/F");
110  AnalysisTree->Branch("EtaCJ",EtaCJ,"EtaCJ[NumberChargedJet]/F");
111  AnalysisTree->Branch("PhiCJ",PhiCJ,"PhiCJ[NumberChargedJet]/F");
112 
113 
114  // alternative storage method:
115  // save TClonesArrays of TLorentzVectors
116  // i.e. store 4-vectors of particles and jets
117 
118  MonteCarlo = new TClonesArray("TLorentzVector", 10000);
119  AnalysisTree->Branch("MonteCarlo", "TClonesArray", &MonteCarlo, 128000, 0);
120 
121  InclusiveJet = new TClonesArray("TLorentzVector", 10000);
122  AnalysisTree->Branch("InclusiveJet", "TClonesArray", &InclusiveJet, 128000, 0);
123 
124  ChargedJet = new TClonesArray("TLorentzVector", 10000);
125  AnalysisTree->Branch("ChargedJet", "TClonesArray", &ChargedJet, 128000, 0);
126 }
127 
128 
130 {
131 
132  e.getByToken( mcEventToken , EvtHandle );
133  e.getByToken( chgGenPartCollToken, CandHandleMC );
134  e.getByToken( chgJetCollToken , ChgGenJetsHandle );
135  e.getByToken( genJetCollToken , GenJetsHandle );
136 
137  const HepMC::GenEvent* Evt = EvtHandle->GetEvent() ;
138 
139  EventKind = Evt->signal_process_id();
140 
141  std::vector<math::XYZTLorentzVector> GenPart;
142  std::vector<GenJet> ChgGenJetContainer;
143  std::vector<GenJet> GenJetContainer;
144 
145  GenPart.clear();
146  ChgGenJetContainer.clear();
147  GenJetContainer.clear();
148 
149  ChargedJet->Clear();
150  InclusiveJet->Clear();
151  MonteCarlo->Clear();
152 
153  if (ChgGenJetsHandle->size()){
154 
155  for ( GenJetCollection::const_iterator it(ChgGenJetsHandle->begin()), itEnd(ChgGenJetsHandle->end());
156  it!=itEnd; ++it)
157  {
158  ChgGenJetContainer.push_back(*it);
159  }
160 
161  std::stable_sort(ChgGenJetContainer.begin(),ChgGenJetContainer.end(),GenJetSort());
162 
163  std::vector<GenJet>::const_iterator it(ChgGenJetContainer.begin()), itEnd(ChgGenJetContainer.end());
164  for ( int iChargedJet(0); it != itEnd; ++it, ++iChargedJet)
165  {
166  fillChargedJet(it->p(),it->pt(),it->eta(),it->phi());
167  new((*ChargedJet)[iChargedJet]) TLorentzVector(it->px(), it->py(), it->pz(), it->energy());
168  }
169  }
170 
171  if (GenJetsHandle->size()){
172 
173  for ( GenJetCollection::const_iterator it(GenJetsHandle->begin()), itEnd(GenJetsHandle->end());
174  it!=itEnd; ++it )
175  {
176  GenJetContainer.push_back(*it);
177  }
178 
179  std::stable_sort(GenJetContainer.begin(),GenJetContainer.end(),GenJetSort());
180 
181  std::vector<GenJet>::const_iterator it(GenJetContainer.begin()), itEnd(GenJetContainer.end());
182  for ( int iInclusiveJet(0); it != itEnd; ++it, ++iInclusiveJet)
183  {
184  fillInclusiveJet(it->p(),it->pt(),it->eta(),it->phi());
185  new((*InclusiveJet)[iInclusiveJet]) TLorentzVector(it->px(), it->py(), it->pz(), it->energy());
186  }
187  }
188 
189  if (CandHandleMC->size()){
190 
191  for (vector<GenParticle>::const_iterator it(CandHandleMC->begin()), itEnd(CandHandleMC->end());
192  it != itEnd;it++)
193  {
194  GenPart.push_back(it->p4());
195  }
196 
197  std::stable_sort(GenPart.begin(),GenPart.end(),GreaterPt());
198 
199  std::vector<math::XYZTLorentzVector>::const_iterator it(GenPart.begin()), itEnd(GenPart.end());
200  for( int iMonteCarlo(0); it != itEnd; ++it, ++iMonteCarlo )
201  {
202  fillMCParticles(it->P(),it->Pt(),it->Eta(),it->Phi());
203  new((*MonteCarlo)[iMonteCarlo]) TLorentzVector(it->Px(), it->Py(), it->Pz(), it->E());
204  }
205  }
206 
207  store();
208 }
209 
211 {
212 }
213 
void fillMCParticles(float, float, float, float)
T getUntrackedParameter(std::string const &, T const &) const
void fillChargedJet(float, float, float, float)
virtual void analyze(const edm::Event &, const edm::EventSetup &)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:462
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:24
double b
Definition: hdecay.h:120
double a
Definition: hdecay.h:121
bool operator()(const GenJet &a, const GenJet &b)
void fillInclusiveJet(float, float, float, float)
virtual double pt() const final
transverse momentum