CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
JetDeltaRValueMapProducer.cc
Go to the documentation of this file.
1 /* \class PFJetSelector
2  *
3  * Selects jets with a configurable string-based cut,
4  * and also writes out the constituents of the jet
5  * into a separate collection.
6  *
7  * \author: Sal Rappoccio
8  *
9  *
10  * for more details about the cut syntax, see the documentation
11  * page below:
12  *
13  * https://twiki.cern.ch/twiki/bin/view/CMS/SWGuidePhysicsCutParser
14  *
15  *
16  */
17 
18 
20 
24 
30 
31 template < class T >
33 
34 public:
35 
36  typedef std::vector<T> JetsInput;
38 
40  srcToken_( consumes< typename edm::View<T> >( params.getParameter<edm::InputTag>("src") ) ),
41  matchedToken_( consumes< typename edm::View<T> >( params.getParameter<edm::InputTag>( "matched" ) ) ),
42  distMax_( params.getParameter<double>( "distMax" ) ),
43  value_( params.getParameter<std::string>("value") ),
45  {
46  produces< JetValueMap >();
47  }
48 
50 
51 private:
52 
53  virtual void beginJob() override {}
54  virtual void endJob() override {}
55 
56  virtual void produce(edm::Event& iEvent, const edm::EventSetup& iSetup) override {
57 
58  std::auto_ptr< JetValueMap > jetValueMap ( new JetValueMap() );
59  edm::ValueMap<float>::Filler filler(*jetValueMap);
60 
61 
63  iEvent.getByToken( srcToken_, h_jets1 );
65  iEvent.getByToken( matchedToken_, h_jets2 );
66 
67  std::vector<float> values( h_jets1->size(), -99999 );
68  std::vector<bool> jets1_locks( h_jets1->size(), false );
69 
70  for ( typename edm::View<T>::const_iterator ibegin = h_jets2->begin(),
71  iend = h_jets2->end(), ijet = ibegin;
72  ijet != iend; ++ijet )
73  {
74  float matched_dR2 = 1e9;
75  int matched_index = -1;
76 
77  for ( typename edm::View<T>::const_iterator jbegin = h_jets1->begin(),
78  jend = h_jets1->end(), jjet = jbegin;
79  jjet != jend; ++jjet )
80  {
81  int index=jjet - jbegin;
82 
83  if( jets1_locks.at(index) ) continue; // skip jets that have already been matched
84 
85  float temp_dR2 = reco::deltaR2(ijet->eta(),ijet->phi(),jjet->eta(),jjet->phi());
86  if ( temp_dR2 < matched_dR2 )
87  {
88  matched_dR2 = temp_dR2;
89  matched_index = index;
90  }
91  }// end loop over src jets
92 
93  if( matched_index>=0 )
94  {
95  if ( matched_dR2 > distMax_*distMax_ )
96  edm::LogWarning("MatchedJetsFarApart") << "Matched jets separated by dR greater than distMax=" << distMax_;
97  else
98  {
99  jets1_locks.at(matched_index) = true;
100  values.at(matched_index) = evaluation_(*ijet);
101  }
102  }
103  }// end loop over matched jets
104 
105  filler.insert(h_jets1, values.begin(), values.end());
106  filler.fill();
107 
108  // put in Event
109  iEvent.put(jetValueMap);
110  }
111 
114  double distMax_;
117 };
118 
120 
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
StringObjectFunction< T > evaluation_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
edm::ValueMap< float > JetValueMap
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:52
virtual void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
int iEvent
Definition: GenABIO.cc:230
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:116
double deltaR2(const T1 &t1, const T2 &t2)
Definition: deltaR.h:36
edm::EDGetTokenT< typename edm::View< T > > matchedToken_
virtual void beginJob() override
JetDeltaRValueMapProducer< reco::Jet > RecoJetDeltaRValueMapProducer
edm::EDGetTokenT< typename edm::View< T > > srcToken_
volatile std::atomic< bool > shutdown_flag false
long double T
JetDeltaRValueMapProducer(edm::ParameterSet const &params)