Bug Summary

File:plugins/Calibration/TOF_calib/JEventProcessor_TOF_calib.cc
Location:line 316, 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 TOFADCtime->Fill(time);
192 if (fabsf(time-ADCTLOC)<ADCTimeCut){
193 // test for overflow if raw data available
194 vector <const Df250PulseIntegral*> PulseIntegral;
195 hit->Get(PulseIntegral);
196 vector <const Df250WindowRawData*> WRawData;
197 PulseIntegral[0]->Get(WRawData);
198 int overflow = 0;
199 if ( WRawData.size() > 0) {
200 for (int n=0;n<100;n++){
201 if (WRawData[0]->samples[n] & 0x1000){
202 overflow++;
203 }
204 }
205 } else {
206 //overflow = PulseIntegral[0]->quality_factor;
207 }
208
209 if (end){
210 ADCHitsRight[plane].push_back(hit);
211 ADCRightOverFlow[plane].push_back(overflow);
212 } else {
213 ADCHitsLeft[plane].push_back(hit);
214 ADCLeftOverFlow[plane].push_back(overflow);
215 }
216 }
217 }
218
219 if (ADCLeftOverFlow[0].size() != ADCHitsLeft[0].size()){
220 cout<<"Error vector size missmatch!"<<endl;
221 }
222
223
224 // loop over DTOFTDCDigiHits : these are the TDC hits
225 // sort them into left and right hits
226 // only keep hits within the time peak
227 // also keep the hodoscope planes separate
228 for (unsigned int k=0; k<TDCHits.size(); k++){
229 const DTOFTDCDigiHit *hit = TDCHits[k];
230 int plane = hit->plane;
231 int end = hit->end;
232 float time = (float)hit->time * BINTDC_2_TIME;
233 TOFTDCtime->Fill(time);
234 if (fabsf(time-TDCTLOC)<TDCTimeCut){
235 if (end){
236 TDCHitsRight[plane].push_back(hit);
237 } else {
238 TDCHitsLeft[plane].push_back(hit);
239 }
240 }
241 }
242
243 float Signum = -1.;
244 vector <paddle> TOFADCPaddles[2];
245 vector <SingleP> TOFADCSingles[2];
246 int firsttime = 1;
247
248 // for each hodoscope plane find matches between
249 // ADC left and right data or find single hits for
250 // the single ended readout paddles.
251 for (int plane=0; plane<2; plane++){
252
253 // loop over right pmts to find single ended paddle hits
254 // these are paddle 22 and paddle 23
255 for (unsigned int i = 0; i<ADCHitsRight[plane].size(); i++) {
256 const DTOFDigiHit *hitR = ADCHitsRight[plane][i];
257 int paddle = hitR->bar;
258 if ((paddle == 22) || (paddle == 23)){
259 struct SingleP newsingle;
260 newsingle.paddle = paddle;
261 newsingle.LR = 1;
262 newsingle.time = (float)hitR->pulse_time*BINADC_2_TIME ;
263 newsingle.adc = (float)hitR->pulse_integral -
264 (float)hitR->pedestal/(float)hitR->nsamples_pedestal*(float)hitR->nsamples_integral;
265 newsingle.OverFlow = ADCRightOverFlow[plane][i];
266 TOFADCSingles[plane].push_back(newsingle);
267 }
268 }
269
270 // loop over left pmts to find single ended paddle hits
271 // these are paddle 22 and paddle 23
272 // for the other paddle loop over the right ones and find match
273
274 for (unsigned int j = 0; j<ADCHitsLeft[plane].size(); j++) {
275 const DTOFDigiHit *hit = ADCHitsLeft[plane][j];
276 int paddle = hit->bar;
277 if ((paddle == 22) || (paddle == 23)){ // save singles of left pmts
278 struct SingleP newsingle;
279 newsingle.paddle = paddle;
280 newsingle.LR = 0;
281 newsingle.adc = (float)hit->pulse_integral -
282 (float)hit->pedestal/(float)hit->nsamples_pedestal*(float)hit->nsamples_integral;
283 newsingle.time = (float)hit->pulse_time*BINADC_2_TIME ;
284 newsingle.OverFlow = ADCLeftOverFlow[plane][j];
285 TOFADCSingles[plane].push_back(newsingle);
286 } else {
287
288 // loop over Right adc hits find match with the left and prepare paddle hits
289 for (unsigned int i = 0; i<ADCHitsRight[plane].size(); i++) {
290 const DTOFDigiHit *hitR = ADCHitsRight[plane][i];
291 if (hitR->bar == paddle){
292 struct paddle newpaddle;
293 newpaddle.paddle = paddle;
294 newpaddle.timeL = (float)hit->pulse_time*BINADC_2_TIME ;
295 newpaddle.timeR = (float)hitR->pulse_time*BINADC_2_TIME ;
296 newpaddle.mt = (newpaddle.timeL + newpaddle.timeR)/2.;
297 newpaddle.td = Signum*(newpaddle.timeL - newpaddle.timeR)/2.;
298 newpaddle.adcL = (float)hit->pulse_integral -
299 (float)hit->pedestal/(float)hit->nsamples_pedestal*(float)hit->nsamples_integral;
300 newpaddle.adcR = (float)hitR->pulse_integral -
301 (float)hitR->pedestal/(float)hitR->nsamples_pedestal*(float)hitR->nsamples_integral;
302 newpaddle.OverFlowL = ADCLeftOverFlow[plane][j];
303 newpaddle.OverFlowR = ADCRightOverFlow[plane][i];
304 if ((paddle != 22) && (paddle !=23)) {
305 //cout<<newpaddle.OverFlowL<<" "<< newpaddle.OverFlowR <<endl;
306 TOFADCPaddles[plane].push_back(newpaddle);
307 }
308 }
309 }
310 }
311 }
312 }
313
314 vector <paddle> TOFTDCPaddles[2];
315 vector <SingleP> TOFTDCSingles[2];
316 firsttime = 1;
Value stored to 'firsttime' is never read
317
318 // now do the same thing for TDC hits
319 // find matches between left and right and treat the single ended paddles separately
320
321 for (int plane=0; plane<2; plane++){
322
323 for (unsigned int j = 0; j<TDCHitsRight[plane].size(); j++) {
324 const DTOFTDCDigiHit *hit = TDCHitsRight[plane][j];
325 int paddle = hit->bar;
326 if ((paddle == 22) || (paddle == 23)){
327 struct SingleP newsingle;
328 newsingle.paddle = paddle;
329 newsingle.LR = 1;
330 newsingle.time = (float)hit->time*BINTDC_2_TIME ;
331 TOFTDCSingles[plane].push_back(newsingle);
332 }
333 }
334
335 for (unsigned int j = 0; j<TDCHitsLeft[plane].size(); j++) {
336 const DTOFTDCDigiHit *hit = TDCHitsLeft[plane][j];
337 int paddle = hit->bar;
338 if ((paddle == 22) || (paddle == 23)){
339 struct SingleP newsingle;
340 newsingle.paddle = paddle;
341 newsingle.LR = 0;
342 newsingle.time = (float)hit->time*BINTDC_2_TIME ;
343 TOFTDCSingles[plane].push_back(newsingle);
344 } else {
345 for (unsigned int i = 0; i<TDCHitsRight[plane].size(); i++) {
346 const DTOFTDCDigiHit *hitR = TDCHitsRight[plane][i];
347 if (hitR->bar == paddle){
348 struct paddle newpaddle;
349 newpaddle.paddle = paddle;
350 newpaddle.timeL = (float)hit->time*BINTDC_2_TIME ;
351 newpaddle.timeR = (float)hitR->time*BINTDC_2_TIME ;
352 newpaddle.mt = (newpaddle.timeL + newpaddle.timeR)/2.;
353 newpaddle.td = Signum*(newpaddle.timeL - newpaddle.timeR)/2.; // left side get positive x
354 if ((paddle != 22) && (paddle !=23)) {
355 TOFTDCPaddles[plane].push_back(newpaddle);
356 }
357 }
358 }
359 }
360 }
361 }
362
363 // FILL HISTOGRAMS
364 // Since we are filling histograms (and trees in a file) local to this plugin, it will not interfere with other ROOT operations: can use plugin-wide ROOT fill lock
365 japp->RootFillLock(this); //ACQUIRE ROOT FILL LOCK
366
367 Event = eventnumber;
368 TShift = TimingShift;
369 Nhits = TOFTDCPaddles[0].size() + TOFTDCPaddles[1].size();
370 int cnt = 0;
371 int AllHits[4]={0,0,0,0};
372
373 if (Nhits<MaxHits100){
374 for (unsigned int k = 0; k<TOFTDCPaddles[0].size() ; k++){
375 Plane[cnt] = 0;
376 Paddle[cnt] = TOFTDCPaddles[0][k].paddle;
377 MeanTime[cnt] = TOFTDCPaddles[0][k].mt;
378 TimeDiff[cnt] = TOFTDCPaddles[0][k].td;
379 cnt++;
380 AllHits[0]++;
381 }
382 AllHits[0] = cnt;
383 for (unsigned int k = 0; k<TOFTDCPaddles[1].size() ; k++){
384 Plane[cnt] = 1;
385 Paddle[cnt] = TOFTDCPaddles[1][k].paddle;
386 MeanTime[cnt] = TOFTDCPaddles[1][k].mt;
387 TimeDiff[cnt] = TOFTDCPaddles[1][k].td;
388 cnt++;
389 AllHits[1]++;
390 }
391 } else {
392 Nhits = 0;
393 }
394
395 cnt = 0;
396 NhitsA = TOFADCPaddles[0].size() + TOFADCPaddles[1].size();
397 if (NhitsA<MaxHits100){
398 for (unsigned int k = 0; k<TOFADCPaddles[0].size() ; k++){
399 PlaneA[cnt] = 0;
400 PaddleA[cnt] = TOFADCPaddles[0][k].paddle;
401 MeanTimeA[cnt] = TOFADCPaddles[0][k].mt;
402 TimeDiffA[cnt] = TOFADCPaddles[0][k].td;
403 ADCL[cnt] = TOFADCPaddles[0][k].adcL;
404 ADCR[cnt] = TOFADCPaddles[0][k].adcR;
405 OFL[cnt] = TOFADCPaddles[0][k].OverFlowL;
406 OFR[cnt] = TOFADCPaddles[0][k].OverFlowR;
407 cnt++;
408 AllHits[2]++;
409 }
410
411 for (unsigned int k = 0; k<TOFADCPaddles[1].size() ; k++){
412 PlaneA[cnt] = 1;
413 PaddleA[cnt] = TOFADCPaddles[1][k].paddle;
414 MeanTimeA[cnt] = TOFADCPaddles[1][k].mt;
415 TimeDiffA[cnt] = TOFADCPaddles[1][k].td;
416 ADCL[cnt] = TOFADCPaddles[1][k].adcL;
417 ADCR[cnt] = TOFADCPaddles[1][k].adcR;
418 OFL[cnt] = TOFADCPaddles[1][k].OverFlowL;
419 OFR[cnt] = TOFADCPaddles[1][k].OverFlowR;
420 cnt++;
421 AllHits[3]++;
422 }
423 } else {
424 NhitsA = 0;
425 }
426
427 NsinglesA = TOFADCSingles[0].size() + TOFADCSingles[1].size();
428 NsinglesT = TOFTDCSingles[0].size() + TOFTDCSingles[1].size();
429
430 unsigned int j=0;
431 for (unsigned int k = 0; k<TOFADCSingles[0].size(); k++){
432 PlaneSA[k] = 0;
433 PaddleSA[k] = TOFADCSingles[0][k].paddle ;
434 LRA[k] = TOFADCSingles[0][k].LR ;
435 ADCS[k] = TOFADCSingles[0][k].adc;
436 TADCS[k] = TOFADCSingles[0][k].time;
437 OF[k] = TOFADCSingles[0][k].OverFlow;
438 j++;
439 }
440 for (unsigned int k = 0; k<TOFADCSingles[1].size(); k++){
441 PlaneSA[k+j] = 1;
442 PaddleSA[k+j] = TOFADCSingles[1][k].paddle ;
443 LRA[k+j] = TOFADCSingles[1][k].LR ;
444 ADCS[k+j] = TOFADCSingles[1][k].adc;
445 TADCS[k+j] = TOFADCSingles[1][k].time; ;
446 OF[k+j] = TOFADCSingles[1][k].OverFlow;
447 }
448 j = 0;
449 for (unsigned int k = 0; k<TOFTDCSingles[0].size(); k++){
450 PlaneST[k] = 0;
451 PaddleST[k] = TOFTDCSingles[0][k].paddle ;
452 LRT[k] = TOFTDCSingles[0][k].LR ;
453 TDCST[k] = TOFTDCSingles[0][k].time;
454 j++;
455 }
456 for (unsigned int k = 0; k<TOFTDCSingles[1].size(); k++){
457 PlaneST[k+j] = 1;
458 PaddleST[k+j] = TOFTDCSingles[1][k].paddle ;
459 LRT[k+j] = TOFTDCSingles[1][k].LR ;
460 TDCST[k+j] = TOFTDCSingles[1][k].time; ;
461 }
462
463 if (((AllHits[0]>0) && (AllHits[1]>0)) ||
464 ((AllHits[2]>0) && (AllHits[3]>0))){
465 t3->Fill();
466 }
467
468 japp->RootFillUnLock(this); //RELEASE ROOT FILL LOCK
469
470 return NOERROR;
471}
472
473//------------------
474// erun
475//------------------
476jerror_t JEventProcessor_TOF_calib::erun(void)
477{
478 // This is called whenever the run number changes, before it is
479 // changed to give you a chance to clean up before processing
480 // events from the next run number.
481 return NOERROR;
482}
483
484//------------------
485// fini
486//------------------
487jerror_t JEventProcessor_TOF_calib::fini(void)
488{
489 // Called before program exit after event processing is finished.
490
491 WriteRootFile();
492
493 return NOERROR;
494}
495
496
497jerror_t JEventProcessor_TOF_calib::WriteRootFile(void){
498
499
500 //sprintf(ROOTFileName,"tofdata_run%d.root",RunNumber);
501 //ROOTFile = new TFile(ROOTFileName,"recreate");
502
503 TDirectory *top = gDirectory(TDirectory::CurrentDirectory());
504
505 ROOTFile->cd();
506 ROOTFile->cd("TOFcalib");
507
508 TOFTDCtime->Write();
509 TOFADCtime->Write();
510 t3->Write();
511 //t3->AutoSave("SaveSelf");
512
513 //ROOTFile->Close();
514 top->cd();
515
516 return NOERROR;
517
518}
519
520jerror_t JEventProcessor_TOF_calib::MakeHistograms(void){
521
522 //NO LOCKS: CALLED IN init(): GUARANTEED TO BE SINGLE-THREADED
523 /*
524 cout<<endl;
525 cout<<"CALL MakeHistograms for TOF_calib!!!! "<<endl;
526 cout<<endl;
527 */
528
529 if (first){
530
531 //cout<<"SETUP HISTOGRAMS AND TREE FOR RUN "<<RunNumber<<flush<<endl;
532
533 first = 0;
534
535 TDirectory *top = gDirectory(TDirectory::CurrentDirectory());
536
537 // create root file here so the tree does not show up in hd_root.root
538 sprintf(ROOTFileName,"hd_root_tofcalib.root");
539 ROOTFile = new TFile(ROOTFileName,"recreate");
540 ROOTFile->cd();
541
542 ROOTFile->mkdir("TOFcalib");
543 ROOTFile->cd("TOFcalib");
544
545
546 TOFTDCtime = new TH1F("TOFTDCtime","TOF CAEN TDC times", 8000, 0., 4000.);
547 TOFADCtime = new TH1F("TOFADCtime","TOF ADC times", 800, 0., 400.);
548
549 t3 = new TTree("t3","TOF Hits");
550 t3->Branch("Event", &Event,"Event/I");
551
552 t3->Branch("Nhits", &Nhits,"Nhits/I");
553 t3->Branch("TShift",&TShift,"TShift/F");
554 t3->Branch("Plane",Plane,"Plane[Nhits]/I");
555 t3->Branch("Paddle",Paddle,"Paddle[Nhits]/I");
556 t3->Branch("MeanTime",MeanTime,"MeanTime[Nhits]/F");
557 t3->Branch("TimeDiff",TimeDiff,"TimeDiff[Nhits]/F");
558
559 t3->Branch("NhitsA", &NhitsA,"NhitsA/I");
560 t3->Branch("PlaneA",PlaneA,"PlaneA[NhitsA]/I");
561 t3->Branch("PaddleA",PaddleA,"PaddleA[NhitsA]/I");
562 t3->Branch("MeanTimeA",MeanTimeA,"MeanTimeA[NhitsA]/F");
563 t3->Branch("TimeDiffA",TimeDiffA,"TimeDiffA[NhitsA]/F");
564 t3->Branch("ADCL",ADCL,"ADCL[NhitsA]/F");
565 t3->Branch("ADCR",ADCR,"ADCR[NhitsA]/F");
566 t3->Branch("OFL",OFL,"OFL[NhitsA]/I");
567 t3->Branch("OFR",OFR,"OFR[NhitsA]/I");
568
569 t3->Branch("NsinglesA", &NsinglesA,"NsinglesA/I");
570 t3->Branch("PlaneSA",PlaneSA,"PlaneSA[NsinglesA]/I");
571 t3->Branch("PaddleSA",PaddleSA,"PaddleSA[NsinglesA]/I");
572 t3->Branch("LRA",LRA,"LRA[NsinglesA]/I"); //LA=0,1 (left/right)
573 t3->Branch("ADCS",ADCS,"ADCS[NsinglesA]/F");
574 t3->Branch("OF",OF,"OF[NsinglesA]/I");
575 t3->Branch("TADCS",TADCS,"TADCS[NsinglesA]/F");
576
577 t3->Branch("NsinglesT", &NsinglesT,"NsinglesT/I");
578 t3->Branch("PlaneST",PlaneST,"PlaneSA[NsinglesT]/I");
579 t3->Branch("PaddleST",PaddleST,"PaddleSA[NsinglesT]/I");
580 t3->Branch("LRT",LRT,"LRT[NsinglesT]/I"); //LA=0,1 (left/right)
581 t3->Branch("TDCST",TDCST,"TDCST[NsinglesT]/F");
582
583 top->cd();
584 }
585
586 return NOERROR;
587}
588