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