00001 #include "HltAlgorithms/CheckEFResult.h"
00002 #include "HltDataTypes/EFResult.h"
00003
00004 #include "GaudiKernel/MsgStream.h"
00005 #include "GaudiKernel/SmartDataPtr.h"
00006 #include "EventModel/Event.h"
00007 #include "EventModel/EventHeader.h"
00008 #include "HltDataTypes/CriteriaItemValue.h"
00009
00010 #include <fstream>
00011
00012 using namespace Event;
00013
00015
00016 CheckEFResult::CheckEFResult(const std::string& name, ISvcLocator* pSvcLocator) :
00017 Algorithm(name, pSvcLocator),
00018 m_notpass()
00019 {
00020 declareProperty("FilterOutput",m_outfile="lv2");
00021 }
00022
00023 CheckEFResult::~CheckEFResult()
00024 {
00025 }
00026
00027 StatusCode CheckEFResult::initialize(){
00028
00029 MsgStream log(msgSvc(), name());
00030 log << MSG::INFO << "in initialize()" << endreq;
00031
00032 StatusCode sc = service( "HltStoreSvc", m_HltStoreSvc);
00033 if( sc.isFailure() ) {
00034 log << MSG::FATAL << name() << ": Unable to locate Service HltStoreSvc" << endreq;
00035 return sc;
00036 }
00037
00038 sc = serviceLocator()->service("EventDataSvc", m_evtDataSvc, true);
00039 if (!sc.isSuccess()) {
00040 log << MSG::FATAL << "Error retrieving EventDataSvc interface IDataProviderSvc." << endreq;
00041 return sc;
00042 }
00043
00044 NTuplePtr nt(ntupleSvc(),"FILE123/EventFilter");
00045 if ( nt ) m_tuple = nt;
00046 else {
00047 m_tuple=ntupleSvc()->book("FILE123/EventFilter",CLID_ColumnWiseTuple,"EventFilter");
00048 if( m_tuple ) {
00049 m_tuple->addItem ("alg", m_alg);
00050 m_tuple->addItem ("nevt", m_nevt);
00051
00052 m_tuple->addItem ("ntof", m_ntof);
00053 m_tuple->addItem ("nemc", m_nemc);
00054 m_tuple->addItem ("nmdc", m_nmdc);
00055 m_tuple->addItem ("nshw", m_nshower);
00056 m_tuple->addItem ("nsec", m_nsec);
00057 m_tuple->addItem ("mbal", m_mbalance);
00058 m_tuple->addItem ("type", m_evttype);
00059
00060
00061
00062 m_tuple->addItem ("nmuc", m_nmuc);
00063 m_tuple->addItem ("etot", m_etot);
00064 m_tuple->addItem ("emax1", m_emax1);
00065 m_tuple->addItem ("emax2", m_emax2);
00066 m_tuple->addItem ("acop", m_acop);
00067 m_tuple->addItem ("ebal", m_ebalance);
00068 m_tuple->addItem ("ebar", m_ebarrel);
00069 m_tuple->addItem ("eend", m_eendcap);
00070 m_tuple->addItem ("ntrk", m_ntrk);
00071 m_tuple->addItem ("pmax1", m_pmax1);
00072 m_tuple->addItem ("pmax2", m_pmax2);
00073 m_tuple->addItem ("acol", m_acol);
00074 m_tuple->addItem ("cost1", m_cost1);
00075 m_tuple->addItem ("cost2", m_cost2);
00076 m_tuple->addItem ("dtof1", m_dtof1);
00077 m_tuple->addItem ("dphi1", m_dphi1);
00078 m_tuple->addItem ("dtof2", m_dtof2);
00079 m_tuple->addItem ("dphi2", m_dphi2);
00080 }
00081 else {
00082 log << MSG::ERROR <<"Cannot book N-tuple:" << long(m_tuple) << endmsg;
00083 return StatusCode::FAILURE;
00084 }
00085 }
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103 return StatusCode::SUCCESS;
00104 }
00105
00106 StatusCode CheckEFResult::execute() {
00107
00108 MsgStream log(msgSvc(), name());
00109
00110
00111 EFResult* efResult;
00112 StatusCode sc = m_HltStoreSvc->get("EFResult", efResult);
00113 if ( sc.isFailure() ) {
00114 log << MSG::ERROR << " Could not find EFResult" << endreq;
00115 return sc;
00116 }
00117
00118 if (efResult->getAnswerIndex() == -1) {
00119 log << MSG::ERROR << " Unvalid efResult(AnswerIndex==-1)" << endreq;
00120 return StatusCode::FAILURE;
00121 }
00122
00123 std::string answer = efResult->getAnswer();
00124
00125 log << MSG::INFO << "this event is " << answer << endreq;
00126
00127 if (answer == "Accepted") {
00128 EFResult* evtType;
00129 sc = m_HltStoreSvc->get("EventType", evtType);
00130 if ( sc.isFailure() ) {
00131 log << MSG::ERROR << " Could not find EventType" << endreq;
00132 return sc;
00133 }
00134 if (evtType->getAnswerIndex() == -1) {
00135 log << MSG::ERROR << " Unvalid evtType(AnswerIndex==-1)" << endreq;
00136 return StatusCode::FAILURE;
00137 }
00138 std::string typeStr = evtType->getAnswer();
00139 log << MSG::INFO << " ==> it's marked as " << typeStr << endreq;
00140
00141
00142 if(typeStr=="Junk") m_evttype=0;
00143 else if(typeStr=="GJunk") m_evttype=1;
00144 else if(typeStr=="Beamgas") m_evttype=2;
00145 else if(typeStr=="GBeamgas") m_evttype=3;
00146 else if(typeStr=="Cosmic") m_evttype=4;
00147 else if(typeStr=="GCosmic") m_evttype=5;
00148 else if(typeStr=="EBhabha") m_evttype=6;
00149 else if(typeStr=="GEBhabha") m_evttype=7;
00150 else if(typeStr=="BBhabha") m_evttype=8;
00151 else if(typeStr=="GBBhabha") m_evttype=9;
00152 else if(typeStr=="Dimuon") m_evttype=10;
00153 else if(typeStr=="GDimuon") m_evttype=11;
00154 else if(typeStr=="Diphoton") m_evttype=12;
00155 else if(typeStr=="GDiphoton") m_evttype=13;
00156 else if(typeStr=="Hadron") m_evttype=14;
00157 else if(typeStr=="GHadron") m_evttype=15;
00158 else if(typeStr=="Twophoton") m_evttype=16;
00159 else if(typeStr=="GTwophoton") m_evttype=17;
00160 else if(typeStr=="RandomTrg") m_evttype=31;
00161 else if(typeStr=="Error") m_evttype=30;
00162 else if(typeStr=="Other") m_evttype=29;
00163 else m_evttype=-1;
00164 }
00165 log << MSG::DEBUG << "get event type info: " << m_evttype << endreq;
00166
00167 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),"/Event/EventHeader");
00168 if (!eventHeader) {
00169 log << MSG::FATAL << "Could not find Event Header" << endreq;
00170 return (StatusCode::FAILURE);
00171 }
00172 m_nevt= eventHeader->eventNumber();
00173 log << MSG::INFO << "EventNo: " << m_nevt <<endl;
00174 if(m_evttype==1||m_evttype==3||m_evttype==5) m_notpass.push_back(eventHeader->eventNumber());
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186 float nmdc,ntof,nemc,nmuc,nshower,ntrk,nsec;
00187 float etot,ebar,eend,ebal,acop,emax1,emax2,dtof1,dphi1,dtof2,dphi2,acol,mbal,pmax1,pmax2;
00188
00189 CriteriaItemValue* pcri;
00190
00191 sc = m_HltStoreSvc->get("nmdc", pcri);
00192 if ( sc.isFailure() ) nmdc=-9;
00193 else pcri->getValue(nmdc);
00194 sc = m_HltStoreSvc->get("nmuc", pcri);
00195 if ( sc.isFailure() ) nmuc=-9;
00196 else pcri->getValue(nmuc);
00197 sc = m_HltStoreSvc->get("ntof", pcri);
00198 if ( sc.isFailure() ) ntof=-9;
00199 else pcri->getValue(ntof);
00200 sc = m_HltStoreSvc->get("nemc", pcri);
00201 if ( sc.isFailure() ) nemc=-9;
00202 else pcri->getValue(nemc);
00203
00204 sc = m_HltStoreSvc->get("nshw", pcri);
00205 if ( sc.isFailure() ) nshower=-9;
00206 else pcri->getValue(nshower);
00207 sc = m_HltStoreSvc->get("ntrk", pcri);
00208 if ( sc.isFailure() ) ntrk=-9;
00209 else pcri->getValue(ntrk);
00210 sc = m_HltStoreSvc->get("etot", pcri);
00211 if ( sc.isFailure() ) etot=-9;
00212 else pcri->getValue(etot);
00213 sc = m_HltStoreSvc->get("ebar", pcri);
00214 if ( sc.isFailure() ) ebar=-9;
00215 else pcri->getValue(ebar);
00216 sc = m_HltStoreSvc->get("eend", pcri);
00217 if ( sc.isFailure() ) eend=-9;
00218 else pcri->getValue(eend);
00219 sc = m_HltStoreSvc->get("ebal", pcri);
00220 if ( sc.isFailure() ) ebal=-9;
00221 else pcri->getValue(ebal);
00222 sc = m_HltStoreSvc->get("acop", pcri);
00223 if ( sc.isFailure() ) acop=-9;
00224 else pcri->getValue(acop);
00225 sc = m_HltStoreSvc->get("emax1", pcri);
00226 if ( sc.isFailure() ) emax1=-9;
00227 else pcri->getValue(emax1);
00228 sc = m_HltStoreSvc->get("emax2", pcri);
00229 if ( sc.isFailure() ) emax2=-9;
00230 else pcri->getValue(emax2);
00231 sc = m_HltStoreSvc->get("dtof1", pcri);
00232 if ( sc.isFailure() ) dtof1=-999;
00233 else pcri->getValue(dtof1);
00234 sc = m_HltStoreSvc->get("dphi1", pcri);
00235 if ( sc.isFailure() ) dphi1=-9;
00236 else pcri->getValue(dphi1);
00237 sc = m_HltStoreSvc->get("dtof2", pcri);
00238 if ( sc.isFailure() ) dtof2=-999;
00239 else pcri->getValue(dtof2);
00240 sc = m_HltStoreSvc->get("dphi2", pcri);
00241 if ( sc.isFailure() ) dphi2=-9;
00242 else pcri->getValue(dphi2);
00243 sc = m_HltStoreSvc->get("acol", pcri);
00244 if ( sc.isFailure() ) acol=-9;
00245 else pcri->getValue(acol);
00246 sc = m_HltStoreSvc->get("pmax1", pcri);
00247 if ( sc.isFailure() ) pmax1=-9;
00248 else pcri->getValue(pmax1);
00249 sc = m_HltStoreSvc->get("pmax2", pcri);
00250 if ( sc.isFailure() ) pmax2=-9;
00251 else pcri->getValue(pmax2);
00252 sc = m_HltStoreSvc->get("nsec", pcri);
00253 if ( sc.isFailure() ) nsec=-9;
00254 else pcri->getValue(nsec);
00255 sc = m_HltStoreSvc->get("mbal", pcri);
00256 if ( sc.isFailure() ) mbal=-9;
00257 else pcri->getValue(mbal);
00258 m_nmdc=long(nmdc);
00259 m_ntof=long(ntof);
00260 m_nemc=long(nemc);
00261 m_nmuc=long(nmuc);
00262 m_nshower=long(nshower);
00263 m_ntrk=long(ntrk);
00264 m_nsec=long(nsec);
00265 m_etot=etot;
00266 m_ebarrel=ebar;
00267 m_eendcap=eend;
00268 m_ebalance=ebal;
00269 m_acop=acop;
00270 m_emax1=emax1;
00271 m_emax2=emax2;
00272 m_dtof1=dtof1;
00273 m_dphi1=dphi1;
00274 m_dtof2=dtof2;
00275 m_dphi2=dphi2;
00276 m_acol=acol;
00277 m_mbalance=mbal;
00278 m_pmax1=pmax1;
00279 m_pmax2=pmax2;
00280
00281 std::vector<uint32_t> efVec=efResult->getEFVec();
00282 m_alg =efVec[0];
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303 log<< MSG::INFO<<efVec<<endreq;
00304 log<< MSG::INFO<<acol<<" "<<etot<<endreq;
00305 if(m_tuple){
00306 StatusCode status = m_tuple->write();
00307 if (!status.isSuccess()) {
00308 log << MSG::ERROR << "Can't fill ntuple!" << endreq;
00309 }
00310 }
00311
00312
00313
00314 return StatusCode::SUCCESS;
00315 }
00316
00317 StatusCode CheckEFResult::finalize() {
00318
00319 MsgStream log(msgSvc(), name());
00320 log << MSG::INFO << "in finalize()" << endreq;
00321
00322
00323 if(m_notpass.size()>0&&m_outfile!="lv2"){
00324 ofstream outfile;
00325 outfile.open(m_outfile.c_str(),ios_base::out);
00326 for(unsigned int i=0;i<m_notpass.size();i++){
00327 outfile << m_notpass[i] <<endl;
00328 }
00329 outfile.close();
00330 }
00331
00332 return StatusCode::SUCCESS;
00333 }
00334