Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TMixture.cxx
Go to the documentation of this file.
1 // @(#)root/g3d:$Id$
2 // Author: Rene Brun 03/10/95
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #include "TMixture.h"
13 
14 #include "TBuffer.h"
15 #include "TMath.h"
16 
17 ClassImp(TMixture);
18 
19 /** \class TMixture
20 \ingroup g3d
21 Manages a detector mixture. See class TGeometry.
22 */
23 
24 ////////////////////////////////////////////////////////////////////////////////
25 /// Mixture default constructor.
26 
27 TMixture::TMixture()
28 {
29  fAmixt = 0;
30  fZmixt = 0;
31  fWmixt = 0;
32  fNmixt = 0;
33 }
34 
35 ////////////////////////////////////////////////////////////////////////////////
36 /// Mixture normal constructor
37 ///
38 /// Defines mixture OR COMPOUND as composed by
39 /// the basic nmixt materials defined later by DefineElement.
40 ///
41 /// If nmixt > 0 then Wmixt contains the PROPORTION BY WEIGHTS
42 /// of each basic material in the mixture.
43 ///
44 /// If nmixt < 0 then Wmixt contains the number of atoms
45 /// of a given kind into the molecule of the COMPOUND
46 /// In this case, Wmixt is changed to relative weights.
47 ///
48 /// nb : the radiation length is computed according
49 /// the EGS manual slac-210 uc-32 June-78
50 /// formula 2-6-8 (37)
51 
52 TMixture::TMixture(const char *name, const char *title, Int_t nmixt)
53  :TMaterial(name,title,0,0,0)
54 {
55  if (nmixt == 0) {
56  fAmixt = 0;
57  fZmixt = 0;
58  fWmixt = 0;
59  fNmixt = 0;
60  Error("TMixture", "mixture number is 0");
61  return;
62  }
63  Int_t nm = TMath::Abs(nmixt);
64  fNmixt = nmixt;
65  fAmixt = new Float_t[nm];
66  fZmixt = new Float_t[nm];
67  fWmixt = new Float_t[nm];
68 }
69 
70 ////////////////////////////////////////////////////////////////////////////////
71 /// Mixture default destructor.
72 
73 TMixture::~TMixture()
74 {
75  delete [] fAmixt;
76  delete [] fZmixt;
77  delete [] fWmixt;
78  fAmixt = 0;
79  fZmixt = 0;
80  fWmixt = 0;
81 }
82 
83 ////////////////////////////////////////////////////////////////////////////////
84 /// Define one mixture element.
85 
86 void TMixture::DefineElement(Int_t n, Float_t a, Float_t z, Float_t w)
87 {
88  if (n < 0 || n >= TMath::Abs(fNmixt)) return;
89  fAmixt[n] = a;
90  fZmixt[n] = z;
91  fWmixt[n] = w;
92 }
93 
94 ////////////////////////////////////////////////////////////////////////////////
95 /// Stream a class object.
96 
97 void TMixture::Streamer(TBuffer &b)
98 {
99  UInt_t R__s, R__c;
100  if (b.IsReading()) {
101  b.ReadVersion(&R__s, &R__c);
102  TMaterial::Streamer(b);
103  b >> fNmixt;
104  Int_t nmixt = TMath::Abs(fNmixt);
105  fAmixt = new Float_t[nmixt];
106  fZmixt = new Float_t[nmixt];
107  fWmixt = new Float_t[nmixt];
108  b.ReadArray(fAmixt);
109  b.ReadArray(fZmixt);
110  b.ReadArray(fWmixt);
111  b.CheckByteCount(R__s, R__c, TMixture::IsA());
112  } else {
113  R__c = b.WriteVersion(TMixture::IsA(), kTRUE);
114  TMaterial::Streamer(b);
115  b << fNmixt;
116  Int_t nmixt = TMath::Abs(fNmixt);
117  b.WriteArray(fAmixt, nmixt);
118  b.WriteArray(fZmixt, nmixt);
119  b.WriteArray(fWmixt, nmixt);
120  b.SetByteCount(R__c, kTRUE);
121  }
122 }