13 using namespace sistrip;
20 targetGain_(pset.getParameter<double>(
"TargetGain")) {
30 <<
" NULL pointer to Analysis object!";
35 if (histos.size() != 12) {
44 std::vector<TH1*>::const_iterator ihis = histos.begin();
45 for (; ihis != histos.end(); ihis++) {
62 ss <<
title.extraInfo().substr(
69 ss <<
title.extraInfo().substr(
73 bool baseline_rms =
false;
80 histos_[gain][digital].first = *ihis;
81 histos_[gain][digital].second = (*ihis)->GetName();
82 }
else if (baseline_rms) {
84 histos_[gain][2].second = (*ihis)->GetName();
99 <<
" NULL pointer to base Analysis object!";
107 <<
" NULL pointer to derived Analysis object!";
112 for (uint16_t igain = 0; igain < 4; igain++) {
114 TH1* base_his =
histos_[igain][0].first;
115 TH1* peak_his =
histos_[igain][1].first;
116 TH1* noise_his =
histos_[igain][2].first;
133 TProfile* base_histo =
dynamic_cast<TProfile*
>(base_his);
139 TProfile* peak_histo =
dynamic_cast<TProfile*
>(peak_his);
145 TProfile* noise_histo =
dynamic_cast<TProfile*
>(noise_his);
152 uint16_t
nbins =
static_cast<uint16_t
>(peak_histo->GetNbinsX());
153 if (static_cast<uint16_t>(base_histo->GetNbinsX()) != nbins) {
155 if (static_cast<uint16_t>(base_histo->GetNbinsX()) < nbins) {
156 nbins =
static_cast<uint16_t
>(base_histo->GetNbinsX());
161 std::vector<float> peak_contents(0);
162 std::vector<float> peak_errors(0);
163 std::vector<float> peak_entries(0);
164 std::vector<float> base_contents(0);
165 std::vector<float> base_errors(0);
166 std::vector<float> base_entries(0);
167 std::vector<float> noise_contents(0);
168 std::vector<float> noise_errors(0);
169 std::vector<float> noise_entries(0);
178 for (uint16_t ibin = 0; ibin <
nbins; ibin++) {
180 peak_contents.push_back(peak_histo->GetBinContent(ibin + 1));
181 peak_errors.push_back(peak_histo->GetBinError(ibin + 1));
182 peak_entries.push_back(peak_histo->GetBinEntries(ibin + 1));
183 if (peak_entries[ibin]) {
184 if (peak_contents[ibin] > peak_max) {
185 peak_max = peak_contents[ibin];
187 if (peak_contents[ibin] < peak_min && ibin) {
188 peak_min = peak_contents[ibin];
193 base_contents.push_back(base_histo->GetBinContent(ibin + 1));
194 base_errors.push_back(base_histo->GetBinError(ibin + 1));
195 base_entries.push_back(base_histo->GetBinEntries(ibin + 1));
196 if (base_entries[ibin]) {
197 if (base_contents[ibin] > base_max) {
198 base_max = base_contents[ibin];
200 if (base_contents[ibin] < base_min && ibin) {
201 base_min = base_contents[ibin];
206 noise_contents.push_back(noise_histo->GetBinContent(ibin + 1));
207 noise_errors.push_back(noise_histo->GetBinError(ibin + 1));
208 noise_entries.push_back(noise_histo->GetBinEntries(ibin + 1));
209 if (noise_entries[ibin]) {
210 if (noise_contents[ibin] > noise_max) {
211 noise_max = noise_contents[ibin];
213 if (noise_contents[ibin] < noise_min && ibin) {
214 noise_min = noise_contents[ibin];
224 for (uint16_t ibin = 0; ibin <
nbins; ibin++) {
225 if (base_entries[ibin]) {
226 zero_light_level = base_contents[ibin];
227 zero_light_error = base_errors[ibin];
234 zero_light_thres = zero_light_level + 5. * zero_light_error;
236 std::stringstream
ss;
243 float base_range = base_max - base_min;
246 float max = peak_max < base_max ? peak_max : base_max;
247 float min = peak_min > base_min ? peak_min : base_min;
251 std::vector<bool> above_zero_light;
252 above_zero_light.resize(3,
true);
260 uint16_t peak_bin = 0;
261 uint16_t base_bin = 0;
262 uint16_t low_bin = 0;
263 for (uint16_t ibin = 0; ibin <
nbins; ibin++) {
265 if (base_entries[ibin]) {
266 above_zero_light.erase(above_zero_light.begin());
267 if (base_contents[ibin] > zero_light_thres) {
268 above_zero_light.push_back(
true);
270 above_zero_light.push_back(
false);
272 if (above_zero_light.size() != 3) {
273 above_zero_light.resize(3,
false);
278 if (peak_entries[ibin] && peak_contents[ibin] > (min + 0.2 * range) &&
279 peak_contents[ibin] < (min + 0.8 * range)) {
283 if ((ibin - peak_bin) < 10) {
284 peak_high.
add(ibin, peak_contents[ibin]);
288 if (base_entries[ibin] && base_contents[ibin] > (min + 0.2 * range) &&
289 base_contents[ibin] < (min + 0.8 * range)) {
293 if ((ibin - base_bin) < 10) {
294 base_high.
add(ibin, base_contents[ibin]);
298 if (base_entries[ibin] &&
300 base_contents[ibin] > (base_min + 0.2 * base_range) && base_contents[ibin] < (base_min + 0.6 * base_range)) {
304 if ((ibin - low_bin) < 10) {
305 base_low.
add(ibin, base_contents[ibin]);
311 float mid = min + 0.5 *
range;
314 peak_high.
fit(peak_params);
315 base_high.
fit(base_params);
320 if (peak_params.
b_ > 0.) {
321 peak_pos = (mid - peak_params.
a_) / peak_params.
b_;
323 if (base_params.
b_ > 0.) {
324 base_pos = (mid - base_params.
a_) / base_params.
b_;
327 width = base_pos - peak_pos;
332 base_low.
fit(low_params);
334 if (low_params.
b_ > 0.) {
335 lift_off = (zero_light_level - low_params.
a_) / low_params.
b_;
341 if (low_params.
b_ > 0.) {
347 anal->
bias_[igain] =
static_cast<uint16_t
>(lift_off) + 2;
354 anal->
liftOff_[igain] = 0.45 * lift_off;
359 anal->
threshold_[igain] = 0.45 * (lift_off - width / 2.);
372 bin_number = (uint16_t)(lift_off + width / 3.);
375 if (bin_number < noise_contents.size()) {
376 anal->
linkNoise_[igain] = noise_contents[bin_number];
397 const float target_gain =
401 for (uint16_t igain = 0; igain < 4; igain++) {
408 if (fabs(anal->
measGain_[igain] - target_gain) < diff_in_gain) {
410 diff_in_gain = fabs(anal->
measGain_[igain] - target_gain);
423 if (gain <= 3 && digital_level <= 1) {
424 return histos_[gain][digital_level];
426 return Histo(
nullptr,
"");
Histogram-based analysis for opto bias/gain scan.
static const char unexpectedTask_[]
const uint32_t & fedKey() const
Histo histo(const uint16_t &gain, const uint16_t &digital_level) const
Utility class that holds histogram title.
void extract(const std::vector< TH1 * > &) override
static const char numberOfHistos_[]
static const char unexpectedExtraInfo_[]
static const uint16_t valid_
static const char numberOfBins_[]
const uint16_t range(const Frame &aFrame)
uint32_t extractFedKey(const TH1 *const)
static const float fedAdcGain_
static const char mlCommissioning_[]
static const uint16_t maximum_
virtual void addErrorCode(const std::string &error)
std::vector< std::vector< Histo > > histos_
void add(const float &value_x, const float &value_y)
static const uint16_t defaultBiasSetting_
Log< level::Info, false > LogInfo
std::pair< TH1 *, std::string > Histo
static const uint16_t invalid_
Abstract base for derived classes that provide analysis of commissioning histograms.
static const uint16_t defaultGainSetting_
Log< level::Warning, false > LogWarning
void fit(Params &fit_params)
static const char unexpectedBinNumber_[]
CommissioningAnalysis *const anal() const
static const char nullPtr_[]
static const char invalidZeroLightLevel_[]