CMS 3D CMS Logo

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

#include <LumiReWeighting.h>

Public Member Functions

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

Protected Attributes

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

Detailed Description

Definition at line 105 of file LumiReWeighting.h.

Constructor & Destructor Documentation

◆ LumiReWeighting() [1/3]

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.

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

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

◆ LumiReWeighting() [2/3]

LumiReWeighting::LumiReWeighting ( const std::vector< float > &  MC_distr,
const std::vector< float > &  Lumi_distr,
const edm::InputTag PileupSumInfoInputTag = edm::InputTag("addPileupInfo") 
)

Definition at line 84 of file LumiReWeighting.cc.

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

References EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0::cerr, gather_cfg::cout, Data_distr_, FirstWarning_, MC_distr_, SiStripSourceConfigP5_cff::NBins, OldLumiSection_, and weights_.

◆ LumiReWeighting() [3/3]

edm::LumiReWeighting::LumiReWeighting ( )
inline

Definition at line 117 of file LumiReWeighting.h.

117 {};

Member Function Documentation

◆ weight() [1/3]

double LumiReWeighting::weight ( const edm::EventBase e)

Definition at line 152 of file LumiReWeighting.cc.

152  {
153  if (FirstWarning_) {
154  e.processHistory();
155  // SetFirstFalse();
156  FirstWarning_ = false;
157  }
159  e.getByLabel(pileupSumInfoTag_, PupInfo);
160 
161  std::vector<PileupSummaryInfo>::const_iterator PVI;
162 
163  int npv = -1;
164  for (PVI = PupInfo->begin(); PVI != PupInfo->end(); ++PVI) {
165  int BX = PVI->getBunchCrossing();
166 
167  if (BX == 0) {
168  npv = PVI->getPU_NumInteractions();
169  continue;
170  }
171  }
172 
173  if (npv < 0)
174  std::cerr << " no in-time beam crossing found\n! ";
175 
176  return weight(npv);
177 }

References L1TStage2uGTEmulatorClient_cff::BX, EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0::cerr, MillePedeFileConverter_cfg::e, FirstWarning_, pileupSumInfoTag_, and weight().

◆ weight() [2/3]

double LumiReWeighting::weight ( float  npv)

Definition at line 144 of file LumiReWeighting.cc.

144  {
145  int bin = weights_->GetXaxis()->FindBin(npv);
146  return weights_->GetBinContent(bin);
147 }

References newFWLiteAna::bin, and weights_.

◆ weight() [3/3]

double LumiReWeighting::weight ( int  npv)

Definition at line 139 of file LumiReWeighting.cc.

139  {
140  int bin = weights_->GetXaxis()->FindBin(npv);
141  return weights_->GetBinContent(bin);
142 }

References newFWLiteAna::bin, and weights_.

Referenced by weight().

◆ weightOOT()

double LumiReWeighting::weightOOT ( const edm::EventBase e)

Definition at line 183 of file LumiReWeighting.cc.

183  {
184  //int Run = e.run();
185  int LumiSection = e.luminosityBlock();
186  // do some caching here, attempt to catch file boundaries
187 
188  if (LumiSection != OldLumiSection_) {
189  e.processHistory(); // keep the function call
190  OldLumiSection_ = LumiSection;
191  }
192  // find the pileup summary information
193 
195  e.getByLabel(pileupSumInfoTag_, PupInfo);
196 
197  std::vector<PileupSummaryInfo>::const_iterator PVI;
198 
199  int npv = -1;
200  int npv50ns = -1;
201 
202  for (PVI = PupInfo->begin(); PVI != PupInfo->end(); ++PVI) {
203  int BX = PVI->getBunchCrossing();
204 
205  if (BX == 0) {
206  npv = PVI->getPU_NumInteractions();
207  }
208 
209  if (BX == 1) {
210  npv50ns = PVI->getPU_NumInteractions();
211  }
212  }
213 
214  // Note: for the "uncorrelated" out-of-time pileup, reweighting is only done on the 50ns
215  // "late" bunch (BX=+1), since that is basically the only one that matters in terms of
216  // energy deposition.
217 
218  if (npv < 0) {
219  std::cerr << " no in-time beam crossing found\n! ";
220  std::cerr << " Returning event weight=0\n! ";
221  return 0.;
222  }
223  if (npv50ns < 0) {
224  std::cerr << " no out-of-time beam crossing found\n! ";
225  std::cerr << " Returning event weight=0\n! ";
226  return 0.;
227  }
228 
229  int bin = weights_->GetXaxis()->FindBin(npv);
230 
231  double inTimeWeight = weights_->GetBinContent(bin);
232 
233  double TotalWeight = 1.0;
234 
235  TotalWeight = inTimeWeight;
236 
237  return TotalWeight;
238 }

