Bug Summary

File:plugins/Calibration/TOF_calib/JEventProcessor_TOF_calib.cc
Location:line 311, column 3
Description:Value stored to 'firsttime' is never read

Annotated Source Code

1// $Id$
2//
3// File: JEventProcessor_TOF_calib.cc
4// Created: Fri Mar 13 10:37:27 EDT 2015
5// Creator: zihlmann (on Linux gluon47.jlab.org 2.6.32-358.23.2.el6.x86_64 x86_64)
6//
7
8#include "JEventProcessor_TOF_calib.h"
9using namespace jana;
10
11// Routine used to create our JEventProcessor
12#include <JANA/JApplication.h>
13#include <JANA/JFactory.h>
14extern "C"{
15 void InitPlugin(JApplication *app){
16 InitJANAPlugin(app);
17 app->AddProcessor(new JEventProcessor_TOF_calib());
18 }
19} // "C"
20
21
22//------------------
23// JEventProcessor_TOF_calib (Constructor)
24//------------------
25JEventProcessor_TOF_calib::JEventProcessor_TOF_calib()
26{
27
28}
29
30//------------------
31// ~JEventProcessor_TOF_calib (Destructor)
32//------------------
33JEventProcessor_TOF_calib::~JEventProcessor_TOF_calib()
34{
35
36}
37
38//------------------
39// init
40//------------------
41jerror_t JEventProcessor_TOF_calib::init(void)
42{
43 // This is called once at program startup. If you are creating
44 // and filling historgrams in this plugin, you should lock the
45 // ROOT mutex like this:
46 //
47 // japp->RootWriteLock();
48 // ... fill historgrams or trees ...
49 // japp->RootUnLock();
50 //
51
52 cout<<"INITIALIZE VARIABLES "<<flush<<endl;
53
54 pthread_mutex_init(&mutex, NULL__null);
55
56 //BINTDC_2_TIME = 0.025;
57 BINTDC_2_TIME = 0.0234375;
58 BINADC_2_TIME = 0.0625; // is 4ns/64
59
60 TDCTLOC = 419.;
61 ADCTLOC = 190.;
62
63 ADCTimeCut = 50.;
64 TDCTimeCut = 60.;
65
66 first = 1;
67 MakeHistograms();
68
69 return NOERROR;
70}
71
72//------------------
73// brun
74//------------------
75jerror_t JEventProcessor_TOF_calib::brun(JEventLoop *eventLoop, int32_t runnumber)
76{
77 // This is called whenever the run number changes
78
79 RunNumber = runnumber;
80
81
82
83 if (first){
84 cout<<"SETUP HISTOGRAMS AND TREE FOR RUN IN brun()"<<RunNumber<<flush<<endl;
85 MakeHistograms();
86 }
87 map<string,double> tdcshift;
88 if (!eventLoop->GetCalib("/TOF/tdc_shift", tdcshift)){
89 TOF_TDC_SHIFT = tdcshift["TOF_TDC_SHIFT"];
90 }
91
92 return NOERROR;
93}
94
95//------------------
96// evnt
97//------------------
98jerror_t JEventProcessor_TOF_calib::evnt(JEventLoop *loop, uint64_t eventnumber)
99{
100 // This is called for every event. Use of common resources like writing
101 // to a file or filling a histogram should be mutex protected. Using
102 // loop->Get(...) to get reconstructed objects (and thereby activating the
103 // reconstruction algorithm) should be done outside of any mutex lock
104 // since multiple threads may call this method at the same time.
105 // Here's an example:
106 //
107 // vector<const MyDataClass*> mydataclasses;
108 // loop->Get(mydataclasses);
109 //
110 // japp->RootWriteLock();
111 // ... fill historgrams or trees ...
112 // japp->RootUnLock();
113
114
115 //cout<<"CALL EVENT ROUTINE!!!! "<<eventnumber<<endl;
116 if (first){
117 MakeHistograms();
118 }
119
120
121 // Get First Trigger Type
122 const DL1Trigger *trig_words = NULL__null;
123 uint32_t trig_mask, fp_trig_mask;
124 try {
125 loop->GetSingle(trig_words);
126 } catch(...) {};
127 if (trig_words) {
128 trig_mask = trig_words->trig_mask;
129 fp_trig_mask = trig_words->fp_trig_mask;
130 }
131 else {
132 trig_mask = 0;
133 fp_trig_mask = 0;
134 }
135
136
137 /* fp_trig_mask & 0x100 - upstream LED
138 fp_trig_mask & 0x200 - downstream LED
139 trig_mask & 0x1 - cosmic trigger*/
140
141 if (fp_trig_mask){ // this is a front pannel trigger like LED
142 return NOERROR;
143 }
144 if (trig_mask>7){ // this is not a BCAL/FCAL trigger
145 return NOERROR;
146 }
147
148 vector<const DCODAEventInfo*> locCODAEventInfo;
149 loop->Get(locCODAEventInfo);
150
151 if (locCODAEventInfo.size() == 0){
152 return NOERROR;
153 }
154
155 uint64_t TriggerTime = locCODAEventInfo[0]->avg_timestamp;
156 int TriggerBIT = TriggerTime%6;
157 float TimingShift = TOF_TDC_SHIFT - (float)TriggerBIT;
158 if(TimingShift <= 0) {
159 TimingShift += 6.;
160 }
161
162 TimingShift *= 4. ;
163
164 vector<const DTOFDigiHit*> ADCHits, ADCHitsLeft[2],ADCHitsRight[2];
165 vector<const DTOFTDCDigiHit*> TDCHits, TDCHitsLeft[2], TDCHitsRight[2];
166 vector<int> ADCLeftOverFlow[2],ADCRightOverFlow[2];
167
168 loop->Get(ADCHits);
169 loop->Get(TDCHits);
170
171 // loop over DTOFDigiHit: this are ADC hits
172 // sort them into ADCLeft and ADCRight hits
173 // only keep hits within the time-peak
174 // also keep the hodoscope planes separate
175 for (unsigned int k=0; k<ADCHits.size(); k++){
176 const DTOFDigiHit *hit = ADCHits[k];
177 int plane = hit->plane;
178 int end = hit->end;
179 float time = (float)hit->pulse_time * BINADC_2_TIME;
180 int val = (hit->pulse_time & 0x3F);
181
182 if (!val){
183 continue;
184 }
185
186 TOFADCtime->Fill(time);
187 if (fabsf(time-ADCTLOC)<ADCTimeCut){
188 // test for overflow if raw data available
189 vector <const Df250PulseIntegral*> PulseIntegral;
190 hit->Get(PulseIntegral);
191 vector <const Df250WindowRawData*> WRawData;
192 PulseIntegral[0]->Get(WRawData);
193 int overflow = 0;
194 if ( WRawData.size() > 0) {
195 for (int n=0;n<100;n++){
196 if (WRawData[0]->samples[n] & 0x1000){
197 overflow++;
198 }
199 }
200 } else {
201 //overflow = PulseIntegral[0]->quality_factor;
202 }
203
204 if (end){
205 ADCHitsRight[plane].push_back(hit);
206 ADCRightOverFlow[plane].push_back(overflow);
207 } else {
208 ADCHitsLeft[plane].push_back(hit);
209 ADCLeftOverFlow[plane].push_back(overflow);
210 }
211 }
212 }
213
214 if (ADCLeftOverFlow[0].size() != ADCHitsLeft[0].size()){
215 cout<<"Error vector size missmatch!"<<endl;
216 }
217
218
219 // loop over DTOFTDCDigiHits : these are the TDC hits
220 // sort them into left and right hits
221 // only keep hits within the time peak
222 // also keep the hodoscope planes separate
223 for (unsigned int k=0; k<TDCHits.size(); k++){
224 const DTOFTDCDigiHit *hit = TDCHits[k];
225 int plane = hit->plane;
226 int end = hit->end;
227 float time = (float)hit->time * BINTDC_2_TIME;
228 TOFTDCtime->Fill(time);
229 if (fabsf(time-TDCTLOC)<TDCTimeCut){
230 if (end){
231 TDCHitsRight[plane].push_back(hit);
232 } else {
233 TDCHitsLeft[plane].push_back(hit);
234 }
235 }
236 }
237
238 float Signum = -1.;
239 vector <paddle> TOFADCPaddles[2];
240 vector <SingleP> TOFADCSingles[2];
241 int firsttime = 1;
242
243 // for each hodoscope plane find matches between
244 // ADC left and right data or find single hits for
245 // the single ended readout paddles.
246 for (int plane=0; plane<2; plane++){
247
248 // loop over right pmts to find single ended paddle hits
249 // these are paddle 22 and paddle 23
250 for (unsigned int i = 0; i<ADCHitsRight[plane].size(); i++) {
251 const DTOFDigiHit *hitR = ADCHitsRight[plane][i];
252 int paddle = hitR->bar;
253 if ((paddle == 22) || (paddle == 23)){
254 struct SingleP newsingle;
255 newsingle.paddle = paddle;
256 newsingle.LR = 1;
257 newsingle.time = (float)hitR->pulse_time*BINADC_2_TIME ;
258 newsingle.adc = (float)hitR->pulse_integral -
259 (float)hitR->pedestal/(float)hitR->nsamples_pedestal*(float)hitR->nsamples_integral;
260 newsingle.OverFlow = ADCRightOverFlow[plane][i];
261 TOFADCSingles[plane].push_back(newsingle);
262 }
263 }
264
265 // loop over left pmts to find single ended paddle hits
266 // these are paddle 22 and paddle 23
267 // for the other paddle loop over the right ones and find match
268
269 for (unsigned int j = 0; j<ADCHitsLeft[plane].size(); j++) {
270 const DTOFDigiHit *hit = ADCHitsLeft[plane][j];
271 int paddle = hit->bar;
272 if ((paddle == 22) || (paddle == 23)){ // save singles of left pmts
273 struct SingleP newsingle;
274 newsingle.paddle = paddle;
275 newsingle.LR = 0;
276 newsingle.adc = (float)hit->pulse_integral -
277 (float)hit->pedestal/(float)hit->nsamples_pedestal*(float)hit->nsamples_integral;
278 newsingle.time = (float)hit->pulse_time*BINADC_2_TIME ;
279 newsingle.OverFlow = ADCLeftOverFlow[plane][j];
280 TOFADCSingles[plane].push_back(newsingle);
281 } else {
282
283 // loop over Right adc hits find match with the left and prepare paddle hits
284 for (unsigned int i = 0; i<ADCHitsRight[plane].size(); i++) {
285 const DTOFDigiHit *hitR = ADCHitsRight[plane][i];
286 if (hitR->bar == paddle){
287 struct paddle newpaddle;
288 newpaddle.paddle = paddle;
289 newpaddle.timeL = (float)hit->pulse_time*BINADC_2_TIME ;
290 newpaddle.timeR = (float)hitR->pulse_time*BINADC_2_TIME ;
291 newpaddle.mt = (newpaddle.timeL + newpaddle.timeR)/2.;
292 newpaddle.td = Signum*(newpaddle.timeL - newpaddle.timeR)/2.;
293 newpaddle.adcL = (float)hit->pulse_integral -
294 (float)hit->pedestal/(float)hit->nsamples_pedestal*(float)hit->nsamples_integral;
295 newpaddle.adcR = (float)hitR->pulse_integral -
296 (float)hitR->pedestal/(float)hitR->nsamples_pedestal*(float)hitR->nsamples_integral;
297 newpaddle.OverFlowL = ADCLeftOverFlow[plane][j];
298 newpaddle.OverFlowR = ADCRightOverFlow[plane][i];
299 if ((paddle != 22) && (paddle !=23)) {
300 //cout<<newpaddle.OverFlowL<<" "<< newpaddle.OverFlowR <<endl;
301 TOFADCPaddles[plane].push_back(newpaddle);
302 }
303 }
304 }
305 }
306 }
307 }
308
309 vector <paddle> TOFTDCPaddles[2];
310 vector <SingleP> TOFTDCSingles[2];
311 firsttime = 1;
Value stored to 'firsttime' is never read
312
313 // now do the same thing for TDC hits
314 // find matches between left and right and treat the single ended paddles separately
315
316 for (int plane=0; plane<2; plane++){
317
318 for (unsigned int j = 0; j<TDCHitsRight[plane].size(); j++) {
319 const DTOFTDCDigiHit *hit = TDCHitsRight[plane][j];
320 int paddle = hit->bar;
321 if ((paddle == 22) || (paddle == 23)){
322 struct SingleP newsingle;
323 newsingle.paddle = paddle;
324 newsingle.LR = 1;
325 newsingle.time = (float)hit->time*BINTDC_2_TIME ;
326 TOFTDCSingles[plane].push_back(newsingle);
327 }
328 }
329
330 for (unsigned int j = 0; j<TDCHitsLeft[plane].size(); j++) {
331 const DTOFTDCDigiHit *hit = TDCHitsLeft[plane][j];
332 int paddle = hit->bar;
333 if ((paddle == 22) || (paddle == 23)){
334 struct SingleP newsingle;
335 newsingle.paddle = paddle;
336 newsingle.LR = 0;
337 newsingle.time = (float)hit->time*BINTDC_2_TIME ;
338 TOFTDCSingles[plane].push_back(newsingle);
339 } else {
340 for (unsigned int i = 0; i<TDCHitsRight[plane].size(); i++) {
341 const DTOFTDCDigiHit *hitR = TDCHitsRight[plane][i];
342 if (hitR->bar == paddle){
343 struct paddle newpaddle;
344 newpaddle.paddle = paddle;
345 newpaddle.timeL = (float)hit->time*BINTDC_2_TIME ;
346 newpaddle.timeR = (float)hitR->time*BINTDC_2_TIME ;
347 newpaddle.mt = (newpaddle.timeL + newpaddle.timeR)/2.;
348 newpaddle.td = Signum*(newpaddle.timeL - newpaddle.timeR)/2.; // left side get positive x
349 if ((paddle != 22) && (paddle !=23)) {
350 TOFTDCPaddles[plane].push_back(newpaddle);
351 }
352 }
353 }
354 }
355 }
356 }
357
358 pthread_mutex_lock(&mutex);
359 Event = eventnumber;
360 TShift = TimingShift;
361 Nhits = TOFTDCPaddles[0].size() + TOFTDCPaddles[1].size();
362 int cnt = 0;
363 int AllHits[4]={0,0,0,0};
364
365 if (Nhits<MaxHits100){
366 for (unsigned int k = 0; k<TOFTDCPaddles[0].size() ; k++){
367 Plane[cnt] = 0;
368 Paddle[cnt] = TOFTDCPaddles[0][k].paddle;
369 MeanTime[cnt] = TOFTDCPaddles[0][k].mt;
370 TimeDiff[cnt] = TOFTDCPaddles[0][k].td;
371 cnt++;
372 AllHits[0]++;
373 }
374 AllHits[0] = cnt;
375 for (unsigned int k = 0; k<TOFTDCPaddles[1].size() ; k++){
376 Plane[cnt] = 1;
377 Paddle[cnt] = TOFTDCPaddles[1][k].paddle;
378 MeanTime[cnt] = TOFTDCPaddles[1][k].mt;
379 TimeDiff[cnt] = TOFTDCPaddles[1][k].td;
380 cnt++;
381 AllHits[1]++;
382 }
383 } else {
384 Nhits = 0;
385 }
386
387 cnt = 0;
388 NhitsA = TOFADCPaddles[0].size() + TOFADCPaddles[1].size();
389 if (NhitsA<MaxHits100){
390 for (unsigned int k = 0; k<TOFADCPaddles[0].size() ; k++){
391 PlaneA[cnt] = 0;
392 PaddleA[cnt] = TOFADCPaddles[0][k].paddle;
393 MeanTimeA[cnt] = TOFADCPaddles[0][k].mt;
394 TimeDiffA[cnt] = TOFADCPaddles[0][k].td;
395 ADCL[cnt] = TOFADCPaddles[0][k].adcL;
396 ADCR[cnt] = TOFADCPaddles[0][k].adcR;
397 OFL[cnt] = TOFADCPaddles[0][k].OverFlowL;
398 OFR[cnt] = TOFADCPaddles[0][k].OverFlowR;
399 cnt++;
400 AllHits[2]++;
401 }
402
403 for (unsigned int k = 0; k<TOFADCPaddles[1].size() ; k++){
404 PlaneA[cnt] = 1;
405 PaddleA[cnt] = TOFADCPaddles[1][k].paddle;
406 MeanTimeA[cnt] = TOFADCPaddles[1][k].mt;
407 TimeDiffA[cnt] = TOFADCPaddles[1][k].td;
408 ADCL[cnt] = TOFADCPaddles[1][k].adcL;
409 ADCR[cnt] = TOFADCPaddles[1][k].adcR;
410 OFL[cnt] = TOFADCPaddles[1][k].OverFlowL;
411 OFR[cnt] = TOFADCPaddles[1][k].OverFlowR;
412 cnt++;
413 AllHits[3]++;
414 }
415 } else {
416 NhitsA = 0;
417 }
418
419 NsinglesA = TOFADCSingles[0].size() + TOFADCSingles[1].size();
420 NsinglesT = TOFTDCSingles[0].size() + TOFTDCSingles[1].size();
421
422 unsigned int j=0;
423 for (unsigned int k = 0; k<TOFADCSingles[0].size(); k++){
424 PlaneSA[k] = 0;
425 PaddleSA[k] = TOFADCSingles[0][k].paddle ;
426 LRA[k] = TOFADCSingles[0][k].LR ;
427 ADCS[k] = TOFADCSingles[0][k].adc;
428 TADCS[k] = TOFADCSingles[0][k].time;
429 OF[k] = TOFADCSingles[0][k].OverFlow;
430 j++;
431 }
432 for (unsigned int k = 0; k<TOFADCSingles[1].size(); k++){
433 PlaneSA[k+j] = 1;
434 PaddleSA[k+j] = TOFADCSingles[1][k].paddle ;
435 LRA[k+j] = TOFADCSingles[1][k].LR ;
436 ADCS[k+j] = TOFADCSingles[1][k].adc;
437 TADCS[k+j] = TOFADCSingles[1][k].time; ;
438 OF[k+j] = TOFADCSingles[1][k].OverFlow;
439 }
440 j = 0;
441 for (unsigned int k = 0; k<TOFTDCSingles[0].size(); k++){
442 PlaneST[k] = 0;
443 PaddleST[k] = TOFTDCSingles[0][k].paddle ;
444 LRT[k] = TOFTDCSingles[0][k].LR ;
445 TDCST[k] = TOFTDCSingles[0][k].time; ;
446 j++;
447 }
448 for (unsigned int k = 0; k<TOFTDCSingles[1].size(); k++){
449 PlaneST[k+j] = 1;
450 PaddleST[k+j] = TOFTDCSingles[1][k].paddle ;
451 LRT[k+j] = TOFTDCSingles[1][k].LR ;
452 TDCST[k+j] = TOFTDCSingles[1][k].time; ;
453 }
454
455 if (((AllHits[0]>0) && (AllHits[1]>0)) ||
456 ((AllHits[2]>0) && (AllHits[3]>0))){
457 t3->Fill();
458 }
459
460 pthread_mutex_unlock(&mutex);
461
462 /*
463 if (!(eventnumber%10000000)){
464 WriteRootFile();
465 }
466 */
467
468 return NOERROR;
469}
470
471//------------------
472// erun
473//------------------
474jerror_t JEventProcessor_TOF_calib::erun(void)
475{
476 // This is called whenever the run number changes, before it is
477 // changed to give you a chance to clean up before processing
478 // events from the next run number.
479 return NOERROR;
480}
481
482//------------------
483// fini
484//------------------
485jerror_t JEventProcessor_TOF_calib::fini(void)
486{
487 // Called before program exit after event processing is finished.
488
489 WriteRootFile();
490
491 return NOERROR;
492}
493
494
495jerror_t JEventProcessor_TOF_calib::WriteRootFile(void){
496
497 sprintf(ROOTFileName,"tofdata_run%d.root",RunNumber);
498 ROOTFile = new TFile(ROOTFileName,"recreate");
499
500 pthread_mutex_lock(&mutex);
501 ROOTFile->cd();
502 TOFTDCtime->Write();
503 TOFADCtime->Write();
504 t3->Write();
505 t3->AutoSave("SaveSelf");
506
507 ROOTFile->Close();
508 pthread_mutex_unlock(&mutex);
509 return NOERROR;
510
511}
512
513jerror_t JEventProcessor_TOF_calib::MakeHistograms(void){
514
515 /*
516 cout<<endl;
517 cout<<"CALL MakeHistograms for TOF_calib!!!! "<<endl;
518 cout<<endl;
519 */
520
521 if (first){
522
523 //cout<<"SETUP HISTOGRAMS AND TREE FOR RUN "<<RunNumber<<flush<<endl;
524
525 first = 0;
526
527 TOFTDCtime = new TH1F("TOFTDCtime","TOF CAEN TDC times", 8000, 0., 4000.);
528 TOFADCtime = new TH1F("TOFADCtime","TOF ADC times", 800, 0., 400.);
529
530 t3 = new TTree("t3","TOF Hits");
531 t3->Branch("Event", &Event,"Event/I");
532
533 t3->Branch("Nhits", &Nhits,"Nhits/I");
534 t3->Branch("TShift",&TShift,"TShift/F");
535 t3->Branch("Plane",Plane,"Plane[Nhits]/I");
536 t3->Branch("Paddle",Paddle,"Paddle[Nhits]/I");
537 t3->Branch("MeanTime",MeanTime,"MeanTime[Nhits]/F");
538 t3->Branch("TimeDiff",TimeDiff,"TimeDiff[Nhits]/F");
539
540 t3->Branch("NhitsA", &NhitsA,"NhitsA/I");
541 t3->Branch("PlaneA",PlaneA,"PlaneA[NhitsA]/I");
542 t3->Branch("PaddleA",PaddleA,"PaddleA[NhitsA]/I");
543 t3->Branch("MeanTimeA",MeanTimeA,"MeanTimeA[NhitsA]/F");
544 t3->Branch("TimeDiffA",TimeDiffA,"TimeDiffA[NhitsA]/F");
545 t3->Branch("ADCL",ADCL,"ADCL[NhitsA]/F");
546 t3->Branch("ADCR",ADCR,"ADCR[NhitsA]/F");
547 t3->Branch("OFL",OFL,"OFL[NhitsA]/I");
548 t3->Branch("OFR",OFR,"OFR[NhitsA]/I");
549
550 t3->Branch("NsinglesA", &NsinglesA,"NsinglesA/I");
551 t3->Branch("PlaneSA",PlaneSA,"PlaneSA[NsinglesA]/I");
552 t3->Branch("PaddleSA",PaddleSA,"PaddleSA[NsinglesA]/I");
553 t3->Branch("LRA",LRA,"LRA[NsinglesA]/I"); //LA=0,1 (left/right)
554 t3->Branch("ADCS",ADCS,"ADCS[NsinglesA]/F");
555 t3->Branch("OF",OF,"OF[NsinglesA]/I");
556 t3->Branch("TADCS",TADCS,"TADCS[NsinglesA]/F");
557
558 t3->Branch("NsinglesT", &NsinglesT,"NsinglesT/I");
559 t3->Branch("PlaneST",PlaneST,"PlaneSA[NsinglesT]/I");
560 t3->Branch("PaddleST",PaddleST,"PaddleSA[NsinglesT]/I");
561 t3->Branch("LRT",LRT,"LRT[NsinglesT]/I"); //LA=0,1 (left/right)
562 t3->Branch("TDCST",TDCST,"TDCST[NsinglesT]/F");
563
564 }
565
566 return NOERROR;
567}
568