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