1414
1515#include < map>
1616
17- #include " TH1D .h"
17+ #include " TList .h"
1818
1919#include " CCDB/BasicCCDBManager.h"
2020#include " CommonDataFormat/InteractionRecord.h"
2121
2222using o2::InteractionRecord;
2323
24+ void Zorro::populateHistRegistry (o2::framework::HistogramRegistry& histRegistry, std::string prefix)
25+ {
26+ TList* list = histRegistry.getListOfHistograms ();
27+ if (mSelections && list->FindObject ((std::to_string (mRunNumber ) + " /" + prefix + " Selections" ).data ()) == nullptr ) {
28+ mAnalysedTriggers = histRegistry.add <TH1>((std::to_string (mRunNumber ) + " /" + prefix + " AnalysedTriggers" ).data (), " " , o2::framework::HistType::kTH1D , {{mSelections ->GetNbinsX () - 2 , -0.5 , mSelections ->GetNbinsX () - 2.5 }});
29+ for (int iBin{2 }; iBin < mSelections ->GetNbinsX (); ++iBin) { // Exclude first and last bins as they are total number of analysed and selected events, respectively
30+ mAnalysedTriggers ->GetXaxis ()->SetBinLabel (iBin - 1 , mSelections ->GetXaxis ()->GetBinLabel (iBin));
31+ }
32+ std::shared_ptr<TH1> selections = histRegistry.add <TH1>((std::to_string (mRunNumber ) + " /" + prefix + " Selections" ).data (), " " , o2::framework::HistType::kTH1D , {{mSelections ->GetNbinsX (), -0.5 , static_cast <double >(mSelections ->GetNbinsX () - 0.5 )}});
33+ for (int iBin{1 }; iBin <= mSelections ->GetNbinsX (); ++iBin) {
34+ selections->GetXaxis ()->SetBinLabel (iBin, mSelections ->GetXaxis ()->GetBinLabel (iBin));
35+ selections->SetBinContent (iBin, mSelections ->GetBinContent (iBin));
36+ selections->SetBinError (iBin, mSelections ->GetBinError (iBin));
37+ }
38+ }
39+ if (mScalers && list->FindObject ((std::to_string (mRunNumber ) + " /" + prefix + " Scalers" ).data ()) == nullptr ) {
40+ std::shared_ptr<TH1> scalers = histRegistry.add <TH1>((std::to_string (mRunNumber ) + " /" + prefix + " Scalers" ).data (), " " , o2::framework::HistType::kTH1D , {{mScalers ->GetNbinsX (), -0.5 , static_cast <double >(mScalers ->GetNbinsX () - 0.5 )}});
41+ for (int iBin{1 }; iBin <= mScalers ->GetNbinsX (); ++iBin) {
42+ scalers->GetXaxis ()->SetBinLabel (iBin, mScalers ->GetXaxis ()->GetBinLabel (iBin));
43+ scalers->SetBinContent (iBin, mScalers ->GetBinContent (iBin));
44+ scalers->SetBinError (iBin, mScalers ->GetBinError (iBin));
45+ }
46+ }
47+ if (mInspectedTVX && list->FindObject ((std::to_string (mRunNumber ) + " /" + prefix + " InspectedTVX" ).data ()) == nullptr ) {
48+ std::shared_ptr<TH1> inspectedTVX = histRegistry.add <TH1>((std::to_string (mRunNumber ) + " /" + prefix + " InspectedTVX" ).data (), " " , o2::framework::HistType::kTH1D , {{mInspectedTVX ->GetNbinsX (), -0.5 , static_cast <double >(mInspectedTVX ->GetNbinsX () - 0.5 )}});
49+ for (int iBin{1 }; iBin <= mInspectedTVX ->GetNbinsX (); ++iBin) {
50+ inspectedTVX->GetXaxis ()->SetBinLabel (iBin, mInspectedTVX ->GetXaxis ()->GetBinLabel (iBin));
51+ inspectedTVX->SetBinContent (iBin, mInspectedTVX ->GetBinContent (iBin));
52+ inspectedTVX->SetBinError (iBin, mInspectedTVX ->GetBinError (iBin));
53+ }
54+ }
55+ }
56+
2457std::vector<int > Zorro::initCCDB (o2::ccdb::BasicCCDBManager* ccdb, int runNumber, uint64_t timestamp, std::string tois, int bcRange)
2558{
2659 if (mRunNumber == runNumber) {
@@ -45,50 +78,61 @@ std::vector<int> Zorro::initCCDB(o2::ccdb::BasicCCDBManager* ccdb, int runNumber
4578 mLastSelectedIdx = 0 ;
4679 mTOIs .clear ();
4780 mTOIidx .clear ();
48- size_t pos = 0 ;
49- while ((pos = tois.find (" ," )) != std::string::npos) {
81+ while (!tois.empty ()) {
82+ size_t pos = tois.find (" ," );
83+ pos = (pos == std::string::npos) ? tois.size () : pos;
5084 std::string token = tois.substr (0 , pos);
5185 // Trim leading and trailing whitespaces from the token
5286 token.erase (0 , token.find_first_not_of (" " ));
5387 token.erase (token.find_last_not_of (" " ) + 1 );
5488 int bin = mScalers ->GetXaxis ()->FindBin (token.c_str ()) - 2 ;
5589 mTOIs .push_back (token);
5690 mTOIidx .push_back (bin);
57- tois.erase (0 , pos + 1 );
91+ tois = tois .erase (0 , pos + 1 );
5892 }
5993 mTOIcounts .resize (mTOIs .size (), 0 );
6094 return mTOIidx ;
6195}
6296
6397std::bitset<128 > Zorro::fetch (uint64_t bcGlobalId, uint64_t tolerance)
6498{
65- std::bitset< 128 > result ;
99+ mLastResult . reset () ;
66100 o2::dataformats::IRFrame bcFrame{InteractionRecord::long2IR (bcGlobalId) - tolerance, InteractionRecord::long2IR (bcGlobalId) + tolerance};
67101 if (bcGlobalId < mLastBCglobalId ) {
68102 mLastSelectedIdx = 0 ;
69103 }
104+ mLastBCglobalId = bcGlobalId;
70105 for (size_t i = mLastSelectedIdx ; i < mBCranges .size (); i++) {
71- if (!bcFrame. getOverlap ( mBCranges [i]). isZeroLength ( )) {
106+ if (!mBCranges [i]. isOutside (bcFrame )) {
72107 for (int iMask{0 }; iMask < 2 ; ++iMask) {
73108 for (int iTOI{0 }; iTOI < 64 ; ++iTOI) {
74- result.set (iMask * 64 + iTOI, mZorroHelpers ->at (i).selMask [iMask] & (1ull << iTOI));
109+ if (mZorroHelpers ->at (i).selMask [iMask] & (1ull << iTOI)) {
110+ mLastResult .set (iMask * 64 + iTOI, 1 );
111+ if (mAnalysedTriggers ) {
112+ mAnalysedTriggers ->Fill (iMask * 64 + iTOI);
113+ }
114+ }
75115 }
76116 }
77117 mLastSelectedIdx = i;
78- return result;
118+ return mLastResult ;
119+ } else if (mBCranges [i].getMax () < bcFrame.getMin ()) {
120+ mLastSelectedIdx = i;
121+ } else if (mBCranges [i].getMin () > bcFrame.getMax ()) {
122+ break ;
79123 }
80124 }
81- return result ;
125+ return mLastResult ;
82126}
83127
84128bool Zorro::isSelected (uint64_t bcGlobalId, uint64_t tolerance)
85129{
86130 uint64_t lastSelectedIdx = mLastSelectedIdx ;
87- std::bitset< 128 > result = fetch (bcGlobalId, tolerance);
131+ fetch (bcGlobalId, tolerance);
88132 for (size_t i{0 }; i < mTOIidx .size (); ++i) {
89133 if (mTOIidx [i] < 0 ) {
90134 continue ;
91- } else if (result .test (mTOIidx [i])) {
135+ } else if (mLastResult .test (mTOIidx [i])) {
92136 mTOIcounts [i] += (lastSelectedIdx != mLastSelectedIdx ); // / Avoid double counting
93137 return true ;
94138 }
0 commit comments