]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/global/AliHLTVertexFinderBase.h
implementing pid hypothesis in track loop, and configuration from OCDB object (Timur)
[u/mrichter/AliRoot.git] / HLT / global / AliHLTVertexFinderBase.h
1 //-*- Mode: C++ -*-
2 // $Id$
3 #ifndef ALIHLTVERTEXFINDERBASE_H
4 #define ALIHLTVERTEXFINDERBASE_H
5 /// This file is property of and copyright by the ALICE HLT Project         
6 /// ALICE Experiment at CERN, All rights reserved.                         
7 /// See cxx source for full Copyright notice                               
8
9 /// @file   AliHLTVertexFinderBase.h
10 /// @author Timur Pocheptsov
11 /// @date   2010-12-26
12 /// @brief  Base class for vertex finder components
13 ///
14
15
16 #include <vector>
17 #include <map>
18
19 #include "TString.h"
20
21 #include "AliHLTProcessor.h"
22 #include "AliHLTDataTypes.h"
23 #include "AliKFParticle.h"
24
25
26 //Auxiliary base class, used by primary and V0 vertex finders.
27 //It defines a nested type AliHLTTrackInfo and some
28 //functions to read tracks from input blocks -
29 //this is usefull for both vertexers.
30 //This class has to inherit AliHLTProcessor to be able
31 //to call member functions from AliHLTComponent.
32 //This class is not for end user, it's just a
33 //common base for vertex finders.
34
35 class AliESDEvent;
36 class AliKFVertex;
37
38 class AliHLTVertexFinderBase : public AliHLTProcessor
39 {
40 protected:
41
42   class AliHLTTrackInfo
43   {
44   public:
45     AliHLTTrackInfo()
46         : fID(0),
47           fParticle(),
48           fPrimUsed(false),
49           fPrimDeviation(0.)
50     {
51     }
52
53     AliHLTTrackInfo(int id, const AliVTrack& track,
54                     int pid, bool primUsed, double dev)
55         : fID(id),
56           fParticle(track, pid),
57           fPrimUsed(primUsed),
58           fPrimDeviation(dev)
59     {
60     }
61
62     //Check AliKFParticle parameters and covariance matrix.
63     bool IsKFFinite()const;
64
65     //Track ID taken from input track, just an index in some "collection".
66     int fID;
67
68     AliKFParticle fParticle; //Corresponding to track KFParticle.
69     bool fPrimUsed; //Particle was used for primary vertex fit.
70     double fPrimDeviation; //Primary deviation.
71   };
72
73   //These data types are
74   //used in FillESD functions,
75   //they also used in vertex finders
76   //(v0 finder uses primary finder's block).
77   struct PrimaryFinderBlock
78   {
79     int fFitTracksFlag;
80     int fNPrimaryTracks;
81     int fMinPrimID;
82     int fMaxPrimID;
83     int fPrimTrackIds[1];
84   };
85
86   struct V0FinderBlock
87   {
88     int fNV0s;
89     int fV0s[1];
90   };
91
92 protected:
93
94   //Compiler-generated def ctor will call vector's def
95   //ctor for member, but still, compiler wants mem-init-list.
96   AliHLTVertexFinderBase() : fTrackInfos()
97   {
98   }
99
100   //Read tracks from AliESDEvent
101   //into fTrackInfos.
102   //IMPORTANT: fTrackInfos is not
103   //cleared here before filling,
104   //tracks are appended to the end.
105   //A user (derived class)
106   //has to clear it, if needed.
107   void ReadESDTracks(int posPID, int negPID);
108   void ReadESDTracks(AliESDEvent* esd, int posPID, int negPID);
109   //Read HLT tracks produced by ITS
110   //or TPC (somewhere else?).
111   //IMPORTANT: fTrackInfos is not
112   //cleared here before filling,
113   //tracks are appended to the end.
114   void ReadHLTTracks(const AliHLTComponentDataType& blockType, int posPID, int negPID);
115
116 public:
117   //Produce output for ESD collector from primary and v0 finders' outputs.
118   static void FillESD(AliESDEvent* esd, AliKFVertex* primVtx, const void* primData,
119                       const void* v0Data);
120
121 protected:
122
123   typedef std::vector<AliHLTTrackInfo> TrackInfoVector_t;
124   typedef TrackInfoVector_t::size_type VectorSize_t;
125
126   TrackInfoVector_t fTrackInfos;
127
128   ClassDef(AliHLTVertexFinderBase, 0);
129 };
130
131 namespace AliHLTUtility
132 {
133
134 //Small utility to automate command line parsing.
135 //Command line consists of commands and parameters.
136 //Currently, parameters can be of type int, double,
137 //bool (so, command with one parameter of built-in type)
138 //or CompoundType (this is for more complex
139 //expressions like -command param1 param2 param3).
140 //If SetParameter failes, it MUST throw std::runtime_error
141 //with description. CmdLineParser will convert this
142 //exception into negative integer and will compose
143 //error message.
144
145 class CompoundType
146 {
147 public:
148   virtual ~CompoundType()
149   {
150   }
151
152   virtual unsigned SetParameter(unsigned argc, const char** argv, unsigned currPos) = 0;
153 };
154
155 //Parameter for a command. If the type is CompoundType, it's up to CompoundType
156 //to do all parsing. If it's int, double, bool - checks are done here:
157 //1. Check if parameter was set already (user specified the same command more than
158 //   once - this is an error).
159 //2. Check if parameter for command was specified.
160 //3. Parameter has correct value: 0 or 1 for bool and
161 //   for int or double non-empty constraint is satisfied
162 //
163 //Object of type Parameter holds a pointer to real object of type int, bool, double
164 //(or CompoundType) and this real objects are updated
165 //from command line parameters, using SetParameter function.
166
167 class Parameter
168 {
169 public:
170   enum Constraint
171   {
172     none,
173     positive,
174     nonNegative
175     //Something else.
176   };
177
178   Parameter();
179   Parameter(bool* b);
180   Parameter(int* i, Constraint c);
181   Parameter(double* d, Constraint c);
182   Parameter(CompoundType* cp);
183
184   //Returns number of argv elements processed, starting from
185   //currPos.
186   unsigned SetParameter(unsigned argc, const char** argv, unsigned currPos);
187
188 private:
189   //If any constraint was set:
190   void CheckConstraint();
191   //
192   void SetConstraintChecker();
193
194   bool fWasSet; //Parameter was set already.
195   Constraint fConstraint; //Constraint on parameter.
196
197   bool* fBool; //Real object to set of type bool.
198   int* fInt; //Real object to set of type int.
199   double* fDouble; //Real object to set of type double.
200   CompoundType* fCompound; //"Object" to set of complex type.
201
202   void (*fConstraintChecker)(const Parameter& param); //Constraint checker.
203
204   static void CheckPositive(const Parameter& param);
205   static void CheckNonNegative(const Parameter& param);
206   //Something else.
207
208   //Compiler generated dtor, copy-ctor and copy-assignment operators are ok.
209 };
210
211 //CmdLineParser parses char** argv, which constains commands and
212 //options for these commands.
213 //Returns the number of processed argv elements.
214
215 class CmdLineParser
216 {
217 public:
218
219   CmdLineParser() : fParameters(), fIgnored(), fError()
220   {
221   }
222
223   void Add(const TString& cmd, bool* b);
224   void Add(const TString& cmd, int* i, Parameter::Constraint c = Parameter::none);
225   void Add(const TString& cmd, double* d, Parameter::Constraint c = Parameter::none);
226   void Add(const TString& cmd, CompoundType* ct);
227
228   //Skip -command nParams * params
229   void IgnoreCommand(const TString& cmd, unsigned nParams);
230
231   int Parse(unsigned argc, const char** argv, unsigned currPos);
232
233   const TString& GetError()const
234   {
235     return fError;
236   }
237
238 private:
239
240   typedef std::map<TString, Parameter> ParameterMap_t;
241   typedef ParameterMap_t::iterator MapIter_t;
242   typedef std::map<TString, unsigned> SkipMap_t;
243   typedef SkipMap_t::const_iterator SkipMapIter_t;
244
245   //Map of commands and it's parameters.
246   ParameterMap_t fParameters;
247   //These commands and its parameters (if any) will be skipped.
248   SkipMap_t fIgnored;
249
250   TString fError; //Error message describing parsing errors.
251 };
252
253 }
254
255 #endif