Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:18:02

0001 // Tell emacs that this is a C++ source
0002 // //  -*- C++ -*-.
0003 #ifndef TPC_COMBINEDRAWDATAUNPACKER_H
0004 #define TPC_COMBINEDRAWDATAUNPACKER_H
0005 
0006 #include <fun4all/SubsysReco.h>
0007 
0008 #include <limits>
0009 #include <map>
0010 #include <string>
0011 #include <vector>
0012 
0013 
0014 class CDBInterface;
0015 class CDBTTree;
0016 class TFile;
0017 class TH1;
0018 class TH2;
0019 class TNtuple;
0020 
0021 class TpcCombinedRawDataUnpacker : public SubsysReco
0022 {
0023  public:
0024   TpcCombinedRawDataUnpacker(std::string const &name = "TpcCombinedRawDataUnpacker", std::string const &outF = "TpcCombinedRawDataUnpackerOutput.root");
0025   ~TpcCombinedRawDataUnpacker() override;
0026   int Init(PHCompositeNode *topNode) override;
0027   int InitRun(PHCompositeNode *) override;
0028   int process_event(PHCompositeNode *) override;
0029   int End(PHCompositeNode *topNode) override;
0030   void writeTree() { m_writeTree = true; }
0031   void doChanHitsCut(bool do_cut, int cut = 9999)
0032   {
0033     m_doChanHitsCut = do_cut;
0034     m_ChanHitsCut = cut;
0035   };
0036   void doBaselineCorr(bool val) { m_do_baseline_corr = val; }
0037   void doZSEmulation(bool val) { m_do_zs_emulation = val; }
0038   void ReadZeroSuppressedData();
0039   void set_presampleShift(int b) { m_presampleShift = b; }
0040   void set_t0(int b) { m_t0 = b; }
0041   void set_zs_threshold(int threshold, int region) { m_zs_threshold[region] = threshold; }
0042   void set_baseline_nsigma(int b) { m_baseline_nsigma = b; }
0043   void skipNevent(int b) { startevt = b; }
0044   void useRawHitNodeName(const std::string &name) { m_TpcRawNodeName = name; }
0045 
0046   void event_range(int a, int b)
0047   {
0048     startevt = a;
0049     endevt = b;
0050   }
0051   unsigned int get_rx(unsigned int layer)
0052   {
0053     return (layer - 7) / 16;
0054   }
0055 
0056   unsigned int create_fee_key(unsigned int side, unsigned int sector, unsigned int rx, unsigned int fee)
0057   {
0058     unsigned int key = rx;
0059     key += side * 10;
0060     key += sector * 100;
0061     key += fee * 10000;
0062     return key;
0063   }
0064   void unpack_fee_key(unsigned int &side, unsigned int &sector, unsigned int &rx, unsigned int &fee, unsigned int fee_key)
0065   {
0066     rx = fee_key % 10;
0067     side = (fee_key % 100) / 10;
0068     sector = ((fee_key - side * 10 - rx) / 100) / 100;
0069     fee = fee_key / 10000;
0070     return;
0071   }
0072   unsigned int create_pad_key(unsigned int side, unsigned int layer, unsigned int padnum)
0073   {
0074     unsigned int key = side;
0075     key += layer * 10;
0076     key += padnum * 1000;
0077     return key;
0078   }
0079   void unpack_pad_key(unsigned int &side, unsigned int &layer, unsigned int &pad_num, unsigned int pad_key)
0080   {
0081     side = pad_key % 10;
0082     layer = (pad_key % 1000) / 10;
0083     pad_num = (pad_key - layer * 10 - side) / 1000;
0084     return;
0085   }
0086 
0087  private:
0088   struct chan_info
0089   {
0090     unsigned int fee = std::numeric_limits<unsigned int>::max();
0091     float ped = -1;
0092     float width = -1;
0093     int entries = 0;
0094   };
0095   TNtuple *m_ntup{nullptr};
0096   TNtuple *m_ntup_hits{nullptr};
0097   TNtuple *m_ntup_hits_corr{nullptr};
0098   TFile *m_file{nullptr};
0099   CDBTTree *m_cdbttree{nullptr};
0100   CDBInterface *m_cdb{nullptr};
0101 
0102   int m_presampleShift{40};  // number of presamples shifted to line up t0
0103   int m_t0{0};
0104   int _ievent{0};
0105   int startevt{-1};
0106   int endevt{9999999};
0107   int mc_sectors[12]{5, 4, 3, 2, 1, 0, 11, 10, 9, 8, 7, 6};
0108   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};
0109   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};
0110 
0111   TH2 *m_HitChanDis{nullptr};
0112   TH1 *m_HitsinChan{nullptr};
0113   bool m_doChanHitsCut{false};
0114   int m_ChanHitsCut{9999};
0115 
0116   float m_ped_sig_cut{4.0};
0117 
0118   bool m_writeTree{false};
0119   bool m_do_baseline_corr{false};
0120   int m_baseline_nsigma{2};
0121   bool m_do_zs_emulation{false};
0122   int m_zs_threshold[3] = {20}; // zs per TPC region
0123   std::string m_TpcRawNodeName{"TPCRAWHIT"};
0124   std::string outfile_name;
0125   std::map<unsigned int, chan_info> chan_map;                  // stays in place
0126   std::map<unsigned int, TH2 *> feeadc_map;                    // histos reset after each event
0127   std::map<unsigned int, std::vector<int>> feeentries_map;     // cleared after each event
0128   std::map<unsigned int, std::vector<float>> feebaseline_map;  // cleared after each event
0129 };
0130 
0131 #endif  // TPC_COMBINEDRAWDATAUNPACKER_H