8 #include "StEventTypes.h"
9 #include "StMuDSTMaker/COMMON/StMuTypes.hh"
10 #include "StMuDSTMaker/COMMON/StMuFmsUtil.h"
12 #include "StFmsDbMaker/StFmsDbMaker.h"
13 #include "StFmsCollection.h"
15 #include "StFmsHitMaker.h"
16 #include "StTriggerData2009.h"
28 StFmsHitMaker::StFmsHitMaker(
const char* name) :
StMaker(name) {
30 mFmsCollection = NULL;
32 LOG_DEBUG <<
"StFmsHitMaker::constructor." << endm;
35 StFmsHitMaker::~StFmsHitMaker(){
36 LOG_DEBUG <<
"StFmsHitMaker::destructor." << endm;
40 LOG_DEBUG <<
"StFmsHitMaker::Clear()" << endm;
44 int StFmsHitMaker::Init() {
45 LOG_DEBUG<<
"StFmsHitMaker::Init() "<<endm;
46 return StMaker::Init();
49 int StFmsHitMaker::InitRun(Int_t runNumber) {
50 LOG_INFO <<
"StFmsHitMaker::InitRun --run# changed to " << runNumber << endm;
51 mFmsDbMaker =
static_cast<StFmsDbMaker*
>(GetMaker(
"fmsDb"));
53 LOG_ERROR <<
"StFmsHitMaker::InitRun Failed to get StFmsDbMaker" << endm;
56 mCurrentRunNumber = runNumber;
62 LOG_DEBUG<<
"StFmsHitMaker::Make start"<<endm;
65 Float_t mCurrentEventNumber=0;
67 if(mReadMuDst>0)
return readMuDst();
75 mCurrentEventNumber=triggerData->eventNumber();
77 LOG_DEBUG<<
"StFmsHitMaker::Make Found StTriggerData from StTriggerDataMaker"<<endm;
86 mCurrentEventNumber=stEvent->id();
87 triggerData = stEvent->triggerData();
90 LOG_DEBUG<<
"StFmsHitMaker::Make Found StTriggerData from StEvent"<<endm;
93 mFmsCollection = stEvent->fmsCollection();
96 LOG_DEBUG<<
"StFmsHitMaker::Make Found StFmsCollection from StEvent"<<endm;
105 if(muDst && muDst->
event()){
106 mCurrentRunNumber = muDst->
event()->runNumber();
107 mCurrentEventNumber = muDst->
event()->eventNumber();
111 LOG_DEBUG<<
"StFmsHitMaker::Make Found StFmsTriggerData in MuDst"<<endm;
113 else LOG_ERROR <<
"Finally, no StFmsTriggerData in MuDst " <<endm;
116 LOG_DEBUG<<
"Flag="<<flag<<
" (0=Not found, 1=StTriggerDataMaker, 2=StEvent, 3=FmsCollection 4=Mudst)"<<endm;
122 for(
unsigned short crt=1; crt<=4; crt++){
123 for(
unsigned short slot=1; slot<=16; slot++){
124 for(
unsigned short ch=0; ch<32; ch++){
125 unsigned short adc=0;
126 unsigned short tdc=0;
127 if(flag<=4 && triggerData){
128 adc=triggerData->fmsADC(crt,slot-1,ch);
129 tdc=triggerData->fmsTDC(crt,slot-1,ch);
137 LOG_ERROR <<
"Failed to create FMS hit, skip this hit."<<endm;
140 hit->setDetectorId(0);
142 hit->setQtCrate(crt);
143 hit->setQtSlot(slot);
144 hit->setQtChannel(ch);
148 mFmsCollection->addHit(hit);
149 if(GetDebug()>0) hit->print();
156 for(
unsigned int i=0; i<mFmsCollection->numberOfHits(); i++){
158 StFmsHit* fmsHit = (mFmsCollection->hits())[i];
159 int crt =fmsHit->qtCrate();
160 int slot =fmsHit->qtSlot();
161 int ch =fmsHit->qtChannel();
162 unsigned short adc =fmsHit->adc();
163 mFmsDbMaker->getReverseMap(crt,slot,ch,&d,&c);
168 if(mCorrectAdcOffByOne){
171 int check=adc % (1<<bitshift);
173 LOG_ERROR << Form(
"Bitshift in DB is not consistent with data! det=%2d ch=%3d adc=%4d bitshift=%2d adc%(1<<bitshift)=%d",
174 d,c,adc,bitshift,check) << endm;
176 }
else if(bitshift<0){
177 int check=adc / (1<< (12+bitshift));
179 LOG_ERROR << Form(
"Bitshift in DB is not consistent with data! det=%2d ch=%3d adc=%4d bitshift=%2d adc/(1<<(12+bitshift))=%d",
180 d,c,adc,bitshift,check) << endm;
190 float g1=mFmsDbMaker->getGain(d,c);
205 if(mCorrectAdcOffByOne){
206 e=(adc+pow(2.0,bitshift))*g1*g2*gt;
211 fmsHit->setDetectorId(d);
212 fmsHit->setChannel(c);
213 fmsHit->setEnergy(e);
214 if(GetDebug()>0) fmsHit->print();
216 LOG_INFO<<
"StFmsHitMaker::Make(): flag = "<<flag<<
", got "<<mFmsCollection->numberOfHits()<<
" hits in StFmsCollection"<<endm;
218 LOG_INFO<<
"StFmsHitMaker::Make(): flag = "<<flag<<
", no StTrigger data found"<<endm;
223 LOG_DEBUG<<
"StFmsHitMaker::Make Adding StFmsCollection to StEvent"<<endm;
224 stEvent->setFmsCollection(mFmsCollection);
226 LOG_INFO <<
"StEvent is empty" << endm;
233 LOG_DEBUG <<
"StFmsHitMaker::Finish() " << endm;
237 Int_t StFmsHitMaker::readMuDst(){
239 if(!event){LOG_ERROR<<
"StFmsHitMaker::readMuDst found no StEvent"<<endm;
return kStErr;}
243 event->setFmsCollection(fmsColl);
246 if(!mudst){LOG_ERROR<<
"StFmsHitMaker::readMuDst found no MuDst"<<endm;
return kStErr;}
248 if(!mufmsColl){LOG_ERROR<<
"StFmsHitMaker::readMuDst found no MuFmsCollection"<<endm;
return kStErr;}
250 util.fillFms(fmsColl,mufmsColl);
static StMuFmsCollection * muFmsCollection()
returns pointer to current StMuFmsCollection
Float_t getGainCorrection(Int_t detectorId, Int_t ch) const
get the gain for the channel
virtual void Clear(Option_t *option="")
User defined functions.
float getTimeDepCorr(int event, int det, int ch)
force bit shift to be read from FmsBitShiftGain.txt
void Clear(Option_t *option="")
User defined functions.
Short_t getBitShiftGain(Int_t detectorId, Int_t ch) const
get the gain correction for the channel
static StMuEvent * event()
returns pointer to current StMuEvent (class holding the event wise information, e.g. event number, run number)
virtual TObject * GetObject() const
The depricated method (left here for the sake of the backward compatibility)