]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRD.cxx
Clean up the dependencies
[u/mrichter/AliRoot.git] / TRD / AliTRD.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 //  Transition Radiation Detector                                            //
21 //  This class contains the basic functions for the Transition Radiation     //
22 //  Detector.                                                                //
23 //                                                                           //
24 ///////////////////////////////////////////////////////////////////////////////
25
26 #include <TVirtualMC.h>
27  
28 #include "AliMC.h"
29 #include "AliMagF.h"
30 #include "AliRun.h"
31
32 #include "AliTRD.h"
33 #include "AliTRDdigitizer.h"
34 #include "AliTRDdigitsManager.h"
35 #include "AliTRDgeometry.h"
36 #include "AliTRDhit.h"
37 #include "AliTRDrawData.h"
38 #include "AliTRDSimParam.h"
39
40 ClassImp(AliTRD)
41  
42 //_____________________________________________________________________________
43 AliTRD::AliTRD()
44   :AliDetector()
45   ,fGeometry(0)
46   ,fGasDensity(0)
47   ,fFoilDensity(0)
48   ,fGasNobleFraction(0)
49 {
50   //
51   // Default constructor
52   //
53  
54 }
55  
56 //_____________________________________________________________________________
57 AliTRD::AliTRD(const char *name, const char *title)
58   :AliDetector(name,title)
59   ,fGeometry(0)
60   ,fGasDensity(0)
61   ,fFoilDensity(0)
62   ,fGasNobleFraction(0)
63 {
64   //
65   // Standard constructor for the TRD
66   //
67
68   // Check that FRAME is there otherwise we have no place where to put TRD
69   AliModule *frame = gAlice->GetModule("FRAME");
70   if (!frame) {
71     AliError("TRD needs FRAME to be present\n");
72     exit(1);
73   } 
74
75   // Define the TRD geometry
76   if ((frame->IsVersion() == 0) ||
77       (frame->IsVersion() == 1)) {
78     fGeometry = new AliTRDgeometry();
79   }
80   else {
81     AliError("Could not find valid FRAME version\n");
82     exit(1);
83   }
84
85   // Allocate the hit array
86   fHits = new TClonesArray("AliTRDhit",405);
87   gAlice->GetMCApp()->AddHitList(fHits);
88
89 }
90
91 //_____________________________________________________________________________
92 AliTRD::~AliTRD()
93 {
94   //
95   // TRD destructor
96   //
97
98   if (fGeometry) {
99     delete fGeometry;
100     fGeometry = 0;
101   }
102
103   if (fHits) {
104     delete fHits;
105     fHits     = 0;
106   }
107
108 }
109
110 //_____________________________________________________________________________
111 void AliTRD::Hits2Digits()
112 {
113   //
114   // Create digits
115   //
116
117   AliTRDdigitizer digitizer("TRDdigitizer","TRD digitizer class");
118   AliLog::SetClassDebugLevel("TRDdigitizer",AliDebugLevel());
119
120   // Initialization
121   digitizer.InitDetector();
122     
123   if (!fLoader->TreeH()) {
124     fLoader->LoadHits("read");
125   }
126   fLoader->LoadDigits("recreate");
127
128   AliRunLoader *runLoader = fLoader->GetRunLoader(); 
129
130   for (Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++) {
131     runLoader->GetEvent(iEvent);
132     digitizer.Open(runLoader,iEvent);
133     digitizer.MakeDigits();
134     digitizer.WriteDigits();
135   }
136
137   fLoader->UnloadHits();
138   fLoader->UnloadDigits();
139
140 }
141
142 //_____________________________________________________________________________
143 void AliTRD::Hits2SDigits()
144 {
145   //
146   // Create summable digits
147   //
148
149   AliTRDdigitizer digitizer("TRDdigitizer","TRD digitizer class");
150   // For the summable digits
151   digitizer.SetSDigits(kTRUE);
152   AliLog::SetClassDebugLevel("TRDdigitizer",AliDebugLevel());
153
154   // Initialization
155   digitizer.InitDetector();
156     
157   if (!fLoader->TreeH()) {
158     fLoader->LoadHits("read");
159   }
160   fLoader->LoadSDigits("recreate");
161
162   AliRunLoader *runLoader = fLoader->GetRunLoader(); 
163
164   for (Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++) {
165     runLoader->GetEvent(iEvent);
166     digitizer.Open(runLoader,iEvent);
167     digitizer.MakeDigits();
168     digitizer.WriteDigits();
169   }
170
171   fLoader->UnloadHits();
172   fLoader->UnloadSDigits();
173   
174 }
175
176 //_____________________________________________________________________________
177 AliDigitizer *AliTRD::CreateDigitizer(AliRunDigitizer *manager) const
178 {
179   //
180   // Creates a new digitizer object
181   //
182
183   return new AliTRDdigitizer(manager);
184
185 }
186
187 //_____________________________________________________________________________
188 void AliTRD::SDigits2Digits()
189 {
190   //
191   // Create final digits from summable digits
192   //
193
194   // Create the TRD digitizer
195   AliTRDdigitizer digitizer("TRDdigitizer","TRD digitizer class");  
196   AliLog::SetClassDebugLevel("TRDdigitizer",AliDebugLevel());
197
198   // Set the parameter
199   digitizer.SetEvent(gAlice->GetEvNumber());
200
201   // Initialization
202   digitizer.InitDetector();
203
204   // Read the s-digits via digits manager
205   AliTRDdigitsManager sdigitsManager;
206  
207   AliLog::SetClassDebugLevel("TRDdigitisManager",AliDebugLevel());
208   sdigitsManager.SetSDigits(kTRUE);
209   sdigitsManager.CreateArrays();
210   
211   if (!fLoader->TreeS()) { 
212     if (fLoader->LoadSDigits("read")) {
213       return;
214     }
215   }
216   if (!fLoader->TreeS()) {
217     AliError(Form("Error while reading SDigits for event %d",gAlice->GetEvNumber()));
218     return;
219   }
220   
221   sdigitsManager.ReadDigits(fLoader->TreeS());
222
223   // Add the s-digits to the input list 
224   digitizer.AddSDigitsManager(&sdigitsManager);
225
226   // Convert the s-digits to normal digits
227   digitizer.SDigits2Digits();
228
229   // Store the digits
230   if (!fLoader->TreeD()) {
231     fLoader->MakeTree("D");
232   }
233   if (digitizer.MakeBranch(fLoader->TreeD())){
234     digitizer.WriteDigits();
235   }
236
237 }
238
239 //_____________________________________________________________________________
240 void AliTRD::Digits2Raw() 
241 {
242   //
243   // Convert digits of the current event to raw data
244   //
245
246   fLoader->LoadDigits();
247   TTree *digits = fLoader->TreeD();
248   if (!digits) {
249     AliError("No digits tree");
250     return;
251   }
252
253   AliTRDrawData rawWriter;
254   if (!rawWriter.Digits2Raw(digits)) {
255     AliError("The raw writer could not load the digits tree");
256   }
257
258   fLoader->UnloadDigits();
259
260 }
261
262 //_____________________________________________________________________________
263 void AliTRD::AddHit(Int_t track, Int_t det, Float_t *hits, Int_t q
264                   , Float_t time, Bool_t inDrift)
265 {
266   //
267   // Add a hit for the TRD
268   // 
269
270   TClonesArray &lhits = *fHits;
271   AliTRDhit *hit = new(lhits[fNhits++]) AliTRDhit(fIshunt
272                                                  ,track
273                                                  ,det
274                                                  ,hits
275                                                  ,q
276                                                  ,time);
277
278   if (inDrift) {
279     hit->SetDrift();
280   }
281   else {
282     hit->SetAmplification();
283   }
284
285   if (q < 0) {
286     hit->SetTRphoton();
287   }
288
289 }
290  
291 //_____________________________________________________________________________
292 void AliTRD::CreateGeometry()
293 {
294   //
295   // Creates the volumes for the TRD chambers
296   //
297
298   // Check that FRAME is there otherwise we have no place where to put the TRD
299   AliModule *frame = gAlice->GetModule("FRAME");
300   if (!frame) {
301     AliFatal("The TRD needs the FRAME to be defined first");
302   }
303
304   fGeometry->CreateGeometry(fIdtmed->GetArray() - 1299);
305
306 }
307
308 //_____________________________________________________________________________
309 void AliTRD::CreateMaterials()
310 {
311   //
312   // Create the materials for the TRD
313   //
314
315   Int_t   isxfld = gAlice->Field()->Integ();
316   Float_t sxmgmx = gAlice->Field()->Max();
317   
318   // For polyethilene (CH2) 
319   Float_t ape[2]    = { 12.011 ,  1.0079 };
320   Float_t zpe[2]    = {  6.0   ,  1.0    };
321   Float_t wpe[2]    = {  1.0   ,  2.0    };
322   Float_t dpe       = 0.95;
323
324   // For CO2 
325   Float_t aco[2]    = { 12.011 , 15.9994 };
326   Float_t zco[2]    = {  6.0   ,  8.0    };
327   Float_t wco[2]    = {  1.0   ,  2.0    };
328   Float_t dco       = 0.00186; // at 20C
329
330   // For water
331   Float_t awa[2]    = {  1.0079, 15.9994 };
332   Float_t zwa[2]    = {  1.0   ,  8.0    };
333   Float_t wwa[2]    = {  2.0   ,  1.0    };
334   Float_t dwa       = 1.0;
335
336   // For plexiglas (C5H8O2)
337   Float_t apg[3]    = { 12.011 ,  1.0079, 15.9994 };
338   Float_t zpg[3]    = {  6.0   ,  1.0   ,  8.0    };
339   Float_t wpg[3]    = {  5.0   ,  8.0   ,  2.0    };
340   Float_t dpg       = 1.18; 
341   
342   // For epoxy (C18H19O3)
343   Float_t aEpoxy[3] = { 15.9994,  1.0079, 12.011  }; 
344   Float_t zEpoxy[3] = {  8.0   ,  1.0   ,  6.0    }; 
345   Float_t wEpoxy[3] = {  3.0   , 19.0   , 18.0    }; 
346   Float_t dEpoxy    = 1.8 ; 
347
348   // For Araldite, low density epoxy (C18H19O3)
349   Float_t aAral[3]  = { 15.9994,  1.0079, 12.011  }; 
350   Float_t zAral[3]  = {  8.0   ,  1.0   ,  6.0    }; 
351   Float_t wAral[3]  = {  3.0   , 19.0   , 18.0    }; 
352   Float_t dAral     = 1.05; 
353
354   // For air  
355   Float_t aAir[4]   = { 12.011   , 14.0     , 15.9994  , 36.0      };
356   Float_t zAir[4]   = {  6.0     ,  7.0     ,  8.0     , 18.0      };
357   Float_t wAir[4]   = {  0.000124,  0.755267,  0.231781,  0.012827 };
358   Float_t dAir      = 1.20479e-03;
359
360   // For G10
361   Float_t aG10[4]   = {  1.0079  , 12.011   , 15.9994  , 28.086    };
362   Float_t zG10[4]   = {  1.0     ,  6.0     ,  8.0     , 14.0      };
363   Float_t wG10[4]   = {  0.15201 ,  0.10641 ,  0.49444 ,  0.24714  };
364   Float_t dG10      = 1.7;
365
366   // For Xe/CO2-gas-mixture 
367   Float_t aXeCO2[3] = { 131.29   ,  12.0107 ,  15.9994  };
368   Float_t zXeCO2[3] = {  54.0    ,   6.0    ,   8.0     };
369   Float_t wXeCO2[3] = {   8.5    ,   1.5    ,   3.0     }; 
370   // Xe-content of the Xe/CO2-mixture (85% / 15%) 
371   Float_t fxc       = 0.85;
372   Float_t dxe       = 0.00549; // at 20C
373   Float_t dgmXe     = fxc * dxe + (1.0 - fxc) * dco;
374
375   // For Ar/CO2-gas-mixture
376   Float_t aArCO2[3] = {  39.948  ,  12.0107 ,  15.9994  };
377   Float_t zArCO2[3] = {  18.0    ,   6.0    ,   8.0     };
378   Float_t wArCO2[3] = {   8.2    ,   1.8    ,   3.6     }; 
379   // Ar-content of the Ar/CO2-mixture (82% / 18%) 
380   Float_t fac       = 0.82;
381   Float_t dar       = 0.00166; // at 20C
382   Float_t dgmAr     = fac * dar + (1.0 - fac) * dco;
383   
384   // General tracking parameter
385   Float_t tmaxfd    = -10.0;
386   Float_t stemax    = -1.0e10;
387   Float_t deemax    = -0.1;
388   Float_t epsil     =  1.0e-4;
389   Float_t stmin     = -0.001;
390   
391   //////////////////////////////////////////////////////////////////////////
392   //     Define Materials 
393   //////////////////////////////////////////////////////////////////////////
394
395   AliMaterial( 1, "Al"   ,  26.98, 13.0, 2.7     ,     8.9 ,    37.2);
396   AliMaterial( 4, "Xe"   , 131.29, 54.0, dxe     ,  1546.16,     0.0);
397   AliMaterial( 5, "Cu"   ,  63.54, 29.0, 8.96    ,     1.43,    14.8);
398   AliMaterial( 6, "C"    ,  12.01,  6.0, 2.265   ,    18.8 ,    74.4);
399   AliMaterial(15, "Sn"   , 118.71, 50.0, 7.31    ,     1.21,    14.8);
400   AliMaterial(16, "Si"   ,  28.09, 14.0, 2.33    ,     9.36,    37.2);
401   AliMaterial(18, "Fe"   ,  55.85, 26.0, 7.87    ,     1.76,    14.8);
402
403   // Mixtures 
404   AliMixture(2, "Air"         , aAir,   zAir,   dAir,    4, wAir  );
405   AliMixture(3, "Polyethilene", ape,    zpe,    dpe,    -2, wpe   );
406   AliMixture(8, "CO2",          aco,    zco,    dco,    -2, wco   );
407   if      (AliTRDSimParam::Instance()->IsXenon()) {
408     AliMixture(10,"XeCO2",        aXeCO2, zXeCO2, dgmXe,  -3, wXeCO2);
409   }
410   else if (AliTRDSimParam::Instance()->IsArgon()) {
411     AliInfo("Gas mixture: Ar C02 (80/20)");
412     AliMixture(10,"ArCO2",        aArCO2, zArCO2, dgmAr,  -3, wArCO2);
413   }
414   else {
415     AliFatal("Wrong gas mixture");
416     exit(1);
417   }
418   AliMixture(12,"G10",          aG10,   zG10,   dG10,    4, wG10  );
419   AliMixture(13,"Water",        awa,    zwa,    dwa,    -2, wwa   );
420   AliMixture(14,"Plexiglas",    apg,    zpg,    dpg,    -3, wpg   );
421   AliMixture(17,"Epoxy",        aEpoxy, zEpoxy, dEpoxy, -3, wEpoxy);
422   AliMixture(19,"Araldite",     aAral,  zAral,  dAral,  -3, wAral );
423
424   //////////////////////////////////////////////////////////////////////////
425   //     Tracking Media Parameters 
426   //////////////////////////////////////////////////////////////////////////
427
428   // Al Frame 
429   AliMedium( 1,"Al Frame"   , 1,0,isxfld,sxmgmx
430               ,tmaxfd,stemax,deemax,epsil,stmin);
431   // Air 
432   AliMedium( 2,"Air"        , 2,0,isxfld,sxmgmx
433               ,tmaxfd,stemax,deemax,epsil,stmin);
434   // Wires
435   AliMedium( 3,"Wires"      , 5,0,isxfld,sxmgmx
436               ,tmaxfd,stemax,deemax,epsil,stmin);
437   // All other ROB materials (caps, etc.)
438   AliMedium( 4,"ROB Other"  , 5,0,isxfld,sxmgmx
439               ,tmaxfd,stemax,deemax,epsil,stmin);
440   // Cu pads 
441   AliMedium( 5,"Padplane"   , 5,1,isxfld,sxmgmx
442               ,tmaxfd,stemax,deemax,epsil,stmin);
443   // Fee + cables 
444   AliMedium( 6,"Readout"    , 5,0,isxfld,sxmgmx
445               ,tmaxfd,stemax,deemax,epsil,stmin);
446   // C frame 
447   AliMedium( 7,"C Frame"    , 6,0,isxfld,sxmgmx
448               ,tmaxfd,stemax,deemax,epsil,stmin);
449   // INOX of cooling bus bars
450   AliMedium( 8,"Cooling bus",18,0,isxfld,sxmgmx
451               ,tmaxfd,stemax,deemax,epsil,stmin);
452   // Gas-mixture (Xe/CO2) 
453   AliMedium( 9,"Gas-mix"    ,10,1,isxfld,sxmgmx
454               ,tmaxfd,stemax,deemax,epsil,stmin);
455   // Nomex-honeycomb
456   AliMedium(10,"Nomex"      ,12,0,isxfld,sxmgmx
457               ,tmaxfd,stemax,deemax,epsil,stmin);
458   // Araldite glue
459   AliMedium(11,"Glue"       ,19,0,isxfld,sxmgmx
460               ,tmaxfd,stemax,deemax,epsil,stmin);
461   // G10-plates
462   AliMedium(13,"G10-plates" ,12,0,isxfld,sxmgmx
463               ,tmaxfd,stemax,deemax,epsil,stmin);
464   // Cooling water
465   AliMedium(14,"Water"      ,13,0,isxfld,sxmgmx
466               ,tmaxfd,stemax,deemax,epsil,stmin);
467   // Rohacell (plexiglas) for the radiator
468   AliMedium(15,"Rohacell"   ,14,0,isxfld,sxmgmx
469               ,tmaxfd,stemax,deemax,epsil,stmin);
470   // Al layer in MCMs
471   AliMedium(16,"MCM-Al"     , 1,0,isxfld,sxmgmx
472               ,tmaxfd,stemax,deemax,epsil,stmin);
473   // Sn layer in MCMs
474   AliMedium(17,"MCM-Sn"     ,15,0,isxfld,sxmgmx
475               ,tmaxfd,stemax,deemax,epsil,stmin);
476   // Cu layer in MCMs
477   AliMedium(18,"MCM-Cu"     , 5,0,isxfld,sxmgmx
478               ,tmaxfd,stemax,deemax,epsil,stmin);
479   // G10 layer in MCMs
480   AliMedium(19,"MCM-G10"    ,12,0,isxfld,sxmgmx
481               ,tmaxfd,stemax,deemax,epsil,stmin);
482   // Si in readout chips
483   AliMedium(20,"Chip-Si"    ,16,0,isxfld,sxmgmx
484               ,tmaxfd,stemax,deemax,epsil,stmin);
485   // Epoxy in readout chips
486   AliMedium(21,"Chip-Ep"    ,17,0,isxfld,sxmgmx
487               ,tmaxfd,stemax,deemax,epsil,stmin);
488   // PE in connectors
489   AliMedium(22,"Conn-PE"    , 3,0,isxfld,sxmgmx
490               ,tmaxfd,stemax,deemax,epsil,stmin);
491   // Cu in connectors
492   AliMedium(23,"Chip-Cu"    , 5,0,isxfld,sxmgmx
493               ,tmaxfd,stemax,deemax,epsil,stmin);
494   // Al of cooling pipes
495   AliMedium(24,"Cooling"    , 1,0,isxfld,sxmgmx
496               ,tmaxfd,stemax,deemax,epsil,stmin);
497   // Cu in services
498   AliMedium(25,"Serv-Cu"    , 5,0,isxfld,sxmgmx
499               ,tmaxfd,stemax,deemax,epsil,stmin);
500
501   // Save the density values for the TRD absorbtion
502   Float_t dmy  = 1.39;
503   fFoilDensity = dmy;
504   if      (AliTRDSimParam::Instance()->IsXenon()) {
505     fGasDensity       = dgmXe;
506     fGasNobleFraction = fxc;
507   }
508   else if (AliTRDSimParam::Instance()->IsArgon()) {
509     fGasDensity       = dgmAr;
510     fGasNobleFraction = fac;
511   }
512
513 }
514  
515 //_____________________________________________________________________________
516 void AliTRD::Init()
517 {
518   //
519   // Initialize the TRD detector after the geometry has been created
520   //
521
522   AliDebug(1,"++++++++++++++++++++++++++++++++++++++++++++++");
523
524   if (fGeometry->IsVersion() != 1) {
525     AliError("Not a valid geometry");
526   }
527
528   // Special tracking options for charged particles for XeCO2
529   gMC->Gstpar((* fIdtmed)[9],"DRAY"    , 1.0);
530   gMC->Gstpar((* fIdtmed)[9],"STRA"    , 1.0); 
531   gMC->Gstpar((* fIdtmed)[9],"LOSS"    ,13.0);      // Specific energy loss
532   gMC->Gstpar((* fIdtmed)[9],"PRIMIO_E",23.53);     // 1st ionisation potential
533   gMC->Gstpar((* fIdtmed)[9],"PRIMIO_N",19.344431); // Number of primaries
534
535 }
536
537 //_____________________________________________________________________________
538 void AliTRD::ResetDigits()
539 {
540   //
541   // Reset number of digits and the digits array for this detector
542   //
543
544   fNdigits = 0;
545
546   if (fDigits) {
547     fDigits->Clear();
548   }
549
550 }
551
552 //_____________________________________________________________________________
553 void AliTRD::SetTreeAddress()
554 {
555   //
556   // Set the branch addresses for the trees.
557   //
558
559   if (fLoader->TreeH() && 
560       (fHits == 0x0)) {
561     fHits = new TClonesArray("AliTRDhit",405);
562   }
563   AliDetector::SetTreeAddress();
564
565 }
566
567 //_____________________________________________________________________________
568 Bool_t AliTRD::Raw2SDigits(AliRawReader *rawReader)
569 {
570   //
571   // Converts RAW data to SDigits
572   //
573
574   AliLoader *loader = fRunLoader->GetLoader("TRDLoader");
575   if (!loader) {
576     AliError("Can not get TRD loader from Run Loader");
577     return kFALSE;
578   }
579     
580   TTree *tree = 0;
581   tree = loader->TreeS();
582   if (!tree) {
583     loader->MakeTree("S");
584     tree = loader->TreeS();
585   }
586
587   AliTRDrawData       *rawdata        = new AliTRDrawData();
588   AliTRDdigitsManager *sdigitsManager = rawdata->Raw2Digits(rawReader);
589   if (sdigitsManager) {
590     sdigitsManager->SetSDigits(kTRUE);
591     sdigitsManager->MakeBranch(tree);
592     sdigitsManager->WriteDigits();
593     return kTRUE;
594   } 
595   else {
596     return kFALSE;
597   }
598
599 }
600
601 //_____________________________________________________________________________
602 AliLoader* AliTRD::MakeLoader(const char* topfoldername)
603 {
604  fLoader = new AliLoader(GetName(),topfoldername);
605
606  AliInfo("Adding Tracklets-loader");
607  AliDataLoader *dl = new AliDataLoader("TRD.Tracklets.root","tracklets", "tracklets");
608  fLoader->AddDataLoader(dl);
609
610  return fLoader;
611 }
612
613 //_____________________________________________________________________________
614 AliTRD &AliTRD::operator=(const AliTRD &trd)
615 {
616   //
617   // Assignment operator
618   //
619
620   if (this != &trd) {
621     ((AliTRD &) trd).Copy(*this);
622   }
623
624   return *this;
625
626 }