1 #ifndef PhysicsTools_Utilities_interface_Lumi3DReWeighting_cc 2 #define PhysicsTools_Utilities_interface_Lumi3DReWeighting_cc 23 #include "TStopwatch.h" 30 #include <boost/shared_ptr.hpp> 45 generatedFileName_( generatedFile),
46 dataFileName_ ( dataFile ),
47 GenHistName_ ( GenHistName ),
48 DataHistName_ ( DataHistName ),
49 weightFileName_ (WeightOutputFile)
54 boost::shared_ptr<TH1> Data_temp = boost::shared_ptr<TH1>( (
static_cast<TH1*
>(
dataFile_->Get(
DataHistName_.c_str() )->Clone() )) );
56 boost::shared_ptr<TH1> MC_temp = boost::shared_ptr<TH1>( (
static_cast<TH1*
>(
generatedFile_->Get(
GenHistName_.c_str() )->Clone() )) );
66 Data_distr_->Scale( 1.0/ Data_distr_->Integral() );
67 MC_distr_->Scale( 1.0/ MC_distr_->Integral() );
80 Int_t NMCBins = MC_distr.size();
82 MC_distr_ = boost::shared_ptr<TH1> (
new TH1F(
"MC_distr",
"MC dist",NMCBins,0.,
float(NMCBins)) );
84 Int_t NDBins = Lumi_distr.size();
86 Data_distr_ = boost::shared_ptr<TH1> (
new TH1F(
"Data_distr",
"Data dist",NDBins,0.,
float(NDBins)) );
88 for(
int ibin = 1; ibin<NMCBins+1; ++ibin ) {
89 MC_distr_->SetBinContent(ibin,MC_distr[ibin-1]);
92 for(
int ibin = 1; ibin<NDBins+1; ++ibin ) {
93 Data_distr_->SetBinContent(ibin, Lumi_distr[ibin-1]);
99 if(fabs(1.0 - deltaH) > 0.001 ) {
103 if(fabs(1.0 - deltaMC) > 0.001 ) {
114 int npm1 =
min(pv1,49);
115 int np0 =
min(pv2,49);
116 int npp1 =
min(pv3,49);
133 std::vector<PileupSummaryInfo>::const_iterator PVI;
139 for(PVI = PupInfo->begin(); PVI != PupInfo->end(); ++PVI) {
141 int BX = PVI->getBunchCrossing();
144 npm1 = PVI->getPU_NumInteractions();
147 np0 = PVI->getPU_NumInteractions();
150 npp1 = PVI->getPU_NumInteractions();
179 boost::shared_ptr<TH1> Data_temp = boost::shared_ptr<TH1>( (
static_cast<TH1*
>(
dataFile_->Get(
DataHistName_.c_str() )->Clone() )) );
181 boost::shared_ptr<TH1> MC_temp = boost::shared_ptr<TH1>( (
static_cast<TH1*
>(
generatedFile_->Get(
GenHistName_.c_str() )->Clone() )) );
191 Data_distr_->Scale( 1.0/ Data_distr_->Integral() );
192 MC_distr_->Scale( 1.0/ MC_distr_->Integral() );
201 TH3D* WHist =
new TH3D(
"WHist",
"3D weights",50,0.,50.,50,0.,50.,50,0.,50. );
202 TH3D* DHist =
new TH3D(
"DHist",
"3D weights",50,0.,50.,50,0.,50.,50,0.,50. );
203 TH3D* MHist =
new TH3D(
"MHist",
"3D weights",50,0.,50.,50,0.,50.,50,0.,50. );
208 std::cout <<
" MC and Data distributions are not initialized! You must call the Lumi3DReWeighting constructor. " << std::endl;
214 double MC_ints[50][50][50];
215 double Data_ints[50][50][50];
217 for (
int i=0;
i<50;
i++) {
218 for(
int j=0; j<50; j++) {
219 for(
int k=0;
k<50;
k++) {
220 MC_ints[
i][j][
k] = 0.;
221 Data_ints[
i][j][
k] = 0.;
233 for (
int i = 1;
i<50; ++
i) {
241 double probi, probj, probk;
249 for (
int jbin=1;jbin<NMCbin+1;jbin++) {
251 xweight =
MC_distr_->GetBinContent(jbin);
261 throw cms::Exception(
"BadInputValue") <<
" Your histogram generates MC luminosity values less than zero!" 262 <<
" Please Check. Terminating." << std::endl;
270 Expval =
exp(-1.*mean);
275 for (
int i = 1;
i<50; ++
i) {
282 for (
int i=0;
i<50;
i++) {
283 probi = PowerSer[
i]/factorial[
i]*Expval;
284 for(
int j=0; j<50; j++) {
285 probj = PowerSer[j]/factorial[j]*Expval;
286 for(
int k=0;
k<50;
k++) {
287 probk = PowerSer[
k]/factorial[
k]*Expval;
289 MC_ints[
i][j][
k] = MC_ints[
i][j][
k]+probi*probj*probk*xweight;
298 for (
int jbin=1;jbin<NDatabin+1;jbin++) {
299 mean = (
Data_distr_->GetBinCenter(jbin))*ScaleFactor;
305 throw cms::Exception(
"BadInputValue") <<
" Your histogram generates Data luminosity values less than zero!" 306 <<
" Please Check. Terminating." << std::endl;
313 Expval =
exp(-1.*mean);
318 for (
int i = 1;
i<50; ++
i) {
325 for (
int i=0;
i<50;
i++) {
326 probi = PowerSer[
i]/factorial[
i]*Expval;
327 for(
int j=0; j<50; j++) {
328 probj = PowerSer[j]/factorial[j]*Expval;
329 for(
int k=0;
k<50;
k++) {
330 probk = PowerSer[
k]/factorial[
k]*Expval;
332 Data_ints[
i][j][
k] = Data_ints[
i][j][
k]+probi*probj*probk*xweight;
340 for (
int i=0;
i<50;
i++) {
342 for(
int j=0; j<50; j++) {
343 for(
int k=0;
k<50;
k++) {
344 if( (MC_ints[
i][j][
k])>0.) {
350 WHist->SetBinContent(
i+1,j+1,k+1,
Weight3D_[
i][j][k] );
351 DHist->SetBinContent(
i+1,j+1,k+1,Data_ints[
i][j][k] );
352 MHist->SetBinContent(
i+1,j+1,k+1,MC_ints[
i][j][k] );
360 std::cout <<
" 3D Weight Matrix initialized! " << std::endl;
381 TFile *infile =
new TFile(WeightFileName.c_str());
382 TH1F *WHist = (TH1F*)infile->Get(
"WHist");
386 throw cms::Exception(
"HistogramNotFound") <<
" Could not find the histogram WHist in the file " 387 <<
"in the file " << WeightFileName <<
"." << std::endl;
390 for (
int i=0;
i<50;
i++) {
392 for(
int j=0; j<50; j++) {
393 for(
int k=0;
k<50;
k++) {
402 std::cout <<
" 3D Weight Matrix initialized! " << std::endl;
411 TFile *infileMC =
new TFile(MCWeightFileName.c_str());
412 TH3D *MHist = (TH3D*)infileMC->Get(
"MHist");
416 throw cms::Exception(
"HistogramNotFound") <<
" Could not find the histogram MHist in the file " 417 <<
"in the file " << MCWeightFileName <<
"." << std::endl;
420 TFile *infileD =
new TFile(DataWeightFileName.c_str());
421 TH3D *DHist = (TH3D*)infileD->Get(
"DHist");
425 throw cms::Exception(
"HistogramNotFound") <<
" Could not find the histogram DHist in the file " 426 <<
"in the file " << DataWeightFileName <<
"." << std::endl;
429 for (
int i=0;
i<50;
i++) {
430 for(
int j=0; j<50; j++) {
431 for(
int k=0;
k<50;
k++) {
432 Weight3D_[
i][j][
k] = DHist->GetBinContent(
i+1,j+1,
k+1)/MHist->GetBinContent(
i+1,j+1,
k+1);
437 std::cout <<
" 3D Weight Matrix initialized! " << std::endl;
double Weight3D_[50][50][50]
T x() const
Cartesian x coordinate.
std::string dataFileName_
std::string DataHistName_
EventID const & min(EventID const &lh, EventID const &rh)
base
Make Sure CMSSW is Setup ##.
double weight3D(const edm::EventBase &e)
void weight3D_set(std::string generatedFile, std::string dataFile, std::string GenHistName, std::string DataHistName, std::string WeightOutputFile)
void weight3D_init(float Scale)
boost::shared_ptr< TH1 > MC_distr_
std::string generatedFileName_
boost::shared_ptr< TFile > dataFile_
bool getByLabel(InputTag const &, Handle< T > &) const
int factorial(int n)
factorial function
boost::shared_ptr< TFile > generatedFile_
boost::shared_ptr< TH1 > Data_distr_
std::string weightFileName_