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