1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
17 //_________________________________________________________________________
18 // This analysis provides a new list of clusters to be used in other analysis
20 // Author: Gustavo Conesa Balbastre,
21 // Adapted from analysis class from Deepa Thomas
24 //_________________________________________________________________________
28 #include "TRefArray.h"
29 #include "TClonesArray.h"
31 #include "TGeoManager.h"
33 #include "TInterpreter.h"
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"
48 #include "AliVEventHandler.h"
49 #include "AliAODInputHandler.h"
52 #include "AliEMCALRecParam.h"
53 #include "AliEMCALAfterBurnerUF.h"
54 #include "AliEMCALGeometry.h"
55 #include "AliEMCALClusterizerNxN.h"
56 #include "AliEMCALClusterizerv1.h"
57 #include "AliEMCALClusterizerv2.h"
58 #include "AliEMCALRecPoint.h"
59 #include "AliEMCALDigit.h"
60 #include "AliCaloCalibPedestal.h"
61 #include "AliEMCALCalibData.h"
62 #include "AliEMCALRecoUtils.h"
64 #include "AliAnalysisTaskEMCALClusterize.h"
66 ClassImp(AliAnalysisTaskEMCALClusterize)
68 //________________________________________________________________________
69 AliAnalysisTaskEMCALClusterize::AliAnalysisTaskEMCALClusterize(const char *name)
70 : AliAnalysisTaskSE(name)
71 , fGeom(0), fGeomName("EMCAL_COMPLETEV1"), fGeomMatrixSet(kFALSE), fLoadGeomMatrices(kFALSE)
72 , fCalibData(0), fPedestalData(0), fOCDBpath("raw://"), fAccessOCDB(kFALSE)
73 , fDigitsArr(0), fClusterArr(0), fCaloClusterArr(0)
74 , fRecParam(0), fClusterizer(0), fUnfolder(0), fJustUnfold(kFALSE)
75 , fOutputAODBranch(0), fOutputAODBranchName("newEMCALClusters")
76 , fFillAODFile(kTRUE), fFillAODHeader(0), fFillAODCaloCells(0)
77 , fRun(-1), fRecoUtils(0), fConfigName("")
78 , fCellLabels(), fCellSecondLabels(), fCellTime()
79 , fMaxEvent(1000000000), fDoTrackMatching(kFALSE)
80 , fSelectCell(kFALSE), fSelectCellMinE(0.005), fSelectCellMinFrac(0.001)
83 for(Int_t i = 0; i < 10; i++) fGeomMatrix[i] = 0;
84 for(Int_t j = 0; j < 24*48*11; j++) {
86 fCellSecondLabels[j] = -1;
90 fDigitsArr = new TClonesArray("AliEMCALDigit",200);
91 fClusterArr = new TObjArray(100);
92 fCaloClusterArr = new TObjArray(1000);
93 fRecParam = new AliEMCALRecParam;
94 fBranchNames = "ESD:AliESDHeader.,EMCALCells.";
95 fRecoUtils = new AliEMCALRecoUtils();
99 //________________________________________________________________________
100 AliAnalysisTaskEMCALClusterize::AliAnalysisTaskEMCALClusterize()
101 : AliAnalysisTaskSE("DefaultAnalysis_AliAnalysisTaskEMCALClusterize")
102 , fGeom(0), fGeomName("EMCAL_COMPLETEV1"), fGeomMatrixSet(kFALSE), fLoadGeomMatrices(kFALSE)
103 , fCalibData(0), fPedestalData(0), fOCDBpath("raw://"), fAccessOCDB(kFALSE)
104 , fDigitsArr(0), fClusterArr(0), fCaloClusterArr(0)
105 , fRecParam(0), fClusterizer(0), fUnfolder(0), fJustUnfold(kFALSE)
106 , fOutputAODBranch(0), fOutputAODBranchName("newEMCALClusters")
107 , fFillAODFile(kFALSE), fFillAODHeader(0), fFillAODCaloCells(0)
108 , fRun(-1), fRecoUtils(0), fConfigName("")
109 , fCellLabels(), fCellSecondLabels(), fMaxEvent(1000000000), fDoTrackMatching(kFALSE)
110 , fSelectCell(kFALSE), fSelectCellMinE(0.005), fSelectCellMinFrac(0.001)
113 for(Int_t i = 0; i < 10; i++) fGeomMatrix[i] = 0;
114 for(Int_t j = 0; j < 24*48*11; j++) {
116 fCellSecondLabels[j] = -1;
119 fDigitsArr = new TClonesArray("AliEMCALDigit",200);
120 fClusterArr = new TObjArray(100);
121 fCaloClusterArr = new TObjArray(100);
122 fRecParam = new AliEMCALRecParam;
123 fBranchNames = "ESD:AliESDHeader.,EMCALCells.";
124 fRecoUtils = new AliEMCALRecoUtils();
128 //________________________________________________________________________
129 AliAnalysisTaskEMCALClusterize::~AliAnalysisTaskEMCALClusterize()
134 fDigitsArr->Clear("C");
139 fClusterArr->Delete();
143 if (fCaloClusterArr){
144 fCaloClusterArr->Delete();
145 delete fCaloClusterArr;
148 if(fClusterizer) delete fClusterizer;
149 if(fUnfolder) delete fUnfolder;
150 if(fRecoUtils) delete fRecoUtils;
154 //-------------------------------------------------------------------
155 void AliAnalysisTaskEMCALClusterize::Init()
157 //Init analysis with configuration macro if available
159 if(gROOT->LoadMacro(fConfigName) >=0){
160 printf("Configure analysis with %s\n",fConfigName.Data());
161 AliAnalysisTaskEMCALClusterize *clus = (AliAnalysisTaskEMCALClusterize*)gInterpreter->ProcessLine("ConfigEMCALClusterize()");
162 fGeomName = clus->fGeomName;
163 fLoadGeomMatrices = clus->fLoadGeomMatrices;
164 fOCDBpath = clus->fOCDBpath;
165 fAccessOCDB = clus->fAccessOCDB;
166 fRecParam = clus->fRecParam;
167 fJustUnfold = clus->fJustUnfold;
168 fFillAODFile = clus->fFillAODFile;
169 fRecoUtils = clus->fRecoUtils;
170 fConfigName = clus->fConfigName;
171 fMaxEvent = clus->fMaxEvent;
172 fDoTrackMatching = clus->fDoTrackMatching;
173 fOutputAODBranchName = clus->fOutputAODBranchName;
174 for(Int_t i = 0; i < 10; i++) fGeomMatrix[i] = clus->fGeomMatrix[i] ;
180 //-------------------------------------------------------------------
181 void AliAnalysisTaskEMCALClusterize::UserCreateOutputObjects()
183 // Init geometry, create list of output clusters
185 fGeom = AliEMCALGeometry::GetInstance(fGeomName) ;
186 if(fOutputAODBranchName.Length()!=0){
187 fOutputAODBranch = new TClonesArray("AliAODCaloCluster", 0);
188 fOutputAODBranch->SetName(fOutputAODBranchName);
189 AddAODBranch("TClonesArray", &fOutputAODBranch);
192 AliFatal("fOutputAODBranchName not set\n");
196 //________________________________________________________________________
197 void AliAnalysisTaskEMCALClusterize::FillAODCaloCells() {
198 // Put calo cells in standard branch
199 AliVEvent * event = InputEvent();
200 AliVCaloCells &eventEMcells = *(event->GetEMCALCells());
201 Int_t nEMcell = eventEMcells.GetNumberOfCells() ;
203 AliAODCaloCells &aodEMcells = *(AODEvent()->GetEMCALCells());
204 aodEMcells.CreateContainer(nEMcell);
205 aodEMcells.SetType(AliVCaloCells::kEMCALCell);
206 Double_t calibFactor = 1.;
207 for (Int_t iCell = 0; iCell < nEMcell; iCell++) {
208 Int_t imod = -1, iphi =-1, ieta=-1,iTower = -1, iIphi = -1, iIeta = -1;
209 fGeom->GetCellIndex(eventEMcells.GetCellNumber(iCell),imod,iTower,iIphi,iIeta);
210 fGeom->GetCellPhiEtaIndexInSModule(imod,iTower,iIphi, iIeta,iphi,ieta);
212 if(fRecoUtils->IsRecalibrationOn()){
213 calibFactor = fRecoUtils->GetEMCALChannelRecalibrationFactor(imod,ieta,iphi);
216 if(!fRecoUtils->GetEMCALChannelStatus(imod, ieta, iphi)){ //Channel is not declared as bad
217 aodEMcells.SetCell(iCell,eventEMcells.GetCellNumber(iCell),eventEMcells.GetAmplitude(iCell)*calibFactor);
220 aodEMcells.SetCell(iCell,eventEMcells.GetCellNumber(iCell),0);
227 //________________________________________________________________________
228 void AliAnalysisTaskEMCALClusterize::FillAODHeader() {
229 //Put event header information in standard AOD branch
231 AliVEvent* event = InputEvent();
232 AliESDEvent* esdevent = dynamic_cast<AliESDEvent*> (event);
233 AliAODEvent* aodevent = dynamic_cast<AliAODEvent*> (event);
237 for (Int_t i = 0; i < 6; i++) covVtx[i] = 0.;
239 AliAODHeader* header = AODEvent()->GetHeader();
240 header->SetRunNumber(event->GetRunNumber());
243 TTree* tree = fInputHandler->GetTree();
245 TFile* file = tree->GetCurrentFile();
246 if (file) header->SetESDFileName(file->GetName());
249 else if (aodevent) header->SetESDFileName(aodevent->GetHeader()->GetESDFileName());
251 header->SetBunchCrossNumber(event->GetBunchCrossNumber());
252 header->SetOrbitNumber(event->GetOrbitNumber());
253 header->SetPeriodNumber(event->GetPeriodNumber());
254 header->SetEventType(event->GetEventType());
257 if(event->GetCentrality()){
258 header->SetCentrality(new AliCentrality(*(event->GetCentrality())));
261 header->SetCentrality(0);
265 header->SetOfflineTrigger(fInputHandler->IsEventSelected()); // propagate the decision of the physics selection
266 if (esdevent) header->SetFiredTriggerClasses(esdevent->GetFiredTriggerClasses());
267 else if (aodevent) header->SetFiredTriggerClasses(aodevent->GetFiredTriggerClasses());
268 header->SetTriggerMask(event->GetTriggerMask());
269 header->SetTriggerCluster(event->GetTriggerCluster());
271 header->SetL0TriggerInputs(esdevent->GetHeader()->GetL0TriggerInputs());
272 header->SetL1TriggerInputs(esdevent->GetHeader()->GetL1TriggerInputs());
273 header->SetL2TriggerInputs(esdevent->GetHeader()->GetL2TriggerInputs());
276 header->SetL0TriggerInputs(aodevent->GetHeader()->GetL0TriggerInputs());
277 header->SetL1TriggerInputs(aodevent->GetHeader()->GetL1TriggerInputs());
278 header->SetL2TriggerInputs(aodevent->GetHeader()->GetL2TriggerInputs());
281 header->SetMagneticField(event->GetMagneticField());
282 //header->SetMuonMagFieldScale(esdevent->GetCurrentDip()/6000.);
284 header->SetZDCN1Energy(event->GetZDCN1Energy());
285 header->SetZDCP1Energy(event->GetZDCP1Energy());
286 header->SetZDCN2Energy(event->GetZDCN2Energy());
287 header->SetZDCP2Energy(event->GetZDCP2Energy());
288 header->SetZDCEMEnergy(event->GetZDCEMEnergy(0),event->GetZDCEMEnergy(1));
290 Float_t diamxy[2]={event->GetDiamondX(),event->GetDiamondY()};
292 event->GetDiamondCovXY(diamcov);
293 header->SetDiamond(diamxy,diamcov);
294 if (esdevent) header->SetDiamondZ(esdevent->GetDiamondZ(),esdevent->GetSigma2DiamondZ());
295 else if (aodevent) header->SetDiamondZ(aodevent->GetDiamondZ(),aodevent->GetSigma2DiamondZ());
299 Int_t nVertices = 1 ;/* = prim. vtx*/;
300 Int_t nCaloClus = event->GetNumberOfCaloClusters();
302 AODEvent()->ResetStd(0, nVertices, 0, 0, 0, nCaloClus, 0, 0);
304 // Access to the AOD container of vertices
305 TClonesArray &vertices = *(AODEvent()->GetVertices());
308 // Add primary vertex. The primary tracks will be defined
309 // after the loops on the composite objects (V0, cascades, kinks)
310 event->GetPrimaryVertex()->GetXYZ(pos);
313 esdevent->GetPrimaryVertex()->GetCovMatrix(covVtx);
314 chi = esdevent->GetPrimaryVertex()->GetChi2toNDF();
317 aodevent->GetPrimaryVertex()->GetCovMatrix(covVtx);
318 chi = aodevent->GetPrimaryVertex()->GetChi2perNDF();//Different from ESD?
321 AliAODVertex * primary = new(vertices[jVertices++])
322 AliAODVertex(pos, covVtx, chi, NULL, -1, AliAODVertex::kPrimary);
323 primary->SetName(event->GetPrimaryVertex()->GetName());
324 primary->SetTitle(event->GetPrimaryVertex()->GetTitle());
328 //________________________________________________________________________
329 void AliAnalysisTaskEMCALClusterize::UserExec(Option_t *)
332 // Called for each event
334 AliAODInputHandler* aodIH = dynamic_cast<AliAODInputHandler*>((AliAnalysisManager::GetAnalysisManager())->GetInputEventHandler());
335 Int_t eventN = Entry();
336 if(aodIH) eventN = aodIH->GetReadEntry();
338 if (eventN > fMaxEvent) return;
339 //printf("Clusterizer --- Event %d-- \n",eventN);
341 //Remove the contents of output list set in the previous event
342 fOutputAODBranch->Clear("C");
344 //Magic line to write events to AOD file
345 AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler()->SetFillAOD(fFillAODFile);
348 //Init pointers, clusterizer, ocdb
349 if(fAccessOCDB) AccessOCDB();
350 InitClusterization();
353 AliVEvent * event = 0;
354 AliESDEvent * esdevent = 0;
356 //Fill output event with header
358 //Check if input event are embedded events
359 //If so, take output event
360 if (aodIH && aodIH->GetMergeEvents()) {
361 //printf("AliAnalysisTaskEMCALClusterize::UserExec() - Use embedded events\n");
364 if(!aodIH->GetMergeEMCALCells())
365 AliFatal("Events merged but not EMCAL cells, check analysis settings!");
367 // printf("InputEvent N Clusters %d, N Cells %d\n",InputEvent()->GetNumberOfCaloClusters(),
368 // InputEvent()->GetEMCALCells()->GetNumberOfCells());
369 // printf("MergedEvent N Clusters %d, N Cells %d\n",aodIH->GetEventToMerge()->GetNumberOfCaloClusters(),
370 // aodIH->GetEventToMerge()->GetEMCALCells()->GetNumberOfCells());
371 // for (Int_t icl=0; icl < aodIH->GetEventToMerge()->GetNumberOfCaloClusters(); icl++) {
372 // AliAODCaloCluster *sigCluster = aodIH->GetEventToMerge()->GetCaloCluster(icl);
373 // if(sigCluster->IsEMCAL()) printf("Signal cluster: i %d, E %f\n",icl,sigCluster->E());
375 // printf("OutputEvent N Clusters %d, N Cells %d\n", AODEvent()->GetNumberOfCaloClusters(),
376 // AODEvent()->GetEMCALCells()->GetNumberOfCells());
380 event = InputEvent();
381 esdevent = dynamic_cast<AliESDEvent*>(InputEvent());
382 if(fFillAODCaloCells) FillAODCaloCells();
383 if(fFillAODHeader) FillAODHeader();
387 Error("UserExec","Event not available");
391 //-------------------------------------------------------------------------------------
392 //Set the geometry matrix, for the first event, skip the rest
393 //-------------------------------------------------------------------------------------
395 if(fLoadGeomMatrices){
396 for(Int_t mod=0; mod < (fGeom->GetEMCGeometry())->GetNumberOfSuperModules(); mod++){
397 if(fGeomMatrix[mod]){
399 fGeomMatrix[mod]->Print();
400 fGeom->SetMisalMatrix(fGeomMatrix[mod],mod) ;
402 fGeomMatrixSet=kTRUE;
405 else if(!gGeoManager){
406 Info("UserExec","Get geo matrices from data");
407 //Still not implemented in AOD, just a workaround to be able to work at least with ESDs
408 if(!strcmp(event->GetName(),"AliAODEvent")) {
410 Warning("UserExec","Use ideal geometry, values geometry matrix not kept in AODs.");
414 Info("UserExec","AliAnalysisTaskEMCALClusterize Load Misaligned matrices.");
415 AliESDEvent* esd = dynamic_cast<AliESDEvent*>(event) ;
417 Error("UserExec","This event does not contain ESDs?");
420 for(Int_t mod=0; mod < (fGeom->GetEMCGeometry())->GetNumberOfSuperModules(); mod++){
422 esd->GetEMCALMatrix(mod)->Print();
423 if(esd->GetEMCALMatrix(mod)) fGeom->SetMisalMatrix(esd->GetEMCALMatrix(mod),mod) ;
425 fGeomMatrixSet=kTRUE;
427 }//Load matrices from Data
429 //Recover time dependent corrections, put then in recalibration histograms. Do it once
430 fRecoUtils->SetTimeDependentCorrections(InputEvent()->GetRunNumber());
434 //Get the list of cells needed for unfolding and reclustering
435 AliVCaloCells *cells = event->GetEMCALCells();
436 Int_t nClustersOrg = 0;
437 Double_t cellAmplitude = 0;
438 Double_t cellTime = 0;
439 Short_t cellNumber = 0;
441 //-------------------------------------------
442 //---------Unfolding clusters----------------
443 //-------------------------------------------
446 //Fill the array with the EMCAL clusters, copy them
447 for (Int_t i = 0; i < event->GetNumberOfCaloClusters(); i++)
449 AliVCluster *clus = event->GetCaloCluster(i);
452 //recalibrate/remove bad channels/etc if requested
453 if(fRecoUtils->ClusterContainsBadChannel(fGeom,clus->GetCellsAbsId(), clus->GetNCells())){
457 if(fRecoUtils->IsRecalibrationOn()){
460 //printf("Energy before %f ",clus->E());
461 fRecoUtils->RecalibrateClusterEnergy(fGeom, clus, cells);
462 //printf("; after %f\n",clus->E());
465 for (Int_t icell = 0; icell < cells->GetNumberOfCells(); icell++)
467 if (cells->GetCell(icell, cellNumber, cellAmplitude, cellTime) != kTRUE)
471 Int_t imod = -1, iphi =-1, ieta=-1,iTower = -1, iIphi = -1, iIeta = -1;
472 fGeom->GetCellIndex(cellNumber,imod,iTower,iIphi,iIeta);
473 fGeom->GetCellPhiEtaIndexInSModule(imod,iTower,iIphi, iIeta,iphi,ieta);
475 //Do not include bad channels found in analysis?
476 if( fRecoUtils->IsBadChannelsRemovalSwitchedOn() &&
477 fRecoUtils->GetEMCALChannelStatus(imod, ieta, iphi)){
478 fCellLabels[cellNumber] =-1; //reset the entry in the array for next event
479 fCellSecondLabels[cellNumber]=-1; //reset the entry in the array for next event
480 fCellTime[cellNumber] = 0.;
484 cells->SetCell(icell, cellNumber, cellAmplitude*fRecoUtils->GetEMCALChannelRecalibrationFactor(imod,ieta,iphi),cellTime);
489 //Cast to ESD or AOD, needed to create the cluster array
490 AliESDCaloCluster * esdCluster = dynamic_cast<AliESDCaloCluster*> (clus);
491 AliAODCaloCluster * aodCluster = dynamic_cast<AliAODCaloCluster*> (clus);
493 fCaloClusterArr->Add( new AliESDCaloCluster(*esdCluster) );
496 fCaloClusterArr->Add( new AliAODCaloCluster(*aodCluster) );
499 Warning("UserExec()"," - Wrong CaloCluster type?");
505 fUnfolder->UnfoldClusters(fCaloClusterArr, cells);
510 } // just unfold ESD/AOD cluster
512 //-------------------------------------------
513 //---------- Recluster cells ----------------
514 //-------------------------------------------
517 //-------------------------------------------------------------------------------------
518 //Transform CaloCells into Digits
519 //-------------------------------------------------------------------------------------
521 //In case of MC, first loop on the clusters and fill MC label to array
522 //.....................................................................
524 // for(Int_t j = 0; j < 24*48*11; j++) {
525 // if(fCellLabels[j] !=-1) printf("Not well initialized cell %d, label1 %d\n",j,fCellLabels[j] ) ;
526 // if(fCellSecondLabels[j]!=-1) printf("Not well initialized cell %d, label2 %d\n",j,fCellSecondLabels[j]) ;
529 Int_t nClusters = event->GetNumberOfCaloClusters();
530 if(aodIH && aodIH->GetEventToMerge()) //Embedding
531 nClusters = aodIH->GetEventToMerge()->GetNumberOfCaloClusters(); //Get clusters directly from embedded signal
532 for (Int_t i = 0; i < nClusters; i++)
534 AliVCluster *clus = 0;
535 if(aodIH && aodIH->GetEventToMerge()) //Embedding
536 clus = aodIH->GetEventToMerge()->GetCaloCluster(i); //Get clusters directly from embedded signal
538 clus = event->GetCaloCluster(i);
541 printf("AliEMCALReclusterize::UserExec() - No Clusters\n");
546 //printf("Cluster Signal %d, energy %f\n",clus->GetID(),clus->E());
547 Int_t label = clus->GetLabel();
549 if (clus->GetNLabels()>=2) label2 = clus->GetLabelAt(1) ;
550 UShort_t * index = clus->GetCellsAbsId() ;
551 for(Int_t icell=0; icell < clus->GetNCells(); icell++ ){
552 fCellLabels[index[icell]] = label;
553 fCellSecondLabels[index[icell]] = label2;
554 fCellTime[icell] = clus->GetTOF();
556 //printf("1) absID %d, label[0] %d label[1] %d\n",index[icell], fCellLabels[index[icell]],fCellSecondLabels[index[icell]]);
569 TTree *digitsTree = new TTree("digitstree","digitstree");
570 digitsTree->Branch("EMCAL","TClonesArray", &fDigitsArr, 32000);
572 for (Int_t icell = 0; icell < cells->GetNumberOfCells(); icell++)
574 if (cells->GetCell(icell, cellNumber, cellAmplitude, cellTime) != kTRUE)
581 Int_t imod = -1, iphi =-1, ieta=-1,iTower = -1, iIphi = -1, iIeta = -1;
582 fGeom->GetCellIndex(id,imod,iTower,iIphi,iIeta);
583 fGeom->GetCellPhiEtaIndexInSModule(imod,iTower,iIphi, iIeta,iphi,ieta);
585 //Do not include bad channels found in analysis?
586 if( fRecoUtils->IsBadChannelsRemovalSwitchedOn() &&
587 fRecoUtils->GetEMCALChannelStatus(imod, ieta, iphi)){
588 fCellLabels[id] =-1; //reset the entry in the array for next event
589 fCellSecondLabels[id]=-1; //reset the entry in the array for next event
591 //printf("Remove channel %d\n",id);
596 if(fRecoUtils->IsRecalibrationOn()){
597 //printf("CalibFactor %f times %f for id %d\n",fRecoUtils->GetEMCALChannelRecalibrationFactor(imod,ieta,iphi),amp,id);
598 amp *=fRecoUtils->GetEMCALChannelRecalibrationFactor(imod,ieta,iphi);
601 // In case of AOD analysis cell time is 0, approximate replacing by time of the cluster the digit belongs.
602 if (time*1e9 < 1.) time = fCellTime[id];
604 //Create the digit, put a fake primary deposited energy to trick the clusterizer when checking the most likely primary
605 new((*fDigitsArr)[idigit]) AliEMCALDigit( fCellLabels[id], fCellLabels[id],id, amp, time,AliEMCALDigit::kHG,idigit, 0, 0, 1);
606 //if(fCellLabels[id]>=0)printf("2) Digit cell %d, label %d\n",id,fCellLabels[id]) ;
607 //else printf("2) Digit cell %d, no label, amp %f \n",id,amp) ;
608 fCellLabels[id] =-1; //reset the entry in the array for next event
610 //printf("Digit: Id %d, amp %f, time %e, index %d\n",id, amp,time,idigit);
614 //Fill the tree with digits
617 //-------------------------------------------------------------------------------------
618 //Do the clusterization
619 //-------------------------------------------------------------------------------------
620 TTree *clustersTree = new TTree("clustertree","clustertree");
622 fClusterizer->SetInput(digitsTree);
623 fClusterizer->SetOutput(clustersTree);
624 fClusterizer->Digits2Clusters("");
626 //-------------------------------------------------------------------------------------
627 //Transform the recpoints into AliVClusters
628 //-------------------------------------------------------------------------------------
630 clustersTree->SetBranchStatus("*",0); //disable all branches
631 clustersTree->SetBranchStatus("EMCALECARP",1); //Enable only the branch we need
633 TBranch *branch = clustersTree->GetBranch("EMCALECARP");
634 branch->SetAddress(&fClusterArr);
637 RecPoints2Clusters(fDigitsArr, fClusterArr, fCaloClusterArr);
639 if(!fCaloClusterArr){
640 printf("AliAnalisysTaskEMCALClusterize::UserExec() - No array with CaloClusters, input RecPoints entries %d\n",fClusterArr->GetEntriesFast());
644 if( DebugLevel() > 0 && fCaloClusterArr->GetEntriesFast() != fClusterArr->GetEntriesFast()){
645 printf("AliAnalisysTaskEMCALClusterize::UserExec() - Some RecRoints not transformed into CaloClusters (clusterizer %d, unfold %d): Input entries %d - Output entries %d - %d (not fast)\n",
646 fRecParam->GetClusterizerFlag(),fRecParam->GetUnfold(),
647 fClusterArr->GetEntriesFast(), fCaloClusterArr->GetEntriesFast(), fCaloClusterArr->GetEntries());
650 //Reset the array with second labels for this event
651 memset(fCellSecondLabels, -1, sizeof(fCellSecondLabels));
654 fClusterizer->Clear();
655 fDigitsArr ->Clear("C");
656 fClusterArr ->Delete(); // Do not Clear(), it leaks, why?
658 clustersTree->Delete("all");
659 digitsTree ->Delete("all");
662 //Recalculate track-matching for the new clusters, only with ESDs
663 if(fDoTrackMatching) fRecoUtils->FindMatches(event,fCaloClusterArr,fGeom);
666 //-------------------------------------------------------------------------------------
667 //Put the new clusters in the AOD list
668 //-------------------------------------------------------------------------------------
670 Int_t kNumberOfCaloClusters = fCaloClusterArr->GetEntriesFast();
671 //printf("New clusters %d, Org clusters %d\n",kNumberOfCaloClusters, nClustersOrg);
672 for(Int_t i = 0; i < kNumberOfCaloClusters; i++){
673 AliAODCaloCluster *newCluster = (AliAODCaloCluster *) fCaloClusterArr->At(i);
674 //if(Entry()==0) Info("UserExec","newCluster E %f\n", newCluster->E());
676 //Add matched track, if any, only with ESDs
677 if(esdevent && fDoTrackMatching){
678 Int_t trackIndex = fRecoUtils->GetMatchedTrackIndex(i);
680 newCluster->AddTrackMatched(event->GetTrack(trackIndex));
682 Info("UserExec","Matched Track index %d to new cluster %d \n",trackIndex,i);
686 //In case of new bad channels, recalculate distance to bad channels
687 if(fRecoUtils->IsBadChannelsRemovalSwitchedOn()){
688 //printf("DistToBad before %f ",newCluster->GetDistanceToBadChannel());
689 fRecoUtils->RecalculateClusterDistanceToBadChannel(fGeom, event->GetEMCALCells(), newCluster);
690 //printf("; after %f \n",newCluster->GetDistanceToBadChannel());
693 // if(newCluster->GetNLabels()>0){
694 // printf("3) MC: N labels %d, label %d ; ", newCluster->GetNLabels(), newCluster->GetLabel() );
695 // UShort_t * newindex = newCluster->GetCellsAbsId() ;
696 // for(Int_t icell=0; icell < newCluster->GetNCells(); icell++ ){
697 // printf("\t absID %d\n",newindex[icell]);
701 // printf("Cluster %d, energy %f\n",newCluster->GetID(),newCluster->E());
702 // printf("labels: ");
703 // for(UInt_t ilab = 0; ilab < newCluster->GetNLabels(); ilab++)
704 // printf("Label[%d]: %d ",ilab, newCluster->GetLabelAt(ilab));
707 newCluster->SetID(i);
708 new((*fOutputAODBranch)[i]) AliAODCaloCluster(*newCluster);
711 //if(fOutputAODBranchName.Length()!=0)
712 fOutputAODBranch->Expand(kNumberOfCaloClusters); // resize TObjArray to 'remove' slots
715 fCaloClusterArr->Delete(); // Do not Clear(), it leaks, why?
718 //_____________________________________________________________________
719 Bool_t AliAnalysisTaskEMCALClusterize::AccessOCDB()
721 //Access to OCDB stuff
723 AliVEvent * event = InputEvent();
726 Warning("AccessOCDB","Event not available!!!");
730 if (event->GetRunNumber()==fRun)
732 fRun = event->GetRunNumber();
734 if(DebugLevel() > 1 )
735 Info("AccessODCD()"," Begin");
737 //fGeom = AliEMCALGeometry::GetInstance(fGeomName);
739 AliCDBManager *cdb = AliCDBManager::Instance();
742 if (fOCDBpath.Length()){
743 cdb->SetDefaultStorage(fOCDBpath.Data());
744 Info("AccessOCDB","Default storage %s",fOCDBpath.Data());
747 cdb->SetRun(event->GetRunNumber());
750 // EMCAL from RAW OCDB
751 if (fOCDBpath.Contains("alien:"))
753 cdb->SetSpecificStorage("EMCAL/Calib/Data","alien://Folder=/alice/data/2010/OCDB");
754 cdb->SetSpecificStorage("EMCAL/Calib/Pedestals","alien://Folder=/alice/data/2010/OCDB");
757 TString path = cdb->GetDefaultStorage()->GetBaseFolder();
761 //Get calibration parameters
764 AliCDBEntry *entry = (AliCDBEntry*)
765 AliCDBManager::Instance()->Get("EMCAL/Calib/Data");
767 if (entry) fCalibData = (AliEMCALCalibData*) entry->GetObject();
771 AliFatal("Calibration parameters not found in CDB!");
773 //Get calibration parameters
776 AliCDBEntry *entry = (AliCDBEntry*)
777 AliCDBManager::Instance()->Get("EMCAL/Calib/Pedestals");
779 if (entry) fPedestalData = (AliCaloCalibPedestal*) entry->GetObject();
783 AliFatal("Dead map not found in CDB!");
788 //________________________________________________________________________________________
789 void AliAnalysisTaskEMCALClusterize::InitClusterization()
791 //Select clusterization/unfolding algorithm and set all the needed parameters
794 // init the unfolding afterburner
796 fUnfolder = new AliEMCALAfterBurnerUF(fRecParam->GetW0(),fRecParam->GetLocMaxCut());
800 //First init the clusterizer
802 if (fRecParam->GetClusterizerFlag() == AliEMCALRecParam::kClusterizerv1)
803 fClusterizer = new AliEMCALClusterizerv1 (fGeom, fCalibData, fPedestalData);
804 else if(fRecParam->GetClusterizerFlag() == AliEMCALRecParam::kClusterizerv2)
805 fClusterizer = new AliEMCALClusterizerv2(fGeom, fCalibData, fPedestalData);
806 else if(fRecParam->GetClusterizerFlag() == AliEMCALRecParam::kClusterizerNxN){
807 fClusterizer = new AliEMCALClusterizerNxN(fGeom, fCalibData, fPedestalData);
808 fClusterizer->SetNRowDiff(fRecParam->GetNRowDiff());
809 fClusterizer->SetNColDiff(fRecParam->GetNColDiff());
811 AliFatal(Form("Clusterizer < %d > not available", fRecParam->GetClusterizerFlag()));
814 //Now set the parameters
815 fClusterizer->SetECAClusteringThreshold( fRecParam->GetClusteringThreshold() );
816 fClusterizer->SetECALogWeight ( fRecParam->GetW0() );
817 fClusterizer->SetMinECut ( fRecParam->GetMinECut() );
818 fClusterizer->SetUnfolding ( fRecParam->GetUnfold() );
819 fClusterizer->SetECALocalMaxCut ( fRecParam->GetLocMaxCut() );
820 fClusterizer->SetTimeCut ( fRecParam->GetTimeCut() );
821 fClusterizer->SetTimeMin ( fRecParam->GetTimeMin() );
822 fClusterizer->SetTimeMax ( fRecParam->GetTimeMax() );
823 fClusterizer->SetInputCalibrated ( kTRUE );
824 fClusterizer->SetJustClusters ( kTRUE );
825 //In case of unfolding after clusterization is requested, set the corresponding parameters
826 if(fRecParam->GetUnfold()){
828 for (i = 0; i < 8; i++) {
829 fClusterizer->SetSSPars(i, fRecParam->GetSSPars(i));
830 }//end of loop over parameters
831 for (i = 0; i < 3; i++) {
832 fClusterizer->SetPar5 (i, fRecParam->GetPar5(i));
833 fClusterizer->SetPar6 (i, fRecParam->GetPar6(i));
834 }//end of loop over parameters
836 fClusterizer->InitClusterUnfolding();
841 //________________________________________________________________________________________
842 void AliAnalysisTaskEMCALClusterize::RecPoints2Clusters(TClonesArray *digitsArr, TObjArray *recPoints, TObjArray *clusArray)
844 // Restore clusters from recPoints
845 // Cluster energy, global position, cells and their amplitude fractions are restored
847 for(Int_t i = 0; i < recPoints->GetEntriesFast(); i++)
849 AliEMCALRecPoint *recPoint = (AliEMCALRecPoint*) recPoints->At(i);
851 const Int_t ncells = recPoint->GetMultiplicity();
852 Int_t ncellsTrue = 0;
854 if(recPoint->GetEnergy() < fRecParam->GetClusteringThreshold()) continue;
856 // cells and their amplitude fractions
857 UShort_t absIds[ncells];
858 Double32_t ratios[ncells];
860 //For later check embedding
861 AliAODInputHandler* aodIH = dynamic_cast<AliAODInputHandler*>((AliAnalysisManager::GetAnalysisManager())->GetInputEventHandler());
863 Float_t clusterE = 0;
864 for (Int_t c = 0; c < ncells; c++) {
865 AliEMCALDigit *digit = (AliEMCALDigit*) digitsArr->At(recPoint->GetDigitsList()[c]);
867 absIds[ncellsTrue] = digit->GetId();
868 ratios[ncellsTrue] = recPoint->GetEnergiesList()[c]/digit->GetAmplitude();
870 // In case of unfolding, remove digits with unfolded energy too low
872 if (recPoint->GetEnergiesList()[c] < fSelectCellMinE || ratios[ncellsTrue] < fSelectCellMinFrac) {
874 if(DebugLevel() > 1) {
875 printf("AliAnalysisTaskEMCALClusterize::RecPoints2Clusters() - Too small energy in cell of cluster: cluster cell %f, digit %f\n",
876 recPoint->GetEnergiesList()[c],digit->GetAmplitude());
884 //Recalculate cluster energy and number of cluster cells in case any of the cells was rejected
886 clusterE +=recPoint->GetEnergiesList()[c];
888 // In case of embedding, fill ratio with amount of signal,
889 if (aodIH && aodIH->GetMergeEvents()) {
891 //AliVCaloCells* inEMCALCells = InputEvent()->GetEMCALCells();
892 AliVCaloCells* meEMCALCells = aodIH->GetEventToMerge()->GetEMCALCells();
893 AliVCaloCells* ouEMCALCells = AODEvent()->GetEMCALCells();
895 Float_t sigAmplitude = meEMCALCells->GetCellAmplitude(absIds[ncellsTrue]);
896 //Float_t bkgAmplitude = inEMCALCells->GetCellAmplitude(absIds[ncellsTrue]);
897 Float_t sumAmplitude = ouEMCALCells->GetCellAmplitude(absIds[ncellsTrue]);
898 //printf("\t AbsID %d, amplitude : bkg %f, sigAmplitude %f, summed %f - %f\n",absIds[ncellsTrue], bkgAmplitude, sigAmplitude, sumAmplitude, digit->GetAmplitude());
900 if(sumAmplitude > 0) ratios[ncellsTrue] = sigAmplitude/sumAmplitude;
901 //printf("\t \t ratio %f\n",ratios[ncellsTrue]);
905 }// cluster cell loop
907 if (ncellsTrue < 1) {
908 if (DebugLevel() > 1)
909 printf("AliAnalysisTaskEMCALClusterize::RecPoints2Clusters() - Skipping cluster with no cells avobe threshold E = %f, ncells %d\n",
910 recPoint->GetEnergy(), ncells);
914 //if(ncellsTrue != ncells) printf("Old E %f, ncells %d; New E %f, ncells %d\n",recPoint->GetEnergy(),ncells,clusterE,ncellsTrue);
916 if(clusterE < fRecParam->GetClusteringThreshold()) {
918 printf("AliAnalysisTaskEMCALClusterize::RecPoints2Clusters() - Remove cluster with energy below seed threshold %f\n",clusterE);
925 // calculate new cluster position
926 recPoint->EvalGlobalPosition(fRecParam->GetW0(), digitsArr);
927 recPoint->GetGlobalPosition(gpos);
930 // create a new cluster
931 //AliAODCaloCluster *clus = new AliAODCaloCluster();
932 (*clusArray)[j] = new AliAODCaloCluster() ;
933 AliAODCaloCluster *clus = dynamic_cast<AliAODCaloCluster *>( clusArray->At(j) ) ;
935 clus->SetType(AliVCluster::kEMCALClusterv1);
936 clus->SetE(clusterE);//recPoint->GetEnergy());
937 clus->SetPosition(g);
938 clus->SetNCells(ncellsTrue);
939 clus->SetCellsAbsId(absIds);
940 clus->SetCellsAmplitudeFraction(ratios);
941 clus->SetChi2(-1); //not yet implemented
942 clus->SetTOF(recPoint->GetTime()) ; //time-of-flight
943 clus->SetNExMax(recPoint->GetNExMax()); //number of local maxima
944 clus->SetDistanceToBadChannel(recPoint->GetDistanceToBadTower());
946 if(ncells == ncellsTrue){
948 recPoint->GetElipsAxis(elipAxis);
949 clus->SetM02(elipAxis[0]*elipAxis[0]) ;
950 clus->SetM20(elipAxis[1]*elipAxis[1]) ;
951 clus->SetDispersion(recPoint->GetDispersion());
953 else if(fSelectCell){
954 // In case some cells rejected, in unfolding case, recalculate
955 // shower shape parameters and position
956 AliVCaloCells* cells = 0x0;
957 if (aodIH && aodIH->GetMergeEvents()) cells = AODEvent() ->GetEMCALCells();
958 else cells = InputEvent()->GetEMCALCells();
959 fRecoUtils->RecalculateClusterShowerShapeParameters(fGeom,cells,clus);
960 fRecoUtils->RecalculateClusterPID(clus);
961 fRecoUtils->RecalculateClusterPosition(fGeom,cells,clus);
963 // Float_t elipAxis[2];
964 // recPoint->GetElipsAxis(elipAxis);
965 // if(ncellsTrue > 2)
966 // printf("SS, old: l0 %f, l1 %f, D %f; New l0 %f, l1 %f, D %f\n",
967 // elipAxis[0]*elipAxis[0],elipAxis[1]*elipAxis[1], recPoint->GetDispersion(),
968 // clus->GetM02(),clus->GetM20(),clus->GetDispersion());
972 Int_t parentMult = 0;
973 Int_t *parentList = recPoint->GetParents(parentMult);
974 clus->SetLabel(parentList, parentMult);
976 // if(parentMult)printf("RecToESD: Labels %d",parentMult);
977 // for (Int_t iii = 0; iii < parentMult; iii++) {
978 // printf("\t label %d\n",parentList[iii]);
981 //Write the second major contributor to each MC cluster.
983 for ( Int_t iLoopCell = 0 ; iLoopCell < clus->GetNCells() ; iLoopCell++ ){
985 Int_t idCell = clus->GetCellAbsId(iLoopCell) ;
987 iNewLabel = 1 ; //iNewLabel makes sure we don't write twice the same label.
988 for ( UInt_t iLoopLabels = 0 ; iLoopLabels < clus->GetNLabels() ; iLoopLabels++ )
990 if ( fCellSecondLabels[idCell] == -1 ) iNewLabel = 0; // -1 is never a good second label.
991 if ( fCellSecondLabels[idCell] == clus->GetLabelAt(iLoopLabels) ) iNewLabel = 0;
995 //Int_t * newLabelArray = (Int_t*)malloc((clus->GetNLabels()+1)*sizeof(Int_t)) ;
996 Int_t * newLabelArray = new Int_t[clus->GetNLabels()+1] ;
997 for ( UInt_t iLoopNewLabels = 0 ; iLoopNewLabels < clus->GetNLabels() ; iLoopNewLabels++ ){
998 newLabelArray[iLoopNewLabels] = clus->GetLabelAt(iLoopNewLabels) ;
1001 newLabelArray[clus->GetNLabels()] = fCellSecondLabels[idCell] ;
1002 //if(fCellSecondLabels[idCell]>-1)printf("\t new label %d\n",fCellSecondLabels[idCell]);
1003 clus->SetLabel(newLabelArray,clus->GetNLabels()+1) ;
1004 delete [] newLabelArray;
1006 }//positive cell number