]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EMCAL/AliEMCALClusterizer.cxx
AliEMCALClusterizer: Correct initialization in ctor of time correction parameter...
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALClusterizer.cxx
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 //  Base class for the clusterization algorithm (pure abstract)
20 //*--
21 //*-- Author: Yves Schutz  SUBATECH 
22 // 
23 //   Clusterization mother class. Contains common methods/data members of different 
24 //   clusterizers. GCB 2010
25 //////////////////////////////////////////////////////////////////////////////
26
27 // --- ROOT system ---
28 #include "TClonesArray.h"
29 #include "TTree.h"
30 #include <TFile.h> 
31 class TFolder;
32 #include <TMath.h> 
33 #include <TMinuit.h>
34 #include <TTree.h> 
35 class TSystem; 
36 #include <TBenchmark.h>
37 #include <TBrowser.h>
38 #include <TROOT.h>
39
40 // --- Standard library ---
41 #include <cassert>
42
43 // --- AliRoot header files ---
44 #include "AliEMCALClusterizer.h"
45 #include "AliEMCALReconstructor.h"
46 #include "AliRunLoader.h"
47 #include "AliRun.h"
48 #include "AliLog.h"
49 #include "AliEMCAL.h"
50 #include "AliEMCALRecPoint.h"
51 #include "AliEMCALRecParam.h"
52 #include "AliEMCALGeometry.h"
53 #include "AliEMCALRecParam.h"
54 #include "AliCDBManager.h"
55 #include "AliCaloCalibPedestal.h"
56 #include "AliEMCALCalibData.h"
57 class AliCDBStorage;
58 #include "AliCDBEntry.h"
59
60 ClassImp(AliEMCALClusterizer)
61
62 //____________________________________________________________________________
63 AliEMCALClusterizer::AliEMCALClusterizer():
64   fIsInputCalibrated(kFALSE),
65   fJustClusters(kFALSE),
66   fDigitsArr(NULL),
67   fTreeR(NULL),
68   fRecPoints(NULL),
69   fGeom(NULL),
70   fCalibData(NULL), 
71   fCaloPed(NULL),
72   fADCchannelECA(0.),fADCpedestalECA(0.), fTimeECA(0.),
73   fTimeMin(-1.),fTimeMax(1.),fTimeCut(1.),
74   fDefaultInit(kFALSE),fToUnfold(kFALSE),
75   fNumberOfECAClusters(0), fECAClusteringThreshold(0.),
76   fECALocMaxCut(0.),fECAW0(0.),fMinECut(0.),
77   fClusterUnfolding(NULL)
78 {
79   // ctor
80   
81   Init();
82 }
83
84 //____________________________________________________________________________
85 AliEMCALClusterizer::AliEMCALClusterizer(AliEMCALGeometry* geometry): 
86   fIsInputCalibrated(kFALSE),
87   fJustClusters(kFALSE),
88   fDigitsArr(NULL),
89   fTreeR(NULL),
90   fRecPoints(NULL),
91   fGeom(geometry),
92   fCalibData(NULL), 
93   fCaloPed(NULL),
94   fADCchannelECA(0.),fADCpedestalECA(0.), fTimeECA(0.),
95   fTimeMin(-1.),fTimeMax(1.),fTimeCut(1.),
96   fDefaultInit(kFALSE),fToUnfold(kFALSE),
97   fNumberOfECAClusters(0), fECAClusteringThreshold(0.),
98   fECALocMaxCut(0.),fECAW0(0.),fMinECut(0.),
99   fClusterUnfolding(NULL)
100 {
101   // Ctor with the indication of the file where header Tree and digits Tree are stored.
102   // Use this contructor to avoid usage of Init() which uses runloader.
103   // Change needed by HLT - MP.
104   // Note for the future: the use on runloader should be avoided or optional at least.
105   // Another way is to make Init virtual and protected at least 
106   // such that the deriving classes can overload Init();
107   
108   if (!fGeom)
109   {
110     AliFatal("Geometry not initialized.");
111   }
112   Int_t i=0;
113   for (i = 0; i < 8; i++)
114     fSSPars[i] = 0.;
115   for (i = 0; i < 3; i++) {
116     fPar5[i] = 0.;
117     fPar6[i] = 0.;
118   }
119 }
120
121 //____________________________________________________________________________
122 AliEMCALClusterizer::AliEMCALClusterizer(AliEMCALGeometry *geometry, 
123                                          AliEMCALCalibData *calib, 
124                                          AliCaloCalibPedestal *caloped): 
125   fIsInputCalibrated(kFALSE),
126   fJustClusters(kFALSE),
127   fDigitsArr(NULL),
128   fTreeR(NULL),
129   fRecPoints(NULL),
130   fGeom(geometry),
131   fCalibData(calib),
132   fCaloPed(caloped),
133   fADCchannelECA(0.),fADCpedestalECA(0.), fTimeECA(0.),
134   fTimeMin(-1.),fTimeMax(1.),fTimeCut(1.),
135   fDefaultInit(kFALSE),fToUnfold(kFALSE),
136   fNumberOfECAClusters(0), fECAClusteringThreshold(0.),
137   fECALocMaxCut(0.),fECAW0(0.),fMinECut(0.),
138   fClusterUnfolding(NULL)
139 {
140   // ctor, geometry and calibration are initialized elsewhere.
141   
142   if (!fGeom)
143     AliFatal("Geometry not initialized.");
144   
145   Int_t i=0;
146   for (i = 0; i < 8; i++)
147     fSSPars[i] = 0.;
148   for (i = 0; i < 3; i++) {
149     fPar5[i] = 0.;
150     fPar6[i] = 0.;
151   }
152 }
153
154 //____________________________________________________________________________
155 AliEMCALClusterizer::~AliEMCALClusterizer()
156 {
157   // dtor
158   //Already deleted in AliEMCALReconstructor.
159
160   if(fClusterUnfolding) delete fClusterUnfolding;
161
162   // make sure we delete the rec points array
163   DeleteRecPoints();
164 }
165
166 //____________________________________________________________________________
167 void AliEMCALClusterizer::DeleteRecPoints()
168 {
169   // free the cluster array
170   if (fRecPoints) 
171     {
172       AliDebug(2, "Deleting fRecPoints.");
173       fRecPoints->Delete();
174       delete fRecPoints;
175       fRecPoints = 0;
176     }
177 }
178
179 //____________________________________________________________________________
180 void AliEMCALClusterizer::Calibrate(Float_t & amp, Float_t & time, const Int_t absId) 
181 {
182   // Convert digitized amplitude into energy, calibrate time
183   // Calibration parameters are taken from OCDB : OCDB/EMCAL/Calib/Data
184
185   //Return energy with default parameters if calibration is not available
186   if (!fCalibData && !fCaloPed) {
187     if (fIsInputCalibrated == kTRUE)
188     {
189       AliDebug(10, Form("Input already calibrated!"));
190       return ;
191     }
192     else{
193       AliFatal("OCDB calibration and bad map parameters are not available");
194       return;
195     }   
196   }
197   
198   if (fGeom==0)
199     AliFatal("Did not get geometry from EMCALLoader") ;
200     
201   Int_t iSupMod = -1;
202   Int_t nModule = -1;
203   Int_t nIphi   = -1;
204   Int_t nIeta   = -1;
205   Int_t iphi    = -1;
206   Int_t ieta    = -1;
207     
208   Bool_t bCell = fGeom->GetCellIndex(absId, iSupMod, nModule, nIphi, nIeta) ;
209   if(!bCell) {
210     fGeom->PrintGeometry();
211     AliError(Form("Wrong cell id number : %i", absId));
212     //assert(0); // GCB: This aborts reconstruction of raw simulations 
213     //where simulation had more SM than default geometry, 
214     //change to return 0, to avoid aborting good generations.
215     amp  = 0;
216     time = 0;
217     return ;
218   }
219     
220   fGeom->GetCellPhiEtaIndexInSModule(iSupMod,nModule,nIphi, nIeta,iphi,ieta);
221           
222   // Check if channel is bad (dead or hot), in this case return 0.      
223   // Gustavo: 15-12-09 In case of RAW data this selection is already done, but not in simulation.
224   // for the moment keep it here but remember to do the selection at the sdigitizer level 
225   // and remove it from here
226   if (fCaloPed) {
227     Int_t channelStatus = (Int_t)(fCaloPed->GetDeadMap(iSupMod))->GetBinContent(ieta,iphi);
228     if(channelStatus == AliCaloCalibPedestal::kHot || channelStatus == AliCaloCalibPedestal::kDead) {
229       AliDebug(2,Form("Tower from SM %d, ieta %d, iphi %d is BAD : status %d !!!",iSupMod,ieta,iphi, channelStatus));
230       amp  = 0 ;
231       time = 0 ;
232       return ;
233     }
234   }
235   //Check if time is too large or too small, indication of a noisy channel, remove in this case
236   if(time > fTimeMax || time < fTimeMin) {
237     amp  = 0 ;
238     time = 0 ;
239     return ;
240   }
241     
242   if (fIsInputCalibrated||!fCalibData)
243   {
244     AliDebug(10, Form("Input already calibrated!"));
245     return ;
246   }
247           
248   fADCchannelECA  = fCalibData->GetADCchannel (iSupMod,ieta,iphi);
249   fADCpedestalECA = fCalibData->GetADCpedestal(iSupMod,ieta,iphi);
250   fTimeECA        = fCalibData->GetTimeChannel(iSupMod,ieta,iphi);
251   
252   time -= fTimeECA ;
253   amp   = amp * fADCchannelECA - fADCpedestalECA ;  
254   
255 }
256
257 //____________________________________________________________________________
258 void AliEMCALClusterizer::GetCalibrationParameters() 
259 {
260   // Set calibration parameters:
261   // If calibration database exists, they are read from database,
262   // otherwise, they are taken from digitizer.
263   // It is a user responsilibity to open CDB before reconstruction, 
264   // for example: 
265   // AliCDBStorage* storage = AliCDBManager::Instance()->GetStorage("local://CalibDB");
266
267   if (fIsInputCalibrated)
268     return;
269   
270   //Check if calibration is stored in data base
271   if(!fCalibData)
272   {
273     AliCDBEntry *entry = (AliCDBEntry*) 
274     AliCDBManager::Instance()->Get("EMCAL/Calib/Data");
275     if (entry) fCalibData =  (AliEMCALCalibData*) entry->GetObject();
276   }
277   
278   if(!fCalibData)
279     AliFatal("Calibration parameters not found in CDB!");
280 }
281
282 //____________________________________________________________________________
283 void AliEMCALClusterizer::GetCaloCalibPedestal() 
284 {
285   // Set calibration parameters:
286   // if calibration database exists, they are read from database,
287   // otherwise, they are taken from digitizer.
288   //
289   // It is a user responsilibity to open CDB before reconstruction, 
290   // for example: 
291   // AliCDBStorage* storage = AliCDBManager::Instance()->GetStorage("local://CalibDB");
292
293   if (fIsInputCalibrated)
294     return;
295   
296   // Check if calibration is stored in data base
297   if(!fCaloPed)
298     {
299       AliCDBEntry *entry = (AliCDBEntry*) 
300         AliCDBManager::Instance()->Get("EMCAL/Calib/Pedestals");
301       if (entry) fCaloPed =  (AliCaloCalibPedestal*) entry->GetObject();
302     }
303   
304   if(!fCaloPed)
305     AliFatal("Pedestal info not found in CDB!");
306 }
307
308 //____________________________________________________________________________
309 void AliEMCALClusterizer::Init()
310 {
311   // Make all memory allocations which can not be done in default constructor.
312   // Attach the Clusterizer task to the list of EMCAL tasks
313   
314   AliRunLoader *rl = AliRunLoader::Instance();
315   if (rl->GetAliRun()){
316     AliEMCAL* emcal = dynamic_cast<AliEMCAL*>(rl->GetAliRun()->GetDetector("EMCAL"));
317     if(emcal)fGeom = emcal->GetGeometry();
318   }
319   
320   if(!fGeom){ 
321     fGeom = AliEMCALGeometry::GetInstance(AliEMCALGeometry::GetDefaultGeometryName());
322   }
323   
324   AliDebug(1,Form("geom %p",fGeom));
325   
326   if(!gMinuit) 
327     gMinuit = new TMinuit(100) ;
328   
329   Int_t i=0;
330   for (i = 0; i < 8; i++)
331     fSSPars[i] = 0.;
332   for (i = 0; i < 3; i++) {
333     fPar5[i] = 0.;
334     fPar6[i] = 0.;
335   }
336 }
337
338 //____________________________________________________________________________
339 void AliEMCALClusterizer::InitParameters()
340
341   // Initializes the parameters for the Clusterizer from AliEMCALReconstructor::GetRecParam().
342
343   return InitParameters(AliEMCALReconstructor::GetRecParam());
344 }
345
346 //____________________________________________________________________________
347 void AliEMCALClusterizer::InitParameters(const AliEMCALRecParam* recParam)
348
349   // Initializes the parameters for the Clusterizer
350
351   fNumberOfECAClusters = 0 ;
352   fCalibData           = 0 ;
353   fCaloPed             = 0 ;
354         
355   if(!recParam) {
356     AliFatal("Reconstruction parameters for EMCAL not set!");
357   } 
358
359   fECAClusteringThreshold = recParam->GetClusteringThreshold();
360   fECAW0                  = recParam->GetW0();
361   fMinECut                = recParam->GetMinECut();    
362   fToUnfold               = recParam->GetUnfold();
363   fECALocMaxCut           = recParam->GetLocMaxCut();
364   fTimeCut                = recParam->GetTimeCut();
365   fTimeMin                = recParam->GetTimeMin();
366   fTimeMax                = recParam->GetTimeMax();
367     
368   AliDebug(1,Form("Reconstruction parameters: fECAClusteringThreshold=%.3f GeV, fECAW=%.3f, fMinECut=%.3f GeV, "
369                   "fToUnfold=%d, fECALocMaxCut=%.3f GeV, fTimeCut=%e s,fTimeMin=%e s,fTimeMax=%e s",
370                   fECAClusteringThreshold,fECAW0,fMinECut,fToUnfold,fECALocMaxCut,fTimeCut, fTimeMin, fTimeMax));
371
372   if (fToUnfold) {
373     Int_t i=0;
374     for (i = 0; i < 8; i++) {
375       fSSPars[i] = recParam->GetSSPars(i);
376     } //end of loop over parameters
377     for (i = 0; i < 3; i++) {
378       fPar5[i] = recParam->GetPar5(i);
379       fPar6[i] = recParam->GetPar6(i);
380     } //end of loop over parameters
381       
382     InitClusterUnfolding();
383       
384     for (i = 0; i < 8; i++) {
385       AliDebug(1,Form("unfolding shower shape parameters: fSSPars=%f \n",fSSPars[i]));
386     }
387     for (i = 0; i < 3; i++) {
388       AliDebug(1,Form("unfolding parameter 5: fPar5=%f \n",fPar5[i]));
389       AliDebug(1,Form("unfolding parameter 6: fPar6=%f \n",fPar6[i]));
390     }
391   } // to unfold
392 }
393
394 //____________________________________________________________________________
395 void AliEMCALClusterizer::Print(Option_t * /*option*/)const
396 {
397   // Print clusterizer parameters
398   
399   TString message("\n") ; 
400   
401   if (strcmp(GetName(),"") == 0) {
402     printf("AliEMCALClusterizer not initialized\n");
403     return;
404   }
405     
406   // Print parameters
407   TString taskName(Version()) ;
408     
409   printf("--------------- "); 
410   printf("%s",taskName.Data()) ; 
411   printf(" "); 
412   printf("Clusterizing digits: "); 
413   printf("\n                       ECA Local Maximum cut    = %f", fECALocMaxCut); 
414   printf("\n                       ECA Logarithmic weight   = %f", fECAW0); 
415   if (fToUnfold) {
416     printf("\nUnfolding on\n");
417     printf("Unfolding parameters: fSSpars: \n");
418     Int_t i=0;
419     for (i = 0; i < 8; i++) {
420       printf("fSSPars[%d] = %f \n", i, fSSPars[i]);
421     }
422     printf("Unfolding parameter 5 and 6: fPar5 and fPar6: \n");
423     for (i = 0; i < 3; i++) {
424       printf("fPar5[%d] = %f \n", i, fPar5[i]);
425       printf("fPar6[%d] = %f \n", i, fPar6[i]);
426     }
427   }
428   else
429     printf("\nUnfolding off\n");
430     
431   printf("------------------------------------------------------------------"); 
432 }
433
434 //____________________________________________________________________________
435 void AliEMCALClusterizer::PrintRecPoints(Option_t * option)
436 {
437   // Prints list of RecPoints produced at the current pass of AliEMCALClusterizer
438
439   if (strstr(option,"deb")) {
440     printf("PrintRecPoints: Clusterization result:") ; 
441     printf("           Found %d ECA Rec Points\n ", 
442            fRecPoints->GetEntriesFast()) ; 
443   }
444   
445   if (strstr(option,"all")) {
446     if (strstr(option,"deb")) {
447       printf("\n-----------------------------------------------------------------------\n") ;
448       printf("Clusters in ECAL section\n") ;
449       printf("Index    Ene(GeV) Multi Module     GX    GY   GZ  lX    lY   lZ   Dispersion Lambda 1   Lambda 2  # of prim  Primaries list\n") ;
450     }
451     Int_t index; 
452     for (index =  0 ; index < fRecPoints->GetEntries() ; index++) {
453       AliEMCALRecPoint * rp = dynamic_cast<AliEMCALRecPoint * >(fRecPoints->At(index)) ; 
454       if (!rp) 
455         continue;
456
457       TVector3  globalpos;  
458       //rp->GetGlobalPosition(globalpos);
459       TVector3  localpos;  
460       rp->GetLocalPosition(localpos);
461       Float_t lambda[2]; 
462       rp->GetElipsAxis(lambda);
463         
464       Int_t nprimaries=0;
465       Int_t * primaries = rp->GetPrimaries(nprimaries);
466       if(strstr(option,"deb")) 
467         printf("\n%6d  %8.4f  %3d     %4.1f    %4.1f %4.1f  %4.1f %4.1f %4.1f    %4.1f   %4f  %4f    %2d     : ", 
468                rp->GetIndexInList(), rp->GetEnergy(), rp->GetMultiplicity(),
469                globalpos.X(), globalpos.Y(), globalpos.Z(), localpos.X(), localpos.Y(), localpos.Z(), 
470                rp->GetDispersion(), lambda[0], lambda[1], nprimaries) ; 
471       if(strstr(option,"deb")){ 
472         for (Int_t iprimary=0; iprimary<nprimaries; iprimary++) {
473           printf("%d ", primaries[iprimary] ) ; 
474         }
475       }
476     }
477     
478     if(strstr(option,"deb"))
479       printf("\n-----------------------------------------------------------------------\n");
480   }
481 }
482
483 //___________________________________________________________________
484 void  AliEMCALClusterizer::PrintRecoInfo()
485 {
486   // Print reco version
487
488   printf(" AliEMCALClusterizer::PrintRecoInfo() : version %s \n", Version() );
489 }
490
491 //____________________________________________________________________________
492 void AliEMCALClusterizer::SetInput(TTree *digitsTree)
493 {
494   // Read the digits from the input tree
495
496   TBranch *branch = digitsTree->GetBranch("EMCAL");
497   if (!branch) { 
498     AliError("can't get the branch with the EMCAL digits !");
499     return;
500   }
501   if (!fDigitsArr)
502     fDigitsArr = new TClonesArray("AliEMCALDigit",100);
503   branch->SetAddress(&fDigitsArr);
504   branch->GetEntry(0);
505 }
506
507 //____________________________________________________________________________
508 void AliEMCALClusterizer::SetOutput(TTree *clustersTree)
509 {
510   // Read the digits from the input tree
511
512   AliDebug(9, "Making array for EMCAL clusters");
513   fRecPoints = new TObjArray(1000);
514   if (clustersTree) {
515     fTreeR = clustersTree;
516     Int_t split = 0;
517     Int_t bufsize = 32000;
518     fTreeR->Branch("EMCALECARP", "TObjArray", &fRecPoints, bufsize, split);
519   }
520 }
521
522 //___________________________________________________________________
523 void AliEMCALClusterizer::SetInputCalibrated(Bool_t val)
524 {
525   // Flag to indicate that input is calibrated - the case when we run already on ESD
526
527   fIsInputCalibrated = val;
528 }
529
530 //___________________________________________________________________
531 void AliEMCALClusterizer::SetJustClusters(Bool_t val)
532 {
533   // Flag to indicate that we are running on ESDs, when calling 
534   // rp->EvalAll(fECAW0,fDigitsArr,fJustClusters); in derived classes
535
536   fJustClusters = val;
537 }