Bug Summary

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