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