]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONGeometryMisAligner.cxx
Add buspatch length & change patch module interface needed for station 2
[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 #include "AliMUONGeometryMisAligner.h"
47 #include "AliMUONGeometryTransformer.h"
48 #include "AliMUONGeometryModuleTransformer.h"
49 #include "AliMUONGeometryDetElement.h"
50 #include "AliMUONGeometryBuilder.h"
51
52 #include "AliMpExMap.h"
53
54 #include "AliLog.h"
55
56 #include <TGeoMatrix.h>
57 #include <TMath.h>
58 #include <TRandom.h>
59 #include <Riostream.h>
60
61 /// \cond CLASSIMP
62 ClassImp(AliMUONGeometryMisAligner)
63 /// \endcond
64
65 //______________________________________________________________________________
66 AliMUONGeometryMisAligner::AliMUONGeometryMisAligner(Double_t cartXMisAligM, Double_t cartXMisAligW, Double_t cartYMisAligM, Double_t cartYMisAligW, Double_t angMisAligM, Double_t angMisAligW)
67   : TObject(),
68     fUseUni(kFALSE),
69     fUseGaus(kTRUE),
70     fXYAngMisAligFactor(0.0),
71     fZCartMisAligFactor(0.0),
72     fDisplacementGenerator(0)
73 {
74   /// Standard constructor
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
88   fDisplacementGenerator = new TRandom(0);
89 }
90
91 //______________________________________________________________________________
92 AliMUONGeometryMisAligner::AliMUONGeometryMisAligner(Double_t cartMisAligM, Double_t cartMisAligW, Double_t angMisAligM, Double_t angMisAligW)
93   : TObject(), 
94     fUseUni(kFALSE),
95     fUseGaus(kTRUE),
96     fXYAngMisAligFactor(0.0),
97     fZCartMisAligFactor(0.0),
98     fDisplacementGenerator(0)
99 {
100   /// Standard constructor
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
114   fDisplacementGenerator = new TRandom(0);
115 }
116
117 //______________________________________________________________________________
118 AliMUONGeometryMisAligner::AliMUONGeometryMisAligner(Double_t cartMisAlig, Double_t angMisAlig)
119   : TObject(), 
120     fUseUni(kTRUE),
121     fUseGaus(kFALSE),
122     fXYAngMisAligFactor(0.0),
123     fZCartMisAligFactor(0.0),
124     fDisplacementGenerator(0)
125 {
126   /// Standard constructor
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
137   fDisplacementGenerator = new TRandom(0);
138 }
139
140 //_____________________________________________________________________________
141 AliMUONGeometryMisAligner::AliMUONGeometryMisAligner()
142   : TObject(), 
143     fUseUni(kTRUE),
144     fUseGaus(kFALSE),
145     fXYAngMisAligFactor(0.0),
146     fZCartMisAligFactor(0.0),
147     fDisplacementGenerator(0)
148 {
149   /// Default constructor
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   }
156 }
157
158 //______________________________________________________________________________
159 AliMUONGeometryMisAligner::~AliMUONGeometryMisAligner()
160 {
161 /// Destructor
162
163   if (fDisplacementGenerator) delete fDisplacementGenerator;
164 }
165
166 //_________________________________________________________________________
167 void
168 AliMUONGeometryMisAligner::SetXYAngMisAligFactor(Double_t factor)
169 {
170   /// Set XY angular misalign factor 
171
172   if (TMath::Abs(factor) > 1.0 && factor > 0.){
173     fXYAngMisAligFactor = factor;
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   }
179   else
180     AliError(Form("Invalid XY angular misalign factor, %d", factor));
181 }
182
183 //_________________________________________________________________________
184 void AliMUONGeometryMisAligner::SetZCartMisAligFactor(Double_t factor) 
185 {
186   /// Set XY angular misalign factor 
187   if (TMath::Abs(factor)<1.0 && factor>0.) {
188     fZCartMisAligFactor = factor;
189     fDetElemMisAlig[2][0] = fDetElemMisAlig[0][0];        // These lines were added to 
190     fDetElemMisAlig[2][1] = fDetElemMisAlig[0][1]*factor; // keep backward compatibility
191   }
192   else
193     AliError(Form("Invalid Z cartesian misalign factor, %d", factor));
194 }
195
196 //_________________________________________________________________________
197 void AliMUONGeometryMisAligner::GetUniMisAlign(Double_t cartMisAlig[3], Double_t angMisAlig[3], const Double_t lParMisAlig[6][2]) const
198 {
199   /// Misalign using uniform distribution
200   /**
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   */
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]);  
212  
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
216 }
217
218 //_________________________________________________________________________
219 void AliMUONGeometryMisAligner::GetGausMisAlign(Double_t cartMisAlig[3], Double_t angMisAlig[3], const Double_t lParMisAlig[6][2]) const
220 {
221   /// Misalign using gaussian distribution
222   /**
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   */
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]);
234  
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
238 }
239
240 //_________________________________________________________________________
241 TGeoCombiTrans AliMUONGeometryMisAligner::MisAlignDetElem(const TGeoCombiTrans & transform) const
242 {
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) 
251   
252   Double_t cartMisAlig[3] = {0,0,0};
253   Double_t angMisAlig[3] = {0,0,0};
254
255   if (fUseUni) { 
256     GetUniMisAlign(cartMisAlig,angMisAlig,fDetElemMisAlig);
257   }
258   else { 
259     if (!fUseGaus) {
260       AliWarning("Neither uniform nor gausian distribution is set! Will use gausian...");
261     } 
262     GetGausMisAlign(cartMisAlig,angMisAlig,fDetElemMisAlig);
263   }
264
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     
274   AliInfo(Form("Rotated DE by %f about Z axis.", angMisAlig[2]));
275
276   return TGeoCombiTrans(newTransfMat);
277 }
278
279 //_________________________________________________________________________
280 TGeoCombiTrans 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) 
290   
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]);
309
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);
316 }
317
318 //______________________________________________________________________
319 AliMUONGeometryTransformer *
320 AliMUONGeometryMisAligner::MisAlign(const AliMUONGeometryTransformer *
321                                     transformer, Bool_t verbose)
322 {
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. 
331   /// Calculates misalignment parameters and applies these
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.
342
343
344   AliMUONGeometryTransformer *newGeometryTransformer =
345     new AliMUONGeometryTransformer();
346   for (Int_t iMt = 0; iMt < transformer->GetNofModuleTransformers(); iMt++)
347     {                           // module transformers
348       const AliMUONGeometryModuleTransformer *kModuleTransformer =
349         transformer->GetModuleTransformer(iMt, true);
350       
351       AliMUONGeometryModuleTransformer *newModuleTransformer =
352         new AliMUONGeometryModuleTransformer(iMt);
353       newGeometryTransformer->AddModuleTransformer(newModuleTransformer);
354
355       TGeoCombiTrans moduleTransform =
356         TGeoCombiTrans(*kModuleTransformer->GetTransformation());
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);
371
372       AliMpExMap *detElements = kModuleTransformer->GetDetElementStore();
373
374       if (verbose)
375         AliInfo(Form("%i DEs in old GeometryStore  %i",detElements->GetSize(), iMt));
376
377       for (Int_t iDe = 0; iDe < detElements->GetSize(); iDe++)
378         {                       // detection elements.
379           AliMUONGeometryDetElement *detElement =
380             (AliMUONGeometryDetElement *) detElements->GetObject(iDe);
381
382           if (!detElement)
383             AliFatal("Detection element not found.");
384
385           /// make a new detection element
386           AliMUONGeometryDetElement *newDetElement =
387             new AliMUONGeometryDetElement(detElement->GetId(),
388                                           detElement->GetVolumePath());
389
390           // local transformation of this detection element.
391           TGeoCombiTrans localTransform
392             = TGeoCombiTrans(*detElement->GetLocalTransformation());
393           TGeoCombiTrans newLocalTransform = MisAlignDetElem(localTransform);
394           newDetElement->SetLocalTransformation(newLocalTransform);
395
396
397           // global transformation
398           TGeoHMatrix newGlobalTransform =
399             AliMUONGeometryBuilder::Multiply(newModuleTransform,
400                                              newLocalTransform);
401           newDetElement->SetGlobalTransformation(newGlobalTransform);
402           
403           // add this det element to module
404           newModuleTransformer->GetDetElementStore()->Add(newDetElement->GetId(),
405                                                           newDetElement);
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: 
412           // Tdelta = Tnew * Told.inverse
413           TGeoHMatrix  deltaGlobalTransform
414             = AliMUONGeometryBuilder::Multiply(
415                 newGlobalTransform, 
416                 newOldGlobalTransform.Inverse());
417           
418           // Create mis alignment matrix
419           newGeometryTransformer
420             ->AddMisAlignDetElement(detElement->GetId(), deltaGlobalTransform);
421         }
422
423       
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