CMS 3D CMS Logo

VertexCompositeCandidateCollectionSelector.cc
Go to the documentation of this file.
1 // system include files
2 #include <memory>
3 
4 // user include files
7 
10 
12 
15 
18 
19 //
20 // class declaration
21 //
22 namespace {
23  const float dummy = -9.;
24  const GlobalPoint dummyGP(dummy, dummy, 0.);
25 } //end anonymous namespace
26 
28 public:
30 
31  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
32 
33 private:
34  void produce(edm::Event&, const edm::EventSetup&) override;
35 
36  // ----------member data ---------------------------
37 
41 
42  int pvNDOF_;
43 
45 
46  // list of variables for the selection
47  float lxyCUT_;
48  float lxyWRTbsCUT_;
49  bool debug_;
50 };
51 
52 //
53 // constants, enums and typedefs
54 //
55 
56 //
57 // static data member definitions
58 //
59 
60 //
61 // constructors and destructor
62 //
64  : v0Token_(consumes<reco::VertexCompositeCandidateCollection>(iConfig.getParameter<edm::InputTag>("v0"))),
65  bsToken_(consumes<reco::BeamSpot>(iConfig.getParameter<edm::InputTag>("beamSpot"))),
66  pvToken_(consumes<reco::VertexCollection>(iConfig.getParameter<edm::InputTag>("primaryVertex"))),
67  pvNDOF_(iConfig.getParameter<int>("pvNDOF")),
68  label_(iConfig.getParameter<edm::InputTag>("v0").instance()),
69  lxyCUT_(iConfig.getParameter<double>("lxyCUT")),
70  lxyWRTbsCUT_(iConfig.getParameter<double>("lxyWRTbsCUT")),
71  debug_(iConfig.getUntrackedParameter<bool>("debug")) {
72  if (debug_)
73  std::cout << "VertexCompositeCandidateCollectionSelector::VertexCompositeCandidateCollectionSelector" << std::endl;
74  // product
75  produces<reco::VertexCompositeCandidateCollection>();
76 
77  //now do what ever other initialization is needed
78 }
79 
80 //
81 // member functions
82 //
83 
84 // ------------ method called to produce the data ------------
86  using namespace edm;
87 
88  if (debug_)
89  std::cout << "VertexCompositeCandidateCollectionSelector::produce" << std::endl;
90 
91  // Create auto_ptr for each collection to be stored in the Event
92  auto result = std::make_unique<reco::VertexCompositeCandidateCollection>();
93 
94  edm::Handle<reco::BeamSpot> beamspotHandle;
95  iEvent.getByToken(bsToken_, beamspotHandle);
96  reco::BeamSpot const* bs = nullptr;
97  if (beamspotHandle.isValid())
98  bs = &(*beamspotHandle);
99 
101  iEvent.getByToken(pvToken_, pvHandle);
102  reco::Vertex const* pv = nullptr;
103  if (pvHandle.isValid()) {
104  pv = &pvHandle->front();
105  //--- pv fake (the pv collection should have size==1 and the pv==beam spot)
106  if (pv->isFake() ||
107  pv->tracksSize() == 0
108  // definition of goodOfflinePrimaryVertex
109  || pv->ndof() < pvNDOF_ || pv->z() > 24.)
110  pv = nullptr;
111  }
112 
114  iEvent.getByToken(v0Token_, v0Handle);
115  int n = (v0Handle.isValid() ? v0Handle->size() : -1);
116  if (debug_)
117  std::cout << "n: " << n << std::endl;
118  if (n > 0) {
119  auto const& v0s = *v0Handle.product();
120  for (auto const& v0 : v0s) {
121  GlobalPoint displacementFromPV2D =
122  (pv == nullptr ? dummyGP : GlobalPoint((pv->x() - v0.vx()), (pv->y() - v0.vy()), 0.));
123  GlobalPoint displacementFromBS2D =
124  (bs == nullptr ? dummyGP : GlobalPoint(v0.vx() - bs->x(v0.vz()), v0.vy() - bs->y(v0.vz()), 0.));
125  float abslxy = (pv == nullptr ? dummy : displacementFromPV2D.perp());
126  float abslxyWRTbs = (bs == nullptr ? dummy : displacementFromBS2D.perp());
127 
128  if (debug_)
129  std::cout << "abslxy: " << abslxy << " w.r.t. " << lxyCUT_ << " ==> " << (abslxy >= lxyCUT_ ? "OK" : "KO")
130  << std::endl;
131  if (debug_)
132  std::cout << "abslxyWRTbs: " << abslxyWRTbs << " w.r.t. " << lxyWRTbsCUT_ << " ==> "
133  << (abslxyWRTbs >= lxyWRTbsCUT_ ? "OK" : "KO") << std::endl;
134  if (abslxy < lxyCUT_)
135  continue;
136  if (abslxyWRTbs < lxyWRTbsCUT_)
137  continue;
138  result->push_back(v0);
139  }
140  }
141 
142  if (debug_)
143  std::cout << "result: " << result->size() << std::endl;
144  // put into the Event
145  // Write the collections to the Event
146  result->shrink_to_fit();
147  iEvent.put(std::move(result));
148 }
149 
150 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
152  //The following says we do not know what parameters are allowed so do no validation
153  // Please change this to state exactly what you do use, even if it is no parameters
155  desc.add<edm::InputTag>("v0");
156  desc.add<edm::InputTag>("beamSpot");
157  desc.add<edm::InputTag>("primaryVertex");
158  desc.add<int>("pvNDOF");
159  desc.add<double>("lxyCUT", 16.); // cm (2016 pixel layer3:10.2 cm ; 2017 pixel layer4: 16.0 cm)
160  desc.add<double>("lxyWRTbsCUT", 0.); // cm
161  desc.addUntracked<bool>("debug", false);
162  descriptions.add("VertexCompositeCandidateCollectionSelector", desc);
163 }
164 
165 //define this as a plug-in
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void produce(edm::Event &, const edm::EventSetup &) override
T perp() const
Definition: PV3DBase.h:69
std::vector< VertexCompositeCandidate > VertexCompositeCandidateCollection
collection of Candidate objects
edm::EDGetTokenT< reco::VertexCompositeCandidateCollection > v0Token_
static PFTauRenderPlugin instance
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
T const * product() const
Definition: Handle.h:70
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
std::vector< Vertex > VertexCollection
Definition: Vertex.h:31
int iEvent
Definition: GenABIO.cc:224
def pv(vc)
Definition: MetAnalyzer.py:7
void add(std::string const &label, ParameterSetDescription const &psetDescription)
bool isValid() const
Definition: HandleBase.h:70
fixed size matrix
HLT enums.
def move(src, dest)
Definition: eostools.py:511