00001 #include "EventTag/FillEventTag.h"
00002 #include "GaudiKernel/MsgStream.h"
00003 #include "GaudiKernel/SmartDataPtr.h"
00004 #include "GaudiKernel/MsgStream.h"
00005
00006 #include "EventModel/EventModel.h"
00007 #include "EventModel/Event.h"
00008 #include "EventModel/EventHeader.h"
00009 #include "McTruth/McParticle.h"
00010
00011 FillEventTag::FillEventTag(const std::string& name, ISvcLocator* pSvcLocator) :
00012 Algorithm(name, pSvcLocator)
00013 {
00014 declareProperty("GeneralEventType", initialEventTag=0);
00015 }
00016
00017 StatusCode FillEventTag::initialize()
00018 {
00019 MsgStream log(msgSvc(), name());
00020 static const bool CREATEIFNOTTHERE(true);
00021 StatusCode EventTagSvcStatus = service("EventTagSvc", m_EventTagSvc, CREATEIFNOTTHERE);
00022 if (!EventTagSvcStatus.isSuccess()) {
00023 log << MSG::ERROR << " Could not initialize Decay code service" << endreq;
00024 return EventTagSvcStatus;
00025 }
00026 return StatusCode::SUCCESS;
00027 }
00028 StatusCode FillEventTag::execute()
00029 {
00030 MsgStream log(msgSvc(), name());
00031
00032 m_EventTag =initialEventTag;
00033
00034
00035 if((m_EventTag&0xF)==1)return StatusCode::SUCCESS;
00036
00037 SmartDataPtr<Event::McParticleCol> mcParticles(eventSvc(),EventModel::MC::McParticleCol);
00038 if(!mcParticles){
00039 log<<MSG::ERROR<<"Can not open McParticleCollection" <<endreq;
00040 return StatusCode::SUCCESS;
00041 }
00042
00043 if(m_EventTag==0){
00044 for(Event::McParticleCol::iterator it=mcParticles->begin();it!=mcParticles->end();it++){
00045
00046 long int pdg=abs((*it)->particleProperty());
00047 if(((pdg%1000)/10) == 44){
00048 m_EventTag=((int)(pdg==443))*4+((int)(pdg==100443))*5+((int)(pdg==30443))*6
00049 +((int)(pdg==9000443))*7+((int)(pdg==9010443))*8+((int)(pdg==9020443))*9;
00050 break;
00051 }
00052 }
00053 }
00054
00055 if(m_EventTag==0){
00056 m_EventTag=2;
00057 for(Event::McParticleCol::iterator it=mcParticles->begin();it!=mcParticles->end();it++){
00058 if((*it)->decayInFlight() || (*it)->primaryParticle()) continue;
00059 long int pdg=abs((*it)->particleProperty());
00060 if(pdg==11){
00061 m_EventTag|=0X20;
00062 break;
00063 }
00064 else if(pdg==13){
00065 m_EventTag|=0X30;
00066 break;
00067 }
00068 else if(pdg==15){
00069 m_EventTag|=0X40;
00070 break;
00071 }
00072 else if((pdg>0)&&(pdg<9)){
00073 m_EventTag|=0X50;
00074 break;
00075 }
00076 }
00077 }
00078
00079
00080 if(((m_EventTag&0xf)>3)&&((m_EventTag&0xf)<9)){
00081 m_EventTag &= 0xf;
00082
00083 for(Event::McParticleCol::iterator it=mcParticles->begin();it!=mcParticles->end();it++){
00084 long int pdg=(*it)->particleProperty();
00085 if(((pdg%1000)/10) != 44)continue;
00086
00087 m_EventTag |= (m_EventTagSvc->getCharmDecayType(*it))<<4;
00088 m_EventTag |= (m_EventTagSvc->getChainCode(*it))<<8;
00089
00090 break;
00091 }
00092 }
00093 else if((m_EventTag&0xf)==0x2){
00094
00095 int ncha=0;
00096 int nneu=0;
00097 for(Event::McParticleCol::iterator it=mcParticles->begin();it!=mcParticles->end();it++){
00098 long int pdg=abs((*it)->particleProperty());
00099 bool good=(!(*it)->decayInFlight())&&(!(*it)->primaryParticle());
00100 ncha+=((int)(good&&((pdg==11)||(pdg==13)||(pdg==211)||(pdg==321)||(pdg==2212)||(pdg==1011))));
00101 nneu+=((int)(good&&((pdg==111)||(pdg==310)||(pdg==130)||(pdg==2112))));
00102
00103
00104
00105
00106
00107 }
00108 m_EventTag|=((ncha&0xF)<<8);
00109 m_EventTag|=((nneu&0xF)<<12);
00110 if((m_EventTag&0xf0)==0x40){
00111
00112 for(Event::McParticleCol::iterator it=mcParticles->begin();it!=mcParticles->end();it++){
00113 long int pdg=(*it)->particleProperty();
00114
00115 if(pdg==-15){
00116 m_EventTag |=(m_EventTagSvc->getDecayCode(*it))<<16;
00117
00118 }else if(pdg==15){
00119 m_EventTag |=(m_EventTagSvc->getDecayCode(*it))<<24;
00120
00121 }
00122 }
00123 }
00124 }
00125
00126
00127 SmartDataPtr<Event::EventHeader> evHead(eventSvc(),EventModel::EventHeader);
00128 if(!evHead){
00129 log<<MSG::ERROR<< " Can not to retreave EventHeader" << endreq;
00130 return StatusCode::SUCCESS;
00131 }
00132 evHead->setEventTag(m_EventTag);
00133
00134 return StatusCode::SUCCESS;
00135 }
00136
00137 StatusCode FillEventTag::finalize(){
00138 MsgStream log(msgSvc(), name());
00139 return StatusCode::SUCCESS;
00140 }