All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
PrepareRECParticles.cc
Go to the documentation of this file.
1 #include "PrepareRECParticles.h"
2 #include <cmath>
3 #include <iostream>
4 #include <iomanip>
5 
6 using namespace std;
7 
8 
9 #ifdef MARLIN_USE_AIDA
10 #include <marlin/AIDAProcessor.h>
11 #include <AIDA/IHistogramFactory.h>
12 #include <AIDA/ICloud1D.h>
13 //#include <AIDA/IHistogram1D.h>
14 #endif
15 
16 #include <EVENT/LCCollection.h>
17 #include <IMPL/LCCollectionVec.h>
18 #include <EVENT/LCRelation.h>
19 #include <IMPL/LCRelationImpl.h>
20 #include <EVENT/MCParticle.h>
21 #include <EVENT/Track.h>
22 #include <EVENT/ReconstructedParticle.h>
23 #include <IMPL/ReconstructedParticleImpl.h>
24 #include <IMPL/TrackImpl.h>
25 #include "IMPL/LCFlagImpl.h"
26 #include "UTIL/LCRelationNavigator.h"
27 
28 #include <marlinutil/GeometryUtil.h>
29 #include <marlin/Global.h>
30 #include "HelixClass.h"
31 
32 // ----- include for verbosity dependend logging ---------
33 #include "marlin/VerbosityLevels.h"
34 
35 using namespace lcio ;
36 using namespace marlin ;
37 using namespace UTIL;
38 
40 
41 template<typename T>
42 T sgn(T n)
43 {
44 if (n < 0) return -1;
45 if (n > 0) return 1;
46 return 0;
47 }
48 
49 PrepareRECParticles::PrepareRECParticles() : Processor("PrepareRECParticles")
50 {
51  // modify processor description
52  _description = "PrepareRECParticles converts input to ReconstructedParticles and puts them into a new collection making sure all the information which is needed to run the TauFinder is provided. ";
53 
54  // register steering parameters: name, description, class-variable, default value
55  registerInputCollection( LCIO::MCPARTICLE,
56  "MCCollectionName " ,
57  "Name of the MCParticle collection" ,
58  _colNameMC ,
59  std::string("MCParticlesSkimmed") ) ;
60 
61  registerInputCollection( LCIO::TRACK,
62  "TrackCollectionName" ,
63  "Name of the Track collection" ,
65  std::string("LDCTracks") ) ;
66 
67  registerProcessorParameter( "outputColMC" ,
68  "Name of the output Collection of refilled information" ,
69  _outcolMC ,
70  std::string("MCParticles_tau")) ;
71 
72  registerProcessorParameter( "outputColTracks" ,
73  "Name of the output Collection of refilled information" ,
75  std::string("Tracks_tau")) ;
76 
77  registerOutputCollection( LCIO::RECONSTRUCTEDPARTICLE,
78  "RecCollection",
79  "Collection of Rec Particles for TauFinder",
80  _outcolMC ,
81  std::string("MCParticles_tau"));
82 
83  registerOutputCollection( LCIO::RECONSTRUCTEDPARTICLE,
84  "RecCollection_Tracks",
85  "Collection of Rec Particles for TauFinder",
87  std::string("Tracks_tau"));
88 
89 
90  registerOutputCollection( LCIO::LCRELATION,
91  "MCRECLinkCollectionName" ,
92  "Name of the MC Truth ReconstructedParticle collection" ,
94  std::string("MCRecLink") ) ;
95 
96  registerOutputCollection( LCIO::LCRELATION,
97  "TrackRECLinkCollectionName" ,
98  "Name of the Track Truth ReconstructedParticle collection" ,
100  std::string("TracksRecLink") ) ;
101 
102 
103 }
104 
105 
107 {
108  streamlog_out(DEBUG) << " init called "
109  << std::endl ;
110 
111  // usually a good idea to
112  printParameters() ;
113  _bField = MarlinUtil::getBzAtOrigin();
114  _nRun = 0 ;
115  _nEvt = 0 ;
116 
117 }
118 
120 {
121  _nRun++ ;
122 }
123 
124 void PrepareRECParticles::processEvent( LCEvent * evt )
125 {
126  // this gets called for every event
127  // usually the working horse ...
128 
129  LCCollection *colMC, *colTrack;
130  try {
131  colMC = evt->getCollection( _colNameMC ) ;
132 } catch (Exception& e) {
133  colMC = 0;
134  }
135 
136  try {
137  colTrack = evt->getCollection( _colNameTrack ) ;
138 } catch (Exception& e) {
139  colTrack = 0;
140  }
141 
142  LCCollectionVec *reccol = new LCCollectionVec(LCIO::RECONSTRUCTEDPARTICLE);
143  LCCollectionVec *trackcol = new LCCollectionVec(LCIO::RECONSTRUCTEDPARTICLE);
144  //LCRelation stuff
145  LCCollectionVec *mc_relationcol = new LCCollectionVec(LCIO::LCRELATION);
146  mc_relationcol->parameters().setValue(std::string("FromType"),LCIO::RECONSTRUCTEDPARTICLE);
147  mc_relationcol->parameters().setValue(std::string("ToType"),LCIO::MCPARTICLE);
148  LCCollectionVec *track_relationcol = new LCCollectionVec(LCIO::LCRELATION);
149  track_relationcol->parameters().setValue(std::string("FromType"),LCIO::RECONSTRUCTEDPARTICLE);
150  track_relationcol->parameters().setValue(std::string("ToType"),LCIO::TRACK);
151 
152  HelixClass *helix = new HelixClass();
153  //convert MCPARTICLES
154  if( colMC != 0 )
155  {
156  int nMCP = colMC->getNumberOfElements();
157  for(int k=0; k < nMCP; k++)
158  {
159  MCParticle *mc = static_cast<MCParticle*>(colMC->getElementAt(k));
160  if(mc->getGeneratorStatus()==1)//only stable ones
161  {
162  //filter out the neutrinos and other invisibles
163  if( (mc->getMass()==0 && fabs(mc->getPDG())!=22)
164  || mc->getPDG()==1000022)
165  continue;
166  ReconstructedParticleImpl *rec = new ReconstructedParticleImpl();
167  //copy values from MC to REC
168  rec->setMomentum(mc->getMomentum());
169  rec->setType(mc->getPDG());
170  rec->setEnergy(mc->getEnergy());
171  rec->setMass(mc->getMass());
172  rec->setCharge(mc->getCharge());
173  //add the track if charged, so that information for D0 is present
174  if(mc->getCharge())
175  {
176  TrackImpl *track=new TrackImpl();
177  float ver[3];
178  float mom[3];
179  float rp[3];
180  for(int i=0;i<3;i++){
181  ver[i]=mc->getVertex()[i];
182  mom[i]=mc->getMomentum()[i];
183  }
184  helix->Initialize_VP(ver,mom,mc->getCharge(),_bField);
185  for(int i=0;i<3;i++)
186  rp[i]=helix->getReferencePoint()[i];
187  track->setReferencePoint(rp);
188  track->setD0(fabs(helix->getD0()));
189  track->setPhi (helix->getPhi0());
190  track->setOmega (helix->getOmega());
191  track->setZ0 (helix->getZ0());
192  track->setTanLambda (helix->getTanLambda());
193  rec->addTrack(track);
194  }
195  reccol->addElement( rec );
196  LCRelationImpl *rel = new LCRelationImpl(rec,mc);
197  mc_relationcol->addElement( rel );
198  }
199  }
200  }
201  delete helix;
202  //convert TRACKS
203  if( colTrack != 0 )
204  {
205  int nt=colTrack->getNumberOfElements();
206  for(int n=0;n<nt;n++)
207  {
208  Track *tr=static_cast<Track*>(colTrack->getElementAt(n));
209  ReconstructedParticleImpl *trec = new ReconstructedParticleImpl();
210  //momentum of track assuming B along z
211  double pt=fabs(_bField/tr->getOmega())*3e-4;
212  double p=fabs(pt/cos(atan(tr->getTanLambda())));
213  double mom[3];
214  mom[0]=pt*cos(tr->getPhi());
215  mom[1]=pt*sin(tr->getPhi());
216  mom[2]=pt*tr->getTanLambda();
217  double charge = sgn(_bField/tr->getOmega());
218  trec->setMomentum(mom);
219  trec->setType(-1);
220  trec->setEnergy(p);
221  trec->setCharge(charge);
222  trec->addTrack(tr);
223  trackcol->addElement( trec );
224  LCRelationImpl *rel = new LCRelationImpl(trec,tr);
225  track_relationcol->addElement( rel );
226  }
227  }
228 
229 
230  evt->addCollection(reccol,_outcolMC);
231  evt->addCollection(mc_relationcol,_colNameMCTruth);
232  evt->addCollection(trackcol,_outcolTracks);
233  evt->addCollection(track_relationcol,_colNameTrackTruth);
234 
235  _nEvt++;
236 
237 }
238 
239 
240 
241 void PrepareRECParticles::check( LCEvent* ) {
242  // nothing to check here - could be used to fill checkplots in reconstruction processor
243 }
244 
245 
247 
248 
249  streamlog_out( DEBUG ) << "PrepareRECParticles::end() " << name()
250  << " processed " << _nEvt << " events in " << _nRun << " runs "
251  << std::endl ;
252 
253  //Close File here
254 
255 
256 }
static const float k
virtual void init()
Called at the begin of the job before anything is read.
static const float T
virtual void processEvent(LCEvent *evt)
Called for every event - the working horse.
PreProcessor for TauFinder to provide necessary information and create universal input for TauFinder...
static const float e
virtual void processRunHeader(LCRunHeader *run)
Called for every run.
std::vector< LCCollection * > LCCollectionVec
Definition: SiStripClus.h:55
std::string _colNameTrackTruth
PrepareRECParticles aPrepareRECParticles
virtual void check(LCEvent *evt)
virtual void end()
Called after data processing for clean up.
T sgn(T n)
std::string _colNameMC
Input collection name.