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 japp->RootWriteLock();
364 pthread_mutex_lock(&mutex);
365
366 Event = eventnumber;
367 TShift = TimingShift;
368 Nhits = TOFTDCPaddles[0].size() + TOFTDCPaddles[1].size();
369 int cnt = 0;
370 int AllHits[4]={0,0,0,0};
371
372 if (Nhits<MaxHits100){
373 for (unsigned int k = 0; k<TOFTDCPaddles[0].size() ; k++){
374 Plane[cnt] = 0;
375 Paddle[cnt] = TOFTDCPaddles[0][k].paddle;
376 MeanTime[cnt] = TOFTDCPaddles[0][k].mt;
377 TimeDiff[cnt] = TOFTDCPaddles[0][k].td;
378 cnt++;
379 AllHits[0]++;
380 }
381 AllHits[0] = cnt;
382 for (unsigned int k = 0; k<TOFTDCPaddles[1].size() ; k++){
383 Plane[cnt] = 1;
384 Paddle[cnt] = TOFTDCPaddles[1][k].paddle;
385 MeanTime[cnt] = TOFTDCPaddles[1][k].mt;
386 TimeDiff[cnt] = TOFTDCPaddles[1][k].td;
387 cnt++;
388 AllHits[1]++;
389 }
390 } else {
391 Nhits = 0;
392 }
393
394 cnt = 0;
395 NhitsA = TOFADCPaddles[0].size() + TOFADCPaddles[1].size();
396 if (NhitsA<MaxHits100){
397 for (unsigned int k = 0; k<TOFADCPaddles[0].size() ; k++){
398 PlaneA[cnt] = 0;
399 PaddleA[cnt] = TOFADCPaddles[0][k].paddle;
400 MeanTimeA[cnt] = TOFADCPaddles[0][k].mt;
401 TimeDiffA[cnt] = TOFADCPaddles[0][k].td;
402 ADCL[cnt] = TOFADCPaddles[0][k].adcL;
403 ADCR[cnt] = TOFADCPaddles[0][k].adcR;
404 OFL[cnt] = TOFADCPaddles[0][k].OverFlowL;
405 OFR[cnt] = TOFADCPaddles[0][k].OverFlowR;
406 cnt++;
407 AllHits[2]++;
408 }
409
410 for (unsigned int k = 0; k<TOFADCPaddles[1].size() ; k++){
411 PlaneA[cnt] = 1;
412 PaddleA[cnt] = TOFADCPaddles[1][k].paddle;
413 MeanTimeA[cnt] = TOFADCPaddles[1][k].mt;
414 TimeDiffA[cnt] = TOFADCPaddles[1][k].td;
415 ADCL[cnt] = TOFADCPaddles[1][k].adcL;
416 ADCR[cnt] = TOFADCPaddles[1][k].adcR;
417 OFL[cnt] = TOFADCPaddles[1][k].OverFlowL;
418 OFR[cnt] = TOFADCPaddles[1][k].OverFlowR;
419 cnt++;
420 AllHits[3]++;
421 }
422 } else {
423 NhitsA = 0;
424 }
425
426 NsinglesA = TOFADCSingles[0].size() + TOFADCSingles[1].size();
427 NsinglesT = TOFTDCSingles[0].size() + TOFTDCSingles[1].size();
428
429 unsigned int j=0;
430 for (unsigned int k = 0; k<TOFADCSingles[0].size(); k++){
431 PlaneSA[k] = 0;
432 PaddleSA[k] = TOFADCSingles[0][k].paddle ;
433 LRA[k] = TOFADCSingles[0][k].LR ;
434 ADCS[k] = TOFADCSingles[0][k].adc;
435 TADCS[k] = TOFADCSingles[0][k].time;
436 OF[k] = TOFADCSingles[0][k].OverFlow;
437 j++;
438 }
439 for (unsigned int k = 0; k<TOFADCSingles[1].size(); k++){
440 PlaneSA[k+j] = 1;
441 PaddleSA[k+j] = TOFADCSingles[1][k].paddle ;
442 LRA[k+j] = TOFADCSingles[1][k].LR ;
443 ADCS[k+j] = TOFADCSingles[1][k].adc;
444 TADCS[k+j] = TOFADCSingles[1][k].time; ;
445 OF[k+j] = TOFADCSingles[1][k].OverFlow;
446 }
447 j = 0;
448 for (unsigned int k = 0; k<TOFTDCSingles[0].size(); k++){
449 PlaneST[k] = 0;
450 PaddleST[k] = TOFTDCSingles[0][k].paddle ;
451 LRT[k] = TOFTDCSingles[0][k].LR ;
452 TDCST[k] = TOFTDCSingles[0][k].time;
453 j++;
454 }
455 for (unsigned int k = 0; k<TOFTDCSingles[1].size(); k++){
456 PlaneST[k+j] = 1;
457 PaddleST[k+j] = TOFTDCSingles[1][k].paddle ;
458 LRT[k+j] = TOFTDCSingles[1][k].LR ;
459 TDCST[k+j] = TOFTDCSingles[1][k].time; ;
460 }
461
462 if (((AllHits[0]>0) && (AllHits[1]>0)) ||
463 ((AllHits[2]>0) && (AllHits[3]>0))){
464 t3->Fill();
465 }
466
467 pthread_mutex_unlock(&mutex);
468 japp->RootUnLock();
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 /*
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 TDirectory *top = gDirectory(TDirectory::CurrentDirectory());
537
538 // create root file here so the tree does not show up in hd_root.root
539 sprintf(ROOTFileName,"hd_root_tofcalib.root");
540 ROOTFile = new TFile(ROOTFileName,"recreate");
541 ROOTFile->cd();
542
543 ROOTFile->mkdir("TOFcalib");
544 ROOTFile->cd("TOFcalib");
545
546
547 TOFTDCtime = new TH1F("TOFTDCtime","TOF CAEN TDC times", 8000, 0., 4000.);
548 TOFADCtime = new TH1F("TOFADCtime","TOF ADC times", 800, 0., 400.);
549
550 t3 = new TTree("t3","TOF Hits");
551 t3->Branch("Event", &Event,"Event/I");
552
553 t3->Branch("Nhits", &Nhits,"Nhits/I");
554 t3->Branch("TShift",&TShift,"TShift/F");
555 t3->Branch("Plane",Plane,"Plane[Nhits]/I");
556 t3->Branch("Paddle",Paddle,"Paddle[Nhits]/I");
557 t3->Branch("MeanTime",MeanTime,"MeanTime[Nhits]/F");
558 t3->Branch("TimeDiff",TimeDiff,"TimeDiff[Nhits]/F");
559
560 t3->Branch("NhitsA", &NhitsA,"NhitsA/I");
561 t3->Branch("PlaneA",PlaneA,"PlaneA[NhitsA]/I");
562 t3->Branch("PaddleA",PaddleA,"PaddleA[NhitsA]/I");
563 t3->Branch("MeanTimeA",MeanTimeA,"MeanTimeA[NhitsA]/F");
564 t3->Branch("TimeDiffA",TimeDiffA,"TimeDiffA[NhitsA]/F");
565 t3->Branch("ADCL",ADCL,"ADCL[NhitsA]/F");
566 t3->Branch("ADCR",ADCR,"ADCR[NhitsA]/F");
567 t3->Branch("OFL",OFL,"OFL[NhitsA]/I");
568 t3->Branch("OFR",OFR,"OFR[NhitsA]/I");
569
570 t3->Branch("NsinglesA", &NsinglesA,"NsinglesA/I");
571 t3->Branch("PlaneSA",PlaneSA,"PlaneSA[NsinglesA]/I");
572 t3->Branch("PaddleSA",PaddleSA,"PaddleSA[NsinglesA]/I");
573 t3->Branch("LRA",LRA,"LRA[NsinglesA]/I"); //LA=0,1 (left/right)
574 t3->Branch("ADCS",ADCS,"ADCS[NsinglesA]/F");
575 t3->Branch("OF",OF,"OF[NsinglesA]/I");
576 t3->Branch("TADCS",TADCS,"TADCS[NsinglesA]/F");
577
578 t3->Branch("NsinglesT", &NsinglesT,"NsinglesT/I");
579 t3->Branch("PlaneST",PlaneST,"PlaneSA[NsinglesT]/I");
580 t3->Branch("PaddleST",PaddleST,"PaddleSA[NsinglesT]/I");
581 t3->Branch("LRT",LRT,"LRT[NsinglesT]/I"); //LA=0,1 (left/right)
582 t3->Branch("TDCST",TDCST,"TDCST[NsinglesT]/F");
583
584 top->cd();
585 japp->RootUnLock(); //RELEASE ROOT LOCK!!
586 }
587
588 return NOERROR;
589}
590