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"
46Algorithm(name, pSvcLocator)
48 declareProperty(
"ParticleRootFlag",m_particleRootFlag=
false);
49 declareProperty(
"MdcRootFlag",m_mdcRootFlag=
false);
50 declareProperty(
"TofRootFlag",m_tofRootFlag=
false);
55 MsgStream log(
msgSvc(), name());
56 log << MSG::INFO <<
" McTestAlg initialize()" << endreq;
58 if(m_particleRootFlag)
61 NTuplePtr ntp(
ntupleSvc(),
"FILE900/particle");
62 if(ntp) tupleParticle = ntp;
64 tupleParticle =
ntupleSvc()->book(
"FILE900/particle",CLID_ColumnWiseTuple,
"McTestAlg");
66 sc = tupleParticle->addItem(
"me",me);
74 if(nt1) tupleMdc1 = nt1;
76 tupleMdc1 =
ntupleSvc()->book(
"FILE901/n1",CLID_ColumnWiseTuple,
"McTestAlg");
79 sc = tupleMdc1->addItem(
"truthIndex",truthMdcIndex);
80 sc = tupleMdc1->addItem(
"truthLayer",truthMdcLayer);
81 sc = tupleMdc1->addItem(
"truthWire",truthMdcWire);
82 sc = tupleMdc1->addItem(
"truthEdep",truthMdcEdep);
83 sc = tupleMdc1->addItem(
"truthDriftD",truthMdcDriftD);
84 sc = tupleMdc1->addItem(
"truthX",truthMdcX);
85 sc = tupleMdc1->addItem(
"truthY",truthMdcY);
86 sc = tupleMdc1->addItem(
"truthZ",truthMdcZ);
87 sc = tupleMdc1->addItem(
"ntruth",ntruthMdc);
90 log << MSG::ERROR <<
"Cannot book MDC N-tuple:" << long(tupleMdc1) << endmsg;
91 return StatusCode::FAILURE;
96 if(nt2) tupleMdc2 = nt2;
98 tupleMdc2 =
ntupleSvc()->book(
"FILE901/n2",CLID_ColumnWiseTuple,
"McTestAlg");
101 sc = tupleMdc2->addItem(
"layer",m_layer);
102 sc = tupleMdc2->addItem(
"cell",m_cell);
103 sc = tupleMdc2->addItem(
"ADC",m_charge);
104 sc = tupleMdc2->addItem(
"TDC",m_time);
113 if(nt) tupleTof = nt;
115 tupleTof=
ntupleSvc()->book(
"FILE902/lr",CLID_ColumnWiseTuple,
"McTestAlg");
118 sc = tupleTof->addItem(
"truthIndex",truthIndex);
119 sc = tupleTof->addItem(
"truthPartId",truthPartId);
120 sc = tupleTof->addItem(
"truthLayer",truthLayer);
121 sc = tupleTof->addItem(
"truthScinNb",truthScinNb);
122 sc = tupleTof->addItem(
"truthX",truthX);
123 sc = tupleTof->addItem(
"truthY",truthY);
124 sc = tupleTof->addItem(
"truthZ",truthZ);
125 sc = tupleTof->addItem(
"ntruth",ntruth);
126 sc = tupleTof->addItem(
"tleft",tleft);
127 sc = tupleTof->addItem(
"tright",tright);
128 sc = tupleTof->addItem(
"qleft",qleft);
129 sc = tupleTof->addItem(
"qright",qright);
132 log << MSG::ERROR <<
"Cannot book N-tuple:" << long(tupleTof) << endmsg;
133 return StatusCode::FAILURE;
137 return StatusCode::SUCCESS;
142 MsgStream log(
msgSvc(), name());
143 log << MSG::INFO <<
"McTestAlg finalize()" << endreq;
145 return StatusCode::SUCCESS;
153 ISvcLocator* svcLocator = Gaudi::svcLocator();
154 StatusCode sc=svcLocator->service(
"EventDataSvc", m_evtSvc);
156 std::cout<<
"Could not accesss EventDataSvc!"<<std::endl;
158 SmartDataPtr<Event::EventHeader> eventHeader(m_evtSvc,
"/Event/EventHeader");
160 std::cout<<
"Could not retrieve EventHeader"<<std::endl;
162 int event=eventHeader->eventNumber();
163 std::cout<<
"event: "<<
event<<std::endl;
171 return StatusCode::SUCCESS;
177 SmartDataPtr<Event::McParticleCol> mcParticleCol(m_evtSvc,
"/Event/MC/McParticleCol");
179 std::cout<<
"Could not retrieve McParticelCol"<<std::endl;
183 double px,py,pz,E,
mass;
185 Event::McParticleCol::iterator iter_mc = mcParticleCol->begin();
186 for (;iter_mc != mcParticleCol->end(); iter_mc++)
189 pdgcode = (*iter_mc)->particleProperty();
190 if((*iter_mc)->trackIndex()<0)
191 std::cout<<
"ERROR! trackIndex<0"<<std::endl;
192 px=(*iter_mc)->initialFourMomentum().x();
193 py=(*iter_mc)->initialFourMomentum().y();
194 pz=(*iter_mc)->initialFourMomentum().z();
195 E=(*iter_mc)->initialFourMomentum().t();
196 if(E*E-px*px-py*py-pz*pz>=0)
197 mass=sqrt(E*E-px*px-py*py-pz*pz);
201 if(m_particleRootFlag)
205 tupleParticle->write();
207 if(
abs(pdgcode)==2212||
abs(pdgcode)==211)
211 std::cout<<
"nflag!=4"<<std::endl;
240 SmartDataPtr<Event::MdcMcHitCol> aMcHitCol(m_evtSvc,
"/Event/MC/MdcMcHitCol");
242 std::cout<<
"Could not retrieve MDC McTruth collection"<<std::endl;
245 Event::MdcMcHitCol::iterator iMcHitCol;
246 for(iMcHitCol=aMcHitCol->begin(); iMcHitCol!=aMcHitCol->end(); iMcHitCol++)
248 const Identifier ident = (*iMcHitCol)->identify();
261 truthMdcIndex = (*iMcHitCol)->getTrackIndex();
264 truthMdcEdep = (*iMcHitCol)->getDepositEnergy();
265 truthMdcDriftD = (*iMcHitCol)->getDriftDistance();
266 truthMdcX = (*iMcHitCol)->getPositionX();
267 truthMdcY = (*iMcHitCol)->getPositionY();
268 truthMdcZ = (*iMcHitCol)->getPositionZ();
277 SmartDataPtr<MdcDigiCol> aDigiCol(m_evtSvc,
"/Event/Digi/MdcDigiCol");
279 std::cout<<
"Could not retrieve MDC digi collection"<<std::endl;
283 MdcDigiCol::iterator iDigiCol;
284 for(iDigiCol=aDigiCol->begin(); iDigiCol!=aDigiCol->end(); iDigiCol++)
286 const Identifier ident = (*iDigiCol)->identify();
289 std::cout<<
" charge: "<<(*iDigiCol)->getChargeChannel();
290 std::cout<<
" time: "<<(*iDigiCol)->getTimeChannel()<<std::endl;
295 m_charge = (*iDigiCol)->getChargeChannel()/1.0e6;
296 m_time = (*iDigiCol)->getTimeChannel()/1.0e5;
323 int partId,layer,scinNb,end;
325 partId = layer = scinNb = end = -9;
331 SmartDataPtr<Event::TofMcHitCol> aMcHitCol(m_evtSvc,
"/Event/MC/TofMcHitCol");
333 std::cout<<
"Could not retrieve TOF McTruth collection"<<std::endl;
336 Event::TofMcHitCol::iterator iMcHitCol;
337 for(iMcHitCol=aMcHitCol->begin(); iMcHitCol!=aMcHitCol->end(); iMcHitCol++)
339 const Identifier ident = (*iMcHitCol)->identify();
355 truthIndex = (*iMcHitCol)->getTrackIndex();
359 truthX = (*iMcHitCol)->getPositionX();
360 truthY = (*iMcHitCol)->getPositionY();
361 truthZ = (*iMcHitCol)->getPositionZ();
368 SmartDataPtr<TofDigiCol> aDigiCol(m_evtSvc,
"/Event/Digi/TofDigiCol");
370 std::cout<<
"Could not retrieve TOF digi collection"<<std::endl;
373 TofDigiCol::iterator iDigiCol;
374 for(iDigiCol=aDigiCol->begin(); iDigiCol!=aDigiCol->end(); iDigiCol++)
376 const Identifier ident = (*iDigiCol)->identify();
390 charge = (*iDigiCol)->getChargeChannel()/1.0e6;
391 time = (*iDigiCol)->getTimeChannel()/1.0e6;
394 if(truthPartId==partId && truthLayer==layer && truthScinNb==scinNb)
401 std::cout<<
"digi doesn't match"<<std::endl;
406 if(tleft>0&&tright>0&&qleft>0&&qright>0)
409 std::cout<<
"no digi match MCtruth"<<std::endl;
419 SmartDataPtr<Event::EmcMcHitCol> aMcHitCol(m_evtSvc,
"/Event/MC/EmcMcHitCol");
421 std::cout<<
"Could not retrieve EMC McTruth collection"<<std::endl;
424 Event::EmcMcHitCol::iterator iMcHitCol;
425 for(iMcHitCol=aMcHitCol->begin(); iMcHitCol!=aMcHitCol->end(); iMcHitCol++)
427 const Identifier ident = (*iMcHitCol)->identify();
445 SmartDataPtr<EmcDigiCol> aDigiCol(m_evtSvc,
"/Event/Digi/EmcDigiCol");
447 std::cout<<
"Could not retrieve EMC digi collection"<<std::endl;
451 EmcDigiCol::iterator iDigiCol;
452 for(iDigiCol=aDigiCol->begin(); iDigiCol!=aDigiCol->end(); iDigiCol++)
454 const Identifier ident = (*iDigiCol)->identify();
468 SmartDataPtr<Event::MucMcHitCol> aMcHitCol(m_evtSvc,
"/Event/MC/MucMcHitCol");
470 std::cout<<
"Could not retrieve MUC McTruth collection"<<std::endl;
473 Event::MucMcHitCol::iterator iMcHitCol;
474 for(iMcHitCol=aMcHitCol->begin(); iMcHitCol!=aMcHitCol->end(); iMcHitCol++)
476 const Identifier ident = (*iMcHitCol)->identify();
494 SmartDataPtr<MucDigiCol> aDigiCol(m_evtSvc,
"/Event/Digi/MucDigiCol");
496 std::cout<<
"Could not retrieve MUC digi collection"<<std::endl;
500 MucDigiCol::iterator iDigiCol;
501 for(iDigiCol=aDigiCol->begin(); iDigiCol!=aDigiCol->end(); iDigiCol++)
503 const Identifier ident = (*iDigiCol)->identify();
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)