CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
PPSAlignmentWorker.cc
Go to the documentation of this file.
1 /****************************************************************************
2 * Authors:
3 * Jan Kašpar (jan.kaspar@gmail.com)
4 * Mateusz Kocot (mateuszkocot99@gmail.com)
5 ****************************************************************************/
6 
10 
17 
21 
24 
25 #include <map>
26 #include <string>
27 #include <cmath>
28 #include <memory>
29 
30 #include "TH2D.h"
31 #include "TGraph.h"
32 
33 //----------------------------------------------------------------------------------------------------
34 
36 public:
38 
39  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
40 
41 private:
42  void bookHistograms(DQMStore::IBooker& iBooker, edm::Run const&, edm::EventSetup const& iSetup) override;
43  void analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) override;
44 
45  // ------------ structures ------------
46  struct SectorData {
48 
49  // hit distributions
50  std::map<unsigned int, MonitorElement*> m_h2_y_vs_x_bef_sel;
51 
52  std::map<unsigned int, MonitorElement*> m_h2_y_vs_x_mlt_sel;
53 
54  std::map<unsigned int, MonitorElement*> m_h2_y_vs_x_aft_sel;
55 
56  // cut plots
61 
66 
67  // near-far plots
70 
71  struct SlicePlots {
75 
76  SlicePlots();
78  };
79 
80  std::map<unsigned int, SlicePlots> x_slice_plots_N, x_slice_plots_F;
81 
82  void init(DQMStore::IBooker& iBooker,
85  const std::string& folder,
86  bool debug);
87 
89  };
90 
91  // ------------ member data ------------
94 
96 
99 
101  bool debug_;
102 };
103 
104 // -------------------------------- DQMEDAnalyzer methods --------------------------------
105 
107  : esTokenBookHistograms_(
109  edm::ESInputTag("", iConfig.getParameter<std::string>("label")))),
111  edm::ESInputTag("", iConfig.getParameter<std::string>("label")))),
112  tracksToken_(consumes<CTPPSLocalTrackLiteCollection>(iConfig.getParameter<edm::InputTag>("tagTracks"))),
113  folder_(iConfig.getParameter<std::string>("folder")),
114  debug_(iConfig.getParameter<bool>("debug")) {
115  edm::LogInfo("PPS").log([&](auto& li) {
116  li << "[worker] parameters:\n";
117  li << "* label: " << iConfig.getParameter<std::string>("label") << "\n";
118  li << "* tagTracks: " << iConfig.getParameter<edm::InputTag>("tagTracks") << "\n";
119  li << "* folder: " << folder_ << "\n";
120  li << "* debug: " << std::boolalpha << debug_;
121  });
122 }
123 
125  const auto& cfg = iSetup.getData(esTokenBookHistograms_);
126 
127  sectorData45_.init(iBooker, cfg, cfg.sectorConfig45(), folder_ + "/worker", debug_);
128  sectorData56_.init(iBooker, cfg, cfg.sectorConfig56(), folder_ + "/worker", debug_);
129 }
130 
132  const auto& tracks = iEvent.get(tracksToken_);
133 
134  const auto& cfg = iSetup.getData(esTokenAnalyze_);
135 
138 }
139 
142 
143  desc.add<std::string>("label", "");
144  desc.add<edm::InputTag>("tagTracks", edm::InputTag("ctppsLocalTrackLiteProducer"));
145  desc.add<std::string>("folder", "AlCaReco/PPSAlignment");
146  desc.add<bool>("debug", false);
147 
148  descriptions.addWithDefaultLabel(desc);
149 }
150 
151 // -------------------------------- SectorData and SlicePlots methods --------------------------------
152 
154 
157  bool debug) {
158  h_y = iBooker.book1DD(
159  "h_y", ";y", cfg.binning().slice_n_bins_x_, cfg.binning().slice_x_min_, cfg.binning().slice_x_max_);
160 
161  auto profilePtr = std::make_unique<TProfile>(
162  "", ";y;y_{F} - y_{N}", cfg.binning().slice_n_bins_x_, cfg.binning().slice_x_min_, cfg.binning().slice_x_max_);
163  p_y_diffFN_vs_y = iBooker.bookProfile("p_y_diffFN_vs_y", profilePtr.get());
164 
165  if (debug)
166  h2_y_diffFN_vs_y = iBooker.book2DD("h2_y_diffFN_vs_y",
167  ";y;y_{F} - y_{N}",
168  cfg.binning().slice_n_bins_x_,
169  cfg.binning().slice_x_min_,
170  cfg.binning().slice_x_max_,
171  cfg.binning().slice_n_bins_y_,
172  cfg.binning().slice_y_min_,
173  cfg.binning().slice_y_max_);
174 }
175 
179  const std::string& folder,
180  bool debug) {
181  scfg_ = scfg;
182 
183  // binning
184  const double bin_size_x = cfg.binning().bin_size_x_;
185  const unsigned int n_bins_x = cfg.binning().n_bins_x_;
186 
187  const double pixel_x_offset = cfg.binning().pixel_x_offset_;
188 
189  const double x_min_pix = pixel_x_offset, x_max_pix = pixel_x_offset + n_bins_x * bin_size_x;
190  const double x_min_str = 0., x_max_str = n_bins_x * bin_size_x;
191 
192  const unsigned int n_bins_y = cfg.binning().n_bins_y_;
193  const double y_min = cfg.binning().y_min_, y_max = cfg.binning().y_max_;
194 
195  // hit distributions
196  iBooker.setCurrentFolder(folder + "/" + scfg_.name_ + "/before selection/" + scfg_.rp_N_.name_);
198  iBooker.book2DD("h2_y_vs_x", ";x;y", n_bins_x, x_min_str, x_max_str, n_bins_y, y_min, y_max);
199  iBooker.setCurrentFolder(folder + "/" + scfg_.name_ + "/before selection/" + scfg_.rp_F_.name_);
201  iBooker.book2DD("h2_y_vs_x", ";x;y", n_bins_x, x_min_pix, x_max_pix, n_bins_y, y_min, y_max);
202 
203  iBooker.setCurrentFolder(folder + "/" + scfg_.name_ + "/multiplicity selection/" + scfg_.rp_N_.name_);
205  iBooker.book2DD("h2_y_vs_x", ";x;y", n_bins_x, x_min_str, x_max_str, n_bins_y, y_min, y_max);
206  iBooker.setCurrentFolder(folder + "/" + scfg_.name_ + "/multiplicity selection/" + scfg_.rp_F_.name_);
208  iBooker.book2DD("h2_y_vs_x", ";x;y", n_bins_x, x_min_pix, x_max_pix, n_bins_y, y_min, y_max);
209 
210  iBooker.setCurrentFolder(folder + "/" + scfg_.name_ + "/after selection/" + scfg_.rp_N_.name_);
212  iBooker.book2DD("h2_y_vs_x", ";x;y", n_bins_x, x_min_str, x_max_str, n_bins_y, y_min, y_max);
213  iBooker.setCurrentFolder(folder + "/" + scfg_.name_ + "/after selection/" + scfg_.rp_F_.name_);
215  iBooker.book2DD("h2_y_vs_x", ";x;y", n_bins_x, x_min_pix, x_max_pix, n_bins_y, y_min, y_max);
216 
217  // cut plots
218  iBooker.setCurrentFolder(folder + "/" + scfg_.name_ + "/cuts/cut_h");
219  h_q_cut_h_bef = iBooker.book1DD("h_q_cut_h_bef", ";cq_h", 400, -2., 2.);
220  h_q_cut_h_aft = iBooker.book1DD("h_q_cut_h_aft", ";cq_h", 400, -2., 2.);
221  h2_cut_h_bef =
222  iBooker.book2DD("h2_cut_h_bef", ";x_up;x_dw", n_bins_x, x_min_str, x_max_str, n_bins_x, x_min_pix, x_max_pix);
223  h2_cut_h_aft =
224  iBooker.book2DD("h2_cut_h_aft", ";x_up;x_dw", n_bins_x, x_min_str, x_max_str, n_bins_x, x_min_pix, x_max_pix);
225 
226  iBooker.setCurrentFolder(folder + "/" + scfg_.name_ + "/cuts/cut_v");
227  h_q_cut_v_bef = iBooker.book1DD("h_q_cut_v_bef", ";cq_v", 400, -2., 2.);
228  h_q_cut_v_aft = iBooker.book1DD("h_q_cut_v_aft", ";cq_v", 400, -2., 2.);
229  h2_cut_v_bef = iBooker.book2DD("h2_cut_v_bef", ";y_up;y_dw", n_bins_y, y_min, y_max, n_bins_y, y_min, y_max);
230  h2_cut_v_aft = iBooker.book2DD("h2_cut_v_aft", ";y_up;y_dw", n_bins_y, y_min, y_max, n_bins_y, y_min, y_max);
231 
232  // near-far plots
233  iBooker.setCurrentFolder(folder + "/" + scfg_.name_ + "/near_far");
234 
235  auto profilePtr = std::make_unique<TProfile>("",
236  ";x_{N};x_{F} - x_{N}",
238  cfg.binning().diffFN_x_min_,
239  cfg.binning().diffFN_x_max_);
240  p_x_diffFN_vs_x_N = iBooker.bookProfile("p_x_diffFN_vs_x_N", profilePtr.get());
241 
242  for (int i = 0; i < scfg_.rp_N_.x_slice_n_; i++) {
243  const double x_min = scfg_.rp_N_.x_slice_min_ + i * scfg_.rp_N_.x_slice_w_;
244  const double x_max = scfg_.rp_N_.x_slice_min_ + (i + 1) * scfg_.rp_N_.x_slice_w_;
245 
246  char buf[100];
247  sprintf(buf, "%.1f-%.1f", x_min, x_max);
248 
249  iBooker.setCurrentFolder(folder + "/" + scfg_.name_ + "/near_far/x slices, N/" + buf);
250  x_slice_plots_N.insert({i, SlicePlots(iBooker, cfg, debug)});
251  }
252 
253  for (int i = 0; i < scfg_.rp_F_.x_slice_n_; i++) {
254  const double x_min = scfg_.rp_F_.x_slice_min_ + i * scfg_.rp_F_.x_slice_w_;
255  const double x_max = scfg_.rp_F_.x_slice_min_ + (i + 1) * scfg_.rp_F_.x_slice_w_;
256 
257  char buf[100];
258  sprintf(buf, "%.1f-%.1f", x_min, x_max);
259 
260  iBooker.setCurrentFolder(folder + "/" + scfg_.name_ + "/near_far/x slices, F/" + buf);
261  x_slice_plots_F.insert({i, SlicePlots(iBooker, cfg, debug)});
262  }
263 }
264 
267  bool debug) {
268  CTPPSLocalTrackLiteCollection tracksUp, tracksDw;
269 
270  for (const auto& tr : tracks) {
271  CTPPSDetId rpId(tr.rpId());
272  unsigned int rpDecId = rpId.arm() * 100 + rpId.station() * 10 + rpId.rp();
273 
274  if (rpDecId != scfg_.rp_N_.id_ && rpDecId != scfg_.rp_F_.id_)
275  continue;
276 
277  // store the track in the right collection
278  if (rpDecId == scfg_.rp_N_.id_)
279  tracksUp.push_back(tr);
280  if (rpDecId == scfg_.rp_F_.id_)
281  tracksDw.push_back(tr);
282  }
283 
284  // update plots before selection
285  for (const auto& tr : tracksUp)
286  m_h2_y_vs_x_bef_sel[scfg_.rp_N_.id_]->Fill(tr.x(), tr.y());
287 
288  for (const auto& tr : tracksDw)
289  m_h2_y_vs_x_bef_sel[scfg_.rp_F_.id_]->Fill(tr.x(), tr.y());
290 
291  // skip crowded events (multiplicity selection)
292  if (tracksUp.size() < cfg.minRPTracksSize() || tracksUp.size() > cfg.maxRPTracksSize())
293  return 0;
294 
295  if (tracksDw.size() < cfg.minRPTracksSize() || tracksDw.size() > cfg.maxRPTracksSize())
296  return 0;
297 
298  // update plots with multiplicity selection
299  for (const auto& tr : tracksUp)
300  m_h2_y_vs_x_mlt_sel[scfg_.rp_N_.id_]->Fill(tr.x(), tr.y());
301 
302  for (const auto& tr : tracksDw)
303  m_h2_y_vs_x_mlt_sel[scfg_.rp_F_.id_]->Fill(tr.x(), tr.y());
304 
305  // do the selection
306  unsigned int pairsSelected = 0;
307 
308  for (const auto& trUp : tracksUp) {
309  for (const auto& trDw : tracksDw) {
310  h2_cut_h_bef->Fill(trUp.x(), trDw.x());
311  h2_cut_v_bef->Fill(trUp.y(), trDw.y());
312 
313  const double cq_h = trDw.x() + scfg_.cut_h_a_ * trUp.x() + scfg_.cut_h_c_;
314  h_q_cut_h_bef->Fill(cq_h);
315  const bool cv_h = (std::fabs(cq_h) < cfg.n_si() * scfg_.cut_h_si_);
316 
317  const double cq_v = trDw.y() + scfg_.cut_v_a_ * trUp.y() + scfg_.cut_v_c_;
318  h_q_cut_v_bef->Fill(cq_v);
319  const bool cv_v = (std::fabs(cq_v) < cfg.n_si() * scfg_.cut_v_si_);
320 
321  bool cutsPassed = true;
322  if (scfg_.cut_h_apply_)
323  cutsPassed &= cv_h;
324  if (scfg_.cut_v_apply_)
325  cutsPassed &= cv_v;
326 
327  if (cutsPassed) {
328  pairsSelected++;
329 
330  h_q_cut_h_aft->Fill(cq_h);
331  h_q_cut_v_aft->Fill(cq_v);
332 
333  h2_cut_h_aft->Fill(trUp.x(), trDw.x());
334  h2_cut_v_aft->Fill(trUp.y(), trDw.y());
335 
336  m_h2_y_vs_x_aft_sel[scfg_.rp_N_.id_]->Fill(trUp.x(), trUp.y());
337  m_h2_y_vs_x_aft_sel[scfg_.rp_F_.id_]->Fill(trDw.x(), trDw.y());
338 
339  p_x_diffFN_vs_x_N->Fill(trUp.x(), trDw.x() - trUp.x());
340 
341  int idx = (trUp.x() - scfg_.rp_N_.x_slice_min_) / scfg_.rp_N_.x_slice_w_;
342  if (idx >= 0 && idx < scfg_.rp_N_.x_slice_n_) {
343  x_slice_plots_N[idx].h_y->Fill(trUp.y());
344  x_slice_plots_N[idx].p_y_diffFN_vs_y->Fill(trUp.y(), trDw.y() - trUp.y());
345  if (debug)
346  x_slice_plots_N[idx].h2_y_diffFN_vs_y->Fill(trUp.y(), trDw.y() - trUp.y());
347  }
348 
349  idx = (trDw.x() - scfg_.rp_F_.x_slice_min_) / scfg_.rp_F_.x_slice_w_;
350  if (idx >= 0 && idx < scfg_.rp_F_.x_slice_n_) {
351  x_slice_plots_F[idx].h_y->Fill(trDw.y());
352  x_slice_plots_F[idx].p_y_diffFN_vs_y->Fill(trDw.y(), trDw.y() - trUp.y());
353  if (debug)
354  x_slice_plots_F[idx].h2_y_diffFN_vs_y->Fill(trDw.y(), trDw.y() - trUp.y());
355  }
356  }
357  }
358  }
359 
360  return pairsSelected;
361 }
362 
std::map< unsigned int, SlicePlots > x_slice_plots_F
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
std::map< unsigned int, MonitorElement * > m_h2_y_vs_x_bef_sel
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void bookHistograms(DQMStore::IBooker &iBooker, edm::Run const &, edm::EventSetup const &iSetup) override
unsigned int process(const CTPPSLocalTrackLiteCollection &tracks, const PPSAlignmentConfiguration &cfg, bool debug)
edm::ESGetToken< PPSAlignmentConfiguration, PPSAlignmentConfigurationRcd > esTokenBookHistograms_
tuple cfg
Definition: looper.py:296
std::string folder_
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:32
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
auto const & tracks
cannot be loose
std::map< unsigned int, MonitorElement * > m_h2_y_vs_x_aft_sel
void init(DQMStore::IBooker &iBooker, const PPSAlignmentConfiguration &cfg, const PPSAlignmentConfiguration::SectorConfig &scfg, const std::string &folder, bool debug)
void Fill(long long x)
bool getData(T &iHolder) const
Definition: EventSetup.h:128
void analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup) override
MonitorElement * book1DD(TString const &name, TString const &title, int nchX, double lowX, double highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:155
int iEvent
Definition: GenABIO.cc:224
MonitorElement * bookProfile(TString const &name, TString const &title, int nchX, double lowX, double highX, int, double lowY, double highY, char const *option="s", FUNC onbooking=NOOP())
Definition: DQMStore.h:322
PPSAlignmentWorker(const edm::ParameterSet &iConfig)
if(conf_.getParameter< bool >("UseStripCablingDB"))
const Binning & binning() const
Transition
Definition: Transition.h:12
bool get(ProductID const &oid, Handle< PROD > &result) const
Definition: Event.h:346
PPSAlignmentConfiguration::SectorConfig scfg_
uint32_t arm() const
Definition: CTPPSDetId.h:51
ParameterDescriptionBase * add(U const &iLabel, T const &value)
edm::EDGetTokenT< CTPPSLocalTrackLiteCollection > tracksToken_
Log< level::Info, false > LogInfo
#define debug
Definition: HDRShower.cc:19
std::vector< CTPPSLocalTrackLite > CTPPSLocalTrackLiteCollection
Collection of CTPPSLocalTrackLite objects.
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
MonitorElement * book2DD(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, FUNC onbooking=NOOP())
Definition: DQMStore.h:261
Base class for CTPPS detector IDs.
Definition: CTPPSDetId.h:32
std::map< unsigned int, SlicePlots > x_slice_plots_N
edm::ESGetToken< PPSAlignmentConfiguration, PPSAlignmentConfigurationRcd > esTokenAnalyze_
std::map< unsigned int, MonitorElement * > m_h2_y_vs_x_mlt_sel
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
Definition: Run.h:45