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 <St_base/StMessMgr.h>
6 #include "St_db_Maker/St_db_Maker.h"
7 
8 #include "StGenericVertexMaker/StiPPVertex/BemcHitList.h"
9 
10 #include "StChain/StMaker.h"
11 #include "StEmcRawMaker/StBemcTables.h"
12 #include "StEmcRawMaker/defines.h"
13 #include "StEmcUtil/geometry/StEmcGeom.h"
14 #include "StEvent/StEmcDetector.h"
15 #include "StEvent/StEmcModule.h"
16 #include "StEvent/StEmcRawHit.h"
17 //Rxy = 222, 242, 262 cm
18 
19 
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(St_db_Maker* db_maker) {
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  myTable->loadTables(db_maker);
49 
50  int nB=0,nA=0;
51  int id;
52  for(id=1; id<=BTOWSIZE; id++) {
53 
54  //........... querry BTOW DB/geom
55  int status;
56  myTable->getStatus(BTOW, id, status);
57  int m,e,s;
58  geomB->getBin(id,m,e,s);
59  float eta,phi;
60  geomB->getEta(m,e,eta);
61  geomB->getPhi(m,s,phi); // -pi <= phi < pi
62  if( phi<0) phi+=2*M_PI; // I want phi in [0,2Pi]
63 
64  //........... convert it to private bins
65  int iEta=etaBin(eta);
66  int iPhi=phiBin(phi);
67  assert( iEta>=0);
68  assert( iPhi>=0);
69  int iBin=iPhiEta2bin(iPhi,iEta);
70 
71  // if(id<41)
72  // printf("%d %d id=%d m,e,s=%d:%d:%d eta=%.4f phi/deg=%.2f bin %d:%d:%d\n",
73  // eta<0 && phi>M_PI, status, id,m,e,s,eta,phi/M_PI*180,iPhi,iEta,iBin);
74  assert(mes2bin[m-1][e-1][s-1]==-1); //tmp, to check BTOW code
75  mes2bin[m-1][e-1][s-1]=iBin;
76 
77  nB++;
78  if( status!= 1) continue; // drop broken towers
79 
80  setActive(iBin);
81  nA++;
82  }
83 
84  LOG_INFO <<" BemcHitList::initRun() done, active="<<nA<<" of "<<nB<<" BTOW towers" <<endm;
85 
86 }
87 
88 //==========================================================
89 //==========================================================
90 void
91 BemcHitList::clear(){
92  ScintHitList::clear();
93 
94 }
95 
96 //==========================================================
97 //==========================================================
98 int
99 BemcHitList::etaBin(float eta){
100  if(fabs(eta)>0.99) return -1; // 20th eta bin is only 0.04 wide in eta
101  int iEta=(int)((eta-eta0)/dEta);
102  if(iEta<0 || iEta>=nEta) return -1; // out of Eta range
103  return iEta;
104 }
105 
106 //==========================================================
107 //==========================================================
108 float
109 BemcHitList::bin2EtaLeft(int iEta){
110  assert(iEta>=0);
111  assert(iEta<nEta);
112  float etaF= eta0+iEta*dEta ;
113  if(etaF<-0.99) etaF=0.99;
114  return etaF;
115 }
116 
117 
118 //==========================================================
119 //==========================================================
120 BemcHitList::~BemcHitList(){
121 
122 }
123 
124 //==========================================================
125 //==========================================================
126 void
127 BemcHitList::build ( StEmcDetector*det, float adcMin){
128  for(int m = 1; m<=BEMCMODULES;m++) { //loop on modules...
129  StEmcModule* module = det->module(m);
130  assert(module);
131  StSPtrVecEmcRawHit& rawHit=module->hits();
132  for(UInt_t k=0;k<rawHit.size();k++) { //loop on hits in modules
133  // check geometry
134  int m=rawHit[k]->module();
135  int e=rawHit[k]->eta();
136  int s=abs(rawHit[k]->sub());
137  int iBin=mes2bin[m-1][e-1][s-1];
138 
139  if ( getActive(iBin)<0) continue;
140 
141  int id;
142  geomB->getId(m,e,s,id); // to get the software id
143  Float_t ped,sig;
144  myTable->getPedestal(BTOW, id, 0, ped,sig);
145  float rawAdc = rawHit[k]->adc();
146  if( rawAdc<ped+ kSigPed*sig ) continue;
147  float adc= rawAdc -ped;
148  if(adc< adcMin) continue;
149  setFired(iBin);
150  }
151  }
152 
153 };
154 
155 /*
156  I think you want something like:
157  myTable->getCalib(BTOW, id, 1, gain);
158  getCalib instead of getGain. It is a bit confiusing, but there are two
159  sets of calibration constants. The ones called 'calib' are the ones you
160  want. The 'gain tables' coudl in principle hold a second, relative gain
161  calibration (that might vary on a shorter timescale), but this option is
162  not used at the moment, so they are all one.
163 */
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.