Пример #1
0
void RunUEAnalysis(int nentries = 1E3,
		   const char* jetfile  = "/gpfs01/star/i_bnl/gdwebb/Run9/500GeVJets/Data/10103041/st_physics_10103041_raw_*.jets.root",
		   const char* skimfile = "/gpfs01/star/i_bnl/gdwebb/Run9/500GeVJets/Data/10103041/st_physics_10103041_raw_*.skim.root",
		   const char* uefile = "/gpfs01/star/i_bnl/gdwebb/Run9/500GeVJets/Data/10103041/st_physics_10103041_raw_*.ue.root",
		   const char* outfile = "test_jetQAData500Gev_10103041.root",
		   const Int_t  mEmbed = 0)
{
  cout << "jetfile  = " << jetfile  << endl;
  cout << "skimfile = " << skimfile << endl;
  cout << "uefile   = " << uefile << endl;
  cout << "outfile  = " << outfile << endl;
  const float area  =  4*TMath::Pi()/3;
  const float area2 =  2*TMath::Pi()/3;

  cout << "area: " << area << endl;

  // Open jet & skim files
  TChain* jetChain  = new TChain("jet");
  TChain* skimChain = new TChain("jetSkimTree");
  TChain* ueChain   = new TChain("ue");

  jetChain->Add(jetfile);
  skimChain->Add(skimfile);
  ueChain->Add(uefile);
  nentries = jetChain->GetEntriesFast();
  cout << "nentries = " << nentries << endl;
  
  // Set jet buffer
  StJetEvent* jetEvent = 0;
  jetChain->SetBranchAddress("AntiKtR060NHits12",&jetEvent);

  // Set skim buffer
  StJetSkimEvent* skimEvent = 0;
  skimChain->SetBranchAddress("skimEventBranch",&skimEvent); 

  StUeEvent* ueEvent_transP = 0;
  ueChain->SetBranchAddress("transP_AntiKtR060NHits12",&ueEvent_transP);

  StUeEvent* ueEvent_transM = 0;
  ueChain->SetBranchAddress("transM_AntiKtR060NHits12",&ueEvent_transM);

  StUeEvent* ueEvent_away = 0;
  ueChain->SetBranchAddress("away_AntiKtR060NHits12",&ueEvent_away);

  StUeEvent* ueEvent_toward = 0;
  ueChain->SetBranchAddress("toward_AntiKtR060NHits12",&ueEvent_toward);

  // Open output file for writing
  TFile* ofile = TFile::Open(outfile,"recreate");
  assert(ofile);

  //Book histograms
  TH1F* hleadingjetpTJP2 = new TH1F("hleadingjetpTJP2",";Leading jet p_{T} [GeV]",40,0,80);

  //Event Histograms
  TH2F* htransP_numTracksVsMaxJetpTJP2 = new TH2F("htransP_numTracksVsMaxJetpTJP2","transP; jet p_{T} [GeV]; <N_{ch}>/[#Delta#eta#Delta(#Delta#phi)]",40,0,80,320,0.,20.);
  TH2F* htransP_sumTrackpTVsMaxJetpTJP2 = new TH2F("htransP_sumTrackpTVsMaxJetpTJP2","transP;  jet p_{T} [GeV]; <#Sigmap_{T,ch}>/[#Delta#eta#Delta(#Delta#phi)]",40,0,80,320,0.,20.);

  TH2F* htransP_numTowersVsMaxJetpTJP2 = new TH2F("htransP_numTowersVsMaxJetpTJP2","transP; jet p_{T} [GeV]; <N_{0}>/[#Delta#eta#Delta(#Delta#phi)]",40,0,80,320,0.,20.);
  TH2F* htransP_sumTowerEtVsMaxJetpTJP2 = new TH2F("htransP_sumTowerEtVsMaxJetpTJP2","transP;  jet p_{T} [GeV]; <#SigmaE_{T}>/[#Delta#eta#Delta(#Delta#phi)]",40,0,80,320,0.,20.);
  TH2F* htransP_sumpTVsMaxJetpTJP2 = new TH2F("htransP_sumpTVsMaxJetpTJP2","transP; jet p_{T} [GeV]; <#Sigmap_{T}>/[#Delta#eta#Delta(#Delta#phi)]",40,0,80,320,0.,20.);

  TH2F* htransM_numTracksVsMaxJetpTJP2 = new TH2F("htransM_numTracksVsMaxJetpTJP2","transM; jet p_{T} [GeV]; <N_{ch}>/[#Delta#eta#Delta(#Delta#phi)]",40,0,80,320,0.,20.);
  TH2F* htransM_sumTrackpTVsMaxJetpTJP2 = new TH2F("htransM_sumTrackpTVsMaxJetpTJP2","transM;  jet p_{T} [GeV]; #Sigmatrack p_{T}",40,0,80,320,0.,20.);

  TH2F* htransM_numTowersVsMaxJetpTJP2 = new TH2F("htransM_numTowersVsMaxJetpTJP2","transM; jet p_{T} [GeV]; <N_{0}>/[#Delta#eta#Delta(#Delta#phi)]",40,0,80,320,0.,20.);
  TH2F* htransM_sumTowerEtVsMaxJetpTJP2 = new TH2F("htransM_sumTowerEtVsMaxJetpTJP2","transM;  jet p_{T} [GeV]; <#SigmaE_{T}>/[#Delta#eta#Delta(#Delta#phi)]",40,0,80,320,0.,20.);
  TH2F* htransM_sumpTVsMaxJetpTJP2 = new TH2F("htransM_sumpTVsMaxJetpTJP2","transM; jet p_{T} [GeV]; <#Sigmap_{T}>/[#Delta#eta#Delta(#Delta#phi)]",40,0,80,320,0.,20.);

  TH2F* htransverse_numTracksVsMaxJetpTJP2 = new TH2F("htransverse_numTracksVsMaxJetpTJP2","transverse; jet p_{T} [GeV]; <N_{ch}>/[#Delta#eta#Delta(#Delta#phi)]",40,0,80,320,0.,20.);
  TH2F* htransverse_sumTrackpTVsMaxJetpTJP2 = new TH2F("htransverse_sumTrackpTVsMaxJetpTJP2","transverse; jet p_{T} [GeV]; #Sigmatrack p_{T}",40,0,80,320,0.,20.);

  TH2F* htransverse_numTowersVsMaxJetpTJP2 = new TH2F("htransverse_numTowersVsMaxJetpTJP2","transverse; jet p_{T} [GeV]; <N_{0}>/[#Delta#eta#Delta(#Delta#phi)]",40,0,80,320,0.,20.);
  TH2F* htransverse_sumTowerEtVsMaxJetpTJP2 = new TH2F("htransverse_sumTowerEtVsMaxJetpTJP2","transverse; jet p_{T} [GeV]; <#SigmaE_{T}>/[#Delta#eta#Delta(#Delta#phi)]",40,0,80,320,0.,20.);
  TH2F* htransverse_sumpTVsMaxJetpTJP2 = new TH2F("htransverse_sumpTVsMaxJetpTJP2","transverse; jet p_{T} [GeV]; <#Sigmap_{T}>/[#Delta#eta#Delta(#Delta#phi)]",40,0,80,320,0.,20.);
  TH2F* htransverse_dPtVsMaxJetpTJP2 = new TH2F("htransverse_dPtVsMaxJetpTJP2","transverse; jet p_{T} [GeV]; <#Sigmap_{T}>/[#Delta#eta#Delta(#Delta#phi)] * (jet area)",40,0,80,320,0.,20.);

  TH2F* htransDiff_numTracksVsMaxJetpTJP2 = new TH2F("htransDiff_numTracksVsMaxJetpTJP2","transDiff; jet p_{T} [GeV]; <N_{ch}>/[#Delta#eta#Delta(#Delta#phi)]",40,0,80,320,0.,20.);
  TH2F* htransDiff_sumTrackpTVsMaxJetpTJP2 = new TH2F("htransDiff_sumTrackpTVsMaxJetpTJP2","transDiff; jet p_{T} [GeV]; #Sigmatrack p_{T}",40,0,80,320,0.,20.);
  TH2F* htransDiff_numTowersVsMaxJetpTJP2 = new TH2F("htransDiff_numTowersVsMaxJetpTJP2","transDiff; jet p_{T} [GeV]; <N_{0}>/[#Delta#eta#Delta(#Delta#phi)]",40,0,80,320,0.,20.);
  TH2F* htransDiff_sumTowerEtVsMaxJetpTJP2 = new TH2F("htransDiff_sumTowerEtVsMaxJetpTJP2","transDiff; jet p_{T} [GeV]; <#SigmaE_{T}>/[#Delta#eta#Delta(#Delta#phi)]",40,0,80,320,0.,20.);
  TH2F* htransDiff_sumpTVsMaxJetpTJP2 = new TH2F("htransDiff_sumpTVsMaxJetpTJP2","transDiff; jet p_{T} [GeV]; <#Sigmap_{T}>/[#Delta#eta#Delta(#Delta#phi)]",40,0,80,320,0.,20.);

  TH2F* htransMax_numTracksVsMaxJetpTJP2 = new TH2F("htransMax_numTracksVsMaxJetpTJP2","transMax; jet p_{T} [GeV]; <N_{ch}>/[#Delta#eta#Delta(#Delta#phi)]",40,0,80,320,0.,20.);
  TH2F* htransMax_sumTrackpTVsMaxJetpTJP2 = new TH2F("htransMax_sumTrackpTVsMaxJetpTJP2","transMax;  jet p_{T} [GeV]; <#Sigmap_{T,ch}>/[#Delta#eta#Delta(#Delta#phi)]",40,0,80,320,0.,20.);

  TH2F* htransMax_numTowersVsMaxJetpTJP2 = new TH2F("htransMax_numTowersVsMaxJetpTJP2","transMax; jet p_{T} [GeV]; <N_{0}>/[#Delta#eta#Delta(#Delta#phi)]",40,0,80,320,0.,20.);
  TH2F* htransMax_sumTowerEtVsMaxJetpTJP2 = new TH2F("htransMax_sumTowerEtVsMaxJetpTJP2","transMax;  jet p_{T} [GeV]; <#SigmaE_{T}>/[#Delta#eta#Delta(#Delta#phi)]",40,0,80,320,0.,20.);

  TH2F* htransMin_numTracksVsMaxJetpTJP2 = new TH2F("htransMin_numTracksVsMaxJetpTJP2","transMin; jet p_{T} [GeV]; <N_{ch}>/[#Delta#eta#Delta(#Delta#phi)]",40,0,80,320,0.,20.);
  TH2F* htransMin_sumTrackpTVsMaxJetpTJP2 = new TH2F("htransMin_sumTrackpTVsMaxJetpTJP2","transMin;  jet p_{T} [GeV]; <#Sigmap_{T,ch}>/[#Delta#eta#Delta(#Delta#phi)]",40,0,80,320,0.,20.);

  TH2F* htransMin_numTowersVsMaxJetpTJP2 = new TH2F("htransMin_numTowersVsMaxJetpTJP2","transMin; jet p_{T} [GeV]; <N_{0}>/[#Delta#eta#Delta(#Delta#phi)]",40,0,80,320,0.,20.);
  TH2F* htransMin_sumTowerEtVsMaxJetpTJP2 = new TH2F("htransMin_sumTowerEtVsMaxJetpTJP2","transMin;  jet p_{T} [GeV]; <#SigmaE_{T}>/[#Delta#eta#Delta(#Delta#phi)]",40,0,80,320,0.,20.);

  TH2F* htransMax_sumpTVsMaxJetpTJP2 = new TH2F("htransMax_sumpTVsMaxJetpTJP2", "transMax; jet p_{T} [GeV]; <#Sigmap_{T}>/[#Delta#eta#Delta(#Delta#phi)]",40,0,80,320,0.,20.);
  TH2F* htransMin_sumpTVsMaxJetpTJP2 = new TH2F("htransMin_sumpTVsMaxJetpTJP2", "transMin; jet p_{T} [GeV]; <#Sigmap_{T}>/[#Delta#eta#Delta(#Delta#phi)]",40,0,80,320,0.,20.);

  TH2F* haway_numTracksVsMaxJetpTJP2 = new TH2F("haway_numTracksVsMaxJetpTJP2","away; jet p_{T} [GeV]; <N_{ch}>/[#Delta#eta#Delta(#Delta#phi)]",40,0,80,320,0.,20.);
  TH2F* haway_sumTrackpTVsMaxJetpTJP2 = new TH2F("haway_sumTrackpTVsMaxJetpTJP2","away;  jet p_{T} [GeV]; <#Sigmap_{T,ch}>/[#Delta#eta#Delta(#Delta#phi)]",40,0,80,320,0.,20.);

  TH2F* haway_numTowersVsMaxJetpTJP2 = new TH2F("haway_numTowersVsMaxJetpTJP2","away; jet p_{T} [GeV]; <N_{0}>/[#Delta#eta#Delta(#Delta#phi)]",40,0,80,320,0.,20.);
  TH2F* haway_sumTowerEtVsMaxJetpTJP2 = new TH2F("haway_sumTowerEtVsMaxJetpTJP2","away;  jet p_{T} [GeV]; <#SigmaE_{T}>/[#Delta#eta#Delta(#Delta#phi)]",40,0,80,320,0.,20.);
  TH2F* haway_sumpTVsMaxJetpTJP2 = new TH2F("haway_sumpTVsMaxJetpTJP2","away; jet p_{T} [GeV]; <#Sigmap_{T}>/[#Delta#eta#Delta(#Delta#phi)]",40,0,80,320,0.,20.);

  TH2F* htoward_numTracksVsMaxJetpTJP2 = new TH2F("htoward_numTracksVsMaxJetpTJP2","toward; jet p_{T} [GeV]; <N_{ch}>/[#Delta#eta#Delta(#Delta#phi)]",40,0,80,320,0.,20.);
  TH2F* htoward_sumTrackpTVsMaxJetpTJP2 = new TH2F("htoward_sumTrackpTVsMaxJetpTJP2","toward;  jet p_{T} [GeV]; <#Sigmap_{T,ch}>/[#Delta#eta#Delta(#Delta#phi)]",40,0,80,320,0.,20.);

  TH2F* htoward_numTowersVsMaxJetpTJP2 = new TH2F("htoward_numTowersVsMaxJetpTJP2","toward; jet p_{T} [GeV]; <N_{0}>/[#Delta#eta#Delta(#Delta#phi)]",40,0,80,320,0.,20.);
  TH2F* htoward_sumTowerEtVsMaxJetpTJP2 = new TH2F("htoward_sumTowerEtVsMaxJetpTJP2","toward;  jet p_{T} [GeV]; <#SigmaE_{T}>/[#Delta#eta#Delta(#Delta#phi)]",40,0,80,320,0.,20.);
  TH2F* htoward_sumpTVsMaxJetpTJP2 = new TH2F("htoward_sumpTVsMaxJetpTJP2","toward; jet p_{T} [GeV]; <#Sigmap_{T}>/[#Delta#eta#Delta(#Delta#phi)]",40,0,80,320,0.,20.);

  Float_t sumtrackpT_transP, sumtowerEt_transP, sumpT_transP, sumtrackpT_transM, sumtowerEt_transM, sumpT_transM;
  Float_t numtracks_transP, numtowers_transP, numtracks_transM, numtowers_transM;
  Float_t sumtrackpT_transMax, sumtowerEt_transMax,sumpT_transMax, sumtrackpT_transMin, sumtowerEt_transMin, sumpT_transMin;
  Float_t numtracks_transMax, numtowers_transMax, numtracks_transMin, numtowers_transMin;
  Float_t sumtowerEt_away, sumtrackpT_away, sumpT_away, sumtrackpT_toward, sumtowerEt_toward, sumpT_toward;
  Float_t numtowers_away, numtracks_away, numtracks_toward, numtowers_toward;
  Float_t leadingJetpT;

  for (int iEntry = 0; iEntry < nentries; ++iEntry) {
    if (jetChain->GetEvent(iEntry) <= 0 || skimChain->GetEvent(iEntry) <= 0 || ueChain->GetEvent(iEntry) <= 0) break;
    // Should not be null
    assert(jetEvent && skimEvent && ueEvent_transP);
    
    // Enforce event synchronization
    assert(jetEvent->runId() == skimEvent->runId() && jetEvent->eventId() == skimEvent->eventId());
    assert(jetEvent->runId() == ueEvent_transP->runId() && jetEvent->eventId() == ueEvent_transP->eventId());
    
    if (iEntry % 1000 == 0) cout << iEntry << endl;
    //   hrunnumber->Fill(jetEvent->runId());
  
    //JP2 trigger
    StJetSkimTrig* trigJP2 = skimEvent->trigger(370621);
    if (!trigJP2) trigJP2 = skimEvent->trigger(230411);
    bool flagtrigJP2 = trigPass(trigJP2, mEmbed); // hardware and software triggers
    map<int,int> barrelJetPatches = skimEvent->barrelJetPatchesAboveTh(2);
    
    StJetVertex* vertex = jetEvent->vertex();
    StJetVertex* ue_vertex = ueEvent_transP->vertex();
    bool vertexBool = vertexPass(vertex, ue_vertex);
    if(!vertexBool) continue;
    
    StJetCandidate *leadingjet = findLeadingJet(vertex); // Leading jet from jet 
    if(leadingjet->pt() != ueEvent_transP->leadingJetpt()) continue;
    if(TMath::Abs(leadingjet->detEta()) > 0.5) { continue;}
    if(leadingjet->rt() > 0.9){continue;} 
    bool trackpT_high = hightrackpT(leadingjet);
    if(trackpT_high) continue;
    
    Bool_t geoFlagJP2  = matchedToJetPatch(leadingjet,barrelJetPatches); // Geo Flag

    leadingJetpT = leadingjet->pt(); //Define the leading jet pT 
    if( flagtrigJP2 && geoFlagJP2){//did, should, and geo trigs fired 

      hleadingjetpTJP2->Fill(leadingJetpT); 
      
      //-----------------Transverse Plus ------------------------
      sumtrackpT_transP = ueEvent_transP->sumTrackPt();
      sumtowerEt_transP = ueEvent_transP->sumTowerPt();
      sumpT_transP      = ueEvent_transP->sumPt();

      numtracks_transP = ueEvent_transP->numberOfTracks();
      numtowers_transP = ueEvent_transP->numberOfTowers();

      //track transP
      htransP_numTracksVsMaxJetpTJP2->Fill(leadingJetpT,numtracks_transP/area2);
      htransP_sumTrackpTVsMaxJetpTJP2->Fill(leadingJetpT,sumtrackpT_transP/area2);

      //tower transP
      htransP_numTowersVsMaxJetpTJP2->Fill(leadingJetpT,numtowers_transP/area2);
      htransP_sumTowerEtVsMaxJetpTJP2->Fill(leadingJetpT,sumtowerEt_transP/area2);

      htransP_sumpTVsMaxJetpTJP2->Fill(leadingJetpT, sumpT_transP/area2);
      // ------------------- End Of Trans Plus --------------------------

      //-----------------Transverse Minus ------------------------
      sumtrackpT_transM = ueEvent_transM->sumTrackPt();
      sumtowerEt_transM = ueEvent_transM->sumTowerPt(); 
      sumpT_transM      = ueEvent_transM->sumPt();

      numtracks_transM = ueEvent_transM->numberOfTracks();
      numtowers_transM = ueEvent_transM->numberOfTowers();
      
      //track transM
      htransM_numTracksVsMaxJetpTJP2->Fill(leadingJetpT,numtracks_transM/area2);
      htransM_sumTrackpTVsMaxJetpTJP2->Fill(leadingJetpT,sumtrackpT_transM/area2);
      
      //tower transM
      htransM_numTowersVsMaxJetpTJP2->Fill(leadingJetpT,numtowers_transM/area2);
      htransM_sumTowerEtVsMaxJetpTJP2->Fill(leadingJetpT,sumtowerEt_transM/area2);

      htransM_sumpTVsMaxJetpTJP2->Fill(leadingJetpT, sumpT_transM/area2);
      // ------------------- End Of Trans Minus --------------------------
      
      //----------------Transverse Region------------------------

      //track transverse
      htransverse_numTracksVsMaxJetpTJP2->Fill(leadingJetpT,(numtracks_transP + numtracks_transM)/area);
      htransverse_sumTrackpTVsMaxJetpTJP2->Fill(leadingJetpT,(sumtrackpT_transP + sumtrackpT_transM)/area);
      
      //tower transverse
      htransverse_numTowersVsMaxJetpTJP2->Fill(leadingJetpT,(numtowers_transP + numtowers_transM)/area);
      htransverse_sumTowerEtVsMaxJetpTJP2->Fill(leadingJetpT,(sumtowerEt_transP + sumtowerEt_transM)/area);

      htransverse_sumpTVsMaxJetpTJP2->Fill(leadingJetpT, (sumpT_transP + sumpT_transM)/area);

      double jet_area = leadingjet->area();
      htransverse_dPtVsMaxJetpTJP2->Fill(leadingJetpT, (sumpT_transP + sumpT_transM) / area * jet_area);

      //--------------End of Transverse-------------------------      

      htransDiff_numTracksVsMaxJetpTJP2->Fill(leadingJetpT, fabs(numtracks_transP - numtracks_transM)/area);
      htransDiff_sumTrackpTVsMaxJetpTJP2->Fill(leadingJetpT, fabs(sumtrackpT_transP - sumtrackpT_transM)/area);

      htransDiff_numTowersVsMaxJetpTJP2->Fill(leadingJetpT, fabs(numtowers_transP - numtowers_transM)/area);
      htransDiff_sumTowerEtVsMaxJetpTJP2->Fill(leadingJetpT, fabs(sumtowerEt_transP - sumtowerEt_transM)/area);

      htransDiff_sumpTVsMaxJetpTJP2->Fill(leadingJetpT, fabs(sumpT_transP - sumpT_transM)/area);

      //----------------- Away Region ------------------------
      sumtrackpT_away = sumtowerEt_away = 0; 
      numtracks_away = numtowers_away = 0; 
      sumpT_away = 0;

      sumtrackpT_away = ueEvent_away->sumTrackPt();
      sumtowerEt_away = ueEvent_away->sumTowerPt(); 
      sumpT_away      = ueEvent_away->sumPt();
     
      numtracks_away = ueEvent_away->numberOfTracks();
      numtowers_away = ueEvent_away->numberOfTowers();
      
      //track away
      haway_numTracksVsMaxJetpTJP2->Fill(leadingJetpT,numtracks_away/area);
      haway_sumTrackpTVsMaxJetpTJP2->Fill(leadingJetpT,sumtrackpT_away/area);
      
      //tower away
      haway_numTowersVsMaxJetpTJP2->Fill(leadingJetpT,numtowers_away/area);
      haway_sumTowerEtVsMaxJetpTJP2->Fill(leadingJetpT,sumtowerEt_away/area);

      haway_sumpTVsMaxJetpTJP2->Fill(leadingJetpT,sumpT_away/area);
      // ------------------- End Of Away --------------------------

      //----------------- Toward Region ---------------------------
      sumtrackpT_toward = sumtowerEt_toward = 0;      
      numtracks_toward  = numtowers_toward  = 0;      
      sumpT_toward = 0;

      sumtrackpT_toward = ueEvent_toward->sumTrackPt();
      sumtowerEt_toward = ueEvent_toward->sumTowerPt(); 
      sumpT_toward      = ueEvent_toward->sumPt();

      numtracks_toward = ueEvent_toward->numberOfTracks();
      numtowers_toward = ueEvent_toward->numberOfTowers(); 

      //track toward
      htoward_numTracksVsMaxJetpTJP2->Fill(leadingJetpT,numtracks_toward/area);
      htoward_sumTrackpTVsMaxJetpTJP2->Fill(leadingJetpT,sumtrackpT_toward/area);
      
      //tower toward
      htoward_numTowersVsMaxJetpTJP2->Fill(leadingJetpT,numtowers_toward/area);
      htoward_sumTowerEtVsMaxJetpTJP2->Fill(leadingJetpT,sumtowerEt_toward/area);

      htoward_sumpTVsMaxJetpTJP2->Fill(leadingJetpT, sumpT_toward/area);
      // ------------------- End Of Toward --------------------------
      
    
      //--------- Sum Track pT Trans Max and Trans Min -------------
      if (sumtrackpT_transP == sumtrackpT_transM) {
         cout << "sumtrackpT_transP = " << sumtrackpT_transP << "\t"
              << "sumtrackpT_transM = " << sumtrackpT_transM << endl;
      }
      sumtrackpT_transMax =  std::max(sumtrackpT_transP, sumtrackpT_transM);
      sumtrackpT_transMin =  std::min(sumtrackpT_transP, sumtrackpT_transM);

      htransMax_sumTrackpTVsMaxJetpTJP2->Fill(leadingJetpT,sumtrackpT_transMax/area2);
      htransMin_sumTrackpTVsMaxJetpTJP2->Fill(leadingJetpT,sumtrackpT_transMin/area2);     
      //---------------------------------------------------      
      

      //--------- Num Tracks Trans Max and Trans Min -------------
      if (numtracks_transP == numtracks_transM) {
         cout << "numtracks_transP = " << numtracks_transP << "\t"
              << "numtracks_transM = " << numtracks_transM << endl;
      }
      numtracks_transMax = std::max(numtracks_transP, numtracks_transM);
      numtracks_transMin = std::min(numtracks_transP, numtracks_transM);
      
      htransMax_numTracksVsMaxJetpTJP2->Fill(leadingJetpT,numtracks_transMax/area2);
      htransMin_numTracksVsMaxJetpTJP2->Fill(leadingJetpT,numtracks_transMin/area2);
      // -----------------------------------------------------------
    
      //--------- Sum Tower Et Trans Max and Trans Min -------------
      if (sumtowerEt_transP == sumtowerEt_transM) {
         cout << "sumtowerEt_transP = " << sumtowerEt_transP << "\t"
              << "sumtowerEt_transM = " << sumtowerEt_transM << endl;
      }
      sumtowerEt_transMax = std::max(sumtowerEt_transP, sumtowerEt_transM);
      sumtowerEt_transMin = std::min(sumtowerEt_transP, sumtowerEt_transM);

      htransMax_sumTowerEtVsMaxJetpTJP2->Fill(leadingJetpT,sumtowerEt_transMax/area2);
      htransMin_sumTowerEtVsMaxJetpTJP2->Fill(leadingJetpT,sumtowerEt_transMin/area2);
      //----------------------------------------------------------

      //--------- Num Towers Trans Max and Trans Min -------------
      if (numtowers_transP == numtowers_transM) {
         cout << "numtowers_transP = " << numtowers_transP << "\t"
              << "numtowers_transM = " << numtowers_transM << endl;
      }
      numtowers_transMax = std::max(numtowers_transP, numtowers_transM);
      numtowers_transMin = std::min(numtowers_transP, numtowers_transM);

      htransMax_numTowersVsMaxJetpTJP2->Fill(leadingJetpT,numtowers_transMax/area2);
      htransMin_numTowersVsMaxJetpTJP2->Fill(leadingJetpT,numtowers_transMin/area2);
      // -------------------------------------------------------


      //--------- Sum pT Trans Max and Trans Min -------------
      if (sumpT_transP == sumpT_transM) {
         cout << "sumpT_transP = " << sumpT_transP << "\t"
              << "sumpT_transM = " << sumpT_transM << endl;
      }
      sumpT_transMax = std::max(sumpT_transP, sumpT_transM);
      sumpT_transMin = std::min(sumpT_transP, sumpT_transM);

      htransMax_sumpTVsMaxJetpTJP2->Fill(leadingJetpT,sumpT_transMax/area2);
      htransMin_sumpTVsMaxJetpTJP2->Fill(leadingJetpT,sumpT_transMin/area2);     
      //---------------------------------------------------      
      
    }// End of JP2 if statement 
  }//End of Event Loop
  ofile->Write();
  ofile->Close();
}
void analyzePFvsCaloJetsppData(std::vector<std::string> urls, const char *outname = "eventObjects.root", Long64_t nentries = 20, Int_t firstF = -1, Int_t lastF = -1) {

  // std::vector<std::string> urls = CollectFiles(list);

  // Printf("anaFile: %d",anaFile);
  
  std::cout << "nfiles: " << urls.size() << std::endl;
  for (auto i = urls.begin(); i != urls.end(); ++i)
    std::cout << *i << std::endl;

  size_t firstFile = 0;
  size_t lastFile = urls.size();

  if(firstF>-1) {
    firstFile = (size_t)firstF;
    lastFile = (size_t)lastF;
  }
  std::cout << "firstFile: " << firstFile << "  lastFile: " << lastFile << std::endl;
  
  //add files to chain
  TChain *chain = NULL;
  chain = new TChain("hiEvtAnalyzer/HiTree");
  for(size_t i=firstFile; i<lastFile; i++) chain->Add(urls[i].c_str());
  Printf("hiTree done");

  TChain *hltTree = new TChain("hltanalysis/HltTree");
  for(size_t i=firstFile; i<lastFile; i++) hltTree->Add(urls[i].c_str());
  chain->AddFriend(hltTree);
  Printf("hltTree done");

  TChain *skimTree = new TChain("skimanalysis/HltTree");
  for(size_t i=firstFile; i<lastFile; i++) skimTree->Add(urls[i].c_str());
  chain->AddFriend(skimTree);
  Printf("skimTree done");

  //TChain *pileupTree = new TChain("pileup/tree");
  // for(size_t i=firstFile; i<lastFile; i++) pileupTree->Add(urls[i].c_str());
  //chain->AddFriend(pileupTree);
  
  TChain *pfTree = new TChain("pfcandAnalyzer/pfTree");
  for(size_t i=firstFile; i<lastFile; i++) pfTree->Add(urls[i].c_str());
  chain->AddFriend(pfTree);
  Printf("pfTree done");
  
  // TChain *muTree = new TChain("hltMuTree/HLTMuTree");
  // for(size_t i=firstFile; i<lastFile; i++) muTree->Add(urls[i].c_str());
  // chain->AddFriend(muTree);
  // Printf("muTree done");

  TChain *pfJetTree = new TChain("ak4PFJetAnalyzer/t");
  for(size_t i=firstFile; i<lastFile; i++) pfJetTree->Add(urls[i].c_str());
  chain->AddFriend(pfJetTree);
  Printf("pfJetTree done");

  TChain *caloJetTree = new TChain("ak4CaloJetAnalyzer/t");
  for(size_t i=firstFile; i<lastFile; i++) caloJetTree->Add(urls[i].c_str());
  //chain->AddFriend(caloJetTree);
  Printf("caloJetTree done");

  // TChain *genTree = new TChain("HiGenParticleAna/hi");
  // for(size_t i=firstFile; i<lastFile; i++) genTree->Add(urls[i].c_str());
  // chain->AddFriend(genTree);
  // Printf("genTree done");
  
  TList *fEventObjects = new TList();


  //---------------------------------------------------------------
  // producers
  //
  hiEventProducer *p_evt = new hiEventProducer("hiEvtProd");
  p_evt->SetInput(chain);
  p_evt->SetHIEventContName("hiEventContainer");
  p_evt->SetEventObjects(fEventObjects);

  pfParticleProducer *p_pf = new pfParticleProducer("pfPartProd");
  p_pf->SetInput(chain);
  p_pf->SetpfParticlesName("pfParticles");
  p_pf->SetEventObjects(fEventObjects);

  lwJetFromForestProducer *p_pfJet = new lwJetFromForestProducer("lwJetForestProd");
  p_pfJet->SetInput(pfJetTree);//chain);
  p_pfJet->SetJetContName("akt4PF");
  p_pfJet->SetGenJetContName("");//akt4Gen");
  p_pfJet->SetEventObjects(fEventObjects);
  p_pfJet->SetRadius(0.4);
  
  lwJetFromForestProducer *p_caloJet = new lwJetFromForestProducer("lwJetForestProd");
  p_caloJet->SetInput(caloJetTree);
  p_caloJet->SetJetContName("akt4Calo");
  p_caloJet->SetGenJetContName("");
  p_caloJet->SetEventObjects(fEventObjects);
  p_caloJet->SetRadius(0.4);
  
  //---------------------------------------------------------------
  //analysis modules
  //

  //handler to which all modules will be added
  anaBaseTask *handler = new anaBaseTask("handler","handler");

  anaJetMatching *matchingPFCaloJet = new anaJetMatching("matchingPFCaloJet","matchingPFCaloJet");
  matchingPFCaloJet->ConnectEventObject(fEventObjects);
  matchingPFCaloJet->SetHiEvtName("hiEventContainer");
  matchingPFCaloJet->DoPFJet80(true);
  matchingPFCaloJet->DoExcludePhoton30(true);
  matchingPFCaloJet->SetJetsNameBase("akt4PF");
  matchingPFCaloJet->SetJetsNameTag("akt4Calo");
  matchingPFCaloJet->SetNCentBins(1);
  handler->Add(matchingPFCaloJet);  
  
  anaPFvsCaloJet *anaPFCaloJet = new anaPFvsCaloJet("anaPFvsCaloJet","anaPFvsCaloJet");
  anaPFCaloJet->ConnectEventObject(fEventObjects);
  anaPFCaloJet->SetHiEvtName("hiEventContainer");
  anaPFCaloJet->DoPFJet80(true);
  anaPFCaloJet->DoExcludePhoton30(true);
  anaPFCaloJet->SetPFJetsName("akt4PF");
  anaPFCaloJet->SetCaloJetsName("akt4Calo");
  handler->Add(anaPFCaloJet);

  anaPFvsCaloJet *anaCaloPFJet = new anaPFvsCaloJet("anaCalovsPFJet","anaCalovsPFJet");
  anaCaloPFJet->ConnectEventObject(fEventObjects);
  anaCaloPFJet->SetHiEvtName("hiEventContainer");
  anaCaloPFJet->DoPFJet80(true);
  anaCaloPFJet->DoExcludePhoton30(true);
  anaCaloPFJet->SetPFJetsName("akt4Calo");
  anaCaloPFJet->SetCaloJetsName("akt4PF");
  handler->Add(anaCaloPFJet);

  /*
  //PF-GEN matching
  anaJetMatching *matchingGenPFJet = new anaJetMatching("matchingGenPFJet","matchingGenPFJet");
  matchingGenPFJet->ConnectEventObject(fEventObjects);
  matchingGenPFJet->SetHiEvtName("");
  matchingGenPFJet->SetJetsNameBase("akt4Gen");
  matchingGenPFJet->SetJetsNameTag("akt4PF");
  matchingGenPFJet->SetNCentBins(1);
  handler->Add(matchingGenPFJet);  
  
  anaPFvsCaloJet *anaGenPFJet = new anaPFvsCaloJet("anaGenVsPFJet","anaGenVsPFJet");
  anaGenPFJet->ConnectEventObject(fEventObjects);
  anaGenPFJet->SetHiEvtName("");
  anaGenPFJet->SetPFJetsName("akt4Gen");
  anaGenPFJet->SetCaloJetsName("akt4PF");
  handler->Add(anaGenPFJet);
  */
  
  //---------------------------------------------------------------
  //Event loop
  //---------------------------------------------------------------	  
  Long64_t entries_tot =  chain->GetEntriesFast(); //93064
  if(nentries<0) nentries = chain->GetEntries();
  // Long64_t nentries = 20;//chain->GetEntriesFast();
  Printf("nentries: %lld  tot: %lld",nentries,entries_tot);
  for (Long64_t jentry=0; jentry<nentries;jentry++) {
    if (jentry%10000==0) Printf("Processing event %d  %d",(int)(jentry), (int)(nentries));
    //Run producers
    // Printf("produce hiEvent");
    p_evt->Run(jentry);   //hi event properties

    //Printf("produce pf particles");
    //  p_pf->Run(jentry);    //pf particles
    p_pfJet->Run(jentry); //jets
    p_caloJet->Run(jentry); //jets
    
    //Execute all analysis tasks
    handler->ExecuteTask();
  }
    
  fEventObjects->Print();

  TFile *out = new TFile(outname,"RECREATE");
  TList *tasks = handler->GetListOfTasks();
  TIter next(tasks);
  anaBaseTask *obj;
  while ((obj = dynamic_cast<anaBaseTask*>(next()) ))
    if(obj->GetOutput()) obj->GetOutput()->Write(obj->GetName(),TObject::kSingleKey);
  
  out->Write();
  out->Close();
  
}
Пример #3
0
void SkimRegression(TString process="ZnnH125", Long64_t skimentries=1000000000)
{
    //gROOT->LoadMacro("HelperFunctions.h" );  // make functions visible to TTreeFormula
    gROOT->SetBatch(1);

    TChain * chain  = new TChain("tree");
    TString fname   = "";
    TString dijet   = "DiJetPt_";
#ifndef XROOTD
    //TString dirMC   = "dcache:/pnfs/cms/WAX/resilient/jiafu/ZnunuHbb/" + tagMC + "/";
    //TString dirData = "dcache:/pnfs/cms/WAX/resilient/jiafu/ZnunuHbb/" + tagData + "/";
    TString dirMC   = "dcache:/pnfs/cms/WAX/11/store/user/lpchbb/apana/" + tagMC + "/";
    TString dirData = "dcache:/pnfs/cms/WAX/11/store/user/lpchbb/apana/" + tagData + "/";
#else
    TString dirMC   = "root://xrootd.ba.infn.it//store/user/arizzi/" + tagMC + "/";
    TString dirData = "root://xrootd.ba.infn.it//store/user/arizzi/" + tagData + "/";
#endif
    TString outdir  = "skim_ZnnH_regression/";
    TString prefix  = "skim_";
    TString suffix  = ".root";

    // ZbbHinv
    if (process == "ZbbHinv105") {
        fname = dirMC + dijet + "ZH_ZToBB_HToInv_M-105_8TeV_pythia6" + suffix;
        chain->Add(fname);
    } else if (process == "ZbbHinv115") {
        fname = dirMC + dijet + "ZH_ZToBB_HToInv_M-115_8TeV_pythia6" + suffix;
        chain->Add(fname);
    } else if (process == "ZbbHinv125") {
        fname = dirMC + dijet + "ZH_ZToBB_HToInv_M-125_8TeV_pythia6" + suffix;
        chain->Add(fname);
    } else if (process == "ZbbHinv135") {
        fname = dirMC + dijet + "ZH_ZToBB_HToInv_M-135_8TeV_pythia6" + suffix;
        chain->Add(fname);
    } else if (process == "ZbbHinv145") {
        fname = dirMC + dijet + "ZH_ZToBB_HToInv_M-145_8TeV_pythia6" + suffix;
        chain->Add(fname);
    } else if (process == "ZbbHinv150") {
        fname = dirMC + dijet + "ZH_ZToBB_HToInv_M-150_8TeV_pythia6" + suffix;
        chain->Add(fname);

    // ZnnH
    } else if (process == "ZnnH110") {
        fname = dirMC + dijet + "ZH_ZToNuNu_HToBB_M-110_8TeV-powheg-herwigpp" + suffix;
        chain->Add(fname);
    } else if (process == "ZnnH115") {
        fname = dirMC + dijet + "ZH_ZToNuNu_HToBB_M-115_8TeV-powheg-herwigpp" + suffix;
        chain->Add(fname);
    } else if (process == "ZnnH120") {
        fname = dirMC + dijet + "ZH_ZToNuNu_HToBB_M-120_8TeV-powheg-herwigpp" + suffix;
        chain->Add(fname);
    } else if (process == "ZnnH125") {
        fname = dirMC + dijet + "ZH_ZToNuNu_HToBB_M-125_8TeV-powheg-herwigpp" + suffix;
        chain->Add(fname);
    } else if (process == "ZnnH130") {
        fname = dirMC + dijet + "ZH_ZToNuNu_HToBB_M-130_8TeV-powheg-herwigpp" + suffix;
        chain->Add(fname);
    } else if (process == "ZnnH135") {
        fname = dirMC + dijet + "ZH_ZToNuNu_HToBB_M-135_8TeV-powheg-herwigpp" + suffix;
        chain->Add(fname);
    } else if (process == "ZnnH140") {
        fname = dirMC + dijet + "ZH_ZToNuNu_HToBB_M-140_8TeV-powheg-herwigpp" + suffix;
        chain->Add(fname);
    } else if (process == "ZnnH145") {
        fname = dirMC + dijet + "ZH_ZToNuNu_HToBB_M-145_8TeV-powheg-herwigpp" + suffix;
        chain->Add(fname);
    } else if (process == "ZnnH150") {
        fname = dirMC + dijet + "ZH_ZToNuNu_HToBB_M-150_8TeV-powheg-herwigpp" + suffix;
        chain->Add(fname);

    // WlnH
    } else if (process == "WlnH110") {
        fname = dirMC + dijet + "WH_WToLNu_HToBB_M-110_8TeV-powheg-herwigpp" + suffix;
        chain->Add(fname);
    } else if (process == "WlnH115") {
        fname = dirMC + dijet + "WH_WToLNu_HToBB_M-115_8TeV-powheg-herwigpp" + suffix;
        chain->Add(fname);
    } else if (process == "WlnH120") {
        fname = dirMC + dijet + "WH_WToLNu_HToBB_M-120_8TeV-powheg-herwigpp" + suffix;
        chain->Add(fname);
    } else if (process == "WlnH125") {
        fname = dirMC + dijet + "WH_WToLNu_HToBB_M-125_8TeV-powheg-herwigpp" + suffix;
        chain->Add(fname);
    } else if (process == "WlnH130") {
        fname = dirMC + dijet + "WH_WToLNu_HToBB_M-130_8TeV-powheg-herwigpp" + suffix;
        chain->Add(fname);
    } else if (process == "WlnH135") {
        fname = dirMC + dijet + "WH_WToLNu_HToBB_M-135_8TeV-powheg-herwigpp" + suffix;
        chain->Add(fname);
    } else if (process == "WlnH140") {
        fname = dirMC + dijet + "WH_WToLNu_HToBB_M-140_8TeV-powheg-herwigpp" + suffix;
        chain->Add(fname);
    } else if (process == "WlnH145") {
        fname = dirMC + dijet + "WH_WToLNu_HToBB_M-145_8TeV-powheg-herwigpp" + suffix;
        chain->Add(fname);
    } else if (process == "WlnH150") {
        fname = dirMC + dijet + "WH_WToLNu_HToBB_M-150_8TeV-powheg-herwigpp" + suffix;
        chain->Add(fname);

    // ZllH
    } else if (process == "ZllH110") {
        fname = dirMC + dijet + "ZH_ZToLL_HToBB_M-110_8TeV-powheg-herwigpp3" + suffix;  // NOTE: '3' in name
        chain->Add(fname);
    } else if (process == "ZllH115") {
        fname = dirMC + dijet + "ZH_ZToLL_HToBB_M-115_8TeV-powheg-herwigpp" + suffix;
        chain->Add(fname);
    } else if (process == "ZllH120") {
        fname = dirMC + dijet + "ZH_ZToLL_HToBB_M-120_8TeV-powheg-herwigpp" + suffix;
        chain->Add(fname);
    } else if (process == "ZllH125") {
        fname = dirMC + dijet + "ZH_ZToLL_HToBB_M-125_8TeV-powheg-herwigpp" + suffix;
        chain->Add(fname);
    } else if (process == "ZllH130") {
        fname = dirMC + dijet + "ZH_ZToLL_HToBB_M-130_8TeV-powheg-herwigpp3" + suffix;  // NOTE: '3' in name
        chain->Add(fname);
    } else if (process == "ZllH135") {
        fname = dirMC + dijet + "ZH_ZToLL_HToBB_M-135_8TeV-powheg-herwigpp" + suffix;
        chain->Add(fname);
    } else if (process == "ZllH140") {
        fname = dirMC + dijet + "ZH_ZToLL_HToBB_M-140_8TeV-powheg-herwigpp" + suffix;
        chain->Add(fname);
    } else if (process == "ZllH145") {
        fname = dirMC + dijet + "ZH_ZToLL_HToBB_M-145_8TeV-powheg-herwigpp" + suffix;
        chain->Add(fname);
    } else if (process == "ZllH150") {
        fname = dirMC + dijet + "ZH_ZToLL_HToBB_M-150_8TeV-powheg-herwigpp" + suffix;
        chain->Add(fname);

    } else {
        std::cout << "Error: Unrecognized process. I quit!" << std::endl;
        return;
    }

    TCut selection = regression.c_str();
    
    // Make output directory if it doesn't exist
    if (gSystem->AccessPathName(outdir))
        gSystem->mkdir(outdir);
    TString outname = outdir + prefix + Form("%s.root", process.Data());

    TFile* f1 = TFile::Open(outname, "RECREATE");
    TTree* t1 = (TTree*) chain->CopyTree(selection);

    if (t1->GetEntriesFast() > skimentries){
        TTree* t2 = t1->CopyTree("", "", skimentries);
        t2->SetName(TString(t1->GetName())+"_train");
        TTree* t3 = t1->CopyTree("", "", 1000000000, skimentries);
        t3->SetName(TString(t1->GetName())+"_test");
        t2->Write();
        t3->Write();
        assert(t1->GetEntriesFast() == t2->GetEntriesFast() + t3->GetEntriesFast());
        delete t1;
        std::clog << process << ": skimmed from " << chain->GetEntriesFast() << " to " << t2->GetEntriesFast() << " (training) and " << t3->GetEntriesFast() << " (test) entries." << std::endl;
    } else {
        t1->Write();
        std::clog << process << ": skimmed from " << chain->GetEntriesFast() << " to " << t1->GetEntriesFast() << " entries." << std::endl;
    }
    
    f1->Close();

    return;
}
Пример #4
0
void analyzePuppi(std::vector<std::string> urls, const char *outname = "eventObjects.root", Long64_t nentries = 20, Int_t firstF = -1, Int_t lastF = -1) {

  // std::vector<std::string> urls = CollectFiles(list);

  // Printf("anaFile: %d",anaFile);
  
  std::cout << "nfiles: " << urls.size() << std::endl;
  for (auto i = urls.begin(); i != urls.end(); ++i)
    std::cout << *i << std::endl;

  size_t firstFile = 0;
  size_t lastFile = urls.size();

  if(firstF>-1) {
    firstFile = (size_t)firstF;
    lastFile = (size_t)lastF;
  }
  std::cout << "firstFile: " << firstFile << "  lastFile: " << lastFile << std::endl;
  
  //add files to chain
  TChain *chain = NULL;
  chain = new TChain("hiEvtAnalyzer/HiTree");
  for(size_t i=firstFile; i<lastFile; i++) chain->Add(urls[i].c_str());
  Printf("hiTree done");
  
  TChain *pfTree = new TChain("pfcandAnalyzer/pfTree");
  for(size_t i=firstFile; i<lastFile; i++) pfTree->Add(urls[i].c_str());
  chain->AddFriend(pfTree);
  Printf("pfTree done");
  
  // TChain *muTree = new TChain("hltMuTree/HLTMuTree");
  // for(size_t i=firstFile; i<lastFile; i++) muTree->Add(urls[i].c_str());
  // chain->AddFriend(muTree);
  // Printf("muTree done");

  //TChain *jetTree = new TChain("akPu3PFJetAnalyzer/t");
  TChain *jetTree = new TChain("akPu2PFJetAnalyzer10/t");
  for(size_t i=firstFile; i<lastFile; i++) jetTree->Add(urls[i].c_str());
  chain->AddFriend(jetTree);
  Printf("jetTree done");

  TChain *genTree = new TChain("HiGenParticleAna/hi");
  for(size_t i=firstFile; i<lastFile; i++) genTree->Add(urls[i].c_str());
  chain->AddFriend(genTree);
  Printf("genTree done");
  
  TList *fEventObjects = new TList();


  //---------------------------------------------------------------
  // producers
  //
  hiEventProducer *p_evt = new hiEventProducer("hiEvtProd");
  p_evt->SetInput(chain);
  p_evt->SetHIEventContName("hiEventContainer");
  p_evt->SetEventObjects(fEventObjects);

  pfParticleProducer *p_pf = new pfParticleProducer("pfPartProd");
  p_pf->SetInput(chain);
  p_pf->SetpfParticlesName("pfParticles");
  p_pf->SetEventObjects(fEventObjects);

  genParticleProducer *p_gen = new genParticleProducer("genParticleProd");
  p_gen->SetInput(chain);
  p_gen->SetGenParticlesName("genParticles");
  p_gen->SetEventObjects(fEventObjects);

  lwJetFromForestProducer *p_PUJet = new lwJetFromForestProducer("lwJetForestProd");
  p_PUJet->SetInput(chain);
  p_PUJet->SetJetContName("aktPUR030");
  p_PUJet->SetEventObjects(fEventObjects);
  p_PUJet->SetRadius(0.3);
  
  //---------------------------------------------------------------
  //analysis modules
  //

  //handler to which all modules will be added
  anaBaseTask *handler = new anaBaseTask("handler","handler");

  //analysis modules which also produce
  anaPuppiProducer *pupProd = new anaPuppiProducer("pupProd","pupProd");
  pupProd->ConnectEventObject(fEventObjects);
  pupProd->SetHiEvtName("hiEventContainer");
  pupProd->SetPFPartName("pfParticles");
  pupProd->SetPuppiPartName("puppiParticles");
  pupProd->SetJetsName("aktPUR030");
  pupProd->SetAddMetricType(anaPuppiProducer::kMass);
  if(doPuppi) handler->Add(pupProd);

  //anti-kt jet finder on reconstructed PUPPI particles ptmin=0
  LWJetProducer *lwjakt = new LWJetProducer("LWJetProducerAKTR030Puppi","LWJetProducerAKTR030Puppi");
  lwjakt->ConnectEventObject(fEventObjects);
  lwjakt->SetJetType(LWJetProducer::kAKT);
  lwjakt->SetRadius(0.3);
  lwjakt->SetGhostArea(0.005);
  lwjakt->SetPtMinConst(0.);
  lwjakt->SetParticlesName("puppiParticles");
  lwjakt->SetJetContName("JetsAKTR030Puppi");
  if(doPuppi) handler->Add(lwjakt);

  //anti-kt jet finder on reconstructed PUPPI particles ptmin=1
  LWJetProducer *lwjaktpt100 = new LWJetProducer("LWJetProducerAKTR030PuppiPtMin100","LWJetProducerAKTR030PuppiPtMin100");
  lwjaktpt100->ConnectEventObject(fEventObjects);
  lwjaktpt100->SetJetType(LWJetProducer::kAKT);
  lwjaktpt100->SetRadius(0.3);
  lwjaktpt100->SetGhostArea(0.005);
  lwjaktpt100->SetPtMinConst(1.);
  lwjaktpt100->SetParticlesName("puppiParticles");
  lwjaktpt100->SetJetContName("JetsAKTR030PuppiPtMin100");
  if(doPuppi) handler->Add(lwjaktpt100);

  //anti-kt jet finder on reconstructed PUPPI particles ptmin=2
  LWJetProducer *lwjaktpt200 = new LWJetProducer("LWJetProducerAKTR030PuppiPtMin200","LWJetProducerAKTR030PuppiPtMin200");
  lwjaktpt200->ConnectEventObject(fEventObjects);
  lwjaktpt200->SetJetType(LWJetProducer::kAKT);
  lwjaktpt200->SetRadius(0.3);
  lwjaktpt200->SetGhostArea(0.005);
  lwjaktpt200->SetPtMinConst(2.);
  lwjaktpt200->SetParticlesName("puppiParticles");
  lwjaktpt200->SetJetContName("JetsAKTR030PuppiPtMin200");
  if(doPuppi) handler->Add(lwjaktpt200);

  //anti-kt jet finder on generated particles
  LWJetProducer *lwjaktGen = new LWJetProducer("LWGenJetProducerAKTR030","LWGenJetProducerAKTR030");
  lwjaktGen->ConnectEventObject(fEventObjects);
  lwjaktGen->SetJetType(LWJetProducer::kAKT);
  lwjaktGen->SetRadius(0.3);
  lwjaktGen->SetGhostArea(0.005);
  lwjaktGen->SetPtMinConst(0.);
  lwjaktGen->SetParticlesName("genParticles");
  lwjaktGen->SetJetContName("GenJetsAKTR030");
  handler->Add(lwjaktGen);
 
  //Initialization of all analysis modules
  anaPuppiParticles *pupAna = new anaPuppiParticles("pupAna","pupAna");
  pupAna->ConnectEventObject(fEventObjects);
  pupAna->SetHiEvtName("hiEventContainer");
  pupAna->SetParticlesName("pfParticles");
  pupAna->SetJetsName("aktPUR030");
  if(doPuppi) handler->Add(pupAna);

  //particle-detector-level jet matching
  anaJetMatching *match = new anaJetMatching("jetMatching","jetMatching");
  match->ConnectEventObject(fEventObjects);
  match->SetHiEvtName("hiEventContainer");
  match->SetJetsNameBase("JetsAKTR030Puppi");
  match->SetJetsNameTag("GenJetsAKTR030");
  if(doPuppi) handler->Add(match);

  anaJetMatching *matchPt100 = new anaJetMatching("jetMatchingPtMin100","jetMatchingPtMin100");
  matchPt100->ConnectEventObject(fEventObjects);
  matchPt100->SetHiEvtName("hiEventContainer");
  matchPt100->SetJetsNameBase("JetsAKTR030PuppiPtMin100");
  matchPt100->SetJetsNameTag("GenJetsAKTR030");
  if(doPuppi) handler->Add(matchPt100);

  anaJetMatching *matchPt200 = new anaJetMatching("jetMatchingPtMin200","jetMatchingPtMin200");
  matchPt200->ConnectEventObject(fEventObjects);
  matchPt200->SetHiEvtName("hiEventContainer");
  matchPt200->SetJetsNameBase("JetsAKTR030PuppiPtMin200");
  matchPt200->SetJetsNameTag("GenJetsAKTR030");
  if(doPuppi) handler->Add(matchPt200);
  
  //---------------------------------------------------------------
  //Event loop
  //---------------------------------------------------------------	  
  Long64_t entries_tot =  chain->GetEntriesFast(); //93064
  if(nentries<0) nentries = chain->GetEntries();
  // Long64_t nentries = 20;//chain->GetEntriesFast();
  Printf("nentries: %lld  tot: %lld",nentries,entries_tot);
  for (Long64_t jentry=0; jentry<nentries;jentry++) {

    //Run producers
    Printf("produce hiEvent");
    p_evt->Run(jentry);   //hi event properties
    Printf("produce pf particles");
    p_pf->Run(jentry);    //pf particles
    Printf("produce gen particles");
    p_gen->Run(jentry);   //generated particles
    Printf("produce PU jets");
    p_PUJet->Run(jentry); //forest jets
	    
    //Execute all analysis tasks
    // handler->ExecuteTask();
  }
    
  fEventObjects->Print();

  TFile *out = new TFile(outname,"RECREATE");
  TList *tasks = handler->GetListOfTasks();
  TIter next(tasks);
  anaBaseTask *obj;
  while ((obj = dynamic_cast<anaBaseTask*>(next()) ))
    if(obj->GetOutput()) obj->GetOutput()->Write(obj->GetName(),TObject::kSingleKey);
  
  out->Write();
  out->Close();
  
}
Пример #5
0
Double_t CalibTree::Loop(int loop, TFile *fout, bool useweight, int nMin,
			 bool inverse, double rmin, double rmax, int ietaMax,
			 int applyL1Cut, double l1Cut, bool last, 
			 double fraction, bool writeHisto, bool debug) {

  if (fChain == 0) return 0;
  Long64_t nbytes(0), nb(0), kprint(0);
  Long64_t nentryTot = fChain->GetEntriesFast();
  Long64_t nentries = (fraction > 0.01 && fraction < 0.99) ? 
    (Long64_t)(fraction*nentryTot) : nentryTot;
  if (detIds.size() == 0) {
    for (Long64_t jentry=0; jentry<nentries; jentry++) {
      Long64_t ientry = LoadTree(jentry);
      if (ientry < 0) break;
      nb = fChain->GetEntry(jentry);   nbytes += nb;
      // Find DetIds contributing to the track
      bool selRun = (includeRun_ ? ((t_Run >= runlo_) && (t_Run <= runhi_)) :
		     ((t_Run < runlo_) || (t_Run > runhi_)));
      if (selRun && (t_nVtx >= nvxlo_) && (t_nVtx <= nvxhi_)) {
	bool isItRBX = (cSelect_ && exclude_ && cSelect_->isItRBX(t_DetIds));
	++kprint;
	if (!isItRBX) {
	  for (unsigned int idet=0; idet<(*t_DetIds).size(); idet++) { 
	    if (selectPhi((*t_DetIds)[idet])) {
	      unsigned int detid = truncateId((*t_DetIds)[idet],
					      truncateFlag_,debug);
	      if (debug && (kprint<=10)) {
		std::cout << "DetId[" << idet << "] Original " << std::hex 
			  << (*t_DetIds)[idet] << " truncated " << detid 
			  << std::dec;
	      }
	      if (std::find(detIds.begin(),detIds.end(),detid) == detIds.end()){
		detIds.push_back(detid);
		if (debug && (kprint<=10)) std::cout << " new";
	      }
	      if (debug && (kprint<=10)) std::cout << std::endl;
	    }
	  }
	  // Also look at the neighbouring cells if available
	  if (t_DetIds3 != 0) {
	    for (unsigned int idet=0; idet<(*t_DetIds3).size(); idet++) { 
	      if (selectPhi((*t_DetIds3)[idet])) {
		unsigned int detid = truncateId((*t_DetIds3)[idet],
						truncateFlag_,debug);
		if (std::find(detIds.begin(),detIds.end(),detid)==detIds.end()){
		  detIds.push_back(detid);
		}
	      }
	    }
	  }
	}
      }
    }
  }
  if (debug) {
    std::cout << "Total of " << detIds.size() << " detIds and " 
	      << histos.size() << " histos found" << std::endl;
    // The masks are defined in DataFormats/HcalDetId/interface/HcalDetId.h
    for (unsigned int k=0; k<detIds.size(); ++k) {
      int subdet, depth, zside, ieta, iphi;
      unpackDetId(detIds[k], subdet, zside, ieta, iphi, depth);
      std::cout << "DetId[" << k << "] " << subdet << ":" << zside*ieta << ":"
		<< depth << ":" << iphi << "  " << std::hex << detIds[k] 
		<< std::dec << std::endl;
    }
  }
  unsigned int k(0);
  for (std::map<unsigned int, TH1D*>::const_iterator itr = histos.begin();
       itr != histos.end(); ++itr,++k) {
    if (debug) {
      std::cout << "histos[" << k << "] " << std::hex << itr->first 
		<< std::dec << " " << itr->second;
      if (itr->second != 0) std::cout << " " << itr->second->GetTitle();
      std::cout << std::endl;
    }
    if (itr->second != 0) itr->second->Delete();
  }

  for (unsigned int k=0; k<detIds.size(); ++k) {
    char name[20], title[100];
    sprintf (name, "Hist%d_%d", detIds[k], loop);
    int subdet, depth, zside, ieta, iphi;
    unpackDetId(detIds[k], subdet, zside, ieta, iphi, depth);
    sprintf (title, "Correction for Subdet %d #eta %d depth %d (Loop %d)", subdet, zside*ieta, depth, loop);
    TH1D* hist = new TH1D(name,title,100, 0.0, 5.0);
    hist->Sumw2();
    if (debug) {
      std::cout << "Book Histo " << k << " " << title << std::endl;
    }
    histos[detIds[k]] = hist;
  }
  std::cout << "Total of " << detIds.size() << " detIds and " << histos.size() 
	    << " found in " << nentries << std::endl;

  nbytes = nb = 0;
  std::map<unsigned int, myEntry > SumW;
  std::map<unsigned int, double  > nTrks;

  int ntkgood(0);
  for (Long64_t jentry=0; jentry<nentries; jentry++) {
    Long64_t ientry = LoadTree(jentry);
    if (ientry < 0)                               break;
    nb = fChain->GetEntry(jentry);   nbytes += nb;
    if (std::find(entries.begin(),entries.end(),jentry) !=
	entries.end())                            continue;
    bool selRun = (includeRun_ ? ((t_Run >= runlo_) && (t_Run <= runhi_)) :
		   ((t_Run < runlo_) || (t_Run > runhi_)));
    if (!selRun)                                  continue;
    if ((t_nVtx < nvxlo_) || (t_nVtx > nvxhi_))   continue;
    if (cSelect_ != nullptr) {
      if (exclude_) {
	if (cSelect_->isItRBX(t_DetIds))          continue;
      } else {
	if (!(cSelect_->isItRBX(t_ieta,t_iphi)))  continue;
      }
    }

    if (debug) {
      std::cout << "***Entry (Track) Number : " << ientry << std::endl;
      std::cout << "p/eHCal/eMipDR/nDets : " << t_p << "/" << t_eHcal << "/"
		<< t_eMipDR << "/" << (*t_DetIds).size() << std::endl;
    }
    double pmom = (useGen_ && (t_gentrackP > 0)) ? t_gentrackP : t_p;
    if (goodTrack()) {
      ++ntkgood;
      double Etot(0), Etot2(0);
      for (unsigned int idet=0; idet<(*t_DetIds).size(); idet++) { 
	if (selectPhi((*t_DetIds)[idet])) {
	  unsigned int id = (*t_DetIds)[idet];
	  double hitEn(0);
	  unsigned int detid = truncateId(id,truncateFlag_,false);
	  if (Cprev.find(detid) != Cprev.end()) 
	    hitEn = Cprev[detid].first * (*t_HitEnergies)[idet];
	  else 
	    hitEn = (*t_HitEnergies)[idet];
	  if (cFactor_) hitEn *= cFactor_->getCorr(t_Run,id);
	  Etot  += hitEn;
	  Etot2 += ((*t_HitEnergies)[idet]);
	}
      }
      // Now the outer cone 
      double Etot1(0), Etot3(0);
      if (t_DetIds1 != 0 && t_DetIds3 != 0) {
	for (unsigned int idet=0; idet<(*t_DetIds1).size(); idet++) { 
	  if (selectPhi((*t_DetIds1)[idet])) {
	    unsigned int id    = (*t_DetIds1)[idet];
	    unsigned int detid = truncateId(id,truncateFlag_,false);
	    double hitEn(0);
	    if (Cprev.find(detid) != Cprev.end()) 
	      hitEn = Cprev[detid].first * (*t_HitEnergies1)[idet];
	    else 
	      hitEn = (*t_HitEnergies1)[idet];
	    if (cFactor_) hitEn *= cFactor_->getCorr(t_Run,id);
	    Etot1  += hitEn;
	  }
	}
	for (unsigned int idet=0; idet<(*t_DetIds3).size(); idet++) { 
	  if (selectPhi((*t_DetIds3)[idet])) {
	    unsigned int id    = (*t_DetIds3)[idet];
	    unsigned int detid = truncateId(id,truncateFlag_,false);
	    double hitEn(0);
	    if (Cprev.find(detid) != Cprev.end()) 
	      hitEn = Cprev[detid].first * (*t_HitEnergies3)[idet];
	    else 
	      hitEn = (*t_HitEnergies3)[idet];
	    if (cFactor_) hitEn *= cFactor_->getCorr(t_Run,id);
	    Etot3  += hitEn;
	  }
	}
      }
      eHcalDelta_ = Etot3-Etot1;
      double evWt = (useweight) ? t_EventWeight : 1.0; 
      // PU correction only for loose isolation cut
      double ehcal = ((puCorr_ == 0) ? Etot : 
		      ((puCorr_ < 0) ? (Etot*puFactor(-puCorr_,t_ieta,pmom,Etot,eHcalDelta_)) :
		       puFactorRho(puCorr_,t_ieta,t_rhoh,Etot)));
      double pufac = (Etot > 0) ? (ehcal/Etot) : 1.0;
      double ratio = ehcal/(pmom-t_eMipDR);
      if (debug) std::cout << " Weights " << evWt << ":" << pufac << " Energy "
			   << Etot2 << ":" << Etot << ":" << pmom << ":" 
			   << t_eMipDR << ":" << t_eHcal << ":" << ehcal 
			   << " ratio " << ratio  << std::endl;
      if (loop==0) {
	h_pbyE->Fill(ratio, evWt);
        h_Ebyp_bfr->Fill(t_ieta, ratio, evWt);
      }
      if (last){
        h_Ebyp_aftr->Fill(t_ieta, ratio, evWt);
      }
      bool l1c(true);
      if (applyL1Cut != 0) l1c = ((t_mindR1 >= l1Cut) || 
				  ((applyL1Cut == 1) && (t_DataType == 1)));
      if ((rmin >=0 && ratio > rmin) && (rmax >= 0 && ratio < rmax) && l1c) {
	for (unsigned int idet=0; idet<(*t_DetIds).size(); idet++) {
	  if (selectPhi((*t_DetIds)[idet])) {
	    unsigned int id    = (*t_DetIds)[idet];
	    unsigned int detid = truncateId(id,truncateFlag_,false);
	    double hitEn=0.0;
	    if (debug) {
	      std::cout << "idet " << idet << " detid/hitenergy : " 
			<< std::hex << (*t_DetIds)[idet] << ":" << detid 
			<< "/" << (*t_HitEnergies)[idet] << std::endl;
	    }
	    if (Cprev.find(detid) != Cprev.end()) 
	      hitEn = Cprev[detid].first * (*t_HitEnergies)[idet];
	    else 
	      hitEn = (*t_HitEnergies)[idet];
	    if (cFactor_) hitEn *= cFactor_->getCorr(t_Run,id);
	    double Wi  = evWt * hitEn/Etot;
	    double Fac = (inverse) ? (ehcal/(pmom-t_eMipDR)) : 
	      ((pmom-t_eMipDR)/ehcal);
	    double Fac2= Wi*Fac*Fac;
	    TH1D* hist(0);
	    std::map<unsigned int,TH1D*>::const_iterator itr = histos.find(detid);
	    if (itr != histos.end()) hist = itr->second;
	    if (debug) {
	      std::cout << "Det Id " << std::hex << detid << std::dec 
			<< " " << hist << std::endl;
	    }
	    if (hist != 0) hist->Fill(Fac, Wi);//////histola
	    Fac       *= Wi;
	    if (SumW.find(detid) != SumW.end() ) {
	      Wi  += SumW[detid].fact0;
	      Fac += SumW[detid].fact1;
	      Fac2+= SumW[detid].fact2;
	      int kount = SumW[detid].kount + 1;
	      SumW[detid]   = myEntry(kount,Wi,Fac,Fac2); 
	      nTrks[detid] += evWt;
	    } else {
	      SumW.insert(std::pair<unsigned int,myEntry>(detid,myEntry(1,Wi,Fac,Fac2)));
	      nTrks.insert(std::pair<unsigned int,unsigned int>(detid, evWt));
	    }
	  }
	}
      }
    }
  }
  if (debug) {
    std::cout << "# of Good Tracks " << ntkgood << " out of " << nentries 
	      << std::endl;
  }
  if (loop==0) {
    h_pbyE->Write("h_pbyE");
    h_Ebyp_bfr->Write("h_Ebyp_bfr");
  }
  if (last) {
    h_Ebyp_aftr->Write("h_Ebyp_aftr");
  }

  std::map<unsigned int, std::pair<double,double> > cfactors;
  unsigned int kount(0), kountus(0);
  double       sumfactor(0);
  for (std::map<unsigned int,TH1D*>::const_iterator itr = histos.begin();
       itr != histos.end(); ++itr) {
    if (writeHisto) {
      std::pair<double,double> result_write = fitMean(itr->second, 0);
      (itr->second)->Write();
    }
    // The masks are defined in DataFormats/HcalDetId/interface/HcalDetId.h
    int subdet, depth, zside, ieta, iphi;
    unpackDetId(itr->first, subdet, zside, ieta, iphi, depth);
    if (debug) {
      std::cout << "DETID :" << subdet << "  IETA :" << ieta 
		<< " HIST ENTRIES :" << (itr->second)->GetEntries()
		<< std::endl;
    }
  }

  for (std::map<unsigned int,TH1D*>::const_iterator itr = histos.begin();
       itr != histos.end(); ++itr,++kount) {
    std::pair<double,double> result = fitMean(itr->second, 0);
    double factor = (inverse) ? (2.-result.first) : result.first;
    if (debug) {
      int subdet, depth, zside, ieta, iphi;
      unpackDetId(itr->first, subdet, zside, ieta, iphi, depth);
      std::cout << "DetId[" << kount << "] " << subdet << ":" << zside*ieta 
		<< ":" << depth << " Factor " << factor << " +- " 
		<< result.second << std::endl;
    }
    if (!useMean_) {
      cfactors[itr->first] = std::pair<double,double>(factor,result.second);
      if (itr->second->GetEntries() > nMin) {
	kountus++;
	if (factor > 1) sumfactor += (1-1/factor);
	else            sumfactor += (1-factor);
      }
    }
  }
  
  std::map<unsigned int, myEntry>::const_iterator SumWItr = SumW.begin();
  for (; SumWItr != SumW.end(); SumWItr++) {
    unsigned int detid = SumWItr->first;
    int subdet, depth, zside, ieta, iphi;
    unpackDetId(detid, subdet, zside, ieta, iphi, depth);
    if (debug) {
      std::cout << "Detid|kount|SumWi|SumFac|myId : " << subdet << ":" 
		<< zside*ieta << ":" << depth << " | " 
		<< (SumWItr->second).kount << " | " << (SumWItr->second).fact0
		<< "|" << (SumWItr->second).fact1 << "|" 
		<< (SumWItr->second).fact2 << std::endl;
    }
    double factor = (SumWItr->second).fact1/(SumWItr->second).fact0;
    double dfac1  = ((SumWItr->second).fact2/(SumWItr->second).fact0-factor*factor);
    if (dfac1 < 0) dfac1 = 0;
    double dfac   = sqrt(dfac1/(SumWItr->second).kount);
    if (debug) {
      std::cout << "Factor " << factor << " " << dfac1 << " " << dfac
		<< std::endl;
    }
    if (inverse) factor = 2.-factor;
    if (useMean_) {
      cfactors[detid] = std::pair<double,double>(factor,dfac);
      if ((SumWItr->second).kount > nMin) {
	kountus++;
	if (factor > 1) sumfactor += (1-1/factor);
	else            sumfactor += (1-factor);
      }
    }
  }

  double dets[150], cfacs[150], wfacs[150], myId[150], nTrk[150];
  kount = 0;
  std::map<unsigned int,std::pair<double,double> >::const_iterator itr=cfactors.begin();
  for (; itr !=cfactors.end(); ++itr,++kount) {
    unsigned int detid = itr->first;
    int subdet, depth, zside, ieta, iphi;
    unpackDetId(detid, subdet, zside, ieta, iphi, depth);
    double id  = ieta*zside + 0.25*(depth-1);
    double factor = (itr->second).first;
    double dfac   = (itr->second).second;
    if (ieta > ietaMax) {
      factor = 1;
      dfac   = 0;
    }
    std::pair<double,double> cfac(factor,dfac);
    if (Cprev.find(detid) != Cprev.end()) {
      dfac        /= factor;
      factor      *= Cprev[detid].first;
      dfac        *= factor;
      Cprev[detid] = std::pair<double,double>(factor,dfac);
      cfacs[kount] = factor;
    } else {
      Cprev[detid] = std::pair<double,double>(factor,dfac);
      cfacs[kount] = factor;
    }
    wfacs[kount]= factor;
    dets[kount] = detid;
    myId[kount] = id;
    nTrk[kount] = nTrks[detid];
  }
  if (higheta_ > 0) highEtaFactors(ietaMax, debug);

  std::cout << kountus << " detids out of " << kount << " have tracks > "
	    << nMin << std::endl;

  char fname[50];
  fout->cd();
  TGraph *g_fac1 = new TGraph(kount, dets, cfacs); 
  sprintf (fname, "Cfacs%d", loop);
  g_fac1->SetMarkerStyle(7);
  g_fac1->SetMarkerSize(5.0);
  g_fac1->Draw("AP");
  g_fac1->Write(fname);
  TGraph *g_fac2 = new TGraph(kount, dets, wfacs); 
  sprintf (fname, "Wfacs%d", loop);
  g_fac2->SetMarkerStyle(7);
  g_fac2->SetMarkerSize(5.0);
  g_fac2->Draw("AP");
  g_fac2->Write(fname);
  TGraph *g_fac3 = new TGraph(kount, myId, cfacs); 
  sprintf (fname, "CfacsVsMyId%d", loop);
  g_fac3->SetMarkerStyle(7);
  g_fac3->SetMarkerSize(5.0);
  g_fac3->Draw("AP");
  g_fac3->Write(fname);
  TGraph *g_fac4 = new TGraph(kount, myId, wfacs); 
  sprintf (fname, "WfacsVsMyId%d", loop);
  g_fac4->SetMarkerStyle(7);
  g_fac4->SetMarkerSize(5.0);
  g_fac4->Draw("AP");
  g_fac4->Write(fname);
  TGraph *g_nTrk = new TGraph(kount, myId, nTrk); 
  sprintf (fname, "nTrk");
  if(loop==0){
    g_nTrk->SetMarkerStyle(7);
    g_nTrk->SetMarkerSize(5.0);
    g_nTrk->Draw("AP");
    g_nTrk->Write(fname);
  }
  std::cout << "The new factors are :" << std::endl;
  std::map<unsigned int, std::pair<double,double> >::const_iterator CprevItr = Cprev.begin();
  unsigned int indx(0);
  for (; CprevItr != Cprev.end(); CprevItr++, indx++){
    unsigned int detid = CprevItr->first;
    int subdet, depth, zside, ieta, iphi;
    unpackDetId(detid, subdet, zside, ieta, iphi, depth);
    std::cout << "DetId[" << indx << "] " << std::hex << detid << std::dec
	      << "(" << ieta*zside << "," << depth << ") (nTrks:" 
	      << nTrks[detid] << ") : " << CprevItr->second.first << " +- "
	      << CprevItr->second.second << std::endl;
  }
  double mean = (kountus > 0) ? (sumfactor/kountus) : 0;
  std::cout << "Mean deviation " << mean << " from 1 for " << kountus 
	    << " DetIds" << std::endl;
  h_cvg->SetBinContent(loop+1,mean);
  if (last) h_cvg->Write("Cvg0");
  return mean;
}
Пример #6
0
void ctlMetXY()
{
  gStyle->SetOptStat(0);
  int metBin(6);
  int vtxBin(5);
   TChain * fChain = new TChain("metPhiCorrInfoWriter/Events","");
   //fChain->Add("histo_data.root/metPhiCorrInfoWriter/Events");
   fChain->Add("~/WorkDir/MetPhiCorrection/CMSSW_8_0_9/src/MetTools/MetPhiCorrections/test/histo_Run2016B_noMetcut.root/metPhiCorrInfoWriter/Events");

   if (fChain == 0) return;

   // Declaration of leaf types
   vector<int>     *Count_catagory;
   vector<int>     *Count_counts;
   vector<double>  *Count_MetX;
   vector<double>  *Count_MetY;
   vector<double>  *Count_pfMetT;
   vector<double>  *Count_pfMetX;
   vector<double>  *Count_pfMetY;
   vector<int>     *nVtx_catagory;
   vector<int>     *nVtx_nVtx;
   vector<double>  *nVtx_MetX;
   vector<double>  *nVtx_MetY;
   vector<double>  *nVtx_pfMetT;
   vector<double>  *nVtx_pfMetX;
   vector<double>  *nVtx_pfMetY;
   vector<int>     *sumPt_catagory;
   vector<double>  *sumPt_sumPt;
   vector<double>  *sumPt_MetX;
   vector<double>  *sumPt_MetY;
   vector<double>  *sumPt_pfMetT;
   vector<double>  *sumPt_pfMetX;
   vector<double>  *sumPt_pfMetY;

   // List of branches
   TBranch        *b_Count_catagory;   //!
   TBranch        *b_Count_counts;   //!
   TBranch        *b_Count_MetX;   //!
   TBranch        *b_Count_MetY;   //!
   TBranch        *b_Count_pfMetT;   //!
   TBranch        *b_Count_pfMetX;   //!
   TBranch        *b_Count_pfMetY;   //!
   TBranch        *b_nVtx_catagory;   //!
   TBranch        *b_nVtx_nVtx;   //!
   TBranch        *b_nVtx_MetX;   //!
   TBranch        *b_nVtx_MetY;   //!
   TBranch        *b_nVtx_pfMetT;   //!
   TBranch        *b_nVtx_pfMetX;   //!
   TBranch        *b_nVtx_pfMetY;   //!
   TBranch        *b_sumPt_catagory;   //!
   TBranch        *b_sumPt_sumPt;   //!
   TBranch        *b_sumPt_MetX;   //!
   TBranch        *b_sumPt_MetY;   //!
   TBranch        *b_sumPt_pfMetT;   //!
   TBranch        *b_sumPt_pfMetX;   //!
   TBranch        *b_sumPt_pfMetY;   //!

   // Set object pointer
   Count_catagory = 0;
   Count_counts = 0;
   Count_MetX = 0;
   Count_MetY = 0;
   Count_pfMetT = 0;
   Count_pfMetX = 0;
   Count_pfMetY = 0;
   nVtx_catagory = 0;
   nVtx_nVtx = 0;
   nVtx_MetX = 0;
   nVtx_MetY = 0;
   nVtx_pfMetT = 0;
   nVtx_pfMetX = 0;
   nVtx_pfMetY = 0;
   sumPt_catagory = 0;
   sumPt_sumPt = 0;
   sumPt_MetX = 0;
   sumPt_MetY = 0;
   sumPt_pfMetT = 0;
   sumPt_pfMetX = 0;
   sumPt_pfMetY = 0;

   fChain->SetBranchAddress("Count_catagory", &Count_catagory, &b_Count_catagory);
   fChain->SetBranchAddress("Count_counts", &Count_counts, &b_Count_counts);
   fChain->SetBranchAddress("Count_MetX", &Count_MetX, &b_Count_MetX);
   fChain->SetBranchAddress("Count_MetY", &Count_MetY, &b_Count_MetY);
   fChain->SetBranchAddress("Count_pfMetT", &Count_pfMetT, &b_Count_pfMetT);
   fChain->SetBranchAddress("Count_pfMetX", &Count_pfMetX, &b_Count_pfMetX);
   fChain->SetBranchAddress("Count_pfMetY", &Count_pfMetY, &b_Count_pfMetY);
   fChain->SetBranchAddress("nVtx_catagory", &nVtx_catagory, &b_nVtx_catagory);
   fChain->SetBranchAddress("nVtx_nVtx", &nVtx_nVtx, &b_nVtx_nVtx);
   fChain->SetBranchAddress("nVtx_MetX", &nVtx_MetX, &b_nVtx_MetX);
   fChain->SetBranchAddress("nVtx_MetY", &nVtx_MetY, &b_nVtx_MetY);
   fChain->SetBranchAddress("nVtx_pfMetT", &nVtx_pfMetT, &b_nVtx_pfMetT);
   fChain->SetBranchAddress("nVtx_pfMetX", &nVtx_pfMetX, &b_nVtx_pfMetX);
   fChain->SetBranchAddress("nVtx_pfMetY", &nVtx_pfMetY, &b_nVtx_pfMetY);
   fChain->SetBranchAddress("sumPt_catagory", &sumPt_catagory, &b_sumPt_catagory);
   fChain->SetBranchAddress("sumPt_sumPt", &sumPt_sumPt, &b_sumPt_sumPt);
   fChain->SetBranchAddress("sumPt_MetX", &sumPt_MetX, &b_sumPt_MetX);
   fChain->SetBranchAddress("sumPt_MetY", &sumPt_MetY, &b_sumPt_MetY);
   fChain->SetBranchAddress("sumPt_pfMetT", &sumPt_pfMetT, &b_sumPt_pfMetT);
   fChain->SetBranchAddress("sumPt_pfMetX", &sumPt_pfMetX, &b_sumPt_pfMetX);
   fChain->SetBranchAddress("sumPt_pfMetY", &sumPt_pfMetY, &b_sumPt_pfMetY);

   Long64_t nentries = fChain->GetEntriesFast();
   //nentries = 30;

   Long64_t nbytes = 0, nb = 0;

   TCanvas *myCan = new TCanvas("myCan","myCan");
   TProfile *pr_MEx_vtx         = new TProfile("pr_MEx_vtx","pr_MEx_vtx",20,0,40);
   TProfile *pr_MEy_vtx         = new TProfile("pr_MEy_vtx","pr_MEy_vtx",20,0,40);
   TProfile *pr_MEx_pfMetT_vtx[vtxBin];
   TProfile *pr_MEx_vtx_pfMetT[metBin];
   TProfile *pr_MEy_vtx_pfMetT[metBin];
   TProfile *pr_MEx_pfMetT = new TProfile("pr_MEx_pfMetT","pr_MEx_pfMetT",30,0,90);
   TString name;
   for(int i(0);i<vtxBin;i++){
     name = Form("pr_MEx_pfMetT_vtx%d", (i+1)*metBin);
     pr_MEx_pfMetT_vtx[i]  = new TProfile(name,name,30,0,90);
   }
   for(int i(0); i<metBin;i++){
     name = Form("pr_MEx_vtx_pfMetT%d", (i+1)*metBin);
     pr_MEx_vtx_pfMetT[i]  = new TProfile(name,name,20,0,40);
     pr_MEx_vtx_pfMetT[i]->SetMaximum(5);
     pr_MEx_vtx_pfMetT[i]->SetMinimum(-3);

     name = Form("pr_MEy_vtx_pfMetT%d", (i+1)*metBin);
     pr_MEy_vtx_pfMetT[i]  = new TProfile(name,name,20,0,40);
     pr_MEy_vtx_pfMetT[i]->SetMaximum(5);
     pr_MEy_vtx_pfMetT[i]->SetMinimum(-3);
   }
   TH1D *h_pfMetT                = new TH1D("h_pfMetT","h_pfMetT",50,0,100);

   for (Long64_t jentry=0; jentry<nentries;jentry++) {
      Long64_t ientry = fChain->LoadTree(jentry);
      if (ientry < 0) break;
      nb = fChain->GetEntry(jentry);   nbytes += nb;
      //cout<<"size catagory: "<<nVtx_catagory->size()<<endl; // size 16
      for(unsigned i(0); i < nVtx_catagory->size(); i++){
	if( (*nVtx_catagory)[i] % PtlTT == PtlIdx){ // 12(hHFMinus)
	  h_pfMetT->Fill((*nVtx_pfMetT)[i]);
	  pr_MEx_vtx->Fill((*nVtx_nVtx)[i],(*nVtx_MetX)[i]);
	  pr_MEy_vtx->Fill((*nVtx_nVtx)[i],(*nVtx_MetY)[i]);
	  pr_MEx_pfMetT->Fill((*nVtx_pfMetT)[i], (*nVtx_MetX)[i]);
	  for(int j(0); j<vtxBin;j++){ // As a ftn of MET
	    if((*nVtx_nVtx)[i] > j*5 && (*nVtx_nVtx)[i] <=(j+1)*5){
	      pr_MEx_pfMetT_vtx[j]->Fill((*nVtx_pfMetT)[i], (*nVtx_MetX)[i]);
	    }
	  }

	  for( int j(0); j<metBin; j++) // As a ftn of vtx
	  {
	    if(j==metBin-1){
	      if( (*nVtx_pfMetT)[i] > j*10 )
	      {
	        pr_MEx_vtx_pfMetT[j]->Fill((*nVtx_nVtx)[i], (*nVtx_MetX)[i]);
	        pr_MEy_vtx_pfMetT[j]->Fill((*nVtx_nVtx)[i], (*nVtx_MetY)[i]);
	      }
	    }else{
	      if( (*nVtx_pfMetT)[i] > j*10 && (*nVtx_pfMetT)[i] < (j+1)*10 )
	      {
	        pr_MEx_vtx_pfMetT[j]->Fill((*nVtx_nVtx)[i], (*nVtx_MetX)[i]);
	        pr_MEy_vtx_pfMetT[j]->Fill((*nVtx_nVtx)[i], (*nVtx_MetY)[i]);
	      }
	    }
	  }
	}
        //cout<<"nVtx_catagory: "<<(*nVtx_catagory)[i]<<endl;
      }
      // if (Cut(ientry) < 0) continue;
   }
   pr_MEx_vtx->Draw();
   myCan->SaveAs("prTest_MEx_vtx.png");
   h_pfMetT->Draw();
   myCan->SaveAs("h_pfMetT.png");
   pr_MEx_pfMetT->Draw();
   myCan->SaveAs("pr_MEx_pfMetT.png");

   TLegend *leg = new TLegend(0.5373563,0.7097458,0.8577586,0.8474576,NULL,"brNDC");
   leg->SetTextFont(62);
   leg->SetTextSize(0.03330866);
   leg->SetLineColor(1);
   leg->SetLineStyle(1);
   leg->SetLineWidth(1);
   leg->SetFillColor(0);
   leg->SetFillStyle(1001);
   leg->SetBorderSize(0);

   for(int i(0);i<vtxBin;i++)
   {
     pr_MEx_pfMetT_vtx[i]->SetLineColor(i+1);
     if(i == 0) pr_MEx_pfMetT_vtx[i]->Draw();
     else pr_MEx_pfMetT_vtx[i]->Draw("same");
     name = Form("pr_MEx_pfMetT_vtx_%d_%d",i*metBin, (i+1)*metBin);
     leg->AddEntry(pr_MEx_pfMetT_vtx[i],name,"lp");
   }

   leg->Draw("same");
   name = Form("pr_MEx_pfMetT_vtxes.png");
   myCan->SaveAs(name);

   TLegend *l_MEx_vtx = new TLegend(0.2373563,0.6097458,0.5577586,0.8474576,NULL,"brNDC");
   l_MEx_vtx->SetTextFont(62);
   l_MEx_vtx->SetTextSize(0.03330866);
   l_MEx_vtx->SetLineColor(1);
   l_MEx_vtx->SetLineStyle(1);
   l_MEx_vtx->SetLineWidth(1);
   l_MEx_vtx->SetFillColor(0);
   l_MEx_vtx->SetFillStyle(1001);
   l_MEx_vtx->SetBorderSize(0);

   for(int i(0);i<metBin;i++)
   {
     pr_MEx_vtx_pfMetT[i]->SetLineColor(i+1);
     pr_MEx_vtx_pfMetT[i]->SetMarkerColor(i+1);
     pr_MEx_vtx_pfMetT[i]->SetMarkerStyle(22);
     pr_MEx_vtx_pfMetT[i]->SetMarkerSize(1);

     if(i == 0){
       pr_MEx_vtx_pfMetT[i]->SetTitle("<MetX> vs vtx");
       pr_MEx_vtx_pfMetT[i]->Draw();
     }else pr_MEx_vtx_pfMetT[i]->Draw("same");

     if(i == metBin-1){
       name = Form("pfMetT_%d_%d",i*10, 100);
       l_MEx_vtx->AddEntry(pr_MEx_vtx_pfMetT[i],name,"lp");
     }else{
       name = Form("pfMetT_%d_%d",i*10, (i+1)*10);
       l_MEx_vtx->AddEntry(pr_MEx_vtx_pfMetT[i],name,"lp");
     }

   }
   pr_MEx_vtx->SetMarkerStyle(20);
   pr_MEx_vtx->Draw("same");
   l_MEx_vtx->AddEntry(pr_MEx_vtx,"all","lp");

   l_MEx_vtx->Draw("same");
   name = Form("pr_MEx_vtx_pfMetTes.png");
   myCan->SaveAs(name);

   TLegend *l_MEy_vtx = new TLegend(0.2373563,0.6097458,0.5577586,0.8474576,NULL,"brNDC");
   l_MEy_vtx->SetTextFont(62);
   l_MEy_vtx->SetTextSize(0.03330866);
   l_MEy_vtx->SetLineColor(1);
   l_MEy_vtx->SetLineStyle(1);
   l_MEy_vtx->SetLineWidth(1);
   l_MEy_vtx->SetFillColor(0);
   l_MEy_vtx->SetFillStyle(1001);
   l_MEy_vtx->SetBorderSize(0);

   for(int i(0);i<metBin;i++)
   {
     pr_MEy_vtx_pfMetT[i]->SetLineColor(i+1);
     pr_MEy_vtx_pfMetT[i]->SetMarkerColor(i+1);
     pr_MEy_vtx_pfMetT[i]->SetMarkerStyle(22);
     pr_MEy_vtx_pfMetT[i]->SetMarkerSize(1);

     if(i == 0){
       pr_MEy_vtx_pfMetT[i]->SetTitle("<MetY> vs vtx");
       pr_MEy_vtx_pfMetT[i]->Draw();
     }else pr_MEy_vtx_pfMetT[i]->Draw("same");

     if(i == metBin-1){
       name = Form("pfMetT_%d_%d",i*10, 100);
       l_MEy_vtx->AddEntry(pr_MEy_vtx_pfMetT[i],name,"lp");
     }else{
       name = Form("pfMetT_%d_%d",i*10, (i+1)*10);
       l_MEy_vtx->AddEntry(pr_MEy_vtx_pfMetT[i],name,"lp");
     }
   }
   pr_MEy_vtx->SetMarkerStyle(20);
   pr_MEy_vtx->Draw("same");
   l_MEy_vtx->AddEntry(pr_MEy_vtx,"all","lp");

   l_MEy_vtx->Draw("same");
   name = Form("pr_MEy_vtx_pfMetTes.png");
   myCan->SaveAs(name);
   
}
Пример #7
0
void Skim(TString fname="ZnnH125", TString outputname = "")
{
    gROOT->LoadMacro("HelperFunctions.h" );  // make functions visible to TTreeFormula
    gROOT->SetBatch(1);

    TChain * chain  = new TChain("tree");
    TString dijet   = "";
    TString outdir  = "/afs/cern.ch/work/d/degrutto/public/MiniAOD/ZnnHbb_Phys14_PU20bx25/skimV11_v2/";
    TString prefix  = "skim_";
    TString suffix  = "tree*.root";
    


    TCut selection = baseline.c_str();
    // Different baseline for dimuons
    // MET filters
    selection += metfilter.c_str();

    // JSON & trigger
    if (fname.Contains("Data")) {
        TCut trigger = mettrigger.c_str();
        selection += trigger;
        //selection.Print();
      }
      /*
    } else if (process == "Data_METBTag_R" || process == "Data_METBTag_P") {
        TCut trigger = metbtagtrigger.c_str();
        selection += trigger;
        //selection.Print();
    } else if (process == "Data_SingleMu_R" || process == "Data_SingleMu_P") {
        TCut trigger = singlemutrigger.c_str();
        selection += trigger;
        //selection.Print();
    } else if (process == "Data_SingleEl_R" || process == "Data_SingleEl_P") {
        TCut trigger = singleeltrigger.c_str();
        selection += trigger;
        //selection.Print();
    }
      */


    chain->Add(fname);

    // Sum Count, CountWithPU, CountWithPUP, CountWithPUM
    TObjArray * files = chain->GetListOfFiles();
    TIter next(files);
    TChainElement * chainElem = 0;
    TFile * f2 = 0;
    TH1D * h1 = new TH1D("Count", ";Counts", 16, 0, 16);
    TH1F * htemp = 0;

    while ((chainElem = (TChainElement*) next())) {
      //#ifndef XROOTD
      //      f2 = TFile::Open("dcache:" + TString(chainElem->GetTitle()));
      //#else
      std::cout << "chainElem->GetTitle() " << chainElem->GetTitle() << std::endl; 
        f2 = TFile::Open( TString(chainElem->GetTitle()));
	//#endif
        htemp = (TH1F*) f2->Get("Count");
        h1->SetBinContent(1, h1->GetBinContent(1)+htemp->GetBinContent(1));
	/*
        htemp = (TH1F*) f2->Get("CountWithPU");
        h1->SetBinContent(2, h1->GetBinContent(2)+htemp->GetBinContent(1));
        htemp = (TH1F*) f2->Get("CountWithPUP");
        h1->SetBinContent(3, h1->GetBinContent(3)+htemp->GetBinContent(1));
        htemp = (TH1F*) f2->Get("CountWithPUM");
        h1->SetBinContent(4, h1->GetBinContent(4)+htemp->GetBinContent(1));
        htemp = (TH1F*) f2->Get("CountWithMCProd");
        h1->SetBinContent(5, h1->GetBinContent(5)+htemp->GetBinContent(1));
        htemp = (TH1F*) f2->Get("CountWithPUMCProd");
        h1->SetBinContent(6, h1->GetBinContent(6)+htemp->GetBinContent(1));
        htemp = (TH1F*) f2->Get("countWithSignalQCDcorrections");
        h1->SetBinContent(7, h1->GetBinContent(7)+htemp->GetBinContent(1));
        */
        std::clog << fname << ": skimmed from " << chainElem->GetTitle() << std::endl;
    }
    
    // LHE Count
    
    TH1D * h2 = new TH1D("LHECount", ";LHE Counts", 16, 0, 16);
    TString process_lhe = fname;
    if (process_lhe.BeginsWith("WJets"))
        process_lhe = "WJets";
    else if (process_lhe.BeginsWith("ZJets"))
        process_lhe = "ZJets";
    else 
        process_lhe = "";
    const std::vector<std::string>& lhecuts = GetLHECuts(process_lhe.Data());
    for (unsigned int i=0; i < lhecuts.size(); i++) {
        TCut cut2 = lhecuts.at(i).c_str();
        h2->SetBinContent(i+1, chain->GetEntries(cut2));
    }
    
    

    // Make output directory if it doesn't exist
    if (gSystem->AccessPathName(outdir))
        gSystem->mkdir(outdir);
    TString outname = outdir + prefix + Form("%s.root", outputname.Data());
    std::cout << "outname is " << outname << std::endl;

    TFile* f1 = TFile::Open(outname, "RECREATE");
    TTree* t1 = (TTree*) chain->CopyTree(selection);
    std::clog << fname << ": skimmed from " << chain->GetEntriesFast() << " to " << t1->GetEntriesFast() << " entries." << std::endl;
    
    t1->Write();
    h1->Write();
     h2->Write();
    f1->Close();

    return;
}
Пример #8
0
void CalibTree::makeplots(double rmin, double rmax, int ietaMax,
			  bool useweight, double fraction, bool debug) {

  if (fChain == 0) return;
  Long64_t nentryTot = fChain->GetEntriesFast();
  Long64_t nentries = (fraction > 0.01 && fraction < 0.99) ? 
    (Long64_t)(fraction*nentryTot) : nentryTot;

  // Book the histograms
  std::map<int,std::pair<TH1D*,TH1D*> > histos;
  for (int ieta=-ietaMax; ieta<=ietaMax; ++ieta) {
    char name[20], title[100];
    sprintf(name,"begin%d",ieta);
    if (ieta==0) sprintf(title,"Ratio at start");
    else         sprintf(title,"Ratio at start for i#eta=%d",ieta);
    TH1D* h1 = new TH1D(name,title,50,rmin,rmax);
    h1->Sumw2();
    sprintf(name,"end%d",ieta);
    if (ieta==0) sprintf(title,"Ratio at the end");
    else         sprintf(title,"Ratio at the end for i#eta=%d",ieta);
    TH1D* h2 = new TH1D(name,title,50,rmin,rmax);
    h2->Sumw2();
    histos[ieta] = std::pair<TH1D*,TH1D*>(h1,h2);
  }
  //Fill the histograms
  Long64_t nbytes(0), nb(0);
  for (Long64_t jentry=0; jentry<nentries;jentry++) {
    Long64_t ientry = LoadTree(jentry);
    if (ientry < 0) break;
    if (std::find(entries.begin(), entries.end(), jentry) != entries.end()) break;
    nb = fChain->GetEntry(jentry);   nbytes += nb;
    if (goodTrack()) {
      double Etot(0);
      for (unsigned int idet=0; idet<(*t_DetIds).size(); idet++) { 
	double hitEn(0);
	unsigned int id    = (*t_DetIds)[idet];
        unsigned int detid = truncateId(id,truncateFlag_,false);
	if (Cprev.find(detid) != Cprev.end()) 
	  hitEn = Cprev[detid].first * (*t_HitEnergies)[idet];
	else 
	  hitEn = (*t_HitEnergies)[idet];
	if (cFactor_) hitEn *= cFactor_->getCorr(t_Run,id);
	Etot += hitEn;
      }
      double evWt   = (useweight) ? t_EventWeight : 1.0; 
      double pmom   = (useGen_ && (t_gentrackP > 0)) ? t_gentrackP : t_p;
      double ratioi = t_eHcal/(pmom-t_eMipDR);
      double ratiof = Etot/(pmom-t_eMipDR);
      if (t_ieta >= -ietaMax && t_ieta <= ietaMax && t_ieta != 0) {
	if (ratioi>=rmin && ratioi<=rmax) {
	  histos[0].first->Fill(ratioi,evWt);
	  histos[t_ieta].first->Fill(ratioi,evWt);
	}
	if (ratiof>=rmin && ratiof<=rmax) {
	  histos[0].second->Fill(ratiof,evWt);
	  histos[t_ieta].second->Fill(ratiof,evWt);
	}
      }
    }
  }

  //Fit the histograms
  TH1D *hbef1 = new TH1D("Eta1Bf","Mean vs i#eta",2*ietaMax,-ietaMax,ietaMax);
  TH1D *hbef2 = new TH1D("Eta2Bf","Median vs i#eta",2*ietaMax,-ietaMax,ietaMax);
  TH1D *haft1 = new TH1D("Eta1Af","Mean vs i#eta",2*ietaMax,-ietaMax,ietaMax);
  TH1D *haft2 = new TH1D("Eta2Af","Median vs i#eta",2*ietaMax,-ietaMax,ietaMax);
  for (int ieta=-ietaMax; ieta<=ietaMax; ++ieta) {
    int    bin   = (ieta < 0) ? (ieta+ietaMax+1) : (ieta+ietaMax);
    TH1D*  h1    = histos[ieta].first;
    double mean1 = h1->GetMean();
    double err1  = h1->GetMeanError();
    std::pair<double,double> fit1 = fitMean(h1,1);
    if (debug) {
      std::cout << ieta << " " << h1->GetName() << " " << mean1 << " +- " 
		<< err1 << " and " << fit1.first <<" +- " << fit1.second 
		<< std::endl;
    }
    if (ieta != 0) {
      hbef1->SetBinContent(bin,mean1);      hbef1->SetBinError(bin,err1);
      hbef2->SetBinContent(bin,fit1.first); hbef2->SetBinError(bin,fit1.second);
    }
    h1->Write();
    TH1D* h2 = histos[ieta].second;
    double mean2 = h2->GetMean();
    double err2  = h2->GetMeanError();
    std::pair<double,double> fit2 = fitMean(h2,1);
    if (debug) { 
      std::cout << ieta << " " << h2->GetName() << " " << mean2 << " +- " 
		<< err2 << " and " << fit2.first <<" +- " << fit2.second 
		<< std::endl;
    }
    if (ieta != 0) {
      haft1->SetBinContent(bin,mean2);      haft1->SetBinError(bin,err2);
      haft2->SetBinContent(bin,fit2.first); haft2->SetBinError(bin,fit2.second);
    }
    h2->Write();
  }
  fitPol0(hbef1,debug); fitPol0(hbef2,debug);
  fitPol0(haft1,debug); fitPol0(haft2,debug);
}
Пример #9
0
void defineBinning(Int_t   jetChannel = 0 , TString theSample = "WW", Bool_t jetGenVeto = 0 ) {

  gSystem->Load("libRooUnfold");

  TH1::SetDefaultSumw2();

  //TString path = Form("rootfiles/%djet/%s/", jetChannel, flavorChannel.Data());
 
  //gSystem->mkdir(path, kTRUE);
 
 
  //----------------------------------------------------------------------------
  // Input files
  //----------------------------------------------------------------------------

  TString filesPath;

  //filesPath = "/gpfs/csic_projects/tier3data/LatinosSkims/ReducedTrees/DiferentialXSection/";
  filesPath = "/gpfs/csic_projects/cms/calderon/WWGEN/";
  

  TChain* tree = new TChain("latino", "latino");

  //tree->Add(filesPath + "latino_000_WWJets2LMad_OF.root");
  //tree->Add(filesPath + "latinostep3_latinosYieldSkim_MC_WWmg.root");
  //tree->Add(filesPath + "latino_006_WWJets_pow_OF.root");
  //tree->Add(filesPath + "latino_006_WWJets_pow_OF_genJets.root");
  //tree->Add(filesPath + "latino_006_WWJets_pow_OF_genJets_Smear.root");
  //tree->Add(filesPath + "latino_006_WWJets_pow_OF_genJets_nll_ewk_Smear.root");

  //tree->Add(filesPath + "latino_002_WWJets_mcnlo_OF.root");
  //tree->Add(filesPath + "latino_002_WWJets_mcnlo_OF_genJets.root");
  //tree->Add(filesPath + "latino_002_WWJets_mcnlo_OF_genJets_Smear.root");
  //tree->Add(filesPath + "latino_002_WWJets_mcnlo_OF_genJets_nll_ewk_Smear.root");


  //tree->Add(filesPath + "latino_000_WWJets_mad_OF.root");
  //tree->Add(filesPath + "latino_000_WWJets_mad_OF_genJets.root");
  //tree->Add(filesPath + "latino_000_WWJets_mad_OF_genJets_Smear.root");
  //tree->Add(filesPath + "latino_000_WWJets_mad_OF_genJets_nll_ewk_Smear.root");

  //tree->Add(filesPath + "latino_001_GGWWJets_OF.root");
  //tree->Add(filesPath + "latino_001_GGWWJets_OF_genJets_Smear.root");
  //tree->Add(filesPath + "latino_001_GGWWJets_OF_jetSmear_METxy.root");

 


  //-*** Final for data 
  //tree->Add("/gpfs/csic_projects/cms/calderon/WWGEN/finalFilesForData/latino006_nll_ewk.root"); // POW 
  tree->Add("/gpfs/csic_projects/cms/calderon/WWGEN/finalFilesForData/latino_001_GGWWJets_jetSmear_METxy.root"); // GG
  //tree->Add("/gpfs/csic_projects/cms/calderon/WWGEN/finalFilesForData/latino000_nll_ewk.root"); // MAD
  //tree->Add("/gpfs/csic_projects/cms/calderon/WWGEN/finalFilesForData/latino002_nll_ewk.root"); // MCNLO


  //----------------------------------------------------------------------------
  // Define functions
  //----------------------------------------------------------------------------
  Float_t smear (Float_t xt); 

   //----------------------------------------------------------------------------
  // Output files
  //----------------------------------------------------------------------------
  
  //TString path = Form("_GEN_0jet_pow_full.root",  jetChannel); 0,0.25,0.5,0.75,1,1.25,1.5,1.75,2,
  //TString path = Form("_GEN_0jet_mcnlo_full_NNLL_JetGenVeto_Eff_NNLOXsec_NewLumi_NoPU_newMiss.root"); 
  TString path = Form("_GEN_0jet_gg_full_JetGenVeto_Eff_NewLumi_NoPU_newMiss.root");
  //TString path = Form("_gg_tmp.root");

  TFile* output = new TFile( theSample+path, "recreate");


  // Defining binning
  //----------------------------------------------------------------------------

  //Double_t pt1bins[6] = {25,50,100,150,200,400};
  
  Double_t RECOpt1bins[11] = {10,20,40,60,80,100,125,150,175,200,210};
  Double_t GENpt1bins[7] = {10,20,50,100,150,200,210};

  const Int_t pt1Nbin = 9;
  const Int_t ptllNbin = 8; 
  const Int_t mllNbin = 9;
  const Int_t dphiNbin = 13;
  const Int_t jetEtNbin = 10;

  Double_t pt1bins[pt1Nbin] = {20,40,60,80,100,125,150,175,200}; 
  Double_t ptllbins[ptllNbin] = {30,40,50,60,70,85,120,150};
  Double_t mllbins[mllNbin] = {20,40,60,80,100,125,150,175,200};
  Double_t dphibins[dphiNbin] = {0,0.25,0.5,0.75,1,1.25,1.5,1.75,2,2.25,2.5,2.75,3};//{0,0.5,1,1.5,2,2.5,3};
  Double_t jetEtbins[jetEtNbin] = {30,40,50,60,70,80,90,100,110,120}; 


  // Pt, Dilepton, DeltaPhi, Mll

  // GEN level ( phase space)  differential histograms 
  //----------------------------------------------------------------------------

  TH1F* hPtLepton1_GEN  = new TH1F("hPtLepton1_GEN",       "", pt1Nbin-1, pt1bins);
  TH1F* hPtLepton1_RECO  = new TH1F("hPtLepton1_RECO",       "", pt1Nbin-1, pt1bins);
  TH2F* hPtLepton1_RECO_GEN =  new TH2F("hPtLepton1_RECO_GEN", "", pt1Nbin-1, pt1bins, pt1Nbin-1, pt1bins);

  TH1F* hDilepton_GEN  = new TH1F("hDilepton_GEN",       "", ptllNbin-1, ptllbins);
  TH1F* hDilepton_RECO  = new TH1F("hDilepton_RECO",       "", ptllNbin-1, ptllbins);
  TH2F* hDilepton_RECO_GEN =  new TH2F("hDilepton_RECO_GEN", "", ptllNbin-1, ptllbins, ptllNbin-1, ptllbins);

  TH1F* hmll_GEN  = new TH1F("hmll_GEN",       "", mllNbin-1, mllbins);
  TH1F* hmll_RECO  = new TH1F("hmll_RECO",       "",mllNbin-1,  mllbins);
  TH2F* hmll_RECO_GEN =  new TH2F("hmll_RECO_GEN", "", mllNbin-1, mllbins, mllNbin-1, mllbins);

  TH1F* hdphi_GEN  = new TH1F("hdphi_GEN",       "", dphiNbin-1, dphibins);
  TH1F* hdphi_RECO  = new TH1F("hdphi_RECO",       "", dphiNbin-1,  dphibins);
  TH2F* hdphi_RECO_GEN =  new TH2F("hdphi_RECO_GEN", "", dphiNbin-1, dphibins, dphiNbin-1, dphibins);

  TH1F* hjetEt_GEN  = new TH1F("hjetEt_GEN",       "", jetEtNbin-1, jetEtbins);
  TH1F* hjetEt_RECO  = new TH1F("hjetEt_RECO",       "", jetEtNbin-1,  jetEtbins);
  TH2F* hjetEt_RECO_GEN =  new TH2F("hjetEt_RECO_GEN", "", jetEtNbin-1, jetEtbins, jetEtNbin-1, jetEtbins);

  TH1F* hInclusive_GEN  = new TH1F("hInclusive_GEN",       "", 3,0,3);
 

  RooUnfoldResponse responsePtLepton1GEN(hPtLepton1_RECO, hPtLepton1_GEN);
  RooUnfoldResponse responseMllGEN(hmll_RECO, hmll_GEN );
  RooUnfoldResponse responseJetEtGEN(hjetEt_RECO, hjetEt_GEN );


  // WW level differential histograms 
  //----------------------------------------------------------------------------

  TH1F* hPtLepton1WWLevel_RECO  = new TH1F("hPtLepton1WWLevel_RECO",       "", pt1Nbin-1, pt1bins);
  TH1F* hPtLepton1WWLevel_GEN  = new TH1F("hPtLepton1WWLevel_GEN",       "", pt1Nbin-1, pt1bins);
  TH2F* hPtLepton1WWLevel_RECO_GEN =  new TH2F("hPtLepton1WWLevel_RECO_GEN", "", pt1Nbin-1, pt1bins, pt1Nbin-1, pt1bins);

 
  TH1F* hDileptonWWLevel_RECO  = new TH1F("hDileptonWWLevel_RECO",       "", ptllNbin-1, ptllbins);
  TH1F* hDileptonWWLevel_GEN  = new TH1F("hDileptonWWLevel_GEN",       "", ptllNbin-1, ptllbins);
  TH2F* hDileptonWWLevel_RECO_GEN =  new TH2F("hDileptonWWLevel_RECO_GEN", "", ptllNbin-1, ptllbins, ptllNbin-1, ptllbins);

  TH1F* hmllWWLevel_RECO  = new TH1F("hmllWWLevel_RECO",       "", mllNbin-1, mllbins);
  TH1F* hmllWWLevel_GEN  = new TH1F("hmllWWLevel_GEN",       "", mllNbin-1, mllbins);
  TH2F* hmllWWLevel_RECO_GEN =  new TH2F("hmllWWLevel_RECO_GEN", "", mllNbin-1, mllbins,mllNbin-1, mllbins);

  TH1F* hdphiWWLevel_RECO  = new TH1F("hdphiWWLevel_RECO",       "", dphiNbin-1, dphibins);
  TH1F* hdphiWWLevel_GEN  = new TH1F("hdphiWWLevel_GEN",       "", dphiNbin-1, dphibins);
  TH2F* hdphiWWLevel_RECO_GEN =  new TH2F("hdphiWWLevel_RECO_GEN", "", dphiNbin-1, dphibins,dphiNbin-1, dphibins);

  TH1F* hjetEtWWLevel_GEN  = new TH1F("hjetEtWWLevel_GEN",       "", jetEtNbin-1, jetEtbins);
  TH1F* hjetEtWWLevel_RECO  = new TH1F("hjetEtWWLevel_RECO",       "", jetEtNbin-1,  jetEtbins);
  TH2F* hjetEtWWLevel_RECO_GEN =  new TH2F("hjetEtWWLevel_RECO_GEN", "", jetEtNbin-1, jetEtbins, jetEtNbin-1, jetEtbins);
  
  TH1D* hPtLepton1WWLevel_nonselected = new TH1D("hPtLepton1WWLevel_nonselected", "hPtLepton1WWLevel_nonselected",pt1Nbin-1, pt1bins);

  TH1F* hdeltaR = new TH1F("hdeltaR", "hdeltaR", 50,0,0.1);

  TH1F* hgenJetEt = new TH1F("hgenJetEt", "hgenJetEt", 100,0,100);
  TH1F* hrecoJetEt = new TH1F("hrecoJetEt", "hrecoJetEt", 100,0,100);
  TH2F* hJetEt_Gen_Reco = new TH2F("hJetEt_Gen_Reco", "hJetEt_Gen_Reco", 100,0,100,100,0,100);

  TH1F* hInclusiveWWLevel_GEN  = new TH1F("hInclusiveWWLevel_GEN",       "",3,0,3);
  TH1F* hInclusiveWWLevel_RECO  = new TH1F("hInclusiveWWLevel_RECO",       "",3,0,3);


  // WW level  define response matrix
  
  RooUnfoldResponse responsePtLepton1(hPtLepton1WWLevel_RECO, hPtLepton1WWLevel_GEN);

  RooUnfoldResponse responseDilepton(hDileptonWWLevel_RECO, hDileptonWWLevel_GEN);

  RooUnfoldResponse responseMll(hmllWWLevel_RECO, hmllWWLevel_GEN );

  RooUnfoldResponse responseDphi(hdphiWWLevel_RECO , hdphiWWLevel_GEN);

  RooUnfoldResponse responseJetEt(hjetEtWWLevel_RECO , hjetEtWWLevel_GEN);

  RooUnfoldResponse responseInclusive(hInclusiveWWLevel_RECO, hInclusiveWWLevel_GEN );

  // Declaration of leaf types
  //----------------------------------------------------------------------------

  Float_t baseW;        tree->SetBranchAddress("baseW"       , &baseW);
  Float_t channel;      tree->SetBranchAddress("channel"     , &channel);
  Float_t chmet;        tree->SetBranchAddress("chmet"       , &chmet);
  Float_t dataset;      tree->SetBranchAddress("dataset"     , &dataset);
  Float_t dphill;       tree->SetBranchAddress("dphill"      , &dphill);
  Float_t dphilljet;    tree->SetBranchAddress("dphilljet"   , &dphilljet);
  Float_t dphilljetjet; tree->SetBranchAddress("dphilljetjet", &dphilljetjet);
  Float_t drll;         tree->SetBranchAddress("drll"        , &drll);
  Float_t effW;         tree->SetBranchAddress("effW"        , &effW);
  Float_t jetphi1;      tree->SetBranchAddress("jetphi1"     , &jetphi1);
  Float_t jetphi2;      tree->SetBranchAddress("jetphi2"     , &jetphi2);
  Float_t jetphi3;      tree->SetBranchAddress("jetphi3"     , &jetphi3);
  Float_t jeteta1;      tree->SetBranchAddress("jeteta1"     , &jeteta1);
  Float_t jeteta2;      tree->SetBranchAddress("jeteta2"     , &jeteta2);
  Float_t jeteta3;      tree->SetBranchAddress("jeteta3"     , &jeteta3);
  Float_t jetpt1;       tree->SetBranchAddress("jetpt1"      , &jetpt1);
  Float_t jetpt2;       tree->SetBranchAddress("jetpt2"      , &jetpt2);
  Float_t jetpt3;       tree->SetBranchAddress("jetpt3"      , &jetpt3);
  Float_t jettche1;     tree->SetBranchAddress("jettche1"    , &jettche1);
  Float_t jettche2;     tree->SetBranchAddress("jettche2"    , &jettche2);
  Float_t mctruth;      tree->SetBranchAddress("mctruth"     , &mctruth);
  Float_t mll;          tree->SetBranchAddress("mll"         , &mll);
  Float_t mpmet;        tree->SetBranchAddress("mpmet"       , &mpmet); 
  Float_t mth;          tree->SetBranchAddress("mth"         , &mth);
  Float_t nbjet;        tree->SetBranchAddress("nbjet"       , &nbjet);
  Float_t nbjettche;    tree->SetBranchAddress("nbjettche"   , &nbjettche);
  Float_t nextra;       tree->SetBranchAddress("nextra"      , &nextra);
  Float_t njet;         tree->SetBranchAddress("njet"        , &njet);
  Float_t nvtx;         tree->SetBranchAddress("nvtx"        , &nvtx);
  Float_t pchmet;       tree->SetBranchAddress("pchmet"      , &pchmet);
  Float_t pfmet;        tree->SetBranchAddress("pfmet"       , &pfmet);
  Float_t ppfmet;       tree->SetBranchAddress("ppfmet"      , &ppfmet);
  Float_t isomva1;      tree->SetBranchAddress("isomva1"     , &isomva1);
  Float_t isomva2;      tree->SetBranchAddress("isomva2"     , &isomva2);
  Float_t pt1;          tree->SetBranchAddress("pt1"         , &pt1);
  Float_t pt2;          tree->SetBranchAddress("pt2"         , &pt2);
  Float_t pt3;          tree->SetBranchAddress("pt3"         , &pt3);
  Float_t phi1;         tree->SetBranchAddress("phi1"         , &phi1);
  Float_t dymva1;       tree->SetBranchAddress("dymva1"         , &dymva1);
  Float_t phi2;         tree->SetBranchAddress("phi2"         , &phi2);
  Float_t eta1;         tree->SetBranchAddress("eta1"         , &eta1);
  Float_t eta2;         tree->SetBranchAddress("eta2"         , &eta2);
  Float_t ch1;          tree->SetBranchAddress("ch1"         , &ch1);
  Float_t ch2;          tree->SetBranchAddress("ch2"         , &ch2);
  Float_t ptll;         tree->SetBranchAddress("ptll"        , &ptll);
  Float_t softtche;     tree->SetBranchAddress("softtche"    , &softtche);
  Float_t trigger;      tree->SetBranchAddress("trigger"     , &trigger);
  Float_t triggW;       tree->SetBranchAddress("triggW"      , &triggW);
  Int_t   bveto;        tree->SetBranchAddress("bveto"       , &bveto);
  Int_t   bveto_ip;     tree->SetBranchAddress("bveto_ip"    , &bveto_ip);
  Int_t   bveto_mu;     tree->SetBranchAddress("bveto_mu"    , &bveto_mu);
  Int_t   bveto_nj30;   tree->SetBranchAddress("bveto_nj30"  , &bveto_nj30);
  Int_t   dphiveto;     tree->SetBranchAddress("dphiveto"    , &dphiveto);
  Int_t   sameflav;     tree->SetBranchAddress("sameflav"    , &sameflav);
  Int_t   zveto;        tree->SetBranchAddress("zveto"       , &zveto);
  UInt_t  event;        tree->SetBranchAddress("event"       , &event);
  UInt_t  lumi;         tree->SetBranchAddress("lumi"        , &lumi);
  UInt_t  run;          tree->SetBranchAddress("run"         , &run);
  Float_t puW;          tree->SetBranchAddress("puW"         , &puW);
  

  // Apply NNLL resummation 
  Float_t nllW = 1; //tree->SetBranchAddress("nllW", &nllW);

// GEN info... 


//Define Status1 leptons 

  Float_t lepGenpt1, lepGenpt2, lepGenpt3;
  tree->SetBranchAddress("genVV_S1lepton1_pt", &lepGenpt1);
  tree->SetBranchAddress("genVV_S1lepton2_pt", &lepGenpt2);
  tree->SetBranchAddress("genVV_S1lepton3_pt", &lepGenpt3);

  Float_t lepGeneta1, lepGeneta2, lepGeneta3;
  tree->SetBranchAddress("genVV_S1lepton1_eta", &lepGeneta1);
  tree->SetBranchAddress("genVV_S1lepton2_eta", &lepGeneta2);
  tree->SetBranchAddress("genVV_S1lepton3_eta", &lepGeneta3);

  Float_t lepGenphi1, lepGenphi2, lepGenphi3;
  tree->SetBranchAddress("genVV_S1lepton1_phi", &lepGenphi1);
  tree->SetBranchAddress("genVV_S1lepton2_phi", &lepGenphi2);
  tree->SetBranchAddress("genVV_S1lepton3_phi", &lepGenphi3);

  Float_t lepGenM1, lepGenM2, lepGenM3;
  tree->SetBranchAddress("genVV_S1lepton1_oVpid", &lepGenM1); 
  tree->SetBranchAddress("genVV_S1lepton2_oVpid", &lepGenM2); 
  tree->SetBranchAddress("genVV_S1lepton3_oVpid", &lepGenM3); 

  Float_t lepGenimTau1, lepGenimTau2, lepGenimTau3;
  tree->SetBranchAddress("genVV_S1lepton1_imTau", &lepGenimTau1); 
  tree->SetBranchAddress("genVV_S1lepton2_imTau", &lepGenimTau2); 
  tree->SetBranchAddress("genVV_S1lepton3_imTau", &lepGenimTau3); 

  Float_t lepGenpid1, lepGenpid2, lepGenpid3;
  tree->SetBranchAddress("genVV_S1lepton1_pid", &lepGenpid1);
  tree->SetBranchAddress("genVV_S1lepton2_pid", &lepGenpid2);
  tree->SetBranchAddress("genVV_S1lepton3_pid", &lepGenpid3);

  Float_t lepGenS3pid1, lepGenS3pid2, lepGenS3pid3;
  tree->SetBranchAddress("genVV_lepton1_pid", &lepGenS3pid1);
  tree->SetBranchAddress("genVV_lepton2_pid", &lepGenS3pid2);
  tree->SetBranchAddress("genVV_lepton3_pid", &lepGenS3pid3);

  Float_t lepGenS3M1, lepGenS3M2, lepGenS3M3;
  tree->SetBranchAddress("genVV_lepton1_oVpid", &lepGenS3M1); 
  tree->SetBranchAddress("genVV_lepton2_oVpid", &lepGenS3M2); 
  tree->SetBranchAddress("genVV_lepton3_oVpid", &lepGenS3M3); 

  Float_t jetGen1_pt, jetGen2_pt, jetGen3_pt, jetGen4_pt, jetGen5_pt;
  tree->SetBranchAddress("genVV_jet1_pt", &jetGen1_pt);
  tree->SetBranchAddress("genVV_jet2_pt", &jetGen2_pt);
  tree->SetBranchAddress("genVV_jet3_pt", &jetGen3_pt);
  tree->SetBranchAddress("genVV_jet4_pt", &jetGen4_pt);  
  tree->SetBranchAddress("genVV_jet5_pt", &jetGen5_pt);

  Float_t jetGen1_eta, jetGen2_eta, jetGen3_eta, jetGen4_eta, jetGen5_eta;
  tree->SetBranchAddress("genVV_jet1_eta", &jetGen1_eta);
  tree->SetBranchAddress("genVV_jet2_eta", &jetGen2_eta);
  tree->SetBranchAddress("genVV_jet3_eta", &jetGen3_eta);
  tree->SetBranchAddress("genVV_jet4_eta", &jetGen4_eta);  
  tree->SetBranchAddress("genVV_jet5_eta", &jetGen5_eta);

  Float_t jetGen1_phi, jetGen2_phi, jetGen3_phi, jetGen4_phi, jetGen5_phi;
  tree->SetBranchAddress("genVV_jet1_phi", &jetGen1_phi);
  tree->SetBranchAddress("genVV_jet2_phi", &jetGen2_phi);
  tree->SetBranchAddress("genVV_jet3_phi", &jetGen3_phi);
  tree->SetBranchAddress("genVV_jet4_phi", &jetGen4_phi);  
  tree->SetBranchAddress("genVV_jet5_phi", &jetGen5_phi);

// 

 

 // Set the channel
  //----------------------------------------------------------------------------
  Float_t SelectedChannel = -999;

  /*  if      (flavorChannel == "MuMu") SelectedChannel =  0;
  else if (flavorChannel == "EE"  ) SelectedChannel =  1;
  else if (flavorChannel == "EMu" ) SelectedChannel =  2;
  else if (flavorChannel == "MuE" ) SelectedChannel =  3;
  else if (flavorChannel == "All" ) SelectedChannel = -1;
  */

  int kk = 0;

 //----------------------------------------------------------------------------
  // Loop
  //----------------------------------------------------------------------------
  

  // Float_t Nentries = 179545; 
  //Float_t Nentries = 187525;
  Float_t Nentries = 10745; // with powheg 
  //Float_t Nentries = 9792; // with madgraph 

  for (int ievent=0; ievent<tree->GetEntriesFast(); ievent++) {
  //for (int ievent=0; ievent<Nentries; ievent++) {
  //for (int ievent=Nentries; ievent<tree->GetEntriesFast(); ievent++) {
   
    tree->GetEntry(ievent);

    //Double_t mybaseW =  5984.0/1933235;//5812.3/1933235; // madgraph (1933232)
    //Double_t mybaseW = 5984.0/999864;//  5812.3/999864; // powheg (999860)
    Double_t mybaseW = 182.852 /109986; // GGWW 
    //Double_t mybaseW = 5984.0/539594; //5812.3/539594; // mcnlo



    Float_t luminosity = 19.365;

    Double_t efficiencyW =  effW * triggW * puW;
    // Double_t totalW = effW * triggW * baseW * efficiencyW * luminosity;

    Double_t totalW = puW * mybaseW * luminosity;//efficiencyW;

    Double_t totalWGen = nllW *  mybaseW * luminosity ; //Removing PU from gen level
    
    Double_t totalWReco =  effW * triggW * puW * nllW *  mybaseW * luminosity;// * effW * triggW ;//puW *  mybaseW * luminosity;//puW * effW * triggW * mybaseW * luminosity;

  
    // The GEN selection begins here
    //--------------------------------------------------------------------------
    
    /// ---> 1) Need status 1 leptons to define the same fiducial region
    /// ---> 2) Count how many GEN leptons we have in each bin, applying the fidual region cuts
    /// ---> 3) Apply also, OF, jetbin and opposite-charged cuts.
    
    
    bool genEvent = false; 

    /*
    if ( fabs(lepGenpid1) > 20 ) continue;
    if ( fabs(lepGenpid2) > 20 ) continue;
    
    //Select the pair of leptons coming from the two Ws   

    if (fabs(lepGenM1)!= 24) continue; 
    if (fabs(lepGenM2)!= 24) continue; 
    
    if (lepGenpt1 <= 20) continue;  
    if (lepGenpt2 <= 20) continue;
    
    if ( fabs(lepGenpid1) == fabs(lepGenpid2) ) continue;
    
    if ( (fabs(lepGenpid1) == 13 && fabs(lepGeneta1) >= 2.4) || 
	 (fabs(lepGenpid1) == 11 && fabs(lepGeneta1) >= 2.5)) continue;

    if ( (fabs(lepGenpid2) == 13 && fabs(lepGeneta2) >= 2.4) || 
	 (fabs(lepGenpid2) == 11 && fabs(lepGeneta2) >= 2.5)) continue;
    


    // If jet veto at GEN level
    //--------------------------------------------------------------------------

    Int_t nGenJets = 0, nGenJet1 = 0, nGenJet2 = 0, nGenJet3 = 0, nGenJet4 = 0, nGenJet5 = 0; 
  
    if ( jetGen1_pt>=30 ) nGenJet1++;
    if ( jetGen2_pt>=30 ) nGenJet2++;
    if ( jetGen3_pt>=30 ) nGenJet3++;
    if ( jetGen4_pt>=30 ) nGenJet4++;
    if ( jetGen5_pt>=30 ) nGenJet5++;
   
    nGenJets = nGenJet1 + nGenJet2 + nGenJet3 + nGenJet4 + nGenJet5; 
    
    if ( jetGenVeto && nGenJets > 0 )  continue;

    if ( jetChannel && nGenJets != 1 ) continue;
    */


    if ( fabs(lepGenpid1) <= 20  && 
	 fabs(lepGenpid1) <= 20  && 
    	 fabs(lepGenM1)== 24 &&  
	 fabs(lepGenM2)== 24 && 
	 lepGenpt1 > 20 &&  
	 lepGenpt2 > 20 &&
	 fabs(lepGenpid1) != fabs(lepGenpid2) &&  
	 ((fabs(lepGenpid1) == 13 && fabs(lepGeneta1) < 2.4) || 
	  (fabs(lepGenpid1) == 11 && fabs(lepGeneta1) < 2.5)) &&  
	 ((fabs(lepGenpid2) == 13 && fabs(lepGeneta2) < 2.4) || 
	  (fabs(lepGenpid2) == 11 && fabs(lepGeneta2) < 2.5)) )  { 


	   // If jet veto at GEN level
	   //--------------------------------------------------------------------------

	   Int_t nGenJets = 0, nGenJet1 = 0, nGenJet2 = 0, nGenJet3 = 0, nGenJet4 = 0, nGenJet5 = 0; 
  
	   if ( jetGen1_pt>=30 ) nGenJet1++;
	   if ( jetGen2_pt>=30 ) nGenJet2++;
	   if ( jetGen3_pt>=30 ) nGenJet3++;
	   if ( jetGen4_pt>=30 ) nGenJet4++;
	   if ( jetGen5_pt>=30 ) nGenJet5++;
	   
	   nGenJets = nGenJet1 + nGenJet2 + nGenJet3 + nGenJet4 + nGenJet5; 
    
	   if (jetGenVeto && nGenJets < 1 )  genEvent = true;

	 } 



    Float_t dileptonGenPt;
    Float_t mllGen;
    Float_t dphiGen;

    TLorentzVector leptonGen1p4;
    TLorentzVector leptonGen2p4;
    leptonGen1p4.SetPtEtaPhiM(lepGenpt1, lepGeneta1, lepGenphi1, 0.0);
    leptonGen2p4.SetPtEtaPhiM(lepGenpt2, lepGeneta2, lepGenphi2, 0.0);   

  
    Float_t Genpt1S = smear(lepGenpt1);    
    
    dileptonGenPt = (leptonGen1p4+leptonGen2p4).Pt();
    mllGen = (leptonGen1p4+leptonGen2p4).M();
    dphiGen = fabs(leptonGen1p4.DeltaPhi(leptonGen2p4));


    
    if  (genEvent ) {

      hPtLepton1_GEN->Fill(lepGenpt1, totalWGen);//*baseW*luminosity*0.00300652); // leading pt ---> which pt should I store here? 
    
      hDilepton_GEN->Fill(dileptonGenPt,totalWGen); // ptll 
    
      hmll_GEN->Fill(mllGen,totalWGen); // mll
      
      hdphi_GEN->Fill(dphiGen,totalWGen); // deltaPhi

      hjetEt_GEN->Fill(jetGen1_pt, totalWGen); 

      hInclusive_GEN->Fill(1, totalWGen);
    }
    
    // The RECO selection begins here. The RECO leptons are supposed to pass the ID+ISO selection already? 
    //----------------------------------------------------------------------------------------------------
  
    TLorentzVector lepton1p4;
    TLorentzVector lepton2p4;
    lepton1p4.SetPtEtaPhiM(pt1, eta1, phi1, 0.0);
    lepton2p4.SetPtEtaPhiM(pt2, eta2, phi2, 0.0);
   

    Float_t dileptonPt = (lepton1p4+lepton2p4).Pt();
    Float_t mll = (lepton1p4+lepton2p4).M();
    Float_t deltaphill = fabs(lepton1p4.DeltaPhi(lepton2p4));

 
    hPtLepton1_RECO_GEN->Fill(pt1, lepGenpt1, totalW);
    hPtLepton1_RECO->Fill(pt1, totalWReco);

    hDilepton_RECO->Fill(dileptonPt, totalW);
    hDilepton_RECO_GEN->Fill(dileptonPt, dileptonGenPt, totalW);

    hmll_RECO->Fill(mll, totalW);
    hmll_RECO_GEN->Fill(mll, mllGen , totalW);

    hdphi_RECO->Fill(dphill, totalW);
    hdphi_RECO_GEN->Fill(dphill,dphiGen , totalW);
 
    hjetEt_RECO->Fill(jetpt1, totalW);
    hjetEt_RECO_GEN->Fill(jetpt1, jetGen1_pt, totalW);


    // ---->>> Fill Response matrix to do only unfolding on resolution
    //         without any selection efficiency propagated, but fiducial region as reco one.

    responsePtLepton1GEN.Fill(pt1, lepGenpt1, totalWReco);
    responseMllGEN.Fill(mll, mllGen, totalWReco);

 

    /// ---> 3) Going to apply the selection analysis cuts on RECO objects

    Int_t dphiv = (njet <= 1 || (njet > 1 && dphilljetjet < 165.*TMath::DegToRad()));
    
    Float_t metvar = (njet <= 1) ? mpmet : pfmet;
    
    Float_t jetbin = njet;
    
    Float_t dyMVA = ( !sameflav || ( (njet!=0 || dymva1>0.88) && (njet!=1 || dymva1>0.84) && ( njet==0 || njet==1 || (pfmet > 45.0)) ) );


    Bool_t isMatched = true; 
    Bool_t isMatchedGEN = true; 
    Bool_t isMatchedRECO = true; 
    Float_t deltaR = 9999.9;
   
    hgenJetEt->Fill(jetGen1_pt );
    
    

    if(  pt1 > 20 && pt2 > 20  && !sameflav && ch1*ch2 < 0 &&
	 trigger == 1                        &&
	 nextra == 0                         && 
	 pfmet > 20                          &&
	 mll > 12                            &&
	 (zveto==1 || !sameflav)             &&
	 (mpmet > 20  && dyMVA)              &&
	 (dphiv || !sameflav)                &&
	 bveto_mu                            &&
	 ptll>30 && (!sameflav || ptll>45 )  &&
	 jetbin == jetChannel                && 
	 (bveto_ip==1 &&  nbjettche==0)   
	 ){
     
	//hgenJetEt->Fill(jetGen1_pt );
	hrecoJetEt->Fill(jetpt1);
	hJetEt_Gen_Reco->Fill(jetGen1_pt, jetpt1);

	//	cout << jetGen1_pt << "  "  <<jetpt1  << endl;

	// if (true) {	     




      // DEFINE MATCHING RECO - GEN
      //--------------------------------------------------------------------------
    
	//if ( lepton1p4.DeltaR(leptonGen1p4) >= 0.15 )isMatchedGEN = false;//&& lepton1p4.DeltaR(leptonGen2p4) >= 0.15 )  isMatchedGEN = false;

	if ( lepton1p4.DeltaR(leptonGen1p4) >= 0.15 && lepton1p4.DeltaR(leptonGen2p4) >= 0.15 )  isMatchedGEN = false;
	
	if ( leptonGen1p4.DeltaR(lepton1p4) >= 0.15 && leptonGen1p4.DeltaR(lepton2p4) >= 0.15 )  isMatchedRECO = false; 
   


	Float_t pt1S = smear(pt1);

	//Float_t pt1S = linearW(pt1, 0.006);
	
	
	//cout << totalWReco  << endl;

	
	hPtLepton1WWLevel_RECO->Fill(pt1,    totalWReco); 
	hPtLepton1WWLevel_GEN->Fill(lepGenpt1,totalW);
	hPtLepton1WWLevel_RECO_GEN->Fill(pt1,lepGenpt1, totalW);
	
	hDileptonWWLevel_RECO->Fill(dileptonPt,        totalWReco); 
	hDileptonWWLevel_GEN->Fill(dileptonGenPt,totalW);
	hDileptonWWLevel_RECO_GEN->Fill(dileptonPt,dileptonGenPt , totalW);
	
	hmllWWLevel_RECO->Fill(mll,        totalWReco); 
	hmllWWLevel_GEN->Fill(mllGen,totalW);
	hmllWWLevel_RECO_GEN->Fill(mll , mllGen, totalW);
	
	hdphiWWLevel_RECO->Fill(dphill,        totalWReco); 
	hdphiWWLevel_GEN->Fill(dphiGen,totalW);
	hdphiWWLevel_RECO_GEN->Fill(dphill,dphiGen, totalW);
	
	hjetEtWWLevel_RECO->Fill(jetpt1, totalWReco);
	hjetEtWWLevel_GEN->Fill( jetGen1_pt, totalWReco);
	hjetEtWWLevel_RECO_GEN->Fill(jetpt1, jetGen1_pt, totalW);

	hInclusiveWWLevel_GEN->Fill(1, totalWGen);
	hInclusiveWWLevel_RECO->Fill(1,   totalWReco);

	
	//---- Fill response matrix ( we have always with our selection 2 gen leptons and 2 reco leptons)
	if  (genEvent) {

	  responsePtLepton1.Fill(pt1, lepGenpt1, totalWReco);
	  responseDilepton.Fill(dileptonPt, dileptonGenPt, totalWReco);
	  responseMll.Fill(mll, mllGen, totalWReco);
	  responseDphi.Fill(dphill, dphiGen, totalWReco);
	  responseInclusive.Fill(1, 1, totalWReco);


	  responsePtLepton1.Miss(lepGenpt1, (1-efficiencyW)*totalWGen );
	  responseDilepton.Miss(dileptonGenPt, (1-efficiencyW)*totalWGen);
	  responseMll.Miss(mllGen, (1-efficiencyW)*totalWGen);
	  responseDphi.Miss(dphiGen, (1-efficiencyW)*totalWGen);
	  responseInclusive.Miss(1, (1-efficiencyW)*totalWGen);
	  


	} else {
	  
	  responsePtLepton1.Fake(pt1, totalWReco);
	  responseDilepton.Fake(dileptonPt, totalWReco);
	  responseMll.Fake(mll,  totalWReco);
	  responseDphi.Fake(dphill, totalWReco);
	  responseInclusive.Fake(1, totalWReco);
	}
   
    } else {	

      if  (genEvent) {
	hPtLepton1WWLevel_nonselected->Fill(lepGenpt1, totalW);
	
	//---- Fill response matrix with efficiency 
	
	responsePtLepton1.Miss(lepGenpt1, totalWGen);
	responseDilepton.Miss(dileptonGenPt, totalWGen);
	responseMll.Miss(mllGen, totalWGen);
	responseDphi.Miss(dphiGen, totalWGen);

	responseInclusive.Miss(1, totalWGen);
   
      }

    }
	   





    /*
	//---- Fill response matrix 	
	
	if (isMatchedGEN ) {
	  
	  responsePtLepton1.Fill(pt1, lepGenpt1, totalWReco);
	  responseDilepton.Fill(dileptonPt, dileptonGenPt, totalWReco);
	  responseMll.Fill(mll, mllGen, totalWReco);
	  responseDphi.Fill(dphill, dphiGen, totalWReco);
	  
	  //      }	else if (!isMatchedGEN ) { 


	} else { 
	   
	  responsePtLepton1.Fake(pt1, totalWReco);
	  responseDilepton.Fake(dileptonPt, totalWReco);
	  responseMll.Fake(mll,  totalWReco);
	  responseDphi.Fake(dphill, totalWReco);
	  
	  if (!isMatchedRECO) responsePtLepton1.Miss(lepGenpt1, totalWGen);
	  
	  //cout << "Not found matched GEN !!! " << endl;
	    
	  //	responsePtLepton1.Miss(lepGenpt1, totalWGen);
	        
	} 

	 } else {	
 
	hPtLepton1WWLevel_nonselected->Fill(lepGenpt1, totalW);
	
	//---- Fill response matrix with efficiency 
	
	responsePtLepton1.Miss(lepGenpt1, totalWGen);
	responseDilepton.Miss(dileptonGenPt, totalWGen);
	responseMll.Miss(mllGen, totalWGen);
	responseDphi.Miss(dphiGen, totalWGen);
	 }
	 
*/

    
    }
 
  // Save the histograms
  //----------------------------------------------------------------------------
  output->cd();
  responsePtLepton1GEN.Write();
  responseMllGEN.Write();
  responseJetEtGEN.Write();
  responsePtLepton1.Write();
  responseDilepton.Write();
  responseMll.Write();
  responseDphi.Write();
  responseInclusive.Write();
  output->Write("", TObject::kOverwrite);
  output->Close();



  // Define binning 

  


  
}
Пример #10
0
void Hyperon(const char* dataset="collection.xml")
{
  /* $Id$ */
  TStopwatch timer;
  timer.Start();


    TStringToken libs("Core,Tree,Geom,VMC,Physics,Minuit,Gui,XMLParser,Minuit2,Proof,STEERBase,ESD,AOD,OADB,ANALYSIS,ANALYSISalice,CDB,RAWDatabase,STEER,CORRFW,PHOSUtils,PHOSbase,PHOSpi0Calib,PHOSrec,PHOSshuttle,PHOSsim", ",");
  while( libs.NextToken() )
    gSystem->Load( Form("lib%s", libs.Data()) );

  gSystem->Load("libTree");
  gSystem->Load("libGeom");
  gSystem->Load("libVMC");
  gSystem->Load("libPhysics");
  gSystem->Load("libPWGGAGammaConv");
  gSystem->Load("libPWGGAHyperon");
  
  //load analysis framework
  gSystem->Load("libANALYSIS");
  gSystem->Load("libANALYSISalice"); //AliAnalysisTaskSE
  
  // Connect to alien
  TString token = gSystem->Getenv("GRID_TOKEN") ;
  if (1) // token == "OK" ) 
    TGrid::Connect("alien://");
  else 
    AliInfo("You are not connected to the GRID") ; 

  cout << "Pi0Analysis: processing collection " << dataset << endl;

  // Create the chain
  TChain* chain = new TChain("aodTree");

  TGridCollection * collection = dynamic_cast<TGridCollection*>(TAlienCollection::Open(dataset));
  
  TAlienResult* result = collection->GetGridResult("",0 ,0);
  TList* rawFileList = result->GetFileInfoList();
  
  for (Int_t counter=0 ; counter < rawFileList->GetEntries() ; counter++) {
    TFileInfo * fi =  static_cast<TFileInfo*>(rawFileList->At(counter)) ; 
    const char * rawFile = fi->GetCurrentUrl()->GetUrl() ;  
    printf("Processing %s\n", rawFile) ;
    chain->Add(rawFile);
    printf("Chain: %d entries.\n",chain->GetEntriesFast()); 
  }

  // Make the analysis manager
  AliAnalysisManager *mgr = new AliAnalysisManager("Hyperon");
  mgr->SetCommonFileName("histos.root");
  
  // AOD input handler
  AliAODInputHandler* aodH = new AliAODInputHandler();
  mgr->SetInputEventHandler(aodH);

  
  // Debug level
  mgr->SetDebugLevel(2);

   gROOT->LoadMacro("$ALICE_PHYSICS/OADB/macros/AddTaskCentrality.C"); 
   AliCentralitySelectionTask* taskCentrality = AddTaskCentrality(); 
   if (analysisMC) 
    taskCentrality->SetMCInput(); 

  // // Update it for Hyperon (YK 22.01.2015)
  // gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskEventplane.C");
  // AliEPSelectionTask *taskEP = AddTaskEventplane() ; 

  // gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskVZEROEPSelection.C");
  // AliVZEROEPSelectionTask *selTask = AddTaskVZEROEPSelection();  

  // Add my task
  AliAnalysisHyperon* task = new AliAnalysisHyperon();
  // gROOT->LoadMacro("$ALICE_ROOT/PWGGA/PHOSTasks/PHOS_PbPb/AddTaskPHOSPi0Flow.C"); // Update it for Hyperon (YK 22.01.2015)
  // task = AddTaskPHOSPi0Flow();

  
  // // Create containers for input/output
  AliAnalysisDataContainer *cinput   = mgr->GetCommonInputContainer(); 
  AliAnalysisDataContainer *coutput1 = mgr->CreateContainer("Hyperon",TList::Class(),AliAnalysisManager::kOutputContainer,"HyperonHist.root");
  
  // // Connect input/output
  mgr->ConnectInput(task , 0, cinput);
  mgr->ConnectOutput(task, 1, coutput1);
 
  if (mgr->InitAnalysis()) {
    mgr->PrintStatus();
    mgr->StartAnalysis("local", chain);
  }

  timer.Stop();
  timer.Print();
}
Пример #11
0
void readTree(TString filelist="/global/project/projectdirs/star/pwg/starhf/zamiller/minBiasTemplates101015/Trees.list",TString outFile="/global/project/projectdirs/star/pwg/starhf/zamiller/minBiasTemplates101015/readTreeOutSubmitTEST.root")
{

  //TString filelist=Form("%s/%s",localDir,fileIn);
  //TString outFile=Form("%s/%s",outDir,fileOut);

  TFile fout(outFile,"RECREATE");
  TH1F::SetDefaultSumw2(); 
  TH1D::SetDefaultSumw2(); 

  for(Int_t c=0; c< numPtBins; c++)
  {
    lowpt[c] = anaConst::lpt[c];
    highpt[c] = anaConst::hpt[c];
  }
  for(Int_t ptbin = 0; ptbin < numPtBins; ptbin++)
  {
    hdEtaRawce[ptbin] = new TH1D(Form("hdEtaRawce_%i",ptbin),"hdEtaRawce",100, -5,5);
    hdEtaRawbe[ptbin] = new TH1D(Form("hdEtaRawbe_%i",ptbin),"hdEtaRawbe",100, -5,5);
    hEventTallyce[ptbin] = new TH1D(Form("ceEventTally_%i",ptbin),"ceEvent Tally",1,0,1);
    hEventTallybe[ptbin] = new TH1D(Form("beEventTally_%i",ptbin),"beEvent Tally",1,0,1);
    hEventTallybce[ptbin] = new TH1D(Form("bceEventTally_%i",ptbin),"bceEvent Tally",1,0,1);
    hdPhiRawce[ptbin] = new TH1D(Form("hdPhiRawce_%i",ptbin),"hdPhiRawce",Phibin, -10,10);
    hdPhiRawbe[ptbin] = new TH1D(Form("hdPhiRawbe_%i",ptbin),"hdPhiRawbe",Phibin, -10,10);
    hdPhiRawbce[ptbin] = new TH1D(Form("hdPhiRawbce_%i",ptbin),"hdPhiRawbce",Phibin, -10,10);
    hept[ptbin] = new TH1D(Form("hept_%i",ptbin),"hept",200,0.,20.);
  }

  // Make Chain
  TChain* chain = new TChain("tree");
  int nfile = 0;
  /*  nfile += chain->Add("Oct30_set13/pythia_tree_Oct30_13.root");
      nfile += chain->Add("Oct30_set14/pythia_tree_Oct30_14.root");
      nfile += chain->Add("Oct30_set15/pythia_tree_Oct30_15.root");
      nfile += chain->Add("Oct30_set16/pythia_tree_Oct30_16.root");
      nfile += chain->Add("Oct30_set17/pythia_tree_Oct30_17.root");
  //  nfile += chain->Add("Oct30_set12/pythia_tree_Oct30_12.root");
  //  nfile += chain->Add("Oct26_set3/pythia_tree_Oct26_3.root");
  // nfile += chain->Add("Oct18_set4/pythia_tree_Oct18_4.root");
  //nfile += chain->Add("liweiTemplate_part2.root");*/
  char filename[1000];
  ifstream fstream(filelist.Data());
  int ifile = 0;
  while (fstream >> filename)
  {
    nfile+= chain->Add(filename);
    std::cout << "Got File: " << filename << std::endl;
  }

  std::cout <<"Added "<<nfile<<" files"<<std::endl;
  std::cout<<"# entries in chain: "<<chain->GetEntries()<<std::endl;
  if (chain == 0) return;

  int ceNtrigger=0;
  int beNtrigger=0;
  int bceNtrigger=0;
  int ptbin,maxptbin;

  //define variables
  Int_t   Event, numberofcElectrons, numberofbElectrons,numberofbcElectrons, numberofHadrons, noTracks;   //
  Float_t celectron_id,celectron_status,celectron_pt,celectron_pz,celectron_phi,celectron_eta,celectron_y;                //track info
  Float_t belectron_id,belectron_status,belectron_pt,belectron_pz,belectron_phi,belectron_eta,belectron_y;
  Float_t bcelectron_id,bcelectron_status,bcelectron_pt,bcelectron_pz,bcelectron_phi,bcelectron_eta,bcelectron_y;
  Float_t assoh_id,assoh_status,assoh_pt,assoh_pz,assoh_phi,assoh_eta,assoh_y;

  int goodEvent = 0;


  Long64_t nentries = chain->GetEntriesFast();
  int x = 0; int n = nentries; int w = 25;

  for(int i = 0; i < nentries; i++){
    Long64_t ientry = chain->LoadTree(i);
    if (ientry < 0) break;
    TBranch *b_destep = chain->GetBranch("hf2eDecay");

    TLeaf* leaf_Event_id            = b_destep->GetLeaf("Event_id");
    TLeaf* leaf_refMult             = b_destep->GetLeaf("refMult");
    TLeaf* leaf_numberofcElectrons  = b_destep->GetLeaf("numberofcElectrons");
    TLeaf* leaf_numberofbElectrons  = b_destep->GetLeaf("numberofbElectrons");
    TLeaf* leaf_numberofbcElectrons = b_destep->GetLeaf("numberofbcElectrons");
    TLeaf* leaf_numberofHadrons     = b_destep->GetLeaf("numberofHadrons");
    TLeaf* leaf_noTracks            = b_destep->GetLeaf("noTracks");

    TLeaf* leaf_ce_id               = b_destep->GetLeaf("ce_id");
    TLeaf* leaf_ce_status           = b_destep->GetLeaf("ce_status");
    TLeaf* leaf_ce_pt               = b_destep->GetLeaf("ce_pt");
    TLeaf* leaf_ce_pz               = b_destep->GetLeaf("ce_pz");
    TLeaf* leaf_ce_phi              = b_destep->GetLeaf("ce_phi");
    TLeaf* leaf_ce_eta              = b_destep->GetLeaf("ce_eta");
    TLeaf* leaf_ce_y                = b_destep->GetLeaf("ce_y");

    TLeaf* leaf_be_id               = b_destep->GetLeaf("be_id");
    TLeaf* leaf_be_status           = b_destep->GetLeaf("be_status");
    TLeaf* leaf_be_pt               = b_destep->GetLeaf("be_pt");
    TLeaf* leaf_be_pz               = b_destep->GetLeaf("be_pz");
    TLeaf* leaf_be_phi              = b_destep->GetLeaf("be_phi");
    TLeaf* leaf_be_eta              = b_destep->GetLeaf("be_eta");
    TLeaf* leaf_be_y                = b_destep->GetLeaf("be_y");

    TLeaf* leaf_bce_id              = b_destep->GetLeaf("bce_id");
    TLeaf* leaf_bce_status          = b_destep->GetLeaf("bce_status");
    TLeaf* leaf_bce_pt              = b_destep->GetLeaf("bce_pt");
    TLeaf* leaf_bce_pz              = b_destep->GetLeaf("bce_pz");
    TLeaf* leaf_bce_phi             = b_destep->GetLeaf("bce_phi");
    TLeaf* leaf_bce_eta             = b_destep->GetLeaf("bce_eta");
    TLeaf* leaf_bce_y               = b_destep->GetLeaf("bce_y");

    TLeaf* leaf_hadron_id           = b_destep->GetLeaf("hadron_id");
    TLeaf* leaf_hadron_status       = b_destep->GetLeaf("hadron_status");
    TLeaf* leaf_hadron_pt           = b_destep->GetLeaf("hadron_pt");
    TLeaf* leaf_hadron_pz           = b_destep->GetLeaf("hadron_pz");
    TLeaf* leaf_hadron_phi          = b_destep->GetLeaf("hadron_phi");
    TLeaf* leaf_hadron_eta          = b_destep->GetLeaf("hadron_eta");
    TLeaf* leaf_hadron_y            = b_destep->GetLeaf("hadron_y");

    x = i+1;
    // Process Completion bar
    if ( (x != n) && (x % (n/100) == 0) )
    {
      float ratio  =  (float)x/(float)n;
      int   c      =  ratio * w;

      if(ratio < 1){
        std::cout << (int)(ratio*100) << "% [";
        for (int x=0; x<c; x++) std::cout << "=";
        for (int x=c; x<w; x++) std::cout << " ";
        std::cout << "]\r" << std::flush ;
      }
    }


    // if(i%10000 == 0)
    //   std::cout <<"Entry: "<< i << std::endl;
    chain->GetEntry(i);

    Event   = (int)leaf_Event_id->GetValue(0);
    numberofcElectrons = (int)leaf_numberofcElectrons->GetValue(0);
    // std::cout << numberofcElectrons << " ";
    numberofbElectrons = (int)leaf_numberofbElectrons->GetValue(0);
    numberofbcElectrons = (int)leaf_numberofbcElectrons->GetValue(0);
    numberofHadrons = (int)leaf_numberofHadrons->GetValue(0);
    // std::cout << "numHad: " << numberofHadrons << std::endl;
    noTracks        = leaf_noTracks->GetValue(0);
    hrefmult -> Fill(noTracks);

    //loop through matched primary tracks electron find c decayed electron
    int ceNtrigcount=0;
    maxptbin = 0;
    for(int trki = 0; trki < numberofcElectrons; trki++){
      celectron_id      = (int)leaf_ce_id->GetValue(trki);
      celectron_status  = (int)leaf_ce_status->GetValue(trki);
      celectron_pt      = leaf_ce_pt->GetValue(trki);
      celectron_pz      = leaf_ce_pz->GetValue(trki);
      celectron_phi     = leaf_ce_phi->GetValue(trki);
      celectron_eta     = leaf_ce_eta->GetValue(trki);
      celectron_y       = leaf_ce_y->GetValue(trki);
      if(celectron_eta > EtaCut || celectron_eta < -EtaCut) continue;
      ptbin = getPtBin(celectron_pt);
      if(ptbin == -99) continue;
      if(ptbin > maxptbin)
        maxptbin = ptbin;
      hept[ptbin]->Fill(celectron_pt);
      hEventTallyce[maxptbin]->Fill(0.5); //fill for each NPE

      for(int trkj = 0; trkj < numberofHadrons; trkj++){

        assoh_id = (int)leaf_hadron_id->GetValue(trkj);
        assoh_status  = (int)leaf_hadron_status->GetValue(trkj);
        assoh_pt      = leaf_hadron_pt->GetValue(trkj);
        assoh_pz      = leaf_hadron_pz->GetValue(trkj);
        assoh_phi     = leaf_hadron_phi->GetValue(trkj);
        assoh_eta     = leaf_hadron_eta->GetValue(trkj);
        assoh_y       = leaf_hadron_y->GetValue(trkj);
        if(assoh_eta > hEtaCut || assoh_eta < -hEtaCut) continue;

        float deltPhi = assoh_phi - celectron_phi;
        float deltEta = assoh_eta - celectron_eta;
        if(deltPhi < -PI)  deltPhi += 2*PI;
        if(deltPhi >  PI) deltPhi -= 2*PI;
        if(abs(deltEta) > deletacut) continue;
        if(assoh_pt>hptCut)
        {
          hdPhiRawce[ptbin]->Fill(deltPhi); 
          hdEtaRawce[ptbin]->Fill(deltEta);
          ceNtrigcount++;
        }
      }
    }
    //if(ceNtrigcount>0)hEventTallyce[maxptbin]->Fill(0.5);
    //if(ceNtrigcount>0)ceNtrigger++;

    //b decayed electron-------------------------------------------------- 
    int beNtrigcount=0;
    maxptbin = 0;
    for(int trki = 0; trki < numberofbElectrons; trki++){
      belectron_id = (int)leaf_be_id->GetValue(trki);
      belectron_status  = (int)leaf_be_status->GetValue(trki);
      belectron_pt      = leaf_be_pt->GetValue(trki);
      belectron_pz      = leaf_be_pz->GetValue(trki);
      belectron_phi     = leaf_be_phi->GetValue(trki);
      belectron_eta     = leaf_be_eta->GetValue(trki);
      belectron_y        = leaf_be_y->GetValue(trki);
      if(belectron_eta > EtaCut || belectron_eta < -EtaCut) continue;
      ptbin = getPtBin(belectron_pt);
      if(ptbin == -99) continue;
      if(ptbin > maxptbin)
        maxptbin = ptbin;
      hept[ptbin]->Fill(belectron_pt);
      hEventTallybe[maxptbin]->Fill(0.5); //fill for each NPE
      for(int trkj = 0; trkj < numberofHadrons; trkj++){

        assoh_id = (int)leaf_hadron_id->GetValue(trkj);
        assoh_status  = (int)leaf_hadron_status->GetValue(trkj);
        assoh_pt      = leaf_hadron_pt->GetValue(trkj);
        assoh_pz      = leaf_hadron_pz->GetValue(trkj);
        assoh_phi     = leaf_hadron_phi->GetValue(trkj);
        assoh_eta     = leaf_hadron_eta->GetValue(trkj);
        assoh_y       = leaf_hadron_y->GetValue(trkj);
        if(assoh_eta > hEtaCut || assoh_eta < -hEtaCut) continue;

        float deltPhi = assoh_phi - belectron_phi;
        float deltEta = assoh_eta - belectron_eta;
        if(deltPhi < -PI)  deltPhi += 2*PI;
        if(deltPhi >  PI) deltPhi -= 2*PI;
        if(abs(deltEta) > deletacut) continue;
        if(assoh_pt>hptCut)
        {
          hdPhiRawbe[ptbin]->Fill(deltPhi);
          hdEtaRawbe[ptbin]->Fill(deltEta);  
          beNtrigcount++;
        }
      }
    }
    //    if(beNtrigcount>0)hEventTallybe[maxptbin]->Fill("be non photonic electron",1);
    //    if(beNtrigcount>0)beNtrigger++;
    //bce decayed electron-----------------------------------------------------------------                                                                                           
    int bceNtrigcount=0;
    maxptbin = 0;
    for(int trki = 0; trki < numberofbcElectrons; trki++){
      bcelectron_id = (int)leaf_bce_id->GetValue(trki);
      bcelectron_status  = (int)leaf_bce_status->GetValue(trki);
      bcelectron_pt      = leaf_bce_pt->GetValue(trki);
      bcelectron_pz      = leaf_bce_pz->GetValue(trki);
      bcelectron_phi     = leaf_bce_phi->GetValue(trki);
      bcelectron_eta     = leaf_bce_eta->GetValue(trki);
      bcelectron_y       = leaf_bce_y->GetValue(trki);
      if(bcelectron_eta > EtaCut || bcelectron_eta < -EtaCut) continue;
      ptbin = getPtBin(bcelectron_pt);
      if(ptbin == -99) continue;
      if(ptbin > maxptbin)
        maxptbin = ptbin;
      hept[ptbin]->Fill(bcelectron_pt);
      hEventTallybe[maxptbin]->Fill(0.5); //fill for each NPE
      for(int trkj = 0; trkj < numberofHadrons; trkj++){

        assoh_id = (int)leaf_hadron_id->GetValue(trkj);
        assoh_status  = (int)leaf_hadron_status->GetValue(trkj);
        assoh_pt      = leaf_hadron_pt->GetValue(trkj);
        assoh_pz      = leaf_hadron_pz->GetValue(trkj);
        assoh_phi     = leaf_hadron_phi->GetValue(trkj);
        assoh_eta     = leaf_hadron_eta->GetValue(trkj);
        assoh_y       = leaf_hadron_y->GetValue(trkj);
        if(assoh_eta > hEtaCut || assoh_eta < -hEtaCut) continue;

        float deltPhi = assoh_phi - bcelectron_phi;
        float deltEta = assoh_eta - celectron_eta;
        if(deltPhi < -PI)  deltPhi += 2*PI;
        if(deltPhi >  PI) deltPhi -= 2*PI;
        if(abs(deltEta) > deletacut) continue;
        if(assoh_pt>hptCut)
        {
          hdPhiRawbe[ptbin]->Fill(deltPhi);
          hdEtaRawbe[ptbin]->Fill(deltEta);  
          bceNtrigcount++;
        }
      }
    }
    //    if(bceNtrigcount>0)hEventTallybe[maxptbin]->Fill("be non photonic electron",1);
    //    if(bceNtrigcount>0)beNtrigger++;


    /* if(ceNtrigger+bceNtrigger+beNtrigger > 0){
       std::cout<<"ce Trigger electron number = "<<ceNtrigger<<std::endl;
       std::cout<<"be Trigger electron number = "<<beNtrigger<<std::endl;
       std::cout<<"bce Trigger electron number = "<<bceNtrigger<<std::endl;
       }*/
  }

  // After Fill Manipulations
  for(int qq = 0; qq < numPtBins; qq++)
  {
    hdPhiRawceN[qq] = (TH1D*)hdPhiRawce[qq]->Clone();
    hdPhiRawceN[qq] -> SetName(Form("hdPhiRawceN_%i",qq));
    hdPhiRawceN[qq] -> Sumw2();
    hdPhiRawceN[qq] -> Scale(1./(Double_t)hEventTallyce[qq]->GetBinContent(1));
    hdPhiRawbeN[qq] = (TH1D*)hdPhiRawbe[qq]->Clone();
    hdPhiRawbeN[qq] -> SetName(Form("hdPhiRawbeN_%i",qq));
    hdPhiRawbeN[qq] -> Sumw2();
    hdPhiRawbeN[qq] -> Scale(1./(Double_t)hEventTallybe[qq]->GetBinContent(1));
  }

  std::cout << "100% [";
  for (int x=0; x<w; x++) std::cout << "=";
  std::cout << "]" << std::endl;
  fout.Write();
  fout.Close();
  delete chain;
}
Пример #12
0
void analyzePFCandidates(std::vector<std::string> urls, const char *outname = "eventObjects.root", Long64_t nentries = 20, Int_t firstF = -1, Int_t lastF = -1) {

  // std::vector<std::string> urls = CollectFiles(list);

  // Printf("anaFile: %d",anaFile);
  
  std::cout << "nfiles: " << urls.size() << std::endl;
  for (auto i = urls.begin(); i != urls.end(); ++i)
    std::cout << *i << std::endl;

  size_t firstFile = 0;
  size_t lastFile = urls.size();

  if(firstF>-1) {
    firstFile = (size_t)firstF;
    lastFile = (size_t)lastF;
  }
  std::cout << "firstFile: " << firstFile << "  lastFile: " << lastFile << std::endl;
  
  //add files to chain
  TChain *chain = NULL;
//  chain = new TChain("hiEvtAnalyzer/HiTree");
  //for(size_t i=firstFile; i<lastFile; i++) chain->Add(urls[i].c_str());
  //Printf("hiTree done");
  
  //TChain *pfTree = new TChain("pfcandAnalyzer/pfTree");
  chain = new TChain("pfcandAnalyzer/pfTree");
  //for(size_t i=firstFile; i<lastFile; i++) pfTree->Add(urls[i].c_str());
  for(size_t i=firstFile; i<lastFile; i++) chain->Add(urls[i].c_str());  
  //chain->AddFriend(pfTree);
  Printf("pfTree done");
  
  // TChain *muTree = new TChain("hltMuTree/HLTMuTree");
  // for(size_t i=firstFile; i<lastFile; i++) muTree->Add(urls[i].c_str());
  // chain->AddFriend(muTree);
  // Printf("muTree done");

  TChain *jetTree = new TChain("ak4PFJetAnalyzer/t");//akPu4CaloJetAnalyzer/t");
  for(size_t i=firstFile; i<lastFile; i++) jetTree->Add(urls[i].c_str());
  chain->AddFriend(jetTree);
  Printf("jetTree done");

  TChain *hltTree = new TChain("hltanalysis/HltTree");
  for(size_t i=firstFile; i<lastFile; i++) hltTree->Add(urls[i].c_str());
  chain->AddFriend(hltTree);
  Printf("hltTree done");

  TChain *skimTree = new TChain("skimanalysis/HltTree");
  for(size_t i=firstFile; i<lastFile; i++) skimTree->Add(urls[i].c_str());
  chain->AddFriend(skimTree);
  Printf("skimTree done");
  
  if(doTracks) {
    //    TChain *trackTree = new TChain("anaTrack/trackTree");
    TChain *trackTree = new TChain("ppTrack/trackTree");
    for(size_t i=firstFile; i<lastFile; i++) trackTree->Add(urls[i].c_str());
    chain->AddFriend(trackTree);
    Printf("trackTree done");
  }
  // TChain *genTree = new TChain("HiGenParticleAna/hi");
  // for(size_t i=firstFile; i<lastFile; i++) genTree->Add(urls[i].c_str());
  // chain->AddFriend(genTree);
  // Printf("genTree done");
  
  TList *fEventObjects = new TList();


  //---------------------------------------------------------------
  // producers
  //
  hiEventProducer *p_evt = new hiEventProducer("hiEvtProd");
  p_evt->SetInput(chain);
  p_evt->SetHIEventContName("hiEventContainer");
  p_evt->SetEventObjects(fEventObjects);

  pfParticleProducer *p_pf = new pfParticleProducer("pfPartProd");
  p_pf->SetInput(chain);
  p_pf->SetpfParticlesName("pfParticles");
  p_pf->SetEventObjects(fEventObjects);

  lwJetFromForestProducer *p_PUJet = new lwJetFromForestProducer("lwJetForestProd");
  p_PUJet->SetInput(chain);
  p_PUJet->SetJetContName("akt4PF");
  p_PUJet->SetGenJetContName("akt4Gen");
  p_PUJet->SetEventObjects(fEventObjects);
  p_PUJet->SetRadius(0.4);

  trackProducer *p_trk = new trackProducer("trackProd");
  if(doTracks) {
    p_trk->SetInput(chain);
    p_trk->SetTracksName("tracks");
    p_trk->SetEventObjects(fEventObjects);
  }
  
  //---------------------------------------------------------------
  //analysis modules
  //

  //handler to which all modules will be added
  anaBaseTask *handler = new anaBaseTask("handler","handler");

  anaPFCandidates *anaPFCandJet = new anaPFCandidates("pfCandWithPFJets","pfCandWithPFJets");
  anaPFCandJet->ConnectEventObject(fEventObjects);
//  anaPFCandJet->SetHiEvtName("hiEventContainer");
  anaPFCandJet->SetParticlesName("pfParticles");
  anaPFCandJet->SetJetsName("akt4PF");
  handler->Add(anaPFCandJet);

  anaPFCandidates *anaPF = new anaPFCandidates("pfCand","pfCand");
  anaPF->ConnectEventObject(fEventObjects);
  //anaPF->SetHiEvtName("hiEventContainer");
  anaPF->SetParticlesName("pfParticles");
  anaPF->SetJetsName("akt4Gen");
  handler->Add(anaPF);

  anaPFCandidates *anaTrkCaloJet = new anaPFCandidates("tracksWithCaloJets","tracksWithCaloJets");
  anaTrkCaloJet->ConnectEventObject(fEventObjects);
  //anaTrkCaloJet->SetHiEvtName("hiEventContainer");
  anaTrkCaloJet->SetParticlesName("tracks");
  anaTrkCaloJet->SetJetsName("aktPu4Calo");
  if(doTracks) handler->Add(anaTrkCaloJet);

  anaPFCandidates *anaTrk = new anaPFCandidates("tracksWithGenJet","tracksWithGenJet");
  anaTrk->ConnectEventObject(fEventObjects);
  //anaTrk->SetHiEvtName("hiEventContainer");
  anaTrk->SetParticlesName("tracks");
  anaTrk->SetJetsName("akt4Gen");
  if(doTracks) handler->Add(anaTrk);
  
  //---------------------------------------------------------------
  //Event loop
  //---------------------------------------------------------------	  
  Long64_t entries_tot =  chain->GetEntriesFast(); //93064
  if(nentries<0) nentries = chain->GetEntries();
  // Long64_t nentries = 20;//chain->GetEntriesFast();
  Printf("nentries: %lld  tot: %lld",nentries,entries_tot);
  for (Long64_t jentry=0; jentry<nentries;jentry++) {

    //Run producers
    // Printf("produce hiEvent");
    // p_evt->Run(jentry);   //hi event properties
    //Printf("produce pf particles");
    p_pf->Run(jentry);    //pf particles
    if(doTracks) p_trk->Run(jentry);    //tracks
    p_PUJet->Run(jentry); //jets
    
    //Execute all analysis tasks
    handler->ExecuteTask();
  }
    
  fEventObjects->Print();

  TFile *out = new TFile(outname,"RECREATE");
  TList *tasks = handler->GetListOfTasks();
  TIter next(tasks);
  anaBaseTask *obj;
  while ((obj = dynamic_cast<anaBaseTask*>(next()) ))
    if(obj->GetOutput()) obj->GetOutput()->Write(obj->GetName(),TObject::kSingleKey);
  
  out->Write();
  out->Close();
  
}
Пример #13
0
void analyzeZJetMCResponse(std::vector<std::string> urls, const char *outname = "eventObjects.root", Long64_t nentries = 20, Int_t firstF = -1, Int_t lastF = -1, Int_t firstEvent = 0) {

  TString jetName = "aktPuppiR040";
  TString jetTreeName = "akPuppi4PFJetAnalyzer";
  jetName = "aktPuR030"; //"aktCsR040";
  jetTreeName = "akPu3PFJetAnalyzer"; //"akCs4PFJetAnalyzer"; //akCs4PFJetAnalyzer

  std::cout << "analyzing Z-jet response for: " << jetName << " tree: " << jetTreeName << std::endl;
  
  std::cout << "nfiles: " << urls.size() << std::endl;
  for (auto i = urls.begin(); i != urls.end(); ++i)
    std::cout << *i << std::endl;

  size_t firstFile = 0;
  size_t lastFile = urls.size();

  if(firstF>-1) {
    firstFile = (size_t)firstF;
    lastFile = (size_t)lastF;
  }
  std::cout << "firstFile: " << firstFile << "  lastFile: " << lastFile << std::endl;

  Int_t lastEvent = nentries;
  if(firstEvent>0) {
    lastEvent = firstEvent + nentries;
  }
  
  //add files to chain
  TChain *chain = NULL;
  chain = new TChain("hiEvtAnalyzer/HiTree");
  for(size_t i=firstFile; i<lastFile; i++) chain->Add(urls[i].c_str());
  Printf("hiTree done");

  // TChain *hltTree = new TChain("hltanalysis/HltTree");
  // for(size_t i=firstFile; i<lastFile; i++) hltTree->Add(urls[i].c_str());
  // chain->AddFriend(hltTree);
  // Printf("hltTree done");

  // TChain *skimTree = new TChain("skimanalysis/HltTree");
  // for(size_t i=firstFile; i<lastFile; i++) skimTree->Add(urls[i].c_str());
  // chain->AddFriend(skimTree);
  // Printf("skimTree done");

  // TChain *muTree = new TChain("ggHiNtuplizer/EventTree");
  // for(size_t i=firstFile; i<lastFile; i++) muTree->Add(urls[i].c_str());
  // chain->AddFriend(muTree);
  // Printf("muTree done");

  TChain *genTree = new TChain("HiGenParticleAna/hi");
  for(size_t i=firstFile; i<lastFile; i++) genTree->Add(urls[i].c_str());
  //chain->AddFriend(genTree);
  Printf("genTree done: %d",(int)genTree->GetEntries());

  TChain *jetTree = new TChain(Form("%s/t",jetTreeName.Data()));
  for(size_t i=firstFile; i<lastFile; i++) jetTree->Add(urls[i].c_str());
  chain->AddFriend(jetTree);
  Printf("jetTree done");

  TList *fEventObjects = new TList();

  //---------------------------------------------------------------
  // producers
  //
  hiEventProducer *p_evt = new hiEventProducer("hiEvtProd");
  p_evt->SetInput(chain);
  p_evt->SetHIEventContName("hiEventContainer");
  p_evt->SetEventObjects(fEventObjects);

  lwMuonProducer *p_mu = new lwMuonProducer("lwMuonProd");
  p_mu->SetInput(chain);
  p_mu->SetlwMuonsRecoName("lwMuonsReco");
  p_mu->SetlwMuonsGeneName("");
  p_mu->SetEventObjects(fEventObjects);

  genParticleProducer *p_gen = new genParticleProducer("genParticleProd");
  p_gen->SetInput(genTree);
  p_gen->SetGenParticlesName("genParticles");
  p_gen->SetEventObjects(fEventObjects);

  lwJetFromForestProducer *p_PUJet = new lwJetFromForestProducer("lwJetForestProd");
  p_PUJet->SetInput(chain);
  p_PUJet->SetJetContName(jetName);
  p_PUJet->SetGenJetContName("");//akt4Gen");
  p_PUJet->SetEventObjects(fEventObjects);
  p_PUJet->SetRadius(0.4);

  //---------------------------------------------------------------
  //analysis modules
  //

  //handler to which all modules will be added
  anaBaseTask *handler = new anaBaseTask("handler","handler");

  //Z to mumu
  anaZToMuMu *ZToMuMu = new anaZToMuMu("ZToMuMu","ZToMuMu");
  ZToMuMu->ConnectEventObject(fEventObjects);
  ZToMuMu->SetHiEvtName("hiEventContainer");
  ZToMuMu->SetMuonsName("genParticles");
  ZToMuMu->SetCheckPid(true);
  ZToMuMu->SetZsName("zMuMuBosons");
  handler->Add(ZToMuMu);

  anaZJetMCResponse *ZResp = new anaZJetMCResponse("ZJetMCResponse","ZJetMCResponse");
  ZResp->ConnectEventObject(fEventObjects);
  ZResp->SetHiEvtName("hiEventContainer");
  ZResp->SetZsName("zMuMuBosons");
  ZResp->SetJetsName(jetName);
  ZResp->SetNCentBins(3);
  handler->Add(ZResp);


 //---------------------------------------------------------------
  //Event loop
  //---------------------------------------------------------------	  
  Long64_t entries_tot =  chain->GetEntriesFast(); //93064
  if(nentries<0) lastEvent = chain->GetEntries();
  // Long64_t nentries = 20;//chain->GetEntriesFast();
  Printf("nentries: %lld  tot: %lld",nentries,entries_tot);
  for (Long64_t jentry=firstEvent; jentry<lastEvent; ++jentry) {
     if (jentry%10000==0) Printf("Processing event %d  %d",(int)(jentry), (int)(lastEvent));
    //Run producers
    // Printf("produce hiEvent");
    p_evt->Run(jentry);   //hi event properties

    //Printf("produce pf particles");
    p_gen->Run(jentry);   //gen particles
    p_PUJet->Run(jentry); //jets
    
    //Execute all analysis tasks
    handler->ExecuteTask();
  }
    
  fEventObjects->Print();

  TFile *out = new TFile(outname,"RECREATE");
  TList *tasks = handler->GetListOfTasks();
  TIter next(tasks);
  anaBaseTask *obj;
  while ((obj = dynamic_cast<anaBaseTask*>(next()) ))
    if(obj->GetOutput()) obj->GetOutput()->Write(obj->GetName(),TObject::kSingleKey);
  
  out->Write();
  out->Close();
  
}