CbmRoot
Loading...
Searching...
No Matches
CbmSpillCheck.cxx
Go to the documentation of this file.
1/* Copyright (C) 2023 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Dario Ramirez [committer] */
4
5#include "CbmSpillCheck.h"
6
7#include <TFitResult.h>
8
9#include <ctime>
10#include <iostream>
11#include <typeinfo>
12
14{
15 LOG(debug) << "Creating an instance of CbmSpillCheck ...";
16}
17
18CbmSpillCheck::CbmSpillCheck(ECbmModuleId ref, double lvl_min, double lvl_max)
19 : fRefSystem{ref}
20 , fRateMinPercent{lvl_min}
21 , fRateMaxPercent{lvl_max}
22{
23 LOG(debug) << "Creating an instance of CbmSpillCheck ...";
24}
25
27{
28 std::string h_name = Form("%s Digi Rate", std::string(cbm::util::ToString(system)).c_str());
29 LOG(debug) << "Booking rate for : " << h_name;
30 fG1D[h_name] = std::make_unique<TGraphErrors>();
31}
32
34{
35 FairRootManager* ioman = FairRootManager::Instance();
36 if (ioman != nullptr) {
38 fDigiManager->Init();
39
40 if (!fDigiManager->IsPresent(fRefSystem)) {
41 LOG(fatal) << GetName() << ": No " << fRefSystem << " branch in input!";
42 }
43
44 for (ECbmModuleId system = ECbmModuleId::kRef; system != ECbmModuleId::kLastModule; ++system) {
45 if (fDigiManager->IsPresent(system)) BookHistograms(system);
46 }
47
48 return kSUCCESS;
49 }
50 return kERROR;
51}
52
53void CbmSpillCheck::Exec(Option_t*)
54{
55 LOG(info) << "Running CbmSpillCheck ...";
56
57 size_t nb_ref_digis = fDigiManager->GetNofDigis(fRefSystem);
58 fRateMin = fRateMin == -1 ? nb_ref_digis : std::min(nb_ref_digis, size_t(fRateMin));
59 fRateMax = fRateMax == -1 ? nb_ref_digis : std::max(nb_ref_digis, size_t(fRateMax));
60 fRefRate.push_back(nb_ref_digis);
61
62 for (ECbmModuleId system = ECbmModuleId::kRef; system != ECbmModuleId::kLastModule; ++system) {
63 if (fDigiManager->IsPresent(system)) {
64 size_t n_of_digis = fDigiManager->GetNofDigis(system);
65 std::string h_name = Form("%s Digi Rate", std::string(cbm::util::ToString(system)).c_str());
66 fG1D[h_name]->SetPoint(fNbPoints, fNbPoints, n_of_digis);
67 }
68 }
69 fNbPoints++;
70}
71
73{
74 double spill_lvl_off = fRateMin + fRateMinPercent * (fRateMax - fRateMin);
75 double spill_lvl_on = fRateMin + fRateMaxPercent * (fRateMax - fRateMin);
76 fSpillStatus = std::vector<int>(fRefRate.size(), 0);
77 for (size_t ts_idx = 0; ts_idx < fRefRate.size(); ts_idx++) {
78 fSpillStatus[ts_idx] = fRefRate[ts_idx] <= spill_lvl_off ? -1 : (fRefRate[ts_idx] <= spill_lvl_on ? 0 : 1);
79 std::cout << fSpillStatus[ts_idx] << std::endl;
80 }
81
82 std::cout << spill_lvl_off << std::endl;
83 std::cout << spill_lvl_on << std::endl;
84
85 SaveToFile();
86 fG1D.clear();
87 fH1D.clear();
88 fH2D.clear();
89}
ECbmModuleId
Enumerator for module Identifiers.
Definition CbmDefs.h:45
@ kLastModule
For loops over all modules.
Definition CbmDefs.h:67
@ kRef
Reference plane.
Definition CbmDefs.h:46
@ kBmon
Bmon Counter.
Definition CbmDefs.h:57
static CbmDigiManager * Instance()
Static instance.
std::vector< int > fRefRate
double fRateMaxPercent
void Exec(Option_t *)
double fRateMinPercent
CbmSpillCheck()
Default constructor.
CbmDigiManager * fDigiManager
ECbmModuleId fRefSystem
void BookHistograms(ECbmModuleId)
Book histograms for a specific module.
std::vector< int > fSpillStatus
InitStatus Init()
std::map< std::string, std::unique_ptr< TGraphErrors > > fG1D
std::map< std::string, std::unique_ptr< TH2D > > fH2D
void SaveToFile()
It write all mapped objects to the FairRunAna sink file.
std::map< std::string, std::unique_ptr< TH1D > > fH1D
std::string_view ToString(T t)
Definition CbmEnumDict.h:64