]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONGeometryMisAligner.cxx
In AliMUONRawStreamTriggerHP:
[u/mrichter/AliRoot.git] / MUON / AliMUONGeometryMisAligner.cxx
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 //-----------------------------------------------------------------------------
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 ///
44 /// \author Bruce Becker, Javier Castillo
45 //-----------------------------------------------------------------------------
46
47 #include "AliMUONGeometryMisAligner.h"
48 #include "AliMUONGeometryTransformer.h"
49 #include "AliMUONGeometryModuleTransformer.h"
50 #include "AliMUONGeometryDetElement.h"
51 #include "AliMUONGeometryBuilder.h"
52
53 #include "AliMpExMap.h"
54 #include "AliMpExMapIterator.h"
55
56 #include "AliLog.h"
57
58 #include <TGeoMatrix.h>
59 #include <TMath.h>
60 #include <TRandom.h>
61 #include <Riostream.h>
62
63 /// \cond CLASSIMP
64 ClassImp(AliMUONGeometryMisAligner)
65 /// \endcond
66
67 //______________________________________________________________________________
68 AliMUONGeometryMisAligner::AliMUONGeometryMisAligner(Double_t cartXMisAligM, Double_t cartXMisAligW, Double_t cartYMisAligM, Double_t cartYMisAligW, Double_t angMisAligM, Double_t angMisAligW)
69   : TObject(),
70     fUseUni(kFALSE),
71     fUseGaus(kTRUE),
72     fXYAngMisAligFactor(0.0),
73     fZCartMisAligFactor(0.0),
74     fDisplacementGenerator(0)
75 {
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;
81     }
82   }
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;
89
90   fDisplacementGenerator = new TRandom(0);
91 }
92
93 //______________________________________________________________________________
94 AliMUONGeometryMisAligner::AliMUONGeometryMisAligner(Double_t cartMisAligM, Double_t cartMisAligW, Double_t angMisAligM, Double_t angMisAligW)
95   : TObject(), 
96     fUseUni(kFALSE),
97     fUseGaus(kTRUE),
98     fXYAngMisAligFactor(0.0),
99     fZCartMisAligFactor(0.0),
100     fDisplacementGenerator(0)
101 {
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;
107     }
108   }
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;
115
116   fDisplacementGenerator = new TRandom(0);
117 }
118
119 //______________________________________________________________________________
120 AliMUONGeometryMisAligner::AliMUONGeometryMisAligner(Double_t cartMisAlig, Double_t angMisAlig)
121   : TObject(), 
122     fUseUni(kTRUE),
123     fUseGaus(kFALSE),
124     fXYAngMisAligFactor(0.0),
125     fZCartMisAligFactor(0.0),
126     fDisplacementGenerator(0)
127 {
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;
133     }
134   }
135   fDetElemMisAlig[0][1] = cartMisAlig; 
136   fDetElemMisAlig[1][1] = cartMisAlig; 
137   fDetElemMisAlig[5][1] = angMisAlig;
138
139   fDisplacementGenerator = new TRandom(0);
140 }
141
142 //_____________________________________________________________________________
143 AliMUONGeometryMisAligner::AliMUONGeometryMisAligner()
144   : TObject(), 
145     fUseUni(kTRUE),
146     fUseGaus(kFALSE),
147     fXYAngMisAligFactor(0.0),
148     fZCartMisAligFactor(0.0),
149     fDisplacementGenerator(0)
150 {
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;
156     }
157   }
158 }
159
160 //______________________________________________________________________________
161 AliMUONGeometryMisAligner::~AliMUONGeometryMisAligner()
162 {
163 /// Destructor
164
165   if (fDisplacementGenerator) delete fDisplacementGenerator;
166 }
167
168 //_________________________________________________________________________
169 void
170 AliMUONGeometryMisAligner::SetXYAngMisAligFactor(Double_t factor)
171 {
172   /// Set XY angular misalign factor 
173
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 
180   }
181   else
182     AliError(Form("Invalid XY angular misalign factor, %d", factor));
183 }
184
185 //_________________________________________________________________________
186 void AliMUONGeometryMisAligner::SetZCartMisAligFactor(Double_t factor) 
187 {
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
193   }
194   else
195     AliError(Form("Invalid Z cartesian misalign factor, %d", factor));
196 }
197
198 //_________________________________________________________________________
199 void AliMUONGeometryMisAligner::GetUniMisAlign(Double_t cartMisAlig[3], Double_t angMisAlig[3], const Double_t lParMisAlig[6][2]) const
200 {
201   /// Misalign using uniform distribution
202   /**
203     misalign the centre of the local transformation
204     rotation axes : 
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
209     plane is more free.
210   */
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]);  
214  
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
218 }
219
220 //_________________________________________________________________________
221 void AliMUONGeometryMisAligner::GetGausMisAlign(Double_t cartMisAlig[3], Double_t angMisAlig[3], const Double_t lParMisAlig[6][2]) const
222 {
223   /// Misalign using gaussian distribution
224   /**
225     misalign the centre of the local transformation
226     rotation axes : 
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
231     plane is more free.
232   */
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]);
236  
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
240 }
241
242 //_________________________________________________________________________
243 TGeoCombiTrans AliMUONGeometryMisAligner::MisAlignDetElem(const TGeoCombiTrans & transform) const
244 {
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) 
253   
254   Double_t cartMisAlig[3] = {0,0,0};
255   Double_t angMisAlig[3] = {0,0,0};
256
257   if (fUseUni) { 
258     GetUniMisAlign(cartMisAlig,angMisAlig,fDetElemMisAlig);
259   }
260   else { 
261     if (!fUseGaus) {
262       AliWarning("Neither uniform nor gausian distribution is set! Will use gausian...");
263     } 
264     GetGausMisAlign(cartMisAlig,angMisAlig,fDetElemMisAlig);
265   }
266
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]);
272
273   TGeoCombiTrans deltaTransf(deltaTrans,deltaRot);
274   TGeoHMatrix newTransfMat = transform * deltaTransf;
275     
276   AliInfo(Form("Rotated DE by %f about Z axis.", angMisAlig[2]));
277
278   return TGeoCombiTrans(newTransfMat);
279 }
280
281 //_________________________________________________________________________
282 TGeoCombiTrans AliMUONGeometryMisAligner::MisAlignModule(const TGeoCombiTrans & transform) const
283 {
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) 
292   
293   Double_t cartMisAlig[3] = {0,0,0};
294   Double_t angMisAlig[3] = {0,0,0};
295
296   if (fUseUni) { 
297     GetUniMisAlign(cartMisAlig,angMisAlig,fModuleMisAlig);
298   }
299   else { 
300     if (!fUseGaus) {
301       AliWarning("Neither uniform nor gausian distribution is set! Will use gausian...");
302     } 
303     GetGausMisAlign(cartMisAlig,angMisAlig,fModuleMisAlig);
304   }
305
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]);
311
312   TGeoCombiTrans deltaTransf(deltaTrans,deltaRot);
313   TGeoHMatrix newTransfMat = transform * deltaTransf;
314
315   AliInfo(Form("Rotated Module by %f about Z axis.", angMisAlig[2]));
316
317   return TGeoCombiTrans(newTransfMat);
318 }
319
320 //______________________________________________________________________
321 AliMUONGeometryTransformer *
322 AliMUONGeometryMisAligner::MisAlign(const AliMUONGeometryTransformer *
323                                     transformer, Bool_t verbose)
324 {
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.
344
345
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);
352       
353       AliMUONGeometryModuleTransformer *newModuleTransformer =
354         new AliMUONGeometryModuleTransformer(iMt);
355       newGeometryTransformer->AddModuleTransformer(newModuleTransformer);
356
357       TGeoCombiTrans moduleTransform =
358         TGeoCombiTrans(*kModuleTransformer->GetTransformation());
359       // New module transformation
360       TGeoCombiTrans newModuleTransform = MisAlignModule(moduleTransform);
361       newModuleTransformer->SetTransformation(newModuleTransform);
362
363       // Get delta transformation: 
364       // Tdelta = Tnew * Told.inverse
365       TGeoHMatrix deltaModuleTransform = 
366         AliMUONGeometryBuilder::Multiply(
367           newModuleTransform, 
368           kModuleTransformer->GetTransformation()->Inverse());
369
370       // Create module mis alignment matrix
371       newGeometryTransformer
372         ->AddMisAlignModule(kModuleTransformer->GetModuleId(), deltaModuleTransform);
373
374       AliMpExMap *detElements = kModuleTransformer->GetDetElementStore();
375
376       if (verbose)
377         AliInfo(Form("%i DEs in old GeometryStore  %i",detElements->GetSize(), iMt));
378
379       TIter next(detElements->CreateIterator());
380       AliMUONGeometryDetElement *detElement;
381       
382       while ( ( detElement = static_cast<AliMUONGeometryDetElement*>(next()) ) )
383       {
384           /// make a new detection element
385           AliMUONGeometryDetElement *newDetElement =
386             new AliMUONGeometryDetElement(detElement->GetId(),
387                                           detElement->GetVolumePath());
388
389           // local transformation of this detection element.
390           TGeoCombiTrans localTransform
391             = TGeoCombiTrans(*detElement->GetLocalTransformation());
392           TGeoCombiTrans newLocalTransform = MisAlignDetElem(localTransform);
393           newDetElement->SetLocalTransformation(newLocalTransform);
394
395
396           // global transformation
397           TGeoHMatrix newGlobalTransform =
398             AliMUONGeometryBuilder::Multiply(newModuleTransform,
399                                              newLocalTransform);
400           newDetElement->SetGlobalTransformation(newGlobalTransform);
401           
402           // add this det element to module
403           newModuleTransformer->GetDetElementStore()->Add(newDetElement->GetId(),
404                                                           newDetElement);
405
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(
414                 newGlobalTransform, 
415                 newOldGlobalTransform.Inverse());
416           
417           // Create mis alignment matrix
418           newGeometryTransformer
419             ->AddMisAlignDetElement(detElement->GetId(), deltaGlobalTransform);
420         }
421
422       
423       if (verbose)
424         AliInfo(Form("Added module transformer %i to the transformer", iMt));
425       newGeometryTransformer->AddModuleTransformer(newModuleTransformer);
426     }
427   return newGeometryTransformer;
428 }
429
430
431
432