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 // Class AliMUONGeometryMisAligner
19 // ----------------------------
20 // Class for misalignment of geometry transformations
22 // Author:Bruce Becker
24 //__________________________________________________________________
26 /////////////////////////////////////////////////////////////////////
27 //This performs the misalignment on an existing muon arm geometry
28 // based on the standard definition of the detector elements in
29 // $ALICE_ROOT/MUON/data
31 // --> User has to specify the magnitude of the alignments, in the Cartesian
32 // co-ordiantes (which are used to apply translation misalignments) and in the
33 // spherical co-ordinates (which are used to apply angular displacements)
34 // --> If the constructor is used with no arguments, user has to set
35 // misalignment ranges by hand using the methods :
36 // SetApplyMisAlig, SetMaxCartMisAlig, SetMaxAngMisAlig, SetXYAngMisAligFactor
37 // (last method takes account of the fact that the misalingment is greatest in
38 // the XY plane, since the detection elements are fixed to a support structure
39 // in this plane. Misalignments in the XZ and YZ plane will be very small
40 // compared to those in the XY plane, which are small already - of the order
43 // Note : If the detection elements are allowed to be misaligned in all
44 // directions, this has consequences for the alignment algorithm
45 // (AliMUONAlignment), which needs to know the number of free parameters.
46 // Eric only allowed 3 : x,y,theta_xy, but in principle z and the other
47 // two angles are alignable as well.
49 #include "AliMUONGeometryMisAligner.h"
50 #include "AliMUONGeometryTransformer.h"
51 #include "AliMUONGeometryModuleTransformer.h"
52 #include "AliMUONGeometryDetElement.h"
53 #include "AliMUONGeometryStore.h"
54 #include "AliMUONGeometryBuilder.h"
58 #include <TGeoManager.h>
59 #include <Riostream.h>
60 #include <TObjArray.h>
67 ClassImp(AliMUONGeometryMisAligner)
68 //______________________________________________________________________________
69 AliMUONGeometryMisAligner::AliMUONGeometryMisAligner(Double_t cartMisAlig, Double_t angMisAlig)
70 :TObject(), fDisplacementGenerator(0)
72 /// Standard constructor
73 fMaxCartMisAlig = cartMisAlig; // 0.5 mm. Perhaps this should go into AliMUONConstants.h ?
74 fMaxAngMisAlig = angMisAlig;
75 fXYAngMisAligFactor = 1.0;
76 fDisplacementGenerator = new TRandom(0);
79 //_____________________________________________________________________________
80 AliMUONGeometryMisAligner::AliMUONGeometryMisAligner()
81 :TObject(), fDisplacementGenerator(0)
83 /// Default constructor
86 //______________________________________________________________________________
87 AliMUONGeometryMisAligner::
88 AliMUONGeometryMisAligner(const AliMUONGeometryMisAligner & right):
91 /// Copy constructor (not implemented)
93 AliFatal("Copy constructor not provided.");
96 //______________________________________________________________________________
97 AliMUONGeometryMisAligner::~AliMUONGeometryMisAligner()
101 delete fDisplacementGenerator;
104 //______________________________________________________________________________
105 AliMUONGeometryMisAligner & AliMUONGeometryMisAligner::
106 operator=(const AliMUONGeometryMisAligner & right)
108 /// Assignement operator (not implemented)
110 // check assignement to self
114 AliFatal("Assignement operator not provided.");
119 //_________________________________________________________________________
121 AliMUONGeometryMisAligner::SetXYAngMisAligFactor(Double_t factor)
125 if (TMath::Abs(factor) > 1.0 && factor > 0.)
126 fXYAngMisAligFactor = factor;
128 AliError(Form("Invalid factor, %d", factor));
131 //_________________________________________________________________________
132 TGeoCombiTrans AliMUONGeometryMisAligner::MisAlign(const TGeoCombiTrans & transform) const
134 /// Misalign given transformation and return the misaligned transformation
136 Double_t cartMisAlig[3] = {0,0,0};
137 Double_t angMisAlig[3] = {0,0,0};
138 const Double_t *trans = transform.GetTranslation();
140 // check if the rotation we obtain is not NULL
141 if (transform.GetRotation())
143 rot = transform.GetRotation();
147 rot = new TGeoRotation("rot");
148 } // default constructor.
150 cartMisAlig[0] = fDisplacementGenerator->Uniform(-1. * fMaxCartMisAlig, fMaxCartMisAlig);
151 cartMisAlig[1] = fDisplacementGenerator->Uniform(-1. * fMaxCartMisAlig, fMaxCartMisAlig);
152 cartMisAlig[2] = fDisplacementGenerator->Uniform(-1. * fMaxCartMisAlig, fMaxCartMisAlig);
154 TGeoTranslation newTrans(cartMisAlig[0] + trans[0], cartMisAlig[1] + trans[1], cartMisAlig[2] + trans[2]);
157 misalign the centre of the local transformation
159 fAngMisAlig[1,2,3] = [x,y,z]
160 Assume that misalignment about the x and y axes (misalignment of z plane)
161 is much smaller, since the entire detection plane has to be moved (the
162 detection elements are on a support structure), while rotation of the x-y
166 angMisAlig[0] = fDisplacementGenerator->Uniform(fXYAngMisAligFactor * fMaxAngMisAlig, 1.0 * fMaxAngMisAlig);
167 angMisAlig[1] = fDisplacementGenerator->Uniform(fXYAngMisAligFactor * fMaxAngMisAlig, 1.0 * fMaxAngMisAlig);
168 angMisAlig[2] = fDisplacementGenerator->Uniform(-1. * fMaxAngMisAlig, fMaxAngMisAlig); // degrees
169 AliInfo(Form("Rotated by %f about Z axis.", angMisAlig[2]));
170 rot->RotateX(angMisAlig[0]);
171 rot->RotateY(angMisAlig[1]);
172 rot->RotateZ(angMisAlig[2]);
174 return TGeoCombiTrans(newTrans, *rot);
178 //______________________________________________________________________
179 AliMUONGeometryTransformer *
180 AliMUONGeometryMisAligner::MisAlign(const AliMUONGeometryTransformer *
181 transformer, Bool_t verbose)
183 /////////////////////////////////////////////////////////////////////
184 // Takes the internal geometry module transformers, copies them
185 // and gets the Detection Elements from them.
186 // Calculates misalignment parameters and applies these
187 // to the local transform of the Detection Element
188 // Obtains the global transform by multiplying the module transformer
189 // transformation with the local transformation
190 // Applies the global transform to a new detection element
191 // Adds the new detection element to a new module transformer
192 // Adds the new module transformer to a new geometry transformer
193 // Returns the new geometry transformer
196 AliMUONGeometryTransformer *newGeometryTransformer =
197 new AliMUONGeometryTransformer(kTRUE);
198 for (Int_t iMt = 0; iMt < transformer->GetNofModuleTransformers(); iMt++)
199 { // module transformers
201 const AliMUONGeometryModuleTransformer *kModuleTransformer =
202 transformer->GetModuleTransformer(iMt, true);
204 AliMUONGeometryModuleTransformer *newModuleTransformer =
205 new AliMUONGeometryModuleTransformer(iMt);
206 newGeometryTransformer->AddModuleTransformer(newModuleTransformer);
208 TGeoCombiTrans moduleTransform =
209 TGeoCombiTrans(*kModuleTransformer->GetTransformation());
210 TGeoCombiTrans *newModuleTransform = new TGeoCombiTrans(moduleTransform);
211 // same module transform as the previous one
212 // no mis align object created
213 newModuleTransformer->SetTransformation(moduleTransform);
215 AliMUONGeometryStore *detElements =
216 kModuleTransformer->GetDetElementStore();
220 ("%i DEs in old GeometryStore %i",
221 detElements->GetNofEntries(), iMt));
223 for (Int_t iDe = 0; iDe < detElements->GetNofEntries(); iDe++)
224 { // detection elements.
225 AliMUONGeometryDetElement *detElement =
226 (AliMUONGeometryDetElement *) detElements->GetEntry(iDe);
228 AliFatal("Detection element not found.");
230 /// make a new detection element
231 AliMUONGeometryDetElement *newDetElement =
232 new AliMUONGeometryDetElement(detElement->GetId(),
233 detElement->GetVolumePath());
235 // local transformation of this detection element.
236 TGeoCombiTrans localTransform
237 = TGeoCombiTrans(*detElement->GetLocalTransformation());
238 TGeoCombiTrans newLocalTransform = MisAlign(localTransform);
239 newDetElement->SetLocalTransformation(newLocalTransform);
241 // global transformation
242 TGeoHMatrix newGlobalTransform =
243 AliMUONGeometryBuilder::Multiply(*newModuleTransform,
245 newDetElement->SetGlobalTransformation(newGlobalTransform);
247 // add this det element to module
248 newModuleTransformer->GetDetElementStore()->Add(newDetElement->GetId(),
250 // Get delta transformation:
251 // Tdelta = Tnew * Told.inverse
252 TGeoHMatrix deltaTransform
253 = AliMUONGeometryBuilder::Multiply(
255 detElement->GetGlobalTransformation()->Inverse());
257 // Create mis alignment matrix
258 newGeometryTransformer
259 ->AddMisAlignDetElement(detElement->GetId(), deltaTransform);
262 AliInfo(Form("Added module transformer %i to the transformer", iMt));
263 newGeometryTransformer->AddModuleTransformer(newModuleTransformer);
265 return newGeometryTransformer;