Back to home page

sPhenix code displayed by LXR

 
 

    


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

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 "CemcMon.h"
0007 
0008 #include <onlmon/OnlMon.h>  // for OnlMon
0009 #include <onlmon/OnlMonServer.h>
0010 #include <onlmon/pseudoRunningMean.h>
0011 #include <onlmon/triggerEnum.h>
0012 
0013 #include <calobase/TowerInfoDefs.h>
0014 #include <caloreco/CaloWaveformFitting.h>
0015 
0016 #include <cdbobjects/CDBTTree.h>
0017 
0018 #include <Event/Event.h>
0019 #include <Event/EventTypes.h>
0020 #include <Event/eventReceiverClient.h>
0021 #include <Event/msg_profile.h>
0022 
0023 #include <TH1.h>
0024 #include <TH2.h>
0025 #include <TProfile.h>
0026 #include <TProfile2D.h>
0027 
0028 #include <cmath>
0029 #include <cstdio>  // for printf
0030 #include <fstream>
0031 #include <iostream>
0032 #include <sstream>
0033 #include <string>  // for allocator, string, char_traits
0034 
0035 enum
0036 {
0037   TRGMESSAGE = 1,
0038   FILLMESSAGE = 2
0039 };
0040 
0041 const int depth = 300000;
0042 // const int historyLength = 100;
0043 // const float hit_threshold = 100;
0044 const float hit_threshold = 50;
0045 const float waveform_hit_threshold = 50;
0046 const float chi2_check_threshold = 3000;
0047 
0048 using namespace std;
0049 
0050 CemcMon::CemcMon(const std::string &name)
0051   : OnlMon(name)
0052   , eventCounter(0)
0053 {
0054   // leave ctor fairly empty, its hard to debug if code crashes already
0055   // during a new CemcMon()
0056 
0057   return;
0058 }
0059 
0060 CemcMon::~CemcMon()
0061 {
0062   for (auto iter : rm_vector_twr)
0063   {
0064     delete iter;
0065   }
0066   for (auto iter : rm_vector_twrhits)
0067   {
0068     delete iter;
0069   }
0070   for (auto iter : rm_vector_twrhits_alltrig)
0071   {
0072     delete iter;
0073   }
0074 
0075   delete WaveformProcessingFast;
0076   delete WaveformProcessingTemp;
0077   delete erc;
0078   return;
0079 }
0080 
0081 int CemcMon::Init()
0082 {
0083   // read our calibrations from CemcMonData.dat
0084   const char *cemccalib = getenv("CEMCCALIB");
0085   if (!cemccalib)
0086   {
0087     std::cout << "CEMCCALIB environment variable not set" << std::endl;
0088     exit(1);
0089   }
0090   std::string fullfile = std::string(cemccalib) + "/" + "CemcMonData.dat";
0091   std::ifstream calib(fullfile);
0092   calib.close();
0093   // use printf for stuff which should go the screen but not into the message
0094   // system (all couts are redirected)
0095   printf("CemcMon::Init()\n");
0096   std::string cdbfile = std::string(cemccalib) + "/cemc_adcskipmask_40430.root";
0097   cdbttree = new CDBTTree(cdbfile.c_str());
0098   // Histograms definitions
0099   // Trigger histograms
0100   for (int itrig = 0; itrig < 64; itrig++)
0101   {
0102     h2_cemc_hits_trig[itrig] = new TH2F(Form("h2_cemc_hits_trig_bit_%d", itrig), "", 96, 0, 96, 256, 0, 256);
0103   }
0104   p2_zsFrac_etaphi = new TProfile2D("p2_zsFrac_etaphi", "", 96, 0, 96, 256, 0, 256);
0105   p2_zsFrac_etaphi_all = new TProfile2D("p2_zsFrac_etaphi_all", "", 96, 0, 96, 256, 0, 256);
0106   h1_cemc_trig = new TH1F("h1_cemc_trig", "", 64, -0.5, 63.5);
0107   h1_packet_event = new TH1F("h1_packet_event", "", 8, packetlow - 0.5, packethigh + 0.5);
0108   h2_caloPack_gl1_clock_diff = new TH2F("h2_caloPack_gl1_clock_diff", "", 8, packetlow - 0.5, packethigh + 0.5, 65536, 0, 65536);
0109   h_evtRec = new TProfile("h_evtRec", "", 1, 0, 1);
0110 
0111   // tower hit information
0112   h2_cemc_hits = new TH2F("h2_cemc_hits", "", 96, 0, 96, 256, 0, 256);
0113   h2_cemc_rm = new TH2F("h2_cemc_rm", "", 96, 0, 96, 256, 0, 256);
0114   h2_cemc_rmhits = new TH2F("h2_cemc_rmhits", "", 96, 0, 96, 256, 0, 256);
0115   h2_cemc_rmhits_alltrig = new TH2F("h2_cemc_rmhits_alltrig", "", 96, 0, 96, 256, 0, 256);
0116   h2_cemc_mean = new TH2F("h2_cemc_mean", "", 96, 0, 96, 256, 0, 256);
0117   h1_cemc_adc = new TH1F("h1_cemc_adc", "", 1000, 0.5, pow(2, 14));
0118   // event counter
0119   h1_event = new TH1F("h1_event", "", 1, 0, 1);
0120 
0121   // waveform processing
0122   // h2_waveform_twrAvg = new TH2F("h2_waveform_twrAvg", "", 16, 0.5, 16.5, 10000,0,pow(2,14));
0123   h2_waveform_twrAvg = new TH2F("h2_waveform_twrAvg", "", 12, -0.5, 11.5, 1000, 0, 15000);
0124   h1_waveform_time = new TH1F("h1_waveform_time", "", 12, -0.5, 11.5);
0125   h1_waveform_pedestal = new TH1F("h1_waveform_pedestal", "", 5000, 1, 5000);
0126 
0127   // waveform processing, template vs. fast interpolation
0128   h1_cemc_fitting_sigDiff = new TH1F("h1_fitting_sigDiff", "", 50, 0, 2);
0129   h1_cemc_fitting_pedDiff = new TH1F("h1_fitting_pedDiff", "", 50, 0, 2);
0130   h1_cemc_fitting_timeDiff = new TH1F("h1_fitting_timeDiff", "", 50, -10, 10);
0131 
0132   // packet information
0133   h1_packet_number = new TH1F("h1_packet_number", "", 128, 6000.5, 6128.5);
0134   h1_packet_length = new TH1F("h1_packet_length", "", 128, 6000.5, 6128.5);
0135   h1_packet_chans = new TH1F("h1_packet_chans", "", 128, 6000.5, 6128.5);
0136   for(int i = 0; i < nPacketStatus; i++) h1_packet_status[i] = new TH1F(Form("h1_packet_status_%d",i),"",128,6000.5, 6128.5);
0137 
0138   p2_bad_chi2 = new TProfile2D("p2_bad_chi2", "", 96, 0, 96, 256, 0, 256);
0139   //s option to track rms
0140   p2_pre_post = new TProfile2D("p2_pre_post", "", 96, 0, 96, 256, 0, 256, "S");
0141 
0142   // make the per-packet running mean objects
0143   // 32 packets and 48 channels for hcal detectors
0144   for (int i = 0; i < Ntower; i++)
0145   {
0146     rm_vector_twr.push_back(new pseudoRunningMean(1, depth));
0147     rm_vector_twrhits.push_back(new pseudoRunningMean(1, depth));
0148     rm_vector_twrhits_alltrig.push_back(new pseudoRunningMean(1, depth));
0149   }
0150   
0151 
0152 
0153   OnlMonServer *se = OnlMonServer::instance();
0154   // register histograms with server otherwise client won't get them
0155 
0156   // Trigger histograms
0157   for (int itrig = 0; itrig < 64; itrig++)
0158   {
0159     se->registerHisto(this, h2_cemc_hits_trig[itrig]);
0160   }
0161   se->registerHisto(this, p2_zsFrac_etaphi);
0162   se->registerHisto(this, p2_zsFrac_etaphi_all);
0163   se->registerHisto(this, p2_bad_chi2);
0164   se->registerHisto(this, h1_cemc_trig);
0165   se->registerHisto(this, h1_packet_event);
0166   se->registerHisto(this, h2_caloPack_gl1_clock_diff);
0167   se->registerHisto(this, h_evtRec);
0168 
0169   se->registerHisto(this, h2_cemc_hits);
0170   se->registerHisto(this, h2_cemc_rm);
0171   se->registerHisto(this, h2_cemc_rmhits);
0172   se->registerHisto(this, h2_cemc_rmhits_alltrig);
0173   se->registerHisto(this, p2_pre_post);
0174   se->registerHisto(this, h2_cemc_mean);
0175   se->registerHisto(this, h1_event);
0176 
0177   se->registerHisto(this, h2_waveform_twrAvg);
0178   se->registerHisto(this, h1_waveform_time);
0179   se->registerHisto(this, h1_waveform_pedestal);
0180   se->registerHisto(this, h1_cemc_fitting_sigDiff);
0181   se->registerHisto(this, h1_cemc_fitting_pedDiff);
0182   se->registerHisto(this, h1_cemc_fitting_timeDiff);
0183   se->registerHisto(this, h1_packet_number);
0184   se->registerHisto(this, h1_packet_length);
0185   se->registerHisto(this, h1_packet_chans);
0186   se->registerHisto(this, h1_cemc_adc);
0187   for(int i = 0; i < nPacketStatus; i++) se->registerHisto(this, h1_packet_status[i]);
0188 
0189 
0190   // Commented until potential replacement with TProfile3D
0191   // h2_waveform=new TProfile**[nPhiIndex];
0192   // for(int iphi=0; iphi<nPhiIndex; iphi++){
0193   //   h2_waveform[iphi]=new TProfile*[nEtaIndex];
0194   //   for(int ieta=0; ieta<nEtaIndex; ieta++){
0195   //     h2_waveform[iphi][ieta]=new TProfile(Form("h2_waveform_phi%d_eta%d",iphi,ieta),Form("Profiled raw waveform for #phi %d and #eta %d",iphi,ieta),12, -0.5, 11.5, "s");
0196   //     h2_waveform[iphi][ieta]->GetXaxis()->SetTitle("sample #");
0197   //     h2_waveform[iphi][ieta]->GetYaxis()->SetTitle("ADC counts");
0198   //     h2_waveform[iphi][ieta]->SetStats(false);
0199   //     se->registerHisto(this, (TH1*)h2_waveform[iphi][ieta]);
0200   //   }
0201   // }
0202 
0203   // initialize waveform extraction tool
0204   WaveformProcessingFast = new CaloWaveformFitting();
0205 
0206   WaveformProcessingTemp = new CaloWaveformFitting();
0207 
0208   std::string cemctemplate;
0209   if (getenv("CEMCCALIB"))
0210   {
0211     cemctemplate = getenv("CEMCCALIB");
0212   }
0213   else
0214   {
0215     cemctemplate = ".";
0216   }
0217   cemctemplate += std::string("/testbeam_cemc_template.root");
0218   WaveformProcessingTemp->initialize_processing(cemctemplate);
0219 
0220   if (anaGL1)
0221   {
0222     erc = new eventReceiverClient(eventReceiverClientHost);
0223   }
0224 
0225   return 0;
0226 }
0227 
0228 int CemcMon::BeginRun(const int /* runno */)
0229 {
0230   // if you need to read calibrations on a run by run basis
0231   // this is the place to do it
0232 
0233   // reset the running means
0234   std::vector<runningMean *>::iterator rm_it;
0235   for (rm_it = rm_vector_twr.begin(); rm_it != rm_vector_twr.end(); ++rm_it)
0236   {
0237     (*rm_it)->Reset();
0238   }
0239   for (rm_it = rm_vector_twrhits.begin(); rm_it != rm_vector_twrhits.end(); ++rm_it)
0240   {
0241     (*rm_it)->Reset();
0242   }
0243   for (rm_it = rm_vector_twrhits_alltrig.begin(); rm_it != rm_vector_twrhits_alltrig.end(); ++rm_it)
0244   {
0245     (*rm_it)->Reset();
0246   }
0247   if (anaGL1)
0248   {
0249     OnlMonServer *se = OnlMonServer::instance();
0250     se->UseGl1();
0251   }
0252   return 0;
0253 }
0254 
0255 // simple wavefrom analysis for possibe issues with the wavforProcessor
0256 std::vector<float> CemcMon::getSignal(Packet *p, const int channel)
0257 {
0258   double baseline = 0;
0259   for (int s = 0; s < 3; s++)
0260   {
0261     baseline += p->iValue(s, channel);
0262   }
0263   baseline /= 3.;
0264 
0265   double signal = 0;
0266   float x = 0;
0267   for (int s = 3; s < p->iValue(0, "SAMPLES"); s++)
0268   {
0269     x++;
0270     signal += p->iValue(s, channel) - baseline;
0271   }
0272 
0273   signal /= x;
0274 
0275   std::vector<float> result;
0276   result.push_back(signal);
0277   result.push_back(2);
0278   result.push_back(1);
0279   return result;
0280 }
0281 
0282 std::vector<float> CemcMon::anaWaveformFast(Packet *p, const int channel)
0283 {
0284   std::vector<float> waveform;
0285 
0286   // int nSamples = p->iValue(0, "SAMPLES");
0287   if (p->iValue(channel, "SUPPRESSED"))
0288   {
0289     waveform.push_back(p->iValue(channel, "PRE"));
0290     waveform.push_back(p->iValue(channel, "POST"));
0291   }
0292   else
0293   {
0294     int nSamples = p->iValue(0, "SAMPLES");
0295     waveform.reserve(nSamples);
0296     for (int s = 0; s < nSamples; s++)
0297     {
0298       waveform.push_back(p->iValue(s, channel));
0299     }
0300   }
0301 
0302   std::vector<std::vector<float>> multiple_wfs;
0303   multiple_wfs.push_back(waveform);
0304 
0305   std::vector<std::vector<float>> fitresults_cemc;
0306   fitresults_cemc = WaveformProcessingFast->calo_processing_fast(multiple_wfs);
0307 
0308   std::vector<float> result;
0309   result = fitresults_cemc.at(0);
0310   return result;
0311 }
0312 
0313 std::vector<float> CemcMon::anaWaveformTemp(Packet *p, const int channel)
0314 {
0315   std::vector<float> waveform;
0316 
0317   if (p->iValue(channel, "SUPPRESSED"))
0318   {
0319     waveform.push_back(p->iValue(channel, "PRE"));
0320     waveform.push_back(p->iValue(channel, "POST"));
0321   }
0322   else
0323   {
0324     waveform.reserve(p->iValue(0, "SAMPLES"));
0325     for (int s = 0; s < p->iValue(0, "SAMPLES"); s++)
0326     {
0327       waveform.push_back(p->iValue(s, channel));
0328     }
0329   }
0330   std::vector<std::vector<float>> multiple_wfs;
0331   multiple_wfs.push_back(waveform);
0332 
0333   std::vector<std::vector<float>> fitresults_cemc;
0334   fitresults_cemc = WaveformProcessingTemp->process_waveform(multiple_wfs);
0335 
0336   std::vector<float> result;
0337   result = fitresults_cemc.at(0);
0338   return result;
0339 }
0340 
0341 int CemcMon::process_event(Event *e /* evt */)
0342 {
0343   float sectorAvg[Nsector] = {0};
0344   unsigned int towerNumber = 0;
0345   bool fillhist = true;
0346   std::vector<bool> trig_bools;
0347   trig_bools.resize(64);
0348   long long int gl1_clock = 0;
0349   bool have_gl1 = false;
0350   if (anaGL1)
0351   {
0352     int evtnr = e->getEvtSequence();
0353     Event *gl1Event = erc->getEvent(evtnr);
0354     if (gl1Event)
0355     {
0356       OnlMonServer *se = OnlMonServer::instance();
0357       se->IncrementGl1FoundCounter();
0358       have_gl1 = true;
0359       Packet *p = gl1Event->getPacket(14001);
0360       h_evtRec->Fill(0.0, 1.0);
0361       if (p)
0362       {
0363         gl1_clock = p->lValue(0, "BCO");
0364         uint64_t triggervec = p->lValue(0, "ScaledVector");
0365         for (int i = 0; i < 64; i++)
0366         {
0367           bool trig_decision = ((triggervec & 0x1U) == 0x1U);
0368           trig_bools[i] = trig_decision;
0369           if (trig_decision)
0370           {
0371             h1_cemc_trig->Fill(i);
0372           }
0373           triggervec = (triggervec >> 1U);
0374         }
0375         delete p;
0376       }
0377       delete gl1Event;
0378     }
0379     else
0380     {
0381       std::cout << "GL1 event is null" << std::endl;
0382       h_evtRec->Fill(0.0, 0.0);
0383     }
0384     
0385     //this is for only process event with the MBD>=2 trigger
0386     //use MBD>=2 for AuAu
0387     if(usembdtrig){
0388       if(trig_bools.at(TriggerEnum::BitCodes::MBD_NS1_ZVRTX10) == 0 
0389       && trig_bools.at(TriggerEnum::BitCodes::MBD_NS1_ZVRTX13) == 0 
0390       && trig_bools.at(TriggerEnum::BitCodes::MBD_NS1_ZVRTX150) == 0 
0391       && trig_bools.at(TriggerEnum::BitCodes::PHOTON4_MBD_NS1_ZVRTX10) ==0)
0392       {
0393         fillhist = false;
0394       }
0395     }
0396     
0397   }
0398 
0399   // loop over packets which contain a single sector
0400   eventCounter++;
0401   int one = 1;
0402   int zero = 0;
0403   for (int packet = packetlow; packet <= packethigh; packet++)
0404   {
0405     Packet *p = e->getPacket(packet);
0406 
0407     if (p)
0408     {
0409       unsigned int adc_skip_mask = cdbttree->GetIntValue(packet, "adcskipmask");
0410       h1_packet_number->Fill(packet);
0411       h1_packet_length->SetBinContent(packet - 6000, h1_packet_length->GetBinContent(packet - 6000) + p->getLength());
0412 
0413       h1_packet_event->SetBinContent(packet - 6000, p->lValue(0, "CLOCK"));
0414       h1_packet_status[(int)p->getStatus()]->Fill(packet);
0415 
0416       if (have_gl1)
0417       {
0418         long long int p_clock = p->lValue(0, "CLOCK");
0419         long long int diff = (p_clock - gl1_clock) % 65536;
0420         h2_caloPack_gl1_clock_diff->Fill(packet, diff);
0421       }
0422       int nChannels = p->iValue(0, "CHANNELS");
0423       int skiped_channel = 0;
0424       if (nChannels > m_nChannels)
0425       {
0426         return -1;  // packet is corrupted, reports too many channels
0427       }
0428       //print packet and nCHannels
0429       for (int c = 0; c < nChannels; c++)
0430       {
0431         h1_packet_chans->Fill(packet);
0432         // skip masked ADC board 
0433         if(c % 64 ==0){
0434           unsigned int adcboard = (unsigned int) c / 64;
0435           if ((adc_skip_mask >> adcboard) & 0x1U){
0436             
0437              towerNumber += 64;
0438              skiped_channel += 64;
0439           }
0440         }
0441 
0442         
0443         towerNumber++;
0444         // channel mapping
0445         unsigned int key = TowerInfoDefs::encode_emcal(towerNumber - 1);
0446         unsigned int phi_bin = TowerInfoDefs::getCaloTowerPhiBin(key);
0447         unsigned int eta_bin = TowerInfoDefs::getCaloTowerEtaBin(key);
0448 
0449         // Commented until potential replacement by TProfile3D
0450         // for (int s = 0; s < p->iValue(0, "SAMPLES"); s++)
0451         //   {
0452         //     h2_waveform[phi_bin][eta_bin]->Fill(s,p->iValue(s,c));//for the moment only for good packet and with signal (potentially also bad packet later, not sure for zero suppressed)
0453         //   }
0454 
0455         ////Uninstrumented area
0456         // if ((packet==6019)||(packet==6073)){
0457         //   if(c>63&&c<128) continue;
0458         // }
0459         // if (packet==6030){
0460         //   if(c>127)continue;
0461         // }
0462 
0463         std::vector<float> resultFast = anaWaveformFast(p, c);  // fast waveform fitting
0464         float signalFast = resultFast.at(0);
0465         float timeFast = resultFast.at(1);
0466         float pedestalFast = resultFast.at(2);
0467         int bin = h2_cemc_mean->FindBin(eta_bin + 0.5, phi_bin + 0.5);
0468         float prepost = p->iValue(c, "PRE") - p->iValue(c, "POST");
0469         //________________________________for this part we only want to deal with the MBD>=1 trigger
0470         
0471         if (isHottower(packet, c)) 
0472         {
0473             continue;
0474         }
0475 
0476         if (fillhist)
0477         {
0478           if (p->iValue(c, "SUPPRESSED"))
0479           {
0480             p2_zsFrac_etaphi->Fill(eta_bin, phi_bin, 0);
0481           }
0482           else
0483           {
0484             p2_zsFrac_etaphi->Fill(eta_bin, phi_bin, 1);
0485           }
0486 
0487           h1_waveform_pedestal->Fill(pedestalFast);
0488           
0489           rm_vector_twr[towerNumber - 1]->Add(&signalFast);
0490 
0491           if (signalFast > hit_threshold)
0492           {
0493             rm_vector_twrhits[towerNumber - 1]->Add(&one);
0494             h2_cemc_hits->SetBinContent(bin, h2_cemc_hits->GetBinContent(bin) + 1);
0495           }
0496           else
0497           {
0498             rm_vector_twrhits[towerNumber - 1]->Add(&zero);
0499           }
0500           h2_cemc_mean->SetBinContent(bin, h2_cemc_mean->GetBinContent(bin) + signalFast);
0501           h2_cemc_rm->SetBinContent(bin, rm_vector_twr[towerNumber - 1]->getMean(0));
0502           h2_cemc_rmhits->SetBinContent(bin, rm_vector_twrhits[towerNumber - 1]->getMean(0));
0503           h1_cemc_adc->Fill(signalFast);
0504         }
0505         //_______________________________________________________end of MBD trigger requirement
0506 
0507          if (p->iValue(c, "SUPPRESSED"))
0508           {
0509             p2_zsFrac_etaphi_all->Fill(eta_bin, phi_bin, 0);
0510           }
0511           else
0512           {
0513             p2_zsFrac_etaphi_all->Fill(eta_bin, phi_bin, 1);
0514           }
0515 
0516 
0517 
0518         if (signalFast > waveform_hit_threshold)
0519         {
0520           // check if hot tower and skip it
0521             for (int s = 0; s < p->iValue(0, "SAMPLES"); s++)
0522             {
0523                 h2_waveform_twrAvg->Fill(s, p->iValue(s, c) - pedestalFast);
0524             }
0525             h1_waveform_time->Fill(timeFast);
0526         }
0527         if (signalFast > hit_threshold)
0528         {
0529           // h2_cemc_hits->SetBinContent(bin, h2_cemc_hits->GetBinContent(bin) + signalFast);
0530           if (have_gl1)
0531           {
0532             for (int itrig = 0; itrig < 64; itrig++)
0533             {
0534               if (trig_bools[itrig])
0535               {
0536                 h2_cemc_hits_trig[itrig]->Fill(eta_bin + 0.5, phi_bin + 0.5);
0537               }
0538             }
0539           }
0540           rm_vector_twrhits_alltrig[towerNumber - 1]->Add(&one);
0541         }
0542         else
0543         {
0544           rm_vector_twrhits_alltrig[towerNumber - 1]->Add(&zero);
0545         }
0546         if(prepost > 0)
0547         {
0548           p2_pre_post->Fill(eta_bin, phi_bin, prepost);
0549           p2_pre_post->Fill(eta_bin, phi_bin, -prepost);
0550         }
0551         
0552         h2_cemc_rmhits_alltrig->SetBinContent(bin, rm_vector_twrhits_alltrig[towerNumber - 1]->getMean(0));
0553 
0554         if (signalFast > chi2_check_threshold)
0555         {
0556           std::vector<float> resultTemp = anaWaveformTemp(p, c);  // template waveform fitting
0557           float chi2 = resultTemp.at(3);
0558           float signalTemp = resultTemp.at(0);
0559           if(chi2 > signalTemp*signalTemp / 50. )
0560           {
0561             p2_bad_chi2->Fill(eta_bin, phi_bin, 1);
0562           }
0563           else
0564           {
0565             p2_bad_chi2->Fill(eta_bin, phi_bin, 0);
0566           }
0567         }
0568         
0569 
0570 
0571         /*
0572         if (!((eventCounter - 2) % 10000))
0573         {
0574           std::vector<float> resultTemp = anaWaveformTemp(p, c);  // template waveform fitting
0575           float signalTemp = resultTemp.at(0);
0576           float timeTemp = resultTemp.at(1);
0577           float pedestalTemp = resultTemp.at(2);
0578           h1_cemc_fitting_sigDiff->Fill(signalFast / signalTemp);
0579           h1_cemc_fitting_pedDiff->Fill(pedestalFast / pedestalTemp);
0580           h1_cemc_fitting_timeDiff->Fill(timeFast - timeTemp - 6);
0581         }
0582         */
0583 
0584       }  // channel loop
0585       if ((nChannels + skiped_channel) < m_nChannels)
0586       {
0587         
0588         // still need to correctly set bad channels to zero.
0589         for (int channel = 0; channel < m_nChannels - (nChannels + skiped_channel); channel++)
0590         {
0591           towerNumber++;
0592 
0593           unsigned int key = TowerInfoDefs::encode_emcal(towerNumber - 1);
0594           unsigned int phi_bin = TowerInfoDefs::getCaloTowerPhiBin(key);
0595           unsigned int eta_bin = TowerInfoDefs::getCaloTowerEtaBin(key);
0596 
0597           int sectorNumber = phi_bin / 8 + 1;
0598 
0599           int bin = h2_cemc_mean->FindBin(eta_bin + 0.5, phi_bin + 0.5);
0600 
0601           sectorAvg[sectorNumber - 1] += 0.;
0602 
0603           float signalFast = 0.0;
0604 
0605           rm_vector_twr[towerNumber - 1]->Add(&signalFast);
0606 
0607           h2_cemc_rm->SetBinContent(bin, rm_vector_twr[towerNumber - 1]->getMean(0));
0608           h2_cemc_rmhits->SetBinContent(bin, rm_vector_twrhits[towerNumber - 1]->getMean(0));
0609 
0610           h2_cemc_mean->SetBinContent(bin, h2_cemc_mean->GetBinContent(bin));
0611         }
0612       }
0613       delete p;
0614     }     // if packet good
0615     else  // packet is corrupted, treat all channels as zero suppressed
0616     {
0617       for (int channel = 0; channel < m_nChannels; channel++)
0618       {
0619         towerNumber++;
0620         unsigned int key = TowerInfoDefs::encode_emcal(towerNumber - 1);
0621         unsigned int phi_bin = TowerInfoDefs::getCaloTowerPhiBin(key);
0622         unsigned int eta_bin = TowerInfoDefs::getCaloTowerEtaBin(key);
0623 
0624         int sectorNumber = phi_bin / 8 + 1;
0625 
0626         int bin = h2_cemc_mean->FindBin(eta_bin + 0.5, phi_bin + 0.5);
0627 
0628         sectorAvg[sectorNumber - 1] += 0;
0629 
0630         float signalFast = 0;
0631 
0632         rm_vector_twr[towerNumber - 1]->Add(&signalFast);
0633 
0634         h2_cemc_rm->SetBinContent(bin, rm_vector_twr[towerNumber - 1]->getMean(0));
0635         h2_cemc_rmhits->SetBinContent(bin, rm_vector_twrhits[towerNumber - 1]->getMean(0));
0636 
0637         h2_cemc_mean->SetBinContent(bin, h2_cemc_mean->GetBinContent(bin));
0638       }
0639     }  // zero filling bad packets
0640   }    // packet loop
0641 
0642   h1_event->Fill(0);
0643 
0644   eventCounter++;
0645   return 0;
0646 }
0647 
0648 int CemcMon::Reset()
0649 {
0650   // reset our internal counters
0651   eventCounter = 0;
0652   idummy = 0;
0653   return 0;
0654 }