]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONGeometryMisAligner.cxx
Corrected mapping management group definition
[u/mrichter/AliRoot.git] / MUON / AliMUONGeometryMisAligner.cxx
CommitLineData
21dd83fc 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. *
6 * *
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 **************************************************************************/
15
16// $Id$
17//
18// Class AliMUONGeometryMisAligner
19// ----------------------------
20// Class for misalignment of geometry transformations
21//
22// Author:Bruce Becker
23
24//__________________________________________________________________
25//
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
30//
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
41// of microns)
42
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.
48
21dd83fc 49#include "AliMUONGeometryMisAligner.h"
50#include "AliMUONGeometryTransformer.h"
51#include "AliMUONGeometryModuleTransformer.h"
52#include "AliMUONGeometryDetElement.h"
53#include "AliMUONGeometryStore.h"
54#include "AliMUONGeometryBuilder.h"
ef79ed3a 55
56#include "AliLog.h"
57
21dd83fc 58#include <TGeoManager.h>
59#include <Riostream.h>
60#include <TObjArray.h>
61#include <TSystem.h>
62#include <TMath.h>
63#include <TRandom.h>
64
21dd83fc 65#include <sstream>
66
67ClassImp(AliMUONGeometryMisAligner)
68//______________________________________________________________________________
69AliMUONGeometryMisAligner::AliMUONGeometryMisAligner(Double_t cartMisAlig, Double_t angMisAlig)
70:TObject(), fDisplacementGenerator(0)
71{
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);
77}
78
79//_____________________________________________________________________________
80AliMUONGeometryMisAligner::AliMUONGeometryMisAligner()
81:TObject(), fDisplacementGenerator(0)
82{
83/// Default constructor
84}
85
86//______________________________________________________________________________
87AliMUONGeometryMisAligner::
88AliMUONGeometryMisAligner(const AliMUONGeometryMisAligner & right):
89TObject(right)
90{
91 /// Copy constructor (not implemented)
92
93 AliFatal("Copy constructor not provided.");
94}
95
96//______________________________________________________________________________
97AliMUONGeometryMisAligner::~AliMUONGeometryMisAligner()
98{
99/// Destructor
100
101 delete fDisplacementGenerator;
102}
103
104//______________________________________________________________________________
105AliMUONGeometryMisAligner & AliMUONGeometryMisAligner::
106operator=(const AliMUONGeometryMisAligner & right)
107{
108 /// Assignement operator (not implemented)
109
110 // check assignement to self
111 if (this == &right)
112 return *this;
113
114 AliFatal("Assignement operator not provided.");
115
116 return *this;
117}
118
119void
120AliMUONGeometryMisAligner::SetXYAngMisAligFactor(Double_t factor)
121{
122 if (TMath::Abs(factor) > 1.0 && factor > 0.)
123 fXYAngMisAligFactor = factor;
124 else
125 AliError(Form("Invalid factor, %d", factor));
126}
127
128//_________________________________________________________________________
129TGeoCombiTrans AliMUONGeometryMisAligner::MisAlign(const TGeoCombiTrans & transform) const
130{
131 /// Misalign given transformation and return the misaligned transformation
132
133 Double_t cartMisAlig[3] = {0,0,0};
134 Double_t angMisAlig[3] = {0,0,0};
135 const Double_t *trans = transform.GetTranslation();
136 TGeoRotation *rot;
137 // check if the rotation we obtain is not NULL
138 if (transform.GetRotation())
139 {
140 rot = transform.GetRotation();
141 }
142 else
143 {
144 rot = new TGeoRotation("rot");
145 } // default constructor.
146
147 cartMisAlig[0] = fDisplacementGenerator->Uniform(-1. * fMaxCartMisAlig, fMaxCartMisAlig);
148 cartMisAlig[1] = fDisplacementGenerator->Uniform(-1. * fMaxCartMisAlig, fMaxCartMisAlig);
149 cartMisAlig[2] = fDisplacementGenerator->Uniform(-1. * fMaxCartMisAlig, fMaxCartMisAlig);
150
151 TGeoTranslation newTrans(cartMisAlig[0] + trans[0], cartMisAlig[1] + trans[1], cartMisAlig[2] + trans[2]);
152
153 /*
154 misalign the centre of the local transformation
155 rotation axes :
156 fAngMisAlig[1,2,3] = [x,y,z]
157 Assume that misalignment about the x and y axes (misalignment of z plane)
158 is much smaller, since the entire detection plane has to be moved (the
159 detection elements are on a support structure), while rotation of the x-y
160 plane is more free.
161 */
162
163 angMisAlig[0] = fDisplacementGenerator->Uniform(fXYAngMisAligFactor * fMaxAngMisAlig, 1.0 * fMaxAngMisAlig);
164 angMisAlig[1] = fDisplacementGenerator->Uniform(fXYAngMisAligFactor * fMaxAngMisAlig, 1.0 * fMaxAngMisAlig);
165 angMisAlig[2] = fDisplacementGenerator->Uniform(-1. * fMaxAngMisAlig, fMaxAngMisAlig); // degrees
166 AliInfo(Form("Rotated by %f about Z axis.", angMisAlig[2]));
167 rot->RotateX(angMisAlig[0]);
168 rot->RotateY(angMisAlig[1]);
169 rot->RotateZ(angMisAlig[2]);
170
171 return TGeoCombiTrans(newTrans, *rot);
172}
173
174
175//______________________________________________________________________
176AliMUONGeometryTransformer *
177AliMUONGeometryMisAligner::MisAlign(const AliMUONGeometryTransformer *
178 transformer, Bool_t verbose)
179{
180 /////////////////////////////////////////////////////////////////////
181 // Takes the internal geometry module transformers, copies them
182 // and gets the Detection Elements from them.
183 // Calculates misalignment parameters and applies these
184 // to the local transform of the Detection Element
185 // Obtains the global transform by multiplying the module transformer
186 // transformation with the local transformation
187 // Applies the global transform to a new detection element
188 // Adds the new detection element to a new module transformer
189 // Adds the new module transformer to a new geometry transformer
190 // Returns the new geometry transformer
191
192
193 AliMUONGeometryTransformer *newGeometryTransformer =
194 new AliMUONGeometryTransformer(kTRUE);
195 for (Int_t iMt = 0; iMt < transformer->GetNofModuleTransformers(); iMt++)
196 { // module transformers
197
198 const AliMUONGeometryModuleTransformer *kModuleTransformer =
199 transformer->GetModuleTransformer(iMt, true);
200
201 AliMUONGeometryModuleTransformer *newModuleTransformer =
202 new AliMUONGeometryModuleTransformer(iMt);
203 newGeometryTransformer->AddModuleTransformer(newModuleTransformer);
204
ef79ed3a 205 TGeoCombiTrans moduleTransform =
206 TGeoCombiTrans(*kModuleTransformer->GetTransformation());
207 TGeoCombiTrans *newModuleTransform = new TGeoCombiTrans(moduleTransform);
208 // same module transform as the previous one
209 // no mis align object created
210 newModuleTransformer->SetTransformation(moduleTransform);
21dd83fc 211
212 AliMUONGeometryStore *detElements =
213 kModuleTransformer->GetDetElementStore();
214
215 if (verbose)
216 AliInfo(Form
217 ("%i DEs in old GeometryStore %i",
218 detElements->GetNofEntries(), iMt));
219
220 for (Int_t iDe = 0; iDe < detElements->GetNofEntries(); iDe++)
221 { // detection elements.
222 AliMUONGeometryDetElement *detElement =
223 (AliMUONGeometryDetElement *) detElements->GetEntry(iDe);
224 if (!detElement)
225 AliFatal("Detection element not found.");
226
ef79ed3a 227 /// make a new detection element
21dd83fc 228 AliMUONGeometryDetElement *newDetElement =
229 new AliMUONGeometryDetElement(detElement->GetId(),
ef79ed3a 230 detElement->GetVolumePath());
21dd83fc 231
ef79ed3a 232 // local transformation of this detection element.
233 TGeoCombiTrans localTransform
234 = TGeoCombiTrans(*detElement->GetLocalTransformation());
235 TGeoCombiTrans newLocalTransform = MisAlign(localTransform);
236 newDetElement->SetLocalTransformation(newLocalTransform);
21dd83fc 237
ef79ed3a 238 // global transformation
239 TGeoHMatrix newGlobalTransform =
240 AliMUONGeometryBuilder::Multiply(*newModuleTransform,
241 newLocalTransform);
21dd83fc 242 newDetElement->SetGlobalTransformation(newGlobalTransform);
ef79ed3a 243
244 // add this det element to module
245 newModuleTransformer->GetDetElementStore()->Add(newDetElement->GetId(),
21dd83fc 246 newDetElement);
ef79ed3a 247 // Get delta transformation:
248 // Tdelta = Tnew * Told.inverse
249 TGeoHMatrix deltaTransform
250 = AliMUONGeometryBuilder::Multiply(
251 newGlobalTransform,
252 detElement->GetGlobalTransformation()->Inverse());
253
254 // Create mis alignment matrix
255 newGeometryTransformer
256 ->AddMisAlignDetElement(detElement->GetId(), deltaTransform);
21dd83fc 257 }
258 if (verbose)
259 AliInfo(Form("Added module transformer %i to the transformer", iMt));
260 newGeometryTransformer->AddModuleTransformer(newModuleTransformer);
261 }
262 return newGeometryTransformer;
263}
264
265
266
267