StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StRHICfDbMaker.cxx
1 /***************************************************************************
2  * $Id: StRHICfDbMaker.cxx,v 1.37 2018/05/22 20:04:45 akio Exp $
3  * \author: Akio Ogawa, Minho Kim, Seunghwan Lee
4  ***************************************************************************
5  *
6  * Description: This maker is the interface between RHICf and the STAR database
7  *
8  ***************************************************************************
9  *
10  * $Log: StRHICfDbMaker.cxx,v $
11  *
12  ***************************************************************************/
13 
14 #include "StRHICfDbMaker.h"
15 #include "St_db_Maker/St_db_Maker.h"
16 #include "StMessMgr.h"
17 #include "tables/St_rhicfPedestal_Table.h"
18 #include "tables/St_rhicfPedestalF_Table.h"
19 #include "tables/St_rhicfGain_Table.h"
20 #include "tables/St_rhicfPlateRange_Table.h"
21 #include "tables/St_rhicfBarMap_Table.h"
22 #include "tables/St_rhicfBarPos_Table.h"
23 #include "tables/St_rhicfCrossTalk_Table.h"
24 
25 #include "tables/St_rhicfNeutronLeakageOut_Table.h"
26 #include "tables/St_rhicfPhotonLeakageOut_Table.h"
27 #include "tables/St_rhicfPhotonLeakageIn_Table.h"
28 
29 ClassImp(StRHICfDbMaker)
30 
31 StRHICfDbMaker::StRHICfDbMaker(const Char_t *name) : StMaker(name)
32 {
33 }
34 
35 StRHICfDbMaker::~StRHICfDbMaker()
36 {
37 }
38 
39 Int_t StRHICfDbMaker::Init()
40 {
41  return StMaker::Init();
42 }
43 
45 {
46  return kStOK;
47 }
48 
49 void StRHICfDbMaker::Clear(const Char_t*)
50 {
52 }
53 
55 {
56  return kStOK;
57 }
58 
59 Int_t StRHICfDbMaker::InitRun(Int_t runNumber)
60 {
62  if(mDebug>0) {
63  St_db_Maker* dbmaker = (St_db_Maker*)GetMaker("db");
64  LOG_INFO << "StRHICfDbMaker::InitRun - Date&time from St_db_Maker="<<dbmaker->GetDate()<<","<< dbmaker->GetTime() << endm;
65  }
66 
67  // Geometry DB
68  TDataSet *DBgeometry = 0;
69  DBgeometry = GetInputDB("Geometry/rhicf");
70  if(!DBgeometry){
71  LOG_ERROR << "StRHICfDbMaker::InitRun - No Geometry/rhicf"<<endm;
72  //return kStOK;
73  return kStFatal;
74  }
75 
76  // RHICf GSOBar mapping
77  St_rhicfBarMap *dbBarMap = 0;
78  dbBarMap = (St_rhicfBarMap*) DBgeometry->Find("rhicfBarMap");
79 
80  if(dbBarMap){
81  int mMaxBarMap = dbBarMap->GetNRows();
82  if(mMaxBarMap==1){
83  rhicfBarMap_st* barmap = (rhicfBarMap_st*) dbBarMap->GetTable();
84  mBarMap = new rhicfBarMap_st;
85  memcpy(mBarMap, barmap, sizeof(*barmap));
86  }
87  }
88 
89  // RHICf GSOBar position
90  St_rhicfBarPos *dbBarPos = 0;
91  dbBarPos = (St_rhicfBarPos*) DBgeometry->Find("rhicfBarPos");
92 
93  if(dbBarPos){
94  int mMaxBarPos = dbBarPos->GetNRows();
95  if(mMaxBarPos==1){
96  rhicfBarPos_st* barpos = (rhicfBarPos_st*) dbBarPos->GetTable();
97  mBarPos = new rhicfBarPos_st;
98  memcpy(mBarPos, barpos, sizeof(*barpos));
99  }
100  }
101 
102  // Calibration DB.
103  TDataSet *DBcalibrations = 0;
104  DBcalibrations = GetInputDB("Calibrations/rhicf");
105  if(!DBcalibrations){
106  LOG_ERROR << "StRHICfDbMaker::InitRun - No Calibrations/rhicf"<<endm;
107  return kStFatal;
108  }
109 
110  // RHICf plate ADC range
111  St_rhicfPlateRange * dbPlateRange = 0;
112  dbPlateRange = (St_rhicfPlateRange*) DBcalibrations -> Find("rhicfPlateRange");
113 
114  if(dbPlateRange){
115  int mMaxPlateRange = dbPlateRange->GetNRows();
116  if(mMaxPlateRange==1){
117  rhicfPlateRange_st* platerange = (rhicfPlateRange_st*) dbPlateRange->GetTable();
118  mPlateRange = new rhicfPlateRange_st;
119  memcpy(mPlateRange, platerange, sizeof(*platerange));
120  }
121  }
122 
123  // RHICf pedestal
124  St_rhicfPedestal* dbPedestal = 0;
125  dbPedestal = (St_rhicfPedestal*) DBcalibrations -> Find("rhicfPedestal");
126 
127  if(dbPedestal){
128  int mMaxPedestal = dbPedestal->GetNRows();
129  if(mMaxPedestal==1){
130  rhicfPedestal_st* pedestal = (rhicfPedestal_st*) dbPedestal->GetTable();
131  mPedestal = new rhicfPedestal_st;
132  memcpy(mPedestal, pedestal, sizeof(*pedestal));
133  }
134  }
135 
136  // RHICf pedestal float part
137  St_rhicfPedestalF* dbPedestalF = 0;
138  dbPedestalF = (St_rhicfPedestalF*) DBcalibrations -> Find("rhicfPedestalF");
139 
140  if(dbPedestalF){
141  int mMaxPedestal = dbPedestalF->GetNRows();
142  if(mMaxPedestal==1){
143  rhicfPedestalF_st* pedestalF = (rhicfPedestalF_st*) dbPedestalF->GetTable();
144  mPedestalF = new rhicfPedestalF_st;
145  memcpy(mPedestalF, pedestalF, sizeof(*pedestalF));
146  }
147  }
148 
149  // RHICf gain
150  St_rhicfGain* dbGain = 0;
151  dbGain = (St_rhicfGain*) DBcalibrations -> Find("rhicfGain");
152 
153  if(dbGain){
154  int mMaxGain = dbGain->GetNRows();
155  if(mMaxGain==1){
156  rhicfGain_st* gain = (rhicfGain_st*) dbGain->GetTable();
157  mGain = new rhicfGain_st;
158  memcpy(mGain, gain, sizeof(*gain));
159  }
160  }
161 
162  // RHICf crossTalk
163  St_rhicfCrossTalk* dbCrossTalk = 0;
164  dbCrossTalk = (St_rhicfCrossTalk*) DBcalibrations -> Find("rhicfCrossTalk");
165 
166  if(dbCrossTalk){
167  int mMaxCrossTalk = dbCrossTalk->GetNRows();
168  if(mMaxCrossTalk==1){
169  rhicfCrossTalk_st* crosstalk = (rhicfCrossTalk_st*) dbCrossTalk->GetTable();
170  mCrossTalk = new rhicfCrossTalk_st;
171  memcpy(mCrossTalk, crosstalk, sizeof(*crosstalk));
172  }
173  }
174 
175  // Leakage map DB.
176  h2_TSneuLeakOut = new TH2D("h2_TSneuLeakOut", "", 20, 0, 20, 20, 0, 20);
177  h2_TLneuLeakOut = new TH2D("h2_TLneuLeakOut", "", 40, 0, 40, 40, 0, 40);
178 
179  for(int i=0; i<15; i++){
180  h2_TSphoLeakOut[i] = new TH2D(Form("h2_TSphoLeakOut_%d", i), "", 20, 0, 20, 20, 0, 20);
181  h2_TLphoLeakOut[i] = new TH2D(Form("h2_TLphoLeakOut_%d", i), "", 40, 0, 40, 40, 0, 40);
182  h2_TSphoLeakIn[i] = new TH2D(Form("h2_TSphoLeakIn_%d", i), "", 20, 0, 20, 20, 0, 20);
183  h2_TLphoLeakIn[i] = new TH2D(Form("h2_TLphoLeakIn_%d", i), "", 40, 0, 40, 40, 0, 40);
184  }
185 
186  St_rhicfNeutronLeakageOut* dbNeutronLeakageOut = 0;
187  dbNeutronLeakageOut = (St_rhicfNeutronLeakageOut*) DBcalibrations -> Find("rhicfNeutronLeakageOut");
188 
189  if(dbNeutronLeakageOut){
190  int mMaxNeutronLeakageOut = dbNeutronLeakageOut->GetNRows();
191  if(mMaxNeutronLeakageOut==1){
192  rhicfNeutronLeakageOut_st* neuleakout = (rhicfNeutronLeakageOut_st*) dbNeutronLeakageOut->GetTable();
193  mNeutronLeakageOut = new rhicfNeutronLeakageOut_st;
194  memcpy(mNeutronLeakageOut, neuleakout, sizeof(*neuleakout));
195  }
196 
197  for(int ix=0; ix<20; ix++){
198  for(int iy=0; iy<20; iy++){
199  h2_TSneuLeakOut -> SetBinContent(ix+1, iy+1, mNeutronLeakageOut->smallplate[20*ix + iy]);
200  }
201  }
202 
203  for(int ix=0; ix<40; ix++){
204  for(int iy=0; iy<40; iy++){
205  h2_TLneuLeakOut -> SetBinContent(ix+1, iy+1, mNeutronLeakageOut->largeplate[40*ix + iy]);
206  }
207  }
208  }
209 
210  St_rhicfPhotonLeakageOut* dbPhotonLeakageOut = 0;
211  dbPhotonLeakageOut = (St_rhicfPhotonLeakageOut*) DBcalibrations -> Find("rhicfPhotonLeakageOut");
212 
213  if(dbPhotonLeakageOut){
214  int mMaxPhotonLeakageOut = dbPhotonLeakageOut->GetNRows();
215  if(mMaxPhotonLeakageOut==1){
216  rhicfPhotonLeakageOut_st* pholeakout = (rhicfPhotonLeakageOut_st*) dbPhotonLeakageOut->GetTable();
217  mPhotonLeakageOut = new rhicfPhotonLeakageOut_st;
218  memcpy(mPhotonLeakageOut, pholeakout, sizeof(*pholeakout));
219  }
220 
221  for(int il=0; il<15; il++){
222  for(int ix=0; ix<20; ix++){
223  for(int iy=0; iy<20; iy++){
224  h2_TSphoLeakOut[il] -> SetBinContent(ix+1, iy+1, mPhotonLeakageOut->smallplate[400*il + 20*ix + iy]);
225  }
226  }
227 
228  for(int ix=0; ix<40; ix++){
229  for(int iy=0; iy<40; iy++){
230  h2_TLphoLeakOut[il] -> SetBinContent(ix+1, iy+1, mPhotonLeakageOut->largeplate[1600*il + 40*ix + iy]);
231  }
232  }
233  }
234  }
235 
236  St_rhicfPhotonLeakageIn* dbPhotonLeakageIn = 0;
237  dbPhotonLeakageIn = (St_rhicfPhotonLeakageIn*) DBcalibrations -> Find("rhicfPhotonLeakageIn");
238 
239  if(dbPhotonLeakageIn){
240  int mMaxPhotonLeakageIn = dbPhotonLeakageIn->GetNRows();
241  if(mMaxPhotonLeakageIn==1){
242  rhicfPhotonLeakageIn_st* pholeakin = (rhicfPhotonLeakageIn_st*) dbPhotonLeakageIn->GetTable();
243  mPhotonLeakageIn = new rhicfPhotonLeakageIn_st;
244  memcpy(mPhotonLeakageIn, pholeakin, sizeof(*pholeakin));
245  }
246 
247  for(int il=0; il<15; il++){
248  for(int ix=0; ix<20; ix++){
249  for(int iy=0; iy<20; iy++){
250  h2_TSphoLeakIn[il] -> SetBinContent(ix+1, iy+1, mPhotonLeakageIn->smallplate[400*il + 20*ix + iy]);
251  }
252  }
253 
254  for(int ix=0; ix<40; ix++){
255  for(int iy=0; iy<40; iy++){
256  h2_TLphoLeakIn[il] -> SetBinContent(ix+1, iy+1, mPhotonLeakageIn->largeplate[1600*il + 40*ix + iy]);
257  }
258  }
259  }
260  }
261  return kStOK;
262 }
263 
264 //=========== Address ===========//
265 unsigned int StRHICfDbMaker::getRHICfRunNumberAddress() const {return 0;}
266 unsigned int StRHICfDbMaker::getRHICfEventNumberAddress() const {return 1;}
267 unsigned int StRHICfDbMaker::getRunTRGMAddress() const {return 4;}
268 unsigned int StRHICfDbMaker::getTriggerAddress() const {return 623;}
269 unsigned int StRHICfDbMaker::getBunchNumberAddress() const {return 649;}
270 unsigned int StRHICfDbMaker::getRunTimeAddress(unsigned int idx) const {return 2+idx;}
271 unsigned int StRHICfDbMaker::getTDCAddress(unsigned int idx) const {return 367+idx;}
272 unsigned int StRHICfDbMaker::getCAD0Address(unsigned int idx) const {return 101+idx;}
273 unsigned int StRHICfDbMaker::getGPI0Address(unsigned int idx) const {return 623+idx;}
274 unsigned int StRHICfDbMaker::getGPI1Address(unsigned int idx) const {return 642+idx;}
275 
276 unsigned int StRHICfDbMaker::getAdcAddress(unsigned int tower, unsigned int plate, unsigned int range) const
277 {
278  if(tower==0){
279  return 10+2*plate+(1-range);
280  }
281  if(tower==1){
282  return 74+2*plate+(1-range);
283  }
284  return kStFatal;
285 }
286 
287 unsigned int StRHICfDbMaker::getAdcDAddress(unsigned int tower, unsigned int plate, unsigned int range) const
288 {
289  if(tower==0){
290  return 42+2*plate+(1-range);
291  }
292  if(tower==1){
293  return 106+2*plate+(1-range);
294  }
295  return kStFatal;
296 }
297 
298 unsigned short StRHICfDbMaker::getScifiAddress(unsigned int tower, unsigned int layer, unsigned xy, unsigned pos) const
299 {
300  if(mBarMap){
301  if(tower==0) return 222 + mBarMap->smallbar[40*layer + 20*xy + pos];
302  if(tower==1) return 222 + mBarMap->largebar[80*layer + 40*xy + pos];
303  }
304  return kStFatal;
305 }
306 
307 //=========== Table values ===========//
308 Float_t StRHICfDbMaker::getPlatePedestal(unsigned int tower, unsigned int plate) const
309 {
310  if(mPedestal) return mPedestal->plate[16*tower + plate];
311  return kStFatal;
312 }
313 
314 Float_t StRHICfDbMaker::getBarPedestal(unsigned int tower, unsigned int layer, unsigned int xy, unsigned int pos) const
315 {
316  if(mPedestal){
317  if(tower==0) return mPedestal->smallbar[40*layer + 20*xy + pos];
318  if(tower==1) return mPedestal->largebar[80*layer + 40*xy + pos];
319  }
320  return kStFatal;
321 }
322 
323 Float_t StRHICfDbMaker::getBarPedestalF(unsigned int tower, unsigned int layer, unsigned int xy, unsigned int pos) const
324 {
325  if(mPedestalF){
326  if(tower==0) return mPedestalF->smallbar[40*layer + 20*xy + pos];
327  if(tower==1) return mPedestalF->largebar[80*layer + 40*xy + pos];
328  }
329  return kStFatal;
330 }
331 
332 Float_t StRHICfDbMaker::getPlateGain(unsigned int tower, unsigned int plate) const
333 {
334  if(mGain) return mGain->plate[16*tower + plate];
335  return kStFatal;
336 }
337 
338 Float_t StRHICfDbMaker::getBarGain(unsigned int tower, unsigned int layer, unsigned int xy, unsigned int pos) const
339 {
340  if(mGain){
341  if(tower==0) return mGain->smallbar[40*layer + 20*xy + pos];
342  if(tower==1) return mGain->largebar[80*layer + 40*xy + pos];
343  }
344  return kStFatal;
345 }
346 
347 Float_t StRHICfDbMaker::getPlateRangePar(unsigned int tower, unsigned int plate, unsigned int parnum) const
348 {
349  if(mPlateRange) return mPlateRange->plate[32*tower + 2*plate + parnum];
350  return kStFatal;
351 }
352 
353 Float_t StRHICfDbMaker::getBarPos(unsigned int tower, unsigned int layer, unsigned xy, unsigned pos) const
354 {
355  if(mBarPos){
356  if(tower==0) return mBarPos->smallbar[40*layer + 20*xy + pos];
357  if(tower==1) return mBarPos->largebar[80*layer + 40*xy + pos];
358  }
359  return kStFatal;
360 }
361 
362 Float_t StRHICfDbMaker::getCrossTalk(unsigned int i, unsigned int j) const
363 {
364  if(mCrossTalk){
365  if((i < 20 && j >= 20) || (i >= 20 && j < 20)){return 0.;}
366 
367  unsigned short tmpI = i;
368  unsigned short tmpJ = j;
369 
370  if(i >= 20){
371  tmpI -= 20;
372  tmpJ -= 20;
373  }
374 
375  if(i<j){
376  unsigned short tmp = tmpI;
377  tmpI = tmpJ;
378  tmpJ = tmp;
379  }
380 
381  unsigned short index = 0;
382  for(unsigned short sum=0; sum<=tmpI; sum++){index += sum;}
383  index += tmpJ;
384 
385  if(i < 20){return mCrossTalk->crossTalk[index];}
386  if(i >= 20){return mCrossTalk->crossTalk[210 + index];}
387  }
388  return kStFatal;
389 }
390 
391 TH2D* StRHICfDbMaker::getLeakOutNeutron(unsigned int tower)
392 {
393  if(tower==0){return h2_TSneuLeakOut;}
394  if(tower==1){return h2_TLneuLeakOut;}
395  return 0;
396 }
397 
398 TH2D* StRHICfDbMaker::getLeakOutPhoton(unsigned int tower, unsigned int plate)
399 {
400  if(plate==15){plate = 14;} // LeakageOut data range [0 ~ 14] in Db
401  if(tower==0){return h2_TSphoLeakOut[plate];}
402  if(tower==1){return h2_TLphoLeakOut[plate];}
403  return 0;
404 }
405 
406 TH2D* StRHICfDbMaker::getLeakInPhoton(unsigned int tower, unsigned int plate)
407 {
408  if(plate==15){plate = 14;} // LeakageIn data range [0 ~ 14] in Db
409  if(tower==0){return h2_TSphoLeakIn[plate];}
410  if(tower==1){return h2_TLphoLeakIn[plate];}
411  return 0;
412 }
virtual void Clear(Option_t *option="")
User defined functions.
Definition: StMaker.cxx:634
Definition: Stypes.h:40
virtual Int_t InitRun(Int_t runNumber)
virtual Int_t Make()
virtual Int_t Finish()
virtual TDataSet * Find(const char *path) const
Definition: TDataSet.cxx:362