AliPhysics  a6017e1 (a6017e1)
ELossTimeTask.C
Go to the documentation of this file.
1 #ifndef __CINT__
2 # include <AliFMDEventInspector.h>
4 # include <TH2.h>
5 # include <AliESDFMD.h>
6 # include <AliAODForwardMult.h>
7 # include <AliESDEvent.h>
8 # include <TFile.h>
9 # include <TSystem.h>
10 #else
12 class TH2;
13 class AliESDFMD;
14 #endif
15 #include <AliBaseESDTask.h>
16 #include <AliForwardUtil.h>
17 #define NO_TASK
18 #define NO_SORTER
19 #include "EventTimeTask.C"
20 
32 {
37  : AliBaseESDTask(),
39  fFMD1i(),
40  fFMD2i(),
41  fFMD2o(),
42  fFMD3i(),
43  fFMD3o(),
44  fMap(0),
45  fDt(0)
46  {}
52  ELossTimeTask(const char* name)
53  : AliBaseESDTask(name, "ELossTimeTask",
54  &(AliForwardCorrectionManager::Instance())),
55  fEventInspector("fmdEventInspector"),
56  fFMD1i(1, 'i'),
57  fFMD2i(2, 'i'),
58  fFMD2o(2, 'o'),
59  fFMD3i(3, 'i'),
60  fFMD3o(3, 'o'),
61  fMap(0),
62  fDt(0)
63  {
64  }
76  virtual Bool_t Book()
77  {
80 
81  fDt = new TH1D("dt", "Time-to-last event (PS-triggered)", 60, 0, 15);
82  fDt->SetXTitle("log_{10}(#Deltat)");
83  fDt->SetFillColor(kYellow+2);
84  fDt->SetLineColor(kYellow+2);
85  fDt->SetFillStyle(3001);
86  fDt->SetDirectory(0);
87  fList->Add(fDt);
88 
89  fFMD1i.Book(fList, fDt);
90  fFMD2i.Book(fList, fDt);
91  fFMD2o.Book(fList, fDt);
92  fFMD3i.Book(fList, fDt);
93  fFMD3o.Book(fList, fDt);
94 
95  // Possibly re-read map
96  ReadMap("map.root");
97 
98  return true;
99  }
107  virtual Bool_t Event(AliESDEvent& esd)
108  {
109  Bool_t lowFlux = kFALSE;
110  UInt_t triggers = 0;
111  UShort_t ivz = 0;
112  TVector3 ip;
113  Double_t cent = 0;
114  UShort_t nClusters = 0;
115  UInt_t found = fEventInspector.Process(&esd, triggers, lowFlux,
116  ivz, ip, cent, nClusters);
117  if (found & AliFMDEventInspector::kNoEvent) return false;
118  if (found & AliFMDEventInspector::kNoTriggers) return false;
119  if (found & AliFMDEventInspector::kNoSPD) return false;
120  if (found & AliFMDEventInspector::kNoFMD) return false;
121  if (found & AliFMDEventInspector::kNoVertex) return false;
122  if (found & AliFMDEventInspector::kBadVertex) return false;
123 
124  // do not process pile-up, A, C, and E events
125  if (triggers & AliAODForwardMult::kPileUp) return false;
126  if (triggers & AliAODForwardMult::kA) return false;
127  if (triggers & AliAODForwardMult::kC) return false;
128  if (triggers & AliAODForwardMult::kE) return false;
129 
130  // We want only the events found by off-line
131  if (!(triggers & AliAODForwardMult::kOffline)) return false;
132 
133  // Perhaps we should also insist on MB only
134  // if (fOnlyMB && (!(triggers & AliAODForwardMult::kInel))) return false;
135 
136  // Get FMD data
137  AliESDFMD* esdFMD = esd.GetFMDData();
138  ULong64_t period = esd.GetPeriodNumber();
139  ULong64_t orbit = esd.GetOrbitNumber();
140  ULong64_t bc = esd.GetBunchCrossNumber();
141  ULong64_t full = EventTimeData::EncodeFull(period, orbit, bc);
142  ULong64_t dt = fMap->Get(full);
143  Double_t logDt = TMath::Log10(25. * dt);
144  if (dt == EventTimeMap::kInvalidTime) {
145  logDt = 0;
146  Printf("!!! Failed to find dT for 0x%016llu", full);
147  }
148  // else
149  // Printf("=== 0x%016llu -> 0x%016llu", full, dt);
150  fDt->Fill(logDt);
151 
152  for (UShort_t d = 1; d <= 3; d++) {
153  UShort_t nQ = d == 1 ? 1 : 2;
154  for (UShort_t q = 0; q < nQ; q++) {
155  RingHistos* r = 0;
156  switch (d) {
157  case 1: r = &fFMD1i; break;
158  case 2: r = (q == 0 ? &fFMD2i : &fFMD2o); break;
159  case 3: r = (q == 0 ? &fFMD3i : &fFMD3o); break;
160  }
161  r->Event(*esdFMD, logDt);
162  }
163  }
164  return true;
165  }
171  virtual Bool_t Finalize()
172  {
173  fDt = static_cast<TH1*>(fList->FindObject("dt"));
174 
180  return true;
181  }
195  virtual const AliFMDEventInspector& GetEventInspector() const
196  {
197  return fEventInspector;
198  }
206  Bool_t ReadMap(const char* filename)
207  {
208  if (gSystem->AccessPathName(filename, kReadPermission)) {
209  // TSystem::AccessPathName returns false if file can be accessed!
210  Error("ReadMap", "File \"%s\" cannot be open for reading", filename);
211  return false;
212  }
213  Printf("Opening \"%s\" ...", filename);
214  TFile* file = TFile::Open(filename, "READ");
215  if (!file) {
216  Error("ReadMap", "Failed to open file \"%s\"", filename);
217  return false;
218  }
219  Printf("Opened \"%s\" ...", filename);
220  TObject* o = file->Get("eventTimeMap");
221  if (!o) {
222  Error("ReadMap", "Failed to get \"eventTimeMap\" from %s", filename);
223  return false;
224  }
225  Printf("Got object \"eventTimeMap\" from \"%s\" ...", filename);
226  if (!o->IsA()->InheritsFrom(EventTimeMap::Class())) {
227  Error("ReadMap", "Object \"%s\" is not an EventTimeMap, but a %s",
228  o->GetName(), o->ClassName());
229  return false;
230  }
231  Printf("Set the \"eventTimeMap\" to use");
232  if (fMap) {
233  delete fMap;
234  fMap = 0;
235  }
236  fMap = static_cast<EventTimeMap*>(o);
237  file->Close();
238  return true;
239  }
247  static Bool_t Create(const char* mapfile)
248  {
249  ELossTimeTask* task = new ELossTimeTask("elossTime");
250  if (!task->ReadMap(mapfile)) return false;
251  task->Connect();
252  return true;
253  }
254 protected:
267  {
273  fDtVsELoss(0)
274  {}
282  : AliForwardUtil::RingHistos(d,r),
283  fDtVsELoss(0)
284  {}
294  {
295  TList* l = DefineOutputList(dir);
296  // Double_t dtBins[] = { 0, 1, 2e3, 5e5, 1.1e6, 5e6, 1e12, 1e20 };
297  fDtVsELoss = new TH2D("dtVsELoss",
298  Form("#Deltat vs #Delta/#Delta_{mip} - %s",
299  GetName()), 450, 0, 15,
300  dt->GetXaxis()->GetNbins(),
301  dt->GetXaxis()->GetXmin(),
302  dt->GetXaxis()->GetXmax());
303  fDtVsELoss->SetXTitle("#Delta/#Delta_{mip}");
304  fDtVsELoss->SetYTitle("log_{10}(#Deltat) [ns]");
305  fDtVsELoss->SetMarkerColor(Color());
306  fDtVsELoss->SetDirectory(0);
307  l->Add(fDtVsELoss);
308 
309  return true;
310  }
317  void Event(AliESDFMD& fmd, Double_t logDt)
318  {
319  const UShort_t nSec = NSector();
320  const UShort_t nStr = NStrip();
321  for (UShort_t s = 0; s < nSec; s++) {
322  for (UShort_t t = 0; t < nStr; t++) {
323  Float_t mult = fmd.Multiplicity(fDet,fRing,s,t);
324  if(mult == AliESDFMD::kInvalidMult || mult <= 0)
325  continue;
326  fDtVsELoss->Fill(mult, logDt);
327  }
328  }
329  }
330  void Finalize(const TList* input, TList* output, TH1* dt)
331  {
332  TList* in = GetOutputList(input);
333  TList* out = DefineOutputList(output);
334 
335  fDtVsELoss = static_cast<TH2*>(in->FindObject("dtVsELoss"));
336 
337  TH2* dtVsELoss = static_cast<TH2*>(fDtVsELoss->Clone());
338  dtVsELoss->SetDirectory(0);
339  dtVsELoss->SetZTitle("1/N_{events}");
340  dtVsELoss->Reset();
341  for (UShort_t j = 1; j <= dt->GetNbinsX(); j++) {
342  Double_t norm = dt->GetBinContent(j);
343  if (norm <= 0) {
344  // Warning("Finalize", "Bin %d empty in dT", j);
345  continue;
346  }
347  for (UShort_t i = 1; i <= fDtVsELoss->GetNbinsX(); i++) {
348  Double_t c = fDtVsELoss->GetBinContent(i, j);
349  Double_t e = fDtVsELoss->GetBinError(i, j);
350  dtVsELoss->SetBinContent(i,j,c/norm);
351  dtVsELoss->SetBinError(i,j,e/norm);
352  }
353  }
354  out->Add(dtVsELoss);
355  }
358  ClassDef(RingHistos,1)
359  };
374  ClassDef(ELossTimeTask,2)
375 };
376 //
377 // EOF
378 //
virtual Bool_t Finalize()
const char * filename
Definition: TestFCM.C:1
virtual const AliFMDEventInspector & GetEventInspector() const
double Double_t
Definition: External.C:58
virtual Bool_t Book()
Definition: ELossTimeTask.C:76
virtual Bool_t Connect(const char *sumFile=0, const char *resFile=0)
RingHistos(UShort_t d, Char_t r)
virtual AliFMDEventInspector & GetEventInspector()
const UShort_t & NStrip() const
TSystem * gSystem
char Char_t
Definition: External.C:18
ELossTimeTask(const ELossTimeTask &o)
const char * GetName() const
static ULong64_t EncodeFull(ULong64_t period, ULong64_t orbit, ULong64_t bc)
Definition: EventTimeTask.C:66
TCanvas * c
Definition: TestFitELoss.C:172
Bool_t Book(TList *dir, TH1 *dt)
RingHistos fFMD3o
virtual Bool_t Event(AliESDEvent &esd)
EventTimeMap * fMap
UInt_t Process(const AliESDEvent *event, UInt_t &triggers, Bool_t &lowFlux, UShort_t &ivz, TVector3 &ip, Double_t &cent, UShort_t &nClusters)
Per-event per bin.
unsigned int UInt_t
Definition: External.C:33
float Float_t
Definition: External.C:68
Various utilities used in PWGLF/FORWARD.
Definition: External.C:228
Definition: External.C:212
Bool_t ReadMap(const char *filename)
UInt_t fExtraCorrections
const UShort_t & NSector() const
void Event(AliESDFMD &fmd, Double_t logDt)
RingHistos fFMD3i
Definition: External.C:220
TFile * file
TList with histograms for a given trigger.
RingHistos fFMD1i
void Finalize(const TList *input, TList *output, TH1 *dt)
RingHistos fFMD2o
unsigned short UShort_t
Definition: External.C:28
TList * DefineOutputList(TList *d) const
UInt_t fNeededCorrections
bool Bool_t
Definition: External.C:53
static Bool_t Create(const char *mapfile)
AliFMDEventInspector fEventInspector
Value Get(const Key &timestamp) const
Definition: External.C:196
RingHistos fFMD2i
TList * GetOutputList(const TList *d) const
TDirectoryFile * dir
ELossTimeTask(const char *name)
Definition: ELossTimeTask.C:52