Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-07-13 03:16:10

0001 #ifndef RecoAlgos_MultiTrackSelector_h
0002 #define RecoAlgos_MultiTrackSelector_h
0003 /** \class MultiTrackSelector
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 #include "CondFormats/DataRecord/interface/GBRWrapperRcd.h"
0035 
0036 class dso_hidden MultiTrackSelector : public edm::stream::EDProducer<> {
0037 private:
0038 public:
0039   /// constructor
0040   explicit MultiTrackSelector();
0041   explicit MultiTrackSelector(const edm::ParameterSet &cfg);
0042   /// destructor
0043   ~MultiTrackSelector() override;
0044 
0045   using MVACollection = std::vector<float>;
0046   using QualityMaskCollection = std::vector<unsigned char>;
0047 
0048 protected:
0049   void beginStream(edm::StreamID) final;
0050 
0051   // void streamBeginRun(edm::StreamID, edm::Run const&, edm::EventSetup const&) const final {
0052   //  init();
0053   //}
0054   //void beginRun(edm::Run const&, edm::EventSetup const&) final { init(); }
0055   // void init(edm::EventSetup const& es) const;
0056 
0057   typedef math::XYZPoint Point;
0058   /// process one event
0059   void produce(edm::Event &evt, const edm::EventSetup &es) final { run(evt, es); }
0060   virtual void run(edm::Event &evt, const edm::EventSetup &es) const;
0061 
0062   /// return class, or -1 if rejected
0063   bool select(unsigned tsNum,
0064               const reco::BeamSpot &vertexBeamSpot,
0065               const TrackingRecHitCollection &recHits,
0066               const reco::Track &tk,
0067               const std::vector<Point> &points,
0068               std::vector<float> &vterr,
0069               std::vector<float> &vzerr,
0070               double mvaVal) const;
0071   void selectVertices(unsigned int tsNum,
0072                       const reco::VertexCollection &vtxs,
0073                       std::vector<Point> &points,
0074                       std::vector<float> &vterr,
0075                       std::vector<float> &vzerr) const;
0076 
0077   void processMVA(edm::Event &evt,
0078                   const edm::EventSetup &es,
0079                   const reco::BeamSpot &beamspot,
0080                   const reco::VertexCollection &vertices,
0081                   int selIndex,
0082                   std::vector<float> &mvaVals_,
0083                   bool writeIt = false) const;
0084   Point getBestVertex(const reco::TrackBaseRef, const reco::VertexCollection) const;
0085 
0086   /// source collection label
0087   edm::EDGetTokenT<reco::TrackCollection> src_;
0088   edm::EDGetTokenT<TrackingRecHitCollection> hSrc_;
0089   edm::EDGetTokenT<reco::BeamSpot> beamspot_;
0090   bool useVertices_;
0091   bool useVtxError_;
0092   bool useAnyMVA_;
0093   edm::EDGetTokenT<reco::VertexCollection> vertices_;
0094 
0095   /// do I have to set a quality bit?
0096   std::vector<bool> setQualityBit_;
0097   std::vector<reco::TrackBase::TrackQuality> qualityToSet_;
0098 
0099   /// vertex cuts
0100   std::vector<int32_t> vtxNumber_;
0101   //StringCutObjectSelector is not const thread safe
0102   std::vector<StringCutObjectSelector<reco::Vertex>> vertexCut_;
0103 
0104   //  parameters for adapted optimal cuts on chi2 and primary vertex compatibility
0105   std::vector<std::vector<double>> res_par_;
0106   std::vector<double> chi2n_par_;
0107   std::vector<double> chi2n_no1Dmod_par_;
0108   std::vector<std::vector<double>> d0_par1_;
0109   std::vector<std::vector<double>> dz_par1_;
0110   std::vector<std::vector<double>> d0_par2_;
0111   std::vector<std::vector<double>> dz_par2_;
0112   // Boolean indicating if adapted primary vertex compatibility cuts are to be applied.
0113   std::vector<bool> applyAdaptedPVCuts_;
0114 
0115   /// Impact parameter absolute cuts
0116   std::vector<double> max_d0_;
0117   std::vector<double> max_z0_;
0118   std::vector<double> nSigmaZ_;
0119 
0120   /// Cuts on numbers of layers with hits/3D hits/lost hits.
0121   std::vector<uint32_t> min_layers_;
0122   std::vector<uint32_t> min_3Dlayers_;
0123   std::vector<uint32_t> max_lostLayers_;
0124   std::vector<uint32_t> min_hits_bypass_;
0125 
0126   // pterror and nvalid hits cuts
0127   std::vector<double> max_relpterr_;
0128   std::vector<uint32_t> min_nhits_;
0129 
0130   std::vector<int32_t> max_minMissHitOutOrIn_;
0131   std::vector<int32_t> max_lostHitFraction_;
0132 
0133   std::vector<double> min_eta_;
0134   std::vector<double> max_eta_;
0135 
0136   // Flag and absolute cuts if no PV passes the selection
0137   std::vector<double> max_d0NoPV_;
0138   std::vector<double> max_z0NoPV_;
0139   std::vector<bool> applyAbsCutsIfNoPV_;
0140   //if true, selector flags but does not select
0141   std::vector<bool> keepAllTracks_;
0142 
0143   // allow one of the previous psets to be used as a prefilter
0144   std::vector<unsigned int> preFilter_;
0145   std::vector<std::string> name_;
0146 
0147   //setup mva selector
0148   std::vector<bool> useMVA_;
0149   std::vector<bool> useMVAonly_;
0150 
0151   std::vector<double> min_MVA_;
0152 
0153   std::vector<std::string> mvaType_;
0154   std::vector<std::string> forestLabel_;
0155   std::vector<edm::ESGetToken<GBRForest, GBRWrapperRcd>> forestToken_;
0156   std::vector<GBRForest *> forest_;
0157   bool useForestFromDB_;
0158   std::string dbFileName_;
0159 };
0160 
0161 #endif