2#include "GaudiKernel/MsgStream.h"
3#include "GaudiKernel/AlgFactory.h"
4#include "GaudiKernel/ISvcLocator.h"
5#include "GaudiKernel/SmartDataPtr.h"
6#include "GaudiKernel/IDataProviderSvc.h"
7#include "GaudiKernel/PropertyMgr.h"
8#include "EventModel/EventModel.h"
9#include "EventModel/Event.h"
10#include "EventModel/EventHeader.h"
11#include "EvtRecEvent/EvtRecEvent.h"
12#include "EvtRecEvent/EvtRecTrack.h"
14#include "MdcRecEvent/RecMdcTrack.h"
15#include "EmcRecEventModel/RecEmcEventModel.h"
16#include "TofRecEvent/RecTofTrack.h"
17#include "DstEvent/TofHitStatus.h"
18#include "MucRawEvent/MucDigi.h"
19#include "MucRecEvent/RecMucTrack.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"
27using CLHEP::Hep3Vector;
28#include "CLHEP/Vector/LorentzVector.h"
29using CLHEP::HepLorentzVector;
30#include "CLHEP/Vector/TwoVector.h"
31using CLHEP::Hep2Vector;
32#include "CLHEP/Geometry/Point3D.h"
33#ifndef ENABLE_BACKWARDS_COMPATIBILITY
36#include "VertexFit/KinematicFit.h"
37#include "VertexFit/VertexFit.h"
38#include "VertexFit/SecondVertexFit.h"
39#include "DimuPreSelect/DimuPreSelect.h"
41typedef std::vector<int>
Vint;
42typedef std::vector<HepLorentzVector>
Vp4;
44const double VELC = 299.792458;
45const double PI = 3.14159265;
46const double XMASS[5] = { 0.000511, 0.105658, 0.139570, 0.493677, 0.938272 };
50 Algorithm(name, pSvcLocator)
52 declareProperty(
"CmsEnergy", m_ecms = 3.686);
53 declareProperty(
"Vr0Cut", m_vr0cut = 1.0);
54 declareProperty(
"Vz0Cut", m_vz0cut = 5.0);
55 declareProperty(
"PUpCut", m_pcut_up = 2.0);
56 declareProperty(
"PDownCut", m_pcut_down = 0.5);
57 declareProperty(
"PSymCut", m_psymcut = 0.5);
58 declareProperty(
"TCut", m_tcut = 4);
59 declareProperty(
"EUpCut", m_ecut_up = 1.0);
60 declareProperty(
"EDownCut", m_ecut_down = 0.1);
61 declareProperty(
"DThetaCut", m_dthetacut = 0.05);
62 declareProperty(
"DPhiCut", m_dphicut = 0.4);
63 declareProperty(
"PartSelect", m_partselect= 0);
64 declareProperty(
"MuDigiCut", m_mudigicut = 6);
65 declareProperty(
"MuTrkCut", m_mutrkcut = 1);
66 declareProperty(
"UseMDC", m_useFlag[0]= 1);
67 declareProperty(
"UseTOF", m_useFlag[1]= 1);
68 declareProperty(
"UseEMC", m_useFlag[2]= 1);
69 declareProperty(
"UseMUC", m_useFlag[3]= 1);
70 declareProperty (
"Output", m_output =
false);
72 declareProperty (
"SelectDimu",m_selectFlag=
true);
79 MsgStream log(
msgSvc(), name());
80 log << MSG::INFO <<
"in initialize()" << endmsg;
82 m_totevent = m_currun = m_curevent = 0;
83 for(
int i = 0; i < 20; i++) m_cutpass[i] = 0;
84 m_subpass[0] = m_subpass[1] = m_subpass[2] = m_subpass[3] = 0;
91 if ( nt ) m_passtuple = nt;
93 m_passtuple =
ntupleSvc()->book (
"FILE1/dimu", CLID_ColumnWiseTuple,
"DimuPreSelect N-Tuple example");
96 status =m_passtuple->addItem (
"run", m_run);
97 status =m_passtuple->addItem (
"event", m_event);
98 status =m_passtuple->addItem (
"part", m_part);
99 status =m_passtuple->addItem (
"c1", m_c1);
100 status =m_passtuple->addItem (
"c2", m_c2);
101 status =m_passtuple->addItem (
"r1", m_r1);
102 status =m_passtuple->addItem (
"r2", m_r2);
103 status =m_passtuple->addItem (
"z1", m_z1);
104 status =m_passtuple->addItem (
"z2", m_z2);
105 status =m_passtuple->addItem (
"p1", m_p1);
106 status =m_passtuple->addItem (
"p2", m_p2);
107 status =m_passtuple->addItem (
"t1", m_t1);
108 status =m_passtuple->addItem (
"t2", m_t2);
109 status =m_passtuple->addItem (
"e1", m_e1);
110 status =m_passtuple->addItem (
"e2", m_e2);
111 status =m_passtuple->addItem (
"theta1",m_theta1);
112 status =m_passtuple->addItem (
"theta2",m_theta2);
113 status =m_passtuple->addItem (
"phi1", m_phi1);
114 status =m_passtuple->addItem (
"phi2", m_phi2);
115 status =m_passtuple->addItem (
"mudigi",m_mudigi);
116 status =m_passtuple->addItem (
"mutrk", m_mutrk);
118 status =m_passtuple->addItem (
"zeroC", m_zeroCFlag);
119 status =m_passtuple->addItem (
"vtRZ", m_vtRZFlag);
120 status =m_passtuple->addItem (
"pLim", m_pLimFlag);
121 status =m_passtuple->addItem (
"pSym", m_pSymFlag);
122 status =m_passtuple->addItem (
"tLim", m_tLimFlag);
123 status =m_passtuple->addItem (
"eLim", m_eLimFlag);
124 status =m_passtuple->addItem (
"eBB", m_eBBFlag);
125 status =m_passtuple->addItem (
"partSlt",m_partFlag);
126 status =m_passtuple->addItem (
"muDigiN",m_mudigiFlag);
127 status =m_passtuple->addItem (
"muTrkN", m_mutrkFlag);
129 status =m_passtuple->addItem (
"mdc", m_mdcFlag);
130 status =m_passtuple->addItem (
"tof", m_tofFlag);
131 status =m_passtuple->addItem (
"emc", m_emcFlag);
132 status =m_passtuple->addItem (
"muc", m_mucFlag);
137 log << MSG::ERROR <<
"Cannot book N-tuple:"<<long(m_passtuple)<<endmsg;
138 return StatusCode::FAILURE;
143 log << MSG::INFO <<
"Initialize done!" << endmsg;
145 return StatusCode::SUCCESS;
151 if(m_selectFlag==
false)
return( StatusCode::SUCCESS );
153 MsgStream log(
msgSvc(),name());
154 log<<MSG::INFO<<
"in execute()"<<endreq;
157 if(m_totevent%1000==0) std::cout << m_totevent <<
"\tdone!" <<std::endl;
159 setFilterPassed(
false);
160 m_mdcPass = m_tofPass = m_emcPass = m_mucPass =
false;
161 for(
int i=0; i<4; i++) m_passFlag[i] =
false;
163 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),
"/Event/EventHeader");
164 m_currun = eventHeader->runNumber();
165 m_curevent = eventHeader->eventNumber();
166 if( m_output ) { m_run = m_currun; m_event = m_curevent; }
169 SmartDataPtr<RecMdcTrackCol> mdcTrackCol(eventSvc(),
"/Event/Recon/RecMdcTrackCol");
171 log << MSG::FATAL <<
"Could not find RecMdcTrackCol!" << endreq;
172 return( StatusCode::FAILURE);
174 log << MSG::INFO <<
"MDC tracks:\t" << mdcTrackCol->size() << endreq;
176 if( mdcTrackCol->size() != 2 )
return ( StatusCode::SUCCESS );
180 double c1, c2, r1, r2, z1, z2, p1, p2;
181 c1 = c2 = r1 = r2 = z1 = z2 = p1 = p2 = 0.;
183 c1 = (*mdcTrackCol)[0]->charge(); c2 = (*mdcTrackCol)[1]->charge();
184 r1 = (*mdcTrackCol)[0]->r(); r2 = (*mdcTrackCol)[1]->r();
185 z1 = (*mdcTrackCol)[0]->z(); z2 = (*mdcTrackCol)[1]->z();
186 p1 = (*mdcTrackCol)[0]->p(); p2 = (*mdcTrackCol)[1]->p();
188 if( m_output ) { m_c1 =
c1; m_c2 = c2; m_r1 = r1; m_r2 = r2; m_z1 = z1; m_z2 = z2; m_p1 = p1; m_p2 = p2; }
190 bool mdcflag1 =
c1 + c2 == 0;
191 bool mdcflag2 = fabs(r1)<=m_vr0cut && fabs(z1)<m_vz0cut;
192 bool mdcflag3 = fabs(r2)<=m_vr0cut && fabs(z2)<m_vz0cut;
193 bool mdcflag4 = p1<m_pcut_up && p2<m_pcut_up;
196 bool mdcflag5 = fabs( p1-p2 )/( p1+p2 ) < m_psymcut;
198 log << MSG::INFO <<
"r1:\t" << r1 <<
"\tz1:" << z1 << endreq;
199 log << MSG::INFO <<
"r2:\t" << r2 <<
"\tz2:" << z2 << endreq;
200 log << MSG::INFO <<
"p1:\t" << p1 <<
"\tp2:" << p2 << endreq;
202 if( mdcflag1 ) { m_cutpass[1] += 1;
if(m_output) m_zeroCFlag = 1; }
203 if( mdcflag2 && mdcflag3 ) { m_cutpass[2] += 1;
if(m_output) m_vtRZFlag = 1; }
204 if( mdcflag4 ) { m_cutpass[3] += 1;
if(m_output) m_pLimFlag = 1; }
205 if( mdcflag5 ) { m_cutpass[4] += 1;
if(m_output) m_pSymFlag = 1; }
206 if( mdcflag1 && mdcflag2 && mdcflag3 && mdcflag4 && mdcflag5 ) { m_mdcPass =
true; m_subpass[0] += 1; }
207 if( !m_useFlag[0] ) m_passFlag[0] =
true;
208 else m_passFlag[0] = m_mdcPass;
209 log << MSG::INFO <<
"MDC selection done!" << endreq;
212 SmartDataPtr<RecTofTrackCol> tofTrackCol(eventSvc(),
"/Event/Recon/RecTofTrackCol");
214 log << MSG::FATAL <<
"Could not find RecTofTrackCol!" << endreq;
215 return( StatusCode::FAILURE);
217 log << MSG::INFO <<
"TOF tracks:\t" << tofTrackCol->size() << endreq;
222 if(tofTrackCol->size() > 7 && tofTrackCol->size() < 21)
225 for(
int itof = 0; itof < tofTrackCol->size(); itof++)
228 status->
setStatus((*tofTrackCol)[itof]->status());
230 if( !(status->
is_cluster()) ) {
delete status;
continue; }
231 if(goodtof==0) t1 = (*tofTrackCol)[itof]->tof();
232 if(goodtof==1) t2 = (*tofTrackCol)[itof]->tof();
239 if( m_output ) { m_t1 = t1; m_t2 = t2; }
241 bool tofflag1 = fabs( t1-t2 ) < m_tcut;
242 log << MSG::INFO <<
"t1:\t" << t1 <<
"\tt2:" << t2 <<
"dt:\t" << fabs(t1-t2) << endreq;
243 if( tofflag1 ) { m_cutpass[5] += 1;
if(m_output) m_tLimFlag = 1; m_tofPass =
true; m_subpass[1] += 1; }
244 if( !m_useFlag[1] ) m_passFlag[1] =
true;
245 else m_passFlag[1] = m_tofPass;
246 log << MSG::INFO <<
"TOF selection done!" << endreq;
249 SmartDataPtr<RecEmcShowerCol> emcShowerCol(eventSvc(),
"/Event/Recon/RecEmcShowerCol");
251 log << MSG::FATAL <<
"Could not find RecEmcShowerCol!" << endreq;
252 return( StatusCode::FAILURE);
254 log << MSG::INFO <<
"EMC showers:\t" << emcShowerCol->size() << endreq;
256 if( emcShowerCol->size() < 2 )
return ( StatusCode::SUCCESS );
261 e1 = (*emcShowerCol)[0]->energy();
e2 = (*emcShowerCol)[1]->energy();
262 theta1 = (*emcShowerCol)[0]->theta();
theta2 = (*emcShowerCol)[1]->theta();
263 phi1 = (*emcShowerCol)[0]->phi();
phi2 = (*emcShowerCol)[1]->phi();
264 part = (*emcShowerCol)[0]->module();
270 bool emcFlag1 = e1 < m_ecut_up && e1 > m_ecut_down;
271 bool emcFlag2 = e2 < m_ecut_up && e2 > m_ecut_down;
273 bool emcFlag4 = fabs(
phi1 -
phi2) -
PI < m_dphicut;
274 bool emcFlag5 = !m_partselect || (m_partselect==1&&part==1) || (m_partselect==2&&part!=1);
276 log << MSG::INFO <<
"e1:\t" <<
e1 <<
"\te2:\t" <<
e2 << endreq;
277 log << MSG::INFO <<
"theta1:\t" <<
theta1 <<
"\ttheta2:\t" <<
theta2 << endreq;
278 log << MSG::INFO <<
"phi1:\t" <<
phi1 <<
"\tphi2:\t" <<
phi2 << endreq;
279 log << MSG::INFO <<
"part:\t" << part <<
"\tpartFlag:\t" << emcFlag5 << endreq;
281 if( emcFlag1 && emcFlag2 ) { m_cutpass[6] += 1;
if(m_output) m_eLimFlag = 1; }
282 if( emcFlag3 && emcFlag4 ) { m_cutpass[7] += 1;
if(m_output) m_eBBFlag = 1; }
283 if( emcFlag5 ) { m_cutpass[8] += 1;
if(m_output) m_partFlag = 1; }
284 if( emcFlag1 && emcFlag2 && emcFlag3 && emcFlag4 && emcFlag5 ) { m_emcPass =
true; m_subpass[2] += 1; }
285 if( !m_useFlag[2] ) m_passFlag[2] =
true;
286 else m_passFlag[2] = m_emcPass;
287 log << MSG::INFO <<
"EMC selection done!" << endreq;
290 SmartDataPtr<MucDigiCol> mucDigiCol(eventSvc(),
"/Event/Digi/MucDigiCol");
292 log << MSG::FATAL <<
"Could not find MucDigiCol!" << endreq;
293 return( StatusCode::FAILURE);
295 SmartDataPtr<RecMucTrackCol> mucTrackCol(eventSvc(),
"/Event/Recon/RecMucTrackCol");
297 log << MSG::FATAL <<
"Could not find RecMucTrackCol" << endreq;
298 return( StatusCode::FAILURE);
301 int mudigiNum, mutrkNum;
302 mudigiNum = mutrkNum = 0;
303 mudigiNum = mucDigiCol->size(); mutrkNum = mucTrackCol->size();
304 if(m_output) { m_mudigi = mudigiNum; m_mutrk = mutrkNum; }
306 bool mucflag1 = mudigiNum >= m_mudigicut;
307 bool mucflag2 = mutrkNum >= m_mutrkcut;
309 log << MSG::INFO <<
"MUC digi:\t" << mudigiNum <<
"\tMUC track:\t" << mutrkNum << endreq;
311 if( mucflag1 ) { m_cutpass[9] += 1;
if(m_output) m_mudigiFlag = 1; }
312 if( mucflag2 ) { m_cutpass[10] += 1;
if(m_output) m_mutrkFlag = 1; }
313 if( mucflag1 && mucflag2 ) { m_mucPass =
true; m_subpass[3] += 1; }
314 if( !m_useFlag[3] ) m_passFlag[3] =
true;
315 else m_passFlag[3] = m_mucPass;
316 log << MSG::INFO <<
"MUC selection done!" << endreq;
320 if( m_passFlag[0] && m_passFlag[1] && m_passFlag[2] && m_passFlag[3] )
323 setFilterPassed(
true);
325 log << MSG::INFO <<
"Set filter passed!" << endreq;
327 if(m_output) { m_mdcFlag = m_mdcPass; m_tofFlag = m_tofPass; m_emcFlag = m_emcPass; m_mucFlag = m_mucPass; }
329 if( m_output ) m_passtuple->write();
331 return StatusCode::SUCCESS;
336 if(m_selectFlag==
false)
return StatusCode::SUCCESS;
338 MsgStream log(
msgSvc(), name());
339 log << MSG::INFO <<
"in finalize()" << endmsg;
340 const string str[3] = {
"all",
"barrel",
"endcap"};
342 cout <<
"pass 0 - 2 MDC tracks : " << m_cutpass[0] << endl;
343 cout <<
"pass 1 - 0 charge : " << m_cutpass[1] << endl;
344 cout <<
"pass 2 - |r|<"<<m_vr0cut<<
" && |z|<"<<m_vz0cut<<
" : " << m_cutpass[2] << endl;
345 cout <<
"pass 3 - p < "<<m_pcut_up<<
" GeV/c : " << m_cutpass[3] << endl;
346 cout <<
"pass 4 - p_sym < "<<m_psymcut<<
" : " << m_cutpass[4] << endl;
347 cout <<
"pass 5 - |t1-t1| < "<<m_tcut<<
" ns : " << m_cutpass[5] << endl;
348 cout <<
"pass 6 - "<<m_ecut_down<<
" < e < "<<m_ecut_up<<
" : " << m_cutpass[6] << endl;
349 cout <<
"pass 7 - |dth|<"<<m_dthetacut<<
" && |dphi|<"<<m_dphicut<<
": " << m_cutpass[7] << endl;
350 cout <<
"pass 8 - "<< str[(int)m_partselect] <<
" part is selected : " << m_cutpass[8] << endl;
351 cout <<
"pass 9 - mudigi >= "<<m_mudigicut<<
" : " << m_cutpass[9] << endl;
352 cout <<
"pass 10- mutrk >= "<<m_mutrkcut<<
" : " << m_cutpass[10]<< endl;
354 cout <<
"pass MDC : " << m_subpass[0] <<
"\tUsed: " << (m_useFlag[0]?
"Yes":
"No") << endl;
355 cout <<
"pass TOF : " << m_subpass[1] <<
"\tUsed: " << (m_useFlag[1]?
"Yes":
"No") << endl;
356 cout <<
"pass EMC : " << m_subpass[2] <<
"\tUsed: " << (m_useFlag[2]?
"Yes":
"No") << endl;
357 cout <<
"pass MUC : " << m_subpass[3] <<
"\tUsed: " << (m_useFlag[3]?
"Yes":
"No") << endl;
360 cout<<
"Total event: " << m_totevent <<endl;
361 cout<<
"Dimu event: " << m_totalpass <<endl;
363 return StatusCode::SUCCESS;
HepGeom::Point3D< double > HepPoint3D
std::vector< HepLorentzVector > Vp4
void setStatus(unsigned int status)