]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliModule.cxx
checking if the QA data object inherits from TH1 rather than isA during Checking
[u/mrichter/AliRoot.git] / 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 "AliRawDataHeader.h"
54
55 #include "AliDAQ.h"
56
57 ClassImp(AliModule)
58  
59 Float_t AliModule::fgDensityFactor = 1.0;
60  
61 //_______________________________________________________________________
62 AliModule::AliModule():
63   fIdtmed(0),
64   fIdmate(0),
65   fLoMedium(0),
66   fHiMedium(0),
67   fActive(0),
68   fEnable(1),
69   fMaxIterTrackRef(0),
70   fCurrentIterTrackRef(0),
71   fRunLoader(0)
72 {
73   //
74   // Default constructor for the AliModule class
75   //
76 }
77  
78 //_______________________________________________________________________
79 AliModule::AliModule(const char* name,const char *title):
80   TNamed(name,title),
81   fIdtmed(new TArrayI(100)),
82   fIdmate(new TArrayI(100)),
83   fLoMedium(65536),
84   fHiMedium(0),
85   fActive(0),
86   fEnable(1),
87   fMaxIterTrackRef(0),
88   fCurrentIterTrackRef(0),
89   fRunLoader(0)
90 {
91   //
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.
95   //
96   // Get the Module numeric ID
97
98   Int_t id = gAlice->GetModuleID(name);
99   if (id>=0) {
100     // Module already added !
101      AliWarning(Form("Module: %s already present at %d",name,id));
102      return;
103   }
104   //
105   // Add this Module to the list of Modules
106
107   gAlice->AddModule(this);
108
109   //PH  SetMarkerColor(3);
110   //
111   // Clear space for tracking media and material indexes
112
113   for(Int_t i=0;i<100;i++) (*fIdmate)[i]=(*fIdtmed)[i]=0;
114 }
115  
116 //_______________________________________________________________________
117 AliModule::~AliModule()
118 {
119   //
120   // Destructor
121   //
122
123   // Remove this Module from the list of Modules
124   if (gAlice) {
125     TObjArray * modules = gAlice->Modules();
126     if (modules) modules->Remove(this);
127   }
128
129   // Delete TArray objects
130   delete fIdtmed;
131   delete fIdmate;
132
133
134
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
139 {
140   //
141   // Store the parameters for a material
142   //
143   // imat        the material index will be stored in (*fIdmate)[imat]
144   // name        material name
145   // a           atomic mass
146   // z           atomic number
147   // dens        density
148   // radl        radiation length
149   // absl        absorbtion length
150   // buf         adress of an array user words
151   // nwbuf       number of user words
152   //
153   Int_t kmat;
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;
163   }else{
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;
168   }
169 }
170   
171 //_______________________________________________________________________
172 void AliModule::AliGetMaterial(Int_t imat, char* name, Float_t &a, 
173                                Float_t &z, Float_t &dens, Float_t &radl,
174                                Float_t &absl) const
175 {
176   //
177   // Store the parameters for a material
178   //
179   // imat        the material index will be stored in (*fIdmate)[imat]
180   // name        material name
181   // a           atomic mass
182   // z           atomic number
183   // dens        density
184   // radl        radiation length
185   // absl        absorbtion length
186   // buf         adress of an array user words
187   // nwbuf       number of user words
188   //
189
190   Float_t buf[10];
191   Int_t nwbuf, kmat;
192   kmat=(*fIdmate)[imat];
193   gMC->Gfmate(kmat, name, a, z, dens, radl, absl, buf, nwbuf);
194 }
195   
196
197 //_______________________________________________________________________
198 void AliModule::AliMixture(Int_t imat, const char *name, Float_t *a,
199                            Float_t *z, Float_t dens, Int_t nlmat,
200                            Float_t *wmat) const
201
202   //
203   // Defines mixture or compound imat as composed by 
204   // nlmat materials defined by arrays a, z and wmat
205   // 
206   // If nlmat > 0 wmat contains the proportion by
207   // weights of each basic material in the mixture  
208   // 
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.
212   //
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
217   // dens        density
218   // nlmat       number of components
219   // wmat        array of concentrations
220   //
221   Int_t kmat;
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;
231   }else{
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;
236   }
237
238  
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,
244                           Int_t nbuf) const
245
246   //
247   // Store the parameters of a tracking medium
248   //
249   // numed       the medium number is stored into (*fIdtmed)[numed]
250   // name        medium name
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
260   //
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
266   //  
267   Int_t kmed;
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());
275     kmed = med->GetId();
276     (*fIdtmed)[numed]=kmed;
277   }else{
278     gMC->Medium(kmed, uniquename.Data(), (*fIdmate)[nmat], isvol, ifield,
279                 fieldm, tmaxfd, stemax, deemax, epsil, stmin, ubuf, nbuf);
280     (*fIdtmed)[numed]=kmed;
281   }
282
283  
284 //_______________________________________________________________________
285 void AliModule::AliMatrix(Int_t &nmat, Float_t theta1, Float_t phi1,
286                           Float_t theta2, Float_t phi2, Float_t theta3,
287                           Float_t phi3) const
288 {
289   // 
290   // Define a rotation matrix. Angles are in degrees.
291   //
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
299   //
300   gMC->Matrix(nmat, theta1, phi1, theta2, phi2, theta3, phi3); 
301
302
303 //_______________________________________________________________________
304 Float_t AliModule::ZMin() const
305 {
306   return -500;
307 }
308
309 //_______________________________________________________________________
310 Float_t AliModule::ZMax() const
311 {
312   return 500;
313 }
314
315 //_______________________________________________________________________
316 void AliModule::AddAlignableVolumes() const
317 {
318   // 
319   if (IsActive())
320     AliWarning(Form(" %s still has to implement the AddAlignableVolumes method!",GetName()));
321 }
322
323 //_______________________________________________________________________
324
325 AliLoader*  AliModule::MakeLoader(const char* /*topfoldername*/)
326 {
327   return 0x0;
328 }
329  
330
331 //_____________________________________________________________________________
332 AliTrackReference*  AliModule::AddTrackReference(Int_t label, Int_t id){
333   //
334   // add a trackrefernce to the list
335     return (gAlice->GetMCApp()->AddTrackReference(label, id));
336 }
337
338 //_____________________________________________________________________________
339 TTree* AliModule::TreeTR()
340 {
341   //
342   // Return TR tree pointer
343   //
344   if ( fRunLoader == 0x0)
345    {
346      AliError("Can not get the run loader");
347      return 0x0;
348    }
349
350   TTree* tree = fRunLoader->TreeTR();
351   return tree;
352 }
353
354
355 //_____________________________________________________________________________
356 void AliModule::Digits2Raw()
357 {
358 // This is a dummy version that just copies the digits file contents
359 // to a raw data file.
360
361   AliWarning(Form("Dummy version called for %s", GetName()));
362
363   Int_t nDDLs = AliDAQ::NumberOfDdls(GetName());
364
365   if (!GetLoader()) return;
366   fstream digitsFile(GetLoader()->GetDigitsFileName(), ios::in);
367   if (!digitsFile) return;
368
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];
373
374   for (Int_t iDDL = 0; iDDL < nDDLs; iDDL++) {
375     char fileName[20];
376     strcpy(fileName,AliDAQ::DdlFileName(GetName(),iDDL));
377     fstream rawFile(fileName, ios::out);
378     if (!rawFile) return;
379
380     AliRawDataHeader header;
381     header.fSize = ddlSize + sizeof(header);
382     rawFile.write((char*) &header, sizeof(header));
383
384     digitsFile.read(buffer, ddlSize);
385     rawFile.write(buffer, ddlSize);
386     rawFile.close();
387   }
388
389   digitsFile.close();
390   delete[] buffer;
391 }