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"
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 "TGeoGlobalMagField.h"
43 #include "AliESDCaloCluster.h"
44 #include "AliEMCALTenderSupply.h"
47 #include "AliEMCALGeometry.h"
48 #include "AliEMCALRecoUtils.h"
49 #include "AliEMCALClusterizer.h"
50 #include "AliEMCALRecParam.h"
51 #include "AliEMCALRecPoint.h"
52 #include "AliEMCALAfterBurnerUF.h"
53 #include "AliEMCALClusterizerNxN.h"
54 #include "AliEMCALClusterizerv1.h"
55 #include "AliEMCALClusterizerv2.h"
56 #include "AliEMCALDigit.h"
58 ClassImp(AliEMCALTenderSupply)
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 fEMCALRecoUtils = new AliEMCALRecoUtils();
104 fDigitsArr = new TClonesArray("AliEMCALDigit",1000);
108 //_____________________________________________________
109 AliEMCALTenderSupply::AliEMCALTenderSupply(const char *name, const AliTender *tender) :
110 AliTenderSupply(name,tender)
112 ,fEMCALGeoName("EMCAL_FIRSTYEARV1")
116 ,fNonLinearFunc(AliEMCALRecoUtils::kNoCorrection)
117 ,fNonLinearThreshold(30)
118 ,fReCalibCluster(kFALSE)
119 ,fReCalibCell(kFALSE)
120 ,fRecalClusPos(kFALSE)
122 ,fNCellsFromEMCALBorder(1)
123 ,fRecalDistToBadChannels(kFALSE)
131 ,fReClusterize(kFALSE)
133 ,fGeomMatrixSet(kFALSE)
134 ,fLoadGeomMatrices(kFALSE)
145 for(Int_t i = 0; i < 10; i++) fEMCALMatrix[i] = 0 ;
146 for(Int_t i = 0; i < 10; i++) fGeomMatrix[i] = 0;
147 fRecParam = new AliEMCALRecParam;
148 fEMCALRecoUtils = new AliEMCALRecoUtils();
149 fDigitsArr = new TClonesArray("AliEMCALDigit",200);
152 //_____________________________________________________
153 AliEMCALTenderSupply::~AliEMCALTenderSupply()
157 delete fEMCALRecoUtils;
164 fDigitsArr->Clear("C");
170 //_____________________________________________________
171 void AliEMCALTenderSupply::Init()
174 // Initialise EMCAL tender
177 if (fDebugLevel>0) AliInfo("Init EMCAL Tender supply\n");
179 AliAnalysisManager *mgr=AliAnalysisManager::GetAnalysisManager();
181 fInputTree = mgr->GetTree();
183 if(gROOT->LoadMacro(fConfigName) >=0){
184 AliDebug(1, Form("Loading settings from macro %s", fConfigName.Data()));
185 AliEMCALTenderSupply *tender = (AliEMCALTenderSupply*)gInterpreter->ProcessLine("ConfigEMCALTenderSupply()");
186 fDebugLevel = tender->fDebugLevel;
187 fEMCALGeoName = tender->fEMCALGeoName;
188 fEMCALRecoUtils = tender->fEMCALRecoUtils;
189 fConfigName = tender->fConfigName;
190 fNonLinearFunc = tender->fNonLinearFunc;
191 fNonLinearThreshold = tender->fNonLinearThreshold;
192 fReCalibCluster = tender->fReCalibCluster;
193 fReCalibCell = tender->fReCalibCell;
194 fRecalClusPos = tender->fRecalClusPos;
195 fFiducial = tender->fFiducial;
196 fNCellsFromEMCALBorder = tender->fNCellsFromEMCALBorder;
197 fRecalDistToBadChannels = tender->fRecalDistToBadChannels;
198 fMass = tender->fMass;
199 fStep = tender->fStep;
200 fRcut = tender->fRcut;
201 fReClusterize = tender->fReClusterize;
202 fLoadGeomMatrices = tender->fLoadGeomMatrices;
203 fRecParam = tender->fRecParam;
204 fOCDBpath = tender->fOCDBpath;
205 for(Int_t i = 0; i < 10; i++) fGeomMatrix[i] = tender->fGeomMatrix[i] ;
209 fEMCALGeo = AliEMCALGeometry::GetInstance(fEMCALGeoName) ;
212 //Initialising Non linearity parameters
213 fEMCALRecoUtils->SetNonLinearityThreshold(fNonLinearThreshold);
214 fEMCALRecoUtils->SetNonLinearityFunction(fNonLinearFunc);
216 //Setting mass, step size and residual cut
217 fEMCALRecoUtils->SwitchOnCutEtaPhiSum();
218 fEMCALRecoUtils->SetCutR(fRcut);
219 fEMCALRecoUtils->SetMass(fMass);
220 fEMCALRecoUtils->SetStep(fStep);
222 //AliLog::SetGlobalDebugLevel(1);
224 if(fDebugLevel>1) fEMCALRecoUtils->Print("");
229 //_____________________________________________________
230 void AliEMCALTenderSupply::ProcessEvent()
233 AliESDEvent *event=fTender->GetEvent();
236 if(fTender->RunChanged()){
237 //Initialising parameters once per run number
238 if (!InitBadChannels()) return;
239 if (fRecalClusPos){ if (!InitMisalignMatrix()) return;}
240 if (fReCalibCluster || fReCalibCell){ if (!InitRecalib()) return;}
241 if (fReClusterize) InitClusterization();
244 AliESDCaloCells *cells= event->GetEMCALCells();
246 //------------ EMCAL cells loop ------------
249 if(fReCalibCell) RecalibrateCells();
251 //------------ Reclusterize ------------
258 //------------Good clusters------------
259 TClonesArray *clusArr;
261 clusArr = dynamic_cast<TClonesArray*>(event->FindListObject("caloClusters"));
262 if(!clusArr) clusArr = dynamic_cast<TClonesArray*>(event->FindListObject("CaloClusters"));
265 Int_t nclusters = clusArr->GetEntriesFast(); //bug fix by Rongrong
266 for (Int_t icluster=0; icluster < nclusters; icluster++ ){
267 AliVCluster *clust = static_cast<AliVCluster*>(clusArr->At(icluster));
269 if (!clust->IsEMCAL()) continue;
270 if(fEMCALRecoUtils->ClusterContainsBadChannel(fEMCALGeo, clust->GetCellsAbsId(), clust->GetNCells() )){
271 delete clusArr->RemoveAt(icluster);
275 if(!fEMCALRecoUtils->CheckCellFiducialRegion(fEMCALGeo, clust, cells)){
276 delete clusArr->RemoveAt(icluster);
280 fEMCALRecoUtils->CorrectClusterEnergyLinearity(clust);
281 if(fRecalDistToBadChannels) fEMCALRecoUtils->RecalculateClusterDistanceToBadChannel(fEMCALGeo, cells, clust);
282 if(fReCalibCluster) fEMCALRecoUtils->RecalibrateClusterEnergy(fEMCALGeo, clust, cells);
283 if(fRecalClusPos) fEMCALRecoUtils->RecalculateClusterPosition(fEMCALGeo, cells, clust);
284 //fEMCALRecoUtils->SetTimeDependentCorrections(event->GetRunNumber());
289 //-------- Track Matching ------------------
292 Double_t magF = event->GetMagneticField();
293 Double_t magSign = 1.0;
294 if(magF<0)magSign = -1.0;
296 if (!TGeoGlobalMagField::Instance()->GetField())
298 AliMagF* field = new AliMagF("Maps","Maps", magSign, magSign, AliMagF::k5kG);
299 TGeoGlobalMagField::Instance()->SetField(field);
303 fEMCALRecoUtils->FindMatches(event,0x0,fEMCALGeo);
305 Int_t nTracks = event->GetNumberOfTracks();
308 SetClusterMatchedToTrack(event);
309 SetTracksMatchedToCluster(event);
314 //_____________________________________________________
315 void AliEMCALTenderSupply::SetClusterMatchedToTrack(AliESDEvent *event)
317 //checks if tracks are matched to EMC clusters and set the matched EMCAL cluster index to ESD track.
319 Int_t matchClusIndex = -1;
320 Int_t nTracks = event->GetNumberOfTracks();
323 for (Int_t iTrack = 0; iTrack < nTracks; iTrack++)
325 AliESDtrack* track = event->GetTrack(iTrack);
327 printf("ERROR: Could not receive track %d\n", iTrack);
331 matchClusIndex = fEMCALRecoUtils->GetMatchedClusterIndex(iTrack);
332 track->SetEMCALcluster(matchClusIndex); //sets -1 if track not matched within residual
333 if(matchClusIndex != -1) track->SetStatus(AliESDtrack::kEMCALmatch);
336 if (fDebugLevel>2) AliInfo("Track matched to closest cluster\n");
339 //_____________________________________________________
340 void AliEMCALTenderSupply::SetTracksMatchedToCluster(AliESDEvent *event)
342 //checks if EMC clusters are matched to ESD track.
343 //Adds track indexes of all the tracks matched to a cluster withing residuals in ESDCalocluster
345 Int_t matchTrackIndex = -1;
346 Int_t nTracks = event->GetNumberOfTracks();
349 for (Int_t iClus=0; iClus < event->GetNumberOfCaloClusters(); iClus++)
351 AliESDCaloCluster * cluster = event->GetCaloCluster(iClus);
352 if (!cluster->IsEMCAL()) continue;
355 TArrayI arrayTrackMatched(nTracks);
357 //get the closest track matched to the cluster
358 matchTrackIndex = fEMCALRecoUtils->GetMatchedTrackIndex(iClus);
359 arrayTrackMatched[nMatched] = matchTrackIndex;
362 //get all other tracks matched to the cluster
364 for(Int_t iTrk=0; iTrk<nTracks; iTrk++){
365 AliESDtrack* track = event->GetTrack(iTrk);
366 if(iTrk == matchTrackIndex) continue;
368 if(track->GetEMCALcluster() == iClus){
369 arrayTrackMatched[nMatched] = iTrk;
374 arrayTrackMatched.Set(nMatched);
375 cluster->AddTracksMatched(arrayTrackMatched);
377 Float_t eta= -999, phi = -999;
378 if(matchTrackIndex != -1) fEMCALRecoUtils->GetMatchedResiduals(iClus, eta, phi);
379 cluster->SetTrackDistance(phi, eta);
381 if (fDebugLevel>2) AliInfo("Cluster matched to tracks \n");
384 //_____________________________________________________
385 Bool_t AliEMCALTenderSupply::InitMisalignMatrix()
387 //Initialising Misalignment matrix
389 AliESDEvent *event=fTender->GetEvent();
390 if (!event) return kFALSE;
392 if (fDebugLevel>0) AliInfo("Initialising Misalignment matrix \n");
395 fInputFile = fInputTree->GetCurrentFile();
397 const char *fileName = fInputFile->GetName();
398 TString FileName = TString(fileName);
399 if (FileName.Contains("pass1")) fFilepass = TString("pass1");
400 else if(FileName.Contains("pass2")) fFilepass = TString("pass2");
401 else if(FileName.Contains("pass3")) fFilepass = TString("pass3");
402 else AliError("pass number not found");
404 else AliError("File not found");
406 else AliError("Tree not found");
409 runGM = event->GetRunNumber();
411 fEMCALRecoUtils->SetPositionAlgorithm(AliEMCALRecoUtils::kPosTowerGlobal);
413 if(runGM <=140000){ //2010 data
415 Double_t rotationMatrix[4][9] = {{-0.014587, -0.999892, -0.002031, 0.999892, -0.014591, 0.001979, -0.002009, -0.002002, 0.999996},
416 {-0.014587, 0.999892, 0.002031, 0.999892, 0.014591, -0.001979, -0.002009, 0.002002, -0.999996},
417 {-0.345864, -0.938278, -0.003412, 0.938276, -0.345874, 0.003010, -0.004004, -0.002161, 0.999990},
418 {-0.345861, 0.938280, 0.003412, 0.938276, 0.345874, -0.003010, -0.004004, 0.002161, -0.999990}};
420 Double_t translationMatrix[4][3] = {{0.351659, 447.576446, 176.269742},
421 {1.062577, 446.893974, -173.728870},
422 {-154.213287, 419.306156, 176.753692},
423 {-153.018950, 418.623681, -173.243605}};
425 for(Int_t mod=0; mod < (fEMCALGeo->GetEMCGeometry())->GetNumberOfSuperModules(); mod++)
427 //if(DebugLevel() > 1) fEMCALMatrix[mod]->Print();
428 fEMCALMatrix[mod] = new TGeoHMatrix(); // mfasel: prevent tender from crashing
429 fEMCALMatrix[mod]->SetRotation(rotationMatrix[mod]);
430 fEMCALMatrix[mod]->SetTranslation(translationMatrix[mod]);
431 fEMCALGeo->SetMisalMatrix(fEMCALMatrix[mod],mod);
436 else if(runGM>140000 && runGM <148531 && (fFilepass = "pass1"))
437 { // 2011 LHC11a pass1 data
438 AliOADBContainer emcalgeoCont(Form("emcal2011"));
439 emcalgeoCont.InitFromFile(Form("%s/BetaGood.root",fBasePath.Data()),Form("AliEMCALgeo"));
441 TObjArray *mobj=(TObjArray*)emcalgeoCont.GetObject(100,"survey11byS");
443 for(Int_t mod=0; mod < (fEMCALGeo->GetEMCGeometry())->GetNumberOfSuperModules(); mod++){
444 fEMCALMatrix[mod] = (TGeoHMatrix*) mobj->At(mod);
445 fEMCALGeo->SetMisalMatrix(fEMCALMatrix[mod],mod);
447 fEMCALMatrix[mod]->Print();
451 else AliInfo("MISALLIGNMENT NOT APPLIED");
456 //_____________________________________________________
457 Bool_t AliEMCALTenderSupply::InitBadChannels()
459 //Initialising Bad channel maps
461 AliESDEvent *event=fTender->GetEvent();
462 if (!event) return kFALSE;
465 fRunBC = event->GetRunNumber();
467 if (fDebugLevel>0) AliInfo("Initialising Bad channel map \n");
470 fInputFile = fInputTree->GetCurrentFile();
472 const char *fileName = fInputFile->GetName();
473 TString FileName = TString(fileName);
474 if (FileName.Contains("pass1")) fFilepass = TString("pass1");
475 else if(FileName.Contains("pass2")) fFilepass = TString("pass2");
476 else if(FileName.Contains("pass3")) fFilepass = TString("pass3");
477 else AliError("pass number not found");
479 else AliError("File not found");
481 else AliError("Tree not found");
484 fEMCALRecoUtils->SetNumberOfCellsFromEMCALBorder(fNCellsFromEMCALBorder);
485 fEMCALRecoUtils->SwitchOnNoFiducialBorderInEMCALEta0();
488 fEMCALRecoUtils->SwitchOnBadChannelsRemoval();
489 if(fRecalDistToBadChannels) fEMCALRecoUtils->SwitchOnDistToBadChannelRecalculation();
494 fbad = new TFile(Form("%s/BadChannels.root",fBasePath.Data()),"read");
495 if (fbad->IsZombie()){
496 TString fPath = TString(fBasePath.Data());
497 if(fPath.Contains("alien")) {
498 if (fDebugLevel>1) AliInfo("Connecting to alien to get BadChannels.root \n");
499 fbad = TFile::Open(Form("%s/BadChannelsDB/BadChannels.root",fBasePath.Data()));
503 TH2I * hb0 = ( TH2I *)fbad->Get("EMCALBadChannelMap_Mod0");
504 TH2I * hb1 = ( TH2I *)fbad->Get("EMCALBadChannelMap_Mod1");
505 TH2I * hb2 = ( TH2I *)fbad->Get("EMCALBadChannelMap_Mod2");
506 TH2I * hb3 = ( TH2I *)fbad->Get("EMCALBadChannelMap_Mod3");
507 fEMCALRecoUtils->SetEMCALChannelStatusMap(0,hb0);
508 fEMCALRecoUtils->SetEMCALChannelStatusMap(1,hb1);
509 fEMCALRecoUtils->SetEMCALChannelStatusMap(2,hb2);
510 fEMCALRecoUtils->SetEMCALChannelStatusMap(3,hb3);
515 Int_t nSupMod=-1, nModule=-1, nIphi=-1, nIeta=-1, iphi=-1, ieta=-1;
517 if(fRunBC>=144871 && fRunBC<=146860){ //LHC11a 2.76 TeV pp
519 if(fFilepass = "pass1"){ // pass1
521 const Int_t nTowers=89;
522 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};
523 for(Int_t i=0; i<nTowers; i++)
525 fEMCALGeo->GetCellIndex(hotChannels[i],nSupMod,nModule,nIphi,nIeta);
527 fEMCALGeo->GetCellPhiEtaIndexInSModule(nSupMod,nModule,nIphi,nIeta,iphi,ieta);
528 fEMCALRecoUtils->SetEMCALChannelStatus(nSupMod, ieta, iphi);
532 if(fFilepass = "pass2"){ // pass2
533 const Int_t nTowers=24;
534 Int_t hotChannels[nTowers]= {74, 103, 152, 917, 1059, 1175, 1276, 1288, 1376, 1382, 1595, 2022, 2026, 2210, 2540, 2778, 2793, 3135, 3764, 5767, 6481, 7371, 7878, 9769};
535 for(Int_t i=0; i<nTowers; i++)
537 fEMCALGeo->GetCellIndex(hotChannels[i],nSupMod,nModule,nIphi,nIeta);
539 fEMCALGeo->GetCellPhiEtaIndexInSModule(nSupMod,nModule,nIphi,nIeta,iphi,ieta);
540 fEMCALRecoUtils->SetEMCALChannelStatus(nSupMod, ieta, iphi);
546 if(fRunBC>=151636 && fRunBC<=155384) //LHC11c : 7TeV by Rongrong
548 const Int_t nTowers=8;
549 Int_t hotChannels[nTowers]={917, 2115, 2123, 2540, 6481, 9815, 10113, 10115};
551 for(Int_t i=0; i<nTowers; i++)
553 fEMCALGeo->GetCellIndex(hotChannels[i],nSupMod,nModule,nIphi,nIeta);
554 fEMCALGeo->GetCellPhiEtaIndexInSModule(nSupMod,nModule,nIphi,nIeta,iphi,ieta);
555 fEMCALRecoUtils->SetEMCALChannelStatus(nSupMod, ieta, iphi);
563 //_____________________________________________________
564 Bool_t AliEMCALTenderSupply::InitRecalib()
566 //Initialising Recalibration Factors
568 AliESDEvent *event=fTender->GetEvent();
569 if (!event) return kFALSE;
571 if (fDebugLevel>0) AliInfo("Initialising Recalibration factors \n");
574 fInputFile = fInputTree->GetCurrentFile();
576 const char *fileName = fInputFile->GetName();
577 TString FileName = TString(fileName);
578 if (FileName.Contains("pass1")) fFilepass = TString("pass1");
579 else if(FileName.Contains("pass2")) fFilepass = TString("pass2");
580 else if(FileName.Contains("pass3")) fFilepass = TString("pass3");
581 else AliError("pass number not found");
583 else AliError("File not found");
585 else AliError("Tree not found");
586 // else {cout << "Tree not found " <<endl; return kFALSE;}
588 Int_t runRC = event->GetRunNumber();
590 //if (event->GetRunNumber()==runRC)
593 fEMCALRecoUtils->SwitchOnRecalibration();
598 fRecalib = new TFile(Form("%s/RecalibrationFactors.root",fBasePath.Data()),"read");
599 if (fRecalib->IsZombie()){
600 TString fPath = TString(fBasePath.Data());
601 if(fPath.Contains("alien")) {
603 if (fDebugLevel>1) AliInfo("Connecting to alien to get RecalibrationFactors.root \n");
605 if( (runRC >= 114737 && runRC <= 117223 && (fFilepass = "pass2")) || //LHC10b pass2
606 (runRC >= 118503 && runRC <= 121040 && ((fFilepass = "pass2")||(fFilepass = "pass3"))) || //LHC10c pass2, LHC10c pass3
607 (runRC >= 122195 && runRC <= 126437 && (fFilepass = "pass1")) || //LHC10d pass1
608 (runRC >= 127712 && runRC <= 130850 && (fFilepass = "pass1")) || //LHC10e pass1
609 (runRC >= 133004 && runRC < 134657 && (fFilepass = "pass1")))// LHC10f pass1 <134657
611 fRecalib = TFile::Open(Form("%s/RecalDB/summer_december_2010/RecalibrationFactors.root",fBasePath.Data()));
614 else if((runRC >= 122195 && runRC <= 126437 && (fFilepass = "pass2")) || //LHC10d pass2
615 (runRC >= 134657 && runRC <= 135029 && (fFilepass = "pass1")) || //LHC10f pass1 >= 134657
616 (runRC >= 135654 && runRC <= 136377 && (fFilepass = "pass1")) || //LHC10g pass1
617 (runRC >= 136851 && runRC < 137231 && (fFilepass = "pass1"))) //LHC10h pass1 untill christmas
619 fRecalib = TFile::Open(Form("%s/RecalDB/december2010/RecalibrationFactors.root",fBasePath.Data()));
622 else if(runRC >= 137231 && runRC <= 139517 && (fFilepass = "pass1")) //LHC10h pass1 from christmas
624 fRecalib = TFile::Open(Form("%s/RecalDB/summer2010/RecalibrationFactors.root",fBasePath.Data()));
627 AliError("Run number or pass number not found; RECALIBRATION NOT APPLIED");
633 TH2F * r0 = ( TH2F *)fRecalib->Get("EMCALRecalFactors_SM0");
634 TH2F * r1 = ( TH2F *)fRecalib->Get("EMCALRecalFactors_SM1");
635 TH2F * r2 = ( TH2F *)fRecalib->Get("EMCALRecalFactors_SM2");
636 TH2F * r3 = ( TH2F *)fRecalib->Get("EMCALRecalFactors_SM3");
637 fEMCALRecoUtils->SetEMCALChannelRecalibrationFactors(0,r0);
638 fEMCALRecoUtils->SetEMCALChannelRecalibrationFactors(1,r1);
639 fEMCALRecoUtils->SetEMCALChannelRecalibrationFactors(2,r2);
640 fEMCALRecoUtils->SetEMCALChannelRecalibrationFactors(3,r3);
644 fRecalib = new TFile(Form("%s/RecalibrationFactors.root",fBasePath.Data()),"read");
645 if (fRecalib->IsZombie()){
646 TString fPath = TString(fBasePath.Data());
647 if(fPath.Contains("alien")) {
648 if (fDebugLevel>1) AliInfo("Connecting to alien to get RecalibrationFactors.root \n");
650 fRecalib = TFile::Open(Form("%s/RecalDB/2011_v0/RecalibrationFactors.root",fBasePath.Data()));
651 if(!fRecalib) AliError("Recalibration file not found");
655 TH2F * r0 = ( TH2F *)fRecalib->Get("EMCALRecalFactors_SM0");
656 TH2F * r1 = ( TH2F *)fRecalib->Get("EMCALRecalFactors_SM1");
657 TH2F * r2 = ( TH2F *)fRecalib->Get("EMCALRecalFactors_SM2");
658 TH2F * r3 = ( TH2F *)fRecalib->Get("EMCALRecalFactors_SM3");
659 TH2F * r4 = ( TH2F *)fRecalib->Get("EMCALRecalFactors_SM4");
660 TH2F * r5 = ( TH2F *)fRecalib->Get("EMCALRecalFactors_SM5");
661 TH2F * r6 = ( TH2F *)fRecalib->Get("EMCALRecalFactors_SM6");
662 TH2F * r7 = ( TH2F *)fRecalib->Get("EMCALRecalFactors_SM7");
663 TH2F * r8 = ( TH2F *)fRecalib->Get("EMCALRecalFactors_SM8");
664 TH2F * r9 = ( TH2F *)fRecalib->Get("EMCALRecalFactors_SM9");
666 fEMCALRecoUtils->SetEMCALChannelRecalibrationFactors(0,r0);
667 fEMCALRecoUtils->SetEMCALChannelRecalibrationFactors(1,r1);
668 fEMCALRecoUtils->SetEMCALChannelRecalibrationFactors(2,r2);
669 fEMCALRecoUtils->SetEMCALChannelRecalibrationFactors(3,r3);
670 fEMCALRecoUtils->SetEMCALChannelRecalibrationFactors(4,r4);
671 fEMCALRecoUtils->SetEMCALChannelRecalibrationFactors(5,r5);
672 fEMCALRecoUtils->SetEMCALChannelRecalibrationFactors(6,r6);
673 fEMCALRecoUtils->SetEMCALChannelRecalibrationFactors(7,r7);
674 fEMCALRecoUtils->SetEMCALChannelRecalibrationFactors(8,r8);
675 fEMCALRecoUtils->SetEMCALChannelRecalibrationFactors(9,r9);
682 //_____________________________________________________
683 void AliEMCALTenderSupply::RecalibrateCells()
685 AliESDCaloCells *cells = fTender->GetEvent()->GetEMCALCells();
687 Int_t nEMCcell = cells->GetNumberOfCells();
688 Double_t calibFactor = 1.;
690 for(Int_t icell=0; icell<nEMCcell; icell++){
691 Int_t imod = -1, iphi =-1, ieta=-1,iTower = -1, iIphi = -1, iIeta = -1;
692 fEMCALGeo->GetCellIndex(cells->GetCellNumber(icell),imod,iTower,iIphi,iIeta);
693 fEMCALGeo->GetCellPhiEtaIndexInSModule(imod,iTower,iIphi, iIeta,iphi,ieta);
694 calibFactor = fEMCALRecoUtils->GetEMCALChannelRecalibrationFactor(imod,ieta,iphi);
695 cells->SetCell(icell,cells->GetCellNumber(icell),cells->GetAmplitude(icell)*calibFactor,cells->GetTime(icell));
700 //_____________________________________________________
701 void AliEMCALTenderSupply::InitClusterization()
703 //Initialing clusterization/unfolding algorithm and set all the needed parameters
704 AliESDEvent *event=fTender->GetEvent();
706 AliWarning("Event not available!!!");
710 if (fDebugLevel>0) AliInfo(Form("Initialising Reclustering parameters: Clusterizer-%d \n",fRecParam->GetClusterizerFlag()));
712 //---set the geometry matrix
714 if (!fGeomMatrixSet) {
715 if (fLoadGeomMatrices) {
716 for(Int_t mod=0; mod < fEMCALGeo->GetNumberOfSuperModules(); ++mod) {
717 if(fGeomMatrix[mod]){
718 if(fDebugLevel > 2) fGeomMatrix[mod]->Print();
719 fEMCALGeo->SetMisalMatrix(fGeomMatrix[mod],mod);
722 } else { // get matrix from file (work around bug in aliroot)
723 for(Int_t mod=0; mod < (fEMCALGeo->GetEMCGeometry())->GetNumberOfSuperModules(); mod++){
724 if(fDebugLevel > 2) event->GetEMCALMatrix(mod)->Print();
725 if(event->GetEMCALMatrix(mod)) fEMCALGeo->SetMisalMatrix(event->GetEMCALMatrix(mod),mod) ;
728 fGeomMatrixSet=kTRUE;
731 //---setup clusterizer
734 if (fRecParam->GetClusterizerFlag() == AliEMCALRecParam::kClusterizerv1)
735 fClusterizer = new AliEMCALClusterizerv1 (fEMCALGeo);
736 else if(fRecParam->GetClusterizerFlag() == AliEMCALRecParam::kClusterizerv2)
737 fClusterizer = new AliEMCALClusterizerv2(fEMCALGeo);
738 else if(fRecParam->GetClusterizerFlag() == AliEMCALRecParam::kClusterizerNxN)
739 fClusterizer = new AliEMCALClusterizerNxN(fEMCALGeo);
740 else if(fRecParam->GetClusterizerFlag() > AliEMCALRecParam::kClusterizerv2) { //FIX this other way.
741 AliEMCALClusterizerNxN *clusterizer = new AliEMCALClusterizerNxN(fEMCALGeo);
742 clusterizer->SetNRowDiff(2);
743 clusterizer->SetNColDiff(2);
744 fClusterizer = clusterizer;
746 AliFatal(Form("Clusterizer < %d > not available", fRecParam->GetClusterizerFlag()));
749 //--- set the parameters
751 fClusterizer->SetECAClusteringThreshold( fRecParam->GetClusteringThreshold() );
752 fClusterizer->SetECALogWeight ( fRecParam->GetW0() );
753 fClusterizer->SetMinECut ( fRecParam->GetMinECut() );
754 fClusterizer->SetUnfolding ( fRecParam->GetUnfold() );
755 fClusterizer->SetECALocalMaxCut ( fRecParam->GetLocMaxCut() );
756 fClusterizer->SetTimeCut ( fRecParam->GetTimeCut() );
757 fClusterizer->SetTimeMin ( fRecParam->GetTimeMin() );
758 fClusterizer->SetTimeMax ( fRecParam->GetTimeMax() );
759 fClusterizer->SetInputCalibrated ( kTRUE );
760 fClusterizer->SetJustClusters ( kTRUE );
762 //In case of unfolding after clusterization is requested, set the corresponding parameters
763 if(fRecParam->GetUnfold()){
765 for (i = 0; i < 8; i++) {
766 fClusterizer->SetSSPars(i, fRecParam->GetSSPars(i));
767 }//end of loop over parameters
768 for (i = 0; i < 3; i++) {
769 fClusterizer->SetPar5 (i, fRecParam->GetPar5(i));
770 fClusterizer->SetPar6 (i, fRecParam->GetPar6(i));
771 }//end of loop over parameters
773 fClusterizer->InitClusterUnfolding();
776 fClusterizer->SetDigitsArr(fDigitsArr);
777 fClusterizer->SetOutput(0);
778 fClusterArr = const_cast<TObjArray *>(fClusterizer->GetRecPoints());
780 //_____________________________________________________
781 void AliEMCALTenderSupply::FillDigitsArray()
783 //Fill digits from cells to a TClonesArray
784 fDigitsArr->Clear("C");
786 AliESDEvent *event=fTender->GetEvent();
788 AliWarning("Event not available!!!");
791 AliESDCaloCells *cells = event->GetEMCALCells();
792 Int_t ncells = cells->GetNumberOfCells();
793 for (Int_t icell = 0, idigit = 0; icell < ncells; ++icell) {
794 Double_t cellAmplitude=0, cellTime=0;
795 Short_t cellNumber=0;
796 if (cells->GetCell(icell, cellNumber, cellAmplitude, cellTime) != kTRUE)
798 AliEMCALDigit *digit = static_cast<AliEMCALDigit*>(fDigitsArr->New(idigit));
799 digit->SetId(cellNumber);
800 digit->SetTime(cellTime);
801 digit->SetTimeR(cellTime);
802 digit->SetIndexInList(idigit);
803 digit->SetType(AliEMCALDigit::kHG);
804 digit->SetAmplitude(cellAmplitude);
809 //_____________________________________________________
810 void AliEMCALTenderSupply::Clusterize()
813 fClusterizer->Digits2Clusters("");
816 //_____________________________________________________
817 void AliEMCALTenderSupply::UpdateClusters()
819 //Update ESD cluster list
820 AliESDEvent *event=fTender->GetEvent();
822 AliWarning("Event not available!!!");
827 clus = dynamic_cast<TClonesArray*>(event->FindListObject("caloClusters"));
828 if(!clus) clus = dynamic_cast<TClonesArray*>(event->FindListObject("CaloClusters"));
831 Int_t nents = clus->GetEntriesFast();
832 for (Int_t i=0;i<nents;++i) {
833 AliESDCaloCluster *c = static_cast<AliESDCaloCluster*>(clus->At(i));
840 RecPoints2Clusters(clus);
843 //_____________________________________________________
844 void AliEMCALTenderSupply::RecPoints2Clusters(TClonesArray *clus)
846 // Convert AliEMCALRecoPoints to AliESDCaloClusters
847 // Cluster energy, global position, cells and their amplitude fractions are restored.
848 Bool_t esdobjects = 0;
849 if (strcmp(clus->GetClass()->GetName(),"AliESDCaloCluster")==0)
852 AliESDEvent *event=fTender->GetEvent();
854 AliWarning("Event not available!!!");
858 Int_t ncls = fClusterArr->GetEntriesFast();
859 for(Int_t i=0, nout=clus->GetEntriesFast(); i < ncls; ++i) {
860 AliEMCALRecPoint *recpoint = static_cast<AliEMCALRecPoint*>(fClusterArr->At(i));
862 Int_t ncells_true = 0;
863 const Int_t ncells = recpoint->GetMultiplicity();
864 UShort_t absIds[ncells];
865 Double32_t ratios[ncells];
866 Int_t *dlist = recpoint->GetDigitsList();
867 Float_t *elist = recpoint->GetEnergiesList();
868 for (Int_t c = 0; c < ncells; ++c) {
869 AliEMCALDigit *digit = static_cast<AliEMCALDigit*>(fDigitsArr->At(dlist[c]));
870 absIds[ncells_true] = digit->GetId();
871 ratios[ncells_true] = elist[c]/digit->GetAmplitude();
872 if (ratios[ncells_true] < 0.001)
877 if (ncells_true < 1) {
878 AliWarning("Skipping cluster with no cells");
882 // calculate new cluster position
884 recpoint->GetGlobalPosition(gpos);
888 AliESDCaloCluster *c = static_cast<AliESDCaloCluster*>(clus->New(nout++));
889 c->SetType(AliVCluster::kEMCALClusterv1);
890 c->SetE(recpoint->GetEnergy());
892 c->SetNCells(ncells_true);
893 c->SetDispersion(recpoint->GetDispersion());
894 c->SetEmcCpvDistance(-1); //not yet implemented
895 c->SetChi2(-1); //not yet implemented
896 c->SetTOF(recpoint->GetTime()) ; //time-of-flight
897 c->SetNExMax(recpoint->GetNExMax()); //number of local maxima
899 recpoint->GetElipsAxis(elipAxis);
900 c->SetM02(elipAxis[0]*elipAxis[0]) ;
901 c->SetM20(elipAxis[1]*elipAxis[1]) ;
903 AliESDCaloCluster *cesd = static_cast<AliESDCaloCluster*>(c);
904 cesd->SetCellsAbsId(absIds);
905 cesd->SetCellsAmplitudeFraction(ratios);