CMS 3D CMS Logo

DeepCMVATagInfoProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: ​RecoBTag/​SecondaryVertex
4 // Class: DeepNNTagInfoProducer
5 //
14 //
15 // Original Author: Mauro Verzetti (U. Rochester)
16 //
17 //
18 
19 
20 // system include files
21 #include <memory>
22 
23 // user include files
27 
30 
33 
36 
46 
47 #include <cmath>
48 #include <map>
49 
50 using namespace reco;
51 
52 //
53 // class declaration
54 //
55 
56 inline bool equals(const edm::RefToBase<Jet> &j1, const edm::RefToBase<Jet> &j2) {
57  return j1.id() == j2.id() && j1.key() == j2.key();
58 }
59 
61 public:
63  ~DeepCMVATagInfoProducer() override;
64 
65  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
66 
67 private:
68  void beginStream(edm::StreamID) override {}
69  void produce(edm::Event&, const edm::EventSetup&) override;
70  void endStream() override {}
71 
72  // ----------member data ---------------------------
77  std::string jpComputer_, jpbComputer_, softmuComputer_, softelComputer_;
79 };
80 
81 //
82 // constants, enums and typedefs
83 //
84 
85 
86 //
87 // static data member definitions
88 //
89 
90 //
91 // constructors and destructor
92 //
94  deepNNSrc_(consumes< std::vector<reco::ShallowTagInfo> >(iConfig.getParameter<edm::InputTag>("deepNNTagInfos"))),
95  ipInfoSrc_(consumes< edm::View<reco::BaseTagInfo> >(iConfig.getParameter<edm::InputTag>("ipInfoSrc"))),
96  muInfoSrc_(consumes< edm::View<reco::BaseTagInfo> >(iConfig.getParameter<edm::InputTag>("muInfoSrc"))),
97  elInfoSrc_(consumes< edm::View<reco::BaseTagInfo> >(iConfig.getParameter<edm::InputTag>("elInfoSrc"))),
98  jpComputer_(iConfig.getParameter<std::string>("jpComputerSrc")),
99  jpbComputer_(iConfig.getParameter<std::string>("jpbComputerSrc")),
100  softmuComputer_(iConfig.getParameter<std::string>("softmuComputerSrc")),
101  softelComputer_(iConfig.getParameter<std::string>("softelComputerSrc")),
102  cMVAPtThreshold_(iConfig.getParameter<double>("cMVAPtThreshold"))
103 {
104 
105  produces<std::vector<reco::ShallowTagInfo> >();
106 
107 }
108 
109 
111 {
112 
113  // do anything here that needs to be done at destruction time
114  // (e.g. close files, deallocate resources etc.)
115 
116 }
117 
118 
119 //
120 // member functions
121 //
122 
123 // ------------ method called to produce the data ------------
124 void
126 {
127  // get input TagInfos from DeepCSV
129  iEvent.getByToken(deepNNSrc_, nnInfos);
130 
131  // get other Taginfos
133  iEvent.getByToken(ipInfoSrc_, ipInfos);
135  iEvent.getByToken(muInfoSrc_, muInfos);
137  iEvent.getByToken(elInfoSrc_, elInfos);
138 
139  //get computers
141  iSetup.get<JetTagComputerRecord>().get(jpComputer_,jp);
142  const JetTagComputer* compjp = jp.product();
144  iSetup.get<JetTagComputerRecord>().get(jpbComputer_,jpb);
145  const JetTagComputer* compjpb = jpb.product();
147  iSetup.get<JetTagComputerRecord>().get(softmuComputer_,softmu);
148  const JetTagComputer* compsoftmu = softmu.product();
150  iSetup.get<JetTagComputerRecord>().get(softelComputer_,softel);
151  const JetTagComputer* compsoftel = softel.product();
152 
153  // create the output collection
154  auto tagInfos = std::make_unique<std::vector<reco::ShallowTagInfo> >();
155 
156  // loop over TagInfos, assume they are ordered in the same way, check later and throw exception if not
157  for(size_t idx = 0; idx<nnInfos->size(); ++idx) {
158  auto& nnInfo = nnInfos->at(idx);
159  auto& ipInfo = ipInfos->at(idx);
160  auto& muInfo = muInfos->at(idx);
161  auto& elInfo = elInfos->at(idx);
162 
163  if(
164  !equals(nnInfo.jet(), ipInfo.jet()) ||
165  !equals(nnInfo.jet(), muInfo.jet()) ||
166  !equals(nnInfo.jet(), elInfo.jet())
167  ) {
168  throw cms::Exception("ValueError") << "DeepNNTagInfoProducer::produce: The tagInfos taken belong to different jets!" << std::endl
169  << "This could be due to: " << std::endl
170  << " - You passed tagInfos computed on different jet collection" << std::endl
171  << " - The assumption that the tagInfos are filled in the same order is actually wrong" << std::endl;
172  }
173 
174  // Make vector of BaseTagInfo, needed for TagInfoHelper
175  std::vector<const BaseTagInfo*> ipBaseInfo;
176  ipBaseInfo.push_back(&ipInfo);
177  std::vector<const BaseTagInfo*> muBaseInfo;
178  muBaseInfo.push_back(&muInfo);
179  std::vector<const BaseTagInfo*> elBaseInfo;
180  elBaseInfo.push_back(&elInfo);
181 
182  // Copy the DeepNN TaggingVariables + add the other discriminators
183  TaggingVariableList vars = nnInfo.taggingVariables();
184  float softmu_discr = (*compsoftmu)( JetTagComputer::TagInfoHelper(muBaseInfo) );
185  float softel_discr = (*compsoftel)( JetTagComputer::TagInfoHelper(elBaseInfo) );
186  float jp_discr = (*compjp)( JetTagComputer::TagInfoHelper(ipBaseInfo) );
187  float jpb_discr = (*compjpb)( JetTagComputer::TagInfoHelper(ipBaseInfo) );
188 
189  //if jetPt larger than cMVAPtThreshold_ --> default these taggers for easier SF measurements
190  if ((nnInfo.jet().get())->pt() < cMVAPtThreshold_){
191  vars.insert(reco::btau::Jet_SoftMu, !(isinf(softmu_discr)) ? softmu_discr : -0.2 , true);
192  vars.insert(reco::btau::Jet_SoftEl, !(isinf(softel_discr)) ? softel_discr : -0.2 , true);
193  vars.insert(reco::btau::Jet_JBP, !(isinf(jpb_discr)) ? jpb_discr : -0.2 , true);
194  vars.insert(reco::btau::Jet_JP, !(isinf(jp_discr)) ? jp_discr : -0.2 , true);
195  }
196 
197  vars.finalize();
198  tagInfos->emplace_back(vars, nnInfo.jet());
199 
200  // just to be sure, clear all containers
201  ipBaseInfo.clear();
202  muBaseInfo.clear();
203  elBaseInfo.clear();
204 
205 
206  }
207 
208  // put the output in the event
209  iEvent.put( std::move(tagInfos) );
210 }
211 
212 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
213 void
215  //The following says we do not know what parameters are allowed so do no validation
216  // Please change this to state exactly what you do use, even if it is no parameters
218  desc.setUnknown();
219  descriptions.addDefault(desc);
220 }
221 
222 //define this as a plug-in
const edm::EDGetTokenT< edm::View< reco::BaseTagInfo > > elInfoSrc_
DeepCMVATagInfoProducer(const edm::ParameterSet &)
const edm::EDGetTokenT< std::vector< reco::ShallowTagInfo > > deepNNSrc_
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
ProductID id() const
Definition: RefToBase.h:242
void produce(edm::Event &, const edm::EventSetup &) override
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void addDefault(ParameterSetDescription const &psetDescription)
size_t key() const
Definition: RefToBase.h:250
bool equals(const edm::RefToBase< Jet > &j1, const edm::RefToBase< Jet > &j2)
const edm::EDGetTokenT< edm::View< reco::BaseTagInfo > > ipInfoSrc_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
fixed size matrix
HLT enums.
const edm::EDGetTokenT< edm::View< reco::BaseTagInfo > > muInfoSrc_
T get() const
Definition: EventSetup.h:71
vars
Definition: DeepTauId.cc:77
void beginStream(edm::StreamID) override
T const * product() const
Definition: ESHandle.h:86
def move(src, dest)
Definition: eostools.py:511
void insert(const TaggingVariable &variable, bool delayed=false)