Commit 41267e4b authored by Frank Winklmeier's avatar Frank Winklmeier
Browse files

Merge branch 'T2BeamSpot_cleanup' into 'master'

Beamspot cleanup

See merge request !35428
parents b1c14846 06494f52
......@@ -104,7 +104,7 @@ namespace PESA {
virtual StatusCode initialize() final;
SG::ReadHandleKeyArray<TrackCollection> m_trackCollections; /*Input list of track collection names which should be used for the algorithms*/
SG::ReadHandleKey<TrackCollection> m_trackCollectionKey; /*track collection name which should be used for the algorithms*/
//The same as in Run2 (m_vertexCollName)
SG::WriteHandleKey<TrigVertexCollection> m_outputVertexCollectionKey;
......
......@@ -53,10 +53,10 @@ HLT::TEVec getAllTEs(const std::vector<HLT::TEVec>& tes_in){
T2VertexBeamSpot::T2VertexBeamSpot( const std::string& name, ISvcLocator* pSvcLocator )
: HLT::AllTEAlgo(name, pSvcLocator){
declareProperty( "TrackCollections", m_trackCollections = {"TrigFastTrackFinder_Tracks"} );
declareProperty( "VertexCollection", m_outputVertexCollectionKey = "myVertices" );
declareProperty( "TrackCollection", m_trackCollectionKey = "TrigFastTrackFinder_Tracks" );
declareProperty( "VertexCollection", m_outputVertexCollectionKey = "myVertices" );
declareProperty("vertexCollName", m_vertexCollName = "TrigBeamSpotVertex");
declareProperty("vertexCollName", m_vertexCollName = "TrigBeamSpotVertex");
......@@ -161,7 +161,7 @@ HLT::ErrorCode T2VertexBeamSpot::hltExecute( std::vector< HLT::TEVec >& tes_in,
auto nPerVecTEHighPTTracks = Monitored::Scalar<unsigned>("nPerVecTEHighPTTracks");
//Loop over Trigger Elements
for ( HLT::TriggerElement* TE : iTE){
for ( HLT::TriggerElement* TE : iTE){
//Monitor how long does it take to loop over each trigger element
auto tTE = Monitored::Timer("TIME_EachTE");
......@@ -183,7 +183,7 @@ HLT::ErrorCode T2VertexBeamSpot::hltExecute( std::vector< HLT::TEVec >& tes_in,
m_beamSpotTool->selectTracks( tracks, mySelectedTrackCollection, nTracks );
//Increment counters per TE
nPerTETracks += nTracks[0];
nPerTETracks += nTracks[0];
nPerTEPassedTracks += nTracks[1];
nPerTEHighPTTracks += nTracks[2];
}
......@@ -216,14 +216,14 @@ HLT::ErrorCode T2VertexBeamSpot::hltExecute( std::vector< HLT::TEVec >& tes_in,
} //End part of track selection
ATH_MSG_DEBUG( "Number of all Tracks: "<< nAllTracks <<" Selected Tracks: " << nSelectedTracks << " highPt Tracks: " << nHighPtTracks );
ATH_MSG_DEBUG( "Number of all Tracks: "<< nAllTracks <<" Selected Tracks: " << nSelectedTracks << " highPt Tracks: " << nHighPtTracks );
if ( !m_beamSpotTool->isHighPTTrack( nHighPtTracks ) ) {
ATH_MSG_DEBUG( " No seed tracks for vertex");
break;
}
m_beamSpotTool->eventStage( hasSeedTrack );
......@@ -258,7 +258,7 @@ HLT::ErrorCode T2VertexBeamSpot::hltExecute( std::vector< HLT::TEVec >& tes_in,
HLT::TEVec allTEs = getAllTEs(tes_in);
ATH_MSG_DEBUG( "n of all TEs: " << allTEs.size() );
//Check how many vertices passed the selection
//Check how many vertices passed the selection
unsigned int nPassedVtx = m_beamSpotTool->m_NvtxPass;
//Save all events, or only those events which pass the Npv cuts (if activated)!
......@@ -397,10 +397,10 @@ StatusCode T2VertexBeamSpot::initialize() {
return StatusCode::FAILURE;
}
ATH_CHECK( m_trackCollections.initialize() );
ATH_CHECK( m_trackCollectionKey.initialize() );
ATH_CHECK( m_outputVertexCollectionKey.initialize() );
ATH_CHECK( m_outputVertexCollectionKey.initialize() );
ATH_CHECK( m_eventInfoKey.initialize() );
......@@ -420,7 +420,7 @@ StatusCode T2VertexBeamSpot::execute(){
//Reset monitored variables from previous event
//Reset monitored variables from previous event
m_beamSpotTool->resetMonitoredVariables();
// Initialize booleans for event stats
m_beamSpotTool->m_eventStageFlag = std::vector<bool>( numStatistics, false );
......@@ -462,22 +462,20 @@ StatusCode T2VertexBeamSpot::execute(){
auto nTotalPassedTracks = Monitored::Scalar<unsigned>("nTotalPassedTracks");
auto nTotalHighPTTracks = Monitored::Scalar<unsigned>("nTotalHighPTTracks");
//Loop over track collections and select tracks
for (SG::ReadHandleKey<TrackCollection> trackCollectionKey : m_trackCollections) {
SG::ReadHandle<TrackCollection> trackCollection (trackCollectionKey);
ATH_CHECK(trackCollection.isValid());
SG::ReadHandle<TrackCollection> trackCollection (m_trackCollectionKey);
ATH_CHECK(trackCollection.isValid());
//Dereference tracks
const TrackCollection* tracks = trackCollection.cptr();
//Dereference tracks
const TrackCollection* tracks = trackCollection.cptr();
//Select tracks
std::vector<unsigned> trackCounter(3,0);//returning all tracks[0]/passed tracks[1]/ hipt tracks[2] counts
m_beamSpotTool->selectTracks( tracks, mySelectedTrackCollection, trackCounter );
//Select tracks
std::vector<unsigned> trackCounter(3,0);//returning all tracks[0]/passed tracks[1]/ hipt tracks[2] counts
m_beamSpotTool->selectTracks( tracks, mySelectedTrackCollection, trackCounter );
//FIXME: make a counter class
nTotalTracks += trackCounter[0];
nTotalPassedTracks += trackCounter[1];
nTotalHighPTTracks += trackCounter[2];
}
//FIXME: make a counter class
nTotalTracks += trackCounter[0];
nTotalPassedTracks += trackCounter[1];
nTotalHighPTTracks += trackCounter[2];
//Store counts for all/highPt/selected tracks
nAllTracks = nTotalTracks;
......
......@@ -10,7 +10,6 @@
#include "TrkTrack/TrackCollection.h"
class TrigVertex;
class TrigInDetTrackCollection;
static const InterfaceID IID_ITrigPrimaryVertexFitter("ITrigPrimaryVertexFitter",1,0);
......@@ -21,10 +20,8 @@ class ITrigPrimaryVertexFitter: virtual public IAlgTool
static const InterfaceID& interfaceID() {
return IID_ITrigPrimaryVertexFitter;
}
virtual TrigVertex* fit(const TrigInDetTrackCollection*, double z=0.0) = 0;
virtual TrigVertex* fit(const TrigInDetTrackCollection*, std::vector<double>&, double z=0.0) = 0;
virtual TrigVertex* fit(const TrackCollection*, TrackCollection&, double z=0.0) = 0;
virtual TrigVertex* fit(const TrackCollection*, std::vector<double>&, double z=0.0) = 0;
virtual TrigVertex* fit(const TrackCollection*, TrackCollection&, double z=0.0) const = 0;
virtual TrigVertex* fit(const TrackCollection*, std::vector<double>&, double z=0.0) const = 0;
};
#endif
......@@ -17,8 +17,6 @@
#include <iostream>
#include <algorithm>
#include "TrigInDetEvent/TrigInDetTrack.h"
#include "TrigInDetEvent/TrigInDetTrackCollection.h"
#include "TrigTimeAlgs/TrigTimerSvc.h"
#include "TrigInDetEvent/TrigL2Vertex.h"
#include "TrigInDetEvent/TrigVertex.h"
......@@ -54,18 +52,6 @@ StatusCode TrigPrimaryVertexFitter::initialize()
ATH_MSG_INFO( "Number of iterations is set to " << m_numIter );
ATH_MSG_INFO( "Accuracy of starting z-position is " << m_zVariance<<" mm" );
ATH_MSG_INFO( "Track lists created ? " << std::boolalpha<<m_createTrackLists );
ServiceHandle<ITrigTimerSvc> timerSvc ("TrigTimerSvc", name());
if( timerSvc.retrieve().isFailure() )
{
ATH_MSG_INFO( "Unable to locate Service TrigTimerSvc " );
m_timers = false;
}
else m_timers = true;
if(m_timers)
{
m_timer[0] = timerSvc->addItem("PrimaryVertexFit");
}
ATH_MSG_INFO( "TrigPrimaryVertexFitter constructed " );
return StatusCode::SUCCESS;
}
......@@ -80,112 +66,8 @@ TrigPrimaryVertexFitter::~TrigPrimaryVertexFitter()
}
TrigVertex* TrigPrimaryVertexFitter::fit(const TrigInDetTrackCollection* tc, double z0)
{
TrigVertex* pVertex=NULL;
double chi2;
int ndof;
if(m_timers) m_timer[0]->start();
bool goodSet=checkTracks(tc);
if(!goodSet)
{
ATH_MSG_WARNING( "Bad track set - vertex cannot be fit" );
return NULL;
}
std::vector<TrigPrimaryVertexTrack*> tracks;
tracks.clear();
int idx=1;
for(TrigInDetTrackCollection::const_iterator ptIt=tc->begin();ptIt!=tc->end();++ptIt)
{
TrigPrimaryVertexTrack* pT= new TrigPrimaryVertexTrack(*ptIt);
if(pT!=NULL) {
pT->setIndex(idx++);
tracks.push_back(pT);
}
}
TrigL2Vertex* pV = new TrigL2Vertex();
pV->getParametersVector()[0]=0.0;
pV->getParametersVector()[1]=0.0;
pV->getParametersVector()[2]=z0;
bool fitFailed=false;
chi2=0.0;ndof=-3;
for(int nIter=0;nIter<m_numIter;nIter++)
{
memset(&pV->m_Gk[0][0],0,sizeof(pV->m_Gk));
pV->m_Gk[0][0]=m_xyVariance*m_xyVariance;
pV->m_Gk[1][1]=m_xyVariance*m_xyVariance;
pV->m_Gk[2][2]=m_zVariance*m_zVariance;
chi2=0.0;ndof=-3;
fitFailed=false;
for(std::vector<TrigPrimaryVertexTrack*>::iterator it=tracks.begin();it!=tracks.end();++it)
{
if(!(*it)->isActive())
(*it)->activate();
double dchi2=(*it)->getChi2Distance(pV);
ATH_MSG_VERBOSE("Track "<<(*it)->getIndex()<<" dchi2="<<dchi2 );
if(std::isnan(dchi2)||(dchi2<0.0)||(dchi2>m_maxChi2Increase))
{
fitFailed=true;
break;
}
if(dchi2<m_chi2cut)
{
chi2+=dchi2;ndof+=2;
(*it)->updateVertex(pV);
}
else
{
(*it)->mask();
ATH_MSG_DEBUG("Skipping track "<<(*it)->getIndex()<<"due to large dchi2="<<dchi2 );
}
}
if(fitFailed) break;
}
if(!fitFailed && (ndof>0))
{
ATH_MSG_DEBUG("Primary vertex fit OK, chi2 = "<<chi2<<" NDOF = "<<ndof );
ATH_MSG_DEBUG("x= "<<pV->getParametersVector()[0]<<
" y= "<<pV->getParametersVector()[1]<<" z= "<<pV->getParametersVector()[2] );
double cv[6];
cv[0]=pV->m_Gk[0][0];cv[1]=pV->m_Gk[0][1];cv[2]=pV->m_Gk[1][1];
cv[3]=pV->m_Gk[0][2];cv[4]=pV->m_Gk[1][2];cv[5]=pV->m_Gk[2][2];
TrackInVertexList* pTL = NULL;
if(m_createTrackLists) {
pTL = new TrackInVertexList;
for(std::vector<TrigPrimaryVertexTrack*>::iterator it=tracks.begin();it!=tracks.end();++it) {
if ((*it)->isActive())
pTL->push_back((*it)->getTrigTrack());
}
}
pVertex = new TrigVertex(pV->getParametersVector()[0],
pV->getParametersVector()[1],
pV->getParametersVector()[2],cv,chi2,ndof,pTL);
}
delete pV;
for(std::vector<TrigPrimaryVertexTrack*>::iterator it=tracks.begin();it!=tracks.end();++it)
{
delete (*it);
}
if(m_timers) m_timer[0]->stop();
return pVertex;
}
//TrigVertex has associated TrigInDetTracks, but we want Trk::Tracks
TrigVertex* TrigPrimaryVertexFitter::fit(const TrackCollection* tc, TrackCollection& output_tc, double z0)
TrigVertex* TrigPrimaryVertexFitter::fit(const TrackCollection* tc, TrackCollection& output_tc, double z0) const
{
TrigVertex* pVertex=NULL;
......@@ -193,8 +75,6 @@ TrigVertex* TrigPrimaryVertexFitter::fit(const TrackCollection* tc, TrackCollect
double chi2;
int ndof;
if(m_timers) m_timer[0]->start();
std::vector<TrigPrimaryVertexTrack*> tracks;
tracks.clear();
int idx=1;
......@@ -276,8 +156,6 @@ TrigVertex* TrigPrimaryVertexFitter::fit(const TrackCollection* tc, TrackCollect
{
delete (*it);
}
if(m_timers) m_timer[0]->stop();
return pVertex;
}
......@@ -289,7 +167,7 @@ struct TrigPrimaryTrackSortPredicate
}
};
TrigVertex* TrigPrimaryVertexFitter::fit(const TrigInDetTrackCollection* tc, std::vector<double>& Chi2V, double z0)
TrigVertex* TrigPrimaryVertexFitter::fit(const TrackCollection* tc, std::vector<double>& Chi2V, double z0) const
{
TrigVertex* pVertex=NULL;
......@@ -297,149 +175,6 @@ TrigVertex* TrigPrimaryVertexFitter::fit(const TrigInDetTrackCollection* tc, std
double chi2;
int ndof;
if(m_timers) m_timer[0]->start();
bool goodSet=checkTracks(tc);
if(!goodSet)
{
ATH_MSG_WARNING( "Bad track set - vertex cannot be fit" );
return NULL;
}
std::vector<TrigPrimaryVertexTrack*> tracks;
tracks.clear();
Chi2V.clear();
int idx=1;
for(TrigInDetTrackCollection::const_iterator ptIt=tc->begin();ptIt!=tc->end();++ptIt)
{
TrigPrimaryVertexTrack* pT= new TrigPrimaryVertexTrack(*ptIt);
if(pT!=NULL)
{
pT->setIndex(idx++);
tracks.push_back(pT);
Chi2V.push_back(-100.0);
}
}
TrigL2Vertex* pV = new TrigL2Vertex();
// 1. preliminary fit
pV->getParametersVector()[0]=0.0;
pV->getParametersVector()[1]=0.0;
pV->getParametersVector()[2]=z0;
memset(&pV->m_Gk[0][0],0,sizeof(pV->m_Gk));
pV->m_Gk[0][0]=m_xyVariance*m_xyVariance;
pV->m_Gk[1][1]=m_xyVariance*m_xyVariance;
pV->m_Gk[2][2]=m_zVariance*m_zVariance;
bool fitFailed=false;
for(std::vector<TrigPrimaryVertexTrack*>::iterator it=tracks.begin();it!=tracks.end();++it)
{
double dchi2=(*it)->getChi2Distance(pV);
if(std::isnan(dchi2)||(dchi2<0.0)||(dchi2>m_maxChi2Increase))
{
fitFailed=true;
break;
}
if(dchi2<m_chi2cut_loose) (*it)->updateVertex(pV);
}
if(fitFailed)
{
delete pV;
for(std::vector<TrigPrimaryVertexTrack*>::iterator it=tracks.begin();
it!=tracks.end();++it) delete (*it);
return pVertex;
}
// 2. calculation of "smoothed" chi2s
memset(&pV->m_Gk[0][0],0,sizeof(pV->m_Gk));
for(std::vector<TrigPrimaryVertexTrack*>::iterator it=tracks.begin();it!=tracks.end();++it)
{
double dchi2=(*it)->getChi2Distance(pV);
ATH_MSG_DEBUG("Track "<<(*it)->getIndex()<<" dchi2="<<dchi2 );
}
// 3. sort tracks in accordance with their chi2s
std::sort(tracks.begin(),tracks.end(),TrigPrimaryTrackSortPredicate());
// 4. Final track fit
pV->getParametersVector()[0]=0.0;
pV->getParametersVector()[1]=0.0;
pV->getParametersVector()[2]=z0;
fitFailed=false;
chi2=0.0;ndof=-3;
for(int nIter=0;nIter<m_numIter;nIter++)
{
memset(&pV->m_Gk[0][0],0,sizeof(pV->m_Gk));
pV->m_Gk[0][0]=100.0;
pV->m_Gk[1][1]=100.0;
pV->m_Gk[2][2]=m_zVariance*m_zVariance;
chi2=0.0;ndof=-3;
fitFailed=false;
for(std::vector<TrigPrimaryVertexTrack*>::iterator it=tracks.begin();it!=tracks.end();++it)
{
double dchi2=(*it)->getChi2Distance(pV);
Chi2V[(*it)->getIndex()-1]=dchi2;
ATH_MSG_VERBOSE("Track "<<(*it)->getIndex()<<" dchi2="<<dchi2 );
if(std::isnan(dchi2)||(dchi2<0.0)||(dchi2>m_maxChi2Increase))
{
fitFailed=true;
break;
}
if(dchi2<m_chi2cut)
{
chi2+=dchi2;ndof+=2;
(*it)->updateVertex(pV);
}
else
{
ATH_MSG_DEBUG("Skipping track "<<(*it)->getIndex()<<"due to large dchi2="<<dchi2 );
}
}
if(fitFailed) break;
}
for(std::vector<TrigPrimaryVertexTrack*>::iterator it=tracks.begin();it!=tracks.end();++it)
{
delete (*it);
}
if(!fitFailed && (ndof>0))
{
ATH_MSG_DEBUG("Primary vertex fit OK, chi2 = "<<chi2<<" NDOF = "<<ndof );
ATH_MSG_DEBUG("x= "<<pV->getParametersVector()[0]<<
" y= "<<pV->getParametersVector()[1]<<" z= "<<pV->getParametersVector()[2] );
double cv[6];
cv[0]=pV->m_Gk[0][0];cv[1]=pV->m_Gk[0][1];cv[2]=pV->m_Gk[1][1];
cv[3]=pV->m_Gk[0][2];cv[4]=pV->m_Gk[1][2];cv[5]=pV->m_Gk[2][2];
pVertex = new TrigVertex(pV->getParametersVector()[0],
pV->getParametersVector()[1],
pV->getParametersVector()[2],cv,chi2,ndof,NULL);
}
delete pV;
if(m_timers) m_timer[0]->stop();
return pVertex;
}
TrigVertex* TrigPrimaryVertexFitter::fit(const TrackCollection* tc, std::vector<double>& Chi2V, double z0)
{
TrigVertex* pVertex=NULL;
double chi2;
int ndof;
if(m_timers) m_timer[0]->start();
std::vector<TrigPrimaryVertexTrack*> tracks;
tracks.clear();
Chi2V.clear();
......@@ -558,33 +293,6 @@ TrigVertex* TrigPrimaryVertexFitter::fit(const TrackCollection* tc, std::vector<
}
delete pV;
if(m_timers) m_timer[0]->stop();
return pVertex;
}
bool TrigPrimaryVertexFitter::checkTracks(const TrigInDetTrackCollection* tc)
{
bool rc=true;
if(tc->size()<2)
{
ATH_MSG_WARNING( "Track set contains less than 2 tracks" );
return false;
}
for(TrigInDetTrackCollection::const_iterator ptIt=tc->begin();ptIt!=tc->end();++ptIt)
{
const TrigInDetTrackFitPar* p=(*ptIt)->param();
if(p==NULL)
{
ATH_MSG_WARNING( "TrigInDetTrack has no parameters" );
rc=false;break;
}
if(p->cov()==NULL)
{
ATH_MSG_WARNING( "TrigInDetTrack covariance is not set" );
rc=false;break;
}
}
return rc;
}
......@@ -18,13 +18,9 @@ class TrigPrimaryVertexFitter: public AthAlgTool, virtual public ITrigPrimaryVer
virtual StatusCode initialize();
virtual StatusCode finalize();
virtual TrigVertex* fit(const TrigInDetTrackCollection*, double z=0.0);
virtual TrigVertex* fit(const TrigInDetTrackCollection*, std::vector<double>&, double z=0.0);
virtual TrigVertex* fit(const TrackCollection*, TrackCollection&, double z=0.0);
virtual TrigVertex* fit(const TrackCollection*, std::vector<double>&, double z=0.0);
virtual TrigVertex* fit(const TrackCollection*, TrackCollection&, double z=0.0) const;
virtual TrigVertex* fit(const TrackCollection*, std::vector<double>&, double z=0.0) const;
private:
bool checkTracks(const TrigInDetTrackCollection*);
int m_numIter;
double m_zVariance,m_maxChi2Increase, m_chi2cut, m_chi2cut_loose;
bool m_createTrackLists;
......
......@@ -38,7 +38,7 @@ def allTE_trkfast( signature="FS" ):
viewAlgs, viewVerify = makeInDetAlgs( whichSignature=signature, rois=inputMakerAlg.InViewRoIs )
vertexAlg = T2VertexBeamSpot_activeAllTE( "vertex_"+signature )
vertexAlg.TrackCollections = ["TrigFastTrackFinder_Tracks_"+signature]
vertexAlg.TrackCollection = "TrigFastTrackFinder_Tracks_"+signature
viewVerify.DataObjects += [( 'TrigRoiDescriptorCollection' , 'StoreGateSvc+beamspotViewRoI_'+signature ),
( 'xAOD::EventInfo' , 'StoreGateSvc+EventInfo' ),
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment