00001 #include "GaudiKernel/MsgStream.h"
00002
00003 #include "GaudiKernel/SmartDataPtr.h"
00004
00005 #include "EventModel/Event.h"
00006 #include "EventModel/EventHeader.h"
00007 #include "EmcRecEventModel/RecEmcEventModel.h"
00008 #include "HltAlgorithms/EFProcessCluster.h"
00009
00010 using namespace Event;
00011
00012 EFProcessCluster::EFProcessCluster(const std::string& name,ISvcLocator* pSvcLocator) :
00013 IEFAlgorithm(name, pSvcLocator) {
00014 int output=(m_output%10000)/1000;
00015
00016 MsgStream log(msgSvc(), name);
00017 msgSvc()->setOutputLevel(name,output);
00018 m_nshower = new CriteriaItemValue;
00019 m_acop = new CriteriaItemValue;
00020 m_acole = new CriteriaItemValue;
00021 m_emax1 = new CriteriaItemValue;
00022 m_emax2 = new CriteriaItemValue;
00023 m_emax3 = new CriteriaItemValue;
00024 m_emax12 = new CriteriaItemValue;
00025 m_coste1 = new CriteriaItemValue;
00026 m_coste2 = new CriteriaItemValue;
00027 m_coste3 = new CriteriaItemValue;
00028 m_phi1 = new CriteriaItemValue;
00029 m_phi2 = new CriteriaItemValue;
00030 m_phi3 = new CriteriaItemValue;
00031 }
00032
00033 EFProcessCluster::~EFProcessCluster() {
00034 delete m_emax1;
00035 delete m_emax2;
00036 delete m_emax3;
00037 delete m_emax12;
00038 delete m_coste1;
00039 delete m_coste2;
00040 delete m_coste3;
00041 delete m_phi1;
00042 delete m_phi2;
00043 delete m_phi3;
00044 delete m_acop;
00045 delete m_acole;
00046 delete m_nshower;
00047 }
00048
00049 StatusCode EFProcessCluster::initialize(){
00050
00051 MsgStream log(msgSvc(), name());
00052 log << MSG::INFO << "in initialize()" << endreq;
00053
00054 IEFAlgorithm::initialize();
00055
00056 StatusCode sc;
00057 sc = m_HltStoreSvc->put("nshw", m_nshower);
00058 if ( sc.isFailure() ) {
00059 log << MSG::ERROR << "m_HltStoreSvc->put(nshw) wrong" << endreq;
00060 return sc;
00061 }
00062 sc = m_HltStoreSvc->put("acop", m_acop);
00063 if ( sc.isFailure() ) {
00064 log << MSG::ERROR << "m_HltStoreSvc->put(acop) wrong" << endreq;
00065 return sc;
00066 }
00067 sc = m_HltStoreSvc->put("acole", m_acole);
00068 if ( sc.isFailure() ) {
00069 log << MSG::ERROR << "m_HltStoreSvc->put(acole) wrong" << endreq;
00070 return sc;
00071 }
00072 sc = m_HltStoreSvc->put("emax1", m_emax1);
00073 if ( sc.isFailure() ) {
00074 log << MSG::ERROR << "m_HltStoreSvc->put(emax1) wrong" << endreq;
00075 return sc;
00076 }
00077 sc = m_HltStoreSvc->put("emax2", m_emax2);
00078 if ( sc.isFailure() ) {
00079 log << MSG::ERROR << "m_HltStoreSvc->put(emax2) wrong" << endreq;
00080 return sc;
00081 }
00082 sc = m_HltStoreSvc->put("emax3", m_emax3);
00083 if ( sc.isFailure() ) {
00084 log << MSG::ERROR << "m_HltStoreSvc->put(emax3) wrong" << endreq;
00085 return sc;
00086 }
00087 sc = m_HltStoreSvc->put("emax12", m_emax12);
00088 if ( sc.isFailure() ) {
00089 log << MSG::ERROR << "m_HltStoreSvc->put(emax12) wrong" << endreq;
00090 return sc;
00091 }
00092 sc = m_HltStoreSvc->put("coste1", m_coste1);
00093 if ( sc.isFailure() ) {
00094 log << MSG::ERROR << "m_HltStoreSvc->put(cos1) wrong" << endreq;
00095 return sc;
00096 }
00097 sc = m_HltStoreSvc->put("coste2", m_coste2);
00098 if ( sc.isFailure() ) {
00099 log << MSG::ERROR << "m_HltStoreSvc->put(cos2) wrong" << endreq;
00100 return sc;
00101 }
00102 sc = m_HltStoreSvc->put("coste3", m_coste3);
00103 if ( sc.isFailure() ) {
00104 log << MSG::ERROR << "m_HltStoreSvc->put(cos3) wrong" << endreq;
00105 return sc;
00106 }
00107 sc = m_HltStoreSvc->put("phi1", m_phi1);
00108 if ( sc.isFailure() ) {
00109 log << MSG::ERROR << "m_HltStoreSvc->put(phi1) wrong" << endreq;
00110 return sc;
00111 }
00112 sc = m_HltStoreSvc->put("phi2", m_phi2);
00113 if ( sc.isFailure() ) {
00114 log << MSG::ERROR << "m_HltStoreSvc->put(phi2) wrong" << endreq;
00115 return sc;
00116 }
00117 sc = m_HltStoreSvc->put("phi3", m_phi3);
00118 if ( sc.isFailure() ) {
00119 log << MSG::ERROR << "m_HltStoreSvc->put(phi3) wrong" << endreq;
00120 return sc;
00121 }
00122
00123 return StatusCode::SUCCESS;
00124 }
00125
00126 StatusCode EFProcessCluster::execute() {
00127
00128 reset();
00129
00130 MsgStream log(msgSvc(), name());
00131
00132 float e1=0,e2=0;
00133 char* electron=getenv("BEPCII_INFO.BER_PRB");
00134 if(electron){
00135 e1=atof(electron);
00136 }
00137 else{
00138 log << MSG::ERROR << "Cannot get beam energy (e-)! Please call online people" << endreq;
00139 }
00140 char* positron=getenv("BEPCII_INFO.BPR_PRB");
00141 if(positron){
00142 e2=atof(positron);
00143 }
00144 else{
00145 log << MSG::ERROR << "Cannot get beam energy (e+)! Please call online people" << endreq;
00146 }
00147 if(e1>0.1&&e2>0.1&&m_beam>0) {
00148 m_beam = 0.5*(e1+e2);
00149 }
00150 else{
00151 }
00152 log << MSG::INFO << "beam energy = " << m_beam << endreq;
00153
00154
00155 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),"/Event/EventHeader");
00156 if (!eventHeader) {
00157 log << MSG::FATAL << "Could not find Event Header" << endreq;
00158 return( StatusCode::FAILURE);
00159 }
00160
00161 SmartDataPtr<RecEmcShowerCol> emcShowerCol(eventSvc(),"/Event/Recon/RecEmcShowerCol");
00162 if (!emcShowerCol) {
00163 log << MSG::FATAL << "Could not find Emc rec!!" << endreq;
00164 return( StatusCode::FAILURE);
00165 }
00166
00167 RecEmcShowerCol::iterator iterShower=emcShowerCol->begin();
00168 double max1=-999,max2=-999,max3=-999;
00169 double cost1=-999,cost2=-999,cost3=-999,phi1=-999,phi2=-999,phi3=-999;
00170
00171 unsigned int nshower=emcShowerCol->size();
00172 for(;iterShower!= emcShowerCol->end();iterShower++){
00173 if((*iterShower)->energy()>=max1){
00174 max3=max2;
00175 max2=max1;
00176 cost3=cost2;
00177 cost2=cost1;
00178 phi3=phi2;
00179 phi2=phi1;
00180 max1=(*iterShower)->energy();
00181 cost1=cos((*iterShower)->position().theta());
00182 phi1=(*iterShower)->position().phi();
00183 }
00184 else if((*iterShower)->energy()>max2){
00185 max3=max2;
00186 cost3=cost2;
00187 phi3=phi2;
00188 max2=(*iterShower)->energy();
00189 cost2=cos((*iterShower)->position().theta());
00190 phi2=(*iterShower)->position().phi();
00191 }
00192 else if((*iterShower)->energy()>max3){
00193 max3=(*iterShower)->energy();
00194 cost3=(*iterShower)->position().theta();
00195 phi3=(*iterShower)->position().phi();
00196 }
00197 }
00198 double acop=180,acol=180.;
00199 if(nshower>=2){
00200 acop=180.-180./3.1415927*acos(cos(phi1)*cos(phi2)+sin(phi1)*sin(phi2));
00201 acol=180.-180./3.1415927*acos(cos(phi1)*sin(acos(cost1))*cos(phi2)*sin(acos(cost2))
00202 +sin(phi1)*sin(acos(cost1))*sin(phi2)*sin(acos(cost2))
00203 +cost1*cost2);
00204 }
00205
00206 log << MSG::INFO << "nshower=" << nshower << "; acop=" << acop
00207 <<"; emax1="<< max1 <<"; emax2="<< max2 <<endreq;
00208
00209
00210 m_nshower->setValue(nshower);
00211 m_acop->setValue(acop);
00212 m_acole->setValue(acol);
00213 m_emax1->setValue(max1/abs(m_beam));
00214 m_emax2->setValue(max2/abs(m_beam));
00215 m_emax3->setValue(max3/abs(m_beam));
00216 m_emax12->setValue((max1+max2)/abs(m_beam));
00217 m_coste1->setValue(cost1);
00218 m_coste2->setValue(cost2);
00219 m_coste3->setValue(cost3);
00220 m_phi1->setValue(phi1);
00221 m_phi2->setValue(phi2);
00222 m_phi3->setValue(phi3);
00223
00224 m_ef->addToEFVec(nshower, 38);
00225 m_ef->appToEFVec(max1, 39);
00226 m_ef->appToEFVec(cost1,40);
00227 m_ef->appToEFVec(phi1,41);
00228 m_ef->appToEFVec(max2, 42);
00229 m_ef->appToEFVec(cost2,43);
00230 m_ef->appToEFVec(phi2,44);
00231 m_ef->appToEFVec(acop, 45);
00232 m_ef->appToEFVec(acol, 46);
00233 m_ef->appToEFVec(max1+max2, 47);
00234 m_ef->appToEFVec(max3, 48);
00235 m_ef->appToEFVec(cost3,49);
00236 m_ef->appToEFVec(phi3,50);
00237
00238 m_ef->setVecBit(true, 0, 2);
00239 if(nshower==0)m_ef->addToEFVec(1<<16,1);
00240 else if(nshower==1)m_ef->addToEFVec(4<<16,1);
00241 else if(nshower==2)m_ef->addToEFVec(10<<16,1);
00242 else if(nshower>=3)m_ef->addToEFVec(13<<16,1);
00243 else m_ef->addToEFVec(0<<16,1);
00244
00245 m_run=1;
00246
00247 return StatusCode::SUCCESS;
00248 }
00249
00250 StatusCode EFProcessCluster::finalize() {
00251 MsgStream log(msgSvc(), name());
00252 log << MSG::INFO << "in finalize()" << endmsg;
00253 return StatusCode::SUCCESS;
00254 }
00255
00256 void EFProcessCluster::reset() {
00257
00258 if(m_run) {
00259 m_nshower->reset();
00260 m_acop->reset();
00261 m_acole->reset();
00262 m_emax1->reset();
00263 m_emax2->reset();
00264 m_emax3->reset();
00265 m_emax12->reset();
00266 m_coste1->reset();
00267 m_coste2->reset();
00268 m_coste3->reset();
00269 m_phi1->reset();
00270 m_phi2->reset();
00271 m_phi3->reset();
00272 m_run=0;
00273 }
00274 return;
00275 }