]>
Commit | Line | Data |
---|---|---|
4c039060 | 1 | /************************************************************************** |
2 | * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * | |
3 | * * | |
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 purpose. It is * | |
13 | * provided "as is" without express or implied warranty. * | |
14 | **************************************************************************/ | |
15 | ||
88cb7938 | 16 | /* $Id$ */ |
4c039060 | 17 | |
58005f18 | 18 | /////////////////////////////////////////////////////////////////////// |
593e9459 | 19 | // ITS geometry manipulation routines. // |
58005f18 | 20 | // Created April 15 1999. // |
21 | // version: 0.0.0 // | |
22 | // By: Bjorn S. Nilsen // | |
23 | // version: 0.0.1 // | |
24 | // Updated May 27 1999. // | |
593e9459 | 25 | // Added Cylindrical random and global based changes. // |
58005f18 | 26 | // Added function PrintComparison. // |
27 | /////////////////////////////////////////////////////////////////////// | |
593e9459 | 28 | |
29 | ||
30 | //////////////////////////////////////////////////////////////////////// | |
593e9459 | 31 | // The local coordinate system by, default, is show in the following |
32 | // figures. Also shown are the ladder numbering scheme. | |
33 | //Begin_Html | |
34 | /* | |
269f57ed | 35 | <img src="picts/ITS/AliITSgeomMatrix_L1.gif"> |
36 | </pre> | |
37 | <br clear=left> | |
38 | <font size=+2 color=blue> | |
39 | <p>This shows the relative geometry differences between the ALICE Global | |
40 | coordinate system and the local detector coordinate system. | |
41 | </font> | |
42 | <pre> | |
43 | ||
44 | <pre> | |
593e9459 | 45 | <img src="picts/ITS/its1+2_convention_front_5.gif"> |
46 | </pre> | |
47 | <br clear=left> | |
48 | <font size=+2 color=blue> | |
49 | <p>This shows the front view of the SPDs and the orientation of the local | |
50 | pixel coordinate system. Note that the inner pixel layer has its y coordinate | |
51 | in the opposite direction from all of the other layers. | |
52 | </font> | |
53 | <pre> | |
54 | ||
55 | <pre> | |
56 | <img src="picts/ITS/its3+4_convention_front_5.gif"> | |
57 | </pre> | |
58 | <br clear=left> | |
59 | <font size=+2 color=blue> | |
60 | <p>This shows the front view of the SDDs and the orientation of the local | |
61 | pixel coordinate system. | |
62 | </font> | |
63 | <pre> | |
64 | ||
65 | <pre> | |
66 | <img src="picts/ITS/its5+6_convention_front_5.gif"> | |
67 | </pre> | |
68 | <br clear=left> | |
69 | <font size=+2 color=blue> | |
70 | <p>This shows the front view of the SSDs and the orientation of the local | |
71 | pixel coordinate system. | |
72 | </font> | |
73 | <pre> | |
74 | */ | |
75 | //End_Html | |
269f57ed | 76 | // |
593e9459 | 77 | //////////////////////////////////////////////////////////////////////// |
78 | ||
79 | //////////////////////////////////////////////////////////////////////// | |
80 | // | |
81 | // version: 0 | |
82 | // Written by Bjorn S. Nilsen | |
83 | // | |
84 | // Data Members: | |
85 | // | |
86 | // Int_t fNlayers | |
87 | // The number of ITS layers for this geometry. By default this | |
88 | // is 6, but can be modified by the creator function if there are | |
89 | // more layers defined. | |
90 | // | |
91 | // Int_t *fNlad | |
92 | // A pointer to an array fNlayers long containing the number of | |
93 | // ladders for each layer. This array is typically created and filled | |
94 | // by the AliITSgeom creator function. | |
95 | // | |
96 | // Int_t *fNdet | |
97 | // A pointer to an array fNlayers long containing the number of | |
98 | // active detector volumes for each ladder. This array is typically | |
99 | // created and filled by the AliITSgeom creator function. | |
100 | // | |
269f57ed | 101 | // AliITSgeomMatrix *fGm |
102 | // A pointer to an array of AliITSgeomMatrix classes. One element | |
103 | // per module (detector) in the ITS. AliITSgeomMatrix basicly contains | |
104 | // all of the necessary information about the detector and it's coordinate | |
105 | // transformations. | |
593e9459 | 106 | // |
107 | // TObjArray *fShape | |
108 | // A pointer to an array of TObjects containing the detailed shape | |
109 | // information for each type of detector used in the ITS. For example | |
110 | // I have created AliITSgeomSPD, AliITSgeomSDD, and AliITSgeomSSD as | |
111 | // example structures, derived from TObjects, to hold the detector | |
112 | // information. I would recommend that one element in each of these | |
113 | // structures, that which describes the shape of the active volume, | |
114 | // be one of the ROOT classes derived from TShape. In this way it would | |
115 | // be easy to have the display program display the correct active | |
116 | // ITS volumes. See the example classes AliITSgeomSPD, AliITSgeomSDD, | |
117 | // and AliITSgeomSSD for a more detailed example. | |
593e9459 | 118 | //////////////////////////////////////////////////////////////////////// |
4ae5bbc4 | 119 | #include <Riostream.h> |
8253cd9a | 120 | |
269f57ed | 121 | #include <TRandom.h> |
f77f13c8 | 122 | #include <TSystem.h> |
e8189707 | 123 | |
58005f18 | 124 | #include "AliITSgeom.h" |
269f57ed | 125 | #include "AliITSgeomSDD.h" |
f77f13c8 | 126 | #include "AliITSgeomSPD.h" |
269f57ed | 127 | #include "AliITSgeomSSD.h" |
f77f13c8 | 128 | #include "AliLog.h" |
58005f18 | 129 | |
130 | ClassImp(AliITSgeom) | |
131 | ||
85f1e34a | 132 | //______________________________________________________________________ |
58005f18 | 133 | AliITSgeom::AliITSgeom(){ |
85f1e34a | 134 | // The default constructor for the AliITSgeom class. It, by default, |
135 | // sets fNlayers to zero and zeros all pointers. | |
136 | // Do not allocate anything zero everything. | |
137 | ||
8253cd9a | 138 | fTrans = 0; // standard GEANT global/local coordinate system. |
139 | fNlayers = 0; | |
140 | fNlad = 0; | |
141 | fNdet = 0; | |
142 | fGm = 0; | |
143 | fShape = 0; | |
144 | strcpy(fVersion,"test"); | |
145 | return; | |
146 | } | |
85f1e34a | 147 | //______________________________________________________________________ |
8253cd9a | 148 | AliITSgeom::AliITSgeom(Int_t itype,Int_t nlayers,Int_t *nlads,Int_t *ndets, |
149 | Int_t mods){ | |
85f1e34a | 150 | // A simple constructor to set basic geometry class variables |
151 | // Inputs: | |
152 | // Int_t itype the type of transformation kept. | |
153 | // bit 0 => Standard GEANT | |
154 | // bit 1 => ITS tracking | |
155 | // bit 2 => A change in the coordinate system has been made. | |
156 | // others are still to be defined as needed. | |
157 | // Int_t nlayers The number of ITS layers also set the size of the arrays | |
158 | // Int_t *nlads an array of the number of ladders for each layer. This | |
159 | // array must be nlayers long. | |
160 | // Int_t *ndets an array of the number of detectors per ladder for each | |
161 | // layer. This array must be nlayers long. | |
162 | // Int_t mods The number of modules. Typicaly the sum of all the | |
163 | // detectors on every layer and ladder. | |
164 | // Outputs: | |
165 | // none | |
8253cd9a | 166 | Int_t i; |
167 | ||
168 | fTrans = itype; | |
169 | fNlayers = nlayers; | |
170 | fNlad = new Int_t[nlayers]; | |
171 | fNdet = new Int_t[nlayers]; | |
172 | for(i=0;i<nlayers;i++){fNlad[i] = nlads[i];fNdet[i] = ndets[i];} | |
173 | fNmodules = mods; | |
174 | fGm = new TObjArray(mods,0); | |
5c9c741e | 175 | fShape = new TObjArray(5); // default value |
176 | for(i=0;i<5;i++) fShape->AddAt(0,i); | |
8253cd9a | 177 | strcpy(fVersion,"test"); |
178 | return; | |
58005f18 | 179 | } |
8253cd9a | 180 | //______________________________________________________________________ |
181 | void AliITSgeom::CreatMatrix(Int_t mod,Int_t lay,Int_t lad,Int_t det, | |
85f1e34a | 182 | AliITSDetector idet,const Double_t tran[3], |
183 | const Double_t rot[10]){ | |
184 | // Given the translation vector tran[3] and the rotation matrix rot[1], | |
185 | // this function creates and adds to the TObject Array fGm the | |
186 | // AliITSgeomMatrix object. | |
187 | // Inputs are: | |
188 | // Int_t mod The module number. The location in TObjArray | |
189 | // Int_t lay The layer where this module is | |
190 | // Int_t lad On which ladder this module is | |
191 | // Int_t det Which detector on this ladder this module is | |
192 | // AliITSDetector idet The type of detector see AliITSgeom.h | |
193 | // Double_t tran[3] The translation vector | |
194 | // Double_t rot[10] The rotation matrix. | |
195 | // Outputs are: | |
196 | // none | |
197 | // The rot[10] matrix is set up like: | |
198 | /* / rot[0] rot[1] rot[2] \ | |
199 | // | rot[3] rot[4] rot[5] | | |
200 | // \ rot[6] rot[7] rot[8] / if(rot[9]!=0) then the Identity matrix | |
201 | // is used regardless of the values in rot[0]-rot[8]. | |
202 | */ | |
8253cd9a | 203 | Int_t id[3]; |
204 | Double_t r[3][3] = {{1.0,0.0,0.0},{0.0,1.0,0.0},{0.0,0.0,1.0}}; | |
58005f18 | 205 | |
8253cd9a | 206 | if(fGm->At(mod)!=0) delete fGm->At(mod); |
207 | id[0] = lay; id[1] = lad; id[2] = det; | |
208 | if(rot[9]!=0.0) { // null rotation | |
209 | r[0][0] = rot[0]; r[0][1] = rot[1]; r[0][2] = rot[2]; | |
210 | r[1][0] = rot[3]; r[1][1] = rot[4]; r[1][2] = rot[5]; | |
211 | r[2][0] = rot[6]; r[2][1] = rot[7]; r[2][2] = rot[8]; | |
212 | } // end if | |
213 | fGm->AddAt(new AliITSgeomMatrix(idet,id,r,tran),mod); | |
214 | } | |
85f1e34a | 215 | //______________________________________________________________________ |
58005f18 | 216 | AliITSgeom::~AliITSgeom(){ |
85f1e34a | 217 | // The destructor for the AliITSgeom class. If the arrays fNlad, |
218 | // fNdet, or fGm have had memory allocated to them, there pointer values | |
219 | // are non zero, then this memory space is freed and they are set | |
220 | // to zero. In addition, fNlayers is set to zero. The destruction of | |
221 | // TObjArray fShape is, by default, handled by the TObjArray destructor. | |
222 | ||
085bb6ed | 223 | if(fGm!=0){ |
36583d28 | 224 | //for(Int_t i=0;i<fNlayers;i++) delete fGm->At(i); |
225 | fGm->Delete(); | |
8253cd9a | 226 | delete fGm; |
085bb6ed | 227 | } // end if fGm!=0 |
58005f18 | 228 | if(fNlad!=0) delete[] fNlad; |
229 | if(fNdet!=0) delete[] fNdet; | |
230 | fNlayers = 0; | |
231 | fNlad = 0; | |
232 | fNdet = 0; | |
269f57ed | 233 | fGm = 0; |
58005f18 | 234 | return; |
235 | } | |
269f57ed | 236 | //______________________________________________________________________ |
237 | void AliITSgeom::ReadNewFile(const char *filename){ | |
85f1e34a | 238 | // It is generaly preferred to define the geometry in AliITSgeom |
239 | // directly from the GEANT geometry, see AliITSvPPRasymm.cxx for | |
240 | // and example. Under some circumstances this may not be possible. | |
241 | // This function will read in a formatted file for all of the | |
242 | // information needed to define the geometry in AliITSgeom. | |
243 | // Unlike the older file format, this file may contain comments | |
244 | // and the order of the data does not need to be completely | |
245 | // respected. A file can be created using the function WriteNewFile | |
246 | // defined below. | |
247 | // Inputs are: | |
248 | // const char *filename The file name of the file to be read in. | |
249 | // Outputs are: | |
250 | // none | |
8253cd9a | 251 | Int_t ncmd=9; |
5c9c741e | 252 | const char *cmda[]={"Version" ,"fTrans" ,"fNmodules", |
253 | "fNlayers" ,"fNladers","fNdetectors", | |
254 | "fNDetectorTypes","fShape" ,"Matrix"}; | |
8253cd9a | 255 | Int_t i,j,lNdetTypes,ldet; |
256 | char cmd[20],c; | |
164da35c | 257 | AliITSgeomSPD *spd=0; |
258 | AliITSgeomSDD *sdd=0; | |
259 | AliITSgeomSSD *ssd=0; | |
260 | AliITSgeomMatrix *m=0; | |
261 | ifstream *fp=0; | |
262 | char *filtmp=0; | |
8253cd9a | 263 | |
264 | filtmp = gSystem->ExpandPathName(filename); | |
f77f13c8 | 265 | AliInfo(Form("Reading New .det file %s",filtmp)); |
8253cd9a | 266 | fp = new ifstream(filtmp,ios::in); // open file to write |
267 | while(fp->get(c)!=NULL){ // for ever loop | |
268 | if(c==' ') continue; // remove blanks | |
269 | if(c=='\n') continue; | |
f77f13c8 | 270 | if(c=='#' || c=='!') {while(fp->get(c)) if(c=='\n') break; continue;} |
8253cd9a | 271 | if(c=='/'){ |
272 | fp->get(c);{ | |
f77f13c8 | 273 | if(c=='/') {while(fp->get(c)) if(c=='\n') break; continue;} |
8253cd9a | 274 | if(c=='*'){ |
275 | NotYet: | |
f77f13c8 | 276 | while(fp->get(c)) if(c=='*') break; |
8253cd9a | 277 | fp->get(c);{ |
278 | if(c=='/') continue; | |
279 | goto NotYet; | |
280 | } // | |
281 | } // end if c=='*' | |
282 | } // end if second / | |
283 | } // end if first / | |
5c9c741e | 284 | fp->putback(c); |
8253cd9a | 285 | *fp >> cmd; |
286 | for(i=0;i<ncmd;i++) if(strcmp(cmd,cmda[i])==0) break; | |
287 | switch (i){ | |
288 | case 0: // Version | |
289 | *fp >> fVersion; | |
290 | break; | |
291 | case 1: // fTrans | |
292 | *fp >> fTrans; | |
293 | break; | |
294 | case 2: // fNModules | |
295 | *fp >> fNmodules; | |
296 | if(fGm!=0){ | |
297 | for(j=0;j<fGm->GetEntriesFast();j++) delete fGm->At(j); | |
298 | delete fGm; | |
299 | } // end if | |
300 | fGm = new TObjArray(fNmodules,0); | |
301 | break; | |
302 | case 3: // fNlayers | |
303 | *fp >> fNlayers; | |
304 | if(fNlad!=0) delete fNlad; | |
305 | if(fNdet!=0) delete fNdet; | |
306 | fNlad = new Int_t[fNlayers]; | |
307 | fNdet = new Int_t[fNlayers]; | |
308 | break; | |
309 | case 4: // fNladers | |
310 | for(j=0;j<fNlayers;j++) *fp >> fNlad[j]; | |
311 | break; | |
312 | case 5: // fNdetectors | |
313 | for(j=0;j<fNlayers;j++) *fp >> fNdet[j]; | |
314 | break; | |
315 | case 6: // fNDetectorTypes | |
316 | *fp >> lNdetTypes; | |
317 | if(fShape!=0){ | |
318 | for(j=0;j<fShape->GetEntriesFast();j++) delete fShape->At(j); | |
319 | delete fShape; | |
320 | } // end if | |
321 | fShape = new TObjArray(lNdetTypes,0); | |
322 | break; | |
323 | case 7: // fShape | |
324 | *fp >> ldet; | |
5c9c741e | 325 | if(fShape==0) fShape = new TObjArray(5,0); |
8253cd9a | 326 | switch (ldet){ |
327 | case kSPD : | |
164da35c | 328 | spd = new AliITSgeomSPD(); |
8253cd9a | 329 | *fp >> *spd; |
164da35c | 330 | ReSetShape(ldet,spd); |
8253cd9a | 331 | spd = 0; |
332 | break; | |
164da35c | 333 | case kSDD : case kSDDp: |
334 | sdd = new AliITSgeomSDD(); | |
8253cd9a | 335 | *fp >> *sdd; |
164da35c | 336 | ReSetShape(ldet,sdd); |
8253cd9a | 337 | sdd = 0; |
338 | break; | |
339 | case kSSD : case kSSDp : | |
164da35c | 340 | ssd = new AliITSgeomSSD(); |
8253cd9a | 341 | *fp >> *ssd; |
164da35c | 342 | ReSetShape(ldet,ssd); |
8253cd9a | 343 | ssd = 0; |
344 | break; | |
345 | default: | |
f77f13c8 | 346 | AliError(Form("Unknown fShape type number=%d c=%c",ldet,c)); |
347 | while(fp->get(c)) if(c=='\n') break; // skip to end of line. | |
8253cd9a | 348 | break; |
349 | } // end switch | |
350 | break; | |
351 | case 8: // Matrix | |
352 | *fp >> ldet; | |
353 | if(fGm==0) fGm = new TObjArray(2270,0); | |
354 | if(fGm->At(ldet)!=0) delete (fGm->At(ldet)); | |
355 | fGm->AddAt((TObject*)new AliITSgeomMatrix(),ldet); | |
356 | m = (AliITSgeomMatrix*) fGm->At(ldet); | |
357 | *fp >> *m; | |
358 | m = 0; | |
359 | break; | |
360 | default: | |
f77f13c8 | 361 | AliError(Form("ReadNewFile","Data line i=%d c=%c",i,c)); |
362 | while(fp->get(c)) if(c=='\n') break; // skip this line | |
8253cd9a | 363 | break; |
364 | } // end switch i | |
365 | } // end while | |
366 | delete fp; | |
367 | ||
368 | return; | |
369 | } | |
370 | //______________________________________________________________________ | |
371 | void AliITSgeom::WriteNewFile(const char *filename){ | |
85f1e34a | 372 | // Writes AliITSgeom, AliITSgeomMatrix, and the defined AliITSgeomS*D |
373 | // classes to a file in a format that is more readable and commendable. | |
374 | // Inputs are: | |
375 | // const char *filename The file name of the file to be write to. | |
376 | // Outputs are: | |
377 | // none | |
8253cd9a | 378 | ofstream *fp; |
379 | Int_t i; | |
380 | char *filtmp; | |
381 | ||
382 | filtmp = gSystem->ExpandPathName(filename); | |
5c9c741e | 383 | cout << "AliITSgeom, Writing New .det file " << filtmp << endl; |
8253cd9a | 384 | fp = new ofstream(filtmp,ios::out); // open file to write |
385 | *fp << "//Comment lines begin with two //, one #, or one !" << endl; | |
386 | *fp << "#Blank lines are skipped including /* and */ sections." << endl; | |
387 | *fp << "!and, in principle the order of the lines is not important" <<endl; | |
388 | *fp << "/* In AliITSgeom.h are defined an enumerated type called" << endl; | |
389 | *fp << " AliITSDetectors These are kSPD=" << (Int_t) kSPD ; | |
390 | *fp << ", kSDD=" << (Int_t) kSDD << ", kSSD=" << (Int_t) kSSD; | |
5c9c741e | 391 | *fp << ", kSSDp=" << (Int_t) kSSDp << ", and kSDDp=" << (Int_t) kSDDp; |
392 | *fp << "*/" << endl; | |
85f1e34a | 393 | *fp << "Version " << fVersion << endl;//This should be consistent with the |
8253cd9a | 394 | // geometry version. |
395 | *fp << "fTrans " << fTrans << endl; | |
396 | *fp << "fNmodules " << fNmodules << endl; | |
397 | *fp << "fNlayers " << fNlayers << endl; | |
398 | *fp << "fNladers "; | |
399 | for(i=0;i<fNlayers;i++) *fp << fNlad[i] << " "; | |
400 | *fp << endl; | |
401 | *fp << "fNdetectors "; | |
402 | for(i=0;i<fNlayers;i++) *fp << fNdet[i] << " "; | |
403 | *fp << endl; | |
404 | *fp << "fNDetectorTypes " << fShape->GetEntriesFast() << endl; | |
405 | for(i=0;i<fShape->GetEntriesFast();i++){ | |
406 | if(!IsShapeDefined(i)) continue; // only print out used shapes. | |
407 | switch (i){ | |
408 | case kSPD : | |
409 | *fp << "fShape " << (Int_t) kSPD << " "; | |
410 | *fp << *((AliITSgeomSPD*)(fShape->At(i))); | |
411 | break; | |
412 | case kSDD : | |
413 | *fp << "fShape " << (Int_t) kSDD << " "; | |
414 | *fp << *((AliITSgeomSDD*)(fShape->At(i))); | |
415 | break; | |
416 | case kSSD : case kSSDp : | |
417 | *fp << "fShape " << i << " "; | |
418 | *fp << *((AliITSgeomSSD*)(fShape->At(i))); | |
419 | break; | |
420 | default: | |
421 | Error("AliITSgeom::WriteNewFile","Unknown Shape value"); | |
422 | } // end switch (i) | |
423 | } // end for i | |
424 | for(i=0;i<fNmodules;i++){ | |
425 | *fp << "Matrix " << i << " "; | |
426 | *fp << *GetGeomMatrix(i); | |
427 | } // end for i | |
428 | *fp << "//End of File" << endl;; | |
429 | ||
430 | delete fp; | |
269f57ed | 431 | return; |
432 | } | |
85f1e34a | 433 | //______________________________________________________________________ |
58005f18 | 434 | AliITSgeom::AliITSgeom(const char *filename){ |
85f1e34a | 435 | // The constructor for the AliITSgeom class. All of the data to fill |
436 | // this structure is read in from the file given my the input filename. | |
437 | // Inputs are: | |
438 | // const char *filename The file name of the file to be read in. | |
439 | // Outputs are: | |
440 | // none | |
441 | FILE *pf=0; | |
442 | Int_t i,lm=0,id[3]; | |
443 | Int_t l,a,d; | |
444 | Float_t x,y,z,o,p,q,r,s,t; | |
445 | Double_t rot6[6],tran[3]; | |
446 | char buf[200],*buff=0; // input character buffer; | |
447 | char *filtmp; | |
58005f18 | 448 | |
85f1e34a | 449 | filtmp = gSystem->ExpandPathName(filename); |
450 | cout << "AliITSgeom reading old .det file " << filtmp << endl; | |
451 | fShape = 0; | |
452 | strcpy(fVersion,"DefauleV5"); | |
453 | pf = fopen(filtmp,"r"); | |
454 | ||
455 | fNlayers = 6; // set default number of ladders | |
456 | TryAgain: | |
457 | fNlad = new Int_t[fNlayers]; | |
458 | fNdet = new Int_t[fNlayers]; | |
459 | fNmodules = 0; | |
460 | // find the number of ladders and detectors in this geometry. | |
461 | for(i=0;i<fNlayers;i++){fNlad[i]=fNdet[i]=0;} // zero out arrays | |
462 | while(fgets(buf,200,pf)!=NULL){ // for ever loop | |
463 | for(i=0;i<200;i++)if(buf[i]!=' '){ // remove blank spaces. | |
464 | buff = &(buf[i]); | |
465 | break; | |
466 | } // end for i | |
467 | // remove blank lines and comments. | |
468 | if(buff[0]=='\n'||buff[0]=='#'||buff[0]=='!'|| | |
469 | (buff[0]=='/'&&buff[1]=='/')) continue; | |
470 | if(isalpha(buff[0])) { // must be the new file formated file. | |
269f57ed | 471 | fclose(pf); |
472 | delete[] fNlad;delete[] fNdet; | |
473 | ReadNewFile(filename); | |
474 | return; | |
85f1e34a | 475 | } // end if isalpha(buff[0]) |
476 | sscanf(buff,"%d %d %d %f %f %f %f %f %f %f %f %f", | |
477 | &l,&a,&d,&x,&y,&z,&o,&p,&q,&r,&s,&t); | |
478 | if(l>lm) lm = l; | |
479 | if(l<1 || l>fNlayers) { | |
480 | printf("error in file %s layer=%d min. is 1 max is %d\n", | |
481 | filename,l,fNlayers); | |
482 | continue; | |
483 | }// end if l | |
484 | fNmodules++; | |
485 | if(l<=fNlayers&&fNlad[l-1]<a) fNlad[l-1] = a; | |
486 | if(l<=fNlayers&&fNdet[l-1]<d) fNdet[l-1] = d; | |
487 | } // end while ever loop | |
488 | if(lm>fNlayers){ | |
269f57ed | 489 | delete[] fNlad; |
490 | delete[] fNdet; | |
491 | fNlayers = lm; | |
492 | goto TryAgain; | |
85f1e34a | 493 | } // end if lm>fNlayers |
494 | // counted the number of ladders and detectors now allocate space. | |
495 | fGm = new TObjArray(fNmodules,0); | |
58005f18 | 496 | |
85f1e34a | 497 | // Set up Shapes for a default configuration of 6 layers. |
498 | fTrans = 0; // standard GEANT global/local coordinate system. | |
499 | // prepare to read in transforms | |
500 | lm = 0; // reuse lm as counter of modules. | |
501 | rewind(pf); // start over reading file | |
502 | while(fgets(buf,200,pf)!=NULL){ // for ever loop | |
503 | for(i=0;i<200;i++)if(buf[i]!=' '){ // remove blank spaces. | |
504 | buff = &(buf[i]); | |
505 | break; | |
506 | } // end for i | |
507 | // remove blank lines and comments. | |
508 | if(buff[0]=='\n'||buff[0]=='#'||buff[0]=='!'|| | |
509 | (buff[0]=='/'&&buff[1]=='/')) continue; | |
510 | x = y = z = o = p = q = r = s = t = 0.0; | |
511 | sscanf(buff,"%d %d %d %f %f %f %f %f %f %f %f %f", | |
512 | &l,&a,&d,&x,&y,&z,&o,&p,&q,&r,&s,&t); | |
513 | if(l<1 || l>fNlayers) { | |
514 | printf("error in file %s layer=%d min. is 1 max is %d/n", | |
515 | filename,l,fNlayers); | |
516 | continue; | |
517 | }// end if l | |
518 | id[0] = l;id[1] = a;id[2] = d; | |
519 | tran[0] = tran[1] = tran[2] = 0.0; | |
520 | tran[0] = (Double_t)x;tran[1] = (Double_t)y;tran[2] = (Double_t)z; | |
521 | rot6[0] = rot6[1] = rot6[2] = rot6[3] = rot6[4] = rot6[5] =0.0; | |
522 | rot6[0] = (Double_t)o;rot6[1] = (Double_t)p;rot6[2] = (Double_t)q; | |
523 | rot6[3] = (Double_t)r;rot6[4] = (Double_t)s;rot6[5] = (Double_t)t; | |
524 | switch (l){ | |
525 | case 1: case 2: // layer 1 or2 SPD | |
526 | fGm->AddAt(new AliITSgeomMatrix(rot6,kSPD,id,tran),lm++); | |
527 | break; | |
528 | case 3: case 4: // layer 3 or 4 SDD | |
529 | fGm->AddAt(new AliITSgeomMatrix(rot6,kSDD,id,tran),lm++); | |
530 | break; | |
531 | case 5: case 6: // layer 5 or 6 SSD | |
532 | fGm->AddAt(new AliITSgeomMatrix(rot6,kSSD,id,tran),lm++); | |
533 | break; | |
534 | } // end switch | |
535 | } // end while ever loop | |
536 | fclose(pf); | |
58005f18 | 537 | } |
85f1e34a | 538 | //______________________________________________________________________ |
7f6ab649 | 539 | AliITSgeom::AliITSgeom(const AliITSgeom &source) : TObject(source){ |
85f1e34a | 540 | // The copy constructor for the AliITSgeom class. It calls the |
541 | // = operator function. See the = operator function for more details. | |
542 | // Inputs are: | |
543 | // AliITSgeom &source The AliITSgeom class with which to make this | |
544 | // a copy of. | |
545 | // Outputs are: | |
546 | // none. | |
593e9459 | 547 | |
548 | *this = source; // Just use the = operator for now. | |
593e9459 | 549 | return; |
58005f18 | 550 | } |
85f1e34a | 551 | //______________________________________________________________________ |
7f6ab649 | 552 | AliITSgeom& AliITSgeom::operator=(const AliITSgeom &source){ |
85f1e34a | 553 | // The = operator function for the AliITSgeom class. It makes an |
554 | // independent copy of the class in such a way that any changes made | |
555 | // to the copied class will not affect the source class in any way. | |
556 | // This is required for many ITS alignment studies where the copied | |
557 | // class is then modified by introducing some misalignment. | |
558 | // Inputs are: | |
559 | // AliITSgeom &source The AliITSgeom class with which to make this | |
560 | // a copy of. | |
561 | // Outputs are: | |
562 | // return *this The a new copy of source. | |
269f57ed | 563 | Int_t i; |
58005f18 | 564 | |
85f1e34a | 565 | if(this == &source) return *this; // don't assign to ones self. |
58005f18 | 566 | |
567 | // if there is an old structure allocated delete it first. | |
269f57ed | 568 | if(this->fGm != 0){ |
8253cd9a | 569 | for(i=0;i<this->fNmodules;i++) delete this->fGm->At(i); |
269f57ed | 570 | delete this->fGm; |
085bb6ed | 571 | } // end if fGm != 0 |
572 | if(fNlad != 0) delete[] fNlad; | |
573 | if(fNdet != 0) delete[] fNdet; | |
574 | ||
269f57ed | 575 | this->fTrans = source.fTrans; |
576 | this->fNmodules = source.fNmodules; | |
577 | this->fNlayers = source.fNlayers; | |
578 | this->fNlad = new Int_t[fNlayers]; | |
579 | for(i=0;i<this->fNlayers;i++) this->fNlad[i] = source.fNlad[i]; | |
580 | this->fNdet = new Int_t[fNlayers]; | |
581 | for(i=0;i<this->fNlayers;i++) this->fNdet[i] = source.fNdet[i]; | |
582 | this->fShape = new TObjArray(*(source.fShape));//This does not make a proper copy. | |
8253cd9a | 583 | this->fGm = new TObjArray(this->fNmodules,0); |
269f57ed | 584 | for(i=0;i<this->fNmodules;i++){ |
8253cd9a | 585 | this->fGm->AddAt(new AliITSgeomMatrix(*( |
586 | (AliITSgeomMatrix*)(source.fGm->At(i)))),i); | |
085bb6ed | 587 | } // end for i |
85f1e34a | 588 | return *this; |
589 | } | |
590 | //______________________________________________________________________ | |
591 | Int_t AliITSgeom::GetModuleIndex(Int_t lay,Int_t lad,Int_t det){ | |
592 | // This routine computes the module index number from the layer, | |
593 | // ladder, and detector numbers. The number of ladders and detectors | |
594 | // per layer is determined when this geometry package is constructed, | |
595 | // see AliITSgeom(const char *filename) for specifics. | |
596 | // Inputs are: | |
597 | // Int_t lay The layer number. Starting from 1. | |
598 | // Int_t lad The ladder number. Starting from 1. | |
599 | // Int_t det The detector number. Starting from 1. | |
600 | // Outputs are: | |
601 | // return the module index number, starting from zero. | |
269f57ed | 602 | Int_t i,j,k,id[3]; |
593e9459 | 603 | |
604 | i = fNdet[lay-1] * (lad-1) + det - 1; | |
605 | j = 0; | |
606 | for(k=0;k<lay-1;k++) j += fNdet[k]*fNlad[k]; | |
269f57ed | 607 | i = i+j; |
7e932df0 | 608 | if(i>=fNmodules) return -1; |
8253cd9a | 609 | GetGeomMatrix(i)->GetIndex(id); |
269f57ed | 610 | if(id[0]==lay&&id[1]==lad&&id[2]==det) return i; |
611 | // Array of modules fGm is not in expected order. Search for this index | |
612 | for(i=0;i<fNmodules;i++){ | |
8253cd9a | 613 | GetGeomMatrix(i)->GetIndex(id); |
269f57ed | 614 | if(id[0]==lay&&id[1]==lad&&id[2]==det) return i; |
615 | } // end for i | |
616 | // This layer ladder and detector combination does not exist return -1. | |
617 | return -1; | |
593e9459 | 618 | } |
269f57ed | 619 | //______________________________________________________________________ |
85f1e34a | 620 | void AliITSgeom::GetModuleId(Int_t index,Int_t &lay,Int_t &lad,Int_t &det){ |
621 | // This routine computes the layer, ladder and detector number | |
622 | // given the module index number. The number of ladders and detectors | |
623 | // per layer is determined when this geometry package is constructed, | |
624 | // see AliITSgeom(const char *filename) for specifics. | |
625 | // Inputs are: | |
626 | // Int_t index The module index number, starting from zero. | |
627 | // Outputs are: | |
628 | // Int_t lay The layer number. Starting from 1. | |
629 | // Int_t lad The ladder number. Starting from 1. | |
630 | // Int_t det The detector number. Starting from 1. | |
269f57ed | 631 | Int_t id[3]; |
88cb7938 | 632 | AliITSgeomMatrix *g = GetGeomMatrix(index); |
633 | if (g == 0x0) | |
634 | { | |
635 | Error("GetModuleId","Can not get GeoMatrix for index = %d",index); | |
636 | lay = -1; lad = -1; det = -1; | |
637 | } | |
638 | else | |
639 | { | |
640 | g->GetIndex(id); | |
641 | lay = id[0]; lad = id[1]; det = id[2]; | |
642 | } | |
269f57ed | 643 | return; |
644 | ||
645 | // The old way kept for posterity. | |
646 | /* | |
647 | Int_t i,j,k; | |
593e9459 | 648 | j = 0; |
649 | for(k=0;k<fNlayers;k++){ | |
58005f18 | 650 | j += fNdet[k]*fNlad[k]; |
aa6248e2 | 651 | if(j>index)break; |
58005f18 | 652 | } // end for k |
653 | lay = k+1; | |
654 | i = index -j + fNdet[k]*fNlad[k]; | |
655 | j = 0; | |
656 | for(k=0;k<fNlad[lay-1];k++){ | |
aa6248e2 | 657 | j += fNdet[lay-1]; |
658 | if(j>i)break; | |
58005f18 | 659 | } // end for k |
660 | lad = k+1; | |
661 | det = 1+i-fNdet[lay-1]*k; | |
662 | return; | |
269f57ed | 663 | */ |
58005f18 | 664 | } |
85f1e34a | 665 | //______________________________________________________________________ |
666 | Int_t AliITSgeom::GetStartDet(Int_t dtype){ | |
667 | // returns the starting module index value for a give type of detector id. | |
668 | // This assumes that the detector types are different on different layers | |
669 | // and that they are not mixed up. | |
670 | // Inputs are: | |
671 | // Int_t dtype A detector type number. 0 for SPD, 1 for SDD, and 2 for SSD. | |
672 | // outputs: | |
673 | // return the module index for the first occurance of that detector type. | |
674 | ||
675 | switch(dtype){ | |
676 | case 0: | |
677 | return GetModuleIndex(1,1,1); | |
678 | break; | |
679 | case 1: | |
680 | return GetModuleIndex(3,1,1); | |
681 | break; | |
682 | case 2: | |
683 | return GetModuleIndex(5,1,1); | |
684 | break; | |
685 | default: | |
686 | Warning("GetStartDet","undefined detector type %d",dtype); | |
687 | return 0; | |
688 | } // end switch | |
689 | ||
690 | Warning("GetStartDet","undefined detector type %d",dtype); | |
691 | return 0; | |
085bb6ed | 692 | } |
85f1e34a | 693 | //______________________________________________________________________ |
694 | Int_t AliITSgeom::GetLastDet(Int_t dtype){ | |
695 | // returns the last module index value for a give type of detector id. | |
696 | // This assumes that the detector types are different on different layers | |
697 | // and that they are not mixed up. | |
698 | // Inputs are: | |
699 | // Int_t dtype A detector type number. 0 for SPD, 1 for SDD, and 2 for SSD. | |
700 | // outputs are: | |
701 | // return the module index for the last occurance of that detector type. | |
702 | ||
703 | switch(dtype){ | |
704 | case 0: | |
705 | return GetLastSPD(); | |
706 | break; | |
707 | case 1: | |
708 | return GetLastSDD(); | |
709 | break; | |
710 | case 2: | |
711 | return GetLastSSD(); | |
712 | break; | |
713 | default: | |
714 | Warning("GetLastDet","undefined detector type %d",dtype); | |
715 | return 0; | |
716 | } // end switch | |
717 | ||
718 | Warning("GetLastDet","undefined detector type %d",dtype); | |
719 | return 0; | |
085bb6ed | 720 | } |
85f1e34a | 721 | //______________________________________________________________________ |
593e9459 | 722 | void AliITSgeom::PrintComparison(FILE *fp,AliITSgeom *other){ |
85f1e34a | 723 | // This function was primarily created for diagnostic reasons. It |
724 | // print to a file pointed to by the file pointer fp the difference | |
725 | // between two AliITSgeom classes. The format of the file is basicly, | |
726 | // define d? to be the difference between the same element of the two | |
727 | // classes. For example dfrx = this->GetGeomMatrix(i)->frx | |
728 | // - other->GetGeomMatrix(i)->frx. | |
729 | // if(at least one of dfx0, dfy0, dfz0,dfrx,dfry,dfrz are non zero) then | |
730 | // print layer ladder detector dfx0 dfy0 dfz0 dfrx dfry dfrz | |
731 | // if(at least one of the 9 elements of dfr[] are non zero) then print | |
732 | // layer ladder detector dfr[0] dfr[1] dfr[2] | |
733 | // dfr[3] dfr[4] dfr[5] | |
734 | // dfr[6] dfr[7] dfr[8] | |
735 | // Only non zero values are printed to save space. The differences are | |
736 | // typical written to a file because there are usually a lot of numbers | |
737 | // printed out and it is usually easier to read them in some nice editor | |
738 | // rather than zooming quickly past you on a screen. fprintf is used to | |
739 | // do the printing. The fShapeIndex difference is not printed at this time. | |
740 | // Inputs are: | |
741 | // FILE *fp A file pointer to an opened file for writing in which | |
742 | // the results of the comparison will be written. | |
743 | // AliITSgeom *other The other AliITSgeom class to which this one is | |
744 | // being compared. | |
745 | // outputs are: | |
746 | // none | |
747 | Int_t i,j,idt[3],ido[3]; | |
748 | Double_t tt[3],to[3]; // translation | |
749 | Double_t rt[3],ro[3]; // phi in radians | |
750 | Double_t mt[3][3],mo[3][3]; // matrixes | |
751 | AliITSgeomMatrix *gt,*go; | |
752 | Bool_t t; | |
753 | ||
754 | for(i=0;i<this->fNmodules;i++){ | |
755 | gt = this->GetGeomMatrix(i); | |
756 | go = other->GetGeomMatrix(i); | |
757 | gt->GetIndex(idt); | |
758 | go->GetIndex(ido); | |
759 | t = kFALSE; | |
760 | for(i=0;i<3;i++) t = t&&idt[i]!=ido[i]; | |
761 | if(t) fprintf(fp,"%4.4d %1.1d %2.2d %2.2d %1.1d %2.2d %2.2d\n",i, | |
762 | idt[0],idt[1],idt[2],ido[0],ido[1],ido[2]); | |
763 | gt->GetTranslation(tt); | |
764 | go->GetTranslation(to); | |
765 | gt->GetAngles(rt); | |
766 | go->GetAngles(ro); | |
767 | t = kFALSE; | |
768 | for(i=0;i<3;i++) t = t&&tt[i]!=to[i]; | |
769 | if(t) fprintf(fp,"%1.1d %2.2d %2.2d dTrans=%f %f %f drot=%f %f %f\n", | |
770 | idt[0],idt[1],idt[2], | |
771 | tt[0]-to[0],tt[1]-to[1],tt[2]-to[2], | |
772 | rt[0]-ro[0],rt[1]-ro[1],rt[2]-ro[2]); | |
773 | t = kFALSE; | |
774 | gt->GetMatrix(mt); | |
775 | go->GetMatrix(mo); | |
776 | for(i=0;i<3;i++)for(j=0;j<3;j++) t = mt[i][j] != mo[i][j]; | |
777 | if(t){ | |
778 | fprintf(fp,"%1.1d %2.2d %2.2d dfr= %e %e %e\n", | |
779 | idt[0],idt[1],idt[2], | |
780 | mt[0][0]-mo[0][0],mt[0][1]-mo[0][1],mt[0][2]-mo[0][2]); | |
781 | fprintf(fp," dfr= %e %e %e\n", | |
782 | mt[1][0]-mo[1][0],mt[1][1]-mo[1][1],mt[1][2]-mo[1][2]); | |
783 | fprintf(fp," dfr= %e %e %e\n", | |
784 | mt[2][0]-mo[2][0],mt[2][1]-mo[2][1],mt[2][2]-mo[2][2]); | |
785 | } // end if t | |
786 | } // end for i | |
787 | return; | |
58005f18 | 788 | } |
85f1e34a | 789 | //______________________________________________________________________ |
790 | void AliITSgeom::PrintData(FILE *fp,Int_t lay,Int_t lad,Int_t det){ | |
791 | // This function prints out the coordinate transformations for | |
792 | // the particular detector defined by layer, ladder, and detector | |
793 | // to the file pointed to by the File pointer fp. fprintf statements | |
794 | // are used to print out the numbers. The format is | |
795 | // layer ladder detector Trans= fx0 fy0 fz0 rot= frx fry frz | |
796 | // Shape=fShapeIndex | |
797 | // dfr= fr[0] fr[1] fr[2] | |
798 | // dfr= fr[3] fr[4] fr[5] | |
799 | // dfr= fr[6] fr[7] fr[8] | |
800 | // By indicating which detector, some control over the information | |
801 | // is given to the user. The output it written to the file pointed | |
802 | // to by the file pointer fp. This can be set to stdout if you want. | |
803 | // Inputs are: | |
804 | // FILE *fp A file pointer to an opened file for writing in which | |
805 | // the results of the comparison will be written. | |
806 | // Int_t lay The layer number. Starting from 1. | |
807 | // Int_t lad The ladder number. Starting from 1. | |
808 | // Int_t det The detector number. Starting from 1. | |
809 | // outputs are: | |
810 | // none | |
811 | AliITSgeomMatrix *gt; | |
812 | Double_t t[3],r[3],m[3][3]; | |
813 | ||
814 | gt = this->GetGeomMatrix(GetModuleIndex(lay,lad,det)); | |
815 | gt->GetTranslation(t); | |
816 | gt->GetAngles(r); | |
817 | fprintf(fp,"%1.1d %2.2d %2.2d Trans=%f %f %f rot=%f %f %f Shape=%d\n", | |
818 | lay,lad,det,t[0],t[1],t[2],r[0],r[1],r[2], | |
819 | gt->GetDetectorIndex()); | |
820 | gt->GetMatrix(m); | |
821 | fprintf(fp," dfr= %e %e %e\n",m[0][0],m[0][1],m[0][2]); | |
822 | fprintf(fp," dfr= %e %e %e\n",m[1][0],m[1][1],m[1][2]); | |
823 | fprintf(fp," dfr= %e %e %e\n",m[2][0],m[2][1],m[2][2]); | |
824 | return; | |
58005f18 | 825 | } |
85f1e34a | 826 | //______________________________________________________________________ |
827 | ofstream & AliITSgeom::PrintGeom(ofstream &rb){ | |
828 | // Stream out an object of class AliITSgeom to standard output. | |
829 | // Intputs are: | |
830 | // ofstream &rb The output streaming buffer. | |
831 | // Outputs are: | |
832 | // ofstream &rb The output streaming buffer. | |
269f57ed | 833 | Int_t i; |
593e9459 | 834 | |
85f1e34a | 835 | rb.setf(ios::scientific); |
836 | rb << fTrans << " "; | |
837 | rb << fNmodules << " "; | |
838 | rb << fNlayers << " "; | |
839 | for(i=0;i<fNlayers;i++) rb << fNlad[i] << " "; | |
840 | for(i=0;i<fNlayers;i++) rb << fNdet[i] << "\n"; | |
269f57ed | 841 | for(i=0;i<fNmodules;i++) { |
85f1e34a | 842 | rb <<setprecision(16) << *(GetGeomMatrix(i)) << "\n"; |
269f57ed | 843 | } // end for i |
164da35c | 844 | rb << fShape->GetEntries()<<endl; |
845 | for(i=0;i<fShape->GetEntries();i++) if(fShape->At(i)!=0) switch (i){ | |
846 | case kSPD: | |
847 | rb << kSPD <<","<< (AliITSgeomSPD*)(fShape->At(kSPD)); | |
848 | break; | |
849 | case kSDD: | |
850 | rb << kSDD <<","<< (AliITSgeomSDD*)(fShape->At(kSDD)); | |
851 | break; | |
852 | case kSSD: | |
853 | rb << kSSD <<","<< (AliITSgeomSSD*)(fShape->At(kSSD)); | |
854 | break; | |
855 | case kSSDp: | |
856 | rb << kSSDp <<","<< (AliITSgeomSSD*)(fShape->At(kSSDp)); | |
857 | break; | |
858 | case kSDDp: | |
859 | rb << kSDDp <<","<< (AliITSgeomSDD*)(fShape->At(kSDDp)); | |
860 | break; | |
861 | } // end for i / switch | |
85f1e34a | 862 | return rb; |
593e9459 | 863 | } |
85f1e34a | 864 | //______________________________________________________________________ |
865 | ifstream & AliITSgeom::ReadGeom(ifstream &rb){ | |
866 | // Stream in an object of class AliITSgeom from standard input. | |
867 | // Intputs are: | |
868 | // ifstream &rb The input streaming buffer. | |
869 | // Outputs are: | |
870 | // ifstream &rb The input streaming buffer. | |
164da35c | 871 | Int_t i,j; |
269f57ed | 872 | |
85f1e34a | 873 | fNlad = new Int_t[fNlayers]; |
874 | fNdet = new Int_t[fNlayers]; | |
875 | if(fGm!=0){ | |
876 | for(i=0;i<fNmodules;i++) delete GetGeomMatrix(i); | |
877 | delete fGm; | |
878 | } // end if fGm!=0 | |
879 | ||
880 | rb >> fTrans >> fNmodules >> fNlayers; | |
881 | fNlad = new Int_t[fNlayers]; | |
882 | fNdet = new Int_t[fNlayers]; | |
883 | for(i=0;i<fNlayers;i++) rb >> fNlad[i]; | |
884 | for(i=0;i<fNlayers;i++) rb >> fNdet[i]; | |
885 | fGm = new TObjArray(fNmodules,0); | |
886 | for(i=0;i<fNmodules;i++){ | |
887 | fGm->AddAt(new AliITSgeomMatrix,i); | |
888 | rb >> *(GetGeomMatrix(i)); | |
889 | } // end for i | |
164da35c | 890 | rb >> i; |
891 | fShape = new TObjArray(i); | |
892 | for(i=0;i<fShape->GetEntries();i++) { | |
893 | rb >> j; | |
894 | switch (j){ | |
895 | case kSPD:{ | |
896 | AliITSgeomSPD *s = new AliITSgeomSPD(); | |
897 | rb >> *s; | |
898 | fShape->AddAt(s,kSPD);} | |
899 | break; | |
900 | case kSDD:{ | |
901 | AliITSgeomSDD *s = new AliITSgeomSDD(); | |
902 | rb >> *s; | |
903 | fShape->AddAt(s,kSDD);} | |
904 | break; | |
905 | case kSSD:{ | |
906 | AliITSgeomSSD *s = new AliITSgeomSSD(); | |
907 | rb >> *s; | |
908 | fShape->AddAt(s,kSSD);} | |
909 | break; | |
910 | case kSSDp:{ | |
911 | AliITSgeomSSD *s = new AliITSgeomSSD(); | |
912 | rb >> *s; | |
913 | fShape->AddAt(s,kSSDp);} | |
914 | break; | |
915 | case kSDDp:{ | |
916 | AliITSgeomSDD *s = new AliITSgeomSDD(); | |
917 | rb >> *s; | |
918 | fShape->AddAt(s,kSDDp);} | |
919 | break; | |
920 | } // end switch | |
921 | } // end for i | |
85f1e34a | 922 | return rb; |
593e9459 | 923 | } |
593e9459 | 924 | //______________________________________________________________________ |
269f57ed | 925 | // The following routines modify the transformation of "this" |
926 | // geometry transformations in a number of different ways. | |
593e9459 | 927 | //______________________________________________________________________ |
269f57ed | 928 | void AliITSgeom::GlobalChange(const Float_t *tran,const Float_t *rot){ |
85f1e34a | 929 | // This function performs a Cartesian translation and rotation of |
930 | // the full ITS from its default position by an amount determined by | |
931 | // the three element arrays tran and rot. If every element | |
932 | // of tran and rot are zero then there is no change made | |
933 | // the geometry. The change is global in that the exact same translation | |
934 | // and rotation is done to every detector element in the exact same way. | |
935 | // The units of the translation are those of the Monte Carlo, usually cm, | |
936 | // and those of the rotation are in radians. The elements of tran | |
937 | // are tran[0] = x, tran[1] = y, and tran[2] = z. | |
938 | // The elements of rot are rot[0] = rx, rot[1] = ry, and | |
939 | // rot[2] = rz. A change in x will move the hole ITS in the ALICE | |
940 | // global x direction, the same for a change in y. A change in z will | |
941 | // result in a translation of the ITS as a hole up or down the beam line. | |
942 | // A change in the angles will result in the inclination of the ITS with | |
943 | // respect to the beam line, except for an effective rotation about the | |
944 | // beam axis which will just rotate the ITS as a hole about the beam axis. | |
945 | // Intputs are: | |
946 | // Float_t *tran A 3 element array representing the global translations. | |
947 | // the elements are x,y,z in cm. | |
948 | // Float_t *rot A 3 element array representing the global rotation | |
949 | // angles about the three axis x,y,z in radians | |
950 | // Outputs are: | |
951 | // none. | |
952 | Int_t i,j; | |
953 | Double_t t[3],r[3]; | |
954 | AliITSgeomMatrix *g; | |
955 | ||
956 | fTrans = (fTrans && 0xfffd) + 2; // set bit 1 true. | |
957 | for(i=0;i<fNmodules;i++){ | |
958 | g = this->GetGeomMatrix(i); | |
959 | g->GetTranslation(t); | |
960 | g->GetAngles(r); | |
961 | for(j=0;j<3;j++){ | |
962 | t[j] += tran[j]; | |
963 | r[j] += rot[j]; | |
964 | } // end for j | |
965 | g->SetTranslation(t); | |
966 | g->SetAngles(r); | |
967 | } // end for i | |
968 | return; | |
593e9459 | 969 | } |
85f1e34a | 970 | //______________________________________________________________________ |
971 | void AliITSgeom::GlobalCylindericalChange(const Float_t *tran, | |
972 | const Float_t *rot){ | |
973 | // This function performs a cylindrical translation and rotation of | |
974 | // each ITS element by a fixed about in radius, rphi, and z from its | |
975 | // default position by an amount determined by the three element arrays | |
976 | // tran and rot. If every element of tran and | |
977 | // rot are zero then there is no change made the geometry. The | |
978 | // change is global in that the exact same distance change in translation | |
979 | // and rotation is done to every detector element in the exact same way. | |
980 | // The units of the translation are those of the Monte Carlo, usually cm, | |
981 | // and those of the rotation are in radians. The elements of tran | |
982 | // are tran[0] = r, tran[1] = rphi, and tran[2] = z. | |
983 | // The elements of rot are rot[0] = rx, rot[1] = ry, and | |
984 | // rot[2] = rz. A change in r will results in the increase of the | |
985 | // radius of each layer by the same about. A change in rphi will results in | |
986 | // the rotation of each layer by a different angle but by the same | |
987 | // circumferential distance. A change in z will result in a translation | |
988 | // of the ITS as a hole up or down the beam line. A change in the angles | |
989 | // will result in the inclination of the ITS with respect to the beam | |
990 | // line, except for an effective rotation about the beam axis which will | |
991 | // just rotate the ITS as a hole about the beam axis. | |
992 | // Intputs are: | |
993 | // Float_t *tran A 3 element array representing the global translations. | |
994 | // the elements are r,theta,z in cm/radians. | |
995 | // Float_t *rot A 3 element array representing the global rotation | |
996 | // angles about the three axis x,y,z in radians | |
997 | // Outputs are: | |
998 | // none. | |
999 | Int_t i,j; | |
1000 | Double_t t[3],ro[3],r,r0,phi,rphi; | |
1001 | AliITSgeomMatrix *g; | |
1002 | ||
1003 | fTrans = (fTrans && 0xfffd) + 2; // set bit 1 true. | |
1004 | for(i=0;i<fNmodules;i++){ | |
1005 | g = this->GetGeomMatrix(i); | |
1006 | g->GetTranslation(t); | |
1007 | g->GetAngles(ro); | |
1008 | r = r0= TMath::Hypot(t[1],t[0]); | |
1009 | phi = TMath::ATan2(t[1],t[0]); | |
1010 | rphi = r0*phi; | |
1011 | r += tran[0]; | |
1012 | rphi += tran[1]; | |
1013 | phi = rphi/r0; | |
1014 | t[0] = r*TMath::Cos(phi); | |
1015 | t[1] = r*TMath::Sin(phi); | |
1016 | t[2] += tran[2]; | |
1017 | for(j=0;j<3;j++){ | |
1018 | ro[j] += rot[j]; | |
1019 | } // end for j | |
1020 | g->SetTranslation(t); | |
1021 | g->SetAngles(ro); | |
1022 | } // end for i | |
1023 | return; | |
593e9459 | 1024 | } |
85f1e34a | 1025 | //______________________________________________________________________ |
269f57ed | 1026 | void AliITSgeom::RandomChange(const Float_t *stran,const Float_t *srot){ |
85f1e34a | 1027 | // This function performs a Gaussian random displacement and/or |
1028 | // rotation about the present global position of each active | |
1029 | // volume/detector of the ITS. The sigma of the random displacement | |
1030 | // is determined by the three element array stran, for the | |
1031 | // x y and z translations, and the three element array srot, | |
1032 | // for the three rotation about the axis x y and z. | |
1033 | // Intputs are: | |
1034 | // Float_t *stran A 3 element array representing the global translations | |
1035 | // variances. The elements are x,y,z in cm. | |
1036 | // Float_t *srot A 3 element array representing the global rotation | |
1037 | // angles variances about the three axis x,y,z in radians. | |
1038 | // Outputs are: | |
1039 | // none. | |
1040 | Int_t i,j; | |
1041 | Double_t t[3],r[3]; | |
1042 | AliITSgeomMatrix *g; | |
1043 | ||
1044 | fTrans = (fTrans && 0xfffd) + 2; // set bit 1 true. | |
1045 | for(i=0;i<fNmodules;i++){ | |
1046 | g = this->GetGeomMatrix(i); | |
1047 | g->GetTranslation(t); | |
1048 | g->GetAngles(r); | |
1049 | for(j=0;j<3;j++){ | |
1050 | t[j] += gRandom->Gaus(0.0,stran[j]); | |
1051 | r[j] += gRandom->Gaus(0.0, srot[j]); | |
1052 | } // end for j | |
1053 | g->SetTranslation(t); | |
1054 | g->SetAngles(r); | |
1055 | } // end for i | |
1056 | return; | |
593e9459 | 1057 | } |
85f1e34a | 1058 | //______________________________________________________________________ |
269f57ed | 1059 | void AliITSgeom::RandomCylindericalChange(const Float_t *stran, |
1060 | const Float_t *srot){ | |
85f1e34a | 1061 | // This function performs a Gaussian random displacement and/or |
1062 | // rotation about the present global position of each active | |
1063 | // volume/detector of the ITS. The sigma of the random displacement | |
1064 | // is determined by the three element array stran, for the | |
1065 | // r rphi and z translations, and the three element array srot, | |
1066 | // for the three rotation about the axis x y and z. This random change | |
1067 | // in detector position allow for the simulation of a random uncertainty | |
1068 | // in the detector positions of the ITS. | |
1069 | // Intputs are: | |
1070 | // Float_t *stran A 3 element array representing the global translations | |
1071 | // variances. The elements are r,theta,z in cm/readians. | |
1072 | // Float_t *srot A 3 element array representing the global rotation | |
1073 | // angles variances about the three axis x,y,z in radians. | |
1074 | // Outputs are: | |
1075 | // none. | |
1076 | Int_t i,j; | |
1077 | Double_t t[3],ro[3],r,r0,phi,rphi; | |
1078 | TRandom ran; | |
1079 | AliITSgeomMatrix *g; | |
1080 | ||
1081 | fTrans = (fTrans && 0xfffd) + 2; // set bit 1 true. | |
1082 | for(i=0;i<fNmodules;i++){ | |
1083 | g = this->GetGeomMatrix(i); | |
1084 | g->GetTranslation(t); | |
1085 | g->GetAngles(ro); | |
1086 | r = r0= TMath::Hypot(t[1],t[0]); | |
1087 | phi = TMath::ATan2(t[1],t[0]); | |
1088 | rphi = r0*phi; | |
1089 | r += ran.Gaus(0.0,stran[0]); | |
1090 | rphi += ran.Gaus(0.0,stran[1]); | |
1091 | phi = rphi/r0; | |
1092 | t[0] = r*TMath::Cos(phi); | |
1093 | t[1] = r*TMath::Sin(phi); | |
1094 | t[2] += ran.Gaus(0.0,stran[2]); | |
1095 | for(j=0;j<3;j++){ | |
1096 | ro[j] += ran.Gaus(0.0, srot[j]); | |
1097 | } // end for j | |
1098 | g->SetTranslation(t); | |
1099 | g->SetAngles(ro); | |
1100 | } // end for i | |
1101 | return; | |
593e9459 | 1102 | } |
1103 | //______________________________________________________________________ | |
1104 | void AliITSgeom::GeantToTracking(AliITSgeom &source){ | |
85f1e34a | 1105 | // Copy the geometry data but change it to go between the ALICE |
1106 | // Global coordinate system to that used by the ITS tracking. A slightly | |
1107 | // different coordinate system is used when tracking. This coordinate | |
1108 | // system is only relevant when the geometry represents the cylindrical | |
1109 | // ALICE ITS geometry. For tracking the Z axis is left alone but X-> -Y | |
1110 | // and Y-> X such that X always points out of the ITS cylinder for every | |
1111 | // layer including layer 1 (where the detectors are mounted upside down). | |
1112 | // Inputs are: | |
1113 | // AliITSgeom &source The AliITSgeom class with which to make this | |
1114 | // a copy of. | |
1115 | // Outputs are: | |
1116 | // return *this The a new copy of source. | |
1117 | //Begin_Html | |
1118 | /* | |
1119 | <img src="picts/ITS/AliITSgeomMatrix_T1.gif"> | |
1120 | */ | |
1121 | //End_Html | |
1122 | Int_t i,j,k,l,id[3]; | |
1123 | Double_t r0[3][3],r1[3][3]; | |
1124 | Double_t a0[3][3] = {{0.,+1.,0.},{-1.,0.,0.},{0.,0.,+1.}}; | |
1125 | Double_t a1[3][3] = {{0.,-1.,0.},{+1.,0.,0.},{0.,0.,+1.}}; | |
1126 | ||
1127 | *this = source; // copy everything | |
1128 | for(i=0;i<GetIndexMax();i++){ | |
1129 | GetGeomMatrix(i)->GetIndex(id); | |
1130 | GetGeomMatrix(i)->GetMatrix(r0); | |
1131 | if(id[0]==1){ // Layer 1 is treated different from the others. | |
1132 | for(j=0;j<3;j++) for(k=0;k<3;k++){ | |
1133 | r1[j][k] = 0.; | |
1134 | for(l=0;l<3;l++) r1[j][k] += a0[j][l]*r0[l][k]; | |
1135 | } // end for j,k | |
1136 | }else{ | |
1137 | for(j=0;j<3;j++) for(k=0;k<3;k++){ | |
1138 | r1[j][k] = 0.; | |
1139 | for(l=0;l<3;l++) r1[j][k] += a1[j][l]*r0[l][k]; | |
1140 | } // end for j,k | |
1141 | } // end if | |
1142 | GetGeomMatrix(i)->SetMatrix(r1); | |
1143 | } // end for i | |
1144 | this->fTrans = (this->fTrans && 0xfffe) + 1; // set bit 0 true. | |
1145 | return; | |
58005f18 | 1146 | } |
269f57ed | 1147 | //______________________________________________________________________ |
85f1e34a | 1148 | Int_t AliITSgeom::GetNearest(const Double_t g[3],Int_t lay){ |
1149 | // Finds the Detector (Module) that is nearest the point g [cm] in | |
1150 | // ALICE Global coordinates. If layer !=0 then the search is restricted | |
1151 | // to Detectors (Modules) in that particular layer. | |
1152 | // Inputs are: | |
1153 | // Double_t g[3] The ALICE Cartesean global coordinate from which the | |
1154 | // distance is to be calculated with. | |
1155 | // Int_t lay The layer to restrict the search to. If layer=0 then | |
1156 | // all layers are searched. Default is lay=0. | |
1157 | // Outputs are: | |
1158 | // return The module number representing the nearest module. | |
1159 | Int_t i,l,a,e,in=0; | |
1160 | Double_t d,dn=1.0e10; | |
1161 | Bool_t t=lay!=0; // skip if lay = 0 default value check all layers. | |
085bb6ed | 1162 | |
85f1e34a | 1163 | for(i=0;i<fNmodules;i++){ |
1164 | if(t){GetModuleId(i,l,a,e);if(l!=lay) continue;} | |
1165 | if((d=GetGeomMatrix(i)->Distance2(g))<dn){ | |
1166 | dn = d; | |
1167 | in = i; | |
1168 | } // end if | |
1169 | } // end for i | |
1170 | return in; | |
085bb6ed | 1171 | } |
269f57ed | 1172 | //______________________________________________________________________ |
85f1e34a | 1173 | void AliITSgeom::GetNearest27(const Double_t g[3],Int_t n[27],Int_t lay){ |
1174 | // Finds 27 Detectors (Modules) that are nearest the point g [cm] in | |
1175 | // ALICE Global coordinates. If layer !=0 then the search is restricted | |
1176 | // to Detectors (Modules) in that particular layer. The number 27 comes | |
1177 | // from including the nearest detector and all those around it (up, down, | |
1178 | // left, right, forwards, backwards, and the corners). | |
1179 | // Inputs are: | |
1180 | // Double_t g[3] The ALICE Cartesean global coordinate from which the | |
1181 | // distance is to be calculated with. | |
1182 | // Int_t lay The layer to restrict the search to. If layer=0 then | |
1183 | // all layers are searched. Default is lay=0. | |
1184 | // Outputs are: | |
1185 | // Int_t n[27] The module number representing the nearest 27 modules | |
1186 | // in order. | |
1187 | Int_t i,l,a,e,in[27]={0,0,0,0,0,0,0,0,0, | |
1188 | 0,0,0,0,0,0,0,0,0, | |
1189 | 0,0,0,0,0,0,0,0,0,}; | |
1190 | Double_t d,dn[27]={1.0e10,1.0e10,1.0e10,1.0e10,1.0e10,1.0e10, | |
1191 | 1.0e10,1.0e10,1.0e10,1.0e10,1.0e10,1.0e10, | |
1192 | 1.0e10,1.0e10,1.0e10,1.0e10,1.0e10,1.0e10, | |
1193 | 1.0e10,1.0e10,1.0e10,1.0e10,1.0e10,1.0e10, | |
1194 | 1.0e10,1.0e10,1.0e10}; | |
1195 | Bool_t t=(lay!=0); // skip if lay = 0 default value check all layers. | |
269f57ed | 1196 | |
85f1e34a | 1197 | for(i=0;i<fNmodules;i++){ |
1198 | if(t){GetModuleId(i,l,a,e);if(l!=lay) continue;} | |
1199 | for(a=0;a<27;a++){ | |
1200 | d = GetGeomMatrix(i)->Distance2(g); | |
1201 | if(d<dn[a]){ | |
1202 | for(e=26;e>a;e--){dn[e] = dn[e-1];in[e] = in[e-1];} | |
1203 | dn[a] = d; in[a] = i; | |
1204 | } // end if d<dn[i] | |
1205 | } // end for a | |
1206 | } // end for i | |
1207 | for(i=0;i<27;i++) n[i] = in[i]; | |
269f57ed | 1208 | } |
1209 | //---------------------------------------------------------------------- |