1#include "GaudiKernel/MsgStream.h"
2#include "GaudiKernel/AlgFactory.h"
3#include "GaudiKernel/ISvcLocator.h"
4#include "GaudiKernel/SmartDataPtr.h"
5#include "GaudiKernel/IDataProviderSvc.h"
6#include "GaudiKernel/PropertyMgr.h"
17#include "GaudiKernel/INTupleSvc.h"
18#include "GaudiKernel/NTuple.h"
19#include "GaudiKernel/Bootstrap.h"
20#include "GaudiKernel/IHistogramSvc.h"
21#include "CLHEP/Vector/ThreeVector.h"
22#include "CLHEP/Vector/LorentzVector.h"
23#include "CLHEP/Vector/TwoVector.h"
24using CLHEP::Hep3Vector;
25using CLHEP::Hep2Vector;
26using CLHEP::HepLorentzVector;
27#include "CLHEP/Geometry/Point3D.h"
28#ifndef ENABLE_BACKWARDS_COMPATIBILITY
41const double mpi = 0.13957;
43const double mk = 0.493677;
44const double xmass[5] = {0.000511, 0.105658, 0.139570,0.493677, 0.938272};
47typedef std::vector<int>
Vint;
48typedef std::vector<HepLorentzVector>
Vp4;
57DECLARE_COMPONENT(
rhopi)
59 Algorithm(name, pSvcLocator) {
64 for(
int i = 0; i < 12; i++) m_pass[i] = 0;
67 declareProperty(
"Vr0cut", m_vr0cut=5.0);
68 declareProperty(
"Vz0cut", m_vz0cut=15.0);
69 declareProperty(
"EnergyThreshold", m_energyThreshold=0.03);
70 declareProperty(
"GammaPhiCut", m_gammaPhiCut=20.0);
71 declareProperty(
"GammaThetaCut", m_gammaThetaCut=20.0);
76 MsgStream log(
msgSvc(), name());
78 log << MSG::INFO <<
"in initialize()" << endmsg;
82 status = service(
"THistSvc", m_thistsvc);
83 if(status.isFailure() ){
84 log << MSG::INFO <<
"Unable to retrieve pointer to THistSvc" << endreq;
87 m_pi_vx =
new TH1F(
"pi_vx",
"pi_vx", 100,-1.0,1.0 );
88 status = m_thistsvc->regHist(
"/VAL/PHY/pi_vx", m_pi_vx);
89 m_pi_vy =
new TH1F(
"pi_vy",
"pi_vy", 100,-1.0,1.0 );
90 status = m_thistsvc->regHist(
"/VAL/PHY/pi_vy", m_pi_vy);
91 m_pi_vz =
new TH1F(
"pi_vz",
"pi_vz", 100,-6.0,6.0 );
92 status = m_thistsvc->regHist(
"/VAL/PHY/pi_vz", m_pi_vz);
93 m_pip_mom =
new TH1F(
"pip_mom",
"pip_moment", 100,0.0,1.6 );
94 status = m_thistsvc->regHist(
"/VAL/PHY/pip_mom", m_pip_mom);
95 m_pim_mom =
new TH1F(
"pim_mom",
"pim_moment", 100,0.0,1.6 );
96 status = m_thistsvc->regHist(
"/VAL/PHY/pim_mom", m_pim_mom);
97 m_rhop_mass =
new TH1F(
"rhop_mass",
"rhop_mass", 100,0.0,1.5 );
98 status = m_thistsvc->regHist(
"/VAL/PHY/rhop_mass", m_rhop_mass);
99 m_rhom_mass =
new TH1F(
"rhom_mass",
"rhom_mass", 100,0.0,1.5 );
100 status = m_thistsvc->regHist(
"/VAL/PHY/rhom_mass", m_rhom_mass);
101 m_rho0_mass =
new TH1F(
"rho0_mass",
"rho0_mass", 100,0.0,1.5 );
102 status = m_thistsvc->regHist(
"/VAL/PHY/rho0_mass", m_rho0_mass);
103 m_pi0_mass =
new TH1F(
"pi0_mass",
"pi0_mass", 100,0.0,0.5 );
104 status = m_thistsvc->regHist(
"/VAL/PHY/pi0_mass", m_pi0_mass);
105 m_chisq_4c =
new TH1F(
"chisq_4c",
"chisq_4c", 100,0.0,150. );
106 status = m_thistsvc->regHist(
"/VAL/PHY/chisq_4c", m_chisq_4c);
107 m_chisq_5c =
new TH1F(
"chisq_5c",
"chisq_5c", 100,0.0,150. );
108 status = m_thistsvc->regHist(
"/VAL/PHY/chisq_5c", m_chisq_5c);
110 m_cos_pip =
new TH1F(
"cos_pip",
"cos_pip", 100, -1.0,1.0);
111 status = m_thistsvc->regHist(
"/VAL/PHY/cos_pip", m_cos_pip);
112 m_cos_pim =
new TH1F(
"cos_pim",
"cos_pim", 100, -1.0,1.0);
113 status = m_thistsvc->regHist(
"/VAL/PHY/cos_pim", m_cos_pim);
115 m_chipi_dedx =
new TH1F(
"chipi_dedx",
"chipi_dedx", 60,-5.0,10. );
116 status = m_thistsvc->regHist(
"/VAL/PHY/chipi_dedx", m_chipi_dedx);
117 m_chie_dedx =
new TH1F(
"chie_dedx",
"chie_dedx", 60,-15.0,5. );
118 status = m_thistsvc->regHist(
"/VAL/PHY/chie_dedx", m_chie_dedx);
119 m_chimu_dedx =
new TH1F(
"chimu_dedx",
"chimu_dedx", 60,-5.0,10. );
120 status = m_thistsvc->regHist(
"/VAL/PHY/chimu_dedx", m_chimu_dedx);
121 m_chik_dedx =
new TH1F(
"chik_dedx",
"chik_dedx", 100,-20.0,10. );
122 status = m_thistsvc->regHist(
"/VAL/PHY/chik_dedx", m_chik_dedx);
123 m_chip_dedx =
new TH1F(
"chip_dedx",
"chip_dedx", 100,-20.0,5. );
124 status = m_thistsvc->regHist(
"/VAL/PHY/chip_dedx", m_chip_dedx);
127 if ( nt4 ) m_tuple4 = nt4;
129 m_tuple4 =
ntupleSvc()->book (
"FILE1/h4", CLID_ColumnWiseTuple,
"4gam6pi Ntuple");
131 status = m_tuple4->addItem (
"ngam", m_ngoodneu);
132 status = m_tuple4->addItem (
"npip", m_npip);
133 status = m_tuple4->addItem (
"npim", m_npim);
134 status = m_tuple4->addItem (
"ngoodch", m_ngoodch);
135 status = m_tuple4->addItem (
"chisq4c", m_chisq4c);
136 status = m_tuple4->addItem (
"ppi04c", m_ppi0);
137 status = m_tuple4->addItem (
"mpi04c", m_mpi0);
138 status = m_tuple4->addItem (
"chisq5c", m_chisq5c);
139 status = m_tuple4->addItem (
"ppi05c", m_ppi0fit);
140 status = m_tuple4->addItem (
"mpi05c", m_mpi0fit);
141 status = m_tuple4->addItem (
"g1inpi0the", m_g1inpi0the);
142 status = m_tuple4->addItem (
"g2inpi0the", m_g2inpi0the);
143 status = m_tuple4->addItem (
"theta2pi", m_theta2pi);
144 status = m_tuple4->addItem (
"ppip", m_ppip);
145 status = m_tuple4->addItem (
"ppim", m_ppim);
146 status = m_tuple4->addItem (
"p2pi", m_p2pi);
147 status = m_tuple4->addItem (
"m2pi", m_m2pi);
148 status = m_tuple4->addItem (
"ppip0", m_ppip0);
149 status = m_tuple4->addItem (
"mpip0", m_mpip0);
150 status = m_tuple4->addItem (
"ppim0", m_ppim0);
151 status = m_tuple4->addItem (
"mpim0", m_mpim0);
152 status = m_tuple4->addItem (
"eneumiss", m_eneumiss);
153 status = m_tuple4->addItem (
"pneumiss", m_pneumiss);
154 status = m_tuple4->addItem (
"mneumiss", m_mneumiss);
158 log << MSG::ERROR <<
" Cannot book N-tuple:" << long(m_tuple4) << endmsg;
159 return StatusCode::FAILURE;
164 if ( nt5 ) m_tuple5 = nt5;
166 m_tuple5 =
ntupleSvc()->book (
"FILE1/h5", CLID_ColumnWiseTuple,
"4gam6pi Ntuple");
168 status = m_tuple5->addItem (
"m2graw", m_m2graw);
169 status = m_tuple5->addItem (
"emiss", m_emiss);
170 status = m_tuple5->addItem (
"pmiss", m_pmiss);
171 status = m_tuple5->addItem (
"mmiss", m_mmiss);
172 status = m_tuple5->addItem (
"prho0", m_prho0);
173 status = m_tuple5->addItem (
"mrho0", m_mrho0);
174 status = m_tuple5->addItem (
"pmrho0", m_pmrho0);
175 status = m_tuple5->addItem (
"mmrho0", m_mmrho0);
176 status = m_tuple5->addItem (
"prhop", m_prhop);
177 status = m_tuple5->addItem (
"mrhop", m_mrhop);
178 status = m_tuple5->addItem (
"pmrhom", m_pmrhom);
179 status = m_tuple5->addItem (
"mmrhom", m_mmrhom);
180 status = m_tuple5->addItem (
"prhom", m_prhom);
181 status = m_tuple5->addItem (
"ppipraw", m_ppipraw);
182 status = m_tuple5->addItem (
"mrhom", m_mrhom);
186 log << MSG::ERROR <<
" Cannot book N-tuple:" << long(m_tuple4) << endmsg;
187 return StatusCode::FAILURE;
196 log << MSG::INFO <<
"successfully return from initialize()" <<endmsg;
197 return StatusCode::SUCCESS;
204 StatusCode sc = StatusCode::SUCCESS;
206 MsgStream log(
msgSvc(), name());
211 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),
"/Event/EventHeader");
222 Vint ipip, ipim, iGood;
232 for(
int i = 0; i < evtRecEvent->totalCharged(); i++){
234 if(!(*itTrk)->isMdcTrackValid())
continue;
237 m_pi_vx->Fill(mdcTrk->
x());
238 m_pi_vy->Fill(mdcTrk->
y());
239 m_pi_vz->Fill(mdcTrk->
z());
241 if(fabs(mdcTrk->
z()) >= m_vz0cut)
continue;
242 if(mdcTrk->
r() >= m_vr0cut)
continue;
243 iGood.push_back((*itTrk)->trackId());
244 TotCharge += mdcTrk->
charge();
249 int nGood = iGood.size();
254 for(
int i = evtRecEvent->totalCharged(); i< evtRecEvent->totalTracks(); i++) {
256 if(!(*itTrk)->isEmcShowerValid())
continue;
258 Hep3Vector emcpos(emcTrk->
x(), emcTrk->
y(), emcTrk->
z());
263 for(
int j = 0; j < evtRecEvent->totalCharged(); j++) {
265 if(!(*jtTrk)->isExtTrackValid())
continue;
270 double angd = extpos.angle(emcpos);
271 double thed = extpos.theta() - emcpos.theta();
272 double phid = extpos.deltaPhi(emcpos);
273 thed = fmod(thed+CLHEP::twopi+CLHEP::twopi+
pi, CLHEP::twopi) - CLHEP::pi;
274 phid = fmod(phid+CLHEP::twopi+CLHEP::twopi+
pi, CLHEP::twopi) - CLHEP::pi;
275 angd = fmod(angd, CLHEP::twopi);
284 if(dang >= 200.)
continue;
286 double eraw = emcTrk->
energy();
287 dthe = dthe * 180 / (CLHEP::pi);
288 dphi = dphi * 180 / (CLHEP::pi);
289 dang = dang * 180 / (CLHEP::pi);
290 if(eraw < m_energyThreshold)
continue;
295 iGam.push_back((*itTrk)->trackId());
300 int nGam = iGam.size();
306 HepLorentzVector ptcharg, ptneu, ptchargp, ptchargm;
309 for(
int i = 0; i < nGam; i++) {
312 double eraw = emcTrk->
energy();
313 double phi = emcTrk->
phi();
314 double the = emcTrk->
theta();
315 HepLorentzVector
ptrk;
320 pGam.push_back(
ptrk);
326 for(
int i = 0; i < nGood; i++) {
328 if(!(*itTrk)->isMdcTrackValid())
continue;
329 if(!(*itTrk)->isMdcDedxValid())
continue;
332 m_chie_dedx ->
Fill(dedxTrk->
chiE());
335 m_chik_dedx ->
Fill(dedxTrk->
chiK());
336 m_chip_dedx ->
Fill(dedxTrk->
chiP());
346 for(
int i = 0; i < nGood; i++) {
358 if(!(*itTrk)->isMdcKalTrackValid()) continue ;
362 TotQ += mdcKalTrk->
charge();
369 HepLorentzVector
ptrk;
370 ptrk.setPx(mdcKalTrk->
px());
371 ptrk.setPy(mdcKalTrk->
py());
372 ptrk.setPz(mdcKalTrk->
pz());
376 ipip.push_back(iGood[i]);
377 ppip.push_back(
ptrk);
379 ipim.push_back(iGood[i]);
380 ppim.push_back(
ptrk);
384 int npip = ipip.size();
385 int npim = ipim.size();
389 if(nGood != 2 || TotCharge!=0)
return sc;
391 if(nGam<2 )
return sc;
397 HepLorentzVector BoostP(0.0,0.0,0.0,
ecms);
398 BoostP[0] = 2*
sin(0.011)*(
ecms/2);
399 Hep3Vector u_Boost = -BoostP.boostVector();
405 HepLorentzVector p2g, ppi0;
406 double delmpi = 999.;
407 int ig11=-1, ig21=-1;
409 for(
int i = 0; i < nGam - 1; i++){
410 for(
int j = i+1; j < nGam; j++) {
411 HepLorentzVector ppi0 = pGam[i] + pGam[j];
412 if(fabs(ppi0.m()-
mpi0c) > delmpi)
continue;
413 if(ppi0.m() > 0.2)
continue;
414 delmpi = fabs(ppi0.m()-
mpi0c);
419 if(ig11==-1 || ig21== -1)
return sc;
420 p2g = pGam[ig11] + pGam[ig21];
423 HepLorentzVector Ppip1 = ppip[0];
424 Ppip1.boost(u_Boost);
432 HepLorentzVector Pmiss = -Ppip1 - p2g;
433 m_pmiss = Pmiss.rho();
434 double emiss =
ecms - Ppip1.e() - p2g.e();
436 m_mmiss = sqrt(fabs(emiss*emiss - Pmiss.rho()*Pmiss.rho()));
438 HepLorentzVector Prho0, Prhop, Prhom, pmisspi, ptot;
439 pmisspi.setPx(Pmiss.px());
440 pmisspi.setPy(Pmiss.py());
441 pmisspi.setPz(Pmiss.pz());
444 Prho0 = Ppip1 + pmisspi;
446 Prhom = pmisspi + p2g;
447 ptot = Ppip1 + pmisspi + p2g;
449 m_pmrho0 = Prho0.rho();
450 m_mmrho0 = Prho0.m();
453 m_prhop = Prhop.rho();
457 m_pmrhom = Prhom.rho();
458 m_mmrhom = Prhom.m();
459 m_ppipraw = Ppip1.rho();
464 if(npip*npim != 1)
return sc;
467 HepLorentzVector Ppim1 = ppim[0];
468 Ppim1.boost(u_Boost);
469 HepLorentzVector Ppip1 = ppip[0];
470 Ppip1.boost(u_Boost);
472 HepLorentzVector Pneumiss = -(Ppim1 + Ppip1);
473 m_pneumiss = Pneumiss.rho();
474 double eneumiss =
ecms - Ppim1.e() - Ppip1.e();
475 m_eneumiss = eneumiss;
476 m_mneumiss = sqrt(fabs(eneumiss*eneumiss - Pneumiss.rho()*Pneumiss.rho()));
482 HepSymMatrix Evx(3, 0);
497 RecMdcKalTrack *pipTrk = (*(evtRecTrkCol->begin()+ipip[0]))->mdcKalTrack();
504 RecMdcKalTrack *pimTrk = (*(evtRecTrkCol->begin()+ipim[0]))->mdcKalTrack();
516 if(!vtxfit->
Fit(0))
return sc;
529 double chisq4c = 9999.;
534 for(
int i = 0; i < nGam-1; i++) {
535 RecEmcShower *g1Trk = (*(evtRecTrkCol->begin()+iGam[i]))->emcShower();
536 for(
int j = i+1; j < nGam; j++) {
537 RecEmcShower *g2Trk = (*(evtRecTrkCol->begin()+iGam[j]))->emcShower();
546 if(!kmfit->
Fit())
continue;
547 double chi2 = kmfit->
chisq();
548 if(chi2 > chisq4c)
continue;
556 if(chisq4c > 500 || ig1 < 0)
return sc;
557 RecEmcShower *g1Trk = (*(evtRecTrkCol->begin()+iGam[ig1]))->emcShower();
558 RecEmcShower *g2Trk = (*(evtRecTrkCol->begin()+iGam[ig2]))->emcShower();
566 if(!kmfit->
Fit())
return sc;
567 double chi = kmfit->
chisq();
569 m_chisq_4c ->
Fill(chi);
571 HepLorentzVector p2gam = kmfit->
pfit(2) + kmfit->
pfit(3);
575 m_pi0_mass ->
Fill(p2gam.m());
592 if(!kmfit->
Fit())
return sc;
593 double chis = kmfit->
chisq();
599 double chisk5c = 9999.;
618 if(kmfit->
Fit()) chisk5c = kmfit->
chisq();
620 if(chisk5c<chis)
return sc;
633 if(!kmfit->
Fit(0))
return sc;
634 if(!kmfit->
Fit())
return sc;
637 m_chisq5c = kmfit->
chisq();
641 HepLorentzVector ppi1 = kmfit->
pfit(0);
642 HepLorentzVector ppi2 = kmfit->
pfit(1);
643 HepLorentzVector pgam1 = kmfit->
pfit(2);
644 HepLorentzVector pgam2 = kmfit->
pfit(3);
645 HepLorentzVector p2gam1 = kmfit->
pfit(2) + kmfit->
pfit(3);
646 HepLorentzVector p2pi = kmfit->
pfit(0) + kmfit->
pfit(1);
647 m_ppi0fit = p2gam1.rho();
648 m_mpi0fit = p2gam1.m();
653 m_ppip0 = (ppi1+p2gam1).rho();
654 m_mpip0 = (ppi1+p2gam1).m();
655 m_ppim0 = (ppi2+p2gam1).rho();
656 m_mpim0 = (ppi2+p2gam1).m();
658 m_pip_mom ->
Fill(ppi1.rho());
659 m_pim_mom ->
Fill(ppi2.rho());
660 m_rho0_mass ->
Fill(p2pi.m());
661 m_rhop_mass ->
Fill((ppi1+p2gam1).m());
662 m_rhom_mass ->
Fill((ppi2+p2gam1).m());
665 double theta2pi= ppi1.px()*ppi2.px()+ppi1.py()*ppi2.py()+ppi1.pz()*ppi2.pz();
666 double time2pi = ppi1.rho()*ppi2.rho();
667 if(time2pi == 0.)
return sc;
671 theta2pi = theta2pi/time2pi;
675 if(theta2pi <= -1.) theta2pi=180.;
676 else if(theta2pi >= 1.) theta2pi=0.;
677 else if(fabs(theta2pi) < 1.) theta2pi = acos(theta2pi)*180./3.14159;
681 HepLorentzVector pg1inpi0, pg2inpi0;
684 double betapi0 = p2gam1.beta();
686 Hep3Vector twogam(p2gam.px(),p2gam.py(),p2gam.pz());
688 m_g1inpi0the = ((boostOf(pgam1,twogam/p2gam.rho(),betapi0)).theta())*180./3.14159;
689 m_g2inpi0the = ((boostOf(pgam2,twogam/p2gam.rho(),betapi0)).theta())*180./3.14159;
730 return StatusCode::SUCCESS;
736 MsgStream log(
msgSvc(), name());
737 log << MSG::ALWAYS <<
"Total Entries : " << m_pass[0] << endreq;
738 log << MSG::ALWAYS <<
"Ncharge=2 Cut : " << m_pass[1] << endreq;
739 log << MSG::ALWAYS <<
"Ngam<2 cut : " << m_pass[2] << endreq;
740 log << MSG::ALWAYS <<
"Nch+=1,Nch-=1 cut : " << m_pass[3] << endreq;
741 log << MSG::ALWAYS <<
"Vertex Fit : " << m_pass[4] << endreq;
742 log << MSG::ALWAYS <<
"4c-Fit : " << m_pass[5] << endreq;
743 log << MSG::ALWAYS <<
"5c-Fit : " << m_pass[6] << endreq;
744 log << MSG::ALWAYS <<
"chi3pi<chikkpi cut : " << m_pass[7] << endreq;
745 log << MSG::ALWAYS <<
"5c-Fit Again: " << m_pass[8] << endreq;
746 log << MSG::ALWAYS <<
"Final : " << m_pass[9] << endreq;
747 return StatusCode::SUCCESS;
double sin(const BesAngle a)
double cos(const BesAngle a)
EvtRecTrackCol::iterator EvtRecTrackIterator
std::vector< HepLorentzVector > Vp4
const Hep3Vector emcPosition() const
const int emcVolumeNumber() const
const HepVector & helix() const
static void setPidType(PidType pidType)
const HepSymMatrix & err() const
static KinematicFit * instance()
void AddResonance(int number, double mres, std::vector< int > tlis)
void AddFourMomentum(int number, HepLorentzVector p4)
HepLorentzVector pfit(int n) const
int methodProbability() const
void setChiMinCut(const double chi=4)
void setRecTrack(EvtRecTrack *trk)
void setMethod(const int method)
void identify(const int pidcase)
void usePidSys(const int pidsys)
static ParticleID * instance()
bool IsPidInfoValid() const
void AddTrack(const int number, const double mass, const RecMdcTrack *trk)
WTrackParameter wtrk(int n) const
void AddVertex(int number, VertexParameter vpar, std::vector< int > lis)
static VertexFit * instance()
void setEvx(const HepSymMatrix &eVx)
void setVx(const HepPoint3D &vx)
_EXTERN_ std::string EvtRecEvent
_EXTERN_ std::string EvtRecTrackCol
HepGeom::Point3D< double > HepPoint3D
std::vector< HepLorentzVector > Vp4