AliPhysics  9df6235 (9df6235)
dNdetaAnalysis.C
Go to the documentation of this file.
1 #ifndef DNDETAANALYSIS_C
2 #define DNDETAANALYSIS_C
3 #ifndef __CINT__
4 # include <TH1.h>
5 # include <TH2.h>
6 # include <TMath.h>
7 # include <TParticle.h>
8 # include <TObjArray.h>
9 # include <TString.h>
10 #else
11 class TH1;
12 class TParticle;
13 class TMap;
14 #endif
15 #include "FastAnalysis.C"
16 #include "FastCentHelper.C"
17 namespace dNdeta {
18  //====================================================================
22  struct Base : public FastAnalysis
23  {
25 
26  Base(Bool_t verbose=false, Int_t monitor=0)
27  : FastAnalysis(verbose,monitor), fdNdeta(0)
28  {}
34  static TH1D* CreatedNdeta()
35  {
36  Double_t maxEta = 9; // 10;
37  Int_t nEta = Int_t(200 * maxEta/5+.5);
38  TH1D* eta = new TH1D("dNdeta",
39  "Charged particle pseudo-rapidity density",
40  nEta, -maxEta, +maxEta);
41  eta->Sumw2();
42  eta->SetXTitle("#it{#eta}");
43  eta->SetYTitle("1/N d#it{N}_{ch}/d#it{#eta}");
44  eta->SetMarkerColor(kRed+2);
45  eta->SetMarkerStyle(20);
46  eta->SetDirectory(0);
47 
48  return eta;
49  }
51  {
52  return CreatedNdeta();
53  }
57  virtual void SlaveBegin(TTree*)
58  {
59  Info("SlaveBegin", "Making dN/deta histogram");
60  fdNdeta = CreatedNdeta();
61  fdNdeta->SetMarkerColor(kBlack);
62  fdNdeta->SetMarkerStyle(21);
63  fdNdeta->SetTitle(GetName());
64  fOutput->Add(fdNdeta);
65  }
71  virtual Bool_t ProcessParticle(const TParticle* p)
72  {
73  Double_t pT = p->Pt();
74  Double_t pZ = p->Pz();
75  Double_t theta = TMath::ATan2(pT, pZ);
76  Double_t eta = (pT < 1e-10 ? 1024 : -TMath::Log(TMath::Tan(theta/2)));
77  if (TMath::Abs(eta) > 1000) return false;
78 
79  Fill(eta);
80  return true;
81  }
82  virtual void Fill(Double_t eta) { fdNdeta->Fill(eta); }
87  virtual void Terminate()
88  {
89  fOK = GetEventCount();
90  if (fOK <= 0) {
91  SetStatus(-1);
92  Warning("Terminate", "No events selected");
93  return;
94  }
95  fdNdeta = static_cast<TH1*>(GetOutputObject("dNdeta", TH1::Class()));
96  if (!fdNdeta) {
97  SetStatus(-1);
98  Warning("Terminate", "No dN/deta histogram found");
99  return;
100  }
101  Printf("A total of %ld events", fOK);
102  TH1* copy = static_cast<TH1*>(fdNdeta->Clone("before"));
103  fOutput->Add(copy);
104 
105  fdNdeta->Scale(1. / fOK, "width");
106  fdNdeta->Draw();
107  SetStatus(0);
108  }
115  {
116  TObject* m1 = new TNamed("dNdeta", "");
117  m1->SetUniqueID(0x8); // Scale
118 
119  TList* ret = new TList;
120  ret->Add(m1);
121 
122  return ret;
123  }
124  ClassDef(Base,1);
125  };
126 
127  //====================================================================
132  struct NSD : public Base
133  {
140  NSD(Bool_t verbose=false, Int_t monitor=0)
141  : Base(verbose, monitor)
142  {}
150  {
151  if (fHeader->fType & 0x1) return false;
152  return true;
153  }
154  ClassDef(NSD,1);
155  };
156 
157  //====================================================================
162  struct INEL : public Base
163  {
170  INEL(Bool_t verbose=false, Int_t monitor=0)
171  : Base(verbose,monitor)
172  {}
178  virtual Bool_t ProcessHeader() { return true; }
179  ClassDef(INEL,1);
180  };
181 
182  //====================================================================
187  struct INELGt0 : public Base
188  {
195  INELGt0(Bool_t verbose=false, Int_t monitor=0)
196  : Base(verbose,monitor)
197  {
198  SetTrigger("INEL>0");
199  }
206  {
207  if (fHeader->fType & 0x4) return true;
208  return false;
209  }
210  ClassDef(INELGt0,1);
211  };
212 
213  //====================================================================
218  struct V0AND : public Base
219  {
226  V0AND(Bool_t verbose=false, Int_t monitor=0)
227  : Base(verbose,monitor)
228  {
229  SetTrigger("V0AND");
230  }
237  {
238  return CheckTrigger();
239  }
240  ClassDef(V0AND,1);
241  };
242 
243  //====================================================================
244  struct Cent : public Base
245  {
247  const Long_t fMinEvents;
256  Cent(const char* method="V0M", Bool_t verbose=true, Int_t monitor=0)
257  : Base(verbose,monitor),
258  fHelper(method),
259  fMinEvents(100),
260  fCentBin(0)
261  {
262  fTrigMask = 0x0;
263  fCentMethod = fHelper.fCentMeth;
264  }
270  virtual TH1* CreateSingle() { return Base::CreatedNdeta(); }
276  virtual void SlaveBegin(TTree* t)
277  {
278  Base::SlaveBegin(t);
279  // We use the parent fdNdeta histogram as a cache
280  fdNdeta->SetName("cache");
281  fdNdeta->SetTitle("Cache");
282 
283  fHelper.CreateHistos(fOutput, Base::CreateOutput);
284  fOutput->ls();
285  }
292  {
293  if (!Base::SetupEstimator()) return false;
294 
295  fHelper.CreateDiagnostics(fOutput, fCentHist);
296  return true;
297  }
298 
302  virtual void Clear(Option_t* option="")
303  {
304  Base::Clear(option);
305  fdNdeta->Reset(); // Clear the cache
306  }
313  {
314  if (!CheckTrigger()) return false;
315  Double_t cent = GetCentrality();
316  fCentBin = fHelper.CheckCentrality(cent,
317  fEventMult,
318  fHeader->fB,
320  fHeader->fNbin);
321  return fCentBin >= 0;
322  }
331  virtual void ProcessParticles()
332  {
333  // Check we got a bin
334  if (fCentBin < 0) return;
335 
336  // Find the histogram to update
337  TH1* out = static_cast<TH1*>(fHelper.fCentList->At(fCentBin-1));
338  // If we still have no histogram, return immediately
339  if (!out) return;
340 
341  // Use parent function to fill cache
343  if (fVerbose) {
344  Double_t n0 = fdNdeta->GetBinContent(fdNdeta->GetNbinsX()/2);
345  Double_t d0 = fdNdeta->GetXaxis()->GetBinWidth(fdNdeta->GetNbinsX()
346  /2);
347  Double_t eta0 = (n0 / d0);
348  Printf("Centrality %6.2f-%6.2f (bin %4d) "
349  "Nch=%8.1f/%4.2f=%8.1f out=%s (%d)",
350  fHelper.fCentAxis->GetBinLowEdge(fCentBin),
351  fHelper.fCentAxis->GetBinUpEdge(fCentBin),
352  fCentBin,
353  n0, d0, eta0,
354  out->GetName(),
355  Int_t(out->GetBinContent(0)));
356  }
357 
358  // Make sure we have nothing in the underflow bin.
359  fdNdeta->SetBinContent(0,0);
360 
361  // Add our cache to the appropriate bin
362  out->Add(fdNdeta);
363  // Increment underflow bin for the event count
364  out->SetBinContent(0, out->GetBinContent(0)+1);
365  }
372  virtual void Terminate()
373  {
374  fOK = GetEventCount();
375  if (fOK <= 0) {
376  SetStatus(-1);
377  Warning("Terminate", "No events selected");
378  return;
379  }
380 
381  if (!fHelper.Finalize(fOutput, fMinEvents, Cent::Normalize))
382  SetStatus(-1);
383  }
384  static TH1* Normalize(TObject* o, Int_t n)
385  {
386  if (!o->IsA()->InheritsFrom(TH1::Class())) return 0;
387  TH1* h = static_cast<TH1*>(o);
388  Int_t m = h->GetBinContent(0);
389  if (m != n)
390  ::Warning("Normalize", "Different event count here:%d helper:%d",m,n);
391  h->SetBinContent(0,0);
392  h->Scale(1. / n, "width");
393  return h;
394  }
395 
402  {
403  TObject* m1 = new TNamed("cent", "hist text30");
404  TObject* m2 = new TNamed("centAcc", "hist text30");
405  TObject* m3 = new TNamed("byCent", "e");
406 
407  m3->SetUniqueID(0x8); // Scale
408  TList* ret = new TList;
409  ret->Add(m1);
410  ret->Add(m2);
411  ret->Add(m3);
412 
413  return ret;
414  }
415  void Print(Option_t* option="") const
416  {
417  Base::Print(option);
418  Printf(" Least # events: %d", fMinEvents);
419  fHelper.Print(option);
420  }
421  ClassDef(Cent,1);
422  };
423 
424  //====================================================================
430  struct Mult : public Cent
431  {
439  Mult(const char* method="RefMult00d80",
440  Bool_t verbose=false,
441  Int_t monitor=0)
442  : Cent(method, verbose,monitor)
443  {
444  // +1 +2 +3 +3 +5, +5, +5, +5,+10,+10,+10,+10,+10,+10,+10
445  Double_t bins[]={ 0, 3, 6, 9, 14, 19, 24, 29, 39, 49, 59, 69, 79, 89, 99};
446  fHelper.SetCentAxis(14, bins);
447  }
448  ClassDef(Mult,1);
449  };
450 } // End of namespace
451 //====================================================================
452 /*
453  * The function to make our analyser
454  */
456 {
460  dNdetaMaker() : FastAnalysis::Maker("dNdeta") {}
461 
472  FastAnalysis* Make(const TString& subtype,
473  Int_t monitor,
474  Bool_t verbose,
475  TMap& uopt)
476  {
477  FastAnalysis* ret = 0;
478  TString t(subtype);
479  if (t.EqualTo("INEL")) ret = new dNdeta::INEL (verbose,monitor);
480  else if (t.EqualTo("NSD")) ret = new dNdeta::NSD (verbose,monitor);
481  else if (t.EqualTo("INELGt0")) ret = new dNdeta::INELGt0(verbose,monitor);
482  else if (t.EqualTo("V0AND")) ret = new dNdeta::V0AND (verbose,monitor);
483  else if (t.BeginsWith("MULT") || t.BeginsWith("CENT")) {
484  TString w(t(4, t.Length()-4));
485  if (!(w.BeginsWith("RefMult") ||
486  w.BeginsWith("ZNA") ||
487  w.BeginsWith("ZNC") ||
488  w.BeginsWith("ZPA") ||
489  w.BeginsWith("ZPC") ||
490  w.BeginsWith("V0M") ||
491  w.BeginsWith("V0A") ||
492  w.BeginsWith("V0C") ||
493  w.BeginsWith("B") ||
494  w.IsNull())) {
495  Printf("Warning: dNdetaMaker::Make: Unknown estimator: %s",
496  w.Data());
497  return 0;
498  }
499  if (t.BeginsWith("MULT"))
500  ret = new dNdeta::Mult(w, verbose, monitor);
501  else
502  ret = new dNdeta::Cent(w, verbose, monitor);
503  }
504 
505  if (ret) {
506  TPair* tp = static_cast<TPair*>(uopt.FindObject("trig"));
507  if( tp) ret->SetTrigger(tp->Value()->GetName());
508  }
509  else
510  Printf("Error: dNdetaMaker::Make: Invalid spec: %s", t.Data());
511  return ret;
512  }
517  void List() const
518  {
519  Printf(" INEL - inelastic");
520  Printf(" INELGt0 - inelastic with at least 1 particle in |eta|<1");
521  Printf(" NSD - Non-single diffractive");
522  Printf(" V0AND - Visible X-section");
523  Printf(" CENT<est> - Centrality classes. <est> is one of ");
524  Printf(" ZNA - ZNA signal");
525  Printf(" ZNC - ZNC signal");
526  Printf(" ZPA - ZPA signal");
527  Printf(" ZPC - ZPC signal");
528  Printf(" V0M - V0-A + -C");
529  Printf(" V0A - V0-A");
530  Printf(" V0C - V0-C");
531  }
535  const char* Script() const { return __FILE__; }
536 };
537 
538 // ------------------------------------------------------------------
539 // Create instance of maker
541 
542 #ifdef __MAKECINT__
543 #pragma link C++ nestedclasses;
544 #pragma link C++ namespace dNdeta;
545 #endif
546 #endif
547 //
548 // EOF
549 //
TObject * GetOutputObject(const char *name, TClass *cls)
Definition: FastAnalysis.C:490
virtual Bool_t ProcessHeader()
virtual Bool_t ProcessParticle(const TParticle *p)
Bool_t CheckTrigger() const
Definition: FastAnalysis.C:173
Cent(const char *method="V0M", Bool_t verbose=true, Int_t monitor=0)
double Double_t
Definition: External.C:58
FastShortHeader * fHeader
Definition: FastAnalysis.C:70
virtual Bool_t SetupEstimator()
Definition: FastAnalysis.C:250
Bool_t Finalize(TCollection *output, Long_t minEvents, TH1 *(*callback)(TObject *, Int_t))
static TObject * CreateOutput()
TH1 * fCentHist
Definition: FastAnalysis.C:84
This script defines classes for looping over the data produced by FastSim.C.
NSD(Bool_t verbose=false, Int_t monitor=0)
virtual Bool_t ProcessHeader()
virtual void Fill(Double_t eta)
FastCentHelper fHelper
dNdetaMaker * _dNdetaMaker
const char * Script() const
virtual void Clear(Option_t *option="")
virtual TList * GetMonitorObjects()
int Int_t
Definition: External.C:63
V0AND(Bool_t verbose=false, Int_t monitor=0)
virtual Bool_t SetupEstimator()
virtual void SlaveBegin(TTree *t)
Int_t method
static TH1 * Normalize(TObject *o, Int_t n)
static TH1D * CreatedNdeta()
virtual Bool_t ProcessHeader()
Definition: External.C:212
void Print(Option_t *option="") const
virtual void Terminate()
Base(Bool_t verbose=false, Int_t monitor=0)
void CreateHistos(TCollection *output, TObject *(*callback)())
virtual void Print(Option_t *option="") const
Definition: FastAnalysis.C:403
Long_t GetEventCount()
Definition: FastAnalysis.C:472
Double_t GetCentrality() const
Definition: FastAnalysis.C:442
virtual void ProcessParticles()
Definition: FastAnalysis.C:561
Bool_t fVerbose
Definition: FastAnalysis.C:74
Mult(const char *method="RefMult00d80", Bool_t verbose=false, Int_t monitor=0)
INEL(Bool_t verbose=false, Int_t monitor=0)
void Print(Option_t *option="") const
virtual Bool_t ProcessHeader()
ULong64_t fEventMult
Definition: FastAnalysis.C:80
ULong_t fOK
Definition: FastAnalysis.C:86
void CreateDiagnostics(TCollection *output, TH1 *centHist)
Int_t CheckCentrality(Double_t cent, Double_t mult, Double_t b, Double_t nPart, Double_t nBin)
virtual Bool_t ProcessHeader()
virtual void ProcessParticles()
INELGt0(Bool_t verbose=false, Int_t monitor=0)
void List() const
virtual void Terminate()
const char Option_t
Definition: External.C:48
FastAnalysis * Make(const TString &subtype, Int_t monitor, Bool_t verbose, TMap &uopt)
bool Bool_t
Definition: External.C:53
void SetTrigger(UInt_t mask)
Definition: FastAnalysis.C:125
UInt_t fTrigMask
Definition: FastAnalysis.C:90
virtual TList * GetMonitorObjects()
const Long_t fMinEvents
TString fCentMethod
Definition: FastAnalysis.C:82
virtual TH1 * CreateSingle()
virtual void SlaveBegin(TTree *)
Definition: External.C:196
virtual void Clear(Option_t *option="")
Definition: FastAnalysis.C:546