]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ANALYSIS/TenderSupplies/AliEMCALTenderSupply.cxx
No need for TAlienFile.h
[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 (fRecalClusPos){ if (!InitMisalignMatrix()) return;}
176                 if (fReCalibCluster || fReCalibCell){ if (!InitRecalib()) 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 //_____________________________________________________
241 void AliEMCALTenderSupply::SetClusterMatchedToTrack(AliESDEvent *event)
242 {
243         //checks if tracks are matched to EMC clusters and set the matched EMCAL cluster index to ESD track. 
244
245         Int_t matchClusIndex = -1;
246         Int_t nTracks = event->GetNumberOfTracks();
247
248         // Track loop 
249         for (Int_t iTrack = 0; iTrack < nTracks; iTrack++) 
250         {
251                 AliESDtrack* track = event->GetTrack(iTrack);
252                 if (!track) {
253                         printf("ERROR: Could not receive track %d\n", iTrack);
254                         continue;
255                 }
256
257                 matchClusIndex = fEMCALRecoUtils->GetMatchedClusterIndex(iTrack);                  
258                 track->SetEMCALcluster(matchClusIndex); //sets -1 if track not matched within residual
259         }
260
261         if (fDebugLevel>2) AliInfo("Track matched to closest cluster\n");       
262 }
263
264 //_____________________________________________________
265 void AliEMCALTenderSupply::SetTracksMatchedToCluster(AliESDEvent *event)
266 {
267         //checks if EMC clusters are matched to ESD track.
268         //Adds track indexes of all the tracks matched to a cluster withing residuals in ESDCalocluster
269
270         Int_t matchTrackIndex = -1;
271         Int_t nTracks = event->GetNumberOfTracks();
272
273         // Cluster loop
274         for (Int_t iClus=0; iClus < event->GetNumberOfCaloClusters(); iClus++)
275         {
276                 AliESDCaloCluster * cluster = event->GetCaloCluster(iClus);
277                 if (!cluster->IsEMCAL()) continue;
278
279                 Int_t nMatched =0;
280                 TArrayI arrayTrackMatched(nTracks);
281
282                 //get the closest track matched to the cluster
283                 matchTrackIndex = fEMCALRecoUtils->GetMatchedTrackIndex(iClus); 
284                 arrayTrackMatched[nMatched] = matchTrackIndex;
285                 nMatched++;
286
287                 //get all other tracks matched to the cluster
288                 //track loop
289                 for(Int_t iTrk=0; iTrk<nTracks; iTrk++){
290                         AliESDtrack* track = event->GetTrack(iTrk);
291                         if(iTrk == matchTrackIndex) continue;
292
293                         if(track->GetEMCALcluster() == iClus){
294                                 arrayTrackMatched[nMatched] = iTrk;
295                                 nMatched++;
296                         }
297                 }
298
299                 arrayTrackMatched.Set(nMatched);
300                 cluster->AddTracksMatched(arrayTrackMatched);
301
302                 Float_t eta= -999, phi = -999;
303                 if(matchTrackIndex != -1) fEMCALRecoUtils->GetMatchedResiduals(iClus, eta, phi);
304                 cluster->SetTrackDistance(phi, eta);
305         }
306         if (fDebugLevel>2) AliInfo("Cluster matched to tracks \n");     
307 }
308
309 //_____________________________________________________
310 Bool_t AliEMCALTenderSupply::InitMisalignMatrix()
311 {
312         //Initialising Misalignment matrix
313
314         AliESDEvent *event=fTender->GetEvent();
315         if (!event) return kFALSE;
316         
317         if (fDebugLevel>0) AliInfo("Initialising Misalignment matrix \n");      
318
319         if(fInputTree){ 
320                 fInputFile = fInputTree->GetCurrentFile();
321                 if(fInputFile){
322                         const char *fileName = fInputFile->GetName();
323                         TString FileName = TString(fileName);
324                         if     (FileName.Contains("pass1")) fFilepass = TString("pass1");
325                         else if(FileName.Contains("pass2")) fFilepass = TString("pass2");
326                         else if(FileName.Contains("pass3")) fFilepass = TString("pass3");
327                         else AliError("pass number not found");
328                 }
329                 else AliError("File not found");
330         }
331         else AliError("Tree not found");
332
333         Int_t runGM = 0;
334         runGM = event->GetRunNumber();
335
336         fEMCALRecoUtils->SetPositionAlgorithm(AliEMCALRecoUtils::kPosTowerGlobal);
337
338         if(runGM <=140000){ //2010 data
339
340                 Double_t rotationMatrix[4][9] = {{-0.014587, -0.999892, -0.002031, 0.999892, -0.014591,  0.001979, -0.002009, -0.002002,  0.999996},
341                         {-0.014587,  0.999892,  0.002031, 0.999892,  0.014591, -0.001979, -0.002009,  0.002002, -0.999996},
342                         {-0.345864, -0.938278, -0.003412, 0.938276, -0.345874,  0.003010, -0.004004, -0.002161,  0.999990},
343                         {-0.345861,  0.938280,  0.003412, 0.938276,  0.345874, -0.003010, -0.004004,  0.002161, -0.999990}};
344
345                 Double_t translationMatrix[4][3] = {{0.351659,    447.576446,  176.269742},
346                         {1.062577,    446.893974, -173.728870},
347                         {-154.213287, 419.306156,  176.753692},
348                         {-153.018950, 418.623681, -173.243605}};
349
350                 for(Int_t mod=0; mod < (fEMCALGeo->GetEMCGeometry())->GetNumberOfSuperModules(); mod++)
351                 {
352                         //if(DebugLevel() > 1)  fEMCALMatrix[mod]->Print();
353                         fEMCALMatrix[mod]->SetRotation(rotationMatrix[mod]);
354                         fEMCALMatrix[mod]->SetTranslation(translationMatrix[mod]);              
355                         fEMCALGeo->SetMisalMatrix(fEMCALMatrix[mod],mod); 
356                 }
357         }
358
359
360         if(runGM>140000 && runGM <148531 && (fFilepass = "pass1"))
361         { // 2011 LHC11a pass1 data
362                 AliOADBContainer emcalgeoCont(Form("emcal2011"));
363                 emcalgeoCont.InitFromFile(Form("BetaGood.root"),Form("AliEMCALgeo"));
364
365                 TObjArray *mobj=(TObjArray*)emcalgeoCont.GetObject(100,"survey11byS");
366
367                 for(Int_t mod=0; mod < (fEMCALGeo->GetEMCGeometry())->GetNumberOfSuperModules(); mod++){
368                         fEMCALMatrix[mod] = (TGeoHMatrix*) mobj->At(mod);
369                         fEMCALGeo->SetMisalMatrix(fEMCALMatrix[mod],mod); 
370
371                         fEMCALMatrix[mod]->Print();
372                 }
373         }
374
375         else AliInfo("MISALLIGNMENT NOT APPLIED");
376
377         return kTRUE;
378 }
379
380 //_____________________________________________________
381 Bool_t AliEMCALTenderSupply::InitBadChannels()
382 {
383         //Initialising Bad channel maps
384
385         AliESDEvent *event=fTender->GetEvent();
386         if (!event) return kFALSE;
387
388         Int_t fRunBC= 0;
389         fRunBC = event->GetRunNumber();
390
391         if (fDebugLevel>0) AliInfo("Initialising Bad channel map \n");  
392
393         if(fFiducial){
394                 fEMCALRecoUtils->SetNumberOfCellsFromEMCALBorder(fNCellsFromEMCALBorder);
395                 fEMCALRecoUtils->SwitchOnNoFiducialBorderInEMCALEta0();
396         }
397
398         fEMCALRecoUtils->SwitchOnBadChannelsRemoval();
399         if(fRecalDistToBadChannels) fEMCALRecoUtils->SwitchOnDistToBadChannelRecalculation();
400
401         TFile *fbad;
402         //2010 
403         if(fRunBC <=140000){
404                 fbad = new TFile("BadChannels.root","read");
405                 if (fbad->IsZombie()){
406                         if (fDebugLevel>1) AliInfo("Connecting to alien to get BadChannels.root \n");   
407                         TGrid::Connect("alien://");
408                         fbad = TFile::Open("alien:///alice/cern.ch/user/g/gconesab/BadChannelsDB/BadChannels.root");
409                 }
410
411                 TH2I * hb0 = ( TH2I *)fbad->Get("EMCALBadChannelMap_Mod0");
412                 TH2I * hb1 = ( TH2I *)fbad->Get("EMCALBadChannelMap_Mod1");
413                 TH2I * hb2 = ( TH2I *)fbad->Get("EMCALBadChannelMap_Mod2");
414                 TH2I * hb3 = ( TH2I *)fbad->Get("EMCALBadChannelMap_Mod3"); 
415                 fEMCALRecoUtils->SetEMCALChannelStatusMap(0,hb0);
416                 fEMCALRecoUtils->SetEMCALChannelStatusMap(1,hb1);
417                 fEMCALRecoUtils->SetEMCALChannelStatusMap(2,hb2);
418                 fEMCALRecoUtils->SetEMCALChannelStatusMap(3,hb3); 
419         }
420
421         //2011
422         if(fRunBC>140000){
423
424                 const Int_t nTowers=89;
425                 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};
426
427                 Int_t nSupMod=-1, nModule=-1, nIphi=-1, nIeta=-1, iphi=-1, ieta=-1;
428                 for(Int_t i=0; i<nTowers; i++)
429                 {
430                         fEMCALGeo->GetCellIndex(hotChannels[i],nSupMod,nModule,nIphi,nIeta);
431
432                         fEMCALGeo->GetCellPhiEtaIndexInSModule(nSupMod,nModule,nIphi,nIeta,iphi,ieta);
433                         fEMCALRecoUtils->SetEMCALChannelStatus(nSupMod, ieta, iphi);
434                 }
435
436         }
437
438         return kTRUE;
439 }
440
441 //_____________________________________________________
442 Bool_t AliEMCALTenderSupply::InitRecalib()
443 {
444         //Initialising Recalibration Factors
445
446         AliESDEvent *event=fTender->GetEvent();
447         if (!event) return kFALSE;
448
449         if (fDebugLevel>0) AliInfo("Initialising Recalibration factors \n");
450         
451         if(fInputTree){ 
452                 fInputFile = fInputTree->GetCurrentFile();
453                 if(fInputFile){
454                         const char *fileName = fInputFile->GetName();
455                         TString FileName = TString(fileName);
456                         if     (FileName.Contains("pass1")) fFilepass = TString("pass1");
457                         else if(FileName.Contains("pass2")) fFilepass = TString("pass2");
458                         else if(FileName.Contains("pass3")) fFilepass = TString("pass3");
459                         else AliError("pass number not found");
460                 }
461                 else AliError("File not found");
462         }
463         else AliError("Tree not found");
464         //        else {cout << "Tree not found " <<endl; return kFALSE;}
465   
466         Int_t runRC = event->GetRunNumber();
467
468   //if (event->GetRunNumber()==runRC)
469   //     return kFALSE;
470
471         fEMCALRecoUtils->SwitchOnRecalibration();
472
473         TFile* fRecalib;
474
475         if(runRC <=140000){
476                 fRecalib = new TFile("RecalibrationFactors.root","read");
477                 if (fRecalib->IsZombie()){
478                         if (fDebugLevel>1) AliInfo("Connecting to alien to get RecalibrationFactors.root \n");  
479
480                         if(     (runRC >= 114737 && runRC <= 117223 && (fFilepass = "pass2")) || //LHC10b pass2 
481                                         (runRC >= 118503 && runRC <= 121040 && ((fFilepass = "pass2")||(fFilepass = "pass3"))) || //LHC10c pass2, LHC10c pass3
482                                         (runRC >= 122195 && runRC <= 126437 && (fFilepass = "pass1")) || //LHC10d pass1
483                                         (runRC >= 127712 && runRC <= 130850 && (fFilepass = "pass1")) || //LHC10e pass1
484                                         (runRC >= 133004 && runRC < 134657  && (fFilepass = "pass1")))// LHC10f pass1 <134657
485                         {
486                                 TGrid::Connect("alien://");
487                                 fRecalib = TFile::Open("alien:///alice/cern.ch/user/g/gconesab/RecalDB/summer_december_2010/RecalibrationFactors.root");
488                         }
489
490                         else if((runRC >= 122195 && runRC <= 126437 && (fFilepass = "pass2")) || //LHC10d pass2
491                                         (runRC >= 134657 && runRC <= 135029 && (fFilepass = "pass1")) || //LHC10f pass1 >= 134657
492                                         (runRC >= 135654 && runRC <= 136377 && (fFilepass = "pass1")) || //LHC10g pass1
493                                         (runRC >= 136851 && runRC < 137231  && (fFilepass = "pass1"))) //LHC10h pass1 untill christmas
494                         {
495                                 TGrid::Connect("alien://");
496                                 fRecalib = TFile::Open("alien:///alice/cern.ch/user/g/gconesab/RecalDB/december2010/RecalibrationFactors.root");
497                         }
498
499                         else if(runRC >= 137231 && runRC <= 139517 && (fFilepass = "pass1")) //LHC10h pass1 from christmas
500                         {
501                                 TGrid::Connect("alien://");
502                                 fRecalib = TFile::Open("alien:///alice/cern.ch/user/g/gconesab/RecalDB/summer2010/RecalibrationFactors.root");
503                         }
504                         else {
505                                 AliError("Run number or pass number not found; RECALIBRATION NOT APPLIED");
506                                 return kTRUE;
507                         }
508
509                 }
510
511                 TH2F * r0 = ( TH2F *)fRecalib->Get("EMCALRecalFactors_SM0");
512                 TH2F * r1 = ( TH2F *)fRecalib->Get("EMCALRecalFactors_SM1");
513                 TH2F * r2 = ( TH2F *)fRecalib->Get("EMCALRecalFactors_SM2");
514                 TH2F * r3 = ( TH2F *)fRecalib->Get("EMCALRecalFactors_SM3");
515                 fEMCALRecoUtils->SetEMCALChannelRecalibrationFactors(0,r0);
516                 fEMCALRecoUtils->SetEMCALChannelRecalibrationFactors(1,r1);
517                 fEMCALRecoUtils->SetEMCALChannelRecalibrationFactors(2,r2);
518                 fEMCALRecoUtils->SetEMCALChannelRecalibrationFactors(3,r3);
519         }
520
521         if(runRC > 140000){
522                 fRecalib = new TFile("RecalibrationFactors.root","read");
523                 if (fRecalib->IsZombie()){
524                         if (fDebugLevel>1) AliInfo("Connecting to alien to get RecalibrationFactors.root \n");
525
526                         TGrid::Connect("alien://");
527                         fRecalib = TFile::Open("alien:///alice/cern.ch/user/g/gconesab/RecalDB/2011_v0/RecalibrationFactors.root");
528                         if(!fRecalib) AliError("Recalibration file not found");
529                         return kFALSE;
530                 }
531
532                 TH2F * r0 = ( TH2F *)fRecalib->Get("EMCALRecalFactors_SM0");
533                 TH2F * r1 = ( TH2F *)fRecalib->Get("EMCALRecalFactors_SM1");
534                 TH2F * r2 = ( TH2F *)fRecalib->Get("EMCALRecalFactors_SM2");
535                 TH2F * r3 = ( TH2F *)fRecalib->Get("EMCALRecalFactors_SM3");
536                 TH2F * r4 = ( TH2F *)fRecalib->Get("EMCALRecalFactors_SM4");
537                 TH2F * r5 = ( TH2F *)fRecalib->Get("EMCALRecalFactors_SM5");
538                 TH2F * r6 = ( TH2F *)fRecalib->Get("EMCALRecalFactors_SM6");
539                 TH2F * r7 = ( TH2F *)fRecalib->Get("EMCALRecalFactors_SM7");
540                 TH2F * r8 = ( TH2F *)fRecalib->Get("EMCALRecalFactors_SM8");
541                 TH2F * r9 = ( TH2F *)fRecalib->Get("EMCALRecalFactors_SM9");
542
543                 fEMCALRecoUtils->SetEMCALChannelRecalibrationFactors(0,r0);
544                 fEMCALRecoUtils->SetEMCALChannelRecalibrationFactors(1,r1);
545                 fEMCALRecoUtils->SetEMCALChannelRecalibrationFactors(2,r2);
546                 fEMCALRecoUtils->SetEMCALChannelRecalibrationFactors(3,r3); 
547                 fEMCALRecoUtils->SetEMCALChannelRecalibrationFactors(4,r4); 
548                 fEMCALRecoUtils->SetEMCALChannelRecalibrationFactors(5,r5); 
549                 fEMCALRecoUtils->SetEMCALChannelRecalibrationFactors(6,r6); 
550                 fEMCALRecoUtils->SetEMCALChannelRecalibrationFactors(7,r7); 
551                 fEMCALRecoUtils->SetEMCALChannelRecalibrationFactors(8,r8); 
552                 fEMCALRecoUtils->SetEMCALChannelRecalibrationFactors(9,r9); 
553
554         }
555
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