10#include "GaudiKernel/IDataProviderSvc.h"
11#include "GaudiKernel/ISvcLocator.h"
12#include "GaudiKernel/Bootstrap.h"
13#include "GaudiKernel/SmartDataPtr.h"
14#include "GaudiKernel/RegistryEntry.h"
15#include "GaudiKernel/MsgStream.h"
17#include "CLHEP/Vector/LorentzVector.h"
18#include "CLHEP/Geometry/Point3D.h"
44Algorithm(name, pSvcLocator)
46 declareProperty(
"ParticleRootFlag",m_particleRootFlag=
false);
47 declareProperty(
"MdcRootFlag",m_mdcRootFlag=
false);
48 declareProperty(
"TofRootFlag",m_tofRootFlag=
false);
53 MsgStream log(
msgSvc(), name());
54 log << MSG::INFO <<
" McTestAlg initialize()" << endreq;
56 if(m_particleRootFlag)
59 NTuplePtr ntp(
ntupleSvc(),
"FILE900/particle");
60 if(ntp) tupleParticle = ntp;
62 tupleParticle =
ntupleSvc()->book(
"FILE900/particle",CLID_ColumnWiseTuple,
"McTestAlg");
64 sc = tupleParticle->addItem(
"me",me);
72 if(nt1) tupleMdc1 = nt1;
74 tupleMdc1 =
ntupleSvc()->book(
"FILE901/n1",CLID_ColumnWiseTuple,
"McTestAlg");
77 sc = tupleMdc1->addItem(
"truthIndex",truthMdcIndex);
78 sc = tupleMdc1->addItem(
"truthLayer",truthMdcLayer);
79 sc = tupleMdc1->addItem(
"truthWire",truthMdcWire);
80 sc = tupleMdc1->addItem(
"truthEdep",truthMdcEdep);
81 sc = tupleMdc1->addItem(
"truthDriftD",truthMdcDriftD);
82 sc = tupleMdc1->addItem(
"truthX",truthMdcX);
83 sc = tupleMdc1->addItem(
"truthY",truthMdcY);
84 sc = tupleMdc1->addItem(
"truthZ",truthMdcZ);
85 sc = tupleMdc1->addItem(
"ntruth",ntruthMdc);
88 log << MSG::ERROR <<
"Cannot book MDC N-tuple:" << long(tupleMdc1) << endmsg;
89 return StatusCode::FAILURE;
94 if(nt2) tupleMdc2 = nt2;
96 tupleMdc2 =
ntupleSvc()->book(
"FILE901/n2",CLID_ColumnWiseTuple,
"McTestAlg");
99 sc = tupleMdc2->addItem(
"layer",m_layer);
100 sc = tupleMdc2->addItem(
"cell",m_cell);
101 sc = tupleMdc2->addItem(
"ADC",m_charge);
102 sc = tupleMdc2->addItem(
"TDC",m_time);
111 if(nt) tupleTof = nt;
113 tupleTof=
ntupleSvc()->book(
"FILE902/lr",CLID_ColumnWiseTuple,
"McTestAlg");
116 sc = tupleTof->addItem(
"truthIndex",truthIndex);
117 sc = tupleTof->addItem(
"truthPartId",truthPartId);
118 sc = tupleTof->addItem(
"truthLayer",truthLayer);
119 sc = tupleTof->addItem(
"truthScinNb",truthScinNb);
120 sc = tupleTof->addItem(
"truthX",truthX);
121 sc = tupleTof->addItem(
"truthY",truthY);
122 sc = tupleTof->addItem(
"truthZ",truthZ);
123 sc = tupleTof->addItem(
"ntruth",ntruth);
124 sc = tupleTof->addItem(
"tleft",tleft);
125 sc = tupleTof->addItem(
"tright",tright);
126 sc = tupleTof->addItem(
"qleft",qleft);
127 sc = tupleTof->addItem(
"qright",qright);
130 log << MSG::ERROR <<
"Cannot book N-tuple:" << long(tupleTof) << endmsg;
131 return StatusCode::FAILURE;
135 return StatusCode::SUCCESS;
140 MsgStream log(
msgSvc(), name());
141 log << MSG::INFO <<
"McTestAlg finalize()" << endreq;
143 return StatusCode::SUCCESS;
151 ISvcLocator* svcLocator = Gaudi::svcLocator();
152 StatusCode sc=svcLocator->service(
"EventDataSvc", m_evtSvc);
154 std::cout<<
"Could not accesss EventDataSvc!"<<std::endl;
156 SmartDataPtr<Event::EventHeader> eventHeader(m_evtSvc,
"/Event/EventHeader");
158 std::cout<<
"Could not retrieve EventHeader"<<std::endl;
160 int event=eventHeader->eventNumber();
161 std::cout<<
"event: "<<
event<<std::endl;
169 return StatusCode::SUCCESS;
175 SmartDataPtr<Event::McParticleCol> mcParticleCol(m_evtSvc,
"/Event/MC/McParticleCol");
177 std::cout<<
"Could not retrieve McParticelCol"<<std::endl;
181 double px,py,pz,E,
mass;
183 Event::McParticleCol::iterator iter_mc = mcParticleCol->begin();
184 for (;iter_mc != mcParticleCol->end(); iter_mc++)
187 pdgcode = (*iter_mc)->particleProperty();
188 if((*iter_mc)->trackIndex()<0)
189 std::cout<<
"ERROR! trackIndex<0"<<std::endl;
190 px=(*iter_mc)->initialFourMomentum().x();
191 py=(*iter_mc)->initialFourMomentum().y();
192 pz=(*iter_mc)->initialFourMomentum().z();
193 E=(*iter_mc)->initialFourMomentum().t();
194 if(E*E-px*px-py*py-pz*pz>=0)
195 mass=sqrt(E*E-px*px-py*py-pz*pz);
199 if(m_particleRootFlag)
203 tupleParticle->write();
205 if(
abs(pdgcode)==2212||
abs(pdgcode)==211)
209 std::cout<<
"nflag!=4"<<std::endl;
238 SmartDataPtr<Event::MdcMcHitCol> aMcHitCol(m_evtSvc,
"/Event/MC/MdcMcHitCol");
240 std::cout<<
"Could not retrieve MDC McTruth collection"<<std::endl;
243 Event::MdcMcHitCol::iterator iMcHitCol;
244 for(iMcHitCol=aMcHitCol->begin(); iMcHitCol!=aMcHitCol->end(); iMcHitCol++)
246 const Identifier ident = (*iMcHitCol)->identify();
259 truthMdcIndex = (*iMcHitCol)->getTrackIndex();
262 truthMdcEdep = (*iMcHitCol)->getDepositEnergy();
263 truthMdcDriftD = (*iMcHitCol)->getDriftDistance();
264 truthMdcX = (*iMcHitCol)->getPositionX();
265 truthMdcY = (*iMcHitCol)->getPositionY();
266 truthMdcZ = (*iMcHitCol)->getPositionZ();
275 SmartDataPtr<MdcDigiCol> aDigiCol(m_evtSvc,
"/Event/Digi/MdcDigiCol");
277 std::cout<<
"Could not retrieve MDC digi collection"<<std::endl;
281 MdcDigiCol::iterator iDigiCol;
282 for(iDigiCol=aDigiCol->begin(); iDigiCol!=aDigiCol->end(); iDigiCol++)
284 const Identifier ident = (*iDigiCol)->identify();
293 m_charge = (*iDigiCol)->getChargeChannel()/1.0e6;
294 m_time = (*iDigiCol)->getTimeChannel()/1.0e5;
321 int partId,layer,scinNb,end;
323 partId = layer = scinNb = end = -9;
329 SmartDataPtr<Event::TofMcHitCol> aMcHitCol(m_evtSvc,
"/Event/MC/TofMcHitCol");
331 std::cout<<
"Could not retrieve TOF McTruth collection"<<std::endl;
334 Event::TofMcHitCol::iterator iMcHitCol;
335 for(iMcHitCol=aMcHitCol->begin(); iMcHitCol!=aMcHitCol->end(); iMcHitCol++)
337 const Identifier ident = (*iMcHitCol)->identify();
353 truthIndex = (*iMcHitCol)->getTrackIndex();
357 truthX = (*iMcHitCol)->getPositionX();
358 truthY = (*iMcHitCol)->getPositionY();
359 truthZ = (*iMcHitCol)->getPositionZ();
366 SmartDataPtr<TofDigiCol> aDigiCol(m_evtSvc,
"/Event/Digi/TofDigiCol");
368 std::cout<<
"Could not retrieve TOF digi collection"<<std::endl;
371 TofDigiCol::iterator iDigiCol;
372 for(iDigiCol=aDigiCol->begin(); iDigiCol!=aDigiCol->end(); iDigiCol++)
374 const Identifier ident = (*iDigiCol)->identify();
388 charge = (*iDigiCol)->getChargeChannel()/1.0e6;
389 time = (*iDigiCol)->getTimeChannel()/1.0e6;
392 if(truthPartId==partId && truthLayer==layer && truthScinNb==scinNb)
399 std::cout<<
"digi doesn't match"<<std::endl;
404 if(tleft>0&&tright>0&&qleft>0&&qright>0)
407 std::cout<<
"no digi match MCtruth"<<std::endl;
417 SmartDataPtr<Event::EmcMcHitCol> aMcHitCol(m_evtSvc,
"/Event/MC/EmcMcHitCol");
419 std::cout<<
"Could not retrieve EMC McTruth collection"<<std::endl;
422 Event::EmcMcHitCol::iterator iMcHitCol;
423 for(iMcHitCol=aMcHitCol->begin(); iMcHitCol!=aMcHitCol->end(); iMcHitCol++)
425 const Identifier ident = (*iMcHitCol)->identify();
443 SmartDataPtr<EmcDigiCol> aDigiCol(m_evtSvc,
"/Event/Digi/EmcDigiCol");
445 std::cout<<
"Could not retrieve EMC digi collection"<<std::endl;
449 EmcDigiCol::iterator iDigiCol;
450 for(iDigiCol=aDigiCol->begin(); iDigiCol!=aDigiCol->end(); iDigiCol++)
452 const Identifier ident = (*iDigiCol)->identify();
466 SmartDataPtr<Event::MucMcHitCol> aMcHitCol(m_evtSvc,
"/Event/MC/MucMcHitCol");
468 std::cout<<
"Could not retrieve MUC McTruth collection"<<std::endl;
471 Event::MucMcHitCol::iterator iMcHitCol;
472 for(iMcHitCol=aMcHitCol->begin(); iMcHitCol!=aMcHitCol->end(); iMcHitCol++)
474 const Identifier ident = (*iMcHitCol)->identify();
492 SmartDataPtr<MucDigiCol> aDigiCol(m_evtSvc,
"/Event/Digi/MucDigiCol");
494 std::cout<<
"Could not retrieve MUC digi collection"<<std::endl;
498 MucDigiCol::iterator iDigiCol;
499 for(iDigiCol=aDigiCol->begin(); iDigiCol!=aDigiCol->end(); iDigiCol++)
501 const Identifier ident = (*iDigiCol)->identify();
McTestAlg(const std::string &name, ISvcLocator *pSvcLocator)
void RetrieveMcParticle()
static int layer(const Identifier &id)
Values of different levels (failure returns 0)
static int wire(const Identifier &id)
static int end(const Identifier &id)
static int phi_module(const Identifier &id)
static int barrel_ec(const Identifier &id)
Values of different levels (failure returns 0)
static int layer(const Identifier &id)