CGEM BOSS 6.6.5.g
BESIII Offline Software System
Loading...
Searching...
No Matches
CgemDigitizerSvc.cxx
Go to the documentation of this file.
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"
14
15#include "GaudiKernel/ISvcLocator.h"
16#include "GaudiKernel/Bootstrap.h"
17
18#include "GaudiKernel/IDataProviderSvc.h"
19#include "GaudiKernel/SmartDataPtr.h"
20#include "GaudiKernel/DataSvc.h"
21
23// #include "CalibData/Cgem/CgemCalibData.h"
24// #include "CalibData/Cgem/CgemDataConst.h"
26#include "GaudiKernel/SmartDataPtr.h"
27
28#include <iomanip>
29#include <iostream>
30#include <fstream>
31#include <cmath>
32
33#include "TObjArray.h"
34#include "TSystem.h"
35
36using namespace std;
37
38CgemDigitizerSvc::CgemDigitizerSvc( const string& name, ISvcLocator* svcloc) :Service (name, svcloc){
39 // declare properties
40 declareProperty("IonizationModel", m_ionModel=1);
41 declareProperty("DriftAvalancheModel", m_driftAvaModel=1); // 3 mean SamplingGar2,
42 declareProperty("InductionModel", m_inductionModel=1); // 3 mean InductionGar2,
43 // this 2 doesnot extend from base normally and have to be used in conjunction.
44 declareProperty("GarfieldDebugging", m_garfDebugging=false);
45 declareProperty("SamplingDebugging", m_samplingDebugging=false);
46 declareProperty("InductionDebugging", m_debugInduction=false);
47 declareProperty("MagConfig", m_magConfig=1);
48 declareProperty("LUTFilePath",m_LUTFilePath = "/bes3fs/cgemCosmic/data/CGEM_cosmic_look_up_table_17.root");
49 declareProperty("QBranchVsampleDelay",sample_delay = 162.5);
50 declareProperty("StoreUnderThrethold",m_storeFlag = false);
51 declareProperty("Saturation",m_saturation = true);
52 declareProperty("SaveNt",m_saveNt= false);
53 declareProperty("SamplingGarGainMultiplier",m_GainMultiplier);
54 declareProperty("SamplingGarTransMultiplier",m_TransMultiplier= 1.0);
55 declareProperty("SamplingGarDiffuMultiplier",m_DiffuMultiplier= 1.0);
56 //cout << "CgemDigitizerSvc::m_ionModel = " << m_ionModel << endl;
57 declareProperty("Ngaps_microSector",m_Ngaps_microSector= 40);
58 declareProperty("gapShift_microSector",m_gapShift_microSector);
59 declareProperty("gap_microSector", m_gap_microSector= 1.1);// in mm
60 declareProperty("microSector_width", m_microSector_width);// in rad
61 declareProperty("QinGausSigma", m_QinGausSigma);
62 declareProperty("ScaleSignalX", m_ScaleSignalX=1.0);
63}
64
66}
67
68StatusCode CgemDigitizerSvc::queryInterface(const InterfaceID& riid, void** ppvInterface){
69 if( IID_ICgemDigitizerSvc.versionMatch(riid) ){
70 *ppvInterface = static_cast<ICgemDigitizerSvc*> (this);
71 } else{
72 return Service::queryInterface(riid, ppvInterface);
73 }
74 return StatusCode::SUCCESS;
75}
76
78 MsgStream log(messageService(), name());
79 log << MSG::INFO << "CgemDigitizerSvc::initialize()" << endreq;
80
81 StatusCode sc = Service::initialize();
82 if( sc.isFailure() ) return sc;
83
84 static IJobOptionsSvc* jobSvc = 0;
85 if ( jobSvc == 0 ) {
86 sc = service("JobOptionsSvc", jobSvc);
87 if ( sc.isFailure() ) {
88 std::cout << "Can't get the JobOptionsSvc @ DistBoss::GetPropertyValue()" << std::endl;
89 return sc;
90 }
91 }
92
93 // const vector<const Property*>* properties = jobSvc->getProperties(client);
94 const vector<const Property*>* properties = jobSvc->getProperties("BesRndmGenSvc");
95 // cout << "client of jobSvc: " << jobSvc->getClients() << endl;
96 if ( properties == NULL ) {
97 std::cout << "In CgemDigitizerSvc::initialize(), can't get client: " << std::endl;
98 return StatusCode::FAILURE;
99 }
100
101 unsigned int randSeed;
102 for ( unsigned int i = 0; i < properties->size(); ++i ) {
103 if ( properties->at(i)->name() == "RndmSeed" ) {
104 cout << "name of property: " << properties->at(i)->name() << endl;
105 string strRnd = properties->at(i)->toString();
106 sscanf(strRnd.c_str(), "%u", &randSeed);
107 cout << "random seed from jobOption: " << randSeed << endl;
108 break;
109 }
110 }
111
112 sc = service("CgemGeomSvc", m_geomSvc); // initial pointer of CgemGeomSvc
113 if(sc != StatusCode::SUCCESS)
114 {
115 log << MSG::ERROR << "can not use CgemGeomSvc" << endreq;
116 return StatusCode::FAILURE;
117 }
118
119 gRandom->SetSeed(randSeed); // set random seed
120
121 cout << "ionModel = " << m_ionModel << endl;
122 if(1 == m_ionModel){
123 m_pIon = new IonizationGar();
124 } else if(2 == m_ionModel){
125 m_pIon = new IonizationGTS();
126 }
127 // m_pIon = new IonizationGar();
128 m_pIon->setDebugging(m_garfDebugging);
129 m_pIon->init(randSeed, m_geomSvc, m_magConfig);
130
131 if ((3==m_driftAvaModel && 3!=m_inductionModel )||(3!=m_driftAvaModel && 3==m_inductionModel )) {
132 cout<<"CgemDigitizerSvc::initialize() Error: DriftAvalancheModel type3 and InductionModel type3 must be used together!"<<endl;
133 return StatusCode::FAILURE;
134 }
135
136 if(1 == m_driftAvaModel){
137 m_pDriftAndAva = new SamplingGar();
138 SamplingGar *pDriftAndAvaGar=(SamplingGar *) m_pDriftAndAva;
139 pDriftAndAvaGar->setGainMultiplier(m_GainMultiplier);
140 pDriftAndAvaGar->setTransMultiplier(m_TransMultiplier);
141 pDriftAndAvaGar->setDiffuMultiplier(m_DiffuMultiplier);
142 } else if(2 == m_driftAvaModel){
143 m_pDriftAndAva = new SamplingGTS();
144 } else if(3 == m_driftAvaModel){
145 m_pDriftAndAva = new SamplingGar2();
146 SamplingGar2* pDriftAndAva=(SamplingGar2*)m_pDriftAndAva;
147 pDriftAndAva->setMultiElectronMapAddr(&m_hitmap);
148
149 // migrate of samGar1;
150 pDriftAndAva->setGainMultiplier(m_GainMultiplier);
151 pDriftAndAva->setTransMultiplier(m_TransMultiplier);
152 pDriftAndAva->setDiffuMultiplier(m_DiffuMultiplier);
153 // migrate of indGar1
154 pDriftAndAva->setNgapsSect(m_Ngaps_microSector);
155 pDriftAndAva->setGapSizeSect(m_gap_microSector);
156 pDriftAndAva->setGapShiftSect(m_gapShift_microSector);
157 pDriftAndAva->setMicroSectorWidthRad(m_microSector_width);
158
159 }
160 m_pDriftAndAva->init(m_geomSvc, m_magConfig);
161 m_pDriftAndAva->setDebugging(m_samplingDebugging);
162
163 if(1 == m_inductionModel){
164 InductionGar* indGar = new InductionGar();
165 indGar->setNgapsSect(m_Ngaps_microSector);
166 indGar->setGapSizeSect(m_gap_microSector);
167 indGar->setGapShiftSect(m_gapShift_microSector);
168 indGar->setMicroSectorWidthRad(m_microSector_width);
169 indGar->setQinGausSigma(m_QinGausSigma);
170 indGar->setScaleSignalX(m_ScaleSignalX);
171 m_pInduction = indGar;
172 //m_pInduction = new InductionGar();
173 m_pInduction->setVsampleDelay(sample_delay);
174 m_pInduction->setLUTFilePath(m_LUTFilePath);
175 m_pInduction->setStoreFlag(m_storeFlag);
176 m_pInduction->setSaturation(m_saturation);
177 } else if(2 == m_inductionModel){
178 m_pInduction = new InductionGTS();
179 //m_pInduction = new InductionGar();
180 }else if (3 == m_inductionModel){
181 m_pInduction = new InductionGar2();
182 InductionGar2* indGar=(InductionGar2*)m_pInduction;
183 indGar->setQinGausSigma(m_QinGausSigma);
184 indGar->setScaleSignalX(m_ScaleSignalX);
185
186 m_pInduction->setVsampleDelay(sample_delay);
187 m_pInduction->setLUTFilePath(m_LUTFilePath);
188 m_pInduction->setStoreFlag(m_storeFlag);
189 m_pInduction->setSaturation(m_saturation);
190 }
191 m_pInduction->init(m_geomSvc, m_magConfig);
192 m_pInduction->setDebugOutput(m_debugInduction);
193
194 // --- check gaps
195 cout<<"CgemDigitizerSvc:"<<endl;
196 cout<<"gapShift_microSector="<<m_gapShift_microSector[0]
197 <<", "<<m_gapShift_microSector[1]
198 <<", "<<m_gapShift_microSector[2]
199 <<", "<<m_gapShift_microSector[3]
200 <<", "<<m_gapShift_microSector[4]
201 <<", "<<m_gapShift_microSector[5]
202 <<endl;
203 cout<<"microSector_width="<<m_microSector_width[0]
204 <<", "<<m_microSector_width[1]
205 <<", "<<m_microSector_width[2]
206 <<", "<<m_microSector_width[3]
207 <<", "<<m_microSector_width[4]
208 <<", "<<m_microSector_width[5]
209 <<endl;
210 cout<<"QinGausSigma="<<m_QinGausSigma[0]
211 <<", "<<m_QinGausSigma[1]
212 <<endl;
213 cout<<"Ngaps_microSector="<<m_Ngaps_microSector<<endl;
214 cout<<"gap_microSector="<<m_gap_microSector<<endl;
215
216 // --- read saturations
217 TFile *LUTFile = TFile::Open(m_LUTFilePath.c_str(),"read");
218 TTree *tree = (TTree*)LUTFile->Get("tree");
219 Float_t QDC_saturation;
220 Int_t layer,sheet,strip_v,strip_x;
221 tree->SetBranchAddress("strip_x_boss", &strip_x);
222 tree->SetBranchAddress("strip_v_boss", &strip_v);
223 tree->SetBranchAddress("layer", &layer);
224 tree->SetBranchAddress("sheet", &sheet);
225 tree->SetBranchAddress("calib_QDC_saturation", &QDC_saturation);
226 for(int i=0;i<tree->GetEntries();i++) {
227 tree->GetEntry(i);
228 if(strip_x!=-1) {
229 Qsaturation[layer][sheet][0][strip_x] = QDC_saturation;
230 }
231 if(strip_v!=-1) {
232 Qsaturation[layer][sheet][1][strip_v] = QDC_saturation;
233 }
234 }
235 for(int i=0;i<832;i++) {
236 Qsaturation[2][0][0][i] = 45.;
237 Qsaturation[2][1][0][i] = 45.;
238 }
239 for(int i=0;i<1395;i++) {
240 Qsaturation[2][0][1][i] = 45.;
241 Qsaturation[2][1][1][i] = 45.;
242 }
243 LUTFile->Close();
244
245 // ntuple
246 if(m_saveNt) {
247 INTupleSvc* ntupleSvc;
248 Gaudi::svcLocator() -> service("NTupleSvc", ntupleSvc);
249 NTuplePtr nt(ntupleSvc, "CgemDigitizerSvcNT/digi");
250 // NTuplePtr nt(ntupleSvc(), "CgemDigitizerSvcNT/digi");
251 if(nt) m_tuple = nt;
252 else{
253 m_tuple = ntupleSvc->book("CgemDigitizerSvcNT/digi", CLID_ColumnWiseTuple, "noise");
254 if(m_tuple){
255 m_tuple->addItem("nIonE", m_ntNIonE);
256 m_tuple->addItem("nMultiE", m_ntNMultiE);
257 m_tuple->addItem("nXstrips", m_ntNxstrips,0,100);
258 m_tuple->addItem("nVstrips", m_ntNvstrips,0,100);
259 m_tuple->addIndexedItem("XstripQ", m_ntNxstrips,m_ntxstripQ);
260 m_tuple->addIndexedItem("XstripT", m_ntNxstrips,m_ntxstripT);
261 m_tuple->addIndexedItem("VstripQ", m_ntNvstrips,m_ntvstripQ);
262 m_tuple->addIndexedItem("VstripT", m_ntNvstrips,m_ntvstripT);
263 m_tuple->addIndexedItem("XstripID", m_ntNxstrips,m_XstripID);
264 m_tuple->addIndexedItem("VstripID", m_ntNvstrips,m_VstripID);
265 }
266 }
267 }
268
269 return StatusCode::SUCCESS;
270}
271
273 MsgStream log(messageService(), name());
274 log << MSG::INFO << "CgemDigitizerSvc::finalize()" << endreq;
275 delete m_pIon;
276 delete m_pDriftAndAva;
277 delete m_pInduction;
278
279 return StatusCode::SUCCESS;
280}
281
282StatusCode CgemDigitizerSvc::setTrack(int layer, int particle, int charge, double p, double trkPosIn[], double trkPosOut[]){
283 vector<int> Vparticle (1,particle);
284 vector<int> Vcharge (1,charge);
285 vector<double> Vp (1,p);
286
287 // awkward way of saying
288 //vector<vector<double> >VtrkPosIn={{trkPosIn[0], trkPosIn[1], trkPosIn[2]}};
289 vector<double> posin;
290 posin.push_back(trkPosIn[0]);
291 posin.push_back(trkPosIn[1]);
292 posin.push_back(trkPosIn[2]);
293 vector<vector<double> > VtrkPosIn;
294 VtrkPosIn.push_back(posin);
295
296 vector<double> posout;
297 posout.push_back(trkPosOut[0]);
298 posout.push_back(trkPosOut[1]);
299 posout.push_back(trkPosOut[2]);
300 vector<vector<double> > VtrkPosOut;
301 VtrkPosOut.push_back(posout);//= {{trkPosOut[0], trkPosOut[1], trkPosOut[2]}};
302
303 StatusCode sc=setTrack(layer,Vparticle, Vcharge, Vp, VtrkPosIn, VtrkPosOut);
304
305 return sc;
306
307 //*******below are original contents of this function.**********
308
309 // //ProcInfo_t info;
310 // //gSystem->GetProcInfo(&info);
311 // //double currentMemory = info.fMemResident/1024;// MB
312 // //cout<<"CgemDigitizerSvc::setTrack() memory 1 "<<currentMemory<<" MB"<<endl;
313 //
314 // double time_spent = 0.;
315 // clock_t begin = clock();
316 // //cout<<"setTrack"<<endl;
317 // clear();
318 // m_layer = layer;
319 //
320 // //cout<<"before m_pIon->setTrack()"<<endl;
321 // //cout<<"set particle "<<particle<<", p="<<p<<endl;
322 // m_pIon->setTrack(particle, charge, p, trkPosIn, trkPosOut);
323 // //cout<<"after m_pIon->setTrack()"<<endl;
324 // //gSystem->GetProcInfo(&info); currentMemory = info.fMemResident/1024; cout<<"CgemDigitizerSvc::setTrack() memory 2 "<<currentMemory<<" MB"<<endl;
325 //
326 // vector<double> ionEx;
327 // vector<double> ionEy;
328 // vector<double> ionEz;
329 // vector<double> ionEt;
330 // int nIonE = m_pIon->getNumberIonE();
331 // for(int i=0; i<nIonE; i++){
332 // ionEx.push_back(m_pIon->getEx(i));
333 // ionEy.push_back(m_pIon->getEy(i));
334 // ionEz.push_back(m_pIon->getEz(i));
335 // ionEt.push_back(m_pIon->getEt(i));
336 // }
337 // //cout<<"after pushing back ionE "<<endl;
338 // if(m_saveNt) m_ntNIonE=nIonE;
339 // clock_t end = clock();
340 // //cout<<" CLOCKS_PER_SEC "<<endl;
341 // //cout<<CLOCKS_PER_SEC<<endl;
342 // //cout<<" calculate time_spent"<<endl;
343 // time_spent += (double)(end - begin) / CLOCKS_PER_SEC;
344 // //cout << "CgemDigitizerSvc::ionization " << time_spent << " seconds" << endl;
345 // // ---------------------------
346 // time_spent = 0.;
347 // begin = clock();
348 //
349 // //gSystem->GetProcInfo(&info); currentMemory = info.fMemResident/1024; cout<<"CgemDigitizerSvc::setTrack() memory 3 "<<currentMemory<<" MB"<<endl;
350 // m_pDriftAndAva->setIonElectrons(layer, nIonE, ionEx, ionEy, ionEz, ionEt);
351 //
352 // m_nMultiE = m_pDriftAndAva->getNelectrons();
353 // //for(int i=0; i<m_nMultiE; i++){
354 // // double x = m_pDriftAndAva->getX(i);
355 // // double y = m_pDriftAndAva->getY(i);
356 // // double z = m_pDriftAndAva->getZ(i);
357 // // double t = m_pDriftAndAva->getT(i);
358 // // (*m_pmultiEx).push_back(x);
359 // // (*m_pmultiEy).push_back(y);
360 // // (*m_pmultiEz).push_back(z);
361 // // (*m_pmultiEt).push_back(t);
362 // //}
363 // m_pmultiEx=& (m_pDriftAndAva->getXContainer());
364 // m_pmultiEy=& (m_pDriftAndAva->getYContainer());
365 // m_pmultiEz=& (m_pDriftAndAva->getZContainer());
366 // m_pmultiEt=& (m_pDriftAndAva->getTContainer());
367 // //std::cout<<m_nMultiE<<"\t";
368 // if(m_saveNt) m_ntNMultiE=m_nMultiE;
369 // end = clock();
370 // time_spent += (double)(end - begin) / CLOCKS_PER_SEC;
371 // //cout << "CgemDigitizerSvc::diffusion " << time_spent << " seconds" << endl;
372 // // --------------------
373 // time_spent = 0.;
374 // begin = clock();
375 //
376 // //gSystem->GetProcInfo(&info); currentMemory = info.fMemResident/1024; cout<<"CgemDigitizerSvc::setTrack() memory 4 "<<currentMemory<<" MB"<<endl;
377 // // Induction process
378 // // positionToStrips();
379 // //cout<<" before m_pInduction->setMultiElectrons "<<endl;
380 // m_pInduction->setMultiElectrons(layer, m_nMultiE, *m_pmultiEx, *m_pmultiEy, *m_pmultiEz, *m_pmultiEt);
381 // //cout<<" after m_pInduction->setMultiElectrons "<<endl;
382 // m_nXstrips = m_pInduction->getNXstrips();
383 // //gSystem->GetProcInfo(&info); currentMemory = info.fMemResident/1024; cout<<"CgemDigitizerSvc::setTrack() memory 5 "<<currentMemory<<" MB"<<endl;
384 // //m_ntNxstrips = m_nXstrips;
385 // //m_ntNvstrips = m_nVstrips;
386 // // cout<<"read data"<<endl;
387 // for(int i=0; i<m_nXstrips; i++){
388 // //m_ntNxstrips=i;
389 // if(m_saveNt && i<100) {
390 // m_ntxstripQ[i]=m_pInduction->getXstripQ(i);
391 // m_ntxstripT[i]=m_pInduction->getXstripT(i);
392 // m_XstripID[i]=m_pInduction->getXstripID(i);
393 // }
394 // m_xstripSheet.push_back(m_pInduction->getXstripSheet(i));
395 // m_xstripID.push_back(m_pInduction->getXstripID(i));
396 // m_xstripQ.push_back(m_pInduction->getXstripQ(i));
397 // m_xstripQ2.push_back(m_pInduction->getXstripQ_Branch(i));
398 // m_xstripT.push_back(m_pInduction->getXstripT(i));
399 // m_xfirstT.push_back(m_pInduction->getXfirstT(i));
400 //
401 // }
402 //
403 // m_nVstrips = m_pInduction->getNVstrips();
404 // for(int i=0; i<m_nVstrips; i++){
405 // //m_ntNvstrips=i;
406 // if(m_saveNt && i<100) {
407 // m_ntvstripQ[i]=m_pInduction->getVstripQ(i);
408 // m_ntvstripT[i]=m_pInduction->getVstripT(i);
409 // m_VstripID[i]=m_pInduction->getVstripID(i);
410 // }
411 // m_vstripSheet.push_back(m_pInduction->getVstripSheet(i));
412 // m_vstripID.push_back(m_pInduction->getVstripID(i));
413 // m_vstripQ.push_back(m_pInduction->getVstripQ(i));
414 // m_vstripQ2.push_back(m_pInduction->getVstripQ_Branch(i));
415 // m_vstripT.push_back(m_pInduction->getVstripT(i));
416 // m_vfirstT.push_back(m_pInduction->getVfirstT(i));
417 // }
418 // end = clock();
419 // time_spent += (double)(end - begin) / CLOCKS_PER_SEC;
420 // // cout << "CgemDigitizerSvc::induction " << time_spent << " seconds" << endl;
421 // // cout << "nXstrips = " << m_nXstrips << " , m_nVstrips = " << m_nVstrips << endl;
422 // // ---------------
423 // time_spent = 0.;
424 // begin = clock();
425 //
426 // if(m_saveNt) {
427 // //m_ntNIonE = nIonE;
428 // //m_ntNMultiE = m_nMultiE;
429 // m_ntNxstrips = m_nXstrips;
430 // m_ntNvstrips = m_nVstrips;
431 // m_tuple->write();
432 // }
433 //
434 // end = clock();
435 // time_spent += (double)(end - begin) / CLOCKS_PER_SEC;
436 // //cout << "CgemDigitizerSvc::write " << time_spent << " seconds" << endl;
437 //
438 // //std::cout<<"wow test2!\t";
439 // //checkMemorySize();
440 // //gSystem->GetProcInfo(&info);
441 // //double currentMemory2 = info.fMemResident/1024;// MB
442 // //cout<<"CgemDigitizerSvc::setTrack() memory from "<<currentMemory<<" to "<<currentMemory2<<" MB"<<endl;
443 //
444 // return StatusCode::SUCCESS;
445}
446
447StatusCode CgemDigitizerSvc::setTrack(int layer, vector<int>particle, vector<int> charge, vector<double> p, vector<vector<double> > trkPosIn, vector<vector<double> > trkPosOut){
448
449 //ProcInfo_t info;
450 //gSystem->GetProcInfo(&info);
451 //double currentMemory = info.fMemResident/1024;// MB
452 //cout<<"CgemDigitizerSvc::setTrack() memory 1 "<<currentMemory<<" MB"<<endl;
453
454 double time_spent = 0.;
455 clock_t begin = clock();
456 int nTotIonE = 0;
457 //cout<<"setTrack"<<endl;
458 clear();
459 m_layer = layer;
460 vector<double> ionEx;
461 vector<double> ionEy;
462 vector<double> ionEz;
463 vector<double> ionEt;
464 for(unsigned TrackSeg=0;TrackSeg<particle.size();TrackSeg++){
465
466 double SegTrkPosIn[3];
467 double SegTrkPosOut[3];
468 for(int i=0;i<3;i++){
469 SegTrkPosIn[i]=trkPosIn[TrackSeg][i];
470 SegTrkPosOut[i]=trkPosOut[TrackSeg][i];
471 }
472 //cout<<"trrpos "<<SegTrkPosIn[0]<<" "<<SegTrkPosIn[1]<<" "<<SegTrkPosIn[2]<<" "<<SegTrkPosOut[0]<<" "<<SegTrkPosOut[1]<<" "<<SegTrkPosOut[2]<<endl;
473 m_pIon->setTrack(particle[TrackSeg], charge[TrackSeg], p[TrackSeg], SegTrkPosIn, SegTrkPosOut);
474
475 int nIonE = m_pIon->getNumberIonE();
476 nTotIonE=nIonE+nTotIonE;
477 for(int i=0; i<nIonE; i++){
478 ionEx.push_back(m_pIon->getEx(i));
479 ionEy.push_back(m_pIon->getEy(i));
480 ionEz.push_back(m_pIon->getEz(i));
481 ionEt.push_back(m_pIon->getEt(i));
482 }
483 }
484 //cout<<"after pushing back ionE "<<endl;
485 if(m_saveNt) m_ntNIonE=nTotIonE;
486 clock_t end = clock();
487 time_spent += (double)(end - begin) / CLOCKS_PER_SEC;
488 //cout << "CgemDigitizerSvc::ionization " << time_spent << " seconds" << endl;
489 // ---------------------------
490 time_spent = 0.;
491
492
493 if (m_driftAvaModel !=3){
494 begin = clock();
495 m_pDriftAndAva->setIonElectrons(layer, nTotIonE, ionEx, ionEy, ionEz, ionEt);
496
497 m_nMultiE = m_pDriftAndAva->getNelectrons();
498 //for(int i=0; i<m_nMultiE; i++){
499 // double x = m_pDriftAndAva->getX(i);
500 // double y = m_pDriftAndAva->getY(i);
501 // double z = m_pDriftAndAva->getZ(i);
502 // double t = m_pDriftAndAva->getT(i);
503 // (*m_pmultiEx).push_back(x);
504 // (*m_pmultiEy).push_back(y);
505 // (*m_pmultiEz).push_back(z);
506 // (*m_pmultiEt).push_back(t);
507 //}
508 m_pmultiEx=& (m_pDriftAndAva->getXContainer());
509 m_pmultiEy=& (m_pDriftAndAva->getYContainer());
510 m_pmultiEz=& (m_pDriftAndAva->getZContainer());
511 m_pmultiEt=& (m_pDriftAndAva->getTContainer());
512
513 if(m_saveNt) {
514 m_ntNMultiE=m_nMultiE;
515 }
516 end = clock();
517 time_spent += (double)(end - begin) / CLOCKS_PER_SEC;
518 //cout << "CgemDigitizerSvc::diffusion " << time_spent << " seconds" << endl;
519 // --------------------
520 time_spent = 0.;
521 begin = clock();
522
523 // Induction process
524 // positionToStrips();
525 // cout << "nXstrips = " << m_nXstrips << " , m_nVstrips = " << m_nVstrips << endl;
526 m_pInduction->setMultiElectrons(layer, m_nMultiE, *m_pmultiEx, *m_pmultiEy, *m_pmultiEz, *m_pmultiEt);
527
528 }
529 else{ //m_driftAvaModel ==3
530 SamplingGar2 *pSampling2=(SamplingGar2 *) m_pDriftAndAva;
531 InductionGar2 *pInduction2=(InductionGar2 *) m_pInduction;
532
533 pSampling2->setIonElectrons(layer, nTotIonE, ionEx, ionEy, ionEz, ionEt);
534 //yields m_hitmap
535 // as test;
536 end = clock();
537 time_spent += (double)(end - begin) / CLOCKS_PER_SEC;
538
539 // cout << "CgemDigitizerSvc::diffusion " << time_spent << " seconds" << endl;
540 // --------------------
541 m_nMultiE = m_pDriftAndAva->getNelectrons();
542
543 time_spent = 0.;
544 begin = clock();
545 if(m_saveNt) {
546 m_ntNMultiE=m_nMultiE;
547 }
548
549 InductionGar2::PVectorXYZT vMultiElectrons;
550 vMultiElectrons.x=& (m_pDriftAndAva->getXContainer());
551 vMultiElectrons.y=& (m_pDriftAndAva->getYContainer());
552 vMultiElectrons.z=& (m_pDriftAndAva->getZContainer());
553 vMultiElectrons.t=& (m_pDriftAndAva->getTContainer());
554 InductionGar2::PVectorXYZT *pMultiElectronsInfo=&vMultiElectrons;
555 if (!m_samplingDebugging){
556 pMultiElectronsInfo=0;
557 }
558 pInduction2->setMultiElectrons(layer, m_hitmap,pMultiElectronsInfo);
559
560 }
561 m_nXstrips = m_pInduction->getNXstrips();
562
563 for(int i=0; i<m_nXstrips; i++){
564 // m_ntNxstrips=i;
565 if(m_saveNt && i<100) {
566 m_ntxstripQ[i]=m_pInduction->getXstripQ(i);
567 m_ntxstripT[i]=m_pInduction->getXstripT(i);
568 m_XstripID[i]=m_pInduction->getXstripID(i);
569 }
570 m_xstripSheet.push_back(m_pInduction->getXstripSheet(i));
571 m_xstripID.push_back(m_pInduction->getXstripID(i));
572 m_xstripQ.push_back(m_pInduction->getXstripQ(i));
573 m_xstripQ2.push_back(m_pInduction->getXstripQ_Branch(i));
574 m_xstripT.push_back(m_pInduction->getXstripT(i));
575 m_xfirstT.push_back(m_pInduction->getXfirstT(i));
576
577
578 }
579
580 m_nVstrips = m_pInduction->getNVstrips();
581 for(int i=0; i<m_nVstrips; i++){
582 // m_ntNvstrips=i;
583 if(m_saveNt && i<100) {
584 m_ntvstripQ[i]=m_pInduction->getVstripQ(i);
585 m_ntvstripT[i]=m_pInduction->getVstripT(i);
586 m_VstripID[i]=m_pInduction->getVstripID(i);
587 }
588 m_vstripSheet.push_back(m_pInduction->getVstripSheet(i));
589 m_vstripID.push_back(m_pInduction->getVstripID(i));
590 m_vstripQ.push_back(m_pInduction->getVstripQ(i));
591 m_vstripQ2.push_back(m_pInduction->getVstripQ_Branch(i));
592 m_vstripT.push_back(m_pInduction->getVstripT(i));
593 m_vfirstT.push_back(m_pInduction->getVfirstT(i));
594 }
595 end = clock();
596
597
598 //cout<<"read finish"<<endl;
599
600 time_spent += (double)(end - begin) / CLOCKS_PER_SEC;
601 //cout << "CgemDigitizerSvc::induction " << time_spent << " seconds" << endl;
602 //cout<< "CgemDigitizerSvc multiplied electrons " << m_nMultiE << endl;
603 // ---------------
604 time_spent = 0.;
605 begin = clock();
606
607 if(m_saveNt) {
608 //m_ntNIonE = nIonE;
609 //m_ntNMultiE = m_nMultiE;
610 m_ntNxstrips = m_nXstrips;
611 m_ntNvstrips = m_nVstrips;
612 m_tuple->write();
613 }
614
615 end = clock();
616 time_spent += (double)(end - begin) / CLOCKS_PER_SEC;
617 // cout << "CgemDigitizerSvc::write " << time_spent << " seconds" << endl;
618 //checkMemorySize();
619
620 return StatusCode::SUCCESS;
621}
622// ZZH i think this function should have been depreciated?
623void CgemDigitizerSvc::positionToStrips(){
624 m_cgemLayer = m_geomSvc->getCgemLayer(m_layer);
625 m_nSheet = m_cgemLayer->getNumberOfSheet();
626 //int i_sheet;
627
628 char hname[200];
629 TObjArray* hlist = new TObjArray(0);
630 // cout << "nMultiE :" << m_nMultiE << endl;
631 for(int i=0; i<m_nMultiE; i++){
632 // ofstream fout("elecPos.txt");
633 // for(int i=0; i<1000; i++)
634 // cout << "nMultiE :" << i << endl;
635 double phi = atan2((*m_pmultiEy)[i], (*m_pmultiEx)[i]);
636 double z = (*m_pmultiEz)[i];
637 G4ThreeVector pos((*m_pmultiEx)[i], (*m_pmultiEy)[i], z);
638 // fout << setw(5) << i << setw(20) << (*m_pmultiEx)[i] << setw(20) << (*m_pmultiEy)[i] << setw(20) << (*m_pmultiEz)[i] << endl;
639 for(int j=0; j<m_nSheet; j++)
640 {
641 m_cgemReadoutPlane = m_geomSvc->getReadoutPlane(m_layer, j);
642 if(m_cgemReadoutPlane->OnThePlane(phi,z))
643 {
644 int iView = 1;
645 int ID = -1;
646 double distV;
647 int vID = m_cgemReadoutPlane->getClosestVStripID(pos, distV);
648 ID = vID;
649 if(vID>=0) {
650 if(distV>0) {
651 double distX;
652 int xID = m_cgemReadoutPlane->getClosestXStripID(phi, distX);
653 if(xID>=0&&distX<distV) {
654 ID = xID;
655 iView = 0;
656 }
657 }
658 map<int, int>::iterator it = m_mapQ[j][iView].find(ID);
659 if(it==m_mapQ[j][iView].end())
660 {
661 m_mapQ[j][iView][ID]=1;
662 m_mapT[j][iView][ID]=(*m_pmultiEt)[i];
663 }
664 else {
665 int Q = (it->second) +1;
666 m_mapQ[j][iView][ID]=Q;
667 if((*m_pmultiEt)[i] < m_mapT[j][iView][ID]) m_mapT[j][iView][ID] = (*m_pmultiEt)[i];
668 }
669 // T info
670 sprintf(hname, "time%d_%d_%d", j, iView, ID);
671 TH1F* hist = (TH1F*)hlist->FindObject(hname);
672 if(NULL == hist){
673 hist = new TH1F(hname, "", 1000, 0, 1000);
674 hlist->Add(hist);
675 }
676 hist->Fill((*m_pmultiEt)[i]);
677 }
678 break;
679 }
680 }
681 }
682 m_nXstrips = m_mapQ[0][0].size() + m_mapQ[1][0].size();
683 m_nVstrips = m_mapQ[0][1].size() + m_mapQ[1][1].size();
684 // fout.close();
685
686 int nhist = hlist->GetEntries();
687 // cout << setw(10) << m_nXstrips+m_nVstrips << setw(10) << nhist
688 // << "nXstrips = " << m_nXstrips << " , m_nVstrips = " << m_nVstrips << endl;
689 for(int i=0; i<nhist; i++){
690 TH1F* hist;
691 TH1F* hlast;
692 if(0==i){
693 hist = (TH1F*)hlist->First();
694 } else{
695 hist = (TH1F*)hlist->After(hlast);
696 }
697 hlast = hist;
698 const char* histname = hist->GetName();
699 int iSheet, iView, ID;
700 sscanf(histname, "%*4s%1d%*1s%1d%*1s%d", &iSheet, &iView, &ID);
701
702 if(0==iView){
703 m_xstripSheet.push_back(iSheet);
704 m_xstripID.push_back(ID);
705 m_xstripQ.push_back(m_mapQ[iSheet][iView][ID]);
706 m_xstripT.push_back(m_mapT[iSheet][iView][ID]);
707 } else{
708 m_vstripSheet.push_back(iSheet);
709 m_vstripID.push_back(ID);
710 m_vstripQ.push_back(m_mapQ[iSheet][iView][ID]);
711 m_vstripT.push_back(m_mapT[iSheet][iView][ID]);
712 }
713 }
714
715 for(int i=0; i<nhist; i++){
716 TH1F* hist = (TH1F*)hlist->Last();
717 hlist->Remove(hist);
718 delete hist;
719 }
720 hlist->Clear();
721 delete hlist;
722}
723
724void CgemDigitizerSvc::clear(){
725 m_nXstrips = 0;
726 m_nVstrips = 0;
727 m_xstripSheet.clear();
728 m_xstripID.clear();
729 m_vstripSheet.clear();
730 m_vstripID.clear();
731 m_xstripQ.clear();
732 m_vstripQ.clear();
733 m_xstripT.clear();
734 m_vstripT.clear();
735 m_xstripQ2.clear();
736 m_vstripQ2.clear();
737 m_xfirstT.clear();
738 m_vfirstT.clear();
739 m_nMultiE = 0;
740 // now that we dont own this. they are cleared by Sampling Obj.
741 //(*m_pmultiEx).clear();
742 //(*m_pmultiEy).clear();
743 //(*m_pmultiEz).clear();
744 //(*m_pmultiEt).clear();
745 for(int i=0; i<2; i++){
746 for(int k=0; k<2; k++){
747 m_mapQ[i][k].clear();
748 m_mapT[i][k].clear();
749 }
750 }
751}
752
753
754void CgemDigitizerSvc::checkMemorySize()
755{
756 ProcInfo_t info;
757 gSystem->GetProcInfo(&info);
758 double currentMemory = info.fMemResident/1024;// MB
759 cout<<"CgemDigitizerSvc: current memory size "<<currentMemory<<" MB"<<endl;
760}
float Float_t
INTupleSvc * ntupleSvc()
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
Definition: CgemGeoLayer.h:215
int getClosestXStripID(double phi, double &dist)
bool OnThePlane(double phi, double z) const
int getClosestVStripID(G4ThreeVector pos, double &dist) const
virtual const std::vector< Float_t > & getXContainer() const =0
virtual const std::vector< Float_t > & getYContainer() 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 void setDebugging(bool debugging)=0
virtual const std::vector< Float_t > & getZContainer() const =0
virtual int getNelectrons() const =0
virtual const std::vector< Float_t > & getTContainer() const =0
virtual CgemGeoReadoutPlane * getReadoutPlane(int iLayer, int iSheet) const =0
virtual CgemGeoLayer * getCgemLayer(int i) const =0
void setQinGausSigma(vector< double > sigma)
Definition: InductionGar2.h:82
void setScaleSignalX(double ScaleSignalX)
Definition: InductionGar2.h:81
void setMultiElectrons(int layer, int nElectrons, const std::vector< Float_t > &x, const std::vector< Float_t > &y, const std::vector< Float_t > &z, const std::vector< Float_t > &t)
Definition: InductionGar2.h:54
void setGapSizeSect(double size)
Definition: InductionGar.h:74
void setMicroSectorWidthRad(vector< double > width)
Definition: InductionGar.h:86
void setNgapsSect(int n)
Definition: InductionGar.h:73
void setScaleSignalX(double ScaleSignalX)
Definition: InductionGar.h:75
void setQinGausSigma(vector< double > sigma)
Definition: InductionGar.h:96
void setGapShiftSect(vector< double > shift)
Definition: InductionGar.h:76
virtual void setStoreFlag(bool flag)=0
virtual double getXstripT(int n) const =0
virtual double getXfirstT(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 getXstripQ_Branch(int n) const =0
virtual void setSaturation(bool flag)=0
virtual double getVstripQ(int n) const =0
virtual void setVsampleDelay(double delay)=0
virtual int getXstripSheet(int n) const =0
virtual double getVfirstT(int n) const =0
virtual void setMultiElectrons(int layer, int nElectrons, const std::vector< Float_t > &x, const std::vector< Float_t > &y, const std::vector< Float_t > &z, const std::vector< Float_t > &t)=0
virtual double getXstripQ(int n) const =0
virtual void setDebugOutput(bool debugOutput)=0
virtual double getVstripQ_Branch(int n) const =0
virtual void setLUTFilePath(std::string path)=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
void setTransMultiplier(double TransMultiplier)
Definition: SamplingGar2.h:45
void setGapSizeSect(double size)
Definition: SamplingGar2.h:54
void setGapShiftSect(vector< double > shift)
Definition: SamplingGar2.h:55
void setNgapsSect(int n)
Definition: SamplingGar2.h:53
void setGainMultiplier(vector< double > GainMultiplier)
Definition: SamplingGar2.h:39
void setIonElectrons(int layer, int nElectrons, std::vector< double > x, std::vector< double > y, std::vector< double > z, std::vector< double > t)
void setDiffuMultiplier(double DiffuMultiplier)
Definition: SamplingGar2.h:46
void setMultiElectronMapAddr(HitHistMap *address)
Definition: SamplingGar2.h:49
void setMicroSectorWidthRad(vector< double > width)
Definition: SamplingGar2.h:64
void setGainMultiplier(vector< double > GainMultiplier)
Definition: SamplingGar.h:35
void setDiffuMultiplier(double DiffuMultiplier)
Definition: SamplingGar.h:42
void setTransMultiplier(double TransMultiplier)
Definition: SamplingGar.h:41
const std::vector< Float_t > * z
const std::vector< Float_t > * t
const std::vector< Float_t > * x
const std::vector< Float_t > * y