]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EMCAL/AliEMCALTracker.cxx
An effective FD corretion
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALTracker.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 //                       
16 //                       Class AliEMCALTracker 
17 //                      -----------------------
18 // Implementation of the track matching method between barrel tracks and
19 // EMCAL clusters.
20 // Besides algorithm implementation, some cuts are required to be set
21 // in order to define, for each track, an acceptance window where clusters
22 // are searched to find best match (if any).
23 // The class accepts as input an ESD container, and works directly on it,
24 // simply setting, for each of its tracks, the fEMCALindex flag, for each
25 // track which is matched to a cluster.
26 // In order to use method, one must launch PropagateBack().
27 //
28 // ------------------------------------------------------------------------
29 // author: A. Pulvirenti (alberto.pulvirenti@ct.infn.it)
30 // Revised by Rongrong 2010-05-31 (rongrong.ma@cern.ch)
31 //=========================================================================
32
33 #include <Riostream.h>
34 #include <iomanip>
35
36 #include <TFile.h>
37 #include <TTree.h>
38 #include <TList.h>
39 #include <TString.h>
40 #include <TVector3.h>
41 #include <TClonesArray.h>
42 #include <TGeoMatrix.h>
43
44 #include "AliLog.h"
45 #include "AliESDEvent.h"
46 #include "AliESDtrack.h"
47 #include "AliESDCaloCluster.h"
48 #include "AliEMCALRecPoint.h"
49 #include "AliRunLoader.h"
50 #include "AliEMCALTrack.h"
51 #include "AliEMCALLoader.h"
52 #include "AliEMCALGeometry.h"
53 #include "AliEMCALReconstructor.h"
54 #include "AliEMCALRecParam.h"
55 #include "AliCDBEntry.h"
56 #include "AliCDBManager.h"
57 #include "AliEMCALReconstructor.h"
58 #include "AliEMCALRecoUtils.h"
59
60 #include "AliEMCALTracker.h"
61
62 using std::cerr;
63 using std::endl;
64 ClassImp(AliEMCALTracker)
65
66 //
67 //------------------------------------------------------------------------------
68 //
69 AliEMCALTracker::AliEMCALTracker() 
70 : AliTracker(),
71   fCutPt(0),
72   fCutNITS(0),
73   fCutNTPC(50),
74   fStep(20),
75   fTrackCorrMode(kTrackCorrMMB),
76   fClusterWindow(50),
77   fCutEta(0.025),
78   fCutPhi(0.05),
79   fITSTrackSA(kFALSE),
80   fTracks(0),
81   fClusters(0),
82   fGeom(0)
83 {
84   //
85   // Default constructor.
86   // Initializes all simple data members to default values,
87    // and all collections to NULL.
88   // Output file name is set to a default value.
89   //
90   InitParameters();
91 }
92 //
93 //------------------------------------------------------------------------------
94 //
95 AliEMCALTracker::AliEMCALTracker(const AliEMCALTracker& copy) 
96   : AliTracker(),
97     fCutPt(copy.fCutPt),
98     fCutNITS(copy.fCutNITS),
99     fCutNTPC(copy.fCutNTPC),
100     fStep(copy.fStep),
101     fTrackCorrMode(copy.fTrackCorrMode),
102     fClusterWindow(copy.fClusterWindow),
103     fCutEta(copy.fCutEta),
104     fCutPhi(copy.fCutPhi),
105     fITSTrackSA(copy.fITSTrackSA), 
106     fTracks((TObjArray*)copy.fTracks->Clone()),
107     fClusters((TObjArray*)copy.fClusters->Clone()),
108     fGeom(copy.fGeom)
109 {
110   //
111   // Copy constructor
112   // Besides copying all parameters, duplicates all collections.
113   //
114 }
115 //
116 //------------------------------------------------------------------------------
117 //
118 AliEMCALTracker& AliEMCALTracker::operator=(const AliEMCALTracker& source)
119 { // assignment operator; use copy ctor
120   if (&source == this) return *this;
121
122   new (this) AliEMCALTracker(source);
123   return *this;
124 }
125 //
126 //------------------------------------------------------------------------------
127 //
128 void AliEMCALTracker::InitParameters()
129 {
130   //
131   // Retrieve initialization parameters
132   //
133         
134   // Check if the instance of AliEMCALRecParam exists, 
135   const AliEMCALRecParam* recParam = AliEMCALReconstructor::GetRecParam();
136
137   if(!recParam){
138     AliFatal("Reconstruction parameters for EMCAL not set!");
139   }
140   else{
141  
142     fCutEta  =  recParam->GetMthCutEta();
143     fCutPhi  =  recParam->GetMthCutPhi();
144     fStep    =  recParam->GetExtrapolateStep();
145     fCutPt   =  recParam->GetTrkCutPt();
146     fCutNITS =  recParam->GetTrkCutNITS();
147     fCutNTPC =  recParam->GetTrkCutNTPC();
148   }
149         
150 }
151
152 //
153 //------------------------------------------------------------------------------
154 //
155 void AliEMCALTracker::Clear(Option_t* option)
156 {
157         //
158         // Clearing method
159         // Deletes all objects in arrays and the arrays themselves
160         //
161
162         TString opt(option);
163         Bool_t clearTracks = opt.Contains("TRACKS");
164         Bool_t clearClusters = opt.Contains("CLUSTERS");
165         if (opt.Contains("ALL")) {
166                 clearTracks = kTRUE;
167                 clearClusters = kTRUE;
168         }
169         
170         //fTracks is a collection of esdTrack
171         //When clearing this array, the linked objects should not be deleted
172         if (fTracks != 0x0 && clearTracks) {
173            fTracks->Clear();
174            delete fTracks;
175            fTracks = 0;
176         }
177         if (fClusters != 0x0 && clearClusters) {
178            fClusters->Delete();
179            delete fClusters;
180            fClusters = 0;
181         }
182 }
183 //
184 //------------------------------------------------------------------------------
185 //
186 Int_t AliEMCALTracker::LoadClusters(TTree *cTree) 
187 {
188         //
189         // Load EMCAL clusters in the form of AliEMCALRecPoint,
190         // from simulation temporary files.
191         // (When included in reconstruction chain, this method is used automatically)
192         //
193         
194         Clear("CLUSTERS");
195
196         cTree->SetBranchStatus("*",0); //disable all branches
197         cTree->SetBranchStatus("EMCALECARP",1); //Enable only the branch we need
198
199         TBranch *branch = cTree->GetBranch("EMCALECARP");
200         if (!branch) {
201                 AliError("Can't get the branch with the EMCAL clusters");
202                 return 1;
203         }
204         
205         TClonesArray *clusters = new TClonesArray("AliEMCALRecPoint", 1000);
206         branch->SetAddress(&clusters);
207         
208         //cTree->GetEvent(0);
209         branch->GetEntry(0);
210         Int_t nClusters = (Int_t)clusters->GetEntries();
211         if(fClusters) fClusters->Delete();
212         else fClusters = new TObjArray(0);
213         for (Int_t i = 0; i < nClusters; i++) {
214                 AliEMCALRecPoint *cluster = (AliEMCALRecPoint*)clusters->At(i);
215                 if (!cluster) continue;
216                 AliEMCALMatchCluster *matchCluster = new AliEMCALMatchCluster(i, cluster);
217                 fClusters->AddLast(matchCluster);
218         }
219
220         branch->SetAddress(0);
221         clusters->Delete();
222         delete clusters;
223
224         AliInfo(Form("Collected %d RecPoints from Tree", fClusters->GetEntries()));
225
226         return 0;
227 }
228 //
229 //------------------------------------------------------------------------------
230 //
231 Int_t AliEMCALTracker::LoadClusters(AliESDEvent *esd) 
232 {
233   //
234   // Load EMCAL clusters in the form of AliESDCaloClusters,
235   // from an AliESD object.
236   //
237   
238   // make sure that tracks/clusters collections are empty
239   Clear("CLUSTERS");
240   fClusters = new TObjArray(0);
241   
242   Int_t nClusters = esd->GetNumberOfCaloClusters();                     
243   for (Int_t i=0; i<nClusters; i++) 
244     {
245       AliESDCaloCluster *cluster = esd->GetCaloCluster(i);
246       if (!cluster || !cluster->IsEMCAL()) continue ; 
247       AliEMCALMatchCluster *matchCluster = new AliEMCALMatchCluster(i, cluster);
248       fClusters->AddLast(matchCluster);
249     }
250   
251   AliInfo(Form("Collected %d clusters from ESD", fClusters->GetEntries()));
252   return 0;
253 }
254 //
255 //------------------------------------------------------------------------------
256 //
257 Int_t AliEMCALTracker::LoadTracks(AliESDEvent *esd)
258 {
259   //
260   // Load ESD tracks.
261   //
262
263   UInt_t mask1 = esd->GetESDRun()->GetDetectorsInDAQ();
264   UInt_t mask2 = esd->GetESDRun()->GetDetectorsInReco();
265   Bool_t desc1 = (mask1 >> 3) & 0x1;
266   Bool_t desc2 = (mask2 >> 3) & 0x1;
267   if (desc1==0 || desc2==0) {
268     AliError(Form("TPC not in DAQ/RECO: %u (%u)/%u (%u)",
269                   mask1, esd->GetESDRun()->GetDetectorsInReco(),
270                   mask2, esd->GetESDRun()->GetDetectorsInDAQ()));
271     fITSTrackSA = kTRUE;
272   }
273   
274   Clear("TRACKS");
275   fTracks = new TObjArray(0);
276         
277   Int_t nTracks = esd->GetNumberOfTracks();
278   //Bool_t isKink=kFALSE;
279   for (Int_t i = 0; i < nTracks; i++) 
280     {
281       AliESDtrack *esdTrack = esd->GetTrack(i);
282       // set by default the value corresponding to "no match"
283       esdTrack->SetEMCALcluster(kUnmatched);
284       esdTrack->ResetStatus(AliESDtrack::kEMCALmatch);
285
286       //Select good quaulity tracks
287       if(esdTrack->Pt()<fCutPt) continue;
288       if(!fITSTrackSA)
289         if(esdTrack->GetNcls(1)<fCutNTPC)continue;
290
291       //Loose geometric cut
292       Double_t phi = esdTrack->Phi()*TMath::RadToDeg();
293       if(TMath::Abs(esdTrack->Eta())>0.8 || phi <= 20 || phi >= 240 ) continue;
294
295       fTracks->AddLast(esdTrack);
296     }
297
298       AliInfo(Form("Collected %d tracks", fTracks->GetEntries()));
299       return 0;
300 }
301 //
302 //------------------------------------------------------------------------------
303 //
304 void AliEMCALTracker::SetTrackCorrectionMode(Option_t *option)
305 {
306   //
307   // Set track correction mode
308   // gest the choice in string format and converts into 
309   // internal enum
310   //
311   
312   TString opt(option);
313   opt.ToUpper();
314   
315   if (!opt.CompareTo("NONE")) 
316     {
317       fTrackCorrMode = kTrackCorrNone;
318     }
319   else if (!opt.CompareTo("MMB")) 
320     {
321       fTrackCorrMode = kTrackCorrMMB;
322     }
323   else 
324     {
325       cerr << "E-AliEMCALTracker::SetTrackCorrectionMode '" << option << "': Unrecognized option" << endl;
326     }
327 }
328 //
329 //------------------------------------------------------------------------------
330 //
331 Int_t AliEMCALTracker::PropagateBack(AliESDEvent* esd)
332 {
333         //
334         // Main operation method.
335         // Gets external AliESD containing tracks to be matched.
336         // After executing match finding, stores in the same ESD object all infos
337         // and releases the object for further reconstruction steps.
338         //
339         //
340         // Note: should always return 0=OK, because otherwise all tracking
341         // is aborted for this event
342   
343         if (!esd) {
344                 AliError("NULL ESD passed");
345                 return 1;
346         }
347         
348         // step 1: collect clusters
349         Int_t okLoadClusters, nClusters;
350         if (!fClusters || (fClusters && fClusters->IsEmpty())) {
351                 okLoadClusters = LoadClusters(esd);
352         }
353         nClusters = fClusters->GetEntries();
354                 
355         // step 2: collect ESD tracks
356         Int_t nTracks, okLoadTracks;
357         okLoadTracks = LoadTracks(esd);
358         nTracks = fTracks->GetEntries();
359         
360         // step 3: for each track, find the closest cluster as matched within residual cuts
361         Int_t index=-1;
362         for (Int_t it = 0; it < nTracks; it++) 
363           {
364             AliESDtrack *track = (AliESDtrack*)fTracks->At(it);
365             index = FindMatchedCluster(track);
366             if (index>-1) 
367               {
368                 AliEMCALMatchCluster *cluster = (AliEMCALMatchCluster*)fClusters->At(index);
369                 track->SetEMCALcluster(cluster->Index());
370                 track->SetStatus(AliESDtrack::kEMCALmatch);
371               }
372           }
373
374         return 0;
375 }
376
377 //
378 //------------------------------------------------------------------------------
379 //
380 Int_t AliEMCALTracker::FindMatchedCluster(AliESDtrack *track)
381 {         
382   //
383   // For each track, extrapolate it to all the clusters
384   // Find the closest one as matched if the residuals (dEta, dPhi) satisfy the cuts
385   //
386
387   Float_t maxEta=fCutEta;
388   Float_t maxPhi=fCutPhi;
389   Int_t index = -1;
390   
391   // If the esdFriend is available, use the TPCOuter point as the starting point of extrapolation
392   // Otherwise use the TPCInner point
393   AliExternalTrackParam *trkParam = 0;
394   
395   if(!fITSTrackSA){ 
396     const AliESDfriendTrack*  friendTrack = track->GetFriendTrack();
397     if(friendTrack && friendTrack->GetTPCOut())
398       trkParam = const_cast<AliExternalTrackParam*>(friendTrack->GetTPCOut());
399     else if(track->GetInnerParam())
400       trkParam = const_cast<AliExternalTrackParam*>(track->GetInnerParam());
401   }
402   else
403     trkParam = new AliExternalTrackParam(*track);
404   
405   if(!trkParam) return index;
406   
407   AliExternalTrackParam trkParamTmp(*trkParam);
408   Float_t eta, phi;
409   if(!AliEMCALRecoUtils::ExtrapolateTrackToEMCalSurface(&trkParamTmp, 430., track->GetMass(kTRUE), fStep, eta, phi))  return index;
410   track->SetTrackPhiEtaOnEMCal(phi,eta);
411   if(TMath::Abs(eta)>0.75 || (phi) < 70*TMath::DegToRad() || (phi) > 190*TMath::DegToRad()) return index;
412
413   //Perform extrapolation
414   Double_t trkPos[3];
415   trkParamTmp.GetXYZ(trkPos);
416   Int_t nclusters = fClusters->GetEntries();
417   for(Int_t ic=0; ic<nclusters; ic++)
418     {
419       AliEMCALMatchCluster *cluster = (AliEMCALMatchCluster*)fClusters->At(ic);
420       Float_t clsPos[3] = {cluster->X(),cluster->Y(),cluster->Z()};
421       Double_t dR = TMath::Sqrt(TMath::Power(trkPos[0]-clsPos[0],2)+TMath::Power(trkPos[1]-clsPos[1],2)+TMath::Power(trkPos[2]-clsPos[2],2));
422 //       printf("\n dR=%f,wind=%f\n",dR,fClusterWindow); //MARCEL
423       if(dR > fClusterWindow) continue;
424       
425       AliExternalTrackParam trkParTmp(trkParamTmp);
426
427       Float_t tmpEta, tmpPhi;
428       if(!AliEMCALRecoUtils::ExtrapolateTrackToPosition(&trkParTmp, clsPos,track->GetMass(kTRUE), 5, tmpEta, tmpPhi)) continue;
429       if(TMath::Abs(tmpPhi)<TMath::Abs(maxPhi) && TMath::Abs(tmpEta)<TMath::Abs(maxEta))
430         {
431           maxPhi=tmpPhi;
432           maxEta=tmpEta;
433           index=ic;
434         }
435       }
436   return index;
437 }
438
439 //
440 //------------------------------------------------------------------------------
441 //
442 void AliEMCALTracker::UnloadClusters() 
443 {
444         //
445         // Free memory from all arrays
446         // This method is called after the local tracking step
447         // so we can safely delete everything 
448         //
449         
450         Clear();
451 }
452
453 //
454 //------------------------------------------------------------------------------
455 //
456 AliEMCALTracker::AliEMCALMatchCluster::AliEMCALMatchCluster(Int_t index, AliEMCALRecPoint *recPoint)
457   : fIndex(index),
458     fX(0.),
459     fY(0.),
460     fZ(0.)
461 {
462         //
463         // Translates an AliEMCALRecPoint object into the internal format.
464         // Index of passed cluster in its native array must be specified.
465         //
466         TVector3 clpos;
467         recPoint->GetGlobalPosition(clpos);
468         
469         fX = clpos.X();
470         fY = clpos.Y();
471         fZ = clpos.Z();
472 }
473 //
474 //------------------------------------------------------------------------------
475 //
476 AliEMCALTracker::AliEMCALMatchCluster::AliEMCALMatchCluster(Int_t index, AliESDCaloCluster *caloCluster)
477   : fIndex(index),
478     fX(0.),
479     fY(0.),
480     fZ(0.)
481 {
482         //
483         // Translates an AliESDCaloCluster object into the internal format.
484         // Index of passed cluster in its native array must be specified.
485         //
486         Float_t clpos[3]= {0., 0., 0.};
487         caloCluster->GetPosition(clpos);
488         
489         fX = (Double_t)clpos[0];
490         fY = (Double_t)clpos[1];
491         fZ = (Double_t)clpos[2];
492 }