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" );
68 MsgStream log(
msgSvc(), name());
69 log << MSG::INFO <<
"in initialize()" <<endreq;
77 return StatusCode::SUCCESS;
82 MsgStream log(
msgSvc(), name());
83 log << MSG::INFO <<
"in finalize()" << endreq;
87 return StatusCode::SUCCESS;
90StatusCode ChargedDReconstruction::registerEvtRecDTagCol(
92 StatusCode sc = eventSvc()->registerObject(
"/Event/EvtRec/EvtRecDTagCol",
94 if (sc != StatusCode::SUCCESS) {
95 log << MSG::FATAL <<
"Could not register EvtRecDTagCol in TDS!" << endreq;
102 MsgStream log(
msgSvc(), name());
103 log << MSG::INFO <<
"in execute()" << endreq;
110 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),
"/Event/EventHeader");
111 int event= eventHeader->eventNumber();
117 log << MSG::DEBUG <<
"run and event = " << eventHeader->runNumber()
118 <<
" " << eventHeader->eventNumber() << endreq;
119 log << MSG::DEBUG <<
"ncharg, nneu, tottks = "
120 << recEvent->totalCharged() <<
" , "
121 << recEvent->totalNeutral() <<
" , "
122 << recEvent->totalTracks() <<endreq;
131 SmartDataPtr<EvtRecPi0Col> recPi0Col(eventSvc(),
"/Event/EvtRec/EvtRecPi0Col");
133 log << MSG::FATAL <<
"Could not find EvtRecPi0Col" << endreq;
134 return StatusCode::FAILURE;
138 SmartDataPtr<EvtRecEtaToGGCol> recEtaToGGCol(eventSvc(),
"/Event/EvtRec/EvtRecEtaToGGCol");
139 if ( ! recEtaToGGCol ) {
140 log << MSG::FATAL <<
"Could not find EvtRecEtaToGGCol" << endreq;
141 return StatusCode::FAILURE;
145 SmartDataPtr<EvtRecVeeVertexCol> recVeeVertexCol(eventSvc(),
"/Event/EvtRec/EvtRecVeeVertexCol");
146 if ( ! recVeeVertexCol ) {
147 log << MSG::FATAL <<
"Could not find EvtRecVeeVertexCol" << endreq;
148 return StatusCode::FAILURE;
154 log << MSG::FATAL <<
"EvtRecDTagCol is not registered yet" << endreq;
155 return StatusCode::FAILURE;
161 Hep3Vector xorigin(0,0,0);
164 Gaudi::svcLocator()->service(
"VertexDbSvc", vtxsvc);
169 xorigin.setX(vertex[0]);
170 xorigin.setY(vertex[1]);
171 xorigin.setZ(vertex[2]);
198 dc_fill(ksList, recVeeVertexCol->begin(), recVeeVertexCol->end());
201 dc_fill(pi0List, recPi0Col->begin(), recPi0Col->end());
204 dc_fill(etaList, recEtaToGGCol->begin(), recEtaToGGCol->end());
214 int run = eventHeader->runNumber();
215 m_ievt = eventHeader->eventNumber();
216 m_nChrg = recEvent->totalCharged();
217 m_nNeu = recEvent->totalNeutral();
218 m_nPion = pionList.
size();
219 m_nKaon = kaonList.
size();
220 m_nPi0 = pi0List.size();
221 m_nKs = ksList.size();
229 if(m_ReadBeamEFromDB && m_irun!=run){
233 m_beamE=m_readDb.
getbeamE(m_irun,m_beamE);
238 double ebeam=m_beamE;
246 for(
int list=0;list<chanlist.size();list++){
248 string channel=chanlist[list];
258 if(channel==
"DptoKPiPi") {
260 numchan.push_back(1);
261 numchan.push_back(2);
262 numchan.push_back(2);
263 decaylist=kaonList.
minus()* pionList.
plus()* pionList.
plus();
265 else if(channel==
"DptoKPiPiPi0") {
267 numchan.push_back(1);
268 numchan.push_back(2);
269 numchan.push_back(2);
270 numchan.push_back(3);
271 decaylist=kaonList.
minus()* pionList.
plus()* pionList.
plus()* pi0List;
273 else if(channel==
"DptoKsPi") {
275 numchan.push_back(5);
276 numchan.push_back(2);
277 decaylist=ksList* pionList.
plus();
279 else if(channel==
"DptoKsPiPi0") {
281 numchan.push_back(5);
282 numchan.push_back(2);
283 numchan.push_back(3);
284 decaylist=ksList* pionList.
plus()* pi0List;
286 else if(channel==
"DptoKsPiPiPi") {
288 numchan.push_back(5);
289 numchan.push_back(2);
290 numchan.push_back(2);
291 numchan.push_back(2);
292 decaylist=ksList* pionList.
plus()* pionList.
plus()* pionList.
minus();
294 else if(channel==
"DptoKKPi") {
296 numchan.push_back(1);
297 numchan.push_back(1);
298 numchan.push_back(2);
299 decaylist=kaonList.
minus()* kaonList.
plus()* pionList.
plus();
301 else if(channel==
"DptoPiPi0") {
303 numchan.push_back(2);
304 numchan.push_back(3);
305 decaylist=pionList.
plus()* pi0List;
307 else if(channel==
"DptoKPi0") {
309 numchan.push_back(1);
310 numchan.push_back(3);
311 decaylist=kaonList.
plus()* pi0List;
313 else if(channel==
"DptoKsK") {
315 numchan.push_back(5);
316 numchan.push_back(1);
317 decaylist=ksList* kaonList.
plus();
319 else if(channel==
"DptoPiPiPi") {
321 numchan.push_back(2);
322 numchan.push_back(2);
323 numchan.push_back(2);
324 decaylist=pionList.
plus()* pionList.
plus()* pionList.
minus() ;
326 else if(channel==
"DptoPiPi0Pi0") {
328 numchan.push_back(2);
329 numchan.push_back(3);
330 numchan.push_back(3);
331 decaylist=pionList.
plus()* pi0List* pi0List;
333 else if(channel==
"DptoKsKsPi") {
335 numchan.push_back(5);
336 numchan.push_back(5);
337 numchan.push_back(2);
338 decaylist=ksList* ksList* pionList.
plus();
340 else if(channel==
"DptoKsKPi0") {
342 numchan.push_back(5);
343 numchan.push_back(1);
344 numchan.push_back(3);
345 decaylist=ksList* kaonList.
plus()* pi0List;
347 else if(channel==
"DptoKsKsK") {
349 numchan.push_back(5);
350 numchan.push_back(5);
351 numchan.push_back(1);
352 decaylist=ksList* ksList* kaonList.
plus();
354 else if(channel==
"DptoPiPiPiPi0") {
356 numchan.push_back(2);
357 numchan.push_back(2);
358 numchan.push_back(2);
359 numchan.push_back(3);
360 decaylist=pionList.
plus()* pionList.
plus()* pionList.
minus()* pi0List;
362 else if(channel==
"DptoKsPiPi0Pi0") {
364 numchan.push_back(5);
365 numchan.push_back(2);
366 numchan.push_back(3);
367 numchan.push_back(3);
368 decaylist=ksList* pionList.
plus()* pi0List* pi0List;
370 else if(channel==
"DptoKsKplusPiPi") {
372 numchan.push_back(5);
373 numchan.push_back(1);
374 numchan.push_back(2);
375 numchan.push_back(2);
376 decaylist=ksList* kaonList.
plus()* pionList.
plus()* pionList.
minus();
378 else if(channel==
"DptoKsKminusPiPi") {
380 numchan.push_back(5);
381 numchan.push_back(1);
382 numchan.push_back(2);
383 numchan.push_back(2);
384 decaylist=ksList* kaonList.
minus()* pionList.
plus()* pionList.
plus();
386 else if(channel==
"DptoKKPiPi0") {
388 numchan.push_back(1);
389 numchan.push_back(1);
390 numchan.push_back(2);
391 numchan.push_back(3);
392 decaylist=kaonList.
minus()* kaonList.
plus()* pionList.
plus()* pi0List;
394 else if(channel==
"DptoPiPiPiPiPi") {
396 numchan.push_back(2);
397 numchan.push_back(2);
398 numchan.push_back(2);
399 numchan.push_back(2);
400 numchan.push_back(2);
403 else if(channel==
"DptoKPiPiPiPi") {
405 numchan.push_back(1);
406 numchan.push_back(2);
407 numchan.push_back(2);
408 numchan.push_back(2);
409 numchan.push_back(2);
412 else if(channel==
"DptoPiEta") {
414 numchan.push_back(2);
415 numchan.push_back(4);
416 decaylist=pionList.
plus()* etaList;
418 else if(channel==
"DptoKsPiEta") {
420 numchan.push_back(5);
421 numchan.push_back(2);
422 numchan.push_back(4);
423 decaylist=ksList* pionList.
plus()* etaList;
434 vector<int> trackid, showerid;
435 vector<int> kaonid, pionid;
436 int numofchildren=numchan.size()-1;
438 for(
int i=0; i< numofchildren;i++){
440 const CDCandidate& daughter=(*it).particle().child(i);
444 trackid.push_back(track->
trackId());
445 kaonid.push_back(track->
trackId());
447 else if(numchan[i+1]==2){
449 trackid.push_back(track->
trackId());
450 pionid.push_back(track->
trackId());
452 else if ( numchan[i+1]==3){
455 showerid.push_back(hiEnGamma->
trackId());
456 showerid.push_back(loEnGamma->
trackId());
458 else if ( numchan[i+1]==4){
461 showerid.push_back(hiEnGamma->
trackId());
462 showerid.push_back(loEnGamma->
trackId());
464 else if ( numchan[i+1]==5){
468 trackid.push_back(pion1Trk->
trackId());
469 trackid.push_back(pion2Trk->
trackId());
475 saveDpInfo(it, ebeam, numofchildren, recDTag);
476 savetrack(trackid,showerid,charged_begin,charged_end,neutral_begin,neutral_end,recDTag);
477 pidtag(kaonid,pionid,kaonList_tight, pionList_tight,recDTag);
480 HepLorentzVector p4change_vfit=util.
vfit(channel, kaonid, pionid, xorigin, charged_begin);
481 recDTag->
setp4(recDTag->
p4()+p4change_vfit);
492 recDTagCol->push_back(recDTag);
502 return StatusCode::SUCCESS;
508 double mass = (*it).particle().mass();
509 int charge= (*it).particle().charge();
510 HepLorentzVector p4((*it).particle().momentum(), (*it).particle().energy());
514 double mbc2_CMS = ebeam*ebeam - p4.v().mag2();
515 double mbc_CMS = mbc2_CMS > 0 ? sqrt( mbc2_CMS ) : -10;
516 double deltaE_CMS = p4.t() - ebeam;
518 if((*it).particle().userTag()==1)
535 vector<EvtRecTrackIterator> trktemp;
536 vector<EvtRecTrackIterator> shrtemp;
541 bool isothertrack=
true;
542 for(
int i=0; i<trackid.size(); i++){
543 if( (*trk)->trackId()==trackid[i] ){
544 trktemp.push_back(trk);
552 for(
int i=0; i<trackid.size();i++){
553 for(
int j=0; j<trktemp.size(); j++){
555 if( (*trk)->trackId()==trackid[i])
563 bool isothershower=
true;
564 for(
int i=0; i<showerid.size(); i++){
565 if( (*shr)->trackId()==showerid[i] ){
566 shrtemp.push_back(shr);
575 for(
int i=0; i<showerid.size();i++){
576 for(
int j=0; j<shrtemp.size(); j++){
578 if( (*shr)->trackId()==showerid[i])
588 bool iskaon=
false,ispion=
false;
594 recDTag->
addKaonId( (*kit).particle().track() );
598 recDTag->
addPionId( (*pit).particle().track() );
649 inFile.open(filename.c_str());
651 cout <<
"Unable to open decay list file";
655 while (inFile >> channel) {
656 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 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 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)
_EXTERN_ std::string EvtRecEvent
_EXTERN_ std::string EvtRecDTagCol
_EXTERN_ std::string EvtRecTrackCol