]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGLF/FORWARD/analysis2/AliForwardQATask.cxx
updates to run FMD QA without correction objects and small upgrades to the analysis...
[u/mrichter/AliRoot.git] / PWGLF / FORWARD / analysis2 / AliForwardQATask.cxx
1 // 
2 // Calculate the multiplicity in the forward regions event-by-event 
3 // 
4 // Inputs: 
5 //   - AliESDEvent 
6 //
7 // Outputs: 
8 //   - AliAODForwardMult 
9 // 
10 // Histograms 
11 //   
12 // Corrections used 
13 //
14 #include "AliForwardQATask.h"
15 #include "AliForwardUtil.h"
16 #include "AliTriggerAnalysis.h"
17 #include "AliPhysicsSelection.h"
18 #include "AliLog.h"
19 #include "AliESDEvent.h"
20 #include "AliAODHandler.h"
21 #include "AliMultiplicity.h"
22 #include "AliInputEventHandler.h"
23 #include "AliForwardCorrectionManager.h"
24 #include "AliAnalysisManager.h"
25 #include "AliAODForwardMult.h"
26 #include <TH1.h>
27 #include <TDirectory.h>
28 #include <TTree.h>
29 #include <TROOT.h>
30 #include <TStopwatch.h>
31
32 //====================================================================
33 AliForwardQATask::AliForwardQATask()
34   : AliAnalysisTaskSE(),
35     fEnableLowFlux(false), 
36     fFirstEvent(true),
37     fCorrManager(0),
38     fESDFMD(),
39     fHistos(),
40     fEventInspector(),
41     fEnergyFitter(),
42     fSharingFilter(),
43     fDensityCalculator(),
44     fList(0),
45     fDebug(0)
46 {
47   // 
48   // Constructor
49   //
50 }
51
52 //____________________________________________________________________
53 AliForwardQATask::AliForwardQATask(const char* name)
54   : AliAnalysisTaskSE(name),
55     fEnableLowFlux(false), 
56     fFirstEvent(true),
57     fCorrManager(0),
58     fESDFMD(),
59     fHistos(),
60     fEventInspector("event"),
61     fEnergyFitter("energy"),
62     fSharingFilter("sharing"), 
63     fDensityCalculator("density"),
64     fList(0),
65     fDebug(0)
66 {
67   // 
68   // Constructor 
69   // 
70   // Parameters:
71   //    name Name of task 
72   //
73   DefineOutput(1, TList::Class());
74   DefineOutput(2, TList::Class());
75   fCorrManager = &AliForwardCorrectionManager::Instance(); 
76   fEnergyFitter.SetNParticles(1); // Just find the 1st peak 
77   fEnergyFitter.SetDoMakeObject(false); 
78   fEnergyFitter.SetUseIncreasingBins(true);
79   fEnergyFitter.SetDoFits(kTRUE);
80   fEnergyFitter.SetLowCut(0.4);
81   fEnergyFitter.SetFitRangeBinWidth(4);
82   fEnergyFitter.SetMinEntries(1000);
83 }
84
85 //____________________________________________________________________
86 AliForwardQATask::AliForwardQATask(const AliForwardQATask& o)
87   : AliAnalysisTaskSE(o),
88     fEnableLowFlux(o.fEnableLowFlux), 
89     fFirstEvent(o.fFirstEvent),
90     fCorrManager(o.fCorrManager),
91     fESDFMD(o.fESDFMD),
92     fHistos(o.fHistos),
93     fEventInspector(o.fEventInspector),
94     fEnergyFitter(o.fEnergyFitter),
95     fSharingFilter(o.fSharingFilter),
96     fDensityCalculator(o.fDensityCalculator),
97     fList(o.fList),
98     fDebug(o.fDebug) 
99 {
100   // 
101   // Copy constructor 
102   // 
103   // Parameters:
104   //    o Object to copy from 
105   //
106   DefineOutput(1, TList::Class());
107   DefineOutput(2, TList::Class());
108 }
109
110 //____________________________________________________________________
111 AliForwardQATask&
112 AliForwardQATask::operator=(const AliForwardQATask& o)
113 {
114   // 
115   // Assignment operator 
116   // 
117   // Parameters:
118   //    o Object to assign from 
119   // 
120   // Return:
121   //    Reference to this object 
122   //
123   if (&o == this) return *this;
124   AliAnalysisTaskSE::operator=(o);
125
126   fEnableLowFlux     = o.fEnableLowFlux;
127   fFirstEvent        = o.fFirstEvent;
128   fCorrManager       = o.fCorrManager;
129   fEventInspector    = o.fEventInspector;
130   fEnergyFitter      = o.fEnergyFitter;
131   fSharingFilter     = o.fSharingFilter;
132   fDensityCalculator = o.fDensityCalculator;
133   fHistos            = o.fHistos;
134   fList              = o.fList;
135   fDebug             = o.fDebug;
136
137   return *this;
138 }
139
140 //____________________________________________________________________
141 void
142 AliForwardQATask::SetDebug(Int_t dbg)
143 {
144   // 
145   // Set debug level 
146   // 
147   // Parameters:
148   //    dbg Debug level
149   //
150   fDebug = dbg;
151   fEventInspector.SetDebug(dbg);
152   fEnergyFitter.SetDebug(dbg);
153   fSharingFilter.SetDebug(dbg);
154   fDensityCalculator.SetDebug(dbg);
155 }
156
157 //____________________________________________________________________
158 Bool_t 
159 AliForwardQATask::CheckCorrections(UInt_t what) const
160 {
161   // 
162   // Check if all needed corrections are there and accounted for.  If not,
163   // do a Fatal exit 
164   // 
165   // Parameters:
166   //    what Which corrections is needed
167   // 
168   // Return:
169   //    true if all present, false otherwise
170   //  
171
172   AliForwardCorrectionManager& fcm = AliForwardCorrectionManager::Instance();
173   // Check that we have the energy loss fits, needed by 
174   //   AliFMDSharingFilter 
175   //   AliFMDDensityCalculator 
176   if (what & AliForwardCorrectionManager::kELossFits && !fcm.GetELossFit()) { 
177     AliWarning("No energy loss fits");
178     return false;
179   }
180   return true;
181 }
182
183 //____________________________________________________________________
184 Bool_t
185 AliForwardQATask::ReadCorrections(const TAxis*& pe, 
186                                   const TAxis*& pv, 
187                                   Bool_t        mc)
188 {
189   //
190   // Read corrections
191   //
192   //
193   UInt_t what = AliForwardCorrectionManager::kAll;
194   what ^= AliForwardCorrectionManager::kDoubleHit;
195   what ^= AliForwardCorrectionManager::kVertexBias;
196   what ^= AliForwardCorrectionManager::kAcceptance;
197   what ^= AliForwardCorrectionManager::kMergingEfficiency;
198
199   AliForwardCorrectionManager& fcm = AliForwardCorrectionManager::Instance();
200   if (!fcm.Init(GetEventInspector().GetCollisionSystem(),
201                 GetEventInspector().GetEnergy(),
202                 GetEventInspector().GetField(),
203                 mc,
204                 what)) return false;
205   if (!CheckCorrections(what)) {
206     return false;
207   }
208
209   // Sett our persistency pointer 
210   // fCorrManager = &fcm;
211
212   // Get the eta axis from the secondary maps - if read in
213   if (!pe) {
214     pe = fcm.GetEtaAxis();
215     if (!pe) AliFatal("No eta axis defined");
216   }
217   // Get the vertex axis from the secondary maps - if read in
218   if (!pv) {
219     pv = fcm.GetVertexAxis();
220     if (!pv) AliFatal("No vertex axis defined");
221   }
222
223   return true;
224 }
225
226 //____________________________________________________________________
227 AliESDEvent*
228 AliForwardQATask::GetESDEvent()
229 {
230   //
231   // Get the ESD event. IF this is the first event, initialise
232   //
233   if (IsZombie()) return 0;
234   AliESDEvent* esd = dynamic_cast<AliESDEvent*>(InputEvent());
235   if (!esd) {
236     AliWarning("No ESD event found for input event");
237     return 0;
238   }
239
240   // On the first event, initialize the parameters
241   if (fFirstEvent && esd->GetESDRun()) {
242     GetEventInspector().ReadRunDetails(esd);
243
244     AliInfoF("Initializing with parameters from the ESD:\n"
245              "         AliESDEvent::GetBeamEnergy()   ->%f\n"
246              "         AliESDEvent::GetBeamType()     ->%s\n"
247              "         AliESDEvent::GetCurrentL3()    ->%f\n"
248              "         AliESDEvent::GetMagneticField()->%f\n"
249              "         AliESDEvent::GetRunNumber()    ->%d",
250              esd->GetBeamEnergy(),
251              esd->GetBeamType(),
252              esd->GetCurrentL3(),
253              esd->GetMagneticField(),
254              esd->GetRunNumber());
255
256
257     if (!InitializeSubs()) {
258       AliWarning("Initialisation of sub algorithms failed!");
259       SetZombie(true);
260       esd = 0;
261       return 0;
262     }
263     AliInfoF("Clearing first event flag from %s to false", 
264              fFirstEvent ? "true" : "false");
265     fFirstEvent = false;
266   }
267   return esd;
268 }
269 //____________________________________________________________________
270 Bool_t
271 AliForwardQATask::InitializeSubs()
272 {
273   // 
274   // Initialise the sub objects and stuff.  Called on first event 
275   // 
276   //
277   const TAxis* pe = 0;
278   const TAxis* pv = 0;
279
280
281
282
283   if (!ReadCorrections(pe,pv)) 
284   { 
285     AliWarning("Used default binning");
286     pv=new TAxis(10,-10, 10);
287     pe=new TAxis(240,-6,6);
288     //return false;
289   }
290
291   fHistos.Init(*pe);
292
293   fEventInspector.Init(*pv);
294   fEnergyFitter.Init(*pe);
295   fSharingFilter.Init();
296   fDensityCalculator.Init(*pe);
297
298   this->Print();
299
300   return true;
301 }
302
303 //____________________________________________________________________
304 void
305 AliForwardQATask::UserCreateOutputObjects()
306 {
307   // 
308   // Create output objects 
309   // 
310   //
311   fList = new TList;
312   fList->SetOwner();
313   
314   fEventInspector.DefineOutput(fList);
315   fEnergyFitter.DefineOutput(fList);
316   fSharingFilter.DefineOutput(fList);
317   fDensityCalculator.DefineOutput(fList);
318
319   PostData(1, fList);
320 }
321 //____________________________________________________________________
322 void
323 AliForwardQATask::UserExec(Option_t*)
324 {
325   // 
326   // Process each event 
327   // 
328   // Parameters:
329   //    option Not used
330   //  
331
332   // static Int_t cnt = 0;
333   // cnt++;
334   // Get the input data 
335   AliESDEvent* esd = GetESDEvent();
336   if (!esd) { 
337     AliWarning("Got no ESD event");
338     return;
339   }
340   if (fFirstEvent) { 
341     // If the first event flag wasn't cleared in the above call to
342     // GetESDEvent, we should not do anything, since nothing has been
343     // initialised yet, so we opt out here (with a warning) 
344     AliWarning("Nothing has been initialized yet, opt'ing out");
345     return;
346   }
347
348   // Clear stuff 
349   fHistos.Clear();
350   fESDFMD.Clear();
351   
352   Bool_t   lowFlux   = kFALSE;
353   UInt_t   triggers  = 0;
354   UShort_t ivz       = 0;
355   Double_t vz        = 0;
356   Double_t cent      = -1;
357   UShort_t nClusters = 0;
358   UInt_t   found     = fEventInspector.Process(esd, triggers, lowFlux, 
359                                                ivz, vz, cent, nClusters);
360   
361   if (found & AliFMDEventInspector::kNoEvent)    return;
362   if (found & AliFMDEventInspector::kNoTriggers) return;
363   if (found & AliFMDEventInspector::kNoSPD)      return;
364   if (found & AliFMDEventInspector::kNoFMD)      return;
365   if (found & AliFMDEventInspector::kNoVertex)   return;
366   if (triggers & AliAODForwardMult::kPileUp)     return;
367   if (found & AliFMDEventInspector::kBadVertex)  return;
368
369   // We we do not want to use low flux specific code, we disable it here. 
370   if (!fEnableLowFlux) lowFlux = false;
371
372   // Get FMD data 
373   AliESDFMD* esdFMD = esd->GetFMDData();
374   
375   // Run the energy loss fitter 
376   if (!fEnergyFitter.Accumulate(*esdFMD, cent, 
377                                 triggers & AliAODForwardMult::kEmpty)) {
378     AliWarning("Energy fitter failed");
379     return;
380   }
381   
382   //  // Apply the sharing filter (or hit merging or clustering if you like)
383   if (!fSharingFilter.Filter(*esdFMD, lowFlux, fESDFMD, vz)) { 
384     AliWarning("Sharing filter failed!");
385     return;
386   }
387  
388   // Calculate the inclusive charged particle density 
389   if (!fDensityCalculator.Calculate(fESDFMD, fHistos, ivz, lowFlux)) { 
390     // if (!fDensityCalculator.Calculate(*esdFMD, fHistos, ivz, lowFlux)) { 
391     AliWarning("Density calculator failed!");
392     return;
393   }
394   
395   PostData(1, fList);
396 }
397
398 //____________________________________________________________________
399 void
400 AliForwardQATask::Terminate(Option_t*)
401 {
402   // 
403   // End of job
404   // 
405   // Parameters:
406   //    option Not used 
407   //
408   if (fDebug) AliInfo("In Forwards terminate");
409   TStopwatch swt;
410   swt.Start();
411
412   TList* list = dynamic_cast<TList*>(GetOutputData(1));
413   if (!list) {
414     AliError(Form("No output list defined (%p)", GetOutputData(1)));
415     if (GetOutputData(1)) GetOutputData(1)->Print();
416     return;
417   }
418   
419   // Get our histograms from the container 
420   TH1I* hEventsTr    = 0;//static_cast<TH1I*>(list->FindObject("nEventsTr"));
421   TH1I* hEventsTrVtx = 0;//static_cast<TH1I*>(list->FindObject("nEventsTrVtx"));
422   TH1I* hTriggers    = 0;
423   if (!fEventInspector.FetchHistograms(list, hEventsTr, 
424                                        hEventsTrVtx, hTriggers)) { 
425     AliError(Form("Didn't get histograms from event selector "
426                   "(hEventsTr=%p,hEventsTrVtx=%p)", 
427                   hEventsTr, hEventsTrVtx));
428     return;
429   }
430
431   TStopwatch swf;
432   swf.Start();
433   fEnergyFitter.Fit(list);
434   swf.Stop();
435   AliInfoF("Fitting took %d real-time seconds, and %f CPU seconds", 
436            Int_t(swf.RealTime()), swf.CpuTime());
437
438   fSharingFilter.ScaleHistograms(list,Int_t(hEventsTr->Integral()));
439   fDensityCalculator.ScaleHistograms(list,Int_t(hEventsTrVtx->Integral()));
440
441   // Make a deep copy and post that as output 2 
442   TList* list2 = static_cast<TList*>(list->Clone(Form("%sResults", 
443                                                       list->GetName())));
444   if (fDebug) AliInfoF("Posting post processing results to %s", 
445                        list2->GetName());
446   list2->SetOwner();
447   PostData(2, list2);
448
449   swt.Stop();
450   AliInfoF("Terminate took %d real-time seconds, and %f CPU seconds", 
451            Int_t(swt.RealTime()), swt.CpuTime());
452
453 }
454
455 //____________________________________________________________________
456 void
457 AliForwardQATask::Print(Option_t* option) const
458 {
459   // 
460   // Print information 
461   // 
462   // Parameters:
463   //    option Not used
464   //
465   
466   std::cout << ClassName() << ": " << GetName() << "\n" 
467             << "  Enable low flux code:   " << (fEnableLowFlux ? "yes" : "no") 
468             << "\n"
469             << "  Off-line trigger mask:  0x" 
470             << std::hex     << std::setfill('0') 
471             << std::setw (8) << fOfflineTriggerMask 
472             << std::dec     << std::setfill (' ') << std::endl;
473   gROOT->IncreaseDirLevel();
474   if (fCorrManager) fCorrManager->Print();
475   else  
476     std::cout << "  Correction manager not set yet" << std::endl;
477   GetEventInspector()   .Print(option);
478   GetEnergyFitter()     .Print(option);
479   GetSharingFilter()    .Print(option);
480   gROOT->DecreaseDirLevel();
481 }
482
483 //
484 // EOF
485 //