]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGLF/FORWARD/analysis2/AliFMDMultCuts.cxx
New multiplicity cut framework. Allows for more dynamic definition
[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     fMethod(kFixed)
22 {
23   Reset();
24 }
25 //____________________________________________________________________
26 AliFMDMultCuts::AliFMDMultCuts(EMethod method, 
27                                Double_t cut1,  
28                                Double_t cut2,
29                                Double_t cut3,
30                                Double_t cut4,
31                                Double_t cut5)
32   : TObject(),
33     fMethod(method)
34 {
35   Set(method, cut1, cut2, cut3, cut4, cut5);
36 }
37
38 //____________________________________________________________________
39 AliFMDMultCuts::AliFMDMultCuts(const AliFMDMultCuts& o)
40   : TObject(o),
41     fMethod(o.fMethod)
42 {
43   for (Int_t i = 0; i < 5; i++) fCuts[i] = o.fCuts[i];
44 }
45 //____________________________________________________________________
46 AliFMDMultCuts&
47 AliFMDMultCuts::operator=(const AliFMDMultCuts& o)
48 {
49   if (&o == this) return *this; 
50   fMethod  = o.fMethod;
51   for (Int_t i = 0; i < 5; i++) fCuts[i] = o.fCuts[i];
52   return *this;
53 }
54 //____________________________________________________________________
55 void
56 AliFMDMultCuts::Reset()
57 {
58   fMethod = kFixed;
59   for (Int_t i = 0; i < 5; i++) fCuts[i] = -1;
60 }
61 //____________________________________________________________________
62 void
63 AliFMDMultCuts::Set(EMethod method, 
64                     Double_t fmd1i, 
65                     Double_t fmd2i, 
66                     Double_t fmd2o, 
67                     Double_t fmd3i, 
68                     Double_t fmd3o)
69 {
70   // First, reset
71   Reset();
72   fMethod      = method; 
73   Double_t oFac = 1;
74   if      (fMethod == kFixed)       oFac = 1.2;
75   else if (fMethod == kMPVFraction) oFac = 1.1;
76   fCuts[0] = fmd1i;
77   fCuts[1] = fmd2i >= 0 ? fmd2i : fmd1i;
78   fCuts[2] = fmd2o >= 0 ? fmd2o : fmd1i * oFac;
79   fCuts[3] = fmd3i >= 0 ? fmd3i : fmd1i;
80   fCuts[4] = fmd3o >= 0 ? fmd3o : fmd1i * oFac;
81 }
82 //____________________________________________________________________
83 void
84 AliFMDMultCuts::DepSet(const char* what,
85                        EMethod method, 
86                        Double_t fmd1i, 
87                        Double_t fmd2i, 
88                        Double_t fmd2o, 
89                        Double_t fmd3i, 
90                        Double_t fmd3o)
91 {
92   Warning(what, "*** DEPRECATED - use AliFMDMultCuts::Set instead ***");
93   Set(method, fmd1i, fmd2i, fmd2o, fmd3i, fmd3o);
94 }
95   
96 //____________________________________________________________________
97 void
98 AliFMDMultCuts::SetIncludeSigma(Bool_t in) 
99 {
100   Warning("SetIncludeSigma",  
101           "*** DEPRECATED - use AliFMDMultCuts::Set instead ***");
102   if (in) { 
103     if (fMethod == kLandauWidth) fMethod = kLandauSigmaWidth;
104   }
105   else {
106     if (fMethod == kLandauSigmaWidth) fMethod = kLandauWidth;
107   }
108 }
109
110 //____________________________________________________________________
111 Double_t
112 AliFMDMultCuts::GetCutParam(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 -kBad;
122   return fCuts[idx];
123 }
124                             
125 //____________________________________________________________________
126 Double_t
127 AliFMDMultCuts::GetMultCut(UShort_t d, Char_t r, Int_t ieta, 
128                            Bool_t errors) const
129 {
130   // 
131   // Get the multiplicity cut.  If the user has set fMultCut (via
132   // SetMultCut) then that value is used.  If not, then the lower
133   // value of the fit range for the enery loss fits is returned.
134   // 
135   // Return:
136   //    Lower cut on multiplicity
137   //
138   DGUARD(fDebug, 5, "Get mult cut for FMD%d%c (method %d) @ etabin=%d", 
139          d, r, fMethod, ieta);
140   Double_t param = GetCutParam(d, r);
141   if (param < 0) {
142     Warning("GetMultCut", "Got bad cut parameter for FMD%d%c ieta=%d",
143             d, r, ieta);
144     return -kBad;
145   }
146
147   // If we're using a fixed cut, just return
148   if (fMethod == kFixed) {
149     DMSG(fDebug, 5, "-> %8.4f", param);
150     return param;
151   }
152
153   // Bad value 
154   Double_t rcut = -kBad;
155
156   // Get the energy loss fits 
157   AliForwardCorrectionManager&  fcm = 
158     AliForwardCorrectionManager::Instance();
159   const AliFMDCorrELossFit* fits = fcm.GetELossFit();
160   if (fits) {
161     switch (fMethod) { 
162     case kMPVFraction:
163       // Return fMPVFraction * mpv 
164       rcut = fits->GetLowerBound(d, r, ieta, param); break;
165     case kLandauWidth:
166       // Return MPV - fNXi * xi
167       rcut = fits->GetLowerBound(d, r, ieta, param, errors,false);
168       break;
169     case kLandauSigmaWidth:
170       // Return MPV - fNXi * xi
171       rcut = fits->GetLowerBound(d, r, ieta, param, errors,true);
172       break;
173     case kProbability:
174       // Return probability cut 
175       rcut = fits->GetLowerBound(d, r, ieta, param, true); break;
176     default:
177       // Return lower fit boundary
178       rcut = fits->GetLowCut(); break;
179     }
180   }
181   else 
182     Warning("GetMultCut", "No energy loss fits obtained from manager");
183
184   DMSG(fDebug, 5, "-> %8.4f", rcut);
185     
186   return rcut;
187 }
188     
189 //____________________________________________________________________
190 Double_t
191 AliFMDMultCuts::GetMultCut(UShort_t d, Char_t r, Double_t eta,
192                            Bool_t errors) const
193 {
194   // 
195   // Get the multiplicity cut.  If the user has set fMultCut (via
196   // SetMultCut) then that value is used.  If not, then the lower
197   // value of the fit range for the enery loss fits is returned.
198   // 
199   // Return:
200   //    Lower cut on multiplicity
201   //
202   DGUARD(fDebug, 5, "Get mult cut for FMD%d%c @ eta=%8.4f", 
203          d, r, eta);
204   AliForwardCorrectionManager&  fcm  = AliForwardCorrectionManager::Instance();
205   const AliFMDCorrELossFit*     fits = fcm.GetELossFit();
206   Int_t                         iEta = fits ? fits->FindEtaBin(eta) : 1;
207   DMSG(fDebug, 5, "bin=%4d", iEta);
208   return GetMultCut(d, r, iEta, errors);
209 }
210 //____________________________________________________________________
211 const char*
212 AliFMDMultCuts::GetMethodString(Bool_t latex) const
213 {
214   return Method2String(fMethod, latex);
215 }
216
217 //____________________________________________________________________
218 const char*
219 AliFMDMultCuts::Method2String(EMethod method, Bool_t latex)
220 {
221   switch (method) {
222   case kFixed:            
223     return latex ? "c=X" : "fixed value";
224   case kMPVFraction:      
225     return latex ? "c=X#times#Delta_{p}":"fraction of MPV";
226   case kFitRange:         
227     return latex ? "range" : "c: lower fit bound";
228   case kLandauWidth:      
229     return latex ? "c=#Delta_{p}-X#times#xi" : "landau width";
230   case kLandauSigmaWidth: 
231     return latex ? "c=#Delta_{p}-X#times(#xi+#sigma)" : "landau+sigma width";
232   case kProbability:      
233     return latex ? "c:P(#Delta<c)<X" : "probability";
234   }
235   return latex ? "c:?" : "unknown";
236
237 //____________________________________________________________________
238 AliFMDMultCuts::EMethod
239 AliFMDMultCuts::String2Method(const char* str)
240 {
241   TString m(str);
242   if (m.EqualTo("fixed value")     || m.Contains("fix")) 
243     return kFixed;
244   else if (m.EqualTo("fraction of mpv") || m.Contains("mpv")) 
245     return kMPVFraction;
246   else if (m.EqualTo("fit range")       || m.Contains("fit")) 
247     return kFitRange;
248   else if (m.EqualTo("landau width")    || m.Contains("xi") || 
249            m.Contains("width")) return kLandauWidth;
250   else if (m.EqualTo("landau+sigma width") || m.Contains("sig")) 
251     return kLandauSigmaWidth;
252   else if (m.EqualTo("probability")        || m.Contains("prob")) 
253     return kProbability;
254   return kFixed;
255  } 
256   
257 //____________________________________________________________________
258 void
259 AliFMDMultCuts::FillHistogram(TH2* h) const
260 {
261   DGUARD(fDebug, 5, "Fill Histogram %s with cuts", h->GetName());
262   // AliInfoF("Caching multiplicity cuts (%s)", h->GetName());
263   TAxis* yAxis = h->GetYaxis(); 
264   for (Int_t iy = 1; iy <= yAxis->GetNbins(); iy++) { 
265     TString lab(yAxis->GetBinLabel(iy));
266     lab.Remove(0,3);
267     UShort_t det = lab.Atoi();
268     Char_t   rng = lab[1];
269     // Printf("Filling for FMD%d%c (bin # %d) %s", det, rng, iy, lab.Data());
270     DMSG(fDebug, 5, "FMD%d%c", det, rng);
271     // AliInfoF("FMD%d%c", det, rng);
272     for (Int_t ix = 1; ix <= h->GetNbinsX(); ix++) {
273       Double_t eta = h->GetXaxis()->GetBinCenter(ix);
274       Double_t c   = GetMultCut(det, rng, eta,  false);
275       DMSG(fDebug, 10, "FMD%s bin=%4d -> eta=%8.4f -> %8.4f", 
276            lab.Data(), ix, eta, c);
277       // Double_t c = GetMultCut(det, rng, ix, false);
278       if (c > 0) h->SetBinContent(ix, iy, c);
279     }
280   }
281 }
282
283 //____________________________________________________________________
284 void
285 AliFMDMultCuts::Output(TList* l, const char* name) const
286 {
287   TList* ll = l;
288   if (name && name[0] != '\0') { 
289     ll = new TList;
290     ll->SetName(name);
291     ll->SetOwner();
292     l->Add(ll);
293   }
294     
295
296   ll->Add(AliForwardUtil::MakeParameter("method", UShort_t(fMethod)));
297   ll->Add(AliForwardUtil::MakeParameter("fmd1i", fCuts[0]));
298   ll->Add(AliForwardUtil::MakeParameter("fmd2i", fCuts[1]));
299   ll->Add(AliForwardUtil::MakeParameter("fmd2o", fCuts[2]));
300   ll->Add(AliForwardUtil::MakeParameter("fmd3i", fCuts[3]));
301   ll->Add(AliForwardUtil::MakeParameter("fmd3o", fCuts[4]));
302 }
303 //____________________________________________________________________
304 Bool_t
305 AliFMDMultCuts::Input(TList* l, const char* name)
306 {
307   if (!l) return false;
308   TList* ll = l;
309   if (name && name[0] != '\0') { 
310     ll = static_cast<TList*>(l->FindObject(name));
311   }
312   if (!ll) return false;
313   
314   TObject* meth    = ll->FindObject("method");
315   TObject* fmd1i   = ll->FindObject("fmd1i");
316   TObject* fmd2i   = ll->FindObject("fmd2i");
317   TObject* fmd2o   = ll->FindObject("fmd2o");
318   TObject* fmd3i   = ll->FindObject("fmd3i");
319   TObject* fmd3o   = ll->FindObject("fmd3o");
320   
321   UShort_t methNum = 0;
322   
323   AliForwardUtil::GetParameter(meth,  methNum);
324   switch (methNum) { 
325   case 0: fMethod = kFixed;            break;
326   case 1: fMethod = kMPVFraction;      break;
327   case 2: fMethod = kFitRange;         break;
328   case 3: fMethod = kLandauWidth;      break;
329   case 4: fMethod = kLandauSigmaWidth; break;
330   case 5: fMethod = kProbability;      break;
331   }
332
333   AliForwardUtil::GetParameter(fmd1i, fCuts[0]);
334   AliForwardUtil::GetParameter(fmd2i, fCuts[1]);
335   AliForwardUtil::GetParameter(fmd2o, fCuts[2]);
336   AliForwardUtil::GetParameter(fmd3i, fCuts[3]);
337   AliForwardUtil::GetParameter(fmd3o, fCuts[4]);
338   
339   return true;
340 }
341 #define PF(N,V,...)                                     \
342   AliForwardUtil::PrintField(N,V, ## __VA_ARGS__)
343 #define PFB(N,FLAG)                             \
344   do {                                                                  \
345     AliForwardUtil::PrintName(N);                                       \
346     std::cout << std::boolalpha << (FLAG) << std::noboolalpha << std::endl; \
347   } while(false)
348 #define PFV(N,VALUE)                                    \
349   do {                                                  \
350     AliForwardUtil::PrintName(N);                       \
351     std::cout << (VALUE) << std::endl; } while(false)
352   
353 //____________________________________________________________________
354 void
355 AliFMDMultCuts::Print(Option_t*) const
356 {
357   gROOT->IncreaseDirLevel();
358   PFV("Method used", GetMethodString());
359   gROOT->IncreaseDirLevel();
360   PFV("FMD1i", GetCutParam(1,'I'));
361   PFV("FMD2i", GetCutParam(2,'I'));
362   PFV("FMD2o", GetCutParam(2,'O'));
363   PFV("FMD3i", GetCutParam(3,'I'));
364   PFV("FMD3o", GetCutParam(3,'O'));
365   gROOT->DecreaseDirLevel();
366   gROOT->DecreaseDirLevel();
367 }
368 //____________________________________________________________________
369 //
370 // EOF
371 //