5#include "GaudiKernel/MsgStream.h"
6#include "GaudiKernel/AlgFactory.h"
7#include "GaudiKernel/ISvcLocator.h"
8#include "GaudiKernel/SmartDataPtr.h"
9#include "GaudiKernel/IDataProviderSvc.h"
12#include "EventModel/EventHeader.h"
13#include "EventModel/Event.h"
14#include "EventModel/EventModel.h"
16#include "EvtRecEvent/EvtRecEvent.h"
17#include "EvtRecEvent/EvtRecTrack.h"
18#include "EvtRecEvent/EvtRecDTag.h"
19#include "EvtRecEvent/EvtRecPi0.h"
20#include "EvtRecEvent/EvtRecEtaToGG.h"
21#include "EvtRecEvent/EvtRecVeeVertex.h"
23#include "BesDChain/CDChargedPionList.h"
24#include "BesDChain/CDChargedKaonList.h"
25#include "BesDChain/CDPhotonList.h"
26#include "BesDChain/CDPi0List.h"
27#include "BesDChain/CDEtaList.h"
28#include "BesDChain/CDKsList.h"
29#include "BesDChain/CDDecayList.h"
31#include "McTruth/McParticle.h"
32#include "ParticleID/ParticleID.h"
33#include "VertexFit/VertexFit.h"
34#include "VertexFit/SecondVertexFit.h"
35#include "VertexFit/IVertexDbSvc.h"
37#include "DTagAlg/ChargedDReconstruction.h"
38#include "DTagAlg/LocalKaonSelector.h"
39#include "DTagAlg/LocalPionSelector.h"
40#include "DTagAlg/LocalPhotonSelector.h"
41#include "DTagAlg/LocalKsSelector.h"
42#include "DTagAlg/LocalPi0Selector.h"
43#include "DTagAlg/LocalEtatoGGSelector.h"
44#include "DTagAlg/LocalEptoPiPiEtaSelector.h"
45#include "DTagAlg/LocalEptoRhoGamSelector.h"
46#include "DTagAlg/LocalRhotoPiPiSelector.h"
47#include "DTagAlg/ChargedDSelector.h"
50#include "DTagAlg/utility.h"
56Algorithm(name, pSvcLocator) {
58 declareProperty(
"debug", m_debug =
false );
59 declareProperty(
"ReadBeamEFromDB", m_ReadBeamEFromDB =
false );
60 declareProperty(
"UseCalibBeamE", m_usecalibBeamE =
false );
61 declareProperty(
"UseVertexfit", m_usevertexfit =
false );
62 declareProperty(
"BeamE", m_beamE = 1.8865 );
63 declareProperty(
"DpList", m_decaylist =
"test.txt" );
64 declareProperty(
"ReadMeasuredEcms", m_RdMeasuredEcms =
false);
69 MsgStream log(
msgSvc(), name());
70 log << MSG::INFO <<
"in initialize()" <<endreq;
80 StatusCode status=serviceLocator()->service(
"MeasuredEcmsSvc", ecmsSvc,
true);
81 if(!status.isSuccess()){
82 std::cout<<
"ERROR: Can not initial the IMeasuredEcmsSvc right"<<std::endl;
88 return StatusCode::SUCCESS;
93 MsgStream log(
msgSvc(), name());
94 log << MSG::INFO <<
"in finalize()" << endreq;
98 return StatusCode::SUCCESS;
101StatusCode ChargedDReconstruction::registerEvtRecDTagCol(
103 StatusCode sc = eventSvc()->registerObject(
"/Event/EvtRec/EvtRecDTagCol",
105 if (sc != StatusCode::SUCCESS) {
106 log << MSG::FATAL <<
"Could not register EvtRecDTagCol in TDS!" << endreq;
113 MsgStream log(
msgSvc(), name());
114 log << MSG::INFO <<
"in execute()" << endreq;
121 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),
"/Event/EventHeader");
122 int event= eventHeader->eventNumber();
128 log << MSG::DEBUG <<
"run and event = " << eventHeader->runNumber()
129 <<
" " << eventHeader->eventNumber() << endreq;
130 log << MSG::DEBUG <<
"ncharg, nneu, tottks = "
131 << recEvent->totalCharged() <<
" , "
132 << recEvent->totalNeutral() <<
" , "
133 << recEvent->totalTracks() <<endreq;
142 SmartDataPtr<EvtRecPi0Col> recPi0Col(eventSvc(),
"/Event/EvtRec/EvtRecPi0Col");
144 log << MSG::FATAL <<
"Could not find EvtRecPi0Col" << endreq;
145 return StatusCode::FAILURE;
149 SmartDataPtr<EvtRecEtaToGGCol> recEtaToGGCol(eventSvc(),
"/Event/EvtRec/EvtRecEtaToGGCol");
150 if ( ! recEtaToGGCol ) {
151 log << MSG::FATAL <<
"Could not find EvtRecEtaToGGCol" << endreq;
152 return StatusCode::FAILURE;
156 SmartDataPtr<EvtRecVeeVertexCol> recVeeVertexCol(eventSvc(),
"/Event/EvtRec/EvtRecVeeVertexCol");
157 if ( ! recVeeVertexCol ) {
158 log << MSG::FATAL <<
"Could not find EvtRecVeeVertexCol" << endreq;
159 return StatusCode::FAILURE;
165 log << MSG::FATAL <<
"EvtRecDTagCol is not registered yet" << endreq;
166 return StatusCode::FAILURE;
172 Hep3Vector xorigin(0,0,0);
175 Gaudi::svcLocator()->service(
"VertexDbSvc", vtxsvc);
180 xorigin.setX(vertex[0]);
181 xorigin.setY(vertex[1]);
182 xorigin.setZ(vertex[2]);
208 dc_fill(ksList, recVeeVertexCol->begin(), recVeeVertexCol->end());
211 map<EvtRecVeeVertex*, vector< double > > fitinfo;
212 for(
CDKsList::iterator ksit = ksList.particle_begin(); ksit != ksList.particle_end(); ++ksit ){
218 dc_fill(pi0List, recPi0Col->begin(), recPi0Col->end());
221 dc_fill(etaList, recEtaToGGCol->begin(), recEtaToGGCol->end());
231 int run = eventHeader->runNumber();
232 m_ievt = eventHeader->eventNumber();
233 m_nChrg = recEvent->totalCharged();
234 m_nNeu = recEvent->totalNeutral();
235 m_nPion = pionList.
size();
236 m_nKaon = kaonList.
size();
237 m_nPi0 = pi0List.size();
238 m_nKs = ksList.size();
247 if(m_RdMeasuredEcms&&m_irun!=run){
250 m_beta.setX(ecmsSvc->
getPx(run));
251 m_beta.setY(ecmsSvc->
getPy(run));
252 m_beta.setZ(ecmsSvc->
getPz(run));
255 log << MSG::INFO <<
"MeasuredEcmsSvc: " <<m_beamE<< endreq;
258 if(m_ReadBeamEFromDB && m_irun!=run){
262 m_beamE=m_readDb.
getbeamE(m_irun,m_beamE);
267 double ebeam=m_beamE;
275 for(
int list=0;list<chanlist.size();list++){
277 string channel=chanlist[list];
287 if(channel==
"DptoKPiPi") {
289 numchan.push_back(1);
290 numchan.push_back(2);
291 numchan.push_back(2);
292 decaylist=kaonList.
minus()* pionList.
plus()* pionList.
plus();
294 else if(channel==
"DptoKPiPiPi0") {
296 numchan.push_back(1);
297 numchan.push_back(2);
298 numchan.push_back(2);
299 numchan.push_back(3);
300 decaylist=kaonList.
minus()* pionList.
plus()* pionList.
plus()* pi0List;
302 else if(channel==
"DptoKsPi") {
304 numchan.push_back(5);
305 numchan.push_back(2);
306 decaylist=ksList* pionList.
plus();
308 else if(channel==
"DptoKsPiPi0") {
310 numchan.push_back(5);
311 numchan.push_back(2);
312 numchan.push_back(3);
313 decaylist=ksList* pionList.
plus()* pi0List;
315 else if(channel==
"DptoKsPiPiPi") {
317 numchan.push_back(5);
318 numchan.push_back(2);
319 numchan.push_back(2);
320 numchan.push_back(2);
321 decaylist=ksList* pionList.
plus()* pionList.
plus()* pionList.
minus();
323 else if(channel==
"DptoKKPi") {
325 numchan.push_back(1);
326 numchan.push_back(1);
327 numchan.push_back(2);
328 decaylist=kaonList.
minus()* kaonList.
plus()* pionList.
plus();
330 else if(channel==
"DptoPiPi0") {
332 numchan.push_back(2);
333 numchan.push_back(3);
334 decaylist=pionList.
plus()* pi0List;
336 else if(channel==
"DptoKPi0") {
338 numchan.push_back(1);
339 numchan.push_back(3);
340 decaylist=kaonList.
plus()* pi0List;
342 else if(channel==
"DptoKsK") {
344 numchan.push_back(5);
345 numchan.push_back(1);
346 decaylist=ksList* kaonList.
plus();
348 else if(channel==
"DptoPiPiPi") {
350 numchan.push_back(2);
351 numchan.push_back(2);
352 numchan.push_back(2);
353 decaylist=pionList.
plus()* pionList.
plus()* pionList.
minus() ;
355 else if(channel==
"DptoPiPi0Pi0") {
357 numchan.push_back(2);
358 numchan.push_back(3);
359 numchan.push_back(3);
360 decaylist=pionList.
plus()* pi0List* pi0List;
362 else if(channel==
"DptoKsKsPi") {
364 numchan.push_back(5);
365 numchan.push_back(5);
366 numchan.push_back(2);
367 decaylist=ksList* ksList* pionList.
plus();
369 else if(channel==
"DptoKsKPi0") {
371 numchan.push_back(5);
372 numchan.push_back(1);
373 numchan.push_back(3);
374 decaylist=ksList* kaonList.
plus()* pi0List;
376 else if(channel==
"DptoKsKsK") {
378 numchan.push_back(5);
379 numchan.push_back(5);
380 numchan.push_back(1);
381 decaylist=ksList* ksList* kaonList.
plus();
383 else if(channel==
"DptoPiPiPiPi0") {
385 numchan.push_back(2);
386 numchan.push_back(2);
387 numchan.push_back(2);
388 numchan.push_back(3);
389 decaylist=pionList.
plus()* pionList.
plus()* pionList.
minus()* pi0List;
391 else if(channel==
"DptoKsPiPi0Pi0") {
393 numchan.push_back(5);
394 numchan.push_back(2);
395 numchan.push_back(3);
396 numchan.push_back(3);
397 decaylist=ksList* pionList.
plus()* pi0List* pi0List;
399 else if(channel==
"DptoKsKplusPiPi") {
401 numchan.push_back(5);
402 numchan.push_back(1);
403 numchan.push_back(2);
404 numchan.push_back(2);
405 decaylist=ksList* kaonList.
plus()* pionList.
plus()* pionList.
minus();
407 else if(channel==
"DptoKsKminusPiPi") {
409 numchan.push_back(5);
410 numchan.push_back(1);
411 numchan.push_back(2);
412 numchan.push_back(2);
413 decaylist=ksList* kaonList.
minus()* pionList.
plus()* pionList.
plus();
415 else if(channel==
"DptoKKPiPi0") {
417 numchan.push_back(1);
418 numchan.push_back(1);
419 numchan.push_back(2);
420 numchan.push_back(3);
421 decaylist=kaonList.
minus()* kaonList.
plus()* pionList.
plus()* pi0List;
423 else if(channel==
"DptoPiPiPiPiPi") {
425 numchan.push_back(2);
426 numchan.push_back(2);
427 numchan.push_back(2);
428 numchan.push_back(2);
429 numchan.push_back(2);
432 else if(channel==
"DptoKPiPiPiPi") {
434 numchan.push_back(1);
435 numchan.push_back(2);
436 numchan.push_back(2);
437 numchan.push_back(2);
438 numchan.push_back(2);
441 else if(channel==
"DptoPiEta") {
443 numchan.push_back(2);
444 numchan.push_back(4);
445 decaylist=pionList.
plus()* etaList;
447 else if(channel==
"DptoKsPiEta") {
449 numchan.push_back(5);
450 numchan.push_back(2);
451 numchan.push_back(4);
452 decaylist=ksList* pionList.
plus()* etaList;
463 vector<int> trackid, showerid;
464 vector<int> kaonid, pionid;
465 int numofchildren=numchan.size()-1;
467 for(
int i=0; i< numofchildren;i++){
469 const CDCandidate& daughter=(*it).particle().child(i);
473 trackid.push_back(track->
trackId());
474 kaonid.push_back(track->
trackId());
476 else if(numchan[i+1]==2){
478 trackid.push_back(track->
trackId());
479 pionid.push_back(track->
trackId());
481 else if ( numchan[i+1]==3){
484 showerid.push_back(hiEnGamma->
trackId());
485 showerid.push_back(loEnGamma->
trackId());
487 else if ( numchan[i+1]==4){
490 showerid.push_back(hiEnGamma->
trackId());
491 showerid.push_back(loEnGamma->
trackId());
493 else if ( numchan[i+1]==5){
496 recDTag->
addToFitInfo(aKsCand->
mass(),fitinfo[aKsCand][0],fitinfo[aKsCand][1],fitinfo[aKsCand][2]);
500 trackid.push_back(pion1Trk->
trackId());
501 trackid.push_back(pion2Trk->
trackId());
508 savetrack(trackid,showerid,charged_begin,charged_end,neutral_begin,neutral_end,recDTag);
509 pidtag(kaonid,pionid,kaonList_tight, pionList_tight,recDTag);
512 HepLorentzVector p4change_vfit=util.
vfit(channel, kaonid, pionid, xorigin, charged_begin);
513 recDTag->
setp4(recDTag->
p4()+p4change_vfit);
523 recDTagCol->push_back(recDTag);
531 return StatusCode::SUCCESS;
537 double mass = (*it).particle().mass();
538 int charge= (*it).particle().charge();
539 HepLorentzVector p4((*it).particle().momentum(), (*it).particle().energy());
543 double mbc2_CMS =
ebeam*
ebeam - p4.v().mag2();
544 double mbc_CMS = mbc2_CMS > 0 ? sqrt( mbc2_CMS ) : -10;
545 double deltaE_CMS = p4.t() -
ebeam;
547 if((*it).particle().userTag()==1)
564 vector<EvtRecTrackIterator> trktemp;
565 vector<EvtRecTrackIterator> shrtemp;
570 bool isothertrack=
true;
571 for(
int i=0; i<trackid.size(); i++){
572 if( (*trk)->trackId()==trackid[i] ){
573 trktemp.push_back(trk);
581 for(
int i=0; i<trackid.size();i++){
582 for(
int j=0; j<trktemp.size(); j++){
584 if( (*trk)->trackId()==trackid[i])
592 bool isothershower=
true;
593 for(
int i=0; i<showerid.size(); i++){
594 if( (*shr)->trackId()==showerid[i] ){
595 shrtemp.push_back(shr);
604 for(
int i=0; i<showerid.size();i++){
605 for(
int j=0; j<shrtemp.size(); j++){
607 if( (*shr)->trackId()==showerid[i])
617 bool iskaon=
false,ispion=
false;
623 recDTag->
addKaonId( (*kit).particle().track() );
627 recDTag->
addPionId( (*pit).particle().track() );
678 inFile.open(filename.c_str());
680 cout <<
"Unable to open decay list file";
684 while (inFile >> channel) {
685 temp.push_back(channel);
void dc_fill(DCFillableChargedList< Charged > &aFillableList, WitnessIterator first, WitnessIterator last)
ObjectVector< EvtRecDTag > EvtRecDTagCol
EvtRecTrackCol::iterator EvtRecTrackIterator
ChargedDSelector chargedDSelector
LocalEtatoGGSelector etatoGGSelector
LocalKaonSelector kaonSelector
LocalKsSelector ksSelector
LocalPi0Selector pi0Selector
LocalPionSelector pionSelector
virtual const EvtRecTrack * track() const
virtual const EvtRecVeeVertex * navKshort() const
virtual const EvtRecPi0 * navPi0() const
virtual const EvtRecEtaToGG * navEta() const
void saveDpInfo(CDDecayList::iterator, double, int, EvtRecDTag *)
vector< string > getlist(string &filename)
void pidtag(vector< int >, vector< int >, CDChargedKaonList &, CDChargedPionList &, EvtRecDTag *)
void savetrack(vector< int >, vector< int >, EvtRecTrackIterator, EvtRecTrackIterator, EvtRecTrackIterator, EvtRecTrackIterator, EvtRecDTag *)
ChargedDReconstruction(const std::string &name, ISvcLocator *pSvcLocator)
void setbeta(Hep3Vector beta)
void setebeam(double ebeam)
void addOtherTrack(const SmartRef< EvtRecTrack > track)
void settype(SelType type)
void setdecayMode(DecayMode decayMode)
HepLorentzVector p4() const
void setp4(HepLorentzVector p4)
void setmass(double mass)
void addToFitInfo(double ksmass, double chi2, double length, double error)
void addOtherShower(const SmartRef< EvtRecTrack > shower)
void addKaonId(const SmartRef< EvtRecTrack > kaonId)
void setdeltaE(double deltaE)
void setcharge(int charge)
void addPionId(const SmartRef< EvtRecTrack > pionId)
void setbeamE(double beamE)
void addShower(const SmartRef< EvtRecTrack > shower)
void setnumOfChildren(int numOfChildren)
void addTrack(const SmartRef< EvtRecTrack > track)
const EvtRecTrack * hiEnGamma() const
const EvtRecTrack * loEnGamma() const
const EvtRecTrack * loEnGamma() const
const EvtRecTrack * hiEnGamma() const
SmartRef< EvtRecTrack > & daughter(int i)
virtual double getPz(int runNo)=0
virtual bool isReadDBValid(int runNo, char *tab, char *col)=0
virtual double getPx(int runNo)=0
virtual double getInfo(int runNo, char *tab, char *col)=0
virtual bool isRunNoValid(int runNo)=0
virtual double getPy(int runNo)=0
virtual bool isVertexValid()=0
virtual double * PrimaryVertex()=0
void setpidtype(int type)
void setpidtype(int type)
bool setcalib(bool calib)
CLHEP::Hep3Vector getbeta()
ChosenChargeList< Charged, CandidateClass > & plus() const
ChosenChargeList< Charged, CandidateClass > & minus() const
iterator particle_begin()
virtual iterator particle_begin()
virtual iterator particle_end()
HepLorentzVector vfit(string channel, vector< int > kaonid, vector< int > pionid, HepPoint3D vx, EvtRecTrackIterator charged_begin)
vector< double > SecondaryVFit(EvtRecVeeVertex *ks, IVertexDbSvc *vtxsvc)
_EXTERN_ std::string EvtRecEvent
_EXTERN_ std::string EvtRecDTagCol
_EXTERN_ std::string EvtRecTrackCol