CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CandOneToManyDeltaRMatcher.cc
Go to the documentation of this file.
1 /* \class CandOneToManyDeltaRMatcher
2  *
3  * Producer for simple match map:
4  * class to match two collections of candidate
5  * with one-to-Many matching
6  * All elements of class "matched" are matched to each element
7  * of class "source" orderd in DeltaR
8  *
9  */
10 
13 
15 
16 #include<vector>
17 #include<iostream>
18 
20  public:
23  private:
24  void produce( edm::Event&, const edm::EventSetup& ) override;
25 
29 };
30 
38 
44 
45 
46 #include <Math/VectorUtil.h>
47 #include <TMath.h>
48 
49 using namespace edm;
50 using namespace std;
51 using namespace reco;
52 using namespace ROOT::Math::VectorUtil;
53 
54 namespace reco {
55  namespace helper {
56  typedef pair<size_t, double> MatchPair;
57 
58  struct SortBySecond {
59  bool operator()( const MatchPair & p1, const MatchPair & p2 ) const {
60  return p1.second < p2.second;
61  }
62  };
63  }
64 }
65 
67  sourceToken_( consumes<CandidateCollection>( cfg.getParameter<InputTag>( "src" ) ) ),
68  matchedToken_( consumes<CandidateCollection>( cfg.getParameter<InputTag>( "matched" ) ) ),
69  printdebug_( cfg.getUntrackedParameter<bool>("printDebug", false) ) {
70  produces<CandMatchMapMany>();
71 }
72 
74 }
75 
77 
80  evt.getByToken( sourceToken_, source ) ;
81  evt.getByToken( matchedToken_, matched ) ;
82 
83  if (printdebug_) {
84  for( CandidateCollection::const_iterator c = source->begin(); c != source->end(); ++c ) {
85  cout << "[CandOneToManyDeltaRMatcher] Et source " << c->et() << endl;
86  }
87  for( CandidateCollection::const_iterator c = matched->begin(); c != matched->end(); ++c ) {
88  cout << "[CandOneToManyDeltaRMatcher] Et matched " << c->et() << endl;
89  }
90  }
91 
92 
93  auto_ptr<CandMatchMapMany> matchMap( new CandMatchMapMany( CandMatchMapMany::ref_type( CandidateRefProd( source ),
94  CandidateRefProd( matched )
95  ) ) );
96  for( size_t c = 0; c != source->size(); ++ c ) {
97  const Candidate & src = (*source)[ c ];
98  if (printdebug_) cout << "[CandOneToManyDeltaRMatcher] source (Et,Eta,Phi) =(" << src.et() << "," <<
99  src.eta() << "," <<
100  src.phi() << ")" << endl;
101  vector<reco::helper::MatchPair> v;
102  for( size_t m = 0; m != matched->size(); ++ m ) {
103  const Candidate & match = ( * matched )[ m ];
104  double dist = DeltaR( src.p4() , match.p4() );
105  v.push_back( make_pair( m, dist ) );
106  }
107  if ( v.size() > 0 ) {
108  sort( v.begin(), v.end(), reco::helper::SortBySecond() );
109  for( size_t m = 0; m != v.size(); ++ m ) {
110  if (printdebug_) cout << "[CandOneToManyDeltaRMatcher] match (Et,Eta,Phi) =(" << ( * matched )[ v[m].first ].et() << "," <<
111  ( * matched )[ v[m].first ].eta() << "," <<
112  ( * matched )[ v[m].first ].phi() << ") DeltaR=" <<
113  v[m].second << endl;
114  matchMap->insert( CandidateRef( source, c ), make_pair( CandidateRef( matched, v[m].first ), v[m].second ) );
115  }
116  }
117  }
118 
119  evt.put( matchMap );
120 
121 }
122 
125 
bool operator()(const MatchPair &p1, const MatchPair &p2) const
edm::AssociationMap< edm::OneToManyWithQuality< reco::CandidateCollection, reco::CandidateCollection, double > > CandMatchMapMany
Definition: deltaR.h:79
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
virtual double et() const =0
transverse energy
virtual float eta() const =0
momentum pseudorapidity
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
virtual float phi() const =0
momentum azimuthal angle
edm::EDGetTokenT< reco::CandidateCollection > sourceToken_
U second(std::pair< T, U > const &p)
CandOneToManyDeltaRMatcher(const edm::ParameterSet &)
edm::EDGetTokenT< reco::CandidateCollection > matchedToken_
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:116
pair< size_t, double > MatchPair
bool first
Definition: L1TdeRCT.cc:75
double p2[4]
Definition: TauolaWrapper.h:90
edm::Ref< CandidateCollection > CandidateRef
persistent reference to an object in a collection of Candidate objects
Definition: CandidateFwd.h:29
void produce(edm::Event &, const edm::EventSetup &) override
std::pair< size_t, double > MatchPair
Definition: Matcher.h:66
double p1[4]
Definition: TauolaWrapper.h:89
tuple cout
Definition: gather_cfg.py:121
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:6
volatile std::atomic< bool > shutdown_flag false
edm::RefProd< CandidateCollection > CandidateRefProd
reference to a collection of Candidate objects
Definition: CandidateFwd.h:37
static std::string const source
Definition: EdmProvDump.cc:43
virtual const LorentzVector & p4() const =0
four-momentum Lorentz vector