Correct formula for phi, in case of current local X <0, in GetLocalXat and GetPhiZat
[u/mrichter/AliRoot.git] / ITS / AliITSAlignMille2.h
CommitLineData
7b85e477 1#ifndef ALIITSALIGNMILLE2_H
2#define ALIITSALIGNMILLE2_H
6526a72c 3
7b85e477 4/* Copyright(c) 2007-2009 , ALICE Experiment at CERN, All rights reserved. *
5 * See cxx source for full Copyright notice */
6
057304f3 7/* $Id$ */
6526a72c 8//-----------------------------------------------------------------------------
7b85e477 9//
6526a72c 10// Interface to AliMillePede2 alignment class for the ALICE ITS detector
11//
12// ITS specific alignment class which interface to AliMillepede.
13// For each track ProcessTrack calculates the local and global derivatives
14// at each hit and fill the corresponding local equations. Provide methods for
15// fixing or constraining detection elements for best results.
16//
17// author M. Lunardon (thanks to J. Castillo), ruben.shahoyan@cern.ch
18//-----------------------------------------------------------------------------
7b85e477 19
6526a72c 20#include <TArrayI.h>
21#include <TArrayD.h>
7b85e477 22#include <TString.h>
23#include <TObject.h>
6526a72c 24#include <TGeoMatrix.h>
25#include "AliITSresponseSDD.h"
7b85e477 26#include "AliTrackPointArray.h"
27#include "AliITSAlignMille2Module.h"
6526a72c 28#include "AliITSAlignMille2Constraint.h"
29#include "AliITSAlignMille2ConstrArray.h"
7b85e477 30
31class AliMillePede2;
32class AliAlignObjParams;
33class TGeoManager;
7b85e477 34//class AliITSAlignMille2Module;
35class AliTrackFitterRieman;
36class TVirtualFitter;
37// number of used objects
38
7b85e477 39
7b85e477 40
41class AliITSAlignMille2: public TObject
42{
43 public:
6526a72c 44 enum {kNLocal=5,kMaxPoints=100,
45 kNParChGeom = AliITSAlignMille2Module::kMaxParGeom,
46 kNParCh = AliITSAlignMille2Module::kMaxParTot,
47 kMaxITSSensID=2197,kMaxITSSensVID=14300,kMinITSSupeModuleID=14336,kSDDoffsID=240};
7b85e477 48 //
6526a72c 49 protected:
50 struct Mille2Data { // structure to store data for 2 LocalEquations (X and Z)
51 enum {kMaxLev = 7};
52 Double_t measX, measZ, sigmaX, sigmaZ;
53 Double_t derlocX[kNLocal], derlocZ[kNLocal];
54 Int_t nModFilled, nGlobFilled, moduleID[kMaxLev];
55 Int_t parMilleID[AliITSAlignMille2Module::kMaxParTot*kMaxLev];
56 Double_t dergloX[AliITSAlignMille2Module::kMaxParTot*kMaxLev];
57 Double_t dergloZ[AliITSAlignMille2Module::kMaxParTot*kMaxLev];
58 };
59 //
7b85e477 60 public:
61 //
6526a72c 62 AliITSAlignMille2(const Char_t *configFilename="AliITSAlignMille.conf");
7b85e477 63 virtual ~AliITSAlignMille2();
64 //
6526a72c 65 AliMillePede2* GetMillePede() const {return fMillepede;}
66 //
67 // configuration methods
68 //
69 Int_t IsVIDDefined(UShort_t voluid) const;
70 Int_t IsVIDContained(UShort_t voluid) const;
71 Int_t IsSymDefined(const Char_t* name) const;
72 Int_t IsSymContained(const Char_t* name) const;
73 //
7b85e477 74 Int_t GetModuleIndex(const Char_t *symname);
75 Int_t GetModuleIndex(UShort_t voluid);
76 UShort_t GetModuleVolumeID(const Char_t *symname);
77 UShort_t GetModuleVolumeID(Int_t index);
6526a72c 78 AliITSAlignMille2Module* GetMilleModuleByVID(UShort_t voluid) const; // get pointer to the defined supermodule
79 AliITSAlignMille2Module* GetMilleModuleBySymName(const Char_t* symname) const; // get pointer to the defined supermodule
80 AliITSAlignMille2Module* GetMilleModuleIfContained(const Char_t* symname) const;
81 AliITSAlignMille2Module* GetMilleModule(Int_t id) const {return (AliITSAlignMille2Module*)fMilleModule[id];}
82 AliITSAlignMille2Module* GetCurrentModule() const {return fCurrentModule;}
83 AliITSAlignMille2Module* GetSuperModule(Int_t id) const {return (AliITSAlignMille2Module*)fSuperModule[id];}
84 //
85 AliAlignObjParams* GetPrealignedObject(const Char_t* symname) const;
86 AliAlignObjParams* GetConstrRefObject(const Char_t* symname) const;
87 //
88 void ConvertParamsToGlobal();
89 void ConvertParamsToLocal();
7b85e477 90 //
7b85e477 91 const Char_t* GetGeometryFileName() {return fGeometryFileName.Data();}
92 const Char_t* GetPreAlignmentFileName() {return fPreAlignmentFileName.Data();}
93 TClonesArray* GetPreAlignmentDeltas() const {return fPrealignment;}
6526a72c 94 AliITSresponseSDD* GetSDDPrecalibration() const {return fCorrectSDD;}
95 AliITSresponseSDD* GetSDDInit() const {return fInitialRecSDD;}
7b85e477 96 void PrintCurrentModuleInfo() const {if (fCurrentModule) fCurrentModule->Print();}
97 void Print(Option_t*) const;
98 Bool_t IsConfigured() const {return fIsConfigured;}
7b85e477 99 Bool_t GetUseGlobalDelta() const {return fUseGlobalDelta;}
6526a72c 100 Bool_t IsConstraintWrtRef() const {return fConstrRef!=0;}
101 Bool_t FixedOrphans() const;
102 //
103 // geometry stuffs
104 Int_t GetNModules() const {return fNModules;}
105 Int_t GetCurrentModuleIndex() const {return fCurrentModule ? fCurrentModule->GetIndex():-1;}
106 TGeoHMatrix *GetCurrentModuleHMatrix() const {return fCurrentModule ? fCurrentModule->GetMatrix():0;}
107 Double_t *GetCurrentModuleTranslation() const {return fCurrentModule ? fCurrentModule->GetMatrix()->GetTranslation():0;}
108 Int_t GetCurrentModuleInternalIndex() const {return fCurrentModule ? Int_t(fCurrentModule->GetUniqueID()):-1;}
109 Int_t GetTotBadLocEqPoints() const {return fTotBadLocEqPoints;}
110 Int_t GetNConstraints() const {return fConstraints.GetLast()+1;}
111 Int_t InitModuleParams();
7b85e477 112 //
113 // fitting methods
114 AliTrackFitterRieman *GetRiemanFitter() const {return fRieman;}
115 AliTrackPointArray *PrepareTrack(const AliTrackPointArray *track);
6526a72c 116 AliTrackPointArray *GetCurrentTrack() {return fTrack;}
117 AliTrackPoint *GetCurrentCluster() {return &fCluster;}
118 void SetCurrentTrack(AliTrackPointArray *atp) {fTrack=atp;}
119 void SetCurrentCluster(AliTrackPoint &atp) {fCluster=atp;}
7b85e477 120 void InitTrackParams(int meth=1);
6526a72c 121 Int_t ProcessTrack(const AliTrackPointArray *track);
7b85e477 122 Int_t CheckCurrentTrack();
6526a72c 123 //
7b85e477 124 Int_t CalcIntersectionPoint(Double_t *lpar, Double_t *gpar);
125 Int_t CalcDerivatives(Int_t paridx, Bool_t islpar);
126 Double_t* GetLocalIntersectionPoint() const {return (Double_t*)fPintLoc;}
127 Double_t* GetGlobalIntersectionPoint() const {return (Double_t*)fPintGlo;}
128 AliTrackPointArray *SortTrack(const AliTrackPointArray *atp);
129 void SetTemporaryExcludedModule(Int_t index) {fTempExcludedModule=index;}
130 Int_t GetTemporaryExcludedModule() const {return fTempExcludedModule;}
6526a72c 131 Double_t GetMeasGlo(Int_t dim) const {return fMeasGlo[dim];}
132 Double_t GetMeasLoc(Int_t dim) const {return fMeasLoc[dim];}
133 Int_t GetCurrentLayer() const;
7b85e477 134 //
135 // Hierarchical contraints
6526a72c 136 Bool_t PseudoParentsAllowed() const {return fAllowPseudoParents;}
137 void ConstrainModuleSubUnitsMean(Int_t idm, Double_t val=0, UInt_t pattern=0xff);
138 void ConstrainModuleSubUnitsMedian(Int_t idm, Double_t val=0, UInt_t pattern=0xff);
139 void ConstrainOrphansMean(Double_t val=0, UInt_t pattern=0xff);
140 void ConstrainOrphansMedian(Double_t val=0, UInt_t pattern=0xff);
141 void ConstrainLocal(const Char_t* name,Double_t *parcf,Int_t npar,Double_t val,Double_t err);
7b85e477 142 //
6526a72c 143 void ApplyGaussianConstraint(AliITSAlignMille2ConstrArray* cstr);
144 void ApplyPreConstraints();
145 void ApplyPostConstraints();
7b85e477 146 //
6526a72c 147 Bool_t IsParModConstrained(AliITSAlignMille2Module* mod,Int_t par, Bool_t &meanmed, Bool_t &gaussian) const;
148 Bool_t IsParModFamilyVaried(AliITSAlignMille2Module* mod,Int_t par,Int_t depth=999) const;
149 Bool_t IsParFamilyFree(AliITSAlignMille2Module* mod,Int_t par,Int_t depth=999) const;
7b85e477 150 //
151 // millepede methods
6526a72c 152 Int_t GlobalFit();
7b85e477 153 void FixParameter(Int_t param, Double_t value);
7b85e477 154 void PrintGlobalParameters();
7b85e477 155 Int_t AddLocalEquation(Mille2Data &m);
156 void SetLocalEquations(const Mille2Data *marr, Int_t neq);
157 //
6526a72c 158 // module specific
7b85e477 159 //
6526a72c 160 Double_t GetTDriftSDD() const;
161 Double_t GetVDriftSDD() const;
162 //
163 AliITSAlignMille2Constraint* GetConstraint(Int_t i) const {return (AliITSAlignMille2Constraint*)fConstraints.At(i);}
164 AliITSAlignMille2Constraint* GetConstraint(const char* name) const {return (AliITSAlignMille2Constraint*)fConstraints.FindObject(name);}
7b85e477 165 //
166 // debug stuffs
6526a72c 167 void FetchCluster(const AliTrackPointArray *trc,int ip) {trc->GetPoint(fCluster,ip);}
168 void SetLocalInitParams(Double_t *par) {for (int i=kNLocal;i--;) fLocalInitParam[i]=par[i];}
7b85e477 169 Double_t *GetMeasLoc() const {return (Double_t*)fMeasLoc;}
170 Double_t *GetSigmaLoc() const {return (Double_t*)fSigmaLoc;}
171 Double_t GetBField() const {return fBField;}
172 Double_t *GetLocalInitParam() const {return (Double_t*)fLocalInitParam;}
173 Double_t *GetLocalInitParEr() const {return (Double_t*)fLocalInitParEr;}
6526a72c 174 Double_t GetLocalDif(int par, int coor) const {return fDerivativeLoc[par][coor];}
175 Double_t GetGlobalDif(int par, int coor) const {return fDerivativeGlo[par][coor];}
7b85e477 176 Int_t GetPreAlignmentQualityFactor(Int_t index) const;// if not prealign. return -1
177 void SetBug(Int_t bug) {fBug=bug;} // 1:SSD inversion sens.18-19
6526a72c 178 static AliITSAlignMille2* GetInstance() {return fgInstance;}
179
180 // pepo
181 // flag for AliITSAlignMille compatibility
182 Int_t GetMilleVersion() const {return fMilleVersion;}
183 void SetMilleVersion(Int_t m1) {fMilleVersion=m1;}
184 // modified existing methods
185 void SetCurrentModule(Int_t id);
186 // old methods recovered
187 Int_t IsDefined(UShort_t voluid) const {return IsVIDDefined(voluid);}
188 Int_t IsContained(UShort_t voluid) const {return IsVIDContained(voluid);}
189 // moved from private to public
190 void SetRequiredPoint(Char_t* where, Int_t ndet, Int_t updw, Int_t nreqpts);
191 Bool_t InitRiemanFit();
192 void SetMinNPtsPerTrack(Int_t pts=3) {fMinNPtsPerTrack=pts;}
7b85e477 193 //
194 private:
195 //
196 // configuration methods
6526a72c 197 void Init();
7b85e477 198 Int_t LoadConfig(const Char_t *cfile="AliITSAlignMille.conf");
6526a72c 199 TObjArray* GetConfigRecord(FILE* stream, TString& recTitle, TString& recOpt, Bool_t rew);
200 //
201 void BuildHierarchy();
7b85e477 202 Int_t LoadSuperModuleFile(const Char_t *cfile="ITSMilleSuperModules.root");
203 void ResetLocalEquation();
6526a72c 204 Int_t InitGeometry();
7b85e477 205 Int_t ApplyToGeometry();
206 //
6526a72c 207 void ConstrainModuleSubUnits(Int_t idm, Double_t val=0, UInt_t pattern=0xff);
208 void ConstrainOrphans(Double_t val=0,UInt_t pattern=0xff);
209 void PostConstrainModuleSubUnits(Int_t type,Int_t idm, Double_t val, UInt_t pattern);
210 void PostConstrainOrphans(Int_t type,Double_t val, UInt_t pattern);
211 //
212 void SetGeometryFileName(const Char_t* filename="geometry.root") { fGeometryFileName = filename; }
213
214 void SetInitTrackParamsMeth(Int_t meth=1) {fInitTrackParamsMeth=meth;}
215 //
216 void AddConstraint(Double_t *factor, Double_t value, Double_t sigma=0);
217 void InitGlobalParameters(Double_t *par);
218 void SetLocalDerivative(Int_t index, Double_t value) {fLocalDerivatives[index] = value;}
219 void SetGlobalDerivative(Int_t index, Double_t value) {fGlobalDerivatives[index] = value;}
220 //
7b85e477 221 // millepede methods
6526a72c 222 //
223 void SetUseGlobalDelta(Bool_t v=kTRUE) {fUseGlobalDelta = v;}
224 void SetAllowPseudoParents(Bool_t v=kTRUE) {fAllowPseudoParents = v;}
225 Int_t SetConstraintWrtRef(const char* reffname);
7b85e477 226 //
227 AliITSAlignMille2(const AliITSAlignMille2& rhs);
228 AliITSAlignMille2& operator=(const AliITSAlignMille2& rhs);
229 //
230 protected:
231 //
232 // millepede stuffs
233 AliMillePede2 *fMillepede; // Detector independent alignment class
234 Double_t fStartFac; // Initial value for chi2 cut
235 Double_t fResCutInitial; // Cut on residual for first iteration
236 Double_t fResCut; // Cut on residual for other iterations
237 Int_t fNGlobal; // Number of global parameters
238 Int_t fNLocal; // Number of local parameters
239 Int_t fNStdDev; // Number of standard deviations for chi2 cut
240 Bool_t fIsMilleInit; // Flag for initialization
6526a72c 241 Bool_t fAllowPseudoParents; // For simple constraints don't involve parents into the fit
7b85e477 242 //
243 // fitting stuffs
244 AliITSAlignMille2Module *fCurrentModule; // Current SuperModule index
245 AliTrackPointArray *fTrack; // pointer to current track
6526a72c 246 TObjArray fTrackBuff; // buffer for tracks of min length
7b85e477 247 AliTrackPoint fCluster; // current cluster
248 Double_t *fGlobalDerivatives; // Array of global derivatives
249 Double_t fLocalDerivatives[kNLocal]; // Array of local deriv.
250 Double_t fLocalInitParam[kNLocal]; // Array with inital values for local parameters for current track
251 Double_t fLocalInitParEr[kNLocal][kNLocal];// Array with inital values for local parameters for current track
252 Double_t fModuleInitParam[kNParCh]; // Array with inital values for current module parameters (init geometry)
253 Double_t fPintLoc[3];
254 Double_t fPintLoc0[3];
255 Double_t fPintGlo[3];
256 Double_t fMeasLoc[3]; // current point local coordinates (the original ones)
257 Double_t fMeasGlo[3]; // current point glob. coord (AliTrackPoint)
258 Double_t fSigmaLoc[3]; // stdev current point
259 Double_t fSigmaFactor[3]; // multiplicative factor for cluster sigmaX,Y,Z
260 //
6526a72c 261 Double_t fDerivativeLoc[kNLocal][3]; // XYZ deriv. over local params
262 Double_t fDerivativeGlo[kNParCh][3]; // XYZ deriv. over global params
7b85e477 263 Int_t fMinNPtsPerTrack; // min number of points per track to accept it
264 Int_t fInitTrackParamsMeth; // method for track fit
265 Int_t fTotBadLocEqPoints; // total number of reject points because of bad EqLoc
266 AliTrackFitterRieman *fRieman; // riemann fitter for helices
267 //
6526a72c 268 TObjArray fConstraints; // list of constraints
7b85e477 269 // >> new members
270 Bool_t fUseGlobalDelta; // intetpret deltas as global
271 Bool_t fRequirePoints; // required points in specific layers
272 Int_t fNReqLayUp[6]; /// number of points required in layer[n] with Y>0
273 Int_t fNReqLayDown[6]; /// number of points required in layer[n] with Y<0
274 Int_t fNReqLay[6]; /// number of points required in layer[n]
275 Int_t fNReqDetUp[3]; /// number of points required in Detector[n] with Y>0
276 Int_t fNReqDetDown[3]; /// number of points required in Detector[n] with Y<0
277 Int_t fNReqDet[3]; /// number of points required in Detector[n]
278 Int_t fTempExcludedModule; /// single module temporary excluded from initial fit
279 // << new members
280 //
281 // geometry stuffs
282 TString fGeometryFileName; // Geometry file name
283 TString fPreAlignmentFileName; // file with prealigned objects
6526a72c 284 TString fConstrRefFileName; // file with prealigned objects wrt which constraints are defined
7b85e477 285 TGeoManager *fGeoManager;
286 Bool_t fIsConfigured;
287 TArrayS fPreAlignQF;
288 //
6526a72c 289 AliITSresponseSDD* fCorrectSDD; // array of SDD t0/vdrift calib params
290 AliITSresponseSDD* fInitialRecSDD; // array of SDD t0/vdrift calib params used to create the track points
7b85e477 291 TClonesArray* fPrealignment; // array of prealignment global deltas
6526a72c 292 TClonesArray* fConstrRef; // array of refererence deltas with respect to which the constraint are defined (survey?)
7b85e477 293 TObjArray fMilleModule; /// array of super modules to be aligned
294 TObjArray fSuperModule; /// array of super modules defined in supermodule file
295 Int_t fNModules; // number of defined modules from config file
296 Int_t fNSuperModules; /// number of custom supermodules in SM file
297 Bool_t fUsePreAlignment; // start from prealigned setup
7b85e477 298 Bool_t fBOn; // magentic field ON
299 Double_t fBField; // value of magnetic field
300 Int_t fBug; /// tag for temporary bug correction
6526a72c 301 // pepo
302 Int_t fMilleVersion; /// tag for backward compatibility
303 // endpepo
304 //
305 Double_t fDriftSpeed[50]; //temporary array for drift times of SDD alitrackpoints
306 Double_t fDriftTime0[50]; //temporary array for drift time 0's used for SDD alitrackpoints
7b85e477 307 //
308 static AliITSAlignMille2* fgInstance; // global pointer on itself
309 static Int_t fgInstanceID; // global counter of the instances
6526a72c 310 //
7b85e477 311 ClassDef(AliITSAlignMille2, 0)
7b85e477 312};
313
314#endif