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"
10#include "EventModel/EventHeader.h"
11#include "EmcRawEvent/EmcDigi.h"
12#include "EmcRecEventModel/RecEmcEventModel.h"
13#include "McTruth/McParticle.h"
14#include "McTruth/EmcMcHit.h"
15#include "RawEvent/RawDataUtil.h"
17#include "EmcRec/EmcRec.h"
18#include "EmcRecGeoSvc/EmcRecGeoSvc.h"
19#include "EmcRec/EmcRecParameter.h"
20#include "EmcRec/EmcRecFastCluster2Shower.h"
21#include "EmcRec/EmcRecCluster2Shower.h"
22#include "EmcRec/EmcRecTofMatch.h"
23#include "EmcRec/EmcRecTofDigitCalib.h"
25#include "EmcRec/EmcRecTDS.h"
26#include "RawDataProviderSvc/RawDataProviderSvc.h"
27#include "RawDataProviderSvc/EmcRawDataProvider.h"
29#include "GaudiKernel/Service.h"
30#include "GaudiKernel/ThreadGaudi.h"
38 Algorithm(name, pSvcLocator),fCluster2Shower(0)
41 fPositionMode.push_back(
"log");
42 fPositionMode.push_back(
"5x5");
44 m_propMgr.declareProperty(
"Output",fOutput=0);
45 m_propMgr.declareProperty(
"EventNb",fEventNb=0);
46 m_propMgr.declareProperty(
"DigiCalib",fDigiCalib=
false);
47 m_propMgr.declareProperty(
"TofEnergy",fTofEnergy=
false);
48 m_propMgr.declareProperty(
"OnlineMode",fOnlineMode=
false);
49 m_propMgr.declareProperty(
"TimeMin",fTimeMin=0);
50 m_propMgr.declareProperty(
"TimeMax",fTimeMax=60);
51 m_propMgr.declareProperty(
"PositionMode",fPositionMode);
55 m_propMgr.declareProperty(
"MethodMode",fMethodMode=0);
57 m_propMgr.declareProperty(
"PosCorr",fPosCorr=1);
58 m_propMgr.declareProperty(
"ElecSaturation",fElecSaturation=1);
60 IJobOptionsSvc* jobSvc;
61 pSvcLocator->service(
"JobOptionsSvc", jobSvc);
62 jobSvc->setMyProperties(
"EmcRecAlg", &m_propMgr);
82 MsgStream log(
msgSvc(), name());
83 log << MSG::INFO <<
"in initialize()" << endreq;
87 std::string rawDataProviderSvc_name(
"RawDataProviderSvc");
88 StatusCode sc = service(rawDataProviderSvc_name.c_str(), m_rawDataProviderSvc);
89 if(sc != StatusCode::SUCCESS) {
90 log << MSG::ERROR <<
"EmcRec Error: Can't get RawDataProviderSvc." << endmsg;
102 if ( nt ) m_tuple = nt;
104 m_tuple=
ntupleSvc()->book(
"FILE301/n1",CLID_ColumnWiseTuple,
"EmcRec");
106 status = m_tuple->addItem (
"pid",pid);
107 status = m_tuple->addItem (
"tp",tp);
108 status = m_tuple->addItem (
"ttheta",ttheta);
109 status = m_tuple->addItem (
"tphi",tphi);
110 status = m_tuple->addItem (
"nrun",nrun);
111 status = m_tuple->addItem (
"nrec",nrec);
112 status = m_tuple->addItem (
"nneu",nneu);
113 status = m_tuple->addItem (
"ncluster",ncluster);
114 status = m_tuple->addItem (
"npart",npart);
115 status = m_tuple->addItem (
"ntheta",ntheta);
116 status = m_tuple->addItem (
"nphi",nphi);
117 status = m_tuple->addItem (
"ndigi",ndigi);
118 status = m_tuple->addItem (
"nhit",nhit);
119 status = m_tuple->addItem (
"pp1",4,pp1);
120 status = m_tuple->addItem (
"theta1",theta1);
121 status = m_tuple->addItem (
"phi1",phi1);
122 status = m_tuple->addItem (
"dphi1",dphi1);
123 status = m_tuple->addItem (
"eseed",eseed);
124 status = m_tuple->addItem (
"e3x3",e3x3);
125 status = m_tuple->addItem (
"e5x5",e5x5);
126 status = m_tuple->addItem (
"enseed",enseed);
127 status = m_tuple->addItem (
"etof2x1",etof2x1);
128 status = m_tuple->addItem (
"etof2x3",etof2x3);
129 status = m_tuple->addItem (
"cluster2ndMoment",cluster2ndMoment);
130 status = m_tuple->addItem (
"secondMoment",secondMoment);
131 status = m_tuple->addItem (
"latMoment",latMoment);
132 status = m_tuple->addItem (
"a20Moment",a20Moment);
133 status = m_tuple->addItem (
"a42Moment",a42Moment);
134 status = m_tuple->addItem (
"mpi0",mpi0);
135 status = m_tuple->addItem (
"thtgap1",thtgap1);
136 status = m_tuple->addItem (
"phigap1",phigap1);
137 status = m_tuple->addItem (
"pp2",4,pp2);
140 log << MSG::ERROR <<
"Cannot book N-tuple:" << long(m_tuple) << endmsg;
141 return StatusCode::FAILURE;
153 return StatusCode::SUCCESS;
159 MsgStream log(
msgSvc(), name());
160 log << MSG::DEBUG <<
"in execute()" << endreq;
165 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),
"/Event/EventHeader");
167 log << MSG::FATAL <<name() <<
" Could not find Event Header" << endreq;
168 return( StatusCode::FAILURE);
170 run=eventHeader->runNumber();
171 event=eventHeader->eventNumber();
178 if(fEventNb!=0&&m_event%fEventNb==0) {
179 log << MSG::FATAL <<m_event<<
"-------: "<<run<<
","<<
event<<endreq;
183 log << MSG::DEBUG <<
"===================================="<<endreq;
184 log << MSG::DEBUG <<
"run= "<<run<<
"; event= "<<
event<<endreq;
190 if(fOutput>=1&&run<0) {
192 SmartDataPtr<McParticleCol> mcParticleCol(eventSvc(),
"/Event/MC/McParticleCol");
193 if (!mcParticleCol) {
194 log << MSG::WARNING <<
"Could not find McParticle" << endreq;
197 McParticleCol::iterator iter_mc = mcParticleCol->begin();
198 for (;iter_mc != mcParticleCol->end(); iter_mc++) {
200 <<
" particleId = " << (*iter_mc)->particleProperty()
202 pG = (*iter_mc)->initialFourMomentum();
203 posG = (*iter_mc)->initialPosition().v();
213 SmartDataPtr<EmcMcHitCol> emcMcHitCol(eventSvc(),
"/Event/MC/EmcMcHitCol");
215 log << MSG::WARNING <<
"Could not find EMC truth" << endreq;
219 unsigned int mcTrackIndex;
220 double mcPosX=0,mcPosY=0,mcPosZ=0;
221 double mcPx=0,mcPy=0,mcPz=0;
224 EmcMcHitCol::iterator iterMc;
225 for(iterMc=emcMcHitCol->begin();iterMc!=emcMcHitCol->end();iterMc++){
226 mcId=(*iterMc)->identify();
227 mcTrackIndex=(*iterMc)->getTrackIndex();
228 mcPosX=(*iterMc)->getPositionX();
229 mcPosY=(*iterMc)->getPositionY();
230 mcPosZ=(*iterMc)->getPositionZ();
231 mcPx=(*iterMc)->getPx();
232 mcPy=(*iterMc)->getPy();
233 mcPz=(*iterMc)->getPz();
234 mcEnergy=(*iterMc)->getDepositEnergy();
257 StatusCode sc = service(
"EmcCalibConstSvc", emcCalibConstSvc);
258 if(sc != StatusCode::SUCCESS) {
263 SmartDataPtr<EmcDigiCol> emcDigiCol(eventSvc(),
"/Event/Digi/EmcDigiCol");
265 log << MSG::FATAL <<
"Could not find EMC digi" << endreq;
266 return( StatusCode::FAILURE);
269 EmcDigiCol::iterator iter3;
270 for (iter3=emcDigiCol->begin();iter3!= emcDigiCol->end();iter3++) {
273 (*iter3)->getChargeChannel());
281 int index = emcCalibConstSvc->
getIndex(nnpart,nnthe,nnphi);
285 if(run>0&&ixtalNumber>0) {
286 unsigned int npartNew=emcCalibConstSvc->
getPartID(ixtalNumber);
287 unsigned int ntheNew=emcCalibConstSvc->
getThetaIndex(ixtalNumber);
288 unsigned int nphiNew=emcCalibConstSvc->
getPhiIndex(ixtalNumber);
293 if (ixtalNumber==-9) {
298 if (ixtalNumber==-99) {
303 aDigit.
Assign(
id,adc,tdc);
304 fDigitMap[id]=aDigit;
308 RecEmcDigitMap::iterator iDigitMap;
309 for(iDigitMap=fDigitMap.begin();
310 iDigitMap!=fDigitMap.end();
319 fDigit2Hit.
Convert(fDigitMap,fHitMap);
321 RecEmcHitMap::iterator iHitMap;
322 for(iHitMap=fHitMap.begin();
323 iHitMap!=fHitMap.end();
327 fDigit2Hit.
Output(fHitMap);
332 fHit2Cluster.
Convert(fHitMap,fClusterMap);
335 RecEmcClusterMap::iterator iClusterMap;
336 for(iClusterMap=fClusterMap.begin();
337 iClusterMap!=fClusterMap.end();
344 fCluster2Shower->
Convert(fClusterMap,fShowerMap);
347 RecEmcShowerMap::iterator iShowerMap;
348 for(iShowerMap=fShowerMap.begin();
349 iShowerMap!=fShowerMap.end();
371 ndigi=fDigitMap.size();
373 ncluster=fClusterMap.size();
375 RecEmcShowerMap::iterator iShowerMap;
376 for(iShowerMap=fShowerMap.begin();
377 iShowerMap!=fShowerMap.end();
379 fShowerVec.push_back(iShowerMap->second);
381 sort(fShowerVec.begin(), fShowerVec.end(), greater<RecEmcShower>());
382 nneu=fShowerMap.size();
386 RecEmcShowerVec::iterator iShowerVec;
387 iShowerVec=fShowerVec.begin();
391 if(iShowerVec!=fShowerVec.end()) {
401 theta1=(aShower.
position()-posG).theta();
402 phi1=(aShower.
position()-posG).phi();
411 eseed=aShower.
eSeed();
424 enseed=fHitMap[nseed].getEnergy();
430 if(dphi1<-
pi) dphi1=dphi1+twopi;
431 if(dphi1>
pi) dphi1=dphi1-twopi;
434 if(iShowerVec!=fShowerVec.end()) {
436 if(iShowerVec!=fShowerVec.end()) {
446 if(fShowerVec.size()>=2) {
447 RecEmcShowerVec::iterator iShowerVec1,iShowerVec2;
448 iShowerVec1=fShowerVec.begin();
449 iShowerVec2=fShowerVec.begin()+1;
450 double e1=(*iShowerVec1).energy();
451 double e2=(*iShowerVec2).energy();
452 double angle=(*iShowerVec1).position().angle((*iShowerVec2).position());
453 mpi0=sqrt(2*
e1*
e2*(1-
cos(angle)));
460 return StatusCode::SUCCESS;
466 if(fCluster2Shower)
delete fCluster2Shower;
468 MsgStream log(
msgSvc(), name());
469 log << MSG::INFO <<
"in finalize()" << endreq;
470 return StatusCode::SUCCESS;
vector< RecEmcShower > RecEmcShowerVec
double cos(const BesAngle a)
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