CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
FedTimingAlgorithm Class Reference

Algorithm for timing run using APV tick marks. More...

#include <FedTimingAlgorithm.h>

Inheritance diagram for FedTimingAlgorithm:
CommissioningAlgorithm

Public Member Functions

 FedTimingAlgorithm (const edm::ParameterSet &pset, FedTimingAnalysis *const)
 
const Histohisto () const
 
 ~FedTimingAlgorithm () override
 
- Public Member Functions inherited from CommissioningAlgorithm
void analysis (const std::vector< TH1 *> &)
 
 CommissioningAlgorithm (CommissioningAnalysis *const)
 
 CommissioningAlgorithm ()
 
virtual ~CommissioningAlgorithm ()
 

Private Member Functions

void analyse () override
 
void extract (const std::vector< TH1 *> &) override
 
 FedTimingAlgorithm ()
 

Private Attributes

Histo histo_
 

Additional Inherited Members

- Public Types inherited from CommissioningAlgorithm
typedef std::pair< TH1 *, std::string > Histo
 
- Protected Member Functions inherited from CommissioningAlgorithm
CommissioningAnalysis *const anal () const
 
uint32_t extractFedKey (const TH1 *const)
 

Detailed Description

Algorithm for timing run using APV tick marks.

Author
M. Wingham, R.Bainbridge

Definition at line 17 of file FedTimingAlgorithm.h.

Constructor & Destructor Documentation

◆ FedTimingAlgorithm() [1/2]

FedTimingAlgorithm::FedTimingAlgorithm ( const edm::ParameterSet pset,
FedTimingAnalysis * const  anal 
)

Definition at line 16 of file FedTimingAlgorithm.cc.

17  : CommissioningAlgorithm(anal), histo_(nullptr, "") {
18  ;
19 }
CommissioningAnalysis *const anal() const

◆ ~FedTimingAlgorithm()

FedTimingAlgorithm::~FedTimingAlgorithm ( )
inlineoverride

Definition at line 21 of file FedTimingAlgorithm.h.

21 { ; }

◆ FedTimingAlgorithm() [2/2]

FedTimingAlgorithm::FedTimingAlgorithm ( )
inlineprivate

Definition at line 26 of file FedTimingAlgorithm.h.

26 { ; }

Member Function Documentation

◆ analyse()

void FedTimingAlgorithm::analyse ( )
overrideprivatevirtual

Performs histogram anaylsis.

Implements CommissioningAlgorithm.

Definition at line 63 of file FedTimingAlgorithm.cc.

References CommissioningAnalysis::addErrorCode(), CommissioningAlgorithm::anal(), newFWLiteAna::base, newFWLiteAna::bin, funct::derivative(), SelectiveReadoutTask_cfi::edges, newFWLiteAna::found, histo_, cuy::ii, sistrip::invalid_, SiStripPI::max, SiStripPI::mean, SiStripPI::min, sistrip::missingTickMark_, sistrip::mlCommissioning_, LaserClient_cfi::nbins, sistrip::nullPtr_, sistrip::numberOfBins_, FastTimerService_cff::range, sistrip::smallDataRange_, jetUpdater_cfi::sort, mathSSE::sqrt(), DiMuonV_cfg::threshold, createJobs::tmp, and validateGeometry_cfg::valid.

