ATLAS Offline Software
AlignTrackCreator.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 
6 #include "GaudiKernel/MsgStream.h"
7 //#include "GaudiKernel/PropertyMgr.h" deprecated
8 
11 
13 
15 #include "TrkTrack/Track.h"
20 
25 
29 
30 #include <fstream>
31 
32 namespace Trk {
33 
34  //________________________________________________________________________
35  AlignTrackCreator::AlignTrackCreator(const std::string& type, const std::string& name,
36  const IInterface* parent)
39  , m_residualCalculator("Trk::AlignResidualCalculator/ResidualCalculator")
40  , m_idHelper{}
41  , m_measTypeIdHelper{}
42  {
43  declareInterface<IAlignTrackCreator>(this);
44 
45  declareProperty("ResidualCalculator", m_residualCalculator);
46  declareProperty("AlignModuleTool", m_alignModuleTool);
47 
48  declareProperty("EventList", m_eventListName = "goodEvents.txt");
49  declareProperty("WriteEventList", m_writeEventList = false );
50  declareProperty("RequireOverlap", m_requireOverlap = false);
51  declareProperty("RemoveATSOSNotInAlignModule", m_removeATSOSNotInAlignModule=true);
52  declareProperty("IncludeScatterers", m_includeScatterers = true );
53 
54  m_logStream = nullptr;
55  }
56 
57  //________________________________________________________________________
59  {
60  ATH_MSG_DEBUG("in AlignTrackCreator d'tor");
61  }
62 
63  //________________________________________________________________________
65  {
66  // Set up ATLAS ID helper
67  if (detStore()->retrieve(m_idHelper, "AtlasID").isFailure()) {
68  ATH_MSG_ERROR ("Could not get AtlasDetectorID helper" );
69  return StatusCode::FAILURE;
70  }
72 
73  if (m_residualCalculator.retrieve().isFailure()) {
74  msg(MSG::FATAL) << "Could not get " << m_residualCalculator << endmsg;
75  return StatusCode::FAILURE;
76  }
77  ATH_MSG_INFO("Retrieved " << m_residualCalculator);
78 
79  // get AlignModuleTool
80  if (m_alignModuleTool.retrieve().isFailure()) {
81  msg(MSG::FATAL) << "Could not get " << m_alignModuleTool << endmsg;
82  return StatusCode::FAILURE;
83  }
84  ATH_MSG_INFO("Retrieved " << m_alignModuleTool);
85 
86  ATH_MSG_INFO("initialize() successful in " << name());
87 
88  return StatusCode::SUCCESS;
89  }
90 
91  //________________________________________________________________________
93  {
94  ATH_MSG_DEBUG("finalize() in AlignTrackCreator");
95 
96  // write run/evt to ASCII file
97  if (m_writeEventList) {
98  std::ofstream output(m_eventListName.c_str());
99  for (std::vector<std::pair<int,int> >::iterator it=
100  m_goodEventList.begin(); it!=m_goodEventList.end(); ++it) {
101  int run=(*it).first;
102  int evt=(*it).second;
103  output << run << " " << evt << std::endl;
104  }
105 
106  // if no events, output dummy run and event number so file isn't empty
107  if (m_goodEventList.empty()) output<<"0 0"<<std::endl;
108  output.close();
109  }
110 
111  delete m_measTypeIdHelper;
112 
113  return StatusCode::SUCCESS;
114  }
115 
116  //________________________________________________________________________
118  {
119  DataVector<AlignTSOS>* alignTSOSCollection=new DataVector<AlignTSOS>;
120 
121  bool goodtrack = false;
122  int ntsos(0);
123  double chi2(0.);
124 
125  AlignModule * lastModule(nullptr);
126  bool overlapTrack(false);
127 
128  ATH_MSG_DEBUG("nDoF: "<<at->fitQuality()->numberDoF()<<", tsos size: "<<at->trackStateOnSurfaces()->size());
129 
130  for (const TrackStateOnSurface* tsos : *at->trackStateOnSurfaces()) {
131 
132  AlignTSOS * atsos(nullptr);
133  AlignModule * module(nullptr);
134 
135  if (tsos->type(TrackStateOnSurface::Outlier) ||
136  tsos->type(TrackStateOnSurface::Perigee) ||
137  tsos->type(TrackStateOnSurface::Hole))
138  continue;
139  else if (tsos->type(TrackStateOnSurface::Measurement)) {
140 
141  ATH_MSG_DEBUG("checking ntsos: "<<ntsos);
142 
143  const MeasurementBase * mesb = tsos->measurementOnTrack();
144  const TrackParameters * tparp = tsos->trackParameters();
145  const RIO_OnTrack * rio = dynamic_cast<const RIO_OnTrack *>(mesb);
146  const CompetingRIOsOnTrack * crio = dynamic_cast<const CompetingRIOsOnTrack *>(mesb);
147 
148  if (!rio && crio) rio=&crio->rioOnTrack(0);
149 
150  if (rio && tparp) {
151 
152  //AlignModule::DetectorType detType=AlignModule::NDetectorTypes;
153  //if (measType!=TrackState::unidentified && measType<=TrackState::TGC)
154  //detType=(AlignModule::DetectorType)(measType-1);
155 
156  //get detector type
157  AlignModule::DetectorType detType = m_alignModuleTool->getDetectorType(rio->detectorElement());
158  ATH_MSG_DEBUG("detType: "<<detType);
159 
160  // see if track is good track
161  if (detType!=AlignModule::NDetectorTypes) {
162  ATH_MSG_DEBUG("calling findAlignModule");
163  module=m_alignModuleTool->findAlignModule(rio,detType);
164  }
165  if (module) {
166  ATH_MSG_DEBUG("found module");
167  goodtrack=true;
168  if (lastModule && module!=lastModule) {
169  overlapTrack=true;
170  ATH_MSG_DEBUG("have overlap track");
171  }
172  else
173  lastModule=module;
174  }
175  ATH_MSG_DEBUG("module not found");
176 
177  // see what kind of TSOS
179 
180  // create AlignTSOS using CompetingRIOsOnTrack or RIO_OnTrack
181  if (crio)
182  atsos = new AlignTSOS(*tsos,module,crio,measType);
183  else
184  atsos = new AlignTSOS(*tsos,module,rio,measType);
185 
186  if (module)
187  ATH_MSG_DEBUG("module id "<<module->identify());
188  else
189  ATH_MSG_VERBOSE("no module");
190 
191  atsos->setValid(true);
192  }
193  }
194 
195  // scatterer with no associated measurement
196  else if (tsos->type(TrackStateOnSurface::Scatterer) && m_includeScatterers) {
197  atsos=new AlignTSOS(*tsos,TrackState::unidentified);
198  atsos->setValid(true);
199  }
200 
201  if (!atsos) {
202  continue;
203  }
204 
206  delete atsos;
207  continue;
208  }
209 
210  // set detector specific properties (if needed)
211  m_alignModuleTool->setMeasurementProperties(atsos);
212 
213  alignTSOSCollection->push_back(atsos);
214  }
215 
216  ATH_MSG_DEBUG("goodtrack="<<goodtrack<<", alignTSOSCollection size: "<<alignTSOSCollection->size());
217 
218  if (goodtrack && (!m_requireOverlap||overlapTrack)) {
219 
220  // store run/evt number in vector
221  if (m_writeEventList) {
222  const xAOD::EventInfo * eventInfo;
223  StatusCode sc=evtStore()->retrieve(eventInfo);
224  if (sc.isFailure())
225  ATH_MSG_ERROR("Couldn't retrieve event info");
226 
227  int run=eventInfo->runNumber();
228  int evt=eventInfo->eventNumber();
229  m_goodEventList.emplace_back(run,evt);
230  }
231 
232  // set residuals on ATSOS and get local chi2
233  ATH_MSG_DEBUG("calling setResiduals");
234  chi2=m_residualCalculator->setResiduals(alignTSOSCollection);
235  ATH_MSG_DEBUG("done with setResiduals");
236 
237  // check that chi2 from fitter matches local chi2
238  if (std::fabs(chi2-at->fitQuality()->chiSquared())>.01) {
239  ATH_MSG_DEBUG("local chi2: "<<chi2<<", from fit: "<<at->fitQuality()->chiSquared());
240  }
241 
242  ATH_MSG_DEBUG("setting alignTrack");
243  at->setAlignTSOSCollection(alignTSOSCollection);
244  at->setChi2(chi2);
245 
246  if (msgLvl(MSG::DEBUG)) at->dump(msg());
247 
248  return true;
249  }
250 
251  ATH_MSG_DEBUG("failed to make AlignTrack");
252  delete alignTSOSCollection;
253  return false;
254  }
255 
256 } // end namespace
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
Trk::AlignTrack::setAlignTSOSCollection
void setAlignTSOSCollection(AlignTSOSCollection *atsosColl)
sets collection of AlignTSOS
Definition: AlignTrack.cxx:341
Trk::AlignTrackCreator::finalize
StatusCode finalize()
Definition: AlignTrackCreator.cxx:92
Trk::TrackStateOnSurface::Perigee
@ Perigee
This represents a perigee, and so will contain a Perigee object only.
Definition: TrackStateOnSurface.h:117
Trk::Track::fitQuality
const FitQuality * fitQuality() const
return a pointer to the fit quality const-overload
Trk::AlignTrackCreator::initialize
StatusCode initialize()
Definition: AlignTrackCreator.cxx:64
Trk::AlignTrackCreator::AlignTrackCreator
AlignTrackCreator(const std::string &type, const std::string &name, const IInterface *parent)
Definition: AlignTrackCreator.cxx:35
MeasurementBase.h
python.Constants.FATAL
int FATAL
Definition: Control/AthenaCommon/python/Constants.py:19
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
xAOD::EventInfo_v1::eventNumber
uint64_t eventNumber() const
The current event's event number.
CompetingRIOsOnTrack.h
Trk::Track::trackStateOnSurfaces
const Trk::TrackStates * trackStateOnSurfaces() const
return a pointer to a const DataVector of const TrackStateOnSurfaces.
Trk::AlignTrackCreator::m_eventListName
std::string m_eventListName
good events read in from ASCII file
Definition: AlignTrackCreator.h:59
Trk::AlignTrackCreator::m_requireOverlap
bool m_requireOverlap
write selected events to event list ASCII file
Definition: AlignTrackCreator.h:61
IAlignResidualCalculator.h
Trk::AlignTSOS
Definition: AlignTSOS.h:37
skel.it
it
Definition: skel.GENtoEVGEN.py:396
Trk::AlignModule
Definition: AlignModule.h:45
AthCommonMsg< AlgTool >::msgLvl
bool msgLvl(const MSG::Level lvl) const
Definition: AthCommonMsg.h:30
Trk::AlignTrackCreator::m_alignModuleTool
ToolHandle< IAlignModuleTool > m_alignModuleTool
Definition: AlignTrackCreator.h:51
Trk::RIO_OnTrack
Definition: RIO_OnTrack.h:70
LArG4FSStartPointFilter.evt
evt
Definition: LArG4FSStartPointFilter.py:42
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
Trk::AlignModule::NDetectorTypes
@ NDetectorTypes
Definition: AlignModule.h:57
Trk::TrackState::unidentified
@ unidentified
Definition: TrackStateDefs.h:27
AlignTrackCreator.h
Trk::AlignTrackCreator::m_idHelper
const AtlasDetectorID * m_idHelper
Definition: AlignTrackCreator.h:54
xAOD::EventInfo_v1::runNumber
uint32_t runNumber() const
The current event's run number.
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
AlignTSOS.h
AthCommonDataStore< AthCommonMsg< AlgTool > >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:95
Trk::TrackStateOnSurface::Outlier
@ Outlier
This TSoS contains an outlier, that is, it contains a MeasurementBase/RIO_OnTrack which was not used ...
Definition: TrackStateOnSurface.h:122
Track.h
MaterialEffectsOnTrack.h
python.PyAthena.module
module
Definition: PyAthena.py:131
Trk::AlignTrackCreator::processAlignTrack
bool processAlignTrack(AlignTrack *track)
creates AlignTrack containing all TSOS on track
Definition: AlignTrackCreator.cxx:117
Trk::AlignTrackCreator::m_includeScatterers
bool m_includeScatterers
remove AlignTSOS not in AlignModules
Definition: AlignTrackCreator.h:63
AthCommonDataStore< AthCommonMsg< AlgTool > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
AtlasDetectorID.h
This class provides an interface to generate or decode an identifier for the upper levels of the dete...
Trk::CompetingRIOsOnTrack::rioOnTrack
virtual const RIO_OnTrack & rioOnTrack(unsigned int) const =0
returns the RIO_OnTrack (also known as ROT) objects depending on the integer.
AlignTrack.h
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
Trk::TrackStateOnSurface::Hole
@ Hole
A hole on the track - this is defined in the following way.
Definition: TrackStateOnSurface.h:128
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
Trk::CompetingRIOsOnTrack
Base class for all CompetingRIOsOnTack implementations, extends the common MeasurementBase.
Definition: CompetingRIOsOnTrack.h:64
chi2
double chi2(TH1 *h0, TH1 *h1)
Definition: comparitor.cxx:523
Trk::TrackState::MeasurementType
MeasurementType
enum describing the flavour of MeasurementBase
Definition: TrackStateDefs.h:26
AlignModuleTool.h
test_pyathena.parent
parent
Definition: test_pyathena.py:15
Trk::AlignTrack::dump
void dump(MsgStream &msg)
dump align track information
Definition: AlignTrack.cxx:316
run
Definition: run.py:1
Trk::ParametersBase
Definition: ParametersBase.h:55
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
AlignModuleList.h
merge.output
output
Definition: merge.py:17
Trk::MeasurementBase
Definition: MeasurementBase.h:58
Trk::AlignTrackCreator::m_goodEventList
std::vector< std::pair< int, int > > m_goodEventList
Definition: AlignTrackCreator.h:57
Trk
Ensure that the ATLAS eigen extensions are properly loaded.
Definition: FakeTrackBuilder.h:9
Trk::AlignTrackCreator::m_residualCalculator
ToolHandle< IAlignResidualCalculator > m_residualCalculator
Definition: AlignTrackCreator.h:52
Trk::AlignTrackCreator::~AlignTrackCreator
virtual ~AlignTrackCreator()
Definition: AlignTrackCreator.cxx:58
Trk::TrackStateOnSurface
represents the track state (measurement, material, fit parameters and quality) at a surface.
Definition: TrackStateOnSurface.h:71
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
RIO_OnTrack.h
Trk::AlignModule::DetectorType
DetectorType
Definition: AlignModule.h:57
Trk::MeasurementTypeID
classifies a MeasurementBase into one of the known inherited flavours or one of the detector types fo...
Definition: MeasurementTypeID.h:26
AlignModule.h
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
Trk::AlignTrackCreator::m_measTypeIdHelper
MeasurementTypeID * m_measTypeIdHelper
Definition: AlignTrackCreator.h:55
Trk::AlignTrack
Definition: AlignTrack.h:41
EventInfo.h
xAOD::EventInfo_v1
Class describing the basic event information.
Definition: EventInfo_v1.h:43
Trk::AlignTrackCreator::m_writeEventList
bool m_writeEventList
name of event list ASCII file
Definition: AlignTrackCreator.h:60
Trk::IAlignTrackCreator
Definition: IAlignTrackCreator.h:30
MeasurementTypeID.h
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
DEBUG
#define DEBUG
Definition: page_access.h:11
AthCommonMsg< AlgTool >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
Trk::AlignTrack::setChi2
void setChi2(double chi2)
Definition: AlignTrack.h:166
Trk::TrackStateOnSurface::Scatterer
@ Scatterer
This represents a scattering point on the track, and so will contain TrackParameters and MaterialEffe...
Definition: TrackStateOnSurface.h:113
Trk::FitQuality::chiSquared
double chiSquared() const
returns the of the overall track fit
Definition: FitQuality.h:56
Trk::AlignTSOS::setValid
void setValid(bool isvalid)
set and retrieve flag to indicate whether hit valid for alignment
Definition: AlignTSOS.h:73
Trk::FitQuality::numberDoF
int numberDoF() const
returns the number of degrees of freedom of the overall track or vertex fit as integer
Definition: FitQuality.h:60
Trk::RIO_OnTrack::detectorElement
virtual const TrkDetElementBase * detectorElement() const =0
returns the detector element, assoicated with the PRD of this class
AthAlgTool
Definition: AthAlgTool.h:26
Trk::AlignTrackCreator::m_removeATSOSNotInAlignModule
bool m_removeATSOSNotInAlignModule
keep only tracks that pass through 2 or more AlignModules
Definition: AlignTrackCreator.h:62
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
Trk::TrackStateOnSurface::Measurement
@ Measurement
This is a measurement, and will at least contain a Trk::MeasurementBase.
Definition: TrackStateOnSurface.h:101
TrackStateOnSurface.h
Trk::MeasurementTypeID::defineType
Trk::TrackState::MeasurementType defineType(const MeasurementBase *) const
createPerigee method - returned by object
Definition: MeasurementTypeID.cxx:20