StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StFgtDbFileMaker.cxx
1 //*-- Author : Renee Fatemi (UKY)
2 
3 
4 #include "StFgtDbFileMaker.h"
5 #include "TDataSetIter.h"
6 #include "StDAQMaker/StDAQReader.h"
7 #include "StFgtUtil/geometry/StFgtGeom.h"
8 
9 ClassImp(StFgtDbFileMaker)
10 
11 
12 StFgtDbFileMaker::StFgtDbFileMaker(const char *name):StMaker(name){
13 
14 }
15 
16 
17 StFgtDbFileMaker::~StFgtDbFileMaker(){
18 
19 }
20 
21 
22 Int_t StFgtDbFileMaker::Init(){
23 
24 
25  //initialize geoIds in array to -1
26  for (Int_t i = 0;i< 51200;i++){
27  mapping[i]=-1;
28  }
29  return StMaker::Init();
30 }
31 
32 
33 //_____________________________________________________________________________
36 
37  //printBigFgtGeomMap();
38  printRealDbMappingFile();
39 
40 
41  return kStOK;
42 }
43 
45  for (Int_t i = 0;i< 51200;i++){
46  cout<<i<<" "<< mapping[i]<<endl;
47  }
48  return kStOk;
49 }
50 
51 void StFgtDbFileMaker::printBigFgtGeomMap()
52 {
53 
54  for (rdo=1;rdo<3;rdo++){// 2 RDOs numbered 1,2
55  for (arm=0;arm<6;arm++){//6 arms numbered from 0
56  for (apv=0;apv<24;apv++){//24 APVs numbered 0-23 but in real life APV# 10,11,22,23 are unused so 0-19 in determining electronic Id
57  for (channel=0;channel<128;channel++){//128 channels numbered from 0
58 
59  if ((apv==10)||(apv==11)||(apv==22)||(apv==23)) continue;
60 
61  apvMod = apv;
62  if (apv > 11) apvMod = apv-2;
63 
64  geoId = geom->getNaiveGeoIdFromElecCoord(rdo,arm,apv,channel);
65  geom->decodeGeoId(geoId,disk,quad,layer,strip);
66  electId = getElectId(rdo,arm,apvMod,channel);
67  cout<<" geoId="<<geoId<<" electId="<<electId<<
68  " rdo="<<rdo<<" arm="<<arm<<" apv="<<apv<<" apvMod="<<apvMod<<" channel="<<channel<<
69  " disk="<<disk<<" quad="<<quad<<" layer="<<layer<<" strip="<<strip<<endl;
70  }
71  }
72  }
73  }
74 
75 }
76 
77 
78 void StFgtDbFileMaker::printIdealDbMappingFile(){
79 
80  for (rdo=1;rdo<3;rdo++){// 2 RDOs numbered 1,2
81  for (arm=0;arm<6;arm++){//6 arms numbered from 0
82  for (apv=0;apv<24;apv++){//24 APVs numbered 0-23 but in real life APV# 10,11,22,23 are unused so 0-19 in determining electronic Id
83  for (channel=0;channel<128;channel++){//128 channels numbered from 0
84 
85  if ((apv==10)||(apv==11)||(apv==22)||(apv==23)) continue;
86 
87  apvMod = apv;
88  if (apv > 11) apvMod = apv-2;
89 
90  geoId = geom->getNaiveGeoIdFromElecCoord(rdo,arm,apv,channel);
91  geom->decodeGeoId(geoId,disk,quad,layer,strip);
92  electId = getElectId(rdo,arm,apvMod,channel);
93  cout<<electId<<" "<<geoId<<endl;
94 
95  }
96  }
97  }
98  }
99 }
100 
101 void StFgtDbFileMaker::printRealDbMappingFile(){
102 
103  //in principle we could use the file provided by Ben Buck here:
104  //http://drupal.star.bnl.gov/STAR/system/files/APV%20Connection%20Map%20Simplified-DAQ%20perspectave_0.txt
105  //however this file has a different number of sig figs and is stored in mm instead of cm (as in StFgtGeom). So the input
106  //file above was opened in a spreadsheet and modified to have the same sigfig and units as those in StFgtGeom::mStrips
107 
108  ifstream f;
109  f.open("NewMappingFileMark2.txt");
110  if (!f) return;
111 
112  Int_t apv,ch,bs;
113  Double_t r,phi;
114  Char_t layer;
115  Int_t strip,stripId;
116  Int_t rdo,arm,group;
117  Int_t electronicID,geoId;
118 
119 
120  while (f>>ch>>apv>>bs>>r>>phi)
121  {
122 
123  //read in file and check it is correct
124  if (0) cout<<" ch = "<<ch<<" apv = "<<apv<<" bs="<<bs<<" r="<<r<<" phi="<<phi<<endl;
125 
126 
127  if (phi == -1) layer = 'R';
128  if (r == -1) layer = 'P';
129 
130  //loop over disk and quad to get strips (from StFgtGeom:mStrips[]) that correspond to this r,phi position
131  //Phi is unique but there are two identical r positions for each quadrant.
132  //Fortunately the r value is unique for APV group 0-4 and 5-9.
133  //GeoId is then constructed from disk,quad, layer and strip
134  //this geoId is then associated with the APV+ch that corresponds to the r,phi position from the original file
135  //The electronic ID is calculated by combining APV+ch with the RDO+ARM+APV_GROUP as defined in Ben's file:
136  //https://docs.google.com/spreadsheet/ccc?key=0Al3dLXZXg8e8dDBSSXplYndKWmNyQ2FkSmppYTNjR3c#gid=1
137 
138  for (int disk= 0; disk< 6; ++disk)
139  {
140  for (int quad = 0; quad<4; ++quad)
141  {
142 
143  if (apv < 5)
144  {
145  stripId = -1;
146  if (layer == 'P') stripId = searchPhiStripId(phi);
147  if (layer == 'R') stripId = searchRStripId_HighPhi(r);
148 
149  if (disk == 0)//disk1
150  {
151 
152  if (quad == 3) //this assumes D == 3!
153  {
154  rdo=2;
155  arm=0;
156  group = 1;
157  }
158 
159 
160  if (quad == 0) //this assumes A == 0!
161  {
162  rdo=1;
163  arm=0;
164  group = 0;
165  }
166 
167 
168  if (quad == 1) //this assumes B == 1!
169  {
170  rdo=1;
171  arm=0;
172  group = 1;
173  }
174 
175 
176  if (quad == 2) //this assumes C == 1!
177  {
178  rdo=2;
179  arm=0;
180  group = 0;
181  }
182 
183  }
184 
185  //disk 2
186  if (disk == 1)
187  {
188 
189  if (quad == 3) //this assumes D == 3!
190  {
191  continue;//no detector here
192  }
193 
194 
195  if (quad == 0) //this assumes A == 0!
196  {
197  rdo=1;
198  arm=1;
199  group = 0;
200 
201  }
202 
203 
204  if (quad == 1) //this assumes B == 1!
205  {
206  rdo=1;
207  arm=1;
208  group = 1;
209  }
210 
211 
212  if (quad == 2) //this assumes C == 1!
213  {
214  continue;//no detector here
215  }
216 
217  }
218 
219 
220  //disk 3
221  if (disk == 2)
222  {
223 
224  if (quad == 3) //this assumes D == 3!
225  {
226  continue;//no detector here
227  }
228 
229 
230  if (quad == 0) //this assumes A == 0!
231  {
232  rdo=2;
233  arm=1;
234  group = 1;
235  }
236 
237 
238  if (quad == 1) //this assumes B == 1!
239  {
240  rdo=1;
241  arm=2;
242  group = 0;
243  }
244 
245 
246  if (quad == 2) //this assumes C == 1!
247  {
248  continue;//no detector here
249  }
250 
251  }
252 
253  //disk 4
254  if (disk == 3)
255  {
256 
257  if (quad == 3) //this assumes D == 3!
258  {
259  continue;//no detector here
260  }
261 
262 
263  if (quad == 0) //this assumes A == 0!
264  {
265  rdo=2;
266  arm=2;
267  group = 0;
268  }
269 
270 
271  if (quad == 1) //this assumes B == 1!
272  {
273  rdo=2;
274  arm=2;
275  group = 1;
276  }
277 
278 
279  if (quad == 2) //this assumes C == 1!
280  {
281  continue;//no detector here
282  }
283 
284  }
285 
286 
287  //disk 5
288  if (disk == 4)
289  {
290 
291  if (quad == 3) //this assumes D == 3!
292  {
293  continue;//no detector here
294  }
295 
296 
297  if (quad == 0) //this assumes A == 0!
298  {
299  rdo=1;
300  arm=3;
301  group = 1;
302  }
303 
304 
305  if (quad == 1) //this assumes B == 1!
306  {
307  rdo=2;
308  arm=3;
309  group = 0;
310  }
311 
312 
313  if (quad == 2) //this assumes C == 1!
314  {
315  continue;//no detector here
316  }
317 
318  }
319 
320 
321  //disk 6
322  if (disk == 5)
323  {
324 
325  if (quad == 3) //this assumes D == 3!
326  {
327  continue;//no detector here
328  }
329 
330 
331  if (quad == 0) //this assumes A == 0!
332  {
333  rdo=1;
334  arm=4;
335  group = 0;
336  }
337 
338 
339  if (quad == 1) //this assumes B == 1!
340  {
341  rdo=1;
342  arm=4;
343  group = 1;
344  }
345 
346 
347  if (quad == 2) //this assumes C == 1!
348  {
349  continue;//no detector here
350  }
351 
352  }
353 
354  }
355  else
356  {
357 
358 
359  stripId = -1;
360  if (layer == 'P') stripId = searchPhiStripId(phi);
361  if (layer == 'R') stripId = searchRStripId_LowPhi(r);
362 
363  if (disk == 0)//disk1
364  {
365 
366  if (quad == 3) //this assumes D == 3!
367  {
368  rdo = 1;
369  arm = 0;
370  group = 0;
371  }
372 
373 
374  if (quad == 0) //this assumes A == 0!
375  {
376  rdo=1;
377  arm=0;
378  group = 1;
379  }
380 
381 
382  if (quad == 1) //this assumes B == 1!
383  {
384  rdo=2;
385  arm=0;
386  group = 0;
387  }
388 
389 
390  if (quad == 2) //this assumes C == 1!
391  {
392  rdo=2;
393  arm=0;
394  group = 1;
395  }
396 
397  }
398 
399  //disk 2
400  if (disk == 1)
401  {
402 
403  if (quad == 3) //this assumes D == 3!
404  {
405  continue;//no detector here
406  }
407 
408 
409  if (quad == 0) //this assumes A == 0!
410  {
411  rdo=1;
412  arm=1;
413  group = 1;
414  }
415 
416 
417  if (quad == 1) //this assumes B == 1!
418  {
419  rdo=2;
420  arm=1;
421  group = 0;
422  }
423 
424 
425  if (quad == 2) //this assumes C == 1!
426  {
427  continue;//no detector here
428  }
429 
430  }
431 
432 
433  //disk 3
434  if (disk == 2)
435  {
436 
437  if (quad == 3) //this assumes D == 3!
438  {
439  continue;//no detector here
440  }
441 
442 
443  if (quad == 0) //this assumes A == 0!
444  {
445  rdo=1;
446  arm=2;
447  group = 0;
448  }
449 
450 
451  if (quad == 1) //this assumes B == 1!
452  {
453  rdo=1;
454  arm=2;
455  group = 1;
456  }
457 
458 
459  if (quad == 2) //this assumes C == 1!
460  {
461  continue;//no detector here
462  }
463 
464  }
465 
466  //disk 4
467  if (disk == 3)
468  {
469 
470  if (quad == 3) //this assumes D == 3!
471  {
472  continue;//no detector here
473  }
474 
475 
476  if (quad == 0) //this assumes A == 0!
477  {
478  rdo=2;
479  arm=2;
480  group = 1;
481  }
482 
483 
484  if (quad == 1) //this assumes B == 1!
485  {
486  rdo=1;
487  arm=3;
488  group = 0;
489  }
490 
491 
492  if (quad == 2) //this assumes C == 1!
493  {
494  continue;//no detector here
495  }
496 
497  }
498 
499 
500  //disk 5
501  if (disk == 4)
502  {
503 
504  if (quad == 3) //this assumes D == 3!
505  {
506  continue;//no detector here
507  }
508 
509 
510  if (quad == 0) //this assumes A == 0!
511  {
512  rdo=2;
513  arm=3;
514  group = 0;
515  }
516 
517 
518  if (quad == 1) //this assumes B == 1!
519  {
520  rdo=2;
521  arm=3;
522  group = 1;
523  }
524 
525 
526  if (quad == 2) //this assumes C == 1!
527  {
528  continue;//no detector here
529  }
530 
531  }
532 
533 
534  //disk 6
535  if (disk == 5)
536  {
537 
538  if (quad == 3) //this assumes D == 3!
539  {
540  continue;//no detector here
541  }
542 
543 
544  if (quad == 0) //this assumes A == 0!
545  {
546  rdo=1;
547  arm=4;
548  group = 1;
549  }
550 
551 
552  if (quad == 1) //this assumes B == 1!
553  {
554  rdo=2;
555  arm=4;
556  group = 0;
557  }
558 
559 
560  if (quad == 2) //this assumes C == 1!
561  {
562  continue;//no detector here
563  }
564 
565  }
566  }
567 
568 
569  //strip = stripId % StFgtGeom::kNumFgtStripsPerLayer;
570  strip = stripId % kFgtNumStrips;
571  geoId= StFgtGeom::encodeGeoId(disk, quad,layer,strip);
572 
573  Int_t real_apv = group*12 + apv;
574  electronicID = StFgtGeom::encodeElectronicId(rdo,arm, real_apv,ch);
575 
576  mapping[electronicID]=geoId;
577 
578  if (1){
579  cout<<" rdo="<<rdo<<" arm="<<arm<<" apv ="<<apv<<" ch="<<ch<<" electId="<<
580  electronicID<<" disk="<<disk<<" quad="<<quad<<" layer="<<layer<<" strip="<<
581  strip<<" stripID="<<stripId<<" geoID="<<geoId<<endl;
582  }
583 
584  }
585  }
586  }
587 }
588 
589 
590 
591 Int_t StFgtDbFileMaker::searchRStripId_HighPhi(Double_t r)
592 {
593 
594  Int_t ii;
595 
596  assert(r!=0);
597 
598  for (ii = 0; ii < 280; ++ii)
599  {
600  if (r == StFgtGeom::mStrips[ii].ordinate) {
601  //cout<<" r="<<r<<" =? "<<StFgtGeom::mStrips[ii].ordinate<<endl;
602  break;
603  }
604  }
605 
606 
607  return ii;
608 }
609 
610 Int_t StFgtDbFileMaker::searchRStripId_LowPhi(Double_t r)
611 {
612 
613  Int_t ii;
614 
615  assert(r!=0);
616 
617  //kFgtNumStrips*2 used to be kNumStrips
618  for (ii = 400; ii < (kFgtNumStrips*2); ++ii)
619  {
620  if (r == StFgtGeom::mStrips[ii].ordinate) {
621  //cout<<" r="<<r<<" =? "<<StFgtGeom::mStrips[ii].ordinate<<endl;
622  break;
623  }
624  }
625 
626 
627  return ii;
628 }
629 
630 
631 Int_t StFgtDbFileMaker::searchPhiStripId(Double_t p)
632 {
633 
634  Int_t ii;
635 
636  assert(p!=-1);
637 
638  //kFgtNumStrips*2 used to be kNumStrips before change of consts and put into StFgtConsts.
639  for (ii = 0; ii < (2*kFgtNumStrips); ++ii)
640  {
641  if (p == StFgtGeom::mStrips[ii].ordinate){
642  //cout<<" p="<<p<<" =? "<<StFgtGeom::mStrips[ii].ordinate<<endl;
643  break;
644  }
645  }
646 
647  return ii;
648 }
649 
650 
651 Int_t StFgtDbFileMaker::getElectId(Int_t rdo, Int_t arm, Int_t apvMod, Int_t channel){
652 
653  Int_t eID = -1;
654  if ((rdo > 0)&&( rdo < 3)){
655  if ((arm >= 0)&&(arm < 6)){
656  if ((apvMod >= 0)&&(apvMod < 20)){
657  if ((channel >= 0)&&(channel < 128)){
658 
659  eID = channel + (128 * (apvMod + (20 * (arm + (6 * (rdo - 1))))));
660  }
661  }
662  }
663  }
664 
665  return eID;
666 }
virtual Int_t Finish()
Definition: Stypes.h:40
virtual Int_t Make()
Make - this method is called in loop for each event.
Definition: Stypes.h:41