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 
14 
15 #include<vector>
16 #include<iostream>
17 
19  public:
22  private:
23  void produce( edm::Event&, const edm::EventSetup& );
24 
28 };
29 
36 
43 
44 
45 #include <Math/VectorUtil.h>
46 #include <TMath.h>
47 
48 using namespace edm;
49 using namespace std;
50 using namespace reco;
51 using namespace ROOT::Math::VectorUtil;
52 
53 namespace reco {
54  namespace helper {
55  typedef pair<size_t, double> MatchPair;
56 
57  struct SortBySecond {
58  bool operator()( const MatchPair & p1, const MatchPair & p2 ) const {
59  return p1.second < p2.second;
60  }
61  };
62  }
63 }
64 
66  source_( cfg.getParameter<InputTag>( "src" ) ),
67  matched_( cfg.getParameter<InputTag>( "matched" ) ),
68  printdebug_( cfg.getUntrackedParameter<bool>("printDebug", false) ) {
69  produces<CandMatchMapMany>();
70 }
71 
73 }
74 
76 
79  evt.getByLabel( source_, source ) ;
80  evt.getByLabel( matched_, matched ) ;
81 
82  if (printdebug_) {
83  for( CandidateCollection::const_iterator c = source->begin(); c != source->end(); ++c ) {
84  cout << "[CandOneToManyDeltaRMatcher] Et source " << c->et() << endl;
85  }
86  for( CandidateCollection::const_iterator c = matched->begin(); c != matched->end(); ++c ) {
87  cout << "[CandOneToManyDeltaRMatcher] Et matched " << c->et() << endl;
88  }
89  }
90 
91 
92  auto_ptr<CandMatchMapMany> matchMap( new CandMatchMapMany( CandMatchMapMany::ref_type( CandidateRefProd( source ),
93  CandidateRefProd( matched )
94  ) ) );
95  for( size_t c = 0; c != source->size(); ++ c ) {
96  const Candidate & src = (*source)[ c ];
97  if (printdebug_) cout << "[CandOneToManyDeltaRMatcher] source (Et,Eta,Phi) =(" << src.et() << "," <<
98  src.eta() << "," <<
99  src.phi() << ")" << endl;
100  vector<reco::helper::MatchPair> v;
101  for( size_t m = 0; m != matched->size(); ++ m ) {
102  const Candidate & match = ( * matched )[ m ];
103  double dist = DeltaR( src.p4() , match.p4() );
104  v.push_back( make_pair( m, dist ) );
105  }
106  if ( v.size() > 0 ) {
107  sort( v.begin(), v.end(), reco::helper::SortBySecond() );
108  for( size_t m = 0; m != v.size(); ++ m ) {
109  if (printdebug_) cout << "[CandOneToManyDeltaRMatcher] match (Et,Eta,Phi) =(" << ( * matched )[ v[m].first ].et() << "," <<
110  ( * matched )[ v[m].first ].eta() << "," <<
111  ( * matched )[ v[m].first ].phi() << ") DeltaR=" <<
112  v[m].second << endl;
113  matchMap->insert( CandidateRef( source, c ), make_pair( CandidateRef( matched, v[m].first ), v[m].second ) );
114  }
115  }
116  }
117 
118  evt.put( matchMap );
119 
120 }
121 
124 
bool operator()(const MatchPair &p1, const MatchPair &p2) const
edm::AssociationMap< edm::OneToManyWithQuality< reco::CandidateCollection, reco::CandidateCollection, double > > CandMatchMapMany
Definition: deltaR.h:51
virtual double et() const =0
transverse energy
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
U second(std::pair< T, U > const &p)
CandOneToManyDeltaRMatcher(const edm::ParameterSet &)
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:85
pair< size_t, double > MatchPair
bool first
Definition: L1TdeRCT.cc:94
double p2[4]
Definition: TauolaWrapper.h:90
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
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 &)
std::pair< size_t, double > MatchPair
Definition: Matcher.h:66
double p1[4]
Definition: TauolaWrapper.h:89
Tag::ref_type ref_type
reference set type
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
edm::RefProd< CandidateCollection > CandidateRefProd
reference to a collection of Candidate objects
Definition: CandidateFwd.h:37
mathSSE::Vec4< T > v
virtual double phi() const =0
momentum azimuthal angle
virtual double eta() const =0
momentum pseudorapidity
virtual const LorentzVector & p4() const =0
four-momentum Lorentz vector