Separating run-dependent mapping data from data, which are not
[u/mrichter/AliRoot.git] / MUON / AliMUONGeometryMisAligner.cxx
CommitLineData
21dd83fc 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * SigmaEffect_thetadegrees *
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 purpeateose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
16// $Id$
17//
3d1463c8 18//-----------------------------------------------------------------------------
a9aad96e 19/// \class AliMUONGeometryMisAligner
20///
21/// This performs the misalignment on an existing muon arm geometry
22/// based on the standard definition of the detector elements in
23/// $ALICE_ROOT/MUON/data
24///
25/// --> User has to specify the magnitude of the alignments, in the Cartesian
26/// co-ordiantes (which are used to apply translation misalignments) and in the
27/// spherical co-ordinates (which are used to apply angular displacements)
28///
29/// --> If the constructor is used with no arguments, user has to set
30/// misalignment ranges by hand using the methods :
31/// SetApplyMisAlig, SetMaxCartMisAlig, SetMaxAngMisAlig, SetXYAngMisAligFactor
32/// (last method takes account of the fact that the misalingment is greatest in
33/// the XY plane, since the detection elements are fixed to a support structure
34/// in this plane. Misalignments in the XZ and YZ plane will be very small
35/// compared to those in the XY plane, which are small already - of the order
36/// of microns)
37///
38/// Note : If the detection elements are allowed to be misaligned in all
39/// directions, this has consequences for the alignment algorithm
40/// (AliMUONAlignment), which needs to know the number of free parameters.
41/// Eric only allowed 3 : x,y,theta_xy, but in principle z and the other
42/// two angles are alignable as well.
43///
4600314b 44/// \author Bruce Becker, Javier Castillo
3d1463c8 45//-----------------------------------------------------------------------------
21dd83fc 46
21dd83fc 47#include "AliMUONGeometryMisAligner.h"
48#include "AliMUONGeometryTransformer.h"
49#include "AliMUONGeometryModuleTransformer.h"
50#include "AliMUONGeometryDetElement.h"
21dd83fc 51#include "AliMUONGeometryBuilder.h"
ef79ed3a 52
8c95578a 53#include "AliMpExMap.h"
630711ed 54#include "AliMpExMapIterator.h"
8c95578a 55
ef79ed3a 56#include "AliLog.h"
57
328e160e 58#include <TGeoMatrix.h>
21dd83fc 59#include <TMath.h>
60#include <TRandom.h>
ef4cb4f1 61#include <Riostream.h>
21dd83fc 62
a9aad96e 63/// \cond CLASSIMP
21dd83fc 64ClassImp(AliMUONGeometryMisAligner)
a9aad96e 65/// \endcond
66
21dd83fc 67//______________________________________________________________________________
328e160e 68AliMUONGeometryMisAligner::AliMUONGeometryMisAligner(Double_t cartXMisAligM, Double_t cartXMisAligW, Double_t cartYMisAligM, Double_t cartYMisAligW, Double_t angMisAligM, Double_t angMisAligW)
8395bff1 69 : TObject(),
70 fUseUni(kFALSE),
71 fUseGaus(kTRUE),
8395bff1 72 fXYAngMisAligFactor(0.0),
73 fZCartMisAligFactor(0.0),
74 fDisplacementGenerator(0)
328e160e 75{
76 /// Standard constructor
4600314b 77 for (Int_t i=0; i<6; i++){
78 for (Int_t j=0; j<2; j++){
79 fDetElemMisAlig[i][j] = 0.0;
80 fModuleMisAlig[i][j] = 0.0;
81 }
82 }
83 fDetElemMisAlig[0][0] = cartXMisAligM;
84 fDetElemMisAlig[0][1] = cartXMisAligW;
85 fDetElemMisAlig[1][0] = cartYMisAligM;
86 fDetElemMisAlig[1][1] = cartYMisAligW;
87 fDetElemMisAlig[5][0] = angMisAligM;
88 fDetElemMisAlig[5][1] = angMisAligW;
89
328e160e 90 fDisplacementGenerator = new TRandom(0);
328e160e 91}
92
93//______________________________________________________________________________
94AliMUONGeometryMisAligner::AliMUONGeometryMisAligner(Double_t cartMisAligM, Double_t cartMisAligW, Double_t angMisAligM, Double_t angMisAligW)
8395bff1 95 : TObject(),
96 fUseUni(kFALSE),
97 fUseGaus(kTRUE),
8395bff1 98 fXYAngMisAligFactor(0.0),
99 fZCartMisAligFactor(0.0),
100 fDisplacementGenerator(0)
328e160e 101{
102 /// Standard constructor
4600314b 103 for (Int_t i=0; i<6; i++){
104 for (Int_t j=0; j<2; j++){
105 fDetElemMisAlig[i][j] = 0.0;
106 fModuleMisAlig[i][j] = 0.0;
107 }
108 }
109 fDetElemMisAlig[0][0] = cartMisAligM;
110 fDetElemMisAlig[0][1] = cartMisAligW;
111 fDetElemMisAlig[1][0] = cartMisAligM;
112 fDetElemMisAlig[1][1] = cartMisAligW;
113 fDetElemMisAlig[5][0] = angMisAligM;
114 fDetElemMisAlig[5][1] = angMisAligW;
115
328e160e 116 fDisplacementGenerator = new TRandom(0);
328e160e 117}
118
119//______________________________________________________________________________
21dd83fc 120AliMUONGeometryMisAligner::AliMUONGeometryMisAligner(Double_t cartMisAlig, Double_t angMisAlig)
8395bff1 121 : TObject(),
122 fUseUni(kTRUE),
123 fUseGaus(kFALSE),
8395bff1 124 fXYAngMisAligFactor(0.0),
125 fZCartMisAligFactor(0.0),
126 fDisplacementGenerator(0)
21dd83fc 127{
128 /// Standard constructor
4600314b 129 for (Int_t i=0; i<6; i++){
130 for (Int_t j=0; j<2; j++){
131 fDetElemMisAlig[i][j] = 0.0;
132 fModuleMisAlig[i][j] = 0.0;
133 }
134 }
135 fDetElemMisAlig[0][1] = cartMisAlig;
136 fDetElemMisAlig[1][1] = cartMisAlig;
137 fDetElemMisAlig[5][1] = angMisAlig;
138
21dd83fc 139 fDisplacementGenerator = new TRandom(0);
140}
141
142//_____________________________________________________________________________
143AliMUONGeometryMisAligner::AliMUONGeometryMisAligner()
8395bff1 144 : TObject(),
145 fUseUni(kTRUE),
146 fUseGaus(kFALSE),
8395bff1 147 fXYAngMisAligFactor(0.0),
148 fZCartMisAligFactor(0.0),
149 fDisplacementGenerator(0)
21dd83fc 150{
8395bff1 151 /// Default constructor
4600314b 152 for (Int_t i=0; i<6; i++){
153 for (Int_t j=0; j<2; j++){
154 fDetElemMisAlig[i][j] = 0.0;
155 fModuleMisAlig[i][j] = 0.0;
156 }
157 }
21dd83fc 158}
159
160//______________________________________________________________________________
21dd83fc 161AliMUONGeometryMisAligner::~AliMUONGeometryMisAligner()
162{
163/// Destructor
164
8395bff1 165 if (fDisplacementGenerator) delete fDisplacementGenerator;
21dd83fc 166}
167
490da820 168//_________________________________________________________________________
21dd83fc 169void
170AliMUONGeometryMisAligner::SetXYAngMisAligFactor(Double_t factor)
171{
328e160e 172 /// Set XY angular misalign factor
490da820 173
4600314b 174 if (TMath::Abs(factor) > 1.0 && factor > 0.){
21dd83fc 175 fXYAngMisAligFactor = factor;
4600314b 176 fDetElemMisAlig[3][0] = fDetElemMisAlig[5][0]*factor; // These lines were
177 fDetElemMisAlig[3][1] = fDetElemMisAlig[5][1]*factor; // added to keep
178 fDetElemMisAlig[4][0] = fDetElemMisAlig[5][0]*factor; // backward
179 fDetElemMisAlig[4][1] = fDetElemMisAlig[5][1]*factor; // compatibility
180 }
21dd83fc 181 else
328e160e 182 AliError(Form("Invalid XY angular misalign factor, %d", factor));
183}
184
185//_________________________________________________________________________
186void AliMUONGeometryMisAligner::SetZCartMisAligFactor(Double_t factor)
187{
188 /// Set XY angular misalign factor
4600314b 189 if (TMath::Abs(factor)<1.0 && factor>0.) {
328e160e 190 fZCartMisAligFactor = factor;
4600314b 191 fDetElemMisAlig[2][0] = fDetElemMisAlig[0][0]; // These lines were added to
192 fDetElemMisAlig[2][1] = fDetElemMisAlig[0][1]*factor; // keep backward compatibility
193 }
328e160e 194 else
195 AliError(Form("Invalid Z cartesian misalign factor, %d", factor));
196}
197
198//_________________________________________________________________________
4600314b 199void AliMUONGeometryMisAligner::GetUniMisAlign(Double_t cartMisAlig[3], Double_t angMisAlig[3], const Double_t lParMisAlig[6][2]) const
328e160e 200{
201 /// Misalign using uniform distribution
a9aad96e 202 /**
328e160e 203 misalign the centre of the local transformation
204 rotation axes :
205 fAngMisAlig[1,2,3] = [x,y,z]
206 Assume that misalignment about the x and y axes (misalignment of z plane)
207 is much smaller, since the entire detection plane has to be moved (the
208 detection elements are on a support structure), while rotation of the x-y
209 plane is more free.
210 */
4600314b 211 cartMisAlig[0] = fDisplacementGenerator->Uniform(-lParMisAlig[0][1]+lParMisAlig[0][0], lParMisAlig[0][0]+lParMisAlig[0][1]);
212 cartMisAlig[1] = fDisplacementGenerator->Uniform(-lParMisAlig[1][1]+lParMisAlig[1][0], lParMisAlig[1][0]+lParMisAlig[1][1]);
213 cartMisAlig[2] = fDisplacementGenerator->Uniform(-lParMisAlig[2][1]+lParMisAlig[2][0], lParMisAlig[2][0]+lParMisAlig[2][1]);
328e160e 214
4600314b 215 angMisAlig[0] = fDisplacementGenerator->Uniform(-lParMisAlig[3][1]+lParMisAlig[3][0], lParMisAlig[3][0]+lParMisAlig[3][1]);
216 angMisAlig[1] = fDisplacementGenerator->Uniform(-lParMisAlig[4][1]+lParMisAlig[4][0], lParMisAlig[4][0]+lParMisAlig[4][1]);
217 angMisAlig[2] = fDisplacementGenerator->Uniform(-lParMisAlig[5][1]+lParMisAlig[5][0], lParMisAlig[5][0]+lParMisAlig[5][1]); // degrees
328e160e 218}
219
220//_________________________________________________________________________
4600314b 221void AliMUONGeometryMisAligner::GetGausMisAlign(Double_t cartMisAlig[3], Double_t angMisAlig[3], const Double_t lParMisAlig[6][2]) const
328e160e 222{
223 /// Misalign using gaussian distribution
a9aad96e 224 /**
328e160e 225 misalign the centre of the local transformation
226 rotation axes :
227 fAngMisAlig[1,2,3] = [x,y,z]
228 Assume that misalignment about the x and y axes (misalignment of z plane)
229 is much smaller, since the entire detection plane has to be moved (the
230 detection elements are on a support structure), while rotation of the x-y
231 plane is more free.
232 */
4600314b 233 cartMisAlig[0] = fDisplacementGenerator->Gaus(lParMisAlig[0][0], lParMisAlig[0][1]);
234 cartMisAlig[1] = fDisplacementGenerator->Gaus(lParMisAlig[1][0], lParMisAlig[1][1]);
235 cartMisAlig[2] = fDisplacementGenerator->Gaus(lParMisAlig[2][0], lParMisAlig[2][1]);
328e160e 236
4600314b 237 angMisAlig[0] = fDisplacementGenerator->Gaus(lParMisAlig[3][0], lParMisAlig[3][1]);
238 angMisAlig[1] = fDisplacementGenerator->Gaus(lParMisAlig[4][0], lParMisAlig[4][1]);
239 angMisAlig[2] = fDisplacementGenerator->Gaus(lParMisAlig[5][0], lParMisAlig[5][1]); // degrees
21dd83fc 240}
241
242//_________________________________________________________________________
4600314b 243TGeoCombiTrans AliMUONGeometryMisAligner::MisAlignDetElem(const TGeoCombiTrans & transform) const
21dd83fc 244{
4600314b 245 /// Misalign given transformation and return the misaligned transformation.
246 /// Use misalignment parameters for detection elements.
247 /// Note that applied misalignments are small deltas with respect to the detection
248 /// element own ideal local reference frame. Thus deltaTransf represents
249 /// the transformation to go from the misaligned d.e. local coordinates to the
250 /// ideal d.e. local coordinates.
251 /// Also note that this -is not- what is in the ALICE alignment framework known
252 /// as local nor global (see AliMUONGeometryMisAligner::MisAlign)
21dd83fc 253
254 Double_t cartMisAlig[3] = {0,0,0};
255 Double_t angMisAlig[3] = {0,0,0};
328e160e 256
257 if (fUseUni) {
4600314b 258 GetUniMisAlign(cartMisAlig,angMisAlig,fDetElemMisAlig);
328e160e 259 }
260 else {
261 if (!fUseGaus) {
262 AliWarning("Neither uniform nor gausian distribution is set! Will use gausian...");
263 }
4600314b 264 GetGausMisAlign(cartMisAlig,angMisAlig,fDetElemMisAlig);
328e160e 265 }
266
4600314b 267 TGeoTranslation deltaTrans(cartMisAlig[0], cartMisAlig[1], cartMisAlig[2]);
268 TGeoRotation deltaRot;
269 deltaRot.RotateX(angMisAlig[0]);
270 deltaRot.RotateY(angMisAlig[1]);
271 deltaRot.RotateZ(angMisAlig[2]);
272
273 TGeoCombiTrans deltaTransf(deltaTrans,deltaRot);
274 TGeoHMatrix newTransfMat = transform * deltaTransf;
275
ef4cb4f1 276 AliInfo(Form("Rotated DE by %f about Z axis.", angMisAlig[2]));
4600314b 277
278 return TGeoCombiTrans(newTransfMat);
279}
280
281//_________________________________________________________________________
282TGeoCombiTrans AliMUONGeometryMisAligner::MisAlignModule(const TGeoCombiTrans & transform) const
283{
284 /// Misalign given transformation and return the misaligned transformation.
285 /// Use misalignment parameters for modules.
286 /// Note that applied misalignments are small deltas with respect to the module
287 /// own ideal local reference frame. Thus deltaTransf represents
288 /// the transformation to go from the misaligned module local coordinates to the
289 /// ideal module local coordinates.
290 /// Also note that this -is not- what is in the ALICE alignment framework known
291 /// as local nor global (see AliMUONGeometryMisAligner::MisAlign)
21dd83fc 292
4600314b 293 Double_t cartMisAlig[3] = {0,0,0};
294 Double_t angMisAlig[3] = {0,0,0};
295
296 if (fUseUni) {
297 GetUniMisAlign(cartMisAlig,angMisAlig,fModuleMisAlig);
298 }
299 else {
300 if (!fUseGaus) {
301 AliWarning("Neither uniform nor gausian distribution is set! Will use gausian...");
302 }
303 GetGausMisAlign(cartMisAlig,angMisAlig,fModuleMisAlig);
304 }
305
306 TGeoTranslation deltaTrans(cartMisAlig[0], cartMisAlig[1], cartMisAlig[2]);
307 TGeoRotation deltaRot;
308 deltaRot.RotateX(angMisAlig[0]);
309 deltaRot.RotateY(angMisAlig[1]);
310 deltaRot.RotateZ(angMisAlig[2]);
21dd83fc 311
4600314b 312 TGeoCombiTrans deltaTransf(deltaTrans,deltaRot);
313 TGeoHMatrix newTransfMat = transform * deltaTransf;
314
315 AliInfo(Form("Rotated Module by %f about Z axis.", angMisAlig[2]));
316
317 return TGeoCombiTrans(newTransfMat);
21dd83fc 318}
319
21dd83fc 320//______________________________________________________________________
321AliMUONGeometryTransformer *
322AliMUONGeometryMisAligner::MisAlign(const AliMUONGeometryTransformer *
4600314b 323 transformer, Bool_t verbose)
21dd83fc 324{
4600314b 325 /// Takes the internal geometry module transformers, copies them to
326 /// new geometry module transformers.
327 /// Calculates module misalignment parameters and applies these
328 /// to the new module transformer.
329 /// Calculates the module misalignment delta transformation in the
330 /// Alice Alignment Framework newTransf = delta * oldTransf.
331 /// Add a module misalignment to the new geometry transformer.
332 /// Gets the Detection Elements from the module transformer.
a9aad96e 333 /// Calculates misalignment parameters and applies these
4600314b 334 /// to the local transformation of the Detection Element.
335 /// Obtains the new global transformation by multiplying the new
336 /// module transformer transformation with the new local transformation.
337 /// Applies the new global transform to a new detection element.
338 /// Adds the new detection element to a new module transformer.
339 /// Calculates the d.e. misalignment delta transformation in the
340 /// Alice Alignment Framework (newGlobalTransf = delta * oldGlobalTransf).
341 /// Add a d.e. misalignment to the new geometry transformer.
342 /// Adds the new module transformer to a new geometry transformer.
343 /// Returns the new geometry transformer.
21dd83fc 344
345
346 AliMUONGeometryTransformer *newGeometryTransformer =
ef4cb4f1 347 new AliMUONGeometryTransformer();
21dd83fc 348 for (Int_t iMt = 0; iMt < transformer->GetNofModuleTransformers(); iMt++)
349 { // module transformers
21dd83fc 350 const AliMUONGeometryModuleTransformer *kModuleTransformer =
351 transformer->GetModuleTransformer(iMt, true);
352
353 AliMUONGeometryModuleTransformer *newModuleTransformer =
354 new AliMUONGeometryModuleTransformer(iMt);
355 newGeometryTransformer->AddModuleTransformer(newModuleTransformer);
356
ef79ed3a 357 TGeoCombiTrans moduleTransform =
358 TGeoCombiTrans(*kModuleTransformer->GetTransformation());
4600314b 359 // New module transformation
360 TGeoCombiTrans newModuleTransform = MisAlignModule(moduleTransform);
361 newModuleTransformer->SetTransformation(newModuleTransform);
362
363 // Get delta transformation:
364 // Tdelta = Tnew * Told.inverse
365 TGeoHMatrix deltaModuleTransform =
366 AliMUONGeometryBuilder::Multiply(
367 newModuleTransform,
368 kModuleTransformer->GetTransformation()->Inverse());
369
370 // Create module mis alignment matrix
371 newGeometryTransformer
372 ->AddMisAlignModule(kModuleTransformer->GetModuleId(), deltaModuleTransform);
21dd83fc 373
8c95578a 374 AliMpExMap *detElements = kModuleTransformer->GetDetElementStore();
21dd83fc 375
376 if (verbose)
4600314b 377 AliInfo(Form("%i DEs in old GeometryStore %i",detElements->GetSize(), iMt));
21dd83fc 378
630711ed 379 TIter next(detElements->CreateIterator());
380 AliMUONGeometryDetElement *detElement;
381
382 while ( ( detElement = static_cast<AliMUONGeometryDetElement*>(next()) ) )
383 {
ef79ed3a 384 /// make a new detection element
21dd83fc 385 AliMUONGeometryDetElement *newDetElement =
386 new AliMUONGeometryDetElement(detElement->GetId(),
ef79ed3a 387 detElement->GetVolumePath());
21dd83fc 388
ef79ed3a 389 // local transformation of this detection element.
390 TGeoCombiTrans localTransform
391 = TGeoCombiTrans(*detElement->GetLocalTransformation());
4600314b 392 TGeoCombiTrans newLocalTransform = MisAlignDetElem(localTransform);
393 newDetElement->SetLocalTransformation(newLocalTransform);
394
21dd83fc 395
ef79ed3a 396 // global transformation
397 TGeoHMatrix newGlobalTransform =
4600314b 398 AliMUONGeometryBuilder::Multiply(newModuleTransform,
399 newLocalTransform);
21dd83fc 400 newDetElement->SetGlobalTransformation(newGlobalTransform);
ef79ed3a 401
402 // add this det element to module
403 newModuleTransformer->GetDetElementStore()->Add(newDetElement->GetId(),
21dd83fc 404 newDetElement);
4600314b 405
406 // In the Alice Alignment Framework misalignment objects store
407 // global delta transformation
408 // Get detection "intermediate" global transformation
409 TGeoHMatrix newOldGlobalTransform = newModuleTransform * localTransform;
410 // Get detection element global delta transformation:
ef79ed3a 411 // Tdelta = Tnew * Told.inverse
4600314b 412 TGeoHMatrix deltaGlobalTransform
ef79ed3a 413 = AliMUONGeometryBuilder::Multiply(
414 newGlobalTransform,
4600314b 415 newOldGlobalTransform.Inverse());
ef79ed3a 416
417 // Create mis alignment matrix
418 newGeometryTransformer
4600314b 419 ->AddMisAlignDetElement(detElement->GetId(), deltaGlobalTransform);
21dd83fc 420 }
4600314b 421
422
21dd83fc 423 if (verbose)
424 AliInfo(Form("Added module transformer %i to the transformer", iMt));
425 newGeometryTransformer->AddModuleTransformer(newModuleTransformer);
426 }
427 return newGeometryTransformer;
428}
429
430
431
432