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