Exemple #1
0
int main (int argc, char *argv[])
{
 
  cout << "#########################" << endl;
  cout << "Beginning of the program" << endl;
  cout << "#########################" << endl;

  //////////////////////
  //Global variables
  //////////////////////
  vector < Dataset > datasets;
  SSDiLeptonSelection sel;
  float Luminosity = 0;
  float LumiError = 0.;
  // 0: MC - 1: Data - 2 Data & MC
  int DataType = 0;
  int verbosity = -1;

  int AnaStep = 6;//which defines the cuts that the events should pass to be considered as selected

  float Nobs_mumu = 0.;
  //////////////////////

  //////////////////////
  // Initialisation
  //////////////////////
  string xmlFileName;
  cout<<"argc "<<argc<<" "<<argv[0]<<endl;
  if (argc>1 ) xmlFileName = string(argv[1]);
  else xmlFileName = string ("../../config/TTbarMETAnalysis.xml");
  AnalysisEnvironmentLoader anaEL (xmlFileName);
  anaEL.LoadSamples (datasets);	// now the list of datasets written in the xml file is known
  anaEL.LoadSSDiLeptonSelection (sel);	// now the parameters for the selection are given to the selection
  anaEL.LoadGeneralInfo (DataType, Luminosity, LumiError, verbosity);
  int flagOriginal=sel.GetFlagb();
  int methodOriginal=sel.GetMethodb();
  int systOriginal= sel.GetSystb();
  std::cout << " For btag : flag " << flagOriginal << ", method " << methodOriginal << ", syst " << systOriginal << std::endl;
  IPHCTree::NTEvent * event = 0;
  //Selection table
  SelectionTable selTable_allChannels (sel.GetCutList (), datasets, string ("*"));
  SelectionTable selTable_ee (sel.GetCutList (), datasets, string ("ee"));
  SelectionTable selTable_emu (sel.GetCutList (), datasets, string ("emu"));
  SelectionTable selTable_mumu (sel.GetCutList (), datasets, string ("mumu"));
  
/*
  //Book keeping of standard histos
  bool doHistoManager = true;
  SSDiLepAnaHistoManager histoManager;
  if(doHistoManager){
  	histoManager.LoadDatasets (datasets);
  	histoManager.LoadSelectionSteps (sel.GetCutList ());
  	histoManager.LoadChannels (sel.GetChannelList ());
  	histoManager.CreateHistos ();
  }
*/

  TH1F* h_mult_lep_0  =  new TH1F("h_mult_lep_0",     "# of leptons (bf cuts)",   5,0.0,5.0);
  TH1F* h_mult_jet_0  =  new TH1F("h_mult_jet_0",     "# of jets (bf cuts)",     10,0.0,10.0);
  TH1F* h_mult_bjet_0 =  new TH1F("h_mult_bjet_0",    "# of b-jets (bf cuts)",    5,0.0,5.0);
  TH1F* h_pt_lep1_0   =  new TH1F("h_pt_lep1_0",      "PT of leading lepton (bf cuts)",60,0.0,300.0);
  TH1F* h_eta_lep1_0  =  new TH1F("h_eta_lep1_0",     "Eta of leading lepton (bf cuts)",66,-3.3,3.3);
  TH1F* h_pt_jet1_0   =  new TH1F("h_pt_jet1_0",      "PT of leading jet (bf cuts)",60,0.0,300.0);
  TH1F* h_pt_jet2_0   =  new TH1F("h_pt_jet2_0",      "PT of jet 2 (bf cuts)",60,0.0,300.0);
  TH1F* h_pt_jet3_0   =  new TH1F("h_pt_jet3_0",      "PT of jet 3 (bf cuts)",60,0.0,300.0);
  TH1F* h_pt_jet4_0   =  new TH1F("h_pt_jet4_0",      "PT of jet 4 (bf cuts)",60,0.0,300.0);
  TH1F* h_met_0       =  new TH1F("h_met_0",          "MET (bf cuts)",40,0.0,400.0);
  TH1F* h_mt_0        =  new TH1F("h_mt_0",           "MT(invisible+lepton) (bf cuts)",100,0.0,1000.0);
  TH1F* h_mt_0_2      =  new TH1F("h_mt_0_2",         "MT(invisible+lepton) (bf cuts)",20,0.0,1000.0);
  TH1F* h_ht_0        =  new TH1F("h_ht_0",           "HT (bf cuts)",100,0.0,500.0);
  TH1F* h_m3_0        =  new TH1F("h_m3_0",           "M3 (bf cuts)",100,0.0,1000.0);

  TH1F* h_mult_jet_1  =  new TH1F("h_mult_jet_1",     "# of jets (af cuts)",     10,0.0,10.0);
  TH1F* h_met_1       =  new TH1F("h_met_1",          "MET (af cuts)",40,0.0,400.0);
  TH1F* h_met_1_2     =  new TH1F("h_met_1_2",        "MET (af cuts)",10,0.0,400.0);
  TH1F* h_mt_1        =  new TH1F("h_mt_1",           "MT(invisible+lepton) (af cuts)",100,0.0,1000.0);
  TH1F* h_mt_1_2      =  new TH1F("h_mt_1_2",         "MT(invisible+lepton) (af cuts)",20,0.0,1000.0);
  TH1F* h_pt_lep1_1   =  new TH1F("h_pt_lep1_1",      "PT of leading lepton (af cuts)",60,0.0,300.0);
  TH1F* h_eta_lep1_1  =  new TH1F("h_eta_lep1_1",     "Eta of leading lepton (af cuts)",66,-3.3,3.3);
  TH1F* h_pt_jet1_1   =  new TH1F("h_pt_jet1_1",      "PT of leading jet (af cuts)",60,0.0,300.0);
  TH1F* h_pt_jet2_1   =  new TH1F("h_pt_jet2_1",      "PT of jet 2 (af cuts)",60,0.0,300.0);
  TH1F* h_pt_jet3_1   =  new TH1F("h_pt_jet3_1",      "PT of jet 3 (af cuts)",60,0.0,300.0);
  TH1F* h_pt_jet4_1   =  new TH1F("h_pt_jet4_1",      "PT of jet 4 (af cuts)",60,0.0,300.0);
  TH1F* h_ht_1        =  new TH1F("h_ht_1",           "HT (af cuts)",100,0.0,500.0);
  TH1F* h_m3_1        =  new TH1F("h_m3_1",           "M3 (af cuts)",100,0.0,1000.0);
  TH1F* h_mult_bjet_1 =  new TH1F("h_mult_bjet_1",    "# of b-jets (af cuts)",    5,0.0,5.0);
  TH1F* h_pt_bjet1_2  =  new TH1F("h_pt_bjet1_2",     "PT of leading b-jet (af cuts)",60,0.0,300.0);

  TH1F* h_tophad_pt_1      =  new TH1F("h_tophad_pt_1",     "PT of top1 (af cuts)",100,0.,1000.);
  TH1F* h_toplep_pt_1      =  new TH1F("h_toplep_pt_1",     "PT of top2 (af cuts)",100,0.,1000.);
  TH1F* h_wlep_pt_1        =  new TH1F("h_wlep_pt_1",       "PT of w2 (af cuts)",100,0.,1000.);
  TH1F* h_toplep_m_1       =  new TH1F("h_toplep_m_1",      "M of top2 (af cuts)",100,0.,1000.);
  TH1F* h_dphi_l_mis_1     =  new TH1F("h_dphi_l_mis_1",    "Dphi(l,MET) (af cuts)",30,-1.*pi,pi);
  TH1F* h_dphi_l_jet4th_1  =  new TH1F("h_dphi_l_jet4th_1", "Dphi(l,jet4th) (af cuts)",30,-1.*pi,pi);
  TH1F* h_dphi_2top_1      =  new TH1F("h_dphi_2top_1",     "Dphi(top1,top2) (af cuts)",30,-1.*pi,pi);
  TH1F* h_deta_l_tophad_1  =  new TH1F("h_deta_l_tophad_1", "Deta(l,top1) (af cuts)",50,0.,5.);
  TH1F* h_deta_l_jet4th_1  =  new TH1F("h_deta_l_jet4th_1", "Deta(l,jet4th) (af cuts)",50,0.,5.);
  TH1F* h_tophad_pt_2      =  new TH1F("h_tophad_pt_2",     "PT of top1 (af cuts)",100,0.,1000.);
  TH1F* h_toplep_pt_2      =  new TH1F("h_toplep_pt_2",     "PT of top2 (af cuts)",100,0.,1000.);
  TH1F* h_wlep_pt_2        =  new TH1F("h_wlep_pt_2",       "PT of w2 (af cuts)",100,0.,1000.);
  TH1F* h_toplep_m_2       =  new TH1F("h_toplep_m_2",      "M of top2 (af cuts)",100,0.,1000.);
  TH1F* h_dphi_l_mis_2     =  new TH1F("h_dphi_l_mis_2",    "Dphi(l,MET) (af cuts)",30,-1.*pi,pi);
  TH1F* h_dphi_l_jet4th_2  =  new TH1F("h_dphi_l_jet4th_2", "Dphi(l,jet4th) (af cuts)",30,-1.*pi,pi);
  TH1F* h_dphi_2top_2      =  new TH1F("h_dphi_2top_2",     "Dphi(top1,top2) (af cuts)",30,-1.*pi,pi);
  TH1F* h_deta_l_tophad_2  =  new TH1F("h_deta_l_tophad_2", "Deta(l,top1) (af cuts)",50,0.,5.);
  TH1F* h_deta_l_jet4th_2  =  new TH1F("h_deta_l_jet4th_2", "Deta(l,jet4th) (af cuts)",50,0.,5.);
  
  TH2F* h_top1_top2_1       =  new TH2F("h_top1_top2_1",      "M of top2 vs M of top1 (af cuts)",100,0.,1000.,100,0.,1000.);
  TH2F* h_top1_top2_2       =  new TH2F("h_top1_top2_2",      "M of top2 vs M of top1 (af cuts)",100,0.,1000.,100,0.,1000.);


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


  cout << "The verbosity mode is " << verbosity << endl;
  cout << "The luminosity is equal to " << Luminosity << endl;
  cout << "The DataType is ";
  switch (DataType) {
  case 0:
    cout << "MC" << endl;
    break;
  case 1:
    cout << "Data" << endl;
    break;
  case 2:
    cout << "Data & MC" << endl;
    break;
  default:
    cout << " unknown" << endl;
    break;
  }
  //////////////////////



  //////////////////////
  //LOOP OVER THE DATASETS
  //////////////////////
  if (verbosity > 0) {
    cout << "#########################" << endl;
    cout << " Loop over the datasets  " << endl;
    cout << "#########################" << endl;
  }

  for (unsigned int d = 0; d < datasets.size (); d++) 
  {

    if(verbosity>2) cout<<"TTbarMET> Dataset: "<<datasets[d].Name()<<endl;
    datasets[d].eventTree ()->SetBranchAddress ("NTEvent", &event);

    unsigned int nEvents = static_cast<unsigned int>(datasets[d].eventTree ()->GetEntries ());
    cout << "TTbarMET> NEvents = " << nEvents << endl;
    cout << "TTbarMET> NEvents to run over = "<<datasets[d].NofEvtsToRunOver()<<endl;


    //LOOP OVER THE EVENTS
    for (unsigned int ievt = 0; ievt < datasets[d].NofEvtsToRunOver(); ievt++)
    {
      float weight = 1.;
      if(datasets[d].isData() == false) weight = datasets[d].NormFactor()*Luminosity; //if Data , weight = 1
      //cout<<"weight "<<weight<<" "<<datasets[d].isData()<<endl;
      datasets[d].eventTree()->GetEntry(ievt);
      IPHCTree::NTTransient::InitializeAfterReading(event);

      if (ievt==0) {
	      cout << "TTbarMET> weight : " << weight << endl;
      }
      if (verbosity > 3)
      {
        std::cout << "event " << ievt 
                  <<" - event number=" << event->general.eventNb
                  <<" - run number="   << event->general.runNb
                  << std::endl;
      }
      if (ievt % 5000 == 0)
	      cout << "TTbarMET> Progress bar : " << ievt << endl;

      //Load event for the selection
      sel.LoadEvent(event);

      //Collection of selected objects
      vector < NTElectron > selElectrons = sel.GetSelectedElectrons ();
      vector < NTMuon > selMuons = sel.GetSelectedMuons ();
      vector < NTJet > selJets = sel.GetSelectedJets (selMuons,selElectrons);
      NTMET themet = sel.GetSelectedMET ();


      // DEFINE NEW OBJECTS
      TLorentzVector resetvector(0.,0.,0.,0.);
      // 1. Leptons
      vector <TLorentzVector> selLepton;
      for (int i=0; i<selElectrons.size(); i++) {
          selLepton.push_back(selElectrons[i].p4);
      }
      for (int i=0; i<selMuons.size(); i++) {
          selLepton.push_back(selMuons[i].p4);
      }
      sort(selLepton.begin(),selLepton.end(),SortByPt());


      // 2. Total hadronic activity
      TLorentzVector all_hadronic;
      for (UInt_t ind=0;ind<selJets.size();ind++) {
        all_hadronic+=selJets[ind].p4;
      }

      // 3. The leptonic W
      TLorentzVector w_leptonic;
      float misset = themet.met();
      float mt_e_mis=-1.;
//      if (ievt<5) std::cout << "MET " << misset << " " << themet.p2.Mod() << " " << themet.p2MuonCorr.Mod() << " " << themet.correction << std::endl;
      TLorentzVector mismis(themet.p2.Px(),themet.p2.Py(),0.,themet.p2.Mod());
      if (misset>0 && selLepton.size()>0) {
         w_leptonic = selLepton[0] + mismis;
         mt_e_mis = sqrt( 2.* selLepton[0].P() * misset *(1. - cos( selLepton[0].Phi() - mismis.Phi()) ));

      }


      //3. The hadronic Top (from M3)
      //4. The 4th jet (after M3)
      TLorentzVector top_hadronic;
      TLorentzVector tmp_b;
      float test_pt=0;
      float test_pt_2=0;

      bool secure_pt_jet_kin= false;
      if (selJets.size()>=3) {
       for (UInt_t ind=0;ind<selJets.size();ind++) {
        for (UInt_t ind1=ind+1; ind1<selJets.size();ind1++) {
         for (UInt_t ind2=ind1+1; ind2<selJets.size();ind2++) {
           TLorentzVector combi_test;
           combi_test=selJets[ind].p4;
           combi_test+=selJets[ind1].p4;
           combi_test+=selJets[ind2].p4;
           if (combi_test.Pt()>test_pt) {
             test_pt=combi_test.Pt();
             top_hadronic=combi_test;
             if (selJets.size()>3) {
              for (UInt_t ind3=0; ind3<selJets.size();ind3++) {
               if (ind3!=ind && ind3!=ind1 && ind3!=ind2 && selJets[ind3].p4.Pt()>test_pt_2) {
                   test_pt_2=selJets[ind3].p4.Pt();
                   tmp_b=selJets[ind3].p4;
                   // mini-test
                   if (selJets[ind].p4.Pt()>25 && selJets[ind1].p4.Pt()>25 && selJets[ind2].p4.Pt()>25 && selJets[ind3].p4.Pt()>25) {
                      secure_pt_jet_kin=true;
                   }
                   else {
                      secure_pt_jet_kin=false;
                   }
          
               }
              }
             }
           }
         }
        }
       }
      }

      //5. The leptonic Top
      TLorentzVector top_leptonic;
      if (misset>0 && selLepton.size()>0 && selJets.size()>3) top_leptonic = w_leptonic + tmp_b;

      //6. The b-jets avant cut en Pt
      vector < NTJet > selBtagJets;
      vector < float >btagDiscri;
      //cas CSV ou JP : recommandation de BTV  
      // CSVL wp = 0.244 ; CSVM wp = 0.679 ; CSVT wp = 0.898 combinedSecondaryVertexBJetTags
      // JPL  wp = 0.275 ; JPM  wp = 0.545 ; JPT  wp = 0.790 jetProbabilityBJetTags
      string btag_algo = "combinedSecondaryVertexBJetTags";
      float btag_DiscriCut=0.244;
      for (UInt_t j = 0; j < selJets.size (); j++) {
//        if (ievt<5) cout << "jet " << j << " algo CSV " << selJets[j].bTag[btag_algo] << " >= ? " << btag_DiscriCut << endl;
        if (selJets[j].bTag[btag_algo] >= btag_DiscriCut) {
            selBtagJets.push_back (selJets[j]);
            btagDiscri.push_back (selJets[j].bTag[btag_algo]);
        }
      }


      // FILL HISTO BEFORE CUTS
      h_mult_lep_0->Fill(selLepton.size(),weight);
      h_mult_jet_0->Fill(selJets.size(),weight);
      h_mult_bjet_0->Fill(selBtagJets.size());
      if (ievt<5) cout << "Bjets " <<  selBtagJets.size() << endl;

      if (selLepton.size()>0) {
        h_pt_lep1_0->Fill(selLepton[0].Pt(),weight);
        h_eta_lep1_0->Fill(selLepton[0].Eta(),weight);
      }

      if (selJets.size()>0) {
        h_pt_jet1_0->Fill(selJets[0].p4.Pt(),weight);
        if (selJets.size()>1) {
          h_pt_jet2_0->Fill(selJets[1].p4.Pt(),weight);
          if (selJets.size()>2) {
            h_pt_jet3_0->Fill(selJets[2].p4.Pt(),weight);
            if (selJets.size()>3) {
              h_pt_jet4_0->Fill(selJets[3].p4.Pt(),weight);
            }
          }
        }
      }  

      h_met_0->Fill(misset,weight);
      h_ht_0->Fill(all_hadronic.Pt(),weight);
      h_mt_0->Fill(mt_e_mis,weight);
      h_mt_0_2->Fill(mt_e_mis,weight);
      h_m3_0->Fill( top_hadronic.M() ,weight); 


      // APPLY SELECTION CUTS

      bool pass_cut = true;
      if (selLepton.size()==0) pass_cut = false ;
      if (selLepton.size()>0 && selLepton[0].Pt()<25.0) pass_cut = false;
      vector < NTJet > selJetsPt25;
      for (UInt_t j = 0; j < selJets.size (); j++) {
        if (selJets[j].p4.Pt()>=25.) {
            selJetsPt25.push_back (selJets[j]);
        }
      }
      if (selJetsPt25.size()<=3) pass_cut = false ;
      if (misset<100.) pass_cut = false; 
      vector < NTJet > selBtagJetsPt25;
      for (UInt_t j = 0; j < selBtagJets.size (); j++) {
        if (selBtagJets[j].p4.Pt()>=25.) {
            selBtagJetsPt25.push_back (selBtagJets[j]);
        }
      }

      if (pass_cut) {

          // 2. Total hadronic activity : recalcul
          all_hadronic = resetvector;
          for (UInt_t ind=0;ind<selJetsPt25.size();ind++) {
           all_hadronic+=selJets[ind].p4;
          }
          // question : est-ce que ces 4 jets selectionnes pour m3 et tmp_b ont bien un Pt>25 GeV???
          if (!secure_pt_jet_kin) {
            // recalcul des info kin
            //3. The hadronic Top (from M3) : recalcul
            //4. The 4th jet (after M3) : recalcul
            top_hadronic = resetvector;
            tmp_b = resetvector;
            test_pt=0;
            test_pt_2=0;
            for (UInt_t ind=0;ind<selJetsPt25.size();ind++) {
             for (UInt_t ind1=ind+1; ind1<selJetsPt25.size();ind1++) {
              for (UInt_t ind2=ind1+1; ind2<selJetsPt25.size();ind2++) {
                TLorentzVector combi_test;
                combi_test=selJetsPt25[ind].p4;
                combi_test+=selJetsPt25[ind1].p4;
                combi_test+=selJetsPt25[ind2].p4;
                if (combi_test.Pt()>test_pt) {
                  test_pt=combi_test.Pt();
                  top_hadronic=combi_test;
                   for (UInt_t ind3=0; ind3<selJetsPt25.size();ind3++) {
                    if (ind3!=ind && ind3!=ind1 && ind3!=ind2 && selJetsPt25[ind3].p4.Pt()>test_pt_2) {
                        test_pt_2=selJetsPt25[ind3].p4.Pt();
                        tmp_b=selJetsPt25[ind3].p4;
                    }
                   }
                  }
                }
               }
              }
              //5. The leptonic Top
              top_leptonic = w_leptonic + tmp_b;
          }

          // FILL HISTO AFTER CUTS

          h_mult_jet_1->Fill(selJetsPt25.size(),weight);
          h_mult_bjet_1->Fill(selBtagJetsPt25.size());

          h_pt_lep1_1->Fill(selLepton[0].Pt(),weight);
          h_eta_lep1_1->Fill(selLepton[0].Eta(),weight);

          h_pt_jet1_1->Fill(selJetsPt25[0].p4.Pt(),weight);
          h_pt_jet2_1->Fill(selJetsPt25[1].p4.Pt(),weight);
          h_pt_jet3_1->Fill(selJetsPt25[2].p4.Pt(),weight);
          h_pt_jet4_1->Fill(selJetsPt25[3].p4.Pt(),weight);

          h_met_1->Fill(misset,weight);
          h_met_1_2->Fill(misset,weight);

          h_mt_1->Fill( mt_e_mis ,weight);
          h_mt_1_2->Fill( mt_e_mis ,weight);

          h_ht_1->Fill(all_hadronic.Pt(),weight);

          h_m3_1->Fill( top_hadronic.M() ,weight);

          float delta_phi_e_miss= selLepton[0].DeltaPhi(mismis);
          float delta_phi_ejet4th= selLepton[0].DeltaPhi(tmp_b);
          float delta_phi_2top= top_hadronic.DeltaPhi(top_leptonic);
          float deta_e_tophad= selLepton[0].Eta() - top_hadronic.Eta();
          if (deta_e_tophad<0.) deta_e_tophad*=-1.;
          float deta_e_jet4th= selLepton[0].Eta() - tmp_b.Eta();
          if (deta_e_jet4th<0.) deta_e_jet4th*=-1.;

          h_tophad_pt_1->Fill( top_hadronic.Pt() ,weight);
          h_toplep_pt_1->Fill( top_leptonic.Pt() ,weight);
          h_wlep_pt_1->Fill( w_leptonic.Pt() ,weight);
          h_toplep_m_1->Fill( top_leptonic.M() ,weight);
          h_dphi_l_mis_1->Fill( delta_phi_e_miss ,weight);
          h_dphi_l_jet4th_1->Fill( delta_phi_ejet4th ,weight);
          h_dphi_2top_1->Fill( delta_phi_2top ,weight);
          h_deta_l_tophad_1->Fill (deta_e_tophad ,weight);
          h_deta_l_jet4th_1->Fill (deta_e_jet4th ,weight);
          h_top1_top2_1->Fill( top_hadronic.M(), top_leptonic.M() ,weight);


          if (selBtagJetsPt25.size()>0) {
           h_pt_bjet1_2->Fill(selBtagJetsPt25[0].p4.Pt());
           h_tophad_pt_2->Fill( top_hadronic.Pt() ,weight);
           h_toplep_pt_2->Fill( top_leptonic.Pt() ,weight);
           h_wlep_pt_2->Fill( w_leptonic.Pt() ,weight);
           h_toplep_m_2->Fill( top_leptonic.M() ,weight);
           h_dphi_l_mis_2->Fill( delta_phi_e_miss ,weight);
           h_dphi_l_jet4th_2->Fill( delta_phi_ejet4th ,weight);
           h_dphi_2top_2->Fill( delta_phi_2top ,weight);
           h_deta_l_tophad_2->Fill (deta_e_tophad ,weight);
           h_deta_l_jet4th_2->Fill (deta_e_jet4th ,weight);
           h_top1_top2_2->Fill( top_hadronic.M(), top_leptonic.M() ,weight);

          }


      }  // end of "after cuts"
      


    }				// end of loop over evts


  }				// end of loop over the datasets 
  cout << "#########################" << endl;
  cout << " Loop over the datasets  " << endl;
  cout << "#########################" << endl;



  ////////////////////////////
  //  Computation after loops
  ////////////////////////////

  ////////////////////////////
  //  Histograms
  ////////////////////////////

  string ofilename= string("CrossSection")+string(".root");
  TFile* fout  = new TFile(ofilename.c_str(),"RECREATE");


    h_mult_lep_0->Write();
    h_mult_jet_0->Write();
    h_mult_bjet_0->Write();
    h_pt_lep1_0->Write();
    h_eta_lep1_0->Write();
    h_pt_jet1_0->Write();
    h_pt_jet2_0->Write();
    h_pt_jet3_0->Write();
    h_pt_jet4_0->Write();
    h_met_0->Write();
    h_mt_0->Write();
    h_mt_0_2->Write();
    h_ht_0->Write();
    h_m3_0->Write();

    
    h_mult_jet_1->Write();
    h_met_1->Write();
    h_met_1_2->Write();    
    h_mt_1->Write();       
    h_mt_1_2->Write();     
    h_pt_lep1_1->Write();
    h_eta_lep1_1->Write(); 
    h_pt_jet1_1->Write();  
    h_pt_jet2_1->Write();
    h_pt_jet3_1->Write(); 
    h_pt_jet4_1->Write(); 
    h_ht_1->Write();       
    h_m3_1->Write();     
    h_mult_bjet_1->Write();
    h_pt_bjet1_2->Write();
    
    h_tophad_pt_1->Write();
    h_toplep_pt_1->Write();
    h_wlep_pt_1->Write();
    h_toplep_m_1->Write();
    h_dphi_l_mis_1->Write();
    h_dphi_l_jet4th_1->Write();
    h_dphi_2top_1->Write();
    h_deta_l_tophad_1->Write();
    h_deta_l_jet4th_1->Write();
    h_tophad_pt_2->Write();
    h_toplep_pt_2->Write();
    h_wlep_pt_2->Write();
    h_toplep_m_2->Write();
    h_dphi_l_mis_2->Write();
    h_dphi_l_jet4th_2->Write();
    h_dphi_2top_2->Write();
    h_deta_l_tophad_2->Write();
    h_deta_l_jet4th_2->Write();

    h_top1_top2_1->Write();
    h_top1_top2_2->Write();

  fout->Close();

  delete fout;


  if (verbosity > 0) {
    cout << "#########################" << endl;
    cout << "    End of the program   " << endl;
    cout << "#########################" << endl;
  }

  return (0);
}
int main( int argc, const char* argv[] ){

  // List of arguments:
  // 0: The executable itself
  // 1: The number of times JetMET is smeared (not smeared if equal to 1)
  // 2: The scale and type of JES shift (if fabs(x) < 0.5, shift by eta, else absolute

// fixme: Depracated
   float JES_JetMET = 1.0;

  string xmlFileName = string ("./MyMassAnalysis.xml");

  for (int i=1;i<argc;++i) {
    if (strncmp(argv[i],"-c",2)==0) xmlFileName = string(argv[i+1]);
    if (strncmp(argv[i],"-h",2)==0) {
      cout << " -c xm_config_file\n";
      exit(1);
    }
  }

  cout<<"#########################"<<endl;
  cout<<"Beginning of the program"<<endl;
  cout<<"#########################"<<endl;

  //////////////////////
  //Global variables
  //////////////////////

  // GEN
  TH1F * histoGenTopRapidity1 = new TH1F("GenTopRapidity1", "GenTopRapidity1", 100, -5, 5);
  TH1F * histoGenTopRapidity2 = new TH1F("GenTopRapidity2", "GenTopRapidity2", 100, -5, 5);
  TH1F * histoGenTopMass1 = new TH1F("GenTopMass1", "GenTopMass1", 200, 0, 200);
  TH1F * histoGenTopMass2 = new TH1F("GenTopMass2", "GenTopMass2", 200, 0, 200);
  TH2F * histoGenTopMass1VsTopMass2 = new TH2F("GenTopMass1VsTopMass2", "GenTopMass1VsTopMass2", 200, 0, 200, 200, 0, 200);
  TH1F * histoGenDelta_y = new TH1F("GenDelta_y", "GenDelta_y", 400, -2, 2);
  TH1F * histoGenTTRapidity = new TH1F("GenTTRapidity", "GenTTRapidity", 500, -2.5, 2.5);
  TH1F * histoGenTTPt = new TH1F("GenTTPt", "GenTTPt", 250, 0, 250);
  TH1F * histoGenTTMass = new TH1F("GenTTMass", "GenTTMass", 100, 0, 1000);

  TH2F * histoGenDelta_yVsTTRapidity = new TH2F("GenDelta_yVsTTRapidity", "GenDelta_yVsTTRapidity", 10, -2, 2, 5, -2.5, 2.5);
  TH2F * histoGenDelta_yVsTTPt = new TH2F("GenDelta_yVsTTPt", "GenDelta_yVsTTPt", 10, -2, 2, 5, 0, 250);
  TH2F * histoGenDelta_yVsTTMass = new TH2F("GenDelta_yVsTTMass", "GenDelta_yVsTTMass", 10, -2, 2, 5, 0, 1000);
  TH1F * histoGenN_plusTTRapidity = new TH1F("GenN_plusTTRapidity", "GenN_plusTTRapidity", 20, -2.5, 2.5);
  histoGenN_plusTTRapidity->Sumw2();
  TH1F * histoGenN_plusTTPt = new TH1F("GenN_plusTTPt", "GenN_plusTTPt", 20, 0, 250);
  histoGenN_plusTTPt->Sumw2();
  TH1F * histoGenN_plusTTMass = new TH1F("GenN_plusTTMass", "GenN_plusTTMass", 20, 0, 1000);
  histoGenN_plusTTMass->Sumw2();
  TH1F * histoGenN_minusTTRapidity = new TH1F("GenN_minusTTRapidity", "GenN_minusTTRapidity", 20, -2.5, 2.5);
  histoGenN_minusTTRapidity->Sumw2();
  TH1F * histoGenN_minusTTPt = new TH1F("GenN_minusTTPt", "GenN_minusTTPt", 20, 0, 250);
  histoGenN_minusTTPt->Sumw2();
  TH1F * histoGenN_minusTTMass = new TH1F("GenN_minusTTMass", "GenN_minusTTMass", 20, 0, 1000);
  histoGenN_minusTTMass->Sumw2();
  TH1F * histoGenN_plusMinusN_minusTTRapidity = new TH1F("GenN_plusMinusN_minusTTRapidity", "GenN_plusMinusN_minusTTRapidity", 20, -2.5, 2.5);
  histoGenN_plusMinusN_minusTTRapidity->Sumw2();
  TH1F * histoGenN_plusPlusN_minusTTRapidity = new TH1F("GenN_plusPlusN_minusTTRapidity", "GenN_plusPlusN_minusTTRapidity", 20, -2.5, 2.5);
  histoGenN_plusPlusN_minusTTRapidity->Sumw2();
  TH1F * histoGenN_plusMinusN_minusTTPt = new TH1F("GenN_plusMinusN_minusTTPt", "GenN_plusMinusN_minusTTPt", 20, 0, 250);
  histoGenN_plusMinusN_minusTTPt->Sumw2();
  TH1F * histoGenN_plusPlusN_minusTTPt = new TH1F("GenN_plusPlusN_minusTTPt", "GenN_plusPlusN_minusTTPt", 20, 0, 250);
  histoGenN_plusPlusN_minusTTPt->Sumw2();
  TH1F * histoGenN_plusMinusN_minusTTMass = new TH1F("GenN_plusMinusN_minusTTMass", "GenN_plusMinusN_minusTTMass", 20, 0, 1000);
  histoGenN_plusMinusN_minusTTMass->Sumw2();
  TH1F * histoGenN_plusPlusN_minusTTMass = new TH1F("GenN_plusPlusN_minusTTMass", "GenN_plusPlusN_minusTTMass", 20, 0, 1000);
  histoGenN_plusPlusN_minusTTMass->Sumw2();
  TH1F * histoGenA_cTTRapidity = new TH1F("GenA_cTTRapidity", "GenA_cTTRapidity", 20, -2.5, 2.5);
  histoGenA_cTTRapidity->Sumw2();
  TH1F * histoGenA_cTTPt = new TH1F("GenA_cTTPt", "GenA_cTTPt", 20, 0, 250);
  histoGenA_cTTPt->Sumw2();
  TH1F * histoGenA_cTTMass = new TH1F("GenA_cTTMass", "GenA_cTTMass", 20, 0, 1000);
  histoGenA_cTTMass->Sumw2();
  // Fine binning
  TH2F * histoFineBinning_GenDelta_yVsTTRapidity = new TH2F("FineBinning_GenDelta_yVsTTRapidity", "FineBinning_GenDelta_yVsTTRapidity", 200, -2, 2, 500, -2.5, 2.5);
  TH2F * histoFineBinning_GenDelta_yVsTTPt = new TH2F("FineBinning_GenDelta_yVsTTPt", "FineBinning_GenDelta_yVsTTPt", 200, -2, 2, 250, 0, 250);
  TH2F * histoFineBinning_GenDelta_yVsTTMass = new TH2F("FineBinning_GenDelta_yVsTTMass", "FineBinning_GenDelta_yVsTTMass", 200, -2, 2, 100, 0, 1000);
  TH1F * histoFineBinning_GenN_plusTTRapidity = new TH1F("FineBinning_GenN_plusTTRapidity", "FineBinning_GenN_plusTTRapidity", 500, -2.5, 2.5);
  histoFineBinning_GenN_plusTTRapidity->Sumw2();
  TH1F * histoFineBinning_GenN_plusTTPt = new TH1F("FineBinning_GenN_plusTTPt", "FineBinning_GenN_plusTTPt", 250, 0, 250);
  histoFineBinning_GenN_plusTTPt->Sumw2();
  TH1F * histoFineBinning_GenN_plusTTMass = new TH1F("FineBinning_GenN_plusTTMass", "FineBinning_GenN_plusTTMass", 100, 0, 1000);
  histoFineBinning_GenN_plusTTMass->Sumw2();
  TH1F * histoFineBinning_GenN_minusTTRapidity = new TH1F("FineBinning_GenN_minusTTRapidity", "FineBinning_GenN_minusTTRapidity", 500, -2.5, 2.5);
  histoFineBinning_GenN_minusTTRapidity->Sumw2();
  TH1F * histoFineBinning_GenN_minusTTPt = new TH1F("FineBinning_GenN_minusTTPt", "FineBinning_GenN_minusTTPt", 250, 0, 250);
  histoFineBinning_GenN_minusTTPt->Sumw2();
  TH1F * histoFineBinning_GenN_minusTTMass = new TH1F("FineBinning_GenN_minusTTMass", "FineBinning_GenN_minusTTMass", 100, 0, 1000);
  histoFineBinning_GenN_minusTTMass->Sumw2();
  TH1F * histoFineBinning_GenN_plusMinusN_minusTTRapidity = new TH1F("FineBinning_GenN_plusMinusN_minusTTRapidity", "FineBinning_GenN_plusMinusN_minusTTRapidity", 500, -2.5, 2.5);
  histoFineBinning_GenN_plusMinusN_minusTTRapidity->Sumw2();
  TH1F * histoFineBinning_GenN_plusPlusN_minusTTRapidity = new TH1F("FineBinning_GenN_plusPlusN_minusTTRapidity", "FineBinning_GenN_plusPlusN_minusTTRapidity", 500, -2.5, 2.5);
  histoFineBinning_GenN_plusPlusN_minusTTRapidity->Sumw2();
  TH1F * histoFineBinning_GenN_plusMinusN_minusTTPt = new TH1F("FineBinning_GenN_plusMinusN_minusTTPt", "FineBinning_GenN_plusMinusN_minusTTPt", 250, 0, 250);
  histoFineBinning_GenN_plusMinusN_minusTTPt->Sumw2();
  TH1F * histoFineBinning_GenN_plusPlusN_minusTTPt = new TH1F("FineBinning_GenN_plusPlusN_minusTTPt", "FineBinning_GenN_plusPlusN_minusTTPt", 250, 0, 250);
  histoFineBinning_GenN_plusPlusN_minusTTPt->Sumw2();
  TH1F * histoFineBinning_GenN_plusMinusN_minusTTMass = new TH1F("FineBinning_GenN_plusMinusN_minusTTMass", "FineBinning_GenN_plusMinusN_minusTTMass", 100, 0, 1000);
  histoFineBinning_GenN_plusMinusN_minusTTMass->Sumw2();
  TH1F * histoFineBinning_GenN_plusPlusN_minusTTMass = new TH1F("FineBinning_GenN_plusPlusN_minusTTMass", "FineBinning_GenN_plusPlusN_minusTTMass", 100, 0, 1000);
  histoFineBinning_GenN_plusPlusN_minusTTMass->Sumw2();
  TH1F * histoFineBinning_GenA_cTTRapidity = new TH1F("FineBinning_GenA_cTTRapidity", "FineBinning_GenA_cTTRapidity", 500, -2.5, 2.5);
  histoFineBinning_GenA_cTTRapidity->Sumw2();
  TH1F * histoFineBinning_GenA_cTTPt = new TH1F("FineBinning_GenA_cTTPt", "FineBinning_GenA_cTTPt", 250, 0, 250);
  histoFineBinning_GenA_cTTPt->Sumw2();
  TH1F * histoFineBinning_GenA_cTTMass = new TH1F("FineBinning_GenA_cTTMass", "FineBinning_GenA_cTTMass", 100, 0, 1000);
  histoFineBinning_GenA_cTTMass->Sumw2();


  // RECO
  TH1F * histoRecoTopRapidity1 = new TH1F("RecoTopRapidity1", "RecoTopRapidity1", 100, -5, 5);
  TH1F * histoRecoTopRapidity2 = new TH1F("RecoTopRapidity2", "RecoTopRapidity2", 100, -5, 5);
  TH1F * histoRecoLeptonRapidity1 = new TH1F("RecoLeptonRapidity1", "RecoLeptonRapidity1", 100, -5, 5);
  TH1F * histoRecoLeptonRapidity2 = new TH1F("RecoLeptonRapidity2", "RecoLeptonRapidity2", 100, -5, 5);
  TH1F * histoRecoTopMass1 = new TH1F("RecoTopMass1", "RecoTopMass1", 300, 0, 300);
  TH1F * histoRecoTopMass2 = new TH1F("RecoTopMass2", "RecoTopMass2", 300, 0, 300);
  TH2F * histoRecoTopMass1VsTopMass2 = new TH2F("RecoTopMass1VsTopMass2", "RecoTopMass1VsTopMass2", 300, 0, 300, 300, 0, 300);
  TH1F * histoRecoDelta_y = new TH1F("RecoDelta_y", "RecoDelta_y", 400, -2, 2);
  TH1F * histoRecoTTRapidity = new TH1F("RecoTTRapidity", "RecoTTRapidity", 500, -2.5, 2.5);
  TH1F * histoRecoTTPt = new TH1F("RecoTTPt", "RecoTTPt", 250, 0, 250);
  TH1F * histoRecoTTMass = new TH1F("RecoTTMass", "RecoTTMass", 100, 0, 1000);

  TH2F * histoRecoDelta_yVsTTRapidity = new TH2F("RecoDelta_yVsTTRapidity", "RecoDelta_yVsTTRapidity", 10, -2, 2, 5, -2.5, 2.5);
  TH2F * histoRecoDelta_yVsTTPt = new TH2F("RecoDelta_yVsTTPt", "RecoDelta_yVsTTPt", 10, -2, 2, 5, 0, 250);
  TH2F * histoRecoDelta_yVsTTMass = new TH2F("RecoDelta_yVsTTMass", "RecoDelta_yVsTTMass", 10, -2, 2, 5, 0, 1000);
  TH1F * histoRecoN_plusTTRapidity = new TH1F("RecoN_plusTTRapidity", "RecoN_plusTTRapidity", 20, -2.5, 2.5);
  histoRecoN_plusTTRapidity->Sumw2();
  TH1F * histoRecoN_plusTTPt = new TH1F("RecoN_plusTTPt", "RecoN_plusTTPt", 20, 0, 250);
  histoRecoN_plusTTPt->Sumw2();
  TH1F * histoRecoN_plusTTMass = new TH1F("RecoN_plusTTMass", "RecoN_plusTTMass", 20, 0, 1000);
  histoRecoN_plusTTMass->Sumw2();
  TH1F * histoRecoN_minusTTRapidity = new TH1F("RecoN_minusTTRapidity", "RecoN_minusTTRapidity", 20, -2.5, 2.5);
  histoRecoN_minusTTRapidity->Sumw2();
  TH1F * histoRecoN_minusTTPt = new TH1F("RecoN_minusTTPt", "RecoN_minusTTPt", 20, 0, 250);
  histoRecoN_minusTTPt->Sumw2();
  TH1F * histoRecoN_minusTTMass = new TH1F("RecoN_minusTTMass", "RecoN_minusTTMass", 20, 0, 1000);
  histoRecoN_minusTTMass->Sumw2();
  TH1F * histoRecoN_plusMinusN_minusTTRapidity = new TH1F("RecoN_plusMinusN_minusTTRapidity", "RecoN_plusMinusN_minusTTRapidity", 20, -2.5, 2.5);
  histoRecoN_plusMinusN_minusTTRapidity->Sumw2();
  TH1F * histoRecoN_plusPlusN_minusTTRapidity = new TH1F("RecoN_plusPlusN_minusTTRapidity", "RecoN_plusPlusN_minusTTRapidity", 20, -2.5, 2.5);
  histoRecoN_plusPlusN_minusTTRapidity->Sumw2();
  TH1F * histoRecoN_plusMinusN_minusTTPt = new TH1F("RecoN_plusMinusN_minusTTPt", "RecoN_plusMinusN_minusTTPt", 20, 0, 250);
  histoRecoN_plusMinusN_minusTTPt->Sumw2();
  TH1F * histoRecoN_plusPlusN_minusTTPt = new TH1F("RecoN_plusPlusN_minusTTPt", "RecoN_plusPlusN_minusTTPt", 20, 0, 250);
  histoRecoN_plusPlusN_minusTTPt->Sumw2();
  TH1F * histoRecoN_plusMinusN_minusTTMass = new TH1F("RecoN_plusMinusN_minusTTMass", "RecoN_plusMinusN_minusTTMass", 20, 0, 1000);
  histoRecoN_plusMinusN_minusTTMass->Sumw2();
  TH1F * histoRecoN_plusPlusN_minusTTMass = new TH1F("RecoN_plusPlusN_minusTTMass", "RecoN_plusPlusN_minusTTMass", 20, 0, 1000);
  histoRecoN_plusPlusN_minusTTMass->Sumw2();
  TH1F * histoRecoA_cTTRapidity = new TH1F("RecoA_cTTRapidity", "RecoA_cTTRapidity", 20, -2.5, 2.5);
  histoRecoA_cTTRapidity->Sumw2();
  TH1F * histoRecoA_cTTPt = new TH1F("RecoA_cTTPt", "RecoA_cTTPt", 20, 0, 250);
  histoRecoA_cTTPt->Sumw2();
  TH1F * histoRecoA_cTTMass = new TH1F("RecoA_cTTMass", "RecoA_cTTMass", 20, 0, 1000);
  histoRecoA_cTTMass->Sumw2();
  // Fine binning
  TH2F * histoFineBinning_RecoDelta_yVsTTRapidity = new TH2F("FineBinning_RecoDelta_yVsTTRapidity", "FineBinning_RecoDelta_yVsTTRapidity", 200, -2, 2, 500, -2.5, 2.5);
  TH2F * histoFineBinning_RecoDelta_yVsTTPt = new TH2F("FineBinning_RecoDelta_yVsTTPt", "FineBinning_RecoDelta_yVsTTPt", 200, -2, 2, 250, 0, 250);
  TH2F * histoFineBinning_RecoDelta_yVsTTMass = new TH2F("FineBinning_RecoDelta_yVsTTMass", "FineBinning_RecoDelta_yVsTTMass", 200, -2, 2, 100, 0, 1000);
  TH1F * histoFineBinning_RecoN_plusTTRapidity = new TH1F("FineBinning_RecoN_plusTTRapidity", "FineBinning_RecoN_plusTTRapidity", 500, -2.5, 2.5);
  histoFineBinning_RecoN_plusTTRapidity->Sumw2();
  TH1F * histoFineBinning_RecoN_plusTTPt = new TH1F("FineBinning_RecoN_plusTTPt", "FineBinning_RecoN_plusTTPt", 250, 0, 250);
  histoFineBinning_RecoN_plusTTPt->Sumw2();
  TH1F * histoFineBinning_RecoN_plusTTMass = new TH1F("FineBinning_RecoN_plusTTMass", "FineBinning_RecoN_plusTTMass", 100, 0, 1000);
  histoFineBinning_RecoN_plusTTMass->Sumw2();
  TH1F * histoFineBinning_RecoN_minusTTRapidity = new TH1F("FineBinning_RecoN_minusTTRapidity", "FineBinning_RecoN_minusTTRapidity", 500, -2.5, 2.5);
  histoFineBinning_RecoN_minusTTRapidity->Sumw2();
  TH1F * histoFineBinning_RecoN_minusTTPt = new TH1F("FineBinning_RecoN_minusTTPt", "FineBinning_RecoN_minusTTPt", 250, 0, 250);
  histoFineBinning_RecoN_minusTTPt->Sumw2();
  TH1F * histoFineBinning_RecoN_minusTTMass = new TH1F("FineBinning_RecoN_minusTTMass", "FineBinning_RecoN_minusTTMass", 100, 0, 1000);
  histoFineBinning_RecoN_minusTTMass->Sumw2();
  TH1F * histoFineBinning_RecoN_plusMinusN_minusTTRapidity = new TH1F("FineBinning_RecoN_plusMinusN_minusTTRapidity", "FineBinning_RecoN_plusMinusN_minusTTRapidity", 500, -2.5, 2.5);
  histoFineBinning_RecoN_plusMinusN_minusTTRapidity->Sumw2();  
  TH1F * histoFineBinning_RecoN_plusPlusN_minusTTRapidity = new TH1F("FineBinning_RecoN_plusPlusN_minusTTRapidity", "FineBinning_RecoN_plusPlusN_minusTTRapidity", 500, -2.5, 2.5);
  histoFineBinning_RecoN_plusPlusN_minusTTRapidity->Sumw2();
  TH1F * histoFineBinning_RecoN_plusMinusN_minusTTPt = new TH1F("FineBinning_RecoN_plusMinusN_minusTTPt", "FineBinning_RecoN_plusMinusN_minusTTPt", 250, 0, 250);
  histoFineBinning_RecoN_plusMinusN_minusTTPt->Sumw2();
  TH1F * histoFineBinning_RecoN_plusPlusN_minusTTPt = new TH1F("FineBinning_RecoN_plusPlusN_minusTTPt", "FineBinning_RecoN_plusPlusN_minusTTPt", 250, 0, 250);
  histoFineBinning_RecoN_plusPlusN_minusTTPt->Sumw2();
  TH1F * histoFineBinning_RecoN_plusMinusN_minusTTMass = new TH1F("FineBinning_RecoN_plusMinusN_minusTTMass", "FineBinning_RecoN_plusMinusN_minusTTMass", 100, 0, 1000);
  histoFineBinning_RecoN_plusMinusN_minusTTMass->Sumw2();
  TH1F * histoFineBinning_RecoN_plusPlusN_minusTTMass = new TH1F("FineBinning_RecoN_plusPlusN_minusTTMass", "FineBinning_RecoN_plusPlusN_minusTTMass", 100, 0, 1000);
  histoFineBinning_RecoN_plusPlusN_minusTTMass->Sumw2();
  TH1F * histoFineBinning_RecoA_cTTRapidity = new TH1F("FineBinning_RecoA_cTTRapidity", "FineBinning_RecoA_cTTRapidity", 500, -2.5, 2.5);
  histoFineBinning_RecoA_cTTRapidity->Sumw2();
  TH1F * histoFineBinning_RecoA_cTTPt = new TH1F("FineBinning_RecoA_cTTPt", "FineBinning_RecoA_cTTPt", 250, 0, 250);
  histoFineBinning_RecoA_cTTPt->Sumw2();
  TH1F * histoFineBinning_RecoA_cTTMass = new TH1F("FineBinning_RecoA_cTTMass", "FineBinning_RecoA_cTTMass", 100, 0, 1000);
  histoFineBinning_RecoA_cTTMass->Sumw2();




  // RECO vs GEN
  TH2F * histoRecoVsGenTopRapidity1 = new TH2F("RecoVsGenTopRapidity1", "RecoVsGenTopRapidity1", 100, -5, 5, 100, -5, 5);
  TH2F * histoRecoVsGenTopRapidity2 = new TH2F("RecoVsGenTopRapidity2", "RecoVsGenTopRapidity2", 100, -5, 5, 100, -5, 5);
  TH2F * histoRecoVsGenTopMass1 = new TH2F("RecoVsGenTopMass1", "RecoVsGenTopMass1", 300, 0, 300, 200, 0, 200);
  TH2F * histoRecoVsGenTopMass2 = new TH2F("RecoVsGenTopMass2", "RecoVsGenTopMass2", 300, 0, 300, 200, 0, 200);
  TH1F * histoRecoMinusGenDivGenTopRapidity1 = new TH1F("RecoMinusGenDivGenTopRapidity1", "RecoMinusGenDivGenTopRapidity1", 100, -3, 3);
  TH1F * histoRecoMinusGenDivGenTopRapidity2 = new TH1F("RecoMinusGenDivGenTopRapidity2", "RecoMinusGenDivGenTopRapidity2", 100, -3, 3);
  TH1F * histoRecoMinusGenDivGenLeptonRapidity1 = new TH1F("RecoMinusGenDivGenLeptonRapidity1", "RecoMinusGenDivGenLeptonRapidity1", 100, -3, 3);
  TH1F * histoRecoMinusGenDivGenLeptonRapidity2 = new TH1F("RecoMinusGenDivGenLeptonRapidity2", "RecoMinusGenDivGenLeptonRapidity2", 100, -3, 3);
  TH1F * histoRecoMinusGenDivGenTopMass1 = new TH1F("RecoMinusGenDivGenTopMass1", "RecoMinusGenDivGenTopMass1", 100, -3, 3);
  TH1F * histoRecoMinusGenDivGenTopMass2 = new TH1F("RecoMinusGenDivGenTopMass2", "RecoMinusGenDivGenTopMass2", 100, -3, 3);

  TH2F * histoFineBinning_RecoVsGenDelta_y = new TH2F("FineBinning_RecoVsGenDelta_y", "FineBinning_RecoVsGenDelta_y", 400, -2, 2, 400, -2, 2); // Migration Matrix
  TH2F * histoRecoVsGenDelta_y = new TH2F("RecoVsGenDelta_y", "RecoVsGenDelta_y", 8, -2, 2, 16, -2, 2); // Migration Matrix
  TH1F * histoRecoMinusGenDivGenDelta_y = new TH1F("RecoMinusGenDivGenDelta_y", "RecoMinusGenDivGenDelta_y", 100, -3, 3);

  TH2F * histoRecoVsGenTTRapidity = new TH2F("RecoVsGenTTRapidity", "RecoVsGenTTRapidity", 500, -2.5, 2.5, 500, -2.5, 2.5);
  TH1F * histoRecoMinusGenDivGenTTRapidity = new TH1F("RecoMinusGenDivGenTTRapidity", "RecoMinusGenDivGenTTRapidity", 100, -3, 3);
  TH2F * histoRecoVsGenTTPt = new TH2F("RecoVsGenTTPt", "RecoVsGenTTPt", 250, 0, 250, 250, 0, 250);
  TH1F * histoRecoMinusGenDivGenTTPt = new TH1F("RecoMinusGenDivGenTTPt", "RecoMinusGenDivGenTTPt", 100, -3, 3);
  TH2F * histoRecoVsGenTTMass = new TH2F("RecoVsGenTTMass", "RecoVsGenTTMass", 100, 0, 1000, 100, 0, 1000);
  TH1F * histoRecoMinusGenDivGenTTMass = new TH1F("RecoMinusGenDivGenTTMass", "RecoMinusGenDivGenTTMass", 100, -3, 3);

  TH1F * histoDelta_yEfficiencyN = new TH1F("Delta_yEfficiencyN", "Delta_yEfficiencyN", 10, -2, 2);
  TH1F * histoDelta_yEfficiencyD = new TH1F("Delta_yEfficiencyD", "Delta_yEfficiencyD", 10, -2, 2);
  TH1F * histoDelta_yEfficiency = new TH1F("Delta_yEfficiency", "Delta_yEfficiency", 10, -2, 2);

  TH2F * histoDelta_yVsTTRapidityEfficiency = new TH2F("Delta_yVsTTRapidityEfficiency", "Delta_yVsTTRapidityEfficiency", 10, -2, 2, 5, -2.5, 2.5);
  TH2F * histoDelta_yVsTTPtEfficiency = new TH2F("Delta_yVsTTPtEfficiency", "Delta_yVsTTPtEfficiency", 10, -2, 2, 5, 0, 250);
  TH2F * histoDelta_yVsTTMassEfficiency = new TH2F("Delta_yVsTTMassEfficiency", "Delta_yVsTTMassEfficiency", 10, -2, 2, 5, 0, 1000);
  // Fine binning
  TH1F * histoFineBinning_Delta_yEfficiencyN = new TH1F("FineBinning_Delta_yEfficiencyN", "FineBinning_Delta_yEfficiencyN", 200, -2, 2);
  TH1F * histoFineBinning_Delta_yEfficiencyD = new TH1F("FineBinning_Delta_yEfficiencyD", "FineBinning_Delta_yEfficiencyD", 200, -2, 2);
  TH1F * histoFineBinning_Delta_yEfficiency = new TH1F("FineBinning_Delta_yEfficiency", "FineBinning_Delta_yEfficiency", 200, -2, 2);

  TH2F * histoFineBinning_Delta_yVsTTRapidityEfficiency = new TH2F("FineBinning_Delta_yVsTTRapidityEfficiency", "FineBinning_Delta_yVsTTRapidityEfficiency", 200, -2, 2, 500, -2.5, 2.5);
  TH2F * histoFineBinning_Delta_yVsTTPtEfficiency = new TH2F("FineBinning_Delta_yVsTTPtEfficiency", "FineBinning_Delta_yVsTTPtEfficiency", 200, -2, 2, 250, 0, 250);
  TH2F * histoFineBinning_Delta_yVsTTMassEfficiency = new TH2F("FineBinning_Delta_yVsTTMassEfficiency", "FineBinning_Delta_yVsTTMassEfficiency", 200, -2, 2, 100, 0, 1000);




  vector < Dataset > datasets;
  DiLeptonSelection sel;
  float Luminosity = 0;
  // 0: MC - 1: Data - 2 Data & MC
  int DataType = 0;
  int verbosity = -1;
  
  // Analysis variables
  int step;
  //4-vectors
  vector < TLorentzVector > nu1;
  vector < TLorentzVector > nu2;
  //  TLorentzVector lvTop1_aux;
  //TLorentzVector lvTop2_aux;

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

  //////////////////////
  // Initialisation
  //////////////////////
  AnalysisEnvironmentLoader anaEL (xmlFileName);
  anaEL.LoadSamples (datasets); // now the list of datasets written in the xml file is known
  anaEL.LoadDiLeptonSelection (sel); // now the parameters for the selection are given to the selection
  anaEL.LoadGeneralInfo(DataType, Luminosity, verbosity );

  float weight_MC; 
  int nEvents;
  int firstEvent;
  int initialEvents;
  anaEL.LoadAnalysisInfo("Run", "firstEvent", firstEvent);
  anaEL.LoadAnalysisInfo("Run", "nEvents", nEvents);
  anaEL.LoadAnalysisInfo("Run", "initialEvents", initialEvents);
  string channelName;
  anaEL.LoadAnalysisInfo("MassAnalysis", "ChannelName", channelName);

  anaEL.LoadWeight (sel); // now the parameters for SFBweight are initialized (for b-tag!)

  //******************************************
  //Load Scale Factors for lepton efficiencies
  //******************************************
  sel.LoadElScaleFactors();
  sel.LoadMuScaleFactors();
  sel.InitJESUnc();

  bool nonskimmed = false;

  TopTree::NTEvent * event = 0;

  TFile * TupleFile = new TFile("TupleFileSkimmed_TTbarSemileptonicPowheg.root","RECREATE");
  float mttbar_rec, mttbar_gen;
  float diffysquare_rec, diffysquare_gen;
  float diffabseta_rec, diffabseta_gen;
  float weight;
  float pt_ttbar, pt_ttbar_gen;
  float pz_ttbar, pz_ttbar_gen;
  float eta_ttbar_rec, eta_ttbar_gen;
  float y_ttbar_rec, y_ttbar_gen;
  float diffabsy_rec, diffabsy_gen;

  TTree *tree = new TTree("Tuple","Tuple");
  tree->Branch("mttbar_rec",&mttbar_rec,"mttbar_rec/F");
  tree->Branch("mttbar_gen",&mttbar_gen,"mttbar_gen/F");
  tree->Branch("diffysquare_rec",&diffysquare_rec,"diffysquare_rec/F");
  tree->Branch("diffysquare_gen",&diffysquare_gen,"diffysquare_gen/F");
  tree->Branch("diffabseta_rec",&diffabseta_rec,"diffabseta_rec/F");
  tree->Branch("diffabseta_gen",&diffabseta_gen,"diffabseta_gen/F");
  tree->Branch("weight",&weight,"weight/F");
  tree->Branch("pt_ttbar",&pt_ttbar,"pt_ttbar/F");
  tree->Branch("pt_ttbar_gen",&pt_ttbar_gen,"pt_ttbar_gen/F");
  tree->Branch("pz_ttbar",&pz_ttbar,"pz_ttbar/F");
  tree->Branch("pz_ttbar_gen",&pz_ttbar_gen,"pz_ttbar_gen/F");
  tree->Branch("eta_ttbar_rec",&eta_ttbar_rec,"eta_ttbar_rec/F");
  tree->Branch("eta_ttbar_gen",&eta_ttbar_gen,"eta_ttbar_gen/F");
  tree->Branch("y_ttbar_rec",&y_ttbar_rec,"y_ttbar_rec/F");
  tree->Branch("y_ttbar_gen",&y_ttbar_gen,"y_ttbar_gen/F");
  tree->Branch("diffabsy_rec",&diffabsy_rec,"diffabsy_rec/F");
  tree->Branch("diffabsy_gen",&diffabsy_gen,"diffabsy_gen/F");

  //////////////////////
  //LOOP OVER THE DATASETS
  //////////////////////
  if(verbosity>0) {
    cout<<"#########################"<<endl;
    cout<<" Loop over the datasets  "<<endl;
    cout<<"#########################"<<endl;
  }

  float num_mttbar_eff = 0.;
  float den_mttbar_eff = 0.;

  for (unsigned int d = 0; d < datasets.size (); d++) {

    weight_MC = datasets[d].NormFactor()*Luminosity;

    if(datasets[d].isData() == true) weight_MC = 1.; cout << "isDATA" << endl;

    AMWT amwt(anaEL, datasets[d].isData());

    TString sample_name(datasets[d].Name());

    bool isData = datasets[d].isData ();
    datasets[d].eventTree ()->SetBranchAddress ("NTEvent",&event);

    cout << "Sample : " << sample_name<< endl;
    cout << "Data   : " << isData<< endl;

    unsigned int nEventsSample = (int) (datasets[d].eventTree ()->GetEntries ());
    unsigned int endEventToRun;

    if (firstEvent>nEventsSample) firstEvent = nEventsSample;
    if ((nEvents==-1)||((nEvents+firstEvent)>nEventsSample)) endEventToRun = nEventsSample;
    else endEventToRun = nEvents+firstEvent;
    cout << "Events to run: number / first / last / all: " << endEventToRun-firstEvent 
         << " / " << firstEvent << " / " << endEventToRun
         << " / " << nEventsSample << endl;

// Standard parameters for doFullSelection:

    bool applyEEScale = false; float EEScaleParam = 1.; bool applyEEResol = false; float EEResolParam = 1.;
    bool applyMEScale = false; float MEScaleParam = 1.; bool applyMEResol = false; float MEResolParam = 1.;
    bool applyMETS = false; float METScale = 1.;
    bool applyJES = false; float JESParam = 1.;
    bool applyJER = false; float JERFactor = 0.; 

    //////////////////////
    //LOOP OVER THE EVENTS
    //////////////////////

    float N_plus_reco = 0;
    float N_minus_reco = 0;

    float N_plus_gen = 0;
    float N_minus_gen = 0;

    mttbar_rec = 0;
    mttbar_gen = 0;
    diffysquare_rec = 0;
    diffysquare_gen = 0;
    diffabseta_rec = 0;
    diffabseta_gen = 0;
    weight = weight_MC;
    pt_ttbar = 0;
    pt_ttbar_gen = 0;
    pz_ttbar = 0;
    pz_ttbar_gen = 0;
    eta_ttbar_rec = 0;
    eta_ttbar_gen = 0;
    y_ttbar_rec = 0;
    y_ttbar_gen = 0;
    diffabsy_rec = 0;
    diffabsy_gen = 0;

    for (unsigned int ievt = firstEvent; ievt < endEventToRun; ievt++) {
//           for (unsigned int ievt = 0; ievt < 10; ievt++) {

      datasets[d].eventTree ()->GetEntry (ievt);

      if(ievt%1000 == 0) cout << "number of processed events " << ievt << endl;
      if (verbosity >= 1) cout << "Event : "<< event->runNb<<" , " << event->lumiblock <<" , " << event->eventNb<<endl;

      if(!(event->TMEME == 10010 || event->TMEME == 10001 || event->TMEME == 1 || event->TMEME == 10 || event->TMEME == 10000 || event->TMEME == 11000 || event->TMEME == 10100 )) continue;

      string candType;
      vector<NTElectron> candElec;
      vector<NTMuon> candMuon;


      //Load event for the selection
      sel.LoadEvent(event);

      int finalCut = sel.doFullSelection(&(datasets[d]), channelName, false, /*print*/ verbosity,
	false, false, -1., -1., applyJES,  JESParam,
	 applyEEScale,  EEScaleParam,  applyEEResol,  EEResolParam,
	 applyMEScale,  MEScaleParam,  
	 applyJER,  JERFactor,  applyMETS,  METScale);




        TLorentzVector lvTop1_gen;
        TLorentzVector lvTop2_gen;
        TLorentzVector lvTop1plusTop2_gen;
        float yt_gen = 0.;
        float ytbar_gen = 0.;
        float Delta_y_gen = 0.;

        if(datasets[d].Name() == "TTJets_Sig"){


        lvTop1_gen = (event->topAndDecays)[0].p4_t_gen;
        lvTop2_gen = (event->topAndDecays)[1].p4_t_gen;
        lvTop1plusTop2_gen = lvTop1_gen + lvTop2_gen;

        /////////////////////////
        //// GENERATOR LEVEL ////
        /////////////////////////

        histoGenTopRapidity1->Fill(lvTop1_gen.Rapidity());
        histoGenTopRapidity2->Fill(lvTop2_gen.Rapidity());
        histoGenTopMass1->Fill(lvTop1_gen.M());
        histoGenTopMass2->Fill(lvTop2_gen.M());
        histoGenTopMass1VsTopMass2->Fill(lvTop1_gen.M(),lvTop2_gen.M());

        yt_gen = lvTop1_gen.Rapidity();
        if(yt_gen<0.) yt_gen = (-1)*yt_gen;
        ytbar_gen = lvTop2_gen.Rapidity();
        if(ytbar_gen<0.) ytbar_gen = (-1)*ytbar_gen;
        Delta_y_gen = yt_gen - ytbar_gen;
	//        cout << "Delta_y_gen:" << Delta_y_gen << endl;
        histoGenDelta_y->Fill(Delta_y_gen);
        histoDelta_yEfficiencyD->Fill(Delta_y_gen);
        histoFineBinning_Delta_yEfficiencyD->Fill(Delta_y_gen);

        if(Delta_y_gen>0.){
          N_plus_gen++;
          histoGenN_plusTTRapidity->Fill(lvTop1plusTop2_gen.Rapidity());
          histoGenN_plusTTPt->Fill(lvTop1plusTop2_gen.Perp());
          histoGenN_plusTTMass->Fill(lvTop1plusTop2_gen.M());
          histoFineBinning_GenN_plusTTRapidity->Fill(lvTop1plusTop2_gen.Rapidity());
          histoFineBinning_GenN_plusTTPt->Fill(lvTop1plusTop2_gen.Perp());
          histoFineBinning_GenN_plusTTMass->Fill(lvTop1plusTop2_gen.M());
	}

        if(Delta_y_gen<0.){
          N_minus_gen++;
          histoGenN_minusTTRapidity->Fill(lvTop1plusTop2_gen.Rapidity());
          histoGenN_minusTTPt->Fill(lvTop1plusTop2_gen.Perp());
          histoGenN_minusTTMass->Fill(lvTop1plusTop2_gen.M());
          histoFineBinning_GenN_minusTTRapidity->Fill(lvTop1plusTop2_gen.Rapidity());
          histoFineBinning_GenN_minusTTPt->Fill(lvTop1plusTop2_gen.Perp());
          histoFineBinning_GenN_minusTTMass->Fill(lvTop1plusTop2_gen.M());

	}

        histoGenTTRapidity->Fill(lvTop1plusTop2_gen.Rapidity());
        histoGenTTPt->Fill(lvTop1plusTop2_gen.Perp());
        histoGenTTMass->Fill(lvTop1plusTop2_gen.M());
        histoGenDelta_yVsTTRapidity->Fill(Delta_y_gen, lvTop1plusTop2_gen.Rapidity());
        histoGenDelta_yVsTTPt->Fill(Delta_y_gen, lvTop1plusTop2_gen.Perp());
        histoGenDelta_yVsTTMass->Fill(Delta_y_gen, lvTop1plusTop2_gen.M());

        histoFineBinning_GenDelta_yVsTTRapidity->Fill(Delta_y_gen, lvTop1plusTop2_gen.Rapidity());
        histoFineBinning_GenDelta_yVsTTPt->Fill(Delta_y_gen, lvTop1plusTop2_gen.Perp());
        histoFineBinning_GenDelta_yVsTTMass->Fill(Delta_y_gen, lvTop1plusTop2_gen.M());


        if(nonskimmed == true){
         mttbar_gen = lvTop1plusTop2_gen.M();
         diffysquare_gen = yt_gen*yt_gen - ytbar_gen*ytbar_gen;
         diffabseta_gen = fabs(lvTop1_gen.Eta()) - fabs(lvTop2_gen.Eta());
         pt_ttbar_gen = lvTop1plusTop2_gen.Perp();
         pz_ttbar_gen = lvTop1plusTop2_gen.Pz();
         eta_ttbar_gen = lvTop1plusTop2_gen.Eta();
         y_ttbar_gen = lvTop1plusTop2_gen.Rapidity();
         diffabsy_gen = fabs(lvTop1_gen.Rapidity()) - fabs(lvTop2_gen.Rapidity());
	}

	}

      if (finalCut >6) {

        if(nonskimmed == false){
         if(datasets[d].Name() == "TTJets_Sig"){
         mttbar_gen = lvTop1plusTop2_gen.M();
         diffysquare_gen = yt_gen*yt_gen - ytbar_gen*ytbar_gen;
         diffabseta_gen = fabs(lvTop1_gen.Eta()) - fabs(lvTop2_gen.Eta());
         pt_ttbar_gen = lvTop1plusTop2_gen.Perp();
         pz_ttbar_gen = lvTop1plusTop2_gen.Pz();
         eta_ttbar_gen = lvTop1plusTop2_gen.Eta();
         y_ttbar_gen = lvTop1plusTop2_gen.Rapidity();
         diffabsy_gen = fabs(lvTop1_gen.Rapidity()) - fabs(lvTop2_gen.Rapidity());
	 }
	}

        sel.GetLeptonPair(candMuon, candElec, candType);

        for(unsigned int i=0; i<candMuon.size(); i++){
          if(candMuon[i].Charge == +1) histoRecoLeptonRapidity1->Fill(candMuon[i].p4.Rapidity());
          if(candMuon[i].Charge == -1) histoRecoLeptonRapidity2->Fill(candMuon[i].p4.Rapidity());
	}

        for(unsigned int j=0; j<candElec.size(); j++){
          if(candElec[j].Charge == +1) histoRecoLeptonRapidity1->Fill(candElec[j].p4.Rapidity());
          if(candElec[j].Charge == -1) histoRecoLeptonRapidity2->Fill(candElec[j].p4.Rapidity());
	}



        TLorentzVector lvTop1_reco;
        TLorentzVector lvTop2_reco;
        TLorentzVector lvTop1plusTop2_reco;


        TopMassVariables * tmv = amwt.findMass(sel, lvTop1_reco, lvTop2_reco);
        lvTop1plusTop2_reco = lvTop1_reco + lvTop2_reco;



        ////////////////////
        /// RECO LEVEL /////
        ////////////////////

        histoRecoTopRapidity1->Fill(lvTop1_reco.Rapidity());
        histoRecoTopRapidity2->Fill(lvTop2_reco.Rapidity());
        histoRecoTopMass1->Fill(lvTop1_reco.M());
        histoRecoTopMass2->Fill(lvTop2_reco.M());
        histoRecoTopMass1VsTopMass2->Fill(lvTop1_reco.M(),lvTop2_reco.M());

        float yt_reco = lvTop1_reco.Rapidity();
        if(yt_reco<0.) yt_reco = (-1)*yt_reco;
        float ytbar_reco = lvTop2_reco.Rapidity();
        if(ytbar_reco<0.) ytbar_reco = (-1)*ytbar_reco;
        float Delta_y_reco = yt_reco - ytbar_reco;
	//        cout << "Delta_y_reco:" << Delta_y_reco << endl;
        histoRecoDelta_y->Fill(Delta_y_reco);
        histoDelta_yEfficiencyN->Fill(Delta_y_reco);
        histoFineBinning_Delta_yEfficiencyN->Fill(Delta_y_reco);

        if(Delta_y_reco>0.){
          N_plus_reco++;
          histoRecoN_plusTTRapidity->Fill(lvTop1plusTop2_reco.Rapidity());
          histoRecoN_plusTTPt->Fill(lvTop1plusTop2_reco.Perp());
          histoRecoN_plusTTMass->Fill(lvTop1plusTop2_reco.M());
          histoFineBinning_RecoN_plusTTRapidity->Fill(lvTop1plusTop2_reco.Rapidity());
          histoFineBinning_RecoN_plusTTPt->Fill(lvTop1plusTop2_reco.Perp());
          histoFineBinning_RecoN_plusTTMass->Fill(lvTop1plusTop2_reco.M());
	}

        if(Delta_y_reco<0.){
          N_minus_reco++;
          histoRecoN_minusTTRapidity->Fill(lvTop1plusTop2_reco.Rapidity());
          histoRecoN_minusTTPt->Fill(lvTop1plusTop2_reco.Perp());
          histoRecoN_minusTTMass->Fill(lvTop1plusTop2_reco.M());
          histoFineBinning_RecoN_minusTTRapidity->Fill(lvTop1plusTop2_reco.Rapidity());
          histoFineBinning_RecoN_minusTTPt->Fill(lvTop1plusTop2_reco.Perp());
          histoFineBinning_RecoN_minusTTMass->Fill(lvTop1plusTop2_reco.M());
	}

        histoRecoTTRapidity->Fill(lvTop1plusTop2_reco.Rapidity());
        histoRecoTTPt->Fill(lvTop1plusTop2_reco.Perp());
        histoRecoTTMass->Fill(lvTop1plusTop2_reco.M());
        histoRecoDelta_yVsTTRapidity->Fill(Delta_y_reco, lvTop1plusTop2_reco.Rapidity());
        histoRecoDelta_yVsTTPt->Fill(Delta_y_reco, lvTop1plusTop2_reco.Perp());
        histoRecoDelta_yVsTTMass->Fill(Delta_y_reco, lvTop1plusTop2_reco.M());

        histoFineBinning_RecoDelta_yVsTTRapidity->Fill(Delta_y_reco, lvTop1plusTop2_reco.Rapidity());
        histoFineBinning_RecoDelta_yVsTTPt->Fill(Delta_y_reco, lvTop1plusTop2_reco.Perp());
        histoFineBinning_RecoDelta_yVsTTMass->Fill(Delta_y_reco, lvTop1plusTop2_reco.M());

        if(nonskimmed == false){

         mttbar_rec = lvTop1plusTop2_reco.M();
         diffysquare_rec = yt_reco*yt_reco - ytbar_reco*ytbar_reco;
         diffabseta_rec = fabs(lvTop1_reco.Eta()) - fabs(lvTop2_reco.Eta());
         pt_ttbar = lvTop1plusTop2_reco.Perp();
         pz_ttbar = lvTop1plusTop2_reco.Pz();
         eta_ttbar_rec = lvTop1plusTop2_reco.Eta();
         y_ttbar_rec = lvTop1plusTop2_reco.Rapidity();
         diffabsy_rec = fabs(lvTop1_reco.Rapidity()) - fabs(lvTop2_reco.Rapidity());

	}

        ////////////////////////
        // RECO VS GEN LEVEL ///
        ////////////////////////
        if(datasets[d].Name() == "TTJets_Sig"){
 
        histoRecoVsGenTopRapidity1->Fill(lvTop1_reco.Rapidity(), lvTop1_gen.Rapidity());
        histoRecoVsGenTopRapidity2->Fill(lvTop2_reco.Rapidity(), lvTop2_gen.Rapidity());
        histoRecoVsGenTopMass1->Fill(lvTop1_reco.M(), lvTop1_gen.M());
        histoRecoVsGenTopMass2->Fill(lvTop2_reco.M(), lvTop2_gen.M());
	histoRecoMinusGenDivGenTopRapidity1->Fill((lvTop1_reco.Rapidity() - lvTop1_gen.Rapidity())/lvTop1_gen.Rapidity());
        histoRecoMinusGenDivGenTopRapidity2->Fill((lvTop2_reco.Rapidity() - lvTop2_gen.Rapidity())/lvTop2_gen.Rapidity());

        for(unsigned int i=0; i<candMuon.size(); i++){
          if(candMuon[i].Charge == +1) histoRecoMinusGenDivGenLeptonRapidity1->Fill((candMuon[i].p4.Rapidity() - lvTop1_gen.Rapidity())/lvTop1_gen.Rapidity());
          if(candMuon[i].Charge == -1) histoRecoMinusGenDivGenLeptonRapidity2->Fill((candMuon[i].p4.Rapidity() - lvTop2_gen.Rapidity())/lvTop2_gen.Rapidity());
	}

        for(unsigned int j=0; j<candElec.size(); j++){
          if(candElec[j].Charge == +1) histoRecoMinusGenDivGenLeptonRapidity1->Fill((candElec[j].p4.Rapidity() - lvTop1_gen.Rapidity())/lvTop1_gen.Rapidity());
          if(candElec[j].Charge == -1) histoRecoMinusGenDivGenLeptonRapidity2->Fill((candElec[j].p4.Rapidity() - lvTop2_gen.Rapidity())/lvTop2_gen.Rapidity());
	}

	histoRecoMinusGenDivGenTopMass1->Fill((lvTop1_reco.M() - lvTop1_gen.M())/lvTop1_gen.M());
        histoRecoMinusGenDivGenTopMass2->Fill((lvTop2_reco.M() - lvTop2_gen.M())/lvTop2_gen.M());

        histoRecoVsGenDelta_y->Fill(Delta_y_reco, Delta_y_gen);
        histoFineBinning_RecoVsGenDelta_y->Fill(Delta_y_reco, Delta_y_gen);
        histoRecoMinusGenDivGenDelta_y->Fill((Delta_y_reco - Delta_y_gen)/Delta_y_gen);

        histoRecoVsGenTTRapidity->Fill(lvTop1plusTop2_reco.Rapidity(),lvTop1plusTop2_gen.Rapidity());
        histoRecoMinusGenDivGenTTRapidity->Fill((lvTop1plusTop2_reco.Rapidity() - lvTop1plusTop2_gen.Rapidity())/lvTop1plusTop2_gen.Rapidity());
        histoRecoVsGenTTPt->Fill(lvTop1plusTop2_reco.Perp(),lvTop1plusTop2_gen.Perp());
        histoRecoMinusGenDivGenTTPt->Fill((lvTop1plusTop2_reco.Perp() - lvTop1plusTop2_gen.Perp())/lvTop1plusTop2_gen.Perp());
        histoRecoVsGenTTMass->Fill(lvTop1plusTop2_reco.M(),lvTop1plusTop2_gen.M());
        histoRecoMinusGenDivGenTTMass->Fill((lvTop1plusTop2_reco.M() - lvTop1plusTop2_gen.M())/lvTop1plusTop2_gen.M());

	}

	//	tmv->printAll();
	delete tmv;
       if(nonskimmed == false && mttbar_rec > 60.){ tree->Fill(); num_mttbar_eff += weight_MC;}
       if(nonskimmed == false) den_mttbar_eff += weight_MC;
      }

      if(nonskimmed == true) tree->Fill();

    }  // end of loop over evts

    float A_C_reco = (N_plus_reco - N_minus_reco)/(N_plus_reco + N_minus_reco);
    float A_C_gen = (N_plus_gen - N_minus_gen)/(N_plus_gen + N_minus_gen);

    cout << "A_C_gen:" << A_C_gen << endl;
    cout << "A_C_reco:" << A_C_reco << endl;

    histoGenN_plusMinusN_minusTTRapidity->Add(histoGenN_plusTTRapidity);
    histoGenN_plusMinusN_minusTTRapidity->Add(histoGenN_minusTTRapidity,-1);
    histoGenN_plusPlusN_minusTTRapidity->Add(histoGenN_plusTTRapidity);
    histoGenN_plusPlusN_minusTTRapidity->Add(histoGenN_minusTTRapidity);

    histoGenA_cTTRapidity->Divide(histoGenN_plusMinusN_minusTTRapidity, histoGenN_plusPlusN_minusTTRapidity);

    histoGenN_plusMinusN_minusTTPt->Add(histoGenN_plusTTPt);
    histoGenN_plusMinusN_minusTTPt->Add(histoGenN_minusTTPt,-1);
    histoGenN_plusPlusN_minusTTPt->Add(histoGenN_plusTTPt);
    histoGenN_plusPlusN_minusTTPt->Add(histoGenN_minusTTPt);

    histoGenA_cTTPt->Divide(histoGenN_plusMinusN_minusTTPt, histoGenN_plusPlusN_minusTTPt);

    histoGenN_plusMinusN_minusTTMass->Add(histoGenN_plusTTMass);
    histoGenN_plusMinusN_minusTTMass->Add(histoGenN_minusTTMass,-1);
    histoGenN_plusPlusN_minusTTMass->Add(histoGenN_plusTTMass);
    histoGenN_plusPlusN_minusTTMass->Add(histoGenN_minusTTMass);

    histoGenA_cTTMass->Divide(histoGenN_plusMinusN_minusTTMass, histoGenN_plusPlusN_minusTTMass);

    histoRecoN_plusMinusN_minusTTRapidity->Add(histoRecoN_plusTTRapidity);
    histoRecoN_plusMinusN_minusTTRapidity->Add(histoRecoN_minusTTRapidity,-1);
    histoRecoN_plusPlusN_minusTTRapidity->Add(histoRecoN_plusTTRapidity);
    histoRecoN_plusPlusN_minusTTRapidity->Add(histoRecoN_minusTTRapidity);

    histoRecoA_cTTRapidity->Divide(histoRecoN_plusMinusN_minusTTRapidity, histoRecoN_plusPlusN_minusTTRapidity);

    histoRecoN_plusMinusN_minusTTPt->Add(histoRecoN_plusTTPt);
    histoRecoN_plusMinusN_minusTTPt->Add(histoRecoN_minusTTPt,-1);
    histoRecoN_plusPlusN_minusTTPt->Add(histoRecoN_plusTTPt);
    histoRecoN_plusPlusN_minusTTPt->Add(histoRecoN_minusTTPt);

    histoRecoA_cTTPt->Divide(histoRecoN_plusMinusN_minusTTPt, histoRecoN_plusPlusN_minusTTPt);

    histoRecoN_plusMinusN_minusTTMass->Add(histoRecoN_plusTTMass);
    histoRecoN_plusMinusN_minusTTMass->Add(histoRecoN_minusTTMass,-1);
    histoRecoN_plusPlusN_minusTTMass->Add(histoRecoN_plusTTMass);
    histoRecoN_plusPlusN_minusTTMass->Add(histoRecoN_minusTTMass);

    histoRecoA_cTTMass->Divide(histoRecoN_plusMinusN_minusTTMass, histoRecoN_plusPlusN_minusTTMass);





    histoFineBinning_GenN_plusMinusN_minusTTRapidity->Add(histoFineBinning_GenN_plusTTRapidity);
    histoFineBinning_GenN_plusMinusN_minusTTRapidity->Add(histoFineBinning_GenN_minusTTRapidity,-1);
    histoFineBinning_GenN_plusPlusN_minusTTRapidity->Add(histoFineBinning_GenN_plusTTRapidity);
    histoFineBinning_GenN_plusPlusN_minusTTRapidity->Add(histoFineBinning_GenN_minusTTRapidity);

    histoFineBinning_GenA_cTTRapidity->Divide(histoFineBinning_GenN_plusMinusN_minusTTRapidity, histoFineBinning_GenN_plusPlusN_minusTTRapidity);

    histoFineBinning_GenN_plusMinusN_minusTTPt->Add(histoFineBinning_GenN_plusTTPt);
    histoFineBinning_GenN_plusMinusN_minusTTPt->Add(histoFineBinning_GenN_minusTTPt,-1);
    histoFineBinning_GenN_plusPlusN_minusTTPt->Add(histoFineBinning_GenN_plusTTPt);
    histoFineBinning_GenN_plusPlusN_minusTTPt->Add(histoFineBinning_GenN_minusTTPt);

    histoFineBinning_GenA_cTTPt->Divide(histoFineBinning_GenN_plusMinusN_minusTTPt, histoFineBinning_GenN_plusPlusN_minusTTPt);

    histoFineBinning_GenN_plusMinusN_minusTTMass->Add(histoFineBinning_GenN_plusTTMass);
    histoFineBinning_GenN_plusMinusN_minusTTMass->Add(histoFineBinning_GenN_minusTTMass,-1);
    histoFineBinning_GenN_plusPlusN_minusTTMass->Add(histoFineBinning_GenN_plusTTMass);
    histoFineBinning_GenN_plusPlusN_minusTTMass->Add(histoFineBinning_GenN_minusTTMass);

    histoFineBinning_GenA_cTTMass->Divide(histoFineBinning_GenN_plusMinusN_minusTTMass, histoFineBinning_GenN_plusPlusN_minusTTMass);

    histoFineBinning_RecoN_plusMinusN_minusTTRapidity->Add(histoFineBinning_RecoN_plusTTRapidity);
    histoFineBinning_RecoN_plusMinusN_minusTTRapidity->Add(histoFineBinning_RecoN_minusTTRapidity,-1);
    histoFineBinning_RecoN_plusPlusN_minusTTRapidity->Add(histoFineBinning_RecoN_plusTTRapidity);
    histoFineBinning_RecoN_plusPlusN_minusTTRapidity->Add(histoFineBinning_RecoN_minusTTRapidity);

    histoFineBinning_RecoA_cTTRapidity->Divide(histoFineBinning_RecoN_plusMinusN_minusTTRapidity, histoFineBinning_RecoN_plusPlusN_minusTTRapidity);

    histoFineBinning_RecoN_plusMinusN_minusTTPt->Add(histoFineBinning_RecoN_plusTTPt);
    histoFineBinning_RecoN_plusMinusN_minusTTPt->Add(histoFineBinning_RecoN_minusTTPt,-1);
    histoFineBinning_RecoN_plusPlusN_minusTTPt->Add(histoFineBinning_RecoN_plusTTPt);
    histoFineBinning_RecoN_plusPlusN_minusTTPt->Add(histoFineBinning_RecoN_minusTTPt);

    histoFineBinning_RecoA_cTTPt->Divide(histoFineBinning_RecoN_plusMinusN_minusTTPt, histoFineBinning_RecoN_plusPlusN_minusTTPt);

    histoFineBinning_RecoN_plusMinusN_minusTTMass->Add(histoFineBinning_RecoN_plusTTMass);
    histoFineBinning_RecoN_plusMinusN_minusTTMass->Add(histoFineBinning_RecoN_minusTTMass,-1);
    histoFineBinning_RecoN_plusPlusN_minusTTMass->Add(histoFineBinning_RecoN_plusTTMass);
    histoFineBinning_RecoN_plusPlusN_minusTTMass->Add(histoFineBinning_RecoN_minusTTMass);

    histoFineBinning_RecoA_cTTMass->Divide(histoFineBinning_RecoN_plusMinusN_minusTTMass, histoFineBinning_RecoN_plusPlusN_minusTTMass);



    histoDelta_yEfficiency->Divide(histoDelta_yEfficiencyN, histoDelta_yEfficiencyD);
    histoFineBinning_Delta_yEfficiency->Divide(histoFineBinning_Delta_yEfficiencyN, histoFineBinning_Delta_yEfficiencyD);


    for (unsigned int bin_index1 = 1; bin_index1 < 11; bin_index1++) {
     for (unsigned int bin_index2 = 1; bin_index2 < 6; bin_index2++) {
       float value = histoRecoDelta_yVsTTRapidity->GetBinContent(bin_index1,bin_index2)/histoGenDelta_yVsTTRapidity->GetBinContent(bin_index1,bin_index2);
       histoDelta_yVsTTRapidityEfficiency->SetBinContent(bin_index1, bin_index2, value);
       float value_fb = histoFineBinning_RecoDelta_yVsTTRapidity->GetBinContent(bin_index1,bin_index2)/histoFineBinning_GenDelta_yVsTTRapidity->GetBinContent(bin_index1,bin_index2);
       histoFineBinning_Delta_yVsTTRapidityEfficiency->SetBinContent(bin_index1, bin_index2, value_fb);

     }
    }

    for (unsigned int bin_index1 = 1; bin_index1 < 11; bin_index1++) {
     for (unsigned int bin_index2 = 1; bin_index2 < 6; bin_index2++) {
       float value = histoRecoDelta_yVsTTPt->GetBinContent(bin_index1,bin_index2)/histoGenDelta_yVsTTPt->GetBinContent(bin_index1,bin_index2);
       histoDelta_yVsTTPtEfficiency->SetBinContent(bin_index1, bin_index2, value);
       float value_fb = histoFineBinning_RecoDelta_yVsTTPt->GetBinContent(bin_index1,bin_index2)/histoFineBinning_GenDelta_yVsTTPt->GetBinContent(bin_index1,bin_index2);
       histoFineBinning_Delta_yVsTTPtEfficiency->SetBinContent(bin_index1, bin_index2, value_fb);

     }
    }


    for (unsigned int bin_index1 = 1; bin_index1 < 11; bin_index1++) {
     for (unsigned int bin_index2 = 1; bin_index2 < 6; bin_index2++) {
       float value = histoRecoDelta_yVsTTMass->GetBinContent(bin_index1,bin_index2)/histoGenDelta_yVsTTMass->GetBinContent(bin_index1,bin_index2);
       histoDelta_yVsTTMassEfficiency->SetBinContent(bin_index1, bin_index2, value);
       float value_fb = histoFineBinning_RecoDelta_yVsTTPt->GetBinContent(bin_index1,bin_index2)/histoFineBinning_GenDelta_yVsTTPt->GetBinContent(bin_index1,bin_index2);
       histoFineBinning_Delta_yVsTTPtEfficiency->SetBinContent(bin_index1, bin_index2, value_fb);

     }
    }






  }				// end of loop over the datasets


//  if(verbosity>0) {
    cout<<"#########################"<<endl;
    cout<<"    End of the program   "<<endl;
    cout<<"#########################"<<endl;
//  }

    tree->Print();

    TupleFile->Write();
    TupleFile->Close();


    TFile * fileCA = new TFile("ChargeAsymmetryResults_Skimmed_TTbarSemileptonicPowheg.root","RECREATE");
    //  fileCA->cd();

    // GEN
    histoGenTopRapidity1->Write();
    histoGenTopRapidity2->Write();
    histoGenTopMass1->Write();
    histoGenTopMass2->Write();
    histoGenTopMass1VsTopMass2->Write();
    histoGenDelta_y->Write();
    histoGenTTRapidity->Write();
    histoGenTTPt->Write();
    histoGenTTMass->Write();
    histoGenDelta_yVsTTRapidity->Write();
    histoGenDelta_yVsTTPt->Write();
    histoGenDelta_yVsTTMass->Write();
    histoGenN_plusTTRapidity->Write();
    histoGenN_plusTTPt->Write();
    histoGenN_plusTTMass->Write();
    histoGenN_minusTTRapidity->Write();
    histoGenN_minusTTPt->Write();
    histoGenN_minusTTMass->Write();
    histoGenN_plusMinusN_minusTTRapidity->Write();
    histoGenN_plusPlusN_minusTTRapidity->Write();
    histoGenN_plusMinusN_minusTTPt->Write();
    histoGenN_plusPlusN_minusTTPt->Write();
    histoGenN_plusMinusN_minusTTMass->Write();
    histoGenN_plusPlusN_minusTTMass->Write();
    histoGenA_cTTRapidity->Write();
    histoGenA_cTTPt->Write();
    histoGenA_cTTMass->Write();
    histoFineBinning_GenDelta_yVsTTRapidity->Write();
    histoFineBinning_GenDelta_yVsTTPt->Write();
    histoFineBinning_GenDelta_yVsTTMass->Write();
    histoFineBinning_GenN_plusTTRapidity->Write();
    histoFineBinning_GenN_plusTTPt->Write();
    histoFineBinning_GenN_plusTTMass->Write();
    histoFineBinning_GenN_minusTTRapidity->Write();
    histoFineBinning_GenN_minusTTPt->Write();
    histoFineBinning_GenN_minusTTMass->Write();
    histoFineBinning_GenN_plusMinusN_minusTTRapidity->Write();
    histoFineBinning_GenN_plusPlusN_minusTTRapidity->Write();
    histoFineBinning_GenN_plusMinusN_minusTTPt->Write();
    histoFineBinning_GenN_plusPlusN_minusTTPt->Write();
    histoFineBinning_GenN_plusMinusN_minusTTMass->Write();
    histoFineBinning_GenN_plusPlusN_minusTTMass->Write();
    histoFineBinning_GenA_cTTRapidity->Write();
    histoFineBinning_GenA_cTTPt->Write();
    histoFineBinning_GenA_cTTMass->Write(); 



    // RECO
    histoRecoTopRapidity1->Write();
    histoRecoTopRapidity2->Write();
    histoRecoLeptonRapidity1->Write();
    histoRecoLeptonRapidity2->Write();
    histoRecoTopMass1->Write();
    histoRecoTopMass2->Write();
    histoRecoTopMass1VsTopMass2->Write();
    histoRecoDelta_y->Write();
    histoRecoTTRapidity->Write();
    histoRecoTTPt->Write();
    histoRecoTTMass->Write();
    histoRecoDelta_yVsTTRapidity->Write();
    histoRecoDelta_yVsTTPt->Write();
    histoRecoDelta_yVsTTMass->Write();
    histoRecoN_plusTTRapidity->Write();
    histoRecoN_plusTTPt->Write();
    histoRecoN_plusTTMass->Write();
    histoRecoN_minusTTRapidity->Write();
    histoRecoN_minusTTPt->Write();
    histoRecoN_minusTTMass->Write();
    histoRecoN_plusMinusN_minusTTRapidity->Write();
    histoRecoN_plusPlusN_minusTTRapidity->Write();
    histoRecoN_plusMinusN_minusTTPt->Write();
    histoRecoN_plusPlusN_minusTTPt->Write();
    histoRecoN_plusMinusN_minusTTMass->Write();
    histoRecoN_plusPlusN_minusTTMass->Write();
    histoRecoA_cTTRapidity->Write();
    histoRecoA_cTTPt->Write();
    histoRecoA_cTTMass->Write();
    histoFineBinning_RecoDelta_yVsTTRapidity->Write();
    histoFineBinning_RecoDelta_yVsTTPt->Write();
    histoFineBinning_RecoDelta_yVsTTMass->Write();
    histoFineBinning_RecoN_plusTTRapidity->Write();
    histoFineBinning_RecoN_plusTTPt->Write();
    histoFineBinning_RecoN_plusTTMass->Write();
    histoFineBinning_RecoN_minusTTRapidity->Write();
    histoFineBinning_RecoN_minusTTPt->Write();
    histoFineBinning_RecoN_minusTTMass->Write();
    histoFineBinning_RecoN_plusMinusN_minusTTRapidity->Write();
    histoFineBinning_RecoN_plusPlusN_minusTTRapidity->Write();
    histoFineBinning_RecoN_plusMinusN_minusTTPt->Write();
    histoFineBinning_RecoN_plusPlusN_minusTTPt->Write();
    histoFineBinning_RecoN_plusMinusN_minusTTMass->Write();
    histoFineBinning_RecoN_plusPlusN_minusTTMass->Write();
    histoFineBinning_RecoA_cTTRapidity->Write();
    histoFineBinning_RecoA_cTTPt->Write();
    histoFineBinning_RecoA_cTTMass->Write(); 

    // RECO vs GEN
    histoRecoVsGenTopRapidity1->Write();
    histoRecoVsGenTopRapidity2->Write();
    histoRecoMinusGenDivGenLeptonRapidity1->Write();
    histoRecoMinusGenDivGenLeptonRapidity2->Write();
    histoRecoMinusGenDivGenTopRapidity1->Write();
    histoRecoMinusGenDivGenTopRapidity2->Write();
    histoRecoVsGenTopMass1->Write();
    histoRecoVsGenTopMass2->Write();
    histoRecoMinusGenDivGenTopMass1->Write();
    histoRecoMinusGenDivGenTopMass2->Write();
    histoRecoVsGenDelta_y->Write();
    histoFineBinning_RecoVsGenDelta_y->Write();
    histoRecoMinusGenDivGenDelta_y->Write();
    histoRecoVsGenTTRapidity->Write();
    histoRecoMinusGenDivGenTTRapidity->Write();
    histoRecoVsGenTTPt->Write();
    histoRecoMinusGenDivGenTTPt->Write();
    histoRecoVsGenTTMass->Write();
    histoRecoMinusGenDivGenTTMass->Write();
    histoDelta_yEfficiencyN->Write();
    histoDelta_yEfficiencyD->Write();
    histoDelta_yEfficiency->Write();
    histoDelta_yVsTTRapidityEfficiency->Write();
    histoDelta_yVsTTPtEfficiency->Write();
    histoDelta_yVsTTMassEfficiency->Write();
    histoFineBinning_Delta_yEfficiencyN->Write();
    histoFineBinning_Delta_yEfficiencyD->Write();
    histoFineBinning_Delta_yEfficiency->Write();
    histoFineBinning_Delta_yVsTTRapidityEfficiency->Write();
    histoFineBinning_Delta_yVsTTPtEfficiency->Write();
    histoFineBinning_Delta_yVsTTMassEfficiency->Write();


    //    fileCA->Write();
    fileCA->Close();
    delete fileCA;

    cout << "num_mttbar_eff = " <<  num_mttbar_eff << endl;
    cout << "den_mttbar_eff = " <<  den_mttbar_eff << endl;
    cout << "mttbar_eff = " <<  num_mttbar_eff / den_mttbar_eff << endl;

  return (0);
}
Exemple #3
0
int main (int argc, char *argv[])
{
 
  cout << "#########################" << endl;
  cout << "Beginning of the program" << endl;
  cout << "#########################" << endl;

  //////////////////////
  //Global variables
  //////////////////////
  vector < Dataset > datasets;
  SSDiLeptonSelection sel;
  float Luminosity = 0;
  float LumiError = 0.;
  // 0: MC - 1: Data - 2 Data & MC
  int DataType = 0;
  int verbosity = -1;

  int AnaStep = 6;//which defines the cuts that the events should pass to be considered as selected

  float Nobs_mumu = 0.;
  //////////////////////

  //////////////////////
  // Initialisation
  //////////////////////
  string xmlFileName;
  cout<<"argc "<<argc<<" "<<argv[0]<<endl;
  if (argc>1 ) xmlFileName = string(argv[1]);
  else xmlFileName = string ("../../config/RPVAnalysis.xml");
  AnalysisEnvironmentLoader anaEL (xmlFileName);
  anaEL.LoadSamples (datasets);	// now the list of datasets written in the xml file is known
  anaEL.LoadSSDiLeptonSelection (sel);	// now the parameters for the selection are given to the selection
  anaEL.LoadGeneralInfo (DataType, Luminosity, LumiError, verbosity);
  int flagOriginal=sel.GetFlagb();
  int methodOriginal=sel.GetMethodb();
  int systOriginal= sel.GetSystb();
  std::cout << " For btag : flag " << flagOriginal << ", method " << methodOriginal << ", syst " << systOriginal << std::endl;
  IPHCTree::NTEvent * event = 0;
  //Selection table
  SelectionTable selTable_allChannels (sel.GetCutList (), datasets, string ("*"));
  SelectionTable selTable_ee (sel.GetCutList (), datasets, string ("ee"));
  SelectionTable selTable_emu (sel.GetCutList (), datasets, string ("emu"));
  SelectionTable selTable_mumu (sel.GetCutList (), datasets, string ("mumu"));
  
  //Book keeping of standard histos
  bool doHistoManager = true;
  SSDiLepAnaHistoManager histoManager;
  if(doHistoManager){
  	histoManager.LoadDatasets (datasets);
  	histoManager.LoadSelectionSteps (sel.GetCutList ());
  	histoManager.LoadChannels (sel.GetChannelList ());
  	histoManager.CreateHistos ();
  }
  //////////////////////


  cout << "The verbosity mode is " << verbosity << endl;
  cout << "The luminosity is equal to " << Luminosity << endl;
  cout << "The DataType is ";
  switch (DataType) {
  case 0:
    cout << "MC" << endl;
    break;
  case 1:
    cout << "Data" << endl;
    break;
  case 2:
    cout << "Data & MC" << endl;
    break;
  default:
    cout << " unknown" << endl;
    break;
  }
  //////////////////////



  //////////////////////
  //LOOP OVER THE DATASETS
  //////////////////////
  if (verbosity > 0) {
    cout << "#########################" << endl;
    cout << " Loop over the datasets  " << endl;
    cout << "#########################" << endl;
  }

  for (unsigned int d = 0; d < datasets.size (); d++) 
  {

    if(verbosity>2) cout<<"RPVAnalysis> Dataset: "<<datasets[d].Name()<<endl;
    datasets[d].eventTree ()->SetBranchAddress ("NTEvent", &event);

    unsigned int nEvents = static_cast<unsigned int>(datasets[d].eventTree ()->GetEntries ());
    cout << "RPVAnalysis> NEvents = " << nEvents << endl;
    cout << "RPVAnalysis> NEvents to run over = "<<datasets[d].NofEvtsToRunOver()<<endl;


    //LOOP OVER THE EVENTS
    for (unsigned int ievt = 0; ievt < datasets[d].NofEvtsToRunOver(); ievt++)
    {
      float weight = 1.;
      if(datasets[d].isData() == false) weight = datasets[d].NormFactor()*Luminosity; //if Data , weight = 1
      //cout<<"weight "<<weight<<" "<<datasets[d].isData()<<endl;
      datasets[d].eventTree()->GetEntry(ievt);
      IPHCTree::NTTransient::InitializeAfterReading(event);

      if (verbosity > 3)
      {
        std::cout << "event " << ievt 
                  <<" - event number=" << event->general.eventNb
                  <<" - run number="   << event->general.runNb
                  << std::endl;
      }
      if (ievt % 1000 == 0)
	      cout << "RPVAnalysis> Progress bar : " << ievt << endl;

      //Load event for the selection
      sel.LoadEvent(event);

      //Collection of selected objects
      vector < NTElectron > selElectrons = sel.GetSelectedElectrons ();
      //vector < NTMuon > selMuons = sel.GetScaledMuons ();
      vector < NTMuon > selMuons = sel.GetSelectedMuons ();
      vector < NTJet > selJets = sel.GetSelectedJets ();
      NTMET met = sel.GetSelectedMET ();	// no criteria applyied

      //Candidate pair of lepton
      string CandType="false";		// ee - emu - mumum or false
      vector < NTElectron > candElec;
      vector < NTMuon > candMuon;
      sel.GetLeptonPair (candMuon, candElec, CandType);	// fill the variables

      //integer which define the last step of the selection that the event fullfill
      int selLastStep = 0;
      int step = 0;

      //////////////////////////////////   
      //   Fill the selection table
      //////////////////////////////////   
      step = sel.FillTable (selTable_ee, &(datasets[d]), d, weight);
      if (CandType=="ee") selLastStep = step;
      step = sel.FillTable (selTable_emu, &(datasets[d]), d, weight);
      if (CandType=="emu") selLastStep = step;
      step = sel.FillTable (selTable_mumu, &(datasets[d]), d, weight);
      if (CandType=="mumu") selLastStep = step;

      //CandType="mumu";
      //cout<<selMuons.size()<<endl;
      histoManager.Fill(sel, event, selMuons, selElectrons, selLastStep, sel.GetChannel(CandType), d, weight);
      if (CandType=="mumu" && selLastStep >= AnaStep)  Nobs_mumu+=weight;

      //     selLastStep = sel.FillTable(selTable_allChannels, &(datasets[d]), d, weight);


    }				// end of loop over evts


  }				// end of loop over the datasets 
  cout << "#########################" << endl;
  cout << " Loop over the datasets  " << endl;
  cout << "#########################" << endl;



  ////////////////////////////
  //  Computation after loops
  ////////////////////////////

  ////////////////////////////
  //  Histograms
  ////////////////////////////

  if(doHistoManager) histoManager.Compute ();


  if (verbosity > 0) {
    cout << "#########################" << endl;
    cout << " Fill the latex tables   " << endl;
    cout << "#########################" << endl;
  }

  string ofilename;
  if(argc>3) ofilename = argv[3];
  else ofilename = string("CrossSectionTable.tex"); 
  ofstream ofile (ofilename.c_str());
  ofile << "\\documentclass[8pt]{article}" << endl;
  ofile << "\\begin{document}" << endl;
//  ofile << "\\usepackage{geometry}" << endl;
//  ofile << "\\geometry{a4paper, textwidth=19cm, textheight=23cm}" << endl;

 //Merge channels consistently
  vector < string > mergenames;
  mergenames.push_back ("QCD1");
  mergenames.push_back ("QCD2");
  mergenames.push_back ("QCD3");
  mergenames.push_back ("QCD4");
  mergenames.push_back ("QCD5");
  mergenames.push_back ("QCD6");
  mergenames.push_back ("QCD7");
  mergenames.push_back ("QCD8");
  selTable_ee.MergeDatasets (mergenames, string ("QCD1"));
  selTable_emu.MergeDatasets (mergenames, string ("QCD1"));
  selTable_mumu.MergeDatasets (mergenames, string ("QCD1"));
  mergenames.clear ();
  mergenames.push_back ("QCD9");
  mergenames.push_back ("QCD10");
  mergenames.push_back ("QCD11");
  mergenames.push_back ("QCD12");
  mergenames.push_back ("QCD13");
  selTable_ee.MergeDatasets (mergenames, string ("QCD2"));
  selTable_emu.MergeDatasets (mergenames, string ("QCD2"));
  selTable_mumu.MergeDatasets (mergenames, string ("QCD2"));
  mergenames.clear ();
  mergenames.push_back ("DYToEE1");
  mergenames.push_back ("DYToEE2");
  mergenames.push_back ("DYToMuMu1");
  mergenames.push_back ("DYToMuMu2");
  mergenames.push_back ("DYToTauTau1");
  mergenames.push_back ("DYToTauTau2");
  selTable_ee.MergeDatasets (mergenames, string ("DYToLL"));
  selTable_emu.MergeDatasets (mergenames, string ("DYToLL"));
  selTable_mumu.MergeDatasets (mergenames, string ("DYToLL"));

  //Define signal
  selTable_ee.DefineFirstDataset (string ("LM1"));
  selTable_emu.DefineFirstDataset (string ("LM1"));
  selTable_mumu.DefineFirstDataset (string ("LM1"));
//  selTable_allChannels.DefineFirstDataset (string ("TTbarSignal"));
  //Calculations
  selTable_ee.TableCalculator ();
  selTable_emu.TableCalculator ();
  selTable_mumu.TableCalculator ();
//  selTable_allChannels.TableCalculator ();
  //Write
  selTable_ee.Write (ofile);
  selTable_emu.Write (ofile);
  selTable_mumu.Write (ofile);
//  selTable_allChannels.Write (ofile);

  ofile << "\\end{document}" << endl;
  system (Form("pdflatex %s", ofilename.data()));


  if (verbosity > 0) {
    cout << "#########################" << endl;
    cout << " Write output root file " << endl;
    cout << "#########################" << endl;
  }

  string orootfilename;
  if(argc>2) orootfilename = argv[2];
  else orootfilename = string("RPVAnalysis.root");
  TFile *fout = new TFile (orootfilename.c_str(), "RECREATE");
  if(doHistoManager) histoManager.Write (fout);
  //fout->Write();
  fout->Close ();

  //Clear histos before deleting the TFile
  if(doHistoManager) histoManager.Clear ();

  delete fout;

  if (verbosity > 0) {
    cout << "#########################" << endl;
    cout << "    End of the program   " << endl;
    cout << "#########################" << endl;
  }

  return (0);
}
int main(int argc, char* argv[]){
  
  //This line could be commented if you don't want display while running, by example using screen.
  //TApplication theApp("App",&argc,argv);
  
  //---------------------------------------//
  // Global variables: could be give as argument later
  //---------------------------------------//
  
  int nwnodes = 10; //8 to 10 is the optimal
  string macroName = "ProofSelectorTTBarTagAndProbe.C+"; //"+" should be put at the end to use ACLIC complication - This macro should inherit from TSelector 
  string xmlFileName = string("/opt/sbg/data/data1/cms/jandrea/TopIPHC_2012_01_16/CMSSW_4_2_8_patch7/src/MiniTreeAnalysis/NTupleAnalysis/config/TTBarTagAndProbe.xml");  
  string outputFileName = "proof.root";
  
  //---------------------------------------//
  //	Decleration of TProof
  //---------------------------------------//
  
  //to be done before colling TProof
  system("../GeneralExamples/./clean_proof.sh ; echo 'Wait few seconds ... ' ; sleep 6");
  system("rm -r $HOME/.proof");
  
  TProof *proof = TProof::Open("");
  proof->SetParallel(nwnodes);
  //you should not have any package yet
  proof->ShowPackages();
  //proof->ClearPackages();
  //Loading package related to NTupleAnalysis
  cout<<" ## Upload package NTAna.par: ";
  proof->UploadPackage("../NTAna.par");
  cout<<" DONE [don't worry with symlink error - do rm NTAna if you change NTAna.par in the meanwhile !] "<<endl;
  proof->EnablePackage("NTAna");
  //Adding histograms for feedback: must exist in the TSelector !
  //proof->AddFeedback("fHist"); //give the "name" of the histogram and not the name of the variable TH1F* (could be the same !)
  
  //This line is required to display histograms durint the process
  TDrawFeedback fb(proof);
  
  
  //---------------------------------------//
  // Xml Loading  & Dataset registration
  //---------------------------------------//
  
  vector < Dataset > datasets;
  AnalysisEnvironmentLoader anaEL (xmlFileName);
  anaEL.LoadSamples (datasets); // now the list of datasets written in the xml file is known
  
  cout<<" #------------------------------------# "<<endl;
  cout<<" PROOF DATASETS SUMMARY [normaly 0]"<<endl;
  proof->ShowDataSets();
  cout<<" #------------------------------------# "<<endl;
  cout<<" # Registring dataset ... "<<endl;
  cout<<" Don't be worry with the checksum error message [at least I'm not ;-) ]"<<endl;
  cout<<" #------------------------------------# "<<endl;
  //Create datasets in proof format
  TFileCollection** fileCollec = new TFileCollection*[datasets.size()];
  for(unsigned int i=0;i<datasets.size();i++){
    fileCollec[i]  = new TFileCollection(datasets[i].Name().c_str(),"");
    for(unsigned int j=0;j<datasets[i].Filenames().size();j++){
      fileCollec[i]->Add(datasets[i].Filenames()[j].c_str());
    }
    //register dataset in proof
    proof->RegisterDataSet(datasets[i].Name().c_str(),fileCollec[i]);
    proof->VerifyDataSet(datasets[i].Name().c_str());
  }
  
  //summarize the list of datasets
  cout<<" #------------------------------------# "<<endl;
  cout<<" PROOF DATASETS SUMMARY"<<endl;
  proof->ShowDataSets();
  cout<<" #------------------------------------# "<<endl;
  
  //---------------------------------------//
  // 	Loading of the xml file
  //---------------------------------------//
  //Possibility to give float ... ex:
  //Double_t f = 3.14;
  //proof->SetParameter("IN_FLOAT",f);
  
  //---------------------------------------//
  // 	Processing of the datasets
  //---------------------------------------//
  
  string outputFileNameModif = outputFileName.substr(0,outputFileName.size()-5);
  //string MergingCommand = "hadd "+outputFileNameModif+"_merged.root "+outputFileNameModif+"_*.root  ";
  
  
  for(unsigned int i=0;i<datasets.size();i++){
    proof->AddInput(new TNamed("PROOF_DATASETNAME", datasets[i].Name()));
    //---------------------------------------//
    // 	Loading of the xml file
    //---------------------------------------//
    //Possibility to give float ... ex:
    //Double_t f = 3.14;
    //proof->SetParameter("IN_FLOAT",f);
    
    proof->AddInput(new TNamed("PROOF_XMLFILENAME", xmlFileName));
    proof->AddInput(new TNamed("PROOF_OUTPUTFILE", outputFileName));
    
    cout<<"#------------------------------------# "<<endl;
    cout<<"PROOF PARAMETERS SUMMARY"<<endl;
    proof->ShowParameters();
    cout<<"#------------------------------------# "<<endl;
    
    
    cout<<"################################################################"<<endl;
    cout<<"########### Processing the dataset "<<datasets[i].Name()<<endl;
    cout<<"################################################################"<<endl;
    //proof->Process(datasets[i].Name().c_str(),macroName.c_str());
    //system("ps -ef |grep jandrea");
    //gSystem->Load("../.lib/libNTupleAna_22-09-11_12-08-49.so");
    //gSystem->Load("../../../MiniTreeFormat/NTFormat/src/libNTuple.so");
    proof->Process(datasets[i].Name().c_str(),macroName.c_str());
    string newFileName = outputFileNameModif+"_"+datasets[i].Name()+".root";
    //system("sleep 30");
    cout<<"Copying the output file with the name "<<endl;
    //string command = "cp "+outputFileName+" "+newFileName;
    //MergingCommand+=newFileName+" ";
    //system(command.c_str());
    proof->ClearInput();
    
  }
  
  //cout<<"## Merging of all the dataset into one single file with hadd: "<<outputFileName<<endl;
  //system(MergingCommand.c_str());
  cout << "start backuping proof root files " << endl;
  system("mkdir backup_outputProof`date +\"%d-%m-%y_%H-%M-%S\"`; mv proof*.root  backup_outputProof`date +\"%d-%m-%y_%H-%M-%S\"`/.");
  
  cout<<"###############################################################"<<endl;
  cout<<"################ 	   May your job 	##############"<<endl;
  cout<<"################      Live long and prosper	##############"<<endl;
  cout<<"###############################################################"<<endl;
  cout<< "  							      "<< endl;
  cout<< "  			     _  			      "<< endl;
  cout<< "  			  .-T |   _			      "<< endl;
  cout<< "  			  | | |  / |			      "<< endl;
  cout<< "  			  | | | / /`|			      "<< endl;
  cout<< "  		       _  | | |/ / /			      "<< endl;
  cout<< "  		       \\`\\| \'.\' / / 		      "<< endl;
  cout<< "  			\\ \\`-. \'--|  		      "<< endl;
  cout<< "  			 \\    \'   |			      "<< endl;
  cout<< "  			  \\ \\  .` /			      "<< endl;
  cout<< "  			    |	 |			      "<< endl;
  cout<< "  							      "<< endl;
  cout<< "  							      "<< endl;
  cout<<"###############################################################"<<endl;
  cout<<"###############################################################"<<endl;
  
  
  
  
  
  
  
  return (0);
  
}
Exemple #5
0
int main (int argc, char *argv[])
{

 
  cout << "#########################" << endl;
  cout << "Beginning of the program" << endl;
  cout << "#########################" << endl;

  //////////////////////
  //Global variables
  //////////////////////
  vector < Dataset > datasets;
  DiLeptonSelection sel;
  float Lumi = 0;
  float LumiError = 0.;
  // 0: MC - 1: Data - 2 Data & MC
  int DataType = 0;
  int verbosity = 2;
  int doPseudoExp = 0;
  int NofPseudoExp = 0;
  //////////////////////

  //////////////////////
  // Initialisation
  //////////////////////
  string xmlFileName;
  cout<<"argc "<<argc<<" "<<argv[0]<<endl;
  if (argc>1 ) xmlFileName = string(argv[1]);
  else xmlFileName = string ("../../config/PLRMeas.xml");

  AnalysisEnvironmentLoader anaEL (xmlFileName);
  if(verbosity>1) cout<<" - Loading datasets ..."<<endl;
  anaEL.LoadSamples (datasets);	// now the list of datasets written in the xml file is known
  if(verbosity>1) cout<<" - Loading general info ..."<<endl;
  anaEL.LoadGeneralInfo (DataType, Lumi, LumiError, verbosity);

  if(verbosity>1) cout<<" - Initializing PLR ..."<<endl;
  PLRMeasurement plr;
  cout<<"a"<<endl;
  plr.LoadDatasets(datasets);
  cout<<"a"<<endl;
  plr.SetLumi(Lumi,LumiError);
  cout<<"a"<<endl;
  //Load additionnal spectific info
  if(verbosity>1) cout<<" - Loading PLRInformation ..."<<endl;
  anaEL.LoadPLRInformation(plr,doPseudoExp, NofPseudoExp);
  if(verbosity>1) if(doPseudoExp) cout<<"Wil perform "<<NofPseudoExp<<" pseudo experiments "<<endl;
  if(verbosity>1) cout<<" - Loading bkg info ..."<<endl;
  anaEL.LoadBgkInformation(plr);
  //Do this after loading the other info (datasets, backgrounds)
  if(verbosity>1) cout<<" - Loading histograms ..."<<endl;
  plr.LoadHistos();
  plr.AddBkgDeterminationParameter();
  if(verbosity>1) cout<<" - Loading Signal Systematics ..."<<endl;
  anaEL.LoadSystematicsEffect(plr);

 
  if(verbosity>1) cout<<" - Run the PLR ..."<<endl;
  plr.RunLikelihood(doPseudoExp,NofPseudoExp,false,true,true);
  //plr.RunLikelihood(false,1,false,true,true);
  //plr.RunLikelihood(true,10000,false,true,true);
  //plr.RunLikelihood(true,1,false,true,true);
 
  plr.TimingReport();
  
  if(verbosity>1) cout<<" - Write output tex file ..."<<endl;
  string ofoutname = string(argv[2])+".tex";
  ofstream ofout(ofoutname.c_str());
  plr.MinimizationTable(ofout);
  plr.UncertaintiesTable(ofout);
  plr.NumberOfEventsTable(ofout);

  if(verbosity>1) cout<<" - Write output root file ..."<<endl;
  TFile* fout = new TFile(argv[2],"RECREATE");
  //TFile* fout = new TFile("PLR.root","RECREATE");
  plr.Write(fout);
  fout->Close();
  delete fout;

 cout << "#########################" << endl;
  cout << "  End of the program" << endl;
  cout << "#########################" << endl;

}
int main (int argc, char *argv[])
{
  cout << endl;
  cout << "   ,-----------------------," << endl;
  cout << "   |   Starting analysis   |" << endl;
  cout << "   `-----------------------`" << endl;
  cout << endl;

  // ##################################
  // #	Some parameters for the user  #
  // ##################################
 
  bool doHistoManager = false;		// False will not produce histos
  bool doLatexOutput = true;		// False will not produce latex table
  bool doPileUpReweigthing = false;	// False will not use pileup reweighting

  // (can be overwritten by argv[1])
  string defaultConfiguration("../../config/TTbarMETAnalysis.xml");
  // (can be overwritten by argv[2])
  string defaultLatexTableName("CutflowTable");
  // (can be overwritten by argv[3])
  string defaultRootOutputName("TTbarMETanalysis.root");

  // ############################
  // #	Initializing variables  #
  // ############################
  
  INFO1_MSG << "Initializing variables..." << endl;
 
  vector < Dataset > datasets;
  TTbarMetSelection sel;
  
  float Luminosity = 0;
  float LumiError = 0.;
  int DataType = 0;				// DataType : 0: MC - 1: Data - 2 Data & MC
  int verbosity = -1;


  reweight::LumiReWeighting *LumiWeights;
  IPHCTree::NTEvent * event = 0;


  std::vector<std::string> dileptonCol;
  dileptonCol.push_back("l+jets");
  dileptonCol.push_back("ll");
  dileptonCol.push_back("llHadrTau");
  dileptonCol.push_back("llHadrTau3+");

  std::vector<std::string> dileptonRow;
  dileptonRow.push_back("baseline");
  dileptonRow.push_back("MET");
  dileptonRow.push_back("stdVeto");
  dileptonRow.push_back("stdVetoEff");
  dileptonRow.push_back("vetoTest0");
  dileptonRow.push_back("vetoTest0Eff");
  dileptonRow.push_back("vetoTest1");
  dileptonRow.push_back("vetoTest1Eff");
  dileptonRow.push_back("vetoTest2");
  dileptonRow.push_back("vetoTest2Eff");
  dileptonRow.push_back("vetoTest3");
  dileptonRow.push_back("vetoTest3Eff");

  // Reading parameters from argv
  // 	-> configuration file
  string xmlFileName;
  if (argc > 1) xmlFileName = string(argv[1]);
  else          xmlFileName = defaultConfiguration;
  // 	-> root output name
  string rootOutputName;
  if (argc > 2) rootOutputName = string(argv[2]);
  else 			rootOutputName = defaultRootOutputName;
  // 	-> latex table name
  string latexTableName;
  if (argc > 3) latexTableName = string(argv[3]);
  else latexTableName = defaultLatexTableName;
  
  // #############################
  // # 	 Loading configuration   #
  // #############################

  cout << endl;
  INFO1_MSG << "Loading configuration..." << endl;
  cout << "        (config : " << xmlFileName << ")" << endl;
  
 
  AnalysisEnvironmentLoader anaEL (xmlFileName);
  anaEL.LoadSamples (datasets);	// now the list of datasets written in the xml file is known
  anaEL.LoadSelection (sel);	// now the parameters for the selection are given to the selection // no specific TTbarMET parameters
  anaEL.LoadGeneralInfo (DataType, Luminosity, LumiError, verbosity);

  // #########################################
  // # 	 Creating tables and histomanagers   #
  // #########################################

  cout << endl;
  INFO1_MSG << "Creating tables and histomanagers..." << endl;

  // Stuff
  
  TFile dileptonTreeFile("dileptonTree.root","RECREATE","Tree for Dilepton background study");
  TTree *dileptonTree = new TTree("dileptonTree","Tree for Dilepton background study");
  
  dileptonTree->Branch("dileptonData",&dileptonDataForTree,"iso_02:iso_03:iso_03_pT1GeV:iso_04:iso_05:iso_05_no01:iso_05_no015:iso_05_no015_pT1GeV:iso_05_no02:iso_045_no015:iso_055_no015:iso_05_no015_pTEqualIso02:hadronicMC_dRmeanDecay:hadronicMC_dRmaxDecay:hadronicMC_dRmeanChargedDecay:hadronicMC_dRmaxChargedDecay:hadronicMC_pTminChargedDecay:hadronicMC_pTmeanChargedDecay:hadronicMC_pTmaxChargedDecay:bestIso03_iso_03:bestIso03_iso_05_no015:bestIso03_iso_05_no01:bestIso03_iso_05_ntrk_01:bestIso03_iso_05_ntrk_015:bestIso03_iso_05_ntrk_015_pT1GeV:bestIso05no015_iso_03:bestIso05no015_iso_05_no015:bestIso05no015_iso_05_no01:bestIso05no015_iso_05_ntrk_01:bestIso05no015_iso_05_ntrk_015:bestIso05no015_iso_05_ntrk_015_pT1GeV:bestIso05no01_iso_03:bestIso05no01_iso_05_no015:bestIso05no01_iso_05_no01:bestIso05no01_iso_05_ntrk_01:bestIso05no01_iso_05_ntrk_015:bestIso05no01_iso_05_ntrk_015_pT1GeV:eventInfo_isSemilep:eventInfo_isDilep:eventInfo_haveTau:eventInfo_haveHadronicTau:eventInfo_haveHadronicTau3");




  TableScrewdriver dileptonTable(dileptonCol,dileptonRow);
  dileptonTable.PrintTable();
  
  
  // Tables
  
  SelectionTable selTable_e (sel.GetCutList (), datasets, string ("e"));
  SelectionTable selTable_mu (sel.GetCutList (), datasets, string ("µ"));
  SelectionTable selTable_l (sel.GetCutList (), datasets, string ("lepton"));
  
  // Histomanagers
  
  TTbarMetHistoManager histoManager;
  if(doHistoManager)
  {
  	histoManager.LoadDatasets(datasets);
  	histoManager.LoadSelectionSteps(sel.GetCutList ());
  	histoManager.LoadChannels(sel.GetChannelList ());
  	histoManager.CreateHistos();
  }

  // HistoManager specific to Dilepton background analysis
  
  DileptonBkgAnaHistoManager histoManagerDileptonBkg;
  if(doHistoManager)
  {
  	histoManagerDileptonBkg.LoadDatasets (datasets);
  	histoManagerDileptonBkg.LoadSelectionSteps (sel.GetCutList ());
  	histoManagerDileptonBkg.LoadChannels (sel.GetChannelList ());
  	histoManagerDileptonBkg.CreateHistos ();
  }


  // ##############################
  // # 	 Printing general infos   #
  // ##############################
  
  cout << endl;
  cout << "   -----------------------------" << endl;
  cout << "     Verbosity mode : " << verbosity << endl;
  cout << "     Luminosity : " << Luminosity << endl;
  cout << "     DataType (whole config) : ";
  switch (DataType) 
  {
  	case 0: { cout << "MC" << endl;   break; }
  	case 1: { cout << "Data" << endl; break; }
  	case 2: { cout << "Data & MC" << endl; break; }
  	default: { cout << "Unknwon" << endl; break; }
  }
  cout << "   -----------------------------" << endl;
  
  // #########################################
  // # 	 Start loop over the dataset infos   #
  // #########################################
  if (verbosity > 0)
  {
  	cout << endl;
  	cout << "   ,---------------------------------," << endl;
  	cout << "   |   Starting loop over datasets   |" << endl;
  	cout << "   `---------------------------------`" << endl;
  	cout << endl;
  }

  int nEvents_tot;
  for (unsigned int datasetId = 0; datasetId < datasets.size (); datasetId++) 
  {

	  // ########################
	  // # 	 Load the dataset   #
	  // ########################
   
	INFO1_MSG << "Loading next dataset..." << endl;

    datasets[datasetId].eventTree()->SetBranchAddress ("NTEvent", &event);
    unsigned int nEvents = static_cast<unsigned int>(datasets[datasetId].eventTree()->GetEntries ());
    nEvents_tot = nEvents;

    if (verbosity > 2)
	{
		cout << endl;
  		cout << "         [ Dataset n°" << datasetId+1 << " ]" << endl;
		cout << "         " << datasets[datasetId].Name() << endl;
		cout << endl;
  		INFO1_MSG << "   NEvents total    : " << nEvents << endl;
  		INFO1_MSG << "NEvents to run over : " << datasets[datasetId].NofEvtsToRunOver() << endl;
		cout << endl;
	}

	// ########################
	// #   Load the pile-up   #
	// ########################
	
	INFO1_MSG << "Loading pile-up informations..." << endl;
   
    // PU from JL's code
	if (datasets[datasetId].isData() == false) {
//   if(datasets[datasetId].Name() == "DY1" || datasets[datasetId].Name() == "signal" ){
//      string datafile = "/opt/sbg/data/data1/cms/ccollard/CMSSW/CMSSW_4_2_8_patch7/src/NTuple/NTupleAnalysis/macros/data/PUdata.root";
//      string mcfile   = "/opt/sbg/data/data1/cms/ccollard/CMSSW/CMSSW_4_2_8_patch7/src/NTuple/NTupleAnalysis/macros/data/PU3DMC_Fall11.root";
//
//      LumiWeights    = new reweight::LumiReWeighting(mcfile, datafile, "histoMCPU", "pileup" );
//    }
//    else{
      string datafile = "/opt/sbg/data/data1/cms/ccollard/CMSSW/CMSSW_4_2_8_patch7/src/NTuple/NTupleAnalysis/macros/data/default73.5mb.root";
      string mcfile   = "/opt/sbg/data/data1/cms/ccollard/CMSSW/CMSSW_4_2_8_patch7/src/NTuple/NTupleAnalysis/macros/data/PU3DMC.root";

      LumiWeights    = new reweight::LumiReWeighting(mcfile, datafile, "histoMCPU", "pileup" );
      LumiWeights->weight3D_init( 1. );

//    }
    }
 
	// ############################
	// #   Loop over the events   #
	// ############################
			  
	if (verbosity > 0)
	{
 		cout << endl;
 	 	cout << "   ,-------------------------------," << endl;
 	 	cout << "   |   Starting loop over events   |" << endl;
  		cout << "   `-------------------------------`" << endl;
  		cout << endl;
	}

    for (unsigned int ievt = 0; ievt < datasets[datasetId].NofEvtsToRunOver(); ievt++)
    {

	  // Display some information

      if (verbosity > 3)
      {
		        INFO1_MSG <<  "run: " << event->general.runNb;
		        std::cout << " lumi: " << event->general.lumiblock;
      		    std::cout << " event: " << event->general.eventNb;
		  		std::cout << std::endl;
      }

      if (ievt % 100000 == 0) printProgressBar(ievt,datasets[datasetId].NofEvtsToRunOver());

	  // Load the event
	   
	  datasets[datasetId].eventTree()->GetEntry(ievt);
	  IPHCTree::NTTransient::InitializeAfterReading(event);
	  int eventId = event->general.eventNb;
	  sel.LoadEvent(event);

	  // Get the weight for pile-up reweighting

	  float weight = 1.;
	  if (doPileUpReweigthing)
	  {
	  		if(datasets[datasetId].isData() == false) weight = datasets[datasetId].NormFactor()*Luminosity; //if Data , weight = 1

      		float weightpu=1.;
      		if(datasets[datasetId].isData() == false) 
			{ 
				// MC
  	//      if( datasets[datasetId].Name() == "DY1" || datasets[datasetId].Name() == "signal")  
	//      {
	//          double ave_npu = (event->pileup.before_npu+event->pileup.intime_npu+event->pileup.after_npu)/3.;
	//          weightpu = LumiWeights->ITweight3BX(ave_npu);
	//      }
	//      else 
	//      {
         	 	weightpu = LumiWeights->weight3D(event->pileup.before_npu, event->pileup.intime_npu, event->pileup.after_npu);
	//      }
	//      weight *= weightpu; //if Data , weight = 1
      		}
	//      else 
	//      { 
	//      	// DATA
	//         JEC_L2L3Residuals.ApplyCorrections(event); // n'appliquer la correction que pour les donnees
	//      }
	  }


	  // Apply full selection
	  int triggerME = 0;
      int selLastStep = sel.doFullSelection (&(datasets[datasetId]), string("all"),&triggerME);


	  // Get trigger info from selection
      bool trigger_e = false;
      bool trigger_mu = false;
	  if (triggerME % 1 == 1) trigger_e  = true;
	  if (triggerME    >= 10) trigger_mu = true; 

	  // Also get the lepton type
      int lep = sel.GetLeptonType();


      // Fill the table

      		//  1. No Selection 
      selTable_e.Fill( datasetId, 0, weight);
      selTable_mu.Fill(datasetId, 0, weight);
      selTable_l.Fill( datasetId, 0, weight);

      		//  2. Trigger
      if (selLastStep > 0) 
	  {
		selTable_l.Fill( datasetId, 1, weight);
		if (trigger_e)  selTable_e.Fill( datasetId, 1, weight);
		if (trigger_mu) selTable_mu.Fill(datasetId, 1, weight);
      }

      		//  3. Rest of the table
	  for (unsigned int i = 2; i < (sel.GetCutList()).size() ; i++)
	  {
        if (selLastStep >= (int) i && lep==0)  selTable_e.Fill( datasetId, i, weight);
        if (selLastStep >= (int) i && lep==1)  selTable_mu.Fill(datasetId, i, weight);
        if (selLastStep >= (int) i) 		   selTable_l.Fill( datasetId, i, weight);
      }

      // Fill the histo
	  
      int selLastStep_e = 0;
      int selLastStep_mu = 0;
      if (trigger_e) 
	  {
		  selLastStep_e = 1;
      	  if (lep == 0) selLastStep_e=selLastStep;
	  }
      if (trigger_mu) 
	  {
		  selLastStep_mu = 1;
      	  if (lep == 1) selLastStep_mu=selLastStep;
	  }

      histoManager.Fill(sel, event, sel.GetMuonsForAna(), sel.GetElectronsForAna(), selLastStep_e, 0, datasetId, weight);
      histoManager.Fill(sel, event, sel.GetMuonsForAna(), sel.GetElectronsForAna(), selLastStep_mu, 1, datasetId, weight);
      //histoManager.Fill(sel, event, sel.GetMuonsForAna(), sel.GetElectronsForAna(), selLastStep, 2, datasetId, weight);

	  //dileptonBackgroundStudy(&sel,trigger_e,trigger_mu,lep,selLastStep,&histoManagerDileptonBkg,datasetId,weight);

	  // Calculate efficiency for semi-leptonic and di-leptonic
		{
 		
			const IPHCTree::NTMonteCarlo mcInfo = *(sel.GetPointer2MC());
	
  			int TMEME =  mcInfo.TMEME; 
  			int  MEME =  TMEME % 10000; 
  			int   EME =   MEME % 1000; 
  			int    ME =    EME % 100; 
 			int     E =     ME % 10;

  			int nTau      = TMEME / 10000;
  			int nMuFromTau = MEME / 1000;
  			int nElFromTau  = EME / 100;
  			int nMuon        = ME / 10;
			int nElec         = E / 1;

			bool foundVeto0 = false;
			bool foundVeto1 = false;
			bool foundVeto2 = false;
			bool foundVeto3 = false;



	  		resetDileptonData(&dileptonDataForTree);
			if (selLastStep >= 5)
			{

						TLorentzVector lepton_p;
						// Get selected muon for the check
						if (sel.GetMuonsForAna().size()==1) lepton_p = (sel.GetMuonsForAna()[0]).p4;
						else                                lepton_p = (sel.GetElectronsForAna()[0]).p4;



			if (nTau > 0)
			{
			  DEBUG_MSG << " NTauMC = " << nTau;
			  if (nMuFromTau + nElFromTau == 0) cout << " hadr ";
			  std::vector<IPHCTree::NTTau> localTaus = *(sel.GetPointer2Taus());
			  for(unsigned int i=0;i<localTaus.size();i++)
			  {
				if ( lepton_p.DeltaR(localTaus[i].p4) < 0.1) continue;
				
				//DEBUG_MSG << "tipi 0" << endl;

				if (localTaus[i].leadTrackPt <= 5) continue;
	
				//DEBUG_MSG << "tipi 1" << endl;
				
				if ((localTaus[i].ID["byLooseIsolation"]  != 1)
				 && (localTaus[i].ID["byMediumIsolation"] != 1)
				 && (localTaus[i].ID["byTightIsolation"]  != 1)
				 && (localTaus[i].ID["byLooseCombinedIsolationDeltaBetaCorr"] != 1)
				 && (localTaus[i].ID["byMediumCombinedIsolationDeltaBetaCorr"] != 1)
				 && (localTaus[i].ID["byTightCombinedIsolationDeltaBetaCorr"]  != 1)) continue;
				
				if(fabs(localTaus[i].p4.Eta()) >= 2.5)              continue;

				if(fabs(localTaus[i].p4.Eta())<1.566 && fabs(localTaus[i].p4.Eta())>1.4442) continue;
				if(localTaus[i].p4.Pt() < 5)                      continue;

				//if ( fabs( localTaus[i].vertex.Z() - sel.GetSelectedVertex()[0].p3.Z() )  > cfg.TauVertexMatchThr_ ) continue;
				if ( fabs( localTaus[i].D0)  >= 0.04 )     continue;


			  	cout << " ; found";
			  }
			cout << endl;
			}




						// Output vector
						std::vector<IPHCTree::NTPFCandidate> vetotracks = sel.GetPFCandidates();
						// Loop over pfcandidates tracks
						for(unsigned int i=0 ; i < vetotracks.size() ; i++)
						{
							if ((vetotracks[i].p4.Pt() > 10)
							&& (fabs(vetotracks[i].dz_firstGoodVertex) < 0.05))
							{
								TLorentzVector vetoTrack_p = vetotracks[i].p4;
								// Check pfcandidate doesnt match the selected lepton
								if (lepton_p.DeltaR(vetoTrack_p) > 0.1)
								{
									float thePt = vetotracks[i].p4.Pt();
								
									if (dileptonDataForTree.iso_03 > vetotracks[i].others["iso_03"]/thePt)
									{
										dileptonDataForTree.iso_03 = vetotracks[i].others["iso_03"]/thePt;
										dileptonDataForTree.bestIso03_iso_03                 = vetotracks[i].others["iso_03"]/thePt;
										dileptonDataForTree.bestIso03_iso_05_no015           = vetotracks[i].others["iso_05_no015"]/thePt;
										dileptonDataForTree.bestIso03_iso_05_no01            = vetotracks[i].others["iso_05_no01"]/thePt;
										dileptonDataForTree.bestIso03_iso_05_ntrk_01         = (float) vetotracks[i].others["ntrk_01"]; 
										dileptonDataForTree.bestIso03_iso_05_ntrk_015        = (float) vetotracks[i].others["ntrk_015"];
										dileptonDataForTree.bestIso03_iso_05_ntrk_015_pT1GeV = (float) vetotracks[i].others["ntrk_015_pT1GeV"];
									}
									if (dileptonDataForTree.iso_05_no01 > vetotracks[i].others["iso_05_no01"]/thePt)
									{
										dileptonDataForTree.iso_05_no01 = vetotracks[i].others["iso_05_no01"]/thePt;
										dileptonDataForTree.bestIso05no01_iso_03                 = vetotracks[i].others["iso_03"]/thePt;
										dileptonDataForTree.bestIso05no01_iso_05_no015           = vetotracks[i].others["iso_05_no015"]/thePt;
										dileptonDataForTree.bestIso05no01_iso_05_no01            = vetotracks[i].others["iso_05_no01"]/thePt;
										dileptonDataForTree.bestIso05no01_iso_05_ntrk_01         = (float) vetotracks[i].others["ntrk_01"]; 
										dileptonDataForTree.bestIso05no01_iso_05_ntrk_015        = (float) vetotracks[i].others["ntrk_015"];
										dileptonDataForTree.bestIso05no01_iso_05_ntrk_015_pT1GeV = (float) vetotracks[i].others["ntrk_015_pT1GeV"];
									}
									if (dileptonDataForTree.iso_05_no015 > vetotracks[i].others["iso_05_no015"]/thePt)
									{
										dileptonDataForTree.iso_05_no015 = vetotracks[i].others["iso_05_no015"]/thePt;
										dileptonDataForTree.bestIso05no015_iso_03                 = vetotracks[i].others["iso_03"]/thePt;
										dileptonDataForTree.bestIso05no015_iso_05_no015           = vetotracks[i].others["iso_05_no015"]/thePt;
										dileptonDataForTree.bestIso05no015_iso_05_no01            = vetotracks[i].others["iso_05_no01"]/thePt;
										dileptonDataForTree.bestIso05no015_iso_05_ntrk_01         = (float) vetotracks[i].others["ntrk_01"]; 
										dileptonDataForTree.bestIso05no015_iso_05_ntrk_015        = (float) vetotracks[i].others["ntrk_015"];
										dileptonDataForTree.bestIso05no015_iso_05_ntrk_015_pT1GeV = (float) vetotracks[i].others["ntrk_015_pT1GeV"];
									}
									if (dileptonDataForTree.iso_02 > vetotracks[i].others["iso_02"]/thePt) dileptonDataForTree.iso_02 = vetotracks[i].others["iso_02"]/thePt;
									if (dileptonDataForTree.iso_04 > vetotracks[i].others["iso_04"]/thePt) dileptonDataForTree.iso_04 = vetotracks[i].others["iso_04"]/thePt;
									if (dileptonDataForTree.iso_05 > vetotracks[i].others["iso_05"]/thePt) dileptonDataForTree.iso_05 = vetotracks[i].others["iso_05"]/thePt;
									if (dileptonDataForTree.iso_03_pT1GeV > vetotracks[i].others["iso_03_pT1GeV"]/thePt) 
										dileptonDataForTree.iso_03_pT1GeV = vetotracks[i].others["iso_03_pT1GeV"]/thePt;
									if (dileptonDataForTree.iso_05_no015_pT1GeV > vetotracks[i].others["iso_05_no015_pT1GeV"]/thePt)
										dileptonDataForTree.iso_05_no015_pT1GeV = vetotracks[i].others["iso_05_no015_pT1GeV"]/thePt;
									if (dileptonDataForTree.iso_05_no02 > vetotracks[i].others["iso_05_no02"]/thePt) 
										dileptonDataForTree.iso_05_no02 = vetotracks[i].others["iso_05_no02"]/thePt;
									if (dileptonDataForTree.iso_045_no015 > vetotracks[i].others["iso_045_no015"]/thePt)
										dileptonDataForTree.iso_045_no015 = vetotracks[i].others["iso_045_no015"]/thePt;
									if (dileptonDataForTree.iso_055_no015 > vetotracks[i].others["iso_055_no015"]/thePt)
										dileptonDataForTree.iso_055_no015 = vetotracks[i].others["iso_055_no015"]/thePt;

									
								}
							}
						}

						// Loop over pfcandidates tracks
						for(unsigned int i=0 ; i < vetotracks.size() ; i++)
						{
							if ((vetotracks[i].p4.Pt() + vetotracks[i].others["iso_02"] > 10)
							&& (fabs(vetotracks[i].dz_firstGoodVertex) < 0.05))
							{
								TLorentzVector vetoTrack_p = vetotracks[i].p4;
								float thePt = vetotracks[i].p4.Pt() + vetotracks[i].others["iso_02"];
								// Check pfcandidate doesnt match the selected lepton
								if (lepton_p.DeltaR(vetoTrack_p) > 0.1)
								{
									if (dileptonDataForTree.iso_05_no015_pTEqualIso02 > vetotracks[i].others["iso_05_no015"]/thePt)
										dileptonDataForTree.iso_05_no015_pTEqualIso02 = vetotracks[i].others["iso_05_no015"]/thePt;
								}
							}
						}
			
			string channelType(""); 

			// Semi-leptonic case
			if (nTau + nMuon + nElec == 1)
			{
				dileptonDataForTree.eventInfo_isSemilep = 1.0;
				channelType = string("l+jets");
				if (nTau >= 1)
					dileptonDataForTree.eventInfo_haveTau = 1.0;
			}
			// Di-leptonic case
			else if (nTau + nMuon + nElec >= 2)	
			{
				dileptonDataForTree.eventInfo_isDilep = 1.0;
				channelType = string("ll");
				if (nTau >= 1)
				{
					// Di-leptonic with a tau
					dileptonDataForTree.eventInfo_haveTau = 1.0;
					if (nMuFromTau + nElFromTau <= 0)
					{
						// Di-leptonic with a hadronic tau
						dileptonDataForTree.eventInfo_haveHadronicTau = 1.0;
						
						std::vector<IPHCTree::NTGenParticle> genParticles = mcInfo.genParticles; 
						IPHCTree::NTGenParticle theGenTau;
						int genTauIndex = -1;
						bool foundTau = false;

						for (int i = 0 ; i < genParticles.size() ; i++)
						{
							IPHCTree::NTGenParticle particle = genParticles[i];
							if (fabs(particle.id) != 15) continue; 
							if (!foundTau) { theGenTau = particle; genTauIndex = i; }
							else { DEBUG_MSG << "Warning : second tau found in the event" << endl; }
						}
					
						int PKKPPL_ = theGenTau.decayMode;
						int  KKPPL_ = PKKPPL_ % 100000;
						int   KPPL_ =  KKPPL_ % 10000;
						int    PPL_ =   KPPL_ % 1000;
						int     PL_ =    PPL_ % 100;
						int      L_ =     PL_ % 10;

						int numberOfPhotons   = PKKPPL_ / 100000;
						int numberOfKCharged  =  KKPPL_ / 10000;
						int numberOfKZero     =   KPPL_ / 1000;
						int numberOfPiCharged =    PPL_ / 100;
						int numberOfPiZero    =     PL_ / 10;
						int leptonFlavor      =      L_ / 1;

						int numberOfCharged   = numberOfKCharged + numberOfPiCharged;
						if (numberOfCharged >= 3) dileptonDataForTree.eventInfo_haveHadronicTau3 = 1.0;

								// Compute dR mean between decays products
								
								// first we find the highest pt charged decay
								int maxPt = -1.0;
								IPHCTree::NTGenParticle maxPtChargedDecay;
								for (int i = 0 ; i < genParticles.size() ; i++)
								{
									IPHCTree::NTGenParticle particle = genParticles[i];
									if (particle.motherIndex_ == genTauIndex)
									if (((abs(particle.id) == 211) || (abs(particle.id) == 321)) && (particle.p4.Pt() > maxPt))
									{
										maxPt = particle.p4.Pt();
										maxPtChargedDecay = particle;
									}
								}
							
								// then compute the sumDr
								float sumDr = 0.0;
								float DrMax = -1.0;
								int nDecay = 1;
								
								float sumDrCharged = 0.0;
								float DrMaxCharged = -1.0;
								float sumPtCharged = maxPtChargedDecay.p4.Pt();
								float pTminCharged = maxPtChargedDecay.p4.Pt();
								float pTmaxCharged = maxPtChargedDecay.p4.Pt();
								int nDecayCharged = 1;

								for (int i = 0 ; i < genParticles.size() ; i++)
								{
									IPHCTree::NTGenParticle particle = genParticles[i];
									if (particle.p4 == maxPtChargedDecay.p4) continue;
									if ((particle.motherIndex_ == genTauIndex) && (abs(particle.id) != 16))
									{
										nDecay++;
										
										// For all decays
										sumDr += maxPtChargedDecay.p4.DeltaR(particle.p4);
										
										if (maxPtChargedDecay.p4.DeltaR(particle.p4) > DrMax)
											DrMax = maxPtChargedDecay.p4.DeltaR(particle.p4);

										// ChargedDecay
										if (((abs(particle.id) == 211) || (abs(particle.id) == 321)))
										{
											nDecayCharged++;
											sumPtCharged += particle.p4.Pt();
											sumDrCharged += maxPtChargedDecay.p4.DeltaR(particle.p4);
											if (particle.p4.Pt() > pTmaxCharged)
												pTmaxCharged = particle.p4.Pt();
											if (particle.p4.Pt() < pTminCharged)
												pTminCharged = particle.p4.Pt();
											if (maxPtChargedDecay.p4.DeltaR(particle.p4) > DrMaxCharged)
												DrMaxCharged = maxPtChargedDecay.p4.DeltaR(particle.p4);
										}
									}

								}

								// Fill tree info
								dileptonDataForTree.hadronicMC_dRmeanDecay = sumDr / nDecay;
								dileptonDataForTree.hadronicMC_dRmaxDecay = DrMax;
								dileptonDataForTree.hadronicMC_dRmeanChargedDecay = sumDrCharged / nDecayCharged;
								dileptonDataForTree.hadronicMC_dRmaxChargedDecay = DrMaxCharged;
								dileptonDataForTree.hadronicMC_pTminChargedDecay = pTminCharged;
								dileptonDataForTree.hadronicMC_pTmeanChargedDecay = sumPtCharged / nDecayCharged;
								dileptonDataForTree.hadronicMC_pTmaxChargedDecay = pTmaxCharged;

					}

				}
				
			}
		
				if (channelType != string(""))
				{
						dileptonTable.Fill(channelType,"baseline",1.0);
					if (selLastStep >= 5)
					{
						dileptonTable.Fill(channelType,"MET"      ,1.0);
						dileptonTable.Fill(channelType,"vetoTest0",(int) foundVeto0);
						dileptonTable.Fill(channelType,"vetoTest1",(int) foundVeto1);
						dileptonTable.Fill(channelType,"vetoTest2",(int) foundVeto2);
						dileptonTable.Fill(channelType,"vetoTest3",(int) foundVeto3);
					}
					if (selLastStep >= 6) 
						dileptonTable.Fill(channelType,"stdVeto",1.0);
				}

				dileptonTree->Fill();
			}
	  	}

	  } // end of loop over evts
  }		// end of loop over datasets 

  dileptonTree->Print();
  dileptonTreeFile.Write();
  dileptonTreeFile.Close();
  dileptonTable.PrintTable();

  // ################################
  // #   Computations after loops   #
  // ################################
	
  cout << endl;
  cout << "   ,-------------------------------," << endl;
  cout << "   |   Compute histos and tables   |" << endl;
  cout << "   `-------------------------------`" << endl;
  cout << endl;

  // Compute and save histograms
  
  if(!doHistoManager) INFO1_MSG << "HistoManagers [skipped]" << endl;
  else
  {	
	  INFO1_MSG << "HistoManagers ..." << endl;
	  
      // Standard histograms

	  histoManager.Compute ();
	  
	  string orootfilename = rootOutputName;
	  TFile *fout = new TFile (orootfilename.c_str(), "RECREATE");
	  histoManager.Write (fout);
	  fout->Close ();  
	  
	  // DileptonBkg histograms
	  
	  histoManagerDileptonBkg.MergeChannels();
	  histoManagerDileptonBkg.DoMCStack();
	  histoManagerDileptonBkg.MergeMCDatasets();
	  histoManagerDileptonBkg.PlotsCutByCut();
	  
	  string orootfilenameDileptonBkg;
	  orootfilenameDileptonBkg = string("TTbarMETanalysis_DileptonBkgAna.root");
	  TFile *fout2 = new TFile (orootfilenameDileptonBkg.c_str(), "RECREATE");
	  histoManagerDileptonBkg.Write (fout2);
	  fout2->Close();

	  string orootfilenameDileptonBkg2D;
	  orootfilenameDileptonBkg2D = string("TTbarMETanalysis_DileptonBkgAna2D.root");
	  TFile *fout3 = new TFile (orootfilenameDileptonBkg2D.c_str(), "RECREATE");
	  histoManagerDileptonBkg.Write2D (fout3);
	  fout3->Close();

	  // Clear
  
	  histoManager.Clear ();
	  histoManagerDileptonBkg.Clear ();

	  delete fout;
	  delete fout2;
	  delete fout3;

  }
  
  // Write and compile tables

  if (!doLatexOutput) INFO1_MSG << "Tables [skipped]" << endl;
  {
	  INFO1_MSG << "Tables ..." << endl;
	
	  selTable_e.TableCalculator();
	  selTable_mu.TableCalculator();
	  selTable_l.TableCalculator();

	  makeSelectionTable(latexTableName,selTable_e,selTable_mu,selTable_l);

  }

  cout << endl;
  cout << "   ,-----------------------," << endl;
  cout << "   |   Program completed   |" << endl;
  cout << "   `-----------------------`" << endl;
  cout << endl;

  return (0);
}
Exemple #7
0
int main ()
{
  cout<<"#########################"<<endl;
  cout<<"Beginning of the program"<<endl;
  cout<<"#########################"<<endl;
  
  //////////////////////
  //Global variables
  //////////////////////
  vector < Dataset > datasets;
  DiLeptonSelection sel; 
  float Luminosity = 0;
  // 0: MC - 1: Data - 2 Data & MC
  int DataType = 0; 
  int verbosity = -1;

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

  //////////////////////
  // Initialisation
  //////////////////////
  string xmlFileName = string ("../../config/MyVar.xml");
  AnalysisEnvironmentLoader anaEL (xmlFileName);
  anaEL.LoadSamples (datasets); // now the list of datasets written in the xml file is known
  anaEL.LoadDiLeptonSelection (sel); // now the parameters for the selection are given to the selection
  anaEL.LoadGeneralInfo(DataType, Luminosity, verbosity );
  anaEL.LoadWeight (sel); // now the parameters for SFBweight are initialized (for b-tag!)
  TopTree::NTEvent * event = 0;

  //dataset weights
  double Dweight[101]; 
  for(int k0=0; k0<5; ++k0) {
    for(int k1=0; k1<101; ++k1) {
      Dweight[k1] = 0.;
    }
  } 
  vector<string> CutName;
  vector<string> VecChannelName;
  


// Here define the studied channel (ee/mumu/emu)
  string ChannelName  = "mumu";  // "mumu", "ee", "emu"


  int ITypeMC	  = -1;
  int ICut	  = -1;  
  int IChannel    = -1;  
  if (  ChannelName  == "mumu" )  IChannel = 0;
  if (  ChannelName  == "ee" )    IChannel = 1;
  if (  ChannelName  == "emu" )   IChannel = 2;

  
  
  int nbins = 200;
  float minx = 0.;
  float maxx = 350;
  
  
  cout<<"The verbosity mode is "<<verbosity <<endl;
  cout<<"The luminosity is equal to "<< Luminosity<<endl;
  cout<<"The DataType is ";
  switch(DataType){
  case 0: 
    cout<<"MC"<<endl; 
    break;
  case 1:
    cout<<"Data"<<endl; 
    break;
  case 2:
    cout<<"Data & MC"<<endl; 
    break;
  default:
    cout<<" unknown"<<endl; 
    break;
  }
  //////////////////////
  
    HistoManager MyhistoManager;
    MyhistoManager.LoadDatasets(datasets);   
     

//     std::vector<TH1F> PATElecPt;
//     std::vector<TH1F> PATElecRelIso;
//     std::vector<TH1F> PATMuonPt;
//     std::vector<TH1F> PATMuonRelIso;
    
    std::vector<TH1F> PFElecPt;
    std::vector<TH1F> PFElecNeutralHadIso;
    std::vector<TH1F> PFElecChargedHadIso;
    std::vector<TH1F> PFElecPhotonIso;
    std::vector<TH1F> PFElecTrackIso;
    std::vector<TH1F> PFElecRelIso;
    std::vector<TH1F> PFElecEcalDriven;
    std::vector<TH1F> PFElecGsfEl;
    std::vector<TH1F> PFElecD0;
    std::vector<TH1F> PFElecId90;
    std::vector<TH1F> PFElecConv;
    std::vector<TH1F> PFElecRelIsoRhoCorrected;
    std::vector<TH1F> PFElecRelIsoNeutralRhoCorrected;
    
    
    std::vector<TH1F> PFMuonPt;
    std::vector<TH1F> PFMuonNeutralHadIso;
    std::vector<TH1F> PFMuonChargedHadIso;
    std::vector<TH1F> PFMuonPhotonIso;
    std::vector<TH1F> PFMuonTrackIso;
    std::vector<TH1F> PFMuonRelIso;
    std::vector<TH1F> PFMuonType;
    std::vector<TH1F> PFMuonChi2;
    std::vector<TH1F> PFMuonTrValHit;
    std::vector<TH1F> PFMuonValHit;
    std::vector<TH1F> PFMuonD0;
    std::vector<TH1F> PFMuonZvx;
    std::vector<TH1F> PFMuonRelIsoRhoCorrected;
    std::vector<TH1F> PFMuonRelIsoNeutralRhoCorrected;

    std::vector<TH1F> TMEME;
    
//     std::vector<TH1F> PATElecPt_FromW;
//     std::vector<TH1F> PATElecRelIso_FromW;
//     std::vector<TH1F> PATMuonPt_FromW;
//     std::vector<TH1F> PATMuonRelIso_FromW;
//     std::vector<TH1F> PATElecPt_FromW_Cut015;
//     std::vector<TH1F> PATMuonPt_FromW_Cut015;
    
    std::vector<TH1F> PFElecPt_FromW;
    std::vector<TH1F> PFElecNeutralHadIso_FromW;
    std::vector<TH1F> PFElecChargedHadIso_FromW;
    std::vector<TH1F> PFElecPhotonIso_FromW;
    std::vector<TH1F> PFElecTrackIso_FromW;
    std::vector<TH1F> PFElecRelIso_FromW;
    
    std::vector<TH1F> PFMuonPt_FromW;
    std::vector<TH1F> PFMuonNeutralHadIso_FromW;
    std::vector<TH1F> PFMuonChargedHadIso_FromW;
    std::vector<TH1F> PFMuonPhotonIso_FromW;
    std::vector<TH1F> PFMuonTrackIso_FromW;
    std::vector<TH1F> PFMuonRelIso_FromW;
    std::vector<TH1F> PFElecPt_FromW_Cut015;
    std::vector<TH1F> PFMuonPt_FromW_Cut015;
    std::vector<TH1F> PFMuonType_FromW;
    
    
//     std::vector<TH1F> PATElecPt_FromBC;
//     std::vector<TH1F> PATElecRelIso_FromBC;
//     std::vector<TH1F> PATMuonPt_FromBC;
//     std::vector<TH1F> PATMuonRelIso_FromBC;
//     std::vector<TH1F> PATElecPt_FromBC_Cut015;
//     std::vector<TH1F> PATMuonPt_FromBC_Cut015;
    
    std::vector<TH1F> PFElecPt_FromBC;
    std::vector<TH1F> PFElecNeutralHadIso_FromBC;
    std::vector<TH1F> PFElecChargedHadIso_FromBC;
    std::vector<TH1F> PFElecPhotonIso_FromBC;
    std::vector<TH1F> PFElecTrackIso_FromBC;
    std::vector<TH1F> PFElecRelIso_FromBC;
    
    std::vector<TH1F> PFMuonPt_FromBC;
    std::vector<TH1F> PFMuonNeutralHadIso_FromBC;
    std::vector<TH1F> PFMuonChargedHadIso_FromBC;
    std::vector<TH1F> PFMuonPhotonIso_FromBC;
    std::vector<TH1F> PFMuonTrackIso_FromBC;
    std::vector<TH1F> PFMuonRelIso_FromBC;
    std::vector<TH1F> PFElecPt_FromBC_Cut015;
    std::vector<TH1F> PFMuonPt_FromBC_Cut015;
    std::vector<TH1F> PFMuonType_FromBC;
    
  
  //////////////////////
  //LOOP OVER THE DATASETS
  //////////////////////
  if(verbosity>0) {
    cout<<"#########################"<<endl;
    cout<<" Loop over the datasets  "<<endl;
    cout<<"#########################"<<endl;
  }
  

  for (unsigned int d = 0; d < datasets.size (); d++) {
    
    
    datasets[d].eventTree ()->SetBranchAddress ("NTEvent",&event);
    
    unsigned int nEvents = (int) (datasets[d].eventTree ()->GetEntries ());
    cout << "NEvents = " << nEvents << endl;
    
//     MyhistoManager.CreateHisto(PATElecPt,                   "PATElecPt" ,datasets[d].Name(),"Pt","Entries",50,0.,100);
//     MyhistoManager.CreateHisto(PATElecRelIso,               "PATElecRelIso" ,datasets[d].Name(),"RelIso","Entries",50,0.,1.0);
//     MyhistoManager.CreateHisto(PATMuonPt,                   "PATMuonPt" ,datasets[d].Name(),"Pt","Entries",50,0.,100);
//     MyhistoManager.CreateHisto(PATMuonRelIso,               "PATMuonRelIso" ,datasets[d].Name(),"RelIso","Entries",50,0.,1.0);

    MyhistoManager.CreateHisto(PFElecPt,                   "PFElecPt" ,datasets[d].Name(),"Pt","Entries",50,0.,100);
    MyhistoManager.CreateHisto(PFElecNeutralHadIso,               "PFElecNeutralHadIso"   ,datasets[d].Name(),"NeutralHadIso","Entries",100,0.,10.0);
    MyhistoManager.CreateHisto(PFElecChargedHadIso,               "PFElecChargedHadIso" ,datasets[d].Name(),"ChargedHadIso","Entries",100,0.,10.0);
    MyhistoManager.CreateHisto(PFElecPhotonIso,               "PFElecPhotonIso" ,datasets[d].Name(),"PhotonIso","Entries",100,0.,10.0);
    MyhistoManager.CreateHisto(PFElecTrackIso,               "PFElecTrackIso" ,datasets[d].Name(),"TrackIso","Entries",100,0.,10.0);
    MyhistoManager.CreateHisto(PFElecRelIso,               "PFElecRelIso" ,datasets[d].Name(),"RelIso","Entries",50,0.,1.0);
    MyhistoManager.CreateHisto(PFElecEcalDriven,               "PFElecEcalDriven" ,datasets[d].Name(),"isEcalDriven","Entries",2,-0.5,1.5);
    MyhistoManager.CreateHisto(PFElecGsfEl,               "PFElecGsfEl" ,datasets[d].Name(),"isGsfEl","Entries",2,-0.5,1.5);
    MyhistoManager.CreateHisto(PFElecD0,               "PFElecD0" ,datasets[d].Name(),"D0","Entries",50,0.,1.);
    MyhistoManager.CreateHisto(PFElecId90,               "PFElecId90" ,datasets[d].Name(),"isId90","Entries",2,-0.5,1.5);
    MyhistoManager.CreateHisto(PFElecConv,               "PFElecConv" ,datasets[d].Name(),"isConv","Entries",2,-0.5,1.5);
    MyhistoManager.CreateHisto(PFElecRelIsoRhoCorrected,               "PFElecRelIsoRhoCorrected" ,datasets[d].Name(),"RelIsoRhoCorrected","Entries",50,0.,1.0);
    MyhistoManager.CreateHisto(PFElecRelIsoNeutralRhoCorrected,               "PFElecRelIsoNeutralRhoCorrected",datasets[d].Name(),"RelIsoNeutralRhoCorrected","Entries",50,0.,1.0);

    MyhistoManager.CreateHisto(PFMuonPt,                   "PFMuonPt" ,datasets[d].Name(),"Pt","Entries",50,0.,100);
    MyhistoManager.CreateHisto(PFMuonNeutralHadIso,               "PFMuonNeutralHadIso" ,datasets[d].Name(),"NeutralHadIso","Entries",100,0.,10.0);
    MyhistoManager.CreateHisto(PFMuonChargedHadIso,               "PFMuonChargedHadIso" ,datasets[d].Name(),"ChargedHadIso","Entries",100,0.,10.0);
    MyhistoManager.CreateHisto(PFMuonPhotonIso,               "PFMuonPhotonIso" ,datasets[d].Name(),"PhotonIso","Entries",100,0.,10.0);
    MyhistoManager.CreateHisto(PFMuonTrackIso,               "PFMuonTrackIso" ,datasets[d].Name(),"TrackIso","Entries",100,0.,10.0);
    MyhistoManager.CreateHisto(PFMuonRelIso,               "PFMuonRelIso" ,datasets[d].Name(),"RelIso","Entries",50,0.,1.0);
    MyhistoManager.CreateHisto(TMEME,                   "TMEME" ,datasets[d].Name(),"TMEME","Entries",1000,0.,30000);
    MyhistoManager.CreateHisto(PFMuonType,               "PFMuonType" ,datasets[d].Name(),"Type","Entries",120,0.,119);
    MyhistoManager.CreateHisto(PFMuonChi2,               "PFMuonChi2" ,datasets[d].Name(),"Chi2","Entries",50,0.,50);
    MyhistoManager.CreateHisto(PFMuonTrValHit,               "PFMuonTrValHit" ,datasets[d].Name(),"TrValHit","Entries",50,0.,50);
    MyhistoManager.CreateHisto(PFMuonValHit,               "PFMuonValHit" ,datasets[d].Name(),"ValHit","Entries",50,0.,50);
    MyhistoManager.CreateHisto(PFMuonD0,               "PFMuonD0" ,datasets[d].Name(),"D0","Entries",50,0.,1.);
    MyhistoManager.CreateHisto(PFMuonZvx,               "PFMuonZvx" ,datasets[d].Name(),"D0","Entries",50,0.,1);
    MyhistoManager.CreateHisto(PFMuonRelIsoRhoCorrected,               "PFMuonRelIsoRhoCorrected" ,datasets[d].Name(),"RelIsoRhoCorrected","Entries",50,0.,1.0);
    MyhistoManager.CreateHisto(PFMuonRelIsoNeutralRhoCorrected,               "PFMuonRelIsoNeutralRhoCorrected",datasets[d].Name(),"RelIsoNeutralRhoCorrected","Entries",50,0.,1.0);
    
//     MyhistoManager.CreateHisto(PATElecPt_FromW,                   "PATElecPt_FromW" ,datasets[d].Name(),"Pt","Entries",50,0.,100);
//     MyhistoManager.CreateHisto(PATElecRelIso_FromW,               "PATElecRelIso_FromW" ,datasets[d].Name(),"RelIso","Entries",50,0.,1.0);
//     MyhistoManager.CreateHisto(PATMuonPt_FromW,                   "PATMuonPt_FromW" ,datasets[d].Name(),"Pt","Entries",50,0.,100);
//     MyhistoManager.CreateHisto(PATMuonRelIso_FromW,               "PATMuonRelIso_FromW" ,datasets[d].Name(),"RelIso","Entries",50,0.,1.0);
//     MyhistoManager.CreateHisto(PATElecPt_FromW_Cut015,                   "PATElecPt_FromW_Cut015" ,datasets[d].Name(),"Pt","Entries",50,0.,100);
//     MyhistoManager.CreateHisto(PATMuonPt_FromW_Cut015,                   "PATMuonPt_FromW_Cut015" ,datasets[d].Name(),"Pt","Entries",50,0.,100);

    MyhistoManager.CreateHisto(PFElecPt_FromW,                   "PFElecPt_FromW" ,datasets[d].Name(),"Pt","Entries",50,0.,100);
    MyhistoManager.CreateHisto(PFElecNeutralHadIso_FromW,               "PFElecNeutralHadIso_FromW"   ,datasets[d].Name(),"NeutralHadIso","Entries",100,0.,10.0);
    MyhistoManager.CreateHisto(PFElecChargedHadIso_FromW,               "PFElecChargedHadIso_FromW" ,datasets[d].Name(),"ChargedHadIso","Entries",100,0.,10.0);
    MyhistoManager.CreateHisto(PFElecPhotonIso_FromW,               "PFElecPhotonIso_FromW" ,datasets[d].Name(),"PhotonIso","Entries",100,0.,10.0);
    MyhistoManager.CreateHisto(PFElecTrackIso_FromW,               "PFElecTrackIso_FromW" ,datasets[d].Name(),"TrackIso","Entries",100,0.,10.0);
    MyhistoManager.CreateHisto(PFElecRelIso_FromW,               "PFElecRelIso_FromW" ,datasets[d].Name(),"RelIso","Entries",50,0.,1.0);
    MyhistoManager.CreateHisto(PFMuonPt_FromW,                   "PFMuonPt_FromW" ,datasets[d].Name(),"Pt","Entries",50,0.,100);
    MyhistoManager.CreateHisto(PFMuonNeutralHadIso_FromW,               "PFMuonNeutralHadIso_FromW" ,datasets[d].Name(),"NeutralHadIso","Entries",100,0.,10.0);
    MyhistoManager.CreateHisto(PFMuonChargedHadIso_FromW,               "PFMuonChargedHadIso_FromW" ,datasets[d].Name(),"ChargedHadIso","Entries",100,0.,10.0);
    MyhistoManager.CreateHisto(PFMuonPhotonIso_FromW,               "PFMuonPhotonIso_FromW" ,datasets[d].Name(),"PhotonIso","Entries",100,0.,10.0);
    MyhistoManager.CreateHisto(PFMuonTrackIso_FromW,               "PFMuonTrackIso_FromW" ,datasets[d].Name(),"TrackIso","Entries",100,0.,10.0);
    MyhistoManager.CreateHisto(PFMuonRelIso_FromW,               "PFMuonRelIso_FromW" ,datasets[d].Name(),"RelIso","Entries",50,0.,1.0);
    MyhistoManager.CreateHisto(PFElecPt_FromW_Cut015,                   "PFElecPt_FromW_Cut015" ,datasets[d].Name(),"Pt","Entries",50,0.,100);
    MyhistoManager.CreateHisto(PFMuonPt_FromW_Cut015,                   "PFMuonPt_FromW_Cut015" ,datasets[d].Name(),"Pt","Entries",50,0.,100);
    MyhistoManager.CreateHisto(PFMuonType_FromW,               "PFMuonType_FromW" ,datasets[d].Name(),"Type","Entries",120,0.,119);

//     MyhistoManager.CreateHisto(PATElecPt_FromBC,                   "PATElecPt_FromBC" ,datasets[d].Name(),"Pt","Entries",50,0.,100);
//     MyhistoManager.CreateHisto(PATElecRelIso_FromBC,               "PATElecRelIso_FromBC" ,datasets[d].Name(),"RelIso","Entries",50,0.,1.0);
//     MyhistoManager.CreateHisto(PATMuonPt_FromBC,                   "PATMuonPt_FromBC" ,datasets[d].Name(),"Pt","Entries",50,0.,100);
//     MyhistoManager.CreateHisto(PATMuonRelIso_FromBC,               "PATMuonRelIso_FromBC" ,datasets[d].Name(),"RelIso","Entries",50,0.,1.0);
//     MyhistoManager.CreateHisto(PATElecPt_FromBC_Cut015,                   "PATElecPt_FromBC_Cut015" ,datasets[d].Name(),"Pt","Entries",50,0.,100);
//     MyhistoManager.CreateHisto(PATMuonPt_FromBC_Cut015,                   "PATMuonPt_FromBC_Cut015" ,datasets[d].Name(),"Pt","Entries",50,0.,100);

    MyhistoManager.CreateHisto(PFElecPt_FromBC,                   "PFElecPt_FromBC" ,datasets[d].Name(),"Pt","Entries",50,0.,100);
    MyhistoManager.CreateHisto(PFElecNeutralHadIso_FromBC,               "PFElecNeutralHadIso_FromBC"   ,datasets[d].Name(),"NeutralHadIso","Entries",100,0.,10.0);
    MyhistoManager.CreateHisto(PFElecChargedHadIso_FromBC,               "PFElecChargedHadIso_FromBC" ,datasets[d].Name(),"ChargedHadIso","Entries",100,0.,10.0);
    MyhistoManager.CreateHisto(PFElecPhotonIso_FromBC,               "PFElecPhotonIso_FromBC" ,datasets[d].Name(),"PhotonIso","Entries",100,0.,10.0);
    MyhistoManager.CreateHisto(PFElecTrackIso_FromBC,               "PFElecTrackIso_FromBC" ,datasets[d].Name(),"TrackIso","Entries",100,0.,10.0);
    MyhistoManager.CreateHisto(PFElecRelIso_FromBC,               "PFElecRelIso_FromBC" ,datasets[d].Name(),"RelIso","Entries",50,0.,1.0);
    MyhistoManager.CreateHisto(PFMuonPt_FromBC,                   "PFMuonPt_FromBC" ,datasets[d].Name(),"Pt","Entries",50,0.,100);
    MyhistoManager.CreateHisto(PFMuonNeutralHadIso_FromBC,               "PFMuonNeutralHadIso_FromBC" ,datasets[d].Name(),"NeutralHadIso","Entries",100,0.,10.0);
    MyhistoManager.CreateHisto(PFMuonChargedHadIso_FromBC,               "PFMuonChargedHadIso_FromBC" ,datasets[d].Name(),"ChargedHadIso","Entries",100,0.,10.0);
    MyhistoManager.CreateHisto(PFMuonPhotonIso_FromBC,               "PFMuonPhotonIso_FromBC" ,datasets[d].Name(),"PhotonIso","Entries",100,0.,10.0);
    MyhistoManager.CreateHisto(PFMuonTrackIso_FromBC,               "PFMuonTrackIso_FromBC" ,datasets[d].Name(),"TrackIso","Entries",100,0.,10.0);
    MyhistoManager.CreateHisto(PFMuonRelIso_FromBC,               "PFMuonRelIso_FromBC" ,datasets[d].Name(),"RelIso","Entries",50,0.,1.0);
    MyhistoManager.CreateHisto(PFElecPt_FromBC_Cut015,                   "PFElecPt_FromBC_Cut015" ,datasets[d].Name(),"Pt","Entries",50,0.,100);
    MyhistoManager.CreateHisto(PFMuonPt_FromBC_Cut015,                   "PFMuonPt_FromBC_Cut015" ,datasets[d].Name(),"Pt","Entries",50,0.,100);
    MyhistoManager.CreateHisto(PFMuonType_FromBC,               "PFMuonType_FromBC" ,datasets[d].Name(),"Type","Entries",120,0.,199);


    //////////////////////
    //LOOP OVER THE EVENTS
    //////////////////////
    for (unsigned int ievt = 0; ievt < nEvents; ievt++) {
      
      float weight = 1.;
      datasets[d].eventTree ()->GetEntry (ievt);
      
      //      cout << "event number=" << event->eventNb << endl;
      //      cout << "normfactor=" << datasets[d].NormFactor() << endl;
      //      cout << "Xsection=" << datasets[d].Xsection() << endl;
      //      cout << "NofEvtsToRunOver=" << datasets[d].NofEvtsToRunOver() << endl;
      
      
      MyhistoManager.FillHisto(TMEME, "TMEME",event->TMEME,datasets[d].Name(),true,1.0);

      if(ievt%10000 == 0) cout << "number of processed events " << ievt << endl;
      //if(ievt > 50000) break;
      //Load event for the selection
      sel.LoadEvent(event);
      
      //Collection of selected objects
      vector<NTVertex>   selVertices  = sel.GetSelectedVertex();
      vector<NTElectron> selElectrons = sel.GetSelectedElectronsNoIso();
      vector<NTMuon>     selMuons     = sel.GetSelectedMuonsNoIso();
      vector<NTJet>      selJets      = sel.GetSelectedJets();
      NTMET met                       = sel.GetMET(); 
      
      
      //Candidate pair of lepton
      string CandType; // ee - emu - mumum or false
      vector<NTElectron> candElec;
      vector<NTMuon> candMuon;
      
      sel.GetLeptonPair(candMuon, candElec, CandType ); 
      
      TLorentzVector DiLepton_mumu;
      for(unsigned int i=0;i<candMuon.size();i++) DiLepton_mumu+=candMuon[i].p4;
      TLorentzVector DiLepton_ee;
      for(unsigned int i=0;i<candElec.size();i++) DiLepton_ee+=candElec[i].p4;
      TLorentzVector DiLepton_emu;
      for(unsigned int i=0;i<candMuon.size();i++) DiLepton_emu+=candMuon[i].p4;
      for(unsigned int i=0;i<candElec.size();i++) DiLepton_emu+=candElec[i].p4;

      float InvDilMass = 0;
      if (ChannelName=="mumu")  InvDilMass = DiLepton_mumu.M();
      if (ChannelName=="ee")	InvDilMass = DiLepton_ee.M();
      if (ChannelName=="emu")	InvDilMass = DiLepton_emu.M();
      
      
// keep only Z mass peak
      if ( InvDilMass<76 ||  InvDilMass>106 ) continue;     
      
      
      
      //Manage DY samples to avoid overlaps
      double dileptInvMass = 0;
      if( (event->zAndDecays).size() > 0){
        TLorentzVector dilept = (event->zAndDecays)[0].p4_Lep1_gen + (event->zAndDecays)[0].p4_Lep2_gen;
	dileptInvMass = dilept.M();
      }
      
      if(datasets[d].Name()=="Zjets" && dileptInvMass < 50 ) cout << "problem !!!" << endl;
       
      if(datasets[d].Name()=="Zjets" && dileptInvMass < 50) continue;
      
      if(datasets[d].Name()=="DYToMuMu_M-20"	   && (dileptInvMass > 50 || dileptInvMass < 20) ) continue;
      if(datasets[d].Name()=="DYToEE_M-20"	   && (dileptInvMass > 50 || dileptInvMass < 20) ) continue;
      if(datasets[d].Name()=="DYToTauTau_M-20"	   && (dileptInvMass > 50 || dileptInvMass < 20) ) continue;
      if(datasets[d].Name()=="DYToMuMu_M-10To20"   &&  dileptInvMass > 20) continue;
      if(datasets[d].Name()=="DYToEE_M-10To20"	   &&  dileptInvMass > 20) continue;
      if(datasets[d].Name()=="DYToTauTau_M-10To20" &&  dileptInvMass > 20) continue;
      
      
     
      double weightITypeMC = Luminosity*datasets[d].Xsection()/datasets[d].getNSkimmedEvent();
      
      
      if ( datasets[d].Name()=="DataEG" || datasets[d].Name()=="DataMu") weightITypeMC = 1;
      bool IsSignal = false;
      int LastStep = 0;
      bool IsData = false;
      
      if ( datasets[d].Name()=="TTbar" ) {
        if ( ChannelName=="mumu" ) {
	  if ( event->TMEME==20 || event->TMEME==11010 || event->TMEME==22000 )    IsSignal = true;
	  if ( !(event->TMEME==20 || event->TMEME==11010 || event->TMEME==22000) ) IsSignal = false;
	}  
        if ( ChannelName=="ee" ) {
	  if ( event->TMEME==2 || event->TMEME==10101 || event->TMEME==20200 )     IsSignal = true;
	  if ( !(event->TMEME==2 || event->TMEME==10101 || event->TMEME==20200) )  IsSignal = false;
	}  
        if ( ChannelName=="emu" ) {
	  if ( event->TMEME==11 || event->TMEME==21100 || event->TMEME==11001 || event->TMEME==10110 )     IsSignal = true;
	  if ( !(event->TMEME==11 || event->TMEME==21100 || event->TMEME==11001 || event->TMEME==10110) )  IsSignal = false;
	}  
      }
      
      
      if ( datasets[d].Name()=="TTbar" ) { 
        if (IsSignal ) { ITypeMC = 0;  Dweight[ITypeMC]= weightITypeMC; 
                       } 
	else { ITypeMC = 1; Dweight[ITypeMC]= weightITypeMC; 
             }
      }
      if ( datasets[d].Name()=="Zjets"              || 
	   datasets[d].Name()=="DYToMuMu_M-20"      || 
	   datasets[d].Name()=="DYToEE_M-20"        || 
	   datasets[d].Name()=="DYToTauTau_M-20"    || 
	   datasets[d].Name()=="DYToMuMu_M-10To20"  || 
	   datasets[d].Name()=="DYToEE_M-10To20"    || 
	   datasets[d].Name()=="DYToTauTau_M-10To20"
	   ) { 
        ITypeMC = 2; IsSignal = false; Dweight[ITypeMC]= weightITypeMC;  
      }
      if ( datasets[d].Name()=="WjetsMu" ||
           datasets[d].Name()=="WjetsE"  ||
           datasets[d].Name()=="WjetsTau" 
       ) { 
        ITypeMC = 3; IsSignal = false;  Dweight[ITypeMC]= weightITypeMC; 
      }
      if ( datasets[d].Name()=="SingleToptW" ) { 
        ITypeMC = 4; IsSignal = false;  Dweight[ITypeMC]= weightITypeMC; 
      }
      if ( datasets[d].Name()=="WZ" || datasets[d].Name()=="WW" || datasets[d].Name()=="ZZ"  ) { 
        ITypeMC = 5; IsSignal = false;  Dweight[ITypeMC]= weightITypeMC; 
      }
      if ( datasets[d].Name()=="DYee" ) { 
        ITypeMC = 6; IsSignal = false;  Dweight[ITypeMC]= weightITypeMC; 
      }
      if ( datasets[d].Name()=="DYmumu" ) { 
        ITypeMC = 7; IsSignal = false;  Dweight[ITypeMC]= weightITypeMC; 
      }
      if ( datasets[d].Name()=="QCD1" ||
           datasets[d].Name()=="QCD2" ||
           datasets[d].Name()=="QCD3" ||
           datasets[d].Name()=="QCD4" ||
           datasets[d].Name()=="QCD5" ||
           datasets[d].Name()=="QCD6" ||
           datasets[d].Name()=="QCD7" ||
           datasets[d].Name()=="QCD8" ||
           datasets[d].Name()=="QCD9" ||
           datasets[d].Name()=="QCD10" ||
           datasets[d].Name()=="QCD11" ||
           datasets[d].Name()=="QCD12" ||
           datasets[d].Name()=="QCD13" 
      
        ) { 
        ITypeMC = 8; IsSignal = false;  Dweight[ITypeMC]= weightITypeMC;
      }
      if ( datasets[d].Name()=="DataEG" || datasets[d].Name()=="DataMu") { 
        ITypeMC = 100; IsData = true;  Dweight[ITypeMC]= weightITypeMC; 
      }
      
      sel.passTriggerSelection ( &datasets[d], ChannelName);
      
      for(unsigned int i=0;i<selElectrons.size();i++){
         NTElectron el = selElectrons[i];   
 
//        vector<NTElectron> allElec = event->electrons;
//       for(unsigned int i=0;i<allElec.size();i++){
//          NTElectron el = allElec[i];
	 
//	 weight = 1.0;
	 
         IsSignal = false;
         if ( event->TMEME==2 || event->TMEME==10101 || event->TMEME==20200 ||event->TMEME==11 || event->TMEME==21100 ||
	      event->TMEME==11001 || event->TMEME==10110 ) IsSignal = true;
	      
    
// 	 MyhistoManager.FillHisto(PATElecPt, "PATElecPt",el.p4.Pt(),datasets[d].Name(),IsSignal,Dweight[ITypeMC]);
// 	 MyhistoManager.FillHisto(PATElecRelIso, "PATElecRelIso",el.CombinedRelIso03(),datasets[d].Name(),IsSignal,Dweight[ITypeMC]);
    
	 MyhistoManager.FillHisto(PFElecPt, "PFElecPt",el.p4.Pt(),datasets[d].Name(),IsSignal,Dweight[ITypeMC]);
	 MyhistoManager.FillHisto(PFElecNeutralHadIso, "PFElecNeutralHadIso",el.PATNeutralHadronIso,datasets[d].Name(),IsSignal,Dweight[ITypeMC]);
	 MyhistoManager.FillHisto(PFElecChargedHadIso, "PFElecChargedHadIso",el.PATChargedHadronIso,datasets[d].Name(),IsSignal,Dweight[ITypeMC]);
	 MyhistoManager.FillHisto(PFElecPhotonIso, "PFElecPhotonIso",el.PATPhotonIso,datasets[d].Name(),IsSignal,Dweight[ITypeMC]);
	 MyhistoManager.FillHisto(PFElecTrackIso, "PFElecTrackIso",el.PATTrackIso,datasets[d].Name(),IsSignal,Dweight[ITypeMC]);
	 MyhistoManager.FillHisto(PFElecRelIso, "PFElecRelIso",(el.PATTrackIso+el.PATChargedHadronIso+el.PATNeutralHadronIso)/el.p4.Pt(),datasets[d].Name(),IsSignal,Dweight[ITypeMC]);
         int isEcalDriven = (el.isEcalDriven ==1);
	 MyhistoManager.FillHisto(PFElecEcalDriven, "PFElecEcalDriven",isEcalDriven,datasets[d].Name(),IsSignal,Dweight[ITypeMC]);
         int isGsfEl = (el.isGsfElectron ==1);
	 MyhistoManager.FillHisto(PFElecGsfEl, "PFElecGsfEl",isGsfEl,datasets[d].Name(),IsSignal,Dweight[ITypeMC]);
	 MyhistoManager.FillHisto(PFElecD0, "PFElecD0",el.D0,datasets[d].Name(),IsSignal,Dweight[ITypeMC]);
         int isId90 = 0;
	 if ( el.elecIdWP90_r & 0x1 ) isId90 =1;  
	 MyhistoManager.FillHisto(PFElecId90, "PFElecId90",isId90,datasets[d].Name(),IsSignal,Dweight[ITypeMC]);
         int isConv = 1;
	 if (el.elecIdWP90_r & 0x4 ) isConv =0;  
	 MyhistoManager.FillHisto(PFElecConv, "PFElecConv",isConv,datasets[d].Name(),IsSignal,Dweight[ITypeMC]);
	 MyhistoManager.FillHisto(PFElecRelIsoRhoCorrected, "PFElecRelIsoRhoCorrected",el.RelIso03PFRhoCorrected(event->rho_PUUE_dens),datasets[d].Name(),IsSignal,Dweight[ITypeMC]);
	 MyhistoManager.FillHisto(PFElecRelIsoNeutralRhoCorrected, "PFElecRelIsoNeutralRhoCorrected",el.RelIso03PFNeutralRhoCorrected(event->rho_PUUE_dens),datasets[d].Name(),IsSignal,Dweight[ITypeMC]);

         if ( el.LeptonOrigin == 1 ) {
//    	    MyhistoManager.FillHisto(PATElecPt_FromW, "PATElecPt_FromW",el.p4.Pt(),datasets[d].Name(),IsSignal,Dweight[ITypeMC]);
// 	    MyhistoManager.FillHisto(PATElecRelIso_FromW, "PATElecRelIso_FromW",el.CombinedRelIso03(),datasets[d].Name(),IsSignal,Dweight[ITypeMC]);
    
	    MyhistoManager.FillHisto(PFElecPt_FromW, "PFElecPt_FromW",el.p4.Pt(),datasets[d].Name(),IsSignal,Dweight[ITypeMC]);
	    MyhistoManager.FillHisto(PFElecNeutralHadIso_FromW, "PFElecNeutralHadIso_FromW",el.PATNeutralHadronIso,datasets[d].Name(),IsSignal,Dweight[ITypeMC]);
	    MyhistoManager.FillHisto(PFElecChargedHadIso_FromW, "PFElecChargedHadIso_FromW",el.PATChargedHadronIso,datasets[d].Name(),IsSignal,Dweight[ITypeMC]);
	    MyhistoManager.FillHisto(PFElecPhotonIso_FromW, "PFElecPhotonIso_FromW",el.PATPhotonIso,datasets[d].Name(),IsSignal,Dweight[ITypeMC]);
	    MyhistoManager.FillHisto(PFElecTrackIso_FromW, "PFElecTrackIso_FromW",el.PATTrackIso,datasets[d].Name(),IsSignal,Dweight[ITypeMC]);
	    MyhistoManager.FillHisto(PFElecRelIso_FromW, "PFElecRelIso_FromW",(el.PATTrackIso+el.PATChargedHadronIso+el.PATNeutralHadronIso)/el.p4.Pt(),datasets[d].Name(),IsSignal,Dweight[ITypeMC]);
//    	    if (el.CombinedRelIso03()<0.15) { 
// 	       MyhistoManager.FillHisto(PATElecPt_FromW_Cut015, "PATElecPt_FromW_Cut015",el.p4.Pt(),datasets[d].Name(),IsSignal,Dweight[ITypeMC]);
// 	    }   
   	    if ((el.PATTrackIso+el.PATChargedHadronIso+el.PATNeutralHadronIso)/el.p4.Pt()<0.15) { 
	       MyhistoManager.FillHisto(PFElecPt_FromW_Cut015, "PFElecPt_FromW_Cut015",el.p4.Pt(),datasets[d].Name(),IsSignal,Dweight[ITypeMC]);
	    }   
         }

         if ( el.LeptonOrigin >= 100 ) {
//    	    MyhistoManager.FillHisto(PATElecPt_FromBC, "PATElecPt_FromBC",el.p4.Pt(),datasets[d].Name(),IsSignal,Dweight[ITypeMC]);
// 	    MyhistoManager.FillHisto(PATElecRelIso_FromBC, "PATElecRelIso_FromBC",el.CombinedRelIso03(),datasets[d].Name(),IsSignal,Dweight[ITypeMC]);
    
	    MyhistoManager.FillHisto(PFElecPt_FromBC, "PFElecPt_FromBC",el.p4.Pt(),datasets[d].Name(),IsSignal,Dweight[ITypeMC]);
	    MyhistoManager.FillHisto(PFElecNeutralHadIso_FromBC, "PFElecNeutralHadIso_FromBC",el.PATNeutralHadronIso,datasets[d].Name(),IsSignal,Dweight[ITypeMC]);
	    MyhistoManager.FillHisto(PFElecChargedHadIso_FromBC, "PFElecChargedHadIso_FromBC",el.PATChargedHadronIso,datasets[d].Name(),IsSignal,Dweight[ITypeMC]);
	    MyhistoManager.FillHisto(PFElecPhotonIso_FromBC, "PFElecPhotonIso_FromBC",el.PATPhotonIso,datasets[d].Name(),IsSignal,Dweight[ITypeMC]);
	    MyhistoManager.FillHisto(PFElecTrackIso_FromBC, "PFElecTrackIso_FromBC",el.PATTrackIso,datasets[d].Name(),IsSignal,Dweight[ITypeMC]);
	    MyhistoManager.FillHisto(PFElecRelIso_FromBC, "PFElecRelIso_FromBC",(el.PATTrackIso+el.PATChargedHadronIso+el.PATNeutralHadronIso)/el.p4.Pt(),datasets[d].Name(),IsSignal,Dweight[ITypeMC]);
//    	    if (el.CombinedRelIso03()<0.15) { 
// 	       MyhistoManager.FillHisto(PATElecPt_FromBC_Cut015, "PATElecPt_FromBC_Cut015",el.p4.Pt(),datasets[d].Name(),IsSignal,Dweight[ITypeMC]);
// 	    }   
   	    if ((el.PATTrackIso+el.PATChargedHadronIso+el.PATNeutralHadronIso)/el.p4.Pt()<0.15) { 
	       MyhistoManager.FillHisto(PFElecPt_FromBC_Cut015, "PFElecPt_FromBC_Cut015",el.p4.Pt(),datasets[d].Name(),IsSignal,Dweight[ITypeMC]);
	    }   
         }

//     std::cout<<"PFElecRelIso "<<(el.PATTrackIso+el.PATChargedHadronIso+el.PATNeutralHadronIso)/el.p4.Pt()<<std::endl;
//     std::cout<<"el.PATTrackIso "<<(el.PATTrackIso)<<std::endl;
//     std::cout<<"el.PATChargedHadronIso "<<(el.PATChargedHadronIso)<<std::endl;
//     std::cout<<"el.PATNeutralHadronIso "<<(el.PATNeutralHadronIso)<<std::endl;
//     std::cout<<"el.PATPhotonIso "<<(el.PATPhotonIso)<<std::endl;
//     if ( el.p4.Pt()>10 ) std::cout<<"el.LeptonOrigin "<<(el.LeptonOrigin)<<std::endl;

      }	 

       for(unsigned int i=0;i<selMuons.size();i++){
          NTMuon mu = selMuons[i];
    
//        vector<NTMuon> allMuon = event->muons;
//       for(unsigned int i=0;i<allMuon.size();i++){
//           NTMuon mu = allMuon[i];
    
//	 weight = 1.0;
	 
         IsSignal = false;
         if ( event->TMEME==20 || event->TMEME==11010 || event->TMEME==22000 ||event->TMEME==11 || event->TMEME==21100 ||
	      event->TMEME==11001 || event->TMEME==10110 ) IsSignal=true;
	      

// 	 MyhistoManager.FillHisto(PATMuonPt, "PATMuonPt",mu.p4.Pt(),datasets[d].Name(),IsSignal,Dweight[ITypeMC]);
// 	 MyhistoManager.FillHisto(PATMuonRelIso, "PATMuonRelIso",mu.RelIso03(),datasets[d].Name(),IsSignal,Dweight[ITypeMC]);

	 MyhistoManager.FillHisto(PFMuonPt, "PFMuonPt",mu.p4.Pt(),datasets[d].Name(),IsSignal,Dweight[ITypeMC]);
	 MyhistoManager.FillHisto(PFMuonNeutralHadIso, "PFMuonNeutralHadIso",mu.PATNeutralHadronIso,datasets[d].Name(),IsSignal,Dweight[ITypeMC]);
	 MyhistoManager.FillHisto(PFMuonChargedHadIso, "PFMuonChargedHadIso",mu.PATChargedHadronIso,datasets[d].Name(),IsSignal,Dweight[ITypeMC]);
	 MyhistoManager.FillHisto(PFMuonPhotonIso, "PFMuonPhotonIso",mu.PATPhotonIso,datasets[d].Name(),IsSignal,Dweight[ITypeMC]);
	 MyhistoManager.FillHisto(PFMuonTrackIso, "PFMuonTrackIso",mu.PATTrackIso,datasets[d].Name(),IsSignal,Dweight[ITypeMC]);
	 MyhistoManager.FillHisto(PFMuonRelIso, "PFMuonRelIso",(mu.PATTrackIso+mu.PATChargedHadronIso+mu.PATNeutralHadronIso)/mu.p4.Pt(),datasets[d].Name(),IsSignal,Dweight[ITypeMC]);
         int isMuon = 0 ;
	 if ( mu.MuonType>=100 ) isMuon += 1;
	 if ( (mu.MuonType-(mu.MuonType/10)*10) !=0 ) isMuon += 10 ;
	 if ( mu.MuonType>=100 && (mu.MuonType-(mu.MuonType/10)*10) !=0 ) isMuon += 100;
	 MyhistoManager.FillHisto(PFMuonType, "PFMuonType",isMuon,datasets[d].Name(),IsSignal,Dweight[ITypeMC]);
	 MyhistoManager.FillHisto(PFMuonChi2, "PFMuonChi2",mu.Chi2,datasets[d].Name(),IsSignal,Dweight[ITypeMC]);
	 MyhistoManager.FillHisto(PFMuonTrValHit, "PFMuonTrValHit",mu.NTrValidHits,datasets[d].Name(),IsSignal,Dweight[ITypeMC]);
	 MyhistoManager.FillHisto(PFMuonValHit, "PFMuonValHit",mu.NValidHits,datasets[d].Name(),IsSignal,Dweight[ITypeMC]);
	 MyhistoManager.FillHisto(PFMuonD0, "PFMuonD0",mu.D0Inner,datasets[d].Name(),IsSignal,Dweight[ITypeMC]);
	 if (selVertices.size()>0 ) MyhistoManager.FillHisto(PFMuonZvx, "PFMuonZvx",fabs( mu.vertex.Z() - selVertices[0].p3.Z()),datasets[d].Name(),IsSignal,Dweight[ITypeMC]);
	 MyhistoManager.FillHisto(PFMuonRelIsoRhoCorrected,"PFMuonRelIsoRhoCorrected",mu.RelIso03PFRhoCorrected(event->rho_PUUE_dens),datasets[d].Name(),IsSignal,Dweight[ITypeMC]);
	 MyhistoManager.FillHisto(PFMuonRelIsoNeutralRhoCorrected, "PFMuonRelIsoNeutralRhoCorrected",mu.RelIso03PFNeutralRhoCorrected(event->rho_PUUE_dens),datasets[d].Name(),IsSignal,Dweight[ITypeMC]);
    
         if ( mu.LeptonOrigin == 1 ) {
// 	    MyhistoManager.FillHisto(PATMuonPt_FromW, "PATMuonPt_FromW",mu.p4.Pt(),datasets[d].Name(),IsSignal,Dweight[ITypeMC]);
// 	    MyhistoManager.FillHisto(PATMuonRelIso_FromW, "PATMuonRelIso_FromW",mu.RelIso03(),datasets[d].Name(),IsSignal,Dweight[ITypeMC]);

	    MyhistoManager.FillHisto(PFMuonPt_FromW, "PFMuonPt_FromW",mu.p4.Pt(),datasets[d].Name(),IsSignal,Dweight[ITypeMC]);
	    MyhistoManager.FillHisto(PFMuonNeutralHadIso_FromW, "PFMuonNeutralHadIso_FromW",mu.PATNeutralHadronIso,datasets[d].Name(),IsSignal,Dweight[ITypeMC]);
	    MyhistoManager.FillHisto(PFMuonChargedHadIso_FromW, "PFMuonChargedHadIso_FromW",mu.PATChargedHadronIso,datasets[d].Name(),IsSignal,Dweight[ITypeMC]);
	    MyhistoManager.FillHisto(PFMuonPhotonIso_FromW, "PFMuonPhotonIso_FromW",mu.PATPhotonIso,datasets[d].Name(),IsSignal,Dweight[ITypeMC]);
	    MyhistoManager.FillHisto(PFMuonTrackIso_FromW, "PFMuonTrackIso_FromW",mu.PATTrackIso,datasets[d].Name(),IsSignal,Dweight[ITypeMC]);
	    MyhistoManager.FillHisto(PFMuonRelIso_FromW, "PFMuonRelIso_FromW",(mu.PATTrackIso+mu.PATChargedHadronIso+mu.PATNeutralHadronIso)/mu.p4.Pt(),datasets[d].Name(),IsSignal,Dweight[ITypeMC]);
            int isMuon = 0 ;
	    if ( mu.MuonType>=100 ) isMuon += 1;
	    if ( (mu.MuonType-(mu.MuonType/10)*10) !=0 ) isMuon += 10 ;
	    if ( mu.MuonType>=100 && (mu.MuonType-(mu.MuonType/10)*10) !=0 ) isMuon += 100;
	    MyhistoManager.FillHisto(PFMuonType_FromW, "PFMuonType_FromW",isMuon,datasets[d].Name(),IsSignal,Dweight[ITypeMC]);
	    
//    	    if (mu.RelIso03()<0.15) { 
// 	       MyhistoManager.FillHisto(PATMuonPt_FromW_Cut015, "PATMuonPt_FromW_Cut015",mu.p4.Pt(),datasets[d].Name(),IsSignal,Dweight[ITypeMC]);
// 	    }   
   	    if ((mu.PATTrackIso+mu.PATChargedHadronIso+mu.PATNeutralHadronIso)/mu.p4.Pt()<0.15) { 
	       MyhistoManager.FillHisto(PFMuonPt_FromW_Cut015, "PFMuonPt_FromW_Cut015",mu.p4.Pt(),datasets[d].Name(),IsSignal,Dweight[ITypeMC]);
	    }   
         }

         if ( mu.LeptonOrigin >= 100 ) {
// 	    MyhistoManager.FillHisto(PATMuonPt_FromBC, "PATMuonPt_FromBC",mu.p4.Pt(),datasets[d].Name(),IsSignal,Dweight[ITypeMC]);
// 	    MyhistoManager.FillHisto(PATMuonRelIso_FromBC, "PATMuonRelIso_FromBC",mu.RelIso03(),datasets[d].Name(),IsSignal,Dweight[ITypeMC]);

	    MyhistoManager.FillHisto(PFMuonPt_FromBC, "PFMuonPt_FromBC",mu.p4.Pt(),datasets[d].Name(),IsSignal,Dweight[ITypeMC]);
	    MyhistoManager.FillHisto(PFMuonNeutralHadIso_FromBC, "PFMuonNeutralHadIso_FromBC",mu.PATNeutralHadronIso,datasets[d].Name(),IsSignal,Dweight[ITypeMC]);
	    MyhistoManager.FillHisto(PFMuonChargedHadIso_FromBC, "PFMuonChargedHadIso_FromBC",mu.PATChargedHadronIso,datasets[d].Name(),IsSignal,Dweight[ITypeMC]);
	    MyhistoManager.FillHisto(PFMuonPhotonIso_FromBC, "PFMuonPhotonIso_FromBC",mu.PATPhotonIso,datasets[d].Name(),IsSignal,Dweight[ITypeMC]);
	    MyhistoManager.FillHisto(PFMuonTrackIso_FromBC, "PFMuonTrackIso_FromBC",mu.PATTrackIso,datasets[d].Name(),IsSignal,Dweight[ITypeMC]);
	    MyhistoManager.FillHisto(PFMuonRelIso_FromBC, "PFMuonRelIso_FromBC",(mu.PATTrackIso+mu.PATChargedHadronIso+mu.PATNeutralHadronIso)/mu.p4.Pt(),datasets[d].Name(),IsSignal,Dweight[ITypeMC]);
            int isMuon = 0 ;
	    if ( mu.MuonType>=100 ) isMuon += 1;
	    if ( (mu.MuonType-(mu.MuonType/10)*10) !=0 ) isMuon += 10 ;
	    if ( mu.MuonType>=100 && (mu.MuonType-(mu.MuonType/10)*10) !=0 ) isMuon += 100;
	    MyhistoManager.FillHisto(PFMuonType_FromBC, "PFMuonType_FromBC",isMuon,datasets[d].Name(),IsSignal,Dweight[ITypeMC]);

//    	    if (mu.RelIso03()<0.15) { 
// 	       MyhistoManager.FillHisto(PATMuonPt_FromBC_Cut015, "PATMuonPt_FromBC_Cut015",mu.p4.Pt(),datasets[d].Name(),IsSignal,Dweight[ITypeMC]);
// 	    }   
   	    if ((mu.PATTrackIso+mu.PATChargedHadronIso+mu.PATNeutralHadronIso)/mu.p4.Pt()<0.15) { 
	       MyhistoManager.FillHisto(PFMuonPt_FromBC_Cut015, "PFMuonPt_FromBC_Cut015",mu.p4.Pt(),datasets[d].Name(),IsSignal,Dweight[ITypeMC]);
	    }   
         }

//     std::cout<<"PFMuonRelIso "<<(mu.PATTrackIso+mu.PATChargedHadronIso+mu.PATNeutralHadronIso)/mu.p4.Pt()<<std::endl;
//     std::cout<<"mu.PATTrackIso "<<(mu.PATTrackIso)<<std::endl;
//     std::cout<<"mu.PATChargedHadronIso "<<(mu.PATChargedHadronIso)<<std::endl;
//     std::cout<<"mu.PATNeutralHadronIso "<<(mu.PATNeutralHadronIso)<<std::endl;
//     std::cout<<"mu.PATPhotonIso "<<(mu.PATPhotonIso)<<std::endl;
      }	 

	  
      
      
    }  // end of loop over evts
    
    
  }				// end of loop over the datasets 
  
  
// // PF electron
//     TH1F PFElecRelIsoEff_FromW_TTbarSig ("PFElecRelIsoEff_FromW_TTbarSig","PFElecRelIsoEff_FromW_TTbarSig",50,0.,1.0);
//     TH1F PFElecRelIsoEff_FromBC_TTbarBkg ("PFElecRelIsoEff_FromBC_TTbarBkg","PFElecRelIsoEff_FromBC_TTbarBkg",50,0.,1.0);
//     TH1F h1 ("h1","h1",50,0.,1.0);
//     TH1F h2 ("h2","h2",50,0.,1.0);
//     MyhistoManager.GetHisto(PFElecRelIso_FromW,"PFElecRelIso_FromW_TTbarSig",h1);
//     MyhistoManager.GetHisto(PFElecRelIso_FromBC,"PFElecRelIso_FromBC_TTbarBkg",h2);
//     
//     const int maxbin=200;
//     float X[maxbin];
//     float Y[maxbin];
//     EffCompute(h1,PFElecRelIsoEff_FromW_TTbarSig,h2,PFElecRelIsoEff_FromBC_TTbarBkg,X,Y);
//     TGraph* PFElecRelIsoPerf = new TGraph(h1.GetNbinsX(), X, Y);
//     PFElecRelIsoPerf->SetName("PFElecRelIsoPerf");
   
// // PAT electron
//     TH1F PATElecRelIsoEff_FromW_TTbarSig ("PATElecRelIsoEff_FromW_TTbarSig","PATElecRelIsoEff_FromW_TTbarSig",50,0.,1.0);
//     TH1F PATElecRelIsoEff_FromBC_TTbarBkg ("PATElecRelIsoEff_FromBC_TTbarBkg","PATElecRelIsoEff_FromBC_TTbarBkg",50,0.,1.0);
//     TH1F h3 ("h3","h3",50,0.,1.0);
//     TH1F h4 ("h4","h4",50,0.,1.0);
//     MyhistoManager.GetHisto(PATElecRelIso_FromW,"PATElecRelIso_FromW_TTbarSig",h3);
//     MyhistoManager.GetHisto(PATElecRelIso_FromBC,"PATElecRelIso_FromBC_TTbarBkg",h4);
//     
//     EffCompute(h3,PATElecRelIsoEff_FromW_TTbarSig,h4,PATElecRelIsoEff_FromBC_TTbarBkg,X,Y);
//     TGraph* PATElecRelIsoPerf = new TGraph(h3.GetNbinsX(), X, Y);
//     PATElecRelIsoPerf->SetName("PATElecRelIsoPerf");
   
// // PF muon
//     TH1F PFMuonRelIsoEff_FromW_TTbarSig ("PFMuonRelIsoEff_FromW_TTbarSig","PFMuonRelIsoEff_FromW_TTbarSig",50,0.,1.0);
//     TH1F PFMuonRelIsoEff_FromBC_TTbarBkg ("PFMuonRelIsoEff_FromBC_TTbarBkg","PFMuonRelIsoEff_FromBC_TTbarBkg",50,0.,1.0);
//     TH1F h5 ("h5","h5",50,0.,1.0);
//     TH1F h6 ("h6","h6",50,0.,1.0);
//     MyhistoManager.GetHisto(PFMuonRelIso_FromW,"PFMuonRelIso_FromW_TTbarSig",h5);
//     MyhistoManager.GetHisto(PFMuonRelIso_FromBC,"PFMuonRelIso_FromBC_TTbarBkg",h6);
//     
//     EffCompute(h5,PFMuonRelIsoEff_FromW_TTbarSig,h6,PFMuonRelIsoEff_FromBC_TTbarBkg,X,Y);
//     TGraph* PFMuonRelIsoPerf = new TGraph(h5.GetNbinsX(), X, Y);
//     PFMuonRelIsoPerf->SetName("PFMuonRelIsoPerf");
   
// // PAT muon
//     TH1F PATMuonRelIsoEff_FromW_TTbarSig ("PATMuonRelIsoEff_FromW_TTbarSig","PATMuonRelIsoEff_FromW_TTbarSig",50,0.,1.0);
//     TH1F PATMuonRelIsoEff_FromBC_TTbarBkg ("PATMuonRelIsoEff_FromBC_TTbarBkg","PATMuonRelIsoEff_FromBC_TTbarBkg",50,0.,1.0);
//     TH1F h7 ("h7","h7",50,0.,1.0);
//     TH1F h8 ("h8","h8",50,0.,1.0);
//     MyhistoManager.GetHisto(PATMuonRelIso_FromW,"PATMuonRelIso_FromW_TTbarSig",h7);
//     MyhistoManager.GetHisto(PATMuonRelIso_FromBC,"PATMuonRelIso_FromBC_TTbarBkg",h8);
//     
//     EffCompute(h7,PATMuonRelIsoEff_FromW_TTbarSig,h8,PATMuonRelIsoEff_FromBC_TTbarBkg,X,Y);
//     TGraph* PATMuonRelIsoPerf = new TGraph(h7.GetNbinsX(), X, Y);
//     PATMuonRelIsoPerf->SetName("PATMuonRelIsoPerf");
   
  
  if(verbosity>0) {
    cout<<"#########################"<<endl;
    cout<<" Write output root file "<<endl;
    cout<<"#########################"<<endl;
  }
  string ofilename = string("MyVar")+string("_")+ChannelName+string(".root");
  TFile* fout  = new TFile(ofilename.c_str(),"RECREATE");
     MyhistoManager.WriteMyHisto(TMEME,"all");
     
//      MyhistoManager.WriteMyHisto(PATElecPt,"all");
//      MyhistoManager.WriteMyHisto(PATElecRelIso,"all");
//      MyhistoManager.WriteMyHisto(PATMuonPt,"all");
//      MyhistoManager.WriteMyHisto(PATMuonRelIso,"all");
     
     MyhistoManager.WriteMyHisto(PFElecPt,"all");
     MyhistoManager.WriteMyHisto(PFElecNeutralHadIso,"all");
     MyhistoManager.WriteMyHisto(PFElecChargedHadIso,"all");
     MyhistoManager.WriteMyHisto(PFElecPhotonIso,"all");
     MyhistoManager.WriteMyHisto(PFElecTrackIso,"all");
     MyhistoManager.WriteMyHisto(PFElecRelIso,"all");
     MyhistoManager.WriteMyHisto(PFElecEcalDriven,"all");
     MyhistoManager.WriteMyHisto(PFElecGsfEl,"all");
     MyhistoManager.WriteMyHisto(PFElecD0,"all");
     MyhistoManager.WriteMyHisto(PFElecId90,"all");
     MyhistoManager.WriteMyHisto(PFElecConv,"all");
     MyhistoManager.WriteMyHisto(PFElecRelIsoRhoCorrected,"all");
     MyhistoManager.WriteMyHisto(PFElecRelIsoNeutralRhoCorrected,"all");
     
     MyhistoManager.WriteMyHisto(PFMuonPt,"all");
     MyhistoManager.WriteMyHisto(PFMuonNeutralHadIso,"all");
     MyhistoManager.WriteMyHisto(PFMuonChargedHadIso,"all");
     MyhistoManager.WriteMyHisto(PFMuonPhotonIso,"all");
     MyhistoManager.WriteMyHisto(PFMuonTrackIso,"all");
     MyhistoManager.WriteMyHisto(PFMuonRelIso,"all");
     MyhistoManager.WriteMyHisto(PFMuonType,"all");
     MyhistoManager.WriteMyHisto(PFMuonChi2,"all");
     MyhistoManager.WriteMyHisto(PFMuonTrValHit,"all");
     MyhistoManager.WriteMyHisto(PFMuonValHit,"all");
     MyhistoManager.WriteMyHisto(PFMuonD0,"all");
     MyhistoManager.WriteMyHisto(PFMuonZvx,"all");
     MyhistoManager.WriteMyHisto(PFMuonRelIsoRhoCorrected,"all");
     MyhistoManager.WriteMyHisto(PFMuonRelIsoNeutralRhoCorrected,"all");

//      MyhistoManager.WriteMyHisto(PATElecPt_FromW,"all");
//      MyhistoManager.WriteMyHisto(PATElecRelIso_FromW,"all");
//      MyhistoManager.WriteMyHisto(PATMuonPt_FromW,"all");
//      MyhistoManager.WriteMyHisto(PATMuonRelIso_FromW,"all");
//      MyhistoManager.WriteMyHisto(PATElecPt_FromW_Cut015,"all");
//      MyhistoManager.WriteMyHisto(PATMuonPt_FromW_Cut015,"all");
     
     MyhistoManager.WriteMyHisto(PFElecPt_FromW,"all");
     MyhistoManager.WriteMyHisto(PFElecNeutralHadIso_FromW,"all");
     MyhistoManager.WriteMyHisto(PFElecChargedHadIso_FromW,"all");
     MyhistoManager.WriteMyHisto(PFElecPhotonIso_FromW,"all");
     MyhistoManager.WriteMyHisto(PFElecTrackIso_FromW,"all");
     MyhistoManager.WriteMyHisto(PFElecRelIso_FromW,"all");
     MyhistoManager.WriteMyHisto(PFMuonPt_FromW,"all");
     MyhistoManager.WriteMyHisto(PFMuonNeutralHadIso_FromW,"all");
     MyhistoManager.WriteMyHisto(PFMuonChargedHadIso_FromW,"all");
     MyhistoManager.WriteMyHisto(PFMuonPhotonIso_FromW,"all");
     MyhistoManager.WriteMyHisto(PFMuonTrackIso_FromW,"all");
     MyhistoManager.WriteMyHisto(PFMuonRelIso_FromW,"all");
     MyhistoManager.WriteMyHisto(PFElecPt_FromW_Cut015,"all");
     MyhistoManager.WriteMyHisto(PFMuonPt_FromW_Cut015,"all");
     MyhistoManager.WriteMyHisto(PFMuonType_FromW,"all");
     
//      MyhistoManager.WriteMyHisto(PATElecPt_FromBC,"all");
//      MyhistoManager.WriteMyHisto(PATElecRelIso_FromBC,"all");
//      MyhistoManager.WriteMyHisto(PATMuonPt_FromBC,"all");
//      MyhistoManager.WriteMyHisto(PATMuonRelIso_FromBC,"all");
//      MyhistoManager.WriteMyHisto(PATElecPt_FromBC_Cut015,"all");
//      MyhistoManager.WriteMyHisto(PATMuonPt_FromBC_Cut015,"all");
     
     MyhistoManager.WriteMyHisto(PFElecPt_FromBC,"all");
     MyhistoManager.WriteMyHisto(PFElecNeutralHadIso_FromBC,"all");
     MyhistoManager.WriteMyHisto(PFElecChargedHadIso_FromBC,"all");
     MyhistoManager.WriteMyHisto(PFElecPhotonIso_FromBC,"all");
     MyhistoManager.WriteMyHisto(PFElecTrackIso_FromBC,"all");
     MyhistoManager.WriteMyHisto(PFElecRelIso_FromBC,"all");
     MyhistoManager.WriteMyHisto(PFMuonPt_FromBC,"all");
     MyhistoManager.WriteMyHisto(PFMuonNeutralHadIso_FromBC,"all");
     MyhistoManager.WriteMyHisto(PFMuonChargedHadIso_FromBC,"all");
     MyhistoManager.WriteMyHisto(PFMuonPhotonIso_FromBC,"all");
     MyhistoManager.WriteMyHisto(PFMuonTrackIso_FromBC,"all");
     MyhistoManager.WriteMyHisto(PFMuonRelIso_FromBC,"all");
     MyhistoManager.WriteMyHisto(PFElecPt_FromBC_Cut015,"all");
     MyhistoManager.WriteMyHisto(PFMuonPt_FromBC_Cut015,"all");
     MyhistoManager.WriteMyHisto(PFMuonType_FromBC,"all");
     
//      PFElecRelIsoEff_FromW_TTbarSig.Write();
//      PFElecRelIsoEff_FromBC_TTbarBkg.Write();
//      PFMuonRelIsoEff_FromW_TTbarSig.Write();
//      PFMuonRelIsoEff_FromBC_TTbarBkg.Write();
     
//      PATElecRelIsoEff_FromW_TTbarSig.Write();
//      PATElecRelIsoEff_FromBC_TTbarBkg.Write();
//      PATMuonRelIsoEff_FromW_TTbarSig.Write();
//      PATMuonRelIsoEff_FromBC_TTbarBkg.Write();
     
//      PFElecRelIsoPerf->Write();
//      PFMuonRelIsoEff_FromW_TTbarSig.Write();
//      PFMuonRelIsoEff_FromBC_TTbarBkg.Write();
//      PFMuonRelIsoPerf->Write();
     
//      PATElecRelIsoPerf->Write();
//      PATMuonRelIsoPerf->Write();
     
  fout->Close();
  
  delete fout;
  
  if(verbosity>0) {
    cout<<"#########################"<<endl;
    cout<<"    End of the program   "<<endl;
    cout<<"#########################"<<endl;
  }
  
  return (0);
  
  
}
int main ()
{
  cout<<"#########################"<<endl;
  cout<<"Beginning of the program"<<endl;
  cout<<"#########################"<<endl;
  
  //////////////////////
  // Initialisation
  //////////////////////
  float Luminosity = 0;
  float LumiError = 0;
  string PUWeightFileName;
  int DataType =0;

  string xmlFileName = string ("../../config/MatrixMethod_MC.xml");
  AnalysisEnvironmentLoader anaEl (xmlFileName);
  vector < Dataset > datasets;
  anaEl.LoadSamples(datasets);
  int verbosity = -1;
  anaEl.LoadGeneralInfo(DataType, Luminosity, LumiError, PUWeightFileName, verbosity);

  ////////////////////////////////
  // Matrix Method declaration
  ///////////////////////////////
  float looseIsoMM = 0.8; float tightIsoMMe = 0.17; float tightIsoMMmu = 0.2;
  unsigned int nbinsMM = 11; float lowEdgeMM = -0.5; float highEdgeMM = 10.5;
  MMEstimation MMestEE(datasets, looseIsoMM, tightIsoMMe, nbinsMM, lowEdgeMM, highEdgeMM, "EE");
  MMEstimation MMestMuMu(datasets, looseIsoMM, tightIsoMMe, nbinsMM, lowEdgeMM, highEdgeMM, "MuMu");

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

  //////////////////////////////////////////
  // Running the Matrix Method in fast way
  //////////////////////////////////////////
  //MMestEE.ReadMMFileForPullTest("MatrixMethod_OutPut_EE_MC_forNoWeight.root", 0.95, 0.2);
  MMestMuMu.ReadMMFileForPullTest("MatrixMethod_OutPut_MuMu_MC_NoWeight.root", 0.95, 0.2);

  /*vector<struct MMEpsilons> valMMEpsilons_EE;
  for(unsigned int bin_index = 0; bin_index < nbinsMM; bin_index++){
    struct MMEpsilons valMMEpsilonsTmp_EE;
    valMMEpsilonsTmp_EE.EpsilonSignal = 0.95;
    valMMEpsilonsTmp_EE.EpsilonSignalErr = 0.1;
    valMMEpsilonsTmp_EE.EpsilonFake = 0.2;
    valMMEpsilonsTmp_EE.EpsilonFakeErr = 0.1;
    valMMEpsilons_EE.push_back(valMMEpsilonsTmp_EE);
  }*/

  vector<struct MMEpsilons> valMMEpsilons_MuMu;
  for(unsigned int bin_index = 0; bin_index < nbinsMM; bin_index++){
    struct MMEpsilons valMMEpsilonsTmp_MuMu;
    valMMEpsilonsTmp_MuMu.EpsilonSignal = 0.95;
    valMMEpsilonsTmp_MuMu.EpsilonSignalErr = 0.1;
    valMMEpsilonsTmp_MuMu.EpsilonFake = 0.2;
    valMMEpsilonsTmp_MuMu.EpsilonFakeErr = 0.1;
    valMMEpsilons_MuMu.push_back(valMMEpsilonsTmp_MuMu);
  }


  float weight = datasets[0].NormFactor()*Luminosity;

  unsigned int NbIterations = 100000;
  bool doStatistical = true; bool doSystematic = false;
  
  /*MMestEE.RunTheMatrixMethodForEpsilonsTest(valMMEpsilons_EE, NbIterations, doStatistical, doSystematic, weight);
  MMestEE.PrintMMEstimated();
  MMestEE.WriteMMFileFastForPullTest("MatrixMethod_OutPut_EE_MC_forNoWeight.root","MatrixMethod_OutPut_EE_MC_Fast_EpsilonsTest.root", 0.95, 0.2);*/


  MMestMuMu.RunTheMatrixMethodForEpsilonsTest(valMMEpsilons_MuMu, NbIterations, doStatistical, doSystematic, weight);
  MMestMuMu.PrintMMEstimated();
  MMestMuMu.WriteMMFileFastForPullTest("MatrixMethod_OutPut_MuMu_MC_NoWeight.root","MatrixMethod_OutPut_MuMu_MC_Fast_EpsilonsTest.root", 0.95, 0.2);


  cout<<"#########################"<<endl;
  cout<<"    End of the program   "<<endl;
  cout<<"#########################"<<endl;

  return (0);
}
Exemple #9
0
void MatrixMethod (string xmlFileName, bool mc=true, string channel="") // MuMu or EE for data, do both for MC
{
  cout<<"#########################"<<endl;
  cout<<"Beginning of the program"<<endl;
  cout<<"#########################"<<endl;
  
  //////////////////////
  // Initialisation
  //////////////////////
  float Luminosity = 0;
  float LumiError = 0;
  string PUWeightFileName;
  int DataType = 0; 

  AnalysisEnvironmentLoader anaEL (xmlFileName);
  vector < Dataset > datasets;
  anaEL.LoadSamples (datasets); // now the list of datasets written in the xml file is known
  int verbosity = -1;

  // Matrix Method
  int MMselStepCut = 3;
  float looseIsoMM = 0.8; float tightIsoMMmu = 0.2; float tightIsoMMe = 0.17;
  unsigned int nbinsMM = 11; float lowEdgeMM = -0.5; float highEdgeMM = 10.5; // Histo nb events en fonction #jets
  MMEstimation MMestEE(datasets, looseIsoMM, tightIsoMMe, nbinsMM, lowEdgeMM, highEdgeMM, "EE"); 
  MMEstimation MMestMuMu(datasets,looseIsoMM, tightIsoMMmu, nbinsMM, lowEdgeMM, highEdgeMM, "MuMu"); 

  SSDiLeptonSelection sel;
  anaEL.LoadSSDiLeptonSelection (sel); // now the parameters for the selection are given to the selection
  anaEL.LoadGeneralInfo(DataType, Luminosity, LumiError, PUWeightFileName, verbosity );
  //Load for PU:
  if(mc) sel.GeneratePUWeight(PUWeightFileName);

  IPHCTree::NTEvent * event = 0;

  /*PUWeighting  thePUReweighter;
  TFile* file1  = new TFile(PUWeightFileName.c_str(),"READ"); 
  TH1D *  hPUData = 0;
  hPUData         = (TH1D*)file1->Get("pileup");
  TH1F *  hPUMC   = new TH1F("pileup_MC", "pileup_MC", hPUData->GetXaxis()->GetNbins(), hPUData->GetXaxis()->GetXmin(), hPUData->GetXaxis()->GetXmax() );
  TFile* file2  = new TFile( "../data/CrossSection_pileup.root" ,"READ");
  hPUMC           = (TH1F*)file2->Get("pileup_TTbarSig");
  // histo in data, histo in Mc, use out-of-time pu in the reweighting
  cout << "get MC histo  " << endl;
  thePUReweighter.setPUHisto( hPUData, hPUMC);
  cout << "set MC histo in thePUReweighter " << endl;
  thePUReweighter.setUseOutOfTimePU(false); // set to true to use out-of-time PU
  */
  
  //////////////////////
  //LOOP OVER THE DATASETS
  //////////////////////
  cout<<"#########################"<<endl;
  cout<<" Loop over the datasets  "<<endl;
  cout<<"#########################"<<endl;

  for (unsigned int d = 0; d < datasets.size (); d++) {
   datasets[d].eventTree ()->SetBranchAddress ("NTEvent",&event);
   cout << "dataset = " << datasets[d].Name() << endl;
   unsigned int nEvents = (int) (datasets[d].eventTree ()->GetEntries ());
    cout << "NEvents = " << nEvents << endl;
    float weight_init;
    weight_init = datasets[d].NormFactor()*Luminosity;
    cout << "weight_init = " << weight_init << endl;
    //LOOP OVER THE EVENTS
    for (unsigned int ievt = 0; ievt < nEvents; ievt++) {
      datasets[d].eventTree ()->GetEntry (ievt);
      IPHCTree::NTTransient::InitializeAfterReading(event); // Important line to read new format files
      //Load event for the selection
      sel.LoadEvent(event);
      if(ievt%10000 == 0) cout << "number of processed events " << ievt << endl;
      
      float weight = 1;
      
      if(mc){
      	
	//Manage DY samples to avoid overlaps
	double dileptInvMass = 0;
	if( (event->mc.zAndDecays).size() > 0){
          TLorentzVector dilept = (event->mc.zAndDecays)[0].p4_Lep1_gen + (event->mc.zAndDecays)[0].p4_Lep2_gen;
          dileptInvMass = dilept.M();
	}
	if(datasets[d].Name()=="Zjets" && dileptInvMass < 50) continue;
	if(datasets[d].Name()=="DYToMuMu_M-20"	   && (dileptInvMass > 50 || dileptInvMass < 20) ) continue;
	if(datasets[d].Name()=="DYToEE_M-20"        && (dileptInvMass > 50 || dileptInvMass < 20) ) continue;
	if(datasets[d].Name()=="DYToTauTau_M-20"    && (dileptInvMass > 50 || dileptInvMass < 20) ) continue;
	if(datasets[d].Name()=="DYToMuMu_M-10To20"   &&  dileptInvMass > 20) continue;
	if(datasets[d].Name()=="DYToEE_M-10To20"    &&  dileptInvMass > 20) continue;
	if(datasets[d].Name()=="DYToTauTau_M-10To20" &&  dileptInvMass > 20) continue;


        weight = weight_init;
        //float weight = weight_init*sel.GetPUWeight();
        /*if(thePUReweighter.getUseOutOfTimePU()){
           weight = weight_init*thePUReweighter.weight(event->pileup.intime_npu, event->general.runNb);
         }else{
	   weight = weight_init*thePUReweighter.weight(event->pileup.intime_npu);
       }*/
      }
      
      if(mc || (!mc && channel=="EE")) MMestEE.CountNSel(sel, datasets[d], "ee_ss", weight, MMselStepCut, &(event->mc));
      if(mc || (!mc && channel=="MuMu")) MMestMuMu.CountNSel(sel, datasets[d], "mumu_ss", weight, MMselStepCut, &(event->mc));
    } // end of loop over evts
  } // end of loop over the datasets 
  cout<<"#########################"<<endl;
  cout<<" Loop over the datasets  "<<endl;
  cout<<"#########################"<<endl;
  
  ////////////////////////////
  //  Computation after loops
  ////////////////////////////
  // Matrix Method estimation for ee and mumu cases 
  vector<struct MMEpsilons> valMMEpsilons; 
  for(unsigned int bin_index = 0; bin_index < nbinsMM; bin_index++){
    struct MMEpsilons valMMEpsilonsTmp;
    valMMEpsilonsTmp.EpsilonSignal = 0.99;
    valMMEpsilonsTmp.EpsilonSignalErr = 0.05;
    valMMEpsilonsTmp.EpsilonFake = 0.20;
    valMMEpsilonsTmp.EpsilonFakeErr = 0.10;
    valMMEpsilons.push_back(valMMEpsilonsTmp);
  }
  unsigned int NbIterations = 10000;
  bool doStatistical = true; bool doSystematic = true; bool doCorrections = false;
  string filename = "MatrixMethod_OutPut_";
  string mcname = "MC";
  if(!mc) mcname = "DATA";
  
  if(mc || (!mc && channel=="EE")) {
    MMestEE.RunTheMatrixMethod(valMMEpsilons, NbIterations, doStatistical, doSystematic, doCorrections);
    MMestEE.PrintMMEstimated();
    MMestEE.WriteMMFile((filename+"EE_"+mcname+".root").c_str());
  }
  if(mc || (!mc && channel=="MuMu")) {
    MMestMuMu.RunTheMatrixMethod(valMMEpsilons,  NbIterations, doStatistical, doSystematic, doCorrections);
    MMestMuMu.PrintMMEstimated();
    MMestMuMu.WriteMMFile((filename+"MuMu_"+mcname+".root").c_str());
  }

  cout<<"#########################"<<endl;
  cout<<"    End of the program   "<<endl;
  cout<<"#########################"<<endl;

  return;
}