2 // This class collects the event histograms into single histograms,
3 // one for each ring in each vertex bin.
5 #ifndef ALIFMDHISTCOLLECTOR_H
6 #define ALIFMDHISTCOLLECTOR_H
8 * @file AliFMDHistCollector.h
9 * @author Christian Holm Christensen <cholm@dalsgaard.hehi.nbi.dk>
10 * @date Wed Mar 23 14:03:01 2011
15 * @ingroup pwglf_forward_aod
20 #include "AliForwardUtil.h"
28 * This class collects the event histograms into single histograms,
29 * one for each ring in each vertex bin.
32 * - AliESDFMD object possibly corrected for sharing
35 * - 5 RingHistos objects - each with a number of vertex dependent
36 * 2D histograms of the inclusive charge particle density
38 * @par HistCollector used:
39 * - AliFMDCorrSecondaryMap
41 * @ingroup pwglf_forward_algo
42 * @ingroup pwglf_forward_aod
44 class AliFMDHistCollector : public TNamed
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$
55 * c = \frac{1}{2}(c_1+c_2)
58 * e = \sqrt{e_1^2+e_2^2}
63 * As above, exept zero's are ignored
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}}
72 * e = \sqrt{\frac{1}{\frac{1}{e_1^2}+\frac{1}{e_2^2}}}
78 * c = \left\{\begin{array}{cl}
79 * c_1 & \mbox{if $e_1 < e_2$} \\
80 * c_2 & \mbox{otherwise}\end{array}\right.
85 * Just sum the signals
89 * In overlaps, prefer inners, or if both are inners,
90 * do the straight mean
94 * In overlaps, prefer outers, or if both are outers (doesn't happen),
95 * do the straight mean
101 * How to obtain the fiducial cuts
103 enum FiducialMethod {
105 * Select bins by fixed cut. Bins with a secondary correction
106 * less than the cut is considered as non-valid
110 * A bin is considered non-valid, if it is less then twice as
111 * large as it's neighbors (in eta)
116 * FMD ring bits for skipping
123 kFMD2 =kFMD2I|kFMD2O,
131 AliFMDHistCollector();
135 * @param title Name of object
137 AliFMDHistCollector(const char* title);
141 * @param o Object to copy from
143 AliFMDHistCollector(const AliFMDHistCollector& o);
148 virtual ~AliFMDHistCollector();
150 * Assignement operator
152 * @param o Object to assign from
154 * @return Reference to this object
156 AliFMDHistCollector& operator=(const AliFMDHistCollector&);
160 * @param vtxAxis @f$ v_z@f$ axis
161 * @param etaAxis @f$ \eta@f$ axis
163 virtual void SetupForData(const TAxis& vtxAxis,
164 const TAxis& etaAxis);
166 * Do the calculations
168 * @param hists Cache of histograms
169 * @param sums Cache to sum ring histograms in
170 * @param vtxBin Vertex bin (1 based)
171 * @param out Output histogram
172 * @param cent Centrality
173 * @param eta2phi Copy eta coverage to phi acceptance
175 * @return true on successs
177 virtual Bool_t Collect(const AliForwardUtil::Histos& hists,
178 AliForwardUtil::Histos& sums,
182 Bool_t eta2phi=false);
184 * Output diagnostic histograms to directory
186 * @param dir List to write in
188 virtual void CreateOutputObjects(TList* dir);
190 * Set the merge method
194 void SetMergeMethod(MergeMethod m) { fMergeMethod = m; }
195 MergeMethod GetMergeMethod() const { return fMergeMethod; }
197 * Set the method for finding the fidicual area of the secondary maps
201 void SetFiducialMethod(FiducialMethod m) { fFiducialMethod = m; }
203 * Set the number of extra bins (beyond the secondary map border)
206 * @param n Number of bins
208 void SetNCutBins(UInt_t n=2) { fNCutBins = n; }
210 * Set the correction cut, that is, when bins in the secondary
211 * correction maps have a value lower than this cut, they are
212 * considered uncertain and not used
216 void SetCorrectionCut(Float_t cut=0.5) { fCorrectionCut = cut; }
218 * Set FMD rings to skip. Argument should be
219 * kFirstRingToSkip|kSecondRingToSkip...
221 * @param mask bit pattern
223 void SetFMDRingsToSkip(UShort_t mask) { fSkipFMDRings = mask; }
225 * Set whether to make bg maps or not
227 * @param use make them
229 void SetMakeBGHitMaps(Bool_t use) { fBgAndHitMaps = use; }
231 * Set whether to make by-centrality sums for each ring
233 * @param use If true, make by-centrality sums
235 void SetMakeCentralitySums(Bool_t use) { fDoByCent = use; }
237 * Set the debug level. The higher the value the more output
239 * @param dbg Debug level
241 void SetDebug(Int_t dbg=1) { fDebug = dbg; }
245 * @param option Not used
247 void Print(Option_t* option="") const;
250 * Get the detector and ring from the ring index
252 * @param idx Ring index
253 * @param d On return, the detector or 0 in case of errors
254 * @param r On return, the ring id or '0' in case of errors
256 static void GetDetRing(Int_t idx, UShort_t& d, Char_t& r);
258 * Get the ring index from detector number and ring identifier
261 * @param r Ring identifier
263 * @return ring index or -1 in case of problems
265 static Int_t GetIdx(UShort_t d, Char_t r);
267 * Check if the detector @a d, ring @a r is listed <i>in</i> the @a
268 * skips bit mask. If the detector/ring is in the mask, return true.
270 * That is, use case is
272 * for (UShort_t d=1. d<=3, d++) {
273 * UShort_t nr = (d == 1 ? 1 : 2);
274 * for (UShort_t q = 0; q < nr; q++) {
275 * Char_t r = (q == 0 ? 'I' : 'O');
276 * if (CheckSkips(d, r, skips)) continue;
277 * // Process detector/ring
284 * @param skips Mask of detector/rings to skip
286 * @return True if detector @a d, ring @a r is in the mask @a skips
288 static Bool_t CheckSkip(UShort_t d, Char_t r, UShort_t skips);
290 * Check the correction
292 * @param m Fiducial method used
293 * @param cut Cut value
294 * @param bg Secondary map
295 * @param ie @f$\eta@f$ bin
296 * @param ip @f$\varphi@f$ bin
298 * @return true if OK.
300 static Bool_t CheckCorrection(FiducialMethod m, Double_t cut,
301 const TH2D* bg, Int_t ie, Int_t ip);
304 * Merge bins accoring to set method
306 * @param m Merging method
307 * @param c Current content
308 * @param e Current error
309 * @param oc Old content
310 * @param oe Old error
311 * @param rc On return, the new content
312 * @param re On return, tne new error
314 static void MergeBins(MergeMethod m,
315 Double_t c, Double_t e,
316 Double_t oc, Double_t oe,
317 Double_t& rc, Double_t& re);
319 //==================================================================
321 * Structure to hold per-vertex bin cache of per-ring histograms
323 struct VtxBin : public TObject
328 * @param index Index number
329 * @param minIpZ Least @f$IP_{z}@f$
330 * @param maxIpZ Largest @f$IP_{z}@f$
331 * @param nCut Cut on n
333 VtxBin(Int_t index=0, Double_t minIpZ=999, Double_t maxIpZ=-999,
338 * @param o Object to copy from
340 VtxBin(const VtxBin& o);
342 * Assignment operator
344 * @param o Object to assign from
346 * @return Reference to this object
348 VtxBin& operator=(const VtxBin& o);
350 * Override to give name based on cuts
354 const Char_t* GetName() const;
358 * @param coverage Diagnostics histogram to be filled
359 * @param skip Skip flags
360 * @param fiducial Fiducial cut method
361 * @param cut Fiducial cut
362 * @param l Parent output list
363 * @param etaAxis @f$\eta@f$ axis used
364 * @param doHitMap If true, also do a per-ring sum
365 * @param storeSecMap If true, store used secondary map
367 void SetupForData(TH2* coverage,
369 FiducialMethod fiducial,
372 const TAxis& etaAxis,
376 * Process one event in this vertex bin
378 * @param hists Histograms
379 * @param sums Sum histograms
380 * @param out Per-event output histogram
381 * @param sumRings Sum per ring
382 * @param skipped Histogram of skipped rings
383 * @param cent Event centrality
384 * @param m Merging method
385 * @param skips Which rings to skip
386 * @param byCent List (or null) of per centrality sums
387 * @param eta2phi Copy eta coverage to phi acceptance
389 * @return true on success
391 Bool_t Collect(const AliForwardUtil::Histos& hists,
392 AliForwardUtil::Histos& sums,
402 * Check if there's an overlap between detector @a d, ring @a r
403 * and some other ring for the given @f$\eta@f$ @a bin. If so,
404 * return the ring index. If not, return -1.
406 * @param d Current detector
407 * @param r Current ring
408 * @param bin Current @f$\eta@f$ bin
410 * @return Index of overlapping ring, or -1
412 Int_t GetOverlap(UShort_t d, Char_t r, Int_t bin) const;
414 * Get the first and last @f$\eta@f$ bin for a detector
416 * @param d Current detector
417 * @param r Current ring
418 * @param first On return, the first @f$\eta@f$ bin
419 * @param last On return, the last @f$\eta@f$ bin
421 void GetFirstAndLast(UShort_t d, UShort_t r,
422 Int_t& first, Int_t& last) const {
423 GetFirstAndLast(GetIdx(d,r), first, last);
426 * Get the first and last @f$\eta@f$ bin for a detector
428 * @param idx Current ring index
429 * @param first On return, the first @f$\eta@f$ bin
430 * @param last On return, the last @f$\eta@f$ bin
432 void GetFirstAndLast(Int_t idx,Int_t& first, Int_t& last) const;
434 * Get the first @f$\eta@f$ bin
436 * @param idx Ring index (0-4)
440 Int_t GetFirst(Int_t idx) const;
442 * Get the last @f$\eta@f$ bin
444 * @param idx Ring index (0-4)
448 Int_t GetLast(Int_t idx) const;
450 * Get the first @f$\eta@f$ bin
457 Int_t GetFirst(UShort_t d, Char_t r) const { return GetFirst(GetIdx(d,r));}
459 * Get the last @f$\eta@f$ bin
466 Int_t GetLast(UShort_t d, Char_t r) const { return GetLast(GetIdx(d,r));}
468 Int_t fIndex; // Vertex bin index
469 Double_t fLow; // Low @f$ ip_z @f$
470 Double_t fHigh; // High @f$ ip_z @f$
471 AliForwardUtil::Histos* fHitMap; // Hit map (optional)
472 TArrayI fFirstBin; // Per-ring first bin
473 TArrayI fLastBin; // Per-ring last bin
474 Int_t fNCutBins; // Number of bins to cut
476 // ClassDef(VtxBin,1); // Vertex bin in histogram collector
481 * @param ivtx Bin number (1-nVz)
483 * @return Bin or null
485 VtxBin* GetVtxBin(Int_t ivtx);
489 * @param ivtx Bin number (1-nVz)
491 * @return Bin or null
493 const VtxBin* GetVtxBin(Int_t ivtx) const;
495 Int_t fNCutBins; // Number of additional bins to cut away
496 Float_t fCorrectionCut; // Cut-off on secondary corrections
497 Int_t fDebug; // Debug level
498 TList* fList; // Output list
499 TH2D* fSumRings; // Sum per ring (on y-axis)
500 TH2D* fCoverage; // Sum per ring (on y-axis)
501 TH1D* fSkipped; // Skipped rings
502 MergeMethod fMergeMethod; // Merge methiod for overlapping bins
503 FiducialMethod fFiducialMethod; // Fidicual method
504 UShort_t fSkipFMDRings; // FMD rings to ignore
505 Bool_t fBgAndHitMaps; // Make hit/bg maps or not
506 TObjArray* fVtxList; //! Per-vertex list
507 TList* fByCent; // By centrality sums
508 Bool_t fDoByCent; // Whether to do by centrality sum
509 ClassDef(AliFMDHistCollector,6); // Calculate Nch density