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