Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-12-19 09:24:45

0001 /*
0002  * TpcPrototypeUnpacker.h
0003  *
0004  *  Created on: Sep 19, 2018
0005  *      Author: jinhuang
0006  */
0007 
0008 #ifndef CORESOFTWARE_OFFLINE_PACKAGES_TPCDAQ_TpcPrototypeUnpacker_H_
0009 #define CORESOFTWARE_OFFLINE_PACKAGES_TPCDAQ_TpcPrototypeUnpacker_H_
0010 
0011 #include <fun4all/SubsysReco.h>
0012 
0013 #include <TObject.h>
0014 
0015 #include <cstdint>
0016 #include <cmath>
0017 #include <map>
0018 #include <set>
0019 #include <string>
0020 #include <utility>  // for pair
0021 #include <vector>
0022 
0023 class PHCompositeNode;
0024 class Fun4AllHistoManager;
0025 class TTree;
0026 class TClonesArray;
0027 class PHG4TpcPadPlane;
0028 class PHG4CylinderCellGeomContainer;
0029 class TrkrClusterContainer;
0030 class TrkrHitSetContainer;
0031 
0032 namespace TpcPrototypeDefs
0033 {
0034 namespace FEEv2
0035 {
0036 class SampleFit_PowerLawDoubleExp_PDFMaker;
0037 }
0038 }  // namespace TpcPrototypeDefs
0039 
0040 class TpcPrototypeUnpacker : public SubsysReco
0041 {
0042  public:
0043   TpcPrototypeUnpacker(const std::string &outputfilename =
0044                            "TpcPrototypeUnpacker.root");
0045   virtual ~TpcPrototypeUnpacker();
0046 
0047   int Init(PHCompositeNode *topNode);
0048   int InitRun(PHCompositeNode *topNode);
0049   int process_event(PHCompositeNode *topNode);
0050   int ResetEvent(PHCompositeNode *topNode);
0051   int End(PHCompositeNode *topNode);
0052 
0053   void setClusteringZeroSuppression(int threshold)
0054   {
0055     m_clusteringZeroSuppression = threshold;
0056   }
0057 
0058   void setNPostSample(int nPostSample)
0059   {
0060     m_nPostSample = nPostSample;
0061   }
0062 
0063   void setNPreSample(int nPreSample)
0064   {
0065     m_nPreSample = nPreSample;
0066   }
0067 
0068   void registerPadPlane(PHG4TpcPadPlane *padplane);
0069 
0070   void setEnableClustering(bool b) { enableClustering = b; }
0071   //! simple event header class for ROOT file IO
0072   class EventHeader : public TObject
0073   {
0074    public:
0075     int run;
0076     int event;
0077 
0078     uint32_t bx_counter;
0079     bool bx_counter_consistent;
0080 
0081     int xray_x;
0082     int xray_y;
0083 
0084     EventHeader()
0085       : run(-1)
0086       , event(-1)
0087       , bx_counter(0)
0088       , bx_counter_consistent(true)
0089       , xray_x(-1)
0090       , xray_y(-1)
0091     {
0092     }
0093 
0094     ClassDefOverride(TpcPrototypeUnpacker::EventHeader, 1)
0095   };
0096 
0097   //! buffer for full event data
0098   class PadPlaneData
0099   {
0100    public:
0101     PadPlaneData();
0102     void Reset();
0103 
0104     struct SampleID
0105     {
0106       int pad_azimuth;
0107       int pad_radial;
0108       int sample;
0109 
0110       void adjust(const SampleID &adjustment)
0111       {
0112         pad_azimuth += adjustment.pad_azimuth;
0113         pad_radial += adjustment.pad_radial;
0114         sample += adjustment.sample;
0115       }
0116     };
0117 
0118     static bool IsValidPad(const int pad_x, const int pad_y);
0119     std::vector<int> &getPad(const int pad_x, const int pad_y);
0120     int getSample(const SampleID &id);
0121 
0122     //! 3-D Graph clustering based on PHMakeGroups()
0123     void Clustering(int zero_suppression, bool verbosity = false);
0124 
0125 
0126     const std::vector<std::vector<std::vector<int>>> &getData() const
0127     {
0128       return m_data;
0129     }
0130 
0131     const std::multimap<int, SampleID> &getGroups() const
0132     {
0133       return m_groups;
0134     }
0135 
0136    private:
0137     //! full event data in index order of m_data[pad_azimuth][pad_radial][sample]
0138     std::vector<std::vector<std::vector<int>>> m_data;
0139 
0140     std::multimap<int, SampleID> m_groups;
0141 
0142   };
0143 
0144   //! buffer for a cluster's data
0145   class ClusterData : public TObject
0146   {
0147    public:
0148     ClusterData()
0149       : clusterID(-1)
0150       , min_sample(-1)
0151       , max_sample(-1)
0152       , min_pad_azimuth(-1)
0153       , max_pad_azimuth(-1)
0154       , peak(NAN)
0155       , peak_sample(NAN)
0156       , pedstal(NAN)
0157       , avg_pad_radial(-1)
0158       , avg_pad_azimuth(NAN)
0159       , size_pad_radial(-1)
0160       , size_pad_azimuth(-1)
0161       , avg_pos_x(NAN)
0162       , avg_pos_y(NAN)
0163       , avg_pos_z(NAN)
0164       , delta_azimuth_bin(NAN)
0165       , delta_z(NAN)
0166     {
0167     }
0168 
0169     void Clear(Option_t * /*option*/ = "");
0170 
0171     int clusterID;
0172 
0173     std::set<int> pad_radials;
0174     std::set<int> pad_azimuths;
0175     std::set<int> samples;
0176 
0177     std::map<int, std::vector<double>> pad_radial_samples;
0178     std::map<int, std::vector<double>> pad_azimuth_samples;
0179     std::vector<double> sum_samples;
0180 
0181     int min_sample;
0182     int max_sample;
0183     int min_pad_azimuth;
0184     int max_pad_azimuth;
0185 
0186     double peak;
0187     double peak_sample;
0188     double pedstal;
0189 
0190     //    std::map<int, double> pad_radial_peaks; // radial always have size = 1 in this analysis
0191     std::map<int, double> pad_azimuth_peaks;
0192 
0193     //! pad coordinate
0194     int avg_pad_radial;
0195     double avg_pad_azimuth;
0196 
0197     //! cluster size in units of pad bins
0198     int size_pad_radial;
0199     int size_pad_azimuth;
0200 
0201     //! pad coordinate
0202     double avg_pos_x;
0203     double avg_pos_y;
0204     double avg_pos_z;
0205 
0206     //! pad bin size
0207     //! phi size per pad in rad
0208     double delta_azimuth_bin;
0209     //! z size per ADC sample bin
0210     double delta_z;
0211 
0212     ClassDefOverride(TpcPrototypeUnpacker::ClusterData, 5);
0213   };
0214 
0215   //! simple channel header class for ROOT file IO
0216   class ChannelHeader : public TObject
0217   {
0218    public:
0219     int size;
0220     //! = p->iValue(channel * kPACKET_LENGTH + 2) & 0xffff;  // that's the Elink packet type
0221     int packet_type;
0222     //! = ((p->iValue(channel * kPACKET_LENGTH + 4) & 0xffff) << 4) | (p->iValue(channel * kPACKET_LENGTH + 5) & 0xffff);
0223     int bx_counter;
0224     //! = (p->iValue(channel * kPACKET_LENGTH + 3) >> 5) & 0xf;
0225     int sampa_address;
0226     //! = p->iValue(channel * kPACKET_LENGTH + 3) & 0x1f;
0227     int sampa_channel;
0228     //! = (sampa_address << 5) | sampa_channel;
0229     int fee_channel;
0230 
0231     //! which fee
0232     int fee_id;
0233 
0234     //! pad coordinate
0235     int pad_x;
0236     int pad_y;
0237 
0238     int pedestal;
0239     int max;
0240 
0241     ChannelHeader()
0242       : size(-1)
0243       , packet_type(-1)
0244       , bx_counter(-1)
0245       , sampa_address(-1)
0246       , sampa_channel(-1)
0247       , fee_channel(-1)
0248       , fee_id(-1)
0249       , pad_x(-1)
0250       , pad_y(-1)
0251       , pedestal(-1)
0252       , max(-1)
0253     {
0254     }
0255 
0256     ClassDefOverride(TpcPrototypeUnpacker::ChannelHeader, 1)
0257   };
0258 
0259  private:
0260   PHG4TpcPadPlane *padplane;
0261   PHG4CylinderCellGeomContainer *tpcCylinderCellGeom;
0262   TrkrHitSetContainer *hitsetcontainer;
0263   TrkrClusterContainer *trkrclusters;
0264 
0265   //! ClusterData &cluster -> DST / TrkrClusterContainer
0266   int exportDSTCluster(ClusterData &cluster, const int i);
0267 
0268   //! PadPlaneData m_padPlaneData -> DST / TrkrHitSetContainer
0269   int exportDSTHits();
0270 
0271   int InitField(PHCompositeNode *topNode);
0272 
0273 
0274   // IO stuff
0275 
0276   Fun4AllHistoManager *getHistoManager();
0277 
0278   std::string m_outputFileName;
0279 
0280   TTree *m_eventT;
0281 
0282   EventHeader m_eventHeader;
0283   EventHeader *m_peventHeader;  //! ->m_eventHeader,  for filling TTree
0284 
0285   int m_nClusters;
0286   TClonesArray *m_IOClusters;
0287 
0288   TTree *m_chanT;
0289 
0290   ChannelHeader m_chanHeader;
0291   ChannelHeader *m_pchanHeader;  //! ->m_chanHeader,  for filling TTree
0292   std::vector<uint32_t> m_chanData;
0293 
0294   // clustering stuff
0295   PadPlaneData m_padPlaneData;
0296   std::map<int, ClusterData> m_clusters;
0297 
0298   //! rough zero suppression by subtracting sample medium value
0299   //! \return pair of pedestal and max
0300   static std::pair<int, int> roughZeroSuppression(std::vector<int> &data);
0301 
0302   bool enableClustering;
0303   //! Clustering then prepare IOs
0304   int Clustering(void);
0305 
0306 
0307   int m_clusteringZeroSuppression;
0308   int m_nPreSample;
0309   int m_nPostSample;
0310   int m_XRayLocationX;
0311   int m_XRayLocationY;
0312 
0313   TpcPrototypeDefs::FEEv2::SampleFit_PowerLawDoubleExp_PDFMaker *m_pdfMaker;
0314 };
0315 
0316 bool operator<(const TpcPrototypeUnpacker::PadPlaneData::SampleID &s1, const TpcPrototypeUnpacker::PadPlaneData::SampleID &s2);
0317 
0318 #endif /* CORESOFTWARE_OFFLINE_PACKAGES_TPCDAQ_TpcPrototypeUnpacker_H_ */