1 #ifndef ALIITSALIGNMILLE2_H
2 #define ALIITSALIGNMILLE2_H
4 /* Copyright(c) 2007-2009 , ALICE Experiment at CERN, All rights reserved. *
5 * See cxx source for full Copyright notice */
8 //-----------------------------------------------------------------------------
10 // Interface to AliMillePede2 alignment class for the ALICE ITS detector
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.
17 // author M. Lunardon (thanks to J. Castillo), ruben.shahoyan@cern.ch
18 //-----------------------------------------------------------------------------
22 #include <TGeoMatrix.h>
25 #include "AliTrackPointArray.h"
26 #include "AliITSAlignMille2Module.h"
32 class AliAlignObjParams;
33 class AliTrackFitterRieman;
34 class AliITSAlignMille2Constraint;
35 class AliITSAlignMille2ConstrArray;
36 class AliITSresponseSDD;
37 class AliITSTPArrayFit;
39 class AliITSAlignMille2: public TObject
43 enum {kNLocal=5,kMaxPoints=100,
44 kNParChGeom = AliITSAlignMille2Module::kMaxParGeom,
45 kNParCh = AliITSAlignMille2Module::kMaxParTot,
46 kMaxITSSensID=2197,kMaxITSSensVID=14300,kMinITSSupeModuleID=14336,
47 kSDDoffsID=240,kNSDDmod=260};
51 AliITSAlignMille2(const Char_t *configFilename="AliITSAlignMille.conf",TList* userInfo=0);
52 virtual ~AliITSAlignMille2();
54 AliMillePede2* GetMillePede() const {return fMillepede;}
55 AliITSTPArrayFit* GetTPAFitter() const {return fTPAFitter;}
57 // configuration methods
59 Int_t IsVIDDefined(UShort_t voluid) const;
60 Int_t IsVIDContained(UShort_t voluid) const;
61 Int_t IsSymDefined(const Char_t* name) const;
62 Int_t IsSymContained(const Char_t* name) const;
64 Int_t GetModuleIndex(const Char_t *symname);
65 Int_t GetModuleIndex(UShort_t voluid);
66 UShort_t GetModuleVolumeID(const Char_t *symname);
67 UShort_t GetModuleVolumeID(Int_t index);
68 AliITSAlignMille2Module* GetMilleModuleByVID(UShort_t voluid) const; // get pointer to the defined supermodule
69 AliITSAlignMille2Module* GetMilleModuleBySymName(const Char_t* symname) const; // get pointer to the defined supermodule
70 AliITSAlignMille2Module* GetMilleModuleIfContained(const Char_t* symname) const;
71 AliITSAlignMille2Module* GetMilleModule(Int_t id) const {return (AliITSAlignMille2Module*)fMilleModule[id];}
72 AliITSAlignMille2Module* GetCurrentModule() const {return fCurrentModule;}
73 AliITSAlignMille2Module* GetSuperModule(Int_t id) const {return (AliITSAlignMille2Module*)fSuperModule[id];}
75 AliAlignObjParams* GetPrealignedObject(const Char_t* symname) const;
76 AliAlignObjParams* GetConstrRefObject(const Char_t* symname) const;
78 void ConvertParamsToGlobal();
79 void ConvertParamsToLocal();
81 const Char_t* GetGeometryPath() {return fGeometryPath.Data();}
82 const Char_t* GetPreAlignmentPath() {return fPreDeltaPath.Data();}
83 TClonesArray* GetPreAlignmentDeltas() const {return fPrealignment;}
84 AliITSresponseSDD* GetSDDPrecalibration() const {return fCorrectSDD;}
85 AliITSresponseSDD* GetSDDInit() const {return fInitialRecSDD;}
86 void PrintCurrentModuleInfo() const {if (fCurrentModule) fCurrentModule->Print();}
87 void Print(Option_t*) const;
88 Bool_t IsConfigured() const {return fIsConfigured;}
89 Bool_t GetUseGlobalDelta() const {return fUseGlobalDelta;}
90 Bool_t IsConstraintWrtRef() const {return fConstrRef!=0;}
91 Bool_t FixedOrphans() const;
92 Bool_t IsLocalYError() const {return fUseLocalYErr;}
95 Int_t GetNModules() const {return fNModules;}
96 Int_t GetCurrentModuleIndex() const {return fCurrentModule ? fCurrentModule->GetIndex():-1;}
97 TGeoHMatrix *GetCurrentModuleHMatrix() const {return fCurrentModule ? fCurrentModule->GetMatrix():0;}
98 Double_t *GetCurrentModuleTranslation() const {return fCurrentModule ? fCurrentModule->GetMatrix()->GetTranslation():0;}
99 Int_t GetCurrentModuleInternalIndex() const {return fCurrentModule ? Int_t(fCurrentModule->GetUniqueID()):-1;}
100 Int_t GetTotBadLocEqPoints() const {return fTotBadLocEqPoints;}
101 Int_t GetNConstraints() const {return fConstraints.GetLast()+1;}
102 Int_t InitModuleParams();
105 AliTrackFitterRieman *GetRiemanFitter() const {return fRieman;}
106 AliTrackPointArray *PrepareTrack(const AliTrackPointArray *track);
107 AliTrackPointArray *GetCurrentTrack() const {return (AliTrackPointArray*)fTrack;}
108 AliTrackPoint *GetCurrentCluster() const {return (AliTrackPoint*)&fCluster;}
109 void SetCurrentTrack(const AliTrackPointArray *atp) {fTrack = (AliTrackPointArray*)atp;}
110 void SetCurrentCluster(const AliTrackPoint &atp);
111 void InitTrackParams(int meth=1);
112 Int_t ProcessTrack(const AliTrackPointArray *track);
113 Int_t CheckCurrentTrack();
115 Int_t CalcIntersectionPoint(Double_t *lpar, Double_t *gpar);
116 Int_t CalcDerivatives(Int_t paridx, Bool_t islpar);
117 Double_t* GetLocalIntersectionPoint() const {return (Double_t*)fPintLoc;}
118 Double_t* GetGlobalIntersectionPoint() const {return (Double_t*)fPintGlo;}
119 AliTrackPointArray *SortTrack(const AliTrackPointArray *atp);
120 void SetTemporaryExcludedModule(Int_t index) {fTempExcludedModule=index;}
121 Int_t GetTemporaryExcludedModule() const {return fTempExcludedModule;}
122 Double_t GetMeasGlo(Int_t dim) const {return fMeasGlo[dim];}
123 Double_t GetMeasLoc(Int_t dim) const {return fMeasLoc[dim];}
124 Int_t GetCurrentLayer() const;
125 void SetBField(Double_t b=0);
126 void SetUseLocalYErrors(Bool_t v=kTRUE) {fUseLocalYErr = v && fTPAFitter;}
127 void SetMinPointsPerSensor( Int_t n ) {fMinPntPerSens = n>0 ? n:0;}
128 Int_t GetMinPointsPerSensor() const {return fMinPntPerSens;}
129 void ConstrainHelixFitPT( Int_t q=0,Double_t pt=-1, Double_t err=-1);
130 void ConstrainHelixFitCurv(Int_t q=0,Double_t crv=-1,Double_t crverr=-1);
131 Double_t GetHelixContraintCharge() const {return fConstrCharge;}
132 Double_t GetHelixContraintPT() const {return fConstrPT;}
133 Double_t GetHelixContraintPTErr() const {return fConstrPTErr;}
135 TGeoHMatrix* GetSensorOrigMatrixSID(Int_t sid) const;
136 TGeoHMatrix* GetSensorOrigMatrixVID(Int_t vid) const;
138 TGeoHMatrix* GetSensorCurrMatrixSID(Int_t sid) const;
139 TGeoHMatrix* GetSensorCurrMatrixVID(Int_t vid) const;
141 // Hierarchical contraints
142 Bool_t PseudoParentsAllowed() const {return fAllowPseudoParents;}
143 void ConstrainModuleSubUnitsMean(Int_t idm, Double_t val=0, UInt_t pattern=0xff);
144 void ConstrainModuleSubUnitsMedian(Int_t idm, Double_t val=0, UInt_t pattern=0xff);
145 void ConstrainOrphansMean(Double_t val=0, UInt_t pattern=0xff);
146 void ConstrainOrphansMedian(Double_t val=0, UInt_t pattern=0xff);
147 void ConstrainLocal(const Char_t* name,Double_t *parcf,Int_t npar,Double_t val,Double_t err);
149 void ApplyGaussianConstraint(const AliITSAlignMille2ConstrArray* cstr);
150 void ApplyPreConstraints();
151 void ApplyPostConstraints();
153 Bool_t IsParModConstrained(const AliITSAlignMille2Module* mod,Int_t par, Bool_t &meanmed, Bool_t &gaussian) const;
154 Bool_t IsParModFamilyVaried(const AliITSAlignMille2Module* mod,Int_t par,Int_t depth=999) const;
155 Bool_t IsParFamilyFree(const AliITSAlignMille2Module* mod,Int_t par,Int_t depth=999) const;
159 void FixParameter(Int_t param, Double_t value);
160 void PrintGlobalParameters();
162 TClonesArray* CreateDeltas();
163 AliITSresponseSDD* CreateSDDResponse();
166 Double_t GetTDriftSDD() const;
167 Double_t GetVDriftSDD() const;
169 AliITSAlignMille2Constraint* GetConstraint(Int_t i) const {return (AliITSAlignMille2Constraint*)fConstraints.At(i);}
170 AliITSAlignMille2Constraint* GetConstraint(const char* name) const {return (AliITSAlignMille2Constraint*)fConstraints.FindObject(name);}
173 void FetchCluster(int ip) {fTrack->GetPoint(fCluster,ip);fCluster.SetUniqueID(ip);}
174 void SetLocalInitParams(const Double_t *par) {for (int i=kNLocal;i--;) fLocalInitParam[i]=par[i];}
175 Double_t *GetMeasLoc() const {return (Double_t*)fMeasLoc;}
176 Double_t *GetSigmaLoc() const {return (Double_t*)fSigmaLoc;}
177 Double_t GetBField() const {return fBField;}
178 Double_t *GetLocalInitParam() const {return (Double_t*)fLocalInitParam;}
179 Double_t *GetLocalInitParEr() const {return (Double_t*)fLocalInitParEr;}
180 Double_t GetLocalDif(int par, int coor) const {return fDerivativeLoc[par][coor];}
181 Double_t GetGlobalDif(int par, int coor) const {return fDerivativeGlo[par][coor];}
182 Int_t GetPreAlignmentQualityFactor(Int_t index) const;// if not prealign. return -1
183 void SetBug(Int_t bug) {fBug=bug;} // 1:SSD inversion sens.18-19
184 static AliITSAlignMille2* GetInstance() {return fgInstance;}
187 Int_t GetExtraClustersMode() const {return fExtraClustersMode;}
188 void SetExtraClustersMode(Int_t mode) {fExtraClustersMode=mode;}
192 // flag for AliITSAlignMille compatibility
193 Int_t GetMilleVersion() const {return fMilleVersion;}
194 void SetMilleVersion(Int_t m1) {fMilleVersion=m1;}
195 // modified existing methods
196 void SetCurrentModule(Int_t id);
197 // old methods recovered
198 Int_t IsDefined(UShort_t voluid) const {return IsVIDDefined(voluid);}
199 Int_t IsContained(UShort_t voluid) const {return IsVIDContained(voluid);}
200 // moved from private to public
201 void SetRequiredPoint(Char_t* where, Int_t ndet, Int_t updw, Int_t nreqpts);
202 Bool_t InitRiemanFit();
203 void SetMinNPtsPerTrack(Int_t pts=3) {fMinNPtsPerTrack=pts;}
205 static Bool_t IsZero(Double_t v,Double_t threshold = 1e-16) { return TMath::Abs(v)<threshold; }
206 static void SetWordBit(UInt_t word,Int_t bitID) { word |= (1<<bitID);}
207 static void ResetWordBit(UInt_t word,Int_t bitID) { word &= ~(1<<bitID);}
208 static Bool_t TestWordBit(UInt_t word,Int_t bitID) { return (Bool_t)(word&(1<<bitID));}
212 struct Mille2Data { // structure to store data for 2 LocalEquations (X and Z)
214 Double_t fMeas[3]; // measured coordinates
215 Double_t fSigma[3]; // measured errors
216 Double_t fDerLoc[kNLocal][3]; // calculated local derivatives
217 Int_t fNModFilled, fNGlobFilled, fModuleID[kMaxLev]; // used module info
218 Int_t fParMilleID[AliITSAlignMille2Module::kMaxParTot*kMaxLev]; // param id's
219 Double_t fDerGlo[AliITSAlignMille2Module::kMaxParTot*kMaxLev][3]; // global derivatives
222 // configuration methods
224 Int_t CacheMatricesOrig();
225 Int_t CacheMatricesCurr();
226 Int_t ProcessUserInfo(TList *userInfo=0);
227 Int_t LoadConfig(const Char_t *cfile="AliITSAlignMille.conf");
228 TObjArray* GetConfigRecord(FILE* stream, TString& recTitle, TString& recOpt, Bool_t rew);
229 Int_t CheckConfigRecords(FILE* stream);
231 void BuildHierarchy();
232 Int_t LoadSuperModuleFile(const Char_t *cfile="ITSMilleSuperModules.root");
233 Int_t LoadSDDResponse(TString& path, AliITSresponseSDD *&resp);
234 Int_t LoadDeltas(TString& path, TClonesArray *&arr);
235 void ResetLocalEquation();
236 Int_t InitGeometry();
237 Int_t ApplyToGeometry();
239 void ConstrainModuleSubUnits(Int_t idm, Double_t val=0, UInt_t pattern=0xff);
240 void ConstrainOrphans(Double_t val=0,UInt_t pattern=0xff);
241 void PostConstrainModuleSubUnits(Int_t type,Int_t idm, Double_t val, UInt_t pattern);
242 void PostConstrainOrphans(Int_t type,Double_t val, UInt_t pattern);
244 void SetGeometryPath(const Char_t* filename="geometry.root") { fGeometryPath = filename; }
246 void SetInitTrackParamsMeth(Int_t meth=1) {fInitTrackParamsMeth=meth;}
248 void AddConstraint(Double_t *factor, Double_t value, Double_t sigma=0);
249 void InitGlobalParameters(Double_t *par);
250 Bool_t SetLocalDerivative(Int_t index, Double_t value) {return IsZero(fLocalDerivatives[index]=value);}
251 Bool_t SetGlobalDerivative(Int_t index, Double_t value) {return IsZero(fGlobalDerivatives[index]=value);}
255 Int_t AddLocalEquation(Mille2Data &m);
256 Int_t AddLocalEquationTPA(Mille2Data &m);
257 void SetLocalEquations(const Mille2Data *marr, Int_t neq);
258 void SetUseGlobalDelta(Bool_t v=kTRUE) {fUseGlobalDelta = v;}
259 void SetAllowPseudoParents(Bool_t v=kTRUE) {fAllowPseudoParents = v;}
260 Int_t SetConstraintWrtRef(const char* reffname);
262 AliITSAlignMille2(const AliITSAlignMille2& rhs);
263 AliITSAlignMille2& operator=(const AliITSAlignMille2& rhs);
300 }; // id's of the keywirds for config file records
303 AliMillePede2 *fMillepede; // Detector independent alignment class
304 Double_t fStartFac; // Initial value for chi2 cut
305 Double_t fResCutInitial; // Cut on residual for first iteration
306 Double_t fResCut; // Cut on residual for other iterations
307 Int_t fNGlobal; // Number of global parameters
308 Int_t fNLocal; // Number of local parameters
309 Int_t fNStdDev; // Number of standard deviations for chi2 cut
310 Bool_t fIsMilleInit; // Flag for initialization
311 Bool_t fAllowPseudoParents; // For simple constraints don't involve parents into the fit
314 AliITSTPArrayFit *fTPAFitter; // TPArrayFitter
315 AliITSAlignMille2Module *fCurrentModule; // Current SuperModule index
316 AliTrackPointArray *fTrack; // pointer to current track
317 TObjArray fTrackBuff; // buffer for tracks of min length
318 AliTrackPoint fCluster; // current cluster
319 Int_t fCurrentSensID; // sensor index for current cluster
320 TArrayD fClusLoc; // local coordinates of the clusters
321 TArrayD fClusGlo; // global coordinates of the clusters
322 TArrayD fClusSigLoc; // local cov matrix of the clusters
323 Double_t *fGlobalDerivatives; // Array of global derivatives
324 Double_t fLocalDerivatives[kNLocal]; // Array of local deriv.
325 Double_t fLocalInitParam[kNLocal]; // Array with inital values for local parameters for current track
326 Double_t fLocalInitParEr[kNLocal][kNLocal];// Array with inital values for local parameters for current track
327 Double_t fModuleInitParam[kNParCh]; // Array with inital values for current module parameters (init geometry)
328 Double_t fPintLoc[3]; // track/module intersection point in local coordinates
329 Double_t fPintLoc0[3]; // track/module intersection point in local coordinates (before variation)
330 Double_t fPintGlo[3]; // track/module intersection point in global coordinates
331 Double_t *fMeasLoc; // current point local coordinates (the original ones)
332 Double_t *fMeasGlo; // current point glob. coord (AliTrackPoint)
333 Double_t *fSigmaLoc; // stdev current point
334 Double_t fSigmaFactor[3]; // multiplicative factor for cluster sigmaX,Y,Z
335 Double_t fConstrPT; // optional PT constraint for helix (abs value)
336 Double_t fConstrPTErr; // error on this constraint (0 - exact)
337 Int_t fConstrCharge; // optional constraint on charge of Helix track (0 - no constraint)
339 Double_t fDerivativeLoc[kNLocal][3]; // XYZ deriv. over local params
340 Double_t fDerivativeGlo[kNParCh][3]; // XYZ deriv. over global params
341 Int_t fMinNPtsPerTrack; // min number of points per track to accept it
342 Int_t fInitTrackParamsMeth; // method for track fit
343 Int_t fTotBadLocEqPoints; // total number of reject points because of bad EqLoc
344 AliTrackFitterRieman *fRieman; // riemann fitter for helices
346 TObjArray fConstraints; // list of constraints
347 TObjArray fCacheMatrixOrig; // cach for original geom matrices
348 TObjArray fCacheMatrixCurr; // cach for prealigned geom matrices
350 Bool_t fUseGlobalDelta; // intetpret deltas as global
351 Bool_t fRequirePoints; // required points in specific layers
352 Int_t fNReqLayUp[6]; /// number of points required in layer[n] with Y>0
353 Int_t fNReqLayDown[6]; /// number of points required in layer[n] with Y<0
354 Int_t fNReqLay[6]; /// number of points required in layer[n]
355 Int_t fNReqDetUp[3]; /// number of points required in Detector[n] with Y>0
356 Int_t fNReqDetDown[3]; /// number of points required in Detector[n] with Y<0
357 Int_t fNReqDet[3]; /// number of points required in Detector[n]
358 Int_t fTempExcludedModule; /// single module temporary excluded from initial fit
362 TString fDefCDBpath; // default OCDB path
363 TString fInitDeltaPath; // where to take the deltas used to produce the points
364 TString fInitSDDRespPath; // where to take the initial SDD response used to produce the points
365 TString fPreCalSDDRespPath; // precalibration SDD response file name
367 TString fGeometryPath; // Geometry file name
368 TString fPreDeltaPath; // file with prealigned objects
369 TString fConstrRefPath; // file with prealigned objects wrt which constraints are defined
370 TGeoManager *fGeoManager; // pointer to Alice geomanager
371 Bool_t fIsConfigured; // flag for loaded config file
372 TArrayS fPreAlignQF; // prealignment flags (not used?)
374 AliITSresponseSDD* fCorrectSDD; // array of SDD t0/vdrift calib params
375 AliITSresponseSDD* fInitialRecSDD; // array of SDD t0/vdrift calib params used to create the track points
376 TClonesArray* fPrealignment; // array of prealignment global deltas
377 TClonesArray* fConstrRef; // array of refererence deltas with respect to which the constraint are defined (survey?)
378 TObjArray fMilleModule; /// array of super modules to be aligned
379 TObjArray fSuperModule; /// array of super modules defined in supermodule file
380 Int_t fNModules; // number of defined modules from config file
381 Int_t fNSuperModules; /// number of custom supermodules in SM file
382 Bool_t fUsePreAlignment; // start from prealigned setup
383 Bool_t fUseLocalYErr; // use local Yerror due to the sensor thickness
384 Bool_t fBOn; // magentic field ON
385 Double_t fBField; // value of magnetic field
386 Int_t fMinPntPerSens; // min number of points per module to vary it
387 Int_t fBug; /// tag for temporary bug correction
389 Int_t fMilleVersion; /// tag for backward compatibility
392 Int_t fExtraClustersMode; /// 1=remove random / 2=remove internal / 10=use only tracks with xcl
395 Double_t fDriftSpeed[50]; //temporary array for drift times of SDD alitrackpoints
396 Double_t fDriftTime0[50]; //temporary array for drift time 0's used for SDD alitrackpoints
397 Double_t fExtClusterPar[9]; //array to store the parameters of the externally imposed cluster
399 static AliITSAlignMille2* fgInstance; // global pointer on itself
400 static Int_t fgInstanceID; // global counter of the instances
401 static const Char_t * fgkRecKeys[]; // keywords for config file records
402 static const Char_t fgkXYZ[]; // XYZ labels
404 ClassDef(AliITSAlignMille2, 0)
408 //______________________________________________________________________________________
409 inline void AliITSAlignMille2::SetCurrentCluster(const AliTrackPoint &atp)
411 // set current cluster
413 fCurrentSensID = AliITSAlignMille2Module::GetIndexFromVolumeID(fCluster.GetVolumeID());
416 //______________________________________________________________________________________
417 inline TGeoHMatrix* AliITSAlignMille2::GetSensorOrigMatrixSID(Int_t sid) const
419 // get cached original matrix by sensor ID
420 return sid<0 ? 0 : (TGeoHMatrix*) fCacheMatrixOrig[sid];
423 //______________________________________________________________________________________
424 inline TGeoHMatrix* AliITSAlignMille2::GetSensorOrigMatrixVID(Int_t vid) const
426 // get cached original matrix by sensor volume ID
427 return GetSensorOrigMatrixSID( AliITSAlignMille2Module::GetIndexFromVolumeID(vid) );
430 //______________________________________________________________________________________
431 inline TGeoHMatrix* AliITSAlignMille2::GetSensorCurrMatrixSID(Int_t sid) const
433 // get cached current matrix by sensor ID
434 return sid<0 ? 0 : (TGeoHMatrix*) fCacheMatrixCurr[sid];
437 //______________________________________________________________________________________
438 inline TGeoHMatrix* AliITSAlignMille2::GetSensorCurrMatrixVID(Int_t vid) const
440 // get cached current matrix by sensor volume ID
441 return GetSensorCurrMatrixSID( AliITSAlignMille2Module::GetIndexFromVolumeID(vid) );