00001 #include "GaudiKernel/SmartDataPtr.h"
00002
00003 #include "EventModel/Event.h"
00004 #include "EventModel/EventHeader.h"
00005 #include "Identifier/HltID.h"
00006 #include "HltEvent/HltInf.h"
00007 #include "HltEvent/DstHltInf.h"
00008
00009 #include "EventFilter/EventFilter.h"
00010
00011 #include "EventFilter/EFTest.h"
00012
00013 EFTest::EFTest(const std::string& name, ISvcLocator* pSvcLocator) :
00014 Algorithm(name, pSvcLocator) {
00015
00016
00017 declareProperty("OutputLevel", m_outputLevel = MSG::NIL);
00018 }
00019
00020 EFTest::~EFTest(){
00021 }
00022
00023 StatusCode EFTest::initialize(){
00024
00025 MsgStream log(msgSvc(), name());
00026 log << MSG::INFO << "in initialize()" << endreq;
00027
00028
00029 StatusCode status=StatusCode::SUCCESS;
00030 NTuplePtr nt1(ntupleSvc(), "FILE1/EventFilter");
00031 if ( nt1 ) m_tuple = nt1;
00032 else {
00033 m_tuple = ntupleSvc()->book ("FILE1/EventFilter", CLID_ColumnWiseTuple, "EventFilter N-Tuple");
00034 if ( m_tuple ) {
00035 status = m_tuple->addItem ("type", m_type);
00036 status = m_tuple->addItem ("alg", m_alg);
00037 status = m_tuple->addItem ("endEE", m_endEE);
00038 status = m_tuple->addItem ("version", m_version);
00039 status = m_tuple->addItem ("etot", m_etot);
00040 status = m_tuple->addItem ("nMDCdata", m_nmdc0);
00041 status = m_tuple->addItem ("nTOFdata", m_ntof0);
00042 status = m_tuple->addItem ("nEMCdata", m_nemc0);
00043 status = m_tuple->addItem ("nMUCdata", m_nmuc0);
00044 status = m_tuple->addItem ("nCONdata", m_ncon0);
00045 status = m_tuple->addItem ("nMDCfill", m_nmdc, 0, (int)HltID::getID_MDC_MAX() );
00046 status = m_tuple->addItem ("nTOFfill", m_ntof, 0, (int)HltID::getID_TOF_MAX() );
00047 status = m_tuple->addItem ("nEMCfill", m_nemc, 0, (int)HltID::getID_EMC_MAX() );
00048 status = m_tuple->addItem ("nMUCfill", m_nmuc, 0, (int)HltID::getID_MUC_MAX() );
00049 status = m_tuple->addItem ("nCONfill", m_ncon, 0, 100 );
00050 status = m_tuple->addIndexedItem ("MDCdata", m_nmdc, m_mdcData);
00051 status = m_tuple->addIndexedItem ("TOFdata", m_ntof, m_tofData);
00052 status = m_tuple->addIndexedItem ("EMCdata", m_nemc, m_emcData);
00053 status = m_tuple->addIndexedItem ("MUCdata", m_nmuc, m_mucData);
00054 status = m_tuple->addIndexedItem ("CONdata", m_ncon, m_conData);
00055 if (!status) {
00056 log << MSG::ERROR << " Cannot add item into N-tuple" << endreq;
00057 return status;
00058 }
00059 }
00060 else {
00061 log << MSG::ERROR << " Cannot book N-tuple:" << long(m_tuple) << endreq;
00062 return StatusCode::FAILURE;
00063 }
00064 }
00065
00066 return StatusCode::SUCCESS;
00067 }
00068
00069 StatusCode EFTest::execute() {
00070
00071 MsgStream log(msgSvc(), name());
00072 log << MSG::INFO << "in execute()" << endreq;
00073
00074 if(!EventFilter::getResult()) {
00075
00076 log << MSG::DEBUG << "this event refused by event filter: "
00077 << EventFilter::getName() <<endreq;
00078
00079
00080 }
00081 else {
00082
00083 log << MSG::DEBUG << "this event accepteded by event filter: "
00084 << EventFilter::getName() <<endreq;
00085
00086
00087 }
00088 SmartDataPtr<HltInf> hlt(eventSvc(),"/Event/Hlt/HltInf");
00089 bool dstFlag=false;
00090 if(!hlt) {
00091 log << MSG::WARNING << "Could not find Event HltInf (try DstHltInf now)" << endreq;
00092 SmartDataPtr<DstHltInf> hltDst(eventSvc(),"/Event/Hlt/DstHltInf");
00093 if(!hltDst){
00094 log << MSG::FATAL << "Could not find Event DstHltInf too ( please re-generate data)" << endreq;
00095 return( StatusCode::FAILURE);
00096 }
00097 else{
00098 hlt=hltDst;
00099 dstFlag=true;
00100 }
00101 }
00102
00103 uint32_t type = hlt->getEventType();
00104 for(int i=0;i<32;i++) {
00105 if((1<<i)&type) m_type=i;
00106 }
00107 m_alg = hlt->getAlgProcess();
00108 m_endEE = hlt->getCriteriaTable();
00109 m_version = hlt->getVersion();
00110 m_etot = hlt->getTotalEnergy();
00111 m_nmdc0 = hlt->getNMDC();
00112 m_ntof0 = hlt->getNTOF();
00113 m_nemc0 = hlt->getNEMC();
00114 m_nmuc0 = hlt->getNMUC();
00115 m_ncon0 = hlt->getNCON();
00116 m_nmdc = 0;
00117 m_ntof = 0;
00118 m_nemc = 0;
00119 m_nmuc = 0;
00120 m_ncon = 0;
00121 if(!dstFlag) {
00122 vector<uint32_t>::iterator it;
00123
00124 vector<uint32_t> mdcData= hlt->getDataVec(HltID::MDC);
00125 it = mdcData.begin();
00126 for(;it!=mdcData.end();it++,m_nmdc++){
00127 if(m_nmdc>1) m_mdcData[m_nmdc]= *((float*) &(*it));
00128 else m_mdcData[m_nmdc]= *it;
00129 }
00130
00131 vector<uint32_t> tofData= hlt->getDataVec(HltID::TOF);
00132 it = tofData.begin();
00133 for(;it!=tofData.end();it++,m_ntof++){
00134 if(m_ntof>0) m_tofData[m_ntof]= *((float*) &(*it));
00135 else m_tofData[m_ntof]= *it;
00136 }
00137
00138 vector<uint32_t> emcData= hlt->getDataVec(HltID::EMC);
00139 it = emcData.begin();
00140 for(;it!=emcData.end();it++,m_nemc++){
00141 if(!(m_nemc==0||m_nemc==7||m_nemc==8)) m_emcData[m_nemc]= *((float*) &(*it));
00142 else m_emcData[m_nemc]= *it;
00143 }
00144
00145 vector<uint32_t> mucData= hlt->getDataVec(HltID::MUC);
00146 it = mucData.begin();
00147 for(;it!=mucData.end();it++,m_nmuc++){
00148 if(m_nmuc>1) m_mucData[m_nmuc]= *((float*) &(*it));
00149 else m_mucData[m_nmuc]= *it;
00150 }
00151
00152 vector<uint32_t> conData= hlt->getDataVec(HltID::CON);
00153 it = conData.begin();
00154 for(;it!=conData.end();it++,m_ncon++){
00155 m_conData[m_ncon]= *it;
00156 }
00157 }
00158
00159 m_tuple->write();
00160
00161 return StatusCode::SUCCESS ;
00162 }
00163
00164 StatusCode EFTest::finalize() {
00165
00166 MsgStream log(msgSvc(), name());
00167 log << MSG::INFO << "in finalize()" << endreq;
00168
00169 long unsigned ntot=EventFilter::getNEvt();
00170 long unsigned npass=EventFilter::getNPass();
00171 log << MSG::ALWAYS << "=========================================" <<endreq
00172 << "total "<< ntot <<" events with " << npass << " effective events " <<endreq
00173 << "========================================="<< endreq;
00174
00175
00176 return StatusCode::SUCCESS;
00177 }