CMS 3D CMS Logo

CTPPSProtonReconstructionEfficiencyEstimatorData.cc
Go to the documentation of this file.
1 /****************************************************************************
2  * Authors:
3  * Jan Kašpar
4  * Mauricio Thiel
5  ****************************************************************************/
6 
14 
17 
19 
24 
25 #include "TFile.h"
26 #include "TH1D.h"
27 #include "TH2D.h"
28 #include "TProfile.h"
29 #include "TF1.h"
30 #include "TGraph.h"
31 
32 #include <map>
33 #include <string>
34 #include <sstream>
35 
36 //----------------------------------------------------------------------------------------------------
37 
39 public:
41 
42  static void fillDescriptions(edm::ConfigurationDescriptions &descriptions);
43 
44 private:
45  void analyze(const edm::Event &, const edm::EventSetup &) override;
46  void endJob() override;
47 
51 
53 
55 
56  unsigned int n_prep_events_;
57 
58  unsigned int n_exp_prot_max_;
59 
60  std::vector<double> n_sigmas_;
61 
63 
64  unsigned int verbosity_;
65 
67 
68  struct ArmData {
69  unsigned int rpId_N, rpId_F;
70 
71  std::shared_ptr<const TSpline3> s_x_to_xi_N;
72 
73  unsigned int n_events_with_tracks;
74 
75  std::unique_ptr<TH1D> h_de_x, h_de_y;
76  std::unique_ptr<TH2D> h2_de_y_vs_de_x;
77 
79  double de_y_mean, de_y_sigma;
80 
81  std::vector<double> n_sigmas;
82 
83  unsigned int n_exp_prot_max;
84 
85  struct EffPlots {
86  std::unique_ptr<TProfile> p_eff1_vs_x_N;
87  std::unique_ptr<TProfile> p_eff1_vs_xi_N;
88 
89  std::unique_ptr<TProfile> p_eff2_vs_x_N;
90  std::unique_ptr<TProfile> p_eff2_vs_xi_N;
91 
93  : p_eff1_vs_x_N(new TProfile("", ";x_{N} (mm);efficiency", 50, 0., 25.)),
94  p_eff1_vs_xi_N(new TProfile("", ";#xi_{si,N};efficiency", 50, 0., 0.25)),
95 
96  p_eff2_vs_x_N(new TProfile("", ";x_{N} (mm);efficiency", 50, 0., 25.)),
97  p_eff2_vs_xi_N(new TProfile("", ";#xi_{si,N};efficiency", 50, 0., 0.25)) {}
98 
99  void write() const {
100  p_eff1_vs_x_N->Write("p_eff1_vs_x_N");
101  p_eff1_vs_xi_N->Write("p_eff1_vs_xi_N");
102 
103  p_eff2_vs_x_N->Write("p_eff2_vs_x_N");
104  p_eff2_vs_xi_N->Write("p_eff2_vs_xi_N");
105  }
106  };
107 
108  // (n exp protons, index in n_sigmas) --> plots
109  // n exp protons = 0 --> no condition (summary case)
110  std::map<unsigned int, std::map<unsigned int, EffPlots>> effPlots;
111 
114 
115  h_de_x(new TH1D("", ";x_{F} - x_{N} (mm)", 200, -1., +1.)),
116  h_de_y(new TH1D("", ";y_{F} - y_{N} (mm)", 200, -1., +1.)),
117  h2_de_y_vs_de_x(new TH2D("", ";x_{F} - x_{N} (mm);y_{F} - y_{N} (mm)", 100, -1., +1., 100, -1., +1.)),
118 
119  de_x_mean(0.),
120  de_x_sigma(0.),
121  de_y_mean(0.),
122  de_y_sigma(0.) {
123  for (unsigned int nep = 0; nep <= n_exp_prot_max; ++nep) {
124  for (unsigned int nsi = 0; nsi < n_sigmas.size(); ++nsi) {
125  effPlots[nep][nsi] = EffPlots();
126  }
127  }
128  }
129 
130  void write() const {
131  h_de_x->Write("h_de_x");
132  h_de_y->Write("h_de_y");
133  h2_de_y_vs_de_x->Write("h2_de_y_vs_de_x");
134 
135  char buf[100];
136 
137  for (const auto &n_si : n_sigmas) {
138  sprintf(buf, "g_de_y_vs_de_x_n_si=%.1f", n_si);
139  TGraph *g = new TGraph();
140  g->SetName(buf);
141 
142  g->SetPoint(0, de_x_mean - n_si * de_x_sigma, de_y_mean - n_si * de_y_sigma);
143  g->SetPoint(1, de_x_mean + n_si * de_x_sigma, de_y_mean - n_si * de_y_sigma);
144  g->SetPoint(2, de_x_mean + n_si * de_x_sigma, de_y_mean + n_si * de_y_sigma);
145  g->SetPoint(3, de_x_mean - n_si * de_x_sigma, de_y_mean + n_si * de_y_sigma);
146  g->SetPoint(4, de_x_mean - n_si * de_x_sigma, de_y_mean - n_si * de_y_sigma);
147 
148  g->Write();
149  }
150 
151  TDirectory *d_top = gDirectory;
152 
153  for (const auto &nep_p : effPlots) {
154  if (nep_p.first == 0)
155  sprintf(buf, "exp prot all");
156  else
157  sprintf(buf, "exp prot %u", nep_p.first);
158 
159  TDirectory *d_nep = d_top->mkdir(buf);
160 
161  for (const auto &nsi_p : nep_p.second) {
162  sprintf(buf, "nsi = %.1f", n_sigmas[nsi_p.first]);
163 
164  TDirectory *d_nsi = d_nep->mkdir(buf);
165 
166  gDirectory = d_nsi;
167 
168  nsi_p.second.write();
169  }
170  }
171 
172  gDirectory = d_top;
173  }
174 
176  const LHCInterpolatedOpticalFunctionsSet *of = nullptr;
177 
178  for (const auto &p : ofc) {
179  CTPPSDetId rpId(p.first);
180  unsigned int decRPId = rpId.arm() * 100 + rpId.station() * 10 + rpId.rp();
181 
182  if (decRPId == rpId_N) {
183  of = &p.second;
184  break;
185  }
186  }
187 
188  if (!of) {
189  edm::LogError("ArmData::UpdateOptics") << "Cannot find optical functions for RP " << rpId_N;
190  return;
191  }
192 
193  std::vector<double> xiValues =
194  of->getXiValues(); // local copy made since the TSpline constructor needs non-const parameters
195  std::vector<double> xDValues = of->getFcnValues()[LHCOpticalFunctionsSet::exd];
196  s_x_to_xi_N = std::make_shared<TSpline3>("", xDValues.data(), xiValues.data(), xiValues.size());
197  }
198  };
199 
200  std::map<unsigned int, ArmData> data_;
201 
202  std::unique_ptr<TF1> ff_;
203 };
204 
205 //----------------------------------------------------------------------------------------------------
206 
207 using namespace std;
208 using namespace edm;
209 
210 //----------------------------------------------------------------------------------------------------
211 
213  const edm::ParameterSet &iConfig)
214  : tokenTracks_(consumes<CTPPSLocalTrackLiteCollection>(iConfig.getParameter<edm::InputTag>("tagTracks"))),
215 
216  tokenRecoProtonsMultiRP_(
217  consumes<reco::ForwardProtonCollection>(iConfig.getParameter<InputTag>("tagRecoProtonsMultiRP"))),
218 
219  opticsESToken_(esConsumes(ESInputTag("", iConfig.getParameter<std::string>("opticsLabel")))),
220 
221  pixelDiscardBXShiftedTracks_(iConfig.getParameter<bool>("pixelDiscardBXShiftedTracks")),
222 
223  localAngleXMin_(iConfig.getParameter<double>("localAngleXMin")),
224  localAngleXMax_(iConfig.getParameter<double>("localAngleXMax")),
225  localAngleYMin_(iConfig.getParameter<double>("localAngleYMin")),
226  localAngleYMax_(iConfig.getParameter<double>("localAngleYMax")),
227 
228  n_prep_events_(iConfig.getParameter<unsigned int>("n_prep_events")),
229  n_exp_prot_max_(iConfig.getParameter<unsigned int>("n_exp_prot_max")),
230  n_sigmas_(iConfig.getParameter<std::vector<double>>("n_sigmas")),
231 
232  outputFile_(iConfig.getParameter<string>("outputFile")),
233 
234  verbosity_(iConfig.getUntrackedParameter<unsigned int>("verbosity")),
235 
236  ff_(new TF1("ff", "[0] * exp(- (x-[1])*(x-[1]) / 2 / [2]/[2]) + [4]")) {
237  data_[0].n_exp_prot_max = n_exp_prot_max_;
238  data_[0].n_sigmas = n_sigmas_;
239  data_[0].rpId_N = iConfig.getParameter<unsigned int>("rpId_45_N");
240  data_[0].rpId_F = iConfig.getParameter<unsigned int>("rpId_45_F");
241 
242  data_[1].n_exp_prot_max = n_exp_prot_max_;
243  data_[1].n_sigmas = n_sigmas_;
244  data_[1].rpId_N = iConfig.getParameter<unsigned int>("rpId_56_N");
245  data_[1].rpId_F = iConfig.getParameter<unsigned int>("rpId_56_F");
246 }
247 
248 //----------------------------------------------------------------------------------------------------
249 
252 
253  desc.add<edm::InputTag>("tagTracks", edm::InputTag())->setComment("input tag for local lite tracks");
254  desc.add<edm::InputTag>("tagRecoProtonsMultiRP", edm::InputTag())->setComment("input tag for multi-RP reco protons");
255 
256  desc.add<bool>("pixelDiscardBXShiftedTracks", false)
257  ->setComment("whether to discard pixel tracks built from BX-shifted planes");
258 
259  desc.add<double>("localAngleXMin", -0.03)->setComment("minimal accepted value of local horizontal angle (rad)");
260  desc.add<double>("localAngleXMax", +0.03)->setComment("maximal accepted value of local horizontal angle (rad)");
261  desc.add<double>("localAngleYMin", -0.04)->setComment("minimal accepted value of local vertical angle (rad)");
262  desc.add<double>("localAngleYMax", +0.04)->setComment("maximal accepted value of local vertical angle (rad)");
263 
264  desc.add<std::string>("opticsLabel", "")->setComment("label of the optics records");
265 
266  desc.add<unsigned int>("n_prep_events", 1000)
267  ->setComment("number of preparatory events (to determine de x and de y window)");
268 
269  desc.add<unsigned int>("n_exp_prot_max", 5)->setComment("maximum number of expected protons per event and per arm");
270 
271  desc.add<std::vector<double>>("n_sigmas", {3., 5., 7.})->setComment("list of n_sigma values");
272 
273  desc.add<unsigned int>("rpId_45_N", 0)->setComment("decimal RP id for 45 near");
274  desc.add<unsigned int>("rpId_45_F", 0)->setComment("decimal RP id for 45 far");
275  desc.add<unsigned int>("rpId_56_N", 0)->setComment("decimal RP id for 56 near");
276  desc.add<unsigned int>("rpId_56_F", 0)->setComment("decimal RP id for 56 far");
277 
278  desc.add<std::string>("outputFile", "output.root")->setComment("output file name");
279 
280  desc.addUntracked<unsigned int>("verbosity", 0)->setComment("verbosity level");
281 
282  descriptions.add("ctppsProtonReconstructionEfficiencyEstimatorData", desc);
283 }
284 
285 //----------------------------------------------------------------------------------------------------
286 
288  const edm::EventSetup &iSetup) {
289  std::ostringstream os;
290 
291  // get conditions
292  const auto &opticalFunctions = iSetup.getData(opticsESToken_);
293 
294  // check optics change
295  if (opticsWatcher_.check(iSetup)) {
296  data_[0].UpdateOptics(opticalFunctions);
297  data_[1].UpdateOptics(opticalFunctions);
298  }
299 
300  // get input
302  iEvent.getByToken(tokenTracks_, hTracks);
303 
304  Handle<reco::ForwardProtonCollection> hRecoProtonsMultiRP;
305  iEvent.getByToken(tokenRecoProtonsMultiRP_, hRecoProtonsMultiRP);
306 
307  // pre-selection of tracks
308  std::vector<unsigned int> sel_track_idc;
309  for (unsigned int idx = 0; idx < hTracks->size(); ++idx) {
310  const auto &tr = hTracks->at(idx);
311 
312  if (tr.tx() < localAngleXMin_ || tr.tx() > localAngleXMax_ || tr.ty() < localAngleYMin_ ||
313  tr.ty() > localAngleYMax_)
314  continue;
315 
317  if (tr.pixelTrackRecoInfo() == CTPPSpixelLocalTrackReconstructionInfo::allShiftedPlanes ||
318  tr.pixelTrackRecoInfo() == CTPPSpixelLocalTrackReconstructionInfo::mixedPlanes)
319  continue;
320  }
321 
322  sel_track_idc.push_back(idx);
323  }
324 
325  // debug print
326  if (verbosity_ > 1) {
327  os << "* tracks (pre-selected):" << std::endl;
328 
329  for (const auto idx : sel_track_idc) {
330  const auto &tr = hTracks->at(idx);
331  CTPPSDetId rpId(tr.rpId());
332  unsigned int decRPId = rpId.arm() * 100 + rpId.station() * 10 + rpId.rp();
333 
334  os << " [" << idx << "] RP=" << decRPId << ", x=" << tr.x() << ", y=" << tr.y() << std::endl;
335  }
336 
337  os << "* protons:" << std::endl;
338  for (unsigned int i = 0; i < hRecoProtonsMultiRP->size(); ++i) {
339  const auto &pr = (*hRecoProtonsMultiRP)[i];
340  os << " [" << i << "] track indices: ";
341  for (const auto &trr : pr.contributingLocalTracks())
342  os << trr.key() << ", ";
343  os << std::endl;
344  }
345  }
346 
347  // make de_x and de_y plots
348  map<unsigned int, bool> hasTracksInArm;
349 
350  for (const auto idx_i : sel_track_idc) {
351  const auto &tr_i = hTracks->at(idx_i);
352  CTPPSDetId rpId_i(tr_i.rpId());
353  unsigned int decRPId_i = rpId_i.arm() * 100 + rpId_i.station() * 10 + rpId_i.rp();
354 
355  for (const auto idx_j : sel_track_idc) {
356  const auto &tr_j = hTracks->at(idx_j);
357  CTPPSDetId rpId_j(tr_j.rpId());
358  unsigned int decRPId_j = rpId_j.arm() * 100 + rpId_j.station() * 10 + rpId_j.rp();
359 
360  // check whether desired RP combination
361  unsigned int arm = 123;
362  for (const auto &ap : data_) {
363  if (ap.second.rpId_N == decRPId_i && ap.second.rpId_F == decRPId_j)
364  arm = ap.first;
365  }
366 
367  if (arm > 1)
368  continue;
369 
370  // update flag
371  hasTracksInArm[arm] = true;
372 
373  // update plots
374  auto &ad = data_[arm];
375  const double de_x = tr_j.x() - tr_i.x();
376  const double de_y = tr_j.y() - tr_i.y();
377 
378  if (ad.n_events_with_tracks < n_prep_events_) {
379  ad.h_de_x->Fill(de_x);
380  ad.h_de_y->Fill(de_y);
381  }
382 
383  ad.h2_de_y_vs_de_x->Fill(de_x, de_y);
384  }
385  }
386 
387  // update event counter
388  for (auto &ap : data_) {
389  if (hasTracksInArm[ap.first])
390  ap.second.n_events_with_tracks++;
391  }
392 
393  // if threshold reached do fits
394  for (auto &ap : data_) {
395  auto &ad = ap.second;
396 
397  if (ad.n_events_with_tracks == n_prep_events_) {
398  if (ad.de_x_sigma > 0. && ad.de_y_sigma > 0.)
399  continue;
400 
401  std::vector<std::pair<unsigned int, TH1D *>> m;
402  m.emplace_back(0, ad.h_de_x.get());
403  m.emplace_back(1, ad.h_de_y.get());
404 
405  for (const auto &p : m) {
406  double max_pos = -1E100, max_val = -1.;
407  for (int bi = 1; bi < p.second->GetNbinsX(); ++bi) {
408  const double pos = p.second->GetBinCenter(bi);
409  const double val = p.second->GetBinContent(bi);
410 
411  if (val > max_val) {
412  max_val = val;
413  max_pos = pos;
414  }
415  }
416 
417  const double sig = 0.2;
418 
419  ff_->SetParameters(max_val, max_pos, sig, 0.);
420  p.second->Fit(ff_.get(), "Q", "", max_pos - 3. * sig, max_pos + 3. * sig);
421  p.second->Fit(ff_.get(), "Q", "", max_pos - 3. * sig, max_pos + 3. * sig);
422 
423  if (p.first == 0) {
424  ad.de_x_mean = ff_->GetParameter(1);
425  ad.de_x_sigma = fabs(ff_->GetParameter(2));
426  }
427  if (p.first == 1) {
428  ad.de_y_mean = ff_->GetParameter(1);
429  ad.de_y_sigma = fabs(ff_->GetParameter(2));
430  }
431  }
432 
433  if (verbosity_) {
434  os << "* fitting arm " << ap.first << std::endl
435  << " de_x: mean = " << ad.de_x_mean << ", sigma = " << ad.de_x_sigma << std::endl
436  << " de_y: mean = " << ad.de_y_mean << ", sigma = " << ad.de_y_sigma;
437  }
438  }
439  }
440 
441  // data structures for efficiency analysis
442  struct ArmEventData {
443  std::map<unsigned int, std::set<unsigned int>> matched_track_idc;
444 
445  std::set<unsigned int> reco_proton_idc;
446 
447  std::map<unsigned int, std::set<unsigned int>> matched_track_with_prot_idc, matched_track_without_prot_idc;
448  };
449 
450  std::map<unsigned int, ArmEventData> armEventData;
451 
452  // determine the number of expected protons
453  for (const auto idx_i : sel_track_idc) {
454  const auto &tr_i = hTracks->at(idx_i);
455  CTPPSDetId rpId_i(tr_i.rpId());
456  unsigned int decRPId_i = rpId_i.arm() * 100 + rpId_i.station() * 10 + rpId_i.rp();
457 
458  for (const auto idx_j : sel_track_idc) {
459  const auto &tr_j = hTracks->at(idx_j);
460  CTPPSDetId rpId_j(tr_j.rpId());
461  unsigned int decRPId_j = rpId_j.arm() * 100 + rpId_j.station() * 10 + rpId_j.rp();
462 
463  // check whether desired RP combination
464  unsigned int arm = 123;
465  for (const auto &ap : data_) {
466  if (ap.second.rpId_N == decRPId_i && ap.second.rpId_F == decRPId_j)
467  arm = ap.first;
468  }
469 
470  if (arm > 1)
471  continue;
472 
473  // check near-far matching
474  auto &ad = data_[arm];
475  const double de_x = tr_j.x() - tr_i.x();
476  const double de_y = tr_j.y() - tr_i.y();
477 
478  for (unsigned int nsi = 0; nsi < ad.n_sigmas.size(); ++nsi) {
479  const double n_si = ad.n_sigmas[nsi];
480  const bool match_x = fabs(de_x - ad.de_x_mean) < n_si * ad.de_x_sigma;
481  const bool match_y = fabs(de_y - ad.de_y_mean) < n_si * ad.de_y_sigma;
482  if (match_x && match_y)
483  armEventData[arm].matched_track_idc[nsi].insert(idx_i);
484  }
485  }
486  }
487 
488  // determine the number of reconstructed protons
489  for (unsigned int i = 0; i < hRecoProtonsMultiRP->size(); ++i) {
490  const auto &proton = (*hRecoProtonsMultiRP)[i];
491 
492  CTPPSDetId rpId((*proton.contributingLocalTracks().begin())->rpId());
493  unsigned int arm = rpId.arm();
494 
495  if (proton.validFit())
496  armEventData[arm].reco_proton_idc.insert(i);
497  }
498 
499  // compare matched tracks with reco protons
500  if (verbosity_ > 1)
501  os << "* cmp matched tracks vs. reco protons" << std::endl;
502 
503  for (auto &ap : armEventData) {
504  auto &ad = data_[ap.first];
505 
506  if (verbosity_ > 1)
507  os << " arm " << ap.first << std::endl;
508 
509  for (unsigned int nsi = 0; nsi < ad.n_sigmas.size(); ++nsi) {
510  if (verbosity_ > 1)
511  os << " nsi = " << nsi << std::endl;
512 
513  for (const auto &tri : ap.second.matched_track_idc[nsi]) {
514  const auto &track = hTracks->at(tri);
515 
516  bool some_proton_matching = false;
517 
518  if (verbosity_ > 1)
519  os << " tri = " << tri << std::endl;
520 
521  for (const auto &pri : ap.second.reco_proton_idc) {
522  const auto &proton = (*hRecoProtonsMultiRP)[pri];
523 
524  bool proton_matching = false;
525 
526  for (const auto &pr_tr : proton.contributingLocalTracks()) {
527  CTPPSDetId rpId(pr_tr->rpId());
528  unsigned int decRPId = rpId.arm() * 100 + rpId.station() * 10 + rpId.rp();
529 
530  if (decRPId != ad.rpId_N)
531  continue;
532 
533  const double x = pr_tr->x();
534  const double y = pr_tr->y();
535  const double th = 1E-3; // 1 um
536 
537  const bool match = (fabs(x - track.x()) < th) && (fabs(y - track.y()) < th);
538 
539  if (verbosity_ > 1)
540  os << " pri = " << pri << ": x_tr = " << track.x() << ", x_pr = " << x
541  << ", match = " << match << std::endl;
542 
543  if (match) {
544  proton_matching = true;
545  break;
546  }
547  }
548 
549  if (proton_matching) {
550  some_proton_matching = true;
551  break;
552  }
553  }
554 
555  if (verbosity_ > 1)
556  os << " --> some_proton_matching " << some_proton_matching << std::endl;
557 
558  if (some_proton_matching)
559  ap.second.matched_track_with_prot_idc[nsi].insert(tri);
560  else
561  ap.second.matched_track_without_prot_idc[nsi].insert(tri);
562  }
563  }
564  }
565 
566  // debug print
567  if (verbosity_ > 1) {
568  for (auto &ap : armEventData) {
569  auto &ad = data_[ap.first];
570 
571  if (ad.de_x_sigma <= 0. && ad.de_y_sigma <= 0.)
572  continue;
573 
574  os << "* results for arm " << ap.first << std::endl;
575 
576  os << " reco_proton_idc: ";
577  for (const auto &idx : ap.second.reco_proton_idc)
578  os << idx << ", ";
579  os << std::endl;
580 
581  for (unsigned int nsi = 0; nsi < ad.n_sigmas.size(); ++nsi) {
582  os << " n_si = " << ad.n_sigmas[nsi] << std::endl;
583 
584  os << " matched_track_idc: ";
585  for (const auto &idx : ap.second.matched_track_idc[nsi])
586  os << idx << ", ";
587  os << std::endl;
588 
589  os << " matched_track_with_prot_idc: ";
590  for (const auto &idx : ap.second.matched_track_with_prot_idc[nsi])
591  os << idx << ", ";
592  os << std::endl;
593 
594  os << " matched_track_without_prot_idc: ";
595  for (const auto &idx : ap.second.matched_track_without_prot_idc[nsi])
596  os << idx << ", ";
597  os << std::endl;
598  }
599  }
600  }
601 
602  // update efficiency plots
603  for (auto &ap : armEventData) {
604  auto &ad = data_[ap.first];
605 
606  // stop if sigmas not yet determined
607  if (ad.de_x_sigma <= 0. && ad.de_y_sigma <= 0.)
608  continue;
609 
610  // loop over n_sigma choices
611  for (unsigned int nsi = 0; nsi < ad.n_sigmas.size(); ++nsi) {
612  const unsigned int n_exp_prot = ap.second.matched_track_idc[nsi].size();
613  const unsigned int n_rec_prot = ap.second.reco_proton_idc.size();
614 
615  // stop if N(expected protons) out of range
616  if (n_exp_prot < 1 || n_exp_prot > ad.n_exp_prot_max)
617  continue;
618 
619  // update method 1 plots
620  const double eff = double(n_rec_prot) / n_exp_prot;
621 
622  for (unsigned int tri : ap.second.matched_track_idc[nsi]) {
623  const double x_N = hTracks->at(tri).x();
624  const double xi_N = ad.s_x_to_xi_N->Eval(x_N * 1E-1); // conversion mm to cm
625 
626  ad.effPlots[0][nsi].p_eff1_vs_x_N->Fill(x_N, eff);
627  ad.effPlots[0][nsi].p_eff1_vs_xi_N->Fill(xi_N, eff);
628 
629  ad.effPlots[n_exp_prot][nsi].p_eff1_vs_x_N->Fill(x_N, eff);
630  ad.effPlots[n_exp_prot][nsi].p_eff1_vs_xi_N->Fill(xi_N, eff);
631  }
632 
633  // update method 2 plots
634  for (const auto &tri : ap.second.matched_track_with_prot_idc[nsi]) {
635  const double x_N = hTracks->at(tri).x();
636  const double xi_N = ad.s_x_to_xi_N->Eval(x_N * 1E-1); // conversion mm to cm
637 
638  ad.effPlots[0][nsi].p_eff2_vs_x_N->Fill(x_N, 1.);
639  ad.effPlots[0][nsi].p_eff2_vs_xi_N->Fill(xi_N, 1.);
640 
641  ad.effPlots[n_exp_prot][nsi].p_eff2_vs_x_N->Fill(x_N, 1.);
642  ad.effPlots[n_exp_prot][nsi].p_eff2_vs_xi_N->Fill(xi_N, 1.);
643  }
644 
645  for (const auto &tri : ap.second.matched_track_without_prot_idc[nsi]) {
646  const double x_N = hTracks->at(tri).x();
647  const double xi_N = ad.s_x_to_xi_N->Eval(x_N * 1E-1); // conversion mm to cm
648 
649  ad.effPlots[0][nsi].p_eff2_vs_x_N->Fill(x_N, 0.);
650  ad.effPlots[0][nsi].p_eff2_vs_xi_N->Fill(xi_N, 0.);
651 
652  ad.effPlots[n_exp_prot][nsi].p_eff2_vs_x_N->Fill(x_N, 0.);
653  ad.effPlots[n_exp_prot][nsi].p_eff2_vs_xi_N->Fill(xi_N, 0.);
654  }
655  }
656  }
657 
658  if (verbosity_)
659  edm::LogInfo("CTPPSProtonReconstructionEfficiencyEstimatorData") << os.str();
660 }
661 
662 //----------------------------------------------------------------------------------------------------
663 
665  auto f_out = std::make_unique<TFile>(outputFile_.c_str(), "recreate");
666 
667  for (const auto &ait : data_) {
668  char buf[100];
669  sprintf(buf, "arm %u", ait.first);
670  TDirectory *d_arm = f_out->mkdir(buf);
671  gDirectory = d_arm;
672 
673  ait.second.write();
674  }
675 }
676 
677 //----------------------------------------------------------------------------------------------------
678 
edm::ESWatcher::check
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:52
CTPPSProtonReconstructionEfficiencyEstimatorData::ArmData::s_x_to_xi_N
std::shared_ptr< const TSpline3 > s_x_to_xi_N
Definition: CTPPSProtonReconstructionEfficiencyEstimatorData.cc:73
DDAxes::y
CTPPSLocalTrackLiteCollection
std::vector< CTPPSLocalTrackLite > CTPPSLocalTrackLiteCollection
Collection of CTPPSLocalTrackLite objects.
Definition: CTPPSLocalTrackLiteFwd.h:18
CTPPSProtonReconstructionEfficiencyEstimatorData::ArmData::de_x_sigma
double de_x_sigma
Definition: CTPPSProtonReconstructionEfficiencyEstimatorData.cc:80
CTPPSProtonReconstructionEfficiencyEstimatorData::ArmData::n_exp_prot_max
unsigned int n_exp_prot_max
Definition: CTPPSProtonReconstructionEfficiencyEstimatorData.cc:85
LHCOpticalFunctionsSet::exd
Definition: LHCOpticalFunctionsSet.h:16
electrons_cff.bool
bool
Definition: electrons_cff.py:366
EDAnalyzer.h
mps_fire.i
i
Definition: mps_fire.py:428
CTPPSProtonReconstructionEfficiencyEstimatorData::tokenRecoProtonsMultiRP_
edm::EDGetTokenT< reco::ForwardProtonCollection > tokenRecoProtonsMultiRP_
Definition: CTPPSProtonReconstructionEfficiencyEstimatorData.cc:51
edm::ESInputTag
Definition: ESInputTag.h:87
HLT_FULL_cff.track
track
Definition: HLT_FULL_cff.py:11713
CTPPSProtonReconstructionEfficiencyEstimatorData::ArmData::de_x_mean
double de_x_mean
Definition: CTPPSProtonReconstructionEfficiencyEstimatorData.cc:80
CTPPSProtonReconstructionEfficiencyEstimatorData::ArmData::EffPlots::EffPlots
EffPlots()
Definition: CTPPSProtonReconstructionEfficiencyEstimatorData.cc:94
CTPPSProtonReconstructionEfficiencyEstimatorData::ArmData::h_de_y
std::unique_ptr< TH1D > h_de_y
Definition: CTPPSProtonReconstructionEfficiencyEstimatorData.cc:77
edm::ESWatcher< CTPPSInterpolatedOpticsRcd >
ESHandle.h
edm::EDGetTokenT< CTPPSLocalTrackLiteCollection >
edm
HLT enums.
Definition: AlignableModifier.h:19
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
CTPPSProtonReconstructionEfficiencyEstimatorData::data_
std::map< unsigned int, ArmData > data_
Definition: CTPPSProtonReconstructionEfficiencyEstimatorData.cc:202
pos
Definition: PixelAliasList.h:18
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89281
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
CTPPSProtonReconstructionEfficiencyEstimatorData::n_sigmas_
std::vector< double > n_sigmas_
Definition: CTPPSProtonReconstructionEfficiencyEstimatorData.cc:62
LHCOpticalFunctionsSet::getFcnValues
const std::vector< std::vector< double > > & getFcnValues() const
Definition: LHCOpticalFunctionsSet.h:29
CTPPSProtonReconstructionEfficiencyEstimatorData::localAngleXMin_
double localAngleXMin_
Definition: CTPPSProtonReconstructionEfficiencyEstimatorData.cc:56
CTPPSLocalTrackLite.h
DDAxes::x
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
edm::one::EDAnalyzer
Definition: EDAnalyzer.h:30
edm::Handle
Definition: AssociativeIterator.h:50
CTPPSProtonReconstructionEfficiencyEstimatorData::ArmData::write
void write() const
Definition: CTPPSProtonReconstructionEfficiencyEstimatorData.cc:132
LHCOpticalFunctionsSet::getXiValues
const std::vector< double > & getXiValues() const
Definition: LHCOpticalFunctionsSet.h:28
heavyIonCSV_trainingSettings.idx
idx
Definition: heavyIonCSV_trainingSettings.py:5
LHCInterpolatedOpticalFunctionsSetCollection
Definition: LHCInterpolatedOpticalFunctionsSetCollection.h:10
CTPPSProtonReconstructionEfficiencyEstimatorData::ArmData::effPlots
std::map< unsigned int, std::map< unsigned int, EffPlots > > effPlots
Definition: CTPPSProtonReconstructionEfficiencyEstimatorData.cc:112
CTPPSProtonReconstructionEfficiencyEstimatorData::ArmData::EffPlots::write
void write() const
Definition: CTPPSProtonReconstructionEfficiencyEstimatorData.cc:101
CTPPSProtonReconstructionEfficiencyEstimatorData::ArmData::de_y_sigma
double de_y_sigma
Definition: CTPPSProtonReconstructionEfficiencyEstimatorData.cc:81
CTPPSProtonReconstructionEfficiencyEstimatorData::ArmData::rpId_F
unsigned int rpId_F
Definition: CTPPSProtonReconstructionEfficiencyEstimatorData.cc:71
MakerMacros.h
CTPPSProtonReconstructionEfficiencyEstimatorData::ArmData::h_de_x
std::unique_ptr< TH1D > h_de_x
Definition: CTPPSProtonReconstructionEfficiencyEstimatorData.cc:77
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
CTPPSProtonReconstructionEfficiencyEstimatorData::ArmData
Definition: CTPPSProtonReconstructionEfficiencyEstimatorData.cc:70
CTPPSProtonReconstructionEfficiencyEstimatorData::tokenTracks_
edm::EDGetTokenT< CTPPSLocalTrackLiteCollection > tokenTracks_
Definition: CTPPSProtonReconstructionEfficiencyEstimatorData.cc:50
visualization-live-secondInstance_cfg.m
m
Definition: visualization-live-secondInstance_cfg.py:72
CTPPSProtonReconstructionEfficiencyEstimatorData::ArmData::EffPlots
Definition: CTPPSProtonReconstructionEfficiencyEstimatorData.cc:87
CTPPSProtonReconstructionEfficiencyEstimatorData::endJob
void endJob() override
Definition: CTPPSProtonReconstructionEfficiencyEstimatorData.cc:663
LHCInterpolatedOpticalFunctionsSetCollection.h
CTPPSProtonReconstructionEfficiencyEstimatorData::ArmData::EffPlots::p_eff1_vs_xi_N
std::unique_ptr< TProfile > p_eff1_vs_xi_N
Definition: CTPPSProtonReconstructionEfficiencyEstimatorData.cc:89
ForwardProtonFwd.h
CTPPSProtonReconstructionEfficiencyEstimatorData::ArmData::UpdateOptics
void UpdateOptics(const LHCInterpolatedOpticalFunctionsSetCollection &ofc)
Definition: CTPPSProtonReconstructionEfficiencyEstimatorData.cc:177
CTPPSProtonReconstructionEfficiencyEstimatorData::opticsESToken_
edm::ESGetToken< LHCInterpolatedOpticalFunctionsSetCollection, CTPPSInterpolatedOpticsRcd > opticsESToken_
Definition: CTPPSProtonReconstructionEfficiencyEstimatorData.cc:52
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
CTPPSDetId::arm
uint32_t arm() const
Definition: CTPPSDetId.h:55
LHCInterpolatedOpticalFunctionsSet
Set of optical functions corresponding to one scoring plane along LHC, including splines for interpol...
Definition: LHCInterpolatedOpticalFunctionsSet.h:14
CTPPSProtonReconstructionEfficiencyEstimatorData::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: CTPPSProtonReconstructionEfficiencyEstimatorData.cc:249
CTPPSpixelLocalTrackReconstructionInfo::mixedPlanes
reco::ForwardProtonCollection
std::vector< ForwardProton > ForwardProtonCollection
Collection of ForwardProton objects.
Definition: ForwardProtonFwd.h:25
CTPPSProtonReconstructionEfficiencyEstimatorData::ArmData::EffPlots::p_eff1_vs_x_N
std::unique_ptr< TProfile > p_eff1_vs_x_N
Definition: CTPPSProtonReconstructionEfficiencyEstimatorData.cc:88
edm::ParameterSet
Definition: ParameterSet.h:47
sipixeldigitoraw
Definition: SiPixelDigiToRaw.cc:39
Event.h
CTPPSProtonReconstructionEfficiencyEstimatorData::verbosity_
unsigned int verbosity_
Definition: CTPPSProtonReconstructionEfficiencyEstimatorData.cc:66
match
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:10
ForwardProton.h
CTPPSDetId
Base class for CTPPS detector IDs.
Definition: CTPPSDetId.h:31
CTPPSpixelLocalTrackReconstructionInfo::allShiftedPlanes
createfilelist.int
int
Definition: createfilelist.py:10
iEvent
int iEvent
Definition: GenABIO.cc:224
CTPPSInterpolatedOpticsRcd.h
CTPPSProtonReconstructionEfficiencyEstimatorData::ArmData::de_y_mean
double de_y_mean
Definition: CTPPSProtonReconstructionEfficiencyEstimatorData.cc:81
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
edm::EventSetup
Definition: EventSetup.h:58
alignCSCRings.de_y
de_y
Definition: alignCSCRings.py:86
CTPPSProtonReconstructionEfficiencyEstimatorData::ff_
std::unique_ptr< TF1 > ff_
Definition: CTPPSProtonReconstructionEfficiencyEstimatorData.cc:204
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
CTPPSProtonReconstructionEfficiencyEstimatorData::pixelDiscardBXShiftedTracks_
bool pixelDiscardBXShiftedTracks_
Definition: CTPPSProtonReconstructionEfficiencyEstimatorData.cc:54
CTPPSProtonReconstructionEfficiencyEstimatorData::n_prep_events_
unsigned int n_prep_events_
Definition: CTPPSProtonReconstructionEfficiencyEstimatorData.cc:58
visDQMUpload.buf
buf
Definition: visDQMUpload.py:154
edm::ESGetToken< LHCInterpolatedOpticalFunctionsSetCollection, CTPPSInterpolatedOpticsRcd >
CTPPSProtonReconstructionEfficiencyEstimatorData::ArmData::n_events_with_tracks
unsigned int n_events_with_tracks
Definition: CTPPSProtonReconstructionEfficiencyEstimatorData.cc:75
edm::EventSetup::getData
bool getData(T &iHolder) const
Definition: EventSetup.h:127
protons_cff.arm
arm
Definition: protons_cff.py:43
CTPPSProtonReconstructionEfficiencyEstimatorData::localAngleXMax_
double localAngleXMax_
Definition: CTPPSProtonReconstructionEfficiencyEstimatorData.cc:56
profile_2016_postTS2_cff.rpId
rpId
Definition: profile_2016_postTS2_cff.py:21
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
heppy_batch.val
val
Definition: heppy_batch.py:351
std
Definition: JetResolutionObject.h:76
CTPPSProtonReconstructionEfficiencyEstimatorData::outputFile_
std::string outputFile_
Definition: CTPPSProtonReconstructionEfficiencyEstimatorData.cc:64
CTPPSProtonReconstructionEfficiencyEstimatorData::ArmData::h2_de_y_vs_de_x
std::unique_ptr< TH2D > h2_de_y_vs_de_x
Definition: CTPPSProtonReconstructionEfficiencyEstimatorData.cc:78
Frameworkfwd.h
ESWatcher.h
CTPPSProtonReconstructionEfficiencyEstimatorData::localAngleYMax_
double localAngleYMax_
Definition: CTPPSProtonReconstructionEfficiencyEstimatorData.cc:56
alignCSCRings.de_x
de_x
Definition: alignCSCRings.py:85
protons_cff.decRPId
decRPId
Definition: protons_cff.py:60
CTPPSLocalTrackLiteFwd.h
EventSetup.h
CTPPSProtonReconstructionEfficiencyEstimatorData::ArmData::EffPlots::p_eff2_vs_xi_N
std::unique_ptr< TProfile > p_eff2_vs_xi_N
Definition: CTPPSProtonReconstructionEfficiencyEstimatorData.cc:92
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
CTPPSDetId.h
CTPPSProtonReconstructionEfficiencyEstimatorData::CTPPSProtonReconstructionEfficiencyEstimatorData
CTPPSProtonReconstructionEfficiencyEstimatorData(const edm::ParameterSet &)
Definition: CTPPSProtonReconstructionEfficiencyEstimatorData.cc:211
CTPPSProtonReconstructionEfficiencyEstimatorData::ArmData::n_sigmas
std::vector< double > n_sigmas
Definition: CTPPSProtonReconstructionEfficiencyEstimatorData.cc:83
CTPPSProtonReconstructionEfficiencyEstimatorData::ArmData::ArmData
ArmData()
Definition: CTPPSProtonReconstructionEfficiencyEstimatorData.cc:114
CTPPSProtonReconstructionEfficiencyEstimatorData::n_exp_prot_max_
unsigned int n_exp_prot_max_
Definition: CTPPSProtonReconstructionEfficiencyEstimatorData.cc:60
DeDxTools::esConsumes
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
CTPPSProtonReconstructionEfficiencyEstimatorData::opticsWatcher_
edm::ESWatcher< CTPPSInterpolatedOpticsRcd > opticsWatcher_
Definition: CTPPSProtonReconstructionEfficiencyEstimatorData.cc:68
CTPPSProtonReconstructionEfficiencyEstimatorData::ArmData::rpId_N
unsigned int rpId_N
Definition: CTPPSProtonReconstructionEfficiencyEstimatorData.cc:71
edm::Event
Definition: Event.h:73
CTPPSProtonReconstructionEfficiencyEstimatorData::ArmData::EffPlots::p_eff2_vs_x_N
std::unique_ptr< TProfile > p_eff2_vs_x_N
Definition: CTPPSProtonReconstructionEfficiencyEstimatorData.cc:91
edm::InputTag
Definition: InputTag.h:15
CTPPSProtonReconstructionEfficiencyEstimatorData::localAngleYMin_
double localAngleYMin_
Definition: CTPPSProtonReconstructionEfficiencyEstimatorData.cc:56
OpticalFunctionsConfig_cfi.opticalFunctions
opticalFunctions
Definition: OpticalFunctionsConfig_cfi.py:16
CTPPSProtonReconstructionEfficiencyEstimatorData::analyze
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: CTPPSProtonReconstructionEfficiencyEstimatorData.cc:286
g
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e g
Definition: Activities.doc:4
CTPPSProtonReconstructionEfficiencyEstimatorData
Definition: CTPPSProtonReconstructionEfficiencyEstimatorData.cc:37