4#include "GaudiKernel/MsgStream.h"
5#include "GaudiKernel/AlgFactory.h"
6#include "GaudiKernel/ISvcLocator.h"
7#include "GaudiKernel/SmartDataPtr.h"
8#include "GaudiKernel/PropertyMgr.h"
9#include "GaudiKernel/IJobOptionsSvc.h"
31#include "GaudiKernel/Service.h"
32#include "GaudiKernel/ThreadGaudi.h"
40 Algorithm(name, pSvcLocator),fCluster2Shower(0)
43 fPositionMode.push_back(
"log");
44 fPositionMode.push_back(
"5x5");
46 m_propMgr.declareProperty(
"Output",fOutput=0);
47 m_propMgr.declareProperty(
"EventNb",fEventNb=0);
48 m_propMgr.declareProperty(
"DigiCalib",fDigiCalib=
false);
49 m_propMgr.declareProperty(
"TofEnergy",fTofEnergy=
false);
50 m_propMgr.declareProperty(
"OnlineMode",fOnlineMode=
false);
51 m_propMgr.declareProperty(
"TimeMin",fTimeMin=0);
52 m_propMgr.declareProperty(
"TimeMax",fTimeMax=60);
53 m_propMgr.declareProperty(
"PositionMode",fPositionMode);
57 m_propMgr.declareProperty(
"MethodMode",fMethodMode=1);
59 m_propMgr.declareProperty(
"PosCorr",fPosCorr=1);
60 m_propMgr.declareProperty(
"ElecSaturation",fElecSaturation=1);
62 IJobOptionsSvc* jobSvc;
63 pSvcLocator->service(
"JobOptionsSvc", jobSvc);
64 jobSvc->setMyProperties(
"EmcRecAlg", &m_propMgr);
84 MsgStream log(
msgSvc(), name());
85 log << MSG::INFO <<
"in initialize()" << endreq;
89 std::string rawDataProviderSvc_name(
"RawDataProviderSvc");
90 StatusCode sc = service(rawDataProviderSvc_name.c_str(), m_rawDataProviderSvc);
91 if(sc != StatusCode::SUCCESS) {
92 log << MSG::ERROR <<
"EmcRec Error: Can't get RawDataProviderSvc." << endmsg;
104 if ( nt ) m_tuple = nt;
106 m_tuple=
ntupleSvc()->book(
"FILE301/n1",CLID_ColumnWiseTuple,
"EmcRec");
108 status = m_tuple->addItem (
"pid",pid);
109 status = m_tuple->addItem (
"tp",tp);
110 status = m_tuple->addItem (
"ttheta",ttheta);
111 status = m_tuple->addItem (
"tphi",tphi);
112 status = m_tuple->addItem (
"nrun",nrun);
113 status = m_tuple->addItem (
"nrec",nrec);
114 status = m_tuple->addItem (
"nneu",nneu);
115 status = m_tuple->addItem (
"ncluster",ncluster);
116 status = m_tuple->addItem (
"npart",npart);
117 status = m_tuple->addItem (
"ntheta",ntheta);
118 status = m_tuple->addItem (
"nphi",nphi);
119 status = m_tuple->addItem (
"ndigi",ndigi);
120 status = m_tuple->addItem (
"nhit",nhit);
121 status = m_tuple->addItem (
"pp1",4,pp1);
122 status = m_tuple->addItem (
"theta1",theta1);
123 status = m_tuple->addItem (
"phi1",phi1);
124 status = m_tuple->addItem (
"dphi1",dphi1);
125 status = m_tuple->addItem (
"eseed",eseed);
126 status = m_tuple->addItem (
"e3x3",e3x3);
127 status = m_tuple->addItem (
"e5x5",e5x5);
128 status = m_tuple->addItem (
"enseed",enseed);
129 status = m_tuple->addItem (
"etof2x1",etof2x1);
130 status = m_tuple->addItem (
"etof2x3",etof2x3);
131 status = m_tuple->addItem (
"cluster2ndMoment",cluster2ndMoment);
132 status = m_tuple->addItem (
"secondMoment",secondMoment);
133 status = m_tuple->addItem (
"latMoment",latMoment);
134 status = m_tuple->addItem (
"a20Moment",a20Moment);
135 status = m_tuple->addItem (
"a42Moment",a42Moment);
136 status = m_tuple->addItem (
"mpi0",mpi0);
137 status = m_tuple->addItem (
"thtgap1",thtgap1);
138 status = m_tuple->addItem (
"phigap1",phigap1);
139 status = m_tuple->addItem (
"pp2",4,pp2);
142 log << MSG::ERROR <<
"Cannot book N-tuple:" << long(m_tuple) << endmsg;
143 return StatusCode::FAILURE;
155 return StatusCode::SUCCESS;
161 MsgStream log(
msgSvc(), name());
162 log << MSG::DEBUG <<
"in execute()" << endreq;
167 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),
"/Event/EventHeader");
169 log << MSG::FATAL <<name() <<
" Could not find Event Header" << endreq;
170 return( StatusCode::FAILURE);
172 run=eventHeader->runNumber();
173 event=eventHeader->eventNumber();
180 if(fEventNb!=0&&m_event%fEventNb==0) {
181 log << MSG::FATAL <<m_event<<
"-------: "<<run<<
","<<
event<<endreq;
185 log << MSG::DEBUG <<
"===================================="<<endreq;
186 log << MSG::DEBUG <<
"run= "<<run<<
"; event= "<<
event<<endreq;
192 if(fOutput>=1&&run<0) {
194 SmartDataPtr<McParticleCol> mcParticleCol(eventSvc(),
"/Event/MC/McParticleCol");
195 if (!mcParticleCol) {
196 log << MSG::WARNING <<
"Could not find McParticle" << endreq;
199 McParticleCol::iterator iter_mc = mcParticleCol->begin();
200 for (;iter_mc != mcParticleCol->end(); iter_mc++) {
202 <<
" particleId = " << (*iter_mc)->particleProperty()
204 pG = (*iter_mc)->initialFourMomentum();
205 posG = (*iter_mc)->initialPosition().v();
215 SmartDataPtr<EmcMcHitCol> emcMcHitCol(eventSvc(),
"/Event/MC/EmcMcHitCol");
217 log << MSG::WARNING <<
"Could not find EMC truth" << endreq;
221 unsigned int mcTrackIndex;
222 double mcPosX=0,mcPosY=0,mcPosZ=0;
223 double mcPx=0,mcPy=0,mcPz=0;
226 EmcMcHitCol::iterator iterMc;
227 for(iterMc=emcMcHitCol->begin();iterMc!=emcMcHitCol->end();iterMc++){
228 mcId=(*iterMc)->identify();
229 mcTrackIndex=(*iterMc)->getTrackIndex();
230 mcPosX=(*iterMc)->getPositionX();
231 mcPosY=(*iterMc)->getPositionY();
232 mcPosZ=(*iterMc)->getPositionZ();
233 mcPx=(*iterMc)->getPx();
234 mcPy=(*iterMc)->getPy();
235 mcPz=(*iterMc)->getPz();
236 mcEnergy=(*iterMc)->getDepositEnergy();
259 StatusCode sc = service(
"EmcCalibConstSvc", emcCalibConstSvc);
260 if(sc != StatusCode::SUCCESS) {
265 SmartDataPtr<EmcDigiCol> emcDigiCol(eventSvc(),
"/Event/Digi/EmcDigiCol");
267 log << MSG::FATAL <<
"Could not find EMC digi" << endreq;
268 return( StatusCode::FAILURE);
271 EmcDigiCol::iterator iter3;
272 for (iter3=emcDigiCol->begin();iter3!= emcDigiCol->end();iter3++) {
275 (*iter3)->getChargeChannel());
283 int index = emcCalibConstSvc->
getIndex(nnpart,nnthe,nnphi);
287 if(run>0&&ixtalNumber>0) {
288 unsigned int npartNew=emcCalibConstSvc->
getPartID(ixtalNumber);
289 unsigned int ntheNew=emcCalibConstSvc->
getThetaIndex(ixtalNumber);
290 unsigned int nphiNew=emcCalibConstSvc->
getPhiIndex(ixtalNumber);
350 if (run>=52940&&run<=52995){
351 unsigned int ntheNew,nphiNew;
356 if (nnphi==58) nphiNew=60;
357 if (nnphi==59) nphiNew=61;
358 if (nnphi==60) nphiNew=58;
359 if (nnphi==61) nphiNew=59;
363 if (nnphi==58) nphiNew=60;
364 if (nnphi==59) nphiNew=61;
365 if (nnphi==60) nphiNew=58;
366 if (nnphi==61) nphiNew=59;
370 if (nnphi==73) nphiNew=75;
371 if (nnphi==74) nphiNew=76;
372 if (nnphi==75) nphiNew=73;
373 if (nnphi==76) nphiNew=74;
378 if (nnphi==73) nphiNew=75;
379 if (nnphi==74) nphiNew=76;
380 if (nnphi==75) nphiNew=73;
381 if (nnphi==76) nphiNew=74;
384 if (nnthe==3&&nnphi==72){
388 if (nnthe==2&&nnphi==77){
394 if (nnphi==87) nphiNew=90;
395 if (nnphi==88) nphiNew=91;
396 if (nnphi==89) nphiNew=92;
397 if (nnphi==90) nphiNew=87;
398 if (nnphi==91) nphiNew=88;
399 if (nnphi==92) nphiNew=89;
403 if (nnphi==87) nphiNew=90;
404 if (nnphi==88) nphiNew=91;
405 if (nnphi==89) nphiNew=92;
406 if (nnphi==90) nphiNew=87;
407 if (nnphi==91) nphiNew=88;
408 if (nnphi==92) nphiNew=89;
422 if (ixtalNumber==-9) {
427 if (ixtalNumber==-99) {
432 aDigit.
Assign(
id,adc,tdc);
433 fDigitMap[id]=aDigit;
437 RecEmcDigitMap::iterator iDigitMap;
438 for(iDigitMap=fDigitMap.begin();
439 iDigitMap!=fDigitMap.end();
448 fDigit2Hit.
Convert(fDigitMap,fHitMap);
450 RecEmcHitMap::iterator iHitMap;
451 for(iHitMap=fHitMap.begin();
452 iHitMap!=fHitMap.end();
456 fDigit2Hit.
Output(fHitMap);
461 fHit2Cluster.
Convert(fHitMap,fClusterMap);
464 RecEmcClusterMap::iterator iClusterMap;
465 for(iClusterMap=fClusterMap.begin();
466 iClusterMap!=fClusterMap.end();
473 fCluster2Shower->
Convert(fClusterMap,fShowerMap);
476 RecEmcShowerMap::iterator iShowerMap;
477 for(iShowerMap=fShowerMap.begin();
478 iShowerMap!=fShowerMap.end();
500 ndigi=fDigitMap.size();
502 ncluster=fClusterMap.size();
504 RecEmcShowerMap::iterator iShowerMap;
505 for(iShowerMap=fShowerMap.begin();
506 iShowerMap!=fShowerMap.end();
508 fShowerVec.push_back(iShowerMap->second);
510 sort(fShowerVec.begin(), fShowerVec.end(), greater<RecEmcShower>());
511 nneu=fShowerMap.size();
515 RecEmcShowerVec::iterator iShowerVec;
516 iShowerVec=fShowerVec.begin();
520 if(iShowerVec!=fShowerVec.end()) {
530 theta1=(aShower.
position()-posG).theta();
531 phi1=(aShower.
position()-posG).phi();
540 eseed=aShower.
eSeed();
553 enseed=fHitMap[nseed].getEnergy();
559 if(dphi1<-
pi) dphi1=dphi1+twopi;
560 if(dphi1>
pi) dphi1=dphi1-twopi;
563 if(iShowerVec!=fShowerVec.end()) {
565 if(iShowerVec!=fShowerVec.end()) {
575 if(fShowerVec.size()>=2) {
576 RecEmcShowerVec::iterator iShowerVec1,iShowerVec2;
577 iShowerVec1=fShowerVec.begin();
578 iShowerVec2=fShowerVec.begin()+1;
579 double e1=(*iShowerVec1).energy();
580 double e2=(*iShowerVec2).energy();
581 double angle=(*iShowerVec1).position().angle((*iShowerVec2).position());
582 mpi0=sqrt(2*e1*e2*(1-
cos(angle)));
589 return StatusCode::SUCCESS;
595 if(fCluster2Shower)
delete fCluster2Shower;
597 MsgStream log(
msgSvc(), name());
598 log << MSG::INFO <<
"in finalize()" << endreq;
599 return StatusCode::SUCCESS;
double cos(const BesAngle a)
vector< RecEmcShower > RecEmcShowerVec
HepPoint3D position() const
double secondMoment() const
static Identifier crystal_id(const unsigned int barrel_ec, const unsigned int theta_module, const unsigned int phi_module)
For a single crystal.
static unsigned int barrel_ec(const Identifier &id)
Values of different levels (failure returns 0)
static unsigned int theta_module(const Identifier &id)
static unsigned int phi_module(const Identifier &id)
virtual void Convert(RecEmcClusterMap &aClusterMap, RecEmcShowerMap &aShowerMap)=0
void Convert(const RecEmcDigitMap &aDigitMap, RecEmcHitMap &aHitMap)
void Output(const RecEmcHitMap &aHitMap) const
void SetAlgName(const string &name)
void Convert(const RecEmcHitMap &aHitMap, RecEmcClusterMap &aClusterMap)
void SetDigiCalib(bool digi)
void SetPositionMode(std::vector< std::string > &mode)
static EmcRecParameter & GetInstance()
void SetTimeMin(double min)
void SetPosCorr(double en)
void SetElecSaturation(int IO)
void SetTimeMax(double max)
void SetDataMode(double en)
void SetMethodMode(double en)
StatusCode RegisterToTDS(RecEmcHitMap &aHitMap, RecEmcClusterMap &aClusterMap, RecEmcShowerMap &aShowerMap)
StatusCode CheckRegister()
EmcRec(const std::string &name, ISvcLocator *pSvcLocator)
virtual unsigned int getPartID(int Index) const =0
virtual int getIxtalNumber(int No) const =0
virtual unsigned int getPhiIndex(int Index) const =0
virtual unsigned int getThetaIndex(int Index) const =0
virtual int getIndex(unsigned int PartId, unsigned int ThetaIndex, unsigned int PhiIndex) const =0
virtual bool isOnlineMode()=0
bool is_valid() const
Check if id is in a valid state.
static double EmcTime(int timeChannel)
static double EmcCharge(int measure, int chargeChannel)
double getSecondMoment() const
void Assign(const RecEmcID &CellId, const RecEmcADC &ADC, const RecEmcTDC &TDC)
RecEmcID getShowerId() const
RecEmcCluster * getCluster() const
RecEmcEnergy getETof2x1() const
RecEmcID NearestSeed() const
RecEmcEnergy getETof2x3() const