]>
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 | |
116cbefd | 36 | #include <TObjArray.h> |
2cad796f | 37 | #include <TClonesArray.h> |
38 | #include <TTree.h> | |
116cbefd | 39 | #include <TSystem.h> |
2cad796f | 40 | #include <TDirectory.h> |
5d12ce38 | 41 | #include <TVirtualMC.h> |
4a9de4af | 42 | #include <TGeoManager.h> |
43 | #include <TString.h> | |
94de3818 | 44 | |
594d8990 | 45 | #include "AliLog.h" |
88cb7938 | 46 | #include "AliConfig.h" |
47 | #include "AliLoader.h" | |
48 | #include "AliMagF.h" | |
8494b010 | 49 | #include "AliModule.h" |
50 | #include "AliRun.h" | |
2cad796f | 51 | #include "AliTrackReference.h" |
5d12ce38 | 52 | #include "AliMC.h" |
d97f1dbe | 53 | #include "AliSimulation.h" |
9876c705 | 54 | #include "AliRawDataHeaderV3.h" |
f21fc003 | 55 | #include "AliDigitizationInput.h" |
00b459eb | 56 | |
362c9d61 | 57 | #include "AliDAQ.h" |
8494b010 | 58 | |
66b0310c | 59 | using std::endl; |
60 | using std::cout; | |
61 | using std::fstream; | |
62 | using std::ios; | |
63 | using std::ostream; | |
8494b010 | 64 | ClassImp(AliModule) |
65 | ||
00ee7999 | 66 | Float_t AliModule::fgDensityFactor = 1.0; |
67 | ||
e2afb3b6 | 68 | //_______________________________________________________________________ |
69 | AliModule::AliModule(): | |
e2afb3b6 | 70 | fIdtmed(0), |
71 | fIdmate(0), | |
72 | fLoMedium(0), | |
73 | fHiMedium(0), | |
74 | fActive(0), | |
2cad796f | 75 | fEnable(1), |
2cad796f | 76 | fMaxIterTrackRef(0), |
6d7874d8 | 77 | fCurrentIterTrackRef(0), |
f21fc003 | 78 | fRunLoader(0), |
79 | fDigInput(0) | |
8494b010 | 80 | { |
81 | // | |
82 | // Default constructor for the AliModule class | |
83 | // | |
8494b010 | 84 | } |
85 | ||
e2afb3b6 | 86 | //_______________________________________________________________________ |
87 | AliModule::AliModule(const char* name,const char *title): | |
88 | TNamed(name,title), | |
e2afb3b6 | 89 | fIdtmed(new TArrayI(100)), |
90 | fIdmate(new TArrayI(100)), | |
91 | fLoMedium(65536), | |
92 | fHiMedium(0), | |
93 | fActive(0), | |
2cad796f | 94 | fEnable(1), |
2cad796f | 95 | fMaxIterTrackRef(0), |
6d7874d8 | 96 | fCurrentIterTrackRef(0), |
f21fc003 | 97 | fRunLoader(0), |
98 | fDigInput(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 |
2e42b4d4 | 106 | |
8494b010 | 107 | Int_t id = gAlice->GetModuleID(name); |
02ca2762 | 108 | if (id>=0) { |
109 | // Module already added ! | |
594d8990 | 110 | AliWarning(Form("Module: %s already present at %d",name,id)); |
8494b010 | 111 | return; |
112 | } | |
113 | // | |
114 | // Add this Module to the list of Modules | |
88cb7938 | 115 | |
116 | gAlice->AddModule(this); | |
117 | ||
e939a978 | 118 | //PH SetMarkerColor(3); |
8494b010 | 119 | // |
e2afb3b6 | 120 | // Clear space for tracking media and material indexes |
121 | ||
8494b010 | 122 | for(Int_t i=0;i<100;i++) (*fIdmate)[i]=(*fIdtmed)[i]=0; |
8494b010 | 123 | } |
124 | ||
e2afb3b6 | 125 | //_______________________________________________________________________ |
8494b010 | 126 | AliModule::~AliModule() |
127 | { | |
128 | // | |
129 | // Destructor | |
130 | // | |
e2afb3b6 | 131 | |
bbcea4df | 132 | // Remove this Module from the list of Modules |
a9cc22a2 | 133 | if (gAlice) { |
134 | TObjArray * modules = gAlice->Modules(); | |
135 | if (modules) modules->Remove(this); | |
136 | } | |
7dd2cbe4 | 137 | |
8494b010 | 138 | // Delete TArray objects |
139 | delete fIdtmed; | |
140 | delete fIdmate; | |
88cb7938 | 141 | |
7dd2cbe4 | 142 | } |
8494b010 | 143 | |
e2afb3b6 | 144 | //_______________________________________________________________________ |
8494b010 | 145 | void AliModule::AliMaterial(Int_t imat, const char* name, Float_t a, |
e2afb3b6 | 146 | Float_t z, Float_t dens, Float_t radl, |
147 | Float_t absl, Float_t *buf, Int_t nwbuf) const | |
8494b010 | 148 | { |
149 | // | |
150 | // Store the parameters for a material | |
151 | // | |
152 | // imat the material index will be stored in (*fIdmate)[imat] | |
153 | // name material name | |
154 | // a atomic mass | |
155 | // z atomic number | |
156 | // dens density | |
157 | // radl radiation length | |
158 | // absl absorbtion length | |
159 | // buf adress of an array user words | |
160 | // nwbuf number of user words | |
161 | // | |
162 | Int_t kmat; | |
4a9de4af | 163 | //Build the string uniquename as "DET_materialname" |
164 | TString uniquename = GetName(); | |
165 | uniquename.Append("_"); | |
166 | uniquename.Append(name); | |
167 | //if geometry loaded from file only fill fIdmate, else create material too | |
d97f1dbe | 168 | if(AliSimulation::Instance()->IsGeometryFromFile()){ |
4a9de4af | 169 | TGeoMaterial *mat = gGeoManager->GetMaterial(uniquename.Data()); |
170 | kmat = mat->GetUniqueID(); | |
171 | (*fIdmate)[imat]=kmat; | |
172 | }else{ | |
00ee7999 | 173 | if (fgDensityFactor != 1.0) |
174 | AliWarning(Form("Material density multiplied by %.2f!", fgDensityFactor)); | |
175 | gMC->Material(kmat, uniquename.Data(), a, z, dens * fgDensityFactor, radl, absl, buf, nwbuf); | |
4a9de4af | 176 | (*fIdmate)[imat]=kmat; |
177 | } | |
8494b010 | 178 | } |
f35a7b6f | 179 | |
e2afb3b6 | 180 | //_______________________________________________________________________ |
0afa509f | 181 | void AliModule::AliGetMaterial(Int_t imat, char* name, Float_t &a, |
e2afb3b6 | 182 | Float_t &z, Float_t &dens, Float_t &radl, |
116cbefd | 183 | Float_t &absl) const |
0afa509f | 184 | { |
185 | // | |
186 | // Store the parameters for a material | |
187 | // | |
188 | // imat the material index will be stored in (*fIdmate)[imat] | |
189 | // name material name | |
190 | // a atomic mass | |
191 | // z atomic number | |
192 | // dens density | |
193 | // radl radiation length | |
194 | // absl absorbtion length | |
195 | // buf adress of an array user words | |
196 | // nwbuf number of user words | |
197 | // | |
198 | ||
f35a7b6f | 199 | Int_t kmat=(*fIdmate)[imat]; |
200 | TString sname; | |
201 | TArrayD par; | |
202 | Double_t da, dz, ddens, dradl, dabsl; | |
203 | gMC->GetMaterial(kmat, sname, da, dz, ddens, dradl, dabsl, par); | |
204 | ||
205 | const char* chname = sname.Data(); | |
516f763d | 206 | strncpy(name, chname, strlen(chname)+1); |
f35a7b6f | 207 | a = da; |
208 | z = dz; | |
209 | dens = ddens; | |
210 | radl = dradl; | |
211 | absl = dabsl; | |
0afa509f | 212 | } |
8494b010 | 213 | |
e2afb3b6 | 214 | //_______________________________________________________________________ |
8494b010 | 215 | void AliModule::AliMixture(Int_t imat, const char *name, Float_t *a, |
e2afb3b6 | 216 | Float_t *z, Float_t dens, Int_t nlmat, |
217 | Float_t *wmat) const | |
8494b010 | 218 | { |
219 | // | |
220 | // Defines mixture or compound imat as composed by | |
221 | // nlmat materials defined by arrays a, z and wmat | |
222 | // | |
223 | // If nlmat > 0 wmat contains the proportion by | |
224 | // weights of each basic material in the mixture | |
225 | // | |
226 | // If nlmat < 0 wmat contains the number of atoms | |
227 | // of eack kind in the molecule of the compound | |
228 | // In this case, wmat is changed on output to the relative weigths. | |
229 | // | |
230 | // imat the material index will be stored in (*fIdmate)[imat] | |
231 | // name material name | |
232 | // a array of atomic masses | |
233 | // z array of atomic numbers | |
234 | // dens density | |
235 | // nlmat number of components | |
236 | // wmat array of concentrations | |
237 | // | |
238 | Int_t kmat; | |
4a9de4af | 239 | //Build the string uniquename as "DET_mixturename" |
240 | TString uniquename = GetName(); | |
241 | uniquename.Append("_"); | |
242 | uniquename.Append(name); | |
243 | //if geometry loaded from file only fill fIdmate, else create mixture too | |
d97f1dbe | 244 | if(AliSimulation::Instance()->IsGeometryFromFile()){ |
4a9de4af | 245 | TGeoMaterial *mat = gGeoManager->GetMaterial(uniquename.Data()); |
246 | kmat = mat->GetUniqueID(); | |
247 | (*fIdmate)[imat]=kmat; | |
248 | }else{ | |
00ee7999 | 249 | if (fgDensityFactor != 1.0) |
250 | AliWarning(Form("Material density multiplied by %.2f!", fgDensityFactor)); | |
251 | gMC->Mixture(kmat, uniquename.Data(), a, z, dens * fgDensityFactor, nlmat, wmat); | |
4a9de4af | 252 | (*fIdmate)[imat]=kmat; |
253 | } | |
8494b010 | 254 | } |
b60e0f5e | 255 | |
e2afb3b6 | 256 | //_______________________________________________________________________ |
8494b010 | 257 | void AliModule::AliMedium(Int_t numed, const char *name, Int_t nmat, |
e2afb3b6 | 258 | Int_t isvol, Int_t ifield, Float_t fieldm, |
259 | Float_t tmaxfd, Float_t stemax, Float_t deemax, | |
260 | Float_t epsil, Float_t stmin, Float_t *ubuf, | |
261 | Int_t nbuf) const | |
8494b010 | 262 | { |
263 | // | |
264 | // Store the parameters of a tracking medium | |
265 | // | |
b13db077 | 266 | // numed the medium number is stored into (*fIdtmed)[numed] |
8494b010 | 267 | // name medium name |
268 | // nmat the material number is stored into (*fIdmate)[nmat] | |
269 | // isvol sensitive volume if isvol!=0 | |
270 | // ifield magnetic field flag (see below) | |
271 | // fieldm maximum magnetic field | |
272 | // tmaxfd maximum deflection angle due to magnetic field | |
273 | // stemax maximum step allowed | |
274 | // deemax maximum fractional energy loss in one step | |
275 | // epsil tracking precision in cm | |
276 | // stmin minimum step due to continuous processes | |
277 | // | |
278 | // ifield = 0 no magnetic field | |
279 | // = -1 user decision in guswim | |
280 | // = 1 tracking performed with Runge Kutta | |
281 | // = 2 tracking performed with helix | |
282 | // = 3 constant magnetic field along z | |
283 | // | |
284 | Int_t kmed; | |
4a9de4af | 285 | //Build the string uniquename as "DET_mediumname" |
286 | TString uniquename = GetName(); | |
287 | uniquename.Append("_"); | |
288 | uniquename.Append(name); | |
289 | //if geometry loaded from file only fill fIdtmed, else create medium too | |
d97f1dbe | 290 | if(AliSimulation::Instance()->IsGeometryFromFile()){ |
4a9de4af | 291 | TGeoMedium *med = gGeoManager->GetMedium(uniquename.Data()); |
292 | kmed = med->GetId(); | |
293 | (*fIdtmed)[numed]=kmed; | |
294 | }else{ | |
295 | gMC->Medium(kmed, uniquename.Data(), (*fIdmate)[nmat], isvol, ifield, | |
296 | fieldm, tmaxfd, stemax, deemax, epsil, stmin, ubuf, nbuf); | |
297 | (*fIdtmed)[numed]=kmed; | |
298 | } | |
8494b010 | 299 | } |
b60e0f5e | 300 | |
e2afb3b6 | 301 | //_______________________________________________________________________ |
8494b010 | 302 | void AliModule::AliMatrix(Int_t &nmat, Float_t theta1, Float_t phi1, |
e2afb3b6 | 303 | Float_t theta2, Float_t phi2, Float_t theta3, |
304 | Float_t phi3) const | |
8494b010 | 305 | { |
306 | // | |
307 | // Define a rotation matrix. Angles are in degrees. | |
308 | // | |
309 | // nmat on output contains the number assigned to the rotation matrix | |
310 | // theta1 polar angle for axis I | |
311 | // phi1 azimuthal angle for axis I | |
312 | // theta2 polar angle for axis II | |
313 | // phi2 azimuthal angle for axis II | |
314 | // theta3 polar angle for axis III | |
315 | // phi3 azimuthal angle for axis III | |
316 | // | |
cfce8870 | 317 | gMC->Matrix(nmat, theta1, phi1, theta2, phi2, theta3, phi3); |
8494b010 | 318 | } |
319 | ||
e2afb3b6 | 320 | //_______________________________________________________________________ |
65fb704d | 321 | Float_t AliModule::ZMin() const |
322 | { | |
323 | return -500; | |
324 | } | |
325 | ||
e2afb3b6 | 326 | //_______________________________________________________________________ |
65fb704d | 327 | Float_t AliModule::ZMax() const |
328 | { | |
329 | return 500; | |
330 | } | |
331 | ||
4787b401 | 332 | //_______________________________________________________________________ |
333 | void AliModule::AddAlignableVolumes() const | |
334 | { | |
335 | // | |
40d37d9d | 336 | if (IsActive()) |
337 | AliWarning(Form(" %s still has to implement the AddAlignableVolumes method!",GetName())); | |
4787b401 | 338 | } |
339 | ||
2cad796f | 340 | //_______________________________________________________________________ |
88cb7938 | 341 | |
df75403f | 342 | AliLoader* AliModule::MakeLoader(const char* /*topfoldername*/) |
343 | { | |
344 | return 0x0; | |
345 | } | |
8494b010 | 346 | |
2cad796f | 347 | |
88cb7938 | 348 | //_____________________________________________________________________________ |
9ac3aec9 | 349 | AliTrackReference* AliModule::AddTrackReference(Int_t label, Int_t id){ |
2cad796f | 350 | // |
351 | // add a trackrefernce to the list | |
9ac3aec9 | 352 | return (gAlice->GetMCApp()->AddTrackReference(label, id)); |
2cad796f | 353 | } |
354 | ||
88cb7938 | 355 | //_____________________________________________________________________________ |
356 | TTree* AliModule::TreeTR() | |
357 | { | |
1bb2a43c | 358 | // |
359 | // Return TR tree pointer | |
360 | // | |
6d7874d8 | 361 | if ( fRunLoader == 0x0) |
88cb7938 | 362 | { |
594d8990 | 363 | AliError("Can not get the run loader"); |
88cb7938 | 364 | return 0x0; |
365 | } | |
366 | ||
6d7874d8 | 367 | TTree* tree = fRunLoader->TreeTR(); |
88cb7938 | 368 | return tree; |
369 | } | |
0421c3d1 | 370 | |
371 | ||
372 | //_____________________________________________________________________________ | |
373 | void AliModule::Digits2Raw() | |
374 | { | |
375 | // This is a dummy version that just copies the digits file contents | |
376 | // to a raw data file. | |
377 | ||
594d8990 | 378 | AliWarning(Form("Dummy version called for %s", GetName())); |
0421c3d1 | 379 | |
362c9d61 | 380 | Int_t nDDLs = AliDAQ::NumberOfDdls(GetName()); |
0421c3d1 | 381 | |
382 | if (!GetLoader()) return; | |
383 | fstream digitsFile(GetLoader()->GetDigitsFileName(), ios::in); | |
384 | if (!digitsFile) return; | |
385 | ||
386 | digitsFile.seekg(0, ios::end); | |
387 | UInt_t size = digitsFile.tellg(); | |
3c166bf6 | 388 | UInt_t ddlSize = 4 * (size / (4*nDDLs)); |
0421c3d1 | 389 | Char_t* buffer = new Char_t[ddlSize+1]; |
390 | ||
391 | for (Int_t iDDL = 0; iDDL < nDDLs; iDDL++) { | |
7275b148 | 392 | char fileName[256]=""; |
393 | strncpy(fileName,AliDAQ::DdlFileName(GetName(),iDDL),255); | |
0421c3d1 | 394 | fstream rawFile(fileName, ios::out); |
7275b148 | 395 | if (!rawFile) break; |
0421c3d1 | 396 | |
9876c705 | 397 | AliRawDataHeaderV3 header; |
0421c3d1 | 398 | header.fSize = ddlSize + sizeof(header); |
399 | rawFile.write((char*) &header, sizeof(header)); | |
400 | ||
401 | digitsFile.read(buffer, ddlSize); | |
402 | rawFile.write(buffer, ddlSize); | |
403 | rawFile.close(); | |
404 | } | |
405 | ||
406 | digitsFile.close(); | |
407 | delete[] buffer; | |
408 | } |