BOSS 7.0.6
BESIII Offline Software System
Loading...
Searching...
No Matches
BesTrigL1.cxx
Go to the documentation of this file.
1#include "GaudiKernel/AlgFactory.h"
2#include "GaudiKernel/MsgStream.h"
3#include "GaudiKernel/ISvcLocator.h"
4#include "GaudiKernel/SmartDataPtr.h"
5#include "GaudiKernel/Bootstrap.h"
6#include "GaudiKernel/IDataProviderSvc.h"
7#include "GaudiKernel/PropertyMgr.h"
8#include "GaudiKernel/IHistogramSvc.h"
9
10#include "CLHEP/Units/PhysicalConstants.h"
11#include <CLHEP/Geometry/Point3D.h>
12
13#include "MdcRawEvent/MdcDigi.h"
14#include "TofRawEvent/TofDigi.h"
15#include "EmcRawEvent/EmcDigi.h"
16#include "MucRawEvent/MucDigi.h"
17#include "McTruth/MucMcHit.h"
19#include "EventModel/Event.h"
21#include "TrigEvent/TrigEvent.h"
22#include "TrigEvent/TrigData.h"
23#include "TrigEvent/TrigGTD.h"
24#include "TrigEvent/TrigTOFT.h"
25#include "TrigEvent/TrigEACC.h"
28#include "Identifier/MdcID.h"
29#include "Identifier/TofID.h"
30#include "Identifier/MucID.h"
31#include "McTruth/McParticle.h"
34
36
39#include "Trigger/BesTrigL1.h"
40#include "Trigger/AsciiData.h"
41#include "Trigger/TrigPara.h"
42#include <TGraph.h>
43#include <TCanvas.h>
44#include "CLHEP/Random/Random.h"
45#include "CLHEP/Random/RandFlat.h"
46#include "CLHEP/Random/RandGauss.h"
47#include <math.h>
48#include <map>
49
50using namespace CLHEP;
51using namespace std;
52using namespace Event;
53
54// Declaration of the Algorithm Factory
55//static const AlgFactory<BesTrigL1> s_factory ;
56//const IAlgFactory& BesTrigL1Factory = s_factory ;
57BesTrigL1::BesTrigL1(const std::string& name, ISvcLocator* pSvcLocator) :
58 Algorithm(name, pSvcLocator), m_pIBGT(0),passNo(0)
59{
60 declareProperty("WriteFile", writeFile=0);
61 declareProperty("IfOutEvtId",ifoutEvtId=0);
62 declareProperty("Input",input="boost.dat");
63 declareProperty("Output",output="boostOut.dat");
64 declareProperty("OutEvtIdFile",outEvtId="evtId.dat");
65 declareProperty("TrigRootFlag", mTrigRootFlag=false);
66 declareProperty("RunMode", m_runMode=1);
67 declareProperty("ClockShift", clock_shift=0);
68 nEvent = 0;
69}
70
71// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
73 MsgStream log(msgSvc(), name());
74 log << MSG::INFO << "in initialize()" << endreq;
75
76 //--------------------------------------
77 // define a pointer of trigger service
78 //--------------------------------------
79 ISvcLocator* svcLocator = Gaudi::svcLocator();
80 StatusCode sc = svcLocator->service("BesGlobalTrigSvc", m_tmpSvc);
81 m_pIBGT = dynamic_cast<BesGlobalTrigSvc* >(m_tmpSvc);
82 if(sc!=StatusCode::SUCCESS) {
83 log<<MSG::DEBUG<< "Unable to open trigger service"<<endreq;
84 }
85
86 // set run mode, 0: online, 1: offline
87 m_pIBGT->setRunMode(m_runMode);
88
89 //--------------------------------------------------------------
90 // define a pointer of RawDataProviderSvc, used in tof trigger
91 //--------------------------------------------------------------
92 static const bool CREATEIFNOTTHERE(true);
93 sc = service ("RawDataProviderSvc", m_rawDataProviderSvc, CREATEIFNOTTHERE);
94 if ( !sc.isSuccess() ) {
95 log<<MSG::ERROR << "Could not load RawDataProviderSvc!" << m_rawDataProviderSvc << endreq;
96 return sc;
97 }
98
99 //--------------------------------------------------------------
100 // use realization service to get trigger configure parameters
101 //--------------------------------------------------------------
102 IRealizationSvc *tmpReal;
103 sc = svcLocator->service("RealizationSvc",tmpReal);
104 if (!sc.isSuccess())
105 {
106 cout << "FATAL: Could not initialize Realization Service" << endl;
107 } else {
108 m_RealizationSvc=dynamic_cast<RealizationSvc*>(tmpReal);
109 }
110
111 //-----------------------------------------------------------------------
112 // use EmcCalibConstSvc to convert crystal id(theta, phi) to global id.
113 //-----------------------------------------------------------------------
114 sc = svcLocator->service("EmcCalibConstSvc", emcCalibConstSvc);
115 if(sc != StatusCode::SUCCESS) {
116 cout << "EmcRecDigit2Hit Error: Can't get EmcCalibConstSvc." << endl;
117 }
118
119 if(mTrigRootFlag) {
120 //-----------------------------------------
121 // define ntuples for performance check
122 //-----------------------------------------
123 NTuplePtr nt(ntupleSvc(),"FILE302/trig1");
124 if ( nt ) m_tuple = nt;
125 else {
126 m_tuple=ntupleSvc()->book("FILE302/trig1",CLID_ColumnWiseTuple,"TrigL1");
127 if(m_tuple) {
128 sc = m_tuple->addItem ("x",m_wire_x);
129 sc = m_tuple->addItem ("y",m_wire_y);
130 sc = m_tuple->addItem ("evtId",m_wire_evtId);
131 sc = m_tuple->addItem ("delta_t",m_delta_tdc);
132 }
133 else {
134 log << MSG::ERROR <<"Cannot book N-tuple:" << long(m_tuple) << endmsg;
135 return StatusCode::FAILURE;
136 }
137 }
138
139 NTuplePtr nt1(ntupleSvc(),"FILE302/trig2");
140 if ( nt1 ) m_tuple1 = nt1;
141 else {
142 m_tuple1=ntupleSvc()->book("FILE302/trig2",CLID_ColumnWiseTuple,"TrigL1");
143 if( m_tuple1 ) {
144 sc = m_tuple1->addItem ("RunId", m_RunId);
145 sc = m_tuple1->addItem ("EventId", m_EventId);
146 sc = m_tuple1->addItem ("mc_totE_all", m_mc_totE_all);
147 sc = m_tuple1->addItem ("data_totE_all", m_data_totE_all);
148 sc = m_tuple1->addItem ("mc_wetotE", m_wetotE);
149 sc = m_tuple1->addItem ("data_wetotE", m_data_wetotE);
150 sc = m_tuple1->addItem ("mc_eetotE", m_eetotE);
151 sc = m_tuple1->addItem ("data_eetotE", m_data_eetotE);
152 sc = m_tuple1->addItem ("index_btc", m_index_btc, 0, 330);
153 sc = m_tuple1->addIndexedItem ("btc_e", m_index_btc, m_btc_e);
154 sc = m_tuple1->addIndexedItem ("data_btc", m_index_btc, m_data_btc);
155 sc = m_tuple1->addItem ("cond_id", m_cond_id, 0, 48);
156 sc = m_tuple1->addIndexedItem ("mc_cond", m_cond_id, m_mc_cond);
157 sc = m_tuple1->addIndexedItem ("data_cond", m_cond_id, m_data_cond);
158 sc = m_tuple1->addItem ("block_id", m_block_id, 0, 12);
159 sc = m_tuple1->addIndexedItem ("mc_blockE", m_block_id, m_mc_blockE);
160 sc = m_tuple1->addIndexedItem ("data_blockE", m_block_id, m_data_blockE);
161 sc = m_tuple1->addIndexedItem ("R_blockE", m_block_id, m_R_blockE);
162 }
163 else { // did not manage to book the N tuple....
164 log << MSG::ERROR <<"Cannot book N-tuple1:" << long(m_tuple1) << endmsg;
165 return StatusCode::FAILURE;
166 }
167 }
168
169
170 NTuplePtr nt2(ntupleSvc(),"FILE302/muc");
171 if ( nt2 ) m_tuple2 = nt2;
172 else {
173 m_tuple2=ntupleSvc()->book("FILE302/muc",CLID_ColumnWiseTuple,"TrigL1");
174 if( m_tuple2 ) {
175 sc = m_tuple2->addItem ("indexlayerSeg", m_index2, 0, 5000);
176 sc = m_tuple2->addIndexedItem ("nlayerSeg", m_index2, m_fireLayer,0,5000);
177 sc = m_tuple2->addItem ("indexhitLayer", m_index3, 0, 5000);
178 sc = m_tuple2->addIndexedItem ("nhitLayer", m_index3, m_hitLayer, 0, 5000);
179 sc = m_tuple2->addItem ("indexhitSeg", m_index4, 0, 5000);
180 sc = m_tuple2->addIndexedItem ("nhitSeg", m_index4, m_hitSeg, 0, 5000);
181 sc = m_tuple2->addItem ("indexpara", m_index5, 0, 5000);
182 sc = m_tuple2->addIndexedItem ("costheta", m_index5, m_costheta, 0, 5000);
183 sc = m_tuple2->addIndexedItem ("phi", m_index5, m_phi, 0, 5000);
184 sc = m_tuple2->addIndexedItem ("p", m_index5, m_p, 0, 5000);
185 sc = m_tuple2->addIndexedItem ("pdgcode", m_index5, m_pdgcode, 0, 5000);
186 sc = m_tuple2->addItem ("indexhitphi", m_index6, 0, 5000);
187 sc = m_tuple2->addIndexedItem ("hitphi", m_index6, m_hitphi, 0, 5000);
188
189 sc = m_tuple2->addItem ("nlayerEE", m_nlayerEE);
190 sc = m_tuple2->addItem ("nlayerBR", m_nlayerBR);
191 sc = m_tuple2->addItem ("nlayerWE", m_nlayerWE);
192 sc = m_tuple2->addItem ("nlayerTotal", m_nlayerTotal);
193 sc = m_tuple2->addItem ("nhitEE", m_nhitEE);
194 sc = m_tuple2->addItem ("nhitBR", m_nhitBR);
195 sc = m_tuple2->addItem ("nhitWE", m_nhitWE);
196 sc = m_tuple2->addItem ("nhitTotal", m_nhitTotal);
197
198 sc = m_tuple2->addItem ("mumcostheta", m_mumcostheta);
199 sc = m_tuple2->addItem ("mumphi", m_mumphi);
200
201 sc = m_tuple2->addItem ("trackfindall", m_trackfindall);
202 sc = m_tuple2->addItem ("trackfind3l", m_trackfind3l);
203 sc = m_tuple2->addItem ("trackb", m_trackb);
204 sc = m_tuple2->addItem ("tracke", m_tracke);
205 sc = m_tuple2->addItem ("ntrack1", m_ntrack1);
206 sc = m_tuple2->addItem ("ntrack2", m_ntrack2);
207 sc = m_tuple2->addItem ("ntrack3", m_ntrack3);
208
209 sc = m_tuple2->addItem ("ngoodevent", m_ngoodevent);
210 sc = m_tuple2->addItem ("ngoodtrack", m_ngoodtrack);
211 }
212 else { // did not manage to book the N tuple....
213 log << MSG::ERROR <<"Cannot book N-tuple2:" << long(m_tuple2) << endmsg;
214 return StatusCode::FAILURE;
215 }
216 }
217
218 NTuplePtr nt3(ntupleSvc(),"FILE302/trig3");
219 if ( nt3 ) m_tuple3 = nt3;
220 else {
221 m_tuple3=ntupleSvc()->book("FILE302/trig3",CLID_ColumnWiseTuple,"TrigL1");
222 if( m_tuple3 ) {
223 sc = m_tuple3->addItem ("evtId", m_evtId);
224 for(int index = 0; index < 48; index++) {
225 std::ostringstream osname1;
226 osname1 << "cond"<<index<<"_1";
227 std::string name1 = osname1.str();
228
229 std::ostringstream osname2;
230 osname2 << "cond"<<index<<"_0";
231 std::string name2 = osname2.str();
232 m_tuple3->addItem(name1.c_str(), m_condNOne[index]);
233 m_tuple3->addItem(name2.c_str(), m_condNZero[index]);
234 }
235
236 }
237 else { // did not manage to book the N tuple....
238 log << MSG::ERROR <<"Cannot book N-tuple3:" << long(m_tuple3) << endmsg;
239 return StatusCode::FAILURE;
240 }
241 }
242 }
243
244 // pointer of mdc trigger
245 m_MdcTSF = MdcTSF::get_Mdc();
246
247 // pointer of tof trigger
248 m_TofHitCount = TofHitCount::get_Tof();
249
250 // pointer of emc trigger
251 m_emcDigi = EmcTCFinder::get_Emc();
252
253 // pointer of muc trigger
254 m_mucDigi = MucTrigHit::get_Muc();
255
256 //-------------------------------------
257 // reset total track and event number
258 //-------------------------------------
259 totalEvent = 0;
260 totalTracks = 0;
261
262 if(mTrigRootFlag) {
263 sc = service("THistSvc", m_thistsvc);
264 if(sc.isFailure() ){
265 log << MSG::INFO << "Unable to retrieve pointer to THistSvc" << endreq;
266 return sc;
267 }
268 m_trigCondi_MC = new TH1F( "trgCond_MC", "trgCond_MC", 48, 0, 48 );
269 sc = m_thistsvc->regHist("/TRG/trgCond_MC", m_trigCondi_MC);
270 m_trigCondi_Data = new TH1F( "trgCond_Data", "trgCond_Data", 48, 0, 48 );
271 sc = m_thistsvc->regHist("/TRG/trgCond_Data", m_trigCondi_Data);
272 }
273
274 //------------------------------------------------------------------
275 // a pointer used to read emc trigger information from eacc board
276 //------------------------------------------------------------------
277 //eacctrig = new TrigEACC("eacc_trig");
278
279 return StatusCode::SUCCESS;
280}
282 MsgStream log(msgSvc(),name());
283
284 log<<MSG::DEBUG<< "in execute()" <<endreq;
285
286 int event, run;
287 ifpass = false;
288
289 //-------------------
290 // get event header
291 //-------------------
292 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),"/Event/EventHeader");
293 if (!eventHeader) {
294 log << MSG::FATAL << "Could not find Event Header" << endreq;
295 return( StatusCode::FAILURE);
296 }
297 run = eventHeader->runNumber();
298 event = eventHeader->eventNumber();
299
300 if(mTrigRootFlag) {
301 // fill run id and event id into ntuple
302 m_RunId = run;
303 m_EventId = event;
304 }
305
306 //-------------------------------------------------------------------
307 // using ascii file for output, but an ascii input file is needed.
308 //-------------------------------------------------------------------
309 if(writeFile==1 && event == 0)
310 {
311 readin.open(input.c_str(),ios_base::in);
312 if(readin) cout<<"Input File is ok "<<input<<endl;
313 readout.open(output.c_str(),ios_base::out);
314 if(readout) cout<<"Output File is ok "<<output<<endl;
315 VERSIONNUM version;
316 readin >> version;
317 readout << version;
318 }
319
320 //---------------------------------
321 // define a map to store mdc hits
322 //---------------------------------
323 multimap<int,uint32_t,less<int> > mdc_hitmap;
324 mdc_hitmap.clear();
325
326 //---------------------------------
327 // define a map to store tof hits
328 //---------------------------------
329 multimap<int,int,less<int> > tof_hitmap;
330 tof_hitmap.clear();
331
332 //----------------------------------------------------
333 // get mdc digits from TDS and save them into a map
334 //----------------------------------------------------
335 SmartDataPtr<MdcDigiCol> mdcDigiCol(eventSvc(),"/Event/Digi/MdcDigiCol");
336 if (!mdcDigiCol) {
337 log << MSG::FATAL << "Could not find MDC digi" << endreq;
338 return( StatusCode::FAILURE);
339 }
340 for(MdcDigiCol::iterator iter3=mdcDigiCol->begin();iter3!=mdcDigiCol->end();iter3++)
341 {
342 Identifier id= (*iter3)->identify();
343 int layer = MdcID::layer(id);
344 int wire = MdcID::wire(id);
345 int tdc = (*iter3)->getTimeChannel();
346 if(tdc < 0x7FFFFFFF && tdc > 0) {
347 if(layer<=19) {
348 typedef pair<int, uint32_t > vpair;
349 uint32_t mdc_Id = (layer & 0xFFFF ) << 16;
350 mdc_Id = mdc_Id | (wire & 0xFFFF);
351 mdc_hitmap.insert(vpair(tdc,mdc_Id));
352 }
353 if(layer>=36&&layer<=39)
354 {
355 typedef pair<int, uint32_t > vpair;
356 uint32_t mdc_Id = (layer & 0xFFFF ) << 16;
357 mdc_Id = mdc_Id | (wire & 0xFFFF);
358 mdc_hitmap.insert(vpair(tdc,mdc_Id));
359 }
360 }
361 }
362
363 //------------------------------------------------------------------
364 // get tof digits from rawDataProviderSvc ant save them into a map
365 //------------------------------------------------------------------
366 TofDataMap tofDigiMap = m_rawDataProviderSvc->tofDataMapEstime();
367 for(TofDataMap::iterator iter3 = tofDigiMap.begin();iter3 != tofDigiMap.end(); iter3++) {
368 Identifier idd = Identifier(iter3->first);
369 TofData * p_tofDigi = iter3->second;
370 int barrel_ec = TofID::barrel_ec(idd);
371 int layer = TofID::layer(idd);
372 int im = TofID::phi_module(idd);
373 if(barrel_ec == 1) {
374 if(((p_tofDigi->quality()) & 0x5) != 0x5) continue;
375 double tdc1 = p_tofDigi->tdc1();
376 double tdc2 = p_tofDigi->tdc2();
377 int tdc;
378 if(tdc1 > tdc2) tdc = (int) tdc1;
379 else tdc = (int) tdc2;
380 typedef pair<int, int > vpair;
381 tdc = tdc;
382 tof_hitmap.insert(vpair(tdc,10000*barrel_ec+1000*layer+im*10));
383 }
384 else {
385 int tdc1 = (int)p_tofDigi->tdc1();
386 typedef pair<int, int > vpair;
387 tdc1 = tdc1;
388 tof_hitmap.insert(vpair(tdc1,10000*barrel_ec+1000*layer+im*10));
389 }
390 }
391
392 //--------------------------
393 // get emc digits from TDS
394 //--------------------------
395 SmartDataPtr<EmcDigiCol> emcDigiCol(eventSvc(),"/Event/Digi/EmcDigiCol");
396 if (!emcDigiCol) {
397 log << MSG::FATAL << "Could not find EMC digi" << endreq;
398 return( StatusCode::FAILURE);
399 }
400
401 //----------------------------------------------------------
402 // define initialize waveform object for each energy block
403 //----------------------------------------------------------
404 EmcWaveform blockWave[16];
405
406 //------------------------------------------------------------
407 // define a map of trigger cell, contains time and id infor.
408 //------------------------------------------------------------
409 multimap<int,uint32_t,less<int> > emc_TC;
410 emc_TC.clear();
411
412 //---------------------------------------------------------------------------------
413 // get emc analog signal, including trigger cell, energy block and cluster infor.
414 //---------------------------------------------------------------------------------
415 getEmcAnalogSig(emcDigiCol, blockWave, emc_TC);
416
417 //-----------------------------------
418 // find peak time of energy block
419 //-----------------------------------
420 double peak_time = 0;
421 findEmcPeakTime(peak_time, blockWave);
422
423 //--------------------------
424 // get muc digits from TDS
425 //--------------------------
426 SmartDataPtr<MucDigiCol> mucDigiCol(eventSvc(),"/Event/Digi/MucDigiCol");
427 if (!mucDigiCol) {
428 log << MSG::FATAL << "Could not find MUC digi" << endreq;
429 return( StatusCode::FAILURE);
430 }
431 if(m_mucDigi) m_mucDigi->getMucDigi(mucDigiCol);
432
433 //----------------------------------------------
434 // output for debugging and count event number
435 //----------------------------------------------
436 if(event%10000 == 0) std::cout << "---> EventNo is " << event << std::endl;
437 nEvent++;
438
439 //********************************************************************
440 // start time clock
441 //********************************************************************
442
443 //--------------------------
444 // find start and end time
445 //--------------------------
446 double stime = -1, etime = -1;
447 findSETime(mdc_hitmap,tof_hitmap,emc_TC,stime,etime);
448
449 // calculate total clock number
450 int nclock = 0;
451 if(stime >= 0) {
452 nclock = int ((etime - stime)/24) + 1;
453 }
454 else {
455 nclock = 0;
456 }
457
458 //------------------------------------------------------------
459 // define an array to store trigger conditions in each clock
460 //------------------------------------------------------------
461 int** trgcond = new int*[48];
462 for(int condId = 0; condId < 48; condId++) {
463 trgcond[condId] = new int[nclock];
464 }
465
466 // used for tof status machine
467 int idle_status = -1;
468
469 for(int iclock = 0; iclock < nclock; iclock++) {
470 //---------------------------
471 // start mdc trigger logic
472 //---------------------------
473 runAclock_mdc(iclock, stime, mdc_hitmap);
474
475 //---------------------------
476 // start tof trigger logic
477 //---------------------------
478 runAclock_tof(iclock, stime, idle_status, tof_hitmap);
479
480 //--------------------------
481 // start emc trigger logic
482 //--------------------------
483 runAclock_emc(iclock, stime, emc_TC, blockWave);
484
485 //----------------------------------
486 // start track match trigger logic
487 //----------------------------------
488 //m_pIBGT->startTMTrig();
489
490 //--------------------------
491 // set trigger conditions
492 //--------------------------
493 StatusCode status = m_pIBGT->setTrigCondition();
494 if(status!=StatusCode::SUCCESS) {
495 log<<MSG::FATAL<< "Could not set trigger condition index" <<endreq;
496 return StatusCode::FAILURE;
497 }
498
499 //--------------------------------------------
500 // get each trigger condition in each clock
501 //--------------------------------------------
502 for(int condId = 0; condId < 48; condId++) {
503 trgcond[condId][iclock] = m_pIBGT->getTrigCond(condId);
504 }
505 }
506
507 //------------------------------
508 // stretch trigger conditions
509 //------------------------------
510 stretchTrgCond(nclock, trgcond);
511
512 //-------------------------
513 // SAF delay
514 //-------------------------
515 //trgSAFDelay(nclock, trgcond);
516
517 //-------------------------
518 // GTL delay
519 //-------------------------
520 //trgGTLDelay(nclock, trgcond);
521
522
523 //********************************************************************
524 // end time clock
525 //********************************************************************
526
527
528 //-------------------------------------------------------------------------------------------------------------------
529 // deal with emc trigger conditions, in principle, if NClus>=1 is true between peaktime - 1.6us and peak time,
530 // other emc conditions can be true, but not used now.
531 //-------------------------------------------------------------------------------------------------------------------
532 bool ifClus1 = false;
533 for(int i = 0; i < nclock; i++) {
534 if(trgcond[0][i] > 0) ifClus1 = true;
535 }
536
537 if(ifClus1 == false) {
538 for(int i = 0; i < nclock; i++) {
539 for(int j = 0; j < 16; j++) {
540 trgcond[j][i] = 0;
541 }
542 }
543 }
544
545 //-----------------------------------------------------------
546 // do logic 'or' for each trigger condition in all clocks.
547 //-----------------------------------------------------------
548 for(int i = 0; i < nclock; i++) {
549 for(int j = 0; j < 48; j++) {
550 if(trgcond[j][i]) m_pIBGT->setTrigCond(j,1);
551 }
552 }
553
554 //----------------------------
555 // match with trigger table
556 //----------------------------
557 m_pIBGT->GlobalTrig();
558
559 //--------------------------------------
560 // this event can pass trigger or not
561 //--------------------------------------
562 ifpass = m_pIBGT->getIfpass();
563 if(ifpass)
564 {
565 passNo++;
566 log<<MSG::INFO<<"pass event number is "<<passNo<<endl;
567 }
568
569 //-------------------------------------------
570 // write out events which can pass trigger.
571 //-------------------------------------------
572 if(writeFile == 2) {
573 if(ifpass)
574 {
575 setFilterPassed(true);
576 }
577 else
578 {
579 setFilterPassed(false);
580 }
581 }
582
583 if(mTrigRootFlag) {
584 //--------------------------------------------
585 // fill histograms, trigger conditions of MC
586 //--------------------------------------------
587 for(int i = 0; i < 48; i++) {
588 bool edge = false;
589 int NOne = 0;
590 m_condNOne[i] = -9;
591 m_condNZero[i] = -9;
592 for(int j = 0; j < nclock; j++) {
593 m_mc_cond[i] += trgcond[i][j];
594 if(trgcond[i][j] != 0) {
595 if (NOne == 0) {
596 m_condNZero[i] = j;
597 m_trigCondi_MC->Fill(i);
598
599 }
600 edge = true;
601 NOne++;
602 }
603 else {
604 edge = false;
605 }
606 if(edge == false && NOne != 0) break;
607 }
608 m_condNOne[i] = NOne;
609 }
610 m_cond_id = 48;
611
612 //-----------------------------------------------
613 // fill histograms, trigger conditions of data
614 //-----------------------------------------------
615 if(m_runMode == 0) {
616 SmartDataPtr<TrigData> trigData(eventSvc(), "/Event/Trig/TrigData");
617 if (!trigData) {
618 log << MSG::FATAL << "Could not find Trigger Data for physics analysis" << endreq;
619 return StatusCode::FAILURE;
620 }
621
622 for(int id = 0; id < 48; id++) {
623 if(trigData->getTrigCondition(id) != 0) { m_trigCondi_Data->Fill(id); }
624 m_data_cond[id] = trigData->getTrigCondition(id);
625 }
626 m_cond_id = 48;
627 }
628 }
629
630 //----------------------------
631 // release memory
632 //----------------------------
633 for(int condId = 0; condId < 48; condId++) {
634 delete trgcond[condId];
635 }
636 delete trgcond;
637
638
639 if(mTrigRootFlag) {
640 m_evtId = event;
641 m_tuple3->write();
642
643 m_mc_totE_all = m_pIBGT->getEmcTotE();
644 m_wetotE = m_pIBGT->getEmcWETotE();
645 m_eetotE = m_pIBGT->getEmcEETotE();
646
647 map<int,vector<complex<int> >, greater<int> > mymap;
648 mymap = m_pIBGT->getEmcClusId();
649 log<<MSG::INFO<<"EMC test: "<<endreq;
650 int emc_btc_id = 0;
651 for(map<int,vector<complex<int> >, greater<int> >::iterator iter=mymap.begin(); iter!=mymap.end(); iter++) {
652 if((iter->first)==1) {
653 for(unsigned int i=0; i<(iter->second).size(); i++) {
654 log<<MSG::INFO<<"barrel theta is "<<(iter->second[i]).real()<<" phi is "<<(iter->second[i]).imag()<<endreq;
655 emc_btc_id++;
656 }
657 }
658 if((iter->first)==0) {
659 for(unsigned int i=0; i<(iter->second).size(); i++)
660 log<<MSG::INFO<<"east theta is "<<(iter->second[i]).real()<<" phi is "<<(iter->second[i]).imag()<<endreq;
661 }
662 if((iter->first)==2) {
663 for(unsigned int i=0; i<(iter->second).size(); i++)
664 log<<MSG::INFO<<"west theta is "<<(iter->second[i]).real()<<" phi is "<<(iter->second[i]).imag()<<endreq;
665 }
666 }
667
668 //retrieve EMC trigger information from EACC
669 /* SmartDataPtr<TrigGTDCol> trigGTDCol(eventSvc(), "/Event/Trig/TrigGTDCol");
670 if (!trigGTDCol) {
671 log << MSG::FATAL << "Could not find Global Trigger Data" << endreq;
672 return StatusCode::FAILURE;
673 }
674 eacctrig->initialize();
675 TrigGTDCol::iterator iter5 = trigGTDCol->begin();
676 for (; iter5 != trigGTDCol->end(); iter5++) {
677 uint32_t size = (*iter5)->getDataSize();
678 const uint32_t* ptr = (*iter5)->getDataPtr();
679 //set EACC trigger data
680 if((*iter5)->getId() == 0xD7) {
681 eacctrig->setEACCTrigData((*iter5)->getId(), (*iter5)->getTimeWindow(), size, ptr);
682 }
683 }
684
685 double bmean[12] = {8.02,10.1,12.3,7.43,14.8,13.0,12.5,13.2,10.9,12.3,14.7,15.7};
686 double bsigma[12] = {0.88,0.52,0.9,0.72,0.7,0.82,0.64,0.78,0.72,0.76,0.54,0.64};
687 vector<double> vblockE = m_pIBGT->getEmcBlockE();
688 for(int blockId = 0; blockId < vblockE.size(); blockId++) {
689 //m_mc_blockE[blockId] = vblockE[blockId];
690 int block_time;
691 m_mc_blockE[blockId] = blockWave[blockId+2].max(block_time)*0.333 - 0xa + RandGauss::shoot(bmean[blockId],bsigma[blockId]);
692 m_data_blockE[blockId] = eacctrig->getBBLKCharge(blockId);
693 float r_blockE;
694 if((eacctrig->getBBLKCharge(blockId) - bmean[blockId]) == 0.) r_blockE = 0;
695 else r_blockE = vblockE[blockId]/(eacctrig->getBBLKCharge(blockId) - bmean[blockId]);
696 if(!(r_blockE >=0. || r_blockE <= 0.)) r_blockE = 0;
697 m_R_blockE[blockId] = r_blockE;
698 }
699 m_block_id = vblockE.size();
700
701 m_data_totE_all = eacctrig->getEMCTotalCharge();
702 //endcap energy
703 int ee_endcap = 0, we_endcap = 0;
704 for(int i = 0; i < 2; i++) {
705 ee_endcap += eacctrig->getEBLKCharge(i);
706 we_endcap += eacctrig->getWBLKCharge(i);
707 }
708 m_data_wetotE = we_endcap;
709 m_data_eetotE = ee_endcap;
710
711 m_data_totE_all = eacctrig->getEMCTotalCharge();
712
713 //fill trigger cell energy
714 int window = eacctrig->getTimeWindow();
715 int index_tc = 0;
716 for(int i=0;i<TrigConf::TCTHETANO_B;i++)
717 for(int j=0;j<TrigConf::TCPHINO_B;j++)
718 {
719 m_btc_e[index_tc] = m_pIBGT->getBTCEnergy(i,j);
720 int if_clus = 0;
721 for(int k = 0; k < window; k++) {
722 if(eacctrig->getBTC(i,j,k) == 1) {
723 if_clus = 1;
724 break;
725 }
726 }
727 m_data_btc[index_tc] = if_clus;
728 index_tc++;
729 }
730 m_index_btc = index_tc;
731
732 index_tc = 0;
733 for(int i =0;i<TrigConf::TCTHETANO_E;i++)
734 for(int j =0;j<TrigConf::TCPHINO_E;j++)
735 {
736 //m_wetc_e[index_tc] = m_pIBGT->getWETCEnergy(i,j);
737 //m_eetc_e[index_tc] = m_pIBGT->getEETCEnergy(i,j);
738 index_tc++;
739 }
740 //m_index_etc = index_tc;
741*/
742 m_tuple1->write();
743
744 //----------------------------------------------
745 // check information of MDC, TOF, EMC output
746 //----------------------------------------------
747 vector<int> vstrkId;
748 vector<int> vltrkId;
749 vstrkId = m_pIBGT->getMdcStrkId();
750 vltrkId = m_pIBGT->getMdcLtrkId();
751 log<<MSG::INFO<<"Mdc test: "<<endreq;
752 for(unsigned int i=0; i<vstrkId.size(); i++) log<<MSG::INFO<<"short is "<<vstrkId[i]<<endreq;
753 for(unsigned int j=0; j<vltrkId.size(); j++) { log<<MSG::INFO<<"long is "<<vltrkId[j]<<endreq; }
754
755 map<int,vector<int>,greater<int> > tofmap;
756 tofmap = m_pIBGT->getTofHitPos();
757 log<<MSG::INFO<<"TOF test: "<<endreq;
758 for(map<int,vector<int>,greater<int> >::iterator iter=tofmap.begin(); iter!=tofmap.end(); iter++) {
759 if(iter->first == 0) {
760 for(unsigned int i=0; i<iter->second.size(); i++) {
761 log<<MSG::INFO<<"east tof Id is "<<iter->second[i]<<endreq;
762 }
763 }
764 if(iter->first == 1) {
765 for(unsigned int i=0; i<iter->second.size(); i++) { log<<MSG::INFO<<" barrel tof Id is "<<iter->second[i]<<endreq; }
766 }
767 if(iter->first == 2) {
768 for(unsigned int i=0; i<iter->second.size(); i++) { log<<MSG::INFO<<"west tof Id is "<<iter->second[i]<<endreq; }
769 }
770 }
771
772 //Fill ntuple for MUC
773 std::vector<int> vtmp;
774
775 vtmp = m_pIBGT->getMuclayerSeg();
776 m_index2 = 0;
777 for(std::vector<int>::iterator iter = vtmp.begin(); iter != vtmp.end(); iter++) {
778 m_fireLayer[m_index2] = (long) *iter;
779 m_index2++;
780 if(m_index2 > m_index2->range().distance()) { break; cerr<<"*********** too many index ************"<<endl; }
781 }
782 //find tracks by count the fired layer number
783 long trackb3=0, tracke3=0, trackb2=0, tracke2=0, trackb1=0, tracke1=0;
784 int trackwe = 0, trackee = 0;
785 for(unsigned int i=0; i<vtmp.size(); i++) {
786 if(0<=vtmp[i]&&vtmp[i]<100) {
787 if((vtmp[i]%10)>=3) { tracke3++; trackee++; }
788 }
789 if(200<=vtmp[i]) {
790 if(((vtmp[i]-200)%10)>=3) { tracke3++; trackwe++; }
791 }
792 if(100<=vtmp[i]&&vtmp[i]<200) {
793 if(((vtmp[i]-100)%10)>=3) trackb3++;
794 }
795 }
796 m_ntrack3 = trackb3 + tracke3;
797
798 for(unsigned int i=0; i<vtmp.size(); i++) {
799 if(0<=vtmp[i]&&vtmp[i]<100) {
800 if((vtmp[i]%10)>=2) tracke2++;
801 }
802 if(200<=vtmp[i]) {
803 if(((vtmp[i]-200)%10)>=2) tracke2++;
804 }
805 if(100<=vtmp[i]&&vtmp[i]<200) {
806 if(((vtmp[i]-100)%10)>=2) trackb2++;
807 }
808 }
809 m_ntrack2 = trackb2 + tracke2;
810
811 for(unsigned int i=0; i<vtmp.size(); i++) {
812 if(0<=vtmp[i]&&vtmp[i]<100) {
813 if((vtmp[i]%10)>=1) tracke1++;
814 }
815 if(200<=vtmp[i]) {
816 if(((vtmp[i]-200)%10)>=1) tracke1++;
817 }
818 if(100<=vtmp[i]&&vtmp[i]<200) {
819 if(((vtmp[i]-100)%10)>=1) trackb1++;
820 }
821 }
822 m_ntrack1 = trackb1 + tracke1;
823 //end of finding tracks by count the fired layer number
824
825 vtmp = m_pIBGT->getMuchitLayer();
826 m_index3 = 0;
827 for(std::vector<int>::iterator iter = vtmp.begin(); iter != vtmp.end(); iter++) {
828 m_hitLayer[m_index3] = (long) *iter;
829 m_index3++;
830 if(m_index3 > m_index3->range().distance()) { break; cerr<<"*********** too many index ************"<<endl; }
831 }
832
833 vtmp = m_pIBGT->getMuchitSeg();
834 m_index4 = 0;
835 for(std::vector<int>::iterator iter = vtmp.begin(); iter != vtmp.end(); iter++) {
836 m_hitSeg[m_index4] = *(iter);
837 m_index4++;
838 if(m_index4 > m_index4->range().distance()) { break; cerr<<"*********** too many index ************"<<endl; }
839 }
840 } // end fill ntuple
841
842 //---------------------------------------------------
843 // write out event number which not passed trigger.
844 //---------------------------------------------------
845 if(ifoutEvtId==1)
846 {
847 ofstream eventnum(outEvtId.c_str(),ios_base::app);
848 if(!ifpass)
849 eventnum<<event<<endl;
850 eventnum.close();
851 }
852
853 //-------------------------------------------------
854 // write out event number which passed trigger.
855 //-------------------------------------------------
856 if(ifoutEvtId==2)
857 {
858 ofstream eventnum(outEvtId.c_str(),ios_base::app);
859 if(ifpass)
860 eventnum<<event<<endl;
861 eventnum.close();
862 }
863
864 //--------------------------------------------------------
865 // write out events (passed trigger) into an ascii file
866 //--------------------------------------------------------
867 if(writeFile==1)
868 {
869 EVENT asciiEvt;
870 readin >> asciiEvt;
871 if(asciiEvt.header.eventNo == event)
872 {
873 if(ifpass==true)
874 readout<<asciiEvt<<endl;
875 }
876 else
877 cout<<"********* Event No. from AsciiFile do not equal Event No. from TDS "
878 <<asciiEvt.header.eventNo<<" "<<event<<endl;
879 }
880
881 //--------------------------------------------------------------
882 // if it is offline mode, register trigger information into TDS
883 //--------------------------------------------------------------
884 if(m_runMode == 1) {
885 const int* trigcond = m_pIBGT->getTrigCond();
886 const int* trigchan = m_pIBGT->getTrigChan();
887 int window = 0;
888 int timing = 0;
889 bool preScale = false;
890
891 StatusCode sc = StatusCode::SUCCESS ;
892 TrigEvent* aTrigEvent = new TrigEvent;
893 sc = eventSvc()->registerObject("/Event/Trig",aTrigEvent);
894 if(sc!=StatusCode::SUCCESS) {
895 log<<MSG::DEBUG<< "Could not register TrigEvent, you can ignore." <<endreq;
896 }
897
898 TrigData* aTrigData = new TrigData(window, timing, trigcond, trigchan, preScale);
899 sc = eventSvc()->registerObject("/Event/Trig/TrigData",aTrigData);
900 if(sc!=StatusCode::SUCCESS) {
901 log<<MSG::ERROR<< "Could not register TrigData!!!!!" <<endreq;
902 }
903 }
904
905 return StatusCode::SUCCESS;
906}
907
909
910 MsgStream msg(msgSvc(), name());
911 msg << MSG::DEBUG << "==> Finalize BesTrigL1" << endreq;
912
913 if(writeFile==1)
914 {
915 readin.close();
916 readout.close();
917 }
918 cout<<"There are total "<< passNo<<" event pass trigger"<<endl;
919 return StatusCode::SUCCESS;
920}
921
922void BesTrigL1::findSETime(multimap<int,uint32_t,less<int> > mdc_hitmap, multimap<int,int,less<int> > tof_hitmap, multimap<int,uint32_t,less<int> > emc_TC,
923 double& stime, double& etime) {
924 std::multimap<int,uint32_t,less<int> >::iterator mdc_iter = mdc_hitmap.begin();
925 double smdctime = -1, emdctime = -1;
926 if(mdc_hitmap.size() != 0) {
927 smdctime = (mdc_iter->first)*0.09375;
928 mdc_iter = mdc_hitmap.end();
929 mdc_iter--;
930 emdctime = (mdc_iter->first)*0.09375;
931 }
932
933 std::multimap<int,int,less<int> >::iterator tof_iter = tof_hitmap.begin();
934 double stoftime = -1, etoftime = -1;
935 if(tof_hitmap.size() != 0) {
936 stoftime = (tof_iter->first);
937 tof_iter = tof_hitmap.end();
938 tof_iter--;
939 etoftime = (tof_iter->first);
940 }
941
942 std::multimap<int,uint32_t,less<int> >::iterator emc_iter = emc_TC.begin();
943 double semctime = -1, eemctime = -1;
944 if(emc_TC.size() != 0) {
945 semctime = (emc_iter->first);
946 emc_iter = emc_TC.end();
947 emc_iter--;
948 eemctime = (emc_iter->first);
949 }
950
951 stime = -1, etime = -1;
952 if(smdctime >= 0 && stoftime >= 0) {
953 if(smdctime > stoftime) stime = stoftime;
954 else stime = smdctime;
955
956 if((emdctime+800) > (etoftime + 24)) etime = emdctime+800;
957 else etime = etoftime + 24;
958 }
959 else if(smdctime < 0 && stoftime >= 0) {
960 stime = stoftime;
961 etime = etoftime + 24;
962 }
963 else if(smdctime >= 0 && stoftime < 0) {
964 stime = smdctime;
965 etime = emdctime+800;
966 }
967 else {
968 stime = -1;
969 etime = -1;
970 }
971 //compare with emc time
972 if(semctime >= 0 && stime >= 0) {
973 if(semctime > stime) stime = stime;
974 else stime = semctime;
975
976 if((eemctime+16*24) > etime) etime = eemctime+16*24;
977 else etime = etime;
978 }
979 else if(semctime < 0 && stime >= 0) {
980 stime = stime;
981 etime = etime;
982 }
983 else if(semctime >= 0 && stime < 0) {
984 stime = semctime;
985 etime = eemctime+16*24;
986 }
987 else {
988 stime = -1;
989 etime = -1;
990 }
991}
992
993void BesTrigL1::runAclock_mdc(int iclock, double stime, multimap<int,uint32_t,less<int> > mdc_hitmap) {
994 std::vector<int> vmdcHit;
995 vmdcHit.clear();
996
997 std::multimap<int,uint32_t,less<int> >::iterator mdc_iter = mdc_hitmap.begin();
998 //int beginclock = int ((mdc_iter->first)*0.09375/24);
999
1000 //--------------------------
1001 // consider mdc noise
1002 //--------------------------
1003 /*
1004 if((iclock - beginclock) >= 0 && (iclock - beginclock) <= 33) {
1005 for(int i = 0; i < 16; i++) {
1006 for(int hit_id = 0; hit_id < 256; hit_id++) {
1007 int layer, wire;
1008 double ratio = -1;
1009 if(i == 0) layer = 8;
1010 if(i == 1) layer = 9;
1011 if(i == 2) layer = 10;
1012 if(i == 3) layer = 11;
1013 if(i == 4) layer = 12;
1014 if(i == 5) layer = 13;
1015 if(i == 6) layer = 14;
1016 if(i == 7) layer = 15;
1017 if(i == 8) layer = 16;
1018 if(i == 9) layer = 17;
1019 if(i == 10) layer = 18;
1020 if(i == 11) layer = 19;
1021 if(i == 12) layer = 36;
1022 if(i == 13) layer = 37;
1023 if(i == 14) layer = 38;
1024 if(i == 15) layer = 39;
1025
1026 if(hit_id < 76) {
1027 if(i == 0) ratio = hit9[hit_id];
1028 if(i == 1) ratio = hit10[hit_id];
1029 }
1030 if(hit_id < 88) {
1031 if(i == 2) ratio = hit11[hit_id];
1032 if(i == 3) ratio = hit12[hit_id];
1033 }
1034 if(hit_id < 100) {
1035 if(i == 4) ratio = hit13[hit_id];
1036 if(i == 5) ratio = hit14[hit_id];
1037 }
1038 if(hit_id < 112) {
1039 if(i == 6) ratio = hit15[hit_id];
1040 if(i == 7) ratio = hit16[hit_id];
1041 }
1042 if(hit_id < 128) {
1043 if(i == 8) ratio = hit17[hit_id];
1044 if(i == 9) ratio = hit18[hit_id];
1045 }
1046 if(hit_id < 140) {
1047 if(i == 10) ratio = hit19[hit_id];
1048 if(i == 11) ratio = hit20[hit_id];
1049 }
1050 if(i == 12) ratio = hit37[hit_id];
1051 if(i == 13) ratio = hit38[hit_id];
1052 if(i == 14) ratio = hit39[hit_id];
1053 if(i == 15) ratio = hit40[hit_id];
1054
1055 wire = hit_id;
1056
1057 if(RandFlat::shoot() < ratio*(33 - iclock)*24/2000.) {
1058 vmdcHit.push_back(layer);
1059 vmdcHit.push_back(wire);
1060 }
1061 }
1062 }
1063 }
1064 */
1065
1066 for(std::multimap<int,uint32_t,less<int> >::iterator mdc_iter = mdc_hitmap.begin(); mdc_iter != mdc_hitmap.end(); mdc_iter++)
1067 {
1068 double time = (mdc_iter->first)*0.09375;
1069 if((time < (stime + (iclock + 1)*24.)) && (time + 800.) > (stime + iclock*24.)) {
1070 uint32_t mdcId = mdc_iter->second;
1071 int layer = (mdcId & 0xFFFF0000 ) >> 16;
1072 int cell = mdcId & 0xFFFF;
1073 bool firstdc = true;
1074 //for(std::multimap<int,int,less<int> >::iterator tmp_mdc = mdc_hitmap.begin(); tmp_mdc != mdc_iter; tmp_mdc++) {
1075 // if(mdcId == (tmp_mdc->second)) firstdc = false;
1076 //}
1077 if(firstdc == true) {
1078 vmdcHit.push_back(layer);
1079 vmdcHit.push_back(cell);
1080 }
1081 }
1082 }
1083
1084 //set mdc vector hit
1085 m_MdcTSF->setMdcDigi(vmdcHit);
1086 m_pIBGT->startMdcTrig();
1087}
1088
1089void BesTrigL1::runAclock_tof(int iclock, double stime, int& idle_status, std::multimap<int,int,less<int> > tof_hitmap) {
1090 std::vector<int> vtofHit;
1091 vtofHit.clear();
1092
1093 //tof trigger
1094 if(idle_status != -1 && (iclock - idle_status) == 3) idle_status = -1;
1095 for(std::multimap<int,int,less<int> >::iterator tof_iter = tof_hitmap.begin(); tof_iter != tof_hitmap.end(); tof_iter++)
1096 {
1097 double time = (tof_iter->first); //ns
1098 if(idle_status == -1) {
1099 if(time < (stime + (iclock + 1)*24) && time >= (stime + iclock*24)) {
1100 //if(time < (stime + (iclock + 1)*24) && (time + 24) > (stime + iclock*24)) { //stretch signal
1101 vtofHit.push_back(tof_iter->second);
1102 }
1103 }
1104 else {
1105 if((iclock - idle_status) == 1) {
1106 if((time < (stime + (iclock + 1)*24) && time >= (stime + iclock*24)) ||
1107 (time < (stime + iclock*24) && time >= (stime + (iclock - 1)*24))
1108 ) {
1109 vtofHit.push_back(tof_iter->second);
1110 }
1111 }
1112 if((iclock - idle_status) == 2) {
1113 if((time < (stime + (iclock + 1)*24) && time >= (stime + iclock*24)) ||
1114 (time < (stime + iclock*24) && time >= (stime + (iclock - 1)*24)) ||
1115 (time < (stime + (iclock - 1)*24) && time >= (stime + (iclock - 2)*24))
1116 ) {
1117 vtofHit.push_back(tof_iter->second);
1118 }
1119 }
1120 }
1121 }
1122 if(idle_status == -1 && vtofHit.size() != 0) idle_status = iclock;
1123
1124 //set tof vector hit
1125 m_TofHitCount->setTofDigi(vtofHit);
1126 m_pIBGT->startTofTrig();
1127}
1128
1129void BesTrigL1::runAclock_emc(int iclock, double stime, std::multimap<int,uint32_t,less<int> > emc_TC, EmcWaveform* blockWave) {
1130 std::vector<uint32_t> vemcClus;
1131 std::vector<double> vemcBlkE;
1132
1133 vemcClus.clear();
1134 vemcBlkE.clear();
1135 //std::cout << "iclock, emc_TC size: " << iclock << ", " << emc_TC.size() << std::endl;
1136 //cluster finding in emc trigger
1137 for(std::multimap<int,uint32_t,less<int> >::iterator emc_iter = emc_TC.begin(); emc_iter != emc_TC.end(); emc_iter++)
1138 {
1139 double time = (emc_iter->first);
1140 if((time < (stime + (iclock + 1)*24.)) && (time + 16*24) > (stime + iclock*24.)) {
1141 vemcClus.push_back(emc_iter->second);
1142 }
1143 }
1144
1145 //energy adding in emc trigger
1146 for(int blockId = 0; blockId < 16; blockId++) {
1147 double block_ADC = (blockWave[blockId]).getADCTrg((int)stime+iclock*24);
1148 vemcBlkE.push_back(block_ADC);
1149 // std::cout << " block_ADC: " << block_ADC << std::endl;
1150 }
1151 //std::cout << "iclock,stime,vemcClus size: " << iclock << "," << stime << ", " << vemcClus.size() << std::endl;
1152 m_emcDigi->setEmcTC(vemcClus);
1153 m_emcDigi->setEmcBE(vemcBlkE); //set block energy
1154 //start EMC trigger logic
1155 m_pIBGT->startEmcTrig();
1156}
1157
1158void BesTrigL1::getEmcAnalogSig(EmcDigiCol* emcDigiCol, EmcWaveform (&blockWave)[16], multimap<int,uint32_t,less<int> >& emc_TC) {
1159 EmcWaveform eewave[32];
1160 EmcWaveform wewave[32];
1161 EmcWaveform bwave[11][30];
1162
1163 for(int i = 0; i < 11; i++) {
1164 for(int j = 0; j < 30; j++) {
1165 bwave[i][j].makeWaveformTrg(0,0);
1166 }
1167 }
1168 for(int i = 0; i < 32; i++) {
1169 if(i < 16) blockWave[i].makeWaveformTrg(0,0);
1170 eewave[i].makeWaveformTrg(0,0);
1171 wewave[i].makeWaveformTrg(0,0);
1172 }
1173
1174 for (EmcDigiCol::iterator iter3=emcDigiCol->begin();iter3!= emcDigiCol->end();iter3++) {
1175 Identifier id=(*iter3)->identify();
1176 unsigned int module = EmcID::barrel_ec(id);
1177 unsigned int theta = EmcID::theta_module(id);
1178 unsigned int phi = EmcID::phi_module(id);
1179
1180 int index = emcCalibConstSvc->getIndex(module,theta,phi);
1181 double trgGain = m_RealizationSvc->getTrgGain(index);
1182 double adc = (double) (*iter3)->getChargeChannel();
1183 double mv = RandGauss::shoot(978.,14.);
1184
1185 if((*iter3)->getMeasure()==0) adc = adc*2*mv*2/65535.*(trgGain);
1186 else if((*iter3)->getMeasure()==1) adc = adc*16*mv*2/65535*(trgGain);
1187 else adc = adc*64*mv*2/65535*(trgGain);
1188
1189 unsigned int tdc = (*iter3)->getTimeChannel();
1190 int theTC = m_emcDigi->getTCThetaId(module,theta,phi);
1191 int phiTC = m_emcDigi->getTCPhiId(module,theta,phi);
1192 EmcWaveform wave1;
1193 if(module == 0) { wave1.makeWaveformTrg(adc,tdc+80); eewave[phiTC] += wave1; }
1194 if(module == 1) { wave1.makeWaveformTrg(adc,tdc+80); bwave[theTC][phiTC] += wave1; }
1195 if(module == 2) { wave1.makeWaveformTrg(adc,tdc+80); wewave[phiTC] += wave1; }
1196 }
1197
1198 //find barrel cluster
1199 for(int i = 0; i < 11; i++) {
1200 for(int j = 0; j < 30; j++) {
1201 int time_low = bwave[i][j].frontEdgeTrg(m_pIBGT->getL1TC_GATE());
1202 int time_high = bwave[i][j].frontEdgeTrg(m_pIBGT->getL1TC_THRESH());
1203 int time = -1;
1204
1205 if(time_high >= 0) {
1206 if(time_low*50+1500 > time_high*50) time = time_low*50 + 1500;
1207 else time = time_high*50;
1208 uint32_t TCID = (1 & 0xFF) << 16;
1209 TCID = TCID | ((i & 0xFF) << 8);
1210 TCID = TCID | (j & 0xFF);
1211 typedef pair<int, uint32_t > vpair;
1212 emc_TC.insert(vpair(time,TCID));
1213 //std::cout <<"i, j: " << i << ", " << j << " time: " << time << std::endl;
1214 }
1215 if(time_low >= 0) {
1216 int blockId = m_emcDigi->getBLKId(i,j);
1217 blockWave[blockId+2] += bwave[i][j];
1218 }
1219 }
1220 }
1221 //find end cap cluster
1222 for(int i = 0; i < 32; i++) {
1223 //east end cap
1224 int time_low1 = eewave[i].frontEdgeTrg(m_pIBGT->getL1TC_GATE());
1225 int time_high1 = eewave[i].frontEdgeTrg(m_pIBGT->getL1TC_THRESH());
1226 int time1 = -1;
1227 if(time_high1 >= 0) {
1228 if(time_low1*50+1500 > time_high1*50) time1 = time_low1*50 + 1500;
1229 else time1 = time_high1*50;
1230 uint32_t TCID1 = (0 & 0xFF) << 16;
1231 TCID1 = TCID1 | ((0 & 0xFF) << 8);
1232 TCID1 = TCID1 | (i & 0xFF);
1233 typedef pair<int, uint32_t > vpair;
1234 emc_TC.insert(vpair(time1,TCID1));
1235 }
1236 if(time_low1 >= 0) {
1237 if(i<16) blockWave[0] += eewave[i];
1238 else blockWave[1] += eewave[i];
1239 }
1240 //west end cap
1241 int time_low2 = wewave[i].frontEdgeTrg(m_pIBGT->getL1TC_GATE());
1242 int time_high2 = wewave[i].frontEdgeTrg(m_pIBGT->getL1TC_THRESH());
1243 int time2 = -1;
1244 if(time_high2 >= 0) {
1245 if(time_low2*50+1500 > time_high2*50) time2 = time_low2*50 + 1500;
1246 else time2 = time_high2*50;
1247 uint32_t TCID2 = (2 & 0xFF) << 16;
1248 TCID2 = TCID2 | ((0 & 0xFF) << 8);
1249 TCID2 = TCID2 | (i & 0xFF);
1250 typedef pair<int, uint32_t > vpair;
1251 emc_TC.insert(vpair(time2,TCID2));
1252 }
1253 if(time_low2 >= 0) {
1254 if(i<16) blockWave[14] += wewave[i];
1255 else blockWave[15] += wewave[i];
1256 }
1257 }
1258}
1259
1260void BesTrigL1::findEmcPeakTime(double& peak_time, EmcWaveform* blockWave) {
1261 double tot_block_max = 0;
1262 for(int i = 0; i < 16; i++) {
1263 int block_time;
1264 double block_max = blockWave[i].max(block_time);
1265 tot_block_max += block_max;
1266 }
1267
1268 for(int i = 0; i < 16; i++) {
1269 if(tot_block_max == 0) break;
1270 int block_time;
1271 double block_max = blockWave[i].max(block_time);
1272 block_time = block_time*50;
1273 peak_time += block_max/tot_block_max*block_time;
1274 }
1275}
1276
1277void BesTrigL1::stretchTrgCond(int nclock, int** & trgcond) {
1278 int emc_clus = 34;
1279 int emc_ener = 50;
1280 int mdc = 34;
1281 int mdc_n = 68;
1282 int tof = 4;
1283 for(int icond = 0; icond < 48; icond++) {
1284 int sclock = -1;
1285 bool retrig = false;
1286 for(int iclock = 0; iclock < nclock; iclock++) {
1287 if(icond < 16) { //stretch emc trigger conditions
1288 if(icond < 7 || icond == 12 || icond == 13) { // stretch cluster trigger conditions
1289 if(sclock != -1 && iclock - sclock == emc_clus) sclock = -1;
1290 if(sclock == -1 && trgcond[icond][iclock] > 0) {
1291 if(iclock == 0) sclock = iclock;
1292 else {
1293 if(trgcond[icond][iclock]*trgcond[icond][iclock-1] == 0) sclock = iclock;
1294 }
1295 }
1296 if(sclock != -1 && iclock - sclock < emc_clus) trgcond[icond][iclock] = 1;
1297 }
1298 else { //stretch emc energy trigger conditions, re-triggering is available
1299 if(sclock != -1 && iclock - sclock == emc_ener) sclock = -1;
1300 if(sclock == -1 && trgcond[icond][iclock] > 0) {
1301 if(iclock == 0) sclock = iclock;
1302 else {
1303 if(trgcond[icond][iclock]*trgcond[icond][iclock-1] == 0) sclock = iclock;
1304 }
1305 }
1306 if(sclock != -1 && iclock - sclock < emc_ener && trgcond[icond][iclock] == 0) retrig = true;
1307 if(retrig == true) {
1308 if(trgcond[icond][iclock] > 0) {
1309 sclock = iclock;
1310 retrig = false;
1311 }
1312 }
1313 if(sclock != -1 && iclock - sclock < emc_ener) trgcond[icond][iclock] = 1;
1314 }
1315 }
1316 else if(icond >= 16 && icond < 23) { //stretch tof trigger conditions
1317 if(sclock != -1 && iclock - sclock == tof) sclock = -1;
1318 if(sclock == -1 && trgcond[icond][iclock] > 0) {
1319 if(iclock == 0) sclock = iclock;
1320 else {
1321 if(trgcond[icond][iclock]*trgcond[icond][iclock-1] == 0) sclock = iclock;
1322 }
1323 }
1324 if(sclock != -1 && iclock - sclock < tof) trgcond[icond][iclock] = 1;
1325 }
1326 else if(icond >= 38) { //stretch mdc trigger conditions
1327 if(icond == 39|| icond == 43) {
1328 if(sclock != -1 && iclock - sclock == mdc_n) sclock = -1;
1329 if(sclock == -1 && trgcond[icond][iclock] > 0) {
1330 if(iclock == 0) sclock = iclock;
1331 else {
1332 if(trgcond[icond][iclock]*trgcond[icond][iclock-1] == 0) sclock = iclock;
1333 }
1334 }
1335 if(sclock != -1 && iclock - sclock < mdc_n) trgcond[icond][iclock] = 1;
1336 }
1337 else {
1338 if(sclock != -1 && iclock - sclock == mdc) sclock = -1;
1339 if(sclock == -1 && trgcond[icond][iclock] > 0) {
1340 if(iclock == 0) sclock = iclock;
1341 else {
1342 if(trgcond[icond][iclock]*trgcond[icond][iclock-1] == 0) sclock = iclock;
1343 }
1344 }
1345 if(sclock != -1 && iclock - sclock < mdc) trgcond[icond][iclock] = 1;
1346 }
1347 }
1348 else { //stretch other trigger conditions, including track match and muc
1349 }
1350 }
1351 }
1352}
1353
1354void BesTrigL1::trgSAFDelay(int nclock, int** & trgcond) {
1355 //SAF delay time
1356// int delay[48] = {31,31,31,31,31,31,31,7,7,7,7,7,31,31,7,7,
1357// 135,135,135,135,135,135,135,83,83,83,6,6,6,83,83,83,
1358// 97,97,97,97,97,97,86,87,85,87,83,85,83,85,122,122};
1359 int delay[48] = {24,24,24,24,24,24,24,7,7,7,7,7,24,24,7,7,
1360 0,0,0,0,0,0,0,83,83,83,6,6,6,83,83,83,
1361 97,97,97,97,97,97,0,0,0,0,0,0,0,0,122,122};
1362
1363 for(int icond = 0; icond < 48; icond++) {
1364 for(int iclock = nclock-1; iclock >= 0; iclock--) {
1365 if(iclock < delay[icond]) trgcond[icond][iclock] = 0;
1366 else {
1367 trgcond[icond][iclock] = trgcond[icond][iclock-delay[icond]];
1368 }
1369 }
1370 }
1371}
1372
1373void BesTrigL1::trgGTLDelay(int nclock, int** & trgcond) {
1374 //GTL delay time
1375 int delay[48] = {1,1,1,1,1,1,1,18,18,18,18,18,1,1,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,14,14,14,14,14,14,10,10,10,10,10,10,10,10,10,10};
1376
1377 for(int icond = 0; icond < 48; icond++) {
1378 for(int iclock = nclock-1; iclock >= 0; iclock--) {
1379 if(iclock < delay[icond]) trgcond[icond][iclock] = 0;
1380 else trgcond[icond][iclock] = trgcond[icond][iclock-delay[icond]];
1381 }
1382 }
1383}
std::string mdc
Definition: CalibModel.cxx:45
ObjectVector< EmcDigi > EmcDigiCol
Definition: EmcDigi.h:43
double imag(const EvtComplex &c)
Definition: EvtComplex.hh:246
EvtStreamInputIterator< typename Generator::result_type > iter(Generator gen, int N=0)
INTupleSvc * ntupleSvc()
IMessageSvc * msgSvc()
std::multimap< unsigned int, TofData * > TofDataMap
Definition: TofData.h:244
StatusCode GlobalTrig()
void setTrigCond(int i, bool j)
map< int, vector< complex< int > >, greater< int > > getEmcClusId()
std::vector< int > getMdcLtrkId()
const int getTrigCond(int i)
std::vector< int > getMdcStrkId()
std::vector< int > getMuchitLayer()
std::vector< int > getMuchitSeg()
const int getTrigChan(int i)
map< int, vector< int >, greater< int > > getTofHitPos()
StatusCode setTrigCondition()
std::vector< int > getMuclayerSeg()
void setRunMode(int mode)
virtual StatusCode execute()
Algorithm execution.
Definition: BesTrigL1.cxx:281
void runAclock_emc(int iclock, double stime, std::multimap< int, uint32_t, less< int > > emc_TC, EmcWaveform *blockWave)
Definition: BesTrigL1.cxx:1129
void findEmcPeakTime(double &peak_time, EmcWaveform *blockWave)
Definition: BesTrigL1.cxx:1260
BesTrigL1(const std::string &name, ISvcLocator *pSvcLocator)
Standard constructor.
Definition: BesTrigL1.cxx:57
void runAclock_tof(int iclock, double stime, int &idle_status, std::multimap< int, int, less< int > > tof_hitmap)
Definition: BesTrigL1.cxx:1089
void getEmcAnalogSig(EmcDigiCol *emcDigiCol, EmcWaveform(&blockWave)[16], multimap< int, uint32_t, less< int > > &emc_TC)
Definition: BesTrigL1.cxx:1158
void trgGTLDelay(int nclock, int **&trgcond)
Definition: BesTrigL1.cxx:1373
void trgSAFDelay(int nclock, int **&trgcond)
Definition: BesTrigL1.cxx:1354
virtual StatusCode finalize()
Algorithm finalization.
Definition: BesTrigL1.cxx:908
void findSETime(multimap< int, uint32_t, less< int > > mdc_hitmap, multimap< int, int, less< int > > tof_hitmap, multimap< int, uint32_t, less< int > > emc_TC, double &stime, double &etime)
Definition: BesTrigL1.cxx:922
virtual StatusCode initialize()
Destructor.
Definition: BesTrigL1.cxx:72
void stretchTrgCond(int nclock, int **&trgcond)
Definition: BesTrigL1.cxx:1277
void runAclock_mdc(int iclock, double stime, multimap< int, uint32_t, less< int > > mdc_hitmap)
Definition: BesTrigL1.cxx:993
EVHEAD header
Definition: AsciiData.hh:393
int eventNo
Definition: AsciiData.hh:27
static unsigned int barrel_ec(const Identifier &id)
Values of different levels (failure returns 0)
Definition: EmcID.cxx:38
static unsigned int theta_module(const Identifier &id)
Definition: EmcID.cxx:43
static unsigned int phi_module(const Identifier &id)
Definition: EmcID.cxx:48
int getTCThetaId(int partId, int ThetaNb, int PhiNb)
static EmcTCFinder * get_Emc(void)
Definition: EmcTCFinder.cxx:32
void setEmcBE(std::vector< double > vBE)
int getTCPhiId(int partId, int ThetaNb, int PhiNb)
void setEmcTC(std::vector< uint32_t > vTC)
int getBLKId(int TCTheta, int TCPhi) const
double max(int &binOfMax) const
Definition: EmcWaveform.cxx:77
void makeWaveformTrg(double energy, double time)
int frontEdgeTrg(double thres)
virtual int getIndex(unsigned int PartId, unsigned int ThetaIndex, unsigned int PhiIndex) const =0
virtual TofDataMap & tofDataMapEstime()=0
static int layer(const Identifier &id)
Values of different levels (failure returns 0)
Definition: MdcID.cxx:49
static int wire(const Identifier &id)
Definition: MdcID.cxx:54
static MdcTSF * get_Mdc(void)
Definition: MdcTSF.cxx:28
void setMdcDigi(std::vector< int > &vmdcHit)
Definition: MdcTSF.cxx:41
static MucTrigHit * get_Muc(void)
Definition: MucTrigHit.cxx:24
void getMucDigi(MucDigiCol *mucDigiCol)
Definition: MucTrigHit.cxx:37
double getTrgGain(int cry_id)
unsigned int quality() const
Definition: TofData.h:168
double tdc2()
Definition: TofData.cxx:665
double tdc1()
Definition: TofData.cxx:647
static TofHitCount * get_Tof(void)
Definition: TofHitCount.cxx:26
void setTofDigi(std::vector< int > &vtofHit)
Definition: TofHitCount.cxx:37
static int phi_module(const Identifier &id)
Definition: TofID.cxx:73
static int barrel_ec(const Identifier &id)
Values of different levels (failure returns 0)
Definition: TofID.cxx:61
static int layer(const Identifier &id)
Definition: TofID.cxx:66
Definition: Event.h:21