BOSS 7.0.2
BESIII Offline Software System
Loading...
Searching...
No Matches
EvtSelExample.cxx
Go to the documentation of this file.
1#include <vector>
2
3#include "GaudiKernel/MsgStream.h"
4#include "GaudiKernel/AlgFactory.h"
5#include "GaudiKernel/ISvcLocator.h"
6#include "GaudiKernel/SmartDataPtr.h"
7#include "GaudiKernel/IDataProviderSvc.h"
8#include "GaudiKernel/PropertyMgr.h"
9#include "VertexFit/IVertexDbSvc.h"
10#include "GaudiKernel/Bootstrap.h"
11#include "GaudiKernel/ISvcLocator.h"
12
13#include "EventModel/EventModel.h"
14#include "EventModel/Event.h"
15
16#include "EvtRecEvent/EvtRecEvent.h"
17#include "EvtRecEvent/EvtRecTrack.h"
18#include "DstEvent/TofHitStatus.h"
19#include "EventModel/EventHeader.h"
20
21#include "TMath.h"
22#include "GaudiKernel/INTupleSvc.h"
23#include "GaudiKernel/NTuple.h"
24#include "GaudiKernel/Bootstrap.h"
25#include "GaudiKernel/IHistogramSvc.h"
26#include "CLHEP/Vector/ThreeVector.h"
27#include "CLHEP/Vector/LorentzVector.h"
28#include "CLHEP/Vector/TwoVector.h"
29
30using CLHEP::Hep3Vector;
31using CLHEP::Hep2Vector;
32using CLHEP::HepLorentzVector;
33#include "CLHEP/Geometry/Point3D.h"
34
35#include "VertexFit/KinematicFit.h"
36#include "VertexFit/VertexFit.h"
37#include "ParticleID/ParticleID.h"
38
39//
40#include "EvtSelExample/EvtSelExample.h"
41
42#ifndef ENABLE_BACKWARDS_COMPATIBILITY
44#endif
45using CLHEP::HepLorentzVector;
46
47const double mpi = 0.13957;
48const double mk = 0.493677;
49const double xmass[5] = {0.000511, 0.105658, 0.139570,0.493677, 0.938272};
50const double velc = 299.792458; // tof path unit in mm
51typedef std::vector<int> Vint;
52typedef std::vector<HepLorentzVector> Vp4;
53
54/////////////////////////////////////////////////////////////////////////////
55
56EvtSelExample::EvtSelExample(const std::string& name, ISvcLocator* pSvcLocator) :
57 Algorithm(name, pSvcLocator) {
58
59 //Declare the properties
60 declareProperty("Vr0cut", m_vr0cut=5.0);
61 declareProperty("Vz0cut", m_vz0cut=20.0);
62 declareProperty("Vr1cut", m_vr1cut=1.0);
63 declareProperty("Vz1cut", m_vz1cut=5.0);
64 declareProperty("Vctcut", m_cthcut=0.93);
65 declareProperty("EnergyThreshold", m_energyThreshold=0.04);
66 declareProperty("GammaAngCut", m_gammaAngCut=20.0);
67}
68
69
70// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
72 MsgStream log(msgSvc(), name());
73
74 log << MSG::INFO << "in initialize()" << endmsg;
75 StatusCode status;
76
77 // DQA
78 // The first directory specifier must be "DQAFILE"
79 // The second is the control sample name, the first letter is in upper format. eg. "Rhopi"
80 NTuplePtr nt(ntupleSvc(), "DQAFILE/Rhopi");
81 if ( nt ) m_tuple = nt;
82 else {
83 m_tuple = ntupleSvc()->book("DQAFILE/Rhopi", CLID_ColumnWiseTuple, "Rhopi ntuple");
84 if( m_tuple ) {
85 status = m_tuple->addItem("runNo", m_runNo);
86 status = m_tuple->addItem("event", m_event);
87 } else {
88 log << MSG::ERROR << "Can not book N-tuple:" << long(m_tuple) << endreq;
89 }
90 }
91
92 log << MSG::INFO << "successfully return from initialize()" <<endmsg;
93 return StatusCode::SUCCESS;
94
95
96}
97
98// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
100
101 MsgStream log(msgSvc(), name());
102 log << MSG::INFO << "in execute()" << endreq;
103
104 // DQA
105 // Add the line below at the beginning of execute()
106 //
107 setFilterPassed(false);
108
109 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),"/Event/EventHeader");
110 m_runNo=eventHeader->runNumber();
111 m_event=eventHeader->eventNumber();
112 log << MSG::DEBUG <<"run, evtnum = "
113 << m_runNo << " , "
114 << m_event <<endreq;
115
116
117 SmartDataPtr<EvtRecEvent> evtRecEvent(eventSvc(), EventModel::EvtRec::EvtRecEvent);
118 log << MSG::DEBUG <<"ncharg, nneu, tottks = "
119 << evtRecEvent->totalCharged() << " , "
120 << evtRecEvent->totalNeutral() << " , "
121 << evtRecEvent->totalTracks() <<endreq;
122
123 SmartDataPtr<EvtRecTrackCol> evtRecTrkCol(eventSvc(), EventModel::EvtRec::EvtRecTrackCol);
124
125 if(evtRecEvent->totalNeutral()>100) {
126 return StatusCode::SUCCESS;
127 }
128
129 Vint iGood, ipip, ipim;
130 iGood.clear();
131 ipip.clear();
132 ipim.clear();
133 Vp4 ppip, ppim;
134 ppip.clear();
135 ppim.clear();
136
137 Hep3Vector xorigin(0,0,0);
138
139 IVertexDbSvc* vtxsvc;
140 Gaudi::svcLocator()->service("VertexDbSvc", vtxsvc);
141 if(vtxsvc->isVertexValid()){
142 double* dbv = vtxsvc->PrimaryVertex();
143 double* vv = vtxsvc->SigmaPrimaryVertex();
144 xorigin.setX(dbv[0]);
145 xorigin.setY(dbv[1]);
146 xorigin.setZ(dbv[2]);
147 }
148
149 int nCharge = 0;
150 for(int i = 0; i < evtRecEvent->totalCharged(); i++){
151 EvtRecTrackIterator itTrk=evtRecTrkCol->begin() + i;
152 if(!(*itTrk)->isMdcTrackValid()) continue;
153 if (!(*itTrk)->isMdcKalTrackValid()) continue;
154 RecMdcTrack *mdcTrk = (*itTrk)->mdcTrack();
155
156 double pch =mdcTrk->p();
157 double x0 =mdcTrk->x();
158 double y0 =mdcTrk->y();
159 double z0 =mdcTrk->z();
160 double phi0=mdcTrk->helix(1);
161 double xv=xorigin.x();
162 double yv=xorigin.y();
163 double Rxy=fabs((x0-xv)*cos(phi0)+(y0-yv)*sin(phi0));
164
165 if(fabs(z0) >= m_vz0cut) continue;
166 if(Rxy >= m_vr0cut) continue;
167// if(fabs(m_Vct)>=m_cthcut) continue;
168 iGood.push_back((*itTrk)->trackId());
169 nCharge += mdcTrk->charge();
170 if (mdcTrk->charge() > 0) {
171 ipip.push_back((*itTrk)->trackId());
172 } else {
173 ipim.push_back((*itTrk)->trackId());
174 }
175 }
176
177 //
178 // Finish Good Charged Track Selection
179 //
180 int nGood = iGood.size();
181 log << MSG::DEBUG << "ngood, totcharge = " << nGood << " , " << nCharge << endreq;
182 if((nGood != 2)||(nCharge!=0)){
183 return StatusCode::SUCCESS;
184 }
185
186 Vint iGam;
187 iGam.clear();
188 for(int i = evtRecEvent->totalCharged(); i< evtRecEvent->totalTracks(); i++) {
189 EvtRecTrackIterator itTrk=evtRecTrkCol->begin() + i;
190 if(!(*itTrk)->isEmcShowerValid()) continue;
191 RecEmcShower *emcTrk = (*itTrk)->emcShower();
192 Hep3Vector emcpos(emcTrk->x(), emcTrk->y(), emcTrk->z());
193 // find the nearest charged track
194 double dthe = 200.;
195 double dphi = 200.;
196 double dang = 200.;
197 for(int j = 0; j < evtRecEvent->totalCharged(); j++) {
198 EvtRecTrackIterator jtTrk = evtRecTrkCol->begin() + j;
199 if(!(*jtTrk)->isExtTrackValid()) continue;
200 RecExtTrack *extTrk = (*jtTrk)->extTrack();
201 if(extTrk->emcVolumeNumber() == -1) continue;
202 Hep3Vector extpos = extTrk->emcPosition();
203 // double ctht = extpos.cosTheta(emcpos);
204 double angd = extpos.angle(emcpos);
205 double thed = extpos.theta() - emcpos.theta();
206 double phid = extpos.deltaPhi(emcpos);
207 thed = fmod(thed+CLHEP::twopi+CLHEP::twopi+pi, CLHEP::twopi) - CLHEP::pi;
208 phid = fmod(phid+CLHEP::twopi+CLHEP::twopi+pi, CLHEP::twopi) - CLHEP::pi;
209
210// if(fabs(thed) < fabs(dthe)) dthe = thed;
211// if(fabs(phid) < fabs(dphi)) dphi = phid;
212 if(angd < dang) {
213 dang = angd;
214 dthe = thed;
215 dphi = phid;
216 }
217 }
218 if(dang>=200) continue;
219 double eraw = emcTrk->energy();
220 dthe = dthe * 180 / (CLHEP::pi);
221 dphi = dphi * 180 / (CLHEP::pi);
222 dang = dang * 180 / (CLHEP::pi);
223 if(eraw < m_energyThreshold) continue;
224 if(dang < m_gammaAngCut) continue;
225// if((fabs(dthe) < m_gammaThetaCut) && (fabs(dphi)<m_gammaPhiCut) ) continue;
226 //
227 // good photon cut will be set here
228 //
229 iGam.push_back((*itTrk)->trackId());
230 }
231
232 //
233 // Finish Good Photon Selection
234 //
235 int nGam = iGam.size();
236
237 log << MSG::DEBUG << "num Good Photon " << nGam << " , " <<evtRecEvent->totalNeutral()<<endreq;
238 if(nGam<2){
239 return StatusCode::SUCCESS;
240 }
241
242 // Vertex Fit
243
244 // Kinamatic Fit
245
246 // finale selection
247
248 m_tuple->write();
249
250 ////////////////////////////////////////////////////////////
251 // DQA
252 // set tag and quality
253
254 // Pid: 1 - electron, 2 - muon, 3 - pion, 4 - kaon, 5 - proton
255
256 (*(evtRecTrkCol->begin()+ipip[0]))->setPartId(2);
257 (*(evtRecTrkCol->begin()+ipim[0]))->setPartId(2);
258 // Quality: defined by whether dE/dx or TOF is used to identify particle
259 // 0 - no dE/dx, no TOF (can be used for dE/dx and TOF calibration)
260 // 1 - only dE/dx (can be used for TOF calibration)
261 // 2 - only TOF (can be used for dE/dx calibration)
262 // 3 - Both dE/dx and TOF
263 (*(evtRecTrkCol->begin()+ipip[0]))->setQuality(0);
264 (*(evtRecTrkCol->begin()+ipim[0]))->setQuality(0);
265
266 // DQA
267 // Add the line below at the end of execute(), (before return)
268 //
269 setFilterPassed(true);
270 ////////////////////////////////////////////////////////////
271
272 return StatusCode::SUCCESS;
273
274}
275
276// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
278
279 MsgStream log(msgSvc(), name());
280 log << MSG::INFO << "in finalize()" << endmsg;
281 return StatusCode::SUCCESS;
282}
283
284
HepGeom::Point3D< double > HepPoint3D
std::vector< HepLorentzVector > Vp4
const double xmass[5]
const double velc
const double mk
const double mpi
std::vector< int > Vint
std::vector< HepLorentzVector > Vp4
Definition: Gam4pikp.cxx:53
std::vector< int > Vint
Definition: Gam4pikp.cxx:52
double sin(const BesAngle a)
double cos(const BesAngle a)
const HepVector helix() const
......
StatusCode initialize()
StatusCode finalize()
StatusCode execute()
EvtSelExample(const std::string &name, ISvcLocator *pSvcLocator)
virtual bool isVertexValid()=0
virtual double * SigmaPrimaryVertex()=0
virtual double * PrimaryVertex()=0