1212// ***********************************************************
1313PFAnalyzer::PFAnalyzer (const edm::ParameterSet& pSet) {
1414 m_directory = " ParticleFlow" ;
15+ m_isMiniAOD= true ;
1516 parameters_ = pSet.getParameter <edm::ParameterSet>(" pfAnalysis" );
1617
18+ // patPfCandidateCollection_ = consumes<pat::PFParticleCollection>(pSet.getParameter<edm::InputTag>("pfCandidates"));
19+ patPfCandidateCollection_ = consumes<pat::PackedCandidateCollection>(pSet.getParameter <edm::InputTag>(" pfCandidates" ));
20+ patJetsToken_ = consumes<pat::JetCollection>(pSet.getParameter <edm::InputTag>(" pfJetCollection" ));
21+
1722 thePfCandidateCollection_ = consumes<reco::PFCandidateCollection>(pSet.getParameter <edm::InputTag>(" pfCandidates" ));
1823 pfJetsToken_ = consumes<reco::PFJetCollection>(pSet.getParameter <edm::InputTag>(" pfJetCollection" ));
1924
@@ -23,8 +28,8 @@ PFAnalyzer::PFAnalyzer(const edm::ParameterSet& pSet) {
2328 triggerResultsToken_ = consumes<edm::TriggerResults>(edm::InputTag (theTriggerResultsLabel_));
2429 m_triggerOptions = pSet.getParameter <vstring>(" TriggerNames" );
2530
26- srcWeights = pSet.getParameter <edm::InputTag>(" srcWeights" );
27- weightsToken_ = consumes<edm::ValueMap<float >>(srcWeights);
31+ // srcWeights = pSet.getParameter<edm::InputTag>("srcWeights");
32+ // weightsToken_ = consumes<edm::ValueMap<float>>(srcWeights);
2833
2934 m_pfNames = {" allPFC" , " neutralHadPFC" , " chargedHadPFC" , " electronPFC" , " muonPFC" , " gammaPFC" , " hadHFPFC" , " emHFPFC" };
3035 vertexTag_ = pSet.getParameter <edm::InputTag>(" PVCollection" );
@@ -592,19 +597,19 @@ int PFAnalyzer::getBinNumbers(std::vector<double> binVal, std::vector<std::vecto
592597 return bin;
593598}
594599
595- int PFAnalyzer::getPFBin (const reco::PFCandidate pfCand, int i) {
600+ int PFAnalyzer::getPFBin (const reco::PFCandidate pfCand, const pat::PackedCandidate packedCand, bool isMini, int i) {
596601 std::vector<double > binVals;
597602 for (unsigned int j = 0 ; j < m_fullCutList[i].size (); j++) {
598- binVals.push_back (m_funcMap[m_fullCutList[i][j]](pfCand));
603+ binVals.push_back (m_funcMap[m_fullCutList[i][j]](pfCand, packedCand, isMini ));
599604 }
600605
601606 return getBinNumbers (binVals, m_binList[i]);
602607}
603608
604- int PFAnalyzer::getJetBin (const reco::PFJet jetCand, int i) {
609+ int PFAnalyzer::getJetBin (const reco::Jet jetCand, const std::vector<reco::PFCandidatePtr> pfCands , int i) {
605610 std::vector<double > binVals;
606611 for (unsigned int j = 0 ; j < m_fullJetCutList[i].size (); j++) {
607- binVals.push_back (m_jetFuncMap[m_fullJetCutList[i][j]](jetCand));
612+ binVals.push_back (m_jetFuncMap[m_fullJetCutList[i][j]](jetCand, pfCands ));
608613 }
609614
610615 return getBinNumbers (binVals, m_jetBinList[i]);
@@ -618,9 +623,6 @@ void PFAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup
618623 eventWeight = genEventInfo->weight ();
619624 }
620625
621- // weights_ = &iEvent.get(weightsToken_);
622-
623-
624626 // Vertex information
625627 edm::Handle<reco::VertexCollection> vertexHandle;
626628 iEvent.getByToken (vertexToken_, vertexHandle);
@@ -648,42 +650,98 @@ void PFAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup
648650 return ;
649651 std::string npvString = Form (" npv_%.0f_%.0f" , m_npvBins[npvBin], m_npvBins[npvBin + 1 ]);
650652
651- // **** Get the TriggerResults container
652- edm::Handle<edm::TriggerResults> triggerResults;
653- iEvent.getByToken (triggerResultsToken_, triggerResults);
653+ // **** Get the TriggerResults container
654+ edm::Handle<edm::TriggerResults> triggerResults;
655+ iEvent.getByToken (triggerResultsToken_, triggerResults);
654656 if (!triggerResults.isValid ()){
655657 edm::LogError (" PFAnalyzer" ) << " invalid trigger result \n " ;
656658 return ;
657659 }
658660 const edm::TriggerNames& triggerNames = iEvent.triggerNames (*triggerResults);
659661
660662
661- edm::Handle<reco::PFCandidateCollection> pfCollection;
662- iEvent.getByToken (thePfCandidateCollection_, pfCollection);
663- if (!pfCollection.isValid ()) {
664- edm::LogError (" PFAnalyzer" ) << " invalid collection: PF candidate \n " ;
665- return ;
666- }
663+ edm::Handle<reco::PFCandidateCollection> recoPfCollection;
664+ edm::Handle<pat::PackedCandidateCollection> patPfCollection;
665+ std::vector<reco::PFCandidate> pfCollection;
667666
667+
668+ edm::Handle<pat::JetCollection> patJets;
668669 edm::Handle<reco::PFJetCollection> pfJets;
669- iEvent.getByToken (pfJetsToken_, pfJets);
670- if (!pfJets.isValid ()) {
671- edm::LogError (" PFAnalyzer" ) << " invalid collection: PF jets \n " ;
672- return ;
670+ std::vector<reco::Jet> jets;
671+
672+ unsigned int numJets = 0 ;
673+ unsigned int numPFCands = 0 ;
674+ m_isMiniAOD= true ;
675+ if (!m_isMiniAOD){
676+ iEvent.getByToken (thePfCandidateCollection_, recoPfCollection);
677+ if (!recoPfCollection.isValid ()) {
678+ edm::LogError (" PFAnalyzer" ) << " invalid collection: PF candidate \n " ;
679+ return ;
680+ }
681+ for (unsigned int i=0 ; i<recoPfCollection->size (); i++){
682+ pfCollection.push_back (recoPfCollection->at (i));
683+ }
684+ numPFCands = recoPfCollection->size ();
685+
686+
687+ iEvent.getByToken (pfJetsToken_, pfJets);
688+ if (!pfJets.isValid ()) {
689+ edm::LogError (" PFAnalyzer" ) << " invalid collection: PF jets \n " ;
690+ return ;
691+ }
692+ numJets = pfJets->size ();
693+ for (unsigned int i=0 ; i<numJets; i++){
694+ jets.push_back (pfJets->at (i));
695+ }
673696 }
697+ else {
674698
675- if (!passesTriggerSelection (pfJets, triggerResults, triggerNames, m_triggerOptions)){
676- return ;
699+ iEvent.getByToken (patJetsToken_, patJets);
700+ if (!patJets.isValid ()) {
701+ edm::LogError (" PFAnalyzer" ) << " invalid collection: PF jets \n " ;
702+ return ;
703+ }
704+ numJets = patJets->size ();
705+ for (unsigned int i=0 ; i<numJets; i++){
706+ jets.push_back (patJets->at (i));
707+ }
708+
709+ std::cout << " Using mini and pat" << std::endl;
710+ iEvent.getByToken (patPfCandidateCollection_, patPfCollection);
711+ if (!patPfCollection.isValid ()) {
712+ edm::LogError (" PFAnalyzer" ) << " invalid collection: PF candidate \n " ;
713+ return ;
714+ }
715+ // for(unsigned int i=0; i<patPfCollection->size(); i++){
716+ // pfCollection.push_back(patPfCollection->at(i));
717+ // }
718+ numPFCands = patPfCollection->size ();
677719 }
678720
679- if (!m_eventSelectionMap[m_selection](pfJets)){
721+ std::cout << numPFCands << std::endl;
722+ // if(!passesTriggerSelection(jets, triggerResults, triggerNames, m_triggerOptions)){
723+ // return;
724+ // }
725+ //
726+
727+ std::cout << " Passes trigger" << std::endl;
728+ if (!m_eventSelectionMap[m_selection](jets)){
680729 return ;
681730 }
731+ std::cout << " Passes event selection" << std::endl;
732+
733+ for (unsigned int i_pfcand=0 ; i_pfcand < numPFCands; i_pfcand++){
734+ reco::PFCandidate recoPF;
735+ pat::PackedCandidate packedCand;
736+ if (m_isMiniAOD){
737+ packedCand = patPfCollection->at (i_pfcand);
738+ } else {
739+ recoPF = pfCollection[i_pfcand];
740+ }
682741
683- for (reco::PFCandidateCollection::const_iterator recoPF = pfCollection->begin (); recoPF != pfCollection->end ();
684- ++recoPF) {
685742 for (unsigned int j = 0 ; j < m_fullCutList.size (); j++) {
686- int binNumber = getPFBin (*recoPF, j);
743+ int binNumber = getPFBin (recoPF, packedCand, m_isMiniAOD, j);
744+
687745 if (binNumber < 0 )
688746 continue ;
689747 if (binNumber >= int (m_allSuffixes[j].size ())) {
@@ -695,9 +753,12 @@ void PFAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup
695753 // For each observable, we make a couple histograms based on a few generic categorizations.
696754 // In all cases, the PFCs that go into these histograms must pass the PFC selection from m_cutList.
697755 std::string histName = Form (" %s_%s" , m_fullCutList2D[i][0 ].c_str (), m_fullCutList2D[i][1 ].c_str ());
698- map_of_MEs[m_directory + " /allPFC_" + histName]->Fill (m_funcMap[m_fullCutList2D[i][0 ]](*recoPF), m_funcMap[m_fullCutList2D[i][1 ]](*recoPF), eventWeight);
699- if (m_particleTypeName.find (recoPF->particleId ()) != m_particleTypeName.end ()){
700- map_of_MEs[m_directory + " /" + m_particleTypeName[recoPF->particleId ()] + " _" + histName]->Fill (m_funcMap[m_fullCutList2D[i][0 ]](*recoPF), m_funcMap[m_fullCutList2D[i][1 ]](*recoPF), eventWeight);
756+ double valX = m_funcMap[m_fullCutList2D[i][0 ]](recoPF, packedCand, m_isMiniAOD);
757+ double valY = m_funcMap[m_fullCutList2D[i][1 ]](recoPF, packedCand, m_isMiniAOD);
758+
759+ map_of_MEs[m_directory + " /allPFC_" + histName]->Fill (valX, valY, eventWeight);
760+ if (m_particleTypeName.find (recoPF.particleId ()) != m_particleTypeName.end ()){
761+ map_of_MEs[m_directory + " /" + m_particleTypeName[recoPF.particleId ()] + " _" + histName]->Fill (valX, valY, eventWeight);
701762 }
702763
703764 }
@@ -707,48 +768,72 @@ void PFAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup
707768 // Make plots of all observables
708769 for (unsigned int i = 0 ; i < m_observables.size (); i++) {
709770 std::string histName = Form (" %s%s_%s" , m_observableNames[i].c_str (), binString.c_str (), npvString.c_str ());
710- map_of_MEs[m_directory + " /allPFC_" + histName]->Fill (m_funcMap[m_observableNames[i]](*recoPF), eventWeight);
771+ double val = m_funcMap[m_observableNames[i]](recoPF, packedCand, m_isMiniAOD);
772+ map_of_MEs[m_directory + " /allPFC_" + histName]->Fill (val, eventWeight);
711773
712- if (m_particleTypeName.find (recoPF-> particleId ()) != m_particleTypeName.end ()){
713- map_of_MEs[m_directory + " /" + m_particleTypeName[recoPF-> particleId ()] + " _" + histName]->Fill (m_funcMap[m_observableNames[i]](*recoPF) , eventWeight);
774+ if (m_particleTypeName.find (recoPF. particleId ()) != m_particleTypeName.end ()){
775+ map_of_MEs[m_directory + " /" + m_particleTypeName[recoPF. particleId ()] + " _" + histName]->Fill (val , eventWeight);
714776 }
715777
716778 }
717779 }
718780 }
719781
782+ /*
720783 for (unsigned int i = 0; i < m_eventObservableNames.size(); i++) {
721784 std::string histName = Form("%s_%s", m_eventObservableNames[i].c_str(), npvString.c_str());
722785 map_of_MEs[m_directory + "/allPFC_" + histName]->Fill(
723- m_eventFuncMap[m_eventObservableNames[i]](* pfCollection, reco::PFCandidate::ParticleType::X), eventWeight);
786+ m_eventFuncMap[m_eventObservableNames[i]](pfCollection, reco::PFCandidate::ParticleType::X), eventWeight);
724787
725788 for(const auto &mypair : m_particleTypeName){
726789 map_of_MEs[m_directory + "/" + mypair.second + "_" + histName]->Fill(
727- m_eventFuncMap[m_eventObservableNames[i]](* pfCollection, mypair.first ), eventWeight);
790+ m_eventFuncMap[m_eventObservableNames[i]](pfCollection, mypair.first), eventWeight);
728791 }
729792 }
730793
731794 // Plots for generic debugging
732795 map_of_MEs[m_directory + "/NPV"]->Fill(numPV, eventWeight);
733- map_of_MEs[m_directory + Form (" /jetPtLead_%s" , npvString.c_str ())]->Fill (pfJets->begin ()->pt (), eventWeight);
734- map_of_MEs[m_directory + Form (" /jetEtaLead_%s" , npvString.c_str ())]->Fill (pfJets->begin ()->eta (), eventWeight);
796+ reco::Jet leadJet;
797+ if(m_isMiniAOD){
798+ leadJet = *patJets->begin();
799+ } else{
800+ leadJet = *pfJets->begin();
801+ }
802+ map_of_MEs[m_directory + Form("/jetPtLead_%s", npvString.c_str())]->Fill(leadJet.pt(), eventWeight);
803+ map_of_MEs[m_directory + Form("/jetEtaLead_%s", npvString.c_str())]->Fill(leadJet.eta(), eventWeight);
804+
735805
736806 // Make plots of all observables, this time for PF candidates within jets
737- for (reco::PFJetCollection::const_iterator cjet = pfJets->begin (); cjet != pfJets->end (); ++cjet) {
738- map_of_MEs[m_directory + Form (" /jetPt_%s" , npvString.c_str ())]->Fill (cjet->pt (), eventWeight);
739- map_of_MEs[m_directory + Form (" /jetEta_%s" , npvString.c_str ())]->Fill (cjet->eta (), eventWeight);
807+ for (unsigned int index=0; index < numJets; index++) {
808+ reco::Jet cjet;
809+ if(m_isMiniAOD){
810+ cjet = patJets->at(index);
811+ } else{
812+ cjet = pfJets->at(index);
813+ }
814+ std::vector<reco::PFCandidatePtr> pfConstits;;
815+ std::vector<pat::PackedCandidateRef> patConstits;;
816+ if(m_isMiniAOD){
817+ //patConstits = patJets->at(index).getPFConstituents();
818+ pfConstits = pfJets->at(index).getPFConstituents();
819+ } else{
820+ pfConstits = pfJets->at(index).getPFConstituents();
821+ }
822+
823+ map_of_MEs[m_directory + Form("/jetPt_%s", npvString.c_str())]->Fill(cjet.pt(), eventWeight);
824+ map_of_MEs[m_directory + Form("/jetEta_%s", npvString.c_str())]->Fill(cjet.eta(), eventWeight);
740825
741826 for (unsigned int k = 0; k < m_fullJetCutList.size(); k++) {
742- int jetBinNumber = getJetBin (*cjet, k);
827+ pat::PackedCandidate packedCand;
828+ int jetBinNumber = getJetBin(cjet, pfConstits, k);
743829 if (jetBinNumber < 0)
744830 continue;
745831 std::string jetBinString = m_allJetSuffixes[k][jetBinNumber];
746832
747- std::vector<reco::PFCandidatePtr> pfConstits = cjet->getPFConstituents ();
748833
749834 for (const auto& recoPF : pfConstits) {
750835 for (unsigned int j = 0; j < m_fullCutList.size(); j++) {
751- int binNumber = getPFBin (*recoPF, j);
836+ int binNumber = getPFBin(*recoPF, packedCand, false, j);
752837 if (binNumber < 0)
753838 continue;
754839 if (binNumber >= int(m_allSuffixes[j].size())) {
@@ -762,10 +847,10 @@ void PFAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup
762847 binString.c_str(),
763848 jetBinString.c_str(),
764849 npvString.c_str());
765- map_of_MEs[m_directory + " /allPFC_jetMatched_" + histName]->Fill (m_funcMap[m_observableNames[i]](*recoPF),
850+ map_of_MEs[m_directory + "/allPFC_jetMatched_" + histName]->Fill(m_funcMap[m_observableNames[i]](*recoPF, packedCand, false ),
766851 eventWeight);
767852 if(m_particleTypeName.find(recoPF->particleId()) != m_particleTypeName.end()){
768- map_of_MEs[m_directory + " /" + m_particleTypeName[recoPF->particleId ()] + " _jetMatched_" + histName]->Fill (m_funcMap[m_observableNames[i]](*recoPF),
853+ map_of_MEs[m_directory + "/" + m_particleTypeName[recoPF->particleId()] + "_jetMatched_" + histName]->Fill(m_funcMap[m_observableNames[i]](*recoPF, packedCand, false ),
769854 eventWeight);
770855 }
771856 }
@@ -777,11 +862,11 @@ void PFAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup
777862 jetBinString.c_str(),
778863 npvString.c_str());
779864 map_of_MEs[m_directory + "/allPFC_jetMatched_" + histName]->Fill(
780- m_pfInJetFuncMap[m_pfInJetObservableNames[i]](*recoPF, * cjet), eventWeight);
865+ m_pfInJetFuncMap[m_pfInJetObservableNames[i]](*recoPF, cjet), eventWeight);
781866
782867 if(m_particleTypeName.find(recoPF->particleId()) != m_particleTypeName.end()){
783868 map_of_MEs[m_directory + "/" + m_particleTypeName[recoPF->particleId()] + "_jetMatched_" + histName]->Fill(
784- m_pfInJetFuncMap[m_pfInJetObservableNames[i]](*recoPF, * cjet), eventWeight);
869+ m_pfInJetFuncMap[m_pfInJetObservableNames[i]](*recoPF, cjet), eventWeight);
785870 }
786871
787872 }
@@ -791,13 +876,15 @@ void PFAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup
791876 std::string histName =
792877 Form("%s_jetCuts%s_%s", m_eventObservableNames[i].c_str(), jetBinString.c_str(), npvString.c_str());
793878 map_of_MEs[m_directory + "/allPFC_jetMatched_" + histName]->Fill(
794- m_jetWideFuncMap[m_eventObservableNames[i]](pfConstits, reco::PFCandidate::ParticleType::X, * cjet), eventWeight);
879+ m_jetWideFuncMap[m_eventObservableNames[i]](pfConstits, reco::PFCandidate::ParticleType::X, cjet), eventWeight);
795880 for(const auto &mypair : m_particleTypeName){
796881 map_of_MEs[m_directory + "/" + mypair.second + "_jetMatched_" + histName]->Fill(
797- m_jetWideFuncMap[m_eventObservableNames[i]](pfConstits, mypair.first , * cjet), eventWeight);
882+ m_jetWideFuncMap[m_eventObservableNames[i]](pfConstits, mypair.first, cjet), eventWeight);
798883 }
799884 }
800885 }
801886 }
802887 }
888+ */
803889}
890+
0 commit comments