00001 #include <stdio.h>
00002 #include "StBemcStatusMaker.h"
00003
00004 #include "StEnumerations.h"
00005 #include "StEvent.h"
00006 #include "StRunInfo.h"
00007 #include "StTriggerIdCollection.h"
00008 #include "StTriggerId.h"
00009 #include "StEmcCollection.h"
00010 #include "StEmcDetector.h"
00011 #include "StEmcModule.h"
00012 #include "StEmcRawHit.h"
00013 #include "StL0Trigger.h"
00014 #include "StMuDSTMaker/COMMON/StMuDst.h"
00015 #include "StMuDSTMaker/COMMON/StMuEmcUtil.h"
00016 #include "StMuDSTMaker/COMMON/StMuEvent.h"
00017 #include "StMuDSTMaker/COMMON/StMuEmcCollection.h"
00018 #include "StMuDSTMaker/COMMON/StMuTriggerIdCollection.h"
00019 #include "StMuDSTMaker/COMMON/StMuEmcTowerData.h"
00020 #include "StEmcADCtoEMaker/StEmcADCtoEMaker.h"
00021
00022 #include "StEmcUtil/geometry/StEmcGeom.h"
00023 #include "StEEmcUtil/database/StEEmcDb.h"
00024 #include "StEEmcUtil/database/EEmcDbItem.h"
00025
00026 #include "StDbManager.hh"
00027 #include "StDbConfigNode.hh"
00028 #include "StDataBaseI.hh"
00029
00030 StBemcStatusMaker::StBemcStatusMaker(StMuDstMaker* maker)
00031 : StMaker("bemcStatus"), mMuDstMaker(maker) {
00032 mOutputDirectory = "/tmp";
00033 mOutputFilePrefix = "junk";
00034 mOutputFile = NULL;
00035 eeDb = 0;
00036 if(eeDb==0) {
00037 cout << "EEmcDbMaker not in chain. Add it." << endl;
00038
00039 }
00040 }
00041
00042 Int_t StBemcStatusMaker::Init() {
00043 eeDb = (StEEmcDb*)this->GetDataSet("StEEmcDb");
00044
00045 string s = mOutputDirectory + "/" + mOutputFilePrefix + "cal.minirun.root";
00046 mOutputFile = new TFile(s.c_str(),"RECREATE");
00047 mOutputTree = new TTree("calinfo","Extraneous Information");
00048 mOutputTree->Branch("fillnum",&mFillNumber,"fillnum/F");
00049 mOutputTree->Branch("thedate",&mTheDate,"thedate/I");
00050 mOutputTree->Branch("thetime",&mTheTime,"thetime/I");
00051 mOutputTree->Branch("statusEEMC",mEemcStatusBits,"statusEEMC/F");
00052 mOutputTree->Branch("statusBEMC",mBemcStatusBits,"statusBEMC/F");
00053 mFirstEvent = kTRUE;
00054 if (!mOutputFile) return kStErr;
00055 return kStOk;
00056 }
00057
00058 Int_t StBemcStatusMaker::Make() {
00059 StMuEvent *muEvent = mMuDstMaker->muDst()->event();
00060 Int_t runnumber=muEvent->eventInfo().runId();
00061
00062
00063 StMuTriggerIdCollection& trgIdColl=muEvent->triggerIdCollection();
00064 const StTriggerId& oflTrgId=trgIdColl.nominal();
00065 vector<unsigned int> trgId=oflTrgId.triggerIds();
00066 bool isGood=false;
00067 uint i;
00068 for(i = 0; i < trgId.size() ; i++){
00069
00070 if(trgId[i]==117001 || trgId[i]==117811 || trgId[i]==147001) isGood=true;
00071 }
00072 if (!isGood) {
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082 }
00083
00084 StEvent* event = static_cast<StEvent*>(GetInputDS("StEvent"));
00085 if (!event) {
00086 cout <<" Not StEvent!"<<endl;
00087 return kStWarn;
00088 }
00089
00090 StEmcCollection* emcColl = event->emcCollection();
00091 if (!emcColl) {
00092 cout <<"No emc Collection"<<endl;
00093 return kStOk;
00094 }
00095 StEmcDetector* bemc = emcColl->detector(kBarrelEmcTowerId);
00096 if (!bemc) {
00097 cout << "No barrel!" << endl;
00098 return kStOk;
00099 }
00100
00101
00102
00103 for(int crate = 1; crate<=MAXCRATES; crate++) {
00104 StEmcCrateStatus crateStatus = bemc->crateStatus(crate);
00105 if (crateStatus==crateHeaderCorrupt) {
00106 cout << "corruption!" << endl;
00107 return kStOk;
00108 }
00109 }
00110
00111 StMuEmcCollection* muemcColl = mMuDstMaker->muDst()->muEmcCollection();
00112
00113
00114
00115 TH2F* bemcAdcHist = getBemcAdcHist(runnumber);
00116
00117
00118
00119 if (!bemcAdcHist
00120
00121 ) {
00122 cout <<"Problems with Histo"<<endl;
00123 return kStWarn;
00124 }
00125
00126
00127
00128 for (UInt_t i = 1; i <= bemc->numberOfModules(); i++) {
00129 StEmcModule* module = bemc->module(i);
00130 if (module) {
00131 StSPtrVecEmcRawHit& hits = module->hits();
00132 for (StEmcRawHitIterator hit = hits.begin(); hit!=hits.end(); ++hit) {
00133 Int_t id = 0;
00134 StEmcGeom* geom = StEmcGeom::instance("bemc");
00135 geom->getId((*hit)->module(),(*hit)->eta(),(*hit)->sub(),id);
00136 bemcAdcHist->Fill(id,(*hit)->adc());
00137
00138 }
00139 }
00140 }
00141
00142 int id, sec, sub, etabin, rawadc;
00143 if(muemcColl) {
00144 for (int i = 0; i < muemcColl->getNEndcapTowerADC(); i++) {
00145 muemcColl->getEndcapTowerADC(i,rawadc,sec,sub,etabin);
00146
00147
00148
00149
00150 mMuDstMaker->muEmcUtil()->getEndcapId(5,sec,etabin,sub,id);
00151 if(id != i+1) {
00152 cout << "my scheme for EEMC doesn't work right" << endl;
00153 cout << "i is " << i << " and id is " << id << endl;
00154 assert(id-i+1);
00155 }
00156
00157 }
00158 }
00159 if(mFirstEvent) {
00160
00161
00162 StDbManager* mgr=StDbManager::Instance();
00163 StDbConfigNode* node=mgr->initConfig("RunLog_onl");
00164 StDbTable* tab=node->addDbTable("beamInfo");
00165 StDataBaseI* filldb=mgr->findDb("RunLog_onl");
00166 unsigned int ts;
00167 char queryStr[128];
00168 sprintf(queryStr," where runNumber='%d' and deactive=0",runnumber);
00169 cout << queryStr << endl;
00170 ts = filldb->QueryDb(tab,queryStr);
00171 cout << ts << endl;
00172 if (ts) {
00173 char* start = tab->getBeginDateTime();
00174 int startTime = atoi(&(start[8]));
00175 start[8] = 0;
00176 mTheDate = atoi(start);
00177 if (start[12] == '0')
00178 mTheTime = startTime - 50;
00179 else
00180 mTheTime = startTime - 10;
00181
00182 }
00183
00184 mFillNumber=muEvent->runInfo().beamFillNumber(yellow);
00185 for(int i=0; i<720; i++) {
00186 muemcColl->getEndcapTowerADC(i,rawadc,sec,sub,etabin);
00187
00188
00189
00190 }
00191
00192
00193 mOutputTree->Fill();
00194 mFirstEvent=kFALSE;
00195 }
00196
00197 return kStOk;
00198 }
00199
00200 Int_t StBemcStatusMaker::Finish() {
00201 if (mOutputFile) {
00202 mOutputFile->Write();
00203 delete mOutputFile;
00204 mOutputFile = NULL;
00205 }
00206 return kStOk;
00207 }
00208
00209 TH2F* StBemcStatusMaker::getBemcAdcHist(Int_t runNumber) {
00210 Char_t name[255];
00211 snprintf(name,254,"bemcStatusAdc_%d",runNumber);
00212 mOutputFile->cd();
00213 TH2F* hist = dynamic_cast<TH2F*>(mOutputFile->Get(name));
00214 if (!hist) {
00215 Char_t title[255];
00216 snprintf(title,254,"BEMC tower adc run %d",runNumber);
00217
00218
00219 hist = new TH2F(name, title,4801,-0.5,4800.5,3000,0,3000);
00220 hist->GetXaxis()->SetTitle("tower id");
00221 hist->GetYaxis()->SetTitle("adc");
00222 }
00223 return hist;
00224 }
00225
00226 TH2F* StBemcStatusMaker::getBemcEnergyHist(Int_t runNumber) {
00227 Char_t name[255];
00228 snprintf(name,254,"bemcStatusEnergy_%d",runNumber);
00229 mOutputFile->cd();
00230 TH2F* hist = dynamic_cast<TH2F*>(mOutputFile->Get(name));
00231 if (!hist) {
00232 Char_t title[255];
00233 snprintf(title,254,"BEMC tower energy run %d",runNumber);
00234 hist = new TH2F(name, title,4801,-0.5,4800.5,150,0,3);
00235 hist->GetXaxis()->SetTitle("tower id");
00236 hist->GetYaxis()->SetTitle("adc");
00237 }
00238 return hist;
00239 }
00240
00241 TH2F* StBemcStatusMaker::getEemcAdcHist(Int_t runNumber) {
00242 Char_t name[255];
00243 snprintf(name,254,"eemcStatusAdc_%d",runNumber);
00244 mOutputFile->cd();
00245 TH2F* hist = dynamic_cast<TH2F*>(mOutputFile->Get(name));
00246 if (!hist) {
00247 Char_t title[255];
00248 snprintf(title,254,"EEMC tower adc run %d",runNumber);
00249 hist = new TH2F(name, title,721,-0.5,720.5,150,0,150);
00250 hist->GetXaxis()->SetTitle("tower id");
00251 hist->GetYaxis()->SetTitle("adc");
00252 }
00253 return hist;
00254 }
00255
00256 TH2F* StBemcStatusMaker::getEemcEnergyHist(Int_t runNumber) {
00257 Char_t name[255];
00258 snprintf(name,254,"eemcStatusEnergy_%d",runNumber);
00259 mOutputFile->cd();
00260 TH2F* hist = dynamic_cast<TH2F*>(mOutputFile->Get(name));
00261 if (!hist) {
00262 Char_t title[255];
00263 snprintf(title,254,"EEMC tower energy run %d",runNumber);
00264 hist = new TH2F(name, title,4801,-0.5,4800.5,150,0,3);
00265 hist->GetXaxis()->SetTitle("tower id");
00266 hist->GetYaxis()->SetTitle("adc");
00267 }
00268 return hist;
00269 }
00270
00271 ClassImp(StBemcStatusMaker)