All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
TauFinder.cc
Go to the documentation of this file.
1 #include "TauFinder.h"
2 #include <iostream>
3 #include <iomanip>
4 
5 using namespace std;
6 
7 
8 #ifdef MARLIN_USE_AIDA
9 #include <marlin/AIDAProcessor.h>
10 #include <AIDA/IHistogramFactory.h>
11 #include <AIDA/ICloud1D.h>
12 //#include <AIDA/IHistogram1D.h>
13 #endif
14 
15 #include <EVENT/LCCollection.h>
16 #include <IMPL/LCCollectionVec.h>
17 #include <EVENT/LCRelation.h>
18 #include <IMPL/LCRelationImpl.h>
19 #include <EVENT/ReconstructedParticle.h>
20 #include <IMPL/ReconstructedParticleImpl.h>
21 #include "UTIL/LCRelationNavigator.h"
22 #include <EVENT/Vertex.h>
23 
24 #include <marlin/Global.h>
25 
26 #include "HelixClass.h"
27 #include "SimpleLine.h"
28 // ----- include for verbosity dependend logging ---------
29 #include "marlin/VerbosityLevels.h"
30 
31 #define coutEv -1
32 
33 #define coutUpToEv 0
34 
35 
36 using namespace lcio ;
37 using namespace marlin ;
38 using namespace UTIL;
39 
41 
42 
43 bool MyEnergySort( ReconstructedParticle *p1, ReconstructedParticle *p2)
44 {
45  return fabs(p1->getEnergy()) > fabs(p2->getEnergy());
46 }
47 
48 TauFinder::TauFinder() : Processor("TauFinder")
49 {
50  // modify processor description
51  _description = "TauFinder writes tau candidates as ReconstructedParticles into collection. It runs on a collection of ReconstructedParticels, if you want to run on MCParticles you have to convert them before hand (use e.g. PrepareRECParticles processor)" ;
52 
53  // register steering parameters: name, description, class-variable, default value
54 
55 
56  //the link between the reconstructed tau and the input particles used for it
57 
58 
59  registerInputCollection( LCIO::RECONSTRUCTEDPARTICLE,
60  "PFOCollection",
61  "Collection of PFOs",
62  _incol ,
63  std::string("PandoraPFANewPFOs"));
64 
65  registerOutputCollection( LCIO::RECONSTRUCTEDPARTICLE,
66  "TauRecCollection",
67  "Collection of Tau Candidates",
68  _outcol ,
69  std::string("TauRec_PFO"));
70 
71  registerOutputCollection( LCIO::RECONSTRUCTEDPARTICLE,
72  "TauRecRestCollection",
73  "Collection of Particles in Rest Group not in Tau Candidates",
74  _outcolRest ,
75  std::string("TauRecRest_PFO"));
76 
77  registerOutputCollection( LCIO::LCRELATION,
78  "TauRecLinkCollectionName" ,
79  "Name of the Tau link to ReconstructedParticle collection" ,
81  std::string("TauRecLink_PFO") ) ;
82 
83  registerProcessorParameter( "FileName_Signal",
84  "Name of the Signal output file " ,
86  std::string("Signal.root") ) ;
87 
88  registerProcessorParameter( "pt_cut" ,
89  "Cut on pt to suppress background" ,
90  _ptcut ,
91  (float)0.2) ;
92  registerProcessorParameter( "cosT_cut" ,
93  "Cut on cosT to suppress background" ,
94  _cosTcut ,
95  (float)0.99) ;
96 
97  registerProcessorParameter( "searchConeAngle" ,
98  "Opening angle of the search cone for tau jet in rad" ,
99  _coneAngle ,
100  (float)0.05) ;
101 
102  registerProcessorParameter( "isolationConeAngle" ,
103  "Outer isolation cone around search cone of tau jet in rad (relativ to cone angle)" ,
104  _isoAngle ,
105  (float)0.02) ;
106 
107  registerProcessorParameter( "isolationEnergy" ,
108  "Energy allowed within isolation cone region" ,
109  _isoE ,
110  (float)5.0) ;
111 
112  registerProcessorParameter( "ptseed" ,
113  "Minimum tranverse momentum of tau seed" ,
114  _ptseed ,
115  (float)5.0) ;
116 
117  registerProcessorParameter( "invariant_mass" ,
118  "Upper limit on invariant mass of tau candidate" ,
119  _minv ,
120  (float)2.0) ;
121 }
122 
123 
125 {
126  streamlog_out(DEBUG) << " init called " << std::endl ;
127 
128  // usually a good idea to
129  printParameters() ;
130 
131  rootfile = new TFile((_OutputFile_Signal).c_str (),"RECREATE");
132 
133  failtuple=new TNtuple("failtuple","failtuple","minv:Qtr:isoE:mergeTries:minv_neg");
134 
135 
136  _nRun = 0 ;
137  _nEvt = 0 ;
138  _fail_minv=0;
139  _fail_minv_neg=0;
140  _fail_Qtr=0;
141  _fail_isoE=0;
142  _mergeTries=0;
143 }
144 
145 void TauFinder::processRunHeader( LCRunHeader* )
146 {
147  _nRun++ ;
148 }
149 
150 void TauFinder::processEvent( LCEvent * evt )
151 {
152 
153  // this gets called for every event
154  // usually the working horse ...
155 
156  LCCollection *colRECO;
157 
158  try {
159  colRECO = evt->getCollection( _incol ) ;
160 } catch (Exception& e) {
161  colRECO = 0;
162  }
163 
164  //LCRelation: to keep information from which particles the tau was made
165  LCCollectionVec *relationcol = new LCCollectionVec(LCIO::LCRELATION);
166  relationcol->parameters().setValue(std::string("FromType"),LCIO::RECONSTRUCTEDPARTICLE);
167  relationcol->parameters().setValue(std::string("ToType"),LCIO::RECONSTRUCTEDPARTICLE);
168 
169  _nEvt = evt->getEventNumber();
170 
171  LCCollectionVec * reccol = new LCCollectionVec(LCIO::RECONSTRUCTEDPARTICLE);
172  LCCollectionVec * restcol = new LCCollectionVec(LCIO::RECONSTRUCTEDPARTICLE);
173  restcol->setSubset(1);
174  //sort all input particles into charged and neutral
175  std::vector<ReconstructedParticle*> Avector;//all particles
176  std::vector<ReconstructedParticle*> Qvector;//charged particles
177  std::vector<ReconstructedParticle*> Nvector;//neutral particles
178 
179 
180  if( colRECO != 0)
181  {
182  int nRCP = colRECO->getNumberOfElements();
183 
184  for (int i = 0; i < nRCP; i++)
185  {
186  ReconstructedParticle *particle = static_cast<ReconstructedParticle*>( colRECO->getElementAt( i ) );
187  double pt=sqrt(particle->getMomentum()[0]*particle->getMomentum()[0]
188  +particle->getMomentum()[1]*particle->getMomentum()[1]);
189  double Cos_T = fabs(particle->getMomentum()[2]) / sqrt(pow(particle->getMomentum()[0],2)+pow(particle->getMomentum()[1],2) + pow(particle->getMomentum()[2],2));
190  if(pt<_ptcut || Cos_T>_cosTcut)
191  continue;
192  Avector.push_back(particle);
193  if(particle->getCharge()==1 || particle->getCharge()==-1)
194  Qvector.push_back(particle);
195  else
196  Nvector.push_back(particle);
197  }
198  }//colRECO
199 
200 
201  //sort mc vec according to energy
202  std::sort(Qvector.begin(), Qvector.end(), MyEnergySort);
203  std::sort(Nvector.begin(), Nvector.end(), MyEnergySort);
204 
205  //vector to hold tau candidates
206  std::vector<std::vector<ReconstructedParticle*> > tauvec;
207  bool finding_done=false;
208  while(Qvector.size() && !finding_done)
209  finding_done= FindTau(Qvector,Nvector,tauvec);
210 
211  //combine associated particles to tau
212  std::vector<std::vector<ReconstructedParticle*> >::iterator iterT=tauvec.begin();
213  std::vector<ReconstructedParticleImpl* > tauRecvec;
214  //remember number of charged tracks in each tau for possible merging later
215  std::vector<int> QTvec;
216  std::vector<int> NTvec;
217  for(unsigned int p=0;p<tauvec.size();p++)
218  {
219  ReconstructedParticleImpl *taurec=new ReconstructedParticleImpl();
220  double E=0;
221  double charge=0;
222  double mom[3]={0,0,0};
223  int chargedtracks=0;
224  int neutraltracks=0;
225  std::vector<ReconstructedParticle*> tau=tauvec[p];
226 
227  for(unsigned int tp=0;tp<tau.size();tp++)
228  {
229  //add up energy and momentum
230  E+=tau[tp]->getEnergy();
231  charge+=tau[tp]->getCharge();
232  mom[0]+=tau[tp]->getMomentum()[0];
233  mom[1]+=tau[tp]->getMomentum()[1];
234  mom[2]+=tau[tp]->getMomentum()[2];
235  if(tau[tp]->getCharge())
236  chargedtracks++;
237  else
238  neutraltracks++;
239  taurec->addParticle(tau[tp]);
240  }
241 
242  double pt_tau=sqrt(mom[0]*mom[0]+mom[1]*mom[1]);
243  double psquare=pt_tau*pt_tau+mom[2]*mom[2];
244  double mass_inv=0;
245 
246  if(E*E<psquare)
247  mass_inv=E-sqrt(psquare);
248  else
249  mass_inv=sqrt(E*E-psquare);
250 
251  //check for invariant mass
252  if(mass_inv>_minv || mass_inv<-0.001 || chargedtracks>4 || chargedtracks==0)
253  {
254  if(mass_inv>_minv)
255  _fail_minv++;
256  if(mass_inv<-0.001)
257  _fail_minv_neg++;
258  if(chargedtracks>4 || chargedtracks==0)
259  _fail_Qtr++;
260 
261  //put those particles into rest group
262  for(unsigned int tp=0;tp<tau.size();tp++)
263  restcol->addElement(tau[tp]);
264 
265  iterT=tauvec.erase(iterT);
266  p--;
267 
268  if(_nEvt<coutUpToEv || _nEvt==coutEv)
269  {
270  double phi=180./TMath::Pi()*atan(mom[1]/mom[0]);
271  double theta=180./TMath::Pi()*atan(pt_tau/fabs(mom[2]));
272  streamlog_out(DEBUG) <<"Tau candidate failed: minv="<<mass_inv<<" pt="<<pt_tau<<" "<<E<<" Q trks:"<<chargedtracks<<" N trks:"<<neutraltracks<<" "<<phi<<" "<<theta<<endl;
273  }
274  delete taurec;
275  continue;
276  }
277  else
278  ++iterT;
279 
280  for(unsigned int tp=0;tp<tau.size();tp++) {
281  LCRelationImpl *rel = new LCRelationImpl(taurec,tau[tp]);
282  relationcol->addElement( rel );
283  }
284 
285  int pdg=15;
286  if(charge<0)
287  pdg=-15;
288 
289  taurec->setEnergy(E);
290  taurec->setCharge(charge);
291  taurec->setMomentum(mom);
292  taurec->setType(pdg);
293  if(_nEvt<coutUpToEv || _nEvt==coutEv)
294  {
295  double phi=180./TMath::Pi()*atan(mom[1]/mom[0]);
296  double theta=180./TMath::Pi()*atan(pt_tau/fabs(mom[2]));
297  streamlog_out(DEBUG)<<"Tau candidate "<<p<<": "<<E<<" Q trks:"<<chargedtracks<<" N trks:"<<neutraltracks<<" "<<phi<<" "<<theta<<endl;
298  }
299  QTvec.push_back(chargedtracks);
300  NTvec.push_back(neutraltracks);
301  tauRecvec.push_back(taurec);
302  }
303  //merge taus that are very close together, because they are likely to be from 1 tau that got split in algorithm
304  LCRelationNavigator *relationNavigator = new LCRelationNavigator( relationcol );
305 
306  if(tauRecvec.size()>1)
307  {
308  std::vector<ReconstructedParticleImpl*>::iterator iterC=tauRecvec.begin();
309  std::vector<ReconstructedParticleImpl*>::iterator iterF=tauRecvec.begin();
310  int erasecount=0;
311  for ( unsigned int t=0; t<tauRecvec.size() ; t++ )
312  {
313  ReconstructedParticleImpl *tau=static_cast<ReconstructedParticleImpl*>(tauRecvec[t]);
314  const double *mom=tau->getMomentum();
315  double pt_tau=sqrt(mom[0]*mom[0]+mom[1]*mom[1]);
316  double phi=180./TMath::Pi()*atan(mom[1]/mom[0]);
317  double theta=180./TMath::Pi()*atan(pt_tau/fabs(mom[2]));
318  double angle=10000000;
319 
320  for ( unsigned int t2=t+1; t2<tauRecvec.size() ; t2++ )
321  {
322  iterC=tauRecvec.begin()+t2;
323  ReconstructedParticleImpl *taun=static_cast<ReconstructedParticleImpl*>(tauRecvec[t2]);
324 
325  const double *momn=taun->getMomentum();
326  angle=acos((mom[0]*momn[0]+mom[1]*momn[1]+mom[2]*momn[2])/
327  (sqrt(mom[0]*mom[0]+mom[1]*mom[1]+mom[2]*mom[2])*
328  sqrt(momn[0]*momn[0]+momn[1]*momn[1]+momn[2]*momn[2])));
329  //merging happens
330  if(angle<_coneAngle)
331  {
332  _mergeTries++;
333  double E=tau->getEnergy();
334  double En=E+taun->getEnergy();
335  tau->setEnergy(En);
336  double newp[3]={mom[0]+momn[0],mom[1]+momn[1],mom[2]+momn[2]};
337  tau->setMomentum(newp);
338  tau->setCharge(tau->getCharge()+taun->getCharge());
339 
340  if(_nEvt<coutUpToEv || _nEvt==coutEv)
341  {
342  streamlog_out(DEBUG)<<" Tau Merging: "<<endl;
343  streamlog_out(DEBUG)<<t<<" "<<E<<" "<<phi<<" "<<theta<<endl;
344  streamlog_out(DEBUG)<<t2<<" "<<taun->getEnergy()<<" "<<angle<<" -> "<<En<<" "<<QTvec[t]+QTvec[t2]<<endl;
345  }
346 
347  //check for invariant mass and number of tracks
348  double ptn=sqrt(newp[0]*newp[0]+newp[1]*newp[1]);
349  double psquaren=ptn*ptn+newp[2]*newp[2];
350  double mass_inv=0;
351  if(En*En<psquaren)
352  mass_inv=En*En-psquaren;
353  else
354  mass_inv= sqrt(En*En-psquaren);
355  //failed to merge
356  if(mass_inv>_minv || mass_inv<-0.001 || QTvec[t+erasecount]+QTvec[t2+erasecount]>4)
357  {
358  if(mass_inv>_minv)
359  _fail_minv++;
360  if(mass_inv<-0.001)
361  _fail_minv_neg++;
362  if(QTvec[t+erasecount]+QTvec[t2+erasecount]>4)
363  _fail_Qtr++;
364 
365  //put those particles into rest group
366  for(unsigned int tp=0;tp<(*iterC)->getParticles().size();tp++)
367  restcol->addElement((*iterC)->getParticles()[tp]);
368  for(unsigned int tp=0;tp<(*iterF)->getParticles().size();tp++)
369  restcol->addElement((*iterF)->getParticles()[tp]);
370 
371  delete *iterC;
372  tauRecvec.erase(iterC);
373  erasecount++;
374  t2--;
375  delete *iterF;
376  iterF=tauRecvec.erase(iterF);
377  erasecount++;
378  if(iterF!=tauRecvec.end())
379  {
380  tau=*iterF;
381  mom=tau->getMomentum();
382  pt_tau=sqrt(mom[0]*mom[0]+mom[1]*mom[1]);
383  phi=180./TMath::Pi()*atan(mom[1]/mom[0]);
384  theta=180./TMath::Pi()*atan(pt_tau/fabs(mom[2]));
385  angle=10000000;
386  }
387  }
388  else //merge
389  {
390  //set the relations and add particles from one tau to the other
391  std::vector< ReconstructedParticle * > mergetaus=taun->getParticles();
392  for(unsigned int p=0;p<mergetaus.size();p++)
393  tau->addParticle(mergetaus[p]);
394  EVENT::LCObjectVec relobjFROM = relationNavigator->getRelatedToObjects(taun);
395  for(unsigned int o=0;o<relobjFROM.size();o++)
396  {
397  ReconstructedParticle *rec=static_cast<ReconstructedParticle*>(relobjFROM[o]);
398  LCRelationImpl *rel = new LCRelationImpl(tau,rec);
399  relationcol->addElement( rel );
400  }
401  delete *iterC;
402  tauRecvec.erase(iterC);
403  erasecount++;
404  t2--;
405  }
406  }
407  }
408  iterF++;
409  }
410  }
411  delete relationNavigator;
412  //test for isolation and too many tracks
413  std::vector<ReconstructedParticleImpl*>::iterator iter=tauRecvec.begin();
414  int erasecount=0;
415  for ( unsigned int t=0; t<tauRecvec.size() ; t++ )
416  {
417  ReconstructedParticleImpl *tau=static_cast<ReconstructedParticleImpl*>(tauRecvec[t]);
418  double E_iso=0;
419  int nparticles=0;
420  const double *pvec_tau=tau->getMomentum();
421  //too many particles in tau
422  if(QTvec[t+erasecount]+NTvec[t+erasecount]>10 || QTvec[t+erasecount]>4)
423  {
424  _fail_Qtr++;
425  if(_nEvt<coutUpToEv || _nEvt==coutEv)
426  streamlog_out(DEBUG) <<"Tau "<<tau->getEnergy()
427  <<": too many particles: "<<QTvec[t+erasecount]<<" "<<NTvec[t+erasecount]<<endl;
428  //put those particles into rest group
429  for(unsigned int tp=0;tp<(*iter)->getParticles().size();tp++)
430  restcol->addElement((*iter)->getParticles()[tp]);
431  delete *iter;
432  iter=tauRecvec.erase(iter);
433  erasecount++;
434  t--;
435  continue;
436  }
437  //isolation
438  for ( unsigned int s=0; s<Avector.size() ; s++ )
439  {
440  ReconstructedParticle *track=static_cast<ReconstructedParticle*>(Avector[s]);
441  const double *pvec=track->getMomentum();
442  double angle=acos((pvec[0]*pvec_tau[0]+pvec[1]*pvec_tau[1]+pvec[2]*pvec_tau[2])/
443  (sqrt(pvec[0]*pvec[0]+pvec[1]*pvec[1]+pvec[2]*pvec[2])*
444  sqrt(pvec_tau[0]*pvec_tau[0]+pvec_tau[1]*pvec_tau[1]+pvec_tau[2]*pvec_tau[2])));
445  if(angle>_coneAngle && angle<_isoAngle+_coneAngle)
446  {
447  nparticles++;
448  E_iso+=track->getEnergy();
449  }
450  }
451 
452  if(E_iso>_isoE)
453  {
454  _fail_isoE++;
455  if(_nEvt<coutUpToEv || _nEvt==coutEv)
456  streamlog_out(DEBUG) <<"Tau "<<tau->getEnergy()
457  <<": Isolation Energy: "<<E_iso<<" in "<<nparticles<<" particles"<<endl;
458  //put those particles into rest group
459  for(unsigned int tp=0;tp<(*iter)->getParticles().size();tp++)
460  restcol->addElement((*iter)->getParticles()[tp]);
461  delete *iter;
462  iter=tauRecvec.erase(iter);
463  erasecount++;
464  t--;
465  }
466  else
467  {
468  reccol->addElement(tau);
469  streamlog_out(DEBUG) << "Tau "<<tau->getEnergy()<<" "<<QTvec[t+erasecount]<<" "<<NTvec[t+erasecount]<<endl;
470  iter++;
471  }
472  }
473 
474  //put remaining particles into rest group
475  for(unsigned int tp=0;tp<Qvector.size();tp++)
476  restcol->addElement(Qvector[tp]);
477  for(unsigned int tp=0;tp<Nvector.size();tp++)
478  restcol->addElement(Nvector[tp]);
479 
480  evt->addCollection(reccol,_outcol);
481  evt->addCollection(restcol,_outcolRest);
482  evt->addCollection(relationcol,_colNameTauRecLink);
483 
484  _nEvt ++ ;
485 
486 }
487 
488 bool TauFinder::FindTau(std::vector<ReconstructedParticle*> &Qvec,std::vector<ReconstructedParticle*> &Nvec,
489  std::vector<std::vector<ReconstructedParticle*> > &tauvec)
490 {
491  std::vector<ReconstructedParticle*> tau;
492  if(Qvec.size()==0)
493  {
494  if(_nEvt<coutUpToEv || _nEvt==coutEv)
495  streamlog_out(DEBUG) << "No charged particle in event!"<<endl;
496  return true;
497  }
498  double OpAngleMax=0;
499  //find a good tauseed, check impact parameter
500  ReconstructedParticle *tauseed=NULL;
501  std::vector<ReconstructedParticle*>::iterator iterS=Qvec.begin();
502  for ( unsigned int s=0; s<Qvec.size() ; s++ )
503  {
504  tauseed=static_cast<ReconstructedParticle*>(Qvec[s]);
505  float mom[3];
506  for (int icomp=0; icomp<3; ++icomp)
507  mom[icomp]=(float)tauseed->getMomentum()[icomp];
508 
509  double pt=sqrt(mom[0]*mom[0]+mom[1]*mom[1]);
510 
511  if(pt>_ptseed)
512  break;
513  else
514  {
515  iterS++;
516  tauseed=NULL;
517  }
518  }
519  if(!tauseed)
520  {
521  if(_nEvt<coutUpToEv || _nEvt==coutEv)
522  streamlog_out(DEBUG) << "no further tau seed!"<<endl;
523  return true;
524  }
525 
526  double Etau=tauseed->getEnergy();
527 
528  tau.push_back(tauseed);
529 
530  // just for printing out info
531  {
532  const double *pvec=tauseed->getMomentum();
533  double pt=sqrt(pvec[0]*pvec[0]+pvec[1]*pvec[1]);
534  double p=sqrt(pt*pt+pvec[2]*pvec[2]);
535  double phi=180./TMath::Pi()*atan(pvec[1]/pvec[0]);
536  double theta=180./TMath::Pi()*atan(pt/fabs(pvec[2]));
537 
538  if(_nEvt<coutUpToEv || _nEvt==coutEv)
539  streamlog_out(DEBUG) << "seeding: "<<tauseed->getType()<<"\t"<<tauseed->getEnergy()<<"\t"<<p<<"\t"<<theta<<"\t"<<phi<<endl;
540  }
541 
542  Qvec.erase(iterS);
543  double pvec_tau[3]={0,0,0};
544  pvec_tau[0]=tauseed->getMomentum()[0];
545  pvec_tau[1]=tauseed->getMomentum()[1];
546  pvec_tau[2]=tauseed->getMomentum()[2];
547 
548  //assign charged particles to tau candidate
549  std::vector<ReconstructedParticle*>::iterator iterQ=Qvec.begin();
550  for (unsigned int s=0; s<Qvec.size() ; s++ )
551  {
552  ReconstructedParticle *track=static_cast<ReconstructedParticle*>(Qvec[s]);
553 
554  const double *pvec=track->getMomentum();
555  double angle=acos((pvec[0]*pvec_tau[0]+pvec[1]*pvec_tau[1]+pvec[2]*pvec_tau[2])/
556  (sqrt(pvec[0]*pvec[0]+pvec[1]*pvec[1]+pvec[2]*pvec[2])*
557  sqrt(pvec_tau[0]*pvec_tau[0]+pvec_tau[1]*pvec_tau[1]+pvec_tau[2]*pvec_tau[2])));
558  double pt=sqrt(pvec[0]*pvec[0]+pvec[1]*pvec[1]);
559  double p=sqrt(pt*pt+pvec[2]*pvec[2]);
560  double phi=180./TMath::Pi()*atan(pvec[1]/pvec[0]);
561  double theta=180./TMath::Pi()*atan(pt/fabs(pvec[2]));
562 
563  if(angle<_coneAngle)
564  {
565  if(angle>OpAngleMax)
566  OpAngleMax=angle;
567  tau.push_back(Qvec[s]);
568  if(_nEvt<coutUpToEv || _nEvt==coutEv)
569  streamlog_out(DEBUG) << "Adding Q: "<<track->getType()<<"\t"<<track->getEnergy()<<"\t"<<p<<"\t"<<theta<<"\t"<<phi<<std::endl;
570  Etau+=Qvec[s]->getEnergy();
571  //combine to new momentum
572  for(int i=0;i<3;i++){
573  pvec_tau[i]=pvec_tau[i]+track->getMomentum()[i];
574  }
575  Qvec.erase(iterQ);
576  s--;
577  }
578  else
579  iterQ++;
580  }
581  //assign neutral particles to tau candidate
582  std::vector<ReconstructedParticle*>::iterator iterN=Nvec.begin();
583  for (unsigned int s=0; s<Nvec.size() ; s++ )
584  {
585  ReconstructedParticle *track=Nvec[s];
586 
587  double *pvec=(double*)track->getMomentum();
588  double angle=acos((pvec[0]*pvec_tau[0]+pvec[1]*pvec_tau[1]+pvec[2]*pvec_tau[2])/
589  (sqrt(pvec[0]*pvec[0]+pvec[1]*pvec[1]+pvec[2]*pvec[2])*
590  sqrt(pvec_tau[0]*pvec_tau[0]+pvec_tau[1]*pvec_tau[1]+pvec_tau[2]*pvec_tau[2])));
591  double pt=sqrt(pvec[0]*pvec[0]+pvec[1]*pvec[1]);
592  double p=sqrt(pt*pt+pvec[2]*pvec[2]);
593  double phi=180./TMath::Pi()*atan(pvec[1]/pvec[0]);
594  double theta=180./TMath::Pi()*atan(pt/fabs(pvec[2]));
595 
596  if(angle<_coneAngle)
597  {
598  if(angle>OpAngleMax)
599  OpAngleMax=angle;
600  tau.push_back(Nvec[s]);
601  if(_nEvt<coutUpToEv || _nEvt==coutEv)
602  streamlog_out(DEBUG) << "Adding N: "<<track->getType()
603  <<"\t"<<track->getEnergy()
604  <<"\t"<<p
605  <<"\t"<<theta
606  <<"\t"<<phi<<std::endl;
607 
608  Etau+=Nvec[s]->getEnergy();
609  //combine to new momentum
610  for(int i=0;i<3;i++){
611  pvec_tau[i]=pvec_tau[i]+track->getMomentum()[i];
612  }
613  s--;
614  Nvec.erase(iterN);
615  }
616  else
617  iterN++;
618  }
619  tauvec.push_back(tau);
620  return false;
621 }
622 
623 void TauFinder::check( LCEvent* ) {
624  // nothing to check here - could be used to fill checkplots in reconstruction processor
625 }
626 
627 
630 
631  streamlog_out( MESSAGE ) << "TauFinder::end() " << name()
632  << " processed " << _nEvt << " events in " << _nRun << " runs "
633  << std::endl;
634  streamlog_out( MESSAGE ) << "Reasons for Failure: " <<std::endl;
635  streamlog_out( MESSAGE ) << "High invariant mass: " << _fail_minv<< std::endl;
636  streamlog_out( MESSAGE ) << "Negative invariant mass: " << _fail_minv_neg<< std::endl;
637  streamlog_out( MESSAGE ) << "No or to many tracks: " << _fail_Qtr<< std::endl;
638  streamlog_out( MESSAGE ) << "No isolation : " << _fail_isoE<< std::endl;
639  streamlog_out( MESSAGE ) << "Tried to merge : " << _mergeTries<< std::endl;
640 
641  rootfile->Write();
642  delete rootfile;
643 
644 
645 }
int _nEvt
Definition: TauFinder.h:68
float _ptcut
Definition: TauFinder.h:70
float _isoE
Definition: TauFinder.h:71
virtual void init()
Called at the begin of the job before anything is read.
Definition: TauFinder.cc:124
int _fail_Qtr
Definition: TauFinder.h:74
int _fail_minv_neg
Definition: TauFinder.h:74
int _fail_isoE
Definition: TauFinder.h:74
int _nRun
Definition: TauFinder.h:67
std::string _outcol
Definition: TauFinder.h:65
virtual void processRunHeader(LCRunHeader *run)
Called for every run.
Definition: TauFinder.cc:145
TauFinder processor for marlin.
Definition: TauFinder.h:26
virtual void processEvent(LCEvent *evt)
Called for every event - the working horse.
Definition: TauFinder.cc:150
#define coutEv
Definition: TauFinder.cc:31
int _mergeTries
Definition: TauFinder.h:74
float _isoAngle
Definition: TauFinder.h:71
static const float s
virtual void check(LCEvent *evt)
Definition: TauFinder.cc:623
std::string _outcolRest
Definition: TauFinder.h:65
int _fail_minv
Definition: TauFinder.h:74
bool MyEnergySort(ReconstructedParticle *p1, ReconstructedParticle *p2)
Definition: TauFinder.cc:43
static const float e
float _minv
Definition: TauFinder.h:72
TFile * rootfile
Definition: TauFinder.h:76
std::vector< LCCollection * > LCCollectionVec
Definition: SiStripClus.h:55
std::string _colNameTauRecLink
Definition: TauFinder.h:64
TNtuple * failtuple
Definition: TauFinder.h:77
float _coneAngle
Definition: TauFinder.h:71
std::string _OutputFile_Signal
Definition: TauFinder.h:66
float _cosTcut
Definition: TauFinder.h:70
std::string _incol
Definition: TauFinder.h:63
#define coutUpToEv
Definition: TauFinder.cc:33
TauFinder aTauFinder
Definition: TauFinder.cc:40
virtual void end()
Called after data processing for clean up.
Definition: TauFinder.cc:628
bool FindTau(std::vector< ReconstructedParticle * > &Qvec, std::vector< ReconstructedParticle * > &Nvec, std::vector< std::vector< ReconstructedParticle * > > &tauvec)
Definition: TauFinder.cc:488
float _ptseed
Definition: TauFinder.h:70