From a9a679d426de7eb04cfbe08adeff8d8081c33bfb Mon Sep 17 00:00:00 2001 From: Aruna Nayak Date: Tue, 4 Aug 2015 19:37:35 +0200 Subject: [PATCH 1/2] adding analysis macro for fullyHad channel --- DesyTauAnalyses/NTupleMaker/bin/BuildFile.xml | 14 + .../bin/analyzerTauTau_Summer15.cc | 1995 +++++++++++++++++ .../bin/preAnalyzerTauTau_Batch_Summer15.py | 21 +- .../bin/preAnalyzerTauTau_Summer15.cc | 160 +- .../bin/preAnalyzerTauTau_Summer15.py | 197 +- .../NTupleMaker/bin/readJSONFile.h | 100 + 6 files changed, 2314 insertions(+), 173 deletions(-) create mode 100644 DesyTauAnalyses/NTupleMaker/bin/analyzerTauTau_Summer15.cc create mode 100644 DesyTauAnalyses/NTupleMaker/bin/readJSONFile.h diff --git a/DesyTauAnalyses/NTupleMaker/bin/BuildFile.xml b/DesyTauAnalyses/NTupleMaker/bin/BuildFile.xml index ce9aa30..7672029 100644 --- a/DesyTauAnalyses/NTupleMaker/bin/BuildFile.xml +++ b/DesyTauAnalyses/NTupleMaker/bin/BuildFile.xml @@ -145,3 +145,17 @@ + + + + + + + + + + + + + + diff --git a/DesyTauAnalyses/NTupleMaker/bin/analyzerTauTau_Summer15.cc b/DesyTauAnalyses/NTupleMaker/bin/analyzerTauTau_Summer15.cc new file mode 100644 index 0000000..e869958 --- /dev/null +++ b/DesyTauAnalyses/NTupleMaker/bin/analyzerTauTau_Summer15.cc @@ -0,0 +1,1995 @@ +#include "FWCore/FWLite/interface/AutoLibraryLoader.h" +#include +#include +#include +#include +#include +#include + +#include "TChain.h" +#include "TEntryList.h" +#include "TMath.h" +#include "TFile.h" +#include "TTree.h" +#include "TString.h" +#include "TObjString.h" +#include "TSystem.h" +#include "TROOT.h" +#include "TPluginManager.h" +#include "TH1F.h" +#include "TH2F.h" +#include "TH1.h" +#include "TFile.h" +#include "TCanvas.h" +#include "TPad.h" +#include "TF1.h" +#include "TLegend.h" +#include "THStack.h" +#include "TCut.h" +#include "TArrayF.h" +#include "TStyle.h" + +//#include "HiggsAnalysis/CombinedLimit/interface/TH1Keys.h" +using namespace std; + +#define MSSM false +#define VERBOSE false +#define DEBUG true +//#define LOOP true +#define scaleByBinWidth false +#define DOSPLIT true +#define useZDataMC false + +typedef map mapchain; + +/////////////////////////////////////////////////////////////////////////////////////////////// +TH1F* blindHistogram(TH1F* h, float xmin, float xmax, TString name) { + + TH1F* hOut = (TH1F*)h->Clone(name); + int nBins = hOut->GetNbinsX(); + float x = 0; + + for(int i=1; iGetBinCenter(i); + if( x>xmin && xSetBinContent(i,-10); + } + + return hOut; + +} +/////////////////////////////////////////////////////////////////////////////////////////////// + +void makeHistoFromDensity(TH1* hDensity, TH1* hHistogram){ + + if(hDensity->GetNbinsX() != hHistogram->GetNbinsX()){ + cout << "makeHistoFromDensity: different binning" << endl; + return; + } + + for(int k = 1 ; k <= hDensity->GetNbinsX(); k++){ + float bink = hDensity->GetBinContent(k); + float widthk = hHistogram->GetBinWidth(k); + hDensity->SetBinContent(k, bink*widthk ); + } + hDensity->Scale(hHistogram->Integral()/hDensity->Integral()); +} + +/////////////////////////////////////////////////////////////////////////////////////////////// + +void chooseSelection(TString variable_, + TString version_, + string selection_, + TCut& tiso, + TCut& tdecaymode, + TCut& ltiso, + TCut& atiso, + TCut& antimu, + TCut& antiele, + TCut& selection, + TCut& tpt + ) +{ + cout<<"VERSION in chooseSelection :"<< version_<50."; + + else if(version_.Contains("taupt45")){ + if(version_.Contains("taupt4560")) + tpt="ptL1>45 && ptL1<60 && ptL2>45 && ptL2<60"; + else + tpt="ptL2>45"; + } + else + tpt="ptL1>45 && ptL2>45"; + + if(version_.Contains("2bTagged")) + selection =" nJets20BTagged>1"; + + // Anti-Mu discriminator // + if(version_.Contains("AntiMu3Loose")) antimu = "tightestAntiMu3WPL1>0 && tightestAntiMu3WPL2>0"; + else if(version_.Contains("AntiMu3Tight")) antimu = "tightestAntiMu3WPL1>1 && tightestAntiMu3WPL2>1"; + else if(version_.Contains("AntiMuMVALoose")) antimu = "tightestAntiMuMVAWPL1>0 && tightestAntiMuMVAWPL2>0"; + else if(version_.Contains("AntiMuMVAMedium")) antimu = "tightestAntiMuMVAWPL1>1 && tightestAntiMuMVAWPL2>1"; + else if(version_.Contains("AntiMuMVATight")) antimu = "tightestAntiMuMVAWPL1>2 && tightestAntiMuMVAWPL2>2"; + + // Anti-Ele discriminator // + if(version_.Contains("AntiEleLoose")) antiele = "tightestAntiECutWPL1 > 0 && tightestAntiECutWPL2 > 0"; + else if(version_.Contains("AntiEleMedium")) antiele = "tightestAntiECutWPL1 > 1 && tightestAntiECutWPL2 > 1"; + else if(version_.Contains("AntiEleTight")) antiele = "tightestAntiECutWPL1 > 2 && tightestAntiECutWPL2 > 2"; + else if(version_.Contains("AntiEle5VLoose")) antiele = "tightestAntiEMVA5WPL1 > 0 && tightestAntiEMVA5WPL2 > 0"; + else if(version_.Contains("AntiEle5Loose")) antiele = "tightestAntiEMVA5WPL1 > 1 && tightestAntiEMVA5WPL2 > 1"; + else if(version_.Contains("AntiEle5Medium")) antiele = "tightestAntiEMVA5WPL1 > 2 && tightestAntiEMVA5WPL2 > 2"; + else if(version_.Contains("AntiEle5Tight")) antiele = "tightestAntiEMVA5WPL1 > 3 && tightestAntiEMVA5WPL2 > 3"; + else if(version_.Contains("AntiEle5VTight")) antiele = "tightestAntiEMVA5WPL1 > 4 && tightestAntiEMVA5WPL2 > 4"; + + //TauID + if(version_.Contains("TauOldDM")) tdecaymode = "decayModeFindingOldDM1>0.5 && decayModeFindingOldDM2>0.5"; + else if(version_.Contains("TauNewDM")) tdecaymode = "decayModeFindingNewDM1>0.5 && decayModeFindingNewDM2>0.5"; + + // TauIso + // TauIso DB3Hits cut-based // + if(version_.Contains("HPSDB3H")) { + tiso = "hpsDB3HL1<1.0 && hpsDB3HL2<1.0" ; + ltiso = "hpsDB3HL1<10.0 && hpsDB3HL2<10.0" ; + atiso = "hpsDB3HL1<10.0 && hpsDB3HL2<10.0 && hpsDB3HL1>1.0 && hpsDB3HL2>1.0"; + } + else if(version_.Contains("HPSMVA3oldDMwLTLoose")) { + tiso = "tightestHPSMVA3oldDMwLTWPL1>0 && tightestHPSMVA3oldDMwLTWPL2>0" ;//Tight 3 + ltiso = "tightestHPSMVA3oldDMwLTWPL1>-1 && tightestHPSMVA3oldDMwLTWPL2>-1" ;//Loose 1 + atiso = "tightestHPSMVA3oldDMwLTWPL1>-1 && tightestHPSMVA3oldDMwLTWPL2>-1 && tightestHPSMVA3oldDMwLTWPL1<=0 && tightestHPSMVA3oldDMwLTWPL2<=0"; + } + else if(version_.Contains("HPSMVA3oldDMwLTMedium")) { + tiso = "tightestHPSMVA3oldDMwLTWPL1>1 && tightestHPSMVA3oldDMwLTWPL2>1" ;//Tight 3 + ltiso = "tightestHPSMVA3oldDMwLTWPL1>-1 && tightestHPSMVA3oldDMwLTWPL2>-1" ;//Loose 1 + atiso = "tightestHPSMVA3oldDMwLTWPL1>-1 && tightestHPSMVA3oldDMwLTWPL2>-1 && tightestHPSMVA3oldDMwLTWPL1<=1 && tightestHPSMVA3oldDMwLTWPL2<=1"; + } + else if(version_.Contains("HPSMVA3oldDMwLTTight")) { + tiso = "tightestHPSMVA3oldDMwLTWPL1>2 && tightestHPSMVA3oldDMwLTWPL2>2" ;//Tight 3 + ltiso = "tightestHPSMVA3oldDMwLTWPL1>-1 && tightestHPSMVA3oldDMwLTWPL2>-1" ;//Loose 1 + atiso = "tightestHPSMVA3oldDMwLTWPL1>-1 && tightestHPSMVA3oldDMwLTWPL2>-1 && tightestHPSMVA3oldDMwLTWPL1<=2 && tightestHPSMVA3oldDMwLTWPL2<=2"; + } + else if(variable_.Contains("hpsMVA3oldDMwLT")) { + tiso = "etaL1<999 && etaL2<999" ;//Tight 3 + ltiso = "etaL1<999 && etaL2<999" ;//Loose 1 + atiso = "etaL1<999 && etaL2<999" ;//Loose 1 + } +} +/////////////////////////////////////////////////////////////////////////////////////////////// + +void drawHistogram(TCut sbinCat, + TString type, + TString version_, + TString analysis_, + TChain* tree, + TString variable, + float& normalization, + float& normalizationError, + float scaleFactor, + TH1F* h, + TCut cut, + int verbose = 0){ + + if(DEBUG) + cout << "Start drawHistogram : " << type << " " << version_ << endl; + + // Start processing + if(tree!=0 && h!=0){ + + // HLT matching // + //TCut hltMatch("run>0"); + // GenMass cut // + TCut genMass("run>0"); + + // Reweighting + TCut weight = "run>0"; + //TCut sampleWeight = "run>0"; + //TCut weightDY = "run>0"; + //TCut weightW = "run>0"; + //TCut weightEmb= "run>0"; + + if(type.Contains("MC")) { + + weight = "(weight*mcweight)"; + + /* //to be used when weight is available + if(!type.Contains("SUSY")) + { + if(type.Contains("GGFHUp")) + weight *= "HqTWeightUp"; + else if(type.Contains("GGFHDown")) + weight *= "HqTWeightDown"; + else + weight *= "HqTWeight"; + } + else + { + if(type.Contains("GGHUp")) + weight *= "mssmHiggsPtReweightGluGlu_mhmax_tanBetaUp"; + else if(type.Contains("GGHDown")) + weight *= "mssmHiggsPtReweightGluGlu_mhmax_tanBetaDown"; + else + weight *= "mssmHiggsPtReweightGluGlu_mhmax"; + } + */ + } + /* //To be used when Embedded sample is available + else if(type.Contains("Embed")) { + genMass = "genDiTauMass>50 && HLTxMu17Mu8>0.5"; // HLTxMu17Mu8 + weightEmb = "embeddingWeight"; + + weight = "(HLTTau*HLTMu*SFTau*SFMuID*ZmmWeight*weightDecayMode)"; + } + + if(version_.Contains("DecayModeNoCorr")) + { + weight = "(HLTTau*HLTMu*SFTau*SFMuID*ZmmWeight)"; + } + } + + + if(type.Contains("TTJetsUp")) + weight *= "topPtWeightUp"; + else if(type.Contains("TTJetsDown")) + weight *= "topPtWeightDown"; + else if(type.Contains("TTJets")) + weight *= "topPtWeightNom"; + */ + // if(type.Contains("SUSY")) cout<<"weight : "<Draw(variable+">>"+TString(h->GetName()),cut*weight*sbinCat*genMass*pairIndex); + + // Scale the histogram, compute norm and err + h->Scale(scaleFactor); + normalization = h->Integral(); + normalizationError = TMath::Sqrt(h->GetEntries()) * (normalization/h->GetEntries()); + + //cout << h->GetEntries() << " entries => integral=" << normalization << endl; + if(DEBUG) cout << h->GetEntries() << " entries => integral=" << normalization << endl; + if(verbose==0) h->Reset(); + + } + else{ + cout << "ERROR : drawHistogram => null pointers to tree or histogram. Exit." << endl; + return; + } +} + +TArrayF createBins(int nBins_ = 80 , + float xMin_ = 0., + float xMax_ = 400., + int& nBins = *(new int()), + string selection_ = "inclusive", + TString variable_ = "diTauVisMass", + TString location = "/nfs/dust/cms/user/anayak/CMS/OnSLC6/CMSSW_746p6_htt/src/DesyTauAnalyses/NTupleMaker/bin/binning/" + ){ + + // input txt file with bins + ifstream is; + + TArrayF dummy(2); + dummy[0] = xMin_; dummy[1] = xMax_; + + char* c = new char[10]; + string filename = Form(location+"/bins_diTau_%s_%s.txt",variable_.Data(), selection_.c_str()); + if(MSSM) + filename = Form(location+"/bins_diTau_%s_%s_mssm.txt",variable_.Data(), selection_.c_str()); + + is.open(filename); + if(nBins_<0 && !is.good()){ + cout << "Bins file not found" << endl; + return dummy; + } + + int nBinsFromFile = 0; + while (is.good()) + { + is.getline(c,999,','); + if (is.good()){ + nBinsFromFile++; + //cout << c << endl; + } + } + + // choose the number of bins + nBins = nBins_>0 ? nBins_ : nBinsFromFile-1 ; + TArrayF bins(nBins+1); + cout << "Making histograms with " << nBins << " bins:" << endl; + + is.close(); + //is.open(Form(location+"/bins_tauTau_%s_%s.txt",variable_.Data(), selection_.c_str())); + is.open(filename); + + nBinsFromFile = 0; + + if(nBins_>0){ + for( ; nBinsFromFile <= nBins ; nBinsFromFile++){ + bins[nBinsFromFile] = xMin_ + nBinsFromFile*(xMax_-xMin_)/nBins_; + } + } + else{ + while (is.good()) + { + is.getline(c,999,','); + if (is.good() && nBinsFromFile<=nBins) { + bins[nBinsFromFile] = atof(c); + cout << bins[nBinsFromFile] << ", " ; + } + nBinsFromFile++; + } + cout << endl; + } + + return bins; + +} + +void evaluateQCD(mapchain mapAllTrees, TString version_, TString analysis_, + TH1F* qcdHisto, TH1F* ssHisto, string sign, + float& SSQCDinSignalRegionDATAIncl_, float& scaleFactorTTSSIncl, + TH1F* hExtrap, TString variable = "", + float scaleFactor=0., float TTxsectionRatio=0., float lumiCorrFactor = 0., + float ExtrapolationFactorZDataMC = 0., + float JtoTauCorrectionFactor=0., float LtoTauCorrectionFactor=0., + float OStoSSRatioQCD = 0., + TCut sbin = "", TCut sbinCat="", + TCut sbinSS="", TCut sbinSSCat="", + TCut sbinAiso = "", + bool subtractTT=true, bool subtractVV=true){ + + + + //Data SS in signal region + float Error = 0.; + float SSQCDinSignalRegionDATAIncl = 0.; + drawHistogram(sbinSSCat,"Data", version_,analysis_, mapAllTrees["Data"], variable, SSQCDinSignalRegionDATAIncl, Error, 1.0, hExtrap, sbinSS, 1); + cout<<"********* HERE IS STANDARD MEASUREMENT OF QCD IN SS *********"<Add( hExtrap, 1.0); + + //W+jets SS + float SSWJetsinSidebandRegionMCIncl = 0.; + drawHistogram(sbinSSCat, "MC",version_,analysis_, mapAllTrees["WJets"], variable, SSWJetsinSidebandRegionMCIncl, Error, scaleFactor, hExtrap, sbinSS,1); + if(ssHisto !=0) ssHisto->Add( hExtrap, 1.0); + + //TTbar SS MC + float SSTTbarinSidebandRegionMCIncl = 0.; + if(subtractTT) { + drawHistogram(sbinSSCat,"MC", version_,analysis_, mapAllTrees["TTbar"], variable, SSTTbarinSidebandRegionMCIncl, Error, scaleFactor*TTxsectionRatio*scaleFactorTTSSIncl, hExtrap, sbinSS,1); + if(ssHisto !=0) ssHisto->Add( hExtrap, -1.0); + } + + //Diboson SS MC + float SSOthersinSidebandRegionMCIncl = 0.; + if(subtractVV) { + drawHistogram(sbinSSCat,"MC", version_,analysis_, mapAllTrees["Others"], variable, SSOthersinSidebandRegionMCIncl, Error, scaleFactor, hExtrap, sbinSS,1); + if(ssHisto !=0) ssHisto->Add( hExtrap, -1.0); + } + + //DY SS MC L To Tau + float SSDYLtoTauinSidebandRegionMCIncl = 0.; + drawHistogram(sbinSSCat,"MC", version_,analysis_, mapAllTrees["DYLtoTau"], variable, SSDYLtoTauinSidebandRegionMCIncl, Error, lumiCorrFactor*scaleFactor*LtoTauCorrectionFactor, hExtrap, sbinSS,1); + if(ssHisto !=0) ssHisto->Add( hExtrap, -1.0); + + //DY SS MC Tau Tau + float SSDYtoTauinSidebandRegionMCIncl = 0.; + if(useZDataMC) + drawHistogram(sbinSSCat,"MC", version_,analysis_, mapAllTrees["DYToTauTau"], variable, SSDYtoTauinSidebandRegionMCIncl, Error, lumiCorrFactor*scaleFactor*ExtrapolationFactorZDataMC, hExtrap, sbinSS,1); + else + drawHistogram(sbinSSCat,"MC", version_,analysis_, mapAllTrees["DYToTauTau"], variable, SSDYtoTauinSidebandRegionMCIncl, Error, lumiCorrFactor*scaleFactor, hExtrap, sbinSS,1); + if(ssHisto !=0) ssHisto->Add( hExtrap, -1.0); + + //DY SS MC Jet To Tau + float SSDYJtoTauinSidebandRegionMCIncl = 0.; + drawHistogram(sbinSSCat,"MC", version_,analysis_, mapAllTrees["DYJtoTau"], variable, SSDYJtoTauinSidebandRegionMCIncl, Error, lumiCorrFactor*scaleFactor*JtoTauCorrectionFactor, hExtrap, sbinSS,1); + if(ssHisto !=0) ssHisto->Add( hExtrap, -1.0); + + cout << "Selected events in inclusive " << sign << " data " << SSQCDinSignalRegionDATAIncl << endl; + + SSQCDinSignalRegionDATAIncl -= SSWJetsinSidebandRegionMCIncl; + SSQCDinSignalRegionDATAIncl -= SSTTbarinSidebandRegionMCIncl; + SSQCDinSignalRegionDATAIncl -= SSOthersinSidebandRegionMCIncl; + SSQCDinSignalRegionDATAIncl -= SSDYLtoTauinSidebandRegionMCIncl; + SSQCDinSignalRegionDATAIncl -= SSDYJtoTauinSidebandRegionMCIncl; + SSQCDinSignalRegionDATAIncl -= SSDYtoTauinSidebandRegionMCIncl; + SSQCDinSignalRegionDATAIncl *= OStoSSRatioQCD; + //if(qcdHisto!=0) qcdHisto->Scale(OStoSSRatioQCD); + + //All non-QCD contributions subtracted from data, taken in the SR (OS, iso) --> dump + cout << "- expected from WJets " << SSWJetsinSidebandRegionMCIncl << endl; + cout << "- expected from TTbar " << SSTTbarinSidebandRegionMCIncl << endl; + cout << "- expected from Others " << SSOthersinSidebandRegionMCIncl << endl; + cout << "- expected from DY->tautau " << SSDYtoTauinSidebandRegionMCIncl << endl; + cout << "- expected from DY->ll, l->tau " << SSDYLtoTauinSidebandRegionMCIncl << endl; + cout << "- expected from DY->ll, j->tau " << SSDYJtoTauinSidebandRegionMCIncl << endl; + cout << "QCD in inclusive SS region is estimated to be " << SSQCDinSignalRegionDATAIncl/OStoSSRatioQCD << "*" << OStoSSRatioQCD + << " = " << SSQCDinSignalRegionDATAIncl << endl; + SSQCDinSignalRegionDATAIncl_ = SSQCDinSignalRegionDATAIncl; + + //Data OS anti-iso + float OSQCDinSignalRegionDATAInclaIso = 0.; + drawHistogram(sbinCat,"Data", version_,analysis_, mapAllTrees["Data"], variable, OSQCDinSignalRegionDATAInclaIso, Error, 1.0, hExtrap, sbinAiso); + if(qcdHisto!=0) qcdHisto->Add(hExtrap, 1.0); + + //W+jets OS anti-iso + float OSWJetsinSignalRegionMCInclaIso = 0.; + drawHistogram(sbinCat, "MC",version_,analysis_, mapAllTrees["WJets"], variable, OSWJetsinSignalRegionMCInclaIso, Error, 1.0, hExtrap, sbinAiso,1); + if(qcdHisto!=0) qcdHisto->Add(hExtrap, -1.0); + + //TTbar OS MC anti-iso + float OSTTbarinSignalRegionMCInclaIso = 0.; + if(subtractTT) { + drawHistogram(sbinCat,"MCTTJets", version_,analysis_, mapAllTrees["TTbar"], variable, OSTTbarinSignalRegionMCInclaIso, Error, scaleFactor*TTxsectionRatio, hExtrap, sbinAiso,1); + if(qcdHisto!=0) qcdHisto->Add(hExtrap, -1.0); + } + + //Diboson OS MC anti-iso + float OSOthersinSignalRegionMCInclaIso = 0.; + if(subtractVV) { + drawHistogram(sbinCat,"MC", version_,analysis_, mapAllTrees["Others"], variable, OSOthersinSignalRegionMCInclaIso, Error, scaleFactor, hExtrap, sbinAiso,1); + if(qcdHisto!=0) qcdHisto->Add(hExtrap, -1.0); + } + + //DY OS MC Mu To Tau + float OSDYLtoTauinSignalRegionMCInclaIso = 0.; + drawHistogram(sbinCat,"MC", version_,analysis_, mapAllTrees["DYLtoTau"], variable, OSDYLtoTauinSignalRegionMCInclaIso, Error, lumiCorrFactor*scaleFactor*LtoTauCorrectionFactor, hExtrap, sbinAiso,1); + if(qcdHisto!=0) qcdHisto->Add(hExtrap, -1.0); + + //DY OS MC Tau Tau + float OSDYtoTauinSignalRegionMCInclaIso = 0.; + if(useZDataMC) + drawHistogram(sbinCat,"MC", version_,analysis_, mapAllTrees["DYToTauTau"], variable, OSDYtoTauinSignalRegionMCInclaIso, Error, lumiCorrFactor*scaleFactor*ExtrapolationFactorZDataMC, hExtrap, sbinAiso,1); + else + drawHistogram(sbinCat,"MC", version_,analysis_, mapAllTrees["DYToTauTau"], variable, OSDYtoTauinSignalRegionMCInclaIso, Error, lumiCorrFactor*scaleFactor, hExtrap, sbinAiso,1); + if(qcdHisto!=0) qcdHisto->Add(hExtrap, -1.0); + + //DY OS MC Jet To Tau + float OSDYJtoTauinSidebandRegionMCInclaIso = 0.; + drawHistogram(sbinCat,"MC", version_,analysis_, mapAllTrees["DYJtoTau"], variable, OSDYJtoTauinSidebandRegionMCInclaIso, Error, lumiCorrFactor*scaleFactor*JtoTauCorrectionFactor, hExtrap, sbinAiso,1); + if(qcdHisto!=0) qcdHisto->Add(hExtrap, -1.0); + + if(qcdHisto!=0)qcdHisto->Scale(SSQCDinSignalRegionDATAIncl/qcdHisto->Integral()); + + //Do separately for VBF +} + + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////7 + +void plotTauTau( Int_t mH_ = 120, + Int_t useEmbedding_ = 0, + string selection_ = "inclusive", + TString analysis_ = "", + TString variable_ = "diTauVisMass", + TString XTitle_ = "Visible mass", + TString Unities_ = "GeV", + TString outputDir = "test", + Int_t nBins_ = 80, Float_t xMin_=0, Float_t xMax_=400, + Float_t magnifySgn_ = 1.0, + Int_t logy_ = 0, + Float_t maxY_ = 1.2, + TString version_ = "v1", + TString location = "" + ) +{ + + location = gSystem->pwd(); + location += "/results/"; + + cout << endl; + cout << "@@@@@@@@@@@@@@@@@@ Category = " << selection_ << endl; + cout << "@@@@@@@@@@@@@@@@@@ Variable = " << string(variable_.Data()) << endl; + cout << endl; + + ostringstream ossiTmH(""); + ossiTmH << mH_ ; + TString TmH_ = ossiTmH.str(); + + //const int nProd=3; + //const int nMasses=0; + //TString nameProd[nProd]={"GGFH","VBFH","VH"}; + ////int hMasses[nMasses]={90,95,100,105,110,115,120,125,130,135,140,145,150,155,160}; + //int hMasses[nMasses]={}; + //TString nameMasses[nMasses]; + // + //if(DEBUG) cout << "build masses string" << endl; + //for(int iM=0 ; iM Lumi = " << Lumi/1000. << " fb-1" << endl; + cout << " > DY xsection SF = " << lumiCorrFactor << endl; + cout << " > TTbar SF = " << TTxsectionRatio << endl; + cout << " > QCD OS/SS SF = " << OStoSSRatioQCD << endl; + cout << " > J->tau SF = " << JtoTauCorrectionFactor << endl; + cout << " > l->tau SF = " << LtoTauCorrectionFactor << endl; + cout << endl; + + ///////////////// change SVfit mass here /////////////////// + + string variableStr = ""; + TString variable(variableStr.c_str()); + variable = variable_; + + ////////////////////////////////////////////////////////////////////////// + ////////////////////////////////////////////////////////////////////////// + + TCanvas *c1 = new TCanvas("c1","",5,30,650,600); + c1->SetGrid(0,0); + c1->SetFillStyle(4000); + c1->SetFillColor(10); + c1->SetTicky(); + c1->SetObjectStat(0); + c1->SetLogy(logy_); + // if(variable=="dxyErrTau")c1->SetLogx(1); + + TPad* pad1 = new TPad("pad1DEta","",0.05,0.22,0.96,0.97); + TPad* pad2 = new TPad("pad2DEta","",0.05,0.02,0.96,0.20); + + pad1->SetFillColor(0); + pad2->SetFillColor(0); + pad1->Draw(); + pad2->Draw(); + + pad1->cd(); + pad1->SetLogy(logy_); + // if(variable=="dxyErrTau")pad1->SetLogx(1); + gStyle->SetOptStat(0); + gStyle->SetTitleFillColor(0); + gStyle->SetCanvasBorderMode(0); + gStyle->SetCanvasColor(0); + gStyle->SetPadBorderMode(0); + gStyle->SetPadColor(0); + gStyle->SetTitleFillColor(0); + gStyle->SetTitleBorderSize(0); + gStyle->SetTitleH(0.07); + gStyle->SetTitleFontSize(0.1); + gStyle->SetTitleStyle(0); + gStyle->SetTitleOffset(1.3,"y"); + + TLegend* leg = new TLegend(0.53,0.48,0.85,0.88,NULL,"brNDC"); + leg->SetFillStyle(0); + leg->SetBorderSize(0); + leg->SetFillColor(10); + leg->SetTextSize(0.03); + leg->SetHeader(Form("#splitline{CMS Preliminary #sqrt{s}=13 TeV}{%.2f fb^{-1} #tau_{had}#tau_{had}}", Lumi/1000. )); + + THStack* aStack = new THStack("aStack",""); + + TH1F* hSiml = new TH1F( "hSiml" ,"all" , nBins , bins.GetArray()); + TH1F* hSgn = new TH1F( "hSgn " ,"vbf+ggf" , nBins , bins.GetArray()); hSgn->SetFillColor(0); hSgn->SetLineColor(kBlue);hSgn->SetLineWidth(2);hSgn->SetLineStyle(kDashed); + TH1F* hSgn1 = new TH1F( "hSgn1" ,"vbf" , nBins , bins.GetArray()); hSgn1->SetLineWidth(2); + TH1F* hSgn2 = new TH1F( "hSgn2" ,"ggf" , nBins , bins.GetArray()); hSgn2->SetLineWidth(2); + TH1F* hSgn3 = new TH1F( "hSgn3" ,"vh" , nBins , bins.GetArray()); hSgn3->SetLineWidth(2); + TH1F* hData = new TH1F( "hData" ," " , nBins , bins.GetArray()); hData->SetMarkerStyle(20);hData->SetMarkerSize(1.2);hData->SetMarkerColor(kBlack);hData->SetLineColor(kBlack);hData->SetXTitle(XTitle_+" ("+Unities_+")");hData->SetYTitle(Form(" Events/(%.1f %s)", hData->GetBinWidth(1), Unities_.Data() ) );hData->SetTitleSize(0.04,"X");hData->SetTitleSize(0.05,"Y");hData->SetTitleOffset(0.95,"Y"); + TH1F* hZttEmb = new TH1F( "hZttEmb","Embedded" , nBins , bins.GetArray()); hZttEmb->SetFillColor(kOrange-4); + TH1F* hW = new TH1F( "hW" ,"W+jets" , nBins , bins.GetArray()); hW->SetFillColor(kRed+2); + TH1F* hEWK = new TH1F( "hEWK" ,"EWK" , nBins , bins.GetArray()); hEWK->SetFillColor(kRed+2); + TH1F* hZtt = new TH1F( "hZtt" ,"Ztautau" , nBins , bins.GetArray()); hZtt->SetFillColor(kOrange-4); + TH1F* hZll = new TH1F( "hZll" ,"Zll" , nBins , bins.GetArray()); hZll->SetFillColor(kBlue-2); + TH1F* hZj = new TH1F( "hZj" ,"Z+jets, jet to tau", nBins , bins.GetArray()); hZj->SetFillColor(kBlue-2); + TH1F* hZfakes = new TH1F( "hZfakes" ,"Z+jets, jet to tau", nBins , bins.GetArray()); hZfakes->SetFillColor(kBlue-2); + TH1F* hTTb = new TH1F( "hTTb" ,"ttbar" , nBins , bins.GetArray()); hTTb->SetFillColor(kBlue-8); + TH1F* hTTbUp = new TH1F( "hTTbUp" ,"ttbarUp" , nBins , bins.GetArray()); hTTbUp->SetFillColor(kBlue-8); + TH1F* hTTbDown = new TH1F( "hTTbDown" ,"ttbarDown" , nBins , bins.GetArray()); hTTbDown->SetFillColor(kBlue-8); + TH1F* hVV = new TH1F( "hVV" ,"Diboson" , nBins , bins.GetArray()); hVV->SetFillColor(kRed+2); + + TH1F* hSS = new TH1F( "hSS" ,"same-sign" , nBins , bins.GetArray()); hSS->SetFillColor(kMagenta-10); + TH1F* hQCD = new TH1F( "hQCD" ,"QCD" , nBins , bins.GetArray()); hQCD->SetFillColor(kMagenta-10); + TH1F* hDataAntiTauIsoQCD = new TH1F( "hDataAntiTauIsoQCD", "AntiTauIsoQCD", nBins , bins.GetArray()); hDataAntiTauIsoQCD->SetFillColor(kMagenta-10); + TH1F* hDataAntiTauIso = new TH1F( "hDataAntiTauIso", "AntiTauIso", nBins , bins.GetArray()); hDataAntiTauIso->SetFillColor(kMagenta-10); + + /* // not needed for now + //W Up/Down + TH1F* hW_TauFakeUp = new TH1F( "hW_TauFakeUp" ,"W+jets" , nBins , bins.GetArray()); hW_TauFakeUp->SetFillColor(kRed+2); + TH1F* hW_TauFakeDown = new TH1F( "hW_TauFakeDown" ,"W+jets" , nBins , bins.GetArray()); hW_TauFakeDown->SetFillColor(kRed+2); + */ + //histograms with fine binning for MSSM + TH1F* hZttEmb_fb = new TH1F( "hZttEmb_fb","Embedded" , 400, 0., 2000.); hZttEmb_fb->SetFillColor(kOrange-4); + TH1F* hW_fb = new TH1F( "hW_fb" ,"W+jets" , 400, 0., 2000.); hW_fb->SetFillColor(kRed+2); + TH1F* hZtt_fb = new TH1F( "hZtt_fb" ,"Ztautau" , 400, 0., 2000.); hZtt_fb->SetFillColor(kOrange-4); + TH1F* hTTb_fb = new TH1F( "hTTb_fb" ,"ttbar" , 400, 0., 2000.); hTTb_fb->SetFillColor(kBlue-8); + TH1F* hVV_fb = new TH1F( "hVV_fb" ,"Diboson" , 400, 0., 2000.); hVV_fb->SetFillColor(kRed+2); + TH1F* hQCD_fb = new TH1F( "hQCD_fb" ,"QCD full vbf" , 400, 0., 2000.); hQCD_fb->SetFillColor(kMagenta-10); + TH1F* hZll_fb = new TH1F( "hZll_fb" ,"Zll" , 400, 0., 2000.); hZll_fb->SetFillColor(kBlue-2); + TH1F* hZj_fb = new TH1F( "hZj_fb" ,"Z+jets, jet to tau" , 400, 0., 2000.); hZj_fb->SetFillColor(kBlue-2); + /* + TH1F* hSignal[nProd][nMasses]; + for(int iP=0 ; iPSetLineWidth(2); + } + } + //GGH Higgs pT weights up/down + TH1F* hGGFHUp[nMasses]; TH1F* hGGFHDown[nMasses]; + for(int iM=0 ; iMSetLineWidth(2); + hGGFHDown[iM] = new TH1F("hGGFH"+nameMasses[iM]+"Down", "GGFH"+nameMasses[iM]+"Down", nBins , bins.GetArray()); + hGGFHDown[iM]->SetLineWidth(2); + } + */ + //GGH Higgs pT weights up/down + TH1F* hSUSYGGHUp[nMassesS]; TH1F* hSUSYGGHDown[nMassesS]; + for(int iM=0 ; iMSetLineWidth(2); + hSUSYGGHDown[iM] = new TH1F("hSUSYGGH"+nameMassesS[iM]+"Down", "SUSYGGH"+nameMassesS[iM]+"Down", nBins , bins.GetArray()); + hSUSYGGHDown[iM]->SetLineWidth(2); + } + /* + TH1F* hSignalWW[nProdWW][nMassesWW]; + for(int iP=0 ; iPSetLineWidth(2); + } + } + */ + + TH1F* hSusy[nProdS][nMassesS]; + + if(MSSM) { + for(int iP=0 ; iPSetLineWidth(2); + } + } + } + + TH1F* hParameters = new TH1F( "hParameters", "" ,30, 0, 30); + /////////////////////////////////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////////// + + TString pathToFile = "/nfs/dust/cms/user/anayak/CMS/Ntuple_HttAnalysis/ntuples74_50ns/"; + TString pathToFileSUSY = "/nfs/dust/cms/user/anayak/CMS/Ntuple_HttAnalysis/ntuples74/"; + cout<<"**********************************"<Add(pathToFile+"/nTupleRun2015B-Data_TauTau.root"); + if(!data) cout << "### DATA NTUPLE NOT FOUND ###" << endl; + + /* // EMBEDDED // + TString treeEmbedded,fileAnalysisEmbedded; + if(analysis_.Contains("TauUp") || analysis_.Contains("TauDown") ){ + treeEmbedded = "outTree"+analysis_; + fileAnalysisEmbedded = analysis_; + } + else { + treeEmbedded = "outTree"; + fileAnalysisEmbedded = "nominal"; + } + TChain *dataEmbedded = new TChain(treeEmbedded); + // + dataEmbedded->Add(pathToFile+"/nTupleRun2012A*Embedded_TauTau_"+fileAnalysisEmbedded+".root"); + */ + + // BACKGROUNDS // + TString treeMC,fileAnalysis; + if(analysis_.Contains("TauUp") || analysis_.Contains("TauDown") ) { + treeMC = "outTree"+analysis_; + fileAnalysis=analysis_; + } + else { + treeMC = "outTree"; + fileAnalysis="nominal"; + } + // + TChain *backgroundDY = new TChain(treeMC); + TChain *backgroundDYTauTau = new TChain(treeMC); + TChain *backgroundDYLtoTau = new TChain(treeMC); + TChain *backgroundDYJtoTau = new TChain(treeMC); + TChain *backgroundTTbar = new TChain(treeMC); + TChain *backgroundOthers = new TChain(treeMC); + TChain *backgroundWJets = new TChain(treeMC); + // + + backgroundDY ->Add(pathToFile+"nTupleDYJets_TauTau_"+fileAnalysis+".root"); + + backgroundTTbar ->Add(pathToFile+"nTupleTTJets_TauTau_"+fileAnalysis+".root"); + // + //backgroundOthers ->Add(pathToFile+"nTupleSAntiTopT_TauTau_"+fileAnalysis+".root"); + backgroundOthers ->Add(pathToFile+"nTupleSTopT_TauTau_"+fileAnalysis+".root"); + backgroundOthers ->Add(pathToFile+"nTupleSAntiTopTW_TauTau_"+fileAnalysis+".root"); + backgroundOthers ->Add(pathToFile+"nTupleSTopTW_TauTau_"+fileAnalysis+".root"); + //backgroundOthers ->Add(pathToFile+"nTupleWWTo2L2Nu_TauTau_"+fileAnalysis+".root"); + //backgroundOthers ->Add(pathToFile+"nTupleWWToLNuQQ_TauTau_"+fileAnalysis+".root"); + //backgroundOthers ->Add(pathToFile+"nTupleWWTo4Q_TauTau_"+fileAnalysis+".root"); + //backgroundOthers ->Add(pathToFile+"nTupleWZTo1L1Nu2Q_TauTau_"+fileAnalysis+".root"); + //backgroundOthers ->Add(pathToFile+"nTupleWZTo3LNu_TauTau_"+fileAnalysis+".root"); + //backgroundOthers ->Add(pathToFile+"nTupleZZ_TauTau_"+fileAnalysis+".root"); + + backgroundWJets ->Add(pathToFile+"nTupleWJets_TauTau_"+fileAnalysis+".root"); + + if(!backgroundDY) cout << "### NTUPLE DY NOT FOUND ###" << endl; + if(!backgroundTTbar) cout << "### NTUPLE TT NOT FOUND ###" << endl; + if(!backgroundOthers)cout << "### NTUPLE VVt NOT FOUND ###" << endl; + if(!backgroundWJets) cout << "### NTUPLE W NOT FOUND ###" << endl; + /* + TChain *signal[nProd][nMasses]; + for(int iP=0 ; iPAdd(pathToFile+"/nTuple"+nameProd[iP]+nameMasses[iM]+"_TauTau_"+fileAnalysis+".root"); + if(!signal[iP][iM])cout << "### NTUPLE Signal " << nameProd[iP]+nameMasses[iM] << " NOT FOUND ###" << endl; + } + } + TChain *signalWW[nProdWW][nMassesWW]; + for(int iP=0 ; iPAdd(pathToFileHWW+"/nTuple"+nameProdWW[iP]+nameMassesWW[iM]+"_TauTau_"+fileAnalysis+".root"); + if(!signalWW[iP][iM])cout << "### NTUPLE Signal " << nameProdWW[iP]+nameMassesWW[iM] << " NOT FOUND ###" << endl; + } + }*/ + TChain *signalSusy[nProdS][nMassesS]; + if(MSSM) { + for(int iP=0 ; iPAdd(pathToFileSUSY+"/nTupleSUSY"+nameProdS[iP]+nameMassesS[iM]+"_TauTau_"+fileAnalysis+".root"); + } + } + } + + // Split DY into 3 sub-samples (Z->TauTau, Z->ll, ZJ) + TFile *dummy1; + if(DOSPLIT) { + cout << "SPLIT DY SAMPLE ON THE FLY" << endl; + // + dummy1 = new TFile("dummy2.root","RECREATE"); + // + cout << "Now copying g/Z -> tau+ tau- " << endl; + backgroundDYTauTau = (TChain*)backgroundDY->CopyTree("isZtt==1"); // g/Z -> tau+ tau- + // + cout << "Now copying g/Z -> l+l- l->tau" << endl; + backgroundDYLtoTau = (TChain*)backgroundDY->CopyTree("isZll==1"); // g/Z -> ll, l->tau + // + cout << "Now copying g/Z, j->tau" << endl; + backgroundDYJtoTau = (TChain*)backgroundDY->CopyTree("isZj==1"); // g/Z -> ll, jet->tau + } + else { + cout << "USE DY SEPARATE SUB-SAMPLES" << endl; + // + backgroundDYTauTau ->Add(pathToFile+"/nTupleDYJetsTauTau_TauTau_" +fileAnalysis+".root"); + + backgroundDYLtoTau->Add(pathToFile+"/nTupleDYJets*ZLtoTau_TauTau_" +fileAnalysis+".root"); + + backgroundDYJtoTau->Add(pathToFile+"/nTupleDYJets*ZJ_TauTau_" +fileAnalysis+".root"); + + + cout << backgroundDYTauTau->GetEntries() << " come from DY->tautau" << endl; + cout << backgroundDYJtoTau->GetEntries() << " come from DY, jet->tau" << endl; + cout << backgroundDYLtoTau->GetEntries() << " come from DY-> LL" << endl; + } + + cout << backgroundDYTauTau->GetEntries() << " come from DY->tautau" << endl; + cout << backgroundDYJtoTau->GetEntries() << " come from DY, jet->tau" << endl; + cout << backgroundDYLtoTau->GetEntries() << " come from DY-> LL" << endl; + + // MAPPING // + if(VERBOSE) cout << "-- gather the trees" << endl; + + const int nVarious = 8; + //const int nChainsSM = nVarious + nProd*nMasses; + //const int nChainsSM = nChainsSM1 + nProdWW*nMassesWW; + const int nChains = nVarious + nProdS*nMassesS; //nChainsSM + nProdS*nMassesS; + TString treeNamesVarious[nVarious]={"SS", "Data", "WJets","TTbar","Others","DYToTauTau", "DYLtoTau", "DYJtoTau"}; + TChain* chainsVarious[nVarious] ={data, data, backgroundWJets,backgroundTTbar,backgroundOthers, backgroundDYTauTau, backgroundDYLtoTau, backgroundDYJtoTau}; + TString treeNames[nChains]; + TChain* chains[nChains]; + mapchain mapAllTrees; + + for(int iCh=0 ; iCh45 && ptL2>45"); + TCut antimu("tightestAntiMu3WPL1>0 && tightestAntiMu3WPL2>0"); + TCut antiele("tightestAntiEMVA5WPL1 > 0 && tightestAntiEMVA5WPL2 > 0"); + TCut tiso("hpsDB3HL1<1.0 && hpsDB3HL2<1.0"); + TCut tdecaymode("decayModeFindingNewDML1>0.5 && decayModeFindingNewDML2>0.5"); + TCut ltiso("hpsDB3HL1<10.0 && hpsDB3HL2<10.0"); + TCut atiso("hpsDB3HL1<10.0 && hpsDB3HL2<10.0 && hpsDB3HL1>1.0 && hpsDB3HL2>1.0 "); + TCut selection("etaL1<999"); + + // Choose selection wrt version_ + //chooseSelection(variable_,version_, selection_, tiso, tdecaymode, ltiso, atiso, antimu, antiele, selection,tpt); + + ////// EVENT WISE ////// + TCut lveto="nVetoMuon<=0 && nVetoElectron<=0"; + TCut SS("diTauCharge>0"); + TCut OS("diTauCharge<0"); + + bool invertDiTauSign = bool(selection_.find("SS")!=string::npos); + TCut diTauCharge = invertDiTauSign ? SS : OS; + string sign = invertDiTauSign ? "SS" : "OS"; + // HLT matching // + TCut hltevent("HLTx==1 && HLTmatchL1==1 && HLTmatchL2==1"); + + ////// CATEGORIES /// + TCut oneJet("nJets30>=1"); + TCut twoJets("nJets30>=2"); + TCut vbf = TCut("nJets30>=2 && ptj1>30 && ptj2>30 && Mjj>500 && Detajj>3.5 && nVetoJets<=0 && nJets20BTagged<1 && diTauRecoPt>100"); + TCut vbfLoose = TCut("nJets30>=2 && pt1>30 && pt2>30 && Mjj>200 && Deta>2.0 && nVetoJets<=0"); + + TCut oneJetHigh("nJets30>0 && ptj1>30 && nJets20BTagged<1 && diTauRecoPt>170"); + TCut oneJetMedium("nJets30>0 && ptj1>30 && nJets20BTagged<1 && diTauRecoPt>100 && diTauRecoPt<170"); + + oneJetHigh = oneJetHigh && !vbf; + oneJetMedium = oneJetMedium && !vbf; + + TCut bTag("nJets30<2 && nJets20BTagged>0"); + TCut bTagLoose("nJets30<2 && nJets20BTaggedLoose>0"); //for W shape in b-Category + TCut nobTag("nJets20BTagged==0"); + TCut inclusive(""); + + TCut novbf("nJets30<1 && nJets20BTagged==0"); + + TCut sbinCatIncl("etaL1<999"); + TCut sbinCat(""); + if( selection_.find("inclusive")!=string::npos) sbinCat = inclusive&&TCut("etaL1<999"); + else if(selection_.find("oneJet")!=string::npos) sbinCat = oneJet; + else if(selection_.find("twoJets")!=string::npos) sbinCat = twoJets; + else if(selection_.find("oneJetHigh")!=string::npos)sbinCat = oneJetHigh; + else if(selection_.find("oneJetMedium")!=string::npos)sbinCat = oneJetMedium; + else if(selection_.find("nobTag")!=string::npos) sbinCat = nobTag; + else if(selection_.find("vbf")!=string::npos) sbinCat = vbf; + else if(selection_.find("bTag")!=string::npos && selection_.find("nobTag")==string::npos) sbinCat = bTag; + + + //TCut sbinPresel = tpt && tiso && tdecaymode && antimu && antiele && lveto && selection && hltevent ; + //TCut sbinEmbeddingPresel = tpt && tiso && tdecaymode && antimu && antiele && lveto && selection ; + //TCut sbinLtisoPresel = tpt && ltiso && tdecaymode && antimu && antiele && lveto && selection && hltevent ; + //TCut sbinAtisoPresel = tpt && atiso && tdecaymode && antimu && antiele && lveto && selection && hltevent ; + + TCut sbinInclusive = tpt && tiso && tdecaymode && antimu && antiele && lveto && selection && diTauCharge && hltevent ; + TCut sbinChargeRelInclusive = tpt && tiso && tdecaymode && antimu && antiele && lveto && selection && hltevent ; + TCut sbinChargeRelLtisoInclusive = tpt && ltiso && tdecaymode && antimu && antiele && lveto && selection && hltevent ; + TCut sbinChargeRelAtisoInclusive = tpt && atiso && tdecaymode && antimu && antiele && lveto && selection && hltevent ; + TCut sbinEmbeddingInclusive = tpt && tiso && tdecaymode && antimu && antiele && lveto && selection && diTauCharge ; + TCut sbinSSInclusive = tpt && tiso && tdecaymode && antimu && antiele && lveto && selection && SS && hltevent ; + + TCut sbinSSLtisoInclusive = tpt && ltiso && tdecaymode && antimu && antiele && lveto && selection && SS && hltevent ; + TCut sbinSSAtisoInclusive = tpt && atiso && tdecaymode && antimu && antiele && lveto && selection && SS && hltevent ; + TCut sbinLtisoInclusive = tpt && ltiso && tdecaymode && antimu && antiele && lveto && selection && diTauCharge && hltevent ; + TCut sbinAtisoInclusive = tpt && atiso && tdecaymode && antimu && antiele && lveto && selection && diTauCharge && hltevent ; + + TCut sbin = tpt && tiso && tdecaymode && antimu && antiele && lveto && selection && diTauCharge && hltevent ; + TCut sbinEmbedding = tpt && tiso && tdecaymode && antimu && antiele && lveto && selection && diTauCharge ; + TCut sbinSS = tpt && tiso && tdecaymode && antimu && antiele && lveto && selection && SS && hltevent ; + TCut sbinSSltiso = tpt && ltiso && tdecaymode && antimu && antiele && lveto && selection && SS && hltevent ; + TCut sbinSSatiso = tpt && atiso && tdecaymode && antimu && antiele && lveto && selection && SS && hltevent ; + TCut sbinLtiso = tpt && ltiso && tdecaymode && antimu && antiele && lveto && selection && diTauCharge && hltevent ; + TCut sbinAtiso = tpt && atiso && tdecaymode && antimu && antiele && lveto && selection && diTauCharge && hltevent ; + + cout << sbin << endl; + ///////////////////////////////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////////////////////////////// + cout << endl; + cout << "#############################################################" << endl; + cout << ">>>>>>>>>>> BEGIN Compute inclusive informations <<<<<<<<<<<<" << endl; + cout << "#############################################################" << endl; + cout << endl; + + cout << "******** Extrapolation factors for Z->tautau normalization ********" << endl; + // inclusive DY->tautau: + TH1F* hExtrap = new TH1F("hExtrap","",nBins , bins.GetArray()); + float Error = 0.; + + //Monte Carlo ZTT Inclusive + float ExtrapDYInclusive = 0.; + drawHistogram(sbinCatIncl,"MC", version_,analysis_, mapAllTrees["DYToTauTau"], variable, ExtrapDYInclusive, Error, Lumi*lumiCorrFactor/1000., hExtrap, sbinInclusive); + cout << "All Z->tautau = " << ExtrapDYInclusive << " +/- " << Error << endl; + + //Monte Carlo ZTT in the category + float ExtrapDYNum = 0.; + drawHistogram(sbinCat,"MC", version_,analysis_, mapAllTrees["DYToTauTau"], variable, ExtrapDYNum, Error, Lumi*lumiCorrFactor/1000., hExtrap, sbin); + + //Monte Carlo ZTT: compute the probability for an event to be in a category + float ExtrapolationFactorMC = ExtrapDYNum/ExtrapDYInclusive;//probability to enter a category taken from MC + float ErrorExtrapolationFactorMC = TMath::Sqrt(ExtrapolationFactorMC*(1-ExtrapolationFactorMC)/ExtrapDYInclusive); + cout << "Extrap. factor using MadGraph = " << ExtrapolationFactorMC << " +/- " << ErrorExtrapolationFactorMC << endl; + + //Embedded ZTT in the category (Embedding sample not available now) + float ExtrapEmbedNum = 0.; + //drawHistogram(sbinEmbeddingPresel,sbinCat,"Embed", version_,analysis_, mapAllTrees["Embedded"], variable, ExtrapEmbedNum, Error, 1.0, hExtrap, sbinEmbedding); + + if(DEBUG) cout << "drawHistogram Embed sbinEmbeddingInclusive" << endl; + //Embedded ZTT Inclusive + float ExtrapEmbedDen = 0.; + //drawHistogram(sbinEmbeddingPresel,sbinCatIncl,"Embed", version_,analysis_, mapAllTrees["Embedded"], variable, ExtrapEmbedDen, Error, 1.0, hExtrap, sbinEmbeddingInclusive); + + //Probability to enter category, from Embedded + ExtrapolationFactorZ = ExtrapEmbedDen!=0 ? ExtrapEmbedNum/ExtrapEmbedDen : 0; + ErrorExtrapolationFactorZ = ExtrapEmbedDen!=0 ? TMath::Sqrt(ExtrapolationFactorZ*(1-ExtrapolationFactorZ)/ExtrapEmbedDen) : 0; + //Ratio of the probabilities from Embedded to MC + ExtrapolationFactorZDataMC = ExtrapolationFactorMC!=0 ? ExtrapolationFactorZ/ExtrapolationFactorMC : 0; + if(!useEmbedding_) { + ExtrapolationFactorZ = ExtrapolationFactorZDataMC = 1; + } + + cout << "Extrap. factor using embedded sample = " << ExtrapolationFactorZ << " +/- " << ErrorExtrapolationFactorZ << endl; + cout << " ==> data/MC (signal region) = " << ExtrapolationFactorZDataMC << " +/- " + << ExtrapolationFactorZDataMC*(ErrorExtrapolationFactorMC/ExtrapolationFactorMC + + ErrorExtrapolationFactorZ/ExtrapolationFactorZ) + << endl; + + ///////////////////////////////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////////////////////////////// + + cout << endl; + cout << "******** Extrapolation factors for QCD normalization ********" << endl; + + float SSQCDinSignalRegionDATAIncl = 0.; + if(invertDiTauSign) OStoSSRatioQCD = 1.0; + + evaluateQCD(mapAllTrees, version_,analysis_, 0, 0, "SS", + SSQCDinSignalRegionDATAIncl, scaleFactorTTSSIncl, + hExtrap, variable, + Lumi/1000, TTxsectionRatio, lumiCorrFactor, + ExtrapolationFactorZDataMC, + JtoTauCorrectionFactor, LtoTauCorrectionFactor, + OStoSSRatioQCD, + sbinInclusive, sbinCat, + sbinSSInclusive, sbinCat, + sbinAtisoInclusive, + true, true); + + delete hExtrap; + + cout << endl; + cout << "#############################################################" << endl; + cout << ">>>>>>>>>>> END Compute inclusive informations <<<<<<<<<<<<<<" << endl; + cout << "#############################################################" << endl; + + ///////////////////////////////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////////////////////////////// + + float SSQCDinSignalRegionDATA = 0.; + + mapchain::iterator it; + TString currentName, h1Name, h2Name ; + TChain* currentTree; + + for(int iCh=0 ; iCh>>> Dealing with sample ## " ; + currentName = treeNames[iCh]; + cout << currentName << " ##" << endl; + + it = mapAllTrees.find(currentName); + if(it!=mapAllTrees.end()) currentTree = it->second; + else { + cout << "ERROR : sample not found in the map ! continue;" << endl; + continue; + } + + if(!currentTree) { + cout << "ERROR : no such tree" << endl; + continue; + } + + if(!MSSM && currentName.Contains("SUSY")) continue; + + h1Name = "h1_"+currentName; + h2Name = "h2_"+currentName; + TH1F* h1 = new TH1F( h1Name ,"" , nBins , bins.GetArray()); + TH1F* h2 = new TH1F( h2Name ,"" , nBins , bins.GetArray()); + + TH1F* hCleaner = new TH1F("hCleaner","",nBins , bins.GetArray()); + TH1F* hCleanerfb = new TH1F("hCleanerfb","",400, 0., 2000.); //fine binning hostogram for MSSM + if ( !h1->GetSumw2N() ) h1->Sumw2(); + if ( !hCleaner->GetSumw2N() ) hCleaner->Sumw2(); + if ( !hCleanerfb->GetSumw2N() ) hCleanerfb->Sumw2(); + + if(currentName.Contains("SS")){ + + cout << "************** BEGIN QCD evaluation using SS events *******************" << endl; + + TH1F* hExtrapSS = new TH1F("hExtrapSS","",nBins , bins.GetArray()); + float dummy1 = 0.; + + evaluateQCD(mapAllTrees, version_,analysis_, h1, hCleaner, "SS", + SSQCDinSignalRegionDATA, scaleFactorTTSS, + hExtrapSS, variable, + Lumi/1000, TTxsectionRatio, lumiCorrFactor, + ExtrapolationFactorZDataMC, + JtoTauCorrectionFactor, LtoTauCorrectionFactor, + OStoSSRatioQCD, + sbin, sbinCat, + sbinSS, sbinCat, + sbinAtiso, + true, true); + + hExtrapSS->Reset(); + hQCD->Add(h1, 1.0); + hSS->Add(hCleaner, OStoSSRatioQCD); + hCleaner->Reset(); + + //fine binning for MSSM + if(selection_.find("nobTag")!=string::npos){ + TH1F* h1fb = new TH1F("h1fb","",400, 0., 2000.); //fine binning hostogram for MSSM + if ( !h1fb->GetSumw2N() ) h1fb->Sumw2(); + TH1F* hExtrapSSfb = new TH1F("hExtrapSSfb","",400, 0., 2000.); + if ( !hExtrapSSfb->GetSumw2N() ) hExtrapSSfb->Sumw2(); + + evaluateQCD(mapAllTrees, version_,analysis_, h1fb, hCleanerfb, "SS", + SSQCDinSignalRegionDATA, scaleFactorTTSS, + hExtrapSSfb, variable, + Lumi/1000, TTxsectionRatio, lumiCorrFactor, + ExtrapolationFactorZDataMC, + JtoTauCorrectionFactor, LtoTauCorrectionFactor, + OStoSSRatioQCD, + sbin, sbinCat, + sbinSS, sbinCat, + sbinAtiso, + true, true); + + cout << "************** END QCD evaluation using SS events *******************" << endl; + hQCD_fb->Add(h1fb, h1->Integral()/h1fb->Integral()); + hCleanerfb->Reset(); + delete hExtrapSSfb; + } + + } + else{ + + if(!currentName.Contains("Embed")){ + + float Error = 0.; + + if(currentName.Contains("DYToTauTau")){ + float NormDYToTauTau = 0.; + drawHistogram(sbinCat,"MC", version_,analysis_, currentTree, variable, NormDYToTauTau, Error, Lumi*lumiCorrFactor/1000., h1, sbin, 1); + hZtt->Add(h1, 1.0); + + //fine binning for MSSM + if(selection_.find("bTag")!=string::npos){ + hCleanerfb->Reset(); float NormDYToTauTau_fb = 0.; + drawHistogram(sbinCat,"MC", version_,analysis_, currentTree, variable, NormDYToTauTau_fb, Error, Lumi*lumiCorrFactor/1000., hCleanerfb, sbin, 1); + hZtt_fb->Add(hCleanerfb, 1.0); + hCleanerfb->Reset(); + } + } + if(currentName.Contains("TTbar")){ + if(selection_.find("vbf")!=string::npos){ + float NormTTjets = 0.; + drawHistogram(vbfLoose,"MC", version_,analysis_, currentTree, variable, NormTTjets, Error, Lumi*TTxsectionRatio/1000., hCleaner, sbinInclusive, 1); + + hTTb->Add(hCleaner, 1.0); + cout << "--- TTbar shape histogram has Integral=" << hTTb->Integral() << endl; + NormTTjets = 0.; + + drawHistogram(sbinCat,"MC", version_,analysis_, currentTree, variable, NormTTjets, Error, Lumi*TTxsectionRatio/1000., h1, sbin, 1); + cout << "--- TTbar Norm histogram has Integral=" << h1->Integral() << endl; + hTTb->Scale( hTTb->Integral()!=0 ? h1->Integral()/hTTb->Integral() : 1.0 ); + } + else{ + float NormTTjets = 0.; + drawHistogram(sbinCat,"MC", version_,analysis_, currentTree, variable, NormTTjets, Error, Lumi*TTxsectionRatio/1000., h1, sbin, 1); + hTTb->Add(h1, 1.0); + + //fine binning for MSSM + if(selection_.find("bTag")!=string::npos){ + hCleanerfb->Reset(); float NormTTjets_fb = 0.; + drawHistogram(sbinCat,"MC", version_,analysis_, currentTree, variable, NormTTjets_fb, Error, Lumi*TTxsectionRatio/1000., hCleanerfb, sbin, 1); + hTTb_fb->Add(hCleanerfb, hTTb->Integral()/hCleanerfb->Integral()); + hCleanerfb->Reset(); + } + } + } + else if(currentName.Contains("WJets")){ + + //For the shape of W in opposite sign region --> taken from MC + float NormWJets = 0.; + drawHistogram(sbinCat,"MC",version_,analysis_, currentTree, variable, NormWJets, Error, Lumi/1000., h1, sbin, 1); + hW->Add(h1, 1.0); + + //fine binning for MSSM + if(selection_.find("bTag")!=string::npos){ + hCleanerfb->Reset(); float NormWJets_fb = 0.; + hW_fb->Reset(); + drawHistogram(sbinCat,"MC",version_,analysis_, currentTree, variable, NormWJets_fb, Error, Lumi/1000., hCleanerfb, sbin, 1); + hW_fb->Add(hCleanerfb, h1->Integral()/hCleanerfb->Integral()); + } + if(selection_.find("oneJet")!=string::npos){ + hCleaner->Reset(); + float NormWJets_ltiso = 0.; + hW->Reset(); + drawHistogram(sbinCat,"MC",version_,analysis_, currentTree, variable, NormWJets_ltiso, Error, Lumi/1000., hCleaner, sbinLtiso, 1); + hW->Add(hCleaner, h1->Integral()/hCleaner->Integral()); + } + else if(selection_.find("vbf")!=string::npos){ + hCleaner->Reset(); + float NormWJets_ltiso = 0.; + hW->Reset(); + drawHistogram(vbfLoose,"MC",version_,analysis_, currentTree, variable, NormWJets_ltiso, Error, Lumi/1000., hCleaner, sbinLtiso, 1); + hW->Add(hCleaner, h1->Integral()/hCleaner->Integral()); + } + } + else if(currentName.Contains("DYJtoTau")){ + if(selection_.find("vbf")!=string::npos){ + float NormDYJtoTau = 0.; + hCleaner->Reset(); + drawHistogram(vbfLoose,"MC", version_,analysis_, currentTree, variable, NormDYJtoTau, Error, Lumi*lumiCorrFactor*JtoTauCorrectionFactor/1000., hCleaner, sbinInclusive, 1); + NormDYJtoTau = 0.; + if(useZDataMC) + drawHistogram(sbinCat,"MC", version_,analysis_, currentTree, variable, NormDYJtoTau, Error, Lumi*lumiCorrFactor*JtoTauCorrectionFactor*ExtrapolationFactorZDataMC/1000., h1, sbin, 1); + else + drawHistogram(sbinCat,"MC", version_,analysis_, currentTree, variable, NormDYJtoTau, Error, Lumi*lumiCorrFactor*JtoTauCorrectionFactor/1000., h1, sbin, 1); + hCleaner->Scale( hCleaner->Integral()!=0 ? h1->Integral()/hCleaner->Integral() : 1.0 ); + if(hCleaner) { + hZj->Add(hCleaner, 1.0); + hZfakes->Add(hCleaner,1.0); + hEWK->Add(hCleaner,1.0); + } + } + else{ + float NormDYJtoTau = 0.; + if(useZDataMC) + drawHistogram(sbinCat,"MC", version_,analysis_, currentTree, variable, NormDYJtoTau, Error, Lumi*lumiCorrFactor*JtoTauCorrectionFactor*ExtrapolationFactorZDataMC/1000., h1, sbin, 1); + else + drawHistogram(sbinCat,"MC", version_,analysis_, currentTree, variable, NormDYJtoTau, Error, Lumi*lumiCorrFactor*JtoTauCorrectionFactor/1000., h1, sbin, 1); + hZj->Add(h1, 1.0); + hZfakes->Add(h1,1.0); + hEWK->Add(h1,1.0); + + //fine binning for MSSM + if(selection_.find("bTag")!=string::npos){ + hCleanerfb->Reset();hZj_fb->Reset(); float NormDYJtoTau_fb = 0.; + drawHistogram(sbinCat,"MC", version_,analysis_, currentTree, variable, NormDYJtoTau_fb, Error, Lumi*lumiCorrFactor*JtoTauCorrectionFactor/1000., hCleanerfb, sbin, 1); + if(hCleanerfb)hZj_fb->Add(hCleanerfb, h1->Integral()/hCleanerfb->Integral()); + } + } + } + else if(currentName.Contains("DYLtoTau")){ + if(selection_.find("vbf")!=string::npos){ + float NormDYLtoTau = 0.; + hCleaner->Reset(); + drawHistogram(vbfLoose,"MC", version_,analysis_, currentTree, variable, NormDYLtoTau, Error, Lumi*lumiCorrFactor*LtoTauCorrectionFactor/1000., hCleaner, sbinInclusive, 1); + NormDYLtoTau = 0.; + if(useZDataMC) + drawHistogram(sbinCat,"MC", version_,analysis_, currentTree, variable, NormDYLtoTau, Error, Lumi*lumiCorrFactor*LtoTauCorrectionFactor*ExtrapolationFactorZDataMC/1000., h1, sbin, 1); + else + drawHistogram(sbinCat,"MC", version_,analysis_, currentTree, variable, NormDYLtoTau, Error, Lumi*lumiCorrFactor*LtoTauCorrectionFactor/1000., h1, sbin, 1); + hCleaner->Scale( hCleaner->Integral()!=0 ? h1->Integral()/hCleaner->Integral() : 1.0 ); + if(hCleaner) { + hZll->Add(hCleaner, 1.0); + hZfakes->Add(hCleaner,1.0); + hEWK->Add(hCleaner,1.0); + } + } + else{ + float NormDYLtoTau = 0.; + if(useZDataMC) + drawHistogram(sbinCat,"MC", version_,analysis_, currentTree, variable, NormDYLtoTau, Error, Lumi*lumiCorrFactor*LtoTauCorrectionFactor*ExtrapolationFactorZDataMC/1000., h1, sbin, 1); + else + drawHistogram(sbinCat,"MC", version_,analysis_, currentTree, variable, NormDYLtoTau, Error, Lumi*lumiCorrFactor*LtoTauCorrectionFactor/1000., h1, sbin, 1); + hZll->Add(h1, 1.0); + hZfakes->Add(h1,1.0); + hEWK->Add(h1,1.0); + + //fine binning for MSSM + if(selection_.find("bTag")!=string::npos){ + hCleanerfb->Reset();hZll_fb->Reset(); float NormDYLtoTau_fb = 0.; + drawHistogram(sbinCat,"MC", version_,analysis_, currentTree, variable, NormDYLtoTau_fb, Error, Lumi*lumiCorrFactor*LtoTauCorrectionFactor/1000., hCleanerfb, sbin, 1); + if(hCleanerfb)hZll_fb->Add(hCleanerfb, h1->Integral()/hCleanerfb->Integral()); + } + } + } + else if(currentName.Contains("Others")){ + if(selection_.find("vbf")!=string::npos){ + float NormOthers = 0.; + drawHistogram(vbfLoose,"MC", version_,analysis_, currentTree, variable, NormOthers, Error, Lumi/1000., hCleaner, sbinInclusive, 1); + NormOthers = 0.; + drawHistogram(sbinCat,"MC", version_,analysis_, currentTree, variable, NormOthers , Error, Lumi/1000., h1, sbin, 1); + hCleaner->Scale( hCleaner->Integral()!=0 ? h1->Integral()/hCleaner->Integral() : 1.0 ); + if(hCleaner) { + hVV->Add(hCleaner, 1.0); + hEWK->Add(hCleaner,1.0); + } + } + else{ + float NormOthers = 0.; + drawHistogram(sbinCat,"MC", version_,analysis_, currentTree, variable, NormOthers , Error, Lumi/1000., h1, sbin, 1); + hVV->Add(h1, 1.0); + hEWK->Add(h1,1.0); + + //fine binning for MSSM + if(selection_.find("bTag")!=string::npos){ + hCleanerfb->Reset();hVV_fb->Reset(); float NormOthers_fb = 0.; + drawHistogram(sbinCat,"MC", version_,analysis_, currentTree, variable, NormOthers_fb, Error, Lumi/1000., hCleanerfb, sbin, 1); + hVV_fb->Add(hCleanerfb, hVV->Integral()/hCleanerfb->Integral()); + } + } + } + else if(currentName.Contains("Data")){ + + float NormData = 0.; + drawHistogram(sbinCat,"Data", version_,analysis_, currentTree, variable, NormData, Error, 1.0 , h1, sbin, 1); + if(VERBOSE) cout << "DATA YIELD : " << NormData << " +/- " << Error << endl; + hData->Add(h1, 1.0); + if ( !hData->GetSumw2N() )hData->Sumw2(); + + if(selection_.find("vbf")!=string::npos){ + drawHistogram(vbfLoose,"Data", version_,analysis_, currentTree, variable, NormData, Error, 1.0 , hCleaner, sbinSSatiso ,1); + hDataAntiTauIso->Add(hCleaner); + //need to subtract other background contributions + float NormDYJtoTau = 0.; + drawHistogram(vbfLoose,"MC", version_,analysis_, mapAllTrees["DYJtoTau"], variable, NormDYJtoTau, Error, Lumi*lumiCorrFactor*JtoTauCorrectionFactor/1000., hCleaner, sbinSSatiso, 1); + hDataAntiTauIso->Add(hCleaner, -1.0); + float NormDYLtoTau = 0.; + drawHistogram(vbfLoose,"MC", version_,analysis_, mapAllTrees["DYLtoTau"], variable, NormDYLtoTau, Error, Lumi*lumiCorrFactor*LtoTauCorrectionFactor/1000., hCleaner, sbinSSatiso, 1); + hDataAntiTauIso->Add(hCleaner, -1.0); + float NormTTjets = 0.; + drawHistogram(vbfLoose,"MC", version_,analysis_, mapAllTrees["TTbar"], variable, NormTTjets, Error, Lumi*TTxsectionRatio*scaleFactorTTSS/1000., hCleaner, sbinSSatiso, 1); + hDataAntiTauIso->Add(hCleaner, -1.0); + float NormDYtoTauTau = 0.; + drawHistogram(vbfLoose,"MC", version_,analysis_, mapAllTrees["DYtoTauTau"], variable, NormDYtoTauTau, Error, Lumi*lumiCorrFactor/1000., hCleaner, sbinSSatiso, 1); + hDataAntiTauIso->Add(hCleaner, -1.0); + float NormWjets = 0.; + drawHistogram(vbfLoose,"MC", version_,analysis_, mapAllTrees["WJet"], variable, NormWjets, Error, Lumi/1000., hCleaner, sbinSSatiso, 1); + hDataAntiTauIso->Add(hCleaner, -1.0); + + hDataAntiTauIsoQCD->Add(hDataAntiTauIso, hQCD->Integral()/hDataAntiTauIso->Integral()); + } + + } + else if(currentName.Contains("VBFH") || + currentName.Contains("GGFH") || + currentName.Contains("VH") || + currentName.Contains("SUSY")){ + + float NormSign = 0.; + if(VERBOSE) cout << "SIGNAL " << currentName << " ENTRIES " << currentTree->GetEntries() << endl; + drawHistogram(sbinCat,"MC", version_,analysis_, currentTree, variable, NormSign, Error, Lumi/1000., h1, sbin, 1); + + if(currentName.Contains("VBFH"+TmH_)){ + hSgn1->Add(h1,1.0); + hSgn1->Scale(magnifySgn_); + hSgn->Add(hSgn1,1.0); + } + else if(currentName.Contains("GGFH"+TmH_)){ + hSgn2->Add(h1,1.0); + hSgn2->Scale(magnifySgn_); + hSgn->Add(hSgn2,1.0); + } + else if(currentName.Contains("VH"+TmH_)){ + hSgn3->Add(h1,1.0); + hSgn3->Scale(magnifySgn_); + hSgn->Add(hSgn3,1.0); + } + /* + for(int iP=0 ; iPAdd(h1,1.0); + //to be used when weight is available + for(int iM=0 ; iMReset(); float NormSignUp = 0.; + drawHistogram(sbinCat,"MCGGFHUp", version_, analysis_,currentTree, variable, NormSignUp, Error, Lumi/1000., hCleaner, sbin, 1); + hGGFHUp[iM]->Add(hCleaner,1.0); + hCleaner->Reset(); float NormSignDown = 0.; + drawHistogram(sbinCat,"MCGGFHDown", version_, analysis_,currentTree, variable, NormSignDown, Error, Lumi/1000., hCleaner, sbin, 1); + hGGFHDown[iM]->Add(hCleaner,1.0); + } + } + + for(int iP=0 ; iPAdd(h1,1.0); + */ + if(MSSM) { + if(currentName.Contains("SUSY")) + { + /* //select events within 30% of Higgs mass + TString sampleName = currentName; + if(sampleName.Contains("SUSYGGH"))sampleName.ReplaceAll("SUSYGGH", ""); + else if(sampleName.Contains("SUSYBBH"))sampleName.ReplaceAll("SUSYBBH", ""); + float mA = atof(sampleName.Data()); + TCut HWidth(Form("genVMass > 0.7*%f && genVMass < 1.3*%f", mA, mA)); + */ + TCut HWidth(""); + float NormSign = 0.; + drawHistogram(sbinCat,"MC", version_,analysis_, currentTree, variable, NormSign, Error, Lumi/1000., h1, (sbin&&HWidth), 1); + + for(int iP=0 ; iPAdd(h1,1.0); + } + } + } + /* + for(int iM=0 ; iMReset(); float NormSignUp = 0.; + drawHistogram(sbinCat,"MCSUSYGGHUp", version_, analysis_,currentTree, variable, NormSignUp, Error, Lumi/1000., h1, (sbin&&HWidth), 1); + hSUSYGGHUp[iM]->Add(h1,1.0); + + h1->Reset(); float NormSignDown = 0.; + drawHistogram(sbinCat,"MCSUSYGGHDown", version_, analysis_,currentTree, variable, NormSignDown, Error, Lumi/1000., h1, (sbin&&HWidth), 1); + hSUSYGGHDown[iM]->Add(h1,1.0); + + }//End SUSY GGH + }//End Masses + */ + }//End SUSY + }//End MSSM + }//End MC Signal + } + else{ + if(selection_.find("vbf")!=string::npos){ + //Moriond method + float NormEmbed = 0.; + drawHistogram(sbinCat,"Embed", version_,analysis_, currentTree, variable, NormEmbed, Error, 1.0 , h1, sbinEmbedding ,1); + h1->Scale( (ExtrapolationFactorZ*ExtrapolationFactorZFromSideband)/h1->Integral()); + hZttEmb->Add(h1, 1.0); + } + else{ + float NormEmbed = 0.; + drawHistogram(sbinCat,"Embed", version_,analysis_, currentTree, variable, NormEmbed, Error, 1.0 , h1, sbinEmbedding ,1); + h1->Scale( (ExtrapolationFactorZ*ExtrapolationFactorZFromSideband)/h1->Integral()); + hZttEmb->Add(h1, 1.0); + + //fine binning for MSSM + if(selection_.find("bTag")!=string::npos){ + hCleanerfb->Reset(); float NormEmbed_fb = 0.; + drawHistogram(sbinCat,"Embed", version_,analysis_, currentTree, variable, NormEmbed_fb, Error, 1.0 , hCleanerfb, sbinEmbedding ,1); + hZttEmb_fb->Add(hCleanerfb, (ExtrapolationFactorZ*ExtrapolationFactorZFromSideband)); + } + } + } + } + + ///////////////////////////////////////////////////////////////////////////////////// + + if(VERBOSE) cout<<(it->first) << " ==> " + << h1->Integral() << " +/- " + << TMath::Sqrt(h1->GetEntries())*(h1->Integral()/h1->GetEntries()) + << endl; + + //out << (it->first) << " " << h1->Integral() << " $\\pm$ " << TMath::Sqrt(h1->GetEntries())*(h1->Integral()/h1->GetEntries()) << endl; + char* c = new char[50]; + if(h1->Integral()>=10) + sprintf(c,"$%.0f\\pm%.0f$",h1->Integral(), TMath::Sqrt(h1->GetEntries())*(h1->Integral()/h1->GetEntries())); + else if(h1->Integral()>=1) + sprintf(c,"$%.1f\\pm%.1f$",h1->Integral(), TMath::Sqrt(h1->GetEntries())*(h1->Integral()/h1->GetEntries())); + else if(h1->Integral()>=0.1) + sprintf(c,"$%.2f\\pm%.2f$",h1->Integral(), TMath::Sqrt(h1->GetEntries())*(h1->Integral()/h1->GetEntries())); + else if(h1->Integral()>=0.01) + sprintf(c,"$%.3f\\pm%.3f$",h1->Integral(), TMath::Sqrt(h1->GetEntries())*(h1->Integral()/h1->GetEntries())); + else + sprintf(c,"$%.5f\\pm%.5f$",h1->Integral(), TMath::Sqrt(h1->GetEntries())*(h1->Integral()/h1->GetEntries())); + out << string(c) << " //" << (it->first) << endl; + delete c; + + delete hCleaner; delete hCleanerfb; + } + + cout << endl; + cout << "All samples done. Filling hParameters..." << endl; + hParameters->SetBinContent(1, ExtrapolationFactorZ); hParameters->GetXaxis()->SetBinLabel(1,"ExtrapolationFactorZ"); + hParameters->SetBinContent(2, ErrorExtrapolationFactorZ); hParameters->GetXaxis()->SetBinLabel(2,"ErrorExtrapolationFactorZ"); + hParameters->SetBinContent(3, ExtrapolationFactorZDataMC); hParameters->GetXaxis()->SetBinLabel(3,"ExtrapolationFactorZDataMC"); + hParameters->SetBinContent(4, ExtrapolationFactorZFromSideband); hParameters->GetXaxis()->SetBinLabel(4,"ExtrapolationFactorZFromSideband"); + hParameters->SetBinContent(5, ExtrapolationFactorSidebandZDataMC); hParameters->GetXaxis()->SetBinLabel(5,"ExtrapolationFactorSidebandZDataMC"); + hParameters->SetBinContent(6, SSQCDinSignalRegionDATAIncl); hParameters->GetXaxis()->SetBinLabel(9,"SSQCDinSignalRegionDATAIncl"); + hParameters->SetBinContent(7,SSQCDinSignalRegionDATA); hParameters->GetXaxis()->SetBinLabel(13,"SSQCDinSignalRegionDATA"); + hParameters->SetBinContent(8,scaleFactorTTOS); hParameters->GetXaxis()->SetBinLabel(20,"scaleFactorTTOS"); + hParameters->SetBinContent(9,scaleFactorTTSS); hParameters->GetXaxis()->SetBinLabel(21,"scaleFactorTTSS"); + hParameters->SetBinContent(10,scaleFactorTTSSIncl); hParameters->GetXaxis()->SetBinLabel(22,"scaleFactorTTSSIncl"); + hParameters->SetBinContent(11,SSIsoToSSAIsoRatioQCD); hParameters->GetXaxis()->SetBinLabel(23,"SSIsoToSSAIsoRatioQCD"); + hParameters->SetBinContent(12,ExtrapDYInclusive); hParameters->GetXaxis()->SetBinLabel(24,"ExtrapDYInclusive"); + hParameters->SetBinContent(13,ExtrapolationFactorMC); hParameters->GetXaxis()->SetBinLabel(28,"ExtrapolationFactorMC"); + hParameters->SetBinContent(14,ErrorExtrapolationFactorMC); hParameters->GetXaxis()->SetBinLabel(29,"ErrorExtrapolationFactorMC"); + + hParameters->GetXaxis()->LabelsOption("v"); + + //YIELDS + if(selection_.find("vbf")!=string::npos){ + out<<"Yields for VBF :"< "<Integral()< "<Integral()< "<Integral()< "<Integral()<t : hZj -> "<Integral()<t : hZll -> "<Integral()< "<Integral()< "<Integral()< "<Integral()< "<Integral()< "<Integral()< "<Integral()< "<Integral()<t : hZj -> "<Integral()<t : hZll -> "<Integral()< "<Integral()< "<Integral()< "<Integral()< "<Integral()< "<Integral()< "<Integral()< "<Integral()<t : hZj -> "<Integral()<t : hZll -> "<Integral()< "<Integral()< "<Integral()< "<Integral()< "<Integral()< "<Integral()< "<Integral()< "<Integral()<t : hZj -> "<Integral()<t : hZll -> "<Integral()< "<Integral()< "<Integral()<Scale(1.0, "width"); + hTTb->Scale(1.0, "width"); + hZttEmb->Scale(1.0, "width"); + hZtt->Scale(1.0, "width"); + hDataAntiTauIsoQCD->Scale(1.0, "width"); + hQCD->Scale(1.0, "width"); + hSS->Scale(1.0, "width"); + hEWK->Scale(1.0, "width"); + hSgn->Scale(1.0, "width"); + } + + hSiml->Add(hTTb,1.0); + if(useEmbedding_) + hSiml->Add(hZttEmb,1.0); + else + hSiml->Add(hZtt); + + if(selection_.find("vbf")!=string::npos) + hSiml->Add(hDataAntiTauIsoQCD,1.0); + else + hSiml->Add(hSS,1.0); //hSiml->Add(hQCD,1.0); + + //VV + W + ZJ + hSiml->Add(hEWK,1.0); + + if(selection_.find("vbf")!=string::npos) + aStack->Add(hDataAntiTauIsoQCD); + else + aStack->Add(hSS); //aStack->Add(hQCD); + + // TT + aStack->Add(hTTb); + + // VV + W + ZJ + aStack->Add(hEWK); + + // ZTT + if(useEmbedding_) + aStack->Add(hZttEmb); + else + aStack->Add(hZtt); + + if(!logy_ && !MSSM) + aStack->Add(hSgn); + + leg->AddEntry(hData,"Observed","P"); + leg->AddEntry(hSgn,Form("(%.0fx) H#rightarrow#tau#tau m_{H}=%d",magnifySgn_,mH_),"F"); + + if(useEmbedding_) + leg->AddEntry(hZttEmb,"Z#rightarrow#tau#tau (embedded)","F"); + else + leg->AddEntry(hZtt,"Z#rightarrow#tau#tau","F"); + leg->AddEntry(hEWK,"Electroweak","F"); + leg->AddEntry(hQCD,"QCD","F"); + leg->AddEntry(hTTb,"t#bar{t}","F"); + + hData->Draw("P"); + aStack->Draw("HISTSAME"); + hData->Draw("PSAME"); + + TH1F* hStack = (TH1F*)aStack->GetHistogram(); + hStack->SetXTitle(XTitle_+" ("+Unities_+")"); + if(scaleByBinWidth && variable_.Contains("diTauNSVfitMass")){ + hStack->SetYTitle(Form(" Events/(%.0f %s)", 1.0, Unities_.Data() ) ); + hData->SetYTitle(Form(" Events/(%.0f %s)", 1.0, Unities_.Data() ) ); + } + else + hStack->SetYTitle(Form(" Events/(%.0f %s)", hStack->GetBinWidth(1), Unities_.Data() ) ); + hStack->SetTitleSize(0.04,"X"); + hStack->SetTitleSize(0.05,"Y"); + hStack->SetTitleOffset(0.95,"Y"); + if(!logy_) + hData->SetAxisRange(0.0, TMath::Max( hData->GetMaximum(), hSiml->GetMaximum() )*maxY_ ,"Y"); + else + hData->SetAxisRange(0.1, TMath::Max( hData->GetMaximum(), hSiml->GetMaximum() )*maxY_ ,"Y"); + aStack->Draw("HISTSAME"); + hData->Draw("PSAME"); + if(logy_ && !MSSM) + hSgn->Draw("HISTSAME"); + + leg->Draw(); + + pad2->cd(); + gStyle->SetOptStat(0); + gStyle->SetTitleFillColor(0); + gStyle->SetCanvasBorderMode(0); + gStyle->SetCanvasColor(0); + gStyle->SetPadBorderMode(0); + gStyle->SetPadColor(0); + gStyle->SetTitleFillColor(0); + gStyle->SetTitleBorderSize(0); + gStyle->SetTitleH(0.07); + gStyle->SetTitleFontSize(0.1); + gStyle->SetTitleStyle(0); + gStyle->SetTitleOffset(1.3,"y"); + + TH1F* hRatio = new TH1F( "hRatio" ," ; ; #frac{(DATA-MC)}{#sqrt{DATA}}" , nBins , bins.GetArray()); + hRatio->Reset(); + hRatio->SetXTitle(""); + hRatio->SetYTitle("#frac{(DATA-MC)}{MC}"); + + hRatio->SetMarkerStyle(kFullCircle); + hRatio->SetMarkerSize(0.8); + hRatio->SetLabelSize(0.12,"X"); + hRatio->SetLabelSize(0.10,"Y"); + hRatio->SetTitleSize(0.12,"Y"); + hRatio->SetTitleOffset(0.36,"Y"); + + float maxPull = 0.; + for(int k = 0 ; k < hRatio->GetNbinsX(); k++){ + float pull = hData->GetBinContent(k) - hSiml->GetBinContent(k); + if(hSiml->GetBinContent(k)>0) + pull /= hSiml->GetBinContent(k); + hRatio->SetBinContent(k, pull); + if(TMath::Abs(pull) > maxPull) + maxPull = TMath::Abs(pull); + } + hRatio->SetAxisRange(-1.2*maxPull,1.2*maxPull,"Y"); + hRatio->Draw("P"); + + TF1* line = new TF1("line","0",hRatio->GetXaxis()->GetXmin(),hStack->GetXaxis()->GetXmax()); + line->SetLineStyle(3); + line->SetLineWidth(1.5); + line->SetLineColor(kBlack); + line->Draw("SAME"); + + //return; + + if(logy_){ + c1->SaveAs(Form(location+"/%s/plots/plot_tauTau_mH%d_%s_%s_%s_log.png",outputDir.Data(), mH_,selection_.c_str(),analysis_.Data(),variable_.Data())); + c1->SaveAs(Form(location+"/%s/plots/plot_tauTau_mH%d_%s_%s_%s_log.pdf",outputDir.Data(), mH_,selection_.c_str(),analysis_.Data(),variable_.Data())); + c1->SaveAs(Form(location+"/%s/plots/plot_tauTau_mH%d_%s_%s_%s_log.root",outputDir.Data(), mH_,selection_.c_str(),analysis_.Data(),variable_.Data())); + } + else{ + c1->SaveAs(Form(location+"/%s/plots/plot_tauTau_mH%d_%s_%s_%s.png",outputDir.Data(), mH_,selection_.c_str(),analysis_.Data(),variable_.Data())); + c1->SaveAs(Form(location+"/%s/plots/plot_tauTau_mH%d_%s_%s_%s.pdf",outputDir.Data(), mH_,selection_.c_str(),analysis_.Data(),variable_.Data())); + c1->SaveAs(Form(location+"/%s/plots/plot_tauTau_mH%d_%s_%s_%s.root",outputDir.Data(), mH_,selection_.c_str(),analysis_.Data(),variable_.Data())); + } + + TH1F* hDataBlind = 0; + TH1F* hRatioBlind = 0; + + // Plot blinded histogram + if(variable_.Contains("Mass")) { + + if(MSSM) { + hDataBlind = blindHistogram(hData, 100, 2000, "hDataBlind"); + hRatioBlind = blindHistogram(hRatio, 100, 2000, "hRatioBlind"); + } + else{ + hDataBlind = blindHistogram(hData, 100, 160, "hDataBlind"); + hRatioBlind = blindHistogram(hRatio, 100, 160, "hRatioBlind"); + } + + c1 = new TCanvas("c2","",5,30,650,600); + c1->SetGrid(0,0); + c1->SetFillStyle(4000); + c1->SetFillColor(10); + c1->SetTicky(); + c1->SetObjectStat(0); + c1->SetLogy(logy_); + + pad1 = new TPad("pad2_1DEta","",0.05,0.22,0.96,0.97); + pad2 = new TPad("pad2_2DEta","",0.05,0.02,0.96,0.20); + + pad1->SetFillColor(0); + pad2->SetFillColor(0); + pad1->Draw(); + pad2->Draw(); + + pad1->cd(); + pad1->SetLogy(logy_); + gStyle->SetOptStat(0); + gStyle->SetTitleFillColor(0); + gStyle->SetCanvasBorderMode(0); + gStyle->SetCanvasColor(0); + gStyle->SetPadBorderMode(0); + gStyle->SetPadColor(0); + gStyle->SetTitleFillColor(0); + gStyle->SetTitleBorderSize(0); + gStyle->SetTitleH(0.07); + gStyle->SetTitleFontSize(0.1); + gStyle->SetTitleStyle(0); + gStyle->SetTitleOffset(1.3,"y"); + + hDataBlind->Draw("P"); + aStack->Draw("HISTSAME"); + hDataBlind->Draw("PSAME"); + if(logy_ && !MSSM) hSgn->Draw("HISTSAME"); + //if(logy_ && MSSM) hSgnSUSY->Draw("HISTSAME"); + leg->Draw(); + + pad2->cd(); + gStyle->SetOptStat(0); + gStyle->SetTitleFillColor(0); + gStyle->SetCanvasBorderMode(0); + gStyle->SetCanvasColor(0); + gStyle->SetPadBorderMode(0); + gStyle->SetPadColor(0); + gStyle->SetTitleFillColor(0); + gStyle->SetTitleBorderSize(0); + gStyle->SetTitleH(0.07); + gStyle->SetTitleFontSize(0.1); + gStyle->SetTitleStyle(0); + gStyle->SetTitleOffset(1.3,"y"); + + hRatioBlind->Draw("P"); + + if(logy_){ + c1->SaveAs(Form(location+"/%s/plots/plot_tauTau_mH%d_%s_%s_%s_blind_log.png",outputDir.Data(), mH_,selection_.c_str(),analysis_.Data(),variable_.Data())); + c1->SaveAs(Form(location+"/%s/plots/plot_tauTau_mH%d_%s_%s_%s_blind_log.pdf",outputDir.Data(), mH_,selection_.c_str(),analysis_.Data(),variable_.Data())); + c1->SaveAs(Form(location+"/%s/plots/plot_tauTau_mH%d_%s_%s_%s_blind_log.root",outputDir.Data(), mH_,selection_.c_str(),analysis_.Data(),variable_.Data())); + } + else{ + c1->SaveAs(Form(location+"/%s/plots/plot_tauTau_mH%d_%s_%s_%s_blind.png",outputDir.Data(), mH_,selection_.c_str(),analysis_.Data(),variable_.Data())); + c1->SaveAs(Form(location+"/%s/plots/plot_tauTau_mH%d_%s_%s_%s_blind.pdf",outputDir.Data(), mH_,selection_.c_str(),analysis_.Data(),variable_.Data())); + c1->SaveAs(Form(location+"/%s/plots/plot_tauTau_mH%d_%s_%s_%s_blind.root",outputDir.Data(), mH_,selection_.c_str(),analysis_.Data(),variable_.Data())); + } + } + + // templates for fitting + TFile* fout = new TFile(Form(location+"/%s/histograms/tauTau_mH%d_%s_%s_%s.root",outputDir.Data(), mH_,selection_.c_str(),analysis_.Data(),variable_.Data()),"RECREATE"); + fout->cd(); + + hSiml->Write(); + hQCD->Write(); + hSS->Write(); + hZj->Write(); + hZfakes->Write(); + hTTb->Write(); + hTTbUp->Write(); + hTTbDown->Write(); + hZtt->Write(); + hZttEmb->Write(); + hW->Write(); + hVV->Write(); + hEWK->Write(); + hSgn1->Write(); + hSgn2->Write(); + hSgn3->Write(); + hDataAntiTauIsoQCD->Write(); + hData->Write(); + hParameters->Write(); + + //fine binning histograms for MSSM + hZttEmb_fb->Write(); hW_fb->Write(); hZtt_fb->Write(); + hZj_fb->Write(); hTTb_fb->Write(); + hQCD_fb->Write(); hVV_fb->Write(); + /* + for(int iP=0 ; iPWrite(); + for(int iM=0 ; iMWrite(); + hGGFHDown[iM]->Write(); + } + for(int iP=0 ; iPWrite(); + */ + if(MSSM) { + for(int iP=0 ; iPWrite(); + } + + for(int iM=0 ; iMWrite(); + hSUSYGGHDown[iM]->Write(); + } + } + + if(variable_.Contains("Mass")) hDataBlind->Write(); + + fout->Write(); + fout->Close(); + std::cout<<" before deleting histograms"<Close(); + delete signal[iP][iM]; + } + } + for(int iP=0 ; iP variables; + vector mH; + + variables.push_back("diTauVisMass"); + variables.push_back("diTauNSVfitMass"); + + mH.push_back(125); + + //plotTauTau(125,0,"inclusive","" ,"decayModeL1", "#tau_{1} decay mode","units" ,outputDir,10,0,10, 5.0,0,1.4); + //plotTauTau(125,0,"inclusive","" ,"visibleTauMassL1","visible #tau_{1} mass","GeV" ,outputDir,40,0,2,5.0,0,1.2); + //plotTauTau(125,0,"inclusive","" ,"decayModeL2", "#tau_{2} decay mode","units" ,outputDir,10,0,10, 5.0,0,1.4); + //plotTauTau(125,0,"inclusive","" ,"visibleTauMassL2","visible #tau_{2} mass","GeV" ,outputDir,40,0,2,5.0,0,1.2); + //plotTauTau(125,0,"inclusive","" ,"MEtMVA","E_{T}^{miss} MVA","GeV" ,outputDir,40,0,100,5.0,0,1.2); + //plotTauTau(125,0,"inclusive","" ,"MEtMVAPhi","E_{T}^{miss} MVA #phi","units" ,outputDir,32,-3.2,3.2, 5.0,0,1.5); + //plotTauTau(125,0,"inclusive","" ,"MtLeg1MVA","M_{T}(#tau_{1}#nu) MVA","GeV" , outputDir,40,0,160,5.0,0,1.2); + //plotTauTau(125,0,"inclusive","" ,"MtLeg2MVA","M_{T}(#tau_{2}#nu) MVA","GeV" , outputDir,40,0,160,5.0,0,1.2); + //plotTauTau(125,0,"inclusive","" ,"MEt","E_{T}^{miss} ","GeV" ,outputDir,40,0,100,5.0,0,1.2); + //plotTauTau(125,0,"inclusive","" ,"MEtPhi","E_{T}^{miss} #phi","units" ,outputDir,32,-3.2,3.2, 5.0,0,1.5); + //plotTauTau(125,0,"inclusive","" ,"MtLeg1","M_{T}(#tau_{1}#nu) ","GeV" , outputDir,40,0,160,5.0,0,1.2); + //plotTauTau(125,0,"inclusive","" ,"MtLeg2","M_{T}(#tau_{2}#nu) ","GeV" , outputDir,40,0,160,5.0,0,1.2); + //plotTauTau(125,0,"inclusive","" ,"diTauVisMass","visible mass","GeV" ,outputDir,50,0,200,5.0,0,1.2); + ////plotTauTau(125,0,"inclusive","" ,"diTauNSVfitMass","SVfit mass","GeV" ,outputDir,60,0,360,5.0,0,1.2); + //plotTauTau(125,0,"inclusive","" ,"etaL1","#tau_{1} #eta", "units" ,outputDir,25,-2.5, 2.5,5.0,0,2.); + //plotTauTau(125,0,"inclusive","" ,"ptL1","#tau_{1} p_{T}", "GeV" ,outputDir,20,40, 140,5.0,0,1.2); + //plotTauTau(125,0,"inclusive","" ,"ptL2","#tau_{2} p_{T}","GeV" ,outputDir,20,40, 140,5.0,0,1.2); + //plotTauTau(125,0,"inclusive","" ,"etaL2","#tau_{2} #eta","units" ,outputDir,25,-2.5, 2.5,5.0,0,2.); + //plotTauTau(125,0,"inclusive","" ,"numPV","reconstructed vertexes","units" ,outputDir,30,0,30,5.0,0,1.5); + //plotTauTau(125,0,"inclusive","" ,"nJets30","jet multiplicity","units" ,outputDir,10,0, 10,5.0,1,10); + //plotTauTau(125,0,"oneJet","" ,"ptj1", "leading jet p_{T}","GeV" ,outputDir,50,30, 330,5.0,1,100); + //plotTauTau(125,0,"oneJet","" ,"etaj1","leading jet #eta","units" ,outputDir,21,-5, 5,5.0,0,2.); + plotTauTau(125,0,"bTag","" ,"ptB1", "leading b-tagged jet p_{T}","GeV" ,outputDir,50,30, 330,5.0,1,10); + //plotTauTau(125,0,"bTag","" ,"etaB1","leading b-tagged jet #eta","units" ,outputDir,21,-5, 5,5.0,0,2.); + + return; + /* + for(unsigned int i = 0 ; i < variables.size(); i++){ + for(unsigned j = 0; j < mH.size(); j++){ + + plotTauTau(mH[j],useEmbedded,"inclusive","" ,variables[i],"mass","GeV",outputDir,-1,0,100,1.0,1.0,1.2); + plotTauTau(mH[j],useEmbedded,"inclusive","TauUp" ,variables[i],"mass","GeV",outputDir,-1,0,100,1.0,1.0,1.2); + plotTauTau(mH[j],useEmbedded,"inclusive","TauDown",variables[i],"mass","GeV",outputDir,-1,0,100,1.0,1.0,1.2); + + plotTauTau(mH[j],useEmbedded,"oneJetLow","" ,variables[i],"mass","GeV",outputDir,-1,0,100,1.0,1.0,1.2); + plotTauTau(mH[j],useEmbedded,"oneJetLow","TauUp" ,variables[i],"mass","GeV",outputDir,-1,0,100,1.0,1.0,1.2); + plotTauTau(mH[j],useEmbedded,"oneJetLow","TauDown",variables[i],"mass","GeV",outputDir,-1,0,100,1.0,1.0,1.2); + + plotTauTau(mH[j],useEmbedded,"oneJetHigh","" ,variables[i],"mass","GeV",outputDir,-1,0,100,1.0,1.0,1.2); + plotTauTau(mH[j],useEmbedded,"oneJetHigh","TauUp" ,variables[i],"mass","GeV",outputDir,-1,0,100,1.0,1.0,1.2); + plotTauTau(mH[j],useEmbedded,"oneJetHigh","TauDown",variables[i],"mass","GeV",outputDir,-1,0,100,1.0,1.0,1.2); + + plotTauTau(mH[j],useEmbedded,"vbf","" ,variables[i],"mass","GeV",outputDir,-1,0,100,1.0,1.0,1.2); + plotTauTau(mH[j],useEmbedded,"vbf","TauUp" ,variables[i],"mass","GeV",outputDir,-1,0,100,1.0,1.0,1.2); + plotTauTau(mH[j],useEmbedded,"vbf","TauDown",variables[i],"mass","GeV",outputDir,-1,0,100,1.0,1.0,1.2); + } + } + + return; + */ +} + +int main(int argc, const char* argv[]) +{ + + std::cout << "plotTauTau()" << std::endl; + gROOT->SetBatch(true); + + gSystem->Load("libFWCoreFWLite"); + AutoLibraryLoader::enable(); + + int mH, nBins, logy, useEmb; + float magnify, hltEff, xMin, xMax, maxY; + float antiWsgn, antiWsdb; + string category, analysis, variable, xtitle, unity, outputDir, version; + + if(argc==1) plotTauTauAll(); + // else if(argc==20) { + else if(argc>14) { + + mH = (int)atof(argv[1]); + category = argv[2]; + variable = argv[3]; + xtitle = argv[4]; + unity = argv[5]; + nBins = (int)atof(argv[6]); + xMin = atof(argv[7]); + xMax = atof(argv[8]); + magnify = atof(argv[9]); + logy = (int)atof(argv[10]); + maxY = atof(argv[11]) ; + outputDir = argv[12]; + version = argv[13]; + useEmb = (int)atof(argv[14]); + analysis = argc>15 ? argv[15] : ""; + // antiWsgn = atof(argv[17]); + // antiWsdb = atof(argv[18]); + cout << endl << " VERSION : " << version << " | ANALYSIS : " << analysis << endl << endl; + + // plotTauTau(mH,useEmb,category,analysis,variable,xtitle,unity,outputDir,nBins,xMin,xMax,magnify,hltEff,logy,maxY, version,antiWsgn,antiWsdb); + plotTauTau(mH,useEmb,category,analysis,variable,xtitle,unity,outputDir,nBins,xMin,xMax,magnify,logy,maxY, version); + } + else { cout << "Please put at least 14 arguments" << endl; return 1;} + + cout << "DONE" << endl; + return 0; +} + diff --git a/DesyTauAnalyses/NTupleMaker/bin/preAnalyzerTauTau_Batch_Summer15.py b/DesyTauAnalyses/NTupleMaker/bin/preAnalyzerTauTau_Batch_Summer15.py index c40903c..2a24532 100644 --- a/DesyTauAnalyses/NTupleMaker/bin/preAnalyzerTauTau_Batch_Summer15.py +++ b/DesyTauAnalyses/NTupleMaker/bin/preAnalyzerTauTau_Batch_Summer15.py @@ -84,6 +84,7 @@ def preAnalyze( ana, sample, runInSeries=False): ########################################### ########################################### ##Data +preAnalyze("nominal","Run2015B-Data_TauTau",True) ##Signal #preAnalyze("nominal","GGFH125",False) @@ -95,13 +96,13 @@ def preAnalyze( ana, sample, runInSeries=False): #preAnalyze("nominal","DYJets_TauTau",True) #preAnalyze("nominal","WJetsToLNu",True) #preAnalyze("nominal","TTJets",True) -preAnalyze("nominal","SingleTop_t",True) -preAnalyze("nominal","SingleAntiTop_t",True) -preAnalyze("nominal","SingleTop_tW",True) -preAnalyze("nominal","SingleAntiTop_tW",True) -preAnalyze("nominal","WWTo2L2Nu",True) -preAnalyze("nominal","WWTo4Q",True) -preAnalyze("nominal","WWToLNuQQ",True) -preAnalyze("nominal","WZTo1L1Nu2Q",True) -preAnalyze("nominal","WZTo3LNu",True) -preAnalyze("nominal","ZZ",True) +#preAnalyze("nominal","SingleTop_t",True) +##preAnalyze("nominal","SingleAntiTop_t",True) +#preAnalyze("nominal","SingleTop_tW",True) +#preAnalyze("nominal","SingleAntiTop_tW",True) +##preAnalyze("nominal","WWTo2L2Nu",True) +##preAnalyze("nominal","WWTo4Q",True) +##preAnalyze("nominal","WWToLNuQQ",True) +##preAnalyze("nominal","WZTo1L1Nu2Q",True) +##preAnalyze("nominal","WZTo3LNu",True) +##preAnalyze("nominal","ZZ",True) diff --git a/DesyTauAnalyses/NTupleMaker/bin/preAnalyzerTauTau_Summer15.cc b/DesyTauAnalyses/NTupleMaker/bin/preAnalyzerTauTau_Summer15.cc index cb2261a..1c1da1c 100644 --- a/DesyTauAnalyses/NTupleMaker/bin/preAnalyzerTauTau_Summer15.cc +++ b/DesyTauAnalyses/NTupleMaker/bin/preAnalyzerTauTau_Summer15.cc @@ -30,7 +30,7 @@ //#include "TauAnalysis/CandidateTools/interface/candidateAuxFunctions.h" //#include "TauAnalysis/CandidateTools/interface/neuralMtautauAuxFunctions.h" //#include "BtagSF.hh" -//#include "LLRAnalysis/Utilities/interface/readJSONFile.h" +#include "readJSONFile.h" #include "Math/Vector3D.h" #include "Math/Vector4D.h" @@ -98,8 +98,9 @@ typedef ROOT::Math::LorentzVector > LV; //"/nfs/dust/cms/user/anayak/CMS/MyHTTAnalysis/data/Data_Pileup_2012_ReRecoPixel-600bins.root","pileup","pileup"); //RecoilCorrector *RecoilCorrector_; - -enum MCEVENTTYPE{HTTHADHAD, HTTLEPHAD, HTTLEPLEP, HLL, ZTTHADHAD, ZTTLEPHAD, ZTTLEPLEP, ZLL, WLNU, WTAULEP, WTAUHAD, UNKNOWN}; +enum MotherNames{HIGGS=1, WBOSON, ZBOSON, TAU}; +enum MvaMetChannel{EMU=1, ETAU, MUTAU, TAUTAU, UNKNOWN}; +enum MCEVENTTYPE{HADHAD, LEPHAD, LEPLEP, LL, LNU, LEPNU, TAUNU, OTHERS}; enum BVariation{kNo = 0, kDown = 1, kUp = 2}; //BtagSF* btsf = new BtagSF(12345); @@ -493,14 +494,14 @@ void fillTrees_TauTauStream(TChain* currentTree, float genparticles_e[1000], genparticles_px[1000], genparticles_py[1000],genparticles_pz[1000], genparticles_vx[1000], genparticles_vy[1000], genparticles_vz[1000]; Int_t genparticles_pdgid[1000], genparticles_status[1000]; - Char_t genparticles_mother[1000]; + UChar_t genparticles_mother[1000]; UInt_t gentau_count; float gentau_e[20], gentau_px[20], gentau_py[20], gentau_pz[20], gentau_visible_e[20], gentau_visible_px[20], gentau_visible_py[20], gentau_visible_pz[20]; int gentau_decayMode[20]; - Char_t gentau_mother[20]; + UChar_t gentau_mother[20]; std::vector *hltriggerresultsV = new std::vector (); std::vector *run_hltfilters = new std::vector(); @@ -879,6 +880,8 @@ void fillTrees_TauTauStream(TChain* currentTree, //event weights float evtweight, mcweight, puweight; + //clasify DY events for splitting + bool isZtt_, isZll_, isZj_; outTree->Branch("ptj1", &ptj1,"ptj1/F"); outTree->Branch("ptj2", &ptj2,"ptj2/F"); @@ -1048,16 +1051,36 @@ void fillTrees_TauTauStream(TChain* currentTree, outTree->Branch("weight", &evtweight, "weight/F"); outTree->Branch("mcweight", &mcweight,"mcweight/F"); outTree->Branch("puweight", &puweight, "puweight/F"); + outTree->Branch("isZtt", &isZtt_, "isZtt/O"); + outTree->Branch("isZll", &isZll_, "isZll/O"); + outTree->Branch("isZj", &isZj_, "isZj/O"); + // define JSON selector // + cout << "JSON selection" << endl; + int nJson=1; + string jsonFile[nJson]; + string dirJson = "/nfs/dust/cms/user/anayak/CMS/OnSLC6/CMSSW_746p6_htt/src/DesyTauAnalyses/NTupleMaker/test/"; + jsonFile[0] = dirJson+"/Cert_246908-251883_13TeV_PromptReco_Collisions15_JSON.txt"; // promptReco + map > > jsonMap[nJson] ; + for(int iJ=0 ; iJGetEntries() ; float crossSection = xsec_; //float scaleFactor = (crossSection != 0) ? Lumi / ( float(nEventsRead)/(crossSection*skimEff_) ) : 1.0; //first loop over the whole events once to get the total sum of gen weights for normalization float totalGenWeight_ = 0; - for(int n = 0 ; n < nEntries ; n++) { - currentTree->GetEntry(n); - - totalGenWeight_ += genweight; + if(!isData){ + for(int n = 0 ; n < nEntries ; n++) { + currentTree->GetEntry(n); + + totalGenWeight_ += genweight; + } } float scaleFactor = (crossSection != 0) ? (Lumi*crossSection) / float(totalGenWeight_) : 1.0; @@ -1074,29 +1097,34 @@ void fillTrees_TauTauStream(TChain* currentTree, //cout<<"n1 = "< scaleFactor " << scaleFactor << endl; //bool dyFinalState=false; - bool isData = sample.Contains("2012"); /////////////////////// // LOOP OVER ENTRIES // /////////////////////// for(int n = n1 ; n < n2 ; n++) { - //for(int n = n1 ; n < 10000 ; n++) { + //for(int n = n1 ; n < 1000 ; n++) { // cout<<"n/n2 = "<GetEntry(n); if(n%1000==0) cout << n <<"/"<<(n2-n1)<< endl; // if(n%1000==0) cout << n <<"/"<=0) + isGoodRun = AcceptEventByRunAndLumiSection(event_run, event_luminosityblock, jsonMap[iJson_]); + + if(!isGoodRun) continue; + //cut on PV if(primvertex_count <= 0)continue; if(primvertex_ndof < 4)continue; @@ -1115,19 +1143,16 @@ void fillTrees_TauTauStream(TChain* currentTree, rho_ = rhoNeutral; // Get Gen boson and daughters to clasify the event - //char genVName_; - LV genVP4_(0, 0, 0, 0); + LV genVP4_(0, 0, 0, 0); unsigned int genVType_ = 100; std::vector genLeptonP4_; genLeptonP4_.clear(); std::vector genTauP4_; genTauP4_.clear(); std::vector genTauVisP4_; genTauVisP4_.clear(); std::vectorgenLeptonPdgId_; genLeptonPdgId_.clear(); - int nLepton_ = 0, TauLepDecay_ = 0; + int nLepton_ = 0, TauLepDecay_ = 0, TauHadDecay_ = 0; if(!isData){ //for mc only if( (sample_.find("WJets")!=string::npos && sample_.find("WWJets")==string::npos ) || - sample_.find("W1Jets")!=string::npos || sample_.find("W2Jets")!=string::npos || - sample_.find("W3Jets")!=string::npos || sample_.find("W4Jets")!=string::npos || sample_.find("DYJets")!=string::npos || sample_.find("HToTauTau")!=string::npos || sample_.find("SUSYGGH")!=string::npos || sample_.find("SUSYBBH")!=string::npos || sample_.find("GGFH")!=string::npos || sample_.find("VBFH")!=string::npos @@ -1136,64 +1161,46 @@ void fillTrees_TauTauStream(TChain* currentTree, for(unsigned int ig = 0; ig < genparticles_count; ig++){ int GenPdgId = genparticles_pdgid[ig]; - //int GenStatus = genparticles_status[ig]; - if(fabs(GenPdgId) == 11 || fabs(GenPdgId) == 13) { + int GenStatus = genparticles_status[ig]; + if(GenStatus == 1 && (fabs(GenPdgId) == 11 || fabs(GenPdgId) == 13)) { - if(strcmp(&(genparticles_mother[ig]), "W") == 0 || strcmp(&(genparticles_mother[ig]), "Z") == 0 || strcmp(&(genparticles_mother[ig]), "H") == 0){ - genLeptonP4_.push_back(LV(genparticles_px[ig], genparticles_py[ig], genparticles_pz[ig], genparticles_e[ig])); - genLeptonPdgId_.push_back(GenPdgId); - nLepton_++; - //genVName_ = genparticles_mother[ig]; - } + genLeptonP4_.push_back(LV(genparticles_px[ig], genparticles_py[ig], genparticles_pz[ig], genparticles_e[ig])); + genLeptonPdgId_.push_back(GenPdgId); + nLepton_++; + if(genparticles_mother[ig] == WBOSON || genparticles_mother[ig] == ZBOSON || genparticles_mother[ig] == HIGGS) + genVType_ = genparticles_mother[ig]; } } for(unsigned int ig = 0; ig < gentau_count; ig++){ - if(strcmp(&(gentau_mother[ig]), "W") == 0 || strcmp(&(gentau_mother[ig]), "Z") == 0 || strcmp(&(gentau_mother[ig]), "H") == 0){ - genTauP4_.push_back(LV(gentau_px[ig], gentau_py[ig], gentau_pz[ig], gentau_e[ig])); - genTauVisP4_.push_back(LV(gentau_visible_px[ig], gentau_visible_py[ig], gentau_visible_pz[ig], gentau_visible_e[ig])); - //genVName_ =gentau_mother[ig]; - if(gentau_decayMode[ig] == 8 || gentau_decayMode[ig] == 9){ - TauLepDecay_++; - } - } + genTauP4_.push_back(LV(gentau_px[ig], gentau_py[ig], gentau_pz[ig], gentau_e[ig])); + genTauVisP4_.push_back(LV(gentau_visible_px[ig], gentau_visible_py[ig], gentau_visible_pz[ig], gentau_visible_e[ig])); + if(gentau_decayMode[ig] == 8 || gentau_decayMode[ig] == 9) + TauLepDecay_++; + else TauHadDecay_++; + if(gentau_mother[ig] == WBOSON || gentau_mother[ig] == ZBOSON || gentau_mother[ig] == HIGGS) + genVType_ = gentau_mother[ig]; } } }//end of MCInfo - //Classify event - /* - int EventType_ = UNKNOWN; - if(strcmp(&genVName_, "H") == 0){ - if(nLepton_ >= 2) - EventType_ = HLL; - else if(TauLepDecay_ >= 2) - EventType_ = HTTLEPLEP; - else if(TauLepDecay_ == 1 && genTauVisP4_.size() >= 2 ) - EventType_ = HTTLEPHAD; - else if(TauLepDecay_ == 0 && genTauVisP4_.size() >= 2 ) - EventType_ = HTTHADHAD; - } - else if(strcmp(&genVName_, "Z") == 0){ - if(nLepton_ >= 2) - EventType_ = ZLL; - else if(TauLepDecay_ >= 2) - EventType_ = ZTTLEPLEP; - else if(TauLepDecay_ == 1 && genTauVisP4_.size() >= 2 ) - EventType_ = ZTTLEPHAD; - else if(TauLepDecay_ == 0 && genTauVisP4_.size() >= 2 ) - EventType_ = ZTTHADHAD; - } - else if(strcmp(&genVName_, "W") == 0){ - if(nLepton_ >= 1) - EventType_ = WLNU; - else if(TauLepDecay_ >= 1) - EventType_ = WTAULEP; - else if(TauLepDecay_ == 0 && genTauVisP4_.size() >= 1 ) - EventType_ = WTAUHAD; - } - */ + //Classify event, HADHAD, LEPHAD, LEPLEP, LL, LNU, LEPNU, TAUNU, OTHERS + int EventType_ = OTHERS; + if(nLepton_ >= 2 && TauLepDecay_ == 0 && TauHadDecay_<=1) + EventType_ = LL; + else if (nLepton_ >= 1 && TauLepDecay_ == 0 && TauHadDecay_<=1) + EventType_ = LNU; + else if(TauLepDecay_ >= 2 && TauLepDecay_ == nLepton_ && TauHadDecay_<=1) + EventType_ = LEPLEP; + else if(TauLepDecay_ == 1 && TauLepDecay_ == nLepton_ && TauHadDecay_ == 0) + EventType_ = LEPNU; + else if(TauLepDecay_ == 1 && TauHadDecay_ >= 1 ) + EventType_ = LEPHAD; + else if(TauLepDecay_ == 0 && TauHadDecay_ >= 2 ) + EventType_ = HADHAD; + else if(TauLepDecay_ == 0 && nLepton_ == 0 && TauHadDecay_ == 1) + EventType_ = TAUNU; //require HLT if(GetTriggerResult((*hltriggerresultsV), "HLT_DoubleMediumIsoPFTau40_Trk1_eta2p1_Reg_v") < 0.5) continue; @@ -1664,6 +1671,23 @@ void fillTrees_TauTauStream(TChain* currentTree, HLTmatchL1 = matchLeg1Level3_; //(matchLeg1Level1_ && matchLeg1Level2_ && matchLeg1Level3_); HLTmatchL2 = matchLeg2Level3_; //(matchLeg2Level1_ && matchLeg2Level2_ && matchLeg2Level3_); + + //Define MC DY event type (used to split DY events) + isZtt_=false; isZll_=false; isZj_=false; + if(sample_.find("DYJets") != std::string::npos){ + //std::cout<<"sample "<= 1 || TauLepDecay_ >= 1){ + bool matchl1gen_ = false, matchl2gen_ = false; + for(size_t l = 0; l < genLeptonP4_.size(); l++){ + if(deltaR(Leg1P4_, genLeptonP4_[l]) < 0.5)matchl1gen_ = true; + if(deltaR(Leg2P4_, genLeptonP4_[l]) < 0.5)matchl2gen_ = true; + } + if(matchl1gen_ && matchl2gen_) isZll_ = true; + } + if(!isZtt_ && !isZll_)isZj_ = true; + } + pairIndex = -1; if(HLTx && HLTmatchL1 && HLTmatchL2){ diTauCounter++; diff --git a/DesyTauAnalyses/NTupleMaker/bin/preAnalyzerTauTau_Summer15.py b/DesyTauAnalyses/NTupleMaker/bin/preAnalyzerTauTau_Summer15.py index 4c183a1..a03fa0a 100644 --- a/DesyTauAnalyses/NTupleMaker/bin/preAnalyzerTauTau_Summer15.py +++ b/DesyTauAnalyses/NTupleMaker/bin/preAnalyzerTauTau_Summer15.py @@ -8,21 +8,26 @@ #WorkdirLoc = '/nfs/dust/cms/user/anayak/CMS/Ntuple_HttAnalysis/Sync2015/' #WorkdirLoc = '/nfs/dust/cms/user/rasp/ntuples/' -WorkdirLoc = '/nfs/dust/cms/group/susy-desy/Run2/MC/Stau/MC_Spring15_25ns_v1/' -OutDir = '/nfs/dust/cms/user/anayak/CMS/Ntuple_HttAnalysis/ntuples74/' +#WorkdirLoc = '/nfs/dust/cms/group/susy-desy/Run2/MC/Stau/MC_Spring15_25ns_v1/' +#OutDir = '/nfs/dust/cms/user/anayak/CMS/Ntuple_HttAnalysis/ntuples74/' +WorkdirData = '/nfs/dust/cms/group/susy-desy/Run2/Stau/Data/50ns/v2/' +WorkdirLoc = '/nfs/dust/cms/group/susy-desy/Run2/MC/Stau/MC_Spring15_50ns_v1/' +OutDir = '/nfs/dust/cms/user/anayak/CMS/Ntuple_HttAnalysis/ntuples74_50ns/' options = { - ###mu+tau samples + ###tau+tau samples - ##DATA -# 'Run2012A-22Jan2013-Data' : { -# 'inputFilePath' : WorkdirLoc+'Data/Data_2012A_ReReco22Jan_HTT_25July2013_Trees_MuTau_v1/', -# 'outputFileName' : OutDir+'nTupleRun2012A-22Jan2013-Data.root', -# 'sample' : 'Run2012A-22Jan2013-Data', -# 'xSection' : 0, -# 'skimEff' : 0, -# 'iJson' : 7 -# }, + ##DATA + 'Run2015B-Data_TauTau' : { + 'inputFilePath' : WorkdirData+'Tau/', + 'outputFileName' : OutDir+'nTupleRun2015B-Data.root', + 'sample' : 'Run2015B-Data', + 'xSection' : 0, + 'skimEff' : 0, + 'iJson' : 0, + 'iDiv' : 0, + 'nDiv' : 1 + }, ##Bkg MC 'DYJets_TauTau' : { 'inputFilePath' : WorkdirLoc+'DYJetsToLL_M-50/', @@ -35,17 +40,19 @@ 'nDiv' : 1 }, 'WJetsToLNu' : { - 'inputFilePath' : WorkdirLoc+'WJetsToLNu/', + #'inputFilePath' : WorkdirLoc+'WJetsToLNu/', + 'inputFilePath' : WorkdirLoc+'WJets/', 'outputFileName' : OutDir+'nTupleWJets_TauTau.root', 'sample' : 'WJets_TauTau', - 'xSection' : 20509, + 'xSection' : 61526.7, 'skimEff' : 1.0, 'iJson' : -1, 'iDiv' : 0, 'nDiv' : 1 }, 'TTJets' : { - 'inputFilePath' : WorkdirLoc+'TTJets_amatnlo/', + #'inputFilePath' : WorkdirLoc+'TTJets_amatnlo/', + 'inputFilePath' : WorkdirLoc+'TTJets/', 'outputFileName' : OutDir+'nTupleTTJets_TauTau.root', 'sample' : 'TTJets_TauTau', 'xSection' : 831.76, @@ -64,16 +71,16 @@ 'iDiv' : 0, 'nDiv' : 1 }, - 'SingleAntiTop_t' : { - 'inputFilePath' : WorkdirLoc+'ST_t-channel_antitop/', - 'outputFileName' : OutDir+'nTupleSAntiTopT_TauTau.root', - 'sample' : 'SAntiTopT_TauTau', - 'xSection' : 80.97*0.108*3, - 'skimEff' : 1.0, - 'iJson' : -1, - 'iDiv' : 0, - 'nDiv' : 1 - }, + #'SingleAntiTop_t' : { + #'inputFilePath' : WorkdirLoc+'ST_t-channel_antitop/', + #'outputFileName' : OutDir+'nTupleSAntiTopT_TauTau.root', + #'sample' : 'SAntiTopT_TauTau', + #'xSection' : 80.97*0.108*3, + #'skimEff' : 1.0, + #'iJson' : -1, + #'iDiv' : 0, + #'nDiv' : 1 + #}, 'SingleTop_tW' : { 'inputFilePath' : WorkdirLoc+'ST_tW_top/', 'outputFileName' : OutDir+'nTupleSTopTW_TauTau.root', @@ -94,66 +101,66 @@ 'iDiv' : 0, 'nDiv' : 1 }, - 'WWTo2L2Nu' : { - 'inputFilePath' : WorkdirLoc+'WWTo2L2Nu/', - 'outputFileName' : OutDir+'nTupleWWTo2L2Nu_TauTau.root', - 'sample' : 'WWTo2L2Nu_TauTau', - 'xSection' : 10.481, - 'skimEff' : 1.0, - 'iJson' : -1, - 'iDiv' : 0, - 'nDiv' : 1 - }, - 'WWTo4Q' : { - 'inputFilePath' : WorkdirLoc+'WWTo4Q/', - 'outputFileName' : OutDir+'nTupleWWTo4Q_TauTau.root', - 'sample' : 'WWTo4Q_TauTau', - 'xSection' : 45.20, - 'skimEff' : 1.0, - 'iJson' : -1, - 'iDiv' : 0, - 'nDiv' : 1 - }, - 'WWToLNuQQ' : { - 'inputFilePath' : WorkdirLoc+'WWToLNuQQ/', - 'outputFileName' : OutDir+'nTupleWWToLNuQQ_TauTau.root', - 'sample' : 'WWToLNuQQ_TauTau', - 'xSection' : 43.53, - 'skimEff' : 1.0, - 'iJson' : -1, - 'iDiv' : 0, - 'nDiv' : 1 - }, - 'WZTo1L1Nu2Q' : { - 'inputFilePath' : WorkdirLoc+'WZTo1L1Nu2Q/', - 'outputFileName' : OutDir+'nTupleWZTo1L1Nu2Q_TauTau.root', - 'sample' : 'WZTo1L1Nu2Q_TauTau', - 'xSection' : 10.96, - 'skimEff' : 1.0, - 'iJson' : -1, - 'iDiv' : 0, - 'nDiv' : 1 - }, - 'WZTo3LNu' : { - 'inputFilePath' : WorkdirLoc+'WZTo3LNu/', - 'outputFileName' : OutDir+'nTupleWZTo3LNu_TauTau.root', - 'sample' : 'WZTo3LNu_TauTau', - 'xSection' : 4.42965, - 'skimEff' : 1.0, - 'iJson' : -1, - 'iDiv' : 0, - 'nDiv' : 1 - }, - 'ZZ' : { - 'inputFilePath' : WorkdirLoc+'ZZ/', - 'outputFileName' : OutDir+'nTupleZZ_TauTau.root', - 'sample' : 'ZZ_TauTau', - 'xSection' : 10.32, - 'skimEff' : 1.0, - 'iJson' : -1, - 'iDiv' : 0, - 'nDiv' : 1 - }, + #'WWTo2L2Nu' : { + #'inputFilePath' : WorkdirLoc+'WWTo2L2Nu/', + #'outputFileName' : OutDir+'nTupleWWTo2L2Nu_TauTau.root', + #'sample' : 'WWTo2L2Nu_TauTau', + #'xSection' : 10.481, + #'skimEff' : 1.0, + #'iJson' : -1, + #'iDiv' : 0, + #'nDiv' : 1 + #}, + #'WWTo4Q' : { + #'inputFilePath' : WorkdirLoc+'WWTo4Q/', + #'outputFileName' : OutDir+'nTupleWWTo4Q_TauTau.root', + #'sample' : 'WWTo4Q_TauTau', + #'xSection' : 45.20, + #'skimEff' : 1.0, + #'iJson' : -1, + #'iDiv' : 0, + #'nDiv' : 1 + #}, + #'WWToLNuQQ' : { + #'inputFilePath' : WorkdirLoc+'WWToLNuQQ/', + #'outputFileName' : OutDir+'nTupleWWToLNuQQ_TauTau.root', + #'sample' : 'WWToLNuQQ_TauTau', + #'xSection' : 43.53, + #'skimEff' : 1.0, + #'iJson' : -1, + #'iDiv' : 0, + #'nDiv' : 1 + #}, + #'WZTo1L1Nu2Q' : { + #'inputFilePath' : WorkdirLoc+'WZTo1L1Nu2Q/', + #'outputFileName' : OutDir+'nTupleWZTo1L1Nu2Q_TauTau.root', + #'sample' : 'WZTo1L1Nu2Q_TauTau', + #'xSection' : 10.96, + #'skimEff' : 1.0, + #'iJson' : -1, + #'iDiv' : 0, + #'nDiv' : 1 + #}, + #'WZTo3LNu' : { + #'inputFilePath' : WorkdirLoc+'WZTo3LNu/', + #'outputFileName' : OutDir+'nTupleWZTo3LNu_TauTau.root', + #'sample' : 'WZTo3LNu_TauTau', + #'xSection' : 4.42965, + #'skimEff' : 1.0, + #'iJson' : -1, + #'iDiv' : 0, + #'nDiv' : 1 + #}, + #'ZZ' : { + #'inputFilePath' : WorkdirLoc+'ZZ/', + #'outputFileName' : OutDir+'nTupleZZ_TauTau.root', + #'sample' : 'ZZ_TauTau', + #'xSection' : 10.32, + #'skimEff' : 1.0, + #'iJson' : -1, + #'iDiv' : 0, + #'nDiv' : 1 + #}, # ##Higgs MC # 'GGFH125' : { # 'inputFilePath' : WorkdirLoc+'HiggsSM/GluGluToHToTauTau_M-125_MC_TauTau_v2', @@ -188,16 +195,16 @@ # 'iDiv' : 0, # 'nDiv' : 1 # }, - 'SUSYBBH160' : { - 'inputFilePath' : WorkdirLoc+'SUSYGluGluToBBHToTauTau_M-160/', - 'outputFileName' : OutDir+'nTupleSUSYBBH160_TauTau.root', - 'sample' : 'SUSYGGH160', - 'xSection' : 1.0, - 'skimEff' : 1.0, - 'iJson' : -1, - 'iDiv' : 0, - 'nDiv' : 1 - }, +# 'SUSYBBH160' : { +# 'inputFilePath' : WorkdirLoc+'SUSYGluGluToBBHToTauTau_M-160/', +# 'outputFileName' : OutDir+'nTupleSUSYBBH160_TauTau.root', +# 'sample' : 'SUSYGGH160', +# 'xSection' : 1.0, +# 'skimEff' : 1.0, +# 'iJson' : -1, +# 'iDiv' : 0, +# 'nDiv' : 1 +# }, } config_template = string.Template(''' diff --git a/DesyTauAnalyses/NTupleMaker/bin/readJSONFile.h b/DesyTauAnalyses/NTupleMaker/bin/readJSONFile.h new file mode 100644 index 0000000..0b65b9d --- /dev/null +++ b/DesyTauAnalyses/NTupleMaker/bin/readJSONFile.h @@ -0,0 +1,100 @@ +#ifndef readJSONFile_h +#define readJSONFile_h + +#include +#include +#include +#include +#include +#include +#include + +std::map > > + readJSONFile(const std::string& inFileName) +{ + std::ifstream inFile(inFileName.c_str(), std::ios::in); + + std::string line; + while(!inFile.eof()) + { + std::string buffer; + inFile >> buffer; + line += buffer; + } + + // define map with result + std::map > > jsonMap; + + // loop on JSON file + for(std::string::const_iterator it = line.begin(); it < line.end(); ++it) + { + // find run number + if( (*(it) == '"') && (*(it+7) == '"') ) + { + std::string run(it+1, it+7); + //std::cout << "found run " << run << std::endl; + + // find lumi sections + std::vector > lumisections; + for(std::string::const_iterator it2 = it+10; it2 < line.end(); ++it2) + { + if( (*(it2) == ']') && (*(it2-1) == ']') ) break; + if( *(it2) != '[' ) continue; + + std::string::const_iterator it_beg = it2; + std::string::const_iterator it_mid; + std::string::const_iterator it_end; + + for(std::string::const_iterator it3 = it_beg; it3 < line.end(); ++it3) + { + if( *(it3) == ',' ) it_mid = it3; + if( *(it3) == ']' ) + { + it_end = it3; + break; + } + } + std::string lumi_beg(it_beg+1, it_mid); + std::string lumi_end(it_mid+1, it_end); + //std::cout << "[" << lumi_beg; + //std::cout << ","; + //std::cout << lumi_end << "]" << std::endl; + + std::pair tempLS(atoi(lumi_beg.c_str()), atoi(lumi_end.c_str())); + lumisections.push_back(tempLS); + + it2 = it_end; + } + + jsonMap[atoi(run.c_str())] = lumisections; + } // find run number + + } // loop on JSON file + + + + return jsonMap; +} + +bool AcceptEventByRunAndLumiSection(const int& runId, const int& lumiId, + std::map > >& jsonMap) +{ + // select by runId + if( jsonMap.find(runId) == jsonMap.end() ) return false; + + // select by lumiId + std::vector > lumisections = jsonMap[runId]; + + int skipEvent = true; + for(unsigned int i = 0; i < lumisections.size(); ++i) + if( (lumiId >= lumisections.at(i).first) && + (lumiId <= lumisections.at(i).second) ) + skipEvent = false; + + if( skipEvent == true ) return false; + + + return true; +} + +#endif From b544dfa79d3e9c80a8e871f8fba8c72cf744eef7 Mon Sep 17 00:00:00 2001 From: Aruna Nayak Date: Thu, 3 Sep 2015 14:30:58 +0200 Subject: [PATCH 2/2] update --- .../bin/preAnalyzerTauTau_Summer15.cc | 92 ++++++++++++++++++- 1 file changed, 90 insertions(+), 2 deletions(-) diff --git a/DesyTauAnalyses/NTupleMaker/bin/preAnalyzerTauTau_Summer15.cc b/DesyTauAnalyses/NTupleMaker/bin/preAnalyzerTauTau_Summer15.cc index 1c1da1c..63cc109 100644 --- a/DesyTauAnalyses/NTupleMaker/bin/preAnalyzerTauTau_Summer15.cc +++ b/DesyTauAnalyses/NTupleMaker/bin/preAnalyzerTauTau_Summer15.cc @@ -30,7 +30,7 @@ //#include "TauAnalysis/CandidateTools/interface/candidateAuxFunctions.h" //#include "TauAnalysis/CandidateTools/interface/neuralMtautauAuxFunctions.h" //#include "BtagSF.hh" -#include "readJSONFile.h" +//#include "readJSONFile.h" #include "Math/Vector3D.h" #include "Math/Vector4D.h" @@ -105,6 +105,93 @@ enum MCEVENTTYPE{HADHAD, LEPHAD, LEPLEP, LL, LNU, LEPNU, TAUNU, OTHERS}; enum BVariation{kNo = 0, kDown = 1, kUp = 2}; //BtagSF* btsf = new BtagSF(12345); +//Reading json file and filter lumi section +std::map > > +readJSONFile(const std::string& inFileName) +{ + std::ifstream inFile(inFileName.c_str(), std::ios::in); + + std::string line; + while(!inFile.eof()) + { + std::string buffer; + inFile >> buffer; + line += buffer; + } + + // define map with result + std::map > > jsonMap; + + // loop on JSON file + for(std::string::const_iterator it = line.begin(); it < line.end(); ++it) + { + // find run number + if( (*(it) == '"') && (*(it+7) == '"') ) + { + std::string run(it+1, it+7); + //std::cout << "found run " << run << std::endl; + + // find lumi sections + std::vector > lumisections; + for(std::string::const_iterator it2 = it+10; it2 < line.end(); ++it2) + { + if( (*(it2) == ']') && (*(it2-1) == ']') ) break; + if( *(it2) != '[' ) continue; + + std::string::const_iterator it_beg = it2; + std::string::const_iterator it_mid; + std::string::const_iterator it_end; + + for(std::string::const_iterator it3 = it_beg; it3 < line.end(); ++it3) + { + if( *(it3) == ',' ) it_mid = it3; + if( *(it3) == ']' ) + { + it_end = it3; + break; + } + } + std::string lumi_beg(it_beg+1, it_mid); + std::string lumi_end(it_mid+1, it_end); + //std::cout << "[" << lumi_beg; + //std::cout << ","; + //std::cout << lumi_end << "]" << std::endl; + + std::pair tempLS(atoi(lumi_beg.c_str()), atoi(lumi_end.c_str())); + lumisections.push_back(tempLS); + + it2 = it_end; + } + + jsonMap[atoi(run.c_str())] = lumisections; + } // find run number + + } // loop on JSON file + + return jsonMap; +} + +bool AcceptEventByRunAndLumiSection(const int& runId, const int& lumiId, + std::map > >& jsonMap) +{ + // select by runId + if( jsonMap.find(runId) == jsonMap.end() ) return false; + + // select by lumiId + std::vector > lumisections = jsonMap[runId]; + + int skipEvent = true; + for(unsigned int i = 0; i < lumisections.size(); ++i) + if( (lumiId >= lumisections.at(i).first) && + (lumiId <= lumisections.at(i).second) ) + skipEvent = false; + + if( skipEvent == true ) return false; + + return true; +} + +//compute DeltaR between two vectors double deltaR(LV v1, LV v2) { double deta = v1.Eta() - v2.Eta(); @@ -114,6 +201,7 @@ double deltaR(LV v1, LV v2) { } +//Weights for N-Jet MC samples float reweightHEPNUPWJets(int hepNUP) { int nJets = hepNUP-5; @@ -173,7 +261,7 @@ int getJetIDMVALoose(double pt, double eta, double rawMVA) } return passId; } - +//Remove duplication of events in ntuples bool checkEventIsDuplicated(MAPDITAU_run &mapDiTau, int run, int lumi, int event, float ptL1, float ptL2, float etaL1, float etaL2) {