115 {
116
117
118 G4Track* currentTrack = currentStep->GetTrack();
119 if ( !currentTrack )
120 {
121 cout << "Can't get currentTrack" << endl;
122 return;
123 }
124 G4TrackStatus currentTrackStatus = currentTrack->GetTrackStatus();
125
126 int stepNumber = currentTrack->GetCurrentStepNumber();
127 if ( msgFlag ) cout << "STEP " << stepNumber << ":" << endl;
128
129
130 Hep3Vector currentPosition = currentTrack->GetPosition();
131 Hep3Vector currentMomentum = currentTrack->GetMomentum();
132
133
134 G4VPhysicalVolume* oldVolume = nullptr;
135 G4VPhysicalVolume* newVolume = nullptr;
136 if ( !currentTrack->GetTouchableHandle() )
137 cout << "Can't get currentTrack->GetTouchableHandle()" << endl;
138 else oldVolume = currentTrack->GetTouchableHandle()->GetVolume();
139 if ( !currentTrack->GetNextTouchableHandle() )
140 cout << "Can't get currentTrack->GetNextTouchableHandle()" << endl;
141 else newVolume = currentTrack->GetNextTouchableHandle()->GetVolume();
142 if ( !oldVolume ) cout << "Can't get oldVolume!" << endl;
143
144
145 if ( stepNumber > 50000 )
146 {
147 cout << "infinite steps in the track " << endl;
148 currentTrack->SetTrackStatus( fStopAndKill );
149 m_trackstop = true;
150 }
151
152 G4String ParticleName = currentTrack->GetDefinition()->GetParticleName();
153 double x_ = currentPosition.x();
154 double y_ = currentPosition.y();
155 double z_ = currentPosition.z();
156 bool inner =
157 ( oldVolume != newVolume ) &&
158 ( !( ( fabs( x_ ) >= myMucR ) || ( fabs( y_ ) >= myMucR ) ||
159 ( ( fabs( x_ - y_ ) / sqrt( 2. ) ) >= myMucR ) ||
160 ( ( fabs( x_ + y_ ) / sqrt( 2. ) ) >= myMucR ) || ( fabs( z_ ) >= myMucZ ) ) );
161 bool mucdec = ( fabs( x_ ) >= myMucR ) || ( fabs( y_ ) >= myMucR ) ||
162 ( ( fabs( x_ - y_ ) / sqrt( 2. ) ) >= myMucR ) ||
163 ( ( fabs( x_ + y_ ) / sqrt( 2. ) ) >= myMucR ) || ( fabs( z_ ) >= myMucZ );
164
165
166 if ( currentTrackStatus == fAlive )
167 {
168
169 if ( inner || mucdec )
170
171 {
172
173 double currentPoint[3] = { currentPosition.x(), currentPosition.y(),
174 currentPosition.z() };
175 double currentBfield[3] = { 0.0, 0.0, 0.0 };
176 Hep3Vector currentB( 0.0, 0.0, 1.0 );
177 if ( G4TransportationManager::GetTransportationManager() )
178 {
179 G4FieldManager* fieldManager =
180 G4TransportationManager::GetTransportationManager()->GetFieldManager();
181 if ( fieldManager )
182 {
183 if ( fieldManager->GetDetectorField() )
184 {
185 fieldManager->GetDetectorField()->GetFieldValue( currentPoint, currentBfield );
186 currentB.set( currentBfield[0] / tesla, currentBfield[1] / tesla,
187 currentBfield[2] / tesla );
188 if ( msgFlag )
189 cout << "B:" << currentB.x() << "," << currentB.y() << "," << currentB.z()
190 << endl;
191 }
192 }
193 }
194
195
196 G4Material* oldMaterial = oldVolume->GetLogicalVolume()->GetMaterial();
197 if ( !oldMaterial ) std::cout << "Can't get oldMaterial" << std::endl;
198 else CalculateChicc( oldMaterial );
199
200
201 if ( !( extXpErr->move( currentPosition, currentMomentum, currentB, 1, chicc ) ) )
202 if ( msgFlag ) cout << "can not update Error Matrix!!" << endl;
203
204
205 if ( msgFlag )
206 {
207 cout << "Volume name:" << newVolume->GetName() << endl;
208 cout << "Volume number:" << newVolume->GetCopyNo() << endl;
209 cout << "x:" << currentPoint[0] << "//y:" << currentPoint[1]
210 << "//z:" << currentPoint[2] << "||px:" << currentMomentum.x()
211 << "//py:" << currentMomentum.y() << "//pz:" << currentMomentum.z() << endl;
212 cout << "ptot = " << currentMomentum.mag() << endl;
213 cout << "trk len = " << currentTrack->GetTrackLength() << endl;
214 cout << "Error matrix is:" << extXpErr->get_err() << endl;
215 cout << "phi:" << atan( currentPoint[1] / currentPoint[0] ) << endl;
216 Hep3Vector nz( 0., 0., 1. );
217 cout << "Projected z error:" << extXpErr->get_plane_err( currentMomentum.unit(), nz )
218 << endl;
221 y = currentPoint[1];
222 R = sqrt(
x *
x + y * y );
223 Hep3Vector nt( -y / R,
x / R, 0. );
224 cout << "Projected phi error:"
225 << ( extXpErr->get_plane_err( currentMomentum.unit(), nt ) ) /
R << endl
226 << endl;
227 }
228
229
230 Hep3Vector xVector( 1.0, 0, 0 );
231 Hep3Vector yVector( 0, 1.0, 0 );
232 Hep3Vector zVector( 0, 0, 1.0 );
233 Hep3Vector tzVector;
234 tzVector.setRThetaPhi( 1.0,
M_PI / 2.0, currentPosition.phi() );
235 double r = currentPosition.perp();
236 double x = currentPosition.x();
237 double y = currentPosition.y();
238 double z = currentPosition.z();
239 G4String newVolumeName = newVolume->GetName();
240 G4String oldVolumeName = oldVolume->GetName();
241 G4StepPoint* postStepPoint = currentStep->GetPostStepPoint();
242 G4TouchableHistory* theTouchable =
243 (G4TouchableHistory*)( postStepPoint->GetTouchable() );
244 int newVolumeNumber = newVolume->GetCopyNo();
245
246
247 G4String name1;
248 if ( newVolumeName == "logical_gasLayer" )
249 {
250 name1 = theTouchable->GetVolume( 3 )->GetName();
251 newVolumeNumber = theTouchable->GetReplicaNumber( 3 );
252 }
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293 if ( ( !myTof1Flag ) &&
294 ( newVolumeName == "logicalScinBr1" || newVolumeName.contains( "ScinEc" ) ||
295 ( newVolumeName == "logical_gasLayer" &&
296 ( name1 == "logical_container_m0" || name1 == "logical_container_m1" ) ) ) )
297 {
298 double currentTrackLength = currentTrack->GetTrackLength();
299 double totalTrackLength = currentTrackLength + initialPath;
300 double localTime = currentTrack->GetLocalTime();
301 double totalTOF = localTime + initialTof;
302 myInTof1 = true;
303 myPathIntoTof1 = currentTrackLength;
304 if ( msgFlag ) cout << "myPathIntoTof1 = " << myPathIntoTof1 << endl;
305
306 newVolumeNumber = theTouchable->GetReplicaNumber( 2 );
307
308 if ( newVolumeName.contains( "ScinEc" ) )
309 {
310 newVolumeNumber = ( 95 - newVolumeNumber ) / 2;
311 newVolumeNumber = newVolumeNumber + 176;
312
313 if ( newVolumeName.contains( "East" ) ) newVolumeNumber = newVolumeNumber + 48;
314 if ( myExtTrack )
315 {
316 double xError = extXpErr->get_plane_err( currentMomentum.unit(), xVector );
317 double yError = extXpErr->get_plane_err( currentMomentum.unit(), yVector );
318 double zError = extXpErr->get_plane_err( currentMomentum.unit(), zVector );
319 double tzError = extXpErr->get_plane_err( currentMomentum.unit(), tzVector );
320 myExtTrack->SetTof1Data(
321 currentPosition / 10, currentMomentum / 1000, newVolumeName, newVolumeNumber,
322 totalTOF, totalTrackLength / 10, myOutputSymMatrix( extXpErr->get_err() ),
323 zError / 10, tzError / 10, xError / 10, yError / 10 );
324 myTof1Flag = true;
325 }
326 }
327
328 else if ( newVolumeName == "logical_gasLayer" )
329 {
330 G4ThreeVector currentPostPosition = currentStep->GetPostStepPoint()->GetPosition();
331 G4ThreeVector localPosition =
332 theTouchable->GetHistory()->GetTopTransform().TransformPoint(
333 currentPostPosition );
334
335
336
337
338
339
340 double z_mm = localPosition.z() - 0.5 + ( 24 + 3 ) * 6;
341 int strip;
342 if ( z_mm <= 0 ) { strip = 0; }
343 else if ( z_mm > 0 && z_mm < 12 * 27 ) { strip = floor( z_mm / 27 ); }
344 else { strip = 11; }
345 if ( strip < 0 ) strip = 0;
346 if ( strip > 11 ) strip = 11;
347
348 newVolumeNumber = theTouchable->GetReplicaNumber( 3 );
349 newVolumeNumber = 35 - newVolumeNumber;
350 if ( currentPosition.z() < 0.0 ) { newVolumeNumber = newVolumeNumber + 36; }
351 newVolumeNumber = 12 * newVolumeNumber + strip;
352 newVolumeNumber = newVolumeNumber + 176 + 96;
353 if ( myExtTrack )
354 {
355 double xError = extXpErr->get_plane_err( currentMomentum.unit(), xVector );
356 double yError = extXpErr->get_plane_err( currentMomentum.unit(), yVector );
357 double zError = extXpErr->get_plane_err( currentMomentum.unit(), zVector );
358 double tzError = extXpErr->get_plane_err( currentMomentum.unit(), tzVector );
359 Hep3Vector locP =
360 Hep3Vector( localPosition.x(), localPosition.y(), localPosition.z() );
361
362
363
364
365
366 myExtTrack->SetTof1Data( locP / 10, currentMomentum / 1000, newVolumeName,
367 newVolumeNumber, totalTOF, totalTrackLength / 10,
368 myOutputSymMatrix( extXpErr->get_err() ), zError / 10,
369 tzError / 10, xError / 10, yError / 10 );
370 myTof1Flag = true;
371 }
372 }
373 else
374 {
375 newVolumeNumber = ( 527 - newVolumeNumber ) / 3;
376 if ( myExtTrack )
377 {
378 double xError = extXpErr->get_plane_err( currentMomentum.unit(), xVector );
379 double yError = extXpErr->get_plane_err( currentMomentum.unit(), yVector );
380 double zError = extXpErr->get_plane_err( currentMomentum.unit(), zVector );
381 double tzError = extXpErr->get_plane_err( currentMomentum.unit(), tzVector );
382 myExtTrack->SetTof1Data(
383 currentPosition / 10, currentMomentum / 1000, newVolumeName, newVolumeNumber,
384 totalTOF, totalTrackLength / 10, myOutputSymMatrix( extXpErr->get_err() ),
385 zError / 10, tzError / 10, xError / 10, yError / 10 );
386 myTof1Flag = true;
387 }
388 }
389
390 return;
391
392 }
393
394 if ( myInTof1 &&
395 ( oldVolumeName == "logicalScinBr1" || oldVolumeName.contains( "ScinEc" ) ||
396 ( oldVolumeName == "logical_gasLayer" &&
397 ( name1 == "logical_container_m0" || name1 == "logical_container_m1" ) ) ) )
398 {
399 myInTof1 = false;
400 myOutTof1 = true;
401 myPathOutTof1 = currentTrack->GetTrackLength();
402 myPathInTof1.push_back( myPathOutTof1 - myPathIntoTof1 );
403 if ( msgFlag ) cout << "myPathOutTof1 = " << myPathOutTof1 << endl;
404 }
405
406 if ( myOutTof1 &&
407 ( newVolumeName == "logicalScinBr1" || newVolumeName.contains( "ScinEc" ) ||
408 ( newVolumeName == "logical_gasLayer" &&
409 ( name1 == "logical_container_m0" || name1 == "logical_container_m1" ) ) ) )
410 {
411 myInTof1 = true;
412 myOutTof1 = false;
413 myPathIntoTof1 = currentTrack->GetTrackLength();
414 if ( msgFlag ) cout << "myPathIntoTof1 = " << myPathIntoTof1 << endl;
415 }
416
417
418 if ( ( !myTof2Flag ) &&
419 ( newVolumeName == "logicalScinBr2" ||
420 ( newVolumeName == "logical_gasLayer" &&
421 ( name1 == "logical_container_m2" || name1 == "logical_container_m3" ) ) ) )
422 {
423 double currentTrackLength = currentTrack->GetTrackLength();
424 double totalTrackLength = currentTrackLength + initialPath;
425
426 double localTime = currentTrack->GetLocalTime();
427 double totalTOF = localTime + initialTof;
428 myInTof2 = true;
429 myPathIntoTof2 = currentTrackLength;
430 if ( msgFlag ) cout << "myPathIntoTof2 = " << myPathIntoTof2 << endl;
431 newVolumeNumber = theTouchable->GetReplicaNumber( 2 );
432
433 if ( newVolumeName == "logical_gasLayer" )
434 {
435 G4ThreeVector currentPostPosition = currentStep->GetPostStepPoint()->GetPosition();
436 G4ThreeVector localPosition =
437 theTouchable->GetHistory()->GetTopTransform().TransformPoint(
438 currentPostPosition );
439
440
441
442
443
444
445 double z_mm = localPosition.z() - 0.5 + ( 24 + 3 ) * 6;
446 int strip;
447 if ( z_mm <= 0 ) { strip = 0; }
448 else if ( z_mm > 0 && z_mm < 12 * 27 ) { strip = floor( z_mm / 27 ); }
449 else { strip = 11; }
450 if ( strip < 0 ) strip = 0;
451 if ( strip > 11 ) strip = 11;
452
453 newVolumeNumber = theTouchable->GetReplicaNumber( 3 );
454 newVolumeNumber = 35 - newVolumeNumber;
455 if ( currentPosition.z() < 0.0 ) { newVolumeNumber = newVolumeNumber + 36; }
456 newVolumeNumber = 12 * newVolumeNumber + strip;
457 newVolumeNumber = newVolumeNumber + 176 + 96;
458
459 if ( myExtTrack )
460 {
461 double xError = extXpErr->get_plane_err( currentMomentum.unit(), xVector );
462 double yError = extXpErr->get_plane_err( currentMomentum.unit(), yVector );
463 double zError = extXpErr->get_plane_err( currentMomentum.unit(), zVector );
464 double tzError = extXpErr->get_plane_err( currentMomentum.unit(), tzVector );
465 Hep3Vector locP =
466 Hep3Vector( localPosition.x(), localPosition.y(), localPosition.z() );
467
468
469
470
471
472 myExtTrack->SetTof2Data( locP / 10, currentMomentum / 1000, newVolumeName,
473 newVolumeNumber, totalTOF, totalTrackLength / 10,
474 myOutputSymMatrix( extXpErr->get_err() ), zError / 10,
475 tzError / 10, xError / 10, yError / 10 );
476 myTof2Flag = true;
477 }
478 }
479 else
480 {
481 newVolumeNumber = ( 527 - newVolumeNumber ) / 3;
482 if ( myExtTrack )
483 {
484 double xError = extXpErr->get_plane_err( currentMomentum.unit(), xVector );
485 double yError = extXpErr->get_plane_err( currentMomentum.unit(), yVector );
486 double zError = extXpErr->get_plane_err( currentMomentum.unit(), zVector );
487 double tzError = extXpErr->get_plane_err( currentMomentum.unit(), tzVector );
488 myExtTrack->SetTof2Data(
489 currentPosition / 10, currentMomentum / 1000, newVolumeName, newVolumeNumber,
490 totalTOF, totalTrackLength / 10, myOutputSymMatrix( extXpErr->get_err() ),
491 zError / 10, tzError / 10, xError / 10, yError / 10 );
492 myTof2Flag = true;
493 }
494 }
495 return;
496 }
497
498 if ( myInTof2 &&
499 ( oldVolumeName == "logicalScinBr2" ||
500 ( oldVolumeName == "logical_gasLayer" &&
501 ( name1 == "logical_container_m2" || name1 == "logical_container_m3" ) ) ) )
502 {
503 myInTof2 = false;
504 myOutTof2 = true;
505 myPathOutTof2 = currentTrack->GetTrackLength();
506 myPathInTof2.push_back( myPathOutTof2 - myPathIntoTof2 );
507 if ( msgFlag ) cout << "myPathOutTof2 = " << myPathOutTof2 << endl;
508 }
509
510 if ( myOutTof2 &&
511 ( newVolumeName == "logicalScinBr2" ||
512 ( newVolumeName == "logical_gasLayer" &&
513 ( name1 == "logical_container_m2" || name1 == "logical_container_m3" ) ) ) )
514 {
515 myInTof2 = true;
516 myOutTof2 = false;
517 myPathIntoTof2 = currentTrack->GetTrackLength();
518 if ( msgFlag ) cout << "myPathIntoTof2 = " << myPathIntoTof2 << endl;
519 }
520
521
522 if ( ( !myPhyEmcFlag ) && ( !myEmcFlag ) &&
523 ( newVolumeName == "EMC" || newVolumeName.contains( "BSC" ) ||
524 newVolumeName == "EndPhi" ) )
525 {
526 newVolumeNumber = -2;
527 if ( myExtTrack )
528 {
529
530 Hep3Vector
nPhi( -y / r,
x / r, 0. );
531 double errorPhi = ( extXpErr->get_plane_err( currentMomentum.unit(),
nPhi ) ) / r;
532
533 Hep3Vector aPosition = currentPosition;
534 double R = aPosition.r();
535 double aTheta = aPosition.theta();
536 aPosition.setTheta( aTheta + M_PI_2 );
537 double errorTheta;
538 errorTheta =
539 ( extXpErr->get_plane_err( currentMomentum.unit(), aPosition.unit() ) ) /
R;
540 if ( msgFlag ) cout << "Theta direction: " << aPosition << endl;
541 myExtTrack->SetEmcData( currentPosition / 10, currentMomentum / 1000, newVolumeName,
542 newVolumeNumber, errorTheta, errorPhi,
543 myOutputSymMatrix( extXpErr->get_err() ) );
544 }
545 myPhyEmcFlag = true;
546 return;
547 }
548
549 if ( !myEmcPathFlag && newVolumeName.contains( "Crystal" ) )
550 {
551 myPathIntoCrystal = currentTrack->GetTrackLength();
552
553 myEmcPathFlag = true;
554 }
555
556
557 if ( ( !myEmcFlag ) && newVolumeName.contains( "Crystal" ) )
558 {
559 if ( myExtTrack )
560 {
561
562 int npart, ntheta, nphi;
563 if ( currentTrack->GetNextTouchableHandle()->GetVolume( 1 )->GetName().contains(
564 "BSC" ) )
565 {
566 npart = 1;
567 std::istringstream thetaBuf(
568 ( currentTrack->GetNextTouchableHandle()->GetVolume( 1 )->GetName() )
569 .substr( 16, 2 ) );
570 thetaBuf >> ntheta;
571 nphi = 308 - currentTrack->GetNextTouchableHandle()->GetCopyNumber( 2 );
572 }
573 else
574 {
575 npart = 2 - 2 * currentTrack->GetNextTouchableHandle()->GetCopyNumber( 3 );
576 int endSector = currentTrack->GetNextTouchableHandle()->GetCopyNumber( 2 );
577 int endNb, endNbGDML;
578 std::istringstream thetaBuf(
579 ( currentTrack->GetNextTouchableHandle()->GetVolume( 0 )->GetName() )
580 .substr( 20, 2 ) );
581 thetaBuf >> endNb;
585 }
586 ostringstream strEmc;
587 if ( ntheta < 10 )
588 { strEmc << "EmcPart" << npart << "Theta0" << ntheta << "Phi" << nphi; }
589 else
590 {
591 strEmc << "EmcPart" << npart << "Theta" << ntheta << "Phi" << nphi;
592 }
593
594
595 Hep3Vector
nPhi( -y / r,
x / r, 0. );
596 double errorPhi = ( extXpErr->get_plane_err( currentMomentum.unit(),
nPhi ) ) / r;
597
598 Hep3Vector aPosition = currentPosition;
599 double R = aPosition.r();
600 double aTheta = aPosition.theta();
601 aPosition.setTheta( aTheta + M_PI_2 );
602 double errorTheta;
603 errorTheta =
604 ( extXpErr->get_plane_err( currentMomentum.unit(), aPosition.unit() ) ) /
R;
605 if ( msgFlag ) cout << "Theta direction: " << aPosition << endl;
606 myExtTrack->SetEmcData( currentPosition / 10, currentMomentum / 1000, strEmc.str(),
607 newVolumeNumber, errorTheta, errorPhi,
608 myOutputSymMatrix( extXpErr->get_err() ) );
609 }
610 myEmcFlag = true;
611 return;
612 }
613
614
615 if ( myEmcPathFlag && oldVolumeName.contains( "Crystal" ) )
616 {
617 myPathOutCrystal = currentTrack->GetTrackLength();
618 myPathInCrystal = myPathInCrystal + myPathOutCrystal - myPathIntoCrystal;
619
620 myEmcPathFlag = false;
621 }
622
623
624 if ( ( !myMucFlag ) &&
625 ( ( fabs(
x ) >= myMucR ) || ( fabs( y ) >= myMucR ) ||
626 ( ( fabs(
x - y ) / sqrt( 2. ) ) >= myMucR ) ||
627 ( ( fabs(
x + y ) / sqrt( 2. ) ) >= myMucR ) || ( fabs( z ) >= myMucZ ) ) )
628 {
629 int newVolumeNumber = newVolume->GetCopyNo();
630 if ( myExtTrack )
631 {
632 Hep3Vector xVector( 1.0, 0, 0 );
633 Hep3Vector yVector( 0, 1.0, 0 );
634 Hep3Vector zVector( 0, 0, 1.0 );
635 double xError = extXpErr->get_plane_err( currentMomentum.unit(), xVector );
636 double yError = extXpErr->get_plane_err( currentMomentum.unit(), yVector );
637 double zError = extXpErr->get_plane_err( currentMomentum.unit(), zVector );
638 double tzError = 0.0;
639 double phi = currentPosition.phi();
640 if ( phi < 0. ) phi +=
M_PI;
641 int i = int( 8.0 * phi /
M_PI );
642 if ( i == 0 || i == 7 || i == 8 ) { tzError = yError; }
643 if ( i == 1 || i == 2 )
644 {
645 Hep3Vector tzVector( -1.0, 1.0, 0. );
646 tzError = extXpErr->get_plane_err( currentMomentum.unit(), tzVector.unit() );
647 }
648 if ( i == 3 || i == 4 ) { tzError = xError; }
649 if ( i == 5 || i == 6 )
650 {
651 Hep3Vector tzVector( 1.0, 1.0, 0. );
652 tzError = extXpErr->get_plane_err( currentMomentum.unit(), tzVector.unit() );
653 }
654 myExtTrack->SetMucData( currentPosition / 10, currentMomentum / 1000, newVolumeName,
655 newVolumeNumber, myOutputSymMatrix( extXpErr->get_err() ),
656 zError / 10, tzError / 10, xError / 10, yError / 10 );
657 }
658 myMucFlag = true;
659 if ( !( ParticleName.contains( "mu" ) && myUseMucKalFlag ) )
660 {
661
662 currentStep->GetTrack()->SetTrackStatus( fStopAndKill );
663 m_trackstop = true;
664 return;
665 }
666 }
667
668
669
670
671 HepSymMatrix XpErr = extXpErr->get_err();
672 int namesize = oldVolumeName.size();
673 bool Flag1( false ), Flag2( false ), Flag3( false ), Flag4( false ), Flag5( false );
674 Flag1 = m_mucdigicol->size() > 0;
675 Flag2 = myUseMucKalFlag;
676 Flag3 = ParticleName.contains( "mu" ) && oldVolumeName.contains( "lMuc" ) &&
677 oldVolumeName.contains( "P" ) && oldVolumeName.contains( "S" ) &&
678 ( oldVolumeName.contains( "G" ) || oldVolumeName.contains( "Ab" ) );
679 Flag4 = oldVolumeName.contains( "lMuc" ) && oldVolumeName.contains( "P" ) &&
680 oldVolumeName.contains( "S" ) &&
681 ( ( namesize == 10 && oldVolumeName.contains( "G" ) ) ||
682 ( namesize == 11 && oldVolumeName.contains( "Ab" ) ) );
683 Flag5 = !( ( RemID[0] == 1 && RemID[2] == 9 ) ||
684 ( ( RemID[0] == 0 || RemID[0] == 2 ) && RemID[2] == 8 ) );
685
686 if ( Flag1 && Flag2 && Flag3 && Flag5 )
687 {
688
689 double depth = currentStep->GetStepLength();
690 if ( oldVolumeName.contains( "Ab" ) ) RemDepth = RemDepth + depth;
691 if ( RemStep == 0 && Flag4 )
692 {
693 Hep3Vector ID_1 =
GetGapID( oldVolumeName );
694 RemID = ID_1;
695
696 bool LastLay = ( ID_1[0] == 1 && ID_1[2] < 9 ) ||
697 ( ( ID_1[0] == 0 || ID_1[0] == 2 ) && ID_1[2] < 8 );
698 if ( RememberID[2] != ID_1[2] && LastLay )
699 {
701 ->
GetGap( ID_1[0], ID_1[1], ID_1[2] )
703 double dist = fabs( pos_loc.z() );
704 RemPositon = currentPosition;
705 RemMomentum = currentMomentum;
706 RemXpErr = XpErr;
707 RemDist = dist;
708 RemStep++;
709 }
710 }
711 if ( RemStep > 0 )
712 {
713 bool WillFilter = false;
714 bool LastLay_ = false;
715 double dist_b = 99999.;
716 Hep3Vector ID_2;
717 if ( Flag4 )
718 {
720 LastLay_ = ( ID_2[0] == 1 && ID_2[2] < 9 ) ||
721 ( ( ID_2[0] == 0 || ID_2[0] == 2 ) && ID_2[2] < 8 );
722 if ( LastLay_ )
724 ->GetGap( ID_2[0], ID_2[1], ID_2[2] )
725 ->TransformToGap( currentPosition )
726 .z() );
727 if ( RemID != ID_2 ) WillFilter = true;
728 }
729
731 ->
GetGap( RemID[0], RemID[1], RemID[2] )
733 double dist = fabs( pos_loc.z() );
734
735 if ( !WillFilter && RemDist > dist )
736 {
737 RemPositon = currentPosition;
738 RemMomentum = currentMomentum;
739 RemXpErr = XpErr;
740 RemDist = dist;
741 RemVol = oldVolumeName;
742 }
743
744
745 if ( WillFilter )
746 {
747 ExtMucKal* muckal = new ExtMucKal();
749 muckal->
SetPosMomErr( RemPositon, RemMomentum, RemXpErr );
753 vector<MucRecHit*> tmp = muckal->
TrackHit();
755
756 double chi2 = muckal->
GetChi2();
758 if ( filter && iniOK )
759 {
760
761 myMucnfit_++;
762
763 myMucchisq_ = myMucchisq_ + chi2;
764 muckal->
XPmod( m_pos_mod, m_mom_mod, m_err_mod );
766 if ( RememberID[0] == 1 ) myMucbrLastLay_ = RememberID[2];
767 if ( RememberID[0] == 0 || RememberID[0] == 2 ) myMucecLastLay_ = RememberID[2];
768 if ( oldVolumeName.contains( "Ab" ) ) RemDepth = RemDepth - depth;
769 if ( myMucnfit_ == 1 ) myMucdepth_ = RemDepth;
770 else myMucdepth_ = myMucdepth_ + RemDepth;
771
772 if ( !samestrip )
773 {
774
775 extXpErr->put_err( m_err_mod );
776 extXpErr->set_pos( m_pos_mod );
777 extXpErr->set_mom( m_mom_mod );
778 currentStep->GetTrack()->SetTrackStatus( fStopAndKill );
779 }
780 else
781 {
782
783 RemPositon = currentPosition;
784 RemMomentum = currentMomentum;
785 RemXpErr = XpErr;
786 RemDist = dist_b;
787 RemID = ID_2;
788 if ( oldVolumeName.contains( "Ab" ) ) RemDepth = depth;
789 else RemDepth = 0.;
790 }
791 if ( msgFlag ) cout << "---------Filter is OK---------- " << endl;
792 }
793 else
794 {
795
796
797 RemPositon = currentPosition;
798 RemMomentum = currentMomentum;
799 RemXpErr = XpErr;
800 RemDist = dist_b;
801 RemID = ID_2;
802
803 }
804 delete muckal;
805 }
806 }
807 if ( myExtTrack )
808 myExtTrack->SetMucKalData( myMucchisq_, myMucnfit_, myMucdepth_, myMucbrLastLay_,
809 myMucecLastLay_, myMucnhits_ );
810 }
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877 }
878 else
879 {
880 if ( msgFlag )
881 cout << "x:" << currentPosition.x() << "//y:" << currentPosition.y()
882 << "//z:" << currentPosition.z() << "||px:" << currentMomentum.x()
883 << "//py:" << currentMomentum.y() << "//pz:" << currentMomentum.z() << endl;
884 double x = currentPosition.x();
885 double y = currentPosition.y();
886 double z = currentPosition.z();
887 if ( ( fabs(
x ) >= 2 * myMucR ) || ( fabs( y ) >= 2 * myMucR ) ||
888 ( fabs( z ) >= 2 * myMucZ ) )
889
890
891 {
892 currentStep->GetTrack()->SetTrackStatus( fStopAndKill );
893 m_trackstop = true;
894 }
895 }
896 }
897 else if ( currentTrackStatus == fStopAndKill )
898 {
899 m_trackstop = true;
900 if ( myEmcFlag ) myExtTrack->SetEmcPath( myPathInCrystal / 10. );
901 if ( myTof1Flag ) myExtTrack->setPathInTof1( myPathInTof1 );
902 if ( myTof2Flag ) myExtTrack->setPathInTof2( myPathInTof2 );
903 if ( msgFlag )
904 {
905 cout << "myPathInTof1 = ";
906 for ( int i = 0; i != myPathInTof1.size(); i++ ) cout << myPathInTof1[i] << " ";
907 cout << endl;
908 cout << "myPathInTof2 = ";
909 for ( int i = 0; i != myPathInTof2.size(); i++ ) cout << myPathInTof2[i] << " ";
910 cout << endl;
911 }
912
913 if ( msgFlag )
914 {
915 if ( newVolume != 0 )
916 {
917 std::cout << "x:" << currentPosition.x() << "//y:" << currentPosition.y()
918 << "//z:" << currentPosition.z() << "||px:" << currentMomentum.x()
919 << "//py:" << currentMomentum.y() << "//pz:" << currentMomentum.z()
920 << "//stoped" << endl;
921 cout << "Error matrix is:" << extXpErr->get_err() << endl;
922 }
923 else
924 {
925 cout << "x:" << currentPosition.x() << "//y:" << currentPosition.y()
926 << "//z:" << currentPosition.z() << "||px:" << currentMomentum.x()
927 << "//py:" << currentMomentum.y() << "//pz:" << currentMomentum.z() << "//escaped"
928 << std::endl;
929 std::cout << "Error matrix is:" << extXpErr->get_err() << std::endl;
930 }
931 }
932 }
933}
void SetGapID(Hep3Vector id)
void SetPosMomErr(Hep3Vector pos, Hep3Vector mom, HepSymMatrix err)
void SetMucWindow(int aMucWindow)
void XPmod(Hep3Vector &pos, Hep3Vector &mom, HepSymMatrix &err)
void SetMucDigiCol(MucDigiCol *amucdigi)
vector< MucRecHit * > TrackHit()
Hep3Vector GetGapID(G4String vol)
void CalculateEmcEndThetaPhi(int npart, int sector, int nb, int &ntheta, int &nphi)
int CalculateEmcEndCopyNb(int num)
int CalculateEmcEndPhiNb(int num)
HepPoint3D TransformToGap(const HepPoint3D gPoint) const
Transform a point from global coordinate to gap coordinate.
MucGeoGap * GetGap(const int part, const int seg, const int gap) const
Get a pointer to the gap identified by (part,seg,gap).
static MucGeoGeneral * Instance()
Get a pointer to the single instance of MucGeoGeneral.
complex_t R(double Q2, double M2, double G, double Mp2, double Mm2)