00001 #include "GaudiKernel/MsgStream.h"
00002 #include "GaudiKernel/AlgFactory.h"
00003 #include "GaudiKernel/ISvcLocator.h"
00004 #include "GaudiKernel/SmartDataPtr.h"
00005 #include "GaudiKernel/IDataProviderSvc.h"
00006 #include "GaudiKernel/PropertyMgr.h"
00007 #include "GaudiKernel/ITHistSvc.h"
00008
00009 #include "EventModel/EventModel.h"
00010 #include "EventModel/Event.h"
00011 #include "EventModel/EventHeader.h"
00012 #include "EvtRecEvent/EvtRecEvent.h"
00013 #include "EvtRecEvent/EvtRecTrack.h"
00014 #include "DstEvent/TofHitStatus.h"
00015 #include "McTruth/McParticle.h"
00016 #include "TMath.h"
00017 #include "GaudiKernel/NTuple.h"
00018 #include "GaudiKernel/Bootstrap.h"
00019 #include "CLHEP/Vector/ThreeVector.h"
00020 #include "CLHEP/Vector/LorentzVector.h"
00021 #include "CLHEP/Vector/TwoVector.h"
00022 using CLHEP::Hep3Vector;
00023 using CLHEP::Hep2Vector;
00024 using CLHEP::HepLorentzVector;
00025 #include "CLHEP/Geometry/Point3D.h"
00026 #include "VertexFit/KinematicFit.h"
00027 #include "VertexFit/VertexFit.h"
00028 #include "ParticleID/ParticleID.h"
00029 const double xmass[5] = {0.000511, 0.105658, 0.139570,0.493677, 0.938272};
00030 const double velc = 299.792458;
00031 typedef std::vector<int> Vint;
00032 typedef std::vector<HepLorentzVector> Vp4;
00033 #include "DiGamAlg/DiGam.h"
00034 #include <vector>
00035 #include "DiGamAlg/Parameter.h"
00036
00037 const double pai=3.1415926;
00038 int N0;int N1;int N2;int N3;int N4;
00039 DiGam::DiGam(const std::string& name, ISvcLocator* pSvcLocator) :
00040 Algorithm(name, pSvcLocator) {
00041 declareProperty("jpsiCrossSection",jpsiCrossSection=249.7);
00042 declareProperty("jpsiMCEff",jpsiMCEff=0.07145);
00043 declareProperty("jpsiMCEffBoost",jpsiMCEffBoost=0.07099);
00044
00045 declareProperty("psi2sCrossSection",psi2sCrossSection=180.8);
00046 declareProperty("psi2sMCEff",psi2sMCEff=0.07159);
00047 declareProperty("psi2sMCEffBoost",psi2sMCEffBoost=0.07123);
00048
00049 declareProperty("psi3770CrossSection",psi3770CrossSection=173.4);
00050 declareProperty("psi3770MCEff",psi3770MCEff=0.071725);
00051 declareProperty("psi3770MCEffBoost",psi3770MCEffBoost=0.0713125);
00052
00053 declareProperty("CrossSection",CrossSection);
00054 declareProperty("MCEff",MCEff);
00055 declareProperty("MCEffBoost",MCEffBoost);
00056
00057 declareProperty("boostPhimin", boostPhimin=2.5);
00058 declareProperty("boostPhimax",boostPhimax=5);
00059 declareProperty("boostMinEmin",boostMinEmin);
00060 declareProperty("boostMinEmax",boostMinEmax);
00061
00062 declareProperty("RunModel",RunModel=2000);
00063 declareProperty("dPhiMin",dPhiMin=-7);
00064 declareProperty("dPhiMax",dPhiMax=5);
00065 declareProperty("dPhiMinSig",dPhiMinSig=-4);
00066 declareProperty("dPhiMaxSig",dPhiMaxSig=2);
00067
00068 declareProperty("flag",flag=true);
00069 declareProperty("E_cms",E_cms);
00070 }
00071
00072 StatusCode DiGam::initialize(){
00073 MsgStream log(msgSvc(), name());
00074 log << MSG::INFO << "in initialize()" << endmsg;
00075
00076 if(RunModel==1){
00077 CrossSection=jpsiCrossSection;
00078 MCEff=jpsiMCEff;
00079 MCEffBoost=jpsiMCEffBoost;
00080 boostPhimin=2.5;
00081 boostPhimax=5;
00082 boostMinEmin=1.2;
00083 boostMinEmax=1.6;
00084 }
00085 else if(RunModel==2){
00086 CrossSection=psi2sCrossSection;
00087 MCEff=psi2sMCEff;
00088 MCEffBoost=psi2sMCEffBoost;
00089 boostPhimin=2.5;
00090 boostPhimax=5;
00091 boostMinEmin=1.4;
00092 boostMinEmax=1.9;
00093 }
00094 else if(RunModel==3){
00095 CrossSection=psi3770CrossSection;
00096 MCEff=psi3770MCEff;
00097 MCEffBoost=psi3770MCEffBoost;
00098 boostPhimin=2.5;
00099 boostPhimax=5;
00100 boostMinEmin=1.4;
00101 boostMinEmax=2;
00102 }
00103
00104 tot=0;
00105 signal=0;
00106 boost_signal=0;
00107 boost_tot=0;
00108 StatusCode ssc=service("THistSvc", m_thsvc);
00109 if(ssc.isFailure()) {
00110 log << MSG::FATAL << "DiGamAlg:Couldn't get THistSvc" << endreq;
00111 return ssc;
00112 }
00113 h_lum=new TH1F("lum","lum",4,0.5,4.5);
00114
00115 StatusCode scBeamEnergy=service("BeamEnergySvc", m_BeamEnergySvc);
00116
00117 if( scBeamEnergy.isFailure() ){
00118 log << MSG::FATAL << "can not use BeamEnergySvc" << endreq;
00119 return scBeamEnergy;
00120 }
00121
00122 StatusCode status;
00123
00124 NTuplePtr nt2(ntupleSvc(),"DQAFILE/zhsDiGam");
00125 if(nt2)m_tuple2=nt2;
00126 else{
00127 m_tuple2=ntupleSvc()->book("DQAFILE/zhsDiGam",CLID_ColumnWiseTuple,"ks N-Tuple example");
00128 if(m_tuple2){
00129 status=m_tuple2->addItem("ETol",m_tot);
00130 status=m_tuple2->addItem("maxE",m_maxE);
00131 status=m_tuple2->addItem("minE",m_minE);
00132 status=m_tuple2->addItem("maxTheta",m_maxTheta);
00133 status=m_tuple2->addItem("minTheta",m_minTheta);
00134 status=m_tuple2->addItem("maxPhi",m_maxPhi);
00135 status=m_tuple2->addItem("minPhi",m_minPhi);
00136 status=m_tuple2->addItem("delTheta",m_delTheta);
00137 status=m_tuple2->addItem("delPhi",m_delPhi);
00138 status=m_tuple2->addItem("angle",m_angle);
00139 status=m_tuple2->addItem("boostAngle",m_boostAngle);
00140 status=m_tuple2->addItem("boostMaxE",m_boostMaxE);
00141 status=m_tuple2->addItem("boostMinE",m_boostMinE);
00142 status=m_tuple2->addItem("boostDelPhi",m_boostDelPhi);
00143 status=m_tuple2->addItem("boostDelTheta",m_boostDelTheta);
00144 status=m_tuple2->addItem("boostM",m_boostM);
00145 status=m_tuple2->addItem("boostIM",m_boostIM);
00146 status=m_tuple2->addItem("m",m_m);
00147 status=m_tuple2->addItem("IM",m_IM);
00148
00149 status=m_tuple2->addItem ("run",m_run );
00150 status=m_tuple2->addItem ("rec",m_rec );
00151 status=m_tuple2->addItem("indexmc", m_idxmc, 0, 100);
00152 status=m_tuple2->addIndexedItem("pdgid", m_idxmc, m_pdgid);
00153 status=m_tuple2->addIndexedItem("motheridx", m_idxmc, m_motheridx);
00154
00155 }
00156 else {
00157 log<<MSG::FATAL<<"Cannot book N-tuple:"<<long(m_tuple2)<<endmsg;
00158 return StatusCode::FAILURE;
00159 }
00160 }
00161
00162 return StatusCode::SUCCESS;
00163 }
00164
00165 StatusCode DiGam::execute() {
00166 MsgStream log(msgSvc(), name());
00167 log << MSG::INFO << "in execute()" << endreq;
00168 N0++;
00169 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),"/Event/EventHeader");
00170 runNo=eventHeader->runNumber();
00171 int event=eventHeader->eventNumber();
00172 log<<MSG::INFO<<"run,evtnum="<<runNo<<","<<event<<endreq;
00173 m_run = eventHeader->runNumber();
00174 m_rec = eventHeader->eventNumber();
00175
00176 if(flag == true)
00177 {
00178 flag = false;
00179 log << MSG::DEBUG << "setting parameter" << endreq;
00180
00181 m_BeamEnergySvc->getBeamEnergyInfo();
00182 if ( ! m_BeamEnergySvc->isRunValid() ) return StatusCode::FAILURE;
00183 E_cms = 2*m_BeamEnergySvc->getbeamE();
00184 log << MSG::DEBUG << "cms energy is " << E_cms << endreq;
00185
00186 Parameter *func = new Parameter();
00187 func->parameters(E_cms);
00188
00189 CrossSection=func->m_CrossSection;
00190 MCEff=func->m_MCEff;
00191 MCEffBoost=func->m_MCEffBoost;
00192 boostMinEmin=func->m_boostMinEmin;
00193 boostMinEmax=func->m_boostMinEmax;
00194 }
00195
00196 SmartDataPtr<EvtRecEvent> evtRecEvent(eventSvc(), EventModel::EvtRec::EvtRecEvent);
00197 log<<MSG::INFO<<"ncharg,nneu,tottks="
00198 <<evtRecEvent->totalCharged()<<","
00199 <<evtRecEvent->totalNeutral()<<","
00200 <<evtRecEvent->totalTracks()<<endreq;
00201 SmartDataPtr<EvtRecTrackCol> evtRecTrkCol(eventSvc(), EventModel::EvtRec::EvtRecTrackCol);
00202 std::vector<int> iGam;
00203 iGam.clear();
00204 N1++;
00205 for(int i=evtRecEvent->totalCharged();i< evtRecEvent->totalTracks();i++){
00206 EvtRecTrackIterator itTrk=evtRecTrkCol->begin() + i;
00207 if(!(*itTrk)->isEmcShowerValid()) continue;
00208 RecEmcShower *emcTrk = (*itTrk)->emcShower();
00209 if(emcTrk->energy()<0.6)continue;
00210 if(fabs(cos(emcTrk->theta()))>0.83)continue;
00211 iGam.push_back((*itTrk)->trackId());
00212 }
00213 if(iGam.size()<2)return StatusCode::SUCCESS;
00214 N2++;
00215 double energy1=0.5;
00216 double energy2=0.5;
00217 int gam1=-9999;
00218 int gam2=-9999;
00219 for(int i=0;i<iGam.size();i++){
00220 EvtRecTrackIterator itTrk=evtRecTrkCol->begin() + iGam[i];
00221 RecEmcShower *emcTrk = (*itTrk)->emcShower();
00222
00223 if(emcTrk->energy()>energy1){
00224 energy2=energy1;
00225 gam2=gam1;
00226 energy1=emcTrk->energy();
00227 gam1=iGam[i];
00228 }
00229 else if(emcTrk->energy()>energy2){
00230 energy2=emcTrk->energy();
00231 gam2=iGam[i];
00232 }
00233 }
00234 if(gam1==-9999 || gam2==-9999)return StatusCode::SUCCESS;
00235 N3++;
00236 m_tot=energy1+energy2;
00237 RecEmcShower* maxEmc=(*(evtRecTrkCol->begin()+gam1))->emcShower();
00238 RecEmcShower* minEmc=(*(evtRecTrkCol->begin()+gam2))->emcShower();
00239 m_maxE=maxEmc->energy();
00240 m_minE=minEmc->energy();
00241 m_maxTheta=maxEmc->theta();
00242 m_minTheta=minEmc->theta();
00243 m_maxPhi=maxEmc->phi();
00244 m_minPhi=minEmc->phi();
00245 m_delPhi=(fabs(m_maxPhi-m_minPhi)-pai)*180./pai;
00246 m_delTheta=(fabs(m_maxTheta+m_minTheta)-pai)*180./pai;
00247
00248 HepLorentzVector max,min;
00249 max.setPx(m_maxE*sin(m_maxTheta)*cos(m_maxPhi));
00250 max.setPy(m_maxE*sin(m_maxTheta)*sin(m_maxPhi));
00251 max.setPz(m_maxE*cos(m_maxTheta));
00252 max.setE(m_maxE);
00253 min.setPx(m_minE*sin(m_minTheta)*cos(m_minPhi));
00254 min.setPy(m_minE*sin(m_minTheta)*sin(m_minPhi));
00255 min.setPz(m_minE*cos(m_minTheta));
00256 min.setE(m_minE);
00257 m_angle=max.angle(min.vect())*180./pai;
00258 m_m=(max+min).m();
00259 m_IM=max.invariantMass(min);
00260
00261 if(m_minE>=boostMinEmin && m_delPhi>dPhiMin && m_delPhi<dPhiMax && m_minE<=boostMinEmax)tot++;
00262 if(m_minE>=boostMinEmin && m_delPhi>dPhiMinSig && m_delPhi<dPhiMaxSig && m_minE<=boostMinEmax)signal++;
00263
00264
00265
00266 HepLorentzVector boost1=max.boost(-0.011,0,0);
00267 HepLorentzVector boost2=min.boost(-0.011,0,0);
00268 m_boostAngle=boost1.angle(boost2.vect())*180./pai;
00269 m_boostMaxE=boost1.e();
00270 m_boostMinE=boost2.e();
00271 m_boostDelPhi=(fabs(boost1.phi()-boost2.phi())-pai)*180./pai;
00272 m_boostDelTheta=(fabs(boost1.theta()+boost2.theta())-pai)*180./pai;
00273 m_boostM=(boost1+boost2).m();
00274 m_boostIM=boost1.invariantMass(boost2);
00275 log << MSG::INFO << "num Good Photon " << iGam.size()<<endreq;
00276 if(m_boostMinE>=boostMinEmin && m_boostMinE<=boostMinEmax && fabs(m_boostDelPhi)<=boostPhimin)boost_signal++;
00277 if(m_boostMinE>=boostMinEmin && m_boostMinE<=boostMinEmax && fabs(m_boostDelPhi)<=boostPhimax)boost_tot++;
00278
00279 if (eventHeader->runNumber()<0)
00280 {
00281 SmartDataPtr<Event::McParticleCol> mcParticleCol(eventSvc(), "/Event/MC/McParticleCol");
00282 int m_numParticle = 0;
00283 if (!mcParticleCol)
00284 {
00285
00286 return StatusCode::FAILURE;
00287 }
00288 else
00289 {
00290 bool jpsipDecay = false;
00291 int rootIndex = -1;
00292 Event::McParticleCol::iterator iter_mc = mcParticleCol->begin();
00293 for (; iter_mc != mcParticleCol->end(); iter_mc++)
00294 {
00295 if ((*iter_mc)->primaryParticle()) continue;
00296 if (!(*iter_mc)->decayFromGenerator()) continue;
00297
00298 if ((*iter_mc)->particleProperty()==443)
00299 {
00300 jpsipDecay = true;
00301 rootIndex = (*iter_mc)->trackIndex();
00302 }
00303 if (!jpsipDecay) continue;
00304 int mcidx = ((*iter_mc)->mother()).trackIndex() - rootIndex;
00305 int pdgid = (*iter_mc)->particleProperty();
00306 m_pdgid[m_numParticle] = pdgid;
00307 m_motheridx[m_numParticle] = mcidx;
00308 m_numParticle += 1;
00309 }
00310 }
00311 m_idxmc = m_numParticle;
00312 }
00313 N4++;
00314 m_tuple2->write();
00315 return StatusCode::SUCCESS;
00316 }
00317
00318 StatusCode DiGam::finalize() {
00319 MsgStream log(msgSvc(), name());
00320 log << MSG::INFO << "in finalize()" << endmsg;
00321
00322 double ssg=0.;
00323 double lum=0.;
00324 double boost_ssg=0.;
00325 double boost_lum=0.;
00326 if(CrossSection*MCEff==0||CrossSection*MCEffBoost==0){
00327 log << MSG::FATAL<<"DiGam Error: cross_section or MC_eff is not correct!"<<endreq;
00328 exit(1);
00329 }
00330 ssg=(signal-(tot-signal))*1.0;
00331
00332 lum=(ssg)/(CrossSection*MCEff);
00333
00334 boost_ssg=(boost_signal-(boost_tot-boost_signal))*1.0;
00335
00336 boost_lum=(boost_ssg)/(CrossSection*MCEffBoost);
00337
00338
00339 std::cout<<"E_cms = "<<E_cms<<std::endl;
00340
00341 std::cout<<"N0 = "<<N0<<std::endl;
00342 std::cout<<"minE, phi in:"<<boostMinEmin<<" ~ "<<boostMinEmax<<", "<<boostPhimin<<" ~ "<<boostPhimax<<std::endl;
00343 std::cout<<"sigma, eff = "<<CrossSection<<","<<MCEff<<std::endl;
00344 std::cout<<"sigma, effBoost = "<<CrossSection<<", "<<MCEffBoost<<std::endl;
00345 std::cout<<"Nsignal, lum, Nsig_boost, boost_lum = "<<ssg<<", "<<lum<<", "<<boost_ssg<<", "<<boost_lum<<std::endl;
00346 h_lum->SetBinContent(1,lum);
00347 h_lum->SetBinContent(2,ssg);
00348 h_lum->SetBinContent(3,boost_lum);
00349 h_lum->SetBinContent(4,boost_ssg);
00350 if(m_thsvc->regHist("/DQAHist/zhsLUM/lum", h_lum).isFailure()){
00351 log << MSG::FATAL<<"DiGam Error:can't write data to LUM!"<<endreq;
00352 exit(1);
00353 }
00354 return StatusCode::SUCCESS;
00355 }