2#include "GaudiKernel/MsgStream.h"
3#include "GaudiKernel/SmartDataPtr.h"
11#include "CLHEP/Units/PhysicalConstants.h"
14#ifndef ENABLE_BACKWARDS_COMPATIBILITY
24#include "GaudiKernel/INTupleSvc.h"
25#include "GaudiKernel/NTuple.h"
27typedef std::vector<HepLorentzVector>
Vp4;
32 Algorithm(name, pSvcLocator) {
33 declareProperty(
"hist", m_hist =
false);
34 declareProperty(
"debug", m_debug= 0);
36 declareProperty(
"emcEneCutLow", m_emcEneCutLow=1.44);
37 declareProperty(
"emcEneCutHigh", m_emcEneCutHigh=1.88);
38 declareProperty(
"emcEneCutTot", m_emcEneCutTot=3.16);
39 declareProperty(
"emcDangCutLow", m_emcDangCutLow=2.94);
40 declareProperty(
"emcDangCutHigh",m_emcDangCutHigh=3.08);
42 declareProperty(
"dPhi", m_dPhiCut= 0.2);
43 declareProperty(
"dCosTheta", m_dCosThetaCut= 0.2);
44 declareProperty(
"d0", m_d0Cut= 1.);
45 declareProperty(
"z0", m_z0Cut= 5.);
47 declareProperty(
"barrelCut", m_barrelCut = 0.8);
48 declareProperty(
"endcapCut", m_endcapCutLow = 0.83);
49 declareProperty(
"endcapCutHigh", m_endcapCutHigh = 0.93);
55 MsgStream log(
msgSvc(), name());
62 for (
int i=0;i<3;i++){
68 if(bookNTuple()<0) sc = StatusCode::FAILURE;
71 return StatusCode::SUCCESS;
76 MsgStream log(
msgSvc(), name());
77 StatusCode sc = StatusCode::SUCCESS;
79 setFilterPassed(
false);
82 if(getEventInfo()<0)
return StatusCode::FAILURE;
85 if(selectBbByEmcShower()<0)
return StatusCode::SUCCESS;
88 if(bbEmcMdcTrackingEff()<0)
return StatusCode::SUCCESS;
90 return StatusCode::SUCCESS;
95 MsgStream log(
msgSvc(), name());
96 log << MSG::INFO <<
"in finalize()" << endreq;
97 if((m_effAllN1+m_effAllN2)>0)std::cout<<
" MdcBbEmcEff efficiency = N2/(N1+N2) = "
98 << m_effAllN2<<
"/("<<m_effAllN1<<
"+"<<m_effAllN2<<
") = "
99 << (m_effAllN2)/((
float)(m_effAllN1+m_effAllN2))<<std::endl;
100 for(
int i=0;i<3;i++){
102 if (0==i) pos=
"barrel";
104 if (2==i) pos=
"endcap";
105 if((m_effN1[i]+m_effN2[i])>0){
106 std::cout<<
" MdcBbEmcEff of "<<pos <<
" N2/(N1+N2) = "
107 << m_effN2[i]<<
"/("<<m_effN1[i]<<
"+"<<m_effN2[i]<<
") = "
108 << (m_effN2[i])/((
float)(m_effN1[i]+m_effN2[i]))<<std::endl;
111 return StatusCode::SUCCESS;
115int MdcBbEmcEff::bookNTuple(){
116 MsgStream log(
msgSvc(), name());
118 NTuplePtr nt1(
ntupleSvc(),
"MdcBbEmcEff/evt");
119 if ( nt1 ) { m_tuple1 = nt1;}
121 m_tuple1 =
ntupleSvc()->book (
"MdcBbEmcEff/evt", CLID_ColumnWiseTuple,
"event");
124 sc = m_tuple1->addItem (
"runNo", m_runNo);
125 sc = m_tuple1->addItem (
"evtNo", m_evtNo);
126 sc = m_tuple1->addItem (
"t0", m_t0);
127 sc = m_tuple1->addItem (
"t0Stat", m_t0Stat);
130 sc = m_tuple1->addItem (
"index", m_index,0,2);
131 sc = m_tuple1->addIndexedItem (
"emcTheta",m_index, m_emcTheta);
132 sc = m_tuple1->addIndexedItem (
"emcPhi", m_index, m_emcPhi);
133 sc = m_tuple1->addIndexedItem (
"emcEne", m_index, m_emcEne);
134 sc = m_tuple1->addItem (
"emcDang", m_emcDang);
137 sc = m_tuple1->addItem (
"dCosTheta", m_dCosTheta);
138 sc = m_tuple1->addItem (
"dPhi", m_dPhi);
139 sc = m_tuple1->addItem (
"nTk", m_nTk,0,2);
140 sc = m_tuple1->addIndexedItem (
"phi", m_nTk,m_phi);
141 sc = m_tuple1->addIndexedItem (
"cosTheta",m_nTk,m_cosTheta);
142 sc = m_tuple1->addIndexedItem (
"d0", m_nTk,m_d0);
143 sc = m_tuple1->addIndexedItem (
"z0", m_nTk,m_z0);
144 sc = m_tuple1->addIndexedItem (
"p", m_nTk,m_p);
145 sc = m_tuple1->addIndexedItem (
"pt", m_nTk,m_pt);
147 log << MSG::ERROR <<
"Cannot book tuple MdcBbEmcEff/evt" << endmsg;
154int MdcBbEmcEff::getEventInfo(){
155 MsgStream log(
msgSvc(), name());
158 SmartDataPtr<Event::EventHeader> evtHead(eventSvc(),
"/Event/EventHeader");
160 t_runNo = evtHead->runNumber();
161 t_evtNo = evtHead->eventNumber();
163 log << MSG::WARNING<<
"Could not retreve event header" << endreq;
166 std::cout<<m_evtIndex <<
"------------evtNo:"<<t_evtNo << std::endl;
172 SmartDataPtr<RecEsTimeCol> aevtmeCol(eventSvc(),
"/Event/Recon/RecEsTimeCol");
173 if ((!aevtmeCol)||(aevtmeCol->size()==0)) {
174 log << MSG::WARNING <<
"Could not fnd RecEsTimeCol" << endreq;
176 RecEsTimeCol::iterator iter_evt = aevtmeCol->begin();
177 t_t0 = (*iter_evt)->getTest();
178 t_t0Stat = (*iter_evt)->getStat();
183int MdcBbEmcEff::selectBbByEmcShower(){
184 MsgStream log(
msgSvc(), name());
186 SmartDataPtr<EvtRecEvent> evtRecEvent(eventSvc(),
"/Event/EvtRec/EvtRecEvent");
187 log << MSG::DEBUG <<
"ncharg, nneu, tottks = "
188 << evtRecEvent->totalCharged() <<
" , "
189 << evtRecEvent->totalNeutral() <<
" , "
190 << evtRecEvent->totalTracks() <<endreq;
191 SmartDataPtr<EvtRecTrackCol> evtRecTrkCol(eventSvc(),
"/Event/EvtRec/EvtRecTrackCol");
194 HepLorentzVector m_lv_ele;
195 for(
int i=0; i<evtRecEvent->totalTracks(); i++){
196 if(i>=evtRecTrkCol->size())
return -1;
199 if(!(*itTrk)->isEmcShowerValid()) {
200 if(m_debug>1)std::cout<<
"EmcShower NOT Valid "<<std::endl;
204 if((emcTrk->
energy()>m_emcEneCutHigh)||(emcTrk->
energy()<m_emcEneCutLow)){
205 if(m_debug>1)std::cout<<
"Cut by EmcEnergy: "<<emcTrk->
energy()<<std::endl;
208 Hep3Vector emcpos(emcTrk->
x(), emcTrk->
y(), emcTrk->
z());
209 m_lv_ele.setVect(emcpos);
210 m_lv_ele.setE(emcTrk->
energy());
212 vGood.push_back(m_lv_ele);
215 if(m_debug>1)std::cout<<
"vGood.size = "<<vGood.size()<<std::endl;
217 if (m_debug>0) std::cout<<
"Cut by vGood.size: "<<vGood.size()<<std::endl;
224 for(
int i=0; i<2; i++){
225 double cosEmcTheta =
cos(vGood[i].vect().theta());
226 if( fabs(cosEmcTheta) <= m_barrelCut ){
228 }
else if((cosEmcTheta>=m_endcapCutLow)&&(cosEmcTheta<=m_endcapCutHigh)){
231 }
else if((cosEmcTheta>m_barrelCut)&&(cosEmcTheta<m_endcapCutLow)){
236 if(m_debug>1) std::cout<<
"Emc cos(theta)="<<cosEmcTheta
237 <<
"Track in "<<m_posFlag<<std::endl;
239 if(m_posFlag == OUT)
return -5;
241 double dang = vGood[0].vect().angle(vGood[1].vect());
242 if(vGood[0].e() > vGood[1].e()) swap(vGood[0],vGood[1]);
243 double emcTheta[2],emcEne[2];
244 for(
int index=0; index<2; index++){
245 emcTheta[index] = vGood[index].vect().theta();
246 t_emcPhi[index] = vGood[index].vect().phi();
247 emcEne[index] = vGood[index].e();
252 for (
int index=0;index<2;index++){
253 m_emcTheta[index] = emcTheta[index];
254 m_emcPhi[index] = t_emcPhi[index];
255 m_emcEne[index] = emcEne[index];
259 if(m_debug>1) std::cout<<
" dang "<<dang<<std::endl;
260 if(m_debug>1) std::cout<<
" energy "<<emcEne[0]<<
" "<<emcEne[1]<<std::endl;
262 if(dang<=m_emcDangCutLow || dang>=m_emcDangCutHigh ) {
263 if(m_debug>0) std::cout<<
"Cut by emcDang "<<dang<<std::endl;
267 if(emcEne[0]<=m_emcEneCutLow || emcEne[1]>=m_emcEneCutHigh){
268 if(m_debug>0) std::cout<<
"Cut by emc energy low or high "
269 <<emcEne[0]<<
" "<<emcEne[1]<<std::endl;
272 if( (emcEne[0] + emcEne[1])<=m_emcEneCutTot){
273 if(m_debug>0) std::cout<<
"Cut by emc total energy:"
274 <<emcEne[0]<<
" "<<emcEne[1]<<
" tot:"<<emcEne[0]+emcEne[1]<<std::endl;
275 return StatusCode::FAILURE;
281int MdcBbEmcEff::bbEmcMdcTrackingEff(){
282 MsgStream log(
msgSvc(), name());
285 SmartDataPtr<RecMdcTrackCol> recMdcTrackCol(eventSvc(),
"/Event/Recon/RecMdcTrackCol");
286 if (!recMdcTrackCol){
287 log << MSG::WARNING<<
" Unable to retrieve recMdcTrackCol" << endreq;
292 t_nTk = recMdcTrackCol->size();
293 if((t_nTk>2) || (0==t_nTk)) {
294 if(m_debug>1)std::cout<<name()<<
"Cut by nTk "<<t_nTk<<std::endl;
299 double d0[2],z0[2],cosTheta[2],phi[2],p[2],pt[2];
300 RecMdcTrackCol::iterator it = recMdcTrackCol->begin();
301 for(
int iTk=0 ; it != recMdcTrackCol->end(); it++,iTk++ ) {
303 d0[iTk] = tk->
helix(0);
304 z0[iTk] = tk->
helix(3);
305 if ((fabs(d0[iTk])>m_d0Cut) || (fabs(z0[iTk])>m_z0Cut)){
306 if(m_debug>0) std::cout<<
"Cut by d0 "
307 <<d0[iTk]<<
" z0 "<<z0[iTk]<<std::endl;
311 phi[iTk] = tk->
phi();
316 double dCosTheta = cosTheta[0]+cosTheta[1];
317 double dPhi = phi[0] - phi[1] + CLHEP::pi;
318 if(dPhi > CLHEP::pi) dPhi-=CLHEP::twopi;
327 for(
int i=0;i<2;i++){
328 m_cosTheta[i]=cosTheta[i];
336 m_dCosTheta= dCosTheta;
345 if((fabs(dCosTheta)>m_dCosThetaCut) || (fabs(dPhi)>m_dPhiCut)){
347 if (fabs(dCosTheta)>m_dCosThetaCut){
348 std::cout<<
"Cut by dCosTheta "<<dCosTheta<<std::endl;
350 std::cout<<
"Cut by dPhi "<<dPhi<<std::endl;
356 m_effN2[m_posFlag]++;
359 m_effN1[m_posFlag]++;
363 if ((1==t_nTk)&&(m_posFlag==BARREL)) setFilterPassed(
true);
double cos(const BesAngle a)
EvtRecTrackCol::iterator EvtRecTrackIterator
std::vector< HepLorentzVector > Vp4
HepGeom::Point3D< double > HepPoint3D
std::vector< HepLorentzVector > Vp4
const double theta() const
const HepVector helix() const
......
MdcBbEmcEff(const std::string &name, ISvcLocator *pSvcLocator)