Logo ROOT   6.13/01
Reference Guide
TFoamMaxwt.cxx
Go to the documentation of this file.
1 // @(#)root/foam:$Id$
2 // Author: S. Jadach <mailto:Stanislaw.jadach@ifj.edu.pl>, P.Sawicki <mailto:Pawel.Sawicki@ifj.edu.pl>
3 
4 //____________________________________________________________________________
5 //
6 // Class TFoamMaxwt
7 // =================
8 // Small auxiliary class for controlling MC weight.
9 // It provides certain measure of the "maximum weight"
10 // depending on small user-parameter "epsilon".
11 // It creates and uses 2 histograms of the TH1D class.
12 // User defines no. of bins nBin, nBin=1000 is recommended
13 // wmax defines weight range (1,wmax), it is adjusted "manually"
14 //
15 //____________________________________________________________________________
16 
17 
18 #include "Riostream.h"
19 #include "TH1.h"
20 #include "TFoamMaxwt.h"
21 
22 ClassImp(TFoamMaxwt);
23 
24 ////////////////////////////////////////////////////////////////////////////////
25 /// Constructor for streamer
26 
28 {
29  fNent = 0;
30  fnBin = 0;
31  fWtHst1 = 0;
32  fWtHst2 = 0;
33 }
34 
35 ////////////////////////////////////////////////////////////////////////////////
36 /// Principal user constructor
37 
38 TFoamMaxwt::TFoamMaxwt(Double_t wmax, Int_t nBin)
39 {
40  fNent = 0;
41  fnBin = nBin;
42  fwmax = wmax;
43  fWtHst1 = new TH1D("TFoamMaxwt_hst_Wt1","Histo of weight ",nBin,0.0,wmax);
44  fWtHst2 = new TH1D("TFoamMaxwt_hst_Wt2","Histo of weight**2",nBin,0.0,wmax);
45  fWtHst1->SetDirectory(0);// exclude from diskfile
46  fWtHst2->SetDirectory(0);// and enable deleting
47 }
48 
49 ////////////////////////////////////////////////////////////////////////////////
50 /// Explicit COPY CONSTRUCTOR (unused, so far)
51 
52 TFoamMaxwt::TFoamMaxwt(TFoamMaxwt &From): TObject(From)
53 {
54  fnBin = From.fnBin;
55  fwmax = From.fwmax;
56  fWtHst1 = From.fWtHst1;
57  fWtHst2 = From.fWtHst2;
58  Error("TFoamMaxwt","COPY CONSTRUCTOR NOT TESTED!");
59 }
60 
61 ////////////////////////////////////////////////////////////////////////////////
62 /// Destructor
63 
65 {
66  delete fWtHst1; // For this SetDirectory(0) is needed!
67  delete fWtHst2; //
68  fWtHst1=0;
69  fWtHst2=0;
70 }
71 ////////////////////////////////////////////////////////////////////////////////
72 /// Reseting weight analysis
73 
75 {
76  fNent = 0;
77  fWtHst1->Reset();
78  fWtHst2->Reset();
79 }
80 
81 ////////////////////////////////////////////////////////////////////////////////
82 /// substitution =
83 
85 {
86  if (&From == this) return *this;
87  fnBin = From.fnBin;
88  fwmax = From.fwmax;
89  fWtHst1 = From.fWtHst1;
90  fWtHst2 = From.fWtHst2;
91  return *this;
92 }
93 
94 ////////////////////////////////////////////////////////////////////////////////
95 /// Filling analyzed weight
96 
97 void TFoamMaxwt::Fill(Double_t wt)
98 {
99  fNent = fNent+1.0;
100  fWtHst1->Fill(wt,1.0);
101  fWtHst2->Fill(wt,wt);
102 }
103 
104 ////////////////////////////////////////////////////////////////////////////////
105 /// Calculates Efficiency= aveWt/wtLim for a given tolerance level epsilon<<1
106 /// To be called at the end of the MC run.
107 
108 void TFoamMaxwt::Make(Double_t eps, Double_t &MCeff)
109 {
110  Double_t wtLim,aveWt;
111  GetMCeff(eps, MCeff, wtLim);
112  aveWt = MCeff*wtLim;
113  std::cout<< "00000000000000000000000000000000000000000000000000000000000000000000000"<<std::endl;
114  std::cout<< "00 -->wtLim: No_evt ="<<fNent<<" <Wt> = "<<aveWt<<" wtLim= "<<wtLim<<std::endl;
115  std::cout<< "00 -->wtLim: For eps = "<<eps <<" EFFICIENCY <Wt>/wtLim= "<<MCeff<<std::endl;
116  std::cout<< "00000000000000000000000000000000000000000000000000000000000000000000000"<<std::endl;
117 }
118 
119 ////////////////////////////////////////////////////////////////////////////////
120 /// Calculates Efficiency= aveWt/wtLim for a given tolerance level epsilon<<1
121 /// using information stored in two histograms.
122 /// To be called at the end of the MC run.
123 
124 void TFoamMaxwt::GetMCeff(Double_t eps, Double_t &MCeff, Double_t &wtLim)
125 {
126  Int_t ib,ibX;
127  Double_t lowEdge,bin,bin1;
128  Double_t aveWt, aveWt1;
129 
130  fWtHst1->Print();
131  fWtHst2->Print();
132 
133 // Convention on bin-numbering: nb=1 for 1-st bin, underflow nb=0, overflow nb=Nb+1
134  Double_t sum = 0.0;
135  Double_t sumWt = 0.0;
136  for(ib=0;ib<=fnBin+1;ib++) {
137  sum += fWtHst1->GetBinContent(ib);
138  sumWt += fWtHst2->GetBinContent(ib);
139  }
140  if( (sum == 0.0) || (sumWt == 0.0) ) {
141  std::cout<<"TFoamMaxwt::Make: zero content of histogram !!!,sum,sumWt ="<<sum<<sumWt<<std::endl;
142  }
143  aveWt = sumWt/sum;
144  /////////////////////////////////////////////////////////////////////////////
145 
146  for( ibX=fnBin+1; ibX>0; ibX--) {
147  lowEdge = (ibX-1.0)*fwmax/fnBin;
148  sum = 0.0;
149  sumWt = 0.0;
150  for( ib=0; ib<=fnBin+1; ib++) {
151  bin = fWtHst1->GetBinContent(ib);
152  bin1 = fWtHst2->GetBinContent(ib);
153  if(ib >= ibX) bin1=lowEdge*bin;
154  sum += bin;
155  sumWt += bin1;
156  }
157  aveWt1 = sumWt/sum;
158  if( TMath::Abs(1.0-aveWt1/aveWt) > eps ) break;
159  }
160  /////////////////////////////////////////////////////////////////////////////
161 
162  if(ibX == (fnBin+1) ) {
163  wtLim = 1.0e200;
164  MCeff = 0.0;
165  std::cout<< "+++++ wtLim undefined. Higher uper limit in histogram"<<std::endl;
166  } else if( ibX == 1) {
167  wtLim = 0.0;
168  MCeff =-1.0;
169  std::cout<< "+++++ wtLim undefined. Lower uper limit or more bins "<<std::endl;
170  } else {
171  wtLim= (ibX)*fwmax/fnBin; // We over-estimate wtLim, under-estimate MCeff
172  MCeff = aveWt/wtLim;
173  }
174 }
175 ///////////////////////////////////////////////////////////////////////////////
176 // //
177 // End of Class TFoamMaxwt //
178 // //
179 ///////////////////////////////////////////////////////////////////////////////
TFoamMaxwt & operator=(const TFoamMaxwt &)
substitution =
Definition: TFoamMaxwt.cxx:84
Int_t fnBin
Definition: TFoamMaxwt.h:21
void GetMCeff(Double_t, Double_t &, Double_t &)
Calculates Efficiency= aveWt/wtLim for a given tolerance level epsilon<<1 using information stored in...
Definition: TFoamMaxwt.cxx:124
void Reset()
Reseting weight analysis.
Definition: TFoamMaxwt.cxx:74
TH1D * fWtHst2
Definition: TFoamMaxwt.h:25
void Make(Double_t, Double_t &)
Calculates Efficiency= aveWt/wtLim for a given tolerance level epsilon<<1 To be called at the end of ...
Definition: TFoamMaxwt.cxx:108
TFoamMaxwt()
Constructor for streamer.
Definition: TFoamMaxwt.cxx:27
TH1D * fWtHst1
Definition: TFoamMaxwt.h:24
virtual ~TFoamMaxwt()
Destructor.
Definition: TFoamMaxwt.cxx:64
Double_t fwmax
Definition: TFoamMaxwt.h:22
void Fill(Double_t)
Filling analyzed weight.
Definition: TFoamMaxwt.cxx:97
Double_t fNent
Definition: TFoamMaxwt.h:20