Back to home page

sPhenix code displayed by LXR

 
 

    


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

0001 #ifndef MICROMEGAS_MICROMEGASCOMBINEDDATAEVALUATION_H
0002 #define MICROMEGAS_MICROMEGASCOMBINEDDATAEVALUATION_H
0003 
0004 /*!
0005  * \file MicromegasCombinedDataEvaluation.h
0006  * \author Hugo Pereira Da Costa <hugo.pereira-da-costa@cea.fr>
0007  */
0008 
0009 #include "MicromegasCalibrationData.h"
0010 #include "MicromegasMapping.h"
0011 
0012 #include <fun4all/SubsysReco.h>
0013 #include <phool/PHObject.h>
0014 
0015 #include <TTree.h>
0016 
0017 #include <map>
0018 #include <memory>
0019 #include <string>
0020 #include <utility>
0021 
0022 class PHCompositeNode;
0023 class TFile;
0024 class TH1;
0025 class TH2;
0026 class TProfile;
0027 
0028 /// micromegas raw data decoder
0029 class MicromegasCombinedDataEvaluation : public SubsysReco
0030 {
0031  public:
0032   /// constructor
0033   MicromegasCombinedDataEvaluation(const std::string& name = "MicromegasCombinedDataEvaluation");
0034 
0035   /// global initialization
0036   int Init(PHCompositeNode*) override;
0037 
0038   /// run initialization
0039   int InitRun(PHCompositeNode*) override;
0040 
0041   /// event processing
0042   int process_event(PHCompositeNode*) override;
0043 
0044   /// end of processing
0045   int End(PHCompositeNode*) override;
0046 
0047   /// calibration file
0048   void set_calibration_file(const std::string& value) { m_calibration_filename = value; }
0049 
0050   /// set number of RMS sigma used to defined static threshold on a given channel
0051   void set_n_sigma(double value) { m_n_sigma = value; }
0052 
0053   /// set minimum ADC value, disregarding pedestal and RMS.
0054   /** This removes faulty channels for which calibration has failed */
0055   void set_min_adc(double value) { m_min_adc = value; }
0056 
0057   /// set min sample for noise estimation
0058   void set_sample_min(int value) { m_sample_min = value; }
0059 
0060   /// set min sample for noise estimation
0061   void set_sample_max(int value) { m_sample_max = value; }
0062 
0063   /// output file name for evaluation histograms
0064   void set_evaluation_outputfile(const std::string& outputfile) { m_evaluation_filename = outputfile; }
0065 
0066   class Sample
0067   {
0068    public:
0069     /// packet
0070     unsigned int packet_id = 0;
0071 
0072     /// ll1 bco
0073     uint64_t lvl1_bco = 0;
0074 
0075     /// fee bco
0076     unsigned int fee_bco = 0;
0077 
0078     /// checksum and checksum error
0079     unsigned int checksum = 0;
0080     unsigned int checksum_error = 0;
0081 
0082     /// fee
0083     unsigned short fee_id = 0;
0084     unsigned short layer = 0;
0085     unsigned short tile = 0;
0086 
0087     /// sampa channel and sampa address
0088     unsigned short sampa_address = 0;
0089     unsigned short sampa_channel = 0;
0090 
0091     /// channel id
0092     unsigned short channel = 0;
0093 
0094     /// physical strip id
0095     unsigned short strip = 0;
0096 
0097     unsigned short sample = 0;
0098     unsigned short adc = 0;
0099 
0100     double pedestal = 0;
0101     double rms = 0;
0102 
0103     using List = std::vector<Sample>;
0104   };
0105 
0106   /**
0107    * waveform is similar to sample except that there is only one of which per waveform,
0108    * and that it stores the max adc and corresponding sample_id
0109    */
0110   class Waveform
0111   {
0112    public:
0113     /// packet
0114     unsigned int packet_id = 0;
0115 
0116     /// ll1 bco
0117     uint64_t lvl1_bco = 0;
0118 
0119     /// fee bco
0120     unsigned int fee_bco = 0;
0121 
0122     /// checksum and checksum error
0123     unsigned int checksum = 0;
0124     unsigned int checksum_error = 0;
0125 
0126     /// fee
0127     unsigned short fee_id = 0;
0128     unsigned short layer = 0;
0129     unsigned short tile = 0;
0130 
0131     /// sampa channel and sampa address
0132     unsigned short sampa_address = 0;
0133     unsigned short sampa_channel = 0;
0134 
0135     /// channel id
0136     unsigned short channel = 0;
0137 
0138     /// physical strip id
0139     unsigned short strip = 0;
0140 
0141     unsigned short sample_max = 0;
0142     unsigned short adc_max = 0;
0143 
0144     double pedestal = 0;
0145     double rms = 0;
0146 
0147     bool is_signal = false;
0148 
0149     //! default constructor
0150     Waveform() = default;
0151 
0152     //! construct from sample
0153     Waveform(const Sample& sample)
0154     {
0155       copy_from(sample);
0156     }
0157 
0158     //! copy from sample
0159     void copy_from(const Sample&);
0160 
0161     using List = std::vector<Waveform>;
0162   };
0163 
0164   class Container : public PHObject
0165   {
0166    public:
0167     void Reset();
0168 
0169     // number of taggers for each packet
0170     std::vector<int> n_tagger;
0171 
0172     // number of waveform for each packet
0173     std::vector<int> n_waveform;
0174 
0175     Waveform::List waveforms;
0176     Sample::List samples;
0177 
0178     // bco for this event
0179     std::vector<uint64_t> lvl1_bco_list;
0180 
0181     // lvl1 count for this event
0182     std::vector<uint32_t> lvl1_count_list;
0183 
0184     ClassDef(Container, 1)
0185   };
0186 
0187  private:
0188   //! raw node
0189   std::string m_rawhitnodename = "MICROMEGASRAWHIT";
0190 
0191   //! calibration filename
0192   std::string m_calibration_filename = "TPOT_Pedestal_000.root";
0193 
0194   //! calibration data
0195   MicromegasCalibrationData m_calibration_data;
0196 
0197   //! mapping
0198   MicromegasMapping m_mapping;
0199 
0200   /// number of RMS sigma used to define threshold
0201   double m_n_sigma = 5;
0202 
0203   //! minimum ADC value, disregarding pedestal and RMS.
0204   /* This removes faulty channels for which calibration has failed */
0205   double m_min_adc = 50;
0206 
0207   /// min sample for signal
0208   int m_sample_min = 0;
0209 
0210   /// max sample for signal
0211   int m_sample_max = 100;
0212 
0213   //! evaluation output filename
0214   std::string m_evaluation_filename = "MicromegasCombinedDataEvaluation.root";
0215   std::unique_ptr<TFile> m_evaluation_file;
0216 
0217   //! tree
0218   TTree* m_evaluation_tree = nullptr;
0219 
0220   //! main branch
0221   Container* m_container = nullptr;
0222 
0223   /// map waveforms to bco
0224   /** this is used to count how many waveforms are found for a given lvl1 bco */
0225   using bco_map_t = std::map<uint64_t, unsigned int>;
0226   bco_map_t m_bco_map;
0227 };
0228 
0229 #endif