ROOT logo
#ifndef HMDCGARCAL2MAKER_H
#define HMDCGARCAL2MAKER_H
#include "TNamed.h"
#include "TObject.h"

class TFile;
class TDirectory;
class TH1F;
class TH2F;
class TString;
class TGraph;

class HMdcGarCal2Maker : public TNamed {
protected:

    TString fNameAsciiOut;               //! file name of ascii output file
    FILE *output;                        //! file pointer to output
    TString fNameRootIn;                 //! file name of root input file
    TFile *inputRoot;                    //! root file pointer
    TFile *outputHists;                  //! root file pointer

    static Float_t cutMax[4];            //! cut at max drift time
    Float_t slope;                       //! slope of drift time/bin
    Int_t voltage[4];                    //! HV voltage for mdc types
  
    TH1F*   htime1;                      //! hist pointer for time1
    TH1F*   htime2;                      //! hist pointer for time2
    Int_t   lastvalidBin[4][18];         //! counter of non empty bins
    static Int_t   maxbinNumber[72];     //  max number of bins/hist

    Float_t mtime1    [4][18][100];      //! array of time1
    Float_t mtime2    [4][18][100];      //! array of time2
    Float_t mtime1_err[4][18][100];      //! array of error of time1
    Float_t mtime2_err[4][18][100];      //! array of error of time2

    Float_t mtime1_corr    [4][18][100]; //! array of corrected time1
    Float_t mtime2_corr    [4][18][100]; //! array of corrected time2
    Float_t mtime1_err_corr[4][18][100]; //! array of corrected error of time1
    Float_t mtime2_err_corr[4][18][100]; //! array of corrected error of time2

    Float_t max1 [4][18];                //! max 1
    Float_t max2 [4][18];                //! max 2
    Int_t max1bin[4][18];                //! bin max 1
    Int_t max2bin[4][18];                //! bin max 2

    Int_t threshold;                     //! threshold value (*stepsize=%)
    Int_t stepsize;                      //! %/step
    Bool_t isBatch;                      //! switch batch/no batch mode
    Bool_t writeHists;                   //! switch write Hists to cal2maker.root or not
    Bool_t printSpikes;                  //! switch print spikes or not
    Bool_t writeascii;                   //! switch for write/don't write asciie output
    Int_t version;                       //! old/new (1/2) file format
    Float_t maxErrTime1;                 //!
    Float_t maxErrTime2;                 //!
    Int_t removeSpike[4];                //! switch for removing spike types
    Float_t threshold1;                  //! threshold for spike removing
    Float_t threshold2;                  //! threshold for spike removing
    Int_t nTimes[4];                     //! number of smooth's per type

    Int_t nBin1D_dist;                   //!
    Int_t nBin2D_angle;                  //!
    Int_t nBin2D_dist;                   //!
    Int_t minCopy;                       //!
    Int_t maxCopy;                       //!

    Int_t activeHists_1D[4];             //!
    Int_t activeHists_2D[4];             //!

    TGraph* g[4][18][4][3];              //!
    Int_t levelColors[4];                //!
    Int_t makeMdc[4];                    //!
    Int_t makeType[4];                   //!

