162{
164 Gaudi::svcLocator() -> service(
"MessageSvc",
msgSvc);
165 MsgStream log(
msgSvc,
"BesCgemDigitizer::Digitize()");
166 bool printFlag=false;
167 ISvcLocator* iface = Gaudi::svcLocator();
168 SmartIF<IDataProviderSvc> eds(iface->service("EventDataSvc"));
169 SmartDataPtr<Event::EventHeader> eventHeader(eds,"/Event/EventHeader");
170 if(m_F_ntuple) m_evt = eventHeader->eventNumber();
171 if(printFlag) {
172 log<< MSG::INFO << "|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" << endreq;
173 log<< MSG::INFO << "INFO : CgemSim::BesCgemDigitizer::Digitize(), Begin !!!" << endreq;
174 }
175
176
177 for (G4int i=0; i<3; i++)
178 {
179 for (G4int j=0; j<2; j++)
180 {
181 for (G4int k=0; k<2; k++)
182 {
183 for (G4int l=0; l<1500; l++)
184 {
185 m_F_hit[i][j][k][l] = -1;
186 }
187 }
188 }
189 }
190
191
192 G4DigiManager *gv_digi_manager = G4DigiManager::GetDMpointer();
193
194
195 G4int lvi_ID_HC = -1;
196 lvi_ID_HC = gv_digi_manager->GetHitsCollectionID("BesCgemHitsCollection");
197
198
200 if (lvi_ID_HC >= 0)
201 {
203 }
204 else
205 {
206 log<< MSG::ERROR << "ERROR : CgemSim::BesCgemDigitizer::Digitize(), Fail to retrieve HitsCollection!"
207 << endreq;
208 return ;
209 }
210
211
212
213 G4int lvi_N_hit = 0;
214 G4int lvi_ID_track = 0;
215 G4int lvi_ID_layer = 0;
216 G4double lvd_global_time = 0.;
217 G4double lvd_E_deposit = 0.;
218 G4double lvd_E_average = 0.;
219 G4ThreeVector lv3_XYZ_pre (0., 0., 0.);
220 G4ThreeVector lv3_XYZ_post(0., 0., 0.);
221
222
223 G4int lvi_RdtElectron = 0;
224
225
226
228 G4int lvi_N_sheet = 0;
229 G4int lvi_N_strip[2];
230 G4double lvd_R_layer = 0.;
231 G4double lvd_L_layer = 0.;
232 G4double lvd_A_stero = 0.;
233 G4double lvd_W_sheet = 0.;
234 G4double lvd_W_pitch_x = 0.;
235 G4double lvd_W_pitch_v = 0.;
236
237
238 G4double lvd_x_pre, lvd_x_post;
239 G4double lvd_v_pre, lvd_v_post;
240 G4int lvi_ID_sheet_pre , lvi_ID_x_pre, lvi_ID_x_post;
241 G4int lvi_ID_sheet_post, lvi_ID_v_pre, lvi_ID_v_post;
242 G4int lvi_N_hit_strip_x, lvi_N_hit_strip_v;
243 G4int lvi_ID_x_start , lvi_ID_v_start ;
244 G4int lvi_ID_sheet_mid_pre , lvi_ID_x_mid_pre , lvi_ID_v_mid_pre ;
245 G4int lvi_ID_sheet_mid_post, lvi_ID_x_mid_post, lvi_ID_v_mid_post;
246 G4int lvi_N_hit_strip_x_pre , lvi_N_hit_strip_v_pre , lvi_ID_x_start_pre , lvi_ID_v_start_pre ;
247 G4int lvi_N_hit_strip_x_post, lvi_N_hit_strip_v_post, lvi_ID_x_start_post, lvi_ID_v_start_post;
248 G4int lvi_N_hit_strip[2], lvi_N_hit_strip_pre[2];
249 G4int lvi_ID_strip_start[2], lvi_ID_strip_start_pre[2], lvi_ID_strip_start_post[2];
250
251 G4int lvi_ID_sheet = 0;
252 G4int lvi_ID_strip = 0;
253 G4double lvd_E_strip = 0.;
254
255 G4int lvi_case = 0;
256
257 if(lv_HC)
258 {
260
261
262 lvi_N_hit = lv_HC->entries();
263 for (G4int ii=0; ii<lvi_N_hit; ii++)
264 {
265
267
268 if(printFlag)
269 {
270 log<< MSG::INFO << "..............................................................................."
271 << endreq;
272 log<< MSG::INFO << "CgemSim::BesCgemDigitizer::Digitize(), Digitize hit " << ii
273 << " of " << lvi_N_hit << endreq;
274 }
275
276
277 lvi_RdtElectron = lv_hit->
GetRdtEl ();
278
279
280
287
288 lv_cgem_layer = m_cgem_geomsvc->
getCgemLayer(lvi_ID_layer);
296
297 lvd_W_sheet = lvd_R_layer * twopi / lvi_N_sheet;
298
299 lvi_N_strip[0] = ceil(lvd_W_sheet / lvd_W_pitch_x);
300 lvi_N_strip[1] = ceil((lvd_W_sheet*
cos(lvd_A_stero)+lvd_L_layer*fabs(
sin(lvd_A_stero))) / lvd_W_pitch_v);
301
302
303 if(lvi_RdtElectron ==1) continue;
304
305
306
307 if (m_F_printStrip ==1)
308 {
309 log<< MSG::INFO << "CgemSim::BesCgemDigitizer::Digitize(), Strip information:" << endreq;
310 log<< MSG::INFO << "ID_layer "
311 << "R "
312 << "N_sheet "
313 << "W_sheet "
314 << "N_X_strip "
315 << "N_V_strip "
316 << "A_stero "
317 << endreq;
318 log<< MSG::INFO << left << setw( 9) << lvi_ID_layer
319 << left << setw( 8) << lvd_R_layer
320 << left << setw( 8) << lvi_N_sheet
321 << left << setw( 8) << lvd_W_sheet
322 << left << setw(10) << lvi_N_strip[0]
323 << left << setw(10) << lvi_N_strip[1]
324 << left << setw( 8) << lvd_A_stero
325 << endreq;
326 log<< MSG::INFO <<"lv3_XYZ_pre, lv3_XYZ_post"<<lv3_XYZ_pre<<", "<<lv3_XYZ_post<<endreq;
327 log<< MSG::INFO << " " << endreq;
328 }
329
330
331 if (m_F_lorentz == 1)
332 {
333 if(printFlag)
334 log<< MSG::INFO << "CgemSim::BesCgemDigitizer::Digitize(), Begin to Lorentz Diffuse!" << endreq;
336 }
337
338
339 if (m_F_smear == 1)
340 {
341 if(printFlag)
342 log<< MSG::INFO << "CgemSim::BesCgemDigitizer::Digitize(), Begin to Smear!" << endreq;
344 }
345
346
347 if (m_F_noise == 1)
348 {
349 if(printFlag)
350 log<< MSG::INFO << "CgemSim::BesCgemDigitizer::Digitize(), Begin to Add Noise!" << endreq;
352 }
353
354
355
357 lvd_x_pre, lvd_v_pre,
358 lvi_ID_sheet_pre, lvi_ID_x_pre, lvi_ID_v_pre);
359
360
362 lvd_x_post, lvd_v_post,
363 lvi_ID_sheet_post, lvi_ID_x_post, lvi_ID_v_post);
364
365
366
367 if (lvi_ID_sheet_pre == lvi_ID_sheet_post and
368 (
abs(lvi_ID_x_post - lvi_ID_x_pre) < (lvi_N_strip[0]-
abs(lvi_ID_x_post - lvi_ID_x_pre))) and
369 (
abs(lvi_ID_v_post - lvi_ID_v_pre) < (lvi_N_strip[1]-
abs(lvi_ID_v_post - lvi_ID_v_pre))))
370 {
371 lvi_case = 0;
372 if(printFlag)
373 log<< MSG::INFO << "CgemSim::BesCgemDigitizer::Digitize(), Step in same sheet!" << endreq;
374
376 lvi_ID_x_post , lvi_ID_v_post ,
377 lvi_N_hit_strip_x , lvi_N_hit_strip_v ,
378 lvi_ID_x_start , lvi_ID_v_start );
379
380 lvi_N_hit_strip[0] = lvi_N_hit_strip_x;
381 lvi_N_hit_strip[1] = lvi_N_hit_strip_v;
382
383 lvi_ID_strip_start[0] = lvi_ID_x_start;
384 lvi_ID_strip_start[1] = lvi_ID_v_start;
385
386 m_phi[ii]=(lvi_ID_x_pre+lvi_ID_x_post)/2*lvd_W_pitch_x;
387 m_v[ii] =(lvi_ID_v_pre+lvi_ID_v_post)/2*lvd_W_pitch_v;
388 m_layer[ii]=lvi_ID_layer;
389 m_sheet[ii]=lvi_ID_sheet_pre;
390 }
391
392 else
393 {
394 if(printFlag)
395 log<< MSG::INFO << "CgemSim::BesCgemDigitizer::Digitize(), Step in different sheet!" << endreq;
396
397 lvi_case = 1;
399 lvi_ID_sheet_pre , lvd_x_pre , lvd_v_pre ,
400 lvi_ID_sheet_post, lvd_x_post, lvd_v_post,
401 lvi_ID_sheet_mid_pre , lvi_ID_x_mid_pre , lvi_ID_v_mid_pre,
402 lvi_ID_sheet_mid_post , lvi_ID_x_mid_post , lvi_ID_v_mid_post);
403
405 lvi_ID_x_mid_pre , lvi_ID_v_mid_pre ,
406 lvi_N_hit_strip_x_pre , lvi_N_hit_strip_v_pre ,
407 lvi_ID_x_start_pre , lvi_ID_v_start_pre );
408
410 lvi_ID_x_mid_post , lvi_ID_v_mid_post ,
411 lvi_N_hit_strip_x_post , lvi_N_hit_strip_v_post ,
412 lvi_ID_x_start_post , lvi_ID_v_start_post );
413
414 if(m_F_ntuple){
415 m_phi[ii]=(lvi_ID_x_pre+lvi_ID_x_mid_pre)/2*0.65;
416 m_v[ii] =(lvi_ID_v_pre+lvi_ID_v_mid_pre)/2*0.65;
417 m_layer[ii]=lvi_ID_layer;
418 m_sheet[ii]=lvi_ID_sheet_mid_pre;
419 }
420
421 lvi_N_hit_strip[0] = lvi_N_hit_strip_x_pre + lvi_N_hit_strip_x_post;
422 lvi_N_hit_strip[1] = lvi_N_hit_strip_v_pre + lvi_N_hit_strip_v_post;
423 lvi_N_hit_strip_pre[0] = lvi_N_hit_strip_x_pre;
424 lvi_N_hit_strip_pre[1] = lvi_N_hit_strip_v_pre;
425 lvi_ID_strip_start_pre[0] = lvi_ID_x_start_pre;
426 lvi_ID_strip_start_pre[1] = lvi_ID_v_start_pre;
427 lvi_ID_strip_start_post[0] = lvi_ID_x_start_post;
428 lvi_ID_strip_start_post[1] = lvi_ID_v_start_post;
429 }
430
431
432
433 if (m_F_printHitStrip == 1)
434 {
435 log<< MSG::INFO << " " << endreq;
436 log<< MSG::INFO << "CgemSim::BesCgemDigitizer::Digitize(), Hit strip information:"
437 << endreq;
438 log<< MSG::INFO << "PreSheet "
439 << "PostSheet "
440 << "PreX "
441 << "PostX "
442 << "PreV "
443 << "PostV "
444 << "N_X "
445 << "N_V "
446 << "StartX "
447 << "StartV "
448 << endreq;
449 log<< MSG::INFO << left << setw( 9) << lvi_ID_sheet_pre
450 << left << setw(10) << lvi_ID_sheet_post
451 << left << setw( 5) << lvi_ID_x_pre
452 << left << setw( 6) << lvi_ID_x_post
453 << left << setw( 5) << lvi_ID_v_pre
454 << left << setw( 6) << lvi_ID_v_post
455 << left << setw( 4) << lvi_N_hit_strip[0]
456 << left << setw( 4) << lvi_N_hit_strip[1]
457 << left << setw( 7) << lvi_ID_strip_start[0]
458 << left << setw( 7) << lvi_ID_strip_start[1]
459 << endreq;
460 log<< MSG::INFO << " " << endreq;
461 }
462
463
464 lvd_E_average = lvd_E_deposit / (lvi_N_hit_strip[0] + lvi_N_hit_strip[1]);
465
466
467 if (m_F_printDigi == 1)
468 {
469 log<< MSG::INFO << "CgemSim::BesCgemDigitizer::Digitize(), Digi information:" << endreq;
470 log<< MSG::INFO << left << setw( 8) << "TrackID "
471 << left << setw( 8) << "LayerID "
472 << left << setw( 8) << "SheetID "
473 << left << setw( 8) << "X-0,V-1 "
474 << left << setw( 8) << "StripID "
475 << left << setw(16) << "GlobalTime "
476 << left << setw(16) << "EnergyDeposit "
477 << endreq;
478 }
479
480
481 vector<int> ident_tmp;
482
483
484
485 for (G4int jj=0; jj<2; jj++)
486 {
487 for (G4int kk=0; kk<lvi_N_hit_strip[jj]; kk++)
488 {
489 if (lvi_case==0)
490 {
491
492 lvi_ID_sheet = lvi_ID_sheet_pre;
493 lvi_ID_strip = lvi_ID_strip_start[jj] + kk;
494 }
495 else
496 {
497 if (kk < lvi_N_hit_strip_pre[jj])
498 {
499
500 lvi_ID_sheet = lvi_ID_sheet_pre;
501 lvi_ID_strip = lvi_ID_strip_start_pre[jj] + kk;
502 }
503 else
504 {
505
506 lvi_ID_sheet = lvi_ID_sheet_post;
507 lvi_ID_strip = lvi_ID_strip_start_post[jj] + kk - lvi_N_hit_strip_pre[jj];
508 }
509 }
510
511
512 G4int &lvi_F_hit = m_F_hit[lvi_ID_layer][lvi_ID_sheet][jj][lvi_ID_strip];
513 if (lvi_F_hit == -1)
514 {
515 lvd_E_strip = lvd_E_average ;
516
517
518 if (lvd_E_strip >= m_E_threshold)
519 {
521
529
530 m_digi_collection->insert(lv_new_digi);
531
532 lvi_F_hit = m_digi_collection->entries() - 1;
533
534
535 unsigned int ident =
CgemID::getIntID(lvi_ID_layer,lvi_ID_sheet,jj,lvi_ID_strip);
536 ident_tmp.push_back(ident);
537
538
539
540 if (m_F_printDigi == 1)
541 {
542 G4cout << left << setw( 8) << lvi_ID_track
543 << left << setw( 8) << lvi_ID_layer
544 << left << setw( 8) << lvi_ID_sheet
545 << left << setw( 8) << jj
546 << left << setw( 8) << lvi_ID_strip
547 << left << setw(16) << lvd_global_time
548 << left << setw(16) << lvd_E_strip
549 << G4endl;
550 }
551 }
552 }
553 else
554 {
555 lvd_E_strip = (*m_digi_collection)[lvi_F_hit]->GetEnergyDeposit() + lvd_E_average;
556
557
558
559 unsigned int ident =
CgemID::getIntID(lvi_ID_layer,lvi_ID_sheet,jj,lvi_ID_strip);
561
562
563 (*m_digi_collection)[lvi_F_hit]->SetEnergyDeposit(lvd_E_strip);
564 }
565
566 }
567 }
568
569
570 int array_tmp[2000];
571 for(unsigned int hh =0; hh < ident_tmp.size(); hh++){
572 array_tmp[hh] = ident_tmp[hh];
573 }
575
576
577 }
578
579 if(m_F_ntuple) m_nhit = lvi_N_hit;
580 StoreDigiCollection(m_digi_collection);
581
582 }
583 if(m_F_ntuple) m_nt1->write();
584}
double abs(const EvtComplex &c)
G4TDigiCollection< BesCgemDigi > BesCgemDigisCollection
G4THitsCollection< BesCgemHit > BesCgemHitsCollection
double sin(const BesAngle a)
double cos(const BesAngle a)
void SetLayerID(G4int f_ID_layer)
void SetGlobalTime(G4double f_global_time)
void SetStripType(G4int f_F_XV)
void SetEnergyDeposit(G4double f_E_deposit)
void SetStripID(G4int f_ID_strip)
void SetSheetID(G4int f_ID_sheet)
void SetTrackID(G4int f_ID_track)
void GetIDFromXYZ(const G4int f_ID_layer, const G4ThreeVector f_XYZ, G4double &f_x, G4double &f_v, G4int &f_ID_sheet, G4int &f_ID_x, G4int &f_ID_v)
void DoLorentzDiffusion(const G4int f_ID_layer, G4ThreeVector &f_XYZ_pre, G4ThreeVector &f_XYZ_post, const int f_F_print=0)
void GetIDFromSegmentInSameSheet(const G4int f_ID_x_pre, const G4int f_ID_v_pre, const G4int f_ID_x_post, const G4int f_ID_v_post, G4int &f_N_hit_strip_x, G4int &f_N_hit_strip_v, G4int &f_ID_x_start, G4int &f_ID_v_start)
void GetMiddleIDFromSegmentCrossedSheet(const G4int f_ID_layer, const G4int f_ID_sheet_pre, const G4double f_x_pre, const G4double f_v_pre, const G4int f_ID_sheet_post, const G4double f_x_post, const G4double f_v_post, G4int &f_ID_sheet_mid_pre, G4int &f_ID_x_mid_pre, G4int &f_ID_v_mid_pre, G4int &f_ID_sheet_mid_post, G4int &f_ID_x_mid_post, G4int &f_ID_v_mid_post)
G4ThreeVector GetPositionOfPrePoint() const
void AddIdentifier(G4int f_ID_Identifier[2000], G4int N_dim)
G4double GetGlobalTime() const
G4ThreeVector GetPositionOfPostPoint() const
G4double GetTotalEnergyDeposit() const
double getWidthOfPitchV() const
double getLengthOfCgemLayer() const
double getInnerROfAnode() const
int getNumberOfSheet() const
double getWidthOfSheet() const
double getAngleOfStereo() const
double getWidthOfPitchX() const
CgemGeoLayer * getCgemLayer(int i) const
static value_type getIntID(unsigned int f_layer, unsigned int f_sheet, unsigned int f_strip_type, unsigned int f_strip)