1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
17 //_________________________________________________________________________
18 // Class utility for Calorimeter specific selection methods ///
22 //-- Author: Gustavo Conesa (LPSC-Grenoble)
23 //////////////////////////////////////////////////////////////////////////////
26 // --- ROOT system ---
27 #include "TGeoManager.h"
29 //---- ANALYSIS system ----
30 #include "AliCalorimeterUtils.h"
31 #include "AliVEvent.h"
32 #include "AliMCEvent.h"
34 #include "AliAODPWG4Particle.h"
35 #include "AliVCluster.h"
36 #include "AliVCaloCells.h"
37 #include "AliMixedEvent.h"
39 ClassImp(AliCalorimeterUtils)
42 //____________________________________________________________________________
43 AliCalorimeterUtils::AliCalorimeterUtils() :
45 fEMCALGeoName("EMCAL_FIRSTYEAR"),fPHOSGeoName("PHOSgeo"),
46 fEMCALGeo(0x0), fPHOSGeo(0x0),
47 fEMCALGeoMatrixSet(kFALSE), fPHOSGeoMatrixSet(kFALSE),
48 fRemoveBadChannels(kFALSE),fPHOSBadChannelMap(0x0),
49 fNCellsFromPHOSBorder(0), fRecalibration(kFALSE),
50 fPHOSRecalibrationFactors(),
51 fEMCALRecoUtils(new AliEMCALRecoUtils),
52 fRecalculatePosition(kFALSE),fCorrectELinearity(kFALSE),
53 fRecalculateMatching(kFALSE),fCutR(20), fCutZ(20)
57 //Initialize parameters
61 //_________________________________
62 AliCalorimeterUtils::~AliCalorimeterUtils() {
65 //if(fPHOSGeo) delete fPHOSGeo ;
66 if(fEMCALGeo) delete fEMCALGeo ;
68 if(fPHOSBadChannelMap) {
69 fPHOSBadChannelMap->Clear();
70 delete fPHOSBadChannelMap;
73 if(fPHOSRecalibrationFactors) {
74 fPHOSRecalibrationFactors->Clear();
75 delete fPHOSRecalibrationFactors;
78 if(fEMCALRecoUtils) delete fEMCALRecoUtils ;
82 //_______________________________________________________________
83 Bool_t AliCalorimeterUtils::CheckCellFiducialRegion(AliVCluster* cluster, AliVCaloCells* cells, AliVEvent * event, Int_t iev) const {
85 // Given the list of AbsId of the cluster, get the maximum cell and
86 // check if there are fNCellsFromBorder from the calorimeter border
88 //If the distance to the border is 0 or negative just exit accept all clusters
89 if(cells->GetType()==AliVCaloCells::kEMCALCell && fEMCALRecoUtils->GetNumberOfCellsFromEMCALBorder() <= 0 ) return kTRUE;
90 if(cells->GetType()==AliVCaloCells::kPHOSCell && fNCellsFromPHOSBorder <= 0 ) return kTRUE;
95 AliMixedEvent * mixEvent = dynamic_cast<AliMixedEvent*> (event);
96 Int_t nMixedEvents = 0 ;
97 Int_t * cellsCumul = NULL ;
98 Int_t numberOfCells = 0 ;
100 nMixedEvents = mixEvent->GetNumberOfEvents() ;
101 if (cells->GetType()==AliVCaloCells::kEMCALCell) {
102 cellsCumul = mixEvent->GetEMCALCellsCumul() ;
103 numberOfCells = mixEvent->GetNumberOfEMCALCells() ;
106 else if (cells->GetType()==AliVCaloCells::kPHOSCell) {
107 cellsCumul = mixEvent->GetPHOSCellsCumul() ;
108 numberOfCells = mixEvent->GetNumberOfPHOSCells() ;
113 Int_t startCell = cellsCumul[iev] ;
114 Int_t endCell = (iev+1 < nMixedEvents)?cellsCumul[iev+1]:numberOfCells;
115 //Find cells with maximum amplitude
116 for(Int_t i = 0; i < cluster->GetNCells() ; i++){
117 Int_t absId = cluster->GetCellAbsId(i) ;
118 for (Int_t j = startCell; j < endCell ; j++) {
122 cells->GetCell(j, cellNumber, amp, time) ;
123 if (absId == cellNumber) {
130 }//loop on cluster cells
131 }// cells cumul available
133 printf("AliCalorimeterUtils::CheckCellFiducialRegion() - CellsCumul is NULL!!!\n");
136 } else {//Normal SE Events
137 for(Int_t i = 0; i < cluster->GetNCells() ; i++){
138 Int_t absId = cluster->GetCellAbsId(i) ;
139 Float_t amp = cells->GetCellAmplitude(absId);
148 printf("AliCalorimeterUtils::CheckCellFiducialRegion() - Cluster Max AbsId %d, Cell Energy %2.2f, Cluster Energy %2.2f\n",
149 absIdMax, ampMax, cluster->E());
151 if(absIdMax==-1) return kFALSE;
153 //Check if the cell is close to the borders:
154 Bool_t okrow = kFALSE;
155 Bool_t okcol = kFALSE;
157 if(cells->GetType()==AliVCaloCells::kEMCALCell){
159 Int_t iTower = -1, iIphi = -1, iIeta = -1, iphi = -1, ieta = -1, iSM = -1;
160 fEMCALGeo->GetCellIndex(absIdMax,iSM,iTower,iIphi,iIeta);
161 fEMCALGeo->GetCellPhiEtaIndexInSModule(iSM,iTower,iIphi, iIeta,iphi,ieta);
162 if(iSM < 0 || iphi < 0 || ieta < 0 ) {
163 Fatal("CheckCellFidutialRegion","Negative value for super module: %d, or cell ieta: %d, or cell iphi: %d, check EMCAL geometry name\n",iSM,ieta,iphi);
167 Int_t nborder = fEMCALRecoUtils->GetNumberOfCellsFromEMCALBorder();
169 if(iphi >= nborder && iphi < 24-nborder) okrow =kTRUE;
172 if(iphi >= nborder && iphi < 12-nborder) okrow =kTRUE;
176 if(!fEMCALRecoUtils->IsEMCALNoBorderAtEta0()){
177 if(ieta > nborder && ieta < 48-nborder) okcol =kTRUE;
181 if(ieta >= nborder) okcol = kTRUE;
184 if(ieta < 48-nborder) okcol = kTRUE;
189 printf("AliCalorimeterUtils::CheckCellFiducialRegion() - EMCAL Cluster in %d cells fiducial volume: ieta %d, iphi %d, SM %d ?",
190 nborder, ieta, iphi, iSM);
191 if (okcol && okrow ) printf(" YES \n");
192 else printf(" NO: column ok? %d, row ok? %d \n",okcol,okrow);
195 else if(cells->GetType()==AliVCaloCells::kPHOSCell){
197 Int_t irow = -1, icol = -1;
198 fPHOSGeo->AbsToRelNumbering(absIdMax,relId);
202 if(irow >= fNCellsFromPHOSBorder && irow < 64-fNCellsFromPHOSBorder) okrow =kTRUE;
203 if(icol >= fNCellsFromPHOSBorder && icol < 56-fNCellsFromPHOSBorder) okcol =kTRUE;
206 printf("AliCalorimeterUtils::CheckCellFiducialRegion() - PHOS Cluster in %d cells fiducial volume: icol %d, irow %d, Module %d?",
207 fNCellsFromPHOSBorder, icol, irow, relId[0]-1);
208 if (okcol && okrow ) printf(" YES \n");
209 else printf(" NO: column ok? %d, row ok? %d \n",okcol,okrow);
213 if (okcol && okrow) return kTRUE;
218 //_________________________________________________________________________________________________________
219 Bool_t AliCalorimeterUtils::ClusterContainsBadChannel(TString calorimeter,UShort_t* cellList, Int_t nCells){
220 // Check that in the cluster cells, there is no bad channel of those stored
221 // in fEMCALBadChannelMap or fPHOSBadChannelMap
223 if (!fRemoveBadChannels) return kFALSE;
224 //printf("fEMCALBadChannelMap %p, fPHOSBadChannelMap %p \n",fEMCALBadChannelMap,fPHOSBadChannelMap);
225 if(calorimeter == "EMCAL" && !fEMCALRecoUtils->GetEMCALChannelStatusMap(0)) return kFALSE;
226 if(calorimeter == "PHOS" && !fPHOSBadChannelMap) return kFALSE;
231 for(Int_t iCell = 0; iCell<nCells; iCell++){
233 //Get the column and row
234 if(calorimeter == "EMCAL"){
235 return fEMCALRecoUtils->ClusterContainsBadChannel((AliEMCALGeometry*)fEMCALGeo,cellList,nCells);
237 else if(calorimeter=="PHOS"){
239 fPHOSGeo->AbsToRelNumbering(cellList[iCell],relId);
243 if(fPHOSBadChannelMap->GetEntries() <= imod)continue;
244 if(GetPHOSChannelStatus(imod, icol, irow)) return kTRUE;
248 }// cell cluster loop
254 //____________________________________________________________________________________________________________________________________________________
255 void AliCalorimeterUtils::CorrectClusterEnergy(AliVCluster *clus){
256 // Correct cluster energy non linearity
257 clus->SetE(fEMCALRecoUtils->CorrectClusterEnergyLinearity(clus));
260 //____________________________________________________________________________________________________________________________________________________
261 Int_t AliCalorimeterUtils::GetModuleNumber(AliAODPWG4Particle * particle, AliVEvent * inputEvent) const
263 //Get the EMCAL/PHOS module number that corresponds to this particle
266 if(particle->GetDetector()=="EMCAL"){
267 fEMCALGeo->GetAbsCellIdFromEtaPhi(particle->Eta(),particle->Phi(), absId);
269 printf("AliCalorimeterUtils::GetModuleNumber(PWG4AOD) - EMCAL: cluster eta %f, phi %f, absid %d, SuperModule %d\n",
270 particle->Eta(), particle->Phi()*TMath::RadToDeg(),absId, fEMCALGeo->GetSuperModuleNumber(absId));
271 return fEMCALGeo->GetSuperModuleNumber(absId) ;
273 else if(particle->GetDetector()=="PHOS"){
274 // In case we use the MC reader, the input are TParticles,
275 // in this case use the corresponing method in PHOS Geometry to get the particle.
276 if(strcmp(inputEvent->ClassName(), "AliMCEvent") == 0 )
279 Double_t z = 0., x=0.;
280 TParticle* primary = 0x0;
281 AliStack * stack = ((AliMCEvent*)inputEvent)->Stack();
283 primary = stack->Particle(particle->GetCaloLabel(0));
286 Fatal("GetModuleNumber(PWG4AOD)", "Stack not available, stop!");
290 fPHOSGeo->ImpactOnEmc(primary,mod,z,x) ;
293 Fatal("GetModuleNumber(PWG4AOD)", "Primary not available, stop!");
297 // Input are ESDs or AODs, get the PHOS module number like this.
299 AliVCluster *cluster = inputEvent->GetCaloCluster(particle->GetCaloLabel(0));
300 return GetModuleNumber(cluster);
307 //____________________________________________________________________________________________________________________________________________________
308 Int_t AliCalorimeterUtils::GetModuleNumber(AliVCluster * cluster) const
310 //Get the EMCAL/PHOS module number that corresponds to this cluster
312 Double_t v[]={0.,0.,0.}; //not necessary to pass the real vertex.
313 cluster->GetMomentum(lv,v);
314 Float_t phi = lv.Phi();
315 if(phi < 0) phi+=TMath::TwoPi();
317 if(cluster->IsEMCAL()){
318 fEMCALGeo->GetAbsCellIdFromEtaPhi(lv.Eta(),phi, absId);
320 printf("AliCalorimeterUtils::GetModuleNumber() - EMCAL: cluster eta %f, phi %f, absid %d, SuperModule %d\n",
321 lv.Eta(), phi*TMath::RadToDeg(),absId, fEMCALGeo->GetSuperModuleNumber(absId));
322 return fEMCALGeo->GetSuperModuleNumber(absId) ;
324 else if(cluster->IsPHOS()) {
326 if ( cluster->GetNCells() > 0) {
327 absId = cluster->GetCellAbsId(0);
329 printf("AliCalorimeterUtils::GetModuleNumber() - PHOS: cluster eta %f, phi %f, e %f, absId %d\n",
330 lv.Eta(), phi*TMath::RadToDeg(), lv.E(), absId);
335 fPHOSGeo->AbsToRelNumbering(absId,relId);
337 printf("AliCalorimeterUtils::GetModuleNumber() - PHOS: Module %d\n",relId[0]-1);
346 //_____________________________________________________________________________________________________________
347 Int_t AliCalorimeterUtils::GetModuleNumberCellIndexes(const Int_t absId, const TString calo, Int_t & icol, Int_t & irow, Int_t & iRCU) const
349 //Get the EMCAL/PHOS module, columns, row and RCU number that corresponds to this absId
353 Int_t iTower = -1, iIphi = -1, iIeta = -1;
354 fEMCALGeo->GetCellIndex(absId,imod,iTower,iIphi,iIeta);
355 fEMCALGeo->GetCellPhiEtaIndexInSModule(imod,iTower,iIphi, iIeta,irow,icol);
356 if(imod < 0 || irow < 0 || icol < 0 ) {
357 Fatal("GetModuleNumberCellIndexes()","Negative value for super module: %d, or cell icol: %d, or cell irow: %d, check EMCAL geometry name\n",imod,icol,irow);
361 if (0<=irow&&irow<8) iRCU=0; // first cable row
362 else if (8<=irow&&irow<16 && 0<=icol&&icol<24) iRCU=0; // first half;
365 else if(8<=irow&&irow<16 && 24<=icol&&icol<48) iRCU=1; // second half;
367 else if(16<=irow&&irow<24) iRCU=1; // third cable row
369 if (imod%2==1) iRCU = 1 - iRCU; // swap for odd=C side, to allow us to cable both sides the same
371 Fatal("GetModuleNumberCellIndexes()","Wrong EMCAL RCU number = %d\n", iRCU);
378 fPHOSGeo->AbsToRelNumbering(absId,relId);
382 iRCU= (Int_t)(relId[2]-1)/16 ;
383 //Int_t iBranch= (Int_t)(relid[3]-1)/28 ; //0 to 1
385 Fatal("GetModuleNumberCellIndexes()","Wrong PHOS RCU number = %d\n", iRCU);
394 //_______________________________________________________________
395 //void AliCalorimeterUtils::Init()
397 // //Init reader. Method to be called in AliAnaPartCorrMaker
399 // fEMCALBadChannelMap->SetName(Form("EMCALBadMap_%s",fTaskName.Data()));
400 // fPHOSBadChannelMap->SetName(Form("PHOSBadMap_%s",fTaskName.Data()));
403 //_______________________________________________________________
404 void AliCalorimeterUtils::InitParameters()
406 //Initialize the parameters of the analysis.
407 fEMCALGeoName = "EMCAL_FIRSTYEAR";
408 fPHOSGeoName = "PHOSgeo";
410 if(gGeoManager) {// geoManager was set
411 if(fDebug > 2)printf("AliCalorimeterUtils::InitParameters() - Geometry manager available\n");
412 fEMCALGeoMatrixSet = kTRUE;
413 fPHOSGeoMatrixSet = kTRUE;
416 fEMCALGeoMatrixSet = kFALSE;
417 fPHOSGeoMatrixSet = kFALSE;
420 fRemoveBadChannels = kFALSE;
422 fNCellsFromPHOSBorder = 0;
426 //________________________________________________________________
427 void AliCalorimeterUtils::InitPHOSBadChannelStatusMap(){
428 //Init PHOS bad channels map
429 if(fDebug > 0 )printf("AliCalorimeterUtils::InitPHOSBadChannelStatusMap()\n");
430 //In order to avoid rewriting the same histograms
431 Bool_t oldStatus = TH1::AddDirectoryStatus();
432 TH1::AddDirectory(kFALSE);
434 fPHOSBadChannelMap = new TObjArray(5);
435 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));
437 fPHOSBadChannelMap->SetOwner(kTRUE);
438 fPHOSBadChannelMap->Compress();
440 //In order to avoid rewriting the same histograms
441 TH1::AddDirectory(oldStatus);
444 //________________________________________________________________
445 void AliCalorimeterUtils::InitPHOSRecalibrationFactors(){
446 //Init EMCAL recalibration factors
447 if(fDebug > 0 )printf("AliCalorimeterUtils::InitPHOSRecalibrationFactors()\n");
448 //In order to avoid rewriting the same histograms
449 Bool_t oldStatus = TH1::AddDirectoryStatus();
450 TH1::AddDirectory(kFALSE);
452 fPHOSRecalibrationFactors = new TObjArray(5);
453 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));
454 //Init the histograms with 1
455 for (Int_t m = 0; m < 5; m++) {
456 for (Int_t i = 0; i < 56; i++) {
457 for (Int_t j = 0; j < 64; j++) {
458 SetPHOSChannelRecalibrationFactor(m,i,j,1.);
462 fPHOSRecalibrationFactors->SetOwner(kTRUE);
463 fPHOSRecalibrationFactors->Compress();
465 //In order to avoid rewriting the same histograms
466 TH1::AddDirectory(oldStatus);
470 //________________________________________________________________
471 void AliCalorimeterUtils::InitEMCALGeometry()
473 //Initialize EMCAL geometry if it did not exist previously
475 fEMCALGeo = new AliEMCALGeoUtils(fEMCALGeoName);
477 printf("AliCalorimeterUtils::InitEMCALGeometry()");
478 if (!gGeoManager) printf(" - Careful!, gGeoManager not loaded, load misalign matrices");
484 //________________________________________________________________
485 void AliCalorimeterUtils::InitPHOSGeometry()
487 //Initialize PHOS geometry if it did not exist previously
489 fPHOSGeo = new AliPHOSGeoUtils(fPHOSGeoName);
491 printf("AliCalorimeterUtils::InitPHOSGeometry()");
492 if (!gGeoManager) printf(" - Careful!, gGeoManager not loaded, load misalign matrices");
498 //________________________________________________________________
499 void AliCalorimeterUtils::Print(const Option_t * opt) const
502 //Print some relevant parameters set for the analysis
506 printf("***** Print: %s %s ******\n", GetName(), GetTitle() ) ;
507 printf("Remove Clusters with bad channels? %d\n",fRemoveBadChannels);
508 printf("Remove Clusters with max cell at less than %d cells from EMCAL border and %d cells from PHOS border\n",
509 fEMCALRecoUtils->GetNumberOfCellsFromEMCALBorder(), fNCellsFromPHOSBorder);
510 if(fEMCALRecoUtils->IsEMCALNoBorderAtEta0()) printf("Do not remove EMCAL clusters at Eta = 0\n");
511 printf("Recalibrate Clusters? %d\n",fRecalibration);
512 printf("Recalculate Clusters Position? %d\n",fRecalculatePosition);
513 printf("Recalculate Clusters Energy? %d\n",fCorrectELinearity);
514 printf("Matching criteria: dR < %2.2f[cm], dZ < %2.2f[cm]\n",fCutR,fCutZ);
519 //________________________________________________________________
520 Float_t AliCalorimeterUtils::RecalibrateClusterEnergy(AliVCluster * cluster, AliVCaloCells * cells){
521 // Recalibrate the cluster energy, considering the recalibration map and the energy of the cells that compose the cluster.
523 //Initialize some used variables
526 Int_t icol = -1, irow = -1, iRCU = -1, module=1;
527 Float_t factor = 1, frac = 0;
531 //Get the cluster number of cells and list of absId, check what kind of cluster do we have.
532 UShort_t * index = cluster->GetCellsAbsId() ;
533 Double_t * fraction = cluster->GetCellsAmplitudeFraction() ;
534 Int_t ncells = cluster->GetNCells();
535 TString calo = "EMCAL";
536 if(cluster->IsPHOS()) calo = "PHOS";
538 //Loop on the cells, get the cell amplitude and recalibration factor, multiply and and to the new energy
539 for(Int_t icell = 0; icell < ncells; icell++){
540 absId = index[icell];
541 frac = fraction[icell];
542 if(frac < 1e-3) frac = 1; //in case of EMCAL, this is set as 0, not used.
543 module = GetModuleNumberCellIndexes(absId,calo,icol,irow,iRCU);
544 if(cluster->IsPHOS()) factor = GetPHOSChannelRecalibrationFactor (module,icol,irow);
545 else factor = GetEMCALChannelRecalibrationFactor(module,icol,irow);
547 printf("AliCalorimeterUtils::RecalibrateClusterEnergy() - recalibrate cell: %s, module %d, col %d, row %d, cell fraction %f, recalibration factor %f, cell energy %f\n",
548 calo.Data(),module,icol,irow,frac,factor,cells->GetCellAmplitude(absId));
550 energy += cells->GetCellAmplitude(absId)*factor*frac;
554 printf("AliCalorimeterUtils::RecalibrateClusterEnergy() - Energy before %f, after %f\n",cluster->E(),energy);
558 Fatal("RecalibrateClusterEnergy()","Cells pointer does not exist!");
564 //________________________________________________________________
565 void AliCalorimeterUtils::SetGeometryTransformationMatrices(AliVEvent* inputEvent)
567 //Set the calorimeters transformation matrices
569 //Get the EMCAL transformation geometry matrices from ESD
570 if (!gGeoManager && fEMCALGeo && !fEMCALGeoMatrixSet) {
572 printf(" AliCalorimeterUtils::SetGeometryTransformationMatrices() - Load EMCAL misalignment matrices. \n");
573 if(!strcmp(inputEvent->GetName(),"AliESDEvent")) {
574 for(Int_t mod=0; mod < (fEMCALGeo->GetEMCGeometry())->GetNumberOfSuperModules(); mod++){
575 if(inputEvent->GetEMCALMatrix(mod)) {
576 //printf("EMCAL: mod %d, matrix %p\n",mod, ((AliESDEvent*)inputEvent)->GetEMCALMatrix(mod));
577 fEMCALGeo->SetMisalMatrix(inputEvent->GetEMCALMatrix(mod),mod) ;
578 fEMCALGeoMatrixSet = kTRUE;//At least one, so good
580 }// loop over super modules
584 printf("AliCalorimeterUtils::SetGeometryTransformationMatrices() - Setting of EMCAL transformation matrixes for AODs not implemented yet. \n Import geometry.root file\n");
586 }//EMCAL geo && no geoManager
588 //Get the PHOS transformation geometry matrices from ESD
589 if (!gGeoManager && fPHOSGeo && !fPHOSGeoMatrixSet) {
591 printf(" AliCalorimeterUtils::SetGeometryTransformationMatrices() - Load PHOS misalignment matrices. \n");
592 if(!strcmp(inputEvent->GetName(),"AliESDEvent")) {
593 for(Int_t mod=0; mod < 5; mod++){
594 if(inputEvent->GetPHOSMatrix(mod)) {
595 //printf("PHOS: mod %d, matrix %p\n",mod, ((AliESDEvent*)inputEvent)->GetPHOSMatrix(mod));
596 fPHOSGeo->SetMisalMatrix(inputEvent->GetPHOSMatrix(mod),mod) ;
597 fPHOSGeoMatrixSet = kTRUE; //At least one so good
599 }// loop over modules
603 printf("AliCalorimeterUtils::SetGeometryTransformationMatrices() - Setting of EMCAL transformation matrixes for AODs not implemented yet. \n Import geometry.root file\n");
605 }//PHOS geo and geoManager was not set
609 //________________________________________________________________
610 void AliCalorimeterUtils::RecalculateClusterPosition(AliVCaloCells* cells, AliVCluster* clu){
612 //Recalculate EMCAL cluster position
614 fEMCALRecoUtils->RecalculateClusterPosition((AliEMCALGeometry*)fEMCALGeo, cells,clu);