    void   initVariables();
    void   initArrays()
    {
	for(Int_t m=0;m<4;m++){
	    for(Int_t a=0;a<18;a++){
		for(Int_t b=0;b<100;b++){
		    mtime1    [m][a][b]=0;
		    mtime2    [m][a][b]=0;
		    mtime1_err[m][a][b]=0;
		    mtime2_err[m][a][b]=0;
                    mtime1_corr    [m][a][b]=0;
		    mtime2_corr    [m][a][b]=0;
		    mtime1_err_corr[m][a][b]=0;
		    mtime2_err_corr[m][a][b]=0;
		}
                max1[m][a]=0;
		max2[m][a]=0;
                max1bin[m][a]=0;
		max2bin[m][a]=0;
		lastvalidBin[m][a] =0;
		for(Int_t t=0;t<4;t++){
		    for(Int_t l=0;l<3;l++){
			g[m][a][t][l]=0;
		    }
		}
	    }
	}
    }
public:
    HMdcGarCal2Maker(const Char_t* name="",const Char_t* title="");
    ~HMdcGarCal2Maker();
    void    setFileNameOut(TString);
    void    setFileNameIn (TString);
    void    setCutMax(Float_t c0,Float_t c1,Float_t c2,Float_t c3)
    {
	cutMax[0]=c0;
        cutMax[1]=c1;
        cutMax[2]=c2;
        cutMax[3]=c3;
    }
    Int_t   getVersion()               {return version;}
    void    setVersion(Int_t vers)     {version=vers;}
    Float_t getCutMax(Int_t i)         {return  cutMax[i];}
    void    setSlope(Float_t s0)       {slope=s0;}
    Float_t getSlope()                 {return slope;}
    void    setThreshold(Int_t thresh) {threshold=thresh;}
    Int_t   getThreshold()             {return threshold;}
    void    setStepSize(Int_t size)    {stepsize=size;}
    Int_t   getStepSize()              {return stepsize;}
    void    setBatchMode(Bool_t mode)  {isBatch=mode;}
    Int_t   getBatchMode()             {return isBatch;}
    void    setPrintMode(Bool_t mode)  {printSpikes=mode;}
    Int_t   getPrintMode()             {return printSpikes;}
    void    setWriteHists(Bool_t write){writeHists=write;}
    Bool_t  getWriteHists()            {return writeHists;}
    void    setWriteAscii(Bool_t write){writeascii=write;}
    Bool_t  getWriteAscii()            {return writeascii;}
    void    setMaxErrTime1(Float_t e)  {maxErrTime1=e;}
    Float_t getMaxErrTime1()           {return maxErrTime1;}
    void    setMaxErrTime2(Float_t e)  {maxErrTime2=e;}
    Float_t getMaxErrTime2()           {return maxErrTime2;}
    void    setSpikeTypes(Int_t s0,Int_t s1,Int_t s2,Int_t s3)
    {
	removeSpike[0]=s0;
        removeSpike[1]=s1;
        removeSpike[2]=s2;
        removeSpike[3]=s3;
    }
    Int_t   getSpikeTypes(Int_t i)     {return removeSpike[i];}
    void    setSpikeThresholds(Float_t t1,Float_t t2)
    {
	threshold1=t1;
        threshold2=t2;
    }
    Float_t getSpikeThreshold1()       {return threshold1;}
    Float_t getSpikeThreshold2()       {return threshold2;}
    void    setNTimes(Int_t s0,Int_t s1,Int_t s2,Int_t s3)
    {
	nTimes[0]=s0;
        nTimes[1]=s1;
        nTimes[2]=s2;
        nTimes[3]=s3;
    }
    Int_t   getNTimes(Int_t i)         {return nTimes[i];}
    void    setNBin1D_Dist(Int_t b)    {nBin1D_dist=b;}
    Int_t   getNBin1D_Dist(       )    {return nBin1D_dist;}
    void    setNBin2D_Dist(Int_t b)    {nBin2D_dist=b;}
    Int_t   getNBin2D_Dist()           {return nBin2D_dist;}
    void    setNBin2D_Angle(Int_t b)   {nBin2D_angle=b;}
    Int_t   getNBin2D_Angle()          {return nBin2D_angle;}
    void    setMinCopy(Int_t b)        {minCopy=b;}
    Int_t   getMinCopy()               {return minCopy;}
    void    setMaxCopy(Int_t b)        {maxCopy=b;}
    Int_t   getMaxCopy()               {return maxCopy;}
    void    setHists_1D(Int_t i,Int_t j,Int_t k,Int_t l)
    {
	activeHists_1D[0]=i;
        activeHists_1D[1]=j;
	activeHists_1D[2]=k;
        activeHists_1D[3]=l;
    }
    Int_t   getHists_1D(Int_t i)       {return activeHists_1D[i];}
    void    setHists_2D(Int_t i,Int_t j,Int_t k,Int_t l)
    {
	activeHists_2D[0]=i;
        activeHists_2D[1]=j;
	activeHists_2D[2]=k;
        activeHists_2D[3]=l;
    }
    Int_t   getHists_2D(Int_t i)       {return activeHists_2D[i];}
    void    setMakeMdc(Int_t i,Int_t j,Int_t k,Int_t l)
    {
	makeMdc[0]=i;
        makeMdc[1]=j;
        makeMdc[2]=k;
        makeMdc[3]=l;
    }
    Int_t   getMakeMdc(Int_t i)       {return makeMdc[i];}
    void    setMakeType(Int_t i,Int_t j,Int_t k,Int_t l)
    {
	makeType[0]=i;
        makeType[1]=j;
        makeType[2]=k;
        makeType[3]=l;
    }
    Int_t   getMakeType(Int_t i)       {return makeType[i];}
    void    setLevelColors(Int_t i,Int_t j,Int_t k)
    {
	levelColors[0]=i;
        levelColors[1]=j;
        levelColors[2]=k;
    }
    Int_t   getLevelColors(Int_t i)    {return levelColors[i];}
    void    setVoltage(Int_t s0,Int_t s1,Int_t s2,Int_t s3)
    {
	voltage[0]=s0;
        voltage[1]=s1;
        voltage[2]=s2;
        voltage[3]=s3;
    }
    Int_t   getVoltage(Int_t i)        {return voltage[i];}
    void    setMaxBinNumber(Int_t* array)
    {
	for(Int_t i=0;i<72;i++){
           maxbinNumber[i]=array[i];
	}
    }
    Int_t   getMaxBinNumber(Int_t i)   {return maxbinNumber[i];}
    void    printStatus  (void);
    void    readInput    ();
    void    fillArrays   (TH1F*,TH1F*,Int_t,Int_t);
    void    fillControl2D(Int_t,Int_t,TString="");
    void    fillControl1D(Int_t,Int_t,TString="");
    void    findMax      (Int_t);
    void    removeSpikes (Int_t);
    void    copyToHist   (TH1F*,Int_t,Int_t,Int_t);
    void    copyToArray  (TH1F*,Int_t,Int_t,Int_t);
    Float_t coefSavGol2(Int_t,Int_t,Int_t,Int_t,Int_t,Int_t);
    void    do2dSavitzkyGolayFiltering(Float_t*,Int_t,Int_t,Bool_t);
    void    smoothHist   (TH1F*,Int_t);
    void    fitHist      (TH1F* h,Int_t,Int_t, Int_t);
    void    replaceBins  (TH1F*,Int_t,Int_t,Int_t);
    void    createGraph(Int_t,Int_t,Int_t);
    void    plotOverlay(Int_t,Int_t);
    void    writeAscii();
    Bool_t  check(Int_t,Int_t);
    void    calcBounderies(Int_t,Int_t,Float_t*,Float_t*);
    void    drawBorders(Int_t,Int_t,Int_t);
    void    make();
    ClassDef(HMdcGarCal2Maker,1) // Class for producing the MDC Cal2 parameters
};
#endif  /*!HMDCGARCAL2MAKER_H*/
 hmdcgarcal2maker.h:1
 hmdcgarcal2maker.h:2
 hmdcgarcal2maker.h:3
 hmdcgarcal2maker.h:4
 hmdcgarcal2maker.h:5
 hmdcgarcal2maker.h:6
 hmdcgarcal2maker.h:7
 hmdcgarcal2maker.h:8
 hmdcgarcal2maker.h:9
 hmdcgarcal2maker.h:10
 hmdcgarcal2maker.h:11
 hmdcgarcal2maker.h:12
 hmdcgarcal2maker.h:13
 hmdcgarcal2maker.h:14
 hmdcgarcal2maker.h:15
 hmdcgarcal2maker.h:16
 hmdcgarcal2maker.h:17
 hmdcgarcal2maker.h:18
 hmdcgarcal2maker.h:19
 hmdcgarcal2maker.h:20
 hmdcgarcal2maker.h:21
 hmdcgarcal2maker.h:22
 hmdcgarcal2maker.h:23
 hmdcgarcal2maker.h:24
 hmdcgarcal2maker.h:25
 hmdcgarcal2maker.h:26
 hmdcgarcal2maker.h:27
 hmdcgarcal2maker.h:28
 hmdcgarcal2maker.h:29
 hmdcgarcal2maker.h:30
 hmdcgarcal2maker.h:31
 hmdcgarcal2maker.h:32
 hmdcgarcal2maker.h:33
 hmdcgarcal2maker.h:34
 hmdcgarcal2maker.h:35
 hmdcgarcal2maker.h:36
 hmdcgarcal2maker.h:37
 hmdcgarcal2maker.h:38
 hmdcgarcal2maker.h:39
 hmdcgarcal2maker.h:40
 hmdcgarcal2maker.h:41
 hmdcgarcal2maker.h:42
 hmdcgarcal2maker.h:43
 hmdcgarcal2maker.h:44
 hmdcgarcal2maker.h:45
 hmdcgarcal2maker.h:46
 hmdcgarcal2maker.h:47
 hmdcgarcal2maker.h:48
 hmdcgarcal2maker.h:49
 hmdcgarcal2maker.h:50
 hmdcgarcal2maker.h:51
 hmdcgarcal2maker.h:52
 hmdcgarcal2maker.h:53
 hmdcgarcal2maker.h:54
 hmdcgarcal2maker.h:55
 hmdcgarcal2maker.h:56
 hmdcgarcal2maker.h:57
 hmdcgarcal2maker.h:58
 hmdcgarcal2maker.h:59
 hmdcgarcal2maker.h:60
 hmdcgarcal2maker.h:61
 hmdcgarcal2maker.h:62
 hmdcgarcal2maker.h:63
 hmdcgarcal2maker.h:64
 hmdcgarcal2maker.h:65
 hmdcgarcal2maker.h:66
 hmdcgarcal2maker.h:67
 hmdcgarcal2maker.h:68
 hmdcgarcal2maker.h:69
 hmdcgarcal2maker.h:70
 hmdcgarcal2maker.h:71
 hmdcgarcal2maker.h:72
 hmdcgarcal2maker.h:73
 hmdcgarcal2maker.h:74
 hmdcgarcal2maker.h:75
 hmdcgarcal2maker.h:76
 hmdcgarcal2maker.h:77
 hmdcgarcal2maker.h:78
 hmdcgarcal2maker.h:79
 hmdcgarcal2maker.h:80
 hmdcgarcal2maker.h:81
 hmdcgarcal2maker.h:82
 hmdcgarcal2maker.h:83
 hmdcgarcal2maker.h:84
 hmdcgarcal2maker.h:85
 hmdcgarcal2maker.h:86
 hmdcgarcal2maker.h:87
 hmdcgarcal2maker.h:88
 hmdcgarcal2maker.h:89
 hmdcgarcal2maker.h:90
 hmdcgarcal2maker.h:91
 hmdcgarcal2maker.h:92
 hmdcgarcal2maker.h:93
 hmdcgarcal2maker.h:94
 hmdcgarcal2maker.h:95
 hmdcgarcal2maker.h:96
 hmdcgarcal2maker.h:97
 hmdcgarcal2maker.h:98
 hmdcgarcal2maker.h:99
 hmdcgarcal2maker.h:100
 hmdcgarcal2maker.h:101
 hmdcgarcal2maker.h:102
 hmdcgarcal2maker.h:103
 hmdcgarcal2maker.h:104
 hmdcgarcal2maker.h:105
 hmdcgarcal2maker.h:106
 hmdcgarcal2maker.h:107
 hmdcgarcal2maker.h:108
 hmdcgarcal2maker.h:109
 hmdcgarcal2maker.h:110
 hmdcgarcal2maker.h:111
 hmdcgarcal2maker.h:112
 hmdcgarcal2maker.h:113
 hmdcgarcal2maker.h:114
 hmdcgarcal2maker.h:115
 hmdcgarcal2maker.h:116
 hmdcgarcal2maker.h:117
 hmdcgarcal2maker.h:118
 hmdcgarcal2maker.h:119
 hmdcgarcal2maker.h:120
 hmdcgarcal2maker.h:121
 hmdcgarcal2maker.h:122
 hmdcgarcal2maker.h:123
 hmdcgarcal2maker.h:124
 hmdcgarcal2maker.h:125
 hmdcgarcal2maker.h:126
 hmdcgarcal2maker.h:127
 hmdcgarcal2maker.h:128
 hmdcgarcal2maker.h:129
 hmdcgarcal2maker.h:130
 hmdcgarcal2maker.h:131
 hmdcgarcal2maker.h:132
 hmdcgarcal2maker.h:133
 hmdcgarcal2maker.h:134
 hmdcgarcal2maker.h:135
 hmdcgarcal2maker.h:136
 hmdcgarcal2maker.h:137
 hmdcgarcal2maker.h:138
 hmdcgarcal2maker.h:139
 hmdcgarcal2maker.h:140
 hmdcgarcal2maker.h:141
 hmdcgarcal2maker.h:142
 hmdcgarcal2maker.h:143
 hmdcgarcal2maker.h:144
 hmdcgarcal2maker.h:145
 hmdcgarcal2maker.h:146
 hmdcgarcal2maker.h:147
 hmdcgarcal2maker.h:148
 hmdcgarcal2maker.h:149
 hmdcgarcal2maker.h:150
 hmdcgarcal2maker.h:151
 hmdcgarcal2maker.h:152
 hmdcgarcal2maker.h:153
 hmdcgarcal2maker.h:154
 hmdcgarcal2maker.h:155
 hmdcgarcal2maker.h:156
 hmdcgarcal2maker.h:157
 hmdcgarcal2maker.h:158
 hmdcgarcal2maker.h:159
 hmdcgarcal2maker.h:160
 hmdcgarcal2maker.h:161
 hmdcgarcal2maker.h:162
 hmdcgarcal2maker.h:163
 hmdcgarcal2maker.h:164
 hmdcgarcal2maker.h:165
 hmdcgarcal2maker.h:166
 hmdcgarcal2maker.h:167
 hmdcgarcal2maker.h:168
 hmdcgarcal2maker.h:169
 hmdcgarcal2maker.h:170
 hmdcgarcal2maker.h:171
 hmdcgarcal2maker.h:172
 hmdcgarcal2maker.h:173
 hmdcgarcal2maker.h:174
 hmdcgarcal2maker.h:175
 hmdcgarcal2maker.h:176
 hmdcgarcal2maker.h:177
 hmdcgarcal2maker.h:178
 hmdcgarcal2maker.h:179
 hmdcgarcal2maker.h:180
 hmdcgarcal2maker.h:181
 hmdcgarcal2maker.h:182
 hmdcgarcal2maker.h:183
 hmdcgarcal2maker.h:184
 hmdcgarcal2maker.h:185
 hmdcgarcal2maker.h:186
 hmdcgarcal2maker.h:187
 hmdcgarcal2maker.h:188
 hmdcgarcal2maker.h:189
 hmdcgarcal2maker.h:190
 hmdcgarcal2maker.h:191
 hmdcgarcal2maker.h:192
 hmdcgarcal2maker.h:193
 hmdcgarcal2maker.h:194
 hmdcgarcal2maker.h:195
 hmdcgarcal2maker.h:196
 hmdcgarcal2maker.h:197
 hmdcgarcal2maker.h:198
 hmdcgarcal2maker.h:199
 hmdcgarcal2maker.h:200
 hmdcgarcal2maker.h:201
 hmdcgarcal2maker.h:202
 hmdcgarcal2maker.h:203
 hmdcgarcal2maker.h:204
 hmdcgarcal2maker.h:205
 hmdcgarcal2maker.h:206
 hmdcgarcal2maker.h:207
 hmdcgarcal2maker.h:208
 hmdcgarcal2maker.h:209
 hmdcgarcal2maker.h:210
 hmdcgarcal2maker.h:211
 hmdcgarcal2maker.h:212
 hmdcgarcal2maker.h:213
 hmdcgarcal2maker.h:214
 hmdcgarcal2maker.h:215
 hmdcgarcal2maker.h:216
 hmdcgarcal2maker.h:217
 hmdcgarcal2maker.h:218
 hmdcgarcal2maker.h:219
 hmdcgarcal2maker.h:220
 hmdcgarcal2maker.h:221
 hmdcgarcal2maker.h:222
 hmdcgarcal2maker.h:223
 hmdcgarcal2maker.h:224
 hmdcgarcal2maker.h:225
 hmdcgarcal2maker.h:226
 hmdcgarcal2maker.h:227
 hmdcgarcal2maker.h:228
 hmdcgarcal2maker.h:229
 hmdcgarcal2maker.h:230
 hmdcgarcal2maker.h:231
 hmdcgarcal2maker.h:232
 hmdcgarcal2maker.h:233
 hmdcgarcal2maker.h:234
 hmdcgarcal2maker.h:235
 hmdcgarcal2maker.h:236
 hmdcgarcal2maker.h:237
 hmdcgarcal2maker.h:238
 hmdcgarcal2maker.h:239
 hmdcgarcal2maker.h:240
 hmdcgarcal2maker.h:241
 hmdcgarcal2maker.h:242
 hmdcgarcal2maker.h:243
 hmdcgarcal2maker.h:244
 hmdcgarcal2maker.h:245