CMS 3D CMS Logo

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:
22  ~CandOneToManyDeltaRMatcher() override;
23  private:
24  void produce( edm::StreamID, edm::Event&, const edm::EventSetup& ) const 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 matchMap = std::make_unique<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.empty() ) {
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(std::move(matchMap) );
120 
121 }
122 
125 
bool operator()(const MatchPair &p1, const MatchPair &p2) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:136
Definition: helper.py:1
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:519
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
size_type size() const
Definition: OwnVector.h:264
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
edm::EDGetTokenT< reco::CandidateCollection > sourceToken_
iterator begin()
Definition: OwnVector.h:244
U second(std::pair< T, U > const &p)
CandOneToManyDeltaRMatcher(const edm::ParameterSet &)
virtual double et() const =0
transverse energy
edm::EDGetTokenT< reco::CandidateCollection > matchedToken_
virtual const LorentzVector & p4() const =0
four-momentum Lorentz vector
pair< size_t, double > MatchPair
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
double p2[4]
Definition: TauolaWrapper.h:90
iterator end()
Definition: OwnVector.h:249
virtual double eta() const =0
momentum pseudorapidity
edm::Ref< CandidateCollection > CandidateRef
persistent reference to an object in a collection of Candidate objects
Definition: CandidateFwd.h:29
fixed size matrix
HLT enums.
double p1[4]
Definition: TauolaWrapper.h:89
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:10
edm::RefProd< CandidateCollection > CandidateRefProd
reference to a collection of Candidate objects
Definition: CandidateFwd.h:37
virtual double phi() const =0
momentum azimuthal angle
static std::string const source
Definition: EdmProvDump.cc:43
def move(src, dest)
Definition: eostools.py:510