9 #include <marlin/AIDAProcessor.h>
10 #include <AIDA/IHistogramFactory.h>
11 #include <AIDA/ICloud1D.h>
15 #include <EVENT/LCCollection.h>
16 #include <EVENT/LCObject.h>
17 #include <IMPL/LCCollectionVec.h>
18 #include <EVENT/LCRelation.h>
19 #include <EVENT/MCParticle.h>
20 #include <EVENT/ReconstructedParticle.h>
21 #include <IMPL/ReconstructedParticleImpl.h>
22 #include <IMPL/VertexImpl.h>
23 #include "UTIL/LCRelationNavigator.h"
25 #include <gear/GEAR.h>
26 #include <gear/BField.h>
27 #include <marlin/Global.h>
29 #include "HelixClass.h"
30 #include "SimpleLine.h"
32 #include "marlin/VerbosityLevels.h"
39 using namespace lcio ;
40 using namespace marlin ;
46 double E,phi,
theta,D0,NQ,N,minv;
51 return fabs(p1.
phi) > fabs(p2.
phi);
57 _description =
"EvaluateTauFinder checks performance of TauFinder and writes output to root file." ;
61 registerProcessorParameter(
"FileName_Signal",
62 "Name of the Signal output file " ,
64 std::string(
"Signal.root") ) ;
68 registerInputCollection( LCIO::MCPARTICLE,
70 "Name of the MCParticle collection" ,
72 std::string(
"MCParticlesSkimmed") ) ;
74 registerInputCollection( LCIO::LCRELATION,
75 "RECOMCTRUTHCollectionName" ,
76 "Name of the MC Truth PFA collection" ,
78 std::string(
"RecoMCTruthLink") ) ;
80 registerInputCollection( LCIO::RECONSTRUCTEDPARTICLE,
82 "Collection of Tau Candidates",
84 std::string(
"TauRec_PFO"));
86 registerInputCollection( LCIO::LCRELATION,
87 "TauLinkCollectionName" ,
88 "Name of the link between tau and pfos" ,
90 std::string(
"TauRecLink_PFO") ) ;
101 streamlog_out(DEBUG) <<
" init called "
120 evtuple=
new TNtuple(
"evtuple",
"evtuple",
"EvID:Ntaus_mc:Ntaus_rec:missed:WpD1:WpD2:WmD1:WmD2:LD");
121 tautuple=
new TNtuple(
"tautuple",
"tautuple",
"EvID:mcE:mcPhi:mcTheta:mcD0:recE:recPhi:recTheta:recD0:recNQ:recN:minv");
122 mcmisstuple=
new TNtuple(
"mcmiss",
"mcmiss",
"EvID:E:pt:theta:D0:D1:D2");
123 taumatchtuple=
new TNtuple(
"taumatch",
"taumatch",
"EvID:E:mcE:mcp:mcpt:mcPhi:mcTheta:mcD0:recE:recp:recpt:recPhi:recTheta:recD0");
124 tauexacttuple=
new TNtuple(
"tauexact",
"tauexact",
"EvID:E:mcE:mcp:mcpt:mcD0:recE:recp:recpt:recD0:ED0seed");
125 faketuple =
new TNtuple(
"fake",
"fake",
"EvID:parentpdg:D1:D2:recE:recp:recD0:pt:theta:N");
126 topofaketuple =
new TNtuple(
"topofake",
"topofake",
"EvID:nfake:WpD1:WpD2:WmD1:WmD2");
127 leptons=
new TNtuple(
"Leptons",
"Leptons",
"EvID:PDG");
141 LCCollection *colMC, *colMCTruth, *colTau;
142 LCCollection *colTauRecLink;
145 }
catch (Exception&
e) {
150 colTau = evt->getCollection(
_incol ) ;
151 }
catch (Exception& e) {
157 }
catch (Exception& e) {
163 }
catch (Exception& e) {
169 _nEvt = evt->getEventNumber();
175 LCRelationNavigator* relationNavigatorTau = 0;
176 LCRelationNavigator* relationNavigatorPFOMC = 0;
177 if( colTauRecLink != 0)
178 relationNavigatorTau =
new LCRelationNavigator( colTauRecLink );
180 relationNavigatorPFOMC =
new LCRelationNavigator( colMCTruth );
185 std::vector<TAU> rectauvec;
188 int nT = colTau->getNumberOfElements();
192 streamlog_out(DEBUG) <<
"EVENT "<<
_nEvt<<
" with "<<nT<<
" taus"<<endl;
193 HelixClass *helix =
new HelixClass();
194 HelixClass *mc_helix =
new HelixClass();
195 for(
int k=0;
k < nT;
k++)
197 ReconstructedParticle *tau =
static_cast<ReconstructedParticle*
>( colTau->getElementAt(
k ) );
198 const double *pvec=tau->getMomentum();
199 double pt=sqrt(pvec[0]*pvec[0]+pvec[1]*pvec[1]);
200 double p=sqrt(pvec[0]*pvec[0]+pvec[1]*pvec[1]+pvec[2]*pvec[2]);
201 double phi=180./TMath::Pi()*atan(pvec[1]/pvec[0]);
202 double theta=180./TMath::Pi()*atan(pt/fabs(pvec[2]));
203 std::vector< ReconstructedParticle * > tauvec=tau->getParticles();
209 for(
unsigned int o=0;o<tauvec.size();o++)
212 if(tauvec[o]->getCharge()!=0)
215 if(tauvec[o]->getEnergy()>Eseed && tauvec[o]->getTracks().size()!=0 )
217 D0=(float)tauvec[o]->getTracks()[0]->getD0();
218 Eseed=tauvec[o]->getEnergy();
222 if(tauvec[o]->getType()==11 ||tauvec[o]->getType()==13)
244 streamlog_out(DEBUG) <<tau->getEnergy()<<
" "<<phi<<
" "<<theta<<
" "<<D0<<
" "<<tauvec.size()<<endl;
247 rtau.
E=tau->getEnergy();
251 rtau.
N=tauvec.size();
254 if(tau->getEnergy()*tau->getEnergy()<p*p)
255 mass_inv=tau->getEnergy()-sqrt(p*p);
257 mass_inv=sqrt(tau->getEnergy()*tau->getEnergy()-p*p);
259 rectauvec.push_back(rtau);
263 if(relationNavigatorTau)
266 bool contaminated=
false;
267 MCParticle *mctau=NULL;
268 EVENT::LCObjectVec relobjFROM = relationNavigatorTau->getRelatedToObjects(tau);
269 for(
unsigned int o=0;o<relobjFROM.size();o++)
271 ReconstructedParticle *rec=
static_cast<ReconstructedParticle*
>(relobjFROM[o]);
272 if(relationNavigatorPFOMC)
274 EVENT::LCObjectVec relobjMC = relationNavigatorPFOMC->getRelatedToObjects(rec);
275 for(
unsigned int m=0;
m<relobjMC.size();
m++)
277 MCParticle *mc=
static_cast<MCParticle*
>(relobjMC[
m]);
279 MCParticle *dummy=mc;
280 MCParticle *parent=mc;
287 int size=mc->getParents().size();
290 dummy=parent->getParents()[0];
291 size=dummy->getParents().size();
293 if(fabs(parent->getPDG())==15)
296 if(fabs(parent->getPDG())==15)
312 const double *mc_pvec=mctau->getMomentum();
313 double mc_pt=sqrt(mc_pvec[0]*mc_pvec[0]+mc_pvec[1]*mc_pvec[1]);
314 double mc_phi=180./TMath::Pi()*atan(mc_pvec[1]/mc_pvec[0]);
315 double mc_theta=180./TMath::Pi()*atan(mc_pt/fabs(mc_pvec[2]));
317 for (
int icomp=0; icomp<3; ++icomp) {
318 mc_mom[icomp]=(float)mctau->getMomentum()[icomp];
319 mc_ver[icomp]=(float)mctau->getDaughters()[0]->getVertex()[icomp];
321 float mc_charge = mctau->getCharge();
322 mc_helix->Initialize_VP(mc_ver,mc_mom,mc_charge,
_bField);
323 double mc_D0=fabs(mc_helix->getD0());
324 double Evis=0,ptvis=0,pvis=0;
328 taumatchtuple->Fill(
_nEvt,mctau->getEnergy(),Evis,pvis,ptvis,mc_phi,mc_theta,mc_D0,tau->getEnergy(),p,pt,phi,theta,D0,LD);
330 tauexacttuple->Fill(
_nEvt,mctau->getEnergy(),Evis,pvis,ptvis,mc_D0,tau->getEnergy(),p,pt,D0,Eseed,LD);
331 _dEsum+=Evis-tau->getEnergy();
332 _dEsumsq+=(Evis-tau->getEnergy())*(Evis-tau->getEnergy());
340 for(
unsigned int o=0;o<relobjFROM.size();o++)
342 ReconstructedParticle *rec=
static_cast<ReconstructedParticle*
>(relobjFROM[o]);
343 if(relationNavigatorPFOMC)
345 EVENT::LCObjectVec relobj = relationNavigatorPFOMC->getRelatedToObjects(rec);
346 for(
unsigned int m=0;
m<relobj.size();
m++)
348 MCParticle *mc=
static_cast<MCParticle*
>(relobj[
m]);
352 if(mc->getCharge()==0)
354 MCParticle *dummy=mc;
355 MCParticle *parent=mc;
356 int size=mc->getParents().size();
359 dummy=parent->getParents()[0];
360 size=dummy->getParents().size();
362 if(parent->getGeneratorStatus()==2)
365 pdg=parent->getPDG();
366 if(parent->getDaughters().size())
367 d1=parent->getDaughters()[0]->getPDG();
368 if(parent->getDaughters().size()>1)
369 d2=parent->getDaughters()[1]->getPDG();
373 const double *tpvec=tau->getMomentum();
374 double tpt=sqrt(tpvec[0]*tpvec[0]+tpvec[1]*tpvec[1]);
375 double ttheta=180./TMath::Pi()*atan(tpt/fabs(tpvec[2]));
376 faketuple->Fill(
_nEvt,pdg,d1,d2,tau->getEnergy(),p,D0,tpt,ttheta,tau->getParticles().size());
387 int D1=0,D2=0,D3=0,D4=0;
388 std::vector<TAU> mctauvec;
391 int nMCP = colMC->getNumberOfElements();
393 streamlog_out(DEBUG) <<
"MCTRUTH: "<<endl;
394 HelixClass * helix =
new HelixClass();
395 for(
int k=0;
k < nMCP;
k++)
397 MCParticle *particle =
static_cast<MCParticle*
>(colMC->getElementAt(
k) );
399 if(particle->getGeneratorStatus()==2 && fabs(particle->getPDG())==15 && particle->getDaughters().size()>1 )
401 if(fabs(particle->getDaughters()[0]->getPDG())==15)
405 const double *pvec=particle->getMomentum();
406 double pt=sqrt(pvec[0]*pvec[0]+pvec[1]*pvec[1]);
407 double phi=180./TMath::Pi()*atan(pvec[1]/pvec[0]);
408 double theta=180./TMath::Pi()*atan(pt/fabs(pvec[2]));
411 for (
int icomp=0; icomp<3; ++icomp) {
412 mom[icomp]=(float)particle->getMomentum()[icomp];
413 ver[icomp]=(float)particle->getDaughters()[0]->getVertex()[icomp];
415 float charge = particle->getCharge();
416 helix->Initialize_VP(ver,mom,charge,
_bField);
417 double D0=fabs(helix->getD0());
418 double Evis=0,ptvis=0,pvis=0;
426 mctauvec.push_back(mctau);
428 streamlog_out(DEBUG) <<Evis<<
" "<<phi<<
" "<<theta<<
" "<<D0<<endl;
431 if(relationNavigatorPFOMC && relationNavigatorTau )
439 if(particle->getDaughters().size()==2)
441 d1=particle->getDaughters()[0]->getPDG();
442 d2=particle->getDaughters()[1]->getPDG();
446 streamlog_out(DEBUG) <<
"Missed: "<<Evis<<
" "<<D0<<
" "<<d1<<
" "<<d2<<endl;
450 if(particle->getGeneratorStatus()<3 && fabs(particle->getPDG())==24)
452 if(particle->getPDG()==24 && particle->getDaughters().size()==2)
454 D1=particle->getDaughters()[0]->getPDG();
455 D2=particle->getDaughters()[1]->getPDG();
457 if(particle->getPDG()==-24 && particle->getDaughters().size()==2)
459 D3=particle->getDaughters()[0]->getPDG();
460 D4=particle->getDaughters()[1]->getPDG();
469 evtuple->Fill(
_nEvt,ntau_mc,ntau_rec,missed,D1,D2,D3,D4,LDev);
471 std::sort(mctauvec.begin(), mctauvec.end(),
MyAngleSort);
472 std::sort(rectauvec.begin(), rectauvec.end(),
MyAngleSort);
474 unsigned int common=mctauvec.size();
475 if(mctauvec.size()>rectauvec.size())
476 common=rectauvec.size();
477 for(
unsigned int p=0;p<common;p++)
478 tautuple->Fill(
_nEvt,mctauvec[p].E,mctauvec[p].phi,mctauvec[p].theta,mctauvec[p].D0,rectauvec[p].E,rectauvec[p].phi,
479 rectauvec[p].theta,rectauvec[p].D0,rectauvec[p].NQ,rectauvec[p].N,rectauvec[p].minv);
480 if(mctauvec.size()>rectauvec.size())
482 for(
unsigned int p=common;p<mctauvec.size();p++)
483 tautuple->Fill(
_nEvt,mctauvec[p].E,mctauvec[p].phi,mctauvec[p].theta,mctauvec[p].D0,0,0,0,0,0,0);
485 if(mctauvec.size()<rectauvec.size())
487 for(
unsigned int p=common;p<rectauvec.size();p++)
488 tautuple->Fill(
_nEvt,0,0,0,0,rectauvec[p].E,rectauvec[p].phi,rectauvec[p].theta,rectauvec[p].D0,rectauvec[p].NQ,rectauvec[p].N,rectauvec[p].minv);
494 delete relationNavigatorTau;
495 delete relationNavigatorPFOMC;
501 for(
unsigned int d=0;d<particle->getDaughters().size();d++)
503 MCParticle *daughter=particle->getDaughters()[d];
505 if(daughter->hasLeftDetector()==
false || fabs(daughter->getPDG())==13)
507 if (daughter->getGeneratorStatus()==1)
510 if(!( fabs(daughter->getPDG())==12 || fabs(daughter->getPDG())==14 || fabs(daughter->getPDG())==16
511 || fabs(daughter->getPDG())==1000022))
515 Evis+=daughter->getEnergy();
516 const double *mc_pvec=daughter->getMomentum();
517 ptvis+=sqrt(mc_pvec[0]*mc_pvec[0]+mc_pvec[1]*mc_pvec[1]);
518 pvis+=sqrt(mc_pvec[0]*mc_pvec[0]+mc_pvec[1]*mc_pvec[1]+mc_pvec[2]*mc_pvec[2]);
523 if(daughter->getDaughters().size())
529 LCRelationNavigator* relationNavigatorPFOMC ,
bool &relToTau)
531 for(
unsigned int d=0;d<particle->getDaughters().size();d++)
533 MCParticle *daughter=particle->getDaughters()[d];
535 if(daughter->hasLeftDetector()==
false || fabs(daughter->getPDG())==13)
537 if (daughter->getGeneratorStatus()==1)
540 EVENT::LCObjectVec relobjTO = relationNavigatorPFOMC->getRelatedFromObjects(daughter);
541 for(
unsigned int o=0;o<relobjTO.size();o++)
544 ReconstructedParticle *rec=
static_cast<ReconstructedParticle*
>(relobjTO[o]);
545 EVENT::LCObjectVec relobj = relationNavigatorTau->getRelatedFromObjects(rec);
553 if(daughter->getDaughters().size())
568 streamlog_out(DEBUG) <<
"EvaluateTauFinder::end() " << name()
569 <<
" processed " <<
_nEvt <<
" events in " <<
_nRun <<
" runs "<<std::endl;
virtual void processRunHeader(LCRunHeader *run)
Called for every run.
virtual void end()
Called after data processing for clean up.
CLHEP::Hep3Vector Vector3D
virtual void LoopDaughtersRelation(MCParticle *particle, LCRelationNavigator *relationNavigatorTau, LCRelationNavigator *relationNavigatorMC, bool &ralToTau)
virtual void check(LCEvent *evt)
EvaluateTauFinder aEvaluateTauFinder
bool MyAngleSort(TAU p1, TAU p2)
virtual void LoopDaughters(MCParticle *particle, double &Evis, double &ptvis, double &pvis)
std::string _colNameTauRecLink
std::string _colNameMC
Input collection name.
virtual void init()
Called at the begin of the job before anything is read.
virtual void processEvent(LCEvent *evt)
Called for every event - the working horse.
Evaluation processor for TauFinder.
std::string _colNameMCTruth
std::string _OutputFile_Signal