Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:06:36

0001 // -*- C++ -*-
0002 //
0003 // Package:    OverlapProblemTPAnalyzer
0004 // Class:      OverlapProblemTPAnalyzer
0005 //
0006 /**\class OverlapProblemTPAnalyzer OverlapProblemTPAnalyzer.cc DebugTools/OverlapProblem/plugins/OverlapProblemTPAnalyzer.cc
0007 
0008  Description: <one line class summary>
0009 
0010  Implementation:
0011      <Notes on implementation>
0012 */
0013 //
0014 // Original Author:  Andrea Venturi
0015 //         Created:  Thu Dec 16 16:32:56 CEST 2010
0016 // $Id: OverlapProblemTPAnalyzer.cc,v 1.1 2011/01/22 17:59:36 venturia Exp $
0017 //
0018 //
0019 
0020 // system include files
0021 #include <memory>
0022 #include <numeric>
0023 #include <vector>
0024 
0025 // user include files
0026 #include "FWCore/Framework/interface/Frameworkfwd.h"
0027 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0028 
0029 #include "FWCore/Framework/interface/Event.h"
0030 #include "FWCore/Framework/interface/ESHandle.h"
0031 #include "FWCore/Framework/interface/Run.h"
0032 #include "FWCore/Framework/interface/MakerMacros.h"
0033 
0034 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0035 
0036 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0037 
0038 #include "FWCore/ServiceRegistry/interface/Service.h"
0039 #include "CommonTools/UtilAlgos/interface/TFileService.h"
0040 
0041 #include "FWCore/Utilities/interface/InputTag.h"
0042 
0043 #include "SimDataFormats/TrackingAnalysis/interface/TrackingParticle.h"
0044 #include "SimDataFormats/TrackingHit/interface/PSimHit.h"
0045 
0046 #include "DataFormats/DetId/interface/DetId.h"
0047 #include "DataFormats/TrackReco/interface/Track.h"
0048 #include "DataFormats/TrackReco/interface/TrackFwd.h"
0049 
0050 #include "SimDataFormats/Associations/interface/TrackToTrackingParticleAssociator.h"
0051 
0052 #include "TH1F.h"
0053 #include "TH2F.h"
0054 //
0055 // class decleration
0056 //
0057 
0058 class OverlapProblemTPAnalyzer : public edm::one::EDAnalyzer<edm::one::WatchRuns, edm::one::SharedResources> {
0059 public:
0060   explicit OverlapProblemTPAnalyzer(const edm::ParameterSet&);
0061   ~OverlapProblemTPAnalyzer() override;
0062 
0063 private:
0064   void beginRun(const edm::Run&, const edm::EventSetup&) override;
0065   void endRun(const edm::Run&, const edm::EventSetup&) override;
0066   void analyze(const edm::Event&, const edm::EventSetup&) override;
0067 
0068   // ----------member data ---------------------------
0069 
0070   TH1F* m_ptp;
0071   TH1F* m_etatp;
0072   TH1F* m_nhits;
0073   TH1F* m_nrechits;
0074   TH2F* m_nrecvssimhits;
0075   TH1F* m_nassotk;
0076   TH1F* m_pdgid;
0077   TH1F* m_llbit;
0078   TH1F* m_statustp;
0079 
0080   std::vector<TH1F*> m_simhitytecr;
0081   std::vector<TH1F*> m_assosimhitytecr;
0082 
0083   edm::EDGetTokenT<TrackingParticleCollection> m_tpcollToken;
0084   edm::EDGetTokenT<edm::View<reco::Track> > m_trkcollToken;
0085   edm::EDGetTokenT<reco::TrackToTrackingParticleAssociator> m_associatorToken;
0086 };
0087 
0088 //
0089 // constants, enums and typedefs
0090 //
0091 
0092 //
0093 // static data member definitions
0094 //
0095 
0096 //
0097 // constructors and destructor
0098 //
0099 OverlapProblemTPAnalyzer::OverlapProblemTPAnalyzer(const edm::ParameterSet& iConfig)
0100     : m_simhitytecr(),
0101       m_assosimhitytecr(),
0102       m_tpcollToken(
0103           consumes<TrackingParticleCollection>(iConfig.getParameter<edm::InputTag>("trackingParticlesCollection"))),
0104       m_trkcollToken(consumes<edm::View<reco::Track> >(iConfig.getParameter<edm::InputTag>("trackCollection"))),
0105       m_associatorToken(consumes<reco::TrackToTrackingParticleAssociator>(edm::InputTag("trackAssociatorByHits"))) {
0106   //now do what ever initialization is needed
0107 
0108   usesResource(TFileService::kSharedResource);
0109 
0110   edm::Service<TFileService> tfserv;
0111 
0112   m_ptp = tfserv->make<TH1F>("tpmomentum", "Tracking Particle momentum", 100, 0., 200.);
0113   m_etatp = tfserv->make<TH1F>("tpeta", "Tracking Particle pseudorapidity", 100, -4., 4.);
0114   m_nhits = tfserv->make<TH1F>("nhits", "Tracking Particle associated hits", 100, -0.5, 99.5);
0115   m_nrechits = tfserv->make<TH1F>("nrechits", "Tracking Particle associated rec hits", 100, -0.5, 99.5);
0116   m_nrecvssimhits = tfserv->make<TH2F>(
0117       "nrecvssimhits", "Tracking Particle associated rec hits vs sim hits", 100, -0.5, 99.5, 100, -0.5, 99.5);
0118   m_nassotk = tfserv->make<TH1F>("nassotk", "Number of assocated reco tracks", 10, -0.5, 9.5);
0119 
0120   m_pdgid = tfserv->make<TH1F>("pdgid", "Tracking Particle PDG id", 1000, -500.5, 499.5);
0121   m_llbit = tfserv->make<TH1F>("llbit", "Tracking Particle LongLived bit", 2, -0.5, 1.5);
0122   m_statustp = tfserv->make<TH1F>("statustp", "Tracking Particle status", 2000, -1000.5, 999.5);
0123 
0124   for (unsigned int ring = 0; ring < 7; ++ring) {
0125     char name[100];
0126     char title[100];
0127 
0128     sprintf(name, "simytecr_%d", ring + 1);
0129     sprintf(title, "SimHit local Y TEC ring %d", ring + 1);
0130 
0131     m_simhitytecr.push_back(tfserv->make<TH1F>(name, title, 200, -20., 20.));
0132 
0133     sprintf(name, "assosimytecr_%d", ring + 1);
0134     sprintf(title, "SimHit local Y TEC ring %d with associated RecHit", ring + 1);
0135 
0136     m_assosimhitytecr.push_back(tfserv->make<TH1F>(name, title, 200, -20., 20.));
0137   }
0138 }
0139 
0140 OverlapProblemTPAnalyzer::~OverlapProblemTPAnalyzer() {
0141   // do anything here that needs to be done at desctruction time
0142   // (e.g. close files, deallocate resources etc.)
0143 }
0144 
0145 //
0146 // member functions
0147 //
0148 
0149 // ------------ method called to for each event  ------------
0150 void OverlapProblemTPAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0151   using namespace edm;
0152 
0153   // reco track Handle
0154 
0155   //   Handle<reco::TrackCollection> trkcoll;
0156   Handle<edm::View<reco::Track> > trkcoll;
0157   iEvent.getByToken(m_trkcollToken, trkcoll);
0158 
0159   Handle<TrackingParticleCollection> tpcoll;
0160   iEvent.getByToken(m_tpcollToken, tpcoll);
0161 
0162   Handle<reco::TrackToTrackingParticleAssociator> tahandle;
0163   iEvent.getByToken(m_associatorToken, tahandle);
0164 
0165   // associate reco to sim tracks
0166 
0167   reco::SimToRecoCollection srcoll = tahandle->associateSimToReco(trkcoll, tpcoll);
0168 
0169   // loop on Handle with index and use find
0170 
0171   for (unsigned int index = 0; index != tpcoll->size(); ++index) {
0172     // get TrackingParticleRef
0173 
0174     const TrackingParticleRef tp(tpcoll, index);
0175 
0176     if (std::abs(tp->pdgId()) != 13)
0177       continue;
0178 
0179     // get the SimHIt from tracker only
0180 
0181     // Commented since the new TP's do not have this method
0182     //    std::vector<PSimHit> tksimhits = tp->trackPSimHit(DetId::Tracker);
0183 
0184     m_ptp->Fill(tp->p());
0185     m_etatp->Fill(tp->eta());
0186     //     m_nhits->Fill(tp->matchedHit());
0187     // With the new Tracking Particles I have to use a different method
0188     //    m_nhits->Fill(tksimhits.size());
0189     m_nhits->Fill(tp->numberOfTrackerHits());
0190 
0191     m_pdgid->Fill(tp->pdgId());
0192     m_llbit->Fill(tp->longLived());
0193     m_statustp->Fill(tp->status());
0194 
0195     // prepare a vector of TrackingRecHit from the associated reco tracks
0196 
0197     std::vector<DetId> rechits;
0198 
0199     // look at associated tracks
0200 
0201     if (srcoll.find(tp) != srcoll.end()) {
0202       reco::SimToRecoCollection::result_type trks = srcoll[tp];
0203       m_nassotk->Fill(trks.size());
0204 
0205       // loop on associated tracks and fill TrackingRecHit vector
0206       for (reco::SimToRecoCollection::result_type::const_iterator trk = trks.begin(); trk != trks.end(); ++trk) {
0207         for (trackingRecHit_iterator rh = trk->first->recHitsBegin(); rh != trk->first->recHitsEnd(); ++rh) {
0208           rechits.push_back((*rh)->geographicalId());
0209         }
0210       }
0211 
0212     } else {
0213       m_nassotk->Fill(0.);
0214       edm::LogInfo("NoAssociatedRecoTrack")
0215           << "No associated reco track for TP with p = " << tp->p() << " and eta = " << tp->eta();
0216     }
0217 
0218     m_nrechits->Fill(rechits.size());
0219     // new method used to be compliant with the new TP's
0220     m_nrecvssimhits->Fill(tp->numberOfTrackerHits(), rechits.size());
0221 
0222     LogDebug("RecHitDetId") << "List of " << rechits.size() << " rechits detid from muon with p = " << tp->p()
0223                             << "and eta = " << tp->eta();
0224     for (unsigned int i = 0; i < rechits.size(); ++i) {
0225       LogTrace("RecHitDetId") << rechits[i].rawId();
0226     }
0227 
0228     // loop on sim hits
0229 
0230     LogDebug("SimHitDetId") << "List of " << tp->numberOfTrackerHits()
0231                             << " simhits detid from muon with p = " << tp->p() << "and eta = " << tp->eta();
0232   }
0233 }
0234 
0235 void OverlapProblemTPAnalyzer::beginRun(const edm::Run& iRun, const edm::EventSetup&) {}
0236 
0237 void OverlapProblemTPAnalyzer::endRun(const edm::Run& iRun, const edm::EventSetup&) {}
0238 
0239 //define this as a plug-in
0240 DEFINE_FWK_MODULE(OverlapProblemTPAnalyzer);