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