Go to the documentation of this file.00001
00002
00003
00004
00005
00011
00012
00013
00014
00015
00016
00017 #include "CommonTools/RecoUtils/interface/PFCand_NoPU_WithAM.h"
00018
00019
00020 #include <memory>
00021 #include <vector>
00022
00023
00024
00025 #include "FWCore/Framework/interface/Event.h"
00026 #include "FWCore/Framework/interface/Run.h"
00027 #include "FWCore/Framework/interface/MakerMacros.h"
00028
00029 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00030
00031 #include "DataFormats/Common/interface/View.h"
00032
00033 #include "DataFormats/TrackReco/interface/Track.h"
00034 #include "DataFormats/TrackReco/interface/TrackFwd.h"
00035 #include "DataFormats/TrackReco/interface/TrackBase.h"
00036
00037 using namespace edm;
00038 using namespace std;
00039 using namespace reco;
00040
00041
00042
00043
00044 PFCand_NoPU_WithAM::PFCand_NoPU_WithAM(const edm::ParameterSet& iConfig)
00045 {
00046
00047
00048 input_AssociationType_ = iConfig.getParameter<InputTag>("AssociationType");
00049
00050 input_VertexPFCandAssociationMap_ = iConfig.getParameter<InputTag>("VertexPFCandAssociationMap");
00051
00052 input_VertexCollection_ = iConfig.getParameter<InputTag>("VertexCollection");
00053
00054 input_MinQuality_ = iConfig.getParameter<int>("MinQuality");
00055
00056
00057
00058 if ( input_AssociationType_.label() == "PFCandsToVertex" ) {
00059 produces<PFCandidateCollection>("P2V");
00060 } else {
00061 if ( input_AssociationType_.label() == "VertexToPFCands" ) {
00062 produces<PFCandidateCollection>("V2P");
00063 } else {
00064 if ( input_AssociationType_.label() == "Both" ) {
00065 produces<PFCandidateCollection>("P2V");
00066 produces<PFCandidateCollection>("V2P");
00067 } else {
00068 cout << "No correct InputTag for AssociationType!" << endl;
00069 cout << "Won't produce any PFCandiateCollection!" << endl;
00070 }
00071 }
00072 }
00073
00074 }
00075
00076
00077 PFCand_NoPU_WithAM::~PFCand_NoPU_WithAM()
00078 {
00079
00080
00081
00082
00083 }
00084
00085
00086
00087
00088
00089
00090 void
00091 PFCand_NoPU_WithAM::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
00092 {
00093
00094 auto_ptr<PFCandidateCollection> p2v_firstvertex(new PFCandidateCollection() );
00095 auto_ptr<PFCandidateCollection> v2p_firstvertex(new PFCandidateCollection() );
00096
00097 bool p2vassmap = false;
00098 bool v2passmap = false;
00099
00100
00101 Handle<PFCandToVertexAssMap> p2vAM;
00102 Handle<VertexToPFCandAssMap> v2pAM;
00103
00104 string asstype = input_AssociationType_.label();
00105
00106 if ( ( asstype == "PFCandsToVertex" ) || ( asstype == "Both" ) ) {
00107 if ( iEvent.getByLabel(input_VertexPFCandAssociationMap_, p2vAM ) ) {
00108 p2vassmap = true;
00109 }
00110 }
00111
00112 if ( ( asstype == "VertexToPFCands" ) || ( asstype == "Both" ) ) {
00113 if ( iEvent.getByLabel(input_VertexPFCandAssociationMap_, v2pAM ) ) {
00114 v2passmap = true;
00115 }
00116 }
00117
00118 if ( !p2vassmap && !v2passmap ) {
00119 cout << "No input collection could be found" << endl;
00120 return;
00121 }
00122
00123 int negativeQuality = 0;
00124 if ( input_MinQuality_ >= 2) {
00125 negativeQuality = -1;
00126 } else {
00127 if ( input_MinQuality_ == 1) {
00128 negativeQuality = -2;
00129 } else{
00130 negativeQuality = -3;
00131 }
00132 }
00133
00134 if ( p2vassmap ){
00135
00136 const PFCandQualityPairVector pfccoll = p2vAM->begin()->val;
00137
00138
00139 for (unsigned int pfccoll_ite = 0; pfccoll_ite < pfccoll.size(); pfccoll_ite++){
00140
00141 PFCandidateRef pfcand = pfccoll[pfccoll_ite].first;
00142 int quality = pfccoll[pfccoll_ite].second;
00143
00144 if ( (quality>=input_MinQuality_) || ( (quality<0) && (quality>=negativeQuality) ) ) {
00145 p2v_firstvertex->push_back(*pfcand);
00146
00147 }
00148
00149 }
00150
00151 iEvent.put( p2v_firstvertex, "P2V" );
00152
00153 }
00154
00155 if ( v2passmap ) {
00156
00157
00158 Handle<VertexCollection> input_vtxcollH;
00159 iEvent.getByLabel(input_VertexCollection_,input_vtxcollH);
00160
00161 VertexRef firstVertexRef(input_vtxcollH,0);
00162
00163 VertexToPFCandAssMap::const_iterator v2p_ite;
00164
00165 for(v2p_ite=v2pAM->begin(); v2p_ite!=v2pAM->end(); v2p_ite++){
00166
00167 PFCandidateRef pfcand = v2p_ite->key;
00168
00169 for(unsigned v_ite = 0; v_ite<(v2p_ite->val).size(); v_ite++){
00170
00171 VertexRef vtxref = (v2p_ite->val)[v_ite].first;
00172 int quality = (v2p_ite->val)[v_ite].second;
00173
00174 if ( (vtxref==firstVertexRef) && ( (quality>=input_MinQuality_) || ( (quality<0) && (quality>=negativeQuality) ) ) ) {
00175 v2p_firstvertex->push_back(*pfcand);
00176 }
00177
00178 }
00179
00180 }
00181
00182 iEvent.put( v2p_firstvertex, "V2P" );
00183
00184 }
00185 }
00186
00187
00188 void
00189 PFCand_NoPU_WithAM::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
00190
00191
00192 edm::ParameterSetDescription desc;
00193 desc.setUnknown();
00194 descriptions.addDefault(desc);
00195 }
00196
00197
00198 DEFINE_FWK_MODULE(PFCand_NoPU_WithAM);