BOSS 6.6.4.p03
BESIII Offline Software System
Loading...
Searching...
No Matches
TofRawDataProvider.cxx
Go to the documentation of this file.
1#include "GaudiKernel/Kernel.h"
2#include "GaudiKernel/IInterface.h"
3#include "GaudiKernel/IIncidentSvc.h"
4#include "GaudiKernel/Incident.h"
5#include "GaudiKernel/IIncidentListener.h"
6#include "GaudiKernel/StatusCode.h"
7#include "GaudiKernel/SvcFactory.h"
8#include "GaudiKernel/MsgStream.h"
9#include "GaudiKernel/IDataProviderSvc.h"
10#include "GaudiKernel/SmartDataPtr.h"
11#include "GaudiKernel/DataSvc.h"
14#include "Identifier/TofID.h"
15#include "TofRawEvent/TofDigi.h"
20
22
23#include <cmath>
24// tianhl for mt
25#include "GaudiKernel/ThreadGaudi.h"
26// tianhl for mt
27
28using namespace std;
29
33
36 m_hasFilled(0)
37{}
38
39
41 RawDataProviderBase( name ),
42 m_hasFilled(0)
43{}
44
45
47 IterTofDataMap iter = m_tofDataMap.begin();
48 for( ; iter != m_tofDataMap.end(); iter++ ) {
49 delete (*iter).second;
50 }
51 m_tofDataMap.clear();
52
53 m_tofDataMapOnline.clear();
54 m_tofDataVectorOnline.clear();
55 m_tofDataMapEstime.clear();
56 m_tofDataVectorEstime.clear();
57 m_tofDataMapTof.clear();
58 m_tofDataVectorTof.clear();
59 m_tofDataMapEmc.clear();
60 m_tofDataVectorEmc.clear();
61
62 return;
63}
64
65
66StatusCode TofRawDataProvider::initialize( bool mode, ISvcLocator* pSvcLoc, IMessageSvc* pMsg ) {
67 MsgStream log( m_msgSvc, m_name );
68 RawDataProviderBase::initialize( pSvcLoc,pMsg );
69
70 //Get TOF Calibtration Service
71 StatusCode scc = m_svcLocator->service("TofCaliSvc", tofCaliSvc);
72 if (scc == StatusCode::SUCCESS) {
73 log << MSG::INFO << "TofRec Get Calibration Service Sucessfully!" << endreq;
74 } else if(!mode) {
75 log << MSG::ERROR << "TofRec Get Calibration Service Failed !" << endreq;
76 return StatusCode::FAILURE;
77 }
78
79 //Get TOF Q Correction Service
80 StatusCode scq = m_svcLocator->service("TofQCorrSvc", tofQCorrSvc);
81 if (scq == StatusCode::SUCCESS) {
82 log << MSG::INFO << "TofRec Get Q Correction Service Sucessfully!" << endreq;
83 } else if(!mode){
84 log << MSG::ERROR << "TofRec Get Q Correction Service Failed !" << endreq;
85 return StatusCode::FAILURE;
86 }
87
88 //Get TOF Q Electronics Saturation Service
89 StatusCode sce = m_svcLocator->service("TofQElecSvc", tofQElecSvc);
90 if (sce == StatusCode::SUCCESS) {
91 log << MSG::INFO << "TofRec Get Q Electronics Calibration Service Sucessfully!" << endreq;
92 } else if(!mode){
93 log << MSG::ERROR << "TofRec Get Q Electronics Calibration Service Failed !" << endreq;
94 return StatusCode::FAILURE;
95 }
96
97 return StatusCode::SUCCESS;
98}
99
100
101void TofRawDataProvider::handle(const Incident& inc){
102 MsgStream log( m_msgSvc, m_name );
103 log << MSG::DEBUG << "handle: " << inc.type() << endreq;
104 if ( inc.type() == "BeginEvent" ){
105 log << MSG::DEBUG << "Begin Event" << endreq;
106 IterTofDataMap iter = m_tofDataMap.begin();
107 for( ; iter != m_tofDataMap.end(); iter++ ) {
108 delete (*iter).second;
109 }
110 IterTofDataMap iterOnline = m_tofDataMapOnline.begin();
111 for( ; iterOnline != m_tofDataMapOnline.end(); iterOnline++ ) {
112 delete (*iterOnline).second;
113 }
114 m_tofDataMap.clear();
115 m_tofDataMapOnline.clear();
116 m_tofDataVectorOnline.clear();
117 m_tofDataMapEstime.clear();
118 m_tofDataVectorEstime.clear();
119 m_tofDataMapTof.clear();
120 m_tofDataVectorTof.clear();
121 m_tofDataMapEmc.clear();
122 m_tofDataVectorEmc.clear();
123
124 m_hasFilled = false;
125 }
126 return;
127}
128
129
130// tofDataMapFull includes all possible combinations.
132
133 MsgStream log(m_msgSvc, m_name);
134 log << MSG::INFO << "TofRawDataProvider::tofDataMapFull()" << endreq;
135
136 if( !m_tofDataMap.empty() ) {
137
138 log << MSG::WARNING << "TofRawDataProvider::tofDataMapFull: m_tofDataMap is NOT empty!" << endreq;
139
140 IterTofDataMap iter = m_tofDataMap.begin();
141 for( ; iter != m_tofDataMap.end(); iter++ ) {
142 delete (*iter).second;
143 }
144 m_tofDataMap.clear();
145 }
146 // tianhl for mt
147 std::string evtDataSvc_name("EventDataSvc");
148 if(isGaudiThreaded(m_name)){
149 evtDataSvc_name += getGaudiThreadIDfromName(m_name);
150 }
151 // tianhl for mt
152
153 IDataProviderSvc* eventSvc;
154 StatusCode sc = m_svcLocator->service( evtDataSvc_name.c_str(),eventSvc, true );
155 if( !sc.isSuccess() ) {
156 log << MSG::FATAL << "TofRawDataProvider::tofDataMapFull: ERROR Could not load EventDataSvc" << endreq;
157 return;
158 }
159
160 // Event Header
161 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc,"/Event/EventHeader");
162 if( !eventHeader ) {
163 log << MSG::FATAL << "TofRawDataProvider could not find Event Header!" << endreq;
164 return;
165 }
166 int run = eventHeader->runNumber();
167
168 bool mc = ( run < 0 ) ? true:false;
169 bool qCorr = bool( tofCaliSvc->QCorr() );
170 qCorr = qCorr && (!mc);
171 bool qElec = bool( tofCaliSvc->QElec() );
172 bool misLable = bool( tofCaliSvc->MisLable() );
173 misLable = ( !mc && misLable );
174 vector<int> deadId;
175
176 int identmp = -1;
177 for( unsigned int i=0; i<5; i++ ) {
178 identmp = tofCaliSvc->BrEast(i);
179 //std::cout << "TofRawDataProvider DeadID: identmp_breast " << identmp << std::endl;
180 if( identmp != 0x2fffffff ) {
181 //std::cout << "TofRawDataProvider deadid pushback " << identmp << std::endl;
182 deadId.push_back( identmp );
183 }
184 identmp = tofCaliSvc->BrWest(i);
185 //std::cout << "TofRawDataProvider DeadID: identmp_brwest " << identmp << std::endl;
186
187 if( identmp != 0x2fffffff ) {
188 //std::cout << "TofRawDataProvider deadid pushback " << identmp << std::endl;
189 deadId.push_back( identmp );
190 }
191 identmp = tofCaliSvc->Endcap(i);
192 //std::cout << "TofRawDataProvider DeadID: identmp_endcap " << identmp << std::endl;
193 if( identmp != 0x2fffffff ) {
194 //std::cout << "TofRawDataProvider deadid pushback " << identmp << std::endl;
195 deadId.push_back( identmp );
196 }
197 }
198
199 // get TDS data in a common class
200 SmartDataPtr<TofDigiCol> tofDigiCol(eventSvc,"/Event/Digi/TofDigiCol");
201 if( !tofDigiCol ) {
202 log << MSG::WARNING << "TofRawDataProvider::tofDataMapFull: Could not find Tof Digi Data!" << endreq;
203 return;
204 }
205
206 int qnumber = 0;
207 int tnumber = 0;
208
209 std::vector<Adc*> chargeVec;
210 std::vector<Tdc*> timeVec;
211
212
213
214
215 TofDigiCol::iterator iter = tofDigiCol->begin();
216
217for( ; iter != tofDigiCol->end(); iter++ ) {
218
219
220
221 Identifier iden_help = (*iter)->identify();
222 int barrel_ec_help = TofID::barrel_ec(iden_help);
223
224
225 if(barrel_ec_help == 0 || barrel_ec_help ==1 || barrel_ec_help==2) // barrel tof or old endcap
226 {
227
228 unsigned int overflow = (*iter)->getOverflow();
229 // electronics error message
230
231
232 if( ( overflow & 0xfe000000 ) == 0xfe000000 )
233 {
234 continue;
235 }
236
237 // overflow 0x 1 1 1 1 1 1
238 // no Q T / multi Q T / overflow Q T
239
240 bool multiQ = ( ( overflow & 0x8 ) != 0 );
241 bool multiT = ( ( overflow & 0x4 ) != 0 );
242
243 Identifier iden = (*iter)->identify();
244
245 unsigned int iden_value = iden.get_value();
246
247
248
249
250 bool sameId = false;
251 vector<int>::iterator iter_dead = deadId.begin();
252 for( ; iter_dead != deadId.end(); iter_dead++ ) {
253 if( iden_value == (*iter_dead) ) {
254 sameId = true;
255 break;
256 }
257 }
258 if( sameId ) {
259 if( mc ) { continue; }
260 else {
261 log << MSG::ERROR << "TofRawDataProvider::tofDataMapFull: Dead Channel Number is not Correct, please check TOF Calibration Constants!" << endreq;
262 }
263 }
264
265
266 int barrel_ec = TofID::barrel_ec(iden);
267 int id = TofID::phi_module(iden);
268 int end = TofID::end(iden);
269
270
271
272 if( ( barrel_ec != 1 ) && ( end == 1 ) ) continue;
273 // TofDigiCol 48 and 96 for luminocity
274 if( ( barrel_ec != 1 ) && ( id == 48 ) ) continue;
275
276 unsigned int tdcChannel = (*iter)->getTimeChannel();
277 unsigned int adcChannel = (*iter)->getChargeChannel();
278
279
280
281
282 if( ( overflow & 0x2 ) != 0 )
283 {
284 adcChannel = ( adcChannel | 0x80000 );
285 }
286
287 if( (adcChannel&0x7fffffff) != 0x7fffffff ) {
288
289 Adc* adc = new Adc;
290 if( qCorr ) adc->setCorr();
291 if( qElec ) adc->setElec();
292
293 adc->setValue( adcChannel );
294 qnumber++;
295 adc->setNumber( qnumber );
296 chargeVec.push_back( adc );
297 }
298
299
300
301 if( tdcChannel != 0x7fffffff ) {
302 Tdc* tdc = new Tdc;
303 tdc->setValue( tdcChannel );
304 tnumber++;
305 tdc->setNumber( tnumber );
306 timeVec.push_back( tdc );
307 }
308
309
310
311 if( multiT || multiQ ) {
312 TofDigiCol::iterator iter_next = iter + 1;
313 if( iter_next != tofDigiCol->end() ) {
314 unsigned int idenNext_value = ((*iter_next)->identify()).get_value();
315 if( iden_value == idenNext_value ) continue;
316 }
317 }
318
319
320
321 qnumber = 0;
322 tnumber = 0;
323
324 std::vector<PmtData*> pmtDataVec;
325 std::vector<Tdc*>::iterator iter_t = timeVec.begin();
326 for( ; iter_t != timeVec.end(); iter_t++ ) {
327 int tclock = (*iter_t)->clock();
328 PmtData* pmt = new PmtData;
329 pmt->setTdc( (*iter_t) );
330
331 std::vector<Adc*>::iterator iter_q = chargeVec.begin();
332 for( ; iter_q != chargeVec.end(); iter_q++ ) {
333 int qclock = (*iter_q)->clock();
334
335 if( abs(tclock-qclock)<2 ) {
336 if( ( pmt->quality() & 0x2 ) != 0 ) { // pmt has Q
337 if( (*iter_q)->value() > pmt->adc() ) {
338 pmt->qtimesmm();
339 pmt->setAdc( (*iter_q) );
340
341
342 }
343 }//close pmt has q
344 else { // pmt has no Q
345 pmt->setAdc( (*iter_q) );
346 }
347 }
348 }
349 pmtDataVec.push_back( pmt );
350 }
351
352
353
354 std::vector<Adc*>::iterator iter_q = chargeVec.begin();
355 for( ; iter_q != chargeVec.end(); iter_q++ ) {
356 //cout << "(*iter_q)->times() " << (*iter_q)->times() <<endl;
357 if( (*iter_q)->times() != -1 )
358 {
359 continue;
360 }
361
362 //cout << "Hallo Hier, d.h. times() von charge !=-1 und barrel_ec ist "<< barrel_ec_help <<endl;
363 PmtData* pmt = new PmtData;
364 pmt->setAdc( (*iter_q) );
365 pmtDataVec.push_back( pmt );
366 }
367
368
369 //std::cout << "TofRawDataProvider old chargeVec.size() " << chargeVec.size() << std::endl;
370 //std::cout << "TofRawDataProvider old timeVec.size() " << timeVec.size() << std::endl;
371 chargeVec.clear();
372 timeVec.clear();
373
374 unsigned int iden_value_key = (iden_value & 0xfffffffe );
375 if( ( barrel_ec == 0 ) || ( barrel_ec == 2 ) ) {
376 std::vector<PmtData*>::iterator iter_pmt = pmtDataVec.begin();
377 for( ; iter_pmt != pmtDataVec.end(); iter_pmt++ ) {
378 TofData* tof = new TofData;
379 if( misLable ) {
380 tof->setMisLable();
381
382 if( barrel_ec==2 && id==42 ) {
383 unsigned int iden91 = TofID::getIntID( 2, 0, 91-48, 0 );
384
385 iden_value_key = iden91;
386 }
387
388 if( barrel_ec==2 && id==43 ) {
389 unsigned int iden90 = TofID::getIntID( 2, 0, 90-48, 0 );
390 iden_value_key = iden90;
391 }
392
393 }
394
395
396 tof->setIdentify( iden );
397 tof->setForward( (*iter_pmt) );
398 tof->setTMatched( true );
399 m_tofDataMap.insert( make_pair( iden_value_key, tof ) );
400 }
401 }
402 else if( barrel_ec == 1 ) { //super
403 unsigned int count = m_tofDataMap.count( iden_value_key );
404 if( count == 0 ) {
405 std::vector<PmtData*>::iterator iter_pmt = pmtDataVec.begin();
406 for( ; iter_pmt != pmtDataVec.end(); iter_pmt++ ) {
407 TofData* tof = new TofData;
408 tof->setIdentify( iden );
409 if( end == 0 ) {
410 tof->setForward( (*iter_pmt) );
411 }
412 else {
413 tof->setBackward( (*iter_pmt) );
414 }
415 tof->setTMatched( true );
416
417 m_tofDataMap.insert( make_pair( iden_value_key, tof ) );
418 }
419 }
420 else {
421 pair< IterTofDataMap, IterTofDataMap > range = m_tofDataMap.equal_range( iden_value_key );
422 std::vector<PmtData*>::iterator iter_pmt = pmtDataVec.begin();
423 for( ; iter_pmt != pmtDataVec.end(); iter_pmt++ ) {
424 bool used = false;
425 IterTofDataMap iter = range.first;
426 for( unsigned int tofDataNumber = 0; tofDataNumber < count; tofDataNumber++, iter++ ) {
427 bool matched = false;
428 if( end == 0 ) { // east, forward
429 if( ( ( (*iter_pmt)->quality() & 0x1 ) != 0 ) && ( ( ((*iter).second)->quality() & 0x1 ) != 0 ) ) { // has east and west time
430 double time1 = (*iter_pmt)->tdc();
431 double time2 = ((*iter).second)->tdc2();
432 matched = ( abs(time1-time2)<timeDiff );
433 }
434 else if( ( ( (*iter_pmt)->quality() & 0x1 ) == 0 ) && ( ( (*iter_pmt)->quality() & 0x2 ) != 0 ) && ( ( ((*iter).second)->quality() & 0x1 ) != 0 ) ) { // has east charge and west time
435 double time1 = (*iter_pmt)->qclock();
436 double time2 = ((*iter).second)->tclock2();
437 double time3 = ((*iter).second)->qclock2();
438 matched = ( ( abs(time1-time2)<=tClockDiff ) || ( abs(time1-time3)<=tClockDiff ) );
439 }
440 else if( ( ( (*iter_pmt)->quality() & 0x1 ) != 0 ) && ( ( ((*iter).second)->quality() & 0x1 ) == 0 ) && ( ( ((*iter).second)->quality() & 0x2 ) != 0 ) ) { // has east time and west charge
441 double time1 = (*iter_pmt)->tclock();
442 double time2 = (*iter_pmt)->qclock();
443 double time3 = ((*iter).second)->qclock2();
444 matched = ( ( abs(time1-time3)<=tClockDiff ) || ( abs(time2-time3)<=tClockDiff ) );
445 }
446 else if( ( ( (*iter_pmt)->quality() & 0x1 ) == 0 ) && ( ( (*iter_pmt)->quality() & 0x2 ) != 0 ) && ( ( ((*iter).second)->quality() & 0x1 ) == 0 ) && ( ( ((*iter).second)->quality() & 0x2 ) != 0 ) ) { // has east and west charge
447 double time1 = (*iter_pmt)->qclock();
448 double time2 = ((*iter).second)->qclock2();
449 matched = ( abs(time1-time2)<=tClockDiff );
450 }
451
452 if( matched ) {
453 used = true;
454 if( ( ( (*iter).second)->quality() & 0xc ) == 0 ) {
455 ((*iter).second)->setForward( (*iter_pmt) );
456 }
457 else {
458 TofData* tof = new TofData;
459 tof->setIdentify( iden );
460 tof->setForward( (*iter_pmt) );
461 tof->setBackward( ((*iter).second)->backward() );
462
463 m_tofDataMap.insert( make_pair( iden_value_key, tof ) );
464 }
465 }
466
467 }//close if(end==0)
468 else { // west, backward
469 if( ( ( (*iter_pmt)->quality() & 0x1 ) != 0 ) && ( ( ((*iter).second)->quality() & 0x4 ) != 0 ) ) { // has west and east time
470 double time1 = (*iter_pmt)->tdc();
471 double time2 = ((*iter).second)->tdc1();
472 matched = ( abs(time1-time2)<timeDiff );
473 }
474 else if( ( ( (*iter_pmt)->quality() & 0x1 ) == 0 ) && ( ( (*iter_pmt)->quality() & 0x2 ) != 0 ) && ( ( ((*iter).second)->quality() & 0x4 ) != 0 ) ) { // has west charge and east time
475 double time1 = (*iter_pmt)->qclock();
476 double time2 = ((*iter).second)->tclock1();
477 double time3 = ((*iter).second)->qclock1();
478 matched = ( ( abs(time1-time2)<=tClockDiff ) || ( abs(time1-time3)<=tClockDiff ) );
479 }
480 else if( ( ( (*iter_pmt)->quality() & 0x1 ) != 0 ) && ( ( ((*iter).second)->quality() & 0x4 ) == 0 ) && ( ( ((*iter).second)->quality() & 0x8 ) != 0 ) ) { // has east time and west charge
481 double time1 = (*iter_pmt)->tclock();
482 double time2 = (*iter_pmt)->qclock();
483 double time3 = ((*iter).second)->qclock1();
484 matched = ( ( abs(time1-time3)<=tClockDiff ) || ( abs(time2-time3)<=tClockDiff ) );
485 }
486 else if( ( ( (*iter_pmt)->quality() & 0x1 ) == 0 ) && ( ( (*iter_pmt)->quality() & 0x2 ) != 0 ) && ( ( ((*iter).second)->quality() & 0x4 ) == 0 ) && ( ( ((*iter).second)->quality() & 0x8 ) != 0 ) ) { // has east and west charge
487 double time1 = (*iter_pmt)->qclock();
488 double time2 = ((*iter).second)->qclock1();
489 matched = ( abs(time1-time2)<=tClockDiff );
490 }
491
492 if( matched ) {
493 used = true;
494 if( ( ( (*iter).second)->quality() & 0x3 ) == 0 ) {
495 ((*iter).second)->setBackward( (*iter_pmt) );
496 if( ( ( ((*iter).second)->quality() & 0x5 )==0x5 ) || ( ( ( ((*iter).second)->quality() & 0x5 )==0x4 ) && ( ((*iter).second)->ttimes1()==1 ) ) || ( ( ( ((*iter).second)->quality() & 0x5 )==0x1 ) && ( ((*iter).second)->ttimes2()==1 ) ) ) {
497 ((*iter).second)->setTMatched( true );
498 }
499 else {
500 ((*iter).second)->setTMatched( false );
501 }
502 }
503 else {
504 TofData* tof = new TofData;
505 tof->setIdentify( iden );
506 tof->setForward( ((*iter).second)->forward() );
507 tof->setBackward( (*iter_pmt) );
508 if( ( ( tof->quality() & 0x5 )==0x5 ) || ( ( ( tof->quality() & 0x5 )==0x4 ) && ( tof->ttimes1()==1 ) ) || ( ( ( tof->quality() & 0x5 )==0x1 ) && ( tof->ttimes2()==1 ) ) ) {
509 tof->setTMatched( true );
510 }
511 else {
512 tof->setTMatched( false );
513 }
514 m_tofDataMap.insert( make_pair( iden_value_key, tof ) );
515 }
516 }
517 }
518 }
519 if( ! used ) {
520 TofData* tof = new TofData;
521 tof->setIdentify( iden );
522 if( end == 0 ) {
523 tof->setForward( (*iter_pmt) );
524 }
525 else {
526 tof->setBackward( (*iter_pmt) );
527 }
528 tof->setTMatched( true );
529 m_tofDataMap.insert( make_pair( iden_value_key, tof ) );
530 }
531 }
532 }
533 }
534
535 pmtDataVec.clear();
536
537 }//close if for barrel/old tof
538
539
540 else if(barrel_ec_help==3 || barrel_ec_help==4 || barrel_ec_help==5 || barrel_ec_help==6)//We treat the new MRPC endcap here!
541 {
542
543
544
545
546 //////////////////////////////////////////////////////
547 //// IMPORTANT ///
548 /// We use the same datastructure as the olf tof, ///
549 /// even if we do not have PMTs and so on ///
550 //////////////////////////////////////////////////////
551
552
553
554 //#Matthias
555 Identifier iden = (*iter)->identify();
556
557 unsigned int iden_value = iden.get_value();
558 //std::cout << "TofRawDataProvider iden " << iden << std::endl;
559 //std::cout << "TofRawDataProvider iden.getvalue " <<iden_value << std::endl;
560
561 int barrel_ec = TofID::barrel_ec(iden);
562 int id = TofID::phi_module(iden);
563 int end = TofID::end(iden);
564 //std::cout << "TofRawDataProvider tofDataMapFull() partID | phi_module | end " << barrel_ec << " | " << id << " | "<< end<< std::endl;
565
566
567
568 /* Alt
569 unsigned int tdcChannel = (*iter)->getTimeChannel();
570 unsigned int tdc2Channel = (*iter)->getChargeChannel();
571 double multiplicationfactor=1000.; //Convert charge from fc to pc as the time-amplitude correlation is in pc and ps
572
573
574 double timedifference=RawDataUtil::TofTime(tdc2Channel-tdcChannel);
575
576 unsigned int adcChannel =0;
577 if(timedifference>4.164) adcChannel = exp(-4.50565/(timedifference-16.6653))/0.0812208; // 4.164 ns = 10 fC; Everything smaller is expected to be noise! ->Deposit charge =0;
578
579
580 //With the calculated charge we correct the tdc-channel using the time amplitude correlation.
581 double my_chargein_pc = (double)adcChannel/multiplicationfactor;
582 double time_of_flight = RawDataUtil::TofTime(tdcChannel);
583
584
585 double correction_ta=0;
586 if(my_chargein_pc<=2.3)
587 {
588 correction_ta = 268.81-134.586*pow(my_chargein_pc,1)+40.8928*pow(my_chargein_pc,2)+46.9348*pow(my_chargein_pc,3)-31.754*pow(my_chargein_pc,4)
589 +0.62064*pow(my_chargein_pc,5)+1.5672*pow(my_chargein_pc,6);
590 }
591 else
592 {
593 correction_ta= 209.332-31.3283*my_chargein_pc;
594 if(correction_ta<0)correction_ta=0;
595 }
596
597 time_of_flight=time_of_flight - correction_ta/1000.; //Divide by 1000 to convert in ns
598 tdcChannel = RawDataUtil::TofTimeChannel(time_of_flight); //This is the correceted time of flight. All further calcualtion are performed with the corrected version.
599
600 adcChannel = ( (tdcChannel & 0x07e000) | adcChannel);
601 */
602
603 unsigned int tdcChannel = (*iter)->getTimeChannel();
604 unsigned int tdc2Channel = (*iter)->getChargeChannel();
605
606
607 double time_of_flight = RawDataUtil::TofTime(tdcChannel);
608 double pulse_length=RawDataUtil::TofTime(tdc2Channel-tdcChannel);
609 unsigned int pulse_length_channel_without_correction = tdc2Channel-tdcChannel;
610
611 if(pulse_length < 4.164){continue;} // 4.164 ns = 10 fC; Everything smaller is expected to be noise! ->Deposit charge =0;
612
613
614 //Next steps: Do the Time-Amplitude-Correlation:
615 //std::cout << "TofRawDataProvider pulselength channe no_correction "<< tdc2Channel-tdcChannel <<std::endl;
616 //std::cout << "TofRawDataProvider pulselength "<< pulse_length <<std::endl;
617 //std::cout << "TofRawDataProvider tdcChannel no correction "<< tdcChannel <<std::endl;
618 //std::cout << "TofRawDataProvider tof no correction "<< time_of_flight <<std::endl;
619
620 double correction_ta=0;
621 if(pulse_length<=13.9)
622 {
623 correction_ta= 321.2;
624 }
625 else
626 {
627 correction_ta = 72310.5 - 15162.2*pulse_length + 1066.06*pulse_length*pulse_length - 25.0252*pulse_length*pulse_length*pulse_length;
628 if(correction_ta<0)correction_ta=0;
629 }
630
631
632 time_of_flight=time_of_flight - correction_ta/1000.; //Divide by 1000 to convert in ns
633 tdcChannel = RawDataUtil::TofTimeChannel(time_of_flight); //This is the correceted time of flight. All further calcualtion are performed with the corrected version.
634 //std::cout << "TofRawDataProvider correction [ns] "<< correction_ta/1000. <<std::endl;
635 //std::cout << "TofRawDataProvider tdcChannel correct "<< tdcChannel <<std::endl;
636 //std::cout << "TofRawDataProvider tof correct "<< time_of_flight <<std::endl;
637
638
639 //std::cout << "TofRawDataProvider qCorr | qElec " << qCorr << " | " << qElec << std::endl;
640
641
642
643
644
645 //Store HIt information: The time of the first hit is stored in the "TDC" the lenght of the pulse in the "ADC", as the pulse length correspond to charge
646
647 Adc* adc = new Adc;
648 if( qCorr ) adc->setCorr(); //qCorr =0 for MC
649 if( qElec ) adc->setElec(); //qElec= 1 for MC
650
651 //std::cout << "TofRawDataProvider tofDataMapFull() qCorr | qElec " << qCorr << " | "<< qElec << std::endl;
652
653
654
655
656 adc->setValue_mrpc( pulse_length_channel_without_correction,(tdcChannel & 0x07e000) ); //We store the length of the pulse into the ADC information as it corresponds to the charge! The other part is the clock information
657 //std::cout << "TofRawDataProvider adc->number() after initialize " << adc->number() << std::endl;
658 //std::cout << "TofRawDataProvider adc->getValue " << adc->channel() << std::endl;
659 qnumber++;
660 adc->setNumber(qnumber);//old stuff ?????
661 //std::cout << "TofRawDataProvider adc->number() after set " << adc->number() << std::endl;
662
663
664 Tdc* tdc = new Tdc;
665 tdc->setValue( tdcChannel );
666 tnumber++;
667
668 //std::cout << "TofRawDataProvider tdc->number() after initialize " << tdc->number() << std::endl;
669 tdc->setNumber( tnumber );//old stuff ?????
670 //std::cout << "TofRawDataProvider tdc->number() after set " << tdc->number() << std::endl;
671
672
673 qnumber = 0;
674 tnumber = 0;
675
676 //Store the ADC and TDC information into a PMT
677 PmtData* pmt = new PmtData;
678 pmt->setTdc(tdc);
679 pmt->setAdc(adc);
680
681
682 chargeVec.clear();//old stuff
683 timeVec.clear();//old stuff
684
685
686
687 //Store this data into the TOFDATAMAP !
688 unsigned int iden_value_key_mrpc = (iden_value & 0xffffffff ); //The MRPC needs the last bit!
689
690 TofData* tof = new TofData;
691 if( misLable ) { tof->setMisLable(); }
692 tof->setIdentify( iden );
693 tof->setForward( pmt );
694 tof->setTMatched( true );//Sof far only MC data -> Match is true
695
696 //std::cout << "TofRawDataProvider tofDataMapFull(): Set the tofdata Endcap! pmt->adcchanel() = " << (*iter_pmt)->adcChannel() << std::endl;
697 //std::cout << "TofRawDataProvider tofDataMapFull(): Set the tofdata Endcap! tof->adc() = " << tof->adc() << std::endl;
698 //std::cout << "TofRawDataProvider tofDataMapFull(): Set the tofdata Endcap! tof->tdc() = " << tof->tdc() << std::endl;
699 //std::cout << "TofRawDataProvider tofDataMapFull(): Set the tofdata Endcap! tof->adc1() = " << tof->adc1() << std::endl;
700 //std::cout << "TofRawDataProvider tofDataMapFull(): Set the tofdata Endcap! tof->tdc1() = " << tof->tdc1() << std::endl;
701 //std::cout << "TofRawDataProvider tofDataMapFull(): Set the tofdata Endcap! tof->adc2() = " << tof->adc2() << std::endl;
702 //std::cout << "TofRawDataProvider tofDataMapFull(): Set the tofdata Endcap! tof->tdc2() = " << tof->tdc2() << std::endl;
703 //std::cout << "TofRawDataProvider tofDataMapFull(): Set the tofdata Endcap! tof->zadc() = " << tof->zadc() << std::endl;
704 //std::cout << "TofRawDataProvider tofDataMapFull(): Set the tofdata Endcap! tof->ztdc() = " << tof->ztdc() << std::endl;
705
706
707 m_tofDataMap.insert( make_pair( iden_value_key_mrpc, tof ) );
708
709
710
711
712
713 }//close else if new endcap.
714
715
716
717}//close for loop
718
719
720
721 return;
722
723}//close tofDataMapFull
724
725
726// onlineMode only T is combined, no Q reserved
728
729 MsgStream log(m_msgSvc, m_name);
730 log << MSG::INFO << "TofRawDataProvider::tofDataMapOnlineMode()" << endreq;
731
732 if( ! m_tofDataMapOnline.empty() ) {
733 if(control){
734 IterTofDataMap iter = m_tofDataMapOnline.begin();
735 for( ; iter != m_tofDataMapOnline.end(); iter++ ) {
736 delete (*iter).second;
737 }
738 m_tofDataMapOnline.clear();
739 }
740 else return m_tofDataMapOnline;
741 }
742 // tianhl for mt
743 std::string evtDataSvc_name("EventDataSvc");
744 if(isGaudiThreaded(m_name)){
745 evtDataSvc_name += getGaudiThreadIDfromName(m_name);
746 }
747 // tianhl for mt
748
749 IDataProviderSvc* eventSvc;
750 StatusCode sc = m_svcLocator->service( evtDataSvc_name.c_str(), eventSvc, true );
751 if( !sc.isSuccess() ) {
752 log << MSG::FATAL << "TofRawDataProvider::tofDataMapOnlineMode(): ERROR Could not load EventDataSvc" << endreq;
753 return m_tofDataMapOnline;
754 }
755
756 // get TDS data in a common class
757 SmartDataPtr<TofDigiCol> tofDigiCol(eventSvc,"/Event/Digi/TofDigiCol");
758 if( !tofDigiCol ) {
759 log << MSG::WARNING << "TofRawDataProvider::tofDataMapOnlineMode(): Could not find Tof Digi Data!" << endreq;
760 return m_tofDataMapOnline;
761 }
762
763 TofDigiCol::iterator iter = tofDigiCol->begin();
764 for( ; iter != tofDigiCol->end(); iter++ ) {
765 unsigned int overflow = (*iter)->getOverflow();
766 if( ( overflow & 0xfe000000 ) == 0xfe000000 ) continue;
767 // overflow 0x 1 1 1 1 1 1
768 // no Q T / multi Q T / overflow Q T
769
770 bool noT = ( ( overflow & 0x10 ) != 0 );
771 // bool multiQ = ( ( overflow & 0x8 ) != 0 );
772 // bool multiT = ( ( overflow & 0x4 ) != 0 );
773 if( noT ) continue;
774
775 Identifier iden = (*iter)->identify();
776 unsigned int iden_value = iden.get_value();
777 int barrel_ec = TofID::barrel_ec(iden);
778 int id = TofID::phi_module(iden);
779 int end = TofID::end(iden);
780 if( ( barrel_ec != 1 ) && ( end == 1 ) ) continue;
781 if( ( barrel_ec != 1 ) && ( id == 48 ) ) continue;
782
783 unsigned int tdcChannel = (*iter)->getTimeChannel();
784 if( tdcChannel == 0x7fffffff ) continue;
785
786 Tdc* tdc = new Tdc;
787 tdc->setValue( tdcChannel );
788 PmtData* pmt = new PmtData;
789 pmt->setTdc( tdc );
790
791 unsigned int iden_value_key = ( iden_value & 0xfffffffe );
792
793 if( barrel_ec == 0 || barrel_ec == 2 ) {
794 TofData* tof = new TofData;
795 tof->setIdentify( iden );
796 tof->setForward( pmt );
797 m_tofDataMapOnline.insert( make_pair( iden_value_key, tof ) );
798 }
799 else if( barrel_ec == 1 ) {
800 unsigned int count = m_tofDataMapOnline.count( iden_value_key );
801
802 if( count == 0 ) {
803 TofData* tof = new TofData;
804 tof->setIdentify( iden );
805 if( end == 0 ) {
806 tof->setForward( pmt );
807 }
808 else {
809 tof->setBackward( pmt );
810 }
811 m_tofDataMapOnline.insert( make_pair( iden_value_key, tof ) );
812 }
813 else {
814 bool used = false;
815 pair< IterTofDataMap, IterTofDataMap > range = m_tofDataMapOnline.equal_range( iden_value_key );
816 IterTofDataMap iter = range.first;
817 for( unsigned int i=0; i<count; i++, iter++ ) {
818 if( ( end == 0 ) && ( ( ( (*iter).second)->quality() & 0x1 ) != 0 ) ) {
819 double time1 = pmt->tdc();
820 double time2 = ((*iter).second)->tdc2();
821 if( abs(time1-time2)<timeDiff ) {
822 used = true;
823 if( ( ( (*iter).second)->quality() & 0x4 ) == 0 ) {
824 ((*iter).second)->setForward( pmt );
825 }
826 else {
827 TofData* tof = new TofData;
828 tof->setIdentify( iden );
829 tof->setForward( pmt );
830 tof->setBackward( ((*iter).second)->backward() );
831 m_tofDataMapOnline.insert( make_pair( iden_value_key, tof ) );
832 }
833 }
834 }
835 else if( ( end == 1 ) && ( ( ((*iter).second)->quality() & 0x4 ) != 0 ) ) {
836 double time1 = ((*iter).second)->tdc1();
837 double time2 = pmt->tdc();
838
839 if( abs(time1-time2)<timeDiff ) {
840 used = true;
841 if( ( ( (*iter).second)->quality() & 0x1 ) == 0 ) {
842 ((*iter).second)->setBackward( pmt );
843 }
844 else {
845 TofData* tof = new TofData;
846 tof->setIdentify( iden );
847 tof->setForward( ((*iter).second)->forward() );
848 tof->setBackward( pmt );
849 m_tofDataMapOnline.insert( make_pair( iden_value_key, tof ) );
850 }
851 }
852 }
853 }
854 if( ! used ) {
855 TofData* tof = new TofData;
856 tof->setIdentify( iden );
857 if( end == 0 ) {
858 tof->setForward( pmt );
859 }
860 else {
861 tof->setBackward( pmt );
862 }
863 m_tofDataMapOnline.insert( make_pair( iden_value_key, tof ) );
864 }
865 }
866 }
867 }
868
869 return m_tofDataMapOnline;
870
871}
872
873
875
876 MsgStream log(m_msgSvc, m_name);
877 log << MSG::INFO << "TofRawDataProvider::tofDataVectorOnlineMode()" << endreq;
878
879 if( m_tofDataVectorOnline.size() != 0 ) {
880 if(!control) return m_tofDataVectorOnline;
881 else m_tofDataVectorOnline.clear();
882 }
884 IterTofDataMap iter = tofRawDataMap.begin();
885 for( ; iter != tofRawDataMap.end(); iter++ ) {
886 m_tofDataVectorOnline.push_back( iter->second );
887 }
888
889 return m_tofDataVectorOnline;
890}
891
892
893// Event Start Time, only Time is required.
895
896 if( !m_hasFilled ) {
898 m_hasFilled = true;
899 }
900
901 if( !m_tofDataMapEstime.empty() ) {
902 m_tofDataMapEstime.clear();
903 }
904
905 IterTofDataMap iter = m_tofDataMap.begin();
906 for( ; iter != m_tofDataMap.end(); iter++ ) {
907 if( ( ( ((*iter).second)->quality() & 0x5 ) != 0 ) && ((*iter).second)->tmatched() ) {
908 m_tofDataMapEstime.insert( make_pair( (*iter).first, (*iter).second ) );
909 }
910 }
911
912 iter = m_tofDataMapEstime.begin();
913 while( iter != m_tofDataMapEstime.end() ) {
914 unsigned int iden_value = (*iter).first;
915 unsigned int count = m_tofDataMapEstime.count( iden_value );
916 for( unsigned int i=0; i != count; i++, iter++ ) {
917 ((*iter).second)->setTimes( count );
918 }
919 }
920
921 return m_tofDataMapEstime;
922}
923
924
926 if( m_tofDataVectorEstime.size() != 0 ) return m_tofDataVectorEstime;
927
930 for( ; iter != tofDataMapEstime.end(); iter++ ) {
931 m_tofDataVectorEstime.push_back( iter->second );
932 }
933 return m_tofDataVectorEstime;
934}
935
936
937// TOF reconstruction, both time and charge are required
939
940 if( !m_hasFilled ) {
942 m_hasFilled = true;
943 }
944
945 if( !m_tofDataMapTof.empty() ) {
946 m_tofDataMapTof.clear();
947 }
948
949 IterTofDataMap iter = m_tofDataMap.begin();
950 for( ; iter != m_tofDataMap.end(); iter++ ) {
951 if( ( ( ((*iter).second)->quality() & 0xc ) == 0xc ) || ( ( ((*iter).second)->quality() & 0x3 ) == 0x3 ) ) {
952
953 if( estime > 1.0e-6 ) {
954 double tdc1 = ((*iter).second)->tdc1();
955 double tdc2 = ((*iter).second)->tdc2();
956 bool forward = ( ( ( estime - tdc1 ) < timeBackward ) && ( ( tdc1 - estime ) < timeForward ) );
957 bool backward = ( ( ( estime - tdc2 ) < timeBackward ) && ( ( tdc2 - estime ) < timeForward ) );
958
959 //std::cout << "TofRawDataProvider tdc1: " << tdc1 << std::endl;
960 //std::cout << "TofRawDataProvider tdc2: " << tdc1<< std::endl;
961 //std::cout << "TofRawDataProvider (est - tdc1) | (tdc1 - est): " << estime - tdc1 << " | " << tdc1 - estime<< std::endl;
962 //std::cout << "TofRawDataProvider (est - tdc2) | (tdc2 - est): " << estime - tdc2 << " | " << tdc2 - estime<< std::endl;
963 //std::cout << "TofRawDataProvider bool (est - tdc1)< 24 && (tdc1 - est)<120: " << forward << std::endl;
964 //std::cout << "TofRawDataProvider bool (est - tdc2)< 24 && (tdc2 - est)<120: " << backward << std::endl;
965 if( !forward && !backward ) continue;
966
967
968 }
969
970 m_tofDataMapTof.insert( make_pair( (*iter).first, (*iter).second ) );
971 }
972 }
973
974 iter = m_tofDataMapTof.begin();
975 while( iter != m_tofDataMapTof.end() ) {
976 unsigned int iden_value = (*iter).first;
977 unsigned int count = m_tofDataMapTof.count( iden_value );
978 for( unsigned int i=0; i != count; i++, iter++ ) {
979 ((*iter).second)->setTimes( count );
980 }
981 }
982
983 return m_tofDataMapTof;
984}
985
986
988 if( m_tofDataVectorTof.size() != 0 ) {
989 m_tofDataVectorTof.clear();
990 }
991
994 for( ; iter != tofDataMapTof.end(); iter++ ) {
995 m_tofDataVectorTof.push_back( iter->second );
996 }
997 return m_tofDataVectorTof;
998}
999
1000
1001// EMC reconstruction, only charge are required
1003
1004 if( !m_hasFilled ) {
1006 m_hasFilled = true;
1007 }
1008
1009 if( !m_tofDataMapEmc.empty() ) {
1010 m_tofDataMapEmc.clear();
1011 }
1012
1013 IterTofDataMap iter = m_tofDataMap.begin();
1014 for( ; iter != m_tofDataMap.end(); iter++ ) {
1015 if( ( ((*iter).second)->quality() & 0xa ) != 0 ) {
1016
1017 if( estime > 1.0e-6 ) {
1018 int t0clock = static_cast<int>(estime/24.0);
1019 int clock1 = ((*iter).second)->qclock1();
1020 int clock2 = ((*iter).second)->qclock2();
1021 bool forward = ( ( ( t0clock - clock1 ) < tClockBackward ) && ( ( clock1 - t0clock ) < tClockForward ) );
1022 bool backward = ( ( ( t0clock - clock2 ) < tClockBackward ) && ( ( clock2 - t0clock ) < tClockForward ) );
1023 if( !forward && !backward ) continue;
1024 }
1025
1026 m_tofDataMapEmc.insert( make_pair( (*iter).first, (*iter).second ) );
1027 }
1028 }
1029
1030 iter = m_tofDataMapEmc.begin();
1031 while( iter != m_tofDataMapEmc.end() ) {
1032 unsigned int iden_value = (*iter).first;
1033 unsigned int count = m_tofDataMapEmc.count( iden_value );
1034 for( unsigned int i=0; i != count; i++, iter++ ) {
1035 ((*iter).second)->setTimes( count );
1036 }
1037 }
1038
1039 return m_tofDataMapEmc;
1040}
1041
1042
1044 if( m_tofDataVectorEmc.size() != 0 ) {
1045 m_tofDataVectorEmc.clear();
1046 }
1047
1050 for( ; iter != tofDataMapEmc.end(); iter++ ) {
1051 m_tofDataVectorEmc.push_back( iter->second );
1052 }
1053 return m_tofDataVectorEmc;
1054}
double abs(const EvtComplex &c)
Definition: EvtComplex.hh:212
EvtStreamInputIterator< typename Generator::result_type > iter(Generator gen, int N=0)
ITofQElecSvc * tofQElecSvc
ITofQCorrSvc * tofQCorrSvc
std::multimap< unsigned int, TofData * > TofDataMap
Definition: TofData.h:244
std::vector< TofData * > TofDataVector
Definition: TofData.h:247
std::multimap< unsignedint, TofData * >::iterator IterTofDataMap
Definition: TofData.h:245
ITofQElecSvc * tofQElecSvc
ITofQCorrSvc * tofQCorrSvc
ITofCaliSvc * tofCaliSvc
const double tClockBackward
const double tClockForward
const double timeDiff
const double timeForward
const double tClockDiff
const double timeBackward
Definition: TofData.h:43
void setElec()
Definition: TofData.h:48
void setCorr()
Definition: TofData.h:47
void setValue_mrpc(int value, int clock)
Definition: TofData.cxx:77
void setValue(int value)
Definition: TofData.cxx:85
virtual const int BrWest(unsigned int No)=0
virtual const int QElec()=0
virtual const int BrEast(unsigned int No)=0
virtual const int QCorr()=0
virtual const int MisLable()=0
virtual const int Endcap(unsigned int No)=0
value_type get_value() const
Definition: Identifier.h:163
void setAdc(Adc *adc)
Definition: TofData.cxx:398
double tdc()
Definition: TofData.cxx:270
void qtimesmm()
Definition: TofData.cxx:308
double adc()
Definition: TofData.cxx:238
void setTdc(Tdc *tdc)
Definition: TofData.cxx:408
unsigned int quality() const
Definition: TofData.h:88
StatusCode initialize(ISvcLocator *svcLoc=0, IMessageSvc *pMsg=0)
ISvcLocator * m_svcLocator
static unsigned int TofTimeChannel(double time)
Definition: RawDataUtil.h:64
static double TofTime(unsigned int timeChannel)
Definition: RawDataUtil.h:63
Definition: TofData.h:63
void setValue(int value)
Definition: TofData.cxx:48
unsigned int quality() const
Definition: TofData.h:170
int ttimes1()
Definition: TofData.cxx:760
void setForward(PmtData *pmt)
Definition: TofData.cxx:907
void setTMatched(bool tmatched)
Definition: TofData.h:207
void setBackward(PmtData *pmt)
Definition: TofData.cxx:926
int ttimes2()
Definition: TofData.cxx:778
void setIdentify(Identifier identify)
Definition: TofData.cxx:503
void setMisLable()
Definition: TofData.h:201
static int end(const Identifier &id)
Definition: TofID.cxx:129
static int phi_module(const Identifier &id)
Definition: TofID.cxx:117
static int barrel_ec(const Identifier &id)
Values of different levels (failure returns 0)
Definition: TofID.cxx:95
static value_type getIntID(int barrel_ec, int layer, int phi_module, int end)
Definition: TofID.cxx:200
TofDataMap & tofDataMapTof(double estime=0.0)
void handle(const Incident &)
TofDataVector & tofDataVectorTof(double estime=0.0)
TofDataMap & tofDataMapOnlineMode(uint32_t control=1)
TofDataMap & tofDataMapEstime()
TofDataVector & tofDataVectorEmc(double estime=0.0)
TofDataVector & tofDataVectorEstime()
TofDataVector & tofDataVectorOnlineMode(uint32_t control=1)
StatusCode initialize(bool mode=false, ISvcLocator *svcLoc=0, IMessageSvc *pMsg=0)
TofDataMap & tofDataMapEmc(double estime=0.0)
void setNumber(int number)
Definition: TofData.h:26