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"
36 // --- AliRoot Analysis Steering
37 #include "AliAnalysisTask.h"
38 #include "AliAnalysisManager.h"
39 #include "AliESDEvent.h"
40 #include "AliGeomManager.h"
41 #include "AliVCaloCells.h"
42 #include "AliAODCaloCluster.h"
43 #include "AliCDBManager.h"
44 #include "AliCDBStorage.h"
45 #include "AliCDBEntry.h"
47 #include "AliVEventHandler.h"
48 #include "AliAODInputHandler.h"
51 #include "AliEMCALRecParam.h"
52 #include "AliEMCALAfterBurnerUF.h"
53 #include "AliEMCALGeometry.h"
54 #include "AliEMCALClusterizerNxN.h"
55 #include "AliEMCALClusterizerv1.h"
56 #include "AliEMCALRecPoint.h"
57 #include "AliEMCALDigit.h"
58 #include "AliCaloCalibPedestal.h"
59 #include "AliEMCALCalibData.h"
60 #include "AliEMCALRecoUtils.h"
62 #include "AliAnalysisTaskEMCALClusterize.h"
64 ClassImp(AliAnalysisTaskEMCALClusterize)
66 //________________________________________________________________________
67 AliAnalysisTaskEMCALClusterize::AliAnalysisTaskEMCALClusterize(const char *name)
68 : AliAnalysisTaskSE(name)
69 , fGeom(0), fGeomName("EMCAL_FIRSTYEARV1"), fGeomMatrixSet(kFALSE), fLoadGeomMatrices(kFALSE)
70 , fCalibData(0), fPedestalData(0), fOCDBpath("raw://")
71 , fDigitsArr(0), fClusterArr(0), fCaloClusterArr(0)
72 , fRecParam(0), fClusterizer(0), fUnfolder(0), fJustUnfold(kFALSE)
73 , fOutputAODBranch(0), fOutputAODBranchName("newEMCALClusters")
74 , fFillAODFile(kTRUE), fFillAODHeader(0), fFillAODCaloCells(0)
75 , fRun(-1), fRecoUtils(0), fConfigName("")
76 , fCellLabels(), fCellSecondLabels(), fMaxEvent(1000000000)
80 for(Int_t i = 0; i < 10; i++) fGeomMatrix[i] = 0;
81 for(Int_t j = 0; j < 24*48*11; j++) {
83 fCellSecondLabels[j] = -1;
85 fDigitsArr = new TClonesArray("AliEMCALDigit",200);
86 fClusterArr = new TObjArray(100);
87 fCaloClusterArr = new TObjArray(100);
88 fRecParam = new AliEMCALRecParam;
89 fBranchNames = "ESD:AliESDHeader.,EMCALCells.";
90 fRecoUtils = new AliEMCALRecoUtils();
93 //________________________________________________________________________
94 AliAnalysisTaskEMCALClusterize::AliAnalysisTaskEMCALClusterize()
95 : AliAnalysisTaskSE("DefaultAnalysis_AliAnalysisTaskEMCALClusterize")
96 , fGeom(0), fGeomName("EMCAL_FIRSTYEARV1"), fGeomMatrixSet(kFALSE), fLoadGeomMatrices(kFALSE)
97 , fCalibData(0), fPedestalData(0), fOCDBpath("raw://")
98 , fDigitsArr(0), fClusterArr(0), fCaloClusterArr(0)
99 , fRecParam(0), fClusterizer(0), fUnfolder(0), fJustUnfold(kFALSE)
100 , fOutputAODBranch(0), fOutputAODBranchName("newEMCALClusters")
101 , fFillAODFile(kFALSE), fFillAODHeader(0), fFillAODCaloCells(0)
102 , fRun(-1), fRecoUtils(0), fConfigName("")
103 , fCellLabels(), fCellSecondLabels(), fMaxEvent(1000000000)
106 for(Int_t i = 0; i < 10; i++) fGeomMatrix[i] = 0;
107 for(Int_t j = 0; j < 24*48*11; j++) {
109 fCellSecondLabels[j] = -1;
111 fDigitsArr = new TClonesArray("AliEMCALDigit",200);
112 fClusterArr = new TObjArray(100);
113 fCaloClusterArr = new TObjArray(100);
114 fRecParam = new AliEMCALRecParam;
115 fBranchNames = "ESD:AliESDHeader.,EMCALCells.";
116 fRecoUtils = new AliEMCALRecoUtils();
120 //________________________________________________________________________
121 AliAnalysisTaskEMCALClusterize::~AliAnalysisTaskEMCALClusterize()
126 fDigitsArr->Clear("C");
131 fClusterArr->Delete();
135 if (fCaloClusterArr){
136 fCaloClusterArr->Delete();
137 delete fCaloClusterArr;
140 if(fClusterizer) delete fClusterizer;
141 if(fUnfolder) delete fUnfolder;
142 if(fRecoUtils) delete fRecoUtils;
146 //-------------------------------------------------------------------
147 void AliAnalysisTaskEMCALClusterize::Init()
149 //Init analysis with configuration macro if available
151 if(gROOT->LoadMacro(fConfigName) >=0){
152 printf("Configure analysis with %s\n",fConfigName.Data());
153 AliAnalysisTaskEMCALClusterize *clus = (AliAnalysisTaskEMCALClusterize*)gInterpreter->ProcessLine("ConfigEMCALClusterize()");
154 fGeomName = clus->fGeomName;
155 fLoadGeomMatrices = clus->fLoadGeomMatrices;
156 fOCDBpath = clus->fOCDBpath;
157 fRecParam = clus->fRecParam;
158 fJustUnfold = clus->fJustUnfold;
159 fFillAODFile = clus->fFillAODFile;
160 fRecoUtils = clus->fRecoUtils;
161 fConfigName = clus->fConfigName;
162 fOutputAODBranchName = clus->fOutputAODBranchName;
163 for(Int_t i = 0; i < 10; i++) fGeomMatrix[i] = clus->fGeomMatrix[i] ;
169 //-------------------------------------------------------------------
170 void AliAnalysisTaskEMCALClusterize::UserCreateOutputObjects()
172 // Init geometry, create list of output clusters
174 fGeom = AliEMCALGeometry::GetInstance(fGeomName) ;
175 if(fOutputAODBranchName.Length()!=0){
176 fOutputAODBranch = new TClonesArray("AliAODCaloCluster", 0);
177 fOutputAODBranch->SetName(fOutputAODBranchName);
178 AddAODBranch("TClonesArray", &fOutputAODBranch);
181 AliFatal("fOutputAODBranchName not set\n");
185 //________________________________________________________________________
186 void AliAnalysisTaskEMCALClusterize::FillAODCaloCells() {
187 // Put calo cells in standard branch
188 AliVEvent * event = InputEvent();
189 AliVCaloCells &eventEMcells = *(event->GetEMCALCells());
190 Int_t nEMcell = eventEMcells.GetNumberOfCells() ;
192 AliAODCaloCells &aodEMcells = *(AODEvent()->GetEMCALCells());
193 aodEMcells.CreateContainer(nEMcell);
194 aodEMcells.SetType(AliVCaloCells::kEMCALCell);
195 Double_t calibFactor = 1.;
196 for (Int_t iCell = 0; iCell < nEMcell; iCell++) {
197 Int_t imod = -1, iphi =-1, ieta=-1,iTower = -1, iIphi = -1, iIeta = -1;
198 fGeom->GetCellIndex(eventEMcells.GetCellNumber(iCell),imod,iTower,iIphi,iIeta);
199 fGeom->GetCellPhiEtaIndexInSModule(imod,iTower,iIphi, iIeta,iphi,ieta);
201 if(fRecoUtils->IsRecalibrationOn()){
202 calibFactor = fRecoUtils->GetEMCALChannelRecalibrationFactor(imod,ieta,iphi);
205 if(!fRecoUtils->GetEMCALChannelStatus(imod, ieta, iphi)){ //Channel is not declared as bad
206 aodEMcells.SetCell(iCell,eventEMcells.GetCellNumber(iCell),eventEMcells.GetAmplitude(iCell)*calibFactor);
207 //printf("GOOD channel\n");
210 aodEMcells.SetCell(iCell,eventEMcells.GetCellNumber(iCell),0);
211 //printf("BAD channel\n");
218 //________________________________________________________________________
219 void AliAnalysisTaskEMCALClusterize::FillAODHeader() {
220 //Put event header information in standard AOD branch
222 AliVEvent* event = InputEvent();
223 AliESDEvent* esdevent = dynamic_cast<AliESDEvent*> (event);
224 AliAODEvent* aodevent = dynamic_cast<AliAODEvent*> (event);
228 for (Int_t i = 0; i < 6; i++) covVtx[i] = 0.;
230 AliAODHeader* header = AODEvent()->GetHeader();
231 header->SetRunNumber(event->GetRunNumber());
234 TTree* tree = fInputHandler->GetTree();
236 TFile* file = tree->GetCurrentFile();
237 if (file) header->SetESDFileName(file->GetName());
240 else if (aodevent) header->SetESDFileName(aodevent->GetHeader()->GetESDFileName());
242 header->SetBunchCrossNumber(event->GetBunchCrossNumber());
243 header->SetOrbitNumber(event->GetOrbitNumber());
244 header->SetPeriodNumber(event->GetPeriodNumber());
245 header->SetEventType(event->GetEventType());
248 if(event->GetCentrality()){
249 header->SetCentrality(new AliCentrality(*(event->GetCentrality())));
252 header->SetCentrality(0);
256 header->SetOfflineTrigger(fInputHandler->IsEventSelected()); // propagate the decision of the physics selection
257 if (esdevent) header->SetFiredTriggerClasses(esdevent->GetFiredTriggerClasses());
258 else if (aodevent) header->SetFiredTriggerClasses(aodevent->GetFiredTriggerClasses());
259 header->SetTriggerMask(event->GetTriggerMask());
260 header->SetTriggerCluster(event->GetTriggerCluster());
262 header->SetL0TriggerInputs(esdevent->GetHeader()->GetL0TriggerInputs());
263 header->SetL1TriggerInputs(esdevent->GetHeader()->GetL1TriggerInputs());
264 header->SetL2TriggerInputs(esdevent->GetHeader()->GetL2TriggerInputs());
267 header->SetL0TriggerInputs(aodevent->GetHeader()->GetL0TriggerInputs());
268 header->SetL1TriggerInputs(aodevent->GetHeader()->GetL1TriggerInputs());
269 header->SetL2TriggerInputs(aodevent->GetHeader()->GetL2TriggerInputs());
272 header->SetMagneticField(event->GetMagneticField());
273 //header->SetMuonMagFieldScale(esdevent->GetCurrentDip()/6000.);
275 header->SetZDCN1Energy(event->GetZDCN1Energy());
276 header->SetZDCP1Energy(event->GetZDCP1Energy());
277 header->SetZDCN2Energy(event->GetZDCN2Energy());
278 header->SetZDCP2Energy(event->GetZDCP2Energy());
279 header->SetZDCEMEnergy(event->GetZDCEMEnergy(0),event->GetZDCEMEnergy(1));
281 Float_t diamxy[2]={event->GetDiamondX(),event->GetDiamondY()};
283 event->GetDiamondCovXY(diamcov);
284 header->SetDiamond(diamxy,diamcov);
285 if (esdevent) header->SetDiamondZ(esdevent->GetDiamondZ(),esdevent->GetSigma2DiamondZ());
286 else if (aodevent) header->SetDiamondZ(aodevent->GetDiamondZ(),aodevent->GetSigma2DiamondZ());
290 Int_t nVertices = 1 ;/* = prim. vtx*/;
291 Int_t nCaloClus = event->GetNumberOfCaloClusters();
293 AODEvent()->ResetStd(0, nVertices, 0, 0, 0, nCaloClus, 0, 0);
295 // Access to the AOD container of vertices
296 TClonesArray &vertices = *(AODEvent()->GetVertices());
299 // Add primary vertex. The primary tracks will be defined
300 // after the loops on the composite objects (V0, cascades, kinks)
301 event->GetPrimaryVertex()->GetXYZ(pos);
304 esdevent->GetPrimaryVertex()->GetCovMatrix(covVtx);
305 chi = esdevent->GetPrimaryVertex()->GetChi2toNDF();
308 aodevent->GetPrimaryVertex()->GetCovMatrix(covVtx);
309 chi = aodevent->GetPrimaryVertex()->GetChi2perNDF();//Different from ESD?
312 AliAODVertex * primary = new(vertices[jVertices++])
313 AliAODVertex(pos, covVtx, chi, NULL, -1, AliAODVertex::kPrimary);
314 primary->SetName(event->GetPrimaryVertex()->GetName());
315 primary->SetTitle(event->GetPrimaryVertex()->GetTitle());
319 //________________________________________________________________________
320 void AliAnalysisTaskEMCALClusterize::UserExec(Option_t *)
323 // Called for each event
325 AliAODInputHandler* aodIH = dynamic_cast<AliAODInputHandler*>((AliAnalysisManager::GetAnalysisManager())->GetInputEventHandler());
326 Int_t eventN = Entry();
328 eventN = aodIH->GetReadEntry();
329 //printf("Clusterizer --- Event %d-- \n",eventN);
331 if (eventN > fMaxEvent) return;
333 //Remove the contents of output list set in the previous event
334 fOutputAODBranch->Clear("C");
336 // if(fOutputAODBranchName.Length()!=0){
337 // //Remove the contents of output list set in the previous event
338 // fOutputAODBranch->Clear("C");
341 // //Reset and put new clusters in standard branch, also cells
342 // AODEvent()->ResetStd(0, 1, 0, 0, 0, AODEvent()->GetNumberOfCaloClusters(), 0, 0);
343 // fOutputAODBranch = AODEvent()->GetCaloClusters();// Put new clusters in standard branch
346 //Magic line to write events to AOD file
347 AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler()->SetFillAOD(fFillAODFile);
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 // printf("OutputEvent N Clusters %d, N Cells %d\n", AODEvent()->GetNumberOfCaloClusters(),
372 // AODEvent()->GetEMCALCells()->GetNumberOfCells());
376 event = InputEvent();
377 esdevent = dynamic_cast<AliESDEvent*>(InputEvent());
378 if(fFillAODCaloCells) FillAODCaloCells();
379 if(fFillAODHeader) FillAODHeader();
383 Error("UserExec","Event not available");
387 //-------------------------------------------------------------------------------------
388 //Set the geometry matrix, for the first event, skip the rest
389 //-------------------------------------------------------------------------------------
391 if(fLoadGeomMatrices){
392 for(Int_t mod=0; mod < (fGeom->GetEMCGeometry())->GetNumberOfSuperModules(); mod++){
393 if(fGeomMatrix[mod]){
395 fGeomMatrix[mod]->Print();
396 fGeom->SetMisalMatrix(fGeomMatrix[mod],mod) ;
398 fGeomMatrixSet=kTRUE;
401 else if(!gGeoManager){
402 Info("UserExec","Get geo matrices from data");
403 //Still not implemented in AOD, just a workaround to be able to work at least with ESDs
404 if(!strcmp(event->GetName(),"AliAODEvent")) {
406 Warning("UserExec","Use ideal geometry, values geometry matrix not kept in AODs.");
410 Info("UserExec","AliAnalysisTaskEMCALClusterize Load Misaligned matrices.");
411 AliESDEvent* esd = dynamic_cast<AliESDEvent*>(event) ;
413 Error("UserExec","This event does not contain ESDs?");
416 for(Int_t mod=0; mod < (fGeom->GetEMCGeometry())->GetNumberOfSuperModules(); mod++){
418 esd->GetEMCALMatrix(mod)->Print();
419 if(esd->GetEMCALMatrix(mod)) fGeom->SetMisalMatrix(esd->GetEMCALMatrix(mod),mod) ;
421 fGeomMatrixSet=kTRUE;
423 }//Load matrices from Data
425 //Recover time dependent corrections, put then in recalibration histograms. Do it once
426 fRecoUtils->SetTimeDependentCorrections(InputEvent()->GetRunNumber());
430 //Get the list of cells needed for unfolding and reclustering
431 AliVCaloCells *cells= event->GetEMCALCells();
432 Int_t nClustersOrg = 0;
433 //-------------------------------------------
434 //---------Unfolding clusters----------------
435 //-------------------------------------------
438 //Fill the array with the EMCAL clusters, copy them
439 for (Int_t i = 0; i < event->GetNumberOfCaloClusters(); i++)
441 AliVCluster *clus = event->GetCaloCluster(i);
443 //printf("Org Cluster %d, E %f\n",i, clus->E());
445 //recalibrate/remove bad channels/etc if requested
446 if(fRecoUtils->ClusterContainsBadChannel(fGeom,clus->GetCellsAbsId(), clus->GetNCells())){
447 //printf("Remove cluster\n");
451 if(fRecoUtils->IsRecalibrationOn()){
452 //printf("Energy before %f ",clus->E());
453 fRecoUtils->RecalibrateClusterEnergy(fGeom, clus, cells);
454 //printf("; after %f\n",clus->E());
456 //Cast to ESD or AOD, needed to create the cluster array
457 AliESDCaloCluster * esdCluster = dynamic_cast<AliESDCaloCluster*> (clus);
458 AliAODCaloCluster * aodCluster = dynamic_cast<AliAODCaloCluster*> (clus);
460 fCaloClusterArr->Add( new AliESDCaloCluster(*esdCluster) );
463 fCaloClusterArr->Add( new AliAODCaloCluster(*aodCluster) );
466 Warning("UserExec()"," - Wrong CaloCluster type?");
472 fUnfolder->UnfoldClusters(fCaloClusterArr, cells);
478 //printf("nClustersOrg %d\n",nClustersOrg);
480 //-------------------------------------------
481 //---------- Recluster cells ----------------
482 //-------------------------------------------
485 //-------------------------------------------------------------------------------------
486 //Transform CaloCells into Digits
487 //-------------------------------------------------------------------------------------
489 //In case of MC, first loop on the clusters and fill MC label to array
490 //.....................................................................
492 // for(Int_t j = 0; j < 24*48*11; j++) {
493 // if(fCellLabels[j]!=-1) printf("Not well initialized cell %d, label %d\n",j,fCellLabels[j]) ;
496 Int_t nClusters = event->GetNumberOfCaloClusters();
497 if(aodIH && aodIH->GetEventToMerge()) //Embedding
498 nClusters = aodIH->GetEventToMerge()->GetNumberOfCaloClusters(); //Get clusters directly from embedded signal
499 for (Int_t i = 0; i < nClusters; i++)
501 AliVCluster *clus = 0;
502 if(aodIH && aodIH->GetEventToMerge()) //Embedding
503 clus = aodIH->GetEventToMerge()->GetCaloCluster(i); //Get clusters directly from embedded signal
505 clus = event->GetCaloCluster(i);
508 printf("AliEMCALReclusterize::UserExec() - No Clusters\n");
513 //printf("Cluster Signal %d, energy %f\n",clus->GetID(),clus->E());
514 Int_t label = clus->GetLabel();
516 if (clus->GetNLabels()>=2) label2 = clus->GetLabelAt(1) ;
517 UShort_t * index = clus->GetCellsAbsId() ;
518 for(Int_t icell=0; icell < clus->GetNCells(); icell++ ){
519 fCellLabels[index[icell]]=label;
520 fCellSecondLabels[index[icell]]=label2;
521 //printf("1) absID %d, label[0] %d label[1] %d\n",index[icell], fCellLabels[index[icell]],fCellSecondLabels[index[icell]]);
534 Double_t cellAmplitude = 0;
535 Double_t cellTime = 0;
536 Short_t cellNumber = 0;
538 TTree *digitsTree = new TTree("digitstree","digitstree");
539 digitsTree->Branch("EMCAL","TClonesArray", &fDigitsArr, 32000);
542 for (Int_t icell = 0; icell < cells->GetNumberOfCells(); icell++)
544 if (cells->GetCell(icell, cellNumber, cellAmplitude, cellTime) != kTRUE)
551 Int_t imod = -1, iphi =-1, ieta=-1,iTower = -1, iIphi = -1, iIeta = -1;
552 fGeom->GetCellIndex(id,imod,iTower,iIphi,iIeta);
553 fGeom->GetCellPhiEtaIndexInSModule(imod,iTower,iIphi, iIeta,iphi,ieta);
555 //Do not include bad channels found in analysis?
556 if( fRecoUtils->IsBadChannelsRemovalSwitchedOn() &&
557 fRecoUtils->GetEMCALChannelStatus(imod, ieta, iphi)){
558 fCellLabels[id]=-1; //reset the entry in the array for next event
559 //printf("Remove channel %d\n",id);
564 if(fRecoUtils->IsRecalibrationOn()){
565 //printf("CalibFactor %f times %f for id %d\n",fRecoUtils->GetEMCALChannelRecalibrationFactor(imod,ieta,iphi),amp,id);
566 amp *=fRecoUtils->GetEMCALChannelRecalibrationFactor(imod,ieta,iphi);
569 //Create the digit, put a fake primary deposited energy to trick the clusterizer when checking the most likely primary
570 new((*fDigitsArr)[idigit]) AliEMCALDigit( fCellLabels[id], fCellLabels[id],id, amp, time,AliEMCALDigit::kHG,idigit, 0, 0, 1);
571 //if(fCellLabels[id]>=0)printf("2) Digit cell %d, label %d\n",id,fCellLabels[id]) ;
572 //else printf("2) Digit cell %d, no label, amp %f \n",id,amp) ;
573 fCellLabels[id]=-1; //reset the entry in the array for next event
575 //AliEMCALDigit *digit = (AliEMCALDigit*) fDigitsArr->New(idigit);
577 //digit->SetAmplitude(amp);
578 //digit->SetTime(time);
579 //digit->SetTimeR(time);
580 //digit->SetIndexInList(idigit);
581 //digit->SetType(AliEMCALDigit::kHG);
583 //printf("Digit: Id %d, amp %f, time %e, index %d\n",id, amp,time,idigit);
587 //Fill the tree with digits
590 //-------------------------------------------------------------------------------------
591 //Do the clusterization
592 //-------------------------------------------------------------------------------------
593 TTree *clustersTree = new TTree("clustertree","clustertree");
595 fClusterizer->SetInput(digitsTree);
596 fClusterizer->SetOutput(clustersTree);
597 fClusterizer->Digits2Clusters("");
599 //-------------------------------------------------------------------------------------
600 //Transform the recpoints into AliVClusters
601 //-------------------------------------------------------------------------------------
603 clustersTree->SetBranchStatus("*",0); //disable all branches
604 clustersTree->SetBranchStatus("EMCALECARP",1); //Enable only the branch we need
606 TBranch *branch = clustersTree->GetBranch("EMCALECARP");
607 branch->SetAddress(&fClusterArr);
610 RecPoints2Clusters(fDigitsArr, fClusterArr, fCaloClusterArr);
613 fClusterizer->Clear();
614 fDigitsArr ->Clear("C");
615 fClusterArr ->Delete(); // Do not Clear(), it leaks, why?
617 clustersTree->Delete("all");
618 digitsTree ->Delete("all");
621 //Recalculate track-matching for the new clusters, only with ESDs
622 if(esdevent)fRecoUtils->FindMatches(esdevent,fCaloClusterArr);
625 //-------------------------------------------------------------------------------------
626 //Put the new clusters in the AOD list
627 //-------------------------------------------------------------------------------------
629 Int_t kNumberOfCaloClusters = fCaloClusterArr->GetEntries();
630 //printf("New clusters %d, Org clusters %d\n",kNumberOfCaloClusters, nClustersOrg);
631 for(Int_t i = 0; i < kNumberOfCaloClusters; i++){
632 AliAODCaloCluster *newCluster = (AliAODCaloCluster *) fCaloClusterArr->At(i);
633 //if(Entry()==0) Info("UserExec","newCluster E %f\n", newCluster->E());
635 //Add matched track, if any, only with ESDs
637 Int_t trackIndex = fRecoUtils->GetMatchedTrackIndex(i);
639 newCluster->AddTrackMatched(event->GetTrack(trackIndex));
641 Info("UserExec","Matched Track index %d to new cluster %d \n",trackIndex,i);
645 //In case of new bad channels, recalculate distance to bad channels
646 if(fRecoUtils->IsBadChannelsRemovalSwitchedOn()){
647 //printf("DistToBad before %f ",newCluster->GetDistanceToBadChannel());
648 fRecoUtils->RecalculateClusterDistanceToBadChannel(fGeom, event->GetEMCALCells(), newCluster);
649 //printf("; after %f \n",newCluster->GetDistanceToBadChannel());
652 // if(newCluster->GetNLabels()>0){
653 // printf("3) MC: N labels %d, label %d ; ", newCluster->GetNLabels(), newCluster->GetLabel() );
654 // UShort_t * newindex = newCluster->GetCellsAbsId() ;
655 // for(Int_t icell=0; icell < newCluster->GetNCells(); icell++ ){
656 // printf("\t absID %d\n",newindex[icell]);
660 // printf("Cluster %d, energy %f\n",newCluster->GetID(),newCluster->E());
661 // printf("labels: ");
662 // for(UInt_t ilab = 0; ilab < newCluster->GetNLabels(); ilab++)
663 // printf("Label[%d]: %d ",ilab, newCluster->GetLabelAt(ilab));
666 newCluster->SetID(i);
667 new((*fOutputAODBranch)[i]) AliAODCaloCluster(*newCluster);
670 //if(fOutputAODBranchName.Length()!=0)
671 fOutputAODBranch->Expand(kNumberOfCaloClusters); // resize TObjArray to 'remove' slots
674 fCaloClusterArr->Delete(); // Do not Clear(), it leaks, why?
677 //_____________________________________________________________________
678 Bool_t AliAnalysisTaskEMCALClusterize::AccessOCDB()
680 //Access to OCDB stuff
682 AliVEvent * event = InputEvent();
685 Warning("AccessOCDB","Event not available!!!");
689 if (event->GetRunNumber()==fRun)
691 fRun = event->GetRunNumber();
693 if(DebugLevel() > 1 )
694 Info("AccessODCD()"," Begin");
696 fGeom = AliEMCALGeometry::GetInstance(fGeomName);
699 AliCDBManager *cdb = AliCDBManager::Instance();
702 if (fOCDBpath.Length()){
703 cdb->SetDefaultStorage(fOCDBpath.Data());
704 Info("AccessOCDB","Default storage %s",fOCDBpath.Data());
707 cdb->SetRun(event->GetRunNumber());
710 // EMCAL from RAW OCDB
711 if (fOCDBpath.Contains("alien:"))
713 cdb->SetSpecificStorage("EMCAL/Calib/Data","alien://Folder=/alice/data/2010/OCDB");
714 cdb->SetSpecificStorage("EMCAL/Calib/Pedestals","alien://Folder=/alice/data/2010/OCDB");
717 TString path = cdb->GetDefaultStorage()->GetBaseFolder();
721 //Get calibration parameters
724 AliCDBEntry *entry = (AliCDBEntry*)
725 AliCDBManager::Instance()->Get("EMCAL/Calib/Data");
727 if (entry) fCalibData = (AliEMCALCalibData*) entry->GetObject();
731 AliFatal("Calibration parameters not found in CDB!");
733 //Get calibration parameters
736 AliCDBEntry *entry = (AliCDBEntry*)
737 AliCDBManager::Instance()->Get("EMCAL/Calib/Pedestals");
739 if (entry) fPedestalData = (AliCaloCalibPedestal*) entry->GetObject();
743 AliFatal("Dead map not found in CDB!");
745 InitClusterization();
750 //________________________________________________________________________________________
751 void AliAnalysisTaskEMCALClusterize::InitClusterization()
753 //Select clusterization/unfolding algorithm and set all the needed parameters
756 // init the unfolding afterburner
758 fUnfolder = new AliEMCALAfterBurnerUF(fRecParam->GetW0(),fRecParam->GetLocMaxCut());
762 //First init the clusterizer
764 if (fRecParam->GetClusterizerFlag() == AliEMCALRecParam::kClusterizerv1)
765 fClusterizer = new AliEMCALClusterizerv1 (fGeom, fCalibData, fPedestalData);
766 else if(fRecParam->GetClusterizerFlag() == AliEMCALRecParam::kClusterizerNxN)
767 fClusterizer = new AliEMCALClusterizerNxN(fGeom, fCalibData, fPedestalData);
768 else if(fRecParam->GetClusterizerFlag() > AliEMCALRecParam::kClusterizerNxN) {
769 AliEMCALClusterizerNxN *clusterizer = new AliEMCALClusterizerNxN(fGeom, fCalibData, fPedestalData);
770 clusterizer->SetNRowDiff(2);
771 clusterizer->SetNColDiff(2);
772 fClusterizer = clusterizer;
774 AliFatal(Form("Clusterizer < %d > not available", fRecParam->GetClusterizerFlag()));
777 //Now set the parameters
778 fClusterizer->SetECAClusteringThreshold( fRecParam->GetClusteringThreshold() );
779 fClusterizer->SetECALogWeight ( fRecParam->GetW0() );
780 fClusterizer->SetMinECut ( fRecParam->GetMinECut() );
781 fClusterizer->SetUnfolding ( fRecParam->GetUnfold() );
782 fClusterizer->SetECALocalMaxCut ( fRecParam->GetLocMaxCut() );
783 fClusterizer->SetTimeCut ( fRecParam->GetTimeCut() );
784 fClusterizer->SetTimeMin ( fRecParam->GetTimeMin() );
785 fClusterizer->SetTimeMax ( fRecParam->GetTimeMax() );
786 fClusterizer->SetInputCalibrated ( kTRUE );
787 fClusterizer->SetJustClusters ( kTRUE );
788 //In case of unfolding after clusterization is requested, set the corresponding parameters
789 if(fRecParam->GetUnfold()){
791 for (i = 0; i < 8; i++) {
792 fClusterizer->SetSSPars(i, fRecParam->GetSSPars(i));
793 }//end of loop over parameters
794 for (i = 0; i < 3; i++) {
795 fClusterizer->SetPar5 (i, fRecParam->GetPar5(i));
796 fClusterizer->SetPar6 (i, fRecParam->GetPar6(i));
797 }//end of loop over parameters
799 fClusterizer->InitClusterUnfolding();
803 //________________________________________________________________________________________
804 void AliAnalysisTaskEMCALClusterize::RecPoints2Clusters(TClonesArray *digitsArr, TObjArray *recPoints, TObjArray *clusArray)
806 // Restore clusters from recPoints
807 // Cluster energy, global position, cells and their amplitude fractions are restored
809 for(Int_t i = 0; i < recPoints->GetEntriesFast(); i++)
811 AliEMCALRecPoint *recPoint = (AliEMCALRecPoint*) recPoints->At(i);
813 const Int_t ncells = recPoint->GetMultiplicity();
814 Int_t ncells_true = 0;
816 // cells and their amplitude fractions
817 UShort_t absIds[ncells];
818 Double32_t ratios[ncells];
820 for (Int_t c = 0; c < ncells; c++) {
821 AliEMCALDigit *digit = (AliEMCALDigit*) digitsArr->At(recPoint->GetDigitsList()[c]);
823 absIds[ncells_true] = digit->GetId();
824 ratios[ncells_true] = recPoint->GetEnergiesList()[c]/digit->GetAmplitude();
826 if (ratios[ncells_true] > 0.001) ncells_true++;
829 if (ncells_true < 1) {
830 Warning("AliAnalysisTaskEMCALClusterize::RecPoints2Clusters", "skipping cluster with no cells");
837 // calculate new cluster position
838 recPoint->EvalGlobalPosition(fRecParam->GetW0(), digitsArr);
839 recPoint->GetGlobalPosition(gpos);
842 // create a new cluster
843 AliAODCaloCluster *clus = new AliAODCaloCluster();
844 clus->SetType(AliVCluster::kEMCALClusterv1);
845 clus->SetE(recPoint->GetEnergy());
846 clus->SetPosition(g);
847 clus->SetNCells(ncells_true);
848 clus->SetCellsAbsId(absIds);
849 clus->SetCellsAmplitudeFraction(ratios);
850 clus->SetDispersion(recPoint->GetDispersion());
851 clus->SetChi2(-1); //not yet implemented
852 clus->SetTOF(recPoint->GetTime()) ; //time-of-flight
853 clus->SetNExMax(recPoint->GetNExMax()); //number of local maxima
855 recPoint->GetElipsAxis(elipAxis);
856 clus->SetM02(elipAxis[0]*elipAxis[0]) ;
857 clus->SetM20(elipAxis[1]*elipAxis[1]) ;
858 clus->SetDistanceToBadChannel(recPoint->GetDistanceToBadTower());
861 Int_t parentMult = 0;
862 Int_t *parentList = recPoint->GetParents(parentMult);
863 clus->SetLabel(parentList, parentMult);
865 //Write the second major contributor to each MC cluster.
867 for ( Int_t iLoopCell = 0 ; iLoopCell < clus->GetNCells() ; iLoopCell++ ){
869 Int_t idCell = clus->GetCellAbsId(iLoopCell) ;
871 iNewLabel = 1 ; //iNewLabel makes sure we don't write twice the same label.
872 for ( UInt_t iLoopLabels = 0 ; iLoopLabels < clus->GetNLabels() ; iLoopLabels++ )
874 if ( fCellSecondLabels[idCell] == -1 ) iNewLabel = 0; // -1 is never a good second label.
875 if ( fCellSecondLabels[idCell] == clus->GetLabelAt(iLoopLabels) ) iNewLabel = 0;
879 Int_t * newLabelArray = (Int_t*)malloc((clus->GetNLabels()+1)*sizeof(Int_t)) ;
880 for ( UInt_t iLoopNewLabels = 0 ; iLoopNewLabels < clus->GetNLabels() ; iLoopNewLabels++ ){
881 newLabelArray[iLoopNewLabels] = clus->GetLabelAt(iLoopNewLabels) ;
884 newLabelArray[clus->GetNLabels()] = fCellSecondLabels[idCell] ;
885 clus->SetLabel(newLabelArray,clus->GetNLabels()+1) ;
886 delete [] newLabelArray;
888 }//positive cell number
891 clusArray->Add(clus);