CGEM BOSS 6.6.5.g
BESIII Offline Software System
Loading...
Searching...
No Matches
EFGlobalEnergy.cxx
Go to the documentation of this file.
1#include <cmath>
2#include "GaudiKernel/MsgStream.h"
3//#include "GaudiKernel/AlgFactory.h"
4#include "GaudiKernel/SmartDataPtr.h"
5//#include "GaudiKernel/PropertyMgr.h"
6#include "EventModel/Event.h"
10#include "Identifier/EmcID.h"
13
14using namespace Event;
15
16EFGlobalEnergy::EFGlobalEnergy(const std::string& name, ISvcLocator* pSvcLocator) :
17 IEFAlgorithm(name, pSvcLocator) {
18 //declareProperty("OutputLevel",m_output = MSG::NIL);
19 int output=(m_output%100000)/10000;
20 MsgStream log(msgSvc(), name);
21 msgSvc()->setOutputLevel(name,output);
22 m_etot = new CriteriaItemValue;
23 m_ebar = new CriteriaItemValue;
24 m_eend = new CriteriaItemValue;
25 m_ebal = new CriteriaItemValue;
26}
27
29 delete m_etot;
30 delete m_ebar;
31 delete m_eend;
32 delete m_ebal;
33}
34
36
37 MsgStream log(msgSvc(), name());
38 log << MSG::INFO << "in initialize()" << endreq;
39
41
42 StatusCode sc;
43 sc = m_HltStoreSvc->put("etot", m_etot);
44 if ( sc.isFailure() ) {
45 log << MSG::ERROR << "m_HltStoreSvc->put(etot) wrong" << endreq;
46 return sc;
47 }
48 sc = m_HltStoreSvc->put("ebar", m_ebar);
49 if ( sc.isFailure() ) {
50 log << MSG::ERROR << "m_HltStoreSvc->put(ebar) wrong" << endreq;
51 return sc;
52 }
53 sc = m_HltStoreSvc->put("eend", m_eend);
54 if ( sc.isFailure() ) {
55 log << MSG::ERROR << "m_HltStoreSvc->put(eend) wrong" << endreq;
56 return sc;
57 }
58 sc = m_HltStoreSvc->put("ebal", m_ebal);
59 if ( sc.isFailure() ) {
60 log << MSG::ERROR << "m_HltStoreSvc->put(ebal) wrong" << endreq;
61 return sc;
62 }
63
64 sc = service("EmcCalibConstSvc", m_emcCalibConstSvc);
65 if(sc != StatusCode::SUCCESS) {
66 log << MSG::ERROR << "Can't get EmcCalibConstSvc." << endreq;
67 m_emcCalibConstSvc=0;
68 }
69
70 if(m_rawDigiSvc){
72 char cbeam[20];
73 sprintf(cbeam,"%f", m_beam);
74 setenv("BEPCII_INFO.BER_PRB",cbeam,0);
75 setenv("BEPCII_INFO.BPR_PRB",cbeam,0);
76 }
77 }
78 return sc;
79}
80
82
83 //cout<<"m_run="<<m_run<<endl;
84 //reset();
85
86 MsgStream log(msgSvc(), name());
87 //DataObject* pObject;
88 float e1=0,e2=0;
89 char* electron=getenv("BEPCII_INFO.BER_PRB");
90 if(electron){
91 e1=atof(electron);
92 }
93 else{
94 log << MSG::ERROR << "Cannot get beam energy (e-)! Please call online people" << endreq;
95 }
96 char* positron=getenv("BEPCII_INFO.BPR_PRB");
97 if(positron){
98 e2=atof(positron);
99 }
100 else{
101 log << MSG::ERROR << "Cannot get beam energy (e+)! Please call online people" << endreq;
102 }
103 if(e1>0.1&&e2>0.1&&m_beam>0) {
104 m_beam = 0.5*(e1+e2);
105 }
106 else{
107
108 }
109 log << MSG::INFO << "beam energy = " << m_beam << endreq;
110
111 // Part 1: Get the event header, print out event and run number
112 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),"/Event/EventHeader");
113 if (!eventHeader) {
114 log << MSG::FATAL << "Could not find Event Header" << endreq;
115 return( StatusCode::FAILURE);
116 }
117
118 //Part 2: Retrieve Hits Collection
119 //vector<EmcDigi*>* emcDigiCol=0;
120 bool calFlag=false;
121 EmcDigiCol* emcDigiCol=0;
122 if(m_rawDigiSvc){
125 calFlag = true;
126 }
127 }
128 if(!emcDigiCol){
129 SmartDataPtr<EmcDigiCol> emcDigi(eventSvc(),"/Event/Digi/EmcDigiCol");
130 if (!emcDigi) {
131 log << MSG::FATAL << "Could not find Emc digi!!" << endreq;
132 return( StatusCode::FAILURE);
133 }
134 //emcDigiCol=dynamic_cast<vector<EmcDigi*>*> (&emcDigi);
135 emcDigiCol=emcDigi;
136 }
137 //Part 3:Calculate total deposited energy and energy balance
138 Identifier id;
139 double adc,etot=0.,ebarrel=0.,eendcap=0.;
140 double energyx=0.,energyy=0.,energyz=0.;
141 double ebalance;
142 unsigned int idBarrel_Endcap,itheta,iphi;
143 double ewest=0.,eeast=0.;
144 //double tdc;
145
146 EmcDigiCol::iterator iterEMC=emcDigiCol->begin();
147 while(iterEMC!= emcDigiCol->end()) {
148 id=(*iterEMC)->identify();
149 idBarrel_Endcap=EmcID::barrel_ec(id);
150 itheta=EmcID::theta_module(id);
151 iphi=EmcID::phi_module(id);
152 adc=RawDataUtil::EmcCharge((*iterEMC)->getMeasure(),(*iterEMC)->getChargeChannel());
153 adc /= 1000. ; //Mev->GeV
154 if(!calFlag&&m_emcCalibConstSvc) {
155 int index = m_emcCalibConstSvc->getIndex(idBarrel_Endcap,itheta,iphi);
156 double adc2e = m_emcCalibConstSvc->getDigiCalibConst(index);
157 log << MSG::DEBUG << "adc= " << adc << " and calibration constant: " << adc2e << " at " << idBarrel_Endcap << " " << itheta << " " << iphi << endreq;
158 adc *= adc2e;
159 }
160 //tdc=(*iterEMC)->getTimeChannel(); !not used
161 etot += adc;
162 double theta=0,phi=0;
163 //Estimate hits position(theta,phi)
164 if(idBarrel_Endcap==1){
165 theta=(34.+112.*(itheta+0.5)/44.)/180.*3.1415926;
166 phi=(iphi+0.5)/120.*6.2831852;
167 ebarrel +=adc;
168 if(itheta<22) eeast+=adc;
169 else ewest+=adc;
170 }
171 else{
172 theta=(90.+(90.-(itheta+0.5)/6.*(34.-21.56)+21.56)*(idBarrel_Endcap-1))
173 /180.*3.1415926;
174 if(itheta==0||itheta==1)phi=(iphi+0.5)/64.*6.2831852;
175 if(itheta==2||itheta==3)phi=(iphi+0.5)/80.*6.2831852;
176 if(itheta==4||itheta==5)phi=(iphi+0.5)/96.*6.2831852;
177 eendcap +=adc;
178 if(idBarrel_Endcap==0) {
179 eeast+=adc;
180 }
181 else {
182 ewest+=adc;
183 }
184 }
185 energyx +=adc*sin(theta)*cos(phi);
186 energyy +=adc*sin(theta)*sin(phi);
187 energyz +=adc*cos(theta);
188 //log << MSG::DEBUG << "Energy:" << idBarrel_Endcap <<","<<itheta << "," << iphi
189 // << ":" << adc <<endreq;
190 iterEMC++;
191 }
192 if(etot>0)
193 ebalance=sqrt(energyx*energyx+energyy*energyy+energyz*energyz)/etot;
194 else
195 ebalance=0;
196
197 log << MSG::INFO << "etot=" << etot << "(" << etot/2./abs(m_beam) << "); ebarrel=" <<ebarrel
198 <<"; eendcap="<<eendcap <<"; ebalanece="<<ebalance<<endreq;
199
200 //Part 4: Put the criteria item(s) to HltStoreSvc here
201 m_etot->setValue(etot/2./abs(m_beam));
202 m_ebar->setValue(ebarrel/2./abs(m_beam));
203 m_eend->setValue(eendcap/2./abs(m_beam));
204 m_ebal->setValue(ebalance);
205
206 m_ef->appToEFVec(etot, 31);
207 m_ef->appToEFVec(ebalance,34);
208 m_ef->appToEFVec(ebarrel,32);
209 m_ef->appToEFVec(eendcap,33);
210 m_ef->appToEFVec(eeast,35);
211 m_ef->appToEFVec(ewest,36);
212 m_ef->setVecBit(true, 0, 1);
213 m_ef->addToEFVec(7<<16,1);
214 m_run=1;
215
216 return StatusCode::SUCCESS;
217}
218
220 MsgStream log(msgSvc(), name());
221 log << MSG::INFO << "in finalize()" << endmsg;
222 return StatusCode::SUCCESS;
223}
224
226
227 if(m_run) {
228 m_etot->reset();
229 m_ebar->reset();
230 m_eend->reset();
231 m_ebal->reset();
232 m_run=0;
233 }
234 return;
235}
double cbeam[56]
Definition: AbsCor.cxx:57
double sin(const BesAngle a)
Definition: BesAngle.h:210
double cos(const BesAngle a)
Definition: BesAngle.h:213
Double_t etot
Double_t e1
Double_t e2
@ electron
Definition: DstMdcDedx.h:9
ObjectVector< EmcDigi > EmcDigiCol
Definition: EmcDigi.h:43
double abs(const EvtComplex &c)
Definition: EvtComplex.hh:212
*******INTEGER m_nBinMax INTEGER m_NdiMax !No of bins in histogram for cell exploration division $ !Last vertex $ !Last active cell $ !Last cell in buffer $ !No of sampling when dividing cell $ !No of function total $ !Flag for random ceel for $ !Flag for type of for WtMax $ !Flag which decides whether vertices are included in the sampling $ entire domain is hyp !Maximum effective eevents per saves r n generator level $ !Flag for chat level in output
Definition: FoamA.h:89
IMessageSvc * msgSvc()
void setValue(float value)
StatusCode finalize()
virtual ~EFGlobalEnergy()
StatusCode execute()
EFGlobalEnergy(const std::string &name, ISvcLocator *pSvcLocator)
virtual StatusCode initialize()
bool addToEFVec(uint32_t val, uint32_t pos)
Definition: EFResult.cxx:81
bool appToEFVec(double val, uint32_t pos)
Definition: EFResult.cxx:68
bool setVecBit(uint32_t val, uint32_t vecpos, uint32_t bbegin, uint32_t bend)
Definition: EFResult.cxx:94
static unsigned int barrel_ec(const Identifier &id)
Values of different levels (failure returns 0)
Definition: EmcID.cxx:38
static unsigned int theta_module(const Identifier &id)
Definition: EmcID.cxx:43
static unsigned int phi_module(const Identifier &id)
Definition: EmcID.cxx:48
bool put(const std::string &name, const T &value)
Definition: HltStoreSvc.h:60
EFResult * m_ef
Definition: IEFAlgorithm.h:22
virtual StatusCode initialize()
IRawDataProviderSvc * m_rawDigiSvc
Definition: IEFAlgorithm.h:21
HltStoreSvc * m_HltStoreSvc
Definition: IEFAlgorithm.h:20
virtual double getDigiCalibConst(int No) const =0
virtual int getIndex(unsigned int PartId, unsigned int ThetaIndex, unsigned int PhiIndex) const =0
virtual EmcDigiCol & getEmcDigiVec(uint32_t control=0)=0
virtual bool isOnlineMode()=0
static double EmcCharge(int measure, int chargeChannel)
Definition: RawDataUtil.h:23
Definition: Event.h:21