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 ///////////////////////////////////////////////////////////////////////////////
19 // EMCAL tender, apply corrections to EMCAl clusters //
20 // and do track matching. //
21 // Author: Deepa Thomas (Utrecht University) //
23 ///////////////////////////////////////////////////////////////////////////////
28 #include <TInterpreter.h>
29 #include <TObjArray.h>
30 #include <TClonesArray.h>
31 #include <TGeoGlobalMagField.h>
33 #include <AliESDEvent.h>
34 #include <AliAnalysisManager.h>
35 #include <AliTender.h>
36 #include "AliOADBContainer.h"
37 #include "AliCDBManager.h"
38 #include "AliCDBStorage.h"
39 #include "AliCDBEntry.h"
41 #include "AliESDCaloCluster.h"
42 #include "AliEMCALTenderSupply.h"
43 #include "AliEMCALGeometry.h"
44 #include "AliEMCALRecoUtils.h"
45 #include "AliEMCALClusterizer.h"
46 #include "AliEMCALRecParam.h"
47 #include "AliEMCALRecPoint.h"
48 #include "AliEMCALAfterBurnerUF.h"
49 #include "AliEMCALClusterizerNxN.h"
50 #include "AliEMCALClusterizerv1.h"
51 #include "AliEMCALClusterizerv2.h"
52 #include "AliEMCALDigit.h"
54 ClassImp(AliEMCALTenderSupply)
56 AliEMCALTenderSupply::AliEMCALTenderSupply() :
59 ,fEMCALGeoName("EMCAL_COMPLETEV1")
63 ,fNonLinearFunc(AliEMCALRecoUtils::kNoCorrection)
64 ,fNonLinearThreshold(30)
65 ,fReCalibCluster(kFALSE)
68 ,fRecalClusPos(kFALSE)
70 ,fNCellsFromEMCALBorder(1)
71 ,fRecalDistToBadChannels(kFALSE)
78 ,fCutEtaPhiSeparate(kFALSE)
83 ,fReClusterize(kFALSE)
85 ,fGeomMatrixSet(kFALSE)
86 ,fLoadGeomMatrices(kFALSE)
93 ,fMisalignSurvey(kdefault)
95 // Default constructor.
96 for(Int_t i = 0; i < 10; i++) fEMCALMatrix[i] = 0 ;
99 //_____________________________________________________
100 AliEMCALTenderSupply::AliEMCALTenderSupply(const char *name, const AliTender *tender) :
101 AliTenderSupply(name,tender)
103 ,fEMCALGeoName("EMCAL_COMPLETEV1")
107 ,fNonLinearFunc(AliEMCALRecoUtils::kNoCorrection)
108 ,fNonLinearThreshold(30)
109 ,fReCalibCluster(kFALSE)
110 ,fReCalibCell(kFALSE)
112 ,fRecalClusPos(kFALSE)
114 ,fNCellsFromEMCALBorder(1)
115 ,fRecalDistToBadChannels(kFALSE)
121 ,fCutEtaPhiSum(kTRUE)
122 ,fCutEtaPhiSeparate(kFALSE)
127 ,fReClusterize(kFALSE)
129 ,fGeomMatrixSet(kFALSE)
130 ,fLoadGeomMatrices(kFALSE)
132 ,fRecParamSet(kFALSE)
137 ,fMisalignSurvey(kdefault)
141 for(Int_t i = 0; i < 10; i++) fEMCALMatrix[i] = 0 ;
143 fEMCALRecoUtils = new AliEMCALRecoUtils();
144 fRecParam = new AliEMCALRecParam;
145 fDigitsArr = new TClonesArray("AliEMCALDigit",1000);
148 //_____________________________________________________
149 AliEMCALTenderSupply::~AliEMCALTenderSupply()
153 delete fEMCALRecoUtils;
157 fDigitsArr->Clear("C");
162 //_____________________________________________________
163 void AliEMCALTenderSupply::Init()
165 // Initialise EMCAL tender.
168 AliInfo("Init EMCAL Tender supply");
170 if(fConfigName.Length()>0 && gROOT->LoadMacro(fConfigName) >=0) {
171 AliDebug(1, Form("Loading settings from macro %s", fConfigName.Data()));
172 AliEMCALTenderSupply *tender = (AliEMCALTenderSupply*)gInterpreter->ProcessLine("ConfigEMCALTenderSupply()");
173 fDebugLevel = tender->fDebugLevel;
174 fEMCALGeoName = tender->fEMCALGeoName;
175 delete fEMCALRecoUtils;
176 fEMCALRecoUtils = tender->fEMCALRecoUtils;
177 fConfigName = tender->fConfigName;
178 fNonLinearFunc = tender->fNonLinearFunc;
179 fNonLinearThreshold = tender->fNonLinearThreshold;
180 fReCalibCluster = tender->fReCalibCluster;
181 fReCalibCell = tender->fReCalibCell;
182 fRecalClusPos = tender->fRecalClusPos;
183 fFiducial = tender->fFiducial;
184 fNCellsFromEMCALBorder = tender->fNCellsFromEMCALBorder;
185 fRecalDistToBadChannels = tender->fRecalDistToBadChannels;
186 fMass = tender->fMass;
187 fStep = tender->fStep;
188 fRcut = tender->fRcut;
189 fEtacut = tender->fEtacut;
190 fPhicut = tender->fPhicut;
191 fReClusterize = tender->fReClusterize;
192 fLoadGeomMatrices = tender->fLoadGeomMatrices;
193 fRecParam = tender->fRecParam;
194 fOCDBpath = tender->fOCDBpath;
195 for(Int_t i = 0; i < 10; i++)
196 fEMCALMatrix[i] = tender->fEMCALMatrix[i] ;
200 fEMCALGeo = AliEMCALGeometry::GetInstance(fEMCALGeoName) ;
202 // Initialising Non linearity parameters
203 fEMCALRecoUtils->SetNonLinearityThreshold(fNonLinearThreshold);
204 fEMCALRecoUtils->SetNonLinearityFunction(fNonLinearFunc);
206 // Setting mass, step size and residual cut
207 fEMCALRecoUtils->SetMass(fMass);
208 fEMCALRecoUtils->SetStep(fStep);
210 fEMCALRecoUtils->SwitchOnCutEtaPhiSum();
211 fEMCALRecoUtils->SetCutR(fRcut);
212 } else if (fCutEtaPhiSeparate) {
213 fEMCALRecoUtils->SwitchOnCutEtaPhiSeparate();
214 fEMCALRecoUtils->SetCutEta(fEtacut);
215 fEMCALRecoUtils->SetCutPhi(fPhicut);
219 //_____________________________________________________
220 void AliEMCALTenderSupply::ProcessEvent()
224 AliESDEvent *event = fTender->GetEvent();
226 AliError("ESD event ptr = 0, returning");
235 fRecParamSet = kTRUE;
239 // Initialising parameters once per run number
240 if(fTender->RunChanged()){
243 Int_t fInitBC=InitBadChannels();
247 AliError("InitBadChannels returned false, returning");
252 AliInfo(Form("No external hot channel set: %d - %s", event->GetRunNumber(), fFilepass.Data()));
255 if (fReCalibCluster || fReCalibCell || fUpdateCell) {
256 Int_t fInitRecalib=InitRecalib();
259 AliError("InitRecalib returned false, returning");
264 AliInfo(Form("No recalibration available: %d - %s", event->GetRunNumber(), fFilepass.Data()));
266 fReCalibCluster=kFALSE;
270 if (fRecalClusPos || fReClusterize || fUpdateCell) {
271 if (!InitMisalignMatrix()) {
272 AliError("InitMisalignmentMatrix returned false, returning");
277 if (fReClusterize || fUpdateCell) {
278 if (!InitClusterization()) {
279 AliError("InitClusterization returned false, returning");
285 fEMCALRecoUtils->Print("");
289 // Test if cells present
290 AliESDCaloCells *cells= event->GetEMCALCells();
291 if (cells->GetNumberOfCells()<=0) {
292 AliWarning(Form("Number of EMCAL cells = %d, returning", cells->GetNumberOfCells()));
297 if (fReCalibCell || fUpdateCell)
300 fReCalibCluster=kFALSE;
303 AliInfo(Form("Re-calibrate cluster %d\n",fReCalibCluster));
307 printf("Update cells\n");
321 // Store good clusters
322 TClonesArray *clusArr = dynamic_cast<TClonesArray*>(event->FindListObject("caloClusters"));
324 clusArr = dynamic_cast<TClonesArray*>(event->FindListObject("CaloClusters"));
326 AliWarning(Form("No cluster array, number of cells in event = %d, returning", cells->GetNumberOfCells()));
329 Int_t nclusters = clusArr->GetEntriesFast();
331 for (Int_t icluster=0; icluster < nclusters; ++icluster) {
332 AliVCluster *clust = static_cast<AliVCluster*>(clusArr->At(icluster));
335 if (!clust->IsEMCAL())
338 if (fEMCALRecoUtils->ClusterContainsBadChannel(fEMCALGeo, clust->GetCellsAbsId(), clust->GetNCells())) {
339 delete clusArr->RemoveAt(icluster);
340 continue; //todo is it really needed to remove it? Or should we flag it?
344 if (!fEMCALRecoUtils->CheckCellFiducialRegion(fEMCALGeo, clust, cells)){
345 delete clusArr->RemoveAt(icluster);
346 continue; // todo it would be nice to store the distance
350 fEMCALRecoUtils->CorrectClusterEnergyLinearity(clust);
351 if(fRecalDistToBadChannels)
352 fEMCALRecoUtils->RecalculateClusterDistanceToBadChannel(fEMCALGeo, cells, clust);
354 fEMCALRecoUtils->RecalibrateClusterEnergy(fEMCALGeo, clust, cells);
356 fEMCALRecoUtils->RecalculateClusterPosition(fEMCALGeo, cells, clust);
361 if (!TGeoGlobalMagField::Instance()->GetField()) {
362 const AliESDRun *erun = event->GetESDRun();
363 AliMagF *field = AliMagF::CreateFieldMap(erun->GetCurrentL3(),
364 erun->GetCurrentDip(),
367 erun->GetBeamEnergy(),
368 erun->GetBeamType());
369 TGeoGlobalMagField::Instance()->SetField(field);
372 fEMCALRecoUtils->FindMatches(event,0x0,fEMCALGeo);
374 SetClusterMatchedToTrack(event);
375 SetTracksMatchedToCluster(event);
379 //_____________________________________________________
380 void AliEMCALTenderSupply::SetClusterMatchedToTrack(AliESDEvent *event)
382 // Checks if tracks are matched to EMC clusters and set the matched EMCAL cluster index to ESD track.
384 Int_t nTracks = event->GetNumberOfTracks();
385 for (Int_t iTrack = 0; iTrack < nTracks; ++iTrack) {
386 AliESDtrack* track = event->GetTrack(iTrack);
388 AliWarning(Form("Could not receive track %d", iTrack));
391 Int_t matchClusIndex = fEMCALRecoUtils->GetMatchedClusterIndex(iTrack);
392 track->SetEMCALcluster(matchClusIndex); //sets -1 if track not matched within residual
393 if(matchClusIndex != -1)
394 track->SetStatus(AliESDtrack::kEMCALmatch);
396 track->ResetStatus(AliESDtrack::kEMCALmatch);
399 AliInfo("Track matched to closest cluster");
402 //_____________________________________________________
403 void AliEMCALTenderSupply::SetTracksMatchedToCluster(AliESDEvent *event)
405 // Checks if EMC clusters are matched to ESD track.
406 // Adds track indexes of all the tracks matched to a cluster withing residuals in ESDCalocluster.
408 for (Int_t iClus=0; iClus < event->GetNumberOfCaloClusters(); ++iClus) {
409 AliESDCaloCluster *cluster = event->GetCaloCluster(iClus);
410 if (!cluster->IsEMCAL())
413 Int_t nTracks = event->GetNumberOfTracks();
414 TArrayI arrayTrackMatched(nTracks);
416 // Get the closest track matched to the cluster
418 Int_t matchTrackIndex = fEMCALRecoUtils->GetMatchedTrackIndex(iClus);
419 if (matchTrackIndex != -1) {
420 arrayTrackMatched[nMatched] = matchTrackIndex;
424 // Get all other tracks matched to the cluster
425 for(Int_t iTrk=0; iTrk<nTracks; ++iTrk) {
426 AliESDtrack* track = event->GetTrack(iTrk);
427 if(iTrk == matchTrackIndex) continue;
428 if(track->GetEMCALcluster() == iClus){
429 arrayTrackMatched[nMatched] = iTrk;
434 arrayTrackMatched.Set(nMatched);
435 cluster->AddTracksMatched(arrayTrackMatched);
437 Float_t eta= -999, phi = -999;
438 if (matchTrackIndex != -1)
439 fEMCALRecoUtils->GetMatchedResiduals(iClus, eta, phi);
440 cluster->SetTrackDistance(phi, eta);
444 AliInfo("Cluster matched to tracks");
447 //_____________________________________________________
448 Bool_t AliEMCALTenderSupply::InitMisalignMatrix()
450 // Initialising misalignment matrices
452 AliESDEvent *event = fTender->GetEvent();
456 if (fGeomMatrixSet) {
457 AliInfo("Misalignment matrix already set");
462 AliInfo("Initialising misalignment matrix");
464 fEMCALRecoUtils->SetPositionAlgorithm(AliEMCALRecoUtils::kPosTowerGlobal);
466 if (fLoadGeomMatrices) {
467 for(Int_t mod=0; mod < fEMCALGeo->GetNumberOfSuperModules(); ++mod) {
468 if (fEMCALMatrix[mod]){
470 fEMCALMatrix[mod]->Print();
471 fEMCALGeo->SetMisalMatrix(fEMCALMatrix[mod],mod);
474 fGeomMatrixSet = kTRUE;
478 Int_t runGM = event->GetRunNumber();
481 if(fMisalignSurvey == kdefault){ //take default alignment corresponding to run no
482 AliOADBContainer emcalgeoCont(Form("emcal"));
483 emcalgeoCont.InitFromFile("$ALICE_ROOT/OADB/EMCAL/EMCALlocal2master.root",Form("AliEMCALgeo"));
484 mobj=(TObjArray*)emcalgeoCont.GetObject(runGM,"EmcalMatrices");
487 if(fMisalignSurvey == kSurveybyS){ //take alignment at sector level
488 if (runGM <= 140000) { //2010 data
489 AliOADBContainer emcalgeoCont(Form("emcal2010"));
490 emcalgeoCont.InitFromFile("$ALICE_ROOT/OADB/EMCAL/EMCALlocal2master.root",Form("AliEMCALgeo"));
491 mobj=(TObjArray*)emcalgeoCont.GetObject(100,"survey10");
493 } else if (runGM>140000) { // 2011 LHC11a pass1 data
494 AliOADBContainer emcalgeoCont(Form("emcal2011"));
495 emcalgeoCont.InitFromFile("$ALICE_ROOT/OADB/EMCAL/EMCALlocal2master.root",Form("AliEMCALgeo"));
496 mobj=(TObjArray*)emcalgeoCont.GetObject(100,"survey11byS");
500 if(fMisalignSurvey == kSurveybyS){ //take alignment at module level
501 if (runGM <= 140000) { //2010 data
502 AliOADBContainer emcalgeoCont(Form("emcal2010"));
503 emcalgeoCont.InitFromFile("$ALICE_ROOT/OADB/EMCAL/EMCALlocal2master.root",Form("AliEMCALgeo"));
504 mobj=(TObjArray*)emcalgeoCont.GetObject(100,"survey10");
506 } else if (runGM>140000) { // 2011 LHC11a pass1 data
507 AliOADBContainer emcalgeoCont(Form("emcal2011"));
508 emcalgeoCont.InitFromFile("$ALICE_ROOT/OADB/EMCAL/EMCALlocal2master.root",Form("AliEMCALgeo"));
509 mobj=(TObjArray*)emcalgeoCont.GetObject(100,"survey11byM");
513 for(Int_t mod=0; mod < (fEMCALGeo->GetEMCGeometry())->GetNumberOfSuperModules(); mod++){
514 fEMCALMatrix[mod] = (TGeoHMatrix*) mobj->At(mod);
515 fEMCALGeo->SetMisalMatrix(fEMCALMatrix[mod],mod);
516 fEMCALMatrix[mod]->Print();
521 //_____________________________________________________
522 Int_t AliEMCALTenderSupply::InitBadChannels()
524 // Initialising bad channel maps
525 AliESDEvent *event = fTender->GetEvent();
530 AliInfo("Initialising Bad channel map");
533 fEMCALRecoUtils->SetNumberOfCellsFromEMCALBorder(fNCellsFromEMCALBorder);
534 fEMCALRecoUtils->SwitchOnNoFiducialBorderInEMCALEta0();
537 fEMCALRecoUtils->SwitchOnBadChannelsRemoval();
538 if (fRecalDistToBadChannels)
539 fEMCALRecoUtils->SwitchOnDistToBadChannelRecalculation();
541 Int_t runBC = event->GetRunNumber();
543 AliOADBContainer *contBC=new AliOADBContainer("");
544 if(fBasePath!=""){ //if fBasePath specified in the ->SetBasePath()
545 if (fDebugLevel>0) AliInfo(Form("Loading Bad Channels OADB from given path %s",fBasePath.Data()));
546 TFile *fbad=new TFile(Form("%s/EMCALBadChannels.root",fBasePath.Data()),"read");
547 if(fbad->IsZombie()){
548 AliFatal(Form("EMCALBadChannels.root was not found in the path provided: %s, aborting",fBasePath.Data()));
551 if(fbad) delete fbad;
552 contBC->InitFromFile(Form("%s/EMCALBadChannels.root",fBasePath.Data()),"AliEMCALBadChannels");
554 else { // Else choose the one in the $ALICE_ROOT directory
555 if (fDebugLevel>0) AliInfo("Loading Bad Channels OADB from $ALICE_ROOT/OADB/EMCAL");
556 TFile *fbad=new TFile("$ALICE_ROOT/OADB/EMCAL/EMCALBadChannels.root","read");
557 if(fbad->IsZombie()){
558 AliFatal("$ALICE_ROOT/OADB/EMCAL/EMCALBadChannels.root was not found, aborting");
561 if(fbad) delete fbad;
562 contBC->InitFromFile("$ALICE_ROOT/OADB/EMCAL/EMCALBadChannels.root","AliEMCALBadChannels");
565 TObjArray *arrayBC=(TObjArray*)contBC->GetObject(runBC);
567 AliError(Form("No external hot channel set for run number: %d", runBC));
571 TObjArray *arrayBCpass=(TObjArray*)arrayBC->FindObject(fFilepass); // Here, it looks for a specific pass
573 AliError(Form("No external hot channel set for: %d -%s", runBC,fFilepass.Data()));
577 if(fDebugLevel>0) arrayBCpass->Print();
579 Int_t sms = fEMCALGeo->GetEMCGeometry()->GetNumberOfSuperModules();
580 for (Int_t i=0; i<sms; ++i) {
581 TH2I *h = fEMCALRecoUtils->GetEMCALChannelStatusMap(i);
584 h=(TH2I*)arrayBCpass->FindObject(Form("EMCALBadChannelMap_Mod%d",i));
587 AliError(Form("Can not get EMCALBadChannelMap_Mod%d",i));
591 fEMCALRecoUtils->SetEMCALChannelStatusMap(i,h);
598 //_____________________________________________________
599 Int_t AliEMCALTenderSupply::InitRecalib()
601 // Initialising recalibration factors.
603 AliESDEvent *event = fTender->GetEvent();
608 AliInfo("Initialising recalibration factors");
610 fEMCALRecoUtils->SwitchOnRecalibration();
611 Int_t runRC = event->GetRunNumber();
613 AliOADBContainer *contRF=new AliOADBContainer("");
614 if(fBasePath!="") { //if fBasePath specified in the ->SetBasePath()
615 if (fDebugLevel>0) AliInfo(Form("Loading Recalib OADB from given path %s",fBasePath.Data()));
616 TFile *fRecalib= new TFile(Form("%s/EMCALRecalib.root",fBasePath.Data()),"read");
617 if (fRecalib->IsZombie()) {
618 AliFatal(Form("EMCALRecalib.root not found in %s, aborting",fBasePath.Data()));
621 if(fRecalib) delete fRecalib;
622 contRF->InitFromFile(Form("%s/EMCALRecalib.root",fBasePath.Data()),"AliEMCALRecalib");
624 else{ // Else choose the one in the $ALICE_ROOT directory
625 if (fDebugLevel>0) AliInfo("Loading Recalib OADB from $ALICE_ROOT/OADB/EMCAL");
626 TFile *fRecalib= new TFile("$ALICE_ROOT/OADB/EMCAL/EMCALRecalib.root","read");
627 if (fRecalib->IsZombie()) {
628 AliFatal("$ALICE_ROOT/OADB/EMCAL/EMCALRecalib.root was not found, aborting");
631 if(fRecalib) delete fRecalib;
632 contRF->InitFromFile("$ALICE_ROOT/OADB/EMCAL/EMCALRecalib.root","AliEMCALRecalib");
635 TObjArray *recal=(TObjArray*)contRF->GetObject(runRC); //GetObject(int runnumber)
637 AliError(Form("No Objects for run: %d",runRC));
641 TObjArray *recalpass=(TObjArray*)recal->FindObject(fFilepass);
643 AliError(Form("No Objects for run: %d - %s",runRC,fFilepass.Data()));
647 TObjArray *recalib=(TObjArray*)recalpass->FindObject("Recalib");
649 AliError(Form("No Recalib histos found for %d - %s",runRC,fFilepass.Data()));
653 if(fDebugLevel>0) recalib->Print();
655 Int_t sms = fEMCALGeo->GetEMCGeometry()->GetNumberOfSuperModules();
656 for (Int_t i=0; i<sms; ++i) {
657 TH2F *h = fEMCALRecoUtils->GetEMCALChannelRecalibrationFactors(i);
660 h = (TH2F*)recalib->FindObject(Form("EMCALRecalFactors_SM%d",i));
662 AliError(Form("Could not load EMCALRecalFactors_SM%d",i));
666 fEMCALRecoUtils->SetEMCALChannelRecalibrationFactors(i,h);
671 //_____________________________________________________
672 void AliEMCALTenderSupply::RecalibrateCells()
674 // Recalibrate cells.
676 AliESDCaloCells *cells = fTender->GetEvent()->GetEMCALCells();
678 Int_t nEMCcell = cells->GetNumberOfCells();
679 for(Int_t icell=0; icell<nEMCcell; ++icell) {
680 Int_t imod = -1, iphi =-1, ieta=-1,iTower = -1, iIphi = -1, iIeta = -1;
681 fEMCALGeo->GetCellIndex(cells->GetCellNumber(icell),imod,iTower,iIphi,iIeta);
682 fEMCALGeo->GetCellPhiEtaIndexInSModule(imod,iTower,iIphi, iIeta,iphi,ieta);
683 Double_t calibFactor = fEMCALRecoUtils->GetEMCALChannelRecalibrationFactor(imod,ieta,iphi);
684 cells->SetCell(icell,cells->GetCellNumber(icell),cells->GetAmplitude(icell)*calibFactor,cells->GetTime(icell));
689 //_____________________________________________________
690 void AliEMCALTenderSupply::UpdateCells()
692 //Remove bad cells from the cell list
693 //This is required for later reclusterization
695 AliESDCaloCells *cells = fTender->GetEvent()->GetEMCALCells();
697 Int_t nEMCcell = cells->GetNumberOfCells();
698 for(Int_t icell=0; icell<nEMCcell; ++icell)
700 Int_t cellId = cells->GetCellNumber(icell);
701 Int_t imod = -1, iphi =-1, ieta=-1,iTower = -1, iIphi = -1, iIeta = -1;
702 fEMCALGeo->GetCellIndex(cellId,imod,iTower,iIphi,iIeta);
703 fEMCALGeo->GetCellPhiEtaIndexInSModule(imod,iTower,iIphi, iIeta,iphi,ieta);
704 if(fEMCALRecoUtils->GetEMCALChannelStatus(imod,ieta,iphi))
706 cells->SetCell(icell,cellId,(-1)*cells->GetAmplitude(icell),cells->GetCellTime(cellId));
712 //_____________________________________________________
713 void AliEMCALTenderSupply::InitRecParam()
716 AliInfo("Initialize the recParam");
717 fRecParam = new AliEMCALRecParam;
721 //_____________________________________________________
722 Bool_t AliEMCALTenderSupply::InitClusterization()
724 // Initialing clusterization/unfolding algorithm and set all the needed parameters.
726 AliESDEvent *event=fTender->GetEvent();
731 AliInfo(Form("Initialising reclustering parameters: Clusterizer-%d",fRecParam->GetClusterizerFlag()));
733 //---setup clusterizer
735 if (fRecParam->GetClusterizerFlag() == AliEMCALRecParam::kClusterizerv1)
736 fClusterizer = new AliEMCALClusterizerv1 (fEMCALGeo);
737 else if(fRecParam->GetClusterizerFlag() == AliEMCALRecParam::kClusterizerv2)
738 fClusterizer = new AliEMCALClusterizerv2(fEMCALGeo);
739 else if(fRecParam->GetClusterizerFlag() == AliEMCALRecParam::kClusterizerNxN) {
740 AliEMCALClusterizerNxN *clusterizer = new AliEMCALClusterizerNxN(fEMCALGeo);
741 clusterizer->SetNRowDiff(fRecParam->GetNRowDiff());
742 clusterizer->SetNColDiff(fRecParam->GetNColDiff());
743 fClusterizer = clusterizer;
745 AliFatal(Form("Clusterizer < %d > not available", fRecParam->GetClusterizerFlag()));
749 // Set the clustering parameters
750 fClusterizer->SetECAClusteringThreshold( fRecParam->GetClusteringThreshold() );
751 fClusterizer->SetECALogWeight ( fRecParam->GetW0() );
752 fClusterizer->SetMinECut ( fRecParam->GetMinECut() );
753 fClusterizer->SetUnfolding ( fRecParam->GetUnfold() );
754 fClusterizer->SetECALocalMaxCut ( fRecParam->GetLocMaxCut() );
755 fClusterizer->SetTimeCut ( fRecParam->GetTimeCut() );
756 fClusterizer->SetTimeMin ( fRecParam->GetTimeMin() );
757 fClusterizer->SetTimeMax ( fRecParam->GetTimeMax() );
758 fClusterizer->SetInputCalibrated ( kTRUE );
759 fClusterizer->SetJustClusters ( kTRUE );
761 // In case of unfolding after clusterization is requested, set the corresponding parameters
762 if (fRecParam->GetUnfold()) {
763 for (Int_t i = 0; i < 8; ++i) {
764 fClusterizer->SetSSPars(i, fRecParam->GetSSPars(i));
766 for (Int_t i = 0; i < 3; ++i) {
767 fClusterizer->SetPar5 (i, fRecParam->GetPar5(i));
768 fClusterizer->SetPar6 (i, fRecParam->GetPar6(i));
770 fClusterizer->InitClusterUnfolding();
773 fClusterizer->SetDigitsArr(fDigitsArr);
774 fClusterizer->SetOutput(0);
775 fClusterArr = const_cast<TObjArray *>(fClusterizer->GetRecPoints());
779 //_____________________________________________________
780 void AliEMCALTenderSupply::FillDigitsArray()
782 // Fill digits from cells to a TClonesArray.
784 AliESDEvent *event = fTender->GetEvent();
788 fDigitsArr->Clear("C");
789 AliESDCaloCells *cells = event->GetEMCALCells();
790 Int_t ncells = cells->GetNumberOfCells();
791 for (Int_t icell = 0, idigit = 0; icell < ncells; ++icell) {
792 Double_t cellAmplitude=0, cellTime=0;
793 Short_t cellNumber=0;
794 if (cells->GetCell(icell, cellNumber, cellAmplitude, cellTime) != kTRUE)
796 AliEMCALDigit *digit = static_cast<AliEMCALDigit*>(fDigitsArr->New(idigit));
797 digit->SetId(cellNumber);
798 digit->SetTime(cellTime);
799 digit->SetTimeR(cellTime);
800 digit->SetIndexInList(idigit);
801 digit->SetType(AliEMCALDigit::kHG);
802 digit->SetAmplitude(cellAmplitude);
807 //_____________________________________________________
808 void AliEMCALTenderSupply::Clusterize()
812 fClusterizer->Digits2Clusters("");
815 //_____________________________________________________
816 void AliEMCALTenderSupply::UpdateClusters()
818 // Update ESD cluster list.
820 AliESDEvent *event = fTender->GetEvent();
824 TClonesArray *clus = dynamic_cast<TClonesArray*>(event->FindListObject("caloClusters"));
826 clus = dynamic_cast<TClonesArray*>(event->FindListObject("CaloClusters"));
828 AliError(" Null pointer to calo clusters array, returning");
832 Int_t nents = clus->GetEntriesFast();
833 for (Int_t i=0; i < nents; ++i) {
834 AliESDCaloCluster *c = static_cast<AliESDCaloCluster*>(clus->At(i));
838 delete clus->RemoveAt(i);
841 RecPoints2Clusters(clus);
844 //_____________________________________________________
845 void AliEMCALTenderSupply::RecPoints2Clusters(TClonesArray *clus)
847 // Convert AliEMCALRecoPoints to AliESDCaloClusters.
848 // Cluster energy, global position, cells and their amplitude fractions are restored.
850 AliESDEvent *event = fTender->GetEvent();
854 Int_t ncls = fClusterArr->GetEntriesFast();
855 for(Int_t i=0, nout=clus->GetEntriesFast(); i < ncls; ++i) {
856 AliEMCALRecPoint *recpoint = static_cast<AliEMCALRecPoint*>(fClusterArr->At(i));
858 Int_t ncells_true = 0;
859 const Int_t ncells = recpoint->GetMultiplicity();
860 UShort_t absIds[ncells];
861 Double32_t ratios[ncells];
862 Int_t *dlist = recpoint->GetDigitsList();
863 Float_t *elist = recpoint->GetEnergiesList();
864 for (Int_t c = 0; c < ncells; ++c) {
865 AliEMCALDigit *digit = static_cast<AliEMCALDigit*>(fDigitsArr->At(dlist[c]));
866 absIds[ncells_true] = digit->GetId();
867 ratios[ncells_true] = elist[c]/digit->GetAmplitude();
868 if (ratios[ncells_true] < 0.001)
873 if (ncells_true < 1) {
874 AliWarning("Skipping cluster with no cells");
878 // calculate new cluster position
880 recpoint->GetGlobalPosition(gpos);
884 AliESDCaloCluster *c = static_cast<AliESDCaloCluster*>(clus->New(nout++));
885 c->SetType(AliVCluster::kEMCALClusterv1);
886 c->SetE(recpoint->GetEnergy());
888 c->SetNCells(ncells_true);
889 c->SetDispersion(recpoint->GetDispersion());
890 c->SetEmcCpvDistance(-1); //not yet implemented
891 c->SetChi2(-1); //not yet implemented
892 c->SetTOF(recpoint->GetTime()) ; //time-of-flight
893 c->SetNExMax(recpoint->GetNExMax()); //number of local maxima
895 recpoint->GetElipsAxis(elipAxis);
896 c->SetM02(elipAxis[0]*elipAxis[0]) ;
897 c->SetM20(elipAxis[1]*elipAxis[1]) ;
898 AliESDCaloCluster *cesd = static_cast<AliESDCaloCluster*>(c);
899 cesd->SetCellsAbsId(absIds);
900 cesd->SetCellsAmplitudeFraction(ratios);
904 //_____________________________________________________
905 void AliEMCALTenderSupply::GetPass()
907 // Get passx from filename.
909 AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
910 fInputTree = mgr->GetTree();
913 AliError("Pointer to tree = 0, returning");
917 fInputFile = fInputTree->GetCurrentFile();
919 AliError("Null pointer input file, returning");
923 TString fname(fInputFile->GetName());
924 if (fname.Contains("pass1")) fFilepass = TString("pass1");
925 else if(fname.Contains("pass2")) fFilepass = TString("pass2");
926 else if(fname.Contains("pass3")) fFilepass = TString("pass3");
928 AliError(Form("Pass number string not found: %s", fname.Data()));