Logo ROOT   6.12/07
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 
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 
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 
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 
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 
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 
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 ///////////////////////////////////////////////////////////////////////////////
virtual void Print(Option_t *option="") const
Print some global quantities for this histogram.
Definition: TH1.cxx:6451
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
Definition: TH1.cxx:3244
static long int sum(long int i)
Definition: Factory.cxx:2173
virtual void SetDirectory(TDirectory *dir)
By default when an histogram is created, it is added to the list of histogram objects in the current ...
Definition: TH1.cxx:8194
TFoamMaxwt & operator=(const TFoamMaxwt &)
substitution =
Definition: TFoamMaxwt.cxx:84
virtual Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
Definition: TH1.cxx:4763
Int_t fnBin
Definition: TFoamMaxwt.h:21
int Int_t
Definition: RtypesCore.h:41
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
Short_t Abs(Short_t d)
Definition: TMathBase.h:108
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
virtual void Reset(Option_t *option="")
Reset.
Definition: TH1.cxx:9540
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:880
TFoamMaxwt()
Constructor for streamer.
Definition: TFoamMaxwt.cxx:27
TH1D * fWtHst1
Definition: TFoamMaxwt.h:24
#define ClassImp(name)
Definition: Rtypes.h:359
double Double_t
Definition: RtypesCore.h:55
virtual ~TFoamMaxwt()
Destructor.
Definition: TFoamMaxwt.cxx:64
Mother of all ROOT objects.
Definition: TObject.h:37
Double_t fwmax
Definition: TFoamMaxwt.h:22
THist< 1, double, THistStatContent, THistStatUncertainty > TH1D
Definition: THist.hxx:284
void Fill(Double_t)
Filling analyzed weight.
Definition: TFoamMaxwt.cxx:97
Double_t fNent
Definition: TFoamMaxwt.h:20