StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StFgtRawMaker.cxx
1 //
2 // \class StFgtRawMaker
3 // \author Anselm Vossen
4 //
5 // $Id: StFgtRawMaker.cxx,v 1.38 2013/12/20 05:19:46 xuanli Exp $
6 //
7 // $Log: StFgtRawMaker.cxx,v $
8 // Revision 1.38 2013/12/20 05:19:46 xuanli
9 // Update FgtRawMaker for run13 test production.
10 //
11 // Revision 1.37 2013/06/03 15:47:52 avossen
12 // changed return code from fatal to warn if #tb is to high in meta data
13 //
14 // Revision 1.36 2013/05/25 17:34:52 avossen
15 // checked for maximum allowed timebin
16 //
17 // Revision 1.35 2013/05/25 17:18:51 avossen
18 // checked for maximum allowed timebin
19 //
20 // Revision 1.34 2013/02/19 20:57:01 akio
21 // Added getting timebin from meta data, and also support for zero suppresed data
22 //
23 // Revision 1.33 2012/07/31 18:25:53 jeromel
24 // Remove virtual + add InitRun to get Db point (previous method implied passing from outside a pointer to a maker (sigh!) not appropriate)
25 //
26 // Revision 1.32 2012/03/07 03:57:23 avossen
27 // various updates
28 //
29 // Revision 1.31 2012/02/21 19:44:45 avossen
30 // implementing reviewers comments take 2
31 //
32 // Revision 1.30 2012/02/21 04:41:57 avossen
33 // *** empty log message ***
34 //
35 // Revision 1.29 2012/02/20 23:56:39 avossen
36 // addressing reviewers comments take 1
37 //
38 // Revision 1.28 2012/02/06 04:17:45 balewski
39 // added 2012 APV exclusions
40 //
41 // Revision 1.27 2012/02/05 21:19:22 avossen
42 // added check for invalid elec coordinates
43 //
44 // Revision 1.26 2012/01/30 10:42:23 sgliske
45 
46 // all time bins. Also fixed bug where setType modified the timebin
47 // rather than the type.
48 //
49 // Revision 1.25 2012/01/28 18:54:47 avossen
50 // removed last naive call and reference to StFgtGeom.h
51 //
52 // Revision 1.24 2012/01/26 13:13:12 sgliske
53 // Updated to use StFgtConsts, which
54 // replaces StFgtEnums and StFgtGeomDefs
55 //
56 // Revision 1.23 2012/01/18 17:48:31 sgliske
57 // StEvent/StFgtStrip now contains rdo/arm/apv/channel
58 //
59 // Revision 1.22 2012/01/18 03:28:25 avossen
60 // removed naive calls
61 //
62 // Revision 1.21 2012/01/18 03:10:51 avossen
63 // added db access to the raw maker
64 //
65 // Revision 1.20 2012/01/17 21:56:26 sgliske
66 // Short_t geoId -> Int_t geoId
67 //
68 // Revision 1.19 2011/11/01 18:45:32 sgliske
69 // Updated to correspond with StEvent containers, take 2.
70 // Note: new FGT containers (and StEvent access) no longer
71 // motivate the use of a common base class
72 //
73 // Revision 1.18 2011/10/27 21:09:47 jeromel
74 // Small info added in Init() + ident
75 //
76 // Revision 1.17 2011/10/26 21:32:01 avossen
77 // fixed mFgtEvent pointer name
78 //
79 // Revision 1.16 2011/10/26 20:57:48 avossen
80 // hopefully made cosmic and raw maker compatible with bfc (again), added clear in make. Unnecessary if member fkt clear() is called after every event
81 //
82 // Revision 1.15 2011/10/06 15:19:43 sgliske
83 // StFgtRawHitArray::PushBack -> pushBack
84 //
85 // Revision 1.14 2011/09/26 14:23:06 sgliske
86 // Update for new 'Char_t mType' field in StFgtRawHit
87 //
88 // Revision 1.13 2011/09/21 17:49:34 sgliske
89 // alternate base class with more
90 // functionality and not an StMaker
91 //
92 // Revision 1.11 2011/09/20 15:53:09 sgliske
93 // Update so that everything compiles nicely
94 // and so that one can execute the macro/simpleTestStandTest.C file
95 //
96 // Revision 1.10 2011/09/19 21:12:36 sgliske
97 // update
98 //
99 // Revision 1.9 2011/09/14 17:21:19 avossen
100 // using dev allows cint to compile.
101 //
102 // Revision 1.8 2011/09/14 15:44:11 avossen
103 // took out the root cint stuff so it compiles
104 //
105 // Revision 1.7 2011/09/13 18:35:42 avossen
106 // added RTS header files
107 //
108 // Revision 1.6 2011/09/13 10:06:43 avossen
109 // *** empty log message ***
110 //
111 // Revision 1.5 2011/09/11 08:06:36 avossen
112 // added cosmic maker
113 //
114 // Revision 1.4 2011/08/24 14:30:44 avossen
115 // Continued raw maker development
116 //
117 //
118 
119 #include "St_base/StMessMgr.h"
120 #include "St_base/Stypes.h"
121 
122 #include "StChain/StRtsTable.h"
123 #include "StEvent/StEvent.h"
124 #include "DAQ_FGT/daq_fgt.h"
125 #include "DAQ_READER/daq_dta.h"
126 
127 #include "StEvent/StFgtCollection.h"
128 #include "StEvent/StFgtStripCollection.h"
129 #include "StEvent/StFgtStrip.h"
130 #include "StFgtDbMaker/StFgtDbMaker.h"
131 #include "St_base/StMessMgr.h"
132 #include "St_base/Stypes.h"
133 #include <string>
134 #include <sstream>
135 #include "StFgtRawMaker.h"
136 
137 
142 {
143  StEvent* eventPtr=0;
144  eventPtr= (StEvent*)StRTSBaseMaker::GetInputDS("StEvent");
145 
146  mFgtCollectionPtr=NULL;
147  if(eventPtr)
148  {
149  mFgtCollectionPtr=eventPtr->fgtCollection();
150  }
151  else
152  {
153  eventPtr=new StEvent();
154  if(!eventPtr)
155  {
156  LOG_DEBUG <<"::prepareEnvironment could not create StFgtEvent" <<endm;
157  return kStFatal;
158  }
159  StRTSBaseMaker::AddData(eventPtr);
160  mFgtCollectionPtr=eventPtr->fgtCollection();
161  }
162  if(!mFgtCollectionPtr)
163  {
164  mFgtCollectionPtr=new StFgtCollection();
165  if(!mFgtCollectionPtr)
166  {
167  LOG_DEBUG <<"::prepareEnvironment could not create StFgtCollection" <<endm;
168  return kStFatal;
169  }
170  eventPtr->setFgtCollection(mFgtCollectionPtr);
171  LOG_DEBUG <<"::prepareEnvironment() has added a non existing StFgtCollection()"<<endm;
172  }
173  else
174  {
175  //this should be unncessary if the member clear function is called
176  mFgtCollectionPtr->Clear();
177  }
178  return kStOK;
179 }
180 
185 {
186 
187  LOG_DEBUG <<"StEmcRawMaker::Make()******************************************************************"<<endm;
188 
189  if( prepareEnvironment()!=kStOK )
190  {
191  LOG_ERROR << "Error preparing enviroment" << endm;
192  return kStFatal;
193  }
194  else
195  {
196  mEvent++;
197  try{
198  return fillHits();
199  }
200  catch(string s)
201  {
202  LOG_ERROR << s << endm;
203  return kStWarn;
204  }
205  }
206 }
207 
208 
213 {
214 
215  Short_t quadrant=0;
216  Char_t layer=0;
217  Double_t ordinate=0;
218  Double_t lowerSpan=0;
219  Double_t upperSpan=0;
220  Int_t rdo=0;
221  Int_t arm=0;
222  Int_t apv=0;
223  Int_t channel=0;
224  Short_t adc=0;
225  Short_t timebin=0;
226  Short_t discIdx=0;
227 
228  //now grab the constants from the header file, loop over the raw data and fill the hits...
229  StRtsTable* rts_tbl=0;
230  int flag=0;
231  int ntimebin=0;
232  while(1){
233  if(flag==0){
234  if(mDataType==0){
235  rts_tbl = GetNextDaqElement("fgt/adc"); flag=1;
236  if(!rts_tbl) { rts_tbl = GetNextDaqElement("fgt/zs"); flag=2; }
237  }else if(mDataType==1){
238  rts_tbl = GetNextDaqElement("fgt/adc"); flag=1;
239  }else if(mDataType==2){
240  rts_tbl = GetNextDaqElement("fgt/zs"); flag=2;
241  }
242  }
243  else if(flag==1){ rts_tbl = GetNextDaqElement("fgt/adc"); }
244  else if(flag==2){ rts_tbl = GetNextDaqElement("fgt/zs"); }
245  if(!rts_tbl) break;
246 
247  apv_meta_t *meta = (apv_meta_t *)rts_tbl->Meta();
248  if(meta){
249  for(int r=1;r<=FGT_RDO_COU;r++) {
250  if(meta->arc[r].present == 0) continue ;
251  for(int arm=0;arm<FGT_ARM_COU;arm++) {
252  if(meta->arc[r].arm[arm].present == 0) continue ;
253  for(int apv=0;apv<FGT_APV_COU;apv++) {
254  if(meta->arc[r].arm[arm].apv[apv].present == 0) continue ;
255  int nt=meta->arc[r].arm[arm].apv[apv].ntim;
256  //printf("RDO=%1d ARM=%1d APV=%02d Number of time bin =%d\n",r,arm,apv,nt);
257  if(ntimebin!=0 && nt!=0 && ntimebin!=nt) {
258  LOG_ERROR << "Different number of timebins in different APV!!! Taking larger one!!!" << endm;
259  }
260  if(ntimebin<nt) ntimebin=nt;
261  if(ntimebin>kFgtNumTimeBins)
262  {
263  stringstream ss;
264  ss<<"timebin nr read from APV ("<<ntimebin<<") larger than allocated space ("<<kFgtNumTimeBins<<")";
265  throw ss.str();
266  }
267  }
268  }
269  }
270  }
271 
272  //works because '*' operator is giving your the row
273  for(StRtsTable::iterator it=rts_tbl->begin();it!=rts_tbl->end();it++)
274  {
275  fgt_adc_t *mFgtRawData=(fgt_adc_t*)*it;
276  rdo=rts_tbl->Rdo();
277  //this is different from rts_example
278  channel=mFgtRawData->ch;
279  timebin=mFgtRawData->tb;
280  //look at rts_example for the mapping
281  adc=mFgtRawData->adc;
282  arm=rts_tbl->Sector();
283  apv=rts_tbl->Pad();
284  //printf("rdo=%1d arm=%1d apv=%2d ch=%3d tb=%1d adc=%4d\n",rdo,arm,apv,channel,timebin,adc);
285 
286  if(apv>=22 || apv < 0 || apv ==10|| apv==11) continue;
287  if(arm<0 || arm>5) continue;
288  if(timebin<0 || timebin>ntimebin || timebin>kFgtNumTimeBins) continue;
289  if(channel<0 || channel>=128) continue;
290  if(rdo<1 || rdo>2) continue;
291 
292  // year 2012 exclusions
293  // if( ( (rdo==1 && arm==1) || (rdo==2 && arm==2) || (rdo==1 && arm==4)) && apv>4 && apv<10 ) continue;
294  // if( ((rdo==2 && arm==1) ||(rdo==1 && arm==3) ||(rdo==2 && arm==4) ) && apv<5 ) continue;
295  // if( rdo==2 && arm==4) continue;
296  // if( ( (rdo==2 && arm==1) ||(rdo==1 && arm==3) ) && apv>16 ) continue;
297  // if( ((rdo==1 && arm==2) ||(rdo==2 && arm==3) ) && apv>10 && apv<17) continue;
298  // end of 2012 exclusions
299 
300 
301  Int_t geoId=-1;
302  if(!mFgtDb)
303  // geoId=StFgtGeom::getNaiveGeoIdFromElecCoord(rdo,arm,apv,channel);
304  {
305  LOG_FATAL<<Form("StFgtRawMaker: No DB available")<<endm;
306  return kStFatal;
307  }
308  else
309  {
310  geoId=mFgtDb->getGeoIdFromElecCoord(rdo, arm, apv, channel);
311  mFgtDb->getPhysCoordFromElecCoord(rdo,arm,apv,channel,discIdx,quadrant,layer,ordinate,lowerSpan,upperSpan);
312  }
313 
314  // StFgtGeom::getNaivePhysCoordFromElecCoord(rdo,arm,apv,channel,discIdx,quadrant,layer,ordinate,lowerSpan,upperSpan);
315 
316  // Char_t type = kFgtRawAdc;
317  // Char_t type = 0;
318 
319  StFgtStripCollection *stripCollectionPtr = mFgtCollectionPtr->getStripCollection( discIdx );
320  if( stripCollectionPtr )
321  {
322  Int_t elecId = StFgtGeom::getElectIdFromElecCoord( rdo, arm, apv, channel );
323  StFgtStrip* stripPtr = stripCollectionPtr->getStrip( elecId );
324  stripPtr->setAdc( adc, timebin );
325  // stripPtr->setType( type );
326  stripPtr->setGeoId( geoId );
327  stripPtr->setElecCoords( rdo, arm, apv, channel );
328  }
329  else
330  { LOG_WARN << "StFgtRawMaker::Make() -- Could not access disc " << discIdx << endm; }
331  }
332  }
333 
334  if(mEvent<3) LOG_INFO << "StFgtRawMaker:: Number of Timebin from meta data = " << Form("%d",ntimebin) << endm;
335  mFgtCollectionPtr->setNumTimeBins(ntimebin);
336 
337  return kStOK;
338 }
339 
344 {
345  LOG_INFO << "StFgtRawMaker::Init we are named " << GetName() << endm;
346  return kStOk;
347 }
348 
349 
351 Int_t StFgtRawMaker::InitRun(Int_t runNumber)
352 {
353  LOG_INFO << "StFgtRawMaker::InitRun with run = " << runNumber << endm;
354  if (! mFgtDb ){
355  StFgtDbMaker * fgtMaker;
356  fgtMaker = (StFgtDbMaker *) GetMaker("fgtDb");
357  if ( fgtMaker ){
358  // NOTE JL 2012/07
359  // we can at least return a point to the expected struct to
360  // get back to our feet but this is non-standard
361  mFgtDb = fgtMaker->getDbTables();
362  LOG_INFO << "::InitRun Getting fgtDb info" << endm;
363  } else {
364  LOG_ERROR << "::InitRun we will fail as fgtDb is not present" << endm;
365  }
366  }
367  return kStOK;
368 }
369 
370 
371 
375 StFgtRawMaker::StFgtRawMaker(const Char_t* name) :
376  StRTSBaseMaker( "adc", name ),
377  mFgtCollectionPtr(0), mFgtDb(0), mEvent(0), mDataType(0)
378 {
379 }
380 
381 
382 StFgtRawMaker::~StFgtRawMaker()
383 {
384  // nothing to do
385 }
386 
387 void StFgtRawMaker::Clear( Option_t *opts )
388 {
389  if( mFgtCollectionPtr )
390  mFgtCollectionPtr->Clear( opts );
391  mFgtCollectionPtr=NULL;
392 }
393 
394 
395 //StFgtRawMaker& StFgtRawMaker::operator=(const StFgtRawMaker &source)
396 //{
397 // StRTSBaseMaker::operator=(source);
398 // return *this;
399 //}
400 
401 //StFgtRawMaker::StFgtRawMaker(const StFgtRawMaker &source):StRTSBaseMaker(source)
402 //{
403 //}
404 
405 ClassImp(StFgtRawMaker)
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...
virtual void AddData(TDataSet *data, const char *dir=".data")
User methods.
Definition: StMaker.cxx:332
Int_t InitRun(Int_t runNumber)
InitRun will be called after FgtDb due to chain dependencies.
StFgtRawMaker(const Char_t *name="FgtRaw")
void Clear(Option_t *opts="")
User defined functions.
Int_t prepareEnvironment()
virtual const char * GetName() const
special overload
Definition: StMaker.cxx:237
Definition: Stypes.h:42
Definition: Stypes.h:40
Definition: Stypes.h:41