Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-02-25 02:41:08

0001 // -*- C++ -*-
0002 //
0003 // Package:    SimHitTrackerAnalyzer
0004 // Class:      SimHitTrackerAnalyzer
0005 //
0006 /**\class SimHitTrackerAnalyzer SimHitTrackerAnalyzer.cc test/SimHitTrackerAnalyzer/src/SimHitTrackerAnalyzer.cc
0007 
0008  Description: <one line class summary>
0009 
0010  Implementation:
0011      <Notes on implementation>
0012 */
0013 //
0014 // Original Author:  Tommaso Boccali
0015 //         Created:  Tue Jul 26 08:47:57 CEST 2005
0016 //
0017 //
0018 
0019 // system include files
0020 #include <memory>
0021 
0022 // user include files
0023 #include "FWCore/Framework/interface/Frameworkfwd.h"
0024 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0025 
0026 #include "FWCore/Framework/interface/Event.h"
0027 #include "FWCore/Framework/interface/EventSetup.h"
0028 #include "FWCore/Framework/interface/MakerMacros.h"
0029 
0030 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0031 #include "SimDataFormats/TrackingHit/interface/PSimHit.h"
0032 #include "SimDataFormats/TrackingHit/interface/PSimHitContainer.h"
0033 
0034 #include "SimDataFormats/GeneratorProducts/interface/HepMCProduct.h"
0035 
0036 #include "SimDataFormats/Track/interface/SimTrack.h"
0037 #include "SimDataFormats/Track/interface/SimTrackContainer.h"
0038 #include "SimDataFormats/Vertex/interface/SimVertex.h"
0039 #include "SimDataFormats/Vertex/interface/SimVertexContainer.h"
0040 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0041 
0042 //
0043 //
0044 // class decleration
0045 //
0046 
0047 class SimHitTrackerAnalyzer : public edm::one::EDAnalyzer<> {
0048 public:
0049   explicit SimHitTrackerAnalyzer(const edm::ParameterSet&);
0050   ~SimHitTrackerAnalyzer() override = default;
0051 
0052   void analyze(const edm::Event&, const edm::EventSetup&) override;
0053 
0054 private:
0055   // ----------member data ---------------------------
0056   const std::string HepMCLabel;
0057   const std::string SimTkLabel;
0058   const std::string SimVtxLabel;
0059   const std::string SimHitLabel;
0060   const edm::EDGetTokenT<edm::SimTrackContainer> tokSimTk_;
0061   const edm::EDGetTokenT<edm::SimVertexContainer> tokSimVtx_;
0062   const edm::EDGetTokenT<edm::PSimHitContainer> tokPixelBarrelHitsLowTof_;
0063   const edm::EDGetTokenT<edm::PSimHitContainer> tokPixelBarrelHitsHighTof_;
0064   const edm::EDGetTokenT<edm::PSimHitContainer> tokPixelEndcapHitsLowTof_;
0065   const edm::EDGetTokenT<edm::PSimHitContainer> tokPixelEndcapHitsHighTof_;
0066   const edm::EDGetTokenT<edm::PSimHitContainer> tokTIBHitsLowTof_;
0067   const edm::EDGetTokenT<edm::PSimHitContainer> tokTIBHitsHighTof_;
0068   const edm::EDGetTokenT<edm::PSimHitContainer> tokTIDHitsLowTof_;
0069   const edm::EDGetTokenT<edm::PSimHitContainer> tokTIDHitsHighTof_;
0070   const edm::EDGetTokenT<edm::PSimHitContainer> tokTOBHitsLowTof_;
0071   const edm::EDGetTokenT<edm::PSimHitContainer> tokTOBHitsHighTof_;
0072   const edm::EDGetTokenT<edm::PSimHitContainer> tokTECHitsLowTof_;
0073   const edm::EDGetTokenT<edm::PSimHitContainer> tokTECHitsHighTof_;
0074 };
0075 
0076 //
0077 // constants, enums and typedefs
0078 //
0079 
0080 //
0081 // static data member definitions
0082 //
0083 
0084 //
0085 // constructors and destructor
0086 //
0087 SimHitTrackerAnalyzer::SimHitTrackerAnalyzer(const edm::ParameterSet& iConfig)
0088     : HepMCLabel(iConfig.getUntrackedParameter("moduleLabelMC", std::string("FlatRandomPtGunProducer"))),
0089       SimTkLabel(iConfig.getUntrackedParameter("moduleLabelTk", std::string("g4SimHits"))),
0090       SimVtxLabel(iConfig.getUntrackedParameter("moduleLabelVtx", std::string("g4SimHits"))),
0091       SimHitLabel(iConfig.getUntrackedParameter("moduleLabelHit", std::string("g4SimHits"))),
0092       tokSimTk_(consumes<edm::SimTrackContainer>(SimTkLabel)),
0093       tokSimVtx_(consumes<edm::SimVertexContainer>(SimVtxLabel)),
0094       tokPixelBarrelHitsLowTof_(
0095           consumes<edm::PSimHitContainer>(edm::InputTag(SimHitLabel, "TrackerHitsPixelBarrelLowTof"))),
0096       tokPixelBarrelHitsHighTof_(
0097           consumes<edm::PSimHitContainer>(edm::InputTag(SimHitLabel, "TrackerHitsPixelBarrelHighTof"))),
0098       tokPixelEndcapHitsLowTof_(
0099           consumes<edm::PSimHitContainer>(edm::InputTag(SimHitLabel, "TrackerHitsPixelEndcapLowTof"))),
0100       tokPixelEndcapHitsHighTof_(
0101           consumes<edm::PSimHitContainer>(edm::InputTag(SimHitLabel, "TrackerHitsPixelEndcapHighTof"))),
0102       tokTIBHitsLowTof_(consumes<edm::PSimHitContainer>(edm::InputTag(SimHitLabel, "TrackerHitsTIBLowTof"))),
0103       tokTIBHitsHighTof_(consumes<edm::PSimHitContainer>(edm::InputTag(SimHitLabel, "TrackerHitsTIBHighTof"))),
0104       tokTIDHitsLowTof_(consumes<edm::PSimHitContainer>(edm::InputTag(SimHitLabel, "TrackerHitsTIDLowTof"))),
0105       tokTIDHitsHighTof_(consumes<edm::PSimHitContainer>(edm::InputTag(SimHitLabel, "TrackerHitsTIDHighTof"))),
0106       tokTOBHitsLowTof_(consumes<edm::PSimHitContainer>(edm::InputTag(SimHitLabel, "TrackerHitsTOBLowTof"))),
0107       tokTOBHitsHighTof_(consumes<edm::PSimHitContainer>(edm::InputTag(SimHitLabel, "TrackerHitsTOBHighTof"))),
0108       tokTECHitsLowTof_(consumes<edm::PSimHitContainer>(edm::InputTag(SimHitLabel, "TrackerHitsTECLowTof"))),
0109       tokTECHitsHighTof_(consumes<edm::PSimHitContainer>(edm::InputTag(SimHitLabel, "TrackerHitsTECHighTof"))) {}
0110 
0111 //
0112 // member functions
0113 //
0114 
0115 // ------------ method called to produce the data  ------------
0116 void SimHitTrackerAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0117   using namespace edm;
0118 
0119   std::vector<PSimHit> theTrackerHits;
0120   std::vector<SimTrack> theSimTracks;
0121   std::vector<SimVertex> theSimVertexes;
0122 
0123   //   Handle<HepMCProduct> MCEvt;
0124   auto const& SimTk = iEvent.getHandle(tokSimTk_);
0125   auto const& SimVtx = iEvent.getHandle(tokSimVtx_);
0126   auto const& PixelBarrelHitsLowTof = iEvent.getHandle(tokPixelBarrelHitsLowTof_);
0127   auto const& PixelBarrelHitsHighTof = iEvent.getHandle(tokPixelBarrelHitsHighTof_);
0128   auto const& PixelEndcapHitsLowTof = iEvent.getHandle(tokPixelEndcapHitsLowTof_);
0129   auto const& PixelEndcapHitsHighTof = iEvent.getHandle(tokPixelEndcapHitsHighTof_);
0130   auto const& TIBHitsLowTof = iEvent.getHandle(tokTIBHitsLowTof_);
0131   auto const& TIBHitsHighTof = iEvent.getHandle(tokTIBHitsHighTof_);
0132   auto const& TIDHitsLowTof = iEvent.getHandle(tokTIDHitsLowTof_);
0133   auto const& TIDHitsHighTof = iEvent.getHandle(tokTIDHitsHighTof_);
0134   auto const& TOBHitsLowTof = iEvent.getHandle(tokTOBHitsLowTof_);
0135   auto const& TOBHitsHighTof = iEvent.getHandle(tokTOBHitsHighTof_);
0136   auto const& TECHitsLowTof = iEvent.getHandle(tokTECHitsLowTof_);
0137   auto const& TECHitsHighTof = iEvent.getHandle(tokTECHitsHighTof_);
0138 
0139   theSimTracks.insert(theSimTracks.end(), SimTk->begin(), SimTk->end());
0140   theSimVertexes.insert(theSimVertexes.end(), SimVtx->begin(), SimVtx->end());
0141   theTrackerHits.insert(theTrackerHits.end(), PixelBarrelHitsLowTof->begin(), PixelBarrelHitsLowTof->end());
0142   theTrackerHits.insert(theTrackerHits.end(), PixelBarrelHitsHighTof->begin(), PixelBarrelHitsHighTof->end());
0143   theTrackerHits.insert(theTrackerHits.end(), PixelEndcapHitsLowTof->begin(), PixelEndcapHitsLowTof->end());
0144   theTrackerHits.insert(theTrackerHits.end(), PixelEndcapHitsHighTof->begin(), PixelEndcapHitsHighTof->end());
0145   theTrackerHits.insert(theTrackerHits.end(), TIBHitsLowTof->begin(), TIBHitsLowTof->end());
0146   theTrackerHits.insert(theTrackerHits.end(), TIBHitsHighTof->begin(), TIBHitsHighTof->end());
0147   theTrackerHits.insert(theTrackerHits.end(), TIDHitsLowTof->begin(), TIDHitsLowTof->end());
0148   theTrackerHits.insert(theTrackerHits.end(), TIDHitsHighTof->begin(), TIDHitsHighTof->end());
0149   theTrackerHits.insert(theTrackerHits.end(), TOBHitsLowTof->begin(), TOBHitsLowTof->end());
0150   theTrackerHits.insert(theTrackerHits.end(), TOBHitsHighTof->begin(), TOBHitsHighTof->end());
0151   theTrackerHits.insert(theTrackerHits.end(), TECHitsLowTof->begin(), TECHitsLowTof->end());
0152   theTrackerHits.insert(theTrackerHits.end(), TECHitsHighTof->begin(), TECHitsHighTof->end());
0153 
0154   /*
0155    Hepmc::GenEvent * myGenEvent = new  HepMC::GenEvent(*(MCEvt->GetEvent()));
0156    
0157    for ( HepMC::GenEvent::particle_iterator p = myGenEvent->particles_begin();
0158      p != myGenEvent->particles_end(); ++p ) {
0159      edm::LogInfo("TrackerSimInfoAnalyzer")<< "Particle type form MC = "<< abs((*p)->pdg_id()) ; 
0160      edm::LogInfo("TrackerSimInfoAnalyzer")<< "Particle momentum Pt form MC = "<< (*p)->momentum().perp() ;  
0161    }
0162    */
0163 
0164   for (std::vector<SimTrack>::iterator isimtk = theSimTracks.begin(); isimtk != theSimTracks.end(); ++isimtk) {
0165     edm::LogInfo("TrackerSimInfoAnalyzer") << " Track momentum  x = " << isimtk->momentum().x()
0166                                            << " y = " << isimtk->momentum().y() << " z = " << isimtk->momentum().z();
0167     edm::LogInfo("TrackerSimInfoAnalyzer") << " Track momentum Ptx = " << std::sqrt(isimtk->momentum().perp2());
0168   }
0169 
0170   for (std::vector<SimVertex>::iterator isimvtx = theSimVertexes.begin(); isimvtx != theSimVertexes.end(); ++isimvtx) {
0171     edm::LogInfo("TrackerSimInfoAnalyzer") << " Vertex position  x = " << isimvtx->position().x()
0172                                            << " y = " << isimvtx->position().y() << " z = " << isimvtx->position().z();
0173   }
0174 
0175   std::map<unsigned int, std::vector<PSimHit>, std::less<unsigned int> > SimHitMap;
0176 
0177   for (std::vector<PSimHit>::iterator isim = theTrackerHits.begin(); isim != theTrackerHits.end(); ++isim) {
0178     SimHitMap[(*isim).detUnitId()].push_back((*isim));
0179     edm::LogInfo("TrackerSimInfoAnalyzer")
0180         << " SimHit position  x = " << isim->localPosition().x() << " y = " << isim->localPosition().y()
0181         << " z = " << isim->localPosition().z();
0182     edm::LogInfo("TrackerSimInfoAnalyzer") << " SimHit DetID = " << isim->detUnitId();
0183     edm::LogInfo("TrackerSimInfoAnalyzer") << " Time of flight = " << isim->timeOfFlight();
0184   }
0185 }
0186 
0187 //define this as a plug-in
0188 DEFINE_FWK_MODULE(SimHitTrackerAnalyzer);