]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWGLF/FORWARD/analysis2/AliFMDHistCollector.h
Merge branch 'feature-movesplit'
[u/mrichter/AliRoot.git] / PWGLF / FORWARD / analysis2 / AliFMDHistCollector.h
CommitLineData
7984e5f7 1//
2// This class collects the event histograms into single histograms,
3// one for each ring in each vertex bin.
4//
5#ifndef ALIFMDHISTCOLLECTOR_H
6#define ALIFMDHISTCOLLECTOR_H
ffca499d 7/**
8 * @file AliFMDHistCollector.h
9 * @author Christian Holm Christensen <cholm@dalsgaard.hehi.nbi.dk>
10 * @date Wed Mar 23 14:03:01 2011
11 *
12 * @brief
13 *
14 *
bd6f5206 15 * @ingroup pwglf_forward_aod
ffca499d 16 */
7e4038b5 17#include <TNamed.h>
18#include <TList.h>
19#include <TArrayI.h>
20#include "AliForwardUtil.h"
21class AliESDFMD;
8449e3e0 22class TH2;
7e4038b5 23class TH2D;
77f97e3f 24class TH1D;
8449e3e0 25class TObjArray;
7e4038b5 26
27/**
28 * This class collects the event histograms into single histograms,
29 * one for each ring in each vertex bin.
30 *
31 * @par Input:
32 * - AliESDFMD object possibly corrected for sharing
33 *
34 * @par Output:
35 * - 5 RingHistos objects - each with a number of vertex dependent
36 * 2D histograms of the inclusive charge particle density
37 *
38 * @par HistCollector used:
171c2d71 39 * - AliFMDCorrSecondaryMap
7e4038b5 40 *
bd6f5206 41 * @ingroup pwglf_forward_algo
42 * @ingroup pwglf_forward_aod
7e4038b5 43 */
44class AliFMDHistCollector : public TNamed
45{
46public:
e1f47419 47 /**
48 * Methods to use when merging overlapping bins @f$b_1@f$, @f$b_2@f$
49 * with content @f$c_1@f$, @f$c_2@f$, and errors @f$e_1@f$,
50 * @f$e_2@f$ into bin @f$ b@f$ with content @f$c@f$ and error @f$e@f$
51 */
52 enum MergeMethod {
53 /**
54 * @f[
55 * c = \frac{1}{2}(c_1+c_2)
56 * @f]
57 * @f[
58 * e = \sqrt{e_1^2+e_2^2}
59 * @f]
60 */
61 kStraightMean,
62 /**
63 * As above, exept zero's are ignored
64 */
65 kStraightMeanNoZero,
66 /**
67 * @f[
68 * c = \frac{\frac{c_1}{e_1^2}+\frac{c_2}{e_2^2}}{
69 * \frac{1}{e_1^2}+\frac{1}{e_2^2}}
70 * @f]
71 * @f[
ffca499d 72 * e = \sqrt{\frac{1}{\frac{1}{e_1^2}+\frac{1}{e_2^2}}}
e1f47419 73 * @f]
74 */
75 kWeightedMean,
76 /**
77 * @f[
78 * c = \left\{\begin{array}{cl}
ffca499d 79 * c_1 & \mbox{if $e_1 < e_2$} \\
80 * c_2 & \mbox{otherwise}\end{array}\right.
e1f47419 81 * @f]
82 */
5ca83fee 83 kLeastError,
84 /**
85 * Just sum the signals
86 */
bfab35d9 87 kSum,
88 /**
89 * In overlaps, prefer inners, or if both are inners,
90 * do the straight mean
91 */
92 kPreferInner,
93 /**
94 * In overlaps, prefer outers, or if both are outers (doesn't happen),
95 * do the straight mean
96 */
97 kPreferOuter
98
e1f47419 99 };
100 /**
101 * How to obtain the fiducial cuts
102 */
103 enum FiducialMethod {
104 /**
105 * Select bins by fixed cut. Bins with a secondary correction
106 * less than the cut is considered as non-valid
107 */
108 kByCut,
109 /**
110 * A bin is considered non-valid, if it is less then twice as
111 * large as it's neighbors (in eta)
112 */
113 kDistance
114 };
ce731b9f 115 /**
116 * FMD ring bits for skipping
117 */
118 enum FMDRingBits {
bfab35d9 119 kFMD1I=0x01,
36ffcf83 120 kFMD1 =kFMD1I,
bfab35d9 121 kFMD2I=0x02,
122 kFMD2O=0x04,
36ffcf83 123 kFMD2 =kFMD2I|kFMD2O,
bfab35d9 124 kFMD3I=0x08,
125 kFMD3O=0x10,
126 kFMD3 =kFMD3I|kFMD3O
ce731b9f 127 };
7e4038b5 128 /**
129 * Constructor
130 */
5bb5d1f6 131 AliFMDHistCollector();
7e4038b5 132 /**
133 * Constructor
134 *
135 * @param title Name of object
136 */
5bb5d1f6 137 AliFMDHistCollector(const char* title);
7e4038b5 138 /**
139 * Copy constructor
140 *
141 * @param o Object to copy from
142 */
5bb5d1f6 143 AliFMDHistCollector(const AliFMDHistCollector& o);
7e4038b5 144
145 /**
146 * Destructor
147 */
12fffad7 148 virtual ~AliFMDHistCollector();
7e4038b5 149 /**
150 * Assignement operator
151 *
7984e5f7 152 * @param o Object to assign from
153 *
7e4038b5 154 * @return Reference to this object
155 */
156 AliFMDHistCollector& operator=(const AliFMDHistCollector&);
157 /**
158 * Intialise
159 *
ffca499d 160 * @param vtxAxis @f$ v_z@f$ axis
161 * @param etaAxis @f$ \eta@f$ axis
7e4038b5 162 */
5934a3e3 163 virtual void SetupForData(const TAxis& vtxAxis,
12fffad7 164 const TAxis& etaAxis);
7e4038b5 165 /**
166 * Do the calculations
167 *
168 * @param hists Cache of histograms
5bb5d1f6 169 * @param sums Cache to sum ring histograms in
0bd4b00f 170 * @param vtxBin Vertex bin (1 based)
7e4038b5 171 * @param out Output histogram
c8b1a7db 172 * @param cent Centrality
45533148 173 * @param eta2phi Copy eta coverage to phi acceptance
174 * @param add If true, add to internal caches
7e4038b5 175 *
176 * @return true on successs
177 */
5bb5d1f6 178 virtual Bool_t Collect(const AliForwardUtil::Histos& hists,
179 AliForwardUtil::Histos& sums,
180 UShort_t vtxBin,
4f9319f3 181 TH2D& out,
c8b1a7db 182 Double_t cent=-1.0,
45533148 183 Bool_t eta2phi=false,
184 Bool_t add=true);
12fffad7 185 /**
186 * Output diagnostic histograms to directory
187 *
188 * @param dir List to write in
189 */
5934a3e3 190 virtual void CreateOutputObjects(TList* dir);
e1f47419 191 /**
192 * Set the merge method
193 *
194 * @param m Method
195 */
196 void SetMergeMethod(MergeMethod m) { fMergeMethod = m; }
bfab35d9 197 MergeMethod GetMergeMethod() const { return fMergeMethod; }
e1f47419 198 /**
199 * Set the method for finding the fidicual area of the secondary maps
200 *
201 * @param m Method
202 */
203 void SetFiducialMethod(FiducialMethod m) { fFiducialMethod = m; }
7e4038b5 204 /**
205 * Set the number of extra bins (beyond the secondary map border)
206 * to cut away.
207 *
208 * @param n Number of bins
209 */
210 void SetNCutBins(UInt_t n=2) { fNCutBins = n; }
211 /**
212 * Set the correction cut, that is, when bins in the secondary
213 * correction maps have a value lower than this cut, they are
214 * considered uncertain and not used
215 *
216 * @param cut Cut-off
217 */
218 void SetCorrectionCut(Float_t cut=0.5) { fCorrectionCut = cut; }
ea3e5d95 219 /**
6af747ad 220 * Set FMD rings to skip. Argument should be
221 * kFirstRingToSkip|kSecondRingToSkip...
ce731b9f 222 *
223 * @param mask bit pattern
224 */
225 void SetFMDRingsToSkip(UShort_t mask) { fSkipFMDRings = mask; }
226 /**
227 * Set whether to make bg maps or not
228 *
229 * @param use make them
230 */
231 void SetMakeBGHitMaps(Bool_t use) { fBgAndHitMaps = use; }
8449e3e0 232 /**
233 * Set whether to make by-centrality sums for each ring
234 *
235 * @param use If true, make by-centrality sums
236 */
237 void SetMakeCentralitySums(Bool_t use) { fDoByCent = use; }
ce731b9f 238 /**
239 * Set the debug level. The higher the value the more output
ea3e5d95 240 *
241 * @param dbg Debug level
242 */
243 void SetDebug(Int_t dbg=1) { fDebug = dbg; }
0bd4b00f 244 /**
245 * Print information
246 *
247 * @param option Not used
248 */
249 void Print(Option_t* option="") const;
7e4038b5 250protected:
7e4038b5 251 /**
252 * Get the detector and ring from the ring index
253 *
254 * @param idx Ring index
255 * @param d On return, the detector or 0 in case of errors
256 * @param r On return, the ring id or '0' in case of errors
257 */
8449e3e0 258 static void GetDetRing(Int_t idx, UShort_t& d, Char_t& r);
7e4038b5 259 /**
260 * Get the ring index from detector number and ring identifier
261 *
262 * @param d Detector
263 * @param r Ring identifier
264 *
265 * @return ring index or -1 in case of problems
266 */
8449e3e0 267 static Int_t GetIdx(UShort_t d, Char_t r);
7e4038b5 268 /**
8449e3e0 269 * Check if the detector @a d, ring @a r is listed <i>in</i> the @a
270 * skips bit mask. If the detector/ring is in the mask, return true.
271 *
272 * That is, use case is
273 * @code
274 * for (UShort_t d=1. d<=3, d++) {
275 * UShort_t nr = (d == 1 ? 1 : 2);
276 * for (UShort_t q = 0; q < nr; q++) {
277 * Char_t r = (q == 0 ? 'I' : 'O');
278 * if (CheckSkips(d, r, skips)) continue;
279 * // Process detector/ring
280 * }
281 * }
282 * @endcode
7e4038b5 283 *
8449e3e0 284 * @param d Detector
285 * @param r Ring
286 * @param skips Mask of detector/rings to skip
7e4038b5 287 *
8449e3e0 288 * @return True if detector @a d, ring @a r is in the mask @a skips
7e4038b5 289 */
8449e3e0 290 static Bool_t CheckSkip(UShort_t d, Char_t r, UShort_t skips);
7e4038b5 291 /**
8449e3e0 292 * Check the correction
7e4038b5 293 *
8449e3e0 294 * @param m Fiducial method used
295 * @param cut Cut value
296 * @param bg Secondary map
297 * @param ie @f$\eta@f$ bin
298 * @param ip @f$\varphi@f$ bin
7e4038b5 299 *
8449e3e0 300 * @return true if OK.
7e4038b5 301 */
8449e3e0 302 static Bool_t CheckCorrection(FiducialMethod m, Double_t cut,
303 const TH2D* bg, Int_t ie, Int_t ip);
304
e1f47419 305 /**
306 * Merge bins accoring to set method
307 *
c8b1a7db 308 * @param m Merging method
e1f47419 309 * @param c Current content
310 * @param e Current error
311 * @param oc Old content
312 * @param oe Old error
313 * @param rc On return, the new content
314 * @param re On return, tne new error
315 */
8449e3e0 316 static void MergeBins(MergeMethod m,
317 Double_t c, Double_t e,
318 Double_t oc, Double_t oe,
319 Double_t& rc, Double_t& re);
5bb5d1f6 320
8449e3e0 321 //==================================================================
322 /**
323 * Structure to hold per-vertex bin cache of per-ring histograms
324 */
325 struct VtxBin : public TObject
326 {
327 /**
328 * Constructor
329 *
c8b1a7db 330 * @param index Index number
331 * @param minIpZ Least @f$IP_{z}@f$
332 * @param maxIpZ Largest @f$IP_{z}@f$
333 * @param nCut Cut on n
8449e3e0 334 */
335 VtxBin(Int_t index=0, Double_t minIpZ=999, Double_t maxIpZ=-999,
336 Int_t nCut=0);
337 /**
338 * Copy constructor
339 *
340 * @param o Object to copy from
341 */
342 VtxBin(const VtxBin& o);
343 /**
344 * Assignment operator
345 *
346 * @param o Object to assign from
347 *
348 * @return Reference to this object
349 */
350 VtxBin& operator=(const VtxBin& o);
351 /**
352 * Override to give name based on cuts
353 *
354 * @return Name
355 */
356 const Char_t* GetName() const;
357 /**
358 * Set up for data
359 *
360 * @param coverage Diagnostics histogram to be filled
c8b1a7db 361 * @param skip Skip flags
362 * @param fiducial Fiducial cut method
363 * @param cut Fiducial cut
8449e3e0 364 * @param l Parent output list
365 * @param etaAxis @f$\eta@f$ axis used
366 * @param doHitMap If true, also do a per-ring sum
367 * @param storeSecMap If true, store used secondary map
368 */
369 void SetupForData(TH2* coverage,
370 UShort_t skip,
371 FiducialMethod fiducial,
372 Double_t cut,
373 TList* l,
374 const TAxis& etaAxis,
375 Bool_t doHitMap,
376 Bool_t storeSecMap);
8449e3e0 377 /**
378 * Process one event in this vertex bin
379 *
380 * @param hists Histograms
381 * @param sums Sum histograms
382 * @param out Per-event output histogram
383 * @param sumRings Sum per ring
67a4bb96 384 * @param skipped Histogram of skipped rings
8449e3e0 385 * @param cent Event centrality
386 * @param m Merging method
387 * @param skips Which rings to skip
388 * @param byCent List (or null) of per centrality sums
c8b1a7db 389 * @param eta2phi Copy eta coverage to phi acceptance
45533148 390 * @param add If true, add to internal caches
c8b1a7db 391 *
8449e3e0 392 * @return true on success
393 */
394 Bool_t Collect(const AliForwardUtil::Histos& hists,
395 AliForwardUtil::Histos& sums,
396 TH2D& out,
397 TH2D* sumRings,
77f97e3f 398 TH1D* skipped,
8449e3e0 399 Double_t cent,
400 MergeMethod m,
401 UShort_t skips,
c8b1a7db 402 TList* byCent,
45533148 403 Bool_t eta2phi,
404 Bool_t add);
8449e3e0 405 /**
406 * Check if there's an overlap between detector @a d, ring @a r
407 * and some other ring for the given @f$\eta@f$ @a bin. If so,
408 * return the ring index. If not, return -1.
409 *
410 * @param d Current detector
411 * @param r Current ring
412 * @param bin Current @f$\eta@f$ bin
413 *
414 * @return Index of overlapping ring, or -1
415 */
416 Int_t GetOverlap(UShort_t d, Char_t r, Int_t bin) const;
417 /**
418 * Get the first and last @f$\eta@f$ bin for a detector
419 *
420 * @param d Current detector
421 * @param r Current ring
422 * @param first On return, the first @f$\eta@f$ bin
423 * @param last On return, the last @f$\eta@f$ bin
424 */
425 void GetFirstAndLast(UShort_t d, UShort_t r,
426 Int_t& first, Int_t& last) const {
427 GetFirstAndLast(GetIdx(d,r), first, last);
428 }
429 /**
430 * Get the first and last @f$\eta@f$ bin for a detector
431 *
432 * @param idx Current ring index
433 * @param first On return, the first @f$\eta@f$ bin
434 * @param last On return, the last @f$\eta@f$ bin
435 */
436 void GetFirstAndLast(Int_t idx,Int_t& first, Int_t& last) const;
437 /**
438 * Get the first @f$\eta@f$ bin
439 *
440 * @param idx Ring index (0-4)
441 *
442 * @return bin number
443 */
444 Int_t GetFirst(Int_t idx) const;
445 /**
446 * Get the last @f$\eta@f$ bin
447 *
448 * @param idx Ring index (0-4)
449 *
450 * @return bin number
451 */
452 Int_t GetLast(Int_t idx) const;
453 /**
454 * Get the first @f$\eta@f$ bin
455 *
456 * @param d Detector
457 * @param r Ring
458 *
459 * @return bin number
460 */
461 Int_t GetFirst(UShort_t d, Char_t r) const { return GetFirst(GetIdx(d,r));}
462 /**
463 * Get the last @f$\eta@f$ bin
464 *
465 * @param d Detector
466 * @param r Ring
467 *
468 * @return bin number
469 */
470 Int_t GetLast(UShort_t d, Char_t r) const { return GetLast(GetIdx(d,r));}
471
472 Int_t fIndex; // Vertex bin index
473 Double_t fLow; // Low @f$ ip_z @f$
474 Double_t fHigh; // High @f$ ip_z @f$
475 AliForwardUtil::Histos* fHitMap; // Hit map (optional)
476 TArrayI fFirstBin; // Per-ring first bin
477 TArrayI fLastBin; // Per-ring last bin
478 Int_t fNCutBins; // Number of bins to cut
479
480 // ClassDef(VtxBin,1); // Vertex bin in histogram collector
481 };
482 /**
483 * Get a vertex bin
484 *
485 * @param ivtx Bin number (1-nVz)
486 *
487 * @return Bin or null
488 */
489 VtxBin* GetVtxBin(Int_t ivtx);
490 /**
491 * Get a vertex bin
492 *
493 * @param ivtx Bin number (1-nVz)
494 *
495 * @return Bin or null
496 */
497 const VtxBin* GetVtxBin(Int_t ivtx) const;
7e4038b5 498
499 Int_t fNCutBins; // Number of additional bins to cut away
500 Float_t fCorrectionCut; // Cut-off on secondary corrections
ea3e5d95 501 Int_t fDebug; // Debug level
12fffad7 502 TList* fList; // Output list
503 TH2D* fSumRings; // Sum per ring (on y-axis)
504 TH2D* fCoverage; // Sum per ring (on y-axis)
77f97e3f 505 TH1D* fSkipped; // Skipped rings
e1f47419 506 MergeMethod fMergeMethod; // Merge methiod for overlapping bins
507 FiducialMethod fFiducialMethod; // Fidicual method
ce731b9f 508 UShort_t fSkipFMDRings; // FMD rings to ignore
509 Bool_t fBgAndHitMaps; // Make hit/bg maps or not
8449e3e0 510 TObjArray* fVtxList; //! Per-vertex list
511 TList* fByCent; // By centrality sums
512 Bool_t fDoByCent; // Whether to do by centrality sum
513 ClassDef(AliFMDHistCollector,6); // Calculate Nch density
7e4038b5 514};
515
7e4038b5 516
517#endif
518// Local Variables:
519// mode: C++
520// End:
521