CMS 3D CMS Logo

ApvTimingHistograms.cc
Go to the documentation of this file.
8 #include "TProfile.h"
9 #include <iostream>
10 #include <memory>
11 
12 #include <sstream>
13 #include <iomanip>
14 
15 using namespace std;
16 using namespace sistrip;
17 
18 // -----------------------------------------------------------------------------
21  : CommissioningHistograms(pset.getParameter<edm::ParameterSet>("ApvTimingParameters"), bei, sistrip::APV_TIMING) {
22  factory_ = std::make_unique<ApvTimingSummaryFactory>();
23  LogTrace(mlDqmClient_) << "[ApvTimingHistograms::" << __func__ << "]"
24  << " Constructing object...";
25 }
26 
27 // -----------------------------------------------------------------------------
30  LogTrace(mlDqmClient_) << "[ApvTimingHistograms::" << __func__ << "]"
31  << " Destructing object...";
32 }
33 
34 // -----------------------------------------------------------------------------
37  LogTrace(mlDqmClient_) << "[ApvTimingHistograms::" << __func__ << "]";
38 
39  // Some initialisation
40  uint16_t valid = 0;
41  HistosMap::const_iterator iter;
42  Analyses::iterator ianal;
43  std::map<std::string, uint16_t> errors;
44 
45  // Clear map holding analysis objects
46  for (ianal = data().begin(); ianal != data().end(); ianal++) {
47  if (ianal->second) {
48  delete ianal->second;
49  }
50  }
51  data().clear();
52 
53  // Reset minimum / maximum delays
54  float time_min = 1. * sistrip::invalid_;
55  float time_max = -1. * sistrip::invalid_;
56  uint32_t device_min = sistrip::invalid_;
57  uint32_t device_max = sistrip::invalid_;
58 
59  // Iterate through map containing histograms
60  for (iter = histos().begin(); iter != histos().end(); iter++) {
61  // Check vector of histos is not empty
62  if (iter->second.empty()) {
63  edm::LogWarning(mlDqmClient_) << "[ApvTimingHistograms::" << __func__ << "]"
64  << " Zero histograms found!";
65  continue;
66  }
67 
68  // Retrieve pointers to histos
69  std::vector<TH1*> profs;
70  Histos::const_iterator ihis = iter->second.begin();
71  for (; ihis != iter->second.end(); ihis++) {
72  TProfile* prof = ExtractTObject<TProfile>().extract((*ihis)->me_);
73  if (prof) {
74  profs.push_back(prof);
75  }
76  }
77 
78  // Perform histo analysis
79  ApvTimingAnalysis* anal = new ApvTimingAnalysis(iter->first);
80  ApvTimingAlgorithm algo(this->pset(), anal);
81  algo.analysis(profs);
82  data()[iter->first] = anal;
83 
84  // Check if tick mark found
85  if (!anal->foundTickMark()) {
86  continue;
87  }
88 
89  // Find maximum time
90  if (anal->time() > time_max) {
91  time_max = anal->time();
92  device_max = iter->first;
93  }
94 
95  // Find minimum time
96  if (anal->time() < time_min) {
97  time_min = anal->time();
98  device_min = iter->first;
99  }
100  }
101 
102  // Adjust maximum (and minimum) delay(s) to find optimum sampling point(s)
103  if (time_max > sistrip::valid_ || time_max < -1. * sistrip::valid_) {
104  edm::LogWarning(mlDqmClient_) << "[ApvTimingHistograms::" << __func__ << "]"
105  << " Unable to set maximum time! Found unexpected value: " << time_max;
106 
107  } else {
108  SiStripFecKey min(device_min);
109  edm::LogVerbatim(mlDqmClient_) << "[ApvTimingHistograms::" << __func__ << "]"
110  << " Crate/FEC/Ring/CCU/module/channel: " << min.fecCrate() << "/" << min.fecSlot()
111  << "/" << min.fecRing() << "/" << min.ccuAddr() << "/" << min.ccuChan() << "/"
112  << min.lldChan() << " has minimum time for tick mark rising edge [ns]: " << time_min;
113 
114  SiStripFecKey max(device_max);
115  edm::LogVerbatim(mlDqmClient_) << "[ApvTimingHistograms::" << __func__ << "]"
116  << " Crate/FEC/Ring/CCU/module/channel: " << max.fecCrate() << "/" << max.fecSlot()
117  << "/" << max.fecRing() << "/" << max.ccuAddr() << "/" << max.ccuChan() << "/"
118  << max.lldChan() << " has maximum time for tick mark rising edge [ns]: " << time_max;
119 
120  edm::LogVerbatim(mlDqmClient_) << "[ApvTimingHistograms::" << __func__ << "]"
121  << " Difference b/w minimum and maximum times"
122  << " for tick mark rising edges [ns] is: " << (time_max - time_min);
123  }
124 
125  // Set reference time for all analysis objects
126  for (ianal = data().begin(); ianal != data().end(); ianal++) {
127  ApvTimingAnalysis* anal = dynamic_cast<ApvTimingAnalysis*>(ianal->second);
128  if (!anal) {
129  continue;
130  }
131  anal->refTime(time_max, this->pset().getParameter<int>("TargetDelay"));
132  if (anal->isValid()) {
133  valid++;
134  }
135  if (!anal->getErrorCodes().empty()) {
136  errors[anal->getErrorCodes()[0]]++;
137  }
138  }
139 
140  if (!histos().empty()) {
141  edm::LogVerbatim(mlDqmClient_) << "[ApvTimingHistograms::" << __func__ << "]"
142  << " Analyzed histograms for " << histos().size() << " FED channels, of which "
143  << valid << " (" << 100 * valid / histos().size() << "%) are valid.";
144  } else {
145  edm::LogWarning(mlDqmClient_) << "[ApvTimingHistograms::" << __func__ << "]"
146  << " No histograms to analyze!";
147  }
148 
149  if (!histos().empty()) {
150  edm::LogVerbatim(mlDqmClient_) << "[ApvTimingHistograms::" << __func__ << "]"
151  << " Analyzed histograms for " << histos().size() << " FED channels, of which "
152  << valid << " (" << 100 * valid / histos().size() << "%) are valid.";
153  if (!errors.empty()) {
154  uint16_t count = 0;
155  std::stringstream ss;
156  ss << std::endl;
157  std::map<std::string, uint16_t>::const_iterator ii;
158  for (ii = errors.begin(); ii != errors.end(); ++ii) {
159  ss << " " << ii->first << ": " << ii->second << std::endl;
160  count += ii->second;
161  }
162  edm::LogWarning(mlDqmClient_) << "[ApvTimingHistograms::" << __func__ << "]"
163  << " Found " << count << " errors (" << 100 * count / histos().size()
164  << "%): " << ss.str();
165  }
166  } else {
167  edm::LogWarning(mlDqmClient_) << "[ApvTimingHistograms::" << __func__ << "]"
168  << " No histograms to analyze!";
169  }
170 }
Log< level::Info, true > LogVerbatim
const HistosMap & histos() const
Analyses & data(bool getMaskedData=false)
Analysis for timing run using APV tick marks.
static const char mlDqmClient_[]
static const uint16_t valid_
Definition: Constants.h:17
sistrip classes
#define LogTrace(id)
Utility class that identifies a position within the strip tracker control structure, down to the level of an APV25.
Definition: SiStripFecKey.h:45
void histoAnalysis(bool debug) override
ii
Definition: cuy.py:589
int extract(std::vector< int > *output, const std::string &dati)
#define debug
Definition: HDRShower.cc:19
std::unique_ptr< Factory > factory_
static const uint16_t invalid_
Definition: Constants.h:16
HLT enums.
const edm::ParameterSet & pset() const
Definition: errors.py:1
Log< level::Warning, false > LogWarning
Analysis for timing run using APV tick marks.
ApvTimingHistograms(const edm::ParameterSet &pset, DQMStore *)