AliPhysics  ad6828d (ad6828d)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
spectraAnalysis.C
Go to the documentation of this file.
1 #ifndef __CINT__
2 # include <TH1.h>
3 # include <TH2.h>
4 # include <TMath.h>
5 # include <TParticle.h>
6 # include <TObjArray.h>
7 # include <TString.h>
8 #else
9 class TH1;
10 class TParticle;
11 #endif
12 #include "FastAnalysis.C"
13 
18 {
19  enum {
20  kPiSty = 20,
21  kKSty = 21,
22  kPSty = 22,
23  kOSty = 23
24  };
25  enum {
26  kPiColor = kRed+2,
27  kKColor = kGreen+2,
28  kPColor = kBlue+2,
29  kOColor = kMagenta+2
30  };
37  spectraAnalysis(Bool_t verbose=false, Int_t monitor=0)
38  : FastAnalysis(verbose,monitor),
39  fNpi(0),
40  fNK(0),
41  fNP(0),
42  fNO(0),
43  fdNdptPi(0),
44  fdNdptK(0),
45  fdNdptP(0),
46  fdNdptO(0),
47  fK2piRatio(0),
48  fP2piRatio(0),
49  fO2piRatio(0)
50  {
51  }
61  TH1* CreateSpectra(UInt_t pdg, Color_t col, Style_t sty)
62  {
63  TH1* h = new TH1D(dNdptName(pdg), "", 100, 0, 10);
64  h->SetXTitle("p_{T}");
65  h->SetYTitle("dN/dp_{T}");
66  h->SetDirectory(0);
67  h->SetMarkerColor(col);
68  h->SetLineColor(col);
69  h->SetFillColor(col);
70  h->SetMarkerStyle(sty);
71  h->Sumw2();
72  fOutput->Add(h);
73  return h;
74  }
84  TH1* CreateRatio(UInt_t pdg, Color_t col, Style_t sty)
85  {
86  TH1* h = new TH1D(RatioName(pdg), "", 100, 0, 10);
87  h->SetXTitle(Form("%d/211",pdg));
88  h->SetYTitle("Events");
89  h->SetDirectory(0);
90  h->SetMarkerColor(col);
91  h->SetLineColor(col);
92  h->SetFillColor(col);
93  h->SetMarkerStyle(sty);
94  h->Sumw2();
95  fOutput->Add(h);
96  return h;
97  }
104  virtual void SlaveBegin(TTree*)
105  {
106  Info("SlaveBegin", "Making dN/deta histogram");
111 
115  }
122  Bool_t ProcessHeader() { return true; }
128  {
129  fNpi = fNK = fNP = fNO = 0;
131  if (fNpi <= 0) return;
132  fK2piRatio->Fill(Double_t(fNK)/fNpi);
133  fP2piRatio->Fill(Double_t(fNP)/fNpi);
134  fO2piRatio->Fill(Double_t(fNO)/fNpi);
135  }
141  virtual Bool_t ProcessParticle(const TParticle* p)
142  {
143  Double_t pT = p->Pt();
144  Int_t pdg = TMath::Abs(p->GetPdgCode());
145  if (pdg == 211) { fdNdptPi->Fill(pT); fNpi++; }
146  else if (pdg == 321) { fdNdptK ->Fill(pT); fNK++; }
147  else if (pdg == 2212) { fdNdptP ->Fill(pT); fNP++; }
148  else { fdNdptO ->Fill(pT); fNO++; }
149  return true;
150  }
158  static const char* dNdptName(UInt_t pdg)
159  {
160  switch (pdg) {
161  case 211: return "dNdptPi";
162  case 321: return "dNdptK";
163  case 2212: return "dNdptP";
164  }
165  return "dNdptO";
166  }
174  static const char* RatioName(UInt_t pdg)
175  {
176  switch (pdg) {
177  case 321: return "KtoPiRatio";
178  case 2212: return "PtoPiRatio";
179  }
180  return "OtoPiRatio";
181  }
190  {
191  TH1* h = static_cast<TH1*>(GetOutputObject(dNdptName(pdg), TH1::Class()));
192  if (!h) {
193  SetStatus(-1);
194  Warning("Terminate", "No %s histogram found", dNdptName(pdg));
195  return false;
196  }
197  h->Scale(1./fOK, "width");
198  return true;
199  }
210  {
211  TH1* h = static_cast<TH1*>(GetOutputObject(RatioName(pdg),
212  TH1::Class()));
213  if (!h) {
214  SetStatus(-1);
215  Warning("Terminate", "No %s histogram found", RatioName(pdg));
216  return false;
217  }
218  r->SetBinContent(bin, h->GetMean());
219  r->SetBinError(bin, h->GetRMS());
220  return true;
221  }
226  virtual void Terminate()
227  {
228  fOK = GetEventCount();
229  if (fOK <= 0) {
230  SetStatus(-1);
231  Warning("Terminate", "No events selected");
232  return;
233  }
234  Printf("A total of %ld events", fOK);
235 
236  Scale(211);
237  Scale(321);
238  Scale(2212);
239  Scale(0);
240 
241  TH1* ratios = new TH1D("ratios","Ratios to #pi",
242  3, .5, 3.5);
243  ratios->GetXaxis()->SetBinLabel(1, "K/#pi");
244  ratios->GetXaxis()->SetBinLabel(2, "p/#pi");
245  ratios->GetXaxis()->SetBinLabel(3, "other/#pi");
246  ratios->SetFillColor(kCyan+2);
247  ratios->SetLineColor(kCyan+2);
248  ratios->SetMarkerColor(kCyan+2);
249  ratios->SetMarkerStyle(20);
250  Ratio(ratios, 1, 321);
251  Ratio(ratios, 2, 2212);
252  Ratio(ratios, 3, 0);
253 
254  fOutput->Add(ratios);
255  }
256  Long_t fNpi;
257  Long_t fNK;
258  Long_t fNP;
259  Long_t fNO;
260 
265 
269 
271 };
272 
273 //====================================================================
274 /*
275  * The function to make our analyser
276  */
278 {
282  spectraMaker() : FastAnalysis::Maker("spectra") {}
293  FastAnalysis* Make(const TString& subtype,
294  Int_t monitor,
295  Bool_t verbose,
296  TString& uopt)
297  {
298  return new spectraAnalysis(verbose,monitor);
299  }
304  void List() const
305  {
306  }
310  const char* Script() const { return __FILE__; }
311 };
312 
313 
314 // ------------------------------------------------------------------
315 // Create instance of maker
317 
318 //
319 // EOF
320 //
Int_t pdg
TObject * GetOutputObject(const char *name, TClass *cls)
Definition: FastAnalysis.C:404
spectraMaker * _spectraMaker
double Double_t
Definition: External.C:58
const char * Script() const
This script defines classes for looping over the data produced by FastSim.C.
TH1 * CreateRatio(UInt_t pdg, Color_t col, Style_t sty)
virtual void SlaveBegin(TTree *)
static const char * RatioName(UInt_t pdg)
int Int_t
Definition: External.C:63
unsigned int UInt_t
Definition: External.C:33
Definition: External.C:212
spectraAnalysis(Bool_t verbose=false, Int_t monitor=0)
static const char * dNdptName(UInt_t pdg)
Bool_t Scale(UInt_t pdg)
FastAnalysis * Make(const TString &subtype, Int_t monitor, Bool_t verbose, TString &uopt)
Long_t GetEventCount()
Definition: FastAnalysis.C:386
virtual void ProcessParticles()
Definition: FastAnalysis.C:475
Bool_t Ratio(TH1 *r, Int_t bin, UInt_t pdg)
ULong_t fOK
Definition: FastAnalysis.C:83
ClassDef(spectraAnalysis, 0)
virtual Bool_t ProcessParticle(const TParticle *p)
Bool_t ProcessHeader()
TH1 * CreateSpectra(UInt_t pdg, Color_t col, Style_t sty)
virtual void Terminate()
bool Bool_t
Definition: External.C:53
Maker(const char *type="")
Definition: FastAnalysis.C:944
Definition: External.C:196
void List() const