Skip to content
Snippets Groups Projects
Commit 4ed68ed1 authored by Vangelis Kourlitis's avatar Vangelis Kourlitis Committed by Marilena Bandieramonte
Browse files

sqrt calculation optimization and few more counters addition on...

sqrt calculation optimization and few more counters addition on SwitchingFieldManager. counters disabled at the moment.
parent 3ece5b6b
No related branches found
No related tags found
No related merge requests found
......@@ -38,6 +38,9 @@ class SwitchingFieldManager : public G4FieldManager
G4double m_Zmax = 1000;
G4int counterON = 0;
G4int counterOFF = 0;
G4int counterNothingOutside = 0;
G4int counterNothingInside = 0;
G4int counterWTF = 0;
G4int counterFieldExist = 0;
G4int counterFieldNotExist = 0;
};
......
......@@ -22,6 +22,9 @@ SwitchingFieldManager::~SwitchingFieldManager()
std::cout<<"Destructor SwitchingFieldManager. \nStatistics:"<<std::endl;
std::cout<<"N. of times turned field OFF: "<<counterOFF<<std::endl;
std::cout<<"N. of times turned field ON: "<<counterON<<std::endl;
std::cout<<"N. of times do nothing INSIDE: "<<counterNothingInside<<std::endl;
std::cout<<"N. of times do nothing OUTSIDE: "<<counterNothingOutside<<std::endl;
std::cout<<"N. of WTF: "<<counterWTF<<std::endl;
std::cout<<"N. of times field exists: "<<counterFieldExist<<std::endl;
std::cout<<"N. of times field does not exist: "<<counterFieldNotExist<<std::endl;
std::cout<<"============== "<<std::endl;
......@@ -42,30 +45,49 @@ void SwitchingFieldManager::ConfigureForTrack(const G4Track * track)
const G4ThreeVector position = track->GetPosition();
// const G4double rXY = position.rho(); // or .perp() sqrt(x*x + y*y)
const G4double rXY = sqrt(position.x()*position.x() + position.y()*position.y()); // according to JA this should be faster
const G4double Z = position.z();
const G4double dOffset = 100.0; // 'zero field area' dOffset mm away of the Calo boudaries
// const G4double rXY = position.rho(); // or .perp() sqrt(x*x + y*y) // according to JA this is slow
const G4double r2XY = position.x()*position.x() + position.y()*position.y();
const G4double Z = position.z();
const G4double dOffset = 100.0; // 'zero field area' dOffset mm away of the Calo boudaries
const G4double r2Min = (m_radiusXYmin + dOffset)*(m_radiusXYmin + dOffset);
const G4double r2Max = (m_radiusXYmax - dOffset)*(m_radiusXYmax - dOffset);
// const bool outSide = rXY > m_radiusXYmax; outSide -> inSide
const bool inSide = (rXY > m_radiusXYmin + dOffset) && (rXY < m_radiusXYmax - dOffset) && (abs(Z) < m_Zmax - dOffset);
const bool inSide = (r2XY > r2Min) && (r2XY < r2Max) && (abs(Z) < m_Zmax - dOffset);
if ( inSide && DoesFieldExist() && !isMuonTrack) {
ChangeDetectorField( nullptr );
}
else if ( !inSide && !DoesFieldExist() ) {
ChangeDetectorField( m_savedField );
}
/* sanity checks
if(DoesFieldExist()) counterFieldExist++;
else counterFieldNotExist++;
if( inSide && DoesFieldExist() && !isMuonTrack) // GetDetectorField() != nullptr
{
ProposeDetectorField( nullptr );
//G4cout.setf( std::ios_base::fmtflags(0), std::ios_base::floatfield );
//G4cout << "Switching field OFF at Rxy= " << rXY << " and Z=" << Z << G4endl;
counterOFF++;
if ( !inSide && DoesFieldExist() ) {
// std::cout<<"Field is ON. I do NOTHING!"<<std::endl;
counterNothingOutside++;
}
else if ( !inSide && !DoesFieldExist() ) {
// std::cout<<"Field has been turned ON!"<<std::endl;
ChangeDetectorField( m_savedField );
counterON++;
}
else if ( !inSide && !DoesFieldExist() )
{
ProposeDetectorField( m_savedField );
//G4cout.setf( std::ios_base::fmtflags(0), std::ios_base::floatfield );
//G4cout << "Switching field ON at Rxy= " << rXY << " and Z=" << Z << G4endl;
counterON++;
else if ( inSide && DoesFieldExist() ) {
// std::cout<<"Field has been turned OFF!"<<std::endl;
ChangeDetectorField( nullptr );
counterOFF++;
}
else if ( inSide && !DoesFieldExist() ) {
// std::cout<<"Field is OFF. I do NOTHING!"<<std::endl;
counterNothingInside++;
}
else counterWTF++;
*/
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment