]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ANALYSIS/TenderSupplies/AliEMCALTenderSupply.cxx
alignment for 2011 only pass1 LHC11a; track matching store deta and dphi (Deepa,...
[u/mrichter/AliRoot.git] / ANALYSIS / TenderSupplies / AliEMCALTenderSupply.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
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  **************************************************************************/
15
16
17 ///////////////////////////////////////////////////////////////////////////////
18 //                                                                           //
19 //  EMCAL tender, apply corrections to EMCAl clusters                        //
20 //  and do track matching                                                    //                                                                           
21 //  Author : Deepa Thomas (Utrecht University)                               //                      
22 //                                                                           //
23 ///////////////////////////////////////////////////////////////////////////////
24
25 #include "TROOT.h"
26 #include "TFile.h"
27 #include "TAlienFile.h"
28 #include "TGrid.h"
29 #include "TTree.h"
30 #include "TInterpreter.h"
31 #include "TObjArray.h"
32
33 #include <AliLog.h>
34 #include <AliESDEvent.h>
35 #include <AliAnalysisManager.h>
36 #include <AliTender.h>
37 #include "AliOADBContainer.h"
38 #include "AliMagF.h"
39 #include "TGeoGlobalMagField.h"
40
41 #include "AliESDCaloCluster.h"
42 #include "AliEMCALTenderSupply.h"
43
44 //EMCAL
45 #include "AliEMCALGeometry.h"
46 #include "AliEMCALRecoUtils.h"
47
48 AliEMCALTenderSupply::AliEMCALTenderSupply() :
49         AliTenderSupply()
50         ,fEMCALGeo(0x0)
51         ,fEMCALGeoName("EMCAL_FIRSTYEARV1")
52         ,fEMCALRecoUtils(new AliEMCALRecoUtils)
53         ,fConfigName("")
54         ,fDebugLevel(0)
55         ,fNonLinearFunc(AliEMCALRecoUtils::kNoCorrection) 
56         ,fNonLinearThreshold(30)        
57         ,fReCalibCluster(kFALSE)        
58         ,fReCalibCell(kFALSE)   
59         ,fRecalClusPos(kFALSE)
60         ,fFiducial(kFALSE) 
61         ,fNCellsFromEMCALBorder(1)      
62         ,fRecalDistToBadChannels(kFALSE)        
63         ,fInputTree(0)  
64         ,fInputFile(0)
65         ,fFilepass(0) 
66         ,fMass(0.139)
67         ,fStep(1)
68         ,fRcut(0.05)    
69 {
70         //
71         // default ctor
72         //
73         for(Int_t i = 0; i < 10; i++) fEMCALMatrix[i] = 0 ;
74 }
75
76 //_____________________________________________________
77 AliEMCALTenderSupply::AliEMCALTenderSupply(const char *name, const AliTender *tender) :
78         AliTenderSupply(name,tender)
79         ,fEMCALGeo(0x0)
80         ,fEMCALGeoName("EMCAL_FIRSTYEARV1")
81         ,fEMCALRecoUtils(new AliEMCALRecoUtils)
82         ,fConfigName("") 
83         ,fDebugLevel(0)
84         ,fNonLinearFunc(AliEMCALRecoUtils::kNoCorrection)       
85         ,fNonLinearThreshold(30)        
86         ,fReCalibCluster(kFALSE)        
87         ,fReCalibCell(kFALSE)   
88         ,fRecalClusPos(kFALSE)
89         ,fFiducial(kFALSE) 
90         ,fNCellsFromEMCALBorder(1)      
91         ,fRecalDistToBadChannels(kFALSE)        
92         ,fInputTree(0)  
93         ,fInputFile(0)
94         ,fFilepass(0)
95         ,fMass(0.139)
96         ,fStep(1)
97         ,fRcut(0.05)
98 {
99         //
100         // named ctor
101         //
102         for(Int_t i = 0; i < 10; i++) fEMCALMatrix[i] = 0 ;
103 }
104
105 //_____________________________________________________
106 AliEMCALTenderSupply::~AliEMCALTenderSupply()
107 {
108         //Destructor
109         delete fEMCALGeo;
110         delete fEMCALRecoUtils;
111         delete fInputTree;
112         delete fInputFile;
113 }
114
115 //_____________________________________________________
116 void AliEMCALTenderSupply::Init()
117 {
118         //
119         // Initialise EMCAL tender
120         //
121
122         if (fDebugLevel>0) AliInfo("Init EMCAL Tender supply\n");       
123
124         AliAnalysisManager *mgr=AliAnalysisManager::GetAnalysisManager();
125
126         fInputTree = mgr->GetTree();
127
128         if(gROOT->LoadMacro(fConfigName) >=0){
129                 AliEMCALTenderSupply *tender = (AliEMCALTenderSupply*)gInterpreter->ProcessLine("ConfigEMCALTenderSupply()");
130                 fDebugLevel         = tender->fDebugLevel;
131                 fEMCALGeoName       = tender->fEMCALGeoName; 
132                 fEMCALRecoUtils     = tender->fEMCALRecoUtils; 
133                 fConfigName         = tender->fConfigName;
134                 fNonLinearFunc      = tender->fNonLinearFunc;
135                 fNonLinearThreshold = tender->fNonLinearThreshold;
136                 fReCalibCluster     = tender->fReCalibCluster;
137                 fReCalibCell        = tender->fReCalibCell;
138                 fRecalClusPos       = tender->fRecalClusPos;
139                 fFiducial           = tender->fFiducial;
140                 fNCellsFromEMCALBorder = tender->fNCellsFromEMCALBorder;
141                 fRecalDistToBadChannels = tender->fRecalDistToBadChannels;    
142                 fMass               = tender->fMass;
143                 fStep               = tender->fStep;
144                 fRcut               = tender->fRcut;
145         }
146
147         // Init goemetry        
148         fEMCALGeo =  AliEMCALGeometry::GetInstance(fEMCALGeoName) ;
149
150         fEMCALRecoUtils = new AliEMCALRecoUtils();
151
152         //Initialising Non linearity parameters
153         fEMCALRecoUtils->SetNonLinearityThreshold(fNonLinearThreshold);
154
155         //Setting mass, step size and residual cut 
156         fEMCALRecoUtils->SwitchOnCutEtaPhiSum(); 
157         fEMCALRecoUtils->SetCutR(fRcut);
158         fEMCALRecoUtils->SetMass(fMass);
159         fEMCALRecoUtils->SetStep(fStep);
160
161         if(fDebugLevel>1) fEMCALRecoUtils->Print("");
162
163 }
164
165 //_____________________________________________________
166 void AliEMCALTenderSupply::ProcessEvent()
167 {
168         //Event loop    
169         AliESDEvent *event=fTender->GetEvent();
170         if (!event) return;
171
172         if(fTender->RunChanged()){ 
173                 //Initialising parameters once per run number
174                 if (!InitBadChannels()) return;
175                 if (fReCalibCluster || fReCalibCell){ if (!InitRecalibCluster()) return;}
176                 if (fRecalClusPos){ if (!InitMisalignMatrix()) return;}
177         }
178
179         AliESDCaloCells *cells= event->GetEMCALCells();
180
181         //------------Good clusters------------
182         TClonesArray *clusArr;
183
184         clusArr = dynamic_cast<TClonesArray*>(event->FindListObject("caloClusters"));
185         if(!clusArr) clusArr = dynamic_cast<TClonesArray*>(event->FindListObject("CaloClusters"));
186         if(!clusArr) return;
187
188         for (Int_t icluster=0; icluster < clusArr->GetEntries(); icluster++ ){
189                 AliVCluster *clust = static_cast<AliVCluster*>(clusArr->At(icluster));
190                 if(!clust) continue;
191                 if (!clust->IsEMCAL()) continue;
192                 if(fEMCALRecoUtils->ClusterContainsBadChannel(fEMCALGeo, clust->GetCellsAbsId(), clust->GetNCells() )){
193                         delete clusArr->RemoveAt(icluster);
194                         continue;
195                 }
196                 if(fFiducial){
197                         if(!fEMCALRecoUtils->CheckCellFiducialRegion(fEMCALGeo, clust, cells)){
198                                 delete clusArr->RemoveAt(icluster);
199                                 continue;
200                         }
201                 }
202                 fEMCALRecoUtils->CorrectClusterEnergyLinearity(clust);
203                 if(fRecalDistToBadChannels) fEMCALRecoUtils->RecalculateClusterDistanceToBadChannel(fEMCALGeo, cells, clust);  
204                 if(fReCalibCluster) fEMCALRecoUtils->RecalibrateClusterEnergy(fEMCALGeo, clust, cells);
205                 if(fRecalClusPos) fEMCALRecoUtils->RecalculateClusterPosition(fEMCALGeo, cells, clust);
206                 //fEMCALRecoUtils->SetTimeDependentCorrections(event->GetRunNumber());
207         }
208         clusArr->Compress();
209
210         //------------ EMCAL cells loop ------------
211         
212         //Recalibrate cells
213         if(fReCalibCell) RecalibrateCells();
214         
215         //-------- Track Matching ------------------
216
217         //set magnetic field
218         Double_t  magF = event->GetMagneticField();
219         Double_t magSign = 1.0;
220         if(magF<0)magSign = -1.0;
221
222         if (!TGeoGlobalMagField::Instance()->GetField()) 
223         {
224                 AliMagF* field = new AliMagF("Maps","Maps", magSign, magSign, AliMagF::k5kG);
225                 TGeoGlobalMagField::Instance()->SetField(field);
226         }
227
228
229         fEMCALRecoUtils->FindMatches(event,0x0,fEMCALGeo);
230
231         Int_t nTracks = event->GetNumberOfTracks();
232
233         if(nTracks>0){
234                 SetClusterMatchedToTrack(event);
235                 SetTracksMatchedToCluster(event);
236         }
237 }
238
239 //_____________________________________________________
240 void AliEMCALTenderSupply::SetClusterMatchedToTrack(AliESDEvent *event)
241 {
242         //checks if tracks are matched to EMC clusters and set the matched EMCAL cluster index to ESD track. 
243
244         Int_t matchClusIndex = -1;
245         Int_t nTracks = event->GetNumberOfTracks();
246
247         // Track loop 
248         for (Int_t iTrack = 0; iTrack < nTracks; iTrack++) 
249         {
250                 AliESDtrack* track = event->GetTrack(iTrack);
251                 if (!track) {
252                         printf("ERROR: Could not receive track %d\n", iTrack);
253                         continue;
254                 }
255
256                 matchClusIndex = fEMCALRecoUtils->GetMatchedClusterIndex(iTrack);                  
257                 track->SetEMCALcluster(matchClusIndex); //sets -1 if track not matched within residual
258         }
259
260         if (fDebugLevel>2) AliInfo("Track matched to closest cluster\n");       
261 }
262
263 //_____________________________________________________
264 void AliEMCALTenderSupply::SetTracksMatchedToCluster(AliESDEvent *event)
265 {
266         //checks if EMC clusters are matched to ESD track.
267         //Adds track indexes of all the tracks matched to a cluster withing residuals in ESDCalocluster
268
269         Int_t matchTrackIndex = -1;
270         Int_t nTracks = event->GetNumberOfTracks();
271
272         // Cluster loop
273         for (Int_t iClus=0; iClus < event->GetNumberOfCaloClusters(); iClus++)
274         {
275                 AliESDCaloCluster * cluster = event->GetCaloCluster(iClus);
276                 if (!cluster->IsEMCAL()) continue;
277
278                 Int_t nMatched =0;
279                 TArrayI arrayTrackMatched(nTracks);
280
281                 //get the closest track matched to the cluster
282                 matchTrackIndex = fEMCALRecoUtils->GetMatchedTrackIndex(iClus); 
283                 arrayTrackMatched[nMatched] = matchTrackIndex;
284                 nMatched++;
285
286                 //get all other tracks matched to the cluster
287                 //track loop
288                 for(Int_t iTrk=0; iTrk<nTracks; iTrk++){
289                         AliESDtrack* track = event->GetTrack(iTrk);
290                         if(iTrk == matchTrackIndex) continue;
291
292                         if(track->GetEMCALcluster() == iClus){
293                                 arrayTrackMatched[nMatched] = iTrk;
294                                 nMatched++;
295                         }
296                 }
297
298                 arrayTrackMatched.Set(nMatched);
299                 cluster->AddTracksMatched(arrayTrackMatched);
300
301                 Float_t eta= -999, phi = -999;
302                 if(matchTrackIndex != -1) fEMCALRecoUtils->GetMatchedResiduals(iClus, eta, phi);
303                 cluster->SetTrackDistance(phi, eta);
304         }
305         if (fDebugLevel>2) AliInfo("Cluster matched to tracks \n");     
306 }
307
308 //_____________________________________________________
309 Bool_t AliEMCALTenderSupply::InitMisalignMatrix()
310 {
311         //Initialising Misalignment matrix
312
313         AliESDEvent *event=fTender->GetEvent();
314         if (!event) return kFALSE;
315         
316         if (fDebugLevel>0) AliInfo("Initialising Misalignment matrix \n");      
317
318         if(fInputTree){ 
319                 fInputFile = fInputTree->GetCurrentFile();
320                 if(fInputFile){
321                         const char *fileName = fInputFile->GetName();
322                         TString FileName = TString(fileName);
323                         if     (FileName.Contains("pass1")) fFilepass = TString("pass1");
324                         else if(FileName.Contains("pass2")) fFilepass = TString("pass2");
325                         else if(FileName.Contains("pass3")) fFilepass = TString("pass3");
326                         else AliError("pass number not found");
327                 }
328                 else AliError("File not found");
329         }
330         else AliError("Tree not found");
331
332         Int_t runGM = 0;
333         runGM = event->GetRunNumber();
334
335         fEMCALRecoUtils->SetPositionAlgorithm(AliEMCALRecoUtils::kPosTowerGlobal);
336
337         if(runGM <=140000){ //2010 data
338
339                 Double_t rotationMatrix[4][9] = {{-0.014587, -0.999892, -0.002031, 0.999892, -0.014591,  0.001979, -0.002009, -0.002002,  0.999996},
340                         {-0.014587,  0.999892,  0.002031, 0.999892,  0.014591, -0.001979, -0.002009,  0.002002, -0.999996},
341                         {-0.345864, -0.938278, -0.003412, 0.938276, -0.345874,  0.003010, -0.004004, -0.002161,  0.999990},
342                         {-0.345861,  0.938280,  0.003412, 0.938276,  0.345874, -0.003010, -0.004004,  0.002161, -0.999990}};
343
344                 Double_t translationMatrix[4][3] = {{0.351659,    447.576446,  176.269742},
345                         {1.062577,    446.893974, -173.728870},
346                         {-154.213287, 419.306156,  176.753692},
347                         {-153.018950, 418.623681, -173.243605}};
348
349                 for(Int_t mod=0; mod < (fEMCALGeo->GetEMCGeometry())->GetNumberOfSuperModules(); mod++)
350                 {
351                         //if(DebugLevel() > 1)  fEMCALMatrix[mod]->Print();
352                         fEMCALMatrix[mod]->SetRotation(rotationMatrix[mod]);
353                         fEMCALMatrix[mod]->SetTranslation(translationMatrix[mod]);              
354                         fEMCALGeo->SetMisalMatrix(fEMCALMatrix[mod],mod); 
355                 }
356         }
357
358
359         if(runGM>140000 && runGM <148531 && (fFilepass = "pass1"))
360         { // 2011 LHC11a pass1 data
361                 AliOADBContainer emcalgeoCont(Form("emcal2011"));
362                 emcalgeoCont.InitFromFile(Form("BetaGood.root"),Form("AliEMCALgeo"));
363
364                 TObjArray *mobj=(TObjArray*)emcalgeoCont.GetObject(100,"survey11byS");
365
366                 for(Int_t mod=0; mod < (fEMCALGeo->GetEMCGeometry())->GetNumberOfSuperModules(); mod++){
367                         fEMCALMatrix[mod] = (TGeoHMatrix*) mobj->At(mod);
368                         fEMCALGeo->SetMisalMatrix(fEMCALMatrix[mod],mod); 
369
370                         fEMCALMatrix[mod]->Print();
371                 }
372         }
373
374         return kTRUE;
375 }
376
377 //_____________________________________________________
378 Bool_t AliEMCALTenderSupply::InitBadChannels()
379 {
380         //Initialising Bad channel maps
381
382         AliESDEvent *event=fTender->GetEvent();
383         if (!event) return kFALSE;
384
385         Int_t fRunBC= 0;
386         fRunBC = event->GetRunNumber();
387
388         if (fDebugLevel>0) AliInfo("Initialising Bad channel map \n");  
389
390         if(fFiducial){
391                 fEMCALRecoUtils->SetNumberOfCellsFromEMCALBorder(fNCellsFromEMCALBorder);
392                 fEMCALRecoUtils->SwitchOnNoFiducialBorderInEMCALEta0();
393         }
394
395         fEMCALRecoUtils->SwitchOnBadChannelsRemoval();
396         if(fRecalDistToBadChannels) fEMCALRecoUtils->SwitchOnDistToBadChannelRecalculation();
397
398         TFile *fbad;
399         //2010 
400         if(fRunBC <=140000){
401                 fbad = new TFile("BadChannels.root","read");
402                 if (fbad->IsZombie()){
403                         if (fDebugLevel>1) AliInfo("Connecting to alien to get BadChannels.root \n");   
404                         TGrid::Connect("alien://");
405                         fbad = TFile::Open("alien:///alice/cern.ch/user/g/gconesab/BadChannelsDB/BadChannels.root");
406                 }
407
408                 TH2I * hb0 = ( TH2I *)fbad->Get("EMCALBadChannelMap_Mod0");
409                 TH2I * hb1 = ( TH2I *)fbad->Get("EMCALBadChannelMap_Mod1");
410                 TH2I * hb2 = ( TH2I *)fbad->Get("EMCALBadChannelMap_Mod2");
411                 TH2I * hb3 = ( TH2I *)fbad->Get("EMCALBadChannelMap_Mod3"); 
412                 fEMCALRecoUtils->SetEMCALChannelStatusMap(0,hb0);
413                 fEMCALRecoUtils->SetEMCALChannelStatusMap(1,hb1);
414                 fEMCALRecoUtils->SetEMCALChannelStatusMap(2,hb2);
415                 fEMCALRecoUtils->SetEMCALChannelStatusMap(3,hb3); 
416         }
417
418         //2011
419         if(fRunBC>140000){
420
421                 const Int_t nTowers=89;
422                 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};
423
424                 Int_t nSupMod=-1, nModule=-1, nIphi=-1, nIeta=-1, iphi=-1, ieta=-1;
425                 for(Int_t i=0; i<nTowers; i++)
426                 {
427                         fEMCALGeo->GetCellIndex(hotChannels[i],nSupMod,nModule,nIphi,nIeta);
428
429                         fEMCALGeo->GetCellPhiEtaIndexInSModule(nSupMod,nModule,nIphi,nIeta,iphi,ieta);
430                         fEMCALRecoUtils->SetEMCALChannelStatus(nSupMod, ieta, iphi);
431                 }
432
433         }
434
435         return kTRUE;
436 }
437
438 //_____________________________________________________
439 Bool_t AliEMCALTenderSupply::InitRecalibCluster()
440 {
441         //Initialising Recalibration Factors
442
443         AliESDEvent *event=fTender->GetEvent();
444         if (!event) return kFALSE;
445
446         if (fDebugLevel>0) AliInfo("Initialising Recalibration factors \n");
447         
448         if(fInputTree){ 
449                 fInputFile = fInputTree->GetCurrentFile();
450                 if(fInputFile){
451                         const char *fileName = fInputFile->GetName();
452                         TString FileName = TString(fileName);
453                         if     (FileName.Contains("pass1")) fFilepass = TString("pass1");
454                         else if(FileName.Contains("pass2")) fFilepass = TString("pass2");
455                         else if(FileName.Contains("pass3")) fFilepass = TString("pass3");
456                         else AliError("pass number not found");
457                 }
458                 else AliError("File not found");
459         }
460         else AliError("Tree not found");
461         //        else {cout << "Tree not found " <<endl; return kFALSE;}
462
463         //      if (event->GetRunNumber()==runRC)
464        return kFALSE;
465
466         Int_t runRC= 0;     
467         runRC = event->GetRunNumber();
468
469         fEMCALRecoUtils->SwitchOnRecalibration();
470
471
472         TFile* fRecalib;
473
474         if(runRC <=140000){
475                 fRecalib = new TFile("RecalibrationFactors.root","read");
476                 if (fRecalib->IsZombie()){
477                         if (fDebugLevel>1) AliInfo("Connecting to alien to get RecalibrationFactors.root \n");  
478
479                         if(     (runRC >= 114737 && runRC <= 117223 && (fFilepass = "pass2")) || //LHC10b pass2 
480                                         (runRC >= 118503 && runRC <= 121040 && ((fFilepass = "pass2")||(fFilepass = "pass3"))) || //LHC10c pass2, LHC10c pass3
481                                         (runRC >= 122195 && runRC <= 126437 && (fFilepass = "pass1")) || //LHC10d pass1
482                                         (runRC >= 127712 && runRC <= 130850 && (fFilepass = "pass1")) || //LHC10e pass1
483                                         (runRC >= 133004 && runRC < 134657  && (fFilepass = "pass1")))// LHC10f pass1 <134657
484                         {
485                                 TGrid::Connect("alien://");
486                                 fRecalib = TFile::Open("alien:///alice/cern.ch/user/g/gconesab/RecalDB/summer_december_2010/RecalibrationFactors.root");
487                         }
488
489                         else if((runRC >= 122195 && runRC <= 126437 && (fFilepass = "pass2")) || //LHC10d pass2
490                                         (runRC >= 134657 && runRC <= 135029 && (fFilepass = "pass1")) || //LHC10f pass1 >= 134657
491                                         (runRC >= 135654 && runRC <= 136377 && (fFilepass = "pass1")) || //LHC10g pass1
492                                         (runRC >= 136851 && runRC < 137231  && (fFilepass = "pass1"))) //LHC10h pass1 untill christmas
493                         {
494                                 TGrid::Connect("alien://");
495                                 fRecalib = TFile::Open("alien:///alice/cern.ch/user/g/gconesab/RecalDB/december2010/RecalibrationFactors.root");
496                         }
497
498                         else if(runRC >= 137231 && runRC <= 139517 && (fFilepass = "pass1")) //LHC10h pass1 from christmas
499                         {
500                                 TGrid::Connect("alien://");
501                                 fRecalib = TFile::Open("alien:///alice/cern.ch/user/g/gconesab/RecalDB/summer2010/RecalibrationFactors.root");
502                         }
503                         else {
504                                 AliError("Run number not found");
505                                 return kFALSE;
506                         }
507
508                 }
509
510                 TH2F * r0 = ( TH2F *)fRecalib->Get("EMCALRecalFactors_SM0");
511                 TH2F * r1 = ( TH2F *)fRecalib->Get("EMCALRecalFactors_SM1");
512                 TH2F * r2 = ( TH2F *)fRecalib->Get("EMCALRecalFactors_SM2");
513                 TH2F * r3 = ( TH2F *)fRecalib->Get("EMCALRecalFactors_SM3");
514                 fEMCALRecoUtils->SetEMCALChannelRecalibrationFactors(0,r0);
515                 fEMCALRecoUtils->SetEMCALChannelRecalibrationFactors(1,r1);
516                 fEMCALRecoUtils->SetEMCALChannelRecalibrationFactors(2,r2);
517                 fEMCALRecoUtils->SetEMCALChannelRecalibrationFactors(3,r3);
518         }
519
520         if(runRC > 140000){
521                 fRecalib = new TFile("RecalibrationFactors.root","read");
522                 if (fRecalib->IsZombie()){
523                         if (fDebugLevel>1) AliInfo("Connecting to alien to get RecalibrationFactors.root \n");
524
525                         TGrid::Connect("alien://");
526                         fRecalib = TFile::Open("alien:///alice/cern.ch/user/g/gconesab/RecalDB/2011_v0/RecalibrationFactors.root");
527                         if(!fRecalib) AliError("Recalibration file not found");
528                         return kFALSE;
529                 }
530
531                 TH2F * r0 = ( TH2F *)fRecalib->Get("EMCALRecalFactors_SM0");
532                 TH2F * r1 = ( TH2F *)fRecalib->Get("EMCALRecalFactors_SM1");
533                 TH2F * r2 = ( TH2F *)fRecalib->Get("EMCALRecalFactors_SM2");
534                 TH2F * r3 = ( TH2F *)fRecalib->Get("EMCALRecalFactors_SM3");
535                 TH2F * r4 = ( TH2F *)fRecalib->Get("EMCALRecalFactors_SM4");
536                 TH2F * r5 = ( TH2F *)fRecalib->Get("EMCALRecalFactors_SM5");
537                 TH2F * r6 = ( TH2F *)fRecalib->Get("EMCALRecalFactors_SM6");
538                 TH2F * r7 = ( TH2F *)fRecalib->Get("EMCALRecalFactors_SM7");
539                 TH2F * r8 = ( TH2F *)fRecalib->Get("EMCALRecalFactors_SM8");
540                 TH2F * r9 = ( TH2F *)fRecalib->Get("EMCALRecalFactors_SM9");
541
542                 fEMCALRecoUtils->SetEMCALChannelRecalibrationFactors(0,r0);
543                 fEMCALRecoUtils->SetEMCALChannelRecalibrationFactors(1,r1);
544                 fEMCALRecoUtils->SetEMCALChannelRecalibrationFactors(2,r2);
545                 fEMCALRecoUtils->SetEMCALChannelRecalibrationFactors(3,r3); 
546                 fEMCALRecoUtils->SetEMCALChannelRecalibrationFactors(4,r4); 
547                 fEMCALRecoUtils->SetEMCALChannelRecalibrationFactors(5,r5); 
548                 fEMCALRecoUtils->SetEMCALChannelRecalibrationFactors(6,r6); 
549                 fEMCALRecoUtils->SetEMCALChannelRecalibrationFactors(7,r7); 
550                 fEMCALRecoUtils->SetEMCALChannelRecalibrationFactors(8,r8); 
551                 fEMCALRecoUtils->SetEMCALChannelRecalibrationFactors(9,r9); 
552
553         }
554
555         delete fRecalib;
556         return kTRUE;
557 }
558
559 //_____________________________________________________
560 void AliEMCALTenderSupply::RecalibrateCells()
561 {
562         AliESDCaloCells *cells = fTender->GetEvent()->GetEMCALCells();
563
564         Int_t nEMCcell = cells->GetNumberOfCells();
565         Double_t calibFactor = 1.;
566
567         for(Int_t icell=0; icell<nEMCcell; icell++){
568                 Int_t imod = -1, iphi =-1, ieta=-1,iTower = -1, iIphi = -1, iIeta = -1; 
569                 fEMCALGeo->GetCellIndex(cells->GetCellNumber(icell),imod,iTower,iIphi,iIeta);
570                 fEMCALGeo->GetCellPhiEtaIndexInSModule(imod,iTower,iIphi, iIeta,iphi,ieta);     
571                 calibFactor = fEMCALRecoUtils->GetEMCALChannelRecalibrationFactor(imod,ieta,iphi);
572                 cells->SetCell(icell,cells->GetCellNumber(icell),cells->GetAmplitude(icell)*calibFactor,cells->GetTime(icell)); 
573         }       
574
575 }
576