updated dphi correlation analysis
[u/mrichter/AliRoot.git] / PWG2 / FORWARD / analysis2 / AliBasedNdetaTask.h
CommitLineData
ce85db45 1//
2// Task to analyse the AOD for for dN/deta in the base regions
3//
4#ifndef ALIBASEDNDETATASK_H
5#define ALIBASEDNDETATASK_H
ffca499d 6/**
7 * @file AliBasedNdetaTask.h
8 * @author Christian Holm Christensen <cholm@dalsgaard.hehi.nbi.dk>
9 * @date Wed Mar 23 13:58:12 2011
10 *
11 * @brief
12 *
13 * @ingroup pwg2_forward_dndeta
14 *
15 */
ce85db45 16#include <AliAnalysisTaskSE.h>
e308a636 17class TAxis;
ce85db45 18class TList;
19class TH2D;
20class TH1D;
ffca499d 21class TH1I;
ce85db45 22class AliAODEvent;
e1f47419 23class AliAODForwardMult;
e308a636 24class TObjArray;
ce85db45 25
ffca499d 26/**
27 * @defgroup pwg2_forward_tasks_dndeta dN/deta tasks
28 * @ingroup pwg2_forward_tasks
29 */
30/**
31 * @defgroup pwg2_forward_dndeta dN/deta
32 *
33 * @f$ dN/d\eta@f$ code
34 *
35 * @ingroup pwg2_forward_topical
36 */
ce85db45 37/**
ffca499d 38 * Base class for tasks to determine @f$ dN/d\eta@f$
39 *
40 * @ingroup pwg2_forward_tasks_dndeta
41 * @ingroup pwg2_forward_dndeta
ce85db45 42 */
43class AliBasedNdetaTask : public AliAnalysisTaskSE
44{
45public:
46 /**
ffca499d 47 * Bit mask values of the normalisation scheme
48 */
49 enum {
50 /** Only normalize to accepted events */
51 kNone = 0,
52 /**
53 * Do the full normalisation
54 * @f[
55 * N = \frac{1}{\epsilon_X}(N_A-N_A/N_V(N_T-N_V)) =
56 * \frac{1}{\epsilon_X}\frac{1}{\epsilon_V}N_A
57 * @f]
58 */
59 kEventLevel = 0x1,
60 /**
ffca499d 61 * Do the shape correction
62 */
0be6c8cd 63 kShape = 0x2,
ffca499d 64 /**
65 * Correct for background events (A+C-E). Not implemented yet
66 */
0be6c8cd 67 kBackground = 0x4,
ffca499d 68 /**
0be6c8cd 69 * Correct for the trigger efficiency from MC
ffca499d 70 */
0be6c8cd 71 kTriggerEfficiency = 0x8,
4fa8d795 72 /**
73 * Correct using zero-bin efficiency only
74 */
75 kZeroBin = 0x10,
0be6c8cd 76 /**
77 * Do the full correction
ffca499d 78 */
0be6c8cd 79 kFull = kEventLevel | kShape | kBackground | kTriggerEfficiency,
ffca499d 80 };
81 /**
ce85db45 82 * Constructor
83 *
84 */
85 AliBasedNdetaTask();
86 /**
87 * Constructor
88 *
89 * @param name Name of task
ce85db45 90 */
91 AliBasedNdetaTask(const char* name);
e1f47419 92 /**
93 * Destructor
94 *
95 */
96 virtual ~AliBasedNdetaTask();
ce85db45 97
98 /**
e1f47419 99 * @{
100 * @name Task configuration
101 */
102 /**
ce85db45 103 * Set the vertex range to use
104 *
105 * @param min Minimum (in centermeter)
106 * @param max Maximum (in centermeter)
107 */
108 void SetVertexRange(Double_t min, Double_t max) { fVtxMin=min; fVtxMax=max; }
109 /**
110 * Set the rebinning factor
111 *
112 * @param rebin Rebinning factor
113 */
114 void SetRebinning(Int_t rebin) { fRebin = rebin; }
115 /**
116 * Set the trigger maskl
117 *
118 * @param mask Trigger mask
119 */
0be6c8cd 120 void SetTriggerMask(UShort_t mask);
ce85db45 121 /**
122 * Set the trigger mask
123 *
124 * @param mask trigger mask
125 */
126 void SetTriggerMask(const char* mask);
e58000b7 127 /**
e308a636 128 * Set the centrality bins to use.
129 *
130 * @code
131 * UShort_t bins[] = { 0, 5, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 };
132 * task->SetCentralityBins(11, bins);
133 * @endcode
134 *
135 * @param n Number of bins (elements in @a bins minus 1)
136 * @param bins Bin limits
137 */
138 void SetCentralityAxis(UShort_t n, Short_t* bins);
139 /**
ffca499d 140 * Whether to cut edges when merging
e58000b7 141 *
ffca499d 142 * @param cut If true, cut edges
e58000b7 143 */
3846ec25 144 void SetCutEdges(Bool_t cut) {fCutEdges = cut;}
145 /**
c25b5e1b 146 * Set whether to correct for empty bins when projecting on the X axis.
147 *
148 * @param use Whether to correct for empty bins
149 */
150 void SetCorrEmpty(Bool_t use) { fCorrEmpty = use; }
151 /**
152 * Set whether to use the ROOT TH2::ProjectionX method when
153 * projecting on the X axis.
154 *
155 * @param use Whether to use TH2::ProjectionX
156 */
157 void SetUseROOTProjectX(Bool_t use) { fUseROOTProj = use; }
158 /**
3846ec25 159 * Trigger efficiency for selected trigger(s)
160 *
161 * @param e Trigger efficiency
162 */
e58000b7 163 void SetTriggerEff(Double_t e) { fTriggerEff = e; }
164 /**
165 * Set the shape correction (a.k.a., track correction) for selected
166 * trigger(s)
167 *
168 * @param h Correction
169 */
678a4979 170 void SetShapeCorrection(const TH1* h);
171 /**
ffca499d 172 * Setthe normalisation scheme to use
173 *
174 * @param scheme Normalisation scheme
175 */
0be6c8cd 176 void SetNormalizationScheme(UShort_t scheme);
ffca499d 177 /**
178 * Space, pipe, or comma separated list of options
179 *
180 * @param what List of options
678a4979 181 */
ffca499d 182 void SetNormalizationScheme(const char* what);
678a4979 183 /**
184 * Load the normalization data - done automatically if not set from outside
185 *
e1f47419 186 * @param sys system
187 * @param energy energy
678a4979 188 */
e1f47419 189 void LoadNormalizationData(UShort_t sys, UShort_t energy);
190 /** @} */
0be6c8cd 191 /**
192 * Print information
193 *
194 * @param option Not used
195 */
196 void Print(Option_t* option="") const;
e1f47419 197 /** @{
198 * @name Task interface
ce85db45 199 */
ce85db45 200 /**
201 * Initialise on master - does nothing
202 *
203 */
204 virtual void Init() {}
205 /**
206 * Create output objects.
207 *
208 * This is called once per slave process
209 */
210 virtual void UserCreateOutputObjects();
211 /**
212 * Process a single event
213 *
214 * @param option Not used
215 */
216 virtual void UserExec(Option_t* option);
217 /**
ffca499d 218 * Called at end of event processing.
ce85db45 219 *
220 * This is called once in the master
221 *
222 * @param option Not used
223 */
224 virtual void Terminate(Option_t* option);
ffca499d 225 /* @} */
ce85db45 226
227 /**
e1f47419 228 * @{
229 * @name Services member functions
ce85db45 230 */
ce85db45 231 /**
232 * Make a copy of the input histogram and rebin that histogram
233 *
ffca499d 234 * @param h Histogram to rebin
235 * @param rebin Rebinning factor
236 * @param cutEdges Whether to cut edges when rebinning
ce85db45 237 *
238 * @return New (rebinned) histogram
239 */
e1f47419 240 static TH1D* Rebin(const TH1D* h, Int_t rebin, Bool_t cutEdges=false);
ce85db45 241 /**
242 * Make an extension of @a h to make it symmetric about 0
243 *
244 * @param h Histogram to symmertrice
245 *
246 * @return Symmetric extension of @a h
247 */
e1f47419 248 static TH1* Symmetrice(const TH1* h);
ce85db45 249 /**
250 * Project onto the X axis
251 *
252 * @param h 2D histogram
253 * @param name New name
254 * @param firstbin First bin to use
255 * @param lastbin Last bin to use
9f773c15 256 * @param useROOT Use TH2::ProjectionX instead of custom code
ffca499d 257 * @param corr Whether to do corrections or not
ce85db45 258 * @param error Whether to calculate errors
259 *
260 * @return Newly created histogram or null
261 */
e1f47419 262 static TH1D* ProjectX(const TH2D* h,
263 const char* name,
264 Int_t firstbin,
265 Int_t lastbin,
c25b5e1b 266 bool useROOT=false,
e1f47419 267 bool corr=true,
268 bool error=true);
ce85db45 269 /**
4fa8d795 270 * Scale the copy of the 2D histogram by coverage in supplied 1D histogram
271 *
272 * @param copy Data to scale
273 * @param norm Coverage histogram
274 */
275 static void ScaleToCoverage(TH2D* copy, const TH1D* norm);
276 /**
ce85db45 277 * Set histogram graphical options, etc.
278 *
279 * @param h Histogram to modify
280 * @param colour Marker color
281 * @param marker Marker style
282 * @param title Title of histogram
283 * @param ytitle Title on y-axis.
284 */
e1f47419 285 static void SetHistogramAttributes(TH1D* h, Int_t colour, Int_t marker,
286 const char* title,
287 const char* ytitle="#frac{1}{N} #frac{dN_{ch}}{d#eta}");
288 /** @} */
289protected:
290 AliBasedNdetaTask(const AliBasedNdetaTask&);
291 AliBasedNdetaTask& operator=(const AliBasedNdetaTask&) { return *this; }
292 class CentralityBin;
293
294 /**
295 * Retrieve the histogram
296 *
297 * @param aod AOD event
298 * @param mc Whether to get the MC histogram or not
299 *
300 * @return Retrieved histogram or null
301 */
302 virtual TH2D* GetHistogram(const AliAODEvent* aod, Bool_t mc=false) = 0;
303 /**
ffca499d 304 * Get the colour to use for markers
305 *
306 * @return Marker colour
307 */
308 virtual Int_t GetColor() const { return kRed+1; }
309 /**
310 * Get the marker style
311 *
312 * @return Marker style
313 */
314 virtual Int_t GetMarker() const { return 20; }
315 /**
e308a636 316 * Add a centrality bin
317 *
ffca499d 318 * @param at Where in the list to add this bin
e308a636 319 * @param low Low cut
320 * @param high High cut
321 */
322 void AddCentralityBin(UShort_t at, Short_t low, Short_t high);
323 /**
e1f47419 324 * Make a centrality bin
325 *
326 * @param name Name used for histograms
327 * @param low Low cut in percent
328 * @param high High cut in percent
329 *
330 * @return A newly created centrality bin
331 */
332 virtual CentralityBin* MakeCentralityBin(const char* name, Short_t low,
333 Short_t high) const;
4fa8d795 334
335 //==================================================================
336 struct Sum : public TNamed
337 {
338 TH2D* fSum; // Sum of non-zero events
339 TH2D* fSum0; // Sum of zero events
340 TH1I* fEvents; // Distribution of events
341
342 Sum() : fSum(0), fSum0(0), fEvents(0) {}
343 Sum(const char* name, const char* postfix)
344 : TNamed(name,postfix),
345 fSum(0),
346 fSum0(0),
347 fEvents(0)
348 {}
349 Sum(const Sum& o)
350 : TNamed(o),
351 fSum(o.fSum),
352 fSum0(o.fSum0),
353 fEvents(o.fEvents)
354 {}
355 Sum& operator=(const Sum& o) {
356 SetName(o.GetName()); fSum = o.fSum; fSum0 = o.fSum0; fEvents=o.fEvents;
357 return *this;
358 }
359 ~Sum() {}
360 void Init(TList* list, const TH2D* data, Int_t col);
361 void Add(const TH2D* data, Bool_t isZero=false);
362 TString GetHistName(Int_t what=0) const;
363 TH2D* GetSum(const TList* l, TList* o, Double_t& ntotal,
364 Double_t zeroEff, Double_t otherEff=1, Int_t marker=20,
365 Bool_t rootXproj=false, Bool_t corrEmpty=true) const;
366 };
367
368
369
370 //==================================================================
e1f47419 371 /**
372 * Calculations done per centrality
373 *
374 */
375 struct CentralityBin : public TNamed
376 {
ffca499d 377 /** dN
e1f47419 378 * Constructor
379 */
380 CentralityBin();
381 /**
382 * Constructor
383 *
384 * @param name Name used for histograms (e.g., Forward)
385 * @param low Lower centrality cut in percent
386 * @param high Upper centrality cut in percent
387 */
388 CentralityBin(const char* name, Short_t low, Short_t high);
389 /**
390 * Copy constructor
391 *
392 * @param other Object to copy from
393 */
394 CentralityBin(const CentralityBin& other);
395 /**
396 * Destructor
397 */
398 virtual ~CentralityBin();
399 /**
400 * Assignment operator
401 *
402 * @param other Object to assign from
403 *
404 * @return Reference to this
405 */
406 CentralityBin& operator=(const CentralityBin& other);
407 /**
408 * Check if this is the 'all' bin
409 *
410 * @return true if low and high cuts are both zero
411 */
412 Bool_t IsAllBin() const { return fLow == 0 && fHigh == 0; }
413 /**
414 * Get the list name
415 *
416 * @return List Name
417 */
418 const char* GetListName() const;
419 /**
420 * Create output objects
421 *
422 * @param dir Parent list
423 */
424 virtual void CreateOutputObjects(TList* dir);
425 /**
426 * Process an event
427 *
428 * @param forward Forward data (for trigger, vertex, & centrality)
429 * @param triggerMask Trigger mask
430 * @param vzMin Minimum IP z coordinate
431 * @param vzMax Maximum IP z coordinate
432 * @param data Data histogram
433 * @param mc MC histogram
434 */
435 virtual void ProcessEvent(const AliAODForwardMult* forward,
ffca499d 436 Int_t triggerMask,
4fa8d795 437 Bool_t isZero,
ffca499d 438 Double_t vzMin,
439 Double_t vzMax,
440 const TH2D* data,
441 const TH2D* mc);
e1f47419 442 /**
b30dee70 443 * Calculate the Event-Level normalization.
444 *
445 * The full event level normalization for trigger @f$X@f$ is given by
446 * @f{eqnarray*}{
447 * N &=& \frac{1}{\epsilon_X}
448 * \left(N_A+\frac{N_A}{N_V}(N_{-V}-\beta)\right)\\
449 * &=& \frac{1}{\epsilon_X}N_A
450 * \left(1+\frac{1}{N_V}(N_T-N_V-\beta)\right)\\
451 * &=& \frac{1}{\epsilon_X}N_A
452 * \left(1+\frac{N_T}{N_V}-1-\frac{\beta}{N_V}\right)\\
453 * &=& \frac{1}{\epsilon_X}N_A
454 * \left(\frac{1}{\epsilon_V}-\frac{\beta}{N_V}\right)
455 * @f}
456 * where
457 *
458 * - @f$\epsilon_X=\frac{N_{T,X}}{N_X}@f$ is the trigger
459 * efficiency evaluated in simulation.
460 * - @f$\epsilon_V=\frac{N_V}{N_T}@f$ is the vertex efficiency
461 * evaluated from the data
462 * - @f$N_X@f$ is the Monte-Carlo truth number of events of type
463 * @f$X@f$.
464 * - @f$N_{T,X}@f$ is the Monte-Carlo truth number of events of type
465 * @f$X@f$ which was also triggered as such.
466 * - @f$N_T@f$ is the number of data events that where triggered
467 * as type @f$X@f$ and had a collision trigger (CINT1B)
468 * - @f$N_V@f$ is the number of data events that where triggered
469 * as type @f$X@f$, had a collision trigger (CINT1B), and had
470 * a vertex.
471 * - @f$N_{-V}@f$ is the number of data events that where triggered
472 * as type @f$X@f$, had a collision trigger (CINT1B), but no
473 * vertex.
474 * - @f$N_A@f$ is the number of data events that where triggered
475 * as type @f$X@f$, had a collision trigger (CINT1B), and had
476 * a vertex in the selected range.
477 * - @f$\beta=N_a+N_c-N_e@f$ is the number of control triggers that
478 * were also triggered as type @f$X@f$.
479 * - @f$N_a@f$ Number of beam-empty events also triggered as type
480 * @f$X@f$ events (CINT1-A or CINT1-AC).
481 * - @f$N_c@f$ Number of empty-beam events also triggered as type
482 * @f$X@f$ events (CINT1-C).
483 * - @f$N_e@f$ Number of empty-empty events also triggered as type
484 * @f$X@f$ events (CINT1-E).
485 *
486 * Note, that if @f$ \beta \ll N_A@f$ the last term can be ignored, and
487 * the expression simplyfies to
488 * @f[
489 * N = \frac{1}{\epsilon_X}\frac{1}{\epsilon_V}N_A
490 * @f]
491 *
492 * @param t Histogram of triggers
493 * @param scheme Normalisation scheme
494 * @param trgEff Trigger efficiency
495 * @param ntotal On return, the total number of events to normalise to.
496 *
497 * @return @f$N_A/N@f$ or negative number in case of errors.
498 */
499 virtual Double_t Normalization(const TH1I& t,
500 UShort_t scheme,
501 Double_t trgEff,
502 Double_t& ntotal) const;
503 /**
c25b5e1b 504 * Generate the dN/deta result from input
505 *
506 * @param sum Sum of 2D hists
507 * @param postfix Post fix on names
508 * @param rootProj Whether to use ROOT TH2::ProjectionX
509 * @param corrEmpty Correct for empty bins
510 * @param shapeCorr Shape correction to use
511 * @param scaler Event-level normalization scaler
512 * @param symmetrice Whether to make symmetric extensions
513 * @param rebin Whether to rebin
514 * @param cutEdges Whether to cut edges when rebinning
9f773c15 515 * @param marker Marker style
c25b5e1b 516 */
517 virtual void MakeResult(const TH2D* sum,
518 const char* postfix,
519 bool rootProj,
520 bool corrEmpty,
521 const TH1* shapeCorr,
522 Double_t scaler,
523 bool symmetrice,
524 Int_t rebin,
525 bool cutEdges,
c25b5e1b 526 Int_t marker);
527 /**
e1f47419 528 * End of processing
529 *
530 * @param sums List of sums
531 * @param results Output list of results
ffca499d 532 * @param scheme Normalisation scheme options
e1f47419 533 * @param shapeCorr Shape correction or nil
534 * @param trigEff Trigger efficiency
535 * @param symmetrice Whether to symmetrice the results
536 * @param rebin Whether to rebin the results
c25b5e1b 537 * @param rootProj If true, use TH2::ProjectionX
e1f47419 538 * @param corrEmpty Whether to correct for empty bins
539 * @param cutEdges Whether to cut edges when rebinning
e1f47419 540 * @param triggerMask Trigger mask
ffca499d 541 * @param marker Marker style
e1f47419 542 */
543 virtual void End(TList* sums,
544 TList* results,
ffca499d 545 UShort_t scheme,
e1f47419 546 const TH1* shapeCorr,
547 Double_t trigEff,
548 Bool_t symmetrice,
549 Int_t rebin,
c25b5e1b 550 Bool_t rootProj,
e1f47419 551 Bool_t corrEmpty,
552 Bool_t cutEdges,
ffca499d 553 Int_t triggerMask,
ffca499d 554 Int_t marker);
e1f47419 555 /**
556 * @{
557 * @name Access histograms
558 */
559 /**
560 * Get sum histogram
561 *
562 * @param mc If true, return MC histogram
563 *
564 * @return Sum histogram
565 */
4fa8d795 566 const Sum* GetSum(Bool_t mc=false) const { return mc ? fSumMC : fSum; }
e1f47419 567 /**
568 * Get sum histogram
569 *
570 * @param mc If true, return MC histogram
571 *
572 * @return Sum histogram
573 */
4fa8d795 574 Sum* GetSum(Bool_t mc=false) { return mc ? fSumMC : fSum; }
e1f47419 575 /**
576 * Get trigger histogram
577 *
578 * @return Trigger histogram
579 */
ffca499d 580 const TH1I* GetTriggers() const { return fTriggers; }
e1f47419 581 /**
582 * Get trigger histogram
583 *
584 * @return Trigger histogram
585 */
ffca499d 586 TH1I* GetTrigggers() { return fTriggers; }
e1f47419 587 /** @} */
5bb5d1f6 588
589 Int_t GetColor() const;
590 TList* GetResults() const { return fOutput; }
591 const char* GetResultName(Int_t rebin, Bool_t sym,
592 const char* postfix="") const;
593 TH1* GetResult(Int_t rebin, Bool_t sym,
594 const char* postfix="") const;
595
e1f47419 596 protected:
597 /**
598 * Create sum histogram
599 *
600 * @param data Data histogram to clone
601 * @param mc (optional) MC histogram to clone
602 */
603 virtual void CreateSums(const TH2D* data, const TH2D* mc);
604 /**
605 * Check the trigger, vertex, and centrality
606 *
ffca499d 607 * @param forward Event input
608 * @param triggerMask The used trigger mask
609 * @param vzMin Least @f$ v_z@f$
610 * @param vzMax Largest @f$ v_z@f$
e1f47419 611 *
612 * @return true if the event is to be used
613 */
614 virtual Bool_t CheckEvent(const AliAODForwardMult* forward,
ffca499d 615 Int_t triggerMask,
616 Double_t vzMin,
617 Double_t vzMax);
e1f47419 618 TList* fSums; // Output list
619 TList* fOutput; // Output list
4fa8d795 620 Sum* fSum; // Sum histogram
621 Sum* fSumMC; // MC sum histogram
ffca499d 622 TH1I* fTriggers; // Trigger histogram
e1f47419 623 UShort_t fLow; // Lower limit (inclusive)
624 UShort_t fHigh; // Upper limit (exclusive)
ce85db45 625
e1f47419 626 ClassDef(CentralityBin,1); // A centrality bin
627 };
ce85db45 628 TList* fSums; // Container of sums
629 TList* fOutput; // Container of outputs
ce85db45 630 Double_t fVtxMin; // Minimum v_z
631 Double_t fVtxMax; // Maximum v_z
632 Int_t fTriggerMask; // Trigger mask
633 Int_t fRebin; // Rebinning factor
634 Bool_t fCutEdges; // Whether to cut edges when rebinning
635 Bool_t fSymmetrice; // Whether to symmetrice data
636 Bool_t fCorrEmpty; // Correct for empty bins
c25b5e1b 637 Bool_t fUseROOTProj; // Whether to use ROOT's ProjectionX
e58000b7 638 Double_t fTriggerEff; // Trigger efficiency for selected trigger(s)
639 TH1* fShapeCorr; // Shape correction
e308a636 640 TObjArray* fListOfCentralities; // Centrality bins
e1f47419 641 TNamed* fSNNString; // sqrt(s_NN) string
642 TNamed* fSysString; // Collision system string
643 TH1D* fCent; // Centrality distribution
e308a636 644 TAxis* fCentAxis; // Centrality axis
ffca499d 645 UShort_t fNormalizationScheme; // Normalization scheme
0be6c8cd 646 TNamed* fSchemeString;
647 TNamed* fTriggerString;
648 ClassDef(AliBasedNdetaTask,4); // Determine multiplicity in base area
ce85db45 649};
650
651#endif
652//
653// Local Variables:
654// mode: C++
655// End:
656//