1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
17 /* History of cvs commits:
20 * Revision 1.9 2007/10/10 09:05:10 schutz
21 * Changing name QualAss to QA
23 * Revision 1.8 2007/08/28 12:55:08 policheh
24 * Loaders removed from the reconstruction code (C.Cheshkov)
26 * Revision 1.7 2007/08/07 14:12:03 kharlov
27 * Quality assurance added (Yves Schutz)
29 * Revision 1.6 2007/08/03 14:41:37 cvetan
30 * Missing header files
32 * Revision 1.5 2007/08/03 13:52:16 kharlov
33 * Working skeleton of matching the ESD tracks and ESD clusters (Iouri Belikov)
37 #include <TClonesArray.h>
41 #include "AliPHOSTracker.h"
42 #include "AliPHOSEmcRecPoint.h"
43 #include "AliPHOSGeometry.h"
44 #include "AliESDEvent.h"
45 #include "AliESDtrack.h"
46 #include "AliPHOSTrackSegmentMakerv1.h"
47 #include "AliPHOSPIDv1.h"
49 //-------------------------------------------------------------------------
51 // Matches ESD tracks with the PHOS and makes the PID.
53 //-------------------------------------------------------------------------
55 ClassImp(AliPHOSTracker)
57 Bool_t AliPHOSTracker::fgDebug = kFALSE ;
59 //____________________________________________________________________________
60 AliPHOSTracker::AliPHOSTracker():
63 //--------------------------------------------------------------------
64 // The default constructor
65 //--------------------------------------------------------------------
66 for (Int_t i=0; i<5; i++)
67 fModules[i]=new TClonesArray("AliPHOSEmcRecPoint",777);
71 //____________________________________________________________________________
72 AliPHOSTracker::~AliPHOSTracker()
74 //--------------------------------------------------------------------
76 //--------------------------------------------------------------------
77 for (Int_t i=0; i<5; i++) {
78 (fModules[i])->Delete();
83 //____________________________________________________________________________
84 Int_t AliPHOSTracker::LoadClusters(TTree *cTree) {
85 //--------------------------------------------------------------------
86 // This function loads the PHOS clusters
87 //--------------------------------------------------------------------
90 TBranch *branch=cTree->GetBranch("PHOSEmcRP");
92 AliError("No branch with the EMC clusters found !");
95 branch->SetAddress(&arr);
97 for(Int_t m=0;m<5; m++) fModules[m]->Clear() ;
100 Int_t nentr=(Int_t)branch->GetEntries();
101 for (Int_t i=0; i<nentr; i++) {
102 if (!branch->GetEvent(i)) continue;
103 Int_t ncl=arr->GetEntriesFast();
105 AliPHOSEmcRecPoint *cl=(AliPHOSEmcRecPoint*)arr->UncheckedAt(ncl);
107 Int_t m=cl->GetPHOSMod();
109 AliError(Form("Wrong module index: %d !",m));
113 // Here is how the alignment is treated
114 // Misalignment is already in cluster coordinates
115 // if (!cl->Misalign()) AliWarning("Can't misalign this cluster !");
117 cl->SetBit(14,kFALSE); // The clusters are not yet attached to any track
119 TClonesArray &module=*fModules[m-1];
120 Int_t idx=module.GetEntriesFast();
121 new (module[idx]) AliPHOSEmcRecPoint(*cl);
128 Info("LoadClusters","Number of loaded clusters: %d",nclusters);
134 //____________________________________________________________________________
135 Int_t AliPHOSTracker::PropagateBack(AliESDEvent *esd) {
136 //--------------------------------------------------------------------
137 // Called by AliReconstruction
138 // Performs the track matching with the PHOS modules
140 //--------------------------------------------------------------------
142 Int_t nt=esd->GetNumberOfTracks();
144 // *** Select and sort the ESD track in accordance with their quality
145 Double_t *quality=new Double_t[nt];
146 Int_t *index=new Int_t[nt];
147 for (Int_t i=0; i<nt; i++) {
148 AliESDtrack *esdTrack=esd->GetTrack(i);
149 quality[i] = esdTrack->GetSigmaY2() + esdTrack->GetSigmaZ2();
151 TMath::Sort(nt,quality,index,kFALSE);
153 AliPHOSGeometry * geom = AliPHOSGeometry::GetInstance() ;
155 // *** Start the matching
156 TVector3 vecEmc ; // Local position of EMC recpoint
157 Double_t bz = GetBz() ; //For approximate matching
158 Double_t b[3]; //For final matching
159 Double_t gposTrack[3] ;
161 for (Int_t i=0; i<nt; i++) {
162 AliESDtrack *esdTrack=esd->GetTrack(index[i]);
164 // Skip the tracks having "wrong" status (has to be checked/tuned)
165 ULong_t status = esdTrack->GetStatus();
166 if ((status & AliESDtrack::kTPCout) == 0) continue;
167 // if ((status & AliESDtrack::kTRDout) == 0) continue;
168 // if ((status & AliESDtrack::kTRDrefit) == 1) continue;
170 //Continue extrapolation from TPC outer surface
171 const AliExternalTrackParam *outerParam=esdTrack->GetOuterParam();
172 if (!outerParam) continue;
173 AliExternalTrackParam t(*outerParam);
177 //Loop over PHOS modules
179 Double_t minDistance=999. ;
181 for(Int_t mod=1; mod<=5; mod++){
182 if(fModules[mod-1]->GetEntriesFast()==0) //no PHOS clusters in this module or module does not exist
185 //Approximate direction to the current PHOS module
186 Double_t phiMod=(330.-20.*mod)/180.*TMath::Pi() ;
187 if(!t.Rotate(phiMod))
190 geom->Local2Global(mod, 0.,0., globaPos) ;
191 const Double_t rPHOS = globaPos.Pt() ; //Distance to center of PHOS module
192 const Double_t kYmax = 72.+10. ; //Size of the module (with some reserve) in phi direction
193 const Double_t kZmax = 64.+20. ; //Size of the module (with some reserve) in z direction
195 Double_t y; // Some tracks do not reach the PHOS
196 if (!t.GetYAt(rPHOS,bz,y)) continue; // because of the bending
199 if(!t.GetZAt(rPHOS,bz,z))
201 if (TMath::Abs(z) > kZmax)
202 continue; // Some tracks miss the PHOS in Z
203 if(TMath::Abs(y) < kYmax){
204 t.PropagateToBxByBz(rPHOS,b); // Propagate to the matching module
205 //t.CorrectForMaterial(...); // Correct for the TOF material, if needed
206 t.GetXYZ(gposTrack) ;
207 TVector3 globalPositionTr(gposTrack) ;
208 TVector3 localPositionTr ;
209 geom->Global2Local(localPositionTr,globalPositionTr,mod) ;
210 for(Int_t icl=0;icl<fModules[mod-1]->GetEntriesFast();icl++){
211 AliPHOSEmcRecPoint * clu =static_cast<AliPHOSEmcRecPoint*>(fModules[mod-1]->At(icl)) ;
212 clu->GetLocalPosition(vecEmc) ;
213 Double_t ddx = vecEmc.X()-localPositionTr.X();
214 Double_t ddz = vecEmc.Z()-localPositionTr.Z();
215 Double_t d2 = ddx*ddx + ddz*ddz;
216 if(d2 < minDistance) {
219 emcIndex=clu->GetIndexInList() ;
225 } //Loop over modules
227 if(minDistance<999.){
229 esdTrack->SetStatus(AliESDtrack::kPHOSmatch) ;
230 esdTrack->SetPHOScluster(-emcIndex) ; //Should be ESDCaloCluster index which is not known yet. Will be transformed later in FillESD().
231 esdTrack->SetPHOSdxdz(dx,dz) ;
237 Info("PropagateBack","Number of matched tracks: %d",matched);
246 //____________________________________________________________________________
247 AliCluster *AliPHOSTracker::GetCluster(Int_t index) const {
248 //--------------------------------------------------------------------
249 // Returns the pointer to a given cluster
250 //--------------------------------------------------------------------
251 Int_t m=(index & 0xf0000000) >> 28; // Module number
252 Int_t i=(index & 0x0fffffff) >> 00; // Index within the module
254 return (AliCluster*)(fModules[m])->UncheckedAt(i);
257 //____________________________________________________________________________
258 void AliPHOSTracker::UnloadClusters() {
259 //--------------------------------------------------------------------
260 // This function unloads the PHOS clusters
261 //--------------------------------------------------------------------
262 // for (Int_t i=0; i<5; i++) (fModules[i])->Delete();