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