BmnRoot
Loading...
Searching...
No Matches
BmnHistMSC.cxx
Go to the documentation of this file.
1#include "BmnHistMSC.h"
2
3#include <algorithm>
4#include <numeric>
5// BmnRoot
6#include <BmnMSCZSDigit.h>
7
8BmnHistMSC::BmnHistMSC(TString title, TString path, Int_t PeriodID, BmnSetup stp, BmnTrigRaw2Digit* trigMapper)
9 : BmnHist(PeriodID, stp)
10 , fTrigMapper(trigMapper)
11{
12 sumMods = 0;
13 maxLayers = 0;
14 refPath = path;
15 fTitle = title;
16 fName = title + "_cl";
17
18 scalers2index_map = fTrigMapper->GetScaler2IdxMap();
19 vector<string>& scaler_idx2name = fTrigMapper->GetScalerIdx2NameMap();
20 uint16_t scalers_ar_size = scaler_idx2name.size();
21
22 TString name;
23 name = fTitle + "_Scalers_Total";
24 TH1I* h = new TH1I(name, name, scalers_ar_size, 0, scalers_ar_size);
25 h->GetXaxis()->SetTitle("Scaler");
26 h->GetYaxis()->SetTitle("Activation Count");
27 TAxis* xaTotal = h->GetXaxis();
28 for (uint16_t i = 0; i < scalers_ar_size; i++) {
29 string& sname = scaler_idx2name[i];
30 xaTotal->SetBinLabel(i + 1, sname.data());
31 }
33 h->SetLineWidth(2);
34 histMscAll.push_back(h);
35 maxLayers = 1;
36 sumMods = 1;
37 // Create canvas
38 name = fTitle + "Canvas";
39 canGemStrip = new TCanvas(name, name, PAD_WIDTH * maxLayers, PAD_HEIGHT * sumMods);
40 canGemStrip->Divide(maxLayers, sumMods, 0.01 / maxLayers, 0.01 / sumMods);
41 // Int_t modCtr = 0; // filling GEM Canvas' pads
42 canStripPads.resize(sumMods * maxLayers);
43 Names.resize(sumMods * maxLayers);
44 PadInfo* pad = new PadInfo();
45 pad->opt = "hist";
46 pad->current = h;
47 pad->logy = true;
48 Int_t iPad = 0; // modCtr * maxLayers + iLayer;
49 canStripPads[iPad] = pad;
50 canGemStrip->GetPad(iPad + 1)->SetGrid();
51 Names[iPad] = canStripPads[iPad]->current->GetName();
52}
53
55{
56 delete canGemStrip;
57 if (fDir)
58 return;
59 for (auto pad : canStripPads)
60 delete pad;
61}
62
63void BmnHistMSC::Register(THttpServer* serv)
64{
65 fServer = serv;
66 fServer->Register("/", this);
67 TString path = "/" + fTitle + "/";
68 fServer->Register(path, canGemStrip);
69 TString cmd = "/" + fName + "/->Reset()";
70 TString cmdTitle = path + "Reset";
71 fServer->RegisterCommand(cmdTitle.Data(), cmd.Data(), "button;");
72 // fServer->Restrict(cmdTitle.Data(), "visible=shift");
73 // fServer->Restrict(cmdTitle.Data(), "allow=shift");
74 // fServer->Restrict(cmdTitle.Data(), "deny=guest");
75 cmd = "/" + fName + "/->SetRefRun(%arg1%)";
76 cmdTitle = path + "SetRefRun";
77 fServer->RegisterCommand(cmdTitle.Data(), cmd.Data(), "button;");
78}
79
80void BmnHistMSC::SetDir(TFile* outFile, TTree* recoTree)
81{
82 frecoTree = recoTree;
83 fDir = NULL;
84 if (outFile != NULL)
85 fDir = outFile->mkdir(fTitle + "_hists");
86 for (auto el : histMscAll)
87 el->SetDirectory(fDir);
88}
89
91{
92 BmnHist::DrawRef(canGemStrip, &canStripPads);
93}
94
96{
97 TClonesArray* digs = fDigiArrays->msc;
98 // printf("evtype %u\n", fDigiArrays->header->GetEventType());
99 // printf("entries %d\n", digs->GetEntriesFast());
100 if (!digs)
101 return;
102 if (digs->GetClass() == BmnMSCZSDigit<uint8_t>::Class()) {
103 for (Int_t digIndex = 0; digIndex < digs->GetEntriesFast(); digIndex++) {
104 BmnMSCZSDigit<uint8_t>* gs = static_cast<BmnMSCZSDigit<uint8_t>*>(digs->At(digIndex));
105 auto it = scalers2index_map.find(make_pair(gs->GetSerial(), gs->GetChannel()));
106 if (it == scalers2index_map.end())
107 continue;
108 vector<uint8_t>& vec = gs->GetValues();
109 uint64_t sum = std::accumulate(vec.begin(), vec.end(), 0);
110 // printf("MSC[%2u] = %lu\n", it->second, sum);
111 histMscAll[0]->Fill(it->second, sum);
112 }
113 }
114}
115
117{
118 if (refID != id) {
119 refID = id;
120 refRunName = Form("bmn_run%04u%s_hist.root", refID, fHistFileNameAdd.Data());
121 BmnHist::LoadRefRun(refID, refPath + refRunName, fTitle, canStripPads, Names);
122 DrawBoth();
123 }
124
125 return kBMNSUCCESS;
126}
127
129{
130 for (auto pad : canStripPads) {
131 if (pad)
132 if (pad->ref) {
133 delete pad->ref;
134 pad->ref = nullptr;
135 }
136 }
137 refID = 0;
138}
139
141{
142 for (auto el : histMscAll)
143 el->Reset();
144}
#define PAD_WIDTH
Definition BmnAdcQA.cxx:3
#define PAD_HEIGHT
Definition BmnAdcQA.cxx:4
int i
Definition P4_F32vec4.h:22
BmnStatus
Definition BmnEnums.h:24
@ kBMNSUCCESS
Definition BmnEnums.h:25
BmnSetup
Definition BmnEnums.h:89
void SetDir(TFile *outFile=NULL, TTree *recoTree=NULL)
BmnHistMSC(TString title, TString path="", Int_t periodID=7, BmnSetup setup=kBMNSETUP, BmnTrigRaw2Digit *trigMapper=nullptr)
Definition BmnHistMSC.cxx:8
void ClearRefRun()
void Register(THttpServer *serv)
BmnStatus SetRefRun(Int_t id)
void FillFromDigi(DigiArrays *fDigiArrays)
void DrawBoth()
virtual ~BmnHistMSC()
TTree * frecoTree
Definition BmnHist.h:88
Int_t refID
Definition BmnHist.h:92
TString refPath
Definition BmnHist.h:90
TDirectory * fDir
Definition BmnHist.h:89
static void DrawRef(unique_ptr< TCanvas > &canGemStrip, vector< PadInfo * > *canGemStripPads)
Definition BmnHist.cxx:15
static void SetHistStyleTH1(TH1 *h)
Definition BmnHist.cxx:195
TString refRunName
Definition BmnHist.h:91
static BmnStatus LoadRefRun(Int_t refID, TString FullName, TString fTitle, vector< PadInfo * > canPads, vector< TString > Names)
Definition BmnHist.cxx:100
THttpServer * fServer
Definition BmnHist.h:87
std::vector< IntType > & GetValues()
uint8_t GetChannel() const
uint32_t GetSerial() const
vector< string > & GetScalerIdx2NameMap()
map< std::pair< uint32_t, uint16_t >, uint16_t > & GetScaler2IdxMap()
TClonesArray * msc
Definition DigiArrays.h:143
Storage for pad content and it's options.
Definition PadInfo.h:20
string opt
Definition PadInfo.h:88
bool logy
Definition PadInfo.h:85
TH1 * current
Definition PadInfo.h:78