CMS 3D CMS Logo

List of all members | Public Member Functions | Protected Attributes
edm::LumiReWeighting Class Reference

#include <LumiReWeighting.h>

Public Member Functions

 LumiReWeighting (std::string generatedFile, std::string dataFile, std::string GenHistName="pileup", std::string DataHistName="pileup", const edm::InputTag &PileupSumInfoInputTag=edm::InputTag("addPileupInfo"))
 
 LumiReWeighting (const std::vector< float > &MC_distr, const std::vector< float > &Lumi_distr, const edm::InputTag &PileupSumInfoInputTag=edm::InputTag("addPileupInfo"))
 
 LumiReWeighting ()
 
double weight (int npv)
 
double weight (float npv)
 
double weight (const edm::EventBase &e)
 
double weightOOT (const edm::EventBase &e)
 

Protected Attributes

boost::shared_ptr< TH1 > Data_distr_
 
boost::shared_ptr< TFile > dataFile_
 
std::string dataFileName_
 
std::string DataHistName_
 
bool FirstWarning_
 
boost::shared_ptr< TFile > generatedFile_
 
std::string generatedFileName_
 
std::string GenHistName_
 
boost::shared_ptr< TH1 > MC_distr_
 
int OldLumiSection_
 
edm::InputTag pileupSumInfoTag_
 
boost::shared_ptr< TH1 > weights_
 

Detailed Description

Definition at line 220 of file LumiReWeighting.h.

Constructor & Destructor Documentation

LumiReWeighting::LumiReWeighting ( std::string  generatedFile,
std::string  dataFile,
std::string  GenHistName = "pileup",
std::string  DataHistName = "pileup",
const edm::InputTag PileupSumInfoInputTag = edm::InputTag( "addPileupInfo" ) 
)

Definition at line 39 of file LumiReWeighting.cc.

References gather_cfg::cout, Data_distr_, dataFile_, dataFileName_, DataHistName_, FirstWarning_, generatedFile_, generatedFileName_, GenHistName_, MC_distr_, OldLumiSection_, and weights_.

43  :
44  generatedFileName_( generatedFile),
45  dataFileName_ ( dataFile ),
46  GenHistName_ ( GenHistName ),
47  DataHistName_ ( DataHistName ),
48  pileupSumInfoTag_ ( PileupSumInfoInputTag )
49  {
50  generatedFile_ = boost::shared_ptr<TFile>( new TFile(generatedFileName_.c_str()) ); //MC distribution
51  dataFile_ = boost::shared_ptr<TFile>( new TFile(dataFileName_.c_str()) ); //Data distribution
52 
53  Data_distr_ = boost::shared_ptr<TH1>( (static_cast<TH1*>(dataFile_->Get( DataHistName_.c_str() )->Clone() )) );
54  MC_distr_ = boost::shared_ptr<TH1>( (static_cast<TH1*>(generatedFile_->Get( GenHistName_.c_str() )->Clone() )) );
55 
56  // MC * data/MC = data, so the weights are data/MC:
57 
58  // normalize both histograms first
59 
60  Data_distr_->Scale( 1.0/ Data_distr_->Integral() );
61  MC_distr_->Scale( 1.0/ MC_distr_->Integral() );
62 
63  weights_ = boost::shared_ptr<TH1>( static_cast<TH1*>(Data_distr_->Clone()) );
64 
65  weights_->SetName("lumiWeights");
66 
67  TH1* den = dynamic_cast<TH1*>(MC_distr_->Clone());
68 
69  //den->Scale(1.0/ den->Integral());
70 
71  weights_->Divide( den ); // so now the average weight should be 1.0
72 
73  std::cout << " Lumi/Pileup Reweighting: Computed Weights per In-Time Nint " << std::endl;
74 
75  int NBins = weights_->GetNbinsX();
76 
77  for(int ibin = 1; ibin<NBins+1; ++ibin){
78  std::cout << " " << ibin-1 << " " << weights_->GetBinContent(ibin) << std::endl;
79  }
80 
81 
82  FirstWarning_ = true;
83  OldLumiSection_ = -1;
84 }
boost::shared_ptr< TH1 > MC_distr_
boost::shared_ptr< TFile > dataFile_
edm::InputTag pileupSumInfoTag_
boost::shared_ptr< TFile > generatedFile_
boost::shared_ptr< TH1 > Data_distr_
boost::shared_ptr< TH1 > weights_
std::string generatedFileName_
LumiReWeighting::LumiReWeighting ( const std::vector< float > &  MC_distr,
const std::vector< float > &  Lumi_distr,
const edm::InputTag PileupSumInfoInputTag = edm::InputTag( "addPileupInfo" ) 
)

Definition at line 86 of file LumiReWeighting.cc.

References MessageLogger_cfi::cerr, gather_cfg::cout, Data_distr_, FirstWarning_, MC_distr_, OldLumiSection_, and weights_.

