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. *
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 **************************************************************************/
18 //__________________________________________________________________
19 /// \class AliMUONGeometryMisAligner
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
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)
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
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.
44 /// \author Bruce Becker, Javier Castillo
46 #include "AliMUONGeometryMisAligner.h"
47 #include "AliMUONGeometryTransformer.h"
48 #include "AliMUONGeometryModuleTransformer.h"
49 #include "AliMUONGeometryDetElement.h"
50 #include "AliMUONGeometryBuilder.h"
52 #include "AliMpExMap.h"
56 #include <TGeoMatrix.h>
61 ClassImp(AliMUONGeometryMisAligner)
64 //______________________________________________________________________________
65 AliMUONGeometryMisAligner::AliMUONGeometryMisAligner(Double_t cartXMisAligM, Double_t cartXMisAligW, Double_t cartYMisAligM, Double_t cartYMisAligW, Double_t angMisAligM, Double_t angMisAligW)
69 fXYAngMisAligFactor(0.0),
70 fZCartMisAligFactor(0.0),
71 fDisplacementGenerator(0)
73 /// Standard constructor
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;
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;
87 fDisplacementGenerator = new TRandom(0);
90 //______________________________________________________________________________
91 AliMUONGeometryMisAligner::AliMUONGeometryMisAligner(Double_t cartMisAligM, Double_t cartMisAligW, Double_t angMisAligM, Double_t angMisAligW)
95 fXYAngMisAligFactor(0.0),
96 fZCartMisAligFactor(0.0),
97 fDisplacementGenerator(0)
99 /// Standard constructor
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;
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;
113 fDisplacementGenerator = new TRandom(0);
116 //______________________________________________________________________________
117 AliMUONGeometryMisAligner::AliMUONGeometryMisAligner(Double_t cartMisAlig, Double_t angMisAlig)
121 fXYAngMisAligFactor(0.0),
122 fZCartMisAligFactor(0.0),
123 fDisplacementGenerator(0)
125 /// Standard constructor
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;
132 fDetElemMisAlig[0][1] = cartMisAlig;
133 fDetElemMisAlig[1][1] = cartMisAlig;
134 fDetElemMisAlig[5][1] = angMisAlig;
136 fDisplacementGenerator = new TRandom(0);
139 //_____________________________________________________________________________
140 AliMUONGeometryMisAligner::AliMUONGeometryMisAligner()
144 fXYAngMisAligFactor(0.0),
145 fZCartMisAligFactor(0.0),
146 fDisplacementGenerator(0)
148 /// Default constructor
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;
157 //______________________________________________________________________________
158 AliMUONGeometryMisAligner::~AliMUONGeometryMisAligner()
162 if (fDisplacementGenerator) delete fDisplacementGenerator;
165 //_________________________________________________________________________
167 AliMUONGeometryMisAligner::SetXYAngMisAligFactor(Double_t factor)
169 /// Set XY angular misalign factor
171 if (TMath::Abs(factor) > 1.0 && factor > 0.){
172 fXYAngMisAligFactor = factor;
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
179 AliError(Form("Invalid XY angular misalign factor, %d", factor));
182 //_________________________________________________________________________
183 void AliMUONGeometryMisAligner::SetZCartMisAligFactor(Double_t factor)
185 /// Set XY angular misalign factor
186 if (TMath::Abs(factor)<1.0 && factor>0.) {
187 fZCartMisAligFactor = factor;
188 fDetElemMisAlig[2][0] = fDetElemMisAlig[0][0]; // These lines were added to
189 fDetElemMisAlig[2][1] = fDetElemMisAlig[0][1]*factor; // keep backward compatibility
192 AliError(Form("Invalid Z cartesian misalign factor, %d", factor));
195 //_________________________________________________________________________
196 void AliMUONGeometryMisAligner::GetUniMisAlign(Double_t cartMisAlig[3], Double_t angMisAlig[3], const Double_t lParMisAlig[6][2]) const
198 /// Misalign using uniform distribution
200 misalign the centre of the local transformation
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
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]);
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
217 //_________________________________________________________________________
218 void AliMUONGeometryMisAligner::GetGausMisAlign(Double_t cartMisAlig[3], Double_t angMisAlig[3], const Double_t lParMisAlig[6][2]) const
220 /// Misalign using gaussian distribution
222 misalign the centre of the local transformation
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
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]);
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
239 //_________________________________________________________________________
240 TGeoCombiTrans AliMUONGeometryMisAligner::MisAlignDetElem(const TGeoCombiTrans & transform) const
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)
251 Double_t cartMisAlig[3] = {0,0,0};
252 Double_t angMisAlig[3] = {0,0,0};
255 GetUniMisAlign(cartMisAlig,angMisAlig,fDetElemMisAlig);
259 AliWarning("Neither uniform nor gausian distribution is set! Will use gausian...");
261 GetGausMisAlign(cartMisAlig,angMisAlig,fDetElemMisAlig);
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]);
270 TGeoCombiTrans deltaTransf(deltaTrans,deltaRot);
271 TGeoHMatrix newTransfMat = transform * deltaTransf;
273 AliInfo(Form("Rotated Module by %f about Z axis.", angMisAlig[2]));
275 return TGeoCombiTrans(newTransfMat);
278 //_________________________________________________________________________
279 TGeoCombiTrans AliMUONGeometryMisAligner::MisAlignModule(const TGeoCombiTrans & transform) const
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)
290 Double_t cartMisAlig[3] = {0,0,0};
291 Double_t angMisAlig[3] = {0,0,0};
294 GetUniMisAlign(cartMisAlig,angMisAlig,fModuleMisAlig);
298 AliWarning("Neither uniform nor gausian distribution is set! Will use gausian...");
300 GetGausMisAlign(cartMisAlig,angMisAlig,fModuleMisAlig);
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]);
309 TGeoCombiTrans deltaTransf(deltaTrans,deltaRot);
310 TGeoHMatrix newTransfMat = transform * deltaTransf;
312 AliInfo(Form("Rotated Module by %f about Z axis.", angMisAlig[2]));
314 return TGeoCombiTrans(newTransfMat);
317 //______________________________________________________________________
318 AliMUONGeometryTransformer *
319 AliMUONGeometryMisAligner::MisAlign(const AliMUONGeometryTransformer *
320 transformer, Bool_t verbose)
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.
330 /// Calculates misalignment parameters and applies these
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.
343 AliMUONGeometryTransformer *newGeometryTransformer =
344 new AliMUONGeometryTransformer(kTRUE);
345 for (Int_t iMt = 0; iMt < transformer->GetNofModuleTransformers(); iMt++)
346 { // module transformers
347 const AliMUONGeometryModuleTransformer *kModuleTransformer =
348 transformer->GetModuleTransformer(iMt, true);
350 AliMUONGeometryModuleTransformer *newModuleTransformer =
351 new AliMUONGeometryModuleTransformer(iMt);
352 newGeometryTransformer->AddModuleTransformer(newModuleTransformer);
354 TGeoCombiTrans moduleTransform =
355 TGeoCombiTrans(*kModuleTransformer->GetTransformation());
356 // New module transformation
357 TGeoCombiTrans newModuleTransform = MisAlignModule(moduleTransform);
358 newModuleTransformer->SetTransformation(newModuleTransform);
360 // Get delta transformation:
361 // Tdelta = Tnew * Told.inverse
362 TGeoHMatrix deltaModuleTransform =
363 AliMUONGeometryBuilder::Multiply(
365 kModuleTransformer->GetTransformation()->Inverse());
367 // Create module mis alignment matrix
368 newGeometryTransformer
369 ->AddMisAlignModule(kModuleTransformer->GetModuleId(), deltaModuleTransform);
371 AliMpExMap *detElements = kModuleTransformer->GetDetElementStore();
374 AliInfo(Form("%i DEs in old GeometryStore %i",detElements->GetSize(), iMt));
376 for (Int_t iDe = 0; iDe < detElements->GetSize(); iDe++)
377 { // detection elements.
378 AliMUONGeometryDetElement *detElement =
379 (AliMUONGeometryDetElement *) detElements->GetObject(iDe);
382 AliFatal("Detection element not found.");
384 /// make a new detection element
385 AliMUONGeometryDetElement *newDetElement =
386 new AliMUONGeometryDetElement(detElement->GetId(),
387 detElement->GetVolumePath());
389 // local transformation of this detection element.
390 TGeoCombiTrans localTransform
391 = TGeoCombiTrans(*detElement->GetLocalTransformation());
392 TGeoCombiTrans newLocalTransform = MisAlignDetElem(localTransform);
393 newDetElement->SetLocalTransformation(newLocalTransform);
396 // global transformation
397 TGeoHMatrix newGlobalTransform =
398 AliMUONGeometryBuilder::Multiply(newModuleTransform,
400 newDetElement->SetGlobalTransformation(newGlobalTransform);
402 // add this det element to module
403 newModuleTransformer->GetDetElementStore()->Add(newDetElement->GetId(),
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:
411 // Tdelta = Tnew * Told.inverse
412 TGeoHMatrix deltaGlobalTransform
413 = AliMUONGeometryBuilder::Multiply(
415 newOldGlobalTransform.Inverse());
417 // Create mis alignment matrix
418 newGeometryTransformer
419 ->AddMisAlignDetElement(detElement->GetId(), deltaGlobalTransform);
424 AliInfo(Form("Added module transformer %i to the transformer", iMt));
425 newGeometryTransformer->AddModuleTransformer(newModuleTransformer);
427 return newGeometryTransformer;