StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StEmcADCtoEMaker.cxx
1 #include "StEmcADCtoEMaker.h"
2 #include "StEventTypes.h"
3 #include "StEvent.h"
4 #include "Stiostream.h"
5 #include <math.h>
6 #include "StEmcUtil/others/emcDetectorName.h"
7 #include "StEmcUtil/geometry/StEmcGeom.h"
8 #include "TStopwatch.h"
9 #include "TString.h"
10 // DAQ Libraries
11 #include "StDaqLib/GENERIC/EventReader.hh"
12 #include "StDaqLib/EMC/EMC_Reader.hh"
13 #include "StDAQMaker/StDAQReader.h"
14 #include "StDaqLib/EMC/StEmcDecoder.h"
15 #include "StMessMgr.h"
16 #include "StMuDSTMaker/COMMON/StMuDst.h"
17 #include "StMuDSTMaker/COMMON/StMuDebug.h"
18 #include "StMuDSTMaker/COMMON/StMuEmcUtil.h"
19 #include "StMuDSTMaker/COMMON/StMuEvent.h"
20 #include "StEnumerations.h"
21 
22 
23 ClassImp(StEmcADCtoEMaker)
24 
25  //_____________________________________________________________________________
26  /*
27  Default constructor. Set Initial values for some variables
28  */
29 StEmcADCtoEMaker::StEmcADCtoEMaker(const char *name):StMaker(name)
30 {
31  mEvent = 0;
32  mEmbed = kFALSE;
33  mBemcData = new StBemcData();
34  mBemcData->towerMapBug(kTRUE); // corrects for tower map bug at analysis level by default
35  mBemcData->psdMapBug2(kTRUE);
36  mBemcData->smdMapBug(kTRUE);
37  mBemcData->setCrateVeto(1);
38  //status checking for all tables at analysis level by default
39  StDetectorId bemcid = static_cast<StDetectorId>(kBarrelEmcTowerId);
40  setCheckStatus(bemcid,1);
41  StDetectorId bprsid = static_cast<StDetectorId>(kBarrelEmcPreShowerId);
42  setCheckStatus(bprsid,1);
43  StDetectorId bsmdeid = static_cast<StDetectorId>(kBarrelSmdEtaStripId);
44  setCheckStatus(bsmdeid, 1);
45  StDetectorId bsmdpid = static_cast<StDetectorId>(kBarrelSmdPhiStripId);
46  setCheckStatus(bsmdpid, 1);
47 }
48 //_____________________________________________________________________________
53 {}
54 //_____________________________________________________________________________
60 {
61  mBemcData->initHisto();
62  mBemcData->printConf();
63  return StMaker::Init();
64 }
65 Int_t StEmcADCtoEMaker::InitRun(Int_t run)
66 {
67  // Load DB and create decoder for the BEMC
68  LOG_INFO <<"Getting database tables for the BEMC detector "<<endm;
69 
70  StMuDst* muDst = (StMuDst*)GetDataSet("MuDst");
71  if(muDst && muDst->event())
72  mBemcData->setProdVer(muDst->event()->runInfo().productionVersion().Data());
73  else
74  mBemcData->setProdVer("");
75  LOG_INFO <<"Setting done prod version"<<endm;
76 
77  mBemcData->createDecoder(GetDate(),GetTime());
78  mBemcData->getTables()->loadTables(this);
79  LOG_INFO <<"loading table done"<<endm;
80 
81  return StMaker::InitRun(run);
82 }
83 //_____________________________________________________________________________
88 {
89  return kStOk;
90 }
91 //_____________________________________________________________________________
96 {
97  TStopwatch clock;
98  clock.Start();
99  LOG_DEBUG <<"StEmcADCtoEMaker::Make()******************************************************************"<<endm;
100  mTestedCorruption = kFALSE;
101  if(!prepareEnvironment())
102  LOG_WARN <<"Could not prepare the proper environment"<<endm;
103  if(!makeBemc())
104  LOG_WARN <<"Could not make BEMC detector"<<endm;
105  fillHistograms();
106  clock.Stop();
107  LOG_DEBUG <<"Time to run StEmcADCtoEMaker::Make() real = "<<clock.RealTime()<<" cpu = "<<clock.CpuTime()<<endm;
108  LOG_DEBUG <<"*******************************************************************************************"<<endm;
109 
110  return kStOK;
111 }
112 //_____________________________________________________________________________
116 Bool_t StEmcADCtoEMaker::prepareEnvironment()
117 {
118  mEvent = 0;
119  LOG_DEBUG <<"Get StEvent pointer and make it ready for filling"<<endm;
121  // Get StEvent pointer and make it ready for filling
122  //
123  mEvent = (StEvent*)GetDataSet("StEvent");
124  StEmcCollection *emc = NULL;
125  mMyStEvent = kFALSE;
126 
127  if(mEvent)
128  emc = mEvent->emcCollection();
129  else
130  {
131  mEvent = new StEvent();
132  AddData(mEvent);
133  emc = mEvent->emcCollection();
134  mMyStEvent = kTRUE;
135  }
136  if(!emc)
137  {
138  emc = new StEmcCollection();
139  mEvent->setEmcCollection(emc);
140  }
141  if(mMyStEvent)
142  {
143  StEmcRawData *BemcData = emc->bemcRawData();
144  if(!BemcData)
145  {
146  BemcData = new StEmcRawData();
147  emc->setBemcRawData(BemcData);
148  }
149  }
150  //
152 
153  return kTRUE;
154 }
155 
156 //_____________________________________________________________________________
160 Bool_t StEmcADCtoEMaker::makeBemc()
161 {
162  mBemcData->setDate(GetDate());
163  mBemcData->getTables()->loadTables(this);
164 
165  // Try DAQ First
166  TDataSet* TheData = GetDataSet("StDAQReader");
167  if(TheData)
168  {
169  LOG_DEBUG <<"Copying EMC information from DAQ structure "<<endm;
170  return mBemcData->make(TheData,mEvent);
171  }
172  // Try StEvent
173  if(mEvent && !mMyStEvent)
174  {
175  StEmcCollection *emc = mEvent->emcCollection();
176  if(emc)
177  {
178  LOG_DEBUG <<"Copying EMC information from StEmcCollection "<<endm;
179  return mBemcData->make(emc,mEvent);
180  }
181  }
182 
183  // try MuDst as last option
184  StMuDst* muDst = (StMuDst*)GetDataSet("MuDst");
185  if(muDst)
186  {
187  StMuEmcCollection *muEmc = muDst->muEmcCollection();
188  if(muEmc)
189  {
190  LOG_DEBUG <<"Copying EMC information from StEmcCollection "<<endm;
191  Bool_t ok = mBemcData->make(muEmc,mEvent);
192  if(ok)
193  {
194  StEmcCollection *emc = mEvent->emcCollection();
195  muDst->setEmcCollection(emc);
196  }
197  else
198  muDst->setEmcCollection(NULL);
199  return ok;
200  }
201  }
202  return kFALSE;
203 }
204 //_____________________________________________________________________________
208 void StEmcADCtoEMaker::fillHistograms()
209 {
210  if(mBemcData)
211  mBemcData->fillHisto();
212 }
214 {
215  LOG_INFO << "::setPrint() is obsolete. Use logger config file to set verbosity instead." << endm;
216 }
217 void StEmcADCtoEMaker::printMap(Int_t detector,char*file)
218 {
219  if(!mBemcData->getDecoder())
220  return;
221  ofstream f(file);
222  if(detector==BTOW)
223  mBemcData->getDecoder()->PrintTowerMap(&f);
224  if(detector==BPRS)
225  mBemcData->getDecoder()->PrintPsdMap(&f);
226  if(detector==BSMDE)
227  mBemcData->getDecoder()->PrintSmdMap(&f);
228  if(detector==BSMDP)
229  mBemcData->getDecoder()->PrintSmdMap(&f);
230  f.close();
231  return;
232 }
234 {
235  if(mEvent)
236  return mEvent->emcCollection();
237  return 0;
238 }
240 {
241  if(!mTestedCorruption)
242  testCorruption();
243  return mIsCorrupted;
244 }
245 void StEmcADCtoEMaker::testCorruption()
246 {
247  mIsCorrupted = kFALSE;
248  mTestedCorruption = kTRUE;
249 
250  StEmcCollection *emc = mEvent->emcCollection();
251  if(!emc)
252  return;
253 
254  StEmcDetector* det = emc->detector(kBarrelEmcTowerId);
255  if(!det)
256  {
257  mIsCorrupted = kTRUE;
258  return;
259  }
260 
261  Bool_t flagsAreOk = kFALSE;
262 
263  //-------------------------- Check for P04k and later productions (this is easy) ----
264  for(int crate = 1; crate<=MAXCRATES; crate++)
265  {
266  StEmcCrateStatus crateStatus = det->crateStatus(crate);
267  if (crateStatus==crateHeaderCorrupt)
268  mIsCorrupted = kTRUE;
269  if (crateStatus==crateHeaderCorrupt || crateStatus==crateOK)
270  flagsAreOk = kTRUE;
271  }
272  if(flagsAreOk)
273  return;
274 
275  //-------------------------- Check for pre P04k productions (this is not so easy) ---
276 
277  // If corrupt header is detected for a crate, then hits for all
278  // modules hooked up to this crate are set to zero.
279  // Then, StEmcAdcToEMaker doesn't save hits with ADC<=0 to StEvent
280  // nModulesWithNoHits together with nModulesOff (if one is not
281  // equal another) can be used for ghost pedestal removal.
282 
283  /* turns out that we don't yet have status tables for pp data, so we need to take a different
284  tack. Thorsten writes:
285 
286  But normaly a large number of crates is corrupted (in FY04 Au+Au express
287  data I've seen never less than 4, also this is just based on a very
288  limited statistics, I just had a look at some log files...). So given
289  the 15 working crates in FY04 you could set a cut at 12, which leaves
290  enough room for failing crates and will still detect corruption.
291 
292 */
293  StBemcTables* tables = this->getBemcData()->getTables();
294  StEmcGeom* geom = StEmcGeom::instance("bemc");
295 
296  Int_t nModulesWithNoHits = 0;
297  Int_t nModulesOff = 0;
298 
299  for(UInt_t imod = 1; imod <= det->numberOfModules(); ++imod)
300  {
301  StEmcModule* module = det->module(imod);
302  Int_t NADCZero = 0;
303  StSPtrVecEmcRawHit& hits = module->hits();
304  for(UInt_t i = 0;i<hits.size();i++)
305  if(hits[i]->adc()==0)
306  NADCZero++;
307  if(NADCZero >=20)
308  {
309  nModulesWithNoHits += 1;
310  // now find out whether this module is off in status tables
311  Int_t nTowersNoGood = 0;
312  for(Int_t eta = 1; eta<=20; eta++)
313  {
314  for(Int_t sub = 1; sub<=2; sub++)
315  {
316  Int_t tower_id;
317  geom->getId(imod, eta, sub, tower_id);
318  Int_t status;
319  tables->getStatus(BTOW, tower_id, status);
320  if(status!=1)
321  nTowersNoGood += 1; // 0 is off, 1 is good, >1 is bad
322  }
323  }
324  if(nTowersNoGood>=20)
325  nModulesOff += 1;
326  }
327  }
328  if(nModulesWithNoHits != nModulesOff)
329  mIsCorrupted = kTRUE;
330  return;
331 }
332 
333 void StEmcADCtoEMaker::setCheckStatus(StDetectorId det, int flag, const char* option)
334 {
335  mBemcData->setCheckStatus(det-kBarrelEmcTowerId, flag, option);
336  return;
337 }
void setCheckStatus(Int_t det, Int_t flag, const char *option="")
Definition: StBemcRaw.cxx:806
Bool_t make(TDataSet *, StEvent *)
Make the BEMC detector from DAQ.
Definition: StBemcData.cxx:55
void PrintPsdMap(ofstream *out) const
Print SMD MAP.
virtual void AddData(TDataSet *data, const char *dir=".data")
User methods.
Definition: StMaker.cxx:332
Bool_t isCorrupted()
Returns if BTOW is corrupted or not.
virtual Int_t Init()
Init function. This method initializes the histograms.
void setPrint(Bool_t)
Obsolete function; users can control messages with logger config file.
virtual Int_t Make()
Process each event.
StBemcData * getBemcData()
Return the StBemcData pointer.
void PrintTowerMap(ofstream *out) const
Print Tower MAP.
void setProdVer(string prodVer)
Set event date.
Definition: StBemcRaw.h:174
void PrintSmdMap(ofstream *out) const
Print SMD MAP.
StBemcTables * getTables()
Return the StBemcTable pointer.
Definition: StBemcRaw.h:207
virtual Int_t Finish()
Finish function.
void setDate(Int_t d)
Set event date.
Definition: StBemcRaw.h:166
StEmcCollection * getEmcCollection()
Return emcCollection.
void createDecoder(Int_t, Int_t)
Create new StEmcDecoder.
Definition: StBemcRaw.cxx:233
void printMap(Int_t, char *)
print map for an EMC detector
StEmcDecoder * getDecoder()
Return the StEmcDecoder pointer.
Definition: StBemcRaw.h:211
void loadTables(StMaker *anyMaker)
load tables.
static StMuEmcCollection * muEmcCollection()
returns pointer to current StMuEmcCollection
Definition: StMuDst.h:389
static StMuEvent * event()
returns pointer to current StMuEvent (class holding the event wise information, e.g. event number, run number)
Definition: StMuDst.h:320
Definition: Stypes.h:40
virtual Int_t InitRun(Int_t)
InitRun function.
void printConf()
Print configuration.
Definition: StBemcRaw.cxx:217
void getStatus(Int_t det, Int_t softId, Int_t &status, const char *option="") const
Return status.
static void setEmcCollection(StEmcCollection *emc_coll)
set pointer to current StEmcCollection
Definition: StMuDst.h:146
Definition: Stypes.h:41
virtual ~StEmcADCtoEMaker()
StEmcADCtoEMaker destructor.
void setCheckStatus(StDetectorId det, int flag, const char *option="")