Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-03 08:21:00

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 "DaqMon.h"
0007 
0008 #include <onlmon/OnlMon.h>  // for OnlMon
0009 #include <onlmon/OnlMonDB.h>
0010 #include <onlmon/OnlMonServer.h>
0011 
0012 #include <calobase/TowerInfoDefs.h>
0013 #include <caloreco/CaloWaveformFitting.h>
0014 
0015 #include <Event/Event.h>
0016 #include <Event/eventReceiverClient.h>
0017 #include <Event/msg_profile.h>
0018 
0019 #include <onlmon/GL1Manager.h>
0020 
0021 
0022 #include <TH1.h>
0023 #include <TH2.h>
0024 #include <TRandom.h>
0025 
0026 #include <cmath>
0027 #include <cstdio>  // for printf
0028 #include <fstream>
0029 #include <iostream>
0030 #include <sstream>
0031 #include <string>  // for allocator, string, char_traits
0032 
0033 enum
0034 {
0035   TRGMESSAGE = 1,
0036   FILLMESSAGE = 2
0037 };
0038 
0039 DaqMon::DaqMon(const std::string &name, const std::string& gl1_host)
0040   : OnlMon(name)
0041 {
0042   GL1host = gl1_host;
0043 
0044   return;
0045 }
0046 
0047 DaqMon::~DaqMon()
0048 {
0049   delete gl1mgr;
0050   return;
0051 }
0052 
0053 int DaqMon::Init()
0054 {
0055   gRandom->SetSeed(rand());
0056   const char *daqcalib = getenv("DAQCALIB");
0057   if (!daqcalib)
0058   {
0059     std::cout << "DAQCALIB environment variable not set" << std::endl;
0060     exit(1);
0061   }
0062   std::string fullfile = std::string(daqcalib) + "/" + "DaqMonData.dat";
0063   std::ifstream calib(fullfile);
0064   calib.close();
0065   printf("doing the Init\n");
0066 
0067   h_gl1_clock_diff = new TH2F("h_gl1_clock_diff","", 6, 0,6, 2, -0.5, 1.5);
0068   h_gl1_clock_diff->GetXaxis()->SetTitleSize(0);
0069   h_gl1_clock_diff->GetYaxis()->SetNdivisions(202);
0070   h_gl1_clock_diff->GetXaxis()->SetNdivisions(101);
0071   h_gl1_clock_diff->GetYaxis()->SetBinLabel(1,"#bf{Unlocked}");
0072   h_gl1_clock_diff->GetYaxis()->SetBinLabel(2,"#bf{Locked}");
0073   h_gl1_clock_diff->GetXaxis()->SetBinLabel(1,"#bf{MBD}");
0074   h_gl1_clock_diff->GetXaxis()->SetBinLabel(2,"#bf{EMCal}");
0075   h_gl1_clock_diff->GetXaxis()->SetBinLabel(3,"#bf{IHCal}");
0076   h_gl1_clock_diff->GetXaxis()->SetBinLabel(4,"#bf{OHCal}");
0077   h_gl1_clock_diff->GetXaxis()->SetBinLabel(5,"#bf{sEPD}");
0078   h_gl1_clock_diff->GetXaxis()->SetBinLabel(6,"#bf{ZDC}");
0079 
0080   h_fem_match = new TH2F("h_fem_match","", 20, -0.5,19.5, 1, 0.5, 1.5);
0081   for(int is=0;is<10;is++){
0082       h_fem_match->GetXaxis()->SetBinLabel(is+1,Form("seb0%d",is));
0083   }
0084   for(int is=10;is<19;is++){
0085       h_fem_match->GetXaxis()->SetBinLabel(is+1,Form("seb%d",is));
0086   }
0087   h_fem_match->GetXaxis()->SetBinLabel(20,"seb20");
0088   
0089   OnlMonServer *se = OnlMonServer::instance();
0090   se->registerHisto(this, h_gl1_clock_diff);  
0091   se->registerHisto(this, h_fem_match); 
0092   Reset();
0093   //erc = new eventReceiverClient("gl1daq");
0094   gl1mgr= new GL1Manager(GL1host.c_str());
0095 
0096 
0097   std::string mappingfile = std::string(daqcalib) + "/" + "packetid_seb_mapping.txt";
0098   loadpacketMapping(mappingfile);
0099 
0100   return 0;
0101 }
0102 
0103 int DaqMon::BeginRun(const int /* runno */)
0104 {
0105 
0106   gl1mgr->Reset();
0107   // we need to reset the previousdiff values. 200 is hard-coded in the header
0108   for (int i = 0; i < 200; i++) previousdiff[i] = 0;
0109 
0110   return 0;
0111 }
0112 
0113 int DaqMon::process_event(Event *e /* evt */)
0114 {
0115     if (e->getEvtType() >= 8) 
0116     {
0117         return 0;
0118     }
0119   
0120   int evtnr = e->getEvtSequence();
0121   if (evtnr < 3)
0122   {
0123     return 0;
0124   }
0125 
0126   evtcnt++;
0127   long long int gl1_clock = 0;
0128 
0129 
0130   Packet *plist[100];
0131   int npackets = e->getPacketList(plist,100);
0132 
0133   int gl1status = -3; // outside of the range for getClockSync
0134 
0135   if ( plist[0])
0136     {
0137       gl1status = gl1mgr->getClockSync(e->getEvtSequence(), plist[0] );
0138 
0139       Packet *pgl1 = gl1mgr->getGL1Packet();
0140       if (pgl1)
0141     {
0142           OnlMonServer *se = OnlMonServer::instance();
0143           se->IncrementGl1FoundCounter();
0144       gl1_clock = pgl1->lValue(0, "BCO");
0145       delete pgl1;
0146     }
0147     }
0148 
0149   bool mismatchfem = true;
0150   int femevtref = 0;
0151   int femclkref = 0;
0152   int sebid = 0;
0153 
0154   if ( gl1status == 0) // ignore all events with gl1 issues
0155     {
0156       { 
0157     for (int ipacket = 0; ipacket < npackets; ipacket++) {
0158       Packet * p = plist[ipacket];
0159       if (p) {
0160         int pnum = p->getIdentifier();
0161         int calomapid = CaloPacketMap(pnum);
0162         long int packet_clock = p->lValue(0,"CLOCK");
0163         clockdiff[ipacket] = gl1_clock  - packet_clock;
0164         int fdiff = (clockdiff[ipacket] != previousdiff[ipacket]) ? 0 : 1;
0165 
0166         // this check will tell us if we have the first event where the previous diff is still 0
0167         if( previousdiff[ipacket] ) h_gl1_clock_diff->Fill(calomapid,fdiff);
0168 
0169         previousdiff[ipacket] = clockdiff[ipacket];
0170         
0171         int nADCs = p->iValue(0,"NRMODULES");
0172         for(int iadc = 0; iadc<nADCs ; iadc++){
0173               if(ipacket==0 && iadc==0){ femevtref = p->iValue(iadc,"FEMEVTNR"); femclkref = p->iValue(iadc,"FEMCLOCK");}
0174           
0175               if(femevtref !=  p->iValue(iadc,"FEMEVTNR") && fabs(femclkref - p->iValue(0,"FEMCLOCK"))>2)
0176         {
0177                   mismatchfem = false;
0178                   sebid = getmapping(pnum);
0179         }
0180         }
0181           
0182           }
0183     }
0184       }
0185       if(mismatchfem == false) h_fem_match->Fill(sebid,1);
0186     }
0187 
0188   for (int ipacket = 0; ipacket < npackets; ipacket++) 
0189     {
0190       delete plist[ipacket];
0191     }
0192 
0193   return 0;
0194 }
0195 
0196 int DaqMon::Reset()
0197 {
0198   evtcnt = 0;
0199   idummy = 0;
0200   OnlMonServer *se = OnlMonServer::instance();
0201   se->UseGl1();
0202   return 0;
0203 }
0204 
0205 int DaqMon::CaloPacketMap(int pnum)
0206 {
0207   int caloid = -1;
0208   if (pnum >= packet_mbd_low && pnum <= packet_mbd_high)
0209   {
0210     caloid = 0;
0211   }
0212   else if (pnum >= packet_emcal_low && pnum <= packet_emcal_high)
0213   {
0214     caloid = 1;
0215   }
0216   else if (pnum >= packet_ihcal_low && pnum <= packet_ihcal_high)
0217   {
0218     caloid = 2;
0219   }
0220   else if (pnum >= packet_ohcal_low && pnum <= packet_ohcal_high)
0221   {
0222     caloid = 3;
0223   }
0224   else if (pnum >= packet_sepd_low && pnum <= packet_sepd_high)
0225   {
0226     caloid = 4;
0227   }
0228   else if (pnum >= packet_zdc)
0229   {
0230     caloid = 5;
0231   }
0232   return caloid;
0233 }