References newFWLiteAna::bin, L1TStage2uGTEmulatorClient_cff::BX, EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0::cerr, MillePedeFileConverter_cfg::e, OldLumiSection_, pileupSumInfoTag_, and weights_.

Member Data Documentation

◆ Data_distr_

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

Definition at line 140 of file LumiReWeighting.h.

Referenced by LumiReWeighting().

◆ dataFile_

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

Definition at line 134 of file LumiReWeighting.h.

Referenced by LumiReWeighting().

◆ dataFileName_

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

Definition at line 129 of file LumiReWeighting.h.

Referenced by LumiReWeighting().

◆ DataHistName_

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

Definition at line 131 of file LumiReWeighting.h.

Referenced by LumiReWeighting().

◆ FirstWarning_

bool edm::LumiReWeighting::FirstWarning_
protected

Definition at line 143 of file LumiReWeighting.h.

Referenced by LumiReWeighting(), and weight().

◆ generatedFile_

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

Definition at line 133 of file LumiReWeighting.h.

Referenced by LumiReWeighting().

◆ generatedFileName_

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

Definition at line 128 of file LumiReWeighting.h.

Referenced by LumiReWeighting().

◆ GenHistName_

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

Definition at line 130 of file LumiReWeighting.h.

Referenced by LumiReWeighting().

◆ MC_distr_

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

Definition at line 139 of file LumiReWeighting.h.

Referenced by LumiReWeighting().

◆ OldLumiSection_

int edm::LumiReWeighting::OldLumiSection_
protected

Definition at line 142 of file LumiReWeighting.h.

Referenced by LumiReWeighting(), and weightOOT().

◆ pileupSumInfoTag_

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

Definition at line 132 of file LumiReWeighting.h.

Referenced by weight(), and weightOOT().

◆ weights_

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

Definition at line 135 of file LumiReWeighting.h.

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

edm::LumiReWeighting::generatedFile_
std::shared_ptr< TFile > generatedFile_
Definition: LumiReWeighting.h:133
edm::LumiReWeighting::weight
double weight(int npv)
Definition: LumiReWeighting.cc:139
gather_cfg.cout
cout
Definition: gather_cfg.py:144
edm::LumiReWeighting::Data_distr_
std::shared_ptr< TH1 > Data_distr_
Definition: LumiReWeighting.h:140
edm::LumiReWeighting::pileupSumInfoTag_
edm::InputTag pileupSumInfoTag_
Definition: LumiReWeighting.h:132
edm::LumiReWeighting::FirstWarning_
bool FirstWarning_
Definition: LumiReWeighting.h:143
edm::Handle
Definition: AssociativeIterator.h:50
edm::LumiReWeighting::dataFileName_
std::string dataFileName_
Definition: LumiReWeighting.h:129
edm::LumiReWeighting::MC_distr_
std::shared_ptr< TH1 > MC_distr_
Definition: LumiReWeighting.h:139
edm::LumiReWeighting::OldLumiSection_
int OldLumiSection_
Definition: LumiReWeighting.h:142
edm::LumiReWeighting::generatedFileName_
std::string generatedFileName_
Definition: LumiReWeighting.h:128
SiStripSourceConfigP5_cff.NBins
NBins
Definition: SiStripSourceConfigP5_cff.py:4
newFWLiteAna.bin
bin
Definition: newFWLiteAna.py:161
edm::LumiReWeighting::DataHistName_
std::string DataHistName_
Definition: LumiReWeighting.h:131
L1TStage2uGTEmulatorClient_cff.BX
BX
Definition: L1TStage2uGTEmulatorClient_cff.py:9
edm::LumiReWeighting::weights_
std::shared_ptr< TH1 > weights_
Definition: LumiReWeighting.h:135
edm::LumiReWeighting::GenHistName_
std::string GenHistName_
Definition: LumiReWeighting.h:130
EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0.cerr
cerr
Definition: EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0.py:8
edm::LumiReWeighting::dataFile_
std::shared_ptr< TFile > dataFile_
Definition: LumiReWeighting.h:134
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37