63  {
64  if (!anal()) {
65  edm::LogWarning(mlCommissioning_) << "[FedTimingAlgorithm::" << __func__ << "]"
66  << " NULL pointer to base Analysis object!";
67  return;
68  }
69 
71  FedTimingAnalysis* anal = dynamic_cast<FedTimingAnalysis*>(tmp);
72  if (!anal) {
73  edm::LogWarning(mlCommissioning_) << "[FedTimingAlgorithm::" << __func__ << "]"
74  << " NULL pointer to derived Analysis object!";
75  return;
76  }
77 
78  if (!histo_.first) {
80  return;
81  }
82 
83  // Transfer histogram contents/errors/stats to containers
84  float max = -1.e9;
85  float min = 1.e9;
86  uint16_t nbins = static_cast<uint16_t>(histo_.first->GetNbinsX());
87  std::vector<float> bin_contents;
88  std::vector<float> bin_errors;
89  std::vector<float> bin_entries;
90  bin_contents.reserve(nbins);
91  bin_errors.reserve(nbins);
92  bin_entries.reserve(nbins);
93  for (uint16_t ibin = 0; ibin < nbins; ibin++) {
94  bin_contents.push_back(histo_.first->GetBinContent(ibin + 1));
95  bin_errors.push_back(histo_.first->GetBinError(ibin + 1));
96  //bin_entries.push_back( histo_.first->GetBinEntries(ibin+1) );
97  if (bin_entries[ibin]) {
98  if (bin_contents[ibin] > max) {
99  max = bin_contents[ibin];
100  }
101  if (bin_contents[ibin] < min) {
102  min = bin_contents[ibin];
103  }
104  }
105  }
106 
107  if (bin_contents.size() < 100) {
109  return;
110  }
111 
112  // Calculate range (max-min) and threshold level (range/2)
113  float range = max - min;
114  float threshold = min + range / 2.;
115  if (range < 50.) {
117  return;
118  }
119  //LogTrace(mlCommissioning_) << " ADC samples: max/min/range/threshold: "
120  //<< max << "/" << min << "/" << range << "/" << threshold;
121 
122  // Associate samples with either "tick mark" or "baseline"
123  std::vector<float> tick;
124  std::vector<float> base;
125  for (uint16_t ibin = 0; ibin < nbins; ibin++) {
126  if (bin_entries[ibin]) {
127  if (bin_contents[ibin] < threshold) {
128  base.push_back(bin_contents[ibin]);
129  } else {
130  tick.push_back(bin_contents[ibin]);
131  }
132  }
133  }
134  //LogTrace(mlCommissioning_) << " Number of 'tick mark' samples: " << tick.size()
135  //<< " Number of 'baseline' samples: " << base.size();
136 
137  // Find median level of tick mark and baseline
138  float tickmark = 0.;
139  float baseline = 0.;
140  sort(tick.begin(), tick.end());
141  sort(base.begin(), base.end());
142  if (!tick.empty()) {
143  tickmark = tick[tick.size() % 2 ? tick.size() / 2 : tick.size() / 2];
144  }
145  if (!base.empty()) {
146  baseline = base[base.size() % 2 ? base.size() / 2 : base.size() / 2];
147  }
148  //LogTrace(mlCommissioning_) << " Tick mark level: " << tickmark << " Baseline level: " << baseline
149  //<< " Range: " << (tickmark-baseline);
150  if ((tickmark - baseline) < 50.) {
152  return;
153  }
154 
155  // Find rms spread in "baseline" samples
156  float mean = 0.;
157  float mean2 = 0.;
158  for (uint16_t ibin = 0; ibin < base.size(); ibin++) {
159  mean += base[ibin];
160  mean2 += base[ibin] * base[ibin];
161  }
162  if (!base.empty()) {
163  mean = mean / base.size();
164  mean2 = mean2 / base.size();
165  } else {
166  mean = 0.;
167  mean2 = 0.;
168  }
169  float baseline_rms = 0.;
170  if (mean2 > mean * mean) {
171  baseline_rms = sqrt(mean2 - mean * mean);
172  } else {
173  baseline_rms = 0.;
174  }
175  //LogTrace(mlCommissioning_) << " Spread in baseline samples: " << baseline_rms;
176 
177  // Find rising edges (derivative across two bins > range/2)
178  std::map<uint16_t, float> edges;
179  for (uint16_t ibin = 1; ibin < nbins - 1; ibin++) {
180  if (bin_entries[ibin + 1] && bin_entries[ibin - 1]) {
181  float derivative = bin_contents[ibin + 1] - bin_contents[ibin - 1];
182  if (derivative > 5. * baseline_rms) {
183  edges[ibin] = derivative;
184  //LogTrace(mlCommissioning_) << " Found edge #" << edges.size() << " at bin " << ibin
185  //<< " and with derivative " << derivative;
186  }
187  }
188  }
189 
190  // Iterate through "edges" std::map
191  bool found = false;
192  uint16_t deriv_bin = sistrip::invalid_;
193  float max_deriv = -1. * sistrip::invalid_;
194  std::map<uint16_t, float>::iterator iter = edges.begin();
195  while (!found && iter != edges.end()) {
196  // Iterate through 50 subsequent samples
197  bool valid = true;
198  for (uint16_t ii = 0; ii < 50; ii++) {
199  uint16_t bin = iter->first + ii;
200 
201  // Calc local derivative
202  float temp_deriv = 0;
203  if (static_cast<uint32_t>(bin) < 1 || static_cast<uint32_t>(bin + 1) >= nbins) {
204  continue;
205  }
206  temp_deriv = bin_contents[bin + 1] - bin_contents[bin - 1];
207 
208  // Store max derivative
209  if (temp_deriv > max_deriv) {
210  max_deriv = temp_deriv;
211  deriv_bin = bin;
212  }
213 
214  // Check if samples following edge are all "high"
215  if (ii > 10 && ii < 40 && bin_entries[bin] && bin_contents[bin] < baseline + 5 * baseline_rms) {
216  valid = false;
217  }
218  }
219 
220  // Break from loop if tick mark found
221  if (valid) {
222  found = true;
223  } else {
224  max_deriv = -1. * sistrip::invalid_;
225  deriv_bin = sistrip::invalid_;
226  edges.erase(iter);
227  }
228 
229  iter++;
230  }
231 
232  // Set monitorables (but not PLL coarse and fine here)
233  if (!edges.empty()) {
234  anal->time_ = deriv_bin;
235  anal->error_ = 0.;
236  anal->base_ = baseline;
237  anal->peak_ = tickmark;
238  anal->height_ = tickmark - baseline;
239  } else {
241  anal->base_ = baseline;
242  anal->peak_ = tickmark;
243  anal->height_ = tickmark - baseline;
244  }
245 }
CommissioningAnalysis *const anal() const
Derivative< X, A >::type derivative(const A &_)
Definition: Derivative.h:18
base
Main Program
Definition: newFWLiteAna.py:92
static const char numberOfBins_[]
static const char missingTickMark_[]
static const char mlCommissioning_[]
T sqrt(T t)
Definition: SSEVec.h:19
virtual void addErrorCode(const std::string &error)
Analysis for timing run using APV tick marks.
ii
Definition: cuy.py:589
static const uint16_t invalid_
Definition: Constants.h:16
static const char smallDataRange_[]
Abstract base for derived classes that provide analysis of commissioning histograms.
Log< level::Warning, false > LogWarning
tmp
align.sh
Definition: createJobs.py:716
static const char nullPtr_[]

