CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
CTPPSDirectProtonSimulationValidator.cc
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * This is a part of CTPPS validation software
4  * Authors:
5  * Jan Kašpar
6  * Laurent Forthomme
7  *
8  ****************************************************************************/
9 
12 
15 
17 
21 
22 #include "TFile.h"
23 #include "TH1D.h"
24 #include "TH2D.h"
25 
26 #include <map>
27 
28 //----------------------------------------------------------------------------------------------------
29 
31 public:
33 
34 private:
35  void beginJob() override {}
36  void analyze(const edm::Event&, const edm::EventSetup&) override;
37  void endJob() override;
38 
41 
43 
44  struct RPPlots {
45  std::unique_ptr<TH2D> h2_xr_vs_xs, h2_yr_vs_ys;
46  std::unique_ptr<TH1D> h_de_x, h_de_y;
47 
49  : h2_xr_vs_xs(new TH2D("", ";x_simu (mm);x_reco (mm)", 100, -10., +10., 100, -10, +10.)),
50  h2_yr_vs_ys(new TH2D("", "y_simu (mm);y_reco (mm)", 100, -10., +10., 100, -10, +10.)),
51  h_de_x(new TH1D("", ";x (mm)", 200, -100E-3, +100E-3)),
52  h_de_y(new TH1D("", ";y (mm)", 200, -100E-3, +100E-3)) {}
53 
54  void fill(double simu_x, double simu_y, double reco_x, double reco_y) {
55  h2_xr_vs_xs->Fill(simu_x, reco_x);
56  h2_yr_vs_ys->Fill(simu_y, reco_y);
57 
58  h_de_x->Fill(reco_x - simu_x);
59  h_de_y->Fill(reco_y - simu_y);
60  }
61 
62  void write() const {
63  h2_xr_vs_xs->Write("h2_xr_vs_xs");
64  h2_yr_vs_ys->Write("h2_yr_vs_ys");
65  h_de_x->Write("h_de_x");
66  h_de_y->Write("h_de_y");
67  }
68  };
69 
70  std::map<unsigned int, RPPlots> rpPlots_;
71 };
72 
73 //----------------------------------------------------------------------------------------------------
74 
76  : simuTracksToken_(consumes<CTPPSLocalTrackLiteCollection>(iConfig.getParameter<edm::InputTag>("simuTracksTag"))),
77  recoTracksToken_(consumes<CTPPSLocalTrackLiteCollection>(iConfig.getParameter<edm::InputTag>("recoTracksTag"))),
78  outputFile_(iConfig.getParameter<std::string>("outputFile")) {}
79 
80 //----------------------------------------------------------------------------------------------------
81 
83  // get input
85  iEvent.getByToken(simuTracksToken_, simuTracks);
86 
88  iEvent.getByToken(recoTracksToken_, recoTracks);
89 
90  // process tracks
91  for (const auto& simuTrack : *simuTracks) {
92  const CTPPSDetId rpId(simuTrack.rpId());
93  for (const auto& recoTrack : *recoTracks) {
94  if (simuTrack.rpId() == recoTrack.rpId()) {
95  unsigned int rpDecId = rpId.arm() * 100 + rpId.station() * 10 + rpId.rp();
96  rpPlots_[rpDecId].fill(simuTrack.x(), simuTrack.y(), recoTrack.x(), recoTrack.y());
97  }
98  }
99  }
100 }
101 
102 //----------------------------------------------------------------------------------------------------
103 
105  auto f_out = std::make_unique<TFile>(outputFile_.c_str(), "recreate");
106 
107  for (const auto& it : rpPlots_) {
108  gDirectory = f_out->mkdir(Form("RP %u", it.first));
109  it.second.write();
110  }
111 }
112 
113 //----------------------------------------------------------------------------------------------------
114 
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
int iEvent
Definition: GenABIO.cc:224
void analyze(const edm::Event &, const edm::EventSetup &) override
uint32_t arm() const
Definition: CTPPSDetId.h:51
std::vector< CTPPSLocalTrackLite > CTPPSLocalTrackLiteCollection
Collection of CTPPSLocalTrackLite objects.
edm::EDGetTokenT< CTPPSLocalTrackLiteCollection > recoTracksToken_
edm::EDGetTokenT< CTPPSLocalTrackLiteCollection > simuTracksToken_
Base class for CTPPS detector IDs.
Definition: CTPPSDetId.h:32
void fill(double simu_x, double simu_y, double reco_x, double reco_y)