File indexing completed on 2025-08-05 08:20:26
0001
0002
0003
0004
0005
0006 #include "LL1Mon.h"
0007 #include "ll1setup.cc"
0008
0009 #include <onlmon/OnlMon.h> // for OnlMon
0010 #include <onlmon/OnlMonDB.h>
0011 #include <onlmon/OnlMonServer.h>
0012
0013 #include <Event/msg_profile.h>
0014
0015 #include <TH1.h>
0016 #include <TH2.h>
0017 #include <TRandom.h>
0018
0019 #include <cmath>
0020 #include <cstdio> // for printf
0021 #include <fstream>
0022 #include <iostream>
0023 #include <sstream>
0024 #include <string> // for allocator, string, char_traits
0025
0026
0027 enum
0028 {
0029 TRGMESSAGE = 1,
0030 FILLMESSAGE = 2
0031 };
0032
0033 LL1Mon::LL1Mon(const std::string &name)
0034 : OnlMon(name)
0035 {
0036
0037
0038 return;
0039 }
0040
0041 LL1Mon::~LL1Mon()
0042 {
0043
0044 return;
0045 }
0046
0047 int LL1Mon::Init()
0048 {
0049 gRandom->SetSeed(rand());
0050
0051 const char *LL1calib = getenv("LL1CALIB");
0052 if (!LL1calib)
0053 {
0054 std::cout << "LL1CALIB environment variable not set" << std::endl;
0055 exit(1);
0056 }
0057 std::string fullfile = std::string(LL1calib) + "/" + "LL1MonData.dat";
0058 std::ifstream calib(fullfile);
0059 calib.close();
0060
0061
0062 printf("doing the Init\n");
0063 h_line_up = new TH2D("h_line_up",";Sample;Channel", 20, -0.5, 19.5, 60, -0.5, 59.5);
0064 h_nhit_corr = new TH2D("h_nhit_corr",";N_{hit}^{north};N_{hit}^{south}",nhitbins, binstart, binend, nhitbins, binstart, binend);
0065
0066
0067 h_nhit_n1 = new TH1D("h_nhit_n1",";N_{hit}^{N1};counts", nhitbins/2 + 1, binstart,binend2);
0068 h_nhit_n2 = new TH1D("h_nhit_n2",";N_{hit}^{N2};counts", nhitbins/2 + 1, binstart,binend2);
0069 h_nhit_s1 = new TH1D("h_nhit_s1",";N_{hit}^{S1};counts", nhitbins/2 + 1, binstart,binend2);
0070 h_nhit_s2 = new TH1D("h_nhit_s2",";N_{hit}^{S2};counts", nhitbins/2 + 1, binstart,binend2);
0071
0072
0073
0074 h_hit_format = new TH1F("h_hit_format","", 21,189.5, 210.5 );
0075 for (int i = 0; i < 16; i++)
0076 {
0077 std::string histname= "h_2x2_sum_emcal_" + std::to_string(i);
0078 std::string title = "EMCAL" + std::to_string(i) + ";2x2 sum; Occurrences";
0079 h_2x2_sum_per_emcal_board[i] = new TH1D(histname.c_str(), title.c_str(), 257, -0.5, 256.5);
0080 }
0081 h_8x8_sum_emcal = new TH2D("h_8x8_sum_emcal", ";#eta <8x8> sum; #phi <8x8> sum;", nbins_emcal_eta_8x8, -0.5, nbins_emcal_eta_8x8 - 0.5, nbins_emcal_phi_8x8, -0.5,nbins_emcal_phi_8x8 - 0.5);
0082 for (int i = 0; i < 4; i++)
0083 {
0084 h_8x8_sum_emcal_above_threshold[i] = new TH2D(Form("h_8x8_sum_emcal_above_threshold_%d", i), ";#eta <8x8> sum; #phi <8x8> sum;", nbins_emcal_eta_8x8, -0.5, nbins_emcal_eta_8x8 - 0.5, nbins_emcal_phi_8x8, -0.5,nbins_emcal_phi_8x8 - 0.5);
0085 }
0086
0087 h_sample_diff_emcal = new TH2D("h_sample_diff_emcal",";Relative Beam Crossing; EMCAL Trigger Card", 5, -0.5, 4.5, 16, -0.5, 15.5);
0088
0089
0090
0091
0092 h_jet_input = new TH2D("h_jet_input", ";#eta Jet Input; #phi Jet Input;", nbins_jet_input_eta, -0.5, nbins_jet_input_eta - 0.5, nbins_jet_input_phi, -0.5,nbins_jet_input_phi - 0.5);
0093 h_jet_output = new TH2D("h_jet_output", ";#eta Jet Output; #phi Jet Output;", nbins_jet_output_eta, -0.5, nbins_jet_output_eta - 0.5, nbins_jet_output_phi, -0.5,nbins_jet_output_phi - 0.5);
0094 for (int i = 0; i < 4; i++)
0095 {
0096 h_jet_output_above_threshold[i] = new TH2D(Form("h_jet_output_above_threshold_%d", i), ";#eta <8x8> sum; #phi <8x8> sum;", nbins_jet_output_eta, -0.5, nbins_jet_output_eta - 0.5, nbins_jet_output_phi, -0.5, nbins_jet_output_phi - 0.5);
0097 }
0098
0099 h_sample_diff_jet_input = new TH2D("h_sample_diff_jet_input",";Relative Beam Crossing; Jet Input Fiber", 5, -0.5, 4.5, 16, -0.5, 15.5);
0100
0101 OnlMonServer *se = OnlMonServer::instance();
0102
0103 se->registerHisto(this, h_line_up);
0104 se->registerHisto(this, h_nhit_corr);
0105 se->registerHisto(this, h_nhit_n1);
0106 se->registerHisto(this, h_nhit_n2);
0107 se->registerHisto(this, h_nhit_s1);
0108 se->registerHisto(this, h_nhit_s2);
0109
0110 se->registerHisto(this, h_hit_format);
0111 se->registerHisto(this, h_jet_input);
0112 se->registerHisto(this, h_jet_output);
0113 se->registerHisto(this, h_8x8_sum_emcal);
0114 se->registerHisto(this, h_sample_diff_emcal);
0115 se->registerHisto(this, h_sample_diff_jet_input);
0116
0117 for (int i = 0; i < 16; i++)
0118 {
0119 se->registerHisto(this, h_2x2_sum_per_emcal_board[i]);
0120 }
0121 for (int i = 0; i < 4; i++)
0122 {
0123 se->registerHisto(this, h_8x8_sum_emcal_above_threshold[i]);
0124 se->registerHisto(this, h_jet_output_above_threshold[i]);
0125 }
0126
0127 Reset();
0128
0129 return 0;
0130 }
0131
0132 int LL1Mon::BeginRun(const int )
0133 {
0134
0135
0136 return 0;
0137 }
0138
0139 int LL1Mon::process_event(Event * evt )
0140 {
0141 evtcnt++;
0142
0143 LL1HEADER *ll1h = new LL1HEADER();
0144
0145 ll1setup(evt,ll1h);
0146
0147 static int counter = 0;
0148 if (counter == 0)
0149 {
0150 counter++;
0151
0152 h_hit_format->Fill(ll1h->hit_format_jet);
0153 }
0154
0155 Packet *pthresh = evt->getPacket(13901);
0156 if (pthresh)
0157 {
0158 for (int ithreshold = 0; ithreshold < nthresholds; ithreshold++)
0159 {
0160 std::cout << " threshold "<<ithreshold << " : " << pthresh->iValue(ithreshold) << std::endl;
0161 if (ithreshold < 4)
0162 {
0163 ll1h->jet_threshold[ithreshold] = pthresh->iValue(ithreshold);
0164 }
0165 else if (ithreshold < 8)
0166 {
0167 ll1h->photon_threshold[ithreshold - 4] = pthresh->iValue(ithreshold);
0168 }
0169 else
0170 {
0171 ll1h->mbd_threshold[ithreshold - 8] = pthresh->iValue(ithreshold);
0172 }
0173 }
0174 delete pthresh;
0175 }
0176 else
0177 {
0178 for (int ithreshold = 0; ithreshold < nthresholds; ithreshold++)
0179 {
0180 if (ithreshold < 4)
0181 {
0182 ll1h->jet_threshold[ithreshold] = ithreshold + 1;
0183 }
0184 else if (ithreshold < 8)
0185 {
0186 ll1h->photon_threshold[ithreshold - 4] = (ithreshold - 4) + 1;
0187 }
0188 else
0189 {
0190 ll1h->mbd_threshold[ithreshold - 8] = 2;
0191 }
0192 }
0193 }
0194
0195 int id=3;
0196
0197 if(ll1h->nhit_n[id] >= ll1h->mbd_threshold[0] && ll1h->nhit_s[0]>=ll1h->mbd_threshold[1]){
0198 id=3;
0199 }
0200 else if (ll1h->nhit_n[ll1h->idxhitn] >= ll1h->mbd_threshold[0] && ll1h->nhit_s[ll1h->idxhitn] >= ll1h->mbd_threshold[0]){
0201 id = ll1h->idxhitn;
0202 }
0203 else if (ll1h->nhit_n[ll1h->idxhits] >= ll1h->mbd_threshold[0] && ll1h->nhit_s[ll1h->idxhits] >= ll1h->mbd_threshold[0]){
0204 id = ll1h->idxhits;
0205 }
0206
0207 h_nhit_corr->Fill(ll1h->nhit_n[id], ll1h->nhit_s[id]);
0208 h_nhit_n1->Fill(ll1h->nhit_n1[id]);
0209 h_nhit_n2->Fill(ll1h->nhit_n2[id]);
0210 h_nhit_s1->Fill(ll1h->nhit_s1[id]);
0211 h_nhit_s2->Fill(ll1h->nhit_s2[id]);
0212
0213 for (int is = 0; is < nSamples; is++)
0214 {
0215 for (int ic = 0; ic < nChannels; ic++)
0216 {
0217 h_line_up->Fill(is, 60 - ic, ll1h->channel[ic][is]);
0218 }
0219 for (int ic = 0; ic < 8; ic++)
0220 {
0221 h_line_up->Fill(is, 8 - ic, ll1h->triggerwords[ic][is]);
0222 }
0223 }
0224
0225
0226
0227
0228 for (int iemcal = 0; iemcal < 16; iemcal++)
0229 {
0230 h_sample_diff_emcal->Fill(ll1h->emcal_sample[iemcal], iemcal);
0231 h_sample_diff_jet_input->Fill(ll1h->jet_sample[iemcal], iemcal);
0232
0233 for (int i = 0; i < 8 ; i++)
0234 {
0235 int ii = i/4;
0236 int imod = i%4;
0237 for (int j = 0; j < 48; j++)
0238 {
0239 int jj = j/4;
0240 int jmod = j%4;
0241 if (!jmod && !imod)
0242 {
0243 h_8x8_sum_emcal->Fill(jj, iemcal * 2 + ii, ll1h->emcal_8x8_map[jj][iemcal*2 + ii]);
0244
0245 h_jet_input->Fill(jj, iemcal*2 + ii, ll1h->jet_input[jj][iemcal*2 + ii]);
0246 if (jj < 9)
0247 {
0248 h_jet_output->Fill(jj, iemcal*2 + ii, ll1h->jet_output[jj][iemcal*2 + ii]);
0249 }
0250 for (int ith = 0; ith < 4; ith++)
0251 {
0252 if (ll1h->emcal_8x8_map[jj][iemcal*2 + ii] > ll1h->photon_threshold[ith])
0253 {
0254 h_8x8_sum_emcal_above_threshold[ith]->Fill(jj, iemcal*2 + ii);
0255 }
0256 if (jj < 9 && ll1h->jet_output[jj][iemcal*2 + ii] > ll1h->jet_threshold[ith])
0257 {
0258 h_jet_output_above_threshold[ith]->Fill(jj, iemcal*2 + ii);
0259 }
0260
0261 }
0262 }
0263 h_2x2_sum_per_emcal_board[iemcal]->Fill(ll1h->emcal_2x2_map[j][iemcal*8 + i]);
0264 }
0265 }
0266 }
0267
0268 delete ll1h;
0269
0270 return 0;
0271 }
0272
0273 int LL1Mon::Reset()
0274 {
0275
0276 evtcnt = 0;
0277 idummy = 0;
0278 return 0;
0279 }
0280