compilation warnings
[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//_________________________________________________________________________
fa42b1f3 19//--
20//-- Yves Schutz (SUBATECH)
f6019cda 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
aaa3cb7c 31#include "AliCodeTimer.h"
af885e0f 32#include "AliESDEvent.h"
89ffc0b0 33#include "AliESDCaloCluster.h"
0e7c6655 34#include "AliESDCaloCells.h"
6a0cf740 35#include "AliESDtrack.h"
5dee926e 36#include "AliEMCALLoader.h"
98e9578e 37#include "AliEMCALRawUtils.h"
0e7c6655 38#include "AliEMCALDigit.h"
f6019cda 39#include "AliEMCALClusterizerv1.h"
5dee926e 40#include "AliEMCALRecPoint.h"
dc293ae9 41#include "AliEMCALPID.h"
0964c2e9 42#include "AliEMCALTrigger.h"
1d59832c 43#include "AliRawReader.h"
fa42b1f3 44#include "AliCDBEntry.h"
45#include "AliCDBManager.h"
46#include "AliEMCALRecParam.h"
c47157cd 47// to be removed - it is here just because of geom
48#include "AliRun.h"
49#include "AliRunLoader.h"
1d59832c 50
f6019cda 51ClassImp(AliEMCALReconstructor)
52
c47157cd 53AliEMCALRecParam* AliEMCALReconstructor::fgkRecParam = 0; // EMCAL rec. parameters
54
f6019cda 55//____________________________________________________________________________
18a21c7c 56AliEMCALReconstructor::AliEMCALReconstructor()
57 : fDebug(kFALSE)
f6019cda 58{
59 // ctor
0e7c6655 60
f6019cda 61}
62
0a4cb131 63//____________________________________________________________________________
18a21c7c 64AliEMCALReconstructor::AliEMCALReconstructor(const AliEMCALReconstructor & rec)
65 : AliReconstructor(rec),
66 fDebug(rec.fDebug)
0a4cb131 67{
68 //copy ctor
0a4cb131 69}
f6019cda 70
71//____________________________________________________________________________
72AliEMCALReconstructor::~AliEMCALReconstructor()
73{
74 // dtor
aaa3cb7c 75
76 AliCodeTimer::Instance()->Print();
f6019cda 77}
78
79//____________________________________________________________________________
fa42b1f3 80void AliEMCALReconstructor::InitRecParam() const
81{
82 // Check if the instance of AliEMCALRecParam exists,
83 // if not, get it from OCDB if available, otherwise create a default one
84
85 if (!fgkRecParam && (AliCDBManager::Instance()->IsDefaultStorageSet())) {
86 AliCDBEntry *entry = (AliCDBEntry*)
87 AliCDBManager::Instance()->Get("EMCAL/Config/RecParam");
88 if (entry) fgkRecParam = (AliEMCALRecParam*) entry->GetObject();
89 }
90
91 if(!fgkRecParam){
92 AliWarning("The Reconstruction parameters for EMCAL nonitialized - Used default one");
93 fgkRecParam = new AliEMCALRecParam;
94 }
95}
96
97//____________________________________________________________________________
c47157cd 98void AliEMCALReconstructor::Reconstruct(TTree* digitsTree, TTree* clustersTree) const
f6019cda 99{
100 // method called by AliReconstruction;
101 // Only the clusterization is performed,; the rest of the reconstruction is done in FillESD because the track
102 // segment maker needs access to the AliESD object to retrieve the tracks reconstructed by
103 // the global tracking.
c47157cd 104 // Works on the current event.
fa42b1f3 105
aaa3cb7c 106 AliCodeTimerAuto("")
107
fa42b1f3 108 InitRecParam();
c47157cd 109 AliEMCALClusterizerv1 clu;
110 clu.SetInput(digitsTree);
111 clu.SetOutput(clustersTree);
0e7c6655 112 if(Debug())
113 clu.Digits2Clusters("deb all") ;
114 else
115 clu.Digits2Clusters("") ;
116
f6019cda 117}
118
119//____________________________________________________________________________
c47157cd 120void AliEMCALReconstructor::ConvertDigits(AliRawReader* rawReader, TTree* digitsTree) const
98e9578e 121
a68156e6 122{
c47157cd 123 // Conversion from raw data to
124 // EMCAL digits.
125 // Works on a single-event basis
85c60a8e 126
aaa3cb7c 127
128 AliCodeTimerAuto("")
129
98e9578e 130 rawReader->Reset() ;
98e9578e 131
c47157cd 132 TClonesArray *digitsArr = new TClonesArray("AliEMCALDigit",100);
133 Int_t bufsize = 32000;
134 digitsTree->Branch("EMCAL", &digitsArr, bufsize);
98e9578e 135
feedcab9 136 //Get Mapping RCU files from the AliEMCALRecParam
137 const TObjArray* maps = AliEMCALRecParam::GetMappings();
138 if(!maps) AliFatal("Cannot retrieve ALTRO mappings!!");
139
140 AliAltroMapping * mapping[2] ; // For the moment only 2
141 for(Int_t i = 0; i < 2; i++) {
142 mapping[i] = (AliAltroMapping*)maps->At(i);
143 }
144
c47157cd 145 static AliEMCALRawUtils rawUtils;
feedcab9 146 rawUtils.SetOption(GetOption());
147 rawUtils.Raw2Digits(rawReader,digitsArr,mapping);
c615db53 148
149 digitsTree->Fill();
150 digitsArr->Delete();
151 delete digitsArr;
152
a68156e6 153}
154
155//____________________________________________________________________________
0e7c6655 156void AliEMCALReconstructor::FillESD(TTree* digitsTree, TTree* clustersTree,
c47157cd 157 AliESDEvent* esd) const
f6019cda 158{
98e9578e 159 // Called by AliReconstruct after Reconstruct() and global tracking and vertexing
c47157cd 160 // Works on the current event
85c60a8e 161 // Creates AliESDCaloCluster from AliEMCALRecPoints
0e7c6655 162 // and AliESDCaloCells from AliEMCALDigits
163 // Also, fills ESD with calorimeter trigger information
92da3372 164
6a0cf740 165 //######################################################
0964c2e9 166 //#########Calculate trigger and set trigger info###########
6a0cf740 167 //######################################################
aaa3cb7c 168
169 AliCodeTimerStart(Form("JLK trigger info"));
0964c2e9 170 AliEMCALTrigger tr ;
171 // tr.SetPatchSize(1);//create 4x4 patches
172 tr.Trigger();
173
174 Float_t maxAmp2x2 = tr.Get2x2MaxAmplitude();
175 Float_t maxAmpnxn = tr.GetnxnMaxAmplitude();
176 Float_t ampOutOfPatch2x2 = tr.Get2x2AmpOutOfPatch() ;
177 Float_t ampOutOfPatchnxn = tr.GetnxnAmpOutOfPatch() ;
178
98e9578e 179 AliEMCALGeometry * geom = 0;
c47157cd 180 AliRunLoader *runLoader = AliRunLoader::GetRunLoader();
98e9578e 181 if (runLoader->GetAliRun() && runLoader->GetAliRun()->GetDetector("EMCAL"))
182 geom = dynamic_cast<AliEMCAL*>(runLoader->GetAliRun()->GetDetector("EMCAL"))->GetGeometry();
183 if (geom == 0)
184 geom = AliEMCALGeometry::GetInstance(AliEMCALGeometry::GetDefaulGeometryName());
185
0964c2e9 186 Int_t iSM2x2 = tr.Get2x2SuperModule();
187 Int_t iSMnxn = tr.GetnxnSuperModule();
188 Int_t iCellPhi2x2 = tr.Get2x2CellPhi();
189 Int_t iCellPhinxn = tr.GetnxnCellPhi();
190 Int_t iCellEta2x2 = tr.Get2x2CellEta();
191 Int_t iCellEtanxn = tr.GetnxnCellEta();
192
193 AliDebug(2, Form("Trigger 2x2 max amp %f, out amp %f, SM %d, iphi %d ieta %d", maxAmp2x2, ampOutOfPatch2x2, iSM2x2,iCellPhi2x2, iCellEta2x2));
194 AliDebug(2, Form("Trigger 4x4 max amp %f , out amp %f, SM %d, iphi %d, ieta %d", maxAmpnxn, ampOutOfPatchnxn, iSMnxn,iCellPhinxn, iCellEtanxn));
195
196 TVector3 pos2x2(-1,-1,-1);
197 TVector3 posnxn(-1,-1,-1);
198
199 Int_t iAbsId2x2 = geom->GetAbsCellIdFromCellIndexes( iSM2x2, iCellPhi2x2, iCellEta2x2) ;
200 Int_t iAbsIdnxn = geom->GetAbsCellIdFromCellIndexes( iSMnxn, iCellPhinxn, iCellEtanxn) ;
201 geom->GetGlobal(iAbsId2x2, pos2x2);
202 geom->GetGlobal(iAbsIdnxn, posnxn);
203
204 TArrayF triggerPosition(6);
205 triggerPosition[0] = pos2x2(0) ;
206 triggerPosition[1] = pos2x2(1) ;
207 triggerPosition[2] = pos2x2(2) ;
208 triggerPosition[3] = posnxn(0) ;
209 triggerPosition[4] = posnxn(1) ;
210 triggerPosition[5] = posnxn(2) ;
211
212 TArrayF triggerAmplitudes(4);
213 triggerAmplitudes[0] = maxAmp2x2 ;
214 triggerAmplitudes[1] = ampOutOfPatch2x2 ;
215 triggerAmplitudes[2] = maxAmpnxn ;
216 triggerAmplitudes[3] = ampOutOfPatchnxn ;
217
218 esd->AddEMCALTriggerPosition(triggerPosition);
219 esd->AddEMCALTriggerAmplitudes(triggerAmplitudes);
aaa3cb7c 220
221 AliCodeTimerStop(Form("JLK trigger info"));
222
0e7c6655 223 //########################################
224 //##############Fill CaloCells###############
225 //########################################
aaa3cb7c 226
227 AliCodeTimerStart(Form("JLK fill calocells"));
228
0e7c6655 229 TClonesArray *digits = new TClonesArray("AliEMCALDigit",1000);
230 TBranch *branchdig = digitsTree->GetBranch("EMCAL");
231 if (!branchdig) {
232 AliError("can't get the branch with the PHOS digits !");
233 return;
234 }
235 branchdig->SetAddress(&digits);
236 digitsTree->GetEvent(0);
237 Int_t nDigits = digits->GetEntries(), idignew = 0 ;
238 AliDebug(1,Form("%d digits",nDigits));
239
240 AliESDCaloCells &emcCells = *(esd->GetEMCALCells());
241 emcCells.CreateContainer(nDigits);
242 emcCells.SetType(AliESDCaloCells::kEMCALCell);
243 for (Int_t idig = 0 ; idig < nDigits ; idig++) {
244 const AliEMCALDigit * dig = (const AliEMCALDigit*)digits->At(idig);
245 if(dig->GetAmp() > 0 ){
246 emcCells.SetCell(idignew,dig->GetId(),dig->GetAmp(), dig->GetTime());
247 idignew++;
248 }
249 }
250 emcCells.SetNumberOfCells(idignew);
251 emcCells.Sort();
252
aaa3cb7c 253 AliCodeTimerStop(Form("JLK fill calocells"));
254
0e7c6655 255 //------------------------------------------------------------
256 //-----------------CLUSTERS-----------------------------
257 //------------------------------------------------------------
258 TObjArray *clusters = new TObjArray(100);
259 TBranch *branch = clustersTree->GetBranch("EMCALECARP");
260 branch->SetAddress(&clusters);
261 clustersTree->GetEvent(0);
262
263 Int_t nClusters = clusters->GetEntries(), nClustersNew=0;
264 AliDebug(1,Form("%d clusters",nClusters));
265 esd->SetFirstEMCALCluster(esd->GetNumberOfCaloClusters()); // Put after Phos clusters
266
6a0cf740 267 //######################################################
268 //#######################TRACK MATCHING###############
269 //######################################################
270 //Fill list of integers, each one is index of track to which the cluster belongs.
271
aaa3cb7c 272 AliCodeTimerStart(Form("JLK track matching"));
273
6a0cf740 274 // step 1 - initialize array of matched track indexes
275 Int_t *matchedTrack = new Int_t[nClusters];
276 for (Int_t iclus = 0; iclus < nClusters; iclus++)
277 matchedTrack[iclus] = -1; // neg. index --> no matched track
278
279 // step 2, change the flag for all matched clusters found in tracks
280 Int_t iemcalMatch = -1;
281 Int_t endtpc = esd->GetNumberOfTracks();
282 for (Int_t itrack = 0; itrack < endtpc; itrack++) {
283 AliESDtrack * track = esd->GetTrack(itrack) ; // retrieve track
284 iemcalMatch = track->GetEMCALcluster();
65f4a419 285 if(iemcalMatch >= 0) matchedTrack[iemcalMatch] = itrack;
6a0cf740 286 }
0e7c6655 287
aaa3cb7c 288 AliCodeTimerStop(Form("JLK track matching"));
289
6a0cf740 290 //########################################
0e7c6655 291 //##############Fill CaloClusters############
6a0cf740 292 //########################################
0964c2e9 293
aaa3cb7c 294 AliCodeTimerStart(Form("JLK fill caloclusters"));
295
0e7c6655 296 esd->SetNumberOfEMCALClusters(nClusters);
5dee926e 297 for (Int_t iClust = 0 ; iClust < nClusters ; iClust++) {
c47157cd 298 const AliEMCALRecPoint * clust = (const AliEMCALRecPoint*)clusters->At(iClust);
8ada0ffe 299 //if(clust->GetClusterType()== AliESDCaloCluster::kEMCALClusterv1) nRP++; else nPC++;
85c60a8e 300 if (Debug()) clust->Print();
a7a5421e 301 // Get information from EMCAL reconstruction points
85c60a8e 302 Float_t xyz[3];
5dee926e 303 TVector3 gpos;
304 clust->GetGlobalPosition(gpos);
f6019cda 305 for (Int_t ixyz=0; ixyz<3; ixyz++)
5dee926e 306 xyz[ixyz] = gpos[ixyz];
8a11aef1 307 Float_t elipAxis[2];
92da3372 308 clust->GetElipsAxis(elipAxis);
7592dfc4 309
0e7c6655 310 //Create digits lists
311 Int_t cellMult = clust->GetMultiplicity();
312 //TArrayS digiList(digitMult);
313 Float_t *amplFloat = clust->GetEnergiesList();
314 Int_t *digitInts = clust->GetAbsId();
315 TArrayS absIdList(cellMult);
316 //Uncomment when unfolding is done
317 //TArrayD fracList(cellMult);
318
319 Int_t newCellMult = 0;
320 for (Int_t iCell=0; iCell<cellMult; iCell++) {
321 if (amplFloat[iCell] > 0) {
322 absIdList[newCellMult] = (UShort_t)(digitInts[iCell]);
323 //Uncomment when unfolding is done
324 //fracList[newCellMult] = amplFloat[iCell]/emcCells.GetCellAmplitude(digitInts[iCell]);
325 newCellMult++;
92da3372 326 }
92da3372 327 }
0e7c6655 328 absIdList.Set(newCellMult);
329 //Uncomment when unfolding is done
330 //fracList.Set(newCellMult);
331
332 if(newCellMult > 0) { // accept cluster if it has some digit
a7a5421e 333 nClustersNew++;
65721814 334 //Primaries
7592dfc4 335 Int_t parentMult = 0;
fa42b1f3 336 Int_t *parentList = clust->GetParents(parentMult);
0e7c6655 337
a7a5421e 338 // fills the ESDCaloCluster
339 AliESDCaloCluster * ec = new AliESDCaloCluster() ;
0e7c6655 340 ec->SetClusterType(AliESDCaloCluster::kEMCALClusterv1);
7592dfc4 341 ec->SetPosition(xyz);
342 ec->SetE(clust->GetEnergy());
0e7c6655 343 ec->SetNCells(newCellMult);
344 //Change type of list from short to ushort
345 UShort_t *newAbsIdList = new UShort_t[newCellMult];
346 //Uncomment when unfolding is done
347 //Double_t *newFracList = new Double_t[newCellMult];
348 for(Int_t i = 0; i < newCellMult ; i++) {
349 newAbsIdList[i]=absIdList[i];
350 //Uncomment when unfolding is done
351 //newFracList[i]=fracList[i];
352 }
353 ec->SetCellsAbsId(newAbsIdList);
354 //Uncomment when unfolding is done
355 //ec->SetCellsAmplitudeFraction(newFracList);
356
357 ec->SetClusterDisp(clust->GetDispersion());
358 ec->SetClusterChi2(-1); //not yet implemented
359 ec->SetM02(elipAxis[0]*elipAxis[0]) ;
360 ec->SetM20(elipAxis[1]*elipAxis[1]) ;
361 ec->SetM11(-1) ; //not yet implemented
362
363 TArrayI arrayTrackMatched(1);// Only one track, temporal solution.
364 arrayTrackMatched[0]= matchedTrack[iClust];
365 ec->AddTracksMatched(arrayTrackMatched);
366
367 TArrayI arrayParents(parentMult,parentList);
368 ec->AddLabels(arrayParents);
369
7592dfc4 370
6a0cf740 371 // add the cluster to the esd object
a7a5421e 372 esd->AddCaloCluster(ec);
373 delete ec;
0e7c6655 374 //delete [] newAbsIdList ;
375 //delete [] newFracList ;
a7a5421e 376 }
377 } // cycle on clusters
0e7c6655 378
17773e2e 379 delete [] matchedTrack;
0e7c6655 380
a7a5421e 381 esd->SetNumberOfEMCALClusters(nClustersNew);
5d9e7bd7 382 //if(nClustersNew != nClusters)
383 //printf(" ##### nClusters %i -> new %i ##### \n", nClusters, nClustersNew );
7592dfc4 384
dc293ae9 385 //Fill ESDCaloCluster with PID weights
0e7c6655 386 AliEMCALPID *pid = new AliEMCALPID;
387 //pid->SetPrintInfo(kTRUE);
388 pid->SetReconstructor(kTRUE);
389 pid->RunPID(esd);
390 delete pid;
aaa3cb7c 391
392 AliCodeTimerStop(Form("JLK fill caloclusters"));
0e7c6655 393
f6019cda 394}
dc293ae9 395
98e9578e 396