Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-10-20 10:42:30

0001 #include "FWCore/Framework/interface/ESHandle.h"
0002 #include "FWCore/Framework/interface/ESProducer.h"
0003 #include "FWCore/Framework/interface/EventSetup.h"
0004 #include "FWCore/Framework/interface/ModuleFactory.h"
0005 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0006 #include "TrackingTools/GsfTools/interface/DistanceBetweenComponents.h"
0007 #include "TrackingTools/GsfTools/interface/KullbackLeiblerDistance.h"
0008 #include "TrackingTools/Records/interface/TrackingComponentsRecord.h"
0009 
0010 #include <memory>
0011 #include <string>
0012 
0013 /** Provides algorithms to measure the distance between  components
0014  * (currently either using a Kullback-Leibler or a Mahalanobis distance)
0015  */
0016 
0017 template <unsigned int N>
0018 class DistanceBetweenComponentsESProducer : public edm::ESProducer {
0019 public:
0020   DistanceBetweenComponentsESProducer(const edm::ParameterSet& p);
0021 
0022   std::unique_ptr<DistanceBetweenComponents<N> > produce(const TrackingComponentsRecord&);
0023 
0024   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0025 
0026 private:
0027   const bool useKullbackLeibler_;
0028 };
0029 
0030 #include "FWCore/Framework/interface/ModuleFactory.h"
0031 typedef DistanceBetweenComponentsESProducer<5> DistanceBetweenComponentsESProducer5D;
0032 DEFINE_FWK_EVENTSETUP_MODULE(DistanceBetweenComponentsESProducer5D);
0033 
0034 template <unsigned int N>
0035 DistanceBetweenComponentsESProducer<N>::DistanceBetweenComponentsESProducer(const edm::ParameterSet& p)
0036     : useKullbackLeibler_(p.getParameter<std::string>("DistanceMeasure") == "KullbackLeibler") {
0037   std::string myname = p.getParameter<std::string>("ComponentName");
0038   setWhatProduced(this, myname);
0039 }
0040 
0041 template <unsigned int N>
0042 typename std::unique_ptr<DistanceBetweenComponents<N> > DistanceBetweenComponentsESProducer<N>::produce(
0043     const TrackingComponentsRecord& iRecord) {
0044   std::unique_ptr<DistanceBetweenComponents<N> > distance;
0045   if (useKullbackLeibler_)
0046     distance = std::unique_ptr<DistanceBetweenComponents<N> >(new KullbackLeiblerDistance<N>());
0047   // //   else if ( distName == "Mahalanobis" )
0048   // //     distance = std::unique_ptr<DistanceBetweenComponents>(new MahalanobisDistance());
0049 
0050   return distance;
0051 }
0052 
0053 template <unsigned int N>
0054 void DistanceBetweenComponentsESProducer<N>::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0055   edm::ParameterSetDescription desc;
0056   desc.add<std::string>("DistanceMeasure");
0057   desc.add<std::string>("ComponentName");
0058 
0059   descriptions.addDefault(desc);
0060 }