]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGLF/FORWARD/analysis2/AliForwardMultDists.h
Merge branch 'master' of https://git.cern.ch/reps/AliRoot
[u/mrichter/AliRoot.git] / PWGLF / FORWARD / analysis2 / AliForwardMultDists.h
1 #ifndef ALIFORWARDMULTDIST_H
2 #define ALIFORWARDMULTDIST_H
3 /**
4  * @file   AliForwardMultDists.h
5  * @author Christian Holm Christensen <cholm@nbi.dk>
6  * @date   Tue Nov 12 09:57:28 2013
7  * 
8  * @brief  Class to make raw @f$P(N_{ch})@f$ distributions 
9  * 
10  * @ingroup pwglf_forward_multdist 
11  */
12
13 #include "AliBaseAODTask.h"
14 #include <TList.h>
15 #include <TString.h>
16 class TH1;
17 class TH2;
18 class AliAODForwardMult;
19
20 /**
21  * Class to make raw @f$ P(N_{ch})@f$ distributions 
22  * 
23  * @ingroup pwglf_forward_multdist
24  */
25 class AliForwardMultDists : public AliBaseAODTask
26 {
27 public:
28   enum { 
29     /** Mark for invalid pseudo-rapidity */
30     kInvalidEta = 999
31   };
32   /** 
33    * Histogram enumeration 
34    */
35   enum { 
36     /** Measured */
37     kAnalysis = 1, 
38     /** MC-truth */
39     kMC       = 2, 
40     /** MC-truth Triggered */
41     kTrigger  = 3, 
42     /** MC-truth w/vertex */
43     kVertex   = 4, 
44     /** MC-truth triggered and w/vertex */
45     kTriggerVertex = 5
46   };
47   /**
48    * Structure to define @f$\eta@f$ bins with an @f$ N_{ch}@f$ axis 
49    */
50   struct BinSpec 
51   {
52     /** 
53      * Constructor
54      * 
55      * @param etaMin Low cut on @f$\eta@f$
56      * @param etaMax High cut on @f$\eta@f$
57      * @param nchLow Lowest @f$ N_{ch}@f$ (e.g., -0.5);
58      */
59     BinSpec(Double_t etaMin, Double_t etaMax, Double_t nchLow);
60     /** 
61      * Push @a n bins of with @a d in @f$ N_{ch}@f$ onto the axis 
62      * 
63      * If only a single push is done, then we will get an axis of
64      * equally sized bins (@a d) from @f$ l@f$ edge to @f$ nd+low@f$ -
65      * e.g., if one only does 
66      *
67      * @code
68      * BinSpec b(e1, e2, -.5);
69      * b.Push(10, 1);
70      * @endcode 
71      *
72      * One ends up with 10 bins from -0.5 to 9.5. 
73      *
74      * @param n Number of bins to push
75      * @param d Bin width of each of the bins
76      */
77     void Push(UShort_t n, Double_t d);
78     /** 
79      * Get the axis computed from the setup using Push
80      * 
81      * @return Reference to the axis 
82      */
83     const TAxis& Axis() const;
84     Double_t fEtaMin; // Least pseudo-rapidity
85     Double_t fEtaMax; // Largest pseudo-rapidity
86     Double_t fLow;    // Low cut 
87     TArrayI  fN;      // Number of bins
88     TArrayD  fD;      // Bin widths 
89     mutable TAxis    fAxis; // Our axis 
90   };
91
92   /** 
93    * Default constructor
94    */
95   AliForwardMultDists();
96   /** 
97    * User constructor 
98    * 
99    * @param name Name of the task 
100    */
101   AliForwardMultDists(const char* name);
102   /** 
103    * Destructor
104    */
105   virtual ~AliForwardMultDists() {}
106   /** 
107    * @{ 
108    * @name Interface memer functions 
109    */
110   /** 
111    * Create output objects - called at start of job in slave 
112    * 
113    * @return true on success
114    */
115   Bool_t Book();
116   /** 
117    * Set-up internal structures on first seen event 
118    * 
119    * @return true on success
120    */
121   Bool_t PreData();
122   /** 
123    * Executed before every event 
124    * 
125    * @return true on success
126    */
127   Bool_t PreEvent() { fIsSelected = false; return true; }
128   /** 
129    * Analyse a single event 
130    * 
131    * @param aod AOD Event
132    *
133    * @return true on success
134    */
135   Bool_t Event(AliAODEvent& aod);
136   /** 
137    * Called at the end of the final processing of the job on the
138    * full data set (merged data)
139    * 
140    * @return true on success
141    */
142   Bool_t Finalize();
143   /* @} */
144   /**
145    * @{
146    * @name Bin definitions 
147    */
148   /** 
149    * Add an @f$ \eta@f$ bin
150    * 
151    * @param spec Bin specification 
152    */
153   void AddBin(const BinSpec& spec);
154   /** 
155    * Add an @f$ \eta@f$ bin.
156    * 
157    * @param etaLow Low cut on @f$\eta@f$  
158    * @param etaMax High cut on @f$\eta@f$ 
159    * @param nAxis  Axis to use for measured @f$ N_{ch}@f$ 
160    */
161   void AddBin(Double_t etaLow, Double_t etaMax, const TAxis& nAxis); 
162   /** 
163    * Add an @f$\eta@f$ bin
164    * 
165    * @param etaLow Low cut on @f$\eta@f$ 
166    * @param etaMax High cut on @f$\eta@f$ 
167    * @param nMax   Maximum @f$ N_{ch}@f$ 
168    * @param nDiv   Number of subdivisions per @f$ N_{ch}@f$
169    *
170    */
171   void AddBin(Double_t etaLow, Double_t etaMax, UShort_t nMax, UShort_t nDiv); 
172   /* @} */
173   /** 
174    * Whether to use the stored phi acceptance 
175    * 
176    * @param use If true, use stored phi acceptance 
177    */
178   void SetUsePhiAcc(Bool_t use) { fUsePhiAcc = use; }
179   /** 
180    * Print this task 
181    * 
182    * @param option Not used
183    */
184   void Print(Option_t* option="") const;
185 protected:
186   /** 
187    * Project a 2D histogram into a 1D histogram taking care to use
188    * either the @f$\phi@f$ acceptance stored in the overflow bins, or
189    * the @f$\eta@f$ coverage stored in the underflow bins.
190    * 
191    * @param input      2D histogram to project 
192    * @param cache      1D histogram to project into 
193    * @param usePhiAcc  If true, use the @f$\phi@f$ acceptance stored in
194    * the overflow bins, or if false the @f$\eta@f$ coverage stored in
195    * the underflow bins.
196    */
197   static void ProjectX(const TH2& input, TH1& cache, Bool_t usePhiAcc=true);
198   /** 
199    * Project on @f$\eta@f$ axis.  If any of the pointers passed is
200    * zero, do nothing.
201    * 
202    * @param input 
203    * @param cache 
204    */
205   static void ProjectX(const TH2* input, TH1* cache);
206   /** 
207    * An @f$\eta@f$ bin 
208    */
209   struct EtaBin : public TObject
210   {
211     /** 
212      * I/O constructor
213      */
214     EtaBin();
215     /** 
216      * User constructor 
217      * 
218      * @param minEta Least @f$\eta@f$ to consider 
219      * @param maxEta Largest @f$\eta@f$ to consider 
220      * @param mAxis  The @f$ N_{ch}@f$ axis to use for measured data 
221      */
222     EtaBin(Double_t minEta, Double_t maxEta, const TAxis& mAxis); 
223     /** 
224      * Copy constructor
225      *
226      * @param o object to copy fron
227      */
228     EtaBin(const EtaBin& o);
229     /** 
230      * Assignment operator
231      * 
232      * @param o object to assign from 
233      *
234      * @return Reference to this object
235      */
236     EtaBin& operator=(const EtaBin& o);
237     /** 
238      * Destructor
239      */
240     virtual ~EtaBin() {}
241     /** 
242      * Get the name of the bin
243      */
244     const char* GetName() const { return fName.Data(); }
245     /** 
246      * Is this bin symmetric around 0?
247      */
248     Bool_t IsSymmetric() const;
249     /** 
250      * Is this bin positive only?
251      */
252     Bool_t IsNegative() const;
253     /** 
254      * Is this bin positive only?
255      */
256     Bool_t IsPositive() const;
257     /** 
258      * Get parent container name 
259      * 
260      * 
261      * @return Parent container name
262      */
263     const char* ParentName() const;
264     /** 
265      * Find the parent container.  if not found, and @a create is
266      * true, then make the container.
267      * 
268      * @param l       Top container 
269      * @param create  If true, create container if not found
270      * 
271      * @return Container, or null
272      */
273     TList* FindParent(TList* l, Bool_t create=true) const;
274     /** 
275      * Create a 1D histogram with specified axis 
276      * 
277      * @param name  Name of histogram 
278      * @param title Title of histogram 
279      * @param xAxis X-axis to use 
280      * 
281      * @return Created histogram
282      */
283     static TH1* CreateH1(const char* name, const char* title, 
284                          const TAxis& xAxis);
285     /** 
286      * Create a 2D histogram with specified axis 
287      * 
288      * @param name  Name of histogram 
289      * @param title Title of histogram 
290      * @param xAxis X-axis to use 
291      * @param yAxis Y-axis to use 
292      * 
293      * @return Created histogram
294      */
295     static TH2* CreateH2(const char* name, const char* title, 
296                          const TAxis& xAxis, const TAxis& yAxis);
297     /** 
298      * Set-up internal structures on first event. 
299      * 
300      * @param list  List to add information to
301      * @param hist  Template histogram 
302      * @param useMC Whether to set-up for MC input 
303      */
304     void SetupForData(TList* list, const TH2& hist, Bool_t useMC);
305     /** 
306      * Process a single event 
307      * 
308      * @param sumForward  Projection of forward data
309      * @param sumCentral  Projection of the central data
310      * @param forward     The original forward data 
311      * @param central     The original central data
312      * @param accepted    True if event is accepted for analysis
313      * @param mc          Distribution of primary particles from MC
314      */
315     void Process(const TH1& sumForward, const TH1& sumCentral,
316                  const TH2& forward,    const TH2& central,
317                  Bool_t     accepted,   const TH1* mc);
318     /** 
319      * Called at the end of the final processing of the job on the
320      * full data set (merged data)
321      * 
322      * @param in    Input list
323      * @param out   Output list 
324      */
325     void Terminate(TList* in, TList* out);
326       
327     TString  fName;          // Name of this bin
328     TAxis    fMAxis;         // Axis used for measured Nch
329     TAxis    fTAxis;         // Axis used for true Nch
330     Double_t fMinEta;        // Least @f$\eta@f$ to consider
331     Double_t fMaxEta;        // Largest @f$\eta@f$ to consider
332     Int_t    fMinBin;        // Least @f$\eta@f$ bin to consider
333     Int_t    fMaxBin;        // Largest @f$\eta@f$ bin to consider
334     TH1*     fSum;           // Distribution 
335     TH2*     fCorr;          // Correlation between forward and central
336     TH2*     fResponse;      // Response matrix (for MC)
337     TH1*     fTruth;         // `true' distribution 
338     TH1*     fTruthAccepted; // `true' distribution for accepted events
339     TH1*     fCoverage;      // How much was covered
340
341     ClassDef(EtaBin,2);
342   };
343   /** 
344    * Copy constructor
345    *
346    * @param o object to copy fron
347    */
348   AliForwardMultDists(const AliForwardMultDists& o);
349   /** 
350    * Assignment operator
351    * 
352    * @param o object to assign from 
353    *
354    * @return Reference to this object
355    */
356   AliForwardMultDists& operator=(const AliForwardMultDists& o);
357   /** 
358    * Check the event 
359    * 
360    * @param fwd Forward data structure 
361    * 
362    * @return Always true 
363    */
364   Bool_t CheckEvent(const AliAODForwardMult& fwd);
365
366   TList    fBins;         // List of bins 
367   TList*   fSymmetric;    // Bins symmetric around 0
368   TList*   fNegative;     // Bins on negative side only 
369   TList*   fPositive;     // Bins on the positive side only
370   TH1*     fMCVertex;     // Histogram of MC IpZ
371   TH2*     fDiag;         // Diagnostics
372   TH1*     fForwardCache; // Projection cache 
373   TH1*     fCentralCache; // Projection cache 
374   TH1*     fMCCache;      // Projection cache 
375   Bool_t   fUsePhiAcc;    // If true, scale by phi acceptance 
376   Bool_t   fIsSelected;   // IF the even was selected
377
378   ClassDef(AliForwardMultDists,1);
379 };
380
381 #endif
382 // Local Variables:
383 //  mode: C++
384 // End:
385
386