CMS 3D CMS Logo

TrackMVAClassifierBase.cc
Go to the documentation of this file.
2 
7 
10 
11 #include<cassert>
12 
13 
15  desc.add<edm::InputTag>("src",edm::InputTag());
16  desc.add<edm::InputTag>("beamspot",edm::InputTag("offlineBeamSpot"));
17  desc.add<edm::InputTag>("vertices",edm::InputTag("firstStepPrimaryVertices"));
18  desc.add<bool>("ignoreVertices",false);
19  desc.add<std::string>("GBRForestLabel",std::string());
20  desc.add<std::string>("GBRForestFileName",std::string());
21  // default cuts for "cut based classification"
22  std::vector<double> cuts = {-.7, 0.1, .7};
23  desc.add<std::vector<double>>("qualityCuts", cuts);
24 }
25 
26 
28 
30  src_ ( consumes<reco::TrackCollection> (cfg.getParameter<edm::InputTag>( "src" )) ),
31  beamspot_( consumes<reco::BeamSpot> (cfg.getParameter<edm::InputTag>( "beamspot" )) ),
32  vertices_( mayConsume<reco::VertexCollection>(cfg.getParameter<edm::InputTag>( "vertices" )) ),
33  ignoreVertices_( cfg.getParameter<bool>( "ignoreVertices" ) ),
34  forestLabel_ ( cfg.getParameter<std::string>("GBRForestLabel") ),
35  dbFileName_ ( cfg.getParameter<std::string>("GBRForestFileName") ),
37 
38  auto const & qv = cfg.getParameter<std::vector<double>>("qualityCuts");
39  assert(qv.size()==3);
41 
42  produces<MVACollection>("MVAValues");
43  produces<QualityMaskCollection>("QualityMasks");
44 
45 }
46 
48 
49  // Get tracks
51  evt.getByToken(src_, hSrcTrack );
52  auto const & tracks(*hSrcTrack);
53 
54  // looking for the beam spot
56  evt.getByToken(beamspot_, hBsp);
57 
58  // Select good primary vertices for use in subsequent track selection
60  evt.getByToken(vertices_, hVtx);
61 
62  GBRForest const * forest = forest_.get();
63  if(useForestFromDB_){
64  edm::ESHandle<GBRForest> forestHandle;
65  es.get<GBRWrapperRcd>().get(forestLabel_,forestHandle);
66  forest = forestHandle.product();
67  }
68 
69  // products
70  auto mvas = std::make_unique<MVACollection>(tracks.size(),-99.f);
71  auto quals = std::make_unique<QualityMaskCollection>(tracks.size(),0);
72 
73  if ( hVtx.isValid() && !ignoreVertices_ ) {
74  computeMVA(tracks,*hBsp,*hVtx,forest,*mvas);
75  } else {
76  if ( !ignoreVertices_ )
77  edm::LogWarning("TrackMVAClassifierBase") << "ignoreVertices is set to False in the configuration, but the vertex collection is not valid";
78  std::vector<reco::Vertex> vertices;
79  computeMVA(tracks,*hBsp,vertices,forest,*mvas);
80  }
81  assert((*mvas).size()==tracks.size());
82 
83  unsigned int k=0;
84  for (auto mva : *mvas) {
85  (*quals)[k++]
89  ;
90 
91  }
92 
93 
94  evt.put(std::move(mvas),"MVAValues");
95  evt.put(std::move(quals),"QualityMasks");
96 
97 }
98 
99 
100 #include <TFile.h>
102  if(!dbFileName_.empty()){
103  TFile gbrfile(dbFileName_.c_str());
104  forest_.reset((GBRForest*)gbrfile.Get(forestLabel_.c_str()));
105  }
106 }
107 
T getParameter(std::string const &) const
void beginStream(edm::StreamID) override final
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:122
TrackMVAClassifierBase(const edm::ParameterSet &cfg)
void produce(edm::Event &evt, const edm::EventSetup &es) override final
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:460
edm::EDGetTokenT< reco::TrackCollection > src_
source collection label
const std::string forestLabel_
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
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
virtual void computeMVA(reco::TrackCollection const &tracks, reco::BeamSpot const &beamSpot, reco::VertexCollection const &vertices, GBRForest const *forestP, MVACollection &mvas) const =0
edm::EDGetTokenT< reco::BeamSpot > beamspot_
edm::EDGetTokenT< reco::VertexCollection > vertices_
#define end
Definition: vmac.h:37
std::unique_ptr< GBRForest > forest_
ParameterDescriptionBase * add(U const &iLabel, T const &value)
bool isValid() const
Definition: HandleBase.h:74
int k[5][pyjets_maxn]
const T & get() const
Definition: EventSetup.h:55
fixed size matrix
#define begin
Definition: vmac.h:30
HLT enums.
EDGetTokenT< ProductType > mayConsume(edm::InputTag const &tag)
T const * product() const
Definition: ESHandle.h:86
def move(src, dest)
Definition: eostools.py:510