StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
EemcTwMask.cxx
1 #include <cstdlib>
2 
3 #include <StMessMgr.h>
4 
5 #include "EemcTwMask.h"
6 
7 //--------------------------------------
8 EemcTwMask::EemcTwMask()
9  : txtH(0)
10  , nMask(0)
11 {
12 }
13 
14 //--------------------------------------
15 EemcTwMask::~EemcTwMask() {
16  if (txtH) delete txtH; txtH = 0;
17 }
18 
19 //--------------------------------------
20 void EemcTwMask::clear() {
21  for (int i = 0;i < nCr;i++) {
22  crG[i].Clear();
23  crG2[i].Clear();
24  }
25  phiG.Clear();
26  if (txtH) txtH->Clear();
27  nMask = 0;
28  memset(crCh, 0, sizeof(crCh));
29 }
30 
31 //--------------------------------------
32 bool useTwMask(const Char_t *fname, EemcTwMask *m) {
33  if (!(fname && fname[0] && m)) return false;
34  const int mx=1000;
35  Char_t buf[mx];
36 
37  LOG_INFO << "EEqaPresenter::useTwMask(\"" << fname << "\") ..." << endm;
38 
39  m->clear();
40  FILE *fd = fopen(fname, "r");
41  int nok = 0;
42  int nM = 1;
43  m->txtH = new TPaveText(0, 0., 1, 1);
44  TString myTxt = "ETOW masked (cr-ch-name): ";
45  if (!fd) goto abandon;
46  while (1) {
47  Char_t *ret = fgets(buf, mx, fd);
48  if (ret == 0) break ; //EOF
49  if (buf[0] == '#') continue; // skip comment
50  if (buf[0] == '\n') continue; // skip empty lines
51  Char_t name[100];
52  int cr, ch;
53  int sec, isub, jeta, jphi;
54  int n = sscanf(buf, "%d %d %s", &cr, &ch, name);
55  if (n != 3) goto abandon;
56  if ((cr < 1) || (cr > m->nCr) || (ch < 0) || (ch >= m->nCh)) goto abandon;
57  if (name[2] != 'T') goto abandon;
58  sec = atoi(name);
59  isub = name[3] - 'A';
60  jeta = atoi(name + 4);
61  jphi = (sec - 1) * 5 + isub;
62  // LOG_DEBUG << Form("%s sec=%d isub=%d jeta=%d, jphi=%d\n",name, sec,isub,jeta,jphi) << endm;
63 
64  m->crCh[cr-1][ch] = 1;
65  int jj = m->crG[cr - 1].GetN();
66  m->crG[cr - 1].SetPoint(jj, ch, 10);
67  m->crG2[cr - 1].SetPoint(jj, 250, ch);
68  m->crG2[cr - 1].SetPointError(jj, 250, 0.);
69 
70  jj = m->phiG.GetN();
71  m->phiG.SetPoint(jj, jphi, jeta);
72  TString tt = Form("%d-%d-%s, ", cr, ch, name);
73  myTxt += tt;
74  nok++;
75  nM++;
76  LOG_DEBUG << Form("mask ETOW cr=%d ch=%d =%s=",cr,ch,name) << endm;
77  if((nM % 4) == 0) {
78  m->txtH->AddText(myTxt);
79  myTxt=" ";
80  }
81  }
82  m->nMask = nok;
83  m->txtH->AddText(myTxt);
84  m->txtH->AddText("--");
85  LOG_INFO << " got " << nok << " masked towers" << endm;
86 
87  for (int i = 0;i < 6;i++){
88  m->crG[i].SetMarkerStyle(23);
89  m->crG[i].SetMarkerColor(kRed);
90  m->crG2[i].SetMarkerStyle(1);
91  m->crG2[i].SetLineColor(kRed);
92  }
93 
94  m->phiG.SetMarkerStyle(24);
95 
96  return true;
97 abandon: // any error has happened (this is a new approach for me, JB)
98  m->clear();
99  m->txtH->AddText("List of ETOW hot towers not found");
100  m->txtH->AddText("--");
101  LOG_ERROR << " EEqaPresenter::useTwMask() FAILED" << endm;
102  return false;
103 }