00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include <TH2.h>
00011 #include <TCanvas.h>
00012 #include <TStyle.h>
00013 #include <stdio.h>
00014
00015 #include "StBemcBeamBckgFinderMaker.h"
00016 #include "StChain.h"
00017 #include "St_DataSetIter.h"
00018 #include "StDAQMaker/StDAQReader.h"
00019
00020 #include <StMessMgr.h>
00021 #include <StEmcUtil/geometry/StEmcGeom.h>
00022 #include <StEmcUtil/database/StBemcTables.h>
00023
00024 #include "StEmcUtil/database/StEmcDecoder.h"
00025 #include "StEmcRawMaker/defines.h"
00026
00027
00028 #include "StMuDSTMaker/COMMON/StMuDstMaker.h"
00029 #include "StMuDSTMaker/COMMON/StMuDst.h"
00030 #include "StMuDSTMaker/COMMON/StMuTriggerIdCollection.h"
00031 #include "StMuDSTMaker/COMMON/StMuEvent.h"
00032
00033
00034 ClassImp(StBemcBeamBckgFinderMaker)
00035
00036 StBemcBeamBckgFinderMaker::StBemcBeamBckgFinderMaker(const char *name):StMaker(name){
00037
00038 mGeomB = 0;
00039 mHList = 0;
00040 mMappB = 0;
00041 memset(mhisto, 0,sizeof(mhisto));
00042 memset(mevtH, 0,sizeof(mevtH));
00043 mAccEve=mInpEve=0;
00044 mTrigId=0;
00045 mAdcThreshold=0;
00046 mAdcSumThreshold=0;
00047 mpattern=0;
00048
00049 }
00050
00051
00052
00053 StBemcBeamBckgFinderMaker::~StBemcBeamBckgFinderMaker(){
00054
00055 }
00056
00057
00058
00059
00060 Int_t StBemcBeamBckgFinderMaker::Init(){
00061
00062 mGeomB = StEmcGeom::instance("bemc");
00063
00064 assert(mHList);
00065 mhisto[0]= new TH1F("Frequency1","Towers Frequency (status =1); Tower SoftId; Frequency",mxSoftId,0.5,mxSoftId+0.5);
00066 mhisto[1]= new TH1F("Frequency2","Towers Frequency (status !=1); Tower SoftId; Frequency",mxSoftId,0.5,mxSoftId+0.5);
00067 mhisto[2]= new TH1F("Frequency3","bin1= All, bin3= Accept, bin5= !Backgnd, bin7=Backgnd bin9=East bin11=Center bin13=West; Bin No",15,0.5,15.5);
00068 mhisto[3]= new TH1F("StartingphiVspattern","Pattern Starting #phi Weighted By Pattern Length; #phi[deg]",360,0.5,360.5);
00069 mhisto[4]= new TH1F("StartingphiVsadcsum","Pattern Starting #phi Weighted By Pattern Summed Adc; #phi[deg]",360,0.5,360.5);
00070
00071 mhisto[5]= new TH1F("Allbunchcrossing7","All Bunch Crossings; Bunch Crossing No (7bit)",128,-0.50,127.5);
00072 mhisto[6]= new TH1F("Trigbunchcrossing7","Trigger Passing Bunch Crossings; Bunch Crossing No (7bit)",128,-0.50,127.5);
00073 mhisto[7]= new TH1F("Bckgbunchcrossing7","Background Passing Bunch Crossings; Bunch Crossing No (7bit)",128,-0.50,127.5);
00074
00075 mevtH[0]= new TH2F("BtowphiVseta","Barrel Towers: ADC-PED; #eta Bin; #phi Bin",mxEta,-0.5,mxEta-0.5,mxPhi,-0.5,mxPhi-0.5);
00076 mevtH[1]= new TH2F("StartingphiVseta","Pattern Starting #phi Vs. Pattern Starting #eta; #eta; #phi(deg)",10,-1,1,30,0.5,360.5);
00077 mevtH[2]= new TH2F("AvgWeightedPhiVsEta","Pattern #phi Vs. Pattern Weighted Average #eta; <#eta>; #phi(deg)",20,-1,1,60,0.5,360.5);
00078
00079 for(int i=0; i<mMaxH; i++){
00080 if(mhisto[i])
00081 mHList->Add(mhisto[i]);
00082 }
00083
00084 for(int i=0; i<mMaxevtH; i++){
00085 if(mevtH[i])
00086 mHList->Add(mevtH[i]);
00087 }
00088
00089 LOG_INFO<< Form("%s::Init() accept TrigID=%d\n",GetName(),mTrigId)<<endm;
00090
00091 return StMaker::Init();
00092 }
00093
00094
00095
00096
00097 void StBemcBeamBckgFinderMaker::Clear(const Option_t* option){
00098
00099 mevtH[0]->Reset();
00100 memset(mAdcArray, 0,sizeof(mAdcArray));
00101 memset(mPattSoftId, 0,sizeof(mPattSoftId));
00102
00103 mDecision=0;
00104 metaBegin=0;
00105 metaEnd=0;
00106 mphiBegin=0;
00107 mpatternLength=0;
00108 msumAdc=0;
00109 mAvgEtaAdc=0;
00110 mSearchDone=0;
00111
00112 StMaker::Clear(option);
00113 }
00114
00115
00116
00117
00118
00119
00120 Int_t StBemcBeamBckgFinderMaker::Make(){
00121
00122
00123 mInpEve++;
00124 printf("\n");
00125
00126 StMuDstMaker *muMk = (StMuDstMaker*)GetMaker("MuDst");
00127 assert(muMk);
00128
00129 StMuEmcCollection *emc = muMk->muDst()->muEmcCollection();
00130
00131
00132 StMuDst *dst = muMk->muDst();
00133 StMuEvent *muEve = dst->event();
00134 StL0Trigger &trig = muEve->l0Trigger();
00135 StEventInfo &info = muEve->eventInfo();
00136
00137 int bx7=trig.bunchCrossingId7bit(info.runId());
00138 mhisto[5]->Fill(bx7);
00139
00140
00141
00142
00143
00144
00145 assert(muEve);
00146 StMuTriggerIdCollection ticB = muEve -> triggerIdCollection();
00147 const StTriggerId *nominal = &ticB.nominal();
00148
00149 mhisto[2]->Fill(1);
00150
00151
00152 if(mTrigId<0) {
00153 vector<unsigned int> nominalL=nominal->triggerIds();
00154 printf("trigL len=%d totEve=%d\n",nominalL.size(),mInpEve);
00155 uint ii;
00156 for(ii=0;ii<nominalL.size();ii++)printf("trgID=%d, ",nominalL[ii]);
00157 printf("\n");
00158 }
00159
00160 if(mTrigId>0 && !nominal->isTrigger(mTrigId)) return kStOK;
00161 mAccEve++;
00162
00163
00164
00165
00166
00167 int id;
00168
00169 for (id=0; id<mxSoftId; id++) {
00170
00171 int ietabin = mdb_btowetaBin[id];
00172 int iphibin = mdb_btowphiBin[id];
00173
00174
00175 int isoftid = mdb_btowSoftId[id];
00176
00177 float rawAdc = emc->getTowerADC(id+1);
00178
00179 if(mdb_btowStat[id] != 1) continue;
00180
00181 float ped = mdb_btowPed[id];
00182 float adc = (rawAdc - ped);
00183
00184
00185
00186 if(adc>mAdcThreshold) {
00187
00188 FillAdc(adc,ietabin,iphibin,isoftid);
00189 mevtH[0]->Fill(ietabin,iphibin,adc);
00190 }
00191
00192 }
00193
00194 mhisto[2]->Fill(3);
00195 mhisto[6]->Fill(bx7);
00196
00197 int myetapattern,myphipattern,myetaendpattern,mypatternlength;
00198 float myadcsum,myavgetaadc;
00199
00200
00201 bool IsItBackGround = CheckPatternType3(myetapattern,myphipattern,myetaendpattern,mypatternlength,myadcsum,myavgetaadc);
00202
00203 mSearchDone=true;
00204
00205 if(IsItBackGround==1){
00206 mDecision=1;
00207 metaBegin=myetapattern;
00208 mphiBegin=myphipattern;
00209 metaEnd=myetaendpattern;
00210 mpatternLength=mypatternlength;
00211 msumAdc=myadcsum;
00212 mAvgEtaAdc=myavgetaadc;
00213
00214
00215 mhisto[2]->Fill(7);
00216 mevtH[1]->Fill((myetapattern-20.)/20.,myphipattern*3);
00217 mevtH[2]->Fill((myavgetaadc-20.)/20.,myphipattern*3);
00218 mhisto[3]->Fill(myphipattern*3,mypatternlength);
00219 mhisto[4]->Fill(myphipattern*3,myadcsum);
00220 mhisto[7]->Fill(bx7);
00221
00222
00223
00224 if(metaEnd<20){
00225 mhisto[2]->Fill(9);
00226 sprintf(mLocation,"East");
00227 }
00228
00229 if((metaBegin<20)&&(metaEnd>=20)){
00230 mhisto[2]->Fill(11);
00231 sprintf(mLocation,"Central");
00232 }
00233
00234 if(metaBegin>19){
00235 mhisto[2]->Fill(13);
00236 sprintf(mLocation,"West");
00237 }
00238
00239
00240 }
00241
00242 else {
00243 mDecision=0;
00244
00245 mhisto[2]->Fill(5);
00246 }
00247
00248
00249
00250 if(IsItBackGround==1) {
00251 if((mMaxYesPlots--)>0) PlotOneEvent();
00252 } else {
00253 if((mMaxNoPlots--)>0) PlotOneEvent();
00254 }
00255
00256 return kStOK;
00257 }
00258
00259
00260
00261
00262 Int_t StBemcBeamBckgFinderMaker::InitRun(int runNo){
00263
00264 LOG_INFO << GetName()<<"::InitRun() run=" <<runNo<<endm;
00265 mRunNumber=runNo;
00266
00267
00268 assert(mMappB==0);
00269 StEmcDecoder *mMappB = new StEmcDecoder(GetDate(),GetTime());
00270
00271 StBemcTables *myTable=new StBemcTables;
00272 myTable->loadTables(this );
00273
00274
00275 memset(mdb_btowPed, 0,sizeof(mdb_btowPed));
00276 memset(mdb_btowStat, 0,sizeof(mdb_btowStat));
00277
00278 memset(mdb_btowetaBin, 0,sizeof(mdb_btowetaBin));
00279 memset(mdb_btowphiBin, 0,sizeof(mdb_btowphiBin));
00280
00281
00282 memset(mdb_btowRdo, 0,sizeof(mdb_btowRdo));
00283 memset(mdb_btowSoftId, 0,sizeof(mdb_btowSoftId));
00284
00285
00286 int softID;
00287
00288 for(softID=1; softID<=BTOWSIZE; softID++) {
00289
00290
00291
00292
00293 int status;
00294 myTable->getStatus(BTOW, softID, status);
00295 int m,e,s;
00296 mGeomB->getBin(softID,m,e,s);
00297
00298 float etaF,phiF;
00299 mGeomB->getEta(m,e,etaF);
00300 mGeomB->getPhi(m,s,phiF);
00301 if(phiF<0) phiF+=2*C_PI;
00302
00303 float ped,sig;
00304 myTable->getPedestal(BTOW, softID, 0, ped,sig);
00305
00306 float gain;
00307 myTable->getCalib(BTOW, softID, 1, gain);
00308
00309 mdb_btowPed[softID-1]=ped;
00310
00311 int Rdo;
00312 assert(mMappB->GetDaqIdFromTowerId(softID,Rdo)==1);
00313
00314 mdb_btowRdo[softID-1] = Rdo;
00315 mdb_btowSoftId[softID-1] = softID;
00316
00317 status= GetNewStatus(softID,Rdo,mRunNumber);
00318 mdb_btowStat[softID-1]=status;
00319
00320
00321
00322 if(status != 1) mhisto[1]->Fill(softID);
00323
00324 int kEta = int ((etaF+1.)*20.);
00325 int kPhi = int (phiF*19.10);
00326
00327
00328
00329 mdb_btowetaBin[softID-1] = kEta;
00330 mdb_btowphiBin[softID-1] = kPhi;
00331
00332 mSoftId[kPhi][kEta] = softID;
00333
00334
00335
00336 }
00337
00338 return kStOk;
00339
00340 }
00341
00342
00343
00344
00345 Int_t StBemcBeamBckgFinderMaker::Finish(){
00346
00347 LOG_INFO << Form("%s::Finish() accepted %d eve of %d input events, TrigID=%d\n",GetName(),mAccEve, mInpEve,mTrigId)<<endm;
00348 return kStOK;
00349 }
00350
00351
00352
00353
00354 Int_t StBemcBeamBckgFinderMaker::GetNewStatus(int id, int rdo, int run){
00355
00356 const int db_btowAddMaskA[] = {4505,533,577,578,579,580,4020,4019,816,839,1612,2916,2897,1773,1774,1775,1776,2085,2105,2257,0};
00357 const int db_btowAddMaskB[] = {3287,3309,3407,3674,0};
00358 const int db_btowAddMaskC[] = {0};
00359
00360 const int *db_btowAddMask;
00361 int xMask;
00362
00363 if(run>7000000) {
00364 db_btowAddMask=db_btowAddMaskA;
00365 xMask=20;
00366 } else {
00367 if(run==6169089) {
00368 db_btowAddMask=db_btowAddMaskB;
00369 xMask=4;
00370 } else {
00371 db_btowAddMask=db_btowAddMaskC;
00372 xMask=0;
00373 }
00374 }
00375
00376
00377 for(int i=0; i<xMask; i++) {
00378
00379
00380
00381 if(db_btowAddMask[i]<=0) {
00382 printf("Error Error Error: your masked array db_btowAddMask=0 for this run number\n");
00383 assert(1==2);
00384 }
00385
00386 if(db_btowAddMask[i]==id){
00387 printf("===================================================================\n");
00388 printf("===================================================================\n");
00389 printf("RunNo=%d :: tower with softid=%d and Rdo=%d will be masked\n",run,id,rdo);
00390 return (0);
00391 }
00392 }
00393
00394 return (1);
00395 }
00396
00397
00398
00399
00400 void StBemcBeamBckgFinderMaker::FillAdc(float adc,int ieta,int iphi,int isoft){
00401 assert(ieta>=0);
00402 assert(ieta<mxEta);
00403
00404 assert(iphi>=0);
00405 assert(iphi<mxPhi);
00406
00407 mAdcArray[iphi][ieta] = adc;
00408
00409
00410
00411 }
00412
00413
00414
00415
00416 void StBemcBeamBckgFinderMaker::PlotOneEvent(){
00417
00418 char Decision[10];
00419 char HistoTitle_Out[2000];
00420 char FileTitle_Out[1000];
00421
00422
00423 if(mDecision==1){
00424 sprintf(Decision,"Yes");
00425 sprintf(HistoTitle_Out,"R=%d E=%05d T=%d Bg=%s #eta1=%d #phi=%d #eta2=%d L=%d Adc+=%f Loct=%s",mRunNumber,mInpEve,mTrigId,Decision,metaBegin,mphiBegin,metaEnd,mpatternLength,msumAdc,mLocation);
00426 }
00427
00428 if(mDecision==0){
00429 sprintf(Decision,"No");
00430 sprintf(HistoTitle_Out,"Run=%d, Eve=%05d, TrgId=%d, Bckg=%s",mRunNumber,mInpEve,mTrigId,Decision);
00431 }
00432
00433
00434 sprintf(FileTitle_Out,"event%05d_%s.ps",mInpEve,Decision);
00435
00436 TCanvas mycanvas("aa","aa",600,800);
00437 mevtH[0]->SetTitle(HistoTitle_Out);
00438 mevtH[0]->GetXaxis()->CenterTitle();
00439 mevtH[0]->GetYaxis()->CenterTitle();
00440 gStyle->SetPalette(1,0);
00441 gStyle->SetOptStat(0);
00442 gStyle->SetTitleFontSize(0.08);
00443 mevtH[0]->Draw("colz");
00444 mycanvas.Print(FileTitle_Out);
00445
00446 }
00447
00448
00449
00450
00451
00452 Int_t StBemcBeamBckgFinderMaker::CheckPatternType3(int &etaBegin, int &phiBegin, int &etaEnd, int &patternLength, float &sumAdc, float &AverageWeightedEta){
00453
00454 int maxLength = 0;
00455 int i,j,k,n;
00456
00457 int FirstEtaFound;
00458 float FirstEtaAdc,sum=0.;
00459 float sumEtaAdc=0.;
00460
00461
00462
00463
00464 for(i=0; i<mxPhi; i++){
00465 float *adc = mAdcArray[i];
00466 n = 0;
00467 maxLength = 0;
00468 memset(mPattSoftId, 0,sizeof(mPattSoftId));
00469
00470
00471 for(j=0; j<mxEta; j++){
00472 if(adc[j]<=0) continue;
00473
00474 n = 1;
00475 FirstEtaFound=j;
00476 FirstEtaAdc = adc[j];
00477 sum = FirstEtaAdc;
00478 sumEtaAdc=(FirstEtaFound*sum);
00479 mPattSoftId[n-1] = mSoftId[i][j];
00480
00481
00482
00483
00484 for(k=j+1; k<mxEta; k++){
00485
00486 if((adc[k]<mAdcThreshold)&&(adc[k+1]<mAdcThreshold)) {
00487
00488 break;
00489 }
00490
00491 sum = sum + adc[k];
00492 sumEtaAdc=sumEtaAdc+(k*adc[k]);
00493 n++;
00494 mPattSoftId[n-1] = mSoftId[i][k];
00495
00496
00497
00498 }
00499
00500 maxLength=0;
00501
00502 if(maxLength<n) maxLength=n;
00503
00504 j=k;
00505
00506
00507 if((maxLength>=mpattern)&&(sum>=mAdcSumThreshold)){
00508
00509
00510
00511
00512
00513
00514
00515
00516 phiBegin=i;
00517 etaBegin=FirstEtaFound;
00518 patternLength=maxLength;
00519 etaEnd=(etaBegin + (patternLength-1));
00520 sumAdc=sum;
00521 AverageWeightedEta=(sumEtaAdc/sum);
00522
00523 return(true);
00524 break;
00525 }
00526 }
00527 }
00528
00529 return(false);
00530 }
00531
00532
00533
00534
00535 void StBemcBeamBckgFinderMaker::GetDecision(int &fDecision, int &eta1, int &phi1, int &eta2, int &patternleng, float &Adcsum){
00536
00537 if((mSearchDone)&&(mDecision)){
00538
00539 fDecision=mDecision;
00540 eta1=metaBegin;
00541 eta2=metaEnd;
00542 phi1=mphiBegin;
00543 patternleng=mpatternLength;
00544 Adcsum=msumAdc;
00545 } else {
00546
00547 if((mSearchDone)&&(!mDecision)){
00548 fDecision=mDecision;
00549 } else {
00550 fDecision=-1;
00551 }
00552 eta1=0;
00553 eta2=0;
00554 phi1=0;
00555 patternleng=0;
00556 Adcsum=0;
00557
00558 }
00559 }
00560
00561
00562
00563
00564
00565
00566
00567
00568
00569
00570
00571
00572
00573
00574
00575
00576
00577
00578
00579
00580
00581
00582
00583
00584
00585
00586
00587
00588
00589
00590
00591
00592
00593
00594
00595
00596
00597
00598
00599
00600
00601
00602
00603
00604
00605
00606