StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StFpsRawHitMaker.cxx
1 // \class StFpsRawHitMaker
2 // \author Akio Ogawa
3 //
4 // $Id: StFpsRawHitMaker.cxx,v 1.4 2017/01/30 18:10:16 akio Exp $
5 // $Log: StFpsRawHitMaker.cxx,v $
6 // Revision 1.4 2017/01/30 18:10:16 akio
7 // remove LOG_INFO
8 //
9 // Revision 1.3 2017/01/30 17:49:28 akio
10 // adding FPost
11 //
12 // Revision 1.2 2015/09/02 14:55:18 akio
13 // Modified to work with StFmsDbMaker
14 //
15 
16 #include "StFpsRawHitMaker.h"
17 
18 #include "St_base/StMessMgr.h"
19 #include "St_base/Stypes.h"
20 #include "RTS/src/DAQ_FPS/daq_fps.h"
21 #include "RTS/src/DAQ_READER/daq_dta.h"
22 #include "StChain/StRtsTable.h"
23 #include "StEvent/StEvent.h"
24 #include "StEvent/StFmsCollection.h"
25 #include "StEvent/StFmsHit.h"
26 #include "StRoot/StFmsDbMaker/StFmsDbMaker.h"
27 
28 StFpsRawHitMaker::StFpsRawHitMaker(const Char_t* name) :
29  StRTSBaseMaker( "adc", name ), mPrePost(0), mFmsCollection(0), mFmsDbMaker(0) {}
30 
31 StFpsRawHitMaker::~StFpsRawHitMaker(){}
32 
34 Int_t StFpsRawHitMaker::InitRun(Int_t runNumber){
35  LOG_DEBUG << "StFpsRawHitMaker::InitRun with run = " << runNumber << endm;
36  mFmsDbMaker = static_cast<StFmsDbMaker*>(GetMaker("fmsDb"));
37  if(!mFmsDbMaker){
38  LOG_ERROR << "StFpsRawHitMaker::InitRun Failed to get StFmsDbMaker" << endm;
39  return kStFatal;
40  }
41  return kStOK;
42 }
43 
45 Int_t StFpsRawHitMaker::prepareEnvironment(){
46  StEvent* eventPtr=0;
47  eventPtr= (StEvent*)StRTSBaseMaker::GetInputDS("StEvent");
48  mFmsCollection=0;
49  if(eventPtr){
50  LOG_DEBUG <<"StFpsRawHitMaker::prepareEnvironment found StEvent" <<endm;
51  mFmsCollection=eventPtr->fmsCollection();
52  }else{
53  LOG_ERROR <<"StFpsRawHitMaker::prepareEnvironment found no StEvent"<<endm;
54  return kStFatal;
55  }
56  if(!mFmsCollection){
57  LOG_DEBUG <<"StFpsRawHitMaker::prepareEnvironment creating new StFmsCollection" <<endm;
58  mFmsCollection=new StFmsCollection;
59  if(!mFmsCollection){
60  LOG_ERROR <<"StFpsRawHitMaker::prepareEnvironment could not create StFmsCollection" <<endm;
61  return kStFatal;
62  }
63  LOG_DEBUG <<"StFpsRawHitMaker::prepareEnvironment setting new StFmsCollection to StEvent" <<endm;
64  eventPtr->setFmsCollection(mFmsCollection);
65  }
66  return kStOK;
67 }
68 
71  StRtsTable* rts_tbl=0;
72  int n[2]={0,0}, ngood[2]={0,0};
73  if(int ret=prepareEnvironment()!=kStOK ) return ret;
74 
75  // loop over DaqElements of FPS data in daq file
76  // A DaqElement contains data from one QT baord and one bunch crossings
77  while((rts_tbl = GetNextDaqElement("fps/adc"))){
78 
79  // 2015
80  //int xing=rts_tbl->Sector();
81  //if(xing>=128) xing-=256;
82  //int qt=rts_tbl->Rdo();
83 
84  // 2017
85  int fpsfpost=rts_tbl->Sector();
86  int xing=rts_tbl->Pad(); if(xing>=128) xing-=256;
87  int qt=rts_tbl->Row();
88 
89  int ndata=rts_tbl->GetNRows();
90  LOG_DEBUG << Form("FPS: fps/fpost=%1d xing=%4d QT=%02d NData=%d",fpsfpost,xing,qt,ndata)<<endm;
91  if(mPrePost==0 && xing!=0) continue;
92  for(StRtsTable::iterator it=rts_tbl->begin(); it!=rts_tbl->end(); it++){
93  fps_adc_t *a=(fps_adc_t *)*it;
94  //fps_adc_t *a=static_cast<fps_adc_t *>(*it); //would not work! use "reinterpret_cast".
95  int ch=a->ch;
96  int adc=a->adc;
97  int tdc=a->tdc;
98  int slatid,q,l,s,det,crate;
99  if(fpsfpost==1){
100  slatid = mFmsDbMaker->fpsSlatidFromQT(qt,ch); //Get SlatId from QT address and channel
101  mFmsDbMaker->fpsQLSfromSlatId(slatid,&q,&l,&s); //Get Quad/Layer/Slat#s from SlatId
102  LOG_DEBUG << Form("FPS: xing=%4d QT%02d ch%02d Slaiid=%3d Q%1dL%1dS%02d ADC=%4d TDC=%2d",xing,qt,ch,slatid,q,l,s,adc,tdc)<<endm;
103  det=kFpsDetId;
104  crate=kFpsQtCrate;
105  }else{
106  slatid = mFmsDbMaker->fpostSlatidFromQT(qt,ch); //Get SlatId from QT address and channel
107  mFmsDbMaker->fpostQLSfromSlatId(slatid,&q,&l,&s); //Get Quad/Layer/Slat#s from SlatId
108  LOG_DEBUG << Form("FPO: xing=%4d QT%02d ch%02d Slaiid=%3d Q%1dL%1dS%02d ADC=%4d TDC=%2d",xing,qt,ch,slatid,q,l,s,adc,tdc)<<endm;
109  det=kFpostDetId;
110  crate=kFpostQtCrate;
111  }
112  n[fpsfpost-1]++;
113  int flag=0;
114  if(slatid<0) { /* LOG_WARN << "Invalid SlatId = "<<slatid<<endm;*/ flag=1; }
115  if(q<1 || l<1 || s<1) { /* LOG_WARN << Form("Invalid Q/L/S = %d/%d/%d",q,l,s);*/ flag=1; }
116  if(flag==0){
117  StFmsHit* hit = new StFmsHit();
118  hit->setDetectorId(det);
119  hit->setChannel(slatid);
120  hit->setQtCrate(crate);
121  hit->setQtSlot(qt);
122  hit->setQtChannel(ch);
123  hit->setAdc(adc);
124  hit->setTdc(tdc);
125  float gain=.0;
126  if(fpsfpost==0) {mFmsDbMaker->fpsGain(slatid);}
127  else {mFmsDbMaker->fpostGain(slatid);}
128  float nmip=0.0;
129  if(gain>0.0) nmip=adc/gain;
130  hit->setEnergy(nmip);
131  mFmsCollection->addHit(hit);
132  if(Debug()) hit->print();
133  ngood[fpsfpost-1]++;
134  }
135  }
136  }
137  LOG_DEBUG << Form("StFpsRawHitMaker:: FPS found total %d hits and %d good",n[0],ngood[0]) << endm;
138  LOG_DEBUG<< Form("StFpsRawHitMaker:: FPOST found total %d hits and %d good",n[1],ngood[1]) << endm;
139  return kStOK;
140 }
141 
142 ClassImp(StFpsRawHitMaker)
StRtsTable * GetNextDaqElement(const char *elementPath)
Query the STAR production chain for the DAQ data.
Class StRTSBaseMaker - is an abstract StMaker to define the interface to access the DAQ data from the...
Int_t InitRun(Int_t runNumber)
Check if global pointer for StFmsDbMaker is available.
Int_t Make()
Read FPS data from daq file, and add to StFmsCollection as a StFmsHit.
virtual Long_t GetNRows() const
Returns the number of the used rows for the wrapped table.
Definition: TTable.cxx:1388
Definition: Stypes.h:40