86  :
87  pileupSumInfoTag_ ( PileupSumInfoInputTag )
88  {
89  // no histograms for input: use vectors
90 
91  // now, make histograms out of them:
92 
93  // first, check they are the same size...
94 
95  if( MC_distr.size() != Lumi_distr.size() ){
96 
97  std::cerr <<"ERROR: LumiReWeighting: input vectors have different sizes. Quitting... \n";
98  return;
99 
100  }
101 
102  Int_t NBins = MC_distr.size();
103 
104  MC_distr_ = boost::shared_ptr<TH1> ( new TH1F("MC_distr","MC dist",NBins,-0.5, float(NBins)-0.5) );
105  Data_distr_ = boost::shared_ptr<TH1> ( new TH1F("Data_distr","Data dist",NBins,-0.5, float(NBins)-0.5) );
106 
107  weights_ = boost::shared_ptr<TH1> ( new TH1F("luminumer","luminumer",NBins,-0.5, float(NBins)-0.5) );
108  TH1* den = new TH1F("lumidenom","lumidenom",NBins,-0.5, float(NBins)-0.5) ;
109 
110  for(int ibin = 1; ibin<NBins+1; ++ibin ) {
111  weights_->SetBinContent(ibin, Lumi_distr[ibin-1]);
112  Data_distr_->SetBinContent(ibin, Lumi_distr[ibin-1]);
113  den->SetBinContent(ibin,MC_distr[ibin-1]);
114  MC_distr_->SetBinContent(ibin,MC_distr[ibin-1]);
115  }
116 
117  // check integrals, make sure things are normalized
118 
119  float deltaH = weights_->Integral();
120  if(fabs(1.0 - deltaH) > 0.02 ) { //*OOPS*...
121  weights_->Scale( 1.0/ weights_->Integral() );
122  Data_distr_->Scale( 1.0/ Data_distr_->Integral() );
123  }
124  float deltaMC = den->Integral();
125  if(fabs(1.0 - deltaMC) > 0.02 ) {
126  den->Scale(1.0/ den->Integral());
127  MC_distr_->Scale(1.0/ MC_distr_->Integral());
128  }
129 
130  weights_->Divide( den ); // so now the average weight should be 1.0
131 
132  std::cout << " Lumi/Pileup Reweighting: Computed Weights per In-Time Nint " << std::endl;
133 
134  for(int ibin = 1; ibin<NBins+1; ++ibin){
135  std::cout << " " << ibin-1 << " " << weights_->GetBinContent(ibin) << std::endl;
136  }
137 
138  FirstWarning_ = true;
139  OldLumiSection_ = -1;
140 }
boost::shared_ptr< TH1 > MC_distr_
edm::InputTag pileupSumInfoTag_
boost::shared_ptr< TH1 > Data_distr_
boost::shared_ptr< TH1 > weights_
edm::LumiReWeighting::LumiReWeighting ( )
inline

Definition at line 230 of file LumiReWeighting.h.

References MillePedeFileConverter_cfg::e, and mps_merge::weight.

230 { } ;

Member Function Documentation

double LumiReWeighting::weight ( int  npv)

Definition at line 142 of file LumiReWeighting.cc.

References stringResolutionProvider_cfi::bin, and weights_.

Referenced by L1Analysis::L1AnalysisEvent::Set(), and weight().

142  {
143  int bin = weights_->GetXaxis()->FindBin( npv );
144  return weights_->GetBinContent( bin );
145 }
bin
set the eta bin as selection string.
boost::shared_ptr< TH1 > weights_
double LumiReWeighting::weight ( float  npv)

Definition at line 147 of file LumiReWeighting.cc.

References stringResolutionProvider_cfi::bin, and weights_.

147  {
148  int bin = weights_->GetXaxis()->FindBin( npv );
149  return weights_->GetBinContent( bin );
150 }
bin
set the eta bin as selection string.
boost::shared_ptr< TH1 > weights_
double LumiReWeighting::weight ( const edm::EventBase e)

Definition at line 158 of file LumiReWeighting.cc.

References rpcdqm::BX, MessageLogger_cfi::cerr, FirstWarning_, edm::EventBase::getByLabel(), pileupSumInfoTag_, edm::EventBase::processHistory(), and weight().

158  {
159 
160  if(FirstWarning_) {
161  e.processHistory();
162  // SetFirstFalse();
163  FirstWarning_ = false;
164  }
166  e.getByLabel(pileupSumInfoTag_, PupInfo);
167 
168  std::vector<PileupSummaryInfo>::const_iterator PVI;
169 
170  int npv = -1;
171  for(PVI = PupInfo->begin(); PVI != PupInfo->end(); ++PVI) {
172 
173  int BX = PVI->getBunchCrossing();
174 
175  if(BX == 0) {
176  npv = PVI->getPU_NumInteractions();
177  continue;
178  }
179 
180  }
181 
182  if(npv < 0) std::cerr << " no in-time beam crossing found\n! " ;
183 
184  return weight(npv);
185 
186 }
virtual ProcessHistory const & processHistory() const =0
double weight(int npv)
edm::InputTag pileupSumInfoTag_
bool getByLabel(InputTag const &, Handle< T > &) const
Definition: EventBase.h:92
double LumiReWeighting::weightOOT ( const edm::EventBase e)

