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"
10#include "CLHEP/Units/PhysicalConstants.h"
11#include <CLHEP/Geometry/Point3D.h>
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"
18#include "EventModel/EventModel.h"
19#include "EventModel/Event.h"
20#include "EventModel/EventHeader.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"
26#include "RawDataProviderSvc/TofData.h"
27#include "Identifier/Identifier.h"
28#include "Identifier/MdcID.h"
29#include "Identifier/TofID.h"
30#include "Identifier/MucID.h"
31#include "McTruth/McParticle.h"
32#include "EvTimeEvent/RecEsTime.h"
33#include "EmcWaveform/EmcWaveform.h"
35#include "EmcCalibConstSvc/EmcCalibConstSvc.h"
37#include "Trigger/IBesGlobalTrigSvc.h"
38#include "Trigger/BesGlobalTrigSvc.h"
39#include "Trigger/BesTrigL1.h"
40#include "Trigger/AsciiData.h"
41#include "Trigger/TrigPara.h"
44#include "CLHEP/Random/Random.h"
45#include "CLHEP/Random/RandFlat.h"
46#include "CLHEP/Random/RandGauss.h"
58 Algorithm(name, pSvcLocator), m_pIBGT(0),passNo(0)
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);
73 MsgStream log(
msgSvc(), name());
74 log << MSG::INFO <<
"in initialize()" << endreq;
79 ISvcLocator* svcLocator = Gaudi::svcLocator();
80 StatusCode sc = svcLocator->service(
"BesGlobalTrigSvc", m_tmpSvc);
82 if(sc!=StatusCode::SUCCESS) {
83 log<<MSG::DEBUG<<
"Unable to open trigger service"<<endreq;
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;
103 sc = svcLocator->service(
"RealizationSvc",tmpReal);
106 cout <<
"FATAL: Could not initialize Realization Service" << endl;
114 sc = svcLocator->service(
"EmcCalibConstSvc", emcCalibConstSvc);
115 if(sc != StatusCode::SUCCESS) {
116 cout <<
"EmcRecDigit2Hit Error: Can't get EmcCalibConstSvc." << endl;
123 NTuplePtr nt(
ntupleSvc(),
"FILE302/trig1");
124 if ( nt ) m_tuple = nt;
126 m_tuple=
ntupleSvc()->book(
"FILE302/trig1",CLID_ColumnWiseTuple,
"TrigL1");
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);
134 log << MSG::ERROR <<
"Cannot book N-tuple:" << long(m_tuple) << endmsg;
135 return StatusCode::FAILURE;
139 NTuplePtr nt1(
ntupleSvc(),
"FILE302/trig2");
140 if ( nt1 ) m_tuple1 = nt1;
142 m_tuple1=
ntupleSvc()->book(
"FILE302/trig2",CLID_ColumnWiseTuple,
"TrigL1");
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);
164 log << MSG::ERROR <<
"Cannot book N-tuple1:" << long(m_tuple1) << endmsg;
165 return StatusCode::FAILURE;
170 NTuplePtr nt2(
ntupleSvc(),
"FILE302/muc");
171 if ( nt2 ) m_tuple2 = nt2;
173 m_tuple2=
ntupleSvc()->book(
"FILE302/muc",CLID_ColumnWiseTuple,
"TrigL1");
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);
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);
198 sc = m_tuple2->addItem (
"mumcostheta", m_mumcostheta);
199 sc = m_tuple2->addItem (
"mumphi", m_mumphi);
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);
209 sc = m_tuple2->addItem (
"ngoodevent", m_ngoodevent);
210 sc = m_tuple2->addItem (
"ngoodtrack", m_ngoodtrack);
213 log << MSG::ERROR <<
"Cannot book N-tuple2:" << long(m_tuple2) << endmsg;
214 return StatusCode::FAILURE;
218 NTuplePtr nt3(
ntupleSvc(),
"FILE302/trig3");
219 if ( nt3 ) m_tuple3 = nt3;
221 m_tuple3=
ntupleSvc()->book(
"FILE302/trig3",CLID_ColumnWiseTuple,
"TrigL1");
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();
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]);
238 log << MSG::ERROR <<
"Cannot book N-tuple3:" << long(m_tuple3) << endmsg;
239 return StatusCode::FAILURE;
263 sc = service(
"THistSvc", m_thistsvc);
265 log << MSG::INFO <<
"Unable to retrieve pointer to THistSvc" << endreq;
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);
279 return StatusCode::SUCCESS;
282 MsgStream log(
msgSvc(),name());
284 log<<MSG::DEBUG<<
"in execute()" <<endreq;
292 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),
"/Event/EventHeader");
294 log << MSG::FATAL <<
"Could not find Event Header" << endreq;
295 return( StatusCode::FAILURE);
297 run = eventHeader->runNumber();
298 event = eventHeader->eventNumber();
309 if(writeFile==1 && event == 0)
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;
323 multimap<int,uint32_t,less<int> > mdc_hitmap;
329 multimap<int,int,less<int> > tof_hitmap;
335 SmartDataPtr<MdcDigiCol> mdcDigiCol(eventSvc(),
"/Event/Digi/MdcDigiCol");
337 log << MSG::FATAL <<
"Could not find MDC digi" << endreq;
338 return( StatusCode::FAILURE);
340 for(MdcDigiCol::iterator iter3=mdcDigiCol->begin();iter3!=mdcDigiCol->end();iter3++)
345 int tdc = (*iter3)->getTimeChannel();
346 if(tdc < 0x7FFFFFFF && tdc > 0) {
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));
353 if(layer>=36&&layer<=39)
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));
367 for(TofDataMap::iterator iter3 = tofDigiMap.begin();iter3 != tofDigiMap.end(); iter3++) {
369 TofData * p_tofDigi = iter3->second;
374 if(((p_tofDigi->
quality()) & 0x5) != 0x5)
continue;
375 double tdc1 = p_tofDigi->
tdc1();
376 double tdc2 = p_tofDigi->
tdc2();
378 if(tdc1 > tdc2) tdc = (int) tdc1;
379 else tdc = (int) tdc2;
380 typedef pair<int, int > vpair;
382 tof_hitmap.insert(vpair(tdc,10000*barrel_ec+1000*layer+im*10));
385 int tdc1 = (int)p_tofDigi->
tdc1();
386 typedef pair<int, int > vpair;
388 tof_hitmap.insert(vpair(tdc1,10000*barrel_ec+1000*layer+im*10));
395 SmartDataPtr<EmcDigiCol> emcDigiCol(eventSvc(),
"/Event/Digi/EmcDigiCol");
397 log << MSG::FATAL <<
"Could not find EMC digi" << endreq;
398 return( StatusCode::FAILURE);
409 multimap<int,uint32_t,less<int> > emc_TC;
420 double peak_time = 0;
426 SmartDataPtr<MucDigiCol> mucDigiCol(eventSvc(),
"/Event/Digi/MucDigiCol");
428 log << MSG::FATAL <<
"Could not find MUC digi" << endreq;
429 return( StatusCode::FAILURE);
431 if(m_mucDigi) m_mucDigi->
getMucDigi(mucDigiCol);
436 if(event%10000 == 0) std::cout <<
"---> EventNo is " <<
event << std::endl;
446 double stime = -1, etime = -1;
447 findSETime(mdc_hitmap,tof_hitmap,emc_TC,stime,etime);
452 nclock = int ((etime - stime)/24) + 1;
461 int** trgcond =
new int*[48];
462 for(
int condId = 0; condId < 48; condId++) {
463 trgcond[condId] =
new int[nclock];
467 int idle_status = -1;
469 for(
int iclock = 0; iclock < nclock; iclock++) {
494 if(status!=StatusCode::SUCCESS) {
495 log<<MSG::FATAL<<
"Could not set trigger condition index" <<endreq;
496 return StatusCode::FAILURE;
502 for(
int condId = 0; condId < 48; condId++) {
503 trgcond[condId][iclock] = m_pIBGT->
getTrigCond(condId);
532 bool ifClus1 =
false;
533 for(
int i = 0; i < nclock; i++) {
534 if(trgcond[0][i] > 0) ifClus1 =
true;
537 if(ifClus1 ==
false) {
538 for(
int i = 0; i < nclock; i++) {
539 for(
int j = 0; j < 16; j++) {
548 for(
int i = 0; i < nclock; i++) {
549 for(
int j = 0; j < 48; j++) {
566 log<<MSG::INFO<<
"pass event number is "<<passNo<<endl;
575 setFilterPassed(
true);
579 setFilterPassed(
false);
587 for(
int i = 0; i < 48; i++) {
592 for(
int j = 0; j < nclock; j++) {
593 m_mc_cond[i] += trgcond[i][j];
594 if(trgcond[i][j] != 0) {
597 m_trigCondi_MC->Fill(i);
606 if(edge ==
false && NOne != 0)
break;
608 m_condNOne[i] = NOne;
616 SmartDataPtr<TrigData> trigData(eventSvc(),
"/Event/Trig/TrigData");
618 log << MSG::FATAL <<
"Could not find Trigger Data for physics analysis" << endreq;
619 return StatusCode::FAILURE;
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);
633 for(
int condId = 0; condId < 48; condId++) {
634 delete trgcond[condId];
647 map<int,vector<complex<int> >, greater<int> > mymap;
649 log<<MSG::INFO<<
"EMC test: "<<endreq;
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;
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;
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;
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; }
755 map<int,vector<int>,greater<int> > tofmap;
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;
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; }
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; }
773 std::vector<int> vtmp;
777 for(std::vector<int>::iterator
iter = vtmp.begin();
iter != vtmp.end();
iter++) {
778 m_fireLayer[m_index2] = (long) *
iter;
780 if(m_index2 > m_index2->range().distance()) {
break; cerr<<
"*********** too many index ************"<<endl; }
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++; }
790 if(((vtmp[i]-200)%10)>=3) { tracke3++; trackwe++; }
792 if(100<=vtmp[i]&&vtmp[i]<200) {
793 if(((vtmp[i]-100)%10)>=3) trackb3++;
796 m_ntrack3 = trackb3 + tracke3;
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++;
803 if(((vtmp[i]-200)%10)>=2) tracke2++;
805 if(100<=vtmp[i]&&vtmp[i]<200) {
806 if(((vtmp[i]-100)%10)>=2) trackb2++;
809 m_ntrack2 = trackb2 + tracke2;
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++;
816 if(((vtmp[i]-200)%10)>=1) tracke1++;
818 if(100<=vtmp[i]&&vtmp[i]<200) {
819 if(((vtmp[i]-100)%10)>=1) trackb1++;
822 m_ntrack1 = trackb1 + tracke1;
827 for(std::vector<int>::iterator
iter = vtmp.begin();
iter != vtmp.end();
iter++) {
828 m_hitLayer[m_index3] = (long) *
iter;
830 if(m_index3 > m_index3->range().distance()) {
break; cerr<<
"*********** too many index ************"<<endl; }
835 for(std::vector<int>::iterator
iter = vtmp.begin();
iter != vtmp.end();
iter++) {
836 m_hitSeg[m_index4] = *(
iter);
838 if(m_index4 > m_index4->range().distance()) {
break; cerr<<
"*********** too many index ************"<<endl; }
847 ofstream eventnum(outEvtId.c_str(),ios_base::app);
849 eventnum<<
event<<endl;
858 ofstream eventnum(outEvtId.c_str(),ios_base::app);
860 eventnum<<
event<<endl;
874 readout<<asciiEvt<<endl;
877 cout<<
"********* Event No. from AsciiFile do not equal Event No. from TDS "
889 bool preScale =
false;
891 StatusCode sc = StatusCode::SUCCESS ;
893 sc = eventSvc()->registerObject(
"/Event/Trig",aTrigEvent);
894 if(sc!=StatusCode::SUCCESS) {
895 log<<MSG::DEBUG<<
"Could not register TrigEvent, you can ignore." <<endreq;
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;
905 return StatusCode::SUCCESS;
910 MsgStream msg(
msgSvc(), name());
911 msg << MSG::DEBUG <<
"==> Finalize BesTrigL1" << endreq;
918 cout<<
"There are total "<< passNo<<
" event pass trigger"<<endl;
919 return StatusCode::SUCCESS;
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();
930 emdctime = (mdc_iter->first)*0.09375;
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();
939 etoftime = (tof_iter->first);
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();
948 eemctime = (emc_iter->first);
951 stime = -1, etime = -1;
952 if(smdctime >= 0 && stoftime >= 0) {
953 if(smdctime > stoftime) stime = stoftime;
954 else stime = smdctime;
956 if((emdctime+800) > (etoftime + 24)) etime = emdctime+800;
957 else etime = etoftime + 24;
959 else if(smdctime < 0 && stoftime >= 0) {
961 etime = etoftime + 24;
963 else if(smdctime >= 0 && stoftime < 0) {
965 etime = emdctime+800;
972 if(semctime >= 0 && stime >= 0) {
973 if(semctime > stime) stime = stime;
974 else stime = semctime;
976 if((eemctime+16*24) > etime) etime = eemctime+16*24;
979 else if(semctime < 0 && stime >= 0) {
983 else if(semctime >= 0 && stime < 0) {
985 etime = eemctime+16*24;
994 std::vector<int> vmdcHit;
997 std::multimap<int,uint32_t,less<int> >::iterator mdc_iter = mdc_hitmap.begin();
1066 for(std::multimap<
int,uint32_t,less<int> >::iterator mdc_iter = mdc_hitmap.begin(); mdc_iter != mdc_hitmap.end(); mdc_iter++)
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;
1077 if(firstdc ==
true) {
1078 vmdcHit.push_back(layer);
1079 vmdcHit.push_back(cell);
1090 std::vector<int> vtofHit;
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++)
1097 double time = (tof_iter->first);
1098 if(idle_status == -1) {
1099 if(
time < (stime + (iclock + 1)*24) &&
time >= (stime + iclock*24)) {
1101 vtofHit.push_back(tof_iter->second);
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))
1109 vtofHit.push_back(tof_iter->second);
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))
1117 vtofHit.push_back(tof_iter->second);
1122 if(idle_status == -1 && vtofHit.size() != 0) idle_status = iclock;
1130 std::vector<uint32_t> vemcClus;
1131 std::vector<double> vemcBlkE;
1137 for(std::multimap<
int,uint32_t,less<int> >::iterator emc_iter = emc_TC.begin(); emc_iter != emc_TC.end(); emc_iter++)
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);
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);
1163 for(
int i = 0; i < 11; i++) {
1164 for(
int j = 0; j < 30; j++) {
1168 for(
int i = 0; i < 32; i++) {
1169 if(i < 16) blockWave[i].makeWaveformTrg(0,0);
1174 for (EmcDigiCol::iterator iter3=emcDigiCol->begin();iter3!= emcDigiCol->end();iter3++) {
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.);
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);
1189 unsigned int tdc = (*iter3)->getTimeChannel();
1191 int phiTC = m_emcDigi->
getTCPhiId(module,theta,phi);
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; }
1199 for(
int i = 0; i < 11; i++) {
1200 for(
int j = 0; j < 30; j++) {
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));
1216 int blockId = m_emcDigi->
getBLKId(i,j);
1217 blockWave[blockId+2] += bwave[i][j];
1222 for(
int i = 0; i < 32; i++) {
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));
1236 if(time_low1 >= 0) {
1237 if(i<16) blockWave[0] += eewave[i];
1238 else blockWave[1] += eewave[i];
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));
1253 if(time_low2 >= 0) {
1254 if(i<16) blockWave[14] += wewave[i];
1255 else blockWave[15] += wewave[i];
1261 double tot_block_max = 0;
1262 for(
int i = 0; i < 16; i++) {
1264 double block_max = blockWave[i].
max(block_time);
1265 tot_block_max += block_max;
1268 for(
int i = 0; i < 16; i++) {
1269 if(tot_block_max == 0)
break;
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;
1283 for(
int icond = 0; icond < 48; icond++) {
1285 bool retrig =
false;
1286 for(
int iclock = 0; iclock < nclock; iclock++) {
1288 if(icond < 7 || icond == 12 || icond == 13) {
1289 if(sclock != -1 && iclock - sclock == emc_clus) sclock = -1;
1290 if(sclock == -1 && trgcond[icond][iclock] > 0) {
1291 if(iclock == 0) sclock = iclock;
1293 if(trgcond[icond][iclock]*trgcond[icond][iclock-1] == 0) sclock = iclock;
1296 if(sclock != -1 && iclock - sclock < emc_clus) trgcond[icond][iclock] = 1;
1299 if(sclock != -1 && iclock - sclock == emc_ener) sclock = -1;
1300 if(sclock == -1 && trgcond[icond][iclock] > 0) {
1301 if(iclock == 0) sclock = iclock;
1303 if(trgcond[icond][iclock]*trgcond[icond][iclock-1] == 0) sclock = iclock;
1306 if(sclock != -1 && iclock - sclock < emc_ener && trgcond[icond][iclock] == 0) retrig =
true;
1307 if(retrig ==
true) {
1308 if(trgcond[icond][iclock] > 0) {
1313 if(sclock != -1 && iclock - sclock < emc_ener) trgcond[icond][iclock] = 1;
1316 else if(icond >= 16 && icond < 23) {
1317 if(sclock != -1 && iclock - sclock == tof) sclock = -1;
1318 if(sclock == -1 && trgcond[icond][iclock] > 0) {
1319 if(iclock == 0) sclock = iclock;
1321 if(trgcond[icond][iclock]*trgcond[icond][iclock-1] == 0) sclock = iclock;
1324 if(sclock != -1 && iclock - sclock < tof) trgcond[icond][iclock] = 1;
1326 else if(icond >= 38) {
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;
1332 if(trgcond[icond][iclock]*trgcond[icond][iclock-1] == 0) sclock = iclock;
1335 if(sclock != -1 && iclock - sclock < mdc_n) trgcond[icond][iclock] = 1;
1338 if(sclock != -1 && iclock - sclock ==
mdc) sclock = -1;
1339 if(sclock == -1 && trgcond[icond][iclock] > 0) {
1340 if(iclock == 0) sclock = iclock;
1342 if(trgcond[icond][iclock]*trgcond[icond][iclock-1] == 0) sclock = iclock;
1345 if(sclock != -1 && iclock - sclock <
mdc) trgcond[icond][iclock] = 1;
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};
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;
1367 trgcond[icond][iclock] = trgcond[icond][iclock-delay[icond]];
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};
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]];
ObjectVector< EmcDigi > EmcDigiCol
std::multimap< unsigned int, TofData * > TofDataMap
double imag(const EvtComplex &c)
double real(const EvtComplex &c)
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.
void runAclock_emc(int iclock, double stime, std::multimap< int, uint32_t, less< int > > emc_TC, EmcWaveform *blockWave)
void findEmcPeakTime(double &peak_time, EmcWaveform *blockWave)
BesTrigL1(const std::string &name, ISvcLocator *pSvcLocator)
Standard constructor.
void runAclock_tof(int iclock, double stime, int &idle_status, std::multimap< int, int, less< int > > tof_hitmap)
void getEmcAnalogSig(EmcDigiCol *emcDigiCol, EmcWaveform(&blockWave)[16], multimap< int, uint32_t, less< int > > &emc_TC)
void trgGTLDelay(int nclock, int **&trgcond)
void trgSAFDelay(int nclock, int **&trgcond)
virtual StatusCode finalize()
Algorithm finalization.
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)
virtual StatusCode initialize()
Destructor.
void stretchTrgCond(int nclock, int **&trgcond)
void runAclock_mdc(int iclock, double stime, multimap< int, uint32_t, less< int > > mdc_hitmap)
static unsigned int barrel_ec(const Identifier &id)
Values of different levels (failure returns 0)
static unsigned int theta_module(const Identifier &id)
static unsigned int phi_module(const Identifier &id)
int getTCThetaId(int partId, int ThetaNb, int PhiNb)
static EmcTCFinder * get_Emc(void)
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
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)
static int wire(const Identifier &id)
static MdcTSF * get_Mdc(void)
void setMdcDigi(std::vector< int > &vmdcHit)
static MucTrigHit * get_Muc(void)
void getMucDigi(MucDigiCol *mucDigiCol)
double getTrgGain(int cry_id)
unsigned int quality() const
static TofHitCount * get_Tof(void)
void setTofDigi(std::vector< int > &vtofHit)
static int phi_module(const Identifier &id)
static int barrel_ec(const Identifier &id)
Values of different levels (failure returns 0)
static int layer(const Identifier &id)