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