Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:22:09

0001 /*
0002 Track Quality Header file
0003 C.Brown 28/07/20
0004 */
0005 
0006 #ifndef L1Trigger_TrackTrigger_interface_L1TrackQuality_h
0007 #define L1Trigger_TrackTrigger_interface_L1TrackQuality_h
0008 
0009 #include <iostream>
0010 #include <set>
0011 #include <vector>
0012 #include <memory>
0013 #include <string>
0014 
0015 #include "FWCore/Framework/interface/Event.h"
0016 #include "FWCore/Framework/interface/EventSetup.h"
0017 #include "FWCore/Framework/interface/Frameworkfwd.h"
0018 #include "FWCore/Framework/interface/MakerMacros.h"
0019 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0020 #include "DataFormats/L1TrackTrigger/interface/TTTrack.h"
0021 #include "DataFormats/L1TrackTrigger/interface/TTTrack_TrackWord.h"
0022 #include "DataFormats/L1TrackTrigger/interface/TTTypes.h"
0023 #include "PhysicsTools/ONNXRuntime/interface/ONNXRuntime.h"
0024 #include <memory>
0025 
0026 #include "conifer.h"
0027 #include "ap_fixed.h"
0028 
0029 class L1TrackQuality {
0030 public:
0031   // Enum class used for determining prediction behaviour in setL1TrackQuality
0032   enum class QualityAlgorithm { Cut, GBDT, GBDT_cpp, NN, None };
0033 
0034   //Default Constructor
0035   L1TrackQuality();
0036 
0037   L1TrackQuality(const edm::ParameterSet& qualityParams);
0038 
0039   //Default Destructor
0040   ~L1TrackQuality() = default;
0041 
0042   // Controls the conversion between TTTrack features and ML model training features
0043   std::vector<float> featureTransform(TTTrack<Ref_Phase2TrackerDigi_>& aTrack,
0044                                       std::vector<std::string> const& featureNames);
0045 
0046   // Passed by reference a track without MVA filled, method fills the track's MVA field
0047   void setL1TrackQuality(TTTrack<Ref_Phase2TrackerDigi_>& aTrack);
0048   // Function to run the BDT in isolation allowing a feature vector in the ap_fixed datatype to be passed
0049   // and a single output to be returned which is then used to fill the bits in the Track Word for situations
0050   // where a TTTrack datatype is unavailable to be passed to the track quality
0051   float runEmulatedTQ(std::vector<ap_fixed<10, 5>> inputFeatures);
0052   // To set private member data
0053   void setCutParameters(std::string const& AlgorithmString,
0054                         float maxZ0,
0055                         float maxEta,
0056                         float chi2dofMax,
0057                         float bendchi2Max,
0058                         float minPt,
0059                         int nStubmin);
0060 
0061   void setONNXModel(std::string const& AlgorithmString,
0062                     edm::FileInPath const& ONNXmodel,
0063                     std::string const& ONNXInputName,
0064                     std::vector<std::string> const& featureNames);
0065 
0066   void setBonusFeatures(std::vector<float> bonusFeatures);
0067 
0068 private:
0069   // Private Member Data
0070   QualityAlgorithm qualityAlgorithm_ = QualityAlgorithm::None;
0071   edm::FileInPath ONNXmodel_;
0072   std::string ONNXInputName_;
0073   std::vector<std::string> featureNames_;
0074   float maxZ0_;
0075   float maxEta_;
0076   float chi2dofMax_;
0077   float bendchi2Max_;
0078   float minPt_;
0079   int nStubsmin_;
0080   bool useHPH_;
0081   std::vector<float> bonusFeatures_;
0082   std::unique_ptr<cms::Ort::ONNXRuntime> runTime_;
0083 };
0084 #endif