]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG3/muondep/AliAnalysisTaskMuonResolution.h
- Remove the holes in the lists of output histograms to make the merging working...
[u/mrichter/AliRoot.git] / PWG3 / muondep / AliAnalysisTaskMuonResolution.h
1 #ifndef ALIANALYSISTASKMUONRESOLUTION_H
2 #define ALIANALYSISTASKMUONRESOLUTION_H
3 /* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4  * See cxx source for full Copyright notice                               */
5
6 /// \ingroup muondep
7 /// \class AliAnalysisTaskMuonResolution
8 /// \brief Muon spectrometer resolution
9 //Author: Philippe Pillot - SUBATECH Nantes
10
11 #include <TString.h>
12 #include <TMatrixD.h>
13 #include <TF1.h>
14 #include "AliMUONConstants.h"
15 #include "AliAnalysisTaskSE.h"
16
17 class TH1;
18 class TH2;
19 class TGraphErrors;
20 class TObjArray;
21 class TList;
22 class AliMUONTrack;
23 class AliMUONTrackParam;
24 class AliMUONGeometryTransformer;
25
26 class AliAnalysisTaskMuonResolution : public AliAnalysisTaskSE {
27 public:
28   
29   AliAnalysisTaskMuonResolution();
30   AliAnalysisTaskMuonResolution(const char *name);
31   virtual ~AliAnalysisTaskMuonResolution();
32   
33   /// Set location of the default OCDB storage (if not set use "raw://")
34   void SetDefaultStorage(const char* ocdbPath) { fDefaultStorage = ocdbPath; }
35   
36   void SetStartingResolution(Int_t chId, Double_t valNB, Double_t valB);
37   void SetStartingResolution(Double_t valNB[10], Double_t valB[10]);
38   void GetStartingResolution(Double_t valNB[10], Double_t valB[10]);
39   
40   /// set the minimum momentum value of the tracks used to compute the resolution
41   void SetMinMomentum(Double_t val) { fMinMomentum = val; }
42   
43   /// set the flag to use only tracks passing the physics selection
44   void SelectPhysics(Bool_t flag = kTRUE) {fSelectPhysics = flag;}
45   
46   /// set the flag to use only tracks matched with trigger or not
47   void MatchTrigger(Bool_t flag = kTRUE) { fMatchTrig = flag; }
48   
49   /// set the flag to use only tracks passing the acceptance cuts (Rabs, eta)
50   void ApplyAccCut(Bool_t flag = kTRUE) { fApplyAccCut = flag; }
51   
52   /// Select events belonging to at least one of the trigger classes selected by the mask to fill histograms:
53   /// - if the physics selection is used, apply the mask to the trigger word returned by the physics selection
54   /// - if not, apply the mask to the trigger word built by looking for triggers listed in "fSelectTriggerClass"
55   void SelectTrigger(Bool_t flag = kTRUE, UInt_t mask = AliVEvent::kMUON) {fSelectTrigger = flag; fTriggerMask = mask;}
56   
57   /// set the extrapolation mode to get the track parameters and covariances at a given cluster:
58   /// 0 = extrapolate from the closest cluster; 1 = extrapolate from the previous cluster except between stations 2-3-4
59   void SetExtrapMode(Int_t val) { fExtrapMode = val; }
60   
61   /// set the flag to add or not the systematic shifts of the residuals to the resolution
62   void CorrectForSystematics(Bool_t flag = kTRUE) { fCorrectForSystematics = flag; }
63   
64   void ReAlign(const char* oldAlignStorage = 0x0, const char* newAlignStorage = "");
65   
66   /// return the list of summary canvases
67   TObjArray* GetCanvases() {return fCanvases;}
68   
69   /// set the flag to show the progression bar
70   void ShowProgressBar(Bool_t flag = kTRUE) {fShowProgressBar = flag;}
71   
72   /// set the flag to print the cluster resolution per chamber/DE
73   void PrintClusterRes(Bool_t perCh = kTRUE, Bool_t perDE = kFALSE) {fPrintClResPerCh = perCh; fPrintClResPerDE = perDE;}
74   
75   void FitResiduals(Bool_t flag = kTRUE);
76   
77   virtual void   UserCreateOutputObjects();
78   virtual void   UserExec(Option_t *);
79   virtual void   NotifyRun();
80   virtual void   Terminate(Option_t *);
81   
82 private:
83   
84   /// Not implemented
85   AliAnalysisTaskMuonResolution(const AliAnalysisTaskMuonResolution& rhs);
86   /// Not implemented
87   AliAnalysisTaskMuonResolution& operator = (const AliAnalysisTaskMuonResolution& rhs);
88   
89   void ModifyClusters(AliMUONTrack& track);
90   void Zoom(TH1* h, Double_t fractionCut = 0.01);
91   void ZoomLeft(TH1* h, Double_t fractionCut = 0.02);
92   void ZoomRight(TH1* h, Double_t fractionCut = 0.02);
93   void GetMean(TH1* h, Double_t& mean, Double_t& meanErr, TGraphErrors* g = 0x0, Int_t i = 0, Double_t x = 0, Bool_t zoom = kTRUE, Bool_t enableFit = kTRUE);
94   void GetRMS(TH1* h, Double_t& rms, Double_t& rmsErr, TGraphErrors* g = 0x0, Int_t i = 0, Double_t x = 0, Bool_t zoom = kTRUE);
95   void FillSigmaClusterVsP(TH2* hIn, TH2* hOut, TGraphErrors* g, Bool_t zoom = kTRUE);
96   void Cov2CovP(const AliMUONTrackParam &param, TMatrixD &covP);
97   UInt_t BuildTriggerWord(TString& FiredTriggerClasses);
98   
99 private:
100   
101   enum eResiduals {
102     kResidualPerCh_ClusterIn            = 0,  ///< cluster-track residual-X/Y distribution per chamber (cluster attached to the track)
103     kResidualPerCh_ClusterOut           = 2,  ///< cluster-track residual-X/Y distribution per chamber (cluster not attached to the track)
104     kTrackResPerCh                      = 4,  ///< track resolution-X/Y per chamber
105     kMCSPerCh                           = 6,  ///< MCS X/Y-dispersion of extrapolated track per chamber
106     kClusterRes2PerCh                   = 8,  ///< cluster X/Y-resolution per chamber
107     kResidualPerDE_ClusterIn            = 10, ///< cluster-track residual-X/Y distribution per DE (cluster attached to the track)
108     kResidualPerDE_ClusterOut           = 12, ///< cluster-track residual-X/Y distribution per DE (cluster not attached to the track)
109     kTrackResPerDE                      = 14, ///< track resolution-X/Y per DE
110     kMCSPerDE                           = 16, ///< MCS X/Y-dispersion of extrapolated track per DE
111     kResidualPerHalfCh_ClusterIn        = 18, ///< cluster-track residual-X/Y distribution per half chamber (cluster attached to the track)
112     kResidualPerHalfCh_ClusterOut       = 20, ///< cluster-track residual-X/Y distribution per half chamber (cluster not attached to the track)
113     kTrackResPerHalfCh                  = 22, ///< track resolution-X/Y per half chamber
114     kMCSPerHalfCh                       = 24, ///< MCS X/Y-dispersion of extrapolated track per half chamber
115     kLocalChi2PerCh                     = 26, ///< local chi2-X/Y/total distribution per chamber
116     kLocalChi2PerDE                     = 29  ///< local chi2-X/Y/total distribution per DE
117   };
118   
119   enum eResidualsVsP {
120     kResidualInChVsP_ClusterIn          = 0,  ///< cluster-track residual-X/Y distribution in chamber i versus momentum (cluster attached to the track)
121     kResidualInChVsP_ClusterOut         = 20  ///< cluster-track residual-X/Y distribution in chamber i versus momentum (cluster not attached to the track)
122   };
123   
124   enum eLocalChi2 {
125     kLocalChi2PerChMean                 = 0,  ///< local chi2-X/Y/total per chamber: mean
126     kLocalChi2PerDEMean                 = 3   ///< local chi2-X/Y/total per DE: mean
127   };
128   
129   enum eChamberRes {
130     kResidualPerChMean_ClusterIn        = 0,  ///< cluster-track residual-X/Y per chamber: mean (cluster in)
131     kResidualPerChMean_ClusterOut       = 2,  ///< cluster-track residual-X/Y per chamber: mean (cluster out)
132     kResidualPerChSigma_ClusterIn       = 4,  ///< cluster-track residual-X/Y per chamber: sigma (cluster in)
133     kResidualPerChSigma_ClusterOut      = 6,  ///< cluster-track residual-X/Y per chamber: sigma (cluster out)
134     kResidualPerChDispersion_ClusterOut = 8,  ///< cluster-track residual-X/Y per chamber: dispersion (cluster out)
135     kCombinedResidualPerChSigma         = 10, ///< combined cluster-track residual-X/Y per chamber
136     kCombinedResidualSigmaVsP           = 12, ///< cluster X/Y-resolution per chamber versus momentum
137     kTrackResPerChMean                  = 14, ///< track X/Y-resolution per chamber
138     kMCSPerChMean                       = 16, ///< MCS X/Y-dispersion of extrapolated track per chamber
139     kClusterResPerCh                    = 18, ///< cluster X/Y-resolution per chamber
140     kCalcClusterResPerCh                = 20, ///< calculated cluster X/Y-resolution per chamber
141     kResidualPerDEMean_ClusterIn        = 22, ///< cluster-track residual-X/Y per DE: mean (cluster in)
142     kResidualPerDEMean_ClusterOut       = 24, ///< cluster-track residual-X/Y per DE: mean (cluster out)
143     kCombinedResidualPerDESigma         = 26, ///< combined cluster-track residual-X/Y per DE
144     kClusterResPerDE                    = 28, ///< cluster X/Y-resolution per DE
145     kResidualPerHalfChMean_ClusterIn    = 30, ///< cluster-track residual-X/Y per half chamber: mean (cluster in)
146     kResidualPerHalfChMean_ClusterOut   = 32, ///< cluster-track residual-X/Y per half chamber: mean (cluster out)
147     kCombinedResidualPerHalfChSigma     = 34, ///< combined cluster-track residual-X/Y per half chamber
148     kClusterResPerHalfCh                = 36  ///< cluster X/Y-resolution per half chamber
149   };
150   
151   enum eTrackRes {
152     kUncorrPRes                         = 0,  ///< muon momentum reconstructed resolution at first cluster vs p
153     kPRes                               = 1,  ///< muon momentum reconstructed resolution at vertex vs p
154     kUncorrPtRes                        = 2,  ///< muon transverse momentum reconstructed resolution at first cluster vs p
155     kPtRes                              = 3,  ///< muon transverse momentum reconstructed resolution at vertex vs p
156     kUncorrSlopeRes                     = 4,  ///< muon slope-X/Y reconstructed resolution at first cluster vs p
157     kSlopeRes                           = 6   ///< muon slope-X/Y reconstructed resolution at vertex vs p
158   };
159   
160   enum eCanvases {
161     kResPerCh                           = 0,  ///< summary canvas
162     kResPerChVsP                        = 1,  ///< summary canvas
163     kResPerDE                           = 2,  ///< summary canvas
164     kResPerHalfCh                       = 3   ///< summary canvas
165   };
166   
167   static const Int_t fgkMinEntries; ///< minimum number of entries needed to compute resolution
168   
169   TObjArray*  fResiduals;    //!< List of residual histos
170   TObjArray*  fResidualsVsP; //!< List of residual vs. p histos
171   TObjArray*  fLocalChi2;    //!< List of plots related to local chi2 per chamber/DE
172   TObjArray*  fChamberRes;   //!< List of plots related to chamber/DE resolution
173   TObjArray*  fTrackRes;     //!< List of plots related to track resolution (p, pT, ...)
174   TObjArray*  fCanvases;     //!< List of canvases summarizing the results
175   
176   Double_t fClusterResNB[10]; ///< cluster resolution in non-bending direction
177   Double_t fClusterResB[10];  ///< cluster resolution in bending direction
178   
179   TString  fDefaultStorage;        ///< location of the default OCDB storage
180   Int_t    fNEvents;               //!< number of processed events
181   Bool_t   fShowProgressBar;       ///< show the progression bar
182   Bool_t   fPrintClResPerCh;       ///< print the cluster resolution per chamber
183   Bool_t   fPrintClResPerDE;       ///< print the cluster resolution per DE
184   TF1*     fGaus;                  ///< gaussian function to fit the residuals
185   Double_t fMinMomentum;           ///< use only tracks with momentum higher than this value
186   Bool_t   fSelectPhysics;         ///< use only tracks passing the physics selection
187   Bool_t   fMatchTrig;             ///< use only tracks matched with trigger
188   Bool_t   fApplyAccCut;           ///< use only tracks passing the acceptance cuts (Rabs, eta)
189   Bool_t   fSelectTrigger;         ///< use only tracks passing the trigger selection
190   UInt_t   fTriggerMask;           ///< trigger mask to be used when selecting tracks
191   /// extrapolation mode to get the track parameters and covariances at a given cluster:
192   /// 0 = extrapolate from the closest cluster; 1 = extrapolate from the previous cluster except between stations 2-3-4
193   Int_t    fExtrapMode;
194   Bool_t   fCorrectForSystematics; ///< add or not the systematic shifts of the residuals to the resolution
195   Bool_t   fOCDBLoaded;            //!< flag telling if the OCDB has been properly loaded or not
196   Int_t    fNDE;                   //!< total number of DE
197   Int_t    fDEIndices[1100];       //!< index of DE in histograms refered by ID
198   Int_t    fDEIds[200];            //!< ID of DE refered by index in histograms
199   Bool_t   fReAlign;               ///< flag telling wether to re-align the spectrometer or not before computing resolution
200   TString  fOldAlignStorage;       ///< location of the OCDB storage where to find old MUON/Align/Data (use the default one if empty)
201   TString  fNewAlignStorage;       ///< location of the OCDB storage where to find new MUON/Align/Data (use the default one if empty)
202   AliMUONGeometryTransformer* fOldGeoTransformer; //!< geometry transformer used to recontruct the present data
203   AliMUONGeometryTransformer* fNewGeoTransformer; //!< new geometry transformer containing the new alignment to be applied
204   
205   TList* fSelectTriggerClass; //!< list of trigger class that can be selected to fill histograms
206   
207   ClassDef(AliAnalysisTaskMuonResolution, 2); // chamber resolution analysis
208 };
209
210 //________________________________________________________________________
211 inline void AliAnalysisTaskMuonResolution::SetStartingResolution(Int_t chId, Double_t valNB, Double_t valB)
212 {
213   /// set chamber non-bending and bending resolutions
214   if (chId < 0 || chId >= AliMUONConstants::NTrackingCh()) return;
215   fClusterResNB[chId] = valNB;
216   fClusterResB[chId] = valB;
217 }
218
219 //________________________________________________________________________
220 inline void AliAnalysisTaskMuonResolution::SetStartingResolution(Double_t valNB[10], Double_t valB[10])
221 {
222   /// set chambers non-bending and bending resolutions
223   for (Int_t i = 0; i < AliMUONConstants::NTrackingCh(); i++) {
224     fClusterResNB[i] = valNB[i];
225     fClusterResB[i] = valB[i];
226   }
227 }
228
229 //________________________________________________________________________
230 inline void AliAnalysisTaskMuonResolution::GetStartingResolution(Double_t valNB[10], Double_t valB[10])
231 {
232   /// set chambers non-bending and bending resolutions
233   for (Int_t i = 0; i < AliMUONConstants::NTrackingCh(); i++) {
234     valNB[i] = fClusterResNB[i];
235     valB[i] = fClusterResB[i];
236   }
237 }
238
239 //________________________________________________________________________
240 inline void AliAnalysisTaskMuonResolution::ReAlign(const char* oldAlignStorage, const char* newAlignStorage)
241 {
242   /// Set the flag to activate the re-alignment and the specific storage where to find the old/new alignment data.
243   /// If oldAlignStorage = 0x0 we assume the spectrometer was not aligned before (default geometry)
244   /// If old(new)AlignStorage = "" we assume the old(new) alignment data are in the default storage
245   if (oldAlignStorage) fOldAlignStorage = oldAlignStorage;
246   else fOldAlignStorage = "none";
247   fNewAlignStorage = newAlignStorage;
248   fReAlign = kTRUE;
249 }
250
251 //________________________________________________________________________
252 inline void AliAnalysisTaskMuonResolution::FitResiduals(Bool_t flag)
253 {
254   /// set gaussian function to fit the residual distribution to extract the mean and the dispersion.
255   /// if not set: take the mean and the RMS of the distribution
256   if (fGaus) delete fGaus;
257   if (flag) fGaus = new TF1("fGaus","gaus");
258   else fGaus = NULL;
259 }
260
261 #endif
262