Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-09-18 02:25:12

0001 #ifndef RecoAlgos_HIMultiTrackSelector_h
0002 #define RecoAlgos_HIMultiTrackSelector_h
0003 /** \class HIMultiTrackSelector
0004  *
0005  * selects a subset of a track collection, copying extra information on demand
0006  * 
0007  * \author David Lange
0008  *
0009  *
0010  *
0011  */
0012 
0013 #include <utility>
0014 #include <vector>
0015 #include <memory>
0016 #include <algorithm>
0017 #include <map>
0018 #include "FWCore/Framework/interface/stream/EDProducer.h"
0019 #include "FWCore/Framework/interface/Event.h"
0020 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0021 #include "FWCore/Utilities/interface/InputTag.h"
0022 
0023 #include "DataFormats/TrackReco/interface/TrackFwd.h"
0024 #include "DataFormats/TrackReco/interface/Track.h"
0025 #include "DataFormats/TrackReco/interface/TrackExtra.h"
0026 #include "DataFormats/VertexReco/interface/VertexFwd.h"
0027 #include "DataFormats/VertexReco/interface/Vertex.h"
0028 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
0029 #include "TrackingTools/PatternTools/interface/Trajectory.h"
0030 #include "TrackingTools/PatternTools/interface/TrajTrackAssociation.h"
0031 #include "DataFormats/TrackerRecHit2D/interface/SiStripRecHit1D.h"
0032 #include "CommonTools/Utils/interface/StringCutObjectSelector.h"
0033 #include "CondFormats/GBRForest/interface/GBRForest.h"
0034 
0035 enum MVAVARIABLES {
0036   chi2perdofperlayer = 0,
0037   dxyperdxyerror = 1,
0038   dzperdzerror = 2,
0039   relpterr = 3,
0040   lostmidfrac = 4,
0041   minlost = 5,
0042   nhits = 6,
0043   eta = 7,
0044   chi2n_no1dmod = 8,
0045   chi2n = 9,
0046   nlayerslost = 10,
0047   nlayers3d = 11,
0048   nlayers = 12,
0049   ndof = 13,
0050   etaerror = 14
0051 };
0052 
0053 class GBRWrapperRcd;
0054 
0055 class dso_hidden HIMultiTrackSelector : public edm::stream::EDProducer<> {
0056 private:
0057 public:
0058   /// constructor
0059   explicit HIMultiTrackSelector();
0060   explicit HIMultiTrackSelector(const edm::ParameterSet &cfg);
0061   /// destructor
0062   ~HIMultiTrackSelector() override;
0063 
0064 protected:
0065   void beginStream(edm::StreamID) final;
0066 
0067   // void streamBeginRun(edm::StreamID, edm::Run const&, edm::EventSetup const&) const final {
0068   //  init();
0069   //}
0070   //void beginRun(edm::Run const&, edm::EventSetup const&) final { init(); }
0071   // void init(edm::EventSetup const& es) const;
0072 
0073   typedef math::XYZPoint Point;
0074   /// process one event
0075   void produce(edm::Event &evt, const edm::EventSetup &es) final { run(evt, es); }
0076   virtual void run(edm::Event &evt, const edm::EventSetup &es) const;
0077 
0078   /// return class, or -1 if rejected
0079   bool select(unsigned tsNum,
0080               const reco::BeamSpot &vertexBeamSpot,
0081               const TrackingRecHitCollection &recHits,
0082               const reco::Track &tk,
0083               const std::vector<Point> &points,
0084               std::vector<float> &vterr,
0085               std::vector<float> &vzerr,
0086               double mvaVal) const;
0087   void selectVertices(unsigned int tsNum,
0088                       const reco::VertexCollection &vtxs,
0089                       std::vector<Point> &points,
0090                       std::vector<float> &vterr,
0091                       std::vector<float> &vzerr) const;
0092 
0093   void processMVA(edm::Event &evt,
0094                   const edm::EventSetup &es,
0095                   std::vector<float> &mvaVals_,
0096                   const reco::VertexCollection &hVtx) const;
0097 
0098   void ParseForestVars();
0099   /// source collection label
0100   edm::EDGetTokenT<reco::TrackCollection> src_;
0101   edm::EDGetTokenT<TrackingRecHitCollection> hSrc_;
0102   edm::EDGetTokenT<reco::BeamSpot> beamspot_;
0103   bool useVertices_;
0104   bool useVtxError_;
0105   bool useAnyMVA_;
0106   edm::EDGetTokenT<reco::VertexCollection> vertices_;
0107 
0108   // Boolean indicating if pixel track merging related cuts are to be applied
0109   bool applyPixelMergingCuts_;
0110 
0111   /// do I have to set a quality bit?
0112   std::vector<bool> setQualityBit_;
0113   std::vector<reco::TrackBase::TrackQuality> qualityToSet_;
0114 
0115   /// vertex cuts
0116   std::vector<int32_t> vtxNumber_;
0117   //StringCutObjectSelector is not const thread safe
0118   std::vector<StringCutObjectSelector<reco::Vertex> > vertexCut_;
0119 
0120   //  parameters for adapted optimal cuts on chi2 and primary vertex compatibility
0121   std::vector<std::vector<double> > res_par_;
0122   std::vector<double> chi2n_par_;
0123   std::vector<double> chi2n_no1Dmod_par_;
0124   std::vector<std::vector<double> > d0_par1_;
0125   std::vector<std::vector<double> > dz_par1_;
0126   std::vector<std::vector<double> > d0_par2_;
0127   std::vector<std::vector<double> > dz_par2_;
0128   // Boolean indicating if adapted primary vertex compatibility cuts are to be applied.
0129   std::vector<bool> applyAdaptedPVCuts_;
0130 
0131   /// Impact parameter absolute cuts
0132   std::vector<double> max_d0_;
0133   std::vector<double> max_z0_;
0134   std::vector<double> nSigmaZ_;
0135 
0136   // parameters for pixel track merging pT dependent chi2 cuts
0137   std::vector<std::vector<double> > pixel_pTMinCut_;
0138   std::vector<std::vector<double> > pixel_pTMaxCut_;
0139 
0140   /// Cuts on numbers of layers with hits/3D hits/lost hits.
0141   std::vector<uint32_t> min_layers_;
0142   std::vector<uint32_t> min_3Dlayers_;
0143   std::vector<uint32_t> max_lostLayers_;
0144   std::vector<uint32_t> min_hits_bypass_;
0145 
0146   // pterror and nvalid hits cuts
0147   std::vector<double> max_relpterr_;
0148   std::vector<uint32_t> min_nhits_;
0149 
0150   std::vector<int32_t> max_minMissHitOutOrIn_;
0151   std::vector<int32_t> max_lostHitFraction_;
0152 
0153   std::vector<double> min_eta_;
0154   std::vector<double> max_eta_;
0155 
0156   // Flag and absolute cuts if no PV passes the selection
0157   std::vector<double> max_d0NoPV_;
0158   std::vector<double> max_z0NoPV_;
0159   std::vector<bool> applyAbsCutsIfNoPV_;
0160   //if true, selector flags but does not select
0161   std::vector<bool> keepAllTracks_;
0162 
0163   // allow one of the previous psets to be used as a prefilter
0164   std::vector<unsigned int> preFilter_;
0165   std::vector<std::string> name_;
0166 
0167   //setup mva selector
0168   std::vector<bool> useMVA_;
0169   //std::vector<TMVA::Reader*> mvaReaders_;
0170 
0171   std::vector<int> mvavars_indices;
0172 
0173   std::vector<double> min_MVA_;
0174 
0175   //std::vector<std::string> mvaType_;
0176   std::string mvaType_;
0177   std::string forestLabel_;
0178   std::vector<std::string> forestVars_;
0179   GBRForest *forest_;
0180   edm::ESGetToken<GBRForest, GBRWrapperRcd> forestToken_;
0181   bool useForestFromDB_;
0182   std::string dbFileName_;
0183 };
0184 
0185 #endif