CMS 3D CMS Logo

ApvTimingAnalysis.cc
Go to the documentation of this file.
5 #include <iostream>
6 #include <sstream>
7 #include <iomanip>
8 #include <cmath>
9 
10 using namespace sistrip;
11 
12 // ----------------------------------------------------------------------------
13 //
14 const float ApvTimingAnalysis::optimumSamplingPoint_ = 15.; // [ns]
15 
16 // ----------------------------------------------------------------------------
17 //
18 const float ApvTimingAnalysis::tickMarkHeightThreshold_ = 50.; // [ADC]
19 
20 // ----------------------------------------------------------------------------
21 //
22 const float ApvTimingAnalysis::frameFindingThreshold_ = (2. / 3.); // fraction of tick mark height
23 
24 // ----------------------------------------------------------------------------
25 //
27 
28 // ----------------------------------------------------------------------------
29 //
32  time_(1. * sistrip::invalid_),
33  error_(1. * sistrip::invalid_),
34  delay_(1. * sistrip::invalid_),
35  height_(1. * sistrip::invalid_),
36  base_(1. * sistrip::invalid_),
37  peak_(1. * sistrip::invalid_),
38  synchronized_(false) {
39  ;
40 }
41 
42 // ----------------------------------------------------------------------------
43 //
46  time_(1. * sistrip::invalid_),
47  error_(1. * sistrip::invalid_),
48  delay_(1. * sistrip::invalid_),
49  height_(1. * sistrip::invalid_),
50  base_(1. * sistrip::invalid_),
51  peak_(1. * sistrip::invalid_),
52  synchronized_(false) {
53  ;
54 }
55 
56 // ----------------------------------------------------------------------------
57 //
59  time_ = 1. * sistrip::invalid_;
63  base_ = 1. * sistrip::invalid_;
64  peak_ = 1. * sistrip::invalid_;
65  synchronized_ = false;
66 }
67 
68 // ----------------------------------------------------------------------------
69 //
70 void ApvTimingAnalysis::refTime(const float& time, const float& targetDelay) {
71  // Checks synchronization to reference time is done only once
72  if (synchronized_) {
73  edm::LogWarning(mlCommissioning_) << "[" << myName() << "::" << __func__ << "]"
74  << " Attempting to re-synchronize with reference time!"
75  << " Not allowed!";
76  return;
77  }
78  synchronized_ = true;
79 
80  // Set reference time and check if tick mark time is valid
81  refTime_ = time;
82  if (time_ > sistrip::valid_) {
83  return;
84  }
85 
86  // Calculate position of "sampling point" of last tick;
87  int32_t position;
88  if (targetDelay == -1) { // by default use latest tick
89  position = static_cast<int32_t>(rint(refTime_ + optimumSamplingPoint_));
90  } else {
91  position = static_cast<int32_t>(rint(targetDelay + optimumSamplingPoint_));
92  }
93 
94  // Calculate adjustment so that sampling point is multiple of 25 (ie, synched with FED sampling)
95  float adjustment = 25 - position % 25;
96 
97  // Calculate delay required to synchronise with this adjusted sampling position
98  if (targetDelay == -1) { // by default align forward to the latest tick
99  delay_ = (refTime_ + adjustment) - time_;
100  } else { // otherwise use the supplied target delay
101  if (adjustment > 25 / 2)
102  adjustment -= 25; // go as close as possible to desired target
103  delay_ = (targetDelay + adjustment) - time_;
104  }
105 
106  // Check reference time
107  if (refTime_ < 0. || refTime_ > sistrip::valid_) {
110  }
111 
112  // Check delay is valid
113  if (delay_ < -sistrip::valid_ || delay_ > sistrip::valid_) {
116  }
117 }
118 
119 // ----------------------------------------------------------------------------
120 //
122  if ((getErrorCodes().empty() || getErrorCodes()[0] == "TickMarkRecovered") && time_ < sistrip::valid_ &&
125  return ((static_cast<uint16_t>(base_ + height_ * ApvTimingAnalysis::frameFindingThreshold_) / 32) * 32);
126  } else {
127  return sistrip::invalid_;
128  }
129 }
130 
131 // ----------------------------------------------------------------------------
132 //
134  return ((getErrorCodes().empty() || getErrorCodes()[0] == "TickMarkRecovered") && time_ < sistrip::valid_ &&
137 }
138 
139 // ----------------------------------------------------------------------------
140 //
142  return ((getErrorCodes().empty() || getErrorCodes()[0] == "TickMarkRecovered") && time_ < sistrip::valid_ &&
146 }
147 
148 // ----------------------------------------------------------------------------
149 //
150 void ApvTimingAnalysis::print(std::stringstream& ss, uint32_t not_used) {
151  header(ss);
152 
153  float sampling1 = sistrip::invalid_;
154  if (time_ <= sistrip::valid_) {
155  sampling1 = time_ + optimumSamplingPoint_;
156  }
157 
158  float sampling2 = sistrip::invalid_;
159  if (refTime_ <= sistrip::valid_) {
160  sampling2 = refTime_ + optimumSamplingPoint_;
161  }
162 
163  float adjust = sistrip::invalid_;
164  if (sampling1 <= sistrip::valid_ && delay_ <= sistrip::valid_) {
165  adjust = sampling1 + delay_;
166  }
167 
168  ss << std::fixed << std::setprecision(2) << " Tick mark: time of rising edge [ns] : " << time_
169  << std::endl
170  //<< " Error on time of rising edge [ns] : " << error_ << std::endl
171  << " Tick mark: time of sampling point [ns] : " << sampling1 << std::endl
172  << " Ref tick: time of rising edge [ns] : " << refTime_ << std::endl
173  << " Ref tick: time of sampling point [ns] : " << sampling2 << std::endl
174  << " Ref tick: adjusted sampling point [ns] : " << adjust << std::endl
175  << " Delay required to synchronise [ns] : " << delay_ << std::endl
176  << " Tick mark bottom (baseline) [ADC] : " << base_ << std::endl
177  << " Tick mark top [ADC] : " << peak_ << std::endl
178  << " Tick mark height [ADC] : " << height_ << std::endl
179  << " Frame finding threshold [ADC] : " << frameFindingThreshold() << std::endl
180  << std::boolalpha << " Tick mark found : " << foundTickMark() << std::endl
181  << " isValid : " << isValid() << std::endl
182  << std::noboolalpha << " Error codes (found " << std::setw(3) << std::setfill(' ') << getErrorCodes().size()
183  << ") : ";
184  if (getErrorCodes().empty()) {
185  ss << "(none)";
186  } else {
187  VString::const_iterator istr = getErrorCodes().begin();
188  VString::const_iterator jstr = getErrorCodes().end();
189  for (; istr != jstr; ++istr) {
190  ss << *istr << " ";
191  }
192  }
193  ss << std::endl;
194 }
const VString & getErrorCodes() const
bool foundTickMark() const
static const float tickMarkHeightThreshold_
static const uint16_t valid_
Definition: Constants.h:17
sistrip classes
const std::string & myName() const
static const char mlCommissioning_[]
void addErrorCode(const std::string &error) override
bool isValid() const override
const float & time() const
void print(std::stringstream &, uint32_t not_used=0) override
key
prepare the HTCondor submission files and eventually submit them
static const char apvTimingAnalysis_[]
const float & refTime() const
static const char invalidRefTime_[]
static const float optimumSamplingPoint_
static const uint16_t invalid_
Definition: Constants.h:16
static float refTime_
virtual void header(std::stringstream &) const
static int position[264][3]
Definition: ReadPGInfo.cc:289
Abstract base for derived classes that provide analysis of commissioning histograms.
Log< level::Warning, false > LogWarning
uint16_t frameFindingThreshold() const
static const float frameFindingThreshold_
static const char invalidDelayTime_[]
void reset() override