]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PHOS/AliPHOSTrackSegmentMakerv1.cxx
New class AliPHOSCpvPreprocessor.
[u/mrichter/AliRoot.git] / PHOS / AliPHOSTrackSegmentMakerv1.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15 /* $Id$ */
16
17 /* History of cvs commits:
18  *
19  * $Log$
20  * Revision 1.93  2007/10/10 09:05:10  schutz
21  * Changing name QualAss to QA
22  *
23  * Revision 1.92  2007/08/28 12:55:08  policheh
24  * Loaders removed from the reconstruction code (C.Cheshkov)
25  *
26  * Revision 1.91  2007/08/07 14:12:03  kharlov
27  * Quality assurance added (Yves Schutz)
28  *
29  * Revision 1.90  2007/07/11 13:43:30  hristov
30  * New class AliESDEvent, backward compatibility with the old AliESD (Christian)
31  *
32  * Revision 1.89  2007/07/03 08:13:04  kharlov
33  * Bug fix in CPV local coordinates
34  *
35  * Revision 1.88  2007/06/27 09:11:07  kharlov
36  * Bug fix for CPV-EMC distance
37  *
38  * Revision 1.87  2007/05/04 14:49:29  policheh
39  * AliPHOSRecPoint inheritance from AliCluster
40  *
41  * Revision 1.86  2007/04/02 15:00:16  cvetan
42  * No more calls to gAlice in the reconstruction
43  *
44  * Revision 1.85  2007/03/28 19:18:15  kharlov
45  * RecPoints recalculation in TSM removed
46  *
47  * Revision 1.84  2007/03/07 07:01:21  hristov
48  * Fixing copy/paste erro. Additional protections
49  *
50  * Revision 1.83  2007/03/06 21:07:37  kharlov
51  * DP: xz CPV-EMC distance filled to TS
52  *
53  * Revision 1.82  2007/03/06 06:54:48  kharlov
54  * DP:Calculation of cluster properties dep. on vertex added
55  *
56  * Revision 1.81  2007/02/05 10:02:40  kharlov
57  * Module numbering is corrected
58  *
59  * Revision 1.80  2006/08/28 10:01:56  kharlov
60  * Effective C++ warnings fixed (Timur Pocheptsov)
61  *
62  * Revision 1.79  2006/04/25 12:41:15  hristov
63  * Moving non-persistent data to AliESDfriend (Yu.Belikov)
64  *
65  * Revision 1.78  2005/11/18 13:04:51  hristov
66  * Bug fix
67  *
68  * Revision 1.77  2005/11/17 23:34:36  hristov
69  * Corrected logics
70  *
71  * Revision 1.76  2005/11/17 22:29:12  hristov
72  * Faster version, no attempt to match tracks outside the PHOS acceptance
73  *
74  * Revision 1.75  2005/11/17 12:35:27  hristov
75  * Use references instead of objects. Avoid to create objects when they are not really needed
76  *
77  * Revision 1.74  2005/07/08 14:01:36  hristov
78  * Tracking in non-uniform nmagnetic field (Yu.Belikov)
79  *
80  * Revision 1.73  2005/05/28 14:19:05  schutz
81  * Compilation warnings fixed by T.P.
82  *
83  */
84
85 //_________________________________________________________________________
86 // Implementation version 1 of algorithm class to construct PHOS track segments
87 // Track segment for PHOS is list of 
88 //        EMC RecPoint + (possibly) CPV RecPoint
89 // To find TrackSegments we do the following: 
90 //  for each EMC RecPoints we look at
91 //   CPV RecPoints in the radious fRcpv. 
92 //  If there is such a CPV RecPoint, 
93 //   we make "Link" it is just indexes of EMC and CPV RecPoint and distance
94 //   between them in the PHOS plane. 
95 //  Then we sort "Links" and starting from the 
96 //   least "Link" pointing to the unassined EMC and CPV RecPoints assing them to 
97 //   new TrackSegment. 
98 // If there is no CPV RecPoint we make TrackSegment 
99 // consisting from EMC alone. There is no TrackSegments without EMC RecPoint.
100 //// In principle this class should be called from AliPHOSReconstructor, but 
101 // one can use it as well in standalone mode.
102 // Use  case:
103 //  root [0] AliPHOSTrackSegmentMakerv1 * t = new AliPHOSTrackSegmentMaker("galice.root", "tracksegmentsname", "recpointsname")
104 //  Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated
105 //               // reads gAlice from header file "galice.root", uses recpoints stored in the branch names "recpointsname" (default = "Default")
106 //               // and saves recpoints in branch named "tracksegmentsname" (default = "recpointsname")                       
107 //  root [1] t->ExecuteTask()
108 //  root [3] t->SetTrackSegmentsBranch("max distance 5 cm")
109 //  root [4] t->ExecuteTask("deb all time") 
110 //                 
111 //*-- Author: Dmitri Peressounko (RRC Ki & SUBATECH) & Yves Schutz (SUBATECH) 
112 //
113
114 // --- ROOT system ---
115 #include "TTree.h"
116 #include "TBenchmark.h"
117
118 // --- Standard library ---
119 #include "Riostream.h"
120 // --- AliRoot header files ---
121 #include "AliPHOSGeometry.h"
122 #include "AliPHOSTrackSegmentMakerv1.h"
123 #include "AliPHOSTrackSegment.h"
124 #include "AliPHOSLink.h"
125 #include "AliESDEvent.h"
126 #include "AliESDtrack.h"
127 #include "AliPHOSEmcRecPoint.h"
128 #include "AliPHOSCpvRecPoint.h"
129
130 ClassImp( AliPHOSTrackSegmentMakerv1) 
131
132
133 //____________________________________________________________________________
134 AliPHOSTrackSegmentMakerv1::AliPHOSTrackSegmentMakerv1() :
135   AliPHOSTrackSegmentMaker(),
136   fDefaultInit(kTRUE),
137   fWrite(kFALSE),
138   fNTrackSegments(0),
139   fRcpv(0.f),
140   fRtpc(0.f),
141   fVtx(0.f), 
142   fLinkUpArray(0),
143   fEmcFirst(0),
144   fEmcLast(0),
145   fCpvFirst(0),
146   fCpvLast(0),
147   fModule(0),
148   fTrackSegments(NULL)
149 {
150   // default ctor (to be used mainly by Streamer)
151   InitParameters() ; 
152 }
153
154 //____________________________________________________________________________
155 AliPHOSTrackSegmentMakerv1::AliPHOSTrackSegmentMakerv1(AliPHOSGeometry *geom) :
156   AliPHOSTrackSegmentMaker(geom),
157   fDefaultInit(kFALSE),
158   fWrite(kFALSE),
159   fNTrackSegments(0),
160   fRcpv(0.f),
161   fRtpc(0.f),
162   fVtx(0.f), 
163   fLinkUpArray(0),
164   fEmcFirst(0),
165   fEmcLast(0),
166   fCpvFirst(0),
167   fCpvLast(0),
168   fModule(0),
169   fTrackSegments(NULL)
170 {
171   // ctor
172   InitParameters() ; 
173   Init() ;
174   fESD = 0;
175 }
176
177
178 AliPHOSTrackSegmentMakerv1::AliPHOSTrackSegmentMakerv1(const AliPHOSTrackSegmentMakerv1 & tsm) :
179   AliPHOSTrackSegmentMaker(tsm),
180   fDefaultInit(kFALSE),
181   fWrite(kFALSE),
182   fNTrackSegments(0),
183   fRcpv(0.f),
184   fRtpc(0.f),
185   fVtx(0.f), 
186   fLinkUpArray(0),
187   fEmcFirst(0),
188   fEmcLast(0),
189   fCpvFirst(0),
190   fCpvLast(0),
191   fModule(0),
192   fTrackSegments(NULL)
193 {
194   // cpy ctor: no implementation yet
195   // requested by the Coding Convention
196   Fatal("cpy ctor", "not implemented") ;
197 }
198
199
200 //____________________________________________________________________________
201  AliPHOSTrackSegmentMakerv1::~AliPHOSTrackSegmentMakerv1()
202
203   // dtor
204   // fDefaultInit = kTRUE if TrackSegmentMaker created by default ctor (to get just the parameters)
205   if (!fDefaultInit)  
206     delete fLinkUpArray ;
207   if (fTrackSegments) {
208     fTrackSegments->Delete();
209     delete fTrackSegments;
210   }
211 }
212
213 //____________________________________________________________________________
214 void  AliPHOSTrackSegmentMakerv1::FillOneModule()
215 {
216   // Finds first and last indexes between which 
217   // clusters from one PHOS module are
218
219   //First EMC clusters
220   Int_t totalEmc = fEMCRecPoints->GetEntriesFast() ;
221   for(fEmcFirst = fEmcLast; (fEmcLast < totalEmc) &&  
222         ((dynamic_cast<AliPHOSRecPoint *>(fEMCRecPoints->At(fEmcLast)))->GetPHOSMod() == fModule ); 
223       fEmcLast ++)  ;
224   
225   //Now CPV clusters
226   Int_t totalCpv = fCPVRecPoints->GetEntriesFast() ;
227
228     for(fCpvFirst = fCpvLast; (fCpvLast < totalCpv) && 
229          ((dynamic_cast<AliPHOSRecPoint *>(fCPVRecPoints->At(fCpvLast)))->GetPHOSMod() == fModule ); 
230        fCpvLast ++) ;
231       
232 }
233
234 //____________________________________________________________________________
235 void  AliPHOSTrackSegmentMakerv1::GetDistanceInPHOSPlane(AliPHOSEmcRecPoint * emcClu,
236                                                          AliPHOSCpvRecPoint * cpvClu, 
237                                                          Int_t &trackindex, 
238                                                          Float_t &dx, Float_t &dz) const
239 {
240   // Calculates the distance between the EMC RecPoint and the CPV RecPoint
241   // Clusters are sorted in "rows" and "columns" of width 1 cm
242
243 //  Float_t delta = 1 ;  // Width of the rows in sorting of RecPoints (in cm)
244 //                       // if you change this value, change it as well in xxxRecPoint::Compare()
245   Float_t distance2Track = fRtpc ; 
246
247   trackindex = -1 ; // closest track within fRCpv 
248
249   TVector3 vecEmc ;   // Local position of EMC recpoint
250   TVector3 vecP ;     // Momentum direction at CPV plain
251   TVector3 vecPloc ;     // Momentum direction at CPV plain
252   
253   //toofar = kTRUE ;
254   if(emcClu->GetPHOSMod() != cpvClu->GetPHOSMod()){
255     dx=999. ;
256     dz=999. ;
257     return ;
258   }
259
260   emcClu->GetLocalPosition(vecEmc) ;
261
262   Double_t xCPV,zCPV ; //EMC-projected coordinates of CPV cluster 
263   TVector3 cpvGlobal; // Global position of the CPV recpoint
264   fGeom->GetGlobalPHOS((AliPHOSRecPoint*)cpvClu,cpvGlobal);
265   Double_t vtxCPV[3]={cpvGlobal.X(),cpvGlobal.Y(),cpvGlobal.Z()} ;
266   Int_t dummyMod ;
267
268   if (fESD == 0x0) {
269      //if no track information available, assume straight line from IP to emcal
270      fGeom->ImpactOnEmc(vtxCPV,cpvGlobal.Theta(),cpvGlobal.Phi(),dummyMod,zCPV,xCPV) ;
271      dx=xCPV - vecEmc.X() ;
272      dz=zCPV - vecEmc.Z() ;
273      return ;
274   } 
275
276   //if there is ESD try to correct distance using TPC information on particle direct in CPV 
277   if (fESD != 0x0) {
278
279     Double_t rCPV = cpvGlobal.Pt() ;// Radius from IP to current point 
280
281     // Extrapolate the global track direction if any to CPV and find the closest track
282     Int_t nTracks = fESD->GetNumberOfTracks();
283     Int_t iClosestTrack = -1;
284     Double_t minDistance = 1.e6;
285     TVector3 inPHOS ; 
286
287     AliESDtrack *track;
288     Double_t xyz[3] ;
289     Double_t pxyz[3]; 
290     for (Int_t iTrack=0; iTrack<nTracks; iTrack++) {
291       track = fESD->GetTrack(iTrack);
292       if (!track->GetXYZAt(rCPV, fESD->GetMagneticField(), xyz))
293            continue; //track coord on the cylinder of PHOS radius
294       if ((TMath::Abs(xyz[0])+TMath::Abs(xyz[1])+TMath::Abs(xyz[2]))<=0)
295            continue;
296       //Check if this track hits PHOS
297       inPHOS.SetXYZ(xyz[0],xyz[1],xyz[2]);
298       distance2Track = inPHOS.Angle(cpvGlobal) ;
299       // Find the closest track to the CPV recpoint
300       if (distance2Track < minDistance) {
301          minDistance = distance2Track;
302          iClosestTrack = iTrack;
303       }
304     }
305
306     if (iClosestTrack != -1) {
307       track = fESD->GetTrack(iClosestTrack);
308       if (track->GetPxPyPzAt(rCPV, fESD->GetMagneticField(), pxyz)) { // track momentum ibid.
309         vecP.SetXYZ(pxyz[0],pxyz[1],pxyz[2]);
310         Int_t dummyMod ;
311         fGeom->ImpactOnEmc(vtxCPV,vecP.Theta(),vecP.Phi(),dummyMod,zCPV,xCPV) ;
312       }
313     }
314     
315     if(minDistance < fRtpc ){
316       trackindex = iClosestTrack ; 
317     }
318   }
319   if(trackindex!=-1){
320     // If the closest global track is found, calculate EMC-CPV distance from it
321     dx=xCPV - vecEmc.X() ;
322     dz=zCPV - vecEmc.Z() ;
323   }
324   else{
325     // If no global track was found, just take the nearest CPV point
326     fGeom->ImpactOnEmc(vtxCPV,cpvGlobal.Theta(),cpvGlobal.Phi(),dummyMod,zCPV,xCPV) ;
327     dx=xCPV - vecEmc.X() ;
328     dz=zCPV - vecEmc.Z() ;
329   }
330   return ;
331 }
332 //____________________________________________________________________________
333 void  AliPHOSTrackSegmentMakerv1::Init()
334 {
335   // Make all memory allocations that are not possible in default constructor
336   
337   fLinkUpArray  = new TClonesArray("AliPHOSLink", 1000); 
338   fTrackSegments = new TClonesArray("AliPHOSTrackSegment",100);
339   fTrackSegments->SetName("TRACKS");
340 }
341
342 //____________________________________________________________________________
343 void  AliPHOSTrackSegmentMakerv1::InitParameters()
344 {
345   //Initializes parameters
346   fRcpv      = 10. ;
347   fRtpc      = 4. ;
348   fEmcFirst  = 0 ;    
349   fEmcLast   = 0 ;   
350   fCpvFirst  = 0 ;   
351   fCpvLast   = 0 ;   
352   fLinkUpArray = 0 ;
353   fWrite                   = kTRUE ;
354 }
355
356
357 //____________________________________________________________________________
358 void  AliPHOSTrackSegmentMakerv1::MakeLinks()const
359
360   // Finds distances (links) between all EMC and CPV clusters, 
361   // which are not further apart from each other than fRcpv 
362   // and sort them in accordance with this distance
363   
364   fLinkUpArray->Clear() ;    
365
366   AliPHOSCpvRecPoint * cpv ;
367   AliPHOSEmcRecPoint * emcclu ;
368
369   Int_t iLinkUp  = 0 ;
370   
371   Int_t iEmcRP;
372   for(iEmcRP = fEmcFirst; iEmcRP < fEmcLast; iEmcRP++ ) {
373     emcclu = dynamic_cast<AliPHOSEmcRecPoint *>(fEMCRecPoints->At(iEmcRP)) ;
374
375     //Bool_t toofar ;        
376     Int_t iCpv = 0 ;    
377     for(iCpv = fCpvFirst; iCpv < fCpvLast;iCpv++ ) { 
378       
379       cpv = dynamic_cast<AliPHOSCpvRecPoint *>(fCPVRecPoints->At(iCpv)) ;
380       Int_t track = -1 ; 
381       Float_t dx,dz ;
382       GetDistanceInPHOSPlane(emcclu, cpv, track,dx,dz) ;     
383       if(TMath::Sqrt(dx*dx+dz*dz) < fRcpv ){ 
384         new ((*fLinkUpArray)[iLinkUp++])  AliPHOSLink(dx, dz, iEmcRP, iCpv, track) ;
385       }      
386     }
387   } 
388   
389   fLinkUpArray->Sort() ;  //first links with smallest distances
390 }
391
392 //____________________________________________________________________________
393 void  AliPHOSTrackSegmentMakerv1::MakePairs()
394
395   // Using the previously made list of "links", we found the smallest link - i.e. 
396   // link with the least distance between EMC and CPV and pointing to still 
397   // unassigned RecParticles. We assign these RecPoints to TrackSegment and 
398   // remove them from the list of "unassigned". 
399
400   //Make arrays to mark clusters already chosen
401   Int_t * emcExist = 0;
402   if(fEmcLast > fEmcFirst)
403     emcExist = new Int_t[fEmcLast-fEmcFirst] ;
404   
405   Int_t index;
406   for(index = 0; index <fEmcLast-fEmcFirst; index ++)
407     emcExist[index] = 1 ;
408   
409   Bool_t * cpvExist = 0;
410   if(fCpvLast > fCpvFirst)
411     cpvExist = new Bool_t[fCpvLast-fCpvFirst] ;
412   for(index = 0; index <fCpvLast-fCpvFirst; index ++)
413     cpvExist[index] = kTRUE ;
414   
415   
416   // Finds the smallest links and makes pairs of CPV and EMC clusters with smallest distance 
417   TIter nextUp(fLinkUpArray) ;
418   
419   AliPHOSLink * linkUp ;
420   
421   AliPHOSCpvRecPoint * nullpointer = 0 ;
422   
423   while ( (linkUp =  static_cast<AliPHOSLink *>(nextUp()) ) ){  
424
425     if(emcExist[linkUp->GetEmc()-fEmcFirst] != -1){
426
427       if(cpvExist[linkUp->GetCpv()-fCpvFirst]){ //CPV still exist
428          Float_t dx,dz ;
429          linkUp->GetXZ(dx,dz) ;
430          new ((* fTrackSegments)[fNTrackSegments]) 
431            AliPHOSTrackSegment(dynamic_cast<AliPHOSEmcRecPoint *>(fEMCRecPoints->At(linkUp->GetEmc())) , 
432                                dynamic_cast<AliPHOSCpvRecPoint *>(fCPVRecPoints->At(linkUp->GetCpv())) , 
433                                linkUp->GetTrack(),dx,dz) ;
434          
435        (dynamic_cast<AliPHOSTrackSegment *>(fTrackSegments->At(fNTrackSegments)))->SetIndexInList(fNTrackSegments);
436        fNTrackSegments++ ;
437        emcExist[linkUp->GetEmc()-fEmcFirst] = -1 ; //Mark emc  that Cpv was found 
438        //mark CPV recpoint as already used 
439        cpvExist[linkUp->GetCpv()-fCpvFirst] = kFALSE ;
440       } //if CpvUp still exist
441     } 
442   }        
443
444   //look through emc recPoints left without CPV
445   if(emcExist){ //if there is emc rec point
446     Int_t iEmcRP ;
447     for(iEmcRP = 0; iEmcRP < fEmcLast-fEmcFirst  ; iEmcRP++ ){
448       if(emcExist[iEmcRP] > 0 ){
449        new ((*fTrackSegments)[fNTrackSegments])  
450          AliPHOSTrackSegment(dynamic_cast<AliPHOSEmcRecPoint *>(fEMCRecPoints->At(iEmcRP+fEmcFirst)), 
451                            nullpointer) ;
452        (dynamic_cast<AliPHOSTrackSegment *>(fTrackSegments->At(fNTrackSegments)))->SetIndexInList(fNTrackSegments);
453        fNTrackSegments++;    
454       } 
455     }
456   }
457   delete [] emcExist ; 
458   delete [] cpvExist ; 
459 }
460
461 //____________________________________________________________________________
462 void AliPHOSTrackSegmentMakerv1::Clusters2TrackSegments(Option_t *option)
463 {
464   // Steering method to perform track segment construction for the current event
465   // Returns an array with the found track-segments.
466   
467   if(strstr(option,"tim"))
468     gBenchmark->Start("PHOSTSMaker");
469  
470   if(strstr(option,"print")) {
471     Print() ; 
472     return ; 
473   }
474   
475   //Make some initializations 
476   fNTrackSegments = 0 ;
477   fEmcFirst = 0 ;    
478   fEmcLast  = 0 ;   
479   fCpvFirst = 0 ;   
480   fCpvLast  = 0 ;   
481
482   fTrackSegments->Clear();
483
484   //   if(!ReadRecPoints(ievent))   continue; //reads RecPoints for event ievent
485     
486   for(fModule = 1; fModule <= fGeom->GetNModules() ; fModule++ ) {
487     FillOneModule() ; 
488     MakeLinks() ;
489     MakePairs() ;
490   }
491     
492   if(strstr(option,"deb"))
493     PrintTrackSegments(option);
494
495   if(strstr(option,"tim")){
496     gBenchmark->Stop("PHOSTSMaker");
497     Info("Exec", "took %f seconds for making TS", 
498          gBenchmark->GetCpuTime("PHOSTSMaker")); 
499   }
500 }
501
502 //____________________________________________________________________________
503 void AliPHOSTrackSegmentMakerv1::Print(const Option_t *)const
504 {
505   //  Print TrackSegmentMaker parameters
506
507   TString message("") ;
508   if( strcmp(GetName(), "") != 0 ) {
509     message = "\n======== AliPHOSTrackSegmentMakerv1 ========\n" ; 
510     message += "Making Track segments\n" ;
511     message += "with parameters:\n" ; 
512     message += "     Maximal EMC - CPV distance (cm) %f\n" ;
513     message += "============================================\n" ;
514     Info("Print", message.Data(),fRcpv) ;
515   }
516   else
517     Info("Print", "AliPHOSTrackSegmentMakerv1 not initialized ") ;
518 }
519
520 //____________________________________________________________________________
521 void AliPHOSTrackSegmentMakerv1::PrintTrackSegments(Option_t * option)
522 {
523   // option deb - prints # of found TrackSegments
524   // option deb all - prints as well indexed of found RecParticles assigned to the TS
525
526   Info("PrintTrackSegments", "Results from TrackSegmentMaker:") ; 
527   printf("        Found %d TrackSegments\n", fTrackSegments->GetEntriesFast() ); 
528   
529   if(strstr(option,"all")) {  // printing found TS
530     printf("TrackSegment #  EMC RP#  CPV RP#\n") ; 
531     Int_t index;
532     for (index = 0 ; index <fTrackSegments->GetEntriesFast() ; index++) {
533       AliPHOSTrackSegment * ts = (AliPHOSTrackSegment * )fTrackSegments->At(index) ; 
534       printf("   %d           %d        %d \n", ts->GetIndexInList(), ts->GetEmcIndex(), ts->GetCpvIndex() ) ; 
535     }   
536   }
537 }