int main(int argc, char** argv)
{ 
 TDRStyle();
 
 gStyle->SetPadTopMargin(0.11);
 gStyle->SetPadLeftMargin(0.07);
 gStyle->SetPadRightMargin(0.23);
 gStyle->cd(); 
 
 
 std::cout << " " << std::endl;
 std::cout << " " << std::endl;
 std::cout << "      ___|                       |                     \\  |   ___|         /      __ \\     \\  __ __|   \\          " << std::endl;
 std::cout << "     |       _ \\   |   |  __ \\   __|   _ \\   __|      |\\/ |  |            /       |   |   _ \\    |    _ \\       " << std::endl;
 std::cout << "     |      (   |  |   |  |   |  |     __/  |         |   |  |           /        |   |  ___ \\   |   ___ \\          " << std::endl;
 std::cout << "    \\____| \\___/  \\__,_| _|  _| \\__| \\___| _|        _|  _| \\____|     _/        ____/ _/    _\\ _| _/    _\\   " << std::endl; 
 std::cout << " " << std::endl;
 std::cout << " " << std::endl; 
 std::cout << " " << std::endl; 
 std::cout << "      ___|                |                            |   _)                         " << std::endl;
 std::cout << "    \\___ \\   |   |   __|  __|   _ \\  __ `__ \\    _` |  __|  |   __|   __|         " << std::endl;
 std::cout << "          |  |   | \\__ \\  |     __/  |   |   |  (   |  |    |  (    \\__ \\     " << std::endl;
 std::cout << "    _____/  \\__, | ____/ \\__| \\___| _|  _|  _| \\__,_| \\__| _| \\___| ____/       " << std::endl;
 std::cout << "            ____/                                                                     " << std::endl;
 std::cout << " " << std::endl;
 std::cout << " " << std::endl;
 
 
 
 
 char normal[] = { 0x1b, '[', '0', ';', '3', '9', 'm', 0 };
 char black[] = { 0x1b, '[', '0', ';', '3', '0', 'm', 0 };
 char red[] = { 0x1b, '[', '0', ';', '3', '1', 'm', 0 };
 char green[] = { 0x1b, '[', '0', ';', '3', '2', 'm', 0 };
 char yellow[] = { 0x1b, '[', '0', ';', '3', '3', 'm', 0 };
 char blue[] = { 0x1b, '[', '0', ';', '3', '4', 'm', 0 };
 char purple[] = { 0x1b, '[', '0', ';', '3', '5', 'm', 0 };
 char cyan[] = { 0x1b, '[', '0', ';', '3', '6', 'm', 0 };
 char Lgray[] = { 0x1b, '[', '0', ';', '3', '7', 'm', 0 };
 char Dgray[] = { 0x1b, '[', '0', ';', '3', '8', 'm', 0 };
 char Bred[] = { 0x1b, '[', '1', ';', '3', '1', 'm', 0 };
 //for bold colors, just change the 0 after the [ to a 1
 
 EColor vColor[1000] = {
  kGreen,
  //kMagenta,(EColor) (kMagenta+1),(EColor) (kMagenta+2),
  kTeal,//(EColor) (kTeal+1),
  kRed,
  kGray,
  kOrange,(EColor) (kOrange+1),
  kBlue,//(EColor)(kBlue+1),(EColor) (kBlue+2),
  (EColor) (kPink+2),//(EColor) (kPink+1),(EColor) (kPink+2),
  kViolet,
  kYellow,
  kGray,(EColor) (kGray+1),(EColor) (kViolet),(EColor) (kYellow),(EColor) (kGray)
 };
 
 
 
 
 //Check if all nedeed arguments to parse are there                                                                                                                               
 if(argc != 2)
 {
  std::cerr << ">>>>> analysis.cpp::usage: " << argv[0] << " configFileName" << std::endl ;
  return 1;
 }


 // Parse the config file                                                                                                                                                          
 parseConfigFile (argv[1]) ;
 
 std::string treeName  = gConfigParser -> readStringOption("Input::treeName");
 std::string treeNameSelections = gConfigParser -> readStringOption("Input::treeNameSelections");
 std::string fileSamples = gConfigParser -> readStringOption("Input::fileSamples");
 std::string inputDirectory = gConfigParser -> readStringOption("Input::inputDirectory");
 
 double LUMI = gConfigParser -> readDoubleOption("Input::Lumi");
 
 double LumiSyst = gConfigParser -> readDoubleOption("Input::LumiSyst");
 
 double Discovery = gConfigParser -> readDoubleOption("Input::Discovery");
 
 std::vector<std::string> SignalName;
 SignalName = gConfigParser -> readStringListOption("Input::SignalName");
 
 ///==== PU reweight (begin) ====
 std::vector<double> PUMC   = gConfigParser -> readDoubleListOption("PU::PUMC");
 std::vector<double> PUDATA = gConfigParser -> readDoubleListOption("PU::PUDATA");
 PUclass PU;
 
 std::cout << " PUMC.size()   = " << PUMC.size()   << std::endl;
 std::cout << " PUDATA.size() = " << PUDATA.size() << std::endl;
 
 if (PUMC.size() != PUDATA.size()) {
  std::cerr << " ERROR " << std::endl;
  return 1;
 }
 
 double sumPUMC = 0;
 for (int itVPU = 0; itVPU < PUMC.size(); itVPU++ ){
  sumPUMC += PUMC.at(itVPU);  
 }
 double sumPUDATA = 0;
 for (int itVPU = 0; itVPU < PUDATA.size(); itVPU++ ){
  sumPUDATA += PUDATA.at(itVPU);  
 } 
 
 for (int itVPU = 0; itVPU < PUMC.size(); itVPU++ ){
  PU.PUWeight.push_back(PUDATA.at(itVPU) / PUMC.at(itVPU) * sumPUMC / sumPUDATA);
 }

 PU.Write("autoWeight.cxx");
 gROOT->ProcessLine(".L autoWeight.cxx");
 ///==== PU reweight (end) ====
 
 ///==== save PU distribution in TH1F ====
 TH1F* hPUMC   = new TH1F("hPUMC","hPUMC",PUMC.size(),0,PUMC.size());
 TH1F* hPUDATA = new TH1F("hPUDATA","hPUDATA",PUDATA.size(),0,PUDATA.size());
 TH1F* hPUWeight = new TH1F("hPUWeight","hPUWeight",PUDATA.size(),0,PUDATA.size());
 
 for (int itVPU = 0; itVPU < PUMC.size(); itVPU++ ){
  hPUMC     -> SetBinContent(itVPU+1,PUMC.at(itVPU) / sumPUMC);
  hPUDATA   -> SetBinContent(itVPU+1,PUDATA.at(itVPU) / sumPUDATA);
  hPUWeight -> SetBinContent(itVPU+1,PUDATA.at(itVPU) / PUMC.at(itVPU) * sumPUMC / sumPUDATA);
 }
 
 
 
 TTree *treeEffVect[100];
 TTree *treeJetLepVect[100];
 

 
  //  [iCut] 
 TString* infoString[20];
 TLatex *infoLatex[20]; 
 TCanvas* ccCanvas[20];
 TCanvas* ccCanvasPull[20];
 TH1F* histoSumMC[20];
 //  [iName][iCut]
 TH1F* histo[100][20];
 TH1F* histo_temp[100][20];

 //  [iName][iCut]
 double numEvents[100][20];
 
 char *nameSample[1000];
 char *nameHumanReadable[1000];
 char* xsectionName[1000];
 
 double Normalization[1000];
 double xsection[1000];
 char nameFileIn[1000];
 sprintf(nameFileIn,"%s",fileSamples.c_str());

 int numberOfSamples = ReadFile(nameFileIn, nameSample, nameHumanReadable, xsectionName);

 
 double XSection  = gConfigParser -> readDoubleOption("Plot::XSection");
 
 ///==== list of selections to perform (NOT sequential additive selections) ====
 std::string CutFile = gConfigParser -> readStringOption("Selections::CutFile");
 std::vector<std::string> vCut;
 std::cout << " nCuts = " << ReadFileCut(CutFile, vCut) << std::endl;
 
 
 ///==== list of systematic variables to change ====
//  std::string CutSystematicFile = gConfigParser -> readfStringOption("Selections::CutSystematicFile");
// 
//  std::vector< std::pair< int, std::pair<std::string, double> > > listSystematics;
//  ReadFileSystematics(CutSystematicFile, listSystematics);
//  ModifyCut(vCut,listSystematics);

 
  std::string CutSystematicFile = gConfigParser -> readStringOption("Selections::CutSystematicFile");
 
  std::vector< std::pair< std::string, std::string> > listSystematics;
  ReadFileSystematicsWithRegion(CutSystematicFile, listSystematics);
  ModifyCutWithRegion(vCut,listSystematics);
  
  
  
  ///==== something to load/exec ====
  try {
   std::string toLoad = gConfigParser -> readStringOption("Exec::ToLoad");
   std::string toExec = ".L ";
   toExec += toLoad;
   toExec += ".cxx";
   gROOT->ProcessLine(toExec.c_str());
   std::cout << std::endl;
   std::cout << " load: " << toLoad.c_str() << std::endl;
   std::cout << " do:   " << toExec.c_str() << std::endl;
   std::cout << std::endl;
  }
  catch (char const* exceptionString){
   std::cerr << " exception = " << exceptionString << std::endl;
  }
  
 
 ///==== output file ====
 std::string OutFileName    = gConfigParser -> readStringOption("Output::outFileName");
 std::cout << ">>>>> Output::outFileName  " << OutFileName  << std::endl;  
 
 TFile outFile(OutFileName.c_str(),"RECREATE");
 outFile.cd();
 
 
 ///==== debug flag ====
 
 bool  debug = false; 
 try {
  debug = gConfigParser -> readBoolOption("Input::debug");
 }
 catch (char const* exceptionString){
  std::cerr << " exception = " << exceptionString << std::endl;
 }
 std::cout << ">>>>> input::debug  " << debug  << std::endl;  
 
 ///==== program ====
 
 
 double start, end;
 start = clock();
 
 
 for (int iSample=0; iSample<numberOfSamples; iSample++){
  xsection[iSample] = atof(xsectionName[iSample]);
 }
 
 for (int iSample=0; iSample<numberOfSamples; iSample++){
  
  char nameFile[20000];
  sprintf(nameFile,"%s/out_NtupleProducer_%s.root",inputDirectory.c_str(),nameSample[iSample]);  
  TFile* f = new TFile(nameFile, "READ");
  
  treeEffVect[iSample] = (TTree*) f->Get(treeNameSelections.c_str());
  char nameTreeEff[100];
  sprintf(nameTreeEff,"treeEff_%d",iSample); 
  treeEffVect[iSample]->SetName(nameTreeEff);      
  
  treeJetLepVect[iSample] = (TTree*) f->Get(treeName.c_str());
  char nameTreeJetLep[100];
  sprintf(nameTreeJetLep,"treeJetLep_%d",iSample); 
  treeJetLepVect[iSample]->SetName(nameTreeJetLep);
 }
 
 ///===== create map for joint sample ====
 
 std::vector<int> join_samples;
 std::vector<std::string> name_samples;
 for (int iSample=0; iSample<numberOfSamples; iSample++){
  name_samples.push_back(nameHumanReadable[iSample]);
  join_samples.push_back(-1);
 }
 
 
 std::vector<std::string> reduced_name_samples;
 std::vector<int>         reduced_name_samples_flag;
 for (int iSample = (numberOfSamples-1); iSample>= 0; iSample--){
  bool flag_name = false;
  for (unsigned int iName=0; iName<reduced_name_samples.size(); iName++){
   if (reduced_name_samples.at(iName) == name_samples.at(iSample)) flag_name = true;
  }
  if (flag_name == false) {
   reduced_name_samples.push_back(name_samples.at(iSample));
   reduced_name_samples_flag.push_back(-1);
  }
 }
 
 std::cout << " numberOfSamples = " << numberOfSamples << std::endl;
 
 for (int iSample = (numberOfSamples-1); iSample>= 0; iSample--){
  double XSection;
  int numEntriesBefore;
  double preselection_efficiency;
  treeEffVect[iSample]->SetBranchAddress("XSection",&XSection);
  treeEffVect[iSample]->SetBranchAddress("numEntriesBefore",&numEntriesBefore);
  treeEffVect[iSample]->SetBranchAddress("preselection_efficiency",&preselection_efficiency);  
  treeEffVect[iSample]->GetEntry(0);
  
  std::cout << " Xsection = " << XSection << " ~~~> " << xsection[iSample] << std::endl;
  XSection = xsection[iSample];
  
  if (numEntriesBefore != 0) {
   Normalization[iSample] = LUMI * XSection * preselection_efficiency / numEntriesBefore;
  }
  else {
   Normalization[iSample] = 0; 
  }    
 }
 
 
 
 TLegend* leg = new TLegend(0.8,0.25,0.98,0.78);
 bool LegendBuilt = false;

 TString lumiName = Form("#splitline{L = %.1f pb^{-1}}{#splitline{#sqrt{s} = 7}{CMS preliminary}}", LUMI);
//  TString lumiName = Form("#sqrt{s}=7 TeV   L=%.1f pb^{-1}", LUMI);
 TLatex *latex = new TLatex(0.80, 0.90, lumiName); 
 latex->SetTextAlign(12);
 latex->SetNDC();
 latex->SetTextFont(42);
 latex->SetTextSize(0.03);
  
 ///==== get number in sample list that correspond to DATA ====
 int numDATA = -1;
 for (unsigned int iName=0; iName<reduced_name_samples.size(); iName++){
  if (reduced_name_samples.at(iName) == "DATA") {
   numDATA = iName;
  }
 }
 
 
 if (debug) std::cout << " Cut size = " << vCut.size() << " ~~ " << std::endl;
 std::cout.precision (2) ;
 std::cout.unsetf(std::ios::scientific);
 ///==== cicle on selections ====
 for (unsigned int iCut = 0; iCut<vCut.size(); iCut++){
  TString Cut = Form ("%s",vCut.at(iCut).c_str());
  if (debug) std::cout << " Cut[" << iCut << ":" << vCut.size() << "] = " << Cut.Data() << " ~~ " << std::endl;
  ///==== initialize ====
  for (unsigned int iName=0; iName<reduced_name_samples.size(); iName++){
   reduced_name_samples_flag.at(iName) = -1;
  }
  
  ///==== cicle on samples ====
  for (int iSample = (numberOfSamples-1); iSample>= 0; iSample--){
   if (debug) std::cout << " Sample[" << iSample << ":" << numberOfSamples << "] = " << nameSample[iSample] << " ~~ " << std::endl;
   TString name_histo_temp = Form("%s_%d_temp",nameSample[iSample], iCut);
   histo_temp[iSample][iCut] = new TH1F(name_histo_temp,name_histo_temp,100,-10,10000000000);
   char toDraw[1000];
   sprintf(toDraw,"eventId >> %s",name_histo_temp.Data());      
   histo_temp[iSample][iCut] -> Sumw2(); //---- così mette l'errore giusto!
   
   TString CutExtended;
   bool isData = false;
   for (unsigned int iName=0; iName<reduced_name_samples.size(); iName++){
    if (name_samples.at(iSample) == reduced_name_samples.at(iName)){
     if (iName == numDATA) {
      isData = true;
     }
    }
   }  
   if (!isData) {
    CutExtended = Form ("(%s) * autoWeight(numPUMC)",Cut.Data());    
   }
   else {
    CutExtended = Form ("(%s)",Cut.Data());    
   }
   if (debug) std::cerr << " drawing ..." << std::endl;
   treeJetLepVect[iSample]->Draw(toDraw,CutExtended,"");
   if (debug) std::cerr << " drawn ..." << std::endl;
   
   if (Normalization[iSample]>0) { 
    histo_temp[iSample][iCut] -> Scale(Normalization[iSample]); 
   }
   for (unsigned int iName=0; iName<reduced_name_samples.size(); iName++){
    if (name_samples.at(iSample) == reduced_name_samples.at(iName)){
     if (reduced_name_samples_flag.at(iName) == -1){
      TString name_histoTot_temp = Form("%s_%d_Tot_temp",reduced_name_samples.at(iName).c_str(),iCut);
      TString name_HR_histoTot_temp = Form("cut %d",iCut);
      histo[iName][iCut] = new TH1F(name_histoTot_temp,name_HR_histoTot_temp,100,-10,10000000000);
      histo[iName][iCut] -> Sumw2(); //---- così mette l'errore giusto!
      reduced_name_samples_flag.at(iName) = 1;
     }
     histo[iName][iCut] -> Add(histo_temp[iSample][iCut]);
    }
   }
   std::cout << "Processing: " << blue << (((double) iCut)/vCut.size())*100. << "% "  << normal <<  " -- " <<  red << (((double) numberOfSamples - iSample)/(numberOfSamples))*100. << "% \r"  << normal << std::flush;   
  } ///==== end cicle on samples ====
//   std::cout << "Processing: " << blue << (((double) iCut)/vCut.size())*100. << "% \r"  << normal << std::flush;   
 } ///==== end cicle on selections ====
 
 //  [iName]
 TH1F* hTrend[100];
 THStack* hsTrend;
 //  [iCut]
 TPie* hTrendPie[100];
 
 //  [iCut]
 THStack* hs[100];
 
 std::cout << std::endl;
 
 ///==== cicle on selections ====
 for (unsigned int iCut = 0; iCut<vCut.size(); iCut++){
  TString nameStack = Form("%d_stack",iCut);
  hs[iCut] = new THStack(nameStack,nameStack);
  
  for (unsigned int iName=0; iName<reduced_name_samples.size(); iName++){
   histo[iName][iCut]->GetXaxis()->SetTitle("eventId");
   histo[iName][iCut]->SetMarkerColor(vColor[iName]);
   histo[iName][iCut]->SetLineColor(vColor[iName]);
   histo[iName][iCut]->SetFillColor(vColor[iName]);
   histo[iName][iCut]->SetLineWidth(2);
   histo[iName][iCut]->SetFillStyle(3001);
   
   bool isSig = false;
   for (std::vector<std::string>::const_iterator itSig = SignalName.begin(); itSig != SignalName.end(); itSig++){
    if (reduced_name_samples.at(iName) == *itSig) isSig = true;
   }
   
   if (!isSig && reduced_name_samples.at(iName) != "DATA") {
    hs[iCut]->Add(histo[iName][iCut]);
   }
   else {
    if (!isSig) {
     histo[iName][iCut]->SetMarkerStyle(20);
     histo[iName][iCut]->SetMarkerSize(1);
     histo[iName][iCut]->SetMarkerColor(kBlack);
     histo[iName][iCut]->SetLineColor(kBlack);
     histo[iName][iCut]->SetFillColor(kBlack);
     histo[iName][iCut]->SetLineWidth(2);
     histo[iName][iCut]->SetFillStyle(3001);  
    }
    else {
     histo[iName][iCut]->SetMarkerStyle(21);
     histo[iName][iCut]->SetMarkerSize(1);
     histo[iName][iCut]->SetLineWidth(2);
     histo[iName][iCut]->SetFillStyle(3001);  
    }
   }
  }
  ///==== histo sum MC ====    
  ///==== Add systrematic error ====
  AddError(hs[iCut],LumiSyst);
  histoSumMC[iCut] = ((TH1F*)(hs[iCut]->GetStack()->Last()));

  std::cout << " MC / DATA[" << iCut << "] = "<< histoSumMC[iCut]->Integral() << " / " << histo[numDATA][iCut]->Integral() << " = " << (histo[numDATA][iCut]->Integral() ? histoSumMC[iCut]->Integral()/ histo[numDATA][iCut]->Integral() : 0) << std::endl;
  
  ///==== legend ====
  if (!LegendBuilt){
   for (unsigned int iName=0; iName<reduced_name_samples.size(); iName++){
    leg->AddEntry(histo[iName][iCut],reduced_name_samples.at(iName).c_str(),"pf");    
    LegendBuilt = true;
   }
  }
 }
 std::cout << std::endl << std::endl;
 
 ///==== calculate number of events after each step of the analysis ====
 //  [iName][iCut]
 hsTrend = new THStack("Trend","Trend");
 
 for (unsigned int iCut = 0; iCut<vCut.size(); iCut++){
  TString nameTHTrendPie = Form("%d_Trend_Pie",iCut);
  hTrendPie[iCut] = new TPie (nameTHTrendPie,nameTHTrendPie,reduced_name_samples.size());
 }
 
 for (unsigned int iName=0; iName<reduced_name_samples.size(); iName++){
  TString nameTHTrend = Form("%s_Trend",reduced_name_samples.at(iName).c_str());
  hTrend[iName] = new TH1F (nameTHTrend,nameTHTrend,vCut.size()+1,0,vCut.size()+1);
  hTrend[iName]->GetXaxis()->SetTitle("Selections");

  if (iName == numDATA) {
   hTrend[iName]->SetMarkerStyle(20);
   hTrend[iName]->SetMarkerSize(1);
   hTrend[iName]->SetMarkerColor(kBlack);
   hTrend[iName]->SetLineColor(kBlack);
   hTrend[iName]->SetFillColor(kBlack);
   hTrend[iName]->SetLineWidth(2);
   hTrend[iName]->SetFillStyle(3001);  
  }
  else {
   hTrend[iName]->SetMarkerColor(vColor[iName]);
   hTrend[iName]->SetLineColor(vColor[iName]);
   hTrend[iName]->SetFillColor(vColor[iName]);
   hTrend[iName]->SetLineWidth(2);
   hTrend[iName]->SetFillStyle(3001);
  }
  for (unsigned int iCut = 0; iCut<vCut.size(); iCut++){
   double error = 0;
   numEvents[iName][iCut] = histo[iName][iCut]->IntegralAndError(0,histo[iName][iCut]->GetNbinsX()+1,error);
   hTrend[iName]->SetBinContent(iCut+1,numEvents[iName][iCut]);
   hTrend[iName]->SetBinError(iCut+1,error);

   TString nameBin = Form("%d",iCut);
   hTrend[iName]->GetXaxis()->SetBinLabel(iCut+1,nameBin);
//     IntegralAndError
//     Double_t IntegralAndError(Int_t binx1, Int_t binx2, Double_t& err, Option_t* option = "") const
   std::cout << ">>>  numEvents[" << iName << "," << reduced_name_samples.at(iName) << "][" << iCut << "] = " << numEvents[iName][iCut] << " , " << histo[iName][iCut]->GetEntries() << " , " << histo[iName][iCut]->GetEffectiveEntries() << std::endl;
   
   if (iName != numDATA) {
    hTrendPie[iCut]->SetTextSize(0.04);
    hTrendPie[iCut]->SetTextFont(12);
    hTrendPie[iCut]->SetEntryFillColor(iName,vColor[iName]);
    hTrendPie[iCut]->SetEntryFillStyle(iName,3001);
    hTrendPie[iCut]->SetEntryLabel(iName, reduced_name_samples.at(iName).c_str());
    hTrendPie[iCut]->SetEntryLineColor(iName, vColor[iName]);
    hTrendPie[iCut]->SetEntryLineStyle(iName, 2);
    hTrendPie[iCut]->SetEntryLineWidth(iName, 2);
    hTrendPie[iCut]->SetEntryRadiusOffset(iName, 0.01);
    hTrendPie[iCut]->SetEntryVal(iName,numEvents[iName][iCut]);
   }
   else {
    hTrendPie[iCut]->SetEntryLabel(iName, "");
   }
  }
  if (iName != numDATA) {
   hsTrend->Add(hTrend[iName]);
  }
 }
 AddError(hsTrend,LumiSyst);
 
 TH1F* hTrendSumMC = ((TH1F*)(hsTrend->GetStack()->Last()));
 ///==== hTrend with pull plot ====
 TH1F* hPullTrendSumMC = PullPlot(hTrend[numDATA], hTrendSumMC);
  
 LumiSyst = 0; ///---- bug fix
 
 
 
 
 TCanvas* cTrendPie[100];
 TCanvas* cTrendPieAll = new TCanvas("cTrendPieAll","cTrendPieAll",400 * vCut.size(),400);
 cTrendPieAll -> Divide (vCut.size());
 TCanvas* cTrend = new TCanvas("cTrend","cTrend",400,400);
 TCanvas* cTrendSample[100];
 
 
 for (unsigned int iName=0; iName<reduced_name_samples.size(); iName++){
  TString nameCanvas = Form("%d_Canvas_Sample",iName);
  cTrendSample[iName] = new TCanvas(nameCanvas,nameCanvas,400,400);
  hTrend[iName] -> Draw();
  gPad->SetLogy();
  gPad->SetGrid();
 }
 
 
 
 
 
 
 ///~~~~ for efficiency calculation ~~~~
 
 std::vector<double> numEntriesFirstStep_reduced_samples;
 for (unsigned int iName=0; iName<reduced_name_samples.size(); iName++){
  numEntriesFirstStep_reduced_samples.push_back(0);
  for (int iSample = (numberOfSamples-1); iSample>= 0; iSample--){
   if (name_samples.at(iSample) == reduced_name_samples.at(iName)){
//     numEntriesFirstStep_reduced_samples.at(iName) += (Normalization[iSample] ? (1. / Normalization[iSample] * LUMI * xsection[iSample] * LUMI * xsection[iSample]) : -1);
    numEntriesFirstStep_reduced_samples.at(iName) += (xsection[iSample] * LUMI);
   }
  }
 }
//   Normalization[iSample] = LUMI * XSection * preselection_efficiency / numEntriesBefore;
//   1. / Normalization[iSample] = numEntriesBefore / preselection_efficiency / LUMI / XSection;
//   1. / Normalization[iSample] * LUMI * xsection[iSample] = numEntriesBefore / preselection_efficiency;
//   1. / Normalization[iSample] * LUMI * xsection[iSample] * LUMI * xsection[iSample] = numEntriesBefore / preselection_efficiency * LUMI * xsection[iSample];

 for (unsigned int iName=0; iName<reduced_name_samples.size(); iName++){
  std::cout << "[" << reduced_name_samples.at(iName) << "] = " << numEntriesFirstStep_reduced_samples.at(iName) << std::endl;
 }
 
 std::cout.precision (2) ;
 std::cout.unsetf(std::ios::scientific);


 
 std::cout << std::endl;
 std::cout << std::endl;
 std::cout << std::endl;
 std::cout << std::endl;
 std::cout << std::endl;
 std::cout << " *********************************** " << std::endl;
 std::cout << std::setw (12) << "sample";
 std::cout << " | " << std::setw (8) <<  -1;
 std::cout << " [" << std::setw (8) <<  "XXX";
 std::cout << " ]";
 for (unsigned int iCut = 0; iCut<vCut.size(); iCut++){
  std::cout << " | " << std::setw (8) <<  iCut;
  std::cout << " [" << std::setw (8) <<  "XXX";
  std::cout << " ]";
 }
 std::cout << std::endl;
 for (unsigned int iName=0; iName<reduced_name_samples.size(); iName++){
  std::cout << std::setw (12) << reduced_name_samples.at(iName) ;
  std::cout << " | " << cyan << std::setw (8) <<  numEntriesFirstStep_reduced_samples.at(iName);
  std::cout << normal << " [" << std::setw (8) <<  "XXX";
  std::cout << " ]";
  for (unsigned int iCut = 0; iCut<vCut.size(); iCut++){
   std::cout << " | " << blue << std::setw (8) <<  hTrend[iName]->GetBinContent(iCut+1);
   std::cout << normal << " [" << std::setw (8) <<  hTrend[iName]->GetBinError(iCut+1);
   std::cout << " ]";
  }
  std::cout << std::endl;
 }
 
 std::cout << std::endl;
 std::cout << " *********************************** " << std::endl;
 for (unsigned int iName=0; iName<reduced_name_samples.size(); iName++){
  std::cout << " | " << std::setw (8) << reduced_name_samples.at(iName) ;
  std::cout << " [" << std::setw (8) <<  "err";
  std::cout << " ]";
 }
 std::cout << std::endl;
 for (unsigned int iName=0; iName<reduced_name_samples.size(); iName++){
  std::cout << " | " << cyan << std::setw (8) <<  numEntriesFirstStep_reduced_samples.at(iName);
  std::cout << normal << " [" << std::setw (8) <<  "XXX";
  std::cout << " ]";
 }
 std::cout << std::endl;
 for (unsigned int iCut = 0; iCut<vCut.size(); iCut++){
  for (unsigned int iName=0; iName<reduced_name_samples.size(); iName++){
   std::cout << " | " << blue << std::setw (8) <<  hTrend[iName]->GetBinContent(iCut+1);
   std::cout << normal << " [" << std::setw (8) <<  hTrend[iName]->GetBinError(iCut+1);
   std::cout << " ]";
  }
  std::cout << std::endl;
 }
 
 
 
 std::cout << std::endl;
 std::cout << std::endl;
 std::cout << std::endl;
 std::cout << " *********************************** " << std::endl;
 std::cout << " ************* 1 fb-1 ************* " << std::endl;
 std::cout << std::setw (12) << "sample";
 std::cout << " | " << std::setw (8) <<  -1;
 std::cout << " [" << std::setw (8) <<  "XXX";
 std::cout << " ]";
 for (unsigned int iCut = 0; iCut<vCut.size(); iCut++){
  std::cout << " | " << std::setw (8) <<  iCut;
  std::cout << " [" << std::setw (8) <<  "XXX";
  std::cout << " ]";
 }
 std::cout << std::endl;
 for (unsigned int iName=0; iName<reduced_name_samples.size(); iName++){
  std::cout << std::setw (12) << reduced_name_samples.at(iName) ;
  std::cout << " | " << purple << std::setw (9) <<  1000 / LUMI * numEntriesFirstStep_reduced_samples.at(iName);
  std::cout << normal << " [" << std::setw (9) <<  "XXX";
  std::cout << " ]";
  for (unsigned int iCut = 0; iCut<vCut.size(); iCut++){
   std::cout << " | " << red << std::setw (9) <<  hTrend[iName]->GetBinContent(iCut+1) / LUMI * 1000.;
   std::cout << normal << " [" << std::setw (9) <<  hTrend[iName]->GetBinError(iCut+1) / LUMI * 1000.;
   std::cout << " ]";
  }
  std::cout << std::endl;
 }
 
 std::cout << std::endl;
 std::cout << " *********************************** " << std::endl;
 for (unsigned int iName=0; iName<reduced_name_samples.size(); iName++){
  std::cout << " | " << red << std::setw (8) << reduced_name_samples.at(iName) ;
  std::cout << normal << " [" << std::setw (8) <<  "err";
  std::cout << " ]";
 }
 std::cout << std::endl;
 for (unsigned int iName=0; iName<reduced_name_samples.size(); iName++){
  std::cout << " | " << purple << std::setw (8) <<  1000 / LUMI * numEntriesFirstStep_reduced_samples.at(iName);
  std::cout << normal << " [" << std::setw (8) <<  "XXX";
  std::cout << " ]";
 }
 std::cout << std::endl;
 for (unsigned int iCut = 0; iCut<vCut.size(); iCut++){
  for (unsigned int iName=0; iName<reduced_name_samples.size(); iName++){
   std::cout << " | " << red << std::setw (8) <<  hTrend[iName]->GetBinContent(iCut+1) / LUMI * 1000.;
   std::cout << normal << " [" << std::setw (8) <<  hTrend[iName]->GetBinError(iCut+1) / LUMI * 1000.;
   std::cout << " ]";
  }
  std::cout << std::endl;
 }
 
  
 std::cout << std::endl;
 std::cout << std::endl;
 std::cout << std::endl;
 std::cout << " **************************************** " << std::endl;
 std::cout << " ************* efficiency *************** " << std::endl;
 std::cout << std::setw (12) << "sample";
 for (unsigned int iCut = 0; iCut<vCut.size(); iCut++){
  std::cout << " | " << std::setw (8) <<  iCut;
  std::cout << " [" << std::setw (8) <<  "XXX";
  std::cout << " ]";
 }
 std::cout << std::endl;
 for (unsigned int iName=0; iName<reduced_name_samples.size(); iName++){
  std::cout << std::setw (12) << reduced_name_samples.at(iName) ;
  for (unsigned int iCut = 0; iCut<vCut.size(); iCut++){
   std::cout << " | " << yellow << std::setw (8) <<  hTrend[iName]->GetBinContent(iCut+1) / numEntriesFirstStep_reduced_samples.at(iName);
   std::cout << normal << " [" << std::setw (8) <<  hTrend[iName]->GetBinError(iCut+1) / numEntriesFirstStep_reduced_samples.at(iName);
//    std::cout << " | " << yellow << std::setw (8) <<  hTrend[iName]->GetBinContent(iCut+1) << " / " << numEntriesFirstStep_reduced_samples.at(iName);
//    std::cout << normal << " [" << std::setw (8) <<  hTrend[iName]->GetBinError(iCut+1) << " / " << numEntriesFirstStep_reduced_samples.at(iName);
   std::cout << " ]";
  }
  std::cout << std::endl;
 }
 
 std::cout << std::endl;
 std::cout << " *********************************** " << std::endl;
 for (unsigned int iName=0; iName<reduced_name_samples.size(); iName++){
  std::cout << " | " << std::setw (8) << reduced_name_samples.at(iName) ;
  std::cout << " [" << std::setw (8) <<  "err";
  std::cout << " ]";
 }
 std::cout << std::endl;
 for (unsigned int iCut = 0; iCut<vCut.size(); iCut++){
  for (unsigned int iName=0; iName<reduced_name_samples.size(); iName++){
   std::cout << " | " << yellow << std::setw (8) <<  hTrend[iName]->GetBinContent(iCut+1) / numEntriesFirstStep_reduced_samples.at(iName);
   std::cout << normal << " [" << std::setw (8) <<  hTrend[iName]->GetBinError(iCut+1) / numEntriesFirstStep_reduced_samples.at(iName);
   std::cout << " ]";
  }
  std::cout << std::endl;
 }
 
 
 
 
 
 
 
 std::cout << std::endl;
 std::cout << std::endl;
 std::cout << std::endl;
 std::cout << std::endl;
 std::cout << std::endl;
 std::cout << " ****************************************************************** " << std::endl;
 std::cout << " ****************************************************************** " << std::endl;
 std::cout << " *********************** for Lands datacard *********************** " << std::endl;
 std::cout << std::endl;
 std::cout << std::endl;
 std::cout << std::endl;
 std::cout << std::endl;
 
 
 
 std::string mass = "160";
 try {
  mass = gConfigParser -> readStringOption("Input::mass");
 }
 catch (char const* exceptionString){
  std::cerr << " exception = " << exceptionString << std::endl;
 }
 std::cout << ">>>>> input::mass  " << mass << std::endl;  
 
 std::ofstream myfile;
 std::string nameOutDataCard = "dataCard_H" + mass + ".txt";
 
 ///==== output - txt file name ====
 try {
  nameOutDataCard = gConfigParser -> readStringOption("Output::DataCard");
 }
 catch (char const* exceptionString){
  std::cerr << " exception = " << exceptionString << std::endl;
 }
 
 myfile.open (nameOutDataCard.c_str());
 std::cout << "Writing to: " << nameOutDataCard << std::endl;
 std::cout << std::endl;
 
 
 myfile << "Limit" << std::endl;
 myfile << "imax 1 number of channels" << std::endl;
 myfile << "jmax "<< (reduced_name_samples.size() - SignalName.size() - 1) << " number of background" << std::endl;
 //---- -1 to take into account "DATA"
 myfile << "kmax "<< 0 << " number of nuisance parameters" << std::endl;
 
 double totalSig = 0;
 double totalBkg = 0;
 for (unsigned int iName=0; iName<reduced_name_samples.size(); iName++){
  if (iName != numDATA) {
   bool isSig = false;
   for (std::vector<std::string>::const_iterator itSig = SignalName.begin(); itSig != SignalName.end(); itSig++){
    if (reduced_name_samples.at(iName) == *itSig) isSig = true;
   }
   if (isSig) {
    totalSig += hTrend[iName]->GetBinContent(vCut.size());   ///---- last cut!
   }
   else {
    totalBkg += hTrend[iName]->GetBinContent(vCut.size());   ///---- last cut!
   }
  }
 }
 myfile << "-------------------------------------------------" << std::endl;
//  myfile << "Observation   " << ((Discovery==1) ? (int) (totalBkg+totalSig) : (int) (totalBkg)) << std::endl;
 myfile << "Observation   " << hTrend[numDATA]->GetBinContent(vCut.size()) << std::endl;
 //# 1 = discovery, 0 = exclusion
 myfile << "-------------------------------------------------" << std::endl;
 
 
 myfile << std::setw (12) << " bin  " << std::setw (8) << 1 << "  ";
 for (int i=0; i < (reduced_name_samples.size() - SignalName.size() - 1); i++){
  myfile << std::setw (8) << 1 << "  ";
 }
 myfile << std::endl;
 
 myfile << std::setw (12) << " process  " << std::setw (8) << "sig" << "  ";
 for (unsigned int iName=0; iName<reduced_name_samples.size(); iName++){
  if (iName != numDATA) {
   bool isSig = false;
   for (std::vector<std::string>::const_iterator itSig = SignalName.begin(); itSig != SignalName.end(); itSig++){
    if (reduced_name_samples.at(iName) == *itSig) isSig = true;
   }
   if (!isSig) {
    myfile << std::setw (8) << reduced_name_samples.at(iName) << "  ";
   }
  }
 }
 myfile << std::endl;
 
 myfile << std::setw (12) << " process  " << std::setw (8) << 0 << "  ";
 for (int i=0; i < (reduced_name_samples.size() - SignalName.size() - 1); i++){
  myfile << std::setw (8) << i+1 << "  ";
 }
 myfile << std::endl;
 
 myfile << std::setw (12) << " rate  " << std::setw (8) << totalSig << "  ";
 for (unsigned int iName=0; iName<reduced_name_samples.size(); iName++){
  if (iName != numDATA) {
   bool isSig = false;
   for (std::vector<std::string>::const_iterator itSig = SignalName.begin(); itSig != SignalName.end(); itSig++){
    if (reduced_name_samples.at(iName) == *itSig) isSig = true;
   }
   if (!isSig) {
    myfile << std::setw (8) << hTrend[iName]->GetBinContent(vCut.size()) << "  ";
   }
  }
 }
 myfile << std::endl;
 
 
 myfile << "-------------------------------------------------" << std::endl;
 
 myfile.close(); 
 
 
 
 
 ///==== plot on the screen ====
 
 std::cout << "Limit" << std::endl;
 std::cout << "imax 1 number of channels" << std::endl;
 std::cout << "jmax "<< (reduced_name_samples.size() - SignalName.size() - 1) << " number of background" << std::endl;
 //---- -1 to take into account "DATA"
 std::cout << "kmax "<< 0 << " number of nuisance parameters" << std::endl;
 
 totalSig = 0;
 totalBkg = 0;
 for (unsigned int iName=0; iName<reduced_name_samples.size(); iName++){
  if (iName != numDATA) {
   bool isSig = false;
   for (std::vector<std::string>::const_iterator itSig = SignalName.begin(); itSig != SignalName.end(); itSig++){
    if (reduced_name_samples.at(iName) == *itSig) isSig = true;
   }
   if (isSig) {
    totalSig += hTrend[iName]->GetBinContent(vCut.size());   ///---- last cut!
   }
   else {
    totalBkg += hTrend[iName]->GetBinContent(vCut.size());   ///---- last cut!
   }
  }
 }
 std::cout << "-------------------------------------------------" << std::endl;
//  std::cout << "Observation   " << ((Discovery==1) ? (int) (totalBkg+totalSig) : (int) (totalBkg)) << std::endl;
 std::cout << "Observation   " << hTrend[numDATA]->GetBinContent(vCut.size()) << std::endl;
 //# 1 = discovery, 0 = exclusion
 std::cout << "-------------------------------------------------" << std::endl;
 
 
 std::cout << std::setw (12) << " bin  " << std::setw (8) << 1 << "  ";
 for (int i=0; i < (reduced_name_samples.size() - SignalName.size() - 1); i++){
  std::cout << std::setw (8) << 1 << "  ";
 }
 std::cout << std::endl;
 
 std::cout << std::setw (12) << " process  " << std::setw (8) << "sig" << "  ";
 for (unsigned int iName=0; iName<reduced_name_samples.size(); iName++){
  if (iName != numDATA) {
   bool isSig = false;
   for (std::vector<std::string>::const_iterator itSig = SignalName.begin(); itSig != SignalName.end(); itSig++){
    if (reduced_name_samples.at(iName) == *itSig) isSig = true;
   }
   if (!isSig) {
    std::cout << std::setw (8) << reduced_name_samples.at(iName) << "  ";
   }
  }
 }
 std::cout << std::endl;
 
 std::cout << std::setw (12) << " process  " << std::setw (8) << 0 << "  ";
 for (int i=0; i < (reduced_name_samples.size() - SignalName.size() - 1); i++){
  std::cout << std::setw (8) << i+1 << "  ";
 }
 std::cout << std::endl;
 
 std::cout << std::setw (12) << " rate  " << std::setw (8) << totalSig << "  ";
 for (unsigned int iName=0; iName<reduced_name_samples.size(); iName++){
  if (iName != numDATA) {
   bool isSig = false;
   for (std::vector<std::string>::const_iterator itSig = SignalName.begin(); itSig != SignalName.end(); itSig++){
    if (reduced_name_samples.at(iName) == *itSig) isSig = true;
   }
   if (!isSig) {
    std::cout << std::setw (8) << hTrend[iName]->GetBinContent(vCut.size()) << "  ";
   }
  }
 }
 std::cout << std::endl;
 
 
 std::cout << "-------------------------------------------------" << std::endl;
 
 
 std::cout << std::endl;
 std::cout << std::endl;
 std::cout << std::endl;
 std::cout << std::endl;
 std::cout << std::endl;
 
 std::cout << std::endl;
 std::cout << std::endl;
 std::cout << std::endl;
 std::cout << std::endl;
 std::cout << std::endl;
 
 
 
 
 
 
 ///==== draw trend vs cut (begin)
 cTrend->cd();
 DrawStack(hsTrend,1,LumiSyst);
 hTrend[numDATA] -> Draw("EsameP");
 gPad->SetLogy();
 gPad->SetGrid();
 leg->Draw();
 latex->Draw();
  
 for (unsigned int iCut = 0; iCut<vCut.size(); iCut++){
  TString nameCanvas = Form("%d_Canvas_Trend",iCut);
  cTrendPie[iCut] = new TCanvas(nameCanvas,nameCanvas,400,400);
  cTrendPie[iCut]->cd();
  hTrendPie[iCut] -> Draw("3d t nol");
  hTrendPie[iCut]->SetX(.45);
  hTrendPie[iCut]->SetRadius(.22);
  leg->Draw();
  latex->Draw();
  
  cTrendPieAll->cd(iCut+1);
  hTrendPie[iCut] -> Draw("3d t nol");
  hTrendPie[iCut]->SetX(.45);
  hTrendPie[iCut]->SetRadius(.22);
  leg->Draw();
  latex->Draw();
 }
 ///==== draw trend vs cut (end)
 
 
 
 std::cerr << " ******************************************* end *******************************************" << std::endl;
 end = clock();
 std::cout <<"Time = " <<  ((double) (end - start)) << " (a.u.)" << std::endl;  
 
 
 
 ///==== save output ====
 outFile.cd();
 cTrend -> Write();
 
 outFile.mkdir("Trend");
 outFile.cd("Trend");
 for (unsigned int iCut = 0; iCut<vCut.size(); iCut++){
  cTrendPie[iCut] -> Write();
 }
 cTrendPieAll -> Write();
 
 
 outFile.cd();
 outFile.mkdir("PU");
 outFile.cd("PU");
 
 hPUMC     -> Write();
 hPUDATA   -> Write();
 hPUWeight -> Write();
 
 
 outFile.cd();
 outFile.mkdir("Sample");
 outFile.cd("Sample");
 
 for (unsigned int iName=0; iName<reduced_name_samples.size(); iName++){
  cTrendSample[iName] ->Write();
 }  
 
 leg->Write();
 
}
Exemplo n.º 2
0
void dileptonMassFit(const char* pInFileName="PanchoSkim4JanAll.root",
                     // "PromtRecoV2V3V3H_DiMuonPlot_TightSTACutsAll15Dec.root",
                     // "Z0_DataMixPt50_PatDiMuonPlots_NewCutAll14Dec.root",
                     const char* pHistNameOpCh="diMuonsGlobalInvMassVsPt",//diMuonsGlobalInvMassVsPtW",
                     const char* pHistNameSameCh="diMuonsGlobalSameChargeInvMassVsPt",
                     const char* pSpectra="pt",  // pt, y, centr
                     bool doMc=false,
                     int nFitFunction = 3,
                     int getYield = 1)
{
    gROOT->Macro("setStyle.C+");

    //gROOT->Macro("/Users/eusmartass/Software/utilities/setStyle.C+");
    char szBuf[256];

    ////////  definitions of Switches   ///////////
    //  nFitFunction  = 1  RBW + Pol2
    //  nFitFunction  = 2  Gaus + Pol2
    //  nFitFunction  = 3  RBWGaus + Pol2

    //  getYield = 1  Bin counting
    //  getYield = 2  Integral
    ////////////////////////////////////////////////////////////

    // make some choices
    float MassZ0         = 91.1876;
    float WidthZ0        = 2.4952;
    float massFit_low    = 60;
    float massFit_high   = 120;   // Fit ranges
    float massDraw_low   = 30.0;  // 0.
    float massDraw_high  = 130.0; // 200/
    int nrebin           = 80;
    bool isLog           = 0;
    bool isFit           = 1; // draw ranges

    float massCount_low  = 60.0; //78.0
    float massCount_high = 120.0; //102.0

    //___________________________________________________________________________________
    // ------- Open input file
    sprintf(szBuf,"%s",pInFileName);
    TString inFileName(szBuf);
    TFile *pfInFile = new TFile(inFileName);

    // ------- get histograms:
    sprintf(szBuf,"%s",pHistNameOpCh);
    TH2D *phDimuMass_1  = (TH2D*)pfInFile->Get(szBuf)->Clone("phDimuMass_1");

    sprintf(szBuf,"%s",pHistNameSameCh);
    TH2D *phDimuMass_1S = (TH2D*)pfInFile->Get(szBuf)->Clone("phDimuMass_1S");

    phDimuMass_1->SetDirectory(0);
    phDimuMass_1S->SetDirectory(0);

    // Open pp data file

    TFile *ppFile = new TFile("Zmumu_40-200_35pb.root");
    TH1F *Zmumu  = (TH1F*)ppFile->Get("hdata");


    //___________________________________________________________________________________
    // bins definition:
    const char* Xname[] = {" ", "p_{T}^{Dimuon} (GeV/c)", "rapidity", "centrality"};
    bool doPt   = false;
    bool doY    =  false;
    bool doCent = false;

    int GenRange, nBins;
    double binEdge[10];
    char* label;
    sprintf(szBuf,"%s",pSpectra);
    TString wichSpectra(szBuf);

    if ( wichSpectra.CompareTo("pt") == 0) {
        doPt               = true;
        label              = (char*)Xname[1];
        GenRange           = 20;
        nBins              = 1;
        binEdge[0] = 0.0;
        binEdge[1]= 100.0;
        //    double binEdge[10] = {0.0, 10., 20., 100.0};
        if(doMc) {
            nBins              = 1;
            binEdge[0] = 0.0;
            binEdge[1]= 50.0;
            //	  nBins          = 7;
            // binEdge[0] =  0.0;  binEdge[1] =  2.0;  binEdge[2] =  4.0;  binEdge[3] = 8.0;
            //binEdge[4] = 12.0;  binEdge[5] = 16.0;  binEdge[6] = 22.0;  binEdge[7] = 50.0;
        }
    } else {
        if ( wichSpectra.CompareTo("y") == 0) {
            doY              = true;
            label            = (char*)Xname[2];
            nBins            = 3;
            GenRange         = 4.8;
            binEdge[0] = -2.4;
            binEdge[1] = -0.8;
            binEdge[2] =  0.8;
            binEdge[3] =  2.4;
        } else {
            if ( wichSpectra.CompareTo("cent") == 0) 	{
                doCent           = true;
                label            = (char*)Xname[3];
                nBins            = 4;
                GenRange         = 40;
                binEdge[0] = 0.;
                binEdge[1] =   4;
                binEdge[2] = 8.;
                binEdge[3] =  16;
                binEdge[4] =  40;
            } else {
                cout<<"Don't know what you want to do!!!!"<<endl;
                return;
            }
        }
    }

    double PT[10], DelPT[10], mom_err[100];
    for (Int_t ih = 0; ih < nBins; ih++)  {
        PT[ih]      = (binEdge[ih] + binEdge[ih+1])/2.0;
        DelPT[ih]   = binEdge[ih+1] - binEdge[ih];
        mom_err[ih] = DelPT[ih]/2.0;
    }

    //___________________________________________________________________________________

    double gen_pt[10];
    double egen_pt[10];

    TCanvas *pcPt_1 = new TCanvas("pcPt_1"," Z0 Yield Vs. Pt ", 40,40,600,600);

    if(doMc) {
        pcPt_1->Divide(nBins,2);

        //TH2D *genMass_1 = (TH2D*)pfInFile->Get("diMuonsGenInvMassVsPt");
        TH2D *genMass_1 = (TH2D*)pfInFile->Get("diMuonsGenInvMassVsPtW");
        TH1D *ptaxis    = (TH1D*)genMass_1->ProjectionY("ptaxis");

        for (Int_t ih = 0; ih < nBins; ih++) {
            pcPt_1->cd(ih+nBins+1);

            int bin1 = ptaxis->FindBin(binEdge[ih]+0.0000001);
            int bin2 = ptaxis->FindBin(binEdge[ih+1]+0.0000001);

            TH1D * genMassVsPt = (TH1D*)genMass_1->ProjectionX("genMassVsPt", bin1, bin2-1);
            genMassVsPt->Draw("EPL");
            pcPt_1->Update();

            TAxis *axs        = genMassVsPt->GetXaxis();
            int binlow        = axs->FindBin(massCount_low);
            int binhi         = axs->FindBin(massCount_high);

            double int_sig_gen;
            double int_sig_gen_sqr;
            for(Int_t bin = binlow; bin<=binhi; bin++) {
                //    cout << "	  int_sig += dimuonsGlobalInvMassVsPt[ih]->GetBinContent(bin);"<<int_sigpow_gen <<"+="<< "bin" << bin << " content"<<genMassVsPt->GetBinContent(bin)<<endl;
                int_sig_gen += genMassVsPt->GetBinContent(bin);
                int_sig_gen_sqr += pow(genMassVsPt->GetBinContent(bin),2);
            }


            gen_pt[ih] = int_sig_gen;//genMassVsPt->GetEntries();
            cout<<" gen entries : "<< gen_pt[ih]<<endl;
            egen_pt[ih] =int_sig_gen_sqr;

        }
    }
    else {
        if (nBins == 2)  pcPt_1->Divide(2,1);
        if (nBins == 3 || nBins == 4)  pcPt_1->Divide(2,2);
        if (nBins == 5 || nBins == 6)  pcPt_1->Divide(3,2);

    }


    //___________________________________________________________________________________
    // Fit Function
    //  const char *name_fit[] = {"  ", "RBWPol1", "GausPol1", "RBWGausPol2"};
    int nParam[]           = {0,6,6,7};
    int nFitParam          = nParam[nFitFunction];
    TF1 *RBWPOL=0;
    if(nFitFunction == 1) RBWPOL = new TF1("RBWPOL", RBWPol2,     0, 200, nFitParam);
    if(nFitFunction == 2) RBWPOL = new TF1("RBWPOL", GausPol2,    0, 200, nFitParam);
    if(nFitFunction == 3) RBWPOL = new TF1("RBWPOL", RBWGausPol2, 0, 200, nFitParam);
    TF1 *EXP               = new TF1("EXP", Exp, 0, 200, 2);

    RBWPOL->SetLineWidth(1);
    RBWPOL->SetParameter(1, MassZ0);
    RBWPOL->SetParameter(2, WidthZ0);

    RBWPOL->SetParLimits(1, 0.9*MassZ0, 1.1*MassZ0);
    RBWPOL->SetParLimits(2, 0.1*WidthZ0, 5.0*WidthZ0);

    if(nFitFunction  == 1 || nFitFunction  == 2) RBWPOL->FixParameter(5, 0);
    if(nFitFunction  == 3 || nFitFunction  == 4)  {
        RBWPOL->SetParameter(3, WidthZ0);
        RBWPOL->SetParLimits(3, 0.1, 20);
        RBWPOL->FixParameter(2, WidthZ0);

        RBWPOL->FixParameter(4, 0);   // for no bkg
        RBWPOL->FixParameter(5, 0);   // for no bkg
        RBWPOL->FixParameter(6, 0);
    }


    //___________________________________________________________________________________
    // Efficiency

    double yld_cat_1[10], cyld_cat_1[10], eyld_cat_1[10], ceyld_cat_1[10];
    double Eff_cat_1[10], errEff_cat_1[10];


    ///// Write the spectra
    sprintf(szBuf,"fileSpecta%d.root", getYield);
    //  TFile *fileSpectra = new TFile(szBuf, "recreate");


    //___________________________________________________________________________________
    // Drawing
    // Category _1
    TLegend *pLegCategory = new TLegend(.66, .74, .92, .94);
    //  pLegCategory = new TLegend(.1, .82, .50, .93);
    pLegCategory->SetBorderSize(0);
    pLegCategory->SetFillStyle(0);
    pLegCategory->SetFillColor(0);
    pLegCategory->SetTextSize(0.03);
    //  pLegCategory->AddEntry(RBWPOL," CMS Preliminary", " ");

    pLegCategory->AddEntry(RBWPOL," CMS Pb+Pb ", " ");
    pLegCategory->AddEntry(RBWPOL," #sqrt{s_{NN}} = 2.76 TeV ", " ");
    pLegCategory->AddEntry(RBWPOL," #int Ldt  = 6.6 #mub^{-1} ", " ");

    //  pLegCategory->AddEntry(RBWPOL," Global-Global ", "");
    //pLegCategory->AddEntry(RBWPOL," |y| < 2.4 ", "P");
    //pLegCategory->AddEntry(RBWPOL," Run# 150431-151027 ", "P");

    TLegend *legend_1[12];
    for(int i=0; i<12; i++) {
        if(isFit) legend_1[i] = new TLegend(.13, .66, .52, 0.94);
        if(!isFit) legend_1[i] = new TLegend(.13, .66, .52, 0.94 );
        //    legend_1[i] = new TLegend(.68, .62, .91, 0.93 );
        legend_1[i]->SetBorderSize(0);
        legend_1[i]->SetFillStyle(0);
        legend_1[i]->SetFillColor(0);
        legend_1[i]->SetTextSize(0.028);
    }

    int bin_bound[100];
    TH1D *dimuonsGlobalInvMassVsPt[10];
    TH1D *dimuonsGlobalInvMassVsPtS[10];
    TH1D *service = (TH1D*)phDimuMass_1->ProjectionY("service");

    //  cout << endl << label << "    Yield      Mass (GeV)    Width (GeV)    GauWidth    chi2/ndf " << endl << endl;
    for (Int_t ih = 0; ih < nBins; ih++)  {
        pcPt_1->cd(ih+1);
        gPad->SetTickx();
        gPad->SetTicky();

        // Project 1 D
        bin_bound[ih]   = service->FindBin(binEdge[ih]+0.0000001);
        bin_bound[ih+1] = service->FindBin(binEdge[ih+1]+0.0000001);

        sprintf(szBuf,"Z0_1_pt_%d",ih);
        dimuonsGlobalInvMassVsPt[ih]  = (TH1D*)phDimuMass_1->ProjectionX(szBuf, bin_bound[ih], bin_bound[ih+1]-1+1, "e");
        sprintf(szBuf,"Z0_1S_pt_%d",ih);
        dimuonsGlobalInvMassVsPtS[ih] = (TH1D*)phDimuMass_1S->ProjectionX(szBuf, bin_bound[ih], bin_bound[ih+1]-1+1);
        cout << "reco entries" << dimuonsGlobalInvMassVsPt[ih]->GetEntries() <<endl;
        if(doPt || doY) {
            sprintf(szBuf," %s [%.1f, %.1f]",
                    label,
                    service->GetBinLowEdge(bin_bound[ih]),
                    service->GetBinLowEdge(bin_bound[ih+1]-1) + service->GetBinWidth(bin_bound[ih+1]));
        }

        if(doCent) {
            sprintf(szBuf," %s [%.1f, %.1f] %s",
                    label,
                    2.5*service->GetBinLowEdge(bin_bound[ih]),
                    2.5*(service->GetBinLowEdge(bin_bound[ih+1]-1) + service->GetBinWidth(bin_bound[ih+1])), "%");
        }

        dimuonsGlobalInvMassVsPt[ih]->Rebin(nrebin);
        dimuonsGlobalInvMassVsPtS[ih]->Rebin(nrebin);

        // -------- Fit Function + Bkg Function
        double part[20];
        dimuonsGlobalInvMassVsPt[ih]->Fit("EXP","LEQ", "", 34, 60);
        EXP->GetParameters(part);
        if(nFitFunction  == 4) {
            RBWPOL->FixParameter(4, part[0]);
            RBWPOL->FixParameter(5, part[1]);
        }

        if(isFit) {
            //dimuonsGlobalInvMassVsPt[ih]->Fit("RBWPOL","LEQ", "", massFit_low, massFit_high);
            //TFitResultPtr r =
            dimuonsGlobalInvMassVsPt[ih]->Fit("RBWPOL","LEQS0","", massFit_low, massFit_high);
            //	if(r->IsValid()) r->Print();
            //else cout<<"Fit not valid!!!\n"<<endl;
        }

        //------  get fit parameters
        double par[20];
        RBWPOL->GetParameters(par);

        float GGphDimuMass = RBWPOL->GetParameter(1);
        float GGZ0Width    = RBWPOL->GetParameter(2);
        float GauWidth     =0;
        if(nFitFunction  == 3 || nFitFunction  == 4) GauWidth = RBWPOL->GetParameter(3);

        double chisq      = RBWPOL->GetChisquare();
        int ndf           = RBWPOL->GetNDF();
        double chisqdf    =1000;
        if(ndf!=0) chisqdf=chisq/ndf;

        // +++ set backgroudn fit
        sprintf(szBuf,"pt_1B_%d",ih);
        TF1 *bkgFit_1 = new TF1(szBuf, Pol2, massFit_low, massFit_high, 3);
        // if(nFitFunction  == 4) bkgFit_1 = new TF1(namePt_1B, Exp, massFit_low, massFit_high, 2);

        bkgFit_1->SetParameters(&par[3]);
        if(nFitFunction  == 3 || nFitFunction  == 4) bkgFit_1->SetParameters(&par[4]);

        // ----------  Integrated Yield
        //    float massCount_low =GGphDimuMass-(4.0*GGZ0Width);
        //    float massCount_high =GGphDimuMass+(4.0*GGZ0Width);

        TAxis *axs        = dimuonsGlobalInvMassVsPt[ih]->GetXaxis();
        int binlow        = axs->FindBin(massCount_low);
        int binhi         = axs->FindBin(massCount_high);
        Double_t bin_size = (1.0*dimuonsGlobalInvMassVsPt[ih]->GetNbinsX())/(axs->GetXmax() - axs->GetXmin());

        Float_t int_sig   = 0.0;
        Float_t int_sig_sqr   = 0.0;
        for(Int_t bin = binlow; bin<=binhi; bin++) {
            //	  cout << "	  int_sig += dimuonsGlobalInvMassVsPt[ih]->GetBinContent(bin);"<<int_sig <<"+="<< "bin" << bin << " content"<<dimuonsGlobalInvMassVsPt[ih]->GetBinContent(bin)<<endl;
            int_sig += dimuonsGlobalInvMassVsPt[ih]->GetBinContent(bin);
            int_sig_sqr += pow(dimuonsGlobalInvMassVsPt[ih]->GetBinContent(bin),2);
        }

        if(getYield == 2) {
            int_sig =  RBWPOL->Integral(massCount_low, massCount_high)*bin_size;
            yld_cat_1[ih]   = int_sig - bin_size*bkgFit_1->Integral(massCount_low, massCount_high);
            eyld_cat_1[ih] = TMath::Sqrt(int_sig + bin_size*bkgFit_1->Integral(massCount_low, massCount_high) );
        }

        else {
            yld_cat_1[ih]   = int_sig ;
            eyld_cat_1[ih] = int_sig_sqr;
        }
        cout << "int_sig - bin_size*bkgFit_1->Integral(massCount_low, massCount_high);" << int_sig<< "  -"<< bin_size<<"*"<<bkgFit_1->Integral(massCount_low, massCount_high)<< " with low"<< massCount_low<<" high "<< massCount_high<<endl;
        //// Printing /////
        cout <<  PT[ih] << "    " << yld_cat_1[ih] << " +- " << eyld_cat_1[ih] <<"     " << GGphDimuMass << "    " << GGZ0Width  << "    " << GauWidth <<"   "<< chisq << "/" << ndf  << endl;


        // -------------- Draw
        //    dimuonsGlobalInvMassVsPt[ih]->SetMinimum(-.05*dimuonsGlobalInvMassVsPt[ih]->GetMaximum());

        if(isLog) gPad->SetLogy(1);

        TColor *pal    = new TColor();
        Int_t kblue    = pal->GetColor(9,0,200);
        //    Int_t korange  = pal->GetColor(101, 42,  0);

        // +++ opposite charge
        dimuonsGlobalInvMassVsPt[ih]->SetMarkerStyle(21);
        dimuonsGlobalInvMassVsPt[ih]->SetMarkerColor(kblue);
        dimuonsGlobalInvMassVsPt[ih]->SetLineColor(kblue);
        dimuonsGlobalInvMassVsPt[ih]->SetMarkerSize(1.1);
        dimuonsGlobalInvMassVsPt[ih]->GetXaxis()->SetTitle("Dimuon mass (GeV/c^{2})");
        dimuonsGlobalInvMassVsPt[ih]->GetYaxis()->SetTitle("dN/dM (2 GeV/c^{2})^{-1}");

        dimuonsGlobalInvMassVsPt[ih]->GetXaxis()->SetRangeUser(massDraw_low,massDraw_high);
        //    dimuonsGlobalInvMassVsPt[ih]->Add(dimuonsGlobalInvMassVsPtS[ih], -1);

        pcPt_1->cd(ih+1);


        dimuonsGlobalInvMassVsPt[ih]->DrawCopy("EPLsame");

        // pp data

        TAxis *axs1   = Zmumu->GetXaxis();
        int ll        = axs1->FindBin(massCount_low);
        int hh        = axs1->FindBin(massCount_high);

        double scalefactor =  yld_cat_1[ih]/Zmumu->Integral(ll, hh);

        cout << Zmumu->Integral(ll, hh) << endl;

        Zmumu->Scale(scalefactor);

        Zmumu->SetFillColor(19);

        Zmumu->Draw("same");

        dimuonsGlobalInvMassVsPt[ih]->DrawCopy("EPLsame");

        //    dimuonsGlobalInvMassVsPt[ih]->Draw("B");

        // +++ same charge
        dimuonsGlobalInvMassVsPtS[ih]->SetMarkerStyle(8);
        dimuonsGlobalInvMassVsPtS[ih]->SetMarkerColor(46);
        dimuonsGlobalInvMassVsPtS[ih]->SetLineColor(46);

        dimuonsGlobalInvMassVsPtS[ih]->SetMarkerSize(1.1);
        dimuonsGlobalInvMassVsPtS[ih]->DrawCopy("EPsame");


        // background
        //    RBWPOL->SetLineColor(kblue);
        bkgFit_1->SetLineColor(46);
        bkgFit_1->SetLineWidth(1);
        //    if(isFit) bkgFit_1->Draw("same");

        // ++++ legend
        pLegCategory->Draw("same");


        //    legend_1[ih]->AddEntry(dimuonsGlobalInvMassVsPt[ih]," Global-Global", " ");

        legend_1[ih]->AddEntry(dimuonsGlobalInvMassVsPt[ih]," |#eta^{#mu}| < 2.4, p_{T}^{#mu} > 10 GeV/c ", "");
        legend_1[ih]->AddEntry(dimuonsGlobalInvMassVsPt[ih]," Unlike Sign ", "LP");
        legend_1[ih]->AddEntry(dimuonsGlobalInvMassVsPtS[ih]," Like Sign ", "LP");
        legend_1[ih]->AddEntry(Zmumu," pp Data ", "L");




        //    legend_1[ih]->AddEntry(dimuonsGlobalInvMassVsPt[ih], text, "");


        sprintf(szBuf, "N=%1.0f #pm %1.1f ", yld_cat_1[ih], sqrt(yld_cat_1[ih]) );

        legend_1[ih]->AddEntry(dimuonsGlobalInvMassVsPt[ih], szBuf, "");

        //    sprintf(label_1, "N_{Z^{0}} = 27");

        sprintf(szBuf, "mass = %1.2f #pm %1.2f GeV/c^{2}", RBWPOL->GetParameter(1), RBWPOL->GetParError(1));
        //    if(isFit) legend_1[ih]->AddEntry(dimuonsGlobalInvMassVsPt[ih],szBuf, "");

        sprintf(szBuf, "#sigma_{Gauss} = %1.2f #pm %1.2f GeV/c^{2}", RBWPOL->GetParameter(2), RBWPOL->GetParError(2));

        if(nFitFunction ==3 || nFitFunction  == 4)
            sprintf(szBuf, "#sigma_{Gauss} = %1.2f #pm %1.2f GeV/c^{2}", RBWPOL->GetParameter(3), RBWPOL->GetParError(3));

        //    if(isFit) legend_1[ih]->AddEntry(dimuonsGlobalInvMassVsPt[ih], szBuf, "");

        sprintf(szBuf, "#chi^{2}/ndf = %1.2f / %d", chisq, ndf);

        //    if(isFit) legend_1[ih]->AddEntry(dimuonsGlobalInvMassVsPt[ih], label_4, "");

        legend_1[ih]->Draw("same");

        pcPt_1->Update();
    }

    cout << endl << endl;


    TGraphErrors *Z0pt_cat_1 = new TGraphErrors(nBins, PT, yld_cat_1, mom_err, eyld_cat_1);
    Z0pt_cat_1->SetMarkerStyle(20);
    Z0pt_cat_1->SetMarkerColor(2);
    Z0pt_cat_1->GetXaxis()->SetTitle(label);
    Z0pt_cat_1->GetYaxis()->SetTitle("counts");

    TCanvas *pc2 = new TCanvas("pc2","pc2");
    Z0pt_cat_1->SetMinimum(0.0);
    Z0pt_cat_1->SetName("Z0pt_cat_1");
    Z0pt_cat_1->Draw("AP");


    TGraphErrors *Z0ptC_cat_1_gen = new TGraphErrors(nBins, PT, gen_pt, mom_err, egen_pt);
    //  Z0ptC_cat_1_gen->SetMarkerStyle(23);
    //Z0ptC_cat_1_gen->SetMarkerColor(3);
    //Z0ptC_cat_1_gen->Draw("AP");


    pLegCategory->Draw("same");

    Z0pt_cat_1->Write();
    pLegCategory->Write();


    //    gPad->Print("Pt_Z0YieldCat_1.png");
    pcPt_1->Print("Pt_Z0YieldCat_1.png");


    cout << endl << endl;




    //////////////////////////////////////////////////////////////////////////////

    // Efficiency correction
    if(doMc)  {
        ofstream fileout("correction.txt");
        cout << label << "   Eff_cat_1  " << endl;

        for (Int_t ih = 0; ih < nBins; ih++)  {
            Eff_cat_1[ih] = yld_cat_1[ih]/gen_pt[ih];

            errEff_cat_1[ih] = sqrt( (pow(Eff_cat_1[ih]/yld_cat_1[ih],2))*eyld_cat_1[ih]
                                     +(pow((1-Eff_cat_1[ih]/yld_cat_1[ih]),2))*( yld_cat_1[ih]-gen_pt[ih]/ yld_cat_1[ih]));
            //	  errEff_cat_1[ih] = sqrt( (pow(Eff_cat_1[ih]/yld_cat_1[ih],2))*eyld_cat_1[ih]
            //			   +(pow((1-Eff_cat_1[ih]/yld_cat_1[ih]),2))*event failing);


            //	fileout << PT[ih] <<"   "<< Eff_cat_1[ih] << "   " << Eff_cat_2[ih] <<"    " << Eff_cat_3[ih] << endl;
            //	cout <<"    " << PT[ih] <<"      "<< Eff_cat_1[ih] << "      " << Eff_cat_2[ih] << "      " << Eff_cat_3[ih] << endl;

            fileout << PT[ih] <<"   "<< Eff_cat_1[ih] << "   " << errEff_cat_1[ih] << endl;
            cout <<"    " << PT[ih] <<"    "<< Eff_cat_1[ih] << " +- " << errEff_cat_1[ih] << endl;
            cyld_cat_1[ih] = Eff_cat_1[ih];
            ceyld_cat_1[ih] = errEff_cat_1[ih];

        }
    }
    else {
        ifstream filein("correction.txt");
        cout <<  label << " yld_cat_1 "  << "  efficiency " <<  " corr. yld_cat_1  " << endl;
        for (Int_t ih = 0; ih < nBins; ih++)  {

            //      filein >> PT[ih] >>  Eff_cat_1[ih] >>  Eff_cat_2[ih]  >>  Eff_cat_3[ih] ;
            //      cout << "       " << PT[ih] << "      "<< yld_cat_1[ih] << "       " << yld_cat_2[ih] <<"      " <<  yld_cat_3[ih] << endl;

            filein >> PT[ih] >>  Eff_cat_1[ih]  >> errEff_cat_1[ih];
            cout << "    " << PT[ih] << "     " << yld_cat_1[ih] << "     " << Eff_cat_1[ih] << "     " << yld_cat_1[ih]/Eff_cat_1[ih] << endl;
            cyld_cat_1[ih] = yld_cat_1[ih]/Eff_cat_1[ih];
            ceyld_cat_1[ih] = eyld_cat_1[ih]/Eff_cat_1[ih];

        }
    }

    //  TF1 *EXPA = new TF1("EXPA", Exp, 0, 100, 2);

    TGraphErrors *Z0ptC_cat_1 = new TGraphErrors(nBins, PT, cyld_cat_1, mom_err, ceyld_cat_1);
    Z0ptC_cat_1->SetMarkerStyle(20);
    Z0ptC_cat_1->SetMarkerColor(2);
    Z0ptC_cat_1->GetXaxis()->SetTitle(label);
    Z0ptC_cat_1->GetYaxis()->SetTitle("Acc x Eff");
    //  if(part == 2) Z0ptC_cat_1->Fit("EXPA","LEQ", "", 7, 16);


    new TCanvas;
    Z0ptC_cat_1->SetMinimum(0.0);
    Z0ptC_cat_1->SetMaximum(0.8);
    Z0ptC_cat_1->SetName("Z0ptC_cat_1");
    Z0ptC_cat_1->Draw("AP");


    pLegCategory->Draw("same");

    cout << endl << endl;

    Z0ptC_cat_1->Write();

}
int main(int argc, char** argv)
{ 
 TDRStyle();
 
 gStyle->SetPadTopMargin(0.11);
 gStyle->SetPadLeftMargin(0.07);
 gStyle->SetPadRightMargin(0.23);
 gStyle->cd(); 
 
 
 std::cout << " " << std::endl;
 std::cout << " " << std::endl;
 std::cout << "   ___|                                       _)                           \\  |   ___|         /      __ \\     \\  __ __|   \\     " << std::endl;
 std::cout << "  |       _ \\   __ `__ \\   __ \\    _` |   __|  |   __|   _ \\   __ \\       |\\/ |  |            /       |   |   _ \\    |    _ \\    " << std::endl;
 std::cout << "  |      (   |  |   |   |  |   |  (   |  |     | \\__ \\  (   |  |   |      |   |  |           /        |   |  ___ \\   |   ___ \\   " << std::endl;
 std::cout << " \\____| \\___/  _|  _|  _|  .__/  \\__,_| _|    _| ____/ \\___/  _|  _|     _|  _| \\____|     _/        ____/ _/    _\\ _| _/    _\\  " << std::endl;
 std::cout << "                          _|                                                                                                     " << std::endl;
 std::cout << " " << std::endl;
 std::cout << " " << std::endl;
 std::cout << "     ___ \\   __ \\        " << std::endl;
 std::cout << "       ) |  |   |          " << std::endl;
 std::cout << "      __/   |   |          " << std::endl;
 std::cout << "    _____| ____/           " << std::endl;
 std::cout << " " << std::endl;
 std::cout << " " << std::endl;
 
 
 
 char normal[] = { 0x1b, '[', '0', ';', '3', '9', 'm', 0 };
 char black[] = { 0x1b, '[', '0', ';', '3', '0', 'm', 0 };
 char red[] = { 0x1b, '[', '0', ';', '3', '1', 'm', 0 };
 char green[] = { 0x1b, '[', '0', ';', '3', '2', 'm', 0 };
 char yellow[] = { 0x1b, '[', '0', ';', '3', '3', 'm', 0 };
 char blue[] = { 0x1b, '[', '0', ';', '3', '4', 'm', 0 };
 char purple[] = { 0x1b, '[', '0', ';', '3', '5', 'm', 0 };
 char cyan[] = { 0x1b, '[', '0', ';', '3', '6', 'm', 0 };
 char Lgray[] = { 0x1b, '[', '0', ';', '3', '7', 'm', 0 };
 char Dgray[] = { 0x1b, '[', '0', ';', '3', '8', 'm', 0 };
 char Bred[] = { 0x1b, '[', '1', ';', '3', '1', 'm', 0 };
 //for bold colors, just change the 0 after the [ to a 1
 
 EColor vColor[1000] = {
  (EColor) (kRed+1),
  (EColor) (kRed+3),
  (EColor) (kGray+1),
  (EColor) (kAzure-2),
  (EColor) (kAzure-9),
  (EColor) (kYellow),
  (EColor) (kGreen+2),
//   
  kGreen,
  //kMagenta,(EColor) (kMagenta+1),(EColor) (kMagenta+2),
  kTeal,//(EColor) (kTeal+1),
  kRed,
  kGray,
  kOrange,(EColor) (kOrange+1),
  kBlue,//(EColor)(kBlue+1),(EColor) (kBlue+2),
  (EColor) (kPink+2),//(EColor) (kPink+1),(EColor) (kPink+2),
  kViolet,
  kYellow,
  kGray,(EColor) (kGray+1),(EColor) (kViolet),(EColor) (kYellow),(EColor) (kGray)
 };
 
 
 
 
 //Check if all nedeed arguments to parse are there                                                                                                                               
 if(argc != 2)
 {
  std::cerr << ">>>>> analysis.cpp::usage: " << argv[0] << " configFileName" << std::endl ;
  return 1;
 }


 // Parse the config file                                                                                                          
 parseConfigFile (argv[1]) ;
 
 std::string treeName  = gConfigParser -> readStringOption("Input::treeName");
 std::string treeNameSelections = gConfigParser -> readStringOption("Input::treeNameSelections");
 std::string fileSamples = gConfigParser -> readStringOption("Input::fileSamples");
 std::string inputDirectory = gConfigParser -> readStringOption("Input::inputDirectory");
 
 std::string inputBeginningFile = "out_NtupleProducer_"; 
 try {
  inputBeginningFile = gConfigParser -> readStringOption("Input::inputBeginningFile");
 }
 catch (char const* exceptionString){
  std::cerr << " exception = " << exceptionString << std::endl;
 }
 std::cout << ">>>>> Input::inputBeginningFile  " << inputBeginningFile  << std::endl;  
 
 double LUMI = gConfigParser -> readDoubleOption("Input::Lumi");
 
 double LumiSyst = gConfigParser -> readDoubleOption("Input::LumiSyst");
 
 double Discovery = gConfigParser -> readDoubleOption("Input::Discovery");
 
 int Normalize = gConfigParser -> readIntOption("Input::Normalize");
 
 std::vector<std::string> SignalName;
 if (Discovery == 1) SignalName = gConfigParser -> readStringListOption("Input::SignalName");
 
 
 ///==== PU reweight (begin) ====
 bool doWeightFromFile = false; 
 try {
  doWeightFromFile = gConfigParser -> readStringOption("PU::doWeightFromFile");
 }
 catch (char const* exceptionString){
  std::cerr << " exception = " << exceptionString << std::endl;
 }
 std::cout << ">>>>> PU::doWeightFromFile  " << doWeightFromFile  << std::endl;  
 
 std::vector<double> PUMC;
 std::vector<double> PUDATA;
 PUclass PU;
 double sumPUMC = 0;
 double sumPUDATA = 0;
 TH1F* hPUMC;
 TH1F* hPUDATA;
 TH1F* hPUWeight;
 
 
 
 std::string nameWeight = "weight"; 
 if (doWeightFromFile) {
  try {
   nameWeight = gConfigParser -> readStringOption("PU::nameWeight");
  }
  catch (char const* exceptionString){
   std::cerr << " exception = " << exceptionString << std::endl;
  }
  std::cout << ">>>>> PU::nameWeight  " << nameWeight  << std::endl;  
 }
 
 if (!doWeightFromFile) {
  
  PUMC   = gConfigParser -> readDoubleListOption("PU::PUMC");
  PUDATA = gConfigParser -> readDoubleListOption("PU::PUDATA");
  
  std::cout << " PUMC.size()   = " << PUMC.size()   << std::endl;
  std::cout << " PUDATA.size() = " << PUDATA.size() << std::endl;
  
  if (PUMC.size() != PUDATA.size()) {
   std::cerr << " ERROR " << std::endl;
   return 1;
  }
  
  for (int itVPU = 0; itVPU < PUMC.size(); itVPU++ ){
   sumPUMC += PUMC.at(itVPU);  
  }
  for (int itVPU = 0; itVPU < PUDATA.size(); itVPU++ ){
   sumPUDATA += PUDATA.at(itVPU);  
  } 
  
  for (int itVPU = 0; itVPU < PUMC.size(); itVPU++ ){
   PU.PUWeight.push_back(PUDATA.at(itVPU) / PUMC.at(itVPU) * sumPUMC / sumPUDATA);
  }
  
  PU.Write("autoWeight.cxx");
  gROOT->ProcessLine(".L autoWeight.cxx");
  
  ///==== save PU distribution in TH1F ====
  hPUMC   = new TH1F("hPUMC","hPUMC",PUMC.size(),0,PUMC.size());
  hPUDATA = new TH1F("hPUDATA","hPUDATA",PUDATA.size(),0,PUDATA.size());
  hPUWeight = new TH1F("hPUWeight","hPUWeight",PUDATA.size(),0,PUDATA.size());
  
  for (int itVPU = 0; itVPU < PUMC.size(); itVPU++ ){
   hPUMC     -> SetBinContent(itVPU+1,PUMC.at(itVPU) / sumPUMC);
   hPUDATA   -> SetBinContent(itVPU+1,PUDATA.at(itVPU) / sumPUDATA);
   hPUWeight -> SetBinContent(itVPU+1,PUDATA.at(itVPU) / PUMC.at(itVPU) * sumPUMC / sumPUDATA);
  }
  
 }
 
 ///==== PU reweight (end) ====
 
 ///==== pT Higgs reweight (begin) ====
 std::string nameptHWeight; 
 try {
  nameptHWeight = gConfigParser -> readStringOption("Input::nameptHWeight");
 }
 catch (char const* exceptionString){
  std::cerr << " exception = " << exceptionString << std::endl;
 }
 std::cout << ">>>>> input::nameptHWeight  " << nameptHWeight  << std::endl;  
 if (nameptHWeight != ""){
  TString toLoad;
  //   toLoad = Form("cp %s ./",nameptHWeight.c_str());
  //   gROOT->ProcessLine(toLoad.Data());
  toLoad = Form(".L %s",nameptHWeight.c_str());
  gROOT->ProcessLine(toLoad.Data());
 }
 
 std::string nameptHWeightSample; 
 try {
  nameptHWeight = gConfigParser -> readStringOption("Input::nameptHWeightSample");
 }
 catch (char const* exceptionString){
  std::cerr << " exception = " << exceptionString << std::endl;
 }
 std::cout << ">>>>> input::nameptHWeightSample  " << nameptHWeightSample  << std::endl;  
 
 
 ///==== pT Higgs reweight (end) ====
 
 TTree *treeEffVect[100];
 TTree *treeJetLepVect[100];
 

 
  //  [iCut][iVar] 
 TString* infoString[20][30];
 TLatex *infoLatex[20][30]; 
 TCanvas* ccCanvas[20][30];
 TCanvas* ccCanvasPull[20][30];
 TCanvas* ccCanvasPullTrace[20][30];
 TH2F* histoSumMC[20][30];
 //  [iName][iCut][iVar]
 TH2F* histo[100][30][30];
 TH2F* histo_temp[100][20][30];

 //  [iName][iCut]
 double numEvents[100][30];
 
 char *nameSample[1000];
 char *nameHumanReadable[1000];
 char* xsectionName[1000];
 
 double Normalization[1000];
 double xsection[1000];
 char nameFileIn[1000];
 sprintf(nameFileIn,"%s",fileSamples.c_str());

 int numberOfSamples = ReadFile(nameFileIn, nameSample, nameHumanReadable, xsectionName); 
 
 ///==== list of variables to plot ====
 std::vector<std::pair<double, double> > vMin;
 std::vector<std::pair<double, double> > vMax;
 std::vector<std::pair<int, int> > vNBin;
 std::vector<std::pair<std::string, std::string> > vVarName;
 std::vector<std::pair<std::string, std::string> > vVarNameHR;
 std::string VarFile = gConfigParser -> readStringOption("Plot::VarFile");
 
 int numVar = ReadFileVar2D(VarFile,vMin,vMax,vNBin,vVarName,vVarNameHR);
  
 
//  double XSection  = gConfigParser -> readDoubleOption("Plot::XSection");
 
 ///==== list of selections to perform (NOT sequential additive selections) ====
 std::string CutFile = gConfigParser -> readStringOption("Selections::CutFile");

 std::string CutHRFile = "";
 try {
  CutHRFile = gConfigParser -> readStringOption("Selections::CutHRFile");
 }
 catch (char const* exceptionString){
  std::cerr << " exception = " << exceptionString << std::endl;
 }
 
 std::vector<std::string> vCut;
 std::vector<std::string> vCutHR;
 
 std::cout << " nCuts   = " << ReadFileCut(CutFile, vCut) << std::endl;
 if (CutHRFile != "") {
  std::cout << " nCutsHR = " << ReadFileCutHR(CutHRFile, vCutHR) << std::endl;
 }
 
 
 if (vCutHR.size() < vCut.size()) {
  int size1 = vCut.size();
  int size2 = vCutHR.size();
  for (int i=0; i<(size1-size2+2); i++) {
   vCutHR.push_back("test");
  }
 }
 
 ///==== output file ====
 std::string OutFileName    = gConfigParser -> readStringOption("Output::outFileName");
 std::cout << ">>>>> Output::outFileName  " << OutFileName  << std::endl;  
 
 TFile outFile(OutFileName.c_str(),"RECREATE");
 outFile.cd();
 
 ///==== Latinos flag ==== 
 bool  Latinos = false; 
 try {
  Latinos = gConfigParser -> readBoolOption("Input::Latinos");
 }
 catch (char const* exceptionString){
  std::cerr << " exception = " << exceptionString << std::endl;
 }
 std::cout << ">>>>> input::Latinos  " << Latinos  << std::endl;  
 
 ///==== debug flag ====
 
 bool  debug = false; 
 try {
  debug = gConfigParser -> readBoolOption("Input::debug");
 }
 catch (char const* exceptionString){
  std::cerr << " exception = " << exceptionString << std::endl;
 }
 std::cout << ">>>>> input::debug  " << debug  << std::endl;  
 
 ///==== program ====
 
 
 double start, end;
 start = clock();
 
 
 for (int iSample=0; iSample<numberOfSamples; iSample++){
  xsection[iSample] = atof(xsectionName[iSample]);
 }
 for (int iSample=0; iSample<numberOfSamples; iSample++){
  
  char nameFile[20000];
  sprintf(nameFile,"%s/%s%s.root",inputDirectory.c_str(),inputBeginningFile.c_str(),nameSample[iSample]);  
  TFile* f = new TFile(nameFile, "READ");
  
  treeEffVect[iSample] = (TTree*) f->Get(treeNameSelections.c_str());
  if (treeEffVect[iSample] != 0) {
   char nameTreeEff[100];
   sprintf(nameTreeEff,"treeEff_%d",iSample); 
   treeEffVect[iSample]->SetName(nameTreeEff);      
  }
  
  treeJetLepVect[iSample] = (TTree*) f->Get(treeName.c_str());
  char nameTreeJetLep[100];
  sprintf(nameTreeJetLep,"treeJetLep_%d",iSample); 
  treeJetLepVect[iSample]->SetName(nameTreeJetLep);
 }
 
 ///===== create map for joint sample ====
 
 std::vector<int> join_samples;
 std::vector<std::string> name_samples;
 for (int iSample=0; iSample<numberOfSamples; iSample++){
  name_samples.push_back(nameHumanReadable[iSample]);
  join_samples.push_back(-1);
 }
 
 
 std::vector<std::string> reduced_name_samples;
 std::vector<int>         reduced_name_samples_flag;
 for (int iSample = (numberOfSamples-1); iSample>= 0; iSample--){
  bool flag_name = false;
  for (unsigned int iName=0; iName<reduced_name_samples.size(); iName++){
   if (reduced_name_samples.at(iName) == name_samples.at(iSample)) flag_name = true;
  }
  if (flag_name == false) {
   reduced_name_samples.push_back(name_samples.at(iSample));
   reduced_name_samples_flag.push_back(-1);
  }
 }
 
 std::cout << " numberOfSamples = " << numberOfSamples << std::endl;
 
 for (int iSample = (numberOfSamples-1); iSample>= 0; iSample--){
  double XSection;
  int numEntriesBefore;
  double preselection_efficiency;
  if (treeEffVect[iSample] != 0) {   
   treeEffVect[iSample]->SetBranchAddress("XSection",&XSection);
   treeEffVect[iSample]->SetBranchAddress("numEntriesBefore",&numEntriesBefore);
   treeEffVect[iSample]->SetBranchAddress("preselection_efficiency",&preselection_efficiency);  
   treeEffVect[iSample]->GetEntry(0);
  }
  
  std::cout << " Xsection = " << XSection << " ~~~> " << xsection[iSample] << std::endl;
  XSection = xsection[iSample];
  
  if (numEntriesBefore != 0) {
   Normalization[iSample] = LUMI * XSection * preselection_efficiency / numEntriesBefore;
  }
  else {
   Normalization[iSample] = 0; 
  }    
  
  if (Latinos) Normalization[iSample] = XSection * LUMI / 1000.;
 }
 
 
 
 TLegend* leg = new TLegend(0.8,0.25,0.98,0.78);
 bool LegendBuilt = false;

 TString lumiName = Form("#splitline{L = %.1f pb^{-1}}{#splitline{#sqrt{s} = 7}{CMS preliminary}}", LUMI);
//  TString lumiName = Form("#sqrt{s}=7 TeV   L=%.1f pb^{-1}", LUMI);
 TLatex *latex = new TLatex(0.80, 0.90, lumiName); 
 latex->SetTextAlign(12);
 latex->SetNDC();
 latex->SetTextFont(42);
 latex->SetTextSize(0.03);
  
 ///==== get number in sample list that correspond to DATA ====
 int numDATA = -1;
 for (unsigned int iName=0; iName<reduced_name_samples.size(); iName++){
  if (reduced_name_samples.at(iName) == "DATA") {
   numDATA = iName;
  }
 }
 
 
 if (debug) std::cout << " Cut size = " << vCut.size() << " ~~ " << std::endl;
 std::cout.precision (2) ;
 
 ///==== cicle on selections ====
 for (unsigned int iCut = 0; iCut<vCut.size(); iCut++){
  TString Cut = Form ("%s",vCut.at(iCut).c_str());
  if (debug) std::cout << " Cut[" << iCut << ":" << vCut.size() << "] = " << Cut.Data() << " ~~ " << std::endl;
  ///==== cicle on variables to plot ====
  for (unsigned int iVar = 0; iVar<vVarName.size(); iVar++){  
   if (debug) std::cout << " Var[" << iVar << ":" << vVarName.size() << "] = " << vVarName.at(iVar).first << " && " << vVarName.at(iVar).second << " ~~ " << std::endl;
   ///==== initialize ====
   for (unsigned int iName=0; iName<reduced_name_samples.size(); iName++){
    reduced_name_samples_flag.at(iName) = -1;
   }
   
   ///==== cicle on samples ====
   for (int iSample = (numberOfSamples-1); iSample>= 0; iSample--){
    if (debug) std::cout << " Sample[" << iSample << ":" << numberOfSamples << "] = " << nameSample[iSample] << " ~~ " << std::endl;
    TString name_histo_temp = Form("%s_%d_%d_temp",nameSample[iSample], iCut, iVar);
    histo_temp[iSample][iCut][iVar] = new TH2F(name_histo_temp,name_histo_temp,vNBin.at(iVar).first,vMin.at(iVar).first, vMax.at(iVar).first,vNBin.at(iVar).second,vMin.at(iVar).second, vMax.at(iVar).second);
    char toDraw[1000];
    sprintf(toDraw,"%s:%s >> %s",vVarName.at(iVar).second.c_str(),vVarName.at(iVar).first.c_str(),name_histo_temp.Data());      

    histo_temp[iSample][iCut][iVar] -> Sumw2(); //---- così mette l'errore giusto!
    
    TString CutExtended;
    bool isData = false;
    for (unsigned int iName=0; iName<reduced_name_samples.size(); iName++){
     if (name_samples.at(iSample) == reduced_name_samples.at(iName)){
      if (iName == numDATA) {
       isData = true;
      }
     }
    }  
    if (!isData) {
     if (nameptHWeight != "" && name_samples.at(iSample) == nameptHWeightSample){
      if (!doWeightFromFile) {
       CutExtended = Form ("(%s) * autoWeight(numPUMC) * ptHWeight(ptH)",Cut.Data());    
      }
      else {
       CutExtended = Form ("(%s) * ptHWeight(ptH) * (%s)",Cut.Data(),nameWeight.c_str());    
      }
     }
     else {
      if (!doWeightFromFile) {
       CutExtended = Form ("(%s) * autoWeight(numPUMC)",Cut.Data());    
      }
      else {
       CutExtended = Form ("(%s) * (%s)",Cut.Data(),nameWeight.c_str());    
      }
     }
     //      CutExtended = Form ("(%s) * autoWeight(numPUMC) * ptHWeight(ptH)",Cut.Data());    
    }
    else {
     CutExtended = Form ("(%s)",Cut.Data());    
    }
    treeJetLepVect[iSample]->Draw(toDraw,CutExtended,"");
    
    if (Normalization[iSample]>0) { 
//      histo_temp[iSample][iCut][iVar] -> Sumw2();
     histo_temp[iSample][iCut][iVar] -> Scale(Normalization[iSample]); 
    }
    
//     std::cout << "Processing: " << blue << (((double) numberOfSamples - iSample)/numberOfSamples) << "% \r"  << normal << std::flush;
   } ///==== end cicle on samples ====
//    std::cout << "###";
  std::cout << "Processing: " << blue << (((double) iCut)/vCut.size())*100. << "% "  << normal <<  " -- " <<  blue << (((double) iVar)/vVarName.size())*100. << "% \r"  << normal << std::flush;   
  } ///==== end cicle on variables to plot ====
  //   std::cout << "***";
 } ///==== end cicle on selections ====
 std::cout << std::endl; 
 
 

 
 ///---- create "big" histos ----
 for (unsigned int iCut = 0; iCut<vCut.size(); iCut++){
  for (unsigned int iVar = 0; iVar<vVarName.size(); iVar++){
   ///---- initialize (begin) ----
   for (unsigned int iName=0; iName<reduced_name_samples.size(); iName++){
    reduced_name_samples_flag.at(iName) = -1;
   }
   ///---- initialize (end) ----
   for (int iSample = (numberOfSamples-1); iSample>= 0; iSample--){    
    for (unsigned int iName=0; iName<reduced_name_samples.size(); iName++){
     if (name_samples.at(iSample) == reduced_name_samples.at(iName) && iName == numDATA){
      if (reduced_name_samples_flag.at(iName) == -1){
       TString name_histoTot_temp = Form("%s_%d_%d_Tot_temp",reduced_name_samples.at(iName).c_str(),iCut, iVar);
       TString name_HR_histoTot_temp = Form("%s vs %s @ %s",vVarNameHR.at(iVar).second.c_str(),vVarNameHR.at(iVar).first.c_str(), vCutHR.at(iCut).c_str());
       //        TString name_HR_histoTot_temp = Form("%s %d %s",vVarNameHR.at(iVar).c_str(), iCut, reduced_name_samples.at(iName).c_str());
       histo[iName][iCut][iVar] = new TH2F(name_histoTot_temp,name_HR_histoTot_temp,vNBin.at(iVar).first,vMin.at(iVar).first, vMax.at(iVar).first,vNBin.at(iVar).second,vMin.at(iVar).second, vMax.at(iVar).second);
       histo[iName][iCut][iVar] -> Sumw2(); //---- così mette l'errore giusto!
       reduced_name_samples_flag.at(iName) = 1;
      }
      histo[iName][iCut][iVar] -> Add(histo_temp[iSample][iCut][iVar]);
     }
    }
   }
  }
 }
 
 
 if (Normalize == 1) { //---- normalize to Data ----
 for (unsigned int iCut = 0; iCut<vCut.size(); iCut++){
  for (unsigned int iVar = 0; iVar<vVarName.size(); iVar++){
   ///---- initialize (begin) ----
   for (unsigned int iName=0; iName<reduced_name_samples.size(); iName++){
    reduced_name_samples_flag.at(iName) = -1;
   }
   ///---- initialize (end) ----
   double data_int = histo[numDATA][iCut][iVar] -> Integral();
   double mc_int = 0;
   
   for (int iSample = (numberOfSamples-1); iSample>= 0; iSample--){
    for (unsigned int iName=0; iName<reduced_name_samples.size(); iName++){
     if (name_samples.at(iSample) == reduced_name_samples.at(iName) && iName != numDATA){
      mc_int += histo_temp[iSample][iCut][iVar] -> Integral();
     }
    }
   }
   
   std::cout << " data_int / mc_int = " << data_int / mc_int << std::endl;
   for (int iSample = (numberOfSamples-1); iSample>= 0; iSample--){ 
    histo_temp[iSample][iCut][iVar] -> Scale (data_int / mc_int);
    
    for (unsigned int iName=0; iName<reduced_name_samples.size(); iName++){
     if (name_samples.at(iSample) == reduced_name_samples.at(iName)  && iName != numDATA){
      if (reduced_name_samples_flag.at(iName) == -1){
       TString name_histoTot_temp = Form("%s_%d_%d_Tot_temp",reduced_name_samples.at(iName).c_str(),iCut, iVar);
       TString name_HR_histoTot_temp = Form("%s vs %s @ %s",vVarNameHR.at(iVar).second.c_str(),vVarNameHR.at(iVar).first.c_str(), vCutHR.at(iCut).c_str());
       //        TString name_HR_histoTot_temp = Form("%s %d %s",vVarNameHR.at(iVar).c_str(), iCut, reduced_name_samples.at(iName).c_str());
       histo[iName][iCut][iVar] = new TH2F(name_histoTot_temp,name_HR_histoTot_temp,vNBin.at(iVar).first,vMin.at(iVar).first, vMax.at(iVar).first,vNBin.at(iVar).second,vMin.at(iVar).second, vMax.at(iVar).second);
       histo[iName][iCut][iVar] -> Sumw2(); //---- così mette l'errore giusto!
       reduced_name_samples_flag.at(iName) = 1;
      }
      histo[iName][iCut][iVar] -> Add(histo_temp[iSample][iCut][iVar]);
     }
    }
   }
  }
 }
 
 }
 else { //---- normalize to Lumi
  
  for (unsigned int iCut = 0; iCut<vCut.size(); iCut++){
   for (unsigned int iVar = 0; iVar<vVarName.size(); iVar++){
    ///---- initialize (begin) ----
    for (unsigned int iName=0; iName<reduced_name_samples.size(); iName++){
     reduced_name_samples_flag.at(iName) = -1;
    }
    ///---- initialize (end) ----
    for (int iSample = (numberOfSamples-1); iSample>= 0; iSample--){
     
     for (unsigned int iName=0; iName<reduced_name_samples.size(); iName++){
      if (name_samples.at(iSample) == reduced_name_samples.at(iName) && iName != numDATA ){
       if (reduced_name_samples_flag.at(iName) == -1){
	TString name_histoTot_temp = Form("%s_%d_%d_Tot_temp",reduced_name_samples.at(iName).c_str(),iCut, iVar);
	TString name_HR_histoTot_temp = Form("%s vs %s @ %s",vVarNameHR.at(iVar).second.c_str(),vVarNameHR.at(iVar).first.c_str(), vCutHR.at(iCut).c_str());
	//        TString name_HR_histoTot_temp = Form("%s %d %s",vVarNameHR.at(iVar).c_str(), iCut, reduced_name_samples.at(iName).c_str());
	histo[iName][iCut][iVar] = new TH2F(name_histoTot_temp,name_HR_histoTot_temp,vNBin.at(iVar).first,vMin.at(iVar).first, vMax.at(iVar).first,vNBin.at(iVar).second,vMin.at(iVar).second, vMax.at(iVar).second);
	histo[iName][iCut][iVar] -> Sumw2(); //---- così mette l'errore giusto!
	reduced_name_samples_flag.at(iName) = 1;
       }
       histo[iName][iCut][iVar] -> Add(histo_temp[iSample][iCut][iVar]);
      }
     }
    }
   }
  }
 }
 
 
 //  [iCut][iVar]
 THStack* hs[100][100];
 
 std::cout << std::endl;
 
 ///==== cicle on selections ====
 for (unsigned int iCut = 0; iCut<vCut.size(); iCut++){
  ///==== cicle on variables to plot ====
  for (unsigned int iVar = 0; iVar<vVarName.size(); iVar++){
   TString nameStack = Form("%d_%d_stack",iCut,iVar);
   hs[iCut][iVar] = new THStack(nameStack,nameStack);
   
   for (unsigned int iName=0; iName<reduced_name_samples.size(); iName++){
    histo[iName][iCut][iVar]->GetXaxis()->SetTitle(vVarNameHR.at(iVar).first.c_str());
    histo[iName][iCut][iVar]->GetYaxis()->SetTitle(vVarNameHR.at(iVar).second.c_str());
    histo[iName][iCut][iVar]->SetMarkerColor(vColor[iName]);
    histo[iName][iCut][iVar]->SetLineColor(vColor[iName]);
    histo[iName][iCut][iVar]->SetFillColor(vColor[iName]);
    histo[iName][iCut][iVar]->SetLineWidth(2);
    histo[iName][iCut][iVar]->SetFillStyle(3001);
    
    bool isSig = false;
    for (std::vector<std::string>::const_iterator itSig = SignalName.begin(); itSig != SignalName.end(); itSig++){
     if (reduced_name_samples.at(iName) == *itSig) isSig = true;
    }
    
    if (!isSig && reduced_name_samples.at(iName) != "DATA") {
     hs[iCut][iVar]->Add(histo[iName][iCut][iVar]);
    }
    else {
     if (!isSig) {
      histo[iName][iCut][iVar]->SetMarkerStyle(20);
      histo[iName][iCut][iVar]->SetMarkerSize(1);
      histo[iName][iCut][iVar]->SetMarkerColor(kBlack);
      histo[iName][iCut][iVar]->SetLineColor(kBlack);
      histo[iName][iCut][iVar]->SetFillColor(kBlack);
      histo[iName][iCut][iVar]->SetLineWidth(2);
      histo[iName][iCut][iVar]->SetFillStyle(3001);  
     }
     else {
      histo[iName][iCut][iVar]->SetMarkerStyle(21);
      histo[iName][iCut][iVar]->SetMarkerSize(1);
      histo[iName][iCut][iVar]->SetLineWidth(2);
      histo[iName][iCut][iVar]->SetFillStyle(3001);  
     }
    }
   }
   ///==== histo sum MC ====    
   ///==== Add systrematic error ====
//    AddError(hs[iCut][iVar],LumiSyst);
   histoSumMC[iCut][iVar] = ((TH2F*)(hs[iCut][iVar]->GetStack()->Last()));
    
   ///==== legend ====
   if (!LegendBuilt){
    for (unsigned int iName=0; iName<reduced_name_samples.size(); iName++){
     leg->AddEntry(histo[iName][iCut][iVar],reduced_name_samples.at(iName).c_str(),"pf");    
     LegendBuilt = true;
    }
   }
  }
 }
 std::cout << std::endl << std::endl;
 
 
 
 LumiSyst = 0; ///---- bug fix
 

//  [iName][iCut][iVar]
 TCanvas* cCanvasAll[100][30][30];

 TCanvas* cCompareCut[100];
 TCanvas* cCompareVar[100];
 
 for (unsigned int iCut = 0; iCut<vCut.size(); iCut++){
  TString nameCanvas = Form("%d_Cut_Canvas",iCut);
  cCompareCut[iCut] = new TCanvas(nameCanvas,nameCanvas,400 * vVarName.size(),400);
  cCompareCut[iCut] -> Divide (vVarName.size(),1);
 }
 
 for (unsigned int iVar = 0; iVar<vVarName.size(); iVar++){ ///==== cicle on variables to plot ====
   TString nameCanvas = Form("%d_Var_Canvas",iVar);
   cCompareVar[iVar] = new TCanvas(nameCanvas,nameCanvas,400,400 * vCut.size());
   cCompareVar[iVar] -> Divide (1,vCut.size());
 }
 
 
 for (unsigned int iCut = 0; iCut<vCut.size(); iCut++){
  for (unsigned int iVar = 0; iVar<vVarName.size(); iVar++){
   TString nameCanvas = Form("%d_%d_Canvas",iCut,iVar);
   ccCanvas[iCut][iVar] = new TCanvas(nameCanvas,nameCanvas,400,400);
   for (unsigned int iName=0; iName<reduced_name_samples.size(); iName++){
    TString nameCanvasName = Form("%d_%d_%d_Canvas",iCut,iVar,iName);
    cCanvasAll[iName][iCut][iVar] = new TCanvas(nameCanvasName,nameCanvasName,400,400);
   }
  }
 } 
 
 ///==== cicle on selections ====
 for (unsigned int iCut = 0; iCut<vCut.size(); iCut++){
  ///==== cicle on variables to plot ====
  for (unsigned int iVar = 0; iVar<vVarName.size(); iVar++){
   ///==== draw in canvas ====
   
   for (unsigned int iName=0; iName<reduced_name_samples.size(); iName++){
    cCanvasAll[iName][iCut][iVar]->cd();
    gPad->SetLeftMargin(0.14);
    gPad->SetRightMargin(0.23);
    histo[iName][iCut][iVar]->Draw();
    histo[iName][iCut][iVar]->GetXaxis()->SetTitle(vVarNameHR.at(iVar).first.c_str());
    histo[iName][iCut][iVar]->GetYaxis()->SetTitle(vVarNameHR.at(iVar).second.c_str());
    gPad->SetLogz();
    gPad->SetGrid();
    leg->Draw();
    latex->Draw();
   }
   
   cCompareCut[iCut] -> cd(iVar+1);
   hs[iCut][iVar] ->Draw();
   hs[iCut][iVar]->GetXaxis()->SetTitle(vVarNameHR.at(iVar).first.c_str());
   hs[iCut][iVar]->GetYaxis()->SetTitle(vVarNameHR.at(iVar).second.c_str());
   gPad->SetLogz();
   gPad->SetGrid();
   leg->Draw();
   latex->Draw();
   
   cCompareVar[iVar] -> cd(iCut+1);
   hs[iCut][iVar] ->Draw("LEGO");
   hs[iCut][iVar]->GetXaxis()->SetTitle(vVarNameHR.at(iVar).first.c_str());
   hs[iCut][iVar]->GetYaxis()->SetTitle(vVarNameHR.at(iVar).second.c_str());
   gPad->SetLogz();
   gPad->SetGrid();
   leg->Draw();
   latex->Draw();

   ccCanvas[iCut][iVar]-> cd();
   hs[iCut][iVar]->Draw("LEGO");
   hs[iCut][iVar]->GetXaxis()->SetTitle(vVarNameHR.at(iVar).first.c_str());
   hs[iCut][iVar]->GetYaxis()->SetTitle(vVarNameHR.at(iVar).second.c_str());
   gPad->SetLogz();
   gPad->SetGrid();
   leg->Draw();
   latex->Draw();

   for (unsigned int iName=0; iName<reduced_name_samples.size(); iName++){
    
    bool isSig = false;
    for (std::vector<std::string>::const_iterator itSig = SignalName.begin(); itSig != SignalName.end(); itSig++){
     if (reduced_name_samples.at(iName) == *itSig) isSig = true;
    }
    
    if (isSig || reduced_name_samples.at(iName) == "DATA") {
     cCompareCut[iCut] -> cd(iVar+1);
//      histo[iName][iCut][iVar]->Draw("EsameB");
//      histo[iName][iCut][iVar]->Draw("same");
     
     cCompareVar[iVar] -> cd(iCut+1);
//      histo[iName][iCut][iVar]->Draw("EsameB");
//      histo[iName][iCut][iVar]->Draw("same");
     
     ccCanvas[iCut][iVar]-> cd();
//      histo[iName][iCut][iVar]->Draw("EsameB");
//      histo[iName][iCut][iVar]->Draw("same");
    }
   }
   
   cCompareCut[iCut] -> cd(iVar+1);
   leg->Draw();
   cCompareVar[iVar] -> cd(iCut+1);
   leg->Draw();
   ccCanvas[iCut][iVar]-> cd();
   leg->Draw();
   
  } ///==== end cicle on variables to plot ====
 } ///==== end cicle on selections ====
 
 std::cerr << " ******************************************* end *******************************************" << std::endl;
 end = clock();
 std::cout <<"Time = " <<  ((double) (end - start)) << " (a.u.)" << std::endl;  
 
 
 
 ///==== save output ====
 outFile.cd();
 
 outFile.cd();
 outFile.mkdir("PU");
 outFile.cd("PU");
 
 if (!doWeightFromFile) { 
  hPUMC     -> Write();
  hPUDATA   -> Write();
  hPUWeight -> Write();
 }
 
 outFile.cd();
 outFile.mkdir("Cut");
 outFile.cd("Cut");
 for (unsigned int iCut = 0; iCut<vCut.size(); iCut++){
  cCompareCut[iCut] -> Write();
  TString nameCut = Form ("Cut_%d",iCut);
  TString Cut = Form ("%s",vCut.at(iCut).c_str());
  TNamed nameCutNamed (nameCut,Cut);
  nameCutNamed.Write();
 }
 
 outFile.cd();
 outFile.mkdir("Var");
 outFile.cd("Var");
 for (unsigned int iVar = 0; iVar<vVarName.size(); iVar++){
  cCompareVar[iVar] -> Write();
 }
 
 outFile.cd();
 TDirectory* cdAll = (TDirectory*) outFile.mkdir("All");
 cdAll->mkdir("Var");
 outFile.cd("All/Var");
 for (unsigned int iCut = 0; iCut<vCut.size(); iCut++){
  for (unsigned int iVar = 0; iVar<vVarName.size(); iVar++){
   ccCanvas[iCut][iVar]-> Write();
  }
 }
 
 
 outFile.cd();
 outFile.mkdir("Data");
 outFile.cd("Data");
 for (unsigned int iCut = 0; iCut<vCut.size(); iCut++){
  for (unsigned int iVar = 0; iVar<vVarName.size(); iVar++){
   hs[iCut][iVar] -> Write() ;
   for (unsigned int iName=0; iName<reduced_name_samples.size(); iName++){
    histo[iName][iCut][iVar] -> Write();
    //     bool isSig = false;
    //     for (std::vector<std::string>::const_iterator itSig = SignalName.begin(); itSig != SignalName.end(); itSig++){
     //      if (reduced_name_samples.at(iName) == *itSig) isSig = true;
    //     }
    //     if (isSig || reduced_name_samples.at(iName) == "DATA") {
     //      histo[iName][iCut][iVar] -> Write();
    //     }
   }
   //    ((TH1F*)(hs[iCut][iVar] ->GetStack()->Last()))->Write() ;
   TH1F* tempH =  ((TH1F*)(hs[iCut][iVar] ->GetStack()->Last())) ;
   TString name = Form("All_%d_%d",iCut,iVar);
   tempH -> SetName(name);
   tempH -> Write();
  }
 }
 
 
 outFile.cd();
 cdAll->mkdir("CutVar");
 outFile.cd("All/CutVar");
 ///==== cicle on selections ====
 for (unsigned int iCut = 0; iCut<vCut.size(); iCut++){
  ///==== cicle on variables to plot ====
  for (unsigned int iVar = 0; iVar<vVarName.size(); iVar++){
   for (unsigned int iName=0; iName<reduced_name_samples.size(); iName++){
    cCanvasAll[iName][iCut][iVar]->Write();
   }
  }
 }
 outFile.cd();
   
 
 
 
 
 
 
 
 leg->Write();
 
}
Exemplo n.º 4
0
//this makes shape plots of MT2 distributions for several VSPT bins for various SM types (W,Z,ttbar,susy,data)
void UTMplots(){

gROOT->cd();
gROOT->SetStyle("Plain");
gStyle->SetPalette(1);
gStyle->SetOptStat(0);

TChain *LM6 = new TChain("MassTree");
TChain *WJets = new TChain("MassTree");
TChain *ZJets = new TChain("MassTree");
TChain *TTbar = new TChain("MassTree");
TChain *Data = new TChain("MassTree");

//read in trees
LM6->Add("dcap://t3se01.psi.ch:22125/pnfs/psi.ch/cms/trivcat/store/user/mmasciov/SUSY/MassTrees/MT2_V02-03-02/20130430_8TeV/SUSY-LM6-sftsht-8TeV-pythia6-Summer12-DR53X-PU-S10-START53-V7A-v1/*.root");
WJets->Add("dcap://t3se01.psi.ch:22125/pnfs/psi.ch/cms/trivcat/store/user/mmasciov/SUSY/MassTrees/MT2_V02-03-02/20130318_8TeV/WJetsToLNu-HT-400ToInf-8TeV-madgraph-Summer12-DR53X-PU-S10-START53-V7A-v1/*.root");
WJets->Add("dcap://t3se01.psi.ch:22125/pnfs/psi.ch/cms/trivcat/store/user/mmasciov/SUSY/MassTrees/MT2_V02-03-02/20130318_8TeV/WJetsToLNu-HT-400ToInf-8TeV-madgraph-v2-Summer12-DR53X-PU-S10-START53-V7A-v1/*.root");
ZJets->Add("dcap://t3se01.psi.ch:22125/pnfs/psi.ch/cms/trivcat/store/user/haweber/SUSY/MassTrees/MT2_V02-03-02/20130318_8TeV/ZJetsToNuNu-400-HT-inf-TuneZ2Star-8TeV-madgraph-Summer12-DR53X-PU-S10-START53-V7A-v1/*.root");
ZJets->Add("dcap://t3se01.psi.ch:22125/pnfs/psi.ch/cms/trivcat/store/user/haweber/SUSY/MassTrees/MT2_V02-03-02/20130318_8TeV/ZJetsToNuNu-400-HT-inf-TuneZ2Star-8TeV-madgraph-ext-Summer12-DR53X-PU-S10-START53-V7A-v1/*.root");
TTbar->Add("dcap://t3se01.psi.ch:22125/pnfs/psi.ch/cms/trivcat/store/user/casal/SUSY/MassTrees/MT2_V02-03-02/20130503_8TeV/TTJets-SemiLeptMGDecays-8TeV-madgraph-tauola-Summer12-DR53X-PU-S10-START53-V7C-v1/*.root");
int nd = Data->Add("dcap://t3se01.psi.ch:22125/pnfs/psi.ch/cms/trivcat/store/user/casal/SUSY/MassTrees/MT2_V02-03-02/20130318_8TeV/HT-Run2012A-13Jul2012-v1-2/*.root");
nd += Data->Add("dcap://t3se01.psi.ch:22125/pnfs/psi.ch/cms/trivcat/store/user/casal/SUSY/MassTrees/MT2_V02-03-02/20130318_8TeV/HT-Run2012A-recover-06Aug2012-v1-2/*.root");
nd += Data->Add("dcap://t3se01.psi.ch:22125/pnfs/psi.ch/cms/trivcat/store/user/casal/SUSY/MassTrees/MT2_V02-03-02/20130318_8TeV/JetHT-Run2012B-13Jul2012-v1-2/*.root");
nd += Data->Add("dcap://t3se01.psi.ch:22125/pnfs/psi.ch/cms/trivcat/store/user/casal/SUSY/MassTrees/MT2_V02-03-02/20130318_8TeV/JetHT-Run2012C-24Aug2012-v2-2/*.root");
nd += Data->Add("dcap://t3se01.psi.ch:22125/pnfs/psi.ch/cms/trivcat/store/user/casal/SUSY/MassTrees/MT2_V02-03-02/20130318_8TeV/JetHT-Run2012C-EcalRecover-11Dec2012-v1-2/*.root");
nd += Data->Add("dcap://t3se01.psi.ch:22125/pnfs/psi.ch/cms/trivcat/store/user/casal/SUSY/MassTrees/MT2_V02-03-02/20130318_8TeV/JetHT-Run2012C-PromptReco-v2-3/*.root");
nd += Data->Add("dcap://t3se01.psi.ch:22125/pnfs/psi.ch/cms/trivcat/store/user/casal/SUSY/MassTrees/MT2_V02-03-02/20130318_8TeV/JetHT-Run2012D-PromptReco-v1-3/*.root");
cout << nd << endl;

//define histograms
TH1D *LM6VSPT0   = new TH1D("LM6VSPT0"  ,"", 75, 0, 750); LM6VSPT0  ->Sumw2(); LM6VSPT0  ->SetLineColor(kBlack);  LM6VSPT0  ->SetLineWidth(2);
TH1D *LM6VSPT20  = new TH1D("LM6VSPT20" ,"", 75, 0, 750); LM6VSPT20 ->Sumw2(); LM6VSPT20 ->SetLineColor(kRed);    LM6VSPT20 ->SetLineWidth(2);
TH1D *LM6VSPT30  = new TH1D("LM6VSPT30" ,"", 75, 0, 750); LM6VSPT30 ->Sumw2(); LM6VSPT30 ->SetLineColor(kGreen);  LM6VSPT30 ->SetLineWidth(2);
TH1D *LM6VSPT40  = new TH1D("LM6VSPT40" ,"", 75, 0, 750); LM6VSPT40 ->Sumw2(); LM6VSPT40 ->SetLineColor(kBlue);   LM6VSPT40 ->SetLineWidth(2);
TH1D *LM6VSPT50  = new TH1D("LM6VSPT50" ,"", 75, 0, 750); LM6VSPT50 ->Sumw2(); LM6VSPT50 ->SetLineColor(kYellow); LM6VSPT50 ->SetLineWidth(2);
TH1D *LM6VSPT70  = new TH1D("LM6VSPT70" ,"", 75, 0, 750); LM6VSPT70 ->Sumw2(); LM6VSPT70 ->SetLineColor(kMagenta);LM6VSPT70 ->SetLineWidth(2);
TH1D *LM6VSPT100 = new TH1D("LM6VSPT100","", 75, 0, 750); LM6VSPT100->Sumw2(); LM6VSPT100->SetLineColor(kCyan);   LM6VSPT100->SetLineWidth(2);
TH1D *WJetsVSPT0   = new TH1D("WJetsVSPT0"  ,"", 75, 0, 750); WJetsVSPT0  ->Sumw2(); WJetsVSPT0  ->SetLineColor(kBlack);   WJetsVSPT0  ->SetLineWidth(2);
TH1D *WJetsVSPT20  = new TH1D("WJetsVSPT20" ,"", 75, 0, 750); WJetsVSPT20 ->Sumw2(); WJetsVSPT20 ->SetLineColor(kRed);     WJetsVSPT20 ->SetLineWidth(2);
TH1D *WJetsVSPT30  = new TH1D("WJetsVSPT30" ,"", 75, 0, 750); WJetsVSPT30 ->Sumw2(); WJetsVSPT30 ->SetLineColor(kGreen);   WJetsVSPT30 ->SetLineWidth(2);
TH1D *WJetsVSPT40  = new TH1D("WJetsVSPT40" ,"", 75, 0, 750); WJetsVSPT40 ->Sumw2(); WJetsVSPT40 ->SetLineColor(kBlue);    WJetsVSPT40 ->SetLineWidth(2);
TH1D *WJetsVSPT50  = new TH1D("WJetsVSPT50" ,"", 75, 0, 750); WJetsVSPT50 ->Sumw2(); WJetsVSPT50 ->SetLineColor(kYellow);  WJetsVSPT50 ->SetLineWidth(2);
TH1D *WJetsVSPT70  = new TH1D("WJetsVSPT70" ,"", 75, 0, 750); WJetsVSPT70 ->Sumw2(); WJetsVSPT70 ->SetLineColor(kMagenta); WJetsVSPT70 ->SetLineWidth(2);
TH1D *WJetsVSPT100 = new TH1D("WJetsVSPT100","", 75, 0, 750); WJetsVSPT100->Sumw2(); WJetsVSPT100->SetLineColor(kCyan);    WJetsVSPT100->SetLineWidth(2);
TH1D *ZJetsVSPT0   = new TH1D("ZJetsVSPT0"  ,"", 75, 0, 750); ZJetsVSPT0  ->Sumw2(); ZJetsVSPT0  ->SetLineColor(kBlack);   ZJetsVSPT0  ->SetLineWidth(2);
TH1D *ZJetsVSPT20  = new TH1D("ZJetsVSPT20" ,"", 75, 0, 750); ZJetsVSPT20 ->Sumw2(); ZJetsVSPT20 ->SetLineColor(kRed);     ZJetsVSPT20 ->SetLineWidth(2);
TH1D *ZJetsVSPT30  = new TH1D("ZJetsVSPT30" ,"", 75, 0, 750); ZJetsVSPT30 ->Sumw2(); ZJetsVSPT30 ->SetLineColor(kGreen);   ZJetsVSPT30 ->SetLineWidth(2);
TH1D *ZJetsVSPT40  = new TH1D("ZJetsVSPT40" ,"", 75, 0, 750); ZJetsVSPT40 ->Sumw2(); ZJetsVSPT40 ->SetLineColor(kBlue);    ZJetsVSPT40 ->SetLineWidth(2);
TH1D *ZJetsVSPT50  = new TH1D("ZJetsVSPT50" ,"", 75, 0, 750); ZJetsVSPT50 ->Sumw2(); ZJetsVSPT50 ->SetLineColor(kYellow);  ZJetsVSPT50 ->SetLineWidth(2);
TH1D *ZJetsVSPT70  = new TH1D("ZJetsVSPT70" ,"", 75, 0, 750); ZJetsVSPT70 ->Sumw2(); ZJetsVSPT70 ->SetLineColor(kMagenta); ZJetsVSPT70 ->SetLineWidth(2);
TH1D *ZJetsVSPT100 = new TH1D("ZJetsVSPT100","", 75, 0, 750); ZJetsVSPT100->Sumw2(); ZJetsVSPT100->SetLineColor(kCyan);    ZJetsVSPT100->SetLineWidth(2);
TH1D *TTbarVSPT0   = new TH1D("TTbarVSPT0"  ,"", 75, 0, 750); TTbarVSPT0  ->Sumw2(); TTbarVSPT0  ->SetLineColor(kBlack);   TTbarVSPT0  ->SetLineWidth(2);
TH1D *TTbarVSPT20  = new TH1D("TTbarVSPT20" ,"", 75, 0, 750); TTbarVSPT20 ->Sumw2(); TTbarVSPT20 ->SetLineColor(kRed);     TTbarVSPT20 ->SetLineWidth(2);
TH1D *TTbarVSPT30  = new TH1D("TTbarVSPT30" ,"", 75, 0, 750); TTbarVSPT30 ->Sumw2(); TTbarVSPT30 ->SetLineColor(kGreen);   TTbarVSPT30 ->SetLineWidth(2);
TH1D *TTbarVSPT40  = new TH1D("TTbarVSPT40" ,"", 75, 0, 750); TTbarVSPT40 ->Sumw2(); TTbarVSPT40 ->SetLineColor(kBlue);    TTbarVSPT40 ->SetLineWidth(2);
TH1D *TTbarVSPT50  = new TH1D("TTbarVSPT50" ,"", 75, 0, 750); TTbarVSPT50 ->Sumw2(); TTbarVSPT50 ->SetLineColor(kYellow);  TTbarVSPT50 ->SetLineWidth(2);
TH1D *TTbarVSPT70  = new TH1D("TTbarVSPT70" ,"", 75, 0, 750); TTbarVSPT70 ->Sumw2(); TTbarVSPT70 ->SetLineColor(kMagenta); TTbarVSPT70 ->SetLineWidth(2);
TH1D *TTbarVSPT100 = new TH1D("TTbarVSPT100","", 75, 0, 750); TTbarVSPT100->Sumw2(); TTbarVSPT100->SetLineColor(kCyan);    TTbarVSPT100->SetLineWidth(2);
//small MinDPhi
TH1D *DataQCDVSPT0   = new TH1D("DataQCDVSPT0"  ,"", 75, 0, 750); DataQCDVSPT0  ->Sumw2(); DataQCDVSPT0  ->SetLineColor(kBlack);  DataQCDVSPT0  ->SetLineWidth(2);
TH1D *DataQCDVSPT20  = new TH1D("DataQCDVSPT20" ,"", 75, 0, 750); DataQCDVSPT20 ->Sumw2(); DataQCDVSPT20 ->SetLineColor(kRed);    DataQCDVSPT20 ->SetLineWidth(2);
TH1D *DataQCDVSPT30  = new TH1D("DataQCDVSPT30" ,"", 75, 0, 750); DataQCDVSPT30 ->Sumw2(); DataQCDVSPT30 ->SetLineColor(kGreen);  DataQCDVSPT30 ->SetLineWidth(2);
TH1D *DataQCDVSPT40  = new TH1D("DataQCDVSPT40" ,"", 75, 0, 750); DataQCDVSPT40 ->Sumw2(); DataQCDVSPT40 ->SetLineColor(kBlue);   DataQCDVSPT40 ->SetLineWidth(2);
TH1D *DataQCDVSPT50  = new TH1D("DataQCDVSPT50" ,"", 75, 0, 750); DataQCDVSPT50 ->Sumw2(); DataQCDVSPT50 ->SetLineColor(kYellow); DataQCDVSPT50 ->SetLineWidth(2);
TH1D *DataQCDVSPT70  = new TH1D("DataQCDVSPT70" ,"", 75, 0, 750); DataQCDVSPT70 ->Sumw2(); DataQCDVSPT70 ->SetLineColor(kMagenta);DataQCDVSPT70 ->SetLineWidth(2);
TH1D *DataQCDVSPT100 = new TH1D("DataQCDVSPT100","", 75, 0, 750); DataQCDVSPT100->Sumw2(); DataQCDVSPT100->SetLineColor(kCyan);   DataQCDVSPT100->SetLineWidth(2);
//1lep,0b
TH1D *DataWVSPT0   = new TH1D("DataWVSPT0"  ,"", 75, 0, 750); DataWVSPT0  ->Sumw2(); DataWVSPT0  ->SetLineColor(kBlack);  DataWVSPT0  ->SetLineWidth(2);
TH1D *DataWVSPT20  = new TH1D("DataWVSPT20" ,"", 75, 0, 750); DataWVSPT20 ->Sumw2(); DataWVSPT20 ->SetLineColor(kRed);    DataWVSPT20 ->SetLineWidth(2);
TH1D *DataWVSPT30  = new TH1D("DataWVSPT30" ,"", 75, 0, 750); DataWVSPT30 ->Sumw2(); DataWVSPT30 ->SetLineColor(kGreen);  DataWVSPT30 ->SetLineWidth(2);
TH1D *DataWVSPT40  = new TH1D("DataWVSPT40" ,"", 75, 0, 750); DataWVSPT40 ->Sumw2(); DataWVSPT40 ->SetLineColor(kBlue);   DataWVSPT40 ->SetLineWidth(2);
TH1D *DataWVSPT50  = new TH1D("DataWVSPT50" ,"", 75, 0, 750); DataWVSPT50 ->Sumw2(); DataWVSPT50 ->SetLineColor(kYellow); DataWVSPT50 ->SetLineWidth(2);
TH1D *DataWVSPT70  = new TH1D("DataWVSPT70" ,"", 75, 0, 750); DataWVSPT70 ->Sumw2(); DataWVSPT70 ->SetLineColor(kMagenta);DataWVSPT70 ->SetLineWidth(2);
TH1D *DataWVSPT100 = new TH1D("DataWVSPT100","", 75, 0, 750); DataWVSPT100->Sumw2(); DataWVSPT100->SetLineColor(kCyan);   DataWVSPT100->SetLineWidth(2);
//1lep,1b 
TH1D *DataTopVSPT0   = new TH1D("DataTopVSPT0"  ,"", 75, 0, 750); DataTopVSPT0  ->Sumw2(); DataTopVSPT0  ->SetLineColor(kBlack);  DataTopVSPT0  ->SetLineWidth(2);
TH1D *DataTopVSPT20  = new TH1D("DataTopVSPT20" ,"", 75, 0, 750); DataTopVSPT20 ->Sumw2(); DataTopVSPT20 ->SetLineColor(kRed);    DataTopVSPT20 ->SetLineWidth(2);
TH1D *DataTopVSPT30  = new TH1D("DataTopVSPT30" ,"", 75, 0, 750); DataTopVSPT30 ->Sumw2(); DataTopVSPT30 ->SetLineColor(kGreen);  DataTopVSPT30 ->SetLineWidth(2);
TH1D *DataTopVSPT40  = new TH1D("DataTopVSPT40" ,"", 75, 0, 750); DataTopVSPT40 ->Sumw2(); DataTopVSPT40 ->SetLineColor(kBlue);   DataTopVSPT40 ->SetLineWidth(2);
TH1D *DataTopVSPT50  = new TH1D("DataTopVSPT50" ,"", 75, 0, 750); DataTopVSPT50 ->Sumw2(); DataTopVSPT50 ->SetLineColor(kYellow); DataTopVSPT50 ->SetLineWidth(2);
TH1D *DataTopVSPT70  = new TH1D("DataTopVSPT70" ,"", 75, 0, 750); DataTopVSPT70 ->Sumw2(); DataTopVSPT70 ->SetLineColor(kMagenta);DataTopVSPT70 ->SetLineWidth(2);
TH1D *DataTopVSPT100 = new TH1D("DataTopVSPT100","", 75, 0, 750); DataTopVSPT100->Sumw2(); DataTopVSPT100->SetLineColor(kCyan);   DataTopVSPT100->SetLineWidth(2);
//highDeltaPhi,0b 
TH1D *DataZVSPT0   = new TH1D("DataZVSPT0"  ,"", 75, 0, 750); DataZVSPT0  ->Sumw2(); DataZVSPT0  ->SetLineColor(kBlack);  DataZVSPT0  ->SetLineWidth(2);
TH1D *DataZVSPT20  = new TH1D("DataZVSPT20" ,"", 75, 0, 750); DataZVSPT20 ->Sumw2(); DataZVSPT20 ->SetLineColor(kRed);    DataZVSPT20 ->SetLineWidth(2);
TH1D *DataZVSPT30  = new TH1D("DataZVSPT30" ,"", 75, 0, 750); DataZVSPT30 ->Sumw2(); DataZVSPT30 ->SetLineColor(kGreen);  DataZVSPT30 ->SetLineWidth(2);
TH1D *DataZVSPT40  = new TH1D("DataZVSPT40" ,"", 75, 0, 750); DataZVSPT40 ->Sumw2(); DataZVSPT40 ->SetLineColor(kBlue);   DataZVSPT40 ->SetLineWidth(2);
TH1D *DataZVSPT50  = new TH1D("DataZVSPT50" ,"", 75, 0, 750); DataZVSPT50 ->Sumw2(); DataZVSPT50 ->SetLineColor(kYellow); DataZVSPT50 ->SetLineWidth(2);
TH1D *DataZVSPT70  = new TH1D("DataZVSPT70" ,"", 75, 0, 750); DataZVSPT70 ->Sumw2(); DataZVSPT70 ->SetLineColor(kMagenta);DataZVSPT70 ->SetLineWidth(2);
TH1D *DataZVSPT100 = new TH1D("DataZVSPT100","", 75, 0, 750); DataZVSPT100->Sumw2(); DataZVSPT100->SetLineColor(kCyan);   DataZVSPT100->SetLineWidth(2);

//fill histograms
gROOT->cd();
cout << "LM6VSPT0" << endl;
LM6->Draw("misc.MT2>>LM6VSPT0",  "NJetsIDLoose40>=2&&misc.HT>450&&misc.MET>30&&NEles==0&&NMuons==0&&NTausIDLoose3Hits==0&&misc.Vectorsumpt>=0&&misc.Vectorsumpt<20","goff");
cout << "LM6VSPT20" << endl;
LM6->Draw("misc.MT2>>LM6VSPT20", "NJetsIDLoose40>=2&&misc.HT>450&&misc.MET>30&&NEles==0&&NMuons==0&&NTausIDLoose3Hits==0&&misc.Vectorsumpt>=20&&misc.Vectorsumpt<30","goff");
cout << "LM6VSPT30" << endl;
LM6->Draw("misc.MT2>>LM6VSPT30", "NJetsIDLoose40>=2&&misc.HT>450&&misc.MET>30&&NEles==0&&NMuons==0&&NTausIDLoose3Hits==0&&misc.Vectorsumpt>=30&&misc.Vectorsumpt<40","goff");
cout << "LM6VSPT40" << endl;
LM6->Draw("misc.MT2>>LM6VSPT40", "NJetsIDLoose40>=2&&misc.HT>450&&misc.MET>30&&NEles==0&&NMuons==0&&NTausIDLoose3Hits==0&&misc.Vectorsumpt>=40&&misc.Vectorsumpt<50","goff");
cout << "LM6VSPT50" << endl;
LM6->Draw("misc.MT2>>LM6VSPT50", "NJetsIDLoose40>=2&&misc.HT>450&&misc.MET>30&&NEles==0&&NMuons==0&&NTausIDLoose3Hits==0&&misc.Vectorsumpt>=50&&misc.Vectorsumpt<70","goff");
cout << "LM6VSPT70" << endl;
LM6->Draw("misc.MT2>>LM6VSPT70", "NJetsIDLoose40>=2&&misc.HT>450&&misc.MET>30&&NEles==0&&NMuons==0&&NTausIDLoose3Hits==0&&misc.Vectorsumpt>=70&&misc.Vectorsumpt<100","goff");
cout << "LM6VSPT100" << endl;
LM6->Draw("misc.MT2>>LM6VSPT100","NJetsIDLoose40>=2&&misc.HT>450&&misc.MET>30&&NEles==0&&NMuons==0&&NTausIDLoose3Hits==0&&misc.Vectorsumpt>=100","goff");

cout << "WJetsVSPT0" << endl;
WJets->Draw("misc.MT2>>WJetsVSPT0",  "NJetsIDLoose40>=2&&misc.HT>450&&misc.MET>30&&NEles==0&&NMuons==0&&NTausIDLoose3Hits==0&&misc.Vectorsumpt>=0&&misc.Vectorsumpt<20","goff");
cout << "WJetsVSPT20" << endl;
WJets->Draw("misc.MT2>>WJetsVSPT20", "NJetsIDLoose40>=2&&misc.HT>450&&misc.MET>30&&NEles==0&&NMuons==0&&NTausIDLoose3Hits==0&&misc.Vectorsumpt>=20&&misc.Vectorsumpt<30","goff");
cout << "WJetsVSPT30" << endl;
WJets->Draw("misc.MT2>>WJetsVSPT30", "NJetsIDLoose40>=2&&misc.HT>450&&misc.MET>30&&NEles==0&&NMuons==0&&NTausIDLoose3Hits==0&&misc.Vectorsumpt>=30&&misc.Vectorsumpt<40","goff");
cout << "WJetsVSPT40" << endl;
WJets->Draw("misc.MT2>>WJetsVSPT40", "NJetsIDLoose40>=2&&misc.HT>450&&misc.MET>30&&NEles==0&&NMuons==0&&NTausIDLoose3Hits==0&&misc.Vectorsumpt>=40&&misc.Vectorsumpt<50","goff");
cout << "WJetsVSPT50" << endl;
WJets->Draw("misc.MT2>>WJetsVSPT50", "NJetsIDLoose40>=2&&misc.HT>450&&misc.MET>30&&NEles==0&&NMuons==0&&NTausIDLoose3Hits==0&&misc.Vectorsumpt>=50&&misc.Vectorsumpt<70","goff");
cout << "WJetsVSPT70" << endl;
WJets->Draw("misc.MT2>>WJetsVSPT70", "NJetsIDLoose40>=2&&misc.HT>450&&misc.MET>30&&NEles==0&&NMuons==0&&NTausIDLoose3Hits==0&&misc.Vectorsumpt>=70&&misc.Vectorsumpt<100","goff");
cout << "WJetsVSPT100" << endl;
WJets->Draw("misc.MT2>>WJetsVSPT100","NJetsIDLoose40>=2&&misc.HT>450&&misc.MET>30&&NEles==0&&NMuons==0&&NTausIDLoose3Hits==0&&misc.Vectorsumpt>=100","goff");

cout << "ZJetsVSPT0" << endl;
ZJets->Draw("misc.MT2>>ZJetsVSPT0",  "NJetsIDLoose40>=2&&misc.HT>450&&misc.MET>30&&NEles==0&&NMuons==0&&NTausIDLoose3Hits==0&&misc.Vectorsumpt>=0&&misc.Vectorsumpt<20","goff");
cout << "ZJetsVSPT20" << endl;
ZJets->Draw("misc.MT2>>ZJetsVSPT20", "NJetsIDLoose40>=2&&misc.HT>450&&misc.MET>30&&NEles==0&&NMuons==0&&NTausIDLoose3Hits==0&&misc.Vectorsumpt>=20&&misc.Vectorsumpt<30","goff");
cout << "ZJetsVSPT30" << endl;
ZJets->Draw("misc.MT2>>ZJetsVSPT30", "NJetsIDLoose40>=2&&misc.HT>450&&misc.MET>30&&NEles==0&&NMuons==0&&NTausIDLoose3Hits==0&&misc.Vectorsumpt>=30&&misc.Vectorsumpt<40","goff");
cout << "ZJetsVSPT40" << endl;
ZJets->Draw("misc.MT2>>ZJetsVSPT40", "NJetsIDLoose40>=2&&misc.HT>450&&misc.MET>30&&NEles==0&&NMuons==0&&NTausIDLoose3Hits==0&&misc.Vectorsumpt>=40&&misc.Vectorsumpt<50","goff");
cout << "ZJetsVSPT50" << endl;
ZJets->Draw("misc.MT2>>ZJetsVSPT50", "NJetsIDLoose40>=2&&misc.HT>450&&misc.MET>30&&NEles==0&&NMuons==0&&NTausIDLoose3Hits==0&&misc.Vectorsumpt>=50&&misc.Vectorsumpt<70","goff");
cout << "ZJetsVSPT70" << endl;
ZJets->Draw("misc.MT2>>ZJetsVSPT70", "NJetsIDLoose40>=2&&misc.HT>450&&misc.MET>30&&NEles==0&&NMuons==0&&NTausIDLoose3Hits==0&&misc.Vectorsumpt>=70&&misc.Vectorsumpt<100","goff");
cout << "ZJetsVSPT100" << endl;
ZJets->Draw("misc.MT2>>ZJetsVSPT100","NJetsIDLoose40>=2&&misc.HT>450&&misc.MET>30&&NEles==0&&NMuons==0&&NTausIDLoose3Hits==0&&misc.Vectorsumpt>=100","goff");

cout << "TTbarVSPT0" << endl;
TTbar->Draw("misc.MT2>>TTbarVSPT0",  "NJetsIDLoose40>=2&&misc.HT>450&&misc.MET>30&&NEles==0&&NMuons==0&&NTausIDLoose3Hits==0&&misc.Vectorsumpt>=0&&misc.Vectorsumpt<20","goff");
cout << "TTbarVSPT20" << endl;
TTbar->Draw("misc.MT2>>TTbarVSPT20", "NJetsIDLoose40>=2&&misc.HT>450&&misc.MET>30&&NEles==0&&NMuons==0&&NTausIDLoose3Hits==0&&misc.Vectorsumpt>=20&&misc.Vectorsumpt<30","goff");
cout << "TTbarVSPT30" << endl;
TTbar->Draw("misc.MT2>>TTbarVSPT30", "NJetsIDLoose40>=2&&misc.HT>450&&misc.MET>30&&NEles==0&&NMuons==0&&NTausIDLoose3Hits==0&&misc.Vectorsumpt>=30&&misc.Vectorsumpt<40","goff");
cout << "TTbarVSPT40" << endl;
TTbar->Draw("misc.MT2>>TTbarVSPT40", "NJetsIDLoose40>=2&&misc.HT>450&&misc.MET>30&&NEles==0&&NMuons==0&&NTausIDLoose3Hits==0&&misc.Vectorsumpt>=40&&misc.Vectorsumpt<50","goff");
cout << "TTbarVSPT50" << endl;
TTbar->Draw("misc.MT2>>TTbarVSPT50", "NJetsIDLoose40>=2&&misc.HT>450&&misc.MET>30&&NEles==0&&NMuons==0&&NTausIDLoose3Hits==0&&misc.Vectorsumpt>=50&&misc.Vectorsumpt<70","goff");
cout << "TTbarVSPT70" << endl;
TTbar->Draw("misc.MT2>>TTbarVSPT70", "NJetsIDLoose40>=2&&misc.HT>450&&misc.MET>30&&NEles==0&&NMuons==0&&NTausIDLoose3Hits==0&&misc.Vectorsumpt>=70&&misc.Vectorsumpt<100","goff");
cout << "TTbarVSPT100" << endl;
TTbar->Draw("misc.MT2>>TTbarVSPT100","NJetsIDLoose40>=2&&misc.HT>450&&misc.MET>30&&NEles==0&&NMuons==0&&NTausIDLoose3Hits==0&&misc.Vectorsumpt>=100","goff");

cout << "DataQCDVSPT0" << endl;
Data->Draw("misc.MT2>>DataQCDVSPT0",  "NJetsIDLoose40>=2&&misc.HT>750&&misc.MET>10&&NEles==0&&NMuons==0&&NTausIDLoose3Hits==0&&misc.MinMetJetDPhi4Pt40<0.2&&misc.PassJet40ID ==1&&misc.HBHENoiseFlag == 0&&misc.CSCTightHaloIDFlag == 0&&misc.trackingFailureFlag==0&&misc.eeBadScFlag==0&&misc.EcalDeadCellTriggerPrimitiveFlag==0&&misc.TrackingManyStripClusFlag==0&&misc.TrackingTooManyStripClusFlag==0&&misc.TrackingLogErrorTooManyClustersFlag==0&&misc.CrazyHCAL==0&&(misc.MET>30||misc.MET/misc.CaloMETRaw<=2.)&&misc.Vectorsumpt>=0&&misc.Vectorsumpt<20","goff");
cout << "DataQCDVSPT20" << endl;
Data->Draw("misc.MT2>>DataQCDVSPT20", "NJetsIDLoose40>=2&&misc.HT>750&&misc.MET>10&&NEles==0&&NMuons==0&&NTausIDLoose3Hits==0&&misc.MinMetJetDPhi4Pt40<0.2&&misc.PassJet40ID ==1&&misc.HBHENoiseFlag == 0&&misc.CSCTightHaloIDFlag == 0&&misc.trackingFailureFlag==0&&misc.eeBadScFlag==0&&misc.EcalDeadCellTriggerPrimitiveFlag==0&&misc.TrackingManyStripClusFlag==0&&misc.TrackingTooManyStripClusFlag==0&&misc.TrackingLogErrorTooManyClustersFlag==0&&misc.CrazyHCAL==0&&(misc.MET>30||misc.MET/misc.CaloMETRaw<=2.)&&misc.Vectorsumpt>=20&&misc.Vectorsumpt<30","goff");
cout << "DataQCDVSPT30" << endl;
Data->Draw("misc.MT2>>DataQCDVSPT30", "NJetsIDLoose40>=2&&misc.HT>750&&misc.MET>10&&NEles==0&&NMuons==0&&NTausIDLoose3Hits==0&&misc.MinMetJetDPhi4Pt40<0.2&&misc.PassJet40ID ==1&&misc.HBHENoiseFlag == 0&&misc.CSCTightHaloIDFlag == 0&&misc.trackingFailureFlag==0&&misc.eeBadScFlag==0&&misc.EcalDeadCellTriggerPrimitiveFlag==0&&misc.TrackingManyStripClusFlag==0&&misc.TrackingTooManyStripClusFlag==0&&misc.TrackingLogErrorTooManyClustersFlag==0&&misc.CrazyHCAL==0&&(misc.MET>30||misc.MET/misc.CaloMETRaw<=2.)&&misc.Vectorsumpt>=30&&misc.Vectorsumpt<40","goff");
cout << "DataQCDVSPT40" << endl;
Data->Draw("misc.MT2>>DataQCDVSPT40", "NJetsIDLoose40>=2&&misc.HT>750&&misc.MET>10&&NEles==0&&NMuons==0&&NTausIDLoose3Hits==0&&misc.MinMetJetDPhi4Pt40<0.2&&misc.PassJet40ID ==1&&misc.HBHENoiseFlag == 0&&misc.CSCTightHaloIDFlag == 0&&misc.trackingFailureFlag==0&&misc.eeBadScFlag==0&&misc.EcalDeadCellTriggerPrimitiveFlag==0&&misc.TrackingManyStripClusFlag==0&&misc.TrackingTooManyStripClusFlag==0&&misc.TrackingLogErrorTooManyClustersFlag==0&&misc.CrazyHCAL==0&&(misc.MET>30||misc.MET/misc.CaloMETRaw<=2.)&&misc.Vectorsumpt>=40&&misc.Vectorsumpt<50","goff");
cout << "DataQCDVSPT50" << endl;
Data->Draw("misc.MT2>>DataQCDVSPT50", "NJetsIDLoose40>=2&&misc.HT>750&&misc.MET>10&&NEles==0&&NMuons==0&&NTausIDLoose3Hits==0&&misc.MinMetJetDPhi4Pt40<0.2&&misc.PassJet40ID ==1&&misc.HBHENoiseFlag == 0&&misc.CSCTightHaloIDFlag == 0&&misc.trackingFailureFlag==0&&misc.eeBadScFlag==0&&misc.EcalDeadCellTriggerPrimitiveFlag==0&&misc.TrackingManyStripClusFlag==0&&misc.TrackingTooManyStripClusFlag==0&&misc.TrackingLogErrorTooManyClustersFlag==0&&misc.CrazyHCAL==0&&(misc.MET>30||misc.MET/misc.CaloMETRaw<=2.)&&misc.Vectorsumpt>=50&&misc.Vectorsumpt<70","goff");
cout << "DataQCDVSPT70" << endl;
Data->Draw("misc.MT2>>DataQCDVSPT70", "NJetsIDLoose40>=2&&misc.HT>750&&misc.MET>10&&NEles==0&&NMuons==0&&NTausIDLoose3Hits==0&&misc.MinMetJetDPhi4Pt40<0.2&&misc.PassJet40ID ==1&&misc.HBHENoiseFlag == 0&&misc.CSCTightHaloIDFlag == 0&&misc.trackingFailureFlag==0&&misc.eeBadScFlag==0&&misc.EcalDeadCellTriggerPrimitiveFlag==0&&misc.TrackingManyStripClusFlag==0&&misc.TrackingTooManyStripClusFlag==0&&misc.TrackingLogErrorTooManyClustersFlag==0&&misc.CrazyHCAL==0&&(misc.MET>30||misc.MET/misc.CaloMETRaw<=2.)&&misc.Vectorsumpt>=70&&misc.Vectorsumpt<100","goff");
cout << "DataQCDVSPT100" << endl;
Data->Draw("misc.MT2>>DataQCDVSPT100","NJetsIDLoose40>=2&&misc.HT>750&&misc.MET>10&&NEles==0&&NMuons==0&&NTausIDLoose3Hits==0&&misc.MinMetJetDPhi4Pt40<0.2&&misc.PassJet40ID ==1&&misc.HBHENoiseFlag == 0&&misc.CSCTightHaloIDFlag == 0&&misc.trackingFailureFlag==0&&misc.eeBadScFlag==0&&misc.EcalDeadCellTriggerPrimitiveFlag==0&&misc.TrackingManyStripClusFlag==0&&misc.TrackingTooManyStripClusFlag==0&&misc.TrackingLogErrorTooManyClustersFlag==0&&misc.CrazyHCAL==0&&(misc.MET>30||misc.MET/misc.CaloMETRaw<=2.)&&misc.Vectorsumpt>=100","goff");

cout << "DataZVSPT0" << endl;
Data->Draw("misc.MT2>>DataZVSPT0",  "NJetsIDLoose40>=2&&misc.HT>750&&misc.MET>10&&NEles==0&&NMuons==0&&NTausIDLoose3Hits==0&&misc.MinMetJetDPhi4Pt40>0.5&&NBJets40CSVM==0&&misc.PassJet40ID ==1&&misc.HBHENoiseFlag == 0&&misc.CSCTightHaloIDFlag == 0&&misc.trackingFailureFlag==0&&misc.eeBadScFlag==0&&misc.EcalDeadCellTriggerPrimitiveFlag==0&&misc.TrackingManyStripClusFlag==0&&misc.TrackingTooManyStripClusFlag==0&&misc.TrackingLogErrorTooManyClustersFlag==0&&misc.CrazyHCAL==0&&(misc.MET>30||misc.MET/misc.CaloMETRaw<=2.)&&misc.Vectorsumpt>=0&&misc.Vectorsumpt<20","goff");
cout << "DataZVSPT20" << endl;
Data->Draw("misc.MT2>>DataZVSPT20", "NJetsIDLoose40>=2&&misc.HT>750&&misc.MET>10&&NEles==0&&NMuons==0&&NTausIDLoose3Hits==0&&misc.MinMetJetDPhi4Pt40>0.5&&NBJets40CSVM==0&&misc.PassJet40ID ==1&&misc.HBHENoiseFlag == 0&&misc.CSCTightHaloIDFlag == 0&&misc.trackingFailureFlag==0&&misc.eeBadScFlag==0&&misc.EcalDeadCellTriggerPrimitiveFlag==0&&misc.TrackingManyStripClusFlag==0&&misc.TrackingTooManyStripClusFlag==0&&misc.TrackingLogErrorTooManyClustersFlag==0&&misc.CrazyHCAL==0&&(misc.MET>30||misc.MET/misc.CaloMETRaw<=2.)&&misc.Vectorsumpt>=20&&misc.Vectorsumpt<30","goff");
cout << "DataZVSPT30" << endl;
Data->Draw("misc.MT2>>DataZVSPT30", "NJetsIDLoose40>=2&&misc.HT>750&&misc.MET>10&&NEles==0&&NMuons==0&&NTausIDLoose3Hits==0&&misc.MinMetJetDPhi4Pt40>0.5&&NBJets40CSVM==0&&misc.PassJet40ID ==1&&misc.HBHENoiseFlag == 0&&misc.CSCTightHaloIDFlag == 0&&misc.trackingFailureFlag==0&&misc.eeBadScFlag==0&&misc.EcalDeadCellTriggerPrimitiveFlag==0&&misc.TrackingManyStripClusFlag==0&&misc.TrackingTooManyStripClusFlag==0&&misc.TrackingLogErrorTooManyClustersFlag==0&&misc.CrazyHCAL==0&&(misc.MET>30||misc.MET/misc.CaloMETRaw<=2.)&&misc.Vectorsumpt>=30&&misc.Vectorsumpt<40","goff");
cout << "DataZVSPT40" << endl;
Data->Draw("misc.MT2>>DataZVSPT40", "NJetsIDLoose40>=2&&misc.HT>750&&misc.MET>10&&NEles==0&&NMuons==0&&NTausIDLoose3Hits==0&&misc.MinMetJetDPhi4Pt40>0.5&&NBJets40CSVM==0&&misc.PassJet40ID ==1&&misc.HBHENoiseFlag == 0&&misc.CSCTightHaloIDFlag == 0&&misc.trackingFailureFlag==0&&misc.eeBadScFlag==0&&misc.EcalDeadCellTriggerPrimitiveFlag==0&&misc.TrackingManyStripClusFlag==0&&misc.TrackingTooManyStripClusFlag==0&&misc.TrackingLogErrorTooManyClustersFlag==0&&misc.CrazyHCAL==0&&(misc.MET>30||misc.MET/misc.CaloMETRaw<=2.)&&misc.Vectorsumpt>=40&&misc.Vectorsumpt<50","goff");
cout << "DataZVSPT50" << endl;
Data->Draw("misc.MT2>>DataZVSPT50", "NJetsIDLoose40>=2&&misc.HT>750&&misc.MET>10&&NEles==0&&NMuons==0&&NTausIDLoose3Hits==0&&misc.MinMetJetDPhi4Pt40>0.5&&NBJets40CSVM==0&&misc.PassJet40ID ==1&&misc.HBHENoiseFlag == 0&&misc.CSCTightHaloIDFlag == 0&&misc.trackingFailureFlag==0&&misc.eeBadScFlag==0&&misc.EcalDeadCellTriggerPrimitiveFlag==0&&misc.TrackingManyStripClusFlag==0&&misc.TrackingTooManyStripClusFlag==0&&misc.TrackingLogErrorTooManyClustersFlag==0&&misc.CrazyHCAL==0&&(misc.MET>30||misc.MET/misc.CaloMETRaw<=2.)&&misc.Vectorsumpt>=50&&misc.Vectorsumpt<70","goff");
cout << "DataZVSPT70" << endl;
Data->Draw("misc.MT2>>DataZVSPT70", "NJetsIDLoose40>=2&&misc.HT>750&&misc.MET>10&&NEles==0&&NMuons==0&&NTausIDLoose3Hits==0&&misc.MinMetJetDPhi4Pt40>0.5&&NBJets40CSVM==0&&misc.PassJet40ID ==1&&misc.HBHENoiseFlag == 0&&misc.CSCTightHaloIDFlag == 0&&misc.trackingFailureFlag==0&&misc.eeBadScFlag==0&&misc.EcalDeadCellTriggerPrimitiveFlag==0&&misc.TrackingManyStripClusFlag==0&&misc.TrackingTooManyStripClusFlag==0&&misc.TrackingLogErrorTooManyClustersFlag==0&&misc.CrazyHCAL==0&&(misc.MET>30||misc.MET/misc.CaloMETRaw<=2.)&&misc.Vectorsumpt>=70&&misc.Vectorsumpt<100","goff");
cout << "DataZVSPT100" << endl;
Data->Draw("misc.MT2>>DataZVSPT100","NJetsIDLoose40>=2&&misc.HT>750&&misc.MET>10&&NEles==0&&NMuons==0&&NTausIDLoose3Hits==0&&misc.MinMetJetDPhi4Pt40>0.5&&NBJets40CSVM==0&&misc.PassJet40ID ==1&&misc.HBHENoiseFlag == 0&&misc.CSCTightHaloIDFlag == 0&&misc.trackingFailureFlag==0&&misc.eeBadScFlag==0&&misc.EcalDeadCellTriggerPrimitiveFlag==0&&misc.TrackingManyStripClusFlag==0&&misc.TrackingTooManyStripClusFlag==0&&misc.TrackingLogErrorTooManyClustersFlag==0&&misc.CrazyHCAL==0&&(misc.MET>30||misc.MET/misc.CaloMETRaw<=2.)&&misc.Vectorsumpt>=100","goff");

cout << "DataWVSPT0" << endl;
Data->Draw("misc.MT2>>DataWVSPT0",  "NJetsIDLoose40>=2&&misc.HT>750&&misc.MET>10&&(NEles+NMuons)==1&&NTausIDLoose3Hits==0&&misc.MinMetJetDPhi4Pt40>0.5&&NBJets40CSVM==0&&misc.PassJet40ID ==1&&misc.HBHENoiseFlag == 0&&misc.CSCTightHaloIDFlag == 0&&misc.trackingFailureFlag==0&&misc.eeBadScFlag==0&&misc.EcalDeadCellTriggerPrimitiveFlag==0&&misc.TrackingManyStripClusFlag==0&&misc.TrackingTooManyStripClusFlag==0&&misc.TrackingLogErrorTooManyClustersFlag==0&&misc.CrazyHCAL==0&&(misc.MET>30||misc.MET/misc.CaloMETRaw<=2.)&&misc.Vectorsumpt>=0&&misc.Vectorsumpt<20","goff");
cout << "DataWVSPT20" << endl;
Data->Draw("misc.MT2>>DataWVSPT20", "NJetsIDLoose40>=2&&misc.HT>750&&misc.MET>10&&(NEles+NMuons)==1&&NTausIDLoose3Hits==0&&misc.MinMetJetDPhi4Pt40>0.5&&NBJets40CSVM==0&&misc.PassJet40ID ==1&&misc.HBHENoiseFlag == 0&&misc.CSCTightHaloIDFlag == 0&&misc.trackingFailureFlag==0&&misc.eeBadScFlag==0&&misc.EcalDeadCellTriggerPrimitiveFlag==0&&misc.TrackingManyStripClusFlag==0&&misc.TrackingTooManyStripClusFlag==0&&misc.TrackingLogErrorTooManyClustersFlag==0&&misc.CrazyHCAL==0&&(misc.MET>30||misc.MET/misc.CaloMETRaw<=2.)&&misc.Vectorsumpt>=20&&misc.Vectorsumpt<30","goff");
cout << "DataWVSPT30" << endl;
Data->Draw("misc.MT2>>DataWVSPT30", "NJetsIDLoose40>=2&&misc.HT>750&&misc.MET>10&&(NEles+NMuons)==1&&NTausIDLoose3Hits==0&&misc.MinMetJetDPhi4Pt40>0.5&&NBJets40CSVM==0&&misc.PassJet40ID ==1&&misc.HBHENoiseFlag == 0&&misc.CSCTightHaloIDFlag == 0&&misc.trackingFailureFlag==0&&misc.eeBadScFlag==0&&misc.EcalDeadCellTriggerPrimitiveFlag==0&&misc.TrackingManyStripClusFlag==0&&misc.TrackingTooManyStripClusFlag==0&&misc.TrackingLogErrorTooManyClustersFlag==0&&misc.CrazyHCAL==0&&(misc.MET>30||misc.MET/misc.CaloMETRaw<=2.)&&misc.Vectorsumpt>=30&&misc.Vectorsumpt<40","goff");
cout << "DataWVSPT40" << endl;
Data->Draw("misc.MT2>>DataWVSPT40", "NJetsIDLoose40>=2&&misc.HT>750&&misc.MET>10&&(NEles+NMuons)==1&&NTausIDLoose3Hits==0&&misc.MinMetJetDPhi4Pt40>0.5&&NBJets40CSVM==0&&misc.PassJet40ID ==1&&misc.HBHENoiseFlag == 0&&misc.CSCTightHaloIDFlag == 0&&misc.trackingFailureFlag==0&&misc.eeBadScFlag==0&&misc.EcalDeadCellTriggerPrimitiveFlag==0&&misc.TrackingManyStripClusFlag==0&&misc.TrackingTooManyStripClusFlag==0&&misc.TrackingLogErrorTooManyClustersFlag==0&&misc.CrazyHCAL==0&&(misc.MET>30||misc.MET/misc.CaloMETRaw<=2.)&&misc.Vectorsumpt>=40&&misc.Vectorsumpt<50","goff");
cout << "DataWVSPT50" << endl;
Data->Draw("misc.MT2>>DataWVSPT50", "NJetsIDLoose40>=2&&misc.HT>750&&misc.MET>10&&(NEles+NMuons)==1&&NTausIDLoose3Hits==0&&misc.MinMetJetDPhi4Pt40>0.5&&NBJets40CSVM==0&&misc.PassJet40ID ==1&&misc.HBHENoiseFlag == 0&&misc.CSCTightHaloIDFlag == 0&&misc.trackingFailureFlag==0&&misc.eeBadScFlag==0&&misc.EcalDeadCellTriggerPrimitiveFlag==0&&misc.TrackingManyStripClusFlag==0&&misc.TrackingTooManyStripClusFlag==0&&misc.TrackingLogErrorTooManyClustersFlag==0&&misc.CrazyHCAL==0&&(misc.MET>30||misc.MET/misc.CaloMETRaw<=2.)&&misc.Vectorsumpt>=50&&misc.Vectorsumpt<70","goff");
cout << "DataWVSPT70" << endl;
Data->Draw("misc.MT2>>DataWVSPT70", "NJetsIDLoose40>=2&&misc.HT>750&&misc.MET>10&&(NEles+NMuons)==1&&NTausIDLoose3Hits==0&&misc.MinMetJetDPhi4Pt40>0.5&&NBJets40CSVM==0&&misc.PassJet40ID ==1&&misc.HBHENoiseFlag == 0&&misc.CSCTightHaloIDFlag == 0&&misc.trackingFailureFlag==0&&misc.eeBadScFlag==0&&misc.EcalDeadCellTriggerPrimitiveFlag==0&&misc.TrackingManyStripClusFlag==0&&misc.TrackingTooManyStripClusFlag==0&&misc.TrackingLogErrorTooManyClustersFlag==0&&misc.CrazyHCAL==0&&(misc.MET>30||misc.MET/misc.CaloMETRaw<=2.)&&misc.Vectorsumpt>=70&&misc.Vectorsumpt<100","goff");
cout << "DataWVSPT100" << endl;
Data->Draw("misc.MT2>>DataWVSPT100","NJetsIDLoose40>=2&&misc.HT>750&&misc.MET>10&&(NEles+NMuons)==1&&NTausIDLoose3Hits==0&&misc.MinMetJetDPhi4Pt40>0.5&&NBJets40CSVM==0&&misc.PassJet40ID ==1&&misc.HBHENoiseFlag == 0&&misc.CSCTightHaloIDFlag == 0&&misc.trackingFailureFlag==0&&misc.eeBadScFlag==0&&misc.EcalDeadCellTriggerPrimitiveFlag==0&&misc.TrackingManyStripClusFlag==0&&misc.TrackingTooManyStripClusFlag==0&&misc.TrackingLogErrorTooManyClustersFlag==0&&misc.CrazyHCAL==0&&(misc.MET>30||misc.MET/misc.CaloMETRaw<=2.)&&misc.Vectorsumpt>=100","goff");

cout << "DataWVSPT0" << endl;
Data->Draw("misc.MT2>>DataTopVSPT0",  "NJetsIDLoose40>=2&&misc.HT>750&&misc.MET>10&&(NEles+NMuons)==1&&NTausIDLoose3Hits==0&&misc.MinMetJetDPhi4Pt40>0.5&&NBJets40CSVM>=1&&misc.PassJet40ID ==1&&misc.HBHENoiseFlag == 0&&misc.CSCTightHaloIDFlag == 0&&misc.trackingFailureFlag==0&&misc.eeBadScFlag==0&&misc.EcalDeadCellTriggerPrimitiveFlag==0&&misc.TrackingManyStripClusFlag==0&&misc.TrackingTooManyStripClusFlag==0&&misc.TrackingLogErrorTooManyClustersFlag==0&&misc.CrazyHCAL==0&&(misc.MET>30||misc.MET/misc.CaloMETRaw<=2.)&&misc.Vectorsumpt>=0&&misc.Vectorsumpt<20","goff");
cout << "DataTopVSPT20" << endl;
Data->Draw("misc.MT2>>DataTopVSPT20", "NJetsIDLoose40>=2&&misc.HT>750&&misc.MET>10&&(NEles+NMuons)==1&&NTausIDLoose3Hits==0&&misc.MinMetJetDPhi4Pt40>0.5&&NBJets40CSVM>=1&&misc.PassJet40ID ==1&&misc.HBHENoiseFlag == 0&&misc.CSCTightHaloIDFlag == 0&&misc.trackingFailureFlag==0&&misc.eeBadScFlag==0&&misc.EcalDeadCellTriggerPrimitiveFlag==0&&misc.TrackingManyStripClusFlag==0&&misc.TrackingTooManyStripClusFlag==0&&misc.TrackingLogErrorTooManyClustersFlag==0&&misc.CrazyHCAL==0&&(misc.MET>30||misc.MET/misc.CaloMETRaw<=2.)&&misc.Vectorsumpt>=20&&misc.Vectorsumpt<30","goff");
cout << "DataTopVSPT30" << endl;
Data->Draw("misc.MT2>>DataTopVSPT30", "NJetsIDLoose40>=2&&misc.HT>750&&misc.MET>10&&(NEles+NMuons)==1&&NTausIDLoose3Hits==0&&misc.MinMetJetDPhi4Pt40>0.5&&NBJets40CSVM>=1&&misc.PassJet40ID ==1&&misc.HBHENoiseFlag == 0&&misc.CSCTightHaloIDFlag == 0&&misc.trackingFailureFlag==0&&misc.eeBadScFlag==0&&misc.EcalDeadCellTriggerPrimitiveFlag==0&&misc.TrackingManyStripClusFlag==0&&misc.TrackingTooManyStripClusFlag==0&&misc.TrackingLogErrorTooManyClustersFlag==0&&misc.CrazyHCAL==0&&(misc.MET>30||misc.MET/misc.CaloMETRaw<=2.)&&misc.Vectorsumpt>=30&&misc.Vectorsumpt<40","goff");
cout << "DataTopVSPT40" << endl;
Data->Draw("misc.MT2>>DataTopVSPT40", "NJetsIDLoose40>=2&&misc.HT>750&&misc.MET>10&&(NEles+NMuons)==1&&NTausIDLoose3Hits==0&&misc.MinMetJetDPhi4Pt40>0.5&&NBJets40CSVM>=1&&misc.PassJet40ID ==1&&misc.HBHENoiseFlag == 0&&misc.CSCTightHaloIDFlag == 0&&misc.trackingFailureFlag==0&&misc.eeBadScFlag==0&&misc.EcalDeadCellTriggerPrimitiveFlag==0&&misc.TrackingManyStripClusFlag==0&&misc.TrackingTooManyStripClusFlag==0&&misc.TrackingLogErrorTooManyClustersFlag==0&&misc.CrazyHCAL==0&&(misc.MET>30||misc.MET/misc.CaloMETRaw<=2.)&&misc.Vectorsumpt>=40&&misc.Vectorsumpt<50","goff");
cout << "DataTopVSPT50" << endl;
Data->Draw("misc.MT2>>DataTopVSPT50", "NJetsIDLoose40>=2&&misc.HT>750&&misc.MET>10&&(NEles+NMuons)==1&&NTausIDLoose3Hits==0&&misc.MinMetJetDPhi4Pt40>0.5&&NBJets40CSVM>=1&&misc.PassJet40ID ==1&&misc.HBHENoiseFlag == 0&&misc.CSCTightHaloIDFlag == 0&&misc.trackingFailureFlag==0&&misc.eeBadScFlag==0&&misc.EcalDeadCellTriggerPrimitiveFlag==0&&misc.TrackingManyStripClusFlag==0&&misc.TrackingTooManyStripClusFlag==0&&misc.TrackingLogErrorTooManyClustersFlag==0&&misc.CrazyHCAL==0&&(misc.MET>30||misc.MET/misc.CaloMETRaw<=2.)&&misc.Vectorsumpt>=50&&misc.Vectorsumpt<70","goff");
cout << "DataTopVSPT70" << endl;
Data->Draw("misc.MT2>>DataTopVSPT70", "NJetsIDLoose40>=2&&misc.HT>750&&misc.MET>10&&(NEles+NMuons)==1&&NTausIDLoose3Hits==0&&misc.MinMetJetDPhi4Pt40>0.5&&NBJets40CSVM>=1&&misc.PassJet40ID ==1&&misc.HBHENoiseFlag == 0&&misc.CSCTightHaloIDFlag == 0&&misc.trackingFailureFlag==0&&misc.eeBadScFlag==0&&misc.EcalDeadCellTriggerPrimitiveFlag==0&&misc.TrackingManyStripClusFlag==0&&misc.TrackingTooManyStripClusFlag==0&&misc.TrackingLogErrorTooManyClustersFlag==0&&misc.CrazyHCAL==0&&(misc.MET>30||misc.MET/misc.CaloMETRaw<=2.)&&misc.Vectorsumpt>=70&&misc.Vectorsumpt<100","goff");
cout << "DataTopVSPT100" << endl;
Data->Draw("misc.MT2>>DataTopVSPT100","NJetsIDLoose40>=2&&misc.HT>750&&misc.MET>10&&(NEles+NMuons)==1&&NTausIDLoose3Hits==0&&misc.MinMetJetDPhi4Pt40>0.5&&NBJets40CSVM>=1&&misc.PassJet40ID ==1&&misc.HBHENoiseFlag == 0&&misc.CSCTightHaloIDFlag == 0&&misc.trackingFailureFlag==0&&misc.eeBadScFlag==0&&misc.EcalDeadCellTriggerPrimitiveFlag==0&&misc.TrackingManyStripClusFlag==0&&misc.TrackingTooManyStripClusFlag==0&&misc.TrackingLogErrorTooManyClustersFlag==0&&misc.CrazyHCAL==0&&(misc.MET>30||misc.MET/misc.CaloMETRaw<=2.)&&misc.Vectorsumpt>=100","goff");

TLegend *leg = new TLegend(.6,.6,.90,.90);
leg->SetName("leg");
leg -> SetFillColor(0);
leg -> SetBorderSize(0);
leg->AddEntry(LM6VSPT0,"0 #leq VSPT < 20 GeV", "l");
leg->AddEntry(LM6VSPT20,"20 #leq VSPT < 30 GeV", "l");
leg->AddEntry(LM6VSPT30,"30 #leq VSPT < 40 GeV", "l");
leg->AddEntry(LM6VSPT40,"40 #leq VSPT < 50 GeV", "l");
leg->AddEntry(LM6VSPT50,"50 #leq VSPT < 70 GeV", "l");
leg->AddEntry(LM6VSPT70,"70 #leq VSPT < 100 GeV", "l");
leg->AddEntry(LM6VSPT100,"100 GeV #leq VSPT", "l");

//store the file
TFile *file = new TFile("UTMfile.root","RECREATE");
file->cd();
LM6VSPT0  ->Write();
LM6VSPT20 ->Write();
LM6VSPT30 ->Write();
LM6VSPT40 ->Write();
LM6VSPT50 ->Write();
LM6VSPT70 ->Write();
LM6VSPT100->Write();
WJetsVSPT0  ->Write();
WJetsVSPT20 ->Write();
WJetsVSPT30 ->Write();
WJetsVSPT40 ->Write();
WJetsVSPT50 ->Write();
WJetsVSPT70 ->Write();
WJetsVSPT100->Write();
ZJetsVSPT0  ->Write();
ZJetsVSPT20 ->Write();
ZJetsVSPT30 ->Write();
ZJetsVSPT40 ->Write();
ZJetsVSPT50 ->Write();
ZJetsVSPT70 ->Write();
ZJetsVSPT100->Write();
TTbarVSPT0  ->Write();
TTbarVSPT20 ->Write();
TTbarVSPT30 ->Write();
TTbarVSPT40 ->Write();
TTbarVSPT50 ->Write();
TTbarVSPT70 ->Write();
TTbarVSPT100->Write();
DataQCDVSPT0  ->Write();
DataQCDVSPT20 ->Write();
DataQCDVSPT30 ->Write();
DataQCDVSPT40 ->Write();
DataQCDVSPT50 ->Write();
DataQCDVSPT70 ->Write();
DataQCDVSPT100->Write();
DataWVSPT0  ->Write();
DataWVSPT20 ->Write();
DataWVSPT30 ->Write();
DataWVSPT40 ->Write();
DataWVSPT50 ->Write();
DataWVSPT70 ->Write();
DataWVSPT100->Write();
DataZVSPT0  ->Write();
DataZVSPT20 ->Write();
DataZVSPT30 ->Write();
DataZVSPT40 ->Write();
DataZVSPT50 ->Write();
DataZVSPT70 ->Write();
DataZVSPT100->Write();
DataTopVSPT0  ->Write();
DataTopVSPT20 ->Write();
DataTopVSPT30 ->Write();
DataTopVSPT40 ->Write();
DataTopVSPT50 ->Write();
DataTopVSPT70 ->Write();
DataTopVSPT100->Write();
leg->Write();
file->Close();

cout << "File saved: " << file->GetName() << endl;

}