]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PHOS/AliPHOSReconstructor.cxx
EMCAL geometry can be created independently form anything now
[u/mrichter/AliRoot.git] / PHOS / AliPHOSReconstructor.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 /* $Id$ */
17
18 //_________________________________________________________________________
19 //*--
20 //*-- Yves Schutz (SUBATECH) 
21 // Reconstruction class. Redesigned from the old AliReconstructionner class and 
22 // derived from STEER/AliReconstructor. 
23 // 
24 // --- ROOT system ---
25
26 // --- Standard library ---
27
28 // --- AliRoot header files ---
29 #include "AliESD.h"
30 #include "AliPHOSReconstructor.h"
31 #include "AliPHOSClusterizerv1.h"
32 #include "AliPHOSTrackSegmentMakerv1.h"
33 #include "AliPHOSPIDv1.h"
34 #include "AliPHOSGetter.h"
35 #include "AliPHOSTracker.h"
36 #include "AliRawReader.h"
37
38  
39 ClassImp(AliPHOSReconstructor)
40
41 Bool_t AliPHOSReconstructor::fgDebug = kFALSE ; 
42
43 //____________________________________________________________________________
44   AliPHOSReconstructor::AliPHOSReconstructor() 
45 {
46   // ctor
47
48
49
50 //____________________________________________________________________________
51   AliPHOSReconstructor::~AliPHOSReconstructor()
52 {
53   // dtor
54
55
56
57 //____________________________________________________________________________
58 void AliPHOSReconstructor::Reconstruct(AliRunLoader* runLoader) const
59 {
60   // method called by AliReconstruction; 
61   // Only the clusterization is performed,; the rest of the reconstruction is done in FillESD because the track
62   // segment maker needs access to the AliESD object to retrieve the tracks reconstructed by 
63   // the global tracking.
64  
65   TString headerFile(runLoader->GetFileName()) ; 
66   TString branchName(runLoader->GetEventFolder()->GetName()) ;  
67   
68   AliPHOSClusterizerv1 clu(headerFile, branchName);
69   clu.SetEventRange(0, -1) ; // do all the events
70   if ( Debug() ) 
71     clu.ExecuteTask("deb all") ; 
72   else 
73     clu.ExecuteTask("") ;  
74
75 }
76
77 //____________________________________________________________________________
78 void AliPHOSReconstructor::Reconstruct(AliRunLoader* runLoader, AliRawReader* rawreader) const
79 {
80   // method called by AliReconstruction; 
81   // Only the clusterization is performed,; the rest of the reconstruction is done in FillESD because the track
82   // segment maker needs access to the AliESD object to retrieve the tracks reconstructed by 
83   // the global tracking.
84   // Here we reconstruct from Raw Data
85
86   rawreader->Reset() ; 
87   TString headerFile(runLoader->GetFileName()) ; 
88   TString branchName(runLoader->GetEventFolder()->GetName()) ;  
89   
90   AliPHOSClusterizerv1 clu(headerFile, branchName);
91   clu.SetEventRange(0, -1) ; // do all the events
92   clu.SetRawReader(rawreader);
93
94   TString option = GetOption();
95   if (option.Contains("OldRCUFormat"))
96     clu.SetOldRCUFormat(kTRUE);
97
98   if ( Debug() ) 
99     clu.ExecuteTask("deb all") ; 
100   else 
101     clu.ExecuteTask("") ;
102
103 }
104
105 //____________________________________________________________________________
106 void AliPHOSReconstructor::FillESD(AliRunLoader* runLoader, AliESD* esd) const
107 {
108   // This function creates AliESDtracks from AliPHOSRecParticles
109   //         and
110   // writes them to the ESD
111
112   Int_t eventNumber = runLoader->GetEventNumber() ;
113
114   AliPHOSGetter *gime = AliPHOSGetter::Instance();
115   gime->Event(eventNumber, "DRTP") ; 
116   TClonesArray *recParticles  = gime->RecParticles();
117   Int_t nOfRecParticles = recParticles->GetEntries();
118
119   esd->SetNumberOfPHOSClusters(nOfRecParticles) ; 
120   esd->SetFirstPHOSCluster(esd->GetNumberOfCaloClusters()) ;
121   
122   AliDebug(2,Form("%d digits and %d rec. particles in event %d, option %s",gime->Digits()->GetEntries(),nOfRecParticles,eventNumber,GetOption()));
123
124   for (Int_t recpart = 0 ; recpart < nOfRecParticles ; recpart++) {
125     AliPHOSRecParticle * rp = dynamic_cast<AliPHOSRecParticle*>(recParticles->At(recpart));
126     if (Debug()) 
127       rp->Print();
128     // Get track segment and EMC rec.point associated with this rec.particle
129     AliPHOSTrackSegment *ts    = gime->TrackSegment(rp->GetPHOSTSIndex());
130     AliPHOSEmcRecPoint  *emcRP = gime->EmcRecPoint(ts->GetEmcIndex());
131     AliESDCaloCluster   *ec    = new AliESDCaloCluster() ; 
132
133     // fills the ESDCaloCluster
134     Float_t xyz[3];
135     for (Int_t ixyz=0; ixyz<3; ixyz++) 
136       xyz[ixyz] = rp->GetPos()[ixyz];
137     
138     AliDebug(2,Form("Global position xyz=(%f,%f,%f)",xyz[0],xyz[1],xyz[2]));
139     
140     Int_t  digitMult  = emcRP->GetDigitsMultiplicity();
141     Int_t *digitsList = emcRP->GetDigitsList();
142     UShort_t *amplList  = new UShort_t[digitMult];
143     UShort_t *timeList  = new UShort_t[digitMult];
144     UShort_t *digiList  = new UShort_t[digitMult];
145
146     // Convert Float_t* and Int_t* to UShort_t* to save memory
147     for (Int_t iDigit=0; iDigit<digitMult; iDigit++) {
148       AliPHOSDigit *digit = gime->Digit(digitsList[iDigit]);
149       amplList[iDigit] = (UShort_t)(digit->GetEnergy()*500); // Energy in units of GeV/500
150       timeList[iDigit] = (UShort_t)(digit->GetTime()*1e9*100); // time in units of 0.01 ns
151       digiList[iDigit] = (UShort_t)(digit->GetId());
152     }
153
154     ec->SetPHOS(kTRUE);
155     ec->SetGlobalPosition(xyz);                 //rec.point position in MARS
156     ec->SetClusterEnergy(rp->Energy());         //total particle energy
157     ec->SetClusterDisp(emcRP->GetDispersion()); //cluster dispersion
158     ec->SetPid          (rp->GetPID()) ;        //array of particle identification
159     ec->SetPrimaryIndex (rp->GetPrimaryIndex());//index of primary particle (for simulations)
160     ec->SetM02(emcRP->GetM2x()) ;               //second moment M2x
161     ec->SetM20(emcRP->GetM2z()) ;               //second moment M2z
162     ec->SetNExMax(emcRP->GetNExMax());          //number of local maxima
163     ec->SetNumberOfDigits(digitMult);           //digit multiplicity
164     ec->SetDigitAmplitude(amplList);            //energies in 1/500 of GeV
165     ec->SetDigitTime(timeList);                 //times in 1/100 on ns
166     ec->SetDigitIndex(digiList);                //abs id of the cell
167     ec->SetEmcCpvDistance(-1);                  //not yet implemented
168     ec->SetClusterChi2(-1);                     //not yet implemented
169     ec->SetM11(-1) ;                            //not yet implemented
170
171     // add the track to the esd object
172     esd->AddCaloCluster(ec);
173     delete ec;    
174   }  
175 }
176
177 //____________________________________________________________________________
178 void AliPHOSReconstructor::FillESD(AliRunLoader* runLoader,
179                                    AliRawReader* rawReader, AliESD* esd) const
180 {
181   //This function creates AliESDtracks from AliPHOSRecParticles 
182   //and writes them to the ESD in the case of raw data reconstruction.
183
184   Int_t eventNumber = runLoader->GetEventNumber() ;
185
186   AliPHOSGetter *gime = AliPHOSGetter::Instance();
187   gime->Event(eventNumber, "DRTP") ; 
188
189   TClonesArray *recParticles  = gime->RecParticles();
190   Int_t nOfRecParticles = recParticles->GetEntries();
191
192   esd->SetNumberOfPHOSClusters(nOfRecParticles) ; 
193   esd->SetFirstPHOSCluster(esd->GetNumberOfCaloClusters()) ;
194   
195   AliDebug(2,Form("%d digits and %d rec. particles in event %d, option %s",gime->Digits()->GetEntries(),nOfRecParticles,eventNumber,GetOption()));
196
197   for (Int_t recpart = 0 ; recpart < nOfRecParticles ; recpart++) {
198     AliPHOSRecParticle * rp = dynamic_cast<AliPHOSRecParticle*>(recParticles->At(recpart));
199
200     if(rp) {
201     Float_t xyz[3];
202     for (Int_t ixyz=0; ixyz<3; ixyz++) 
203       xyz[ixyz] = rp->GetPos()[ixyz];
204
205     AliDebug(2,Form("Global position xyz=(%f,%f,%f)",xyz[0],xyz[1],xyz[2]));
206     
207     AliPHOSTrackSegment *ts    = gime->TrackSegment(rp->GetPHOSTSIndex());
208     AliPHOSEmcRecPoint  *emcRP = gime->EmcRecPoint(ts->GetEmcIndex());
209     AliESDCaloCluster   *ec    = new AliESDCaloCluster() ; 
210
211     Int_t  digitMult  = emcRP->GetDigitsMultiplicity();
212     Int_t *digitsList = emcRP->GetDigitsList();
213     UShort_t *amplList  = new UShort_t[digitMult];
214     UShort_t *digiList  = new UShort_t[digitMult];
215
216     // Convert Float_t* and Int_t* to UShort_t* to save memory
217     for (Int_t iDigit=0; iDigit<digitMult; iDigit++) {
218       AliPHOSDigit *digit = gime->Digit(digitsList[iDigit]);
219       if(!digit) {
220         AliFatal(Form("Digit not found at the expected position %d!",iDigit));
221       }
222       else {
223         amplList[iDigit] = (UShort_t)digit->GetEnergy();
224         digiList[iDigit] = (UShort_t)(digit->GetId());
225       }
226     }
227
228     ec->SetPHOS(kTRUE);
229     ec->SetGlobalPosition(xyz);                 //rec.point position in MARS
230     ec->SetClusterEnergy(rp->Energy());         //total particle energy
231     ec->SetClusterDisp(emcRP->GetDispersion()); //cluster dispersion
232     ec->SetPid          (rp->GetPID()) ;        //array of particle identification
233     ec->SetM02(emcRP->GetM2x()) ;               //second moment M2x
234     ec->SetM20(emcRP->GetM2z()) ;               //second moment M2z
235     ec->SetNExMax(emcRP->GetNExMax());          //number of local maxima
236     ec->SetNumberOfDigits(digitMult);           //digit multiplicity
237     ec->SetDigitAmplitude(amplList);            //digit energies
238     ec->SetDigitIndex(digiList);                //abs id of the cell
239     ec->SetEmcCpvDistance(-1);                  //not yet implemented
240     ec->SetClusterChi2(-1);                     //not yet implemented
241     ec->SetM11(-1) ;                            //not yet implemented
242
243     // add the track to the esd object
244     esd->AddCaloCluster(ec);
245     delete ec;    
246
247     }
248   }
249
250
251 }
252
253 AliTracker* AliPHOSReconstructor::CreateTracker(AliRunLoader* runLoader) const
254 {
255 // creates the PHOS tracker
256   if (!runLoader) return NULL; 
257   return new AliPHOSTracker(runLoader);
258 }
259