StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
BemcHitList.cxx
1 #include <string.h>
2 #include <assert.h>
3 #include <cmath>
4 
5 #include <StMessMgr.h>
6 
7 #include "BemcHitList.h"
8 
9 #include "StMaker.h"
10 #include "StEmcRawMaker/StBemcTables.h"
11 #include "StEmcRawMaker/defines.h"
12 #include "StEmcUtil/geometry/StEmcGeom.h"
13 #include "StEmcDetector.h"
14 #include "StEmcModule.h"
15 #include "StEmcRawHit.h"
16 //Rxy = 222, 242, 262 cm
17 
18 
19 namespace StEvPPV {
20 //==========================================================
21 //==========================================================
22 BemcHitList::BemcHitList() :
23  ScintHitList(0.,M_PI/60,120, -1.,0.05,40,(char *) "Bemc",4,0.75) {
24  myTable = new StBemcTables();
25  geomB = StEmcGeom::instance("bemc");
26  kSigPed=5.0;
27 
28  gMessMgr->Message("","I")
29  <<" BemcHitList::use kSigPed="<<kSigPed
30  <<endm;
31 }
32 
33 
34 //==========================================================
35 //==========================================================
36 void
37 BemcHitList::initRun() {
38  LOG_DEBUG <<Form("BemcHitList::initRun() start")<<endm;
39  ScintHitList::initRun();
40  // clear old lookup table
41  int i,j,k;
42  for(i=0;i<mxm;i++)
43  for(j=0;j<mxe;j++)
44  for(k=0;k<mxs;k++)
45  mes2bin[i][j][k]=-1;
46 
47  // .. grab table
48  StMaker*mk=(StMaker*)StMaker::GetChain()->GetMaker("GenericVertex");
49  assert(mk);
50  myTable->loadTables(mk );
51 
52  int nB=0,nA=0;
53  int id;
54  for(id=1; id<=BTOWSIZE; id++) {
55 
56  //........... querry BTOW DB/geom
57  int status;
58  myTable->getStatus(BTOW, id, status);
59  int m,e,s;
60  geomB->getBin(id,m,e,s);
61  float eta,phi;
62  geomB->getEta(m,e,eta);
63  geomB->getPhi(m,s,phi); // -pi <= phi < pi
64  if( phi<0) phi+=2*M_PI; // I want phi in [0,2Pi]
65 
66  //........... convert it to private bins
67  int iEta=etaBin(eta);
68  int iPhi=phiBin(phi);
69  assert( iEta>=0);
70  assert( iPhi>=0);
71  int iBin=iPhiEta2bin(iPhi,iEta);
72 
73  // if(id<41)
74  // printf("%d %d id=%d m,e,s=%d:%d:%d eta=%.4f phi/deg=%.2f bin %d:%d:%d\n",
75  // eta<0 && phi>M_PI, status, id,m,e,s,eta,phi/M_PI*180,iPhi,iEta,iBin);
76  assert(mes2bin[m-1][e-1][s-1]==-1); //tmp, to check BTOW code
77  mes2bin[m-1][e-1][s-1]=iBin;
78 
79  nB++;
80  if( status!= 1) continue; // drop broken towers
81 
82  setActive(iBin);
83  nA++;
84  }
85 
86  LOG_INFO <<" BemcHitList::initRun() done, active="<<nA<<" of "<<nB<<" BTOW towers" <<endm;
87 
88 }
89 
90 //==========================================================
91 //==========================================================
92 void
93 BemcHitList::clear(){
94  ScintHitList::clear();
95 
96 }
97 
98 //==========================================================
99 //==========================================================
100 int
101 BemcHitList::etaBin(float eta){
102  if(fabs(eta)>0.99) return -1; // 20th eta bin is only 0.04 wide in eta
103  int iEta=(int)((eta-eta0)/dEta);
104  if(iEta<0 || iEta>=nEta) return -1; // out of Eta range
105  return iEta;
106 }
107 
108 //==========================================================
109 //==========================================================
110 float
111 BemcHitList::bin2EtaLeft(int iEta){
112  assert(iEta>=0);
113  assert(iEta<nEta);
114  float etaF= eta0+iEta*dEta ;
115  if(etaF<-0.99) etaF=0.99;
116  return etaF;
117 }
118 
119 
120 //==========================================================
121 //==========================================================
122 BemcHitList::~BemcHitList(){
123 
124 }
125 
126 //==========================================================
127 //==========================================================
128 void
129 BemcHitList::build ( StEmcDetector*det, float adcMin){
130  for(int m = 1; m<=BEMCMODULES;m++) { //loop on modules...
131  StEmcModule* module = det->module(m);
132  assert(module);
133  StSPtrVecEmcRawHit& rawHit=module->hits();
134  for(UInt_t k=0;k<rawHit.size();k++) { //loop on hits in modules
135  // check geometry
136  int m=rawHit[k]->module();
137  int e=rawHit[k]->eta();
138  int s=abs(rawHit[k]->sub());
139  int iBin=mes2bin[m-1][e-1][s-1];
140 
141  if ( getActive(iBin)<0) continue;
142 
143  int id;
144  geomB->getId(m,e,s,id); // to get the software id
145  Float_t ped,sig;
146  myTable->getPedestal(BTOW, id, 0, ped,sig);
147  float rawAdc = rawHit[k]->adc();
148  if( rawAdc<ped+ kSigPed*sig ) continue;
149  float adc= rawAdc -ped;
150  if(adc< adcMin) continue;
151  setFired(iBin);
152  }
153  }
154 
155 };
156 }// end namespace StEvPPV
157 
158 /*
159  I think you want something like:
160  myTable->getCalib(BTOW, id, 1, gain);
161  getCalib instead of getGain. It is a bit confiusing, but there are two
162  sets of calibration constants. The ones called 'calib' are the ones you
163  want. The 'gain tables' coudl in principle hold a second, relative gain
164  calibration (that might vary on a shorter timescale), but this option is
165  not used at the moment, so they are all one.
166 */
void getPedestal(Int_t det, Int_t softId, Int_t cap, Float_t &ped, Float_t &rms) const
Return pedestal mean and rms.
void loadTables(StMaker *anyMaker)
load tables.
Int_t getBin(const Float_t phi, const Float_t eta, Int_t &m, Int_t &e, Int_t &s) const
Definition: StEmcGeom.h:321
void getStatus(Int_t det, Int_t softId, Int_t &status, const char *option="") const
Return status.