CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
JetDeltaRTagInfoValueMapProducer.cc
Go to the documentation of this file.
1 /* \class JetDeltaRTagInfoValueMapProducer<T,I>
2  *
3  * Inputs two jet collections ("src" and "matched", type T), with
4  * the second having tag infos run on them ("matchedTagInfos", type I).
5  * The jet collections are matched using delta-R matching. The
6  * tag infos from the second collection are then rewritten into a
7  * new TagInfoCollection, keyed to the first jet collection.
8  * This can be used in the miniAOD to associate the previously-run
9  * CA8 "Top-Tagged" jets with their CATopTagInfos to the AK8 jets
10  * that are stored in the miniAOD.
11  *
12  * \author: Sal Rappoccio
13  *
14  *
15  * for more details about the cut syntax, see the documentation
16  * page below:
17  *
18  * https://twiki.cern.ch/twiki/bin/view/CMS/SWGuidePhysicsCutParser
19  *
20  *
21  */
22 
23 
25 
30 
35 
36 template < class T, class I >
38 
39 public:
40 
41  typedef std::vector<T> JetsInput;
42  typedef std::vector<I> TagInfosCollection;
43 
45  srcToken_( consumes< typename edm::View<T> >( params.getParameter<edm::InputTag>("src") ) ),
46  matchedToken_( consumes< typename edm::View<T> >( params.getParameter<edm::InputTag>( "matched" ) ) ),
47  matchedTagInfosToken_( consumes< typename edm::View<I> >( params.getParameter<edm::InputTag>( "matchedTagInfos" ) ) ),
48  distMax_( params.getParameter<double>( "distMax" ) )
49  {
50  produces< TagInfosCollection >();
51  }
52 
54 
55 private:
56 
57  virtual void beginJob() override {}
58  virtual void endJob() override {}
59 
60  virtual void produce(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const override {
61 
62  std::auto_ptr< TagInfosCollection > mappedTagInfos ( new TagInfosCollection() );
63 
64 
66  iEvent.getByToken( srcToken_, h_jets1 );
68  iEvent.getByToken( matchedToken_, h_jets2 );
70  iEvent.getByToken( matchedTagInfosToken_, h_tagInfos );
71 
72  const double distMax2 = distMax_*distMax_;
73 
74  std::vector<bool> jets2_locks( h_jets2->size(), false );
75 
76  for ( typename edm::View<T>::const_iterator ibegin = h_jets1->begin(),
77  iend = h_jets1->end(), ijet = ibegin;
78  ijet != iend; ++ijet )
79  {
80  float matched_dR2 = 1e9;
81  int matched_index = -1;
82 
83  //std::cout << "Looking at jet " << ijet - ibegin << ", mass = " << ijet->mass() << std::endl;
84 
85  for ( typename edm::View<T>::const_iterator jbegin = h_jets2->begin(),
86  jend = h_jets2->end(), jjet = jbegin;
87  jjet != jend; ++jjet )
88  {
89  int index=jjet - jbegin;
90 
91  //std::cout << "Checking jet " << index << ", mass = " << jjet->mass() << std::endl;
92 
93  if( jets2_locks.at(index) ) continue; // skip jets that have already been matched
94 
95  float temp_dR2 = reco::deltaR2(ijet->eta(),ijet->phi(),jjet->eta(),jjet->phi());
96  if ( temp_dR2 < matched_dR2 )
97  {
98  matched_dR2 = temp_dR2;
99  matched_index = index;
100  }
101  }// end loop over src jets
102 
103  I mappedTagInfo;
104 
105  if( matched_index>=0 && static_cast<size_t>(matched_index) < h_tagInfos->size() )
106  {
107  if ( matched_dR2 > distMax2 )
108  LogDebug("MatchedJetsFarApart") << "Matched jets separated by dR greater than distMax=" << distMax_;
109  else
110  {
111  jets2_locks.at(matched_index) = true;
112 
113  auto otherTagInfo = h_tagInfos->at( matched_index );
114  otherTagInfo.setJetRef( h_jets1->refAt( ijet - ibegin) );
115  mappedTagInfo = otherTagInfo;
116  //std::cout << "Matched! : " << matched_index << ", mass = " << mappedTagInfo.properties().topMass << std::endl;
117  }
118  }
119 
120  mappedTagInfos->push_back( mappedTagInfo );
121 
122  }// end loop over matched jets
123 
124 
125  // put in Event
126  iEvent.put(mappedTagInfos);
127  }
128 
132  const double distMax_;
133 
134 };
135 
137 
#define LogDebug(id)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:464
JetDeltaRTagInfoValueMapProducer< reco::Jet, reco::CATopJetTagInfo > RecoJetDeltaRTagInfoValueMapProducer
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
JetDeltaRTagInfoValueMapProducer(edm::ParameterSet const &params)
const edm::EDGetTokenT< typename edm::View< T > > srcToken_
const edm::EDGetTokenT< typename edm::View< I > > matchedTagInfosToken_
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:120
virtual void produce(edm::StreamID, edm::Event &iEvent, const edm::EventSetup &iSetup) const override
const std::complex< double > I
Definition: I.h:8
double deltaR2(const T1 &t1, const T2 &t2)
Definition: deltaR.h:36
volatile std::atomic< bool > shutdown_flag false
long double T
const edm::EDGetTokenT< typename edm::View< T > > matchedToken_