CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 //
45  time_(1.*sistrip::invalid_),
46  error_(1.*sistrip::invalid_),
47  delay_(1.*sistrip::invalid_),
48  height_(1.*sistrip::invalid_),
49  base_(1.*sistrip::invalid_),
50  peak_(1.*sistrip::invalid_),
51  synchronized_(false)
52 {;}
53 
54 // ----------------------------------------------------------------------------
55 //
63  synchronized_ = false;
64 }
65 
66 // ----------------------------------------------------------------------------
67 //
68 void ApvTimingAnalysis::refTime( const float& time, const float& targetDelay ) {
69 
70  // Checks synchronization to reference time is done only once
71  if ( synchronized_ ) {
73  << "[" << 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_ ) { return; }
83 
84  // Calculate position of "sampling point" of last tick;
85  int32_t position;
86  if ( targetDelay == -1 ) { // by default use latest tick
87  position = static_cast<int32_t>( rint( refTime_ + optimumSamplingPoint_ ) );
88  } else {
89  position = static_cast<int32_t>( rint( targetDelay + optimumSamplingPoint_ ) );
90  }
91 
92  // Calculate adjustment so that sampling point is multiple of 25 (ie, synched with FED sampling)
93  float adjustment = 25 - position % 25;
94 
95  // Calculate delay required to synchronise with this adjusted sampling position
96  if ( targetDelay == -1 ) { // by default align forward to the latest tick
97  delay_ = ( refTime_ + adjustment ) - time_;
98  } else { // otherwise use the supplied target delay
99  if ( adjustment > 25/2 ) adjustment -= 25; // go as close as possible to desired target
100  delay_ = ( targetDelay + adjustment ) - time_;
101  }
102 
103  // Check reference time
104  if ( refTime_ < 0. || refTime_ > sistrip::valid_ ) {
107  }
108 
109  // Check delay is valid
110  if ( delay_ < -sistrip::valid_ || delay_ > sistrip::valid_ ) {
113  }
114 
115 }
116 
117 // ----------------------------------------------------------------------------
118 //
120  if ( ( getErrorCodes().empty() || getErrorCodes()[0] == "TickMarkRecovered" ) &&
122  base_ < sistrip::valid_ &&
123  peak_ < sistrip::valid_ &&
126  return ( ( static_cast<uint16_t>( base_ +
127  height_ *
129  } else { return sistrip::invalid_; }
130 }
131 
132 // ----------------------------------------------------------------------------
133 //
135  return ( ( getErrorCodes().empty() || getErrorCodes()[0] == "TickMarkRecovered") &&
141 }
142 
143 // ----------------------------------------------------------------------------
144 //
146  return ( ( getErrorCodes().empty() || getErrorCodes()[0] == "TickMarkRecovered" ) &&
152  synchronized_ &&
155 }
156 
157 // ----------------------------------------------------------------------------
158 //
159 void ApvTimingAnalysis::print( std::stringstream& ss, uint32_t not_used ) {
160  header( ss );
161 
162  float sampling1 = sistrip::invalid_;
163  if ( time_ <= sistrip::valid_ ) { sampling1 = time_ + optimumSamplingPoint_; }
164 
165  float sampling2 = sistrip::invalid_;
166  if ( refTime_ <= sistrip::valid_ ) { sampling2 = refTime_ + optimumSamplingPoint_; }
167 
168  float adjust = sistrip::invalid_;
169  if ( sampling1 <= sistrip::valid_ && delay_ <= sistrip::valid_ ) { adjust = sampling1 + delay_; }
170 
171  ss << std::fixed << std::setprecision(2)
172  << " Tick mark: time of rising edge [ns] : " << time_ << std::endl
173  //<< " Error on time of rising edge [ns] : " << error_ << std::endl
174  << " Tick mark: time of sampling point [ns] : " << sampling1 << std::endl
175  << " Ref tick: time of rising edge [ns] : " << refTime_ << std::endl
176  << " Ref tick: time of sampling point [ns] : " << sampling2 << std::endl
177  << " Ref tick: adjusted sampling point [ns] : " << adjust << std::endl
178  << " Delay required to synchronise [ns] : " << delay_ << std::endl
179  << " Tick mark bottom (baseline) [ADC] : " << base_ << std::endl
180  << " Tick mark top [ADC] : " << peak_ << std::endl
181  << " Tick mark height [ADC] : " << height_ << std::endl
182  << " Frame finding threshold [ADC] : " << frameFindingThreshold() << std::endl
183  << std::boolalpha
184  << " Tick mark found : " << foundTickMark() << std::endl
185  << " isValid : " << isValid() << std::endl
186  << std::noboolalpha
187  << " Error codes (found "
188  << std::setw(3) << std::setfill(' ') << getErrorCodes().size()
189  << ") : ";
190  if ( getErrorCodes().empty() ) { ss << "(none)"; }
191  else {
192  VString::const_iterator istr = getErrorCodes().begin();
193  VString::const_iterator jstr = getErrorCodes().end();
194  for ( ; istr != jstr; ++istr ) { ss << *istr << " "; }
195  }
196  ss << std::endl;
197 }
198 
const float & refTime() const
static const float tickMarkHeightThreshold_
static const uint16_t valid_
Definition: Constants.h:17
void addErrorCode(const std::string &error)
static const char mlCommissioning_[]
static const char apvTimingAnalysis_[]
const float & time() const
void print(std::stringstream &, uint32_t not_used=0)
uint16_t frameFindingThreshold() const
static const char invalidRefTime_[]
virtual void header(std::stringstream &) const
static const float optimumSamplingPoint_
static const uint16_t invalid_
Definition: Constants.h:16
static int position[264][3]
Definition: ReadPGInfo.cc:509
Abstract base for derived classes that provide analysis of commissioning histograms.
volatile std::atomic< bool > shutdown_flag false
static const float frameFindingThreshold_
const VString & getErrorCodes() const
const std::string & myName() const
bool foundTickMark() const
static const char invalidDelayTime_[]