Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:20:30

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