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"
54 #include "AliMpExMapIterator.h"
58 #include <TGeoMatrix.h>
61 #include <Riostream.h>
64 ClassImp(AliMUONGeometryMisAligner)
67 //______________________________________________________________________________
68 AliMUONGeometryMisAligner::AliMUONGeometryMisAligner(Double_t cartXMisAligM, Double_t cartXMisAligW, Double_t cartYMisAligM, Double_t cartYMisAligW, Double_t angMisAligM, Double_t angMisAligW)
72 fXYAngMisAligFactor(0.0),
73 fZCartMisAligFactor(0.0),
74 fDisplacementGenerator(0)
76 /// Standard constructor
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;
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;
90 fDisplacementGenerator = new TRandom(0);
93 //______________________________________________________________________________
94 AliMUONGeometryMisAligner::AliMUONGeometryMisAligner(Double_t cartMisAligM, Double_t cartMisAligW, Double_t angMisAligM, Double_t angMisAligW)
98 fXYAngMisAligFactor(0.0),
99 fZCartMisAligFactor(0.0),
100 fDisplacementGenerator(0)
102 /// Standard constructor
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;
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;
116 fDisplacementGenerator = new TRandom(0);
119 //______________________________________________________________________________
120 AliMUONGeometryMisAligner::AliMUONGeometryMisAligner(Double_t cartMisAlig, Double_t angMisAlig)
124 fXYAngMisAligFactor(0.0),
125 fZCartMisAligFactor(0.0),
126 fDisplacementGenerator(0)
128 /// Standard constructor
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;
135 fDetElemMisAlig[0][1] = cartMisAlig;
136 fDetElemMisAlig[1][1] = cartMisAlig;
137 fDetElemMisAlig[5][1] = angMisAlig;
139 fDisplacementGenerator = new TRandom(0);
142 //_____________________________________________________________________________
143 AliMUONGeometryMisAligner::AliMUONGeometryMisAligner()
147 fXYAngMisAligFactor(0.0),
148 fZCartMisAligFactor(0.0),
149 fDisplacementGenerator(0)
151 /// Default constructor
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;
160 //______________________________________________________________________________
161 AliMUONGeometryMisAligner::~AliMUONGeometryMisAligner()
165 if (fDisplacementGenerator) delete fDisplacementGenerator;
168 //_________________________________________________________________________
170 AliMUONGeometryMisAligner::SetXYAngMisAligFactor(Double_t factor)
172 /// Set XY angular misalign factor
174 if (TMath::Abs(factor) > 1.0 && factor > 0.){
175 fXYAngMisAligFactor = factor;
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
182 AliError(Form("Invalid XY angular misalign factor, %d", factor));
185 //_________________________________________________________________________
186 void AliMUONGeometryMisAligner::SetZCartMisAligFactor(Double_t factor)
188 /// Set XY angular misalign factor
189 if (TMath::Abs(factor)<1.0 && factor>0.) {
190 fZCartMisAligFactor = factor;
191 fDetElemMisAlig[2][0] = fDetElemMisAlig[0][0]; // These lines were added to
192 fDetElemMisAlig[2][1] = fDetElemMisAlig[0][1]*factor; // keep backward compatibility
195 AliError(Form("Invalid Z cartesian misalign factor, %d", factor));
198 //_________________________________________________________________________
199 void AliMUONGeometryMisAligner::GetUniMisAlign(Double_t cartMisAlig[3], Double_t angMisAlig[3], const Double_t lParMisAlig[6][2]) const
201 /// Misalign using uniform distribution
203 misalign the centre of the local transformation
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
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]);
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
220 //_________________________________________________________________________
221 void AliMUONGeometryMisAligner::GetGausMisAlign(Double_t cartMisAlig[3], Double_t angMisAlig[3], const Double_t lParMisAlig[6][2]) const
223 /// Misalign using gaussian distribution
225 misalign the centre of the local transformation
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
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]);
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
242 //_________________________________________________________________________
243 TGeoCombiTrans AliMUONGeometryMisAligner::MisAlignDetElem(const TGeoCombiTrans & transform) const
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)
254 Double_t cartMisAlig[3] = {0,0,0};
255 Double_t angMisAlig[3] = {0,0,0};
258 GetUniMisAlign(cartMisAlig,angMisAlig,fDetElemMisAlig);
262 AliWarning("Neither uniform nor gausian distribution is set! Will use gausian...");
264 GetGausMisAlign(cartMisAlig,angMisAlig,fDetElemMisAlig);
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]);
273 TGeoCombiTrans deltaTransf(deltaTrans,deltaRot);
274 TGeoHMatrix newTransfMat = transform * deltaTransf;
276 AliInfo(Form("Rotated DE by %f about Z axis.", angMisAlig[2]));
278 return TGeoCombiTrans(newTransfMat);
281 //_________________________________________________________________________
282 TGeoCombiTrans AliMUONGeometryMisAligner::MisAlignModule(const TGeoCombiTrans & transform) const
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)
293 Double_t cartMisAlig[3] = {0,0,0};
294 Double_t angMisAlig[3] = {0,0,0};
297 GetUniMisAlign(cartMisAlig,angMisAlig,fModuleMisAlig);
301 AliWarning("Neither uniform nor gausian distribution is set! Will use gausian...");
303 GetGausMisAlign(cartMisAlig,angMisAlig,fModuleMisAlig);
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]);
312 TGeoCombiTrans deltaTransf(deltaTrans,deltaRot);
313 TGeoHMatrix newTransfMat = transform * deltaTransf;
315 AliInfo(Form("Rotated Module by %f about Z axis.", angMisAlig[2]));
317 return TGeoCombiTrans(newTransfMat);
320 //______________________________________________________________________
321 AliMUONGeometryTransformer *
322 AliMUONGeometryMisAligner::MisAlign(const AliMUONGeometryTransformer *
323 transformer, Bool_t verbose)
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.
333 /// Calculates misalignment parameters and applies these
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.
346 AliMUONGeometryTransformer *newGeometryTransformer =
347 new AliMUONGeometryTransformer();
348 for (Int_t iMt = 0; iMt < transformer->GetNofModuleTransformers(); iMt++)
349 { // module transformers
350 const AliMUONGeometryModuleTransformer *kModuleTransformer =
351 transformer->GetModuleTransformer(iMt, true);
353 AliMUONGeometryModuleTransformer *newModuleTransformer =
354 new AliMUONGeometryModuleTransformer(iMt);
355 newGeometryTransformer->AddModuleTransformer(newModuleTransformer);
357 TGeoCombiTrans moduleTransform =
358 TGeoCombiTrans(*kModuleTransformer->GetTransformation());
359 // New module transformation
360 TGeoCombiTrans newModuleTransform = MisAlignModule(moduleTransform);
361 newModuleTransformer->SetTransformation(newModuleTransform);
363 // Get delta transformation:
364 // Tdelta = Tnew * Told.inverse
365 TGeoHMatrix deltaModuleTransform =
366 AliMUONGeometryBuilder::Multiply(
368 kModuleTransformer->GetTransformation()->Inverse());
370 // Create module mis alignment matrix
371 newGeometryTransformer
372 ->AddMisAlignModule(kModuleTransformer->GetModuleId(), deltaModuleTransform);
374 AliMpExMap *detElements = kModuleTransformer->GetDetElementStore();
377 AliInfo(Form("%i DEs in old GeometryStore %i",detElements->GetSize(), iMt));
379 TIter next(detElements->CreateIterator());
380 AliMUONGeometryDetElement *detElement;
382 while ( ( detElement = static_cast<AliMUONGeometryDetElement*>(next()) ) )
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;