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
VertexCompositeCandidateCollectionSelector::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: VertexCompositeCandidateCollectionSelector.cc:85
electrons_cff.bool
bool
Definition: electrons_cff.py:372
V0Monitor_cff.v0
v0
Definition: V0Monitor_cff.py:7
edm::ParameterSetDescription::add
ParameterDescriptionBase * add(U const &iLabel, T const &value)
Definition: ParameterSetDescription.h:95
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
edm::Handle::product
T const * product() const
Definition: Handle.h:70
align::BeamSpot
Definition: StructureType.h:89
edm::EDGetTokenT< reco::VertexCompositeCandidateCollection >
edm
HLT enums.
Definition: AlignableModifier.h:19
reco::VertexCollection
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
gather_cfg.cout
cout
Definition: gather_cfg.py:144
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
EDProducer.h
VertexCompositeCandidateCollectionSelector::pvNDOF_
int pvNDOF_
Definition: VertexCompositeCandidateCollectionSelector.cc:42
VertexCompositeCandidateCollectionSelector::debug_
bool debug_
Definition: VertexCompositeCandidateCollectionSelector.cc:49
VertexCompositeCandidateCollectionSelector::lxyCUT_
float lxyCUT_
Definition: VertexCompositeCandidateCollectionSelector.cc:47
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
edm::Handle< reco::BeamSpot >
MakerMacros.h
cms::cuda::bs
bs
Definition: HistoContainer.h:127
VertexCompositeCandidateCollectionSelector::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: VertexCompositeCandidateCollectionSelector.cc:151
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
VertexCompositeCandidate.h
reco::BeamSpot
Definition: BeamSpot.h:21
GlobalPoint
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
VertexCompositeCandidateCollectionSelector::label_
std::string label_
Definition: VertexCompositeCandidateCollectionSelector.cc:44
Point3DBase< float, GlobalTag >
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
VertexCompositeCandidateCollectionSelector::VertexCompositeCandidateCollectionSelector
VertexCompositeCandidateCollectionSelector(const edm::ParameterSet &)
Definition: VertexCompositeCandidateCollectionSelector.cc:63
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
Vertex.h
edm::ParameterSetDescription::addUntracked
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
Definition: ParameterSetDescription.h:100
HLT_2018_cff.InputTag
InputTag
Definition: HLT_2018_cff.py:79016
edm::ParameterSet
Definition: ParameterSet.h:36
Event.h
createfilelist.int
int
Definition: createfilelist.py:10
MetAnalyzer.pv
def pv(vc)
Definition: MetAnalyzer.py:7
iEvent
int iEvent
Definition: GenABIO.cc:224
edm::stream::EDProducer
Definition: EDProducer.h:38
edm::EventSetup
Definition: EventSetup.h:57
instance
static PFTauRenderPlugin instance
Definition: PFTauRenderPlugin.cc:70
reco::VertexCompositeCandidateCollection
std::vector< VertexCompositeCandidate > VertexCompositeCandidateCollection
collection of Candidate objects
Definition: VertexCompositeCandidateFwd.h:19
VertexFwd.h
VertexCompositeCandidateCollectionSelector
Definition: VertexCompositeCandidateCollectionSelector.cc:27
eostools.move
def move(src, dest)
Definition: eostools.py:511
VertexCompositeCandidateCollectionSelector::v0Token_
edm::EDGetTokenT< reco::VertexCompositeCandidateCollection > v0Token_
Definition: VertexCompositeCandidateCollectionSelector.cc:38
RecoChargedCandidate.h
Frameworkfwd.h
VertexCompositeCandidateCollectionSelector::lxyWRTbsCUT_
float lxyWRTbsCUT_
Definition: VertexCompositeCandidateCollectionSelector.cc:48
mps_fire.result
result
Definition: mps_fire.py:303
ParameterSet.h
dummy
Definition: DummySelector.h:38
edm::HandleBase::isValid
bool isValid() const
Definition: HandleBase.h:70
edm::Event
Definition: Event.h:73
VertexCompositeCandidateCollectionSelector::bsToken_
edm::EDGetTokenT< reco::BeamSpot > bsToken_
Definition: VertexCompositeCandidateCollectionSelector.cc:39
PV3DBase::perp
T perp() const
Definition: PV3DBase.h:69
edm::InputTag
Definition: InputTag.h:15
reco::Vertex
Definition: Vertex.h:35
VertexCompositeCandidateCollectionSelector::pvToken_
edm::EDGetTokenT< reco::VertexCollection > pvToken_
Definition: VertexCompositeCandidateCollectionSelector.cc:40