Definition at line 192 of file LumiReWeighting.cc.

References stringResolutionProvider_cfi::bin, rpcdqm::BX, MessageLogger_cfi::cerr, edm::EventBase::getByLabel(), edm::EventBase::luminosityBlock(), OldLumiSection_, pileupSumInfoTag_, edm::EventBase::processHistory(), and weights_.

192  {
193 
194 
195  //int Run = e.run();
196  int LumiSection = e.luminosityBlock();
197  // do some caching here, attempt to catch file boundaries
198 
199  if(LumiSection != OldLumiSection_){
200  e.processHistory(); // keep the function call
201  OldLumiSection_ = LumiSection;
202  }
203  // find the pileup summary information
204 
206  e.getByLabel(pileupSumInfoTag_, PupInfo);
207 
208  std::vector<PileupSummaryInfo>::const_iterator PVI;
209 
210  int npv = -1;
211  int npv50ns = -1;
212 
213  for(PVI = PupInfo->begin(); PVI != PupInfo->end(); ++PVI) {
214 
215  int BX = PVI->getBunchCrossing();
216 
217  if(BX == 0) {
218  npv = PVI->getPU_NumInteractions();
219  }
220 
221  if(BX == 1) {
222  npv50ns = PVI->getPU_NumInteractions();
223  }
224 
225  }
226 
227  // Note: for the "uncorrelated" out-of-time pileup, reweighting is only done on the 50ns
228  // "late" bunch (BX=+1), since that is basically the only one that matters in terms of
229  // energy deposition.
230 
231  if(npv < 0) {
232  std::cerr << " no in-time beam crossing found\n! " ;
233  std::cerr << " Returning event weight=0\n! ";
234  return 0.;
235  }
236  if(npv50ns < 0) {
237  std::cerr << " no out-of-time beam crossing found\n! " ;
238  std::cerr << " Returning event weight=0\n! ";
239  return 0.;
240  }
241 
242  int bin = weights_->GetXaxis()->FindBin( npv );
243 
244  double inTimeWeight = weights_->GetBinContent( bin );
245 
246  double TotalWeight = 1.0;
247 
248  TotalWeight = inTimeWeight;
249 
250  return TotalWeight;
251 
252 }
virtual ProcessHistory const & processHistory() const =0
edm::LuminosityBlockNumber_t luminosityBlock() const
Definition: EventBase.h:61
edm::InputTag pileupSumInfoTag_
bin
set the eta bin as selection string.
bool getByLabel(InputTag const &, Handle< T > &) const
Definition: EventBase.h:92
boost::shared_ptr< TH1 > weights_

Member Data Documentation

boost::shared_ptr<TH1> edm::LumiReWeighting::Data_distr_
protected

Definition at line 254 of file LumiReWeighting.h.

Referenced by LumiReWeighting().

boost::shared_ptr<TFile> edm::LumiReWeighting::dataFile_
protected

Definition at line 248 of file LumiReWeighting.h.

Referenced by LumiReWeighting().

std::string edm::LumiReWeighting::dataFileName_
protected

Definition at line 243 of file LumiReWeighting.h.

Referenced by LumiReWeighting().

std::string edm::LumiReWeighting::DataHistName_
protected

Definition at line 245 of file LumiReWeighting.h.

Referenced by LumiReWeighting().

bool edm::LumiReWeighting::FirstWarning_
protected

Definition at line 257 of file LumiReWeighting.h.

Referenced by LumiReWeighting(), and weight().

boost::shared_ptr<TFile> edm::LumiReWeighting::generatedFile_
protected

Definition at line 247 of file LumiReWeighting.h.

Referenced by LumiReWeighting().

std::string edm::LumiReWeighting::generatedFileName_
protected

Definition at line 242 of file LumiReWeighting.h.

Referenced by LumiReWeighting().

std::string edm::LumiReWeighting::GenHistName_
protected

Definition at line 244 of file LumiReWeighting.h.

Referenced by LumiReWeighting().

boost::shared_ptr<TH1> edm::LumiReWeighting::MC_distr_
protected

Definition at line 253 of file LumiReWeighting.h.

Referenced by LumiReWeighting().

int edm::LumiReWeighting::OldLumiSection_
protected

Definition at line 256 of file LumiReWeighting.h.

Referenced by LumiReWeighting(), and weightOOT().

edm::InputTag edm::LumiReWeighting::pileupSumInfoTag_
protected

Definition at line 246 of file LumiReWeighting.h.

Referenced by weight(), and weightOOT().

boost::shared_ptr<TH1> edm::LumiReWeighting::weights_
protected

Definition at line 249 of file LumiReWeighting.h.

Referenced by LumiReWeighting(), weight(), and weightOOT().