1#include "CgemDigitizerSvc/CgemDigitizerSvc.h"
2#include "GaudiKernel/Kernel.h"
3#include "GaudiKernel/IInterface.h"
4#include "GaudiKernel/StatusCode.h"
5#include "GaudiKernel/SvcFactory.h"
6#include "GaudiKernel/IJobOptionsSvc.h"
7#include "GaudiKernel/MsgStream.h"
8#include "GaudiKernel/PropertyMgr.h"
9#include "GaudiKernel/IIncidentSvc.h"
10#include "GaudiKernel/Incident.h"
11#include "GaudiKernel/IIncidentListener.h"
12#include "GaudiKernel/INTupleSvc.h"
13#include "GaudiKernel/NTuple.h"
15#include "GaudiKernel/ISvcLocator.h"
16#include "GaudiKernel/Bootstrap.h"
18#include "GaudiKernel/IDataProviderSvc.h"
19#include "GaudiKernel/SmartDataPtr.h"
20#include "GaudiKernel/DataSvc.h"
22#include "CalibData/CalibModel.h"
25#include "EventModel/EventHeader.h"
26#include "GaudiKernel/SmartDataPtr.h"
39 declareProperty(
"IonizationModel", m_ionModel);
40 declareProperty(
"DriftAvalancheModel", m_driftAvaModel);
41 declareProperty(
"InductionModel", m_inductionModel);
42 declareProperty(
"GarfieldDebugging", m_garfDebugging);
43 declareProperty(
"InductionDebugging", m_debugInduction);
44 declareProperty(
"MagConfig", m_magConfig);
52 if( IID_ICgemDigitizerSvc.versionMatch(riid) ){
55 return Service::queryInterface(riid, ppvInterface);
57 return StatusCode::SUCCESS;
61 MsgStream log(messageService(), name());
62 log << MSG::INFO <<
"CgemDigitizerSvc::initialize()" << endreq;
64 StatusCode sc = Service::initialize();
65 if( sc.isFailure() )
return sc;
67 static IJobOptionsSvc* jobSvc = 0;
69 sc = service(
"JobOptionsSvc", jobSvc);
70 if ( sc.isFailure() ) {
71 std::cout <<
"Can't get the JobOptionsSvc @ DistBoss::GetPropertyValue()" << std::endl;
77 const vector<const Property*>* properties = jobSvc->getProperties(
"BesRndmGenSvc");
79 if ( properties == NULL ) {
80 std::cout <<
"In CgemDigitizerSvc::initialize(), can't get client: " << std::endl;
81 return StatusCode::FAILURE;
84 unsigned int randSeed;
85 for (
unsigned int i = 0; i < properties->size(); ++i ) {
86 if ( properties->at(i)->name() ==
"RndmSeed" ) {
87 cout <<
"name of property: " << properties->at(i)->name() << endl;
88 string strRnd = properties->at(i)->toString();
89 sscanf(strRnd.c_str(),
"%u", &randSeed);
90 cout <<
"random seed from jobOption: " << randSeed << endl;
95 sc = service(
"CgemGeomSvc", m_geomSvc);
96 if(sc != StatusCode::SUCCESS)
98 log << MSG::ERROR <<
"can not use CgemGeomSvc" << endreq;
99 return StatusCode::FAILURE;
102 gRandom->SetSeed(randSeed);
104 cout <<
"ionModel = " << m_ionModel << endl;
107 }
else if(2 == m_ionModel){
111 m_pIon->
init(randSeed, m_geomSvc, m_magConfig);
114 if(1 == m_driftAvaModel){
116 }
else if(2 == m_driftAvaModel){
119 m_pDriftAndAva->
init(m_geomSvc, m_magConfig);
121 if(1 == m_inductionModel){
123 }
else if(2 == m_inductionModel){
126 m_pInduction->
init(m_geomSvc, m_magConfig);
131 Gaudi::svcLocator() -> service(
"NTupleSvc",
ntupleSvc);
132 NTuplePtr nt(
ntupleSvc,
"CgemDigitizerSvcNT/digi");
136 m_tuple =
ntupleSvc->book(
"CgemDigitizerSvcNT/digi", CLID_ColumnWiseTuple,
"noise");
138 m_tuple->addItem(
"nIonE", m_ntNIonE);
139 m_tuple->addItem(
"nMultiE", m_ntNMultiE);
140 m_tuple->addItem(
"nXstrips", m_ntNxstrips,0,100);
141 m_tuple->addItem(
"nVstrips", m_ntNvstrips,0,100);
142 m_tuple->addIndexedItem(
"XstripQ", m_ntNxstrips,m_ntxstripQ);
143 m_tuple->addIndexedItem(
"XstripT", m_ntNxstrips,m_ntxstripT);
144 m_tuple->addIndexedItem(
"VstripQ", m_ntNvstrips,m_ntvstripQ);
145 m_tuple->addIndexedItem(
"VstripT", m_ntNvstrips,m_ntvstripT);
146 m_tuple->addIndexedItem(
"XstripID", m_ntNxstrips,m_XstripID);
147 m_tuple->addIndexedItem(
"VstripID", m_ntNvstrips,m_VstripID);
151 return StatusCode::SUCCESS;
155 MsgStream log(messageService(), name());
156 log << MSG::INFO <<
"CgemDigitizerSvc::finalize()" << endreq;
158 delete m_pDriftAndAva;
161 return StatusCode::SUCCESS;
166 double time_spent = 0.;
167 clock_t begin = clock();
172 m_pIon->
setTrack(particle, charge, p, trkPosIn, trkPosOut);
174 vector<double> ionEx;
175 vector<double> ionEy;
176 vector<double> ionEz;
177 vector<double> ionEt;
179 for(
int i=0; i<nIonE; i++){
180 ionEx.push_back(m_pIon->
getEx(i));
181 ionEy.push_back(m_pIon->
getEy(i));
182 ionEz.push_back(m_pIon->
getEz(i));
183 ionEt.push_back(m_pIon->
getEt(i));
185 clock_t end = clock();
186 time_spent += (double)(end - begin) / CLOCKS_PER_SEC;
192 m_pDriftAndAva->
setIonElectrons(layer, nIonE, ionEx, ionEy, ionEz, ionEt);
195 for(
int i=0; i<m_nMultiE; i++){
196 double x = m_pDriftAndAva->
getX(i);
197 double y = m_pDriftAndAva->
getY(i);
198 double z = m_pDriftAndAva->
getZ(i);
199 double t = m_pDriftAndAva->
getT(i);
200 m_multiEx.push_back(
x);
201 m_multiEy.push_back(y);
202 m_multiEz.push_back(z);
203 m_multiEt.push_back(
t);
206 time_spent += (double)(end - begin) / CLOCKS_PER_SEC;
215 m_pInduction->
setMultiElectrons(layer, m_nMultiE, m_multiEx, m_multiEy, m_multiEz, m_multiEt);
217 for(
int i=0; i<m_nXstrips; i++){
219 m_xstripID.push_back(m_pInduction->
getXstripID(i));
220 m_xstripQ.push_back(m_pInduction->
getXstripQ(i));
221 m_xstripT.push_back(m_pInduction->
getXstripT(i));
224 for(
int i=0; i<m_nVstrips; i++){
226 m_vstripID.push_back(m_pInduction->
getVstripID(i));
227 m_vstripQ.push_back(m_pInduction->
getVstripQ(i));
228 m_vstripT.push_back(m_pInduction->
getVstripT(i));
231 time_spent += (double)(end - begin) / CLOCKS_PER_SEC;
244 time_spent += (double)(end - begin) / CLOCKS_PER_SEC;
248 return StatusCode::SUCCESS;
251void CgemDigitizerSvc::positionToStrips(){
257 TObjArray* hlist =
new TObjArray(0);
259 for(
int i=0; i<m_nMultiE; i++){
263 double phi = atan2(m_multiEy[i], m_multiEx[i]);
264 double z = m_multiEz[i];
265 G4ThreeVector pos(m_multiEx[i], m_multiEy[i], z);
267 for(
int j=0; j<m_nSheet; j++)
281 if(xID>=0&&distX<distV) {
286 map<int, int>::iterator it = m_mapQ[j][iView].find(ID);
287 if(it==m_mapQ[j][iView].end())
289 m_mapQ[j][iView][ID]=1;
290 m_mapT[j][iView][ID]=m_multiEt[i];
293 int Q = (it->second) +1;
294 m_mapQ[j][iView][ID]=Q;
295 if(m_multiEt[i] < m_mapT[j][iView][ID]) m_mapT[j][iView][ID] = m_multiEt[i];
298 sprintf(hname,
"time%d_%d_%d", j, iView, ID);
299 TH1F* hist = (TH1F*)hlist->FindObject(hname);
301 hist =
new TH1F(hname,
"", 1000, 0, 1000);
304 hist->Fill(m_multiEt[i]);
310 m_nXstrips = m_mapQ[0][0].size() + m_mapQ[1][0].size();
311 m_nVstrips = m_mapQ[0][1].size() + m_mapQ[1][1].size();
314 int nhist = hlist->GetEntries();
317 for(
int i=0; i<nhist; i++){
321 hist = (TH1F*)hlist->First();
323 hist = (TH1F*)hlist->After(hlast);
326 const char* histname = hist->GetName();
327 int iSheet, iView, ID;
328 sscanf(histname,
"%*4s%1d%*1s%1d%*1s%d", &iSheet, &iView, &ID);
331 m_xstripSheet.push_back(iSheet);
332 m_xstripID.push_back(ID);
333 m_xstripQ.push_back(m_mapQ[iSheet][iView][ID]);
334 m_xstripT.push_back(m_mapT[iSheet][iView][ID]);
336 m_vstripSheet.push_back(iSheet);
337 m_vstripID.push_back(ID);
338 m_vstripQ.push_back(m_mapQ[iSheet][iView][ID]);
339 m_vstripT.push_back(m_mapT[iSheet][iView][ID]);
343 for(
int i=0; i<nhist; i++){
344 TH1F* hist = (TH1F*)hlist->Last();
352void CgemDigitizerSvc::clear(){
355 m_xstripSheet.clear();
357 m_vstripSheet.clear();
370 for(
int i=0; i<2; i++){
371 for(
int k=0; k<2; k++){
372 m_mapQ[i][k].clear();
373 m_mapT[i][k].clear();
virtual StatusCode finalize()
CgemDigitizerSvc(const std::string &name, ISvcLocator *svcloc)
virtual StatusCode initialize()
StatusCode setTrack(int layer, int particle, int charge, double p, double trkPosIn[], double trkPosOut[])
virtual StatusCode queryInterface(const InterfaceID &riid, void **ppvUnknown)
int getNumberOfSheet() const
int getClosestXStripID(double phi, double &dist)
bool OnThePlane(double phi, double z) const
int getClosestVStripID(G4ThreeVector pos, double &dist) const
virtual double getX(int n) const =0
virtual double getY(int n) const =0
virtual void setIonElectrons(int layer, int nElectrons, std::vector< double > x, std::vector< double > y, std::vector< double > z, std::vector< double > t)=0
virtual void init(ICgemGeomSvc *geomSvc, double magConfig)=0
virtual double getZ(int n) const =0
virtual double getT(int n) const =0
virtual int getNelectrons() const =0
virtual CgemGeoReadoutPlane * getReadoutPlane(int iLayer, int iSheet) const =0
virtual CgemGeoLayer * getCgemLayer(int i) const =0
virtual double getXstripT(int n) const =0
virtual int getNVstrips() const =0
virtual int getVstripSheet(int n) const =0
virtual int getXstripID(int n) const =0
virtual int getVstripID(int n) const =0
virtual double getVstripQ(int n) const =0
virtual int getXstripSheet(int n) const =0
virtual double getXstripQ(int n) const =0
virtual void setDebugOutput(bool debugOutput)=0
virtual void setMultiElectrons(int layer, int nElectrons, std::vector< double > x, std::vector< double > y, std::vector< double > z, std::vector< double > t)=0
virtual void init(ICgemGeomSvc *geomSvc, double magConfig)=0
virtual double getVstripT(int n) const =0
virtual int getNXstrips() const =0
virtual double getEx(int nElec)=0
virtual int getNumberIonE()=0
virtual double getEy(int nElec)=0
virtual void setDebugging(bool debugging)=0
virtual double getEt(int nElec)=0
virtual double getEz(int nElec)=0
virtual void setTrack(int particle, int charge, double p, double trkPosIn[], double trkPosOut[])=0
virtual void init(unsigned int random, ICgemGeomSvc *geomSvc, double magConfig)=0