StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StJanBarrelDbMaker.cxx
1 //*-- Author : Victor Perevoztchikov
2 //
3 // $Id: StJanBarrelDbMaker.cxx,v 1.5 2010/04/15 19:13:30 mattheww Exp $
4 #include <stdio.h>
5 #include <TFile.h>
6 #include <TH1.h>
7 #include <TH2.h>
8 
9 #include "StJanBarrelDbMaker.h"
10 
11 #include "StEmcRawMaker/defines.h"
12 #include "StEmcUtil/database/StBemcTables.h"
13 #include "StEmcUtil/geometry/StEmcGeom.h"
14 #include "StEmcUtil/database/StEmcDecoder.h"
15 
16 ClassImp(StJanBarrelDbMaker)
17 
18 //____________________________________________________________________
19 //____________________________________________________________________
20 StJanBarrelDbMaker::StJanBarrelDbMaker(const char *name):StMaker(name){
21  mMappB=0;
22  setDbType(kStarDb); setHList(0);
23 }
24 
25 
26 //____________________________________________________________________
27 //____________________________________________________________________
28 
29 StJanBarrelDbMaker::~StJanBarrelDbMaker(){
30  //
31 }
32 
33 
34 //____________________________________________________________________
35 //____________________________________________________________________
36 
37 Int_t StJanBarrelDbMaker::Init(){
38  LOG_INFO<<Form("::Init() ")<<endm;
39  assert(HList);
40 
41  mBtowGeom = StEmcGeom::instance("bemc");
42  mBprsGeom = StEmcGeom::instance("bprs");
43  mSmdEGeom = StEmcGeom::instance("bsmde");
44  mSmdPGeom = StEmcGeom::instance("bsmdp"); // needed only to map m-s-e --> softID
45  mTables = new StBemcTables();
46 
47  initBprsGeometry();
48 
49  // janDb_bprsSoft2Hard=new TH1I("bprsMapS2H","BPRS software mapping Y=icr*5000 + position; BPRS softID",mxBtow,0.5, 0.5+mxBtow);
50  // HList->Add(janDb_bprsSoft2Hard);
51 
52  return StMaker::Init();
53 }
54 
55 //____________________________________________________________________
56 //____________________________________________________________________
57 
58 Int_t StJanBarrelDbMaker::InitRun (int runNo){
59  LOG_INFO<<Form("::InitRun(%d) algo params:dbType=%d",
60  runNo, par_dbType
61  )<<endm;
62 
63  // St_db_Maker* mydb =(St_db_Maker*) StMaker::GetChain()->GetMaker("StarDb");
64  //assert(mydb);
65 
66  mMappB = new StEmcDecoder(GetDateTime().GetDate(),GetDateTime().GetTime());
67 
68  mTables->loadTables(this );
69  janDb_bprsPed2D=0;
70  janDb_bprsReMap=janDb_btowReMap=0; // optional mapping correction
71 
72  if(par_dbType==kJanDb ) { //
73  assert(par_dbType==kJanDb); // other options not implemnented,
74  int pedRun=runNo;
75 
76 
77  LOG_INFO<<"upload local peds from run"<<pedRun<<endm;
78  char txt[100];
79 
80  const char *pedPath="/star/institutions/mit/balewski/2008-janDb-BprsPeds-v3.1";
81  sprintf(txt,"%s/pedBprsR%d-allCap.hist.root",pedPath,pedRun);
82  TFile* fd=new TFile(txt); assert(fd->IsOpen());
83  fd->ls();
84  janDb_bprsPed2D=(TH2S *)fd->Get("pedBPRScap"); assert(janDb_bprsPed2D);
85  janDb_bprsSigPed2D=(TH2S *)fd->Get("rmsPedBPRScap"); assert(janDb_bprsSigPed2D);
86  janDb_bprsStat=(TH1S *)fd->Get("statBPRSallCap"); assert( janDb_bprsStat); // use stats from every run
87 
88  const char *path= "calib-jan3.1/";
89 
90  sprintf(txt,"%s/mipGainBprs+Btow_v2.hist.root",path);
91  TFile* fd5=new TFile(txt); assert(fd5->IsOpen());
92  fd5->ls();
93  const char *core[mxBTile]={"btow","bprs"};
94  for(int ibp=0;ibp<mxBTile;ibp++) {
95  TString tit=core[ibp]; tit+="MipGain";
96  janDb_mipMean[ibp]=(TH1F *)fd5->Get(tit); assert( janDb_mipMean[ibp]);
97  tit=core[ibp]; tit+="MipSig";
98  janDb_mipSig[ibp]=(TH1F *)fd5->Get(tit); assert( janDb_mipSig[ibp]);
99  tit=core[ibp]; tit+="MipStat";
100  janDb_mipStat[ibp]=(TH1F *)fd5->Get(tit); assert( janDb_mipStat[ibp]);
101  }
102 
103 
104  //Temp1 - use private mapping fix
105  sprintf(txt,"%s/bprsReMap-ver3.hist.root",path);
106  TFile* fd3=new TFile(txt); assert(fd3->IsOpen());
107  janDb_bprsReMap=(TH1I *)fd3->Get("bprsReMap"); assert(janDb_bprsReMap);
108  printf("use BPRS softID corection: %s\n",txt);
109 
110 
111  //Temp1b - use private mapping fix
112  sprintf(txt,"%s/btowReMap-ver3.hist.root",path);
113  TFile* fd4=new TFile(txt); assert(fd4->IsOpen());
114  janDb_btowReMap=(TH1I *)fd4->Get("btowReMap"); assert(janDb_btowReMap);
115  printf("use BTOW softID corection: %s\n",txt);
116 
117  // compute MIP peak limits based on gains
118  // save results to log file
119 
120  for(int ibp=0;ibp<mxBTile;ibp++) {
121  for(int id=1;id<=mxBtow;id++) {
122  float adcL=5., adcH=40.; // default for _BTOW_
123  if(ibp==kBPrs) adcL=3.5; // BPRS
124  int statGain=(int)mipStat(ibp)->GetBinContent(id);
125  if(!statGain){ //valid gain
126  float mean=mipMean(ibp)->GetBinContent(id);
127  float sig=mipSig(ibp)->GetBinContent(id);
128  adcL=mean-sig;
129  adcH=mean+sig;
130  if(ibp==kBTow && adcL<5) adcL=5;
131  if(ibp==kBPrs && adcL<3.5) adcL=3.5;
132  if(adcH>2*mean) adcH=2*mean;
133  if(id%77==0)
134  printf("%s id=%4d MIP mean=%.1f sig=%.1f adcL=%.1f H=%.1f\n",core[ibp],id,mean,sig,adcL,adcH);
135 
136  }
137  cut_mipAdcL[ibp][id-1]=adcL;
138  cut_mipAdcH[ibp][id-1]=adcH;
139  } //Loop over tiles
140  } // Loop over B/P
141 
142  LOG_INFO<<Form("::InitRun() Load private DB, nBad BPRS=%.0f",janDb_bprsStat->GetEntries())<<endm;
143 
144  printf("WARN: tmp disable 2 BPRS & 1 tiles\n");
145  // tower 1075 is masked in getStat();
146 
147  janDb_bprsStat->SetBinContent(2821,99); // 2 channels overwritten by bug in mapping
148  janDb_bprsStat->SetBinContent(3781,99);
149 
150 
151  } // end of JAN-DB
152 
153 
154 #if 0
155  // test1 of BPRS mapping
156  int RDO;
157  int posInFiber;
158  int softId;
159  int PMTbox;
160  int wire;
161  int A_value;
162 
163  for(softId=650; softId<750;softId++) {
164  int newId;
165  mMappB->GetPsdRDO(softId, RDO, posInFiber);
166  mMappB->GetPsdId( RDO, posInFiber, newId,PMTbox,wire, A_value, true);
167  assert(newId==softId);
168  //printf("Bmap soft=%d rdo=%d posInFib=%d \n", softId,RDO,posInFiber);
169  }
170 
171  // test2 of BPRS mapping after my swaps
172  printf("JJJBprs softID rdo posInFib \n");
173 
174  for(softId=1; softId<=4800;softId++) {
175  mMappB->GetPsdRDO(softId, RDO, posInFiber);
176  int newId=(int)bprsReMap()->GetBinContent(softId);
177  // fix to known channels
178  if(newId==4525) { RDO=2; posInFiber=487; }
179  if(newId==4526) { RDO=2; posInFiber=507; }
180  printf("JJJBprs %4d %2d %4d \n", newId,RDO,posInFiber);
181  janDb_bprsSoft2Hard->SetBinContent(softId, RDO*5000 + posInFiber);
182  }
183 
184  // test3 of BBTOW mapping after my swaps
185  printf("JJJBtow softID rdo posInFib \n");
186  for(int softId=1; softId<=4800;softId++) {
187  int RDO;
188  int posInFiber;
189  mMappB->GetCrateFromTowerId(softId, RDO, posInFiber);
190  int newId=softId;
191  printf("JJJBtow %4d %2d %4d \n", newId,RDO,posInFiber);
192  }
193 #endif
194 
195  LOG_INFO<<Form("::InitRun() done")<<endm;
196  return StMaker::Init();
197 }
198 
199 
200 //____________________________________________________________
201 //____________________________________________________________
202 
204  LOG_INFO<<Form("::Make() ")<<endm;
205 
206 
207  return kStOK;
208 }
209 
210 //____________________________________________________________
211 //____________________________________________________________
212 
213 int StJanBarrelDbMaker::bprsCrate(int softID) {
214  assert(softID>0);
215  assert(softID<=mxBtow);
216  if(softID<=340 ) return 0; // PSD_1W
217  else if(softID<=1540 ) return 1; // PSD_19W
218  else if(softID<=2400 ) return 0; // PSD_1W
219  else if(softID<=2900 ) return 2; // PSD_1E
220  else if(softID<=4100 ) return 3; // PSD_20E
221  return 2; // PSD_1E
222 }
223 
224 
225 //____________________________________________________________
226 //____________________________________________________________
227 
228 float StJanBarrelDbMaker::pedTile(int ibp, int softID, int capID){
229  assert(softID>0 && softID<=mxBtow);
230  assert(capID>=0 && capID<mxBcap);
231 
232  float ped=-991;
233  int jBP=BTOW;
234  if(ibp==kBPrs)jBP=BPRS;
235 
236  float pedOfl,sigPedOfl;
237  mTables->getPedestal(jBP,softID,capID,pedOfl,sigPedOfl);
238 
239  ped=pedOfl;
240 
241  // overwtite STAR db for some cases
242  if(ibp==kBPrs && par_dbType==kJanDb)
243  ped=0.1*janDb_bprsPed2D->GetBinContent(softID,capID+1);
244 
245  return ped;
246 
247 }
248 
249 //____________________________________________________________
250 //____________________________________________________________
251 
252 float StJanBarrelDbMaker::sigPedTile(int ibp, int softID, int capID){
253 
254  assert(softID>0 && softID<=mxBtow);
255  assert(capID>=0 && capID<mxBcap);
256 
257  float sigPed=-991;
258  int jBP=BTOW;
259  if(ibp==kBPrs)jBP=BPRS;
260 
261  float pedOfl,sigPedOfl;
262  mTables->getPedestal(jBP,softID,capID,pedOfl,sigPedOfl);
263 
264  sigPed=sigPedOfl;
265 
266  // overwtite STAR db for some cases
267  if(ibp==kBPrs && par_dbType==kJanDb)
268  sigPed=0.1*janDb_bprsSigPed2D->GetBinContent(softID,capID+1);
269 
270 
271  return sigPed;
272 
273 }
274 
275 
276 //____________________________________________________________
277 //____________________________________________________________
278 
279 int StJanBarrelDbMaker::statTile(int ibp, int softID){
280 
281  assert(softID>0 && softID<=mxBtow);
282 
283  int jBP=BTOW;
284  if(ibp==kBPrs)jBP=BPRS;
285  int statOflPed;
286  mTables->getStatus(jBP, softID, statOflPed,"pedestal");
287  int stat=0;
288  if(statOflPed!=1) stat=1; // flip meanung of bad flag, i.e. Jan's convention
289 
290 
291  if(ibp==kBTow ){ // tmp
292  if( softID==1075) stat=1;
293  if( softID==2969) stat=1;
294  if( softID==3289) stat=1;
295  }
296 
297  // overwtite STAR db for some cases
298  if(ibp==kBPrs && par_dbType==kJanDb)
299  stat=(int)janDb_bprsStat->GetBinContent(softID);
300 
301  return stat;
302 
303 }
304 
305 
306 //____________________________________________________________________
307 //____________________________________________________________________
308 
309 void StJanBarrelDbMaker::initBprsGeometry(){
310  printf("\nggg BPRS geometry initialization\n");
311  // getEta(const Int_t softId, Float_t &eta)
312 
313  for( int id0=0; id0< mxBTetaBin; id0++) {
314  int id=id0+1;
315  float eta;
316  assert(mBprsGeom->getEta(id,eta)==0);
317  float eta2;
318  assert(mBtowGeom->getEta(id,eta2)==0);
319  printf("id=%d, BPRS eta=%f BTOW eta=%f\n",id,eta,eta2);
320  // printf("%f\n",eta);
321  }
322 }
323 
324 // $Log: StJanBarrelDbMaker.cxx,v $
325 // Revision 1.5 2010/04/15 19:13:30 mattheww
326 // fixed some future gcc issues
327 //
328 // Revision 1.4 2009/08/25 16:08:04 fine
329 // fix the compilation issues under SL5_64_bits gcc 4.3.2
330 //
331 // Revision 1.3 2009/04/17 18:44:43 mattheww
332 // fixed a bug in the last comment
333 //
334 // Revision 1.2 2009/02/04 20:33:32 ogrebeny
335 // Moved the EEMC database functionality from StEEmcDbMaker to StEEmcUtil/database. See ticket http://www.star.bnl.gov/rt2/Ticket/Display.html?id=1388
336 //
337 // Revision 1.1 2008/11/24 23:06:37 balewski
338 // start
339 //
340 
341  #if 0
342 //Some combination of these two methods:
343 
345 int GetPsdId(int RDO, int posInFiber, int &softId, int &PMTbox, int &wire, int &A_value, bool print=false) const;
346 
348 int GetPsdRDO(int softId, int &RDO, int &posInFiber) const;
349 
350 //I believe RDO == CRATE-1. I'm not sure how "wire" and "A_value" translate into "pixel" in the MAPMT. But these are the methods you want.
351 
352 //Adam
353 
354 #endif
355 
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.
int GetPsdRDO(int softId, int &RDO, int &posInFiber) const
Get PSD fiber and position from id.
int GetCrateFromTowerId(int softId, int &crate, int &sequence) const
Get crate number and position in crate for Software Id.
Definition: Stypes.h:40
void getStatus(Int_t det, Int_t softId, Int_t &status, const char *option="") const
Return status.
int GetPsdId(int RDO, int posInFiber, int &softId, bool print=false) const
Get PSD id.