]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/global/AliHLTGlobalHistoComponent.h
Add output of VZERO reco directly to multCorr
[u/mrichter/AliRoot.git] / HLT / global / AliHLTGlobalHistoComponent.h
1 // -*- Mode: C++ -*-
2 // $Id$
3
4 #ifndef ALIHLTGLOBALHISTOCOMPONENT_H
5 #define ALIHLTGLOBALHISTOCOMPONENT_H
6 //* This file is property of and copyright by the ALICE HLT Project        * 
7 //* ALICE Experiment at CERN, All rights reserved.                         *
8 //* See cxx source for full Copyright notice                               *
9
10 /// @file   AliHLTGlobalHistoComponent.h
11 /// @author Matthias Richter
12 /// @date   2010-09-16
13 /// @brief  A histogramming component for global ESD properties based
14 ///         on the AliHLTTTreeProcessor
15
16 #include "AliHLTTTreeProcessor.h"
17 #include "TObjString.h"
18 #include "TObjArray.h"
19 #include <string>
20 #include <map>
21 #include <vector>
22
23 /**
24  * @class AliHLTGlobalHistoComponent
25  *
26  * <h2>General properties:</h2>
27  *
28  * Component ID: \b GlobalHisto                                         <br>
29  * Library: \b libAliHLTGlobal.so                                       <br>
30  * Input Data Types: ::kAliHLTAnyDataType                               <br>
31  * Output Data Types: none                                              <br>
32  *
33  * <h2>Mandatory arguments:</h2>
34  * <!-- NOTE: ignore the \li. <i> and </i>: it's just doxygen formatting -->
35  *      
36  * <h2>Optional arguments:</h2>
37  * <!-- NOTE: ignore the \li. <i> and </i>: it's just doxygen formatting -->
38  *
39  * <h2>Configuration:</h2>
40  * <!-- NOTE: ignore the \li. <i> and </i>: it's just doxygen formatting -->
41  * Configuration by component arguments.
42  *
43  * <h2>Default CDB entries:</h2>
44  * The component loads no CDB entries.
45  *
46  * <h2>Performance:</h2>
47  * The component does not process any event data.
48  *
49  * <h2>Memory consumption:</h2>
50  * The component does not process any event data.
51  *
52  * <h2>Output size:</h2>
53  * Depending on the mode.
54  *
55  * @ingroup alihlt_util_components
56  */
57 class AliHLTGlobalHistoComponent : public AliHLTTTreeProcessor
58 {
59  public:
60   /// standard constructor
61   AliHLTGlobalHistoComponent();
62   /// destructor
63   virtual ~AliHLTGlobalHistoComponent();
64
65   /// inherited from AliHLTComponent: return id of the component.
66   virtual const char* GetComponentID() {return "GlobalHisto";};
67   /// inherited from AliHLTComponent: input data types
68   virtual void GetInputDataTypes(AliHLTComponentDataTypeList&);
69  
70   
71   /// interface function, see AliHLTComponent for description
72   AliHLTComponentDataType GetOutputDataType();
73   
74   
75   /// inherited from AliHLTComponent: spawn function, create an instance.
76   virtual AliHLTComponent* Spawn() {return new AliHLTGlobalHistoComponent;}
77
78   void FillHistogramDefinitions();
79
80   /// @class AliHLTGlobalHistoVariables
81   /// container for the tree branch variables
82   template <typename T>
83   class AliHLTGlobalHistoVariables {
84   public:
85     AliHLTGlobalHistoVariables()  : fCapacity(0), fArrays(), fCount(), fKeys() {}
86     AliHLTGlobalHistoVariables(const AliHLTGlobalHistoVariables& src)  : fCapacity(0), fArrays(), fCount(), fKeys() {}
87     ~AliHLTGlobalHistoVariables() {Reset();}
88
89     /// init the arrays
90     int Init(int capacity, const char* names)
91     {
92       /// init the arrays
93       int iResult=0;
94       TString initializer(names);
95       TObjArray* pTokens=initializer.Tokenize(" ");
96       fCapacity=capacity;
97       if (pTokens) {
98         int entries=pTokens->GetEntriesFast();
99         fArrays.resize(entries);
100         fCount.resize(entries);
101         for (int i=0; i<entries; i++) {
102           fKeys[pTokens->At(i)->GetName()]=i;
103           fArrays[i]=new T[fCapacity];
104         }
105         delete pTokens;
106       }
107       if (fArrays.size()!=fCount.size() ||
108           fArrays.size()!=fKeys.size()) {
109         return -EFAULT;
110       }
111
112       ResetCount();
113       return iResult;
114     }
115
116     /// capacity for every key
117     int Capacity() const {return fCapacity;}
118     /// number of variables
119     int Variables() const {return fArrays.size();}
120
121     /// fill variable at index
122     int Fill(unsigned index, T value)
123     {
124       if (index>=fArrays.size() || index>=fCount.size()) return -ENOENT;
125       if (fCount[index]>=fCapacity) return -ENOSPC;
126
127       (fArrays[index])[fCount[index]++]=value;
128       return fCount[index];
129     }
130
131     /// fill variable at key
132     int Fill(const char* key, T value)
133     {
134       int index=FindKey(key);
135       if (index<0) return -ENOENT;
136       return Fill(index, value);
137     }
138
139     /// get array at key
140     T* GetArray(const char* key)
141     {
142       int index=FindKey(key); if (index<0) return NULL;
143       if ((unsigned)index>=fArrays.size()) return NULL;
144       return fArrays[index];
145     }
146
147     /// get the key of an array
148     const char* GetKey(int index) const
149     {
150       for (map<string, int>::const_iterator element=fKeys.begin(); element!=fKeys.end(); element++) {
151         if (element->second==index) return element->first.c_str();
152       }
153       return NULL;
154     }
155
156     /// reset and cleanup arrays
157     int Reset()
158     {
159       for (unsigned i=0; i<fArrays.size(); i++) {delete fArrays[i];}
160       fArrays.clear(); fCount.clear(); fKeys.clear();
161       return 0;
162     }
163
164     /// reset the fill counts
165     int ResetCount()
166     {
167       for (vector<int>::iterator element=fCount.begin(); element!=fCount.end(); element++) *element=0;
168       return 0;
169     }
170
171     char GetType() const {AliHLTGlobalHistoVariablesType type(T&); return type.GetType();}
172
173   private:
174     int FindKey(const char* key) const
175     {
176       map<string, int>::const_iterator element=fKeys.find(key);
177       if (element==fKeys.end()) return -ENOENT;
178       return element->second;
179     }
180
181     /// internal helper class to get the type of the template
182     class AliHLTGlobalHistoVariablesType {
183     public:
184       AliHLTGlobalHistoVariablesType(float&) : fType('f') {}
185       AliHLTGlobalHistoVariablesType(int&)   : fType('i') {}
186       char GetType() const {return fType;}
187     private:
188       char fType; //!
189     };
190
191     /// capacity of all arrays
192     int fCapacity; //!
193     /// pointers of arrays
194     vector<T*> fArrays; //!
195     /// fill count for arrays
196     vector<int> fCount; //!
197     /// map of keys
198     map<string,int> fKeys; //!
199   };
200
201  protected:
202   /// inherited from AliHLTTTreeProcessor: create the tree instance and all branches
203   TTree* CreateTree(int argc, const char** argv);
204   /// inherited from AliHLTTTreeProcessor: process input blocks and fill tree
205   int FillTree(TTree* pTree, const AliHLTComponentEventData& evtData, 
206                        AliHLTComponentTriggerData& trigData );
207   /// dtOrigin for PushBack.
208   AliHLTComponentDataType GetOriginDataType() const;
209   /// spec for PushBack
210   AliHLTUInt32_t GetDataSpec() const {return 0;}
211
212   int ResetVariables();
213   
214 private:
215   /// copy constructor prohibited
216   AliHLTGlobalHistoComponent(const AliHLTGlobalHistoComponent&);
217   /// assignment operator prohibited
218   AliHLTGlobalHistoComponent& operator=(const AliHLTGlobalHistoComponent&);
219     
220   /// the event number, tree filling variable
221   int fEvent; //!
222   /// track count, tree filling variable
223   int fNofTracks; //!
224   /// V0 count, tree filling variable
225   int fNofV0s; //!
226   /// UPC pair count (=1), tree filling variable
227   int fNofUPCpairs; //!
228   /// contributors count, tree filling variable
229   int fNofContributors; //!
230  /// x coordinate of vertex
231   float fVertexX; //!
232   /// y coordinate of vertex
233   float fVertexY; //!
234   /// z coordinate of vertex
235   float fVertexZ; //!
236   /// vertex status, found or not
237   bool fVertexStatus; //!
238  
239   /// filling arrays for track parameters
240   AliHLTGlobalHistoVariables<float> fTrackVariables; //!
241   AliHLTGlobalHistoVariables<int> fTrackVariablesInt; //!
242  
243   /// filling arrays for V0 parameters
244   AliHLTGlobalHistoVariables<float> fV0Variables; //!
245  
246   /// filling arrays for UPC parameters
247   AliHLTGlobalHistoVariables<float> fUPCVariables; //!
248   
249  
250   Double_t fGammaCuts[8];  // cuts for gammas
251   Double_t fKsCuts[8];     // cuts for Ks
252   Double_t fLambdaCuts[8]; // cuts for Lambdas
253   Double_t fAPCuts[8];     // cuts for Armenteros-Podolanski plot
254
255   Int_t fNEvents;  // n of processed events
256   Int_t fNGammas;  // n found total
257   Int_t fNKShorts; // n found total
258   Int_t fNLambdas; // n found total
259   Int_t fNPi0s;    // n found total
260
261   ClassDef(AliHLTGlobalHistoComponent, 0) // HLT Global Histogram component
262 };
263 #endif