]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG4/PartCorrBase/AliCalorimeterUtils.cxx
886dd8de47bf4507363f9e6ee10d78b0aaa42c7f
[u/mrichter/AliRoot.git] / PWG4 / PartCorrBase / AliCalorimeterUtils.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 /* $Id:  $ */
16
17 //_________________________________________________________________________
18 // Class utility for Calorimeter specific selection methods                ///
19 //
20 //
21 //
22 //-- Author: Gustavo Conesa (LPSC-Grenoble) 
23 //////////////////////////////////////////////////////////////////////////////
24
25
26 // --- ROOT system ---
27 #include "TGeoManager.h"
28
29 //---- ANALYSIS system ----
30 #include "AliCalorimeterUtils.h"
31 #include "AliVEvent.h"
32 #include "AliMCEvent.h"
33 #include "AliStack.h"
34 #include "AliAODPWG4Particle.h"
35 #include "AliVCluster.h"
36 #include "AliVCaloCells.h"
37 #include "AliMixedEvent.h"
38
39 ClassImp(AliCalorimeterUtils)
40   
41   
42 //____________________________________________________________________________
43   AliCalorimeterUtils::AliCalorimeterUtils() : 
44     TObject(), fDebug(0), 
45     fEMCALGeoName("EMCAL_FIRSTYEAR"),fPHOSGeoName("PHOSgeo"), 
46     fEMCALGeo(0x0), fPHOSGeo(0x0), 
47     fEMCALGeoMatrixSet(kFALSE), fPHOSGeoMatrixSet(kFALSE), 
48     fRemoveBadChannels(kFALSE),fPHOSBadChannelMap(0x0), 
49     fNCellsFromPHOSBorder(0), fRecalibration(kFALSE),
50     fPHOSRecalibrationFactors(),
51     fEMCALRecoUtils(new AliEMCALRecoUtils),
52     fRecalculatePosition(kFALSE),fCorrectELinearity(kFALSE),
53     fRecalculateMatching(kFALSE),fCutR(20), fCutZ(20)
54 {
55   //Ctor
56   
57   //Initialize parameters
58   InitParameters();
59 }
60
61 //_________________________________
62 AliCalorimeterUtils::~AliCalorimeterUtils() {
63   //Dtor
64   
65   //if(fPHOSGeo)  delete fPHOSGeo  ;
66   if(fEMCALGeo) delete fEMCALGeo ;
67
68   if(fPHOSBadChannelMap) { 
69     fPHOSBadChannelMap->Clear();
70     delete  fPHOSBadChannelMap;
71   }
72         
73   if(fPHOSRecalibrationFactors) { 
74     fPHOSRecalibrationFactors->Clear();
75     delete  fPHOSRecalibrationFactors;
76   }
77         
78   if(fEMCALRecoUtils) delete fEMCALRecoUtils ;
79   
80 }
81
82 //_______________________________________________________________
83 Bool_t AliCalorimeterUtils::CheckCellFiducialRegion(AliVCluster* cluster, AliVCaloCells* cells, AliVEvent * event, Int_t iev) const {
84
85         // Given the list of AbsId of the cluster, get the maximum cell and 
86         // check if there are fNCellsFromBorder from the calorimeter border
87         
88     //If the distance to the border is 0 or negative just exit accept all clusters
89         if(cells->GetType()==AliVCaloCells::kEMCALCell && fEMCALRecoUtils->GetNumberOfCellsFromEMCALBorder() <= 0 ) return kTRUE;
90         if(cells->GetType()==AliVCaloCells::kPHOSCell  && fNCellsFromPHOSBorder  <= 0 ) return kTRUE;
91
92   Int_t absIdMax        = -1;
93         Float_t ampMax  = -1;
94         
95   AliMixedEvent * mixEvent = dynamic_cast<AliMixedEvent*> (event);
96   Int_t nMixedEvents = 0 ; 
97   Int_t * cellsCumul = NULL ;
98   Int_t numberOfCells = 0 ;  
99   if (mixEvent){
100     nMixedEvents = mixEvent->GetNumberOfEvents() ; 
101     if (cells->GetType()==AliVCaloCells::kEMCALCell) {
102       cellsCumul =  mixEvent->GetEMCALCellsCumul() ; 
103       numberOfCells = mixEvent->GetNumberOfEMCALCells() ;
104     } 
105       
106     else if (cells->GetType()==AliVCaloCells::kPHOSCell) {
107       cellsCumul =  mixEvent->GetPHOSCellsCumul() ; 
108       numberOfCells = mixEvent->GetNumberOfPHOSCells() ;
109     } 
110     
111     if(cellsCumul){
112       
113       Int_t startCell = cellsCumul[iev] ; 
114       Int_t endCell   = (iev+1 < nMixedEvents)?cellsCumul[iev+1]:numberOfCells;
115       //Find cells with maximum amplitude
116       for(Int_t i = 0; i < cluster->GetNCells() ; i++){
117         Int_t absId = cluster->GetCellAbsId(i) ;
118         for (Int_t j = startCell; j < endCell ;  j++) {
119           Short_t cellNumber; 
120           Double_t amp ; 
121           Double_t time; 
122           cells->GetCell(j, cellNumber, amp, time) ; 
123           if (absId == cellNumber) {
124             if(amp > ampMax){
125               ampMax   = amp;
126               absIdMax = absId;
127             }        
128           }
129         }
130       }//loop on cluster cells
131     }// cells cumul available
132     else {
133       printf("AliCalorimeterUtils::CheckCellFiducialRegion() - CellsCumul is NULL!!!\n");
134       abort();
135     }
136   } else {//Normal SE Events
137     for(Int_t i = 0; i < cluster->GetNCells() ; i++){
138       Int_t absId = cluster->GetCellAbsId(i) ;
139       Float_t amp       = cells->GetCellAmplitude(absId);
140       if(amp > ampMax){
141         ampMax   = amp;
142         absIdMax = absId;
143       }
144     }
145   }
146         
147         if(fDebug > 1)
148                 printf("AliCalorimeterUtils::CheckCellFiducialRegion() - Cluster Max AbsId %d, Cell Energy %2.2f, Cluster Energy %2.2f\n", 
149                    absIdMax, ampMax, cluster->E());
150         
151         if(absIdMax==-1) return kFALSE;
152         
153         //Check if the cell is close to the borders:
154         Bool_t okrow = kFALSE;
155         Bool_t okcol = kFALSE;
156
157         if(cells->GetType()==AliVCaloCells::kEMCALCell){
158         
159                 Int_t iTower = -1, iIphi = -1, iIeta = -1, iphi = -1, ieta = -1, iSM = -1; 
160                 fEMCALGeo->GetCellIndex(absIdMax,iSM,iTower,iIphi,iIeta); 
161                 fEMCALGeo->GetCellPhiEtaIndexInSModule(iSM,iTower,iIphi, iIeta,iphi,ieta);
162                 if(iSM < 0 || iphi < 0 || ieta < 0 ) {
163       Fatal("CheckCellFidutialRegion","Negative value for super module: %d, or cell ieta: %d, or cell iphi: %d, check EMCAL geometry name\n",iSM,ieta,iphi);
164     }
165       
166                 //Check rows/phi
167     Int_t nborder = fEMCALRecoUtils->GetNumberOfCellsFromEMCALBorder();
168                 if(iSM < 10){
169                         if(iphi >= nborder && iphi < 24-nborder) okrow =kTRUE; 
170             }
171                 else{
172                         if(iphi >= nborder && iphi < 12-nborder) okrow =kTRUE; 
173                 }
174                 
175                 //Check columns/eta
176                 if(!fEMCALRecoUtils->IsEMCALNoBorderAtEta0()){
177                         if(ieta  > nborder && ieta < 48-nborder) okcol =kTRUE; 
178                 }
179                 else{
180                         if(iSM%2==0){
181                                 if(ieta >= nborder)     okcol = kTRUE;  
182                         }
183                         else {
184                                 if(ieta <  48-nborder)  okcol = kTRUE;  
185                         }
186                 }//eta 0 not checked
187                 if(fDebug > 1)
188                 {
189                         printf("AliCalorimeterUtils::CheckCellFiducialRegion() - EMCAL Cluster in %d cells fiducial volume: ieta %d, iphi %d, SM %d ?",
190                                    nborder, ieta, iphi, iSM);
191                         if (okcol && okrow ) printf(" YES \n");
192                         else  printf(" NO: column ok? %d, row ok? %d \n",okcol,okrow);
193                 }
194         }//EMCAL
195         else if(cells->GetType()==AliVCaloCells::kPHOSCell){
196                 Int_t relId[4];
197                 Int_t irow = -1, icol = -1;
198                 fPHOSGeo->AbsToRelNumbering(absIdMax,relId);
199                 irow = relId[2];
200                 icol = relId[3];
201                 //imod = relId[0]-1;
202                 if(irow >= fNCellsFromPHOSBorder && irow < 64-fNCellsFromPHOSBorder) okrow =kTRUE; 
203                 if(icol >= fNCellsFromPHOSBorder && icol < 56-fNCellsFromPHOSBorder) okcol =kTRUE; 
204                 if(fDebug > 1)
205                 {
206                         printf("AliCalorimeterUtils::CheckCellFiducialRegion() - PHOS Cluster in %d cells fiducial volume: icol %d, irow %d, Module %d?",
207                                    fNCellsFromPHOSBorder, icol, irow, relId[0]-1);
208                         if (okcol && okrow ) printf(" YES \n");
209                         else  printf(" NO: column ok? %d, row ok? %d \n",okcol,okrow);
210                 }
211         }//PHOS
212         
213         if (okcol && okrow) return kTRUE; 
214         else                return kFALSE;
215         
216 }       
217
218 //_________________________________________________________________________________________________________
219 Bool_t AliCalorimeterUtils::ClusterContainsBadChannel(TString calorimeter,UShort_t* cellList, Int_t nCells){
220         // Check that in the cluster cells, there is no bad channel of those stored 
221         // in fEMCALBadChannelMap or fPHOSBadChannelMap
222         
223         if (!fRemoveBadChannels) return kFALSE;
224         //printf("fEMCALBadChannelMap %p, fPHOSBadChannelMap %p \n",fEMCALBadChannelMap,fPHOSBadChannelMap);
225         if(calorimeter == "EMCAL" && !fEMCALRecoUtils->GetEMCALChannelStatusMap(0)) return kFALSE;
226         if(calorimeter == "PHOS"  && !fPHOSBadChannelMap)  return kFALSE;
227
228         Int_t icol = -1;
229         Int_t irow = -1;
230         Int_t imod = -1;
231         for(Int_t iCell = 0; iCell<nCells; iCell++){
232         
233                 //Get the column and row
234                 if(calorimeter == "EMCAL"){
235       return fEMCALRecoUtils->ClusterContainsBadChannel((AliEMCALGeometry*)fEMCALGeo,cellList,nCells);
236                 }
237                 else if(calorimeter=="PHOS"){
238                         Int_t    relId[4];
239                         fPHOSGeo->AbsToRelNumbering(cellList[iCell],relId);
240                         irow = relId[2];
241                         icol = relId[3];
242                         imod = relId[0]-1;
243                         if(fPHOSBadChannelMap->GetEntries() <= imod)continue;
244                         if(GetPHOSChannelStatus(imod, icol, irow)) return kTRUE;
245                 }
246                 else return kFALSE;
247                 
248         }// cell cluster loop
249
250         return kFALSE;
251
252 }
253
254 //____________________________________________________________________________________________________________________________________________________
255 void AliCalorimeterUtils::CorrectClusterEnergy(AliVCluster *clus){
256   // Correct cluster energy non linearity
257   clus->SetE(fEMCALRecoUtils->CorrectClusterEnergyLinearity(clus));
258 }
259
260 //____________________________________________________________________________________________________________________________________________________
261 Int_t AliCalorimeterUtils::GetModuleNumber(AliAODPWG4Particle * particle, AliVEvent * inputEvent) const
262 {
263         //Get the EMCAL/PHOS module number that corresponds to this particle
264         
265         Int_t absId = -1;
266         if(particle->GetDetector()=="EMCAL"){
267                 fEMCALGeo->GetAbsCellIdFromEtaPhi(particle->Eta(),particle->Phi(), absId);
268                 if(fDebug > 2) 
269                   printf("AliCalorimeterUtils::GetModuleNumber(PWG4AOD) - EMCAL: cluster eta %f, phi %f, absid %d, SuperModule %d\n",
270                          particle->Eta(), particle->Phi()*TMath::RadToDeg(),absId, fEMCALGeo->GetSuperModuleNumber(absId));
271                 return fEMCALGeo->GetSuperModuleNumber(absId) ;
272         }//EMCAL
273         else if(particle->GetDetector()=="PHOS"){
274     // In case we use the MC reader, the input are TParticles, 
275     // in this case use the corresponing method in PHOS Geometry to get the particle.
276     if(strcmp(inputEvent->ClassName(), "AliMCEvent") == 0 )
277     {
278       Int_t mod =-1;
279       Double_t z = 0., x=0.;
280       TParticle* primary = 0x0;
281       AliStack * stack = ((AliMCEvent*)inputEvent)->Stack();
282       if(stack) {
283         primary = stack->Particle(particle->GetCaloLabel(0));
284       }
285       else {
286         Fatal("GetModuleNumber(PWG4AOD)", "Stack not available, stop!");
287       }
288       
289       if(primary){
290         fPHOSGeo->ImpactOnEmc(primary,mod,z,x) ;
291       }
292       else{
293         Fatal("GetModuleNumber(PWG4AOD)", "Primary not available, stop!");
294       }
295       return mod;
296     }
297     // Input are ESDs or AODs, get the PHOS module number like this.
298     else{
299       AliVCluster *cluster = inputEvent->GetCaloCluster(particle->GetCaloLabel(0));
300       return GetModuleNumber(cluster);
301     }
302         }//PHOS
303         
304         return -1;
305 }
306
307 //____________________________________________________________________________________________________________________________________________________
308 Int_t AliCalorimeterUtils::GetModuleNumber(AliVCluster * cluster) const
309 {
310         //Get the EMCAL/PHOS module number that corresponds to this cluster
311         TLorentzVector lv;
312         Double_t v[]={0.,0.,0.}; //not necessary to pass the real vertex.
313         cluster->GetMomentum(lv,v);
314         Float_t phi = lv.Phi();
315         if(phi < 0) phi+=TMath::TwoPi();        
316         Int_t absId = -1;
317         if(cluster->IsEMCAL()){
318                 fEMCALGeo->GetAbsCellIdFromEtaPhi(lv.Eta(),phi, absId);
319                 if(fDebug > 2) 
320                   printf("AliCalorimeterUtils::GetModuleNumber() - EMCAL: cluster eta %f, phi %f, absid %d, SuperModule %d\n",
321                          lv.Eta(), phi*TMath::RadToDeg(),absId, fEMCALGeo->GetSuperModuleNumber(absId));
322                 return fEMCALGeo->GetSuperModuleNumber(absId) ;
323         }//EMCAL
324         else if(cluster->IsPHOS()) {
325                 Int_t    relId[4];
326                 if ( cluster->GetNCells() > 0) {
327                         absId = cluster->GetCellAbsId(0);
328                         if(fDebug > 2) 
329                                 printf("AliCalorimeterUtils::GetModuleNumber() - PHOS: cluster eta %f, phi %f, e %f, absId %d\n",
330                                            lv.Eta(), phi*TMath::RadToDeg(), lv.E(), absId);
331                 }
332                 else return -1;
333                 
334                 if ( absId >= 0) {
335                         fPHOSGeo->AbsToRelNumbering(absId,relId);
336                         if(fDebug > 2) 
337                           printf("AliCalorimeterUtils::GetModuleNumber() - PHOS: Module %d\n",relId[0]-1);
338                         return relId[0]-1;
339                 }
340                 else return -1;
341         }//PHOS
342         
343         return -1;
344 }
345
346 //_____________________________________________________________________________________________________________
347 Int_t AliCalorimeterUtils::GetModuleNumberCellIndexes(const Int_t absId, const TString calo, Int_t & icol, Int_t & irow, Int_t & iRCU) const
348 {
349         //Get the EMCAL/PHOS module, columns, row and RCU number that corresponds to this absId
350         Int_t imod = -1;
351         if ( absId >= 0) {
352                 if(calo=="EMCAL"){
353                         Int_t iTower = -1, iIphi = -1, iIeta = -1; 
354                         fEMCALGeo->GetCellIndex(absId,imod,iTower,iIphi,iIeta); 
355                         fEMCALGeo->GetCellPhiEtaIndexInSModule(imod,iTower,iIphi, iIeta,irow,icol);
356       if(imod < 0 || irow < 0 || icol < 0 ) {
357         Fatal("GetModuleNumberCellIndexes()","Negative value for super module: %d, or cell icol: %d, or cell irow: %d, check EMCAL geometry name\n",imod,icol,irow);
358       }
359       
360                         //RCU0
361                         if (0<=irow&&irow<8) iRCU=0; // first cable row
362                         else if (8<=irow&&irow<16 && 0<=icol&&icol<24) iRCU=0; // first half; 
363                         //second cable row
364                         //RCU1
365                         else if(8<=irow&&irow<16 && 24<=icol&&icol<48) iRCU=1; // second half; 
366                         //second cable row
367                         else if(16<=irow&&irow<24) iRCU=1; // third cable row
368                         
369                         if (imod%2==1) iRCU = 1 - iRCU; // swap for odd=C side, to allow us to cable both sides the same
370                         if (iRCU<0) {
371                                 Fatal("GetModuleNumberCellIndexes()","Wrong EMCAL RCU number = %d\n", iRCU);
372                         }                       
373                         
374                         return imod ;
375                 }//EMCAL
376                 else{//PHOS
377                         Int_t    relId[4];
378                         fPHOSGeo->AbsToRelNumbering(absId,relId);
379                         irow = relId[2];
380                         icol = relId[3];
381                         imod = relId[0]-1;
382                         iRCU= (Int_t)(relId[2]-1)/16 ;
383                         //Int_t iBranch= (Int_t)(relid[3]-1)/28 ; //0 to 1
384                         if (iRCU >= 4) {
385                                 Fatal("GetModuleNumberCellIndexes()","Wrong PHOS RCU number = %d\n", iRCU);
386                         }                       
387                         return imod;
388                 }//PHOS 
389         }
390         
391         return -1;
392 }
393
394 //_______________________________________________________________
395 //void AliCalorimeterUtils::Init()
396 //{
397 //      //Init reader. Method to be called in AliAnaPartCorrMaker
398 //      
399 //      fEMCALBadChannelMap->SetName(Form("EMCALBadMap_%s",fTaskName.Data()));
400 //      fPHOSBadChannelMap->SetName(Form("PHOSBadMap_%s",fTaskName.Data()));
401 //}
402
403 //_______________________________________________________________
404 void AliCalorimeterUtils::InitParameters()
405 {
406   //Initialize the parameters of the analysis.
407   fEMCALGeoName = "EMCAL_FIRSTYEAR";
408   fPHOSGeoName  = "PHOSgeo";
409         
410   if(gGeoManager) {// geoManager was set
411         if(fDebug > 2)printf("AliCalorimeterUtils::InitParameters() - Geometry manager available\n");
412         fEMCALGeoMatrixSet = kTRUE;      
413         fPHOSGeoMatrixSet  = kTRUE;      
414   }
415   else{
416         fEMCALGeoMatrixSet = kFALSE;
417         fPHOSGeoMatrixSet  = kFALSE;
418   }
419                 
420   fRemoveBadChannels   = kFALSE;
421         
422   fNCellsFromPHOSBorder    = 0;
423 }
424
425
426 //________________________________________________________________
427 void AliCalorimeterUtils::InitPHOSBadChannelStatusMap(){
428   //Init PHOS bad channels map
429   if(fDebug > 0 )printf("AliCalorimeterUtils::InitPHOSBadChannelStatusMap()\n");
430   //In order to avoid rewriting the same histograms
431   Bool_t oldStatus = TH1::AddDirectoryStatus();
432   TH1::AddDirectory(kFALSE);
433
434   fPHOSBadChannelMap = new TObjArray(5);        
435   for (int i = 0; i < 5; i++)fPHOSBadChannelMap->Add(new TH2I(Form("PHOSBadChannelMap_Mod%d",i),Form("PHOSBadChannelMap_Mod%d",i), 56, 0, 56, 64, 0, 64));
436
437   fPHOSBadChannelMap->SetOwner(kTRUE);
438   fPHOSBadChannelMap->Compress();
439   
440   //In order to avoid rewriting the same histograms
441   TH1::AddDirectory(oldStatus);         
442 }
443
444 //________________________________________________________________
445 void AliCalorimeterUtils::InitPHOSRecalibrationFactors(){
446         //Init EMCAL recalibration factors
447         if(fDebug > 0 )printf("AliCalorimeterUtils::InitPHOSRecalibrationFactors()\n");
448         //In order to avoid rewriting the same histograms
449         Bool_t oldStatus = TH1::AddDirectoryStatus();
450         TH1::AddDirectory(kFALSE);
451
452         fPHOSRecalibrationFactors = new TObjArray(5);
453         for (int i = 0; i < 5; i++)fPHOSRecalibrationFactors->Add(new TH2F(Form("PHOSRecalFactors_Mod%d",i),Form("PHOSRecalFactors_Mod%d",i), 56, 0, 56, 64, 0, 64));
454         //Init the histograms with 1
455         for (Int_t m = 0; m < 5; m++) {
456                 for (Int_t i = 0; i < 56; i++) {
457                         for (Int_t j = 0; j < 64; j++) {
458                                 SetPHOSChannelRecalibrationFactor(m,i,j,1.);
459                         }
460                 }
461         }
462         fPHOSRecalibrationFactors->SetOwner(kTRUE);
463         fPHOSRecalibrationFactors->Compress();
464         
465         //In order to avoid rewriting the same histograms
466         TH1::AddDirectory(oldStatus);           
467 }
468
469
470 //________________________________________________________________
471 void AliCalorimeterUtils::InitEMCALGeometry()
472 {
473         //Initialize EMCAL geometry if it did not exist previously
474         if (!fEMCALGeo){
475                 fEMCALGeo = new AliEMCALGeoUtils(fEMCALGeoName);
476                 if(fDebug > 0){
477                         printf("AliCalorimeterUtils::InitEMCALGeometry()");
478                         if (!gGeoManager) printf(" - Careful!, gGeoManager not loaded, load misalign matrices");
479                         printf("\n");
480                 }
481         }
482 }
483
484 //________________________________________________________________
485 void AliCalorimeterUtils::InitPHOSGeometry()
486 {
487         //Initialize PHOS geometry if it did not exist previously
488         if (!fPHOSGeo){
489                 fPHOSGeo = new AliPHOSGeoUtils(fPHOSGeoName); 
490                 if(fDebug > 0){
491                         printf("AliCalorimeterUtils::InitPHOSGeometry()");
492                         if (!gGeoManager) printf(" - Careful!, gGeoManager not loaded, load misalign matrices");
493                         printf("\n");
494                 }       
495         }       
496 }
497
498 //________________________________________________________________
499 void AliCalorimeterUtils::Print(const Option_t * opt) const
500 {
501
502   //Print some relevant parameters set for the analysis
503   if(! opt)
504     return;
505
506   printf("***** Print: %s %s ******\n", GetName(), GetTitle() ) ;
507   printf("Remove Clusters with bad channels? %d\n",fRemoveBadChannels);
508   printf("Remove Clusters with max cell at less than %d cells from EMCAL border and %d cells from PHOS border\n",
509          fEMCALRecoUtils->GetNumberOfCellsFromEMCALBorder(), fNCellsFromPHOSBorder);
510   if(fEMCALRecoUtils->IsEMCALNoBorderAtEta0()) printf("Do not remove EMCAL clusters at Eta = 0\n");
511   printf("Recalibrate Clusters? %d\n",fRecalibration);
512   printf("Recalculate Clusters Position? %d\n",fRecalculatePosition);
513   printf("Recalculate Clusters Energy? %d\n",fCorrectELinearity);
514   printf("Matching criteria: dR < %2.2f[cm], dZ < %2.2f[cm]\n",fCutR,fCutZ);
515
516   printf("    \n") ;
517
518
519 //________________________________________________________________
520 Float_t AliCalorimeterUtils::RecalibrateClusterEnergy(AliVCluster * cluster, AliVCaloCells * cells){
521         // Recalibrate the cluster energy, considering the recalibration map and the energy of the cells that compose the cluster.
522
523   //Initialize some used variables
524         Float_t energy   = 0;
525         Int_t absId      = -1;
526         Int_t icol = -1, irow = -1, iRCU = -1, module=1;
527         Float_t factor = 1, frac = 0;  
528   
529         if(cells) {
530         
531         //Get the cluster number of cells and list of absId, check what kind of cluster do we have.
532         UShort_t * index    = cluster->GetCellsAbsId() ;
533         Double_t * fraction = cluster->GetCellsAmplitudeFraction() ;
534         Int_t ncells     = cluster->GetNCells();        
535         TString calo     = "EMCAL";
536         if(cluster->IsPHOS()) calo = "PHOS";
537         
538         //Loop on the cells, get the cell amplitude and recalibration factor, multiply and and to the new energy
539         for(Int_t icell = 0; icell < ncells; icell++){
540                 absId = index[icell];
541                 frac =  fraction[icell];
542                 if(frac < 1e-3) frac = 1; //in case of EMCAL, this is set as 0, not used.
543         module = GetModuleNumberCellIndexes(absId,calo,icol,irow,iRCU);
544                 if(cluster->IsPHOS()) factor = GetPHOSChannelRecalibrationFactor (module,icol,irow);
545                 else                  factor = GetEMCALChannelRecalibrationFactor(module,icol,irow);
546                 if(fDebug>2)
547                         printf("AliCalorimeterUtils::RecalibrateClusterEnergy() - recalibrate cell: %s, module %d, col %d, row %d, cell fraction %f, recalibration factor %f, cell energy %f\n", 
548                                 calo.Data(),module,icol,irow,frac,factor,cells->GetCellAmplitude(absId));
549                 
550                 energy += cells->GetCellAmplitude(absId)*factor*frac;
551         }
552         
553         if(fDebug>1)
554                 printf("AliCalorimeterUtils::RecalibrateClusterEnergy() - Energy before %f, after %f\n",cluster->E(),energy);
555     
556         }// cells available
557   else{
558     Fatal("RecalibrateClusterEnergy()","Cells pointer does not exist!");
559   }
560   
561         return energy;
562 }
563
564 //________________________________________________________________
565 void AliCalorimeterUtils::SetGeometryTransformationMatrices(AliVEvent* inputEvent) 
566 {
567   //Set the calorimeters transformation matrices
568         
569   //Get the EMCAL transformation geometry matrices from ESD 
570   if (!gGeoManager && fEMCALGeo && !fEMCALGeoMatrixSet) { 
571           if(fDebug > 1) 
572                   printf(" AliCalorimeterUtils::SetGeometryTransformationMatrices() - Load EMCAL misalignment matrices. \n");
573           if(!strcmp(inputEvent->GetName(),"AliESDEvent"))  {
574                         for(Int_t mod=0; mod < (fEMCALGeo->GetEMCGeometry())->GetNumberOfSuperModules(); mod++){ 
575                                 if(inputEvent->GetEMCALMatrix(mod)) {
576                                         //printf("EMCAL: mod %d, matrix %p\n",mod, ((AliESDEvent*)inputEvent)->GetEMCALMatrix(mod));
577                                         fEMCALGeo->SetMisalMatrix(inputEvent->GetEMCALMatrix(mod),mod) ;
578                                         fEMCALGeoMatrixSet = kTRUE;//At least one, so good
579                                 }
580                         }// loop over super modules     
581                 }//ESD as input
582                 else {
583                         if(fDebug > 1)
584                                 printf("AliCalorimeterUtils::SetGeometryTransformationMatrices() - Setting of EMCAL transformation matrixes for AODs not implemented yet. \n Import geometry.root file\n");
585                                 }//AOD as input
586   }//EMCAL geo && no geoManager
587         
588         //Get the PHOS transformation geometry matrices from ESD 
589         if (!gGeoManager && fPHOSGeo && !fPHOSGeoMatrixSet) {
590                 if(fDebug > 1) 
591                         printf(" AliCalorimeterUtils::SetGeometryTransformationMatrices() - Load PHOS misalignment matrices. \n");
592                         if(!strcmp(inputEvent->GetName(),"AliESDEvent"))  {
593                                 for(Int_t mod=0; mod < 5; mod++){ 
594                                         if(inputEvent->GetPHOSMatrix(mod)) {
595                                                 //printf("PHOS: mod %d, matrix %p\n",mod, ((AliESDEvent*)inputEvent)->GetPHOSMatrix(mod));
596                                                 fPHOSGeo->SetMisalMatrix(inputEvent->GetPHOSMatrix(mod),mod) ;
597                                                 fPHOSGeoMatrixSet  = kTRUE; //At least one so good
598                                         }
599                                 }// loop over modules   
600                         }//ESD as input
601                         else {
602                                 if(fDebug > 1) 
603                                         printf("AliCalorimeterUtils::SetGeometryTransformationMatrices() - Setting of EMCAL transformation matrixes for AODs not implemented yet. \n Import geometry.root file\n");
604                                         }//AOD as input
605         }//PHOS geo     and  geoManager was not set
606
607 }
608
609 //________________________________________________________________
610 void AliCalorimeterUtils::RecalculateClusterPosition(AliVCaloCells* cells, AliVCluster* clu){
611   
612   //Recalculate EMCAL cluster position
613   
614   fEMCALRecoUtils->RecalculateClusterPosition((AliEMCALGeometry*)fEMCALGeo, cells,clu);
615
616 }