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 ///////////////////////////////////////////////////////////////////////////////
27 #include "TAlienFile.h"
30 #include "TInterpreter.h"
31 #include "TObjArray.h"
32 #include "TClonesArray.h"
35 #include <AliESDEvent.h>
36 #include <AliAnalysisManager.h>
37 #include <AliTender.h>
38 #include "AliOADBContainer.h"
39 #include "AliCDBManager.h"
40 #include "AliCDBStorage.h"
41 #include "AliCDBEntry.h"
43 #include "TGeoGlobalMagField.h"
45 #include "AliESDCaloCluster.h"
46 #include "AliEMCALTenderSupply.h"
49 #include "AliEMCALGeometry.h"
50 #include "AliEMCALRecoUtils.h"
51 #include "AliEMCALClusterizer.h"
52 #include "AliEMCALRecParam.h"
53 #include "AliEMCALRecPoint.h"
54 #include "AliEMCALAfterBurnerUF.h"
55 #include "AliEMCALClusterizerNxN.h"
56 #include "AliEMCALClusterizerv1.h"
57 #include "AliEMCALClusterizerv2.h"
58 #include "AliEMCALDigit.h"
61 // Remove all calls to TGrid::Connect - grid connection is global and better steer by the run macro
63 AliEMCALTenderSupply::AliEMCALTenderSupply() :
66 ,fEMCALGeoName("EMCAL_FIRSTYEARV1")
67 // ,fEMCALRecoUtils(new AliEMCALRecoUtils)
71 ,fNonLinearFunc(AliEMCALRecoUtils::kNoCorrection)
72 ,fNonLinearThreshold(30)
73 ,fReCalibCluster(kFALSE)
75 ,fRecalClusPos(kFALSE)
77 ,fNCellsFromEMCALBorder(1)
78 ,fRecalDistToBadChannels(kFALSE)
86 ,fReClusterize(kFALSE)
88 ,fGeomMatrixSet(kFALSE)
89 ,fLoadGeomMatrices(kFALSE)
100 for(Int_t i = 0; i < 10; i++) fEMCALMatrix[i] = 0 ;
101 for(Int_t i = 0; i < 10; i++) fGeomMatrix[i] = 0;
102 fRecParam = new AliEMCALRecParam;
103 fDigitsArr = new TClonesArray("AliEMCALDigit",1000);
107 //_____________________________________________________
108 AliEMCALTenderSupply::AliEMCALTenderSupply(const char *name, const AliTender *tender) :
109 AliTenderSupply(name,tender)
111 ,fEMCALGeoName("EMCAL_FIRSTYEARV1")
115 ,fNonLinearFunc(AliEMCALRecoUtils::kNoCorrection)
116 ,fNonLinearThreshold(30)
117 ,fReCalibCluster(kFALSE)
118 ,fReCalibCell(kFALSE)
119 ,fRecalClusPos(kFALSE)
121 ,fNCellsFromEMCALBorder(1)
122 ,fRecalDistToBadChannels(kFALSE)
130 ,fReClusterize(kFALSE)
132 ,fGeomMatrixSet(kFALSE)
133 ,fLoadGeomMatrices(kFALSE)
144 for(Int_t i = 0; i < 10; i++) fEMCALMatrix[i] = 0 ;
145 for(Int_t i = 0; i < 10; i++) fGeomMatrix[i] = 0;
146 fRecParam = new AliEMCALRecParam;
147 fDigitsArr = new TClonesArray("AliEMCALDigit",200);
150 //_____________________________________________________
151 AliEMCALTenderSupply::~AliEMCALTenderSupply()
155 delete fEMCALRecoUtils;
162 fDigitsArr->Clear("C");
168 //_____________________________________________________
169 void AliEMCALTenderSupply::Init()
172 // Initialise EMCAL tender
175 if (fDebugLevel>0) AliInfo("Init EMCAL Tender supply\n");
177 AliAnalysisManager *mgr=AliAnalysisManager::GetAnalysisManager();
179 fInputTree = mgr->GetTree();
181 if(gROOT->LoadMacro(fConfigName) >=0){
182 AliDebug(1, Form("Loading settings from macro %s", fConfigName.Data()));
183 AliEMCALTenderSupply *tender = (AliEMCALTenderSupply*)gInterpreter->ProcessLine("ConfigEMCALTenderSupply()");
184 fDebugLevel = tender->fDebugLevel;
185 fEMCALGeoName = tender->fEMCALGeoName;
186 fEMCALRecoUtils = tender->fEMCALRecoUtils;
187 fConfigName = tender->fConfigName;
188 fNonLinearFunc = tender->fNonLinearFunc;
189 fNonLinearThreshold = tender->fNonLinearThreshold;
190 fReCalibCluster = tender->fReCalibCluster;
191 fReCalibCell = tender->fReCalibCell;
192 fRecalClusPos = tender->fRecalClusPos;
193 fFiducial = tender->fFiducial;
194 fNCellsFromEMCALBorder = tender->fNCellsFromEMCALBorder;
195 fRecalDistToBadChannels = tender->fRecalDistToBadChannels;
196 fMass = tender->fMass;
197 fStep = tender->fStep;
198 fRcut = tender->fRcut;
199 fReClusterize = tender->fReClusterize;
200 fLoadGeomMatrices = tender->fLoadGeomMatrices;
201 fRecParam = tender->fRecParam;
202 fOCDBpath = tender->fOCDBpath;
203 for(Int_t i = 0; i < 10; i++) fGeomMatrix[i] = tender->fGeomMatrix[i] ;
207 fEMCALGeo = AliEMCALGeometry::GetInstance(fEMCALGeoName) ;
209 fEMCALRecoUtils = new AliEMCALRecoUtils();
211 //Initialising Non linearity parameters
212 fEMCALRecoUtils->SetNonLinearityThreshold(fNonLinearThreshold);
214 //Setting mass, step size and residual cut
215 fEMCALRecoUtils->SwitchOnCutEtaPhiSum();
216 fEMCALRecoUtils->SetCutR(fRcut);
217 fEMCALRecoUtils->SetMass(fMass);
218 fEMCALRecoUtils->SetStep(fStep);
220 if(fDebugLevel>1) fEMCALRecoUtils->Print("");
225 //_____________________________________________________
226 void AliEMCALTenderSupply::ProcessEvent()
229 AliESDEvent *event=fTender->GetEvent();
232 if(fTender->RunChanged()){
233 //Initialising parameters once per run number
234 if (!InitBadChannels()) return;
235 if (fRecalClusPos){ if (!InitMisalignMatrix()) return;}
236 if (fReCalibCluster || fReCalibCell){ if (!InitRecalib()) return;}
237 if (fReClusterize) InitClusterization();
240 AliESDCaloCells *cells= event->GetEMCALCells();
242 //------------ EMCAL cells loop ------------
245 if(fReCalibCell) RecalibrateCells();
247 //------------ Reclusterize ------------
254 //------------Good clusters------------
255 TClonesArray *clusArr;
257 clusArr = dynamic_cast<TClonesArray*>(event->FindListObject("caloClusters"));
258 if(!clusArr) clusArr = dynamic_cast<TClonesArray*>(event->FindListObject("CaloClusters"));
261 for (Int_t icluster=0; icluster < clusArr->GetEntries(); icluster++ ){
262 AliVCluster *clust = static_cast<AliVCluster*>(clusArr->At(icluster));
264 if (!clust->IsEMCAL()) continue;
265 if(fEMCALRecoUtils->ClusterContainsBadChannel(fEMCALGeo, clust->GetCellsAbsId(), clust->GetNCells() )){
266 delete clusArr->RemoveAt(icluster);
270 if(!fEMCALRecoUtils->CheckCellFiducialRegion(fEMCALGeo, clust, cells)){
271 delete clusArr->RemoveAt(icluster);
275 fEMCALRecoUtils->CorrectClusterEnergyLinearity(clust);
276 if(fRecalDistToBadChannels) fEMCALRecoUtils->RecalculateClusterDistanceToBadChannel(fEMCALGeo, cells, clust);
277 if(fReCalibCluster) fEMCALRecoUtils->RecalibrateClusterEnergy(fEMCALGeo, clust, cells);
278 if(fRecalClusPos) fEMCALRecoUtils->RecalculateClusterPosition(fEMCALGeo, cells, clust);
279 //fEMCALRecoUtils->SetTimeDependentCorrections(event->GetRunNumber());
284 //-------- Track Matching ------------------
287 Double_t magF = event->GetMagneticField();
288 Double_t magSign = 1.0;
289 if(magF<0)magSign = -1.0;
291 if (!TGeoGlobalMagField::Instance()->GetField())
293 AliMagF* field = new AliMagF("Maps","Maps", magSign, magSign, AliMagF::k5kG);
294 TGeoGlobalMagField::Instance()->SetField(field);
298 fEMCALRecoUtils->FindMatches(event,0x0,fEMCALGeo);
300 Int_t nTracks = event->GetNumberOfTracks();
303 SetClusterMatchedToTrack(event);
304 SetTracksMatchedToCluster(event);
309 //_____________________________________________________
310 void AliEMCALTenderSupply::SetClusterMatchedToTrack(AliESDEvent *event)
312 //checks if tracks are matched to EMC clusters and set the matched EMCAL cluster index to ESD track.
314 Int_t matchClusIndex = -1;
315 Int_t nTracks = event->GetNumberOfTracks();
318 for (Int_t iTrack = 0; iTrack < nTracks; iTrack++)
320 AliESDtrack* track = event->GetTrack(iTrack);
322 printf("ERROR: Could not receive track %d\n", iTrack);
326 matchClusIndex = fEMCALRecoUtils->GetMatchedClusterIndex(iTrack);
327 track->SetEMCALcluster(matchClusIndex); //sets -1 if track not matched within residual
330 if (fDebugLevel>2) AliInfo("Track matched to closest cluster\n");
333 //_____________________________________________________
334 void AliEMCALTenderSupply::SetTracksMatchedToCluster(AliESDEvent *event)
336 //checks if EMC clusters are matched to ESD track.
337 //Adds track indexes of all the tracks matched to a cluster withing residuals in ESDCalocluster
339 Int_t matchTrackIndex = -1;
340 Int_t nTracks = event->GetNumberOfTracks();
343 for (Int_t iClus=0; iClus < event->GetNumberOfCaloClusters(); iClus++)
345 AliESDCaloCluster * cluster = event->GetCaloCluster(iClus);
346 if (!cluster->IsEMCAL()) continue;
349 TArrayI arrayTrackMatched(nTracks);
351 //get the closest track matched to the cluster
352 matchTrackIndex = fEMCALRecoUtils->GetMatchedTrackIndex(iClus);
353 arrayTrackMatched[nMatched] = matchTrackIndex;
356 //get all other tracks matched to the cluster
358 for(Int_t iTrk=0; iTrk<nTracks; iTrk++){
359 AliESDtrack* track = event->GetTrack(iTrk);
360 if(iTrk == matchTrackIndex) continue;
362 if(track->GetEMCALcluster() == iClus){
363 arrayTrackMatched[nMatched] = iTrk;
368 arrayTrackMatched.Set(nMatched);
369 cluster->AddTracksMatched(arrayTrackMatched);
371 Float_t eta= -999, phi = -999;
372 if(matchTrackIndex != -1) fEMCALRecoUtils->GetMatchedResiduals(iClus, eta, phi);
373 cluster->SetTrackDistance(phi, eta);
375 if (fDebugLevel>2) AliInfo("Cluster matched to tracks \n");
378 //_____________________________________________________
379 Bool_t AliEMCALTenderSupply::InitMisalignMatrix()
381 //Initialising Misalignment matrix
383 AliESDEvent *event=fTender->GetEvent();
384 if (!event) return kFALSE;
386 if (fDebugLevel>0) AliInfo("Initialising Misalignment matrix \n");
389 fInputFile = fInputTree->GetCurrentFile();
391 const char *fileName = fInputFile->GetName();
392 TString FileName = TString(fileName);
393 if (FileName.Contains("pass1")) fFilepass = TString("pass1");
394 else if(FileName.Contains("pass2")) fFilepass = TString("pass2");
395 else if(FileName.Contains("pass3")) fFilepass = TString("pass3");
396 else AliError("pass number not found");
398 else AliError("File not found");
400 else AliError("Tree not found");
403 runGM = event->GetRunNumber();
405 fEMCALRecoUtils->SetPositionAlgorithm(AliEMCALRecoUtils::kPosTowerGlobal);
407 if(runGM <=140000){ //2010 data
409 Double_t rotationMatrix[4][9] = {{-0.014587, -0.999892, -0.002031, 0.999892, -0.014591, 0.001979, -0.002009, -0.002002, 0.999996},
410 {-0.014587, 0.999892, 0.002031, 0.999892, 0.014591, -0.001979, -0.002009, 0.002002, -0.999996},
411 {-0.345864, -0.938278, -0.003412, 0.938276, -0.345874, 0.003010, -0.004004, -0.002161, 0.999990},
412 {-0.345861, 0.938280, 0.003412, 0.938276, 0.345874, -0.003010, -0.004004, 0.002161, -0.999990}};
414 Double_t translationMatrix[4][3] = {{0.351659, 447.576446, 176.269742},
415 {1.062577, 446.893974, -173.728870},
416 {-154.213287, 419.306156, 176.753692},
417 {-153.018950, 418.623681, -173.243605}};
419 for(Int_t mod=0; mod < (fEMCALGeo->GetEMCGeometry())->GetNumberOfSuperModules(); mod++)
421 //if(DebugLevel() > 1) fEMCALMatrix[mod]->Print();
422 fEMCALMatrix[mod] = new TGeoHMatrix(); // mfasel: prevent tender from crashing
423 fEMCALMatrix[mod]->SetRotation(rotationMatrix[mod]);
424 fEMCALMatrix[mod]->SetTranslation(translationMatrix[mod]);
425 fEMCALGeo->SetMisalMatrix(fEMCALMatrix[mod],mod);
430 else if(runGM>140000 && runGM <148531 && (fFilepass = "pass1"))
431 { // 2011 LHC11a pass1 data
432 AliOADBContainer emcalgeoCont(Form("emcal2011"));
433 emcalgeoCont.InitFromFile(Form("BetaGood.root"),Form("AliEMCALgeo"));
435 TObjArray *mobj=(TObjArray*)emcalgeoCont.GetObject(100,"survey11byS");
437 for(Int_t mod=0; mod < (fEMCALGeo->GetEMCGeometry())->GetNumberOfSuperModules(); mod++){
438 fEMCALMatrix[mod] = (TGeoHMatrix*) mobj->At(mod);
439 fEMCALGeo->SetMisalMatrix(fEMCALMatrix[mod],mod);
441 fEMCALMatrix[mod]->Print();
445 else AliInfo("MISALLIGNMENT NOT APPLIED");
450 //_____________________________________________________
451 Bool_t AliEMCALTenderSupply::InitBadChannels()
453 //Initialising Bad channel maps
455 AliESDEvent *event=fTender->GetEvent();
456 if (!event) return kFALSE;
459 fRunBC = event->GetRunNumber();
461 if (fDebugLevel>0) AliInfo("Initialising Bad channel map \n");
464 fEMCALRecoUtils->SetNumberOfCellsFromEMCALBorder(fNCellsFromEMCALBorder);
465 fEMCALRecoUtils->SwitchOnNoFiducialBorderInEMCALEta0();
468 fEMCALRecoUtils->SwitchOnBadChannelsRemoval();
469 if(fRecalDistToBadChannels) fEMCALRecoUtils->SwitchOnDistToBadChannelRecalculation();
474 fbad = new TFile("BadChannels.root","read");
475 if (fbad->IsZombie()){
476 TString fPath = TString(fBasePath.Data());
477 if(fPath.Contains("alien")) {
478 if (fDebugLevel>1) AliInfo("Connecting to alien to get BadChannels.root \n");
479 fbad = TFile::Open(Form("%s/BadChannelsDB/BadChannels.root",fBasePath.Data()));
483 TH2I * hb0 = ( TH2I *)fbad->Get("EMCALBadChannelMap_Mod0");
484 TH2I * hb1 = ( TH2I *)fbad->Get("EMCALBadChannelMap_Mod1");
485 TH2I * hb2 = ( TH2I *)fbad->Get("EMCALBadChannelMap_Mod2");
486 TH2I * hb3 = ( TH2I *)fbad->Get("EMCALBadChannelMap_Mod3");
487 fEMCALRecoUtils->SetEMCALChannelStatusMap(0,hb0);
488 fEMCALRecoUtils->SetEMCALChannelStatusMap(1,hb1);
489 fEMCALRecoUtils->SetEMCALChannelStatusMap(2,hb2);
490 fEMCALRecoUtils->SetEMCALChannelStatusMap(3,hb3);
497 const Int_t nTowers=89;
498 Int_t hotChannels[nTowers]={74, 103, 152, 320, 321, 322, 323, 324, 325, 326, 327, 328, 329, 330, 331, 332, 333, 334, 335, 368, 369, 370, 371, 372, 373, 374,375, 376, 377, 378, 379, 380, 381, 382, 383, 917, 1275, 1288, 1519, 1595, 1860, 1967, 2022, 2026, 2047, 2117, 2298, 2540, 2776, 3135, 3764, 6095, 6111, 6481, 6592, 6800, 6801, 6802, 6803, 6804, 6805, 6806, 6807, 6808, 6809, 6810, 6811, 6812, 6813, 6814, 6815, 7371, 7425, 7430, 7457, 7491, 7709, 8352, 8353, 8356, 8357, 8808, 8810, 8812, 8814, 9056, 9769, 9815, 9837};
500 Int_t nSupMod=-1, nModule=-1, nIphi=-1, nIeta=-1, iphi=-1, ieta=-1;
501 for(Int_t i=0; i<nTowers; i++)
503 fEMCALGeo->GetCellIndex(hotChannels[i],nSupMod,nModule,nIphi,nIeta);
505 fEMCALGeo->GetCellPhiEtaIndexInSModule(nSupMod,nModule,nIphi,nIeta,iphi,ieta);
506 fEMCALRecoUtils->SetEMCALChannelStatus(nSupMod, ieta, iphi);
514 //_____________________________________________________
515 Bool_t AliEMCALTenderSupply::InitRecalib()
517 //Initialising Recalibration Factors
519 AliESDEvent *event=fTender->GetEvent();
520 if (!event) return kFALSE;
522 if (fDebugLevel>0) AliInfo("Initialising Recalibration factors \n");
525 fInputFile = fInputTree->GetCurrentFile();
527 const char *fileName = fInputFile->GetName();
528 TString FileName = TString(fileName);
529 if (FileName.Contains("pass1")) fFilepass = TString("pass1");
530 else if(FileName.Contains("pass2")) fFilepass = TString("pass2");
531 else if(FileName.Contains("pass3")) fFilepass = TString("pass3");
532 else AliError("pass number not found");
534 else AliError("File not found");
536 else AliError("Tree not found");
537 // else {cout << "Tree not found " <<endl; return kFALSE;}
539 Int_t runRC = event->GetRunNumber();
541 //if (event->GetRunNumber()==runRC)
544 fEMCALRecoUtils->SwitchOnRecalibration();
549 fRecalib = new TFile("RecalibrationFactors.root","read");
550 if (fRecalib->IsZombie()){
551 TString fPath = TString(fBasePath.Data());
552 if(fPath.Contains("alien")) {
554 if (fDebugLevel>1) AliInfo("Connecting to alien to get RecalibrationFactors.root \n");
556 if( (runRC >= 114737 && runRC <= 117223 && (fFilepass = "pass2")) || //LHC10b pass2
557 (runRC >= 118503 && runRC <= 121040 && ((fFilepass = "pass2")||(fFilepass = "pass3"))) || //LHC10c pass2, LHC10c pass3
558 (runRC >= 122195 && runRC <= 126437 && (fFilepass = "pass1")) || //LHC10d pass1
559 (runRC >= 127712 && runRC <= 130850 && (fFilepass = "pass1")) || //LHC10e pass1
560 (runRC >= 133004 && runRC < 134657 && (fFilepass = "pass1")))// LHC10f pass1 <134657
562 fRecalib = TFile::Open(Form("%s/RecalDB/summer_december_2010/RecalibrationFactors.root",fBasePath.Data()));
565 else if((runRC >= 122195 && runRC <= 126437 && (fFilepass = "pass2")) || //LHC10d pass2
566 (runRC >= 134657 && runRC <= 135029 && (fFilepass = "pass1")) || //LHC10f pass1 >= 134657
567 (runRC >= 135654 && runRC <= 136377 && (fFilepass = "pass1")) || //LHC10g pass1
568 (runRC >= 136851 && runRC < 137231 && (fFilepass = "pass1"))) //LHC10h pass1 untill christmas
570 fRecalib = TFile::Open(Form("%s/RecalDB/december2010/RecalibrationFactors.root",fBasePath.Data()));
573 else if(runRC >= 137231 && runRC <= 139517 && (fFilepass = "pass1")) //LHC10h pass1 from christmas
575 fRecalib = TFile::Open(Form("%s/RecalDB/summer2010/RecalibrationFactors.root",fBasePath.Data()));
578 AliError("Run number or pass number not found; RECALIBRATION NOT APPLIED");
584 TH2F * r0 = ( TH2F *)fRecalib->Get("EMCALRecalFactors_SM0");
585 TH2F * r1 = ( TH2F *)fRecalib->Get("EMCALRecalFactors_SM1");
586 TH2F * r2 = ( TH2F *)fRecalib->Get("EMCALRecalFactors_SM2");
587 TH2F * r3 = ( TH2F *)fRecalib->Get("EMCALRecalFactors_SM3");
588 fEMCALRecoUtils->SetEMCALChannelRecalibrationFactors(0,r0);
589 fEMCALRecoUtils->SetEMCALChannelRecalibrationFactors(1,r1);
590 fEMCALRecoUtils->SetEMCALChannelRecalibrationFactors(2,r2);
591 fEMCALRecoUtils->SetEMCALChannelRecalibrationFactors(3,r3);
595 fRecalib = new TFile("RecalibrationFactors.root","read");
596 if (fRecalib->IsZombie()){
597 TString fPath = TString(fBasePath.Data());
598 if(fPath.Contains("alien")) {
599 if (fDebugLevel>1) AliInfo("Connecting to alien to get RecalibrationFactors.root \n");
601 fRecalib = TFile::Open(Form("%s/RecalDB/2011_v0/RecalibrationFactors.root",fBasePath.Data()));
602 if(!fRecalib) AliError("Recalibration file not found");
606 TH2F * r0 = ( TH2F *)fRecalib->Get("EMCALRecalFactors_SM0");
607 TH2F * r1 = ( TH2F *)fRecalib->Get("EMCALRecalFactors_SM1");
608 TH2F * r2 = ( TH2F *)fRecalib->Get("EMCALRecalFactors_SM2");
609 TH2F * r3 = ( TH2F *)fRecalib->Get("EMCALRecalFactors_SM3");
610 TH2F * r4 = ( TH2F *)fRecalib->Get("EMCALRecalFactors_SM4");
611 TH2F * r5 = ( TH2F *)fRecalib->Get("EMCALRecalFactors_SM5");
612 TH2F * r6 = ( TH2F *)fRecalib->Get("EMCALRecalFactors_SM6");
613 TH2F * r7 = ( TH2F *)fRecalib->Get("EMCALRecalFactors_SM7");
614 TH2F * r8 = ( TH2F *)fRecalib->Get("EMCALRecalFactors_SM8");
615 TH2F * r9 = ( TH2F *)fRecalib->Get("EMCALRecalFactors_SM9");
617 fEMCALRecoUtils->SetEMCALChannelRecalibrationFactors(0,r0);
618 fEMCALRecoUtils->SetEMCALChannelRecalibrationFactors(1,r1);
619 fEMCALRecoUtils->SetEMCALChannelRecalibrationFactors(2,r2);
620 fEMCALRecoUtils->SetEMCALChannelRecalibrationFactors(3,r3);
621 fEMCALRecoUtils->SetEMCALChannelRecalibrationFactors(4,r4);
622 fEMCALRecoUtils->SetEMCALChannelRecalibrationFactors(5,r5);
623 fEMCALRecoUtils->SetEMCALChannelRecalibrationFactors(6,r6);
624 fEMCALRecoUtils->SetEMCALChannelRecalibrationFactors(7,r7);
625 fEMCALRecoUtils->SetEMCALChannelRecalibrationFactors(8,r8);
626 fEMCALRecoUtils->SetEMCALChannelRecalibrationFactors(9,r9);
633 //_____________________________________________________
634 void AliEMCALTenderSupply::RecalibrateCells()
636 AliESDCaloCells *cells = fTender->GetEvent()->GetEMCALCells();
638 Int_t nEMCcell = cells->GetNumberOfCells();
639 Double_t calibFactor = 1.;
641 for(Int_t icell=0; icell<nEMCcell; icell++){
642 Int_t imod = -1, iphi =-1, ieta=-1,iTower = -1, iIphi = -1, iIeta = -1;
643 fEMCALGeo->GetCellIndex(cells->GetCellNumber(icell),imod,iTower,iIphi,iIeta);
644 fEMCALGeo->GetCellPhiEtaIndexInSModule(imod,iTower,iIphi, iIeta,iphi,ieta);
645 calibFactor = fEMCALRecoUtils->GetEMCALChannelRecalibrationFactor(imod,ieta,iphi);
646 cells->SetCell(icell,cells->GetCellNumber(icell),cells->GetAmplitude(icell)*calibFactor,cells->GetTime(icell));
651 //_____________________________________________________
652 void AliEMCALTenderSupply::InitClusterization()
654 //Initialing clusterization/unfolding algorithm and set all the needed parameters
655 AliESDEvent *event=fTender->GetEvent();
657 AliWarning("Event not available!!!");
661 if (fDebugLevel>0) AliInfo(Form("Initialising Reclustering parameters: Clusterizer-%d \n",fRecParam->GetClusterizerFlag()));
663 //---set the geometry matrix
665 if (!fGeomMatrixSet) {
666 if (fLoadGeomMatrices) {
667 for(Int_t mod=0; mod < fEMCALGeo->GetNumberOfSuperModules(); ++mod) {
668 if(fGeomMatrix[mod]){
669 if(fDebugLevel > 2) fGeomMatrix[mod]->Print();
670 fEMCALGeo->SetMisalMatrix(fGeomMatrix[mod],mod);
673 } else { // get matrix from file (work around bug in aliroot)
674 for(Int_t mod=0; mod < (fEMCALGeo->GetEMCGeometry())->GetNumberOfSuperModules(); mod++){
675 if(fDebugLevel > 2) event->GetEMCALMatrix(mod)->Print();
676 if(event->GetEMCALMatrix(mod)) fEMCALGeo->SetMisalMatrix(event->GetEMCALMatrix(mod),mod) ;
679 fGeomMatrixSet=kTRUE;
682 //---setup clusterizer
685 if (fRecParam->GetClusterizerFlag() == AliEMCALRecParam::kClusterizerv1)
686 fClusterizer = new AliEMCALClusterizerv1 (fEMCALGeo);
687 else if(fRecParam->GetClusterizerFlag() == AliEMCALRecParam::kClusterizerv2)
688 fClusterizer = new AliEMCALClusterizerv2(fEMCALGeo);
689 else if(fRecParam->GetClusterizerFlag() == AliEMCALRecParam::kClusterizerNxN)
690 fClusterizer = new AliEMCALClusterizerNxN(fEMCALGeo);
691 else if(fRecParam->GetClusterizerFlag() > AliEMCALRecParam::kClusterizerv2) { //FIX this other way.
692 AliEMCALClusterizerNxN *clusterizer = new AliEMCALClusterizerNxN(fEMCALGeo);
693 clusterizer->SetNRowDiff(2);
694 clusterizer->SetNColDiff(2);
695 fClusterizer = clusterizer;
697 AliFatal(Form("Clusterizer < %d > not available", fRecParam->GetClusterizerFlag()));
700 //--- set the parameters
702 fClusterizer->SetECAClusteringThreshold( fRecParam->GetClusteringThreshold() );
703 fClusterizer->SetECALogWeight ( fRecParam->GetW0() );
704 fClusterizer->SetMinECut ( fRecParam->GetMinECut() );
705 fClusterizer->SetUnfolding ( fRecParam->GetUnfold() );
706 fClusterizer->SetECALocalMaxCut ( fRecParam->GetLocMaxCut() );
707 fClusterizer->SetTimeCut ( fRecParam->GetTimeCut() );
708 fClusterizer->SetTimeMin ( fRecParam->GetTimeMin() );
709 fClusterizer->SetTimeMax ( fRecParam->GetTimeMax() );
710 fClusterizer->SetInputCalibrated ( kTRUE );
711 fClusterizer->SetJustClusters ( kTRUE );
713 //In case of unfolding after clusterization is requested, set the corresponding parameters
714 if(fRecParam->GetUnfold()){
716 for (i = 0; i < 8; i++) {
717 fClusterizer->SetSSPars(i, fRecParam->GetSSPars(i));
718 }//end of loop over parameters
719 for (i = 0; i < 3; i++) {
720 fClusterizer->SetPar5 (i, fRecParam->GetPar5(i));
721 fClusterizer->SetPar6 (i, fRecParam->GetPar6(i));
722 }//end of loop over parameters
724 fClusterizer->InitClusterUnfolding();
727 fClusterizer->SetDigitsArr(fDigitsArr);
728 fClusterizer->SetOutput(0);
729 fClusterArr = const_cast<TObjArray *>(fClusterizer->GetRecPoints());
731 //_____________________________________________________
732 void AliEMCALTenderSupply::FillDigitsArray()
734 //Fill digits from cells to a TClonesArray
735 fDigitsArr->Clear("C");
737 AliESDEvent *event=fTender->GetEvent();
739 AliWarning("Event not available!!!");
742 AliESDCaloCells *cells = event->GetEMCALCells();
743 Int_t ncells = cells->GetNumberOfCells();
744 for (Int_t icell = 0, idigit = 0; icell < ncells; ++icell) {
745 Double_t cellAmplitude=0, cellTime=0;
746 Short_t cellNumber=0;
747 if (cells->GetCell(icell, cellNumber, cellAmplitude, cellTime) != kTRUE)
749 AliEMCALDigit *digit = static_cast<AliEMCALDigit*>(fDigitsArr->New(idigit));
750 digit->SetId(cellNumber);
751 digit->SetTime(cellTime);
752 digit->SetTimeR(cellTime);
753 digit->SetIndexInList(idigit);
754 digit->SetType(AliEMCALDigit::kHG);
755 digit->SetAmplitude(cellAmplitude);
760 //_____________________________________________________
761 void AliEMCALTenderSupply::Clusterize()
764 fClusterizer->Digits2Clusters("");
767 //_____________________________________________________
768 void AliEMCALTenderSupply::UpdateClusters()
770 //Update ESD cluster list
771 AliESDEvent *event=fTender->GetEvent();
773 AliWarning("Event not available!!!");
778 clus = dynamic_cast<TClonesArray*>(event->FindListObject("caloClusters"));
779 if(!clus) clus = dynamic_cast<TClonesArray*>(event->FindListObject("CaloClusters"));
782 Int_t nents = clus->GetEntries();
783 for (Int_t i=0;i<nents;++i) {
784 AliESDCaloCluster *c = static_cast<AliESDCaloCluster*>(clus->At(i));
791 RecPoints2Clusters(clus);
794 //_____________________________________________________
795 void AliEMCALTenderSupply::RecPoints2Clusters(TClonesArray *clus)
797 // Convert AliEMCALRecoPoints to AliESDCaloClusters
798 // Cluster energy, global position, cells and their amplitude fractions are restored.
799 Bool_t esdobjects = 0;
800 if (strcmp(clus->GetClass()->GetName(),"AliESDCaloCluster")==0)
803 AliESDEvent *event=fTender->GetEvent();
805 AliWarning("Event not available!!!");
809 Int_t Ncls = fClusterArr->GetEntriesFast();
810 for(Int_t i=0, nout=clus->GetEntries(); i < Ncls; ++i) {
811 AliEMCALRecPoint *recpoint = static_cast<AliEMCALRecPoint*>(fClusterArr->At(i));
813 Int_t ncells_true = 0;
814 const Int_t ncells = recpoint->GetMultiplicity();
815 UShort_t absIds[ncells];
816 Double32_t ratios[ncells];
817 Int_t *dlist = recpoint->GetDigitsList();
818 Float_t *elist = recpoint->GetEnergiesList();
819 for (Int_t c = 0; c < ncells; ++c) {
820 AliEMCALDigit *digit = static_cast<AliEMCALDigit*>(fDigitsArr->At(dlist[c]));
821 absIds[ncells_true] = digit->GetId();
822 ratios[ncells_true] = elist[c]/digit->GetAmplitude();
823 if (ratios[ncells_true] < 0.001)
828 if (ncells_true < 1) {
829 AliWarning("Skipping cluster with no cells");
833 // calculate new cluster position
835 recpoint->GetGlobalPosition(gpos);
839 AliESDCaloCluster *c = static_cast<AliESDCaloCluster*>(clus->New(nout++));
840 c->SetType(AliVCluster::kEMCALClusterv1);
841 c->SetE(recpoint->GetEnergy());
843 c->SetNCells(ncells_true);
844 c->SetDispersion(recpoint->GetDispersion());
845 c->SetEmcCpvDistance(-1); //not yet implemented
846 c->SetChi2(-1); //not yet implemented
847 c->SetTOF(recpoint->GetTime()) ; //time-of-flight
848 c->SetNExMax(recpoint->GetNExMax()); //number of local maxima
850 recpoint->GetElipsAxis(elipAxis);
851 c->SetM02(elipAxis[0]*elipAxis[0]) ;
852 c->SetM20(elipAxis[1]*elipAxis[1]) ;
854 AliESDCaloCluster *cesd = static_cast<AliESDCaloCluster*>(c);
855 cesd->SetCellsAbsId(absIds);
856 cesd->SetCellsAmplitudeFraction(ratios);