◆ extract()

void FedTimingAlgorithm::extract ( const std::vector< TH1 *> &  )
overrideprivatevirtual

Extracts and organises histograms.

Implements CommissioningAlgorithm.

Definition at line 23 of file FedTimingAlgorithm.cc.

References CommissioningAnalysis::addErrorCode(), CommissioningAlgorithm::anal(), CommissioningAlgorithm::extractFedKey(), sistrip::FED_TIMING, CommissioningAnalysis::fedKey(), histo_, combine::histos, sistrip::mlCommissioning_, sistrip::numberOfHistos_, runGCPTkAlMap::title, and sistrip::unexpectedTask_.

23  {
24  if (!anal()) {
25  edm::LogWarning(mlCommissioning_) << "[FedTimingAlgorithm::" << __func__ << "]"
26  << " NULL pointer to Analysis object!";
27  return;
28  }
29 
30  // Check number of histograms
31  if (histos.size() != 1) {
33  }
34 
35  // Extract FED key from histo title
36  if (!histos.empty()) {
37  anal()->fedKey(extractFedKey(histos.front()));
38  }
39 
40  // Extract histograms
41  std::vector<TH1*>::const_iterator ihis = histos.begin();
42  for (; ihis != histos.end(); ihis++) {
43  // Check for NULL pointer
44  if (!(*ihis)) {
45  continue;
46  }
47 
48  // Check name
49  SiStripHistoTitle title((*ihis)->GetName());
50  if (title.runType() != sistrip::FED_TIMING) {
52  continue;
53  }
54 
55  // Extract timing histo
56  histo_.first = *ihis;
57  histo_.second = (*ihis)->GetName();
58  }
59 }
CommissioningAnalysis *const anal() const
static const char unexpectedTask_[]
Utility class that holds histogram title.
static const char numberOfHistos_[]
uint32_t extractFedKey(const TH1 *const)
static const char mlCommissioning_[]
virtual void addErrorCode(const std::string &error)
const uint32_t & fedKey() const
histos
Definition: combine.py:4
Log< level::Warning, false > LogWarning

◆ histo()

const FedTimingAlgorithm::Histo & FedTimingAlgorithm::histo ( ) const
inline

Definition at line 37 of file FedTimingAlgorithm.h.

References histo_.

37 { return histo_; }

Member Data Documentation

◆ histo_

Histo FedTimingAlgorithm::histo_
private

APV tick mark

Definition at line 34 of file FedTimingAlgorithm.h.

Referenced by analyse(), extract(), and histo().