Moving CounterCollection class to PWG3/base (Gines)
[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
39
40ClassImp(AliCalorimeterUtils)
41
42
43//____________________________________________________________________________
44 AliCalorimeterUtils::AliCalorimeterUtils() :
45 TObject(), fDebug(0),
c8fe2783 46 fEMCALGeoName("EMCAL_FIRSTYEAR"),fPHOSGeoName("PHOSgeo"),
765d44e7 47 fEMCALGeo(0x0), fPHOSGeo(0x0),
48 fEMCALGeoMatrixSet(kFALSE), fPHOSGeoMatrixSet(kFALSE),
49 fRemoveBadChannels(kFALSE),
78219bac 50 fEMCALBadChannelMap(0x0),fPHOSBadChannelMap(0x0),
765d44e7 51 fNCellsFromEMCALBorder(0), fNCellsFromPHOSBorder(0),
09e819c9 52 fNoEMCALBorderAtEta0(kFALSE),fRecalibration(kFALSE),
78219bac 53 fEMCALRecalibrationFactors(), fPHOSRecalibrationFactors()
765d44e7 54{
55 //Ctor
56
57 //Initialize parameters
58 InitParameters();
59}
78219bac 60/*
765d44e7 61//____________________________________________________________________________
62AliCalorimeterUtils::AliCalorimeterUtils(const AliCalorimeterUtils & calo) :
63 TObject(calo), fDebug(calo.fDebug),
64 fEMCALGeoName(calo.fEMCALGeoName), fPHOSGeoName(calo.fPHOSGeoName),
65 fEMCALGeo(new AliEMCALGeoUtils(*calo.fEMCALGeo)),
66 fPHOSGeo(new AliPHOSGeoUtils(*calo.fPHOSGeo)),
67 fEMCALGeoMatrixSet(calo.fEMCALGeoMatrixSet),
68 fPHOSGeoMatrixSet(calo.fPHOSGeoMatrixSet),
69 fRemoveBadChannels(calo.fRemoveBadChannels),
70 fEMCALBadChannelMap(new TObjArray(*calo.fEMCALBadChannelMap)),
71 fPHOSBadChannelMap(new TObjArray(*calo.fPHOSBadChannelMap)),
72 fNCellsFromEMCALBorder(calo.fNCellsFromEMCALBorder),
73 fNCellsFromPHOSBorder(calo.fNCellsFromPHOSBorder),
09e819c9 74 fNoEMCALBorderAtEta0(calo.fNoEMCALBorderAtEta0),
75 fRecalibration(calo.fRecalibration),
76 fEMCALRecalibrationFactors(new TObjArray(*calo.fEMCALRecalibrationFactors)),
77 fPHOSRecalibrationFactors(new TObjArray(*calo.fEMCALRecalibrationFactors))
765d44e7 78{
79 // cpy ctor
80}
78219bac 81*/
765d44e7 82
83//_________________________________
84AliCalorimeterUtils::~AliCalorimeterUtils() {
85 //Dtor
86
4df35693 87 //if(fPHOSGeo) delete fPHOSGeo ;
765d44e7 88 if(fEMCALGeo) delete fEMCALGeo ;
89
90 if(fEMCALBadChannelMap) {
91 fEMCALBadChannelMap->Clear();
92 delete fEMCALBadChannelMap;
93 }
94 if(fPHOSBadChannelMap) {
95 fPHOSBadChannelMap->Clear();
96 delete fPHOSBadChannelMap;
97 }
98
09e819c9 99 if(fEMCALRecalibrationFactors) {
78219bac 100 fEMCALRecalibrationFactors->Clear();
101 delete fEMCALRecalibrationFactors;
09e819c9 102 }
103 if(fPHOSRecalibrationFactors) {
78219bac 104 fPHOSRecalibrationFactors->Clear();
105 delete fPHOSRecalibrationFactors;
09e819c9 106 }
107
765d44e7 108}
109
110//_______________________________________________________________
c8fe2783 111Bool_t AliCalorimeterUtils::CheckCellFiducialRegion(AliVCluster* cluster, AliVCaloCells* cells, AliVEvent * event, Int_t iev) const {
112
765d44e7 113 // Given the list of AbsId of the cluster, get the maximum cell and
114 // check if there are fNCellsFromBorder from the calorimeter border
115
c8fe2783 116 //If the distance to the border is 0 or negative just exit accept all clusters
117 if(cells->GetType()==AliVCaloCells::kEMCALCell && fNCellsFromEMCALBorder <= 0 ) return kTRUE;
118 if(cells->GetType()==AliVCaloCells::kPHOSCell && fNCellsFromPHOSBorder <= 0 ) return kTRUE;
765d44e7 119
c8fe2783 120 Int_t absIdMax = -1;
765d44e7 121 Float_t ampMax = -1;
c8fe2783 122
123 AliMixedEvent * mixEvent = dynamic_cast<AliMixedEvent*> (event);
124 Int_t nMixedEvents = 0 ;
125 Int_t * cellsCumul = NULL ;
126 Int_t numberOfCells = 0 ;
127 if (mixEvent){
128 nMixedEvents = mixEvent->GetNumberOfEvents() ;
129 if (cells->GetType()==AliVCaloCells::kEMCALCell) {
130 cellsCumul = mixEvent->GetEMCALCellsCumul() ;
131 numberOfCells = mixEvent->GetNumberOfEMCALCells() ;
132 }
133
134 else if (cells->GetType()==AliVCaloCells::kPHOSCell) {
135 cellsCumul = mixEvent->GetPHOSCellsCumul() ;
136 numberOfCells = mixEvent->GetNumberOfPHOSCells() ;
137 }
138 Int_t startCell = cellsCumul[iev] ;
139 Int_t endCell = (iev+1 < nMixedEvents)?cellsCumul[iev+1]:numberOfCells;
140 //Find cells with maximum amplitude
141 for(Int_t i = 0; i < cluster->GetNCells() ; i++){
142 Int_t absId = cluster->GetCellAbsId(i) ;
143 for (Int_t j = startCell; j < endCell ; j++) {
144 Short_t cellNumber;
145 Double_t amp ;
146 Double_t time;
147 cells->GetCell(j, cellNumber, amp, time) ;
148 if (absId == cellNumber) {
149 if(amp > ampMax){
150 ampMax = amp;
151 absIdMax = absId;
152 }
153 }
154 }
155 }
156 } else {
157 for(Int_t i = 0; i < cluster->GetNCells() ; i++){
158 Int_t absId = cluster->GetCellAbsId(i) ;
159 Float_t amp = cells->GetCellAmplitude(absId);
160 if(amp > ampMax){
161 ampMax = amp;
162 absIdMax = absId;
163 }
164 }
165 }
765d44e7 166
167 if(fDebug > 1)
168 printf("AliCalorimeterUtils::CheckCellFiducialRegion(AOD) - Cluster Max AbsId %d, Cell Energy %2.2f, Cluster Energy %2.2f\n",
169 absIdMax, ampMax, cluster->E());
170
171 if(absIdMax==-1) return kFALSE;
172
173 //Check if the cell is close to the borders:
174 Bool_t okrow = kFALSE;
175 Bool_t okcol = kFALSE;
176
c8fe2783 177 if(cells->GetType()==AliVCaloCells::kEMCALCell){
765d44e7 178
179 Int_t iTower = -1, iIphi = -1, iIeta = -1, iphi = -1, ieta = -1, iSM = -1;
180 fEMCALGeo->GetCellIndex(absIdMax,iSM,iTower,iIphi,iIeta);
181 fEMCALGeo->GetCellPhiEtaIndexInSModule(iSM,iTower,iIphi, iIeta,iphi,ieta);
182
183 //Check rows/phi
184 if(iSM < 10){
185 if(iphi >= fNCellsFromEMCALBorder && iphi < 24-fNCellsFromEMCALBorder) okrow =kTRUE;
186 }
187 else{
188 if(iphi >= fNCellsFromEMCALBorder && iphi < 12-fNCellsFromEMCALBorder) okrow =kTRUE;
189 }
190
191 //Check collumns/eta
192 if(!fNoEMCALBorderAtEta0){
193 if(ieta > fNCellsFromEMCALBorder && ieta < 48-fNCellsFromEMCALBorder) okcol =kTRUE;
194 }
195 else{
196 if(iSM%2==0){
197 if(ieta >= fNCellsFromEMCALBorder) okcol = kTRUE;
198 }
199 else {
200 if(ieta < 48-fNCellsFromEMCALBorder) okcol = kTRUE;
201 }
202 }//eta 0 not checked
203 if(fDebug > 1)
204 {
205 printf("AliCalorimeterUtils::CheckCellFiducialRegion(AOD) - EMCAL Cluster in %d cells fiducial volume: ieta %d, iphi %d, SM %d ?",
206 fNCellsFromEMCALBorder, ieta, iphi, iSM);
207 if (okcol && okrow ) printf(" YES \n");
208 else printf(" NO: column ok? %d, row ok? %d \n",okcol,okrow);
209 }
210 }//EMCAL
c8fe2783 211 else if(cells->GetType()==AliVCaloCells::kPHOSCell){
765d44e7 212 Int_t relId[4];
213 Int_t irow = -1, icol = -1;
214 fPHOSGeo->AbsToRelNumbering(absIdMax,relId);
215 irow = relId[2];
216 icol = relId[3];
217 //imod = relId[0]-1;
218 if(irow >= fNCellsFromPHOSBorder && irow < 64-fNCellsFromPHOSBorder) okrow =kTRUE;
219 if(icol >= fNCellsFromPHOSBorder && icol < 56-fNCellsFromPHOSBorder) okcol =kTRUE;
220 if(fDebug > 1)
221 {
222 printf("AliCalorimeterUtils::CheckCellFiducialRegion(AOD) - PHOS Cluster in %d cells fiducial volume: icol %d, irow %d, Module %d?",
223 fNCellsFromPHOSBorder, icol, irow, relId[0]-1);
224 if (okcol && okrow ) printf(" YES \n");
225 else printf(" NO: column ok? %d, row ok? %d \n",okcol,okrow);
226 }
227 }//PHOS
228
229 if (okcol && okrow) return kTRUE;
230 else return kFALSE;
231
232}
233
234//_______________________________________________________________
c8fe2783 235//Bool_t AliCalorimeterUtils::CheckCellFiducialRegion(AliESDCaloCluster* cluster, AliESDCaloCells* cells) const {
236// // Given the list of AbsId of the cluster, get the maximum cell and
237// // check if there are fNCellsFromBorder from the calorimeter border
238//
239// //If the distance to the border is 0 or negative just exit accept all clusters
240// if(cells->GetType()==AliVCaloCells::kEMCALCell && fNCellsFromEMCALBorder <= 0 ) return kTRUE;
241// if(cells->GetType()==AliVCaloCells::kPHOSCell && fNCellsFromPHOSBorder <= 0 ) return kTRUE;
242//
243// //Find cell with maximum amplitude
244// Int_t absIdMax = -1;
245// Float_t ampMax = -1;
246// for(Int_t i = 0; i < cluster->GetNCells() ; i++){
247// Int_t absId = cluster->GetCellAbsId(i) ;
248// Float_t amp = cells->GetCellAmplitude(absId);
249// if(amp > ampMax){
250// ampMax = amp;
251// absIdMax = absId;
252// }
253// }
254//
255// if(fDebug > 1)
256// printf("AliCalorimeterUtils::CheckCellFiducialRegion(ESD) - Cluster Max AbsId %d, Cell Energy %2.2f, Cluster Energy %2.2f\n",
257// absIdMax, ampMax, cluster->E());
258// if(absIdMax==-1) return kFALSE;
259//
260// //Check if the cell is close to the borders:
261// Bool_t okrow = kFALSE;
262// Bool_t okcol = kFALSE;
263//
264// if(cells->GetType()==AliESDCaloCells::kEMCALCell){
265//
266// Int_t iTower = -1, iIphi = -1, iIeta = -1, iphi = -1, ieta = -1, iSM = -1;
267// fEMCALGeo->GetCellIndex(absIdMax,iSM,iTower,iIphi,iIeta);
268// fEMCALGeo->GetCellPhiEtaIndexInSModule(iSM,iTower,iIphi, iIeta,iphi,ieta);
269//
270// //Check rows/phi
271// if(iSM < 10){
272// if(iphi >= fNCellsFromEMCALBorder && iphi < 24-fNCellsFromEMCALBorder) okrow =kTRUE;
273// }
274// else{
275// if(iphi >= fNCellsFromEMCALBorder && iphi < 12-fNCellsFromEMCALBorder) okrow =kTRUE;
276// }
277//
278// //Check collumns/eta
279// if(!fNoEMCALBorderAtEta0){
280// if(ieta > fNCellsFromEMCALBorder && ieta < 48-fNCellsFromEMCALBorder) okcol =kTRUE;
281// }
282// else{
283// if(iSM%2==0){
284// if(ieta >= fNCellsFromEMCALBorder) okcol = kTRUE;
285// }
286// else {
287// if(ieta < 48-fNCellsFromEMCALBorder) okcol = kTRUE;
288// }
289// }//eta 0 not checked
290// if(fDebug > 1)
291// {
292// printf("AliCalorimeterUtils::CheckCellFiducialRegion(ESD) - EMCAL Cluster in %d cells fiducial volume: ieta %d, iphi %d, SM %d ?",
293// fNCellsFromEMCALBorder, ieta, iphi, iSM);
294// if (okcol && okrow ) printf(" YES \n");
295// else printf(" NO: column ok? %d, row ok? %d \n",okcol,okrow);
296// }
297// }//EMCAL
298// else if(cells->GetType()==AliVCaloCells::kPHOSCell){
299// Int_t relId[4];
300// Int_t irow = -1, icol = -1;
301// fPHOSGeo->AbsToRelNumbering(absIdMax,relId);
302// irow = relId[2];
303// icol = relId[3];
304// //imod = relId[0]-1;
305// if(irow >= fNCellsFromPHOSBorder && irow < 64-fNCellsFromPHOSBorder) okrow =kTRUE;
306// if(icol >= fNCellsFromPHOSBorder && icol < 56-fNCellsFromPHOSBorder) okcol =kTRUE;
307// if(fDebug > 1)
308// {
309// printf("AliCalorimeterUtils::CheckCellFiducialRegion(ESD) - PHOS Cluster in %d cells fiducial volume: icol %d, irow %d, Module %d ?",
310// fNCellsFromPHOSBorder, icol, irow,relId[0]-1);
311// if (okcol && okrow ) printf(" YES \n");
312// else printf(" NO: column ok? %d, row ok? %d \n",okcol,okrow);
313// }
314// }//PHOS
315//
316// if (okcol && okrow) return kTRUE;
317// else return kFALSE;
318//
319//}
320//
765d44e7 321
322//_________________________________________________________________________________________________________
323Bool_t AliCalorimeterUtils::ClusterContainsBadChannel(TString calorimeter,UShort_t* cellList, Int_t nCells){
324 // Check that in the cluster cells, there is no bad channel of those stored
325 // in fEMCALBadChannelMap or fPHOSBadChannelMap
326
327 if (!fRemoveBadChannels) return kFALSE;
36037088 328 //printf("fEMCALBadChannelMap %p, fPHOSBadChannelMap %p \n",fEMCALBadChannelMap,fPHOSBadChannelMap);
78219bac 329 if(calorimeter == "EMCAL" && !fEMCALBadChannelMap) return kFALSE;
330 if(calorimeter == "PHOS" && !fPHOSBadChannelMap) return kFALSE;
765d44e7 331
332 Int_t icol = -1;
333 Int_t irow = -1;
334 Int_t imod = -1;
335 for(Int_t iCell = 0; iCell<nCells; iCell++){
336
337 //Get the column and row
338 if(calorimeter == "EMCAL"){
339 Int_t iTower = -1, iIphi = -1, iIeta = -1;
340 fEMCALGeo->GetCellIndex(cellList[iCell],imod,iTower,iIphi,iIeta);
341 if(fEMCALBadChannelMap->GetEntries() <= imod) continue;
342 fEMCALGeo->GetCellPhiEtaIndexInSModule(imod,iTower,iIphi, iIeta,irow,icol);
343 if(GetEMCALChannelStatus(imod, icol, irow))return kTRUE;
344 }
345 else if(calorimeter=="PHOS"){
346 Int_t relId[4];
347 fPHOSGeo->AbsToRelNumbering(cellList[iCell],relId);
348 irow = relId[2];
349 icol = relId[3];
350 imod = relId[0]-1;
351 if(fPHOSBadChannelMap->GetEntries() <= imod)continue;
352 if(GetPHOSChannelStatus(imod, icol, irow)) return kTRUE;
353 }
354 else return kFALSE;
355
356 }// cell cluster loop
357
358 return kFALSE;
359
360}
361
362//____________________________________________________________________________________________________________________________________________________
363Int_t AliCalorimeterUtils::GetModuleNumber(AliAODPWG4Particle * particle, AliVEvent * inputEvent) const
364{
365 //Get the EMCAL/PHOS module number that corresponds to this particle
366
367 Int_t absId = -1;
368 if(particle->GetDetector()=="EMCAL"){
369 fEMCALGeo->GetAbsCellIdFromEtaPhi(particle->Eta(),particle->Phi(), absId);
370 if(fDebug > 2)
371 printf("AliCalorimeterUtils::GetModuleNumber(PWG4AOD) - EMCAL: cluster eta %f, phi %f, absid %d, SuperModule %d\n",
372 particle->Eta(), particle->Phi()*TMath::RadToDeg(),absId, fEMCALGeo->GetSuperModuleNumber(absId));
373 return fEMCALGeo->GetSuperModuleNumber(absId) ;
374 }//EMCAL
375 else if(particle->GetDetector()=="PHOS"){
46a3cde6 376 // In case we use the MC reader, the input are TParticles,
377 // in this case use the corresponing method in PHOS Geometry to get the particle.
378 if(strcmp(inputEvent->ClassName(), "AliMCEvent") == 0 )
379 {
380 Int_t mod =-1;
381 Double_t z = 0., x=0.;
382 TParticle* primary = 0x0;
383 AliStack * stack = ((AliMCEvent*)inputEvent)->Stack();
384 if(stack) {
385 primary = stack->Particle(particle->GetCaloLabel(0));
386 }
387 else {
388 printf("AliCalorimeterUtils::GetModuleNumber(AOD) - Stack not available, stop!");
389 abort();
390 }
391
392 fPHOSGeo->ImpactOnEmc(primary,mod,z,x) ;
393 return mod;
394 }
395 // Input are ESDs or AODs, get the PHOS module number like this.
396 else{
397 AliVCluster *cluster = inputEvent->GetCaloCluster(particle->GetCaloLabel(0));
398 return GetModuleNumber(cluster);
399 }
765d44e7 400 }//PHOS
401
402 return -1;
403}
404
405//____________________________________________________________________________________________________________________________________________________
c8fe2783 406Int_t AliCalorimeterUtils::GetModuleNumber(AliVCluster * cluster) const
765d44e7 407{
408 //Get the EMCAL/PHOS module number that corresponds to this cluster, input are AODs
409 TLorentzVector lv;
410 Double_t v[]={0.,0.,0.}; //not necessary to pass the real vertex.
411 cluster->GetMomentum(lv,v);
412 Float_t phi = lv.Phi();
413 if(phi < 0) phi+=TMath::TwoPi();
414 Int_t absId = -1;
c8fe2783 415 if(cluster->IsEMCAL()){
765d44e7 416 fEMCALGeo->GetAbsCellIdFromEtaPhi(lv.Eta(),phi, absId);
417 if(fDebug > 2)
418 printf("AliCalorimeterUtils::GetModuleNumber(ESD) - EMCAL: cluster eta %f, phi %f, absid %d, SuperModule %d\n",
419 lv.Eta(), phi*TMath::RadToDeg(),absId, fEMCALGeo->GetSuperModuleNumber(absId));
420 return fEMCALGeo->GetSuperModuleNumber(absId) ;
421 }//EMCAL
c8fe2783 422 else if(cluster->IsPHOS()) {
765d44e7 423 Int_t relId[4];
424 if ( cluster->GetNCells() > 0) {
425 absId = cluster->GetCellAbsId(0);
426 if(fDebug > 2)
427 printf("AliCalorimeterUtils::GetModuleNumber(AOD) - PHOS: cluster eta %f, phi %f, e %f, absId %d\n",
428 lv.Eta(), phi*TMath::RadToDeg(), lv.E(), absId);
429 }
430 else return -1;
431
432 if ( absId >= 0) {
433 fPHOSGeo->AbsToRelNumbering(absId,relId);
434 if(fDebug > 2)
435 printf("AliCalorimeterUtils::GetModuleNumber(AOD) - PHOS: Module %d\n",relId[0]-1);
436 return relId[0]-1;
437 }
438 else return -1;
439 }//PHOS
440
441 return -1;
442}
443
765d44e7 444//_____________________________________________________________________________________________________________
445Int_t AliCalorimeterUtils::GetModuleNumberCellIndexes(const Int_t absId, const TString calo, Int_t & icol, Int_t & irow, Int_t & iRCU) const
446{
447 //Get the EMCAL/PHOS module, columns, row and RCU number that corresponds to this absId
448 Int_t imod = -1;
449 if ( absId >= 0) {
450 if(calo=="EMCAL"){
451 Int_t iTower = -1, iIphi = -1, iIeta = -1;
452 fEMCALGeo->GetCellIndex(absId,imod,iTower,iIphi,iIeta);
453 fEMCALGeo->GetCellPhiEtaIndexInSModule(imod,iTower,iIphi, iIeta,irow,icol);
454
455 //RCU0
456 if (0<=irow&&irow<8) iRCU=0; // first cable row
457 else if (8<=irow&&irow<16 && 0<=icol&&icol<24) iRCU=0; // first half;
458 //second cable row
459 //RCU1
460 else if(8<=irow&&irow<16 && 24<=icol&&icol<48) iRCU=1; // second half;
461 //second cable row
462 else if(16<=irow&&irow<24) iRCU=1; // third cable row
463
464 if (imod%2==1) iRCU = 1 - iRCU; // swap for odd=C side, to allow us to cable both sides the same
465 if (iRCU<0) {
466 printf("AliCalorimeterUtils::GetModuleNumberCellIndexes() - Wrong EMCAL RCU number = %d\n", iRCU);
467 abort();
468 }
469
470 return imod ;
471 }//EMCAL
472 else{//PHOS
473 Int_t relId[4];
474 fPHOSGeo->AbsToRelNumbering(absId,relId);
475 irow = relId[2];
476 icol = relId[3];
477 imod = relId[0]-1;
478 iRCU= (Int_t)(relId[2]-1)/16 ;
479 //Int_t iBranch= (Int_t)(relid[3]-1)/28 ; //0 to 1
480 if (iRCU >= 4) {
481 printf("AliCalorimeterUtils::GetModuleNumberCellIndexes() - Wrong PHOS RCU number = %d\n", iRCU);
482 abort();
483 }
484 return imod;
485 }//PHOS
486 }
487
488 return -1;
489}
490
491//_______________________________________________________________
492//void AliCalorimeterUtils::Init()
493//{
494// //Init reader. Method to be called in AliAnaPartCorrMaker
495//
496// fEMCALBadChannelMap->SetName(Form("EMCALBadMap_%s",fTaskName.Data()));
497// fPHOSBadChannelMap->SetName(Form("PHOSBadMap_%s",fTaskName.Data()));
498//}
499
500//_______________________________________________________________
501void AliCalorimeterUtils::InitParameters()
502{
503 //Initialize the parameters of the analysis.
c8fe2783 504 fEMCALGeoName = "EMCAL_FIRSTYEAR";
765d44e7 505 fPHOSGeoName = "PHOSgeo";
506
507 if(gGeoManager) {// geoManager was set
508 if(fDebug > 2)printf("AliCalorimeterUtils::InitParameters() - Geometry manager available\n");
509 fEMCALGeoMatrixSet = kTRUE;
510 fPHOSGeoMatrixSet = kTRUE;
511 }
512 else{
513 fEMCALGeoMatrixSet = kFALSE;
514 fPHOSGeoMatrixSet = kFALSE;
515 }
516
517 fRemoveBadChannels = kFALSE;
518
519 fNCellsFromEMCALBorder = 0;
520 fNCellsFromPHOSBorder = 0;
521 fNoEMCALBorderAtEta0 = kFALSE;
522}
523
524//________________________________________________________________
525void AliCalorimeterUtils::InitEMCALBadChannelStatusMap(){
526 //Init EMCAL bad channels map
527 if(fDebug > 0 )printf("AliCalorimeterUtils::InitEMCALBadChannelStatusMap()\n");
528 //In order to avoid rewriting the same histograms
529 Bool_t oldStatus = TH1::AddDirectoryStatus();
530 TH1::AddDirectory(kFALSE);
78219bac 531
532 fEMCALBadChannelMap = new TObjArray(12);
533 //TH2F * hTemp = new TH2I("EMCALBadChannelMap","EMCAL SuperModule bad channel map", 48, 0, 48, 24, 0, 24);
534 for (int i = 0; i < 12; i++) {
535 fEMCALBadChannelMap->Add(new TH2I(Form("EMCALBadChannelMap_Mod%d",i),Form("EMCALBadChannelMap_Mod%d",i), 48, 0, 48, 24, 0, 24));
536 //fEMCALBadChannelMap->Add((TH2I*)hTemp->Clone(Form("EMCALBadChannelMap_Mod%d",i)));
537 }
538
539 //delete hTemp;
765d44e7 540
541 fEMCALBadChannelMap->SetOwner(kTRUE);
542 fEMCALBadChannelMap->Compress();
78219bac 543
765d44e7 544 //In order to avoid rewriting the same histograms
545 TH1::AddDirectory(oldStatus);
546}
547
548//________________________________________________________________
549void AliCalorimeterUtils::InitPHOSBadChannelStatusMap(){
550 //Init PHOS bad channels map
551 if(fDebug > 0 )printf("AliCalorimeterUtils::InitPHOSBadChannelStatusMap()\n");
552 //In order to avoid rewriting the same histograms
553 Bool_t oldStatus = TH1::AddDirectoryStatus();
554 TH1::AddDirectory(kFALSE);
78219bac 555
556 fPHOSBadChannelMap = new TObjArray(5);
765d44e7 557 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));
558
559 fPHOSBadChannelMap->SetOwner(kTRUE);
560 fPHOSBadChannelMap->Compress();
561
562 //In order to avoid rewriting the same histograms
563 TH1::AddDirectory(oldStatus);
564}
565
566//________________________________________________________________
09e819c9 567void AliCalorimeterUtils::InitEMCALRecalibrationFactors(){
568 //Init EMCAL recalibration factors
569 if(fDebug > 0 )printf("AliCalorimeterUtils::InitEMCALRecalibrationFactors()\n");
570 //In order to avoid rewriting the same histograms
571 Bool_t oldStatus = TH1::AddDirectoryStatus();
572 TH1::AddDirectory(kFALSE);
78219bac 573
574 fEMCALRecalibrationFactors = new TObjArray(12);
09e819c9 575 for (int i = 0; i < 12; i++) fEMCALRecalibrationFactors->Add(new TH2F(Form("EMCALRecalFactors_SM%d",i),Form("EMCALRecalFactors_SM%d",i), 48, 0, 48, 24, 0, 24));
576 //Init the histograms with 1
577 for (Int_t sm = 0; sm < 12; sm++) {
578 for (Int_t i = 0; i < 48; i++) {
579 for (Int_t j = 0; j < 24; j++) {
580 SetEMCALChannelRecalibrationFactor(sm,i,j,1.);
581 }
582 }
583 }
584 fEMCALRecalibrationFactors->SetOwner(kTRUE);
585 fEMCALRecalibrationFactors->Compress();
586
587 //In order to avoid rewriting the same histograms
588 TH1::AddDirectory(oldStatus);
589}
590
591//________________________________________________________________
592void AliCalorimeterUtils::InitPHOSRecalibrationFactors(){
593 //Init EMCAL recalibration factors
594 if(fDebug > 0 )printf("AliCalorimeterUtils::InitPHOSRecalibrationFactors()\n");
595 //In order to avoid rewriting the same histograms
596 Bool_t oldStatus = TH1::AddDirectoryStatus();
597 TH1::AddDirectory(kFALSE);
78219bac 598
599 fPHOSRecalibrationFactors = new TObjArray(5);
09e819c9 600 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));
601 //Init the histograms with 1
602 for (Int_t m = 0; m < 5; m++) {
603 for (Int_t i = 0; i < 56; i++) {
604 for (Int_t j = 0; j < 64; j++) {
605 SetPHOSChannelRecalibrationFactor(m,i,j,1.);
606 }
607 }
608 }
609 fPHOSRecalibrationFactors->SetOwner(kTRUE);
610 fPHOSRecalibrationFactors->Compress();
611
612 //In order to avoid rewriting the same histograms
613 TH1::AddDirectory(oldStatus);
614}
615
616
617//________________________________________________________________
765d44e7 618void AliCalorimeterUtils::InitEMCALGeometry()
619{
620 //Initialize EMCAL geometry if it did not exist previously
621 if (!fEMCALGeo){
622 fEMCALGeo = new AliEMCALGeoUtils(fEMCALGeoName);
623 if(fDebug > 0){
624 printf("AliCalorimeterUtils::InitEMCALGeometry()");
625 if (!gGeoManager) printf(" - Careful!, gGeoManager not loaded, load misalign matrices");
626 printf("\n");
627 }
628 }
629}
630
631//________________________________________________________________
632void AliCalorimeterUtils::InitPHOSGeometry()
633{
634 //Initialize PHOS geometry if it did not exist previously
635 if (!fPHOSGeo){
636 fPHOSGeo = new AliPHOSGeoUtils(fPHOSGeoName);
637 if(fDebug > 0){
638 printf("AliCalorimeterUtils::InitPHOSGeometry()");
639 if (!gGeoManager) printf(" - Careful!, gGeoManager not loaded, load misalign matrices");
640 printf("\n");
641 }
642 }
643}
644
645//________________________________________________________________
646void AliCalorimeterUtils::Print(const Option_t * opt) const
647{
648
649 //Print some relevant parameters set for the analysis
650 if(! opt)
651 return;
652
653 printf("***** Print: %s %s ******\n", GetName(), GetTitle() ) ;
654 printf("Remove Clusters with bad channels? %d\n",fRemoveBadChannels);
655 printf("Remove Clusters with max cell at less than %d cells from EMCAL border and %d cells from PHOS border\n",
656 fNCellsFromEMCALBorder, fNCellsFromPHOSBorder);
657 if(fNoEMCALBorderAtEta0) printf("Do not remove EMCAL clusters at Eta = 0\n");
09e819c9 658 printf("Recalibrate Clusters? %d\n",fRecalibration);
765d44e7 659
660 printf(" \n") ;
661}
662
663//________________________________________________________________
c8fe2783 664Float_t AliCalorimeterUtils::RecalibrateClusterEnergy(AliVCluster * cluster, AliVCaloCells * cells){
09e819c9 665 // Recalibrate the cluster energy, considering the recalibration map and the energy of the cells that compose the cluster.
666 // ESD case
667
668 if(!cells) {
669 printf("AliCalorimeterUtils::RecalibrateClusterEnergy(ESD) - Cells pointer does not exist, stop!");
670 abort();
671 }
672 //Get the cluster number of cells and list of absId, check what kind of cluster do we have.
673 UShort_t * index = cluster->GetCellsAbsId() ;
674 Double_t * fraction = cluster->GetCellsAmplitudeFraction() ;
675 Int_t ncells = cluster->GetNCells();
676 TString calo = "EMCAL";
677 if(cluster->IsPHOS()) calo = "PHOS";
678 //Initialize some used variables
679 Float_t energy = 0;
680 Int_t absId = -1;
681 Int_t icol = -1, irow = -1, iRCU = -1, module=1;
682 Float_t factor = 1, frac = 0;
683
684 //Loop on the cells, get the cell amplitude and recalibration factor, multiply and and to the new energy
685 for(Int_t icell = 0; icell < ncells; icell++){
686 absId = index[icell];
687 frac = fraction[icell];
688 if(frac < 1e-3) frac = 1; //in case of EMCAL, this is set as 0, not used.
689 module = GetModuleNumberCellIndexes(absId,calo,icol,irow,iRCU);
690 if(cluster->IsPHOS()) factor = GetPHOSChannelRecalibrationFactor (module,icol,irow);
691 else factor = GetEMCALChannelRecalibrationFactor(module,icol,irow);
692 if(fDebug>2)
693 printf("AliCalorimeterUtils::RecalibrateClusterEnergy(ESD) - recalibrate cell: %s, module %d, col %d, row %d, cell fraction %f, recalibration factor %f, cell energy %f\n",
694 calo.Data(),module,icol,irow,frac,factor,cells->GetCellAmplitude(absId));
695
696 energy += cells->GetCellAmplitude(absId)*factor*frac;
697 }
698
699 if(fDebug>1)
700 printf("AliCalorimeterUtils::RecalibrateClusterEnergy(ESD) - Energy before %f, after %f\n",cluster->E(),energy);
701
702 return energy;
09e819c9 703}
704
705//________________________________________________________________
765d44e7 706void AliCalorimeterUtils::SetGeometryTransformationMatrices(AliVEvent* inputEvent)
707{
708 //Set the calorimeters transformation matrices
709
710 //Get the EMCAL transformation geometry matrices from ESD
36037088 711 if (!gGeoManager && fEMCALGeo && !fEMCALGeoMatrixSet) {
765d44e7 712 if(fDebug > 1)
713 printf(" AliCalorimeterUtils::SetGeometryTransformationMatrices() - Load EMCAL misalignment matrices. \n");
714 if(!strcmp(inputEvent->GetName(),"AliESDEvent")) {
715 for(Int_t mod=0; mod < (fEMCALGeo->GetEMCGeometry())->GetNumberOfSuperModules(); mod++){
c8fe2783 716 if(inputEvent->GetEMCALMatrix(mod)) {
765d44e7 717 //printf("EMCAL: mod %d, matrix %p\n",mod, ((AliESDEvent*)inputEvent)->GetEMCALMatrix(mod));
c8fe2783 718 fEMCALGeo->SetMisalMatrix(inputEvent->GetEMCALMatrix(mod),mod) ;
765d44e7 719 fEMCALGeoMatrixSet = kTRUE;//At least one, so good
720 }
721 }// loop over super modules
722 }//ESD as input
723 else {
724 if(fDebug > 1)
725 printf("AliCalorimeterUtils::SetGeometryTransformationMatrices() - Setting of EMCAL transformation matrixes for AODs not implemented yet. \n Import geometry.root file\n");
726 }//AOD as input
727 }//EMCAL geo && no geoManager
728
729 //Get the PHOS transformation geometry matrices from ESD
730 if (!gGeoManager && fPHOSGeo && !fPHOSGeoMatrixSet) {
731 if(fDebug > 1)
732 printf(" AliCalorimeterUtils::SetGeometryTransformationMatrices() - Load PHOS misalignment matrices. \n");
733 if(!strcmp(inputEvent->GetName(),"AliESDEvent")) {
734 for(Int_t mod=0; mod < 5; mod++){
c8fe2783 735 if(inputEvent->GetPHOSMatrix(mod)) {
765d44e7 736 //printf("PHOS: mod %d, matrix %p\n",mod, ((AliESDEvent*)inputEvent)->GetPHOSMatrix(mod));
c8fe2783 737 fPHOSGeo->SetMisalMatrix(inputEvent->GetPHOSMatrix(mod),mod) ;
765d44e7 738 fPHOSGeoMatrixSet = kTRUE; //At least one so good
739 }
740 }// loop over modules
741 }//ESD as input
742 else {
743 if(fDebug > 1)
744 printf("AliCalorimeterUtils::SetGeometryTransformationMatrices() - Setting of EMCAL transformation matrixes for AODs not implemented yet. \n Import geometry.root file\n");
745 }//AOD as input
746 }//PHOS geo and geoManager was not set
747
748}
749