|
| 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