All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
KITutil.cc
Go to the documentation of this file.
1 
2 #include <algorithm>
3 
4 
5 #include "KITutil.h"
6 
7 void CreateAllShits2(LCCollection* colt,CellIDDecoder<CalorimeterHit>& id,vector<Superhit2*>* calo)
8 {
9 
10  unsigned int nelem=colt->getNumberOfElements();
11 
12 
13  for(unsigned int ll=0;ll<nelem;ll++)
14  {
15  CalorimeterHit* ch=dynamic_cast<CalorimeterHit*>(colt->getElementAt(ll));
16  unsigned int layer =(unsigned int)id(ch)["K-1"];
17  Superhit2 * stmp;
18 
19  if( layer<=PGDB[PGdb::ECAL1_BAR].max_lay)
20  stmp= new Superhit2(PGDB[PGdb::ECAL1_BAR].mip_whole,ch);
21  else
22  stmp= new Superhit2(PGDB[PGdb::ECAL2_BAR].mip_whole,ch);
23 
24  calo[0].push_back(stmp);
25 
26  }
27 }
28 
29 void TotalPrecalc2(vector<Superhit2*>* calo,CellIDDecoder<CalorimeterHit>& id,
30  unsigned int nelem, int Ncut)
31 {
32 
33  vector<Superhit2*> tmpsh[9];
34 
35  for(unsigned int ll=0;ll<nelem;ll++)
36  {
37  CalorimeterHit* chh=(calo[0])[ll]->chit;
38  int stove =id(chh)["S-1"];
39  int module =id(chh)["M"];
40  int layer =id(chh)["K-1"];
41 
42  (calo[0])[ll]->S=stove;
43  (calo[0])[ll]->M=module;
44  (calo[0])[ll]->K=layer;
45  (calo[0])[ll]->tip=1;
46 
47  if( module !=0 && module!=6)
48  {
49  if(layer!=0)
50  {
51  tmpsh[stove].push_back((calo[0])[ll]);
52  }else{
53 
54  double fi=atan2(-(calo[0])[ll]->chit->getPosition()[0],(calo[0])[ll]->chit->getPosition()[1]);
55  if ( fi< 0.0)
56  {
57  if( stove!=0)
58  fi=2.0*M_PI+fi;
59  else
60  fi=fabs(fi);
61  }
62 
63  double diff=fi-M_PI_4*stove;
64  tmpsh[stove].push_back((calo[0])[ll]);
65  if ( fabs(diff)<M_PI_4/2.0)
66  {
67  tmpsh[stove].push_back((calo[0])[ll]);
68  }else{
69 
70  (calo[0])[ll]->connect=true;
71 
72  tmpsh[stove].push_back((calo[0])[ll]);
73 
74  int stovem1=stove-1;
75 
76  if( stovem1>=0)
77  tmpsh[stovem1].push_back((calo[0])[ll]);
78  else
79  tmpsh[7].push_back((calo[0])[ll]);
80  }
81  }
82  }else{
83  tmpsh[8].push_back((calo[0])[ll]);
84  }
85  }
86 
87 
88 
89  double celx=PGDB[PGdb::ECAL1_BAR].cell_size;
90  double distcut=0.98*(2.0*celx)*(2.0*celx);
91 
92  for(unsigned int ll=0;ll<8;ll++)
93  {
94  if(tmpsh[ll].size()!=0)
95  Precalc2(tmpsh[ll],PGDB[PGdb::ECAL1_BAR].r_inner,
96  PGDB[PGdb::ECAL1_CAP].z_inner,
97  PGDB[PGdb::ECAL1_BAR].cell_size,distcut,true,ll,1,id);
98  }
99 
100 
101  if(tmpsh[8].size()!=0)
102  Precalc2(tmpsh[8],PGDB[PGdb::ECAL1_BAR].r_inner,
103  PGDB[PGdb::ECAL1_CAP].z_inner,
104  PGDB[PGdb::ECAL1_BAR].cell_size,distcut,false,1,1,id);
105 
106 
107 
108  for(unsigned int ii=0;ii<calo[0].size();ii++)
109  calo[0][ii]->top=calo[0][ii]->neighbours.size();
110 
111 
112  for(unsigned int ii=0;ii<(calo[0]).size();ii++)
113  {
114  if ((calo[0])[ii]->top !=0)
115  {
116  if((calo[0])[ii]->top >= 1 && (calo[0])[ii]->top <Ncut)
117  {
118  (calo[2]).push_back((calo[0])[ii]);
119  }else{
120  (calo[4]).push_back((calo[0])[ii]);
121  }
122  }else{ // zero or not
123  (calo[6]).push_back((calo[0])[ii]);
124  }
125  }
126 }
127 
128 
129 
130 
131 
132 
133 
134 
135 
136 
137 
138 
139 
140 void Precalc2(vector< Superhit2* >& shvec,double r, double z, double cell, double dist,bool tip,int stove,int module,CellIDDecoder<CalorimeterHit>& id){
141 
142  unsigned int nPts=shvec.size();
143  ANNpointArray dataPts;
144  ANNpoint queryPt;
145  ANNidxArray nnIdx;
146  ANNdistArray dists;
147  ANNkd_tree* kdTree;
148 
149  queryPt=annAllocPt(3); // 3d point
150  dataPts=annAllocPts(nPts,3);
151  nnIdx=new ANNidx[36];
152  dists=new ANNdist[36];
153  float xxx[3];
154  float Ecalradius=r;
155  float Ecalhalfz=z;
156  float Ecalcellsize=cell;
157 
158  for ( unsigned int ii=0; ii<nPts;ii++)
159  {
160  GridTransform2(shvec[ii]->chit,Ecalradius,Ecalhalfz,Ecalcellsize,xxx,tip,stove,module,id);
161  dataPts[ii][0]=xxx[0];
162  dataPts[ii][1]=xxx[1];
163  dataPts[ii][2]=xxx[2];
164  shvec[ii]->point[0]=xxx[0];
165  shvec[ii]->point[1]=xxx[1];
166  shvec[ii]->point[2]=xxx[2];
167  }
168 
169 
170  kdTree=new ANNkd_tree(dataPts,nPts,3);
171  ANNdist trd=dist;
172 
173  for (unsigned int ii=0; ii<nPts;ii++)
174  {
175  unsigned int koliko = (unsigned int)kdTree->annkFRSearch(dataPts[ii],trd,26,nnIdx,dists,0.0);
176  if (koliko>26)
177  koliko=26;
178  if( tip )
179  {
180  if( shvec[ii]->connect )
181  {
182 
183  for(unsigned int ij=0;ij<koliko;ij++)
184  {
185  if( shvec[ii]->neighbours.end() ==
186  find(shvec[ii]->neighbours.begin(),shvec[ii]->neighbours.end(), shvec[nnIdx[ij]]))
187  {
188  shvec[ii]->neighbours.push_back(shvec[nnIdx[ij]]);
189  shvec[ii]->top++;
190 
191  }
192  if( shvec[nnIdx[ij]]->neighbours.end() ==
193  find(shvec[nnIdx[ij]]->neighbours.begin(),shvec[nnIdx[ij]]->neighbours.end(), shvec[ii]))
194  {
195  shvec[nnIdx[ij]]->neighbours.push_back(shvec[ii]);
196  shvec[nnIdx[ij]]->top++;
197  }
198 
199  }
200 
201  }else{
202  if( koliko !=0)
203  {
204  shvec[ii]->top=koliko;
205  for(unsigned int ij=0;ij<koliko ;ij++)
206  shvec[ii]->neighbours.push_back( shvec[nnIdx[ij]]);
207  }
208  }
209  }else{
210  if( koliko !=0)
211  {
212  shvec[ii]->top=koliko;
213  for(unsigned int ij=0;ij<koliko;ij++)
214  shvec[ii]->neighbours.push_back( shvec[nnIdx[ij]]);
215  }
216  }
217  }
218  delete [] nnIdx;
219  delete [] dists;
220  annDeallocPts(dataPts);
221  delete kdTree;
222  annClose();
223 
224 }
225 
226 
227 
228 void GridTransform2( CalorimeterHit* clh,float& radius, float& halfz, float& cellsize,float*X,
229  bool tip,int stove,int module,CellIDDecoder<CalorimeterHit>& id)
230 {
231 
232  unsigned int layer;
233  double coss;
234  double sinn;
235 
236  if( !tip)
237  {
238  stove = id(clh)["S-1"];
239  module = id(clh)["M"];
240  layer = id(clh)["K-1"];
241 
242  }else{
243  int stove2= id(clh)["S-1"];
244  if ( stove2!=stove)
245  {
246 
247  coss= cos(M_PI_4*stove);
248  sinn= sin(M_PI_4*stove);
249  float tmp_y=coss*clh->getPosition()[1]-sinn*clh->getPosition()[0];
250  layer=(unsigned int) ((tmp_y-radius)/PGDB[PGdb::ECAL1_BAR].sampling);
251 
252  if ( layer> PGDB[PGdb::ECAL1_BAR].n_sampl-1 )
253  {
254  layer=PGDB[PGdb::ECAL1_BAR].n_sampl-1+
255  (unsigned int)(( tmp_y-radius- PGDB[PGdb::ECAL1_BAR].n_sampl*
256  PGDB[PGdb::ECAL1_BAR].sampling)/PGDB[PGdb::ECAL2_BAR].sampling);
257  }
258 
259  }else{
260  layer = id(clh)["K-1"];
261  }
262 
263  }
264 
265  coss= cos(M_PI_4*stove);
266  sinn= sin(M_PI_4*stove);
267 
268  if( module !=0 && module!=6)
269  {
270  float tmp_x=coss*clh->getPosition()[0]+sinn*clh->getPosition()[1];
271  float tmp_y=radius+(layer+1)*cellsize;
272 
273  X[0]= coss*tmp_x-sinn*tmp_y;
274  X[1]= coss*tmp_y+sinn*tmp_x;
275  X[2]=clh->getPosition()[2];
276 
277  }else{ // endcap
278  X[0]=clh->getPosition()[0];
279  X[1]=clh->getPosition()[1];
280  X[2]= (-1+module/3)*(halfz+layer*cellsize);
281  }
282 
283 }
284 
285 
286 void FindCores2(Shitvec2* secal1, vector<Tmpclvec2>& bbb , vector <PROTSEED2> * prs2,
287  unsigned int N, vector<float> miipstep, CoreCut2 Ccut)
288 {
289  typedef pair<int,int> test;
290  int psl_plun_global=0;
291 
292  double Diagby2=PGDB[PGdb::ECAL1_BAR].cell_size*sqrt(2.0)/2.0;
293  double d=PGDB[PGdb::ECAL1_BAR].r_inner;
294  double z=PGDB[PGdb::ECAL1_CAP].z_inner;
295  double Xatf[3];
296  vector< vector<Superhit2*> > blk(N) ;
297 
298  for( unsigned int iim=0;iim<secal1->size();iim++)
299  {
300  int koji=0;
301 
302  for(unsigned int ib=0;ib<N;ib++)
303  {
304  if( (*secal1)[iim]->mip > miipstep[ib])
305  koji=ib;
306  else
307  break;
308  }
309  for( int im=koji;im>=0 ;im--)
310  blk[im].push_back((*secal1)[iim]);
311  }
312 
313  vector<Tmpcl2*> testvektor;
314 
315  for( unsigned int iim=0;iim<N;iim++)
316  {
317  cluster5(&blk[iim],&bbb[iim]);
318  }
319 
320  for(unsigned int iim=0;iim<N;iim++)
321  {
322 
323  if(bbb[iim].size()!=0)
324  {
325  for(unsigned int im=0;im<bbb[iim].size();im++)
326  {
327  bbb[iim][im]->calcCenter();
328  bbb[iim][im]->findInertia();
329 
330  }
331  }
332  }
333 
334  int poslednjipun=N-1;
335  for( unsigned int im=0;im<N;im++)
336  {
337  if(bbb[im].size()==0)
338  {
339  poslednjipun=im-1;
340  break;
341  }
342  poslednjipun=im;
343  }
344  psl_plun_global=poslednjipun;
345 
346  vector < PROTSEED2 > prs;
347 
348  for(unsigned int im=0;im<bbb[0].size();im++)
349  {
350  if(bbb[0][im]->hits.size()>Ccut.MinHit0)
351  {
352  PROTSEED2 km;
353  km.cl=bbb[0][im];
354  km.level=0;
355  km.X[0]=0.0;
356  km.X[1]=0.0;
357  km.X[2]=0.0;
358  km.active=true;
359  prs.push_back(km);
360  }
361  }
362 
363 
364  for( unsigned int iim=0;iim<prs.size();iim++)
365  {
366  Xatf[0]=0.0;
367  Xatf[1]=0.0;
368  Xatf[2]=0.0;
369 
370  LineCaloIntersectD2(prs[iim].cl->getCenter(), prs[iim].cl->direction,d,z,Xatf);
371 
372  prs[iim].X[0]=Xatf[0];
373  prs[iim].X[1]=Xatf[1];
374  prs[iim].X[2]=Xatf[2];
375  prs2->push_back(prs[iim]);
376 
377  }
378 
379  for(int i=1;i<=poslednjipun;i++)
380  {
381 
382  for( unsigned int im=0;im<prs2->size();im++)
383  {
384  if( (*prs2)[im].active)
385  {
386  Tmpclvec2 izv;
387  ClusterInCluster2((*prs2)[im].cl, bbb[i],izv);
388 
389  if( izv.size()<=1)
390  {
391  // 1-in-1 nothing to do
392  }else{
393 
394  vector < int > gssf;
395  vector < int > gssfa;
396  for( unsigned int imj=0;imj<izv.size();imj++)
397  {
398 
399  for(unsigned int imm=0;imm<izv.size();imm++)
400  {
401  if(imm!=imj)
402  {
403 
404  if( izv[imj]->hits.size()>=Ccut.MinHitSplit
405  && izv[imm]->hits.size()>=Ccut.MinHitSplit)
406  {
407  double XIP[3];
408  XIP[0]=0.0; XIP[1]=0.0; XIP[2]=0.0;
409 
410  // Split the split in two categories
411  // clear one (larger distance) and not so clear
412 
413  if((LinePointDistance2(XIP,(*prs2)[im].cl->center,izv[imm]->center)>Diagby2 ||
414  LinePointDistance2(XIP,(*prs2)[im].cl->center,izv[imj]->center)>Diagby2 ))
415  {
416  if(find(gssf.begin(),gssf.end(),(int)imm)==gssf.end())
417  gssf.push_back(imm);
418  if(find(gssf.begin(),gssf.end(),(int)imj)==gssf.end())
419  gssf.push_back(imj);
420 
421  }else{
422  if(find(gssfa.begin(),gssfa.end(),(int)imm)==gssfa.end())
423  gssfa.push_back(imm);
424  if(find(gssfa.begin(),gssfa.end(),(int)imj)==gssfa.end())
425  gssfa.push_back(imj);
426  }
427  }
428  }
429  }
430  }
431 
432  if(gssf.size()!=0)
433  {
434 
435  int nh1=0;
436 
437  int nh3=(*prs2)[im].cl->hits.size();
438  for( unsigned int j=0;j<gssf.size();j++)
439  nh1+=izv[gssf[j]]->hits.size();
440 
441  double ratio = ((double)nh1)/((double)nh3);
442  (*prs2)[im].active=false;
443 
444  if( ratio > Ccut.Rcut )
445  {
446  for( unsigned int j=0;j<gssfa.size();j++)
447  {
448  Xatf[0]=0.0;
449  Xatf[1]=0.0;
450  Xatf[2]=0.0;
451 
452  PROTSEED2 a;
453 
454  a.cl=izv[gssfa[j]];
455  a.level=i;
456  LineCaloIntersectD2(izv[gssfa[j]]->getCenter(),
457  izv[gssfa[j]]->direction,d,z,Xatf);
458  a.X[0]=Xatf[0];
459  a.X[1]=Xatf[1];
460  a.X[2]=Xatf[2];
461  a.active=true;
462  bool stavi=true;
463  for( unsigned int im=0;im<prs2->size();im++)
464  {
465  if((*prs2)[im].active)
466  {
467  if( (*prs2)[im].cl==a.cl)
468  stavi=false;
469  }
470  }
471  if(stavi)
472  prs2->push_back(a);
473 
474  }
475  }
476 
477 
478  for( unsigned int j=0;j<gssf.size();j++)
479  {
480 
481  Xatf[0]=0.0;
482  Xatf[1]=0.0;
483  Xatf[2]=0.0;
484 
485  PROTSEED2 a;
486 
487  a.cl=izv[gssf[j]];
488  a.level=i;
489  LineCaloIntersectD2(izv[gssf[j]]->getCenter(),
490  izv[gssf[j]]->direction,d,z,Xatf);
491  a.X[0]=Xatf[0];
492  a.X[1]=Xatf[1];
493  a.X[2]=Xatf[2];
494  a.active=true;
495 
496  bool stavi=true;
497  for( unsigned int im=0;im<prs2->size();im++)
498  {
499  if((*prs2)[im].active)
500  {
501  if( (*prs2)[im].cl==a.cl)
502  stavi=false;
503  }
504  }
505  if(stavi)
506  prs2->push_back(a);
507  }
508 
509 
510  }
511 
512  }
513  }// if active
514  }
515 
516  }
517 
518 
519  vector <test> kojsv;
520 
521  for( unsigned int im=0;im<prs2->size();im++)
522  {
523  if((*prs2)[im].active)
524  {
525 
526  double Xa[3];
527  ModuleNormal2((*prs2)[im].cl->center,z, Xa);
528 
529 
530  for( unsigned int ij=0;ij<prs2->size();ij++)
531  {
532  if( ij!=im && (*prs2)[ij].active)
533  {
534 
535  double dircc[3];
536  dircc[0]=(*prs2)[im].cl->center[0]-(*prs2)[ij].cl->center[0];
537  dircc[1]=(*prs2)[im].cl->center[1]-(*prs2)[ij].cl->center[1];
538  dircc[2]=(*prs2)[im].cl->center[2]-(*prs2)[ij].cl->center[2];
539 
540  //MERGE CONDITION
541  if ( D_cl_cl2((*prs2)[im].cl,(*prs2)[ij].cl)<Ccut.Distcut
542  && fabs( Dot2((*prs2)[ij].cl->center,dircc))>Ccut.Coscut)
543  {
544  test a,b;
545  a.first=im;
546  a.second=ij;
547  b.first=ij;
548  b.second=im;
549  if(find(kojsv.begin(),kojsv.end(),a)==kojsv.end() &&
550  find(kojsv.begin(),kojsv.end(),b)==kojsv.end())
551  {
552  kojsv.push_back(a);
553 
554  }
555  }
556 
557  }
558  }
559  }
560  }
561 
562 
563  if(kojsv.size()!=0)
564  {
565 
566  int iskoristio[kojsv.size()];
567  for(unsigned int i=0;i<kojsv.size();i++)
568  {
569  iskoristio[i]=0;
570  }
571  for(unsigned int i=0;i<kojsv.size();i++)
572  {
573  if( iskoristio[i]==0)
574  {
575  vector <int> trojka;
576  trojka.push_back(kojsv[i].first);
577  trojka.push_back(kojsv[i].second);
578  iskoristio[i]=1;
579  for(unsigned int j=0;j<kojsv.size();j++)
580  {
581 
582  if(
583  (find(trojka.begin(),trojka.end(),kojsv[j].first)!=trojka.end() &&
584  find(trojka.begin(),trojka.end(),kojsv[j].second)==trojka.end() ) ||
585  (find(trojka.begin(),trojka.end(),kojsv[j].second)!=trojka.end() &&
586  find(trojka.begin(),trojka.end(),kojsv[j].first)==trojka.end() ))
587  {
588 
589  if(find(trojka.begin(),trojka.end(),kojsv[j].first)==trojka.end())
590  {
591  if(iskoristio[j]!=1)
592  {
593 
594  iskoristio[j]=1;
595  if( (*prs2)[kojsv[j].first].active)
596  trojka.push_back(kojsv[j].first);
597  }
598 
599  } else{
600  if(iskoristio[j]!=1)
601  {
602  if( (*prs2)[kojsv[j].second].active)
603  trojka.push_back(kojsv[j].second);
604  iskoristio[j]=1;
605  }
606  }
607  }
608  }
609 
610 
611  int kakvi=1;
612  for( unsigned int j=1;j<trojka.size();j++)
613  {
614  if((*prs2)[trojka[0]].level!=(*prs2)[trojka[j]].level)
615  kakvi++;
616  }
617 
618  if(kakvi==1)
619  {
620 
621  Tmpcl2* cl = new Tmpcl2();
622  for(unsigned int j=0;j<trojka.size();j++)
623  {
624  if( (*prs2)[trojka[j]].active)
625  {
626  for(unsigned int jj=0;jj<(*prs2)[trojka[j]].cl->hits.size();jj++)
627  {
628  cl->hits.push_back((*prs2)[trojka[j]].cl->hits[jj]);
629  }
630  (*prs2)[trojka[j]].active=false;
631  }
632  }
633  if( cl->hits.size()!=0)
634  {
635 
636  cl->calcCenter();
637  cl->findInertia();
638  bbb[(*prs2)[trojka[0]].level].push_back(cl);
639 
640  Xatf[0]=0.0;
641  Xatf[1]=0.0;
642  Xatf[2]=0.0;
643 
644  PROTSEED2 a;
645  a.cl=cl;
646  a.level=(*prs2)[trojka[0]].level;
648  cl->direction,d,z,Xatf);
649  a.X[0]=Xatf[0];
650  a.X[1]=Xatf[1];
651  a.X[2]=Xatf[2];
652  a.active=true;
653 
654  bool stavi=true;
655  for( unsigned int im=0;im<prs2->size();im++)
656  {
657  if((*prs2)[im].active)
658  {
659  if( (*prs2)[im].cl==a.cl)
660  stavi=false;
661  }
662  }
663  if(stavi)
664  prs2->push_back(a);
665 
666  }else{
667  delete cl;
668  }
669  }else{
670 
671 
672  vector <int > nivoi;
673  for(unsigned int j=0;j<trojka.size();j++)
674  {
675  if( find(nivoi.begin(),nivoi.end(),(*prs2)[trojka[j]].level)==nivoi.end())
676  nivoi.push_back((*prs2)[trojka[j]].level);
677  }
678 
679  if(trojka.size()==2)
680  {
681  if( (*prs2)[trojka[0]].cl->getEnergy() >=(*prs2)[trojka[1]].cl->getEnergy())
682  {
683  (*prs2)[trojka[1]].active=false;
684  }else{
685  (*prs2)[trojka[0]].active=false;
686  }
687  }else{
688 
689  vector <int> izabrani;
690  int isko[trojka.size()];
691  for(unsigned int jj=0;jj<trojka.size();jj++)
692  {
693  isko[jj]=0;
694  }
695  for(unsigned int j=0;j<nivoi.size();j++)
696  {
697  vector<int> sabr;
698  for(unsigned int jj=0;jj<trojka.size();jj++)
699  {
700  if(isko[jj]==0)
701  {
702  if( nivoi[j]==(*prs2)[trojka[jj]].level)
703  {
704  sabr.push_back(trojka[jj]);
705  isko[jj]=1;
706  }
707  }
708  }
709 
710  if(sabr.size()>1)
711  {
712 
713  Tmpcl2* cl = new Tmpcl2();
714  for(unsigned int jk=0;jk<sabr.size();jk++)
715  {
716  (*prs2)[sabr[jk]].active=false;
717  for(unsigned int jj=0;jj<(*prs2)[sabr[jk]].cl->hits.size();jj++)
718  cl->hits.push_back((*prs2)[sabr[jk]].cl->hits[jj]);
719  }
720 
721  cl->calcCenter();
722  cl->findInertia();
723  bbb[nivoi[j]].push_back(cl);
724 
725  Xatf[0]=0.0;
726  Xatf[1]=0.0;
727  Xatf[2]=0.0;
728 
729  PROTSEED2 a;
730 
731  a.cl=cl;
732  a.level=(*prs2)[nivoi[j]].level;
734  cl->direction,d,z,Xatf);
735  a.X[0]=Xatf[0];
736  a.X[1]=Xatf[1];
737  a.X[2]=Xatf[2];
738  a.active=true;
739 
740  bool stavi=true;
741  for( unsigned int im=0;im<prs2->size();im++)
742  {
743  if((*prs2)[im].active)
744  {
745  if( (*prs2)[im].cl==a.cl)
746  stavi=false;
747  }
748  }
749  if(stavi)
750  {
751  prs2->push_back(a);
752  izabrani.push_back(prs2->size()-1);
753  }else{
754  delete cl;
755  }
756  }else{
757  izabrani.push_back(sabr[0]);
758  }
759  }
760  if( izabrani.size()>1)
761  {
762  typedef pair <double,int> DpI;
763  vector <DpI> bfjl;
764  for( unsigned int j=0;j<izabrani.size();j++)
765  {
766  DpI tmp;
767  tmp.first=(*prs2)[izabrani[j]].cl->getEnergy();
768  tmp.second=izabrani[j];
769  bfjl.push_back(tmp);
770  }
771 
772  sort(bfjl.begin(),bfjl.end());
773 
774  for( unsigned int j=0;j<izabrani.size()-1;j++)
775  {
776  (*prs2)[bfjl[j].second].active=false;
777  }
778 
779 
780  }
781  }
782 
783  }
784  }
785  } // koj =0.0
786  }
787 }
788 
789 
790 
791 
792 void cluster5( vector<Superhit2*>* shv, vector<Tmpcl2*>* clv)
793 {
794 
795  if( (*shv).size()!=0)
796  {
797 
798  for(unsigned int i=0;i<(*shv).size();i++)
799  {
800  (*shv)[i]->is_assigned=false;
801  }
802 
803  unsigned int shvsz=(*shv).size();
804 
805  for(unsigned int i=0;i<shvsz;i++)
806  {
807 
808  if( (*shv)[i]->top==0 )
809  {
810  Tmpcl2* cl =new Tmpcl2();
811  cl->hits.push_back((*shv)[i]);
812  (*shv)[i]->is_assigned=true;
813  clv->push_back(cl);
814  continue;
815  }else{
816 
817  if( (*shv)[i]->is_assigned==false)
818  {
819  vector<Superhit2*> sshv;
820  stack <Superhit2*> shstack;
821  sshv.push_back((*shv)[i]);
822 
823  for(unsigned int j=0;j<(*shv)[i]->neighbours.size();j++)
824  {
825  if( !((*shv)[i]->neighbours[j]->is_assigned) &&
826  shv->end() !=find(shv->begin(),shv->end(), (*shv)[i]->neighbours[j]))
827  {
828  sshv.push_back((*shv)[i]->neighbours[j]);
829  (*shv)[i]->neighbours[j]->is_assigned=true;
830  shstack.push((*shv)[i]->neighbours[j]);
831  }
832  }
833 
834  while(!shstack.empty())
835  {
836  Superhit2* sh=shstack.top();
837  shstack.pop();
838  //sshv.push_back(sh);
839 
840  for(unsigned int j=0;j<sh->neighbours.size();j++)
841  {
842  if( sh->neighbours[j]!=0 )
843  {
844  if( ! sh->neighbours[j]->is_assigned &&
845  shv->end() !=find(shv->begin(),shv->end(), sh->neighbours[j]))
846  {
847  if(sshv.end()==find(sshv.begin(),sshv.end(),sh->neighbours[j]))
848  {
849  sshv.push_back(sh->neighbours[j]);
850  sh->neighbours[j]->is_assigned=true;
851 
852  shstack.push(sh->neighbours[j]);
853  }
854  }
855  }
856  }
857  }
858  if(sshv.size()!=0)
859  {
860  Tmpcl2* cl=new Tmpcl2();
861  for(unsigned int im=0;im<sshv.size();im++)
862  {
863  cl->hits.push_back(sshv[im]);
864  }
865  clv->push_back(cl);
866  }
867  }
868  }
869 
870  }// over all hits
871 
872  for(unsigned int i=0;i<shv->size();i++)
873  if((*shv)[i]->is_assigned==false)
874  {
875  Tmpcl2* cl=new Tmpcl2();
876  cl->hits.push_back((*shv)[i]);
877  clv->push_back(cl);
878  }
879 
880  }
881 }
882 
883 
885 
886 Superhit2::Superhit2(float E, CalorimeterHit* chitin){
887  chit=chitin;
888  for(unsigned int i=0;i<3;i++)
889  {
890  point[i]=0.0;
891  pointt[i]=chitin->getPosition()[i];
892  }
893  mip=chit->getEnergy()/E;
894  connect=false;
895  is_assigned=false;
896  mipE=E;
897  top=0;
898  cl=0;
899  S=0;
900  M=0;
901  K=0;
902  tip=0;
903 
904 }
906 {
907  return center;
908 }
909 
910 
912  energy=0.0;
913 }
915 
917 
918  energy =0.0;
919  for( unsigned int i=0; i<hits.size();i++)
920  {
921  energy+=hits[i]->chit->getEnergy();
922  }
923  return energy;
924 }
926 {
927  center[0]=0.0;
928  center[1]=0.0;
929  center[2]=0.0;
930  double norm=0.0;
931  double en=0.0;
932  for( unsigned int i=0; i<hits.size();i++)
933  {
934  en=hits[i]->chit->getEnergy();
935  center[0]+=hits[i]->pointt[0]*en;
936  center[1]+=hits[i]->pointt[1]*en;
937  center[2]+=hits[i]->pointt[2]*en;
938  norm+=en;
939  }
940  center[0]=center[0]/norm;
941  center[1]=center[1]/norm;
942  center[2]=center[2]/norm;
943 }
944 
945 
946 
948 {
949 
950  double aIne[3][3];
951  for (int i(0); i < 3; ++i) {
952  for (int j(0); j < 3; ++j) {
953  aIne[i][j] = 0.0;
954  }
955  }
956 
957 
958  for( unsigned int i=0; i<hits.size();i++)
959  {
960  double dX = hits[i]->pointt[0] - center[0];
961  double dY = hits[i]->pointt[1] - center[1];
962  double dZ = hits[i]->pointt[2] - center[2];
963  double eneh=hits[i]->chit->getEnergy();
964  eneh=1.0;
965  aIne[0][0] += eneh*(dY*dY+dZ*dZ);
966  aIne[1][1] += eneh*(dX*dX+dZ*dZ);
967  aIne[2][2] += eneh*(dX*dX+dY*dY);
968  aIne[0][1] -= eneh*dX*dY;
969  aIne[0][2] -= eneh*dX*dZ;
970  aIne[1][2] -= eneh*dY*dZ;
971  }
972 
973  for (int i(0); i < 2; ++i) {
974  for (int j = i+1; j < 3; ++j) {
975  aIne[j][i] = aIne[i][j];
976  }
977  }
978 
979 
980  gsl_matrix_view aMatrix = gsl_matrix_view_array((double*)aIne,3,3);
981  gsl_vector* aVector = gsl_vector_alloc(3);
982  gsl_matrix* aEigenVec = gsl_matrix_alloc(3,3);
983  gsl_eigen_symmv_workspace* wa = gsl_eigen_symmv_alloc(3);
984  gsl_eigen_symmv(&aMatrix.matrix,aVector,aEigenVec,wa);
985  gsl_eigen_symmv_free(wa);
986  gsl_eigen_symmv_sort(aVector,aEigenVec,GSL_EIGEN_SORT_ABS_ASC);
987  double norm=0.0;
988  for (int i(0); i < 3; i++) {
989  inteigen[i] = gsl_vector_get(aVector,i);
990  norm+=inteigen[i]* inteigen[i];
991  for (int j(0); j < 3; j++) {
992  inteigenvec[i+3*j] = gsl_matrix_get(aEigenVec,i,j);
993  }
994  }
995  norm=sqrt(norm);
996 
997 
998  for (int i(0); i < 3; i++)
999  inteigen[i]=inteigen[i]/norm;
1000 
1001  direction[0]=inteigenvec[0];
1002  direction[1]=inteigenvec[1];
1003  direction[2]=inteigenvec[2];
1004 
1005  gsl_vector_free(aVector);
1006  gsl_matrix_free(aEigenVec);
1007 
1008 
1009 }
1010 
1011 void LineCaloIntersectD2( double* X1, double* dir,double&d,double&zmax, double*X)
1012 {
1013 
1014  double X2[3];
1015  X2[0]=X1[0]+dir[0]*400.0;
1016  X2[1]=X1[1]+dir[1]*400.0;
1017  X2[2]=X1[2]+dir[2]*400.0;
1018 
1019  LineCaloIntersect2( X2,X1,d,zmax,X);
1020 
1021  if( X[0]==0.0)
1022  {
1023 
1024  X2[0]=X1[0]-dir[0]*400.0;
1025  X2[1]=X1[1]-dir[1]*400.0;
1026  X2[2]=X1[2]-dir[2]*400.0;
1027 
1028  LineCaloIntersect2(X2, X1,d,zmax,X);
1029 
1030  }
1031 }
1032 
1033 void LineCaloIntersect2(double* X1, double* X2,double&d,double&zmax, double*X)
1034 {
1035  double n[10][3];
1036 
1037  double koren2=M_SQRT2/2.0;
1038 
1039  n[0][0]=0.0;
1040  n[0][1]=1.0;
1041  n[0][2]=0.0;
1042 
1043  n[1][0]=koren2;
1044  n[1][1]=koren2;
1045  n[1][2]=0.0;
1046 
1047  n[2][0]=1.0;
1048  n[2][1]=0.0;
1049  n[2][2]=0.0;
1050 
1051  n[3][0]=-1.0;
1052  n[3][1]=0.0;
1053  n[3][2]=0.0;
1054 
1055  n[4][0]=0.0;
1056  n[4][1]=-1.0;
1057  n[4][2]=0.0;
1058 
1059  n[5][0]=-koren2;
1060  n[5][1]=-koren2;
1061  n[5][2]=0.0;
1062 
1063  n[6][0]=koren2;
1064  n[6][1]=-koren2;
1065  n[6][2]=0.0;
1066 
1067  n[7][0]=-koren2;
1068  n[7][1]=koren2;
1069  n[7][2]=0.0;
1070 
1071 
1072  n[8][0]=0.0;
1073  n[8][1]=0.0;
1074  n[8][2]=1.0;
1075 
1076  n[9][0]=0.0;
1077  n[9][1]=0.0;
1078  n[9][2]=-1.0;
1079 
1080 
1081 
1082  if ( abs(X2[2])<zmax)
1083  {
1084 
1085 
1086  vector < vector <double> > test;
1087  for ( unsigned int i=0; i<8;i++)
1088  {
1089  double tmp=-(n[i][0]*n[i][0]+n[i][1]*n[i][1]+n[i][2]*n[i][2])*d
1090  +n[i][0]*X1[0]+n[i][1]*X1[1]+n[i][2]*X1[2];
1091 
1092  double tmp2=n[i][0]*(X1[0]-X2[0])+n[i][1]*(X1[1]-X2[1])+n[i][2]*(X1[2]-X2[2]);
1093 
1094  double t=-2.0;
1095  if(tmp2!=0.0)
1096  {
1097  t=tmp/tmp2;
1098 
1099  }
1100 
1101  if (t>0.0 && t<=1.0)
1102  {
1103  vector <double> tmpi;
1104  tmpi.push_back(X1[0]+(X2[0]-X1[0])*t);
1105  tmpi.push_back(X1[1]+(X2[1]-X1[1])*t);
1106  tmpi.push_back(X1[2]+(X2[2]-X1[2])*t);
1107  test.push_back(tmpi);
1108  }
1109 
1110  }
1111 
1112  if (test.size()==1)
1113  {
1114 
1115  X[0]=test[0][0];
1116  X[1]=test[0][1];
1117  X[2]=test[0][2];
1118  double rts=sqrt(X[0]*X[0]+X[1]*X[1]);
1119  if( rts< ((d+2.0)*1.0823922002924))
1120  {
1121  return;
1122  }else{
1123  X[0]=0.0;
1124  X[1]=0.0;
1125  X[2]=0.0;
1126  return;
1127  }
1128  }else{
1129 
1130  double rmin=1e+22;
1131  unsigned int imin=999;
1132 
1133  for( unsigned int i=0; i<test.size();i++)
1134  {
1135  double Xa[3];
1136  Xa[0]=test[i][0]; Xa[1]=test[i][1]; Xa[2]=test[i][2];
1137 
1138  double tmpr=sqrt(Xa[0]*Xa[0]+Xa[1]*Xa[1]);
1139  if( tmpr<rmin)
1140  {
1141  rmin=tmpr;
1142  imin=i;
1143  }
1144  }
1145 
1146  if ( imin< test.size())
1147  {
1148  X[0]=test[imin][0];
1149  X[1]=test[imin][1];
1150  X[2]=test[imin][2];
1151  return;
1152  }else{
1153  X[0]=0.0;
1154  X[1]=0.0;
1155  X[2]=0.0;
1156  return;
1157  }
1158  }
1159 
1160  }else { // endcap
1161  double n[8][3];
1162  if(X2[2]>0.0)
1163  {
1164  n[0][0]=0.0;
1165  n[0][1]=0.0;
1166  n[0][2]=1.0;
1167  }else{
1168  n[0][0]=0.0;
1169  n[0][1]=0.0;
1170  n[0][2]=-1.0;
1171  }
1172 
1173 
1174  double tmp=-(n[0][0]*n[0][0]+n[0][1]*n[0][1]+n[0][2]*n[0][2])*zmax
1175  +n[0][0]*X1[0]+n[0][1]*X1[1]+n[0][2]*X1[2];
1176  double tmp2=n[0][0]*(X1[0]-X2[0])+n[0][1]*(X1[1]-X2[1])+n[0][2]*(X1[2]-X2[2]);
1177  double t=0.0;
1178 
1179  if(tmp2!=0.0)
1180  {
1181  t=tmp/tmp2;
1182  }
1183  if(t>0.0 && t<=1.0)
1184  {
1185  X[0]=X1[0]+(X2[0]-X1[0])*t ;
1186  X[1]=X1[1]+(X2[1]-X1[1])*t ;
1187  X[2]=X1[2]+(X2[2]-X1[2])*t ;
1188  return;
1189  }else{
1190  X[0]=0.0;
1191  X[1]=0.0;
1192  X[2]=0.0;
1193  return;
1194  }
1195  }
1196 }
1197 
1198 
1199 void ClusterInCluster2(Tmpcl2* cl, vector<Tmpcl2*>& clv)
1200 {
1201 
1202  sort(cl->hits.begin(),cl->hits.end());
1203 
1204  for(unsigned int i=0;i<clv.size();i++)
1205  {
1206  sort(clv[i]->hits.begin(),clv[i]->hits.end());
1207  if( includes(cl->hits.begin(),cl->hits.end(),clv[i]->hits.begin(),clv[i]->hits.end()))
1208  {
1209  cl->daughters.push_back(clv[i]);
1210  clv[i]->parents.push_back(cl);
1211  }
1212  }
1213 
1214 }
1215 
1216 double LinePointDistance2( double* X1, double* X2, double* X0){
1217 
1218 double tmp1=X1[1]*X2[0]-X1[0]*X2[1]-X1[1]*X0[0]+X2[1]*X0[0]+X1[0]*X0[1]-X2[0]*X0[1];
1219 double tmp2=X1[2]*X2[0]-X1[0]*X2[2]-X1[2]*X0[0]+X2[2]*X0[0]+X1[0]*X0[2]-X2[0]*X0[2];
1220 double tmp3=X1[2]*X2[1]-X1[1]*X2[2]-X1[2]*X0[1]+X2[2]*X0[1]+X1[1]*X0[2]-X2[1]*X0[2];
1221 double tmp4=(X1[0]-X2[0])*(X1[0]-X2[0])+(X1[1]-X2[1])*(X1[1]-X2[1])+(X1[2]-X2[2])*(X1[2]-X2[2]);
1222 
1223  double tmp5=tmp1*tmp1+tmp2*tmp2+tmp3*tmp3;
1224  tmp5=tmp5/tmp4;
1225  return sqrt(tmp5);
1226 
1227 }
1228 
1229 void ModuleNormal2(double* X1,double& zmax, double* X0)
1230 {
1231 
1232 
1233  if ( abs(X1[2])<zmax)
1234  {
1235 
1236  double fi=atan2(X1[0],X1[1]);
1237  double fi0=M_PI_4/2.0;
1238 
1239  int i;
1240  if( fi>=0.)
1241  i=(int)((fi+fi0)/M_PI_4);
1242  else
1243  i=(int)((fi-fi0)/M_PI_4);
1244 
1245 
1246  double fip=i*M_PI_4;
1247  if( i!=0)
1248  {
1249  X0[0]=sin(fip);
1250  X0[1]=cos(fip);
1251  X0[2]=0.0;
1252  }else{
1253  X0[0]=0.0;
1254  X0[1]=1.0;
1255  X0[2]=0.0;
1256 
1257  }
1258  }else{
1259 
1260  if( X1[2]>0.)
1261  {
1262  X0[0]=0.0;
1263  X0[1]=0.0;
1264  X0[2]=1.0;
1265  }else{
1266  X0[0]=0.0;
1267  X0[1]=0.0;
1268  X0[2]=-1.0;
1269  }
1270  }
1271 }
1272 double D_cl_cl2(Tmpcl2* cl1,Tmpcl2* cl2)
1273 {
1274 
1275  vector <double> dist;
1276 
1277 
1278  for( unsigned int i=0; i<cl1->hits.size();i++)
1279  {
1280  double x1=cl1->hits[i]->pointt[0];
1281  double y1=cl1->hits[i]->pointt[1];
1282  double z1=cl1->hits[i]->pointt[2];
1283 
1284  for( unsigned int j=0; j<cl2->hits.size();j++)
1285  {
1286 
1287  double tmp=((x1-cl2->hits[j]->pointt[0])*(x1-cl2->hits[j]->pointt[0])+
1288  (y1-cl2->hits[j]->pointt[1])*(y1-cl2->hits[j]->pointt[1])+
1289  (z1-cl2->hits[j]->pointt[2])*(z1-cl2->hits[j]->pointt[2]) ) ;
1290  dist.push_back(tmp);
1291  }
1292  }
1293  sort(dist.begin(),dist.end());
1294  return sqrt(dist[0]);
1295 
1296 }
1297 inline double Dot2(double* X1,double* X2)
1298 {
1299  double n1=sqrt(X1[0]*X1[0]+X1[1]*X1[1]+X1[2]*X1[2]);
1300  double n2=sqrt(X2[0]*X2[0]+X2[1]*X2[1]+X2[2]*X2[2]);
1301 
1302  return (X1[0]*X2[0]+X1[1]*X2[1]+X1[2]*X2[2])/(n1*n2);
1303 }
1304 void ClusterInCluster2(Tmpcl2* cl, vector<Tmpcl2*>& clv,vector<Tmpcl2*>& clout)
1305 {
1306 
1307 
1308  sort(cl->hits.begin(),cl->hits.end());
1309 
1310  for(unsigned int i=0;i<clv.size();i++)
1311  {
1312  sort(clv[i]->hits.begin(),clv[i]->hits.end());
1313  if( includes(cl->hits.begin(),cl->hits.end(),clv[i]->hits.begin(),clv[i]->hits.end()))
1314  clout.push_back(clv[i]);
1315  }
1316 }
1318 
1319 Photon2:: Photon2(double Ein,double* pravac, double* pocetak)
1320 {
1321  Ee=Ein;
1322  dir[0]=pravac[0];
1323  dir[1]=pravac[1];
1324  dir[2]=pravac[2];
1325  start[0]=pocetak[0];
1326  start[1]=pocetak[1];
1327  start[2]=pocetak[2];
1328 
1329  PGdb::ZONE zons ;
1330  zons=PGdb::ECAL1_BAR;
1331 
1332  Z =PGDB[zons].Zeff;
1333  x0eff =PGDB[zons].x0eff;
1334  sampling =PGDB[zons].sampling;
1335  Eceff =PGDB[zons].Eceff;
1336  eprime =PGDB[zons].eprime;
1337  Rm =PGDB[zons].Rmeff;
1338 
1339  z1=0.0251+0.00319*log(Ee*1000.0);
1340  z2=0.1162-0.000381*Z;
1341  k1=0.659-0.00309*Z;
1342  k2=0.645;
1343  k3=-2.59;
1344  k4=0.3585+0.0421*log(Ee*1000.0);
1345  p1=2.632-0.00094*Z;
1346  p2=0.401+0.00187*Z;
1347  p3=1.313-0.0686*log(Ee*1000.0);
1348  y=Ee*1000.0/Eceff;
1349 
1350  Fs=x0eff/sampling;
1351 
1352  Thom=log(y)-0.858;
1353  Tsam=Thom-0.59/Fs-0.53*(1.0-eprime);
1354  alfahom=0.21+(0.492+2.38/Z)*log(y);
1355  alfasam=alfahom-0.444/Fs;
1356  betasam=0.5;
1357 
1358 }
1359 
1360 
1361 void Photon2::Prob(CalorimeterHit* ch,double cut,double* out)
1362 {
1363 
1364  double X[3];
1365  PointOnLine22(start, dir,ch->getPosition(),X);
1366 
1367  double TP[3]; TP[0]=ch->getPosition()[0]-start[0];
1368  TP[1]=ch->getPosition()[1]-start[1];
1369  TP[2]=ch->getPosition()[2]-start[2];
1370  // distance must have direction
1371  if( Dot2(TP,dir)<0.0)
1372  {
1373  out[0]=0.0;
1374  out[1]=0.0;
1375  return ;
1376  }
1377 
1378  double t=sqrt( (start[0]-X[0])*(start[0]-X[0])+
1379  (start[1]-X[1])*(start[1]-X[1])+
1380  (start[2]-X[2])*(start[2]-X[2]))/x0eff;
1381  double tau= t/Tsam;
1382  double pos[3]; pos[0]=ch->getPosition()[0];pos[1]=ch->getPosition()[1];pos[2]=ch->getPosition()[2];
1383 
1384  double r= LinePointDistance2(start,dir,pos);
1385 
1386 // average radial profiles
1387  double RChom=z1+z2*tau;
1388  double RThom=k1*(exp(k3*(tau-k2))+exp(k4*(tau-k2)));
1389  double phom=p1*exp((p2-tau)/p3-exp((p2-tau)/p3));
1390 
1391 // average radial profiles sampling
1392  double RCsam=RChom-0.0203*(1.0-eprime)+0.0397*exp(-tau)/Fs;
1393  double RTsam=RThom-0.14*(1.0-eprime)-0.495*exp(-tau)/Fs;
1394  double psam =phom+(1.0-eprime)*(0.348-0.642*exp(-pow(tau-1.0,2.0))/Fs);
1395 
1396  double rb=r/Rm;
1397 
1398  if ( rb < 20.0 && t< 35.0)
1399  {
1400  double tmp= pow(betasam*t,alfasam-1.0)*betasam*exp(-betasam*t)/gsl_sf_gamma(alfasam);
1401  tmp=Ee*tmp*(psam*2.0*rb*RCsam*RCsam/pow(rb*rb+RCsam*RCsam,2.0) +
1402  (1-psam)*(2.0*rb*RTsam*RTsam/pow(rb*rb+RTsam*RTsam,2.0)))/rb;
1403  if(tmp>cut)
1404  {
1405  out[0]= tmp;
1406  out[1]= r;
1407  }else{
1408  out[0]=0.0;
1409  out[1]=0.0;
1410  }
1411  }else{
1412  out[0]=0.0;
1413  out[1]=0.0;
1414  }
1415 
1416 
1417 }
1418 
1419 
1420 
1421 void PointOnLine3(const double* X1,const double* X2,const float* X0,double* Xline)
1422 {
1423 
1424 double tmp1=(X1[0]-X0[0])*(X2[0]-X1[0])+(X1[1]-X0[1])*(X2[1]-X1[1])+(X1[2]-X0[2])*(X2[2]-X1[2]);
1425 double tmp4=(X1[0]-X2[0])*(X1[0]-X2[0])+(X1[1]-X2[1])*(X1[1]-X2[1])+(X1[2]-X2[2])*(X1[2]-X2[2]);
1426 double t=-tmp1/tmp4;
1427 
1428 
1429  Xline[0]=X1[0]+(X2[0]-X1[0])*t;
1430  Xline[1]=X1[1]+(X2[1]-X1[1])*t;
1431  Xline[2]=X1[2]+(X2[2]-X1[2])*t;
1432 
1433 }
1434 void PointOnLine22(const double* Xstart,const double* dir,const float* X0,double* Xline)
1435 {
1436  double X1[3];
1437  double X2[3];
1438  X1[0]=Xstart[0]-dir[0]*100.0;
1439  X1[1]=Xstart[1]-dir[1]*100.0;
1440  X1[2]=Xstart[2]-dir[2]*100.0;
1441  X2[0]=Xstart[0]+dir[0]*100.0;
1442  X2[1]=Xstart[1]+dir[1]*100.0;
1443  X2[2]=Xstart[2]+dir[2]*100.0;
1444 
1445 
1446  PointOnLine3(X1,X2,X0,Xline);
1447 
1448 }
1449 
1450 double giveMeEEstimate2(int nivo,double Ecore, vector<CoreCalib2> cc)
1451 {
1452  for(unsigned int i=0;i<cc.size();i++)
1453  {
1454  if( cc[i].level==nivo && cc[i].Emax>Ecore)
1455  {
1456  return cc[i].a+cc[i].b*Ecore;
1457  }
1458  }
1459  return 0.0;
1460 }
1461 
1462 
1463 void CreateCalibrationLDC00(vector<CoreCalib2>* cc)
1464 {
1465 
1466 
1467  double aEnom[9]={0.5,1.0,2.0,3.0,5.0,8.0,12.0,20.0,40.0};
1468  double aa[9][10]={{0.283,0.357,0.337,0.398,0.000,0.000,0.000,0.000,0.000,0.000},
1469  {0.703,0.346,0.814,0.785,0.939,0.000,0.000,0.000,0.000,0.000},
1470  {0.505,0.821,1.000,1.112,1.527,1.860,0.000,0.000,0.000,0.000},
1471  {0.809,0.892,1.999,1.554,2.170,2.870,0.000,0.000,0.000,0.000},
1472  {1.075,0.827,1.290,2.350,2.123,3.958,4.814,0.000,0.000,0.000},
1473  {1.140,1.310,1.765,3.652,4.030,5.600,6.670,0.000,0.000,0.000},
1474  {0.760,1.845,3.444,2.850,5.150,6.760,10.72,0.000,0.000,0.000},
1475  {3.770,4.460,2.270,5.930,8.730,11.00,17.40,17.77,0.000,0.000},
1476  {1.890,3.560,5.120,7.320,9.650,11.71,21.74,0.000,0.000,0.000}};
1477 
1478  double bb[9][10]={{0.730,0.595,0.772,0.683,0.000,0.000,0.000,0.000,0.000,0.000},
1479  {0.493,1.079,0.458,0.592,0.447,0.000,0.000,0.000,0.000,0.000},
1480  {0.941,0.813,0.766,0.782,0.559,0.405,0.000,0.000,0.000,0.000},
1481  {0.892,0.910,0.550,0.809,0.593,0.347,0.000,0.000,0.000,0.000},
1482  {0.918,1.015,0.967,0.800,0.954,0.510,0.356,0.000,0.000,0.000},
1483  {0.974,0.986,0.970,0.778,0.784,0.593,0.509,0.000,0.000,0.000},
1484  {1.032,0.971,0.869,0.986,0.835,0.742,0.339,0.000,0.000,0.000},
1485  {0.891,0.888,1.025,0.884,0.782,0.620,0.314,0.361,0.000,0.000},
1486  {1.020,0.992,0.977,0.962,0.945,0.943,0.724,0.000,0.000,0.000}};
1487 
1488 double aEmin[9][10]={{0.250,0.200,0.150,0.060,0.000,0.000,0.000,0.000,0.000,0.000},
1489  {0.600,0.500,0.350,0.200,0.100,0.000,0.000,0.000,0.000,0.000},
1490  {1.500,1.200,1.100,0.900,0.650,0.300,0.000,0.000,0.000,0.000},
1491  {2.400,2.100,1.900,1.600,1.300,0.600,0.000,0.000,0.000,0.000},
1492  {4.000,4.100,3.900,3.200,2.900,2.400,1.100,0.000,0.000,0.000},
1493  {7.000,6.800,6.200,5.500,5.000,4.200,2.600,0.000,0.000,0.000},
1494  {10.50,10.00,9.500,8.600,8.400,8.300,5.200,0.000,0.000,0.000},
1495  {18.50,18.20,17.40,16.00,15.50,13.00,11.50,9.000,0.000,0.000},
1496  {36.00,35.00,34.00,33.50,32.50,31.00,28.00,0.000,0.000,0.000}};
1497 
1498 double aEmax[9][10]={{0.600,0.500,0.350,0.300,0.000,0.000,0.000,0.000,0.000,0.000},
1499  {1.200,1.100,1.000,0.900,0.700,0.000,0.000,0.000,0.000,0.000},
1500  {2.500,2.200,1.900,1.800,1.400,1.200,0.000,0.000,0.000,0.000},
1501  {3.300,3.100,3.000,2.700,2.400,2.000,0.000,0.000,0.000,0.000},
1502  {5.600,5.500,5.200,4.800,4.300,3.900,2.900,0.000,0.000,0.000},
1503  {9.000,8.800,8.300,7.600,7.200,6.400,5.200,0.000,0.000,0.000},
1504  {13.50,13.00,12.50,11.70,11.10,11.00,8.300,0.000,0.000,0.000},
1505  {22.20,22.80,21.50,20.50,19.00,16.30,15.50,13.50,0.000,0.000},
1506  {44.00,43.50,42.50,41.50,39.20,37.50,33.50,0.000,0.000,0.000}};
1507 
1508  for(unsigned int ibl=0;ibl<10;ibl++)
1509  {
1510  for(unsigned int ibk=0;ibk<9;ibk++)
1511  {
1512  if( aEmin[ibk][ibl]!=0.0 && aEmax[ibk][ibl]!=0.0)
1513  {
1514  CoreCalib2 cck;
1515  cck.level=ibl;
1516  cck.Enom=aEnom[ibk];
1517  cck.a=aa[ibk][ibl];
1518  cck.b=bb[ibk][ibl];
1519  cck.Emin=aEmin[ibk][ibl];
1520  cck.Emax=aEmax[ibk][ibl];
1521 
1522  cc->push_back(cck);
1523  }
1524  }
1525  }
1526 
1527 }
double Tsam
Definition: KITutil.h:221
Photon2(double Ein, double *pravac, double *pocetak)
Constructor.
Definition: KITutil.cc:1319
void Prob(CalorimeterHit *ch, double cut, double *out)
Definition: KITutil.cc:1361
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
vector< Superhit2 * > hits
hit in the cluster
Definition: KITutil.h:151
double Eceff
Definition: KITutil.h:217
double alfahom
Definition: KITutil.h:223
unsigned int MinHitSplit
minimal number of hits in i-th level cluster to be accepted for splitting of the core ...
Definition: KITutil.h:309
void findInertia()
calculates eigenvalues and eigenvectors of inertia tensor
Definition: KITutil.cc:947
double Ee
Definition: KITutil.h:227
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
~Tmpcl2()
Destructor.
Definition: KITutil.cc:914
void PointOnLine22(const double *Xstart, const double *dir, const float *X0, double *Xline)
Definition: KITutil.cc:1434
double start[3]
Definition: KITutil.h:229
void ModuleNormal2(double *X1, double &zmax, double *X0)
Definition: KITutil.cc:1229
double k2
Definition: KITutil.h:206
unsigned int MinHit0
minimal number of hits needed for 0-th level cluster to be accepted as a core candidate ...
Definition: KITutil.h:305
double alfasam
Definition: KITutil.h:224
void ClusterInCluster2(Tmpcl2 *cl, vector< Tmpcl2 * > &clv)
Definition: KITutil.cc:1199
float mipE
MIP value [GeV].
Definition: KITutil.h:80
~Superhit2()
Destructor.
Definition: KITutil.cc:884
int top
Number of neighbours.
Definition: KITutil.h:84
double direction[3]
principal axes of inertia tensor , calculated in calcInertia
Definition: KITutil.h:171
vector< Tmpcl2 * > Tmpclvec2
Definition: KITutil.h:232
double dir[3]
Definition: KITutil.h:228
double k1
Definition: KITutil.h:205
~Photon2()
Destructor.
Definition: KITutil.cc:1317
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 sampling
Definition: KITutil.h:216
double z2
Definition: KITutil.h:204
float mip
Energy of hit i terms of MIP.
Definition: KITutil.h:76
double Distcut
distance cut for core merging
Definition: KITutil.h:297
CalorimeterHit * chit
Pointer to the LCIO calorimeter hit.
Definition: KITutil.h:62
double z1
Definition: KITutil.h:203
double y
Definition: KITutil.h:212
float point[3]
Transformed position of the hit.
Definition: KITutil.h:68
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
double * getCenter()
returnes double[3] for the center as calculated with calcCenter method
Definition: KITutil.cc:905
double p3
Definition: KITutil.h:211
double center[3]
position of cluster center (x,y,z)
Definition: KITutil.h:167
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
bool is_assigned
Is hit assigned to a cluster or not.
Definition: KITutil.h:88
double inteigenvec[9]
eigenvectors of inertia tensor
Definition: KITutil.h:179
int level
level of cluster
Definition: KITutil.h:241
float pointt[3]
Real coordinate of the hit, copy of calorimeter hit data for direct access.
Definition: KITutil.h:72
double Emax
upper validity range of energy estimation funciton in GeV
Definition: KITutil.h:261
int S
stove as coded by Mokka
Definition: KITutil.h:100
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 getEnergy()
returnes energy of cluster in GeV.
Definition: KITutil.cc:916
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
double Thom
Definition: KITutil.h:220
static const float e
static const float K
double Z
Definition: KITutil.h:214
double Enom
nominal i.e.
Definition: KITutil.h:245
double p2
Definition: KITutil.h:210
bool connect
Definition: KITutil.h:64
double a
Eestimate = a+b*Ecore , a parameter of this funcition.
Definition: KITutil.h:249
vector< Superhit2 * > Shitvec2
Definition: KITutil.h:231
double k4
Definition: KITutil.h:208
Superhit2(const Superhit2 &)=delete
double Fs
Definition: KITutil.h:219
int M
module as coded by Mokka
Definition: KITutil.h:108
double betasam
Definition: KITutil.h:225
double k3
Definition: KITutil.h:207
void calcCenter()
Calculates center of inerta for the objects in hits vector.
Definition: KITutil.cc:925
void LineCaloIntersect2(double *X1, double *X2, double &d, double &zmax, double *X)
Definition: KITutil.cc:1033
Tmpcl2()
Constructor.
Definition: KITutil.cc:911
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 p1
Definition: KITutil.h:209
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
double X[3]
center of the candidate
Definition: KITutil.h:279
int level
level of the cluster
Definition: KITutil.h:275
vector< Tmpcl2 * > daughters
pointers to clusters that are contained in this cluster
Definition: KITutil.h:155
double energy
energy in GeV (sum over hits in cluster)
Definition: KITutil.h:163
Tmpcl2 * cl
pointer to the cluster
Definition: KITutil.h:271
int K
layer as coded by Mokka
Definition: KITutil.h:104
double inteigen[3]
normalized eigenvalues of inertia tensor
Definition: KITutil.h:175
double x0eff
Definition: KITutil.h:215
vector< Superhit2 * > neighbours
Vector of pointers to the neighbouring hits of Superhit2 type.
Definition: KITutil.h:92
Basic hit class for reconstruction, contains the calorimeter hit plus additional parameters.
Definition: KITutil.h:40
Tmpcl2 * cl
Pointer to the cluster to wich hit belong.
Definition: KITutil.h:96
int tip
0 by constructor 1 for ecal 2 for hcal
Definition: KITutil.h:112
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
double Rm
Definition: KITutil.h:218
bool active
flag to activate deactivate
Definition: KITutil.h:283
double eprime
Definition: KITutil.h:213
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