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:
22 #include <TClonesArray.h>
25 #include "AliPHOSTracker.h"
26 #include "AliPHOSEmcRecPoint.h"
27 #include "AliESDEvent.h"
29 //-------------------------------------------------------------------------
31 // Matches ESD tracks with the PHOS and makes the PID.
33 //-------------------------------------------------------------------------
35 ClassImp(AliPHOSTracker)
37 Bool_t AliPHOSTracker::fgDebug = kFALSE ;
40 // ***** Some geometrical constants (used in PropagateBack)
42 const Double_t kR=460.+ 9; // Radial coord. of the centre of EMC module (cm)
44 const Double_t kAlpha=20.*TMath::Pi()/180.; // Segmentation angle (rad)
45 const Double_t kYmax=kR*TMath::Tan(0.5*kAlpha); // Maximal possible y-coord.(cm)
46 const Double_t kZmax=65.; // Approximately: the maximal possible z-coord.(cm)
50 AliPHOSTracker::AliPHOSTracker(): AliTracker(), fRunLoader(0) {
51 //--------------------------------------------------------------------
52 // The default constructor
53 //--------------------------------------------------------------------
54 for (Int_t i=0; i<5; i++)
55 fModules[i]=new TClonesArray("AliPHOSEmcRecPoint",777);
58 AliPHOSTracker::~AliPHOSTracker() {
59 //--------------------------------------------------------------------
61 //--------------------------------------------------------------------
62 for (Int_t i=0; i<5; i++) {
63 (fModules[i])->Delete();
68 Int_t AliPHOSTracker::LoadClusters(TTree *cTree) {
69 //--------------------------------------------------------------------
70 // This function loads the PHOS clusters
71 //--------------------------------------------------------------------
73 TBranch *branch=cTree->GetBranch("PHOSEmcRP");
75 AliError("No branch with the EMC clusters found !");
78 branch->SetAddress(&arr);
81 Int_t nentr=(Int_t)branch->GetEntries();
82 for (Int_t i=0; i<nentr; i++) {
83 if (!branch->GetEvent(i)) continue;
84 Int_t ncl=arr->GetEntriesFast();
86 AliPHOSEmcRecPoint *cl=(AliPHOSEmcRecPoint*)arr->UncheckedAt(ncl);
88 Int_t m=cl->GetPHOSMod();
90 AliError("Wrong module index !");
94 // Here is how the alignment is treated
95 if (!cl->Misalign()) AliWarning("Can't misalign this cluster !");
97 cl->SetBit(14,kFALSE); // The clusters are not yet attached to any track
99 TClonesArray &module=*fModules[m-1];
100 Int_t idx=module.GetEntriesFast();
101 new (module[idx]) AliPHOSEmcRecPoint(*cl);
108 Info("LoadClusters","Number of loaded clusters: %d",nclusters);
114 Int_t AliPHOSTracker::PropagateBack(AliESDEvent *esd) {
115 //--------------------------------------------------------------------
116 // Called by AliReconstruction
117 // Performs the track matching with the PHOS modules
119 //--------------------------------------------------------------------
121 // The following old function is a bad function: it uses RunLoader ;(
122 PropagateBackOld(esd);
125 Int_t nt=esd->GetNumberOfTracks();
127 // *** Select and sort the ESD track in accordance with their quality
128 Double_t *quality=new Double_t[nt];
129 Int_t *index=new Int_t[nt];
130 for (Int_t i=0; i<nt; i++) {
131 AliESDtrack *esdTrack=esd->GetTrack(i);
132 quality[i] = esdTrack->GetSigmaY2() + esdTrack->GetSigmaZ2();
134 TMath::Sort(nt,quality,index,kFALSE);
137 // *** Start the matching
140 for (Int_t i=0; i<nt; i++) {
141 AliESDtrack *esdTrack=esd->GetTrack(index[i]);
143 // Skip the tracks having "wrong" status (has to be checked/tuned)
144 ULong_t status = esdTrack->GetStatus();
145 if ((status & AliESDtrack::kTRDout) == 0) continue;
146 if ((status & AliESDtrack::kTRDrefit) == 1) continue;
148 AliExternalTrackParam t(*esdTrack);
150 Int_t isec=Int_t(t.GetAlpha()/kAlpha);
151 Int_t imod=-isec-2; // PHOS module
153 Double_t y; // Some tracks do not reach the PHOS
154 if (!t.GetYAt(kR,bz,y)) continue; // because of the bending
156 Double_t z; t.GetZAt(kR,bz,z);
157 if (TMath::Abs(z) > kZmax) continue; // Some tracks miss the PHOS in Z
160 while (TMath::Abs(y) > kYmax) { // Find the matching module
161 Double_t alp=t.GetAlpha();
163 if (!t.Rotate(alp+kAlpha)) {ok=kFALSE; break;}
165 } else if (y < -kYmax) {
166 if (!t.Rotate(alp-kAlpha)) {ok=kFALSE; break;}
169 if (!t.GetYAt(kR,bz,y)) {ok=kFALSE; break;}
171 if (!ok) continue; // Track rotation failed
174 if ((imod<0)||(imod>4)) continue; // Some tracks miss the PHOS in azimuth
176 //t.CorrectForMaterial(...); // Correct for the TOF material, if needed
177 t.PropagateTo(kR,bz); // Propagate to the matching module
180 // *** Search for the "best" cluster (can be improved)
181 TClonesArray &cArray=*fModules[imod];
182 Int_t ncl=cArray.GetEntriesFast();
183 AliPHOSEmcRecPoint *bestCluster=0; // The "best" cluster
184 Double_t maxd2=400; // (cm^2)
185 for (Int_t i=0; i<ncl; i++) {
186 AliPHOSEmcRecPoint *c=(AliPHOSEmcRecPoint *)cArray.UncheckedAt(i);
188 if (c->TestBit(14)) continue; // This clusters is "used"
190 Double_t dy = t.GetY() - c->GetY(), dz = t.GetZ() - c->GetZ();
191 Double_t d2 = dy*dy + dz*dz;
198 if (!bestCluster) continue; // No reasonable matching found
200 bestCluster->SetBit(14,kTRUE); // This clusters is now attached to a track
204 // *** Now, do the PID with the "bestCluster"
205 // and add the corresponding info to the ESD track pointed by "esdTrack"
208 printf("%e %e %e %e\n",t.GetSign(), t.GetX() - bestCluster->GetX(),
209 t.GetY() - bestCluster->GetY(),
210 t.GetZ() - bestCluster->GetZ());
214 Info("PropagateBack","Number of matched tracks: %d",matched);
222 AliCluster *AliPHOSTracker::GetCluster(Int_t index) const {
223 //--------------------------------------------------------------------
224 // Returns the pointer to a given cluster
225 //--------------------------------------------------------------------
226 Int_t m=(index & 0xf0000000) >> 28; // Module number
227 Int_t i=(index & 0x0fffffff) >> 00; // Index within the module
229 return (AliCluster*)(fModules[m])->UncheckedAt(i);
232 void AliPHOSTracker::UnloadClusters() {
233 //--------------------------------------------------------------------
234 // This function unloads the PHOS clusters
235 //--------------------------------------------------------------------
236 for (Int_t i=0; i<5; i++) (fModules[i])->Delete();
241 // **** The following are bad functions: they use RunLoader ;(
242 // **** To be rewritten.
244 #include "AliPHOSTrackSegmentMakerv1.h"
245 #include "AliPHOSTrackSegmentMakerv2.h"
246 #include "AliPHOSPIDv1.h"
247 #include "AliRunLoader.h"
249 Int_t AliPHOSTracker::PropagateBackOld(AliESDEvent *esd) {
250 // Bad function: it uses RunLoader ;(
251 // Creates the tracksegments and Recparticles
254 Int_t eventNumber = fRunLoader->GetEventNumber() ;
256 TString headerFile(fRunLoader->GetFileName()) ;
257 TString branchName(fRunLoader->GetEventFolder()->GetName()) ;
259 AliPHOSTrackSegmentMakerv1 tsm(headerFile, branchName);
260 // AliPHOSTrackSegmentMakerv2 tsm(headerFile, branchName);
262 AliPHOSPIDv1 pid(headerFile, branchName);
267 // do current event; the loop over events is done by AliReconstruction::Run()
268 tsm.SetEventRange(eventNumber, eventNumber) ;
269 pid.SetEventRange(eventNumber, eventNumber) ;
271 tsm.ExecuteTask("deb all") ;
272 pid.ExecuteTask("deb all") ;
275 tsm.ExecuteTask("") ;
276 pid.ExecuteTask("") ;
282 AliPHOSTracker::AliPHOSTracker(AliRunLoader *l): AliTracker(), fRunLoader(l) {
283 //--------------------------------------------------------------------
284 // Bad constructor: uses RunLoader ;(
285 //--------------------------------------------------------------------
286 for (Int_t i=0; i<5; i++)
287 fModules[i]=new TClonesArray("AliPHOSEmcRecPoint",777);