84 for ( G4int part = 0; part < 3; part++ )
86 for ( G4int seg = 0; seg < 8; seg++ )
88 for ( G4int gap = 0; gap < 9; gap++ )
90 m_noise[part][seg][gap] = 1;
95 G4cout <<
"filename: " << filename << G4endl;
96 std::ifstream fin( filename );
97 if ( !fin ) { G4cout <<
"error opening muc_noise data" << G4endl; }
99 fin.getline( buffer, 200,
'\n' );
100 std::istringstream stringBuf( buffer );
103 G4int tot_NoDaughter = logicalMuc->GetNoDaughters();
105 for ( G4int i = 0; i < tot_NoDaughter; i++ )
107 G4LogicalVolume* i_LogicalGap = logicalMuc->GetDaughter( i )->GetLogicalVolume();
108 G4String i_GapName = i_LogicalGap->GetName();
110 if ( i_GapName.find(
"G" ) == 8 )
112 G4LogicalVolume* i_LogicalBox = i_LogicalGap->GetDaughter( 0 )->GetLogicalVolume();
113 G4LogicalVolume* i_LogicalStripPlane =
114 i_LogicalBox->GetDaughter( 0 )->GetLogicalVolume();
117 G4String strPart = i_GapName.substr( 5, 1 );
118 G4String strSeg = i_GapName.substr( 7, 1 );
119 G4String strGap = i_GapName.substr( 9, 1 );
121 std::istrstream partBuf( strPart.c_str(), strlen( strPart.c_str() ) );
122 std::istrstream segBuf( strSeg.c_str(), strlen( strSeg.c_str() ) );
123 std::istrstream gapBuf( strGap.c_str(), strlen( strGap.c_str() ) );
125 G4int part, seg, gap;
132 G4int tot_NoStrip = i_LogicalStripPlane->GetNoDaughters();
133 area[part][seg][gap][0] = tot_NoStrip;
134 G4float tot_Area = 0;
136 G4LogicalVolume* i_LogicalStrip1 =
137 i_LogicalStripPlane->GetDaughter( 1 )->GetLogicalVolume();
138 G4LogicalVolume* i_LogicalStrip2 =
139 i_LogicalStripPlane->GetDaughter( 2 )->GetLogicalVolume();
143 temp1 = (G4Box*)i_LogicalStrip1->GetSolid();
144 temp2 = (G4Box*)i_LogicalStrip2->GetSolid();
145 G4float Width1 = temp1->GetXHalfLength() * 2;
146 G4float Width2 = temp2->GetXHalfLength() * 2;
147 G4float pos1 = i_LogicalStripPlane->GetDaughter( 1 )->GetObjectTranslation().x();
148 G4float pos2 = i_LogicalStripPlane->GetDaughter( 2 )->GetObjectTranslation().x();
149 if ( ( part == 1 && gap % 2 != 0 ) || ( part != 1 && gap % 2 == 0 ) )
151 Width1 = temp1->GetYHalfLength() * 2;
152 Width2 = temp2->GetYHalfLength() * 2;
153 pos1 = i_LogicalStripPlane->GetDaughter( 1 )->GetObjectTranslation().y();
154 pos2 = i_LogicalStripPlane->GetDaughter( 2 )->GetObjectTranslation().y();
156 G4float width_between_strip = pos2 - pos1 - Width1 / 2 - Width2 / 2;
161 for ( G4int j = 0; j < tot_NoStrip; j++ )
163 G4LogicalVolume* i_LogicalStrip =
164 i_LogicalStripPlane->GetDaughter( j )->GetLogicalVolume();
166 temp = (G4Box*)i_LogicalStrip->GetSolid();
167 G4float
Width = temp->GetXHalfLength() * 2;
168 G4float Length = temp->GetYHalfLength() * 2;
169 if ( ( part == 1 && gap % 2 != 0 ) || ( part != 1 && gap % 2 == 0 ) )
171 Width = temp->GetYHalfLength() * 2;
172 Length = temp->GetXHalfLength() * 2;
176 if ( j == 0 || j == ( tot_NoStrip - 1 ) )
Width =
Width + width_between_strip / 2;
178 G4float Strip_Area = fabs(
Width * Length );
179 tot_Area = tot_Area + Strip_Area;
180 area[part][seg][gap][j + 1] = tot_Area;
181 strip_area[part][seg][gap][j] = Strip_Area;
187 box_area[part][seg][gap] = tot_Area;
189 for ( G4int k = 1; k < tot_NoStrip + 1; k++ )
191 area[part][seg][gap][k] = area[part][seg][gap][k] / tot_Area;
245 m_noiseLevel = m_ptrCalibSvc->getLevel();
247 for (
int i = 0; i < m_kPart; i++ )
249 for (
int j = 0; j < m_kSegment[i]; j++ )
251 for (
int k = 0; k < m_kGap[i]; k++ )
253 if ( m_noiseLevel == 2 )
256 for ( G4int ii = 0; ii < hitNum; ii++ )
261 bool noiseHitExist =
false;
262 noiseHitExist =
IsExist( noiseHit, MucHitList );
263 MucHitCollection->insert( noiseHit );
264 if ( !noiseHitExist )
266 MucHitList->insert( noiseHit2 );
272 else delete noiseHit2;
276 if ( m_noiseLevel == 3 )
278 int stripNum = m_ptrIdTr->GetStripMax( i, j, k );
279 for (
int strip = 0; strip < stripNum; strip++ )
281 G4int hitNum =
NoiseSampling( m_noiseLevel, i, j, k, strip );
286 bool noiseHitExist =
false;
287 noiseHitExist =
IsExist( noiseHit, MucHitList );
288 MucHitCollection->insert( noiseHit );
289 if ( !noiseHitExist )
291 MucHitList->insert( noiseHit2 );
297 else delete noiseHit2;
314 random = G4UniformRand();
315 for (
int i = 0; i < 20; i++ )
317 if ( random < m_Prob[i][1] )
326 int prt, seg, lay, str, tmp_strip;
327 G4float nosRatio = 0.;
329 for (
int i = 0; i < noiseNum; i++ )
332 random = G4UniformRand();
333 tmp_strip = TMath::Nint( random * STRIP_MAX );
334 m_ptrIdTr->SetStripPos( tmp_strip, &
prt, &seg, &lay, &str );
335 nosRatio = m_ptrCalibSvc->getNosRatio(
prt, seg, lay, str );
336 random = G4UniformRand();
337 if ( random < nosRatio )
break;
346 bool noiseHitExist =
false;
347 noiseHitExist =
IsExist( noiseHit, MucHitList );
348 MucHitCollection->insert( noiseHit );
349 if ( !noiseHitExist ) MucHitList->insert( noiseHit2 );
350 else delete noiseHit2;
417 G4float random = ( rand() % 100000 ) / 100000.0;
420 G4float width = area[part][seg][gap][3] - area[part][seg][gap][2];
421 stripno = G4int( ( random - area[part][seg][gap][1] ) / width ) + 2;
422 if ( stripno < 1 ) stripno = 1;
423 if ( stripno > 111 ) stripno = 111;
438 G4int
max,
min, mid, pass;
440 max = area[part][seg][gap][0];
441 mid = G4int( (
min +
max ) / 2 );
448 if ( random > area[part][seg][gap][mid] )
451 mid = G4int( (
min +
max ) / 2 );
453 else if ( random < area[part][seg][gap][mid - 1] )
455 if ( random < area[part][seg][gap][1] )
464 mid = G4int( (
min +
max ) / 2 );
469 if (
min == mid ) mid =
max;
471 }
while ( pass == 0 && (
max > mid && mid >
min ) );