File indexing completed on 2023-03-17 11:14:00
0001 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0002 #include "FWCore/Framework/interface/Run.h"
0003 #include "FWCore/Framework/interface/Event.h"
0004 #include "FWCore/Framework/interface/EventSetup.h"
0005 #include "FWCore/Framework/interface/MakerMacros.h"
0006 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0007 #include "FWCore/ServiceRegistry/interface/Service.h"
0008 #include "CommonTools/UtilAlgos/interface/TFileService.h"
0009 #include "FWCore/Utilities/interface/EDGetToken.h"
0010 #include "FWCore/Utilities/interface/InputTag.h"
0011 #include "FWCore/Utilities/interface/Exception.h"
0012 #include "DataFormats/Common/interface/Handle.h"
0013
0014 #include "SimTracker/TrackTriggerAssociation/interface/StubAssociation.h"
0015 #include "L1Trigger/TrackTrigger/interface/Setup.h"
0016
0017 #include <TProfile.h>
0018 #include <TH1F.h>
0019
0020 using namespace std;
0021 using namespace edm;
0022 using namespace tt;
0023
0024 namespace trklet {
0025
0026
0027
0028
0029
0030
0031 class AnalyzerTT : public one::EDAnalyzer<one::WatchRuns, one::SharedResources> {
0032 public:
0033 AnalyzerTT(const ParameterSet& iConfig);
0034 void beginJob() override {}
0035 void beginRun(const Run& iEvent, const EventSetup& iSetup) override;
0036 void analyze(const Event& iEvent, const EventSetup& iSetup) override;
0037 void endRun(const Run& iEvent, const EventSetup& iSetup) override {}
0038 void endJob() override {}
0039
0040 private:
0041
0042 EDGetTokenT<TTTrackRefMap> edGetTokenTTTrackMap_;
0043
0044 EDGetTokenT<StubAssociation> edGetTokenStubAssociation_;
0045
0046 ESGetToken<Setup, SetupRcd> esGetTokenSetup_;
0047
0048 const Setup* setup_ = nullptr;
0049
0050
0051
0052 TH1F* hisQoverPt_;
0053 TH1F* hisPhi0_;
0054 TH1F* hisEta_;
0055 TH1F* hisZ0_;
0056 TProfile* profResQoverPtOverEta_;
0057 TProfile* profResPhi0OverEta_;
0058 TProfile* profResEtaOverEta_;
0059 TProfile* profResZ0OverEta_;
0060 };
0061
0062 AnalyzerTT::AnalyzerTT(const ParameterSet& iConfig) {
0063 usesResource("TFileService");
0064
0065 const auto& label = iConfig.getParameter<string>("LabelAS");
0066 const auto& branch = iConfig.getParameter<string>("BranchAcceptedTracks");
0067 const auto& inputTag = iConfig.getParameter<InputTag>("InputTagSelection");
0068 edGetTokenTTTrackMap_ = consumes<TTTrackRefMap>(InputTag(label, branch));
0069 edGetTokenStubAssociation_ = consumes<StubAssociation>(inputTag);
0070
0071 esGetTokenSetup_ = esConsumes<Setup, SetupRcd, Transition::BeginRun>();
0072 }
0073
0074 void AnalyzerTT::beginRun(const Run& iEvent, const EventSetup& iSetup) {
0075
0076 setup_ = &iSetup.getData(esGetTokenSetup_);
0077
0078 Service<TFileService> fs;
0079 TFileDirectory dir;
0080 dir = fs->mkdir("TT");
0081 hisQoverPt_ = dir.make<TH1F>("His qOverPt", ";", 100, -1., 1.);
0082 hisPhi0_ = dir.make<TH1F>("His phi0", ";", 100, -M_PI, M_PI);
0083 hisEta_ = dir.make<TH1F>("His eta", ";", 100, -2.5, 2.5);
0084 hisZ0_ = dir.make<TH1F>("His z0", ";", 100, -20., 20.);
0085 profResQoverPtOverEta_ = dir.make<TProfile>("Prof Res qOverPt over |eta|", ";", 100, 0., 2.5);
0086 profResPhi0OverEta_ = dir.make<TProfile>("Prof Res phi0 over |eta|", ";", 100, 0., 2.5);
0087 profResEtaOverEta_ = dir.make<TProfile>("Prof Res eta over |eta|", ";", 100, 0., 2.5);
0088 profResZ0OverEta_ = dir.make<TProfile>("Prof Res z0 over |eta|", ";", 100, 0., 2.5);
0089 }
0090
0091 void AnalyzerTT::analyze(const Event& iEvent, const EventSetup& iSetup) {
0092 Handle<TTTrackRefMap> handleTTTrackMap;
0093 iEvent.getByToken<TTTrackRefMap>(edGetTokenTTTrackMap_, handleTTTrackMap);
0094 Handle<StubAssociation> handleStubAssociation;
0095 iEvent.getByToken<StubAssociation>(edGetTokenStubAssociation_, handleStubAssociation);
0096 for (const auto& p : *handleTTTrackMap) {
0097 const TTTrackRef& ttTrackRef = p.first;
0098 const vector<TTStubRef>& ttStubRefs = ttTrackRef->getStubRefs();
0099 const vector<TPPtr>& tpPtrs = handleStubAssociation->associate(ttStubRefs);
0100 if (tpPtrs.empty())
0101 continue;
0102 const TPPtr& tpPtr = tpPtrs.front();
0103 const math::XYZPointD& v = tpPtr->vertex();
0104 const double qOverPtTT = ttTrackRef->rInv() / setup_->invPtToDphi() / 2.0;
0105 const double qOverPtTP = tpPtr->charge() / tpPtr->pt();
0106 const double qOverPtDiff = qOverPtTP - qOverPtTT;
0107 const double phi0TT = deltaPhi(ttTrackRef->phi() + ttTrackRef->phiSector() * setup_->baseRegion());
0108 const double phi0TP = tpPtr->phi();
0109 const double phi0Diff = phi0TP - phi0TT;
0110 const double etaTT = asinh(ttTrackRef->tanL());
0111 const double etaTP = tpPtr->eta();
0112 const double etaDiff = etaTP - etaTT;
0113 const double z0TT = ttTrackRef->z0();
0114 const double z0TP = v.z() - sinh(tpPtr->eta()) * (v.x() * cos(tpPtr->phi()) + v.y() * sin(tpPtr->phi()));
0115 const double z0Diff = z0TP - z0TT;
0116 hisQoverPt_->Fill(qOverPtTT);
0117 hisPhi0_->Fill(phi0TT);
0118 hisEta_->Fill(etaTT);
0119 hisZ0_->Fill(z0TT);
0120 profResQoverPtOverEta_->Fill(abs(etaTP), abs(qOverPtDiff));
0121 profResPhi0OverEta_->Fill(abs(etaTP), abs(phi0Diff));
0122 profResEtaOverEta_->Fill(abs(etaTP), abs(etaDiff));
0123 profResZ0OverEta_->Fill(abs(etaTP), abs(z0Diff));
0124 }
0125 }
0126
0127 }
0128
0129 DEFINE_FWK_MODULE(trklet::AnalyzerTT);