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