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