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>
59 #include <Riostream.h>
62 ClassImp(AliMUONGeometryMisAligner)
65 //______________________________________________________________________________
66 AliMUONGeometryMisAligner::AliMUONGeometryMisAligner(Double_t cartXMisAligM, Double_t cartXMisAligW, Double_t cartYMisAligM, Double_t cartYMisAligW, Double_t angMisAligM, Double_t angMisAligW)
70 fXYAngMisAligFactor(0.0),
71 fZCartMisAligFactor(0.0),
72 fDisplacementGenerator(0)
74 /// Standard constructor
75 for (Int_t i=0; i<6; i++){
76 for (Int_t j=0; j<2; j++){
77 fDetElemMisAlig[i][j] = 0.0;
78 fModuleMisAlig[i][j] = 0.0;
81 fDetElemMisAlig[0][0] = cartXMisAligM;
82 fDetElemMisAlig[0][1] = cartXMisAligW;
83 fDetElemMisAlig[1][0] = cartYMisAligM;
84 fDetElemMisAlig[1][1] = cartYMisAligW;
85 fDetElemMisAlig[5][0] = angMisAligM;
86 fDetElemMisAlig[5][1] = angMisAligW;
88 fDisplacementGenerator = new TRandom(0);
91 //______________________________________________________________________________
92 AliMUONGeometryMisAligner::AliMUONGeometryMisAligner(Double_t cartMisAligM, Double_t cartMisAligW, Double_t angMisAligM, Double_t angMisAligW)
96 fXYAngMisAligFactor(0.0),
97 fZCartMisAligFactor(0.0),
98 fDisplacementGenerator(0)
100 /// Standard constructor
101 for (Int_t i=0; i<6; i++){
102 for (Int_t j=0; j<2; j++){
103 fDetElemMisAlig[i][j] = 0.0;
104 fModuleMisAlig[i][j] = 0.0;
107 fDetElemMisAlig[0][0] = cartMisAligM;
108 fDetElemMisAlig[0][1] = cartMisAligW;
109 fDetElemMisAlig[1][0] = cartMisAligM;
110 fDetElemMisAlig[1][1] = cartMisAligW;
111 fDetElemMisAlig[5][0] = angMisAligM;
112 fDetElemMisAlig[5][1] = angMisAligW;
114 fDisplacementGenerator = new TRandom(0);
117 //______________________________________________________________________________
118 AliMUONGeometryMisAligner::AliMUONGeometryMisAligner(Double_t cartMisAlig, Double_t angMisAlig)
122 fXYAngMisAligFactor(0.0),
123 fZCartMisAligFactor(0.0),
124 fDisplacementGenerator(0)
126 /// Standard constructor
127 for (Int_t i=0; i<6; i++){
128 for (Int_t j=0; j<2; j++){
129 fDetElemMisAlig[i][j] = 0.0;
130 fModuleMisAlig[i][j] = 0.0;
133 fDetElemMisAlig[0][1] = cartMisAlig;
134 fDetElemMisAlig[1][1] = cartMisAlig;
135 fDetElemMisAlig[5][1] = angMisAlig;
137 fDisplacementGenerator = new TRandom(0);
140 //_____________________________________________________________________________
141 AliMUONGeometryMisAligner::AliMUONGeometryMisAligner()
145 fXYAngMisAligFactor(0.0),
146 fZCartMisAligFactor(0.0),
147 fDisplacementGenerator(0)
149 /// Default constructor
150 for (Int_t i=0; i<6; i++){
151 for (Int_t j=0; j<2; j++){
152 fDetElemMisAlig[i][j] = 0.0;
153 fModuleMisAlig[i][j] = 0.0;
158 //______________________________________________________________________________
159 AliMUONGeometryMisAligner::~AliMUONGeometryMisAligner()
163 if (fDisplacementGenerator) delete fDisplacementGenerator;
166 //_________________________________________________________________________
168 AliMUONGeometryMisAligner::SetXYAngMisAligFactor(Double_t factor)
170 /// Set XY angular misalign factor
172 if (TMath::Abs(factor) > 1.0 && factor > 0.){
173 fXYAngMisAligFactor = factor;
174 fDetElemMisAlig[3][0] = fDetElemMisAlig[5][0]*factor; // These lines were
175 fDetElemMisAlig[3][1] = fDetElemMisAlig[5][1]*factor; // added to keep
176 fDetElemMisAlig[4][0] = fDetElemMisAlig[5][0]*factor; // backward
177 fDetElemMisAlig[4][1] = fDetElemMisAlig[5][1]*factor; // compatibility
180 AliError(Form("Invalid XY angular misalign factor, %d", factor));
183 //_________________________________________________________________________
184 void AliMUONGeometryMisAligner::SetZCartMisAligFactor(Double_t factor)
186 /// Set XY angular misalign factor
187 if (TMath::Abs(factor)<1.0 && factor>0.) {
188 fZCartMisAligFactor = factor;
189 fDetElemMisAlig[2][0] = fDetElemMisAlig[0][0]; // These lines were added to
190 fDetElemMisAlig[2][1] = fDetElemMisAlig[0][1]*factor; // keep backward compatibility
193 AliError(Form("Invalid Z cartesian misalign factor, %d", factor));
196 //_________________________________________________________________________
197 void AliMUONGeometryMisAligner::GetUniMisAlign(Double_t cartMisAlig[3], Double_t angMisAlig[3], const Double_t lParMisAlig[6][2]) const
199 /// Misalign using uniform distribution
201 misalign the centre of the local transformation
203 fAngMisAlig[1,2,3] = [x,y,z]
204 Assume that misalignment about the x and y axes (misalignment of z plane)
205 is much smaller, since the entire detection plane has to be moved (the
206 detection elements are on a support structure), while rotation of the x-y
209 cartMisAlig[0] = fDisplacementGenerator->Uniform(-lParMisAlig[0][1]+lParMisAlig[0][0], lParMisAlig[0][0]+lParMisAlig[0][1]);
210 cartMisAlig[1] = fDisplacementGenerator->Uniform(-lParMisAlig[1][1]+lParMisAlig[1][0], lParMisAlig[1][0]+lParMisAlig[1][1]);
211 cartMisAlig[2] = fDisplacementGenerator->Uniform(-lParMisAlig[2][1]+lParMisAlig[2][0], lParMisAlig[2][0]+lParMisAlig[2][1]);
213 angMisAlig[0] = fDisplacementGenerator->Uniform(-lParMisAlig[3][1]+lParMisAlig[3][0], lParMisAlig[3][0]+lParMisAlig[3][1]);
214 angMisAlig[1] = fDisplacementGenerator->Uniform(-lParMisAlig[4][1]+lParMisAlig[4][0], lParMisAlig[4][0]+lParMisAlig[4][1]);
215 angMisAlig[2] = fDisplacementGenerator->Uniform(-lParMisAlig[5][1]+lParMisAlig[5][0], lParMisAlig[5][0]+lParMisAlig[5][1]); // degrees
218 //_________________________________________________________________________
219 void AliMUONGeometryMisAligner::GetGausMisAlign(Double_t cartMisAlig[3], Double_t angMisAlig[3], const Double_t lParMisAlig[6][2]) const
221 /// Misalign using gaussian distribution
223 misalign the centre of the local transformation
225 fAngMisAlig[1,2,3] = [x,y,z]
226 Assume that misalignment about the x and y axes (misalignment of z plane)
227 is much smaller, since the entire detection plane has to be moved (the
228 detection elements are on a support structure), while rotation of the x-y
231 cartMisAlig[0] = fDisplacementGenerator->Gaus(lParMisAlig[0][0], lParMisAlig[0][1]);
232 cartMisAlig[1] = fDisplacementGenerator->Gaus(lParMisAlig[1][0], lParMisAlig[1][1]);
233 cartMisAlig[2] = fDisplacementGenerator->Gaus(lParMisAlig[2][0], lParMisAlig[2][1]);
235 angMisAlig[0] = fDisplacementGenerator->Gaus(lParMisAlig[3][0], lParMisAlig[3][1]);
236 angMisAlig[1] = fDisplacementGenerator->Gaus(lParMisAlig[4][0], lParMisAlig[4][1]);
237 angMisAlig[2] = fDisplacementGenerator->Gaus(lParMisAlig[5][0], lParMisAlig[5][1]); // degrees
240 //_________________________________________________________________________
241 TGeoCombiTrans AliMUONGeometryMisAligner::MisAlignDetElem(const TGeoCombiTrans & transform) const
243 /// Misalign given transformation and return the misaligned transformation.
244 /// Use misalignment parameters for detection elements.
245 /// Note that applied misalignments are small deltas with respect to the detection
246 /// element own ideal local reference frame. Thus deltaTransf represents
247 /// the transformation to go from the misaligned d.e. local coordinates to the
248 /// ideal d.e. local coordinates.
249 /// Also note that this -is not- what is in the ALICE alignment framework known
250 /// as local nor global (see AliMUONGeometryMisAligner::MisAlign)
252 Double_t cartMisAlig[3] = {0,0,0};
253 Double_t angMisAlig[3] = {0,0,0};
256 GetUniMisAlign(cartMisAlig,angMisAlig,fDetElemMisAlig);
260 AliWarning("Neither uniform nor gausian distribution is set! Will use gausian...");
262 GetGausMisAlign(cartMisAlig,angMisAlig,fDetElemMisAlig);
265 TGeoTranslation deltaTrans(cartMisAlig[0], cartMisAlig[1], cartMisAlig[2]);
266 TGeoRotation deltaRot;
267 deltaRot.RotateX(angMisAlig[0]);
268 deltaRot.RotateY(angMisAlig[1]);
269 deltaRot.RotateZ(angMisAlig[2]);
271 TGeoCombiTrans deltaTransf(deltaTrans,deltaRot);
272 TGeoHMatrix newTransfMat = transform * deltaTransf;
274 AliInfo(Form("Rotated DE by %f about Z axis.", angMisAlig[2]));
276 return TGeoCombiTrans(newTransfMat);
279 //_________________________________________________________________________
280 TGeoCombiTrans AliMUONGeometryMisAligner::MisAlignModule(const TGeoCombiTrans & transform) const
282 /// Misalign given transformation and return the misaligned transformation.
283 /// Use misalignment parameters for modules.
284 /// Note that applied misalignments are small deltas with respect to the module
285 /// own ideal local reference frame. Thus deltaTransf represents
286 /// the transformation to go from the misaligned module local coordinates to the
287 /// ideal module local coordinates.
288 /// Also note that this -is not- what is in the ALICE alignment framework known
289 /// as local nor global (see AliMUONGeometryMisAligner::MisAlign)
291 Double_t cartMisAlig[3] = {0,0,0};
292 Double_t angMisAlig[3] = {0,0,0};
295 GetUniMisAlign(cartMisAlig,angMisAlig,fModuleMisAlig);
299 AliWarning("Neither uniform nor gausian distribution is set! Will use gausian...");
301 GetGausMisAlign(cartMisAlig,angMisAlig,fModuleMisAlig);
304 TGeoTranslation deltaTrans(cartMisAlig[0], cartMisAlig[1], cartMisAlig[2]);
305 TGeoRotation deltaRot;
306 deltaRot.RotateX(angMisAlig[0]);
307 deltaRot.RotateY(angMisAlig[1]);
308 deltaRot.RotateZ(angMisAlig[2]);
310 TGeoCombiTrans deltaTransf(deltaTrans,deltaRot);
311 TGeoHMatrix newTransfMat = transform * deltaTransf;
313 AliInfo(Form("Rotated Module by %f about Z axis.", angMisAlig[2]));
315 return TGeoCombiTrans(newTransfMat);
318 //______________________________________________________________________
319 AliMUONGeometryTransformer *
320 AliMUONGeometryMisAligner::MisAlign(const AliMUONGeometryTransformer *
321 transformer, Bool_t verbose)
323 /// Takes the internal geometry module transformers, copies them to
324 /// new geometry module transformers.
325 /// Calculates module misalignment parameters and applies these
326 /// to the new module transformer.
327 /// Calculates the module misalignment delta transformation in the
328 /// Alice Alignment Framework newTransf = delta * oldTransf.
329 /// Add a module misalignment to the new geometry transformer.
330 /// Gets the Detection Elements from the module transformer.
331 /// Calculates misalignment parameters and applies these
332 /// to the local transformation of the Detection Element.
333 /// Obtains the new global transformation by multiplying the new
334 /// module transformer transformation with the new local transformation.
335 /// Applies the new global transform to a new detection element.
336 /// Adds the new detection element to a new module transformer.
337 /// Calculates the d.e. misalignment delta transformation in the
338 /// Alice Alignment Framework (newGlobalTransf = delta * oldGlobalTransf).
339 /// Add a d.e. misalignment to the new geometry transformer.
340 /// Adds the new module transformer to a new geometry transformer.
341 /// Returns the new geometry transformer.
344 AliMUONGeometryTransformer *newGeometryTransformer =
345 new AliMUONGeometryTransformer();
346 for (Int_t iMt = 0; iMt < transformer->GetNofModuleTransformers(); iMt++)
347 { // module transformers
348 const AliMUONGeometryModuleTransformer *kModuleTransformer =
349 transformer->GetModuleTransformer(iMt, true);
351 AliMUONGeometryModuleTransformer *newModuleTransformer =
352 new AliMUONGeometryModuleTransformer(iMt);
353 newGeometryTransformer->AddModuleTransformer(newModuleTransformer);
355 TGeoCombiTrans moduleTransform =
356 TGeoCombiTrans(*kModuleTransformer->GetTransformation());
357 // New module transformation
358 TGeoCombiTrans newModuleTransform = MisAlignModule(moduleTransform);
359 newModuleTransformer->SetTransformation(newModuleTransform);
361 // Get delta transformation:
362 // Tdelta = Tnew * Told.inverse
363 TGeoHMatrix deltaModuleTransform =
364 AliMUONGeometryBuilder::Multiply(
366 kModuleTransformer->GetTransformation()->Inverse());
368 // Create module mis alignment matrix
369 newGeometryTransformer
370 ->AddMisAlignModule(kModuleTransformer->GetModuleId(), deltaModuleTransform);
372 AliMpExMap *detElements = kModuleTransformer->GetDetElementStore();
375 AliInfo(Form("%i DEs in old GeometryStore %i",detElements->GetSize(), iMt));
377 for (Int_t iDe = 0; iDe < detElements->GetSize(); iDe++)
378 { // detection elements.
379 AliMUONGeometryDetElement *detElement =
380 (AliMUONGeometryDetElement *) detElements->GetObject(iDe);
383 AliFatal("Detection element not found.");
385 /// make a new detection element
386 AliMUONGeometryDetElement *newDetElement =
387 new AliMUONGeometryDetElement(detElement->GetId(),
388 detElement->GetVolumePath());
390 // local transformation of this detection element.
391 TGeoCombiTrans localTransform
392 = TGeoCombiTrans(*detElement->GetLocalTransformation());
393 TGeoCombiTrans newLocalTransform = MisAlignDetElem(localTransform);
394 newDetElement->SetLocalTransformation(newLocalTransform);
397 // global transformation
398 TGeoHMatrix newGlobalTransform =
399 AliMUONGeometryBuilder::Multiply(newModuleTransform,
401 newDetElement->SetGlobalTransformation(newGlobalTransform);
403 // add this det element to module
404 newModuleTransformer->GetDetElementStore()->Add(newDetElement->GetId(),
407 // In the Alice Alignment Framework misalignment objects store
408 // global delta transformation
409 // Get detection "intermediate" global transformation
410 TGeoHMatrix newOldGlobalTransform = newModuleTransform * localTransform;
411 // Get detection element global delta transformation:
412 // Tdelta = Tnew * Told.inverse
413 TGeoHMatrix deltaGlobalTransform
414 = AliMUONGeometryBuilder::Multiply(
416 newOldGlobalTransform.Inverse());
418 // Create mis alignment matrix
419 newGeometryTransformer
420 ->AddMisAlignDetElement(detElement->GetId(), deltaGlobalTransform);
425 AliInfo(Form("Added module transformer %i to the transformer", iMt));
426 newGeometryTransformer->AddModuleTransformer(newModuleTransformer);
428 return newGeometryTransformer;