CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
AlignPCLThresholdPlotHelper::AlignPCLThresholds_CompareBase< PayloadType, nIOVs, ntags > Class Template Reference

#include <SiPixelAliPCLThresholdsPayloadInspectorHelper.h>

Inheritance diagram for AlignPCLThresholdPlotHelper::AlignPCLThresholds_CompareBase< PayloadType, nIOVs, ntags >:
cond::payloadInspector::PlotImage< PayloadType, nIOVs, ntags > cond::payloadInspector::PlotImpl< IOV_M, NTAGS > cond::payloadInspector::PlotBase

Public Member Functions

 AlignPCLThresholds_CompareBase ()
 
bool fill () override
 
- Public Member Functions inherited from cond::payloadInspector::PlotImage< PayloadType, nIOVs, ntags >
std::shared_ptr< PayloadType > fetchPayload (const cond::Hash &payloadHash)
 
 PlotImage (const std::string &title)
 
std::string serializeData () override
 
- Public Member Functions inherited from cond::payloadInspector::PlotImpl< IOV_M, NTAGS >
 PlotImpl (const std::string &type, const std::string &title)
 
std::string processData () override
 
 ~PlotImpl () override=default
 
- Public Member Functions inherited from cond::payloadInspector::PlotBase
void addInputParam (const std::string &paramName)
 
cond::persistency::Session dbSession ()
 
template<typename PayloadType >
std::shared_ptr< PayloadType > fetchPayload (const cond::Hash &payloadHash)
 
template<int index>
TagReference getTag ()
 
cond::Tag_t getTagInfo (const std::string &tag)
 
virtual void init ()
 
const std::map< std::string, std::string > & inputParamValues () const
 
bool isSingleIov () const
 
bool isTwoTags () const
 
unsigned int ntags () const
 
std::string payloadType () const
 
 PlotBase ()
 
std::string title () const
 
std::string type () const
 
virtual ~PlotBase ()=default
 

Private Member Functions

template<typename T >
bool isEqual (std::vector< T > const &v1, std::vector< T > const &v2)
 

Private Attributes

bool isHighGranularity_
 
std::string label_
 

Additional Inherited Members

- Public Types inherited from cond::payloadInspector::PlotImage< PayloadType, nIOVs, ntags >
typedef PlotImpl< IOV_M, NTAGS > Base
 
- Protected Attributes inherited from cond::payloadInspector::PlotImage< PayloadType, nIOVs, ntags >
std::string m_imageFileName
 
- Protected Attributes inherited from cond::payloadInspector::PlotBase
std::set< std::string > m_inputParams
 
std::map< std::string, std::string > m_inputParamValues
 
PlotAnnotations m_plotAnnotations
 
std::vector< std::pair< cond::Time_t, cond::Time_t > > m_tagBoundaries
 
std::vector< std::vector< std::tuple< cond::Time_t, cond::Hash > > > m_tagIovs
 
std::vector< std::string > m_tagNames
 

Detailed Description

template<class PayloadType, cond::payloadInspector::IOVMultiplicity nIOVs, int ntags>
class AlignPCLThresholdPlotHelper::AlignPCLThresholds_CompareBase< PayloadType, nIOVs, ntags >

Definition at line 209 of file SiPixelAliPCLThresholdsPayloadInspectorHelper.h.

Constructor & Destructor Documentation

◆ AlignPCLThresholds_CompareBase()

template<class PayloadType , cond::payloadInspector::IOVMultiplicity nIOVs, int ntags>
AlignPCLThresholdPlotHelper::AlignPCLThresholds_CompareBase< PayloadType, nIOVs, ntags >::AlignPCLThresholds_CompareBase ( )
inline

Member Function Documentation

◆ fill()

template<class PayloadType , cond::payloadInspector::IOVMultiplicity nIOVs, int ntags>
bool AlignPCLThresholdPlotHelper::AlignPCLThresholds_CompareBase< PayloadType, nIOVs, ntags >::fill ( )
inlineoverridevirtual

Implements cond::payloadInspector::PlotImpl< IOV_M, NTAGS >.

Definition at line 222 of file SiPixelAliPCLThresholdsPayloadInspectorHelper.h.

