Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-03-12 05:47:40

0001 #ifndef MuonTrackValidator_h
0002 #define MuonTrackValidator_h
0003 
0004 /** \class MuonTrackValidator
0005 * Class that produces histograms to validate Muon Track Reconstruction performances
0006 *
0007 */
0008 #include "FWCore/Framework/interface/Frameworkfwd.h"
0009 #include "Validation/RecoMuon/plugins/MuonTrackValidatorBase.h"
0010 #include "SimDataFormats/Associations/interface/TrackToTrackingParticleAssociator.h"
0011 
0012 #include "DataFormats/TrackReco/interface/Track.h"
0013 #include "SimDataFormats/Associations/interface/TrackAssociation.h"
0014 #include "DQMServices/Core/interface/DQMEDAnalyzer.h"
0015 
0016 #include "SimTracker/TrackAssociation/interface/ParametersDefinerForTP.h"
0017 #include "SimTracker/TrackAssociation/interface/CosmicParametersDefinerForTP.h"
0018 
0019 #include "FWCore/Framework/interface/Event.h"
0020 #include "FWCore/Framework/interface/ESHandle.h"
0021 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0022 #include "FWCore/Framework/interface/ConsumesCollector.h"
0023 
0024 class MuonTrackValidator : public DQMEDAnalyzer, protected MuonTrackValidatorBase {
0025 public:
0026   /// Constructor
0027   MuonTrackValidator(const edm::ParameterSet& pset) : MuonTrackValidatorBase(pset) {
0028     dirName_ = pset.getParameter<std::string>("dirName");
0029     associatormap = pset.getParameter<edm::InputTag>("associatormap");
0030     UseAssociators = pset.getParameter<bool>("UseAssociators");
0031     useGEMs_ = pset.getParameter<bool>("useGEMs");
0032     useME0_ = pset.getParameter<bool>("useME0");
0033     edm::ParameterSet tpset = pset.getParameter<edm::ParameterSet>("muonTPSelector");
0034     tpSelector = TrackingParticleSelector(tpset.getParameter<double>("ptMin"),
0035                                           tpset.getParameter<double>("ptMax"),
0036                                           tpset.getParameter<double>("minRapidity"),
0037                                           tpset.getParameter<double>("maxRapidity"),
0038                                           tpset.getParameter<double>("tip"),
0039                                           tpset.getParameter<double>("lip"),
0040                                           tpset.getParameter<int>("minHit"),
0041                                           tpset.getParameter<bool>("signalOnly"),
0042                                           tpset.getParameter<bool>("intimeOnly"),
0043                                           tpset.getParameter<bool>("chargedOnly"),
0044                                           tpset.getParameter<bool>("stableOnly"),
0045                                           tpset.getParameter<std::vector<int> >("pdgId"));
0046 
0047     cosmictpSelector = CosmicTrackingParticleSelector(tpset.getParameter<double>("ptMin"),
0048                                                       tpset.getParameter<double>("minRapidity"),
0049                                                       tpset.getParameter<double>("maxRapidity"),
0050                                                       tpset.getParameter<double>("tip"),
0051                                                       tpset.getParameter<double>("lip"),
0052                                                       tpset.getParameter<int>("minHit"),
0053                                                       tpset.getParameter<bool>("chargedOnly"),
0054                                                       tpset.getParameter<std::vector<int> >("pdgId"));
0055 
0056     BiDirectional_RecoToSim_association = pset.getParameter<bool>("BiDirectional_RecoToSim_association");
0057 
0058     // dump cfg parameters
0059     edm::LogVerbatim("MuonTrackValidator") << "constructing MuonTrackValidator: " << pset.dump();
0060 
0061     // Declare consumes (also for the base class)
0062     bsSrc_Token = consumes<reco::BeamSpot>(bsSrc);
0063     if (label_tp_refvector)
0064       tp_refvector_Token = consumes<TrackingParticleRefVector>(label_tp);
0065     else
0066       tp_Token = consumes<TrackingParticleCollection>(label_tp);
0067     pileupinfo_Token = consumes<std::vector<PileupSummaryInfo> >(label_pileupinfo);
0068     for (unsigned int www = 0; www < label.size(); www++) {
0069       track_Collection_Token.push_back(consumes<edm::View<reco::Track> >(label[www]));
0070     }
0071     simToRecoCollection_Token = consumes<reco::SimToRecoCollection>(associatormap);
0072     recoToSimCollection_Token = consumes<reco::RecoToSimCollection>(associatormap);
0073 
0074     if (parametersDefiner == "LhcParametersDefinerForTP") {
0075       lhcParametersDefinerTP_ = std::make_unique<ParametersDefinerForTP>(bsSrc, consumesCollector());
0076     } else if (parametersDefiner == "CosmicParametersDefinerForTP") {
0077       cosmicParametersDefinerTP_ = std::make_unique<CosmicParametersDefinerForTP>(consumesCollector());
0078     } else {
0079       throw cms::Exception("Configuration") << "Unexpected label: parametersDefiner = " << parametersDefiner;
0080     }
0081 
0082     _simHitTpMapTag = mayConsume<SimHitTPAssociationProducer::SimHitTPAssociationList>(
0083         pset.getParameter<edm::InputTag>("simHitTpMapTag"));
0084 
0085     MABH = false;
0086     if (!UseAssociators) {
0087       // flag MuonAssociatorByHits
0088       if (associators[0] == "MuonAssociationByHits")
0089         MABH = true;
0090       // reset string associators to the map label
0091       associators.clear();
0092       associators.push_back(associatormap.label());
0093       edm::LogVerbatim("MuonTrackValidator") << "--> associators reset to: " << associators[0];
0094     } else {
0095       for (auto const& associator : associators) {
0096         consumes<reco::TrackToTrackingParticleAssociator>(edm::InputTag(associator));
0097       }
0098     }
0099 
0100     // inform on which SimHits will be counted
0101     if (usetracker)
0102       edm::LogVerbatim("MuonTrackValidator") << "\n usetracker = TRUE : Tracker SimHits WILL be counted";
0103     else
0104       edm::LogVerbatim("MuonTrackValidator") << "\n usetracker = FALSE : Tracker SimHits WILL NOT be counted";
0105     if (usemuon)
0106       edm::LogVerbatim("MuonTrackValidator") << " usemuon = TRUE : Muon SimHits WILL be counted";
0107     else
0108       edm::LogVerbatim("MuonTrackValidator") << " usemuon = FALSE : Muon SimHits WILL NOT be counted" << std::endl;
0109 
0110     // loop over the reco::Track collections to validate: check for inconsistent input settings
0111     for (unsigned int www = 0; www < label.size(); www++) {
0112       std::string recoTracksLabel = label[www].label();
0113       std::string recoTracksInstance = label[www].instance();
0114 
0115       // tracks with hits only on tracker
0116       if (recoTracksLabel == "generalTracks" || recoTracksLabel == "probeTracks" ||
0117           recoTracksLabel == "displacedTracks" || recoTracksLabel == "extractGemMuons" ||
0118           recoTracksLabel == "extractMe0Muons" || recoTracksLabel == "ctfWithMaterialTracksP5LHCNavigation" ||
0119           recoTracksLabel == "ctfWithMaterialTracksP5" ||
0120           recoTracksLabel == "hltIterL3OIMuonTrackSelectionHighPurity" || recoTracksLabel == "hltIterL3MuonMerged" ||
0121           recoTracksLabel == "hltIterL3MuonAndMuonFromL1Merged") {
0122         if (usemuon) {
0123           edm::LogWarning("MuonTrackValidator")
0124               << "\n*** WARNING : inconsistent input tracksTag = " << label[www] << "\n with usemuon == true"
0125               << "\n ---> resetting to usemuon == false ";
0126           usemuon = false;
0127         }
0128         if (!usetracker) {
0129           edm::LogWarning("MuonTrackValidator")
0130               << "\n*** WARNING : inconsistent input tracksTag = " << label[www] << "\n with usetracker == false"
0131               << "\n ---> resetting to usetracker == true ";
0132           usetracker = true;
0133         }
0134       }
0135 
0136       // tracks with hits only on muon detectors
0137       else if (recoTracksLabel == "seedsOfSTAmuons" || recoTracksLabel == "standAloneMuons" ||
0138                recoTracksLabel == "seedsOfDisplacedSTAmuons" || recoTracksLabel == "displacedStandAloneMuons" ||
0139                recoTracksLabel == "refittedStandAloneMuons" || recoTracksLabel == "cosmicMuons" ||
0140                recoTracksLabel == "cosmicMuons1Leg" || recoTracksLabel == "hltL2Muons") {
0141         if (usetracker) {
0142           edm::LogWarning("MuonTrackValidator")
0143               << "\n*** WARNING : inconsistent input tracksTag = " << label[www] << "\n with usetracker == true"
0144               << "\n ---> resetting to usetracker == false ";
0145           usetracker = false;
0146         }
0147         if (!usemuon) {
0148           edm::LogWarning("MuonTrackValidator")
0149               << "\n*** WARNING : inconsistent input tracksTag = " << label[www] << "\n with usemuon == false"
0150               << "\n ---> resetting to usemuon == true ";
0151           usemuon = true;
0152         }
0153       }
0154 
0155     }  // for (unsigned int www=0;www<label.size();www++)
0156   }
0157 
0158   /// Destructor
0159   ~MuonTrackValidator() override {}
0160 
0161   void analyze(const edm::Event&, const edm::EventSetup&) override;
0162   void bookHistograms(DQMEDAnalyzer::DQMStore::IBooker&, edm::Run const&, edm::EventSetup const&) override;
0163 
0164 private:
0165   std::string dirName_;
0166   edm::InputTag associatormap;
0167   edm::EDGetTokenT<reco::SimToRecoCollection> simToRecoCollection_Token;
0168   edm::EDGetTokenT<reco::RecoToSimCollection> recoToSimCollection_Token;
0169   edm::EDGetTokenT<SimHitTPAssociationProducer::SimHitTPAssociationList> _simHitTpMapTag;
0170 
0171   std::unique_ptr<ParametersDefinerForTP> lhcParametersDefinerTP_;
0172   std::unique_ptr<CosmicParametersDefinerForTP> cosmicParametersDefinerTP_;
0173 
0174   bool UseAssociators;
0175   bool useGEMs_;
0176   bool useME0_;
0177 
0178   // select tracking particles
0179   //(i.e. "denominator" of the efficiency ratio)
0180   TrackingParticleSelector tpSelector;
0181   CosmicTrackingParticleSelector cosmictpSelector;
0182 
0183   // flag new validation logic (bidirectional RecoToSim association)
0184   bool BiDirectional_RecoToSim_association;
0185   // flag MuonAssociatorByHits
0186   bool MABH;
0187 };
0188 
0189 #endif