BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
SD0Tag.cxx
Go to the documentation of this file.
1//
2// SD0Tag.cxx is the Single D0 tag code transfered from the Fortran routine "SD0Tag.f"
3// which was used for study of the D0D0-bar production and D0 decays at the BES-II experiment.
4// The orignal routine "SD0Tag.f" used at the BES-II experiment was coded by G. Rong in 2001.
5//
6// SD0Tag.cxx was transfered by G. Rong and J. Liu in December, 2005.
7// Since 2008, G. Rong and L.L. Jiang have been working on developing this
8// code to analyze of the data taken at 3.773 GeV with the BES-III detector
9// at the BEPC-II collider.
10//
11// During developing this code, many People made significant contributions to this code. These
12// are
13// G. Rong, L.L. Jiang, J. Liu, H.L. Ma, J.C. Chen, D.H. Zhang,
14// M.G. Zhao, B. Zheng, L. Li, Y. Fang, Z.Y. Yi, H.H. Liu, Z.Q. Liu et al.
15//
16// By G. Rong and L.L. Jiang
17// March, 2009
18//
19//
20// We updated the Single D0 Tag Software Package for the BES-III collaborators use in their
21// studies of the D0 semileptonic decays as well as other decays. Acctually, the Referee
22// committee for reviewing these analysis of the D0-->K-e+v, pi-e+v decays and the BES-III
23// Physics Analysis Coordinators required the analysis authors for these decays to use the
24// common analysis cuts for selection of the events of anti-D0 tags VS the D0-->K-e+v, pi-e+v
25// for preparing the analysis MEMO and paper to be published. They also recommended the
26// analysis authors to use the IHEP SD0Tag Software to select the anti-D0 tags in their
27// analyses. To response the Analysis Committee Members and Physics Coordinator requirements
28// for these analyses, we updated the Single anti-D0 Tag Software Package SD0Tag
29// (D0TagAlg-00-00-02) with the common event selection cuts set by the Referee Committe and
30// the Physics Analysis Coordinators. The updated version of the SD0Tag is SD0TagAlg-00-00-03.
31// In this releasion of the software, we use this common event selection cuts. The details of
32// these common event selection cuts can be found on the webpage of
33//
34// http://hnbes3.ihep.ac.cn/HyperNews/get/paper71/75.html
35//
36// In an e-mail message from the Referee Committee and Physics Analysis Coordinators about
37// these analyses, the Referee Committee and Physics Analysis Coordinators like to recommend
38// for analysis authors to use the SDTS to do anti-D0 reconstruction. They also required the
39// IHEP authors to supply the run-dependent Ebeam that have been used in the original IHEP
40// analysis.
41//
42// In the updated releasion of SD0Tag (D0TagAlg-00-00-03), we supply all of these.
43//
44//
45// G. Rong, L.L. Jiang, Y. Fang and H.L. Ma
46// 1 Dec, 2013
47//
48// ==========================================================================================
49//
50#include "SD0TagAlg/SD0Tag.h"
51#include "DTagTool/DTagTool.h"
52#include "SD0TagAlg/Sing.h"
54// #include "Ecmset/Ecmset.h"
55#include <fstream>
56#include <iostream>
57int nD0 = 0;
58int n1 = 0;
59int n2 = 0;
60int ND0 = 0;
61int NDp = 0;
62//
63
64// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
65/////////////////////////////////////////////////////////////////////////////
67SD0Tag::SD0Tag( const std::string& name, ISvcLocator* pSvcLocator )
68 : Algorithm( name, pSvcLocator ) {
69 // Declare the properties
70 declareProperty( "PID_FLAG", PID_flag = 1 );
71 declareProperty( "MC_sample", m_MC_sample = 1 );
72
73 declareProperty( "m_Seperate_Charge", Seperate_Charge = 1 );
74 declareProperty( "m_Charge_default", Charge_default = 1 );
75}
76
77// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
78
79StatusCode SD0Tag::initialize() {
80
81 MsgStream log( msgSvc(), name() );
82
83 log << MSG::INFO << "in initialize()" << endmsg;
84
85 StatusCode status;
86
87 ifstream readrunEcm;
88 //
89 // Read in the energy calibration constant for run-by-run data
90 readrunEcm.open( "../share/psipp_ecms_calrunbyrun_runno_3648runs.dat" );
91 cout << "readrunEcm = " << readrunEcm.is_open() << endl;
92 for ( int i = 0; i < 3467; i++ )
93 {
94 readrunEcm >> p_run[i];
95 readrunEcm >> p_Ecm[i];
96 }
97
98 NTuplePtr nt1( ntupleSvc(), "FILE1/tag" );
99 if ( nt1 ) m_tuple1 = nt1;
100 else
101 {
102 m_tuple1 = ntupleSvc()->book( "FILE1/tag", CLID_ColumnWiseTuple, "tag N-Tuple example" );
103 if ( m_tuple1 )
104 {
105 status = m_tuple1->addItem( "tagmode", m_tagmode );
106 status = m_tuple1->addItem( "mass_bc", m_mass_bc );
107 status = m_tuple1->addItem( "delE_tag", m_delE_tag );
108
109 status = m_tuple1->addItem( "cosmic_ok", m_cosmic_ok );
110 status = m_tuple1->addItem( "EGam_max_0", m_EGam_max_0 );
111 status = m_tuple1->addItem( "nGood", m_nGood );
112 status = m_tuple1->addItem( "nGam", m_nGam );
113 status = m_tuple1->addItem( "runNo", m_runNo );
114 status = m_tuple1->addItem( "event", m_event );
115 }
116 else
117 {
118 log << MSG::ERROR << " Cannot book N-tuple:" << long( m_tuple1 ) << endmsg;
119 return StatusCode::FAILURE;
120 }
121 }
122
123 log << MSG::INFO << "successfully return from initialize()" << endmsg;
124 return StatusCode::SUCCESS;
125}
126
127//
128// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
129//
130
131StatusCode SD0Tag::execute() {
132
133 MsgStream log( msgSvc(), name() );
134
135 SmartDataPtr<Event::EventHeader> eventHeader( eventSvc(), "/Event/EventHeader" );
136 int runNo = eventHeader->runNumber();
137 int event = eventHeader->eventNumber();
138
139 SmartDataPtr<EvtRecEvent> evtRecEvent( eventSvc(), EventModel::EvtRec::EvtRecEvent );
140 SmartDataPtr<EvtRecTrackCol> evtRecTrkCol( eventSvc(), EventModel::EvtRec::EvtRecTrackCol );
141 // cout<<"//////////////////////////////////////"<<endl;
142 nD0++;
143
144 //
145 // The default energy is 3.773 GeV for psi(3770) data.
146 // Alayizer can add calibrated energy here.
147 double Ebeam = 3.773 / 2.0;
148
149 if ( runNo >= 11414 && runNo <= 23500 )
150 {
151 for ( int i = 0; i < 3467; i++ )
152 {
153 if ( runNo == p_run[i] ) { Ebeam = p_Ecm[i] / 2.0; }
154 }
155 }
156
157 if ( runNo < 0 )
158 {
159 int irun = abs( runNo );
160 // Ecmset* ECMSET = Ecmset::instance();
161 // ECMSET->EcmSet(irun);
162 // Ebeam = ECMSET->ECM()/2.0;
163 }
164
165 if ( nD0 % 1000 == 0 )
166 cout << "SD0TagAlg-13-11-15pp = " << nD0 << " " << runNo << " " << event << " "
167 << Ebeam * 2 << endl;
168
169 Hep3Vector xorigin( 0, 0, 0 );
170 IVertexDbSvc* vtxsvc;
171 Gaudi::svcLocator()->service( "VertexDbSvc", vtxsvc );
172 if ( vtxsvc->isVertexValid() )
173 {
174 double* dbv = vtxsvc->PrimaryVertex();
175 double* vv = vtxsvc->SigmaPrimaryVertex();
176 xorigin.setX( dbv[0] );
177 xorigin.setY( dbv[1] );
178 xorigin.setZ( dbv[2] );
179 }
180
181 /////////////////////////////////////
182 Vint iCharge_good;
183 iCharge_good.clear();
184 for ( int i = 0; i < evtRecEvent->totalCharged(); i++ )
185 {
186 EvtRecTrackIterator itTrk = evtRecTrkCol->begin() + i;
187 if ( !( *itTrk )->isMdcTrackValid() ) continue;
188 RecMdcTrack* mdcTrk = ( *itTrk )->mdcTrack();
189 //%%%%%%%%%%%%%%%%%%%%%%%%
190 HepVector a = mdcTrk->helix();
191 HepSymMatrix Ea = mdcTrk->err();
192 HepPoint3D point0( 0., 0., 0. ); // the initial point for MDC recosntruction
193 HepPoint3D IP( xorigin[0], xorigin[1], xorigin[2] );
194 VFHelix helixip( point0, a, Ea );
195 helixip.pivot( IP );
196 HepVector vecipa = helixip.a();
197 double Rvxy0 = fabs( vecipa[0] ); // the nearest distance to IP in xy plane
198 double Rvz0 = vecipa[3]; // the nearest distance to IP in z direction
199 double costheta = cos( mdcTrk->theta() );
200 //%%%%%%%%%%%%%%%%%%%%%%%%
201 if ( fabs( Rvxy0 ) >= 1.0 ) continue;
202 if ( fabs( Rvz0 ) >= 10.0 ) continue;
203 if ( fabs( costheta ) >= 0.930 ) continue;
204 iCharge_good.push_back( i );
205 }
206
207 ///////////////////////////////////////////////////////
208 Vint iGam;
209 iGam.clear();
210 for ( int i = evtRecEvent->totalCharged(); i < evtRecEvent->totalTracks(); i++ )
211 {
212 EvtRecTrackIterator itTrk = evtRecTrkCol->begin() + i;
213 if ( !( *itTrk )->isEmcShowerValid() ) continue;
214 RecEmcShower* emcTrk = ( *itTrk )->emcShower();
215 //
216 // We here remove the hot channels of EMC
217 //
218 if ( abs( runNo ) >= 11615 && abs( runNo ) <= 11617 && emcTrk->cellId() == 805438481 )
219 continue;
220 if ( abs( runNo ) >= 11615 && abs( runNo ) <= 11655 && emcTrk->cellId() == 805376008 )
221 continue;
222 if ( abs( runNo ) >= 13629 && abs( runNo ) <= 13669 && emcTrk->cellId() == 805374754 )
223 continue;
224 if ( abs( runNo ) >= 21190 && abs( runNo ) <= 21231 && emcTrk->cellId() == 805375262 )
225 continue;
226
227 int emctdc = emcTrk->time();
228 if ( emctdc > 14 || emctdc < 0 ) continue;
229
230 double eraw = emcTrk->energy();
231 double theta = emcTrk->theta();
232 int Module = 0;
233 if ( fabs( cos( theta ) ) < 0.80 && eraw > 0.025 ) { Module = 1; }
234 if ( fabs( cos( theta ) ) > 0.86 && fabs( cos( theta ) ) < 0.92 && eraw > 0.05 )
235 { Module = 2; }
236 if ( Module == 0 ) continue;
237 iGam.push_back( ( *itTrk )->trackId() );
238 }
239 /////////////////////////////////////////////////////////////////
240 DTagTool trk;
241 bool cosmic_ok = trk.cosmicandleptonVeto();
242 /////////////////////////////////////////////////////////////////
243
244 int ntk;
245 double tagmass, ebeam, tagmode, ksmass, dlte;
246
247 Vint tagtrk;
248 tagtrk.clear();
249 Vint tagGam;
250 tagGam.clear();
251
252 HepLorentzVector tagp;
253
254 double mass_bc_temp, mass_kf_temp, kf_chi2_temp, mks_temp, mpi0_temp, ptag_temp;
255 int Charge_candidate_D = 0;
256 double EGam_max_0 = 0;
257
258 for ( int i1 = 0; i1 < 2; i1++ )
259 {
260 if ( Seperate_Charge == 2 )
261 {
262 Charge_candidate_D = Charge_default;
263 i1 = 2;
264 }
265 if ( Seperate_Charge == 1 ) { Charge_candidate_D = pow( -1, i1 ); }
266 if ( Seperate_Charge == 0 )
267 {
268 Charge_candidate_D = 0;
269 i1 = 2;
270 }
271
272 for ( int i = 0; i < 15; i++ )
273 {
274 EGam_max_0 = 0;
275 int mdslct = pow( 2., i );
276 Sing sing;
277 sing.Mdset( event, evtRecTrkCol, iCharge_good, iGam, mdslct, Ebeam, PID_flag,
278 Charge_candidate_D );
279 bool oktag = sing.Getoktg();
280 if ( oktag )
281 {
282 //
283 // Here analysizer should pick up variables from anti-D0 tags
284 // to do physics analysis
285 //
286 tagtrk = sing.Gettagtrk1();
287 tagmode = sing.Gettagmd();
288 //==========================================================================
289 if ( ( abs( tagmode ) == 11 || abs( tagmode ) == 15 || abs( tagmode ) == 19 ) )
290 {
291 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
292 for ( int i = evtRecEvent->totalCharged(); i < evtRecEvent->totalTracks(); i++ )
293 {
294 EvtRecTrackIterator itTrk = evtRecTrkCol->begin() + i;
295 int itrk = ( *itTrk )->trackId();
296 if ( !( *itTrk )->isEmcShowerValid() ) continue;
297 RecEmcShower* emcTrk = ( *itTrk )->emcShower();
298
299 int emctdc = emcTrk->time();
300 if ( emctdc > 14 || emctdc < 0 ) continue;
301
302 Hep3Vector emcpos( emcTrk->x(), emcTrk->y(), emcTrk->z() );
303 double dang = 200.;
304 for ( int j = 0; j < tagtrk.size(); j++ )
305 {
306 EvtRecTrackIterator jtTrk = evtRecTrkCol->begin() + tagtrk[j];
307 if ( !( *jtTrk )->isExtTrackValid() ) continue;
308 RecExtTrack* extTrk = ( *jtTrk )->extTrack();
309 if ( extTrk->emcVolumeNumber() == -1 ) continue;
310 Hep3Vector extpos = extTrk->emcPosition();
311 double angd = extpos.angle( emcpos );
312 if ( angd < dang ) dang = angd;
313 }
314 dang = dang * 180 / ( CLHEP::pi );
315 if ( fabs( dang ) < 20. ) continue;
316
317 double eraw = emcTrk->energy();
318 if ( eraw > EGam_max_0 ) EGam_max_0 = eraw;
319 }
320 }
321 //==========================================================================
322 m_cosmic_ok = cosmic_ok;
323 m_EGam_max_0 = EGam_max_0;
324 m_nGood = iCharge_good.size();
325 m_nGam = iGam.size();
326 m_runNo = runNo;
327 m_event = event;
328
329 m_tagmode = sing.Gettagmd();
330 m_mass_bc = sing.Getmass_bc();
331 m_delE_tag = sing.GetdelE_tag();
332
333 m_tuple1->write();
334
335 // Here one can do double tag analysis based on the variables
336 // from single anti-D0 tag analysis.
337 // To do so, analyzer should make his/her codes
338 //
339 }
340 }
341 } // The end of loopping over mdslct
342
343 return StatusCode::SUCCESS;
344}
345
346//
347// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
348//
349
350StatusCode SD0Tag::finalize() {
351 MsgStream log( msgSvc(), name() );
352 cout << "nD0 = " << nD0 << endl;
353 cout << "n1 = " << n1 << endl;
354 cout << "n2 = " << n2 << endl;
355 cout << "ND0 ==== " << ND0 << endl;
356 cout << "NDp ==== " << NDp << endl;
357 log << MSG::INFO << "in finalize()" << endmsg;
358 return StatusCode::SUCCESS;
359}
DECLARE_COMPONENT(BesBdkRc)
int runNo
Definition DQA_TO_DB.cxx:13
EvtRecTrackCol::iterator EvtRecTrackIterator
double ebeam
int NDp
Definition SD0Tag.cxx:61
int ND0
Definition SD0Tag.cxx:60
int n2
Definition SD0Tag.cxx:59
int nD0
Definition SD0Tag.cxx:57
int n1
Definition SD0Tag.cxx:58
std::vector< int > Vint
Definition SD0Tag.h:11
INTupleSvc * ntupleSvc()
IMessageSvc * msgSvc()
bool cosmicandleptonVeto(bool emc=true)
const HepSymMatrix err() const
const HepVector helix() const
......
virtual bool isVertexValid()=0
virtual double * SigmaPrimaryVertex()=0
virtual double * PrimaryVertex()=0
StatusCode finalize()
Definition SD0Tag.cxx:350
SD0Tag(const std::string &name, ISvcLocator *pSvcLocator)
Definition SD0Tag.cxx:67
StatusCode execute()
Definition SD0Tag.cxx:131
StatusCode initialize()
Definition SD0Tag.cxx:79
Definition Sing.h:20
double Gettagmd()
Definition Sing.h:27
double GetdelE_tag()
Definition Sing.h:30
double Getmass_bc()
Definition Sing.h:28
void Mdset(double event, SmartDataPtr< EvtRecTrackCol > evtRecTrkCol, Vint iGood, Vint iGam, int mdset, double Ebeam, int PID_flag, int Charge_candidate_D)
Definition Sing.cxx:51
bool Getoktg()
Definition Sing.h:26
Vint Gettagtrk1()
Definition Sing.h:31
const HepPoint3D & pivot(void) const
returns pivot position.
const HepVector & a(void) const
returns helix parameters.