Example #1
0
void TestCorrections(double rawPt, double rawEta, double rawPhi, double rawE, double JPTE, int NPV)
{
  gROOT->ProcessLine("#include <vector>");
  gSystem->Load("libFWCoreFWLite.so");
  FWLiteEnabler::enable();
  ////////////// Construct the JetCorrectorParameters objects ///////////////////////
  string L1Tag    = "../data/Jec11V0_L1Offset_AK5JPT.txt"; 
  string L1JPTTag = "../data/Jec11V0_L1JPTOffset_AK5JPT.txt"; 
  JetCorrectorParameters *L1Par    = new JetCorrectorParameters(L1Tag);
  JetCorrectorParameters *L1JPTPar = new JetCorrectorParameters(L1JPTTag);
  vector<JetCorrectorParameters> vPar;
  vPar.push_back(*L1Par);
  vPar.push_back(*L1JPTPar);
  ////////////// Construct a FactorizedJetCorrector object //////////////////////
  FactorizedJetCorrector *JetCorrector = new FactorizedJetCorrector(vPar);
  ////////////// Loop over jets //////////////////////
  TLorentzVector rawJetP4(0);
  rawJetP4.SetPtEtaPhiE(rawPt,rawEta,rawPhi,rawE);
  JetCorrector->setJPTrawP4(rawJetP4); 
  JetCorrector->setJetE(JPTE);
  JetCorrector->setNPV(NPV);
  vector<float> vcor;
  vcor = JetCorrector->getSubCorrections();
  cout<<"Correction applied to JPT jet after L1Offset = "<<vcor[0]<<endl;
  cout<<"Correction applied to JPT jet after L1JPTOffset = "<<vcor[1]<<endl;
}
int NeroPuppiFatJets::analyze(const edm::Event& iEvent)
{

    if ( mOnlyMc  ) return 0;

    if ( mMinId == "none" ) return 0;

    // maybe handle should be taken before
    iEvent.getByToken(token, handle);
    iEvent.getByToken(rho_token,rho_handle);
    
    TString tPrefix(cachedPrefix);

    edm::Handle<reco::PFJetCollection> subjets_handle;
    edm::InputTag subjetLabel("PFJetsSoftDrop"+tPrefix,"SubJets");
    //iEvent.getByLabel(subjetLabel,subjets_handle);
    iEvent.getByToken(subjets_token,subjets_handle);
    const reco::PFJetCollection *subjetCol = subjets_handle.product();
    assert(subjets_handle.isValid());

    edm::Handle<reco::JetTagCollection> btags_handle;
    //iEvent.getByLabel(edm::InputTag((tPrefix+"PFCombinedInclusiveSecondaryVertexV2BJetTags").Data()),btags_handle);
    iEvent.getByToken(btags_token,btags_handle);
    assert((btags_handle.isValid()));

    FactorizedJetCorrector *corrector = ( iEvent.isRealData() ) ? mDataJetCorrector : mMCJetCorrector;

    int ijetRef = -1;
    int nsubjet = 0;
    
          
    for (const pat::Jet& j : *handle)
    {
        ijetRef++;

        if (fabs(j.eta() ) > mMaxEta)  continue; 
        if ( !NeroPuppiJets::JetId(j,mMinId) ) continue;
        // pT cut applied after applying JEC if necessary

        // GET  ValueMaps

        // Fill output object   

          // this was reclustered from mini AOD, so we have to apply JEC, etc

          edm::RefToBase<pat::Jet> jetRef(edm::Ref<pat::JetCollection>(handle,ijetRef));

          double jecFactor=0;
          if (fabs(j.eta())<5.191) {
            corrector->setJetPt(j.pt());
            corrector->setJetEta(j.eta());
            corrector->setJetPhi(j.phi());
            corrector->setJetE(j.energy());
            corrector->setRho(*rho_handle);
            corrector->setJetA(j.jetArea());
            corrector->setJetEMF(-99.0);
            jecFactor = corrector->getCorrection();
          }

          if (j.pt()*jecFactor < mMinPt)  continue;
          rawPt -> push_back (j.pt());
          new ( (*p4)[p4->GetEntriesFast()]) TLorentzVector(j.px()*jecFactor, j.py()*jecFactor, j.pz()*jecFactor, j.energy()*jecFactor);

          tau1 -> push_back(j.userFloat(tPrefix+"Njettiness:tau1"));
          tau2 -> push_back(j.userFloat(tPrefix+"Njettiness:tau2"));
          tau3 -> push_back(j.userFloat(tPrefix+"Njettiness:tau3"));
  
          softdropMass->push_back(j.userFloat(tPrefix+"SDKinematics:Mass")*jecFactor);
    
          unsigned int nsubjetThisJet=0;
          firstSubjet->push_back(nsubjet);

          for (reco::PFJetCollection::const_iterator i = subjetCol->begin(); i!=subjetCol->end(); ++i) {
            if (reco::deltaR(i->eta(),i->phi(),j.eta(),j.phi())>jetRadius) continue;
            nsubjetThisJet++;
           
            new ( (*subjet)[nsubjet]) TLorentzVector(i->px(), i->py(), i->pz(), i->energy());
            nsubjet++;

            reco::JetBaseRef sjBaseRef(reco::PFJetRef(subjets_handle,i-subjetCol->begin()));
            subjet_btag->push_back((float)(*(btags_handle.product()))[sjBaseRef]);
          }

          nSubjets->push_back(nsubjetThisJet);

    }
    return 0;
}