All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
KITutil.h
Go to the documentation of this file.
1 #ifndef KITUTIL_h
2 #define KITUTIL_h 1
3 
4 #include "lcio.h"
5 #include "EVENT/LCIO.h"
6 #include <EVENT/SimCalorimeterHit.h>
7 #include <EVENT/CalorimeterHit.h>
8 #include <vector>
9 #include <list>
10 #include <stack>
11 #include <string>
12 #include <UTIL/CellIDDecoder.h>
13 #include "Phys_Geom_Database.h"
14 #include <gsl/gsl_vector.h>
15 #include <gsl/gsl_matrix.h>
16 #include <gsl/gsl_blas.h>
17 #include <gsl/gsl_linalg.h>
18 #include <gsl/gsl_eigen.h>
19 #include <gsl/gsl_multifit_nlin.h>
20 #include <gsl/gsl_rng.h>
21 #include <gsl/gsl_sf_gamma.h>
22 #include <gsl/gsl_integration.h>
23 #include <gsl/gsl_sf_pow_int.h>
24 #include <ANN/ANN.h>
25 
26 using namespace lcio;
27 using namespace std;
28 
29 /**
30 \addtogroup Clustering Clustering
31 @{
32 */
33 
34 class Tmpcl2;
35 /**
36  * Basic hit class for reconstruction, contains the calorimeter hit plus
37  * additional parameters
38  * @authors P.Krstonosic (DESY)
39  */
40 class Superhit2
41 {
42  public:
43 
44  Superhit2(const Superhit2&) = delete;
45  Superhit2& operator=(const Superhit2&) = delete;
46  /**
47  * Constructor , needs absolute MIP energy (calibrated ) , and pointer to
48  * calorimeter hit
49  */
50  Superhit2(float E,CalorimeterHit* chitin);
51  /**
52  * Destructor
53  */
54  ~Superhit2();
55  /**
56  * Returns position of the hit i=1 transformed position, i=2 true position
57  */
58  const float* getPosition(int i);
59  /**
60  * Pointer to the LCIO calorimeter hit
61  */
62  CalorimeterHit* chit{};
63 
64  bool connect{};
65  /**
66  * Transformed position of the hit
67  */
68  float point[3]{}; // transform position
69  /**
70  * Real coordinate of the hit, copy of calorimeter hit data for direct access
71  */
72  float pointt[3]{}; // true position
73  /**
74  * Energy of hit i terms of MIP
75  */
76  float mip{};
77  /**
78  * MIP value [GeV]
79  */
80  float mipE{};
81  /**
82  * Number of neighbours
83  */
84  int top{}; // topological parameter
85  /**
86  * Is hit assigned to a cluster or not
87  */
88  bool is_assigned{};
89  /**
90  * Vector of pointers to the neighbouring hits of Superhit2 type
91  */
92  vector <Superhit2*> neighbours{};
93  /**
94  * Pointer to the cluster to wich hit belong
95  */
96  Tmpcl2 * cl{};
97  /**
98  * stove as coded by Mokka
99  */
100  int S{};
101  /**
102  * layer as coded by Mokka
103  */
104  int K{};
105  /**
106  * module as coded by Mokka
107  */
108  int M{};
109  /**
110  * 0 by constructor 1 for ecal 2 for hcal
111  */
112  int tip{};
113 
114 };
115 /**
116  * Basic cluster class for reconstruction
117  * @authors P.Krstonosic (DESY)
118  */
119 class Tmpcl2{
120 
121  public :
122  /**
123  * Constructor.
124  */
125  Tmpcl2();
126  /**
127  * Destructor.
128  */
129  ~Tmpcl2();
130  /**
131  * Calculates center of inerta for the objects in hits vector
132  */
133  void calcCenter();
134  /**
135  * returnes double[3] for the center as calculated with calcCenter method
136  */
137  double* getCenter();
138  /**
139  * returnes energy of cluster in GeV.
140  */
141  double getEnergy();
142  /**
143  * calculates eigenvalues and eigenvectors of inertia tensor
144  */
145  void findInertia();
146 
147  // vector<Superhit2*> konektori;
148  /**
149  * hit in the cluster
150  */
151  vector<Superhit2*> hits{};
152  /**
153  * pointers to clusters that are contained in this cluster
154  */
155  vector<Tmpcl2*> daughters{};
156  /**
157  * pointers to clusters that contain this cluster
158  */
159  vector<Tmpcl2*> parents{};
160  /**
161  * energy in GeV (sum over hits in cluster)
162  */
163  double energy{};
164  /**
165  * position of cluster center (x,y,z)
166  */
167  double center[3]{};
168  /**
169  * principal axes of inertia tensor , calculated in calcInertia
170  */
171  double direction[3]{};
172  /**
173  * normalized eigenvalues of inertia tensor
174  */
175  double inteigen[3]{};
176  /**
177  * eigenvectors of inertia tensor
178  */
179  double inteigenvec[9]{};
180 
181  /**
182  * Internal type of the cluster
183  */
184  int type{};
185 };
186 
187 class Photon2
188 {
189 
190  public:
191  /**
192  * Constructor.
193  */
194  Photon2(double Ein,double* pravac, double* pocetak);
195  /**
196  * Destructor.
197  */
198  ~Photon2();
199 
200  void Prob(CalorimeterHit* ch,double cut,double* out);
201 
202  // data- stvari koje se racunaju jednom i gotovo
203  double z1{};
204  double z2{};
205  double k1{};
206  double k2{};
207  double k3{};
208  double k4{};
209  double p1{};
210  double p2{};
211  double p3{};
212  double y{};
213  double eprime{};
214  double Z{};
215  double x0eff{};
216  double sampling{};
217  double Eceff{};
218  double Rm{};
219  double Fs{};
220  double Thom{};
221  double Tsam{};
222 
223  double alfahom{};
224  double alfasam{};
225  double betasam{};
226  //
227  double Ee{};
228  double dir[3]{};
229  double start[3]{};
230 };
231 typedef vector<Superhit2*> Shitvec2;
232 typedef vector<Tmpcl2*> Tmpclvec2;
233 
234 /**
235  * container for holding the numbers needed for energy estimation
236  */
237 typedef struct{
238  /**
239  * level of cluster
240  */
241  int level;
242  /**
243  * nominal i.e. input energy in GeV
244  */
245  double Enom;
246  /**
247  * Eestimate = a+b*Ecore , a parameter of this funcition
248  */
249  double a;
250  /**
251  * Eestimate = a+b*Ecore , b parameter of this funcition
252  */
253  double b;
254  /**
255  * lower validity range of energy estimation funciton in GeV
256  */
257  double Emin;
258  /**
259  * upper validity range of energy estimation funciton in GeV
260  */
261  double Emax;
262 } CoreCalib2;
263 
264 /**
265  * container for storing the EM shower core candidates
266  */
267 typedef struct{
268  /**
269  * pointer to the cluster
270  */
272  /**
273  * level of the cluster
274  */
275  int level;
276  /**
277  * center of the candidate
278  */
279  double X[3];
280  /**
281  * flag to activate deactivate
282  */
283  bool active;
284 }PROTSEED2;
285 
286 /**
287  * container for keeping the parameters of the core fineder together
288  */
289 typedef struct{
290  /**
291  * fluctuation suppresion cut
292  */
293  double Rcut;
294  /**
295  * distance cut for core merging
296  */
297  double Distcut;
298  /**
299  * angular cut for core merging (value of the cosine is stored not the angle!)
300  */
301  double Coscut;
302  /**
303  * minimal number of hits needed for 0-th level cluster to be accepted as a core candidate
304  */
305  unsigned int MinHit0;
306  /**
307  * minimal number of hits in i-th level cluster to be accepted for splitting of the core
308  */
309  unsigned int MinHitSplit;
310 }CoreCut2;
311 
312 
313 /**
314  * Creation of superhits, input is ECAL collection ,it's decoded and pointer to resulting container for
315  * superhits
316  */
317 void CreateAllShits2(LCCollection* colt,CellIDDecoder<CalorimeterHit>& id,vector<Superhit2*>* calo);
318 
319 /**
320  * Global precalculation function , iput is vector of superhits, ECAL decoder, number of hits, and
321  * number of neighbors cut for hit separation
322  */
323 void TotalPrecalc2(vector<Superhit2*>* calo,CellIDDecoder<CalorimeterHit>& id,
324  unsigned int nelem, int Ncut);
325 /**
326  * Precalculation function used internaly by TotalPrecalc
327  */
328 void Precalc2(vector< Superhit2* >& shvec,double r, double z, double cell, double dist,bool tip,int stove,int module,CellIDDecoder<CalorimeterHit>& id);
329 
330 /**
331  * Basic function for transformation of hit coordinates
332  */
333 void GridTransform2( CalorimeterHit* clh,float& radius, float& halfz, float& cellsize,float*X,
334  bool tip,int stove,int module,CellIDDecoder<CalorimeterHit>& id);
335 
336 /**
337  * Global EM core finding function , iput is vector of superhits, array of Tmpcl vectors bbb for internal
338  * computation, vector of EM core candidates prs2, and parameters of the algorithm
339  */
340 void FindCores2(Shitvec2* secal1, vector< Tmpclvec2>& bbb , vector <PROTSEED2> * prs2,
341  unsigned int N, vector<float> miipstep, CoreCut2 Ccut);
342 /**
343  * NN clustering
344  */
345 void cluster5( vector<Superhit2*>* shv, vector<Tmpcl2*>* clv);
346 /**
347  * returns energy estimate for a given core , input int level, double core energy in GeV, and
348  * calibration data table
349  */
350 double giveMeEEstimate2(int nivo,double Ecore, vector<CoreCalib2> cc);
351 /**
352  * Example function for creation of the energy estimaiton table
353  */
354 void CreateCalibrationLDC00(vector<CoreCalib2>* cc);
355 
356 
357 void LineCaloIntersectD2( double* X1, double* dir,double&d,double&zmax, double*X);
358 void LineCaloIntersect2(double* X1, double* X2,double&d,double&zmax, double*X);
359 double LinePointDistance2( double* X1, double* X2, double* X0);
360 void PointOnLine3(const double* X1,const double* X2,const float* X0,double* Xline);
361 void PointOnLine22(const double* Xstart,const double* dir,const float* X0,double* Xline);
362 void ModuleNormal2(double* X1,double& zmax, double* X0);
363 void ClusterInCluster2(Tmpcl2* cl, vector<Tmpcl2*>& clv);
364 double D_cl_cl2(Tmpcl2* cl1,Tmpcl2* cl2) ;
365 inline double Dot2(double* X1,double* X2);
366 void ClusterInCluster2(Tmpcl2* cl, vector<Tmpcl2*>& clv,vector<Tmpcl2*>& clout);
367 
368 /** @} */
369 
370 #endif
double LinePointDistance2(double *X1, double *X2, double *X0)
Definition: KITutil.cc:1216
container for keeping the parameters of the core fineder together
Definition: KITutil.h:289
void LineCaloIntersectD2(double *X1, double *dir, double &d, double &zmax, double *X)
Definition: KITutil.cc:1011
unsigned int MinHitSplit
minimal number of hits in i-th level cluster to be accepted for splitting of the core ...
Definition: KITutil.h:309
double D_cl_cl2(Tmpcl2 *cl1, Tmpcl2 *cl2)
Definition: KITutil.cc:1272
double b
Eestimate = a+b*Ecore , b parameter of this funcition.
Definition: KITutil.h:253
void cluster5(vector< Superhit2 * > *shv, vector< Tmpcl2 * > *clv)
NN clustering.
Definition: KITutil.cc:792
void PointOnLine22(const double *Xstart, const double *dir, const float *X0, double *Xline)
Definition: KITutil.cc:1434
void ModuleNormal2(double *X1, double &zmax, double *X0)
Definition: KITutil.cc:1229
unsigned int MinHit0
minimal number of hits needed for 0-th level cluster to be accepted as a core candidate ...
Definition: KITutil.h:305
void ClusterInCluster2(Tmpcl2 *cl, vector< Tmpcl2 * > &clv)
Definition: KITutil.cc:1199
vector< Tmpcl2 * > Tmpclvec2
Definition: KITutil.h:232
void FindCores2(Shitvec2 *secal1, vector< Tmpclvec2 > &bbb, vector< PROTSEED2 > *prs2, unsigned int N, vector< float > miipstep, CoreCut2 Ccut)
Global EM core finding function , iput is vector of superhits, array of Tmpcl vectors bbb for interna...
Definition: KITutil.cc:286
double Distcut
distance cut for core merging
Definition: KITutil.h:297
void GridTransform2(CalorimeterHit *clh, float &radius, float &halfz, float &cellsize, float *X, bool tip, int stove, int module, CellIDDecoder< CalorimeterHit > &id)
Basic function for transformation of hit coordinates.
Definition: KITutil.cc:228
void TotalPrecalc2(vector< Superhit2 * > *calo, CellIDDecoder< CalorimeterHit > &id, unsigned int nelem, int Ncut)
Global precalculation function , iput is vector of superhits, ECAL decoder, number of hits...
Definition: KITutil.cc:29
Basic cluster class for reconstruction.
Definition: KITutil.h:119
int level
level of cluster
Definition: KITutil.h:241
double Emax
upper validity range of energy estimation funciton in GeV
Definition: KITutil.h:261
void PointOnLine3(const double *X1, const double *X2, const float *X0, double *Xline)
Definition: KITutil.cc:1421
double Emin
lower validity range of energy estimation funciton in GeV
Definition: KITutil.h:257
double Coscut
angular cut for core merging (value of the cosine is stored not the angle!)
Definition: KITutil.h:301
double Dot2(double *X1, double *X2)
Definition: KITutil.cc:1297
container for storing the EM shower core candidates
Definition: KITutil.h:267
static const float K
double Enom
nominal i.e.
Definition: KITutil.h:245
double a
Eestimate = a+b*Ecore , a parameter of this funcition.
Definition: KITutil.h:249
vector< Superhit2 * > Shitvec2
Definition: KITutil.h:231
void LineCaloIntersect2(double *X1, double *X2, double &d, double &zmax, double *X)
Definition: KITutil.cc:1033
void Precalc2(vector< Superhit2 * > &shvec, double r, double z, double cell, double dist, bool tip, int stove, int module, CellIDDecoder< CalorimeterHit > &id)
Precalculation function used internaly by TotalPrecalc.
Definition: KITutil.cc:140
double Rcut
fluctuation suppresion cut
Definition: KITutil.h:293
double giveMeEEstimate2(int nivo, double Ecore, vector< CoreCalib2 > cc)
returns energy estimate for a given core , input int level, double core energy in GeV...
Definition: KITutil.cc:1450
int level
level of the cluster
Definition: KITutil.h:275
Tmpcl2 * cl
pointer to the cluster
Definition: KITutil.h:271
Basic hit class for reconstruction, contains the calorimeter hit plus additional parameters.
Definition: KITutil.h:40
void CreateCalibrationLDC00(vector< CoreCalib2 > *cc)
Example function for creation of the energy estimaiton table.
Definition: KITutil.cc:1463
container for holding the numbers needed for energy estimation
Definition: KITutil.h:237
bool active
flag to activate deactivate
Definition: KITutil.h:283
void CreateAllShits2(LCCollection *colt, CellIDDecoder< CalorimeterHit > &id, vector< Superhit2 * > *calo)
Creation of superhits, input is ECAL collection ,it&#39;s decoded and pointer to resulting container for ...
Definition: KITutil.cc:7