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 "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   gl1mgr= new GL1Manager(eventReceiverClientHost);
0094 
0095 
0096   std::string mappingfile = std::string(daqcalib) + "/" + "packetid_seb_mapping.txt";
0097   loadpacketMapping(mappingfile);
0098 
0099   return 0;
0100 }
0101 
0102 int DaqMon::BeginRun(const int /* runno */)
0103 {
0104 
0105   gl1mgr->Reset();
0106   // we need to reset the previousdiff values. 200 is hard-coded in the header
0107   for (int i = 0; i < 200; i++) previousdiff[i] = 0;
0108 
0109   return 0;
0110 }
0111 
0112 int DaqMon::process_event(Event *e /* evt */)
0113 {
0114     if (e->getEvtType() >= 8) 
0115     {
0116         return 0;
0117     }
0118   
0119   int evtnr = e->getEvtSequence();
0120   if (evtnr < 3)
0121   {
0122     return 0;
0123   }
0124 
0125   evtcnt++;
0126   long long int gl1_clock = 0;
0127 
0128 
0129   Packet *plist[100];
0130   int npackets = e->getPacketList(plist,100);
0131 
0132   int gl1status = -3; // outside of the range for getClockSync
0133 
0134   if ( plist[0])
0135     {
0136       gl1status = gl1mgr->getClockSync(e->getEvtSequence(), plist[0] );
0137 
0138       Packet *pgl1 = gl1mgr->getGL1Packet();
0139       if (pgl1)
0140     {
0141           OnlMonServer *se = OnlMonServer::instance();
0142           se->IncrementGl1FoundCounter();
0143       gl1_clock = pgl1->lValue(0, "BCO");
0144       delete pgl1;
0145     }
0146     }
0147 
0148   bool mismatchfem = true;
0149   int femevtref = 0;
0150   int femclkref = 0;
0151   int sebid = 0;
0152 
0153   if ( gl1status == 0) // ignore all events with gl1 issues
0154     {
0155       { 
0156     for (int ipacket = 0; ipacket < npackets; ipacket++) {
0157       Packet * p = plist[ipacket];
0158       if (p) {
0159         int pnum = p->getIdentifier();
0160         int calomapid = CaloPacketMap(pnum);
0161         long int packet_clock = p->lValue(0,"CLOCK");
0162         clockdiff[ipacket] = gl1_clock  - packet_clock;
0163         int fdiff = (clockdiff[ipacket] != previousdiff[ipacket]) ? 0 : 1;
0164 
0165         // this check will tell us if we have the first event where the previous diff is still 0
0166         if( previousdiff[ipacket] ) h_gl1_clock_diff->Fill(calomapid,fdiff);
0167 
0168         previousdiff[ipacket] = clockdiff[ipacket];
0169         
0170         int nADCs = p->iValue(0,"NRMODULES");
0171         for(int iadc = 0; iadc<nADCs ; iadc++){
0172               if(ipacket==0 && iadc==0){ femevtref = p->iValue(iadc,"FEMEVTNR"); femclkref = p->iValue(iadc,"FEMCLOCK");}
0173           
0174               if(femevtref !=  p->iValue(iadc,"FEMEVTNR") && fabs(femclkref - p->iValue(0,"FEMCLOCK"))>2)
0175         {
0176                   mismatchfem = false;
0177                   sebid = getmapping(pnum);
0178         }
0179         }
0180           
0181           }
0182     }
0183       }
0184       if(mismatchfem == false) h_fem_match->Fill(sebid,1);
0185     }
0186 
0187   for (int ipacket = 0; ipacket < npackets; ipacket++) 
0188     {
0189       delete plist[ipacket];
0190     }
0191 
0192   return 0;
0193 }
0194 
0195 int DaqMon::Reset()
0196 {
0197   evtcnt = 0;
0198   idummy = 0;
0199   OnlMonServer *se = OnlMonServer::instance();
0200   se->UseGl1();
0201   return 0;
0202 }
0203 
0204 int DaqMon::CaloPacketMap(int pnum)
0205 {
0206   int caloid = -1;
0207   if (pnum >= packet_mbd_low && pnum <= packet_mbd_high)
0208   {
0209     caloid = 0;
0210   }
0211   else if (pnum >= packet_emcal_low && pnum <= packet_emcal_high)
0212   {
0213     caloid = 1;
0214   }
0215   else if (pnum >= packet_ihcal_low && pnum <= packet_ihcal_high)
0216   {
0217     caloid = 2;
0218   }
0219   else if (pnum >= packet_ohcal_low && pnum <= packet_ohcal_high)
0220   {
0221     caloid = 3;
0222   }
0223   else if (pnum >= packet_sepd_low && pnum <= packet_sepd_high)
0224   {
0225     caloid = 4;
0226   }
0227   else if (pnum >= packet_zdc)
0228   {
0229     caloid = 5;
0230   }
0231   return caloid;
0232 }