]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG4/CaloCalib/AliAnalysisTaskEMCALClusterize.cxx
Isolate only leading particles, and some cosmetics
[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"
5994e71f 32#include "TROOT.h"
33#include "TInterpreter.h"
1f77507b 34#include "TFile.h"
01313069 35//#include "string.h"
6fdd30c4 36
37// --- AliRoot Analysis Steering
38#include "AliAnalysisTask.h"
39#include "AliAnalysisManager.h"
40#include "AliESDEvent.h"
41#include "AliGeomManager.h"
42#include "AliVCaloCells.h"
43#include "AliAODCaloCluster.h"
44#include "AliCDBManager.h"
45#include "AliCDBStorage.h"
46#include "AliCDBEntry.h"
47#include "AliLog.h"
48#include "AliVEventHandler.h"
6060ed91 49#include "AliAODInputHandler.h"
6fdd30c4 50
51// --- EMCAL
52#include "AliEMCALRecParam.h"
53#include "AliEMCALAfterBurnerUF.h"
54#include "AliEMCALGeometry.h"
55#include "AliEMCALClusterizerNxN.h"
56#include "AliEMCALClusterizerv1.h"
cfcbe5d2 57#include "AliEMCALClusterizerv2.h"
6fdd30c4 58#include "AliEMCALRecPoint.h"
59#include "AliEMCALDigit.h"
60#include "AliCaloCalibPedestal.h"
61#include "AliEMCALCalibData.h"
385b7abf 62#include "AliEMCALRecoUtils.h"
6fdd30c4 63
64#include "AliAnalysisTaskEMCALClusterize.h"
65
66ClassImp(AliAnalysisTaskEMCALClusterize)
67
68//________________________________________________________________________
69AliAnalysisTaskEMCALClusterize::AliAnalysisTaskEMCALClusterize(const char *name)
70 : AliAnalysisTaskSE(name)
dd9a9f63 71 , fGeom(0), fGeomName("EMCAL_COMPLETEV1"), fGeomMatrixSet(kFALSE), fLoadGeomMatrices(kFALSE)
e9dd2d80 72 , fCalibData(0), fPedestalData(0), fOCDBpath("raw://"), fAccessOCDB(kFALSE)
6fdd30c4 73 , fDigitsArr(0), fClusterArr(0), fCaloClusterArr(0)
74 , fRecParam(0), fClusterizer(0), fUnfolder(0), fJustUnfold(kFALSE)
1f77507b 75 , fOutputAODBranch(0), fOutputAODBranchName("newEMCALClusters")
76 , fFillAODFile(kTRUE), fFillAODHeader(0), fFillAODCaloCells(0)
37d2296c 77 , fRun(-1), fRecoUtils(0), fConfigName("")
cb3001b9 78 , fCellLabels(), fCellSecondLabels(), fMaxEvent(1000000000), fDoTrackMatching(kFALSE)
6fdd30c4 79
80 {
81 //ctor
6060ed91 82 for(Int_t i = 0; i < 10; i++) fGeomMatrix[i] = 0;
37d2296c 83 for(Int_t j = 0; j < 24*48*11; j++) {
84 fCellLabels[j] = -1;
85 fCellSecondLabels[j] = -1;
86 }
6fdd30c4 87 fDigitsArr = new TClonesArray("AliEMCALDigit",200);
88 fClusterArr = new TObjArray(100);
89 fCaloClusterArr = new TObjArray(100);
90 fRecParam = new AliEMCALRecParam;
385b7abf 91 fBranchNames = "ESD:AliESDHeader.,EMCALCells.";
92 fRecoUtils = new AliEMCALRecoUtils();
6fdd30c4 93}
94
95//________________________________________________________________________
96AliAnalysisTaskEMCALClusterize::AliAnalysisTaskEMCALClusterize()
97 : AliAnalysisTaskSE("DefaultAnalysis_AliAnalysisTaskEMCALClusterize")
dd9a9f63 98 , fGeom(0), fGeomName("EMCAL_COMPLETEV1"), fGeomMatrixSet(kFALSE), fLoadGeomMatrices(kFALSE)
e9dd2d80 99 , fCalibData(0), fPedestalData(0), fOCDBpath("raw://"), fAccessOCDB(kFALSE)
1f77507b 100 , fDigitsArr(0), fClusterArr(0), fCaloClusterArr(0)
101 , fRecParam(0), fClusterizer(0), fUnfolder(0), fJustUnfold(kFALSE)
102 , fOutputAODBranch(0), fOutputAODBranchName("newEMCALClusters")
103 , fFillAODFile(kFALSE), fFillAODHeader(0), fFillAODCaloCells(0)
104 , fRun(-1), fRecoUtils(0), fConfigName("")
cb3001b9 105 , fCellLabels(), fCellSecondLabels(), fMaxEvent(1000000000), fDoTrackMatching(kFALSE)
6fdd30c4 106{
107 // Constructor
6060ed91 108 for(Int_t i = 0; i < 10; i++) fGeomMatrix[i] = 0;
37d2296c 109 for(Int_t j = 0; j < 24*48*11; j++) {
110 fCellLabels[j] = -1;
111 fCellSecondLabels[j] = -1;
112 }
6fdd30c4 113 fDigitsArr = new TClonesArray("AliEMCALDigit",200);
114 fClusterArr = new TObjArray(100);
115 fCaloClusterArr = new TObjArray(100);
116 fRecParam = new AliEMCALRecParam;
385b7abf 117 fBranchNames = "ESD:AliESDHeader.,EMCALCells.";
118 fRecoUtils = new AliEMCALRecoUtils();
6fdd30c4 119}
120
5994e71f 121
6fdd30c4 122//________________________________________________________________________
123AliAnalysisTaskEMCALClusterize::~AliAnalysisTaskEMCALClusterize()
124{
125 //dtor
126
127 if (fDigitsArr){
128 fDigitsArr->Clear("C");
542e1379 129 delete fDigitsArr;
6fdd30c4 130 }
131
132 if (fClusterArr){
133 fClusterArr->Delete();
542e1379 134 delete fClusterArr;
6fdd30c4 135 }
136
137 if (fCaloClusterArr){
138 fCaloClusterArr->Delete();
542e1379 139 delete fCaloClusterArr;
6fdd30c4 140 }
141
385b7abf 142 if(fClusterizer) delete fClusterizer;
143 if(fUnfolder) delete fUnfolder;
144 if(fRecoUtils) delete fRecoUtils;
145
6fdd30c4 146}
147
5994e71f 148//-------------------------------------------------------------------
149void AliAnalysisTaskEMCALClusterize::Init()
150{
151 //Init analysis with configuration macro if available
152
153 if(gROOT->LoadMacro(fConfigName) >=0){
154 printf("Configure analysis with %s\n",fConfigName.Data());
155 AliAnalysisTaskEMCALClusterize *clus = (AliAnalysisTaskEMCALClusterize*)gInterpreter->ProcessLine("ConfigEMCALClusterize()");
156 fGeomName = clus->fGeomName;
157 fLoadGeomMatrices = clus->fLoadGeomMatrices;
2ef5608f 158 fOCDBpath = clus->fOCDBpath;
159 fAccessOCDB = clus->fAccessOCDB;
5994e71f 160 fRecParam = clus->fRecParam;
161 fJustUnfold = clus->fJustUnfold;
162 fFillAODFile = clus->fFillAODFile;
163 fRecoUtils = clus->fRecoUtils;
164 fConfigName = clus->fConfigName;
2ef5608f 165 fMaxEvent = clus->fMaxEvent;
166 fDoTrackMatching = clus->fDoTrackMatching;
5994e71f 167 fOutputAODBranchName = clus->fOutputAODBranchName;
168 for(Int_t i = 0; i < 10; i++) fGeomMatrix[i] = clus->fGeomMatrix[i] ;
169
170 }
171
172}
173
6fdd30c4 174//-------------------------------------------------------------------
175void AliAnalysisTaskEMCALClusterize::UserCreateOutputObjects()
176{
177 // Init geometry, create list of output clusters
5994e71f 178
6fdd30c4 179 fGeom = AliEMCALGeometry::GetInstance(fGeomName) ;
1f77507b 180 if(fOutputAODBranchName.Length()!=0){
181 fOutputAODBranch = new TClonesArray("AliAODCaloCluster", 0);
182 fOutputAODBranch->SetName(fOutputAODBranchName);
183 AddAODBranch("TClonesArray", &fOutputAODBranch);
184 }
185 else {
186 AliFatal("fOutputAODBranchName not set\n");
187 }
188}
189
190//________________________________________________________________________
191void AliAnalysisTaskEMCALClusterize::FillAODCaloCells() {
192 // Put calo cells in standard branch
193 AliVEvent * event = InputEvent();
194 AliVCaloCells &eventEMcells = *(event->GetEMCALCells());
195 Int_t nEMcell = eventEMcells.GetNumberOfCells() ;
196
197 AliAODCaloCells &aodEMcells = *(AODEvent()->GetEMCALCells());
198 aodEMcells.CreateContainer(nEMcell);
199 aodEMcells.SetType(AliVCaloCells::kEMCALCell);
200 Double_t calibFactor = 1.;
201 for (Int_t iCell = 0; iCell < nEMcell; iCell++) {
202 Int_t imod = -1, iphi =-1, ieta=-1,iTower = -1, iIphi = -1, iIeta = -1;
203 fGeom->GetCellIndex(eventEMcells.GetCellNumber(iCell),imod,iTower,iIphi,iIeta);
204 fGeom->GetCellPhiEtaIndexInSModule(imod,iTower,iIphi, iIeta,iphi,ieta);
205
206 if(fRecoUtils->IsRecalibrationOn()){
207 calibFactor = fRecoUtils->GetEMCALChannelRecalibrationFactor(imod,ieta,iphi);
208 }
209
210 if(!fRecoUtils->GetEMCALChannelStatus(imod, ieta, iphi)){ //Channel is not declared as bad
211 aodEMcells.SetCell(iCell,eventEMcells.GetCellNumber(iCell),eventEMcells.GetAmplitude(iCell)*calibFactor);
212 //printf("GOOD channel\n");
213 }
214 else {
215 aodEMcells.SetCell(iCell,eventEMcells.GetCellNumber(iCell),0);
216 //printf("BAD channel\n");
217 }
218 }
219 aodEMcells.Sort();
220
221}
6fdd30c4 222
1f77507b 223//________________________________________________________________________
224void AliAnalysisTaskEMCALClusterize::FillAODHeader() {
225 //Put event header information in standard AOD branch
226
227 AliVEvent* event = InputEvent();
228 AliESDEvent* esdevent = dynamic_cast<AliESDEvent*> (event);
229 AliAODEvent* aodevent = dynamic_cast<AliAODEvent*> (event);
5994e71f 230
1f77507b 231 Double_t pos[3] ;
232 Double_t covVtx[6];
233 for (Int_t i = 0; i < 6; i++) covVtx[i] = 0.;
234
235 AliAODHeader* header = AODEvent()->GetHeader();
236 header->SetRunNumber(event->GetRunNumber());
237
238 if(esdevent){
239 TTree* tree = fInputHandler->GetTree();
240 if (tree) {
241 TFile* file = tree->GetCurrentFile();
242 if (file) header->SetESDFileName(file->GetName());
243 }
244 }
9a42b255 245 else if (aodevent) header->SetESDFileName(aodevent->GetHeader()->GetESDFileName());
1f77507b 246
247 header->SetBunchCrossNumber(event->GetBunchCrossNumber());
248 header->SetOrbitNumber(event->GetOrbitNumber());
249 header->SetPeriodNumber(event->GetPeriodNumber());
250 header->SetEventType(event->GetEventType());
251
252 //Centrality
253 if(event->GetCentrality()){
254 header->SetCentrality(new AliCentrality(*(event->GetCentrality())));
255 }
256 else{
257 header->SetCentrality(0);
258 }
259
260 //Trigger
261 header->SetOfflineTrigger(fInputHandler->IsEventSelected()); // propagate the decision of the physics selection
9a42b255 262 if (esdevent) header->SetFiredTriggerClasses(esdevent->GetFiredTriggerClasses());
263 else if (aodevent) header->SetFiredTriggerClasses(aodevent->GetFiredTriggerClasses());
1f77507b 264 header->SetTriggerMask(event->GetTriggerMask());
265 header->SetTriggerCluster(event->GetTriggerCluster());
266 if(esdevent){
267 header->SetL0TriggerInputs(esdevent->GetHeader()->GetL0TriggerInputs());
268 header->SetL1TriggerInputs(esdevent->GetHeader()->GetL1TriggerInputs());
269 header->SetL2TriggerInputs(esdevent->GetHeader()->GetL2TriggerInputs());
270 }
9a42b255 271 else if (aodevent){
1f77507b 272 header->SetL0TriggerInputs(aodevent->GetHeader()->GetL0TriggerInputs());
273 header->SetL1TriggerInputs(aodevent->GetHeader()->GetL1TriggerInputs());
274 header->SetL2TriggerInputs(aodevent->GetHeader()->GetL2TriggerInputs());
275 }
276
277 header->SetMagneticField(event->GetMagneticField());
278 //header->SetMuonMagFieldScale(esdevent->GetCurrentDip()/6000.);
279
280 header->SetZDCN1Energy(event->GetZDCN1Energy());
281 header->SetZDCP1Energy(event->GetZDCP1Energy());
282 header->SetZDCN2Energy(event->GetZDCN2Energy());
283 header->SetZDCP2Energy(event->GetZDCP2Energy());
284 header->SetZDCEMEnergy(event->GetZDCEMEnergy(0),event->GetZDCEMEnergy(1));
285
286 Float_t diamxy[2]={event->GetDiamondX(),event->GetDiamondY()};
287 Float_t diamcov[3];
288 event->GetDiamondCovXY(diamcov);
289 header->SetDiamond(diamxy,diamcov);
9a42b255 290 if (esdevent) header->SetDiamondZ(esdevent->GetDiamondZ(),esdevent->GetSigma2DiamondZ());
291 else if (aodevent) header->SetDiamondZ(aodevent->GetDiamondZ(),aodevent->GetSigma2DiamondZ());
1f77507b 292
293 //
294 //
295 Int_t nVertices = 1 ;/* = prim. vtx*/;
296 Int_t nCaloClus = event->GetNumberOfCaloClusters();
297
298 AODEvent()->ResetStd(0, nVertices, 0, 0, 0, nCaloClus, 0, 0);
299
300 // Access to the AOD container of vertices
301 TClonesArray &vertices = *(AODEvent()->GetVertices());
302 Int_t jVertices=0;
303
304 // Add primary vertex. The primary tracks will be defined
305 // after the loops on the composite objects (V0, cascades, kinks)
306 event->GetPrimaryVertex()->GetXYZ(pos);
307 Float_t chi = 0;
308 if (esdevent){
309 esdevent->GetPrimaryVertex()->GetCovMatrix(covVtx);
310 chi = esdevent->GetPrimaryVertex()->GetChi2toNDF();
311 }
312 else if (aodevent){
313 aodevent->GetPrimaryVertex()->GetCovMatrix(covVtx);
314 chi = aodevent->GetPrimaryVertex()->GetChi2perNDF();//Different from ESD?
315 }
316
317 AliAODVertex * primary = new(vertices[jVertices++])
318 AliAODVertex(pos, covVtx, chi, NULL, -1, AliAODVertex::kPrimary);
319 primary->SetName(event->GetPrimaryVertex()->GetName());
320 primary->SetTitle(event->GetPrimaryVertex()->GetTitle());
321
6fdd30c4 322}
323
324//________________________________________________________________________
325void AliAnalysisTaskEMCALClusterize::UserExec(Option_t *)
326{
327 // Main loop
328 // Called for each event
1f77507b 329
220447cd 330 AliAODInputHandler* aodIH = dynamic_cast<AliAODInputHandler*>((AliAnalysisManager::GetAnalysisManager())->GetInputEventHandler());
331 Int_t eventN = Entry();
332 if(aodIH) eventN = aodIH->GetReadEntry();
333
1f77507b 334 if (eventN > fMaxEvent) return;
c50e6949 335 //printf("Clusterizer --- Event %d-- \n",eventN);
1f77507b 336
6fdd30c4 337 //Remove the contents of output list set in the previous event
338 fOutputAODBranch->Clear("C");
339
1f77507b 340// if(fOutputAODBranchName.Length()!=0){
341// //Remove the contents of output list set in the previous event
342// fOutputAODBranch->Clear("C");
343// }
344// else{
345// //Reset and put new clusters in standard branch, also cells
346// AODEvent()->ResetStd(0, 1, 0, 0, 0, AODEvent()->GetNumberOfCaloClusters(), 0, 0);
347// fOutputAODBranch = AODEvent()->GetCaloClusters();// Put new clusters in standard branch
348// }
349
350 //Magic line to write events to AOD file
351 AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler()->SetFillAOD(fFillAODFile);
352 LoadBranches();
353
1f77507b 354
e9dd2d80 355 //Init pointers, clusterizer, ocdb
356 if(fAccessOCDB) AccessOCDB();
357 InitClusterization();
358
6060ed91 359 //Get the event
360 AliVEvent * event = 0;
361 AliESDEvent * esdevent = 0;
1f77507b 362
363 //Fill output event with headerø
364
6060ed91 365 //Check if input event are embedded events
366 //If so, take output event
6060ed91 367 if (aodIH && aodIH->GetMergeEvents()) {
e9dd2d80 368 //printf("AliAnalysisTaskEMCALClusterize::UserExec() - Use embedded events\n");
6060ed91 369 event = AODEvent();
1f77507b 370
371 if(!aodIH->GetMergeEMCALCells())
372 AliFatal("Events merged but not EMCAL cells, check analysis settings!");
373
6060ed91 374// printf("InputEvent N Clusters %d, N Cells %d\n",InputEvent()->GetNumberOfCaloClusters(),
375// InputEvent()->GetEMCALCells()->GetNumberOfCells());
1f77507b 376// printf("MergedEvent N Clusters %d, N Cells %d\n",aodIH->GetEventToMerge()->GetNumberOfCaloClusters(),
377// aodIH->GetEventToMerge()->GetEMCALCells()->GetNumberOfCells());
220447cd 378// for (Int_t icl=0; icl < aodIH->GetEventToMerge()->GetNumberOfCaloClusters(); icl++) {
379// AliAODCaloCluster *sigCluster = aodIH->GetEventToMerge()->GetCaloCluster(icl);
380// if(sigCluster->IsEMCAL()) printf("Signal cluster: i %d, E %f\n",icl,sigCluster->E());
381// }
6060ed91 382// printf("OutputEvent N Clusters %d, N Cells %d\n", AODEvent()->GetNumberOfCaloClusters(),
383// AODEvent()->GetEMCALCells()->GetNumberOfCells());
1f77507b 384
6060ed91 385 }
386 else {
387 event = InputEvent();
388 esdevent = dynamic_cast<AliESDEvent*>(InputEvent());
1f77507b 389 if(fFillAODCaloCells) FillAODCaloCells();
390 if(fFillAODHeader) FillAODHeader();
6060ed91 391 }
392
6fdd30c4 393 if (!event) {
3fa4fb85 394 Error("UserExec","Event not available");
6fdd30c4 395 return;
396 }
3fa4fb85 397
6fdd30c4 398 //-------------------------------------------------------------------------------------
399 //Set the geometry matrix, for the first event, skip the rest
400 //-------------------------------------------------------------------------------------
401 if(!fGeomMatrixSet){
402 if(fLoadGeomMatrices){
403 for(Int_t mod=0; mod < (fGeom->GetEMCGeometry())->GetNumberOfSuperModules(); mod++){
404 if(fGeomMatrix[mod]){
405 if(DebugLevel() > 1)
406 fGeomMatrix[mod]->Print();
407 fGeom->SetMisalMatrix(fGeomMatrix[mod],mod) ;
408 }
409 fGeomMatrixSet=kTRUE;
410 }//SM loop
411 }//Load matrices
412 else if(!gGeoManager){
3fa4fb85 413 Info("UserExec","Get geo matrices from data");
6fdd30c4 414 //Still not implemented in AOD, just a workaround to be able to work at least with ESDs
415 if(!strcmp(event->GetName(),"AliAODEvent")) {
416 if(DebugLevel() > 1)
3fa4fb85 417 Warning("UserExec","Use ideal geometry, values geometry matrix not kept in AODs.");
6fdd30c4 418 }//AOD
419 else {
3fa4fb85 420 if(DebugLevel() > 1)
421 Info("UserExec","AliAnalysisTaskEMCALClusterize Load Misaligned matrices.");
6fdd30c4 422 AliESDEvent* esd = dynamic_cast<AliESDEvent*>(event) ;
423 if(!esd) {
3fa4fb85 424 Error("UserExec","This event does not contain ESDs?");
6fdd30c4 425 return;
426 }
427 for(Int_t mod=0; mod < (fGeom->GetEMCGeometry())->GetNumberOfSuperModules(); mod++){
428 if(DebugLevel() > 1)
429 esd->GetEMCALMatrix(mod)->Print();
430 if(esd->GetEMCALMatrix(mod)) fGeom->SetMisalMatrix(esd->GetEMCALMatrix(mod),mod) ;
431 }
432 fGeomMatrixSet=kTRUE;
433 }//ESD
434 }//Load matrices from Data
5994e71f 435
436 //Recover time dependent corrections, put then in recalibration histograms. Do it once
437 fRecoUtils->SetTimeDependentCorrections(InputEvent()->GetRunNumber());
438
6fdd30c4 439 }//first event
440
441 //Get the list of cells needed for unfolding and reclustering
442 AliVCaloCells *cells= event->GetEMCALCells();
443 Int_t nClustersOrg = 0;
444 //-------------------------------------------
445 //---------Unfolding clusters----------------
446 //-------------------------------------------
447 if (fJustUnfold) {
448
449 //Fill the array with the EMCAL clusters, copy them
450 for (Int_t i = 0; i < event->GetNumberOfCaloClusters(); i++)
451 {
452 AliVCluster *clus = event->GetCaloCluster(i);
453 if(clus->IsEMCAL()){
3fa4fb85 454 //printf("Org Cluster %d, E %f\n",i, clus->E());
5994e71f 455
456 //recalibrate/remove bad channels/etc if requested
457 if(fRecoUtils->ClusterContainsBadChannel(fGeom,clus->GetCellsAbsId(), clus->GetNCells())){
458 //printf("Remove cluster\n");
459 continue;
460 }
461
462 if(fRecoUtils->IsRecalibrationOn()){
463 //printf("Energy before %f ",clus->E());
464 fRecoUtils->RecalibrateClusterEnergy(fGeom, clus, cells);
465 //printf("; after %f\n",clus->E());
466 }
467 //Cast to ESD or AOD, needed to create the cluster array
e615d952 468 AliESDCaloCluster * esdCluster = dynamic_cast<AliESDCaloCluster*> (clus);
469 AliAODCaloCluster * aodCluster = dynamic_cast<AliAODCaloCluster*> (clus);
470 if (esdCluster){
471 fCaloClusterArr->Add( new AliESDCaloCluster(*esdCluster) );
6fdd30c4 472 }//ESD
e615d952 473 else if(aodCluster){
474 fCaloClusterArr->Add( new AliAODCaloCluster(*aodCluster) );
6fdd30c4 475 }//AOD
3fa4fb85 476 else
477 Warning("UserExec()"," - Wrong CaloCluster type?");
6fdd30c4 478 nClustersOrg++;
479 }
480 }
481
482 //Do the unfolding
483 fUnfolder->UnfoldClusters(fCaloClusterArr, cells);
484
485 //CLEAN-UP
486 fUnfolder->Clear();
487
5994e71f 488
6fdd30c4 489 //printf("nClustersOrg %d\n",nClustersOrg);
490 }
491 //-------------------------------------------
492 //---------- Recluster cells ----------------
493 //-------------------------------------------
494
495 else{
496 //-------------------------------------------------------------------------------------
497 //Transform CaloCells into Digits
498 //-------------------------------------------------------------------------------------
6060ed91 499
500 //In case of MC, first loop on the clusters and fill MC label to array
501 //.....................................................................
502
c50e6949 503// for(Int_t j = 0; j < 24*48*11; j++) {
504// if(fCellLabels[j] !=-1) printf("Not well initialized cell %d, label1 %d\n",j,fCellLabels[j] ) ;
505// if(fCellSecondLabels[j]!=-1) printf("Not well initialized cell %d, label2 %d\n",j,fCellSecondLabels[j]) ;
506// }
6060ed91 507
1f77507b 508 Int_t nClusters = event->GetNumberOfCaloClusters();
006e9636 509 if(aodIH && aodIH->GetEventToMerge()) //Embedding
1f77507b 510 nClusters = aodIH->GetEventToMerge()->GetNumberOfCaloClusters(); //Get clusters directly from embedded signal
511 for (Int_t i = 0; i < nClusters; i++)
6060ed91 512 {
1f77507b 513 AliVCluster *clus = 0;
006e9636 514 if(aodIH && aodIH->GetEventToMerge()) //Embedding
515 clus = aodIH->GetEventToMerge()->GetCaloCluster(i); //Get clusters directly from embedded signal
516 else
517 clus = event->GetCaloCluster(i);
1f77507b 518
519 if(!clus) {
520 printf("AliEMCALReclusterize::UserExec() - No Clusters\n");
521 return;
522 }
523
6060ed91 524 if(clus->IsEMCAL()){
1f77507b 525 //printf("Cluster Signal %d, energy %f\n",clus->GetID(),clus->E());
6060ed91 526 Int_t label = clus->GetLabel();
1f77507b 527 Int_t label2 = -1 ;
528 if (clus->GetNLabels()>=2) label2 = clus->GetLabelAt(1) ;
6060ed91 529 UShort_t * index = clus->GetCellsAbsId() ;
530 for(Int_t icell=0; icell < clus->GetNCells(); icell++ ){
220447cd 531 fCellLabels[index[icell]] =label;
1f77507b 532 fCellSecondLabels[index[icell]]=label2;
abf0860a 533 //printf("1) absID %d, label[0] %d label[1] %d\n",index[icell], fCellLabels[index[icell]],fCellSecondLabels[index[icell]]);
6060ed91 534 }
535 nClustersOrg++;
536 }
537 }
1f77507b 538
6060ed91 539 // Create digits
540 //.................
6fdd30c4 541 Int_t idigit = 0;
542 Int_t id = -1;
543 Float_t amp = -1;
544 Float_t time = -1;
545
546 Double_t cellAmplitude = 0;
547 Double_t cellTime = 0;
548 Short_t cellNumber = 0;
549
550 TTree *digitsTree = new TTree("digitstree","digitstree");
551 digitsTree->Branch("EMCAL","TClonesArray", &fDigitsArr, 32000);
552
6060ed91 553
6fdd30c4 554 for (Int_t icell = 0; icell < cells->GetNumberOfCells(); icell++)
555 {
556 if (cells->GetCell(icell, cellNumber, cellAmplitude, cellTime) != kTRUE)
557 break;
558
559 time = cellTime;
560 amp = cellAmplitude;
561 id = cellNumber;
562
5994e71f 563 Int_t imod = -1, iphi =-1, ieta=-1,iTower = -1, iIphi = -1, iIeta = -1;
564 fGeom->GetCellIndex(id,imod,iTower,iIphi,iIeta);
565 fGeom->GetCellPhiEtaIndexInSModule(imod,iTower,iIphi, iIeta,iphi,ieta);
566
567 //Do not include bad channels found in analysis?
568 if( fRecoUtils->IsBadChannelsRemovalSwitchedOn() &&
569 fRecoUtils->GetEMCALChannelStatus(imod, ieta, iphi)){
220447cd 570 fCellLabels[id] =-1; //reset the entry in the array for next event
571 fCellSecondLabels[id]=-1; //reset the entry in the array for next event
5994e71f 572 //printf("Remove channel %d\n",id);
573 continue;
574 }
575
576 //Recalibrate?
577 if(fRecoUtils->IsRecalibrationOn()){
578 //printf("CalibFactor %f times %f for id %d\n",fRecoUtils->GetEMCALChannelRecalibrationFactor(imod,ieta,iphi),amp,id);
579 amp *=fRecoUtils->GetEMCALChannelRecalibrationFactor(imod,ieta,iphi);
580 }
581
6060ed91 582 //Create the digit, put a fake primary deposited energy to trick the clusterizer when checking the most likely primary
583 new((*fDigitsArr)[idigit]) AliEMCALDigit( fCellLabels[id], fCellLabels[id],id, amp, time,AliEMCALDigit::kHG,idigit, 0, 0, 1);
584 //if(fCellLabels[id]>=0)printf("2) Digit cell %d, label %d\n",id,fCellLabels[id]) ;
585 //else printf("2) Digit cell %d, no label, amp %f \n",id,amp) ;
220447cd 586 fCellLabels[id] =-1; //reset the entry in the array for next event
220447cd 587
6060ed91 588 //AliEMCALDigit *digit = (AliEMCALDigit*) fDigitsArr->New(idigit);
589 //digit->SetId(id);
590 //digit->SetAmplitude(amp);
591 //digit->SetTime(time);
592 //digit->SetTimeR(time);
593 //digit->SetIndexInList(idigit);
594 //digit->SetType(AliEMCALDigit::kHG);
5994e71f 595
596 //printf("Digit: Id %d, amp %f, time %e, index %d\n",id, amp,time,idigit);
6fdd30c4 597 idigit++;
598 }
599
600 //Fill the tree with digits
601 digitsTree->Fill();
602
603 //-------------------------------------------------------------------------------------
604 //Do the clusterization
605 //-------------------------------------------------------------------------------------
606 TTree *clustersTree = new TTree("clustertree","clustertree");
3fa4fb85 607
6fdd30c4 608 fClusterizer->SetInput(digitsTree);
609 fClusterizer->SetOutput(clustersTree);
610 fClusterizer->Digits2Clusters("");
6060ed91 611
6fdd30c4 612 //-------------------------------------------------------------------------------------
613 //Transform the recpoints into AliVClusters
614 //-------------------------------------------------------------------------------------
615
616 clustersTree->SetBranchStatus("*",0); //disable all branches
617 clustersTree->SetBranchStatus("EMCALECARP",1); //Enable only the branch we need
618
619 TBranch *branch = clustersTree->GetBranch("EMCALECARP");
620 branch->SetAddress(&fClusterArr);
621 branch->GetEntry(0);
dd9a9f63 622 if(fCaloClusterArr->GetEntriesFast() > 0) {
623 printf("AliAnalysisTaskEMCALClusterize::UserExec() Non empty cluster array before filling!!!");
624 }
6fdd30c4 625 RecPoints2Clusters(fDigitsArr, fClusterArr, fCaloClusterArr);
626
01313069 627 //Reset the array with second labels for this event
628 memset(fCellSecondLabels, -1, sizeof(fCellSecondLabels));
629
6fdd30c4 630 //---CLEAN UP-----
631 fClusterizer->Clear();
632 fDigitsArr ->Clear("C");
633 fClusterArr ->Delete(); // Do not Clear(), it leaks, why?
634
635 clustersTree->Delete("all");
636 digitsTree ->Delete("all");
6fdd30c4 637 }
638
385b7abf 639 //Recalculate track-matching for the new clusters, only with ESDs
cb3001b9 640 if(fDoTrackMatching) fRecoUtils->FindMatches(event,fCaloClusterArr,fGeom);
385b7abf 641
642
6fdd30c4 643 //-------------------------------------------------------------------------------------
644 //Put the new clusters in the AOD list
645 //-------------------------------------------------------------------------------------
646
dd9a9f63 647 Int_t kNumberOfCaloClusters = fCaloClusterArr->GetEntriesFast();
6060ed91 648 //printf("New clusters %d, Org clusters %d\n",kNumberOfCaloClusters, nClustersOrg);
6fdd30c4 649 for(Int_t i = 0; i < kNumberOfCaloClusters; i++){
650 AliAODCaloCluster *newCluster = (AliAODCaloCluster *) fCaloClusterArr->At(i);
3fa4fb85 651 //if(Entry()==0) Info("UserExec","newCluster E %f\n", newCluster->E());
385b7abf 652
653 //Add matched track, if any, only with ESDs
cb3001b9 654 if(esdevent && fDoTrackMatching){
385b7abf 655 Int_t trackIndex = fRecoUtils->GetMatchedTrackIndex(i);
656 if(trackIndex >= 0){
657 newCluster->AddTrackMatched(event->GetTrack(trackIndex));
658 if(DebugLevel() > 1)
659 Info("UserExec","Matched Track index %d to new cluster %d \n",trackIndex,i);
660 }
661 }
0821ba9f 662
5994e71f 663 //In case of new bad channels, recalculate distance to bad channels
664 if(fRecoUtils->IsBadChannelsRemovalSwitchedOn()){
665 //printf("DistToBad before %f ",newCluster->GetDistanceToBadChannel());
666 fRecoUtils->RecalculateClusterDistanceToBadChannel(fGeom, event->GetEMCALCells(), newCluster);
667 //printf("; after %f \n",newCluster->GetDistanceToBadChannel());
668 }
669
6060ed91 670// if(newCluster->GetNLabels()>0){
671// printf("3) MC: N labels %d, label %d ; ", newCluster->GetNLabels(), newCluster->GetLabel() );
672// UShort_t * newindex = newCluster->GetCellsAbsId() ;
673// for(Int_t icell=0; icell < newCluster->GetNCells(); icell++ ){
674// printf("\t absID %d\n",newindex[icell]);
675// }
676// }
1f77507b 677
abf0860a 678// printf("Cluster %d, energy %f\n",newCluster->GetID(),newCluster->E());
679// printf("labels: ");
680// for(UInt_t ilab = 0; ilab < newCluster->GetNLabels(); ilab++)
681// printf("Label[%d]: %d ",ilab, newCluster->GetLabelAt(ilab));
682// printf("\n ");
6060ed91 683
0821ba9f 684 newCluster->SetID(i);
6fdd30c4 685 new((*fOutputAODBranch)[i]) AliAODCaloCluster(*newCluster);
686 }
687
1f77507b 688 //if(fOutputAODBranchName.Length()!=0)
689 fOutputAODBranch->Expand(kNumberOfCaloClusters); // resize TObjArray to 'remove' slots
690
6fdd30c4 691 //---CLEAN UP-----
692 fCaloClusterArr->Delete(); // Do not Clear(), it leaks, why?
3fa4fb85 693}
6fdd30c4 694
695//_____________________________________________________________________
bd9e8ebd 696Bool_t AliAnalysisTaskEMCALClusterize::AccessOCDB()
6fdd30c4 697{
698 //Access to OCDB stuff
e9dd2d80 699
6fdd30c4 700 AliVEvent * event = InputEvent();
bd9e8ebd 701 if (!event)
6fdd30c4 702 {
385b7abf 703 Warning("AccessOCDB","Event not available!!!");
bd9e8ebd 704 return kFALSE;
705 }
e9dd2d80 706
bd9e8ebd 707 if (event->GetRunNumber()==fRun)
708 return kTRUE;
709 fRun = event->GetRunNumber();
e9dd2d80 710
bd9e8ebd 711 if(DebugLevel() > 1 )
712 Info("AccessODCD()"," Begin");
385b7abf 713
e9dd2d80 714 //fGeom = AliEMCALGeometry::GetInstance(fGeomName);
385b7abf 715
bd9e8ebd 716 AliCDBManager *cdb = AliCDBManager::Instance();
e9dd2d80 717
718
385b7abf 719 if (fOCDBpath.Length()){
6fdd30c4 720 cdb->SetDefaultStorage(fOCDBpath.Data());
385b7abf 721 Info("AccessOCDB","Default storage %s",fOCDBpath.Data());
722 }
723
bd9e8ebd 724 cdb->SetRun(event->GetRunNumber());
e9dd2d80 725
bd9e8ebd 726 //
727 // EMCAL from RAW OCDB
728 if (fOCDBpath.Contains("alien:"))
729 {
730 cdb->SetSpecificStorage("EMCAL/Calib/Data","alien://Folder=/alice/data/2010/OCDB");
731 cdb->SetSpecificStorage("EMCAL/Calib/Pedestals","alien://Folder=/alice/data/2010/OCDB");
732 }
e9dd2d80 733
bd9e8ebd 734 TString path = cdb->GetDefaultStorage()->GetBaseFolder();
385b7abf 735
bd9e8ebd 736 // init parameters:
385b7abf 737
bd9e8ebd 738 //Get calibration parameters
739 if(!fCalibData)
740 {
741 AliCDBEntry *entry = (AliCDBEntry*)
e9dd2d80 742 AliCDBManager::Instance()->Get("EMCAL/Calib/Data");
385b7abf 743
bd9e8ebd 744 if (entry) fCalibData = (AliEMCALCalibData*) entry->GetObject();
6fdd30c4 745 }
bd9e8ebd 746
747 if(!fCalibData)
748 AliFatal("Calibration parameters not found in CDB!");
e9dd2d80 749
bd9e8ebd 750 //Get calibration parameters
751 if(!fPedestalData)
6fdd30c4 752 {
bd9e8ebd 753 AliCDBEntry *entry = (AliCDBEntry*)
e9dd2d80 754 AliCDBManager::Instance()->Get("EMCAL/Calib/Pedestals");
385b7abf 755
bd9e8ebd 756 if (entry) fPedestalData = (AliCaloCalibPedestal*) entry->GetObject();
6fdd30c4 757 }
e9dd2d80 758
bd9e8ebd 759 if(!fPedestalData)
760 AliFatal("Dead map not found in CDB!");
385b7abf 761
6fdd30c4 762 return kTRUE;
6fdd30c4 763}
764
765//________________________________________________________________________________________
766void AliAnalysisTaskEMCALClusterize::InitClusterization()
767{
768 //Select clusterization/unfolding algorithm and set all the needed parameters
769
bd9e8ebd 770 if (fJustUnfold){
771 // init the unfolding afterburner
772 delete fUnfolder;
773 fUnfolder = new AliEMCALAfterBurnerUF(fRecParam->GetW0(),fRecParam->GetLocMaxCut());
774 return;
775 }
776
777 //First init the clusterizer
778 delete fClusterizer;
779 if (fRecParam->GetClusterizerFlag() == AliEMCALRecParam::kClusterizerv1)
780 fClusterizer = new AliEMCALClusterizerv1 (fGeom, fCalibData, fPedestalData);
cfcbe5d2 781 else if(fRecParam->GetClusterizerFlag() == AliEMCALRecParam::kClusterizerv2)
782 fClusterizer = new AliEMCALClusterizerv2(fGeom, fCalibData, fPedestalData);
bd9e8ebd 783 else if(fRecParam->GetClusterizerFlag() == AliEMCALRecParam::kClusterizerNxN)
784 fClusterizer = new AliEMCALClusterizerNxN(fGeom, fCalibData, fPedestalData);
cfcbe5d2 785 else if(fRecParam->GetClusterizerFlag() > AliEMCALRecParam::kClusterizerv2) { //FIX this other way.
bd9e8ebd 786 AliEMCALClusterizerNxN *clusterizer = new AliEMCALClusterizerNxN(fGeom, fCalibData, fPedestalData);
787 clusterizer->SetNRowDiff(2);
788 clusterizer->SetNColDiff(2);
789 fClusterizer = clusterizer;
790 } else{
791 AliFatal(Form("Clusterizer < %d > not available", fRecParam->GetClusterizerFlag()));
792 }
6fdd30c4 793
bd9e8ebd 794 //Now set the parameters
795 fClusterizer->SetECAClusteringThreshold( fRecParam->GetClusteringThreshold() );
796 fClusterizer->SetECALogWeight ( fRecParam->GetW0() );
797 fClusterizer->SetMinECut ( fRecParam->GetMinECut() );
798 fClusterizer->SetUnfolding ( fRecParam->GetUnfold() );
799 fClusterizer->SetECALocalMaxCut ( fRecParam->GetLocMaxCut() );
800 fClusterizer->SetTimeCut ( fRecParam->GetTimeCut() );
801 fClusterizer->SetTimeMin ( fRecParam->GetTimeMin() );
802 fClusterizer->SetTimeMax ( fRecParam->GetTimeMax() );
803 fClusterizer->SetInputCalibrated ( kTRUE );
2af35150 804 fClusterizer->SetJustClusters ( kTRUE );
bd9e8ebd 805 //In case of unfolding after clusterization is requested, set the corresponding parameters
806 if(fRecParam->GetUnfold()){
807 Int_t i=0;
808 for (i = 0; i < 8; i++) {
809 fClusterizer->SetSSPars(i, fRecParam->GetSSPars(i));
810 }//end of loop over parameters
811 for (i = 0; i < 3; i++) {
812 fClusterizer->SetPar5 (i, fRecParam->GetPar5(i));
813 fClusterizer->SetPar6 (i, fRecParam->GetPar6(i));
814 }//end of loop over parameters
6fdd30c4 815
bd9e8ebd 816 fClusterizer->InitClusterUnfolding();
817 }// to unfold
6fdd30c4 818}
3fa4fb85 819
6fdd30c4 820//________________________________________________________________________________________
821void AliAnalysisTaskEMCALClusterize::RecPoints2Clusters(TClonesArray *digitsArr, TObjArray *recPoints, TObjArray *clusArray)
822{
823 // Restore clusters from recPoints
824 // Cluster energy, global position, cells and their amplitude fractions are restored
937b6c91 825
6fdd30c4 826 for(Int_t i = 0; i < recPoints->GetEntriesFast(); i++)
827 {
828 AliEMCALRecPoint *recPoint = (AliEMCALRecPoint*) recPoints->At(i);
829
830 const Int_t ncells = recPoint->GetMultiplicity();
831 Int_t ncells_true = 0;
832
833 // cells and their amplitude fractions
834 UShort_t absIds[ncells];
835 Double32_t ratios[ncells];
836
837 for (Int_t c = 0; c < ncells; c++) {
838 AliEMCALDigit *digit = (AliEMCALDigit*) digitsArr->At(recPoint->GetDigitsList()[c]);
839
840 absIds[ncells_true] = digit->GetId();
841 ratios[ncells_true] = recPoint->GetEnergiesList()[c]/digit->GetAmplitude();
842
843 if (ratios[ncells_true] > 0.001) ncells_true++;
844 }
845
846 if (ncells_true < 1) {
847 Warning("AliAnalysisTaskEMCALClusterize::RecPoints2Clusters", "skipping cluster with no cells");
848 continue;
849 }
850
851 TVector3 gpos;
852 Float_t g[3];
853
854 // calculate new cluster position
855 recPoint->EvalGlobalPosition(fRecParam->GetW0(), digitsArr);
856 recPoint->GetGlobalPosition(gpos);
857 gpos.GetXYZ(g);
858
859 // create a new cluster
937b6c91 860 //AliAODCaloCluster *clus = new AliAODCaloCluster();
861
862 (*clusArray)[i] = new AliAODCaloCluster() ;
863 AliAODCaloCluster *clus = dynamic_cast<AliAODCaloCluster *>( clusArray->At(i) ) ;
6fdd30c4 864 clus->SetType(AliVCluster::kEMCALClusterv1);
865 clus->SetE(recPoint->GetEnergy());
866 clus->SetPosition(g);
867 clus->SetNCells(ncells_true);
868 clus->SetCellsAbsId(absIds);
869 clus->SetCellsAmplitudeFraction(ratios);
870 clus->SetDispersion(recPoint->GetDispersion());
871 clus->SetChi2(-1); //not yet implemented
bd9e8ebd 872 clus->SetTOF(recPoint->GetTime()) ; //time-of-flight
6fdd30c4 873 clus->SetNExMax(recPoint->GetNExMax()); //number of local maxima
874 Float_t elipAxis[2];
875 recPoint->GetElipsAxis(elipAxis);
876 clus->SetM02(elipAxis[0]*elipAxis[0]) ;
877 clus->SetM20(elipAxis[1]*elipAxis[1]) ;
5994e71f 878 clus->SetDistanceToBadChannel(recPoint->GetDistanceToBadTower());
6060ed91 879
880 //MC
881 Int_t parentMult = 0;
882 Int_t *parentList = recPoint->GetParents(parentMult);
883 clus->SetLabel(parentList, parentMult);
884
220447cd 885// if(parentMult)printf("RecToESD: Labels %d",parentMult);
886// for (Int_t iii = 0; iii < parentMult; iii++) {
887// printf("\t label %d\n",parentList[iii]);
888// }
37d2296c 889 //Write the second major contributor to each MC cluster.
890 Int_t iNewLabel ;
891 for ( Int_t iLoopCell = 0 ; iLoopCell < clus->GetNCells() ; iLoopCell++ ){
892
893 Int_t idCell = clus->GetCellAbsId(iLoopCell) ;
6ffa213f 894 if(idCell>=0){
895 iNewLabel = 1 ; //iNewLabel makes sure we don't write twice the same label.
896 for ( UInt_t iLoopLabels = 0 ; iLoopLabels < clus->GetNLabels() ; iLoopLabels++ )
897 {
898 if ( fCellSecondLabels[idCell] == -1 ) iNewLabel = 0; // -1 is never a good second label.
899 if ( fCellSecondLabels[idCell] == clus->GetLabelAt(iLoopLabels) ) iNewLabel = 0;
900 }
901 if (iNewLabel == 1)
902 {
937b6c91 903 //Int_t * newLabelArray = (Int_t*)malloc((clus->GetNLabels()+1)*sizeof(Int_t)) ;
904 Int_t * newLabelArray = new Int_t[clus->GetNLabels()+1] ;
6ffa213f 905 for ( UInt_t iLoopNewLabels = 0 ; iLoopNewLabels < clus->GetNLabels() ; iLoopNewLabels++ ){
906 newLabelArray[iLoopNewLabels] = clus->GetLabelAt(iLoopNewLabels) ;
907 }
abf0860a 908
6ffa213f 909 newLabelArray[clus->GetNLabels()] = fCellSecondLabels[idCell] ;
220447cd 910 //if(fCellSecondLabels[idCell]>-1)printf("\t new label %d\n",fCellSecondLabels[idCell]);
6ffa213f 911 clus->SetLabel(newLabelArray,clus->GetNLabels()+1) ;
abf0860a 912 delete [] newLabelArray;
6ffa213f 913 }
914 }//positive cell number
37d2296c 915 }
916
937b6c91 917 //clusArray->Add(clus);
918
6fdd30c4 919 } // recPoints loop
6fdd30c4 920}