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 
reco::GenJet
Jets made from MC generator particles.
Definition: GenJet.h:23
DiDispStaMuonMonitor_cfi.pt
pt
Definition: DiDispStaMuonMonitor_cfi.py:39
GreaterPt::operator()
bool operator()(const math::XYZTLorentzVector &a, const math::XYZTLorentzVector &b)
Definition: AnalysisRootpleProducerOnlyMC.cc:10
edm
HLT enums.
Definition: AlignableModifier.h:19
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
AnalysisRootpleProducerOnlyMC::fillMCParticles
void fillMCParticles(float, float, float, float)
Definition: AnalysisRootpleProducerOnlyMC.cc:28
AnalysisRootpleProducerOnlyMC::endJob
void endJob() override
Definition: AnalysisRootpleProducerOnlyMC.cc:179
AnalysisRootpleProducerOnlyMC::fillChargedJet
void fillChargedJet(float, float, float, float)
Definition: AnalysisRootpleProducerOnlyMC.cc:44
GenJetSort::operator()
bool operator()(const GenJet &a, const GenJet &b)
Definition: AnalysisRootpleProducerOnlyMC.cc:15
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
HepMC::GenEvent
Definition: hepmc_rootio.cc:9
AnalysisRootpleProducerOnlyMC::beginJob
void beginJob() override
Definition: AnalysisRootpleProducerOnlyMC.cc:67
AnalysisRootpleProducerOnlyMC.h
AnalysisRootpleProducerOnlyMC::store
void store()
Definition: AnalysisRootpleProducerOnlyMC.cc:18
PVValHelper::eta
Definition: PVValidationHelpers.h:69
AnalysisRootpleProducerOnlyMC::AnalysisRootpleProducerOnlyMC
AnalysisRootpleProducerOnlyMC(const edm::ParameterSet &)
Definition: AnalysisRootpleProducerOnlyMC.cc:52
AnalysisRootpleProducerOnlyMC::fillEventInfo
void fillEventInfo(int)
Definition: AnalysisRootpleProducerOnlyMC.cc:26
nanoDQM_cfi.GenPart
GenPart
Definition: nanoDQM_cfi.py:288
b
double b
Definition: hdecay.h:118
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::ParameterSet
Definition: ParameterSet.h:47
a
double a
Definition: hdecay.h:119
GreaterPt
Definition: AnalysisRootpleProducer.cc:9
edm::EventSetup
Definition: EventSetup.h:57
HLT_FULL_cff.MonteCarlo
MonteCarlo
Definition: HLT_FULL_cff.py:4990
std
Definition: JetResolutionObject.h:76
AnalysisRootpleProducerOnlyMC::fillInclusiveJet
void fillInclusiveJet(float, float, float, float)
Definition: AnalysisRootpleProducerOnlyMC.cc:36
math::XYZTLorentzVector
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
AnalysisRootpleProducerOnlyMC::analyze
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: AnalysisRootpleProducerOnlyMC.cc:111
GenJetSort
Definition: AnalysisRootpleProducer.cc:14
edm::Event
Definition: Event.h:73
edm::InputTag
Definition: InputTag.h:15
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37