]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG4/CaloCalib/AliAnalysisTaskEMCALClusterize.cxx
Implemented NxM cluster finder
[u/mrichter/AliRoot.git] / PWG4 / CaloCalib / AliAnalysisTaskEMCALClusterize.cxx
CommitLineData
6fdd30c4 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/* $Id: $ */
16
17//_________________________________________________________________________
18// This analysis provides a new list of clusters to be used in other analysis
19//
20// Author: Gustavo Conesa Balbastre,
21// Adapted from analysis class from Deepa Thomas
22//
23//
24//_________________________________________________________________________
25
26// --- Root ---
27#include "TString.h"
28#include "TRefArray.h"
29#include "TClonesArray.h"
30#include "TTree.h"
31#include "TGeoManager.h"
32
33// --- AliRoot Analysis Steering
34#include "AliAnalysisTask.h"
35#include "AliAnalysisManager.h"
36#include "AliESDEvent.h"
37#include "AliGeomManager.h"
38#include "AliVCaloCells.h"
39#include "AliAODCaloCluster.h"
40#include "AliCDBManager.h"
41#include "AliCDBStorage.h"
42#include "AliCDBEntry.h"
43#include "AliLog.h"
44#include "AliVEventHandler.h"
45
46// --- EMCAL
47#include "AliEMCALRecParam.h"
48#include "AliEMCALAfterBurnerUF.h"
49#include "AliEMCALGeometry.h"
50#include "AliEMCALClusterizerNxN.h"
51#include "AliEMCALClusterizerv1.h"
52#include "AliEMCALRecPoint.h"
53#include "AliEMCALDigit.h"
54#include "AliCaloCalibPedestal.h"
55#include "AliEMCALCalibData.h"
56
57#include "AliAnalysisTaskEMCALClusterize.h"
58
59ClassImp(AliAnalysisTaskEMCALClusterize)
60
61//________________________________________________________________________
62AliAnalysisTaskEMCALClusterize::AliAnalysisTaskEMCALClusterize(const char *name)
63 : AliAnalysisTaskSE(name)
64 , fGeom(0), fGeomName("EMCAL_FIRSTYEARV1"), fGeomMatrixSet(kFALSE), fLoadGeomMatrices(kFALSE)
65 , fCalibData(0), fPedestalData(0), fOCDBpath("raw://")
66 , fDigitsArr(0), fClusterArr(0), fCaloClusterArr(0)
67 , fRecParam(0), fClusterizer(0), fUnfolder(0), fJustUnfold(kFALSE)
68 , fOutputAODBranch(0), fOutputAODBranchName("newEMCALClusters"), fFillAODFile(kTRUE)
69
70 {
71 //ctor
72 for(Int_t i = 0; i < 10; i++) fGeomMatrix[i] = 0 ;
73 fDigitsArr = new TClonesArray("AliEMCALDigit",200);
74 fClusterArr = new TObjArray(100);
75 fCaloClusterArr = new TObjArray(100);
76 fRecParam = new AliEMCALRecParam;
3fa4fb85 77 fBranchNames="ESD:EMCALCells.";
6fdd30c4 78}
79
80//________________________________________________________________________
81AliAnalysisTaskEMCALClusterize::AliAnalysisTaskEMCALClusterize()
82 : AliAnalysisTaskSE("DefaultAnalysis_AliAnalysisTaskEMCALClusterize")
83 , fGeom(0), fGeomName("EMCAL_FIRSTYEARV1"), fGeomMatrixSet(kFALSE), fLoadGeomMatrices(kFALSE)
84 , fCalibData(0), fPedestalData(0), fOCDBpath("raw://")
85 , fDigitsArr(0), fClusterArr(0), fCaloClusterArr(0)
542e1379 86 , fRecParam(0), fClusterizer(0), fUnfolder(0), fJustUnfold(kFALSE)
6fdd30c4 87 , fOutputAODBranch(0), fOutputAODBranchName("newEMCALClusters"), fFillAODFile(kFALSE)
88{
89 // Constructor
90 for(Int_t i = 0; i < 10; i++) fGeomMatrix[i] = 0 ;
91 fDigitsArr = new TClonesArray("AliEMCALDigit",200);
92 fClusterArr = new TObjArray(100);
93 fCaloClusterArr = new TObjArray(100);
94 fRecParam = new AliEMCALRecParam;
3fa4fb85 95 fBranchNames="ESD:EMCALCells.";
6fdd30c4 96}
97
98//________________________________________________________________________
99AliAnalysisTaskEMCALClusterize::~AliAnalysisTaskEMCALClusterize()
100{
101 //dtor
102
103 if (fDigitsArr){
104 fDigitsArr->Clear("C");
542e1379 105 delete fDigitsArr;
6fdd30c4 106 }
107
108 if (fClusterArr){
109 fClusterArr->Delete();
542e1379 110 delete fClusterArr;
6fdd30c4 111 }
112
113 if (fCaloClusterArr){
114 fCaloClusterArr->Delete();
542e1379 115 delete fCaloClusterArr;
6fdd30c4 116 }
117
542e1379 118 if(fClusterizer) {delete fClusterizer;}
119 if(fGeom) {delete fGeom; }
120 if(fUnfolder) {delete fUnfolder; }
6fdd30c4 121
122}
123
124//-------------------------------------------------------------------
125void AliAnalysisTaskEMCALClusterize::UserCreateOutputObjects()
126{
127 // Init geometry, create list of output clusters
128
129 fGeom = AliEMCALGeometry::GetInstance(fGeomName) ;
130
131 fOutputAODBranch = new TClonesArray("AliAODCaloCluster", 0);
132 fOutputAODBranch->SetName(fOutputAODBranchName);
133 AddAODBranch("TClonesArray", &fOutputAODBranch);
3fa4fb85 134 Info("UserCreateOutputObjects","Create Branch: %s",fOutputAODBranchName.Data());
6fdd30c4 135}
136
137//________________________________________________________________________
138void AliAnalysisTaskEMCALClusterize::UserExec(Option_t *)
139{
140 // Main loop
141 // Called for each event
142
6fdd30c4 143 //Remove the contents of output list set in the previous event
144 fOutputAODBranch->Clear("C");
145
146 AliVEvent * event = InputEvent();
147 if (!event) {
3fa4fb85 148 Error("UserExec","Event not available");
6fdd30c4 149 return;
150 }
151
152 //Magic line to write events to AOD file
153 AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler()->SetFillAOD(fFillAODFile);
3fa4fb85 154 LoadBranches();
155
6fdd30c4 156 //-------------------------------------------------------------------------------------
157 //Set the geometry matrix, for the first event, skip the rest
158 //-------------------------------------------------------------------------------------
159 if(!fGeomMatrixSet){
160 if(fLoadGeomMatrices){
161 for(Int_t mod=0; mod < (fGeom->GetEMCGeometry())->GetNumberOfSuperModules(); mod++){
162 if(fGeomMatrix[mod]){
163 if(DebugLevel() > 1)
164 fGeomMatrix[mod]->Print();
165 fGeom->SetMisalMatrix(fGeomMatrix[mod],mod) ;
166 }
167 fGeomMatrixSet=kTRUE;
168 }//SM loop
169 }//Load matrices
170 else if(!gGeoManager){
3fa4fb85 171 Info("UserExec","Get geo matrices from data");
6fdd30c4 172 //Still not implemented in AOD, just a workaround to be able to work at least with ESDs
173 if(!strcmp(event->GetName(),"AliAODEvent")) {
174 if(DebugLevel() > 1)
3fa4fb85 175 Warning("UserExec","Use ideal geometry, values geometry matrix not kept in AODs.");
6fdd30c4 176 }//AOD
177 else {
3fa4fb85 178 if(DebugLevel() > 1)
179 Info("UserExec","AliAnalysisTaskEMCALClusterize Load Misaligned matrices.");
6fdd30c4 180 AliESDEvent* esd = dynamic_cast<AliESDEvent*>(event) ;
181 if(!esd) {
3fa4fb85 182 Error("UserExec","This event does not contain ESDs?");
6fdd30c4 183 return;
184 }
185 for(Int_t mod=0; mod < (fGeom->GetEMCGeometry())->GetNumberOfSuperModules(); mod++){
186 if(DebugLevel() > 1)
187 esd->GetEMCALMatrix(mod)->Print();
188 if(esd->GetEMCALMatrix(mod)) fGeom->SetMisalMatrix(esd->GetEMCALMatrix(mod),mod) ;
189 }
190 fGeomMatrixSet=kTRUE;
191 }//ESD
192 }//Load matrices from Data
193 }//first event
194
195 //Get the list of cells needed for unfolding and reclustering
196 AliVCaloCells *cells= event->GetEMCALCells();
197 Int_t nClustersOrg = 0;
198 //-------------------------------------------
199 //---------Unfolding clusters----------------
200 //-------------------------------------------
201 if (fJustUnfold) {
202
203 //Fill the array with the EMCAL clusters, copy them
204 for (Int_t i = 0; i < event->GetNumberOfCaloClusters(); i++)
205 {
206 AliVCluster *clus = event->GetCaloCluster(i);
207 if(clus->IsEMCAL()){
3fa4fb85 208 //printf("Org Cluster %d, E %f\n",i, clus->E());
e615d952 209 AliESDCaloCluster * esdCluster = dynamic_cast<AliESDCaloCluster*> (clus);
210 AliAODCaloCluster * aodCluster = dynamic_cast<AliAODCaloCluster*> (clus);
211 if (esdCluster){
212 fCaloClusterArr->Add( new AliESDCaloCluster(*esdCluster) );
6fdd30c4 213 }//ESD
e615d952 214 else if(aodCluster){
215 fCaloClusterArr->Add( new AliAODCaloCluster(*aodCluster) );
6fdd30c4 216 }//AOD
3fa4fb85 217 else
218 Warning("UserExec()"," - Wrong CaloCluster type?");
6fdd30c4 219 nClustersOrg++;
220 }
221 }
222
223 //Do the unfolding
224 fUnfolder->UnfoldClusters(fCaloClusterArr, cells);
225
226 //CLEAN-UP
227 fUnfolder->Clear();
228
229 //printf("nClustersOrg %d\n",nClustersOrg);
230 }
231 //-------------------------------------------
232 //---------- Recluster cells ----------------
233 //-------------------------------------------
234
235 else{
236 //-------------------------------------------------------------------------------------
237 //Transform CaloCells into Digits
238 //-------------------------------------------------------------------------------------
239 Int_t idigit = 0;
240 Int_t id = -1;
241 Float_t amp = -1;
242 Float_t time = -1;
243
244 Double_t cellAmplitude = 0;
245 Double_t cellTime = 0;
246 Short_t cellNumber = 0;
247
248 TTree *digitsTree = new TTree("digitstree","digitstree");
249 digitsTree->Branch("EMCAL","TClonesArray", &fDigitsArr, 32000);
250
251 for (Int_t icell = 0; icell < cells->GetNumberOfCells(); icell++)
252 {
253 if (cells->GetCell(icell, cellNumber, cellAmplitude, cellTime) != kTRUE)
254 break;
255
256 time = cellTime;
257 amp = cellAmplitude;
258 id = cellNumber;
259
260 AliEMCALDigit *digit = (AliEMCALDigit*) fDigitsArr->New(idigit);
261 digit->SetId(id);
262 digit->SetAmplitude(amp);
263 digit->SetTime(time);
264 digit->SetTimeR(time);
265 digit->SetIndexInList(idigit);
266 digit->SetType(AliEMCALDigit::kHG);
267 //if(Entry()==0) printf("Digit: Id %d, amp %f, time %e, index %d\n",id, amp,time,idigit);
268 idigit++;
269 }
270
271 //Fill the tree with digits
272 digitsTree->Fill();
273
274 //-------------------------------------------------------------------------------------
275 //Do the clusterization
276 //-------------------------------------------------------------------------------------
277 TTree *clustersTree = new TTree("clustertree","clustertree");
3fa4fb85 278
6fdd30c4 279 fClusterizer->SetInput(digitsTree);
280 fClusterizer->SetOutput(clustersTree);
281 fClusterizer->Digits2Clusters("");
282
283 //-------------------------------------------------------------------------------------
284 //Transform the recpoints into AliVClusters
285 //-------------------------------------------------------------------------------------
286
287 clustersTree->SetBranchStatus("*",0); //disable all branches
288 clustersTree->SetBranchStatus("EMCALECARP",1); //Enable only the branch we need
289
290 TBranch *branch = clustersTree->GetBranch("EMCALECARP");
291 branch->SetAddress(&fClusterArr);
292 branch->GetEntry(0);
293
294 RecPoints2Clusters(fDigitsArr, fClusterArr, fCaloClusterArr);
295
296 //---CLEAN UP-----
297 fClusterizer->Clear();
298 fDigitsArr ->Clear("C");
299 fClusterArr ->Delete(); // Do not Clear(), it leaks, why?
300
301 clustersTree->Delete("all");
302 digitsTree ->Delete("all");
6fdd30c4 303 }
304
305 //-------------------------------------------------------------------------------------
306 //Put the new clusters in the AOD list
307 //-------------------------------------------------------------------------------------
308
309 Int_t kNumberOfCaloClusters = fCaloClusterArr->GetEntries();
3fa4fb85 310 //Info("UserExec","New clusters %d",kNumberOfCaloClusters);
311 //if(nClustersOrg!=kNumberOfCaloClusters) Info("UserExec","Different number: Org %d, New %d\n",nClustersOrg,kNumberOfCaloClusters);
6fdd30c4 312 for(Int_t i = 0; i < kNumberOfCaloClusters; i++){
313 AliAODCaloCluster *newCluster = (AliAODCaloCluster *) fCaloClusterArr->At(i);
3fa4fb85 314 //if(Entry()==0) Info("UserExec","newCluster E %f\n", newCluster->E());
6fdd30c4 315 new((*fOutputAODBranch)[i]) AliAODCaloCluster(*newCluster);
316 }
317
318 //---CLEAN UP-----
319 fCaloClusterArr->Delete(); // Do not Clear(), it leaks, why?
3fa4fb85 320}
6fdd30c4 321
322//_____________________________________________________________________
323Bool_t AliAnalysisTaskEMCALClusterize::UserNotify()
324{
325 //Access to OCDB stuff
3fa4fb85 326 if(DebugLevel() > 1 )
327 Info("UserNotify()"," Begin");
6fdd30c4 328 AliVEvent * event = InputEvent();
329 if (event)
330 {
331 fGeom = AliEMCALGeometry::GetInstance(fGeomName);
332 AliCDBManager *cdb = AliCDBManager::Instance();
333 cdb->SetDefaultStorage(fOCDBpath.Data());
334 cdb->SetRun(event->GetRunNumber());
335 //
336 // EMCAL from RAW OCDB
337 if (fOCDBpath.Contains("alien:"))
338 {
339 cdb->SetSpecificStorage("EMCAL/Calib/Data","alien://Folder=/alice/data/2010/OCDB");
340 cdb->SetSpecificStorage("EMCAL/Calib/Pedestals","alien://Folder=/alice/data/2010/OCDB");
341 }
342 TString path = cdb->GetDefaultStorage()->GetBaseFolder();
343
344 // init parameters:
345 //Get calibration parameters
346 if(!fCalibData)
347 {
348 AliCDBEntry *entry = (AliCDBEntry*)
349 AliCDBManager::Instance()->Get("EMCAL/Calib/Data");
350 if (entry) fCalibData = (AliEMCALCalibData*) entry->GetObject();
351 }
352
353 if(!fCalibData)
354 AliFatal("Calibration parameters not found in CDB!");
355
356 //Get calibration parameters
357 if(!fPedestalData)
358 {
359 AliCDBEntry *entry = (AliCDBEntry*)
360 AliCDBManager::Instance()->Get("EMCAL/Calib/Pedestals");
361 if (entry) fPedestalData = (AliCaloCalibPedestal*) entry->GetObject();
362 }
363
364 if(!fPedestalData)
365 AliFatal("Dead map not found in CDB!");
366
367 // cout << "[i] Change of run number: " << fAOD->GetRunNumber() << endl;
368 InitClusterization();
6fdd30c4 369 }
370 else
371 {
3fa4fb85 372 Warning("UserNotify","Event not available!!!");
6fdd30c4 373 }
374
375 return kTRUE;
6fdd30c4 376}
377
378//________________________________________________________________________________________
379void AliAnalysisTaskEMCALClusterize::InitClusterization()
380{
381 //Select clusterization/unfolding algorithm and set all the needed parameters
382
383 if(!fJustUnfold){
384
385 //First init the clusterizer
386 if (fRecParam->GetClusterizerFlag() == AliEMCALRecParam::kClusterizerv1)
387 fClusterizer = new AliEMCALClusterizerv1 (fGeom, fCalibData, fPedestalData);
388 else if(fRecParam->GetClusterizerFlag() == AliEMCALRecParam::kClusterizerNxN)
389 fClusterizer = new AliEMCALClusterizerNxN(fGeom, fCalibData, fPedestalData);
390 else{
3fa4fb85 391 AliFatal(Form("Clusterizer < %d > not available", fRecParam->GetClusterizerFlag()));
6fdd30c4 392 }
393
394 //Now set the parameters
395 fClusterizer->SetECAClusteringThreshold( fRecParam->GetClusteringThreshold() );
396 fClusterizer->SetECALogWeight ( fRecParam->GetW0() );
397 fClusterizer->SetMinECut ( fRecParam->GetMinECut() );
398 fClusterizer->SetUnfolding ( fRecParam->GetUnfold() );
399 fClusterizer->SetECALocalMaxCut ( fRecParam->GetLocMaxCut() );
400 fClusterizer->SetTimeCut ( fRecParam->GetTimeCut() );
401 fClusterizer->SetTimeMin ( fRecParam->GetTimeMin() );
402 fClusterizer->SetTimeMax ( fRecParam->GetTimeMax() );
403 fClusterizer->SetInputCalibrated ( kTRUE );
404
405 //In case of unfolding after clusterization is requested, set the corresponding parameters
406 if(fRecParam->GetUnfold()){
407
408 Int_t i=0;
409 for (i = 0; i < 8; i++) {
410 fClusterizer->SetSSPars(i, fRecParam->GetSSPars(i));
411 }//end of loop over parameters
412 for (i = 0; i < 3; i++) {
413 fClusterizer->SetPar5 (i, fRecParam->GetPar5(i));
414 fClusterizer->SetPar6 (i, fRecParam->GetPar6(i));
415 }//end of loop over parameters
416
417 fClusterizer->InitClusterUnfolding();
418
419 }// to unfold
420
6fdd30c4 421 }else{
422 //Now init the unfolding afterburner
423 fUnfolder = new AliEMCALAfterBurnerUF(fRecParam->GetW0(),fRecParam->GetLocMaxCut());
424 }
425}
3fa4fb85 426
6fdd30c4 427//________________________________________________________________________________________
428void AliAnalysisTaskEMCALClusterize::RecPoints2Clusters(TClonesArray *digitsArr, TObjArray *recPoints, TObjArray *clusArray)
429{
430 // Restore clusters from recPoints
431 // Cluster energy, global position, cells and their amplitude fractions are restored
432
433 for(Int_t i = 0; i < recPoints->GetEntriesFast(); i++)
434 {
435 AliEMCALRecPoint *recPoint = (AliEMCALRecPoint*) recPoints->At(i);
436
437 const Int_t ncells = recPoint->GetMultiplicity();
438 Int_t ncells_true = 0;
439
440 // cells and their amplitude fractions
441 UShort_t absIds[ncells];
442 Double32_t ratios[ncells];
443
444 for (Int_t c = 0; c < ncells; c++) {
445 AliEMCALDigit *digit = (AliEMCALDigit*) digitsArr->At(recPoint->GetDigitsList()[c]);
446
447 absIds[ncells_true] = digit->GetId();
448 ratios[ncells_true] = recPoint->GetEnergiesList()[c]/digit->GetAmplitude();
449
450 if (ratios[ncells_true] > 0.001) ncells_true++;
451 }
452
453 if (ncells_true < 1) {
454 Warning("AliAnalysisTaskEMCALClusterize::RecPoints2Clusters", "skipping cluster with no cells");
455 continue;
456 }
457
458 TVector3 gpos;
459 Float_t g[3];
460
461 // calculate new cluster position
462 recPoint->EvalGlobalPosition(fRecParam->GetW0(), digitsArr);
463 recPoint->GetGlobalPosition(gpos);
464 gpos.GetXYZ(g);
465
466 // create a new cluster
467 AliAODCaloCluster *clus = new AliAODCaloCluster();
468 clus->SetType(AliVCluster::kEMCALClusterv1);
469 clus->SetE(recPoint->GetEnergy());
470 clus->SetPosition(g);
471 clus->SetNCells(ncells_true);
472 clus->SetCellsAbsId(absIds);
473 clus->SetCellsAmplitudeFraction(ratios);
474 clus->SetDispersion(recPoint->GetDispersion());
475 clus->SetChi2(-1); //not yet implemented
476 clus->SetTOF(recPoint->GetTime()) ; //time-of-fligh
477 clus->SetNExMax(recPoint->GetNExMax()); //number of local maxima
478 Float_t elipAxis[2];
479 recPoint->GetElipsAxis(elipAxis);
480 clus->SetM02(elipAxis[0]*elipAxis[0]) ;
481 clus->SetM20(elipAxis[1]*elipAxis[1]) ;
482
483 clusArray->Add(clus);
6fdd30c4 484 } // recPoints loop
6fdd30c4 485}