]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITSMultReconstructor.h
Bug fix (Melinda)
[u/mrichter/AliRoot.git] / ITS / AliITSMultReconstructor.h
1 #ifndef ALIITSMULTRECONSTRUCTOR_H
2 #define ALIITSMULTRECONSTRUCTOR_H
3 /* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4  * See cxx source for full Copyright notice                               */
5
6 //_________________________________________________________________________
7 // 
8 //        Implementation of the ITS-SPD trackleter class
9 //
10 // It retrieves clusters in the pixels (theta and phi) and finds tracklets.
11 // These can be used to extract charged particle multiplicity from the ITS.
12 //
13 // A tracklet consists of two ITS clusters, one in the first pixel layer and 
14 // one in the second. The clusters are associated if the differences in 
15 // Phi (azimuth) and Theta (polar angle) are within fiducial windows.
16 // In case of multiple candidates the candidate with minimum
17 // distance is selected. 
18 //_________________________________________________________________________
19 #include "AliTrackleter.h"
20 #include "AliITSsegmentationSPD.h"
21 #include "TMath.h"
22
23 class TBits;
24 class TTree;
25 class TH1F;
26 class TH2F; 
27 class AliITSDetTypeRec;
28 class AliITSgeom;
29 class AliESDEvent;
30 class AliESDtrack;
31 class AliVertex;
32 class AliESDVertex;
33 class AliMultiplicity;
34 class AliRefArray;
35
36 class AliITSMultReconstructor : public AliTrackleter
37 {
38 public:
39   //
40   enum {kClTh,kClPh,kClZ,kClMC0,kClMC1,kClMC2,kClNPar};
41   enum {kTrTheta,kTrPhi,kTrDPhi,kTrDTheta,kTrLab1,kTrLab2,kClID1,kClID2,kTrNPar};
42   enum {kSCTh,kSCPh,kSCLab,kSCID,kSCNPar};   
43   enum {kITSTPC,kITSSAP,kITSTPCBit=BIT(kITSTPC),kITSSAPBit=BIT(kITSSAP)}; // RS
44   AliITSMultReconstructor();
45   virtual ~AliITSMultReconstructor();
46
47   void Reconstruct(AliESDEvent* esd, TTree* treeRP);
48   void Reconstruct(TTree* tree, Float_t* vtx, Float_t* vtxRes=0);   // old reconstructor invocation
49   void ReconstructMix(TTree* clusterTree, TTree* clusterTreeMix, Float_t* vtx, Float_t* vtrRes=0);
50   void FindTracklets(const Float_t* vtx); 
51   void LoadClusterFiredChips(TTree* tree);
52   void FlagClustersInOverlapRegions(Int_t ic1,Int_t ic2);
53   void FlagTrackClusters(Int_t id);
54   void FlagIfSecondary(AliESDtrack* track, const AliVertex* vtx);
55   void FlagV0s(const AliESDVertex *vtx);
56   void ProcessESDTracks();
57   Bool_t  CanBeElectron(const AliESDtrack* trc) const;
58   
59   virtual void CreateMultiplicityObject();
60   //
61   // Following members are set via AliITSRecoParam
62   void SetPhiWindow(Float_t w=0.08)    {fDPhiWindow=w;   fDPhiWindow2 = w*w;}
63   void SetThetaWindow(Float_t w=0.025) {fDThetaWindow=w; fDThetaWindow2=w*w;}
64   void SetPhiShift(Float_t w=0.0045) {fPhiShift=w;}
65   void SetRemoveClustersFromOverlaps(Bool_t b = kFALSE) {fRemoveClustersFromOverlaps = b;}
66   void SetPhiOverlapCut(Float_t w=0.005) {fPhiOverlapCut=w;}
67   void SetZetaOverlapCut(Float_t w=0.05) {fZetaOverlapCut=w;}
68   void SetPhiRotationAngle(Float_t w=0.0) {fPhiRotationAngle=w;}
69
70   Int_t GetNClustersLayer1() const {return fNClustersLay[0];}
71   Int_t GetNClustersLayer2() const {return fNClustersLay[1];}
72   Int_t GetNClustersLayer(Int_t i) const {return fNClustersLay[i];}
73   Int_t GetNTracklets() const {return fNTracklets;}
74   Int_t GetNSingleClusters() const {return fNSingleCluster;}
75   Short_t GetNFiredChips(Int_t layer) const {return fNFiredChips[layer];}
76
77   Float_t* GetClusterLayer1(Int_t n) {return &fClustersLay[0][n*kClNPar];}
78   Float_t* GetClusterLayer2(Int_t n) {return &fClustersLay[1][n*kClNPar];}
79   Float_t* GetClusterOfLayer(Int_t lr,Int_t n) {return &fClustersLay[lr][n*kClNPar];}
80   
81   Float_t* GetTracklet(Int_t n) {return fTracklets[n];}
82   Float_t* GetCluster(Int_t n) {return fSClusters[n];}
83
84   void     SetScaleDThetaBySin2T(Bool_t v=kTRUE)         {fScaleDTBySin2T = v;}
85   Bool_t   GetScaleDThetaBySin2T()               const   {return fScaleDTBySin2T;}
86   //
87   void     SetNStdDev(Float_t f=1.)                      {fNStdDev = f<0.01 ? 0.01 : f; fNStdDevSq=TMath::Sqrt(fNStdDev);}
88   Float_t  GetNStdDev()                          const   {return fNStdDev;}
89   //
90   void SetHistOn(Bool_t b=kFALSE) {fHistOn=b;}
91   void SaveHists();
92
93   AliITSDetTypeRec *GetDetTypeRec() const {return fDetTypeRec;}
94   void SetDetTypeRec(AliITSDetTypeRec *ptr){fDetTypeRec = ptr;}
95   //
96   void    SetCutPxDrSPDin(Float_t v=0.1)             { fCutPxDrSPDin = v;}
97   void    SetCutPxDrSPDout(Float_t v=0.15)           { fCutPxDrSPDout = v;}
98   void    SetCutPxDz(Float_t v=0.2)                  { fCutPxDz = v;}
99   void    SetCutDCArz(Float_t v=0.5)                 { fCutDCArz = v;}
100   void    SetCutMinElectronProbTPC(Float_t v=0.5)    { fCutMinElectronProbTPC = v;}
101   void    SetCutMinElectronProbESD(Float_t v=0.1)    { fCutMinElectronProbESD = v;}
102   void    SetCutMinP(Float_t v=0.05)                 { fCutMinP = v;}
103   void    SetCutMinRGamma(Float_t v=2.)              { fCutMinRGamma = v;}
104   void    SetCutMinRK0(Float_t v=1.)                 { fCutMinRK0 = v;}
105   void    SetCutMinPointAngle(Float_t v=0.98)        { fCutMinPointAngle = v;}
106   void    SetCutMaxDCADauther(Float_t v=0.5)         { fCutMaxDCADauther = v;}
107   void    SetCutMassGamma(Float_t v=0.03)            { fCutMassGamma = v;}
108   void    SetCutMassGammaNSigma(Float_t v=5.)        { fCutMassGammaNSigma = v;}
109   void    SetCutMassK0(Float_t v=0.03)               { fCutMassK0 = v;}
110   void    SetCutMassK0NSigma(Float_t v=5.)           { fCutMassK0NSigma = v;}
111   void    SetCutChi2cGamma(Float_t v=2.)             { fCutChi2cGamma = v;}
112   void    SetCutChi2cK0(Float_t v=2.)                { fCutChi2cK0 = v;}
113   void    SetCutGammaSFromDecay(Float_t v=-10.)      { fCutGammaSFromDecay = v;}
114   void    SetCutK0SFromDecay(Float_t v=-10.)         { fCutK0SFromDecay = v;}
115   void    SetCutMaxDCA(Float_t v=1.)                 { fCutMaxDCA = v;}
116   //
117   Float_t GetCutPxDrSPDin()                    const {return fCutPxDrSPDin;}
118   Float_t GetCutPxDrSPDout()                   const {return fCutPxDrSPDout;}
119   Float_t GetCutPxDz()                         const {return fCutPxDz;}
120   Float_t GetCutDCArz()                        const {return fCutDCArz;}
121   Float_t GetCutMinElectronProbTPC()           const {return fCutMinElectronProbTPC;}
122   Float_t GetCutMinElectronProbESD()           const {return fCutMinElectronProbESD;}
123   Float_t GetCutMinP()                         const {return fCutMinP;}
124   Float_t GetCutMinRGamma()                    const {return fCutMinRGamma;}
125   Float_t GetCutMinRK0()                       const {return fCutMinRK0;}
126   Float_t GetCutMinPointAngle()                const {return fCutMinPointAngle;}
127   Float_t GetCutMaxDCADauther()                const {return fCutMaxDCADauther;}
128   Float_t GetCutMassGamma()                    const {return fCutMassGamma;}
129   Float_t GetCutMassGammaNSigma()              const {return fCutMassGammaNSigma;}
130   Float_t GetCutMassK0()                       const {return fCutMassK0;}
131   Float_t GetCutMassK0NSigma()                 const {return fCutMassK0NSigma;}
132   Float_t GetCutChi2cGamma()                   const {return fCutChi2cGamma;}
133   Float_t GetCutChi2cK0()                      const {return fCutChi2cK0;}
134   Float_t GetCutGammaSFromDecay()              const {return fCutGammaSFromDecay;}
135   Float_t GetCutK0SFromDecay()                 const {return fCutK0SFromDecay;}
136   Float_t GetCutMaxDCA()                       const {return fCutMaxDCA;}
137   //
138   void  InitAux();
139   void  ClusterPos2Angles(const Float_t *vtx);
140   void  ClusterPos2Angles(Float_t *clPar, const Float_t *vtx);
141   Int_t AssociateClusterOfL1(Int_t iC1);
142   Int_t StoreTrackletForL2Cluster(Int_t iC2);
143   void  StoreL1Singles();
144   TClonesArray* GetClustersOfLayer(Int_t il)   const {return fClArr[il];}
145   void  LoadClusters()                               {LoadClusterArrays(fTreeRP);}
146   void  SetTreeRP(TTree* rp)                         {fTreeRP    = rp;}
147   void  SetTreeRPMix(TTree* rp=0)                    {fTreeRPMix = rp;}
148   Bool_t AreClustersLoaded()                   const {return fClustersLoaded;}
149   Bool_t GetCreateClustersCopy()               const {return fCreateClustersCopy;}
150   Bool_t IsRecoDone()                          const {return fRecoDone;}
151   void  SetCreateClustersCopy(Bool_t v=kTRUE)        {fCreateClustersCopy=v;}
152   //
153   Float_t* GetClustersArray(Int_t lr)          const {return (Float_t*) (lr==0) ? fClustersLay[0]:fClustersLay[1];}
154   Int_t*   GetPartnersOfL2()                   const {return (Int_t*)fPartners;}
155   Float_t* GetMinDistsOfL2()                   const {return (Float_t*)fMinDists;}
156   Double_t GetDPhiShift()                      const {return fDPhiShift;}
157   Double_t GetDPhiWindow2()                    const {return fDPhiWindow2;}
158   Double_t GetDThetaWindow2()                  const {return fDThetaWindow2;}
159   Double_t CalcDist(Double_t dphi, Double_t dtheta, Double_t theta) const; 
160   //
161  protected:
162   void   SetClustersLoaded(Bool_t v=kTRUE)           {fClustersLoaded = v;}
163   AliITSMultReconstructor(const AliITSMultReconstructor& mr);
164   AliITSMultReconstructor& operator=(const AliITSMultReconstructor& mr);
165   void              CalcThetaPhi(float dx,float dy,float dz,float &theta,float &phi) const;
166   AliITSDetTypeRec* fDetTypeRec;            //! pointer to DetTypeRec
167   AliESDEvent*      fESDEvent;              //! pointer to ESD event
168   TTree*            fTreeRP;                //! ITS recpoints
169   TTree*            fTreeRPMix;             //! ITS recpoints for mixing
170   AliRefArray*      fUsedClusLay[2][2];     //! RS: clusters usage in ESD tracks
171   //
172   Float_t*      fClustersLay[2];            //! clusters in the SPD layers of ITS 
173   Int_t*        fDetectorIndexClustersLay[2];  //! module index for clusters in ITS layers
174   Bool_t*       fOverlapFlagClustersLay[2];  //! flag for clusters in the overlap regions in ITS layers
175
176   Float_t**     fTracklets;            //! tracklets 
177   Float_t**     fSClusters;            //! single clusters (unassociated)
178   
179   Int_t         fNClustersLay[2];      // Number of clusters on each layer
180   Int_t         fNTracklets;           // Number of tracklets
181   Int_t         fNSingleCluster;       // Number of unassociated clusters
182   Short_t       fNFiredChips[2];       // Number of fired chips in the two SPD layers
183   //
184   // Following members are set via AliITSRecoParam
185   //
186   Float_t       fDPhiWindow;                   // Search window in phi
187   Float_t       fDThetaWindow;                 // Search window in theta
188   Float_t       fPhiShift;                     // Phi shift reference value (at 0.5 T) 
189   Bool_t        fRemoveClustersFromOverlaps;   // Option to skip clusters in the overlaps
190   Float_t       fPhiOverlapCut;                // Fiducial window in phi for overlap cut
191   Float_t       fZetaOverlapCut;               // Fiducial window in eta for overlap cut
192   Float_t       fPhiRotationAngle;             // Angle to rotate the inner layer cluster for combinatorial reco only 
193   //
194   Bool_t        fScaleDTBySin2T;               // use in distance definition
195   Float_t       fNStdDev;                      // number of standard deviations to keep
196   Float_t       fNStdDevSq;                    // sqrt of number of standard deviations to keep
197   //
198   // cuts for secondaries identification
199   Float_t       fCutPxDrSPDin;                 // max P*DR for primaries involving at least 1 SPD
200   Float_t       fCutPxDrSPDout;                // max P*DR for primaries not involving any SPD
201   Float_t       fCutPxDz;                      // max P*DZ for primaries
202   Float_t       fCutDCArz;                     // max DR or DZ for primares
203   //
204   // cuts for flagging tracks in V0s
205   Float_t       fCutMinElectronProbTPC;     // min probability for e+/e- PID involving TPC
206   Float_t       fCutMinElectronProbESD;     // min probability for e+/e- PID not involving TPC
207   //
208   Float_t       fCutMinP;                   // min P of V0
209   Float_t       fCutMinRGamma;              // min transv. distance from ESDVertex to V0 for gammas
210   Float_t       fCutMinRK0;                 // min transv. distance from ESDVertex to V0 for K0s
211   Float_t       fCutMinPointAngle;          // min pointing angle cosine
212   Float_t       fCutMaxDCADauther;          // max DCA of daughters at V0
213   Float_t       fCutMassGamma;              // max gamma mass
214   Float_t       fCutMassGammaNSigma;        // max standard deviations from 0 for gamma
215   Float_t       fCutMassK0;                 // max K0 mass difference from PGD value
216   Float_t       fCutMassK0NSigma;           // max standard deviations for K0 mass from PDG value
217   Float_t       fCutChi2cGamma;             // max constrained chi2 cut for gammas
218   Float_t       fCutChi2cK0;                // max constrained chi2 cut for K0s
219   Float_t       fCutGammaSFromDecay;        // min path*P for gammas
220   Float_t       fCutK0SFromDecay;           // min path*P for K0s
221   Float_t       fCutMaxDCA;                 // max DCA for V0 at ESD vertex  
222
223   Bool_t        fHistOn;               // Option to define and fill the histograms 
224
225   TH1F*         fhClustersDPhiAcc;     // Phi2 - Phi1 for tracklets 
226   TH1F*         fhClustersDThetaAcc;   // Theta2 - Theta1 for tracklets 
227   TH1F*         fhClustersDPhiAll;     // Phi2 - Phi1 all the combinations 
228   TH1F*         fhClustersDThetaAll;   // Theta2 - Theta1 all the combinations
229  
230   TH2F*         fhDPhiVsDThetaAll;     // 2D plot for all the combinations  
231   TH2F*         fhDPhiVsDThetaAcc;     // same plot for tracklets 
232
233   TH1F*         fhetaTracklets;        // Pseudorapidity distr. for tracklets 
234   TH1F*         fhphiTracklets;        // Azimuthal (Phi) distr. for tracklets  
235   TH1F*         fhetaClustersLay1;     // Pseudorapidity distr. for Clusters L. 1
236   TH1F*         fhphiClustersLay1;     // Azimuthal (Phi) distr. for Clusters L. 1 
237
238   // temporary stuff for single event trackleting
239   Double_t      fDPhiShift;            // shift in dphi due to the curvature
240   Double_t      fDPhiWindow2;          // phi window^2
241   Double_t      fDThetaWindow2;        // theta window^2
242   Int_t*        fPartners;             //! L2 partners of L1
243   Int_t*        fAssociatedLay1;       //! association flag
244   Float_t*      fMinDists;             //! smallest distances for L2->L1
245   AliRefArray*  fBlackList;            //! blacklisted cluster references
246   Bool_t        fStoreRefs[2][2];      //! which cluster to track refs to store
247   //
248   // this is for the analysis mode only
249   TClonesArray  *fClArr[2];            //! original clusters
250   Bool_t        fCreateClustersCopy;   //  read and clone clusters directly from the tree
251   Bool_t        fClustersLoaded;       // flag of clusters loaded
252   Bool_t        fRecoDone;             // flag that reconstruction is done
253   //
254   AliITSsegmentationSPD fSPDSeg;       // SPD segmentation model
255   //
256   void LoadClusterArrays(TTree* tree, TTree* treeMix=0);
257   void LoadClusterArrays(TTree* tree,int il);
258
259   ClassDef(AliITSMultReconstructor,10)
260 };
261
262 //____________________________________________________________________
263 inline void AliITSMultReconstructor::ClusterPos2Angles(Float_t *clPar, const Float_t *vtx)
264 {
265   // convert cluster coordinates to angles wrt vertex
266   Float_t x = clPar[kClTh] - vtx[0];
267   Float_t y = clPar[kClPh] - vtx[1];
268   Float_t z = clPar[kClZ]  - vtx[2];
269   Float_t r    = TMath::Sqrt(x*x + y*y + z*z);
270   clPar[kClTh] = TMath::ACos(z/r);                   // Store Theta
271   clPar[kClPh] = TMath::Pi() + TMath::ATan2(-y,-x);  // Store Phi 
272   //
273 }
274
275 //____________________________________________________________________
276 inline Double_t AliITSMultReconstructor::CalcDist(Double_t dphi, Double_t dtheta, Double_t theta) const
277 {
278   // calculate eliptical distance. theta is the angle of cl1, dtheta = tht(cl1)-tht(cl2)
279   dphi = TMath::Abs(dphi) - fDPhiShift;
280   if (fScaleDTBySin2T) {
281     double sinTI = TMath::Sin(theta-dtheta/2);
282     sinTI *= sinTI;
283     dtheta /= sinTI>1.e-6 ? sinTI : 1.e-6;
284   }
285   return dphi*dphi/fDPhiWindow2 + dtheta*dtheta/fDThetaWindow2;
286 }
287
288 //____________________________________________________________________
289 inline void AliITSMultReconstructor::CalcThetaPhi(float x, float y,float z,float &theta,float &phi) const
290 {
291   // get theta and phi in tracklet convention
292   theta = TMath::ACos(z/TMath::Sqrt(x*x + y*y + z*z));
293   phi   = TMath::Pi() + TMath::ATan2(-y,-x);
294 }
295
296
297 #endif