//-------------------------------------------------------------------------------------------------- // Get Total Number of Events in the sample //-------------------------------------------------------------------------------------------------- Double_t getNormalizationWeight(TString filename, TString datasetName) { // Get Normalization Weight Factor //Get Number of Events in the Sample TFile *file = new TFile(filename.Data(),"READ"); if (!file) { cout << "Could not open file " << filename << endl; return 0; } //TDirectory *dir = (TDirectory*)file->FindObjectAny("AnaFwkMod"); //if (!dir) { // cout << "Could not find directory AnaFwkMod" // << " in file " << filename << endl; // delete file; // return 0; //} TH1D *hist = (TH1D*) gROOT->FindObject("hDAllEvents"); if (!hist) { cout << "Could not find histogram hDAllEvents in directory AnaFwkMod" << " in file " << filename << endl; //delete dir; delete file; return 0; } Double_t NEvents = hist->Integral(); cout << "Original events in the sample: " << NEvents << endl; //Get CrossSection mithep::SimpleTable xstab("$CMSSW_BASE/src/MitPhysics/data/xs.dat"); Double_t CrossSection = xstab.Get(datasetName.Data()); Double_t Weight = CrossSection / NEvents; // weight for data is always 1 (-1 to make a trick for fakes) if(CrossSection < 0) Weight = -1.0; // Only gg->H and qqH samples if(datasetName.Contains("-gf-") || datasetName.Contains("-vbf-")){ // Only high mass samples if(datasetName.Contains("h250") || datasetName.Contains("h300") || datasetName.Contains("h350") || datasetName.Contains("h400") || datasetName.Contains("h450") || datasetName.Contains("h500") || datasetName.Contains("h550") || datasetName.Contains("h600") || datasetName.Contains("h700") || datasetName.Contains("h800") || datasetName.Contains("h900") || datasetName.Contains("h1000")){ TH1D *histBeforeWeight = (TH1D*) gROOT->FindObject("hDHKFactor_1"); TH1D *histAfterWeight = (TH1D*) gROOT->FindObject("hDHKFactor_2"); cout << "Nevents before/after reweighting: " << histBeforeWeight->GetSumOfWeights() << " " << histAfterWeight->GetSumOfWeights() << endl; Weight = Weight * histBeforeWeight->GetSumOfWeights() / histAfterWeight->GetSumOfWeights(); } } //delete dir; delete file; return Weight; }
//-------------------------------------------------------------------------------------------------- // Get Total Number of Events in the sample //-------------------------------------------------------------------------------------------------- Double_t getNormalizationWeight(string filename, string datasetName) { // Get Normalization Weight Factor //Get Number of Events in the Sample Double_t NEvents = 1; TFile *file = new TFile(filename.c_str(),"READ"); TDirectory *dir = 0; TH1F *hist = 0; if (!file) { cout << "Could not open file " << filename << endl; } else { hist = (TH1F*)file->Get("hDAllEvents"); if (!hist) { dir = (TDirectory*)file->FindObjectAny("AnaFwkMod"); if (!dir) { cout << "Could not find directory AnaFwkMod" << " in file " << filename << endl; delete file; } else { hist = (TH1F*)dir->Get("hDAllEvents"); if (!hist) { cout << "Could not find histogram hDEvents in directory AnaFwkMod" << " in file " << filename << endl; delete dir; delete file; } } } } if (hist) { NEvents = hist->Integral(); } //Get CrossSection Double_t Weight = 1.0; if (datasetName.find("data") == string::npos) { mithep::SimpleTable xstab("/home/sixie/CMSSW_analysis/src/MitPhysics/data/xs.dat"); cerr << "Use xs table: " << "$CMSSW_BASE/src/MitPhysics/data/xs.dat" << endl; Double_t CrossSection = xstab.Get(datasetName.c_str()); Weight = CrossSection / NEvents; cerr << datasetName << " : " << CrossSection << " " << NEvents << " " << Weight << endl; } // if (dir) delete dir; // if (file) delete file; return Weight; }
//-------------------------------------------------------------------------------------------------- // Get Total Number of Events in the sample //-------------------------------------------------------------------------------------------------- Double_t getNormalizationWeight(string filename, string datasetName) { // Get Normalization Weight Factor //Get Number of Events in the Sample TFile *file = new TFile(filename.c_str(),"READ"); if (!file) { cout << "Could not open file " << filename << endl; return 0; } //TDirectory *dir = (TDirectory*)file->FindObjectAny("AnaFwkMod"); //if (!dir) { // cout << "Could not find directory AnaFwkMod" // << " in file " << filename << endl; // delete file; // return 0; //} TH1D *hist = (TH1D*) gROOT->FindObject("hDAllEvents"); if (!hist) { cout << "Could not find histogram hDAllEvents in directory AnaFwkMod" << " in file " << filename << endl; //delete dir; delete file; return 0; } Double_t NEvents = hist->Integral(); cout << "Original events in the sample: " << NEvents << endl; //Get CrossSection mithep::SimpleTable xstab("$CMSSW_BASE/src/MitPhysics/data/xs.dat"); Double_t CrossSection = xstab.Get(datasetName.c_str()); Double_t Weight = CrossSection / NEvents; // weight for data is always 1 if(CrossSection < 0) Weight = 1.0; //delete dir; delete file; return Weight; }
//-------------------------------------------------------------------------------------------------- // Get Total Number of Events in the sample //-------------------------------------------------------------------------------------------------- Double_t getNormalizationWeight(string filename, string datasetName) { // Get Normalization Weight Factor //Get Number of Events in the Sample TFile *file = new TFile(filename.c_str(),"READ"); if (!file) { cout << "Could not open file " << filename << endl; return 0; } TDirectory *dir = (TDirectory*)file->FindObjectAny("AnaFwkMod"); if (!dir) { cout << "Could not find directory AnaFwkMod" << " in file " << filename << endl; delete file; return 0; } TH1F *hist = (TH1F*)dir->Get("hDAllEvents"); if (!hist) { cout << "Could not find histogram hDAllEvents in directory AnaFwkMod" << " in file " << filename << endl; delete dir; delete file; return 0; } Double_t NEvents = hist->Integral(); //Get CrossSection mithep::SimpleTable xstab("$CMSSW_BASE/src/MitPhysics/data/xs.dat"); Double_t CrossSection = xstab.Get(datasetName.c_str()); Double_t Weight = CrossSection / NEvents; delete dir; delete file; return Weight; }