StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StEmcRawMaker.cxx
1 //
2 // $Id: StEmcRawMaker.cxx,v 1.24 2010/12/22 22:58:57 stevens4 Exp $
3 
4 #include <math.h>
5 
6 #include <StEventTypes.h>
7 #include <StEvent.h>
8 #include <TStopwatch.h>
9 #include <TString.h>
10 
11 #include <StEmcUtil/others/emcDetectorName.h>
12 #include <StEmcUtil/geometry/StEmcGeom.h>
13 
14 // DAQ Libraries
15 #include <StDaqLib/GENERIC/EventReader.hh>
16 #include <StDaqLib/EMC/EMC_Reader.hh>
17 #include <StDAQMaker/StDAQReader.h>
18 #include <StEmcUtil/database/StEmcDecoder.h>
19 #include <StMessMgr.h>
20 
21 //EEMC ........
22 #include <StEEmcUtil/database/StEEmcDb.h>
23 #include <StEEmcUtil/database/EEmcDbCrate.h> // for print outs
24 
25 #include "StEmcRawMaker.h"
26 #include "StEemcRaw.h"
27 
28 ClassImp(StEmcRawMaker)
29 
30 //_____________________________________________________________________________
31 /*
32  Default constructor. Set Initial values for some variables
33 */
34 StEmcRawMaker::StEmcRawMaker(const char *name):StRTSBaseMaker(name)
35 {
36  m_Mode = 0;
37  mEvent = 0;
38  mBemcRaw = new StBemcRaw();
39  // does not correct for tower map bug at production level by default
40  // this assures consistency between the muDst/StEvent files and database
41  mBemcRaw->towerMapBug(kFALSE);
42  mBemcRaw->psdMapBug2(kFALSE);
43  mBemcRaw->smdMapBug(kFALSE);
44 
45  mEemcRaw = new StEemcRaw();
46  eeStDb=0;
47 }
48 
49 //_____________________________________________________________________________
54 {}
55 
56 //_____________________________________________________________________________
61 {
62  //................BEMC stuff ..............
63  if(IAttr("BEmcCheckStatus")) {
64  LOG_INFO << "StEmcRawMaker will suppress hits from towers with bad status" << endm;
65  mBemcRaw->getControlTable()->CheckStatus[0] = 1;
66  }
67 
68  TString EmcOpts = SAttr(".gopt.emc");
69  if (EmcOpts.IsHex()) {
70  Int_t optionMap[] = {0, 2, 4, 4, 1, 3, 5, 5};
71  controlADCtoE_st* tab = mBemcRaw->getControlTable();
72  for(Int_t i=0; i<MAXDETBARREL; i++) {
73  Int_t optI;
74  TString optIs = EmcOpts(optionMap[i],1);
75  sscanf(optIs.Data(),"%x",&optI); // convert hex to decimal
76  tab->CheckStatus[i] = (optI>>0) & 1;
77  tab->CutOffType[i] = (optI>>1) & 1;
78  // etc.
79  }
80  }
81 
82  mBemcRaw->initHisto();
83  mBemcRaw->printConf();
84  if((m_Mode&0x1)==1)
85  {
86  LOG_INFO << "Setting BEMC debug Mode -> save all hits into StEvent"<<endm;
87  mBemcRaw->saveAllStEvent(kTRUE);
88  mBemcRaw->initQAHisto();
89  }
90  if(m_Mode==10)
91  {
92  LOG_INFO << "Saveing all BTOW hits for bfc->picoDst production" << endm;
93  mBemcRaw->saveAllBTOW(kTRUE);
94  }
95  //................EEMC stuff ..............
96  eeStDb = (StEEmcDb*)this->GetDataSet("StEEmcDb");
97  if(eeStDb==0)
98  {
99  LOG_ERROR << "FATAL !!! \n did not found \"eeDb-maker\", all EEMC data will be ignored\n fix it, JB\n" <<endm;
100  }
101 
102  mEemcRaw->initHisto(); // EEMC histos to monitor corruption
103 
104  if (IAttr(".histos"))
105  {
106  /* EEMC and BEMC has no unneeded histos to skip during production,
107  all monitor corruption,
108  require ~1000 float bins in total, JB
109  */
110  }
111 
112 
113  //never change control table after here
114  assert(mBemcRaw->getControlTable()->CutOffType[2]==mBemcRaw->getControlTable()->CutOffType[3]);
115 
116  if(mBemcRaw->getControlTable()->CutOffType[2]){
117  mBemcRaw->getControlTable()->DeductPedestal[2] = 0;
118  mBemcRaw->getControlTable()->DeductPedestal[3] = 0;
119  }
120  if(mBemcRaw->getControlTable()->CutOffType[1]){
121  mBemcRaw->getControlTable()->DeductPedestal[1] = 0;
122  }
123  return StMaker::Init();
124 }
125 
126 //____________________________________________________
127 //____________________________________________________
131 Int_t StEmcRawMaker::InitRun(Int_t runNumber)
132 {
133  // Load DB and create decoder for the BEMC
134  LOG_INFO <<"Getting database tables for the BEMC detector "<<endm;
135  mBemcRaw->createDecoder(GetDate(),GetTime());
136  mBemcRaw->getTables()->loadTables((StMaker*)this);
137 
138  //................EEMC stuff ..............
139 
140  LOG_INFO << "(" << runNumber << ")" << endm;
141 
142  if(eeStDb==0)
143  {
144  LOG_ERROR << "did not found \"eeDb-maker\", all EEMC data will be ignored\n\n"<<endm;
145  }
146  else if ( eeStDb->valid()==0 )
147  {
148  LOG_ERROR << "found \"eeDb-maker\", but without any DB data, all EEMC data will be ignored\n\n"<<endm;
149  eeStDb=0;
150  }
151  else
152  {// all is OK, no warning
153  //eeStDb->exportAscii();
154  }
155  mEemcRaw->setDb(eeStDb);
156  return StMaker::InitRun(runNumber);
157 }
158 
159 //_____________________________________________________________________________
164 {
165  return kStOk;
166 }
167 //____________________________________
169 {
170  LOG_INFO << "this function is obsolete. Use logger config file to set verbosity instead." << endm;
171 }
172 //_____________________________________________________________________________
177 {
178  TStopwatch clock;
179  clock.Start();
180  LOG_DEBUG <<"StEmcRawMaker::Make()******************************************************************"<<endm;
181  if(!prepareEnvironment())
182  { LOG_WARN <<"Could not prepare the environment to process the event "<<endm; }
183 
184  if(!makeBemc())
185  { LOG_WARN <<"Could not process BEMC information properly "<<endm; }
186 
187  if(!makeEemc())
188  { LOG_WARN <<"Could not process EEMC information properly "<<endm; }
189 
190  fillHistograms();
191  clock.Stop();
192  LOG_DEBUG <<"Time to run StEmcRawMaker::Make() real = "<<clock.RealTime()<<" cpu = "<<clock.CpuTime()<<endm;
193  LOG_DEBUG <<"*******************************************************************************************"<<endm;
194 
195  //cleanup B+EmcRawCollection
196 
197  if( mEvent->id()%555 ) {// clear raw data from StEvent for most of events
198  int i;
199  StEmcRawData *eemcRaw = mEvent->emcCollection()->eemcRawData();
200  for (i=0; i<eemcRaw->getNBlocks();i++) eemcRaw->deleteBank(i);
201  StEmcRawData *bemcRaw = mEvent->emcCollection()->bemcRawData();
202  for (i=0; i<bemcRaw->getNBlocks();i++) bemcRaw->deleteBank(i);
203  } else {
204  LOG_INFO<< Form("B+EmcRawData are retained for eve=%d\n",mEvent->id())<<endm;
205  }
206  return kStOK;
207 }
208 //_____________________________________________________________________________
213 {
214  mEvent = 0;
215 
216  LOG_DEBUG <<"Get StEvent pointer and make it ready for filling"<<endm;
218  // Get StEvent pointer and make it ready for filling
219  //
220  mEvent = (StEvent*)GetInputDS("StEvent");
221  StEmcCollection *emc = NULL;
222 
223  if(mEvent)
224  {
225  emc = mEvent->emcCollection();
226  }
227  else
228  {
229  mEvent = new StEvent();
230  AddData(mEvent);
231  emc = mEvent->emcCollection();
232  }
233 
234  if(!emc)
235  {
236  emc = new StEmcCollection();
237  mEvent->setEmcCollection(emc);
238  LOG_DEBUG << "::prepareEnvironment() has added a non existing StEmcCollection()"<<endm;
239  }
240 
241  StEmcRawData *bemcRaw = emc->bemcRawData();
242  if(bemcRaw)
243  {
244  LOG_WARN << "::prepareEnvironment() found old StEmcRawData *bemcRaw. Will delete it and create a new one"<<endm;
245  delete bemcRaw;
246  }
247  bemcRaw = new StEmcRawData();
248  emc->setBemcRawData(bemcRaw);
249 
250  StEmcRawData *eemcRaw = emc->eemcRawData();
251  if(eemcRaw)
252  {
253  LOG_FATAL << "::prepareEnvironment() found old StEmcRawData *eemcRaw, TOTAL failure,\n STOP this chain, JB"<<endm;
254  delete eemcRaw;
255  }
256  eemcRaw = new StEmcRawData(); // always create new collection for EEMC
257  emc->setEemcRawData(eemcRaw);
258 
259 
260  //
262 
263  return kTRUE;
264 }
265 
266 //_____________________________________________________________________________
271 {
272  LOG_DEBUG <<"Copying BEMC information from DAQ structure "<<endm;
273 
274  if(GetDate() < 20081101){
275  TDataSet* TheData = GetDataSet("StDAQReader");
276  if(!TheData){
277  LOG_ERROR <<"Could not find DAQ Reader "<<endm;
278  return kFALSE;
279  }
280  mBemcRaw->setDate(GetDate());
281  mBemcRaw->getTables()->loadTables((StMaker*)this);
282  return mBemcRaw->make(TheData,mEvent);
283  }
284  mBemcRaw->setDate(GetDate());
285  mBemcRaw->getTables()->loadTables((StMaker*)this);
286  return mBemcRaw->make((StEmcRawMaker*)this,mEvent);
287 }
288 
289 //_____________________________________________________________________________
294 {
295  LOG_DEBUG <<"Copying EEMC information from daqReader->StEvent "<<endm;
296 
297  if(GetDate() < 20081101){
298  St_DataSet *daq = GetDataSet("StDAQReader");
299 
300  if (! daq){
301  LOG_ERROR << "::makeEemc() , StDAQReader not available" << endm;
302  return false;
303  }
304 
305  StDAQReader *fromVictor = (StDAQReader*) (daq->GetObject());
306 
307  if (!fromVictor ){
308  LOG_ERROR << "::makeEemc() , daq->GetObject() failed" << endm;
309  return false;
310  }
311 
312  StEEMCReader *eeReader = fromVictor->getEEMCReader();
313  if(!eeReader)
314  return false ;
315 
316  if (! eeReader){
317  LOG_ERROR << "::makeEemc() , fromVictor->getEEMCReader() failed" << endm;
318  return false;
319  }
320  return mEemcRaw->make(eeReader,mEvent);
321  }
322  return mEemcRaw->make( (StEmcRawMaker*)this,mEvent ); //eeReader,eemcRaw, token);
323 }
324 
325 //_____________________________________________________________________________
330 {
331  if(mBemcRaw)
332  mBemcRaw->fillHisto();
333 }
334 
335 // $Log: StEmcRawMaker.cxx,v $
336 // Revision 1.24 2010/12/22 22:58:57 stevens4
337 // Patch for BSMDE mapping problem in P10ih and P10ij productions (RT #2043)
338 //
339 // Revision 1.23 2010/08/27 22:31:34 ogrebeny
340 // *** empty log message ***
341 //
342 // Revision 1.22 2009/11/17 15:55:48 mattheww
343 // fixed a bunch of warnings
344 //
345 // Revision 1.21 2009/02/11 22:38:56 mattheww
346 // fixed a bug in getting CAP
347 //
348 // Revision 1.20 2009/02/04 21:05:42 kocolosk
349 // Refactor StEEmcDb(Maker), new location for StEmcDecoder. Fixes RT #1388.
350 //
351 // Revision 1.19 2009/02/01 02:27:55 mattheww
352 // fixed behavior for older data
353 //
354 // Revision 1.18 2009/01/27 19:58:36 mattheww
355 // Updates to StEmcRawMaker to be compatible with 2009 DAQ Format
356 //
357 // Revision 1.17 2008/03/27 19:54:16 genevb
358 // Utilize new BFC option for GoptEMC for controlADCtoE table
359 //
360 // Revision 1.16 2007/12/26 17:47:35 kocolosk
361 // added support for "BEmcCheckStatus" attribute to suppress hot towers in fastOffline
362 //
363 // Revision 1.15 2007/09/10 22:21:42 kocolosk
364 // Support for new BPRS swap fixes (off by default for 06/07 production, on for analysis).
365 // StBemcTables now matches map fixes in case end users want to use this copy.
366 //
367 // Revision 1.14 2007/04/11 03:29:11 balewski
368 // undo hacks,
369 // Endcap code is now in default configuration
370 //
371 // Revision 1.13 2007/03/27 16:53:42 balewski
372 // disable RawEndcap hits filtering
373 //
374 // Revision 1.12 2007/01/22 19:13:37 kocolosk
375 // use STAR logger for all output
376 //
377 // Revision 1.11 2006/12/12 20:29:17 balewski
378 // added hooks for Endcap embedding
379 //
380 // Revision 1.10 2006/08/01 14:45:31 balewski
381 // clear EmcRawData for eveID%555!=0 to reduce footprint of StEvent, for B+E-EMC
382 //
383 // Revision 1.9 2006/01/16 11:12:00 suaide
384 // tower map bug fixed and astyle run
385 //
386 // Revision 1.8 2004/12/14 11:32:11 suaide
387 // added histograms for status tables creation
388 //
389 // Revision 1.7 2004/11/24 00:12:19 suaide
390 // added check in for m_Mode&0x1==1 for bemcDebug flag in bfc
391 //
392 // Revision 1.6 2004/11/22 12:46:22 suaide
393 // added new flags for hit reconstruction. Status are not checked
394 // dureing production anymore in order to avoid bad status loaded in
395 // DB
396 //
397 // Revision 1.5 2004/11/02 03:23:09 suaide
398 // small changes in order to fix a bug
399 //
400 // Revision 1.4 2004/10/21 00:01:50 suaide
401 // small changes in histogramming and messages for BEMC
402 // Complete version for EEMC done by Jan Balewski
403 //
404 // Revision 1.3 2004/10/19 23:48:49 suaide
405 // Initial implementation of the endcap detector done by Jan Balewski
406 //
407 // Revision 1.2 2004/10/19 17:53:00 suaide
408 // code clean up
409 //
410 // Revision 1.1 2004/10/18 18:20:07 suaide
411 // New Maker. Will replace StEmcADCtoEMaker in production.
412 // It reads only DAQ structures. Output is StEvent.
413 //
virtual ~StEmcRawMaker()
StEmcRawMaker destructor.
Int_t m_Mode
counters
Definition: StMaker.h:81
void fillHistograms()
Fill QA histograms.
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
virtual Int_t Init()
Init function. This method initializes the histograms.
void setPrint(Bool_t a)
Obsolete function; users can control messages with logger config file.
void saveAllBTOW(Bool_t a)
Set to kTRUE if all BTOW hits are to be saved on StEvent (for picoDst/triggerSimu) ...
Definition: StBemcRaw.h:182
StEEmcDb * eeStDb
to assess EEMC DB
Definition: StEmcRawMaker.h:69
virtual Int_t Finish()
Finish function.
controlADCtoE_st * getControlTable()
Return Control table (NULL)
Definition: StBemcRaw.h:215
StBemcTables * getTables()
Return the StBemcTable pointer.
Definition: StBemcRaw.h:207
void setDate(Int_t d)
Set event date.
Definition: StBemcRaw.h:166
void setDb(StEEmcDb *aa)
DB-reader must exist.
Definition: StEemcRaw.h:44
void createDecoder(Int_t, Int_t)
Create new StEmcDecoder.
Definition: StBemcRaw.cxx:233
Bool_t makeBemc()
Make the Barrel-EMC detector.
virtual Int_t Make()
Process each event.
void loadTables(StMaker *anyMaker)
load tables.
virtual TObject * GetObject() const
The depricated method (left here for the sake of the backward compatibility)
Definition: TDataSet.cxx:428
Bool_t prepareEnvironment()
Prepare the StEvent environment to fill the EMC data.
Definition: Stypes.h:40
void saveAllStEvent(Bool_t a)
Set to kTRUE if all hits are to be saved on StEvent.
Definition: StBemcRaw.h:178
virtual Int_t InitRun(Int_t runumber)
InitRun function.
void printConf()
Print configuration.
Definition: StBemcRaw.cxx:217
Bool_t makeEemc()
Make the Endcap-EMC detector.
Definition: Stypes.h:41