CMS 3D CMS Logo

HLTDoubletSinglet.h
Go to the documentation of this file.
1 #ifndef HLTrigger_HLTfilters_plugins_HLTDoubletSinglet_h
2 #define HLTrigger_HLTfilters_plugins_HLTDoubletSinglet_h
3 
25 
28 
34 
36 
37 #include <string>
38 #include <vector>
39 #include <cmath>
40 
41 //
42 // class declaration
43 //
44 
45 template <typename T1, typename T2, typename T3>
46 class HLTDoubletSinglet : public HLTFilter {
47 public:
48  explicit HLTDoubletSinglet(const edm::ParameterSet&);
49  ~HLTDoubletSinglet() override;
50  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
51  bool hltFilter(edm::Event&,
52  const edm::EventSetup&,
53  trigger::TriggerFilterObjectWithRefs& filterproduct) const override;
54 
55 private:
56  // configuration
57  const std::vector<edm::InputTag> originTag1_; // input tag identifying originals 1st product
58  const std::vector<edm::InputTag> originTag2_; // input tag identifying originals 2nd product
59  const std::vector<edm::InputTag> originTag3_; // input tag identifying originals 3rd product
60  const edm::InputTag inputTag1_; // input tag identifying filtered 1st product
61  const edm::InputTag inputTag2_; // input tag identifying filtered 2nd product
62  const edm::InputTag inputTag3_; // input tag identifying filtered 3rd product
66  const int triggerType1_;
67  const int triggerType2_;
68  const int triggerType3_;
69  const double min_Dphi_, max_Dphi_; // DeltaPhi (1,3) and (2,3) window
70  const double min_Deta_, max_Deta_; // DeltaEta (1,3) and (2,3) window
71  const double min_Minv_, max_Minv_; // Minv(1,2) and Minv(2,3) window
72  const double min_DelR_, max_DelR_; // DeltaR (1,3) and (2,3) window
73  const double min_Pt_, max_Pt_; // Pt(1,3) and (2,3) window
74  const int min_N_; // number of triplets passing cuts required
75 
76  // calculated from configuration in c'tor
77  const bool same12_, same13_, same23_; // 1st and 2nd product are one and the same
78  const double min_DelR2_, max_DelR2_; // DeltaR (1,3) and (2,3) window
79  const bool cutdphi_, cutdeta_, cutminv_, cutdelr_, cutpt_; // cuts are on=true or off=false
80 
81  // typedefs
82  typedef std::vector<T1> T1Collection;
84  typedef std::vector<T2> T2Collection;
86  typedef std::vector<T3> T3Collection;
88 };
89 
90 //
91 // class implementation
92 //
93 
94 //
95 // constructors and destructor
96 //
97 template <typename T1, typename T2, typename T3>
99  : HLTFilter(iConfig),
100  originTag1_(iConfig.getParameter<std::vector<edm::InputTag>>("originTag1")),
101  originTag2_(iConfig.getParameter<std::vector<edm::InputTag>>("originTag2")),
102  originTag3_(iConfig.getParameter<std::vector<edm::InputTag>>("originTag3")),
103  inputTag1_(iConfig.getParameter<edm::InputTag>("inputTag1")),
104  inputTag2_(iConfig.getParameter<edm::InputTag>("inputTag2")),
105  inputTag3_(iConfig.getParameter<edm::InputTag>("inputTag3")),
106  inputToken1_(consumes(inputTag1_)),
107  inputToken2_(consumes(inputTag2_)),
108  inputToken3_(consumes(inputTag3_)),
109  triggerType1_(iConfig.getParameter<int>("triggerType1")),
110  triggerType2_(iConfig.getParameter<int>("triggerType2")),
111  triggerType3_(iConfig.getParameter<int>("triggerType3")),
112  min_Dphi_(iConfig.getParameter<double>("MinDphi")),
113  max_Dphi_(iConfig.getParameter<double>("MaxDphi")),
114  min_Deta_(iConfig.getParameter<double>("MinDeta")),
115  max_Deta_(iConfig.getParameter<double>("MaxDeta")),
116  min_Minv_(iConfig.getParameter<double>("MinMinv")),
117  max_Minv_(iConfig.getParameter<double>("MaxMinv")),
118  min_DelR_(iConfig.getParameter<double>("MinDelR")),
119  max_DelR_(iConfig.getParameter<double>("MaxDelR")),
120  min_Pt_(iConfig.getParameter<double>("MinPt")),
121  max_Pt_(iConfig.getParameter<double>("MaxPt")),
122  min_N_(iConfig.getParameter<int>("MinN")),
123  same12_(inputTag1_.encode() == inputTag2_.encode()), // same collections to be compared?
124  same13_(inputTag1_.encode() == inputTag3_.encode()), // same collections to be compared?
125  same23_(inputTag2_.encode() == inputTag3_.encode()), // same collections to be compared?
126  min_DelR2_(min_DelR_ < 0 ? 0 : min_DelR_ * min_DelR_), // avoid computing sqrt(R2)
127  max_DelR2_(max_DelR_ < 0 ? 0 : max_DelR_ * max_DelR_), // avoid computing sqrt(R2)
128  cutdphi_(min_Dphi_ <= max_Dphi_), // cut active?
129  cutdeta_(min_Deta_ <= max_Deta_), // cut active?
130  cutminv_(min_Minv_ <= max_Minv_), // cut active?
131  cutdelr_(min_DelR_ <= max_DelR_), // cut active?
132  cutpt_(min_Pt_ <= max_Pt_) // cut active?
133 {
134  LogDebug("") << "InputTags and cuts : " << inputTag1_.encode() << " " << inputTag2_.encode() << " "
135  << inputTag3_.encode() << triggerType1_ << " " << triggerType2_ << " " << triggerType3_ << " Dphi ["
136  << min_Dphi_ << " " << max_Dphi_ << "]"
137  << " Deta [" << min_Deta_ << " " << max_Deta_ << "]"
138  << " Minv [" << min_Minv_ << " " << max_Minv_ << "]"
139  << " DelR [" << min_DelR_ << " " << max_DelR_ << "]"
140  << " Pt [" << min_Pt_ << " " << max_Pt_ << "]"
141  << " MinN =" << min_N_ << " same12/same13/same23/dphi/deta/minv/delr/pt " << same12_ << same13_
142  << same23_ << cutdphi_ << cutdeta_ << cutminv_ << cutdelr_ << cutpt_;
143  if (cutdelr_ && max_DelR_ <= 0)
144  edm::LogWarning("HLTDoubletSinglet")
145  << " moduleLabel: " << moduleLabel()
146  << "Warning: The deltaR requirement is active, but its range is invalid: DelR [" << min_DelR_ << " "
147  << max_DelR_ << "]";
148 }
149 
150 template <typename T1, typename T2, typename T3>
152 
153 template <typename T1, typename T2, typename T3>
156  makeHLTFilterDescription(desc);
157  desc.add<std::vector<edm::InputTag>>("originTag1", {edm::InputTag("hltOriginal1")});
158  desc.add<std::vector<edm::InputTag>>("originTag2", {edm::InputTag("hltOriginal2")});
159  desc.add<std::vector<edm::InputTag>>("originTag3", {edm::InputTag("hltOriginal3")});
160  desc.add<edm::InputTag>("inputTag1", edm::InputTag("hltFiltered1"));
161  desc.add<edm::InputTag>("inputTag2", edm::InputTag("hltFiltered2"));
162  desc.add<edm::InputTag>("inputTag3", edm::InputTag("hltFiltered3"));
163  desc.add<int>("triggerType1", 0);
164  desc.add<int>("triggerType2", 0);
165  desc.add<int>("triggerType3", 0);
166  desc.add<double>("MinDphi", +1.0);
167  desc.add<double>("MaxDphi", -1.0);
168  desc.add<double>("MinDeta", +1.0);
169  desc.add<double>("MaxDeta", -1.0);
170  desc.add<double>("MinMinv", +1.0);
171  desc.add<double>("MaxMinv", -1.0);
172  desc.add<double>("MinDelR", +1.0);
173  desc.add<double>("MaxDelR", -1.0);
174  desc.add<double>("MinPt", +1.0);
175  desc.add<double>("MaxPt", -1.0);
176  desc.add<int>("MinN", 1);
178 }
179 
180 //
181 // member functions
182 //
183 
184 // ------------ method called to produce the data ------------
185 template <typename T1, typename T2, typename T3>
187  const edm::EventSetup& iSetup,
188  trigger::TriggerFilterObjectWithRefs& filterproduct) const {
189  using namespace std;
190  using namespace edm;
191  using namespace reco;
192  using namespace trigger;
193 
194  // All HLT filters must create and fill an HLT filter object,
195  // recording any reconstructed physics objects satisfying (or not)
196  // this HLT filter, and place it in the Event.
197 
198  int n(0);
199 
200  LogVerbatim("HLTDoubletSinglet") << " moduleLabel: " << moduleLabel() << " 0 ";
201 
202  // get hold of pre-filtered object collections
203  std::vector<T1Ref> coll1;
204  auto const& objsWithRefs1 = iEvent.get(inputToken1_);
205  objsWithRefs1.getObjects(triggerType1_, coll1);
206  std::vector<T2Ref> coll2;
207  auto const& objsWithRefs2 = iEvent.get(inputToken2_);
208  objsWithRefs2.getObjects(triggerType2_, coll2);
209  std::vector<T3Ref> coll3;
210  auto const& objsWithRefs3 = iEvent.get(inputToken3_);
211  objsWithRefs3.getObjects(triggerType3_, coll3);
212 
213  const size_type n1(coll1.size());
214  const size_type n2(coll2.size());
215  const size_type n3(coll3.size());
216 
217  if (saveTags()) {
218  InputTag tagOld;
219  for (size_t i = 0; i < originTag1_.size(); ++i) {
220  filterproduct.addCollectionTag(originTag1_[i]);
221  LogVerbatim("HLTDoubletSinglet") << " moduleLabel: " << moduleLabel() << " 1a/" << i << " "
222  << originTag1_[i].encode();
223  }
224  tagOld = InputTag();
225  for (size_type i1 = 0; i1 != n1; ++i1) {
226  const ProductID pid(coll1[i1].id());
227  const auto& prov = iEvent.getStableProvenance(pid);
228  const string& label(prov.moduleLabel());
229  const string& instance(prov.productInstanceName());
230  const string& process(prov.processName());
232  if (tagOld.encode() != tagNew.encode()) {
233  filterproduct.addCollectionTag(tagNew);
234  tagOld = tagNew;
235  LogVerbatim("HLTDoubletSinglet") << " moduleLabel: " << moduleLabel() << " 1b " << tagNew.encode();
236  }
237  }
238  for (size_t i = 0; i < originTag2_.size(); ++i) {
239  filterproduct.addCollectionTag(originTag2_[i]);
240  LogVerbatim("HLTDoubletSinglet") << " moduleLabel: " << moduleLabel() << " 2a/" << i << " "
241  << originTag2_[i].encode();
242  }
243  tagOld = InputTag();
244  for (size_type i2 = 0; i2 != n2; ++i2) {
245  const ProductID pid(coll2[i2].id());
246  const auto& prov = iEvent.getStableProvenance(pid);
247  const string& label(prov.moduleLabel());
248  const string& instance(prov.productInstanceName());
249  const string& process(prov.processName());
251  if (tagOld.encode() != tagNew.encode()) {
252  filterproduct.addCollectionTag(tagNew);
253  tagOld = tagNew;
254  LogVerbatim("HLTDoubletSinglet") << " moduleLabel: " << moduleLabel() << " 2b " << tagNew.encode();
255  }
256  }
257  for (size_t i = 0; i < originTag3_.size(); ++i) {
258  filterproduct.addCollectionTag(originTag3_[i]);
259  LogVerbatim("HLTDoubletSinglet") << " moduleLabel: " << moduleLabel() << " 3a/" << i << " "
260  << originTag3_[i].encode();
261  }
262  tagOld = InputTag();
263  for (size_type i3 = 0; i3 != n3; ++i3) {
264  const ProductID pid(coll3[i3].id());
265  const auto& prov = iEvent.getStableProvenance(pid);
266  const string& label(prov.moduleLabel());
267  const string& instance(prov.productInstanceName());
268  const string& process(prov.processName());
270  if (tagOld.encode() != tagNew.encode()) {
271  filterproduct.addCollectionTag(tagNew);
272  tagOld = tagNew;
273  LogVerbatim("HLTDoubletSinglet") << " moduleLabel: " << moduleLabel() << " 3b " << tagNew.encode();
274  }
275  }
276 
277  T1Ref r1;
278  T2Ref r2;
279  T3Ref r3;
280  Candidate::LorentzVector p1, p2, p3, p13, p23;
281  for (size_t i1 = 0; i1 != n1; i1++) {
282  r1 = coll1[i1];
283  p1 = r1->p4();
284  auto const i2_min = (same12_ ? i1 + 1 : 0);
285  for (size_t i2 = i2_min; i2 != n2; i2++) {
286  r2 = coll2[i2];
287  p2 = r2->p4();
288 
289  auto const i3_min = (same23_ ? i2_min + 1 : (same13_ ? i1 + 1 : 0));
290  for (size_t i3 = i3_min; i3 != n3; i3++) {
291  r3 = coll3[i3];
292  p3 = r3->p4();
293 
294  //deltaPhi
295  auto const dPhi13(std::abs(deltaPhi(p1.phi(), p3.phi())));
296  if (cutdphi_ && (min_Dphi_ > dPhi13 || dPhi13 > max_Dphi_))
297  continue;
298  auto const dPhi23(std::abs(deltaPhi(p2.phi(), p3.phi())));
299  if (cutdphi_ && (min_Dphi_ > dPhi23 || dPhi23 > max_Dphi_))
300  continue;
301 
302  //deltaEta
303  auto const dEta13(std::abs(p1.eta() - p3.eta()));
304  if (cutdeta_ && (min_Deta_ > dEta13 || dEta13 > max_Deta_))
305  continue;
306  auto const dEta23(std::abs(p2.eta() - p3.eta()));
307  if (cutdeta_ && (min_Deta_ > dEta23 || dEta23 > max_Deta_))
308  continue;
309 
310  //deltaR
311  auto const delR2_13(dPhi13 * dPhi13 + dEta13 * dEta13);
312  if (cutdelr_ && (min_DelR2_ > delR2_13 || delR2_13 > max_DelR2_))
313  continue;
314  auto const delR2_23(dPhi23 * dPhi23 + dEta23 * dEta23);
315  if (cutdelr_ && (min_DelR2_ > delR2_23 || delR2_23 > max_DelR2_))
316  continue;
317 
318  //Pt and Minv
319  p13 = p1 + p3;
320  auto const mInv13(std::abs(p13.mass()));
321  if (cutminv_ && (min_Minv_ > mInv13 || mInv13 > max_Minv_))
322  continue;
323  auto const pt13(p13.pt());
324  if (cutpt_ && (min_Pt_ > pt13 || pt13 > max_Pt_))
325  continue;
326 
327  p23 = p2 + p3;
328  auto const mInv23(std::abs(p23.mass()));
329  if (cutminv_ && (min_Minv_ > mInv23 || mInv23 > max_Minv_))
330  continue;
331  auto const pt23(p23.pt());
332  if (cutpt_ && (min_Pt_ > pt23 || pt23 > max_Pt_))
333  continue;
334 
335  n++;
336  filterproduct.addObject(triggerType1_, r1);
337  filterproduct.addObject(triggerType2_, r2);
338  filterproduct.addObject(triggerType3_, r3);
339  }
340  }
341  }
342  }
343 
344  // filter decision
345  return (n >= min_N_);
346 }
347 
348 #endif //HLTrigger_HLTfilters_plugins_HLTDoubletSinglet_h
Log< level::Info, true > LogVerbatim
static PFTauRenderPlugin instance
std::string encode() const
Definition: InputTag.cc:159
const double min_DelR_
bool hltFilter(edm::Event &, const edm::EventSetup &, trigger::TriggerFilterObjectWithRefs &filterproduct) const override
const double min_Pt_
std::vector< T1 > T1Collection
const double min_Deta_
std::string defaultModuleLabel()
const double max_DelR_
uint16_t size_type
const double max_DelR2_
const double min_Dphi_
const std::vector< edm::InputTag > originTag1_
edm::Ref< T2Collection > T2Ref
void addObject(int id, const reco::RecoEcalCandidateRef &ref)
setters for L3 collections: (id=physics type, and Ref<C>)
char const * label
~HLTDoubletSinglet() override
const double max_Pt_
int iEvent
Definition: GenABIO.cc:224
const edm::EDGetTokenT< trigger::TriggerFilterObjectWithRefs > inputToken3_
const edm::InputTag inputTag1_
const std::string * moduleLabel() const
Definition: HLTFilter.cc:61
edm::Ref< T1Collection > T1Ref
const double max_Dphi_
const edm::InputTag inputTag3_
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
edm::Ref< T3Collection > T3Ref
const double min_DelR2_
std::vector< T3 > T3Collection
const std::vector< edm::InputTag > originTag3_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
const edm::InputTag inputTag2_
const edm::EDGetTokenT< trigger::TriggerFilterObjectWithRefs > inputToken1_
void addCollectionTag(const edm::InputTag &collectionTag)
collectionTags
void add(std::string const &label, ParameterSetDescription const &psetDescription)
def encode(args, files)
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Candidate.h:36
const std::vector< edm::InputTag > originTag2_
fixed size matrix
HLT enums.
std::vector< T2 > T2Collection
const double max_Deta_
const double max_Minv_
Log< level::Warning, false > LogWarning
HLTDoubletSinglet(const edm::ParameterSet &)
const double min_Minv_
const edm::EDGetTokenT< trigger::TriggerFilterObjectWithRefs > inputToken2_
#define LogDebug(id)