1 |
amagnan |
1.1 |
#include "TLorentzVector.h"
|
2 |
|
|
#include <limits>
|
3 |
|
|
|
4 |
|
|
#include "DataFormats/Common/interface/Handle.h"
|
5 |
|
|
#include "DataFormats/Common/interface/ValueMap.h"
|
6 |
|
|
|
7 |
|
|
#include "DataFormats/Candidate/interface/Candidate.h"
|
8 |
|
|
#include "DataFormats/HepMCCandidate/interface/GenParticle.h"
|
9 |
|
|
#include "DataFormats/GeometryVector/interface/GlobalPoint.h"
|
10 |
|
|
#include "DataFormats/JetReco/interface/GenJet.h"
|
11 |
amagnan |
1.2 |
#include "DataFormats/JetReco/interface/Jet.h"
|
12 |
amagnan |
1.1 |
#include "SimDataFormats/GeneratorProducts/interface/GenRunInfoProduct.h"
|
13 |
|
|
#include "SimDataFormats/GeneratorProducts/interface/HepMCProduct.h"
|
14 |
|
|
#include "SimDataFormats/GeneratorProducts/interface/LHEEventProduct.h"
|
15 |
|
|
#include "SimDataFormats/GeneratorProducts/interface/GenEventInfoProduct.h"
|
16 |
|
|
|
17 |
|
|
|
18 |
|
|
#include "FWCore/ServiceRegistry/interface/Service.h"
|
19 |
|
|
#include "FWCore/Framework/interface/Run.h"
|
20 |
|
|
#include "FWCore/Framework/interface/ESHandle.h"
|
21 |
|
|
#include "CommonTools/UtilAlgos/interface/TFileService.h"
|
22 |
|
|
|
23 |
|
|
#include "UserCode/HbbAnalysis/plugins/MCTreeMaker.hh"
|
24 |
|
|
#include "boost/regex.hpp"
|
25 |
|
|
#include "boost/lexical_cast.hpp"
|
26 |
|
|
|
27 |
|
|
MCTreeMaker::MCTreeMaker(const edm::ParameterSet & pset):
|
28 |
|
|
debug_(pset.getParameter<int>("DEBUG")),
|
29 |
|
|
doGen_(pset.getParameter<bool>("DOGEN")),
|
30 |
|
|
genParticleSrc_(pset.getParameter<edm::InputTag>("GenParticles")),
|
31 |
|
|
genJetSrc_(pset.getParameter<edm::InputTag>("GenJets")),
|
32 |
|
|
partonJetSrc_(pset.getParameter<edm::InputTag>("PartonJets")),
|
33 |
amagnan |
1.2 |
pfJetSrc_(pset.getParameter<edm::InputTag>("PFJets")),
|
34 |
amagnan |
1.1 |
status1ToKeep_(pset.getParameter<std::vector<std::string> >("Status1ToKeep")),
|
35 |
|
|
status2ToKeep_(pset.getParameter<std::vector<std::string> >("Status2ToKeep")),
|
36 |
|
|
status3ToKeep_(pset.getParameter<std::vector<std::string> >("Status3ToKeep")),
|
37 |
|
|
event_(0),
|
38 |
|
|
tree_(0)
|
39 |
|
|
//processVec_(pset.getParameter<std::vector<std::string> >("ProcessVec"))
|
40 |
|
|
{//constructor
|
41 |
|
|
for (unsigned i = 0; i < status1ToKeep_.size(); ++i){
|
42 |
|
|
status1ToKeepRegex_.push_back(boost::regex(status1ToKeep_[i]));
|
43 |
|
|
}
|
44 |
|
|
for (unsigned i = 0; i < status2ToKeep_.size(); ++i){
|
45 |
|
|
status2ToKeepRegex_.push_back(boost::regex(status2ToKeep_[i]));
|
46 |
|
|
}
|
47 |
|
|
for (unsigned i = 0; i < status3ToKeep_.size(); ++i){
|
48 |
|
|
status3ToKeepRegex_.push_back(boost::regex(status3ToKeep_[i]));
|
49 |
|
|
}
|
50 |
|
|
}//constructor
|
51 |
|
|
|
52 |
|
|
MCTreeMaker::~MCTreeMaker()
|
53 |
|
|
{//destructor
|
54 |
|
|
|
55 |
|
|
}//destructor
|
56 |
|
|
|
57 |
|
|
|
58 |
|
|
|
59 |
|
|
void MCTreeMaker::beginJob(){//beginJob
|
60 |
|
|
|
61 |
|
|
|
62 |
|
|
edm::Service<TFileService> lFileService;
|
63 |
|
|
|
64 |
|
|
TFileDirectory lDir = lFileService->mkdir("MCAnalysis");
|
65 |
|
|
|
66 |
|
|
tree_ = lDir.make<TTree>("Tree","Tree");
|
67 |
|
|
tree_->Branch("MCEvent","HbbAnalysis::MCEvent",&event_);
|
68 |
|
|
event_ = new HbbAnalysis::MCEvent();
|
69 |
|
|
|
70 |
|
|
}//beginJob
|
71 |
|
|
|
72 |
|
|
|
73 |
|
|
|
74 |
|
|
void MCTreeMaker::endJob(){//endJob
|
75 |
|
|
|
76 |
|
|
//tree_->Write();
|
77 |
|
|
//delete tree_;
|
78 |
|
|
//delete event_;
|
79 |
|
|
|
80 |
|
|
}//endJob
|
81 |
|
|
|
82 |
|
|
void MCTreeMaker::beginRun(const edm::Run& aRun, const edm::EventSetup& aEvtSetup){//beginRun
|
83 |
|
|
|
84 |
|
|
}
|
85 |
|
|
|
86 |
|
|
void MCTreeMaker::analyze(const edm::Event& aEvt, const edm::EventSetup& aEvtSetup){//analyze
|
87 |
|
|
|
88 |
|
|
if (debug_) std::cout << "Processing event #" << aEvt.id().event() << std::endl;
|
89 |
|
|
|
90 |
|
|
|
91 |
|
|
static bool firstEvent = true;
|
92 |
|
|
|
93 |
|
|
event_->Clear();
|
94 |
|
|
event_->event(aEvt.id().event());
|
95 |
|
|
|
96 |
|
|
event_->run(aEvt.run());
|
97 |
|
|
//used in jet method....
|
98 |
|
|
edm::Handle<reco::GenParticleCollection> lGenParticles;
|
99 |
|
|
|
100 |
|
|
// edm::Handle<edm::HepMCProduct> mcProd;
|
101 |
|
|
// edm::Handle<GenRunInfoProduct> lRunProd;
|
102 |
|
|
// edm::Handle<GenEventInfoProduct> genEventInfoHandle;
|
103 |
|
|
|
104 |
|
|
// try {
|
105 |
|
|
// aEvt.getByLabel("generator", mcProd );
|
106 |
|
|
// } catch(cms::Exception& e) {
|
107 |
|
|
// std::cout << "AMM: Collection HepMCProduct not available! Exception : " << e.what() << ". " << std::endl;
|
108 |
|
|
// }
|
109 |
|
|
// try {
|
110 |
|
|
// aEvt.getRun().getByLabel("generator",lRunProd);
|
111 |
|
|
// } catch(cms::Exception& e) {
|
112 |
|
|
// std::cout << "AMM: Collection GenInfoProduct not available! Exception : " << e.what() << ". " << std::endl;
|
113 |
|
|
// }
|
114 |
|
|
// try {
|
115 |
|
|
// aEvt.getByLabel("generator",genEventInfoHandle);
|
116 |
|
|
// } catch(cms::Exception& e) {
|
117 |
|
|
// std::cout << "AMM: Collection GenEventInfoProduct not available! Exception : " << e.what() << ". " << std::endl;
|
118 |
|
|
// }
|
119 |
|
|
|
120 |
|
|
// HbbGenInfo(mcProd,lRunProd,genEventInfoHandle);
|
121 |
|
|
|
122 |
|
|
edm::Handle<reco::GenJetCollection> lGenJets;
|
123 |
|
|
try {
|
124 |
|
|
aEvt.getByLabel(genJetSrc_,lGenJets);
|
125 |
|
|
if (debug_) std::cout << "** ngenJets = " << lGenJets->size() << std::endl;
|
126 |
|
|
} catch(cms::Exception& e) {
|
127 |
|
|
std::cout << "AMM: Collection GenJets not available! Exception : " << e.what() << ". " << std::endl;
|
128 |
|
|
}
|
129 |
|
|
|
130 |
|
|
//save components
|
131 |
|
|
if (lGenJets.isValid()) HbbGenJets(lGenJets,event_->genjets(),true);
|
132 |
|
|
|
133 |
|
|
edm::Handle<reco::GenJetCollection> lPartonJets;
|
134 |
|
|
try {
|
135 |
|
|
aEvt.getByLabel(partonJetSrc_,lPartonJets);
|
136 |
|
|
if (debug_) std::cout << "** npartonJets = " << lPartonJets->size() << std::endl;
|
137 |
|
|
} catch(cms::Exception& e) {
|
138 |
|
|
std::cout << "AMM: Collection PartonJets not available! Exception : " << e.what() << ". " << std::endl;
|
139 |
|
|
}
|
140 |
|
|
|
141 |
|
|
//save components
|
142 |
|
|
if (lPartonJets.isValid()) HbbGenJets(lPartonJets,event_->partonjets(),true);
|
143 |
|
|
|
144 |
|
|
edm::Handle<LHEEventProduct> lLHEEvt;
|
145 |
|
|
try {
|
146 |
|
|
aEvt.getByType(lLHEEvt);
|
147 |
|
|
} catch(cms::Exception& e) {
|
148 |
|
|
std::cout << "AMM: Collection of LHEEventProduct not available! Exception : " << e.what() << ". " << std::endl;
|
149 |
|
|
}
|
150 |
|
|
|
151 |
|
|
if (lLHEEvt.isValid()){
|
152 |
|
|
HbbLHEInfo(lLHEEvt,event_->lheParticles());
|
153 |
|
|
}
|
154 |
|
|
|
155 |
|
|
try {
|
156 |
|
|
aEvt.getByLabel(genParticleSrc_,lGenParticles);
|
157 |
|
|
if (debug_) std::cout << "** ngenParticles = " << lGenParticles->size() << std::endl;
|
158 |
|
|
} catch(cms::Exception& e) {
|
159 |
|
|
std::cout << "AMM: Collection genParticles not available! Exception : " << e.what() << ". " << std::endl;
|
160 |
|
|
}
|
161 |
|
|
|
162 |
|
|
//if (doGen_) HbbParticles(lGenParticles,event_->particles());
|
163 |
|
|
HbbParticles(lGenParticles,event_->particles(), event_->p4total());
|
164 |
|
|
|
165 |
amagnan |
1.2 |
edm::Handle<std::vector<pat::Jet> > lPfJetCollection;
|
166 |
|
|
|
167 |
|
|
try {
|
168 |
|
|
aEvt.getByLabel(pfJetSrc_,lPfJetCollection);
|
169 |
|
|
if (!lPfJetCollection.isValid()){
|
170 |
|
|
edm::LogInfo("ERROR")<< "Error! Can't get pfJets by label. ";
|
171 |
|
|
}
|
172 |
|
|
if (debug_) std::cout << "** pfJetcollection = " << lPfJetCollection->size() << " elements." << std::endl;
|
173 |
|
|
} catch(cms::Exception& e) {
|
174 |
|
|
std::cout << "AMM: Collection " << pfJetSrc_ << " not available! Exception : " << e.what() << ". " << std::endl;
|
175 |
|
|
}
|
176 |
|
|
|
177 |
|
|
//std::cout << "Processing PF jets:" << std::endl;
|
178 |
|
|
HbbJets(lPfJetCollection,lGenParticles,event_->pfjets());
|
179 |
|
|
|
180 |
amagnan |
1.1 |
|
181 |
|
|
tree_->Fill();
|
182 |
|
|
firstEvent = false;
|
183 |
|
|
|
184 |
|
|
}//analyze
|
185 |
|
|
|
186 |
|
|
|
187 |
|
|
|
188 |
|
|
void MCTreeMaker::HbbParticles(const edm::Handle<reco::GenParticleCollection> & aCol,
|
189 |
|
|
std::vector<HbbAnalysis::GenParticle> & aVec,
|
190 |
|
|
HbbAnalysis::P4Total & p4total)
|
191 |
|
|
{//genparticles
|
192 |
|
|
|
193 |
|
|
|
194 |
|
|
const reco::GenParticle *ptrToFirst = 0;
|
195 |
|
|
if (aCol->size() > 0) ptrToFirst = &((*aCol)[0]);
|
196 |
|
|
//add genParticle inside vector
|
197 |
|
|
p4total.comE = 0.0;
|
198 |
|
|
p4total.sumPx = 0.0;
|
199 |
|
|
p4total.sumPy = 0.0;
|
200 |
|
|
p4total.sumPz = 0.0;
|
201 |
|
|
p4total.sumE = 0.0;
|
202 |
|
|
for (unsigned int mccount = 0;mccount<aCol->size();++mccount)
|
203 |
|
|
{//loop on particles
|
204 |
|
|
const reco::GenParticle & p = (*aCol)[mccount];
|
205 |
|
|
|
206 |
|
|
if (p.status() == 3 && p.pdgId() == 2212){
|
207 |
|
|
p4total.comE += p.energy();
|
208 |
|
|
}
|
209 |
|
|
if (p.status() == 1){
|
210 |
|
|
p4total.sumPx += p.px();
|
211 |
|
|
p4total.sumPy += p.py();
|
212 |
|
|
p4total.sumPz += p.pz();
|
213 |
|
|
p4total.sumE += p.energy();
|
214 |
|
|
}
|
215 |
|
|
|
216 |
|
|
bool keep = false;
|
217 |
|
|
if (p.status() == 1){
|
218 |
|
|
for (unsigned i = 0; i < status1ToKeepRegex_.size(); ++i){
|
219 |
|
|
//if (boost::regex_match(boost::lexical_cast<std::string>(p.pdgId()),status1ToKeepRegex_[i]) && p.pt() > 5.0) keep = true;
|
220 |
|
|
if (boost::regex_match(boost::lexical_cast<std::string>(p.pdgId()),status1ToKeepRegex_[i])) keep = true;
|
221 |
|
|
//if (abs(p.pdgId()) <= 16) keep = true; //Keep all status 1 leptons, regardless of matches passed through config
|
222 |
|
|
}
|
223 |
|
|
}
|
224 |
|
|
if (p.status() == 2){
|
225 |
|
|
for (unsigned i = 0; i < status2ToKeepRegex_.size(); ++i){
|
226 |
|
|
if (boost::regex_match(boost::lexical_cast<std::string>(p.pdgId()),status2ToKeepRegex_[i])) keep = true;
|
227 |
|
|
}
|
228 |
|
|
}
|
229 |
|
|
if (p.status() == 3){
|
230 |
|
|
for (unsigned i = 0; i < status3ToKeepRegex_.size(); ++i){
|
231 |
|
|
if (boost::regex_match(boost::lexical_cast<std::string>(p.pdgId()),status3ToKeepRegex_[i])) keep = true;
|
232 |
|
|
}
|
233 |
|
|
}
|
234 |
|
|
|
235 |
|
|
if (keep){
|
236 |
|
|
|
237 |
|
|
HbbAnalysis::FourMomentum lGenFourVec;
|
238 |
|
|
HbbAnalysis::GenVars lGen;
|
239 |
|
|
lGenFourVec.px = p.px();
|
240 |
|
|
lGenFourVec.py = p.py();
|
241 |
|
|
lGenFourVec.pz = p.pz();
|
242 |
|
|
lGenFourVec.e = p.energy();
|
243 |
|
|
lGen.charge = p.charge();
|
244 |
|
|
lGen.pdgId = p.pdgId();
|
245 |
|
|
lGen.status = p.status();
|
246 |
|
|
lGen.index = mccount;
|
247 |
|
|
lGen.vertex.vx = p.vx();
|
248 |
|
|
lGen.vertex.vy = p.vy();
|
249 |
|
|
lGen.vertex.vz = p.vz();
|
250 |
|
|
|
251 |
|
|
HbbAnalysis::GenParticle lObj(lGenFourVec,lGen);
|
252 |
|
|
|
253 |
|
|
for (unsigned i = 0; i < p.numberOfMothers(); ++i){
|
254 |
|
|
lObj.setParent((reco::GenParticle*)p.mother(i) - ptrToFirst);
|
255 |
|
|
//std::cout << ((reco::GenParticle*)p.mother(i) - ptrToFirst) << " " << p.mother(i) << "\t";
|
256 |
|
|
}
|
257 |
|
|
//std::cout << std::endl;
|
258 |
|
|
//std::cout << "Daughters: ";
|
259 |
|
|
for (unsigned i = 0; i < p.numberOfDaughters(); ++i){
|
260 |
|
|
lObj.setChild((reco::GenParticle*)p.daughter(i) - ptrToFirst);
|
261 |
|
|
//std::cout << ((reco::GenParticle*)p.daughter(i) - ptrToFirst) << " " << p.daughter(i) << "\t";
|
262 |
|
|
}
|
263 |
|
|
aVec.push_back(lObj);
|
264 |
|
|
//if (mccount < 50) std::cout << "------Particle " << mccount << std::endl;
|
265 |
|
|
//if (mccount < 50) lObj.Print();
|
266 |
|
|
//std::cout << std::endl;
|
267 |
|
|
}
|
268 |
|
|
/*
|
269 |
|
|
unsigned int nMum = p.numberOfMothers();
|
270 |
|
|
//std::cout << mccount << " index = " << const_cast<reco::GenParticle *>(&p)-lBegin << " has " << nMum << " mother(s)." << std::endl;
|
271 |
|
|
|
272 |
|
|
if ( (!doGen_ &&
|
273 |
|
|
(p.status()==3 ||
|
274 |
|
|
(p.status()==2 && (abs(p.pdgId())==4 || abs(p.pdgId())==5)) ||
|
275 |
|
|
(p.status()==1 && ( (p.pt()>5 && abs(p.pdgId()) > 16) || abs(p.pdgId()) <= 16) )
|
276 |
|
|
)) || doGen_){
|
277 |
|
|
for(unsigned int mum=0;mum<nMum;++mum){//loop on mothers
|
278 |
|
|
const reco::Candidate * pMother = p.mother(mum);
|
279 |
|
|
//std::cout << "-- mother index = " << pMother-lBegin << std::endl;
|
280 |
|
|
for (unsigned int mccount2 = 0;mccount2<mccount;++mccount2)
|
281 |
|
|
{//loop on particles
|
282 |
|
|
const reco::Candidate & p2 = (*aCol)[mccount2];
|
283 |
|
|
if (pMother == &p2) {
|
284 |
|
|
lObj.setParent(mccount2);
|
285 |
|
|
break;
|
286 |
|
|
}
|
287 |
|
|
}
|
288 |
|
|
}//loop on mothers
|
289 |
|
|
*/
|
290 |
|
|
}//loop on particles
|
291 |
|
|
|
292 |
|
|
|
293 |
amagnan |
1.2 |
if (debug_>2){
|
294 |
amagnan |
1.1 |
for (unsigned int imc(0); imc < aVec.size(); ++imc){
|
295 |
|
|
HbbAnalysis::GenParticle & p = aVec.at(imc);
|
296 |
|
|
p.Print();
|
297 |
|
|
}
|
298 |
|
|
}
|
299 |
|
|
|
300 |
|
|
|
301 |
|
|
}//genparticles
|
302 |
|
|
|
303 |
|
|
void MCTreeMaker::HbbGenJets(const edm::Handle<reco::GenJetCollection> & aCol,
|
304 |
|
|
std::vector<HbbAnalysis::GenJet> & aVec,
|
305 |
|
|
const bool aSaveConstituants)
|
306 |
|
|
{
|
307 |
|
|
|
308 |
|
|
if (aCol.isValid()){//valid
|
309 |
|
|
if (aCol->size() > 0) {//non empty
|
310 |
|
|
|
311 |
|
|
unsigned int iEle = 0;
|
312 |
|
|
for (std::vector<reco::GenJet>::const_iterator iter = aCol->begin();
|
313 |
|
|
iter != aCol->end();
|
314 |
|
|
++iter,++iEle)
|
315 |
|
|
{//loop on element
|
316 |
|
|
//if (debug_ > 1) std::cout << "**** Ele #" << iEle << ", pT,eta,phi = " << (*iter).pt() << " " << (*iter).eta() << " " << (*iter).phi() << std::endl;
|
317 |
|
|
|
318 |
|
|
HbbAnalysis::FourMomentum lGenJetFourVec;
|
319 |
|
|
HbbAnalysis::GenJetVars lGenJet;
|
320 |
|
|
lGenJetFourVec.px = (*iter).px();
|
321 |
|
|
lGenJetFourVec.py = (*iter).py();
|
322 |
|
|
lGenJetFourVec.pz = (*iter).pz();
|
323 |
|
|
lGenJetFourVec.e = (*iter).energy();
|
324 |
|
|
lGenJet.mass = (*iter).mass();
|
325 |
|
|
lGenJet.nConstituents = (*iter).getGenConstituents().size();
|
326 |
|
|
lGenJet.flavour = 0; //Flavour will be set if constituents are added
|
327 |
|
|
|
328 |
|
|
|
329 |
|
|
//only status 1 saved !!!!
|
330 |
|
|
//get flavour from list of constituants.
|
331 |
|
|
//std::vector <const reco::GenParticle*> lConst = (*iter).getGenConstituents();
|
332 |
|
|
//unsigned int nb=0, nc=0;
|
333 |
|
|
// for (unsigned int iMC(0); iMC<lConst.size(); ++iMC){
|
334 |
|
|
// const reco::GenParticle* lPart = lConst[iMC];
|
335 |
|
|
// //std::cout << lPart->pdgId() << " " << fabs(lPart->pdgId()) << " " << abs(lPart->pdgId()) << std::endl;
|
336 |
|
|
// if (fabs(lPart->pdgId()) == 5){
|
337 |
|
|
// ++nb;
|
338 |
|
|
// break;
|
339 |
|
|
// }
|
340 |
|
|
// if (fabs(lPart->pdgId()) == 4) ++nc;
|
341 |
|
|
// }
|
342 |
|
|
// if (nb > 0) lGenJet.pdgId = 5;
|
343 |
|
|
// else if (nc > 0) lGenJet.pdgId = 4;
|
344 |
|
|
// else lGenJet.pdgId = 3;
|
345 |
|
|
|
346 |
|
|
HbbAnalysis::GenJet lObj(lGenJetFourVec, lGenJet);
|
347 |
|
|
if (aSaveConstituants){
|
348 |
|
|
for (unsigned int iC(0); iC<(*iter).getGenConstituents().size(); ++iC){
|
349 |
|
|
const reco::GenParticle* p = (*iter).getGenConstituent(iC);
|
350 |
|
|
HbbAnalysis::FourMomentum lGenFourVec;
|
351 |
|
|
HbbAnalysis::GenVars lGen;
|
352 |
|
|
lGenFourVec.px = p->px();
|
353 |
|
|
lGenFourVec.py = p->py();
|
354 |
|
|
lGenFourVec.pz = p->pz();
|
355 |
|
|
lGenFourVec.e = p->energy();
|
356 |
|
|
lGen.charge = p->charge();
|
357 |
|
|
lGen.pdgId = p->pdgId();
|
358 |
|
|
lGen.status = p->status();
|
359 |
|
|
lGen.index = -1; //We don't know this now
|
360 |
|
|
lGen.vertex.vx = p->vx();
|
361 |
|
|
lGen.vertex.vy = p->vy();
|
362 |
|
|
lGen.vertex.vz = p->vz();
|
363 |
|
|
lObj.addConstituent(HbbAnalysis::GenParticle(lGenFourVec,lGen));
|
364 |
|
|
}
|
365 |
|
|
}
|
366 |
|
|
//std::cout << "--------------------------------------------" << std::endl;
|
367 |
|
|
//std::cout << "GenJet: " << std::endl;
|
368 |
|
|
//std::cout << "--------------------------------------------" << std::endl;
|
369 |
|
|
//lObj.Print();
|
370 |
|
|
aVec.push_back(lObj);
|
371 |
|
|
}
|
372 |
|
|
}
|
373 |
|
|
}
|
374 |
|
|
}
|
375 |
|
|
|
376 |
|
|
|
377 |
|
|
|
378 |
|
|
|
379 |
|
|
void MCTreeMaker::HbbLHEInfo(const edm::Handle<LHEEventProduct> & aLHEEvt,
|
380 |
|
|
std::vector<HbbAnalysis::GenParticle> & aVec) {
|
381 |
|
|
|
382 |
|
|
const lhef::HEPEUP lhepeup = aLHEEvt->hepeup();
|
383 |
|
|
|
384 |
|
|
//4-momentum (px,py,pz,E)+mass
|
385 |
|
|
const std::vector<lhef::HEPEUP::FiveVector> lpup = lhepeup.PUP;
|
386 |
|
|
//pdgid int
|
387 |
|
|
const std::vector<int> lidup = lhepeup.IDUP;
|
388 |
|
|
//status int
|
389 |
|
|
const std::vector<int> listup = lhepeup.ISTUP;
|
390 |
|
|
//mother: pair<int,int>
|
391 |
|
|
const std::vector<std::pair<int,int> > lmothup = lhepeup.MOTHUP;
|
392 |
|
|
|
393 |
|
|
|
394 |
|
|
//add genParticle inside vector
|
395 |
|
|
for (unsigned int imc = 0;imc<lpup.size();++imc)
|
396 |
|
|
{//loop on particles
|
397 |
|
|
|
398 |
|
|
HbbAnalysis::FourMomentum lFourVec;
|
399 |
|
|
HbbAnalysis::GenVars lMC;
|
400 |
|
|
lMC.index = imc;
|
401 |
|
|
|
402 |
|
|
TLorentzVector lVec((lpup[imc])[0],(lpup[imc])[1],(lpup[imc])[2],(lpup[imc])[3]);
|
403 |
|
|
|
404 |
|
|
lFourVec.e = lVec.E();
|
405 |
|
|
lFourVec.px = lVec.Px();
|
406 |
|
|
lFourVec.py = lVec.Py();
|
407 |
|
|
lFourVec.pz = lVec.Pz();
|
408 |
|
|
/*
|
409 |
|
|
// Special case if pT = 0 (otherwise ROOT complains)
|
410 |
|
|
if (fabs(0.0 - lVec.Pt()) < std::numeric_limits<double>::epsilon()){
|
411 |
|
|
if (lVec.Pz() >= 0) {
|
412 |
|
|
lMC.eta = 1E10;
|
413 |
|
|
lMC.y = 1E10;
|
414 |
|
|
} else {
|
415 |
|
|
lMC.eta = -1E10;
|
416 |
|
|
lMC.y = -1E10;
|
417 |
|
|
}
|
418 |
|
|
} else {
|
419 |
|
|
lMC.eta = lVec.Eta();
|
420 |
|
|
lMC.y = lVec.Rapidity();
|
421 |
|
|
}
|
422 |
|
|
lMC.phi = lVec.Phi();
|
423 |
|
|
*/
|
424 |
|
|
lMC.pdgId = lidup[imc];
|
425 |
|
|
lMC.status = listup[imc];
|
426 |
|
|
|
427 |
|
|
HbbAnalysis::GenParticle lObj(lFourVec,lMC);
|
428 |
|
|
lObj.setParent(lmothup[imc].first);
|
429 |
|
|
lObj.setParent(lmothup[imc].second);
|
430 |
|
|
aVec.push_back(lObj);
|
431 |
|
|
|
432 |
|
|
}//loop on particles
|
433 |
|
|
|
434 |
amagnan |
1.2 |
if (debug_>2){
|
435 |
amagnan |
1.1 |
for (unsigned int imc(0); imc < aVec.size(); ++imc){
|
436 |
|
|
//HbbAnalysis::GenParticle & p = aVec.at(imc);
|
437 |
|
|
//p.print();
|
438 |
|
|
}
|
439 |
|
|
}
|
440 |
|
|
}
|
441 |
|
|
|
442 |
amagnan |
1.2 |
|
443 |
|
|
void MCTreeMaker::HbbJets(const edm::Handle<std::vector<pat::Jet> > & aCol,
|
444 |
|
|
const edm::Handle<reco::GenParticleCollection> & aGenParticles,
|
445 |
|
|
std::vector<HbbAnalysis::Jet> & aVec)
|
446 |
|
|
{//HbbJets
|
447 |
|
|
|
448 |
|
|
if (aCol.isValid()){//valid
|
449 |
|
|
if (aCol->size() > 0) {//non empty
|
450 |
|
|
|
451 |
|
|
unsigned int iEle = 0;
|
452 |
|
|
for (std::vector<pat::Jet>::const_iterator iter = aCol->begin();
|
453 |
|
|
iter != aCol->end();
|
454 |
|
|
++iter,++iEle)
|
455 |
|
|
{//loop on element
|
456 |
|
|
if (debug_ > 1) std::cout << "**** Ele #" << iEle << ", pT,eta,phi = " << (*iter).pt() << " " << (*iter).eta() << " " << (*iter).phi() << std::endl;
|
457 |
|
|
|
458 |
|
|
//----------------------------------------------------------------------
|
459 |
|
|
HbbAnalysis::FourMomentum lFourVec;
|
460 |
|
|
//----------------------------------------------------------------------
|
461 |
|
|
lFourVec.e = (*iter).energy();
|
462 |
|
|
lFourVec.px = (*iter).px();
|
463 |
|
|
lFourVec.py = (*iter).py();
|
464 |
|
|
lFourVec.pz = (*iter).pz();
|
465 |
|
|
//----------------------------------------------------------------------
|
466 |
|
|
HbbAnalysis::JetVars lJet;
|
467 |
|
|
//----------------------------------------------------------------------
|
468 |
|
|
lJet.partonFlavour = (*iter).partonFlavour();
|
469 |
|
|
lJet.nAssociatedTracks = ((*iter).associatedTracks()).size();
|
470 |
|
|
lJet.etaMean = (*iter).etaPhiStatistics().etaMean;
|
471 |
|
|
lJet.phiMean = (*iter).etaPhiStatistics().phiMean;
|
472 |
|
|
lJet.etaEtaMoment = (*iter).etaPhiStatistics().etaEtaMoment;
|
473 |
|
|
lJet.phiPhiMoment = (*iter).etaPhiStatistics().phiPhiMoment;
|
474 |
|
|
lJet.etaPhiMoment = (*iter).etaPhiStatistics().etaPhiMoment;
|
475 |
|
|
//Construct a GenParticle if processing MC and a match has been found by PAT
|
476 |
|
|
if ((*iter).genParton()){
|
477 |
|
|
HbbAnalysis::FourMomentum lGenFourVec;
|
478 |
|
|
HbbAnalysis::GenVars lGen;
|
479 |
|
|
lGenFourVec.px = (*iter).genParton()->px();
|
480 |
|
|
lGenFourVec.py = (*iter).genParton()->py();
|
481 |
|
|
lGenFourVec.pz = (*iter).genParton()->pz();
|
482 |
|
|
lGenFourVec.e = (*iter).genParton()->energy();
|
483 |
|
|
lGen.charge = (*iter).genParton()->charge();
|
484 |
|
|
lGen.pdgId = (*iter).genParton()->pdgId();
|
485 |
|
|
lGen.status = (*iter).genParton()->status();
|
486 |
|
|
lGen.vertex.vx = (*iter).genParton()->vx();
|
487 |
|
|
lGen.vertex.vy = (*iter).genParton()->vy();
|
488 |
|
|
lGen.vertex.vz = (*iter).genParton()->vz();
|
489 |
|
|
lJet.genMatches.push_back(HbbAnalysis::GenParticle(lGenFourVec, lGen));
|
490 |
|
|
}
|
491 |
|
|
//Construct a GenJet if processing MC and a match has been found by PAT
|
492 |
|
|
if ((*iter).genJet()){
|
493 |
|
|
HbbAnalysis::FourMomentum lGenJetFourVec;
|
494 |
|
|
HbbAnalysis::GenJetVars lGenJet;
|
495 |
|
|
lGenJetFourVec.px = (*iter).genJet()->px();
|
496 |
|
|
lGenJetFourVec.py = (*iter).genJet()->py();
|
497 |
|
|
lGenJetFourVec.pz = (*iter).genJet()->pz();
|
498 |
|
|
lGenJetFourVec.e = (*iter).genJet()->energy();
|
499 |
|
|
lGenJet.flavour = 0; //Flavour unknown in this context (will be filled for parton jets)
|
500 |
|
|
lGenJet.mass = (*iter).genJet()->mass();
|
501 |
|
|
lGenJet.nConstituents = (*iter).genJet()->getGenConstituents().size();
|
502 |
|
|
lJet.genJetMatches.push_back(HbbAnalysis::GenJet(lGenJetFourVec, lGenJet));
|
503 |
|
|
}
|
504 |
|
|
|
505 |
|
|
HbbAnalysis::JetECorVars lEnergyCorrections;
|
506 |
|
|
if ((*iter).jecSetsAvailable()){
|
507 |
|
|
std::vector<std::string> lJECnames = (*iter).availableJECSets();
|
508 |
|
|
for (unsigned int iSet(0); iSet < lJECnames.size(); ++iSet){
|
509 |
|
|
if (debug_>1) std::cout << " -- JEC SET " << iSet << " " << lJECnames[iSet] << std::endl;
|
510 |
|
|
std::vector<std::string> lJEClevels = (*iter).availableJECLevels(iSet);
|
511 |
|
|
for (unsigned int iLev(0); iLev<lJEClevels.size(); ++iLev){
|
512 |
|
|
if (debug_>1) std::cout << " ---- JEC level " << iLev << " " << lJEClevels[iLev]
|
513 |
|
|
<< " , factor = " << (*iter).jecFactor(iLev,pat::JetCorrFactors::NONE,iSet)
|
514 |
|
|
<< std::endl;
|
515 |
|
|
lEnergyCorrections.Levels[(lJEClevels[iLev])] = (*iter).jecFactor(iLev,pat::JetCorrFactors::NONE,iSet);
|
516 |
|
|
}
|
517 |
|
|
}
|
518 |
|
|
}
|
519 |
|
|
|
520 |
|
|
HbbAnalysis::JetBtagVars lBtag;
|
521 |
|
|
if (debug_>1) {
|
522 |
|
|
const std::vector<std::pair<std::string, float> > & lDiscris = (*iter).getPairDiscri();
|
523 |
|
|
std::cout << " -- btaggers: " << lDiscris.size() << " elements"
|
524 |
|
|
<< std::endl;
|
525 |
|
|
for (unsigned int iD(0); iD<lDiscris.size(); ++iD){
|
526 |
|
|
std::cout << "---- " << iD << " " << lDiscris[iD].first << std::endl;
|
527 |
|
|
}
|
528 |
|
|
}
|
529 |
|
|
|
530 |
|
|
lBtag.cSV = (*iter).bDiscriminator("combinedSecondaryVertexBJetTags");
|
531 |
|
|
lBtag.cSVMVA = (*iter).bDiscriminator("combinedSecondaryVertexMVABJetTags");
|
532 |
|
|
//lBtag.iPMVA = (*iter).bDiscriminator("impactParameterMVABJetTags");
|
533 |
|
|
lBtag.bProba = (*iter).bDiscriminator("jetBProbabilityBJetTags");
|
534 |
|
|
lBtag.probability = (*iter).bDiscriminator("jetProbabilityBJetTags");
|
535 |
|
|
lBtag.sSVHP = (*iter).bDiscriminator("simpleSecondaryVertexHighPurBJetTags");
|
536 |
|
|
lBtag.sSVHE = (*iter).bDiscriminator("simpleSecondaryVertexHighEffBJetTags");
|
537 |
|
|
//lBtag.softElectronByPt = ((*iter).bDiscriminator("softElectronByPtBJetTags") < -100) ? -100 : (*iter).bDiscriminator("softElectronByPtBJetTags");
|
538 |
|
|
//lBtag.softElectronByIP3d = ((*iter).bDiscriminator("softElectronByIP3dBJetTags") < -100) ? -100 : (*iter).bDiscriminator("softElectronByIP3dBJetTags");
|
539 |
|
|
lBtag.softMuon = ((*iter).bDiscriminator("softMuonBJetTags") < -100) ? -100 : (*iter).bDiscriminator("softMuonBJetTags");
|
540 |
|
|
lBtag.softMuonByPt = ((*iter).bDiscriminator("softMuonByPtBJetTags") < -100) ? -100 : (*iter).bDiscriminator("softMuonByPtBJetTags");
|
541 |
|
|
lBtag.softMuonByIP3d = ((*iter).bDiscriminator("softMuonByIP3dBJetTags") < -100) ? -100 : (*iter).bDiscriminator("softMuonByIP3dBJetTags");
|
542 |
|
|
lBtag.tCHE = (*iter).bDiscriminator("trackCountingHighEffBJetTags");
|
543 |
|
|
lBtag.tCHP = (*iter).bDiscriminator("trackCountingHighPurBJetTags");
|
544 |
|
|
|
545 |
|
|
//std::cout << " -- New values of b-discri for jet : " << iEle << std::endl
|
546 |
|
|
// << " ---- softElecs: " << lBtag.softElectronByPt << " " << lBtag.softElectronByIP3d << std::endl
|
547 |
|
|
// << " ---- softMus: " << lBtag.softMuon << " " << lBtag.softMuonByPt << " " << lBtag.softMuonByIP3d << std::endl;
|
548 |
|
|
|
549 |
|
|
if (debug_>1) {
|
550 |
|
|
std::cout << " -- Filling tag info variables : "
|
551 |
|
|
<< (*iter).hasTagInfo("SecondaryVertex")
|
552 |
|
|
<< std::endl;
|
553 |
|
|
}
|
554 |
|
|
|
555 |
|
|
std::vector<HbbAnalysis::JetSecVertexVars> jetSecVertexVars;
|
556 |
|
|
|
557 |
|
|
for (unsigned iVtx = 0; iVtx < (*iter).tagInfoSecondaryVertex()->nVertices(); ++iVtx){
|
558 |
|
|
HbbAnalysis::JetSecVertexVars jetSecVertexVarsTmp;
|
559 |
|
|
math::XYZTLorentzVectorD vec = (*iter).tagInfoSecondaryVertex()->secondaryVertex(iVtx).p4();
|
560 |
|
|
jetSecVertexVarsTmp.fourVec.e = vec.E();
|
561 |
|
|
jetSecVertexVarsTmp.fourVec.px = vec.Px();
|
562 |
|
|
jetSecVertexVarsTmp.fourVec.py = vec.Py();
|
563 |
|
|
jetSecVertexVarsTmp.fourVec.pz = vec.Pz();
|
564 |
|
|
jetSecVertexVarsTmp.vertex.vx = (*iter).tagInfoSecondaryVertex()->secondaryVertex(iVtx).x();
|
565 |
|
|
jetSecVertexVarsTmp.vertex.vy = (*iter).tagInfoSecondaryVertex()->secondaryVertex(iVtx).y();
|
566 |
|
|
jetSecVertexVarsTmp.vertex.vz = (*iter).tagInfoSecondaryVertex()->secondaryVertex(iVtx).z();
|
567 |
|
|
jetSecVertexVars.push_back(jetSecVertexVarsTmp);
|
568 |
|
|
}
|
569 |
|
|
|
570 |
|
|
|
571 |
|
|
bool isPF = (*iter).isPFJet();
|
572 |
|
|
if (debug_>1) {
|
573 |
|
|
std::cout << " -- Filling JPTPF jet variables " << std::endl;
|
574 |
|
|
}
|
575 |
|
|
|
576 |
|
|
HbbAnalysis::JPTPFJetVars lJPTPF;
|
577 |
|
|
if (isPF){
|
578 |
|
|
lJPTPF.chargedEmEnergy = (*iter).chargedEmEnergy();
|
579 |
|
|
lJPTPF.neutralEmEnergy = (*iter).neutralEmEnergy();
|
580 |
|
|
lJPTPF.muonMultiplicity = (*iter).muonMultiplicity();
|
581 |
|
|
lJPTPF.chargedHadronEnergy = (*iter).chargedHadronEnergy();
|
582 |
|
|
lJPTPF.neutralHadronEnergy = (*iter).neutralHadronEnergy();
|
583 |
|
|
lJPTPF.chargedMultiplicity = (*iter).chargedMultiplicity();
|
584 |
|
|
lJPTPF.chargedHadronEnergyFraction = (*iter).chargedHadronEnergyFraction();
|
585 |
|
|
lJPTPF.neutralHadronEnergyFraction = (*iter).neutralHadronEnergyFraction();
|
586 |
|
|
lJPTPF.chargedEmEnergyFraction = (*iter).chargedEmEnergyFraction();
|
587 |
|
|
lJPTPF.neutralEmEnergyFraction = (*iter).neutralEmEnergyFraction();
|
588 |
|
|
}
|
589 |
|
|
if (debug_>1) {
|
590 |
|
|
std::cout << " -- Filling PF jet variables " << std::endl;
|
591 |
|
|
}
|
592 |
|
|
if (isPF) {
|
593 |
|
|
HbbAnalysis::PFJetVars lPF;
|
594 |
|
|
lPF.chargedMuEnergy = (*iter).chargedMuEnergy();
|
595 |
|
|
lPF.chargedMuEnergyFraction = (*iter).chargedMuEnergyFraction();
|
596 |
|
|
lPF.neutralMultiplicity = (*iter).neutralMultiplicity();
|
597 |
|
|
lPF.numberOfDaughters = (*iter).numberOfDaughters();
|
598 |
|
|
lPF.HFHadronEnergy = (*iter).HFHadronEnergy();
|
599 |
|
|
|
600 |
|
|
HbbAnalysis::Jet lObj(lFourVec,lJet,lPF,lJPTPF,lBtag,lEnergyCorrections);
|
601 |
|
|
lObj.secVertexVars(jetSecVertexVars);
|
602 |
|
|
aVec.push_back(lObj);
|
603 |
|
|
}
|
604 |
|
|
|
605 |
|
|
if (debug_>1) {
|
606 |
|
|
std::cout << " -- Element added. " << std::endl;
|
607 |
|
|
}
|
608 |
|
|
|
609 |
|
|
}//loop on element
|
610 |
|
|
}//non empty
|
611 |
|
|
}//valid
|
612 |
|
|
|
613 |
|
|
}//HbbJets
|
614 |
|
|
|
615 |
|
|
|
616 |
amagnan |
1.1 |
#include "FWCore/Framework/interface/MakerMacros.h"
|
617 |
|
|
DEFINE_FWK_MODULE(MCTreeMaker);
|
618 |
|
|
|
619 |
|
|
|