Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-01-10 06:14:22

0001 #ifndef CompositeTrajectoryFilter_H
0002 #define CompositeTrajectoryFilter_H
0003 
0004 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0005 #include "FWCore/ParameterSet/interface/PluginDescription.h"
0006 #include "TrackingTools/TrajectoryFiltering/interface/TrajectoryFilter.h"
0007 #include "TrackingTools/TrajectoryFiltering/interface/TrajectoryFilterFactory.h"
0008 #include "TrackingTools/PatternTools/interface/Trajectory.h"
0009 #include "TrackingTools/PatternTools/interface/TempTrajectory.h"
0010 
0011 /** A TrajectoryFilter that stops reconstruction if P_t drops
0012  *  below some value at some confidence level.
0013  *  The CkfTrajectoryBuilder uses this class to
0014  *  implement the minimal P_t cut.
0015  */
0016 
0017 class CompositeTrajectoryFilter : public TrajectoryFilter {
0018 public:
0019   explicit CompositeTrajectoryFilter() { filters.clear(); }
0020   explicit CompositeTrajectoryFilter(const edm::ParameterSet& pset, edm::ConsumesCollector& iC) {
0021     //look for VPSet of filters
0022     std::vector<edm::ParameterSet> vpset = pset.getParameter<std::vector<edm::ParameterSet> >("filters");
0023     for (unsigned int i = 0; i != vpset.size(); i++) {
0024       filters.emplace_back(
0025           TrajectoryFilterFactory::get()->create(vpset[i].getParameter<std::string>("ComponentType"), vpset[i], iC));
0026     }
0027   }
0028 
0029   ~CompositeTrajectoryFilter() override {}
0030 
0031   static void fillPSetDescription(edm::ParameterSetDescription& iDesc) {
0032     edm::ParameterSetDescription psdTF;
0033     psdTF.addNode(edm::PluginDescription<TrajectoryFilterFactory>("ComponentType", true));
0034     std::vector<edm::ParameterSet> vPSetFilters;
0035     iDesc.addVPSet("filters", psdTF, vPSetFilters);
0036   }
0037 
0038   void setEvent(const edm::Event& iEvent, const edm::EventSetup& iSetup) override {
0039     for (auto& f : filters) {
0040       f->setEvent(iEvent, iSetup);
0041     }
0042   }
0043 
0044   bool qualityFilter(const Trajectory& traj) const override { return QF<Trajectory>(traj); }
0045   bool qualityFilter(const TempTrajectory& traj) const override { return QF<TempTrajectory>(traj); }
0046 
0047   bool toBeContinued(Trajectory& traj) const override { return TBC<Trajectory>(traj); }
0048   bool toBeContinued(TempTrajectory& traj) const override { return TBC<TempTrajectory>(traj); }
0049 
0050   std::string name() const override {
0051     std::string rname = "CompositeTrajectoryFilter";
0052     unsigned int i = 0;
0053     unsigned int n = filters.size();
0054     for (; i < n; i++) {
0055       rname += "_" + filters[i]->name();
0056     }
0057     return rname;
0058   }
0059 
0060 protected:
0061   template <class T>
0062   bool TBC(T& traj) const {
0063     unsigned int i = 0;
0064     unsigned int n = filters.size();
0065     for (; i < n; i++) {
0066       if (!filters[i]->toBeContinued(traj))
0067         return false;
0068     }
0069     return true;
0070   }
0071 
0072   template <class T>
0073   bool QF(const T& traj) const {
0074     unsigned int i = 0;
0075     unsigned int n = filters.size();
0076     for (; i < n; i++) {
0077       if (!filters[i]->qualityFilter(traj))
0078         return false;
0079     }
0080     return true;
0081   }
0082 
0083 protected:
0084   std::vector<std::unique_ptr<TrajectoryFilter> > filters;
0085 };
0086 
0087 #endif