File indexing completed on 2023-03-17 11:13:37
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/Utilities/interface/EDGetToken.h"
0008 #include "FWCore/Utilities/interface/InputTag.h"
0009 #include "FWCore/Utilities/interface/Exception.h"
0010 #include "DataFormats/Common/interface/Handle.h"
0011
0012 #include "SimTracker/TrackTriggerAssociation/interface/StubAssociation.h"
0013 #include "L1Trigger/TrackTrigger/interface/Setup.h"
0014
0015 using namespace std;
0016 using namespace edm;
0017 using namespace tt;
0018
0019 namespace trackerTFP {
0020
0021
0022
0023
0024
0025
0026 class AnalyzerTT : public one::EDAnalyzer<one::WatchRuns> {
0027 public:
0028 AnalyzerTT(const ParameterSet& iConfig);
0029 void beginJob() override {}
0030 void beginRun(const Run& iEvent, const EventSetup& iSetup) override;
0031 void analyze(const Event& iEvent, const EventSetup& iSetup) override;
0032 void endRun(const Run& iEvent, const EventSetup& iSetup) override {}
0033 void endJob() override {}
0034
0035 private:
0036
0037 EDGetTokenT<tt::TTTrackRefMap> edGetTokenTTTrackMap_;
0038
0039 EDGetTokenT<StubAssociation> edGetTokenStubAssociation_;
0040
0041 ESGetToken<Setup, SetupRcd> esGetTokenSetup_;
0042
0043 const Setup* setup_ = nullptr;
0044 };
0045
0046 AnalyzerTT::AnalyzerTT(const ParameterSet& iConfig) {
0047
0048 const auto& label = iConfig.getParameter<string>("LabelAS");
0049 const auto& branch = iConfig.getParameter<string>("BranchAcceptedTracks");
0050 const auto& inputTag = iConfig.getParameter<InputTag>("InputTagSelection");
0051 edGetTokenTTTrackMap_ = consumes<tt::TTTrackRefMap>(InputTag(label, branch));
0052 edGetTokenStubAssociation_ = consumes<StubAssociation>(inputTag);
0053
0054 esGetTokenSetup_ = esConsumes<Setup, SetupRcd, Transition::BeginRun>();
0055 }
0056
0057 void AnalyzerTT::beginRun(const Run& iEvent, const EventSetup& iSetup) {
0058
0059 setup_ = &iSetup.getData(esGetTokenSetup_);
0060 }
0061
0062 void AnalyzerTT::analyze(const Event& iEvent, const EventSetup& iSetup) {
0063 Handle<tt::TTTrackRefMap> handleTTTrackMap;
0064 iEvent.getByToken<tt::TTTrackRefMap>(edGetTokenTTTrackMap_, handleTTTrackMap);
0065 Handle<StubAssociation> handleStubAssociation;
0066 iEvent.getByToken<StubAssociation>(edGetTokenStubAssociation_, handleStubAssociation);
0067 if (false)
0068 return;
0069 for (const auto& p : *handleTTTrackMap) {
0070 const TTTrackRef& found = p.second;
0071 const TTTrackRef& fitted = p.first;
0072 const vector<TTStubRef>& ttStubRefsFound = found->getStubRefs();
0073 const vector<TPPtr>& tpPtrsFound = handleStubAssociation->associate(ttStubRefsFound);
0074 if (tpPtrsFound.empty())
0075 continue;
0076 const vector<TTStubRef>& ttStubRefsFitted = fitted->getStubRefs();
0077 const vector<TPPtr>& tpPtrsFitted = handleStubAssociation->associate(ttStubRefsFitted);
0078 if (!tpPtrsFitted.empty())
0079 continue;
0080 const TPPtr& tpPtr = tpPtrsFound.front();
0081 const double off = (found->phiSector() - .5) * 2. * M_PI / setup_->numRegions() / setup_->numSectorsPhi();
0082 cout << setprecision(8);
0083 cout << found->phiSector() << " " << found->etaSector() << " " << endl;
0084 cout << "Found" << endl;
0085 for (const TTStubRef& ttStubRef : ttStubRefsFound) {
0086 const GlobalPoint& gp = setup_->stubPos(ttStubRef);
0087 cout << gp.perp() << " " << gp.phi() << " " << gp.z() << " " << setup_->layerId(ttStubRef) << endl;
0088 }
0089 cout << "Fitted" << endl;
0090 for (const TTStubRef& ttStubRef : ttStubRefsFitted) {
0091 const GlobalPoint& gp = setup_->stubPos(ttStubRef);
0092 cout << gp.perp() << " " << gp.phi() << " " << gp.z() << " " << setup_->layerId(ttStubRef) << endl;
0093 }
0094 cout << "TP" << endl;
0095 for (const TTStubRef& ttStubRef : handleStubAssociation->findTTStubRefs(tpPtr)) {
0096 const GlobalPoint& gp = setup_->stubPos(ttStubRef);
0097 cout << gp.perp() << " " << gp.phi() << " " << gp.z() << " " << setup_->layerId(ttStubRef) << endl;
0098 }
0099 cout << found->hitPattern() << " " << found->trackSeedType() << endl;
0100 cout << "m0SF = "
0101 << " " << -found->rInv() << endl;
0102 cout << "c0SF = "
0103 << " " << deltaPhi(found->phi() + found->rInv() * setup_->chosenRofPhi() + off) << endl;
0104 cout << "m1SF = "
0105 << " " << found->tanL() + setup_->sectorCot(found->etaSector()) << endl;
0106 cout << "c1SF = "
0107 << " " << found->z0() - found->tanL() * setup_->chosenRofZ() << endl;
0108 cout << "m0KF = "
0109 << " " << -fitted->rInv() * setup_->invPtToDphi() << endl;
0110 cout << "c0KF = "
0111 << " " << fitted->phi() << endl;
0112 cout << "m1KF = "
0113 << " " << fitted->tanL() << endl;
0114 cout << "c1KF = "
0115 << " " << fitted->z0() << endl;
0116 cout << "m0TP = "
0117 << " " << -tpPtr->charge() / tpPtr->pt() * setup_->invPtToDphi() << endl;
0118 cout << "c0TP = "
0119 << " " << tpPtr->phi() << endl;
0120 cout << "m1TP = "
0121 << " " << sinh(tpPtr->eta()) << endl;
0122 const math::XYZPointD& v = tpPtr->vertex();
0123 cout << "c1TP = "
0124 << " " << v.z() - sinh(tpPtr->eta()) * (v.x() * cos(tpPtr->phi()) + v.y() * sin(tpPtr->phi())) << endl;
0125 throw cms::Exception("...");
0126 }
0127 }
0128
0129 }
0130
0131 DEFINE_FWK_MODULE(trackerTFP::AnalyzerTT);