Exemple #1
0
void ControlPlotter(){

  string directory("HH4b_subjetBTagged_01Mar2016/"); 

  string s_file = directory + "ControlPlotsSignal.root"; 
  //string s_file = "ControlPlotsNoReg_X270.root"; 
  fWrite  = new TFile(s_file.data(), "RECREATE");

  const int ntrees = 21;

  string s[ntrees] = {
    //   "QCD_HT1000to1500_Moriond.root", 
    //  };
  
    "Data_RunCD_Moriond.root",
    "TT_TuneCUETP8M1_13TeV-powheg-pythia8_Moriond.root",
    "QCD_HT500to700_Moriond.root", 
    "QCD_HT700to1000_Moriond.root", 
    "QCD_HT1000to1500_Moriond.root", 
    "QCD_HT1500to2000_Moriond.root", 
    "QCD_HT2000toInf_Moriond.root", 
    "hh4bTree_RadionTohhTohbbhbb_narrow_M-1000_13TeV-madgraph_Moriond.root", 
    "hh4bTree_RadionTohhTohbbhbb_narrow_M-1200_13TeV-madgraph_Moriond.root",
    "hh4bTree_RadionTohhTohbbhbb_narrow_M-1400_13TeV-madgraph_Moriond.root", 
    "hh4bTree_RadionTohhTohbbhbb_narrow_M-1600_13TeV-madgraph_Moriond.root",
    "hh4bTree_RadionTohhTohbbhbb_narrow_M-1800_13TeV-madgraph_Moriond.root",//10 
    "hh4bTree_RadionTohhTohbbhbb_narrow_M-2000_13TeV-madgraph_Moriond.root",
    "hh4bTree_RadionTohhTohbbhbb_narrow_M-2500_13TeV-madgraph_Moriond.root", 
    "hh4bTree_BulkGravTohhTohbbhbb_narrow_M-1000_13TeV-madgraph_Moriond.root",
    "hh4bTree_BulkGravTohhTohbbhbb_narrow_M-1200_13TeV-madgraph_Moriond.root",
    "hh4bTree_BulkGravTohhTohbbhbb_narrow_M-1400_13TeV-madgraph_Moriond.root",
    "hh4bTree_BulkGravTohhTohbbhbb_narrow_M-1600_13TeV-madgraph_Moriond.root",
    "hh4bTree_BulkGravTohhTohbbhbb_narrow_M-1800_13TeV-madgraph_Moriond.root",
    "hh4bTree_BulkGravTohhTohbbhbb_narrow_M-2000_13TeV-madgraph_Moriond.root",
    "hh4bTree_BulkGravTohhTohbbhbb_narrow_M-2500_13TeV-madgraph_Moriond.root" //19
  };
  
  string sampleName[ntrees] = {
    //"QCD_HT1000to1500"
    //  };
    "Data",
    "TTbar",
    "QCD_HT500to700", 
    "QCD_HT700to1000", 
    "QCD_HT1000to1500", 
    "QCD_HT1500to2000", 
    "QCD_HT2000toInf", 
    "Radion_m1000_13TeV",
    "Radion_m1200_13TeV",
    "Radion_m1400_13TeV",
    "Radion_m1600_13TeV",
    "Radion_m1800_13TeV",
    "Radion_m2000_13TeV",
    "Radion_m2500_13TeV",
    "Graviton_m1000_13TeV",
    "Graviton_m1200_13TeV",
    "Graviton_m1400_13TeV",
    "Graviton_m1600_13TeV",
    "Graviton_m1800_13TeV",
    "Graviton_m2000_13TeV",
    "Graviton_m2500_13TeV"
  };
  


  //ControlPlotsSignal.root                                        hh4bTree_RadionTohhTohbbhbb_narrow_M-1800_13TeV-madgraph.root  Plots
  //hh4bTree_JetHT_Run2015D-05Oct2015-v1.root                      hh4bTree_RadionTohhTohbbhbb_narrow_M-2000_13TeV-madgraph.root  QCD_HT1000to1500.root
  //hh4bTree_JetHT_Run2015D-PromptReco-v4.root                     hh4bTree_RadionTohhTohbbhbb_narrow_M-2500_13TeV-madgraph.root  QCD_HT1500to2000.root
  //hh4bTree_RadionTohhTohbbhbb_narrow_M-1000_13TeV-madgraph.root  hh4bTree_RadionTohhTohbbhbb_narrow_M-3500_13TeV-madgraph.root  QCD_HT2000toInf.root
  //hh4bTree_RadionTohhTohbbhbb_narrow_M-1200_13TeV-madgraph.root  hh4bTree_RadionTohhTohbbhbb_narrow_M-4000_13TeV-madgraph.root  QCD_HT300to500.root
  //hh4bTree_RadionTohhTohbbhbb_narrow_M-1400_13TeV-madgraph.root  hh4bTree_RadionTohhTohbbhbb_narrow_M-4500_13TeV-madgraph.root  QCD_HT500to700.root
  //hh4bTree_RadionTohhTohbbhbb_narrow_M-1600_13TeV-madgraph.root  MassPlotFineBins.root                                          QCD_HT700to1000.root








  for (int i = 0; i < ntrees; i++){

    //    if (sampleName[i].find("Data") != string::npos) generalCut =  "(HJets_MassPruned[0] > 105) * (HJets_MassPruned[1] > 105) * (HJets_MassPruned[0] < 135) * (HJets_MassPruned[1] < 135) * (SelectedEventminv_leading2hjets > 1100)*(TMath::Abs(SelectedEvent_deta_leading2hjets) < 1.3)";// * ((HJets_nsubjetsBTaggedCSVL[0]+HJets_nsubjetsBTaggedCSVL[1]) > 0.1)";
//    else  generalCut =  "SelectedEvent_btagsf*(HJets_MassPruned[0] > 105) * (HJets_MassPruned[1] > 105) * (HJets_MassPruned[0] < 135) * (HJets_MassPruned[1] < 135) * (SelectedEventminv_leading2hjets > 1000)";
//    else generalCut =  "(HJets_MassPruned[0] > 105) * (HJets_MassPruned[1] > 105) * (HJets_MassPruned[0] < 135) * (HJets_MassPruned[1] < 135) * (SelectedEventminv_leading2hjets > 1000)*(TMath::Abs(SelectedEvent_deta_leading2hjets) < 1.3)*(TMath::Abs(HJets_Eta[0]) < 2.4)*(TMath::Abs(HJets_Eta[1]) < 2.4)";// * ((HJets_nsubjetsBTaggedCSVL[0]+HJets_nsubjetsBTaggedCSVL[1]) > 0.1)";
    

    generalCut =  "SelectedEvent_btagsf*(HJets_MassPruned[0] > 105) * (HJets_MassPruned[1] > 105) * (HJets_MassPruned[0] < 135) * (HJets_MassPruned[1] < 135)";
    generalCut = generalCut*mainCut;
/*

    if (sampleName[i].find("Data") != string::npos) generalCut =  mainCut;
    else {

    }
*/
    string s1 = directory + "" + s[i];

 


    f1  = TFile::Open(s1.data());
    TDirectory* hh4b = (TDirectory*) f1->Get("hh4b;1");

    TFile* test = new TFile("test", "RECREATE");

    R2S = ((TTree*) hh4b->Get("tree;1"))->CopyTree(mainCut);

    TDirectory* allEvents = (TDirectory*) f1->Get("allEvents;1");

    TH1D* counter = (TH1D*) allEvents->Get("hEventCount;1");

    cout << s1.c_str() << endl;
    
    
    counter = (TH1D*) allEvents->Get("hEventCount;1");
    if (counter) cout << "TOTAL NUMBER OF EVENTS hEventCount ======================================= " << counter->Integral() << endl;
    else{
      counter = (TH1D*) allEvents->Get("hEventCount_wt;1");
      cout << "TOTAL NUMBER OF EVENTS  ======================================= " << counter->Integral() << endl;
    }

      
    
     // R2S->Print();
 
    nbins = 10; 
    minBin = 0.8, width = 0.1; 
    maxBin = minBin + nbins*width;
    plotName  = "BTAG_SF_" + sampleName[i];
    histo_title = "";
    xaxis_title = "btag SF";
    yaxis_title = "Events / 40 GeV";
    variable = "SelectedEvent_btagsf";
    cut0 = "";
    cut = cut0*generalCut;
 
    PlottiPlotta(); 


    // R2S->Print();
 
    nbins = 75; 
    minBin = 600., width = 40.; 
    maxBin = minBin + nbins*width;
    plotName  = "TotalMass_" + sampleName[i];
    histo_title = "";
    xaxis_title = "m_{4b} (GeV)";
    yaxis_title = "Events / 40 GeV";
    variable = "SelectedEvent_minv_leading2hjets";
    cut0 = "";
    cut = cut0*generalCut;
 
    PlottiPlotta();

    cout << "Leading jets" << endl;

    nbins = 75; 
    minBin = 1000., width = 40.; 
    maxBin = minBin + nbins*width;
    plotName  = "TotalMass_0to2btag_" + sampleName[i];
    histo_title = "";
    xaxis_title = "m_{4b} (GeV)";
    yaxis_title = "Events / 40 GeV";
    variable = "SelectedEvent_minv_leading2hjets";
    cut0 = "((HJets_nsubjetsBTaggedCSVL[0]+HJets_nsubjetsBTaggedCSVL[1])<2.99)";
    cut = cut0*generalCut;
 
    PlottiPlotta();


    nbins = 4000; 
    minBin = 1000., width = 1.; 
    maxBin = minBin + nbins*width;
    plotName  = "TotalMass1GeV_" + sampleName[i];
    histo_title = "";
    xaxis_title = "m_{4b} (GeV)";
    yaxis_title = "Events / 1 GeV";
    variable = "SelectedEvent_minv_leading2hjets";
    cut0 = "";
    cut = cut0*generalCut;
 
    PlottiPlotta();


    nbins = 4000; 
    minBin = 1000., width = 1.; 
    maxBin = minBin + nbins*width;
    plotName  = "TotalMass1GeV_3btag_" + sampleName[i];
    histo_title = "";
    xaxis_title = "m_{4b} (GeV)";
    yaxis_title = "Events / 1 GeV";
    variable = "SelectedEvent_minv_leading2hjets";
    cut0 = "(HJets_nsubjetsBTaggedCSVL[0]+HJets_nsubjetsBTaggedCSVL[1])>2.99";
    cut = cut0*generalCut;
 
    PlottiPlotta();


    nbins = 4000; 
    minBin = 1000., width = 1.; 
    maxBin = minBin + nbins*width;
    plotName  = "TotalMass1GeV_3btagExactly_" + sampleName[i];
    histo_title = "";
    xaxis_title = "m_{4b} (GeV)";
    yaxis_title = "Events / 1 GeV";
    variable = "SelectedEvent_minv_leading2hjets";
    cut0 = "((HJets_nsubjetsBTaggedCSVL[0]+HJets_nsubjetsBTaggedCSVL[1])>2.99) * ((HJets_nsubjetsBTaggedCSVL[0]+HJets_nsubjetsBTaggedCSVL[1])<3.01)";
    cut = cut0*generalCut;
 
    PlottiPlotta();



    nbins = 4000; 
    minBin = 1000., width = 1.; 
    maxBin = minBin + nbins*width;
    plotName  = "TotalMass1GeV_3btagExactly_HPHP_" + sampleName[i];
    histo_title = "";
    xaxis_title = "m_{4b} (GeV)";
    yaxis_title = "Events / 1 GeV";
    variable = "SelectedEvent_minv_leading2hjets";
    cut0 = "((HJets_nsubjetsBTaggedCSVL[0]+HJets_nsubjetsBTaggedCSVL[1])>2.99) * ((HJets_nsubjetsBTaggedCSVL[0]+HJets_nsubjetsBTaggedCSVL[1])<3.01)*(HJets_tau2[0]/HJets_tau1[0] < 0.6)*(HJets_tau2[1]/HJets_tau1[1] < 0.6)";
    cut = cut0*generalCut;
 
    PlottiPlotta();



    nbins = 4000; 
    minBin = 1000., width = 1.; 
    maxBin = minBin + nbins*width;
    plotName  = "TotalMass1GeV_3btagExactly_HPLP_" + sampleName[i];
    histo_title = "";
    xaxis_title = "m_{4b} (GeV)";
    yaxis_title = "Events / 1 GeV";
    variable = "SelectedEvent_minv_leading2hjets";
    cut0 = "((HJets_nsubjetsBTaggedCSVL[0]+HJets_nsubjetsBTaggedCSVL[1])>2.99) * ((HJets_nsubjetsBTaggedCSVL[0]+HJets_nsubjetsBTaggedCSVL[1])<3.01)*(HJets_tau2[0]/HJets_tau1[0] < 0.6)*(HJets_tau2[1]/HJets_tau1[1] > 0.6)";
    cut = cut0*generalCut;
 
    PlottiPlotta();


    nbins = 4000; 
    minBin = 1000., width = 1.; 
    maxBin = minBin + nbins*width;
    plotName  = "TotalMass1GeV_3btagExactly_LPHP_" + sampleName[i];
    histo_title = "";
    xaxis_title = "m_{4b} (GeV)";
    yaxis_title = "Events / 1 GeV";
    variable = "SelectedEvent_minv_leading2hjets";
    cut0 = "((HJets_nsubjetsBTaggedCSVL[0]+HJets_nsubjetsBTaggedCSVL[1])>2.99) * ((HJets_nsubjetsBTaggedCSVL[0]+HJets_nsubjetsBTaggedCSVL[1])<3.01)*(HJets_tau2[0]/HJets_tau1[0] > 0.6)*(HJets_tau2[1]/HJets_tau1[1] < 0.6)";
    cut = cut0*generalCut;
 
    PlottiPlotta();



    nbins = 4000; 
    minBin = 1000., width = 1.; 
    maxBin = minBin + nbins*width;
    plotName  = "TotalMass1GeV_4btag_" + sampleName[i];
    histo_title = "";
    xaxis_title = "m_{4b} (GeV)";
    yaxis_title = "Events / 1 GeV";
    variable = "SelectedEvent_minv_leading2hjets";
    cut0 = "(HJets_nsubjetsBTaggedCSVL[0]+HJets_nsubjetsBTaggedCSVL[1])>3.99";
    cut = cut0*generalCut;
 
    PlottiPlotta();

 


    nbins = 16; 
    minBin = -0.1, width = 0.1; 
    maxBin = minBin + nbins*width;
    plotName  = "DeltaEta_" + sampleName[i];
    histo_title = "";
    xaxis_title = "#Delta #eta";
    yaxis_title = "Events / 0.1";
    variable = "SelectedEvent_deta_leading2hjets";
    cut0 = "";
    cut = cut0*generalCut;
 
    PlottiPlotta();

    nbins = 84; 
    minBin = 200., width = 25; 
    maxBin = minBin + nbins*width;
    plotName  = "HThat_" + sampleName[i];
    histo_title = "";
    xaxis_title = "HT_hat (GeV)";
    yaxis_title = "Events / 25 GeV";
    variable = "SelectedEvent_htHat";
    cut0 = "";
    cut = cut0*generalCut;
 
    PlottiPlotta();


    nbins = 42; 
    minBin = 200., width = 25; 
    maxBin = minBin + nbins*width;
    plotName  = "PT0_" + sampleName[i];
    histo_title = "";
    xaxis_title = "p_{T, j0} (GeV)";
    yaxis_title = "Events / 25 GeV";
    variable = "HJets_Pt[0]";
    cut0 = "";
    cut = cut0*generalCut;
 
    PlottiPlotta();



    nbins = 42; 
    minBin = 200., width = 25; 
    maxBin = minBin + nbins*width;
    plotName  = "PT1_" + sampleName[i];
    histo_title = "";
    xaxis_title = "p_{T, j1} (GeV)";
    yaxis_title = "Events / 25 GeV";
    variable = "HJets_Pt[1]";
    cut0 = "";
    cut = cut0*generalCut;
 
    PlottiPlotta();


    nbins = 30; 
    minBin = -3., width = 0.2; 
    maxBin = minBin + nbins*width;
    plotName  = "ETA_" + sampleName[i];
    histo_title = "";
    xaxis_title = "#eta ";
    yaxis_title = "Events / 0.1";
    variable = "HJets_Eta";
    cut0 = "";
    cut = cut0*generalCut;
 
    PlottiPlotta();


    nbins = 30; 
    minBin =90., width = 2; 
    maxBin = minBin + nbins*width;
    plotName  = "M0Pruned_" + sampleName[i];
    histo_title = "";
    xaxis_title = "m_{j0} (GeV)";
    yaxis_title = "Events / 5 GeV";
    variable = "HJets_MassPruned[0]";
    cut0 = "SelectedEvent_btagsf*(SelectedEvent_minv_leading2hjets > 1000)*(TMath::Abs(SelectedEvent_deta_leading2hjets) < 1.3)";
    cut = cut0; // no general cut applied
 
    PlottiPlotta();



    nbins = 30; 
    minBin =90., width = 2; 
    maxBin = minBin + nbins*width;
    plotName  = "M1Pruned_" + sampleName[i];
    histo_title = "";
    xaxis_title = "m_{j1} (GeV)";
    yaxis_title = "Events / 5 GeV";
    variable = "HJets_MassPruned[1]";
    cut0 = "SelectedEvent_btagsf*(SelectedEvent_minv_leading2hjets > 1000)*(TMath::Abs(SelectedEvent_deta_leading2hjets) < 1.3)";
    cut = cut0;  // no general cut applied
 
    PlottiPlotta();
    
 
    nbins = 30; 
    minBin =90., width = 2; 
    maxBin = minBin + nbins*width;
    plotName  = "M0Pruned_WMJcut_" + sampleName[i];
    histo_title = "";
    xaxis_title = "m_{j0} (GeV)";
    yaxis_title = "Events / 5 GeV";
    variable = "HJets_MassPruned[0]";
    cut0 = "";
    cut = cut0*generalCut; // no general cut applied
 
    PlottiPlotta();



    nbins = 30; 
    minBin =90., width = 2; 
    maxBin = minBin + nbins*width;
    plotName  = "M1Pruned_WMJcut_" + sampleName[i];
    histo_title = "";
    xaxis_title = "m_{j1} (GeV)";
    yaxis_title = "Events / 5 GeV";
    variable = "HJets_MassPruned[1]";
    cut0 = "";
    cut = cut0*generalCut;  // no general cut applied
 
    PlottiPlotta();



    nbins = 10; 
    minBin =0., width = 0.1; 
    maxBin = minBin + nbins*width;
    plotName  = "nCSV_J0_SJ0_" + sampleName[i];
    histo_title = "";
    xaxis_title = "CSV J0 SJ0";
    yaxis_title = "Events / 0.1";
    variable = "HJets_csvSubjet0[0]";
    cut0 = "";
    cut = cut0*generalCut;
 
    PlottiPlotta();



    nbins = 10; 
    minBin =0., width = 0.11; 
    maxBin = minBin + nbins*width;
    plotName  = "nCSV_J1_SJ0_" + sampleName[i];
    histo_title = "";
    xaxis_title = "CSV J1 SJ0";
    yaxis_title = "Events";
    variable = "HJets_csvSubjet0[1]";
    cut0 = "";
    cut = cut0*generalCut;
 
    PlottiPlotta();


    nbins = 10; 
    minBin =0., width = 0.1; 
    maxBin = minBin + nbins*width;
    plotName  = "nCSV_J0_SJ1_" + sampleName[i];
    histo_title = "";
    xaxis_title = "CSV J0 SJ1";
    yaxis_title = "Events / 0.1";
    variable = "HJets_csvSubjet1[0]";
    cut0 = "";
    cut = cut0*generalCut;
 
    PlottiPlotta();



    nbins = 10; 
    minBin =0., width = 0.11; 
    maxBin = minBin + nbins*width;
    plotName  = "nCSV_J1_SJ1_" + sampleName[i];
    histo_title = "";
    xaxis_title = "CSV J1 SJ1";
    yaxis_title = "Events / 0.1";
    variable = "HJets_csvSubjet1[1]";
    cut0 = "";
    cut = cut0*generalCut;
 
    PlottiPlotta();



    nbins = 6; 
    minBin =-0.5, width = 1; 
    maxBin = minBin + nbins*width;
    plotName  = "nCSV_" + sampleName[i];
    histo_title = "";
    xaxis_title = "N(CSV0)+N(CSV1)";
    yaxis_title = "Events";
    variable = "HJets_nsubjetsBTaggedCSVL[0]+HJets_nsubjetsBTaggedCSVL[1]";
    cut0 = "";
    cut = cut0*generalCut;
 
    PlottiPlotta();

    //================================================================= nobtasf 


    cut0 = "(HJets_MassPruned[0] > 105) * (HJets_MassPruned[1] > 105) * (HJets_MassPruned[0] < 135) * (HJets_MassPruned[1] < 135) * (SelectedEvent_minv_leading2hjets > 1000)*(TMath::Abs(SelectedEvent_deta_leading2hjets) < 1.3) * ((HJets_nsubjetsBTaggedCSVL[0]+HJets_nsubjetsBTaggedCSVL[1]) > 0.1)";


   nbins = 10; 
    minBin =0., width = 0.1; 
    maxBin = minBin + nbins*width;
    plotName  = "nCSV_J0_SJ0_noBtagSF_" + sampleName[i];
    histo_title = "";
    xaxis_title = "CSV J0 SJ0";
    yaxis_title = "Events / 0.1";
    variable = "HJets_csvSubjet0[0]";
    cut = cut0;
 
    PlottiPlotta();



    nbins = 10; 
    minBin =0., width = 0.11; 
    maxBin = minBin + nbins*width;
    plotName  = "nCSV_J1_SJ0_noBtagSF_" + sampleName[i];
    histo_title = "";
    xaxis_title = "CSV J1 SJ0";
    yaxis_title = "Events";
    variable = "HJets_csvSubjet0[1]";
    cut = cut0;
 
    PlottiPlotta();


    nbins = 10; 
    minBin =0., width = 0.1; 
    maxBin = minBin + nbins*width;
    plotName  = "nCSV_J0_SJ1_noBtagSF_" + sampleName[i];
    histo_title = "";
    xaxis_title = "CSV J0 SJ1";
    yaxis_title = "Events / 0.1";
    variable = "HJets_csvSubjet1[0]";
    cut = cut0;
 
    PlottiPlotta();



    nbins = 10; 
    minBin =0., width = 0.11; 
    maxBin = minBin + nbins*width;
    plotName  = "nCSV_J1_SJ1_noBtagSF_" + sampleName[i];
    histo_title = "";
    xaxis_title = "CSV J1 SJ1";
    yaxis_title = "Events / 0.1";
    variable = "HJets_csvSubjet1[1]";
    cut = cut0;
 
    PlottiPlotta();



    nbins = 6; 
    minBin =-0.5, width = 1; 
    maxBin = minBin + nbins*width;
    plotName  = "nCSV_noBtagSF_" + sampleName[i];
    histo_title = "";
    xaxis_title = "N(CSV0)+N(CSV1)";
    yaxis_title = "Events";
    variable = "HJets_nsubjetsBTaggedCSVL[0]+HJets_nsubjetsBTaggedCSVL[1]";
    cut = cut0;
 
    PlottiPlotta();





    //======================================================

    // R2S->Print();
 
    nbins = 150; 
    minBin = 1000., width = 20.; 
    maxBin = minBin + nbins*width;
    plotName  = "TotalMass3btag_" + sampleName[i];
    histo_title = "3 btags";
    xaxis_title = "m_{4b} (GeV)";
    yaxis_title = "Events / 20 GeV";
    variable = "SelectedEvent_minv_leading2hjets";
    cut0 = "(HJets_nsubjetsBTaggedCSVL[0]+HJets_nsubjetsBTaggedCSVL[1])>2.99";
    cut = cut0*generalCut;
 
    PlottiPlotta();

    nbins = 150; 
    minBin = 1000., width = 20.; 
    maxBin = minBin + nbins*width;
    plotName  = "TotalMass4btag_" + sampleName[i];
    histo_title = "4 btags";
    xaxis_title = "m_{4b} (GeV)";
    yaxis_title = "Events / 20 GeV";
    variable = "SelectedEvent_minv_leading2hjets";
    cut0 = "(HJets_nsubjetsBTaggedCSVL[0]+HJets_nsubjetsBTaggedCSVL[1])>3.99";
    cut = cut0*generalCut;
 
    PlottiPlotta();

    nbins = 10; 
    minBin =0., width = 0.1; 
    maxBin = minBin + nbins*width;
    plotName  = "TAU21_J0_" + sampleName[i];
    histo_title = "";
    xaxis_title = "#tau_{21} J0";
    yaxis_title = "Events / 0.1";
    variable = "HJets_tau2[0]/HJets_tau1[0]";
    cut0 = "";
    cut = cut0*generalCut;
 
    PlottiPlotta();

    nbins = 10; 
    minBin =0., width = 0.1; 
    maxBin = minBin + nbins*width;
    plotName  = "TAU21_J1_" + sampleName[i];
    histo_title = "";
    xaxis_title = "#tau_{21} J1";
    yaxis_title = "Events / 0.1";
    variable = "HJets_tau2[1]/HJets_tau1[1]";
    cut0 = "";
    cut = cut0*generalCut;

    PlottiPlotta();


    test->Close();
    f1->Close();
  }


  fWrite->Close();



}
void ProduceNuclearHistos_example(){

 


  string s_file = "example_NI.root";
  
//  string s1 = "/castor/cern.ch/user/m/mgouzevi/cmst3/CMSSW_BEAMPIPE/4T/20110531_ntuple_nuclint.root"; bDATA = false;

  string s1 = "ntuple_nuclint.root";

  f1  = TFile::Open(s1.data());


  R2S = ntupleR2S->CopyTree(generalCut);

 R2S->SetAlias("rho", "sqrt(x*x+y*y)");

 R2S->SetAlias("PIX_x", "-0.147");
 R2S->SetAlias("PIX_y", "-0.378");
 R2S->SetAlias("PIX_z", "-0.485");
 R2S->SetAlias("PIX_z06", "-0.6");
 R2S->SetAlias("rhoShift", "sqrt( (x-PIX_x)*(x-PIX_x)+(y-PIX_y)*(y-PIX_y) )");
 R2S->SetAlias("p", "sqrt( (x-PIX_x)*(x-PIX_x)+(y-PIX_y)*(y-PIX_y) )");

 R2S->SetAlias("cosShift", "(x-PIX_x)/rhoShift");

 R2S->SetAlias("zShift", "z-PIX_z");

 R2S->SetAlias("P", "ptOut");

 if (bDATA) generalCut =  generalCut;
 else generalCut =  generalCut;

 RailCut = "cosShift < -1/2.  || cosShift > 1/2.";


 /*
FCN=10340.4 FROM MIGRAD    STATUS=CONVERGED     280 CALLS         281 TOTAL
                     EDM=0.000144842    STRATEGY= 1      ERROR MATRIX ACCURATE
  EXT PARAMETER                                   STEP         FIRST
  NO.   NAME      VALUE            ERROR          SIZE      DERIVATIVE
   1  x0           7.51145e-02   2.08214e-04   6.84889e-06  -4.70489e+01
   2  y0          -1.73901e-01   1.52677e-04   5.91533e-06   1.07475e+02
   3  R0           8.51282e+00   7.63835e-04   2.21906e-05   9.53501e+00
 EXTERNAL ERROR MATRIX.    NDIM=  25    NPAR=  3    ERR DEF=1
  4.335e-08  1.558e-08  1.174e-07
  1.558e-08  2.331e-08  6.554e-08
  1.174e-07  6.554e-08  5.834e-07
 PARAMETER  CORRELATION COEFFICIENTS
       NO.  GLOBAL      1      2      3
        1  0.74377   1.000  0.490  0.738
        2  0.57294   0.490  1.000  0.562
        3  0.77309   0.738  0.562  1.000
 */


 /*

MC beam pipe corrected:

   2  Mean         2.93989e+00   2.10168e-04   1.43973e-06   2.37972e-02
   3  Sigma        3.04202e-02   1.55038e-04   9.49746e-06  -2.13246e-03



DATA BEAM PIPE CORRECTED

   2  Mean         2.93656e+00   1.24991e-04   1.85890e-06  -1.25195e-03
   3  Sigma        3.28939e-02   9.03305e-05   1.13489e-05  -6.52762e-04

 */

 R2S->SetAlias("x_minus", "-0.03");
 R2S->SetAlias("x_plus", "+0.03");
 R2S->SetAlias("y_minus",  "-0.03");
 R2S->SetAlias("y_plus", "+0.03");


 R2S->SetAlias("BEAM_x_shift_minus", "0.086-0.03-0.0007*z");
 R2S->SetAlias("BEAM_x_shift_plus", "0.086+0.03-0.0007*z");
 R2S->SetAlias("BEAM_y_shift_minus", "-0.197-0.03+0.0007*z");
 R2S->SetAlias("BEAM_y_shift_plus", "-0.197+0.03+0.0005*z");


 R2S->SetAlias("BEAM_x_shift_minus_700", "0.086-0.07-0.0007*z");
 R2S->SetAlias("BEAM_x_shift_plus_700", "0.086+0.07-0.0007*z");
 R2S->SetAlias("BEAM_y_shift_minus_700", "-0.197-0.07+0.0007*z");
 R2S->SetAlias("BEAM_y_shift_plus_700", "-0.197+0.07+0.0007*z");

 R2S->SetAlias("BEAM_x", "0.086-0.0007*z");
 R2S->SetAlias("BEAM_y", "-0.197+0.0007*z");
 R2S->SetAlias("rhoShiftBeam", "sqrt( (x-BEAM_x)*(x-BEAM_x)+(y-BEAM_y)*(y-BEAM_y) )");
 R2S->SetAlias("rhoShiftBeam_xminus", "sqrt( (x-BEAM_x_shift_minus)*(x-BEAM_x_shift_minus)+(y-BEAM_y)*(y-BEAM_y) )");
 R2S->SetAlias("rhoShiftBeam_xplus", "sqrt( (x-BEAM_x_shift_plus)*(x-BEAM_x_shift_plus)+(y-BEAM_y)*(y-BEAM_y) )");
 R2S->SetAlias("rhoShiftBeam_yminus", "sqrt( (x-BEAM_x)*(x-BEAM_x)+(y-BEAM_y_shift_minus)*(y-BEAM_y_shift_minus) )");
 R2S->SetAlias("rhoShiftBeam_yplus", "sqrt( (x-BEAM_x)*(x-BEAM_x)+(y-BEAM_y_shift_plus)*(y-BEAM_y_shift_plus) )");


 R2S->SetAlias("rhoBeam_xminus", "sqrt( (x-x_minus)*(x-x_minus)+y*y )");
 R2S->SetAlias("rhoBeam_xplus", "sqrt( (x-x_plus)*(x-x_plus)+y*y )");
 R2S->SetAlias("rhoBeam_yminus", "sqrt( x*x+(y-y_minus)*(y-y_minus) )");
 R2S->SetAlias("rhoBeam_yplus", "sqrt( x*x+(y-y_plus)*(y-y_plus) )");


  write  = new TFile(s_file.data(), "RECREATE");

 //PSFile = new TPostScript(psFileName, 112);

// ================ BEGINING OF REC STUDY ================ //


//--------------------------------------//
//------------- Canvas 1.2 --------------//
//------------- Rho Barrel Nucl ----------------//
//--------------------------------------//

 nbins = 50; 
 min = 0., max = min + nbins*1.0;
 plotName  = "RHO_BARREL";
 histo_title = "#rho Nucl";
 xaxis_title = "#rho Nucl (cm)";
 variable = "rho";
 cut0 = BarrelCut;
 cut = cut0&&generalCut;
 
 PlottiPlotta();


//--------------------------------------//
//------------- Canvas 1.2 --------------//
//------------- Rho Barrel Nucl ----------------//
//--------------------------------------//

 nbins = 50; 
 min = 0, max = min + nbins*0.2;
 plotName  = "M_Out";
 histo_title = "M_Out";
 xaxis_title = "M_Out";
 variable = "mOut";
 cut0 = "";
 cut = cut0&&generalCut;
 
 PlottiPlotta();

//--------------------------------------//
//------------- Canvas 1.2 --------------//
//------------- Rho Barrel Nucl ----------------//
//--------------------------------------//

 nbins = 100; 
 min = 0, max = min + nbins*0.2;
 plotName  = "Pt_Out";
 histo_title = "Pt_Out";
 xaxis_title = "ptOut";
 variable = "ptOut";
 cut0 = "";
 cut = cut0&&generalCut;
 
 PlottiPlotta();



 
//--------------------------------------//
//------------- Canvas 1.2 --------------//
//------------- Rho Barrel Nucl ----------------//
//--------------------------------------//

 nbins = 280;
 min = -70, max = min + nbins*0.5;
 nbins1 = 280;
 min1 = -70, max1 = min1 + nbins1*0.5;
 nbins2 = 600;
 min2 = -150, max2 = min2 + nbins2*0.5;

 plotName  = "TRACKER";
 histo_title = "TRACKER";
 xaxis_title = "x Nucl (cm)";
 yaxis_title = "y Nucl (cm)";
 zaxis_title = "z Nucl (cm)";
 variable = "x";
 variable1 = "y";
 variable2 = "z";

 cut0 = "";
 cut = cut0&&generalCut;

 PlottiPlotta3D();


//--------------------------------------//
//------------- Canvas 1.2 --------------//
//------------- Rho Barrel Nucl ----------------//
//--------------------------------------//

 nbins = 400; 
 min = -20, max = min + nbins*0.1;
 nbins1 = 400; 
 min1 = -20, max1 = min1 + nbins1*0.1;
 nbins2 = 1200;
 min2 = -60, max2 = min2 + nbins2*0.1;

 plotName  = "PIXEL";
 histo_title = "PIXEL";
 xaxis_title = "x Nucl (cm)";
 yaxis_title = "y Nucl (cm)";
 zaxis_title = "z Nucl (cm)";
 variable = "x";
 variable1 = "y";
 variable2 = "z";

 cut0 = "";
 cut = cut0&&generalCut;
 
 PlottiPlotta3D();
 



}
void ProduceNuclearHistos_BEAMPIPE_dxystudy(){

 

  //  string s1 = "rfio:/castor/cern.ch/user/m/mgouzevi/CMSSW_358p3/NuclearSkim_CMSSW358p3_goodcoll7TeV_R2S_20100525_HighPurity.root";  bDATA = true;

  //  string s1 = "NuclearSkim_CMSSW358p3_goodcoll7TeV_R2S_20100604_HighPurity.root";  bDATA = true;

  //  string s1 = "rfio:/castor/cern.ch/user/m/mgouzevi/CMSSW_358p3/NuclearSkim_CMSSW358p3_minbias7TeV_R2S_20100604_HighPurity.root";  bDATA = false;

  //  string s1 = "rfio:/castor/cern.ch/user/m/mgouzevi/CMSSW_358p3/NuclearSkim_CMSSW358p3_minbias7TeV_R2S_20100604_HighPurity_v2.root";  bDATA = false;

  //  string s1 = "rfio:/castor/cern.ch/user/m/mgouzevi/CMSSW_358p3/NuclearSkim_CMSSW358p3_goodcoll7TeV_R2S_20100604_HighPurity.root";  bDATA = true;
  //    string s1 = "~sguazz/public/xLloyd/ntuple_nuclint_HIRun2010_4T.root";  bDATA = true;
  //  string s1 = "/tmp/mgouzevi/ntuple_nuclint.root"; bDATA = false;
 
  //  string s1 = "/afs/cern.ch/user/s/sguazz/public/xLloyd/ntuple_nuclint_HIRun2010_0T_10k.root";
  //  string s1 = "~sguazz/public/xLloyd/ntuple_nuclint_HIRun2010_0T_20k.root";

 string s_file = "2011_4T_isNucl_before2T_dxystudy.root";

  // string s_file = "2011_2T_isNucl_2Vtx.root";
  //  string s_file = "2011_MC_2T_isNucl.root";

  //string s_file = "2011_4T_isNucl_after2T.root";
  // string s_file = "2011_4T_isNucl_before2T.root";

  // string s1 = "/castor/cern.ch/user/m/mgouzevi/cmst3/CMSSW_BEAMPIPE/ntuple_nuclint_HIRun2010.root"; bDATA = false;
  // string s1 = "rfio:/castor/cern.ch/user/m/mgouzevi/cmst3/CMSSW_BEAMPIPE/ntuple_nuclint_3.root";  bDATA = false;
  //  string s1 = "rfio:/castor/cern.ch/user/m/mgouzevi/cmst3/CMSSW_BEAMPIPE/2T/ntuple_nuclint_MinBiasMC_altTrig_smallstats.root";

  //  string s1 = "rfio:/castor/cern.ch/user/m/mgouzevi/cmst3/CMSSW_BEAMPIPE/2T/LARGE/ntuple_nuclint_MinBiasMC_2cm.root";

  string s1 = "/castor/cern.ch/user/m/mgouzevi/cmst3/CMSSW_BEAMPIPE/4T/20110601_ntuple_nuclint.root"; bDATA = false;


 //  string s1 = "rfio:/castor/cern.ch/user/m/mgouzevi/cmst3/CMSSW_BEAMPIPE/2T/LARGE/ntuple_nuclint_2T_MB_newNPlizer.root";

  //string s1 = "rfio:/castor/cern.ch/user/s/sguazz/MaterialNtuples/ntuple_nuclint_pre2T_MB.root";
  //  string s1 = "rfio:/castor/cern.ch/user/s/sguazz/MaterialNtuples/ntuple_nuclint_post2T_MB.root";

  //  string s1 = "rfio:/castor/cern.ch/user/s/sguazz/MaterialNtuples/ntuple_nuclint_2T_MB.root";


  // string s1 = "rfio:/castor/cern.ch/user/m/mgouzevi//cmst3/CMSSW_DOMENICO_STEPS/ntuple_Total_wDomenicoStep.root";
  //string s1 = "rfio:/castor/cern.ch/user/m/mgouzevi//cmst3/CMSSW_DOMENICO_STEPS/ntuple_Total_wDomenicoStep.root";


  // string s1 = "rfio:/castor/cern.ch/user/s/sguazz/MaterialNtuples/2T/ntuple_nuclint_MinBiasMC_2cm.root";
  // string s1 = "rfio:/castor/cern.ch/user/m/mgouzevi/cmst3/CMSSW_BEAMPIPE/0T/ntuple_nuclint.root";
  //  string s1 = "ntuple_nuclint_2TExpress.root";
  

  //  string s1 = "/tmp/mgouzevi/ntuple_nuclint_CMSSW356_minbias7TeV.root";

  f1  = TFile::Open(s1.data());

  //f1 = TFile::Open(s1.data());



  //  TTree* ntupleR2S = (TTree*) f1->Get("ntupleR2S;1");

  R2S = ntupleR2S->CopyTree(generalCut);

  // R2S = ntupleR2S;

  R2S->SetAlias("rho", "sqrt(x*x+y*y)");

  R2S->SetAlias("PIX_x", "-0.147");
  R2S->SetAlias("PIX_y", "-0.378");
  R2S->SetAlias("PIX_z", "-0.485");
  R2S->SetAlias("PIX_z06", "-0.6");
  R2S->SetAlias("rhoShift", "sqrt( (x-PIX_x)*(x-PIX_x)+(y-PIX_y)*(y-PIX_y) )");
  R2S->SetAlias("p", "sqrt( (x-PIX_x)*(x-PIX_x)+(y-PIX_y)*(y-PIX_y) )");

  R2S->SetAlias("cosShift", "(x-PIX_x)/rhoShift");

  R2S->SetAlias("zShift", "z-PIX_z");

  R2S->SetAlias("P", "ptOut");

  if (bDATA) generalCut =  generalCut;
  else generalCut =  generalCut;

  RailCut = "cosShift < -1/2.  || cosShift > 1/2.";


  /*
    FCN=10340.4 FROM MIGRAD    STATUS=CONVERGED     280 CALLS         281 TOTAL
    EDM=0.000144842    STRATEGY= 1      ERROR MATRIX ACCURATE
    EXT PARAMETER                                   STEP         FIRST
    NO.   NAME      VALUE            ERROR          SIZE      DERIVATIVE
    1  x0           7.51145e-02   2.08214e-04   6.84889e-06  -4.70489e+01
    2  y0          -1.73901e-01   1.52677e-04   5.91533e-06   1.07475e+02
    3  R0           8.51282e+00   7.63835e-04   2.21906e-05   9.53501e+00
    EXTERNAL ERROR MATRIX.    NDIM=  25    NPAR=  3    ERR DEF=1
    4.335e-08  1.558e-08  1.174e-07
    1.558e-08  2.331e-08  6.554e-08
    1.174e-07  6.554e-08  5.834e-07
    PARAMETER  CORRELATION COEFFICIENTS
    NO.  GLOBAL      1      2      3
    1  0.74377   1.000  0.490  0.738
    2  0.57294   0.490  1.000  0.562
    3  0.77309   0.738  0.562  1.000
  */


  /*

  MC beam pipe corrected:

  2  Mean         2.93989e+00   2.10168e-04   1.43973e-06   2.37972e-02
  3  Sigma        3.04202e-02   1.55038e-04   9.49746e-06  -2.13246e-03



  DATA BEAM PIPE CORRECTED

  2  Mean         2.93656e+00   1.24991e-04   1.85890e-06  -1.25195e-03
  3  Sigma        3.28939e-02   9.03305e-05   1.13489e-05  -6.52762e-04

  */

  R2S->SetAlias("x_minus", "-0.03");
  R2S->SetAlias("x_plus", "+0.03");
  R2S->SetAlias("y_minus",  "-0.03");
  R2S->SetAlias("y_plus", "+0.03");

  R2S->SetAlias("x_minus_700", "-0.07");
  R2S->SetAlias("x_plus_700", "+0.07");
  R2S->SetAlias("y_minus_700",  "-0.07");
  R2S->SetAlias("y_plus_700", "+0.07");



  R2S->SetAlias("BEAM_x_shift_minus", "0.086-0.03-0.0007*z");
  R2S->SetAlias("BEAM_x_shift_plus", "0.086+0.03-0.0007*z");
  R2S->SetAlias("BEAM_y_shift_minus", "-0.197-0.03+0.0007*z");
  R2S->SetAlias("BEAM_y_shift_plus", "-0.197+0.03+0.0005*z");


  R2S->SetAlias("BEAM_x_shift_minus_700", "0.086-0.07-0.0007*z");
  R2S->SetAlias("BEAM_x_shift_plus_700", "0.086+0.07-0.0007*z");
  R2S->SetAlias("BEAM_y_shift_minus_700", "-0.197-0.07+0.0007*z");
  R2S->SetAlias("BEAM_y_shift_plus_700", "-0.197+0.07+0.0007*z");

  R2S->SetAlias("BEAM_x", "0.086-0.0007*z");
  R2S->SetAlias("BEAM_y", "-0.197+0.0007*z");
  R2S->SetAlias("rhoShiftBeam", "sqrt( (x-BEAM_x)*(x-BEAM_x)+(y-BEAM_y)*(y-BEAM_y) )");
  R2S->SetAlias("rhoShiftBeam_xminus", "sqrt( (x-BEAM_x_shift_minus)*(x-BEAM_x_shift_minus)+(y-BEAM_y)*(y-BEAM_y) )");
  R2S->SetAlias("rhoShiftBeam_xplus", "sqrt( (x-BEAM_x_shift_plus)*(x-BEAM_x_shift_plus)+(y-BEAM_y)*(y-BEAM_y) )");
  R2S->SetAlias("rhoShiftBeam_yminus", "sqrt( (x-BEAM_x)*(x-BEAM_x)+(y-BEAM_y_shift_minus)*(y-BEAM_y_shift_minus) )");
  R2S->SetAlias("rhoShiftBeam_yplus", "sqrt( (x-BEAM_x)*(x-BEAM_x)+(y-BEAM_y_shift_plus)*(y-BEAM_y_shift_plus) )");

  R2S->SetAlias("rhoShiftBeam_xminus_700", "sqrt( (x-BEAM_x_shift_minus_700)*(x-BEAM_x_shift_minus_700)+(y-BEAM_y)*(y-BEAM_y) )");
  R2S->SetAlias("rhoShiftBeam_xplus_700", "sqrt( (x-BEAM_x_shift_plus_700)*(x-BEAM_x_shift_plus_700)+(y-BEAM_y)*(y-BEAM_y) )");
  R2S->SetAlias("rhoShiftBeam_yminus_700", "sqrt( (x-BEAM_x)*(x-BEAM_x)+(y-BEAM_y_shift_minus_700)*(y-BEAM_y_shift_minus_700) )");
  R2S->SetAlias("rhoShiftBeam_yplus_700", "sqrt( (x-BEAM_x)*(x-BEAM_x)+(y-BEAM_y_shift_plus_700)*(y-BEAM_y_shift_plus_700) )");



  R2S->SetAlias("rhoBeam_xminus", "sqrt( (x-x_minus)*(x-x_minus)+y*y )");
  R2S->SetAlias("rhoBeam_xplus", "sqrt( (x-x_plus)*(x-x_plus)+y*y )");
  R2S->SetAlias("rhoBeam_yminus", "sqrt( x*x+(y-y_minus)*(y-y_minus) )");
  R2S->SetAlias("rhoBeam_yplus", "sqrt( x*x+(y-y_plus)*(y-y_plus) )");

  R2S->SetAlias("rhoBeam_xminus_700", "sqrt( (x-x_minus_700)*(x-x_minus_700)+y*y )");
  R2S->SetAlias("rhoBeam_xplus_700", "sqrt( (x-x_plus_700)*(x-x_plus_700)+y*y )");
  R2S->SetAlias("rhoBeam_yminus_700", "sqrt( x*x+(y-y_minus_700)*(y-y_minus_700) )");
  R2S->SetAlias("rhoBeam_yplus_700", "sqrt( x*x+(y-y_plus_700)*(y-y_plus_700) )");

  write  = new TFile(s_file.data(), "RECREATE");

  generalCut =  (nuclCut && cVtx);

  //PSFile = new TPostScript(psFileName, 112);

  // ================ BEGINING OF REC STUDY ================ //


//--------------------------------------//
//------------- Canvas 1.2 --------------//
//------------- Rho Barrel Nucl ----------------//
//--------------------------------------//

 nbins = 100; 
 min = -5, max = min + nbins*0.1;
 plotName  = "z_BeamSpot";
 histo_title = "z_BeamSpot";
 xaxis_title = "z(BeamSpot)";
 variable = "bsz0";
 cut0 = "rho < 3.2 && rho > 2.8";
 cut = cut0&&generalCut;
 
 PlottiPlotta();



//------------- Canvas 1.2 --------------//
//------------- Rho Barrel Nucl ----------------//
//--------------------------------------//

 nbins = 200; 
 min = -0.1, max = min + nbins*0.001;
 plotName  = "x_BeamSpot";
 histo_title = "x_BeamSpot";
 xaxis_title = "x(BeamSpot)";
 variable = "bsx0";
 cut0 = "rho < 3.2 && rho > 2.8";
 cut = cut0&&generalCut;
 
 PlottiPlotta();


//------------- Canvas 1.2 --------------//
//------------- Rho Barrel Nucl ----------------//
//--------------------------------------//

 nbins = 200; 
 min = -0.1, max = min + nbins*0.001;
 plotName  = "y_BeamSpot";
 histo_title = "y_BeamSpot";
 xaxis_title = "y(BeamSpot)";
 variable = "bsy0";
 cut0 = "rho < 3.2 && rho > 2.8";
 cut = cut0&&generalCut;
 
 PlottiPlotta();







//------------- Canvas 1.2 --------------//
//------------- Rho Barrel Nucl ----------------//
//--------------------------------------//

 nbins = 60; 
 min = -3, max = min + nbins*0.1;
 plotName  = "tkDxy_min";
 histo_title = "tkDxy_min";
 xaxis_title = "dxy min wrto to primary vertices";
 variable = "tkDxy_min";
 cut0 = "rho < 3.2 && rho > 2.8 && minDxyVertexNumber>0";
 cut = cut0&&generalCut;
 
 PlottiPlotta();



    //------------- Canvas 1.1 --------------//
    //------------- XY Barrel Nucl ----------------//
    //--------------------------------------//

 nbins = 60; 
 min = -3, max = min + nbins*0.1;
 nbins1 = 60; 
 min1 = -6, max1 = min1 + nbins1*0.2;
 plotName = "tkDxy_vs_tkDz_map";
 histo_title = "tkDxy_vs_tkDz_map";
 xaxis_title = "tkDxy_min";
 yaxis_title = "tkDzForDxyMin";
 variable1 = "tkDzForDxyMin";  variable = "tkDxy_min";
 cut0 = "rho < 3.2 && rho > 2.8 && minDxyVertexNumber>0";
 cut = cut0&&generalCut;
 
 PlottiPlotta2D();























}