References cms::cuda::assert(), svgfig::canvas(), AlignPCLThresholdPlotHelper::DELTA, AlignPCLThresholdPlotHelper::END_OF_TYPES, AlignPCLThresholds::extra_DOF, cond::payloadInspector::PlotImage< PayloadType, nIOVs, ntags >::fetchPayload(), MillePedeFileConverter_cfg::fileName, custom_jme_cff::foo, AlignPCLThresholdPlotHelper::FRACTION_CUT, AlignPCLThresholdPlotHelper::getStringFromCoordEnum(), AlignPCLThresholdPlotHelper::getStringFromTypeEnum(), AlignPCLThresholdPlotHelper::AlignPCLThresholds_CompareBase< PayloadType, nIOVs, ntags >::isEqual(), AlignPCLThresholdPlotHelper::AlignPCLThresholds_CompareBase< PayloadType, nIOVs, ntags >::isHighGranularity_, crabWrapper::key, AlignPCLThresholdPlotHelper::AlignPCLThresholds_CompareBase< PayloadType, nIOVs, ntags >::label_, cond::payloadInspector::PlotImage< PayloadType, nIOVs, ntags >::m_imageFileName, cond::payloadInspector::PlotBase::m_plotAnnotations, AlignPCLThresholdPlotHelper::MAXERR, AlignPCLThresholdPlotHelper::MAXMOVE, Skims_PA_cff::name, cond::payloadInspector::PlotAnnotations::ntags, AlignPCLThresholdPlotHelper::replaceAll(), runTheMatrix::ret, DBoxMetadataHelper::set_difference(), DBoxMetadataHelper::set_intersection(), AlignPCLThresholdPlotHelper::SIG, contentValuesCheck::ss, AlCaHLTBitMon_QueryRunRegistry::string, HLT_2023v11_cff::Thresholds, cond::impl::to_string(), X, photonAnalyzer_cfi::xBin, and photonAnalyzer_cfi::yBin.

