ROOT logo
#ifndef HMDCDEDX2_H
#define HMDCDEDX2_H
#include "TArrayF.h"
#include "TH2.h"
#include "TCanvas.h"
#include "TGraph.h"
#include "hparcond.h"
#include "hlocation.h"

class HParamList;
class HLocation;
class HCategory;
class HMdcSeg;
class HMdcSizesCells;
class HGeantKine;


#define MAX_WIRES 80
#define N_ANGLE 18
#define N_DIST  40
#define N_PARAM  4
#define N_SHIFT_PARAM 2

#define ref_MOD 1
#define ref_ANGLE 90
#define ref_DIST 15

class HMdcDeDx2 : public HParCond {
protected:

     Double_t par     [6][4][N_ANGLE][N_DIST][N_PARAM];       // fitparams  for tot->dedx
     Double_t shiftpar[6][4][N_ANGLE][N_DIST][N_SHIFT_PARAM]; // width of tot distribution
     Double_t parMax  [6][4][N_ANGLE][N_DIST];                // max val for tot in tot->dEdx

     Double_t pargaincorr[6][4][6][220];  // gain correction per wire
     Double_t parmindistcut[4];           // max value for mindist used for calculate dEdx

     static Float_t MaxMdcMinDist[4];   // max value for mindist

     Float_t MinDistStep[4];            // step size for mindist
     Float_t AngleStep;                 // step size for angle
     Double_t hefr;                     // fraction of helium of the gas mix
     Int_t minimumWires;                // minimum required wires
     Float_t window;                    // window for truncating arround mean (units of sigma)

     HMdcSizesCells *sizescells;        //! pointer to HMdcSizesCells container
     HCategory* catcal;                 //! pointer to mdc cal1
     HCategory* cathit;                 //! pointer to mdc hit
     HCategory* catclusinf;             //! pointer to mdc clusinf
     HCategory* catclus;                //! pointer to mdc clusinf
     HLocation loccal;                  //! location object of cal1

     Bool_t isInitialized;              //! flag after init
     Int_t method;                      //! method switch for filling input
     Int_t module;                      //! method switch for filling input for module 1/2 of segment

     TArrayD measurements;              //! array of measurements
     Bool_t  useCalibration;            //! use/don't use normalization table
     Int_t ctskipmod0;                  //! counter for wires skipped with t2<=-998 in mod0 of seg
     Int_t ctskipmod1;                  //! counter for wires skipped with t2<=-998 in mod1 of seg
     static Bool_t debug;                //! kTRUE print infos of trun mean

     void     sort(Int_t);
     UChar_t  fillingInput (HMdcSeg* seg[2], Int_t inputselect = 0);
     UChar_t  select       (Float_t,Float_t,UChar_t,Float_t wind = -99.);
     void     calcSegPoints(HMdcSeg *,Double_t&,Double_t&,Double_t&,Double_t&,Double_t&,Double_t&);
     Double_t calcLength   (Int_t m,Double_t angle,Double_t dist);

 public:
    HMdcDeDx2(const Char_t* name   = "MdcDeDx2",
	      const Char_t* title  = "Mdc lookup for MDC dEdX calculation",
	      const Char_t* context= "MdcDeDx2Production");
    ~HMdcDeDx2();

    Bool_t    initContainer();
    Bool_t    createMaxPar(Bool_t print = kFALSE);

    void      putParams(HParamList*);
    Bool_t    getParams(HParamList*);
    void      clear();
    void      printParam(TString opt = "all");

    //------------set Parameters-----------------------
    void       setFuncPar     (Int_t s,Int_t m,Int_t abin,Int_t dbin,Double_t* p,Int_t size);
    void       setFuncPar     (Double_t* p);
    void       setFuncMaxPar  (Int_t s,Int_t m,Int_t abin,Int_t dbin,Double_t val);
    void       setFuncMaxPar  (Double_t* p);
    void       setFuncWidthPar(Int_t s,Int_t m,Int_t abin,Int_t dbin,Double_t* p,Int_t size);
    void       setFuncWidthPar(Double_t* p);

    void       setFuncGainPar(Int_t s,Int_t m,Int_t l,Int_t c,Double_t p);
    void       setFuncGainPar(Double_t* p);
    void       setMinDistCutPar(Int_t m,Double_t p);
    void       setMinDistCutPar(Double_t* p);

