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