correction in C commentaries
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALReconstructor.cxx
CommitLineData
f6019cda 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 ---
f6019cda 29#include "AliEMCALReconstructor.h"
5dee926e 30
31#include "AliESD.h"
32#include "AliRunLoader.h"
33#include "AliEMCALLoader.h"
f6019cda 34#include "AliEMCALClusterizerv1.h"
5dee926e 35#include "AliEMCALRecPoint.h"
dc293ae9 36#include "AliEMCALPID.h"
0964c2e9 37#include "AliEMCALTrigger.h"
1d59832c 38#include "AliRawReader.h"
39
f6019cda 40
41ClassImp(AliEMCALReconstructor)
42
43//____________________________________________________________________________
18a21c7c 44AliEMCALReconstructor::AliEMCALReconstructor()
45 : fDebug(kFALSE)
f6019cda 46{
47 // ctor
f6019cda 48}
49
0a4cb131 50//____________________________________________________________________________
18a21c7c 51AliEMCALReconstructor::AliEMCALReconstructor(const AliEMCALReconstructor & rec)
52 : AliReconstructor(rec),
53 fDebug(rec.fDebug)
0a4cb131 54{
55 //copy ctor
0a4cb131 56}
f6019cda 57
58//____________________________________________________________________________
59AliEMCALReconstructor::~AliEMCALReconstructor()
60{
61 // dtor
62}
63
64//____________________________________________________________________________
65void AliEMCALReconstructor::Reconstruct(AliRunLoader* runLoader) const
66{
67 // method called by AliReconstruction;
68 // Only the clusterization is performed,; the rest of the reconstruction is done in FillESD because the track
69 // segment maker needs access to the AliESD object to retrieve the tracks reconstructed by
70 // the global tracking.
71
72 TString headerFile(runLoader->GetFileName()) ;
b4975670 73 TString branchName(runLoader->GetEventFolder()->GetName() ) ;
f6019cda 74
75 AliEMCALClusterizerv1 clu(headerFile, branchName);
76 clu.SetEventRange(0, -1) ; // do all the events
77 if ( Debug() )
78 clu.ExecuteTask("deb all") ;
79 else
85c60a8e 80 clu.ExecuteTask("pseudo") ;
81
f6019cda 82}
83
84//____________________________________________________________________________
5dee926e 85void AliEMCALReconstructor::Reconstruct(AliRunLoader* runLoader, AliRawReader* rawreader) const
a68156e6 86{
87 // method called by AliReconstruction;
88 // Only the clusterization is performed,; the rest of the reconstruction is done in FillESD because the track
89 // segment maker needs access to the AliESD object to retrieve the tracks reconstructed by
90 // the global tracking.
91 // Here we reconstruct from Raw Data
92
93 rawreader->Reset() ;
94 TString headerFile(runLoader->GetFileName()) ;
95 TString branchName(runLoader->GetEventFolder()->GetName()) ;
85c60a8e 96
a68156e6 97 AliEMCALClusterizerv1 clu(headerFile, branchName);
98 clu.SetEventRange(0, -1) ; // do all the events
99 if ( Debug() )
85c60a8e 100 clu.ExecuteTask("deb pseudo all") ;
a68156e6 101 else
85c60a8e 102 clu.ExecuteTask("pseudo") ;
a68156e6 103
104}
105
106//____________________________________________________________________________
f6019cda 107void AliEMCALReconstructor::FillESD(AliRunLoader* runLoader, AliESD* esd) const
108{
109 // Called by AliReconstruct after Reconstruct() and global tracking and vertxing
f1487f22 110 const double timeScale = 1.e+11; // transition constant from sec to 0.01ns (10ps)
92da3372 111
b4975670 112 Int_t eventNumber = runLoader->GetEventNumber() ;
113
1963b290 114 TString headerFile(runLoader->GetFileName()) ;
115 TString branchName(runLoader->GetEventFolder()->GetName()) ;
85c60a8e 116 // Creates AliESDCaloCluster from AliEMCALRecPoints
5dee926e 117 AliRunLoader *rl = AliRunLoader::GetRunLoader();
118 AliEMCALLoader *emcalLoader = dynamic_cast<AliEMCALLoader*>(rl->GetDetectorLoader("EMCAL"));
119 rl->LoadRecPoints();
92da3372 120 rl->LoadKinematics(); // To get the primary label
121 rl->LoadDigits(); // To get the primary label
122 rl->LoadHits(); // To get the primary label
5dee926e 123 rl->GetEvent(eventNumber);
124 TObjArray *clusters = emcalLoader->RecPoints();
a7a5421e 125 Int_t nClusters = clusters->GetEntries(), nClustersNew=0;
5d9e7bd7 126 // Int_t nRP=0, nPC=0; // in input
a7a5421e 127 esd->SetFirstEMCALCluster(esd->GetNumberOfCaloClusters()); // Put after Phos clusters
92da3372 128
0964c2e9 129 //#########Calculate trigger and set trigger info###########
130
131 AliEMCALTrigger tr ;
132 // tr.SetPatchSize(1);//create 4x4 patches
133 tr.Trigger();
134
135 Float_t maxAmp2x2 = tr.Get2x2MaxAmplitude();
136 Float_t maxAmpnxn = tr.GetnxnMaxAmplitude();
137 Float_t ampOutOfPatch2x2 = tr.Get2x2AmpOutOfPatch() ;
138 Float_t ampOutOfPatchnxn = tr.GetnxnAmpOutOfPatch() ;
139
140 AliEMCALGeometry * geom = AliEMCALGeometry::GetInstance(AliEMCALGeometry::GetDefaulGeometryName());
141
142 Int_t iSM2x2 = tr.Get2x2SuperModule();
143 Int_t iSMnxn = tr.GetnxnSuperModule();
144 Int_t iCellPhi2x2 = tr.Get2x2CellPhi();
145 Int_t iCellPhinxn = tr.GetnxnCellPhi();
146 Int_t iCellEta2x2 = tr.Get2x2CellEta();
147 Int_t iCellEtanxn = tr.GetnxnCellEta();
148
149 AliDebug(2, Form("Trigger 2x2 max amp %f, out amp %f, SM %d, iphi %d ieta %d", maxAmp2x2, ampOutOfPatch2x2, iSM2x2,iCellPhi2x2, iCellEta2x2));
150 AliDebug(2, Form("Trigger 4x4 max amp %f , out amp %f, SM %d, iphi %d, ieta %d", maxAmpnxn, ampOutOfPatchnxn, iSMnxn,iCellPhinxn, iCellEtanxn));
151
152 TVector3 pos2x2(-1,-1,-1);
153 TVector3 posnxn(-1,-1,-1);
154
155 Int_t iAbsId2x2 = geom->GetAbsCellIdFromCellIndexes( iSM2x2, iCellPhi2x2, iCellEta2x2) ;
156 Int_t iAbsIdnxn = geom->GetAbsCellIdFromCellIndexes( iSMnxn, iCellPhinxn, iCellEtanxn) ;
157 geom->GetGlobal(iAbsId2x2, pos2x2);
158 geom->GetGlobal(iAbsIdnxn, posnxn);
159
160 TArrayF triggerPosition(6);
161 triggerPosition[0] = pos2x2(0) ;
162 triggerPosition[1] = pos2x2(1) ;
163 triggerPosition[2] = pos2x2(2) ;
164 triggerPosition[3] = posnxn(0) ;
165 triggerPosition[4] = posnxn(1) ;
166 triggerPosition[5] = posnxn(2) ;
167
168 TArrayF triggerAmplitudes(4);
169 triggerAmplitudes[0] = maxAmp2x2 ;
170 triggerAmplitudes[1] = ampOutOfPatch2x2 ;
171 triggerAmplitudes[2] = maxAmpnxn ;
172 triggerAmplitudes[3] = ampOutOfPatchnxn ;
173
174 esd->AddEMCALTriggerPosition(triggerPosition);
175 esd->AddEMCALTriggerAmplitudes(triggerAmplitudes);
176
177 //######################################
178
179 //Fill CaloClusters
180
5dee926e 181 for (Int_t iClust = 0 ; iClust < nClusters ; iClust++) {
182 const AliEMCALRecPoint * clust = emcalLoader->RecPoint(iClust);
5d9e7bd7 183 //if(clust->GetClusterType()== AliESDCaloCluster::kClusterv1) nRP++; else nPC++;
85c60a8e 184 if (Debug()) clust->Print();
a7a5421e 185 // Get information from EMCAL reconstruction points
85c60a8e 186 Float_t xyz[3];
5dee926e 187 TVector3 gpos;
188 clust->GetGlobalPosition(gpos);
f6019cda 189 for (Int_t ixyz=0; ixyz<3; ixyz++)
5dee926e 190 xyz[ixyz] = gpos[ixyz];
92da3372 191
85c60a8e 192 Int_t digitMult = clust->GetMultiplicity();
193 UShort_t *amplList = new UShort_t[digitMult];
194 UShort_t *timeList = new UShort_t[digitMult];
195 UShort_t *digiList = new UShort_t[digitMult];
196 Float_t *amplFloat = clust->GetEnergiesList();
197 Float_t *timeFloat = clust->GetTimeList();
198 Int_t *digitInts = clust->GetAbsId();
8a11aef1 199 Float_t elipAxis[2];
92da3372 200 clust->GetElipsAxis(elipAxis);
85c60a8e 201
a7a5421e 202 // Convert Float_t* and Int_t* to UShort_t* to save memory
203 // Problem : we should recalculate a cluster characteristics when discard digit(s)
f1487f22 204 Int_t newdigitMult = 0;
92da3372 205 for (Int_t iDigit=0; iDigit<digitMult; iDigit++) {
f1487f22 206 if(timeFloat[iDigit] < 65536./timeScale) {
a7a5421e 207 amplList[newdigitMult] = (UShort_t)(amplFloat[iDigit]*500);
208 if(amplList[newdigitMult] > 0) { // accept digit if poztive amplitude
f1487f22 209 timeList[newdigitMult] = (UShort_t)(timeFloat[iDigit]*timeScale); // Time in units of 0.01 ns = 10 ps
a7a5421e 210 digiList[newdigitMult] = (UShort_t)(digitInts[iDigit]);
211 newdigitMult++;
212 }
92da3372 213 }
92da3372 214 }
a7a5421e 215
216 if(newdigitMult > 0) { // accept cluster if it has some digit
217 nClustersNew++;
218 if(newdigitMult != digitMult) { // some digits were deleted
219 UShort_t *amplListNew = new UShort_t[newdigitMult];
220 UShort_t *timeListNew = new UShort_t[newdigitMult];
221 UShort_t *digiListNew = new UShort_t[newdigitMult];
222 for (Int_t iDigit=0; iDigit<newdigitMult; iDigit++) {
223 amplListNew[iDigit] = amplList[iDigit];
224 timeListNew[iDigit] = timeList[iDigit];
225 digiListNew[iDigit] = digiList[iDigit];
226 }
227
228 delete [] amplList;
229 delete [] timeList;
230 delete [] digiList;
231
232 amplList = amplListNew;
233 timeList = timeListNew;
234 digiList = digiListNew;
235 }
236 // fills the ESDCaloCluster
237 AliESDCaloCluster * ec = new AliESDCaloCluster() ;
238 ec->SetClusterType(clust->GetClusterType());
239 ec->SetGlobalPosition(xyz);
240 ec->SetClusterEnergy(clust->GetEnergy());
241
242 ec->SetNumberOfDigits(newdigitMult);
243 ec->SetDigitAmplitude(amplList); //energies
244 ec->SetDigitTime(timeList); //times
245 ec->SetDigitIndex(digiList); //indices
246 if(clust->GetClusterType()== AliESDCaloCluster::kClusterv1){
247 ec->SetClusterDisp(clust->GetDispersion());
248 ec->SetClusterChi2(-1); //not yet implemented
249 ec->SetM02(elipAxis[0]*elipAxis[0]) ;
250 ec->SetM20(elipAxis[1]*elipAxis[1]) ;
251 ec->SetM11(-1) ; //not yet implemented
252 ec->SetPrimaryIndex(clust->GetPrimaryIndex());
253 }
85c60a8e 254 // add the cluster to the esd object
a7a5421e 255 esd->AddCaloCluster(ec);
256 delete ec;
257 } else { // no new ESD cluster
258 delete [] amplList;
259 delete [] timeList;
260 delete [] digiList;
261 }
262 } // cycle on clusters
d948db41 263 // printf(" %i : nClusters %i : RP %i PC %i \n", eventNumber, nClusters, nRP, nPC);
a7a5421e 264 esd->SetNumberOfEMCALClusters(nClustersNew);
5d9e7bd7 265 //if(nClustersNew != nClusters)
266 //printf(" ##### nClusters %i -> new %i ##### \n", nClusters, nClustersNew );
dc293ae9 267
dc293ae9 268 //Fill ESDCaloCluster with PID weights
dc293ae9 269 AliEMCALPID *pid = new AliEMCALPID;
270 //pid->SetPrintInfo(kTRUE);
271 pid->SetReconstructor(kTRUE);
272 pid->RunPID(esd);
f6019cda 273}
dc293ae9 274