1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | #include <stdint.h> |
9 | #include <vector> |
10 | #include <deque> |
11 | #include <string> |
12 | #include <iostream> |
13 | #include <algorithm> |
14 | #include <stdio.h> |
15 | #include <stdlib.h> |
16 | |
17 | #include "JEventProcessor_EPICS_dump.h" |
18 | #include <JANA/JApplication.h> |
19 | |
20 | #include "DLorentzVector.h" |
21 | #include "TMatrixD.h" |
22 | |
23 | #include "BCAL/DBCALShower.h" |
24 | #include "BCAL/DBCALCluster.h" |
25 | #include "BCAL/DBCALPoint.h" |
26 | #include "BCAL/DBCALHit.h" |
27 | #include "FCAL/DFCALShower.h" |
28 | #include "FCAL/DFCALCluster.h" |
29 | #include "FCAL/DFCALHit.h" |
30 | #include "TRACKING/DMCThrown.h" |
31 | #include "ANALYSIS/DAnalysisUtilities.h" |
32 | #include "TRIGGER/DL1Trigger.h" |
33 | #include <DANA/DStatusBits.h> |
34 | #include "FCAL/DFCALGeometry.h" |
35 | #include "DAQ/DEPICSvalue.h" |
36 | #include "DAQ/DTSscalers.h" |
37 | |
38 | |
39 | using namespace std; |
40 | using namespace jana; |
41 | |
42 | |
43 | |
44 | #include <TDirectory.h> |
45 | #include <TH1.h> |
46 | |
47 | |
48 | |
49 | |
50 | static TH1I* h1epics_trgbits = NULL__null; |
51 | static TH1I* h1epics_AD00 = NULL__null; |
52 | static TH2I* h2epics_pos_inner = NULL__null; |
53 | static TH2I* h2epics_pos_outer = NULL__null; |
54 | Int_t const nscalers=32; |
55 | static TH1I* h1_trig_rates[nscalers]={NULL__null,NULL__null,NULL__null,NULL__null,NULL__null,NULL__null,NULL__null,NULL__null, |
56 | NULL__null,NULL__null,NULL__null,NULL__null,NULL__null,NULL__null,NULL__null,NULL__null, |
57 | NULL__null,NULL__null,NULL__null,NULL__null,NULL__null,NULL__null,NULL__null,NULL__null, |
58 | NULL__null,NULL__null,NULL__null,NULL__null,NULL__null,NULL__null,NULL__null,NULL__null}; |
59 | static TH1I* h1_trig_livetimes[nscalers]={NULL__null,NULL__null,NULL__null,NULL__null,NULL__null,NULL__null,NULL__null,NULL__null, |
60 | NULL__null,NULL__null,NULL__null,NULL__null,NULL__null,NULL__null,NULL__null,NULL__null, |
61 | NULL__null,NULL__null,NULL__null,NULL__null,NULL__null,NULL__null,NULL__null,NULL__null, |
62 | NULL__null,NULL__null,NULL__null,NULL__null,NULL__null,NULL__null,NULL__null,NULL__null}; |
63 | static TH1I* h1epics_liveinst = NULL__null; |
64 | static TH1F* h1epics_AD00_VSevent = NULL__null; |
65 | static TH1F* h1epics_entries1_VSevent = NULL__null;; |
66 | static TH1F* h1epics_entries2_VSevent = NULL__null; |
67 | static TH1F* h1epics_liveinst_VSevent = NULL__null; |
68 | |
69 | static uint64_t save_ntrig[nscalers]; |
70 | static uint64_t save_ntrig0[nscalers]; |
71 | static bool init_ntrig = false; |
72 | |
73 | |
74 | |
75 | |
76 | |
77 | |
78 | extern "C"{ |
79 | void InitPlugin(JApplication *locApplication){ |
80 | InitJANAPlugin(locApplication); |
81 | locApplication->AddProcessor(new JEventProcessor_EPICS_dump()); |
82 | } |
83 | } |
84 | |
85 | |
86 | |
87 | |
88 | |
89 | JEventProcessor_EPICS_dump::JEventProcessor_EPICS_dump() { |
90 | } |
91 | |
92 | |
93 | |
94 | |
95 | |
96 | JEventProcessor_EPICS_dump::~JEventProcessor_EPICS_dump() { |
97 | } |
98 | |
99 | |
100 | |
101 | |
102 | jerror_t JEventProcessor_EPICS_dump::init(void) { |
103 | |
104 | |
105 | |
106 | if(h1epics_trgbits != NULL__null){ |
107 | return NOERROR; |
108 | } |
109 | |
110 | |
111 | TDirectory *main = gDirectory(TDirectory::CurrentDirectory()); |
112 | gDirectory(TDirectory::CurrentDirectory())->mkdir("EPICS_dump")->cd(); |
113 | |
114 | |
115 | |
116 | int const nbins=100; |
117 | Int_t const nscalers=32; |
118 | char string[132]; |
119 | |
120 | h1epics_trgbits = new TH1I("h1epics_trgbits", "Trig Trgbits",80,0,80); |
121 | h1epics_trgbits->SetXTitle("trig_mask || (70+fp_trig_mask/256)"); |
122 | h1epics_trgbits->SetYTitle("counts"); |
123 | |
124 | for (Int_t j=0; j<nscalers;j++) { |
125 | sprintf (string,"Rates%d(kHz)",j); |
126 | h1_trig_rates[j] = new TH1I(string,string,nbins,0,100); |
127 | h1_trig_rates[j]->SetTitle(string); |
128 | sprintf (string,"Livetimes%d",j); |
129 | h1_trig_livetimes[j] = new TH1I(string,string,nbins,0,1); |
130 | h1_trig_livetimes[j]->SetTitle(string); |
131 | } |
132 | |
133 | h1epics_liveinst = new TH1I("h1epics_liveinst", "Liveinst",nbins,0,1); |
134 | h1epics_liveinst->SetXTitle("Instantaneous Live time"); |
135 | h1epics_liveinst->SetYTitle("counts"); |
136 | |
137 | h1epics_AD00 = new TH1I("h1epics_AD00", "Current AD00",nbins,0,500); |
138 | h1epics_AD00->SetXTitle("Current AD00 (nA)"); |
139 | h1epics_AD00->SetYTitle("counts"); |
140 | |
141 | h2epics_pos_inner = new TH2I("h1epics_pos_inner", "Position AC inner",nbins,-10,10,nbins,-10,10); |
142 | h2epics_pos_inner->SetXTitle("Position AC inner x (mm)"); |
143 | h2epics_pos_inner->SetYTitle("Position AC inner y (mm)"); |
144 | h2epics_pos_outer = new TH2I("h1epics_pos_outer", "Position AC outer",nbins,-20,20,nbins,-20,20); |
145 | h2epics_pos_outer->SetXTitle("Position AC outer x (mm)"); |
146 | h2epics_pos_outer->SetYTitle("Position AC outer y (mm)"); |
147 | |
148 | |
149 | h1epics_AD00_VSevent = new TH1F("h1epics_AD00_VSevent", "Current AD00 (nA)",200,0,2e6); |
150 | h1epics_AD00_VSevent->SetXTitle("Event number"); |
151 | h1epics_AD00_VSevent->SetYTitle("Current (nA)"); |
152 | h1epics_entries1_VSevent = new TH1F("h1epics_entries1_VSevent", "No synch events/bin",200,0,200e6); |
153 | h1epics_entries1_VSevent->SetXTitle("Event number"); |
154 | h1epics_entries1_VSevent->SetYTitle("No of synch events"); |
155 | h1epics_entries2_VSevent = new TH1F("h1epics_entries2_VSevent", "No epics events/bin",200,0,2e6); |
156 | h1epics_entries2_VSevent->SetXTitle("Event number"); |
157 | h1epics_entries2_VSevent->SetYTitle("No of synch events"); |
158 | h1epics_liveinst_VSevent = new TH1F("h1epics_liveinst_VSevent", "",200,0,200e6); |
159 | h1epics_liveinst_VSevent->SetXTitle("Event number"); |
160 | h1epics_liveinst_VSevent->SetYTitle("Live Time"); |
161 | |
162 | |
163 | |
164 | |
165 | main->cd(); |
166 | |
167 | |
168 | for (Int_t j=0; j<nscalers; j++) { |
169 | save_ntrig[j] = 0; |
170 | save_ntrig0[j] = 0; |
171 | } |
172 | |
173 | return NOERROR; |
174 | } |
175 | |
176 | |
177 | |
178 | |
179 | |
180 | jerror_t JEventProcessor_EPICS_dump::brun(jana::JEventLoop* locEventLoop, int locRunNumber) { |
181 | |
182 | return NOERROR; |
183 | } |
184 | |
185 | |
186 | |
187 | |
188 | |
189 | jerror_t JEventProcessor_EPICS_dump::evnt(jana::JEventLoop* locEventLoop, uint64_t locEventNumber) { |
190 | |
191 | |
192 | |
193 | |
194 | |
195 | |
196 | |
197 | vector<const DFCALShower*> locFCALShowers; |
198 | vector<const DBCALPoint*> bcalpoints; |
199 | vector<const DFCALHit*> fcalhits; |
200 | vector<const DFCALCluster*> locFCALClusters; |
201 | vector<const DEPICSvalue*> epicsvalues; |
202 | |
203 | |
204 | locEventLoop->Get(locFCALShowers); |
205 | locEventLoop->Get(bcalpoints); |
206 | locEventLoop->Get(fcalhits); |
207 | locEventLoop->Get(locFCALClusters); |
208 | locEventLoop->Get(epicsvalues); |
209 | DFCALGeometry fcalgeom; |
210 | Int_t const nscalers=32; |
211 | |
212 | bool isPhysics = locEventLoop->GetJEvent().GetStatusBit(kSTATUS_PHYSICS_EVENT); |
213 | bool isEPICS = locEventLoop->GetJEvent().GetStatusBit(kSTATUS_EPICS_EVENT); |
214 | |
215 | |
216 | |
217 | const DL1Trigger *trig_words = NULL__null; |
218 | |
219 | try { |
220 | locEventLoop->GetSingle(trig_words); |
221 | } catch(...) {}; |
222 | |
223 | |
224 | const DTSscalers *ts_scalers = NULL__null; |
225 | try { |
226 | locEventLoop->GetSingle(ts_scalers); |
227 | } catch(...) {}; |
228 | |
229 | |
230 | |
231 | japp->RootFillLock(this); |
232 | |
233 | uint32_t trig_mask=0, fp_trig_mask=0; |
234 | uint32_t temp_mask=0; |
235 | |
236 | if (isPhysics) { |
237 | |
238 | |
239 | if (trig_words) { |
240 | trig_mask = trig_words->trig_mask; |
241 | fp_trig_mask = trig_words->fp_trig_mask; |
242 | for (int j=0; j<nscalers; j++) { |
243 | temp_mask = trig_mask & 1<<j; |
244 | if (temp_mask && init_ntrig) save_ntrig[j] += 1; |
245 | } |
246 | } |
247 | else { |
248 | trig_mask = 0; |
249 | fp_trig_mask = 0; |
250 | } |
251 | |
252 | int trig_bits = fp_trig_mask > 0? 70 + fp_trig_mask/256: trig_mask; |
253 | if (fp_trig_mask>0) printf (" Event=%d trig_bits=%d trig_mask=%X fp_trig_mask=%X\n",(int)locEventNumber,trig_bits,trig_mask,fp_trig_mask); |
254 | |
255 | |
256 | |
257 | |
258 | |
259 | h1epics_trgbits->Fill(trig_bits); |
260 | |
261 | |
262 | |
263 | |
264 | uint32_t livetime; |
265 | uint32_t busytime; |
266 | uint32_t live_inst; |
267 | uint32_t timestamp; |
268 | |
269 | uint32_t gtp_sc[nscalers]; |
270 | |
271 | uint32_t gtp_rate[nscalers]; |
272 | |
273 | |
274 | if (ts_scalers) { |
275 | livetime = ts_scalers->live_time; |
276 | busytime = ts_scalers->busy_time; |
| Value stored to 'busytime' is never read |
277 | live_inst = ts_scalers->inst_livetime; |
278 | timestamp = ts_scalers->time; |
279 | h1epics_liveinst->Fill((float)live_inst/1000.); |
280 | h1epics_liveinst_VSevent->Fill((float)locEventNumber,(float)live_inst/1000.); |
281 | h1epics_entries1_VSevent->Fill((float)locEventNumber); |
282 | |
283 | if (! init_ntrig) { |
284 | for (int j=0; j<nscalers; j++) { |
285 | save_ntrig0[j] = ts_scalers->gtp_scalers[j]; |
286 | init_ntrig = true; |
287 | } |
288 | } |
289 | for (int j=0; j<nscalers; j++) { |
290 | gtp_sc[j] = ts_scalers->gtp_scalers[j] - save_ntrig0[j]; |
291 | gtp_rate[j] = ts_scalers->gtp_rate[j]; |
292 | |
293 | |
294 | h1_trig_rates[j]->Fill(gtp_rate[j]/1000); |
295 | if (gtp_sc[j] >0) { |
296 | h1_trig_livetimes[j]->Fill((float)save_ntrig[j]/(float)gtp_sc[j]); |
297 | save_ntrig0[j] = ts_scalers->gtp_scalers[j]; |
298 | save_ntrig[j] = 0; |
299 | } |
300 | } |
301 | } |
302 | } |
303 | else if (isEPICS) { |
304 | |
305 | |
306 | printf (" Event=%d is an EPICS record\n",(int)locEventNumber); |
307 | |
308 | |
309 | |
310 | |
311 | |
312 | float pos_default=-1000.; |
313 | float xpos_inner = pos_default; |
314 | float ypos_inner = pos_default;; |
315 | float xpos_outer = pos_default; |
316 | float ypos_outer = pos_default; |
317 | for(vector<const DEPICSvalue*>::const_iterator val_itr = epicsvalues.begin(); |
318 | val_itr != epicsvalues.end(); val_itr++) { |
319 | const DEPICSvalue* epics_val = *val_itr; |
320 | cout << "EPICS: " << epics_val->name << " = " << epics_val->sval << endl; |
321 | float fconv = atof(epics_val->sval.c_str()); |
322 | unsigned int iconv = atoi(epics_val->sval.c_str()); |
323 | bool isDigit = epics_val->name.length()> 12 && isdigit(epics_val->name[12]); |
324 | |
325 | if ((epics_val->name.substr(0,11) == "BCAL:pulser") & isdigit(epics_val->name[11])) { |
326 | val_itr++; |
327 | epics_val = *val_itr; |
328 | cout << "EPICS: " << epics_val->name << " = " << epics_val->sval << endl; |
329 | unsigned int iconv_low = atoi(epics_val->sval.c_str()); |
330 | |
331 | |
332 | iconv_low = iconv_low >> 31; |
333 | iconv = ((iconv <<1) & 0XFFFF) + iconv_low; |
334 | |
335 | printf ("BCAL:pulser status=%d, %0X, iconv_low=%0X\n",iconv,iconv,iconv_low); |
336 | } |
337 | else if ((epics_val->name.substr(0,11) == "BCAL:pulser") & isDigit) { |
338 | double freq = 1.e8/fconv; |
339 | cout << "BCAL:pulser=" << epics_val->name.substr(0,11) << epics_val->fval << " freq=" << freq <<endl; |
340 | } |
341 | else if (epics_val->name == "IBCAD00CRCUR6") { |
342 | h1epics_AD00->Fill(fconv); |
343 | h1epics_AD00_VSevent->Fill((float)locEventNumber,fconv); |
344 | h1epics_entries2_VSevent->Fill((float)locEventNumber); |
345 | cout << "IBCAD00CRCUR6 " << epics_val->name << " fconv=" << fconv << endl; |
346 | } |
347 | else if (epics_val->name == "AC:inner:position:x") { |
348 | xpos_inner = fconv; |
349 | } |
350 | else if (epics_val->name == "AC:inner:position:y") { |
351 | ypos_inner = fconv; |
352 | } |
353 | else if (epics_val->name == "AC:outer:position:x") { |
354 | xpos_outer = fconv; |
355 | } |
356 | else if (epics_val->name == "AC:outer:position:y") { |
357 | ypos_outer = fconv; |
358 | } |
359 | } |
360 | if (xpos_inner> pos_default && ypos_inner > pos_default) { |
361 | h2epics_pos_inner->Fill(xpos_inner,ypos_inner); |
362 | } |
363 | if (xpos_outer> pos_default && ypos_outer > pos_default) { |
364 | h2epics_pos_outer->Fill(xpos_outer,ypos_outer); |
365 | } |
366 | |
367 | } |
368 | |
369 | japp->RootFillUnLock(this); |
370 | |
371 | return NOERROR; |
372 | } |
373 | |
374 | |
375 | |
376 | |
377 | |
378 | jerror_t JEventProcessor_EPICS_dump::erun(void) { |
379 | |
380 | |
381 | |
382 | return NOERROR; |
383 | } |
384 | |
385 | |
386 | |
387 | |
388 | |
389 | jerror_t JEventProcessor_EPICS_dump::fini(void) { |
390 | |
391 | return NOERROR; |
392 | } |
393 | |
394 | |
395 | |
396 | |