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 **************************************************************************/
16 /* $Id: AliEMCALRecoUtils.cxx 33808 2009-07-15 09:48:08Z gconesab $ */
18 ///////////////////////////////////////////////////////////////////////////////
20 // Class AliEMCALRecoUtils
21 // Some utilities to recalculate the cluster position or energy linearity
24 // Author: Gustavo Conesa (LPSC- Grenoble)
25 // Track matching part: Rongrong Ma (Yale)
27 ///////////////////////////////////////////////////////////////////////////////
30 // standard C++ includes
31 //#include <Riostream.h>
34 #include <TGeoManager.h>
35 #include <TGeoMatrix.h>
40 #include <TObjArray.h>
43 #include "AliVCluster.h"
44 #include "AliVCaloCells.h"
47 #include "AliESDEvent.h"
48 #include "AliAODEvent.h"
49 #include "AliESDtrack.h"
50 #include "AliAODTrack.h"
51 #include "AliExternalTrackParam.h"
52 #include "AliESDfriendTrack.h"
53 #include "AliTrackerBase.h"
56 #include "AliEMCALRecoUtils.h"
57 #include "AliEMCALGeometry.h"
58 #include "AliTrackerBase.h"
59 #include "AliEMCALCalibTimeDepCorrection.h" // Run dependent
60 #include "AliEMCALPIDUtils.h"
63 ClassImp(AliEMCALRecoUtils)
65 //_____________________________________
66 AliEMCALRecoUtils::AliEMCALRecoUtils():
67 fParticleType(0), fPosAlgo(0), fW0(0),
68 fNonLinearityFunction(0), fNonLinearThreshold(0),
69 fSmearClusterEnergy(kFALSE), fRandom(),
70 fCellsRecalibrated(kFALSE), fRecalibration(kFALSE), fEMCALRecalibrationFactors(),
71 fTimeRecalibration(kFALSE), fEMCALTimeRecalibrationFactors(),
72 fUseRunCorrectionFactors(kFALSE), fRunCorrectionFactorsSet(kFALSE),
73 fRemoveBadChannels(kFALSE), fRecalDistToBadChannels(kFALSE), fEMCALBadChannelMap(),
74 fNCellsFromEMCALBorder(0), fNoEMCALBorderAtEta0(kTRUE),
75 fRejectExoticCluster(kFALSE), fRejectExoticCells(kFALSE),
76 fExoticCellFraction(0), fExoticCellDiffTime(0), fExoticCellMinAmplitude(0),
77 fPIDUtils(), fAODFilterMask(0),
78 fMatchedTrackIndex(0x0), fMatchedClusterIndex(0x0),
79 fResidualEta(0x0), fResidualPhi(0x0), fCutEtaPhiSum(kFALSE), fCutEtaPhiSeparate(kFALSE),
80 fCutR(0), fCutEta(0), fCutPhi(0),
81 fClusterWindow(0), fMass(0),
82 fStepSurface(0), fStepCluster(0),
83 fTrackCutsType(0), fCutMinTrackPt(0), fCutMinNClusterTPC(0),
84 fCutMinNClusterITS(0), fCutMaxChi2PerClusterTPC(0), fCutMaxChi2PerClusterITS(0),
85 fCutRequireTPCRefit(kFALSE), fCutRequireITSRefit(kFALSE), fCutAcceptKinkDaughters(kFALSE),
86 fCutMaxDCAToVertexXY(0), fCutMaxDCAToVertexZ(0), fCutDCAToVertex2D(kFALSE)
90 // Initialize all constant values which have to be used
91 // during Reco algorithm execution
98 fMatchedTrackIndex = new TArrayI();
99 fMatchedClusterIndex = new TArrayI();
100 fResidualPhi = new TArrayF();
101 fResidualEta = new TArrayF();
102 fPIDUtils = new AliEMCALPIDUtils();
107 //______________________________________________________________________
108 AliEMCALRecoUtils::AliEMCALRecoUtils(const AliEMCALRecoUtils & reco)
110 fParticleType(reco.fParticleType), fPosAlgo(reco.fPosAlgo), fW0(reco.fW0),
111 fNonLinearityFunction(reco.fNonLinearityFunction), fNonLinearThreshold(reco.fNonLinearThreshold),
112 fSmearClusterEnergy(reco.fSmearClusterEnergy), fRandom(),
113 fCellsRecalibrated(reco.fCellsRecalibrated),
114 fRecalibration(reco.fRecalibration), fEMCALRecalibrationFactors(reco.fEMCALRecalibrationFactors),
115 fTimeRecalibration(reco.fTimeRecalibration), fEMCALTimeRecalibrationFactors(reco.fEMCALTimeRecalibrationFactors),
116 fUseRunCorrectionFactors(reco.fUseRunCorrectionFactors), fRunCorrectionFactorsSet(reco.fRunCorrectionFactorsSet),
117 fRemoveBadChannels(reco.fRemoveBadChannels), fRecalDistToBadChannels(reco.fRecalDistToBadChannels),
118 fEMCALBadChannelMap(reco.fEMCALBadChannelMap),
119 fNCellsFromEMCALBorder(reco.fNCellsFromEMCALBorder), fNoEMCALBorderAtEta0(reco.fNoEMCALBorderAtEta0),
120 fRejectExoticCluster(reco.fRejectExoticCluster), fRejectExoticCells(reco.fRejectExoticCells),
121 fExoticCellFraction(reco.fExoticCellFraction), fExoticCellDiffTime(reco.fExoticCellDiffTime),
122 fExoticCellMinAmplitude(reco.fExoticCellMinAmplitude),
123 fPIDUtils(reco.fPIDUtils), fAODFilterMask(reco.fAODFilterMask),
124 fMatchedTrackIndex( reco.fMatchedTrackIndex? new TArrayI(*reco.fMatchedTrackIndex):0x0),
125 fMatchedClusterIndex(reco.fMatchedClusterIndex?new TArrayI(*reco.fMatchedClusterIndex):0x0),
126 fResidualEta( reco.fResidualEta? new TArrayF(*reco.fResidualEta):0x0),
127 fResidualPhi( reco.fResidualPhi? new TArrayF(*reco.fResidualPhi):0x0),
128 fCutEtaPhiSum(reco.fCutEtaPhiSum), fCutEtaPhiSeparate(reco.fCutEtaPhiSeparate),
129 fCutR(reco.fCutR), fCutEta(reco.fCutEta), fCutPhi(reco.fCutPhi),
130 fClusterWindow(reco.fClusterWindow),
131 fMass(reco.fMass), fStepSurface(reco.fStepSurface), fStepCluster(reco.fStepCluster),
132 fTrackCutsType(reco.fTrackCutsType), fCutMinTrackPt(reco.fCutMinTrackPt),
133 fCutMinNClusterTPC(reco.fCutMinNClusterTPC), fCutMinNClusterITS(reco.fCutMinNClusterITS),
134 fCutMaxChi2PerClusterTPC(reco.fCutMaxChi2PerClusterTPC), fCutMaxChi2PerClusterITS(reco.fCutMaxChi2PerClusterITS),
135 fCutRequireTPCRefit(reco.fCutRequireTPCRefit), fCutRequireITSRefit(reco.fCutRequireITSRefit),
136 fCutAcceptKinkDaughters(reco.fCutAcceptKinkDaughters), fCutMaxDCAToVertexXY(reco.fCutMaxDCAToVertexXY),
137 fCutMaxDCAToVertexZ(reco.fCutMaxDCAToVertexZ), fCutDCAToVertex2D(reco.fCutDCAToVertex2D)
141 for(Int_t i = 0; i < 15 ; i++) { fMisalRotShift[i] = reco.fMisalRotShift[i] ;
142 fMisalTransShift[i] = reco.fMisalTransShift[i] ; }
143 for(Int_t i = 0; i < 7 ; i++) { fNonLinearityParams[i] = reco.fNonLinearityParams[i] ; }
144 for(Int_t i = 0; i < 3 ; i++) { fSmearClusterParam[i] = reco.fSmearClusterParam[i] ; }
149 //______________________________________________________________________
150 AliEMCALRecoUtils & AliEMCALRecoUtils::operator = (const AliEMCALRecoUtils & reco)
152 //Assignment operator
154 if(this == &reco)return *this;
155 ((TNamed *)this)->operator=(reco);
157 for(Int_t i = 0; i < 15 ; i++) { fMisalTransShift[i] = reco.fMisalTransShift[i] ;
158 fMisalRotShift[i] = reco.fMisalRotShift[i] ; }
159 for(Int_t i = 0; i < 7 ; i++) { fNonLinearityParams[i] = reco.fNonLinearityParams[i] ; }
160 for(Int_t i = 0; i < 3 ; i++) { fSmearClusterParam[i] = reco.fSmearClusterParam[i] ; }
162 fParticleType = reco.fParticleType;
163 fPosAlgo = reco.fPosAlgo;
166 fNonLinearityFunction = reco.fNonLinearityFunction;
167 fNonLinearThreshold = reco.fNonLinearThreshold;
168 fSmearClusterEnergy = reco.fSmearClusterEnergy;
170 fCellsRecalibrated = reco.fCellsRecalibrated;
171 fRecalibration = reco.fRecalibration;
172 fEMCALRecalibrationFactors = reco.fEMCALRecalibrationFactors;
174 fTimeRecalibration = reco.fTimeRecalibration;
175 fEMCALTimeRecalibrationFactors = reco.fEMCALTimeRecalibrationFactors;
177 fUseRunCorrectionFactors = reco.fUseRunCorrectionFactors;
178 fRunCorrectionFactorsSet = reco.fRunCorrectionFactorsSet;
180 fRemoveBadChannels = reco.fRemoveBadChannels;
181 fRecalDistToBadChannels = reco.fRecalDistToBadChannels;
182 fEMCALBadChannelMap = reco.fEMCALBadChannelMap;
184 fNCellsFromEMCALBorder = reco.fNCellsFromEMCALBorder;
185 fNoEMCALBorderAtEta0 = reco.fNoEMCALBorderAtEta0;
187 fRejectExoticCluster = reco.fRejectExoticCluster;
188 fRejectExoticCells = reco.fRejectExoticCells;
189 fExoticCellFraction = reco.fExoticCellFraction;
190 fExoticCellDiffTime = reco.fExoticCellDiffTime;
191 fExoticCellMinAmplitude = reco.fExoticCellMinAmplitude;
193 fPIDUtils = reco.fPIDUtils;
195 fAODFilterMask = reco.fAODFilterMask;
197 fCutEtaPhiSum = reco.fCutEtaPhiSum;
198 fCutEtaPhiSeparate = reco.fCutEtaPhiSeparate;
200 fCutEta = reco.fCutEta;
201 fCutPhi = reco.fCutPhi;
202 fClusterWindow = reco.fClusterWindow;
204 fStepSurface = reco.fStepSurface;
205 fStepCluster = reco.fStepCluster;
207 fTrackCutsType = reco.fTrackCutsType;
208 fCutMinTrackPt = reco.fCutMinTrackPt;
209 fCutMinNClusterTPC = reco.fCutMinNClusterTPC;
210 fCutMinNClusterITS = reco.fCutMinNClusterITS;
211 fCutMaxChi2PerClusterTPC = reco.fCutMaxChi2PerClusterTPC;
212 fCutMaxChi2PerClusterITS = reco.fCutMaxChi2PerClusterITS;
213 fCutRequireTPCRefit = reco.fCutRequireTPCRefit;
214 fCutRequireITSRefit = reco.fCutRequireITSRefit;
215 fCutAcceptKinkDaughters = reco.fCutAcceptKinkDaughters;
216 fCutMaxDCAToVertexXY = reco.fCutMaxDCAToVertexXY;
217 fCutMaxDCAToVertexZ = reco.fCutMaxDCAToVertexZ;
218 fCutDCAToVertex2D = reco.fCutDCAToVertex2D;
220 if(reco.fResidualEta)
222 // assign or copy construct
225 *fResidualEta = *reco.fResidualEta;
229 fResidualEta = new TArrayF(*reco.fResidualEta);
234 if(fResidualEta)delete fResidualEta;
238 if(reco.fResidualPhi)
240 // assign or copy construct
243 *fResidualPhi = *reco.fResidualPhi;
247 fResidualPhi = new TArrayF(*reco.fResidualPhi);
252 if(fResidualPhi)delete fResidualPhi;
256 if(reco.fMatchedTrackIndex)
258 // assign or copy construct
259 if(fMatchedTrackIndex)
261 *fMatchedTrackIndex = *reco.fMatchedTrackIndex;
265 fMatchedTrackIndex = new TArrayI(*reco.fMatchedTrackIndex);
270 if(fMatchedTrackIndex)delete fMatchedTrackIndex;
271 fMatchedTrackIndex = 0;
274 if(reco.fMatchedClusterIndex)
276 // assign or copy construct
277 if(fMatchedClusterIndex)
279 *fMatchedClusterIndex = *reco.fMatchedClusterIndex;
283 fMatchedClusterIndex = new TArrayI(*reco.fMatchedClusterIndex);
288 if(fMatchedClusterIndex)delete fMatchedClusterIndex;
289 fMatchedClusterIndex = 0;
296 //_____________________________________
297 AliEMCALRecoUtils::~AliEMCALRecoUtils()
301 if(fEMCALRecalibrationFactors)
303 fEMCALRecalibrationFactors->Clear();
304 delete fEMCALRecalibrationFactors;
307 if(fEMCALTimeRecalibrationFactors)
309 fEMCALTimeRecalibrationFactors->Clear();
310 delete fEMCALTimeRecalibrationFactors;
313 if(fEMCALBadChannelMap)
315 fEMCALBadChannelMap->Clear();
316 delete fEMCALBadChannelMap;
319 delete fMatchedTrackIndex ;
320 delete fMatchedClusterIndex ;
321 delete fResidualEta ;
322 delete fResidualPhi ;
328 //_______________________________________________________________________________
329 Bool_t AliEMCALRecoUtils::AcceptCalibrateCell(const Int_t absID, const Int_t bc,
330 Float_t & amp, Double_t & time,
331 AliVCaloCells* cells)
333 // Reject cell if criteria not passed and calibrate it
335 AliEMCALGeometry* geom = AliEMCALGeometry::GetInstance();
337 if(absID < 0 || absID >= 24*48*geom->GetNumberOfSuperModules()) return kFALSE;
339 Int_t imod = -1, iphi =-1, ieta=-1,iTower = -1, iIphi = -1, iIeta = -1;
341 if(!geom->GetCellIndex(absID,imod,iTower,iIphi,iIeta))
343 // cell absID does not exist
348 geom->GetCellPhiEtaIndexInSModule(imod,iTower,iIphi, iIeta,iphi,ieta);
350 // Do not include bad channels found in analysis,
351 if( IsBadChannelsRemovalSwitchedOn() && GetEMCALChannelStatus(imod, ieta, iphi))
357 amp = cells->GetCellAmplitude(absID);
358 if(!fCellsRecalibrated && IsRecalibrationOn())
359 amp *= GetEMCALChannelRecalibrationFactor(imod,ieta,iphi);
363 time = cells->GetCellTime(absID);
365 RecalibrateCellTime(absID,bc,time);
370 //_____________________________________________________________________________
371 Bool_t AliEMCALRecoUtils::CheckCellFiducialRegion(const AliEMCALGeometry* geom,
372 const AliVCluster* cluster,
373 AliVCaloCells* cells)
375 // Given the list of AbsId of the cluster, get the maximum cell and
376 // check if there are fNCellsFromBorder from the calorimeter border
380 AliInfo("Cluster pointer null!");
384 //If the distance to the border is 0 or negative just exit accept all clusters
385 if(cells->GetType()==AliVCaloCells::kEMCALCell && fNCellsFromEMCALBorder <= 0 ) return kTRUE;
387 Int_t absIdMax = -1, iSM =-1, ieta = -1, iphi = -1;
388 Bool_t shared = kFALSE;
389 GetMaxEnergyCell(geom, cells, cluster, absIdMax, iSM, ieta, iphi, shared);
391 AliDebug(2,Form("Cluster Max AbsId %d, Cell Energy %2.2f, Cluster Energy %2.2f, Ncells from border %d, EMCAL eta=0 %d\n",
392 absIdMax, cells->GetCellAmplitude(absIdMax), cluster->E(), fNCellsFromEMCALBorder, fNoEMCALBorderAtEta0));
394 if(absIdMax==-1) return kFALSE;
396 //Check if the cell is close to the borders:
397 Bool_t okrow = kFALSE;
398 Bool_t okcol = kFALSE;
400 if(iSM < 0 || iphi < 0 || ieta < 0 )
402 AliFatal(Form("Negative value for super module: %d, or cell ieta: %d, or cell iphi: %d, check EMCAL geometry name\n",
409 if(iphi >= fNCellsFromEMCALBorder && iphi < 24-fNCellsFromEMCALBorder) okrow =kTRUE;
411 else if (iSM >=10 && ( ( geom->GetEMCGeometry()->GetGeoName()).Contains("12SMV1")))
413 if(iphi >= fNCellsFromEMCALBorder && iphi < 8-fNCellsFromEMCALBorder) okrow =kTRUE; //1/3 sm case
417 if(iphi >= fNCellsFromEMCALBorder && iphi < 12-fNCellsFromEMCALBorder) okrow =kTRUE; // half SM case
421 if(!fNoEMCALBorderAtEta0)
423 if(ieta > fNCellsFromEMCALBorder && ieta < 48-fNCellsFromEMCALBorder) okcol =kTRUE;
429 if(ieta >= fNCellsFromEMCALBorder) okcol = kTRUE;
433 if(ieta < 48-fNCellsFromEMCALBorder) okcol = kTRUE;
437 AliDebug(2,Form("EMCAL Cluster in %d cells fiducial volume: ieta %d, iphi %d, SM %d: column? %d, row? %d\nq",
438 fNCellsFromEMCALBorder, ieta, iphi, iSM, okcol, okrow));
442 //printf("Accept\n");
447 //printf("Reject\n");
448 AliDebug(2,Form("Reject cluster in border, max cell : ieta %d, iphi %d, SM %d\n",ieta, iphi, iSM));
455 //_______________________________________________________________________________
456 Bool_t AliEMCALRecoUtils::ClusterContainsBadChannel(const AliEMCALGeometry* geom,
457 const UShort_t* cellList,
460 // Check that in the cluster cells, there is no bad channel of those stored
461 // in fEMCALBadChannelMap or fPHOSBadChannelMap
463 if(!fRemoveBadChannels) return kFALSE;
464 if(!fEMCALBadChannelMap) return kFALSE;
469 for(Int_t iCell = 0; iCell<nCells; iCell++)
471 //Get the column and row
472 Int_t iTower = -1, iIphi = -1, iIeta = -1;
473 geom->GetCellIndex(cellList[iCell],imod,iTower,iIphi,iIeta);
474 if(fEMCALBadChannelMap->GetEntries() <= imod) continue;
475 geom->GetCellPhiEtaIndexInSModule(imod,iTower,iIphi, iIeta,irow,icol);
476 if(GetEMCALChannelStatus(imod, icol, irow))
478 AliDebug(2,Form("Cluster with bad channel: SM %d, col %d, row %d\n",imod, icol, irow));
482 }// cell cluster loop
487 //_____________________________________________________________________________________________
488 Bool_t AliEMCALRecoUtils::IsExoticCell(const Int_t absID, AliVCaloCells* cells, const Int_t bc)
490 // Look to cell neighbourhood and reject if it seems exotic
491 // Do before recalibrating the cells
493 if(!fRejectExoticCells) return kFALSE;
495 AliEMCALGeometry * geom = AliEMCALGeometry::GetInstance();
497 Int_t imod = -1, iphi =-1, ieta=-1,iTower = -1, iIphi = -1, iIeta = -1;
498 geom->GetCellIndex(absID,imod,iTower,iIphi,iIeta);
499 geom->GetCellPhiEtaIndexInSModule(imod,iTower,iIphi, iIeta,iphi,ieta);
501 //Get close cells index, energy and time, not in corners
506 if( iphi < AliEMCALGeoParams::fgkEMCALRows-1) absID1 = geom-> GetAbsCellIdFromCellIndexes(imod, iphi+1, ieta);
507 if( iphi > 0 ) absID2 = geom-> GetAbsCellIdFromCellIndexes(imod, iphi-1, ieta);
509 // In case of cell in eta = 0 border, depending on SM shift the cross cell index
515 if ( ieta == AliEMCALGeoParams::fgkEMCALCols-1 && !(imod%2) )
517 absID3 = geom-> GetAbsCellIdFromCellIndexes(imod+1, iphi, 0);
518 absID4 = geom-> GetAbsCellIdFromCellIndexes(imod, iphi, ieta-1);
520 else if( ieta == 0 && imod%2 )
522 absID3 = geom-> GetAbsCellIdFromCellIndexes(imod, iphi, ieta+1);
523 absID4 = geom-> GetAbsCellIdFromCellIndexes(imod-1, iphi, AliEMCALGeoParams::fgkEMCALCols-1);
527 if( ieta < AliEMCALGeoParams::fgkEMCALCols-1 )
528 absID3 = geom-> GetAbsCellIdFromCellIndexes(imod, iphi, ieta+1);
530 absID4 = geom-> GetAbsCellIdFromCellIndexes(imod, iphi, ieta-1);
533 //printf("IMOD %d, AbsId %d, a %d, b %d, c %d e %d \n",imod,absID,absID1,absID2,absID3,absID4);
536 Float_t ecell = 0, ecell1 = 0, ecell2 = 0, ecell3 = 0, ecell4 = 0;
537 Double_t tcell = 0, tcell1 = 0, tcell2 = 0, tcell3 = 0, tcell4 = 0;
538 Bool_t accept = 0, accept1 = 0, accept2 = 0, accept3 = 0, accept4 = 0;
540 accept = AcceptCalibrateCell(absID, bc, ecell ,tcell ,cells);
542 if(!accept) return kTRUE; // reject this cell
544 if(ecell < fExoticCellMinAmplitude) return kFALSE; // do not reject low energy cells
546 accept1 = AcceptCalibrateCell(absID1,bc, ecell1,tcell1,cells);
547 accept2 = AcceptCalibrateCell(absID2,bc, ecell2,tcell2,cells);
548 accept3 = AcceptCalibrateCell(absID3,bc, ecell3,tcell3,cells);
549 accept4 = AcceptCalibrateCell(absID4,bc, ecell4,tcell4,cells);
552 printf("Cell absID %d \n",absID);
553 printf("\t accept1 %d, accept2 %d, accept3 %d, accept4 %d\n",
554 accept1,accept2,accept3,accept4);
555 printf("\t id %d: id1 %d, id2 %d, id3 %d, id4 %d\n",
556 absID,absID1,absID2,absID3,absID4);
557 printf("\t e %f: e1 %f, e2 %f, e3 %f, e4 %f\n",
558 ecell,ecell1,ecell2,ecell3,ecell4);
559 printf("\t t %f: t1 %f, t2 %f, t3 %f, t4 %f;\n dt1 %f, dt2 %f, dt3 %f, dt4 %f\n",
560 tcell*1.e9,tcell1*1.e9,tcell2*1.e9,tcell3*1.e9,tcell4*1.e9,
561 TMath::Abs(tcell-tcell1)*1.e9, TMath::Abs(tcell-tcell2)*1.e9, TMath::Abs(tcell-tcell3)*1.e9, TMath::Abs(tcell-tcell4)*1.e9);
564 if(TMath::Abs(tcell-tcell1)*1.e9 > fExoticCellDiffTime) ecell1 = 0 ;
565 if(TMath::Abs(tcell-tcell2)*1.e9 > fExoticCellDiffTime) ecell2 = 0 ;
566 if(TMath::Abs(tcell-tcell3)*1.e9 > fExoticCellDiffTime) ecell3 = 0 ;
567 if(TMath::Abs(tcell-tcell4)*1.e9 > fExoticCellDiffTime) ecell4 = 0 ;
569 Float_t eCross = ecell1+ecell2+ecell3+ecell4;
571 //printf("\t eCell %f, eCross %f, 1-eCross/eCell %f\n",ecell,eCross,1-eCross/ecell);
573 if(1-eCross/ecell > fExoticCellFraction)
575 AliDebug(2,Form("AliEMCALRecoUtils::IsExoticCell() - EXOTIC CELL id %d, eCell %f, eCross %f, 1-eCross/eCell %f\n",
576 absID,ecell,eCross,1-eCross/ecell));
583 //___________________________________________________________________
584 Bool_t AliEMCALRecoUtils::IsExoticCluster(const AliVCluster *cluster,
585 AliVCaloCells *cells,
588 // Check if the cluster highest energy tower is exotic
592 AliInfo("Cluster pointer null!");
596 if(!fRejectExoticCluster) return kFALSE;
598 // Get highest energy tower
599 AliEMCALGeometry* geom = AliEMCALGeometry::GetInstance();
600 Int_t iSupMod = -1, absId = -1, ieta = -1, iphi = -1;
601 Bool_t shared = kFALSE;
602 GetMaxEnergyCell(geom, cells, cluster, absId, iSupMod, ieta, iphi, shared);
604 return IsExoticCell(absId,cells,bc);
608 //_______________________________________________________________________
609 Float_t AliEMCALRecoUtils::SmearClusterEnergy(const AliVCluster* cluster)
611 //In case of MC analysis, smear energy to match resolution/calibration in real data
615 AliInfo("Cluster pointer null!");
619 Float_t energy = cluster->E() ;
620 Float_t rdmEnergy = energy ;
621 if(fSmearClusterEnergy)
623 rdmEnergy = fRandom.Gaus(energy,fSmearClusterParam[0] * TMath::Sqrt(energy) +
624 fSmearClusterParam[1] * energy +
625 fSmearClusterParam[2] );
626 AliDebug(2, Form("Energy: original %f, smeared %f\n", energy, rdmEnergy));
632 //____________________________________________________________________________
633 Float_t AliEMCALRecoUtils::CorrectClusterEnergyLinearity(AliVCluster* cluster)
635 // Correct cluster energy from non linearity functions
639 AliInfo("Cluster pointer null!");
643 Float_t energy = cluster->E();
645 switch (fNonLinearityFunction)
650 //Non-Linearity correction (from MC with function ([0]*exp(-[1]/E))+(([2]/([3]*2.*TMath::Pi())*exp(-(E-[4])^2/(2.*[3]^2)))))
651 //Double_t fNonLinearityParams[0] = 1.014;
652 //Double_t fNonLinearityParams[1] = -0.03329;
653 //Double_t fNonLinearityParams[2] = -0.3853;
654 //Double_t fNonLinearityParams[3] = 0.5423;
655 //Double_t fNonLinearityParams[4] = -0.4335;
656 energy *= (fNonLinearityParams[0]*exp(-fNonLinearityParams[1]/energy))+
657 ((fNonLinearityParams[2]/(fNonLinearityParams[3]*2.*TMath::Pi())*
658 exp(-(energy-fNonLinearityParams[4])*(energy-fNonLinearityParams[4])/(2.*fNonLinearityParams[3]*fNonLinearityParams[3]))));
664 //Non-Linearity correction (from Olga Data with function p0+p1*exp(-p2*E))
665 //Double_t fNonLinearityParams[0] = 1.04;
666 //Double_t fNonLinearityParams[1] = -0.1445;
667 //Double_t fNonLinearityParams[2] = 1.046;
668 energy /= (fNonLinearityParams[0]+fNonLinearityParams[1]*exp(-fNonLinearityParams[2]*energy)); //Olga function
672 case kPi0GammaConversion:
674 //Non-Linearity correction (Nicolas from Dimitri Data with function C*[1-a*exp(-b*E)])
675 //fNonLinearityParams[0] = 0.139393/0.1349766;
676 //fNonLinearityParams[1] = 0.0566186;
677 //fNonLinearityParams[2] = 0.982133;
678 energy /= fNonLinearityParams[0]*(1-fNonLinearityParams[1]*exp(-fNonLinearityParams[2]*energy));
685 //From beam test, Alexei's results, for different ZS thresholds
686 // th=30 MeV; th = 45 MeV; th = 75 MeV
687 //fNonLinearityParams[0] = 1.007; 1.003; 1.002
688 //fNonLinearityParams[1] = 0.894; 0.719; 0.797
689 //fNonLinearityParams[2] = 0.246; 0.334; 0.358
690 //Rescale the param[0] with 1.03
691 energy /= fNonLinearityParams[0]/(1+fNonLinearityParams[1]*exp(-energy/fNonLinearityParams[2]));
696 case kBeamTestCorrected:
698 //From beam test, corrected for material between beam and EMCAL
699 //fNonLinearityParams[0] = 0.99078
700 //fNonLinearityParams[1] = 0.161499;
701 //fNonLinearityParams[2] = 0.655166;
702 //fNonLinearityParams[3] = 0.134101;
703 //fNonLinearityParams[4] = 163.282;
704 //fNonLinearityParams[5] = 23.6904;
705 //fNonLinearityParams[6] = 0.978;
706 energy *= fNonLinearityParams[6]/(fNonLinearityParams[0]*(1./(1.+fNonLinearityParams[1]*exp(-energy/fNonLinearityParams[2]))*1./(1.+fNonLinearityParams[3]*exp((energy-fNonLinearityParams[4])/fNonLinearityParams[5]))));
712 AliDebug(2,"No correction on the energy\n");
720 //__________________________________________________
721 void AliEMCALRecoUtils::InitNonLinearityParam()
723 //Initialising Non Linearity Parameters
725 if(fNonLinearityFunction == kPi0MC)
727 fNonLinearityParams[0] = 1.014;
728 fNonLinearityParams[1] = -0.03329;
729 fNonLinearityParams[2] = -0.3853;
730 fNonLinearityParams[3] = 0.5423;
731 fNonLinearityParams[4] = -0.4335;
734 if(fNonLinearityFunction == kPi0GammaGamma)
736 fNonLinearityParams[0] = 1.04;
737 fNonLinearityParams[1] = -0.1445;
738 fNonLinearityParams[2] = 1.046;
741 if(fNonLinearityFunction == kPi0GammaConversion)
743 fNonLinearityParams[0] = 0.139393;
744 fNonLinearityParams[1] = 0.0566186;
745 fNonLinearityParams[2] = 0.982133;
748 if(fNonLinearityFunction == kBeamTest)
750 if(fNonLinearThreshold == 30)
752 fNonLinearityParams[0] = 1.007;
753 fNonLinearityParams[1] = 0.894;
754 fNonLinearityParams[2] = 0.246;
756 if(fNonLinearThreshold == 45)
758 fNonLinearityParams[0] = 1.003;
759 fNonLinearityParams[1] = 0.719;
760 fNonLinearityParams[2] = 0.334;
762 if(fNonLinearThreshold == 75)
764 fNonLinearityParams[0] = 1.002;
765 fNonLinearityParams[1] = 0.797;
766 fNonLinearityParams[2] = 0.358;
770 if(fNonLinearityFunction == kBeamTestCorrected)
772 fNonLinearityParams[0] = 0.99078;
773 fNonLinearityParams[1] = 0.161499;
774 fNonLinearityParams[2] = 0.655166;
775 fNonLinearityParams[3] = 0.134101;
776 fNonLinearityParams[4] = 163.282;
777 fNonLinearityParams[5] = 23.6904;
778 fNonLinearityParams[6] = 0.978;
782 //_________________________________________________________
783 Float_t AliEMCALRecoUtils::GetDepth(const Float_t energy,
784 const Int_t iParticle,
785 const Int_t iSM) const
787 //Calculate shower depth for a given cluster energy and particle type
797 depth = x0 * (TMath::Log(energy*1000/ ecr) + 0.5); //Multiply energy by 1000 to transform to MeV
801 depth = x0 * (TMath::Log(energy*1000/ ecr) - 0.5); //Multiply energy by 1000 to transform to MeV
809 gGeoManager->cd("ALIC_1/XEN1_1");
810 TGeoNode *geoXEn1 = gGeoManager->GetCurrentNode();
811 TGeoNodeMatrix *geoSM = dynamic_cast<TGeoNodeMatrix *>(geoXEn1->GetDaughter(iSM));
814 TGeoVolume *geoSMVol = geoSM->GetVolume();
815 TGeoShape *geoSMShape = geoSMVol->GetShape();
816 TGeoBBox *geoBox = dynamic_cast<TGeoBBox *>(geoSMShape);
817 if(geoBox) depth = 0.5 * geoBox->GetDX()*2 ;
818 else AliFatal("Null GEANT box");
820 else AliFatal("NULL GEANT node matrix");
824 depth = x0 * (TMath::Log(energy*1000 / ecr) - 0.5); //Multiply energy by 1000 to transform to MeV
830 depth = x0 * (TMath::Log(energy*1000 / ecr) + 0.5); //Multiply energy by 1000 to transform to MeV
836 //____________________________________________________________________
837 void AliEMCALRecoUtils::GetMaxEnergyCell(const AliEMCALGeometry *geom,
838 AliVCaloCells* cells,
839 const AliVCluster* clu,
846 //For a given CaloCluster gets the absId of the cell
847 //with maximum energy deposit.
850 Double_t eCell = -1.;
851 Float_t fraction = 1.;
852 Float_t recalFactor = 1.;
853 Int_t cellAbsId = -1 ;
862 AliInfo("Cluster pointer null!");
863 absId=-1; iSupMod0=-1, ieta = -1; iphi = -1; shared = -1;
867 for (Int_t iDig=0; iDig< clu->GetNCells(); iDig++)
869 cellAbsId = clu->GetCellAbsId(iDig);
870 fraction = clu->GetCellAmplitudeFraction(iDig);
871 //printf("a Cell %d, id, %d, amp %f, fraction %f\n",iDig,cellAbsId,cells->GetCellAmplitude(cellAbsId),fraction);
872 if(fraction < 1e-4) fraction = 1.; // in case unfolding is off
873 geom->GetCellIndex(cellAbsId,iSupMod,iTower,iIphi,iIeta);
874 geom->GetCellPhiEtaIndexInSModule(iSupMod,iTower,iIphi, iIeta,iphi,ieta);
879 else if(iSupMod0!=iSupMod)
882 //printf("AliEMCALRecoUtils::GetMaxEnergyCell() - SHARED CLUSTER\n");
884 if(!fCellsRecalibrated && IsRecalibrationOn())
886 recalFactor = GetEMCALChannelRecalibrationFactor(iSupMod,ieta,iphi);
888 eCell = cells->GetCellAmplitude(cellAbsId)*fraction*recalFactor;
889 //printf("b Cell %d, id, %d, amp %f, fraction %f\n",iDig,cellAbsId,eCell,fraction);
894 //printf("\t new max: cell %d, e %f, ecell %f\n",maxId, eMax,eCell);
898 //Get from the absid the supermodule, tower and eta/phi numbers
899 geom->GetCellIndex(absId,iSupMod,iTower,iIphi,iIeta);
900 //Gives SuperModule and Tower numbers
901 geom->GetCellPhiEtaIndexInSModule(iSupMod,iTower,
902 iIphi, iIeta,iphi,ieta);
903 //printf("Max id %d, iSM %d, col %d, row %d\n",absId,iSupMod,ieta,iphi);
904 //printf("Max end---\n");
907 //______________________________________
908 void AliEMCALRecoUtils::InitParameters()
910 // Initialize data members with default values
912 fParticleType = kPhoton;
913 fPosAlgo = kUnchanged;
916 fNonLinearityFunction = kNoCorrection;
917 fNonLinearThreshold = 30;
919 fExoticCellFraction = 0.97;
920 fExoticCellDiffTime = 1e6;
921 fExoticCellMinAmplitude = 0.5;
925 fCutEtaPhiSum = kTRUE;
926 fCutEtaPhiSeparate = kFALSE;
932 fClusterWindow = 100;
937 fTrackCutsType = kLooseCut;
940 fCutMinNClusterTPC = -1;
941 fCutMinNClusterITS = -1;
943 fCutMaxChi2PerClusterTPC = 1e10;
944 fCutMaxChi2PerClusterITS = 1e10;
946 fCutRequireTPCRefit = kFALSE;
947 fCutRequireITSRefit = kFALSE;
948 fCutAcceptKinkDaughters = kFALSE;
950 fCutMaxDCAToVertexXY = 1e10;
951 fCutMaxDCAToVertexZ = 1e10;
952 fCutDCAToVertex2D = kFALSE;
955 //Misalignment matrices
956 for(Int_t i = 0; i < 15 ; i++)
958 fMisalTransShift[i] = 0.;
959 fMisalRotShift[i] = 0.;
963 for(Int_t i = 0; i < 7 ; i++) fNonLinearityParams[i] = 0.;
965 //For kBeamTestCorrected case, but default is no correction
966 fNonLinearityParams[0] = 0.99078;
967 fNonLinearityParams[1] = 0.161499;
968 fNonLinearityParams[2] = 0.655166;
969 fNonLinearityParams[3] = 0.134101;
970 fNonLinearityParams[4] = 163.282;
971 fNonLinearityParams[5] = 23.6904;
972 fNonLinearityParams[6] = 0.978;
974 //For kPi0GammaGamma case
975 //fNonLinearityParams[0] = 0.1457/0.1349766/1.038;
976 //fNonLinearityParams[1] = -0.02024/0.1349766/1.038;
977 //fNonLinearityParams[2] = 1.046;
979 //Cluster energy smearing
980 fSmearClusterEnergy = kFALSE;
981 fSmearClusterParam[0] = 0.07; // * sqrt E term
982 fSmearClusterParam[1] = 0.00; // * E term
983 fSmearClusterParam[2] = 0.00; // constant
986 //_____________________________________________________
987 void AliEMCALRecoUtils::InitEMCALRecalibrationFactors()
989 //Init EMCAL recalibration factors
990 AliDebug(2,"AliCalorimeterUtils::InitEMCALRecalibrationFactors()");
991 //In order to avoid rewriting the same histograms
992 Bool_t oldStatus = TH1::AddDirectoryStatus();
993 TH1::AddDirectory(kFALSE);
995 fEMCALRecalibrationFactors = new TObjArray(12);
996 for (int i = 0; i < 12; i++)
997 fEMCALRecalibrationFactors->Add(new TH2F(Form("EMCALRecalFactors_SM%d",i),
998 Form("EMCALRecalFactors_SM%d",i), 48, 0, 48, 24, 0, 24));
999 //Init the histograms with 1
1000 for (Int_t sm = 0; sm < 12; sm++)
1002 for (Int_t i = 0; i < 48; i++)
1004 for (Int_t j = 0; j < 24; j++)
1006 SetEMCALChannelRecalibrationFactor(sm,i,j,1.);
1011 fEMCALRecalibrationFactors->SetOwner(kTRUE);
1012 fEMCALRecalibrationFactors->Compress();
1014 //In order to avoid rewriting the same histograms
1015 TH1::AddDirectory(oldStatus);
1018 //_________________________________________________________
1019 void AliEMCALRecoUtils::InitEMCALTimeRecalibrationFactors()
1021 //Init EMCAL recalibration factors
1022 AliDebug(2,"AliCalorimeterUtils::InitEMCALRecalibrationFactors()");
1023 //In order to avoid rewriting the same histograms
1024 Bool_t oldStatus = TH1::AddDirectoryStatus();
1025 TH1::AddDirectory(kFALSE);
1027 fEMCALTimeRecalibrationFactors = new TObjArray(4);
1028 for (int i = 0; i < 4; i++)
1029 fEMCALTimeRecalibrationFactors->Add(new TH1F(Form("hAllTimeAvBC%d",i),
1030 Form("hAllTimeAvBC%d",i),
1031 48*24*12,0.,48*24*12) );
1032 //Init the histograms with 1
1033 for (Int_t bc = 0; bc < 4; bc++)
1035 for (Int_t i = 0; i < 48*24*12; i++)
1036 SetEMCALChannelTimeRecalibrationFactor(bc,i,0.);
1039 fEMCALTimeRecalibrationFactors->SetOwner(kTRUE);
1040 fEMCALTimeRecalibrationFactors->Compress();
1042 //In order to avoid rewriting the same histograms
1043 TH1::AddDirectory(oldStatus);
1046 //____________________________________________________
1047 void AliEMCALRecoUtils::InitEMCALBadChannelStatusMap()
1049 //Init EMCAL bad channels map
1050 AliDebug(2,"AliEMCALRecoUtils::InitEMCALBadChannelStatusMap()");
1051 //In order to avoid rewriting the same histograms
1052 Bool_t oldStatus = TH1::AddDirectoryStatus();
1053 TH1::AddDirectory(kFALSE);
1055 fEMCALBadChannelMap = new TObjArray(12);
1056 //TH2F * hTemp = new TH2I("EMCALBadChannelMap","EMCAL SuperModule bad channel map", 48, 0, 48, 24, 0, 24);
1057 for (int i = 0; i < 12; i++)
1059 fEMCALBadChannelMap->Add(new TH2I(Form("EMCALBadChannelMap_Mod%d",i),Form("EMCALBadChannelMap_Mod%d",i), 48, 0, 48, 24, 0, 24));
1062 fEMCALBadChannelMap->SetOwner(kTRUE);
1063 fEMCALBadChannelMap->Compress();
1065 //In order to avoid rewriting the same histograms
1066 TH1::AddDirectory(oldStatus);
1069 //____________________________________________________________________________
1070 void AliEMCALRecoUtils::RecalibrateClusterEnergy(const AliEMCALGeometry* geom,
1071 AliVCluster * cluster,
1072 AliVCaloCells * cells,
1075 // Recalibrate the cluster energy and Time, considering the recalibration map
1076 // and the energy of the cells and time that compose the cluster.
1077 // bc= bunch crossing number returned by esdevent->GetBunchCrossNumber();
1081 AliInfo("Cluster pointer null!");
1085 //Get the cluster number of cells and list of absId, check what kind of cluster do we have.
1086 UShort_t * index = cluster->GetCellsAbsId() ;
1087 Double_t * fraction = cluster->GetCellsAmplitudeFraction() ;
1088 Int_t ncells = cluster->GetNCells();
1090 //Initialize some used variables
1093 Int_t icol =-1, irow =-1, imod=1;
1094 Float_t factor = 1, frac = 0;
1095 Int_t absIdMax = -1;
1098 //Loop on the cells, get the cell amplitude and recalibration factor, multiply and and to the new energy
1099 for(Int_t icell = 0; icell < ncells; icell++)
1101 absId = index[icell];
1102 frac = fraction[icell];
1103 if(frac < 1e-5) frac = 1; //in case of EMCAL, this is set as 0 since unfolding is off
1105 if(!fCellsRecalibrated && IsRecalibrationOn())
1108 Int_t iTower = -1, iIphi = -1, iIeta = -1;
1109 geom->GetCellIndex(absId,imod,iTower,iIphi,iIeta);
1110 if(fEMCALRecalibrationFactors->GetEntries() <= imod) continue;
1111 geom->GetCellPhiEtaIndexInSModule(imod,iTower,iIphi, iIeta,irow,icol);
1112 factor = GetEMCALChannelRecalibrationFactor(imod,icol,irow);
1114 AliDebug(2,Form("AliEMCALRecoUtils::RecalibrateClusterEnergy - recalibrate cell: module %d, col %d, row %d, cell fraction %f,recalibration factor %f, cell energy %f\n",
1115 imod,icol,irow,frac,factor,cells->GetCellAmplitude(absId)));
1119 energy += cells->GetCellAmplitude(absId)*factor*frac;
1121 if(emax < cells->GetCellAmplitude(absId)*factor*frac)
1123 emax = cells->GetCellAmplitude(absId)*factor*frac;
1128 AliDebug(2,Form("AliEMCALRecoUtils::RecalibrateClusterEnergy - Energy before %f, after %f \n",cluster->E(),energy));
1130 cluster->SetE(energy);
1132 // Recalculate time of cluster
1133 Double_t timeorg = cluster->GetTOF();
1134 if(!fCellsRecalibrated && IsTimeRecalibrationOn())
1136 Double_t time = timeorg;
1137 RecalibrateCellTime(absIdMax,bc,time);
1138 cluster->SetTOF(time);
1141 AliDebug(2,Form("AliEMCALRecoUtils::RecalibrateClusterEnergy - Time before %f, after %f \n",timeorg,cluster->GetTOF()));
1145 //_____________________________________________________________
1146 void AliEMCALRecoUtils::RecalibrateCells(AliVCaloCells * cells,
1149 // Recalibrate the cells time and energy, considering the recalibration map and the energy
1150 // of the cells that compose the cluster.
1151 // bc= bunch crossing number returned by esdevent->GetBunchCrossNumber();
1153 if(!IsRecalibrationOn() && !IsTimeRecalibrationOn()) return;
1157 AliInfo("Cells pointer null!");
1162 Bool_t accept = kFALSE;
1166 Int_t nEMcell = cells->GetNumberOfCells() ;
1167 for (Int_t iCell = 0; iCell < nEMcell; iCell++)
1169 absId = cells->GetCellNumber(iCell);
1171 accept = AcceptCalibrateCell(absId, bc, ecell ,tcell ,cells);
1179 cells->SetCell(iCell,absId,ecell, tcell);
1182 fCellsRecalibrated = kTRUE;
1185 //_______________________________________________________________________________________________________
1186 void AliEMCALRecoUtils::RecalibrateCellTime(const Int_t absId, const Int_t bc, Double_t & celltime) const
1188 // Recalibrate time of cell with absID considering the recalibration map
1189 // bc= bunch crossing number returned by esdevent->GetBunchCrossNumber();
1191 if(!fCellsRecalibrated && IsTimeRecalibrationOn() && bc >= 0)
1193 celltime -= GetEMCALChannelTimeRecalibrationFactor(bc%4,absId)*1.e-9; ;
1197 //______________________________________________________________________________
1198 void AliEMCALRecoUtils::RecalculateClusterPosition(const AliEMCALGeometry *geom,
1199 AliVCaloCells* cells,
1202 //For a given CaloCluster recalculates the position for a given set of misalignment shifts and puts it again in the CaloCluster.
1206 AliInfo("Cluster pointer null!");
1210 if (fPosAlgo==kPosTowerGlobal) RecalculateClusterPositionFromTowerGlobal( geom, cells, clu);
1211 else if(fPosAlgo==kPosTowerIndex) RecalculateClusterPositionFromTowerIndex ( geom, cells, clu);
1212 else AliDebug(2,"Algorithm to recalculate position not selected, do nothing.");
1215 //_____________________________________________________________________________________________
1216 void AliEMCALRecoUtils::RecalculateClusterPositionFromTowerGlobal(const AliEMCALGeometry *geom,
1217 AliVCaloCells* cells,
1220 // For a given CaloCluster recalculates the position for a given set of misalignment shifts and puts it again in the CaloCluster.
1221 // The algorithm is a copy of what is done in AliEMCALRecPoint
1223 Double_t eCell = 0.;
1224 Float_t fraction = 1.;
1225 Float_t recalFactor = 1.;
1228 Int_t iTower = -1, iIphi = -1, iIeta = -1;
1229 Int_t iSupModMax = -1, iSM=-1, iphi = -1, ieta = -1;
1230 Float_t weight = 0., totalWeight=0.;
1231 Float_t newPos[3] = {0,0,0};
1232 Double_t pLocal[3], pGlobal[3];
1233 Bool_t shared = kFALSE;
1235 Float_t clEnergy = clu->E(); //Energy already recalibrated previously
1236 GetMaxEnergyCell(geom, cells, clu, absId, iSupModMax, ieta, iphi,shared);
1237 Double_t depth = GetDepth(clEnergy,fParticleType,iSupModMax) ;
1239 //printf("** Cluster energy %f, ncells %d, depth %f\n",clEnergy,clu->GetNCells(),depth);
1241 for (Int_t iDig=0; iDig< clu->GetNCells(); iDig++)
1243 absId = clu->GetCellAbsId(iDig);
1244 fraction = clu->GetCellAmplitudeFraction(iDig);
1245 if(fraction < 1e-4) fraction = 1.; // in case unfolding is off
1247 if (!fCellsRecalibrated)
1249 geom->GetCellIndex(absId,iSM,iTower,iIphi,iIeta);
1250 geom->GetCellPhiEtaIndexInSModule(iSM,iTower,iIphi, iIeta,iphi,ieta);
1252 if(IsRecalibrationOn())
1254 recalFactor = GetEMCALChannelRecalibrationFactor(iSM,ieta,iphi);
1258 eCell = cells->GetCellAmplitude(absId)*fraction*recalFactor;
1260 weight = GetCellWeight(eCell,clEnergy);
1261 totalWeight += weight;
1263 geom->RelPosCellInSModule(absId,depth,pLocal[0],pLocal[1],pLocal[2]);
1264 //printf("pLocal (%f,%f,%f), SM %d, absId %d\n",pLocal[0],pLocal[1],pLocal[2],iSupModMax,absId);
1265 geom->GetGlobal(pLocal,pGlobal,iSupModMax);
1266 //printf("pLocal (%f,%f,%f)\n",pGlobal[0],pGlobal[1],pGlobal[2]);
1268 for(int i=0; i<3; i++ ) newPos[i] += (weight*pGlobal[i]);
1273 for(int i=0; i<3; i++ ) newPos[i] /= totalWeight;
1276 //Float_t pos[]={0,0,0};
1277 //clu->GetPosition(pos);
1278 //printf("OldPos : %2.3f,%2.3f,%2.3f\n",pos[0],pos[1],pos[2]);
1279 //printf("NewPos : %2.3f,%2.3f,%2.3f\n",newPos[0],newPos[1],newPos[2]);
1281 if(iSupModMax > 1) //sector 1
1283 newPos[0] +=fMisalTransShift[3];//-=3.093;
1284 newPos[1] +=fMisalTransShift[4];//+=6.82;
1285 newPos[2] +=fMisalTransShift[5];//+=1.635;
1286 //printf(" + : %2.3f,%2.3f,%2.3f\n",fMisalTransShift[3],fMisalTransShift[4],fMisalTransShift[5]);
1289 newPos[0] +=fMisalTransShift[0];//+=1.134;
1290 newPos[1] +=fMisalTransShift[1];//+=8.2;
1291 newPos[2] +=fMisalTransShift[2];//+=1.197;
1292 //printf(" + : %2.3f,%2.3f,%2.3f\n",fMisalTransShift[0],fMisalTransShift[1],fMisalTransShift[2]);
1294 //printf("NewPos : %2.3f,%2.3f,%2.3f\n",newPos[0],newPos[1],newPos[2]);
1296 clu->SetPosition(newPos);
1299 //____________________________________________________________________________________________
1300 void AliEMCALRecoUtils::RecalculateClusterPositionFromTowerIndex(const AliEMCALGeometry *geom,
1301 AliVCaloCells* cells,
1304 // For a given CaloCluster recalculates the position for a given set of misalignment shifts and puts it again in the CaloCluster.
1305 // The algorithm works with the tower indeces, averages the indeces and from them it calculates the global position
1307 Double_t eCell = 1.;
1308 Float_t fraction = 1.;
1309 Float_t recalFactor = 1.;
1313 Int_t iIphi = -1, iIeta = -1;
1314 Int_t iSupMod = -1, iSupModMax = -1;
1315 Int_t iphi = -1, ieta =-1;
1316 Bool_t shared = kFALSE;
1318 Float_t clEnergy = clu->E(); //Energy already recalibrated previously.
1319 GetMaxEnergyCell(geom, cells, clu, absId, iSupModMax, ieta, iphi,shared);
1320 Float_t depth = GetDepth(clEnergy,fParticleType,iSupMod) ;
1322 Float_t weight = 0., weightedCol = 0., weightedRow = 0., totalWeight=0.;
1323 Bool_t areInSameSM = kTRUE; //exclude clusters with cells in different SMs for now
1324 Int_t startingSM = -1;
1326 for (Int_t iDig=0; iDig< clu->GetNCells(); iDig++)
1328 absId = clu->GetCellAbsId(iDig);
1329 fraction = clu->GetCellAmplitudeFraction(iDig);
1330 if(fraction < 1e-4) fraction = 1.; // in case unfolding is off
1332 if (iDig==0) startingSM = iSupMod;
1333 else if(iSupMod != startingSM) areInSameSM = kFALSE;
1335 eCell = cells->GetCellAmplitude(absId);
1337 geom->GetCellIndex(absId,iSupMod,iTower,iIphi,iIeta);
1338 geom->GetCellPhiEtaIndexInSModule(iSupMod,iTower,iIphi, iIeta,iphi,ieta);
1340 if (!fCellsRecalibrated)
1342 if(IsRecalibrationOn())
1344 recalFactor = GetEMCALChannelRecalibrationFactor(iSupMod,ieta,iphi);
1348 eCell = cells->GetCellAmplitude(absId)*fraction*recalFactor;
1350 weight = GetCellWeight(eCell,clEnergy);
1351 if(weight < 0) weight = 0;
1352 totalWeight += weight;
1353 weightedCol += ieta*weight;
1354 weightedRow += iphi*weight;
1356 //printf("Max cell? cell %d, amplitude org %f, fraction %f, recalibration %f, amplitude new %f \n",cellAbsId, cells->GetCellAmplitude(cellAbsId), fraction, recalFactor, eCell) ;
1359 Float_t xyzNew[]={0.,0.,0.};
1360 if(areInSameSM == kTRUE)
1362 //printf("In Same SM\n");
1363 weightedCol = weightedCol/totalWeight;
1364 weightedRow = weightedRow/totalWeight;
1365 geom->RecalculateTowerPosition(weightedRow, weightedCol, iSupModMax, depth, fMisalTransShift, fMisalRotShift, xyzNew);
1369 //printf("In Different SM\n");
1370 geom->RecalculateTowerPosition(iphi, ieta, iSupModMax, depth, fMisalTransShift, fMisalRotShift, xyzNew);
1373 clu->SetPosition(xyzNew);
1376 //___________________________________________________________________________________________
1377 void AliEMCALRecoUtils::RecalculateClusterDistanceToBadChannel(const AliEMCALGeometry * geom,
1378 AliVCaloCells* cells,
1379 AliVCluster * cluster)
1381 //re-evaluate distance to bad channel with updated bad map
1383 if(!fRecalDistToBadChannels) return;
1387 AliInfo("Cluster pointer null!");
1391 //Get channels map of the supermodule where the cluster is.
1392 Int_t absIdMax = -1, iSupMod =-1, icolM = -1, irowM = -1;
1393 Bool_t shared = kFALSE;
1394 GetMaxEnergyCell(geom, cells, cluster, absIdMax, iSupMod, icolM, irowM, shared);
1395 TH2D* hMap = (TH2D*)fEMCALBadChannelMap->At(iSupMod);
1398 Float_t minDist = 10000.;
1401 //Loop on tower status map
1402 for(Int_t irow = 0; irow < AliEMCALGeoParams::fgkEMCALRows; irow++)
1404 for(Int_t icol = 0; icol < AliEMCALGeoParams::fgkEMCALCols; icol++)
1406 //Check if tower is bad.
1407 if(hMap->GetBinContent(icol,irow)==0) continue;
1408 //printf("AliEMCALRecoUtils::RecalculateDistanceToBadChannels() - \n \t Bad channel in SM %d, col %d, row %d, \n \t Cluster max in col %d, row %d\n",
1409 // iSupMod,icol, irow, icolM,irowM);
1411 dRrow=TMath::Abs(irowM-irow);
1412 dRcol=TMath::Abs(icolM-icol);
1413 dist=TMath::Sqrt(dRrow*dRrow+dRcol*dRcol);
1416 //printf("MIN DISTANCE TO BAD %2.2f\n",dist);
1422 //In case the cluster is shared by 2 SuperModules, need to check the map of the second Super Module
1426 Int_t iSupMod2 = -1;
1428 //The only possible combinations are (0,1), (2,3) ... (8,9)
1429 if(iSupMod%2) iSupMod2 = iSupMod-1;
1430 else iSupMod2 = iSupMod+1;
1431 hMap2 = (TH2D*)fEMCALBadChannelMap->At(iSupMod2);
1433 //Loop on tower status map of second super module
1434 for(Int_t irow = 0; irow < AliEMCALGeoParams::fgkEMCALRows; irow++)
1436 for(Int_t icol = 0; icol < AliEMCALGeoParams::fgkEMCALCols; icol++)
1438 //Check if tower is bad.
1439 if(hMap2->GetBinContent(icol,irow)==0) continue;
1440 //printf("AliEMCALRecoUtils::RecalculateDistanceToBadChannels(shared) - \n \t Bad channel in SM %d, col %d, row %d \n \t Cluster max in SM %d, col %d, row %d\n",
1441 // iSupMod2,icol, irow,iSupMod,icolM,irowM);
1442 dRrow=TMath::Abs(irow-irowM);
1446 dRcol=TMath::Abs(icol-(AliEMCALGeoParams::fgkEMCALCols+icolM));
1449 dRcol=TMath::Abs(AliEMCALGeoParams::fgkEMCALCols+icol-icolM);
1452 dist=TMath::Sqrt(dRrow*dRrow+dRcol*dRcol);
1453 if(dist < minDist) minDist = dist;
1456 }// shared cluster in 2 SuperModules
1458 AliDebug(2,Form("Max cluster cell (SM,col,row)=(%d %d %d) - Distance to Bad Channel %2.2f",iSupMod, icolM, irowM, minDist));
1459 cluster->SetDistanceToBadChannel(minDist);
1462 //__________________________________________________________________
1463 void AliEMCALRecoUtils::RecalculateClusterPID(AliVCluster * cluster)
1465 //re-evaluate identification parameters with bayesian
1469 AliInfo("Cluster pointer null!");
1473 if ( cluster->GetM02() != 0)
1474 fPIDUtils->ComputePID(cluster->E(),cluster->GetM02());
1476 Float_t pidlist[AliPID::kSPECIESN+1];
1477 for(Int_t i = 0; i < AliPID::kSPECIESN+1; i++) pidlist[i] = fPIDUtils->GetPIDFinal(i);
1479 cluster->SetPID(pidlist);
1482 //___________________________________________________________________________________________________________________
1483 void AliEMCALRecoUtils::RecalculateClusterShowerShapeParameters(const AliEMCALGeometry * geom,
1484 AliVCaloCells* cells,
1485 AliVCluster * cluster,
1486 Float_t & l0, Float_t & l1,
1487 Float_t & disp, Float_t & dEta, Float_t & dPhi,
1488 Float_t & sEta, Float_t & sPhi, Float_t & sEtaPhi)
1490 // Calculates new center of gravity in the local EMCAL-module coordinates
1491 // and tranfers into global ALICE coordinates
1492 // Calculates Dispersion and main axis
1496 AliInfo("Cluster pointer null!");
1500 Double_t eCell = 0.;
1501 Float_t fraction = 1.;
1502 Float_t recalFactor = 1.;
1510 Double_t etai = -1.;
1511 Double_t phii = -1.;
1516 Double_t etaMean = 0.;
1517 Double_t phiMean = 0.;
1520 for(Int_t iDigit=0; iDigit < cluster->GetNCells(); iDigit++)
1522 //Get from the absid the supermodule, tower and eta/phi numbers
1523 geom->GetCellIndex(cluster->GetCellAbsId(iDigit),iSupMod,iTower,iIphi,iIeta);
1524 geom->GetCellPhiEtaIndexInSModule(iSupMod,iTower,iIphi,iIeta, iphi,ieta);
1526 //Get the cell energy, if recalibration is on, apply factors
1527 fraction = cluster->GetCellAmplitudeFraction(iDigit);
1528 if(fraction < 1e-4) fraction = 1.; // in case unfolding is off
1530 if (!fCellsRecalibrated)
1532 if(IsRecalibrationOn())
1534 recalFactor = GetEMCALChannelRecalibrationFactor(iSupMod,ieta,iphi);
1538 eCell = cells->GetCellAmplitude(cluster->GetCellAbsId(iDigit))*fraction*recalFactor;
1540 if(cluster->E() > 0 && eCell > 0)
1542 w = GetCellWeight(eCell,cluster->E());
1544 etai=(Double_t)ieta;
1545 phii=(Double_t)iphi;
1552 sEta += w * etai * etai ;
1553 etaMean += w * etai ;
1554 sPhi += w * phii * phii ;
1555 phiMean += w * phii ;
1556 sEtaPhi += w * etai * phii ;
1560 AliError(Form("Wrong energy %f and/or amplitude %f\n", eCell, cluster->E()));
1563 //Normalize to the weight
1570 AliError(Form("Wrong weight %f\n", wtot));
1572 //Calculate dispersion
1573 for(Int_t iDigit=0; iDigit < cluster->GetNCells(); iDigit++)
1575 //Get from the absid the supermodule, tower and eta/phi numbers
1576 geom->GetCellIndex(cluster->GetCellAbsId(iDigit),iSupMod,iTower,iIphi,iIeta);
1577 geom->GetCellPhiEtaIndexInSModule(iSupMod,iTower,iIphi,iIeta, iphi,ieta);
1579 //Get the cell energy, if recalibration is on, apply factors
1580 fraction = cluster->GetCellAmplitudeFraction(iDigit);
1581 if(fraction < 1e-4) fraction = 1.; // in case unfolding is off
1582 if (IsRecalibrationOn())
1584 recalFactor = GetEMCALChannelRecalibrationFactor(iSupMod,ieta,iphi);
1586 eCell = cells->GetCellAmplitude(cluster->GetCellAbsId(iDigit))*fraction*recalFactor;
1588 if(cluster->E() > 0 && eCell > 0)
1590 w = GetCellWeight(eCell,cluster->E());
1592 etai=(Double_t)ieta;
1593 phii=(Double_t)iphi;
1596 disp += w *((etai-etaMean)*(etai-etaMean)+(phii-phiMean)*(phii-phiMean));
1597 dEta += w * (etai-etaMean)*(etai-etaMean) ;
1598 dPhi += w * (phii-phiMean)*(phii-phiMean) ;
1602 AliError(Form("Wrong energy %f and/or amplitude %f\n", eCell, cluster->E()));
1605 //Normalize to the weigth and set shower shape parameters
1606 if (wtot > 0 && nstat > 1)
1615 sEta -= etaMean * etaMean ;
1616 sPhi -= phiMean * phiMean ;
1617 sEtaPhi -= etaMean * phiMean ;
1619 l0 = (0.5 * (sEta + sPhi) + TMath::Sqrt( 0.25 * (sEta - sPhi) * (sEta - sPhi) + sEtaPhi * sEtaPhi ));
1620 l1 = (0.5 * (sEta + sPhi) - TMath::Sqrt( 0.25 * (sEta - sPhi) * (sEta - sPhi) + sEtaPhi * sEtaPhi ));
1626 dEta = 0. ; dPhi = 0. ; disp = 0. ;
1627 sEta = 0. ; sPhi = 0. ; sEtaPhi = 0. ;
1632 //____________________________________________________________________________________________
1633 void AliEMCALRecoUtils::RecalculateClusterShowerShapeParameters(const AliEMCALGeometry * geom,
1634 AliVCaloCells* cells,
1635 AliVCluster * cluster)
1637 // Calculates new center of gravity in the local EMCAL-module coordinates
1638 // and tranfers into global ALICE coordinates
1639 // Calculates Dispersion and main axis and puts them into the cluster
1641 Float_t l0 = 0., l1 = 0.;
1642 Float_t disp = 0., dEta = 0., dPhi = 0.;
1643 Float_t sEta = 0., sPhi = 0., sEtaPhi = 0.;
1645 AliEMCALRecoUtils::RecalculateClusterShowerShapeParameters(geom,cells,cluster,l0,l1,disp,
1646 dEta, dPhi, sEta, sPhi, sEtaPhi);
1648 cluster->SetM02(l0);
1649 cluster->SetM20(l1);
1650 if(disp > 0. ) cluster->SetDispersion(TMath::Sqrt(disp)) ;
1654 //____________________________________________________________________________
1655 void AliEMCALRecoUtils::FindMatches(AliVEvent *event,
1656 TObjArray * clusterArr,
1657 const AliEMCALGeometry *geom)
1659 //This function should be called before the cluster loop
1660 //Before call this function, please recalculate the cluster positions
1661 //Given the input event, loop over all the tracks, select the closest cluster as matched with fCutR
1662 //Store matched cluster indexes and residuals
1664 fMatchedTrackIndex ->Reset();
1665 fMatchedClusterIndex->Reset();
1666 fResidualPhi->Reset();
1667 fResidualEta->Reset();
1669 fMatchedTrackIndex ->Set(1000);
1670 fMatchedClusterIndex->Set(1000);
1671 fResidualPhi->Set(1000);
1672 fResidualEta->Set(1000);
1674 AliESDEvent* esdevent = dynamic_cast<AliESDEvent*> (event);
1675 AliAODEvent* aodevent = dynamic_cast<AliAODEvent*> (event);
1677 // init the magnetic field if not already on
1678 if(!TGeoGlobalMagField::Instance()->GetField())
1680 AliInfo("Init the magnetic field\n");
1683 esdevent->InitMagneticField();
1687 Double_t curSol = 30000*aodevent->GetMagneticField()/5.00668;
1688 Double_t curDip = 6000 *aodevent->GetMuonMagFieldScale();
1689 AliMagF *field = AliMagF::CreateFieldMap(curSol,curDip);
1690 TGeoGlobalMagField::Instance()->SetField(field);
1694 AliInfo("Mag Field not initialized, null esd/aod evetn pointers");
1699 TObjArray *clusterArray = 0x0;
1702 clusterArray = new TObjArray(event->GetNumberOfCaloClusters());
1703 for(Int_t icl=0; icl<event->GetNumberOfCaloClusters(); icl++)
1705 AliVCluster *cluster = (AliVCluster*) event->GetCaloCluster(icl);
1706 if(geom && !IsGoodCluster(cluster,geom,(AliVCaloCells*)event->GetEMCALCells())) continue;
1707 clusterArray->AddAt(cluster,icl);
1713 for (Int_t i=0; i<21;i++) cv[i]=0;
1714 for(Int_t itr=0; itr<event->GetNumberOfTracks(); itr++)
1716 AliExternalTrackParam *trackParam = 0;
1718 //If the input event is ESD, the starting point for extrapolation is TPCOut, if available, or TPCInner
1719 AliESDtrack *esdTrack = 0;
1720 AliAODTrack *aodTrack = 0;
1723 esdTrack = esdevent->GetTrack(itr);
1724 if(!esdTrack) continue;
1725 if(!IsAccepted(esdTrack)) continue;
1726 if(esdTrack->Pt()<fCutMinTrackPt) continue;
1727 Double_t phi = esdTrack->Phi()*TMath::RadToDeg();
1728 if(TMath::Abs(esdTrack->Eta())>0.8 || phi <= 20 || phi >= 240 ) continue;
1729 trackParam = const_cast<AliExternalTrackParam*>(esdTrack->GetInnerParam());
1732 //If the input event is AOD, the starting point for extrapolation is at vertex
1733 //AOD tracks are selected according to its filterbit.
1736 aodTrack = aodevent->GetTrack(itr);
1737 if(!aodTrack) continue;
1738 if(!aodTrack->TestFilterMask(fAODFilterMask)) continue; //Select AOD tracks that fulfill GetStandardITSTPCTrackCuts2010()
1739 if(aodTrack->Pt()<fCutMinTrackPt) continue;
1740 Double_t phi = aodTrack->Phi()*TMath::RadToDeg();
1741 if(TMath::Abs(aodTrack->Eta())>0.8 || phi <= 20 || phi >= 240 ) continue;
1742 Double_t pos[3],mom[3];
1743 aodTrack->GetXYZ(pos);
1744 aodTrack->GetPxPyPz(mom);
1745 AliDebug(5,Form("aod track: i=%d | pos=(%5.4f,%5.4f,%5.4f) | mom=(%5.4f,%5.4f,%5.4f) | charge=%d\n",itr,pos[0],pos[1],pos[2],mom[0],mom[1],mom[2],aodTrack->Charge()));
1746 trackParam= new AliExternalTrackParam(pos,mom,cv,aodTrack->Charge());
1749 //Return if the input data is not "AOD" or "ESD"
1752 printf("Wrong input data type! Should be \"AOD\" or \"ESD\"\n");
1755 clusterArray->Clear();
1756 delete clusterArray;
1761 if(!trackParam) continue;
1763 //Extrapolate the track to EMCal surface
1764 AliExternalTrackParam emcalParam(*trackParam);
1766 if(!ExtrapolateTrackToEMCalSurface(&emcalParam, 430., fMass, fStepSurface, eta, phi))
1768 if(aodevent && trackParam) delete trackParam;
1774 // esdTrack->SetOuterParam(&emcalParam,AliExternalTrackParam::kMultSec);
1777 if(TMath::Abs(eta)>0.75 || (phi) < 70*TMath::DegToRad() || (phi) > 190*TMath::DegToRad())
1779 if(aodevent && trackParam) delete trackParam;
1784 //Find matched clusters
1786 Float_t dEta = -999, dPhi = -999;
1789 index = FindMatchedClusterInClusterArr(&emcalParam, &emcalParam, clusterArray, dEta, dPhi);
1793 index = FindMatchedClusterInClusterArr(&emcalParam, &emcalParam, clusterArr, dEta, dPhi);
1798 fMatchedTrackIndex ->AddAt(itr,matched);
1799 fMatchedClusterIndex ->AddAt(index,matched);
1800 fResidualEta ->AddAt(dEta,matched);
1801 fResidualPhi ->AddAt(dPhi,matched);
1804 if(aodevent && trackParam) delete trackParam;
1809 clusterArray->Clear();
1810 delete clusterArray;
1813 AliDebug(2,Form("Number of matched pairs = %d !\n",matched));
1815 fMatchedTrackIndex ->Set(matched);
1816 fMatchedClusterIndex ->Set(matched);
1817 fResidualPhi ->Set(matched);
1818 fResidualEta ->Set(matched);
1821 //________________________________________________________________________________
1822 Int_t AliEMCALRecoUtils::FindMatchedClusterInEvent(const AliESDtrack *track,
1823 const AliVEvent *event,
1824 const AliEMCALGeometry *geom,
1825 Float_t &dEta, Float_t &dPhi)
1828 // This function returns the index of matched cluster to input track
1829 // Returns -1 if no match is found
1831 Double_t phiV = track->Phi()*TMath::RadToDeg();
1832 if(TMath::Abs(track->Eta())>0.8 || phiV <= 20 || phiV >= 240 ) return index;
1833 AliExternalTrackParam *trackParam = const_cast<AliExternalTrackParam*>(track->GetInnerParam());
1834 if(!trackParam) return index;
1835 AliExternalTrackParam emcalParam(*trackParam);
1837 if(!ExtrapolateTrackToEMCalSurface(&emcalParam, 430., fMass, fStepSurface, eta, phi)) return index;
1838 if(TMath::Abs(eta)>0.75 || (phi) < 70*TMath::DegToRad() || (phi) > 190*TMath::DegToRad()) return index;
1840 TObjArray *clusterArr = new TObjArray(event->GetNumberOfCaloClusters());
1842 for(Int_t icl=0; icl<event->GetNumberOfCaloClusters(); icl++)
1844 AliVCluster *cluster = (AliVCluster*) event->GetCaloCluster(icl);
1845 if(geom && !IsGoodCluster(cluster,geom,(AliVCaloCells*)event->GetEMCALCells())) continue;
1846 clusterArr->AddAt(cluster,icl);
1849 index = FindMatchedClusterInClusterArr(&emcalParam, &emcalParam, clusterArr, dEta, dPhi);
1850 clusterArr->Clear();
1856 //_______________________________________________________________________________________________
1857 Int_t AliEMCALRecoUtils::FindMatchedClusterInClusterArr(const AliExternalTrackParam *emcalParam,
1858 AliExternalTrackParam *trkParam,
1859 const TObjArray * clusterArr,
1860 Float_t &dEta, Float_t &dPhi)
1862 // Find matched cluster in array
1864 dEta=-999, dPhi=-999;
1865 Float_t dRMax = fCutR, dEtaMax=fCutEta, dPhiMax=fCutPhi;
1867 Float_t tmpEta=-999, tmpPhi=-999;
1869 Double_t exPos[3] = {0.,0.,0.};
1870 if(!emcalParam->GetXYZ(exPos)) return index;
1872 Float_t clsPos[3] = {0.,0.,0.};
1873 for(Int_t icl=0; icl<clusterArr->GetEntriesFast(); icl++)
1875 AliVCluster *cluster = dynamic_cast<AliVCluster*> (clusterArr->At(icl)) ;
1876 if(!cluster || !cluster->IsEMCAL()) continue;
1877 cluster->GetPosition(clsPos);
1878 Double_t dR = TMath::Sqrt(TMath::Power(exPos[0]-clsPos[0],2)+TMath::Power(exPos[1]-clsPos[1],2)+TMath::Power(exPos[2]-clsPos[2],2));
1879 if(dR > fClusterWindow) continue;
1881 AliExternalTrackParam trkPamTmp (*trkParam);//Retrieve the starting point every time before the extrapolation
1882 if(!ExtrapolateTrackToCluster(&trkPamTmp, cluster, fMass, fStepCluster, tmpEta, tmpPhi)) continue;
1885 Float_t tmpR=TMath::Sqrt(tmpEta*tmpEta + tmpPhi*tmpPhi);
1894 else if(fCutEtaPhiSeparate)
1896 if(TMath::Abs(tmpEta)<TMath::Abs(dEtaMax) && TMath::Abs(tmpPhi)<TMath::Abs(dPhiMax))
1905 printf("Error: please specify your cut criteria\n");
1906 printf("To cut on sqrt(dEta^2+dPhi^2), use: SwitchOnCutEtaPhiSum()\n");
1907 printf("To cut on dEta and dPhi separately, use: SwitchOnCutEtaPhiSeparate()\n");
1918 //------------------------------------------------------------------------------------
1919 Bool_t AliEMCALRecoUtils::ExtrapolateTrackToEMCalSurface(AliExternalTrackParam *trkParam,
1920 const Double_t emcalR,
1921 const Double_t mass,
1922 const Double_t step,
1926 //Extrapolate track to EMCAL surface
1928 eta = -999, phi = -999;
1929 if(!trkParam) return kFALSE;
1930 if(!AliTrackerBase::PropagateTrackToBxByBz(trkParam, emcalR, mass, step, kTRUE, 0.8, -1)) return kFALSE;
1931 Double_t trkPos[3] = {0.,0.,0.};
1932 if(!trkParam->GetXYZ(trkPos)) return kFALSE;
1933 TVector3 trkPosVec(trkPos[0],trkPos[1],trkPos[2]);
1934 eta = trkPosVec.Eta();
1935 phi = trkPosVec.Phi();
1937 phi += 2*TMath::Pi();
1942 //-----------------------------------------------------------------------------------
1943 Bool_t AliEMCALRecoUtils::ExtrapolateTrackToPosition(AliExternalTrackParam *trkParam,
1944 const Float_t *clsPos,
1951 //Return the residual by extrapolating a track param to a global position
1955 if(!trkParam) return kFALSE;
1956 Double_t trkPos[3] = {0.,0.,0.};
1957 TVector3 vec(clsPos[0],clsPos[1],clsPos[2]);
1958 Double_t alpha = ((int)(vec.Phi()*TMath::RadToDeg()/20)+0.5)*20*TMath::DegToRad();
1959 vec.RotateZ(-alpha); //Rotate the cluster to the local extrapolation coordinate system
1960 if(!AliTrackerBase::PropagateTrackToBxByBz(trkParam, vec.X(), mass, step,kTRUE, 0.8, -1)) return kFALSE;
1961 if(!trkParam->GetXYZ(trkPos)) return kFALSE; //Get the extrapolated global position
1963 TVector3 clsPosVec(clsPos[0],clsPos[1],clsPos[2]);
1964 TVector3 trkPosVec(trkPos[0],trkPos[1],trkPos[2]);
1966 // track cluster matching
1967 tmpPhi = clsPosVec.DeltaPhi(trkPosVec); // tmpPhi is between -pi and pi
1968 tmpEta = clsPosVec.Eta()-trkPosVec.Eta();
1973 //----------------------------------------------------------------------------------
1974 Bool_t AliEMCALRecoUtils::ExtrapolateTrackToCluster(AliExternalTrackParam *trkParam,
1975 const AliVCluster *cluster,
1976 const Double_t mass,
1977 const Double_t step,
1982 //Return the residual by extrapolating a track param to a cluster
1986 if(!cluster || !trkParam) return kFALSE;
1988 Float_t clsPos[3] = {0.,0.,0.};
1989 cluster->GetPosition(clsPos);
1991 return ExtrapolateTrackToPosition(trkParam, clsPos, mass, step, tmpEta, tmpPhi);
1994 //---------------------------------------------------------------------------------
1995 Bool_t AliEMCALRecoUtils::ExtrapolateTrackToCluster(AliExternalTrackParam *trkParam,
1996 const AliVCluster *cluster,
2001 //Return the residual by extrapolating a track param to a clusterfStepCluster
2004 return ExtrapolateTrackToCluster(trkParam, cluster, fMass, fStepCluster, tmpEta, tmpPhi);
2007 //_______________________________________________________________________
2008 void AliEMCALRecoUtils::GetMatchedResiduals(const Int_t clsIndex,
2009 Float_t &dEta, Float_t &dPhi)
2011 //Given a cluster index as in AliESDEvent::GetCaloCluster(clsIndex)
2012 //Get the residuals dEta and dPhi for this cluster to the closest track
2013 //Works with ESDs and AODs
2015 if( FindMatchedPosForCluster(clsIndex) >= 999 )
2017 AliDebug(2,"No matched tracks found!\n");
2022 dEta = fResidualEta->At(FindMatchedPosForCluster(clsIndex));
2023 dPhi = fResidualPhi->At(FindMatchedPosForCluster(clsIndex));
2026 //______________________________________________________________________________________________
2027 void AliEMCALRecoUtils::GetMatchedClusterResiduals(Int_t trkIndex, Float_t &dEta, Float_t &dPhi)
2029 //Given a track index as in AliESDEvent::GetTrack(trkIndex)
2030 //Get the residuals dEta and dPhi for this track to the closest cluster
2031 //Works with ESDs and AODs
2033 if( FindMatchedPosForTrack(trkIndex) >= 999 )
2035 AliDebug(2,"No matched cluster found!\n");
2040 dEta = fResidualEta->At(FindMatchedPosForTrack(trkIndex));
2041 dPhi = fResidualPhi->At(FindMatchedPosForTrack(trkIndex));
2044 //__________________________________________________________
2045 Int_t AliEMCALRecoUtils::GetMatchedTrackIndex(Int_t clsIndex)
2047 //Given a cluster index as in AliESDEvent::GetCaloCluster(clsIndex)
2048 //Get the index of matched track to this cluster
2049 //Works with ESDs and AODs
2051 if(IsClusterMatched(clsIndex))
2052 return fMatchedTrackIndex->At(FindMatchedPosForCluster(clsIndex));
2057 //__________________________________________________________
2058 Int_t AliEMCALRecoUtils::GetMatchedClusterIndex(Int_t trkIndex)
2060 //Given a track index as in AliESDEvent::GetTrack(trkIndex)
2061 //Get the index of matched cluster to this track
2062 //Works with ESDs and AODs
2064 if(IsTrackMatched(trkIndex))
2065 return fMatchedClusterIndex->At(FindMatchedPosForTrack(trkIndex));
2070 //______________________________________________________________
2071 Bool_t AliEMCALRecoUtils::IsClusterMatched(Int_t clsIndex) const
2073 //Given a cluster index as in AliESDEvent::GetCaloCluster(clsIndex)
2074 //Returns if the cluster has a match
2075 if(FindMatchedPosForCluster(clsIndex) < 999)
2081 //____________________________________________________________
2082 Bool_t AliEMCALRecoUtils::IsTrackMatched(Int_t trkIndex) const
2084 //Given a track index as in AliESDEvent::GetTrack(trkIndex)
2085 //Returns if the track has a match
2086 if(FindMatchedPosForTrack(trkIndex) < 999)
2092 //______________________________________________________________________
2093 UInt_t AliEMCALRecoUtils::FindMatchedPosForCluster(Int_t clsIndex) const
2095 //Given a cluster index as in AliESDEvent::GetCaloCluster(clsIndex)
2096 //Returns the position of the match in the fMatchedClusterIndex array
2097 Float_t tmpR = fCutR;
2100 for(Int_t i=0; i<fMatchedClusterIndex->GetSize(); i++)
2102 if(fMatchedClusterIndex->At(i)==clsIndex)
2104 Float_t r = TMath::Sqrt(fResidualEta->At(i)*fResidualEta->At(i) + fResidualPhi->At(i)*fResidualPhi->At(i));
2109 AliDebug(3,Form("Matched cluster index: index: %d, dEta: %2.4f, dPhi: %2.4f.\n",
2110 fMatchedClusterIndex->At(i),fResidualEta->At(i),fResidualPhi->At(i)));
2117 //____________________________________________________________________
2118 UInt_t AliEMCALRecoUtils::FindMatchedPosForTrack(Int_t trkIndex) const
2120 //Given a track index as in AliESDEvent::GetTrack(trkIndex)
2121 //Returns the position of the match in the fMatchedTrackIndex array
2122 Float_t tmpR = fCutR;
2125 for(Int_t i=0; i<fMatchedTrackIndex->GetSize(); i++)
2127 if(fMatchedTrackIndex->At(i)==trkIndex)
2129 Float_t r = TMath::Sqrt(fResidualEta->At(i)*fResidualEta->At(i) + fResidualPhi->At(i)*fResidualPhi->At(i));
2134 AliDebug(3,Form("Matched track index: index: %d, dEta: %2.4f, dPhi: %2.4f.\n",
2135 fMatchedTrackIndex->At(i),fResidualEta->At(i),fResidualPhi->At(i)));
2142 //__________________________________________________________________________
2143 Bool_t AliEMCALRecoUtils::IsGoodCluster(AliVCluster *cluster,
2144 const AliEMCALGeometry *geom,
2145 AliVCaloCells* cells,const Int_t bc)
2147 // check if the cluster survives some quality cut
2150 Bool_t isGood=kTRUE;
2152 if(!cluster || !cluster->IsEMCAL()) return kFALSE;
2154 if(ClusterContainsBadChannel(geom,cluster->GetCellsAbsId(),cluster->GetNCells())) return kFALSE;
2156 if(!CheckCellFiducialRegion(geom,cluster,cells)) return kFALSE;
2158 if(IsExoticCluster(cluster, cells,bc)) return kFALSE;
2163 //__________________________________________________________
2164 Bool_t AliEMCALRecoUtils::IsAccepted(AliESDtrack *esdTrack)
2166 // Given a esd track, return whether the track survive all the cuts
2168 // The different quality parameter are first
2169 // retrieved from the track. then it is found out what cuts the
2170 // track did not survive and finally the cuts are imposed.
2172 UInt_t status = esdTrack->GetStatus();
2174 Int_t nClustersITS = esdTrack->GetITSclusters(0);
2175 Int_t nClustersTPC = esdTrack->GetTPCclusters(0);
2177 Float_t chi2PerClusterITS = -1;
2178 Float_t chi2PerClusterTPC = -1;
2179 if (nClustersITS!=0)
2180 chi2PerClusterITS = esdTrack->GetITSchi2()/Float_t(nClustersITS);
2181 if (nClustersTPC!=0)
2182 chi2PerClusterTPC = esdTrack->GetTPCchi2()/Float_t(nClustersTPC);
2186 if(fTrackCutsType==kGlobalCut)
2188 Float_t maxDCAToVertexXYPtDep = 0.0182 + 0.0350/TMath::Power(esdTrack->Pt(),1.01); //This expression comes from AliESDtrackCuts::GetStandardITSTPCTrackCuts2010()
2189 //AliDebug(3,Form("Track pT = %f, DCAtoVertexXY = %f",esdTrack->Pt(),MaxDCAToVertexXYPtDep));
2190 SetMaxDCAToVertexXY(maxDCAToVertexXYPtDep); //Set pT dependent DCA cut to vertex in x-y plane
2196 esdTrack->GetImpactParameters(b,bCov);
2197 if (bCov[0]<=0 || bCov[2]<=0)
2199 AliDebug(1, "Estimated b resolution lower or equal zero!");
2200 bCov[0]=0; bCov[2]=0;
2203 Float_t dcaToVertexXY = b[0];
2204 Float_t dcaToVertexZ = b[1];
2205 Float_t dcaToVertex = -1;
2207 if (fCutDCAToVertex2D)
2208 dcaToVertex = TMath::Sqrt(dcaToVertexXY*dcaToVertexXY/fCutMaxDCAToVertexXY/fCutMaxDCAToVertexXY + dcaToVertexZ*dcaToVertexZ/fCutMaxDCAToVertexZ/fCutMaxDCAToVertexZ);
2210 dcaToVertex = TMath::Sqrt(dcaToVertexXY*dcaToVertexXY + dcaToVertexZ*dcaToVertexZ);
2214 Bool_t cuts[kNCuts];
2215 for (Int_t i=0; i<kNCuts; i++) cuts[i]=kFALSE;
2217 // track quality cuts
2218 if (fCutRequireTPCRefit && (status&AliESDtrack::kTPCrefit)==0)
2220 if (fCutRequireITSRefit && (status&AliESDtrack::kITSrefit)==0)
2222 if (nClustersTPC<fCutMinNClusterTPC)
2224 if (nClustersITS<fCutMinNClusterITS)
2226 if (chi2PerClusterTPC>fCutMaxChi2PerClusterTPC)
2228 if (chi2PerClusterITS>fCutMaxChi2PerClusterITS)
2230 if (!fCutAcceptKinkDaughters && esdTrack->GetKinkIndex(0)>0)
2232 if (fCutDCAToVertex2D && dcaToVertex > 1)
2234 if (!fCutDCAToVertex2D && TMath::Abs(dcaToVertexXY) > fCutMaxDCAToVertexXY)
2236 if (!fCutDCAToVertex2D && TMath::Abs(dcaToVertexZ) > fCutMaxDCAToVertexZ)
2239 if(fTrackCutsType==kGlobalCut)
2241 //Require at least one SPD point + anything else in ITS
2242 if( (esdTrack->HasPointOnITSLayer(0) || esdTrack->HasPointOnITSLayer(1)) == kFALSE)
2247 for (Int_t i=0; i<kNCuts; i++)
2248 if (cuts[i]) { cut = kTRUE ; }
2257 //_____________________________________
2258 void AliEMCALRecoUtils::InitTrackCuts()
2260 //Intilize the track cut criteria
2261 //By default these cuts are set according to AliESDtrackCuts::GetStandardTPCOnlyTrackCuts()
2262 //Also you can customize the cuts using the setters
2264 switch (fTrackCutsType)
2268 AliInfo(Form("Track cuts for matching: GetStandardTPCOnlyTrackCuts()"));
2270 SetMinNClustersTPC(70);
2271 SetMaxChi2PerClusterTPC(4);
2272 SetAcceptKinkDaughters(kFALSE);
2273 SetRequireTPCRefit(kFALSE);
2276 SetRequireITSRefit(kFALSE);
2277 SetMaxDCAToVertexZ(3.2);
2278 SetMaxDCAToVertexXY(2.4);
2279 SetDCAToVertex2D(kTRUE);
2286 AliInfo(Form("Track cuts for matching: GetStandardITSTPCTrackCuts2010(kTURE)"));
2288 SetMinNClustersTPC(70);
2289 SetMaxChi2PerClusterTPC(4);
2290 SetAcceptKinkDaughters(kFALSE);
2291 SetRequireTPCRefit(kTRUE);
2294 SetRequireITSRefit(kTRUE);
2295 SetMaxDCAToVertexZ(2);
2296 SetMaxDCAToVertexXY();
2297 SetDCAToVertex2D(kFALSE);
2304 AliInfo(Form("Track cuts for matching: Loose cut w/o DCA cut"));
2305 SetMinNClustersTPC(50);
2306 SetAcceptKinkDaughters(kTRUE);
2314 //________________________________________________________________________
2315 void AliEMCALRecoUtils::SetClusterMatchedToTrack(const AliVEvent *event)
2317 // Checks if tracks are matched to EMC clusters and set the matched EMCAL cluster index to ESD track.
2319 Int_t nTracks = event->GetNumberOfTracks();
2320 for (Int_t iTrack = 0; iTrack < nTracks; ++iTrack)
2322 AliVTrack* track = dynamic_cast<AliVTrack*>(event->GetTrack(iTrack));
2325 AliWarning(Form("Could not receive track %d", iTrack));
2329 Int_t matchClusIndex = GetMatchedClusterIndex(iTrack);
2330 track->SetEMCALcluster(matchClusIndex); //sets -1 if track not matched within residual
2331 /*the following can be done better if AliVTrack::SetStatus will be there. Patch pending with Andreas/Peter*/
2332 AliESDtrack* esdtrack = dynamic_cast<AliESDtrack*>(track);
2334 if(matchClusIndex != -1)
2335 esdtrack->SetStatus(AliESDtrack::kEMCALmatch);
2337 esdtrack->ResetStatus(AliESDtrack::kEMCALmatch);
2339 AliAODTrack* aodtrack = dynamic_cast<AliAODTrack*>(track);
2340 if(matchClusIndex != -1)
2341 aodtrack->SetStatus(AliESDtrack::kEMCALmatch);
2343 aodtrack->ResetStatus(AliESDtrack::kEMCALmatch);
2347 AliDebug(2,"Track matched to closest cluster");
2350 //_________________________________________________________________________
2351 void AliEMCALRecoUtils::SetTracksMatchedToCluster(const AliVEvent *event)
2353 // Checks if EMC clusters are matched to ESD track.
2354 // Adds track indexes of all the tracks matched to a cluster withing residuals in ESDCalocluster.
2356 for (Int_t iClus=0; iClus < event->GetNumberOfCaloClusters(); ++iClus)
2358 AliVCluster *cluster = event->GetCaloCluster(iClus);
2359 if (!cluster->IsEMCAL())
2362 Int_t nTracks = event->GetNumberOfTracks();
2363 TArrayI arrayTrackMatched(nTracks);
2365 // Get the closest track matched to the cluster
2367 Int_t matchTrackIndex = GetMatchedTrackIndex(iClus);
2368 if (matchTrackIndex != -1)
2370 arrayTrackMatched[nMatched] = matchTrackIndex;
2374 // Get all other tracks matched to the cluster
2375 for(Int_t iTrk=0; iTrk<nTracks; ++iTrk)
2377 AliVTrack* track = dynamic_cast<AliVTrack*>(event->GetTrack(iTrk));
2378 if(iTrk == matchTrackIndex) continue;
2379 if(track->GetEMCALcluster() == iClus)
2381 arrayTrackMatched[nMatched] = iTrk;
2386 //printf("Tender::SetTracksMatchedToCluster - cluster E %f, N matches %d, first match %d\n",cluster->E(),nMatched,arrayTrackMatched[0]);
2388 arrayTrackMatched.Set(nMatched);
2389 AliESDCaloCluster *esdcluster = dynamic_cast<AliESDCaloCluster*>(cluster);
2391 esdcluster->AddTracksMatched(arrayTrackMatched);
2392 else if (nMatched>0) {
2393 AliAODCaloCluster *aodcluster = dynamic_cast<AliAODCaloCluster*>(cluster);
2395 aodcluster->AddTrackMatched(event->GetTrack(arrayTrackMatched.At(0)));
2398 Float_t eta= -999, phi = -999;
2399 if (matchTrackIndex != -1)
2400 GetMatchedResiduals(iClus, eta, phi);
2401 cluster->SetTrackDistance(phi, eta);
2404 AliDebug(2,"Cluster matched to tracks");
2408 //___________________________________________________
2409 void AliEMCALRecoUtils::Print(const Option_t *) const
2413 printf("AliEMCALRecoUtils Settings: \n");
2414 printf("Misalignment shifts\n");
2415 for(Int_t i=0; i<5; i++) printf("\t sector %d, traslation (x,y,z)=(%f,%f,%f), rotation (x,y,z)=(%f,%f,%f)\n",i,
2416 fMisalTransShift[i*3],fMisalTransShift[i*3+1],fMisalTransShift[i*3+2],
2417 fMisalRotShift[i*3], fMisalRotShift[i*3+1], fMisalRotShift[i*3+2] );
2418 printf("Non linearity function %d, parameters:\n", fNonLinearityFunction);
2419 for(Int_t i=0; i<6; i++) printf("param[%d]=%f\n",i, fNonLinearityParams[i]);
2421 printf("Position Recalculation option %d, Particle Type %d, fW0 %2.2f, Recalibrate Data %d \n",fPosAlgo,fParticleType,fW0, fRecalibration);
2423 printf("Matching criteria: ");
2426 printf("sqrt(dEta^2+dPhi^2)<%4.3f\n",fCutR);
2428 else if(fCutEtaPhiSeparate)
2430 printf("dEta<%4.3f, dPhi<%4.3f\n",fCutEta,fCutPhi);
2435 printf("please specify your cut criteria\n");
2436 printf("To cut on sqrt(dEta^2+dPhi^2), use: SwitchOnCutEtaPhiSum()\n");
2437 printf("To cut on dEta and dPhi separately, use: SwitchOnCutEtaPhiSeparate()\n");
2440 printf("Mass hypothesis = %2.3f [GeV/c^2], extrapolation step to surface = %2.2f[cm], step to cluster = %2.2f[cm]\n",fMass,fStepSurface, fStepCluster);
2441 printf("Cluster selection window: dR < %2.0f\n",fClusterWindow);
2443 printf("Track cuts: \n");
2444 printf("Minimum track pT: %1.2f\n",fCutMinTrackPt);
2445 printf("AOD track selection mask: %d\n",fAODFilterMask);
2446 printf("TPCRefit = %d, ITSRefit = %d\n",fCutRequireTPCRefit,fCutRequireITSRefit);
2447 printf("AcceptKinks = %d\n",fCutAcceptKinkDaughters);
2448 printf("MinNCulsterTPC = %d, MinNClusterITS = %d\n",fCutMinNClusterTPC,fCutMinNClusterITS);
2449 printf("MaxChi2TPC = %2.2f, MaxChi2ITS = %2.2f\n",fCutMaxChi2PerClusterTPC,fCutMaxChi2PerClusterITS);
2450 printf("DCSToVertex2D = %d, MaxDCAToVertexXY = %2.2f, MaxDCAToVertexZ = %2.2f\n",fCutDCAToVertex2D,fCutMaxDCAToVertexXY,fCutMaxDCAToVertexZ);
2453 //_________________________________________________________________
2454 void AliEMCALRecoUtils::SetRunDependentCorrections(Int_t runnumber)
2456 //Get EMCAL time dependent corrections from file and put them in the recalibration histograms
2457 //Do it only once and only if it is requested
2459 if(!fUseRunCorrectionFactors) return;
2460 if(fRunCorrectionFactorsSet) return;
2462 AliInfo(Form("AliEMCALRecoUtils::GetRunDependentCorrections() - Get Correction Factors for Run number %d\n",runnumber));
2464 AliEMCALCalibTimeDepCorrection *corr = new AliEMCALCalibTimeDepCorrection();
2465 corr->ReadRootInfo(Form("CorrectionFiles/Run%d_Correction.root",runnumber));
2467 SwitchOnRecalibration();
2469 AliEMCALGeometry* geom = AliEMCALGeometry::GetInstance();
2471 for(Int_t ism = 0; ism < geom->GetNumberOfSuperModules(); ism++)
2473 for(Int_t icol = 0; icol < 48; icol++)
2475 for(Int_t irow = 0; irow < 24; irow++)
2477 Float_t orgRecalFactor = GetEMCALChannelRecalibrationFactors(ism)->GetBinContent(icol,irow);
2478 Float_t newRecalFactor = orgRecalFactor*corr->GetCorrection(ism, icol,irow,0);
2479 GetEMCALChannelRecalibrationFactors(ism)->SetBinContent(icol,irow,newRecalFactor);
2480 //printf("ism %d, icol %d, irow %d, corrections : org %f, time dep %f, final %f (org*time %f)\n",ism, icol, irow,
2481 // orgRecalFactor, corr->GetCorrection(ism, icol,irow,0),
2482 // (GetEMCALChannelRecalibrationFactors(ism))->GetBinContent(icol,irow),newRecalFactor);
2487 fRunCorrectionFactorsSet = kTRUE;