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
45 //-----------------------------------------------------------------------------
47 #include "AliMUONGeometryMisAligner.h"
48 #include "AliMUONGeometryTransformer.h"
49 #include "AliMUONGeometryModuleTransformer.h"
50 #include "AliMUONGeometryDetElement.h"
51 #include "AliMUONGeometryBuilder.h"
53 #include "AliMpExMap.h"
57 #include <TGeoMatrix.h>
60 #include <Riostream.h>
63 ClassImp(AliMUONGeometryMisAligner)
66 //______________________________________________________________________________
67 AliMUONGeometryMisAligner::AliMUONGeometryMisAligner(Double_t cartXMisAligM, Double_t cartXMisAligW, Double_t cartYMisAligM, Double_t cartYMisAligW, Double_t angMisAligM, Double_t angMisAligW)
71 fXYAngMisAligFactor(0.0),
72 fZCartMisAligFactor(0.0),
73 fDisplacementGenerator(0)
75 /// Standard constructor
76 for (Int_t i=0; i<6; i++){
77 for (Int_t j=0; j<2; j++){
78 fDetElemMisAlig[i][j] = 0.0;
79 fModuleMisAlig[i][j] = 0.0;
82 fDetElemMisAlig[0][0] = cartXMisAligM;
83 fDetElemMisAlig[0][1] = cartXMisAligW;
84 fDetElemMisAlig[1][0] = cartYMisAligM;
85 fDetElemMisAlig[1][1] = cartYMisAligW;
86 fDetElemMisAlig[5][0] = angMisAligM;
87 fDetElemMisAlig[5][1] = angMisAligW;
89 fDisplacementGenerator = new TRandom(0);
92 //______________________________________________________________________________
93 AliMUONGeometryMisAligner::AliMUONGeometryMisAligner(Double_t cartMisAligM, Double_t cartMisAligW, Double_t angMisAligM, Double_t angMisAligW)
97 fXYAngMisAligFactor(0.0),
98 fZCartMisAligFactor(0.0),
99 fDisplacementGenerator(0)
101 /// Standard constructor
102 for (Int_t i=0; i<6; i++){
103 for (Int_t j=0; j<2; j++){
104 fDetElemMisAlig[i][j] = 0.0;
105 fModuleMisAlig[i][j] = 0.0;
108 fDetElemMisAlig[0][0] = cartMisAligM;
109 fDetElemMisAlig[0][1] = cartMisAligW;
110 fDetElemMisAlig[1][0] = cartMisAligM;
111 fDetElemMisAlig[1][1] = cartMisAligW;
112 fDetElemMisAlig[5][0] = angMisAligM;
113 fDetElemMisAlig[5][1] = angMisAligW;
115 fDisplacementGenerator = new TRandom(0);
118 //______________________________________________________________________________
119 AliMUONGeometryMisAligner::AliMUONGeometryMisAligner(Double_t cartMisAlig, Double_t angMisAlig)
123 fXYAngMisAligFactor(0.0),
124 fZCartMisAligFactor(0.0),
125 fDisplacementGenerator(0)
127 /// Standard constructor
128 for (Int_t i=0; i<6; i++){
129 for (Int_t j=0; j<2; j++){
130 fDetElemMisAlig[i][j] = 0.0;
131 fModuleMisAlig[i][j] = 0.0;
134 fDetElemMisAlig[0][1] = cartMisAlig;
135 fDetElemMisAlig[1][1] = cartMisAlig;
136 fDetElemMisAlig[5][1] = angMisAlig;
138 fDisplacementGenerator = new TRandom(0);
141 //_____________________________________________________________________________
142 AliMUONGeometryMisAligner::AliMUONGeometryMisAligner()
146 fXYAngMisAligFactor(0.0),
147 fZCartMisAligFactor(0.0),
148 fDisplacementGenerator(0)
150 /// Default constructor
151 for (Int_t i=0; i<6; i++){
152 for (Int_t j=0; j<2; j++){
153 fDetElemMisAlig[i][j] = 0.0;
154 fModuleMisAlig[i][j] = 0.0;
159 //______________________________________________________________________________
160 AliMUONGeometryMisAligner::~AliMUONGeometryMisAligner()
164 if (fDisplacementGenerator) delete fDisplacementGenerator;
167 //_________________________________________________________________________
169 AliMUONGeometryMisAligner::SetXYAngMisAligFactor(Double_t factor)
171 /// Set XY angular misalign factor
173 if (TMath::Abs(factor) > 1.0 && factor > 0.){
174 fXYAngMisAligFactor = factor;
175 fDetElemMisAlig[3][0] = fDetElemMisAlig[5][0]*factor; // These lines were
176 fDetElemMisAlig[3][1] = fDetElemMisAlig[5][1]*factor; // added to keep
177 fDetElemMisAlig[4][0] = fDetElemMisAlig[5][0]*factor; // backward
178 fDetElemMisAlig[4][1] = fDetElemMisAlig[5][1]*factor; // compatibility
181 AliError(Form("Invalid XY angular misalign factor, %d", factor));
184 //_________________________________________________________________________
185 void AliMUONGeometryMisAligner::SetZCartMisAligFactor(Double_t factor)
187 /// Set XY angular misalign factor
188 if (TMath::Abs(factor)<1.0 && factor>0.) {
189 fZCartMisAligFactor = factor;
190 fDetElemMisAlig[2][0] = fDetElemMisAlig[0][0]; // These lines were added to
191 fDetElemMisAlig[2][1] = fDetElemMisAlig[0][1]*factor; // keep backward compatibility
194 AliError(Form("Invalid Z cartesian misalign factor, %d", factor));
197 //_________________________________________________________________________
198 void AliMUONGeometryMisAligner::GetUniMisAlign(Double_t cartMisAlig[3], Double_t angMisAlig[3], const Double_t lParMisAlig[6][2]) const
200 /// Misalign using uniform distribution
202 misalign the centre of the local transformation
204 fAngMisAlig[1,2,3] = [x,y,z]
205 Assume that misalignment about the x and y axes (misalignment of z plane)
206 is much smaller, since the entire detection plane has to be moved (the
207 detection elements are on a support structure), while rotation of the x-y
210 cartMisAlig[0] = fDisplacementGenerator->Uniform(-lParMisAlig[0][1]+lParMisAlig[0][0], lParMisAlig[0][0]+lParMisAlig[0][1]);
211 cartMisAlig[1] = fDisplacementGenerator->Uniform(-lParMisAlig[1][1]+lParMisAlig[1][0], lParMisAlig[1][0]+lParMisAlig[1][1]);
212 cartMisAlig[2] = fDisplacementGenerator->Uniform(-lParMisAlig[2][1]+lParMisAlig[2][0], lParMisAlig[2][0]+lParMisAlig[2][1]);
214 angMisAlig[0] = fDisplacementGenerator->Uniform(-lParMisAlig[3][1]+lParMisAlig[3][0], lParMisAlig[3][0]+lParMisAlig[3][1]);
215 angMisAlig[1] = fDisplacementGenerator->Uniform(-lParMisAlig[4][1]+lParMisAlig[4][0], lParMisAlig[4][0]+lParMisAlig[4][1]);
216 angMisAlig[2] = fDisplacementGenerator->Uniform(-lParMisAlig[5][1]+lParMisAlig[5][0], lParMisAlig[5][0]+lParMisAlig[5][1]); // degrees
219 //_________________________________________________________________________
220 void AliMUONGeometryMisAligner::GetGausMisAlign(Double_t cartMisAlig[3], Double_t angMisAlig[3], const Double_t lParMisAlig[6][2]) const
222 /// Misalign using gaussian distribution
224 misalign the centre of the local transformation
226 fAngMisAlig[1,2,3] = [x,y,z]
227 Assume that misalignment about the x and y axes (misalignment of z plane)
228 is much smaller, since the entire detection plane has to be moved (the
229 detection elements are on a support structure), while rotation of the x-y
232 cartMisAlig[0] = fDisplacementGenerator->Gaus(lParMisAlig[0][0], lParMisAlig[0][1]);
233 cartMisAlig[1] = fDisplacementGenerator->Gaus(lParMisAlig[1][0], lParMisAlig[1][1]);
234 cartMisAlig[2] = fDisplacementGenerator->Gaus(lParMisAlig[2][0], lParMisAlig[2][1]);
236 angMisAlig[0] = fDisplacementGenerator->Gaus(lParMisAlig[3][0], lParMisAlig[3][1]);
237 angMisAlig[1] = fDisplacementGenerator->Gaus(lParMisAlig[4][0], lParMisAlig[4][1]);
238 angMisAlig[2] = fDisplacementGenerator->Gaus(lParMisAlig[5][0], lParMisAlig[5][1]); // degrees
241 //_________________________________________________________________________
242 TGeoCombiTrans AliMUONGeometryMisAligner::MisAlignDetElem(const TGeoCombiTrans & transform) const
244 /// Misalign given transformation and return the misaligned transformation.
245 /// Use misalignment parameters for detection elements.
246 /// Note that applied misalignments are small deltas with respect to the detection
247 /// element own ideal local reference frame. Thus deltaTransf represents
248 /// the transformation to go from the misaligned d.e. local coordinates to the
249 /// ideal d.e. local coordinates.
250 /// Also note that this -is not- what is in the ALICE alignment framework known
251 /// as local nor global (see AliMUONGeometryMisAligner::MisAlign)
253 Double_t cartMisAlig[3] = {0,0,0};
254 Double_t angMisAlig[3] = {0,0,0};
257 GetUniMisAlign(cartMisAlig,angMisAlig,fDetElemMisAlig);
261 AliWarning("Neither uniform nor gausian distribution is set! Will use gausian...");
263 GetGausMisAlign(cartMisAlig,angMisAlig,fDetElemMisAlig);
266 TGeoTranslation deltaTrans(cartMisAlig[0], cartMisAlig[1], cartMisAlig[2]);
267 TGeoRotation deltaRot;
268 deltaRot.RotateX(angMisAlig[0]);
269 deltaRot.RotateY(angMisAlig[1]);
270 deltaRot.RotateZ(angMisAlig[2]);
272 TGeoCombiTrans deltaTransf(deltaTrans,deltaRot);
273 TGeoHMatrix newTransfMat = transform * deltaTransf;
275 AliInfo(Form("Rotated DE by %f about Z axis.", angMisAlig[2]));
277 return TGeoCombiTrans(newTransfMat);
280 //_________________________________________________________________________
281 TGeoCombiTrans AliMUONGeometryMisAligner::MisAlignModule(const TGeoCombiTrans & transform) const
283 /// Misalign given transformation and return the misaligned transformation.
284 /// Use misalignment parameters for modules.
285 /// Note that applied misalignments are small deltas with respect to the module
286 /// own ideal local reference frame. Thus deltaTransf represents
287 /// the transformation to go from the misaligned module local coordinates to the
288 /// ideal module local coordinates.
289 /// Also note that this -is not- what is in the ALICE alignment framework known
290 /// as local nor global (see AliMUONGeometryMisAligner::MisAlign)
292 Double_t cartMisAlig[3] = {0,0,0};
293 Double_t angMisAlig[3] = {0,0,0};
296 GetUniMisAlign(cartMisAlig,angMisAlig,fModuleMisAlig);
300 AliWarning("Neither uniform nor gausian distribution is set! Will use gausian...");
302 GetGausMisAlign(cartMisAlig,angMisAlig,fModuleMisAlig);
305 TGeoTranslation deltaTrans(cartMisAlig[0], cartMisAlig[1], cartMisAlig[2]);
306 TGeoRotation deltaRot;
307 deltaRot.RotateX(angMisAlig[0]);
308 deltaRot.RotateY(angMisAlig[1]);
309 deltaRot.RotateZ(angMisAlig[2]);
311 TGeoCombiTrans deltaTransf(deltaTrans,deltaRot);
312 TGeoHMatrix newTransfMat = transform * deltaTransf;
314 AliInfo(Form("Rotated Module by %f about Z axis.", angMisAlig[2]));
316 return TGeoCombiTrans(newTransfMat);
319 //______________________________________________________________________
320 AliMUONGeometryTransformer *
321 AliMUONGeometryMisAligner::MisAlign(const AliMUONGeometryTransformer *
322 transformer, Bool_t verbose)
324 /// Takes the internal geometry module transformers, copies them to
325 /// new geometry module transformers.
326 /// Calculates module misalignment parameters and applies these
327 /// to the new module transformer.
328 /// Calculates the module misalignment delta transformation in the
329 /// Alice Alignment Framework newTransf = delta * oldTransf.
330 /// Add a module misalignment to the new geometry transformer.
331 /// Gets the Detection Elements from the module transformer.
332 /// Calculates misalignment parameters and applies these
333 /// to the local transformation of the Detection Element.
334 /// Obtains the new global transformation by multiplying the new
335 /// module transformer transformation with the new local transformation.
336 /// Applies the new global transform to a new detection element.
337 /// Adds the new detection element to a new module transformer.
338 /// Calculates the d.e. misalignment delta transformation in the
339 /// Alice Alignment Framework (newGlobalTransf = delta * oldGlobalTransf).
340 /// Add a d.e. misalignment to the new geometry transformer.
341 /// Adds the new module transformer to a new geometry transformer.
342 /// Returns the new geometry transformer.
345 AliMUONGeometryTransformer *newGeometryTransformer =
346 new AliMUONGeometryTransformer();
347 for (Int_t iMt = 0; iMt < transformer->GetNofModuleTransformers(); iMt++)
348 { // module transformers
349 const AliMUONGeometryModuleTransformer *kModuleTransformer =
350 transformer->GetModuleTransformer(iMt, true);
352 AliMUONGeometryModuleTransformer *newModuleTransformer =
353 new AliMUONGeometryModuleTransformer(iMt);
354 newGeometryTransformer->AddModuleTransformer(newModuleTransformer);
356 TGeoCombiTrans moduleTransform =
357 TGeoCombiTrans(*kModuleTransformer->GetTransformation());
358 // New module transformation
359 TGeoCombiTrans newModuleTransform = MisAlignModule(moduleTransform);
360 newModuleTransformer->SetTransformation(newModuleTransform);
362 // Get delta transformation:
363 // Tdelta = Tnew * Told.inverse
364 TGeoHMatrix deltaModuleTransform =
365 AliMUONGeometryBuilder::Multiply(
367 kModuleTransformer->GetTransformation()->Inverse());
369 // Create module mis alignment matrix
370 newGeometryTransformer
371 ->AddMisAlignModule(kModuleTransformer->GetModuleId(), deltaModuleTransform);
373 AliMpExMap *detElements = kModuleTransformer->GetDetElementStore();
376 AliInfo(Form("%i DEs in old GeometryStore %i",detElements->GetSize(), iMt));
378 for (Int_t iDe = 0; iDe < detElements->GetSize(); iDe++)
379 { // detection elements.
380 AliMUONGeometryDetElement *detElement =
381 (AliMUONGeometryDetElement *) detElements->GetObject(iDe);
384 AliFatal("Detection element not found.");
386 /// make a new detection element
387 AliMUONGeometryDetElement *newDetElement =
388 new AliMUONGeometryDetElement(detElement->GetId(),
389 detElement->GetVolumePath());
391 // local transformation of this detection element.
392 TGeoCombiTrans localTransform
393 = TGeoCombiTrans(*detElement->GetLocalTransformation());
394 TGeoCombiTrans newLocalTransform = MisAlignDetElem(localTransform);
395 newDetElement->SetLocalTransformation(newLocalTransform);
398 // global transformation
399 TGeoHMatrix newGlobalTransform =
400 AliMUONGeometryBuilder::Multiply(newModuleTransform,
402 newDetElement->SetGlobalTransformation(newGlobalTransform);
404 // add this det element to module
405 newModuleTransformer->GetDetElementStore()->Add(newDetElement->GetId(),
408 // In the Alice Alignment Framework misalignment objects store
409 // global delta transformation
410 // Get detection "intermediate" global transformation
411 TGeoHMatrix newOldGlobalTransform = newModuleTransform * localTransform;
412 // Get detection element global delta transformation:
413 // Tdelta = Tnew * Told.inverse
414 TGeoHMatrix deltaGlobalTransform
415 = AliMUONGeometryBuilder::Multiply(
417 newOldGlobalTransform.Inverse());
419 // Create mis alignment matrix
420 newGeometryTransformer
421 ->AddMisAlignDetElement(detElement->GetId(), deltaGlobalTransform);
426 AliInfo(Form("Added module transformer %i to the transformer", iMt));
427 newGeometryTransformer->AddModuleTransformer(newModuleTransformer);
429 return newGeometryTransformer;