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