All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
SelectReconstructedParticle.cc
Go to the documentation of this file.
2 #include <iostream>
3 #include <cmath>
4 
5 #include <EVENT/LCCollection.h>
6 #include <EVENT/LCIO.h>
7 #include <Exceptions.h>
8 // #include <EVENT/ReconstructedParticle.h>
9 
10 // #include <EVENT/MCParticle.h>
11 // #include <IMPL/LCRunHeaderImpl.h>
12 // #include <IMPL/LCEventImpl.h>
13 #include <IMPL/LCCollectionVec.h>
14 #include <IMPL/ReconstructedParticleImpl.h>
15 
16 
17 using namespace lcio ;
18 using namespace marlin ;
19 using namespace std ;
20 
21 
23 
24 
26  : Processor("SelectReconstructedParticle") {
27 
28  // modify processor description
29  _description = "SelectReconstructedParticle: Selects particles from all reconstructed particles to be used for the thrust finder" ;
30 
31 
32  // register steering parameters:
33  // name, description, class-variable, default value
34 
35  registerInputCollection( LCIO::RECONSTRUCTEDPARTICLE,
36  "inputCollectionName" ,
37  "Collection of reconstructed particles to chose from" ,
39  std::string(LCIO::RECONSTRUCTEDPARTICLE) ) ;
40 
41  registerOutputCollection( LCIO::RECONSTRUCTEDPARTICLE,
42  "outputCollectionName" ,
43  "Collection of selected reconstructed particles" ,
45  std::string("SelectedReconstructedParticle") ) ;
46 
47 
48  registerProcessorParameter(
49  "MinimumMomentum" ,
50  "Minimum momentum a particle has to have to be used for the thrust calculation" ,
52  float(0) ) ;
53 
54 }
55 
57 
58  // usually a good idea to
59  printParameters() ;
60 
61 }
62 
63 void SelectReconstructedParticle::processRunHeader( LCRunHeader* /*run*/) {
64  // cout << "processing runheader" << endl;
65 }
66 
68  int good = 0;
69  std::stringstream errorMsg;
70  // cout << "processing event: " << endl;
71 
72  // get pointer to collection vec of input particles
73  LCCollection* inParVec = evt->getCollection(_inputCollectionName) ;
74  if (inParVec->getTypeName()!=LCIO::RECONSTRUCTEDPARTICLE) {
75  errorMsg << "\nProcessor: SelectReconstructedParticle \n" <<
76  "Collection is of wrong type (" << inParVec->getTypeName() <<
77  "). Processor requires collection tpye " << LCIO::RECONSTRUCTEDPARTICLE << "\n" ;
78  throw Exception(errorMsg.str());
79  }
80 
81  // create collection of output particles
82  LCCollectionVec* outParVec = new LCCollectionVec(LCIO::RECONSTRUCTEDPARTICLE) ;
83  outParVec->setSubset(true);
84 
85 
86  // loop over all Particles an do cuts
87  for (int i = 0; i < inParVec->getNumberOfElements() ; i++)
88  {
89  float totparmom;
90  const double *pparmom;
91  // float x;
92  pparmom = dynamic_cast<ReconstructedParticle*>(inParVec->getElementAt(i))->getMomentum();
93 
94 
95  // (inParVec->getElementAt(i))->getMomentum();
96  totparmom = sqrt( pparmom[0]*pparmom[0]
97  + pparmom[1]*pparmom[1]
98  + pparmom[2]*pparmom[2]);
99  if (totparmom >= _minimumMomentum &&
100  totparmom <= 5000 &&
101  !dynamic_cast<ReconstructedParticle*>(inParVec->getElementAt(i))->isCompound()) {
102  good++;
103  if (good <3000)
104  outParVec->addElement(inParVec->getElementAt(i));
105  }
106  }
107 
108  // add collection to event
109  evt->addCollection( outParVec, _outputCollectionName ) ;
110 
111  /* cout << "run: " << evt->getRunNumber()
112  << " Event no.: " << evt->getEventNumber() <<
113  " Teilchen: " << inParVec->getNumberOfElements()
114  << outParVec->getNumberOfElements() << endl; */
115 
116 }
117 
119 
120 // std::cout << "MyProcessor::end() " << name()
121 // << " processed " << _nEvt << " events in " << _nRun << " runs "
122 // << std::endl ;
123 
124 }
virtual void end()
Called after data processing for clean up.
virtual void init()
Called at the begin of the job before anything is read.
std::string _inputCollectionName
Input and output collection name.
Processor for marlin selecting reconstructed particle for further use.
virtual void processRunHeader(LCRunHeader *run)
Called for every run.
virtual void processEvent(LCEvent *evt)
Called for every event - the working horse.
std::vector< LCCollection * > LCCollectionVec
Definition: SiStripClus.h:55
SelectReconstructedParticle aSelectReconstructedParticle