Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 // -*- C++ -*-
0002 //
0003 // Package:    OverlapProblemTSOSAnalyzer
0004 // Class:      OverlapProblemTSOSAnalyzer
0005 //
0006 /**\class OverlapProblemTSOSAnalyzer OverlapProblemTSOSAnalyzer.cc DebugTools/OverlapProblem/plugins/OverlapProblemTSOSAnalyzer.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: OverlapProblemTSOSAnalyzer.cc,v 1.2 2013/04/10 21:08:01 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 "TrackingTools/PatternTools/interface/Trajectory.h"
0044 #include "TrackingTools/PatternTools/interface/TrajTrackAssociation.h"
0045 #include "TrackingTools/PatternTools/interface/TrajectoryMeasurement.h"
0046 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateOnSurface.h"
0047 #include "TrackingTools/TrackFitters/interface/TrajectoryStateCombiner.h"
0048 #include "TrackingTools/TransientTrackingRecHit/interface/TransientTrackingRecHit.h"
0049 
0050 #include "DataFormats/Common/interface/Ref.h"
0051 #include "DataFormats/DetId/interface/DetId.h"
0052 #include "DataFormats/TrackReco/interface/Track.h"
0053 #include "DataFormats/TrackReco/interface/TrackFwd.h"
0054 #include "CommonTools/UtilAlgos/interface/DetIdSelector.h"
0055 #include "DataFormats/TrackerRecHit2D/interface/SiPixelRecHit.h"
0056 
0057 #include "TH1F.h"
0058 
0059 #include "DPGAnalysis/SiStripTools/interface/TSOSHistogramMaker.h"
0060 //
0061 // class decleration
0062 //
0063 
0064 class OverlapProblemTSOSAnalyzer : public edm::one::EDAnalyzer<edm::one::WatchRuns, edm::one::SharedResources> {
0065 public:
0066   explicit OverlapProblemTSOSAnalyzer(const edm::ParameterSet&);
0067   ~OverlapProblemTSOSAnalyzer() override;
0068 
0069 private:
0070   void beginRun(const edm::Run&, const edm::EventSetup&) override;
0071   void endRun(const edm::Run&, const edm::EventSetup&) override;
0072   void analyze(const edm::Event&, const edm::EventSetup&) override;
0073 
0074   // ----------member data ---------------------------
0075 
0076   TH1F* m_ptrk;
0077   TH1F* m_etatrk;
0078 
0079   bool m_validOnly;
0080   edm::EDGetTokenT<TrajTrackAssociationCollection> m_ttacollToken;
0081   const bool m_debug;
0082 
0083   TSOSHistogramMaker m_tsoshm;
0084 };
0085 
0086 //
0087 // constants, enums and typedefs
0088 //
0089 
0090 //
0091 // static data member definitions
0092 //
0093 
0094 //
0095 // constructors and destructor
0096 //
0097 OverlapProblemTSOSAnalyzer::OverlapProblemTSOSAnalyzer(const edm::ParameterSet& iConfig)
0098     : m_validOnly(iConfig.getParameter<bool>("onlyValidRecHit")),
0099       m_ttacollToken(
0100           consumes<TrajTrackAssociationCollection>(iConfig.getParameter<edm::InputTag>("trajTrackAssoCollection"))),
0101       m_debug(iConfig.getUntrackedParameter<bool>("debugMode", false)),
0102       m_tsoshm(iConfig.getParameter<edm::ParameterSet>("tsosHMConf")) {
0103   //now do what ever initialization is needed
0104   usesResource(TFileService::kSharedResource);
0105 
0106   edm::Service<TFileService> tfserv;
0107 
0108   m_ptrk = tfserv->make<TH1F>("trkmomentum", "Refitted Track  momentum", 100, 0., 200.);
0109   m_etatrk = tfserv->make<TH1F>("trketa", "Refitted Track pseudorapidity", 100, -4., 4.);
0110 }
0111 
0112 OverlapProblemTSOSAnalyzer::~OverlapProblemTSOSAnalyzer() {
0113   // do anything here that needs to be done at desctruction time
0114   // (e.g. close files, deallocate resources etc.)
0115 }
0116 
0117 //
0118 // member functions
0119 //
0120 
0121 // ------------ method called to for each event  ------------
0122 void OverlapProblemTSOSAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0123   using namespace edm;
0124 
0125   // loop on trajectories and plot TSOS local coordinate
0126 
0127   TrajectoryStateCombiner tsoscomb;
0128 
0129   // Trajectory Handle
0130 
0131   DetIdSelector selector("0x1fbff004-0x14ac1004");
0132 
0133   Handle<TrajTrackAssociationCollection> ttac;
0134   iEvent.getByToken(m_ttacollToken, ttac);
0135 
0136   for (TrajTrackAssociationCollection::const_iterator pair = ttac->begin(); pair != ttac->end(); ++pair) {
0137     const edm::Ref<std::vector<Trajectory> >& traj = pair->key;
0138     const reco::TrackRef& trk = pair->val;
0139     const std::vector<TrajectoryMeasurement>& tmcoll = traj->measurements();
0140 
0141     m_ptrk->Fill(trk->p());
0142     m_etatrk->Fill(trk->eta());
0143 
0144     for (std::vector<TrajectoryMeasurement>::const_iterator meas = tmcoll.begin(); meas != tmcoll.end(); ++meas) {
0145       if (!meas->updatedState().isValid())
0146         continue;
0147 
0148       TrajectoryStateOnSurface tsos = tsoscomb(meas->forwardPredictedState(), meas->backwardPredictedState());
0149       TransientTrackingRecHit::ConstRecHitPointer hit = meas->recHit();
0150 
0151       m_tsoshm.fill(tsos, hit);
0152 
0153       if (!hit->isValid() && m_validOnly)
0154         continue;
0155 
0156       if (m_debug) {
0157         if (selector.isSelected(hit->geographicalId())) {
0158           const SiPixelRecHit* pixelrh = dynamic_cast<const SiPixelRecHit*>(hit->hit());
0159           if (pixelrh) {
0160             edm::LogInfo("ClusterFound") << "Cluster reference" << pixelrh->cluster().key();
0161           } else {
0162             edm::LogInfo("NoCluster") << "No cluster found!";
0163           }
0164         }
0165       }
0166     }
0167   }
0168 }
0169 
0170 void OverlapProblemTSOSAnalyzer::beginRun(const edm::Run& iRun, const edm::EventSetup&) {}
0171 
0172 void OverlapProblemTSOSAnalyzer::endRun(const edm::Run& iRun, const edm::EventSetup&) {}
0173 
0174 //define this as a plug-in
0175 DEFINE_FWK_MODULE(OverlapProblemTSOSAnalyzer);