CMS 3D CMS Logo

HIProtoTrackSelector.h
Go to the documentation of this file.
1 #ifndef HIProtoTrackSelection_h
2 #define HIProtoTrackSelection_h
3 
7 
10 
13 
16 
18 
19 #include <algorithm>
20 #include <iostream>
21 
27 public:
28  // input collection type
30 
31  // output collection type
32  typedef std::vector<const reco::Track*> container;
33 
34  // iterator over result collection type.
35  typedef container::const_iterator const_iterator;
36 
37  // constructor from parameter set configurability
39  : vertexCollection_(iConfig.getParameter<edm::InputTag>("VertexCollection")),
41  beamSpot_(iConfig.getParameter<edm::InputTag>("beamSpotLabel")),
42  beamSpotToken_(iC.consumes<reco::BeamSpot>(beamSpot_)),
43  ptMin_(iConfig.getParameter<double>("ptMin")),
44  nSigmaZ_(iConfig.getParameter<double>("nSigmaZ")),
45  minZCut_(iConfig.getParameter<double>("minZCut")),
46  maxD0Significance_(iConfig.getParameter<double>("maxD0Significance")){};
47 
48  // select object from a collection and possibly event content
50  selected_.clear();
51 
52  const collection& c = *(TCH.product());
53 
54  // Get fast reco vertex
56  iEvent.getByToken(vertexCollectionToken_, vc);
58 
59  math::XYZPoint vtxPoint(0.0, 0.0, 0.0);
60  double vzErr = 0.0;
61 
62  if (!vertices->empty()) {
63  vtxPoint = vertices->begin()->position();
64  vzErr = vertices->begin()->zError();
65  edm::LogInfo("HeavyIonVertexing") << "Select prototracks compatible with median vertex"
66  << "\n vz = " << vtxPoint.Z() << "\n " << nSigmaZ_
67  << " vz sigmas = " << vzErr * nSigmaZ_
68  << "\n cut at = " << std::max(vzErr * nSigmaZ_, minZCut_);
69  }
70  // Supress this warning, since events w/ no vertex are expected
71  //else {
72  //edm::LogError("HeavyIonVertexing") << "No vertex found in collection '" << vertexCollection_ << "'";
73  //}
74 
75  // Get beamspot
77  edm::Handle<reco::BeamSpot> beamSpotHandle;
78  iEvent.getByToken(beamSpotToken_, beamSpotHandle);
79 
80  math::XYZPoint bsPoint(0.0, 0.0, 0.0);
81  double bsWidth = 0.0;
82 
83  if (beamSpotHandle.isValid()) {
84  beamSpot = *beamSpotHandle;
85  bsPoint = beamSpot.position();
86  bsWidth = sqrt(beamSpot.BeamWidthX() * beamSpot.BeamWidthY());
87  edm::LogInfo("HeavyIonVertexing") << "Select prototracks compatible with beamspot"
88  << "\n (x,y,z) = (" << bsPoint.X() << "," << bsPoint.Y() << "," << bsPoint.Z()
89  << ")"
90  << "\n width = " << bsWidth
91  << "\n cut at d0/d0sigma = " << maxD0Significance_;
92  } else {
93  edm::LogError("HeavyIonVertexing") << "No beam spot available from '" << beamSpot_ << "\n";
94  }
95 
96  // Do selection
97  int nSelected = 0;
98  int nRejected = 0;
99  double d0 = 0.0;
100  double d0sigma = 0.0;
101  for (reco::TrackCollection::const_iterator trk = c.begin(); trk != c.end(); ++trk) {
102  d0 = -1. * trk->dxy(bsPoint);
103  d0sigma = sqrt(trk->d0Error() * trk->d0Error() + bsWidth * bsWidth);
104  if (trk->pt() > ptMin_ // keep only tracks above ptMin
105  && fabs(d0 / d0sigma) < maxD0Significance_ // keep only tracks with D0 significance less than cut
106  && fabs(trk->dz(vtxPoint)) < std::max(vzErr * nSigmaZ_, minZCut_) // within minZCut, nSigmaZ of fast vertex
107  ) {
108  nSelected++;
109  selected_.push_back(&*trk);
110  } else
111  nRejected++;
112  }
113 
114  edm::LogInfo("HeavyIonVertexing") << "selected " << nSelected << " prototracks out of " << nRejected + nSelected
115  << "\n";
116  }
117 
118  // iterators over selected objects: collection begin
119  const_iterator begin() const { return selected_.begin(); }
120 
121  // iterators over selected objects: collection end
122  const_iterator end() const { return selected_.end(); }
123 
124  // true if no object has been selected
125  size_t size() const { return selected_.size(); }
126 
127 private:
133  double ptMin_;
134  double nSigmaZ_;
135  double minZCut_;
137 };
138 
139 #endif
T const * product() const
Definition: Handle.h:70
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
Log< level::Error, false > LogError
std::vector< Vertex > VertexCollection
Definition: Vertex.h:31
edm::EDGetTokenT< reco::VertexCollection > vertexCollectionToken_
int iEvent
Definition: GenABIO.cc:224
T sqrt(T t)
Definition: SSEVec.h:19
const_iterator begin() const
void select(edm::Handle< reco::TrackCollection > &TCH, const edm::Event &iEvent, const edm::EventSetup &iSetup)
Log< level::Info, false > LogInfo
static constexpr float d0
edm::EDGetTokenT< reco::BeamSpot > beamSpotToken_
std::vector< const reco::Track * > container
HIProtoTrackSelector(const edm::ParameterSet &iConfig, edm::ConsumesCollector &&iC)
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
reco::TrackCollection collection
bool isValid() const
Definition: HandleBase.h:70
fixed size matrix
HLT enums.
container::const_iterator const_iterator
const_iterator end() const