StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StMuFcsHit.cxx
1 /***************************************************************************
2  *
3  * $Id: StMuFcsHit.cxx,v 1.0 2021/11/17 03:57:39 jdb Exp $
4  *
5  * Author: jdb, 2021
6  ***************************************************************************
7  *
8  * Description: StMuFcsHit is data for individual cell
9  *
10  ***************************************************************************
11  *
12  **************************************************************************/
13 #include "StMuFcsHit.h"
14 #include "TString.h"
15 
16 #include "StMuFcsCluster.h"
17 ClassImp(StMuFcsHit)
18 
19 StMuFcsHit::StMuFcsHit() { /* no operation */}
20 
21 StMuFcsHit::StMuFcsHit(unsigned short zs, unsigned short det, unsigned short id,
22  unsigned short ns, unsigned short ehp, unsigned short dep, unsigned short ch,
23  int ntimebin, unsigned short* data)
24 {
25  setFcsHit(zs, det, id, ns, ehp, dep, ch, ntimebin, data);
26 }
27 StMuFcsHit::StMuFcsHit(unsigned short zs, unsigned short det, unsigned short id,
28  unsigned short ns, unsigned short ehp, unsigned short dep, unsigned short ch,
29  float e)
30 {
31  setFcsHit(zs, det, id, ns, ehp, dep, ch, e);
32 }
33 
34 StMuFcsHit::~StMuFcsHit() {
35  mData.Set(0);
36 }
37 
38 unsigned short StMuFcsHit::zs() const {return (mDetId >> 15 ) & 0x0001;}
39 unsigned short StMuFcsHit::detectorId() const {return (mDetId >> 12 ) & 0x0007;}
40 unsigned short StMuFcsHit::id() const {return (mDetId ) & 0x0fff;}
41 unsigned short StMuFcsHit::ns() const {return (mDepCh >> 15 ) & 0x01;}
42 unsigned short StMuFcsHit::ehp() const {return (mDepCh >> 13 ) & 0x03;}
43 unsigned short StMuFcsHit::dep() const {return (mDepCh >> 8 ) & 0x1f;}
44 unsigned short StMuFcsHit::channel() const {return (mDepCh ) & 0xff;}
45 unsigned int StMuFcsHit::nTimeBin() const {
46  if(zs()) return mData.GetSize()/2;
47  return mData.GetSize();
48 }
49 unsigned short StMuFcsHit::data(int i) const {return mData.At(i);}
50 unsigned short StMuFcsHit::timebin(int i) const {
51  if(zs()) return mData.At(i*2+1);
52  return i;
53 }
54 unsigned short StMuFcsHit::adc(int i) const {
55  if(zs()) return mData.At(i*2 ) & 0xfff;
56  return mData.At(i) & 0xfff;
57 }
58 unsigned short StMuFcsHit::flag(int i) const {
59  if(zs()) return mData.At(i*2 ) >> 12;
60  return mData.At(i) >> 12;
61 }
62 
63 int StMuFcsHit::adcSum() const {return mAdcSum;}
64 float StMuFcsHit::fitPeak() const {return mFitPeak;}
65 float StMuFcsHit::fitSigma() const {return mFitSigma;}
66 float StMuFcsHit::fitChi2() const {return mFitChi2;}
67 int StMuFcsHit::nPeak() const {return mNPeak;}
68 float StMuFcsHit::energy() const {return mEnergy;}
69 
70 void StMuFcsHit::setDepCh(unsigned short ns, unsigned short ehp, unsigned short dep, unsigned short ch) {
71  mDepCh = (ns << 15) | (ehp<<13) | (dep<<8) | ch;
72 }
73 void StMuFcsHit::setNS(unsigned short val) { setDepCh(val,ehp(),dep(),channel());}
74 void StMuFcsHit::setEHP(unsigned short val) { setDepCh(ns(),val,dep(),channel());}
75 void StMuFcsHit::setDep(unsigned short val) { setDepCh(ns(),ehp(),val,channel());}
76 void StMuFcsHit::setChannel(unsigned short val) { setDepCh(ns(),ehp(),dep(),val);}
77 
78 void StMuFcsHit::setDetId(unsigned short zs, unsigned short det, unsigned short id) {
79  mDetId = (zs & 0x1)<<15 | (det & 0x7)<<12 | (id & 0xfff);
80 }
81 void StMuFcsHit::setZS(unsigned short val) { setDetId(val,detectorId(),id()); }
82 void StMuFcsHit::setDetectorId(unsigned short val) { setDetId(zs(),val,id()); }
83 void StMuFcsHit::setId(unsigned short val) { setDetId(zs(),detectorId(),val); }
84 
85 void StMuFcsHit::setData(int ndata, const unsigned short* data) {
86  mData.Set(ndata,(const short*)data);
87 }
88 void StMuFcsHit::setDataAt(int i, unsigned short val) { mData.AddAt(val,i); }
89 void StMuFcsHit::setAdcFlag(int i, unsigned short adc, unsigned short flag) { mData.AddAt(((flag&0xf)<<12) + adc, i); }
90 void StMuFcsHit::setAdc(int i, unsigned short val) { setAdcFlag(i,val,flag(i)); }
91 void StMuFcsHit::setFlag(int i, unsigned short val) { setAdcFlag(i,adc(i),val); }
92 
93 void StMuFcsHit::setAdcSum(int val) { mAdcSum = val; }
94 void StMuFcsHit::setFitPeak(float val) { mFitPeak = val; }
95 void StMuFcsHit::setFitSigma(float val) { mFitSigma = val; }
96 void StMuFcsHit::setFitChi2(float val) { mFitChi2 = val; }
97 void StMuFcsHit::setNPeak(int val) { mNPeak = val; }
98 void StMuFcsHit::setEnergy(float val) { mEnergy = val; }
99 
100 void StMuFcsHit::setFcsHit(unsigned short zs, unsigned short det, unsigned short id,
101  unsigned short ns, unsigned short ehp, unsigned short dep, unsigned short ch,
102  int ntimebin, unsigned short* data) {
103  setDetId(zs, det,id);
104  setDepCh(ns,ehp,dep,ch);
105  setData(ntimebin,data);
106 }
107 void StMuFcsHit::setFcsHit(unsigned short zs, unsigned short det, unsigned short id,
108  unsigned short ns, unsigned short ehp, unsigned short dep, unsigned short ch,
109  float e) {
110  setDetId(zs, det,id);
111  setDepCh(ns,ehp,dep,ch);
112  unsigned short data[2]={0,0};
113  if(zs==0) {
114  setData(1,data);
115  }
116  else {
117  setData(2,data);
118  }
119  setEnergy(e);
120 }
121 
122 void StMuFcsHit::print(Option_t *option) const {
123  cout << Form("StMuFcsHit: det=%2d id=%3d | ns=%1d ehp=%1d dep=%2d ch=%2d | Ntb=%3d Sum=%6d Fit=%6.2f %6.2f E=%6.2f | ",
124  detectorId(),id(),ns(),ehp(),dep(),channel(),
125  nTimeBin(),adcSum(),fitPeak(),fitSigma(),energy());
126  for(unsigned int i=0; i<nTimeBin(); i++) {
127  //if(timebin(i)>30 && timebin(i)<60)
128  cout << Form("%4d (%3d) ",adc(i),timebin(i));
129  }
130  cout << endl;
131 }
132 
133 
134 void StMuFcsHit::setCluster( StMuFcsCluster* cluster ){
135  mCluster = cluster;
136 }
137 
138 StMuFcsCluster* StMuFcsHit::cluster() {
139  return static_cast<StMuFcsCluster*>( mCluster.GetObject() );
140 }
141 
142 const StMuFcsCluster* StMuFcsHit::cluster() const {
143  return static_cast<StMuFcsCluster*>( mCluster.GetObject() );
144 }