All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
Fox.cc
Go to the documentation of this file.
1 #include "Fox.h"
2 #include <iostream>
3 #include <cmath>
4 #include <vector>
5 #include <algorithm>
6 #include <sstream>
7 #ifdef MARLIN_USE_AIDA
8 #include <marlin/AIDAProcessor.h>
9 #include <AIDA/IHistogramFactory.h>
10 #include <AIDA/ICloud1D.h>
11 //#include <AIDA/IHistogram1D.h>
12 #endif
13 #include "IMPL/LCEventImpl.h"
14 #include "IMPL/LCCollectionVec.h"
15 #include "IMPL/SimCalorimeterHitImpl.h"
16 #include "IMPL/CalorimeterHitImpl.h"
17 #include "IMPL/MCParticleImpl.h"
18 #include "IMPL/TrackerHitImpl.h"
19 #include "IMPL/TrackImpl.h"
20 #include "IMPL/ClusterImpl.h"
21 #include "IMPL/ReconstructedParticleImpl.h"
22 #include "IMPL/ParticleIDImpl.h"
23 #include "IMPL/LCFlagImpl.h"
24 #include "MCTree.h"
25 #include "IMPL/LCRelationImpl.h"
26 
27 
28 #include <EVENT/LCCollection.h>
29 #include <EVENT/ReconstructedParticle.h>
30 
31 using namespace lcio ;
32 using namespace marlin ;
33 using namespace std;
34 
35 vector <double> legendre_recursive(const double& x , const int& n,const vector<int> moments );
36 
38 
39 
40 Fox::Fox() : Processor("Fox") {
41 
42  // modify processor description
43  _description = "Fox calculates Fox-Wolfram moments" ;
44 
45 
46  // register steering parameters: name, description, class-variable, default value
47 
48  registerInputCollection( LCIO::RECONSTRUCTEDPARTICLE,
49  "NameOfReconstructedParticlesCollection" ,
50  "Name of the ReconstructedParticle collection" ,
51  _colName ,
52  std::string("RecoParticles") ) ;
53 
54  vector<int> momentsToCalculate;
55 
56  registerProcessorParameter("CalculateFoxWolframMoments",
57  "Numbers of the moments that are to be calculate 0-th is calculate by default",
59  momentsToCalculate);
60 
61 }
62 
63 
64 void Fox::init() {
65 
66  // usually a good idea to
67  printParameters() ;
68 
69  _nRun = 0 ;
70  _nEvt = 0 ;
71 
72 }
73 
74 void Fox::processRunHeader( LCRunHeader* /*run*/) {
75 
76  _nRun++ ;
77 }
78 
79 void Fox::processEvent( LCEvent * evt ) {
80 
81  // this gets called for every event
82  // usually the working horse ...
83 
84 
85  vector<ReconstructedParticle*> rpart;
86 
87 
88  // fill histogram from LCIO data :
89  try{
90  LCCollection* col = evt->getCollection( _colName ) ;
91 
92  vector < int > moments;
93  moments.push_back(0);
94 // to be shure that 0-th moment is calculated
95  for ( unsigned int kk=0 ; kk<_momentsToCalculate.size();kk++)
96  moments.push_back(_momentsToCalculate[kk]);
97 
98 
99  sort(moments.begin(),moments.end());
100  unsigned int largest_moment;
101  largest_moment=*max_element(moments.begin(),moments.end());
102 
103 
104  vector <double> outputMoments;
105  for ( unsigned int jj=0 ; jj < moments.size();jj++) outputMoments.push_back(0.0);
106 
107  if( col != 0 )
108  {
109  unsigned int nRecP = col->getNumberOfElements();
110 
111  for(unsigned int kk=0; kk< nRecP ; kk++)
112  {
113  rpart.push_back(dynamic_cast<ReconstructedParticle*>( col->getElementAt( kk ) ));
114  }
115  double* pi;
116  double* pj;
117  double eVisible=0.0;
118  double pimod;
119  double pjmod;
120 
121  for(unsigned int i=0; i<nRecP; i++)
122  {
123  pi=const_cast<double*>((rpart[i])->getMomentum());
124  pimod=sqrt( pi[0]*pi[0]+ pi[1]*pi[1]+ pi[2]*pi[2]);
125  for ( unsigned int j=0;j<nRecP; j++)
126  { double cosThetaIJ=0.0;
127  pj=const_cast<double*>((rpart[j])->getMomentum());
128  pjmod=sqrt( pj[0]*pj[0]+ pj[1]*pj[1]+ pj[2]*pj[2]);
129  eVisible+=(rpart[j])->getEnergy();
130  if ( (pimod!=0.0)&&(pjmod!=0))
131  cosThetaIJ= (pi[0]*pj[0]+ pi[1]*pj[1]+ pi[2]*pj[2])/(pimod*pjmod);
132 
133 
134  vector <double > legendreOutput(legendre_recursive(cosThetaIJ,largest_moment,moments));
135  for ( unsigned int kk=0; kk<legendreOutput.size(); kk++)
136  {
137  outputMoments[kk]+=pimod*pjmod*legendreOutput[kk];
138  }
139  }
140  }
141 
142 
143  for ( unsigned int kk=0; kk<outputMoments.size(); kk++)
144  {
145  outputMoments[kk]=outputMoments[kk]/(eVisible*eVisible);
146  }
147 
148  for ( unsigned int kk=0; kk<outputMoments.size(); kk++)
149  {
150  ostringstream dtes;
151  dtes<< moments[kk];
152  string nth= dtes.str();
153  string base_name="FoxWolfram_moment(";
154  base_name=base_name+nth+")";
155  col->parameters().setValue(base_name.c_str(),(float)outputMoments[kk]);
156 
157  }
158 
159 
160 
161  } //col
162  }catch(DataNotAvailableException &e) {}
163  // getchar();
164 
165  _nEvt ++ ;
166 }
167 
168 
169 
170 void Fox::check( LCEvent * /*evt*/ ) {
171  // nothing to check here - could be used to fill checkplots in reconstruction processor
172 }
173 
174 
175 void Fox::end(){
176 
177 // std::cout << "MyProcessor::end() " << name()
178 // << " processed " << _nEvt << " events in " << _nRun << " runs "
179 // << std::endl ;
180 
181 }
182 
183 vector <double> legendre_recursive(const double& x , const int& n, const vector <int> moments)
184  {
185 
186  vector <double> lr,rr;
187  lr.push_back(1.0);
188  lr.push_back(x);
189  for ( int i=2;i<n+1;i++)
190  lr.push_back(((1.0/i)*((2.0*i-1.0)*x*lr[i-1]-(i-1.0)*lr[i-2])));
191  for (unsigned int i=0;i<moments.size();i++)
192  rr.push_back(lr[moments[i]]);
193  return rr;
194 
195 
196  }
const float pi
Definition: G2CD.cc:34
Fox aFox
Definition: Fox.cc:37
int _nEvt
Definition: Fox.h:64
Fox()
Definition: Fox.cc:40
std::vector< int > _momentsToCalculate
Vector of moments orders to be calculated.
Definition: Fox.h:62
int _nRun
Definition: Fox.h:63
virtual void processRunHeader(LCRunHeader *run)
Called for every run.
Definition: Fox.cc:74
std::string _colName
Input collection name.
Definition: Fox.h:59
virtual void init()
Called at the begin of the job before anything is read.
Definition: Fox.cc:64
static const float e
virtual void processEvent(LCEvent *evt)
Called for every event - the working horse.
Definition: Fox.cc:79
Processor calculates Fox-Wolfram moments.
Definition: Fox.h:24
virtual void end()
Called after data processing for clean up.
Definition: Fox.cc:175
vector< double > legendre_recursive(const double &x, const int &n, const vector< int > moments)
Definition: Fox.cc:183
virtual void check(LCEvent *evt)
Definition: Fox.cc:170