222  {
223  gStyle->SetPalette(kTemperatureMap);
224 
225  // to be able to see zeros
226  gStyle->SetHistMinimumZero(kTRUE);
227 
228  // trick to deal with the multi-ioved tag and two tag case at the same time
229  auto theIOVs = cond::payloadInspector::PlotBase::getTag<0>().iovs;
230  auto f_tagname = cond::payloadInspector::PlotBase::getTag<0>().name;
231  std::string l_tagname = "";
232  auto firstiov = theIOVs.front();
233  std::tuple<cond::Time_t, cond::Hash> lastiov;
234 
235  // we don't support (yet) comparison with more than 2 tags
236  assert(this->m_plotAnnotations.ntags < 3);
237 
238  if (this->m_plotAnnotations.ntags == 2) {
239  auto tag2iovs = cond::payloadInspector::PlotBase::getTag<1>().iovs;
240  l_tagname = cond::payloadInspector::PlotBase::getTag<1>().name;
241  lastiov = tag2iovs.front();
242  } else {
243  lastiov = theIOVs.back();
244  }
245 
246  std::shared_ptr<PayloadType> l_payload = this->fetchPayload(std::get<1>(lastiov));
247  std::shared_ptr<PayloadType> f_payload = this->fetchPayload(std::get<1>(firstiov));
248 
249  std::string lastIOVsince = std::to_string(std::get<0>(lastiov));
250  std::string firstIOVsince = std::to_string(std::get<0>(firstiov));
251 
252  const auto& alignables = l_payload->getAlignableList();
253  const auto& alignables2 = f_payload->getAlignableList();
254 
255  std::vector<std::string> v_intersection;
256 
257  if (!isEqual(alignables, alignables2)) {
259  << "Cannot compare directly the two AlignPCLThresholds objects, as the list of alignables differs";
260  std::set_intersection(alignables.begin(),
261  alignables.end(),
262  alignables2.begin(),
263  alignables2.end(),
264  std::back_inserter(v_intersection));
265 
266  std::vector<std::string> not_in_first_keys, not_in_last_keys;
267 
268  // find the elements not in common
269  std::set_difference(alignables.begin(),
270  alignables.end(),
271  alignables2.begin(),
272  alignables2.end(),
273  std::inserter(not_in_last_keys, not_in_last_keys.begin()));
274 
275  std::stringstream ss;
276  ss << "the following keys are not in the last IoV: ";
277  for (const auto& key : not_in_last_keys) {
278  ss << key << ",";
279  }
280  ss << std::endl;
281  edm::LogWarning(label_) << ss.str();
282  ss.str(std::string()); /* clear the stream */
283 
284  std::set_difference(alignables2.begin(),
285  alignables2.end(),
286  alignables.begin(),
287  alignables.end(),
288  std::inserter(not_in_first_keys, not_in_first_keys.begin()));
289 
290  ss << "the following keys are not in the first IoV: ";
291  for (const auto& key : not_in_first_keys) {
292  ss << key << ",";
293  }
294  ss << std::endl;
295  edm::LogWarning(label_) << ss.str();
296  } else {
297  // vectors are the same, just copy one
298  v_intersection = alignables;
299  }
300 
301  TCanvas canvas("Alignment PCL thresholds summary", "Alignment PCL thresholds summary", 1500, 800);
302  canvas.cd();
303 
304  canvas.SetTopMargin(0.07);
305  canvas.SetBottomMargin(isHighGranularity_ ? 0.20 : 0.06);
306  canvas.SetLeftMargin(0.11);
307  canvas.SetRightMargin(0.12);
308  canvas.Modified();
309  canvas.SetGrid();
310 
311  // needed for the internal loop
312  const auto& local_end_of_types = isHighGranularity_ ? END_OF_TYPES : FRACTION_CUT;
313  const int N_Y_BINS = AlignPCLThresholds::extra_DOF * local_end_of_types;
314 
315  auto Thresholds = std::make_unique<TH2F>(
316  "Thresholds", "", v_intersection.size(), 0, v_intersection.size(), N_Y_BINS, 0, N_Y_BINS);
317  Thresholds->SetStats(false);
318  Thresholds->GetXaxis()->SetLabelSize(0.028);
319 
320  auto ThresholdsColor = std::make_unique<TH2F>(
321  "ThresholdsC", "", v_intersection.size(), 0, v_intersection.size(), N_Y_BINS, 0, N_Y_BINS);
322  ThresholdsColor->SetStats(false);
323  ThresholdsColor->GetXaxis()->SetLabelSize(0.028);
324 
325  std::function<float(types, std::string, AlignPCLThresholds::coordType)> cutFunctor =
326  [&f_payload, &l_payload](types my_type, std::string alignable, AlignPCLThresholds::coordType coord) {
327  float ret(-999.);
328  switch (my_type) {
329  case DELTA:
330  return l_payload->getCut(alignable, coord) - f_payload->getCut(alignable, coord);
331  case SIG:
332  return l_payload->getSigCut(alignable, coord) - f_payload->getSigCut(alignable, coord);
333  case MAXMOVE:
334  return l_payload->getMaxMoveCut(alignable, coord) - f_payload->getMaxMoveCut(alignable, coord);
335  case MAXERR:
336  return l_payload->getMaxErrorCut(alignable, coord) - f_payload->getMaxErrorCut(alignable, coord);
337  case FRACTION_CUT: {
338  if constexpr (std::is_same_v<PayloadType, AlignPCLThresholdsHG>) {
339  const AlignPCLThresholdsHG::param_map& f_floatMap = f_payload->getFloatMap();
340  const AlignPCLThresholdsHG::param_map& l_floatMap = l_payload->getFloatMap();
341  if (f_floatMap.find(alignable) != f_floatMap.end() &&
342  l_floatMap.find(alignable) != l_floatMap.end()) {
343  return l_payload->getFractionCut(alignable, coord) - f_payload->getFractionCut(alignable, coord);
344  } else {
345  return +999.f;
346  }
347  } else {
348  assert(false); /* cannot be here */
349  }
350  }
351  case END_OF_TYPES:
352  return ret;
353  default:
354  return ret;
355  }
356  };
357 
358  unsigned int xBin = 0;
359  for (const auto& alignable : v_intersection) {
360  xBin++;
361  auto xLabel = replaceAll(replaceAll(alignable, "minus", "(-)"), "plus", "(+)");
362  Thresholds->GetXaxis()->SetBinLabel(xBin, (xLabel).c_str());
363  ThresholdsColor->GetXaxis()->SetBinLabel(xBin, (xLabel).c_str());
364  unsigned int yBin = N_Y_BINS;
365  for (int foo = PayloadType::X; foo != PayloadType::extra_DOF; foo++) {
367  for (int bar = DELTA; bar != local_end_of_types; bar++) {
368  types type = static_cast<types>(bar);
370  if (xBin == 1) {
371  Thresholds->GetYaxis()->SetBinLabel(yBin, theLabel.c_str());
372  ThresholdsColor->GetYaxis()->SetBinLabel(yBin, theLabel.c_str());
373  }
374 
375  const auto& value = cutFunctor(type, alignable, coord);
376  Thresholds->SetBinContent(xBin, yBin, value);
377  ThresholdsColor->SetBinContent(xBin, yBin, value);
378 
379  yBin--;
380  } // loop on types
381  } // loop on coordinates
382  } // loop on alignables
383 
384  ThresholdsColor->Draw("COLZ0");
385  ThresholdsColor->GetXaxis()->LabelsOption(isHighGranularity_ ? "v" : "h");
386  Thresholds->Draw("TEXTsame");
387  Thresholds->GetXaxis()->LabelsOption(isHighGranularity_ ? "v" : "h");
388 
389  auto ltx = TLatex();
390  ltx.SetTextFont(62);
391  //ltx.SetTextColor(kBlue);
392  ltx.SetTextSize(0.047);
393  ltx.SetTextAlign(11);
394  std::string ltxText;
395  if (this->m_plotAnnotations.ntags == 2) {
396  ltxText = fmt::sprintf("#color[2]{%s, %s} vs #color[4]{%s, %s}",
397  f_tagname,
398  std::to_string(std::get<0>(firstiov)),
399  l_tagname,
400  std::to_string(std::get<0>(lastiov)));
401  } else {
402  ltxText = fmt::sprintf("%s IOV: #color[2]{%s} vs IOV: #color[4]{%s}",
403  f_tagname,
404  std::to_string(std::get<0>(firstiov)),
405  std::to_string(std::get<0>(lastiov)));
406  }
407  ltx.DrawLatexNDC(gPad->GetLeftMargin(), 1 - gPad->GetTopMargin() + 0.01, ltxText.c_str());
408 
410  canvas.SaveAs(fileName.c_str());
411 
412  return true;
413  }
std::unordered_map< std::string, std::vector< float > > param_map
const std::string getStringFromCoordEnum(const AlignPCLThresholds::coordType &coord)
bool isEqual(std::vector< T > const &v1, std::vector< T > const &v2)
ret
prodAgent to be discontinued
const std::string getStringFromTypeEnum(const types &type)
#define X(str)
Definition: MuonsGrabber.cc:38
std::string to_string(const V &value)
Definition: OMSAccess.h:71
assert(be >=bs)
std::string replaceAll(const std::string &str, const std::string &from, const std::string &to)
Definition: value.py:1
def canvas(sub, attr)
Definition: svgfig.py:482
Log< level::Warning, false > LogWarning
std::vector< std::string > set_difference(std::vector< std::string > const &v1, std::vector< std::string > const &v2)
std::shared_ptr< PayloadType > fetchPayload(const cond::Hash &payloadHash)
std::vector< std::string > set_intersection(std::vector< std::string > const &v1, std::vector< std::string > const &v2)

