All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
Sphere.cc
Go to the documentation of this file.
1 #include "Sphere.h"
2 #include <iostream>
3 #include <vector>
4 #include "jama_eig.h"
5 #include "tnt_math_utils.h"
6 #ifdef MARLIN_USE_AIDA
7 #include <marlin/AIDAProcessor.h>
8 #include "marlin/Exceptions.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 
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 using namespace JAMMA;
35 using namespace TNT;
37 
38 
39 Sphere::Sphere() : Processor("Sphere") {
40 
41  // modify processor description
42  _description = "Sphere calculates eigenvalues of sphericity tensor" ;
43 
44 
45  // register steering parameters: name, description, class-variable, default value
46 
47  registerInputCollection( LCIO::RECONSTRUCTEDPARTICLE,
48  "CollectionName" ,
49  "Name of the ReconstructedParticle collection" ,
50  _colName ,
51  std::string("RecontructedParticle") ) ;
52 
53  registerProcessorParameter("r_value",
54  " exponent in sphericity tensor use 2.0 for classical 1.0 for C,D",
55  _r,
56  float(2.0));
57  registerProcessorParameter("eigenvalues_parameter_name",
58  "name of parameter to store the results ",
60  std::string("sphericity_tensor_eigenvalues"));
61 
62 }
63 
64 
65 void Sphere::init() {
66 
67  // usually a good idea to
68  printParameters() ;
69 
70  _nRun = 0 ;
71  _nEvt = 0 ;
72 
73 }
74 
75 void Sphere::processRunHeader( LCRunHeader* /*run*/) {
76 
77  _nRun++ ;
78 }
79 
80 void Sphere::processEvent( LCEvent * evt ) {
81 
82  // this gets called for every event
83  // usually the working horse ...
84 
85 // float Pduzi;
86  double Pduzi;
87  float sp[3][3];
88  float norm=0.0;
89 // float *pp;
90  const double *pp ;
91 // float dvojka=2.0;
92  double dvojka=2.0;
93 
94  ReconstructedParticle* p;
95  LCCollection* col ;
96 
97  try{ col = evt -> getCollection( _colName ) ; }
98  catch(EVENT::DataNotAvailableException&){
99  streamlog_out(DEBUG) << "Cannot find PFO Collection in event/run " << evt->getEventNumber() <<" / "<< evt->getRunNumber() <<std::endl;
100  streamlog_out(DEBUG) << "Skipping this event!" << std::endl;
101  throw marlin::SkipEventException(this);
102  }
103 
104  if (col->getNumberOfElements() == 0){
105  streamlog_out(DEBUG) << "PFO Collection is empty in event/run " << evt->getEventNumber() <<" / "<< evt->getRunNumber() <<std::endl;
106  return;
107  }
108 
109 
110 
111  for(int i=0;i<3;i++)
112  {
113  for (int j=0;j<3;j++)
114  {
115  sp[j][i]=0.0;
116  }
117  }
118 
119  if( col != 0 ){
120 
121  int nRecP = col->getNumberOfElements() ;
122 
123  for(int kk=0; kk< nRecP ; kk++){
124  p=dynamic_cast<ReconstructedParticle*>( col->getElementAt( kk ) );
125 
126 // pp=const_cast<float*>(p->getMomentum());
127  pp = p->getMomentum() ;
128 
129  Pduzi=sqrt(pow(pp[0],dvojka)+pow(pp[1],dvojka)+pow(pp[2],dvojka));
130 
131  norm=norm+pow(Pduzi,(double) _r);
132  for(int j=0;j<3;j++)
133  {
134  for(int i=0;i<3;i++)
135  {
136  sp[j][i]=sp[j][i]+pp[i]*pp[j]*pow(Pduzi,(_r-dvojka));
137  }
138  }
139 
140  }
141  }
142 
143  for(int j=0;j<3;j++)
144  {
145  for(int i=0;i<3;i++)
146  {
147  sp[j][i]=sp[j][i]/norm;
148  // cout << "sp tenzor "<< sp[j][i] << endl;
149  }
150  }
151  float lre[3];
152  Eigenvalue test(sp);
153  test.getRealEigenvalues(lre);
154  // cout << lre[0] << " " << lre[1] << " " << lre[2] << endl;
155  float sphericity;
156  float aplanarity;
157  string out_name;
158  sphericity=1.5*(lre[0]+lre[1]);
159  aplanarity=1.5*lre[0];
160  FloatVec udri_me_do_zore;
161  udri_me_do_zore.push_back(lre[0]);
162  udri_me_do_zore.push_back(lre[1]);
163  udri_me_do_zore.push_back(lre[2]);
164  if (_r==2.0){
165  col->parameters().setValue("sphericity",sphericity);
166  col->parameters().setValue("aplanarity",aplanarity);
167  col->parameters().setValues(_dumpobjectname.c_str(),udri_me_do_zore);
168  }
169  if (_r==1.0){
170  float ccc;
171  float ddd;
172  ccc=3.0*(lre[0]*lre[1]+lre[0]*lre[2]+lre[2]*lre[1]);
173  ddd=27.0*lre[0]*lre[1]*lre[2];
174  col->parameters().setValue("C",ccc);
175  col->parameters().setValue("D",ddd);
176  col->parameters().setValues(_dumpobjectname.c_str(),udri_me_do_zore);
177  }
178  else
179  {
180  col->parameters().setValues(_dumpobjectname.c_str(),udri_me_do_zore);
181  }
182  _nEvt ++ ;
183 }
184 
185 
186 
187 void Sphere::check( LCEvent * /*evt*/ ) {
188  // nothing to check here - could be used to fill checkplots in reconstruction processor
189 }
190 
191 
192 void Sphere::end(){
193 
194 // std::cout << "MyProcessor::end() " << name()
195 // << " processed " << _nEvt << " events in " << _nRun << " runs "
196 // << std::endl ;
197 
198 }
int _nRun
Definition: Sphere.h:58
float _r
Definition: Sphere.h:57
std::string _dumpobjectname
Name of the parameter to store egenvalues of sphericity tensor.
Definition: Sphere.h:56
virtual void end()
Called after data processing for clean up.
Definition: Sphere.cc:192
Sphere()
Definition: Sphere.cc:39
virtual void processRunHeader(LCRunHeader *run)
Called for every run.
Definition: Sphere.cc:75
virtual void check(LCEvent *evt)
Definition: Sphere.cc:187
virtual void processEvent(LCEvent *evt)
Called for every event - the working horse.
Definition: Sphere.cc:80
void getRealEigenvalues(float d_[3])
Return the real parts of the eigenvalues.
Definition: jama_eig.h:897
int _nEvt
Definition: Sphere.h:59
std::string _colName
Input collection name.
Definition: Sphere.h:53
lcio::LCCollection * getCollection(lcio::LCEvent *evt, const std::string name)
helper function to get collection safely
virtual void init()
Called at the begin of the job before anything is read.
Definition: Sphere.cc:65
Sphere aSphere
Definition: Sphere.cc:36
Processor that calculates sphericity,aplanarity, C and D event parametres for detail explanation look...
Definition: Sphere.h:18