Modifications required for handling dots in HLT trigger names.
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALClusterizer.cxx
CommitLineData
483b0559 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
ee08edde 22//
23// Clusterization mother class. Contains common methods/data members of different
24// clusterizers. GCB 2010
483b0559 25//////////////////////////////////////////////////////////////////////////////
26
27// --- ROOT system ---
c47157cd 28#include "TClonesArray.h"
29#include "TTree.h"
ee08edde 30#include <TFile.h>
31class TFolder;
32#include <TMath.h>
33#include <TMinuit.h>
34#include <TTree.h>
35class TSystem;
36#include <TBenchmark.h>
37#include <TBrowser.h>
38#include <TROOT.h>
483b0559 39
40// --- Standard library ---
ee08edde 41#include <cassert>
483b0559 42
43// --- AliRoot header files ---
483b0559 44#include "AliEMCALClusterizer.h"
ee08edde 45#include "AliEMCALReconstructor.h"
46#include "AliRunLoader.h"
47#include "AliRun.h"
c47157cd 48#include "AliLog.h"
ee08edde 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"
57class AliCDBStorage;
58#include "AliCDBEntry.h"
483b0559 59
60ClassImp(AliEMCALClusterizer)
61
62//____________________________________________________________________________
c47157cd 63AliEMCALClusterizer::AliEMCALClusterizer():
64 fDigitsArr(NULL),
65 fTreeR(NULL),
ee08edde 66 fRecPoints(NULL),
67 fGeom(NULL),
68 fCalibData(NULL),
69 fCaloPed(NULL),
70 fADCchannelECA(0.),fADCpedestalECA(0.),
71 fTimeMin(-1.),fTimeMax(1.),fTimeCut(1.),
72 fDefaultInit(kFALSE),fToUnfold(kFALSE),
73 fNumberOfECAClusters(0), fECAClusteringThreshold(0.),
74 fECALocMaxCut(0.),fECAW0(0.),fMinECut(0.)
483b0559 75{
76 // ctor
ee08edde 77
78 Init();
79
80}
81
82//____________________________________________________________________________
83AliEMCALClusterizer::AliEMCALClusterizer(AliEMCALGeometry* geometry):
84 fDigitsArr(NULL),
85 fTreeR(NULL),
86 fRecPoints(NULL),
87 fGeom(geometry),
88 fCalibData(NULL),
89 fCaloPed(NULL),
90 fADCchannelECA(0.),fADCpedestalECA(0.),
91 fTimeMin(-1.),fTimeMax(1.),fTimeCut(1.),
92 fDefaultInit(kFALSE),fToUnfold(kFALSE),
93 fNumberOfECAClusters(0), fECAClusteringThreshold(0.),
94 fECALocMaxCut(0.),fECAW0(0.),fMinECut(0.)
95{
96 // ctor with the indication of the file where header Tree and digits Tree are stored
97 // use this contructor to avoid usage of Init() which uses runloader
98 // change needed by HLT - MP
99
100 // Note for the future: the use on runloader should be avoided or optional at least
101 // another way is to make Init virtual and protected at least such that the deriving classes can overload
102 // Init() ;
103 //
104
105 if (!fGeom)
106 {
107 AliFatal("Geometry not initialized.");
108 }
109
483b0559 110}
839828a6 111
ee08edde 112//____________________________________________________________________________
113AliEMCALClusterizer::AliEMCALClusterizer(AliEMCALGeometry* geometry, AliEMCALCalibData * calib, AliCaloCalibPedestal * caloped):
114 fDigitsArr(NULL),
115 fTreeR(NULL),
116 fRecPoints(NULL),
117 fGeom(geometry),
118 fCalibData(calib),
119 fCaloPed(caloped),
120 fADCchannelECA(0.),fADCpedestalECA(0.),
121 fTimeMin(-1.),fTimeMax(1.),fTimeCut(1.),
122 fDefaultInit(kFALSE),fToUnfold(kFALSE),
123 fNumberOfECAClusters(0), fECAClusteringThreshold(0.),
124 fECALocMaxCut(0.),fECAW0(0.),fMinECut(0.)
125{
126 // ctor, geometry and calibration are initialized elsewhere.
127
128 if (!fGeom)
129 AliFatal("Geometry not initialized.");
130
131}
132
133
483b0559 134//____________________________________________________________________________
c47157cd 135AliEMCALClusterizer::~AliEMCALClusterizer()
483b0559 136{
c47157cd 137 // dtor
23ca956b 138 //Already deleted in AliEMCALReconstructor.
139
140// if(fGeom) delete fGeom;
141// if(fCalibData) delete fCalibData;
142// if(fCaloPed) delete fCaloPed;
143
144// if (fDigitsArr) {
145// fDigitsArr->Clear("C");
146// delete fDigitsArr;
147// }
148// if (fRecPoints) {
149// fRecPoints->Delete();
150// delete fRecPoints;
151// }
18a21c7c 152}
153
ee08edde 154//____________________________________________________________________________
155Float_t AliEMCALClusterizer::Calibrate(const Float_t amp, const Float_t time, const Int_t absId)
156{
157
158 // Convert digitized amplitude into energy.
159 // Calibration parameters are taken from calibration data base for raw data,
160 // or from digitizer parameters for simulated data.
161 if(fCalibData){
162
163 if (fGeom==0)
164 AliFatal("Did not get geometry from EMCALLoader") ;
165
166 Int_t iSupMod = -1;
167 Int_t nModule = -1;
168 Int_t nIphi = -1;
169 Int_t nIeta = -1;
170 Int_t iphi = -1;
171 Int_t ieta = -1;
172
173 Bool_t bCell = fGeom->GetCellIndex(absId, iSupMod, nModule, nIphi, nIeta) ;
174 if(!bCell) {
175 fGeom->PrintGeometry();
176 Error("Calibrate()"," Wrong cell id number : %i", absId);
177 assert(0);
178 }
179
180 fGeom->GetCellPhiEtaIndexInSModule(iSupMod,nModule,nIphi, nIeta,iphi,ieta);
181
182 // Check if channel is bad (dead or hot), in this case return 0.
183 // Gustavo: 15-12-09 In case of RAW data this selection is already done, but not in simulation.
184 // for the moment keep it here but remember to do the selection at the sdigitizer level
185 // and remove it from here
186 Int_t channelStatus = (Int_t)(fCaloPed->GetDeadMap(iSupMod))->GetBinContent(ieta,iphi);
187 if(channelStatus == AliCaloCalibPedestal::kHot || channelStatus == AliCaloCalibPedestal::kDead) {
188 AliDebug(2,Form("Tower from SM %d, ieta %d, iphi %d is BAD : status %d !!!",iSupMod,ieta,iphi, channelStatus));
189 return 0;
190 }
191 //Check if time is too large or too small, indication of a noisy channel, remove in this case
192 if(time > fTimeMax || time < fTimeMin) return 0;
193
194 fADCchannelECA = fCalibData->GetADCchannel (iSupMod,ieta,iphi);
195 fADCpedestalECA = fCalibData->GetADCpedestal(iSupMod,ieta,iphi);
196
197 return -fADCpedestalECA + amp * fADCchannelECA ;
198
199 }
200 else //Return energy with default parameters if calibration is not available
201 return -fADCpedestalECA + amp * fADCchannelECA ;
202
203}
204
205//____________________________________________________________________________
206void AliEMCALClusterizer::GetCalibrationParameters()
207{
208 // Set calibration parameters:
209 // if calibration database exists, they are read from database,
210 // otherwise, they are taken from digitizer.
211 //
212 // It is a user responsilibity to open CDB before reconstruction,
213 // for example:
214 // AliCDBStorage* storage = AliCDBManager::Instance()->GetStorage("local://CalibDB");
215
216 //Check if calibration is stored in data base
217
218 if(!fCalibData)
219 {
220 AliCDBEntry *entry = (AliCDBEntry*)
221 AliCDBManager::Instance()->Get("EMCAL/Calib/Data");
222 if (entry) fCalibData = (AliEMCALCalibData*) entry->GetObject();
223 }
224
225 if(!fCalibData)
226 AliFatal("Calibration parameters not found in CDB!");
227
228}
229
230//____________________________________________________________________________
231void AliEMCALClusterizer::GetCaloCalibPedestal()
232{
233 // Set calibration parameters:
234 // if calibration database exists, they are read from database,
235 // otherwise, they are taken from digitizer.
236 //
237 // It is a user responsilibity to open CDB before reconstruction,
238 // for example:
239 // AliCDBStorage* storage = AliCDBManager::Instance()->GetStorage("local://CalibDB");
240
241 //Check if calibration is stored in data base
242
243 if(!fCaloPed)
244 {
245 AliCDBEntry *entry = (AliCDBEntry*)
246 AliCDBManager::Instance()->Get("EMCAL/Calib/Pedestals");
247 if (entry) fCaloPed = (AliCaloCalibPedestal*) entry->GetObject();
248 }
249
250 if(!fCaloPed)
251 AliFatal("Pedestal info not found in CDB!");
252
253}
254
255//____________________________________________________________________________
256void AliEMCALClusterizer::Init()
257{
258 // Make all memory allocations which can not be done in default constructor.
259 // Attach the Clusterizer task to the list of EMCAL tasks
260
261 AliRunLoader *rl = AliRunLoader::Instance();
a51e676d 262 if (rl->GetAliRun()){
263 AliEMCAL* emcal = dynamic_cast<AliEMCAL*>(rl->GetAliRun()->GetDetector("EMCAL"));
264 if(emcal)fGeom = emcal->GetGeometry();
265 }
266
267 if(!fGeom){
ee08edde 268 fGeom = AliEMCALGeometry::GetInstance(AliEMCALGeometry::GetDefaultGeometryName());
a51e676d 269 }
ee08edde 270
271 AliDebug(1,Form("geom %p",fGeom));
272
273 if(!gMinuit)
274 gMinuit = new TMinuit(100) ;
275
276}
277
278//____________________________________________________________________________
279void AliEMCALClusterizer::InitParameters()
280{
281 // Initializes the parameters for the Clusterizer
282 fNumberOfECAClusters = 0 ;
283 fCalibData = 0 ;
284 fCaloPed = 0 ;
285
286 const AliEMCALRecParam* recParam = AliEMCALReconstructor::GetRecParam();
287 if(!recParam) {
288 AliFatal("Reconstruction parameters for EMCAL not set!");
289 } else {
290 fECAClusteringThreshold = recParam->GetClusteringThreshold();
291 fECAW0 = recParam->GetW0();
292 fMinECut = recParam->GetMinECut();
293 fToUnfold = recParam->GetUnfold();
294 if(fToUnfold) AliWarning("Cluster Unfolding ON. Implementing only for eta=0 case!!!");
295 fECALocMaxCut = recParam->GetLocMaxCut();
296 fTimeCut = recParam->GetTimeCut();
297 fTimeMin = recParam->GetTimeMin();
298 fTimeMax = recParam->GetTimeMax();
299
300 AliDebug(1,Form("Reconstruction parameters: fECAClusteringThreshold=%.3f GeV, fECAW=%.3f, fMinECut=%.3f GeV, fToUnfold=%d, fECALocMaxCut=%.3f GeV, fTimeCut=%e s,fTimeMin=%e s,fTimeMax=%e s",
301 fECAClusteringThreshold,fECAW0,fMinECut,fToUnfold,fECALocMaxCut,fTimeCut, fTimeMin, fTimeMax));
302 }
303
304}
305
306
307//____________________________________________________________________________
308void AliEMCALClusterizer::Print(Option_t * /*option*/)const
309{
310 // Print clusterizer parameters
311
312 TString message("\n") ;
313
314 if( strcmp(GetName(), "") !=0 ){
315
316 // Print parameters
317
318 TString taskName(Version()) ;
319
320 printf("--------------- ");
321 printf("%s",taskName.Data()) ;
322 printf(" ");
323 printf("Clusterizing digits: ");
324 printf("\n ECA Local Maximum cut = %f", fECALocMaxCut);
325 printf("\n ECA Logarithmic weight = %f", fECAW0);
326 if(fToUnfold)
327 printf("\nUnfolding on\n");
328 else
329 printf("\nUnfolding off\n");
330
331 printf("------------------------------------------------------------------");
332 }
333 else
334 printf("AliEMCALClusterizer not initialized ") ;
335}
336
337//____________________________________________________________________________
338void AliEMCALClusterizer::PrintRecPoints(Option_t * option)
339{
340 // Prints list of RecPoints produced at the current pass of AliEMCALClusterizer
341 if(strstr(option,"deb")) {
342 printf("PrintRecPoints: Clusterization result:") ;
343
344 printf(" Found %d ECA Rec Points\n ",
345 fRecPoints->GetEntriesFast()) ;
346 }
347
348 if(strstr(option,"all")) {
349 if(strstr(option,"deb")) {
350 printf("\n-----------------------------------------------------------------------\n") ;
351 printf("Clusters in ECAL section\n") ;
352 printf("Index Ene(GeV) Multi Module GX GY GZ lX lY lZ Dispersion Lambda 1 Lambda 2 # of prim Primaries list\n") ;
353 }
354 Int_t index;
355 for (index = 0 ; index < fRecPoints->GetEntries() ; index++) {
356 AliEMCALRecPoint * rp = dynamic_cast<AliEMCALRecPoint * >(fRecPoints->At(index)) ;
51e4198e 357 if(rp){
358 TVector3 globalpos;
359 //rp->GetGlobalPosition(globalpos);
360 TVector3 localpos;
361 rp->GetLocalPosition(localpos);
362 Float_t lambda[2];
363 rp->GetElipsAxis(lambda);
364
365 Int_t nprimaries=0;
366 Int_t * primaries = rp->GetPrimaries(nprimaries);
367
368 if(strstr(option,"deb"))
369 printf("\n%6d %8.4f %3d %4.1f %4.1f %4.1f %4.1f %4.1f %4.1f %4.1f %4f %4f %2d : ",
370 rp->GetIndexInList(), rp->GetEnergy(), rp->GetMultiplicity(),
371 globalpos.X(), globalpos.Y(), globalpos.Z(), localpos.X(), localpos.Y(), localpos.Z(),
372 rp->GetDispersion(), lambda[0], lambda[1], nprimaries) ;
373 if(strstr(option,"deb")){
374 for (Int_t iprimary=0; iprimary<nprimaries; iprimary++) {
375 printf("%d ", primaries[iprimary] ) ;
376 }
ee08edde 377 }
378 }
379 }
380
381 if(strstr(option,"deb"))
382 printf("\n-----------------------------------------------------------------------\n");
383 }
384}
385
386//___________________________________________________________________
387void AliEMCALClusterizer::PrintRecoInfo()
388{
389 //print reco version
390 printf(" AliEMCALClusterizer::PrintRecoInfo() : version %s \n", Version() );
391
392}
393
18a21c7c 394//____________________________________________________________________________
c47157cd 395void AliEMCALClusterizer::SetInput(TTree *digitsTree)
18a21c7c 396{
c47157cd 397 // Read the digits from the input tree
398 TBranch *branch = digitsTree->GetBranch("EMCAL");
399 if (!branch) {
400 AliError("can't get the branch with the EMCAL digits !");
401 return;
402 }
3f9ad99f 403 if (!fDigitsArr)
404 fDigitsArr = new TClonesArray("AliEMCALDigit",100);
c47157cd 405 branch->SetAddress(&fDigitsArr);
406 branch->GetEntry(0);
483b0559 407}
408
409//____________________________________________________________________________
c47157cd 410void AliEMCALClusterizer::SetOutput(TTree *clustersTree)
483b0559 411{
c47157cd 412 // Read the digits from the input tree
413 fTreeR = clustersTree;
414
415 AliDebug(9, "Making array for EMCAL clusters");
416 fRecPoints = new TObjArray(100) ;
417 Int_t split = 0;
418 Int_t bufsize = 32000;
419 fTreeR->Branch("EMCALECARP", "TObjArray", &fRecPoints, bufsize, split);
88cb7938 420}
ee08edde 421
422
423