]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EMCAL/AliEMCALRecoUtils.cxx
Adding parameters for LHC13f muon_pass2 (Diego)
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALRecoUtils.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 /* $Id: AliEMCALRecoUtils.cxx 33808 2009-07-15 09:48:08Z gconesab $ */
17
18 ///////////////////////////////////////////////////////////////////////////////
19 //
20 // Class AliEMCALRecoUtils
21 // Some utilities to recalculate the cluster position or energy linearity
22 //
23 //
24 // Author:  Gustavo Conesa (LPSC- Grenoble) 
25 //          Track matching part: Rongrong Ma (Yale)
26
27 ///////////////////////////////////////////////////////////////////////////////
28 // --- standard c ---
29
30 // standard C++ includes
31 //#include <Riostream.h>
32
33 // ROOT includes
34 #include <TGeoManager.h>
35 #include <TGeoMatrix.h>
36 #include <TGeoBBox.h>
37 #include <TH2F.h>
38 #include <TArrayI.h>
39 #include <TArrayF.h>
40 #include <TObjArray.h>
41
42 // STEER includes
43 #include "AliVCluster.h"
44 #include "AliVCaloCells.h"
45 #include "AliLog.h"
46 #include "AliPID.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"
54
55 // EMCAL includes
56 #include "AliEMCALRecoUtils.h"
57 #include "AliEMCALGeometry.h"
58 #include "AliTrackerBase.h"
59 #include "AliEMCALPIDUtils.h"
60
61 ClassImp(AliEMCALRecoUtils)
62   
63 //_____________________________________
64 AliEMCALRecoUtils::AliEMCALRecoUtils():
65   fParticleType(0),                       fPosAlgo(0),                            fW0(0), 
66   fNonLinearityFunction(0),               fNonLinearThreshold(0),
67   fSmearClusterEnergy(kFALSE),            fRandom(),
68   fCellsRecalibrated(kFALSE),             fRecalibration(kFALSE),                 fEMCALRecalibrationFactors(),
69   fTimeRecalibration(kFALSE),             fEMCALTimeRecalibrationFactors(),       fUseRunCorrectionFactors(kFALSE),       
70   fRemoveBadChannels(kFALSE),             fRecalDistToBadChannels(kFALSE),        fEMCALBadChannelMap(),
71   fNCellsFromEMCALBorder(0),              fNoEMCALBorderAtEta0(kTRUE),
72   fRejectExoticCluster(kFALSE),           fRejectExoticCells(kFALSE), 
73   fExoticCellFraction(0),                 fExoticCellDiffTime(0),                 fExoticCellMinAmplitude(0),
74   fPIDUtils(),                            fAODFilterMask(0),
75   fAODHybridTracks(0),                    fAODTPCOnlyTracks(0),
76   fMatchedTrackIndex(0x0),                fMatchedClusterIndex(0x0), 
77   fResidualEta(0x0), fResidualPhi(0x0),   fCutEtaPhiSum(kFALSE),                  fCutEtaPhiSeparate(kFALSE), 
78   fCutR(0),                               fCutEta(0),                             fCutPhi(0),
79   fClusterWindow(0),                      fMass(0),                           
80   fStepSurface(0),                        fStepCluster(0),
81   fITSTrackSA(kFALSE),                    fEMCalSurfaceDistance(430.),
82   fTrackCutsType(0),                      fCutMinTrackPt(0),                      fCutMinNClusterTPC(0), 
83   fCutMinNClusterITS(0),                  fCutMaxChi2PerClusterTPC(0),            fCutMaxChi2PerClusterITS(0),
84   fCutRequireTPCRefit(kFALSE),            fCutRequireITSRefit(kFALSE),            fCutAcceptKinkDaughters(kFALSE),
85   fCutMaxDCAToVertexXY(0),                fCutMaxDCAToVertexZ(0),                 fCutDCAToVertex2D(kFALSE),
86   fCutRequireITSStandAlone(kFALSE),       fCutRequireITSpureSA(kFALSE) 
87 {
88 //
89   // Constructor.
90   // Initialize all constant values which have to be used
91   // during Reco algorithm execution
92   //
93   
94   // Init parameters
95   InitParameters();
96   
97   //Track matching
98   fMatchedTrackIndex     = new TArrayI();
99   fMatchedClusterIndex   = new TArrayI();
100   fResidualPhi           = new TArrayF();
101   fResidualEta           = new TArrayF();
102   fPIDUtils              = new AliEMCALPIDUtils();
103
104 }
105
106 //______________________________________________________________________
107 AliEMCALRecoUtils::AliEMCALRecoUtils(const AliEMCALRecoUtils & reco) 
108 : TNamed(reco), 
109   fParticleType(reco.fParticleType),                         fPosAlgo(reco.fPosAlgo),     fW0(reco.fW0),
110   fNonLinearityFunction(reco.fNonLinearityFunction),         fNonLinearThreshold(reco.fNonLinearThreshold),
111   fSmearClusterEnergy(reco.fSmearClusterEnergy),             fRandom(),
112   fCellsRecalibrated(reco.fCellsRecalibrated),
113   fRecalibration(reco.fRecalibration),                       fEMCALRecalibrationFactors(reco.fEMCALRecalibrationFactors),
114   fTimeRecalibration(reco.fTimeRecalibration),               fEMCALTimeRecalibrationFactors(reco.fEMCALTimeRecalibrationFactors),
115   fUseRunCorrectionFactors(reco.fUseRunCorrectionFactors),   
116   fRemoveBadChannels(reco.fRemoveBadChannels),               fRecalDistToBadChannels(reco.fRecalDistToBadChannels),
117   fEMCALBadChannelMap(reco.fEMCALBadChannelMap),
118   fNCellsFromEMCALBorder(reco.fNCellsFromEMCALBorder),       fNoEMCALBorderAtEta0(reco.fNoEMCALBorderAtEta0),
119   fRejectExoticCluster(reco.fRejectExoticCluster),           fRejectExoticCells(reco.fRejectExoticCells), 
120   fExoticCellFraction(reco.fExoticCellFraction),             fExoticCellDiffTime(reco.fExoticCellDiffTime),               
121   fExoticCellMinAmplitude(reco.fExoticCellMinAmplitude),
122   fPIDUtils(reco.fPIDUtils),                                 fAODFilterMask(reco.fAODFilterMask),
123   fAODHybridTracks(reco.fAODHybridTracks),                   fAODTPCOnlyTracks(reco.fAODTPCOnlyTracks),
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   fITSTrackSA(reco.fITSTrackSA),                             fEMCalSurfaceDistance(430.),
133   fTrackCutsType(reco.fTrackCutsType),                       fCutMinTrackPt(reco.fCutMinTrackPt), 
134   fCutMinNClusterTPC(reco.fCutMinNClusterTPC),               fCutMinNClusterITS(reco.fCutMinNClusterITS), 
135   fCutMaxChi2PerClusterTPC(reco.fCutMaxChi2PerClusterTPC),   fCutMaxChi2PerClusterITS(reco.fCutMaxChi2PerClusterITS),
136   fCutRequireTPCRefit(reco.fCutRequireTPCRefit),             fCutRequireITSRefit(reco.fCutRequireITSRefit),
137   fCutAcceptKinkDaughters(reco.fCutAcceptKinkDaughters),     fCutMaxDCAToVertexXY(reco.fCutMaxDCAToVertexXY),    
138   fCutMaxDCAToVertexZ(reco.fCutMaxDCAToVertexZ),             fCutDCAToVertex2D(reco.fCutDCAToVertex2D),
139   fCutRequireITSStandAlone(reco.fCutRequireITSStandAlone),   fCutRequireITSpureSA(reco.fCutRequireITSpureSA) 
140 {
141   //Copy ctor
142   
143   for(Int_t i = 0; i < 15 ; i++) { fMisalRotShift[i]      = reco.fMisalRotShift[i]      ; 
144                                    fMisalTransShift[i]    = reco.fMisalTransShift[i]    ; } 
145   for(Int_t i = 0; i < 7  ; i++) { fNonLinearityParams[i] = reco.fNonLinearityParams[i] ; }
146   for(Int_t i = 0; i < 3  ; i++) { fSmearClusterParam[i]  = reco.fSmearClusterParam[i]  ; }
147
148 }
149
150
151 //______________________________________________________________________
152 AliEMCALRecoUtils & AliEMCALRecoUtils::operator = (const AliEMCALRecoUtils & reco) 
153 {
154   //Assignment operator
155   
156   if(this == &reco)return *this;
157   ((TNamed *)this)->operator=(reco);
158
159   for(Int_t i = 0; i < 15 ; i++) { fMisalTransShift[i]    = reco.fMisalTransShift[i]    ; 
160                                    fMisalRotShift[i]      = reco.fMisalRotShift[i]      ; }
161   for(Int_t i = 0; i < 7  ; i++) { fNonLinearityParams[i] = reco.fNonLinearityParams[i] ; }
162   for(Int_t i = 0; i < 3  ; i++) { fSmearClusterParam[i]  = reco.fSmearClusterParam[i]  ; }   
163   
164   fParticleType              = reco.fParticleType;
165   fPosAlgo                   = reco.fPosAlgo; 
166   fW0                        = reco.fW0;
167   
168   fNonLinearityFunction      = reco.fNonLinearityFunction;
169   fNonLinearThreshold        = reco.fNonLinearThreshold;
170   fSmearClusterEnergy        = reco.fSmearClusterEnergy;
171
172   fCellsRecalibrated         = reco.fCellsRecalibrated;
173   fRecalibration             = reco.fRecalibration;
174   fEMCALRecalibrationFactors = reco.fEMCALRecalibrationFactors;
175
176   fTimeRecalibration             = reco.fTimeRecalibration;
177   fEMCALTimeRecalibrationFactors = reco.fEMCALTimeRecalibrationFactors;
178
179   fUseRunCorrectionFactors   = reco.fUseRunCorrectionFactors;
180   
181   fRemoveBadChannels         = reco.fRemoveBadChannels;
182   fRecalDistToBadChannels    = reco.fRecalDistToBadChannels;
183   fEMCALBadChannelMap        = reco.fEMCALBadChannelMap;
184   
185   fNCellsFromEMCALBorder     = reco.fNCellsFromEMCALBorder;
186   fNoEMCALBorderAtEta0       = reco.fNoEMCALBorderAtEta0;
187   
188   fRejectExoticCluster       = reco.fRejectExoticCluster;           
189   fRejectExoticCells         = reco.fRejectExoticCells; 
190   fExoticCellFraction        = reco.fExoticCellFraction;
191   fExoticCellDiffTime        = reco.fExoticCellDiffTime;              
192   fExoticCellMinAmplitude    = reco.fExoticCellMinAmplitude;
193   
194   fPIDUtils                  = reco.fPIDUtils;
195
196   fAODFilterMask             = reco.fAODFilterMask;
197   fAODHybridTracks           = reco.fAODHybridTracks;
198   fAODTPCOnlyTracks          = reco.fAODTPCOnlyTracks;
199   
200   fCutEtaPhiSum              = reco.fCutEtaPhiSum;
201   fCutEtaPhiSeparate         = reco.fCutEtaPhiSeparate;
202   fCutR                      = reco.fCutR;
203   fCutEta                    = reco.fCutEta;
204   fCutPhi                    = reco.fCutPhi;
205   fClusterWindow             = reco.fClusterWindow;
206   fMass                      = reco.fMass;
207   fStepSurface               = reco.fStepSurface;
208   fStepCluster               = reco.fStepCluster;
209   fITSTrackSA                = reco.fITSTrackSA;
210   fEMCalSurfaceDistance      = reco.fEMCalSurfaceDistance;
211   
212   fTrackCutsType             = reco.fTrackCutsType;
213   fCutMinTrackPt             = reco.fCutMinTrackPt;
214   fCutMinNClusterTPC         = reco.fCutMinNClusterTPC;
215   fCutMinNClusterITS         = reco.fCutMinNClusterITS; 
216   fCutMaxChi2PerClusterTPC   = reco.fCutMaxChi2PerClusterTPC;
217   fCutMaxChi2PerClusterITS   = reco.fCutMaxChi2PerClusterITS;
218   fCutRequireTPCRefit        = reco.fCutRequireTPCRefit;
219   fCutRequireITSRefit        = reco.fCutRequireITSRefit;
220   fCutAcceptKinkDaughters    = reco.fCutAcceptKinkDaughters;
221   fCutMaxDCAToVertexXY       = reco.fCutMaxDCAToVertexXY;
222   fCutMaxDCAToVertexZ        = reco.fCutMaxDCAToVertexZ;
223   fCutDCAToVertex2D          = reco.fCutDCAToVertex2D;
224   fCutRequireITSStandAlone   = reco.fCutRequireITSStandAlone; 
225   fCutRequireITSpureSA       = reco.fCutRequireITSpureSA; 
226   if(reco.fResidualEta)
227   {
228     // assign or copy construct
229     if(fResidualEta)
230     { 
231       *fResidualEta = *reco.fResidualEta;
232     }
233     else 
234     {
235       fResidualEta = new TArrayF(*reco.fResidualEta);
236     }
237   }
238   else
239   {
240     if(fResidualEta)delete fResidualEta;
241     fResidualEta = 0;
242   }
243   
244   if(reco.fResidualPhi)
245   {
246     // assign or copy construct
247     if(fResidualPhi)
248     { 
249       *fResidualPhi = *reco.fResidualPhi;
250     }
251     else 
252     {
253       fResidualPhi = new TArrayF(*reco.fResidualPhi);
254     }
255   }
256   else
257   {
258     if(fResidualPhi)delete fResidualPhi;
259     fResidualPhi = 0;
260   }
261   
262   if(reco.fMatchedTrackIndex)
263   {
264     // assign or copy construct
265     if(fMatchedTrackIndex)
266     { 
267       *fMatchedTrackIndex = *reco.fMatchedTrackIndex;
268     }
269     else 
270     { 
271       fMatchedTrackIndex = new TArrayI(*reco.fMatchedTrackIndex);
272     }
273   }
274   else
275   {
276     if(fMatchedTrackIndex)delete fMatchedTrackIndex;
277     fMatchedTrackIndex = 0;
278   }  
279   
280   if(reco.fMatchedClusterIndex)
281   {
282     // assign or copy construct
283     if(fMatchedClusterIndex)
284     { 
285       *fMatchedClusterIndex = *reco.fMatchedClusterIndex;
286     }
287     else 
288     {
289       fMatchedClusterIndex = new TArrayI(*reco.fMatchedClusterIndex);
290     }
291   }
292   else
293   {
294     if(fMatchedClusterIndex)delete fMatchedClusterIndex;
295     fMatchedClusterIndex = 0;
296   }
297    
298   return *this;
299 }
300
301
302 //_____________________________________
303 AliEMCALRecoUtils::~AliEMCALRecoUtils()
304 {
305   //Destructor.
306   
307   if(fEMCALRecalibrationFactors) 
308   { 
309     fEMCALRecalibrationFactors->Clear();
310     delete fEMCALRecalibrationFactors;
311   }  
312   
313   if(fEMCALTimeRecalibrationFactors) 
314   { 
315     fEMCALTimeRecalibrationFactors->Clear();
316     delete fEMCALTimeRecalibrationFactors;
317   }  
318   
319   if(fEMCALBadChannelMap) 
320   { 
321     fEMCALBadChannelMap->Clear();
322     delete fEMCALBadChannelMap;
323   }
324  
325   delete fMatchedTrackIndex   ; 
326   delete fMatchedClusterIndex ; 
327   delete fResidualEta         ; 
328   delete fResidualPhi         ; 
329   delete fPIDUtils            ;
330
331   InitTrackCuts();
332 }
333
334 //_______________________________________________________________________________
335 Bool_t AliEMCALRecoUtils::AcceptCalibrateCell(const Int_t absID, const Int_t bc,
336                                               Float_t  & amp,    Double_t & time, 
337                                               AliVCaloCells* cells) 
338 {
339   // Reject cell if criteria not passed and calibrate it
340   
341   AliEMCALGeometry* geom = AliEMCALGeometry::GetInstance();
342   
343   if(absID < 0 || absID >= 24*48*geom->GetNumberOfSuperModules()) return kFALSE;
344   
345   Int_t imod = -1, iphi =-1, ieta=-1,iTower = -1, iIphi = -1, iIeta = -1; 
346   
347   if(!geom->GetCellIndex(absID,imod,iTower,iIphi,iIeta)) 
348   {
349     // cell absID does not exist
350     amp=0; time = 1.e9;
351     return kFALSE; 
352   }
353   
354   geom->GetCellPhiEtaIndexInSModule(imod,iTower,iIphi, iIeta,iphi,ieta);  
355
356   // Do not include bad channels found in analysis,
357   if( IsBadChannelsRemovalSwitchedOn() && GetEMCALChannelStatus(imod, ieta, iphi)) 
358   {
359     return kFALSE;
360   }
361   
362   //Recalibrate energy
363   amp  = cells->GetCellAmplitude(absID);
364   if(!fCellsRecalibrated && IsRecalibrationOn())
365     amp *= GetEMCALChannelRecalibrationFactor(imod,ieta,iphi);
366   
367   
368   // Recalibrate time
369   time = cells->GetCellTime(absID);
370   
371   RecalibrateCellTime(absID,bc,time);
372   
373   return kTRUE;
374 }
375
376 //_____________________________________________________________________________
377 Bool_t AliEMCALRecoUtils::CheckCellFiducialRegion(const AliEMCALGeometry* geom, 
378                                                   const AliVCluster* cluster, 
379                                                   AliVCaloCells* cells) 
380 {
381   // Given the list of AbsId of the cluster, get the maximum cell and 
382   // check if there are fNCellsFromBorder from the calorimeter border
383   
384   if(!cluster)
385   {
386     AliInfo("Cluster pointer null!");
387     return kFALSE;
388   }
389   
390   //If the distance to the border is 0 or negative just exit accept all clusters
391   if(cells->GetType()==AliVCaloCells::kEMCALCell && fNCellsFromEMCALBorder <= 0 ) return kTRUE;
392   
393   Int_t absIdMax  = -1, iSM =-1, ieta = -1, iphi = -1;
394   Bool_t shared = kFALSE;
395   GetMaxEnergyCell(geom, cells, cluster, absIdMax,  iSM, ieta, iphi, shared);
396   
397   AliDebug(2,Form("Cluster Max AbsId %d, Cell Energy %2.2f, Cluster Energy %2.2f, Ncells from border %d, EMCAL eta=0 %d\n", 
398                   absIdMax, cells->GetCellAmplitude(absIdMax), cluster->E(), fNCellsFromEMCALBorder, fNoEMCALBorderAtEta0));
399   
400   if(absIdMax==-1) return kFALSE;
401   
402   //Check if the cell is close to the borders:
403   Bool_t okrow = kFALSE;
404   Bool_t okcol = kFALSE;
405   
406   if(iSM < 0 || iphi < 0 || ieta < 0 ) 
407   {
408     AliFatal(Form("Negative value for super module: %d, or cell ieta: %d, or cell iphi: %d, check EMCAL geometry name\n",
409                   iSM,ieta,iphi));
410   }
411   
412   //Check rows/phi
413   if(iSM < 10)
414   {
415     if(iphi >= fNCellsFromEMCALBorder && iphi < 24-fNCellsFromEMCALBorder) okrow =kTRUE; 
416   }
417   else if (iSM >=10 && ( ( geom->GetEMCGeometry()->GetGeoName()).Contains("12SMV1"))) 
418   {
419     if(iphi >= fNCellsFromEMCALBorder && iphi < 8-fNCellsFromEMCALBorder) okrow =kTRUE; //1/3 sm case
420   }
421   else 
422   {
423     if(iphi >= fNCellsFromEMCALBorder && iphi < 12-fNCellsFromEMCALBorder) okrow =kTRUE; // half SM case
424   }
425   
426   //Check columns/eta
427   if(!fNoEMCALBorderAtEta0)
428   {
429     if(ieta  > fNCellsFromEMCALBorder && ieta < 48-fNCellsFromEMCALBorder) okcol =kTRUE; 
430   }
431   else
432   {
433     if(iSM%2==0)
434     {
435       if(ieta >= fNCellsFromEMCALBorder)     okcol = kTRUE;  
436     }
437     else 
438     {
439       if(ieta <  48-fNCellsFromEMCALBorder)  okcol = kTRUE;  
440     }
441   }//eta 0 not checked
442   
443   AliDebug(2,Form("EMCAL Cluster in %d cells fiducial volume: ieta %d, iphi %d, SM %d:  column? %d, row? %d\nq",
444                   fNCellsFromEMCALBorder, ieta, iphi, iSM, okcol, okrow));
445   
446   if (okcol && okrow) 
447   {
448     //printf("Accept\n");
449     return kTRUE;
450   }
451   else  
452   {
453     //printf("Reject\n");
454     AliDebug(2,Form("Reject cluster in border, max cell : ieta %d, iphi %d, SM %d\n",ieta, iphi, iSM));
455     return kFALSE;
456   }
457   
458 }  
459
460
461 //_______________________________________________________________________________
462 Bool_t AliEMCALRecoUtils::ClusterContainsBadChannel(const AliEMCALGeometry* geom, 
463                                                     const UShort_t* cellList, 
464                                                     const Int_t nCells)
465 {
466   // Check that in the cluster cells, there is no bad channel of those stored 
467   // in fEMCALBadChannelMap or fPHOSBadChannelMap
468   
469   if(!fRemoveBadChannels)  return kFALSE;
470   if(!fEMCALBadChannelMap) return kFALSE;
471   
472   Int_t icol = -1;
473   Int_t irow = -1;
474   Int_t imod = -1;
475   for(Int_t iCell = 0; iCell<nCells; iCell++)
476   {
477     //Get the column and row
478     Int_t iTower = -1, iIphi = -1, iIeta = -1; 
479     geom->GetCellIndex(cellList[iCell],imod,iTower,iIphi,iIeta); 
480     if(fEMCALBadChannelMap->GetEntries() <= imod) continue;
481     geom->GetCellPhiEtaIndexInSModule(imod,iTower,iIphi, iIeta,irow,icol);      
482     if(GetEMCALChannelStatus(imod, icol, irow))
483     {
484       AliDebug(2,Form("Cluster with bad channel: SM %d, col %d, row %d\n",imod, icol, irow));
485       return kTRUE;
486     }
487     
488   }// cell cluster loop
489   
490   return kFALSE;
491 }
492
493
494 //___________________________________________________________________________
495 Float_t AliEMCALRecoUtils::GetECross(const Int_t absID, const Double_t tcell,
496                                      AliVCaloCells* cells, const Int_t bc)
497 {
498   //Calculate the energy in the cross around the energy given cell
499   
500   AliEMCALGeometry * geom = AliEMCALGeometry::GetInstance();
501   
502   Int_t imod = -1, iphi =-1, ieta=-1,iTower = -1, iIphi = -1, iIeta = -1; 
503   geom->GetCellIndex(absID,imod,iTower,iIphi,iIeta); 
504   geom->GetCellPhiEtaIndexInSModule(imod,iTower,iIphi, iIeta,iphi,ieta);  
505   
506   //Get close cells index, energy and time, not in corners
507   
508   Int_t absID1 = -1;
509   Int_t absID2 = -1;
510   
511   if( iphi < AliEMCALGeoParams::fgkEMCALRows-1) absID1 = geom-> GetAbsCellIdFromCellIndexes(imod, iphi+1, ieta);
512   if( iphi > 0 )                                absID2 = geom-> GetAbsCellIdFromCellIndexes(imod, iphi-1, ieta);
513   
514   // In case of cell in eta = 0 border, depending on SM shift the cross cell index
515   
516   Int_t absID3 = -1;
517   Int_t absID4 = -1;
518   
519   if     ( ieta == AliEMCALGeoParams::fgkEMCALCols-1 && !(imod%2) )
520   {
521     absID3 = geom-> GetAbsCellIdFromCellIndexes(imod+1, iphi, 0);
522     absID4 = geom-> GetAbsCellIdFromCellIndexes(imod,   iphi, ieta-1); 
523   }
524   else if( ieta == 0 && imod%2 )
525   {
526     absID3 = geom-> GetAbsCellIdFromCellIndexes(imod,   iphi, ieta+1);
527     absID4 = geom-> GetAbsCellIdFromCellIndexes(imod-1, iphi, AliEMCALGeoParams::fgkEMCALCols-1); 
528   }
529   else
530   {
531     if( ieta < AliEMCALGeoParams::fgkEMCALCols-1 ) 
532       absID3 = geom-> GetAbsCellIdFromCellIndexes(imod, iphi, ieta+1);
533     if( ieta > 0 )                                 
534       absID4 = geom-> GetAbsCellIdFromCellIndexes(imod, iphi, ieta-1); 
535   }
536   
537   //printf("IMOD %d, AbsId %d, a %d, b %d, c %d e %d \n",imod,absID,absID1,absID2,absID3,absID4);
538   
539   Float_t  ecell1  = 0, ecell2  = 0, ecell3  = 0, ecell4  = 0;
540   Double_t tcell1  = 0, tcell2  = 0, tcell3  = 0, tcell4  = 0;
541   Bool_t   accept1 = 0, accept2 = 0, accept3 = 0, accept4 = 0;
542   
543   accept1 = AcceptCalibrateCell(absID1,bc, ecell1,tcell1,cells); 
544   accept2 = AcceptCalibrateCell(absID2,bc, ecell2,tcell2,cells); 
545   accept3 = AcceptCalibrateCell(absID3,bc, ecell3,tcell3,cells); 
546   accept4 = AcceptCalibrateCell(absID4,bc, ecell4,tcell4,cells); 
547   
548   /*
549    printf("Cell absID %d \n",absID);
550    printf("\t  accept1 %d, accept2 %d, accept3 %d, accept4 %d\n",
551    accept1,accept2,accept3,accept4);
552    printf("\t id %d: id1 %d, id2 %d, id3 %d, id4 %d\n",
553    absID,absID1,absID2,absID3,absID4);
554    printf("\t e %f: e1 %f, e2 %f, e3 %f, e4 %f\n",
555    ecell,ecell1,ecell2,ecell3,ecell4);
556    printf("\t t %f: t1 %f, t2 %f, t3 %f, t4 %f;\n dt1 %f, dt2 %f, dt3 %f, dt4 %f\n",
557    tcell*1.e9,tcell1*1.e9,tcell2*1.e9,tcell3*1.e9,tcell4*1.e9,
558    TMath::Abs(tcell-tcell1)*1.e9, TMath::Abs(tcell-tcell2)*1.e9, TMath::Abs(tcell-tcell3)*1.e9, TMath::Abs(tcell-tcell4)*1.e9);
559    */
560   
561   if(TMath::Abs(tcell-tcell1)*1.e9 > fExoticCellDiffTime) ecell1 = 0 ;
562   if(TMath::Abs(tcell-tcell2)*1.e9 > fExoticCellDiffTime) ecell2 = 0 ;
563   if(TMath::Abs(tcell-tcell3)*1.e9 > fExoticCellDiffTime) ecell3 = 0 ;
564   if(TMath::Abs(tcell-tcell4)*1.e9 > fExoticCellDiffTime) ecell4 = 0 ;
565   
566   return ecell1+ecell2+ecell3+ecell4;
567   
568 }
569
570 //_____________________________________________________________________________________________
571 Bool_t AliEMCALRecoUtils::IsExoticCell(const Int_t absID, AliVCaloCells* cells, const Int_t bc)
572 {
573   // Look to cell neighbourhood and reject if it seems exotic
574   // Do before recalibrating the cells
575
576   if(!fRejectExoticCells) return kFALSE;
577   
578   Float_t  ecell  = 0;
579   Double_t tcell  = 0;
580   Bool_t   accept = AcceptCalibrateCell(absID, bc, ecell ,tcell ,cells); 
581   
582   if(!accept) return kTRUE; // reject this cell
583   
584   if(ecell < fExoticCellMinAmplitude) return kFALSE; // do not reject low energy cells
585
586   Float_t eCross = GetECross(absID,tcell,cells,bc);
587   
588   if(1-eCross/ecell > fExoticCellFraction) 
589   {
590     AliDebug(2,Form("AliEMCALRecoUtils::IsExoticCell() - EXOTIC CELL id %d, eCell %f, eCross %f, 1-eCross/eCell %f\n",
591                     absID,ecell,eCross,1-eCross/ecell));
592     return kTRUE;
593   }
594
595   return kFALSE;
596 }
597
598 //___________________________________________________________________
599 Bool_t AliEMCALRecoUtils::IsExoticCluster(const AliVCluster *cluster, 
600                                           AliVCaloCells *cells, 
601                                           const Int_t bc) 
602 {
603   // Check if the cluster highest energy tower is exotic
604   
605   if(!cluster)
606   {
607     AliInfo("Cluster pointer null!");
608     return kFALSE;
609   }
610   
611   if(!fRejectExoticCluster) return kFALSE;
612   
613   // Get highest energy tower
614   AliEMCALGeometry* geom = AliEMCALGeometry::GetInstance();
615   Int_t iSupMod = -1, absId = -1, ieta = -1, iphi = -1;
616   Bool_t shared = kFALSE;
617   GetMaxEnergyCell(geom, cells, cluster, absId, iSupMod, ieta, iphi, shared);
618   
619   return IsExoticCell(absId,cells,bc);
620   
621 }
622
623 //_______________________________________________________________________
624 Float_t AliEMCALRecoUtils::SmearClusterEnergy(const AliVCluster* cluster) 
625 {
626   //In case of MC analysis, smear energy to match resolution/calibration in real data
627   
628   if(!cluster)
629   {
630     AliInfo("Cluster pointer null!");
631     return 0;
632   }
633   
634   Float_t energy    = cluster->E() ;
635   Float_t rdmEnergy = energy ;
636   if(fSmearClusterEnergy)
637   {
638     rdmEnergy = fRandom.Gaus(energy,fSmearClusterParam[0] * TMath::Sqrt(energy) +
639                                     fSmearClusterParam[1] * energy +
640                                     fSmearClusterParam[2] );
641     AliDebug(2, Form("Energy: original %f, smeared %f\n", energy, rdmEnergy));
642   }
643   
644   return rdmEnergy;
645 }
646
647 //____________________________________________________________________________
648 Float_t AliEMCALRecoUtils::CorrectClusterEnergyLinearity(AliVCluster* cluster)
649 {
650   // Correct cluster energy from non linearity functions
651   
652   if(!cluster)
653   {
654     AliInfo("Cluster pointer null!");
655     return 0;
656   }
657   
658   Float_t energy = cluster->E();
659
660   if(energy < 0.05)
661   {
662     // Clusters with less than 50 MeV or negative are not possible
663     AliInfo(Form("Too Low Cluster energy!, E = %f < 0.05 GeV",energy));
664     return 0;
665   }
666   
667   switch (fNonLinearityFunction) 
668   {
669       
670     case kPi0MC:
671     {
672       //Non-Linearity correction (from MC with function ([0]*exp(-[1]/E))+(([2]/([3]*2.*TMath::Pi())*exp(-(E-[4])^2/(2.*[3]^2)))))
673       //fNonLinearityParams[0] = 1.014;
674       //fNonLinearityParams[1] =-0.03329;
675       //fNonLinearityParams[2] =-0.3853;
676       //fNonLinearityParams[3] = 0.5423;
677       //fNonLinearityParams[4] =-0.4335;
678        energy *= (fNonLinearityParams[0]*exp(-fNonLinearityParams[1]/energy))+
679                   ((fNonLinearityParams[2]/(fNonLinearityParams[3]*2.*TMath::Pi())*
680                     exp(-(energy-fNonLinearityParams[4])*(energy-fNonLinearityParams[4])/(2.*fNonLinearityParams[3]*fNonLinearityParams[3]))));
681       break;
682     }
683      
684     case kPi0MCv2:
685     {
686       //Non-Linearity correction (from MC with function [0]/((x+[1])^[2]))+1;
687       //fNonLinearityParams[0] = 3.11111e-02;
688       //fNonLinearityParams[1] =-5.71666e-02; 
689       //fNonLinearityParams[2] = 5.67995e-01;      
690       
691       energy *= fNonLinearityParams[0]/TMath::Power(energy+fNonLinearityParams[1],fNonLinearityParams[2])+1;
692       break;
693     }
694     
695     case kPi0MCv3:
696     {
697       //Same as beam test corrected, change parameters
698       //fNonLinearityParams[0] =  9.81039e-01
699       //fNonLinearityParams[1] =  1.13508e-01;
700       //fNonLinearityParams[2] =  1.00173e+00; 
701       //fNonLinearityParams[3] =  9.67998e-02;
702       //fNonLinearityParams[4] =  2.19381e+02;
703       //fNonLinearityParams[5] =  6.31604e+01;
704       //fNonLinearityParams[6] =  1;
705       energy *= fNonLinearityParams[6]/(fNonLinearityParams[0]*(1./(1.+fNonLinearityParams[1]*exp(-energy/fNonLinearityParams[2]))*1./(1.+fNonLinearityParams[3]*exp((energy-fNonLinearityParams[4])/fNonLinearityParams[5]))));
706       
707       break;
708     }
709       
710       
711     case kPi0GammaGamma:
712     {
713       //Non-Linearity correction (from Olga Data with function p0+p1*exp(-p2*E))
714       //fNonLinearityParams[0] = 1.04;
715       //fNonLinearityParams[1] = -0.1445;
716       //fNonLinearityParams[2] = 1.046;
717       energy /= (fNonLinearityParams[0]+fNonLinearityParams[1]*exp(-fNonLinearityParams[2]*energy)); //Olga function
718       break;
719     }
720       
721     case kPi0GammaConversion:
722     {
723       //Non-Linearity correction (Nicolas from Dimitri Data with function C*[1-a*exp(-b*E)])
724       //fNonLinearityParams[0] = 0.139393/0.1349766;
725       //fNonLinearityParams[1] = 0.0566186;
726       //fNonLinearityParams[2] = 0.982133;
727       energy /= fNonLinearityParams[0]*(1-fNonLinearityParams[1]*exp(-fNonLinearityParams[2]*energy));
728       
729       break;
730     }
731       
732     case kBeamTest:
733     {
734       //From beam test, Alexei's results, for different ZS thresholds
735       //                        th=30 MeV; th = 45 MeV; th = 75 MeV
736       //fNonLinearityParams[0] = 1.007;      1.003;      1.002 
737       //fNonLinearityParams[1] = 0.894;      0.719;      0.797 
738       //fNonLinearityParams[2] = 0.246;      0.334;      0.358 
739       //Rescale the param[0] with 1.03
740       energy /= fNonLinearityParams[0]/(1+fNonLinearityParams[1]*exp(-energy/fNonLinearityParams[2]));
741       
742       break;
743     }
744       
745     case kBeamTestCorrected:
746     {
747       //From beam test, corrected for material between beam and EMCAL
748       //fNonLinearityParams[0] =  0.99078
749       //fNonLinearityParams[1] =  0.161499;
750       //fNonLinearityParams[2] =  0.655166; 
751       //fNonLinearityParams[3] =  0.134101;
752       //fNonLinearityParams[4] =  163.282;
753       //fNonLinearityParams[5] =  23.6904;
754       //fNonLinearityParams[6] =  0.978;
755         energy *= fNonLinearityParams[6]/(fNonLinearityParams[0]*(1./(1.+fNonLinearityParams[1]*exp(-energy/fNonLinearityParams[2]))*1./(1.+fNonLinearityParams[3]*exp((energy-fNonLinearityParams[4])/fNonLinearityParams[5]))));
756
757       break;
758     }
759       
760     case kNoCorrection:
761       AliDebug(2,"No correction on the energy\n");
762       break;
763       
764   }
765
766   return energy;
767 }
768
769 //__________________________________________________
770 void AliEMCALRecoUtils::InitNonLinearityParam()
771 {
772   //Initialising Non Linearity Parameters
773   
774   if(fNonLinearityFunction == kPi0MC) 
775   {
776     fNonLinearityParams[0] = 1.014;
777     fNonLinearityParams[1] = -0.03329;
778     fNonLinearityParams[2] = -0.3853;
779     fNonLinearityParams[3] = 0.5423;
780     fNonLinearityParams[4] = -0.4335;
781   }
782   
783   if(fNonLinearityFunction == kPi0MCv2) 
784   {
785     fNonLinearityParams[0] = 3.11111e-02;
786     fNonLinearityParams[1] =-5.71666e-02; 
787     fNonLinearityParams[2] = 5.67995e-01;      
788   }
789   
790   if(fNonLinearityFunction == kPi0MCv3) 
791   {
792     fNonLinearityParams[0] =  9.81039e-01;
793     fNonLinearityParams[1] =  1.13508e-01;
794     fNonLinearityParams[2] =  1.00173e+00; 
795     fNonLinearityParams[3] =  9.67998e-02;
796     fNonLinearityParams[4] =  2.19381e+02;
797     fNonLinearityParams[5] =  6.31604e+01;
798     fNonLinearityParams[6] =  1;
799   }
800   
801   if(fNonLinearityFunction == kPi0GammaGamma) 
802   {
803     fNonLinearityParams[0] = 1.04;
804     fNonLinearityParams[1] = -0.1445;
805     fNonLinearityParams[2] = 1.046;
806   }  
807
808   if(fNonLinearityFunction == kPi0GammaConversion) 
809   {
810     fNonLinearityParams[0] = 0.139393;
811     fNonLinearityParams[1] = 0.0566186;
812     fNonLinearityParams[2] = 0.982133;
813   }  
814
815   if(fNonLinearityFunction == kBeamTest) 
816   {
817     if(fNonLinearThreshold == 30) 
818     {
819       fNonLinearityParams[0] = 1.007; 
820       fNonLinearityParams[1] = 0.894; 
821       fNonLinearityParams[2] = 0.246; 
822     }
823     if(fNonLinearThreshold == 45) 
824     {
825       fNonLinearityParams[0] = 1.003; 
826       fNonLinearityParams[1] = 0.719; 
827       fNonLinearityParams[2] = 0.334; 
828     }
829     if(fNonLinearThreshold == 75) 
830     {
831       fNonLinearityParams[0] = 1.002; 
832       fNonLinearityParams[1] = 0.797; 
833       fNonLinearityParams[2] = 0.358; 
834     }
835   }
836
837   if(fNonLinearityFunction == kBeamTestCorrected) 
838   {
839     fNonLinearityParams[0] =  0.99078;
840     fNonLinearityParams[1] =  0.161499;
841     fNonLinearityParams[2] =  0.655166; 
842     fNonLinearityParams[3] =  0.134101;
843     fNonLinearityParams[4] =  163.282;
844     fNonLinearityParams[5] =  23.6904;
845     fNonLinearityParams[6] =  0.978;
846   }
847 }
848
849 //_________________________________________________________
850 Float_t  AliEMCALRecoUtils::GetDepth(const Float_t energy, 
851                                      const Int_t iParticle, 
852                                      const Int_t iSM) const 
853 {
854   //Calculate shower depth for a given cluster energy and particle type
855
856   // parameters 
857   Float_t x0    = 1.31;
858   Float_t ecr   = 8;
859   Float_t depth = 0;
860   Float_t arg   = energy*1000/ ecr; //Multiply energy by 1000 to transform to MeV
861   
862   switch ( iParticle )
863   {
864     case kPhoton:
865       if (arg < 1) 
866         depth = 0;
867       else
868         depth = x0 * (TMath::Log(arg) + 0.5); 
869       break;
870       
871     case kElectron:
872       if (arg < 1) 
873         depth = 0;
874       else
875         depth = x0 * (TMath::Log(arg) - 0.5); 
876       break;
877       
878     case kHadron:
879       // hadron 
880       // boxes anc. here
881       if(gGeoManager)
882       {
883         gGeoManager->cd("ALIC_1/XEN1_1");
884         TGeoNode        *geoXEn1    = gGeoManager->GetCurrentNode();
885         TGeoNodeMatrix  *geoSM      = dynamic_cast<TGeoNodeMatrix *>(geoXEn1->GetDaughter(iSM));
886         if(geoSM)
887         {
888           TGeoVolume      *geoSMVol   = geoSM->GetVolume(); 
889           TGeoShape       *geoSMShape = geoSMVol->GetShape();
890           TGeoBBox        *geoBox     = dynamic_cast<TGeoBBox *>(geoSMShape);
891           if(geoBox) depth = 0.5 * geoBox->GetDX()*2 ;
892           else AliFatal("Null GEANT box");
893         }
894         else AliFatal("NULL  GEANT node matrix");
895       }
896       else
897       {//electron
898         if (arg < 1) 
899           depth = 0;
900         else
901           depth = x0 * (TMath::Log(arg) - 0.5); 
902       }
903         
904       break;
905       
906     default://photon
907       if (arg < 1) 
908         depth = 0;
909       else
910         depth = x0 * (TMath::Log(arg) + 0.5);
911   }  
912   
913   return depth;
914 }
915
916 //____________________________________________________________________
917 void AliEMCALRecoUtils::GetMaxEnergyCell(const AliEMCALGeometry *geom, 
918                                          AliVCaloCells* cells, 
919                                          const AliVCluster* clu, 
920                                          Int_t  & absId,  
921                                          Int_t  & iSupMod, 
922                                          Int_t  & ieta, 
923                                          Int_t  & iphi, 
924                                          Bool_t & shared)
925 {
926   //For a given CaloCluster gets the absId of the cell 
927   //with maximum energy deposit.
928   
929   Double_t eMax        = -1.;
930   Double_t eCell       = -1.;
931   Float_t  fraction    = 1.;
932   Float_t  recalFactor = 1.;
933   Int_t    cellAbsId   = -1 ;
934
935   Int_t iTower  = -1;
936   Int_t iIphi   = -1;
937   Int_t iIeta   = -1;
938   Int_t iSupMod0= -1;
939
940   if(!clu)
941   {
942     AliInfo("Cluster pointer null!");
943     absId=-1; iSupMod0=-1, ieta = -1; iphi = -1; shared = -1;
944     return;
945   }
946   
947   for (Int_t iDig=0; iDig< clu->GetNCells(); iDig++) 
948   {
949     cellAbsId = clu->GetCellAbsId(iDig);
950     fraction  = clu->GetCellAmplitudeFraction(iDig);
951     //printf("a Cell %d, id, %d, amp %f, fraction %f\n",iDig,cellAbsId,cells->GetCellAmplitude(cellAbsId),fraction);
952     if(fraction < 1e-4) fraction = 1.; // in case unfolding is off
953     geom->GetCellIndex(cellAbsId,iSupMod,iTower,iIphi,iIeta); 
954     geom->GetCellPhiEtaIndexInSModule(iSupMod,iTower,iIphi, iIeta,iphi,ieta);
955     if     (iDig==0) 
956     {
957       iSupMod0=iSupMod;
958     }
959     else if(iSupMod0!=iSupMod) 
960     {
961       shared = kTRUE;
962       //printf("AliEMCALRecoUtils::GetMaxEnergyCell() - SHARED CLUSTER\n");
963     }
964     if(!fCellsRecalibrated && IsRecalibrationOn()) 
965     {
966       recalFactor = GetEMCALChannelRecalibrationFactor(iSupMod,ieta,iphi);
967     }
968     eCell  = cells->GetCellAmplitude(cellAbsId)*fraction*recalFactor;
969     //printf("b Cell %d, id, %d, amp %f, fraction %f\n",iDig,cellAbsId,eCell,fraction);
970     if(eCell > eMax)  
971     { 
972       eMax  = eCell; 
973       absId = cellAbsId;
974       //printf("\t new max: cell %d, e %f, ecell %f\n",maxId, eMax,eCell);
975     }
976   }// cell loop
977   
978   //Get from the absid the supermodule, tower and eta/phi numbers
979   geom->GetCellIndex(absId,iSupMod,iTower,iIphi,iIeta); 
980   //Gives SuperModule and Tower numbers
981   geom->GetCellPhiEtaIndexInSModule(iSupMod,iTower,
982                                          iIphi, iIeta,iphi,ieta); 
983   //printf("Max id %d, iSM %d, col %d, row %d\n",absId,iSupMod,ieta,iphi);
984   //printf("Max end---\n");
985 }
986
987 //______________________________________
988 void AliEMCALRecoUtils::InitParameters()
989 {
990   // Initialize data members with default values
991   
992   fParticleType = kPhoton;
993   fPosAlgo      = kUnchanged;
994   fW0           = 4.5;
995   
996   fNonLinearityFunction = kNoCorrection;
997   fNonLinearThreshold   = 30;
998   
999   fExoticCellFraction     = 0.97;
1000   fExoticCellDiffTime     = 1e6;
1001   fExoticCellMinAmplitude = 0.5;
1002   
1003   fAODFilterMask    = 128;
1004   fAODHybridTracks  = kFALSE;
1005   fAODTPCOnlyTracks = kTRUE;
1006   
1007   fCutEtaPhiSum      = kTRUE;
1008   fCutEtaPhiSeparate = kFALSE;
1009   
1010   fCutR   = 0.05; 
1011   fCutEta = 0.025; 
1012   fCutPhi = 0.05;
1013   
1014   fClusterWindow = 100;
1015   fMass          = 0.139;
1016   
1017   fStepSurface   = 20.;                      
1018   fStepCluster   = 5.;
1019   fTrackCutsType = kLooseCut;
1020   
1021   fCutMinTrackPt     = 0;
1022   fCutMinNClusterTPC = -1;
1023   fCutMinNClusterITS = -1;
1024   
1025   fCutMaxChi2PerClusterTPC  = 1e10;
1026   fCutMaxChi2PerClusterITS  = 1e10;
1027   
1028   fCutRequireTPCRefit     = kFALSE;
1029   fCutRequireITSRefit     = kFALSE;
1030   fCutAcceptKinkDaughters = kFALSE;
1031   
1032   fCutMaxDCAToVertexXY = 1e10;             
1033   fCutMaxDCAToVertexZ  = 1e10;              
1034   fCutDCAToVertex2D    = kFALSE;
1035   
1036   fCutRequireITSStandAlone = kFALSE; //MARCEL
1037   fCutRequireITSpureSA     = kFALSE; //Marcel
1038   
1039   //Misalignment matrices
1040   for(Int_t i = 0; i < 15 ; i++) 
1041   {
1042     fMisalTransShift[i] = 0.; 
1043     fMisalRotShift[i]   = 0.; 
1044   }
1045   
1046   //Non linearity
1047   for(Int_t i = 0; i < 7  ; i++) fNonLinearityParams[i] = 0.; 
1048   
1049   //For kBeamTestCorrected case, but default is no correction
1050   fNonLinearityParams[0] =  0.99078;
1051   fNonLinearityParams[1] =  0.161499;
1052   fNonLinearityParams[2] =  0.655166; 
1053   fNonLinearityParams[3] =  0.134101;
1054   fNonLinearityParams[4] =  163.282;
1055   fNonLinearityParams[5] =  23.6904;
1056   fNonLinearityParams[6] =  0.978;
1057   
1058   //For kPi0GammaGamma case
1059   //fNonLinearityParams[0] = 0.1457/0.1349766/1.038;
1060   //fNonLinearityParams[1] = -0.02024/0.1349766/1.038;
1061   //fNonLinearityParams[2] = 1.046;
1062   
1063   //Cluster energy smearing
1064   fSmearClusterEnergy   = kFALSE;
1065   fSmearClusterParam[0] = 0.07; // * sqrt E term
1066   fSmearClusterParam[1] = 0.00; // * E term
1067   fSmearClusterParam[2] = 0.00; // constant
1068 }
1069
1070 //_____________________________________________________
1071 void AliEMCALRecoUtils::InitEMCALRecalibrationFactors()
1072 {
1073   //Init EMCAL recalibration factors
1074   AliDebug(2,"AliCalorimeterUtils::InitEMCALRecalibrationFactors()");
1075   //In order to avoid rewriting the same histograms
1076   Bool_t oldStatus = TH1::AddDirectoryStatus();
1077   TH1::AddDirectory(kFALSE);
1078   
1079   fEMCALRecalibrationFactors = new TObjArray(12);
1080   for (int i = 0; i < 12; i++) 
1081     fEMCALRecalibrationFactors->Add(new TH2F(Form("EMCALRecalFactors_SM%d",i),
1082                                              Form("EMCALRecalFactors_SM%d",i),  48, 0, 48, 24, 0, 24));
1083   //Init the histograms with 1
1084   for (Int_t sm = 0; sm < 12; sm++) 
1085   {
1086     for (Int_t i = 0; i < 48; i++) 
1087     {
1088       for (Int_t j = 0; j < 24; j++) 
1089       {
1090         SetEMCALChannelRecalibrationFactor(sm,i,j,1.);
1091       }
1092     }
1093   }
1094   
1095   fEMCALRecalibrationFactors->SetOwner(kTRUE);
1096   fEMCALRecalibrationFactors->Compress();
1097   
1098   //In order to avoid rewriting the same histograms
1099   TH1::AddDirectory(oldStatus);    
1100 }
1101
1102 //_________________________________________________________
1103 void AliEMCALRecoUtils::InitEMCALTimeRecalibrationFactors()
1104 {
1105   //Init EMCAL recalibration factors
1106   AliDebug(2,"AliCalorimeterUtils::InitEMCALRecalibrationFactors()");
1107   //In order to avoid rewriting the same histograms
1108   Bool_t oldStatus = TH1::AddDirectoryStatus();
1109   TH1::AddDirectory(kFALSE);
1110   
1111   fEMCALTimeRecalibrationFactors = new TObjArray(4);
1112   for (int i = 0; i < 4; i++) 
1113     fEMCALTimeRecalibrationFactors->Add(new TH1F(Form("hAllTimeAvBC%d",i),
1114                                                  Form("hAllTimeAvBC%d",i),  
1115                                                  48*24*12,0.,48*24*12)          );
1116   //Init the histograms with 1
1117   for (Int_t bc = 0; bc < 4; bc++) 
1118   {
1119     for (Int_t i = 0; i < 48*24*12; i++) 
1120       SetEMCALChannelTimeRecalibrationFactor(bc,i,0.);
1121   }
1122   
1123   fEMCALTimeRecalibrationFactors->SetOwner(kTRUE);
1124   fEMCALTimeRecalibrationFactors->Compress();
1125   
1126   //In order to avoid rewriting the same histograms
1127   TH1::AddDirectory(oldStatus);    
1128 }
1129
1130 //____________________________________________________
1131 void AliEMCALRecoUtils::InitEMCALBadChannelStatusMap()
1132 {
1133   //Init EMCAL bad channels map
1134   AliDebug(2,"AliEMCALRecoUtils::InitEMCALBadChannelStatusMap()");
1135   //In order to avoid rewriting the same histograms
1136   Bool_t oldStatus = TH1::AddDirectoryStatus();
1137   TH1::AddDirectory(kFALSE);
1138   
1139   fEMCALBadChannelMap = new TObjArray(12);
1140   //TH2F * hTemp = new  TH2I("EMCALBadChannelMap","EMCAL SuperModule bad channel map", 48, 0, 48, 24, 0, 24);
1141   for (int i = 0; i < 12; i++) 
1142   {
1143     fEMCALBadChannelMap->Add(new TH2I(Form("EMCALBadChannelMap_Mod%d",i),Form("EMCALBadChannelMap_Mod%d",i), 48, 0, 48, 24, 0, 24));
1144   }
1145   
1146   fEMCALBadChannelMap->SetOwner(kTRUE);
1147   fEMCALBadChannelMap->Compress();
1148   
1149   //In order to avoid rewriting the same histograms
1150   TH1::AddDirectory(oldStatus);    
1151 }
1152
1153 //____________________________________________________________________________
1154 void AliEMCALRecoUtils::RecalibrateClusterEnergy(const AliEMCALGeometry* geom, 
1155                                                  AliVCluster * cluster, 
1156                                                  AliVCaloCells * cells, 
1157                                                  const Int_t bc)
1158 {
1159   // Recalibrate the cluster energy and Time, considering the recalibration map 
1160   // and the energy of the cells and time that compose the cluster.
1161   // bc= bunch crossing number returned by esdevent->GetBunchCrossNumber();
1162   
1163   if(!cluster)
1164   {
1165     AliInfo("Cluster pointer null!");
1166     return;
1167   }  
1168   
1169   //Get the cluster number of cells and list of absId, check what kind of cluster do we have.
1170   UShort_t * index    = cluster->GetCellsAbsId() ;
1171   Double_t * fraction = cluster->GetCellsAmplitudeFraction() ;
1172   Int_t ncells = cluster->GetNCells();
1173   
1174   //Initialize some used variables
1175   Float_t energy = 0;
1176   Int_t   absId  =-1;
1177   Int_t   icol   =-1, irow =-1, imod=1;
1178   Float_t factor = 1, frac = 0;
1179   Int_t   absIdMax = -1;
1180   Float_t emax     = 0;
1181   
1182   //Loop on the cells, get the cell amplitude and recalibration factor, multiply and and to the new energy
1183   for(Int_t icell = 0; icell < ncells; icell++)
1184   {
1185     absId = index[icell];
1186     frac =  fraction[icell];
1187     if(frac < 1e-5) frac = 1; //in case of EMCAL, this is set as 0 since unfolding is off
1188     
1189     if(!fCellsRecalibrated && IsRecalibrationOn()) 
1190     {
1191       // Energy  
1192       Int_t iTower = -1, iIphi = -1, iIeta = -1; 
1193       geom->GetCellIndex(absId,imod,iTower,iIphi,iIeta); 
1194       if(fEMCALRecalibrationFactors->GetEntries() <= imod) continue;
1195       geom->GetCellPhiEtaIndexInSModule(imod,iTower,iIphi, iIeta,irow,icol);      
1196       factor = GetEMCALChannelRecalibrationFactor(imod,icol,irow);
1197       
1198       AliDebug(2,Form("AliEMCALRecoUtils::RecalibrateClusterEnergy - recalibrate cell: module %d, col %d, row %d, cell fraction %f,recalibration factor %f, cell energy %f\n",
1199                       imod,icol,irow,frac,factor,cells->GetCellAmplitude(absId)));
1200       
1201     } 
1202     
1203     energy += cells->GetCellAmplitude(absId)*factor*frac;
1204     
1205     if(emax < cells->GetCellAmplitude(absId)*factor*frac)
1206     {
1207       emax     = cells->GetCellAmplitude(absId)*factor*frac;
1208       absIdMax = absId;
1209     }
1210   }
1211   
1212   AliDebug(2,Form("AliEMCALRecoUtils::RecalibrateClusterEnergy - Energy before %f, after %f \n",cluster->E(),energy));
1213
1214   cluster->SetE(energy);
1215
1216   // Recalculate time of cluster
1217   Double_t timeorg = cluster->GetTOF();
1218
1219   Double_t time = cells->GetCellTime(absIdMax);
1220   if(!fCellsRecalibrated && IsTimeRecalibrationOn())
1221     RecalibrateCellTime(absIdMax,bc,time);
1222
1223   cluster->SetTOF(time);
1224
1225   AliDebug(2,Form("AliEMCALRecoUtils::RecalibrateClusterEnergy - Time before %f, after %f \n",timeorg,cluster->GetTOF()));
1226 }
1227
1228 //_____________________________________________________________
1229 void AliEMCALRecoUtils::RecalibrateCells(AliVCaloCells * cells,
1230                                          const Int_t bc)
1231 {
1232   // Recalibrate the cells time and energy, considering the recalibration map and the energy 
1233   // of the cells that compose the cluster.
1234   // bc= bunch crossing number returned by esdevent->GetBunchCrossNumber();
1235
1236   if(!IsRecalibrationOn() && !IsTimeRecalibrationOn() && !IsBadChannelsRemovalSwitchedOn()) return;
1237   
1238   if(!cells)
1239   {
1240     AliInfo("Cells pointer null!");
1241     return;
1242   }  
1243   
1244   Short_t  absId  =-1;
1245   Bool_t   accept = kFALSE;
1246   Float_t  ecell  = 0;
1247   Double_t tcell  = 0;
1248   Double_t ecellin = 0;
1249   Double_t tcellin = 0;
1250   Int_t  mclabel = -1;
1251   Double_t efrac = 0;
1252   
1253   Int_t nEMcell  = cells->GetNumberOfCells() ;  
1254   for (Int_t iCell = 0; iCell < nEMcell; iCell++) 
1255   { 
1256     cells->GetCell( iCell, absId, ecellin, tcellin, mclabel, efrac );
1257     
1258     accept = AcceptCalibrateCell(absId, bc, ecell ,tcell ,cells); 
1259     if(!accept) 
1260     {
1261       ecell = 0;
1262       tcell = -1;
1263     }
1264     
1265     //Set new values
1266     cells->SetCell(iCell,absId,ecell, tcell, mclabel, efrac);
1267   }
1268
1269   fCellsRecalibrated = kTRUE;
1270 }
1271
1272 //_______________________________________________________________________________________________________
1273 void AliEMCALRecoUtils::RecalibrateCellTime(const Int_t absId, const Int_t bc, Double_t & celltime) const
1274 {
1275   // Recalibrate time of cell with absID  considering the recalibration map 
1276   // bc= bunch crossing number returned by esdevent->GetBunchCrossNumber();
1277   
1278   if(!fCellsRecalibrated && IsTimeRecalibrationOn() && bc >= 0)
1279   {
1280     celltime -= GetEMCALChannelTimeRecalibrationFactor(bc%4,absId)*1.e-9;    ;  
1281   }
1282 }
1283   
1284 //______________________________________________________________________________
1285 void AliEMCALRecoUtils::RecalculateClusterPosition(const AliEMCALGeometry *geom, 
1286                                                    AliVCaloCells* cells, 
1287                                                    AliVCluster* clu)
1288 {
1289   //For a given CaloCluster recalculates the position for a given set of misalignment shifts and puts it again in the CaloCluster.
1290   
1291   if(!clu)
1292   {
1293     AliInfo("Cluster pointer null!");
1294     return;
1295   }
1296     
1297   if     (fPosAlgo==kPosTowerGlobal) RecalculateClusterPositionFromTowerGlobal( geom, cells, clu);
1298   else if(fPosAlgo==kPosTowerIndex)  RecalculateClusterPositionFromTowerIndex ( geom, cells, clu);
1299   else   AliDebug(2,"Algorithm to recalculate position not selected, do nothing.");
1300 }  
1301
1302 //_____________________________________________________________________________________________
1303 void AliEMCALRecoUtils::RecalculateClusterPositionFromTowerGlobal(const AliEMCALGeometry *geom, 
1304                                                                   AliVCaloCells* cells, 
1305                                                                   AliVCluster* clu)
1306 {
1307   // For a given CaloCluster recalculates the position for a given set of misalignment shifts and puts it again in the CaloCluster.
1308   // The algorithm is a copy of what is done in AliEMCALRecPoint
1309   
1310   Double_t eCell       = 0.;
1311   Float_t  fraction    = 1.;
1312   Float_t  recalFactor = 1.;
1313   
1314   Int_t    absId   = -1;
1315   Int_t    iTower  = -1, iIphi  = -1, iIeta  = -1;
1316   Int_t    iSupModMax = -1, iSM=-1, iphi   = -1, ieta   = -1;
1317   Float_t  weight = 0.,  totalWeight=0.;
1318   Float_t  newPos[3] = {0,0,0};
1319   Double_t pLocal[3], pGlobal[3];
1320   Bool_t shared = kFALSE;
1321
1322   Float_t  clEnergy = clu->E(); //Energy already recalibrated previously
1323   if (clEnergy <= 0)
1324     return;
1325   GetMaxEnergyCell(geom, cells, clu, absId,  iSupModMax, ieta, iphi,shared);
1326   Double_t depth = GetDepth(clEnergy,fParticleType,iSupModMax) ;
1327   
1328   //printf("** Cluster energy %f, ncells %d, depth %f\n",clEnergy,clu->GetNCells(),depth);
1329   
1330   for (Int_t iDig=0; iDig< clu->GetNCells(); iDig++) 
1331   {
1332     absId = clu->GetCellAbsId(iDig);
1333     fraction  = clu->GetCellAmplitudeFraction(iDig);
1334     if(fraction < 1e-4) fraction = 1.; // in case unfolding is off
1335     
1336     if (!fCellsRecalibrated)
1337     {
1338       geom->GetCellIndex(absId,iSM,iTower,iIphi,iIeta); 
1339       geom->GetCellPhiEtaIndexInSModule(iSM,iTower,iIphi, iIeta,iphi,ieta);      
1340       
1341       if(IsRecalibrationOn()) 
1342       {
1343         recalFactor = GetEMCALChannelRecalibrationFactor(iSM,ieta,iphi);
1344       }
1345     }
1346     
1347     eCell  = cells->GetCellAmplitude(absId)*fraction*recalFactor;
1348     
1349     weight = GetCellWeight(eCell,clEnergy);
1350     totalWeight += weight;
1351     
1352     geom->RelPosCellInSModule(absId,depth,pLocal[0],pLocal[1],pLocal[2]);
1353     //printf("pLocal (%f,%f,%f), SM %d, absId %d\n",pLocal[0],pLocal[1],pLocal[2],iSupModMax,absId);
1354     geom->GetGlobal(pLocal,pGlobal,iSupModMax);
1355     //printf("pLocal (%f,%f,%f)\n",pGlobal[0],pGlobal[1],pGlobal[2]);
1356
1357     for(int i=0; i<3; i++ ) newPos[i] += (weight*pGlobal[i]);
1358   }// cell loop
1359   
1360   if(totalWeight>0)
1361   {
1362     for(int i=0; i<3; i++ )    newPos[i] /= totalWeight;
1363   }
1364     
1365   //Float_t pos[]={0,0,0};
1366   //clu->GetPosition(pos);
1367   //printf("OldPos  : %2.3f,%2.3f,%2.3f\n",pos[0],pos[1],pos[2]);
1368   //printf("NewPos  : %2.3f,%2.3f,%2.3f\n",newPos[0],newPos[1],newPos[2]);
1369   
1370   if(iSupModMax > 1) //sector 1
1371   {
1372     newPos[0] +=fMisalTransShift[3];//-=3.093; 
1373     newPos[1] +=fMisalTransShift[4];//+=6.82;
1374     newPos[2] +=fMisalTransShift[5];//+=1.635;
1375     //printf("   +    : %2.3f,%2.3f,%2.3f\n",fMisalTransShift[3],fMisalTransShift[4],fMisalTransShift[5]);
1376   } else //sector 0
1377   {
1378     newPos[0] +=fMisalTransShift[0];//+=1.134;
1379     newPos[1] +=fMisalTransShift[1];//+=8.2;
1380     newPos[2] +=fMisalTransShift[2];//+=1.197;
1381     //printf("   +    : %2.3f,%2.3f,%2.3f\n",fMisalTransShift[0],fMisalTransShift[1],fMisalTransShift[2]);
1382   }
1383   //printf("NewPos : %2.3f,%2.3f,%2.3f\n",newPos[0],newPos[1],newPos[2]);
1384
1385   clu->SetPosition(newPos);
1386 }  
1387
1388 //____________________________________________________________________________________________
1389 void AliEMCALRecoUtils::RecalculateClusterPositionFromTowerIndex(const AliEMCALGeometry *geom, 
1390                                                                  AliVCaloCells* cells, 
1391                                                                  AliVCluster* clu)
1392 {
1393   // For a given CaloCluster recalculates the position for a given set of misalignment shifts and puts it again in the CaloCluster.
1394   // The algorithm works with the tower indeces, averages the indeces and from them it calculates the global position
1395   
1396   Double_t eCell       = 1.;
1397   Float_t  fraction    = 1.;
1398   Float_t  recalFactor = 1.;
1399   
1400   Int_t absId   = -1;
1401   Int_t iTower  = -1;
1402   Int_t iIphi   = -1, iIeta   = -1;
1403   Int_t iSupMod = -1, iSupModMax = -1;
1404   Int_t iphi = -1, ieta =-1;
1405   Bool_t shared = kFALSE;
1406
1407   Float_t clEnergy = clu->E(); //Energy already recalibrated previously.
1408   
1409   if (clEnergy <= 0)
1410     return;
1411   GetMaxEnergyCell(geom, cells, clu, absId,  iSupModMax, ieta, iphi,shared);
1412   Float_t  depth = GetDepth(clEnergy,fParticleType,iSupMod) ;
1413
1414   Float_t weight = 0., weightedCol = 0., weightedRow = 0., totalWeight=0.;
1415   Bool_t areInSameSM = kTRUE; //exclude clusters with cells in different SMs for now
1416   Int_t startingSM = -1;
1417   
1418   for (Int_t iDig=0; iDig< clu->GetNCells(); iDig++) 
1419   {
1420     absId = clu->GetCellAbsId(iDig);
1421     fraction  = clu->GetCellAmplitudeFraction(iDig);
1422     if(fraction < 1e-4) fraction = 1.; // in case unfolding is off
1423
1424     if     (iDig==0)  startingSM = iSupMod;
1425     else if(iSupMod != startingSM) areInSameSM = kFALSE;
1426
1427     eCell  = cells->GetCellAmplitude(absId);
1428     
1429     geom->GetCellIndex(absId,iSupMod,iTower,iIphi,iIeta); 
1430     geom->GetCellPhiEtaIndexInSModule(iSupMod,iTower,iIphi, iIeta,iphi,ieta);    
1431     
1432     if (!fCellsRecalibrated)
1433     {
1434       if(IsRecalibrationOn()) 
1435       {
1436         recalFactor = GetEMCALChannelRecalibrationFactor(iSupMod,ieta,iphi);
1437       }
1438     }
1439     
1440     eCell  = cells->GetCellAmplitude(absId)*fraction*recalFactor;
1441     
1442     weight = GetCellWeight(eCell,clEnergy);
1443     if(weight < 0) weight = 0;
1444     totalWeight += weight;
1445     weightedCol += ieta*weight;
1446     weightedRow += iphi*weight;
1447     
1448     //printf("Max cell? cell %d, amplitude org %f, fraction %f, recalibration %f, amplitude new %f \n",cellAbsId, cells->GetCellAmplitude(cellAbsId), fraction, recalFactor, eCell) ;
1449   }// cell loop
1450     
1451   Float_t xyzNew[]={0.,0.,0.};
1452   if(areInSameSM == kTRUE) 
1453   {
1454     //printf("In Same SM\n");
1455     weightedCol = weightedCol/totalWeight;
1456     weightedRow = weightedRow/totalWeight;
1457     geom->RecalculateTowerPosition(weightedRow, weightedCol, iSupModMax, depth, fMisalTransShift, fMisalRotShift, xyzNew); 
1458   } 
1459   else 
1460   {
1461     //printf("In Different SM\n");
1462     geom->RecalculateTowerPosition(iphi,        ieta,        iSupModMax, depth, fMisalTransShift, fMisalRotShift, xyzNew); 
1463   }
1464   
1465   clu->SetPosition(xyzNew);
1466 }
1467
1468 //___________________________________________________________________________________________
1469 void AliEMCALRecoUtils::RecalculateClusterDistanceToBadChannel(const AliEMCALGeometry * geom, 
1470                                                                AliVCaloCells* cells, 
1471                                                                AliVCluster * cluster)
1472 {           
1473   //re-evaluate distance to bad channel with updated bad map
1474   
1475   if(!fRecalDistToBadChannels) return;
1476   
1477   if(!cluster)
1478   {
1479     AliInfo("Cluster pointer null!");
1480     return;
1481   }  
1482   
1483   //Get channels map of the supermodule where the cluster is.
1484   Int_t absIdMax  = -1, iSupMod =-1, icolM = -1, irowM = -1;
1485   Bool_t shared = kFALSE;
1486   GetMaxEnergyCell(geom, cells, cluster, absIdMax,  iSupMod, icolM, irowM, shared);
1487   TH2D* hMap  = (TH2D*)fEMCALBadChannelMap->At(iSupMod);
1488
1489   Int_t dRrow, dRcol;  
1490   Float_t  minDist = 10000.;
1491   Float_t  dist    = 0.;
1492   
1493   //Loop on tower status map 
1494   for(Int_t irow = 0; irow < AliEMCALGeoParams::fgkEMCALRows; irow++)
1495   {
1496     for(Int_t icol = 0; icol < AliEMCALGeoParams::fgkEMCALCols; icol++)
1497     {
1498       //Check if tower is bad.
1499       if(hMap->GetBinContent(icol,irow)==0) continue;
1500       //printf("AliEMCALRecoUtils::RecalculateDistanceToBadChannels() - \n \t Bad channel in SM %d, col %d, row %d, \n \t Cluster max in col %d, row %d\n",
1501       //       iSupMod,icol, irow, icolM,irowM);
1502       
1503       dRrow=TMath::Abs(irowM-irow);
1504       dRcol=TMath::Abs(icolM-icol);
1505       dist=TMath::Sqrt(dRrow*dRrow+dRcol*dRcol);
1506       if(dist < minDist)
1507       {
1508         //printf("MIN DISTANCE TO BAD %2.2f\n",dist);
1509         minDist = dist;
1510       }
1511     }
1512   }
1513   
1514   //In case the cluster is shared by 2 SuperModules, need to check the map of the second Super Module
1515   if (shared) 
1516   {
1517     TH2D* hMap2 = 0;
1518     Int_t iSupMod2 = -1;
1519     
1520     //The only possible combinations are (0,1), (2,3) ... (8,9)
1521     if(iSupMod%2) iSupMod2 = iSupMod-1;
1522     else          iSupMod2 = iSupMod+1;
1523     hMap2  = (TH2D*)fEMCALBadChannelMap->At(iSupMod2);
1524     
1525     //Loop on tower status map of second super module
1526     for(Int_t irow = 0; irow < AliEMCALGeoParams::fgkEMCALRows; irow++)
1527     {
1528       for(Int_t icol = 0; icol < AliEMCALGeoParams::fgkEMCALCols; icol++)
1529       {
1530         //Check if tower is bad.
1531         if(hMap2->GetBinContent(icol,irow)==0) continue;
1532         //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",
1533         //     iSupMod2,icol, irow,iSupMod,icolM,irowM);
1534         dRrow=TMath::Abs(irow-irowM);
1535         
1536         if(iSupMod%2) 
1537         {
1538           dRcol=TMath::Abs(icol-(AliEMCALGeoParams::fgkEMCALCols+icolM));
1539         } else 
1540         {
1541           dRcol=TMath::Abs(AliEMCALGeoParams::fgkEMCALCols+icol-icolM);
1542         }                    
1543         
1544         dist=TMath::Sqrt(dRrow*dRrow+dRcol*dRcol);
1545         if(dist < minDist) minDist = dist;        
1546       }
1547     }
1548   }// shared cluster in 2 SuperModules
1549   
1550   AliDebug(2,Form("Max cluster cell (SM,col,row)=(%d %d %d) - Distance to Bad Channel %2.2f",iSupMod, icolM, irowM, minDist));
1551   cluster->SetDistanceToBadChannel(minDist);
1552 }
1553
1554 //__________________________________________________________________
1555 void AliEMCALRecoUtils::RecalculateClusterPID(AliVCluster * cluster)
1556 {           
1557   //re-evaluate identification parameters with bayesian
1558   
1559   if(!cluster)
1560   {
1561     AliInfo("Cluster pointer null!");
1562     return;
1563   }
1564   
1565   if ( cluster->GetM02() != 0)
1566     fPIDUtils->ComputePID(cluster->E(),cluster->GetM02());
1567   
1568   Float_t pidlist[AliPID::kSPECIESCN+1];
1569   for(Int_t i = 0; i < AliPID::kSPECIESCN+1; i++) pidlist[i] = fPIDUtils->GetPIDFinal(i);
1570         
1571   cluster->SetPID(pidlist);
1572 }
1573
1574 //___________________________________________________________________________________________________________________
1575 void AliEMCALRecoUtils::RecalculateClusterShowerShapeParameters(const AliEMCALGeometry * geom, 
1576                                                                 AliVCaloCells* cells, 
1577                                                                 AliVCluster * cluster,
1578                                                                 Float_t & l0,   Float_t & l1,   
1579                                                                 Float_t & disp, Float_t & dEta, Float_t & dPhi,
1580                                                                 Float_t & sEta, Float_t & sPhi, Float_t & sEtaPhi)
1581 {
1582   // Calculates new center of gravity in the local EMCAL-module coordinates 
1583   // and tranfers into global ALICE coordinates
1584   // Calculates Dispersion and main axis
1585   
1586   if(!cluster)
1587   {
1588     AliInfo("Cluster pointer null!");
1589     return;
1590   }
1591     
1592   Double_t eCell       = 0.;
1593   Float_t  fraction    = 1.;
1594   Float_t  recalFactor = 1.;
1595
1596   Int_t    iSupMod = -1;
1597   Int_t    iTower  = -1;
1598   Int_t    iIphi   = -1;
1599   Int_t    iIeta   = -1;
1600   Int_t    iphi    = -1;
1601   Int_t    ieta    = -1;
1602   Double_t etai    = -1.;
1603   Double_t phii    = -1.;
1604   
1605   Int_t    nstat   = 0 ;
1606   Float_t  wtot    = 0.;
1607   Double_t w       = 0.;
1608   Double_t etaMean = 0.;
1609   Double_t phiMean = 0.;
1610   
1611   //Loop on cells, calculate the cluster energy, in case a cut on cell energy is added
1612   // and to check if the cluster is between 2 SM in eta
1613   Int_t   iSM0   = -1;
1614   Bool_t  shared = kFALSE;
1615   Float_t energy = 0;
1616   
1617   for(Int_t iDigit=0; iDigit < cluster->GetNCells(); iDigit++)
1618   {
1619     //Get from the absid the supermodule, tower and eta/phi numbers
1620     geom->GetCellIndex(cluster->GetCellAbsId(iDigit),iSupMod,iTower,iIphi,iIeta);
1621     geom->GetCellPhiEtaIndexInSModule(iSupMod,iTower,iIphi,iIeta, iphi,ieta);
1622     
1623     //Check if there are cells of different SM
1624     if     (iDigit == 0   ) iSM0 = iSupMod;
1625     else if(iSupMod!= iSM0) shared = kTRUE;
1626     
1627     //Get the cell energy, if recalibration is on, apply factors
1628     fraction  = cluster->GetCellAmplitudeFraction(iDigit);
1629     if(fraction < 1e-4) fraction = 1.; // in case unfolding is off
1630     
1631     if(IsRecalibrationOn())
1632     {
1633       recalFactor = GetEMCALChannelRecalibrationFactor(iSupMod,ieta,iphi);
1634     }
1635     
1636     eCell  = cells->GetCellAmplitude(cluster->GetCellAbsId(iDigit))*fraction*recalFactor;
1637     
1638     energy += eCell;
1639     
1640   }//cell loop
1641   
1642   //Loop on cells
1643   for(Int_t iDigit=0; iDigit < cluster->GetNCells(); iDigit++) 
1644   {
1645     //Get from the absid the supermodule, tower and eta/phi numbers
1646     geom->GetCellIndex(cluster->GetCellAbsId(iDigit),iSupMod,iTower,iIphi,iIeta); 
1647     geom->GetCellPhiEtaIndexInSModule(iSupMod,iTower,iIphi,iIeta, iphi,ieta);        
1648     
1649     //Get the cell energy, if recalibration is on, apply factors
1650     fraction  = cluster->GetCellAmplitudeFraction(iDigit);
1651     if(fraction < 1e-4) fraction = 1.; // in case unfolding is off
1652     
1653     if (!fCellsRecalibrated)
1654     {
1655       if(IsRecalibrationOn()) 
1656       {
1657         recalFactor = GetEMCALChannelRecalibrationFactor(iSupMod,ieta,iphi);
1658       }
1659     }
1660     
1661     eCell  = cells->GetCellAmplitude(cluster->GetCellAbsId(iDigit))*fraction*recalFactor;
1662     
1663     // In case of a shared cluster, index of SM in C side, columns start at 48 and ends at 48*2
1664     // C Side impair SM, nSupMod%2=1; A side pair SM, nSupMod%2=0
1665     if(shared && iSupMod%2) ieta+=AliEMCALGeoParams::fgkEMCALCols;
1666     
1667     if(cluster->E() > 0 && eCell > 0)
1668     {
1669       w  = GetCellWeight(eCell,cluster->E());
1670       
1671       etai=(Double_t)ieta;
1672       phii=(Double_t)iphi;  
1673       
1674       if(w > 0.0) 
1675       {
1676         wtot += w ;
1677         nstat++;            
1678         //Shower shape
1679         sEta     += w * etai * etai ;
1680         etaMean  += w * etai ;
1681         sPhi     += w * phii * phii ;
1682         phiMean  += w * phii ; 
1683         sEtaPhi  += w * etai * phii ; 
1684       }
1685     } 
1686     else
1687       AliError(Form("Wrong energy %f and/or amplitude %f\n", eCell, cluster->E()));
1688   }//cell loop
1689   
1690   //Normalize to the weight  
1691   if (wtot > 0) 
1692   {
1693     etaMean /= wtot ;
1694     phiMean /= wtot ;
1695   }
1696   else
1697     AliError(Form("Wrong weight %f\n", wtot));
1698   
1699   //Calculate dispersion  
1700   for(Int_t iDigit=0; iDigit < cluster->GetNCells(); iDigit++) 
1701   {
1702     //Get from the absid the supermodule, tower and eta/phi numbers
1703     geom->GetCellIndex(cluster->GetCellAbsId(iDigit),iSupMod,iTower,iIphi,iIeta); 
1704     geom->GetCellPhiEtaIndexInSModule(iSupMod,iTower,iIphi,iIeta, iphi,ieta);
1705     
1706     //Get the cell energy, if recalibration is on, apply factors
1707     fraction  = cluster->GetCellAmplitudeFraction(iDigit);
1708     if(fraction < 1e-4) fraction = 1.; // in case unfolding is off
1709     if (IsRecalibrationOn()) 
1710     {
1711       recalFactor = GetEMCALChannelRecalibrationFactor(iSupMod,ieta,iphi);
1712     }
1713     eCell  = cells->GetCellAmplitude(cluster->GetCellAbsId(iDigit))*fraction*recalFactor;
1714     
1715     // In case of a shared cluster, index of SM in C side, columns start at 48 and ends at 48*2
1716     // C Side impair SM, nSupMod%2=1; A side pair SM, nSupMod%2=0
1717     if(shared && iSupMod%2) ieta+=AliEMCALGeoParams::fgkEMCALCols;
1718     
1719     if(cluster->E() > 0 && eCell > 0)
1720     {
1721       w  = GetCellWeight(eCell,cluster->E());
1722       
1723       etai=(Double_t)ieta;
1724       phii=(Double_t)iphi;    
1725       if(w > 0.0) 
1726       { 
1727         disp +=  w *((etai-etaMean)*(etai-etaMean)+(phii-phiMean)*(phii-phiMean)); 
1728         dEta +=  w * (etai-etaMean)*(etai-etaMean) ; 
1729         dPhi +=  w * (phii-phiMean)*(phii-phiMean) ; 
1730       }
1731     }
1732     else
1733       AliError(Form("Wrong energy %f and/or amplitude %f\n", eCell, cluster->E()));
1734   }// cell loop
1735   
1736   //Normalize to the weigth and set shower shape parameters
1737   if (wtot > 0 && nstat > 1) 
1738   {
1739     disp    /= wtot ;
1740     dEta    /= wtot ;
1741     dPhi    /= wtot ;
1742     sEta    /= wtot ;
1743     sPhi    /= wtot ;
1744     sEtaPhi /= wtot ;
1745     
1746     sEta    -= etaMean * etaMean ;
1747     sPhi    -= phiMean * phiMean ;
1748     sEtaPhi -= etaMean * phiMean ;
1749     
1750     l0 = (0.5 * (sEta + sPhi) + TMath::Sqrt( 0.25 * (sEta - sPhi) * (sEta - sPhi) + sEtaPhi * sEtaPhi ));
1751     l1 = (0.5 * (sEta + sPhi) - TMath::Sqrt( 0.25 * (sEta - sPhi) * (sEta - sPhi) + sEtaPhi * sEtaPhi ));
1752   }
1753   else
1754   {
1755     l0   = 0. ;
1756     l1   = 0. ;
1757     dEta = 0. ; dPhi = 0. ; disp    = 0. ;
1758     sEta = 0. ; sPhi = 0. ; sEtaPhi = 0. ;
1759   }  
1760   
1761 }
1762
1763 //____________________________________________________________________________________________
1764 void AliEMCALRecoUtils::RecalculateClusterShowerShapeParameters(const AliEMCALGeometry * geom, 
1765                                                                 AliVCaloCells* cells, 
1766                                                                 AliVCluster * cluster)
1767 {
1768   // Calculates new center of gravity in the local EMCAL-module coordinates 
1769   // and tranfers into global ALICE coordinates
1770   // Calculates Dispersion and main axis and puts them into the cluster
1771   
1772   Float_t l0   = 0., l1   = 0.;
1773   Float_t disp = 0., dEta = 0., dPhi    = 0.; 
1774   Float_t sEta = 0., sPhi = 0., sEtaPhi = 0.;
1775   
1776   AliEMCALRecoUtils::RecalculateClusterShowerShapeParameters(geom,cells,cluster,l0,l1,disp,
1777                                                              dEta, dPhi, sEta, sPhi, sEtaPhi);
1778   
1779   cluster->SetM02(l0);
1780   cluster->SetM20(l1);
1781   if(disp > 0. ) cluster->SetDispersion(TMath::Sqrt(disp)) ;
1782   
1783
1784
1785 //____________________________________________________________________________
1786 void AliEMCALRecoUtils::FindMatches(AliVEvent *event,
1787                                     TObjArray * clusterArr,  
1788                                     const AliEMCALGeometry *geom)
1789 {
1790   //This function should be called before the cluster loop
1791   //Before call this function, please recalculate the cluster positions
1792   //Given the input event, loop over all the tracks, select the closest cluster as matched with fCutR
1793   //Store matched cluster indexes and residuals
1794   
1795   fMatchedTrackIndex  ->Reset();
1796   fMatchedClusterIndex->Reset();
1797   fResidualPhi->Reset();
1798   fResidualEta->Reset();
1799   
1800   fMatchedTrackIndex  ->Set(1000);
1801   fMatchedClusterIndex->Set(1000);
1802   fResidualPhi->Set(1000);
1803   fResidualEta->Set(1000);
1804   
1805   AliESDEvent* esdevent = dynamic_cast<AliESDEvent*> (event);
1806   AliAODEvent* aodevent = dynamic_cast<AliAODEvent*> (event);
1807   
1808   // init the magnetic field if not already on
1809   if(!TGeoGlobalMagField::Instance()->GetField())
1810   {
1811     AliInfo("Init the magnetic field\n");
1812     if     (esdevent) 
1813     {
1814       esdevent->InitMagneticField();
1815     }
1816     else if(aodevent)
1817     {
1818       Double_t curSol = 30000*aodevent->GetMagneticField()/5.00668;
1819       Double_t curDip = 6000 *aodevent->GetMuonMagFieldScale();
1820       AliMagF *field  = AliMagF::CreateFieldMap(curSol,curDip);
1821       TGeoGlobalMagField::Instance()->SetField(field);
1822     }
1823     else
1824     {
1825       AliInfo("Mag Field not initialized, null esd/aod evetn pointers");
1826     }
1827     
1828   } // Init mag field
1829   
1830   if (esdevent) {
1831     UInt_t mask1 = esdevent->GetESDRun()->GetDetectorsInDAQ();
1832     UInt_t mask2 = esdevent->GetESDRun()->GetDetectorsInReco();
1833     Bool_t desc1 = (mask1 >> 3) & 0x1;
1834     Bool_t desc2 = (mask2 >> 3) & 0x1;
1835     if (desc1==0 || desc2==0) { 
1836 //       AliError(Form("TPC not in DAQ/RECO: %u (%u)/%u (%u)", 
1837 //       mask1, esdevent->GetESDRun()->GetDetectorsInReco(),
1838 //       mask2, esdevent->GetESDRun()->GetDetectorsInDAQ()));
1839       fITSTrackSA=kTRUE;
1840     }
1841   }
1842
1843   TObjArray *clusterArray = 0x0;
1844   if(!clusterArr)
1845     {
1846       clusterArray = new TObjArray(event->GetNumberOfCaloClusters());
1847       for(Int_t icl=0; icl<event->GetNumberOfCaloClusters(); icl++)
1848   {
1849     AliVCluster *cluster = (AliVCluster*) event->GetCaloCluster(icl);
1850     if(geom && !IsGoodCluster(cluster,geom,(AliVCaloCells*)event->GetEMCALCells())) continue;
1851     clusterArray->AddAt(cluster,icl);
1852   }
1853     }
1854   
1855   Int_t    matched=0;
1856   Double_t cv[21];
1857   for (Int_t i=0; i<21;i++) cv[i]=0;
1858   for(Int_t itr=0; itr<event->GetNumberOfTracks(); itr++)
1859   {
1860     AliExternalTrackParam *trackParam = 0;
1861     
1862     //If the input event is ESD, the starting point for extrapolation is TPCOut, if available, or TPCInner 
1863     AliESDtrack *esdTrack = 0;
1864     AliAODTrack *aodTrack = 0;
1865     if(esdevent)
1866     {
1867       esdTrack = esdevent->GetTrack(itr);
1868       if(!esdTrack) continue;
1869       if(!IsAccepted(esdTrack)) continue;
1870       if(esdTrack->Pt()<fCutMinTrackPt) continue;
1871       Double_t phi = esdTrack->Phi()*TMath::RadToDeg();
1872       if(TMath::Abs(esdTrack->Eta())>0.8 || phi <= 20 || phi >= 240 ) continue;
1873       if(!fITSTrackSA)
1874         trackParam =  const_cast<AliExternalTrackParam*>(esdTrack->GetInnerParam());  // if TPC Available
1875       else
1876         trackParam =  new AliExternalTrackParam(*esdTrack); // If ITS Track Standing alone              
1877     }
1878     
1879     //If the input event is AOD, the starting point for extrapolation is at vertex
1880     //AOD tracks are selected according to its filterbit.
1881     else if(aodevent)
1882     {
1883       aodTrack = aodevent->GetTrack(itr);
1884       if(!aodTrack) continue;
1885             
1886       if(fAODTPCOnlyTracks) // Match with TPC only tracks, default from May 2013, before filter bit 32
1887       {
1888         //printf("Match with TPC only tracks, accept? %d, test bit 128 <%d> \n", aodTrack->IsTPCOnly(), aodTrack->TestFilterMask(128));
1889         if(!aodTrack->IsTPCOnly()) continue ;
1890       }
1891       else if(fAODHybridTracks) // Match with hybrid tracks
1892       {
1893         //printf("Match with Hybrid tracks, accept? %d \n", aodTrack->IsHybridGlobalConstrainedGlobal());
1894         if(!aodTrack->IsHybridGlobalConstrainedGlobal()) continue ;
1895       }
1896       else // Match with tracks on a mask
1897       {
1898         //printf("Match with tracks having filter bit mask %d, accept? %d \n",fAODFilterMask,aodTrack->TestFilterMask(fAODFilterMask));
1899         if(!aodTrack->TestFilterMask(fAODFilterMask) ) continue; //Select AOD tracks
1900       }
1901       
1902       if(aodTrack->Pt()<fCutMinTrackPt) continue;
1903
1904       Double_t phi = aodTrack->Phi()*TMath::RadToDeg();
1905       if(TMath::Abs(aodTrack->Eta())>0.8 || phi <= 20 || phi >= 240 ) continue;
1906       Double_t pos[3],mom[3];
1907       aodTrack->GetXYZ(pos);
1908       aodTrack->GetPxPyPz(mom);
1909       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()));
1910
1911       trackParam= new AliExternalTrackParam(pos,mom,cv,aodTrack->Charge());
1912     }
1913     
1914     //Return if the input data is not "AOD" or "ESD"
1915     else
1916     {
1917       printf("Wrong input data type! Should be \"AOD\" or \"ESD\"\n");
1918       if(clusterArray)
1919   {
1920     clusterArray->Clear();
1921     delete clusterArray;
1922   }
1923       return;
1924     }
1925     
1926     if(!trackParam) continue;
1927
1928     //Extrapolate the track to EMCal surface
1929     AliExternalTrackParam emcalParam(*trackParam);
1930     Float_t eta, phi, pt;
1931     if(!ExtrapolateTrackToEMCalSurface(&emcalParam, fEMCalSurfaceDistance, fMass, fStepSurface, eta, phi, pt)) 
1932       {
1933   if(aodevent && trackParam) delete trackParam;
1934   if(fITSTrackSA && trackParam) delete trackParam;
1935   continue;
1936       }
1937
1938 //    if(esdevent)
1939 //      {
1940 //  esdTrack->SetOuterParam(&emcalParam,AliExternalTrackParam::kMultSec);
1941 //      }
1942
1943     if(TMath::Abs(eta)>0.75 || (phi) < 70*TMath::DegToRad() || (phi) > 190*TMath::DegToRad())
1944       {
1945   if(aodevent && trackParam) delete trackParam;
1946   if(fITSTrackSA && trackParam) delete trackParam;
1947   continue;
1948       }
1949
1950
1951     //Find matched clusters
1952     Int_t index = -1;
1953     Float_t dEta = -999, dPhi = -999;
1954     if(!clusterArr)
1955       {
1956   index = FindMatchedClusterInClusterArr(&emcalParam, &emcalParam, clusterArray, dEta, dPhi);  
1957       }
1958     else
1959       {
1960   index = FindMatchedClusterInClusterArr(&emcalParam, &emcalParam, clusterArr, dEta, dPhi);  
1961       }  
1962     
1963     if(index>-1)
1964     {
1965       fMatchedTrackIndex   ->AddAt(itr,matched);
1966       fMatchedClusterIndex ->AddAt(index,matched);
1967       fResidualEta         ->AddAt(dEta,matched);
1968       fResidualPhi         ->AddAt(dPhi,matched);
1969       matched++;
1970     }
1971     if(aodevent && trackParam) delete trackParam;
1972     if(fITSTrackSA && trackParam) delete trackParam;
1973   }//track loop
1974
1975   if(clusterArray)
1976     {
1977       clusterArray->Clear();
1978       delete clusterArray;
1979     }
1980   
1981   AliDebug(2,Form("Number of matched pairs = %d !\n",matched));
1982   
1983   fMatchedTrackIndex   ->Set(matched);
1984   fMatchedClusterIndex ->Set(matched);
1985   fResidualPhi         ->Set(matched);
1986   fResidualEta         ->Set(matched);
1987 }
1988
1989 //________________________________________________________________________________
1990 Int_t AliEMCALRecoUtils::FindMatchedClusterInEvent(const AliESDtrack *track, 
1991                                                    const AliVEvent *event, 
1992                                                    const AliEMCALGeometry *geom, 
1993                                                    Float_t &dEta, Float_t &dPhi)
1994 {
1995   //
1996   // This function returns the index of matched cluster to input track
1997   // Returns -1 if no match is found
1998   Int_t index = -1;
1999   Double_t phiV = track->Phi()*TMath::RadToDeg();
2000   if(TMath::Abs(track->Eta())>0.8 || phiV <= 20 || phiV >= 240 ) return index;
2001   AliExternalTrackParam *trackParam = 0;
2002   if(!fITSTrackSA)
2003     trackParam = const_cast<AliExternalTrackParam*>(track->GetInnerParam());  // If TPC
2004   else
2005     trackParam = new AliExternalTrackParam(*track);
2006     
2007   if(!trackParam) return index;
2008   AliExternalTrackParam emcalParam(*trackParam);
2009   Float_t eta, phi, pt;
2010
2011   if(!ExtrapolateTrackToEMCalSurface(&emcalParam, fEMCalSurfaceDistance, fMass, fStepSurface, eta, phi, pt))    {
2012         if(fITSTrackSA) delete trackParam;
2013         return index;
2014   }
2015   if(TMath::Abs(eta)>0.75 || (phi) < 70*TMath::DegToRad() || (phi) > 190*TMath::DegToRad()){
2016         if(fITSTrackSA) delete trackParam;
2017         return index;
2018   }
2019   
2020   TObjArray *clusterArr = new TObjArray(event->GetNumberOfCaloClusters());
2021
2022   for(Int_t icl=0; icl<event->GetNumberOfCaloClusters(); icl++)
2023   {
2024     AliVCluster *cluster = (AliVCluster*) event->GetCaloCluster(icl);
2025     if(geom && !IsGoodCluster(cluster,geom,(AliVCaloCells*)event->GetEMCALCells())) continue;
2026     clusterArr->AddAt(cluster,icl);
2027   }
2028
2029   index = FindMatchedClusterInClusterArr(&emcalParam, &emcalParam, clusterArr, dEta, dPhi);  
2030   clusterArr->Clear();
2031   delete clusterArr;
2032   if(fITSTrackSA) delete trackParam;
2033
2034   return index;
2035 }
2036
2037 //_______________________________________________________________________________________________
2038 Int_t  AliEMCALRecoUtils::FindMatchedClusterInClusterArr(const AliExternalTrackParam *emcalParam, 
2039                                                          AliExternalTrackParam *trkParam, 
2040                                                          const TObjArray * clusterArr, 
2041                                                          Float_t &dEta, Float_t &dPhi)
2042 {
2043   // Find matched cluster in array
2044   
2045   dEta=-999, dPhi=-999;
2046   Float_t dRMax = fCutR, dEtaMax=fCutEta, dPhiMax=fCutPhi;
2047   Int_t index = -1;
2048   Float_t tmpEta=-999, tmpPhi=-999;
2049
2050   Double_t exPos[3] = {0.,0.,0.};
2051   if(!emcalParam->GetXYZ(exPos)) return index;
2052
2053   Float_t clsPos[3] = {0.,0.,0.};
2054   for(Int_t icl=0; icl<clusterArr->GetEntriesFast(); icl++)
2055     {
2056       AliVCluster *cluster = dynamic_cast<AliVCluster*> (clusterArr->At(icl)) ;
2057       if(!cluster || !cluster->IsEMCAL()) continue;
2058       cluster->GetPosition(clsPos);
2059       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));
2060       if(dR > fClusterWindow) continue;
2061
2062       AliExternalTrackParam trkPamTmp (*trkParam);//Retrieve the starting point every time before the extrapolation
2063       if(!ExtrapolateTrackToCluster(&trkPamTmp, cluster, fMass, fStepCluster, tmpEta, tmpPhi)) continue;
2064       if(fCutEtaPhiSum)
2065         {
2066           Float_t tmpR=TMath::Sqrt(tmpEta*tmpEta + tmpPhi*tmpPhi);
2067           if(tmpR<dRMax)
2068       {
2069         dRMax=tmpR;
2070         dEtaMax=tmpEta;
2071         dPhiMax=tmpPhi;
2072         index=icl;
2073       }
2074         }
2075       else if(fCutEtaPhiSeparate)
2076         {
2077           if(TMath::Abs(tmpEta)<TMath::Abs(dEtaMax) && TMath::Abs(tmpPhi)<TMath::Abs(dPhiMax))
2078       {
2079         dEtaMax = tmpEta;
2080         dPhiMax = tmpPhi;
2081         index=icl;
2082       }
2083         }
2084       else
2085         {
2086           printf("Error: please specify your cut criteria\n");
2087           printf("To cut on sqrt(dEta^2+dPhi^2), use: SwitchOnCutEtaPhiSum()\n");
2088           printf("To cut on dEta and dPhi separately, use: SwitchOnCutEtaPhiSeparate()\n");
2089           return index;
2090         }
2091     }
2092
2093   dEta=dEtaMax;
2094   dPhi=dPhiMax;
2095
2096   return index;
2097 }
2098
2099 //------------------------------------------------------------------------------------
2100 Bool_t AliEMCALRecoUtils::ExtrapolateTrackToEMCalSurface(AliExternalTrackParam *trkParam, 
2101                                                          const Double_t emcalR,
2102                                                          const Double_t mass, 
2103                                                          const Double_t step, 
2104                                                          Float_t &eta, 
2105                                                          Float_t &phi,
2106                                                          Float_t &pt)
2107 {
2108   //Extrapolate track to EMCAL surface
2109   
2110   eta = -999, phi = -999, pt = -999;
2111   if(!trkParam) return kFALSE;
2112   if(!AliTrackerBase::PropagateTrackToBxByBz(trkParam, emcalR, mass, step, kTRUE, 0.8, -1)) return kFALSE;
2113   Double_t trkPos[3] = {0.,0.,0.};
2114   if(!trkParam->GetXYZ(trkPos)) return kFALSE;
2115   TVector3 trkPosVec(trkPos[0],trkPos[1],trkPos[2]);
2116   eta = trkPosVec.Eta();
2117   phi = trkPosVec.Phi();
2118   pt = trkParam->Pt();
2119   if(phi<0)
2120     phi += 2*TMath::Pi();
2121
2122   return kTRUE;
2123 }
2124
2125 //-----------------------------------------------------------------------------------
2126 Bool_t AliEMCALRecoUtils::ExtrapolateTrackToPosition(AliExternalTrackParam *trkParam, 
2127                                                      const Float_t *clsPos, 
2128                                                      Double_t mass, 
2129                                                      Double_t step, 
2130                                                      Float_t &tmpEta, 
2131                                                      Float_t &tmpPhi)
2132 {
2133   //
2134   //Return the residual by extrapolating a track param to a global position
2135   //
2136   tmpEta = -999;
2137   tmpPhi = -999;
2138   if(!trkParam) return kFALSE;
2139   Double_t trkPos[3] = {0.,0.,0.};
2140   TVector3 vec(clsPos[0],clsPos[1],clsPos[2]);
2141   Double_t alpha =  ((int)(vec.Phi()*TMath::RadToDeg()/20)+0.5)*20*TMath::DegToRad();
2142   vec.RotateZ(-alpha); //Rotate the cluster to the local extrapolation coordinate system
2143   if(!AliTrackerBase::PropagateTrackToBxByBz(trkParam, vec.X(), mass, step,kTRUE, 0.8, -1)) return kFALSE;
2144   if(!trkParam->GetXYZ(trkPos)) return kFALSE; //Get the extrapolated global position
2145
2146   TVector3 clsPosVec(clsPos[0],clsPos[1],clsPos[2]);
2147   TVector3 trkPosVec(trkPos[0],trkPos[1],trkPos[2]);
2148
2149   // track cluster matching
2150   tmpPhi = clsPosVec.DeltaPhi(trkPosVec);    // tmpPhi is between -pi and pi
2151   tmpEta = clsPosVec.Eta()-trkPosVec.Eta();
2152
2153   return kTRUE;
2154 }
2155
2156 //----------------------------------------------------------------------------------
2157 Bool_t AliEMCALRecoUtils::ExtrapolateTrackToCluster(AliExternalTrackParam *trkParam, 
2158                                                     const AliVCluster *cluster, 
2159                                                     const Double_t mass, 
2160                                                     const Double_t step, 
2161                                                     Float_t &tmpEta, 
2162                                                     Float_t &tmpPhi)
2163 {
2164   //
2165   //Return the residual by extrapolating a track param to a cluster
2166   //
2167   tmpEta = -999;
2168   tmpPhi = -999;
2169   if(!cluster || !trkParam) return kFALSE;
2170
2171   Float_t clsPos[3] = {0.,0.,0.};
2172   cluster->GetPosition(clsPos);
2173
2174   return ExtrapolateTrackToPosition(trkParam, clsPos, mass, step, tmpEta, tmpPhi);
2175 }
2176
2177 //---------------------------------------------------------------------------------
2178 Bool_t AliEMCALRecoUtils::ExtrapolateTrackToCluster(AliExternalTrackParam *trkParam, 
2179                                                     const AliVCluster *cluster, 
2180                                                     Float_t &tmpEta, 
2181                                                     Float_t &tmpPhi)
2182 {
2183   //
2184   //Return the residual by extrapolating a track param to a clusterfStepCluster
2185   //
2186
2187   return ExtrapolateTrackToCluster(trkParam, cluster, fMass, fStepCluster, tmpEta, tmpPhi);
2188 }
2189
2190 //_______________________________________________________________________
2191 void AliEMCALRecoUtils::GetMatchedResiduals(const Int_t clsIndex, 
2192                                             Float_t &dEta, Float_t &dPhi)
2193 {
2194   //Given a cluster index as in AliESDEvent::GetCaloCluster(clsIndex)
2195   //Get the residuals dEta and dPhi for this cluster to the closest track
2196   //Works with ESDs and AODs
2197
2198   if( FindMatchedPosForCluster(clsIndex) >= 999 )
2199   {
2200     AliDebug(2,"No matched tracks found!\n");
2201     dEta=999.;
2202     dPhi=999.;
2203     return;
2204   }
2205   dEta = fResidualEta->At(FindMatchedPosForCluster(clsIndex));
2206   dPhi = fResidualPhi->At(FindMatchedPosForCluster(clsIndex));
2207 }
2208
2209 //______________________________________________________________________________________________
2210 void AliEMCALRecoUtils::GetMatchedClusterResiduals(Int_t trkIndex, Float_t &dEta, Float_t &dPhi)
2211 {
2212   //Given a track index as in AliESDEvent::GetTrack(trkIndex)
2213   //Get the residuals dEta and dPhi for this track to the closest cluster
2214   //Works with ESDs and AODs
2215
2216   if( FindMatchedPosForTrack(trkIndex) >= 999 )
2217   {
2218     AliDebug(2,"No matched cluster found!\n");
2219     dEta=999.;
2220     dPhi=999.;
2221     return;
2222   }
2223   dEta = fResidualEta->At(FindMatchedPosForTrack(trkIndex));
2224   dPhi = fResidualPhi->At(FindMatchedPosForTrack(trkIndex));
2225 }
2226
2227 //__________________________________________________________
2228 Int_t AliEMCALRecoUtils::GetMatchedTrackIndex(Int_t clsIndex)
2229 {
2230   //Given a cluster index as in AliESDEvent::GetCaloCluster(clsIndex)
2231   //Get the index of matched track to this cluster
2232   //Works with ESDs and AODs
2233   
2234   if(IsClusterMatched(clsIndex))
2235     return fMatchedTrackIndex->At(FindMatchedPosForCluster(clsIndex));
2236   else 
2237     return -1; 
2238 }
2239
2240 //__________________________________________________________
2241 Int_t AliEMCALRecoUtils::GetMatchedClusterIndex(Int_t trkIndex)
2242 {
2243   //Given a track index as in AliESDEvent::GetTrack(trkIndex)
2244   //Get the index of matched cluster to this track
2245   //Works with ESDs and AODs
2246   
2247   if(IsTrackMatched(trkIndex))
2248     return fMatchedClusterIndex->At(FindMatchedPosForTrack(trkIndex));
2249   else 
2250     return -1; 
2251 }
2252
2253 //______________________________________________________________
2254 Bool_t AliEMCALRecoUtils::IsClusterMatched(Int_t clsIndex) const
2255 {
2256   //Given a cluster index as in AliESDEvent::GetCaloCluster(clsIndex)
2257   //Returns if the cluster has a match
2258   if(FindMatchedPosForCluster(clsIndex) < 999) 
2259     return kTRUE;
2260   else
2261     return kFALSE;
2262 }
2263
2264 //____________________________________________________________
2265 Bool_t AliEMCALRecoUtils::IsTrackMatched(Int_t trkIndex) const 
2266 {
2267   //Given a track index as in AliESDEvent::GetTrack(trkIndex)
2268   //Returns if the track has a match
2269   if(FindMatchedPosForTrack(trkIndex) < 999) 
2270     return kTRUE;
2271   else
2272     return kFALSE;
2273 }
2274
2275 //______________________________________________________________________
2276 UInt_t AliEMCALRecoUtils::FindMatchedPosForCluster(Int_t clsIndex) const
2277 {
2278   //Given a cluster index as in AliESDEvent::GetCaloCluster(clsIndex)
2279   //Returns the position of the match in the fMatchedClusterIndex array
2280   Float_t tmpR = fCutR;
2281   UInt_t pos = 999;
2282   
2283   for(Int_t i=0; i<fMatchedClusterIndex->GetSize(); i++) 
2284   {
2285     if(fMatchedClusterIndex->At(i)==clsIndex) 
2286     {
2287       Float_t r = TMath::Sqrt(fResidualEta->At(i)*fResidualEta->At(i) + fResidualPhi->At(i)*fResidualPhi->At(i));
2288       if(r<tmpR) 
2289       {
2290         pos=i;
2291         tmpR=r;
2292         AliDebug(3,Form("Matched cluster index: index: %d, dEta: %2.4f, dPhi: %2.4f.\n",
2293                         fMatchedClusterIndex->At(i),fResidualEta->At(i),fResidualPhi->At(i)));
2294       }
2295     }
2296   }
2297   return pos;
2298 }
2299
2300 //____________________________________________________________________
2301 UInt_t AliEMCALRecoUtils::FindMatchedPosForTrack(Int_t trkIndex) const
2302 {
2303   //Given a track index as in AliESDEvent::GetTrack(trkIndex)
2304   //Returns the position of the match in the fMatchedTrackIndex array
2305   Float_t tmpR = fCutR;
2306   UInt_t pos = 999;
2307   
2308   for(Int_t i=0; i<fMatchedTrackIndex->GetSize(); i++) 
2309   {
2310     if(fMatchedTrackIndex->At(i)==trkIndex) 
2311     {
2312       Float_t r = TMath::Sqrt(fResidualEta->At(i)*fResidualEta->At(i) + fResidualPhi->At(i)*fResidualPhi->At(i));
2313       if(r<tmpR) 
2314       {
2315         pos=i;
2316         tmpR=r;
2317         AliDebug(3,Form("Matched track index: index: %d, dEta: %2.4f, dPhi: %2.4f.\n",
2318                         fMatchedTrackIndex->At(i),fResidualEta->At(i),fResidualPhi->At(i)));
2319       }
2320     }
2321   }
2322   return pos;
2323 }
2324
2325 //__________________________________________________________________________
2326 Bool_t AliEMCALRecoUtils::IsGoodCluster(AliVCluster *cluster, 
2327                                         const AliEMCALGeometry *geom, 
2328                                         AliVCaloCells* cells,const Int_t bc)
2329 {
2330   // check if the cluster survives some quality cut
2331   //
2332   //
2333   Bool_t isGood=kTRUE;
2334
2335   if(!cluster || !cluster->IsEMCAL())              return kFALSE;
2336   
2337   if(ClusterContainsBadChannel(geom,cluster->GetCellsAbsId(),cluster->GetNCells())) return kFALSE;
2338   
2339   if(!CheckCellFiducialRegion(geom,cluster,cells)) return kFALSE;
2340   
2341   if(IsExoticCluster(cluster, cells,bc))           return kFALSE;
2342
2343   return isGood;
2344 }
2345
2346 //__________________________________________________________
2347 Bool_t AliEMCALRecoUtils::IsAccepted(AliESDtrack *esdTrack)
2348 {
2349   // Given a esd track, return whether the track survive all the cuts
2350
2351   // The different quality parameter are first
2352   // retrieved from the track. then it is found out what cuts the
2353   // track did not survive and finally the cuts are imposed.
2354
2355   UInt_t status = esdTrack->GetStatus();
2356
2357   Int_t nClustersITS = esdTrack->GetITSclusters(0);
2358   Int_t nClustersTPC = esdTrack->GetTPCclusters(0);
2359
2360   Float_t chi2PerClusterITS = -1;
2361   Float_t chi2PerClusterTPC = -1;
2362   if (nClustersITS!=0)
2363     chi2PerClusterITS = esdTrack->GetITSchi2()/Float_t(nClustersITS);
2364   if (nClustersTPC!=0) 
2365     chi2PerClusterTPC = esdTrack->GetTPCchi2()/Float_t(nClustersTPC);
2366
2367
2368   //DCA cuts
2369   if(fTrackCutsType==kGlobalCut)
2370     {
2371       Float_t maxDCAToVertexXYPtDep = 0.0182 + 0.0350/TMath::Power(esdTrack->Pt(),1.01); //This expression comes from AliESDtrackCuts::GetStandardITSTPCTrackCuts2010()
2372       //AliDebug(3,Form("Track pT = %f, DCAtoVertexXY = %f",esdTrack->Pt(),MaxDCAToVertexXYPtDep));
2373       SetMaxDCAToVertexXY(maxDCAToVertexXYPtDep); //Set pT dependent DCA cut to vertex in x-y plane
2374     }
2375
2376
2377   Float_t b[2];
2378   Float_t bCov[3];
2379   esdTrack->GetImpactParameters(b,bCov);
2380   if (bCov[0]<=0 || bCov[2]<=0) 
2381   {
2382     AliDebug(1, "Estimated b resolution lower or equal zero!");
2383     bCov[0]=0; bCov[2]=0;
2384   }
2385
2386   Float_t dcaToVertexXY = b[0];
2387   Float_t dcaToVertexZ = b[1];
2388   Float_t dcaToVertex = -1;
2389
2390   if (fCutDCAToVertex2D)
2391     dcaToVertex = TMath::Sqrt(dcaToVertexXY*dcaToVertexXY/fCutMaxDCAToVertexXY/fCutMaxDCAToVertexXY + dcaToVertexZ*dcaToVertexZ/fCutMaxDCAToVertexZ/fCutMaxDCAToVertexZ);
2392   else
2393     dcaToVertex = TMath::Sqrt(dcaToVertexXY*dcaToVertexXY + dcaToVertexZ*dcaToVertexZ);
2394     
2395   // cut the track?
2396   
2397   Bool_t cuts[kNCuts];
2398   for (Int_t i=0; i<kNCuts; i++) cuts[i]=kFALSE;
2399   
2400   // track quality cuts
2401   if (fCutRequireTPCRefit && (status&AliESDtrack::kTPCrefit)==0)
2402     cuts[0]=kTRUE;
2403   if (fCutRequireITSRefit && (status&AliESDtrack::kITSrefit)==0)
2404     cuts[1]=kTRUE;
2405   if (nClustersTPC<fCutMinNClusterTPC)
2406     cuts[2]=kTRUE;
2407   if (nClustersITS<fCutMinNClusterITS) 
2408     cuts[3]=kTRUE;
2409   if (chi2PerClusterTPC>fCutMaxChi2PerClusterTPC) 
2410     cuts[4]=kTRUE; 
2411   if (chi2PerClusterITS>fCutMaxChi2PerClusterITS) 
2412     cuts[5]=kTRUE;  
2413   if (!fCutAcceptKinkDaughters && esdTrack->GetKinkIndex(0)>0)
2414     cuts[6]=kTRUE;
2415   if (fCutDCAToVertex2D && dcaToVertex > 1)
2416     cuts[7] = kTRUE;
2417   if (!fCutDCAToVertex2D && TMath::Abs(dcaToVertexXY) > fCutMaxDCAToVertexXY)
2418     cuts[8] = kTRUE;
2419   if (!fCutDCAToVertex2D && TMath::Abs(dcaToVertexZ) > fCutMaxDCAToVertexZ)
2420     cuts[9] = kTRUE;
2421
2422   if(fTrackCutsType==kGlobalCut)
2423     {
2424       //Require at least one SPD point + anything else in ITS
2425       if( (esdTrack->HasPointOnITSLayer(0) || esdTrack->HasPointOnITSLayer(1)) == kFALSE)
2426   cuts[10] = kTRUE;
2427     }
2428
2429       // ITS
2430   if(fCutRequireITSStandAlone || fCutRequireITSpureSA){
2431     if ((status & AliESDtrack::kITSin) == 0 || (status & AliESDtrack::kTPCin)){
2432       // TPC tracks
2433       cuts[11] = kTRUE; 
2434     }else{
2435       // ITS standalone tracks
2436       if(fCutRequireITSStandAlone && !fCutRequireITSpureSA){
2437         if(status & AliESDtrack::kITSpureSA) cuts[11] = kTRUE;
2438       }else if(fCutRequireITSpureSA){
2439         if(!(status & AliESDtrack::kITSpureSA)) cuts[11] = kTRUE;
2440       }
2441     }
2442   }
2443   
2444   Bool_t cut=kFALSE;
2445   for (Int_t i=0; i<kNCuts; i++)
2446     if (cuts[i]) { cut = kTRUE ; }
2447
2448     // cut the track
2449   if (cut) 
2450     return kFALSE;
2451   else 
2452     return kTRUE;
2453 }
2454
2455 //_____________________________________
2456 void AliEMCALRecoUtils::InitTrackCuts()
2457 {
2458   //Intilize the track cut criteria
2459   //By default these cuts are set according to AliESDtrackCuts::GetStandardTPCOnlyTrackCuts()
2460   //Also you can customize the cuts using the setters
2461   
2462   switch (fTrackCutsType)
2463   {
2464     case kTPCOnlyCut:
2465     {
2466       AliInfo(Form("Track cuts for matching: GetStandardTPCOnlyTrackCuts()"));
2467       //TPC
2468       SetMinNClustersTPC(70);
2469       SetMaxChi2PerClusterTPC(4);
2470       SetAcceptKinkDaughters(kFALSE);
2471       SetRequireTPCRefit(kFALSE);
2472       
2473       //ITS
2474       SetRequireITSRefit(kFALSE);
2475       SetMaxDCAToVertexZ(3.2);
2476       SetMaxDCAToVertexXY(2.4);
2477       SetDCAToVertex2D(kTRUE);
2478       
2479       break;
2480     }
2481       
2482     case kGlobalCut:
2483     {
2484       AliInfo(Form("Track cuts for matching: GetStandardITSTPCTrackCuts2010(kTURE)"));
2485       //TPC
2486       SetMinNClustersTPC(70);
2487       SetMaxChi2PerClusterTPC(4);
2488       SetAcceptKinkDaughters(kFALSE);
2489       SetRequireTPCRefit(kTRUE);
2490       
2491       //ITS
2492       SetRequireITSRefit(kTRUE);
2493       SetMaxDCAToVertexZ(2);
2494       SetMaxDCAToVertexXY();
2495       SetDCAToVertex2D(kFALSE);
2496       
2497       break;
2498     }
2499       
2500     case kLooseCut:
2501     {
2502       AliInfo(Form("Track cuts for matching: Loose cut w/o DCA cut"));
2503       SetMinNClustersTPC(50);
2504       SetAcceptKinkDaughters(kTRUE);
2505       
2506       break;
2507     }
2508
2509     case kITSStandAlone:
2510     {
2511       AliInfo(Form("Track cuts for matching: ITS Stand Alone tracks cut w/o DCA cut"));
2512       SetRequireITSRefit(kTRUE);
2513       SetRequireITSStandAlone(kTRUE);
2514       SetITSTrackSA(kTRUE);
2515       break;
2516     }
2517     
2518   }
2519 }
2520
2521
2522 //________________________________________________________________________
2523 void AliEMCALRecoUtils::SetClusterMatchedToTrack(const AliVEvent *event)
2524 {
2525   // Checks if tracks are matched to EMC clusters and set the matched EMCAL cluster index to ESD track. 
2526
2527   Int_t nTracks = event->GetNumberOfTracks();
2528   for (Int_t iTrack = 0; iTrack < nTracks; ++iTrack) 
2529   {
2530     AliVTrack* track = dynamic_cast<AliVTrack*>(event->GetTrack(iTrack));
2531     if (!track) 
2532     {
2533       AliWarning(Form("Could not receive track %d", iTrack));
2534       continue;
2535     }
2536     
2537     Int_t matchClusIndex = GetMatchedClusterIndex(iTrack);       
2538     track->SetEMCALcluster(matchClusIndex); //sets -1 if track not matched within residual
2539     /*the following can be done better if AliVTrack::SetStatus will be there. Patch pending with Andreas/Peter*/
2540     AliESDtrack* esdtrack = dynamic_cast<AliESDtrack*>(track);
2541     if (esdtrack) { 
2542       if(matchClusIndex != -1) 
2543         esdtrack->SetStatus(AliESDtrack::kEMCALmatch);
2544       else
2545         esdtrack->ResetStatus(AliESDtrack::kEMCALmatch);
2546     } else {
2547       AliAODTrack* aodtrack = dynamic_cast<AliAODTrack*>(track);
2548       if(matchClusIndex != -1) 
2549         aodtrack->SetStatus(AliESDtrack::kEMCALmatch);
2550       else
2551         aodtrack->ResetStatus(AliESDtrack::kEMCALmatch);
2552     }
2553
2554   }
2555   AliDebug(2,"Track matched to closest cluster");  
2556 }
2557
2558 //_________________________________________________________________________
2559 void AliEMCALRecoUtils::SetTracksMatchedToCluster(const AliVEvent *event)
2560 {
2561   // Checks if EMC clusters are matched to ESD track.
2562   // Adds track indexes of all the tracks matched to a cluster withing residuals in ESDCalocluster.
2563   
2564   for (Int_t iClus=0; iClus < event->GetNumberOfCaloClusters(); ++iClus) 
2565   {
2566     AliVCluster *cluster = event->GetCaloCluster(iClus);
2567     if (!cluster->IsEMCAL()) 
2568       continue;
2569     
2570     Int_t nTracks = event->GetNumberOfTracks();
2571     TArrayI arrayTrackMatched(nTracks);
2572     
2573     // Get the closest track matched to the cluster
2574     Int_t nMatched = 0;
2575     Int_t matchTrackIndex = GetMatchedTrackIndex(iClus);
2576     if (matchTrackIndex != -1) 
2577     {
2578       arrayTrackMatched[nMatched] = matchTrackIndex;
2579       nMatched++;
2580     }
2581     
2582     // Get all other tracks matched to the cluster
2583     for(Int_t iTrk=0; iTrk<nTracks; ++iTrk) 
2584     {
2585       AliVTrack* track = dynamic_cast<AliVTrack*>(event->GetTrack(iTrk));
2586       if(iTrk == matchTrackIndex) continue;
2587       if(track->GetEMCALcluster() == iClus)
2588       {
2589         arrayTrackMatched[nMatched] = iTrk;
2590         ++nMatched;
2591       }
2592     }
2593     
2594     //printf("Tender::SetTracksMatchedToCluster - cluster E %f, N matches %d, first match %d\n",cluster->E(),nMatched,arrayTrackMatched[0]);
2595     
2596     arrayTrackMatched.Set(nMatched);
2597     AliESDCaloCluster *esdcluster = dynamic_cast<AliESDCaloCluster*>(cluster);
2598     if (esdcluster) 
2599       esdcluster->AddTracksMatched(arrayTrackMatched);
2600     else if (nMatched>0) {
2601       AliAODCaloCluster *aodcluster = dynamic_cast<AliAODCaloCluster*>(cluster);
2602       if (aodcluster)
2603         aodcluster->AddTrackMatched(event->GetTrack(arrayTrackMatched.At(0)));
2604     }
2605     
2606     Float_t eta= -999, phi = -999;
2607     if (matchTrackIndex != -1) 
2608       GetMatchedResiduals(iClus, eta, phi);
2609     cluster->SetTrackDistance(phi, eta);
2610   }
2611   
2612   AliDebug(2,"Cluster matched to tracks");  
2613 }
2614
2615 //___________________________________________________
2616 void AliEMCALRecoUtils::Print(const Option_t *) const 
2617 {
2618   // Print Parameters
2619   
2620   printf("AliEMCALRecoUtils Settings: \n");
2621   printf("Misalignment shifts\n");
2622   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, 
2623                                   fMisalTransShift[i*3],fMisalTransShift[i*3+1],fMisalTransShift[i*3+2],
2624                                   fMisalRotShift[i*3],  fMisalRotShift[i*3+1],  fMisalRotShift[i*3+2]   );
2625   printf("Non linearity function %d, parameters:\n", fNonLinearityFunction);
2626   for(Int_t i=0; i<6; i++) printf("param[%d]=%f\n",i, fNonLinearityParams[i]);
2627   
2628   printf("Position Recalculation option %d, Particle Type %d, fW0 %2.2f, Recalibrate Data %d \n",fPosAlgo,fParticleType,fW0, fRecalibration);
2629
2630   printf("Matching criteria: ");
2631   if(fCutEtaPhiSum)
2632     {
2633       printf("sqrt(dEta^2+dPhi^2)<%4.3f\n",fCutR);
2634     }
2635   else if(fCutEtaPhiSeparate)
2636     {
2637       printf("dEta<%4.3f, dPhi<%4.3f\n",fCutEta,fCutPhi);
2638     }
2639   else
2640     {
2641       printf("Error\n");
2642       printf("please specify your cut criteria\n");
2643       printf("To cut on sqrt(dEta^2+dPhi^2), use: SwitchOnCutEtaPhiSum()\n");
2644       printf("To cut on dEta and dPhi separately, use: SwitchOnCutEtaPhiSeparate()\n");
2645     }
2646
2647   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);
2648   printf("Cluster selection window: dR < %2.0f\n",fClusterWindow);
2649
2650   printf("Track cuts: \n");
2651   printf("Minimum track pT: %1.2f\n",fCutMinTrackPt);
2652   printf("AOD track selection: tpc only %d, or hybrid %d, or mask: %d\n",fAODTPCOnlyTracks,fAODHybridTracks, fAODFilterMask);
2653   printf("TPCRefit = %d, ITSRefit = %d\n",fCutRequireTPCRefit,fCutRequireITSRefit);
2654   printf("AcceptKinks = %d\n",fCutAcceptKinkDaughters);
2655   printf("MinNCulsterTPC = %d, MinNClusterITS = %d\n",fCutMinNClusterTPC,fCutMinNClusterITS);
2656   printf("MaxChi2TPC = %2.2f, MaxChi2ITS = %2.2f\n",fCutMaxChi2PerClusterTPC,fCutMaxChi2PerClusterITS);
2657   printf("DCSToVertex2D = %d, MaxDCAToVertexXY = %2.2f, MaxDCAToVertexZ = %2.2f\n",fCutDCAToVertex2D,fCutMaxDCAToVertexXY,fCutMaxDCAToVertexZ);
2658 }
2659