Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-10-13 08:43:17

0001 /**
0002  * @file TileSpectra.h
0003  * @brief Declaration of the TileSpectra class used to build per-channel spectra and fits.
0004  *
0005  * TileSpectra holds the ROOT histograms and profile objects used during calibration,
0006  * pedestal estimation and signal extraction for individual detector tiles.
0007  */
0008 
0009 #ifndef TILESPECTRA_H
0010 #define TILESPECTRA_H
0011 
0012 #include "TObject.h"
0013 #include "TString.h"
0014 #include "TH1D.h"
0015 #include "TH2D.h"
0016 #include "TProfile.h"
0017 #include "TF1.h"
0018 #include "TPad.h" 
0019 #include "TCanvas.h"
0020 #include "TLegend.h"
0021 #include "Calib.h"
0022 #include "Tile.h"
0023 
0024 /**
0025  * @class TileSpectra
0026  * @brief Accumulate and fit per-tile spectra for CAEN and HGCROC channels.
0027  *
0028  * The class manages the per-cell histograms used to monitor pedestal stability,
0029  * trigger primitives, correlations, and waveform properties. It also performs
0030  * fit routines for noise and MIP estimation based on the active readout type.
0031  */
0032 class TileSpectra: public TObject{
0033 
0034  public:
0035   /**
0036    * @brief Default constructor.
0037    */
0038   TileSpectra():TObject(){}
0039 
0040   /**
0041    * @brief Construct TileSpectra for a cell with standard monitoring histograms.
0042    * @param name Base name used for histogram creation.
0043    * @param id Cell identifier.
0044    * @param cal Calibration object used during fits.
0045    * @param type Readout type (CAEN or HGCROC).
0046    * @param integ Integration sample count for waveform studies.
0047    * @param deb Debug verbosity level.
0048    */
0049   TileSpectra(TString name, int id, TileCalib* cal, ReadOut::Type type, int integ = 1, int deb=0):TObject()
0050   {
0051     TileName      = name;
0052     ROType        = type;
0053     cellID        = id;
0054     calib         = cal;
0055     debug         = deb;
0056     bpedHG        = false;
0057     bpedLG        = false;
0058     bmipHG        = false;
0059     bmipLG        = false;
0060     bcorrHGLG     = false;
0061     bcorrLGHG     = false;
0062     bpedWave      = false;
0063     bwave         = false;
0064     integSample   = integ;
0065     if (ROType == ReadOut::Type::Caen){
0066       hspectraHG    = TH1D(Form("hspectra%sHGCellID%d",name.Data(),id),Form("ADC spectrum High Gain CellID %d; HG ADC (arb. units); counts ",id),
0067                            4200,-200,4000);
0068       hspectraHG.SetDirectory(0);
0069       hspectraLG    = TH1D(Form("hspectra%sLGCellID%d",name.Data(),id),Form("ADC spectrum Low  Gain CellID %d; LG ADC (arb. units); counts",id),
0070                            4200,-200,4000);
0071       hspectraLG.SetDirectory(0);
0072       hTriggPrim    = TH1D(Form("hTriggerPrimitive%sCellID%d",name.Data(),id),Form("Trigger primitive CellID %d; HG ADC (arb. units); counts ",id),
0073                            500,0,4000);
0074       hTriggPrim.SetDirectory(0);
0075       hspectraLGHG  = TProfile(Form("hCoorspectra%sLGHGCellID%d",name.Data(),id),
0076                                Form("ADC Low  Gain/High Gain correlation CellID %d; LG ADC (arb. units); HG ADC (arb. units)",id),
0077                                800,0,800);
0078       hspectraLGHG.SetDirectory(0); 
0079       hspectraHGLG  = TProfile(Form("hCoorspectra%sHGLGCellID%d",name.Data(),id),
0080                                Form("ADC High  Gain/Low Gain correlation CellID %d; HG ADC (arb. units); LG ADC (arb. units)",id),
0081                                4100,-100,4000);
0082       hspectraHGLG.SetDirectory(0);
0083     } else if (ROType == ReadOut::Type::Hgcroc){
0084       hspectraHG    = TH1D(Form("hspectra%sADCCellID%d",name.Data(),id),Form("ADC spectrum CellID %d; ADC (arb. units); counts ",id),
0085                            1024*integ+100,-100,1024*integ);
0086       hspectraHG.SetDirectory(0);      
0087       hspectraTOT    = TH1D(Form("hspectra%sTOTCellID%d",name.Data(),id),Form("ToT spectrum CellID %d; TOT (arb. units); counts",id),
0088                             4197,-100,4097);
0089       hspectraTOT.SetDirectory(0);
0090       hspectraTOA    = TH1D(Form("hspectra%sTOACellID%d",name.Data(),id),Form("ToA spectrum CellID %d; TOA (arb. units); counts",id),
0091                             1124,-100,1024);
0092       hspectraTOA.SetDirectory(0);
0093       hTriggPrim    = TH1D(Form("hTriggerPrimitive%sCellID%d",name.Data(),id),Form("Trigger primitive CellID %d; ADC (arb. units); counts ",id),
0094                            500,0,500);
0095       hTriggPrim.SetDirectory(0);
0096       hADCTOT  = TProfile(Form("hCoorspectra%sTOTADCCellID%d",name.Data(),id),Form("TOT-ADC correlation CellID %d; ADC (arb. units); TOT (arb. units)",id),
0097                           1024+100,-100,1024*integ);
0098       hADCTOT.SetDirectory(0); 
0099       hTOAADC  = TProfile(Form("hCoorspectra%sTOAADCCellID%d",name.Data(),id),Form("ADC-TOA correlation CellID %d; TOA (arb. units); ADC (arb. units)",id),
0100                           1024,0,1024);
0101       hTOAADC.SetDirectory(0);
0102       hADCTOA  = TProfile(Form("hCoorspectra%sADCTOACellID%d",name.Data(),id),Form("TOA-ADC correlation CellID %d; TOA (arb. units); ADC (arb. units)",id),
0103                           500,0,500);
0104       hADCTOA.SetDirectory(0);
0105 
0106     }
0107   }
0108   /**
0109    * @brief Construct TileSpectra with extended histogram definitions.
0110    * @param name Base name used for histogram creation.
0111    * @param ext Extension mode selecting the histogram layout.
0112    * @param id Cell identifier.
0113    * @param cal Calibration object used during fits.
0114    * @param type Readout type (CAEN or HGCROC).
0115    * @param integ Integration sample count for waveform studies.
0116    * @param deb Debug verbosity level.
0117    */
0118   TileSpectra(TString name, int ext, int id, TileCalib* cal, ReadOut::Type type, int integ = 1, int deb=0):TObject()
0119   {
0120     TileName      = name;
0121     extend        = ext;
0122     cellID        = id;
0123     calib         = cal;
0124     debug         = deb;
0125     ROType        = type;
0126     bpedHG        = false;
0127     bpedLG        = false;
0128     bmipHG        = false;
0129     bmipLG        = false;
0130     bcorrHGLG     = false;
0131     bcorrLGHG     = false;
0132     bpedWave      = false;
0133     bwave         = false;
0134     integSample   = integ;
0135     // Calibrated output
0136     if (extend == 1){
0137       if (type == ReadOut::Type::Caen){
0138         hspectraHG    = TH1D(Form("hspectra%sHGCellID%d",name.Data(),id),
0139                              Form("ADC spectrum High Gain CellID %d; Corr HG ADC (arb. units); counts ",id),
0140                              4200,-200,4000);
0141         hspectraHG.SetDirectory(0);
0142         hspectraLG    = TH1D(Form("hspectra%sLGCellID%d",name.Data(),id),
0143                              Form("ADC spectrum Low  Gain CellID %d; Corr LG ADC (arb. units); counts",id),
0144                              4200,-200,4000);
0145         hspectraLG.SetDirectory(0);
0146         hcombined     = TH1D(Form("hspectra%sCombCellID%d",name.Data(),id),
0147                              Form("Energy CellID %d; E (mip eq./tile); counts",id),
0148                              4020,-5,1000);
0149         hcombined.SetDirectory(0);
0150         hspectraLGHG  = TProfile(Form("hCoorspectra%sLGHGCellID%d",name.Data(),id),
0151                                  Form("ADC Low  Gain/High Gain correlation CellID %d; Corr LG  (arb. units); HG E (mip eq./tile)",id),
0152                                  800,0,800);
0153         hspectraLGHG.SetDirectory(0);
0154         hspectraHGLG  = TProfile(Form("hCoorspectra%sHGLGCellID%d",name.Data(),id),
0155                                  Form("ADC Low Gain converted CellID %d; LG (arb. units); LG ( HG eq.)- HG",id),
0156                                  700,-100,600);
0157         hspectraHGLG.SetDirectory(0);
0158       }
0159     // Detailed output after transfering the calibration
0160     } else if (extend == 2){
0161       if (type == ReadOut::Type::Caen){
0162         hspectraHG    = TH1D(Form("hspectra%sHGCellID%d",name.Data(),id),
0163                              Form("ADC spectrum High Gain CellID %d; Corr HG ADC (arb. units); counts ",id),
0164                              1050,-200,4000);
0165         hspectraHG.SetDirectory(0);
0166         hspectraLG    = TH1D(Form("hspectra%sLGCellID%d",name.Data(),id),
0167                              Form("ADC spectrum Low  Gain CellID %d; Corr LG ADC (arb. units); counts",id),
0168                              1050,-200,4000);
0169         hspectraLG.SetDirectory(0);
0170         hspectraLGHG  = TProfile(Form("hCorrProf%sLGHGCellID%d",name.Data(),id),
0171                                  Form("ADC Low Gain/High Gain correlation CellID %d; Corr LG  (arb. units); HG E (arb. units)",id),
0172                                  400,0,400);
0173         hspectraLGHG.SetDirectory(0);
0174         hcorr         = TH2D(Form("hCorr2D%sLGHGCellID%d",name.Data(),id),
0175                              Form("2D ADC Low  Gain/High Gain correlation CellID %d; Corr LG  (arb. units); HG E (arb. units)",id), 
0176                              400,0,400, 525, -200, 4000 );
0177         hcorr.SetDirectory(0);
0178       } else if (type == ReadOut::Type::Hgcroc){
0179         hspectraHG    = TH1D(Form("hspectra%sADCCellID%d",name.Data(),id),Form("ADC spectrumCellID %d; ADC (arb. units); counts ",id),
0180                              1024*integ+100,-100,1024*integ);
0181         hspectraHG.SetDirectory(0);
0182         hspectraTOA    = TH1D(Form("hspectra%sTOACellID%d",name.Data(),id),Form("TOA spectrumCellID %d; TOA (arb. units); counts",id),
0183                               1024,0,1024);
0184         hspectraTOA.SetDirectory(0);
0185         hspectraTOT    = TH1D(Form("hspectra%sTOTCellID%d",name.Data(),id),Form("TOT spectrumCellID %d; TOT (arb. units); counts",id),
0186                               4096,0,4096);
0187         hspectraTOT.SetDirectory(0);
0188         hADCTOT  = TProfile(Form("h%sTOTADCCellID%d",name.Data(),id),Form("TOT-ADC correlation CellID %d; ADC (arb. units); TOT  (arb. units)",id),
0189                             (1024+100)/8,-100,1024*integ); 
0190         hADCTOT.SetDirectory(0);
0191         hcorr         = TH2D(Form("waveform%sCellID%d",name.Data(),id),Form("2D waveform CellID %d; sample ; ADC (arb. units)",id),
0192                              20,0,20, 1034, -10, 1024);
0193         hcorr.SetDirectory(0);
0194         hcorrADCTOT   = TH2D(Form("hCorr2DTOTADC%sCellID%d",name.Data(),id),Form("2D TOT-ADC CellID %d;  ADC (arb. units); TOT  (arb. units)",id),
0195                              (1024+100)/8,-100,1024*integ, 4096/8,0,4096);
0196         hcorrADCTOT.SetDirectory(0);
0197         hWaveForm     = TProfile(Form("waveform1D%sCellID%d",name.Data(),id),Form("1D waveform CellID %d;  sample ; ADC (arb. units)",id),
0198                                  20,0,20);
0199         hWaveForm.SetDirectory(0);
0200         
0201         
0202       }
0203     // Waveform analysis
0204     } else if (extend == 3){
0205       if (type == ReadOut::Type::Hgcroc){
0206         hspectraHG    = TH1D(Form("hspectra%sADCCellID%d",name.Data(),id),Form("ADC spectrumCellID %d; ADC (arb. units); counts ",id),
0207                              1024*integ+100,-100,1024*integ);
0208         hspectraHG.SetDirectory(0);
0209         hspectraTOA    = TH1D(Form("hspectra%sTOACellID%d",name.Data(),id),Form("TOA spectrumCellID %d; TOA (arb. units); counts",id),1024,0,1024);
0210         hspectraTOA.SetDirectory(0);
0211         hspectraTOT    = TH1D(Form("hspectra%sTOTCellID%d",name.Data(),id),Form("TOT spectrumCellID %d; TOT (arb. units); counts",id),4096,0,4096);
0212         hWaveForm     = TProfile(Form("waveform1D%sCellID%d",name.Data(),id),Form("1D waveform CellID %d;  t (ns) ; ADC (arb. units)",id),
0213                                  550,-50,500);
0214         hWaveForm.SetDirectory(0);
0215         hcorr         = TH2D(Form("waveform%sCellID%d",name.Data(),id),Form("2D waveform CellID %d; t (ns) ; ADC (arb. units)",id),
0216                              550,-50,500, 1034, -10, 1024);
0217         hcorr.SetDirectory(0);
0218         hcorrTOAADC   = TH2D(Form("h2DTOAADC%sCellID%d",name.Data(),id),Form("2D ADC vs TOA CellID %d; TOA (arb. units); ADC (arb. units)",id),
0219                              1024/8,0,1024, (1024+100)/8,-100,1024*integ);
0220         hcorrTOAADC.SetDirectory(0);
0221         hcorrADCTOA   = TH2D(Form("h2DADCTOA%sCellID%d",name.Data(),id),Form("2D ADC vs TOA CellID %d; ADC (arb. units); TOA (ns)",id),
0222                              325,-25,300, 1124/4, -100, 1024);
0223         hcorrADCTOA.SetDirectory(0);
0224         
0225         hcorrTOASample = TH2D(Form("h2DTOASample%sCellID%d",name.Data(),id),Form("2D Sample vs TOA CellID %d; TOA (arb. units); #sample",id),
0226                               1024/8,0,1024,20,0,20);
0227         hcorrTOASample.SetDirectory(0);
0228         hTOAADC       = TProfile(Form("h%sTOAADCCellID%d",name.Data(),id),Form("TOA-ADC correlation CellID %d; TOA (arb. units); ADC (arb. units)",id),
0229                                  1024/8,0,1024, "");
0230         hTOAADC.SetDirectory(0);
0231         hADCTOA       = TProfile(Form("h%sADCTOACellID%d",name.Data(),id),Form("ADC-TOA correlation CellID %d; ADC (arb. units); TOA (ns)",id),
0232                                   325,-25,300, "");
0233         hADCTOA.SetDirectory(0);
0234       }
0235     // extended pedestal output
0236     } else if (extend == 4){
0237       if (type == ReadOut::Type::Hgcroc){
0238         hspectraHG    = TH1D(Form("hspectra%sADCCellID%d",name.Data(),id),Form("ADC spectrumCellID %d; ADC (arb. units) 1st sample; counts ",id),1124,-100,1024);
0239         hspectraHG.SetDirectory(0);
0240         hspectraLG    = TH1D(Form("hspectra%sADCAllCellID%d",name.Data(),id),Form("ADC spectrumCellID %d; ADC (arb. units) all samples; counts ",id),1124,-100,1024);
0241         hspectraLG.SetDirectory(0);
0242         hcorr         = TH2D(Form("waveform%sCellID%d",name.Data(),id),Form("2D waveform CellID %d; sample ; ADC (arb. units)",id),20,0,20, 1034, -10, 1024);
0243         hcorr.SetDirectory(0);
0244       }
0245     // Waveform analysis option 2  
0246     } else if (extend == 5){
0247       if (type == ReadOut::Type::Hgcroc){
0248         hWaveForm     = TProfile(Form("waveform1D%sCellID%d",name.Data(),id),Form("1D waveform CellID %d;  t (ns) ; ADC (arb. units)",id),550,-50,500);
0249         hWaveForm.SetDirectory(0);
0250         hcorr         = TH2D(Form("waveform%sCellID%d",name.Data(),id),Form("2D waveform CellID %d; t (ns) ; ADC (arb. units)",id),550,-50,500, 1124/4, -100, 1024);
0251         hcorr.SetDirectory(0);
0252         hcorrTOAADC   = TH2D(Form("h2DADCLinTOA%sCellID%d",name.Data(),id),Form("2D ADC vs TOA CellID %d; TOA (arb. units); ADC (arb. units)",id), 1024/2,-6*1024,-2*1024,1124/4,-100,1024);
0253         hcorrTOAADC.SetDirectory(0);
0254         hcorrADCTOA   = TH2D(Form("h2DTOALinADC%sCellID%d",name.Data(),id),Form("2D ADC vs TOA CellID %d; ADC (arb. units); TOA (ns)",id),1124/4,-100,1024, 1124/4, -100, 1024);
0255         hcorrADCTOA.SetDirectory(0);
0256         hTOAADC       = TProfile(Form("h%sADCLinTOACellID%d",name.Data(),id),Form("ADC-TOA correlation CellID %d; TOA (arb. units); ADC (arb. units)",id),1024/2,-6*1024,-2*1024, "");
0257         hTOAADC.SetDirectory(0);
0258         hADCTOA       = TProfile(Form("h%sTOALinADCCellID%d",name.Data(),id),Form("TOA-ADC correlation CellID %d; ADC (arb. units); TOA (ns)",id),325,-25,300, "");
0259         hADCTOA.SetDirectory(0);
0260       }
0261     } else if (extend == 6){
0262       if (type == ReadOut::Type::Hgcroc){
0263         hWaveForm     = TProfile(Form("waveform1D%sCellID%d",name.Data(),id),Form("1D waveform CellID %d;  t (ns) ; ADC (arb. units)",id),550,-50,500);
0264         hWaveForm.SetDirectory(0);
0265         hcorr         = TH2D(Form("waveform%sCellID%d",name.Data(),id),Form("2D waveform CellID %d; t (ns) ; ADC (arb. units)",id),550,-50,500, 1124/4, -100, 1024);
0266         hcorr.SetDirectory(0);
0267       }
0268     } else if (extend == 7){
0269       if (type == ReadOut::Type::Hgcroc){
0270         hWaveForm     = TProfile(Form("waveform1D%sCellID%d",name.Data(),id),Form("1D waveform CellID %d;  sample ; ADC (arb. units)",id),20,0,20);
0271         hWaveForm.SetDirectory(0);
0272         hcorr         = TH2D(Form("waveform%sCellID%d",name.Data(),id),Form("2D waveform CellID %d; sample ; ADC (arb. units)",id),20,0,20, 1124/4, -100, 1024);
0273         hcorr.SetDirectory(0);
0274       }
0275     // Waveform analysis for the HG2Calib parser 
0276     } else if(extend == 8){
0277         hWaveForm     = TProfile(Form("waveform1D%sCellID%d",name.Data(),id),Form("1D waveform CellID %d;  t (ns) ; ADC (arb. units)",id),550,-50,500);
0278         hWaveForm.SetDirectory(0);
0279         hcorr         = TH2D(Form("waveform%sCellID%d",name.Data(),id),Form("2D f CellID %d; t (ns) ; ADC (arb. units)",id),550,-50,500, 1034, -10, 1024);
0280         hcorr.SetDirectory(0);
0281         hProfileTOT   = TProfile( Form("TOT%sCellID%d",name.Data(),id),Form("TOT CellID %d; t(ns); TOT (arb.units)",id),4400,-50,500,-10,4300,""); 
0282         hProfileTOT.SetDirectory(0);
0283         hProfileTOA   = TProfile( Form("TOA%sCellID%d",name.Data(),id),Form("TOA CellID %d; t(ns); TOA (arb.units)",id),1100,-50,500,-10,1090,""); 
0284         hProfileTOA.SetDirectory(0);
0285     }
0286   }
0287   ~TileSpectra(){}
0288 
0289   /**
0290    * @brief Fill a CAEN low/high-gain spectrum pair for one event.
0291    * @param l Low-gain ADC value.
0292    * @param h High-gain ADC value.
0293    * @return Always true for successful histogram insertion.
0294    */
0295   bool FillCAEN(double, double);
0296 
0297   /**
0298    * @brief Fill the basic CAEN spectra without correlation plots.
0299    * @param l Low-gain ADC value.
0300    * @param h High-gain ADC value.
0301    * @return Always true after updating the histograms.
0302    */
0303   bool FillSpectraCAEN(double, double);
0304 
0305   /**
0306    * @brief Fill extended CAEN diagnostics with energy and equivalent-charge information.
0307    * @param l Low-gain ADC value.
0308    * @param h High-gain ADC value.
0309    * @param e Reconstructed energy estimate.
0310    * @param lheq Low-gain equivalent value.
0311    * @return True if the histogram update succeeded.
0312    */
0313   bool FillExtCAEN(double, double, double, double);
0314 
0315   /**
0316    * @brief Fill CAEN correlation profiles between the two gains.
0317    * @param l Low-gain ADC value.
0318    * @param h High-gain ADC value.
0319    * @return True on successful update.
0320    */
0321   bool FillCorrCAEN(double, double);
0322 
0323   /**
0324    * @brief Fill the HGCROC ADC/TOA/TOT spectra for one event.
0325    * @param adc ADC value.
0326    * @param toa Time-over-threshold value.
0327    * @param tot Time-over-threshold or pulse width measure.
0328    * @return True on successful update.
0329    */
0330   bool FillHGCROC(double, double, double);
0331 
0332   /**
0333    * @brief Fill the basic HGCROC spectra without correlation histograms.
0334    * @param adc ADC value.
0335    * @param toa Time-over-threshold value.
0336    * @param tot Time-over-threshold or pulse width measure.
0337    * @return True on successful update.
0338    */
0339   bool FillSpectraHGCROC(double, double, double);
0340 
0341   /**
0342    * @brief Fill extended HGCROC diagnostics for a waveform or timing-analysis mode.
0343    * @param adc ADC value.
0344    * @param toa TOA value.
0345    * @param tot TOT value.
0346    * @param sample Sample index associated with the waveform measurement.
0347    * @param fixedTOA Fixed TOA value used for selection logic.
0348    * @return True on successful update.
0349    */
0350   bool FillExtHGCROC(double, double, double, int, int);
0351 
0352   /**
0353    * @brief Fill pedestal-only waveform information from a vector of samples.
0354    * @param samples Raw ADC samples for the waveform.
0355    * @param h Pedestal reference value.
0356    * @return True on successful update.
0357    */
0358   bool FillExtHGCROCPed(std::vector<int>, double);
0359 
0360   /**
0361    * @brief Fill HGCROC correlation plots between ADC, TOA and TOT observables.
0362    * @param adc ADC value.
0363    * @param toa TOA value.
0364    * @param tot TOT value.
0365    * @return True on successful update.
0366    */
0367   bool FillCorrHGCROC(double, double, double);
0368 
0369   /**
0370    * @brief Fill the trigger primitive spectrum for the channel.
0371    * @param t Trigger primitive value.
0372    * @return True on successful update.
0373    */
0374   bool FillTrigger(double);
0375 
0376   /**
0377    * @brief Fill a waveform profile from a sample vector.
0378    * @param samples Raw ADC samples in waveform order.
0379    * @param ped Pedestal offset to subtract from each sample.
0380    * @return True on successful update.
0381    */
0382   bool FillWaveform(std::vector<int>,double);
0383 
0384   /**
0385    * @brief Fill a waveform versus time using a linearized timing conversion.
0386    * @param samples ADC sample values.
0387    * @param toalincorr Linearized TOA correction.
0388    * @param ped Pedestal offset.
0389    * @param offset Sample offset in the waveform.
0390    * @return True on successful update.
0391    */
0392   bool FillWaveformVsTime(std::vector<int> , double, double, int );
0393 
0394   /**
0395    * @brief Fill the waveform maximum as a function of time.
0396    * @param adc Peak ADC value.
0397    * @param toalincorr Timing correction applied to the sample position.
0398    * @param offset Sample offset in the waveform.
0399    * @param nSampleADCMax Sample index at which the maximum occurs.
0400    * @return True on successful update.
0401    */
0402   bool FillMaxVsTime(double , double, int, int );
0403 
0404   /**
0405    * @brief Fill waveform information using the parser-specific convention.
0406    * @param samples ADC samples to store.
0407    * @param ped Pedestal offset to remove before filling.
0408    * @return True on successful update.
0409    */
0410   bool FillWaveformVsTimeParser(std::vector<int>,double);
0411 
0412   /**
0413    * @brief Fill the TOT profile histogram from sample values.
0414    * @param samples Vector of TOT values.
0415    * @return True on successful update.
0416    */
0417   bool FillTOTProfile(std::vector<int>);
0418 
0419   /**
0420    * @brief Fill the TOA profile histogram from sample values.
0421    * @param samples Vector of TOA values.
0422    * @return True on successful update.
0423    */
0424   bool FillTOAProfile(std::vector<int>);
0425    
0426   /**
0427    * @brief Fit noise and pedestal parameters for the configured readout channel.
0428    * @param out Output array with fitted mean and sigma values.
0429    * @param year Data-taking year used to tune fit ranges.
0430    * @param isNoiseTrigg Flag indicating a trigger-noise fit mode.
0431    * @return True if the pedestal fit converged.
0432    */
0433   bool FitNoise(double*, int, bool);
0434 
0435   /**
0436    * @brief Fit a Gaussian model to the noise pedestal using fixed calibration ranges.
0437    */
0438   void FitFixedNoise();
0439 
0440   /**
0441    * @brief Initialize pedestal fits from the calibration constants instead of an unconstrained fit.
0442    */
0443   void InitializeNoiseFitsFromCalib();
0444   bool FitMipHG(double*, double*, int, int, bool, double, double );
0445   bool FitMipLG(double*, double*, int, int, bool, double, double );
0446   bool FitCorrCAEN(int);
0447   bool FitLGHGCorr(int , bool);
0448   bool FitPedConstWave(int);
0449   bool FitNoiseWithBG(double*);
0450   short DetermineBadChannel();
0451 
0452   /**
0453    * @brief Return the cell identifier associated with this spectrum object.
0454    * @return Cell ID.
0455    */
0456   int GetCellID();
0457   void SetBadChannelInCalib(short);
0458    
0459   /**
0460    * @brief Determine the fitting range for a signal fit depending on the readout and gain.
0461    * @param fitrange Output array containing [min,max] bounds.
0462    * @param year Data-taking year.
0463    * @param bHG True for high-gain fits.
0464    * @param impE If true, use improved estimates from the MIP spectrum.
0465    * @param vov Over-voltage value used for dynamic tuning.
0466    * @param avmip Average MIP estimate used for range selection.
0467    */
0468   void GetFitRange(double* , int, bool, bool, double, double);
0469 
0470   /**
0471    * @brief Set the starting values and parameter limits for the high-gain fit model.
0472    * @param startvalues Output array of starting values.
0473    * @param parlimitslo Lower bounds for each fit parameter.
0474    * @param parlimitshi Upper bounds for each fit parameter.
0475    * @param integ Integration sample count.
0476    * @param year Data-taking year.
0477    * @param impE Improved-range mode.
0478    * @param vov Over-voltage value.
0479    * @param avmip Average MIP value.
0480    */
0481   void SetParametersFitHG (double*, double*, double*, int,  int, bool, double,  double);
0482    
0483   double GetMaxXInRangeLG(double, double);
0484   double GetMaxXInRangeHG(double, double);
0485   double GetMinimumInRangeSpectra(bool, float, float);
0486    
0487   /**
0488    * @brief Return the active readout type associated with the object.
0489    * @return CAEN or HGCROC readout enum value.
0490    */
0491   ReadOut::Type GetROType() {return ROType;};  
0492   TH1D* GetHG();
0493   TH1D* GetLG();
0494   TH1D* GetComb();
0495   TH1D* GetTriggPrim();
0496   TProfile* GetLGHGcorr();
0497   TProfile* GetHGLGcorr();
0498   TH2D* GetCorr();
0499   // HGCROC specific
0500   TH1D* GetTOT();
0501   TH1D* GetTOA();
0502   TProfile* GetWave1D();
0503   TProfile* GetTOAADC();
0504   TProfile* GetADCTOT();
0505   TProfile* GetADCTOA();
0506   TH2D* GetCorrTOAADC();
0507   TH2D* GetCorrADCTOA();
0508   TH2D* GetCorrTOASample();
0509   TH2D* GetCorrADCTOT();
0510   TProfile* GetTOTProfile();
0511   TProfile* GetTOAProfile();
0512    
0513   TF1* GetBackModel(int);
0514   TF1* GetSignalModel(int);
0515   TF1* GetCorrModel(int);
0516 
0517   /**
0518    * @brief Return the calibration object used by this spectra instance.
0519    * @return Pointer to the associated TileCalib object.
0520    */
0521   TileCalib* GetCalib();
0522    
0523   /**
0524    * @brief Write the standard histogram collection to disk.
0525    * @param option ROOT write option string.
0526    */
0527   void Write(bool);
0528 
0529   /**
0530    * @brief Write the extended histogram collection to disk.
0531    * @param option ROOT write option string.
0532    */
0533   void WriteExt(bool);
0534 
0535   static double langaufun(double */*x*/, double */*par*/);
0536   
0537  protected:
0538   TString TileName      = "";
0539   ReadOut::Type ROType;
0540   int cellID            = -1;
0541   TileCalib* calib;
0542   int debug             = 0;
0543   int extend            = 0;
0544   int integSample       = 1;
0545   bool resetAxisLabels  = false;
0546   bool bpedHG           = false;
0547   bool bpedLG           = false;
0548   bool bmipHG           = false;
0549   bool bmipLG           = false;
0550   bool bcorrHGLG        = false;
0551   bool bcorrLGHG        = false;
0552   bool bpedWave         = false;
0553   bool bwave            = false;
0554   bool bTriggPrim       = false;
0555   TF1 BackgroundLG;
0556   TF1 BackgroundHG;
0557   TF1 SignalLG;
0558   TF1 SignalHG;
0559   TF1 HGLGcorr;
0560   TF1 LGHGcorr;
0561   TF1 pedWave;
0562   TF1 wave;
0563   TH1D hspectraHG;
0564   TH1D hspectraLG;
0565   TH1D hspectraTOT;     // only in HGCROC case
0566   TH1D hspectraTOA;     // only in HGCROC case
0567   TH1D hTriggPrim;
0568   TH1D hcombined;
0569   TProfile hspectraLGHG;
0570   TProfile hspectraHGLG;
0571   TProfile hWaveForm;   // only in HGCROC case
0572   TProfile hADCTOT;
0573   TProfile hTOAADC;
0574   TProfile hADCTOA;     // for timewalk correction
0575   TH2D hcorr; 
0576   TH2D hcorrTOAADC;     // only in HGCROC case
0577   TH2D hcorrADCTOA;     // only in HGCROC case
0578   TH2D hcorrTOASample;  // only in HGCROC case
0579   TH2D hcorrADCTOT;     // only in HGCROC case
0580   TProfile hProfileTOT; // only in HGCROC case
0581   TProfile hProfileTOA; // only in HGCROC case
0582   static double langauWithPedestal(double */*x*/, double */*par*/);
0583   static int langaupro(double */*params*/, double &/*maxx*/, double &/*FWHM*/);
0584 
0585   ClassDef(TileSpectra,4);
0586 };
0587 
0588 
0589 #endif