]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONGeometryMisAligner.cxx
Added functionality to generate module misalignments
[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//
21dd83fc 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
21dd83fc 45
21dd83fc 46#include "AliMUONGeometryMisAligner.h"
47#include "AliMUONGeometryTransformer.h"
48#include "AliMUONGeometryModuleTransformer.h"
49#include "AliMUONGeometryDetElement.h"
21dd83fc 50#include "AliMUONGeometryBuilder.h"
ef79ed3a 51
8c95578a 52#include "AliMpExMap.h"
53
ef79ed3a 54#include "AliLog.h"
55
328e160e 56#include <TGeoMatrix.h>
21dd83fc 57#include <TMath.h>
58#include <TRandom.h>
59
a9aad96e 60/// \cond CLASSIMP
21dd83fc 61ClassImp(AliMUONGeometryMisAligner)
a9aad96e 62/// \endcond
63
328e160e 64//______________________________________________________________________________
65AliMUONGeometryMisAligner::AliMUONGeometryMisAligner(Double_t cartXMisAligM, Double_t cartXMisAligW, Double_t cartYMisAligM, Double_t cartYMisAligW, Double_t angMisAligM, Double_t angMisAligW)
8395bff1 66 : TObject(),
67 fUseUni(kFALSE),
68 fUseGaus(kTRUE),
8395bff1 69 fXYAngMisAligFactor(0.0),
70 fZCartMisAligFactor(0.0),
71 fDisplacementGenerator(0)
328e160e 72{
73 /// Standard constructor
4600314b 74 for (Int_t i=0; i<6; i++){
75 for (Int_t j=0; j<2; j++){
76 fDetElemMisAlig[i][j] = 0.0;
77 fModuleMisAlig[i][j] = 0.0;
78 }
79 }
80 fDetElemMisAlig[0][0] = cartXMisAligM;
81 fDetElemMisAlig[0][1] = cartXMisAligW;
82 fDetElemMisAlig[1][0] = cartYMisAligM;
83 fDetElemMisAlig[1][1] = cartYMisAligW;
84 fDetElemMisAlig[5][0] = angMisAligM;
85 fDetElemMisAlig[5][1] = angMisAligW;
86
328e160e 87 fDisplacementGenerator = new TRandom(0);
328e160e 88}
89
90//______________________________________________________________________________
91AliMUONGeometryMisAligner::AliMUONGeometryMisAligner(Double_t cartMisAligM, Double_t cartMisAligW, Double_t angMisAligM, Double_t angMisAligW)
8395bff1 92 : TObject(),
93 fUseUni(kFALSE),
94 fUseGaus(kTRUE),
8395bff1 95 fXYAngMisAligFactor(0.0),
96 fZCartMisAligFactor(0.0),
97 fDisplacementGenerator(0)
328e160e 98{
99 /// Standard constructor
4600314b 100 for (Int_t i=0; i<6; i++){
101 for (Int_t j=0; j<2; j++){
102 fDetElemMisAlig[i][j] = 0.0;
103 fModuleMisAlig[i][j] = 0.0;
104 }
105 }
106 fDetElemMisAlig[0][0] = cartMisAligM;
107 fDetElemMisAlig[0][1] = cartMisAligW;
108 fDetElemMisAlig[1][0] = cartMisAligM;
109 fDetElemMisAlig[1][1] = cartMisAligW;
110 fDetElemMisAlig[5][0] = angMisAligM;
111 fDetElemMisAlig[5][1] = angMisAligW;
112
328e160e 113 fDisplacementGenerator = new TRandom(0);
328e160e 114}
115
21dd83fc 116//______________________________________________________________________________
117AliMUONGeometryMisAligner::AliMUONGeometryMisAligner(Double_t cartMisAlig, Double_t angMisAlig)
8395bff1 118 : TObject(),
119 fUseUni(kTRUE),
120 fUseGaus(kFALSE),
8395bff1 121 fXYAngMisAligFactor(0.0),
122 fZCartMisAligFactor(0.0),
123 fDisplacementGenerator(0)
21dd83fc 124{
125 /// Standard constructor
4600314b 126 for (Int_t i=0; i<6; i++){
127 for (Int_t j=0; j<2; j++){
128 fDetElemMisAlig[i][j] = 0.0;
129 fModuleMisAlig[i][j] = 0.0;
130 }
131 }
132 fDetElemMisAlig[0][1] = cartMisAlig;
133 fDetElemMisAlig[1][1] = cartMisAlig;
134 fDetElemMisAlig[5][1] = angMisAlig;
135
21dd83fc 136 fDisplacementGenerator = new TRandom(0);
137}
138
139//_____________________________________________________________________________
140AliMUONGeometryMisAligner::AliMUONGeometryMisAligner()
8395bff1 141 : TObject(),
142 fUseUni(kTRUE),
143 fUseGaus(kFALSE),
8395bff1 144 fXYAngMisAligFactor(0.0),
145 fZCartMisAligFactor(0.0),
146 fDisplacementGenerator(0)
21dd83fc 147{
8395bff1 148 /// Default constructor
4600314b 149 for (Int_t i=0; i<6; i++){
150 for (Int_t j=0; j<2; j++){
151 fDetElemMisAlig[i][j] = 0.0;
152 fModuleMisAlig[i][j] = 0.0;
153 }
154 }
21dd83fc 155}
156
21dd83fc 157//______________________________________________________________________________
158AliMUONGeometryMisAligner::~AliMUONGeometryMisAligner()
159{
160/// Destructor
161
8395bff1 162 if (fDisplacementGenerator) delete fDisplacementGenerator;
21dd83fc 163}
164
490da820 165//_________________________________________________________________________
21dd83fc 166void
167AliMUONGeometryMisAligner::SetXYAngMisAligFactor(Double_t factor)
168{
328e160e 169 /// Set XY angular misalign factor
490da820 170
4600314b 171 if (TMath::Abs(factor) > 1.0 && factor > 0.){
21dd83fc 172 fXYAngMisAligFactor = factor;
4600314b 173 fDetElemMisAlig[3][0] = fDetElemMisAlig[5][0]*factor; // These lines were
174 fDetElemMisAlig[3][1] = fDetElemMisAlig[5][1]*factor; // added to keep
175 fDetElemMisAlig[4][0] = fDetElemMisAlig[5][0]*factor; // backward
176 fDetElemMisAlig[4][1] = fDetElemMisAlig[5][1]*factor; // compatibility
177 }
21dd83fc 178 else
328e160e 179 AliError(Form("Invalid XY angular misalign factor, %d", factor));
180}
181
182//_________________________________________________________________________
183void AliMUONGeometryMisAligner::SetZCartMisAligFactor(Double_t factor)
184{
185 /// Set XY angular misalign factor
4600314b 186 if (TMath::Abs(factor)<1.0 && factor>0.) {
328e160e 187 fZCartMisAligFactor = factor;
4600314b 188 fDetElemMisAlig[2][0] = fDetElemMisAlig[0][0]; // These lines were added to
189 fDetElemMisAlig[2][1] = fDetElemMisAlig[0][1]*factor; // keep backward compatibility
190 }
328e160e 191 else
192 AliError(Form("Invalid Z cartesian misalign factor, %d", factor));
193}
194
195//_________________________________________________________________________
4600314b 196void AliMUONGeometryMisAligner::GetUniMisAlign(Double_t cartMisAlig[3], Double_t angMisAlig[3], const Double_t lParMisAlig[6][2]) const
328e160e 197{
198 /// Misalign using uniform distribution
a9aad96e 199 /**
328e160e 200 misalign the centre of the local transformation
201 rotation axes :
202 fAngMisAlig[1,2,3] = [x,y,z]
203 Assume that misalignment about the x and y axes (misalignment of z plane)
204 is much smaller, since the entire detection plane has to be moved (the
205 detection elements are on a support structure), while rotation of the x-y
206 plane is more free.
207 */
4600314b 208 cartMisAlig[0] = fDisplacementGenerator->Uniform(-lParMisAlig[0][1]+lParMisAlig[0][0], lParMisAlig[0][0]+lParMisAlig[0][1]);
209 cartMisAlig[1] = fDisplacementGenerator->Uniform(-lParMisAlig[1][1]+lParMisAlig[1][0], lParMisAlig[1][0]+lParMisAlig[1][1]);
210 cartMisAlig[2] = fDisplacementGenerator->Uniform(-lParMisAlig[2][1]+lParMisAlig[2][0], lParMisAlig[2][0]+lParMisAlig[2][1]);
328e160e 211
4600314b 212 angMisAlig[0] = fDisplacementGenerator->Uniform(-lParMisAlig[3][1]+lParMisAlig[3][0], lParMisAlig[3][0]+lParMisAlig[3][1]);
213 angMisAlig[1] = fDisplacementGenerator->Uniform(-lParMisAlig[4][1]+lParMisAlig[4][0], lParMisAlig[4][0]+lParMisAlig[4][1]);
214 angMisAlig[2] = fDisplacementGenerator->Uniform(-lParMisAlig[5][1]+lParMisAlig[5][0], lParMisAlig[5][0]+lParMisAlig[5][1]); // degrees
328e160e 215}
216
217//_________________________________________________________________________
4600314b 218void AliMUONGeometryMisAligner::GetGausMisAlign(Double_t cartMisAlig[3], Double_t angMisAlig[3], const Double_t lParMisAlig[6][2]) const
328e160e 219{
220 /// Misalign using gaussian distribution
a9aad96e 221 /**
328e160e 222 misalign the centre of the local transformation
223 rotation axes :
224 fAngMisAlig[1,2,3] = [x,y,z]
225 Assume that misalignment about the x and y axes (misalignment of z plane)
226 is much smaller, since the entire detection plane has to be moved (the
227 detection elements are on a support structure), while rotation of the x-y
228 plane is more free.
229 */
4600314b 230 cartMisAlig[0] = fDisplacementGenerator->Gaus(lParMisAlig[0][0], lParMisAlig[0][1]);
231 cartMisAlig[1] = fDisplacementGenerator->Gaus(lParMisAlig[1][0], lParMisAlig[1][1]);
232 cartMisAlig[2] = fDisplacementGenerator->Gaus(lParMisAlig[2][0], lParMisAlig[2][1]);
328e160e 233
4600314b 234 angMisAlig[0] = fDisplacementGenerator->Gaus(lParMisAlig[3][0], lParMisAlig[3][1]);
235 angMisAlig[1] = fDisplacementGenerator->Gaus(lParMisAlig[4][0], lParMisAlig[4][1]);
236 angMisAlig[2] = fDisplacementGenerator->Gaus(lParMisAlig[5][0], lParMisAlig[5][1]); // degrees
21dd83fc 237}
238
239//_________________________________________________________________________
4600314b 240TGeoCombiTrans AliMUONGeometryMisAligner::MisAlignDetElem(const TGeoCombiTrans & transform) const
21dd83fc 241{
4600314b 242 /// Misalign given transformation and return the misaligned transformation.
243 /// Use misalignment parameters for detection elements.
244 /// Note that applied misalignments are small deltas with respect to the detection
245 /// element own ideal local reference frame. Thus deltaTransf represents
246 /// the transformation to go from the misaligned d.e. local coordinates to the
247 /// ideal d.e. local coordinates.
248 /// Also note that this -is not- what is in the ALICE alignment framework known
249 /// as local nor global (see AliMUONGeometryMisAligner::MisAlign)
21dd83fc 250
251 Double_t cartMisAlig[3] = {0,0,0};
252 Double_t angMisAlig[3] = {0,0,0};
328e160e 253
254 if (fUseUni) {
4600314b 255 GetUniMisAlign(cartMisAlig,angMisAlig,fDetElemMisAlig);
328e160e 256 }
257 else {
258 if (!fUseGaus) {
259 AliWarning("Neither uniform nor gausian distribution is set! Will use gausian...");
260 }
4600314b 261 GetGausMisAlign(cartMisAlig,angMisAlig,fDetElemMisAlig);
328e160e 262 }
263
4600314b 264 TGeoTranslation deltaTrans(cartMisAlig[0], cartMisAlig[1], cartMisAlig[2]);
265 TGeoRotation deltaRot;
266 deltaRot.RotateX(angMisAlig[0]);
267 deltaRot.RotateY(angMisAlig[1]);
268 deltaRot.RotateZ(angMisAlig[2]);
269
270 TGeoCombiTrans deltaTransf(deltaTrans,deltaRot);
271 TGeoHMatrix newTransfMat = transform * deltaTransf;
272
273 AliInfo(Form("Rotated Module by %f about Z axis.", angMisAlig[2]));
274
275 return TGeoCombiTrans(newTransfMat);
276}
277
278//_________________________________________________________________________
279TGeoCombiTrans AliMUONGeometryMisAligner::MisAlignModule(const TGeoCombiTrans & transform) const
280{
281 /// Misalign given transformation and return the misaligned transformation.
282 /// Use misalignment parameters for modules.
283 /// Note that applied misalignments are small deltas with respect to the module
284 /// own ideal local reference frame. Thus deltaTransf represents
285 /// the transformation to go from the misaligned module local coordinates to the
286 /// ideal module local coordinates.
287 /// Also note that this -is not- what is in the ALICE alignment framework known
288 /// as local nor global (see AliMUONGeometryMisAligner::MisAlign)
21dd83fc 289
4600314b 290 Double_t cartMisAlig[3] = {0,0,0};
291 Double_t angMisAlig[3] = {0,0,0};
292
293 if (fUseUni) {
294 GetUniMisAlign(cartMisAlig,angMisAlig,fModuleMisAlig);
295 }
296 else {
297 if (!fUseGaus) {
298 AliWarning("Neither uniform nor gausian distribution is set! Will use gausian...");
299 }
300 GetGausMisAlign(cartMisAlig,angMisAlig,fModuleMisAlig);
301 }
302
303 TGeoTranslation deltaTrans(cartMisAlig[0], cartMisAlig[1], cartMisAlig[2]);
304 TGeoRotation deltaRot;
305 deltaRot.RotateX(angMisAlig[0]);
306 deltaRot.RotateY(angMisAlig[1]);
307 deltaRot.RotateZ(angMisAlig[2]);
21dd83fc 308
4600314b 309 TGeoCombiTrans deltaTransf(deltaTrans,deltaRot);
310 TGeoHMatrix newTransfMat = transform * deltaTransf;
311
312 AliInfo(Form("Rotated Module by %f about Z axis.", angMisAlig[2]));
313
314 return TGeoCombiTrans(newTransfMat);
21dd83fc 315}
316
21dd83fc 317//______________________________________________________________________
318AliMUONGeometryTransformer *
319AliMUONGeometryMisAligner::MisAlign(const AliMUONGeometryTransformer *
4600314b 320 transformer, Bool_t verbose)
21dd83fc 321{
4600314b 322 /// Takes the internal geometry module transformers, copies them to
323 /// new geometry module transformers.
324 /// Calculates module misalignment parameters and applies these
325 /// to the new module transformer.
326 /// Calculates the module misalignment delta transformation in the
327 /// Alice Alignment Framework newTransf = delta * oldTransf.
328 /// Add a module misalignment to the new geometry transformer.
329 /// Gets the Detection Elements from the module transformer.
a9aad96e 330 /// Calculates misalignment parameters and applies these
4600314b 331 /// to the local transformation of the Detection Element.
332 /// Obtains the new global transformation by multiplying the new
333 /// module transformer transformation with the new local transformation.
334 /// Applies the new global transform to a new detection element.
335 /// Adds the new detection element to a new module transformer.
336 /// Calculates the d.e. misalignment delta transformation in the
337 /// Alice Alignment Framework (newGlobalTransf = delta * oldGlobalTransf).
338 /// Add a d.e. misalignment to the new geometry transformer.
339 /// Adds the new module transformer to a new geometry transformer.
340 /// Returns the new geometry transformer.
21dd83fc 341
342
343 AliMUONGeometryTransformer *newGeometryTransformer =
344 new AliMUONGeometryTransformer(kTRUE);
345 for (Int_t iMt = 0; iMt < transformer->GetNofModuleTransformers(); iMt++)
346 { // module transformers
21dd83fc 347 const AliMUONGeometryModuleTransformer *kModuleTransformer =
348 transformer->GetModuleTransformer(iMt, true);
349
350 AliMUONGeometryModuleTransformer *newModuleTransformer =
351 new AliMUONGeometryModuleTransformer(iMt);
352 newGeometryTransformer->AddModuleTransformer(newModuleTransformer);
353
ef79ed3a 354 TGeoCombiTrans moduleTransform =
355 TGeoCombiTrans(*kModuleTransformer->GetTransformation());
4600314b 356 // New module transformation
357 TGeoCombiTrans newModuleTransform = MisAlignModule(moduleTransform);
358 newModuleTransformer->SetTransformation(newModuleTransform);
359
360 // Get delta transformation:
361 // Tdelta = Tnew * Told.inverse
362 TGeoHMatrix deltaModuleTransform =
363 AliMUONGeometryBuilder::Multiply(
364 newModuleTransform,
365 kModuleTransformer->GetTransformation()->Inverse());
366
367 // Create module mis alignment matrix
368 newGeometryTransformer
369 ->AddMisAlignModule(kModuleTransformer->GetModuleId(), deltaModuleTransform);
21dd83fc 370
8c95578a 371 AliMpExMap *detElements = kModuleTransformer->GetDetElementStore();
21dd83fc 372
373 if (verbose)
4600314b 374 AliInfo(Form("%i DEs in old GeometryStore %i",detElements->GetSize(), iMt));
21dd83fc 375
8c95578a 376 for (Int_t iDe = 0; iDe < detElements->GetSize(); iDe++)
21dd83fc 377 { // detection elements.
378 AliMUONGeometryDetElement *detElement =
8c95578a 379 (AliMUONGeometryDetElement *) detElements->GetObject(iDe);
4600314b 380
21dd83fc 381 if (!detElement)
382 AliFatal("Detection element not found.");
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