Skip to content

Commit f4ca0bc

Browse files
authored
Merge pull request #13 from Mu2e/pgirotti/CaloSiDETDQM
Added DQM started module for SiDET
2 parents 7152099 + 3ae5ad8 commit f4ca0bc

File tree

3 files changed

+335
-0
lines changed

3 files changed

+335
-0
lines changed

otsdaq-mu2e-dqm/ArtModules/CMakeLists.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,23 @@ ROOT::RIO
110110
ROOT::Gui
111111
)
112112

113+
cet_build_plugin(CaloSiDETDQM art::module LIBRARIES REG
114+
art_root_io::TFileService_service
115+
artdaq_core_mu2e::artdaq-core-mu2e_Data
116+
otsdaq_mu2e::otsdaq-mu2e_ArtModules
117+
otsdaq::NetworkUtilities
118+
Offline::DataProducts
119+
Offline::RecoDataProducts
120+
Offline::TrkHitReco
121+
Offline::DAQ
122+
Offline::CaloConditions
123+
ROOT::Hist
124+
ROOT::Tree
125+
ROOT::Core
126+
ROOT::RIO
127+
ROOT::Gui
128+
)
129+
113130
cet_build_plugin(IntegrationDQM art::module LIBRARIES REG
114131
art_root_io::TFileService_service
115132
artdaq_core_mu2e::artdaq-core-mu2e_Data
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#ifndef _CaloSiDETDQMHistoContainer_h_
2+
#define _CaloSiDETDQMHistoContainer_h_
3+
4+
#include "art/Framework/Services/Registry/ServiceHandle.h"
5+
#include "art_root_io/TFileDirectory.h"
6+
#include "art_root_io/TFileService.h"
7+
#include "otsdaq/Macros/CoutMacros.h"
8+
#include "otsdaq/NetworkUtilities/TCPPublishServer.h"
9+
#include <TH1F.h>
10+
#include <string>
11+
12+
#include "TRACE/tracemf.h"
13+
#define TRACE_NAME "CaloSiDETDQM"
14+
15+
namespace ots {
16+
17+
class CaloSiDETDQMHistoContainer {
18+
public:
19+
CaloSiDETDQMHistoContainer(){};
20+
virtual ~CaloSiDETDQMHistoContainer(void){};
21+
struct InfoHist_ {
22+
TH1F *_Hist;
23+
std::string _type;
24+
InfoHist_() {
25+
_Hist = nullptr;
26+
_type = "add";
27+
}
28+
};
29+
struct InfoGraph_ {
30+
TGraph *_Graph;
31+
InfoGraph_() { _Graph = NULL; }
32+
};
33+
34+
InfoHist_ h1_channel_occupancy;
35+
InfoHist_ h1_channel_occupancy_lastevent;
36+
InfoGraph_ g_nhits_event;
37+
38+
// Histogram colors by status
39+
static void GoodHist(TH1 *h) {
40+
h->SetLineColor(kAzure + 2);
41+
h->SetFillColor(kAzure - 9);
42+
}
43+
static void WarningHist(TH1 *h) {
44+
h->SetLineColor(kOrange + 6);
45+
h->SetFillColor(kOrange - 4);
46+
}
47+
static void BadHist(TH1 *h) {
48+
h->SetLineColor(kRed - 4);
49+
h->SetFillColor(kRed - 6);
50+
}
51+
52+
static void BookHist(InfoHist_ &h, art::ServiceHandle<art::TFileService> tfs,
53+
std::string Name, std::string Title, const int nBins,
54+
const float xmin, const float xmax, const char *folder,
55+
std::string type = "add") {
56+
art::TFileDirectory testDir = tfs->mkdir(folder);
57+
h._Hist =
58+
testDir.make<TH1F>(Name.c_str(), Title.c_str(), nBins, xmin, xmax);
59+
h._type = type;
60+
61+
// Initialize histogram style
62+
h._Hist->SetLineWidth(2);
63+
h._Hist->GetXaxis()->SetTitleSize(.04);
64+
h._Hist->GetYaxis()->SetTitleSize(.04);
65+
GoodHist(h._Hist);
66+
}
67+
68+
static void BookGraph(InfoGraph_ &g,
69+
art::ServiceHandle<art::TFileService> tfs,
70+
std::string Name, std::string Title,
71+
const char *folder) {
72+
art::TFileDirectory testDir = tfs->mkdir(folder);
73+
g._Graph = testDir.makeAndRegister<TGraph>(Name.c_str(), Title.c_str());
74+
75+
// Initialize histogram style
76+
g._Graph->SetLineWidth(2);
77+
g._Graph->SetMarkerStyle(20);
78+
g._Graph->GetXaxis()->SetTitleSize(.04);
79+
g._Graph->GetYaxis()->SetTitleSize(.04);
80+
}
81+
};
82+
83+
} // namespace ots
84+
85+
#endif
Lines changed: 233 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,233 @@
1+
// Author: G. Pezzullo
2+
// This module produces histograms of data from the TriggerResults
3+
4+
#include "art/Framework/Core/EDAnalyzer.h"
5+
#include "art/Framework/Core/ModuleMacros.h"
6+
#include "art/Framework/Principal/Event.h"
7+
#include "art/Framework/Principal/Handle.h"
8+
#include "art/Framework/Services/System/TriggerNamesService.h"
9+
#include "art_root_io/TFileService.h"
10+
#include "canvas/Persistency/Common/TriggerResults.h"
11+
#include "fhiclcpp/types/OptionalAtom.h"
12+
13+
#include "TRACE/tracemf.h"
14+
15+
#include <TBufferFile.h>
16+
#include <TF1.h>
17+
#include <TFile.h>
18+
#include <TGraph.h>
19+
#include <TGraphErrors.h>
20+
#include <TH1F.h>
21+
#include <TSpline.h>
22+
#include <TVirtualFitter.h>
23+
#include <map>
24+
#include <vector>
25+
26+
#include "otsdaq-mu2e-dqm/ArtModules/CaloSiDETDQMHistoContainer.h"
27+
#include "otsdaq-mu2e/ArtModules/HistoSender.hh"
28+
#include "otsdaq/Macros/CoutMacros.h"
29+
#include "otsdaq/Macros/ProcessorPluginMacros.h"
30+
#include "otsdaq/MessageFacility/MessageFacility.h"
31+
#include "otsdaq/NetworkUtilities/TCPSendClient.h"
32+
33+
//-- insert calls to proditions ..for calodmap-----
34+
#include "Offline/CaloConditions/inc/CaloDAQMap.hh"
35+
#include "Offline/ProditionsService/inc/ProditionsHandle.hh"
36+
//-------------------------------------------------
37+
38+
#include "Offline/DAQ/inc/CaloDAQUtilities.hh"
39+
#include "Offline/RecoDataProducts/inc/CaloDigi.hh"
40+
41+
namespace ots {
42+
class CaloSiDETDQM : public art::EDAnalyzer {
43+
public:
44+
struct Config {
45+
using Name = fhicl::Name;
46+
using Comment = fhicl::Comment;
47+
fhicl::Atom<int> port{
48+
Name("port"),
49+
Comment(
50+
"This parameter sets the port where the histogram will be sent")};
51+
fhicl::Atom<std::string> address{
52+
Name("address"), Comment("This paramter sets the IP address where the "
53+
"histogram will be sent")};
54+
fhicl::Atom<std::string> moduleTag{Name("moduleTag"),
55+
Comment("Module tag name")};
56+
fhicl::Atom<std::string> caloDigiTag{Name("caloDigiTag"),
57+
Comment("Module tag name")};
58+
fhicl::Sequence<std::string> histType{
59+
Name("histType"),
60+
Comment("This parameter determines which quantity is histogrammed")};
61+
fhicl::Atom<int> freqDQM{
62+
Name("freqDQM"),
63+
Comment("Frequency for sending histograms to the data-receiver")};
64+
fhicl::Atom<int> diag{Name("diagLevel"), Comment("Diagnostic level"), 0};
65+
fhicl::Atom<std::string> spline{Name("splineFilename"),
66+
Comment("spline root file path"), ""};
67+
fhicl::Atom<bool> uset0{Name("uset0"),
68+
Comment("Use t0 instead of fitting with templates"),
69+
false};
70+
fhicl::Atom<int> skipAfterN{Name("skipAfterN"),
71+
Comment("Don't fit after N hits"), -1};
72+
};
73+
74+
typedef art::EDAnalyzer::Table<Config> Parameters;
75+
76+
explicit CaloSiDETDQM(Parameters const &conf);
77+
78+
void analyze(art::Event const &event) override;
79+
void beginRun(art::Run const &) override;
80+
void beginJob() override;
81+
void endJob() override;
82+
83+
void summary_fill(art::Event const &event, CaloSiDETDQMHistoContainer *histos,
84+
const mu2e::CaloDigiCollection *caloDigis);
85+
void PlotRate(art::Event const &e);
86+
87+
private:
88+
Config conf_;
89+
int port_;
90+
std::string address_;
91+
std::string moduleTag_;
92+
std::string caloDigiTag_;
93+
std::vector<std::string> histType_;
94+
int freqDQM_, diagLevel_, evtCounter_;
95+
art::ServiceHandle<art::TFileService> tfs;
96+
CaloSiDETDQMHistoContainer *histo_container =
97+
new CaloSiDETDQMHistoContainer();
98+
HistoSender *histSender_;
99+
bool doOnspillHist_, doOffspillHist_;
100+
mu2e::ProditionsHandle<mu2e::CaloDAQMap> _calodaqconds_h;
101+
102+
int this_eventNumber;
103+
};
104+
} // namespace ots
105+
106+
ots::CaloSiDETDQM::CaloSiDETDQM(Parameters const &conf)
107+
: art::EDAnalyzer(conf), conf_(conf()), port_(conf().port()),
108+
address_(conf().address()), moduleTag_(conf().moduleTag()),
109+
caloDigiTag_(conf().caloDigiTag()), histType_(conf().histType()),
110+
freqDQM_(conf().freqDQM()), diagLevel_(conf().diag()), evtCounter_(0),
111+
doOnspillHist_(false), doOffspillHist_(false) {
112+
histSender_ = new HistoSender(address_, port_);
113+
114+
if (diagLevel_ > 0) {
115+
__COUT__ << "[CaloSiDETDQM::analyze] DQM for " << histType_[0] << std::endl;
116+
}
117+
118+
for (std::string name : histType_) {
119+
if (name == "Onspill") {
120+
doOnspillHist_ = true;
121+
}
122+
if (name == "Offspill") {
123+
doOffspillHist_ = true;
124+
}
125+
}
126+
}
127+
128+
void ots::CaloSiDETDQM::beginJob() {
129+
__COUT__ << "[CaloSiDETDQM::beginJob] Beginning job" << std::endl;
130+
131+
histo_container->BookHist(histo_container->h1_channel_occupancy, tfs,
132+
"h1_channel_occupancy",
133+
"Channel occupancy;Board*100+Channel;Total hits",
134+
16000, 0, 16000, "summary");
135+
136+
histo_container->BookHist(
137+
histo_container->h1_channel_occupancy_lastevent, tfs,
138+
"h1_channel_occupancy_lastevent",
139+
"Channel occupancy in the last event;Board*100+Channel;Total hits", 16000,
140+
0, 16000, "summary");
141+
142+
histo_container->BookGraph(
143+
histo_container->g_nhits_event, tfs, "g_nhits_event",
144+
"Channel occupancy;Board*100+Channel;Total hits", "summary");
145+
}
146+
147+
void ots::CaloSiDETDQM::analyze(art::Event const &event) {
148+
++evtCounter_;
149+
150+
art::EventNumber_t eventNumber = event.event();
151+
this_eventNumber = (int)eventNumber;
152+
TLOG(TLVL_DEBUG) << "Analyzing event " << this_eventNumber;
153+
154+
art::Handle<mu2e::CaloDigiCollection> caloDigisHandle;
155+
if (!event.getByLabel(caloDigiTag_, caloDigisHandle)) {
156+
__COUT__ << "[CaloSiDETDQM::" << __func__
157+
<< "] No calo digis found with tag " << caloDigiTag_.c_str()
158+
<< std::endl;
159+
return;
160+
} else if (diagLevel_ > 0) {
161+
__COUT__ << "[CaloSiDETDQM::" << __func__
162+
<< "] Calo digi collection handle found\n";
163+
}
164+
165+
auto caloDigis = caloDigisHandle.product();
166+
if (!caloDigis) {
167+
__COUT__ << "[CaloSiDETDQM::" << __func__
168+
<< "] No calo digis found with tag " << caloDigiTag_.c_str()
169+
<< std::endl;
170+
return;
171+
} else if (diagLevel_ > 0) {
172+
__COUT__ << "[CaloSiDETDQM::" << __func__
173+
<< "] Calo digi collection found\n";
174+
}
175+
176+
if (!caloDigis) {
177+
TLOG(TLVL_DEBUG) << "CaloDigi pointer is null";
178+
} else {
179+
TLOG(TLVL_DEBUG) << "CaloDigi pointer has size " << caloDigis->size();
180+
}
181+
TLOG(TLVL_DEBUG) << "Filling calo DQM plots for event " << this_eventNumber;
182+
summary_fill(event, histo_container, caloDigis);
183+
184+
if (evtCounter_ % freqDQM_ != 0)
185+
return;
186+
187+
// send a packet AND reset the histograms
188+
std::map<std::string, std::vector<TH1 *>> hists_to_send;
189+
std::map<std::string, std::vector<TGraph *>> graphs_to_send;
190+
191+
// send the summary hists
192+
193+
hists_to_send[moduleTag_ + ":replace"].push_back(
194+
(TH1 *)histo_container->h1_channel_occupancy._Hist->Clone());
195+
hists_to_send[moduleTag_ + ":replace"].push_back(
196+
(TH1 *)histo_container->h1_channel_occupancy_lastevent._Hist->Clone());
197+
graphs_to_send[moduleTag_ + ":replace"].push_back(
198+
(TGraph *)histo_container->g_nhits_event._Graph->Clone());
199+
200+
histSender_->sendHistograms(hists_to_send);
201+
histSender_->sendGraphs(graphs_to_send);
202+
}
203+
204+
void ots::CaloSiDETDQM::summary_fill(
205+
art::Event const &event, CaloSiDETDQMHistoContainer *histo_container,
206+
const mu2e::CaloDigiCollection *caloDigis) {
207+
208+
histo_container->h1_channel_occupancy_lastevent._Hist->Reset();
209+
210+
mu2e::CaloDAQMap const &calodaqconds = _calodaqconds_h.get(event.id());
211+
212+
TLOG(TLVL_DEBUG) << "There are " << caloDigis->size() << " calo digis";
213+
for (uint ihit = 0; ihit < caloDigis->size(); ihit++) {
214+
int SiPMID = caloDigis->at(ihit).SiPMID();
215+
int BoardChan = calodaqconds.rawId(mu2e::CaloSiPMId(SiPMID)).id();
216+
int boardID = BoardChan / 20;
217+
int chanID = BoardChan % 20;
218+
// float thisTime = caloDigis->at(ihit).t0();
219+
220+
histo_container->h1_channel_occupancy._Hist->Fill(boardID * 100 + chanID);
221+
histo_container->h1_channel_occupancy_lastevent._Hist->Fill(boardID * 100 +
222+
chanID);
223+
}
224+
225+
histo_container->g_nhits_event._Graph->AddPoint(this_eventNumber,
226+
caloDigis->size());
227+
}
228+
229+
void ots::CaloSiDETDQM::endJob() {}
230+
231+
void ots::CaloSiDETDQM::beginRun(const art::Run &run) {}
232+
233+
DEFINE_ART_MODULE(ots::CaloSiDETDQM)

0 commit comments

Comments
 (0)