]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGLF/FORWARD/analysis2/AliFMDMultCuts.cxx
Merge branch 'master' of https://git.cern.ch/reps/AliRoot
[u/mrichter/AliRoot.git] / PWGLF / FORWARD / analysis2 / AliFMDMultCuts.cxx
1 #include "AliFMDMultCuts.h"
2 #include "AliForwardCorrectionManager.h"
3 #include "AliFMDCorrELossFit.h"
4 #include "AliForwardUtil.h"
5 #include <AliLog.h>
6 #include <iostream>
7 #include <TROOT.h>
8 #include <TParameter.h>
9 #include <TH2.h>
10 namespace { 
11   Int_t fDebug = 1;
12 }
13 ClassImp(AliFMDMultCuts)
14 #if 0
15 ; // This is for Emacs
16 #endif
17
18 //____________________________________________________________________
19 AliFMDMultCuts::AliFMDMultCuts()
20   : TObject(),
21     fMPVFraction(0), 
22     fNXi(0), 
23     fIncludeSigma(false),
24     fProbability(0)
25 {
26   Reset();
27 }
28 //____________________________________________________________________
29 AliFMDMultCuts::AliFMDMultCuts(EMethod method, 
30                                Double_t cut1,  
31                                Double_t cut2,
32                                Double_t cut3,
33                                Double_t cut4,
34                                Double_t cut5)
35   : TObject(),
36     fMPVFraction(0), 
37     fNXi(0), 
38     fIncludeSigma(false),
39     fProbability(0)
40 {
41   Set(method, cut1, cut2, cut3, cut4, cut5);
42 }
43
44 //____________________________________________________________________
45 AliFMDMultCuts::AliFMDMultCuts(const AliFMDMultCuts& o)
46   : TObject(o),
47     fMPVFraction(o.fMPVFraction), 
48     fNXi(o.fNXi), 
49     fIncludeSigma(o.fIncludeSigma),
50     fProbability(o.fProbability)
51 {
52   for (Int_t i = 0; i < 5; i++) fMultCuts[i] = o.fMultCuts[i];
53 }
54 //____________________________________________________________________
55 AliFMDMultCuts&
56 AliFMDMultCuts::operator=(const AliFMDMultCuts& o)
57 {
58   if (&o == this) return *this; 
59   fMPVFraction  = o.fMPVFraction;
60   fNXi          = o.fNXi;
61   fIncludeSigma = o.fIncludeSigma;
62   fProbability  = o.fProbability;
63   for (Int_t i = 0; i < 5; i++) fMultCuts[i] = o.fMultCuts[i];
64   return *this;
65 }
66 //____________________________________________________________________
67 void
68 AliFMDMultCuts::Reset()
69 {
70   for (Int_t i = 0; i < 5; i++) fMultCuts[i] = -1;
71   fMPVFraction  = -1;
72   fNXi          = -1;
73   fIncludeSigma = false;
74   fProbability  = -1;
75 }
76 //____________________________________________________________________
77 void
78 AliFMDMultCuts::Set(EMethod method, 
79                     Double_t cut1, 
80                     Double_t cut2, 
81                     Double_t cut3, 
82                     Double_t cut4, 
83                     Double_t cut5)
84 {
85   // First, reset
86   Reset();
87   
88   // Then switch on method 
89   switch(method) { 
90   case kFixed:  
91     if (cut2 < 0) SetMultCuts(cut1, cut1, cut1*1.2, cut1*1.2, cut1);
92     else          SetMultCuts(cut1, cut2, cut3, cut4, cut5);
93     break;
94   case kMPVFraction: 
95     SetMPVFraction(cut1);
96     break;
97   case kFitRange:
98     break;
99   case kLandauWidth:
100     SetNXi(cut1);
101     SetIncludeSigma(cut2 > 0);
102     break;
103   case kProbability:
104     SetProbability(cut1);
105     break;
106   }
107 }
108   
109
110 //____________________________________________________________________
111 Double_t
112 AliFMDMultCuts::GetFixedCut(UShort_t d, Char_t r) const
113 {
114   // Int_t    idx = (d == 1 ? 0 : 2*(d - 2) + 1 + ((r=='I' || r=='i') ? 0 : 1));
115   Int_t idx = -1;
116   switch (d) { 
117   case 1: idx = 0; break;
118   case 2: idx = 1 + ((r == 'I' || r == 'i') ? 0 : 1); break;
119   case 3: idx = 3 + ((r == 'I' || r == 'i') ? 0 : 1); break;
120   }
121   if (idx < 0) return -1024;
122   return fMultCuts[idx];
123 }
124
125 //____________________________________________________________________
126 void
127 AliFMDMultCuts::SetMultCuts(Double_t fmd1i, 
128                             Double_t fmd2i, 
129                             Double_t fmd2o, 
130                             Double_t fmd3i, 
131                             Double_t fmd3o)
132 {
133   fMultCuts[0] = fmd1i;
134   fMultCuts[1] = fmd2i >= 0 ? fmd2i : fmd1i;
135   fMultCuts[2] = fmd2o >= 0 ? fmd2o : fmd1i;
136   fMultCuts[3] = fmd3i >= 0 ? fmd3i : fmd1i;
137   fMultCuts[4] = fmd3o >= 0 ? fmd3o : fmd1i;
138 }
139
140                             
141 //____________________________________________________________________
142 Double_t
143 AliFMDMultCuts::GetMultCut(UShort_t d, Char_t r, Int_t ieta, 
144                            Bool_t errors) const
145 {
146   // 
147   // Get the multiplicity cut.  If the user has set fMultCut (via
148   // SetMultCut) then that value is used.  If not, then the lower
149   // value of the fit range for the enery loss fits is returned.
150   // 
151   // Return:
152   //    Lower cut on multiplicity
153   //
154   UShort_t meth = GetMethod();
155   DGUARD(fDebug, 5, "Get mult cut for FMD%d%c (method %d) @ etabin=%d", 
156          d, r, meth, ieta);
157   Double_t rcut = -1024;
158   if (meth == kFixed) rcut = GetFixedCut(d, r);
159
160   if (rcut < 0) {
161     // Get the energy loss fits 
162     AliForwardCorrectionManager&  fcm = 
163       AliForwardCorrectionManager::Instance();
164     const AliFMDCorrELossFit* fits = fcm.GetELossFit();
165     if (fits) {
166       switch (meth) { 
167       case kMPVFraction:
168         // Return fMPVFraction * mpv 
169         rcut = fits->GetLowerBound(d, r, ieta, fMPVFraction); break;
170       case kLandauWidth:
171         // Return MPV - fNXi * xi
172         rcut = fits->GetLowerBound(d, r, ieta, fNXi, errors,fIncludeSigma);
173         break;
174       case kProbability:
175         // Return probability cut 
176         rcut = fits->GetLowerBound(d, r, ieta, fProbability, true); break;
177       default:
178         // Return lower fit boundary
179         rcut = fits->GetLowCut(); break;
180       }
181     }
182     else 
183       Warning("GetMultCut", "No energy loss fits obtained from manager");
184   }
185   DMSG(fDebug, 5, "-> %8.4f", rcut);
186     
187   return rcut;
188 }
189     
190 //____________________________________________________________________
191 Double_t
192 AliFMDMultCuts::GetMultCut(UShort_t d, Char_t r, Double_t eta,
193                            Bool_t errors) const
194 {
195   // 
196   // Get the multiplicity cut.  If the user has set fMultCut (via
197   // SetMultCut) then that value is used.  If not, then the lower
198   // value of the fit range for the enery loss fits is returned.
199   // 
200   // Return:
201   //    Lower cut on multiplicity
202   //
203   DGUARD(fDebug, 5, "Get mult cut for FMD%d%c @ eta=%8.4f", 
204          d, r, eta);
205   AliForwardCorrectionManager&  fcm  = AliForwardCorrectionManager::Instance();
206   const AliFMDCorrELossFit*     fits = fcm.GetELossFit();
207   Int_t                         iEta = fits ? fits->FindEtaBin(eta) : 1;
208   DMSG(fDebug, 5, "bin=%4d", iEta);
209   return GetMultCut(d, r, iEta, errors);
210 }
211 //____________________________________________________________________
212 UShort_t
213 AliFMDMultCuts::GetMethod() const
214 {
215   return (fMultCuts[0] >= 0 ? kFixed : // Fixed
216           fMPVFraction >  0 ? kMPVFraction : // Fraction MPV
217           fNXi         >  0 ? kLandauWidth :  // Width 
218           fProbability >  0 ? kProbability : 
219           kFitRange); // Fit range
220 }
221 //____________________________________________________________________
222 const char*
223 AliFMDMultCuts::GetMethodString() const
224 {
225   switch (GetMethod()) {
226   case kFixed:       return "fixed value";
227   case kMPVFraction: return "fraction of MPV";
228   case kFitRange:    return "fit range";
229   case kLandauWidth: return "landau width";
230   case kProbability: return "probability";
231   }
232   return "unknown";
233  } 
234   
235 //____________________________________________________________________
236 void
237 AliFMDMultCuts::FillHistogram(TH2* h) const
238 {
239   DGUARD(fDebug, 5, "Fill Histogram %s with cuts", h->GetName());
240   AliInfoF("Caching multiplicity cuts (%s)", h->GetName());
241   TAxis* yAxis = h->GetYaxis(); 
242   for (Int_t iy = 1; iy <= yAxis->GetNbins(); iy++) { 
243     TString lab(yAxis->GetBinLabel(iy));
244     lab.Remove(0,3);
245     UShort_t det = lab.Atoi();
246     Char_t   rng = lab[1];
247     // Printf("Filling for FMD%d%c (bin # %d) %s", det, rng, iy, lab.Data());
248     AliInfoF("FMD%d%c", det, rng);
249     for (Int_t ix = 1; ix <= h->GetNbinsX(); ix++) {
250       Double_t eta = h->GetXaxis()->GetBinCenter(ix);
251       Double_t c   = GetMultCut(det, rng, eta,  false);
252       DMSG(fDebug, 5, "FMD%s bin=%4d -> eta=%8.4f -> %8.4f", 
253            lab.Data(), ix, eta, c);
254       // Double_t c = GetMultCut(det, rng, ix, false);
255       if (c > 0) h->SetBinContent(ix, iy, c);
256     }
257   }
258 }
259
260 //____________________________________________________________________
261 void
262 AliFMDMultCuts::Output(TList* l, const char* name) const
263 {
264   TList* ll = l;
265   if (name && name[0] != '\0') { 
266     ll = new TList;
267     ll->SetName(name);
268     ll->SetOwner();
269     l->Add(ll);
270   }
271     
272
273   ll->Add(AliForwardUtil::MakeParameter("nXi", fNXi));
274   ll->Add(AliForwardUtil::MakeParameter("frac", fMPVFraction));
275   ll->Add(AliForwardUtil::MakeParameter("sigma", fIncludeSigma));
276   ll->Add(AliForwardUtil::MakeParameter("probability", fProbability));
277   ll->Add(AliForwardUtil::MakeParameter("method", GetMethod()));
278 }
279 //____________________________________________________________________
280 Bool_t
281 AliFMDMultCuts::Input(TList* l, const char* name)
282 {
283   if (!l) return false;
284   TList* ll = l;
285   if (name && name[0] != '\0') { 
286     ll = static_cast<TList*>(l->FindObject(name));
287   }
288   if (!ll) return false;
289   
290   TObject* nXi   = ll->FindObject("nXi");
291   TObject* frac  = ll->FindObject("frac");
292   TObject* sigma = ll->FindObject("sigma");
293   TObject* prob  = ll->FindObject("probability");
294   if (!nXi || !frac || !sigma) return false;
295   AliForwardUtil::GetParameter(nXi, fNXi);
296   AliForwardUtil::GetParameter(frac, fMPVFraction);
297   AliForwardUtil::GetParameter(sigma, fIncludeSigma);
298   AliForwardUtil::GetParameter(prob, fProbability);
299   
300   return true;
301 }
302 #define PF(N,V,...)                                     \
303   AliForwardUtil::PrintField(N,V, ## __VA_ARGS__)
304 #define PFB(N,FLAG)                             \
305   do {                                                                  \
306     AliForwardUtil::PrintName(N);                                       \
307     std::cout << std::boolalpha << (FLAG) << std::noboolalpha << std::endl; \
308   } while(false)
309 #define PFV(N,VALUE)                                    \
310   do {                                                  \
311     AliForwardUtil::PrintName(N);                       \
312     std::cout << (VALUE) << std::endl; } while(false)
313   
314 //____________________________________________________________________
315 void
316 AliFMDMultCuts::Print(Option_t*) const
317 {
318   gROOT->IncreaseDirLevel();
319   PFV("Method used", GetMethodString());
320   PF("Fixed cuts","");
321   gROOT->IncreaseDirLevel();
322   PFV("FMD1i", GetFixedCut(1,'I'));
323   PFV("FMD2i", GetFixedCut(2,'I'));
324   PFV("FMD2o", GetFixedCut(2,'O'));
325   PFV("FMD3i", GetFixedCut(3,'I'));
326   PFV("FMD3o", GetFixedCut(3,'O'));
327   gROOT->DecreaseDirLevel();
328   PFV("N xi factor",            fNXi);
329   PFB("Include sigma in cut",   fIncludeSigma);
330   PFV("MPV fraction",           fMPVFraction);
331   PFV("Probability",            fProbability);
332   gROOT->DecreaseDirLevel();
333 }
334 //____________________________________________________________________
335 //
336 // EOF
337 //