CMS 3D CMS Logo

TrackMVAClassifierBase.cc
Go to the documentation of this file.
2 
4 
7 
8 #include<cassert>
9 
10 
12  desc.add<edm::InputTag>("src",edm::InputTag());
13  desc.add<edm::InputTag>("beamspot",edm::InputTag("offlineBeamSpot"));
14  desc.add<edm::InputTag>("vertices",edm::InputTag("firstStepPrimaryVertices"));
15  desc.add<bool>("ignoreVertices",false);
16  // default cuts for "cut based classification"
17  std::vector<double> cuts = {-.7, 0.1, .7};
18  desc.add<std::vector<double>>("qualityCuts", cuts);
19 }
20 
21 
23 
25  src_ ( consumes<reco::TrackCollection> (cfg.getParameter<edm::InputTag>( "src" )) ),
26  beamspot_( consumes<reco::BeamSpot> (cfg.getParameter<edm::InputTag>( "beamspot" )) ),
27  vertices_( mayConsume<reco::VertexCollection>(cfg.getParameter<edm::InputTag>( "vertices" )) ),
28  ignoreVertices_( cfg.getParameter<bool>( "ignoreVertices" ) ) {
29 
30  auto const & qv = cfg.getParameter<std::vector<double>>("qualityCuts");
31  assert(qv.size()==3);
33 
34  produces<MVACollection>("MVAValues");
35  produces<QualityMaskCollection>("QualityMasks");
36 
37 }
38 
40 
41  // Get tracks
43  evt.getByToken(src_, hSrcTrack );
44  auto const & tracks(*hSrcTrack);
45 
46  // looking for the beam spot
48  evt.getByToken(beamspot_, hBsp);
49 
50  // Select good primary vertices for use in subsequent track selection
52  evt.getByToken(vertices_, hVtx);
53 
54  initEvent(es);
55 
56  // products
57  auto mvaPairs = std::make_unique<MVAPairCollection>(tracks.size(),std::make_pair(-99.f,true));
58  auto mvas = std::make_unique<MVACollection>(tracks.size(),-99.f);
59  auto quals = std::make_unique<QualityMaskCollection>(tracks.size(),0);
60 
61  if ( hVtx.isValid() && !ignoreVertices_ ) {
62  computeMVA(tracks,*hBsp,*hVtx,*mvaPairs);
63  } else {
64  if ( !ignoreVertices_ )
65  edm::LogWarning("TrackMVAClassifierBase") << "ignoreVertices is set to False in the configuration, but the vertex collection is not valid";
66  std::vector<reco::Vertex> vertices;
67  computeMVA(tracks,*hBsp,vertices,*mvaPairs);
68  }
69  assert((*mvaPairs).size()==tracks.size());
70 
71  unsigned int k=0;
72  for (auto const& output : *mvaPairs) {
73  if(output.second){
74  (*mvas)[k] = output.first;
75  }else{
76  // If the MVA value is known to be unreliable, force into generalTracks collection
77  (*mvas)[k] = std::max(output.first, float(qualityCuts[0]+0.001));
78  }
79  float mva = (*mvas)[k];
80  (*quals)[k++]
84  ;
85  }
86 
87 
88  evt.put(std::move(mvas),"MVAValues");
89  evt.put(std::move(quals),"QualityMasks");
90 
91 }
T getParameter(std::string const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
TrackMVAClassifierBase(const edm::ParameterSet &cfg)
virtual void initEvent(const edm::EventSetup &es)=0
def copy(args, dbName)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
edm::EDGetTokenT< reco::TrackCollection > src_
source collection label
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:15
static void fill(edm::ParameterSetDescription &desc)
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
edm::EDGetTokenT< reco::BeamSpot > beamspot_
void produce(edm::Event &evt, const edm::EventSetup &es) final
double f[11][100]
edm::EDGetTokenT< reco::VertexCollection > vertices_
#define end
Definition: vmac.h:39
ParameterDescriptionBase * add(U const &iLabel, T const &value)
bool isValid() const
Definition: HandleBase.h:74
int k[5][pyjets_maxn]
fixed size matrix
#define begin
Definition: vmac.h:32
HLT enums.
virtual void computeMVA(reco::TrackCollection const &tracks, reco::BeamSpot const &beamSpot, reco::VertexCollection const &vertices, MVAPairCollection &mvas) const =0
def move(src, dest)
Definition: eostools.py:511