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