10 #include <EVENT/LCCollection.h>
11 #include <EVENT/MCParticle.h>
12 #include <IMPL/LCCollectionVec.h>
13 #include <EVENT/ReconstructedParticle.h>
14 #include <IMPL/ReconstructedParticleImpl.h>
15 #include <EVENT/Cluster.h>
16 #include <UTIL/LCTypedVector.h>
17 #include <EVENT/Track.h>
18 #include <UTIL/LCRelationNavigator.h>
19 #include <EVENT/ParticleID.h>
20 #include <marlin/Exceptions.h>
21 #include <EVENT/Vertex.h>
24 #include "marlin/VerbosityLevels.h"
32 #include "TLorentzVector.h"
38 using namespace lcio ;
39 using namespace marlin ;
42 using namespace isolep;
50 _description =
"IsoLepTrainingProcessor does whatever it does ..." ;
55 registerInputCollection( LCIO::MCPARTICLE,
56 "InputMCParticlesCollection" ,
57 "Name of the MCParticle collection" ,
59 std::string(
"MCParticlesSkimmed") ) ;
61 registerInputCollection( LCIO::LCRELATION,
62 "InputMCTruthLinkCollection" ,
63 "Name of the MCTruthLink collection" ,
65 std::string(
"RecoMCTruthLink") ) ;
67 registerInputCollection( LCIO::RECONSTRUCTEDPARTICLE,
68 "InputPandoraPFOsCollection" ,
69 "Name of the PandoraPFOs collection" ,
71 std::string(
"PandoraPFOs") ) ;
73 registerInputCollection( LCIO::VERTEX,
74 "InputPrimaryVertexCollection" ,
75 "Name of the Primary Vertex collection" ,
77 std::string(
"PrimaryVertex") ) ;
79 registerProcessorParameter(
"IsLepTune",
84 registerProcessorParameter(
"MCDebugging" ,
85 "set true if you want to check generator information",
90 registerProcessorParameter(
"IsForSignal",
95 registerProcessorParameter(
"IsoLepType",
96 "Isolated Lepton Type" ,
103 streamlog_out(DEBUG) <<
" init called "
128 Double_t fEtrackCut = -1.;
130 Double_t fEtrackCut = 0.05;
132 Double_t fCosConeCut = 0.98;
133 Double_t fCosLargeConeCut = 0.95;
135 TDirectory *last = gDirectory;
138 cerr << endl <<
"Hello, MVA Lepton Training! Event No. " <<
_nEvt << endl;
140 static TNtupleD *hGen = 0;
142 stringstream tupstr_gen;
143 tupstr_gen <<
"nhbb:pdg:npvt:zipmc:xipmc:yipmc:zipvf:xipvf:yipvf:nlepmc:ievt:seriallep:iov:xerrip:yerrip:zerrip:ntrksip" <<
":"
146 hGen =
new TNtupleD(
"hGen",
"",tupstr_gen.str().data());
148 static TNtupleD *hLep = 0;
150 stringstream tupstr_lep;
151 tupstr_lep <<
"pdg:nlepmc:ievt:seriallep:iov:orig"
153 hLep =
new TNtupleD(
"hLep",
"",tupstr_lep.str().data());
157 LCCollection *colMCTL = evt->getCollection(
_colMCTL);
158 LCRelationNavigator *navMCTL =
new LCRelationNavigator(colMCTL);
162 LCCollection *colMC = evt->getCollection(
_colMCP);
164 std::cerr <<
"No MC Collection Found!" << std::endl;
165 throw marlin::SkipEventException(
this);
168 Int_t nMCP = colMC->getNumberOfElements();
170 Int_t pdgLepMC = -1,serialLepMC = -1,nMCLep=0,iOvlLepMC=-999;
171 Double_t z_IPMC=999.,x_IPMC=999.,y_IPMC=999.;
172 std::vector<Int_t> pdgLepMCv,serialLepMCv;
173 TLorentzVector lortzLepMC;
176 for (Int_t i=0;i<nMCP;i++) {
177 MCParticle *mcPart =
dynamic_cast<MCParticle*
>(colMC->getElementAt(i));
178 Int_t pdg = mcPart->getPDG();
179 Double_t energy = mcPart->getEnergy();
180 TVector3 pv = TVector3(mcPart->getMomentum());
181 TLorentzVector lortz = TLorentzVector(pv,energy);
184 Int_t status = mcPart->getGeneratorStatus();
186 if (TMath::Abs(pdg) == 11 || TMath::Abs(pdg) == 13 || TMath::Abs(pdg) == 15) {
188 pdgLepMCv.push_back(pdgLepMC);
191 Int_t origw = pdgLepMC > 0? -24 : 24;
197 serialLepMCv.push_back(i);
199 iOvlLepMC = mcPart->isOverlay() ? 1 : 0;
201 Double_t data_lep[20];
203 data_lep[ 1] = nMCLep;
204 data_lep[ 2] =
_nEvt;
205 data_lep[ 3] = serialLepMC;
206 data_lep[ 4] = iOvlLepMC;
208 hLep->Fill(data_lep);
211 TVector3 vip = TVector3(mcPart->getVertex());
225 LCCollection *colPVtx = evt->getCollection(
_colPVtx);
226 Int_t npvtx = colPVtx->getNumberOfElements();
227 Vertex *pvtx =
dynamic_cast<Vertex*
>(colPVtx->getElementAt(0));
228 TVector3 v_pvtx = TVector3(pvtx->getPosition());
229 Double_t z_pvtx = v_pvtx[2];
230 Double_t x_pvtx = v_pvtx[0];
231 Double_t y_pvtx = v_pvtx[1];
232 Double_t xerr_pvtx = TMath::Sqrt(pvtx->getCovMatrix()[0]);
233 Double_t yerr_pvtx = TMath::Sqrt(pvtx->getCovMatrix()[2]);
234 Double_t zerr_pvtx = TMath::Sqrt(pvtx->getCovMatrix()[5]);
236 ReconstructedParticle *pvtx_rp = pvtx->getAssociatedParticle();
237 Int_t ntrks_pvtx = pvtx_rp->getParticles().size();
239 std::vector<Int_t> nHDecay;
241 Double_t nHbb = nHDecay[0];
242 Double_t data_gen[20];
244 data_gen[ 1] = pdgLepMC;
245 data_gen[ 2] = npvtx;
246 data_gen[ 3] = z_IPMC;
247 data_gen[ 4] = x_IPMC;
248 data_gen[ 5] = y_IPMC;
249 data_gen[ 6] = z_pvtx;
250 data_gen[ 7] = x_pvtx;
251 data_gen[ 8] = y_pvtx;
252 data_gen[ 9] = nMCLep;
253 data_gen[10] =
_nEvt;
254 data_gen[11] = serialLepMC;
255 data_gen[12] = iOvlLepMC;
256 data_gen[13] = xerr_pvtx;
257 data_gen[14] = yerr_pvtx;
258 data_gen[15] = zerr_pvtx;
259 data_gen[16] = ntrks_pvtx;
260 data_gen[17] = lortzLepMC.CosTheta();
261 data_gen[18] = lortzLepMC.Phi();
262 data_gen[19] = lortzLepMC.P();
263 hGen->Fill(data_gen);
267 std::cerr <<
"This is not an signal event with isolated muon or electron" << std::endl;
268 throw marlin::SkipEventException(
this);
273 LCCollection *colPFO = evt->getCollection(
_colPFOs);
275 std::cerr <<
"No PFO Collection Found!" << std::endl;
276 throw marlin::SkipEventException(
this);
278 Int_t nPFOs = colPFO->getNumberOfElements();
280 static TNtupleD *hPfo = 0;
282 stringstream tupstr_pfo;
283 tupstr_pfo <<
"ntracks:charge:mcpdg:motherpdg:deltae:mmotherpdg:ndaughters" <<
":"
284 <<
"mcoriginal:energy:type:pid" <<
":"
285 <<
"totalcalenergy:momentum:ecalenergy:hcalenergy:coneenergy" <<
":"
286 <<
"nmctl:mcwgt:ievt:irun" <<
":"
287 <<
"nhits:ncones:nconechg:nconeneu:coneec:coneen:energylink" <<
":"
288 <<
"costheta:yokeenergy:energycor:momentumcor" <<
":"
289 <<
"d0:z0:r0:deltad0:deltaz0:nsigd0:nsigz0:nsigr0:iov" <<
":"
290 <<
"coslarcon:energyratio:nphoton:ratioecal:ratiototcal" <<
":"
291 <<
"isim:pdgmc:orig:isorig:zipvf:zipmc" <<
":"
292 <<
"x0:y0:xipmc:yipmc:xipvf:yipvf:mcserial:serialLepMC" <<
":"
295 hPfo =
new TNtupleD(
"hPfo",
"",tupstr_pfo.str().data());
299 for (Int_t i=0;i<nPFOs;i++) {
300 ReconstructedParticle *recPart =
dynamic_cast<ReconstructedParticle*
>(colPFO->getElementAt(i));
301 LCObjectVec vecMCTL = navMCTL->getRelatedToObjects(recPart);
302 FloatVec vecWgtMCTL = navMCTL->getRelatedToWeights(recPart);
303 Int_t mcpdg,motherpdg,mmotherpdg;
308 Double_t deltaE = -99999.;
309 Double_t energyLink = -99999.;
310 Int_t mcoriginal = 0;
311 Int_t mcoriginalIsoLep = 0;
312 Int_t mcndaughters = 0;
313 Int_t nMCTL = vecMCTL.size();
315 Int_t iCreatedInSim = 0;
318 if (vecMCTL.size() > 0) {
321 if (!mcPart)
continue;
322 if (mcPart->isOverlay()) iOverlay = 1;
323 if (mcPart->isCreatedInSimulation()) iCreatedInSim = 1;
324 mcpdg = mcPart->getPDG();
326 deltaE = mcPart->getEnergy()-recPart->getEnergy();
327 energyLink = mcPart->getEnergy();
332 mcndaughters = mcPart->getDaughters().size();
333 if (mcPart->getParents().size() != 0) {
334 MCParticle *motherPart = mcPart->getParents()[0];
335 motherpdg = motherPart->getPDG();
337 if (motherPart->getParents().size() != 0) {
338 MCParticle *mmotherPart = motherPart->getParents()[0];
339 mmotherpdg = mmotherPart->getPDG();
347 for (
size_t j=0;j<serialLepMCv.size();j++) {
348 if (mcserial == serialLepMCv[j]) {
356 Double_t energy = recPart->getEnergy();
357 Double_t charge = recPart->getCharge();
358 Int_t itype = recPart->getType();
360 TrackVec tckvec = recPart->getTracks();
361 Int_t ntracks = tckvec.size();
362 Double_t d0=0.,z0=0.,deltad0=0.,deltaz0=0.,nsigd0=0.,nsigz0=0.;
363 Double_t phi0=0.,x0=0.,y0=0.;
365 d0 = tckvec[0]->getD0();
366 z0 = tckvec[0]->getZ0();
367 phi0 = tckvec[0]->getPhi();
368 x0 = -d0*TMath::Sin(phi0);
369 y0 = d0*TMath::Cos(phi0);
373 deltad0 = TMath::Sqrt(tckvec[0]->getCovMatrix()[0]);
374 deltaz0 = TMath::Sqrt(tckvec[0]->getCovMatrix()[9]);
378 Double_t r0 = TMath::Sqrt(d0*d0+z0*z0);
379 Double_t nsigr0 = TMath::Sqrt(nsigd0*nsigd0+nsigz0*nsigz0);
386 data[5] = mmotherpdg;
387 data[6] = mcndaughters;
388 data[7] = mcoriginal;
392 if (energy > fEtrackCut) {
393 Double_t ecalEnergy = 0;
394 Double_t hcalEnergy = 0;
395 Double_t yokeEnergy = 0;
396 Double_t totalCalEnergy = 0;
398 std::vector<lcio::Cluster*> clusters = recPart->getClusters();
399 for (std::vector<lcio::Cluster*>::const_iterator iCluster=clusters.begin();iCluster!=clusters.end();++iCluster) {
400 ecalEnergy += (*iCluster)->getSubdetectorEnergies()[0];
401 hcalEnergy += (*iCluster)->getSubdetectorEnergies()[1];
402 yokeEnergy += (*iCluster)->getSubdetectorEnergies()[2];
403 ecalEnergy += (*iCluster)->getSubdetectorEnergies()[3];
404 hcalEnergy += (*iCluster)->getSubdetectorEnergies()[4];
405 CalorimeterHitVec calHits = (*iCluster)->getCalorimeterHits();
407 nHits = calHits.size();
409 totalCalEnergy = ecalEnergy + hcalEnergy;
410 TVector3 momentum = TVector3(recPart->getMomentum());
411 Double_t momentumMagnitude = momentum.Mag();
412 Double_t cosTheta = momentum.CosTheta();
416 Bool_t woFSR = kTRUE;
417 Double_t coneEnergy0[3] = {0.,0.,0.};
418 Double_t pFSR[4] = {0.,0.,0.,0.};
419 Double_t pLargeCone[4] = {0.,0.,0.,0.};
420 Int_t nConePhoton = 0;
422 getConeEnergy(recPart,colPFO,fCosConeCut,woFSR,coneEnergy0,pFSR,fCosLargeConeCut,pLargeCone,nConePhoton);
423 Double_t coneEnergy = coneEnergy0[0];
424 Double_t coneEN = coneEnergy0[1];
425 Double_t coneEC = coneEnergy0[2];
426 TLorentzVector lortzFSR = TLorentzVector(pFSR[0],pFSR[1],pFSR[2],pFSR[3]);
427 TLorentzVector lortzLargeCone = TLorentzVector(pLargeCone[0],pLargeCone[1],pLargeCone[2],pLargeCone[3]);
428 TVector3 momentumLargeCone = lortzLargeCone.Vect();
429 Double_t cosThetaWithLargeCone = 1.;
430 if (momentumLargeCone.Mag() > 0.0000001) {
431 cosThetaWithLargeCone = momentum.Dot(momentumLargeCone)/momentumMagnitude/momentumLargeCone.Mag();
433 Double_t energyRatioWithLargeCone = energy/(energy+lortzLargeCone.E());
434 Double_t energyCorr = energy + lortzFSR.E();
435 TVector3 momentumCorr = momentum + TVector3(lortzFSR.Px(),lortzFSR.Py(),lortzFSR.Pz());
436 Double_t momentumMagCorr = momentumCorr.Mag();
437 Double_t ratioECal = 0., ratioTotalCal = 0.;
438 if (ecalEnergy > 0.) ratioECal = ecalEnergy/totalCalEnergy;
440 ratioTotalCal = totalCalEnergy/(momentumMagnitude+0.00000001);
443 Int_t nConeCharged = 0;
444 Int_t nConeNeutral = 0;
446 data[11] = totalCalEnergy;
447 data[12] = momentumMagnitude;
448 data[13] = ecalEnergy;
449 data[14] = hcalEnergy;
450 data[15] = coneEnergy;
456 data[21] = nConePFOs;
457 data[22] = nConeCharged;
458 data[23] = nConeNeutral;
461 data[26] = energyLink;
463 data[28] = yokeEnergy;
464 data[29] = energyCorr;
465 data[30] = momentumMagCorr;
475 data[40] = cosThetaWithLargeCone;
476 data[41] = energyRatioWithLargeCone;
477 data[42] = nConePhoton;
478 data[43] = ratioECal;
479 data[44] = ratioTotalCal;
480 data[45] = iCreatedInSim;
482 data[47] = mcoriginalIsoLep;
483 data[48] = isOrigLep;
493 data[58] = serialLepMC;
494 data[59] = lortzLepMC.CosTheta();
495 data[60] = lortzLepMC.Phi();
496 data[61] = lortzLepMC.P();
499 if (isOrigLep==1) hPfo->Fill(data);
510 streamlog_out(DEBUG) <<
" processing event: " << evt->getEventNumber()
511 <<
" in run: " << evt->getRunNumber()
528 cerr <<
"IsoLepTrainingProcessor::end() " << name()
529 <<
" processed " <<
_nEvt <<
" events in " <<
_nRun <<
" runs "
Int_t getOriginalPDGForIsoLep(MCParticle *mcPart, LCCollection *colMC)
void mcDebug(LCCollection *colMC)
Example processor for marlin.
IsoLepTrainingProcessor aIsoLepTrainingProcessor
std::string _colMCP
Input collection name.
Double_t getConeEnergy(ReconstructedParticle *recPart, LCCollection *colPFO, Double_t cosCone)
virtual void processEvent(LCEvent *evt)
Called for every event - the working horse.
Int_t getOriginalPDG(MCParticle *mcPart, Bool_t iHiggs=0)
Int_t getMCSerial(MCParticle *mcPart, LCCollection *colMCP)
virtual void init()
Called at the begin of the job before anything is read.
IsoLepTrainingProcessor()
MCParticle * getMCParticle(ReconstructedParticle *recPart, LCCollection *colMCTL)
virtual void check(LCEvent *evt)
virtual void end()
Called after data processing for clean up.
std::vector< Int_t > getHiggsDecayModes(LCCollection *colMC)
virtual void processRunHeader(LCRunHeader *run)
Called for every run.