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
19
20////////////////////////////////////////////////////////////////////////////////
21/// Constructor for streamer
22
24{
25 fNent = 0;
26 fnBin = 0;
27 fWtHst1 = nullptr;
28 fWtHst2 = nullptr;
29}
30
31////////////////////////////////////////////////////////////////////////////////
32/// Principal user constructor
33
35{
36 fNent = 0;
37 fnBin = nBin;
38 fwmax = wmax;
39 fWtHst1 = new TH1D("TFoamMaxwt_hst_Wt1","Histo of weight ",nBin,0.0,wmax);
40 fWtHst2 = new TH1D("TFoamMaxwt_hst_Wt2","Histo of weight**2",nBin,0.0,wmax);
41 fWtHst1->SetDirectory(nullptr);// exclude from diskfile
42 fWtHst2->SetDirectory(nullptr);// and enable deleting
43}
44
45////////////////////////////////////////////////////////////////////////////////
46/// Explicit COPY CONSTRUCTOR (unused, so far)
47
49{
50 fnBin = From.fnBin;
51 fwmax = From.fwmax;
52 fWtHst1 = From.fWtHst1;
53 fWtHst2 = From.fWtHst2;
54 Error("TFoamMaxwt","COPY CONSTRUCTOR NOT TESTED!");
55}
56
57////////////////////////////////////////////////////////////////////////////////
58/// Destructor
59
61{
62 delete fWtHst1; // For this SetDirectory(0) is needed!
63 delete fWtHst2; //
64 fWtHst1=nullptr;
65 fWtHst2=nullptr;
66}
67////////////////////////////////////////////////////////////////////////////////
68/// Resetting weight analysis
69
71{
72 fNent = 0;
73 fWtHst1->Reset();
74 fWtHst2->Reset();
75}
76
77////////////////////////////////////////////////////////////////////////////////
78/// substitution =
79
81{
82 if (&From == this) return *this;
83 fnBin = From.fnBin;
84 fwmax = From.fwmax;
85 fWtHst1 = From.fWtHst1;
86 fWtHst2 = From.fWtHst2;
87 return *this;
88}
89
90////////////////////////////////////////////////////////////////////////////////
91/// Filling analyzed weight
92
94{
95 fNent = fNent+1.0;
96 fWtHst1->Fill(wt,1.0);
97 fWtHst2->Fill(wt,wt);
98}
99
100////////////////////////////////////////////////////////////////////////////////
101/// Calculates Efficiency= aveWt/wtLim for a given tolerance level epsilon<<1
102/// To be called at the end of the MC run.
103
105{
106 Double_t wtLim,aveWt;
107 GetMCeff(eps, MCeff, wtLim);
108 aveWt = MCeff*wtLim;
109 std::cout<< "00000000000000000000000000000000000000000000000000000000000000000000000"<<std::endl;
110 std::cout<< "00 -->wtLim: No_evt ="<<fNent<<" <Wt> = "<<aveWt<<" wtLim= "<<wtLim<<std::endl;
111 std::cout<< "00 -->wtLim: For eps = "<<eps <<" EFFICIENCY <Wt>/wtLim= "<<MCeff<<std::endl;
112 std::cout<< "00000000000000000000000000000000000000000000000000000000000000000000000"<<std::endl;
113}
114
115////////////////////////////////////////////////////////////////////////////////
116/// Calculates Efficiency= aveWt/wtLim for a given tolerance level epsilon<<1
117/// using information stored in two histograms.
118/// To be called at the end of the MC run.
119
121{
122 Int_t ib,ibX;
123 Double_t lowEdge,bin,bin1;
124 Double_t aveWt, aveWt1;
125
126 fWtHst1->Print();
127 fWtHst2->Print();
128
129// Convention on bin-numbering: nb=1 for 1-st bin, underflow nb=0, overflow nb=Nb+1
130 Double_t sum = 0.0;
131 Double_t sumWt = 0.0;
132 for(ib=0;ib<=fnBin+1;ib++) {
133 sum += fWtHst1->GetBinContent(ib);
134 sumWt += fWtHst2->GetBinContent(ib);
135 }
136 if( (sum == 0.0) || (sumWt == 0.0) ) {
137 std::cout<<"TFoamMaxwt::Make: zero content of histogram !!!,sum,sumWt ="<<sum<<sumWt<<std::endl;
138 }
139 aveWt = sumWt/sum;
140 /////////////////////////////////////////////////////////////////////////////
141
142 for( ibX=fnBin+1; ibX>0; ibX--) {
143 lowEdge = (ibX-1.0)*fwmax/fnBin;
144 sum = 0.0;
145 sumWt = 0.0;
146 for( ib=0; ib<=fnBin+1; ib++) {
147 bin = fWtHst1->GetBinContent(ib);
148 bin1 = fWtHst2->GetBinContent(ib);
149 if(ib >= ibX) bin1=lowEdge*bin;
150 sum += bin;
151 sumWt += bin1;
152 }
153 aveWt1 = sumWt/sum;
154 if( TMath::Abs(1.0-aveWt1/aveWt) > eps ) break;
155 }
156 /////////////////////////////////////////////////////////////////////////////
157
158 if(ibX == (fnBin+1) ) {
159 wtLim = 1.0e200;
160 MCeff = 0.0;
161 std::cout<< "+++++ wtLim undefined. Higher upper limit in histogram"<<std::endl;
162 } else if( ibX == 1) {
163 wtLim = 0.0;
164 MCeff =-1.0;
165 std::cout<< "+++++ wtLim undefined. Lower upper limit or more bins "<<std::endl;
166 } else {
167 wtLim= (ibX)*fwmax/fnBin; // We over-estimate wtLim, under-estimate MCeff
168 MCeff = aveWt/wtLim;
169 }
170}
171
#define ClassImp(name)
Definition Rtypes.h:382
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:670
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:8937
void Print(Option_t *option="") const override
Print some global quantities for this histogram.
Definition TH1.cxx:7009
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
Definition TH1.cxx:3344
virtual Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
Definition TH1.cxx:5061
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:993
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.
Definition TMathBase.h:123
static uint64_t sum(uint64_t i)
Definition Factory.cxx:2345