Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2026-04-04 08:16:14

0001 // use #include "" only for your local include and put
0002 // those in the first line(s) before any #include <>
0003 // otherwise you are asking for weird behavior
0004 // (more info - check the difference in include path search when using "" versus <>)
0005 
0006 #include "TpcMon.h"
0007 
0008 #include <onlmon/OnlMon.h>  // for OnlMon
0009 #include <onlmon/OnlMonDB.h>
0010 #include <onlmon/OnlMonServer.h>
0011 
0012 #include <Event/Event.h>
0013 #include <Event/msg_profile.h>
0014 #include <Event/oncsSubConstants.h>
0015 
0016 #include <tpc/TpcMap.h>
0017 
0018 #include <TH1.h>
0019 #include <TH2.h>
0020 #include <TLatex.h>
0021 #include <TMath.h>
0022 #include <TTree.h>
0023 
0024 #include <algorithm>
0025 #include <cmath>
0026 #include <cstdio>  // for printf
0027 #include <fstream>
0028 #include <iostream>
0029 #include <sstream>
0030 #include <string>  // for allocator, string, char_traits
0031 #include <vector>
0032 
0033 enum
0034 {
0035   TRGMESSAGE = 1,
0036   FILLMESSAGE = 2
0037 };
0038 
0039 TpcMon::TpcMon(const std::string &name)
0040   : OnlMon(name)
0041 {
0042   // leave ctor fairly empty, its hard to debug if code crashes already
0043   // during a new TpcMon()
0044 
0045   serverid = 0;  // default case - initializing in constructor
0046   // BCO initialization in TPCMon
0047   starting_BCO = -1;
0048   starting_BCO_DC = -1;
0049   rollover_value = 0;
0050   rollover_value_DC = 0x000000;
0051   current_BCOBIN = 0;
0052   // Evgeny Map
0053   M.setMapNames("AutoPad-R1-RevA.sch.ChannelMapping.csv", "AutoPad-R2-RevA-Pads.sch.ChannelMapping.csv", "AutoPad-R3-RevA.sch.ChannelMapping.csv");
0054   return;
0055 }
0056 
0057 int TpcMon::Init()
0058 {
0059   // read our calibrations from TpcMonData.dat
0060   const char *tpccalib = getenv("TPCCALIB");
0061   if (!tpccalib)
0062   {
0063     std::cout << "TPCCALIB environment variable not set" << std::endl;
0064     exit(1);
0065   }
0066   std::string fullfile = std::string(tpccalib) + "/" + "TpcMonData.dat";
0067   std::ifstream calib(fullfile);
0068   calib.close();
0069   // use printf for stuff which should go the screen but not into the message
0070   // system (all couts are redirected)
0071   printf("doing the Init\n");
0072   // TPC GEM Module Displays
0073   NorthSideADC = new TH2F("NorthSideADC", "ADC Counts North Side", N_thBins, -TMath::Pi() / 12., 23. * TMath::Pi() / 12., N_rBins, rBin_edges);
0074   SouthSideADC = new TH2F("SouthSideADC", "ADC Counts South Side", N_thBins, -TMath::Pi() / 12., 23. * TMath::Pi() / 12., N_rBins, rBin_edges);
0075   //
0076 
0077   // TPC "cluster" XY heat maps WEIGHTED
0078   // NorthSideADC_clusterXY_R1 = new TH2F("NorthSideADC_clusterXY_R1" , "ADC Peaks North Side", N_phi_binx_XY_R1, -TMath::Pi(), TMath::Pi(), N_rBins_XY, r_bins);
0079   NorthSideADC_clusterXY_R1 = new TH2F("NorthSideADC_clusterXY_R1", "(ADC-Pedestal) > 5#sigma North Side", 400, -800, 800, 400, -800, 800);
0080   NorthSideADC_clusterXY_R1->SetXTitle("X [mm]");
0081   NorthSideADC_clusterXY_R1->SetYTitle("Y [mm]");
0082 
0083   // NorthSideADC_clusterXY_R2 = new TH2F("NorthSideADC_clusterXY_R2" , "ADC Peaks North Side", N_phi_binx_XY_R2, -TMath::Pi(), TMath::Pi(), N_rBins_XY, r_bins);
0084   NorthSideADC_clusterXY_R2 = new TH2F("NorthSideADC_clusterXY_R2", "(ADC-Pedestal) > 5#sigma North Side", 400, -800, 800, 400, -800, 800);
0085   NorthSideADC_clusterXY_R2->SetXTitle("X [mm]");
0086   NorthSideADC_clusterXY_R2->SetYTitle("Y [mm]");
0087 
0088   // NorthSideADC_clusterXY_R3 = new TH2F("NorthSideADC_clusterXY_R3" , "ADC Peaks North Side", N_phi_binx_XY_R3, -TMath::Pi(), TMath::Pi(), N_rBins_XY, r_bins);
0089   NorthSideADC_clusterXY_R3 = new TH2F("NorthSideADC_clusterXY_R3", "(ADC-Pedestal) > 5#sigma North Side", 400, -800, 800, 400, -800, 800);
0090   NorthSideADC_clusterXY_R3->SetXTitle("X [mm]");
0091   NorthSideADC_clusterXY_R3->SetYTitle("Y [mm]");
0092 
0093   // SouthSideADC_clusterXY_R1 = new TH2F("SouthSideADC_clusterXY_R1" , "ADC Peaks South Side", N_phi_binx_XY_R1, -TMath::Pi(), TMath::Pi(), N_rBins_XY, r_bins);
0094   SouthSideADC_clusterXY_R1 = new TH2F("SouthSideADC_clusterXY_R1", "(ADC-Pedestal) > 5#sigma South Side", 400, -800, 800, 400, -800, 800);
0095   SouthSideADC_clusterXY_R1->SetXTitle("X [mm]");
0096   SouthSideADC_clusterXY_R1->SetYTitle("Y [mm]");
0097 
0098   // SouthSideADC_clusterXY_R2 = new TH2F("SouthSideADC_clusterXY_R2" , "ADC Peaks South Side", N_phi_binx_XY_R2, -TMath::Pi(), TMath::Pi(), N_rBins_XY, r_bins);
0099   SouthSideADC_clusterXY_R2 = new TH2F("SouthSideADC_clusterXY_R2", "(ADC-Pedestal) > 5#sigma South Side", 400, -800, 800, 400, -800, 800);
0100   SouthSideADC_clusterXY_R2->SetXTitle("X [mm]");
0101   SouthSideADC_clusterXY_R2->SetYTitle("Y [mm]");
0102 
0103   // SouthSideADC_clusterXY_R3 = new TH2F("SouthSideADC_clusterXY_R3" , "ADC Peaks South Side", N_phi_binx_XY_R3, -TMath::Pi(), TMath::Pi(), N_rBins_XY, r_bins);
0104   SouthSideADC_clusterXY_R3 = new TH2F("SouthSideADC_clusterXY_R3", "(ADC-Pedestal) > 5#sigma South Side", 400, -800, 800, 400, -800, 800);
0105   SouthSideADC_clusterXY_R3->SetXTitle("X [mm]");
0106   SouthSideADC_clusterXY_R3->SetYTitle("Y [mm]");
0107 
0108   //____________________________________________________________________//
0109 
0110   // TPC "cluster" XY heat maps DURING LASER TIME WEIGHTED
0111   //
0112   NorthSideADC_clusterXY_R1_LASER = new TH2F("NorthSideADC_clusterXY_R1_LASER", "(ADC-Pedestal) > 5#sigma North Side", 400, -800, 800, 400, -800, 800);
0113   NorthSideADC_clusterXY_R1_LASER->SetXTitle("X [mm]");
0114   NorthSideADC_clusterXY_R1_LASER->SetYTitle("Y [mm]");
0115 
0116   //
0117   NorthSideADC_clusterXY_R2_LASER = new TH2F("NorthSideADC_clusterXY_R2_LASER", "(ADC-Pedestal) > 5#sigma North Side", 400, -800, 800, 400, -800, 800);
0118   NorthSideADC_clusterXY_R2_LASER->SetXTitle("X [mm]");
0119   NorthSideADC_clusterXY_R2_LASER->SetYTitle("Y [mm]");
0120 
0121   //
0122   NorthSideADC_clusterXY_R3_LASER = new TH2F("NorthSideADC_clusterXY_R3_LASER", "(ADC-Pedestal) > 5#sigma North Side", 400, -800, 800, 400, -800, 800);
0123   NorthSideADC_clusterXY_R3_LASER->SetXTitle("X [mm]");
0124   NorthSideADC_clusterXY_R3_LASER->SetYTitle("Y [mm]");
0125 
0126   //
0127   SouthSideADC_clusterXY_R1_LASER = new TH2F("SouthSideADC_clusterXY_R1_LASER", "(ADC-Pedestal) > 5#sigma South Side", 400, -800, 800, 400, -800, 800);
0128   SouthSideADC_clusterXY_R1_LASER->SetXTitle("X [mm]");
0129   SouthSideADC_clusterXY_R1_LASER->SetYTitle("Y [mm]");
0130 
0131   //
0132   SouthSideADC_clusterXY_R2_LASER = new TH2F("SouthSideADC_clusterXY_R2_LASER", "(ADC-Pedestal) > 5#sigma South Side", 400, -800, 800, 400, -800, 800);
0133   SouthSideADC_clusterXY_R2_LASER->SetXTitle("X [mm]");
0134   SouthSideADC_clusterXY_R2_LASER->SetYTitle("Y [mm]");
0135 
0136   //
0137   SouthSideADC_clusterXY_R3_LASER = new TH2F("SouthSideADC_clusterXY_R3_LASER", "(ADC-Pedestal) > 5#sigma South Side", 400, -800, 800, 400, -800, 800);
0138   SouthSideADC_clusterXY_R3_LASER->SetXTitle("X [mm]");
0139   SouthSideADC_clusterXY_R3_LASER->SetYTitle("Y [mm]");
0140 
0141   //____________________________________________________________________//
0142 
0143   // TPC "cluster" XY heat maps UNWEIGHTED
0144   // NorthSideADC_clusterXY_R1 = new TH2F("NorthSideADC_clusterXY_R1" , "ADC Peaks North Side", N_phi_binx_XY_R1, -TMath::Pi(), TMath::Pi(), N_rBins_XY, r_bins);
0145   NorthSideADC_clusterXY_R1_unw = new TH2F("NorthSideADC_clusterXY_R1_unw", "(ADC-Pedestal) > 5#sigma North Side", 400, -800, 800, 400, -800, 800);
0146   NorthSideADC_clusterXY_R1_unw->SetXTitle("X [mm]");
0147   NorthSideADC_clusterXY_R1_unw->SetYTitle("Y [mm]");
0148 
0149   // NorthSideADC_clusterXY_R2 = new TH2F("NorthSideADC_clusterXY_R2" , "ADC Peaks North Side", N_phi_binx_XY_R2, -TMath::Pi(), TMath::Pi(), N_rBins_XY, r_bins);
0150   NorthSideADC_clusterXY_R2_unw = new TH2F("NorthSideADC_clusterXY_R2_unw", "(ADC-Pedestal) > 5#sigma Side", 400, -800, 800, 400, -800, 800);
0151   NorthSideADC_clusterXY_R2_unw->SetXTitle("X [mm]");
0152   NorthSideADC_clusterXY_R2_unw->SetYTitle("Y [mm]");
0153 
0154   // NorthSideADC_clusterXY_R3 = new TH2F("NorthSideADC_clusterXY_R3" , "ADC Peaks North Side", N_phi_binx_XY_R3, -TMath::Pi(), TMath::Pi(), N_rBins_XY, r_bins);
0155   NorthSideADC_clusterXY_R3_unw = new TH2F("NorthSideADC_clusterXY_R3_unw", "(ADC-Pedestal) > 5#sigma Side", 400, -800, 800, 400, -800, 800);
0156   NorthSideADC_clusterXY_R3_unw->SetXTitle("X [mm]");
0157   NorthSideADC_clusterXY_R3_unw->SetYTitle("Y [mm]");
0158 
0159   // SouthSideADC_clusterXY_R1 = new TH2F("SouthSideADC_clusterXY_R1" , "ADC Peaks South Side", N_phi_binx_XY_R1, -TMath::Pi(), TMath::Pi(), N_rBins_XY, r_bins);
0160   SouthSideADC_clusterXY_R1_unw = new TH2F("SouthSideADC_clusterXY_R1_unw", "(ADC-Pedestal) > 5#sigma", 400, -800, 800, 400, -800, 800);
0161   SouthSideADC_clusterXY_R1_unw->SetXTitle("X [mm]");
0162   SouthSideADC_clusterXY_R1_unw->SetYTitle("Y [mm]");
0163 
0164   // SouthSideADC_clusterXY_R2 = new TH2F("SouthSideADC_clusterXY_R2" , "ADC Peaks South Side", N_phi_binx_XY_R2, -TMath::Pi(), TMath::Pi(), N_rBins_XY, r_bins);
0165   SouthSideADC_clusterXY_R2_unw = new TH2F("SouthSideADC_clusterXY_R2_unw", "(ADC-Pedestal) > 5#sigma", 400, -800, 800, 400, -800, 800);
0166   SouthSideADC_clusterXY_R2_unw->SetXTitle("X [mm]");
0167   SouthSideADC_clusterXY_R2_unw->SetYTitle("Y [mm]");
0168 
0169   // SouthSideADC_clusterXY_R3 = new TH2F("SouthSideADC_clusterXY_R3" , "ADC Peaks South Side", N_phi_binx_XY_R3, -TMath::Pi(), TMath::Pi(), N_rBins_XY, r_bins);
0170   SouthSideADC_clusterXY_R3_unw = new TH2F("SouthSideADC_clusterXY_R3_unw", "(ADC-Pedestal) > 5#sigma", 400, -800, 800, 400, -800, 800);
0171   SouthSideADC_clusterXY_R3_unw->SetXTitle("X [mm]");
0172   SouthSideADC_clusterXY_R3_unw->SetYTitle("Y [mm]");
0173 
0174   //____________________________________________________________________//
0175 
0176   // TPC 5 event "cluster" XY heat maps WEIGHTED
0177   // NorthSideADC_clusterXY_R1 = new TH2F("NorthSideADC_clusterXY_R1" , "ADC Peaks North Side", N_phi_binx_XY_R1, -TMath::Pi(), TMath::Pi(), N_rBins_XY, r_bins);
0178   NorthSideADC_clusterXY_R1_u5 = new TH2F("NorthSideADC_clusterXY_R1_u5", "(ADC-Pedestal) > 5#sigma North Side", 400, -800, 800, 400, -800, 800);
0179   NorthSideADC_clusterXY_R1_u5->SetXTitle("X [mm]");
0180   NorthSideADC_clusterXY_R1_u5->SetYTitle("Y [mm]");
0181 
0182   // NorthSideADC_clusterXY_R2 = new TH2F("NorthSideADC_clusterXY_R2" , "ADC Peaks North Side", N_phi_binx_XY_R2, -TMath::Pi(), TMath::Pi(), N_rBins_XY, r_bins);
0183   NorthSideADC_clusterXY_R2_u5 = new TH2F("NorthSideADC_clusterXY_R2_u5", "(ADC-Pedestal) > 5#sigma North Side", 400, -800, 800, 400, -800, 800);
0184   NorthSideADC_clusterXY_R2_u5->SetXTitle("X [mm]");
0185   NorthSideADC_clusterXY_R2_u5->SetYTitle("Y [mm]");
0186 
0187   // NorthSideADC_clusterXY_R3 = new TH2F("NorthSideADC_clusterXY_R3" , "ADC Peaks North Side", N_phi_binx_XY_R3, -TMath::Pi(), TMath::Pi(), N_rBins_XY, r_bins);
0188   NorthSideADC_clusterXY_R3_u5 = new TH2F("NorthSideADC_clusterXY_R3_u5", "(ADC-Pedestal) > 5#sigma North Side", 400, -800, 800, 400, -800, 800);
0189   NorthSideADC_clusterXY_R3_u5->SetXTitle("X [mm]");
0190   NorthSideADC_clusterXY_R3_u5->SetYTitle("Y [mm]");
0191 
0192   // SouthSideADC_clusterXY_R1 = new TH2F("SouthSideADC_clusterXY_R1" , "ADC Peaks South Side", N_phi_binx_XY_R1, -TMath::Pi(), TMath::Pi(), N_rBins_XY, r_bins);
0193   SouthSideADC_clusterXY_R1_u5 = new TH2F("SouthSideADC_clusterXY_R1_u5", "(ADC-Pedestal) > 5#sigma South Side", 400, -800, 800, 400, -800, 800);
0194   SouthSideADC_clusterXY_R1_u5->SetXTitle("X [mm]");
0195   SouthSideADC_clusterXY_R1_u5->SetYTitle("Y [mm]");
0196 
0197   // SouthSideADC_clusterXY_R2 = new TH2F("SouthSideADC_clusterXY_R2" , "ADC Peaks South Side", N_phi_binx_XY_R2, -TMath::Pi(), TMath::Pi(), N_rBins_XY, r_bins);
0198   SouthSideADC_clusterXY_R2_u5 = new TH2F("SouthSideADC_clusterXY_R2_u5", "(ADC-Pedestal) > 5#sigma South Side", 400, -800, 800, 400, -800, 800);
0199   SouthSideADC_clusterXY_R2_u5->SetXTitle("X [mm]");
0200   SouthSideADC_clusterXY_R2_u5->SetYTitle("Y [mm]");
0201 
0202   // SouthSideADC_clusterXY_R3 = new TH2F("SouthSideADC_clusterXY_R3" , "ADC Peaks South Side", N_phi_binx_XY_R3, -TMath::Pi(), TMath::Pi(), N_rBins_XY, r_bins);
0203   SouthSideADC_clusterXY_R3_u5 = new TH2F("SouthSideADC_clusterXY_R3_u5", "(ADC-Pedestal) > 5#sigma South Side", 400, -800, 800, 400, -800, 800);
0204   SouthSideADC_clusterXY_R3_u5->SetXTitle("X [mm]");
0205   SouthSideADC_clusterXY_R3_u5->SetYTitle("Y [mm]");
0206 
0207   //____________________________________________________________________//
0208 
0209   // TPC "cluster" ZY heat maps WEIGHTED
0210   NorthSideADC_clusterZY = new TH2F("NorthSideADC_clusterZY", "(ADC-Pedestal) > 5#sigma North Side", 206, -1030, 1030, 400, -800, 800);
0211   SouthSideADC_clusterZY = new TH2F("SouthSideADC_clusterZY", "(ADC-Pedestal) > 5#sigma South Side", 206, -1030, 1030, 400, -800, 800);
0212 
0213   //____________________________________________________________________//
0214 
0215   // TPC "cluster" ZY heat maps UNWEIGHTED
0216   NorthSideADC_clusterZY_unw = new TH2F("NorthSideADC_clusterZY_unw", "(ADC-Pedestal) > 5#sigma North Side", 206, -1030, 1030, 400, -800, 800);
0217   SouthSideADC_clusterZY_unw = new TH2F("SouthSideADC_clusterZY_unw", "(ADC-Pedestal) > 5#sigma South Side", 206, -1030, 1030, 400, -800, 800);
0218 
0219   //____________________________________________________________________//
0220 
0221   //
0222 
0223   // ADC vs Sample (small)
0224   char ADC_vs_SAMPLE_str[100];
0225   char ADC_vs_SAMPLE_xaxis_str[100];
0226   sprintf(ADC_vs_SAMPLE_str, "ADC Counts vs Sample: SECTOR %i", ebdc_from_serverid(MonitorServerId()));
0227   sprintf(ADC_vs_SAMPLE_xaxis_str, "Sector %i: ADC Time bin [1/17.5MHz]", ebdc_from_serverid(MonitorServerId()));
0228   ADC_vs_SAMPLE = new TH2F("ADC_vs_SAMPLE", ADC_vs_SAMPLE_str, 500, 0, 500, 256, 0, 1024);
0229   ADC_vs_SAMPLE->SetXTitle(ADC_vs_SAMPLE_xaxis_str);
0230   ADC_vs_SAMPLE->SetYTitle("ADC [ADU]");
0231 
0232   ADC_vs_SAMPLE->GetXaxis()->SetLabelSize(0.05);
0233   ADC_vs_SAMPLE->GetXaxis()->SetTitleSize(0.05);
0234   ADC_vs_SAMPLE->GetYaxis()->SetLabelSize(0.05);
0235   ADC_vs_SAMPLE->GetYaxis()->SetTitleSize(0.05);
0236   ADC_vs_SAMPLE->GetYaxis()->SetTitleOffset(1.0);
0237 
0238   // PEDEST SUB ADC vs Sample (small)
0239   char PEDEST_SUB_ADC_vs_SAMPLE_str[100];
0240   char PEDEST_SUB_ADC_vs_SAMPLE_xaxis_str[100];
0241   sprintf(PEDEST_SUB_ADC_vs_SAMPLE_str, "ADC Counts vs Sample: SECTOR %i", ebdc_from_serverid(MonitorServerId()));
0242   sprintf(PEDEST_SUB_ADC_vs_SAMPLE_xaxis_str, "Sector %i: ADC Time bin [1/17.5MHz]", ebdc_from_serverid(MonitorServerId()));
0243   PEDEST_SUB_ADC_vs_SAMPLE = new TH2F("PEDEST_SUB_ADC_vs_SAMPLE", PEDEST_SUB_ADC_vs_SAMPLE_str, 500, 0, 500, 281, -100, 1024);
0244   PEDEST_SUB_ADC_vs_SAMPLE->SetXTitle(PEDEST_SUB_ADC_vs_SAMPLE_xaxis_str);
0245   PEDEST_SUB_ADC_vs_SAMPLE->SetYTitle("ADC-ped. [ADU]");
0246 
0247   PEDEST_SUB_ADC_vs_SAMPLE->GetXaxis()->SetLabelSize(0.05);
0248   PEDEST_SUB_ADC_vs_SAMPLE->GetXaxis()->SetTitleSize(0.05);
0249   PEDEST_SUB_ADC_vs_SAMPLE->GetYaxis()->SetLabelSize(0.05);
0250   PEDEST_SUB_ADC_vs_SAMPLE->GetYaxis()->SetTitleSize(0.05);
0251   PEDEST_SUB_ADC_vs_SAMPLE->GetYaxis()->SetTitleOffset(1.0);
0252 
0253   // ADC vs Sample (small)
0254   char PEDEST_SUB_ADC_vs_SAMPLE_R1_str[100];
0255   char PEDEST_SUB_ADC_vs_SAMPLE_R1_xaxis_str[100];
0256   sprintf(PEDEST_SUB_ADC_vs_SAMPLE_R1_str, "ADC Counts vs Sample: SECTOR %i R1", ebdc_from_serverid(MonitorServerId()));
0257   sprintf(PEDEST_SUB_ADC_vs_SAMPLE_R1_xaxis_str, "Sector %i R1: ADC Time bin [1/17.5MHz]", ebdc_from_serverid(MonitorServerId()));
0258   PEDEST_SUB_ADC_vs_SAMPLE_R1 = new TH2F("PEDEST_SUB_ADC_vs_SAMPLE_R1", PEDEST_SUB_ADC_vs_SAMPLE_R1_str, 500, 0, 500, 281, -100, 1024);
0259   PEDEST_SUB_ADC_vs_SAMPLE_R1->SetXTitle(PEDEST_SUB_ADC_vs_SAMPLE_R1_xaxis_str);
0260   PEDEST_SUB_ADC_vs_SAMPLE_R1->SetYTitle("ADC-ped. [ADU]");
0261 
0262   PEDEST_SUB_ADC_vs_SAMPLE_R1->GetXaxis()->SetLabelSize(0.05);
0263   PEDEST_SUB_ADC_vs_SAMPLE_R1->GetXaxis()->SetTitleSize(0.05);
0264   PEDEST_SUB_ADC_vs_SAMPLE_R1->GetYaxis()->SetLabelSize(0.05);
0265   PEDEST_SUB_ADC_vs_SAMPLE_R1->GetYaxis()->SetTitleSize(0.05);
0266   PEDEST_SUB_ADC_vs_SAMPLE_R1->GetYaxis()->SetTitleOffset(1.0);
0267 
0268   // ADC vs Sample (small)
0269   char PEDEST_SUB_ADC_vs_SAMPLE_R2_str[100];
0270   char PEDEST_SUB_ADC_vs_SAMPLE_R2_xaxis_str[100];
0271   sprintf(PEDEST_SUB_ADC_vs_SAMPLE_R2_str, "ADC Counts vs Sample: SECTOR %i R2", ebdc_from_serverid(MonitorServerId()));
0272   sprintf(PEDEST_SUB_ADC_vs_SAMPLE_R2_xaxis_str, "Sector %i R2: ADC Time bin [1/17.5MHz]", ebdc_from_serverid(MonitorServerId()));
0273   PEDEST_SUB_ADC_vs_SAMPLE_R2 = new TH2F("PEDEST_SUB_ADC_vs_SAMPLE_R2", PEDEST_SUB_ADC_vs_SAMPLE_R2_str, 500, 0, 500, 281, -100, 1024);
0274   PEDEST_SUB_ADC_vs_SAMPLE_R2->SetXTitle(PEDEST_SUB_ADC_vs_SAMPLE_R2_xaxis_str);
0275   PEDEST_SUB_ADC_vs_SAMPLE_R2->SetYTitle("ADC-ped. [ADU]");
0276 
0277   PEDEST_SUB_ADC_vs_SAMPLE_R2->GetXaxis()->SetLabelSize(0.05);
0278   PEDEST_SUB_ADC_vs_SAMPLE_R2->GetXaxis()->SetTitleSize(0.05);
0279   PEDEST_SUB_ADC_vs_SAMPLE_R2->GetYaxis()->SetLabelSize(0.05);
0280   PEDEST_SUB_ADC_vs_SAMPLE_R2->GetYaxis()->SetTitleSize(0.05);
0281   PEDEST_SUB_ADC_vs_SAMPLE_R2->GetYaxis()->SetTitleOffset(1.0);
0282 
0283   // ADC vs Sample (small)
0284   char PEDEST_SUB_ADC_vs_SAMPLE_R3_str[100];
0285   char PEDEST_SUB_ADC_vs_SAMPLE_R3_xaxis_str[100];
0286   sprintf(PEDEST_SUB_ADC_vs_SAMPLE_R3_str, "ADC Counts vs Sample: SECTOR %i R3", ebdc_from_serverid(MonitorServerId()));
0287   sprintf(PEDEST_SUB_ADC_vs_SAMPLE_R3_xaxis_str, "Sector %i R3: ADC Time bin [1/17.5MHz]", ebdc_from_serverid(MonitorServerId()));
0288   PEDEST_SUB_ADC_vs_SAMPLE_R3 = new TH2F("PEDEST_SUB_ADC_vs_SAMPLE_R3", PEDEST_SUB_ADC_vs_SAMPLE_R3_str, 500, 0, 500, 281, -100, 1024);
0289   PEDEST_SUB_ADC_vs_SAMPLE_R3->SetXTitle(PEDEST_SUB_ADC_vs_SAMPLE_R3_xaxis_str);
0290   PEDEST_SUB_ADC_vs_SAMPLE_R3->SetYTitle("ADC-ped. [ADU]");
0291 
0292   PEDEST_SUB_ADC_vs_SAMPLE_R3->GetXaxis()->SetLabelSize(0.05);
0293   PEDEST_SUB_ADC_vs_SAMPLE_R3->GetXaxis()->SetTitleSize(0.05);
0294   PEDEST_SUB_ADC_vs_SAMPLE_R3->GetYaxis()->SetLabelSize(0.05);
0295   PEDEST_SUB_ADC_vs_SAMPLE_R3->GetYaxis()->SetTitleSize(0.05);
0296   PEDEST_SUB_ADC_vs_SAMPLE_R1->GetYaxis()->SetTitleOffset(1.0);
0297 
0298   // ADC vs Sample (large)
0299   char ADC_vs_SAMPLE_large_str[100];
0300   char ADC_vs_SAMPLE_xaxis_large_str[100];
0301   sprintf(ADC_vs_SAMPLE_large_str, "ADC Counts vs Large Sample: SECTOR %i", ebdc_from_serverid(MonitorServerId()));
0302   sprintf(ADC_vs_SAMPLE_xaxis_large_str, "Sector %i: ADC Time bin [1/17.5MHz]", ebdc_from_serverid(MonitorServerId()));
0303   ADC_vs_SAMPLE_large = new TH2F("ADC_vs_SAMPLE_large", ADC_vs_SAMPLE_large_str, 1080, 0, 1080, 256, 0, 1024);
0304   ADC_vs_SAMPLE_large->SetXTitle(ADC_vs_SAMPLE_xaxis_large_str);
0305 
0306   ADC_vs_SAMPLE_large->SetYTitle("ADC [ADU]");
0307   ADC_vs_SAMPLE_large->GetXaxis()->SetLabelSize(0.05);
0308   ADC_vs_SAMPLE_large->GetXaxis()->SetTitleSize(0.05);
0309   ADC_vs_SAMPLE_large->GetYaxis()->SetLabelSize(0.05);
0310   ADC_vs_SAMPLE_large->GetYaxis()->SetTitleSize(0.05);
0311   ADC_vs_SAMPLE_large->GetYaxis()->SetTitleOffset(1.0);
0312 
0313   // Sample size distribution 1D histogram
0314   char sample_size_title_str[100];
0315   sprintf(sample_size_title_str, "Distribution of Sample Sizes in Events: SECTOR %i", ebdc_from_serverid(MonitorServerId()));
0316   sample_size_hist = new TH1F("sample_size_hist", sample_size_title_str, 1500, 0.5, 1500.5);
0317   sample_size_hist->SetXTitle("sample size");
0318   sample_size_hist->SetYTitle("counts");
0319 
0320   sample_size_hist->GetXaxis()->SetLabelSize(0.05);
0321   sample_size_hist->GetXaxis()->SetTitleSize(0.05);
0322   sample_size_hist->GetYaxis()->SetLabelSize(0.05);
0323   sample_size_hist->GetYaxis()->SetTitleSize(0.05);
0324   sample_size_hist->GetYaxis()->SetTitleOffset(1.0);
0325 
0326   // Stuck Channel 1D histogram
0327   char stuck_channel_title_str[100];
0328   sprintf(stuck_channel_title_str, "Stuck Channels per FEE in Events: Sector %i", ebdc_from_serverid(MonitorServerId()));
0329   Stuck_Channels = new TH1F("Stuck_Channels", stuck_channel_title_str, 26, -0.5, 25.5);
0330   Stuck_Channels->SetXTitle("FEE_NUM");
0331   Stuck_Channels->SetYTitle("NUM_STUCK_CHANNELS");
0332 
0333   Stuck_Channels->GetXaxis()->SetLabelSize(0.05);
0334   Stuck_Channels->GetXaxis()->SetTitleSize(0.05);
0335   Stuck_Channels->GetYaxis()->SetLabelSize(0.05);
0336   Stuck_Channels->GetYaxis()->SetTitleSize(0.05);
0337   Stuck_Channels->GetYaxis()->SetTitleOffset(1.0);
0338 
0339   // entries vs FEE*8 + SAMPA Number
0340   Check_Sums = new TH1F("Check_Sums", "Entries vs Fee*8 + SAMPA in Events", 208, -0.5, 207.5);
0341   Check_Sums->SetXTitle("FEE_NUM*8 + SAMPA_ADRR");
0342   Check_Sums->SetYTitle("Entries");
0343   Check_Sums->Sumw2(kFALSE);  // explicity turn off Sumw2 - we do not want it
0344   Check_Sums->SetFillColor(4);
0345 
0346   Check_Sums->GetXaxis()->SetLabelSize(0.05);
0347   Check_Sums->GetXaxis()->SetTitleSize(0.05);
0348   Check_Sums->GetYaxis()->SetLabelSize(0.05);
0349   Check_Sums->GetYaxis()->SetTitleSize(0.05);
0350   Check_Sums->GetYaxis()->SetTitleOffset(1.0);
0351 
0352   // checksum error vs FEE*8 + SAMPA Number
0353   char checksum_title_str[100];
0354   sprintf(checksum_title_str, "Check Sum Error Probability vs Fee*8 + SAMPA in Events: SECTOR %i", ebdc_from_serverid(MonitorServerId()));
0355   Check_Sum_Error = new TH1F("Check_Sum_Error", checksum_title_str, 208, -0.5, 207.5);
0356   Check_Sum_Error->SetXTitle("FEE_NUM*8 + SAMPA_ADDR");
0357   Check_Sum_Error->SetYTitle("Prob. Check Sum. Err.");
0358   Check_Sum_Error->Sumw2(kFALSE);  // explicity turn off Sumw2 - we do not want it
0359   Check_Sum_Error->SetFillColor(4);
0360 
0361   Check_Sum_Error->GetXaxis()->SetLabelSize(0.05);
0362   Check_Sum_Error->GetXaxis()->SetTitleSize(0.05);
0363   Check_Sum_Error->GetYaxis()->SetLabelSize(0.05);
0364   Check_Sum_Error->GetYaxis()->SetTitleSize(0.05);
0365   Check_Sum_Error->GetYaxis()->SetTitleOffset(1.0);
0366 
0367   // Parity error vs FEE*8 + SAMPA Number
0368   char parity_title_str[100];
0369   sprintf(parity_title_str, "Parity Error Probability vs Fee*8 + SAMPA in Events: SECTOR %i", ebdc_from_serverid(MonitorServerId()));
0370   Parity_Error = new TH1F("Parity_Error", checksum_title_str, 208, -0.5, 207.5);
0371   Parity_Error->SetXTitle("FEE_NUM*8 + SAMPA_ADDR");
0372   Parity_Error->SetYTitle("Prob. Parity Err.");
0373   Parity_Error->Sumw2(kFALSE);  // explicity turn off Sumw2 - we do not want it
0374   Parity_Error->SetFillColor(4);
0375 
0376   Parity_Error->GetXaxis()->SetLabelSize(0.05);
0377   Parity_Error->GetXaxis()->SetTitleSize(0.05);
0378   Parity_Error->GetYaxis()->SetLabelSize(0.05);
0379   Parity_Error->GetYaxis()->SetTitleSize(0.05);
0380   Parity_Error->GetYaxis()->SetTitleOffset(1.0);
0381 
0382   // number of nonZS channels - <number of channels in sampa with values != 65 K ADC> vs sampa number + (feeID * sampa number)
0383   char num_nonZS_channels_title_str[100];
0384   sprintf(num_nonZS_channels_title_str, "Number of non ZS Channels: # of samples in channel waveform != 65K vs SAMPA ID: SECTOR %i", ebdc_from_serverid(MonitorServerId()));
0385   // x-axis is channel phi, y-axis is channel layer, z axis is ADC weithing
0386   Num_non_ZS_channels_vs_SAMPA = new TH2F("Num_non_ZS_channels_vs_SAMPA", num_nonZS_channels_title_str, 208, -0.5, 207.5, 1324, -300.5, 1023.5);
0387   Num_non_ZS_channels_vs_SAMPA->SetXTitle("SAMPA ID: SAMPA # + (feeID * 8)");
0388   Num_non_ZS_channels_vs_SAMPA->SetYTitle("# of Non-Zero Suppressed Samples in WF");
0389 
0390   Num_non_ZS_channels_vs_SAMPA->GetXaxis()->SetLabelSize(0.05);
0391   Num_non_ZS_channels_vs_SAMPA->GetXaxis()->SetTitleSize(0.05);
0392   Num_non_ZS_channels_vs_SAMPA->SetLabelSize(0.05);
0393   Num_non_ZS_channels_vs_SAMPA->GetYaxis()->SetTitleSize(0.05);
0394   Num_non_ZS_channels_vs_SAMPA->GetYaxis()->SetTitleOffset(1.0);
0395 
0396   // # of times channels are in packet per RCDAQ event
0397   char chans_in_packet_title_str[100];
0398   sprintf(chans_in_packet_title_str, "Channel counts vs Channel in packets in  RCDAQ Events: SECTOR %i", ebdc_from_serverid(MonitorServerId()));
0399   Channels_in_Packet = new TH1F("Channels_in_Packet", chans_in_packet_title_str, 6656, -0.5, 6655.5);
0400   Channels_in_Packet->SetXTitle("(FEE # * 256) + chan. #");
0401   Channels_in_Packet->SetYTitle("Counts / Packet in RCDAQ Event");
0402   Channels_in_Packet->SetStats(0);
0403 
0404   Channels_in_Packet->GetXaxis()->SetLabelSize(0.05);
0405   Channels_in_Packet->GetXaxis()->SetTitleSize(0.05);
0406   Channels_in_Packet->GetYaxis()->SetLabelSize(0.05);
0407   Channels_in_Packet->GetYaxis()->SetTitleSize(0.05);
0408   Channels_in_Packet->GetYaxis()->SetTitleOffset(1.0);
0409 
0410   // # of times channels could be in packet per RCDAQ event
0411   char chans_always_title_str[100];
0412   sprintf(chans_always_title_str, "Channel counts vs all channels (filled once per event w/ packets): SECTOR %i", ebdc_from_serverid(MonitorServerId()));
0413   Channels_Always = new TH1F("Channels_Always", chans_always_title_str, 6656, -0.5, 6655.5);
0414   Channels_Always->SetXTitle("(FEE # * 256) + chan. #");
0415   Channels_Always->SetYTitle("Counts");
0416   Channels_Always->SetStats(0);
0417 
0418   Channels_Always->GetXaxis()->SetLabelSize(0.05);
0419   Channels_Always->GetXaxis()->SetTitleSize(0.05);
0420   Channels_Always->GetYaxis()->SetLabelSize(0.05);
0421   Channels_Always->GetYaxis()->SetTitleSize(0.05);
0422   Channels_Always->GetYaxis()->SetTitleOffset(1.0);
0423 
0424   // # of LVL 1 tagger per EBDC
0425   LVL_1_TAGGER_per_EBDC = new TH1F("LVL_1_TAGGER_per_EBDC", "Number of LEVEL 1 TAGGERS PER EBDC", 24, -0.5, 23.5);
0426   LVL_1_TAGGER_per_EBDC->SetXTitle("EBDC #");
0427   LVL_1_TAGGER_per_EBDC->SetYTitle("N_{LVL_1_TAGGER}");
0428 
0429   // ZS ADC vs Sample (small)
0430   char ZS_ADC_vs_SAMPLE_str[100];
0431   char ZS_ADC_vs_SAMPLE_xaxis_str[100];
0432   sprintf(ZS_ADC_vs_SAMPLE_str, "ADC Counts vs Sample - Trigger QA: SECTOR %i", ebdc_from_serverid(MonitorServerId()));
0433   sprintf(ZS_ADC_vs_SAMPLE_xaxis_str, "Sector %i: ADC Time bin [1/17.5MHz]", ebdc_from_serverid(MonitorServerId()));
0434   ZS_Trigger_ADC_vs_Sample = new TH2F("ZS_Trigger_ADC_vs_Sample", ZS_ADC_vs_SAMPLE_str, 500, 0, 500, 1024, 0, 1024);
0435   ZS_Trigger_ADC_vs_Sample->SetXTitle(ZS_ADC_vs_SAMPLE_xaxis_str);
0436   ZS_Trigger_ADC_vs_Sample->SetYTitle("ADC [ADU]");
0437 
0438   ZS_Trigger_ADC_vs_Sample->GetXaxis()->SetLabelSize(0.05);
0439   ZS_Trigger_ADC_vs_Sample->GetXaxis()->SetTitleSize(0.05);
0440   ZS_Trigger_ADC_vs_Sample->GetYaxis()->SetLabelSize(0.05);
0441   ZS_Trigger_ADC_vs_Sample->GetYaxis()->SetTitleSize(0.05);
0442   ZS_Trigger_ADC_vs_Sample->GetYaxis()->SetTitleOffset(1.0);
0443 
0444   // First non-ZS ADC vs Sample (small)
0445   char First_ADC_vs_First_Time_Bin_str[100];
0446   char First_ADC_vs_First_Time_Bin_xaxis_str[100];
0447   sprintf(First_ADC_vs_First_Time_Bin_str, "1st nonZS ADC vs 1st nonZS Sample Time: SECTOR %i", ebdc_from_serverid(MonitorServerId()));
0448   sprintf(First_ADC_vs_First_Time_Bin_xaxis_str, "Sector %i: 1st non-ZS Time bin [1/17.5MHz]", ebdc_from_serverid(MonitorServerId()));
0449   First_ADC_vs_First_Time_Bin = new TH2F("First_ADC_vs_First_Time_Bin", First_ADC_vs_First_Time_Bin_str, 500, 0, 500, 256, 0, 1024);
0450   First_ADC_vs_First_Time_Bin->SetXTitle(First_ADC_vs_First_Time_Bin_xaxis_str);
0451   First_ADC_vs_First_Time_Bin->SetYTitle("1st non-ZS ADC [ADU]");
0452 
0453   First_ADC_vs_First_Time_Bin->GetXaxis()->SetLabelSize(0.05);
0454   First_ADC_vs_First_Time_Bin->GetXaxis()->SetTitleSize(0.05);
0455   First_ADC_vs_First_Time_Bin->GetYaxis()->SetLabelSize(0.05);
0456   First_ADC_vs_First_Time_Bin->GetYaxis()->SetTitleSize(0.05);
0457   First_ADC_vs_First_Time_Bin->GetYaxis()->SetTitleOffset(1.0);
0458 
0459   // Max ADC per waveform dist for each module (R1, R2, R3)
0460   char MAXADC_str[100];
0461   char YLabel_str[5];
0462 
0463   sprintf(MAXADC_str, "MAX ADC per Waveform in SLIDING WINDOW: SECTOR %i", ebdc_from_serverid(MonitorServerId()));
0464 
0465   MAXADC = new TH2F("MAXADC", MAXADC_str, 1025, -0.5, 1024.5, 3, -0.5, 2.5);
0466   MAXADC->SetXTitle("LocalMAX ADC in Waveform [ADU]");
0467   MAXADC->SetYTitle("Entries");
0468   MAXADC->Sumw2(kFALSE);  // explicity turn off Sumw2 - we do not want it
0469 
0470   for (int i = 0; i < 3; i++)
0471   {
0472     sprintf(YLabel_str, "R%i", i + 1);
0473     MAXADC->GetYaxis()->SetBinLabel(i + 1, YLabel_str);
0474     MAXADC->GetYaxis()->SetLabelSize(0.12);
0475     MAXADC->GetXaxis()->SetLabelSize(0.04);
0476   }
0477 
0478   //________For 1D ADC spectra - Doing this the hard way because I'm not sure if I can have a TH1 array
0479   char RAWADC_1D_titlestr[100];
0480   char MAXADC_1D_titlestr[100];
0481   char SUBADC_1D_titlestr[100];
0482   char COUNTS_SAMPLE_1D_titlestr[100];
0483   char COUNTS_SAMPLE_1D_xtitlestr[100];
0484 
0485   sprintf(RAWADC_1D_titlestr, "RAW ADC for Sector %i R1", ebdc_from_serverid(MonitorServerId()));
0486   sprintf(MAXADC_1D_titlestr, "MAX ADC in SLIDING WINDOW for Sector %i R1", ebdc_from_serverid(MonitorServerId()));
0487   sprintf(SUBADC_1D_titlestr, "PEDEST_SUB RAW ADC for Sector %i R1", ebdc_from_serverid(MonitorServerId()));
0488   sprintf(COUNTS_SAMPLE_1D_titlestr, "COUNTS_vs_SAMPLE for Sector %i R1", ebdc_from_serverid(MonitorServerId()));
0489   sprintf(COUNTS_SAMPLE_1D_xtitlestr, "Sector %i: Time bin [1/17.5MHz]", ebdc_from_serverid(MonitorServerId()));
0490 
0491   RAWADC_1D_R1 = new TH1F("RAWADC_1D_R1", RAWADC_1D_titlestr, 1025, -0.5, 1024.5);
0492   MAXADC_1D_R1 = new TH1F("MAXADC_1D_R1", MAXADC_1D_titlestr, 1025, -0.5, 1024.5);
0493   PEDEST_SUB_1D_R1 = new TH1F("PEDEST_SUB_1D_R1", SUBADC_1D_titlestr, 1125, -100.5, 1024.5);
0494   COUNTS_vs_SAMPLE_1D_R1 = new TH1F("COUNTS_vs_SAMPLE_1D_R1", COUNTS_SAMPLE_1D_titlestr, 500, 0, 500);
0495 
0496   RAWADC_1D_R1->SetYTitle("Entries");
0497   RAWADC_1D_R1->SetXTitle("ADC [ADU]");
0498 
0499   MAXADC_1D_R1->SetYTitle("Entries");
0500   MAXADC_1D_R1->SetXTitle("(MAXADC-pedestal) [ADU]");
0501 
0502   PEDEST_SUB_1D_R1->SetYTitle("Entries");
0503   PEDEST_SUB_1D_R1->SetXTitle("(ADC-pedestal) [ADU]");
0504 
0505   PEDEST_SUB_1D_R1->SetYTitle("Entries");
0506   PEDEST_SUB_1D_R1->SetXTitle("(ADC-pedestal) [ADU]");
0507 
0508   COUNTS_vs_SAMPLE_1D_R1->SetYTitle("Entries");
0509   COUNTS_vs_SAMPLE_1D_R1->SetXTitle(COUNTS_SAMPLE_1D_xtitlestr);
0510 
0511   MAXADC_1D_R1->Sumw2(kFALSE);
0512   RAWADC_1D_R1->Sumw2(kFALSE);
0513   PEDEST_SUB_1D_R1->Sumw2(kFALSE);
0514   COUNTS_vs_SAMPLE_1D_R1->Sumw2(kFALSE);
0515 
0516   MAXADC_1D_R1->SetLineColor(2);
0517   RAWADC_1D_R1->SetLineColor(2);
0518   PEDEST_SUB_1D_R1->SetLineColor(2);
0519   COUNTS_vs_SAMPLE_1D_R1->SetLineColor(2);
0520 
0521   MAXADC_1D_R1->GetXaxis()->SetLabelSize(0.05);
0522   MAXADC_1D_R1->GetXaxis()->SetTitleSize(0.05);
0523   MAXADC_1D_R1->GetYaxis()->SetLabelSize(0.05);
0524   MAXADC_1D_R1->GetYaxis()->SetTitleSize(0.05);
0525   MAXADC_1D_R1->GetYaxis()->SetTitleOffset(1.0);
0526   RAWADC_1D_R1->GetXaxis()->SetLabelSize(0.05);
0527   RAWADC_1D_R1->GetXaxis()->SetTitleSize(0.05);
0528   RAWADC_1D_R1->GetYaxis()->SetLabelSize(0.05);
0529   RAWADC_1D_R1->GetYaxis()->SetTitleSize(0.05);
0530   RAWADC_1D_R1->GetYaxis()->SetTitleOffset(1.0);
0531   PEDEST_SUB_1D_R1->GetXaxis()->SetLabelSize(0.05);
0532   PEDEST_SUB_1D_R1->GetXaxis()->SetTitleSize(0.05);
0533   PEDEST_SUB_1D_R1->GetYaxis()->SetLabelSize(0.05);
0534   PEDEST_SUB_1D_R1->GetYaxis()->SetTitleSize(0.05);
0535   PEDEST_SUB_1D_R1->GetYaxis()->SetTitleOffset(1.0);
0536   COUNTS_vs_SAMPLE_1D_R1->GetXaxis()->SetLabelSize(0.05);
0537   COUNTS_vs_SAMPLE_1D_R1->GetXaxis()->SetTitleSize(0.05);
0538   COUNTS_vs_SAMPLE_1D_R1->GetYaxis()->SetLabelSize(0.05);
0539   COUNTS_vs_SAMPLE_1D_R1->GetYaxis()->SetTitleSize(0.05);
0540   COUNTS_vs_SAMPLE_1D_R1->GetYaxis()->SetTitleOffset(1.0);
0541 
0542   sprintf(RAWADC_1D_titlestr, "RAW ADC for Sector %i R2", ebdc_from_serverid(MonitorServerId()));
0543   sprintf(MAXADC_1D_titlestr, "MAX ADC for Sector %i R2", ebdc_from_serverid(MonitorServerId()));
0544   sprintf(SUBADC_1D_titlestr, "PEDEST_SUB RAW ADC for Sector %i R2`", ebdc_from_serverid(MonitorServerId()));
0545   sprintf(COUNTS_SAMPLE_1D_titlestr, "COUNTS_vs_SAMPLE for Sector %i R2", ebdc_from_serverid(MonitorServerId()));
0546 
0547   RAWADC_1D_R2 = new TH1F("RAWADC_1D_R2", RAWADC_1D_titlestr, 1025, -0.5, 1024.5);
0548   MAXADC_1D_R2 = new TH1F("MAXADC_1D_R2", MAXADC_1D_titlestr, 1025, -0.5, 1024.5);
0549   PEDEST_SUB_1D_R2 = new TH1F("PEDEST_SUB_1D_R2", SUBADC_1D_titlestr, 1125, -100.5, 1024.5);
0550   COUNTS_vs_SAMPLE_1D_R2 = new TH1F("COUNTS_vs_SAMPLE_1D_R2", COUNTS_SAMPLE_1D_titlestr, 500, 0, 500);
0551 
0552   RAWADC_1D_R2->SetYTitle("Entries");
0553   RAWADC_1D_R2->SetXTitle("ADC [ADU]");
0554 
0555   MAXADC_1D_R2->SetYTitle("Entries");
0556   MAXADC_1D_R2->SetXTitle("(MAXADC-pedestal) [ADU]");
0557 
0558   PEDEST_SUB_1D_R2->SetYTitle("Entries");
0559   PEDEST_SUB_1D_R2->SetXTitle("(ADC-pedestal) [ADU]");
0560 
0561   COUNTS_vs_SAMPLE_1D_R2->SetYTitle("Entries");
0562   COUNTS_vs_SAMPLE_1D_R2->SetXTitle(COUNTS_SAMPLE_1D_xtitlestr);
0563 
0564   MAXADC_1D_R2->Sumw2(kFALSE);
0565   RAWADC_1D_R2->Sumw2(kFALSE);
0566   PEDEST_SUB_1D_R2->Sumw2(kFALSE);
0567   COUNTS_vs_SAMPLE_1D_R2->Sumw2(kFALSE);
0568 
0569   MAXADC_1D_R2->SetLineColor(3);
0570   RAWADC_1D_R2->SetLineColor(3);
0571   PEDEST_SUB_1D_R2->SetLineColor(3);
0572   COUNTS_vs_SAMPLE_1D_R2->SetLineColor(3);
0573 
0574   MAXADC_1D_R2->GetXaxis()->SetLabelSize(0.05);
0575   MAXADC_1D_R2->GetXaxis()->SetTitleSize(0.05);
0576   MAXADC_1D_R2->GetYaxis()->SetLabelSize(0.05);
0577   MAXADC_1D_R2->GetYaxis()->SetTitleSize(0.05);
0578   MAXADC_1D_R2->GetYaxis()->SetTitleOffset(1.0);
0579   RAWADC_1D_R2->GetXaxis()->SetLabelSize(0.05);
0580   RAWADC_1D_R2->GetXaxis()->SetTitleSize(0.05);
0581   RAWADC_1D_R2->GetYaxis()->SetLabelSize(0.05);
0582   RAWADC_1D_R2->GetYaxis()->SetTitleSize(0.05);
0583   RAWADC_1D_R2->GetYaxis()->SetTitleOffset(1.0);
0584   PEDEST_SUB_1D_R2->GetXaxis()->SetLabelSize(0.05);
0585   PEDEST_SUB_1D_R2->GetXaxis()->SetTitleSize(0.05);
0586   PEDEST_SUB_1D_R2->GetYaxis()->SetLabelSize(0.05);
0587   PEDEST_SUB_1D_R2->GetYaxis()->SetTitleSize(0.05);
0588   PEDEST_SUB_1D_R2->GetYaxis()->SetTitleOffset(1.0);
0589   COUNTS_vs_SAMPLE_1D_R2->GetXaxis()->SetLabelSize(0.05);
0590   COUNTS_vs_SAMPLE_1D_R2->GetXaxis()->SetTitleSize(0.05);
0591   COUNTS_vs_SAMPLE_1D_R2->GetYaxis()->SetLabelSize(0.05);
0592   COUNTS_vs_SAMPLE_1D_R2->GetYaxis()->SetTitleSize(0.05);
0593   COUNTS_vs_SAMPLE_1D_R2->GetYaxis()->SetTitleOffset(1.0);
0594 
0595   sprintf(RAWADC_1D_titlestr, "RAW ADC for Sector %i R3", ebdc_from_serverid(MonitorServerId()));
0596   sprintf(MAXADC_1D_titlestr, "MAX ADC for Sector %i R3", ebdc_from_serverid(MonitorServerId()));
0597   sprintf(SUBADC_1D_titlestr, "PEDEST_SUB RAW ADC for Sector %i R3", ebdc_from_serverid(MonitorServerId()));
0598 
0599   RAWADC_1D_R3 = new TH1F("RAWADC_1D_R3", RAWADC_1D_titlestr, 1025, -0.5, 1024.5);
0600   MAXADC_1D_R3 = new TH1F("MAXADC_1D_R3", MAXADC_1D_titlestr, 1025, -0.5, 1024.5);
0601   PEDEST_SUB_1D_R3 = new TH1F("PEDEST_SUB_1D_R3", SUBADC_1D_titlestr, 1125, -100.5, 1024.5);
0602   COUNTS_vs_SAMPLE_1D_R3 = new TH1F("COUNTS_vs_SAMPLE_1D_R3", COUNTS_SAMPLE_1D_titlestr, 500, 0, 500);
0603 
0604   RAWADC_1D_R3->SetYTitle("Entries");
0605   RAWADC_1D_R3->SetXTitle("ADC [ADU]");
0606 
0607   MAXADC_1D_R3->SetYTitle("Entries");
0608   MAXADC_1D_R3->SetXTitle("(MAXADC-pedestal) [ADU]");
0609 
0610   PEDEST_SUB_1D_R3->SetYTitle("Entries");
0611   PEDEST_SUB_1D_R3->SetXTitle("(ADC-pedestal) [ADU]");
0612 
0613   COUNTS_vs_SAMPLE_1D_R3->SetYTitle("Entries");
0614   COUNTS_vs_SAMPLE_1D_R3->SetXTitle(COUNTS_SAMPLE_1D_xtitlestr);
0615 
0616   MAXADC_1D_R3->Sumw2(kFALSE);  // ADC vs Sample (small)
0617   RAWADC_1D_R3->Sumw2(kFALSE);
0618   PEDEST_SUB_1D_R3->Sumw2(kFALSE);
0619   COUNTS_vs_SAMPLE_1D_R3->Sumw2(kFALSE);
0620 
0621   MAXADC_1D_R3->SetLineColor(4);
0622   RAWADC_1D_R3->SetLineColor(4);
0623   PEDEST_SUB_1D_R3->SetLineColor(4);
0624   COUNTS_vs_SAMPLE_1D_R3->SetLineColor(4);
0625 
0626   MAXADC_1D_R3->GetXaxis()->SetLabelSize(0.05);
0627   MAXADC_1D_R3->GetXaxis()->SetTitleSize(0.05);
0628   MAXADC_1D_R3->GetYaxis()->SetLabelSize(0.05);
0629   MAXADC_1D_R3->GetYaxis()->SetTitleSize(0.05);
0630   MAXADC_1D_R3->GetYaxis()->SetTitleOffset(1.0);
0631   RAWADC_1D_R3->GetXaxis()->SetLabelSize(0.05);
0632   RAWADC_1D_R3->GetXaxis()->SetTitleSize(0.05);
0633   RAWADC_1D_R3->GetYaxis()->SetLabelSize(0.05);
0634   RAWADC_1D_R3->GetYaxis()->SetTitleSize(0.05);
0635   RAWADC_1D_R3->GetYaxis()->SetTitleOffset(1.0);
0636   PEDEST_SUB_1D_R3->GetXaxis()->SetLabelSize(0.05);
0637   PEDEST_SUB_1D_R3->GetXaxis()->SetTitleSize(0.05);
0638   PEDEST_SUB_1D_R3->GetYaxis()->SetLabelSize(0.05);
0639   PEDEST_SUB_1D_R3->GetYaxis()->SetTitleSize(0.05);
0640   PEDEST_SUB_1D_R3->GetYaxis()->SetTitleOffset(1.0);
0641   COUNTS_vs_SAMPLE_1D_R3->GetXaxis()->SetLabelSize(0.05);
0642   COUNTS_vs_SAMPLE_1D_R3->GetXaxis()->SetTitleSize(0.05);
0643   COUNTS_vs_SAMPLE_1D_R3->GetYaxis()->SetLabelSize(0.05);
0644   COUNTS_vs_SAMPLE_1D_R3->GetYaxis()->SetTitleSize(0.05);
0645   COUNTS_vs_SAMPLE_1D_R3->GetYaxis()->SetTitleOffset(1.0);
0646 
0647   char Layer_ChannelPhi_ADC_weighted_title_str[256];
0648   sprintf(Layer_ChannelPhi_ADC_weighted_title_str, "Layer vs Channel Phi");
0649   // x-axis is channel phi, y-axis is channel layer, z axis is ADC weithing
0650   Layer_ChannelPhi_ADC_weighted = new TH2F("Layer_ChannelPhi_ADC_weighted", Layer_ChannelPhi_ADC_weighted_title_str, 4610, -2305.5, 2304.5, 61, -0.5, 59.5);
0651   Layer_ChannelPhi_ADC_weighted->SetXTitle("Channel # (#phi bin)");
0652   Layer_ChannelPhi_ADC_weighted->SetYTitle("Layer");
0653 
0654   char NStreakers_vs_Event_title_str[256];
0655   sprintf(NStreakers_vs_Event_title_str, "Number of Streakers vs Event, Sector # %i", ebdc_from_serverid(MonitorServerId()));
0656   NStreaks_vs_EventNo = new TH1F("NStreaks_vs_EventNo", NStreakers_vs_Event_title_str, 1000000, -0.5, 999999.5);
0657   NStreaks_vs_EventNo->SetXTitle("Event #");
0658   NStreaks_vs_EventNo->SetYTitle("Number of horizontal streak channels");
0659   NStreaks_vs_EventNo->GetXaxis()->SetLabelSize(0.05);
0660   NStreaks_vs_EventNo->GetXaxis()->SetTitleSize(0.05);
0661   NStreaks_vs_EventNo->GetYaxis()->SetLabelSize(0.05);
0662   NStreaks_vs_EventNo->GetYaxis()->SetTitleSize(0.05);
0663   NStreaks_vs_EventNo->GetYaxis()->SetTitleOffset(1.0);
0664 
0665   char NEvents_vs_EBDC_title_str[256];
0666   sprintf(NEvents_vs_EBDC_title_str, "N_{Events} vs EBDC");
0667   NEvents_vs_EBDC = new TH1F("NEvents_vs_EBDC", NEvents_vs_EBDC_title_str, 24, -0.5, 23.5);
0668   NEvents_vs_EBDC->SetXTitle("EBDC #");
0669   NEvents_vs_EBDC->SetYTitle("N_{Events}");
0670 
0671   char Packet_Type_Fraction_title_str[256];
0672   sprintf(Packet_Type_Fraction_title_str, "Numer of Waveforms per Packet Type, Sector # %i", ebdc_from_serverid(MonitorServerId()));
0673   Packet_Type_Fraction_HB = new TH1F("Packet_Type_Fraction_HB", Packet_Type_Fraction_title_str, 7, 0, 7);
0674   Packet_Type_Fraction_HB->SetYTitle("N_{Waveforms}");
0675   Packet_Type_Fraction_HB->SetLineColor(4);
0676   Packet_Type_Fraction_HB->SetFillColor(4);
0677 
0678   Packet_Type_Fraction_NORM = new TH1F("Packet_Type_Fraction_NORM", Packet_Type_Fraction_title_str, 7, 0, 7);
0679   Packet_Type_Fraction_NORM->SetYTitle("N_{Waveforms}");
0680   Packet_Type_Fraction_NORM->SetLineColor(3);
0681   Packet_Type_Fraction_NORM->SetFillColor(3);
0682 
0683   Packet_Type_Fraction_ELSE = new TH1F("Packet_Type_Fraction_ELSE", Packet_Type_Fraction_title_str, 7, 0, 7);
0684   Packet_Type_Fraction_ELSE->SetYTitle("N_{Waveforms}");
0685   Packet_Type_Fraction_ELSE->SetLineColor(2);
0686   Packet_Type_Fraction_ELSE->SetFillColor(2);
0687 
0688   const char *label[7] = {"HEARTBEAT_T", "TRUNCATED_DATA_T ", "TRUNCATED_TRIG_EARLY_DATA_T", "NORMAL_DATA_T", "LARGE_DATA_T", "TRIG_EARLY_DATA_T", "TRIG_EARLY_LARGE_DATA_T"};
0689   for (int i = 0; i != 7; ++i)
0690   {
0691     Packet_Type_Fraction_HB->GetXaxis()->SetBinLabel(i + 1, label[i]);
0692     Packet_Type_Fraction_NORM->GetXaxis()->SetBinLabel(i + 1, label[i]);
0693     Packet_Type_Fraction_ELSE->GetXaxis()->SetBinLabel(i + 1, label[i]);
0694   }
0695 
0696   Packet_Type_Fraction_HB->GetXaxis()->SetLabelSize(0.08);
0697   Packet_Type_Fraction_HB->GetYaxis()->SetLabelSize(0.08);
0698   Packet_Type_Fraction_HB->GetYaxis()->SetTitleSize(0.08);
0699   Packet_Type_Fraction_HB->GetYaxis()->SetTitleOffset(0.6);
0700 
0701   Packet_Type_Fraction_NORM->GetXaxis()->SetLabelSize(0.08);
0702   Packet_Type_Fraction_NORM->GetYaxis()->SetLabelSize(0.08);
0703   Packet_Type_Fraction_NORM->GetYaxis()->SetTitleSize(0.08);
0704   Packet_Type_Fraction_NORM->GetYaxis()->SetTitleOffset(0.6);
0705 
0706   Packet_Type_Fraction_ELSE->GetXaxis()->SetLabelSize(0.08);
0707   Packet_Type_Fraction_ELSE->GetYaxis()->SetLabelSize(0.08);
0708   Packet_Type_Fraction_ELSE->GetYaxis()->SetTitleSize(0.08);
0709   Packet_Type_Fraction_ELSE->GetYaxis()->SetTitleOffset(0.6);
0710 
0711   // Noise Channel Plots for Takao
0712 
0713   char Noise_Channel_Plots_title_str[256];
0714   sprintf(Noise_Channel_Plots_title_str, "Counts of ADC-Ped. > 300, t < 360 ,Sector # %i", ebdc_from_serverid(MonitorServerId()));
0715   Noise_Channel_Plots = new TH1F("Noise_Channel_Plots", "", 6656, -0.5, 6655.5);
0716   Noise_Channel_Plots->GetXaxis()->SetLabelSize(0.05);
0717   Noise_Channel_Plots->GetXaxis()->SetTitleSize(0.05);
0718   Noise_Channel_Plots->GetYaxis()->SetLabelSize(0.05);
0719   Noise_Channel_Plots->GetYaxis()->SetTitleSize(0.05);
0720   Noise_Channel_Plots->GetYaxis()->SetTitleOffset(1.0);
0721 
0722   Noise_Channel_Plots->SetXTitle("(FEE # * 256) + chan. #");
0723   Noise_Channel_Plots->SetYTitle("Counts/Event");
0724   Noise_Channel_Plots->SetStats(0);
0725 
0726   // DC vs SAMPA
0727   char DC_channels_title_str[100];
0728   sprintf(DC_channels_title_str, "DIGITAL CURRENT vs SAMPA ID: SECTOR %i", ebdc_from_serverid(MonitorServerId()));
0729   // DC_vs_SAMPA = new TH2F("DC_vs_SAMPA",DC_channels_title_str,208,-0.5,207.5,5924,-9000.5,50239.5);
0730   DC_vs_SAMPA = new TH2F("DC_vs_SAMPA", DC_channels_title_str, 208, -0.5, 207.5, 741, -9000.5, 50239.5);
0731   DC_vs_SAMPA->SetXTitle("SAMPA ID: SAMPA # + (feeID * 8)");
0732   DC_vs_SAMPA->SetYTitle("DC = #Sigma ADC - 60*BIN_SUM");
0733 
0734   DC_vs_SAMPA->GetXaxis()->SetLabelSize(0.05);
0735   DC_vs_SAMPA->GetXaxis()->SetTitleSize(0.05);
0736   DC_vs_SAMPA->SetLabelSize(0.05);
0737   DC_vs_SAMPA->GetYaxis()->SetTitleSize(0.05);
0738   DC_vs_SAMPA->GetYaxis()->SetTitleOffset(1.0);
0739 
0740   // SAMPA vs Time (weighted by DC)
0741   char SAMPA_vs_Time_DC_title_str[100];
0742   sprintf(SAMPA_vs_Time_DC_title_str, "SAMPA ID vs TIME (WTD. by DC = #Sigma ADC - 60*BIN_SUM): SECTOR %i", ebdc_from_serverid(MonitorServerId()));
0743   DC_SAMPA_vs_TIME = new TH2F("DC_SAMPA_vs_TIME", SAMPA_vs_Time_DC_title_str, 6000, -660000, 1200000, 208, -0.5, 207.5);  // rollover
0744   // DC_SAMPA_vs_TIME = new TH2F("DC_SAMPA_vs_TIME",SAMPA_vs_Time_DC_title_str,10050,-49500000,150000000,208,-0.5,207.5); // no rollover
0745   // DC_SAMPA_vs_TIME = new TH2F("DC_SAMPA_vs_TIME",SAMPA_vs_Time_DC_title_str,1256,-49500000,150000000,208,-0.5,207.5); // no rollover
0746   DC_SAMPA_vs_TIME->SetXTitle("BCO");
0747   DC_SAMPA_vs_TIME->SetYTitle("SAMPA ID: SAMPA # + (feeID *8)");
0748 
0749   DC_SAMPA_vs_TIME->GetXaxis()->SetLabelSize(0.05);
0750   DC_SAMPA_vs_TIME->GetXaxis()->SetTitleSize(0.05);
0751   DC_SAMPA_vs_TIME->SetLabelSize(0.05);
0752   DC_SAMPA_vs_TIME->GetYaxis()->SetTitleSize(0.05);
0753   DC_SAMPA_vs_TIME->GetYaxis()->SetTitleOffset(1.0);
0754 
0755   // Packet type vs SAMPLE plots wtd. by ADC for Jin
0756   char Packet_type_vs_sample_ADC_title_str[256];
0757   char Packet_type_vs_sample_ADC_xtitle_str[256];
0758   sprintf(Packet_type_vs_sample_ADC_title_str, "Packet type vs sample, Sector # %i", ebdc_from_serverid(MonitorServerId()));
0759   Packet_Type_vs_sample_ADC = new TH2F("Packet_Type_vs_sample_ADC", Packet_type_vs_sample_ADC_title_str, 501, -0.5, 500.5, 7, 0, 7);
0760   for (int i = 0; i != 7; ++i)
0761   {
0762     Packet_Type_vs_sample_ADC->GetYaxis()->SetBinLabel(i + 1, label[i]);
0763   }
0764   sprintf(Packet_type_vs_sample_ADC_xtitle_str, "Sector %i: Time bin [1/17.5MHz]", ebdc_from_serverid(MonitorServerId()));
0765   Packet_Type_vs_sample_ADC->SetXTitle(Packet_type_vs_sample_ADC_xtitle_str);
0766 
0767   Packet_Type_vs_sample_ADC->GetXaxis()->SetLabelSize(0.08);
0768   Packet_Type_vs_sample_ADC->GetYaxis()->SetLabelSize(0.08);
0769   Packet_Type_vs_sample_ADC->GetYaxis()->SetTitleSize(0.08);
0770   Packet_Type_vs_sample_ADC->GetYaxis()->SetTitleOffset(0.6);
0771 
0772   OnlMonServer *se = OnlMonServer::instance();
0773   // register histograms with server otherwise client won't get them
0774   se->registerHisto(this, NorthSideADC);
0775   se->registerHisto(this, SouthSideADC);
0776   se->registerHisto(this, sample_size_hist);
0777   se->registerHisto(this, Check_Sum_Error);
0778   se->registerHisto(this, Parity_Error);
0779   se->registerHisto(this, Check_Sums);
0780   se->registerHisto(this, Stuck_Channels);
0781   se->registerHisto(this, Channels_in_Packet);
0782   se->registerHisto(this, Channels_Always);
0783   se->registerHisto(this, LVL_1_TAGGER_per_EBDC);
0784   se->registerHisto(this, Num_non_ZS_channels_vs_SAMPA);
0785   se->registerHisto(this, ZS_Trigger_ADC_vs_Sample);
0786   se->registerHisto(this, First_ADC_vs_First_Time_Bin);
0787   se->registerHisto(this, ADC_vs_SAMPLE);
0788   se->registerHisto(this, PEDEST_SUB_ADC_vs_SAMPLE);
0789   se->registerHisto(this, PEDEST_SUB_ADC_vs_SAMPLE_R1);
0790   se->registerHisto(this, PEDEST_SUB_ADC_vs_SAMPLE_R2);
0791   se->registerHisto(this, PEDEST_SUB_ADC_vs_SAMPLE_R3);
0792   se->registerHisto(this, ADC_vs_SAMPLE_large);
0793   se->registerHisto(this, MAXADC);
0794   se->registerHisto(this, RAWADC_1D_R1);
0795   se->registerHisto(this, MAXADC_1D_R1);
0796   se->registerHisto(this, PEDEST_SUB_1D_R1);
0797   se->registerHisto(this, COUNTS_vs_SAMPLE_1D_R1);
0798   se->registerHisto(this, RAWADC_1D_R2);
0799   se->registerHisto(this, MAXADC_1D_R2);
0800   se->registerHisto(this, PEDEST_SUB_1D_R2);
0801   se->registerHisto(this, COUNTS_vs_SAMPLE_1D_R2);
0802   se->registerHisto(this, RAWADC_1D_R3);
0803   se->registerHisto(this, MAXADC_1D_R3);
0804   se->registerHisto(this, PEDEST_SUB_1D_R3);
0805   se->registerHisto(this, COUNTS_vs_SAMPLE_1D_R3);
0806 
0807   se->registerHisto(this, NorthSideADC_clusterXY_R1);
0808   se->registerHisto(this, NorthSideADC_clusterXY_R2);
0809   se->registerHisto(this, NorthSideADC_clusterXY_R3);
0810 
0811   se->registerHisto(this, SouthSideADC_clusterXY_R1);
0812   se->registerHisto(this, SouthSideADC_clusterXY_R2);
0813   se->registerHisto(this, SouthSideADC_clusterXY_R3);
0814 
0815   se->registerHisto(this, NorthSideADC_clusterXY_R1_unw);
0816   se->registerHisto(this, NorthSideADC_clusterXY_R2_unw);
0817   se->registerHisto(this, NorthSideADC_clusterXY_R3_unw);
0818 
0819   se->registerHisto(this, SouthSideADC_clusterXY_R1_unw);
0820   se->registerHisto(this, SouthSideADC_clusterXY_R2_unw);
0821   se->registerHisto(this, SouthSideADC_clusterXY_R3_unw);
0822 
0823   se->registerHisto(this, NorthSideADC_clusterXY_R1_LASER);
0824   se->registerHisto(this, NorthSideADC_clusterXY_R2_LASER);
0825   se->registerHisto(this, NorthSideADC_clusterXY_R3_LASER);
0826 
0827   se->registerHisto(this, SouthSideADC_clusterXY_R1_LASER);
0828   se->registerHisto(this, SouthSideADC_clusterXY_R2_LASER);
0829   se->registerHisto(this, SouthSideADC_clusterXY_R3_LASER);
0830 
0831   se->registerHisto(this, NorthSideADC_clusterXY_R1_u5);
0832   se->registerHisto(this, NorthSideADC_clusterXY_R2_u5);
0833   se->registerHisto(this, NorthSideADC_clusterXY_R3_u5);
0834 
0835   se->registerHisto(this, SouthSideADC_clusterXY_R1_u5);
0836   se->registerHisto(this, SouthSideADC_clusterXY_R2_u5);
0837   se->registerHisto(this, SouthSideADC_clusterXY_R3_u5);
0838 
0839   se->registerHisto(this, NorthSideADC_clusterZY);
0840   se->registerHisto(this, SouthSideADC_clusterZY);
0841 
0842   se->registerHisto(this, NorthSideADC_clusterZY_unw);
0843   se->registerHisto(this, SouthSideADC_clusterZY_unw);
0844 
0845   se->registerHisto(this, Layer_ChannelPhi_ADC_weighted);
0846   se->registerHisto(this, NEvents_vs_EBDC);
0847   se->registerHisto(this, NStreaks_vs_EventNo);
0848   se->registerHisto(this, Packet_Type_Fraction_HB);
0849   se->registerHisto(this, Packet_Type_Fraction_NORM);
0850   se->registerHisto(this, Packet_Type_Fraction_ELSE);
0851   se->registerHisto(this, Packet_Type_vs_sample_ADC);
0852 
0853   se->registerHisto(this, Noise_Channel_Plots);
0854   se->registerHisto(this, DC_vs_SAMPA);
0855   se->registerHisto(this, DC_SAMPA_vs_TIME);
0856 
0857   Reset();
0858   return 0;
0859 }
0860 
0861 int TpcMon::BeginRun(const int /* runno */)
0862 {
0863   // if you need to read calibrations on a run by run basis
0864   // this is the place to do it
0865 
0866   // we reset the BCO for the new run
0867   starting_BCO = -1;
0868   rollover_value = 0;
0869   current_BCOBIN = 0;
0870 
0871   return 0;
0872 }
0873 
0874 int TpcMon::process_event(Event *evt /* evt */)
0875 {
0876   // std::cout << "TpcMon::process_event(Event * evt) Processing Event" << std::endl;
0877 
0878   if (evt == nullptr)
0879   {
0880     std::cout << "TpcMon::process_event - Event not found" << std::endl;
0881     return -1;
0882   }
0883 
0884   if (evt->getEvtType() >= 8)  /// special events
0885   {
0886     std::cout << "TpcMon::process_event - Special Event type >= 8, moving on" << std::endl;
0887     return -1;
0888   }
0889 
0890   // reset these each event
0891   float North_Side_Arr[36] = {0};
0892   float South_Side_Arr[36] = {0};
0893 
0894   std::vector<int> store_ten;
0895   std::vector<int> median_and_stdev_vec;
0896 
0897   // we check if we have legacy data and start with packet 4000
0898   // the range for the TPC is really 4001...4032
0899   // we assume we start properly at 4001, but check if not
0900 
0901   //  int firstpacket=4000;
0902   // if (evt->existPacket(4000))
0903   //{
0904   // Packet *p = evt->getPacket(4000);
0905   // if(evt->getPacket(4000))
0906   // {
0907   //   Packet *p = evt->getPacket(4000);
0908   //   if (p->getHitFormat() == IDTPCFEEV3 || p->getHitFormat() == IDTPCFEEV4) firstpacket = 4000;
0909   //   delete p;
0910   // }
0911   //}
0912   //  int lastpacket = firstpacket+232;
0913 
0914   NEvents_vs_EBDC->Fill(ebdc_from_serverid(MonitorServerId()));
0915   // std::cout<<"Event #"<< evtcnt <<std::endl;
0916 
0917   std::vector<Packet *> pktvec = evt->getPacketVector();
0918   //  if( evtcnt >= 1200 ){ //evtcnt debug
0919   // for( int packet = firstpacket; packet < lastpacket; packet++) //packet 4001 or 4002 = Sec 00, packet 4231 or 4232 = Sec 23
0920   for (auto p : pktvec)
0921   {
0922     //    Packet* p = evt->getPacket(packet);
0923     if (!p)
0924     {
0925       // std::cout << "TpcMon::process_event - No packet numbered " << packet << " in this event!!" << std::endl;
0926       continue;
0927     }
0928     else
0929     {
0930       // std::cout << "____________________________________" << std::endl;
0931       // std::cout << "Packet # " << packet << std::endl;
0932       int nr_of_waveforms = p->iValue(0, "NR_WF");
0933 
0934       //________________________________________________________________________________
0935 
0936       // digital current loop
0937       // std::cout<<"NR_DC = "<<p->iValue(0,"NR_DC")<<std::endl;
0938       if (p->iValue(0, "NR_DC") != 0)  // && evtcnt > 9000)
0939       {
0940         // std::cout<<"NR_DC = "<<p->iValue(0,"NR_DC")<<std::endl;
0941         for (int i = 0; i < p->iValue(0, "NR_DC"); i++)
0942         {
0943           // std::cout<<"_____________________________"<<std::endl;
0944           // std::cout<<"TYPE_DC = "<<p->iValue(i,"TYPE_DC")<<std::endl;
0945           // std::cout<<"CRC ERROR = "<<p->iValue(i,"CHECKSUMERROR_DC")<<std::endl;
0946           // std::cout<<"rollover BCO = "<<rollover_value_DC<<std::endl;
0947           // std::cout<<"Starting BCO = "<<starting_BCO_DC<<std::endl;
0948           // std::cout<<"RAW BCO = " <<p->iValue(i,"BCO_DC")<<std::endl;
0949 
0950           int current_BCO_DC = p->iValue(i, "BCO_DC") + rollover_value_DC;
0951           if (starting_BCO_DC < 0)
0952           {
0953             starting_BCO_DC = p->iValue(i, "BCO_DC");
0954           }
0955           // int conv_starting_BCO_DC = starting_BCO_DC; //no rollover
0956           // if( current_BCO_DC < conv_starting_BCO_DC ) //no rollover
0957           /*
0958           if(current_BCO_DC < starting_BCO_DC ) //rollover
0959           {
0960             //std::cout<<"you had a rollover"<<std::endl;
0961             rollover_value_DC += 0x100000;
0962             current_BCO_DC = p->iValue(i,"BCO_DC") + rollover_value_DC;
0963             starting_BCO_DC =  p->iValue(i,"BCO_DC") + rollover_value_DC;
0964           }
0965           */
0966           // starting_BCO_DC =  p->iValue(i,"BCO_DC") + rollover_value_DC; //no rollover
0967           // std::cout<<"Corrected BCO = "<<current_BCO_DC<<std::endl;
0968 
0969           for (int j = 0; j < 8; j++)
0970           {
0971             if ((p->iValue(i, j + 1040) != 0 && p->iValue(i, "CHECKSUMERROR_DC") == 0))
0972             {
0973               // std::cout<<"FEE = "<<p->iValue(i,"FEE_DC")<<", SAMPA = "<<j<<", DC = "<<p->iValue(i,j+1030) - 60*p->iValue(i,j+1040)<<", BIN_SUM = "<<p->iValue(i,j+1040)<<std::endl;
0974               DC_vs_SAMPA->Fill(j + (8 * FEE_transform[p->iValue(i, "FEE_DC")]), p->iValue(i, j + 1030) - 60 * p->iValue(i, j + 1040));
0975               DC_SAMPA_vs_TIME->Fill(current_BCO_DC, j + (8 * FEE_transform[p->iValue(i, "FEE_DC")]), p->iValue(i, j + 1030) - 60 * p->iValue(i, j + 1040));
0976             }
0977           }
0978           // std::cout<<"_____________________________"<<std::endl;
0979         }
0980       }  // end DC loop
0981 
0982       //________________________________________________________________________________
0983 
0984       // std::cout << "Hello Waveforms ! - There are " << nr_of_waveforms << " of you !" << std::endl;
0985 
0986       bool is_channel_stuck = 0;
0987 
0988       for (int ci = 0; ci < 6656; ci++)
0989       {
0990         Channels_Always->Fill(ci);
0991       }
0992 
0993       for (int wf = 0; wf < nr_of_waveforms; wf++)
0994       {
0995         // std::cout<<"START OF WF LOOP, "<<"current wf = "<<wf<<", total wf = "<<nr_of_waveforms<<" EVENT "<<evtcnt<<std::endl;
0996         int current_BCO = p->iValue(wf, "BCO") + rollover_value;
0997         if (starting_BCO < 0)
0998         {
0999           starting_BCO = current_BCO;
1000         }
1001 
1002         if (current_BCO < starting_BCO)  // we have a rollover
1003         {
1004           rollover_value += 0x100000;
1005           current_BCO = p->iValue(wf, "BCO") + rollover_value;
1006           starting_BCO = current_BCO;
1007           current_BCOBIN++;
1008         }
1009 
1010         int type = p->iValue(wf, "TYPE");
1011         switch (type)
1012         {
1013         case 0:
1014           Packet_Type_Fraction_HB->Fill(0.5);  // HEARTBEAT_T 0b000
1015           break;
1016         case 1:
1017           Packet_Type_Fraction_ELSE->Fill(1.5);  // TRUNCATED_DATA_T 0b001
1018           break;
1019         case 3:
1020           Packet_Type_Fraction_ELSE->Fill(2.5);  // TRUNCATED_TRIG_EARLY_DATA_T 0b011
1021           break;
1022         case 4:
1023           Packet_Type_Fraction_NORM->Fill(3.5);  // NORMAL_DATA_T 0b100
1024           break;
1025         case 5:
1026           Packet_Type_Fraction_ELSE->Fill(4.5);  // LARGE_DATA_T 0b101
1027           break;
1028         case 6:
1029           Packet_Type_Fraction_ELSE->Fill(5.5);  // TRIG_EARLY_DATA_T 0b110
1030           break;
1031         case 7:
1032           Packet_Type_Fraction_ELSE->Fill(6.5);  // TRIG_EARLY_LARGE_DATA_T 0b111
1033           break;
1034         default:
1035           std::cout << "unhandled type: " << type << std::endl;
1036           break;
1037         }
1038         // if( p->iValue(wf,"TYPE")==0 ){Packet_Type_Fraction_HB->Fill(0.5);} //HEARTBEAT_T 0b000
1039         // if( p->iValue(wf,"TYPE")==1 ){Packet_Type_Fraction_ELSE->Fill(1.5);} //TRUNCATED_DATA_T 0b001
1040         // if( p->iValue(wf,"TYPE")==3 ){Packet_Type_Fraction_ELSE->Fill(2.5);} //TRUNCATED_TRIG_EARLY_DATA_T 0b011
1041         // if( p->iValue(wf,"TYPE")==4 ){Packet_Type_Fraction_NORM->Fill(3.5);} //NORMAL_DATA_T 0b100
1042         // if( p->iValue(wf,"TYPE")==5 ){Packet_Type_Fraction_ELSE->Fill(4.5);} //LARGE_DATA_T 0b101
1043         // if( p->iValue(wf,"TYPE")==6 ){Packet_Type_Fraction_ELSE->Fill(5.5);} //TRIG_EARLY_DATA_T 0b110
1044         // if( p->iValue(wf,"TYPE")==7 ){Packet_Type_Fraction_ELSE->Fill(6.5);} //TRIG_EARLY_LARGE_DATA_T 0b111
1045 
1046         const int n_tagger = p->lValue(0, "N_TAGGER");
1047         for (int t = 0; t < n_tagger; t++)
1048         {
1049           const bool is_lvl1_tagger(static_cast<uint8_t>(p->lValue(t, "IS_LEVEL1_TRIGGER")));
1050           if (is_lvl1_tagger)
1051           {
1052             LVL_1_TAGGER_per_EBDC->Fill(ebdc_from_serverid(MonitorServerId()));
1053           }
1054         }
1055 
1056         int fee = p->iValue(wf, "FEE");
1057         int sampaAddress = p->iValue(wf, "SAMPAADDRESS");
1058         int checksumError = p->iValue(wf, "CHECKSUMERROR");
1059         int parityError = p->iValue(wf, "DATAPARITYERROR");
1060         int channel = p->iValue(wf, "CHANNEL");
1061 
1062         if (p->iValue(wf, "TYPE") != 0)
1063         {
1064           Check_Sums->Fill(FEE_transform[fee] * 8 + sampaAddress);
1065           if (checksumError == 1)
1066           {
1067             Check_Sum_Error->Fill(FEE_transform[fee] * 8 + sampaAddress);
1068           }
1069           if (parityError == 1)
1070           {
1071             Parity_Error->Fill(FEE_transform[fee] * 8 + sampaAddress);
1072           }
1073         }
1074 
1075         if ((checksumError == 0 && parityError == 0) && p->iValue(wf, "TYPE") != 0)
1076         {
1077           Channels_in_Packet->Fill(channel + (256 * FEE_transform[fee]));
1078         }  // do not fill for heartbeat WFs
1079 
1080         int nr_Samples = p->iValue(wf, "SAMPLES");
1081         sample_size_hist->Fill(nr_Samples);
1082 
1083         // clockwise FEE mapping
1084         // int FEE_map[26]={5, 6, 1, 3, 2, 12, 10, 11, 9, 8, 7, 1, 2, 4, 8, 7, 6, 5, 4, 3, 1, 3, 2, 4, 6, 5};
1085         int FEE_R[26] = {2, 2, 1, 1, 1, 3, 3, 3, 3, 3, 3, 2, 2, 1, 2, 2, 1, 1, 2, 2, 3, 3, 3, 3, 3, 3};
1086         // counter clockwise FEE mapping (From Takao - DEPRECATED AS OF 08.29)
1087         // int FEE_map[26]={3, 2, 5, 3, 4, 0, 2, 1, 3, 4, 5, 7, 6, 2, 0, 1, 0, 1, 4, 5, 11, 9, 10, 8, 6, 7};
1088 
1089         // FEE mapping from Jin
1090         int FEE_map[26] = {4, 5, 0, 2, 1, 11, 9, 10, 8, 7, 6, 0, 1, 3, 7, 6, 5, 4, 3, 2, 0, 2, 1, 3, 5, 4};
1091 
1092         // int pads_per_sector[3] = {96, 128, 192};
1093 
1094         serverid = ebdc_from_serverid(MonitorServerId());
1095 
1096         // setting the mapp of the FEE
1097         int feeM = FEE_map[fee];
1098         if (FEE_R[fee] == 2) feeM += 6;
1099         if (FEE_R[fee] == 3) feeM += 14;
1100 
1101         // getting R and Phi coordinates
1102         double R = M.getR(feeM, channel);
1103         double padphi = 0;
1104 
1105         if (side(serverid) == 0)  // NS
1106         {
1107           padphi = M.getPad(feeM, channel) + (serverid) * (2304. / 12.);
1108         }
1109         else if (side(serverid) == 1)  // SS
1110         {
1111           padphi = -M.getPad(feeM, channel) - (serverid - 12) * (2304. / 12);
1112         }
1113 
1114         int layer = M.getLayer(feeM, channel) + (serverid);
1115         double phi = 0;
1116 
1117         // double phi = M.getPhi(feeM, channel) + (serverid - 12*side(serverid)) * M_PI / 6 ;
1118 
1119         // Evgeny Map
1120         if (side(serverid) == 0)  // NS
1121         {
1122           phi = M.getPhi(feeM, channel) + (serverid) *M_PI / 6;
1123         }
1124         else if (side(serverid) == 1)  // SS
1125         {
1126           phi = M.getPhi(feeM, channel) + (18 - serverid) * M_PI / 6;
1127         }
1128 
1129         /*
1130         //Mariia map
1131         if( side(serverid) == 0 ) //NS
1132         {
1133           phi = M.getPhi(feeM, channel) + (serverid ) * M_PI / 6    - (M_PI/2.) ;
1134         }
1135         else if( side(serverid) == 1 ) //SS
1136         {
1137           phi = M.getPhi(feeM, channel) + (18 - serverid ) * M_PI / 6 - (- M_PI/2.) ;
1138         }
1139         */
1140         // std::cout<<"Sector = "<< serverid <<" FEE = "<<fee<<" channel = "<<channel<<std::endl;
1141 
1142         // int mid = floor(360/2); //get median sample from 0-360 (we are assuming the sample > 360 is not useful to us as of 05.01.24)
1143         int num_of_nonZS_samples = 0;  // start counter from 0
1144 
1145         int tr_samp = 0;
1146         int start_flag = 0;
1147         int prev_sample = 65000;
1148         int first_non_ZS_sample = 1;
1149 
1150         if (nr_Samples > 0)
1151         {
1152           // if( (p->iValue(wf,mid) == p->iValue(wf,mid-1)) && (p->iValue(wf,mid) == p->iValue(wf,mid-2)) && (p->iValue(wf,mid) == p->iValue(wf,mid+1)) && (p->iValue(wf,mid) == p->iValue(wf,mid+2)) )
1153           //{
1154           // is_channel_stuck = 1;
1155           // }
1156 
1157           for (int si = 0; si < nr_Samples; si++)  // get pedestal and noise before hand
1158           {
1159             if ((p->iValue(wf, si)) < 1025 && prev_sample > 64500)  // start condition to record
1160             {
1161               start_flag = 1;
1162               if (first_non_ZS_sample == 1)
1163               {
1164                 First_ADC_vs_First_Time_Bin->Fill(si, (p->iValue(wf, si)));
1165                 first_non_ZS_sample = 0;
1166               }  // this is the first sample, its all we want
1167             }
1168             if ((p->iValue(wf, si)) > 64500 && prev_sample < 1025)
1169             {
1170               tr_samp = 0;
1171               start_flag = 0;
1172               prev_sample = (p->iValue(wf, si));
1173             }  // end condition to record
1174             if (start_flag == 1)
1175             {
1176               ZS_Trigger_ADC_vs_Sample->Fill(tr_samp, p->iValue(wf, si));
1177               tr_samp++;
1178               prev_sample = p->iValue(wf, si);
1179             }  // record the ZS trigger histo if you should
1180 
1181             if ((p->iValue(wf, si)) > 64500 && si > 1023)
1182             {
1183               break;
1184             }  // for new firmware/ZS mode - we don't entries w/ ADC > 65 K after 1023 (50 us window), that's nonsense - per Jin's suggestion once you see this, BREAK out of loop
1185             if ((p->iValue(wf, si)) > 64500)
1186             {
1187               continue;
1188             }  // only use reasonable values to calculate median
1189             median_and_stdev_vec.push_back(p->iValue(wf, si));
1190             num_of_nonZS_samples++;
1191           }
1192         }  // Compare 5 values to determine stuck !!
1193 
1194         Num_non_ZS_channels_vs_SAMPA->Fill(sampaAddress + (8 * FEE_transform[fee]), num_of_nonZS_samples);
1195 
1196         if (median_and_stdev_vec.size() == 0)  // if all waveform values were 65 K
1197         {
1198           // std::cout<<"All values skipped, Event # "<<evtcnt<<std::endl;
1199           is_channel_stuck = 0;          // reset after looping through waveform samples
1200           store_ten.clear();             // clear this after every waveform
1201           median_and_stdev_vec.clear();  // clear this after every waveform
1202           continue;
1203         }
1204 
1205         std::pair<float, float> result = calculateMedianAndStdDev(median_and_stdev_vec);
1206         // std::cout<<"pedestal = "<<result.first<<", RMS = "<<result.second<<" ADC, fee: "<<fee<<", channel: "<<channel<<", layer: "<<layer<<", phi: "<<phi<<", event num: "<<evtcnt<<std::endl;
1207         float pedestal = result.first;  // average/pedestal -- based on MEDIAN OF ALL ENTRIES NOW, NOT MEAN OF FIRST 10 (02/12/24)
1208         float noise = result.second;    // stdev - BASED ON REASONABLE SIGMA OF ENTRIES THAT ARE +/- 40 ADC WITHIN PEDESTAL
1209 
1210         float rawnoise = calculateRawStdDev(median_and_stdev_vec);
1211 
1212         if (rawnoise == 0. && median_and_stdev_vec.size() > 1)
1213         {
1214           // for( int si=0;si < nr_Samples; si++ ){ std::cout<<"SAMPLE: "<<si<<", ADC: "<< p->iValue(wf,si) << std::endl; }
1215           stuck_channel_count[channel][FEE_transform[fee]]++;  // if the RMS is 0, this channel must be stuck
1216           if (stuck_channel_count[channel][FEE_transform[fee]] == 1)
1217           {
1218             Stuck_Channels->Fill(FEE_transform[fee]);
1219           }  // only count # of unique channels in FEE that get stuck at least once
1220           is_channel_stuck = 1;
1221         }
1222 
1223         int wf_max = 0;
1224         int t_max = 0;
1225 
1226         float pedest_sub_wf_max = 0.;
1227 
1228         int wf_max_laser_peak = 0;
1229         float pedest_sub_wf_max_laser_peak = 0.;
1230 
1231         int num_samples_over_threshold = 0;
1232 
1233         for (int s = 0; s < nr_Samples; s++)
1234         {
1235           // std::cout<<"MADE IT TO START OF sample LOOP, "<<"current sample = "<<s<<", total sample = "<<nr_Samples<<" EVENT "<<evtcnt<<std::endl;
1236           // int t = s + 2 * (current_BCO - starting_BCO);
1237 
1238           int adc = p->iValue(wf, s);
1239 
1240           if (((adc - pedestal) > 300 && (adc < 1500)) && s < 360)
1241           {
1242             // std::cout<<"FEE #: "<<fee<<", channel #: "<<channel<<", sample: "<<s<<", adc-pedestal: "<<(adc-pedestal)<<std::endl;
1243             Noise_Channel_Plots->Fill(channel + (256 * FEE_transform[fee]));
1244           }  // only intended to be looked at during pedestal runs with 360 time samples
1245 
1246           // std::cout<<"adc = "<<adc<<" ADC, FEE = "<<fee<<", channel: "<<channel<<", layer: "<<layer<<", phi: "<<phi<<", event num: "<<evtcnt<<std::endl;
1247 
1248           if (adc > 64500 && s > 1023)
1249           {
1250             break;
1251           }  // for new firmware/ZS mode - we don't entries w/ ADC > 65 K after 1023 (50 us), that's nonsense - per Jin's suggestion once you see this, BREAK out of loop
1252           else if (adc > 64500)
1253           {
1254             continue;
1255           }  // we do not care about 65K ADC entries - ignore them
1256 
1257           Layer_ChannelPhi_ADC_weighted->Fill(padphi, layer, adc - pedestal);
1258 
1259           if (adc > wf_max)
1260           {
1261             wf_max = adc;
1262             t_max = s;
1263             pedest_sub_wf_max = adc - pedestal;
1264           }
1265 
1266           if ((s > 362 && s < 374) && (adc > wf_max_laser_peak))
1267           {
1268             wf_max_laser_peak = adc;
1269             pedest_sub_wf_max_laser_peak = adc - pedestal;
1270           }  // old peak near 416, new peak near 403-404 wth 50 ns clock, 368 with 57.14 ns clock
1271 
1272           if ((store_ten.size() < 10))  // get first 10
1273           {
1274             store_ten.push_back(adc);
1275           }
1276           else
1277           {
1278             // nine_max = Max_Nine(p->iValue(wf,s-9),p->iValue(wf,s-8),p->iValue(wf,s-7),p->iValue(wf,s-6),p->iValue(wf,s-5),p->iValue(wf,s-4),p->iValue(wf,s-3),p->iValue(wf,s-2),p->iValue(wf,s-1)); //take the previous 9 numbers
1279 
1280             // VERY IMPORTANT, erase first entry, push_back current
1281             store_ten.erase(store_ten.begin());
1282             store_ten.push_back(adc);
1283 
1284             int max_of_previous_10 = *max_element(store_ten.begin(), store_ten.end());
1285 
1286             if ((adc == max_of_previous_10 && checksumError == 0) && (parityError == 0 && is_channel_stuck == 0))  // if the new value is greater than the previous 9
1287             {
1288               MAXADC->Fill(adc - pedestal, Module_ID(fee));
1289               if (Module_ID(fee) == 0)
1290               {
1291                 MAXADC_1D_R1->Fill(adc - pedestal);
1292               }  // Raw 1D for R1
1293               else if (Module_ID(fee) == 1)
1294               {
1295                 MAXADC_1D_R2->Fill(adc - pedestal);
1296               }  // Raw 1D for R2
1297               else if (Module_ID(fee) == 2)
1298               {
1299                 MAXADC_1D_R3->Fill(adc - pedestal);
1300               }  // Raw 1D for R3
1301             }
1302           }
1303 
1304           // if( R < 290 ){std::cout<<"R = "<<R<<" mm, layer:" <<layer<<std::endl; ADC_vs_SAMPLE -> Fill(s, adc);}
1305 
1306           if ((checksumError == 0 && parityError == 0) && is_channel_stuck == 0)
1307           {
1308             Packet_Type_vs_sample_ADC->Fill(s, type, adc);
1309             ADC_vs_SAMPLE->Fill(s, adc);
1310             PEDEST_SUB_ADC_vs_SAMPLE->Fill(s, adc - pedestal);
1311             ADC_vs_SAMPLE_large->Fill(s, adc);
1312 
1313             if (Module_ID(fee) == 0)
1314             {
1315               RAWADC_1D_R1->Fill(adc);
1316               PEDEST_SUB_1D_R1->Fill(adc - pedestal);
1317               PEDEST_SUB_ADC_vs_SAMPLE_R1->Fill(s, adc - pedestal);
1318             }  // Raw/pedest_sub 1D for R1
1319             if (Module_ID(fee) == 1)
1320             {
1321               RAWADC_1D_R2->Fill(adc);
1322               PEDEST_SUB_1D_R2->Fill(adc - pedestal);
1323               PEDEST_SUB_ADC_vs_SAMPLE_R2->Fill(s, adc - pedestal);
1324             }  // Raw/pedest_sub 1D for R2
1325             if (Module_ID(fee) == 2)
1326             {
1327               RAWADC_1D_R3->Fill(adc);
1328               PEDEST_SUB_1D_R3->Fill(adc - pedestal);
1329               PEDEST_SUB_ADC_vs_SAMPLE_R3->Fill(s, adc - pedestal);
1330             }  // Raw/pedest_sub 1D for R3
1331 
1332             if (Module_ID(fee) == 0 && ((adc - pedestal) > std::max(5.0 * noise, 20.)) && layer != 0)
1333             {
1334               COUNTS_vs_SAMPLE_1D_R1->Fill(s);
1335             }  // Drift window in R1
1336             if (Module_ID(fee) == 1 && ((adc - pedestal) > std::max(5.0 * noise, 20.)) && layer != 0)
1337             {
1338               COUNTS_vs_SAMPLE_1D_R2->Fill(s);
1339             }  // Drift window in R2
1340             if (Module_ID(fee) == 2 && ((adc - pedestal) > std::max(5.0 * noise, 20.)) && layer != 0)
1341             {
1342               COUNTS_vs_SAMPLE_1D_R3->Fill(s);
1343             }  // Drift window in R3
1344 
1345             // if(Module_ID(fee)==0 && (layer != 0)){COUNTS_vs_SAMPLE_1D_R1->Fill(s);} //Drift window in R1
1346             // if(Module_ID(fee)==1 && (layer != 0)){COUNTS_vs_SAMPLE_1D_R2->Fill(s);} //Drift window in R2
1347             // if(Module_ID(fee)==2 && (layer != 0)){COUNTS_vs_SAMPLE_1D_R3->Fill(s);} //Drift window in R3
1348 
1349             if ((adc - pedestal) > 25)
1350             {
1351               num_samples_over_threshold++;
1352             }
1353           }
1354 
1355           // increment
1356           if (serverid >= 0 && serverid < 12)
1357           {
1358             North_Side_Arr[Index_from_Module(serverid, fee)] += adc;
1359           }
1360           else
1361           {
1362             South_Side_Arr[Index_from_Module(serverid, fee) - 36] += adc;
1363           }
1364 
1365           // std::cout<<"MADE IT TO END OF sample LOOP, "<<"current sample = "<<s<<", total sample = "<<nr_Samples<<" EVENT "<<evtcnt<<std::endl;
1366         }  // nr samples
1367 
1368         // for streaker diagnostic:
1369         if (num_samples_over_threshold > 15)
1370         {
1371           NStreaks_vs_EventNo->Fill(evtcnt);
1372         }
1373 
1374         // for complicated XY stuff ____________________________________________________
1375         // 20 = 3-5 * sigma - hard-coded
1376         //  OR 10*noise = 10 sigma
1377 
1378         float z = 0;  // mm
1379 
1380         if ((serverid < 12 && (pedest_sub_wf_max) > std::max(5.0 * noise, 20.)) && layer != 0)
1381         {
1382           if (Module_ID(fee) == 0)
1383           {
1384             NorthSideADC_clusterXY_R1->Fill(R * cos(phi), R * sin(phi), pedest_sub_wf_max);
1385             NorthSideADC_clusterXY_R1_unw->Fill(R * cos(phi), R * sin(phi));
1386           }  // Raw 1D for R1
1387           else if (Module_ID(fee) == 1)
1388           {
1389             NorthSideADC_clusterXY_R2->Fill(R * cos(phi), R * sin(phi), pedest_sub_wf_max);
1390             NorthSideADC_clusterXY_R2_unw->Fill(R * cos(phi), R * sin(phi));
1391           }  // Raw 1D for R2
1392           else if (Module_ID(fee) == 2)
1393           {
1394             NorthSideADC_clusterXY_R3->Fill(R * cos(phi), R * sin(phi), pedest_sub_wf_max);
1395             NorthSideADC_clusterXY_R3_unw->Fill(R * cos(phi), R * sin(phi));
1396           }  // Raw 1D for R3
1397 
1398           // old gas (Ar:CF4 - 60:40)
1399           // if( t_max >= 10 && t_max <=255 ){z = 1030 - (t_max - 10)*(50 * 0.084);NorthSideADC_clusterZY->Fill(z,R*sin(phi),pedest_sub_wf_max);NorthSideADC_clusterZY_unw->Fill(z,R*sin(phi));}
1400           // new gas (Ar:CF4:ISO - 75:20:5)
1401           // if( t_max >= 40 && t_max <=320 ){z = 1030 - (t_max - 40)*(50 * 0.0735);NorthSideADC_clusterZY->Fill(z,R*sin(phi),pedest_sub_wf_max);NorthSideADC_clusterZY_unw->Fill(z,R*sin(phi));}//50 clock
1402           if (t_max >= 50 && t_max <= 330)
1403           {
1404             z = 1030 - (t_max - 50) * (57.14 * 0.0735);
1405             NorthSideADC_clusterZY->Fill(z, R * sin(phi), pedest_sub_wf_max);
1406             NorthSideADC_clusterZY_unw->Fill(z, R * sin(phi));
1407           }  // 57 clock
1408         }
1409         else if ((serverid >= 12 && (pedest_sub_wf_max) > std::max(5.0 * noise, 20.)) && layer != 0)
1410         {
1411           if (Module_ID(fee) == 0)
1412           {
1413             SouthSideADC_clusterXY_R1->Fill(R * cos(phi), R * sin(phi), pedest_sub_wf_max);
1414             SouthSideADC_clusterXY_R1_unw->Fill(R * cos(phi), R * sin(phi));
1415           }  // Raw 1D for R1
1416           else if (Module_ID(fee) == 1)
1417           {
1418             SouthSideADC_clusterXY_R2->Fill(R * cos(phi), R * sin(phi), pedest_sub_wf_max);
1419             SouthSideADC_clusterXY_R2_unw->Fill(R * cos(phi), R * sin(phi));
1420           }  // Raw 1D for R2
1421           else if (Module_ID(fee) == 2)
1422           {
1423             SouthSideADC_clusterXY_R3->Fill(R * cos(phi), R * sin(phi), pedest_sub_wf_max);
1424             SouthSideADC_clusterXY_R3_unw->Fill(R * cos(phi), R * sin(phi));
1425           }  // Raw 1D for R3
1426 
1427           // old gas (Ar:CF4 - 60:40)
1428           // if( t_max >= 10 && t_max <=255 ){z = -1030 + (t_max - 10)*(50 * 0.084);SouthSideADC_clusterZY->Fill(z,R*sin(phi),pedest_sub_wf_max);SouthSideADC_clusterZY_unw->Fill(z,R*sin(phi));}
1429           // new gas (Ar:CF4:ISO - 75:20:5)
1430           // if( t_max >= 40 && t_max <=320 ){z = -1030 + (t_max - 40)*(50 * 0.0735);SouthSideADC_clusterZY->Fill(z,R*sin(phi),pedest_sub_wf_max);SouthSideADC_clusterZY_unw->Fill(z,R*sin(phi));}//50 clock
1431           if (t_max >= 50 && t_max <= 330)
1432           {
1433             z = -1030 + (t_max - 50) * (57.14 * 0.0735);
1434             SouthSideADC_clusterZY->Fill(z, R * sin(phi), pedest_sub_wf_max);
1435             SouthSideADC_clusterZY_unw->Fill(z, R * sin(phi));
1436           }  // 57 clock
1437         }
1438         //________________________________________________________________________________
1439         // XY laser peak
1440         if ((serverid < 12 && (pedest_sub_wf_max_laser_peak) > std::max(5.0 * noise, 20.)) && ((t_max > 362 && t_max < 374) && (layer != 0)))  // only fill if the laser was the max old peak 416, new 403 w/ 50 clock, 368 w/ 57.14 clock
1441         {
1442           if (Module_ID(fee) == 0)
1443           {
1444             NorthSideADC_clusterXY_R1_LASER->Fill(R * cos(phi), R * sin(phi), pedest_sub_wf_max_laser_peak);
1445           }  // Raw 1D for R1
1446           else if (Module_ID(fee) == 1)
1447           {
1448             NorthSideADC_clusterXY_R2_LASER->Fill(R * cos(phi), R * sin(phi), pedest_sub_wf_max_laser_peak);
1449           }  // Raw 1D for R2
1450           else if (Module_ID(fee) == 2)
1451           {
1452             NorthSideADC_clusterXY_R3_LASER->Fill(R * cos(phi), R * sin(phi), pedest_sub_wf_max_laser_peak);
1453           }  // Raw 1D for R3
1454         }
1455         else if ((serverid >= 12 && (pedest_sub_wf_max_laser_peak) > std::max(5.0 * noise, 20.)) && ((t_max > 362 && t_max < 374) && (layer != 0)))  // only fill if the laser was the max old peak 416, new 403 w/ 50 clock, 368 w/ 57.14 clock
1456         {
1457           if (Module_ID(fee) == 0)
1458           {
1459             SouthSideADC_clusterXY_R1_LASER->Fill(R * cos(phi), R * sin(phi), pedest_sub_wf_max_laser_peak);
1460           }  // Raw 1D for R1
1461           else if (Module_ID(fee) == 1)
1462           {
1463             SouthSideADC_clusterXY_R2_LASER->Fill(R * cos(phi), R * sin(phi), pedest_sub_wf_max_laser_peak);
1464           }  // Raw 1D for R2
1465           else if (Module_ID(fee) == 2)
1466           {
1467             SouthSideADC_clusterXY_R3_LASER->Fill(R * cos(phi), R * sin(phi), pedest_sub_wf_max_laser_peak);
1468           }  // Raw 1D for R3
1469         }
1470         //________________________________________________________________________________
1471         // 5 event displays
1472         if ((serverid < 12 && (pedest_sub_wf_max) > std::max(5.0 * noise, 20.)) && layer != 0)
1473         {
1474           if (Module_ID(fee) == 0)
1475           {
1476             NorthSideADC_clusterXY_R1_u5->Fill(R * cos(phi), R * sin(phi));
1477           }  // Raw 1D for R1
1478           else if (Module_ID(fee) == 1)
1479           {
1480             NorthSideADC_clusterXY_R2_u5->Fill(R * cos(phi), R * sin(phi));
1481           }  // Raw 1D for R2
1482           else if (Module_ID(fee) == 2)
1483           {
1484             NorthSideADC_clusterXY_R3_u5->Fill(R * cos(phi), R * sin(phi));
1485           }  // Raw 1D for R3
1486         }
1487         if ((serverid >= 12 && (pedest_sub_wf_max) > std::max(5.0 * noise, 20.)) && layer != 0)
1488         {
1489           if (Module_ID(fee) == 0)
1490           {
1491             SouthSideADC_clusterXY_R1_u5->Fill(R * cos(phi), R * sin(phi));
1492           }  // Raw 1D for R1
1493           else if (Module_ID(fee) == 1)
1494           {
1495             SouthSideADC_clusterXY_R2_u5->Fill(R * cos(phi), R * sin(phi));
1496           }  // Raw 1D for R2
1497           else if (Module_ID(fee) == 2)
1498           {
1499             SouthSideADC_clusterXY_R3_u5->Fill(R * cos(phi), R * sin(phi));
1500           }  // Raw 1D for R3
1501         }
1502         //________________________________________________________________________________
1503 
1504         is_channel_stuck = 0;  // reset after looping through waveform samples
1505 
1506         store_ten.clear();  // clear this after every waveform
1507 
1508         median_and_stdev_vec.clear();  // clear this after every waveform
1509         // std::cout<<"MADE IT TO END OF WF LOOP, "<<"current wf = "<<wf<<", total wf = "<<nr_of_waveforms<<" EVENT "<<evtcnt<<std::endl;
1510 
1511       }  // nr waveforms
1512       // std::cout<<"ABOUT TO DELETE THE EXISTING PACKET, EVENT # "<<evtcnt<<std::endl;
1513       delete p;
1514       // std::cout<<"JUST DELETETED THE EXISTING PACKET, EVENT # "<<evtcnt<<std::endl;
1515     }  // if packet exists
1516     // std::cout<<"MADE IT TO END OF PACKET LOOP, EVENT # "<<evtcnt<<std::endl;
1517   }  // end of packet loop
1518   //} //debug if evt >=1203
1519   evtcnt++;
1520   if (evtcnt5 < 5)  // increment 5 event counter for 5 events
1521   {
1522     evtcnt5++;
1523   }
1524   else if (evtcnt5 >= 5)  // reset to to 0 when get to event 5 (6th event starting from 0)
1525   {
1526     evtcnt5 = 0;
1527     NorthSideADC_clusterXY_R1_u5->Reset();
1528     NorthSideADC_clusterXY_R2_u5->Reset();
1529     NorthSideADC_clusterXY_R3_u5->Reset();
1530 
1531     SouthSideADC_clusterXY_R1_u5->Reset();
1532     SouthSideADC_clusterXY_R2_u5->Reset();
1533     SouthSideADC_clusterXY_R3_u5->Reset();
1534   }
1535 
1536   // get temporary pointers to histograms
1537   // one can do in principle directly se->getHisto("tpchist1")->Fill()
1538   // but the search in the histogram Map is somewhat expensive and slows
1539   // things down if you make more than one operation on a histogram
1540   // fill the TPC module displays
1541   float r, theta;
1542 
1543   // dummy data
1544   // float North_Side_Arr[36] = { 12, 8, 40, 39, 80, 50, 12, 8, 40, 39, 80, 50, 12, 8, 40, 39, 80, 50, 12, 8, 40, 39, 80, 50, 12, 8, 40, 39, 80, 50, 12, 8, 40, 39, 80, 50 };
1545   // float South_Side_Arr[36] = { 12, 8, 40, 39, 80, 50, 12, 8, 40, 39, 80, 50, 12, 8, 40, 39, 80, 50, 12, 8, 40, 39, 80, 50, 12, 8, 40, 39, 80, 50, 12, 8, 40, 39, 80, 50 };
1546 
1547   for (int tpciter = 1; tpciter < 73; tpciter++)
1548   {
1549     Locate(tpciter, &r, &theta);
1550     // std::cout << "r is: "<< r <<" theta is: "<< theta <<"\n";
1551     if (tpciter < 37)
1552     {                                                             // South side
1553       NorthSideADC->Fill(theta, r, North_Side_Arr[tpciter - 1]);  // fill South side with the weight = bin content
1554     }
1555     else
1556     {                                                              // North side
1557       SouthSideADC->Fill(theta, r, South_Side_Arr[tpciter - 37]);  // fill North side with the weight = bin content
1558     }
1559   }  // end loop over tpciter
1560 
1561   return 0;
1562 }  // end PROCESS_EVENT FUNCTION
1563 
1564 int TpcMon::Module_ID(int fee_id)  // for simply determining which module you are in (doesn't care about sector)
1565 {
1566   int mod_id;
1567 
1568   if (fee_id == 2 || fee_id == 3 || fee_id == 4 || fee_id == 13 || fee_id == 16 || fee_id == 17)
1569   {
1570     mod_id = 0;
1571   }  // R1
1572 
1573   else if (fee_id == 0 || fee_id == 1 || fee_id == 11 || fee_id == 12 || fee_id == 14 || fee_id == 15 || fee_id == 18 || fee_id == 19)
1574   {
1575     mod_id = 1;
1576   }  // R2
1577 
1578   else if (fee_id == 5 || fee_id == 6 || fee_id == 7 || fee_id == 8 || fee_id == 9 || fee_id == 10 || fee_id == 20 || fee_id == 21 || fee_id == 22 || fee_id == 23 || fee_id == 24 || fee_id == 25)
1579   {
1580     mod_id = 2;
1581   }  // R3
1582 
1583   else
1584     mod_id = 0;
1585 
1586   return mod_id;
1587 }
1588 
1589 int TpcMon::ebdc_from_serverid(int server_id)  // for getting the ebdc from the serverid with the double rcdaq
1590 {
1591   int ebdc_id;
1592 
1593   if (server_id < 24)
1594   {
1595     ebdc_id = server_id;
1596   }
1597   else if (server_id >= 24)
1598   {
1599     ebdc_id = server_id - 24;
1600   }
1601 
1602   return ebdc_id;
1603 }
1604 
1605 int TpcMon::Index_from_Module(int sec_id, int fee_id)  // for placing in the array (takes into account sector)
1606 {
1607   int mod_id;
1608 
1609   if (fee_id == 2 || fee_id == 3 || fee_id == 4 || fee_id == 13 || fee_id == 16 || fee_id == 17)
1610   {
1611     mod_id = 3 * sec_id + 0;
1612   }  // R1
1613 
1614   else if (fee_id == 0 || fee_id == 1 || fee_id == 11 || fee_id == 12 || fee_id == 14 || fee_id == 15 || fee_id == 18 || fee_id == 19)
1615   {
1616     mod_id = 3 * sec_id + 1;
1617   }  // R2
1618 
1619   else if (fee_id == 5 || fee_id == 6 || fee_id == 7 || fee_id == 8 || fee_id == 9 || fee_id == 10 || fee_id == 20 || fee_id == 21 || fee_id == 22 || fee_id == 23 || fee_id == 24 || fee_id == 25)
1620   {
1621     mod_id = 3 * sec_id + 2;
1622   }  // R3
1623 
1624   else
1625     mod_id = 0;
1626 
1627   return mod_id;
1628 }
1629 
1630 void TpcMon::Locate(int id, float *rbin, float *thbin)
1631 {
1632   float CSIDE_angle_bins[12] = {0.1 * 2. * TMath::Pi() / 12, 1.1 * 2. * TMath::Pi() / 12, 2.1 * 2. * TMath::Pi() / 12, 3.1 * 2. * TMath::Pi() / 12, 4.1 * 2. * TMath::Pi() / 12, 5.1 * 2. * TMath::Pi() / 12, 6.1 * 2. * TMath::Pi() / 12, 7.1 * 2. * TMath::Pi() / 12, 8.1 * 2. * TMath::Pi() / 12, 9.1 * 2. * TMath::Pi() / 12, 10.1 * 2. * TMath::Pi() / 12, 11.1 * 2. * TMath::Pi() / 12};  // CCW from x = 0 (RHS horizontal)
1633 
1634   float ASIDE_angle_bins[12] = {6.1 * 2. * TMath::Pi() / 12, 5.1 * 2. * TMath::Pi() / 12, 4.1 * 2. * TMath::Pi() / 12, 3.1 * 2. * TMath::Pi() / 12, 2.1 * 2. * TMath::Pi() / 12, 1.1 * 2. * TMath::Pi() / 12, 0.1 * 2. * TMath::Pi() / 12, 11.1 * 2. * TMath::Pi() / 12, 10.1 * 2. * TMath::Pi() / 12, 9.1 * 2. * TMath::Pi() / 12, 8.1 * 2. * TMath::Pi() / 12, 7.1 * 2. * TMath::Pi() / 12};  // CCW from x = 0 (RHS horizontal)
1635 
1636   int modid3 = id % 3;
1637 
1638   switch (modid3)
1639   {
1640   case 1:
1641     *rbin = 0.4;  // R1
1642     break;
1643   case 2:
1644     *rbin = 0.6;  // R2
1645     break;
1646   case 0:
1647     *rbin = 0.8;  // R3
1648     break;
1649   }
1650 
1651   if (id < 37)
1652   {
1653     *thbin = CSIDE_angle_bins[TMath::FloorNint((id - 1) / 3)];
1654   }
1655   else if (id >= 37)
1656   {
1657     *thbin = ASIDE_angle_bins[TMath::FloorNint((id - 37) / 3)];
1658   }
1659 }
1660 
1661 int TpcMon::Max_Nine(int one, int two, int three, int four, int five, int six, int seven, int eight, int nine)
1662 {
1663   int max = 0;
1664   int nine_array[9] = {one, two, three, four, five, six, seven, eight, nine};
1665 
1666   for (int i = 0; i < 9; i++)
1667   {
1668     if (nine_array[i] > max)
1669     {
1670       max = nine_array[i];
1671     }
1672   }
1673 
1674   return max;
1675 }
1676 
1677 bool TpcMon::side(int server_id)
1678 {
1679   bool side_id = 0;  // side = 0 for NS, side = 1 for SS
1680   if (server_id >= 12)
1681   {
1682     side_id = 1;
1683   }  // side = 1 when serverid 12 or more
1684 
1685   return side_id;
1686 }
1687 
1688 std::pair<float, float> TpcMon::calculateMedianAndStdDev(const std::vector<int> &values)
1689 {
1690   // Calculate the median
1691   // first, sort
1692   std::vector<int> sortedValues = values;
1693   std::sort(sortedValues.begin(), sortedValues.end());
1694   size_t size = sortedValues.size();
1695 
1696   // std::cout<<"SIZE OF INPUT VEC = "<<size<<std::endl;
1697 
1698   float median;
1699   if (size % 2 == 0)
1700   {
1701     median = (sortedValues[size / 2 - 1] + sortedValues[size / 2]) / 2.0;
1702   }
1703   else
1704   {
1705     median = sortedValues[size / 2];
1706   }
1707 
1708   std::vector<int> selectedValues;
1709 
1710   // Select values within the range of median +/- 40
1711   for (int value : values)
1712   {
1713     if (value >= median - 40 && value <= median + 40)
1714     {
1715       selectedValues.push_back(value);
1716     }
1717   }
1718 
1719   float stdDev = 3;  // default answer is 3 ADC if nothing passes the +/- 40 ADC band for stdDev calc.
1720 
1721   if (selectedValues.size() > 0)
1722   {
1723     // Calculate Mean of selected values
1724     float sum = 0.0;
1725     for (int value : selectedValues)
1726     {
1727       sum += value;
1728     }
1729     float mean = sum / selectedValues.size();
1730 
1731     // Calculate RMS of selected values
1732     float sumSquares = 0.0;
1733 
1734     // Calculate the standard deviation of selected values only
1735     for (int value : selectedValues)
1736     {
1737       float diff = value - mean;
1738       sumSquares += std::pow(diff, 2);
1739     }
1740     float variance = sumSquares / selectedValues.size();
1741     stdDev = std::sqrt(variance);
1742   }
1743   // std::cout<<"PED = "<< median << "ADC, NOISE = "<< stdDev <<" ADC"<<std::endl;
1744   return std::make_pair(median, stdDev);
1745 }
1746 
1747 float TpcMon::calculateRawStdDev(const std::vector<int> &values)
1748 {
1749   float stdDev = 3;  // default answer is 3 ADC if somehow you don't have anything in the values vector
1750 
1751   if (values.size() > 0)
1752   {
1753     // Calculate Mean of values
1754     float sum = 0.0;
1755     for (int value : values)
1756     {
1757       sum += value;
1758     }
1759     float mean = sum / values.size();
1760 
1761     // Calculate RMS of selected values
1762     float sumSquares = 0.0;
1763 
1764     // Calculate the standard deviation of values
1765     for (int value : values)
1766     {
1767       float diff = value - mean;
1768       sumSquares += std::pow(diff, 2);
1769     }
1770     float variance = sumSquares / values.size();
1771     stdDev = std::sqrt(variance);
1772   }
1773   // std::cout<<"PED = "<< median << "ADC, NOISE = "<< stdDev <<" ADC"<<std::endl;
1774   return stdDev;
1775 }
1776 
1777 int TpcMon::Reset()
1778 {
1779   // reset our internal counters
1780   evtcnt = 0;
1781   return 0;
1782 }