Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-03 08:18:52

0001 // Tell emacs that this is a C++ source
0002 //  -*- C++ -*-.
0003 /*!  
0004  * \file CaloWaveformSim.h
0005  * \brief create waveform from hits, could also use for event overlay
0006  * \author Shuhang Li <sli7@bnl.gov>
0007  * \version $Revision:   $
0008  * \date    $Date: $
0009  */
0010 #ifndef CALOWAVEFORMSIM_H
0011 #define CALOWAVEFORMSIM_H
0012 
0013 #include <calobase/TowerInfoDefs.h>
0014 #include <caloreco/CaloTowerDefs.h>
0015 #include <fun4all/SubsysReco.h>
0016 #include <g4detectors/LightCollectionModel.h>
0017 #include <gsl/gsl_randist.h>
0018 #include <gsl/gsl_rng.h>
0019 #include <string>
0020 #include <vector>
0021 
0022 class PHCompositeNode;
0023 class TProfile;
0024 class PHG4Hit;
0025 class PHG4CylinderCellGeom_Spacalv1;
0026 class PHG4CylinderGeom_Spacalv3;
0027 class TRandom3;
0028 class TTree;
0029 class CDBTTree;
0030 class TowerInfoContainer;
0031 
0032 class CaloWaveformSim : public SubsysReco
0033 {
0034 public:
0035   CaloWaveformSim(const std::string &name = "CaloWaveformSim");
0036   ~CaloWaveformSim() override;
0037 
0038   int InitRun(PHCompositeNode *topNode) override;
0039   int process_event(PHCompositeNode *topNode) override;
0040   int End(PHCompositeNode *topNode) override;
0041 
0042   // Detector configuration
0043   void set_detector_type(CaloTowerDefs::DetectorSystem dettype) { m_dettype = dettype; }
0044   void set_detector(const std::string &detector) { m_detector = detector; }
0045 
0046   // Calibration settings (data energy)
0047   void set_fieldname(const std::string &fieldname) { m_fieldname = fieldname; m_overrideFieldName = true; }
0048   void set_calibName(const std::string &calibName) { m_calibName = calibName; m_overrideCalibName = true; }
0049   void set_directURL_calib(const std::string &url) { m_giveDirectURL = true; m_directURL = url; }
0050   void set_overrideCalibName(bool overrideCalib) { m_overrideCalibName = overrideCalib; }
0051   void set_overrideFieldName(bool overrideField) { m_overrideFieldName = overrideField; }
0052 
0053   // Calibration settings (MC energy)
0054   void set_MC_fieldname(const std::string &MC_fieldname) { m_MC_fieldname = MC_fieldname; m_overrideMCFieldName = true; }
0055   void set_MC_calibName(const std::string &MC_calibName) { m_MC_calibName = MC_calibName; m_overrideMCCalibName = true; }
0056   void set_directURL_MCcalib(const std::string &url) { m_giveDirectURL_MC = true; m_directURL_MC = url; }
0057   void set_overrideMCFieldName(bool overrideField) { m_overrideMCFieldName = overrideField; }
0058   void set_overrideMCCalibName(bool overrideCalib) { m_overrideMCCalibName = overrideCalib; }
0059 
0060   // Time calibration (data)
0061   void set_fieldname_time(const std::string &fieldname_time) { m_fieldname_time = fieldname_time; m_overrideTimeFieldName = true; }
0062   void set_calibName_time(const std::string &calibName_time) { m_calibName_time = calibName_time; m_overrideTimeCalibName = true; }
0063   void set_directURL_timecalib(const std::string &url) { m_giveDirectURL_time = true; m_directURL_time = url; }
0064   void set_dotimecalib(bool dotimecalib) { m_dotimecalib = dotimecalib; }
0065   void set_overrideTimeFieldName(bool overrideField) { m_overrideTimeFieldName = overrideField; }
0066   void set_overrideTimeCalibName(bool overrideCalib) { m_overrideTimeCalibName = overrideCalib; }
0067 
0068   // Time calibration (MC)
0069   void set_MC_fieldname_time(const std::string &MC_fieldname_time) { m_MC_fieldname_time = MC_fieldname_time; m_overrideMCTimeFieldName = true; }
0070   void set_MC_calibName_time(const std::string &MC_calibName_time) { m_MC_calibName_time = MC_calibName_time; m_overrideMCTimeCalibName = true; }
0071   void set_directURL_MCtimecalib(const std::string &url) { m_giveDirectURL_MC_time = true; m_directURL_MC_time = url; }
0072   void set_overrideMCTimeFieldName(bool overrideField) { m_overrideMCTimeFieldName = overrideField; }
0073   void set_overrideMCTimeCalibName(bool overrideCalib) { m_overrideMCTimeCalibName = overrideCalib; }
0074 
0075   // Waveform template & sampling
0076   void set_templatefile(const std::string &templatefile) { m_templatefile = templatefile; }
0077   void set_nsamples(int nsamples) { m_nsamples = nsamples; }
0078   void set_pedestalsamples(int pedestalsamples) { m_pedestalsamples = pedestalsamples; }
0079   void set_sampletime(float sampletime) { m_sampletime = sampletime; }
0080   void set_nchannels(int nchannels) { m_nchannels = nchannels; }
0081   void set_sampling_fraction(float fraction) { m_sampling_fraction = fraction; }
0082 
0083   // Signal shaping parameters
0084   void set_deltaT(float deltaT) { m_deltaT = deltaT; }
0085   void set_timewidth(float timewidth) { m_timeshiftwidth = timewidth; }
0086   void set_peakpos(float peakpos) { m_peakpos = peakpos; }
0087   void set_highgain(bool highgain = true) { m_highgain = highgain; }
0088   void set_gain(int gain) { m_gain = gain; }
0089   void set_pedestal_scale(float scale) { m_pedestal_scale = scale; }
0090 
0091   // Noise configuration
0092   enum NoiseType { NOISE_NONE = 0, NOISE_GAUSSIAN = 1, NOISE_TREE = 2 };
0093   void set_noise_type(NoiseType noiseType) { m_noiseType = noiseType; }
0094   void set_fixpedestal(int fixpedestal) { m_fixpedestal = fixpedestal; }
0095   void set_gaussian_noise(int gaussian_noise) { m_gaussian_noise = gaussian_noise; }
0096 
0097   // Light collection model access
0098   LightCollectionModel &get_light_collection_model() { return light_collection_model; }
0099 
0100 private:
0101   CaloTowerDefs::DetectorSystem m_dettype{CaloTowerDefs::CEMC};
0102   std::string m_detector{"CEMC"};
0103 
0104   // Data energy calibration
0105   std::string m_fieldname{"Femc_datadriven_qm1_correction"};
0106   std::string m_calibName{"cemc_pi0_twrSlope_v1"};
0107   bool        m_overrideCalibName{false};
0108   bool        m_overrideFieldName{false};
0109   bool        m_giveDirectURL{false};
0110   std::string m_directURL{""};
0111   // MC energy calibration
0112   std::string m_MC_fieldname{"Femc_datadriven_qm1_correction"};
0113   std::string m_MC_calibName{"cemc_pi0_twrSlope_v1"};
0114   bool        m_overrideMCFieldName{false};
0115   bool        m_overrideMCCalibName{false};
0116   bool        m_giveDirectURL_MC{false};
0117   std::string m_directURL_MC{""};
0118 
0119   // Data time calibration
0120   std::string m_fieldname_time{"time"};
0121   std::string m_calibName_time{"CEMC_meanTime"};
0122   bool        m_overrideTimeFieldName{false};
0123   bool        m_overrideTimeCalibName{false};
0124   bool        m_dotimecalib{true};
0125   bool        m_giveDirectURL_time{false};
0126   std::string m_directURL_time{""};
0127   // MC time calibration
0128   std::string m_MC_fieldname_time{"time"};
0129   std::string m_MC_calibName_time{"CEMC_meanTime"};
0130   bool        m_overrideMCTimeFieldName{false};
0131   bool        m_overrideMCTimeCalibName{false};
0132   bool        m_giveDirectURL_MC_time{false};
0133   std::string m_directURL_MC_time{""};
0134 
0135   // Waveform settings
0136   std::string m_templatefile{"waveformtemptempohcalcosmic.root"};
0137   int         m_nsamples{31};
0138   int         m_pedestalsamples{31};
0139   float       m_sampletime{50. / 3.};
0140   int         m_nchannels{24576};
0141   float       m_sampling_fraction{1.0f};
0142 
0143   //containers
0144   TowerInfoContainer *m_CaloWaveformContainer{nullptr};
0145   TowerInfoContainer *m_PedestalContainer{nullptr};
0146 
0147   // Shaping & noise
0148   int   m_fixpedestal{1500};
0149   int   m_gaussian_noise{3};
0150   float m_deltaT{100.};
0151   float m_timeshiftwidth{0.};
0152   bool  m_highgain{false};
0153   int   m_gain{1};
0154   float m_peakpos{6.};
0155   float m_pedestal_scale{1.};
0156 
0157   gsl_rng *m_RandomGenerator{nullptr};
0158   PHG4CylinderCellGeom_Spacalv1 *geo{nullptr};
0159   const PHG4CylinderGeom_Spacalv3  *layergeom{nullptr};
0160   std::vector<std::vector<float>> m_waveforms;
0161   int m_runNumber{0};
0162 
0163   unsigned int (*encode_tower)(unsigned int, unsigned int){TowerInfoDefs::encode_emcal};
0164   unsigned int (*decode_tower)(unsigned int){TowerInfoDefs::decode_emcal};
0165 
0166   CDBTTree *cdbttree{nullptr}, *cdbttree_MC{nullptr};
0167   CDBTTree *cdbttree_time{nullptr}, *cdbttree_MC_time{nullptr};
0168   TProfile *h_template{nullptr};
0169   LightCollectionModel light_collection_model;
0170 
0171   NoiseType m_noiseType{NOISE_TREE};
0172 
0173   void CreateNodeTree(PHCompositeNode *topNode);
0174   void maphitetaphi(PHG4Hit *g4hit,
0175                     unsigned short &etabin,
0176                     unsigned short &phibin,
0177                     float &correction);
0178   double template_function(double *x, double *par);
0179 };
0180 
0181 #endif  // CALOWAVEFORMSIM_H