CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
L1ExtraMixerPluginT.cc
Go to the documentation of this file.
2 
4 
6 
8 
10 
11 #include <TMath.h>
12 
13 const size_t maxNumL1ExtraObjects = 4;
14 
15 template <typename T>
18 {
19  if ( cfg.exists("srcSelectedMuons1") ) {
20  srcSelectedMuons1_ = cfg.getParameter<edm::InputTag>("srcSelectedMuons1");
21  dRveto1_ = cfg.getParameter<double>("dRveto1");
22  }
23  if ( cfg.exists("srcSelectedMuons2") ) {
24  srcSelectedMuons2_ = cfg.getParameter<edm::InputTag>("srcSelectedMuons2");
25  dRveto2_ = cfg.getParameter<double>("dRveto2");
26  }
27 }
28 
29 template <typename T>
31 {
32  producer.produces<l1ExtraCollection>(instanceLabel_);
33 }
34 
35 namespace
36 {
37  template <typename T>
38  std::vector<const T*> getCleanedCollection(const std::vector<T>& l1ExtraObjects, const edm::Event& evt, const edm::InputTag& srcSelectedMuons, double dRveto)
39  {
40  std::vector<const T*> l1ExtraObjects_cleaned;
41  if ( srcSelectedMuons.label() != "" ) {
42  std::vector<reco::CandidateBaseRef> selMuons = getSelMuons(evt, srcSelectedMuons);
43  for ( typename std::vector<T>::const_iterator l1ExtraObject = l1ExtraObjects.begin();
44  l1ExtraObject != l1ExtraObjects.end(); ++l1ExtraObject ) {
45  bool isVetoed = false;
46  for ( std::vector<reco::CandidateBaseRef>::const_iterator selMuon = selMuons.begin();
47  selMuon != selMuons.end(); ++selMuon ) {
48  double dR = deltaR(l1ExtraObject->p4(), (*selMuon)->p4());
49  if ( dR < dRveto ) isVetoed = true;
50  }
51  if ( !isVetoed ) l1ExtraObjects_cleaned.push_back(&(*l1ExtraObject));
52  }
53  } else {
54  for ( typename std::vector<T>::const_iterator l1ExtraObject = l1ExtraObjects.begin();
55  l1ExtraObject != l1ExtraObjects.end(); ++l1ExtraObject ) {
56  l1ExtraObjects_cleaned.push_back(&(*l1ExtraObject));
57  }
58  }
59  return l1ExtraObjects_cleaned;
60  }
61 
62  template <typename TPtr>
63  struct higherPtT
64  {
65  bool operator() (const TPtr& t1, const TPtr& t2)
66  {
67  return (t1->pt() > t2->pt());
68  }
69  };
70 }
71 
72 template <typename T>
74 {
75  edm::Handle<l1ExtraCollection> l1ExtraObjects1;
76  evt.getByLabel(src1_, l1ExtraObjects1);
77  l1ExtraPtrCollection l1ExtraObjects1_cleaned = getCleanedCollection(*l1ExtraObjects1, evt, srcSelectedMuons1_, dRveto1_);
78 
79  edm::Handle<l1ExtraCollection> l1ExtraObjects2;
80  evt.getByLabel(src2_, l1ExtraObjects2);
81  l1ExtraPtrCollection l1ExtraObjects2_cleaned = getCleanedCollection(*l1ExtraObjects2, evt, srcSelectedMuons2_, dRveto2_);
82 
83  l1ExtraPtrCollection l1ExtraObjects_sorted;
84  l1ExtraObjects_sorted.insert(l1ExtraObjects_sorted.end(), l1ExtraObjects1_cleaned.begin(), l1ExtraObjects1_cleaned.end());
85  l1ExtraObjects_sorted.insert(l1ExtraObjects_sorted.end(), l1ExtraObjects2_cleaned.begin(), l1ExtraObjects2_cleaned.end());
86  higherPtT<const T*> higherPt;
87  std::sort(l1ExtraObjects_sorted.begin(), l1ExtraObjects_sorted.end(), higherPt);
88 
89  std::auto_ptr<l1ExtraCollection> l1ExtraObjects_output(new l1ExtraCollection());
90 
91  size_t numL1ExtraObjects = l1ExtraObjects_sorted.size();
92  for ( size_t iObject = 0; iObject < TMath::Min(numL1ExtraObjects, maxNumL1ExtraObjects); ++iObject ) {
93  l1ExtraObjects_output->push_back(*l1ExtraObjects_sorted.at(iObject));
94  }
95 
96  evt.put(l1ExtraObjects_output, instanceLabel_);
97 }
98 
102 
106 
108 
109 DEFINE_EDM_PLUGIN(L1ExtraMixerPluginFactory, L1ExtraEmParticleMixerPlugin, "L1ExtraEmParticleMixerPlugin");
110 DEFINE_EDM_PLUGIN(L1ExtraMixerPluginFactory, L1ExtraMuonParticleMixerPlugin, "L1ExtraMuonParticleMixerPlugin");
111 DEFINE_EDM_PLUGIN(L1ExtraMixerPluginFactory, L1ExtraJetParticleMixerPlugin, "L1ExtraJetParticleMixerPlugin");
T getParameter(std::string const &) const
const size_t maxNumL1ExtraObjects
tuple cfg
Definition: looper.py:237
std::vector< T > l1ExtraCollection
bool exists(std::string const &parameterName) const
checks if a parameter exists
T Min(T a, T b)
Definition: MathUtil.h:39
std::vector< const T * > l1ExtraPtrCollection
L1ExtraMixerPluginT< l1extra::L1MuonParticle > L1ExtraMuonParticleMixerPlugin
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:113
L1ExtraMixerPluginT(const edm::ParameterSet &)
virtual void produce(edm::Event &, const edm::EventSetup &)
virtual void registerProducts(edm::EDProducer &)
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:402
double deltaR(double eta1, double eta2, double phi1, double phi2)
Definition: TreeUtility.cc:17
L1ExtraMixerPluginT< l1extra::L1EmParticle > L1ExtraEmParticleMixerPlugin
edm::InputTag srcSelectedMuons2_
std::string const & label() const
Definition: InputTag.h:42
L1ExtraMixerPluginT< l1extra::L1JetParticle > L1ExtraJetParticleMixerPlugin
edm::InputTag srcSelectedMuons1_
#define DEFINE_EDM_PLUGIN(factory, type, name)
std::vector< reco::CandidateBaseRef > getSelMuons(const edm::Event &, const edm::InputTag &)