StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StFcsWaveformFitMaker.h
1 // $Id: StFcsWaveformFitMaker.h,v 1.2 2021/05/30 21:26:53 akio Exp $
2 // $Log: StFcsWaveformFitMaker.h,v $
3 // Revision 1.2 2021/05/30 21:26:53 akio
4 // Added mFitDrawOn=2 for resetting mHitIdx for end of page, instead of each event
5 // Increased accepted tb range as hit, need further tuning
6 //
7 // Revision 1.1 2021/03/30 13:40:13 akio
8 // FCS code after peer review and moved from $CVSROOT/offline/upgrades/akio
9 //
10 // Revision 1.13 2021/02/25 21:56:28 akio
11 // Int_t -> int
12 //
13 // Revision 1.12 2021/02/25 19:24:33 akio
14 // Modified for STAR code review (Hongwei)
15 //
16 // Revision 1.11 2021/02/13 13:43:09 akio
17 // Some cleanups
18 //
19 // Revision 1.10 2021/02/13 03:11:44 akio
20 // Added TGraphAsymmErrorsWithReset and separate resetGraph() and simplify getGraph(idx=-1)
21 //
22 // Revision 1.9 2021/02/10 04:11:24 akio
23 // Code from David on improving TGraphArray housekeeping
24 //
25 // Revision 1.8 2021/01/26 18:43:14 akio
26 // Include David's fitter & holding of TGA for the event. Separate drawFit().
27 //
28 // Revision 1.7 2021/01/11 14:46:18 akio
29 // Adding another tail functional form, adding fit drawing to PDF
30 //
31 // Revision 1.6 2021/01/02 21:38:03 akio
32 // Fix some minor issues
33 //
34 // Revision 1.5 2021/01/02 21:04:54 akio
35 // added 11 for ped sub
36 //
37 // Revision 1.4 2020/09/17 19:01:52 akio
38 // fix bugs David reported
39 //
40 // Revision 1.3 2020/09/16 14:52:46 akio
41 // Use of TGraphAsymmErrors to deal with adc saturation
42 // Impelment gausFit() for gaussian fit
43 //
44 // Revision 1.2 2020/09/03 20:15:49 akio
45 // Adding res array for peak height/position/sigma and chi2
46 //
47 // Revision 1.1 2020/08/19 19:51:08 akio
48 // Initial version
49 //
50 
51 #ifndef STROOT_STFCSWAVEFORMFITMAKER_STFCSWAVEFORMFITMAKER_H_
52 #define STROOT_STFCSWAVEFORMFITMAKER_STFCSWAVEFORMFITMAKER_H_
53 
54 #include "StMaker.h"
55 #include "StFcsPulseAna.h"
56 
57 #include "TH2.h"
58 
59 class StFcsCollection;
60 class StFcsHit;
61 class StFcsDb;
62 class StFcsDbPulse;
63 class TGraphAsymmErrors;
64 class TGraph;
65 class TCanvas;
66 
68 public:
69 
70  StFcsWaveformFitMaker(const char* name = "StFcsWaveformFitMaker");
72  virtual int Init();
73  virtual int InitRun(int runNumber);
74  virtual int Make();
75  virtual int Finish();
76  virtual void Clear(Option_t* option = "");
77 
78  void setDebug(int v=1) {SetDebug(v);}
79  void setTest(int v);
80  void setEnergySelect(int ecal=13, int hcal=13, int pres=1) {mEnergySelect[0]=ecal; mEnergySelect[1]=hcal; mEnergySelect[2]=pres;}
81  void setEnergySumScale(double ecal=1.0, double hcal=1.0, double pres=1.0) {mEnergySumScale[0]=ecal; mEnergySumScale[1]=hcal; mEnergySumScale[2]=pres;}
82  void setCenterTimeBins(int v, int min=0, int max=512) {mCenterTB=v; mMinTB=min; mMaxTB=max;}
83  void setAdcSaturation(int v) {mAdcSaturation=(double)v;}
84  void setError(double v) {mError=v;}
85  void setErrorSaturated(int v) {mErrorSaturated=v;}
86  void setMinAdc(int v) {mMinAdc=v;}
87  void setTail(int v);
88  void setMaxPeak(int v) {mMaxPeak=v;}
89  void setPedTimeBins(int min, int max) {mPedMin=min; mPedMax=max;}
90  void setAnaWaveform(bool value=true){ mAnaWaveform=value; }
91 
92  TGraphAsymmErrors* resetGraph();
93 
99  TGraphAsymmErrors* getGraph(int idx=-1);
100  TGraphAsymmErrors* getGraph(int det, int id);
101 
102  //measuring fit time
103  void setMeasureTime(char* file) {mMeasureTime=file;}
104  TH1F* mTime = 0;
105 
106  //stage0 peak algo study
107  TH2F* mTimeIntg[4];
108 
120  TGraphAsymmErrors* makeTGraphAsymmErrors(int n, double* t, double* adc);
121  TGraphAsymmErrors* makeTGraphAsymmErrors(TGraph* g);
122  TGraphAsymmErrors* makeTGraphAsymmErrors(StFcsHit* hit);
123  TGraphAsymmErrors* makeTGraphAsymmErrors(TH1* hist);
124 
157  float analyzeWaveform(int select, TGraphAsymmErrors* g, float* res, TF1*& f, float ped=0.0);
158  float analyzeWaveform(int select, int n, double* t, double* adc, float* res, TF1*& f, float ped=0.0);
159  float analyzeWaveform(int select, TGraph* g, float* res, TF1*& f,float ped=0.0);
160  float analyzeWaveform(int select, StFcsHit* hit, float* res, TF1*& f,float ped=0.0);
161 
162  //Pedestal analysis methods
163  float AnaPed( TGraphAsymmErrors* g, float& ped, float& pedstd );
164  float AnaPed( StFcsHit* hit, float& ped, float& pedstd );
165  //actual analysis methods
166  float sum8 (TGraphAsymmErrors* g, float *res);
167  float sum16 (TGraphAsymmErrors* g, float *res);
168  float highest (TGraphAsymmErrors* g, float *res);
169  float highest3(TGraphAsymmErrors* g, float *res);
170  float gausFit (TGraphAsymmErrors* g, float *res, TF1*& f, float ped=0.0);
171  float gausFitWithPed (TGraphAsymmErrors* g, float *res, TF1*& f);
172  float PulseFit1(TGraphAsymmErrors* g, float* res, TF1*& f, float ped=0.0);
173  float PulseFit2(TGraphAsymmErrors* g, float* res, TF1*& f, float ped=0.0);
174  float PulseFitAll(TGraphAsymmErrors* g, float* res, TF1*& f, float ped=0.0);
175  float PulseFit2WithPed( TGraphAsymmErrors* g, float* res, TF1*& f);
176  float PulseFitAllWithPed( TGraphAsymmErrors* g, float* res, TF1*& f);
177  float PedFitPulseFit( TGraphAsymmErrors* g, float* res, TF1*& f);
178 
179  //Draw fits
180  void setMaxPage(int v){mMaxPage=v;}
181  void setSkip(int v){mSkip=v;}
182 
190  void setFileName(char* file, int maxpage=25, int skip=5){mFilename=file; mMaxPage=maxpage; mSkip=skip;}
191  void writeFile(std::string filename);
192 
201  void setFitDrawOn(int v=1) {mFitDrawOn=v;}
202  void setFitFilter(char* filter) {mFilter=filter; mFitDrawOn=2;}
203 
204  //Draw from David
205  int centerTB()const{return mCenterTB;}
208  StFcsPulseAna* InitFitter(Double_t ped=0);
209 
219  static int GenericPadPos(int value, int Nvals, int PadNums );
229  static int PadNum4x4(int det, int col, int row);
243  void drawRegion(int det, int col_low, int row_low, int col_high, int row_high, int event=0);
244  void drawEvent(int det, int event=0);
245  void drawFitter(Option_t* opt){ if(mPulseFit!=0){mPulseFit->Draw(opt);} }
246 
255  void drawCh(UInt_t detid, UInt_t ch) const;
265  void drawDualFit(UInt_t detid, UInt_t ch);
266 
267  void printArray() const;
268  void printSetup() const;
269 
270  protected:
271  TClonesArray mChWaveData;
272  void drawFit(TGraphAsymmErrors* gg, TF1* func);
274 
289  int mTest = 0;
290 
291  TFile* mOutFile;
292  //For testing Dep0 algo (mTest==1)
293  TH2F* mH2_Dep0DepMod[3];
294  TH2F* mH2_Sum8Dep0[3];
295  TH2F* mH2_Sum8DepMod[3];
296  //For testing number of peaks finding (mTest==2||mTest==3||mTest==6||mTest==8)
297  TH1F* mH1_NPeaksAkio = 0;
299  TH2F* mH2F_AdcTbAkio[6];
300  TH2F* mH2F_AdcTbMine[6];
303  TH2F* mH2F_APeakvMPeak[6];
304  TH1F* mH1F_PeakStart[6];
305  TH1F* mH1F_PeakEnd[6];
306  TH1F* mH1_PeakTiming = 0;
307 
308  TH1F* mH1F_NPeaks[7];
312  TH1F* mH1_VOverlap = 0;
313  TH2F* mH2_NOvsNPeaks = 0;
314  TH2F* mH2_VvsNOverlap = 0;
315  TH2F* mH2F_NOvsId[6];
316  TH1F* mH1F_Res0[7];
317  TH1F* mH1F_Res0Zoom[7];
318  TH1F* mH1F_Sum8Res0[7];
319  TH1F* mH1F_Sum8Res0Zoom[7];
320  TH1F* mH1F_FitRes0[7];
321  TH1F* mH1F_FitRes0Zoom[7];
322  TH2F* mH2F_Sum8vFit[7];
323  TH1F* mH1_TimeFitPulse = 0;
324 
325  //For testing peak height vs. sigma
326  TH2F* mH2_HeightvsSigma = 0;
328  TH1F* mH1_ChiNdf = 0;
329  TH2F* mH2_HeightvsChiNdf = 0;
330  TH2F* mH2_MeanvsChiNdf = 0;
331  TH2F* mH2_SigmavsChiNdf = 0;
332 
333  TH1F* mH1_PeakTimingGaus = 0;
334  TH1F* mH1_PeakTimingPuls = 0;
336 
337  void SetupDavidFitterMay2022(Double_t ped=0);
338 
345  int PeakCompare(const PeakWindow& pwin1, const PeakWindow& pwin2 );
354  std::vector<int> NPeaksPrePost(int& trigidx, Double_t& xmin, Double_t& xmax) const;
355 
356  private:
357  StFcsDb* mDb=0;
358  StFcsDbPulse* mDbPulse = 0;
359  StFcsCollection* mFcsCollection=0;
360 
361  unsigned int mHitIdx = 0;
362 
363  //Figures out error to set on the TGraphAsymmErrors for a given point and adc
364  char *mMeasureTime=0;
365 
366  int mEnergySelect[3];
367  double mEnergySumScale[3];
368  bool mAnaWaveform;
369  int mCenterTB=50;
370  int mMinTB=0;
371  int mMaxTB=512;
372 
373  double mError=1.0;
374  double mErrorSaturated=1000.0;
375  double mAdcSaturation=4000.0;
376 
377  int mPedMin=-1;
378  int mPedMax=-1;
379 
380  //gausFit
381  int mMinAdc=5;
382  int mTail=2;
383  int mMaxPeak=5;
384 
385  //Drawing fits
386  TCanvas* mCanvas=0;
387  int mPage=0;
388  int mPad=0;
389  int mMaxPage=25;
390  int mSkip=2;
391  char* mFilename=0;
392  char* mFilter=0;
393  char mDetName[100];
394  int mFitDrawOn=0;
395 
396  virtual const Char_t *GetCVS() const {static const Char_t cvs[]="Tag " __DATE__ " " __TIME__ ; return cvs;}
397 
398  ClassDef(StFcsWaveformFitMaker, 4)
399 };
400 #endif // STROOT_STFCSWAVEFORMFITMAKER_STFCSWAVEFORMFITMAKER_H_
TH2F * mH2_MeanvsChiNdf
Histogram of height vs. chi^2/ndf for all fits.
float sum8(TGraphAsymmErrors *g, float *res)
mEnergySelect=1
void drawCh(UInt_t detid, UInt_t ch) const
Draw a single channel on the current canvas/pad.
float PedFitPulseFit(TGraphAsymmErrors *g, float *res, TF1 *&f)
mEnergySelect=17, first find pedestal using #StFcsPulseAna::AnalyzePedestal() then call PulseFitAll()...
static int PadNum4x4(int det, int col, int row)
Helper function for drawRegion()
TH2F * mH2_SigmavsChiNdf
Histogram of chi^2/ndf for all fits.
float analyzeWaveform(int select, TGraphAsymmErrors *g, float *res, TF1 *&f, float ped=0.0)
Perfom the analysis using selected method.
void printSetup() const
Print contents of internal variables.
float PulseFit1(TGraphAsymmErrors *g, float *res, TF1 *&f, float ped=0.0)
mEnergySelect=12, find and fit selected peaks around triggered crossing using PeakCompare() ...
float highest(TGraphAsymmErrors *g, float *res)
mEnergySelect=3
void setPedTimeBins(int min, int max)
Set the timebin region where the pedestal occurs, for non-pedestal subtracted data.
TH1F * mH1F_PeakStart[6]
PeakWindow Starting x-values
void drawDualFit(UInt_t detid, UInt_t ch)
Special draw function, to compare fits for a single channel.
TH1F * mH1_TimeFitPulse
Histogram to time how long just the fitting takes in PulseFit1() and PulseFit2()
void setTail(int v)
Set tail parameters to use for #mDbPulse, see StFcsDbPulse::setTail()
TH1F * mH1_PeakTimingGaus
Histogram to test timing of gausFit()
float PulseFit2WithPed(TGraphAsymmErrors *g, float *res, TF1 *&f)
mEnergySelect=15, first find pedestal using #AnaPed(), then call PulseFit2()
TGraphAsymmErrors * getGraph(int idx=-1)
Return TGraphAsymmErrors at idx.
TH2F * mH2F_SumFitvSumWin[6]
Sum from Akio&#39;s Fit function vs. Sum from my found peak window for different number of peaks...
TGraphAsymmErrors * makeTGraphAsymmErrors(int n, double *t, double *adc)
Create TGraphAsymmErrors from given timebin and adc data.
TH1F * mH1_NPeaksFilteredAkio
Number of peaks found by gausFit() for signals that had a triggered crossing.
TH2F * mH2_NOvsNPeaks
NO (Number of overlaps) vs. Number of peaks.
TClonesArray mChWaveData
Contains all graph data.
TGraphAsymmErrors * resetGraph()
Create or Reset TGraphAsymmErrors (at #mHitIdx)
void setMaxPage(int v)
Max pages to draw.
int PeakCompare(const PeakWindow &pwin1, const PeakWindow &pwin2)
Compare if two peaks overlap and return a bit vector of tests passed/failed.
TH2F * mH2_VvsNOverlap
Compare value for that peak comparison vs. Overlap index.
void printArray() const
Print contents of mChWaveData, excluding timebin and adc information.
TH1F * mH1_PeakTiming
Timing for just peak finding.
virtual void Draw(Option_t *opt="")
Draw method for PeakAna.
Definition: PeakAna.cxx:984
void setAnaWaveform(bool value=true)
Set whether to compute integral of waveform (true); or just recompute energy (false); see #mAnaWavefo...
TH1F * mH1_PeakTimingPuls
Histogram to test timing of PulseFit1()
TH1F * mH1F_FitRes0Zoom[7]
same as mH1F_FitRes0 with finer bining at low end
void setFileName(char *file, int maxpage=25, int skip=5)
Set event drawing options.
StFcsPulseAna * InitFitter(Double_t ped=0)
Sets up basic values needed by StFcsPulseAna.
TH2F * mH2_PeakTimingCompare
Histogram to test timing between PulseFit1() vs. gausFit()
void SetupDavidFitterMay2022(Double_t ped=0)
This special function is used to set all the parameters for StFcsPulseAna based on cosmic and Run 22 ...
void drawFitter(Option_t *opt)
Call StFcsPulseAna::Draw()
float PulseFitAllWithPed(TGraphAsymmErrors *g, float *res, TF1 *&f)
mEnergySelect=16, first find pedestal using #AnaPed(), then call PulseFitAll()
void drawEvent(int det, int event=0)
Utilizes drawRegion() to draw all channels in an event.
TH1F * mH1_ChiNdf
Histogram of chi^2/ndf for all fits.
TH1F * mH1F_Res0Zoom[7]
Histogram of all res[0] with finer bining at low end.
void setDavidFitter(StFcsPulseAna *v)
Override mPulseFit, will be deleted.
TH2F * mH2F_APeakvMPeak[6]
PeakLocations from Akio vs. Mine.
float gausFit(TGraphAsymmErrors *g, float *res, TF1 *&f, float ped=0.0)
mEnergySelect=10
TH1F * mH1F_PeakEnd[6]
PeakWindow Ending x-values
TH1F * mH1F_Sum8Res0[7]
Histogram of &quot;res[0]&quot; using sum8 regardless of method called.
TH2F * mH2_HeightvsChiNdf
Histogram of height vs. chi^2/ndf for all fits.
float highest3(TGraphAsymmErrors *g, float *res)
mEnergySelect=4
TH2F * mH2F_Sum8vFit[7]
Histograms of Fit res[0] vs. sum8 res[0].
void drawFit(TGraphAsymmErrors *gg, TF1 *func)
Draw a single TGraph.
virtual void Clear(Option_t *option="")
User defined functions.
TH2F * mH2F_AdcTbValidPeak[7]
Adc vs. Tb from my algorithm that had a peak at #mCenterTb (Need an extra one for non-valid peaks) ...
TH2F * mH2_HeightvsSigma
Histogram of all fitted peak heights vs. their sigma.
TH2F * mH2_HeightvsSigmaTrig
Histogram of height of fitted peaks in triggered crossing vs. their sigma.
TH1F * mH1F_FitRes0[7]
Histogram of &quot;res[0]&quot; from fit regardless of method called.
TH2F * mH2F_AdcTbAkio[6]
Adc vs. Tb for different number of peaks Akio method.
float PulseFitAll(TGraphAsymmErrors *g, float *res, TF1 *&f, float ped=0.0)
mEnergySelect=14, fit all peaks less than mMaxPeak
TH1F * mH1F_Res0[7]
Histogram of all res[0] regardless of method.
TH2F * mH2F_NOvsId[6]
NO (number of overlaps) vs channel id for the 6 detector ids.
TH1F * mH1F_NPeaks[7]
Number of peaks found by peak finder StFcsPulseAna.
void writeFile(std::string filename)
Use to change the name of the file where test histograms will be saved.
TH2F * mH2_NPeakvsPeakYratio
Number of peaks vs. Peak Y ratio.
int mTest
Variable to use when testing StFcsWaveformFitMaker algorithms.
void setTest(int v)
Set test level. Intended to be used for single files. Output file name can be changed with writeFile(...
void setFitDrawOn(int v=1)
Sets how much channel data will saved in mChWaveData.
TH1F * mH1F_Sum8Res0Zoom[7]
same as mH1F_Sum8Res0 with finer bining at low end
void setMaxPeak(int v)
Set maximum number of peaks to fit, see #mMaxPeak.
float gausFitWithPed(TGraphAsymmErrors *g, float *res, TF1 *&f)
mEnergySelect=11
StFcsPulseAna * mPulseFit
Pointer to peak finder used by some analysis methods.
TH2F * mH2_NPeakvsPeakXdiff
Number of peaks vs. Peak X diff.
std::vector< int > NPeaksPrePost(int &trigidx, Double_t &xmin, Double_t &xmax) const
Finds out how many peaks are within a fixed number of pre-crossings and post-crossings.
static int GenericPadPos(int value, int Nvals, int PadNums)
Helper function for PadNum4x4.
void drawRegion(int det, int col_low, int row_low, int col_high, int row_high, int event=0)
draw a region of the Ecal or Hcal
float sum16(TGraphAsymmErrors *g, float *res)
mEnergySelect=2
float PulseFit2(TGraphAsymmErrors *g, float *res, TF1 *&f, float ped=0.0)
mEnergySelect=13, (default) find and fit selected peaks around triggered crossing using NPeaksPrePost...
TFile * mOutFile
Root output file for testing.
void setSkip(int v)
Number of channels to skip before drawing.
TH1F * mH1_VOverlap
Value of overlap.
TH1F * mH1_NPeaksAkio
Number of peaks found by gausFit()
TH1F * mH1F_NPeaksFiltered[7]
Number of peaks for cases where a peak around #mCenterTB was found.
TH2F * mH2F_AdcTbMine[6]
Adc vs. Tb for different number of peaks my method.
StFcsPulseAna * davidFitter()