Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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/** \class TFoamMaxwt
5
6Small auxiliary class for controlling MC weight.
7It provides certain measure of the "maximum weight"
8depending on small user-parameter "epsilon".
9It creates and uses 2 histograms of the TH1D class.
10User defines no. of bins nBin, nBin=1000 is recommended
11wmax defines weight range (1,wmax), it is adjusted "manually"
12*/
13
14#include <iostream>
15#include "TH1.h"
16#include "TFoamMaxwt.h"
17
18
19////////////////////////////////////////////////////////////////////////////////
20/// Constructor for streamer
21
23{
24 fNent = 0;
25 fnBin = 0;
26 fWtHst1 = nullptr;
27 fWtHst2 = nullptr;
28}
29
30////////////////////////////////////////////////////////////////////////////////
31/// Principal user constructor
32
34{
35 fNent = 0;
36 fnBin = nBin;
37 fwmax = wmax;
38 fWtHst1 = new TH1D("TFoamMaxwt_hst_Wt1","Histo of weight ",nBin,0.0,wmax);
39 fWtHst2 = new TH1D("TFoamMaxwt_hst_Wt2","Histo of weight**2",nBin,0.0,wmax);
40 fWtHst1->SetDirectory(nullptr);// exclude from diskfile
41 fWtHst2->SetDirectory(nullptr);// and enable deleting
42}
43
44////////////////////////////////////////////////////////////////////////////////
45/// Explicit COPY CONSTRUCTOR (unused, so far)
46
48{
49 fnBin = From.fnBin;
50 fwmax = From.fwmax;
51 fWtHst1 = From.fWtHst1;
52 fWtHst2 = From.fWtHst2;
53 Error("TFoamMaxwt","COPY CONSTRUCTOR NOT TESTED!");
54}
55
56////////////////////////////////////////////////////////////////////////////////
57/// Destructor
58
60{
61 delete fWtHst1; // For this SetDirectory(0) is needed!
62 delete fWtHst2; //
63 fWtHst1=nullptr;
64 fWtHst2=nullptr;
65}
66////////////////////////////////////////////////////////////////////////////////
67/// Resetting weight analysis
68
70{
71 fNent = 0;
72 fWtHst1->Reset();
73 fWtHst2->Reset();
74}
75
76////////////////////////////////////////////////////////////////////////////////
77/// substitution =
78
80{
81 if (&From == this) return *this;
82 fnBin = From.fnBin;
83 fwmax = From.fwmax;
84 fWtHst1 = From.fWtHst1;
85 fWtHst2 = From.fWtHst2;
86 return *this;
87}
88
89////////////////////////////////////////////////////////////////////////////////
90/// Filling analyzed weight
91
93{
94 fNent = fNent+1.0;
95 fWtHst1->Fill(wt,1.0);
96 fWtHst2->Fill(wt,wt);
97}
98
99////////////////////////////////////////////////////////////////////////////////
100/// Calculates Efficiency= aveWt/wtLim for a given tolerance level epsilon<<1
101/// To be called at the end of the MC run.
102
104{
106 GetMCeff(eps, MCeff, wtLim);
107 aveWt = MCeff*wtLim;
108 std::cout<< "00000000000000000000000000000000000000000000000000000000000000000000000"<<std::endl;
109 std::cout<< "00 -->wtLim: No_evt ="<<fNent<<" <Wt> = "<<aveWt<<" wtLim= "<<wtLim<<std::endl;
110 std::cout<< "00 -->wtLim: For eps = "<<eps <<" EFFICIENCY <Wt>/wtLim= "<<MCeff<<std::endl;
111 std::cout<< "00000000000000000000000000000000000000000000000000000000000000000000000"<<std::endl;
112}
113
114////////////////////////////////////////////////////////////////////////////////
115/// Calculates Efficiency= aveWt/wtLim for a given tolerance level epsilon<<1
116/// using information stored in two histograms.
117/// To be called at the end of the MC run.
118
120{
121 Int_t ib,ibX;
124
125 fWtHst1->Print();
126 fWtHst2->Print();
127
128// Convention on bin-numbering: nb=1 for 1-st bin, underflow nb=0, overflow nb=Nb+1
129 Double_t sum = 0.0;
130 Double_t sumWt = 0.0;
131 for(ib=0;ib<=fnBin+1;ib++) {
134 }
135 if( (sum == 0.0) || (sumWt == 0.0) ) {
136 std::cout<<"TFoamMaxwt::Make: zero content of histogram !!!,sum,sumWt ="<<sum<<sumWt<<std::endl;
137 }
138 aveWt = sumWt/sum;
139 /////////////////////////////////////////////////////////////////////////////
140
141 for( ibX=fnBin+1; ibX>0; ibX--) {
142 lowEdge = (ibX-1.0)*fwmax/fnBin;
143 sum = 0.0;
144 sumWt = 0.0;
145 for( ib=0; ib<=fnBin+1; ib++) {
146 bin = fWtHst1->GetBinContent(ib);
148 if(ib >= ibX) bin1=lowEdge*bin;
149 sum += bin;
150 sumWt += bin1;
151 }
152 aveWt1 = sumWt/sum;
153 if( std::abs(1.0-aveWt1/aveWt) > eps ) break;
154 }
155 /////////////////////////////////////////////////////////////////////////////
156
157 if(ibX == (fnBin+1) ) {
158 wtLim = 1.0e200;
159 MCeff = 0.0;
160 std::cout<< "+++++ wtLim undefined. Higher upper limit in histogram"<<std::endl;
161 } else if( ibX == 1) {
162 wtLim = 0.0;
163 MCeff =-1.0;
164 std::cout<< "+++++ wtLim undefined. Lower upper limit or more bins "<<std::endl;
165 } else {
166 wtLim= (ibX)*fwmax/fnBin; // We over-estimate wtLim, under-estimate MCeff
167 MCeff = aveWt/wtLim;
168 }
169}
170
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t wmax
Small auxiliary class for controlling MC weight.
Definition TFoamMaxwt.h:12
void Make(Double_t, Double_t &)
Calculates Efficiency= aveWt/wtLim for a given tolerance level epsilon<<1 To be called at the end of ...
void Fill(Double_t)
Filling analyzed weight.
TFoamMaxwt()
Constructor for streamer.
void Reset()
Resetting weight analysis.
TH1D * fWtHst1
Histogram of the weight wt.
Definition TFoamMaxwt.h:18
Double_t fNent
No. of MC events.
Definition TFoamMaxwt.h:14
Int_t fnBin
No. of bins on the weight distribution.
Definition TFoamMaxwt.h:15
void GetMCeff(Double_t, Double_t &, Double_t &)
Calculates Efficiency= aveWt/wtLim for a given tolerance level epsilon<<1 using information stored in...
Double_t fwmax
Maximum analyzed weight.
Definition TFoamMaxwt.h:16
TH1D * fWtHst2
Histogram of wt filled with wt.
Definition TFoamMaxwt.h:19
TFoamMaxwt & operator=(const TFoamMaxwt &)
substitution =
~TFoamMaxwt() override
Destructor.
1-D histogram with a double per channel (see TH1 documentation)
Definition TH1.h:927
void Reset(Option_t *option="") override
Reset.
Definition TH1.cxx:10491
virtual void SetDirectory(TDirectory *dir)
By default, when a histogram is created, it is added to the list of histogram objects in the current ...
Definition TH1.cxx:8965
void Print(Option_t *option="") const override
Print some global quantities for this histogram.
Definition TH1.cxx:7044
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
Definition TH1.cxx:3315
virtual Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
Definition TH1.cxx:5063
Mother of all ROOT objects.
Definition TObject.h:41
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:1071
static uint64_t sum(uint64_t i)
Definition Factory.cxx:2339