12 using namespace sistrip;
27 <<
"[ApvTimingAlgorithm::" << __func__ <<
"]"
28 <<
" NULL pointer to Analysis object!";
33 if ( histos.size() != 1 ) {
41 std::vector<TH1*>::const_iterator ihis = histos.begin();
42 for ( ; ihis != histos.end(); ihis++ ) {
45 if ( !(*ihis) ) {
continue; }
56 histo_.second = (*ihis)->GetName();
68 <<
"[ApvTimingAlgorithm::" << __func__ <<
"]"
69 <<
" NULL pointer to base Analysis object!";
77 <<
"[ApvTimingAlgorithm::" << __func__ <<
"]"
78 <<
" NULL pointer to derived Analysis object!";
87 TProfile*
histo =
dynamic_cast<TProfile*
>(
histo_.first);
94 uint16_t non_zero = 0;
97 uint16_t
nbins =
static_cast<uint16_t
>( histo->GetNbinsX() );
98 std::vector<float> bin_contents;
99 std::vector<float> bin_errors;
100 std::vector<float> bin_entries;
101 bin_contents.reserve( nbins );
102 bin_errors.reserve( nbins );
103 bin_entries.reserve( nbins );
104 for ( uint16_t ibin = 0; ibin <
nbins; ibin++ ) {
105 bin_contents.push_back( histo->GetBinContent(ibin+1) );
106 bin_errors.push_back( histo->GetBinError(ibin+1) );
107 bin_entries.push_back( histo->GetBinEntries(ibin+1) );
108 if ( bin_entries[ibin] ) {
109 if ( bin_contents[ibin] > max ) { max = bin_contents[ibin]; }
110 if ( bin_contents[ibin] < min ) { min = bin_contents[ibin]; }
114 if ( bin_contents.size() < 100 ) {
130 std::vector<float> tick;
131 std::vector<float>
base;
132 for ( uint16_t ibin = 0; ibin <
nbins; ibin++ ) {
133 if ( bin_entries[ibin] ) {
134 if ( bin_contents[ibin] < threshold ) {
135 base.push_back( bin_contents[ibin] );
137 tick.push_back( bin_contents[ibin] );
145 sort( tick.begin(), tick.end() );
146 sort( base.begin(), base.end() );
147 if ( !tick.empty() ) { tickmark = tick[ tick.size()%2 ? tick.size()/2 : tick.size()/2 ]; }
148 if ( !base.empty() ) { baseline = base[ base.size()%2 ? base.size()/2 : base.size()/2 ]; }
149 anal->
base_ = baseline;
150 anal->
peak_ = tickmark;
151 anal->
height_ = tickmark - baseline;
160 for ( uint16_t ibin = 0; ibin < base.size(); ibin++ ) {
162 mean2 += base[ibin] * base[ibin];
164 if ( !base.empty() ) {
165 mean = mean / base.size();
166 mean2 = mean2 / base.size();
171 float baseline_rms =
sqrt( fabs( mean2 - mean*mean ) );
175 std::map<uint16_t,float> edges;
176 for ( uint16_t ibin = 1; ibin < nbins-1; ibin++ ) {
177 if ( bin_entries[ibin+1] &&
178 bin_entries[ibin-1] ) {
179 float derivative = bin_contents[ibin+1] - bin_contents[ibin-1];
180 if ( derivative > 3.*baseline_rms ) {
185 if ( edges.empty() ) {
196 std::map<uint16_t,float>::iterator iter = edges.begin();
197 while ( !found && iter != edges.end() ) {
201 for ( uint16_t
ii = 0;
ii < 50;
ii++ ) {
202 uint16_t
bin = iter->first +
ii;
206 if ( static_cast<uint32_t>(bin) < 1 ||
207 static_cast<uint32_t
>(bin+1) >= nbins ) {
212 temp = bin_contents[bin+1] - bin_contents[bin-1];
215 if ( temp > max_derivative ) {
216 max_derivative =
temp;
217 max_derivative_bin =
bin;
221 if (
ii > 10 &&
ii < 40 && bin_entries[bin] &&
222 bin_contents[bin] < baseline + 5.*baseline_rms ) {
229 if ( valid ) { found =
true; }
252 std::map<uint16_t,float> edges_r;
253 for ( uint16_t ibin_r = 1; ibin_r < nbins-1; ibin_r++ ) {
254 if (bin_entries[ibin_r+4] &&
255 bin_entries[ibin_r+3] &&
256 bin_entries[ibin_r+2] &&
257 bin_entries[ibin_r+1] &&
258 bin_entries[ibin_r] &&
259 bin_entries[ibin_r-1]) {
260 float derivative_r = bin_contents[ibin_r+1] - bin_contents[ibin_r-1];
261 float derivative_r1 = bin_contents[ibin_r+1] - bin_contents[ibin_r];
262 float derivative_r2 = bin_contents[ibin_r+2] - bin_contents[ibin_r+1];
263 float derivative_r3 = bin_contents[ibin_r+3] - bin_contents[ibin_r+2];
265 if ( derivative_r > 3.*baseline_rms &&
266 derivative_r1 > 1.*baseline_rms &&
267 derivative_r2 > 1.*baseline_rms &&
268 derivative_r3 > 1.*baseline_rms ) {
269 edges_r[ibin_r] = derivative_r;
273 if ( edges_r.empty() ) {
281 bool found_r =
false;
282 std::map<uint16_t,float>::iterator iter_r = edges_r.begin();
283 while ( !found_r && iter_r != edges_r.end() ) {
287 int lowpointcount_r = 0;
288 const int lowpointallow_r = 25;
289 for ( uint16_t ii_r = 0; ii_r < 50; ii_r++ ) {
290 uint16_t bin_r = iter_r->first + ii_r;
294 if ( static_cast<uint32_t>(bin_r) < 1 ||
295 static_cast<uint32_t
>(bin_r+1) >= nbins ) {
300 temp_r = bin_contents[bin_r+1] - bin_contents[bin_r-1];
303 if ( temp_r > max_derivative_r && ii_r < 10) {
304 max_derivative_r = temp_r;
305 max_derivative = temp_r;
306 max_derivative_bin = bin_r;
311 if ( ii_r > 10 && ii_r < 40 && bin_entries[bin_r] &&
312 bin_contents[bin_r] < baseline + 5.*baseline_rms ) {
314 if(lowpointcount_r > lowpointallow_r){
341 anal->
time_ = max_derivative_bin * 25. / 24.;
static const char unexpectedTask_[]
const uint32_t & fedKey() const
Derivative< X, A >::type derivative(const A &_)
Utility class that holds histogram title.
static const char numberOfHistos_[]
static const float tickMarkHeightThreshold_
static const uint16_t valid_
static const char incompletePlateau_[]
static const char numberOfBins_[]
static const char missingTickMark_[]
void addErrorCode(const std::string &error)
static const char rejectedCandidate_[]
static const char mlCommissioning_[]
static const char tickMarkRecovered_[]
uint32_t extractFedKey(const TH1 *const )
static const char tickMarkBelowThresh_[]
virtual void addErrorCode(const std::string &error)
const Histo & histo() const
static const char smallTickMarkHeight_[]
void extract(const std::vector< TH1 * > &)
static const uint16_t invalid_
static const char noRisingEdges_[]
static const char smallDataRange_[]
std::vector< std::vector< double > > tmp
Abstract base for derived classes that provide analysis of commissioning histograms.
Analysis for timing run using APV tick marks.
CommissioningAnalysis *const anal() const
static const char nullPtr_[]