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 | |
acd84897 |
16 | /* $Id$ */ |
4c039060 |
17 | |
8494b010 |
18 | /////////////////////////////////////////////////////////////////////////////// |
19 | // // |
20 | // Base class for ALICE modules. Both sensitive modules (Modules) and // |
21 | // non-sensitive ones are described by this base class. This class // |
22 | // supports the hit and digit trees produced by the simulation and also // |
23 | // the objects produced by the reconstruction. // |
24 | // // |
25 | // This class is also responsible for building the geometry of the // |
26 | // Modules. // |
27 | // // |
28 | //Begin_Html |
29 | /* |
1439f98e |
30 | <img src="picts/AliModuleClass.gif"> |
8494b010 |
31 | */ |
32 | //End_Html |
33 | // // |
34 | /////////////////////////////////////////////////////////////////////////////// |
88cb7938 |
35 | |
94de3818 |
36 | #include <TNode.h> |
116cbefd |
37 | #include <TObjArray.h> |
2cad796f |
38 | #include <TClonesArray.h> |
39 | #include <TTree.h> |
116cbefd |
40 | #include <TSystem.h> |
2cad796f |
41 | #include <TDirectory.h> |
5d12ce38 |
42 | #include <TVirtualMC.h> |
94de3818 |
43 | |
88cb7938 |
44 | #include "AliConfig.h" |
45 | #include "AliLoader.h" |
46 | #include "AliMagF.h" |
8494b010 |
47 | #include "AliModule.h" |
48 | #include "AliRun.h" |
2cad796f |
49 | #include "AliTrackReference.h" |
5d12ce38 |
50 | #include "AliMC.h" |
8494b010 |
51 | |
52 | ClassImp(AliModule) |
53 | |
e2afb3b6 |
54 | //_______________________________________________________________________ |
55 | AliModule::AliModule(): |
56 | fEuclidMaterial(""), |
57 | fEuclidGeometry(""), |
58 | fIdtmed(0), |
59 | fIdmate(0), |
60 | fLoMedium(0), |
61 | fHiMedium(0), |
62 | fActive(0), |
63 | fHistograms(0), |
64 | fNodes(0), |
65 | fDebug(0), |
2cad796f |
66 | fEnable(1), |
67 | fTrackReferences(0), |
68 | fMaxIterTrackRef(0), |
69 | fCurrentIterTrackRef(0) |
8494b010 |
70 | { |
71 | // |
72 | // Default constructor for the AliModule class |
73 | // |
8494b010 |
74 | } |
75 | |
e2afb3b6 |
76 | //_______________________________________________________________________ |
77 | AliModule::AliModule(const char* name,const char *title): |
78 | TNamed(name,title), |
79 | fEuclidMaterial(""), |
80 | fEuclidGeometry(""), |
81 | fIdtmed(new TArrayI(100)), |
82 | fIdmate(new TArrayI(100)), |
83 | fLoMedium(65536), |
84 | fHiMedium(0), |
85 | fActive(0), |
86 | fHistograms(new TList()), |
87 | fNodes(new TList()), |
88 | fDebug(0), |
2cad796f |
89 | fEnable(1), |
90 | fTrackReferences(new TClonesArray("AliTrackReference", 100)), |
91 | fMaxIterTrackRef(0), |
92 | fCurrentIterTrackRef(0) |
8494b010 |
93 | { |
94 | // |
95 | // Normal constructor invoked by all Modules. |
96 | // Create the list for Module specific histograms |
97 | // Add this Module to the global list of Modules in Run. |
98 | // |
8494b010 |
99 | // Get the Module numeric ID |
100 | Int_t id = gAlice->GetModuleID(name); |
02ca2762 |
101 | if (id>=0) { |
102 | // Module already added ! |
103 | Warning("Ctor","Module: %s already present at %d\n",name,id); |
8494b010 |
104 | return; |
105 | } |
106 | // |
107 | // Add this Module to the list of Modules |
88cb7938 |
108 | |
109 | gAlice->AddModule(this); |
110 | |
8494b010 |
111 | SetMarkerColor(3); |
112 | // |
e2afb3b6 |
113 | // Clear space for tracking media and material indexes |
114 | |
8494b010 |
115 | for(Int_t i=0;i<100;i++) (*fIdmate)[i]=(*fIdtmed)[i]=0; |
9e1a0ddb |
116 | |
9e1a0ddb |
117 | |
65fb704d |
118 | SetDebug(gAlice->GetDebug()); |
8494b010 |
119 | } |
120 | |
e2afb3b6 |
121 | //_______________________________________________________________________ |
122 | AliModule::AliModule(const AliModule &mod): |
123 | TNamed(mod), |
124 | TAttLine(mod), |
125 | TAttMarker(mod), |
126 | AliRndm(mod), |
127 | fEuclidMaterial(""), |
128 | fEuclidGeometry(""), |
129 | fIdtmed(0), |
130 | fIdmate(0), |
131 | fLoMedium(0), |
132 | fHiMedium(0), |
133 | fActive(0), |
134 | fHistograms(0), |
135 | fNodes(0), |
136 | fDebug(0), |
2cad796f |
137 | fEnable(0), |
138 | fTrackReferences(0), |
139 | fMaxIterTrackRef(0), |
140 | fCurrentIterTrackRef(0) |
aee8290b |
141 | { |
142 | // |
143 | // Copy constructor |
144 | // |
8918e700 |
145 | mod.Copy(*this); |
aee8290b |
146 | } |
147 | |
e2afb3b6 |
148 | //_______________________________________________________________________ |
8494b010 |
149 | AliModule::~AliModule() |
150 | { |
151 | // |
152 | // Destructor |
153 | // |
e2afb3b6 |
154 | |
bbcea4df |
155 | // Remove this Module from the list of Modules |
a9cc22a2 |
156 | if (gAlice) { |
157 | TObjArray * modules = gAlice->Modules(); |
158 | if (modules) modules->Remove(this); |
159 | } |
8494b010 |
160 | // Delete ROOT geometry |
bf9b027f |
161 | if(fNodes) { |
162 | fNodes->Clear(); |
163 | delete fNodes; |
004a2444 |
164 | fNodes = 0; |
bf9b027f |
165 | } |
a1629660 |
166 | // Delete histograms |
167 | if(fHistograms) { |
168 | fHistograms->Clear(); |
169 | delete fHistograms; |
004a2444 |
170 | fHistograms = 0; |
171 | } |
172 | // Delete track references |
173 | if (fTrackReferences) { |
174 | fTrackReferences->Delete(); |
175 | delete fTrackReferences; |
176 | fTrackReferences = 0; |
a1629660 |
177 | } |
8494b010 |
178 | // Delete TArray objects |
179 | delete fIdtmed; |
180 | delete fIdmate; |
88cb7938 |
181 | |
8494b010 |
182 | } |
183 | |
e2afb3b6 |
184 | //_______________________________________________________________________ |
6c4904c2 |
185 | void AliModule::Copy(TObject & /* mod */) const |
aee8290b |
186 | { |
187 | // |
188 | // Copy *this onto mod, not implemented for AliModule |
189 | // |
190 | Fatal("Copy","Not implemented!\n"); |
191 | } |
192 | |
e2afb3b6 |
193 | //_______________________________________________________________________ |
8494b010 |
194 | void AliModule::Disable() |
195 | { |
196 | // |
197 | // Disable Module on viewer |
198 | // |
199 | fActive = kFALSE; |
200 | TIter next(fNodes); |
201 | TNode *node; |
202 | // |
203 | // Loop through geometry to disable all |
204 | // nodes for this Module |
e2afb3b6 |
205 | while((node = dynamic_cast<TNode*>(next()))) { |
5bef1017 |
206 | node->SetVisibility(-1); |
8494b010 |
207 | } |
208 | } |
209 | |
e2afb3b6 |
210 | //_______________________________________________________________________ |
8494b010 |
211 | void AliModule::Enable() |
212 | { |
213 | // |
214 | // Enable Module on the viewver |
215 | // |
216 | fActive = kTRUE; |
217 | TIter next(fNodes); |
218 | TNode *node; |
219 | // |
220 | // Loop through geometry to enable all |
221 | // nodes for this Module |
e2afb3b6 |
222 | while((node = dynamic_cast<TNode*>(next()))) { |
5bef1017 |
223 | node->SetVisibility(3); |
8494b010 |
224 | } |
225 | } |
226 | |
e2afb3b6 |
227 | //_______________________________________________________________________ |
8494b010 |
228 | void AliModule::AliMaterial(Int_t imat, const char* name, Float_t a, |
e2afb3b6 |
229 | Float_t z, Float_t dens, Float_t radl, |
230 | Float_t absl, Float_t *buf, Int_t nwbuf) const |
8494b010 |
231 | { |
232 | // |
233 | // Store the parameters for a material |
234 | // |
235 | // imat the material index will be stored in (*fIdmate)[imat] |
236 | // name material name |
237 | // a atomic mass |
238 | // z atomic number |
239 | // dens density |
240 | // radl radiation length |
241 | // absl absorbtion length |
242 | // buf adress of an array user words |
243 | // nwbuf number of user words |
244 | // |
245 | Int_t kmat; |
cfce8870 |
246 | gMC->Material(kmat, name, a, z, dens, radl, absl, buf, nwbuf); |
8494b010 |
247 | (*fIdmate)[imat]=kmat; |
248 | } |
249 | |
e2afb3b6 |
250 | //_______________________________________________________________________ |
0afa509f |
251 | void AliModule::AliGetMaterial(Int_t imat, char* name, Float_t &a, |
e2afb3b6 |
252 | Float_t &z, Float_t &dens, Float_t &radl, |
116cbefd |
253 | Float_t &absl) const |
0afa509f |
254 | { |
255 | // |
256 | // Store the parameters for a material |
257 | // |
258 | // imat the material index will be stored in (*fIdmate)[imat] |
259 | // name material name |
260 | // a atomic mass |
261 | // z atomic number |
262 | // dens density |
263 | // radl radiation length |
264 | // absl absorbtion length |
265 | // buf adress of an array user words |
266 | // nwbuf number of user words |
267 | // |
268 | |
269 | Float_t buf[10]; |
270 | Int_t nwbuf, kmat; |
271 | kmat=(*fIdmate)[imat]; |
272 | gMC->Gfmate(kmat, name, a, z, dens, radl, absl, buf, nwbuf); |
273 | } |
274 | |
8494b010 |
275 | |
e2afb3b6 |
276 | //_______________________________________________________________________ |
8494b010 |
277 | void AliModule::AliMixture(Int_t imat, const char *name, Float_t *a, |
e2afb3b6 |
278 | Float_t *z, Float_t dens, Int_t nlmat, |
279 | Float_t *wmat) const |
8494b010 |
280 | { |
281 | // |
282 | // Defines mixture or compound imat as composed by |
283 | // nlmat materials defined by arrays a, z and wmat |
284 | // |
285 | // If nlmat > 0 wmat contains the proportion by |
286 | // weights of each basic material in the mixture |
287 | // |
288 | // If nlmat < 0 wmat contains the number of atoms |
289 | // of eack kind in the molecule of the compound |
290 | // In this case, wmat is changed on output to the relative weigths. |
291 | // |
292 | // imat the material index will be stored in (*fIdmate)[imat] |
293 | // name material name |
294 | // a array of atomic masses |
295 | // z array of atomic numbers |
296 | // dens density |
297 | // nlmat number of components |
298 | // wmat array of concentrations |
299 | // |
300 | Int_t kmat; |
cfce8870 |
301 | gMC->Mixture(kmat, name, a, z, dens, nlmat, wmat); |
8494b010 |
302 | (*fIdmate)[imat]=kmat; |
303 | } |
304 | |
e2afb3b6 |
305 | //_______________________________________________________________________ |
8494b010 |
306 | void AliModule::AliMedium(Int_t numed, const char *name, Int_t nmat, |
e2afb3b6 |
307 | Int_t isvol, Int_t ifield, Float_t fieldm, |
308 | Float_t tmaxfd, Float_t stemax, Float_t deemax, |
309 | Float_t epsil, Float_t stmin, Float_t *ubuf, |
310 | Int_t nbuf) const |
8494b010 |
311 | { |
312 | // |
313 | // Store the parameters of a tracking medium |
314 | // |
b13db077 |
315 | // numed the medium number is stored into (*fIdtmed)[numed] |
8494b010 |
316 | // name medium name |
317 | // nmat the material number is stored into (*fIdmate)[nmat] |
318 | // isvol sensitive volume if isvol!=0 |
319 | // ifield magnetic field flag (see below) |
320 | // fieldm maximum magnetic field |
321 | // tmaxfd maximum deflection angle due to magnetic field |
322 | // stemax maximum step allowed |
323 | // deemax maximum fractional energy loss in one step |
324 | // epsil tracking precision in cm |
325 | // stmin minimum step due to continuous processes |
326 | // |
327 | // ifield = 0 no magnetic field |
328 | // = -1 user decision in guswim |
329 | // = 1 tracking performed with Runge Kutta |
330 | // = 2 tracking performed with helix |
331 | // = 3 constant magnetic field along z |
332 | // |
333 | Int_t kmed; |
cfce8870 |
334 | gMC->Medium(kmed,name, (*fIdmate)[nmat], isvol, ifield, fieldm, |
8494b010 |
335 | tmaxfd, stemax, deemax, epsil, stmin, ubuf, nbuf); |
ad51aeb0 |
336 | (*fIdtmed)[numed]=kmed; |
8494b010 |
337 | } |
338 | |
e2afb3b6 |
339 | //_______________________________________________________________________ |
8494b010 |
340 | void AliModule::AliMatrix(Int_t &nmat, Float_t theta1, Float_t phi1, |
e2afb3b6 |
341 | Float_t theta2, Float_t phi2, Float_t theta3, |
342 | Float_t phi3) const |
8494b010 |
343 | { |
344 | // |
345 | // Define a rotation matrix. Angles are in degrees. |
346 | // |
347 | // nmat on output contains the number assigned to the rotation matrix |
348 | // theta1 polar angle for axis I |
349 | // phi1 azimuthal angle for axis I |
350 | // theta2 polar angle for axis II |
351 | // phi2 azimuthal angle for axis II |
352 | // theta3 polar angle for axis III |
353 | // phi3 azimuthal angle for axis III |
354 | // |
cfce8870 |
355 | gMC->Matrix(nmat, theta1, phi1, theta2, phi2, theta3, phi3); |
8494b010 |
356 | } |
357 | |
e2afb3b6 |
358 | //_______________________________________________________________________ |
65fb704d |
359 | Float_t AliModule::ZMin() const |
360 | { |
361 | return -500; |
362 | } |
363 | |
e2afb3b6 |
364 | //_______________________________________________________________________ |
65fb704d |
365 | Float_t AliModule::ZMax() const |
366 | { |
367 | return 500; |
368 | } |
369 | |
e2afb3b6 |
370 | //_______________________________________________________________________ |
8494b010 |
371 | void AliModule::SetEuclidFile(char* material, char* geometry) |
372 | { |
373 | // |
374 | // Sets the name of the Euclid file |
375 | // |
376 | fEuclidMaterial=material; |
377 | if(geometry) { |
378 | fEuclidGeometry=geometry; |
379 | } else { |
380 | char* name = new char[strlen(material)]; |
381 | strcpy(name,material); |
382 | strcpy(&name[strlen(name)-4],".euc"); |
383 | fEuclidGeometry=name; |
384 | delete [] name; |
385 | } |
386 | } |
387 | |
e2afb3b6 |
388 | //_______________________________________________________________________ |
b13db077 |
389 | void AliModule::ReadEuclid(const char* filnam, char* topvol) |
390 | { |
391 | // |
392 | // read in the geometry of the detector in euclid file format |
393 | // |
394 | // id_det : the detector identification (2=its,...) |
395 | // topvol : return parameter describing the name of the top |
396 | // volume of geometry. |
397 | // |
398 | // author : m. maire |
399 | // |
400 | // 28.07.98 |
401 | // several changes have been made by miroslav helbich |
402 | // subroutine is rewrited to follow the new established way of memory |
403 | // booking for tracking medias and rotation matrices. |
404 | // all used tracking media have to be defined first, for this you can use |
405 | // subroutine greutmed. |
406 | // top volume is searched as only volume not positioned into another |
407 | // |
408 | |
409 | Int_t i, nvol, iret, itmed, irot, numed, npar, ndiv, iaxe; |
410 | Int_t ndvmx, nr, flag; |
411 | char key[5], card[77], natmed[21]; |
412 | char name[5], mother[5], shape[5], konly[5], volst[7000][5]; |
413 | char *filtmp; |
d43b40e2 |
414 | Float_t par[100]; |
b13db077 |
415 | Float_t teta1, phi1, teta2, phi2, teta3, phi3, orig, step; |
416 | Float_t xo, yo, zo; |
aee8290b |
417 | const Int_t kMaxRot=5000; |
418 | Int_t idrot[kMaxRot],istop[7000]; |
b13db077 |
419 | FILE *lun; |
420 | // |
421 | // *** The input filnam name will be with extension '.euc' |
422 | filtmp=gSystem->ExpandPathName(filnam); |
423 | lun=fopen(filtmp,"r"); |
424 | delete [] filtmp; |
425 | if(!lun) { |
426 | Error("ReadEuclid","Could not open file %s\n",filnam); |
427 | return; |
428 | } |
429 | //* --- definition of rotation matrix 0 --- |
430 | TArrayI &idtmed = *fIdtmed; |
aee8290b |
431 | for(i=1; i<kMaxRot; ++i) idrot[i]=-99; |
b13db077 |
432 | idrot[0]=0; |
433 | nvol=0; |
434 | L10: |
435 | for(i=0;i<77;i++) card[i]=0; |
436 | iret=fscanf(lun,"%77[^\n]",card); |
437 | if(iret<=0) goto L20; |
438 | fscanf(lun,"%*c"); |
439 | //* |
440 | strncpy(key,card,4); |
441 | key[4]='\0'; |
442 | if (!strcmp(key,"TMED")) { |
443 | sscanf(&card[5],"%d '%[^']'",&itmed,natmed); |
444 | if( itmed<0 || itmed>=100 ) { |
445 | Error("ReadEuclid","TMED illegal medium number %d for %s\n",itmed,natmed); |
446 | exit(1); |
447 | } |
448 | //Pad the string with blanks |
449 | i=-1; |
450 | while(natmed[++i]); |
451 | while(i<20) natmed[i++]=' '; |
452 | natmed[i]='\0'; |
453 | // |
454 | if( idtmed[itmed]<=0 ) { |
455 | Error("ReadEuclid","TMED undefined medium number %d for %s\n",itmed,natmed); |
456 | exit(1); |
457 | } |
458 | gMC->Gckmat(idtmed[itmed],natmed); |
459 | //* |
460 | } else if (!strcmp(key,"ROTM")) { |
461 | sscanf(&card[4],"%d %f %f %f %f %f %f",&irot,&teta1,&phi1,&teta2,&phi2,&teta3,&phi3); |
aee8290b |
462 | if( irot<=0 || irot>=kMaxRot ) { |
b13db077 |
463 | Error("ReadEuclid","ROTM rotation matrix number %d illegal\n",irot); |
464 | exit(1); |
465 | } |
466 | AliMatrix(idrot[irot],teta1,phi1,teta2,phi2,teta3,phi3); |
467 | //* |
468 | } else if (!strcmp(key,"VOLU")) { |
469 | sscanf(&card[5],"'%[^']' '%[^']' %d %d", name, shape, &numed, &npar); |
470 | if (npar>0) { |
471 | for(i=0;i<npar;i++) fscanf(lun,"%f",&par[i]); |
472 | fscanf(lun,"%*c"); |
473 | } |
474 | gMC->Gsvolu( name, shape, idtmed[numed], par, npar); |
475 | //* save the defined volumes |
476 | strcpy(volst[++nvol],name); |
477 | istop[nvol]=1; |
478 | //* |
479 | } else if (!strcmp(key,"DIVN")) { |
480 | sscanf(&card[5],"'%[^']' '%[^']' %d %d", name, mother, &ndiv, &iaxe); |
481 | gMC->Gsdvn ( name, mother, ndiv, iaxe ); |
482 | //* |
483 | } else if (!strcmp(key,"DVN2")) { |
484 | sscanf(&card[5],"'%[^']' '%[^']' %d %d %f %d",name, mother, &ndiv, &iaxe, &orig, &numed); |
485 | gMC->Gsdvn2( name, mother, ndiv, iaxe, orig,idtmed[numed]); |
486 | //* |
487 | } else if (!strcmp(key,"DIVT")) { |
488 | sscanf(&card[5],"'%[^']' '%[^']' %f %d %d %d", name, mother, &step, &iaxe, &numed, &ndvmx); |
489 | gMC->Gsdvt ( name, mother, step, iaxe, idtmed[numed], ndvmx); |
490 | //* |
491 | } else if (!strcmp(key,"DVT2")) { |
492 | sscanf(&card[5],"'%[^']' '%[^']' %f %d %f %d %d", name, mother, &step, &iaxe, &orig, &numed, &ndvmx); |
493 | gMC->Gsdvt2 ( name, mother, step, iaxe, orig, idtmed[numed], ndvmx ); |
494 | //* |
495 | } else if (!strcmp(key,"POSI")) { |
496 | sscanf(&card[5],"'%[^']' %d '%[^']' %f %f %f %d '%[^']'", name, &nr, mother, &xo, &yo, &zo, &irot, konly); |
aee8290b |
497 | if( irot<0 || irot>=kMaxRot ) { |
b13db077 |
498 | Error("ReadEuclid","POSI %s#%d rotation matrix number %d illegal\n",name,nr,irot); |
499 | exit(1); |
500 | } |
501 | if( idrot[irot] == -99) { |
502 | Error("ReadEuclid","POSI %s#%d undefined matrix number %d\n",name,nr,irot); |
503 | exit(1); |
504 | } |
505 | //*** volume name cannot be the top volume |
506 | for(i=1;i<=nvol;i++) { |
507 | if (!strcmp(volst[i],name)) istop[i]=0; |
508 | } |
509 | //* |
510 | gMC->Gspos ( name, nr, mother, xo, yo, zo, idrot[irot], konly ); |
511 | //* |
512 | } else if (!strcmp(key,"POSP")) { |
513 | sscanf(&card[5],"'%[^']' %d '%[^']' %f %f %f %d '%[^']' %d", name, &nr, mother, &xo, &yo, &zo, &irot, konly, &npar); |
aee8290b |
514 | if( irot<0 || irot>=kMaxRot ) { |
b13db077 |
515 | Error("ReadEuclid","POSP %s#%d rotation matrix number %d illegal\n",name,nr,irot); |
516 | exit(1); |
517 | } |
518 | if( idrot[irot] == -99) { |
519 | Error("ReadEuclid","POSP %s#%d undefined matrix number %d\n",name,nr,irot); |
520 | exit(1); |
521 | } |
522 | if (npar > 0) { |
523 | for(i=0;i<npar;i++) fscanf(lun,"%f",&par[i]); |
524 | fscanf(lun,"%*c"); |
525 | } |
526 | //*** volume name cannot be the top volume |
527 | for(i=1;i<=nvol;i++) { |
528 | if (!strcmp(volst[i],name)) istop[i]=0; |
529 | } |
530 | //* |
531 | gMC->Gsposp ( name, nr, mother, xo,yo,zo, idrot[irot], konly, par, npar); |
532 | } |
533 | //* |
534 | if (strcmp(key,"END")) goto L10; |
535 | //* find top volume in the geometry |
536 | flag=0; |
537 | for(i=1;i<=nvol;i++) { |
538 | if (istop[i] && flag) { |
539 | Warning("ReadEuclid"," %s is another possible top volume\n",volst[i]); |
540 | } |
541 | if (istop[i] && !flag) { |
542 | strcpy(topvol,volst[i]); |
9e1a0ddb |
543 | if(fDebug) printf("%s::ReadEuclid: volume %s taken as a top volume\n",ClassName(),topvol); |
b13db077 |
544 | flag=1; |
545 | } |
546 | } |
547 | if (!flag) { |
548 | Warning("ReadEuclid","top volume not found\n"); |
549 | } |
550 | fclose (lun); |
551 | //* |
552 | //* commented out only for the not cernlib version |
9e1a0ddb |
553 | if(fDebug) printf("%s::ReadEuclid: file: %s is now read in\n",ClassName(),filnam); |
b13db077 |
554 | // |
555 | return; |
556 | //* |
557 | L20: |
558 | Error("ReadEuclid","reading error or premature end of file\n"); |
559 | } |
560 | |
e2afb3b6 |
561 | //_______________________________________________________________________ |
b13db077 |
562 | void AliModule::ReadEuclidMedia(const char* filnam) |
563 | { |
564 | // |
565 | // read in the materials and tracking media for the detector |
566 | // in euclid file format |
567 | // |
568 | // filnam: name of the input file |
569 | // id_det: id_det is the detector identification (2=its,...) |
570 | // |
571 | // author : miroslav helbich |
572 | // |
573 | Float_t sxmgmx = gAlice->Field()->Max(); |
574 | Int_t isxfld = gAlice->Field()->Integ(); |
575 | Int_t end, i, iret, itmed; |
576 | char key[5], card[130], natmed[21], namate[21]; |
577 | Float_t ubuf[50]; |
578 | char* filtmp; |
579 | FILE *lun; |
580 | Int_t imate; |
581 | Int_t nwbuf, isvol, ifield, nmat; |
582 | Float_t a, z, dens, radl, absl, fieldm, tmaxfd, stemax, deemax, epsil, stmin; |
583 | // |
584 | end=strlen(filnam); |
585 | for(i=0;i<end;i++) if(filnam[i]=='.') { |
586 | end=i; |
587 | break; |
588 | } |
589 | // |
590 | // *** The input filnam name will be with extension '.euc' |
9e1a0ddb |
591 | if(fDebug) printf("%s::ReadEuclid: The file name is %s\n",ClassName(),filnam); //Debug |
b13db077 |
592 | filtmp=gSystem->ExpandPathName(filnam); |
593 | lun=fopen(filtmp,"r"); |
594 | delete [] filtmp; |
595 | if(!lun) { |
596 | Warning("ReadEuclidMedia","Could not open file %s\n",filnam); |
597 | return; |
598 | } |
599 | // |
600 | // Retrieve Mag Field parameters |
aee8290b |
601 | Int_t globField=gAlice->Field()->Integ(); |
602 | Float_t globMaxField=gAlice->Field()->Max(); |
b13db077 |
603 | // TArrayI &idtmed = *fIdtmed; |
604 | // |
605 | L10: |
606 | for(i=0;i<130;i++) card[i]=0; |
607 | iret=fscanf(lun,"%4s %[^\n]",key,card); |
608 | if(iret<=0) goto L20; |
609 | fscanf(lun,"%*c"); |
610 | //* |
611 | //* read material |
612 | if (!strcmp(key,"MATE")) { |
613 | sscanf(card,"%d '%[^']' %f %f %f %f %f %d",&imate,namate,&a,&z,&dens,&radl,&absl,&nwbuf); |
614 | if (nwbuf>0) for(i=0;i<nwbuf;i++) fscanf(lun,"%f",&ubuf[i]); |
615 | //Pad the string with blanks |
616 | i=-1; |
617 | while(namate[++i]); |
618 | while(i<20) namate[i++]=' '; |
619 | namate[i]='\0'; |
620 | // |
621 | AliMaterial(imate,namate,a,z,dens,radl,absl,ubuf,nwbuf); |
622 | //* read tracking medium |
623 | } else if (!strcmp(key,"TMED")) { |
624 | sscanf(card,"%d '%[^']' %d %d %d %f %f %f %f %f %f %d", |
625 | &itmed,natmed,&nmat,&isvol,&ifield,&fieldm,&tmaxfd, |
626 | &stemax,&deemax,&epsil,&stmin,&nwbuf); |
627 | if (nwbuf>0) for(i=0;i<nwbuf;i++) fscanf(lun,"%f",&ubuf[i]); |
628 | if (ifield<0) ifield=isxfld; |
629 | if (fieldm<0) fieldm=sxmgmx; |
630 | //Pad the string with blanks |
631 | i=-1; |
632 | while(natmed[++i]); |
633 | while(i<20) natmed[i++]=' '; |
634 | natmed[i]='\0'; |
635 | // |
aee8290b |
636 | AliMedium(itmed,natmed,nmat,isvol,globField,globMaxField,tmaxfd, |
b13db077 |
637 | stemax,deemax,epsil,stmin,ubuf,nwbuf); |
638 | // (*fImedia)[idtmed[itmed]-1]=id_det; |
639 | //* |
640 | } |
641 | //* |
642 | if (strcmp(key,"END")) goto L10; |
643 | fclose (lun); |
644 | //* |
645 | //* commented out only for the not cernlib version |
9e1a0ddb |
646 | if(fDebug) printf("%s::ReadEuclidMedia: file %s is now read in\n", |
647 | ClassName(),filnam); |
b13db077 |
648 | //* |
649 | return; |
650 | //* |
651 | L20: |
652 | Warning("ReadEuclidMedia","reading error or premature end of file\n"); |
653 | } |
2cad796f |
654 | |
655 | //_______________________________________________________________________ |
656 | void AliModule::RemapTrackReferencesIDs(Int_t *map) |
657 | { |
658 | // |
659 | // Remapping track reference |
660 | // Called at finish primary |
661 | // |
662 | if (!fTrackReferences) return; |
663 | for (Int_t i=0;i<fTrackReferences->GetEntries();i++){ |
664 | AliTrackReference * ref = dynamic_cast<AliTrackReference*>(fTrackReferences->UncheckedAt(i)); |
665 | if (ref) { |
666 | Int_t newID = map[ref->GetTrack()]; |
667 | if (newID>=0) ref->SetTrack(newID); |
2b22f272 |
668 | else { |
669 | //ref->SetTrack(-1); |
670 | ref->SetBit(kNotDeleted,kFALSE); |
671 | fTrackReferences->RemoveAt(i); |
672 | } |
2cad796f |
673 | } |
674 | } |
2b22f272 |
675 | fTrackReferences->Compress(); |
676 | |
2cad796f |
677 | } |
678 | |
679 | |
680 | //_______________________________________________________________________ |
681 | AliTrackReference* AliModule::FirstTrackReference(Int_t track) |
682 | { |
683 | // |
684 | // Initialise the hit iterator |
685 | // Return the address of the first hit for track |
686 | // If track>=0 the track is read from disk |
687 | // while if track<0 the first hit of the current |
688 | // track is returned |
689 | // |
88cb7938 |
690 | if(track>=0) |
691 | { |
692 | AliRunLoader* rl = AliRunLoader::GetRunLoader(); |
693 | |
5d12ce38 |
694 | rl->GetAliRun()->GetMCApp()->ResetTrackReferences(); |
88cb7938 |
695 | rl->TreeTR()->GetEvent(track); |
696 | if (rl == 0x0) |
697 | Fatal("FirstTrackReference","AliRunLoader not initialized. Can not proceed"); |
698 | } |
2cad796f |
699 | // |
700 | fMaxIterTrackRef = fTrackReferences->GetEntriesFast(); |
701 | fCurrentIterTrackRef = 0; |
702 | if(fMaxIterTrackRef) return dynamic_cast<AliTrackReference*>(fTrackReferences->UncheckedAt(0)); |
703 | else return 0; |
704 | } |
705 | |
706 | //_______________________________________________________________________ |
707 | AliTrackReference* AliModule::NextTrackReference() |
708 | { |
709 | // |
710 | // Return the next hit for the current track |
711 | // |
712 | if(fMaxIterTrackRef) { |
713 | if(++fCurrentIterTrackRef<fMaxIterTrackRef) |
714 | return dynamic_cast<AliTrackReference*>(fTrackReferences->UncheckedAt(fCurrentIterTrackRef)); |
715 | else |
716 | return 0; |
717 | } else { |
88cb7938 |
718 | printf("* AliModule::NextTrackReference * TrackReference Iterator called without calling FistTrackReference before\n"); |
2cad796f |
719 | return 0; |
720 | } |
721 | } |
722 | |
723 | |
724 | //_______________________________________________________________________ |
725 | void AliModule::ResetTrackReferences() |
726 | { |
727 | // |
728 | // Reset number of hits and the hits array |
729 | // |
730 | fMaxIterTrackRef = 0; |
731 | if (fTrackReferences) fTrackReferences->Clear(); |
732 | } |
b13db077 |
733 | |
88cb7938 |
734 | //_____________________________________________________________________________ |
735 | |
d1898505 |
736 | AliLoader* AliModule::MakeLoader(const char* /*topfoldername*/) |
88cb7938 |
737 | { |
738 | return 0x0; |
739 | }//skowron |
8494b010 |
740 | |
88cb7938 |
741 | //PH Merged with v3-09-08 | |
742 | // V |
743 | //_____________________________________________________________________________ |
2cad796f |
744 | |
745 | void AliModule::SetTreeAddress() |
746 | { |
747 | // |
88cb7938 |
748 | // Set branch address for track reference Tree |
2cad796f |
749 | // |
88cb7938 |
750 | |
751 | TBranch *branch; |
752 | |
753 | // Branch address for track reference tree |
754 | TTree *treeTR = TreeTR(); |
755 | |
756 | if (treeTR && fTrackReferences) { |
757 | branch = treeTR->GetBranch(GetName()); |
758 | if (branch) |
759 | { |
f2a509af |
760 | if(GetDebug()) |
761 | Info("SetTreeAddress","(%s) Setting for TrackRefs",GetName()); |
88cb7938 |
762 | branch->SetAddress(&fTrackReferences); |
763 | } |
764 | else |
f2a509af |
765 | { |
766 | //can be called before MakeBranch and than does not make sense to issue the warning |
767 | if(GetDebug()) |
768 | Warning("SetTreeAddress", |
769 | "(%s) Failed for Track References. Can not find branch in tree.", |
770 | GetName()); |
88cb7938 |
771 | } |
772 | } |
2cad796f |
773 | } |
774 | |
88cb7938 |
775 | //_____________________________________________________________________________ |
2cad796f |
776 | void AliModule::AddTrackReference(Int_t label){ |
777 | // |
778 | // add a trackrefernce to the list |
779 | if (!fTrackReferences) { |
780 | cerr<<"Container trackrefernce not active\n"; |
781 | return; |
782 | } |
783 | Int_t nref = fTrackReferences->GetEntriesFast(); |
784 | TClonesArray &lref = *fTrackReferences; |
785 | new(lref[nref]) AliTrackReference(label); |
786 | } |
787 | |
788 | |
88cb7938 |
789 | //_____________________________________________________________________________ |
d1898505 |
790 | void AliModule::MakeBranchTR(Option_t */*option*/) |
2cad796f |
791 | { |
792 | // |
793 | // Makes branch in treeTR |
794 | // |
88cb7938 |
795 | if(GetDebug()) Info("MakeBranchTR","Making Track Refs. Branch for %s",GetName()); |
796 | TTree * tree = TreeTR(); |
797 | if (fTrackReferences && tree) |
798 | { |
799 | TBranch *branch = tree->GetBranch(GetName()); |
800 | if (branch) |
801 | { |
802 | if(GetDebug()) Info("MakeBranch","Branch %s is already in tree.",GetName()); |
803 | return; |
804 | } |
805 | |
806 | branch = tree->Branch(GetName(),&fTrackReferences); |
807 | } |
808 | else |
809 | { |
810 | if(GetDebug()) |
811 | Info("MakeBranchTR","FAILED for %s: tree=%#x fTrackReferences=%#x", |
812 | GetName(),tree,fTrackReferences); |
2cad796f |
813 | } |
814 | } |
88cb7938 |
815 | |
816 | //_____________________________________________________________________________ |
817 | TTree* AliModule::TreeTR() |
818 | { |
819 | AliRunLoader* rl = AliRunLoader::GetRunLoader(); |
820 | |
821 | if ( rl == 0x0) |
822 | { |
823 | Error("TreeTR","Can not get the run loader"); |
824 | return 0x0; |
825 | } |
826 | |
827 | TTree* tree = rl->TreeTR(); |
828 | return tree; |
829 | } |