StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StBemcStatusMaker.cxx
1 #ifdef __APPLE__
2 #include <sys/types.h>
3 #endif
4 #include <stdio.h>
5 #include "StBemcStatusMaker.h"
6 
7 #include "StEnumerations.h"
8 #include "StEvent.h"
9 #include "StRunInfo.h"
10 #include "StTriggerIdCollection.h"
11 #include "StTriggerId.h"
12 #include "StEmcCollection.h"
13 #include "StEmcDetector.h"
14 #include "StEmcModule.h"
15 #include "StEmcRawHit.h"
16 #include "StL0Trigger.h"
17 #include "StMuDSTMaker/COMMON/StMuDst.h"
18 #include "StMuDSTMaker/COMMON/StMuEmcUtil.h"
19 #include "StMuDSTMaker/COMMON/StMuEvent.h"
20 #include "StMuDSTMaker/COMMON/StMuEmcCollection.h"
21 #include "StMuDSTMaker/COMMON/StMuTriggerIdCollection.h"
22 #include "StMuDSTMaker/COMMON/StMuEmcTowerData.h"
23 #include "StEmcADCtoEMaker/StEmcADCtoEMaker.h"
24 
25 #include "StEmcUtil/geometry/StEmcGeom.h"
26 #include "StEEmcUtil/database/StEEmcDb.h"
27 #include "StEEmcUtil/database/EEmcDbItem.h"
28 
29 #include "StDbManager.hh" // D.Staszak
30 #include "StDbConfigNode.hh"
31 #include "StDataBaseI.hh"
32 
33 StBemcStatusMaker::StBemcStatusMaker(StMuDstMaker* maker)
34  : StMaker("bemcStatus"), mMuDstMaker(maker) {
35  mOutputDirectory = "/tmp";
36  mOutputFilePrefix = "junk";
37  mOutputFile = NULL;
38  eeDb = 0;
39  if(eeDb==0) {
40  cout << "EEmcDbMaker not in chain. Add it." << endl;
41 // assert(eeDb);
42  }
43 }
44 
45 Int_t StBemcStatusMaker::Init() {
46  eeDb = (StEEmcDb*)this->GetDataSet("StEEmcDb");
47  // create the output file
48  string s = mOutputDirectory + "/" + mOutputFilePrefix + "cal.minirun.root";
49  mOutputFile = new TFile(s.c_str(),"RECREATE");
50  mOutputTree = new TTree("calinfo","Extraneous Information");
51  mOutputTree->Branch("fillnum",&mFillNumber,"fillnum/F");
52  mOutputTree->Branch("thedate",&mTheDate,"thedate/I");
53  mOutputTree->Branch("thetime",&mTheTime,"thetime/I");
54  mOutputTree->Branch("statusEEMC",mEemcStatusBits,"statusEEMC/F");
55  mOutputTree->Branch("statusBEMC",mBemcStatusBits,"statusBEMC/F");
56  mFirstEvent = kTRUE;
57  if (!mOutputFile) return kStErr;
58  return kStOk;
59 }
60 
62  StMuEvent *muEvent = mMuDstMaker->muDst()->event();
63  Int_t runnumber=muEvent->eventInfo().runId();
64 // Int_t otherrunnumber = GetRunNumber();
65 
66  StMuTriggerIdCollection& trgIdColl=muEvent->triggerIdCollection();
67  const StTriggerId& oflTrgId=trgIdColl.nominal();
68  vector<unsigned int> trgId=oflTrgId.triggerIds();
69  bool isGood=false;
70  uint i;
71  for(i = 0; i < trgId.size() ; i++){
72  //if(trgId[i]==96011 || trgId[i]==106011 || trgId[i]==117001) isGood=true;
73  if(trgId[i]==117001 || trgId[i]==117811 || trgId[i]==147001) isGood=true; //2006 mb and mb-fast(200GeV), mb (62GeV)
74  }
75  if (!isGood) {
76 // cout <<" wrong triggers!"<<endl;
77 
78 
79  //this is a huge change, I'm just doing it to see what happens
80  //with all triggers. The only change is the removal of the
81  //following line.
82  //line put back
83 
84  //return kStOk;
85  }
86 
87  StEvent* event = static_cast<StEvent*>(GetInputDS("StEvent"));
88  if (!event) {
89  cout <<" Not StEvent!"<<endl;
90  return kStWarn;
91  }
92 
93  StEmcCollection* emcColl = event->emcCollection();
94  if (!emcColl) {
95  cout <<"No emc Collection"<<endl;
96  return kStOk;
97  }
98  StEmcDetector* bemc = emcColl->detector(kBarrelEmcTowerId);
99  if (!bemc) {
100  cout << "No barrel!" << endl;
101  return kStOk;
102  }
103 
104 //crate corruption check
105 
106  for(int crate = 1; crate<=MAXCRATES; crate++) {
107  StEmcCrateStatus crateStatus = bemc->crateStatus(crate);
108  if (crateStatus==crateHeaderCorrupt) {
109  cout << "corruption!" << endl;
110  return kStOk; //corrupt event
111  }
112  }
113 
114  StMuEmcCollection* muemcColl = mMuDstMaker->muDst()->muEmcCollection();
115 
116 //make histograms to be saved
117 
118  TH2F* bemcAdcHist = getBemcAdcHist(runnumber);
119  // TH2F* bemcEnergyHist = getBemcEnergyHist(runnumber);
120  // TH2F* eemcAdcHist = getEemcAdcHist(runnumber);
121  // TH2F* eemcEnergyHist = getEemcEnergyHist(event->runId());
122  if (!bemcAdcHist //|| !eemcAdcHist || !bemcEnergyHist
123  // || !eemcEnergyHist
124  ) {
125  cout <<"Problems with Histo"<<endl;
126  return kStWarn;
127  }
128 
129 // loop over bemc and fill histograms
130 
131  for (UInt_t i = 1; i <= bemc->numberOfModules(); i++) {
132  StEmcModule* module = bemc->module(i);
133  if (module) {
134  StSPtrVecEmcRawHit& hits = module->hits();
135  for (StEmcRawHitIterator hit = hits.begin(); hit!=hits.end(); ++hit) {
136  Int_t id = 0;
137  StEmcGeom* geom = StEmcGeom::instance("bemc");
138  geom->getId((*hit)->module(),(*hit)->eta(),(*hit)->sub(),id);
139  bemcAdcHist->Fill(id,(*hit)->adc());
140  //bemcEnergyHist->Fill(id,(*hit)->energy());
141  }
142  }
143  }
144 // loop over eemc and fill histograms
145  int id, sec, sub, etabin, rawadc;
146  if(muemcColl) {
147  for (int i = 0; i < muemcColl->getNEndcapTowerADC(); i++) {
148  muemcColl->getEndcapTowerADC(i,rawadc,sec,sub,etabin);
149 //now we need to find the ID for it
150 //the EEMC does not support the primary MuDst EEMC indexing code
151 //classic
152 //btw, id = etabin + 12*(sub-1) + 5*12*(sec-1);
153  mMuDstMaker->muEmcUtil()->getEndcapId(5,sec,etabin,sub,id);
154  if(id != i+1) {
155  cout << "my scheme for EEMC doesn't work right" << endl;
156  cout << "i is " << i << " and id is " << id << endl;
157  assert(id-i+1);
158  }
159  // eemcAdcHist->Fill(id,rawadc); //D.Staszak
160  }
161  }
162  if(mFirstEvent) {
163 
164  // Query the Db to find the run start time and date --- D.Staszak
166  StDbConfigNode* node=mgr->initConfig("RunLog_onl");
167  StDbTable* tab=node->addDbTable("beamInfo");
168  StDataBaseI* filldb=mgr->findDb("RunLog_onl");
169  unsigned int ts;
170  char queryStr[128];
171  sprintf(queryStr," where runNumber='%d' and deactive=0",runnumber);
172  cout << queryStr << endl;
173  ts = filldb->QueryDb(tab,queryStr);
174  cout << ts << endl;
175  if (ts) {
176  char* start = tab->getBeginDateTime();
177  int startTime = atoi(&(start[8]));
178  start[8] = 0;
179  mTheDate = atoi(start);
180  if (start[12] == '0')
181  mTheTime = startTime - 50;
182  else
183  mTheTime = startTime - 10;
184  //cout << "theTime: " << mTheTime << "\ttheDate: " << mTheDate << endl;
185  }
186 
187  mFillNumber=muEvent->runInfo().beamFillNumber(yellow);
188  for(int i=0; i<720; i++) {
189  muemcColl->getEndcapTowerADC(i,rawadc,sec,sub,etabin);
190 // const EEmcDbItem *x=eeDb->getTile(sec,'A'+sub-1,etabin,'T');
191 // mEemcFailBits[i] = x->fail;
192 // mEemcStatusBits[i] = x->stat;
193  }
194 
195  //FIND BEMC STATUSES
196  mOutputTree->Fill();
197  mFirstEvent=kFALSE;
198  }
199 
200  return kStOk;
201 }
202 
204  if (mOutputFile) {
205  mOutputFile->Write();
206  delete mOutputFile;
207  mOutputFile = NULL;
208  }
209  return kStOk;
210 }
211 
212 TH2F* StBemcStatusMaker::getBemcAdcHist(Int_t runNumber) {
213  Char_t name[255];
214  snprintf(name,254,"bemcStatusAdc_%d",runNumber);
215  mOutputFile->cd();
216  TH2F* hist = dynamic_cast<TH2F*>(mOutputFile->Get(name));
217  if (!hist) {
218  Char_t title[255];
219  snprintf(title,254,"BEMC tower adc run %d",runNumber);
220  //hist = new TH2F(name, title,4801,-0.5,4800.5,150,0,150);
221  //hist = new TH2F(name, title,4801,-0.5,4800.5,750,0,750);
222  hist = new TH2F(name, title,4801,-0.5,4800.5,3000,0,3000);
223  hist->GetXaxis()->SetTitle("tower id");
224  hist->GetYaxis()->SetTitle("adc");
225  }
226  return hist;
227 }
228 
229 TH2F* StBemcStatusMaker::getBemcEnergyHist(Int_t runNumber) {
230  Char_t name[255];
231  snprintf(name,254,"bemcStatusEnergy_%d",runNumber);
232  mOutputFile->cd();
233  TH2F* hist = dynamic_cast<TH2F*>(mOutputFile->Get(name));
234  if (!hist) {
235  Char_t title[255];
236  snprintf(title,254,"BEMC tower energy run %d",runNumber);
237  hist = new TH2F(name, title,4801,-0.5,4800.5,150,0,3);
238  hist->GetXaxis()->SetTitle("tower id");
239  hist->GetYaxis()->SetTitle("adc");
240  }
241  return hist;
242 }
243 
244 TH2F* StBemcStatusMaker::getEemcAdcHist(Int_t runNumber) {
245  Char_t name[255];
246  snprintf(name,254,"eemcStatusAdc_%d",runNumber);
247  mOutputFile->cd();
248  TH2F* hist = dynamic_cast<TH2F*>(mOutputFile->Get(name));
249  if (!hist) {
250  Char_t title[255];
251  snprintf(title,254,"EEMC tower adc run %d",runNumber);
252  hist = new TH2F(name, title,721,-0.5,720.5,150,0,150);
253  hist->GetXaxis()->SetTitle("tower id");
254  hist->GetYaxis()->SetTitle("adc");
255  }
256  return hist;
257 }
258 
259 TH2F* StBemcStatusMaker::getEemcEnergyHist(Int_t runNumber) {
260  Char_t name[255];
261  snprintf(name,254,"eemcStatusEnergy_%d",runNumber);
262  mOutputFile->cd();
263  TH2F* hist = dynamic_cast<TH2F*>(mOutputFile->Get(name));
264  if (!hist) {
265  Char_t title[255];
266  snprintf(title,254,"EEMC tower energy run %d",runNumber);
267  hist = new TH2F(name, title,4801,-0.5,4800.5,150,0,3);
268  hist->GetXaxis()->SetTitle("tower id");
269  hist->GetYaxis()->SetTitle("adc");
270  }
271  return hist;
272 }
273 
274 ClassImp(StBemcStatusMaker)
virtual Int_t Finish()
virtual Int_t Make()
StMuDst * muDst()
Definition: StMuDstMaker.h:425
StMuEmcUtil * muEmcUtil()
return pointer to StMuEmcUtil;
Definition: StMuDstMaker.h:193
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:42
static StDbManager * Instance()
strdup(..) is not ANSI
Definition: StDbManager.cc:155
Definition: Stypes.h:44
Collection of trigger ids as stored in MuDst.
Definition: Stypes.h:41