Fixing one more REVERSE_INULL defect reported by Coverity
[u/mrichter/AliRoot.git] / MUON / AliMUONAlignment.cxx
CommitLineData
010eb601 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
16/* $Id$ */
17
18//-----------------------------------------------------------------------------
c25af45b 19/// \class AliMUONAlignment
20/// Alignment class for the ALICE DiMuon spectrometer
010eb601 21///
22/// MUON specific alignment class which interface to AliMillepede.
23/// For each track ProcessTrack calculates the local and global derivatives
96ebe67e 24/// at each cluster and fill the corresponding local equations. Provide methods
25/// for fixing or constraining detection elements for best results.
010eb601 26///
27/// \author Bruce Becker, Javier Castillo
28//-----------------------------------------------------------------------------
29
30#include "AliMUONAlignment.h"
31#include "AliMUONTrack.h"
010eb601 32#include "AliMUONTrackParam.h"
96ebe67e 33#include "AliMUONVCluster.h"
010eb601 34#include "AliMUONGeometryTransformer.h"
35#include "AliMUONGeometryModuleTransformer.h"
36#include "AliMUONGeometryDetElement.h"
010eb601 37#include "AliMUONGeometryBuilder.h"
010eb601 38#include "AliMillepede.h"
39
8c95578a 40#include "AliMpExMap.h"
630711ed 41#include "AliMpExMapIterator.h"
8c95578a 42
4818a9b7 43#include "AliAlignObjMatrix.h"
8c95578a 44#include "AliLog.h"
45
2060b217 46#include "TMath.h"
4818a9b7 47#include "TMatrixDSym.h"
8c95578a 48
78649106 49/// \cond CLASSIMP
010eb601 50ClassImp(AliMUONAlignment)
78649106 51/// \endcond
52
010eb601 53 Int_t AliMUONAlignment::fgNDetElem = 4*2+4*2+18*2+26*2+26*2;
54 Int_t AliMUONAlignment::fgNDetElemCh[10] = {4,4,4,4,18,18,26,26,26,26};
55 Int_t AliMUONAlignment::fgSNDetElemCh[10] = {4,8,12,16,34,52,78,104,130,156};
723b0b5b 56 Int_t AliMUONAlignment::fgNParCh = 4;
3b2890be 57 Int_t AliMUONAlignment::fgNTrkMod = 16;
010eb601 58 Int_t AliMUONAlignment::fgNCh = 10;
59 Int_t AliMUONAlignment::fgNSt = 5;
60
8395bff1 61AliMUONAlignment::AliMUONAlignment()
62 : TObject(),
63 fBFieldOn(kTRUE),
723b0b5b 64 fStartFac(256.),
8395bff1 65 fResCutInitial(100.),
66 fResCut(100.),
67 fMillepede(0),
96ebe67e 68 fTrackParamAtCluster(0),
8395bff1 69 fTrack(0),
96ebe67e 70 fCluster(0),
8395bff1 71 fTrackParam(0),
72 fNGlobal(fgNDetElem*fgNParCh),
73 fNLocal(4),
74 fNStdDev(3),
75 fDetElemId(0),
76 fDetElemNumber(0),
77 fPhi(0.),
78 fCosPhi(1.),
79 fSinPhi(0.),
80 fTransform(0)
010eb601 81{
82 /// Default constructor, setting define alignment parameters
83 fSigma[0] = 1.0e-1;
84 fSigma[1] = 1.0e-2;
010eb601 85
64e2c144 86 AliInfo(Form("fSigma[0]: %f\t fSigma[1]: %f",fSigma[0],fSigma[1]));
87
723b0b5b 88 fDoF[0] = kTRUE; fDoF[1] = kTRUE; fDoF[2] = kTRUE; fDoF[3] = kTRUE;
89 fAllowVar[0] = 0.05; fAllowVar[1] = 0.05; fAllowVar[2] = 0.001; fAllowVar[3] = 0.5;
8395bff1 90
010eb601 91 AliInfo(Form("fAllowVar[0]: %f\t fAllowVar[1]: %f\t fPhi: %f\t fgNDetElem: %i\t fNGlobal: %i\t fNLocal: %i",fAllowVar[0],fAllowVar[1],fPhi,fgNDetElem,fNGlobal,fNLocal));
92
93 fMillepede = new AliMillepede();
94
95 Init(fNGlobal, fNLocal, fNStdDev);
96
97 ResetLocalEquation();
98 AliInfo("Parameters initialized to zero");
99
100}
101
102AliMUONAlignment::~AliMUONAlignment() {
103 /// Destructor
104}
105
106void AliMUONAlignment::Init(Int_t nGlobal, /* number of global paramers */
107 Int_t nLocal, /* number of local parameters */
108 Int_t nStdDev /* std dev cut */ )
109{
110 /// Initialization of AliMillepede. Fix parameters, define constraints ...
111 fMillepede->InitMille(nGlobal,nLocal,nStdDev,fResCut,fResCutInitial);
112
d8ad38e5 113// Bool_t bStOnOff[5] = {kTRUE,kTRUE,kTRUE,kTRUE,kTRUE};
114// Bool_t bChOnOff[10] = {kTRUE,kTRUE,kTRUE,kTRUE,kTRUE,kTRUE,kTRUE,kTRUE,kTRUE,kTRUE};
115// Bool_t bSpecLROnOff[2] = {kTRUE,kTRUE};
010eb601 116
d8ad38e5 117// AllowVariations(bChOnOff);
010eb601 118
119 // Fix parameters or add constraints here
d8ad38e5 120// for (Int_t iSt=0; iSt<5; iSt++)
121// if (!bStOnOff[iSt]) FixStation(iSt+1);
122// for (Int_t iCh=0; iCh<10; iCh++)
123// if (!bChOnOff[iCh]) FixChamber(iCh+1);
010eb601 124
d8ad38e5 125// FixHalfSpectrometer(bChOnOff,bSpecLROnOff);
3b2890be 126
010eb601 127 ResetConstraints();
3b2890be 128
129 // Define global constrains to be applied
130 // X, Y, P, XvsZ, YvsZ, PvsZ, XvsY, YvsY, PvsY
131 Bool_t bVarXYT[9] = {kTRUE,kTRUE,kTRUE,kTRUE,kTRUE,kTRUE,kTRUE,kTRUE,kTRUE};
132 Bool_t bDetTLBR[4] = {kFALSE,kTRUE,kFALSE,kTRUE};
133 // AddConstraints(bStOnOff,bVarXYT,bDetTLBR,bSpecLROnOff);
134
135 // Other possible way to add constrains
010eb601 136 bVarXYT[0] = kFALSE; bVarXYT[1] = kFALSE; bVarXYT[2] = kTRUE;
137 bDetTLBR[0] = kFALSE; bDetTLBR[1] = kTRUE; bDetTLBR[2] = kFALSE; bDetTLBR[3] = kFALSE;
3b2890be 138// AddConstraints(bStOnOff,bVarXYT,bDetTLBR);
139
140 bVarXYT[0] = kTRUE; bVarXYT[1] = kTRUE; bVarXYT[2] = kFALSE;
141 // AddConstraints(bStOnOff,bVarXYT);
010eb601 142
143 // Set iterations
144 if (fStartFac>1) fMillepede->SetIterations(fStartFac);
145}
146
147void AliMUONAlignment::FixStation(Int_t iSt){
148 /// Fix all detection elements of station iSt
149 Int_t iDetElemFirst = (iSt>1) ? fgSNDetElemCh[2*(iSt-1)-1] : 0;
150 Int_t iDetElemLast = fgSNDetElemCh[2*(iSt)-1];
151 for (Int_t i = iDetElemFirst; i < iDetElemLast; i++){
152 FixParameter(i*fgNParCh+0, 0.0);
153 FixParameter(i*fgNParCh+1, 0.0);
154 FixParameter(i*fgNParCh+2, 0.0);
723b0b5b 155 FixParameter(i*fgNParCh+3, 0.0);
010eb601 156 }
157}
158
d8ad38e5 159void AliMUONAlignment::FixChamber(Int_t iCh){
160 /// Fix all detection elements of chamber iCh
161 Int_t iDetElemFirst = (iCh>1) ? fgSNDetElemCh[iCh-2] : 0;
162 Int_t iDetElemLast = fgSNDetElemCh[iCh-1];
163 for (Int_t i = iDetElemFirst; i < iDetElemLast; i++){
164 FixParameter(i*fgNParCh+0, 0.0);
165 FixParameter(i*fgNParCh+1, 0.0);
166 FixParameter(i*fgNParCh+2, 0.0);
723b0b5b 167 FixParameter(i*fgNParCh+3, 0.0);
168 }
169}
170
171void AliMUONAlignment::FixDetElem(Int_t iDetElemId, TString sVarXYT){
172 /// Fix a given detection element
173 Int_t iDetElemNumber = iDetElemId%100;
174 for (int iCh=0; iCh<iDetElemId/100-1; iCh++){
175 iDetElemNumber += fgNDetElemCh[iCh];
176 }
177 if (sVarXYT.Contains("X")) { // X constraint
178 FixParameter(iDetElemNumber*fgNParCh+0, 0.0);
179 }
180 if (sVarXYT.Contains("Y")) { // Y constraint
181 FixParameter(iDetElemNumber*fgNParCh+1, 0.0);
182 }
183 if (sVarXYT.Contains("T")) { // T constraint
184 FixParameter(iDetElemNumber*fgNParCh+2, 0.0);
185 }
186 if (sVarXYT.Contains("Z")) { // T constraint
187 FixParameter(iDetElemNumber*fgNParCh+3, 0.0);
d8ad38e5 188 }
189}
190
a6ec842d 191void AliMUONAlignment::FixHalfSpectrometer(const Bool_t *lChOnOff, const Bool_t *lSpecLROnOff){
3b2890be 192 /// Fix left or right detector
193 for (Int_t i = 0; i < fgNDetElem; i++){
194 Int_t iCh=0;
195 for (iCh=1; iCh<=fgNCh; iCh++){
196 if (i<fgSNDetElemCh[iCh-1]) break;
197 }
d8ad38e5 198 if (lChOnOff[iCh-1]){
3b2890be 199 Int_t lDetElemNumber = (iCh==1) ? i : i-fgSNDetElemCh[iCh-2];
200 if (iCh>=1 && iCh<=4){
201 if ((lDetElemNumber==1 || lDetElemNumber==2) && !lSpecLROnOff[0]){ // From track crossings
202 FixParameter(i*fgNParCh+0, 0.0);
203 FixParameter(i*fgNParCh+1, 0.0);
204 FixParameter(i*fgNParCh+2, 0.0);
723b0b5b 205 FixParameter(i*fgNParCh+3, 0.0);
3b2890be 206 }
207 if ((lDetElemNumber==0 || lDetElemNumber==3) && !lSpecLROnOff[1]){ // From track crossings
208 FixParameter(i*fgNParCh+0, 0.0);
209 FixParameter(i*fgNParCh+1, 0.0);
210 FixParameter(i*fgNParCh+2, 0.0);
723b0b5b 211 FixParameter(i*fgNParCh+3, 0.0);
3b2890be 212 }
213 }
214 if (iCh>=5 && iCh<=6){
215 if ((lDetElemNumber>=5&&lDetElemNumber<=13) && !lSpecLROnOff[0]){
216 FixParameter(i*fgNParCh+0, 0.0);
217 FixParameter(i*fgNParCh+1, 0.0);
218 FixParameter(i*fgNParCh+2, 0.0);
723b0b5b 219 FixParameter(i*fgNParCh+3, 0.0);
3b2890be 220 }
221 if (((lDetElemNumber>=0&&lDetElemNumber<=4) ||
222 (lDetElemNumber>=14&&lDetElemNumber<=17)) && !lSpecLROnOff[1]){
223 FixParameter(i*fgNParCh+0, 0.0);
224 FixParameter(i*fgNParCh+1, 0.0);
225 FixParameter(i*fgNParCh+2, 0.0);
723b0b5b 226 FixParameter(i*fgNParCh+3, 0.0);
3b2890be 227 }
228 }
229 if (iCh>=7 && iCh<=10){
230 if ((lDetElemNumber>=7&&lDetElemNumber<=19) && !lSpecLROnOff[0]){
231 FixParameter(i*fgNParCh+0, 0.0);
232 FixParameter(i*fgNParCh+1, 0.0);
233 FixParameter(i*fgNParCh+2, 0.0);
723b0b5b 234 FixParameter(i*fgNParCh+3, 0.0);
3b2890be 235 }
236 if (((lDetElemNumber>=0&&lDetElemNumber<=6) ||
237 (lDetElemNumber>=20&&lDetElemNumber<=25)) && !lSpecLROnOff[1]){
238 FixParameter(i*fgNParCh+0, 0.0);
239 FixParameter(i*fgNParCh+1, 0.0);
240 FixParameter(i*fgNParCh+2, 0.0);
723b0b5b 241 FixParameter(i*fgNParCh+3, 0.0);
3b2890be 242 }
243 }
244 }
245 }
246}
247
a6ec842d 248void AliMUONAlignment::SetNonLinear(const Bool_t *lChOnOff, const Bool_t *lVarXYT){
d8ad38e5 249 /// Set non linear parameter flag selected chambers and degrees of freedom
010eb601 250 for (Int_t i = 0; i < fgNDetElem; i++){
251 Int_t iCh=0;
252 for (iCh=1; iCh<=fgNCh; iCh++){
253 if (i<fgSNDetElemCh[iCh-1]) break;
254 }
d8ad38e5 255 if (lChOnOff[iCh-1]){
010eb601 256 if (lVarXYT[0]) { // X constraint
257 SetNonLinear(i*fgNParCh+0);
258 }
259 if (lVarXYT[1]) { // Y constraint
260 SetNonLinear(i*fgNParCh+1);
261 }
262 if (lVarXYT[2]) { // T constraint
263 SetNonLinear(i*fgNParCh+2);
264 }
723b0b5b 265 if (lVarXYT[3]) { // Z constraint
266 SetNonLinear(i*fgNParCh+3);
267 }
010eb601 268 }
269 }
270}
271
a6ec842d 272void AliMUONAlignment::AddConstraints(const Bool_t *lChOnOff, const Bool_t *lVarXYT){
d8ad38e5 273 /// Add constraint equations for selected chambers and degrees of freedom
010eb601 274 for (Int_t i = 0; i < fgNDetElem; i++){
275 Int_t iCh=0;
276 for (iCh=1; iCh<=fgNCh; iCh++){
277 if (i<fgSNDetElemCh[iCh-1]) break;
278 }
d8ad38e5 279 if (lChOnOff[iCh-1]){
010eb601 280 if (lVarXYT[0]) { // X constraint
281 fConstraintX[i*fgNParCh+0]=1.0;
282 }
283 if (lVarXYT[1]) { // Y constraint
284 fConstraintY[i*fgNParCh+1]=1.0;
285 }
286 if (lVarXYT[2]) { // T constraint
287 fConstraintP[i*fgNParCh+2]=1.0;
288 }
723b0b5b 289// if (lVarXYT[3]) { // Z constraint
290// fConstraintP[i*fgNParCh+3]=1.0;
291// }
010eb601 292 }
293 }
294 if (lVarXYT[0]) { // X constraint
295 AddConstraint(fConstraintX,0.0);
296 }
297 if (lVarXYT[1]) { // Y constraint
298 AddConstraint(fConstraintY,0.0);
299 }
300 if (lVarXYT[2]) { // T constraint
301 AddConstraint(fConstraintP,0.0);
302 }
723b0b5b 303// if (lVarXYT[3]) { // Z constraint
304// AddConstraint(fConstraintP,0.0);
305// }
010eb601 306}
307
a6ec842d 308void AliMUONAlignment::AddConstraints(const Bool_t *lChOnOff, const Bool_t *lVarXYT, const Bool_t *lDetTLBR, const Bool_t *lSpecLROnOff){
d8ad38e5 309 /// Add constraint equations for selected chambers, degrees of freedom and detector half
3b2890be 310 Double_t lDetElemLocX = 0.;
311 Double_t lDetElemLocY = 0.;
312 Double_t lDetElemLocZ = 0.;
313 Double_t lDetElemGloX = 0.;
314 Double_t lDetElemGloY = 0.;
315 Double_t lDetElemGloZ = 0.;
316 Double_t lMeanY = 0.;
317 Double_t lSigmaY = 0.;
318 Double_t lMeanZ = 0.;
319 Double_t lSigmaZ = 0.;
320 Int_t lNDetElem = 0;
010eb601 321 for (Int_t i = 0; i < fgNDetElem; i++){
322 Int_t iCh=0;
323 for (iCh=1; iCh<=fgNCh; iCh++){
324 if (i<fgSNDetElemCh[iCh-1]) break;
325 }
d8ad38e5 326 if (lChOnOff[iCh-1]){
3b2890be 327 Int_t lDetElemNumber = (iCh==1) ? i : i-fgSNDetElemCh[iCh-2];
328 Int_t lDetElemId = iCh*100+lDetElemNumber;
329 fTransform->Local2Global(lDetElemId,lDetElemLocX,lDetElemLocY,lDetElemLocZ,
330 lDetElemGloX,lDetElemGloY,lDetElemGloZ);
331 if (iCh>=1 && iCh<=4){
332 if ((lDetElemNumber==1 || lDetElemNumber==2) && lSpecLROnOff[0]){ // From track crossings
333 lMeanY += lDetElemGloY;
334 lSigmaY += lDetElemGloY*lDetElemGloY;
335 lMeanZ += lDetElemGloZ;
336 lSigmaZ += lDetElemGloZ*lDetElemGloZ;
337 lNDetElem++;
338 }
339 if ((lDetElemNumber==0 || lDetElemNumber==3) && lSpecLROnOff[1]){ // From track crossings
340 lMeanY += lDetElemGloY;
341 lSigmaY += lDetElemGloY*lDetElemGloY;
342 lMeanZ += lDetElemGloZ;
343 lSigmaZ += lDetElemGloZ*lDetElemGloZ;
344 lNDetElem++;
345 }
346 }
347 if (iCh>=5 && iCh<=6){
348 if ((lDetElemNumber>=5&&lDetElemNumber<=13) && lSpecLROnOff[0]){
349 lMeanY += lDetElemGloY;
350 lSigmaY += lDetElemGloY*lDetElemGloY;
351 lMeanZ += lDetElemGloZ;
352 lSigmaZ += lDetElemGloZ*lDetElemGloZ;
353 lNDetElem++;
354 }
355 if (((lDetElemNumber>=0&&lDetElemNumber<=4) ||
356 (lDetElemNumber>=14&&lDetElemNumber<=17)) && lSpecLROnOff[1]){
357 lMeanY += lDetElemGloY;
358 lSigmaY += lDetElemGloY*lDetElemGloY;
359 lMeanZ += lDetElemGloZ;
360 lSigmaZ += lDetElemGloZ*lDetElemGloZ;
361 lNDetElem++;
362 }
363 }
364 if (iCh>=7 && iCh<=10){
365 if ((lDetElemNumber>=7&&lDetElemNumber<=19) && lSpecLROnOff[0]){
366 lMeanY += lDetElemGloY;
367 lSigmaY += lDetElemGloY*lDetElemGloY;
368 lMeanZ += lDetElemGloZ;
369 lSigmaZ += lDetElemGloZ*lDetElemGloZ;
370 lNDetElem++;
371 }
372 if (((lDetElemNumber>=0&&lDetElemNumber<=6) ||
373 (lDetElemNumber>=20&&lDetElemNumber<=25)) && lSpecLROnOff[1]){
374 lMeanY += lDetElemGloY;
375 lSigmaY += lDetElemGloY*lDetElemGloY;
376 lMeanZ += lDetElemGloZ;
377 lSigmaZ += lDetElemGloZ*lDetElemGloZ;
378 lNDetElem++;
379 }
380 }
381 }
382 }
383 lMeanY /= lNDetElem;
384 lSigmaY /= lNDetElem;
385 lSigmaY = TMath::Sqrt(lSigmaY-lMeanY*lMeanY);
386 lMeanZ /= lNDetElem;
387 lSigmaZ /= lNDetElem;
388 lSigmaZ = TMath::Sqrt(lSigmaZ-lMeanZ*lMeanZ);
389 AliInfo(Form("Used %i DetElem, MeanZ= %f , SigmaZ= %f", lNDetElem,lMeanZ,lSigmaZ));
390
391 for (Int_t i = 0; i < fgNDetElem; i++){
392 Int_t iCh=0;
393 for (iCh=1; iCh<=fgNCh; iCh++){
394 if (i<fgSNDetElemCh[iCh-1]) break;
395 }
d8ad38e5 396 if (lChOnOff[iCh-1]){
3b2890be 397 Int_t lDetElemNumber = (iCh==1) ? i : i-fgSNDetElemCh[iCh-2];
398 Int_t lDetElemId = iCh*100+lDetElemNumber;
399 fTransform->Local2Global(lDetElemId,lDetElemLocX,lDetElemLocY,lDetElemLocZ,
400 lDetElemGloX,lDetElemGloY,lDetElemGloZ);
010eb601 401 if (lVarXYT[0]) { // X constraint
402 if (lDetTLBR[0]) ConstrainT(i,iCh,fConstraintXT,0); // Top half
403 if (lDetTLBR[1]) ConstrainL(i,iCh,fConstraintXL,0); // Left half
404 if (lDetTLBR[2]) ConstrainB(i,iCh,fConstraintXB,0); // Bottom half
405 if (lDetTLBR[3]) ConstrainR(i,iCh,fConstraintXR,0); // Right half
406 }
3b2890be 407 if (lVarXYT[1]) { // Y constraint
010eb601 408 if (lDetTLBR[0]) ConstrainT(i,iCh,fConstraintYT,1); // Top half
409 if (lDetTLBR[1]) ConstrainL(i,iCh,fConstraintYL,1); // Left half
410 if (lDetTLBR[2]) ConstrainB(i,iCh,fConstraintYB,1); // Bottom half
411 if (lDetTLBR[3]) ConstrainR(i,iCh,fConstraintYR,1); // Right half
412 }
3b2890be 413 if (lVarXYT[2]) { // P constraint
010eb601 414 if (lDetTLBR[0]) ConstrainT(i,iCh,fConstraintPT,2); // Top half
415 if (lDetTLBR[1]) ConstrainL(i,iCh,fConstraintPL,2); // Left half
416 if (lDetTLBR[2]) ConstrainB(i,iCh,fConstraintPB,2); // Bottom half
417 if (lDetTLBR[3]) ConstrainR(i,iCh,fConstraintPR,2); // Right half
418 }
3b2890be 419 if (lVarXYT[3]) { // X-Z shearing
420 if (lDetTLBR[0]) ConstrainT(i,iCh,fConstraintXZT,0,(lDetElemGloZ-lMeanZ)/lSigmaZ); // Top half
421 if (lDetTLBR[1]) ConstrainL(i,iCh,fConstraintXZL,0,(lDetElemGloZ-lMeanZ)/lSigmaZ); // Left half
422 if (lDetTLBR[2]) ConstrainB(i,iCh,fConstraintXZB,0,(lDetElemGloZ-lMeanZ)/lSigmaZ); // Bottom half
423 if (lDetTLBR[3]) ConstrainR(i,iCh,fConstraintXZR,0,(lDetElemGloZ-lMeanZ)/lSigmaZ); // Right half
424 }
425 if (lVarXYT[4]) { // Y-Z shearing
426 if (lDetTLBR[0]) ConstrainT(i,iCh,fConstraintYZT,1,(lDetElemGloZ-lMeanZ)/lSigmaZ); // Top half
427 if (lDetTLBR[1]) ConstrainL(i,iCh,fConstraintYZL,1,(lDetElemGloZ-lMeanZ)/lSigmaZ); // Left half
428 if (lDetTLBR[2]) ConstrainB(i,iCh,fConstraintYZB,1,(lDetElemGloZ-lMeanZ)/lSigmaZ); // Bottom half
429 if (lDetTLBR[3]) ConstrainR(i,iCh,fConstraintYZR,1,(lDetElemGloZ-lMeanZ)/lSigmaZ); // Right half
430 }
431 if (lVarXYT[5]) { // P-Z rotation
432 if (lDetTLBR[0]) ConstrainT(i,iCh,fConstraintPZT,2,(lDetElemGloZ-lMeanZ)/lSigmaZ); // Top half
433 if (lDetTLBR[1]) ConstrainL(i,iCh,fConstraintPZL,2,(lDetElemGloZ-lMeanZ)/lSigmaZ); // Left half
434 if (lDetTLBR[2]) ConstrainB(i,iCh,fConstraintPZB,2,(lDetElemGloZ-lMeanZ)/lSigmaZ); // Bottom half
435 if (lDetTLBR[3]) ConstrainR(i,iCh,fConstraintPZR,2,(lDetElemGloZ-lMeanZ)/lSigmaZ); // Right half
436 }
437 if (lVarXYT[6]) { // X-Y shearing
438 if (lDetTLBR[0]) ConstrainT(i,iCh,fConstraintXYT,0,(lDetElemGloY-lMeanY)/lSigmaY); // Top half
439 if (lDetTLBR[1]) ConstrainL(i,iCh,fConstraintXYL,0,(lDetElemGloY-lMeanY)/lSigmaY); // Left half
440 if (lDetTLBR[2]) ConstrainB(i,iCh,fConstraintXYB,0,(lDetElemGloY-lMeanY)/lSigmaY); // Bottom half
441 if (lDetTLBR[3]) ConstrainR(i,iCh,fConstraintXYR,0,(lDetElemGloY-lMeanY)/lSigmaY); // Right half
442 }
443 if (lVarXYT[7]) { // Y-Y scaling
444 if (lDetTLBR[0]) ConstrainT(i,iCh,fConstraintYYT,1,(lDetElemGloY-lMeanY)/lSigmaY); // Top half
445 if (lDetTLBR[1]) ConstrainL(i,iCh,fConstraintYYL,1,(lDetElemGloY-lMeanY)/lSigmaY); // Left half
446 if (lDetTLBR[2]) ConstrainB(i,iCh,fConstraintYYB,1,(lDetElemGloY-lMeanY)/lSigmaY); // Bottom half
447 if (lDetTLBR[3]) ConstrainR(i,iCh,fConstraintYYR,1,(lDetElemGloY-lMeanY)/lSigmaY); // Right half
448 }
449 if (lVarXYT[8]) { // P-Y rotation
450 if (lDetTLBR[0]) ConstrainT(i,iCh,fConstraintPYT,2,(lDetElemGloY-lMeanY)/lSigmaY); // Top half
451 if (lDetTLBR[1]) ConstrainL(i,iCh,fConstraintPYL,2,(lDetElemGloY-lMeanY)/lSigmaY); // Left half
452 if (lDetTLBR[2]) ConstrainB(i,iCh,fConstraintPYB,2,(lDetElemGloY-lMeanY)/lSigmaY); // Bottom half
453 if (lDetTLBR[3]) ConstrainR(i,iCh,fConstraintPYR,2,(lDetElemGloY-lMeanY)/lSigmaY); // Right half
454 }
010eb601 455 }
456 }
457 if (lVarXYT[0]) { // X constraint
458 if (lDetTLBR[0]) AddConstraint(fConstraintXT,0.0); // Top half
459 if (lDetTLBR[1]) AddConstraint(fConstraintXL,0.0); // Left half
460 if (lDetTLBR[2]) AddConstraint(fConstraintXB,0.0); // Bottom half
461 if (lDetTLBR[3]) AddConstraint(fConstraintXR,0.0); // Right half
462 }
463 if (lVarXYT[1]) { // Y constraint
464 if (lDetTLBR[0]) AddConstraint(fConstraintYT,0.0); // Top half
465 if (lDetTLBR[1]) AddConstraint(fConstraintYL,0.0); // Left half
466 if (lDetTLBR[2]) AddConstraint(fConstraintYB,0.0); // Bottom half
467 if (lDetTLBR[3]) AddConstraint(fConstraintYR,0.0); // Right half
468 }
469 if (lVarXYT[2]) { // T constraint
470 if (lDetTLBR[0]) AddConstraint(fConstraintPT,0.0); // Top half
471 if (lDetTLBR[1]) AddConstraint(fConstraintPL,0.0); // Left half
472 if (lDetTLBR[2]) AddConstraint(fConstraintPB,0.0); // Bottom half
473 if (lDetTLBR[3]) AddConstraint(fConstraintPR,0.0); // Right half
474 }
3b2890be 475 if (lVarXYT[3]) { // X-Z constraint
476 if (lDetTLBR[0]) AddConstraint(fConstraintXZT,0.0); // Top half
477 if (lDetTLBR[1]) AddConstraint(fConstraintXZL,0.0); // Left half
478 if (lDetTLBR[2]) AddConstraint(fConstraintXZB,0.0); // Bottom half
479 if (lDetTLBR[3]) AddConstraint(fConstraintXZR,0.0); // Right half
480 }
481 if (lVarXYT[4]) { // Y-Z constraint
482 if (lDetTLBR[0]) AddConstraint(fConstraintYZT,0.0); // Top half
483 if (lDetTLBR[1]) AddConstraint(fConstraintYZL,0.0); // Left half
484 if (lDetTLBR[2]) AddConstraint(fConstraintYZB,0.0); // Bottom half
485 if (lDetTLBR[3]) AddConstraint(fConstraintYZR,0.0); // Right half
486 }
487 if (lVarXYT[5]) { // P-Z constraint
488 if (lDetTLBR[0]) AddConstraint(fConstraintPZT,0.0); // Top half
489 if (lDetTLBR[1]) AddConstraint(fConstraintPZL,0.0); // Left half
490 if (lDetTLBR[2]) AddConstraint(fConstraintPZB,0.0); // Bottom half
491 if (lDetTLBR[3]) AddConstraint(fConstraintPZR,0.0); // Right half
492 }
493 if (lVarXYT[6]) { // X-Y constraint
494 if (lDetTLBR[0]) AddConstraint(fConstraintXYT,0.0); // Top half
495 if (lDetTLBR[1]) AddConstraint(fConstraintXYL,0.0); // Left half
496 if (lDetTLBR[2]) AddConstraint(fConstraintXYB,0.0); // Bottom half
497 if (lDetTLBR[3]) AddConstraint(fConstraintXYR,0.0); // Right half
498 }
499 if (lVarXYT[7]) { // Y-Y constraint
500 if (lDetTLBR[0]) AddConstraint(fConstraintYYT,0.0); // Top half
501 if (lDetTLBR[1]) AddConstraint(fConstraintYYL,0.0); // Left half
502 if (lDetTLBR[2]) AddConstraint(fConstraintYYB,0.0); // Bottom half
503 if (lDetTLBR[3]) AddConstraint(fConstraintYYR,0.0); // Right half
504 }
505 if (lVarXYT[8]) { // P-Y constraint
506 if (lDetTLBR[0]) AddConstraint(fConstraintPYT,0.0); // Top half
507 if (lDetTLBR[1]) AddConstraint(fConstraintPYL,0.0); // Left half
508 if (lDetTLBR[2]) AddConstraint(fConstraintPYB,0.0); // Bottom half
509 if (lDetTLBR[3]) AddConstraint(fConstraintPYR,0.0); // Right half
510 }
010eb601 511}
512
a6ec842d 513void AliMUONAlignment::ConstrainT(Int_t lDetElem, Int_t lCh, Double_t *lConstraintT, Int_t iVar, Double_t /*lWeight*/) const{
010eb601 514 /// Set constrain equation for top half of spectrometer
515 Int_t lDetElemNumber = (lCh==1) ? lDetElem : lDetElem-fgSNDetElemCh[lCh-2];
516 if (lCh>=1 && lCh<=4){
517 if (lDetElemNumber==0 || lDetElemNumber==1){ // From track crossings
518 lConstraintT[lDetElem*fgNParCh+iVar]=1.0;
519 }
520 }
521 if (lCh>=5 && lCh<=6){
522 if (lDetElemNumber>=0&&lDetElemNumber<=9){
523 lConstraintT[lDetElem*fgNParCh+iVar]=1.0;
524 }
525 }
526 if (lCh>=7 && lCh<=10){
527 if (lDetElemNumber>=0&&lDetElemNumber<=13){
528 lConstraintT[lDetElem*fgNParCh+iVar]=1.0;
529 }
530 }
531}
532
a6ec842d 533void AliMUONAlignment::ConstrainL(Int_t lDetElem, Int_t lCh, Double_t *lConstraintL, Int_t iVar, Double_t lWeight) const{
010eb601 534 /// Set constrain equation for left half of spectrometer
535 Int_t lDetElemNumber = (lCh==1) ? lDetElem : lDetElem-fgSNDetElemCh[lCh-2];
536 if (lCh>=1 && lCh<=4){
537 if (lDetElemNumber==1 || lDetElemNumber==2){ // From track crossings
3b2890be 538 lConstraintL[lDetElem*fgNParCh+iVar]=lWeight;
010eb601 539 }
540 }
541 if (lCh>=5 && lCh<=6){
542 if (lDetElemNumber>=5&&lDetElemNumber<=13){
3b2890be 543 lConstraintL[lDetElem*fgNParCh+iVar]=lWeight;
010eb601 544 }
545 }
546 if (lCh>=7 && lCh<=10){
547 if (lDetElemNumber>=7&&lDetElemNumber<=19){
3b2890be 548 lConstraintL[lDetElem*fgNParCh+iVar]=lWeight;
010eb601 549 }
550 }
551}
552
a6ec842d 553void AliMUONAlignment::ConstrainB(Int_t lDetElem, Int_t lCh, Double_t *lConstraintB, Int_t iVar, Double_t /*lWeight*/) const{
010eb601 554 /// Set constrain equation for bottom half of spectrometer
555 Int_t lDetElemNumber = (lCh==1) ? lDetElem : lDetElem-fgSNDetElemCh[lCh-2];
556 if (lCh>=1 && lCh<=4){
3b2890be 557 if (lDetElemNumber==2 || lDetElemNumber==3){ // From track crossings
010eb601 558 lConstraintB[lDetElem*fgNParCh+iVar]=1.0;
559 }
560 }
561 if (lCh>=5 && lCh<=6){
562 if ((lDetElemNumber>=9&&lDetElemNumber<=17) ||
563 (lDetElemNumber==0)){
564 lConstraintB[lDetElem*fgNParCh+iVar]=1.0;
565 }
566 }
567 if (lCh>=7 && lCh<=10){
568 if ((lDetElemNumber>=13&&lDetElemNumber<=25) ||
569 (lDetElemNumber==0)){
570 lConstraintB[lDetElem*fgNParCh+iVar]=1.0;
571 }
572 }
573}
574
a6ec842d 575void AliMUONAlignment::ConstrainR(Int_t lDetElem, Int_t lCh, Double_t *lConstraintR, Int_t iVar, Double_t lWeight) const{
010eb601 576 /// Set constrain equation for right half of spectrometer
577 Int_t lDetElemNumber = (lCh==1) ? lDetElem : lDetElem-fgSNDetElemCh[lCh-2];
578 if (lCh>=1 && lCh<=4){
3b2890be 579 if (lDetElemNumber==0 || lDetElemNumber==3){ // From track crossings
580 lConstraintR[lDetElem*fgNParCh+iVar]=lWeight;
010eb601 581 }
582 }
583 if (lCh>=5 && lCh<=6){
584 if ((lDetElemNumber>=0&&lDetElemNumber<=4) ||
585 (lDetElemNumber>=14&&lDetElemNumber<=17)){
3b2890be 586 lConstraintR[lDetElem*fgNParCh+iVar]=lWeight;
010eb601 587 }
588 }
589 if (lCh>=7 && lCh<=10){
590 if ((lDetElemNumber>=0&&lDetElemNumber<=6) ||
591 (lDetElemNumber>=20&&lDetElemNumber<=25)){
3b2890be 592 lConstraintR[lDetElem*fgNParCh+iVar]=lWeight;
010eb601 593 }
594 }
595}
596
597void AliMUONAlignment::ResetConstraints(){
598 /// Reset all constraint equations
599 for (Int_t i = 0; i < fgNDetElem; i++){
3b2890be 600 fConstraintX[i*fgNParCh+0]=0.0;
601 fConstraintX[i*fgNParCh+1]=0.0;
602 fConstraintX[i*fgNParCh+2]=0.0;
603 fConstraintY[i*fgNParCh+0]=0.0;
604 fConstraintY[i*fgNParCh+1]=0.0;
605 fConstraintY[i*fgNParCh+2]=0.0;
606 fConstraintP[i*fgNParCh+0]=0.0;
607 fConstraintP[i*fgNParCh+1]=0.0;
608 fConstraintP[i*fgNParCh+2]=0.0;
609 fConstraintXT[i*fgNParCh+0]=0.0;
610 fConstraintXT[i*fgNParCh+1]=0.0;
611 fConstraintXT[i*fgNParCh+2]=0.0;
612 fConstraintYT[i*fgNParCh+0]=0.0;
613 fConstraintYT[i*fgNParCh+1]=0.0;
614 fConstraintYT[i*fgNParCh+2]=0.0;
615 fConstraintPT[i*fgNParCh+0]=0.0;
616 fConstraintPT[i*fgNParCh+1]=0.0;
617 fConstraintPT[i*fgNParCh+2]=0.0;
618 fConstraintXZT[i*fgNParCh+0]=0.0;
619 fConstraintXZT[i*fgNParCh+1]=0.0;
620 fConstraintXZT[i*fgNParCh+2]=0.0;
621 fConstraintYZT[i*fgNParCh+0]=0.0;
622 fConstraintYZT[i*fgNParCh+1]=0.0;
623 fConstraintYZT[i*fgNParCh+2]=0.0;
624 fConstraintPZT[i*fgNParCh+0]=0.0;
625 fConstraintPZT[i*fgNParCh+1]=0.0;
626 fConstraintPZT[i*fgNParCh+2]=0.0;
627 fConstraintXYT[i*fgNParCh+0]=0.0;
628 fConstraintXYT[i*fgNParCh+1]=0.0;
629 fConstraintXYT[i*fgNParCh+2]=0.0;
630 fConstraintYYT[i*fgNParCh+0]=0.0;
631 fConstraintYYT[i*fgNParCh+1]=0.0;
632 fConstraintYYT[i*fgNParCh+2]=0.0;
633 fConstraintPYT[i*fgNParCh+0]=0.0;
634 fConstraintPYT[i*fgNParCh+1]=0.0;
635 fConstraintPYT[i*fgNParCh+2]=0.0;
636 fConstraintXL[i*fgNParCh+0]=0.0;
637 fConstraintXL[i*fgNParCh+1]=0.0;
638 fConstraintXL[i*fgNParCh+2]=0.0;
639 fConstraintYL[i*fgNParCh+0]=0.0;
640 fConstraintYL[i*fgNParCh+1]=0.0;
641 fConstraintYL[i*fgNParCh+2]=0.0;
642 fConstraintPL[i*fgNParCh+0]=0.0;
643 fConstraintPL[i*fgNParCh+1]=0.0;
644 fConstraintPL[i*fgNParCh+2]=0.0;
645 fConstraintXZL[i*fgNParCh+0]=0.0;
646 fConstraintXZL[i*fgNParCh+1]=0.0;
647 fConstraintXZL[i*fgNParCh+2]=0.0;
648 fConstraintYZL[i*fgNParCh+0]=0.0;
649 fConstraintYZL[i*fgNParCh+1]=0.0;
650 fConstraintYZL[i*fgNParCh+2]=0.0;
651 fConstraintPZL[i*fgNParCh+0]=0.0;
652 fConstraintPZL[i*fgNParCh+1]=0.0;
653 fConstraintPZL[i*fgNParCh+2]=0.0;
654 fConstraintXYL[i*fgNParCh+0]=0.0;
655 fConstraintXYL[i*fgNParCh+1]=0.0;
656 fConstraintXYL[i*fgNParCh+2]=0.0;
657 fConstraintYYL[i*fgNParCh+0]=0.0;
658 fConstraintYYL[i*fgNParCh+1]=0.0;
659 fConstraintYYL[i*fgNParCh+2]=0.0;
660 fConstraintPYL[i*fgNParCh+0]=0.0;
661 fConstraintPYL[i*fgNParCh+1]=0.0;
662 fConstraintPYL[i*fgNParCh+2]=0.0;
663 fConstraintXB[i*fgNParCh+0]=0.0;
664 fConstraintXB[i*fgNParCh+1]=0.0;
665 fConstraintXB[i*fgNParCh+2]=0.0;
666 fConstraintYB[i*fgNParCh+0]=0.0;
667 fConstraintYB[i*fgNParCh+1]=0.0;
668 fConstraintYB[i*fgNParCh+2]=0.0;
669 fConstraintPB[i*fgNParCh+0]=0.0;
670 fConstraintPB[i*fgNParCh+1]=0.0;
671 fConstraintPB[i*fgNParCh+2]=0.0;
672 fConstraintXZB[i*fgNParCh+0]=0.0;
673 fConstraintXZB[i*fgNParCh+1]=0.0;
674 fConstraintXZB[i*fgNParCh+2]=0.0;
675 fConstraintYZB[i*fgNParCh+0]=0.0;
676 fConstraintYZB[i*fgNParCh+1]=0.0;
677 fConstraintYZB[i*fgNParCh+2]=0.0;
678 fConstraintPZB[i*fgNParCh+0]=0.0;
679 fConstraintPZB[i*fgNParCh+1]=0.0;
680 fConstraintPZB[i*fgNParCh+2]=0.0;
681 fConstraintXYB[i*fgNParCh+0]=0.0;
682 fConstraintXYB[i*fgNParCh+1]=0.0;
683 fConstraintXYB[i*fgNParCh+2]=0.0;
684 fConstraintYYB[i*fgNParCh+0]=0.0;
685 fConstraintYYB[i*fgNParCh+1]=0.0;
686 fConstraintYYB[i*fgNParCh+2]=0.0;
687 fConstraintPYB[i*fgNParCh+0]=0.0;
688 fConstraintPYB[i*fgNParCh+1]=0.0;
689 fConstraintPYB[i*fgNParCh+2]=0.0;
690 fConstraintXR[i*fgNParCh+0]=0.0;
691 fConstraintXR[i*fgNParCh+1]=0.0;
692 fConstraintXR[i*fgNParCh+2]=0.0;
693 fConstraintYR[i*fgNParCh+0]=0.0;
694 fConstraintYR[i*fgNParCh+1]=0.0;
695 fConstraintYR[i*fgNParCh+2]=0.0;
696 fConstraintPR[i*fgNParCh+0]=0.0;
697 fConstraintPR[i*fgNParCh+1]=0.0;
698 fConstraintPR[i*fgNParCh+2]=0.0;
699 fConstraintXZR[i*fgNParCh+0]=0.0;
700 fConstraintXZR[i*fgNParCh+1]=0.0;
701 fConstraintXZR[i*fgNParCh+2]=0.0;
702 fConstraintYZR[i*fgNParCh+0]=0.0;
703 fConstraintYZR[i*fgNParCh+1]=0.0;
704 fConstraintYZR[i*fgNParCh+2]=0.0;
705 fConstraintPZR[i*fgNParCh+0]=0.0;
706 fConstraintPZR[i*fgNParCh+1]=0.0;
707 fConstraintPZR[i*fgNParCh+2]=0.0;
708 fConstraintPZR[i*fgNParCh+0]=0.0;
709 fConstraintPZR[i*fgNParCh+1]=0.0;
710 fConstraintPZR[i*fgNParCh+2]=0.0;
711 fConstraintXYR[i*fgNParCh+0]=0.0;
712 fConstraintXYR[i*fgNParCh+1]=0.0;
713 fConstraintXYR[i*fgNParCh+2]=0.0;
714 fConstraintYYR[i*fgNParCh+0]=0.0;
715 fConstraintYYR[i*fgNParCh+1]=0.0;
716 fConstraintYYR[i*fgNParCh+2]=0.0;
717 fConstraintPYR[i*fgNParCh+0]=0.0;
718 fConstraintPYR[i*fgNParCh+1]=0.0;
719 fConstraintPYR[i*fgNParCh+2]=0.0;
010eb601 720 }
721}
722
723void AliMUONAlignment::AddConstraint(Double_t *par, Double_t value) {
724 /// Constrain equation defined by par to value
725 fMillepede->SetGlobalConstraint(par, value);
726 AliInfo("Adding constraint");
727}
728
729void AliMUONAlignment::InitGlobalParameters(Double_t *par) {
730 /// Initialize global parameters with par array
731 fMillepede->SetGlobalParameters(par);
732 AliInfo("Init Global Parameters");
733}
734
735void AliMUONAlignment::FixParameter(Int_t iPar, Double_t value) {
736 /// Parameter iPar is encourage to vary in [-value;value].
737 /// If value == 0, parameter is fixed
738 fMillepede->SetParSigma(iPar, value);
a6ec842d 739 if (TMath::Abs(value)<1e-4) AliInfo(Form("Parameter %i Fixed", iPar));
010eb601 740}
741
742void AliMUONAlignment::ResetLocalEquation()
743{
744 /// Reset the derivative vectors
745 for(int i=0; i<fNLocal; i++) {
746 fLocalDerivatives[i] = 0.0;
747 }
748 for(int i=0; i<fNGlobal; i++) {
749 fGlobalDerivatives[i] = 0.0;
750 }
751}
752
a6ec842d 753void AliMUONAlignment::AllowVariations(const Bool_t *bChOnOff) {
d8ad38e5 754 /// Set allowed variation for selected chambers based on fDoF and fAllowVar
755 for (Int_t iCh=1; iCh<=10; iCh++) {
756 if (bChOnOff[iCh-1]) {
757 Int_t iDetElemFirst = (iCh>1) ? fgSNDetElemCh[iCh-2] : 0;
758 Int_t iDetElemLast = fgSNDetElemCh[iCh-1];
010eb601 759 for (int i=0; i<fgNParCh; i++) {
760 AliDebug(1,Form("fDoF[%d]= %d",i,fDoF[i]));
761 if (fDoF[i]) {
762 for (Int_t j=iDetElemFirst; j<iDetElemLast; j++){
763 FixParameter(j*fgNParCh+i, fAllowVar[i]);
764 }
765 }
766 }
767 }
768 }
769}
770
771void AliMUONAlignment::SetNonLinear(Int_t iPar /* set non linear flag */ ) {
772 /// Set nonlinear flag for parameter iPar
773 fMillepede->SetNonLinear(iPar);
774 AliInfo(Form("Parameter %i set to non linear", iPar));
775}
776
64e2c144 777
778void AliMUONAlignment::SetSigmaXY(Double_t sigmaX, Double_t sigmaY) {
779 /// Set expected measurement resolution
780 fSigma[0] = sigmaX; fSigma[1] = sigmaY;
781 AliInfo(Form("Using fSigma[0]=%f and fSigma[1]=%f",fSigma[0],fSigma[1]));
782}
783
784
010eb601 785void AliMUONAlignment::LocalEquationX() {
96ebe67e 786 /// Define local equation for current track and cluster in x coor. measurement
010eb601 787 // set local derivatives
788 SetLocalDerivative(0, fCosPhi);
789 SetLocalDerivative(1, fCosPhi * (fTrackPos[2] - fTrackPos0[2]));
790 SetLocalDerivative(2, fSinPhi);
791 SetLocalDerivative(3, fSinPhi * (fTrackPos[2] - fTrackPos0[2]));
792
793 // set global derivatives
3b2890be 794 SetGlobalDerivative(fDetElemNumber*fgNParCh+0, -fCosPhi);
795 SetGlobalDerivative(fDetElemNumber*fgNParCh+1, -fSinPhi);
010eb601 796 if (fBFieldOn){
797 SetGlobalDerivative(fDetElemNumber*fgNParCh+2,
798 -fSinPhi*(fTrackPos[0]-fDetElemPos[0])
799 +fCosPhi*(fTrackPos[1]-fDetElemPos[1]));
800 }
801 else {
802 SetGlobalDerivative(fDetElemNumber*fgNParCh+2,
803 -fSinPhi*(fTrackPos0[0]+fTrackSlope0[0]*
804 (fTrackPos[2]-fTrackPos0[2])-fDetElemPos[0])
805 +fCosPhi*(fTrackPos0[1]+fTrackSlope0[1]*
806 (fTrackPos[2]-fTrackPos0[2])-fDetElemPos[1]));
807 }
723b0b5b 808 SetGlobalDerivative(fDetElemNumber*fgNParCh+3,
809 fCosPhi*fTrackSlope0[0]+fSinPhi*fTrackSlope0[1]);
010eb601 810
811 fMillepede->SetLocalEquation(fGlobalDerivatives, fLocalDerivatives, fMeas[0], fSigma[0]);
812}
813
814void AliMUONAlignment::LocalEquationY() {
96ebe67e 815 /// Define local equation for current track and cluster in y coor. measurement
010eb601 816 // set local derivatives
817 SetLocalDerivative(0,-fSinPhi);
818 SetLocalDerivative(1,-fSinPhi * (fTrackPos[2] - fTrackPos0[2]));
819 SetLocalDerivative(2, fCosPhi);
820 SetLocalDerivative(3, fCosPhi * (fTrackPos[2] - fTrackPos0[2]));
821
822 // set global derivatives
3b2890be 823 SetGlobalDerivative(fDetElemNumber*fgNParCh+0, fSinPhi);
824 SetGlobalDerivative(fDetElemNumber*fgNParCh+1, -fCosPhi);
010eb601 825 if (fBFieldOn){
826 SetGlobalDerivative(fDetElemNumber*fgNParCh+2,
827 -fCosPhi*(fTrackPos[0]-fDetElemPos[0])
828 -fSinPhi*(fTrackPos[1]-fDetElemPos[1]));
829 }
830 else {
831 SetGlobalDerivative(fDetElemNumber*fgNParCh+2,
832 -fCosPhi*(fTrackPos0[0]+fTrackSlope0[0]*
833 (fTrackPos[2]-fTrackPos0[2])-fDetElemPos[0])
834 -fSinPhi*(fTrackPos0[1]+fTrackSlope0[1]*
835 (fTrackPos[2]-fTrackPos0[2])-fDetElemPos[1]));
836 }
723b0b5b 837 SetGlobalDerivative(fDetElemNumber*fgNParCh+3,
838 -fSinPhi*fTrackSlope0[0]+fCosPhi*fTrackSlope0[1]);
010eb601 839
840 fMillepede->SetLocalEquation(fGlobalDerivatives, fLocalDerivatives, fMeas[1], fSigma[1]);
841}
842
843void AliMUONAlignment::FillRecPointData() {
96ebe67e 844 /// Get information of current cluster
845 fClustPos[0] = fCluster->GetX();
846 fClustPos[1] = fCluster->GetY();
847 fClustPos[2] = fCluster->GetZ();
010eb601 848 fTransform->Global2Local(fDetElemId,fClustPos[0],fClustPos[1],fClustPos[2],
849 fClustPosLoc[0],fClustPosLoc[1],fClustPosLoc[2]);
850}
851
852void AliMUONAlignment::FillTrackParamData() {
96ebe67e 853 /// Get information of current track at current cluster
010eb601 854 fTrackPos[0] = fTrackParam->GetNonBendingCoor();
855 fTrackPos[1] = fTrackParam->GetBendingCoor();
856 fTrackPos[2] = fTrackParam->GetZ();
857 fTrackSlope[0] = fTrackParam->GetNonBendingSlope();
858 fTrackSlope[1] = fTrackParam->GetBendingSlope();
859 fTransform->Global2Local(fDetElemId,fTrackPos[0],fTrackPos[1],fTrackPos[2],
860 fTrackPosLoc[0],fTrackPosLoc[1],fTrackPosLoc[2]);
861}
862
863void AliMUONAlignment::FillDetElemData() {
864 /// Get information of current detection element
865 Double_t lDetElemLocX = 0.;
866 Double_t lDetElemLocY = 0.;
867 Double_t lDetElemLocZ = 0.;
96ebe67e 868 fDetElemId = fCluster->GetDetElemId();
010eb601 869 fDetElemNumber = fDetElemId%100;
870 for (int iCh=0; iCh<fDetElemId/100-1; iCh++){
871 fDetElemNumber += fgNDetElemCh[iCh];
872 }
873 fTransform->Local2Global(fDetElemId,lDetElemLocX,lDetElemLocY,lDetElemLocZ,
874 fDetElemPos[0],fDetElemPos[1],fDetElemPos[2]);
010eb601 875}
876
877void AliMUONAlignment::ProcessTrack(AliMUONTrack * track) {
96ebe67e 878 /// Process track; Loop over clusters and set local equations
010eb601 879 fTrack = track;
880 // get tclones arrays.
96ebe67e 881 fTrackParamAtCluster = fTrack->GetTrackParamAtCluster();
010eb601 882
883 // get size of arrays
96ebe67e 884 Int_t nTrackParam = fTrackParamAtCluster->GetEntries();
3b2890be 885 AliDebug(1,Form("Number of track param entries : %i ", nTrackParam));
010eb601 886
96ebe67e 887 for(Int_t iCluster=0; iCluster<nTrackParam; iCluster++) {
888 fTrackParam = (AliMUONTrackParam *) fTrack->GetTrackParamAtCluster()->At(iCluster);
e6fb429f 889 if (!fTrackParam) continue;
96ebe67e 890 fCluster = fTrackParam->GetClusterPtr();
e6fb429f 891 if (!fCluster) continue;
010eb601 892 // fill local variables for this position --> one measurement
893 FillDetElemData();
894 FillRecPointData();
895 FillTrackParamData();
896// if (fDetElemId<500) continue;
897 fTrackPos0[0] = fTrackPos[0];
898 fTrackPos0[1] = fTrackPos[1];
899 fTrackPos0[2] = fTrackPos[2];
900 fTrackSlope0[0] = fTrackSlope[0];
901 fTrackSlope0[1] = fTrackSlope[1];
902 break;
903 }
904
96ebe67e 905 for(Int_t iCluster=0; iCluster<nTrackParam; iCluster++) {
010eb601 906 // and get new pointers
96ebe67e 907 fTrackParam = (AliMUONTrackParam *) fTrack->GetTrackParamAtCluster()->At(iCluster);
c53d44b8 908 if (!fTrackParam) continue;
96ebe67e 909 fCluster = fTrackParam->GetClusterPtr();
c53d44b8 910 if (!fCluster) continue;
010eb601 911 // fill local variables for this position --> one measurement
912 FillDetElemData();
913 FillRecPointData();
914 FillTrackParamData();
915// if (fDetElemId<500) continue;
96ebe67e 916 AliDebug(1,Form("cluster: %i", iCluster));
010eb601 917 AliDebug(1,Form("x: %f\t y: %f\t z: %f\t DetElemID: %i\t ", fClustPos[0], fClustPos[1], fClustPos[2], fDetElemId));
918 AliDebug(1,Form("fDetElemPos[0]: %f\t fDetElemPos[1]: %f\t fDetElemPos[2]: %f\t DetElemID: %i\t ", fDetElemPos[0],fDetElemPos[1],fDetElemPos[2], fDetElemId));
919
96ebe67e 920 AliDebug(1,Form("Track Parameter: %i", iCluster));
010eb601 921 AliDebug(1,Form("x: %f\t y: %f\t z: %f\t slopex: %f\t slopey: %f", fTrackPos[0], fTrackPos[1], fTrackPos[2], fTrackSlope[0], fTrackSlope[1]));
922 AliDebug(1,Form("x0: %f\t y0: %f\t z0: %f\t slopex0: %f\t slopey0: %f", fTrackPos0[0], fTrackPos0[1], fTrackPos0[2], fTrackSlope0[0], fTrackSlope0[1]));
923
924 fCosPhi = TMath::Cos(fPhi);
925 fSinPhi = TMath::Sin(fPhi);
926 if (fBFieldOn){
927 fMeas[0] = fTrackPos[0] - fClustPos[0];
928 fMeas[1] = fTrackPos[1] - fClustPos[1];
929 }
930 else {
931 fMeas[0] = - fClustPos[0];
932 fMeas[1] = - fClustPos[1];
933 }
934 AliDebug(1,Form("fMeas[0]: %f\t fMeas[1]: %f\t fSigma[0]: %f\t fSigma[1]: %f", fMeas[0], fMeas[1], fSigma[0], fSigma[1]));
935 // Set local equations
936 LocalEquationX();
937 LocalEquationY();
938 }
939}
940
941void AliMUONAlignment::LocalFit(Int_t iTrack, Double_t *lTrackParam, Int_t lSingleFit) {
942 /// Call local fit for this tracks
943 Int_t iRes = fMillepede->LocalFit(iTrack,lTrackParam,lSingleFit);
944 if (iRes && !lSingleFit) {
945 fMillepede->SetNLocalEquations(fMillepede->GetNLocalEquations()+1);
946 }
947}
948
949void AliMUONAlignment::GlobalFit(Double_t *parameters,Double_t *errors,Double_t *pulls) {
950 /// Call global fit; Global parameters are stored in parameters
951 fMillepede->GlobalFit(parameters,errors,pulls);
3b2890be 952
010eb601 953 AliInfo("Done fitting global parameters!");
954 for (int iGlob=0; iGlob<fgNDetElem; iGlob++){
955 printf("%d\t %f\t %f\t %f \n",iGlob,parameters[iGlob*fgNParCh+0],parameters[iGlob*fgNParCh+1],parameters[iGlob*fgNParCh+2]);
956 }
957}
958
959Double_t AliMUONAlignment::GetParError(Int_t iPar) {
960 /// Get error of parameter iPar
961 Double_t lErr = fMillepede->GetParError(iPar);
962 return lErr;
963}
964
965void AliMUONAlignment::PrintGlobalParameters() {
966 /// Print global parameters
967 fMillepede->PrintGlobalParameters();
968}
969
970//_________________________________________________________________________
a6ec842d 971TGeoCombiTrans AliMUONAlignment::ReAlign(const TGeoCombiTrans & transform, const double *lMisAlignment) const
010eb601 972{
973 /// Realign given transformation by given misalignment and return the misaligned transformation
974
975 Double_t cartMisAlig[3] = {0,0,0};
976 Double_t angMisAlig[3] = {0,0,0};
3b2890be 977// const Double_t *trans = transform.GetTranslation();
978// TGeoRotation *rot;
979// // check if the rotation we obtain is not NULL
980// if (transform.GetRotation()) {
981// rot = transform.GetRotation();
982// }
983// else {
984// rot = new TGeoRotation("rot");
985// } // default constructor.
986
723b0b5b 987 cartMisAlig[0] = -TMath::Sign(1.0,transform.GetRotationMatrix()[0])*lMisAlignment[0];
988 cartMisAlig[1] = -TMath::Sign(1.0,transform.GetRotationMatrix()[4])*lMisAlignment[1];
989 cartMisAlig[2] = -TMath::Sign(1.0,transform.GetRotationMatrix()[8])*lMisAlignment[3];
990 angMisAlig[2] = -TMath::Sign(1.0,transform.GetRotationMatrix()[0]*transform.GetRotationMatrix()[4])*lMisAlignment[2]*180./TMath::Pi();
3b2890be 991
992 TGeoTranslation deltaTrans(cartMisAlig[0], cartMisAlig[1], cartMisAlig[2]);
993 TGeoRotation deltaRot;
994 deltaRot.RotateX(angMisAlig[0]);
995 deltaRot.RotateY(angMisAlig[1]);
996 deltaRot.RotateZ(angMisAlig[2]);
997
998 TGeoCombiTrans deltaTransf(deltaTrans,deltaRot);
999 TGeoHMatrix newTransfMat = transform * deltaTransf;
1000
1001 return TGeoCombiTrans(newTransfMat);
010eb601 1002}
1003
1004//______________________________________________________________________
1005AliMUONGeometryTransformer *
1006AliMUONAlignment::ReAlign(const AliMUONGeometryTransformer * transformer,
a6ec842d 1007 const double *misAlignments, Bool_t verbose)
010eb601 1008
1009{
625f657d 1010 /// Returns a new AliMUONGeometryTransformer with the found misalignments
1011 /// applied.
1012
1013 // Takes the internal geometry module transformers, copies them
010eb601 1014 // and gets the Detection Elements from them.
1015 // Takes misalignment parameters and applies these
1016 // to the local transform of the Detection Element
1017 // Obtains the global transform by multiplying the module transformer
1018 // transformation with the local transformation
1019 // Applies the global transform to a new detection element
1020 // Adds the new detection element to a new module transformer
1021 // Adds the new module transformer to a new geometry transformer
1022 // Returns the new geometry transformer
1023
64e2c144 1024 Double_t lModuleMisAlignment[4] = {0.,0.,0.,0.};
723b0b5b 1025 Double_t lDetElemMisAlignment[4] = {0.,0.,0.,0.};
3b2890be 1026 Int_t iDetElemId = 0;
1027 Int_t iDetElemNumber = 0;
010eb601 1028
1029 AliMUONGeometryTransformer *newGeometryTransformer =
ef4cb4f1 1030 new AliMUONGeometryTransformer();
3b2890be 1031 for (Int_t iMt = 0; iMt < transformer->GetNofModuleTransformers(); iMt++) {
1032 // module transformers
1033 const AliMUONGeometryModuleTransformer *kModuleTransformer =
1034 transformer->GetModuleTransformer(iMt, true);
010eb601 1035
3b2890be 1036 AliMUONGeometryModuleTransformer *newModuleTransformer =
1037 new AliMUONGeometryModuleTransformer(iMt);
1038 newGeometryTransformer->AddModuleTransformer(newModuleTransformer);
1039
1040 TGeoCombiTrans moduleTransform =
1041 TGeoCombiTrans(*kModuleTransformer->GetTransformation());
1042 // New module transformation
1043 TGeoCombiTrans newModuleTransform = ReAlign(moduleTransform,lModuleMisAlignment);
1044 newModuleTransformer->SetTransformation(newModuleTransform);
1045
1046 // Get delta transformation:
1047 // Tdelta = Tnew * Told.inverse
1048 TGeoHMatrix deltaModuleTransform =
1049 AliMUONGeometryBuilder::Multiply(newModuleTransform,
1050 kModuleTransformer->GetTransformation()->Inverse());
1051 // Create module mis alignment matrix
1052 newGeometryTransformer
1053 ->AddMisAlignModule(kModuleTransformer->GetModuleId(), deltaModuleTransform);
1054
1055 AliMpExMap *detElements = kModuleTransformer->GetDetElementStore();
1056
1057 if (verbose)
1058 AliInfo(Form("%i DEs in old GeometryStore %i",detElements->GetSize(), iMt));
1059
630711ed 1060 TIter next(detElements->CreateIterator());
1061 AliMUONGeometryDetElement* detElement;
1062 Int_t iDe(-1);
1063 while ( ( detElement = static_cast<AliMUONGeometryDetElement*>(next()) ) )
1064 {
1065 ++iDe;
625f657d 1066 // make a new detection element
3b2890be 1067 AliMUONGeometryDetElement *newDetElement =
1068 new AliMUONGeometryDetElement(detElement->GetId(),
1069 detElement->GetVolumePath());
1070 TString lDetElemName(detElement->GetDEName());
1071 lDetElemName.ReplaceAll("DE","");
1072 iDetElemId = lDetElemName.Atoi();
1073 iDetElemNumber = iDetElemId%100;
1074 for (int iCh=0; iCh<iDetElemId/100-1; iCh++){
1075 iDetElemNumber += fgNDetElemCh[iCh];
1076 }
1077 for (int i=0; i<fgNParCh; i++) {
1078 lDetElemMisAlignment[i] = 0.0;
1079 if (iMt<fgNTrkMod) {
1080 AliInfo(Form("iMt %i, iCh %i, iDe %i, iDeId %i, iDeNb %i, iPar %i",iMt, iDetElemId/100, iDe, iDetElemId, iDetElemNumber, iDetElemNumber*fgNParCh+i));
1081 lDetElemMisAlignment[i] = misAlignments[iDetElemNumber*fgNParCh+i];
1082 }
1083 }
1084 // local transformation of this detection element.
1085 TGeoCombiTrans localTransform
1086 = TGeoCombiTrans(*detElement->GetLocalTransformation());
1087 TGeoCombiTrans newLocalTransform = ReAlign(localTransform,lDetElemMisAlignment);
1088 newDetElement->SetLocalTransformation(newLocalTransform);
1089
1090 // global transformation
1091 TGeoHMatrix newGlobalTransform =
1092 AliMUONGeometryBuilder::Multiply(newModuleTransform,
1093 newLocalTransform);
1094 newDetElement->SetGlobalTransformation(newGlobalTransform);
010eb601 1095
3b2890be 1096 // add this det element to module
1097 newModuleTransformer->GetDetElementStore()->Add(newDetElement->GetId(),
1098 newDetElement);
1099
1100 // In the Alice Alignment Framework misalignment objects store
1101 // global delta transformation
1102 // Get detection "intermediate" global transformation
1103 TGeoHMatrix newOldGlobalTransform = newModuleTransform * localTransform;
1104 // Get detection element global delta transformation:
1105 // Tdelta = Tnew * Told.inverse
1106 TGeoHMatrix deltaGlobalTransform
1107 = AliMUONGeometryBuilder::Multiply(newGlobalTransform,
1108 newOldGlobalTransform.Inverse());
010eb601 1109
3b2890be 1110 // Create mis alignment matrix
1111 newGeometryTransformer
1112 ->AddMisAlignDetElement(detElement->GetId(), deltaGlobalTransform);
010eb601 1113 }
3b2890be 1114
1115 if (verbose)
1116 AliInfo(Form("Added module transformer %i to the transformer", iMt));
1117 newGeometryTransformer->AddModuleTransformer(newModuleTransformer);
1118 }
010eb601 1119 return newGeometryTransformer;
1120}
1121
4818a9b7 1122//______________________________________________________________________
1123void AliMUONAlignment::SetAlignmentResolution(const TClonesArray* misAlignArray, Int_t rChId, Double_t rChResX, Double_t rChResY, Double_t rDeResX, Double_t rDeResY){
625f657d 1124 /// Set alignment resolution to misalign objects to be stored in CDB
4818a9b7 1125 Int_t chIdMin = (rChId<0)? 0 : rChId;
1126 Int_t chIdMax = (rChId<0)? 9 : rChId;
1127 Double_t chResX = rChResX;
1128 Double_t chResY = rChResY;
1129 Double_t deResX = rDeResX;
1130 Double_t deResY = rDeResY;
1131
1132 TMatrixDSym mChCorrMatrix(6);
1133 mChCorrMatrix[0][0]=chResX*chResX;
1134 mChCorrMatrix[1][1]=chResY*chResY;
1135 // mChCorrMatrix.Print();
1136
1137 TMatrixDSym mDECorrMatrix(6);
1138 mDECorrMatrix[0][0]=deResX*deResX;
1139 mDECorrMatrix[1][1]=deResY*deResY;
1140 // mDECorrMatrix.Print();
1141
1142 AliAlignObjMatrix *alignMat = 0x0;
1143
1144 for(Int_t chId=chIdMin; chId<=chIdMax; chId++) {
1145 TString chName1;
1146 TString chName2;
1147 if (chId<4){
1148 chName1 = Form("GM%d",chId);
1149 chName2 = Form("GM%d",chId);
1150 } else {
1151 chName1 = Form("GM%d",4+(chId-4)*2);
1152 chName2 = Form("GM%d",4+(chId-4)*2+1);
1153 }
1154
1155 for (int i=0; i<misAlignArray->GetEntries(); i++) {
1156 alignMat = (AliAlignObjMatrix*)misAlignArray->At(i);
1157 TString volName(alignMat->GetSymName());
1158 if((volName.Contains(chName1)&&
1159 ((volName.Last('/')==volName.Index(chName1)+chName1.Length())||
1160 (volName.Length()==volName.Index(chName1)+chName1.Length())))||
1161 (volName.Contains(chName2)&&
1162 ((volName.Last('/')==volName.Index(chName2)+chName2.Length())||
1163 (volName.Length()==volName.Index(chName2)+chName2.Length())))){
1164 volName.Remove(0,volName.Last('/')+1);
1165 if (volName.Contains("GM")) {
1166 // alignMat->Print("NULL");
1167 alignMat->SetCorrMatrix(mChCorrMatrix);
1168 } else if (volName.Contains("DE")) {
1169 // alignMat->Print("NULL");
1170 alignMat->SetCorrMatrix(mDECorrMatrix);
1171 }
1172 }
1173 }
1174 }
1175}