15 #include "StBemcBeamBckgFinderMaker.h"
17 #include "St_DataSetIter.h"
18 #include "StDAQMaker/StDAQReader.h"
20 #include <StMessMgr.h>
21 #include <StEmcUtil/geometry/StEmcGeom.h>
22 #include <StEmcUtil/database/StBemcTables.h>
24 #include "StEmcUtil/database/StEmcDecoder.h"
25 #include "StEmcRawMaker/defines.h"
28 #include "StMuDSTMaker/COMMON/StMuDstMaker.h"
29 #include "StMuDSTMaker/COMMON/StMuDst.h"
30 #include "StMuDSTMaker/COMMON/StMuTriggerIdCollection.h"
31 #include "StMuDSTMaker/COMMON/StMuEvent.h"
41 memset(mhisto, 0,
sizeof(mhisto));
42 memset(mevtH, 0,
sizeof(mevtH));
53 StBemcBeamBckgFinderMaker::~StBemcBeamBckgFinderMaker(){
60 Int_t StBemcBeamBckgFinderMaker::Init(){
62 mGeomB = StEmcGeom::instance(
"bemc");
65 mhisto[0]=
new TH1F(
"Frequency1",
"Towers Frequency (status =1); Tower SoftId; Frequency",mxSoftId,0.5,mxSoftId+0.5);
66 mhisto[1]=
new TH1F(
"Frequency2",
"Towers Frequency (status !=1); Tower SoftId; Frequency",mxSoftId,0.5,mxSoftId+0.5);
67 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);
68 mhisto[3]=
new TH1F(
"StartingphiVspattern",
"Pattern Starting #phi Weighted By Pattern Length; #phi[deg]",360,0.5,360.5);
69 mhisto[4]=
new TH1F(
"StartingphiVsadcsum",
"Pattern Starting #phi Weighted By Pattern Summed Adc; #phi[deg]",360,0.5,360.5);
71 mhisto[5]=
new TH1F(
"Allbunchcrossing7",
"All Bunch Crossings; Bunch Crossing No (7bit)",128,-0.50,127.5);
72 mhisto[6]=
new TH1F(
"Trigbunchcrossing7",
"Trigger Passing Bunch Crossings; Bunch Crossing No (7bit)",128,-0.50,127.5);
73 mhisto[7]=
new TH1F(
"Bckgbunchcrossing7",
"Background Passing Bunch Crossings; Bunch Crossing No (7bit)",128,-0.50,127.5);
75 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);
76 mevtH[1]=
new TH2F(
"StartingphiVseta",
"Pattern Starting #phi Vs. Pattern Starting #eta; #eta; #phi(deg)",10,-1,1,30,0.5,360.5);
77 mevtH[2]=
new TH2F(
"AvgWeightedPhiVsEta",
"Pattern #phi Vs. Pattern Weighted Average #eta; <#eta>; #phi(deg)",20,-1,1,60,0.5,360.5);
79 for(
int i=0; i<mMaxH; i++){
81 mHList->Add(mhisto[i]);
84 for(
int i=0; i<mMaxevtH; i++){
86 mHList->Add(mevtH[i]);
89 LOG_INFO<< Form(
"%s::Init() accept TrigID=%d\n",
GetName(),mTrigId)<<endm;
91 return StMaker::Init();
97 void StBemcBeamBckgFinderMaker::Clear(
const Option_t* option){
100 memset(mAdcArray, 0,
sizeof(mAdcArray));
101 memset(mPattSoftId, 0,
sizeof(mPattSoftId));
137 int bx7=trig.bunchCrossingId7bit(info.runId());
138 mhisto[5]->Fill(bx7);
153 vector<unsigned int> nominalL=nominal->triggerIds();
154 printf(
"trigL len=%d totEve=%d\n",nominalL.size(),mInpEve);
156 for(ii=0;ii<nominalL.size();ii++)printf(
"trgID=%d, ",nominalL[ii]);
160 if(mTrigId>0 && !nominal->isTrigger(mTrigId))
return kStOK;
169 for (
id=0;
id<mxSoftId;
id++) {
171 int ietabin = mdb_btowetaBin[id];
172 int iphibin = mdb_btowphiBin[id];
175 int isoftid = mdb_btowSoftId[id];
177 float rawAdc = emc->getTowerADC(
id+1);
179 if(mdb_btowStat[
id] != 1)
continue;
181 float ped = mdb_btowPed[id];
182 float adc = (rawAdc - ped);
186 if(adc>mAdcThreshold) {
188 FillAdc(adc,ietabin,iphibin,isoftid);
189 mevtH[0]->Fill(ietabin,iphibin,adc);
195 mhisto[6]->Fill(bx7);
197 int myetapattern,myphipattern,myetaendpattern,mypatternlength;
198 float myadcsum,myavgetaadc;
201 bool IsItBackGround = CheckPatternType3(myetapattern,myphipattern,myetaendpattern,mypatternlength,myadcsum,myavgetaadc);
205 if(IsItBackGround==1){
207 metaBegin=myetapattern;
208 mphiBegin=myphipattern;
209 metaEnd=myetaendpattern;
210 mpatternLength=mypatternlength;
212 mAvgEtaAdc=myavgetaadc;
216 mevtH[1]->Fill((myetapattern-20.)/20.,myphipattern*3);
217 mevtH[2]->Fill((myavgetaadc-20.)/20.,myphipattern*3);
218 mhisto[3]->Fill(myphipattern*3,mypatternlength);
219 mhisto[4]->Fill(myphipattern*3,myadcsum);
220 mhisto[7]->Fill(bx7);
226 sprintf(mLocation,
"East");
229 if((metaBegin<20)&&(metaEnd>=20)){
231 sprintf(mLocation,
"Central");
236 sprintf(mLocation,
"West");
250 if(IsItBackGround==1) {
251 if((mMaxYesPlots--)>0) PlotOneEvent();
253 if((mMaxNoPlots--)>0) PlotOneEvent();
262 Int_t StBemcBeamBckgFinderMaker::InitRun(
int runNo){
264 LOG_INFO <<
GetName()<<
"::InitRun() run=" <<runNo<<endm;
275 memset(mdb_btowPed, 0,
sizeof(mdb_btowPed));
276 memset(mdb_btowStat, 0,
sizeof(mdb_btowStat));
278 memset(mdb_btowetaBin, 0,
sizeof(mdb_btowetaBin));
279 memset(mdb_btowphiBin, 0,
sizeof(mdb_btowphiBin));
282 memset(mdb_btowRdo, 0,
sizeof(mdb_btowRdo));
283 memset(mdb_btowSoftId, 0,
sizeof(mdb_btowSoftId));
288 for(softID=1; softID<=BTOWSIZE; softID++) {
294 myTable->
getStatus(BTOW, softID, status);
296 mGeomB->
getBin(softID,m,e,s);
299 mGeomB->getEta(m,e,etaF);
300 mGeomB->getPhi(m,s,phiF);
301 if(phiF<0) phiF+=2*C_PI;
307 myTable->
getCalib(BTOW, softID, 1, gain);
309 mdb_btowPed[softID-1]=ped;
314 mdb_btowRdo[softID-1] = Rdo;
315 mdb_btowSoftId[softID-1] = softID;
317 status= GetNewStatus(softID,Rdo,mRunNumber);
318 mdb_btowStat[softID-1]=status;
322 if(status != 1) mhisto[1]->Fill(softID);
324 int kEta = int ((etaF+1.)*20.);
325 int kPhi = int (phiF*19.10);
329 mdb_btowetaBin[softID-1] = kEta;
330 mdb_btowphiBin[softID-1] = kPhi;
332 mSoftId[kPhi][kEta] = softID;
347 LOG_INFO << Form(
"%s::Finish() accepted %d eve of %d input events, TrigID=%d\n",
GetName(),mAccEve, mInpEve,mTrigId)<<endm;
354 Int_t StBemcBeamBckgFinderMaker::GetNewStatus(
int id,
int rdo,
int run){
356 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};
357 const int db_btowAddMaskB[] = {3287,3309,3407,3674,0};
358 const int db_btowAddMaskC[] = {0};
360 const int *db_btowAddMask;
364 db_btowAddMask=db_btowAddMaskA;
368 db_btowAddMask=db_btowAddMaskB;
371 db_btowAddMask=db_btowAddMaskC;
377 for(
int i=0; i<xMask; i++) {
381 if(db_btowAddMask[i]<=0) {
382 printf(
"Error Error Error: your masked array db_btowAddMask=0 for this run number\n");
386 if(db_btowAddMask[i]==
id){
387 printf(
"===================================================================\n");
388 printf(
"===================================================================\n");
389 printf(
"RunNo=%d :: tower with softid=%d and Rdo=%d will be masked\n",run,
id,rdo);
400 void StBemcBeamBckgFinderMaker::FillAdc(
float adc,
int ieta,
int iphi,
int isoft){
407 mAdcArray[iphi][ieta] = adc;
416 void StBemcBeamBckgFinderMaker::PlotOneEvent(){
419 char HistoTitle_Out[2000];
420 char FileTitle_Out[1000];
424 sprintf(Decision,
"Yes");
425 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);
429 sprintf(Decision,
"No");
430 sprintf(HistoTitle_Out,
"Run=%d, Eve=%05d, TrgId=%d, Bckg=%s",mRunNumber,mInpEve,mTrigId,Decision);
434 sprintf(FileTitle_Out,
"event%05d_%s.ps",mInpEve,Decision);
436 TCanvas mycanvas(
"aa",
"aa",600,800);
437 mevtH[0]->SetTitle(HistoTitle_Out);
438 mevtH[0]->GetXaxis()->CenterTitle();
439 mevtH[0]->GetYaxis()->CenterTitle();
440 gStyle->SetPalette(1,0);
441 gStyle->SetOptStat(0);
442 gStyle->SetTitleFontSize(0.08);
443 mevtH[0]->Draw(
"colz");
444 mycanvas.Print(FileTitle_Out);
452 Int_t StBemcBeamBckgFinderMaker::CheckPatternType3(
int &etaBegin,
int &phiBegin,
int &etaEnd,
int &patternLength,
float &sumAdc,
float &AverageWeightedEta){
458 float FirstEtaAdc,sum=0.;
464 for(i=0; i<mxPhi; i++){
465 float *adc = mAdcArray[i];
468 memset(mPattSoftId, 0,
sizeof(mPattSoftId));
471 for(j=0; j<mxEta; j++){
472 if(adc[j]<=0)
continue;
476 FirstEtaAdc = adc[j];
478 sumEtaAdc=(FirstEtaFound*sum);
479 mPattSoftId[n-1] = mSoftId[i][j];
484 for(k=j+1; k<mxEta; k++){
486 if((adc[k]<mAdcThreshold)&&(adc[k+1]<mAdcThreshold)) {
492 sumEtaAdc=sumEtaAdc+(k*adc[k]);
494 mPattSoftId[n-1] = mSoftId[i][k];
502 if(maxLength<n) maxLength=n;
507 if((maxLength>=mpattern)&&(sum>=mAdcSumThreshold)){
517 etaBegin=FirstEtaFound;
518 patternLength=maxLength;
519 etaEnd=(etaBegin + (patternLength-1));
521 AverageWeightedEta=(sumEtaAdc/sum);
535 void StBemcBeamBckgFinderMaker::GetDecision(
int &fDecision,
int &eta1,
int &phi1,
int &eta2,
int &patternleng,
float &Adcsum){
537 if((mSearchDone)&&(mDecision)){
543 patternleng=mpatternLength;
547 if((mSearchDone)&&(!mDecision)){
virtual void Clear(Option_t *option="")
User defined functions.
void getPedestal(Int_t det, Int_t softId, Int_t cap, Float_t &ped, Float_t &rms) const
Return pedestal mean and rms.
void loadTables(StMaker *anyMaker)
load tables.
static StMuEmcCollection * muEmcCollection()
returns pointer to current StMuEmcCollection
static StMuEvent * event()
returns pointer to current StMuEvent (class holding the event wise information, e.g. event number, run number)
void getCalib(Int_t det, Int_t softId, Int_t power, Float_t &calib) const
Return calibration constant.
virtual const char * GetName() const
special overload
Int_t getBin(const Float_t phi, const Float_t eta, Int_t &m, Int_t &e, Int_t &s) const
void getStatus(Int_t det, Int_t softId, Int_t &status, const char *option="") const
Return status.
int GetDaqIdFromTowerId(int softId, int &RDO) const
Get Daq Id from Software Id for towers.
Collection of trigger ids as stored in MuDst.