Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-03 08:21:08

0001 #ifndef TPOT_TPOTMONDRAW_H
0002 #define TPOT_TPOTMONDRAW_H
0003 
0004 #include "MicromegasGeometry.h"
0005 
0006 #include <micromegas/MicromegasDefs.h>
0007 #include <micromegas/MicromegasMapping.h>
0008 #include <onlmon/OnlMonDraw.h>
0009 
0010 #include <TFile.h>
0011 
0012 #include <array>
0013 #include <memory>
0014 #include <string>
0015 
0016 class OnlMonDB;
0017 class TCanvas;
0018 class TH1;
0019 class TH2Poly;
0020 class TPad;
0021 
0022 class TpotMonDraw : public OnlMonDraw
0023 {
0024   public:
0025 
0026   /// constructor
0027   TpotMonDraw(const std::string &name);
0028 
0029   /// destructor
0030   ~TpotMonDraw() override = default;
0031 
0032   int Init() override;
0033   int Draw(const std::string &what = "ALL") override;
0034   int MakeHtml(const std::string &what = "ALL") override;
0035   int SavePlot(const std::string &what = "ALL", const std::string &type = "png") override;
0036 
0037   // get detector names
0038   std::vector<std::string> get_detnames_sphenix() const
0039   { return m_detnames_sphenix; }
0040 
0041   //! calibration file
0042   void set_calibration_file( const std::string& value )
0043   { m_calibration_filename = value; }
0044 
0045 
0046   // define sample window
0047   using sample_window_t = std::pair<int, int>;
0048   void set_sample_window( const sample_window_t& value )
0049   { m_sample_window = value; }
0050 
0051   // define signal sample window
0052   void set_sample_window_signal( const sample_window_t& value )
0053   { m_sample_window_signal = value; }
0054 
0055   /// set number of RMS sigma used to defined static threshold on a given channel
0056   void set_n_sigma( double value ) { m_n_sigma = value; }
0057 
0058   private:
0059 
0060   // draw message to specify that server is dead
0061   int DrawDeadServer(TPad*) override;
0062 
0063   // draw run and time in a given pad
0064   void draw_time( TPad*);
0065 
0066   TCanvas* get_canvas(const std::string& name, bool clear = true );
0067   TCanvas* create_canvas(const std::string &name);
0068 
0069   int draw_counters();
0070   int draw_detector_occupancy();
0071   int draw_resist_occupancy();
0072   int draw_server_statistics();
0073 
0074   using histogram_array_t = std::array<TH1*, MicromegasDefs::m_nfee>;
0075 
0076   using threshold_array_t = std::array<double, MicromegasDefs::m_nfee>;
0077 
0078   // drawing options
0079   enum DrawOptions
0080   {
0081     None = 0,
0082     Logx = 1<<0,
0083     Logy = 1<<1,
0084     Logz = 1<<2,
0085     Colz = 1<<3,
0086     MatchRange = 1<<4,
0087     Normalize = 1<<5
0088   };
0089 
0090   /// get histogram by name
0091   TH1* get_histogram( const std::string& name ) const;
0092 
0093   /// get detector dependent histogram array from base name
0094   histogram_array_t get_histograms( const std::string& name ) const;
0095 
0096   /// get histogram by name
0097   TH1* get_ref_histogram( const std::string& name ) const;
0098 
0099   /// get detector dependent histogram array from base name
0100   histogram_array_t get_ref_histograms( const std::string& name ) const;
0101 
0102   /// get detector dependent histogram array from base name
0103   histogram_array_t get_ref_histograms_scaled( const std::string& name ) const;
0104 
0105   /// get scale factor for reference histograms
0106   /** the normaliztion factor is based on the ratio of number of events in the event counters histogram */
0107   double get_ref_scale_factor() const;
0108 
0109   /// normalize reference histogram
0110   /*
0111    * a copy of the source histogram is done. It must be deleted after the fact
0112    */
0113   TH1* normalize( TH1*, double scale = 1 ) const;
0114 
0115   /// draw histogram array
0116   int draw_array( const std::string& name, const histogram_array_t& array, unsigned int options = DrawOptions::None, double norm_factor = 1 )
0117   { return draw_array( name, array, {{nullptr}}, options, norm_factor ); }
0118 
0119   /// draw histogram array and reference histgorams
0120   int draw_array( const std::string& name, const histogram_array_t&, const histogram_array_t& /*reference*/, unsigned int /*options*/ = DrawOptions::None, double /*norm_factor*/ = 1 );
0121 
0122   /// draw detector names in current canvas
0123   /** only works if canvas contains one of the properly formated TH2Poly histograms */
0124   void draw_detnames_sphenix( const std::string& suffix = std::string());
0125 
0126   /// draw occupancy
0127   void draw_occupancy( TH2Poly* );
0128 
0129   /// keep track of trigger count
0130   double m_triggercnt = 0;
0131 
0132   /// keep track of heartbeat count
0133   double m_heartbeatcnt = 0;
0134 
0135   /// mapping
0136   MicromegasMapping m_mapping;
0137 
0138   /// geometry
0139   MicromegasGeometry m_geometry;
0140 
0141   //! calibration filename
0142   std::string m_calibration_filename;
0143 
0144   //! keep track on per channel thresholds, used to define signal hits
0145   histogram_array_t m_threshold_histograms;
0146 
0147   //! keep track of mean threshold per FEE
0148   threshold_array_t m_mean_thresholds;
0149 
0150   /// detector names
0151   std::vector<std::string> m_detnames_sphenix;
0152 
0153   /// needed to get time axis right
0154   int TimeOffsetTicks = -1;
0155 
0156   // sample window
0157   sample_window_t m_sample_window = {0, 50};
0158 
0159   // sample window
0160   sample_window_t m_sample_window_signal = {3, 18};
0161 
0162   //! number of RMS sigma used to define threshold
0163   double m_n_sigma = 5;
0164 
0165   // reference histograms filename
0166   std::string m_ref_histograms_filename;
0167 
0168   // reference histograms TFile
0169   std::unique_ptr<TFile> m_ref_histograms_tfile;
0170 
0171   // canvases
0172   std::vector<TCanvas*> m_canvas;
0173   std::unique_ptr<OnlMonDB> dbvars;
0174 };
0175 
0176 #endif /* TPOT_TPOTMONDRAW_H */