File indexing completed on 2025-08-03 08:20:58
0001
0002
0003
0004
0005
0006 #include "BbcMon.h"
0007 #include <mbd/MbdEvent.h>
0008
0009 #include <onlmon/OnlMon.h>
0010 #include <onlmon/OnlMonDB.h>
0011 #include <onlmon/OnlMonServer.h>
0012 #include <onlmon/RunDBodbc.h>
0013 #include <onlmon/triggerEnum.h>
0014
0015 #include <Event/msg_profile.h>
0016
0017 #include <Event/Event.h>
0018 #include <Event/EventTypes.h>
0019 #include <Event/packet.h>
0020 #include <Event/eventReceiverClient.h>
0021
0022 #include <mbd/MbdGeomV1.h>
0023 #include <mbd/MbdOutV2.h>
0024 #include <mbd/MbdPmtContainerV1.h>
0025 #include <mbd/MbdPmtHit.h>
0026
0027 #include <TF1.h>
0028 #include <TGraphErrors.h>
0029 #include <TH1.h>
0030 #include <TH2.h>
0031 #include <TH2Poly.h>
0032 #include <TString.h>
0033 #include <TSystem.h>
0034
0035 #include <cmath>
0036 #include <cstdio> // for printf
0037 #include <ctime>
0038 #include <fstream>
0039 #include <iomanip>
0040 #include <iostream>
0041 #include <sstream>
0042 #include <vector>
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053 BbcMon::BbcMon(const std::string &name)
0054 : OnlMon(name)
0055 {
0056
0057
0058 return;
0059 }
0060
0061 BbcMon::~BbcMon()
0062 {
0063 delete bevt;
0064 delete _mbdgeom;
0065 delete erc;
0066
0067 return;
0068 }
0069
0070 int BbcMon::Init()
0071 {
0072
0073
0074 std::cout << "BbcMon::Init()" << std::endl;
0075
0076 bevt = new MbdEvent();
0077 _mbdgeom = new MbdGeomV1();
0078
0079
0080 mbdns = (0x1UL << TriggerEnum::MBD_NS2) | (0x1UL << TriggerEnum::MBD_NS1);
0081 mbdnsvtx10 = (0x1UL << TriggerEnum::MBD_NS2_ZVRTX10) | (0x1UL << TriggerEnum::MBD_NS1_ZVRTX10);
0082 mbdnsvtx30 = (0x1UL << TriggerEnum::MBD_NS2_ZVRTX30);
0083 mbdnsvtx150 = (0x1UL << TriggerEnum::MBD_NS2_ZVRTX150);
0084 mbdtrig = mbdns | mbdnsvtx10 | mbdnsvtx30 | mbdnsvtx150;
0085 zdcns = (0x1UL << TriggerEnum::ZDC_NS);
0086 emcal = (0x1UL << TriggerEnum::PHOTON6_MBD_NS2) | (0x1UL << TriggerEnum::PHOTON8_MBD_NS2)
0087 | (0x1UL << TriggerEnum::PHOTON10_MBD_NS2) | (0x1UL << TriggerEnum::PHOTON12_MBD_NS2);
0088 hcal = (0x1UL << TriggerEnum::HCAL_SINGLES);
0089 emcalmbd = emcal | mbdtrig;
0090 hcalmbd = hcal | mbdtrig;
0091 trigmask = mbdtrig | zdcns | emcal | hcal;
0092
0093
0094 const char *bbccalib = getenv("BBCCALIB");
0095 if (!bbccalib)
0096 {
0097 std::cout << "BBCCALIB environment variable not set" << std::endl;
0098 exit(1);
0099 }
0100 std::string configfname = std::string(bbccalib) + "/" + "BbcMonData.dat";
0101 std::ifstream configfile(configfname);
0102 if ( configfile.is_open() )
0103 {
0104 std::cout << "MBD: Reading " << configfname << std::endl;
0105 std::string label;
0106 uint64_t trigbit{0};
0107 while ( configfile >> label >> std::hex >> trigbit >> std::dec )
0108 {
0109 if ( label == "#" )
0110 {
0111 continue;
0112 }
0113 else if ( label == "USEGL1" )
0114 {
0115 useGL1 = static_cast<int>(trigbit);
0116 }
0117 else if ( label == "TRIGMASK" )
0118 {
0119 trigmask = trigbit;
0120 std::cout << "Overriding with trigmask " << label << " 0x" << std::hex << trigbit << std::dec << std::endl;
0121 }
0122 else if ( label[0] != '#' && label[0] != '/' )
0123 {
0124 std::cout << "Using trigger " << label << " 0x" << std::hex << trigbit << std::dec << std::endl;
0125 }
0126 }
0127
0128 configfile.close();
0129 }
0130 else
0131 {
0132 std::cout << "MBD: ERROR, " << configfname << " not found" << std::endl;
0133 exit(1);
0134 }
0135 orig_trigmask = trigmask;
0136
0137
0138 if ( useGL1==1 )
0139 {
0140 erc = new eventReceiverClient("gl1daq");
0141 rdb = new RunDBodbc;
0142 }
0143 else if ( useGL1==2 )
0144 {
0145 std::cout << "Connecting to eventserver on localhost" << std::endl;
0146 erc = new eventReceiverClient("localhost");
0147 rdb = new RunDBodbc;
0148 }
0149
0150
0151
0152
0153 if ( useGL1 )
0154 {
0155 bbc_trigs = new TH1F("bbc_trigs", "Trigger Counts", 64, -0.5, 63.5);
0156
0157 for ( int i = 0; i < TriggerEnum::NUM_MBD_TRIGGERS; i++ ){
0158 std::string name = Form("bbc_zvertex_autoupdate_%i", i);
0159 bbc_zvertex_autoupdate[i] = new TH1F(name.c_str(),
0160 Form("MBD ZVertex Trigger %s", TriggerEnum::MBTriggerNames[i]),
0161 BbcMonDefs::zvtnbin, BbcMonDefs::min_zvertex, BbcMonDefs::max_zvertex);
0162 bbc_zvertex_autoupdate[i]->Sumw2();
0163 bbc_zvertex_autoupdate[i]->GetXaxis()->SetTitle("ZVertex [cm]");
0164 bbc_zvertex_autoupdate[i]->GetYaxis()->SetTitle("Number of Event");
0165 bbc_zvertex_autoupdate[i]->GetXaxis()->SetTitleSize(0.05);
0166 bbc_zvertex_autoupdate[i]->GetYaxis()->SetTitleSize(0.05);
0167 bbc_zvertex_autoupdate[i]->GetXaxis()->SetTitleOffset(0.70);
0168 bbc_zvertex_autoupdate[i]->GetYaxis()->SetTitleOffset(1.75);
0169 bbc_zvertex_autoupdate[i]->GetXaxis()->SetLabelSize(0.07);
0170 bbc_zvertex_autoupdate[i]->GetXaxis()->SetTickSize(0.1);
0171 }
0172 }
0173
0174
0175 bbc_south_nhit = new TH1F("bbc_south_nhit","MBD.S Nhits",64,-0.5,63.5);
0176 bbc_north_nhit = new TH1F("bbc_north_nhit","MBD.N Nhits",64,-0.5,63.5);
0177 for (int iarm=0; iarm<2; iarm++)
0178 {
0179 TString name = "bbc_nhit_emcal"; name += iarm;
0180 bbc_nhit_emcal[iarm] = new TH1F(name,"MBD Nhits, EMCAL trig",64,-0.5,63.5);
0181 name = "bbc_nhit_hcal"; name += iarm;
0182 bbc_nhit_hcal[iarm] = new TH1F(name,"MBD Nhits, JET trig",64,-0.5,63.5);
0183 name = "bbc_nhit_emcalmbd"; name += iarm;
0184 bbc_nhit_emcalmbd[iarm] = new TH1F(name,"MBD Nhits, EMCAL&&MBD trig",64,-0.5,63.5);
0185 name = "bbc_nhit_hcalmbd"; name += iarm;
0186 bbc_nhit_hcalmbd[iarm] = new TH1F(name,"MBD Nhits, JET&&MBD trig",64,-0.5,63.5);
0187 }
0188
0189
0190
0191 bbc_tdc = new TH2F("bbc_tdc", "BBC Raw TDC Distribution",
0192 nPMT_BBC, -.5, nPMT_BBC - .5,
0193 BbcMonDefs::nBIN_TDC, 0, BbcMonDefs::tdc_max_overflow * BbcMonDefs::TDC_CONVERSION_FACTOR);
0194
0195
0196
0197 bbc_tdc_overflow = new TH2F("bbc_tdc_overflow", "MBD TDC Overflow Deviation",
0198 nPMT_BBC, -.5, nPMT_BBC - .5,
0199 int(BbcMonDefs::VIEW_OVERFLOW_MAX - BbcMonDefs::VIEW_OVERFLOW_MIN + 1),
0200 BbcMonDefs::VIEW_OVERFLOW_MIN - .5, BbcMonDefs::VIEW_OVERFLOW_MAX + .5);
0201
0202 std::ostringstream name, title;
0203
0204
0205 for (int ipmt = 0; ipmt < nPMT_BBC; ipmt++)
0206 {
0207 name << "bbc_tdc_overflow_" << std::setw(3) << std::setfill('0') << ipmt;
0208 title << "MBD TDC Overflow Deviation of #" << std::setw(3) << std::setfill('0') << ipmt;
0209 bbc_tdc_overflow_each[ipmt] = new TH1F(name.str().c_str(), title.str().c_str(),
0210 int(BbcMonDefs::VIEW_OVERFLOW_MAX - BbcMonDefs::VIEW_OVERFLOW_MIN + 1),
0211 BbcMonDefs::VIEW_OVERFLOW_MIN, BbcMonDefs::VIEW_OVERFLOW_MAX);
0212 name.str("");
0213 name.clear();
0214 title.str("");
0215 title.clear();
0216 }
0217
0218
0219
0220 bbc_adc = new TH2F("bbc_adc", "MBD ADC(Charge) Distribution", nPMT_BBC, -.5, nPMT_BBC - .5, BbcMonDefs::nBIN_ADC, 0, BbcMonDefs::MAX_ADC_MIP);
0221
0222 bbc_tdc_armhittime = new TH2F("bbc_tdc_armhittime", "Arm-Hit-Time Correlation of North and South MBD",
0223 64, BbcMonDefs::min_armhittime, BbcMonDefs::max_armhittime,
0224 64, BbcMonDefs::min_armhittime, BbcMonDefs::max_armhittime);
0225 bbc_tdc_armhittime->GetXaxis()->SetTitle("South [ns]");
0226 bbc_tdc_armhittime->GetYaxis()->SetTitle("North [ns]");
0227
0228
0229
0230 bbc_zvertex = new TH1F("bbc_zvertex", "MBD ZVertex, main trigger", BbcMonDefs::zvtnbin, BbcMonDefs::min_zvertex, BbcMonDefs::max_zvertex);
0231 bbc_zvertex->Sumw2();
0232 bbc_zvertex->GetXaxis()->SetTitle("ZVertex [cm]");
0233 bbc_zvertex->GetYaxis()->SetTitle("Number of Event");
0234 bbc_zvertex->GetXaxis()->SetTitleSize(0.05);
0235 bbc_zvertex->GetYaxis()->SetTitleSize(0.05);
0236 bbc_zvertex->GetXaxis()->SetTitleOffset(0.70);
0237 bbc_zvertex->GetYaxis()->SetTitleOffset(1.75);
0238 bbc_zvertex->GetXaxis()->SetLabelSize(0.07);
0239 bbc_zvertex->GetXaxis()->SetTickSize(0.1);
0240
0241 bbc_zvertex_alltrigger = new TH1F("bbc_zvertex_alltrigger", "MBD ZVertex, all triggers",
0242 BbcMonDefs::zvtnbin, BbcMonDefs::min_zvertex, BbcMonDefs::max_zvertex);
0243 bbc_zvertex_alltrigger->Sumw2();
0244 bbc_zvertex_alltrigger->GetXaxis()->SetTitle("ZVertex [cm]");
0245 bbc_zvertex_alltrigger->GetYaxis()->SetTitle("Number of Event");
0246 bbc_zvertex_alltrigger->GetXaxis()->SetTitleSize(0.05);
0247 bbc_zvertex_alltrigger->GetYaxis()->SetTitleSize(0.05);
0248 bbc_zvertex_alltrigger->GetXaxis()->SetTitleOffset(0.70);
0249 bbc_zvertex_alltrigger->GetYaxis()->SetTitleOffset(1.75);
0250 bbc_zvertex_alltrigger->GetXaxis()->SetLabelSize(0.07);
0251 bbc_zvertex_alltrigger->GetXaxis()->SetTickSize(0.1);
0252
0253 bbc_zvertex_short = new TH1F("bbc_zvertex_short", "MBD ZVertex (NS, wide), short time scale",
0254 BbcMonDefs::zvtnbin, BbcMonDefs::min_zvertex, BbcMonDefs::max_zvertex);
0255 bbc_zvertex_short->Sumw2();
0256 bbc_zvertex_short->GetXaxis()->SetTitle("ZVertex [cm]");
0257 bbc_zvertex_short->GetYaxis()->SetTitle("Number of Event");
0258 bbc_zvertex_short->GetXaxis()->SetTitleSize(0.05);
0259 bbc_zvertex_short->GetYaxis()->SetTitleSize(0.05);
0260 bbc_zvertex_short->GetXaxis()->SetTitleOffset(0.70);
0261 bbc_zvertex_short->GetYaxis()->SetTitleOffset(1.75);
0262
0263 bbc_zvertex_prime_short = new TH1F("bbc_zvertex_prime_short", "MBD ZVertex (NS, prime), short time scale",
0264 BbcMonDefs::zvtnbin, BbcMonDefs::min_zvertex, BbcMonDefs::max_zvertex);
0265 bbc_zvertex_prime_short->Sumw2();
0266 bbc_zvertex_prime_short->GetXaxis()->SetTitle("ZVertex [cm]");
0267 bbc_zvertex_prime_short->GetYaxis()->SetTitle("Number of Event");
0268 bbc_zvertex_prime_short->GetXaxis()->SetTitleSize(0.05);
0269 bbc_zvertex_prime_short->GetYaxis()->SetTitleSize(0.05);
0270 bbc_zvertex_prime_short->GetXaxis()->SetTitleOffset(0.70);
0271 bbc_zvertex_prime_short->GetYaxis()->SetTitleOffset(1.75);
0272
0273 bbc_zvertex_ns = new TH1F("bbc_zvertex_ns", "MBD zvertex_ns, main trigger", BbcMonDefs::zvtnbin, BbcMonDefs::min_zvertex, BbcMonDefs::max_zvertex);
0274 bbc_zvertex_ns->GetXaxis()->SetTitle("zvertex [cm]");
0275 bbc_zvertex_ns->GetYaxis()->SetTitle("Number of Event");
0276 bbc_zvertex_ns->GetXaxis()->SetTitleSize(0.05);
0277 bbc_zvertex_ns->GetYaxis()->SetTitleSize(0.05);
0278 bbc_zvertex_ns->GetXaxis()->SetTitleOffset(0.70);
0279 bbc_zvertex_ns->GetYaxis()->SetTitleOffset(1.75);
0280 bbc_zvertex_ns->GetXaxis()->SetLabelSize(0.07);
0281 bbc_zvertex_ns->GetXaxis()->SetTickSize(0.1);
0282
0283 bbc_zvertex_10 = new TH1F("bbc_zvertex_10", "MBD ZVertex (|z|<10)",
0284 BbcMonDefs::zvtnbin, BbcMonDefs::min_zvertex, BbcMonDefs::max_zvertex);
0285 bbc_zvertex_10->GetXaxis()->SetTitle("ZVertex [cm]");
0286 bbc_zvertex_10->GetYaxis()->SetTitle("Number of Event");
0287 bbc_zvertex_10->GetXaxis()->SetTitleSize(0.05);
0288 bbc_zvertex_10->GetYaxis()->SetTitleSize(0.05);
0289 bbc_zvertex_10->GetXaxis()->SetTitleOffset(0.70);
0290 bbc_zvertex_10->GetYaxis()->SetTitleOffset(1.75);
0291 bbc_zvertex_10->GetXaxis()->SetLabelSize(0.05);
0292 bbc_zvertex_10->GetXaxis()->SetTickSize(0.1);
0293
0294 bbc_zvertex_30 = new TH1F("bbc_zvertex_30", "MBD ZVertex (|z|<30)",
0295 BbcMonDefs::zvtnbin, BbcMonDefs::min_zvertex, BbcMonDefs::max_zvertex);
0296 bbc_zvertex_30->GetXaxis()->SetTitle("ZVertex [cm]");
0297 bbc_zvertex_30->GetYaxis()->SetTitle("Number of Event");
0298 bbc_zvertex_30->GetXaxis()->SetTitleSize(0.05);
0299 bbc_zvertex_30->GetYaxis()->SetTitleSize(0.05);
0300 bbc_zvertex_30->GetXaxis()->SetTitleOffset(0.70);
0301 bbc_zvertex_30->GetYaxis()->SetTitleOffset(1.75);
0302 bbc_zvertex_30->GetXaxis()->SetLabelSize(0.05);
0303 bbc_zvertex_30->GetXaxis()->SetTickSize(0.1);
0304
0305 bbc_zvertex_60 = new TH1F("bbc_zvertex_60", "MBD ZVertex (|z|<60)",
0306 BbcMonDefs::zvtnbin, BbcMonDefs::min_zvertex, BbcMonDefs::max_zvertex);
0307 bbc_zvertex_60->GetXaxis()->SetTitle("ZVertex [cm]");
0308 bbc_zvertex_60->GetYaxis()->SetTitle("Number of Event");
0309 bbc_zvertex_60->GetXaxis()->SetTitleSize(0.05);
0310 bbc_zvertex_60->GetYaxis()->SetTitleSize(0.05);
0311 bbc_zvertex_60->GetXaxis()->SetTitleOffset(0.70);
0312 bbc_zvertex_60->GetYaxis()->SetTitleOffset(1.75);
0313 bbc_zvertex_60->GetXaxis()->SetLabelSize(0.05);
0314 bbc_zvertex_60->GetXaxis()->SetTickSize(0.1);
0315
0316 bbc_zvertex_ns_chk = new TH1F("bbc_zvertex_ns_chk", "MBD ZVertex (|z|<10)",
0317 BbcMonDefs::zvtnbin, BbcMonDefs::min_zvertex, BbcMonDefs::max_zvertex);
0318 bbc_zvertex_ns_chk->GetXaxis()->SetTitle("ZVertex [cm]");
0319 bbc_zvertex_ns_chk->GetYaxis()->SetTitle("Number of Event");
0320 bbc_zvertex_ns_chk->GetXaxis()->SetTitleSize(0.05);
0321 bbc_zvertex_ns_chk->GetYaxis()->SetTitleSize(0.05);
0322 bbc_zvertex_ns_chk->GetXaxis()->SetTitleOffset(0.70);
0323 bbc_zvertex_ns_chk->GetYaxis()->SetTitleOffset(1.75);
0324 bbc_zvertex_ns_chk->GetXaxis()->SetLabelSize(0.05);
0325 bbc_zvertex_ns_chk->GetXaxis()->SetTickSize(0.1);
0326
0327 bbc_zvertex_10_chk = new TH1F("bbc_zvertex_10_chk", "MBD ZVertex (|z|<10)",
0328 BbcMonDefs::zvtnbin, BbcMonDefs::min_zvertex, BbcMonDefs::max_zvertex);
0329 bbc_zvertex_10_chk->GetXaxis()->SetTitle("ZVertex [cm]");
0330 bbc_zvertex_10_chk->GetYaxis()->SetTitle("Number of Event");
0331 bbc_zvertex_10_chk->GetXaxis()->SetTitleSize(0.05);
0332 bbc_zvertex_10_chk->GetYaxis()->SetTitleSize(0.05);
0333 bbc_zvertex_10_chk->GetXaxis()->SetTitleOffset(0.70);
0334 bbc_zvertex_10_chk->GetYaxis()->SetTitleOffset(1.75);
0335 bbc_zvertex_10_chk->GetXaxis()->SetLabelSize(0.05);
0336 bbc_zvertex_10_chk->GetXaxis()->SetTickSize(0.1);
0337
0338 bbc_zvertex_30_chk = new TH1F("bbc_zvertex_30_chk", "MBD ZVertex (|z|<30)",
0339 BbcMonDefs::zvtnbin, BbcMonDefs::min_zvertex, BbcMonDefs::max_zvertex);
0340 bbc_zvertex_30_chk->GetXaxis()->SetTitle("ZVertex [cm]");
0341 bbc_zvertex_30_chk->GetYaxis()->SetTitle("Number of Event");
0342 bbc_zvertex_30_chk->GetXaxis()->SetTitleSize(0.05);
0343 bbc_zvertex_30_chk->GetYaxis()->SetTitleSize(0.05);
0344 bbc_zvertex_30_chk->GetXaxis()->SetTitleOffset(0.70);
0345 bbc_zvertex_30_chk->GetYaxis()->SetTitleOffset(1.75);
0346 bbc_zvertex_30_chk->GetXaxis()->SetLabelSize(0.05);
0347 bbc_zvertex_30_chk->GetXaxis()->SetTickSize(0.1);
0348
0349 bbc_zvertex_60_chk = new TH1F("bbc_zvertex_60_chk", "MBD ZVertex (|z|<60)",
0350 BbcMonDefs::zvtnbin, BbcMonDefs::min_zvertex, BbcMonDefs::max_zvertex);
0351 bbc_zvertex_60_chk->GetXaxis()->SetTitle("ZVertex [cm]");
0352 bbc_zvertex_60_chk->GetYaxis()->SetTitle("Number of Event");
0353 bbc_zvertex_60_chk->GetXaxis()->SetTitleSize(0.05);
0354 bbc_zvertex_60_chk->GetYaxis()->SetTitleSize(0.05);
0355 bbc_zvertex_60_chk->GetXaxis()->SetTitleOffset(0.70);
0356 bbc_zvertex_60_chk->GetYaxis()->SetTitleOffset(1.75);
0357 bbc_zvertex_60_chk->GetXaxis()->SetLabelSize(0.05);
0358 bbc_zvertex_60_chk->GetXaxis()->SetTickSize(0.1);
0359
0360 bbc_zvertex_zdcns = new TH1F("bbc_zvertex_zdcns", "MBD zvertex, ZDCNS trig", BbcMonDefs::zvtnbin, BbcMonDefs::min_zvertex, BbcMonDefs::max_zvertex);
0361 bbc_zvertex_zdcns->GetXaxis()->SetTitle("zvertex [cm]");
0362 bbc_zvertex_zdcns->GetYaxis()->SetTitle("Number of Event");
0363 bbc_zvertex_zdcns->GetXaxis()->SetTitleSize(0.05);
0364 bbc_zvertex_zdcns->GetYaxis()->SetTitleSize(0.05);
0365 bbc_zvertex_zdcns->GetXaxis()->SetTitleOffset(0.70);
0366 bbc_zvertex_zdcns->GetYaxis()->SetTitleOffset(1.75);
0367 bbc_zvertex_zdcns->GetXaxis()->SetLabelSize(0.07);
0368 bbc_zvertex_zdcns->GetXaxis()->SetTickSize(0.1);
0369
0370 bbc_zvertex_emcal = new TH1F("bbc_zvertex_emcal", "MBD zvertex, PHOTON trig", BbcMonDefs::zvtnbin, BbcMonDefs::min_zvertex, BbcMonDefs::max_zvertex);
0371 bbc_zvertex_emcal->GetXaxis()->SetTitle("zvertex [cm]");
0372 bbc_zvertex_emcal->GetYaxis()->SetTitle("Number of Event");
0373 bbc_zvertex_emcal->GetXaxis()->SetTitleSize(0.05);
0374 bbc_zvertex_emcal->GetYaxis()->SetTitleSize(0.05);
0375 bbc_zvertex_emcal->GetXaxis()->SetTitleOffset(0.70);
0376 bbc_zvertex_emcal->GetYaxis()->SetTitleOffset(1.75);
0377 bbc_zvertex_emcal->GetXaxis()->SetLabelSize(0.07);
0378 bbc_zvertex_emcal->GetXaxis()->SetTickSize(0.1);
0379
0380 bbc_zvertex_hcal = new TH1F("bbc_zvertex_hcal", "MBD zvertex, JET trig", BbcMonDefs::zvtnbin, BbcMonDefs::min_zvertex, BbcMonDefs::max_zvertex);
0381 bbc_zvertex_hcal->GetXaxis()->SetTitle("zvertex [cm]");
0382 bbc_zvertex_hcal->GetYaxis()->SetTitle("Number of Event");
0383 bbc_zvertex_hcal->GetXaxis()->SetTitleSize(0.05);
0384 bbc_zvertex_hcal->GetYaxis()->SetTitleSize(0.05);
0385 bbc_zvertex_hcal->GetXaxis()->SetTitleOffset(0.70);
0386 bbc_zvertex_hcal->GetYaxis()->SetTitleOffset(1.75);
0387 bbc_zvertex_hcal->GetXaxis()->SetLabelSize(0.07);
0388 bbc_zvertex_hcal->GetXaxis()->SetTickSize(0.1);
0389
0390 bbc_zvertex_emcalmbd = new TH1F("bbc_zvertex_emcalmbd", "MBD zvertex, PHOTON&&MBD trig", BbcMonDefs::zvtnbin, BbcMonDefs::min_zvertex, BbcMonDefs::max_zvertex);
0391 bbc_zvertex_emcalmbd->GetXaxis()->SetTitle("zvertex [cm]");
0392 bbc_zvertex_emcalmbd->GetYaxis()->SetTitle("Number of Event");
0393 bbc_zvertex_emcalmbd->GetXaxis()->SetTitleSize(0.05);
0394 bbc_zvertex_emcalmbd->GetYaxis()->SetTitleSize(0.05);
0395 bbc_zvertex_emcalmbd->GetXaxis()->SetTitleOffset(0.70);
0396 bbc_zvertex_emcalmbd->GetYaxis()->SetTitleOffset(1.75);
0397 bbc_zvertex_emcalmbd->GetXaxis()->SetLabelSize(0.07);
0398 bbc_zvertex_emcalmbd->GetXaxis()->SetTickSize(0.1);
0399
0400 bbc_zvertex_hcalmbd = new TH1F("bbc_zvertex_hcalmbd", "MBD zvertex, JET&&MBD trig", BbcMonDefs::zvtnbin, BbcMonDefs::min_zvertex, BbcMonDefs::max_zvertex);
0401 bbc_zvertex_hcalmbd->GetXaxis()->SetTitle("zvertex [cm]");
0402 bbc_zvertex_hcalmbd->GetYaxis()->SetTitle("Number of Event");
0403 bbc_zvertex_hcalmbd->GetXaxis()->SetTitleSize(0.05);
0404 bbc_zvertex_hcalmbd->GetYaxis()->SetTitleSize(0.05);
0405 bbc_zvertex_hcalmbd->GetXaxis()->SetTitleOffset(0.70);
0406 bbc_zvertex_hcalmbd->GetYaxis()->SetTitleOffset(1.75);
0407 bbc_zvertex_hcalmbd->GetXaxis()->SetLabelSize(0.07);
0408 bbc_zvertex_hcalmbd->GetXaxis()->SetTickSize(0.1);
0409
0410 f_zvtx = new TF1("f_zvtx", "gaus", -30., 30.);
0411 bbc_nevent_counter = new TH1F("bbc_nevent_counter",
0412 "The nEvent Counter bin1:Total Event bin2:Collision Event bin3:Laser Event",
0413 16, 0, 16);
0414
0415
0416
0417 bbc_tzero_zvtx = new TH2F("bbc_tzero_zvtx", "TimeZero vs ZVertex", 100, -200, 200, 110, -16, 16);
0418 bbc_tzero_zvtx->SetXTitle("ZVertex [cm]");
0419 bbc_tzero_zvtx->SetYTitle("TimeZero[ns]");
0420
0421 bbc_avr_hittime = new TH1F("bbc_avr_hittime", "MBD Average Hittime", 128, 0, 24);
0422 bbc_avr_hittime->Sumw2();
0423 bbc_avr_hittime->GetXaxis()->SetTitle("Avr HitTime [ns]");
0424 bbc_avr_hittime->GetYaxis()->SetTitle("Number of Event");
0425 bbc_avr_hittime->GetXaxis()->SetTitleSize(0.05);
0426 bbc_avr_hittime->GetYaxis()->SetTitleSize(0.05);
0427 bbc_avr_hittime->GetXaxis()->SetTitleOffset(0.70);
0428 bbc_avr_hittime->GetYaxis()->SetTitleOffset(1.75);
0429
0430
0431
0432
0433 bbc_south_hittime = new TH1F("bbc_south_hittime", "MBD South Hittime", 150, -15, 15);
0434 bbc_north_hittime = new TH1F("bbc_north_hittime", "MBD North Hittime", 150, -15, 15);
0435
0436 bbc_south_hittime->GetXaxis()->SetTitle("South HitTime [ns]");
0437 bbc_south_hittime->GetYaxis()->SetTitle("Number of Event");
0438 bbc_south_hittime->GetXaxis()->SetTitleSize(0.05);
0439 bbc_south_hittime->GetYaxis()->SetTitleSize(0.05);
0440 bbc_south_hittime->GetXaxis()->SetTitleOffset(0.70);
0441 bbc_south_hittime->GetYaxis()->SetTitleOffset(1.75);
0442
0443 bbc_north_hittime->GetXaxis()->SetTitle("North HitTime [ns]");
0444 bbc_north_hittime->GetYaxis()->SetTitle("Number of Event");
0445 bbc_north_hittime->GetXaxis()->SetTitleSize(0.05);
0446 bbc_north_hittime->GetYaxis()->SetTitleSize(0.05);
0447 bbc_north_hittime->GetXaxis()->SetTitleOffset(0.70);
0448 bbc_north_hittime->GetYaxis()->SetTitleOffset(1.75);
0449
0450
0451
0452 bbc_south_chargesum = new TH1F("bbc_south_chargesum", "BBC South ChargeSum [AU]", 128, 0, BbcMonDefs::MAX_CHARGE_SUM);
0453 bbc_north_chargesum = new TH1F("bbc_north_chargesum", "BBC North ChargeSum [AU]", 128, 0, BbcMonDefs::MAX_CHARGE_SUM);
0454
0455 bbc_north_chargesum->SetTitle("MBD ChargeSum [MIP]");
0456 bbc_north_chargesum->GetXaxis()->SetTitle("ChargeSum [MIP]");
0457
0458 bbc_north_chargesum->GetYaxis()->SetTitle("Number of Event");
0459 bbc_north_chargesum->GetXaxis()->SetTitleSize(0.05);
0460 bbc_north_chargesum->GetYaxis()->SetTitleSize(0.05);
0461 bbc_north_chargesum->GetXaxis()->SetTitleOffset(0.70);
0462 bbc_north_chargesum->GetYaxis()->SetTitleOffset(1.75);
0463
0464
0465 bbc_south_chargesum->GetYaxis()->SetTitle("Number of Event");
0466 bbc_south_chargesum->GetXaxis()->SetTitleSize(0.05);
0467 bbc_south_chargesum->GetYaxis()->SetTitleSize(0.05);
0468 bbc_south_chargesum->GetXaxis()->SetTitleOffset(0.70);
0469 bbc_south_chargesum->GetYaxis()->SetTitleOffset(1.75);
0470
0471
0472 bbc_prescale_hist = new TH1F("bbc_prescale_hist", "prescales", 64, 0, 64);
0473 bbc_prescale_hist->SetXTitle("trigger");
0474
0475
0476 bbc_time_wave = new TH2F("bbc_time_wave", "MBD time waveforms by ch", BbcMonDefs::BBC_MAXSAMPLES, -0.5, BbcMonDefs::BBC_MAXSAMPLES - 0.5, 128, 0, 128);
0477 bbc_charge_wave = new TH2F("bbc_charge_wave", "MBD charge waveforms by ch", BbcMonDefs::BBC_MAXSAMPLES, -0.5, BbcMonDefs::BBC_MAXSAMPLES - 0.5, 128, 0, 128);
0478
0479 bbc_time_wave->GetXaxis()->SetTitle("Sample");
0480 bbc_time_wave->GetYaxis()->SetTitle("Ch");
0481 bbc_time_wave->GetXaxis()->SetTitleSize(0.05);
0482 bbc_time_wave->GetYaxis()->SetTitleSize(0.05);
0483 bbc_time_wave->GetXaxis()->SetTitleOffset(0.70);
0484 bbc_time_wave->GetYaxis()->SetTitleOffset(0.75);
0485 bbc_charge_wave->GetXaxis()->SetTitle("Sample");
0486 bbc_charge_wave->GetYaxis()->SetTitle("Ch");
0487 bbc_charge_wave->GetXaxis()->SetTitleSize(0.05);
0488 bbc_charge_wave->GetYaxis()->SetTitleSize(0.05);
0489 bbc_charge_wave->GetXaxis()->SetTitleOffset(0.70);
0490 bbc_charge_wave->GetYaxis()->SetTitleOffset(0.75);
0491
0492 bbc_runvtx = new TH1F("bbc_runvtx","running vtx",2000,0,2000);
0493 bbc_runvtxerr = new TH1F("bbc_runvtxerr","running vtx err",2000,0,2000);
0494 bbc_runvtxtime = new TH1F("bbc_runvtxtime","running vtx time",2000,0,2000);
0495
0496
0497 bbc_south_hitmap = new TH2Poly();
0498 bbc_south_hitmap->SetName("bbc_south_hitmap");
0499 bbc_south_hitmap->SetTitle("MBD South Hitmap");
0500 bbc_south_hitmap->GetXaxis()->SetTitle("x (cm)");
0501 bbc_south_hitmap->GetYaxis()->SetTitle("y (cm)");
0502 bbc_south_hitmap->GetXaxis()->SetTitleSize(0.05);
0503 bbc_south_hitmap->GetYaxis()->SetTitleSize(0.05);
0504 bbc_south_hitmap->GetXaxis()->SetTitleOffset(0.70);
0505 bbc_south_hitmap->GetYaxis()->SetTitleOffset(0.70);
0506 bbc_south_hitmap->SetMinimum(0.001);
0507
0508 bbc_north_hitmap = new TH2Poly();
0509 bbc_north_hitmap->SetName("bbc_north_hitmap");
0510 bbc_north_hitmap->SetTitle("MBD North Hitmap");
0511 bbc_north_hitmap->GetXaxis()->SetTitle("x (cm)");
0512 bbc_north_hitmap->GetYaxis()->SetTitle("y (cm)");
0513 bbc_north_hitmap->GetXaxis()->SetTitleSize(0.05);
0514 bbc_north_hitmap->GetYaxis()->SetTitleSize(0.05);
0515 bbc_north_hitmap->GetXaxis()->SetTitleOffset(0.70);
0516 bbc_north_hitmap->GetYaxis()->SetTitleOffset(0.70);
0517 bbc_north_hitmap->SetMinimum(0.001);
0518
0519
0520 Double_t x[6];
0521 Double_t y[6];
0522 for (int ipmt = 0; ipmt < 128; ipmt++)
0523 {
0524 float xcent = _mbdgeom->get_x(ipmt);
0525 float ycent = _mbdgeom->get_y(ipmt);
0526 int arm = _mbdgeom->get_arm(ipmt);
0527 std::cout << ipmt << "\t" << xcent << "\t" << ycent << std::endl;
0528
0529
0530 x[0] = xcent - 0.8;
0531 y[0] = ycent + 1.4;
0532 x[1] = xcent + 0.8;
0533 y[1] = ycent + 1.4;
0534 x[2] = xcent + 1.6;
0535 y[2] = ycent;
0536 x[3] = xcent + 0.8;
0537 y[3] = ycent - 1.4;
0538 x[4] = xcent - 0.8;
0539 y[4] = ycent - 1.4;
0540 x[5] = xcent - 1.6;
0541 y[5] = ycent;
0542
0543 if (arm == 0)
0544 {
0545 bbc_south_hitmap->AddBin(6, x, y);
0546 }
0547 else if (arm == 1)
0548 {
0549 bbc_north_hitmap->AddBin(6, x, y);
0550 }
0551 }
0552
0553
0554 OnlMonServer *se = OnlMonServer::instance();
0555
0556
0557
0558 se->registerHisto(this, bbc_trigs);
0559 for ( int i = 0; i < TriggerEnum::NUM_MBD_TRIGGERS; i++ ){
0560 se->registerHisto(this, bbc_zvertex_autoupdate[i]);
0561 }
0562
0563 se->registerHisto(this, bbc_south_nhit);
0564 se->registerHisto(this, bbc_north_nhit);
0565 for (int iarm=0; iarm<2; iarm++)
0566 {
0567 se->registerHisto(this, bbc_nhit_emcal[iarm]);
0568 se->registerHisto(this, bbc_nhit_hcal[iarm]);
0569 se->registerHisto(this, bbc_nhit_emcalmbd[iarm]);
0570 se->registerHisto(this, bbc_nhit_hcalmbd[iarm]);
0571 }
0572 se->registerHisto(this, bbc_adc);
0573 se->registerHisto(this, bbc_tdc);
0574 se->registerHisto(this, bbc_tdc_overflow);
0575 for (auto &ipmt : bbc_tdc_overflow_each)
0576 {
0577 se->registerHisto(this, ipmt);
0578 }
0579
0580 se->registerHisto(this, bbc_tdc_armhittime);
0581 se->registerHisto(this, bbc_zvertex);
0582 se->registerHisto(this, bbc_zvertex_alltrigger);
0583 se->registerHisto(this, bbc_zvertex_ns);
0584 se->registerHisto(this, bbc_zvertex_10);
0585 se->registerHisto(this, bbc_zvertex_30);
0586 se->registerHisto(this, bbc_zvertex_60);
0587 se->registerHisto(this, bbc_zvertex_ns_chk);
0588 se->registerHisto(this, bbc_zvertex_10_chk);
0589 se->registerHisto(this, bbc_zvertex_30_chk);
0590 se->registerHisto(this, bbc_zvertex_60_chk);
0591 se->registerHisto(this, bbc_zvertex_zdcns);
0592 se->registerHisto(this, bbc_zvertex_emcal);
0593 se->registerHisto(this, bbc_zvertex_hcal);
0594 se->registerHisto(this, bbc_zvertex_emcalmbd);
0595 se->registerHisto(this, bbc_zvertex_hcalmbd);
0596 se->registerHisto(this, bbc_nevent_counter);
0597 se->registerHisto(this, bbc_tzero_zvtx);
0598 se->registerHisto(this, bbc_prescale_hist);
0599 se->registerHisto(this, bbc_avr_hittime);
0600 se->registerHisto(this, bbc_north_hittime);
0601 se->registerHisto(this, bbc_south_hittime);
0602 se->registerHisto(this, bbc_north_chargesum);
0603 se->registerHisto(this, bbc_south_chargesum);
0604 se->registerHisto(this, bbc_north_hitmap);
0605 se->registerHisto(this, bbc_south_hitmap);
0606
0607
0608
0609
0610 se->registerHisto(this, bbc_time_wave);
0611 se->registerHisto(this, bbc_charge_wave);
0612 se->registerHisto(this, bbc_runvtx);
0613 se->registerHisto(this, bbc_runvtxerr);
0614 se->registerHisto(this, bbc_runvtxtime);
0615
0616
0617
0618
0619
0620 Reset();
0621
0622 m_mbdout = new MbdOutV2();
0623 m_mbdpmts = new MbdPmtContainerV1();
0624
0625
0626 char hname[1024];
0627 gethostname(hname,sizeof(hname)-1);
0628 sendflagfname = "/home/phnxrc/operations/mbd/mbd2mcr.";
0629 sendflagfname += hname;
0630 std::cout << "sendflagfname " << sendflagfname << "\t" << hname << std::endl;
0631 fillnumber = 0;
0632
0633
0634
0635
0636
0637
0638
0639
0640
0641 zresetflagfname = "/home/phnxrc/operations/mbd/mbdzreset.";
0642 zresetflagfname += hname;
0643 UpdateZResetFlag( 0 );
0644
0645 gl1badflagfname = "/home/phnxrc/operations/mbd/mbdgl1bypass.";
0646 gl1badflagfname += hname;
0647 std::cout << "gl1badflagfname " << gl1badflagfname << "\t" << hname << std::endl;
0648
0649 return 0;
0650 }
0651
0652 int BbcMon::BeginRun(const int runno)
0653 {
0654
0655
0656 std::cout << "BbcMon::BeginRun(), run " << runno << std::endl;
0657 Reset();
0658 if ( useGL1 )
0659 {
0660 OnlMonServer *se = OnlMonServer::instance();
0661 se->UseGl1();
0662 }
0663 bevt->InitRun();
0664
0665
0666 int prev_fill = fillnumber;
0667 int current_fill = GetFillNumber();
0668 if ( prev_fill==0 || current_fill!=prev_fill )
0669 {
0670 std::cout << "MBD: Found new fill " << current_fill << std::endl;
0671 fillnumber = current_fill;
0672
0673
0674
0675
0676
0677
0678 }
0679
0680
0681 UpdateZResetFlag( 0 );
0682
0683
0684 tstart = std::time(nullptr);
0685
0686
0687 GetGL1BadFlag();
0688
0689 uint64_t trigs_enabled = 0;
0690 if ( rdb != nullptr )
0691 {
0692 std::vector<int> scaledowns;
0693 rdb->GetScaledowns( scaledowns, runno );
0694 bbc_prescale_hist->Reset();
0695 for ( int itrig = 0; itrig < 64; itrig++)
0696 {
0697 bbc_prescale_hist->SetBinContent( itrig+1, scaledowns[itrig] );
0698 std::cout << "scaledowns " << itrig << "\t" << scaledowns[itrig] << std::endl;
0699
0700 if ( scaledowns[itrig] >= 0 )
0701 {
0702 trigs_enabled |= (0x1UL<<itrig);
0703 }
0704 }
0705 }
0706 std::cout << "trigs_enabled 0x" << std::hex << trigs_enabled << std::dec << std::endl;
0707
0708 mbdbest = GetMinBiasTrigBit( trigs_enabled );
0709 mbdwidebest = GetMinBiasWideTrigBit( trigs_enabled );
0710
0711 if ( mbdbest == std::numeric_limits<uint64_t>::max() )
0712 {
0713 std::cout << "Oddball run without a proper MB trigger, using all triggers instead" << std::endl;
0714 trigmask = std::numeric_limits<uint64_t>::max();
0715 std::cout << std::hex << "trigmask " << trigmask << std::dec << std::endl;
0716 }
0717 else
0718 {
0719 trigmask = orig_trigmask;
0720 }
0721
0722 return 0;
0723 }
0724
0725 int BbcMon::GetFillNumber()
0726 {
0727 TString retval = gSystem->GetFromPipe( "/home/phnxrc/mbd/chiu/mbd_operations/httpRequestDemo.py -g ringSpec.blue fillNumberM | awk 'NR==1 {print $3}'" );
0728 if ( retval.IsDec() )
0729 {
0730 int fill = retval.Atoi();
0731 return fill;
0732 }
0733
0734 std::cerr << PHWHERE << "GetFromPipe() failed with retval " << retval << std::endl;
0735 return 0;
0736 }
0737
0738 uint64_t BbcMon::GetMinBiasTrigBit(uint64_t trigs_enabled)
0739 {
0740
0741 std::vector<int> widebits = {
0742 TriggerEnum::MBD_NS2_ZVRTX10,
0743 TriggerEnum::MBD_NS1_ZVRTX10,
0744 TriggerEnum::MBD_NS2_ZVRTX30,
0745 TriggerEnum::MBD_NS1,
0746 TriggerEnum::MBD_NS2,
0747 TriggerEnum::MBD_NS2_ZVRTX150,
0748 };
0749
0750 int best_scaledown = 999999999;
0751 int best_trig = -1;
0752 for ( int itrig : widebits )
0753 {
0754 int scaledown = bbc_prescale_hist->GetBinContent( itrig + 1 );
0755 std::cout << "BEST_TRIG " << itrig << "\t" << scaledown << std::endl;
0756 if ( scaledown>=0 && scaledown<best_scaledown )
0757 {
0758 best_scaledown = scaledown;
0759 best_trig = itrig;
0760 }
0761 }
0762
0763 if ( best_trig>=0 )
0764 {
0765 std::cout << "BEST MBDTRIG IS " << best_trig << std::endl;
0766 return ( 0x1UL << best_trig );
0767 }
0768
0769
0770 if ( (zdcns&trigs_enabled) == zdcns )
0771 {
0772 return zdcns;
0773 }
0774
0775
0776 return std::numeric_limits<uint64_t>::max();
0777 }
0778
0779 uint64_t BbcMon::GetMinBiasWideTrigBit(uint64_t trigs_enabled)
0780 {
0781
0782 std::vector<int> widebits = {
0783 TriggerEnum::MBD_NS1,
0784 TriggerEnum::MBD_NS2,
0785 TriggerEnum::MBD_NS2_ZVRTX150
0786 };
0787
0788 int best_scaledown = 99999999;
0789 int best_trig = -1;
0790 for ( int itrig : widebits )
0791 {
0792 int scaledown = bbc_prescale_hist->GetBinContent( itrig + 1 );
0793 if ( scaledown>=0 && scaledown<best_scaledown )
0794 {
0795 best_scaledown = scaledown;
0796 best_trig = itrig;
0797 }
0798 }
0799
0800 if ( best_trig>=0 )
0801 {
0802 std::cout << "BEST WIDE MBDTRIG IS " << best_trig << std::endl;
0803 return ( 0x1UL << best_trig );
0804 }
0805
0806
0807 if ( (zdcns&trigs_enabled) == zdcns )
0808 {
0809 std::cout << "BEST WIDE MBDTRIG IS ZDCNS" << std::endl;
0810 return zdcns;
0811 }
0812
0813
0814 return std::numeric_limits<uint64_t>::max();
0815 }
0816
0817 int BbcMon::UpdateSendFlag(const int flag)
0818 {
0819 sendflag = flag;
0820 std::ofstream sendflagfile( sendflagfname );
0821 if ( sendflagfile.is_open() )
0822 {
0823 sendflagfile << sendflag << std::endl;
0824 }
0825 else
0826 {
0827 std::cout << "unable to open file " << sendflagfname << std::endl;
0828 return 0;
0829 }
0830 sendflagfile.close();
0831 return 1;
0832 }
0833
0834 int BbcMon::GetSendFlag()
0835 {
0836 std::ifstream sendflagfile( sendflagfname );
0837 if ( sendflagfile.is_open() )
0838 {
0839 sendflagfile >> sendflag;
0840 }
0841 else
0842 {
0843 std::cout << "unable to open file " << sendflagfname << std::endl;
0844 sendflag = 0;
0845 }
0846 sendflagfile.close();
0847
0848 return sendflag;
0849 }
0850
0851 int BbcMon::UpdateZResetFlag(const int flag)
0852 {
0853 zresetflag = flag;
0854 std::ofstream zresetflagfile( zresetflagfname );
0855 if ( zresetflagfile.is_open() )
0856 {
0857 zresetflagfile << zresetflag << std::endl;
0858 }
0859 else
0860 {
0861 std::cout << "unable to open file " << zresetflagfname << std::endl;
0862 return 0;
0863 }
0864 zresetflagfile.close();
0865 return 1;
0866 }
0867
0868 int BbcMon::GetZResetFlag()
0869 {
0870 std::ifstream zresetflagfile( zresetflagfname );
0871 if ( zresetflagfile.is_open() )
0872 {
0873 zresetflagfile >> zresetflag;
0874 }
0875 else
0876 {
0877 std::cout << "unable to open file " << zresetflagfname << std::endl;
0878 zresetflag = 0;
0879 }
0880 zresetflagfile.close();
0881
0882 return zresetflag;
0883 }
0884
0885 int BbcMon::UpdateGL1BadFlag(const int flag)
0886 {
0887 gl1badflag = flag;
0888 std::ofstream gl1badflagfile( gl1badflagfname );
0889 if ( gl1badflagfile.is_open() )
0890 {
0891 gl1badflagfile << gl1badflag << std::endl;
0892 }
0893 else
0894 {
0895 std::cout << "unable to open file " << gl1badflagfname << std::endl;
0896 return 0;
0897 }
0898 gl1badflagfile.close();
0899 std::cout << "YYY setting gl1bad " << gl1badflag << std::endl;
0900 return 1;
0901 }
0902
0903 int BbcMon::GetGL1BadFlag()
0904 {
0905 std::ifstream gl1badflagfile( gl1badflagfname );
0906 if ( gl1badflagfile.is_open() )
0907 {
0908 gl1badflagfile >> gl1badflag;
0909 }
0910 else
0911 {
0912 std::cout << "unable to open file " << gl1badflagfname << std::endl;
0913 gl1badflag = 0;
0914 }
0915 gl1badflagfile.close();
0916
0917
0918 return gl1badflag;
0919 }
0920
0921 int BbcMon::EndRun(const int )
0922 {
0923
0924
0925 return 0;
0926 }
0927
0928 int BbcMon::process_event(Event *evt)
0929 {
0930
0931
0932
0933
0934
0935
0936
0937
0938
0939
0940
0941
0942
0943
0944
0945 if (evt->getEvtType() != DATAEVENT)
0946 {
0947 return 0;
0948 }
0949
0950 evtcnt++;
0951 bbc_nevent_counter->Fill(0);
0952
0953 [[maybe_unused]] OnlMonServer *se = OnlMonServer::instance();
0954
0955 Packet *p[2];
0956 p[0] = evt->getPacket(1001);
0957 p[1] = evt->getPacket(1002);
0958
0959
0960 if (!p[0] || !p[1])
0961 {
0962 std::ostringstream msg;
0963 msg << "MBD packet not found";
0964 se->send_message(this, MSG_SOURCE_BBC, MSG_SEV_WARNING, msg.str(), 1);
0965 msg.str("");
0966 bbc_nevent_counter->Fill(3);
0967
0968 delete p[0];
0969 delete p[1];
0970
0971 return 0;
0972 }
0973
0974
0975 if ((p[0]->iValue(0, "EVENCHECKSUMOK") == 0) || (p[0]->iValue(0, "ODDCHECKSUMOK") == 0) ||
0976 (p[1]->iValue(0, "EVENCHECKSUMOK") == 0) || (p[1]->iValue(0, "ODDCHECKSUMOK") == 0))
0977 {
0978 std::ostringstream msg;
0979 msg << "MBD packets have bad checksum(s)";
0980 se->send_message(this, MSG_SOURCE_BBC, MSG_SEV_WARNING, msg.str(), 1);
0981 msg.str("");
0982 bbc_nevent_counter->Fill(4);
0983
0984 delete p[0];
0985 delete p[1];
0986
0987 return 0;
0988 }
0989
0990 delete p[0];
0991 delete p[1];
0992
0993 int f_evt = evt->getEvtSequence();
0994 if ( Verbosity() && f_evt%1000 == 0 )
0995 {
0996 std::cout << "mbd evt " << f_evt << "\t" << useGL1 << std::endl;
0997 }
0998
0999 if ( f_evt < skipto )
1000 {
1001 if ( (f_evt%10000)==0 )
1002 {
1003 std::cout << "skipping " << f_evt << std::endl;
1004 }
1005 return 0;
1006 }
1007
1008 if ( (f_evt%1000)==0 )
1009 {
1010 GetGL1BadFlag();
1011 }
1012
1013
1014 int zreset = GetZResetFlag();
1015 if ( zreset == 1 )
1016 {
1017 bbc_zvertex->Reset();
1018 bbc_zvertex_alltrigger->Reset();
1019 bbc_zvertex_ns->Reset();
1020 bbc_zvertex_10->Reset();
1021 bbc_zvertex_30->Reset();
1022 bbc_zvertex_60->Reset();
1023 bbc_zvertex_ns_chk->Reset();
1024 bbc_zvertex_10_chk->Reset();
1025 bbc_zvertex_30_chk->Reset();
1026 bbc_zvertex_60_chk->Reset();
1027 bbc_zvertex_zdcns->Reset();
1028 bbc_zvertex_emcal->Reset();
1029 bbc_zvertex_hcal->Reset();
1030 bbc_zvertex_emcalmbd->Reset();
1031 bbc_zvertex_hcalmbd->Reset();
1032
1033 UpdateZResetFlag( 0 );
1034 }
1035
1036
1037 if ( useGL1 )
1038 {
1039
1040 triggervec = 0UL;
1041 triginput = 0UL;
1042 trigraw = 0UL;
1043 triglive = 0UL;
1044 trigscaled = 0UL;
1045 Event *gl1Event = erc->getEvent( f_evt );
1046
1047
1048 if (gl1Event)
1049 {
1050 se->IncrementGl1FoundCounter();
1051
1052 Packet* p_gl1 = gl1Event->getPacket(14001);
1053 if (p_gl1)
1054 {
1055
1056 triggervec = static_cast<uint64_t>( p_gl1->lValue(0,"TriggerVector") );
1057 triginput = static_cast<uint64_t>( p_gl1->lValue(0,"TriggerInput") );
1058
1059
1060 trigraw = static_cast<uint64_t>( p_gl1->lValue(0,"TriggerInput") );
1061 triglive = static_cast<uint64_t>( p_gl1->lValue(0,"LiveVector") );
1062 trigscaled = static_cast<uint64_t>( p_gl1->lValue(0,"ScaledVector") );
1063
1064 triggervec = trigscaled;
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085 for (int itrig = 0; itrig < 64; itrig++ )
1086 {
1087 uint64_t trigbit = 0x1UL << itrig;
1088 if ( (triggervec&trigbit) != 0 )
1089 {
1090 bbc_trigs->Fill( itrig );
1091 }
1092 }
1093
1094 delete p_gl1;
1095 }
1096 delete gl1Event;
1097 }
1098 }
1099 else
1100 {
1101
1102 triggervec = std::numeric_limits<uint64_t>::max();
1103 }
1104
1105
1106 bevt->Clear();
1107 bevt->SetRawData(evt,m_mbdpmts);
1108
1109 if (bevt->calib_is_done() == 0)
1110 {
1111 return 0;
1112 }
1113
1114
1115
1116 if ( ((triggervec&trigmask) == 0UL) && (gl1badflag==0) )
1117 {
1118 if ( f_evt%1000 == 0 )
1119 {
1120 std::cout << "skipping " << f_evt << "\t" << std::hex << triggervec
1121 << "\t" << trigmask << std::dec << std::endl;
1122 }
1123 return 0;
1124 }
1125
1126 bevt->Calculate(m_mbdpmts, m_mbdout);
1127
1128 bbc_nevent_counter->Fill(1);
1129 double zvtx = m_mbdout->get_zvtx();
1130 double t0 = m_mbdout->get_t0();
1131 double qsum[2] = {0, 0};
1132 qsum[0] = m_mbdout->get_q(0);
1133 qsum[1] = m_mbdout->get_q(1);
1134 int south_nhits = m_mbdout->get_npmt(0);
1135 int north_nhits = m_mbdout->get_npmt(1);
1136
1137 static int counter = 0;
1138 evtcnt++;
1139 if (counter < 10)
1140 {
1141 std::cout << "zt\t" << f_evt << "\t" << zvtx << "\t" << t0 << std::endl;
1142 counter++;
1143 }
1144
1145 for ( int i = 0; i < TriggerEnum::NUM_MBD_TRIGGERS; i++ ){
1146 if ( (triggervec&TriggerEnum::MBTriggers[i]) != 0 )
1147 {
1148 bbc_last_update_ticker[i]++;
1149 if ( bbc_last_update_ticker[i] > zvtx_autoupdate_ticker ){
1150 for ( int ix = 0; ix < BbcMonDefs::zvtnbin; ix++ )
1151 {
1152 bbc_zvertex_autoupdate[i]->SetBinContent( ix+1, 0 );
1153 }
1154 bbc_last_update_ticker[i] = 0;
1155 }
1156 bbc_zvertex_autoupdate[i]->Fill(zvtx);
1157 }
1158 }
1159
1160
1161
1162 if ( (triggervec&mbdbest)!=0 )
1163 {
1164 bbc_nevent_counter->Fill(5);
1165
1166 bbc_zvertex->Fill(zvtx);
1167 bbc_zvertex_prime_short->Fill(zvtx);
1168 bbc_south_nhit->Fill( south_nhits );
1169 bbc_north_nhit->Fill( north_nhits );
1170 }
1171 if ( (triggervec&mbdwidebest)!=0 )
1172 {
1173 bbc_zvertex_ns->Fill(zvtx);
1174 bbc_zvertex_short->Fill(zvtx);
1175 bbc_zvertex_ns_chk->Fill(zvtx);
1176
1177 if ( triglive&mbdnsvtx10 )
1178 {
1179 bbc_zvertex_10_chk->Fill(zvtx);
1180 }
1181 if ( triglive&mbdnsvtx30 )
1182 {
1183 bbc_zvertex_30_chk->Fill(zvtx);
1184 }
1185 if ( triglive&mbdnsvtx150 )
1186 {
1187 bbc_zvertex_60_chk->Fill(zvtx);
1188 }
1189 }
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215 if ( triggervec&mbdnsvtx10 )
1216 {
1217 bbc_zvertex_10->Fill(zvtx);
1218 }
1219 if ( triggervec&mbdnsvtx30 )
1220 {
1221 bbc_zvertex_30->Fill(zvtx);
1222 }
1223 if ( triggervec&mbdnsvtx150 )
1224 {
1225 bbc_zvertex_60->Fill(zvtx);
1226 }
1227 if ( triggervec&zdcns )
1228 {
1229 bbc_zvertex_zdcns->Fill(zvtx);
1230 }
1231 if ( triggervec&emcal )
1232 {
1233 bbc_zvertex_emcal->Fill(zvtx);
1234 bbc_nhit_emcal[0]->Fill( south_nhits );
1235 bbc_nhit_emcal[1]->Fill( north_nhits );
1236 }
1237 if ( triggervec&hcal )
1238 {
1239 bbc_zvertex_hcal->Fill(zvtx);
1240 bbc_nhit_hcal[0]->Fill( south_nhits );
1241 bbc_nhit_hcal[1]->Fill( north_nhits );
1242 }
1243 if ( triggervec&emcalmbd )
1244 {
1245 bbc_zvertex_emcalmbd->Fill(zvtx);
1246 bbc_nhit_emcalmbd[0]->Fill( south_nhits );
1247 bbc_nhit_emcalmbd[1]->Fill( north_nhits );
1248 }
1249 if ( triggervec&hcalmbd )
1250 {
1251 bbc_zvertex_hcalmbd->Fill(zvtx);
1252 bbc_nhit_hcalmbd[0]->Fill( south_nhits );
1253 bbc_nhit_hcalmbd[1]->Fill( north_nhits );
1254 }
1255
1256
1257 if ( gl1badflag )
1258 {
1259 bbc_zvertex_ns->Fill(zvtx);
1260 bbc_zvertex_10->Fill(zvtx);
1261 }
1262
1263 bbc_zvertex_alltrigger->Fill(zvtx);
1264
1265
1266 if ( ((triggervec&mbdtrig) == 0) && ((triggervec&zdcns)==0) && (gl1badflag==0) )
1267 {
1268 return 0;
1269 }
1270
1271 bbc_tzero_zvtx->Fill(zvtx, t0);
1272
1273
1274 if ( prev_send_time == 0 )
1275 {
1276 prev_send_time = time(0);
1277 }
1278 time_t timediff = time(0) - prev_send_time;
1279
1280
1281
1282 if ( ((timediff > 5) && (bbc_zvertex_short->Integral() >= 1000)) || (timediff > 60) )
1283 {
1284 f_zvtx->SetRange(-75., 75.);
1285 f_zvtx->SetParameters(250, 0., 10);
1286 {
1287 bbc_zvertex_short->Fit(f_zvtx, "RNQL");
1288
1289
1290 Double_t mean = f_zvtx->GetParameter(1);
1291 Double_t rms = f_zvtx->GetParameter(2);
1292
1293 Double_t meanerr = f_zvtx->GetParError(1);
1294 Double_t rmserr = f_zvtx->GetParError(2);
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305 std::ostringstream msg;
1306 msg << "MBD zvertex mean/width: " << mean << " " << rms << " " << meanerr << " " << rmserr;
1307 se->send_message(this, MSG_SOURCE_BBC, MSG_SEV_INFORMATIONAL, msg.str(), 1);
1308 std::cout << "MBD zvtx mean/width: " << mean << " " << rms << " " << meanerr << " " << rmserr << std::endl;
1309
1310 if ( useGL1==1 && GetSendFlag() == 1 )
1311 {
1312 TString cmd = "/home/phnxrc/mbd/chiu/mbd_operations/httpRequestDemo.py -s sphenix.detector zMeanM "; cmd += mean;
1313 cmd += "; /home/phnxrc/mbd/chiu/mbd_operations/httpRequestDemo.py -s sphenix.detector zRmsM "; cmd += rms;
1314 gSystem->Exec( cmd );
1315 }
1316
1317
1318 std::time_t currtime = time(0) - tstart;
1319 std::cout << "currtime " << static_cast<Float_t>(currtime) << "\t" << time(0) << "\t" << tstart << std::endl;
1320 int n = bbc_runvtx->GetEntries();
1321 bbc_runvtx->SetBinContent( n+1, mean );
1322 bbc_runvtxerr->SetBinContent( n+1, meanerr );
1323 bbc_runvtxtime->SetBinContent( n+1, static_cast<Float_t>(currtime) );
1324 }
1325 bbc_zvertex_short->Reset();
1326 prev_send_time = time(0);
1327 }
1328
1329 for (int ipmt = 0; ipmt < 128; ipmt++)
1330 {
1331 float q = m_mbdpmts->get_pmt(ipmt)->get_q();
1332 bbc_adc->Fill(ipmt, q);
1333
1334
1335 if (q > 0.5)
1336 {
1337 float tt = m_mbdpmts->get_pmt(ipmt)->get_time();
1338 if (ipmt < 64)
1339 {
1340 bbc_south_hittime->Fill(tt);
1341 }
1342 else
1343 {
1344 bbc_north_hittime->Fill(tt);
1345 }
1346
1347
1348 }
1349
1350 }
1351
1352
1353 bbc_south_chargesum->Fill(qsum[0]);
1354 bbc_north_chargesum->Fill(qsum[1]);
1355
1356
1357 for (int ipmt = 0; ipmt < 128; ipmt++)
1358 {
1359 int tch = (ipmt / 8) * 16 + ipmt % 8;
1360 MbdSig *bbcsig = bevt->GetSig(tch);
1361 TGraphErrors *gwave = bbcsig->GetGraph();
1362 Int_t n = gwave->GetN();
1363 Double_t *x = gwave->GetX();
1364 Double_t *y = gwave->GetY();
1365
1366 for (int jsamp = 0; jsamp < n; jsamp++)
1367 {
1368 if ( y[jsamp]>20 )
1369 {
1370 for (int isamp = 0; isamp < n; isamp++)
1371 {
1372 bbc_time_wave->Fill(x[isamp], ipmt, y[isamp]);
1373 }
1374 break;
1375 }
1376 }
1377
1378 int qch = tch + 8;
1379 bbcsig = bevt->GetSig(qch);
1380 gwave = bbcsig->GetGraph();
1381 n = gwave->GetN();
1382 x = gwave->GetX();
1383 y = gwave->GetY();
1384 for (int isamp = 0; isamp < n; isamp++)
1385 {
1386 bbc_charge_wave->Fill(x[isamp], ipmt, y[isamp]);
1387 }
1388
1389
1390 float q = m_mbdpmts->get_pmt(ipmt)->get_q();
1391
1392 if ( q>0. )
1393 {
1394 float xcent = _mbdgeom->get_x(ipmt);
1395 float ycent = _mbdgeom->get_y(ipmt);
1396 int arm = _mbdgeom->get_arm(ipmt);
1397
1398 if (arm == 0)
1399 {
1400 bbc_south_hitmap->Fill(xcent, ycent, q);
1401 }
1402 else if (arm == 1)
1403 {
1404 bbc_north_hitmap->Fill(xcent, ycent, q);
1405 }
1406 }
1407 }
1408
1409 return 0;
1410 }
1411
1412 int BbcMon::Reset()
1413 {
1414
1415 evtcnt = 0;
1416
1417
1418 bbc_south_nhit->Reset();
1419 bbc_north_nhit->Reset();
1420 for (int iarm=0; iarm<2; iarm++)
1421 {
1422 bbc_nhit_emcal[iarm]->Reset();
1423 bbc_nhit_hcal[iarm]->Reset();
1424 bbc_nhit_emcalmbd[iarm]->Reset();
1425 bbc_nhit_hcalmbd[iarm]->Reset();
1426 }
1427 bbc_adc->Reset();
1428 bbc_tdc->Reset();
1429 bbc_tdc_overflow->Reset();
1430 bbc_tdc_armhittime->Reset();
1431 bbc_nevent_counter->Reset();
1432 bbc_zvertex->Reset();
1433 bbc_zvertex_short->Reset();
1434 bbc_zvertex_prime_short->Reset();
1435 bbc_zvertex_ns->Reset();
1436 bbc_zvertex_10->Reset();
1437 bbc_zvertex_30->Reset();
1438 bbc_zvertex_60->Reset();
1439 bbc_zvertex_ns_chk->Reset();
1440 bbc_zvertex_10_chk->Reset();
1441 bbc_zvertex_30_chk->Reset();
1442 bbc_zvertex_60_chk->Reset();
1443 bbc_zvertex_zdcns->Reset();
1444 bbc_zvertex_emcal->Reset();
1445 bbc_zvertex_hcal->Reset();
1446 bbc_zvertex_emcalmbd->Reset();
1447 bbc_zvertex_hcalmbd->Reset();
1448 bbc_tzero_zvtx->Reset();
1449 bbc_avr_hittime->Reset();
1450 bbc_south_hittime->Reset();
1451 bbc_north_hittime->Reset();
1452 bbc_south_chargesum->Reset();
1453 bbc_north_chargesum->Reset();
1454 bbc_prescale_hist->Reset();
1455 bbc_time_wave->Reset();
1456 bbc_charge_wave->Reset();
1457 bbc_runvtx->Reset();
1458 bbc_runvtxerr->Reset();
1459 bbc_runvtxtime->Reset();
1460 for ( int i = 0; i < TriggerEnum::NUM_MBD_TRIGGERS; i++ ){
1461 bbc_zvertex_autoupdate[i]->Reset();
1462 bbc_last_update_ticker[i] = 0;
1463 }
1464
1465 return 0;
1466 }
1467
1468 int BbcMon::DBVarInit()
1469 {
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485 return 0;
1486 }