|
| 1 | +// system include files |
| 2 | +#include <memory> |
| 3 | + |
| 4 | +#include "TTree.h" |
| 5 | +#include "TFile.h" |
| 6 | + |
| 7 | + |
| 8 | +// user include files |
| 9 | +#include "FWCore/Framework/interface/Frameworkfwd.h" |
| 10 | +#include "FWCore/Framework/interface/one/EDAnalyzer.h" |
| 11 | + |
| 12 | +#include "FWCore/Framework/interface/Event.h" |
| 13 | +#include "FWCore/Framework/interface/MakerMacros.h" |
| 14 | + |
| 15 | +#include "FWCore/ParameterSet/interface/ParameterSet.h" |
| 16 | +#include "FWCore/Utilities/interface/InputTag.h" |
| 17 | +#include "DataFormats/TrackReco/interface/Track.h" |
| 18 | +#include "DataFormats/TrackReco/interface/TrackFwd.h" |
| 19 | + |
| 20 | +#include "SimTracker/TrackerHitAssociation/interface/ClusterTPAssociation.h" |
| 21 | +#include "SimDataFormats/PileupSummaryInfo/interface/PileupSummaryInfo.h" |
| 22 | +#include "SimDataFormats/Associations/interface/TrackToTrackingParticleAssociator.h" |
| 23 | + |
| 24 | +#include "SimTracker/Common/interface/TrackingParticleSelector.h" |
| 25 | + |
| 26 | +#include "FWCore/ServiceRegistry/interface/Service.h" |
| 27 | +#include "CommonTools/UtilAlgos/interface/TFileService.h" |
| 28 | + |
| 29 | +using reco::TrackCollection; |
| 30 | + |
| 31 | +class SimpleTrackValidation : public edm::one::EDAnalyzer<edm::one::SharedResources> { |
| 32 | +public: |
| 33 | + explicit SimpleTrackValidation(const edm::ParameterSet&); |
| 34 | + ~SimpleTrackValidation() override; |
| 35 | + |
| 36 | + static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); |
| 37 | + |
| 38 | +private: |
| 39 | + |
| 40 | + |
| 41 | + void beginJob() override; |
| 42 | + void analyze(const edm::Event&, const edm::EventSetup&) override; |
| 43 | + void endJob() override; |
| 44 | + |
| 45 | + // Counters |
| 46 | + int global_rt_ = 0; |
| 47 | + int global_at_ = 0; |
| 48 | + int global_st_ = 0; |
| 49 | + int global_dt_ = 0; |
| 50 | + int global_ast_ = 0; |
| 51 | + |
| 52 | + TrackingParticleSelector tpSelector; |
| 53 | + TTree* output_tree_; |
| 54 | + std::vector<edm::InputTag> trackLabels_; |
| 55 | + edm::EDGetTokenT<ClusterTPAssociation> tpMap_; |
| 56 | + std::vector<edm::EDGetTokenT<edm::View<reco::Track>>> trackTokens_; |
| 57 | + edm::EDGetTokenT<reco::TrackToTrackingParticleAssociator> trackAssociatorToken_; |
| 58 | + edm::EDGetTokenT<TrackingParticleCollection> trackingParticleToken_; |
| 59 | + |
| 60 | +}; |
| 61 | + |
| 62 | +SimpleTrackValidation::SimpleTrackValidation(const edm::ParameterSet& iConfig) |
| 63 | + : trackLabels_(iConfig.getParameter<std::vector<edm::InputTag>>("trackLabels")), |
| 64 | + trackAssociatorToken_(consumes<reco::TrackToTrackingParticleAssociator>(iConfig.getUntrackedParameter<edm::InputTag>("trackAssociator"))), |
| 65 | + trackingParticleToken_(consumes<TrackingParticleCollection>(iConfig.getParameter< edm::InputTag >("trackingParticles"))) |
| 66 | +{ |
| 67 | + |
| 68 | + for (auto& itag : trackLabels_) { |
| 69 | + trackTokens_.push_back(consumes<edm::View<reco::Track>>(itag)); |
| 70 | + } |
| 71 | + tpSelector = TrackingParticleSelector(iConfig.getParameter<double>("ptMinTP"), |
| 72 | + iConfig.getParameter<double>("ptMaxTP"), |
| 73 | + iConfig.getParameter<double>("minRapidityTP"), |
| 74 | + iConfig.getParameter<double>("maxRapidityTP"), |
| 75 | + iConfig.getParameter<double>("tipTP"), |
| 76 | + iConfig.getParameter<double>("lipTP"), |
| 77 | + iConfig.getParameter<int>("minHitTP"), |
| 78 | + iConfig.getParameter<bool>("signalOnlyTP"), |
| 79 | + iConfig.getParameter<bool>("intimeOnlyTP"), |
| 80 | + iConfig.getParameter<bool>("chargedOnlyTP"), |
| 81 | + iConfig.getParameter<bool>("stableOnlyTP"), |
| 82 | + iConfig.getParameter<std::vector<int>>("pdgIdTP"), |
| 83 | + iConfig.getParameter<bool>("invertRapidityCutTP"), |
| 84 | + iConfig.getParameter<double>("minPhiTP"), |
| 85 | + iConfig.getParameter<double>("maxPhiTP")); |
| 86 | +} |
| 87 | + |
| 88 | +SimpleTrackValidation::~SimpleTrackValidation(){} |
| 89 | + |
| 90 | +void SimpleTrackValidation::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) { |
| 91 | + |
| 92 | + using namespace edm; |
| 93 | + |
| 94 | + auto const& associatorByHits = iEvent.get(trackAssociatorToken_); |
| 95 | + |
| 96 | + TrackingParticleRefVector tpCollection; |
| 97 | + edm::Handle<TrackingParticleCollection> TPCollectionH; |
| 98 | + iEvent.getByToken(trackingParticleToken_, TPCollectionH); |
| 99 | + |
| 100 | + for (size_t i = 0, size = TPCollectionH->size(); i < size; ++i) { |
| 101 | + auto tp = TrackingParticleRef(TPCollectionH, i); |
| 102 | + if (tpSelector(*tp)) { |
| 103 | + tpCollection.push_back(tp); |
| 104 | + } |
| 105 | + } |
| 106 | + |
| 107 | + for (const auto& trackToken : trackTokens_) |
| 108 | + { |
| 109 | + |
| 110 | + edm::Handle<edm::View<reco::Track>> tracksHandle; |
| 111 | + iEvent.getByToken(trackToken, tracksHandle); |
| 112 | + const edm::View<reco::Track>& tracks = *tracksHandle; |
| 113 | + |
| 114 | + edm::RefToBaseVector<reco::Track> trackRefs; |
| 115 | + for (edm::View<reco::Track>::size_type i = 0; i < tracks.size(); ++i) { |
| 116 | + trackRefs.push_back(tracks.refAt(i)); |
| 117 | + } |
| 118 | + |
| 119 | + reco::RecoToSimCollection recSimColl = associatorByHits.associateRecoToSim(trackRefs, tpCollection); |
| 120 | + reco::SimToRecoCollection simRecColl = associatorByHits.associateSimToReco(trackRefs, tpCollection); |
| 121 | + int rt = 0; |
| 122 | + int at = 0; |
| 123 | + int ast = 0; |
| 124 | + int dt = 0; |
| 125 | + int st = tpCollection.size(); |
| 126 | + for (const auto& track : trackRefs) { |
| 127 | + rt++; |
| 128 | + auto foundTP = recSimColl.find(track); |
| 129 | + if (foundTP != recSimColl.end()) { |
| 130 | + const auto& tp = foundTP->val; |
| 131 | + if (!tp.empty()) { |
| 132 | + at++; |
| 133 | + } |
| 134 | + if (simRecColl.find(tp[0].first) != simRecColl.end()) { |
| 135 | + if (simRecColl[tp[0].first].size() > 1) { |
| 136 | + dt++; |
| 137 | + } |
| 138 | + } |
| 139 | + } |
| 140 | + } |
| 141 | + for (const TrackingParticleRef& tpr : tpCollection) { |
| 142 | + auto foundTrack = simRecColl.find(tpr); |
| 143 | + if (foundTrack != simRecColl.end()) { |
| 144 | + ast++; |
| 145 | + } |
| 146 | + } |
| 147 | + |
| 148 | + LogPrint("TrackValidator") << "Tag " << trackLabels_[0].label() << " Total simulated "<< st << " Associated tracks " << at << " Total reconstructed " << rt; |
| 149 | + global_rt_ += rt; |
| 150 | + global_st_ += st; |
| 151 | + global_at_ += at; |
| 152 | + global_dt_ += dt; |
| 153 | + global_ast_ += ast; |
| 154 | + } |
| 155 | +} |
| 156 | + |
| 157 | +void SimpleTrackValidation::beginJob() { |
| 158 | + |
| 159 | + edm::Service<TFileService> fs; |
| 160 | + output_tree_ = fs->make<TTree>("output", "Simple Track Validation TTree"); |
| 161 | + |
| 162 | + output_tree_->Branch("rt", &global_rt_); |
| 163 | + output_tree_->Branch("at", &global_at_); |
| 164 | + output_tree_->Branch("st", &global_st_); |
| 165 | + output_tree_->Branch("dt", &global_dt_); |
| 166 | + output_tree_->Branch("ast", &global_ast_); |
| 167 | +} |
| 168 | + |
| 169 | +void SimpleTrackValidation::endJob() { |
| 170 | + output_tree_->Fill(); |
| 171 | +} |
| 172 | + |
| 173 | +void SimpleTrackValidation::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { |
| 174 | + |
| 175 | + edm::ParameterSetDescription desc; |
| 176 | + desc.setUnknown(); |
| 177 | + descriptions.addDefault(desc); |
| 178 | + desc.add<std::vector<edm::InputTag>>("trackLabels", {edm::InputTag("generalTracks")}); |
| 179 | + desc.add<edm::InputTag>("trackingParticles", edm::InputTag("mix", "MergedTrackTruth")); |
| 180 | + desc.add<edm::InputTag>("trackAssociator", edm::InputTag("trackingParticleRecoTrackAsssociation")); |
| 181 | + |
| 182 | + // TP Selector parameters |
| 183 | + desc.add<double>("ptMinTP", 0.9); |
| 184 | + desc.add<double>("ptMaxTP", 1e100); |
| 185 | + desc.add<double>("minRapidityTP", -2.4); |
| 186 | + desc.add<double>("maxRapidityTP", 2.4); |
| 187 | + desc.add<double>("tipTP", 3.5); |
| 188 | + desc.add<double>("lipTP", 30.0); |
| 189 | + desc.add<int>("minHitTP", 0); |
| 190 | + desc.add<bool>("signalOnlyTP", true); |
| 191 | + desc.add<bool>("intimeOnlyTP", false); |
| 192 | + desc.add<bool>("chargedOnlyTP", true); |
| 193 | + desc.add<bool>("stableOnlyTP", false); |
| 194 | + desc.add<std::vector<int>>("pdgIdTP", {}); |
| 195 | + desc.add<bool>("invertRapidityCutTP", false); |
| 196 | + desc.add<double>("minPhiTP", -3.2); |
| 197 | + desc.add<double>("maxPhiTP", 3.2); |
| 198 | + |
| 199 | + descriptions.addWithDefaultLabel(desc); |
| 200 | +} |
| 201 | + |
| 202 | +DEFINE_FWK_MODULE(SimpleTrackValidation); |
0 commit comments