]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGLF/FORWARD/analysis2/AliBaseESDTask.h
Merge branch 'workdir'
[u/mrichter/AliRoot.git] / PWGLF / FORWARD / analysis2 / AliBaseESDTask.h
1 //
2 // Base class for FMD ESD input - sub classes can use the services to
3 // easily setup a task to process the FMD ESD data 
4 //
5 #ifndef ALIFMDESDTASK_H
6 #define ALIFMDESDTASK_H
7
8 #include <AliAnalysisTaskSE.h>
9 class AliFMDEventInspector;
10 class AliCorrectionManagerBase;
11 class AliAODHandler;
12 class AliESDEvent;
13 class TAxis;
14 class TList;
15
16 /**
17  * Base class for tasks that analyse the FMD ESD.  This wraps a
18  * single-event analysis task, and provides a modified interface to
19  * implement for the sub-classes:
20  *
21  * @code
22  * class MyFMDESDTask : public AliBaseESDTask 
23  * { 
24  * public: 
25  *   MyFMDESDTask() : AliBaseESDTask() {}
26  *   MyFMDESDTask(const char* name) : AliBaseESDTask(name)
27  *   { 
28  *   }
29  *   AliFMDEventInspector& GetEventInspector() { return fInspector; }
30  *   const AliFMDEventInspector& GetEventInspector() const{ return fInspector; }
31  *   Bool_t Book() 
32  *   {
33  *     fNeededCorrections = AliForwardCorrectionManager::kELossFits;
34  *     fSharingFilter.CreateUserObject(fList);
35  *     return true;
36  *   }
37  *   Bool_t PreData(const TAxis& vertex, const TAxis& eta)
38  *   {
39  *     fSharingFilter.SetupForData(eta);
40  *     return true;
41  *   }
42  *   Bool_t PreEvent() { fESDFMD.Clear(); return true; } 
43  *   Bool_t PostEvent() { return true; } 
44  *   Bool_t Event(AliESDEvent& esd)
45  *   {
46  *     Bool_t   lowFlux   = kFALSE;
47  *     UInt_t   triggers  = 0;
48  *     UShort_t ivz       = 0;
49  *     TVector3 ip;
50  *     Double_t cent      = -1;
51  *     UShort_t nClusters = 0;
52  *     UInt_t   found     = fEventInspector.Process(esd, triggers, lowFlux, 
53  *                                                  ivz, ip, cent, nClusters);
54  *     if (found & AliFMDEventInspector::kNoEvent)    return false;
55  *     if (found & AliFMDEventInspector::kNoTriggers) return false;
56  *     if (found & AliFMDEventInspector::kNoSPD)      return;
57  *     if (found & AliFMDEventInspector::kNoFMD)      return;
58  *     if (found & AliFMDEventInspector::kNoVertex)   return;
59  *     if (triggers & AliAODForwardMult::kPileUp)     return;
60  *     if (found & AliFMDEventInspector::kBadVertex)  return;
61  * 
62  *     Bool_t ret = fSharingFilter.Filter(esd, lowFlux, fESDFMD, ip.Z());
63  *     return ret;
64  *   }
65  *   Bool_t Finalize()
66  *   {
67  *     GetSharingFilter().Terminate(fList,fResults,Int_t(nTr));
68  *     return true;
69  *   }
70  * protected:
71  *   AliFMDEventInsepctor fInspector;
72  *   AliFMDSharingFilter  fSharingFilter;
73  *   AliESDFMD            fESDFMD;
74  * };
75  * @endcode 
76  * 
77  */
78 class AliBaseESDTask : public AliAnalysisTaskSE
79 {
80 public:
81   /** 
82    * Default (I/O) constructor - do not use directly
83    */
84   AliBaseESDTask();
85   /** 
86    * User constructor 
87    * 
88    * @param name  Name of the task 
89    * @param title Class name used in configuration script 
90    * @param manager Correction manager 
91    */
92   AliBaseESDTask(const char* name, const char* title,
93                  AliCorrectionManagerBase* manager);
94   /** 
95    * Add this task to the manager and connect the outputs.  If @a
96    * sumFile is null or the empty string, then the sum container is
97    * stored in the default output file of the manager.  If @a resFile
98    * is null or the empty string, then it is set to @a resFile if
99    * defined, otherwise to the default output file of the manager.
100    * 
101    * @param sumFile Output file for sums
102    * @param resFile Output file for sums
103    * 
104    * @return true on success 
105    */
106   virtual Bool_t Connect(const char* sumFile=0, const char* resFile=0);
107   /** 
108    * Called when initializing the train 
109    */
110   virtual Bool_t Setup() { return true; }
111   /** 
112    * Book output objects. Derived class should define this to book
113    * output objects on the processing output list @c fList before the
114    * actual event processing.  This is called on the master and on
115    * each slave.
116    * 
117    * If this member function returns false, the execution is stopped
118    * with a fatal signal.
119    *
120    * @return true on success. 
121    */
122   virtual Bool_t Book() = 0;
123   /** 
124    * Called after reading in the first event. Here we can setup stuff
125    * depending on the conditions we're running under.
126    * 
127    * @return true on success.  If this returns false, then we turn the
128    * task into a zombie and we do no more processing.
129    */
130   virtual Bool_t PreData(const TAxis& vertex, const TAxis& eta);
131   /** 
132    * Called before processing a single event - should not do anything
133    * but clear data, etc.
134    * 
135    * @return true on success
136    */
137   virtual Bool_t PreEvent() { return true; }
138   /** 
139    * Process a single event
140    * 
141    * @param esd Input event 
142    * 
143    * @return true on success 
144    */
145   virtual Bool_t Event(AliESDEvent& esd) = 0;
146   /** 
147    * Called after processing a single event - should not do anything
148    * but clear data, etc.
149    * 
150    * @return true on success
151    */
152   virtual Bool_t PostEvent() { return true; }
153   /** 
154    * Do the final analysis on the merged output. 
155    * 
156    * @return true on success
157    */
158   virtual Bool_t Finalize() { return true; }
159   /** 
160    * @{ 
161    * @name Utility methods 
162    */
163   /** 
164    * Print information 
165    * 
166    * @param option Not used
167    */
168   virtual void Print(Option_t* option="") const;
169   /** 
170    * Set the debug level 
171    * 
172    * @param dbg 
173    */
174   virtual void SetDebug(Int_t dbg);
175   /** 
176    * Overload super class method for setting debug level to call our
177    * SetDebug member function.
178    * 
179    * @param dbg Debug level (0: no output, 1: essentials, 3: a whole lot)
180    */
181   virtual void SetDebugLevel(Int_t dbg) 
182   { 
183     AliAnalysisTaskSE::SetDebugLevel(dbg); 
184     SetDebug(dbg);
185   }
186   /* @} */
187   // --- Configuration etc -------------------------------------------
188   /** @{ 
189    * @name Access sub-components 
190    */
191   /** 
192    * Configure this task via a macro 
193    * 
194    * @param macro Macro to configure va 
195    * 
196    * @return true on success, false otherwise
197    */
198   virtual Bool_t Configure(const char* macro="ForwardAODConfig.C");
199   /** 
200    * Get a reference to the event inspector. User must override this
201    * to return proper object
202    * 
203    * @return Reference to the event inspector 
204    */
205   virtual AliFMDEventInspector& GetEventInspector() = 0;
206   /** 
207    * Get a reference to the event inspector. User must override this
208    * to return proper object
209    * 
210    * @return Reference to the event inspector 
211    */
212   virtual const AliFMDEventInspector& GetEventInspector() const = 0;
213   /* @} */
214 protected:
215   /** 
216    * Copy constructor - left undefined
217    * 
218    * @param o Object to copy from 
219    */
220   AliBaseESDTask(const AliBaseESDTask& o);
221   /** 
222    * Assignment operator - left undefined 
223    * 
224    * @param o Object to assign from 
225    * 
226    * @return Reference to this object.
227    */
228   AliBaseESDTask& operator=(const AliBaseESDTask& o);
229   // --- Customize ---------------------------------------------------
230   /** 
231    * Evaluate wether this is for MC. User class can override this 
232    * 
233    * @return true if we're to initialize corrections for MC input
234    */
235   virtual Bool_t IsMC() const { return false; }
236   /** 
237    * Set the default eta axis to use in case we didn't get one from
238    * the read-in corretions.  Override this if the sub class should go
239    * on even without a valid eta axis from the corrections (e.g. QA
240    * task)
241    * 
242    * @return null
243    */
244   virtual TAxis* DefaultEtaAxis() const;
245   /** 
246    * Set the default eta axis to use in case we didn't get one from
247    * the read-in corretions.  Override this if the sub class should go
248    * on even without a valid eta axis from the corrections (e.g. QA
249    * task)
250    * 
251    * @return null
252    */
253   virtual TAxis* DefaultVertexAxis() const;
254   /** 
255    * Get the correction mananger.  Derived class should overload this
256    * to return the proper object.
257    * 
258    * @return Pointer to correction manager
259    */
260   virtual AliCorrectionManagerBase* GetManager() const { return fCorrManager; }
261   /** 
262    * Get the correction mananger.  Derived class should overload this
263    * to return the proper object.
264    * 
265    * @return Pointer to correction manager
266    */
267   virtual AliCorrectionManagerBase* GetManager() { return fCorrManager; }
268
269   // --- Task methods ------------------------------------------------
270   /** 
271    * @{ 
272    * @name Task interface methods 
273    */
274   /** 
275    * Initialize the task 
276    */
277   void LocalInit();
278   /** 
279    * Create output objects 
280    */
281   void UserCreateOutputObjects();
282   /** 
283    * Process each event 
284    *
285    * @param option Not used
286    */  
287   void UserExec(Option_t* option);
288   /** 
289    * End of job
290    * 
291    * @param option Not used 
292    */
293   void Terminate(Option_t* option);
294   /** 
295    * @} 
296    */
297   // --- Services for derived classes --------------------------------
298   /**
299    * Create output branches - called from UserCreateOutputObjects
300    */
301   virtual void CreateBranches(AliAODHandler*) {}
302   /**
303    * Mark this event as one to store in the AOD 
304    * 
305    */
306   virtual void MarkEventForStore() const;
307   /** 
308    * Check if all needed corrections are there and accounted for.  If not,
309    * do a Fatal exit 
310    * 
311    * @param what Which corrections is needed
312    * 
313    * @return true if all present, false otherwise
314    */  
315   virtual Bool_t CheckCorrections(UInt_t what) const;
316   /** 
317    * Read corrections
318    * 
319    * 
320    * @param pe  On return, the eta axis
321    * @param pv  On return ,the vertex axis 
322    * @param mc  True assume MC input
323    * @param sat True if we need for satellite interactions too 
324    * 
325    * @return true ons succcss
326    */
327   virtual Bool_t ReadCorrections(const TAxis*& pe, 
328                                  const TAxis*& pv,
329                                  Bool_t mc=false,
330                                  Bool_t sat=false);
331   /**
332    * Get the ESD event. IF this is the first event, initialise
333    *
334    * @return Pointer to ESD event structore 
335    */
336   virtual AliESDEvent* GetESDEvent();
337
338   // --- Members -----------------------------------------------------
339   Bool_t fFirstEvent;        // Wheter we're waiting for the first event
340   TList* fList;              // Output list 
341   TList* fResults;           // Results list 
342   UInt_t fNeededCorrections; // Set this to bit-mask of corrections we need
343   UInt_t fExtraCorrections;  // Set this to bit-mask of corrections we'd like
344   Bool_t fCloneList;         // Result list is a clone of sum list
345 private:
346   /**
347    * A pointer to the corrections manager.  This is here to make the
348    * corrections manager persistent - that is, when we write the
349    * analysis train to a file (as done in PROOF) we should also write
350    * down the corrections mananger.   This pointer ensures that. 
351    * 
352    */
353   AliCorrectionManagerBase* fCorrManager; // Pointer to corrections manager
354
355   ClassDef(AliBaseESDTask,1);
356 };
357 #endif
358 // Local Variables:
359 //   mode: C++
360 // End: