CMS 3D CMS Logo

CTPPSOpticsPlotter.cc
Go to the documentation of this file.
1 /****************************************************************************
2  * Authors:
3  * Jan Kašpar
4  ****************************************************************************/
5 
10 
13 
15 
18 
19 #include "TFile.h"
20 #include "TGraph.h"
21 
22 #include <map>
23 #include <string>
24 
25 //----------------------------------------------------------------------------------------------------
26 
28 public:
29  explicit CTPPSOpticsPlotter(const edm::ParameterSet&);
30 
31 private:
32  void analyze(const edm::Event&, const edm::EventSetup&) override;
33  void endJob() override;
34 
36 
37  unsigned int rpId_45_N_, rpId_45_F_;
38  unsigned int rpId_56_N_, rpId_56_F_;
39 
41 
42  struct RPPlots {
43  std::unique_ptr<TGraph> g_v_x_vs_xi, g_L_x_vs_xi, g_x_D_vs_xi;
44  std::unique_ptr<TGraph> g_v_y_vs_xi, g_L_y_vs_xi, g_y_D_vs_xi;
45  std::unique_ptr<TGraph> h_y_vs_x_disp;
46 
47  RPPlots()
48  : g_v_x_vs_xi(new TGraph),
49  g_L_x_vs_xi(new TGraph),
50  g_x_D_vs_xi(new TGraph),
51  g_v_y_vs_xi(new TGraph),
52  g_L_y_vs_xi(new TGraph),
53  g_y_D_vs_xi(new TGraph),
54  h_y_vs_x_disp(new TGraph) {}
55 
56  void write() const {
57  g_v_x_vs_xi->SetTitle(";xi;v_{x}");
58  g_v_x_vs_xi->Write("g_v_x_vs_xi");
59 
60  g_L_x_vs_xi->SetTitle(";xi;L_{x} (cm)");
61  g_L_x_vs_xi->Write("g_L_x_vs_xi");
62 
63  g_x_D_vs_xi->SetTitle(";xi;x_{D} (cm)");
64  g_x_D_vs_xi->Write("g_x_D_vs_xi");
65 
66  g_v_y_vs_xi->SetTitle(";xi;v_{y}");
67  g_v_y_vs_xi->Write("g_v_y_vs_xi");
68 
69  g_L_y_vs_xi->SetTitle(";xi;L_{y} (cm)");
70  g_L_y_vs_xi->Write("g_L_y_vs_xi");
71 
72  g_y_D_vs_xi->SetTitle(";xi;y_{D} (cm)");
73  g_y_D_vs_xi->Write("g_y_D_vs_xi");
74 
75  h_y_vs_x_disp->SetTitle(";x (cm);y (cm)");
76  h_y_vs_x_disp->Write("h_y_vs_x_disp");
77  }
78  };
79 
80  std::map<unsigned int, RPPlots> rp_plots_;
81 
82  struct ArmPlots {
83  unsigned int id_N, id_F;
84 
85  std::unique_ptr<TGraph> g_de_x_vs_x_disp, g_de_y_vs_x_disp;
86 
87  ArmPlots() : g_de_x_vs_x_disp(new TGraph), g_de_y_vs_x_disp(new TGraph) {}
88 
89  void write() const {
90  g_de_x_vs_x_disp->SetTitle(";x_N (cm);x_F - x_N (cm)");
91  g_de_x_vs_x_disp->Write("g_de_x_vs_x_disp");
92 
93  g_de_y_vs_x_disp->SetTitle(";x_N (cm);y_F - y_N (cm)");
94  g_de_y_vs_x_disp->Write("g_de_y_vs_x_disp");
95  }
96  };
97 
98  std::map<unsigned int, ArmPlots> arm_plots_;
99 };
100 
101 //----------------------------------------------------------------------------------------------------
102 
103 using namespace std;
104 using namespace edm;
105 
106 //----------------------------------------------------------------------------------------------------
107 
109  : opticsLabel_(iConfig.getParameter<std::string>("opticsLabel")),
110 
111  rpId_45_N_(iConfig.getParameter<unsigned int>("rpId_45_N")),
112  rpId_45_F_(iConfig.getParameter<unsigned int>("rpId_45_F")),
113  rpId_56_N_(iConfig.getParameter<unsigned int>("rpId_56_N")),
114  rpId_56_F_(iConfig.getParameter<unsigned int>("rpId_56_F")),
115 
116  outputFile_(iConfig.getParameter<string>("outputFile")) {
117  arm_plots_[0].id_N = rpId_45_N_;
118  arm_plots_[0].id_F = rpId_45_F_;
119 
120  arm_plots_[1].id_N = rpId_56_N_;
121  arm_plots_[1].id_F = rpId_56_F_;
122 }
123 
124 //----------------------------------------------------------------------------------------------------
125 
126 void CTPPSOpticsPlotter::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
127  // stop if plots already made
128  if (!rp_plots_.empty())
129  return;
130 
131  // get conditions
133  iSetup.get<CTPPSInterpolatedOpticsRcd>().get(opticsLabel_, hOpticalFunctions);
134 
135  // stop if conditions invalid
136  if (hOpticalFunctions->empty())
137  return;
138 
139  // make per-RP plots
140  for (const auto& it : *hOpticalFunctions) {
141  CTPPSDetId rpId(it.first);
142  unsigned int rpDecId = rpId.arm() * 100 + rpId.station() * 10 + rpId.rp();
143 
144  auto& pl = rp_plots_[rpDecId];
145 
146  LHCInterpolatedOpticalFunctionsSet::Kinematics k_in_beam = {0., 0., 0., 0., 0.};
148  it.second.transport(k_in_beam, k_out_beam);
149 
150  const double vtx_ep = 1E-4; // cm
151  const double th_ep = 1E-6; // rad
152 
153  for (double xi = 0.; xi < 0.30001; xi += 0.001) {
154  LHCInterpolatedOpticalFunctionsSet::Kinematics k_in_xi = {0., 0., 0., 0., xi};
156  it.second.transport(k_in_xi, k_out_xi);
157 
158  LHCInterpolatedOpticalFunctionsSet::Kinematics k_in_xi_vtx_x = {vtx_ep, 0., 0., 0., xi};
160  it.second.transport(k_in_xi_vtx_x, k_out_xi_vtx_x);
161 
162  LHCInterpolatedOpticalFunctionsSet::Kinematics k_in_xi_th_x = {0., th_ep, 0., 0., xi};
164  it.second.transport(k_in_xi_th_x, k_out_xi_th_x);
165 
166  LHCInterpolatedOpticalFunctionsSet::Kinematics k_in_xi_vtx_y = {0., 0., vtx_ep, 0., xi};
168  it.second.transport(k_in_xi_vtx_y, k_out_xi_vtx_y);
169 
170  LHCInterpolatedOpticalFunctionsSet::Kinematics k_in_xi_th_y = {0., 0., 0., th_ep, xi};
172  it.second.transport(k_in_xi_th_y, k_out_xi_th_y);
173 
174  int idx = pl.g_v_x_vs_xi->GetN();
175 
176  pl.g_v_x_vs_xi->SetPoint(idx, xi, (k_out_xi_vtx_x.x - k_out_xi.x) / vtx_ep);
177  pl.g_L_x_vs_xi->SetPoint(idx, xi, (k_out_xi_th_x.x - k_out_xi.x) / th_ep);
178  pl.g_x_D_vs_xi->SetPoint(idx, xi, k_out_xi.x - k_out_beam.x);
179 
180  pl.g_v_y_vs_xi->SetPoint(idx, xi, (k_out_xi_vtx_y.y - k_out_xi.y) / vtx_ep);
181  pl.g_L_y_vs_xi->SetPoint(idx, xi, (k_out_xi_th_y.y - k_out_xi.y) / th_ep);
182  pl.g_y_D_vs_xi->SetPoint(idx, xi, k_out_xi.y - k_out_beam.y);
183 
184  pl.h_y_vs_x_disp->SetPoint(idx, k_out_xi.x - k_out_beam.x, k_out_xi.y - k_out_beam.y);
185  }
186  }
187 
188  // make per-arm plots
189  for (const auto& ap : arm_plots_) {
190  // find optics objects
191  const LHCInterpolatedOpticalFunctionsSet *opt_N = nullptr, *opt_F = nullptr;
192 
193  for (const auto& it : *hOpticalFunctions) {
194  CTPPSDetId rpId(it.first);
195  unsigned int rpDecId = rpId.arm() * 100 + rpId.station() * 10 + rpId.rp();
196 
197  if (rpDecId == ap.second.id_N)
198  opt_N = &it.second;
199  if (rpDecId == ap.second.id_F)
200  opt_F = &it.second;
201  }
202 
203  if (!opt_N || !opt_F) {
204  edm::LogError("CTPPSOpticsPlotter::analyze") << "Cannot find optics objects for arm " << ap.first;
205  continue;
206  }
207 
208  LHCInterpolatedOpticalFunctionsSet::Kinematics k_in_beam = {0., 0., 0., 0., 0.};
209 
210  LHCInterpolatedOpticalFunctionsSet::Kinematics k_out_beam_N, k_out_beam_F;
211  opt_N->transport(k_in_beam, k_out_beam_N);
212  opt_F->transport(k_in_beam, k_out_beam_F);
213 
214  for (double xi = 0.; xi < 0.30001; xi += 0.001) {
215  LHCInterpolatedOpticalFunctionsSet::Kinematics k_in_xi = {0., 0., 0., 0., xi};
216 
217  LHCInterpolatedOpticalFunctionsSet::Kinematics k_out_xi_N, k_out_xi_F;
218  opt_N->transport(k_in_xi, k_out_xi_N);
219  opt_F->transport(k_in_xi, k_out_xi_F);
220 
221  int idx = ap.second.g_de_x_vs_x_disp->GetN();
222 
223  ap.second.g_de_x_vs_x_disp->SetPoint(
224  idx, k_out_xi_N.x - k_out_beam_N.x, (k_out_xi_F.x - k_out_beam_F.x) - (k_out_xi_N.x - k_out_beam_N.x));
225  ap.second.g_de_y_vs_x_disp->SetPoint(
226  idx, k_out_xi_N.x - k_out_beam_N.x, (k_out_xi_F.y - k_out_beam_F.y) - (k_out_xi_N.y - k_out_beam_N.y));
227  }
228  }
229 }
230 
231 //----------------------------------------------------------------------------------------------------
232 
234  auto f_out = std::make_unique<TFile>(outputFile_.c_str(), "recreate");
235 
236  for (const auto& p : rp_plots_) {
237  gDirectory = f_out->mkdir(Form("%u", p.first));
238  p.second.write();
239  }
240 
241  for (const auto& p : arm_plots_) {
242  gDirectory = f_out->mkdir(Form("arm %u", p.first));
243  p.second.write();
244  }
245 }
246 
247 //----------------------------------------------------------------------------------------------------
248 
CTPPSOpticsPlotter::RPPlots::write
void write() const
Definition: CTPPSOpticsPlotter.cc:57
CTPPSOpticsPlotter::ArmPlots::id_F
unsigned int id_F
Definition: CTPPSOpticsPlotter.cc:84
CTPPSOpticsPlotter::RPPlots::g_x_D_vs_xi
std::unique_ptr< TGraph > g_x_D_vs_xi
Definition: CTPPSOpticsPlotter.cc:44
EDAnalyzer.h
CTPPSOpticsPlotter::analyze
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: CTPPSOpticsPlotter.cc:125
LHCInterpolatedOpticalFunctionsSet::Kinematics
proton kinematics description
Definition: LHCInterpolatedOpticalFunctionsSet.h:28
ESHandle.h
CTPPSOpticsPlotter::ArmPlots::g_de_y_vs_x_disp
std::unique_ptr< TGraph > g_de_y_vs_x_disp
Definition: CTPPSOpticsPlotter.cc:86
edm
HLT enums.
Definition: AlignableModifier.h:19
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
CTPPSOpticsPlotter
Definition: CTPPSOpticsPlotter.cc:26
hybridSuperClusters_cfi.xi
xi
Definition: hybridSuperClusters_cfi.py:10
CTPPSOpticsPlotter::RPPlots::RPPlots
RPPlots()
Definition: CTPPSOpticsPlotter.cc:48
CTPPSOpticsPlotter::rpId_45_F_
unsigned int rpId_45_F_
Definition: CTPPSOpticsPlotter.cc:38
edm::one::EDAnalyzer
Definition: EDAnalyzer.h:30
year_2016_postTS2_cff.rpId
rpId
Definition: year_2016_postTS2_cff.py:23
CTPPSOpticsPlotter::rpId_56_F_
unsigned int rpId_56_F_
Definition: CTPPSOpticsPlotter.cc:39
CTPPSOpticsPlotter::RPPlots::g_L_y_vs_xi
std::unique_ptr< TGraph > g_L_y_vs_xi
Definition: CTPPSOpticsPlotter.cc:45
heavyIonCSV_trainingSettings.idx
idx
Definition: heavyIonCSV_trainingSettings.py:5
CTPPSOpticsPlotter::ArmPlots::write
void write() const
Definition: CTPPSOpticsPlotter.cc:90
CTPPSOpticsPlotter::endJob
void endJob() override
Definition: CTPPSOpticsPlotter.cc:232
MakerMacros.h
CTPPSOpticsPlotter::RPPlots::h_y_vs_x_disp
std::unique_ptr< TGraph > h_y_vs_x_disp
Definition: CTPPSOpticsPlotter.cc:46
edm::EventSetup::get
T get() const
Definition: EventSetup.h:80
CTPPSOpticsPlotter::rpId_56_N_
unsigned int rpId_56_N_
Definition: CTPPSOpticsPlotter.cc:39
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
LHCInterpolatedOpticalFunctionsSet::Kinematics::y
double y
Definition: LHCInterpolatedOpticalFunctionsSet.h:31
CTPPSOpticsPlotter::ArmPlots
Definition: CTPPSOpticsPlotter.cc:83
edm::ESHandle< LHCInterpolatedOpticalFunctionsSetCollection >
LHCInterpolatedOpticalFunctionsSetCollection.h
LHCInterpolatedOpticalFunctionsSet::Kinematics::x
double x
Definition: LHCInterpolatedOpticalFunctionsSet.h:29
CTPPSOpticsPlotter::ArmPlots::id_N
unsigned int id_N
Definition: CTPPSOpticsPlotter.cc:84
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
CTPPSOpticsPlotter::rp_plots_
std::map< unsigned int, RPPlots > rp_plots_
Definition: CTPPSOpticsPlotter.cc:81
LHCInterpolatedOpticalFunctionsSet
Set of optical functions corresponding to one scoring plane along LHC, including splines for interpol...
Definition: LHCInterpolatedOpticalFunctionsSet.h:14
edm::ParameterSet
Definition: ParameterSet.h:47
CTPPSOpticsPlotter::outputFile_
std::string outputFile_
Definition: CTPPSOpticsPlotter.cc:41
Event.h
CTPPSOpticsPlotter::RPPlots::g_L_x_vs_xi
std::unique_ptr< TGraph > g_L_x_vs_xi
Definition: CTPPSOpticsPlotter.cc:44
CTPPSDetId
Base class for CTPPS detector IDs.
Definition: CTPPSDetId.h:31
createfilelist.int
int
Definition: createfilelist.py:10
iEvent
int iEvent
Definition: GenABIO.cc:224
CTPPSInterpolatedOpticsRcd.h
CTPPSOpticsPlotter::rpId_45_N_
unsigned int rpId_45_N_
Definition: CTPPSOpticsPlotter.cc:38
CTPPSOpticsPlotter::RPPlots::g_v_y_vs_xi
std::unique_ptr< TGraph > g_v_y_vs_xi
Definition: CTPPSOpticsPlotter.cc:45
edm::EventSetup
Definition: EventSetup.h:57
CTPPSOpticsPlotter::opticsLabel_
std::string opticsLabel_
Definition: CTPPSOpticsPlotter.cc:36
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
get
#define get
CTPPSOpticsPlotter::ArmPlots::ArmPlots
ArmPlots()
Definition: CTPPSOpticsPlotter.cc:88
CTPPSOpticsPlotter::RPPlots::g_y_D_vs_xi
std::unique_ptr< TGraph > g_y_D_vs_xi
Definition: CTPPSOpticsPlotter.cc:45
CTPPSOpticsPlotter::CTPPSOpticsPlotter
CTPPSOpticsPlotter(const edm::ParameterSet &)
Definition: CTPPSOpticsPlotter.cc:107
CTPPSOpticsPlotter::RPPlots::g_v_x_vs_xi
std::unique_ptr< TGraph > g_v_x_vs_xi
Definition: CTPPSOpticsPlotter.cc:44
std
Definition: JetResolutionObject.h:76
CTPPSOpticsPlotter::arm_plots_
std::map< unsigned int, ArmPlots > arm_plots_
Definition: CTPPSOpticsPlotter.cc:99
Frameworkfwd.h
CTPPSOpticsPlotter::RPPlots
Definition: CTPPSOpticsPlotter.cc:43
EventSetup.h
CTPPSDetId.h
CTPPSOpticsPlotter::ArmPlots::g_de_x_vs_x_disp
std::unique_ptr< TGraph > g_de_x_vs_x_disp
Definition: CTPPSOpticsPlotter.cc:86
LHCInterpolatedOpticalFunctionsSet::transport
void transport(const Kinematics &input, Kinematics &output, bool calculateAngles=false) const
transports proton according to the splines
Definition: LHCInterpolatedOpticalFunctionsSet.cc:17
edm::Event
Definition: Event.h:73
CTPPSInterpolatedOpticsRcd
Definition: CTPPSInterpolatedOpticsRcd.h:13