BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
misc/Pi0EtaToGGRecAlg.cxx
Go to the documentation of this file.
1#include "GaudiKernel/MsgStream.h"
2#include "GaudiKernel/SmartDataPtr.h"
3
4#include "EventModel/EventHeader.h"
5#include "EvtRecEvent/EvtRecEvent.h"
6#include "EvtRecEvent/EvtRecPi0.h"
7#include "EvtRecEvent/EvtRecTrack.h"
8#include "VertexFit/KinematicFit.h"
9
10#include "Pi0EtaToGGRecAlg/Pi0EtaToGGRecAlg.h"
11
12const double xmpi0 = 0.13497;
13
14//*******************************************************************************************
15Pi0EtaToGGRecAlg::Pi0EtaToGGRecAlg( const std::string& name, ISvcLocator* pSvcLocator )
16 : Algorithm( name, pSvcLocator ) {
17 // Declare the properties
18 declareProperty( "Pi0MinMass", m_minmass_cut = 0.07 );
19 declareProperty( "Pi0MaxMass", m_maxmass_cut = 0.18 );
20 declareProperty( "Pi0ChisqCut", m_chisq_cut = 20.0 );
21
22 /// Individual photons
23 declareProperty( "PhotonUseBarrelEmc", m_useBarrel = true );
24 declareProperty( "PhotonUseEndcapEmc", m_useEndcap = true );
25 declareProperty( "PhotonMinEnergy", m_minEnergy = 0.02 );
26 declareProperty( "PhotonDeltaAngleCut", m_angled_cut = 20.0 );
27 declareProperty( "PhotonDeltaThetaCut", m_thed_cut = 20.0 );
28 declareProperty( "PhotonDeltaPhiCut", m_phid_cut = 20.0 );
29}
30
31//******************************************************************************************
33
34 MsgStream log( msgSvc(), name() );
35 log << MSG::INFO << "in initialize()" << endmsg;
36
37 return StatusCode::SUCCESS;
38}
39
40//*********************************************************************************************
42
43 MsgStream log( msgSvc(), name() );
44 log << MSG::INFO << "in execute()" << endmsg;
45
46 // get event header, eventlist and tracklist from TDS
47 SmartDataPtr<Event::EventHeader> eventHeader( eventSvc(), "/Event/EventHeader" );
48 SmartDataPtr<EvtRecEvent> recEvt( eventSvc(), EventModel::EvtRec::EvtRecEvent );
49 SmartDataPtr<EvtRecTrackCol> recTrkCol( eventSvc(), EventModel::EvtRec::EvtRecTrackCol );
50
51 bool save2TDS = false;
52 SmartDataPtr<EvtRecPi0Col> recPi0Col( eventSvc(), EventModel::EvtRec::EvtRecPi0Col );
53 if ( !recPi0Col )
54 {
55 recPi0Col = new EvtRecPi0Col;
56 save2TDS = true;
57 }
58
60
61 //
62 // Set up the pi0's list
63 //
64 for ( int i1 = recEvt->totalCharged(); i1 < ( recEvt->totalTracks() - 1 ); i1++ )
65 {
66 EvtRecTrack* g1Trk = *( recTrkCol->begin() + i1 );
67 if ( !validPhoton( g1Trk, recEvt, recTrkCol ) ) continue;
68 RecEmcShower* g1Shower = g1Trk->emcShower();
69 HepLorentzVector g1P4 = getP4( g1Shower );
70
71 for ( int i2 = i1 + 1; i2 < recEvt->totalTracks(); i2++ )
72 {
73 EvtRecTrack* g2Trk = *( recTrkCol->begin() + i2 );
74 if ( !validPhoton( g2Trk, recEvt, recTrkCol ) ) continue;
75 RecEmcShower* g2Shower = g2Trk->emcShower();
76 HepLorentzVector g2P4 = getP4( g2Shower );
77
78 HepLorentzVector p2g = g1P4 + g2P4;
79 if ( p2g.m() < m_minmass_cut ) continue;
80 if ( p2g.m() > m_maxmass_cut ) continue;
81
82 /// Perform pi0 1C kinfit
83 kmfit->init();
84 kmfit->setIterNumber( 1 );
85 kmfit->AddTrack( 0, 0.0, g1Shower );
86 kmfit->AddTrack( 1, 0.0, g2Shower );
87 kmfit->AddResonance( 0, xmpi0, 0, 1 );
88 if ( !kmfit->Fit( 0 ) ) continue;
89 kmfit->BuildVirtualParticle( 0 );
90
91 double pi0_chisq = kmfit->chisq( 0 );
92 if ( pi0_chisq > m_chisq_cut ) continue;
93
94 double e1 = ( kmfit->pfit( 0 ) ).e();
95 double e2 = ( kmfit->pfit( 1 ) ).e();
96 HepLorentzVector ppi0 = kmfit->pfit( 0 ) + kmfit->pfit( 1 );
97
98 EvtRecPi0* recPi0 = new EvtRecPi0();
99 recPi0->setRawMass( p2g.restMass() );
100 recPi0->setChisq( pi0_chisq );
101 recPi0->setFcos( ( e1 - e2 ) / ppi0.rho() );
102
103 if ( g1P4.e() >= g2P4.e() )
104 {
105 recPi0->setHiPfit( kmfit->pfit( 0 ) );
106 recPi0->setLoPfit( kmfit->pfit( 1 ) );
107 recPi0->setHiEnGamma( g1Trk );
108 recPi0->setLoEnGamma( g2Trk );
109 }
110 else
111 {
112 recPi0->setHiPfit( kmfit->pfit( 1 ) );
113 recPi0->setLoPfit( kmfit->pfit( 0 ) );
114 recPi0->setHiEnGamma( g2Trk );
115 recPi0->setLoEnGamma( g1Trk );
116 }
117
118 std::cout << "p(g1) = " << g1P4 << std::endl;
119 std::cout << "p(g2) = " << g2P4 << std::endl;
120 std::cout << "chi2(pi0) = " << pi0_chisq << std::endl;
121 std::cout << "m(gg) before fill = " << p2g.restMass() << std::endl << std::endl;
122
123 recPi0Col->push_back( recPi0 );
124 }
125 }
126
127 /// Fill number of pi0s in EvtRecEvent
128 recEvt->setNumberOfPi0( recPi0Col->size() );
129
130 if ( save2TDS )
131 {
132 StatusCode sc = eventSvc()->registerObject( EventModel::EvtRec::EvtRecPi0Col, recPi0Col );
133 if ( sc.isFailure() )
134 {
135 log << MSG::ERROR << "could not register EvtRecPi0Col in TDS" << endmsg;
136 return StatusCode::FAILURE;
137 }
138 }
139
140 return StatusCode::SUCCESS;
141}
142
143//********************************************************************************************
145
146 MsgStream log( msgSvc(), name() );
147 log << MSG::INFO << "in finalize()" << endmsg;
148
149 return StatusCode::SUCCESS;
150}
151
152HepLorentzVector Pi0EtaToGGRecAlg::getP4( RecEmcShower* gTrk ) {
153
154 double eraw = gTrk->energy();
155 double phi = gTrk->phi();
156 double the = gTrk->theta();
157
158 return HepLorentzVector( eraw * sin( the ) * cos( phi ), eraw * sin( the ) * sin( phi ),
159 eraw * cos( the ), eraw );
160}
161
162bool Pi0EtaToGGRecAlg::validPhoton( EvtRecTrack* recTrk, SmartDataPtr<EvtRecEvent> recEvt,
163 SmartDataPtr<EvtRecTrackCol> recTrkCol ) {
164
165 if ( !recTrk->isEmcShowerValid() ) return ( false );
166
167 RecEmcShower* emcTrk = recTrk->emcShower();
168
169 // flag = 1: Barrel = 0,2 : Endcap
170 int flag = ( emcTrk->cellId() & 0x000F0000 ) >> 16;
171 if ( ( flag == 1 ) && !m_useBarrel ) return ( false );
172 if ( ( flag == 0 || flag == 2 ) && !m_useEndcap ) return ( false );
173
174 if ( emcTrk->energy() < m_minEnergy ) return ( false );
175
176 /// find the nearest charged track
177 Hep3Vector emcpos( emcTrk->x(), emcTrk->y(), emcTrk->z() );
178 if ( recEvt->totalCharged() > 0 )
179 {
180 double dthe = 200.;
181 double dphi = 200.;
182 double dang1 = 200.;
183 for ( int j = 0; j < recEvt->totalCharged(); j++ )
184 {
185 EvtRecTrackIterator jtTrk = recTrkCol->begin() + j;
186 if ( !( *jtTrk )->isExtTrackValid() ) continue;
187 RecExtTrack* extTrk = ( *jtTrk )->extTrack();
188 if ( extTrk->emcVolumeNumber() == -1 ) continue;
189 Hep3Vector extpos = extTrk->emcPosition();
190 double angd1 = extpos.angle( emcpos );
191 double thed = extpos.theta() - emcpos.theta();
192 double phid = extpos.deltaPhi( emcpos );
193 thed = fmod( thed + CLHEP::twopi + CLHEP::twopi + CLHEP::pi, CLHEP::twopi ) - CLHEP::pi;
194 phid = fmod( phid + CLHEP::twopi + CLHEP::twopi + CLHEP::pi, CLHEP::twopi ) - CLHEP::pi;
195
196 if ( fabs( thed ) < fabs( dthe ) ) dthe = thed;
197 if ( fabs( phid ) < fabs( dphi ) ) dphi = phid;
198 if ( angd1 < dang1 ) dang1 = angd1;
199 }
200 if ( dang1 < 200 )
201 {
202 dthe = dthe * 180 / ( CLHEP::pi );
203 dphi = dphi * 180 / ( CLHEP::pi );
204 dang1 = dang1 * 180 / ( CLHEP::pi );
205 if ( m_angled_cut > 0 )
206 {
207 if ( dang1 < m_angled_cut ) return ( false );
208 }
209 else
210 {
211 if ( ( fabs( dthe ) < m_thed_cut ) && ( fabs( dphi ) < m_phid_cut ) ) return ( false );
212 }
213 } // End of "dang1 < 200" IF
214
215 } // End of "recEvt->totalCharged() > 0" IF
216
217 return true;
218}
Double_t e1
Double_t e2
ObjectVector< EvtRecPi0 > EvtRecPi0Col
EvtRecTrackCol::iterator EvtRecTrackIterator
***************************************************************************************Pseudo Class RRes *****************************************************************************************Parameters and physical constants **Maarten sept ************************************************************************DOUBLE PRECISION xsmu **************************************************************************PARTICLE DATA all others are from PDG *Only resonances with known widths into electron pairs are sept ************************************************************************C Declarations xmb DOUBLE PRECISION xcb DOUBLE PRECISION xmpi0
Definition RRes.h:32
IMessageSvc * msgSvc()
void setLoPfit(const HepLorentzVector &loPfit)
void setLoEnGamma(const EvtRecTrack *trk)
void setHiPfit(const HepLorentzVector &hiPfit)
void setHiEnGamma(const EvtRecTrack *trk)
static KinematicFit * instance()
void BuildVirtualParticle(int number)
void AddResonance(int number, double mres, std::vector< int > tlis)
Pi0EtaToGGRecAlg(const std::string &name, ISvcLocator *pSvcLocator)
void AddTrack(const int number, const double mass, const RecMdcTrack *trk)
Definition TrackPool.cxx:21