Add method to recalculate cluster distance to bad channels
[u/mrichter/AliRoot.git] / PWG4 / PartCorrBase / AliCalorimeterUtils.cxx
CommitLineData
765d44e7 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"
c8fe2783 31#include "AliVEvent.h"
46a3cde6 32#include "AliMCEvent.h"
33#include "AliStack.h"
765d44e7 34#include "AliAODPWG4Particle.h"
c8fe2783 35#include "AliVCluster.h"
36#include "AliVCaloCells.h"
37#include "AliMixedEvent.h"
765d44e7 38
39ClassImp(AliCalorimeterUtils)
40
41
42//____________________________________________________________________________
43 AliCalorimeterUtils::AliCalorimeterUtils() :
44 TObject(), fDebug(0),
c8fe2783 45 fEMCALGeoName("EMCAL_FIRSTYEAR"),fPHOSGeoName("PHOSgeo"),
765d44e7 46 fEMCALGeo(0x0), fPHOSGeo(0x0),
47 fEMCALGeoMatrixSet(kFALSE), fPHOSGeoMatrixSet(kFALSE),
247abff4 48 fRemoveBadChannels(kFALSE),fPHOSBadChannelMap(0x0),
49 fNCellsFromPHOSBorder(0), fRecalibration(kFALSE),
19db8f8c 50 fPHOSRecalibrationFactors(),
247abff4 51 fEMCALRecoUtils(new AliEMCALRecoUtils),
f2ccb5b8 52 fRecalculatePosition(kFALSE),fCorrectELinearity(kFALSE),
53 fRecalculateMatching(kFALSE),fCutR(20), fCutZ(20)
765d44e7 54{
55 //Ctor
56
57 //Initialize parameters
58 InitParameters();
59}
765d44e7 60
61//_________________________________
62AliCalorimeterUtils::~AliCalorimeterUtils() {
63 //Dtor
64
4df35693 65 //if(fPHOSGeo) delete fPHOSGeo ;
765d44e7 66 if(fEMCALGeo) delete fEMCALGeo ;
247abff4 67
765d44e7 68 if(fPHOSBadChannelMap) {
69 fPHOSBadChannelMap->Clear();
70 delete fPHOSBadChannelMap;
71 }
72
09e819c9 73 if(fPHOSRecalibrationFactors) {
78219bac 74 fPHOSRecalibrationFactors->Clear();
75 delete fPHOSRecalibrationFactors;
09e819c9 76 }
77
9584c261 78 if(fEMCALRecoUtils) delete fEMCALRecoUtils ;
79
765d44e7 80}
81
82//_______________________________________________________________
c8fe2783 83Bool_t AliCalorimeterUtils::CheckCellFiducialRegion(AliVCluster* cluster, AliVCaloCells* cells, AliVEvent * event, Int_t iev) const {
84
765d44e7 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
c8fe2783 88 //If the distance to the border is 0 or negative just exit accept all clusters
247abff4 89 if(cells->GetType()==AliVCaloCells::kEMCALCell && fEMCALRecoUtils->GetNumberOfCellsFromEMCALBorder() <= 0 ) return kTRUE;
c8fe2783 90 if(cells->GetType()==AliVCaloCells::kPHOSCell && fNCellsFromPHOSBorder <= 0 ) return kTRUE;
765d44e7 91
c8fe2783 92 Int_t absIdMax = -1;
765d44e7 93 Float_t ampMax = -1;
c8fe2783 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 }
898c9d44 110
111 if(cellsCumul){
112
113 Int_t startCell = cellsCumul[iev] ;
114 Int_t endCell = (iev+1 < nMixedEvents)?cellsCumul[iev+1]:numberOfCells;
c8fe2783 115 //Find cells with maximum amplitude
898c9d44 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 }
c8fe2783 129 }
898c9d44 130 }//loop on cluster cells
131 }// cells cumul available
132 else {
133 printf("AliCalorimeterUtils::CheckCellFiducialRegion() - CellsCumul is NULL!!!\n");
134 abort();
c8fe2783 135 }
898c9d44 136 } else {//Normal SE Events
c8fe2783 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 }
765d44e7 146
147 if(fDebug > 1)
280e6766 148 printf("AliCalorimeterUtils::CheckCellFiducialRegion() - Cluster Max AbsId %d, Cell Energy %2.2f, Cluster Energy %2.2f\n",
765d44e7 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
c8fe2783 157 if(cells->GetType()==AliVCaloCells::kEMCALCell){
765d44e7 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);
280e6766 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
765d44e7 166 //Check rows/phi
247abff4 167 Int_t nborder = fEMCALRecoUtils->GetNumberOfCellsFromEMCALBorder();
765d44e7 168 if(iSM < 10){
247abff4 169 if(iphi >= nborder && iphi < 24-nborder) okrow =kTRUE;
765d44e7 170 }
171 else{
247abff4 172 if(iphi >= nborder && iphi < 12-nborder) okrow =kTRUE;
765d44e7 173 }
174
247abff4 175 //Check columns/eta
176 if(!fEMCALRecoUtils->IsEMCALNoBorderAtEta0()){
177 if(ieta > nborder && ieta < 48-nborder) okcol =kTRUE;
765d44e7 178 }
179 else{
180 if(iSM%2==0){
247abff4 181 if(ieta >= nborder) okcol = kTRUE;
765d44e7 182 }
183 else {
247abff4 184 if(ieta < 48-nborder) okcol = kTRUE;
765d44e7 185 }
186 }//eta 0 not checked
187 if(fDebug > 1)
188 {
280e6766 189 printf("AliCalorimeterUtils::CheckCellFiducialRegion() - EMCAL Cluster in %d cells fiducial volume: ieta %d, iphi %d, SM %d ?",
247abff4 190 nborder, ieta, iphi, iSM);
765d44e7 191 if (okcol && okrow ) printf(" YES \n");
192 else printf(" NO: column ok? %d, row ok? %d \n",okcol,okrow);
193 }
194 }//EMCAL
c8fe2783 195 else if(cells->GetType()==AliVCaloCells::kPHOSCell){
765d44e7 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 {
280e6766 206 printf("AliCalorimeterUtils::CheckCellFiducialRegion() - PHOS Cluster in %d cells fiducial volume: icol %d, irow %d, Module %d?",
765d44e7 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
765d44e7 218//_________________________________________________________________________________________________________
219Bool_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;
36037088 224 //printf("fEMCALBadChannelMap %p, fPHOSBadChannelMap %p \n",fEMCALBadChannelMap,fPHOSBadChannelMap);
247abff4 225 if(calorimeter == "EMCAL" && !fEMCALRecoUtils->GetEMCALChannelStatusMap(0)) return kFALSE;
78219bac 226 if(calorimeter == "PHOS" && !fPHOSBadChannelMap) return kFALSE;
765d44e7 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"){
247abff4 235 return fEMCALRecoUtils->ClusterContainsBadChannel((AliEMCALGeometry*)fEMCALGeo,cellList,nCells);
765d44e7 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//____________________________________________________________________________________________________________________________________________________
9584c261 255void AliCalorimeterUtils::CorrectClusterEnergy(AliVCluster *clus){
256 // Correct cluster energy non linearity
257 clus->SetE(fEMCALRecoUtils->CorrectClusterEnergyLinearity(clus));
258}
259
260//____________________________________________________________________________________________________________________________________________________
765d44e7 261Int_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"){
46a3cde6 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 {
280e6766 286 Fatal("GetModuleNumber(PWG4AOD)", "Stack not available, stop!");
46a3cde6 287 }
898c9d44 288
289 if(primary){
290 fPHOSGeo->ImpactOnEmc(primary,mod,z,x) ;
291 }
292 else{
293 Fatal("GetModuleNumber(PWG4AOD)", "Primary not available, stop!");
294 }
46a3cde6 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 }
765d44e7 302 }//PHOS
303
304 return -1;
305}
306
307//____________________________________________________________________________________________________________________________________________________
c8fe2783 308Int_t AliCalorimeterUtils::GetModuleNumber(AliVCluster * cluster) const
765d44e7 309{
280e6766 310 //Get the EMCAL/PHOS module number that corresponds to this cluster
765d44e7 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;
c8fe2783 317 if(cluster->IsEMCAL()){
765d44e7 318 fEMCALGeo->GetAbsCellIdFromEtaPhi(lv.Eta(),phi, absId);
319 if(fDebug > 2)
280e6766 320 printf("AliCalorimeterUtils::GetModuleNumber() - EMCAL: cluster eta %f, phi %f, absid %d, SuperModule %d\n",
765d44e7 321 lv.Eta(), phi*TMath::RadToDeg(),absId, fEMCALGeo->GetSuperModuleNumber(absId));
322 return fEMCALGeo->GetSuperModuleNumber(absId) ;
323 }//EMCAL
c8fe2783 324 else if(cluster->IsPHOS()) {
765d44e7 325 Int_t relId[4];
326 if ( cluster->GetNCells() > 0) {
327 absId = cluster->GetCellAbsId(0);
328 if(fDebug > 2)
280e6766 329 printf("AliCalorimeterUtils::GetModuleNumber() - PHOS: cluster eta %f, phi %f, e %f, absId %d\n",
765d44e7 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)
280e6766 337 printf("AliCalorimeterUtils::GetModuleNumber() - PHOS: Module %d\n",relId[0]-1);
765d44e7 338 return relId[0]-1;
339 }
340 else return -1;
341 }//PHOS
342
343 return -1;
344}
345
765d44e7 346//_____________________________________________________________________________________________________________
347Int_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);
280e6766 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
765d44e7 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) {
280e6766 371 Fatal("GetModuleNumberCellIndexes()","Wrong EMCAL RCU number = %d\n", iRCU);
765d44e7 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) {
280e6766 385 Fatal("GetModuleNumberCellIndexes()","Wrong PHOS RCU number = %d\n", iRCU);
765d44e7 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//_______________________________________________________________
404void AliCalorimeterUtils::InitParameters()
405{
406 //Initialize the parameters of the analysis.
c8fe2783 407 fEMCALGeoName = "EMCAL_FIRSTYEAR";
765d44e7 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
765d44e7 422 fNCellsFromPHOSBorder = 0;
765d44e7 423}
424
765d44e7 425
426//________________________________________________________________
427void 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);
78219bac 433
434 fPHOSBadChannelMap = new TObjArray(5);
765d44e7 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//________________________________________________________________
09e819c9 445void 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);
78219bac 451
452 fPHOSRecalibrationFactors = new TObjArray(5);
09e819c9 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//________________________________________________________________
765d44e7 471void 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//________________________________________________________________
485void 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//________________________________________________________________
499void 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",
247abff4 509 fEMCALRecoUtils->GetNumberOfCellsFromEMCALBorder(), fNCellsFromPHOSBorder);
510 if(fEMCALRecoUtils->IsEMCALNoBorderAtEta0()) printf("Do not remove EMCAL clusters at Eta = 0\n");
09e819c9 511 printf("Recalibrate Clusters? %d\n",fRecalibration);
9584c261 512 printf("Recalculate Clusters Position? %d\n",fRecalculatePosition);
513 printf("Recalculate Clusters Energy? %d\n",fCorrectELinearity);
f2ccb5b8 514 printf("Matching criteria: dR < %2.2f[cm], dZ < %2.2f[cm]\n",fCutR,fCutZ);
765d44e7 515
516 printf(" \n") ;
517}
518
519//________________________________________________________________
c8fe2783 520Float_t AliCalorimeterUtils::RecalibrateClusterEnergy(AliVCluster * cluster, AliVCaloCells * cells){
09e819c9 521 // Recalibrate the cluster energy, considering the recalibration map and the energy of the cells that compose the cluster.
09e819c9 522
898c9d44 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
09e819c9 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";
09e819c9 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)
280e6766 547 printf("AliCalorimeterUtils::RecalibrateClusterEnergy() - recalibrate cell: %s, module %d, col %d, row %d, cell fraction %f, recalibration factor %f, cell energy %f\n",
09e819c9 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)
280e6766 554 printf("AliCalorimeterUtils::RecalibrateClusterEnergy() - Energy before %f, after %f\n",cluster->E(),energy);
898c9d44 555
556 }// cells available
557 else{
558 Fatal("RecalibrateClusterEnergy()","Cells pointer does not exist!");
559 }
560
09e819c9 561 return energy;
09e819c9 562}
563
564//________________________________________________________________
765d44e7 565void AliCalorimeterUtils::SetGeometryTransformationMatrices(AliVEvent* inputEvent)
566{
567 //Set the calorimeters transformation matrices
568
569 //Get the EMCAL transformation geometry matrices from ESD
36037088 570 if (!gGeoManager && fEMCALGeo && !fEMCALGeoMatrixSet) {
765d44e7 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++){
c8fe2783 575 if(inputEvent->GetEMCALMatrix(mod)) {
765d44e7 576 //printf("EMCAL: mod %d, matrix %p\n",mod, ((AliESDEvent*)inputEvent)->GetEMCALMatrix(mod));
c8fe2783 577 fEMCALGeo->SetMisalMatrix(inputEvent->GetEMCALMatrix(mod),mod) ;
765d44e7 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++){
c8fe2783 594 if(inputEvent->GetPHOSMatrix(mod)) {
765d44e7 595 //printf("PHOS: mod %d, matrix %p\n",mod, ((AliESDEvent*)inputEvent)->GetPHOSMatrix(mod));
c8fe2783 596 fPHOSGeo->SetMisalMatrix(inputEvent->GetPHOSMatrix(mod),mod) ;
765d44e7 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
9584c261 609//________________________________________________________________
610void AliCalorimeterUtils::RecalculateClusterPosition(AliVCaloCells* cells, AliVCluster* clu){
611
612 //Recalculate EMCAL cluster position
613
19db8f8c 614 fEMCALRecoUtils->RecalculateClusterPosition((AliEMCALGeometry*)fEMCALGeo, cells,clu);
615
9584c261 616}