Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:30:41

0001 // system include files
0002 #include <vector>
0003 
0004 // user include files
0005 #include "FWCore/Framework/interface/Frameworkfwd.h"
0006 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0007 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0008 #include "FWCore/Utilities/interface/EDGetToken.h"
0009 #include "DataFormats/Common/interface/ValidHandle.h"
0010 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0011 
0012 #include "FWCore/Framework/interface/Event.h"
0013 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0014 
0015 #include "SimDataFormats/TrackingAnalysis/interface/TrackingParticle.h"
0016 #include "SimDataFormats/TrackingAnalysis/interface/TrackingParticleFwd.h"
0017 #include "SimDataFormats/TrackingAnalysis/interface/TrackingVertexContainer.h"
0018 
0019 class TrackingTruthDumper : public edm::one::EDAnalyzer<> {
0020 public:
0021   explicit TrackingTruthDumper(const edm::ParameterSet&);
0022   ~TrackingTruthDumper() override{};
0023 
0024   void analyze(const edm::Event&, const edm::EventSetup&) override;
0025   void beginJob() override{};
0026   void endJob() override{};
0027 
0028   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0029 
0030 private:
0031   edm::EDGetTokenT<TrackingParticleCollection> simTPToken_;
0032   edm::EDGetTokenT<TrackingVertexCollection> simTVToken_;
0033 
0034   bool dumpVtx_;
0035   bool dumpTk_;
0036 };
0037 
0038 TrackingTruthDumper::TrackingTruthDumper(const edm::ParameterSet& iConfig)
0039     : simTPToken_(consumes<TrackingParticleCollection>(iConfig.getParameter<edm::InputTag>("moduleLabelTk"))),
0040       simTVToken_(consumes<TrackingVertexCollection>(iConfig.getParameter<edm::InputTag>("moduleLabelVtx"))),
0041       dumpVtx_(iConfig.getUntrackedParameter<bool>("dumpVtx")),
0042       dumpTk_(iConfig.getUntrackedParameter<bool>("dumpTk")) {}
0043 
0044 //
0045 // member functions
0046 //
0047 
0048 // ------------ method called to produce the data  ------------
0049 void TrackingTruthDumper::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0050   auto SimTk = edm::makeValid(iEvent.getHandle(simTPToken_));
0051   auto SimVtx = edm::makeValid(iEvent.getHandle(simTVToken_));
0052 
0053   edm::LogPrint("DumpTkVtx") << "\n SimVertex / SimTrack structure dump \n";
0054   edm::LogPrint("DumpTkVtx") << " SimVertex in the event = " << (*SimTk).size();
0055   edm::LogPrint("DumpTkVtx") << " SimTracks in the event = " << (*SimVtx).size();
0056   edm::LogPrint("DumpTkVtx") << "\n";
0057   size_t isimvtx(0);
0058   size_t isimtk(0);
0059 
0060   if (dumpVtx_) {
0061     for (const auto& vtx : *SimVtx) {
0062       edm::LogPrint("DumpTkVtx") << "TrackingVertex " << isimvtx << " = " << vtx << "\n";
0063       edm::LogPrint("DumpTkVtx") << "TPs of this vertex: \n";
0064       isimtk = 0;
0065       for (const auto& tk : vtx.daughterTracks()) {
0066         edm::LogPrint("DumpTkVtx") << "TrackingParticle " << isimtk << " = " << *tk << "\n";
0067         isimtk++;
0068       }
0069       edm::LogPrint("DumpTkVtx") << "\n";
0070       isimvtx++;
0071     }
0072   }
0073 
0074   if (dumpTk_) {
0075     isimtk = 0;
0076     for (const auto& tk : *SimTk) {
0077       bool isMerged = tk.g4Tracks().size() > 1;
0078       edm::LogPrint("DumpTkVtx") << "TrackingParticle " << isimtk << " isMerged " << isMerged << " = " << tk << "\n";
0079       isimtk++;
0080     }
0081   }
0082 
0083   return;
0084 }
0085 
0086 void TrackingTruthDumper::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0087   edm::ParameterSetDescription desc;
0088   desc.add<edm::InputTag>("moduleLabelTk", edm::InputTag("mix", "MergedTrackTruth"))
0089       ->setComment("Module for input TrackingParticle collection");
0090   desc.add<edm::InputTag>("moduleLabelVtx", edm::InputTag("mix", "MergedTrackTruth"))
0091       ->setComment("Module for input TrackingVertex collection");
0092   desc.addUntracked<bool>("dumpVtx", true);
0093   desc.addUntracked<bool>("dumpTk", true);
0094   descriptions.add("trackingTruthDumper", desc);
0095 }
0096 
0097 #include "FWCore/Framework/interface/MakerMacros.h"
0098 
0099 //define this as a plug-in
0100 DEFINE_FWK_MODULE(TrackingTruthDumper);