1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 ///////////////////////////////////////////////////////////////////////////////
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. //
25 // This class is also responsible for building the geometry of the //
30 <img src="picts/AliModuleClass.gif">
34 ///////////////////////////////////////////////////////////////////////////////
36 #include <TObjArray.h>
37 #include <TClonesArray.h>
40 #include <TDirectory.h>
41 #include <TVirtualMC.h>
42 #include <TGeoManager.h>
46 #include "AliConfig.h"
47 #include "AliLoader.h"
49 #include "AliModule.h"
51 #include "AliTrackReference.h"
53 #include "AliRawDataHeader.h"
59 Float_t AliModule::fgDensityFactor = 1.0;
61 //_______________________________________________________________________
62 AliModule::AliModule():
70 fCurrentIterTrackRef(0),
74 // Default constructor for the AliModule class
78 //_______________________________________________________________________
79 AliModule::AliModule(const char* name,const char *title):
81 fIdtmed(new TArrayI(100)),
82 fIdmate(new TArrayI(100)),
88 fCurrentIterTrackRef(0),
92 // Normal constructor invoked by all Modules.
93 // Create the list for Module specific histograms
94 // Add this Module to the global list of Modules in Run.
96 // Get the Module numeric ID
98 Int_t id = gAlice->GetModuleID(name);
100 // Module already added !
101 AliWarning(Form("Module: %s already present at %d",name,id));
105 // Add this Module to the list of Modules
107 gAlice->AddModule(this);
109 //PH SetMarkerColor(3);
111 // Clear space for tracking media and material indexes
113 for(Int_t i=0;i<100;i++) (*fIdmate)[i]=(*fIdtmed)[i]=0;
116 //_______________________________________________________________________
117 AliModule::~AliModule()
123 // Remove this Module from the list of Modules
125 TObjArray * modules = gAlice->Modules();
126 if (modules) modules->Remove(this);
129 // Delete TArray objects
135 //_______________________________________________________________________
136 void AliModule::AliMaterial(Int_t imat, const char* name, Float_t a,
137 Float_t z, Float_t dens, Float_t radl,
138 Float_t absl, Float_t *buf, Int_t nwbuf) const
141 // Store the parameters for a material
143 // imat the material index will be stored in (*fIdmate)[imat]
144 // name material name
148 // radl radiation length
149 // absl absorbtion length
150 // buf adress of an array user words
151 // nwbuf number of user words
154 //Build the string uniquename as "DET_materialname"
155 TString uniquename = GetName();
156 uniquename.Append("_");
157 uniquename.Append(name);
158 //if geometry loaded from file only fill fIdmate, else create material too
159 if(gAlice->IsRootGeometry()){
160 TGeoMaterial *mat = gGeoManager->GetMaterial(uniquename.Data());
161 kmat = mat->GetUniqueID();
162 (*fIdmate)[imat]=kmat;
164 if (fgDensityFactor != 1.0)
165 AliWarning(Form("Material density multiplied by %.2f!", fgDensityFactor));
166 gMC->Material(kmat, uniquename.Data(), a, z, dens * fgDensityFactor, radl, absl, buf, nwbuf);
167 (*fIdmate)[imat]=kmat;
171 //_______________________________________________________________________
172 void AliModule::AliGetMaterial(Int_t imat, char* name, Float_t &a,
173 Float_t &z, Float_t &dens, Float_t &radl,
177 // Store the parameters for a material
179 // imat the material index will be stored in (*fIdmate)[imat]
180 // name material name
184 // radl radiation length
185 // absl absorbtion length
186 // buf adress of an array user words
187 // nwbuf number of user words
192 kmat=(*fIdmate)[imat];
193 gMC->Gfmate(kmat, name, a, z, dens, radl, absl, buf, nwbuf);
197 //_______________________________________________________________________
198 void AliModule::AliMixture(Int_t imat, const char *name, Float_t *a,
199 Float_t *z, Float_t dens, Int_t nlmat,
203 // Defines mixture or compound imat as composed by
204 // nlmat materials defined by arrays a, z and wmat
206 // If nlmat > 0 wmat contains the proportion by
207 // weights of each basic material in the mixture
209 // If nlmat < 0 wmat contains the number of atoms
210 // of eack kind in the molecule of the compound
211 // In this case, wmat is changed on output to the relative weigths.
213 // imat the material index will be stored in (*fIdmate)[imat]
214 // name material name
215 // a array of atomic masses
216 // z array of atomic numbers
218 // nlmat number of components
219 // wmat array of concentrations
222 //Build the string uniquename as "DET_mixturename"
223 TString uniquename = GetName();
224 uniquename.Append("_");
225 uniquename.Append(name);
226 //if geometry loaded from file only fill fIdmate, else create mixture too
227 if(gAlice->IsRootGeometry()){
228 TGeoMaterial *mat = gGeoManager->GetMaterial(uniquename.Data());
229 kmat = mat->GetUniqueID();
230 (*fIdmate)[imat]=kmat;
232 if (fgDensityFactor != 1.0)
233 AliWarning(Form("Material density multiplied by %.2f!", fgDensityFactor));
234 gMC->Mixture(kmat, uniquename.Data(), a, z, dens * fgDensityFactor, nlmat, wmat);
235 (*fIdmate)[imat]=kmat;
239 //_______________________________________________________________________
240 void AliModule::AliMedium(Int_t numed, const char *name, Int_t nmat,
241 Int_t isvol, Int_t ifield, Float_t fieldm,
242 Float_t tmaxfd, Float_t stemax, Float_t deemax,
243 Float_t epsil, Float_t stmin, Float_t *ubuf,
247 // Store the parameters of a tracking medium
249 // numed the medium number is stored into (*fIdtmed)[numed]
251 // nmat the material number is stored into (*fIdmate)[nmat]
252 // isvol sensitive volume if isvol!=0
253 // ifield magnetic field flag (see below)
254 // fieldm maximum magnetic field
255 // tmaxfd maximum deflection angle due to magnetic field
256 // stemax maximum step allowed
257 // deemax maximum fractional energy loss in one step
258 // epsil tracking precision in cm
259 // stmin minimum step due to continuous processes
261 // ifield = 0 no magnetic field
262 // = -1 user decision in guswim
263 // = 1 tracking performed with Runge Kutta
264 // = 2 tracking performed with helix
265 // = 3 constant magnetic field along z
268 //Build the string uniquename as "DET_mediumname"
269 TString uniquename = GetName();
270 uniquename.Append("_");
271 uniquename.Append(name);
272 //if geometry loaded from file only fill fIdtmed, else create medium too
273 if(gAlice->IsRootGeometry()){
274 TGeoMedium *med = gGeoManager->GetMedium(uniquename.Data());
276 (*fIdtmed)[numed]=kmed;
278 gMC->Medium(kmed, uniquename.Data(), (*fIdmate)[nmat], isvol, ifield,
279 fieldm, tmaxfd, stemax, deemax, epsil, stmin, ubuf, nbuf);
280 (*fIdtmed)[numed]=kmed;
284 //_______________________________________________________________________
285 void AliModule::AliMatrix(Int_t &nmat, Float_t theta1, Float_t phi1,
286 Float_t theta2, Float_t phi2, Float_t theta3,
290 // Define a rotation matrix. Angles are in degrees.
292 // nmat on output contains the number assigned to the rotation matrix
293 // theta1 polar angle for axis I
294 // phi1 azimuthal angle for axis I
295 // theta2 polar angle for axis II
296 // phi2 azimuthal angle for axis II
297 // theta3 polar angle for axis III
298 // phi3 azimuthal angle for axis III
300 gMC->Matrix(nmat, theta1, phi1, theta2, phi2, theta3, phi3);
303 //_______________________________________________________________________
304 Float_t AliModule::ZMin() const
309 //_______________________________________________________________________
310 Float_t AliModule::ZMax() const
315 //_______________________________________________________________________
316 void AliModule::AddAlignableVolumes() const
320 AliWarning(Form(" %s still has to implement the AddAlignableVolumes method!",GetName()));
323 //_______________________________________________________________________
325 AliLoader* AliModule::MakeLoader(const char* /*topfoldername*/)
331 //_____________________________________________________________________________
332 AliTrackReference* AliModule::AddTrackReference(Int_t label, Int_t id){
334 // add a trackrefernce to the list
335 return (gAlice->GetMCApp()->AddTrackReference(label, id));
338 //_____________________________________________________________________________
339 TTree* AliModule::TreeTR()
342 // Return TR tree pointer
344 if ( fRunLoader == 0x0)
346 AliError("Can not get the run loader");
350 TTree* tree = fRunLoader->TreeTR();
355 //_____________________________________________________________________________
356 void AliModule::Digits2Raw()
358 // This is a dummy version that just copies the digits file contents
359 // to a raw data file.
361 AliWarning(Form("Dummy version called for %s", GetName()));
363 Int_t nDDLs = AliDAQ::NumberOfDdls(GetName());
365 if (!GetLoader()) return;
366 fstream digitsFile(GetLoader()->GetDigitsFileName(), ios::in);
367 if (!digitsFile) return;
369 digitsFile.seekg(0, ios::end);
370 UInt_t size = digitsFile.tellg();
371 UInt_t ddlSize = 4 * (size / (4*nDDLs));
372 Char_t* buffer = new Char_t[ddlSize+1];
374 for (Int_t iDDL = 0; iDDL < nDDLs; iDDL++) {
376 strcpy(fileName,AliDAQ::DdlFileName(GetName(),iDDL));
377 fstream rawFile(fileName, ios::out);
378 if (!rawFile) return;
380 AliRawDataHeader header;
381 header.fSize = ddlSize + sizeof(header);
382 rawFile.write((char*) &header, sizeof(header));
384 digitsFile.read(buffer, ddlSize);
385 rawFile.write(buffer, ddlSize);