00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "CSMStatusUtils.h"
00015
00016 #include "TMath.h"
00017 #include "TH2.h"
00018 #include "TAxis.h"
00019 #include "TROOT.h"
00020 #include "TKey.h"
00021 #include "TIterator.h"
00022 #include "TFile.h"
00023 #include "TSystem.h"
00024 #include "TF1.h"
00025 #include "TCanvas.h"
00026 #include "TStyle.h"
00027 #include "tables/St_emcStatus_Table.h"
00028 #include "tables/St_emcPed_Table.h"
00029 #include "StEmcUtil/database/StEmcDecoder.h"
00030
00031 #include <iostream>
00032 #include <fstream>
00033 #include <iomanip>
00034 #include <map>
00035 #include <set>
00036 #include <string>
00037 #include <stdio.h>
00038
00039 using namespace std;
00040
00041 typedef map<Int_t,vector<Short_t>*>::const_iterator IntToPtrVecShortConstIter ;
00042
00043
00044 void
00045 CSMStatusUtils::setDetectorFlavor(TString flavor) {
00046 mDetectorFlavor=flavor;
00047 if(mDetectorFlavor=="bemc") {
00048 mDetectorSize=4800;
00049 mDetectorActualSize=4800;
00050 mRunStatusMapPtr=&mBEMCRunStatusMap;
00051 } else if(mDetectorFlavor=="eemc") {
00052 mDetectorSize=720;
00053 mDetectorActualSize=720;
00054 mRunStatusMapPtr=&mEEMCRunStatusMap;
00055 TString tms;
00056 ifstream ifs("StRoot/StEmcPool/CSMStatusUtils/eemccratemap");
00057 int tower, crate, channel;
00058 while(!ifs.eof()) {
00059 tms.ReadLine(ifs);
00060 sscanf(tms.Data(),"%d %d %d",&crate,&channel,&tower);
00061 eemcCrateMap[crate-1][channel] = tower;
00062 }
00063 ifs.close();
00064 }
00065 }
00066
00067
00068
00069
00070 Int_t
00071 CSMStatusUtils::initializeHistFileFromDir(TString directory,TString filter) {
00072
00073 void *dir = NULL;
00074 if ((dir = gSystem->OpenDirectory(directory.Data())) != NULL) {
00075 const Char_t *dirEntry;
00076 while ((dirEntry = gSystem->GetDirEntry(dir)) != NULL) {
00077 Char_t buffer[2048];
00078 strcpy(buffer,directory.Data());
00079 if (buffer[strlen(buffer)-1] != '/') strcat(buffer,"/");
00080 strcat(buffer,dirEntry);
00081 if (!strstr(buffer,filter.Data())) continue;
00082 Char_t* needle = strstr(buffer,"run");
00083 Int_t runNumber = 0;
00084 if (needle) {
00085 needle+=3;
00086 Char_t runString[10];
00087 strncpy(runString,needle,7);
00088 runNumber = atoi(runString);
00089 }
00090 if (runNumber != 0) mHistFileMap[runNumber] = buffer;
00091 }
00092 }
00093 return mHistFileMap.size();
00094 }
00095
00096
00097
00098
00099 Int_t
00100 CSMStatusUtils::readTablesFromASCII(TString directory,TString filter) {
00101 void* dir = NULL;
00102 TString buffert = directory + "/status/";
00103 TString tmpstr;
00104 if ((dir = gSystem->OpenDirectory(buffert.Data())) != NULL) {
00105 const Char_t *dirEntry;
00106 while ((dirEntry = gSystem->GetDirEntry(dir)) != NULL) {
00107 Char_t buffer[2048];
00108 strcpy(buffer,buffert.Data());
00109 strcat(buffer,dirEntry);
00110 if (!strstr(buffer,filter.Data())) continue;
00111 tmpstr = dirEntry;
00112 if(!tmpstr.Contains(mDetectorFlavor.Data())) continue;
00113 Char_t* needle = strstr(buffer,"run");
00114 Int_t runNumber = 0, thetime = 0, thedate = 0;
00115 if (needle) {
00116 needle+=3;
00117 Char_t runString[10];
00118 Char_t timeString[10];
00119 Char_t dateString[10];
00120 strncpy(runString,needle,7);
00121 runNumber = atoi(runString);
00122 needle+=13;
00123 strncpy(dateString,needle,8);
00124 thedate = atoi(dateString);
00125 needle+=9;
00126 strncpy(timeString,needle,6);
00127 thetime = atoi(timeString);
00128 }
00129 if (runNumber != 0) {
00130 ifstream in(buffer);
00131 if(in.good()) {
00132 Int_t status,itemp;
00133 vector<Short_t>* vec = new vector<Short_t>(mDetectorSize+1);
00134 for(int id=1; id<mDetectorSize+1; id++) {
00135
00136 in >> itemp >> status;
00137
00138 (*vec)[id] = status;
00139 }
00140 cout << buffer << " is status file that was read" << endl;
00141 (*mRunStatusMapPtr)[runNumber] = vec;
00142 mRunTimestampMap[runNumber] = thetime;
00143 mRunDatestampMap[runNumber] = thedate;
00144
00145
00146 }
00147 in.close();
00148 }
00149 }
00150 }
00151 return mRunStatusMapPtr->size();
00152 }
00153
00154 void
00155 CSMStatusUtils::plotAllStatuses(TString rootfiledir,int year,int runstart) {
00156 void* dir = NULL;
00157 TString tmpstr;
00158 vector<Int_t> runlist;
00159 int runnumber;
00160 if ((dir = gSystem->OpenDirectory(rootfiledir.Data())) != NULL) {
00161 const Char_t *dirEntry;
00162 while ((dirEntry = gSystem->GetDirEntry(dir)) != NULL) {
00163 Char_t buffer[2048];
00164 strcpy(buffer,rootfiledir.Data());
00165 strcat(buffer,dirEntry);
00166 if (!strstr(buffer,".root")) continue;
00167 if (strstr(buffer,"run.root")) continue;
00168 Char_t* needle = strstr(buffer,"run");
00169 Int_t runNumber = 0;
00170 if (needle) {
00171 needle+=3;
00172 Char_t runString[10];
00173 strncpy(runString,needle,7);
00174 runNumber = atoi(runString);
00175 runlist.push_back(runNumber);
00176 }
00177 }
00178 }
00179 tm ptm;
00180 ptm.tm_year = year-1900;
00181 int firstdate=99999999, firsttime,lastdate=0, lasttime, firstrun=99999999, lastrun=0;
00182 IntToPtrVecShortConstIter first = mRunStatusMapPtr->begin();
00183 IntToPtrVecShortConstIter last = mRunStatusMapPtr->end();
00184 IntToPtrVecShortConstIter iter = first;
00185 for(iter=first;iter!=last;iter++) {
00186 runnumber = iter->first;
00187 if(runnumber < runstart) continue;
00188 if(firstdate > mRunDatestampMap[runnumber]) {
00189 firstdate = mRunDatestampMap[runnumber];
00190 firsttime = mRunTimestampMap[runnumber];
00191 } else if (firstdate == mRunDatestampMap[runnumber] && firsttime > mRunTimestampMap[runnumber]) {
00192 firsttime = mRunTimestampMap[runnumber];
00193 }
00194 if(lastdate < mRunDatestampMap[runnumber]) {
00195 lastdate = mRunDatestampMap[runnumber];
00196 lasttime = mRunTimestampMap[runnumber];
00197 } else if (lastdate == mRunDatestampMap[runnumber] && lasttime < mRunTimestampMap[runnumber]) {
00198 lasttime = mRunTimestampMap[runnumber];
00199 }
00200 if(firstrun > runnumber && runnumber > runstart) firstrun = runnumber;
00201 if(lastrun < runnumber) lastrun = runnumber;
00202 }
00203
00204 int bigyearnumber = year*10000;
00205
00206 ptm.tm_mon = ((firstdate-bigyearnumber)/100)+1;
00207 ptm.tm_mday = (firstdate-bigyearnumber)%100;
00208 ptm.tm_hour = firsttime/10000;
00209 ptm.tm_min = (firsttime%10000)/100;
00210 ptm.tm_sec = firsttime%100;
00211 time_t firstdatet = mktime(&ptm);
00212 ptm.tm_mon = ((lastdate-bigyearnumber)/100)+1;
00213 ptm.tm_mday = (lastdate-bigyearnumber)%100;
00214 ptm.tm_hour = lasttime/10000;
00215 ptm.tm_min = (lasttime%10000)/100;
00216 ptm.tm_sec = lasttime%100;
00217 time_t lastdatet = mktime(&ptm);
00218
00219 int diffseconds = (int)difftime(lastdatet,firstdatet);
00220 TCanvas* tc = new TCanvas("peter","Status vs Run Number",800,800);
00221 tc->cd();
00222 int timegap = 3600;
00223
00224 TH2F* histogram = new TH2F("stevegeech","Time (Hours) vs BEMC Channels (bad)",4801,-0.5,4800.5,diffseconds/timegap+1,-0.5,diffseconds/timegap+0.5);
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239 vector<int> binbounds;
00240 int currentbin;
00241 for(iter=first;iter!=last;iter++) {
00242 runnumber = iter->first;
00243 if(runnumber < runstart) continue;
00244 vector<Short_t>* statusVector = (*mRunStatusMapPtr)[runnumber];
00245 if(statusVector) {
00246 ptm.tm_mon = ((mRunDatestampMap[runnumber]-bigyearnumber)/100)+1;
00247 ptm.tm_mday = (mRunDatestampMap[runnumber]-bigyearnumber)%100;
00248 ptm.tm_hour = mRunTimestampMap[runnumber]/10000;
00249 ptm.tm_min = (mRunTimestampMap[runnumber]%10000)/100;
00250 ptm.tm_sec = mRunTimestampMap[runnumber]%100;
00251 time_t timet = mktime(&ptm);
00252 double timedifference = difftime(timet,firstdatet);
00253 int ratiodifftogap = (int)timedifference/timegap;
00254 currentbin = histogram->GetBin(0,ratiodifftogap)/(mDetectorSize+3);
00255
00256 binbounds.push_back(currentbin);
00257 }
00258 }
00259 binbounds.push_back(currentbin);
00260 int bb=0;
00261 for(iter=first;iter!=last;iter++) {
00262 runnumber = iter->first;
00263 if(runnumber < runstart) continue;
00264 vector<Short_t>* statusVector = (*mRunStatusMapPtr)[runnumber];
00265 if(statusVector) {
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275 for(int i=1; i<4801; i++) {
00276 if((*statusVector)[i]!=1) {
00277 for(int bound=binbounds[bb]; bound<binbounds[bb+1]; bound++) {
00278 histogram->Fill(i,bound);
00279
00280 }
00281 }
00282 }
00283
00284 }
00285 bb++;
00286 }
00287 histogram->Draw("colz");
00288 }
00289
00290
00291
00292
00293
00294
00295
00296 Int_t
00297 CSMStatusUtils::saveAbbreviatedStatusTablesToASCII(TString directory) {
00298
00299 TString tmpstr;
00300 int runnumber;
00301 IntToPtrVecShortConstIter first = mRunStatusMapPtr->begin();
00302 IntToPtrVecShortConstIter last = mRunStatusMapPtr->end();
00303 IntToPtrVecShortConstIter iter = first;
00304 IntToPtrVecShortConstIter preiter = first;
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314 vector<Float_t> statuscounter(mDetectorSize+1);
00315 vector<Short_t> totalStatusVector(mDetectorSize+1);
00316 for(int i=0; i<mDetectorSize+1; i++) {
00317 totalStatusVector[i] = 1;
00318 statuscounter[i] = 0;
00319 }
00320 Short_t fakeZero = 1024;
00321 Bool_t firstone = kTRUE;
00322 Short_t oldstatus, status;
00323 Int_t badChannelsInRun;
00324 for(iter=first;iter!=last;iter++) {
00325 runnumber = iter->first;
00326 vector<Short_t>* statusVector = iter->second;
00327 vector<Short_t>* oldStatusVector = preiter->second;
00328 badChannelsInRun = 0;
00329 for (Int_t i = 1; i < mDetectorSize + 1; i++) {
00330 oldstatus = (*oldStatusVector)[i];
00331 status = (*statusVector)[i];
00332 if(oldstatus == 0) oldstatus = fakeZero;
00333 if(status == 0) status = fakeZero;
00334
00335
00336
00337
00338
00339
00340 if(firstone) {
00341 totalStatusVector[i] = status;
00342 } else if(oldstatus == 1 && status == 1) {
00343 continue;
00344 } else if(status != 1) {
00345 if(totalStatusVector[i] == 1) {
00346 totalStatusVector[i] = status;
00347 } else {
00348 totalStatusVector[i] |= status;
00349 }
00350 } else if(oldstatus != 1) {
00351 if(totalStatusVector[i] == 1) {
00352 totalStatusVector[i] = oldstatus;
00353 } else {
00354 totalStatusVector[i] |= oldstatus;
00355 }
00356 } else {
00357 if(totalStatusVector[i] == 1) {
00358 totalStatusVector[i] = (oldstatus | status);
00359 } else {
00360 totalStatusVector[i] |= (oldstatus | status);
00361 }
00362 }
00363
00364
00365
00366 if(i < mDetectorActualSize) badChannelsInRun++;
00367
00368
00369 if (oldstatus != status) statuscounter[i] += 1;
00370 }
00371
00372 for (Int_t i = 1; i < mDetectorSize + 1; i++) {
00373 oldstatus = (*oldStatusVector)[i];
00374 status = (*statusVector)[i];
00375 if(badChannelsInRun > 0.5 * mDetectorActualSize && oldstatus != status)
00376 statuscounter[i] -= 1;
00377 }
00378 preiter = iter;
00379 firstone = kFALSE;
00380 }
00381
00382
00383 iter = first;
00384 preiter = first;
00385 TString datetimestring, runnumberstring;
00386 firstone = kTRUE;
00387 for(iter=first; iter!=last; iter++) {
00388 int numberofchangedchannels=0;
00389 runnumber = iter->first;
00390 runnumberstring = "";
00391 runnumberstring += runnumber;
00392 tmpstr = directory + "/status/short_status_" + mDetectorFlavor + "_run"
00393 + runnumberstring + ".status";
00394 ofstream ofs(tmpstr.Data());
00395
00396 St_emcStatus *bemc_status=new St_emcStatus("bemcStatus",1);
00397 emcStatus_st *emcstatus=bemc_status->GetTable();
00398 for (Int_t i_tow=0; i_tow<4800; i_tow++) emcstatus->Status[i_tow]=1;
00399
00400 vector<Short_t>* statusVector = iter->second;
00401 vector<Short_t>* oldStatusVector = preiter->second;
00402 for (UInt_t i = 1; i < statusVector->size(); i++) {
00403 oldstatus = (*oldStatusVector)[i];
00404 status = (*statusVector)[i];
00405
00406
00407 if ( firstone && (statuscounter[i]/mRunStatusMapPtr->size() > 0.1 ) && mRunStatusMapPtr->size() > 3) {
00408
00409
00410 cout << "statcou is " << statuscounter[i] << " for channel " << i << " and size is " << mRunStatusMapPtr->size() << endl;
00411 if(totalStatusVector[i] & fakeZero) ofs << i << "\t" << "0" << endl;
00412 else ofs << i << "\t" << totalStatusVector[i] << endl;
00413
00414
00415 } else if (firstone ||
00416 (oldstatus != status && (statuscounter[i]/mRunStatusMapPtr->size() <= 0.1 || mRunStatusMapPtr->size() <= 10))) {
00417 ofs << i << "\t" << status << endl;
00418 numberofchangedchannels++;
00419 }
00420
00421
00422
00423
00424
00425
00426
00427 emcstatus->Status[i-1]=status;
00428 }
00429 ofs << numberofchangedchannels << " channels changed" << endl;
00430 ofs.close();
00431 datetimestring = getDateTimeString(runnumber);
00432 TString statusrootfilename =
00433 directory + "/status/" + mDetectorFlavor + "Status" + datetimestring + "root";
00434 TFile* fout_status = new TFile(statusrootfilename.Data(),"RECREATE");
00435 fout_status->cd();
00436 bemc_status->AddAt(emcstatus,0);
00437 bemc_status->Write();
00438 fout_status->Close();
00439 delete bemc_status;
00440 delete fout_status;
00441
00442 preiter = iter;
00443 firstone = kFALSE;
00444 }
00445 return 0;
00446 }
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488 Int_t
00489 CSMStatusUtils::makeStatusPlots(TString plotDir) {
00490
00491
00492 gStyle->SetOptStat(0);
00493 gStyle->SetOptTitle(0);
00494 TString tmpstr;
00495 tmpstr = mDetectorFlavor + "StatusPlots";
00496 TCanvas *c1 = new TCanvas(tmpstr.Data(),tmpstr.Data());
00497 c1->SetLogy();
00498 c1->Draw();
00499 TCanvas *c2 = new TCanvas("towerAdcPlots","towerAdcPlots",400,400);
00500 c2->SetLogy();
00501 c2->Draw();
00502
00503
00504 tmpstr = plotDir + mDetectorFlavor + "Status.html";
00505 cout << "htmlSummary: " << tmpstr << endl;
00506 ofstream htmlSummary(tmpstr.Data());
00507 if (!htmlSummary) cout << "htmlSummary isn't defined!" << endl;
00508 writeHtmlHeaderSummary(htmlSummary);
00509
00510 Char_t buffer[2048];
00511
00512 findFillEnds();
00513
00514
00515 TH2F* priorHist = NULL;
00516 TH2F* currentHist = NULL;
00517 TH2F* tmpHist = NULL;
00518 TString runnumberstring;
00519 int runnumber, priorRunNumber, currentRunNumber=99999999, savedCurrentRunNumber;
00520 int priorTimeStamp, currentTimeStamp=99999999;
00521 int priorDateStamp, currentDateStamp=99999999;
00522 Bool_t firstGoodRun = kTRUE;
00523 Float_t averageNumberHitsPerChan;
00524 Int_t goodTowers;
00525
00526 std::vector<Short_t>* statusVector;
00527 std::vector<Float_t>* pedestalmean;
00528 std::vector<Float_t>* pedestalwidth;
00529 std::vector<Float_t>* pedestalchi;
00530 TH1F* hHotTower;
00531 Int_t hottowerPlotNameIter = -1;
00532 ofstream outputlog("MOSTRECENTLOG.txt");
00533
00534 for (map<Int_t,string>::const_iterator iter = mHistFileMap.begin();
00535 iter != mHistFileMap.end(); ++iter) {
00536
00537 TFile* file = new TFile(iter->second.c_str(),"READ");
00538 outputlog << "doing file " << iter->second.c_str() << endl;
00539 cout << "doing file " << iter->second.c_str() << endl;
00540 if (file && file->IsOpen()) {
00541 outputlog << " it opened" << endl;
00542 cout << " it opened" << endl;
00543 runnumber = iter->first;
00544
00545 runnumberstring = "";
00546 runnumberstring += runnumber;
00547 hottowerPlotNameIter++;
00548 tmpstr = mDetectorFlavor + "StatusAdc_" + runnumberstring;
00549 TH2F* runHist = dynamic_cast<TH2F*>(file->Get(tmpstr.Data()));
00550 TTree* myTree = dynamic_cast<TTree*>(file->Get("calinfo"));
00551 assert(runHist);
00552 assert(myTree);
00553
00554
00555
00556 if(firstGoodRun) {
00557 outputlog << "it's the first good run" << endl;
00558 cout << "it's the first good run" << endl;
00559 currentHist = dynamic_cast<TH2F*>(runHist->Clone("ch1"));
00560 currentHist->SetDirectory(0);
00561 priorHist = dynamic_cast<TH2F*>(runHist->Clone("ph1"));
00562 priorHist->SetDirectory(0);
00563 priorHist->Reset();
00564 firstGoodRun = kFALSE;
00565 } else {
00566 currentHist->Add(runHist);
00567 }
00568
00569 setDateTimeInfo(runnumber,myTree);
00570
00571
00572 Float_t runFillNum;
00573 myTree->SetBranchAddress("fillnum",&runFillNum);
00574 myTree->GetEvent(0);
00575
00576
00577 cout<<"runfillnumb is " << runFillNum << endl;
00578
00579
00580
00581
00582 if(runnumber < currentRunNumber) currentRunNumber = runnumber;
00583 runnumberstring = "";
00584 runnumberstring += currentRunNumber;
00585 savedCurrentRunNumber = currentRunNumber;
00586 if(mRunDatestampMap[runnumber] < currentDateStamp) {
00587 currentDateStamp = mRunDatestampMap[runnumber];
00588 currentTimeStamp = mRunTimestampMap[runnumber];
00589 } else if(mRunDatestampMap[runnumber] == currentDateStamp &&
00590 mRunTimestampMap[runnumber] < currentTimeStamp) {
00591 currentTimeStamp = mRunTimestampMap[runnumber];
00592 }
00593
00594
00595
00596 statusVector = new vector<Short_t>(mDetectorSize+1);
00597 pedestalmean = new vector<Float_t>(mDetectorSize+1);
00598 pedestalwidth = new vector<Float_t>(mDetectorSize+1);
00599 pedestalchi = new vector<Float_t>(mDetectorSize+1);
00600
00601 tmpstr = "hotTower";
00602 tmpstr += hottowerPlotNameIter;
00603
00604 hHotTower = new TH1F(tmpstr.Data(),"# of tower hits",mDetectorSize+1,-0.5,mDetectorSize+1-0.5);
00605 hHotTower->GetXaxis()->SetTitle("Tower Id");
00606 hHotTower->GetYaxis()->SetTitle("Number of Hits Above Pedestal");
00607
00608
00609
00610 goodTowers = analyseStatusHistogram(currentHist,plotDir,averageNumberHitsPerChan,
00611 currentDateStamp,currentTimeStamp,
00612 *statusVector,*pedestalmean,*pedestalwidth,*pedestalchi,hHotTower);
00613
00614 if(averageNumberHitsPerChan > 100) {
00615
00616 outputlog << " good statistics!" << endl;
00617 cout << " good statistics!" << endl << endl;
00618
00619 priorHist->Reset();
00620 tmpHist = priorHist;
00621 priorHist = currentHist;
00622 currentHist = tmpHist;
00623 priorTimeStamp = currentTimeStamp;
00624 currentTimeStamp = 99999999;
00625 priorDateStamp = currentDateStamp;
00626 currentDateStamp = 99999999;
00627 priorRunNumber = currentRunNumber;
00628 currentRunNumber = 99999999;
00629
00630 } else if(mFillEndMap[runnumber]) {
00631 outputlog << "end of fill and poor statistics! average: " << averageNumberHitsPerChan << endl;
00632 cout << "end of fill and poor statistics! average: " << averageNumberHitsPerChan << endl << endl;
00633 currentHist->Add(priorHist);
00634 if(priorRunNumber < currentRunNumber) currentRunNumber = priorRunNumber;
00635 runnumberstring = "";
00636 runnumberstring += currentRunNumber;
00637 savedCurrentRunNumber = currentRunNumber;
00638 if(priorDateStamp < currentDateStamp) {
00639 currentDateStamp = priorDateStamp;
00640 currentTimeStamp = priorTimeStamp;
00641 } else if(priorDateStamp == currentDateStamp &&
00642 priorTimeStamp < currentTimeStamp) {
00643 currentTimeStamp = priorTimeStamp;
00644 }
00645 delete statusVector;
00646 delete pedestalmean;
00647 delete pedestalwidth;
00648 delete pedestalchi;
00649 statusVector = new vector<Short_t>(mDetectorSize+1);
00650 pedestalmean = new vector<Float_t>(mDetectorSize+1);
00651 pedestalwidth = new vector<Float_t>(mDetectorSize+1);
00652 pedestalchi = new vector<Float_t>(mDetectorSize+1);
00653 hHotTower->Reset();
00654 hHotTower->GetXaxis()->SetTitle("Tower Id");
00655 hHotTower->GetYaxis()->SetTitle("Number of Hits Above Pedestal");
00656 goodTowers = analyseStatusHistogram(currentHist,plotDir,averageNumberHitsPerChan,
00657 currentDateStamp,currentTimeStamp,
00658 *statusVector,*pedestalmean,*pedestalwidth,*pedestalchi,hHotTower);
00659 if(averageNumberHitsPerChan < 50) {
00660 outputlog << " fill has ended and stats suck! Number is " << averageNumberHitsPerChan << endl;
00661 cout << " fill has ended and stats suck! Number is " << averageNumberHitsPerChan << endl << endl;
00662 priorHist->Reset();
00663 currentHist->Reset();
00664 priorTimeStamp = 99999999;
00665 currentTimeStamp = 99999999;
00666 priorDateStamp = 99999999;
00667 currentDateStamp = 99999999;
00668 priorRunNumber = 99999999;
00669 currentRunNumber = 99999999;
00670 delete statusVector;
00671 delete pedestalmean;
00672 delete pedestalwidth;
00673 delete pedestalchi;
00674 delete hHotTower;
00675 file->Close();
00676 delete file;
00677 continue;
00678 }
00679 } else {
00680 outputlog << " poor statistics! average: " << averageNumberHitsPerChan << endl;
00681 cout << " poor statistics! average: " << averageNumberHitsPerChan << endl;
00682 delete statusVector;
00683 delete pedestalmean;
00684 delete pedestalwidth;
00685 delete pedestalchi;
00686 delete hHotTower;
00687 file->Close();
00688 delete file;
00689 continue;
00690 }
00691
00692 if(mFillEndMap[runnumber]) {
00693 outputlog << " fill has ended!" << endl;
00694 cout << " fill has ended!" << endl << endl;
00695
00696
00697 currentHist->Reset();
00698 priorTimeStamp = 99999999;
00699 currentTimeStamp = 99999999;
00700 priorDateStamp = 99999999;
00701 currentDateStamp = 99999999;
00702 priorRunNumber = 99999999;
00703 currentRunNumber = 99999999;
00704
00705 }
00706
00707 cout << "Got here? 1 " << endl;
00708
00709
00710
00711
00712
00713
00714
00715
00716
00717
00718
00719
00720
00721
00722
00723
00724
00725
00726
00727
00728 (*mRunStatusMapPtr)[savedCurrentRunNumber] = statusVector;
00729
00730 writePedestals(savedCurrentRunNumber,plotDir,*statusVector,*pedestalmean,*pedestalwidth,*pedestalchi);
00731
00732
00733 tmpstr = plotDir + "/status/";
00734 saveStatusTablesToASCII(tmpstr.Data(), savedCurrentRunNumber);
00735
00736 gStyle->SetOptStat(1111);
00737 c1->cd();
00738 hHotTower->Draw();
00739 c1->Update();
00740 tmpstr = plotDir + "/run" + runnumberstring + "_" + mDetectorFlavor + "_hotTowers.gif";
00741 if(gROOT->IsBatch()) {
00742 tmpstr = plotDir + "/run" + runnumberstring + "_" + mDetectorFlavor + "_hotTowers.eps";
00743 }
00744 c1->SaveAs(tmpstr.Data());
00745 delete hHotTower;
00746
00747 htmlSummary << "<tr>" << endl
00748 << "<td>" << "Fill " << runFillNum << "</td>" << ", " << endl
00749 << "<td> " << "Run " << savedCurrentRunNumber << " </td> " << endl
00750 << "<td> " << goodTowers << " good towers" << " </td>" << endl
00751 << "<td> " << getNumberOfChangedTowers(savedCurrentRunNumber) << " towers changed from previous run"
00752 << " </td>" << endl;
00753
00754 tmpstr = "./run" + runnumberstring + "_" + mDetectorFlavor + "_badTowers.html";
00755 htmlSummary << "<td> <a href=\"" << tmpstr.Data() << "\"> list </a></td><br>"
00756 << endl;
00757
00758
00759
00760 tmpstr = plotDir + "/run" + runnumberstring + "_" + mDetectorFlavor + "_badTowers.html";
00761 ofstream htmlout(tmpstr.Data());
00762 writeHtmlHeaderBadTowerList(htmlout,savedCurrentRunNumber);
00763
00764
00765
00766
00767
00768
00769 for (Int_t i=1; i<=mDetectorSize; i++) {
00770 if ((*statusVector)[i] != 1 && (*statusVector)[i] != 18 && (*statusVector)[i] != 0) {
00771
00772 htmlout << "<tr> <td> " << i << " </td> <td> "
00773 << (*statusVector)[i] << " </td> <td> " << endl;
00774
00775 IntToPtrVecShortConstIter statusIter;
00776 statusIter = mRunStatusMapPtr->find(savedCurrentRunNumber);
00777
00778 if (statusIter != mRunStatusMapPtr->begin()) {
00779 IntToPtrVecShortConstIter preIter = statusIter;
00780 preIter--;
00781
00782 if ((*(statusIter->second))[i] == (*(preIter->second))[i] ||
00783 (*(statusIter->second))[i] == 1 ||
00784 (*(statusIter->second))[i] == 0) {
00785 htmlout << "- </td> </tr><br>" << endl;
00786 continue;
00787 }
00788 if(getNumberOfChangedTowers(runnumber) > 25) {
00789
00790 htmlout << "- </td> </tr><br>" << endl;
00791 continue;
00792 }
00793 }
00794
00795
00796
00797
00798
00799
00800 Int_t bin = priorHist->GetXaxis()->FindFixBin(i);
00801 TH1D *hTemp = priorHist->ProjectionY("projTemp",bin,bin);
00802 c2->cd();
00803 c2->Clear();
00804 hTemp->GetXaxis()->SetTitle("adc");
00805 hTemp->GetXaxis()->SetRange(0,150);
00806 hTemp->Draw();
00807 c2->Update();
00808 sprintf(buffer,"%s/run%dtower%d_adc.gif",plotDir.Data(),iter->first,i);
00809 c2->SaveAs(buffer);
00810 sprintf(buffer,"./run%dtower%d_adc.gif",savedCurrentRunNumber,i);
00811
00812 htmlout << "<a href=\"" << buffer << "\" > plot </a>"
00813 << "</td> </tr>" << endl;
00814 delete hTemp;
00815 }
00816 }
00817
00818
00819
00820 IntToPtrVecShortConstIter statusIter;
00821 statusIter = mRunStatusMapPtr->find(savedCurrentRunNumber);
00822 if (statusIter == mRunStatusMapPtr->begin()) {
00823
00824 htmlout << "</tbody>" << endl;
00825 htmlout << "</table>" << endl;
00826 htmlout << "<br><br> <div>Partial Good Tower List for Comparison</div><br>" << endl;
00827 htmlout << "<table border=\"1\">" << endl;
00828 htmlout << "<tbody>" << endl;
00829 htmlout << "<tr> <th width=\"50\"> Tower ID </th> <th width=\"50\"> Status Code </th> <th width=\"100\"> ADC plot </th> </tr>" << endl;
00830
00831 Int_t good_toplot = 1;
00832 for (Int_t i=100; i<mDetectorSize && good_toplot<10; i = i+100) {
00833 if ((*statusVector)[i] == 1) {
00834 htmlout << "<tr> <td> " << i << " </td> <td> "
00835 << (*statusVector)[i] << " </td> <td> " << endl;
00836
00837
00838
00839 Int_t bin = priorHist->GetXaxis()->FindFixBin(i);
00840 TH1D *hTemp = priorHist->ProjectionY("projTemp",bin,bin);
00841
00842 c2->cd();
00843 c2->Clear();
00844 hTemp->GetXaxis()->SetTitle("adc");
00845 hTemp->Draw();
00846 c2->Update();
00847
00848 sprintf(buffer,"%s/run%dtower%d_adc.gif",plotDir.Data(),iter->first,i);
00849 c2->SaveAs(buffer);
00850 sprintf(buffer,"./run%dtower%d_adc.gif",savedCurrentRunNumber,i);
00851 htmlout << "<a href=\"" << buffer << "\" > plot </a>"
00852 << "</td> </tr>" << endl;
00853 delete hTemp;
00854 }
00855 good_toplot++;
00856
00857 }
00858 }
00859 writeHtmlFooterSummary(htmlout);
00860 htmlSummary << "</tr>" << endl;
00861 htmlout.close();
00862
00863
00864
00865 }
00866 file->Close();
00867 delete file;
00868 }
00869 htmlSummary.close();
00870 outputlog.close();
00871 writeHtmlFooterSummary(htmlSummary);
00872 TH2F* statusHist = makeStatusVersusTimePlot();
00873 if (statusHist) {
00874 c1->cd();
00875 c1->SetLogy(kFALSE);
00876 c1->Clear();
00877
00878 statusHist->Draw("colz");
00879 sprintf(buffer,"%s/bemcStatusPlot.gif",plotDir.Data());
00880 c1->SaveAs(buffer);
00881
00882
00883 delete statusHist;
00884 }
00885 delete c1;
00886 delete c2;
00887 return 0;
00888 }
00889
00890
00891
00892
00893
00894
00895 Int_t
00896 CSMStatusUtils::analyseStatusHistogram(TH2F* hist,
00897 TString directory,
00898 Float_t& averageNumberOfHitsPerChannel,
00899 Int_t dateStamp,
00900 Int_t timeStamp,
00901 std::vector<Short_t>& statusVector,
00902 std::vector<Float_t>& pedestalmean,
00903 std::vector<Float_t>& pedestalwidth,
00904 std::vector<Float_t>& pedestalchi,
00905 TH1F* hHotTower,
00906 TH1F* hPedMean,
00907 TH1F* hPedWidth) {
00908
00909 TString runnumber = hist->GetName();
00910 runnumber = runnumber(runnumber.Length()-7,7);
00911
00912 void* dir;
00913
00914 if ((dir = gSystem->OpenDirectory(directory)) == NULL)
00915 gSystem->MakeDirectory(directory);
00916
00917 TF1* gaus = new TF1("gaus","gaus");
00918
00919
00920 for (vector<Short_t>::iterator iter = statusVector.begin(); iter != statusVector.end(); ++iter)
00921 *iter = 0;
00922
00923
00924 for (Int_t chanId = 1; chanId < mDetectorSize+1; chanId++) {
00925
00926
00927 TH1D* proj = hist->ProjectionY("projTemp",chanId+1,chanId+1);
00928
00929 if (proj) {
00930
00931
00932 Int_t maxBin = 0;
00933 Float_t maxValue = -1;
00934
00935 for (Int_t j = 2; j < proj->GetXaxis()->GetNbins(); j++) {
00936 if (proj->GetBinContent(j) > maxValue) {
00937 maxBin = j;
00938 maxValue = proj->GetBinContent(j);
00939 }
00940 }
00941 Float_t pedMean = proj->GetXaxis()->GetBinCenter(maxBin);
00942
00943
00944
00945
00946
00947
00948
00949
00950
00951
00952
00953
00954
00955
00956
00957 gaus->SetParameter(0,maxValue);
00958 gaus->SetParameter(1,pedMean);
00959 gaus->SetParameter(2,3.5);
00960
00961
00962
00963
00964
00965 gaus->SetRange(pedMean-10,pedMean+10);
00966 proj->Fit(gaus,"0RQ");
00967
00968 if(hPedMean) hPedMean->Fill(gaus->GetParameter(1));
00969 if(hPedWidth) hPedWidth->Fill(gaus->GetParameter(2));
00970
00971 pedestalmean[chanId] = gaus->GetParameter(1);
00972 pedestalwidth[chanId] = gaus->GetParameter(2);
00973 pedestalchi[chanId] = gaus->GetChisquare();
00974
00975
00976
00977
00978 if (pedestalwidth[chanId] <= 0.5 || pedestalwidth[chanId] > 2.8) {
00979
00980 statusVector[chanId] |= 4+32;
00981 }
00982
00983
00984
00985 if (mDetectorFlavor=="bemc" && (pedestalmean[chanId] < 4 || pedestalmean[chanId] > 145)) {
00986 if (pedestalmean[chanId] > 2.6 && pedestalwidth[chanId] < 1.5) {
00987
00988 } else {
00989 statusVector[chanId] |= 4;
00990
00991 }
00992 }
00993
00994
00995
00996
00997
00998
00999 Int_t minBin = proj->GetXaxis()->FindFixBin(pedestalmean[chanId] + 10*pedestalwidth[chanId]);
01000 maxBin = proj->GetXaxis()->GetNbins() - 1;
01001 Int_t hottowerthreshold = minBin;
01002 if(hHotTower) {
01003
01004 Float_t nHitsAbovePedestal = proj->Integral(hottowerthreshold,maxBin);
01005
01006 if(nHitsAbovePedestal==0) {
01007 nHitsAbovePedestal=1;
01008
01009
01010
01011 Float_t deadorno = proj->Integral(2,maxBin);
01012 if (deadorno) {
01013 nHitsAbovePedestal=2;
01014 }
01015 else {
01016 statusVector[chanId] |= mZerobit;
01017
01018 }
01019
01020
01021 }
01022 hHotTower->AddAt(nHitsAbovePedestal,chanId);
01023 }
01024
01025
01026
01027
01028
01029
01030
01031
01032
01033
01034
01035
01036
01037
01038
01039
01040
01041 int numberofnonzerohits = 0;
01042 Short_t bitoff = 0;
01043 Short_t bitcompare = (1+2+4+8);
01044 Short_t biton = bitcompare;
01045 Short_t sixteenbiton = 16;
01046 for(Short_t bin=1; bin<maxBin; bin++) {
01047 if(proj->GetBinContent(bin) > 0) {
01048 bitoff |= (bin-1);
01049 biton &= (bin-1);
01050 sixteenbiton &= (bin-1);
01051 numberofnonzerohits++;
01052 }
01053 }
01054 Bool_t typea=kFALSE,typeb=kFALSE,typec=kFALSE;
01055 if((bitoff & 16) != 16 || (sixteenbiton & 16) != 0) {
01056 for(Short_t bin=1; bin<maxBin; bin++) {
01057 if(proj->GetBinContent(bin) > 0) {
01058 if(!typea) {
01059 typea=kTRUE;
01060 bin = bin/16*16+15;
01061 } else if(!typeb) {
01062 typeb=kTRUE;
01063 bin = bin/16*16+15;
01064 } else if(!typec) {
01065 typec=kTRUE;
01066 break;
01067 }
01068 }
01069 }
01070 }
01071
01072 if((bitoff & bitcompare) != bitcompare && numberofnonzerohits > 10) {
01073 cout << "136: " << chanId << " bitoff: " << bitoff << endl;
01074 statusVector[chanId] = statusVector[chanId] | (8+128);
01075 }
01076 if(biton != 0 && numberofnonzerohits > 10) {
01077 cout << "72: " << chanId << " biton: " << biton << endl;
01078 statusVector[chanId] = statusVector[chanId] | (8+64);
01079 }
01080
01081 if((bitoff & 16) != 16 && typec && numberofnonzerohits > 10) {
01082 cout << "136: " << chanId << " 16" << endl;
01083 statusVector[chanId] = statusVector[chanId] | (8+128);
01084 }
01085 if((sixteenbiton & 16) != 0 && typec && numberofnonzerohits > 10) {
01086 cout << "72: " << chanId << " 16" << endl;
01087 statusVector[chanId] = statusVector[chanId] | (8+64);
01088 }
01089
01090 for(Short_t bin=1; bin<maxBin; bin++) {
01091 if(proj->GetBinContent(bin) > 0) {
01092 bitoff |= (bin-1);
01093 biton &= (bin-1);
01094 numberofnonzerohits++;
01095 }
01096 }
01097
01098
01099 Float_t entries = proj->Integral(1,proj->GetXaxis()->GetNbins());
01100 if (entries == 0) {
01101 statusVector[chanId] |= mZerobit;
01102 if (chanId==50 || chanId==139) cout << "entries=0 " << chanId << " Status: " << statusVector[chanId] << endl;
01103 }
01104
01105
01106
01107
01108
01109
01110
01111
01112
01113
01114
01115
01116
01117
01118
01119
01120
01121
01122
01123
01124
01125
01126 delete proj;
01127 } else {
01128
01129 statusVector[chanId] |= mZerobit;
01130 }
01131
01132 }
01133
01134 unsigned int date = dateStamp;
01135 unsigned int time = timeStamp;
01136 StEmcDecoder barry(date,time);
01137 Int_t towerId,nextTowerId;
01138 Bool_t histogramsAreSame;
01139
01140
01141
01142
01143
01144
01145 if(mDetectorFlavor == "bemc") {
01146
01147
01148
01149 for(int crate=1; crate<31; crate++) {
01150 for(int channel=0; channel<160-1; channel++) {
01151 histogramsAreSame = kTRUE;
01152 barry.GetTowerIdFromCrate(crate, channel, towerId);
01153 barry.GetTowerIdFromCrate(crate, channel+1, nextTowerId);
01154
01155 TH1D* projnow = hist->ProjectionY("projTemp2",towerId+1,towerId+1);
01156 TH1D* projnext = hist->ProjectionY("projTemp3",nextTowerId+1,nextTowerId+1);
01157
01158 for (Int_t i=1; i<projnow->GetXaxis()->GetNbins() && histogramsAreSame; i++) {
01159 if( projnow->GetBinContent(i) != projnext->GetBinContent(i))
01160 histogramsAreSame = kFALSE;
01161 }
01162 if(histogramsAreSame) {
01163 statusVector[towerId] |= 256;
01164 statusVector[nextTowerId] |= 256;
01165 }
01166 }
01167 }
01168 } else {
01169
01170
01171
01172 for(int crate=0; crate<6; crate++) {
01173 for(int channel=0; channel<120-1; channel++) {
01174 histogramsAreSame = kTRUE;
01175 towerId = eemcCrateMap[crate][channel];
01176 nextTowerId = eemcCrateMap[crate][channel+1];
01177
01178 TH1D* projnow = hist->ProjectionY("projTemp2",towerId+1,towerId+1);
01179 TH1D* projnext = hist->ProjectionY("projTemp3",nextTowerId+1,nextTowerId+1);
01180
01181 for (Int_t i=1; i<projnow->GetXaxis()->GetNbins() && histogramsAreSame; i++) {
01182 if( projnow->GetBinContent(i) != projnext->GetBinContent(i))
01183 histogramsAreSame = kFALSE;
01184 }
01185 if(histogramsAreSame) {
01186 statusVector[towerId] |= 256;
01187 statusVector[nextTowerId] |= 256;
01188 }
01189 }
01190 }
01191 }
01192
01193
01194
01195 Float_t sumofhits=0, nbinhits=0, ncratehottowers=0;
01196 Int_t goodTowers = 0;
01197 for(int i=1; i<mDetectorSize+1; i++) {
01198 if(hHotTower->GetBinContent(i) > 2) {
01199 sumofhits += hHotTower->GetBinContent(i);
01200 nbinhits++;
01201 }
01202 }
01203 if(nbinhits!=0) {
01204
01205
01206 averageNumberOfHitsPerChannel = sumofhits/nbinhits;
01207 for(int i=1; i<mDetectorSize+1; i++) {
01208 if ( i==509 || i==533 || i==1306 || i==1397 || i==1503 || i==1892 || i==1893 || i==2074 || i==2075 ) cout << i << " Avg numberHits/chan= " << averageNumberOfHitsPerChannel << " for this tower: " << hHotTower->GetBinContent(i) << endl;
01209
01210
01211
01212 if( (hHotTower->GetBinContent(i) > 8*averageNumberOfHitsPerChannel)
01213 || (i==1503 && (hHotTower->GetBinContent(i) > 5*averageNumberOfHitsPerChannel))
01214 || (i==1612 && (hHotTower->GetBinContent(i) > 5*averageNumberOfHitsPerChannel)) ) {
01215 statusVector[i] |= 2;
01216 cout << "ID: " << i << " average: " << averageNumberOfHitsPerChannel << " this tower: " << hHotTower->GetBinContent(i) << endl;
01217 }
01218 if(hHotTower->GetBinContent(i) < averageNumberOfHitsPerChannel/40) statusVector[i] |= 2+16;
01219 }
01220
01221
01222
01223
01224
01225
01226
01227
01228
01229
01230
01231
01232
01233
01234
01235 if(mDetectorFlavor == "bemc") {
01236 for(int crate=1; crate<31; crate++) {
01237 sumofhits = 0;
01238 nbinhits = 0;
01239 ncratehottowers=0;
01240 for(int channel=0; channel<160; channel++) {
01241 barry.GetTowerIdFromCrate(crate, channel, towerId);
01242 if(hHotTower->GetBinContent(towerId) > 10*averageNumberOfHitsPerChannel) {
01243 ncratehottowers++;
01244 } else if(hHotTower->GetBinContent(towerId) > 2) {
01245 sumofhits += hHotTower->GetBinContent(towerId);
01246 nbinhits++;
01247 }
01248 }
01249 if(nbinhits == 0 || (nbinhits != 0 && sumofhits/nbinhits < averageNumberOfHitsPerChannel/5) || ncratehottowers >= 40) {
01250 for(int channel=0; channel<160; channel++) {
01251 barry.GetTowerIdFromCrate(crate, channel, towerId);
01252 statusVector[towerId] |= 2+16;
01253 }
01254 }
01255 }
01256 } else {
01257 for(int crate=0; crate<6; crate++) {
01258 sumofhits = 0;
01259 nbinhits = 0;
01260 ncratehottowers=0;
01261 for(int channel=0; channel<120; channel++) {
01262 towerId = eemcCrateMap[crate][channel];
01263 if(hHotTower->GetBinContent(towerId) > 10*averageNumberOfHitsPerChannel) {
01264 ncratehottowers++;
01265 } else if(hHotTower->GetBinContent(towerId) > 2) {
01266 sumofhits += hHotTower->GetBinContent(towerId);
01267 nbinhits++;
01268 }
01269 }
01270 if(nbinhits == 0 || (nbinhits != 0 && sumofhits/nbinhits < averageNumberOfHitsPerChannel/5) || ncratehottowers >= 30) {
01271 for(int channel=0; channel<120; channel++) {
01272 towerId = eemcCrateMap[crate][channel];
01273 statusVector[towerId] |= 2+16;
01274 }
01275 }
01276 }
01277 }
01278
01279 for(int i=1; i<mDetectorSize+1; i++) {
01280 if(statusVector[i] == 0) {
01281 statusVector[i]=1;
01282 if (i==50 || i==139) cout << "status=1 " << i << " Status: " << statusVector[i] << endl;
01283 goodTowers++;
01284 } else if(statusVector[i] & mZerobit) {
01285 statusVector[i]=0;
01286 if (i==50 || i==139) cout << "statusVec & mZerobit " << i << " Status: " << statusVector[i] << endl;
01287 }
01288 }
01289 } else {
01290 for(int i=1; i<mDetectorSize+1; i++) {
01291 statusVector[i]=0;
01292 if (i==50 || i==139) cout << "nbinhits=0 " << i << " Status: " << statusVector[i] << endl;
01293 }
01294 }
01295 delete gaus;
01296
01297 return goodTowers;
01298 }
01299
01300 void
01301 CSMStatusUtils::setDateTimeInfo(int runnumber,TTree* ttree) {
01302
01303 Int_t thedate, thetime;
01304 TString thedatestring = "", thetimestring = "", tmpstr="";
01305 if(ttree) {
01306 ttree->SetBranchAddress("thedate",&thedate);
01307 ttree->SetBranchAddress("thetime",&thetime);
01308 ttree->GetEvent(0);
01309 mRunTimestampMap[runnumber] = thetime;
01310 mRunDatestampMap[runnumber] = thedate;
01311 } else {
01312 assert(ttree);
01313 }
01314 }
01315
01316 TString
01317 CSMStatusUtils::getDateTimeString(int runnumber,TTree* ttree) {
01318
01319 if(ttree) setDateTimeInfo(runnumber,ttree);
01320 Int_t thedate, thetime;
01321 TString thedatestring = "", thetimestring = "", tmpstr="";
01322 if(mRunTimestampMap.count(runnumber)>0) {
01323
01324
01325
01326
01327 thedate = mRunDatestampMap[runnumber];
01328 thetime = mRunTimestampMap[runnumber];
01329 } else {
01330 thedate = 0;
01331 thetime = 0;
01332 }
01333 thedatestring += thedate;
01334 thetimestring += thetime;
01335
01336 for(int i=0; i<5-TMath::Floor(TMath::Log10(thetime)); i++) tmpstr += "0";
01337
01338
01339 TString datetimestring = "." + thedatestring + "." + tmpstr + thetimestring + ".";
01340 cout << datetimestring << endl;
01341 return datetimestring;
01342 }
01343
01344
01345
01346 Int_t
01347 CSMStatusUtils::saveStatusTablesToASCII(TString directory,int runnumber) {
01348
01349 void* dir;
01350 if ((dir = gSystem->OpenDirectory(directory)) == NULL)
01351 gSystem->MakeDirectory(directory);
01352
01353 IntToPtrVecShortConstIter first = mRunStatusMapPtr->begin();
01354 IntToPtrVecShortConstIter last = mRunStatusMapPtr->end();
01355 if(runnumber != 0) {
01356 first = mRunStatusMapPtr->find(runnumber);
01357 last = first;
01358 last++;
01359 }
01360 TString tmpstr, runnumberstring, datetimestring;
01361 for (IntToPtrVecShortConstIter iter = first; iter != last; ++iter) {
01362 int runnumber = iter->first;
01363 runnumberstring = "";
01364 runnumberstring += runnumber;
01365 datetimestring = getDateTimeString(runnumber);
01366 tmpstr = directory + "/run" + runnumberstring + "_" + mDetectorFlavor
01367 + datetimestring + "badTowers.txt";
01368 ofstream txtout(tmpstr.Data());
01369 for (Int_t i = 1; i <= mDetectorSize; i++) {
01370 txtout << i << "\t" << (*(iter->second))[i] << endl;
01371 }
01372 txtout.close();
01373 }
01374 return 0;
01375 }
01376
01377
01378
01379
01380 Int_t
01381 CSMStatusUtils::getNumberOfChangedTowers(Int_t runnumber) {
01382
01383 IntToPtrVecShortConstIter iter = mRunStatusMapPtr->find(runnumber);
01384
01385 if (iter == mRunStatusMapPtr->begin())
01386 return -1;
01387
01388 if (iter == mRunStatusMapPtr->end())
01389 return -1;
01390
01391
01392 IntToPtrVecShortConstIter preIter = iter;
01393 preIter--;
01394 Int_t changedTowers = 0;
01395 vector<Short_t>* statusVector = iter->second;
01396 vector<Short_t>* oldStatusVector = preIter->second;
01397 for (UInt_t i = 1; i < statusVector->size(); i++)
01398 if ((((*statusVector)[i] != 1) && ((*oldStatusVector)[i] == 1)) ||
01399 (((*statusVector)[i] == 1) && ((*oldStatusVector)[i] != 1)))
01400 changedTowers++;
01401
01402 return changedTowers;
01403 }
01404
01405
01406
01407 void
01408 CSMStatusUtils::writePedestals(Int_t runNumber, TString directory,
01409 std::vector<Short_t>& statusVector,
01410 std::vector<Float_t>& pedestalmean,
01411 std::vector<Float_t>& pedestalwidth,
01412 std::vector<Float_t>& pedestalchi) {
01413
01414
01415 TString pedtxtfilename = directory + "/pedestals/";
01416
01417
01418 void* dir = NULL;
01419 if ((dir = gSystem->OpenDirectory(pedtxtfilename.Data())) == NULL)
01420 gSystem->MakeDirectory(pedtxtfilename.Data());
01421
01422 TString runnumber = "";
01423 runnumber += runNumber;
01424 pedtxtfilename = directory + "/pedestals/" + mDetectorFlavor
01425 + "pedestals_for_run_" + runnumber + ".ped";
01426 ofstream pedestalfile(pedtxtfilename.Data());
01427 pedestalfile.setf(ios::left);
01428 pedestalfile << setw(8) << "ID" <<
01429 setw(8) << "PED" <<
01430 setw(8) << "RMS" <<
01431 setw(8) << "STATUS" << endl;
01432
01433 St_emcPed *bemc_ped=new St_emcPed("bemcPed",1);
01434 emcPed_st t_ped;
01435 cout << t_ped.Status[367] << endl;
01436 TString datetimestring = getDateTimeString(runNumber);
01437 TString pedrootfilename = directory + "/pedestals/" + mDetectorFlavor
01438 + "Ped" + datetimestring + "root";
01439 TFile* fout_status = new TFile(pedrootfilename.Data(),"RECREATE");
01440
01441 Short_t shortpedmean,shortpedwidth;
01442 for (UInt_t i = 1; i < statusVector.size(); i++) {
01443 shortpedmean = TMath::Nint(100*pedestalmean[i]);
01444 shortpedwidth = TMath::Nint(100*pedestalwidth[i]);
01445 t_ped.Status[i-1] = statusVector[i];
01446 t_ped.AdcPedestal[i-1] = shortpedmean;
01447 t_ped.AdcPedestalRMS[i-1] = shortpedwidth;
01448 t_ped.ChiSquare[i-1]=pedestalchi[i];
01449 pedestalfile << setw(8) << i <<
01450 setw(8) << setprecision(4) << shortpedmean <<
01451 setw(8) << setprecision(3) << shortpedwidth <<
01452 setw(8) << setprecision(3) << statusVector[i] << endl;
01453 }
01454 pedestalfile.close();
01455
01456 TString tmpstr = "rm -f " + pedtxtfilename + ".gz";
01457 gSystem->Exec(tmpstr.Data());
01458 tmpstr = "gzip " + pedtxtfilename;
01459 gSystem->Exec(tmpstr.Data());
01460
01461 fout_status->cd();
01462 bemc_ped->AddAt(&t_ped,0);
01463 bemc_ped->Write();
01464 fout_status->Close();
01465 delete bemc_ped;
01466 delete fout_status;
01467 }
01468
01469
01470
01471
01472 void
01473 CSMStatusUtils::findFillEnds() {
01474
01475 Float_t runFillNumber, priorRunFillNumber=-1;
01476 int runnumber, priorRunNumber=0;
01477 for (map<Int_t,string>::const_iterator iter = mHistFileMap.begin();
01478 iter != mHistFileMap.end(); ++iter) {
01479 TFile* file = new TFile(iter->second.c_str(),"READ");
01480 if (file && file->IsOpen()) {
01481 runnumber = iter->first;
01482 assert(runnumber);
01483 TTree* runTree = dynamic_cast<TTree*>(file->Get("calinfo"));
01484 assert(runTree);
01485 runTree->SetBranchAddress("fillnum",&runFillNumber);
01486 runTree->GetEvent(0);
01487
01488
01489
01490
01491
01492 if(priorRunNumber != 0) {
01493 if(runFillNumber != priorRunFillNumber)
01494 mFillEndMap[priorRunNumber] = kTRUE;
01495 else
01496 mFillEndMap[priorRunNumber] = kFALSE;
01497 }
01498 ++iter;
01499 if(iter == mHistFileMap.end())
01500 mFillEndMap[runnumber] = kTRUE;
01501 --iter;
01502
01503 priorRunNumber = runnumber;
01504 priorRunFillNumber = runFillNumber;
01505 }
01506 file->Close();
01507 delete file;
01508 }
01509 }
01510
01511
01512
01513
01514
01515
01516 TH2F*
01517 CSMStatusUtils::makeStatusVersusTimePlot() {
01518 gStyle->SetPalette(1,0);
01519 Int_t runs = mRunStatusMapPtr->size();
01520 TH2F* hist;
01521 if(mDetectorFlavor=="bemc")
01522 hist = new TH2F("bemcStatus_run","bemcStatus vs run",
01523 4801,-0.5,4800.5,runs+1,-0.5,runs+0.5);
01524 else
01525 hist = new TH2F("eemcStatus_run","eemcStatus vs run",
01526 721,-0.5,720.5,runs+1,-0.5,runs+0.5);
01527
01528 hist->GetXaxis()->SetTitle("tower id");
01529 hist->GetYaxis()->SetTitle("relative run number");
01530 Int_t runNumber = 0;
01531 for (IntToPtrVecShortConstIter iter = mRunStatusMapPtr->begin();
01532 iter != mRunStatusMapPtr->end(); ++iter) {
01533 for (Int_t i=1; i<=mDetectorSize; i++) {
01534 if ((*(iter->second))[i] != 0) {
01535 hist->Fill(i,runNumber,(*(iter->second))[i]);
01536 }
01537 }
01538 runNumber++;
01539 }
01540 return hist;
01541 }
01542
01543 void CSMStatusUtils::writeHtmlHeaderBadTowerList(ofstream& out,Int_t runnumber) {
01544 out << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << endl;
01545 out << "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 STRICT//EN\"" << endl;
01546 out << " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">" << endl;
01547 out << "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\" >" << endl;
01548 out << "<head>" << endl;
01549 out << "<meta content=\"text/html; charset=UTF-8\" />" << endl;
01550 out << "<title> Bad BEMC Tower List Run " << runnumber << " </title>" << endl;
01551 out << "<link rel=\"StyleSheet\" href=\"../../myStyle.css\" type=\"text/css\" />" << endl;
01552 out << "</head>" << endl;
01553 out << "<body xml:lang=\"en\" lang=\"en\" >" << endl;
01554 out << "<h1> Bad BEMC Tower List Run " << runnumber << " </h1>" << endl;
01555 out << "<div class=\"header\">Status Codes</div>" << endl;
01556 out << "(codes are backward compatible with prior status tables)" << endl;
01557 out << "<ul>" << endl;
01558 out << "<li> 0 == channel does not exist </li>" << endl;
01559 out << "<li> 1 == channel is good </li>" << endl;
01560 out << "<li> 2 == channel is either hot or cold (see bit 16) </li>" << endl;
01561 out << "<li> 4 == channel has a weird pedestal (see bit 32)</li>" << endl;
01562 out << "<li> 8 == channel has a stuck bit (see bits 64 and 128) </li>" << endl;
01563 out << "<li> 16 == if off, hot tower (10x as many hits as others); if on, " <<
01564 "cold tower (40x fewer hits than others) </li>" << endl;
01565 out << "<li> 32 == if off, pedestal mean is out of bounds; if on, " <<
01566 "pedestal width is too large/small</li>" << endl;
01567 out << "<li> 64 == bit stuck on</li>" << endl;
01568 out << "<li> 128 == bit stuck off</li>" << endl;
01569 out << "</ul>" << endl;
01570 out << "<div class=\"header\">Bad Tower List</div>" << endl;
01571 out << "<p> Tower ADC plots are only available if the tower status has changed"
01572 << " compared to the previous run</p>" << endl;
01573 out << "<table border=\"1\">" << endl;
01574 out << "<tbody>" << endl;
01575 out << "<tr> <th width=\"50\"> Tower ID </th> <th width=\"50\"> Status Code </th> <th width=\"100\"> ADC plot </th> </tr>" << endl;
01576 }
01577
01578 void CSMStatusUtils::writeHtmlFooterBadTowerList(ofstream& out) {
01579 out << "</tbody>" << endl;
01580 out << "</table>" << endl;
01581 out << "<address> Thorsten Kollegger - last updated";
01582 out << " 7/30/2004";
01583 out << "</address>" << endl;
01584 out << "</body>" << endl;
01585 out << "</html>" << endl;
01586 }
01587
01588 void CSMStatusUtils::writeHtmlHeaderSummary(ofstream& out) {
01589 out << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << endl;
01590 out << "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 STRICT//EN\"" << endl;
01591 out << " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">" << endl;
01592 out << "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\" >" << endl;
01593 out << "<head>" << endl;
01594 out << "<meta content=\"text/html; charset=UTF-8\" />" << endl;
01595 out << "<title> BEMC Tower Status Analysis </title>" << endl;
01596 out << "<link rel=\"StyleSheet\" href=\"../../myStyle.css\" type=\"text/css\" />" << endl;
01597 out << "</head>" << endl;
01598 out << "<body xml:lang=\"en\" lang=\"en\" >" << endl;
01599 ifstream in("StRoot/StElectronInvMassAna/CSMStatusUtilsSummary.html");
01600 Char_t buffer[2048];
01601 while (in.is_open()) {
01602 in.getline(buffer,2048);
01603 if (in.eof()) {
01604 break;
01605 }
01606 out << buffer << endl;
01607 }
01608 }
01609
01610 void CSMStatusUtils::writeHtmlFooterSummary(ofstream& out) {
01611 out << "</tbody>" << endl;
01612 out << "</table>" << endl;
01613 out << "<address> David Staszak (taken from David Relyea, Thorsten Kollegger) - last updated";
01614 out << " 8/20/2006";
01615 out << "</address>" << endl;
01616 out << "</body>" << endl;
01617 out << "</html>" << endl;
01618 }
01619
01620 ClassImp(CSMStatusUtils)