Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2026-08-31 08:20:41

0001 // Tell emacs that this is a C++ source
0002 // -*- C++ -*-
0003 #ifndef CALOTOWERTIMECALIBRATION_H
0004 #define CALOTOWERTIMECALIBRATION_H
0005 
0006 #include <caloreco/CaloTowerDefs.h>
0007 
0008 #include <fun4all/SubsysReco.h>
0009 
0010 #include <string>
0011 #include <vector>
0012 
0013 class CDBTTree;
0014 class PHCompositeNode;
0015 class TH1;
0016 class TH2;
0017 
0018 /**
0019  * Timing-only sidecar calibration for calibrated TowerInfo nodes.
0020  *
0021  * Default input node:
0022  *   TOWERINFO_CALIB_<detector>
0023  *
0024  * Default output node:
0025  *   TOWERINFO_CALIB_TIMING_<detector>
0026  *
0027  * The input node is never modified. The output container is copied from the
0028  * input container, preserving calibrated energy and tower metadata/status.
0029  * Only the output tower time is replaced for valid, non-ZS towers:
0030  *
0031  *   raw_time = standard_time + official_mean_time
0032  *
0033  *   slew(E) = slew_p0 + slew_p1 * exp(slew_p2 * calibrated_energy)
0034  *
0035  *   corrected_time = raw_time
0036  *                  + phase1_shift(sample alignment)
0037  *                  - sector_offset
0038  *                  - tower_offset
0039  *                  - slew(E)
0040  *
0041  * QA is intentionally reduced to:
0042  *   - standard and corrected tower-time distributions;
0043  *   - standard and corrected energy-vs-time distributions;
0044  *   - ZS-tower time, energy, and energy-vs-time distributions.
0045  *
0046  * ZS towers are copied into the timing sidecar without a custom timing
0047  * correction. Their QA therefore uses the time and calibrated energy from the
0048  * standard input tower directly.
0049  *
0050  * There are two tower-quality populations:
0051  *   (1) all accepted non-ZS towers, with no get_isGood() requirement;
0052  *   (2) strict TowerInfo::get_isGood().
0053  *
0054  * QA histograms are filled only for events with a finite reconstructed global
0055  * z vertex, but no |zvtx| magnitude cut is applied.
0056  */
0057 class CaloTowerTimeCalibration : public SubsysReco
0058 {
0059  public:
0060   explicit CaloTowerTimeCalibration(
0061       const std::string &name = "CaloTowerTimeCalibration");
0062   ~CaloTowerTimeCalibration() override;
0063 
0064   CaloTowerTimeCalibration(const CaloTowerTimeCalibration &) = delete;
0065 
0066   CaloTowerTimeCalibration &operator=(const CaloTowerTimeCalibration &) = delete;
0067 
0068   CaloTowerTimeCalibration(CaloTowerTimeCalibration &&) = delete;
0069 
0070   CaloTowerTimeCalibration &operator=(CaloTowerTimeCalibration &&) = delete;
0071 
0072 
0073   int InitRun(PHCompositeNode *topNode) override;
0074   int process_event(PHCompositeNode *topNode) override;
0075 
0076   void set_detector_type(CaloTowerDefs::DetectorSystem detector)
0077   {
0078     m_detectorType = detector;
0079   }
0080 
0081   void set_inputNodePrefix(const std::string &prefix)
0082   {
0083     m_inputNodePrefix = prefix;
0084   }
0085 
0086   void set_outputNodePrefix(const std::string &prefix)
0087   {
0088     m_outputNodePrefix = prefix;
0089   }
0090 
0091   void set_inputNodeName(const std::string &name)
0092   {
0093     m_inputNodeName = name;
0094   }
0095 
0096   void set_outputNodeName(const std::string &name)
0097   {
0098     m_outputNodeName = name;
0099   }
0100 
0101   void set_meanTimeCalibName(const std::string &name)
0102   {
0103     m_meanTimeCalibName = name;
0104   }
0105 
0106   void set_timeCorrectionCalibName(const std::string &name)
0107   {
0108     m_timeCorrectionCalibName = name;
0109   }
0110 
0111   void set_directURL_timeCorrection(const std::string &url)
0112   {
0113     m_directTimeCorrectionURL = url;
0114   }
0115 
0116   void set_directURL_meanTime(const std::string &url)
0117   {
0118     m_directMeanTimeURL = url;
0119   }
0120 
0121   void set_doQA(bool value = true)
0122   {
0123     m_doQA = value;
0124   }
0125 
0126   // QA threshold only; calibration is still applied below this energy.
0127   void set_qaEnergyThreshold(float value)
0128   {
0129     m_qaEnergyThreshold = value;
0130   }
0131 
0132  private:
0133   struct TimingInfo
0134   {
0135     float meanTime{0.0F};
0136     float phase1Shift{0.0F};
0137     float sectorOffset{0.0F};
0138     float towerOffset{0.0F};
0139     float slewP0{0.0F};
0140     float slewP1{0.0F};
0141     float slewP2{0.0F};
0142     bool valid{false};
0143   };
0144 
0145   struct TowerQASet
0146   {
0147     TH1 *hStandardTime{nullptr};
0148     TH1 *hCorrectedTime{nullptr};
0149     TH2 *hStandardEnergyVsTime{nullptr};
0150     TH2 *hCorrectedEnergyVsTime{nullptr};
0151   };
0152 
0153   bool ResolveDetector();
0154   void ResolveNames();
0155   void CreateNodeTree(PHCompositeNode *topNode);
0156   void LoadCalibration(PHCompositeNode *topNode);
0157   void CreateQAHistograms();
0158 
0159   CaloTowerDefs::DetectorSystem m_detectorType{CaloTowerDefs::HCALOUT};
0160   std::string m_detector{"HCALOUT"};
0161 
0162   std::string m_inputNodePrefix{"TOWERINFO_CALIB_"};
0163   std::string m_outputNodePrefix{"TOWERINFO_CALIB_TIMING_"};
0164   std::string m_inputNodeName;
0165   std::string m_outputNodeName;
0166 
0167   std::string m_meanTimeCalibName;
0168   std::string m_timeCorrectionCalibName;
0169 
0170   std::string m_directMeanTimeURL;
0171   std::string m_directTimeCorrectionURL;
0172 
0173   bool m_calibrationAvailable{false};
0174 
0175   CDBTTree *m_meanTimeCDB{nullptr};
0176   CDBTTree *m_timeCorrectionCDB{nullptr};
0177   std::vector<TimingInfo> m_timingInfo;
0178 
0179   bool m_doQA{false};
0180   bool m_qaHistogramsInitialized{false};
0181   float m_qaEnergyThreshold;
0182 
0183   // ZS-tower QA. ZS timing is not custom-corrected.
0184   TH1 *m_hZSTime{nullptr};
0185   TH1 *m_hZSEnergy{nullptr};
0186   TH2 *m_hZSEnergyVsTime{nullptr};
0187 
0188   // Complete tower QA without a get_isGood() requirement.
0189   TowerQASet m_qaAllTowers;
0190 
0191   // Strict TowerInfo::get_isGood() QA.
0192   TowerQASet m_qaGoodTowers;
0193 };
0194 
0195 #endif  // CALOTOWERTIMECALIBRATION_H