Skip to content
Snippets Groups Projects

Muon upgrade Alignment

Merged Peter Noel Griffith requested to merge muon-upgrade into master
All threads resolved!
Files
10
/*****************************************************************************\
* (c) Copyright 2000-2018 CERN for the benefit of the LHCb Collaboration *
* *
* This software is distributed under the terms of the GNU General Public *
* Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". *
* *
* In applying this licence, CERN does not waive the privileges and immunities *
* granted to it by virtue of its status as an Intergovernmental Organization *
* or submit itself to any jurisdiction. *
\*****************************************************************************/
// Include files
#include <memory>
// from Gaudi
#include "GaudiKernel/SmartIF.h"
#include "GaudiKernel/SystemOfUnits.h"
#include "MuonTrackSelector.h"
using namespace LHCb;
using namespace Gaudi::Units;
// Declaration of the Algorithm Factory
DECLARE_COMPONENT( MuonTrackSelector )
//=============================================================================
// Standard constructor, initializes variables
//=============================================================================
MuonTrackSelector::MuonTrackSelector( const std::string& name, ISvcLocator* pSvcLocator )
: GaudiAlgorithm( name, pSvcLocator )
, m_tracksInputContainer( "" )
, m_tracksOutputContainer( "" )
, m_trackType( "" )
, m_trackSelectorName( "" )
, m_trackSelector( 0 ) {
declareProperty( "TracksInputContainer", m_tracksInputContainer = TrackLocation::Default );
declareProperty( "TracksOutputContainer", m_tracksOutputContainer = "Alignment/FilteredTracks" );
declareProperty( "TrackType", m_trackType = "Long" );
declareProperty( "TrackSelector", m_trackSelectorName = "AlignSelTool" );
declareProperty( "MuonPcut", m_pcut = 0. * GeV );
declareProperty( "inCaloAcceptance", m_calo = false );
declareProperty( "noOverlap", m_noOverlap = false );
declareProperty( "minHitStation", m_nStation = 2 );
declareProperty( "MuonChisquareCut", m_muonChisquareCut = 0. );
declareProperty( "TheRegion", m_theR = -1 );
}
//=============================================================================
// Initialization
//=============================================================================
StatusCode MuonTrackSelector::initialize() {
StatusCode sc = GaudiAlgorithm::initialize();
if ( sc.isFailure() ) return sc;
if ( m_tracksOutputContainer == "" )
return Error( "==> Please specify an output location for the filtered tracks", StatusCode::FAILURE );
info() << " " << endmsg << "=========== " << name() << " Settings ============" << endmsg
<< " Tracks input container : " << m_tracksInputContainer << endmsg
<< " Tracks output container : " << m_tracksOutputContainer << endmsg
<< "==================================================" << endmsg << " " << endmsg;
return StatusCode::SUCCESS;
}
//=============================================================================
// Main execution
//=============================================================================
StatusCode MuonTrackSelector::execute() {
/// Get tracks
Tracks* tracks = get<Tracks>( m_tracksInputContainer );
filterTracks( tracks );
return StatusCode::SUCCESS;
}
//=============================================================================
void MuonTrackSelector::filterMuonTrack( LHCb::Track* track, LHCb::Tracks* outputContainer ) {
//=============================================================================
debug() << " filtering with filterMuonTrack" << endmsg;
bool select = true;
if ( m_pcut && track->p() < m_pcut ) {
debug() << " Discard the track due to the low momentum" << track->p() << endmsg;
select = false; // select high momentum tracks
}
bool ASide = false;
bool CSide = false;
int MA[5] = {0, 0, 0, 0, 0};
int MC[5] = {0, 0, 0, 0, 0};
int MR[4] = {0, 0, 0, 0};
const std::vector<LHCb::LHCbID>& lhcbids = track->lhcbIDs();
for ( std::vector<LHCb::LHCbID>::const_iterator id = lhcbids.begin(); id != lhcbids.end(); ++id ) {
if ( id->isMuon() ) {
int iS = id->muonID().station();
int iR = id->muonID().region();
int iQ = id->muonID().quarter();
if ( iQ < 2 )
MA[iS] = 1; // A-side
else
MC[iS] = 1;
MR[iR]++;
}
}
int MAside = MA[0] + MA[1] + MA[2] + MA[3] + MA[4];
int MCside = MC[0] + MC[1] + MC[2] + MC[3] + MC[4];
if ( m_theR > -1 && m_theR < 4 ) {
for ( int iR = 0; iR < 4; iR++ ) {
if ( iR != m_theR && MR[iR] != 0 ) {
debug() << " Descard the track since it hits unwanted Region" << iR << endmsg;
select = false;
}
}
if ( MR[m_theR] == 0 ) {
debug() << " Descard the track since it doesn't hit Region" << m_theR << endmsg;
select = false;
}
} else if ( m_theR > 9 && m_theR < 40 ) {
for ( int iR = 0; iR < 4; iR++ ) {
if ( iR > int( m_theR / 10 ) && MR[iR] != 0 ) {
debug() << " Descard the track since it hits unwanted Region" << iR << endmsg;
select = false;
}
}
} else if ( m_theR == 10 ) {
int iMR = 0;
for ( int iR = 0; iR < 4; iR++ ) {
if ( MR[iR] != 0 ) iMR++;
}
if ( iMR > 1 ) {
debug() << " Descard the track since it hits more than one region" << iMR << endmsg;
select = false;
}
}
if ( MAside != 0 && MCside == 0 )
ASide = true;
else if ( MAside == 0 && MCside != 0 )
CSide = true;
if ( MAside + MCside < m_nStation ) {
debug() << " Discard the track due to the low number of hit station " << MAside + MCside << endmsg;
select = false; /// requirese at least some hits somewhere
}
if ( m_noOverlap && !( ( ASide || CSide ) && ( MAside > m_nStation || MCside > m_nStation ) ) ) {
debug() << " Discard the track since overlaps hit station Cside " << MCside << " Aside " << MAside << endmsg;
select = false;
} else {
debug() << " Track hit station Cside " << MCside << " Aside " << MAside << endmsg;
}
if ( m_calo ) {
State stateAtCALO;
if ( fabs( stateAtCALO.x() ) > 3900 && fabs( stateAtCALO.y() ) > 3150 ) {
debug() << " Discard the track since falls off the CALO acceptance x" << fabs( stateAtCALO.x() ) << " y "
<< stateAtCALO.y() << endmsg;
select = false; // out the calo acceptance
}
}
if ( m_muonChisquareCut > 0 && track->chi2PerDoF() > m_muonChisquareCut ) {
debug() << " Discard the track due to the chisquare " << track->chi2PerDoF() << endmsg;
select = false;
}
if ( select ) {
debug() << " Track selected " << endmsg;
auto clonedTrack = std::make_unique<Track>( *track, track->key() );
LHCBIDS ids = clonedTrack->lhcbIDs();
outputContainer->add( clonedTrack.release() );
}
debug() << "outputContainer.size " << outputContainer->size() << endmsg;
}
//=============================================================================
void MuonTrackSelector::filterTracks( const Tracks* tracks ) {
//=============================================================================
Tracks* output = new Tracks();
std::for_each( tracks->begin(), tracks->end(),
[&, f = &MuonTrackSelector::filterMuonTrack]( LHCb::Track* t ) { ( this->*f )( t, output ); } );
/// put filtered track container in TES
debug() << " going to save the filtered tracks in the " << m_tracksOutputContainer << " container " << endmsg;
put( output, m_tracksOutputContainer );
}
/*
using namespace LHCb;
using namespace Gaudi::Units;
DECLARE_COMPONENT( MuonTrackSelector )
bool MuonTrackSelector::accept( const LHCb::Track& track) const {
if (m_pcut && track->p() < m_pcut ) {
debug()<< " Discard the track due to the low momentum"<<track->p()<<endmsg;
return false;
}
return true;
}
*/
Loading