BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
Pi0EtaToGGRecAlg.cxx
Go to the documentation of this file.
1#include "GaudiKernel/IDataManagerSvc.h"
2#include "GaudiKernel/MsgStream.h"
3#include "GaudiKernel/SmartDataPtr.h"
4#include "GaudiKernel/SmartIF.h"
5
6#include "EventModel/EventHeader.h"
7#include "EvtRecEvent/EvtRecEtaToGG.h"
8#include "EvtRecEvent/EvtRecEvent.h"
9#include "EvtRecEvent/EvtRecPi0.h"
10#include "EvtRecEvent/EvtRecTrack.h"
11#include "VertexFit/KalmanKinematicFit.h"
12
13#include "Pi0EtaToGGRecAlg.h"
14
15const double xmpi0 = 0.134976; // BOSS 6.4.1 pdt.table value
16const double xmeta = 0.54784; // PDG08 = 0.547853, BOSS 6.4.1 pdt.table = 0.54784
18//*************************************************************************************
19Pi0EtaToGGRecAlg::Pi0EtaToGGRecAlg( const std::string& name, ISvcLocator* pSvcLocator )
20 : Algorithm( name, pSvcLocator ) {
21 // Declare the properties
22
23 declareProperty( "RejectBothInEndcap", m_rejectEndEnd = false );
24
25 /// pi0 properties
26 declareProperty( "Pi0MinMass", m_pi0minmass_cut = 0.08 );
27 declareProperty( "Pi0MaxMass", m_pi0maxmass_cut = 0.18 );
28 declareProperty( "Pi0ChisqCut", m_pi0chisq_cut = 2500 );
29
30 /// eta properties
31 declareProperty( "EtaMinMass", m_etaminmass_cut = 0.4 );
32 declareProperty( "EtaMaxMass", m_etamaxmass_cut = 0.7 );
33 declareProperty( "EtaChisqCut", m_etachisq_cut = 2500 );
34
35 /// Individual photons properties
36 declareProperty( "PhotonMinEnergy", m_minEnergy = 0.025 );
37
38 declareProperty( "PhotonInBarrelOrEndcap", m_useBarrelEndcap = true );
39 declareProperty( "PhotonMaxCosThetaBarrel", m_maxCosThetaBarrel = 0.8 );
40 declareProperty( "PhotonMinCosThetaEndcap", m_minCosThetaEndcap = 0.86 );
41 declareProperty( "PhotonMaxCosThetaEndcap", m_maxCosThetaEndcap = 0.92 );
42 declareProperty( "PhotonMinEndcapEnergy", m_minEndcapEnergy = 0.050 );
43
44 declareProperty( "PhotonApplyTimeCut", m_applyTimeCut = true );
45 declareProperty( "PhotonMinTime", m_minTime = 0. );
46 declareProperty( "PhotonMaxTime", m_maxTime = 14. );
47 declareProperty( "PhotonDeltaTime", m_deltaTime = 10. );
48
49 declareProperty( "PhotonApplyDangCut", m_applyDangCut = false );
50 declareProperty( "PhotonMinDang", m_minDang = 20.0 );
51
52 /// Limits for number of photons, pi0s and etas
53 declareProperty( "MaxNGoodPhoton", m_maxNGoodPhoton = 50 );
54 declareProperty( "MaxNPi0", m_maxNPi0 = 100 );
55 // declareProperty("MaxNEta", m_maxNEta = 100);
56
57 declareProperty( "DoClear", m_doClear = false );
58}
59
60//******************************************************************************************
62
63 MsgStream log( msgSvc(), name() );
64 log << MSG::INFO << "in initialize()" << endmsg;
65
66 return StatusCode::SUCCESS;
67}
68
69//*********************************************************************************************
70StatusCode Pi0EtaToGGRecAlg::execute() {
71
72 MsgStream log( msgSvc(), name() );
73 log << MSG::INFO << "in execute()" << endmsg;
74
75 // get event header, eventlist and tracklist from TDS
76 SmartDataPtr<Event::EventHeader> eventHeader( eventSvc(), "/Event/EventHeader" );
77 SmartDataPtr<EvtRecEvent> recEvt( eventSvc(), EventModel::EvtRec::EvtRecEvent );
78 SmartDataPtr<EvtRecTrackCol> recTrkCol( eventSvc(), EventModel::EvtRec::EvtRecTrackCol );
79
80 SmartDataPtr<EvtRecPi0Col> recPi0Col( eventSvc(), EventModel::EvtRec::EvtRecPi0Col );
81 if ( !recPi0Col )
82 {
83 recPi0Col = new EvtRecPi0Col;
84 StatusCode sc = eventSvc()->registerObject( EventModel::EvtRec::EvtRecPi0Col, recPi0Col );
85 if ( sc.isFailure() )
86 {
87 log << MSG::ERROR << "could not register EvtRecPi0Col in TDS" << endmsg;
88 return StatusCode::FAILURE;
89 }
90 }
91
92 SmartDataPtr<EvtRecEtaToGGCol> recEtaToGGCol( eventSvc(),
94 if ( !recEtaToGGCol )
95 {
96 recEtaToGGCol = new EvtRecEtaToGGCol;
97 StatusCode sc =
98 eventSvc()->registerObject( EventModel::EvtRec::EvtRecEtaToGGCol, recEtaToGGCol );
99 if ( sc.isFailure() )
100 {
101 log << MSG::ERROR << "could not register EvtRecEtaToGGCol in TDS" << endmsg;
102 return StatusCode::FAILURE;
103 }
104 }
105
106 if ( m_doClear )
107 {
108 SmartIF<IDataManagerSvc> dataManSvc( eventSvc() );
109 dataManSvc->clearSubTree( EventModel::EvtRec::EvtRecPi0Col );
110 dataManSvc->clearSubTree( EventModel::EvtRec::EvtRecEtaToGGCol );
111 }
112
113 // select good photons
114 std::vector<EvtRecTrack*> vGoodPhotons;
115 for ( int i = recEvt->totalCharged(); i < recEvt->totalTracks(); i++ )
116 {
117 EvtRecTrack* gTrk = *( recTrkCol->begin() + i );
118 if ( !validPhoton( gTrk, recEvt, recTrkCol ) ) continue;
119 vGoodPhotons.push_back( gTrk );
120 }
121
122 int nGoodPhoton = vGoodPhotons.size();
123 if ( nGoodPhoton > m_maxNGoodPhoton ) return StatusCode::SUCCESS;
124
125 /// Needed for 1C mass fits for pi0 and eta
126 KalmanKinematicFit* kmfit = KalmanKinematicFit::instance();
127
128 //
129 // Form two-photon combinations
130 //
131 for ( int i1 = 0; i1 < ( nGoodPhoton - 1 ); i1++ )
132 {
133 EvtRecTrack* g1Trk = vGoodPhotons[i1];
134 RecEmcShower* g1Shower = g1Trk->emcShower();
135 HepLorentzVector g1P4 = getP4( g1Shower );
136
137 for ( int i2 = i1 + 1; i2 < nGoodPhoton; i2++ )
138 {
139 EvtRecTrack* g2Trk = vGoodPhotons[i2];
140 RecEmcShower* g2Shower = g2Trk->emcShower();
141 HepLorentzVector g2P4 = getP4( g2Shower );
142
143 HepLorentzVector p2g = g1P4 + g2P4;
144
145 /// If RejectBothInEndcap=true, reject candidate if both photons are in endcaps
146 if ( m_rejectEndEnd && bothInEndcap( g1P4, g2P4 ) ) continue;
147
148 /// Select pi0 candidates
149 if ( ( p2g.m() > m_pi0minmass_cut ) && ( p2g.m() < m_pi0maxmass_cut ) )
150 {
151
152 /// Perform pi0 1C KinematicFit
153 kmfit->init();
154 kmfit->setIterNumber( 5 );
155 kmfit->AddTrack( 0, 0.0, g1Shower );
156 kmfit->AddTrack( 1, 0.0, g2Shower );
157 kmfit->AddResonance( 0, xmpi0, 0, 1 );
158
159 kmfit->Fit( 0 ); // Perform fit
160 kmfit->BuildVirtualParticle( 0 );
161
162 double pi0_chisq = kmfit->chisq( 0 );
163 if ( pi0_chisq >= m_pi0chisq_cut ) continue;
164
165 /// Fill EvtRecPi0
166 EvtRecPi0* recPi0 = new EvtRecPi0();
167 recPi0->setUnconMass( p2g.restMass() );
168 recPi0->setChisq( pi0_chisq );
169
170 if ( g1P4.e() >= g2P4.e() )
171 {
172 recPi0->setHiPfit( kmfit->pfit( 0 ) );
173 recPi0->setLoPfit( kmfit->pfit( 1 ) );
174 recPi0->setHiEnGamma( g1Trk );
175 recPi0->setLoEnGamma( g2Trk );
176 }
177 else
178 {
179 recPi0->setHiPfit( kmfit->pfit( 1 ) );
180 recPi0->setLoPfit( kmfit->pfit( 0 ) );
181 recPi0->setHiEnGamma( g2Trk );
182 recPi0->setLoEnGamma( g1Trk );
183 }
184 recPi0Col->push_back( recPi0 );
185
186 } // End of pi0 mass window IF
187
188 /// Select eta candidates
189 if ( ( p2g.m() > m_etaminmass_cut ) && ( p2g.m() < m_etamaxmass_cut ) )
190 {
191
192 /// Perform eta 1C KinematicFit
193 kmfit->init();
194 kmfit->setIterNumber( 5 );
195 kmfit->AddTrack( 0, 0.0, g1Shower );
196 kmfit->AddTrack( 1, 0.0, g2Shower );
197 kmfit->AddResonance( 0, xmeta, 0, 1 );
198
199 kmfit->Fit( 0 ); // Perform fit
200 kmfit->BuildVirtualParticle( 0 );
201
202 double eta_chisq = kmfit->chisq( 0 );
203 if ( eta_chisq >= m_etachisq_cut ) continue;
204
205 /// Fill EvtRecEtaToGG
206 EvtRecEtaToGG* recEtaToGG = new EvtRecEtaToGG();
207 recEtaToGG->setUnconMass( p2g.restMass() );
208 recEtaToGG->setChisq( eta_chisq );
209
210 if ( g1P4.e() >= g2P4.e() )
211 {
212 recEtaToGG->setHiPfit( kmfit->pfit( 0 ) );
213 recEtaToGG->setLoPfit( kmfit->pfit( 1 ) );
214 recEtaToGG->setHiEnGamma( g1Trk );
215 recEtaToGG->setLoEnGamma( g2Trk );
216 }
217 else
218 {
219 recEtaToGG->setHiPfit( kmfit->pfit( 1 ) );
220 recEtaToGG->setLoPfit( kmfit->pfit( 0 ) );
221 recEtaToGG->setHiEnGamma( g2Trk );
222 recEtaToGG->setLoEnGamma( g1Trk );
223 }
224 recEtaToGGCol->push_back( recEtaToGG );
225
226 } // End of etaToGG mass window IF
227
228 } // End of g2Trk evtRec FOR
229 } // End of g1Trk evtRec FOR
230
231 // If there are too many pi0s, it's possibly a bad event and all pi0s are abandoned
232 if ( recPi0Col->size() > m_maxNPi0 ) { recPi0Col->clear(); }
233
234 return StatusCode::SUCCESS;
235}
236
237//********************************************************************************************
238StatusCode Pi0EtaToGGRecAlg::finalize() {
239
240 MsgStream log( msgSvc(), name() );
241 log << MSG::INFO << "in finalize()" << endmsg;
242
243 return StatusCode::SUCCESS;
244}
245
246/// ************************** FUNCTIONS *****************************************************
247HepLorentzVector Pi0EtaToGGRecAlg::getP4( RecEmcShower* gTrk ) {
248
249 double eraw = gTrk->energy();
250 double phi = gTrk->phi();
251 double the = gTrk->theta();
252
253 return HepLorentzVector( eraw * sin( the ) * cos( phi ), eraw * sin( the ) * sin( phi ),
254 eraw * cos( the ), eraw );
255}
256
257bool Pi0EtaToGGRecAlg::validPhoton( EvtRecTrack* recTrk, SmartDataPtr<EvtRecEvent> recEvt,
258 SmartDataPtr<EvtRecTrackCol> recTrkCol ) {
259 if ( !recTrk->isEmcShowerValid() ) return false;
260
261 RecEmcShower* emcTrk = recTrk->emcShower();
262
263 HepLorentzVector shP4 = getP4( emcTrk );
264 double cosThetaSh = shP4.vect().cosTheta();
265
266 /// Minimum energy
267 if ( shP4.e() <= m_minEnergy ) return false;
268
269 /// Barrel/Endcap
270 if ( m_useBarrelEndcap )
271 {
272 bool inBarrelEndcap = false;
273
274 if ( fabs( cosThetaSh ) < m_maxCosThetaBarrel ) inBarrelEndcap = true;
275
276 if ( ( fabs( cosThetaSh ) > m_minCosThetaEndcap ) &&
277 ( fabs( cosThetaSh ) < m_maxCosThetaEndcap ) && ( shP4.e() > m_minEndcapEnergy ) )
278 inBarrelEndcap = true;
279
280 if ( !inBarrelEndcap ) return false;
281 }
282
283 /// Time, only apply timing cuts if "recEvt->totalCharged() > 0"
284 if ( m_applyTimeCut )
285 {
286 double time = emcTrk->time();
287 if ( recEvt->totalCharged() > 0 )
288 {
289 if ( time < m_minTime || time > m_maxTime ) return false;
290 }
291 else
292 {
293 RecEmcShower* firstG = ( *( recTrkCol->begin() ) )->emcShower();
294 double deltaTime = fabs( time - firstG->time() );
295 if ( deltaTime > 10 ) return false;
296 }
297 }
298
299 /// Dang
300 if ( m_applyDangCut && recEvt->totalCharged() > 0 )
301 {
302 Hep3Vector emcpos( emcTrk->x(), emcTrk->y(), emcTrk->z() );
303 double dang = 200.;
304
305 for ( int j = 0; j < recEvt->totalCharged(); j++ )
306 {
307 EvtRecTrackIterator jtTrk = recTrkCol->begin() + j;
308 if ( !( *jtTrk )->isExtTrackValid() ) continue;
309 RecExtTrack* extTrk = ( *jtTrk )->extTrack();
310 if ( extTrk->emcVolumeNumber() == -1 ) continue;
311 Hep3Vector extpos = extTrk->emcPosition();
312 double angd1 = extpos.angle( emcpos );
313 if ( angd1 < dang ) dang = angd1;
314 }
315
316 if ( dang < 200 )
317 {
318 dang = dang * 180 / ( CLHEP::pi );
319 if ( dang <= m_minDang ) return false;
320 }
321 } // End of "recEvt->totalCharged() > 0" IF
322
323 return true;
324}
325
326bool Pi0EtaToGGRecAlg::bothInEndcap( HepLorentzVector g1_P4, HepLorentzVector g2_P4 ) {
327
328 double g1_CosTheta = g1_P4.vect().cosTheta();
329 double g2_CosTheta = g2_P4.vect().cosTheta();
330
331 bool g1InEndcap = false;
332 bool g2InEndcap = false;
333
334 if ( ( fabs( g1_CosTheta ) > m_minCosThetaEndcap ) &&
335 ( fabs( g1_CosTheta ) < m_maxCosThetaEndcap ) )
336 g1InEndcap = true;
337
338 if ( ( fabs( g2_CosTheta ) > m_minCosThetaEndcap ) &&
339 ( fabs( g2_CosTheta ) < m_maxCosThetaEndcap ) )
340 g2InEndcap = true;
341
342 if ( g1InEndcap && g2InEndcap ) return ( true );
343
344 return ( false );
345}
DECLARE_COMPONENT(BesBdkRc)
Double_t time
ObjectVector< EvtRecEtaToGG > EvtRecEtaToGGCol
ObjectVector< EvtRecPi0 > EvtRecPi0Col
EvtRecTrackCol::iterator EvtRecTrackIterator
const double xmeta
***************************************************************************************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 setHiPfit(const HepLorentzVector &hiPfit)
void setLoPfit(const HepLorentzVector &loPfit)
void setLoPfit(const HepLorentzVector &loPfit)
void setLoEnGamma(const EvtRecTrack *trk)
void setHiPfit(const HepLorentzVector &hiPfit)
void setUnconMass(const double unconMass)
void setHiEnGamma(const EvtRecTrack *trk)
void BuildVirtualParticle(int number)
void AddResonance(int number, double mres, std::vector< int > tlis)
static KalmanKinematicFit * instance()
Pi0EtaToGGRecAlg(const std::string &name, ISvcLocator *pSvcLocator)
void AddTrack(const int number, const double mass, const RecMdcTrack *trk)
Definition TrackPool.cxx:21