StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StEmcAsciiDbMaker.cxx
1 // $Id: StEmcAsciiDbMaker.cxx,v 1.6 2012/12/12 22:00:59 fisyak Exp $
2 // Emulates L2 in offline for algorithm testing
3 // Interface to online/L2jetAlgo/
4 // Jan Balewski, Fall 2005
5 
6 #ifdef __APPLE__
7 #include <sys/types.h>
8 #endif
9 #include <stdio.h>
10 #include <TH2.h>
11 #include <TFile.h>
12 
13 #include <StMessMgr.h>
14 
15 #include "StEmcAsciiDbMaker.h"
16 #include "StEmcRawMaker/defines.h"
17 
18 #include <StEEmcUtil/database/StEEmcDb.h>
19 #include <StEEmcUtil/database/EEmcDbItem.h>
20 #include <StEEmcUtil/database/EEmcDbCrate.h>
21 //#include <St_db_Maker/St_db_Maker.h>
22 
23 // BTOW stuff
24 #include "StEmcUtil/geometry/StEmcGeom.h"
25 #include "StEmcUtil/database/StBemcTables.h"
26 #include "StEmcUtil/database/StEmcDecoder.h"
27 
28 
29 ClassImp(StEmcAsciiDbMaker)
30 
31 //========================================
32 //========================================
33  StEmcAsciiDbMaker::StEmcAsciiDbMaker() : StMaker("StEmcAsciiDb") {
34 
35  mGeomB =0;
36  mEeDb=0;
37  mMappB=0;
38  mHList=0;
39  mgain60Et=false;
40 
41  memset(hA,0,sizeof(hA));
42  /* Alexandre A. P. Suaide wrote:
43  The default if false for 2004/2005 runs and true
44  for 2006 and future runs. You use true *only* if
45  you would like to have the map corrected at decoder
46  level for the 2005 data. */
47 
48 }
49 
50 //========================================
51 //========================================
52 StEmcAsciiDbMaker::~StEmcAsciiDbMaker() {
53 }
54 
55 //========================================
56 //========================================
57 Int_t StEmcAsciiDbMaker::Init() {
58 
59  //................EEMC stuff ..............
60  mEeDb = (StEEmcDb*)this->GetDataSet("StEEmcDb");
61  assert(mEeDb);
62  mGeomB = StEmcGeom::instance("bemc");
63  initAuxHisto();
64  LOG_INFO << Form(" %s::Init() setGain60Et=%d",GetName(),mgain60Et) <<endm;
65 
66  mMappB =0;
67  return kStOk;
68 }
69 
70 //========================================
71 //========================================
72 Int_t StEmcAsciiDbMaker::InitRun(int runNo){
73  int yyyymmdd = this->GetDBTime().GetDate();
74  int hhmmss = this->GetDBTime().GetTime();
75 
76 
77  TString outPath="L2setup-"; outPath+=yyyymmdd; //<--- +yyyymmdd
78  printf("outPath=%s=\n",outPath.Data());
79  LOG_INFO << GetName()<<"::InitRun() run=" <<runNo<<" outPath="<<outPath<<endm;
80 
81  // this is how BTOW mapping is accesible
82  assert( mMappB==0) ; // do not know how to destroy previous instance,JB
83  mMappB = new StEmcDecoder(yyyymmdd,hhmmss);
84  //one can drop mTowerMapBug and use default constructor- siad Pibero
85 
86  exportBtowDb(outPath+"/btowDb.current",runNo,yyyymmdd,hhmmss);
87  exportEtowDb(outPath+"/etowDb.current",runNo,yyyymmdd,hhmmss);
88 
89  return kStOk;
90 }
91 
92 
93 
94 //========================================
95 //========================================
97  //empty
98  return kStOk;
99 
100 }
101 
102 //========================================
103 //========================================
104 void StEmcAsciiDbMaker::Clear(const Option_t* ){
105 }
106 
107 //========================================
108 //========================================
110  return kStOk;
111 }
112 
113 
114 //========================================
115 //========================================
116 void StEmcAsciiDbMaker::exportBtowDb(TString fname, int runNo, int yyyymmdd,int hhmmss){
117  LOG_INFO << GetName()<<"::exportBtowDb start -->"<<fname<<endm;
118 
119  // for calulation of ideal gains @ maxEt=60 GeV - if needed
120  const int par_maxADC=4096; // chan
121  const float par_maxEt=60; // GeV Et
122 
123  StBemcTables *myTable=new StBemcTables;
124  myTable->loadTables(this );
125 
126  FILE *fd=fopen(fname.Data(),"w");
127  assert(fd);
128  fprintf(fd,"# ::exportBtowDb(), time stamp: day=%d hhmmss=%06d run=R%d\n",yyyymmdd,hhmmss, runNo);
129  if(mgain60Et) fprintf(fd,"# ideal gains(ch/GeV) set at maxEt=60 GeV\n");
130  else fprintf(fd,"# real gains(ch/GeV) from OFL DB\n");
131 
132  fprintf(fd,"# see online/EmcDbAnsiC/EmcCDbItem.h for definitions\n");
133  fprintf(fd,"#name, crate,chan, sec,sub,eta, gain, ped, thr, stat,fail, id-m-s-e, RDO\n");
134 
135  int softID;
136  int nB=0,nA=0,nC=0;
137  for(softID=1; softID<=BTOWSIZE; softID++) {
138  nA++;
139 
140  int RDO, CR,CHAN;
141  assert(mMappB->GetDaqIdFromTowerId(softID,RDO)==1);// is good range
142  assert(mMappB->GetTowerCrateFromDaqId(RDO,CR,CHAN)==1);
143  // printf("soft=%d DRO=%d CR=%d CHAN=%d\n",softID,RDO,CR,CHAN);
144 
145  //........... querry BTOW DB/geom
146  int status;
147  myTable->getStatus(BTOW, softID, status);
148  int m,e,s;
149  mGeomB->getBin(softID,m,e,s);
150 
151  float etaF,phiF;
152  mGeomB->getEta(m,e,etaF);
153  mGeomB->getPhi(m,s,phiF); // -pi <= phi < pi
154  if( phiF<0) phiF+=2*C_PI; // I want phi in [0,2Pi]
155  // printf("soft=%4d DRO=%4d CR=0x%02x CHAN=%3d eta=%.2f phi/deg=%.1f\n",softID,RDO,CR,CHAN,etaF,phiF/3.1416*180.);
156 
157  float ped,sig;
158  myTable->getPedestal(BTOW, softID, 0, ped,sig);
159 
160  float gain;
161  myTable->getCalib(BTOW, softID, 1, gain);
162 
163  //........... convert it to private bins
164 
165 
166  assert(fabs(etaF)<0.99);
167  int kEta=1+(int)((etaF+1.)/0.05);
168 
169  int kPhi=24-(int)( phiF/C_PI*60.);
170  if(kPhi<0) kPhi+=120;
171  // convention: kPhi=[0,119], kEta=[1,40]
172 
173  char name[10]="nnn", pname[100];
174  int sec=1+kPhi/10;
175  char sub='a'+kPhi%10;
176  sprintf(name,"%02dt%c%02d",sec,sub,kEta);
177 
178  hA[2]->Fill(softID,1000*kPhi+(kEta-1));
179  hA[3]->SetBinContent(kEta,kPhi+1,softID);
180 
181  // printf("phiF/deg=%.1f kPhi=%d %s\n",phiF/C_PI*180.,kPhi,name);
182  float myGain=-2;
183  if(gain>0) {
184  myGain=1/gain;
185  nC++;
186  }
187 
188  if(mgain60Et) myGain=par_maxADC/par_maxEt/cosh(etaF); // ideal gains?
189 
190  // printf("%s %f %d\n",name,myGain,nC); assert(2==3);
191  ushort stat=0;
192  ushort fail=0;
193  if(status==1) {
194  nB++;
195  float ph=phiF/C_PI*180.;
196  while(ph<0) ph+=360.;
197  ((TH2F*) hA[0])->Fill(etaF,ph,myGain);
198  }
199 
200  float thr=ped+mEeDb->getKsigOverPed()*sig;
201  sprintf(pname,"id%04d-%03d-%d-%02d",softID,m,s,e);
202  fprintf(fd,"%6s 0x%02x 0x%02x %2d %c %2d %8.2f %5.2f %5.2f 0x%02x 0x%02x %8s %4d\n",
203  name,CR,CHAN,sec,sub,kEta,myGain,ped,thr,stat,fail,pname,RDO);
204  // if(softID>100) break;
205  }
206  fclose(fd);
207 
208  LOG_INFO << Form("exportBtowDb -->%s ,nTw=%d nNotFail=%d nGoodGain=%d",fname.Data(),nA,nB,nC) <<endm;
209 
210 #if 0 // tmp, somehow HList does not write, fix it
211  TString outName="btowMap.hist.root";
212  TFile f( outName,"recreate");
213  assert(f.IsOpen());
214  printf("BTOW map histos are written to '%s' ...\n",outName.Data());
215  hA[2]->Write();
216  hA[3]->Write();
217  f.Close();
218 
219 #endif
220 
221 
222 }
223 
224 //========================================
225 //========================================
226 void StEmcAsciiDbMaker::exportEtowDb(TString fname, int runNo, int yyyymmdd,int hhmmss){
227  LOG_INFO << GetName()<<"::exportEtowDb start -->"<<fname<<endm;
228 
229  // for calulation of ideal gains @ maxEt=60 GeV - if needed
230  const int par_maxADC=4096; // chan
231  const float par_maxEt=60; // GeV Et
232  const float etaF[12]={1.95,1.855,1.765,1.675,1.59,1.51,1.435,1.365,1.3,1.235,1.17,1.115};
233 
234  // not that nice redundance, JB
235  const int cETOW_DATSIZE=160;
236  const int cETOW_MAXFEE=6;
237 
238  FILE *fd=fopen(fname.Data(),"w");
239  assert(fd);
240  fprintf(fd,"# ::exportEtowDb(), time stamp: day=%d hhmmss=%06d run=R%d\n",yyyymmdd, runNo,hhmmss);
241 
242  if(mgain60Et) fprintf(fd,"# ideal gains(ch/GeV) set at maxEt=60 GeV\n");
243  else fprintf(fd,"# real gains(ch/GeV) from OFL DB\n");
244 
245  fprintf(fd,"# see online/EmcDbAnsiC/EmcDbItemStruct.h for definitions\n");
246  fprintf(fd,"#name, crate,chan, sec,sub,eta, gain, ped, thr, stat,fail, PsoftId, RDO\n");
247  int nB=0,nA=0,nC=0;
248  int icr;
249 
250  for(icr=0;icr<mEeDb->getNFiber();icr++) {
251  const EEmcDbCrate *fiber=mEeDb->getFiber(icr);
252  if(fiber->crID>6) continue; // drop non-tower crates
253  assert(fiber->useIt); // code not ready to handle masked crates
254  assert(fiber->crID==icr+1);
255  int i;
256  for(i=0;i<cETOW_DATSIZE;i++) {
257  const EEmcDbItem *x=mEeDb->getByCrate(fiber->crID,i);
258  if(x==0) continue;
259  nA++;
260  int rdo = icr + i*cETOW_MAXFEE;
261 
262  assert(x->eta>0 && x->eta<=12);
263 
264  float myGain=x->gain;
265  if(mgain60Et) myGain=par_maxADC/par_maxEt/cosh(etaF[x->eta-1]); // ideal gains?
266 
267 
268  fprintf(fd,"%6s 0x%02x 0x%02x %2d %c %2d %8.2f %5.2f %5.2f 0x%02x 0x%02x %8s %4d\n",
269  x->name,fiber->crID,x->chan,x->sec,x->sub,x->eta,myGain,x->ped,x->thr,0,0,x->tube,rdo);
270  if( !x->fail) {
271  nB++;
272  float ph=5*(x->sec-1)+x->sub-'A';
273  ((TH2F*) hA[1])->Fill(13-x->eta,ph,myGain);
274  }
275 
276  //tmp else printf("bad %s stat/fail: 0x%02x 0x%02x\n", x->name,x->stat,x->fail); //tmp
277  if(x->gain>0) nC++;
278  }
279  }
280  fclose(fd);
281 
282  LOG_INFO << Form("exportEtowDb -->%s ,nTw=%d nNotFail=%d nGain=%d",fname.Data(),nA,nB,nC) <<endm;
283 }
284 
285 
286 
287 //========================================
288 //========================================
289 void StEmcAsciiDbMaker::initAuxHisto() {
290  assert(mHList);
291  hA[0]=new TH2F("bGn","BTOW gains from DB in [ch/GeV] ; eta; STAR phi (deg)",40,-1.,1.,120,0,360);
292 
293  hA[1]=new TH2F("eGn","ETOW gains from DB in [ch/GeV] ; eta bins reversed, (eta[+1,+2]); phi bin (5*sec-1 +sub-1)",12,0.5,12.5,60,-0.5,59.5);
294 
295 
296  hA[2]=new TH1I("L2mapBTOWrev","map BTOW(softID) --> 1000*#phi_{bin} + #eta_{bin} , L2 di-jet convention; BTOW softID; composite {#eta,#phi} index ",4800,0.5,4800.5);
297 
298  hA[3]=new TH2I("L2mapBTOW","map BTOW(#eta_{bin},#phi_{bin}) --> softID , L2 di-jet convention ;BTOW #eta_{bin} ;BTOW #phi_{bin} ",40,-0.5,39.5,120,-0.5,119.5);
299 
300 
301  for(int i=0;i<4;i++) mHList->Add( hA[i]);
302  mHList->Print();
303 
304 }
305 
306 /* *******************************
307  $Log: StEmcAsciiDbMaker.cxx,v $
308  Revision 1.6 2012/12/12 22:00:59 fisyak
309  add sys/types.h include for APPLE
310 
311  Revision 1.5 2009/02/26 20:30:54 balewski
312  now mask from DB s NOT written to asscii files
313 
314  Revision 1.4 2009/02/04 20:33:06 ogrebeny
315  Moved the EEMC database functionality from StEEmcDbMaker to StEEmcUtil/database. See ticket http://www.star.bnl.gov/rt2/Ticket/Display.html?id=1388
316 
317  Revision 1.3 2008/12/06 13:20:42 balewski
318  fix of histo code, was non-fatal
319 
320  Revision 1.2 2008/07/31 14:18:37 balewski
321  saves BTOW reative location mapping, needs manual activatio
322 
323  Revision 1.1 2006/03/09 01:33:10 balewski
324  start
325 
326 */
327 
char name[StEEmcNameLen]
ASCII name of the channel, see Readme.
Definition: EEmcDbItem.h:20
int useIt
flag to ignore data from misconfig/broken crate/box
Definition: EEmcDbCrate.h:19
void getPedestal(Int_t det, Int_t softId, Int_t cap, Float_t &ped, Float_t &rms) const
Return pedestal mean and rms.
int GetTowerCrateFromDaqId(int RDO, int &crate, int &sequence) const
Get crate number from Daq Id for towers.
void loadTables(StMaker *anyMaker)
load tables.
char tube[StEEmcNameLen]
name of PMT or MAPMT pixel
Definition: EEmcDbItem.h:21
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
Definition: StMaker.cxx:237
Int_t getBin(const Float_t phi, const Float_t eta, Int_t &m, Int_t &e, Int_t &s) const
Definition: StEmcGeom.h:321
void getStatus(Int_t det, Int_t softId, Int_t &status, const char *option="") const
Return status.
int crID
logical crate ID
Definition: EEmcDbCrate.h:13
int GetDaqIdFromTowerId(int softId, int &RDO) const
Get Daq Id from Software Id for towers.
int chan
hardware channel
Definition: EEmcDbItem.h:28
Definition: Stypes.h:41