CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
AnalyticalTrackSelector.cc
Go to the documentation of this file.
4 
6 #include <Math/DistFunc.h>
7 #include "TMath.h"
8 
10 
11 AnalyticalTrackSelector::AnalyticalTrackSelector( const edm::ParameterSet & cfg ) : MultiTrackSelector( )
12 {
13  //Spoof the pset for each track selector!
14  //Size is always 1!!!
15  qualityToSet_.reserve(1);
16  vtxNumber_.reserve(1);
17  vertexCut_.reserve(1);
18  res_par_.reserve(1);
19  chi2n_par_.reserve(1);
20  chi2n_no1Dmod_par_.reserve(1);
21  d0_par1_.reserve(1);
22  dz_par1_.reserve(1);
23  d0_par2_.reserve(1);
24  dz_par2_.reserve(1);
25  applyAdaptedPVCuts_.reserve(1);
26  max_d0_.reserve(1);
27  max_z0_.reserve(1);
28  nSigmaZ_.reserve(1);
29  min_layers_.reserve(1);
30  min_3Dlayers_.reserve(1);
31  max_lostLayers_.reserve(1);
32  min_hits_bypass_.reserve(1);
33  applyAbsCutsIfNoPV_.reserve(1);
34  max_d0NoPV_.reserve(1);
35  max_z0NoPV_.reserve(1);
36  preFilter_.reserve(1);
37  max_relpterr_.reserve(1);
38  min_nhits_.reserve(1);
39  max_minMissHitOutOrIn_.reserve(1);
40  max_lostHitFraction_.reserve(1);
41  min_eta_.reserve(1);
42  max_eta_.reserve(1);
43 
44  produces<edm::ValueMap<float> >("MVAVals");
45  useAnyMVA_ = false;
46  forest_ = 0;
47  gbrVals_ = 0;
48 
49  src_ = cfg.getParameter<edm::InputTag>( "src" );
50  beamspot_ = cfg.getParameter<edm::InputTag>( "beamspot" );
51  useVertices_ = cfg.getParameter<bool>( "useVertices" );
52  useVtxError_ = cfg.getParameter<bool>( "useVtxError" );
53  vertices_ = useVertices_ ? cfg.getParameter<edm::InputTag>( "vertices" ) : edm::InputTag("NONE");
54  copyExtras_ = cfg.getUntrackedParameter<bool>("copyExtras", false);
55  copyTrajectories_ = cfg.getUntrackedParameter<bool>("copyTrajectories", false);
56 
58  // parameters for vertex selection
59  vtxNumber_.push_back( useVertices_ ? cfg.getParameter<int32_t>("vtxNumber") : 0 );
60  vertexCut_.push_back( useVertices_ ? cfg.getParameter<std::string>("vertexCut") : "");
61  // parameters for adapted optimal cuts on chi2 and primary vertex compatibility
62  res_par_.push_back(cfg.getParameter< std::vector<double> >("res_par") );
63  chi2n_par_.push_back( cfg.getParameter<double>("chi2n_par") );
64  chi2n_no1Dmod_par_.push_back( cfg.getParameter<double>("chi2n_no1Dmod_par") );
65  d0_par1_.push_back(cfg.getParameter< std::vector<double> >("d0_par1"));
66  dz_par1_.push_back(cfg.getParameter< std::vector<double> >("dz_par1"));
67  d0_par2_.push_back(cfg.getParameter< std::vector<double> >("d0_par2"));
68  dz_par2_.push_back(cfg.getParameter< std::vector<double> >("dz_par2"));
69 
70  // Boolean indicating if adapted primary vertex compatibility cuts are to be applied.
71  applyAdaptedPVCuts_.push_back(cfg.getParameter<bool>("applyAdaptedPVCuts"));
72  // Impact parameter absolute cuts.
73  max_d0_.push_back(cfg.getParameter<double>("max_d0"));
74  max_z0_.push_back(cfg.getParameter<double>("max_z0"));
75  nSigmaZ_.push_back(cfg.getParameter<double>("nSigmaZ"));
76  // Cuts on numbers of layers with hits/3D hits/lost hits.
77  min_layers_.push_back(cfg.getParameter<uint32_t>("minNumberLayers") );
78  min_3Dlayers_.push_back(cfg.getParameter<uint32_t>("minNumber3DLayers") );
79  max_lostLayers_.push_back(cfg.getParameter<uint32_t>("maxNumberLostLayers"));
80  min_hits_bypass_.push_back(cfg.getParameter<uint32_t>("minHitsToBypassChecks"));
81  max_relpterr_.push_back(cfg.getParameter<double>("max_relpterr"));
82  min_nhits_.push_back(cfg.getParameter<uint32_t>("min_nhits"));
83  max_minMissHitOutOrIn_.push_back(
84  cfg.existsAs<int32_t>("max_minMissHitOutOrIn") ?
85  cfg.getParameter<int32_t>("max_minMissHitOutOrIn") : 99);
86  max_lostHitFraction_.push_back(
87  cfg.existsAs<double>("max_lostHitFraction") ?
88  cfg.getParameter<double>("max_lostHitFraction") : 1.0);
89  min_eta_.push_back(cfg.getParameter<double>("min_eta"));
90  max_eta_.push_back(cfg.getParameter<double>("max_eta"));
91 
92  // Flag to apply absolute cuts if no PV passes the selection
93  applyAbsCutsIfNoPV_.push_back(cfg.getParameter<bool>("applyAbsCutsIfNoPV"));
94  keepAllTracks_.push_back( cfg.exists("keepAllTracks") ?
95  cfg.getParameter<bool>("keepAllTracks") :
96  false );
97 
98  setQualityBit_.push_back( false );
99  std::string qualityStr = cfg.getParameter<std::string>("qualityBit");
100 
101  if(d0_par1_[0].size()!=2 || dz_par1_[0].size()!=2 || d0_par2_[0].size()!=2 || dz_par2_[0].size()!=2)
102  {
103  edm::LogError("MisConfiguration")<<"vector of size less then 2";
104  throw;
105  }
106 
107  if (cfg.exists("qualityBit")) {
108  std::string qualityStr = cfg.getParameter<std::string>("qualityBit");
109  if (qualityStr != "") {
110  setQualityBit_[0] = true;
112  }
113  }
114 
115  if (keepAllTracks_[0] && !setQualityBit_[0]) throw cms::Exception("Configuration") <<
116  "If you set 'keepAllTracks' to true, you must specify which qualityBit to set.\n";
117  if (setQualityBit_[0] && (qualityToSet_[0] == TrackBase::undefQuality)) throw cms::Exception("Configuration") <<
118  "You can't set the quality bit " << cfg.getParameter<std::string>("qualityBit") << " as it is 'undefQuality' or unknown.\n";
119  if (applyAbsCutsIfNoPV_[0]) {
120  max_d0NoPV_.push_back(cfg.getParameter<double>("max_d0NoPV"));
121  max_z0NoPV_.push_back(cfg.getParameter<double>("max_z0NoPV"));
122  }
123  else{//dummy values
124  max_d0NoPV_.push_back(0.);
125  max_z0NoPV_.push_back(0.);
126  }
127 
128  std::string alias( cfg.getParameter<std::string>( "@module_label" ) );
129  produces<reco::TrackCollection>().setBranchAlias( alias + "Tracks");
130  if (copyExtras_) {
131  produces<reco::TrackExtraCollection>().setBranchAlias( alias + "TrackExtras");
132  produces<TrackingRecHitCollection>().setBranchAlias( alias + "RecHits");
133  }
134  if (copyTrajectories_) {
135  produces< std::vector<Trajectory> >().setBranchAlias( alias + "Trajectories");
136  produces< TrajTrackAssociationCollection >().setBranchAlias( alias + "TrajectoryTrackAssociations");
137  }
138 }
139 
141 }
142 
144 {
145  using namespace std;
146  using namespace edm;
147  using namespace reco;
148 
149  Handle<TrackCollection> hSrcTrack;
153 
154  // looking for the beam spot
156  evt.getByLabel(beamspot_, hBsp);
157  reco::BeamSpot vertexBeamSpot;
158  vertexBeamSpot = *hBsp;
159 
160  // Select good primary vertices for use in subsequent track selection
162  std::vector<Point> points;
163  std::vector<float> vterr, vzerr;
164  if (useVertices_) {
165  evt.getByLabel(vertices_, hVtx);
166  selectVertices(0,*hVtx, points, vterr, vzerr);
167  // Debug
168  LogDebug("SelectVertex") << points.size() << " good pixel vertices";
169  }
170 
171  // Get tracks
172  evt.getByLabel( src_, hSrcTrack );
173 
174  selTracks_ = auto_ptr<TrackCollection>(new TrackCollection());
176  if (copyExtras_) {
177  selTrackExtras_ = auto_ptr<TrackExtraCollection>(new TrackExtraCollection());
178  selHits_ = auto_ptr<TrackingRecHitCollection>(new TrackingRecHitCollection());
181  }
182 
183  if (copyTrajectories_) trackRefs_.resize(hSrcTrack->size());
184 
185  processMVA(evt,es);
186 
187  // Loop over tracks
188  size_t current = 0;
189  for (TrackCollection::const_iterator it = hSrcTrack->begin(), ed = hSrcTrack->end(); it != ed; ++it, ++current) {
190  const Track & trk = * it;
191  // Check if this track passes cuts
192 
193  LogTrace("TrackSelection") << "ready to check track with pt="<< trk.pt() ;
194 
195  double mvaVal = 0;
196  if(useAnyMVA_)mvaVal = mvaVals_[current];
197  bool ok = select(0,vertexBeamSpot, trk, points, vterr, vzerr,mvaVal);
198  if (!ok) {
199 
200  LogTrace("TrackSelection") << "track with pt="<< trk.pt() << " NOT selected";
201 
203  if (!keepAllTracks_[0]) continue;
204  }
205  LogTrace("TrackSelection") << "track with pt="<< trk.pt() << " selected";
206  selTracks_->push_back( Track( trk ) ); // clone and store
207  if (ok && setQualityBit_[0]) {
208  selTracks_->back().setQuality(qualityToSet_[0]);
209  if (!points.empty()) {
212  }
213  }
214  if (copyExtras_) {
215  // TrackExtras
216  selTrackExtras_->push_back( TrackExtra( trk.outerPosition(), trk.outerMomentum(), trk.outerOk(),
217  trk.innerPosition(), trk.innerMomentum(), trk.innerOk(),
218  trk.outerStateCovariance(), trk.outerDetId(),
219  trk.innerStateCovariance(), trk.innerDetId(),
220  trk.seedDirection(), trk.seedRef() ) );
221  selTracks_->back().setExtra( TrackExtraRef( rTrackExtras_, selTrackExtras_->size() - 1) );
222  TrackExtra & tx = selTrackExtras_->back();
223  tx.setResiduals(trk.residuals());
224  // TrackingRecHits
225  for( trackingRecHit_iterator hit = trk.recHitsBegin(); hit != trk.recHitsEnd(); ++ hit ) {
226  selHits_->push_back( (*hit)->clone() );
227  tx.add( TrackingRecHitRef( rHits_, selHits_->size() - 1) );
228  }
229  }
230  if (copyTrajectories_) {
231  trackRefs_[current] = TrackRef(rTracks_, selTracks_->size() - 1);
232  }
233  }
234  if ( copyTrajectories_ ) {
237  evt.getByLabel(src_, hTTAss);
238  evt.getByLabel(src_, hTraj);
239  selTrajs_ = auto_ptr< vector<Trajectory> >(new vector<Trajectory>());
240  rTrajectories_ = evt.getRefBeforePut< vector<Trajectory> >();
241  selTTAss_ = auto_ptr< TrajTrackAssociationCollection >(new TrajTrackAssociationCollection());
242  for (size_t i = 0, n = hTraj->size(); i < n; ++i) {
243  Ref< vector<Trajectory> > trajRef(hTraj, i);
245  if (match != hTTAss->end()) {
246  const Ref<TrackCollection> &trkRef = match->val;
247  short oldKey = static_cast<short>(trkRef.key());
248  if (trackRefs_[oldKey].isNonnull()) {
249  selTrajs_->push_back( Trajectory(*trajRef) );
250  selTTAss_->insert ( Ref< vector<Trajectory> >(rTrajectories_, selTrajs_->size() - 1), trackRefs_[oldKey] );
251  }
252  }
253  }
254  }
255 
256  static const std::string emptyString;
257  evt.put(selTracks_);
258  if (copyExtras_ ) {
259  evt.put(selTrackExtras_);
260  evt.put(selHits_);
261  }
262  if ( copyTrajectories_ ) {
263  evt.put(selTrajs_);
264  evt.put(selTTAss_);
265  }
266 }
#define LogDebug(id)
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
std::vector< double > max_d0_
Impact parameter absolute cuts.
int i
Definition: DBlmapReader.cc:9
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:187
std::vector< std::vector< double > > dz_par1_
std::auto_ptr< reco::TrackExtraCollection > selTrackExtras_
std::vector< std::vector< double > > d0_par1_
std::vector< std::vector< double > > d0_par2_
void produce(edm::Event &evt, const edm::EventSetup &es) override
process one event
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:10
bool exists(std::string const &parameterName) const
checks if a parameter exists
std::auto_ptr< std::vector< Trajectory > > selTrajs_
bool innerOk() const
return true if the innermost hit is valid
Definition: Track.h:40
std::vector< uint32_t > min_3Dlayers_
edm::Ref< TrackExtraCollection > TrackExtraRef
persistent reference to a TrackExtra
Definition: TrackExtraFwd.h:13
std::vector< int32_t > vtxNumber_
vertex cuts
const math::XYZPoint & outerPosition() const
position of the outermost hit
Definition: Track.h:47
bool copyExtras_
copy only the tracks, not extras and rechits (for AOD)
edm::RefProd< std::vector< Trajectory > > rTrajectories_
const math::XYZPoint & innerPosition() const
position of the innermost hit
Definition: Track.h:42
std::auto_ptr< TrajTrackAssociationCollection > selTTAss_
std::vector< std::vector< double > > res_par_
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:94
edm::Ref< TrackingRecHitCollection > TrackingRecHitRef
persistent reference to a TrackingRecHit
void processMVA(edm::Event &evt, const edm::EventSetup &es)
CovarianceMatrix outerStateCovariance() const
outermost trajectory state curvilinear errors
Definition: Track.h:51
double pt() const
track transverse momentum
Definition: TrackBase.h:131
std::vector< uint32_t > min_nhits_
unsigned int outerDetId() const
DetId of the detector on which surface the outermost state is located.
Definition: Track.h:59
std::vector< reco::TrackRef > trackRefs_
std::vector< unsigned int > preFilter_
trackingRecHit_iterator recHitsBegin() const
Iterator to first hit on the track.
Definition: Track.h:63
edm::AssociationMap< edm::OneToOne< std::vector< Trajectory >, reco::TrackCollection, unsigned short > > TrajTrackAssociationCollection
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:361
#define LogTrace(id)
std::vector< uint32_t > min_hits_bypass_
RefProd< PROD > getRefBeforePut()
Definition: Event.h:106
void selectVertices(unsigned int tsNum, const reco::VertexCollection &vtxs, std::vector< Point > &points, std::vector< float > &vterr, std::vector< float > &vzerr)
edm::InputTag src_
source collection label
std::vector< TrackExtra > TrackExtraCollection
collection of TrackExtra objects
Definition: TrackExtraFwd.h:9
edm::OwnVector< TrackingRecHit > TrackingRecHitCollection
collection of TrackingRecHits
edm::RefToBase< TrajectorySeed > seedRef() const
Definition: Track.h:112
static TrackQuality qualityByName(const std::string &name)
Definition: TrackBase.cc:46
std::vector< double > chi2n_no1Dmod_par_
const math::XYZVector & outerMomentum() const
momentum vector at the outermost hit position
Definition: Track.h:49
std::vector< StringCutObjectSelector< reco::Vertex > > vertexCut_
bool outerOk() const
return true if the outermost hit is valid
Definition: Track.h:38
edm::Ref< TrackCollection > TrackRef
persistent reference to a Track
Definition: TrackFwd.h:14
CovarianceMatrix innerStateCovariance() const
innermost trajectory state curvilinear errors
Definition: Track.h:53
key_type key() const
Accessor for product key.
Definition: Ref.h:266
bool select(unsigned tsNum, const reco::BeamSpot &vertexBeamSpot, const reco::Track &tk, const std::vector< Point > &points, std::vector< float > &vterr, std::vector< float > &vzerr, double mvaVal)
return class, or -1 if rejected
std::vector< TrackBase::TrackQuality > qualityToSet_
void add(const TrackingRecHitRef &r)
add a reference to a RecHit
std::vector< bool > setQualityBit_
do I have to set a quality bit?
std::vector< uint32_t > min_layers_
Cuts on numbers of layers with hits/3D hits/lost hits.
static std::string const emptyString("")
std::auto_ptr< reco::TrackCollection > selTracks_
storage
const math::XYZVector & innerMomentum() const
momentum vector at the innermost hit position
Definition: Track.h:45
const TrackResiduals & residuals() const
Definition: Track.h:117
PropagationDirection seedDirection() const
direction of how the hits were sorted in the original seed
Definition: Track.h:105
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:6
std::vector< uint32_t > max_lostLayers_
std::vector< std::vector< double > > dz_par2_
std::auto_ptr< TrackingRecHitCollection > selHits_
unsigned int innerDetId() const
DetId of the detector on which surface the innermost state is located.
Definition: Track.h:61
std::vector< int32_t > max_minMissHitOutOrIn_
tuple size
Write out results.
std::vector< int32_t > max_lostHitFraction_
bool copyTrajectories_
copy also trajectories and trajectory-&gt;track associations
trackingRecHit_iterator recHitsEnd() const
Iterator to last hit on the track.
Definition: Track.h:65
void setResiduals(const TrackResiduals &r)
set the residuals
Definition: TrackExtra.h:131