Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
InttMon.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file InttMon.cc
1 #include "InttMon.h"
2 
3 //=== Public Methods ===//
5 {
6  //leaving fairly empty
7  return;
8 }
9 
11 {
12  delete dbvars;
13 }
14 
16 {
18 
19  //dbvars
20  dbvars = new OnlMonDB(ThisName);
21  DBVarInit();
22 
23  //histograms
24  NumEvents = new TH1D(Form("InttNumEvents"), Form("InttNumEvents"), 1, 0, 1);
25  HitMap = new TH1D(Form("InttMap"), Form("InttMap"), INTT::ADCS, 0, INTT::ADCS);
26  //...
27 
28  omc->registerHisto(this, NumEvents);
29  omc->registerHisto(this, HitMap);
30  //...
31 
32  //Read in calibrartion data from InttMonData.dat
33  const char *inttcalib = getenv("INTTCALIB");
34  if (!inttcalib)
35  {
36  std::cout << "INTTCALIB environment variable not set" << std::endl;
37  exit(1);
38  }
39  std::string fullfile = std::string(inttcalib) + "/" + "InttMonData.dat";
40  std::ifstream calib(fullfile);
41  //probably need to do stuff here (maybe write to expectation maps)
42  //or reimplment in BeginRun()
43  calib.close();
44 
45  // for testing/debugging without unpacker, remove later
46  rng = new TRandom(1234);
47  //~for testing/debugging without unpacker, remove later
48 
49  Reset();
50 
51  return 0;
52 }
53 
54 int InttMon::BeginRun(const int /* run_num */)
55 {
56  //per-run calibrations; don't think we need to do anything here yet
57 
58  return 0;
59 }
60 
62 {
63  int bin;
64  int N;
65  int n;
66 
67  int pid = 3001;
68  int felix;
69  int felix_channel;
70  struct INTT_Felix::Ladder_s lddr_s;
71 
72  struct INTT::Indexes_s indexes;
73 
74  for(pid = 3001; pid < 3009; ++pid)
75  {
76  felix = pid - 3001;
77 
78  Packet* p = evt->getPacket(pid);
79  if(!p)continue;
80 
81  N = p->iValue(0, "NR_HITS");
82 
83  //p->identify();
84  //if(N)std::cout << N << std::endl;
85 
86  for(n = 0; n < N; ++n)
87  {
88  felix_channel = p->iValue(n, "FEE");
89 
90  INTT_Felix::FelixMap(felix, felix_channel, lddr_s);
91 
92  indexes.lyr = lddr_s.barrel * 2 + lddr_s.layer;
93  indexes.ldr = lddr_s.ladder;
94 
95  indexes.arm = (felix / 4) % 2;
96  indexes.chp = p->iValue(n, "CHIP_ID") % 26;
97  indexes.chn = p->iValue(n, "CHANNEL_ID");
98  indexes.adc = p->iValue(n, "ADC");
99 
100  //std::cout << "\t" << indexes.lyr << std::endl;
101  //std::cout << "\t" << indexes.ldr << std::endl;
102  //std::cout << "\t" << indexes.arm << std::endl;
103  //std::cout << "\t" << indexes.chp << std::endl;
104  //std::cout << "\t" << indexes.chn << std::endl;
105  //std::cout << std::endl;
106 
107  INTT::GetFelixBinFromIndexes(bin, felix_channel, indexes);
108  if(bin < 0)
109  {
110  std::cout << "n: " << n << std::endl;
111  std::cout << "bin: " << bin << std::endl;
112  std::cout << "lyr: " << indexes.lyr << std::endl;
113  std::cout << "ldr: " << indexes.ldr << std::endl;
114  std::cout << "arm: " << indexes.arm << std::endl;
115  std::cout << "chp: " << indexes.chp << std::endl;
116  std::cout << "chn: " << indexes.chn << std::endl;
117  std::cout << "adc: " << indexes.adc << std::endl;
118 
119  break;
120  }
121  HitMap->AddBinContent(bin);
122  }
123 
124  delete p;
125  }
126 
127  NumEvents->AddBinContent(1);
128 
129  DBVarUpdate();
130 
131  return 0;
132 }
133 
135 {
136  //reset our DBVars
137  evtcnt = 0;
138 
139  //clear our histogram entries
140  NumEvents->Reset();
141  HitMap->Reset();
142 
143  return 0;
144 }
145 //=== ~Public Methods ===//
146 
147 //=== Private Methods ===//
149 {
150  std::string var_name;
151 
152  var_name = "intt_evtcnt";
153  dbvars->registerVar(var_name);
154 
155  dbvars->DBInit();
156 
157  return 0;
158 }
159 
161 {
162  dbvars->SetVar("intt_evtcnt", (float)evtcnt, 0.1 * evtcnt, (float)evtcnt);
163 
164  return 0;
165 }
166 //=== ~Private Methods ===//
167 
168 // for testing/debugging
169 void InttMon::RandomEvent(int felix)
170 {
171  int bin;
172 
173  int felix_channel;
174  struct INTT::Indexes_s indexes;
175  struct INTT_Felix::Ladder_s ldr_struct;
176 
177  int hits = rng->Poisson(16);
178  for(int hit = 0; hit < hits; ++hit)
179  {
180  felix_channel = rng->Uniform(INTT::FELIX_CHANNEL);
181  if(felix_channel == INTT::FELIX_CHANNEL)felix_channel -= 1;
182 
183  INTT_Felix::FelixMap(felix, felix_channel, ldr_struct);
184  indexes.lyr = 2 * ldr_struct.barrel + ldr_struct.layer;
185  indexes.ldr = ldr_struct.ladder;
186  indexes.arm = felix / 4;
187 
188  indexes.chp = rng->Uniform(INTT::CHIP);
189  if(indexes.chp == INTT::CHIP)indexes.chp -= 1;
190 
191  indexes.chn = rng->Uniform(INTT::CHANNEL);
192  if(indexes.chn == INTT::CHANNEL)indexes.chn -= 1;
193 
194  indexes.adc = rng->Uniform(INTT::ADC);
195  if(indexes.adc == INTT::ADC)indexes.adc -= 1;
196 
197  INTT::GetFelixBinFromIndexes(bin, felix_channel, indexes);
198  HitMap->SetBinContent(bin, HitMap->GetBinContent(bin) + 1);
199  NumEvents->AddBinContent(1);
200 
201  printf("Layer:%2d\tLadder:%3d (%s)\tChip:%3d\tChannel:%4d\n", indexes.lyr, indexes.ldr, indexes.arm ? "North" : "South", indexes.chp, indexes.chn);
202  }
203 }
204 
206 {
207  int b = 0;
208  int c = -1;
209 
210  int felix_channel = 0;
211  int gelix_channel = -1;
212 
213  struct INTT::Indexes_s indexes = (struct INTT::Indexes_s){.lyr = 0, .ldr = 0, .arm = 0, .chp = 0, .chn = 0, .adc = 0};
214  struct INTT::Indexes_s jndexes = (struct INTT::Indexes_s){.lyr = -1, .ldr = -1, .arm = -1, .chp = -1, .chn = -1, .adc = -1};
215 
216  while(true)
217  {
218  INTT::GetFelixBinFromIndexes(b, felix_channel, indexes);
219  INTT::GetFelixIndexesFromBin(b, gelix_channel, jndexes);
220  INTT::GetFelixBinFromIndexes(c, gelix_channel, jndexes);
221 
222  if(b != c)
223  {
224  std::cout << "Round trip failed" << std::endl;
225  std::cout << "bin: " << b << " -> " << c << std::endl;
226  std::cout << "felix_channel: " << felix_channel << " -> " << gelix_channel << std::endl;
227  std::cout << "chp: " << indexes.chp << " -> " << jndexes.chp << std::endl;
228  std::cout << "chn: " << indexes.chn << " -> " << jndexes.chn << std::endl;
229  std::cout << "adc: " << indexes.adc << " -> " << jndexes.adc << std::endl;
230 
231  return 0;
232  }
233 
234  ++indexes.adc;
235  if(indexes.adc < INTT::ADC)continue;
236  indexes.adc = 0;
237 
238  ++indexes.chn;
239  if(indexes.chn < INTT::CHANNEL)continue;
240  indexes.chn = 0;
241 
242  ++indexes.chp;
243  if(indexes.chp < INTT::CHIP)continue;
244  indexes.chp = 0;
245 
246  ++felix_channel;
247  if(felix_channel < INTT::FELIX_CHANNEL)continue;
248 
249  break;
250  }
251 
252  std::cout << "Felix Round trip worked" << std::endl;
253 
254  return 0;
255 }
256 
257