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_COMPLETEV1")
67 // ,fEMCALRecoUtils(new AliEMCALRecoUtils)
71 ,fNonLinearFunc(AliEMCALRecoUtils::kNoCorrection)
72 ,fNonLinearThreshold(30)
73 ,fReCalibCluster(kFALSE)
75 ,fRecalClusPos(kFALSE)
77 ,fNCellsFromEMCALBorder(1)
78 ,fRecalDistToBadChannels(kFALSE)
85 ,fCutEtaPhiSeparate(kFALSE)
90 ,fReClusterize(kFALSE)
92 ,fGeomMatrixSet(kFALSE)
93 ,fLoadGeomMatrices(kFALSE)
104 for(Int_t i = 0; i < 10; i++) fEMCALMatrix[i] = 0 ;
105 for(Int_t i = 0; i < 10; i++) fGeomMatrix[i] = 0;
106 fRecParam = new AliEMCALRecParam;
107 fEMCALRecoUtils = new AliEMCALRecoUtils();
108 fDigitsArr = new TClonesArray("AliEMCALDigit",1000);
112 //_____________________________________________________
113 AliEMCALTenderSupply::AliEMCALTenderSupply(const char *name, const AliTender *tender) :
114 AliTenderSupply(name,tender)
116 ,fEMCALGeoName("EMCAL_COMPLETEV1")
120 ,fNonLinearFunc(AliEMCALRecoUtils::kNoCorrection)
121 ,fNonLinearThreshold(30)
122 ,fReCalibCluster(kFALSE)
123 ,fReCalibCell(kFALSE)
124 ,fRecalClusPos(kFALSE)
126 ,fNCellsFromEMCALBorder(1)
127 ,fRecalDistToBadChannels(kFALSE)
133 ,fCutEtaPhiSum(kTRUE)
134 ,fCutEtaPhiSeparate(kFALSE)
139 ,fReClusterize(kFALSE)
141 ,fGeomMatrixSet(kFALSE)
142 ,fLoadGeomMatrices(kFALSE)
153 for(Int_t i = 0; i < 10; i++) fEMCALMatrix[i] = 0 ;
154 for(Int_t i = 0; i < 10; i++) fGeomMatrix[i] = 0;
155 fRecParam = new AliEMCALRecParam;
156 fEMCALRecoUtils = new AliEMCALRecoUtils();
157 fDigitsArr = new TClonesArray("AliEMCALDigit",200);
160 //_____________________________________________________
161 AliEMCALTenderSupply::~AliEMCALTenderSupply()
165 delete fEMCALRecoUtils;
172 fDigitsArr->Clear("C");
178 //_____________________________________________________
179 void AliEMCALTenderSupply::Init()
182 // Initialise EMCAL tender
185 if (fDebugLevel>0) AliInfo("Init EMCAL Tender supply\n");
187 AliAnalysisManager *mgr=AliAnalysisManager::GetAnalysisManager();
189 fInputTree = mgr->GetTree();
191 if(gROOT->LoadMacro(fConfigName) >=0){
192 AliDebug(1, Form("Loading settings from macro %s", fConfigName.Data()));
193 AliEMCALTenderSupply *tender = (AliEMCALTenderSupply*)gInterpreter->ProcessLine("ConfigEMCALTenderSupply()");
194 fDebugLevel = tender->fDebugLevel;
195 fEMCALGeoName = tender->fEMCALGeoName;
196 fEMCALRecoUtils = tender->fEMCALRecoUtils;
197 fConfigName = tender->fConfigName;
198 fNonLinearFunc = tender->fNonLinearFunc;
199 fNonLinearThreshold = tender->fNonLinearThreshold;
200 fReCalibCluster = tender->fReCalibCluster;
201 fReCalibCell = tender->fReCalibCell;
202 fRecalClusPos = tender->fRecalClusPos;
203 fFiducial = tender->fFiducial;
204 fNCellsFromEMCALBorder = tender->fNCellsFromEMCALBorder;
205 fRecalDistToBadChannels = tender->fRecalDistToBadChannels;
206 fMass = tender->fMass;
207 fStep = tender->fStep;
208 fRcut = tender->fRcut;
209 fEtacut = tender->fEtacut;
210 fPhicut = tender->fPhicut;
211 fReClusterize = tender->fReClusterize;
212 fLoadGeomMatrices = tender->fLoadGeomMatrices;
213 fRecParam = tender->fRecParam;
214 fOCDBpath = tender->fOCDBpath;
215 for(Int_t i = 0; i < 10; i++) fGeomMatrix[i] = tender->fGeomMatrix[i] ;
219 fEMCALGeo = AliEMCALGeometry::GetInstance(fEMCALGeoName) ;
222 //Initialising Non linearity parameters
223 fEMCALRecoUtils->SetNonLinearityThreshold(fNonLinearThreshold);
224 fEMCALRecoUtils->SetNonLinearityFunction(fNonLinearFunc);
226 //Setting mass, step size and residual cut
228 fEMCALRecoUtils->SwitchOnCutEtaPhiSum();
229 fEMCALRecoUtils->SetCutR(fRcut);
231 else if (fCutEtaPhiSeparate)
233 fEMCALRecoUtils->SwitchOnCutEtaPhiSeparate();
234 fEMCALRecoUtils->SetCutEta(fEtacut);
235 fEMCALRecoUtils->SetCutPhi(fPhicut);
237 fEMCALRecoUtils->SetMass(fMass);
238 fEMCALRecoUtils->SetStep(fStep);
240 //AliLog::SetGlobalDebugLevel(1);
242 if(fDebugLevel>1) fEMCALRecoUtils->Print("");
247 //_____________________________________________________
248 void AliEMCALTenderSupply::ProcessEvent()
251 AliESDEvent *event=fTender->GetEvent();
254 if(fTender->RunChanged()){
255 //Initialising parameters once per run number
256 if (!InitBadChannels()) return;
257 if (fRecalClusPos){ if (!InitMisalignMatrix()) return;}
258 if (fReCalibCluster || fReCalibCell){ if (!InitRecalib()) return;}
259 if (fReClusterize) InitClusterization();
262 AliESDCaloCells *cells= event->GetEMCALCells();
264 //------------ EMCAL cells loop ------------
267 if(fReCalibCell) RecalibrateCells();
269 //------------ Reclusterize ------------
276 //------------Good clusters------------
277 TClonesArray *clusArr;
279 clusArr = dynamic_cast<TClonesArray*>(event->FindListObject("caloClusters"));
280 if(!clusArr) clusArr = dynamic_cast<TClonesArray*>(event->FindListObject("CaloClusters"));
283 Int_t nclusters = clusArr->GetEntriesFast(); //bug fix by Rongrong
284 for (Int_t icluster=0; icluster < nclusters; icluster++ ){
285 AliVCluster *clust = static_cast<AliVCluster*>(clusArr->At(icluster));
287 if (!clust->IsEMCAL()) continue;
288 if(fEMCALRecoUtils->ClusterContainsBadChannel(fEMCALGeo, clust->GetCellsAbsId(), clust->GetNCells() )){
289 delete clusArr->RemoveAt(icluster);
293 if(!fEMCALRecoUtils->CheckCellFiducialRegion(fEMCALGeo, clust, cells)){
294 delete clusArr->RemoveAt(icluster);
298 fEMCALRecoUtils->CorrectClusterEnergyLinearity(clust);
299 if(fRecalDistToBadChannels) fEMCALRecoUtils->RecalculateClusterDistanceToBadChannel(fEMCALGeo, cells, clust);
300 if(fReCalibCluster) fEMCALRecoUtils->RecalibrateClusterEnergy(fEMCALGeo, clust, cells);
301 if(fRecalClusPos) fEMCALRecoUtils->RecalculateClusterPosition(fEMCALGeo, cells, clust);
302 //fEMCALRecoUtils->SetTimeDependentCorrections(event->GetRunNumber());
307 //-------- Track Matching ------------------
310 Double_t magF = event->GetMagneticField();
311 Double_t magSign = 1.0;
312 if(magF<0)magSign = -1.0;
314 if (!TGeoGlobalMagField::Instance()->GetField())
316 AliMagF* field = new AliMagF("Maps","Maps", magSign, magSign, AliMagF::k5kG);
317 TGeoGlobalMagField::Instance()->SetField(field);
321 fEMCALRecoUtils->FindMatches(event,0x0,fEMCALGeo);
323 Int_t nTracks = event->GetNumberOfTracks();
326 SetClusterMatchedToTrack(event);
327 SetTracksMatchedToCluster(event);
332 //_____________________________________________________
333 void AliEMCALTenderSupply::SetClusterMatchedToTrack(AliESDEvent *event)
335 //checks if tracks are matched to EMC clusters and set the matched EMCAL cluster index to ESD track.
337 Int_t matchClusIndex = -1;
338 Int_t nTracks = event->GetNumberOfTracks();
341 for (Int_t iTrack = 0; iTrack < nTracks; iTrack++)
343 AliESDtrack* track = event->GetTrack(iTrack);
345 printf("ERROR: Could not receive track %d\n", iTrack);
349 matchClusIndex = fEMCALRecoUtils->GetMatchedClusterIndex(iTrack);
350 track->SetEMCALcluster(matchClusIndex); //sets -1 if track not matched within residual
351 if(matchClusIndex != -1) track->SetStatus(AliESDtrack::kEMCALmatch);
354 if (fDebugLevel>2) AliInfo("Track matched to closest cluster\n");
357 //_____________________________________________________
358 void AliEMCALTenderSupply::SetTracksMatchedToCluster(AliESDEvent *event)
360 //checks if EMC clusters are matched to ESD track.
361 //Adds track indexes of all the tracks matched to a cluster withing residuals in ESDCalocluster
363 Int_t matchTrackIndex = -1;
364 Int_t nTracks = event->GetNumberOfTracks();
367 for (Int_t iClus=0; iClus < event->GetNumberOfCaloClusters(); iClus++)
369 AliESDCaloCluster * cluster = event->GetCaloCluster(iClus);
370 if (!cluster->IsEMCAL()) continue;
373 TArrayI arrayTrackMatched(nTracks);
375 //get the closest track matched to the cluster
376 matchTrackIndex = fEMCALRecoUtils->GetMatchedTrackIndex(iClus);
377 if(matchTrackIndex != -1){ //Bug fix from Rongrong
378 arrayTrackMatched[nMatched] = matchTrackIndex;
381 //get all other tracks matched to the cluster
383 for(Int_t iTrk=0; iTrk<nTracks; iTrk++){
384 AliESDtrack* track = event->GetTrack(iTrk);
385 if(iTrk == matchTrackIndex) continue;
387 if(track->GetEMCALcluster() == iClus){
388 arrayTrackMatched[nMatched] = iTrk;
393 arrayTrackMatched.Set(nMatched);
394 cluster->AddTracksMatched(arrayTrackMatched);
396 Float_t eta= -999, phi = -999;
397 if(matchTrackIndex != -1) fEMCALRecoUtils->GetMatchedResiduals(iClus, eta, phi);
398 cluster->SetTrackDistance(phi, eta);
400 if (fDebugLevel>2) AliInfo("Cluster matched to tracks \n");
403 //_____________________________________________________
404 Bool_t AliEMCALTenderSupply::InitMisalignMatrix()
406 //Initialising Misalignment matrix
408 AliESDEvent *event=fTender->GetEvent();
409 if (!event) return kFALSE;
411 if (fDebugLevel>0) AliInfo("Initialising Misalignment matrix \n");
414 fInputFile = fInputTree->GetCurrentFile();
416 const char *fileName = fInputFile->GetName();
417 TString FileName = TString(fileName);
418 if (FileName.Contains("pass1")) fFilepass = TString("pass1");
419 else if(FileName.Contains("pass2")) fFilepass = TString("pass2");
420 else if(FileName.Contains("pass3")) fFilepass = TString("pass3");
421 else AliError("pass number not found");
423 else AliError("File not found");
425 else AliError("Tree not found");
428 runGM = event->GetRunNumber();
430 fEMCALRecoUtils->SetPositionAlgorithm(AliEMCALRecoUtils::kPosTowerGlobal);
432 if(runGM <=140000){ //2010 data
434 Double_t rotationMatrix[4][9] = {{-0.014587, -0.999892, -0.002031, 0.999892, -0.014591, 0.001979, -0.002009, -0.002002, 0.999996},
435 {-0.014587, 0.999892, 0.002031, 0.999892, 0.014591, -0.001979, -0.002009, 0.002002, -0.999996},
436 {-0.345864, -0.938278, -0.003412, 0.938276, -0.345874, 0.003010, -0.004004, -0.002161, 0.999990},
437 {-0.345861, 0.938280, 0.003412, 0.938276, 0.345874, -0.003010, -0.004004, 0.002161, -0.999990}};
439 Double_t translationMatrix[4][3] = {{0.351659, 447.576446, 176.269742},
440 {1.062577, 446.893974, -173.728870},
441 {-154.213287, 419.306156, 176.753692},
442 {-153.018950, 418.623681, -173.243605}};
444 for(Int_t mod=0; mod < (fEMCALGeo->GetEMCGeometry())->GetNumberOfSuperModules(); mod++)
446 //if(DebugLevel() > 1) fEMCALMatrix[mod]->Print();
447 fEMCALMatrix[mod] = new TGeoHMatrix(); // mfasel: prevent tender from crashing
448 fEMCALMatrix[mod]->SetRotation(rotationMatrix[mod]);
449 fEMCALMatrix[mod]->SetTranslation(translationMatrix[mod]);
450 fEMCALGeo->SetMisalMatrix(fEMCALMatrix[mod],mod);
455 else if(runGM>140000 && runGM <148531 && (fFilepass = "pass1"))
456 { // 2011 LHC11a pass1 data
457 AliOADBContainer emcalgeoCont(Form("emcal2011"));
458 emcalgeoCont.InitFromFile(Form("%s/BetaGood.root",fBasePath.Data()),Form("AliEMCALgeo"));
460 TObjArray *mobj=(TObjArray*)emcalgeoCont.GetObject(100,"survey11byS");
462 for(Int_t mod=0; mod < (fEMCALGeo->GetEMCGeometry())->GetNumberOfSuperModules(); mod++){
463 fEMCALMatrix[mod] = (TGeoHMatrix*) mobj->At(mod);
464 fEMCALGeo->SetMisalMatrix(fEMCALMatrix[mod],mod);
466 fEMCALMatrix[mod]->Print();
470 else AliInfo("MISALLIGNMENT NOT APPLIED");
475 //_____________________________________________________
476 Bool_t AliEMCALTenderSupply::InitBadChannels()
478 //Initialising Bad channel maps
480 AliESDEvent *event=fTender->GetEvent();
481 if (!event) return kFALSE;
484 fRunBC = event->GetRunNumber();
486 if (fDebugLevel>0) AliInfo("Initialising Bad channel map \n");
489 fInputFile = fInputTree->GetCurrentFile();
491 const char *fileName = fInputFile->GetName();
492 TString FileName = TString(fileName);
493 if (FileName.Contains("pass1")) fFilepass = TString("pass1");
494 else if(FileName.Contains("pass2")) fFilepass = TString("pass2");
495 else if(FileName.Contains("pass3")) fFilepass = TString("pass3");
496 else AliError("pass number not found");
498 else AliError("File not found");
500 else AliError("Tree not found");
503 fEMCALRecoUtils->SetNumberOfCellsFromEMCALBorder(fNCellsFromEMCALBorder);
504 fEMCALRecoUtils->SwitchOnNoFiducialBorderInEMCALEta0();
507 fEMCALRecoUtils->SwitchOnBadChannelsRemoval();
508 if(fRecalDistToBadChannels) fEMCALRecoUtils->SwitchOnDistToBadChannelRecalculation();
513 fbad = new TFile(Form("%s/BadChannels.root",fBasePath.Data()),"read");
514 if (fbad->IsZombie()){
515 TString fPath = TString(fBasePath.Data());
516 if(fPath.Contains("alien")) {
517 if (fDebugLevel>1) AliInfo("Connecting to alien to get BadChannels.root \n");
518 fbad = TFile::Open(Form("%s/BadChannelsDB/BadChannels.root",fBasePath.Data()));
522 TH2I * hb0 = ( TH2I *)fbad->Get("EMCALBadChannelMap_Mod0");
523 TH2I * hb1 = ( TH2I *)fbad->Get("EMCALBadChannelMap_Mod1");
524 TH2I * hb2 = ( TH2I *)fbad->Get("EMCALBadChannelMap_Mod2");
525 TH2I * hb3 = ( TH2I *)fbad->Get("EMCALBadChannelMap_Mod3");
526 fEMCALRecoUtils->SetEMCALChannelStatusMap(0,hb0);
527 fEMCALRecoUtils->SetEMCALChannelStatusMap(1,hb1);
528 fEMCALRecoUtils->SetEMCALChannelStatusMap(2,hb2);
529 fEMCALRecoUtils->SetEMCALChannelStatusMap(3,hb3);
534 Int_t nSupMod=-1, nModule=-1, nIphi=-1, nIeta=-1, iphi=-1, ieta=-1;
536 if(fRunBC>=144871 && fRunBC<=146860){ //LHC11a 2.76 TeV pp
538 if(fFilepass = "pass1"){ // pass1
540 const Int_t nTowers=89;
541 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};
542 for(Int_t i=0; i<nTowers; i++)
544 fEMCALGeo->GetCellIndex(hotChannels[i],nSupMod,nModule,nIphi,nIeta);
546 fEMCALGeo->GetCellPhiEtaIndexInSModule(nSupMod,nModule,nIphi,nIeta,iphi,ieta);
547 fEMCALRecoUtils->SetEMCALChannelStatus(nSupMod, ieta, iphi);
551 if(fFilepass = "pass2"){ // pass2
552 const Int_t nTowers=24;
553 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};
554 for(Int_t i=0; i<nTowers; i++)
556 fEMCALGeo->GetCellIndex(hotChannels[i],nSupMod,nModule,nIphi,nIeta);
558 fEMCALGeo->GetCellPhiEtaIndexInSModule(nSupMod,nModule,nIphi,nIeta,iphi,ieta);
559 fEMCALRecoUtils->SetEMCALChannelStatus(nSupMod, ieta, iphi);
565 if(fRunBC>=151636 && fRunBC<=155384) //LHC11c : 7TeV by Rongrong
567 const Int_t nTowers=8;
568 Int_t hotChannels[nTowers]={917, 2115, 2123, 2540, 6481, 9815, 10113, 10115};
570 for(Int_t i=0; i<nTowers; i++)
572 fEMCALGeo->GetCellIndex(hotChannels[i],nSupMod,nModule,nIphi,nIeta);
573 fEMCALGeo->GetCellPhiEtaIndexInSModule(nSupMod,nModule,nIphi,nIeta,iphi,ieta);
574 fEMCALRecoUtils->SetEMCALChannelStatus(nSupMod, ieta, iphi);
582 //_____________________________________________________
583 Bool_t AliEMCALTenderSupply::InitRecalib()
585 //Initialising Recalibration Factors
587 AliESDEvent *event=fTender->GetEvent();
588 if (!event) return kFALSE;
590 if (fDebugLevel>0) AliInfo("Initialising Recalibration factors \n");
593 fInputFile = fInputTree->GetCurrentFile();
595 const char *fileName = fInputFile->GetName();
596 TString FileName = TString(fileName);
597 if (FileName.Contains("pass1")) fFilepass = TString("pass1");
598 else if(FileName.Contains("pass2")) fFilepass = TString("pass2");
599 else if(FileName.Contains("pass3")) fFilepass = TString("pass3");
600 else AliError("pass number not found");
602 else AliError("File not found");
604 else AliError("Tree not found");
605 // else {cout << "Tree not found " <<endl; return kFALSE;}
607 Int_t runRC = event->GetRunNumber();
609 //if (event->GetRunNumber()==runRC)
612 fEMCALRecoUtils->SwitchOnRecalibration();
617 fRecalib = new TFile(Form("%s/RecalibrationFactors.root",fBasePath.Data()),"read");
618 if (fRecalib->IsZombie()){
619 TString fPath = TString(fBasePath.Data());
620 if(fPath.Contains("alien")) {
622 if (fDebugLevel>1) AliInfo("Connecting to alien to get RecalibrationFactors.root \n");
624 if( (runRC >= 114737 && runRC <= 117223 && (fFilepass = "pass2")) || //LHC10b pass2
625 (runRC >= 118503 && runRC <= 121040 && ((fFilepass = "pass2")||(fFilepass = "pass3"))) || //LHC10c pass2, LHC10c pass3
626 (runRC >= 122195 && runRC <= 126437 && (fFilepass = "pass1")) || //LHC10d pass1
627 (runRC >= 127712 && runRC <= 130850 && (fFilepass = "pass1")) || //LHC10e pass1
628 (runRC >= 133004 && runRC < 134657 && (fFilepass = "pass1")))// LHC10f pass1 <134657
630 fRecalib = TFile::Open(Form("%s/RecalDB/summer_december_2010/RecalibrationFactors.root",fBasePath.Data()));
633 else if((runRC >= 122195 && runRC <= 126437 && (fFilepass = "pass2")) || //LHC10d pass2
634 (runRC >= 134657 && runRC <= 135029 && (fFilepass = "pass1")) || //LHC10f pass1 >= 134657
635 (runRC >= 135654 && runRC <= 136377 && (fFilepass = "pass1")) || //LHC10g pass1
636 (runRC >= 136851 && runRC < 137231 && (fFilepass = "pass1"))) //LHC10h pass1 untill christmas
638 fRecalib = TFile::Open(Form("%s/RecalDB/december2010/RecalibrationFactors.root",fBasePath.Data()));
641 else if(runRC >= 137231 && runRC <= 139517 && (fFilepass = "pass1")) //LHC10h pass1 from christmas
643 fRecalib = TFile::Open(Form("%s/RecalDB/summer2010/RecalibrationFactors.root",fBasePath.Data()));
646 AliError("Run number or pass number not found; RECALIBRATION NOT APPLIED");
652 TH2F * r0 = ( TH2F *)fRecalib->Get("EMCALRecalFactors_SM0");
653 TH2F * r1 = ( TH2F *)fRecalib->Get("EMCALRecalFactors_SM1");
654 TH2F * r2 = ( TH2F *)fRecalib->Get("EMCALRecalFactors_SM2");
655 TH2F * r3 = ( TH2F *)fRecalib->Get("EMCALRecalFactors_SM3");
656 fEMCALRecoUtils->SetEMCALChannelRecalibrationFactors(0,r0);
657 fEMCALRecoUtils->SetEMCALChannelRecalibrationFactors(1,r1);
658 fEMCALRecoUtils->SetEMCALChannelRecalibrationFactors(2,r2);
659 fEMCALRecoUtils->SetEMCALChannelRecalibrationFactors(3,r3);
663 fRecalib = new TFile(Form("%s/RecalibrationFactors.root",fBasePath.Data()),"read");
664 if (fRecalib->IsZombie()){
665 TString fPath = TString(fBasePath.Data());
666 if(fPath.Contains("alien")) {
667 if (fDebugLevel>1) AliInfo("Connecting to alien to get RecalibrationFactors.root \n");
669 fRecalib = TFile::Open(Form("%s/RecalDB/2011_v0/RecalibrationFactors.root",fBasePath.Data()));
670 if(!fRecalib) AliError("Recalibration file not found");
674 TH2F * r0 = ( TH2F *)fRecalib->Get("EMCALRecalFactors_SM0");
675 TH2F * r1 = ( TH2F *)fRecalib->Get("EMCALRecalFactors_SM1");
676 TH2F * r2 = ( TH2F *)fRecalib->Get("EMCALRecalFactors_SM2");
677 TH2F * r3 = ( TH2F *)fRecalib->Get("EMCALRecalFactors_SM3");
678 TH2F * r4 = ( TH2F *)fRecalib->Get("EMCALRecalFactors_SM4");
679 TH2F * r5 = ( TH2F *)fRecalib->Get("EMCALRecalFactors_SM5");
680 TH2F * r6 = ( TH2F *)fRecalib->Get("EMCALRecalFactors_SM6");
681 TH2F * r7 = ( TH2F *)fRecalib->Get("EMCALRecalFactors_SM7");
682 TH2F * r8 = ( TH2F *)fRecalib->Get("EMCALRecalFactors_SM8");
683 TH2F * r9 = ( TH2F *)fRecalib->Get("EMCALRecalFactors_SM9");
685 fEMCALRecoUtils->SetEMCALChannelRecalibrationFactors(0,r0);
686 fEMCALRecoUtils->SetEMCALChannelRecalibrationFactors(1,r1);
687 fEMCALRecoUtils->SetEMCALChannelRecalibrationFactors(2,r2);
688 fEMCALRecoUtils->SetEMCALChannelRecalibrationFactors(3,r3);
689 fEMCALRecoUtils->SetEMCALChannelRecalibrationFactors(4,r4);
690 fEMCALRecoUtils->SetEMCALChannelRecalibrationFactors(5,r5);
691 fEMCALRecoUtils->SetEMCALChannelRecalibrationFactors(6,r6);
692 fEMCALRecoUtils->SetEMCALChannelRecalibrationFactors(7,r7);
693 fEMCALRecoUtils->SetEMCALChannelRecalibrationFactors(8,r8);
694 fEMCALRecoUtils->SetEMCALChannelRecalibrationFactors(9,r9);
701 //_____________________________________________________
702 void AliEMCALTenderSupply::RecalibrateCells()
704 AliESDCaloCells *cells = fTender->GetEvent()->GetEMCALCells();
706 Int_t nEMCcell = cells->GetNumberOfCells();
707 Double_t calibFactor = 1.;
709 for(Int_t icell=0; icell<nEMCcell; icell++){
710 Int_t imod = -1, iphi =-1, ieta=-1,iTower = -1, iIphi = -1, iIeta = -1;
711 fEMCALGeo->GetCellIndex(cells->GetCellNumber(icell),imod,iTower,iIphi,iIeta);
712 fEMCALGeo->GetCellPhiEtaIndexInSModule(imod,iTower,iIphi, iIeta,iphi,ieta);
713 calibFactor = fEMCALRecoUtils->GetEMCALChannelRecalibrationFactor(imod,ieta,iphi);
714 cells->SetCell(icell,cells->GetCellNumber(icell),cells->GetAmplitude(icell)*calibFactor,cells->GetTime(icell));
719 //_____________________________________________________
720 void AliEMCALTenderSupply::InitClusterization()
722 //Initialing clusterization/unfolding algorithm and set all the needed parameters
723 AliESDEvent *event=fTender->GetEvent();
725 AliWarning("Event not available!!!");
729 if (fDebugLevel>0) AliInfo(Form("Initialising Reclustering parameters: Clusterizer-%d \n",fRecParam->GetClusterizerFlag()));
731 //---set the geometry matrix
733 if (!fGeomMatrixSet) {
734 if (fLoadGeomMatrices) {
735 for(Int_t mod=0; mod < fEMCALGeo->GetNumberOfSuperModules(); ++mod) {
736 if(fGeomMatrix[mod]){
737 if(fDebugLevel > 2) fGeomMatrix[mod]->Print();
738 fEMCALGeo->SetMisalMatrix(fGeomMatrix[mod],mod);
741 } else { // get matrix from file (work around bug in aliroot)
742 for(Int_t mod=0; mod < (fEMCALGeo->GetEMCGeometry())->GetNumberOfSuperModules(); mod++){
743 if(fDebugLevel > 2) event->GetEMCALMatrix(mod)->Print();
744 if(event->GetEMCALMatrix(mod)) fEMCALGeo->SetMisalMatrix(event->GetEMCALMatrix(mod),mod) ;
747 fGeomMatrixSet=kTRUE;
750 //---setup clusterizer
753 if (fRecParam->GetClusterizerFlag() == AliEMCALRecParam::kClusterizerv1)
754 fClusterizer = new AliEMCALClusterizerv1 (fEMCALGeo);
755 else if(fRecParam->GetClusterizerFlag() == AliEMCALRecParam::kClusterizerv2)
756 fClusterizer = new AliEMCALClusterizerv2(fEMCALGeo);
757 else if(fRecParam->GetClusterizerFlag() == AliEMCALRecParam::kClusterizerNxN)
758 fClusterizer = new AliEMCALClusterizerNxN(fEMCALGeo);
759 else if(fRecParam->GetClusterizerFlag() > AliEMCALRecParam::kClusterizerv2) { //FIX this other way.
760 AliEMCALClusterizerNxN *clusterizer = new AliEMCALClusterizerNxN(fEMCALGeo);
761 clusterizer->SetNRowDiff(2);
762 clusterizer->SetNColDiff(2);
763 fClusterizer = clusterizer;
765 AliFatal(Form("Clusterizer < %d > not available", fRecParam->GetClusterizerFlag()));
768 //--- set the parameters
770 fClusterizer->SetECAClusteringThreshold( fRecParam->GetClusteringThreshold() );
771 fClusterizer->SetECALogWeight ( fRecParam->GetW0() );
772 fClusterizer->SetMinECut ( fRecParam->GetMinECut() );
773 fClusterizer->SetUnfolding ( fRecParam->GetUnfold() );
774 fClusterizer->SetECALocalMaxCut ( fRecParam->GetLocMaxCut() );
775 fClusterizer->SetTimeCut ( fRecParam->GetTimeCut() );
776 fClusterizer->SetTimeMin ( fRecParam->GetTimeMin() );
777 fClusterizer->SetTimeMax ( fRecParam->GetTimeMax() );
778 fClusterizer->SetInputCalibrated ( kTRUE );
779 fClusterizer->SetJustClusters ( kTRUE );
781 //In case of unfolding after clusterization is requested, set the corresponding parameters
782 if(fRecParam->GetUnfold()){
784 for (i = 0; i < 8; i++) {
785 fClusterizer->SetSSPars(i, fRecParam->GetSSPars(i));
786 }//end of loop over parameters
787 for (i = 0; i < 3; i++) {
788 fClusterizer->SetPar5 (i, fRecParam->GetPar5(i));
789 fClusterizer->SetPar6 (i, fRecParam->GetPar6(i));
790 }//end of loop over parameters
792 fClusterizer->InitClusterUnfolding();
795 fClusterizer->SetDigitsArr(fDigitsArr);
796 fClusterizer->SetOutput(0);
797 fClusterArr = const_cast<TObjArray *>(fClusterizer->GetRecPoints());
799 //_____________________________________________________
800 void AliEMCALTenderSupply::FillDigitsArray()
802 //Fill digits from cells to a TClonesArray
803 fDigitsArr->Clear("C");
805 AliESDEvent *event=fTender->GetEvent();
807 AliWarning("Event not available!!!");
810 AliESDCaloCells *cells = event->GetEMCALCells();
811 Int_t ncells = cells->GetNumberOfCells();
812 for (Int_t icell = 0, idigit = 0; icell < ncells; ++icell) {
813 Double_t cellAmplitude=0, cellTime=0;
814 Short_t cellNumber=0;
815 if (cells->GetCell(icell, cellNumber, cellAmplitude, cellTime) != kTRUE)
817 AliEMCALDigit *digit = static_cast<AliEMCALDigit*>(fDigitsArr->New(idigit));
818 digit->SetId(cellNumber);
819 digit->SetTime(cellTime);
820 digit->SetTimeR(cellTime);
821 digit->SetIndexInList(idigit);
822 digit->SetType(AliEMCALDigit::kHG);
823 digit->SetAmplitude(cellAmplitude);
828 //_____________________________________________________
829 void AliEMCALTenderSupply::Clusterize()
832 fClusterizer->Digits2Clusters("");
835 //_____________________________________________________
836 void AliEMCALTenderSupply::UpdateClusters()
838 //Update ESD cluster list
839 AliESDEvent *event=fTender->GetEvent();
841 AliWarning("Event not available!!!");
846 clus = dynamic_cast<TClonesArray*>(event->FindListObject("caloClusters"));
847 if(!clus) clus = dynamic_cast<TClonesArray*>(event->FindListObject("CaloClusters"));
850 Int_t nents = clus->GetEntriesFast();
851 for (Int_t i=0;i<nents;++i) {
852 AliESDCaloCluster *c = static_cast<AliESDCaloCluster*>(clus->At(i));
859 RecPoints2Clusters(clus);
862 //_____________________________________________________
863 void AliEMCALTenderSupply::RecPoints2Clusters(TClonesArray *clus)
865 // Convert AliEMCALRecoPoints to AliESDCaloClusters
866 // Cluster energy, global position, cells and their amplitude fractions are restored.
867 Bool_t esdobjects = 0;
868 if (strcmp(clus->GetClass()->GetName(),"AliESDCaloCluster")==0)
871 AliESDEvent *event=fTender->GetEvent();
873 AliWarning("Event not available!!!");
877 Int_t ncls = fClusterArr->GetEntriesFast();
878 for(Int_t i=0, nout=clus->GetEntriesFast(); i < ncls; ++i) {
879 AliEMCALRecPoint *recpoint = static_cast<AliEMCALRecPoint*>(fClusterArr->At(i));
881 Int_t ncells_true = 0;
882 const Int_t ncells = recpoint->GetMultiplicity();
883 UShort_t absIds[ncells];
884 Double32_t ratios[ncells];
885 Int_t *dlist = recpoint->GetDigitsList();
886 Float_t *elist = recpoint->GetEnergiesList();
887 for (Int_t c = 0; c < ncells; ++c) {
888 AliEMCALDigit *digit = static_cast<AliEMCALDigit*>(fDigitsArr->At(dlist[c]));
889 absIds[ncells_true] = digit->GetId();
890 ratios[ncells_true] = elist[c]/digit->GetAmplitude();
891 if (ratios[ncells_true] < 0.001)
896 if (ncells_true < 1) {
897 AliWarning("Skipping cluster with no cells");
901 // calculate new cluster position
903 recpoint->GetGlobalPosition(gpos);
907 AliESDCaloCluster *c = static_cast<AliESDCaloCluster*>(clus->New(nout++));
908 c->SetType(AliVCluster::kEMCALClusterv1);
909 c->SetE(recpoint->GetEnergy());
911 c->SetNCells(ncells_true);
912 c->SetDispersion(recpoint->GetDispersion());
913 c->SetEmcCpvDistance(-1); //not yet implemented
914 c->SetChi2(-1); //not yet implemented
915 c->SetTOF(recpoint->GetTime()) ; //time-of-flight
916 c->SetNExMax(recpoint->GetNExMax()); //number of local maxima
918 recpoint->GetElipsAxis(elipAxis);
919 c->SetM02(elipAxis[0]*elipAxis[0]) ;
920 c->SetM20(elipAxis[1]*elipAxis[1]) ;
922 AliESDCaloCluster *cesd = static_cast<AliESDCaloCluster*>(c);
923 cesd->SetCellsAbsId(absIds);
924 cesd->SetCellsAmplitudeFraction(ratios);