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