File indexing completed on 2024-04-06 12:31:58
0001
0002
0003
0004
0005
0006
0007 #include "FWCore/Framework/interface/Frameworkfwd.h"
0008 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0009 #include "FWCore/Framework/interface/ESHandle.h"
0010 #include "FWCore/Framework/interface/MakerMacros.h"
0011 #include "FWCore/Utilities/interface/Exception.h"
0012 #include "FWCore/Framework/interface/Event.h"
0013 #include "FWCore/Framework/interface/EventSetup.h"
0014 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0015
0016 #include "DataFormats/CTPPSDetId/interface/CTPPSDetId.h"
0017
0018 #include "DataFormats/CTPPSReco/interface/CTPPSLocalTrackLite.h"
0019 #include "DataFormats/ProtonReco/interface/ForwardProton.h"
0020 #include "DataFormats/ProtonReco/interface/ForwardProtonFwd.h"
0021
0022 #include "Geometry/Records/interface/VeryForwardRealGeometryRecord.h"
0023 #include "Geometry/VeryForwardGeometryBuilder/interface/CTPPSGeometry.h"
0024
0025 #include "TFile.h"
0026 #include "TGraphErrors.h"
0027 #include "TH1D.h"
0028 #include "TH2D.h"
0029 #include "TProfile.h"
0030
0031
0032
0033 class CTPPSProtonReconstructionDiffPlotter : public edm::one::EDAnalyzer<> {
0034 public:
0035 explicit CTPPSProtonReconstructionDiffPlotter(const edm::ParameterSet &);
0036 ~CTPPSProtonReconstructionDiffPlotter() override {}
0037
0038 private:
0039 void analyze(const edm::Event &, const edm::EventSetup &) override;
0040
0041 void endJob() override;
0042
0043 edm::EDGetTokenT<reco::ForwardProtonCollection> tokenRecoProtonsRef_;
0044 edm::EDGetTokenT<reco::ForwardProtonCollection> tokenRecoProtonsTest_;
0045
0046 std::string outputFile_;
0047
0048 std::unique_ptr<TH1D> h_de_xi, h_de_th_x, h_de_th_y, h_de_vtx_y;
0049 };
0050
0051
0052
0053 using namespace std;
0054 using namespace edm;
0055
0056
0057
0058 CTPPSProtonReconstructionDiffPlotter::CTPPSProtonReconstructionDiffPlotter(const edm::ParameterSet &ps)
0059 : tokenRecoProtonsRef_(consumes<reco::ForwardProtonCollection>(ps.getParameter<InputTag>("tagRecoProtonsRef"))),
0060 tokenRecoProtonsTest_(consumes<reco::ForwardProtonCollection>(ps.getParameter<InputTag>("tagRecoProtonsTest"))),
0061
0062 outputFile_(ps.getParameter<string>("outputFile")),
0063
0064 h_de_xi(new TH1D("", ";#Delta#xi", 200, -0.01, +0.01)),
0065 h_de_th_x(new TH1D("", ";#Delta#theta_{x}", 200, -100E-6, +100E-6)),
0066 h_de_th_y(new TH1D("", ";#Delta#theta_{y}", 200, -100E-6, +100E-6)),
0067 h_de_vtx_y(new TH1D("", ";#Deltay^{*} (cm)", 200, -0.01, +0.01)) {}
0068
0069
0070
0071 void CTPPSProtonReconstructionDiffPlotter::analyze(const edm::Event &event, const edm::EventSetup &iSetup) {
0072
0073 Handle<reco::ForwardProtonCollection> hRecoProtonsRef;
0074 event.getByToken(tokenRecoProtonsRef_, hRecoProtonsRef);
0075
0076 Handle<reco::ForwardProtonCollection> hRecoProtonsTest;
0077 event.getByToken(tokenRecoProtonsTest_, hRecoProtonsTest);
0078
0079 if (hRecoProtonsRef->size() != hRecoProtonsTest->size()) {
0080 edm::LogWarning("CTPPSProtonReconstructionDiffPlotter::analyze")
0081 << "Different number of Ref and Test protons. Skipping event.";
0082 return;
0083 }
0084
0085 for (unsigned int i = 0; i < hRecoProtonsRef->size(); ++i) {
0086 const auto &pr_ref = hRecoProtonsRef->at(i);
0087 const auto &pr_test = hRecoProtonsTest->at(i);
0088
0089 if (!pr_ref.validFit() || !pr_test.validFit())
0090 continue;
0091
0092 h_de_xi->Fill(pr_test.xi() - pr_ref.xi());
0093 h_de_th_x->Fill(pr_test.thetaX() - pr_ref.thetaX());
0094 h_de_th_y->Fill(pr_test.thetaY() - pr_ref.thetaY());
0095 h_de_vtx_y->Fill(pr_test.vy() - pr_ref.vy());
0096 }
0097 }
0098
0099
0100
0101 void CTPPSProtonReconstructionDiffPlotter::endJob() {
0102 auto f_out = std::make_unique<TFile>(outputFile_.c_str(), "recreate");
0103
0104 h_de_xi->Write("h_de_xi");
0105 h_de_th_x->Write("h_de_th_x");
0106 h_de_th_y->Write("h_de_th_y");
0107 h_de_vtx_y->Write("h_de_vtx_y");
0108 }
0109
0110
0111
0112 DEFINE_FWK_MODULE(CTPPSProtonReconstructionDiffPlotter);