    Double_t*  getFuncPar     (Int_t s,Int_t m,Int_t abin,Int_t dbin){return &par[s][m][abin][dbin][0];}
    void       getFuncPar     (Double_t* p);
    Double_t   getFuncMaxPar  (Int_t s,Int_t m,Int_t abin,Int_t dbin){return parMax[s][m][abin][dbin];}
    void       getFuncMaxPar  (Double_t* p);
    Double_t*  getFuncWidthPar(Int_t s,Int_t m,Int_t abin,Int_t dbin){return &shiftpar[s][m][abin][dbin][0];}
    void       getFuncWidthPar(Double_t* p);

    Double_t   getFuncGainPar (Int_t s,Int_t m,Int_t l,Int_t c){return pargaincorr[s][m][l][c];}
    void       getFuncGainPar (Double_t* p);
    Double_t   getMinDistCutPar(Int_t m,Double_t p){return parmindistcut[m];}
    void       getMinDistCutPar(Double_t* p);

    Int_t      getN_Param(void)       {return N_PARAM;}
    Int_t      getN_Shift_Param(void) {return N_SHIFT_PARAM;}
    Int_t      getN_Angle(void)       {return N_ANGLE;}
    Int_t      getN_Dist(void)        {return N_DIST;}

    //------------set user values----------------------
    Float_t   getWindow()                    {return window;}
    void      setWindow(Float_t win)         {window = win;}
    Int_t     getMinimumWires()              {return minimumWires;}
    void      setMinimumWires(Int_t minwires){minimumWires = minwires;}
    static void setDebugMode(Bool_t dodebug)   {debug = dodebug;}
    void      setUseCalibration(Bool_t ok)   {useCalibration = ok;}
    Double_t* getArray (Int_t& size)         {size = MAX_WIRES; return measurements.GetArray();}
    Float_t   calcDeDx(HMdcSeg* seg[2],Float_t*,Float_t*,UChar_t*,Float_t*,UChar_t*,
		      Int_t vers = 2,Int_t mod = 2, Bool_t useTruncMean = kTRUE, Float_t truncMeanWindow = -99.,Int_t inputselect = 0);
    //------------conversion------------------------
    Double_t toTTodEdX(Int_t s,Int_t m,Int_t l,Int_t c,Double_t angle,Double_t mindist,Double_t ToT);
    Double_t dEdXToToT(Int_t s,Int_t m,Int_t l,Int_t c,Double_t angle,Double_t mindist,Double_t dEdX);
    Double_t toTSigma (Int_t s,Int_t m,Double_t angle,Double_t mindist,Int_t shift = 0);
    Double_t normalize(Int_t s,Int_t m,Int_t l,Int_t c,Double_t angle,Double_t mindist,Double_t ToT);
    void     findBin  (Int_t m,Double_t* angle,Double_t* mindist,Int_t* abin,Int_t* dbin);

