test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TrackMVAClassifierBase.cc
Go to the documentation of this file.
2 
6 
8 
9 
10 #include<cassert>
11 
12 
14  desc.add<edm::InputTag>("src",edm::InputTag());
15  desc.add<edm::InputTag>("beamspot",edm::InputTag("offlineBeamSpot"));
16  desc.add<edm::InputTag>("vertices",edm::InputTag("firstStepPrimaryVertices"));
17  desc.add<std::string>("GBRForestLabel",std::string());
18  desc.add<std::string>("GBRForestFileName",std::string());
19  // default cuts for "cut based classification"
20  std::vector<double> cuts = {-.7, 0.1, .7};
21  desc.add<std::vector<double>>("qualityCuts", cuts);
22 }
23 
24 
26 
28  src_( consumes<reco::TrackCollection>( cfg.getParameter<edm::InputTag>( "src" ) ) ),
29  beamspot_( consumes<reco::BeamSpot>( cfg.getParameter<edm::InputTag>( "beamspot" ) ) ),
30  vertices_(consumes<reco::VertexCollection>(cfg.getParameter<edm::InputTag>( "vertices" ))),
31  forestLabel_(cfg.getParameter<std::string>("GBRForestLabel")),
32  dbFileName_(cfg.getParameter<std::string>("GBRForestFileName")),
33  useForestFromDB_( (!forestLabel_.empty()) & dbFileName_.empty()) {
34 
35  auto const & qv = cfg.getParameter<std::vector<double>>("qualityCuts");
36  assert(qv.size()==3);
38 
39  produces<MVACollection>("MVAValues");
40  produces<QualityMaskCollection>("QualityMasks");
41 
42 }
43 
45 
46  // Get tracks
48  evt.getByToken(src_, hSrcTrack );
49  auto const & tracks(*hSrcTrack);
50 
51  // looking for the beam spot
53  evt.getByToken(beamspot_, hBsp);
54 
55 
56  // Select good primary vertices for use in subsequent track selection
58  evt.getByToken(vertices_, hVtx);
59 
60  GBRForest const * forest = forest_.get();
61  if(useForestFromDB_){
62  edm::ESHandle<GBRForest> forestHandle;
63  es.get<GBRWrapperRcd>().get(forestLabel_,forestHandle);
64  forest = forestHandle.product();
65  }
66 
67  // products
68  auto mvas = std::make_unique<MVACollection>(tracks.size(),-99.f);
69  auto quals = std::make_unique<QualityMaskCollection>(tracks.size(),0);
70 
71 
72 
73  computeMVA(tracks,*hBsp,*hVtx,forest,*mvas);
74  assert((*mvas).size()==tracks.size());
75 
76  unsigned int k=0;
77  for (auto mva : *mvas) {
78  (*quals)[k++]
82  ;
83 
84  }
85 
86 
87  evt.put(std::move(mvas),"MVAValues");
88  evt.put(std::move(quals),"QualityMasks");
89 
90 }
91 
92 
93 #include <TFile.h>
95  if(!dbFileName_.empty()){
96  TFile gbrfile(dbFileName_.c_str());
97  forest_.reset((GBRForest*)gbrfile.Get(forestLabel_.c_str()));
98  }
99 }
100 
T getParameter(std::string const &) const
TrackMVAClassifierBase(const edm::ParameterSet &cfg)
tuple cfg
Definition: looper.py:293
virtual void computeMVA(reco::TrackCollection const &tracks, reco::BeamSpot const &beamSpot, reco::VertexCollection const &vertices, GBRForest const *forestP, MVACollection &mvas) const =0
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:462
edm::EDGetTokenT< reco::TrackCollection > src_
source collection label
const std::string forestLabel_
assert(m_qm.get())
const std::string dbFileName_
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
static void fill(edm::ParameterSetDescription &desc)
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
void produce(edm::Event &evt, const edm::EventSetup &es) overridefinal
void beginStream(edm::StreamID) overridefinal
edm::EDGetTokenT< reco::BeamSpot > beamspot_
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:121
def move
Definition: eostools.py:510
edm::EDGetTokenT< reco::VertexCollection > vertices_
#define end
Definition: vmac.h:37
std::unique_ptr< GBRForest > forest_
ParameterDescriptionBase * add(U const &iLabel, T const &value)
tuple tracks
Definition: testEve_cfg.py:39
const T & get() const
Definition: EventSetup.h:56
T const * product() const
Definition: ESHandle.h:86
#define begin
Definition: vmac.h:30