Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:17:51

0001 #ifndef MBD_MBDEVENT_H
0002 #define MBD_MBDEVENT_H
0003 
0004 #include "MbdDefs.h"
0005 #include "MbdSig.h"
0006 
0007 #include <TFile.h>
0008 #include <TTree.h>
0009 
0010 #ifndef ONLINE
0011 #include <fun4all/Fun4AllBase.h>
0012 #endif
0013 
0014 #include <array>
0015 #include <limits>
0016 #include <vector>
0017 
0018 class PHCompositeNode;
0019 class Event;
0020 class MbdPmtContainer;
0021 class MbdOut;
0022 class MbdCalib;
0023 class MbdGeom;
0024 class CDBUtils;
0025 class TF1;
0026 class TCanvas;
0027 #ifndef ONLINE
0028 class CaloPacket;
0029 class CaloPacketContainer;
0030 class Gl1Packet;
0031 class PHG4TruthInfoContainer;
0032 class PHG4VtxPoint;
0033 #endif
0034 
0035 class MbdEvent
0036 {
0037  public:
0038   MbdEvent(const int cal_pass = 0, const bool proc_charge = false);
0039   virtual ~MbdEvent();
0040 
0041   int SetRawData(Event *event, MbdPmtContainer *bbcpmts);
0042 #ifndef ONLINE
0043   int SetRawData(std::array< CaloPacket *,2> &dstp, MbdPmtContainer *bbcpmts, Gl1Packet *gl1raw);
0044 #endif
0045   void PostProcessChannels(MbdPmtContainer *bbcpmts);
0046   int Calculate(MbdPmtContainer *bbcpmts, MbdOut *bbcout, PHCompositeNode *topNode = nullptr);
0047   int InitRun();
0048   int End();
0049   void Clear();
0050 
0051   void SetSim(const int s) { _simflag = s; }
0052 
0053   float get_bbcz() { return m_bbcz; }
0054   float get_bbczerr() { return m_bbczerr; }
0055   float get_bbct0() { return m_bbct0; }
0056   float get_bbct0err() { return m_bbct0err; }
0057 
0058   int   get_bbcn(const int iarm) { return m_bbcn[iarm]; }
0059   float get_bbcq(const int iarm) { return m_bbcq[iarm]; }
0060   float get_bbct(const int iarm) { return m_bbct[iarm]; }
0061   float get_bbcte(const int iarm) { return m_bbcte[iarm]; }
0062 
0063   int   get_pmtq(const int ipmt) { return m_pmtq[ipmt]; }
0064   float get_pmttt(const int ipmt) { return m_pmttt[ipmt]; }
0065   float get_pmttq(const int ipmt) { return m_pmttq[ipmt]; }
0066 
0067   int  get_EventNumber(void) const { return m_evt; }
0068   void set_EventNumber(int ievt) { m_evt = ievt; }
0069 
0070   void set_debug(const int d) { _debug = d; }
0071 
0072   MbdSig *GetSig(const int ipmt) { return &_mbdsig[ipmt]; }
0073 
0074   MbdCalib *GetCalib() { return _mbdcal; }
0075 
0076   int FillSampMaxCalib();
0077 
0078   int  calib_is_done() { return _calib_done; }
0079 
0080   int ProcessRawPackets(MbdPmtContainer *bbcpmts);
0081 
0082   int  Verbosity() { return _verbose; }
0083   void Verbosity(const int v) { _verbose = v; }
0084 
0085  private:
0086   static const int NCHPERPKT = 128;
0087 
0088   MbdGeom *_mbdgeom{nullptr};
0089   MbdCalib *_mbdcal{nullptr};
0090 
0091   int Read_Charge_Calib(const std::string &gainfname);
0092   int Read_TQ_T0_Offsets(const std::string &t0cal_fname);
0093   int Read_TQ_CLK_Offsets(const std::string &t0cal_fname);
0094   int Read_TT_CLK_Offsets(const std::string &t0cal_fname);
0095   //int DoQuickClockOffsetCalib();
0096 
0097   bool isbadtch(const int ipmtch);
0098 
0099   // Debugging variables
0100   int _debug{0};
0101 #ifndef ONLINE
0102   PHG4TruthInfoContainer* _truth_container {nullptr};
0103   PHG4VtxPoint* _vtxp {nullptr};
0104   PHG4VtxPoint* GetPrimaryVtx(PHCompositeNode *topNode);
0105 #endif
0106   int epmt[2]{-1, -1};  // pmt of earliest time
0107   // int lpmt[2] {-1,-1};        // pmt of latest time
0108   double tepmt[2]{1e9, 1e9};    // earliest time
0109   double tlpmt[2]{-1e9, -1e9};  // latest time
0110   void ReadSyncFile(const char *fname = "SYNC_INTTMBD.root");
0111 
0112   float gaincorr[MbdDefs::MBD_N_PMT]{};       // gain corrections
0113   float tq_t0_offsets[MbdDefs::MBD_N_PMT]{};  // t0 offsets in charge channels
0114   float tq_clk_offsets[MbdDefs::MBD_N_PMT]{};
0115   float tt_clk_offsets[MbdDefs::MBD_N_PMT]{};
0116 
0117   // float bz_offset{0.};
0118 
0119   int _verbose{0};
0120   int _runnum{0};
0121   int _simflag{0};
0122   int _nsamples{31};
0123   int _calib_done{0}; 
0124   unsigned int _no_sampmax{0};      //! sampmax calib doesn't exist
0125   int _is_online{0};                //! for OnlMon
0126 
0127   // alignment data
0128   Int_t   m_evt{0};
0129   Short_t m_clk{0};
0130   Short_t m_femclk{0};
0131   UInt_t  m_xmitclocks[2]{};     // [ipkt]
0132   UInt_t  m_femclocks[2][2]{};   // [ipkt][iadc]
0133 
0134   // raw data
0135   Float_t m_adc[MbdDefs::MBD_N_FEECH][MbdDefs::MAX_SAMPLES]{};   // raw waveform, adc values
0136   Float_t m_samp[MbdDefs::MBD_N_FEECH][MbdDefs::MAX_SAMPLES]{};  // raw waveform, sample values
0137   Float_t m_ampl[MbdDefs::MBD_N_FEECH]{};                        // raw amplitude
0138 
0139   std::vector<MbdSig> _mbdsig;
0140 
0141   Float_t m_pmtq[MbdDefs::MBD_N_PMT]{};   // npe in each arm
0142   Float_t m_pmttt[MbdDefs::MBD_N_PMT]{};  // time in each arm
0143   Float_t m_pmttq[MbdDefs::MBD_N_PMT]{};  // time in each arm
0144 
0145   int do_templatefit{1};
0146 
0147   // output data
0148   Short_t m_bbcn[2]{};                                            // num hits for each arm (north and south)
0149   Float_t m_bbcq[2]{};                                            // total charge (currently npe) in each arm
0150   Float_t m_bbct[2]{};                                            // time in arm
0151   Float_t m_bbcte[2]{};                                           // earliest hit time in arm
0152   Float_t m_bbctl[2]{};                                           // latest hit time in arm
0153   Float_t m_bbcz{std::numeric_limits<Float_t>::quiet_NaN()};      // z-vertex
0154   Float_t m_bbczerr{std::numeric_limits<Float_t>::quiet_NaN()};   // z-vertex error
0155   Float_t m_bbct0{std::numeric_limits<Float_t>::quiet_NaN()};     // start time
0156   Float_t m_bbct0err{std::numeric_limits<Float_t>::quiet_NaN()};  // start time error
0157   Float_t _tres{std::numeric_limits<Float_t>::quiet_NaN()};       // time resolution of one channel
0158 
0159   TH1 *hevt_bbct[2]{};  // time in each bbc, per event
0160   TF1 *gausfit[2]{nullptr, nullptr};
0161 
0162   float TRIG_SAMP[16]{};  // [board]
0163 
0164   // Calibration Data
0165   int  _calpass{0};
0166   bool _always_process_charge{false};
0167   TString _caldir;
0168   //std::string _caldir;
0169 
0170   // sampmax and other calib stuff
0171   int CalcSampMaxCalib();
0172   std::unique_ptr<TFile> _calpass1_tfile{nullptr};
0173   std::unique_ptr<TFile> _calpass2_tfile{nullptr};
0174   TH1 *h_smax[256]{};     // [feech], max sample in event
0175   TH2 *h2_smax[2]{};      // [0 == time ch, 1 == chg ch], max sample in evt vs ch
0176   TH2 *h2_wave[2]{};      // [0 == time ch, 1 == chg ch], all samples in evt vs ch
0177   TH2 *h2_trange_raw{};   // raw tdc at maxsamp vs ch
0178   TH2 *h2_trange{};       // subtracted tdc at maxsamp vs ch
0179   //TH1 *h_trange[2]{};     // subtracted tdc at maxsamp, [S/N]
0180 
0181   // pedestals (hists are in MbdSig)
0182   int CalcPedCalib();
0183 
0184   //
0185   void ClusterEarliest(std::vector<float> &times, double& mean, double& rms, double& rmin, double& rmax);
0186  
0187   // debug stuff
0188   TCanvas *ac{nullptr};  // for plots used during debugging
0189   void PlotDebug();
0190   std::unique_ptr<TFile> _synctfile{nullptr};
0191   TTree *_syncttree{nullptr};
0192   Double_t _refz{ std::numeric_limits<double>::quiet_NaN() };
0193   std::vector<Int_t> bbevt;
0194   std::vector<UShort_t> bbclk;
0195   std::vector<Float_t> mybbz;
0196   std::vector<Long64_t> bco;
0197   std::vector<Double_t> intz;
0198   std::vector<Double_t> bbz;
0199 };
0200 
0201 #endif /* MBD_MBDEVENT_H */