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 //
58 // static data member definitions
59 //
60 
61 //
62 // constructors and destructor
63 //
65  : v0Token_ ( consumes<reco::VertexCompositeCandidateCollection>(iConfig.getParameter<edm::InputTag>("v0") ) )
66  , bsToken_ ( consumes<reco::BeamSpot> (iConfig.getParameter<edm::InputTag>("beamSpot") ) )
67  , pvToken_ ( consumes<reco::VertexCollection> (iConfig.getParameter<edm::InputTag>("primaryVertex") ) )
68  , pvNDOF_ ( iConfig.getParameter<int> ("pvNDOF") )
69  , label_ ( iConfig.getParameter<edm::InputTag>("v0").instance() )
70  , lxyCUT_ ( iConfig.getParameter<double>("lxyCUT") )
71  , lxyWRTbsCUT_ ( iConfig.getParameter<double>("lxyWRTbsCUT") )
72  , debug_ ( iConfig.getUntrackedParameter<bool>("debug") )
73 {
74  if (debug_) std::cout << "VertexCompositeCandidateCollectionSelector::VertexCompositeCandidateCollectionSelector" << std::endl;
75  // product
76  produces<reco::VertexCompositeCandidateCollection>();
77 
78  //now do what ever other initialization is needed
79 
80 }
81 
82 
83 //
84 // member functions
85 //
86 
87 // ------------ method called to produce the data ------------
88 void
90 {
91  using namespace edm;
92 
93  if (debug_) std::cout << "VertexCompositeCandidateCollectionSelector::produce" << std::endl;
94 
95  // Create auto_ptr for each collection to be stored in the Event
96  auto result = std::make_unique<reco::VertexCompositeCandidateCollection>();
97 
98  edm::Handle<reco::BeamSpot> beamspotHandle;
99  iEvent.getByToken(bsToken_,beamspotHandle);
100  reco::BeamSpot const * bs = nullptr;
101  if (beamspotHandle.isValid())
102  bs = &(*beamspotHandle);
103 
104 
106  iEvent.getByToken(pvToken_, pvHandle );
107  reco::Vertex const * pv = nullptr;
108  if (pvHandle.isValid()) {
109  pv = &pvHandle->front();
110  //--- pv fake (the pv collection should have size==1 and the pv==beam spot)
111  if ( pv->isFake() || pv->tracksSize()==0
112  // definition of goodOfflinePrimaryVertex
113  || pv->ndof() < pvNDOF_ || pv->z() > 24.) pv = nullptr;
114  }
115 
117  iEvent.getByToken(v0Token_, v0Handle);
118  int n = ( v0Handle.isValid() ? v0Handle->size() : -1 );
119  if (debug_) std::cout << "n: " << n << std::endl;
120  if (n>0) {
121 
122  auto const& v0s = *v0Handle.product();
123  for ( auto const& v0 : v0s ) {
124  GlobalPoint displacementFromPV2D = ( pv==nullptr ? dummyGP : GlobalPoint( (pv->x() - v0.vx()),
125  (pv->y() - v0.vy()),
126  0. ) );
127  GlobalPoint displacementFromBS2D = ( bs==nullptr ? dummyGP : GlobalPoint( v0.vx() - bs->x(v0.vz()),
128  v0.vy() - bs->y(v0.vz()),
129  0. ) );
130  float abslxy = ( pv==nullptr ? dummy : displacementFromPV2D.perp() );
131  float abslxyWRTbs = ( bs==nullptr ? dummy : displacementFromBS2D.perp() );
132 
133  if (debug_) std::cout << "abslxy: " << abslxy << " w.r.t. " << lxyCUT_ << " ==> " << ( abslxy >= lxyCUT_ ? "OK" : "KO" ) << std::endl;
134  if (debug_) std::cout << "abslxyWRTbs: " << abslxyWRTbs << " w.r.t. " << lxyWRTbsCUT_ << " ==> " << ( abslxyWRTbs >= lxyWRTbsCUT_ ? "OK" : "KO" ) << std::endl;
135  if (abslxy < lxyCUT_ ) continue;
136  if (abslxyWRTbs < lxyWRTbsCUT_) continue;
137  result->push_back(v0);
138  }
139  }
140 
141  if (debug_) std::cout << "result: " << result->size() << std::endl;
142  // put into the Event
143  // Write the collections to the Event
144  result->shrink_to_fit(); iEvent.put(std::move(result) );
145 
146 }
147 
148 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
149 void
151  //The following says we do not know what parameters are allowed so do no validation
152  // Please change this to state exactly what you do use, even if it is no parameters
154  desc.add<edm::InputTag>("v0");
155  desc.add<edm::InputTag>("beamSpot");
156  desc.add<edm::InputTag>("primaryVertex");
157  desc.add<int>("pvNDOF");
158  desc.add<double>("lxyCUT", 16.); // cm (2016 pixel layer3:10.2 cm ; 2017 pixel layer4: 16.0 cm)
159  desc.add<double>("lxyWRTbsCUT", 0.); // cm
160  desc.addUntracked<bool>("debug",false);
161  descriptions.add("VertexCompositeCandidateCollectionSelector",desc);
162 }
163 
164 //define this as a plug-in
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void produce(edm::Event &, const edm::EventSetup &) override
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:127
std::vector< VertexCompositeCandidate > VertexCompositeCandidateCollection
collection of Candidate objects
T perp() const
Definition: PV3DBase.h:72
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
edm::EDGetTokenT< reco::VertexCompositeCandidateCollection > v0Token_
static PFTauRenderPlugin instance
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:508
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
double y() const
y coordinate
Definition: Vertex.h:113
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
int iEvent
Definition: GenABIO.cc:230
def pv(vc)
Definition: MetAnalyzer.py:6
double z() const
z coordinate
Definition: Vertex.h:115
ParameterDescriptionBase * add(U const &iLabel, T const &value)
bool isValid() const
Definition: HandleBase.h:74
double ndof() const
Definition: Vertex.h:105
double x() const
x coordinate
Definition: Vertex.h:111
bool isFake() const
Definition: Vertex.h:72
T const * product() const
Definition: Handle.h:81
double x(const double z) const
x coordinate of the beeam spot position at a given z value (it takes into account the dxdz slope) ...
Definition: BeamSpot.h:71
void add(std::string const &label, ParameterSetDescription const &psetDescription)
fixed size matrix
HLT enums.
double y(const double z) const
y coordinate of the beeam spot position at a given z value (it takes into account the dydz slope) ...
Definition: BeamSpot.h:73
def move(src, dest)
Definition: eostools.py:510
size_t tracksSize() const
number of tracks
Definition: Vertex.cc:71