◆ isEqual()

template<class PayloadType , cond::payloadInspector::IOVMultiplicity nIOVs, int ntags>
template<typename T >
bool AlignPCLThresholdPlotHelper::AlignPCLThresholds_CompareBase< PayloadType, nIOVs, ntags >::isEqual ( std::vector< T > const &  v1,
std::vector< T > const &  v2 
)
inlineprivate

Definition at line 417 of file SiPixelAliPCLThresholdsPayloadInspectorHelper.h.

References cond::serialization::equal().

Referenced by AlignPCLThresholdPlotHelper::AlignPCLThresholds_CompareBase< PayloadType, nIOVs, ntags >::fill().

417  {
418  return (v1.size() == v2.size() && std::equal(v1.begin(), v1.end(), v2.begin()));
419  }
bool equal(const T &first, const T &second)
Definition: Equal.h:32

Member Data Documentation

◆ isHighGranularity_

template<class PayloadType , cond::payloadInspector::IOVMultiplicity nIOVs, int ntags>
bool AlignPCLThresholdPlotHelper::AlignPCLThresholds_CompareBase< PayloadType, nIOVs, ntags >::isHighGranularity_
private

◆ label_

template<class PayloadType , cond::payloadInspector::IOVMultiplicity nIOVs, int ntags>
std::string AlignPCLThresholdPlotHelper::AlignPCLThresholds_CompareBase< PayloadType, nIOVs, ntags >::label_
private