    //------------energy loss-----------------------
    void      setHeFraction(Double_t fr)     {hefr = fr;}
    Double_t  getHeFraction()                {return hefr;}
    static Double_t  beta(Int_t id, Double_t p);
    static Double_t  gamma(Int_t id, Double_t p);
    static Double_t  energyLoss     (Int_t id,Double_t p,Double_t hefr = 0.6);
    static TGraph*   energyLossGraph(Int_t id,Double_t hefr = 0.6,TString opt = "p",Bool_t exchange = kFALSE,Int_t markerstyle = 8,Int_t markercolor = 2,Float_t markersize = 0.7);
    static TGraph*   betaGraph(Int_t id,Int_t opt = 1,Int_t markerstyle = 8,Int_t markercolor = 2,Float_t markersize =0.7);
    Double_t         scaledTimeAboveThreshold(HGeantKine* kine = 0,Double_t p = -1,
                                              Float_t t1 = -999, Float_t t2 = -999,Float_t* t2err = 0,
					      Int_t s = 0,Int_t m = 0,Int_t l = 0,Int_t c = 0,Double_t alpha = 0,Double_t mindist = 0);
    ClassDef(HMdcDeDx2,2) //  MDC lookup table (dedx2 normalization parameters)
};
#endif  /*!HMDCDEDX2_H*/
 hmdcdedx2.h:1
 hmdcdedx2.h:2
 hmdcdedx2.h:3
 hmdcdedx2.h:4
 hmdcdedx2.h:5
 hmdcdedx2.h:6
 hmdcdedx2.h:7
 hmdcdedx2.h:8
 hmdcdedx2.h:9
 hmdcdedx2.h:10
 hmdcdedx2.h:11
 hmdcdedx2.h:12
 hmdcdedx2.h:13
 hmdcdedx2.h:14
 hmdcdedx2.h:15
 hmdcdedx2.h:16
 hmdcdedx2.h:17
 hmdcdedx2.h:18
 hmdcdedx2.h:19
 hmdcdedx2.h:20
 hmdcdedx2.h:21
 hmdcdedx2.h:22
 hmdcdedx2.h:23
 hmdcdedx2.h:24
 hmdcdedx2.h:25
 hmdcdedx2.h:26
 hmdcdedx2.h:27
 hmdcdedx2.h:28
 hmdcdedx2.h:29
 hmdcdedx2.h:30
 hmdcdedx2.h:31
 hmdcdedx2.h:32
 hmdcdedx2.h:33
 hmdcdedx2.h:34
 hmdcdedx2.h:35
 hmdcdedx2.h:36
 hmdcdedx2.h:37
 hmdcdedx2.h:38
 hmdcdedx2.h:39
 hmdcdedx2.h:40
 hmdcdedx2.h:41
 hmdcdedx2.h:42
 hmdcdedx2.h:43
 hmdcdedx2.h:44
 hmdcdedx2.h:45
 hmdcdedx2.h:46
 hmdcdedx2.h:47
 hmdcdedx2.h:48
 hmdcdedx2.h:49
 hmdcdedx2.h:50
 hmdcdedx2.h:51
 hmdcdedx2.h:52
 hmdcdedx2.h:53
 hmdcdedx2.h:54
 hmdcdedx2.h:55
 hmdcdedx2.h:56
 hmdcdedx2.h:57
 hmdcdedx2.h:58
 hmdcdedx2.h:59
 hmdcdedx2.h:60
 hmdcdedx2.h:61
 hmdcdedx2.h:62
 hmdcdedx2.h:63
 hmdcdedx2.h:64
 hmdcdedx2.h:65
 hmdcdedx2.h:66
 hmdcdedx2.h:67
 hmdcdedx2.h:68
 hmdcdedx2.h:69
 hmdcdedx2.h:70
 hmdcdedx2.h:71
 hmdcdedx2.h:72
 hmdcdedx2.h:73
 hmdcdedx2.h:74
 hmdcdedx2.h:75
 hmdcdedx2.h:76
 hmdcdedx2.h:77
 hmdcdedx2.h:78
 hmdcdedx2.h:79
 hmdcdedx2.h:80
 hmdcdedx2.h:81
 hmdcdedx2.h:82
 hmdcdedx2.h:83
 hmdcdedx2.h:84
 hmdcdedx2.h:85
 hmdcdedx2.h:86
 hmdcdedx2.h:87
 hmdcdedx2.h:88
 hmdcdedx2.h:89
 hmdcdedx2.h:90
 hmdcdedx2.h:91
 hmdcdedx2.h:92
 hmdcdedx2.h:93
 hmdcdedx2.h:94
 hmdcdedx2.h:95
 hmdcdedx2.h:96
 hmdcdedx2.h:97
 hmdcdedx2.h:98
 hmdcdedx2.h:99
 hmdcdedx2.h:100
 hmdcdedx2.h:101
 hmdcdedx2.h:102
 hmdcdedx2.h:103
 hmdcdedx2.h:104
 hmdcdedx2.h:105
 hmdcdedx2.h:106
 hmdcdedx2.h:107
 hmdcdedx2.h:108
 hmdcdedx2.h:109
 hmdcdedx2.h:110
 hmdcdedx2.h:111
 hmdcdedx2.h:112
 hmdcdedx2.h:113
 hmdcdedx2.h:114
 hmdcdedx2.h:115
 hmdcdedx2.h:116
 hmdcdedx2.h:117
 hmdcdedx2.h:118
 hmdcdedx2.h:119
 hmdcdedx2.h:120
 hmdcdedx2.h:121
 hmdcdedx2.h:122
 hmdcdedx2.h:123
 hmdcdedx2.h:124
 hmdcdedx2.h:125
 hmdcdedx2.h:126
 hmdcdedx2.h:127
 hmdcdedx2.h:128
 hmdcdedx2.h:129
 hmdcdedx2.h:130
 hmdcdedx2.h:131
 hmdcdedx2.h:132
 hmdcdedx2.h:133
 hmdcdedx2.h:134
 hmdcdedx2.h:135
 hmdcdedx2.h:136
 hmdcdedx2.h:137
 hmdcdedx2.h:138
 hmdcdedx2.h:139
 hmdcdedx2.h:140
 hmdcdedx2.h:141
 hmdcdedx2.h:142
 hmdcdedx2.h:143