]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONGeometryMisAligner.cxx
More robust raw-reader for HLT
[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//
21dd83fc 18//__________________________________________________________________
a9aad96e 19/// \class AliMUONGeometryMisAligner
20///
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
24///
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)
28///
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
36/// of microns)
37///
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.
43///
4600314b 44/// \author Bruce Becker, Javier Castillo
21dd83fc 45
21dd83fc 46#include "AliMUONGeometryMisAligner.h"
47#include "AliMUONGeometryTransformer.h"
48#include "AliMUONGeometryModuleTransformer.h"
49#include "AliMUONGeometryDetElement.h"
21dd83fc 50#include "AliMUONGeometryBuilder.h"
ef79ed3a 51
8c95578a 52#include "AliMpExMap.h"
53
ef79ed3a 54#include "AliLog.h"
55
328e160e 56#include <TGeoMatrix.h>
21dd83fc 57#include <TMath.h>
58#include <TRandom.h>
ef4cb4f1 59#include <Riostream.h>
21dd83fc 60
a9aad96e 61/// \cond CLASSIMP
21dd83fc 62ClassImp(AliMUONGeometryMisAligner)
a9aad96e 63/// \endcond
64
328e160e 65//______________________________________________________________________________
66AliMUONGeometryMisAligner::AliMUONGeometryMisAligner(Double_t cartXMisAligM, Double_t cartXMisAligW, Double_t cartYMisAligM, Double_t cartYMisAligW, Double_t angMisAligM, Double_t angMisAligW)
8395bff1 67 : TObject(),
68 fUseUni(kFALSE),
69 fUseGaus(kTRUE),
8395bff1 70 fXYAngMisAligFactor(0.0),
71 fZCartMisAligFactor(0.0),
72 fDisplacementGenerator(0)
328e160e 73{
74 /// Standard constructor
4600314b 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;
79 }
80 }
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;
87
328e160e 88 fDisplacementGenerator = new TRandom(0);
328e160e 89}
90
91//______________________________________________________________________________
92AliMUONGeometryMisAligner::AliMUONGeometryMisAligner(Double_t cartMisAligM, Double_t cartMisAligW, Double_t angMisAligM, Double_t angMisAligW)
8395bff1 93 : TObject(),
94 fUseUni(kFALSE),
95 fUseGaus(kTRUE),
8395bff1 96 fXYAngMisAligFactor(0.0),
97 fZCartMisAligFactor(0.0),
98 fDisplacementGenerator(0)
328e160e 99{
100 /// Standard constructor
4600314b 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;
105 }
106 }
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;
113
328e160e 114 fDisplacementGenerator = new TRandom(0);
328e160e 115}
116
21dd83fc 117//______________________________________________________________________________
118AliMUONGeometryMisAligner::AliMUONGeometryMisAligner(Double_t cartMisAlig, Double_t angMisAlig)
8395bff1 119 : TObject(),
120 fUseUni(kTRUE),
121 fUseGaus(kFALSE),
8395bff1 122 fXYAngMisAligFactor(0.0),
123 fZCartMisAligFactor(0.0),
124 fDisplacementGenerator(0)
21dd83fc 125{
126 /// Standard constructor
4600314b 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;
131 }
132 }
133 fDetElemMisAlig[0][1] = cartMisAlig;
134 fDetElemMisAlig[1][1] = cartMisAlig;
135 fDetElemMisAlig[5][1] = angMisAlig;
136
21dd83fc 137 fDisplacementGenerator = new TRandom(0);
138}
139
140//_____________________________________________________________________________
141AliMUONGeometryMisAligner::AliMUONGeometryMisAligner()
8395bff1 142 : TObject(),
143 fUseUni(kTRUE),
144 fUseGaus(kFALSE),
8395bff1 145 fXYAngMisAligFactor(0.0),
146 fZCartMisAligFactor(0.0),
147 fDisplacementGenerator(0)
21dd83fc 148{
8395bff1 149 /// Default constructor
4600314b 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;
154 }
155 }
21dd83fc 156}
157
21dd83fc 158//______________________________________________________________________________
159AliMUONGeometryMisAligner::~AliMUONGeometryMisAligner()
160{
161/// Destructor
162
8395bff1 163 if (fDisplacementGenerator) delete fDisplacementGenerator;
21dd83fc 164}
165
490da820 166//_________________________________________________________________________
21dd83fc 167void
168AliMUONGeometryMisAligner::SetXYAngMisAligFactor(Double_t factor)
169{
328e160e 170 /// Set XY angular misalign factor
490da820 171
4600314b 172 if (TMath::Abs(factor) > 1.0 && factor > 0.){
21dd83fc 173 fXYAngMisAligFactor = factor;
4600314b 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
178 }
21dd83fc 179 else
328e160e 180 AliError(Form("Invalid XY angular misalign factor, %d", factor));
181}
182
183//_________________________________________________________________________
184void AliMUONGeometryMisAligner::SetZCartMisAligFactor(Double_t factor)
185{
186 /// Set XY angular misalign factor
4600314b 187 if (TMath::Abs(factor)<1.0 && factor>0.) {
328e160e 188 fZCartMisAligFactor = factor;
4600314b 189 fDetElemMisAlig[2][0] = fDetElemMisAlig[0][0]; // These lines were added to
190 fDetElemMisAlig[2][1] = fDetElemMisAlig[0][1]*factor; // keep backward compatibility
191 }
328e160e 192 else
193 AliError(Form("Invalid Z cartesian misalign factor, %d", factor));
194}
195
196//_________________________________________________________________________
4600314b 197void AliMUONGeometryMisAligner::GetUniMisAlign(Double_t cartMisAlig[3], Double_t angMisAlig[3], const Double_t lParMisAlig[6][2]) const
328e160e 198{
199 /// Misalign using uniform distribution
a9aad96e 200 /**
328e160e 201 misalign the centre of the local transformation
202 rotation axes :
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
207 plane is more free.
208 */
4600314b 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]);
328e160e 212
4600314b 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
328e160e 216}
217
218//_________________________________________________________________________
4600314b 219void AliMUONGeometryMisAligner::GetGausMisAlign(Double_t cartMisAlig[3], Double_t angMisAlig[3], const Double_t lParMisAlig[6][2]) const
328e160e 220{
221 /// Misalign using gaussian distribution
a9aad96e 222 /**
328e160e 223 misalign the centre of the local transformation
224 rotation axes :
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
229 plane is more free.
230 */
4600314b 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]);
328e160e 234
4600314b 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
21dd83fc 238}
239
240//_________________________________________________________________________
4600314b 241TGeoCombiTrans AliMUONGeometryMisAligner::MisAlignDetElem(const TGeoCombiTrans & transform) const
21dd83fc 242{
4600314b 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)
21dd83fc 251
252 Double_t cartMisAlig[3] = {0,0,0};
253 Double_t angMisAlig[3] = {0,0,0};
328e160e 254
255 if (fUseUni) {
4600314b 256 GetUniMisAlign(cartMisAlig,angMisAlig,fDetElemMisAlig);
328e160e 257 }
258 else {
259 if (!fUseGaus) {
260 AliWarning("Neither uniform nor gausian distribution is set! Will use gausian...");
261 }
4600314b 262 GetGausMisAlign(cartMisAlig,angMisAlig,fDetElemMisAlig);
328e160e 263 }
264
4600314b 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]);
270
271 TGeoCombiTrans deltaTransf(deltaTrans,deltaRot);
272 TGeoHMatrix newTransfMat = transform * deltaTransf;
273
ef4cb4f1 274 AliInfo(Form("Rotated DE by %f about Z axis.", angMisAlig[2]));
4600314b 275
276 return TGeoCombiTrans(newTransfMat);
277}
278
279//_________________________________________________________________________
280TGeoCombiTrans AliMUONGeometryMisAligner::MisAlignModule(const TGeoCombiTrans & transform) const
281{
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)
21dd83fc 290
4600314b 291 Double_t cartMisAlig[3] = {0,0,0};
292 Double_t angMisAlig[3] = {0,0,0};
293
294 if (fUseUni) {
295 GetUniMisAlign(cartMisAlig,angMisAlig,fModuleMisAlig);
296 }
297 else {
298 if (!fUseGaus) {
299 AliWarning("Neither uniform nor gausian distribution is set! Will use gausian...");
300 }
301 GetGausMisAlign(cartMisAlig,angMisAlig,fModuleMisAlig);
302 }
303
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]);
21dd83fc 309
4600314b 310 TGeoCombiTrans deltaTransf(deltaTrans,deltaRot);
311 TGeoHMatrix newTransfMat = transform * deltaTransf;
312
313 AliInfo(Form("Rotated Module by %f about Z axis.", angMisAlig[2]));
314
315 return TGeoCombiTrans(newTransfMat);
21dd83fc 316}
317
21dd83fc 318//______________________________________________________________________
319AliMUONGeometryTransformer *
320AliMUONGeometryMisAligner::MisAlign(const AliMUONGeometryTransformer *
4600314b 321 transformer, Bool_t verbose)
21dd83fc 322{
4600314b 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.
a9aad96e 331 /// Calculates misalignment parameters and applies these
4600314b 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.
21dd83fc 342
343
344 AliMUONGeometryTransformer *newGeometryTransformer =
ef4cb4f1 345 new AliMUONGeometryTransformer();
21dd83fc 346 for (Int_t iMt = 0; iMt < transformer->GetNofModuleTransformers(); iMt++)
347 { // module transformers
21dd83fc 348 const AliMUONGeometryModuleTransformer *kModuleTransformer =
349 transformer->GetModuleTransformer(iMt, true);
350
351 AliMUONGeometryModuleTransformer *newModuleTransformer =
352 new AliMUONGeometryModuleTransformer(iMt);
353 newGeometryTransformer->AddModuleTransformer(newModuleTransformer);
354
ef79ed3a 355 TGeoCombiTrans moduleTransform =
356 TGeoCombiTrans(*kModuleTransformer->GetTransformation());
4600314b 357 // New module transformation
358 TGeoCombiTrans newModuleTransform = MisAlignModule(moduleTransform);
359 newModuleTransformer->SetTransformation(newModuleTransform);
360
361 // Get delta transformation:
362 // Tdelta = Tnew * Told.inverse
363 TGeoHMatrix deltaModuleTransform =
364 AliMUONGeometryBuilder::Multiply(
365 newModuleTransform,
366 kModuleTransformer->GetTransformation()->Inverse());
367
368 // Create module mis alignment matrix
369 newGeometryTransformer
370 ->AddMisAlignModule(kModuleTransformer->GetModuleId(), deltaModuleTransform);
21dd83fc 371
8c95578a 372 AliMpExMap *detElements = kModuleTransformer->GetDetElementStore();
21dd83fc 373
374 if (verbose)
4600314b 375 AliInfo(Form("%i DEs in old GeometryStore %i",detElements->GetSize(), iMt));
21dd83fc 376
8c95578a 377 for (Int_t iDe = 0; iDe < detElements->GetSize(); iDe++)
21dd83fc 378 { // detection elements.
379 AliMUONGeometryDetElement *detElement =
8c95578a 380 (AliMUONGeometryDetElement *) detElements->GetObject(iDe);
4600314b 381
21dd83fc 382 if (!detElement)
383 AliFatal("Detection element not found.");
384
ef79ed3a 385 /// make a new detection element
21dd83fc 386 AliMUONGeometryDetElement *newDetElement =
387 new AliMUONGeometryDetElement(detElement->GetId(),
ef79ed3a 388 detElement->GetVolumePath());
21dd83fc 389
ef79ed3a 390 // local transformation of this detection element.
391 TGeoCombiTrans localTransform
392 = TGeoCombiTrans(*detElement->GetLocalTransformation());
4600314b 393 TGeoCombiTrans newLocalTransform = MisAlignDetElem(localTransform);
394 newDetElement->SetLocalTransformation(newLocalTransform);
395
21dd83fc 396
ef79ed3a 397 // global transformation
398 TGeoHMatrix newGlobalTransform =
4600314b 399 AliMUONGeometryBuilder::Multiply(newModuleTransform,
400 newLocalTransform);
21dd83fc 401 newDetElement->SetGlobalTransformation(newGlobalTransform);
ef79ed3a 402
403 // add this det element to module
404 newModuleTransformer->GetDetElementStore()->Add(newDetElement->GetId(),
21dd83fc 405 newDetElement);
4600314b 406
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:
ef79ed3a 412 // Tdelta = Tnew * Told.inverse
4600314b 413 TGeoHMatrix deltaGlobalTransform
ef79ed3a 414 = AliMUONGeometryBuilder::Multiply(
415 newGlobalTransform,
4600314b 416 newOldGlobalTransform.Inverse());
ef79ed3a 417
418 // Create mis alignment matrix
419 newGeometryTransformer
4600314b 420 ->AddMisAlignDetElement(detElement->GetId(), deltaGlobalTransform);
21dd83fc 421 }
4600314b 422
423
21dd83fc 424 if (verbose)
425 AliInfo(Form("Added module transformer %i to the transformer", iMt));
426 newGeometryTransformer->AddModuleTransformer(newModuleTransformer);
427 }
428 return newGeometryTransformer;
429}
430
431
432
433