Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:31:40

0001 #ifndef CompositeLogicalTrajectoryFilter_H
0002 #define CompositeLogicalTrajectoryFilter_H
0003 
0004 #include "TrackingTools/TrajectoryFiltering/interface/TrajectoryFilter.h"
0005 #include "TrackingTools/TrajectoryFiltering/interface/TrajectoryFilterFactory.h"
0006 #include "TrackingTools/PatternTools/interface/Trajectory.h"
0007 #include "TrackingTools/PatternTools/interface/TempTrajectory.h"
0008 
0009 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0010 
0011 class CompositeLogicalTrajectoryFilter : public TrajectoryFilter {
0012 public:
0013   enum logic { OR, AND };
0014   explicit CompositeLogicalTrajectoryFilter() { filters.clear(); }
0015 
0016   explicit CompositeLogicalTrajectoryFilter(const edm::ParameterSet& pset, edm::ConsumesCollector& iC) {
0017     //look for VPSet of filters
0018     std::vector<edm::ParameterSet> vpset = pset.getParameter<std::vector<edm::ParameterSet> >("filters");
0019     for (unsigned int i = 0; i != vpset.size(); i++) {
0020       std::string ls = vpset[i].getParameter<std::string>("logic");
0021       logic l = OR;
0022       if (ls == "OR")
0023         l = OR;
0024       else if (ls == "AND")
0025         l = AND;
0026       else {
0027         edm::LogError("CompositeLogicalTrajectoryFilter") << "I don't understand the logic: " << ls;
0028       }
0029       filters.emplace_back(
0030           l, TrajectoryFilterFactory::get()->create(vpset[i].getParameter<std::string>("ComponentName"), vpset[i], iC));
0031     }
0032   }
0033 
0034   ~CompositeLogicalTrajectoryFilter() override {}
0035 
0036   void setEvent(const edm::Event& iEvent, const edm::EventSetup& iSetup) override {
0037     for (auto& item : filters) {
0038       item.second->setEvent(iEvent, iSetup);
0039     }
0040   }
0041 
0042   bool qualityFilter(const Trajectory& traj) const override { return QF<Trajectory>(traj); }
0043   bool qualityFilter(const TempTrajectory& traj) const override { return QF<TempTrajectory>(traj); }
0044 
0045   bool toBeContinued(Trajectory& traj) const override { return TBC<Trajectory>(traj); }
0046   bool toBeContinued(TempTrajectory& traj) const override { return TBC<TempTrajectory>(traj); }
0047 
0048   std::string name() const override { return "CompositeLogicalTrajectoryFilter"; }
0049 
0050 protected:
0051   template <class T>
0052   bool TBC(T& traj) const {
0053     unsigned int i = 0;
0054     unsigned int n = filters.size();
0055     for (; i < n; i++) {
0056       if (!filters[i].second->toBeContinued(traj))
0057         return false;
0058     }
0059     return true;
0060   }
0061 
0062   template <class T>
0063   bool QF(const T& traj) const {
0064     bool condition = true;
0065 
0066     unsigned int n = filters.size();
0067     if (n == 0) {
0068       edm::LogError("CompositeLogicalTrajectoryFilter") << n << " filters !.";
0069       return false;
0070     }
0071     condition = filters[0].second->qualityFilter(traj);
0072 
0073     unsigned int i = 1;
0074     for (; i < n; i++) {
0075       bool lcondition = filters[i].second->qualityFilter(traj);
0076       if (filters[i].first == OR)
0077         condition = condition || lcondition;
0078       else if (filters[i].first == AND)
0079         condition = condition && lcondition;
0080     }
0081     return condition;
0082   }
0083 
0084 protected:
0085   std::vector<std::pair<logic, std::unique_ptr<TrajectoryFilter> > > filters;
0086 };
0087 
0088 #endif