Correction in output format.
[u/mrichter/AliRoot.git] / PHOS / AliPHOSReconstructor.cxx
CommitLineData
d15a28e7 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
b2a60966 16/* $Id$ */
17
d15a28e7 18//_________________________________________________________________________
a3dfe79c 19//*--
dfe0be07 20//*-- Yves Schutz (SUBATECH)
21// Reconstruction class. Redesigned from the old AliReconstructionner class and
22// derived from STEER/AliReconstructor.
23//
d15a28e7 24// --- ROOT system ---
25
d15a28e7 26// --- Standard library ---
364de5c6 27
d15a28e7 28// --- AliRoot header files ---
35293055 29#include "AliESD.h"
f444a19f 30#include "AliPHOSReconstructor.h"
7acf6008 31#include "AliPHOSClusterizerv1.h"
7acf6008 32#include "AliPHOSTrackSegmentMakerv1.h"
33#include "AliPHOSPIDv1.h"
35293055 34#include "AliPHOSGetter.h"
23904d16 35#include "AliPHOSTracker.h"
d22dd3b4 36#include "AliRawReader.h"
e957fea8 37
2e60107f 38
f444a19f 39ClassImp(AliPHOSReconstructor)
d15a28e7 40
2e60107f 41Bool_t AliPHOSReconstructor::fgDebug = kFALSE ;
42
d15a28e7 43//____________________________________________________________________________
2e60107f 44 AliPHOSReconstructor::AliPHOSReconstructor()
d15a28e7 45{
b2a60966 46 // ctor
0379a13e 47
6ad0bfa0 48}
49
0379a13e 50//____________________________________________________________________________
51 AliPHOSReconstructor::~AliPHOSReconstructor()
52{
53 // dtor
54
55}
7acf6008 56
7acf6008 57//____________________________________________________________________________
772634e0 58void AliPHOSReconstructor::Reconstruct(AliRunLoader* runLoader) const
35293055 59{
dfe0be07 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()) ;
9ee4fde2 66 TString branchName(runLoader->GetEventFolder()->GetName()) ;
a68156e6 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//____________________________________________________________________________
772634e0 78void AliPHOSReconstructor::Reconstruct(AliRunLoader* runLoader, AliRawReader* rawreader) const
a68156e6 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
772634e0 85
a68156e6 86 rawreader->Reset() ;
87 TString headerFile(runLoader->GetFileName()) ;
88 TString branchName(runLoader->GetEventFolder()->GetName()) ;
35293055 89
dfe0be07 90 AliPHOSClusterizerv1 clu(headerFile, branchName);
f88e2313 91 clu.SetEventRange(0, -1) ; // do all the events
d22dd3b4 92 clu.SetRawReader(rawreader);
f5eaa851 93
94 TString option = GetOption();
95 if (option.Contains("OldRCUFormat"))
96 clu.SetOldRCUFormat(kTRUE);
97
dfe0be07 98 if ( Debug() )
99 clu.ExecuteTask("deb all") ;
100 else
d22dd3b4 101 clu.ExecuteTask("") ;
0379a13e 102
35293055 103}
7acf6008 104
7acf6008 105//____________________________________________________________________________
dfe0be07 106void AliPHOSReconstructor::FillESD(AliRunLoader* runLoader, AliESD* esd) const
7acf6008 107{
23904d16 108 // This function creates AliESDtracks from AliPHOSRecParticles
109 // and
110 // writes them to the ESD
bf72996e 111
23904d16 112 Int_t eventNumber = runLoader->GetEventNumber() ;
dfe0be07 113
25ed816e 114 AliPHOSGetter *gime = AliPHOSGetter::Instance();
115 gime->Event(eventNumber, "DRTP") ;
116 TClonesArray *recParticles = gime->RecParticles();
dfe0be07 117 Int_t nOfRecParticles = recParticles->GetEntries();
25ed816e 118
85c60a8e 119 esd->SetNumberOfPHOSClusters(nOfRecParticles) ;
dd7ee508 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()));
8013c27e 123
dfe0be07 124 for (Int_t recpart = 0 ; recpart < nOfRecParticles ; recpart++) {
125 AliPHOSRecParticle * rp = dynamic_cast<AliPHOSRecParticle*>(recParticles->At(recpart));
126 if (Debug())
127 rp->Print();
25ed816e 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
85c60a8e 133 // fills the ESDCaloCluster
134 Float_t xyz[3];
8013c27e 135 for (Int_t ixyz=0; ixyz<3; ixyz++)
136 xyz[ixyz] = rp->GetPos()[ixyz];
dd7ee508 137
138 AliDebug(2,Form("Global position xyz=(%f,%f,%f)",xyz[0],xyz[1],xyz[2]));
139
25ed816e 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]);
ae3e6f29 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
25ed816e 151 digiList[iDigit] = (UShort_t)(digit->GetId());
152 }
153 ec->SetGlobalPosition(xyz); //rec.point position in MARS
154 ec->SetClusterEnergy(rp->Energy()); //total particle energy
155 ec->SetClusterDisp(emcRP->GetDispersion()); //cluster dispersion
156 ec->SetPid (rp->GetPID()) ; //array of particle identification
157 ec->SetPrimaryIndex (rp->GetPrimaryIndex());//index of primary particle (for simulations)
158 ec->SetM02(emcRP->GetM2x()) ; //second moment M2x
159 ec->SetM20(emcRP->GetM2z()) ; //second moment M2z
160 ec->SetNExMax(emcRP->GetNExMax()); //number of local maxima
161 ec->SetNumberOfDigits(digitMult); //digit multiplicity
162 ec->SetDigitAmplitude(amplList); //energies in 1/500 of GeV
163 ec->SetDigitTime(timeList); //times in 1/100 on ns
164 ec->SetDigitIndex(digiList); //abs id of the cell
165 ec->SetEmcCpvDistance(-1); //not yet implemented
166 ec->SetClusterChi2(-1); //not yet implemented
167 ec->SetM11(-1) ; //not yet implemented
168
dfe0be07 169 // add the track to the esd object
85c60a8e 170 esd->AddCaloCluster(ec);
dd7ee508 171 delete ec;
172 }
173}
174
175void AliPHOSReconstructor::FillESD(AliRunLoader* runLoader,
176 AliRawReader* rawReader, AliESD* esd) const
177{
178 //This function creates AliESDtracks from AliPHOSRecParticles
179 //and writes them to the ESD in the case of raw data reconstruction.
180
181 Int_t eventNumber = runLoader->GetEventNumber() ;
182
183 if(eventNumber==0) {
184 rawReader->RewindEvents();
185 rawReader->NextEvent();
7acf6008 186 }
dd7ee508 187
188 AliPHOSGetter *gime = AliPHOSGetter::Instance();
189
190 Bool_t isOldRCUFormat = kFALSE;
191 TString opt = GetOption();
192 if(opt.Contains("OldRCUFormat"))
193 isOldRCUFormat = kTRUE;
194
195 gime->ReadRaw(rawReader,isOldRCUFormat) ;
196
197 TClonesArray *recParticles = gime->RecParticles();
198 Int_t nOfRecParticles = recParticles->GetEntries();
199
200 esd->SetNumberOfPHOSClusters(nOfRecParticles) ;
201 esd->SetFirstPHOSCluster(esd->GetNumberOfCaloClusters()) ;
202
203 AliDebug(2,Form("%d digits and %d rec. particles in event %d, option %s",gime->Digits()->GetEntries(),nOfRecParticles,eventNumber,GetOption()));
204
205 for (Int_t recpart = 0 ; recpart < nOfRecParticles ; recpart++) {
206 AliPHOSRecParticle * rp = dynamic_cast<AliPHOSRecParticle*>(recParticles->At(recpart));
207
208 if(rp) {
209 Float_t xyz[3];
210 for (Int_t ixyz=0; ixyz<3; ixyz++)
211 xyz[ixyz] = rp->GetPos()[ixyz];
212
213 AliDebug(2,Form("Global position xyz=(%f,%f,%f)",xyz[0],xyz[1],xyz[2]));
214
215 AliPHOSTrackSegment *ts = gime->TrackSegment(rp->GetPHOSTSIndex());
216 AliPHOSEmcRecPoint *emcRP = gime->EmcRecPoint(ts->GetEmcIndex());
217 AliESDCaloCluster *ec = new AliESDCaloCluster() ;
218
219 Int_t digitMult = emcRP->GetDigitsMultiplicity();
220 Int_t *digitsList = emcRP->GetDigitsList();
221 UShort_t *amplList = new UShort_t[digitMult];
222 UShort_t *digiList = new UShort_t[digitMult];
223
224 // Convert Float_t* and Int_t* to UShort_t* to save memory
225 for (Int_t iDigit=0; iDigit<digitMult; iDigit++) {
226 AliPHOSDigit *digit = gime->Digit(digitsList[iDigit]);
227 if(!digit) {
228 AliFatal(Form("Digit not found at the expected position %d!",iDigit));
229 }
230 else {
231 amplList[iDigit] = (UShort_t)(digit->GetEnergy()*500); // Energy in units of GeV/500
232 digiList[iDigit] = (UShort_t)(digit->GetId());
233 }
234 }
235
236 ec->SetGlobalPosition(xyz); //rec.point position in MARS
237 ec->SetClusterEnergy(rp->Energy()); //total particle energy
238 ec->SetClusterDisp(emcRP->GetDispersion()); //cluster dispersion
239 ec->SetPid (rp->GetPID()) ; //array of particle identification
240 ec->SetM02(emcRP->GetM2x()) ; //second moment M2x
241 ec->SetM20(emcRP->GetM2z()) ; //second moment M2z
242 ec->SetNExMax(emcRP->GetNExMax()); //number of local maxima
243 ec->SetNumberOfDigits(digitMult); //digit multiplicity
244 ec->SetDigitAmplitude(amplList); //energies in 1/500 of GeV
245 ec->SetDigitIndex(digiList); //abs id of the cell
246 ec->SetEmcCpvDistance(-1); //not yet implemented
247 ec->SetClusterChi2(-1); //not yet implemented
248 ec->SetM11(-1) ; //not yet implemented
249
250 // add the track to the esd object
251 esd->AddCaloCluster(ec);
252 delete ec;
253
254 }
255 }
256
257
d7d3b67b 258}
23904d16 259
260AliTracker* AliPHOSReconstructor::CreateTracker(AliRunLoader* runLoader) const
261{
262// creates the PHOS tracker
263 if (!runLoader) return NULL;
264 return new AliPHOSTracker(runLoader);
265}
266