StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StjBEMCMuDst.cxx
1 // $Id: StjBEMCMuDst.cxx,v 1.12 2017/05/23 18:32:15 zchang Exp $
2 #include "StjBEMCMuDst.h"
3 
4 #include <StMuDSTMaker/COMMON/StMuDst.h>
5 #include <StMuDSTMaker/COMMON/StMuEvent.h>
6 
7 #include <StEvent/StEmcRawHit.h>
8 #include <StEvent/StEmcCollection.h>
9 #include <StEvent/StEmcModule.h>
10 #include <StEvent/StEmcDetector.h>
11 #include <StEvent/StEvent.h>
12 
13 #include <StEmcUtil/geometry/StEmcGeom.h>
14 
15 
16 #include <StEmcRawMaker/defines.h>
17 #include <StEmcRawMaker/StBemcTables.h>
18 
19 #include "StEmcADCtoEMaker/StEmcADCtoEMaker.h"
20 #include "StEmcSimulatorMaker/StEmcSimulatorMaker.h"
21 
22 #include <TVector3.h>
23 
24 #include <iostream>
25 
26 using namespace std;
27 
28 int StjBEMCMuDst::_runNumber = -1;
29 int StjBEMCMuDst::_eventId = -1;
30 StjTowerEnergyList StjBEMCMuDst::_list;
31 
32 StjBEMCMuDst::StjBEMCMuDst(bool doTowerSwapFix) : _bemcTables(0)
33 {
34  // If data, StEmcADCtoEMaker will be in the chain
35  if (StEmcADCtoEMaker* adc2e = (StEmcADCtoEMaker*)StMaker::GetChain()->GetMakerInheritsFrom("StEmcADCtoEMaker")) {
36  _bemcTables = adc2e->getBemcData()->getTables();
37  }
38 
39  // If simulation, StEmcSimulatorMaker will be in the chain
40  if (StEmcSimulatorMaker* emcSim = (StEmcSimulatorMaker*)StMaker::GetChain()->GetMakerInheritsFrom("StEmcSimulatorMaker")) {
41  _bemcTables = emcSim->getTables();
42  }
43 
44  assert(_bemcTables);
45 
46  _setVertex = false;
47 }
48 
49 StjTowerEnergyList StjBEMCMuDst::getEnergyList()
50 {
51  if(isNewEvent()) _list = getlist();
52  return _list;
53 }
54 
55 void StjBEMCMuDst::setVertex(float vx, float vy, float vz)
56 {
57  _setVertex = true;
58 
59  _vx = vx;
60  _vy = vy;
61  _vz = vz;
62 }
63 
64 bool StjBEMCMuDst::isNewEvent()
65 {
66  if(_runNumber != StMuDst::event()->runId()) return true;
67  if(_eventId != StMuDst::event()->eventId()) return true;
68  return false;
69 }
70 
71 StjTowerEnergyList StjBEMCMuDst::getlist()
72 {
73  _runNumber = StMuDst::event()->runId();
74  _eventId = StMuDst::event()->eventId();
75 
76  StjTowerEnergyList ret;
77 
78  StEmcCollection* emcCollection = findEmcCollection();
79  if (emcCollection) {
80  StEmcDetector* detector = emcCollection->detector(kBarrelEmcTowerId);
81  if (detector) {
82  for(unsigned int m = 1; m <= detector->numberOfModules(); ++m) {
83  StSPtrVecEmcRawHit& rawHits = detector->module(m)->hits();
84  for(size_t k = 0; k < rawHits.size(); ++k) {
85  ret.push_back(readTowerHit(*rawHits[k]));
86  }
87  }
88  }
89  }
90 
91  return ret;
92 }
93 
94 StEmcCollection* StjBEMCMuDst::findEmcCollection()
95 {
96  StEvent* event = dynamic_cast<StEvent*>(StMaker::GetChain()->GetInputDS("StEvent") );
97  return (event) ? event->emcCollection() : StMuDst::emcCollection();
98 }
99 
100 StjTowerEnergy StjBEMCMuDst::readTowerHit(const StEmcRawHit& hit)
101 {
102  StjTowerEnergy ret;
103 
104  ret.runNumber = StMuDst::event()->runId();
105  ret.eventId = StMuDst::event()->eventId();
106 
107  ret.detectorId = kBarrelEmcTowerId;
108 
109  int towerId;
110  StEmcGeom::instance("bemc")->getId(hit.module(), hit.eta(), abs(hit.sub()), towerId);
111 
112  ret.towerId = towerId;
113 
114  float towerX, towerY, towerZ;
115  StEmcGeom::instance("bemc")->getXYZ(towerId, towerX, towerY, towerZ);
116  TVector3 tower(towerX, towerY, towerZ);
117 
118  ret.towerR = tower.Perp();
119  ret.towerEta = tower.Eta();
120  ret.towerPhi = tower.Phi();
121 
122  if (_setVertex) {
123  ret.vertexX = _vx;
124  ret.vertexY = _vy;
125  ret.vertexZ = _vz;
126  }
127  else {
129 
130  ret.vertexX = vertex.x();
131  ret.vertexY = vertex.y();
132  ret.vertexZ = vertex.z();
133  }
134 
135  ret.energy = hit.energy();
136  ret.adc = hit.adc();
137 
138  float pedestal, rms;
139  int CAP(0);
140  _bemcTables->getPedestal(BTOW, towerId, CAP, pedestal, rms);
141  ret.pedestal = pedestal;
142  ret.rms = rms;
143 
144  int status;
145  _bemcTables->getStatus(BTOW, towerId, status);
146  ret.status = status;
147 
148  return ret;
149 }
StThreeVectorF primaryVertexPosition(int vtx_id=-1) const
The StMuDst is supposed to be structured in &#39;physical events&#39;. Therefore there is only 1 primary vert...
Definition: StMuEvent.cxx:221
void getPedestal(Int_t det, Int_t softId, Int_t cap, Float_t &ped, Float_t &rms) const
Return pedestal mean and rms.
static StMuEvent * event()
returns pointer to current StMuEvent (class holding the event wise information, e.g. event number, run number)
Definition: StMuDst.h:320
static StEmcCollection * emcCollection()
returns pointer to current StEmcCollection
Definition: StMuDst.h:405
void getStatus(Int_t det, Int_t softId, Int_t &status, const char *option="") const
Return status.