diff --git a/MuonSpectrometer/MuonCalib/MuonCalibTools/MuonCalibTools/IdToFixedIdTool.h b/MuonSpectrometer/MuonCalib/MuonCalibTools/MuonCalibTools/IdToFixedIdTool.h new file mode 100644 index 0000000000000000000000000000000000000000..508e1cb06403c47c0f107f99087f96330e4ffaf7 --- /dev/null +++ b/MuonSpectrometer/MuonCalib/MuonCalibTools/MuonCalibTools/IdToFixedIdTool.h @@ -0,0 +1,72 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +/*************************************************************************** + * Tool responsible for wrapping ATHENA identifier to Standalone Muon Fixed Identifier + * -------------------------------------- + * Copyright (C) 2004 by ATLAS Collaboration + * + * Author : Zdenko van Kesteren + * Creation Date: 20 May 2005 + * Last Update : 20 May 2005 + ***************************************************************************/ + +#ifndef MUONCALIB_IDTOFIXEDID_H +#define MUONCALIB_IDTOFIXEDID_H +// std +#include <string> + +// other packages +#include "AthenaBaseComps/AthAlgTool.h" + +// this package +#include "MuonCalibITools/IIdToFixedIdTool.h" +#include "MuonReadoutGeometry/MuonDetectorManager.h" +#include "Identifier/Identifier.h" + +namespace MuonCalib { + +/** +@class IdToFixedIdTool +Tool responsible for wrapping the athena dependent Identifier class to a standalone Calib-EDM +MuonFixedId identifier. + +The athena-dependent Indentifier relies on idHelpers in order to decode the content. A MuonFixedId has methods itself to decode the content of the identifier. + +@author Zdenko.Van.Kesteren@cern.ch +*/ + +class IdToFixedIdTool : public AthAlgTool, virtual public MuonCalib::IIdToFixedIdTool { + public: + IdToFixedIdTool(const std::string& type, + const std::string& name, + const IInterface* parent); //!< AlgTool constructor + virtual ~IdToFixedIdTool(); //!< AlgTool destructor + + StatusCode initialize(); //!< IdToFixedIdTool initialization: retrieve all the IdHelpers needed to do strap the ATHENA Identifier + StatusCode finalize(); //!< IdToFixedIdTool finalization: does not do anything special + + void print(const Identifier& id) const; //!< print method to output an ATHENA Identifier, warning the user when the conversion and reconversion yields different results. + void print(const MuonFixedId& fid) const; //!< dump MuonFixedId + + Identifier fixedIdToId(const MuonFixedId& fid) const; //!< Convert MuonFixedId to ATHENA Identifier + MuonFixedId idToFixedId(const Identifier& id) const; //!< Convert ATHENA Identifier to MuonFixedId + Identifier regionKeyToId(std::string region) const; //!< Returns an ATHENA Identifier for a given Region key. + + private: + const MuonGM::MuonDetectorManager* p_MuonMgr; //!< pointer to Detector manager + + const MdtIdHelper* p_MdtIdHelper; //!< MDT IdHelper + const CscIdHelper* p_CscIdHelper; //!< CSC IdHelper + const RpcIdHelper* p_RpcIdHelper; //!< RPC IdHelper + const TgcIdHelper* p_TgcIdHelper; //!< TGC IdHelper + + int m_print_level; //!< Sets printlevel of output + mutable Identifier m_identifier; //!< object to store ATHENA Identifier in + mutable MuonFixedId m_fixedId; //!< object to store Calib MuonFixedId in + +}; +} + +#endif //MUONCALIB_IDTOFIXEDID_H diff --git a/MuonSpectrometer/MuonCalib/MuonCalibTools/MuonCalibTools/PatternNtupleMaker.h b/MuonSpectrometer/MuonCalib/MuonCalibTools/MuonCalibTools/PatternNtupleMaker.h new file mode 100644 index 0000000000000000000000000000000000000000..b31e678b13b3d7d638bde0fafde9e34bf766e947 --- /dev/null +++ b/MuonSpectrometer/MuonCalib/MuonCalibTools/MuonCalibTools/PatternNtupleMaker.h @@ -0,0 +1,77 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +/////////////////////////////////////////////////////////////////// +// PatternNtupleMaker.h.h +// Header file for class PatternNtupleMaker.h +/////////////////////////////////////////////////////////////////// +// (c) ATLAS Detector software +/////////////////////////////////////////////////////////////////// +// Niels.Van.Eldik@cern.ch, +/////////////////////////////////////////////////////////////////// + + +#ifndef MUONCALIB_PATTERNNTUPLEMAKER_H +#define MUONCALIB_PATTERNNTUPLEMAKER_H + +// Gaudi +#include "AthenaBaseComps/AthAlgTool.h" + +#include "MuonCalibITools/IMuonCalibTool.h" + +#include <string> +#include <map> + +class StoreGateSvc; + + +namespace MuonCalib { + class MuonCalibEvent; + class MuonFixedId; + class MuonCalibBranchNtuple; + class MuonTruthBranchNtuple; + class MuonCalibTruthCollection; + class MuonCalibEventInfo; + class MuonCalibTriggerTimeInfo; + class MuonCalibRawHitCollection; + class MuonCalibPattern; + + /**@class PatternNtupleMaker.h + Creates and fills ntuple with MuonCalibEvents + + @author Niels.Van.Eldik@cern.ch, + */ + + class PatternNtupleMaker : public AthAlgTool, virtual public IMuonCalibTool { + public: + PatternNtupleMaker(const std::string&,const std::string&,const IInterface*); //!<AlgTool constructor + virtual ~PatternNtupleMaker(); //!<Virtual destructor + + StatusCode initialize(); //!< AlgTool initailize method: Creates an instance of MuonCalib::MuonCalibBranchNtuple, retrieves Storegate. + StatusCode finalize(); //!< AlgTool finalize method: does not do anything special + + virtual bool handleEvent( const MuonCalibEvent* event ); //!< Interface method: feeds the several constituents of the MuonCalibEvent to the MuonCalibBranchNtuple. + virtual bool analyse(); //!< Interface method: writes the Tree. + + private: + StoreGateSvc* m_storeGate; //!< Pointer to StoreGateSvc (obsolete, by the way, should be removed) + + bool handleEventInfo( const MuonCalibEventInfo* eventInfo, const MuonCalibTriggerTimeInfo* trigTimeInfo); //!< Feeds MuonCalibEventInfo to muonCalibBranchNtuple + bool handleTruthCollection( const MuonCalibTruthCollection* truthCollection ); //!< Feeds MuonCalibTruthCollection to muonCalibBranchNtuple + bool handlePattern( const MuonCalibPattern* pattern ); //!< Feeds MuonCalibPattern to muonCalibBranchNtuple + bool handleRawHits( const MuonCalibRawHitCollection* rawHits ); //!< Feeds MuonCalibRawHitCollection to muonCalibBranchNtuple + + + std::string m_ntupleName; //!< ntuple name + std::string m_eventTag; //!< tag of the event, describing reconstruction mechanism + int m_printLevel; //!< print level of ntuple maker + bool m_delayFinish; //!< property flag used to delay the writing of the CalibrationNtuple when a MuonCalibExtraTree is created in the same Tree. + MuonCalibBranchNtuple* m_ntMaker; //!< pointer to the MuonCalibBranchNtuple + bool m_fillTruth; + bool m_doRawTgc; + }; + +} + +#endif diff --git a/MuonSpectrometer/MuonCalib/MuonCalibTools/cmt/requirements b/MuonSpectrometer/MuonCalib/MuonCalibTools/cmt/requirements new file mode 100644 index 0000000000000000000000000000000000000000..5781bf08573e38edab0e970b44c32b4ed4b3390a --- /dev/null +++ b/MuonSpectrometer/MuonCalib/MuonCalibTools/cmt/requirements @@ -0,0 +1,32 @@ +package MuonCalibTools + +manager Niels van Eldik <nveldik@nikhef.nl> +author Ketevi A. Assamagan <ketevi@bnl.gov> + +use AthenaBaseComps AthenaBaseComps-* Control +use AtlasPolicy AtlasPolicy-* + +use Identifier Identifier-* DetectorDescription + +use MuonCalibITools MuonCalibITools-* MuonSpectrometer/MuonCalib + +branches src MuonCalibTools share + +apply_pattern dual_use_library files="*.cxx" + +apply_pattern declare_joboptions files="*.py" + +use MuonReadoutGeometry MuonReadoutGeometry-* MuonSpectrometer/MuonDetDescr + +private +use GaudiInterface GaudiInterface-* External +use MuonCalibEventBase MuonCalibEventBase-* MuonSpectrometer/MuonCalib +use MuonCalibIdentifier MuonCalibIdentifier-* MuonSpectrometer/MuonCalib +use MuonCalibNtuple MuonCalibNtuple-* MuonSpectrometer/MuonCalib +use MuonIdHelpers MuonIdHelpers-* MuonSpectrometer + +use StoreGate StoreGate-* Control + + +#macro cppdebugflags '$(cppdebugflags_s)' +#macro_remove componentshr_linkopts "-Wl,-s" diff --git a/MuonSpectrometer/MuonCalib/MuonCalibTools/doc/mainpage.h b/MuonSpectrometer/MuonCalib/MuonCalibTools/doc/mainpage.h new file mode 100644 index 0000000000000000000000000000000000000000..9932c7a2c4477ce1728db5d57b7e0c6526d9635b --- /dev/null +++ b/MuonSpectrometer/MuonCalib/MuonCalibTools/doc/mainpage.h @@ -0,0 +1,37 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +/** +@mainpage MuonCalibTools Package +@author Niels.Van.Eldik@cern.ch, ketevi@bnl.gov, Zdenko.Van.Kesteren@cern.ch + +@section MuonCalibToolsIntro Introduction +This package contains general tools needed by the Muon Calibration Framework + +@section MuonCalibToolsOverview Class Overview + +- MuonCalib::AtlasRegionSelectorTool: default Region Selector for Atlas calibration, segments are selected by chamber + +- MuonCalib::TestbeamRegionSelectorTool: Region Selector for 2004 testbeam, only segments in the 2 multilayers of rotating BIL are used by the calibration + +- MuonCalib::PatternNtupleMaker: creates and fills ntuple with MuonCalibEvents + +- MuonCalib::IdToFixedIdTool: translates an (ATHENA) Identifier to a (Calib EDM) MuonFixedId. And vice versa. + +@ref used_MuonCalibTools + +@ref requirements_MuonCalibTools + +*/ + +/** +@page used_MuonCalibTools Used Packages +@htmlinclude used_packages.html +*/ + +/** +@page requirements_MuonCalibTools Requirements +@include requirements +*/ + diff --git a/MuonSpectrometer/MuonCalib/MuonCalibTools/share/AtlasRegionSelectorTool.py b/MuonSpectrometer/MuonCalib/MuonCalibTools/share/AtlasRegionSelectorTool.py new file mode 100644 index 0000000000000000000000000000000000000000..3807b939dcb06709ea92955d225568d9e12f261d --- /dev/null +++ b/MuonSpectrometer/MuonCalib/MuonCalibTools/share/AtlasRegionSelectorTool.py @@ -0,0 +1,5 @@ +theApp.Dlls += ["MuonCalibTools"] + +#properties are set for the named instances: see MdtCalibTool.py +#ToolSvc = Service( "ToolSvc" ) +#AtlasRegionSelectorTool = Service( "ToolSvc.MuonCalib::AtlasRegionSelectorTool" ) diff --git a/MuonSpectrometer/MuonCalib/MuonCalibTools/share/MooPatternForCalibrationTool.py b/MuonSpectrometer/MuonCalib/MuonCalibTools/share/MooPatternForCalibrationTool.py new file mode 100644 index 0000000000000000000000000000000000000000..e71ebb5210c0f858333d4fb23a282c83abc42159 --- /dev/null +++ b/MuonSpectrometer/MuonCalib/MuonCalibTools/share/MooPatternForCalibrationTool.py @@ -0,0 +1,8 @@ +theApp.Dlls += ["MuonCalibTools"] + +MooMakeRoads.WriteCalibPatterns = 2 +MooMakeTracks.WriteCalibPatterns = 2 + +ToolSvc = Service( "ToolSvc" ) +MooPatternForCalibrationTool = Service( "ToolSvc.MuonCalib::MooPatternForCalibrationTool" ) +MooPatternForCalibrationTool.MooreCalibPatternsLocation = "Moore_patternsForCalibration" diff --git a/MuonSpectrometer/MuonCalib/MuonCalibTools/share/TestbeamRegionSelectorTool.py b/MuonSpectrometer/MuonCalib/MuonCalibTools/share/TestbeamRegionSelectorTool.py new file mode 100644 index 0000000000000000000000000000000000000000..cc6bad2d3d21abe25532da2bf8cc603fbd14b6a3 --- /dev/null +++ b/MuonSpectrometer/MuonCalib/MuonCalibTools/share/TestbeamRegionSelectorTool.py @@ -0,0 +1,5 @@ +theApp.Dlls += ["MuonCalibTools"] + +#properties are set for the named instances: see MdtCalibTool.py +#ToolSvc = Service( "ToolSvc" ) +#TestbeamRegionSelectorTool = Service( "ToolSvc.MuonCalib::TestbeamRegionSelectorTool" ) diff --git a/MuonSpectrometer/MuonCalib/MuonCalibTools/src/IdToFixedIdTool.cxx b/MuonSpectrometer/MuonCalib/MuonCalibTools/src/IdToFixedIdTool.cxx new file mode 100644 index 0000000000000000000000000000000000000000..461854843ed232b941fd33b8c67d1c41b5e98b5c --- /dev/null +++ b/MuonSpectrometer/MuonCalib/MuonCalibTools/src/IdToFixedIdTool.cxx @@ -0,0 +1,235 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#include "MuonCalibTools/IdToFixedIdTool.h" +#include "StoreGate/StoreGateSvc.h" + +#include "MuonIdHelpers/MdtIdHelper.h" +#include "MuonIdHelpers/CscIdHelper.h" +#include "MuonIdHelpers/RpcIdHelper.h" +#include "MuonIdHelpers/TgcIdHelper.h" +#include "MuonIdHelpers/MuonIdHelper.h" +#include "AthenaBaseComps/AthMsgStreamMacros.h" +#include <iostream> +#include <string> +#include <sstream> + +namespace MuonCalib { + +IdToFixedIdTool::IdToFixedIdTool(const std::string& t, + const std::string& n, + const IInterface* p) + : AthAlgTool(t,n,p), + p_MuonMgr( 0 ), + p_MdtIdHelper( 0 ), + p_CscIdHelper( 0 ), + p_RpcIdHelper( 0 ), + p_TgcIdHelper( 0 ), + m_print_level(0) +{ + declareInterface< IIdToFixedIdTool >(this) ; + declareProperty("print_level" , m_print_level); +} + +IdToFixedIdTool::~IdToFixedIdTool() +{ +} + +StatusCode IdToFixedIdTool::initialize() +{ + ATH_MSG_VERBOSE("Initialisation started"); + + StatusCode status = AlgTool::initialize(); + if ( status.isFailure() ) return status; + + StoreGateSvc* detStore=0; + status = serviceLocator()->service("DetectorStore", detStore); + + if ( status.isSuccess() ) { + status = detStore->retrieve( p_MuonMgr ); + if ( status.isFailure() ) { + ATH_MSG_ERROR(" Cannot retrieve MuonDetDescrMgr "); + } else { + p_MdtIdHelper = p_MuonMgr->mdtIdHelper(); + p_CscIdHelper = p_MuonMgr->cscIdHelper(); + p_RpcIdHelper = p_MuonMgr->rpcIdHelper(); + p_TgcIdHelper = p_MuonMgr->tgcIdHelper(); + ATH_MSG_INFO(" Retrieved IdHelpers: (muon, mdt, csc, rpc and tgc) "); + } + } else { + ATH_MSG_ERROR(" MuonDetDescrMgr not found in DetectorStore "); + } + + return status; +} + +MuonFixedId IdToFixedIdTool::idToFixedId(const Identifier& id) const +{ + bool done; + + ATH_MSG_VERBOSE("IdToFixedId started"); + m_fixedId.clear(); + + if( !(p_MdtIdHelper->is_muon(id)) ){ + ATH_MSG_INFO(" MuonIdentifier doesn't correspond to a muon "); + } else { + //setting the Muon specific fields + done = m_fixedId.setStationName( m_fixedId.stationStringToFixedStationNumber( p_MdtIdHelper->stationNameString( p_MdtIdHelper->stationName( id ) ) ) ); + // if(done) done = m_fixedId.setStationEta( p_MdtIdHelper->stationEta( id ) ); + // if(done) done = m_fixedId.setStationPhi( p_MdtIdHelper->stationPhi( id ) ); + if(!done) ATH_MSG_INFO("Something went wrong in the conversion id->fid (general) "); + if( p_MdtIdHelper->is_mdt(id) ){ + done = m_fixedId.setTechnology(0) ; // MDT = 0; + //setting the Mdt specific fields + if(done) done = m_fixedId.setStationEta( p_MdtIdHelper->stationEta( id ) ); + if(done) done = m_fixedId.setStationPhi( p_MdtIdHelper->stationPhi( id ) ); + + if(done) done = m_fixedId.setMdtTube( p_MdtIdHelper->tube( id ) ); + if(done) done = m_fixedId.setMdtTubeLayer( p_MdtIdHelper->tubeLayer( id ) ); + if(done) done = m_fixedId.setMdtMultilayer( p_MdtIdHelper->multilayer( id ) ); + if(!done) ATH_MSG_INFO("Something went wrong in the conversion id->fid (MDT) "); + } else if ( p_RpcIdHelper->is_rpc(id) ){ + done = m_fixedId.setTechnology(3) ; // RPC = 3; + //setting the Rpc specific fields + if(done) done = m_fixedId.setStationEta( p_RpcIdHelper->stationEta( id ) ); + if(done) done = m_fixedId.setStationPhi( p_RpcIdHelper->stationPhi( id ) ); + + if(done) done = m_fixedId.setRpcDoubletR( p_RpcIdHelper->doubletR( id ) ); + if(done) done = m_fixedId.setRpcDoubletZ( p_RpcIdHelper->doubletZ( id ) ); + if(done) done = m_fixedId.setRpcDoubletPhi( p_RpcIdHelper->doubletPhi( id ) ); + if(done) done = m_fixedId.setRpcGasGap( p_RpcIdHelper->gasGap( id ) ); + if(done) done = m_fixedId.setRpcMeasuresPhi( p_RpcIdHelper->measuresPhi( id ) ); + if(done) done = m_fixedId.setRpcStrip( p_RpcIdHelper->strip( id ) ); + if(!done) ATH_MSG_INFO("Something went wrong in the conversion id->fid (RPC) "); + } else if ( p_CscIdHelper->is_csc(id) ){ + done = m_fixedId.setTechnology(1) ; // CSC = 1; + //setting the Csc specific fields + if(done) done = m_fixedId.setStationEta( p_CscIdHelper->stationEta( id ) ); + if(done) done = m_fixedId.setStationPhi( p_CscIdHelper->stationPhi( id ) ); + + if(done) done = m_fixedId.setCscChamberLayer( p_CscIdHelper->chamberLayer( id ) ); + if(done) done = m_fixedId.setCscWireLayer( p_CscIdHelper->wireLayer( id ) ); + if(done) done = m_fixedId.setCscMeasuresPhi( p_CscIdHelper->measuresPhi( id ) ); + if(done) done = m_fixedId.setCscStrip( p_CscIdHelper->strip( id ) ); + if(!done) ATH_MSG_INFO("Something went wrong in the conversion id->fid (CSC) "); + } else if ( p_TgcIdHelper->is_tgc(id) ){ + done = m_fixedId.setTechnology(2) ; // TGC = 2; + //setting the Tgc specific fields + if(done) done = m_fixedId.setStationEta( p_TgcIdHelper->stationEta( id ) ); + if(done) done = m_fixedId.setStationPhi( p_TgcIdHelper->stationPhi( id ) ); + + if(done) done = m_fixedId.setTgcGasGap( p_TgcIdHelper->gasGap( id ) ); + if(done) done = m_fixedId.setTgcIsStrip( p_TgcIdHelper->isStrip( id ) ); + if(done) done = m_fixedId.setTgcChannel( p_TgcIdHelper->channel( id ) ); + if(!done) ATH_MSG_INFO("Something went wrong in the conversion id->fid (TGC) "); + } + } + return m_fixedId; +} + +StatusCode IdToFixedIdTool::finalize() +{ + return StatusCode::SUCCESS; +} + +Identifier IdToFixedIdTool::fixedIdToId(const MuonFixedId& fid) const +{ + ATH_MSG_VERBOSE("FixedIdToId started "); + Identifier tmp; + if( fid.is_mdt() ){ + tmp = p_MdtIdHelper->channelID( fid.stationNumberToFixedStationString( fid.stationName() ) , + fid.eta(), + fid.phi(), + fid.mdtMultilayer(), + fid.mdtTubeLayer(), + fid.mdtTube() ); + } else if( fid.is_rpc() ){ + tmp = p_RpcIdHelper->channelID( fid.stationNumberToFixedStationString( fid.stationName() ) , + fid.eta(), + fid.phi(), + fid.rpcDoubletR(), + fid.rpcDoubletZ(), + fid.rpcDoubletPhi(), + fid.rpcGasGap(), + fid.rpcMeasuresPhi(), + fid.rpcStrip() ); + } else if( fid.is_csc() ){ + tmp = p_CscIdHelper->channelID( fid.stationNumberToFixedStationString( fid.stationName() ) , + fid.eta(), + fid.phi(), + fid.cscChamberLayer(), + fid.cscWireLayer(), + fid.cscMeasuresPhi(), + fid.cscStrip() ); + } else if( fid.is_tgc() ){ + tmp = p_TgcIdHelper->channelID( fid.stationNumberToFixedStationString( fid.stationName() ) , + fid.eta(), + fid.phi(), + fid.tgcGasGap(), + fid.tgcIsStrip(), + fid.tgcChannel() ); + } + return tmp; +} + +Identifier IdToFixedIdTool::regionKeyToId(std::string region) const +{ + // unpack the region key string used by the calibration framework and return + // an Athena Identifier + int eta,phi,ml; + std::string stnName(region,0,3); + std::string::size_type separator1=region.find_first_of("_"); + std::string::size_type separator2=region.find_last_of("_"); + if((separator1==std::string::npos)||(separator2==std::string::npos)||(separator1==separator2)) { + std::cout <<"IdToFixedIdTool::regionKeyToId : invalid region key "<<region<<std::endl; + return Identifier(0); + } + std::string::size_type separator3=region.find( "_", separator1+1); + if(separator3!=separator2){ + // format STN_ETA_PHI_ML + std::string stnPhi(region,separator1+1,separator2-separator1-1); + std::string stnEta(region,separator2+1,separator3-separator2-1); + std::istringstream is1,is2; + is1.str(stnEta); + is1 >> eta; + is2.str(stnPhi); + is2 >> phi; + std::string Ml(region,separator3+1,region.size()-separator3-1); + std::istringstream is3; + is3.str(Ml); + is3 >> ml; + } else { + // format STN_ETA_PHI + std::string stnPhi(region,separator1+1,separator2-separator1-1); + std::string stnEta(region,separator2+1,region.size()-separator2-1); + std::istringstream is1,is2; + is1.str(stnEta); + is1 >> eta; + is2.str(stnPhi); + is2 >> phi; + ml=0; + } + // figure out what to do here when ml!=0 ... + Identifier athenaId = p_MdtIdHelper->elementID(stnName,eta,phi); + return athenaId; +} + +void IdToFixedIdTool::print(const Identifier& id) const +{ + + MuonFixedId tmp = idToFixedId( id ); + Identifier test = fixedIdToId( tmp ); + if(id != test) + ATH_MSG_WARNING("SOMETHING WENT WRONG PROCESSING FIXEDID<->ID"); + + p_MdtIdHelper->print(id); +} + +void IdToFixedIdTool::print(const MuonFixedId& fid) const +{ + ATH_MSG_INFO("MuonFixedId conversion yields: " << fid); +} + + +} diff --git a/MuonSpectrometer/MuonCalib/MuonCalibTools/src/PatternNtupleMaker.cxx b/MuonSpectrometer/MuonCalib/MuonCalibTools/src/PatternNtupleMaker.cxx new file mode 100644 index 0000000000000000000000000000000000000000..9673bc6403eeed27b06644e075b7804c5620d0c6 --- /dev/null +++ b/MuonSpectrometer/MuonCalib/MuonCalibTools/src/PatternNtupleMaker.cxx @@ -0,0 +1,224 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#include "MuonCalibTools/PatternNtupleMaker.h" + +// gaudi +#include "StoreGate/StoreGateSvc.h" + +#include "MuonCalibNtuple/RootFileManager.h" +#include "MuonCalibNtuple/MuonCalibBranchNtuple.h" +#include "MuonCalibIdentifier/MuonFixedId.h" + +#include "MuonCalibEventBase/MuonCalibTruthCollection.h" +#include "MuonCalibEventBase/MuonCalibTruth.h" +#include "MuonCalibEventBase/MuonCalibMdtTruthHit.h" +#include "MuonCalibEventBase/MuonCalibRpcTruthHit.h" +#include "MuonCalibEventBase/MuonCalibTgcTruthHit.h" +#include "MuonCalibEventBase/MuonCalibCscTruthHit.h" + +namespace MuonCalib { + + PatternNtupleMaker::PatternNtupleMaker(const std::string& t, const std::string& n, const IInterface* p) : + AthAlgTool(t,n,p),m_ntupleName("PatternNtupleMaker"),m_printLevel(0), + m_delayFinish(false),m_ntMaker(0), m_fillTruth(true) + { + declareInterface< IMuonCalibTool >(this) ; + + declareProperty("NtupleName",m_ntupleName); + declareProperty("PrintLevel",m_printLevel); + declareProperty("DelayFinish",m_delayFinish); + declareProperty("FillTruth", m_fillTruth); + declareProperty("DoRawTGC", m_doRawTgc=false); + } + + + PatternNtupleMaker::~PatternNtupleMaker() + { + // if(m_ntMaker) delete m_ntMaker; + } + + StatusCode PatternNtupleMaker::initialize() + { + ATH_MSG_DEBUG("initialize "); + + + ATH_MSG_DEBUG("building MuonCalibBranchNtuple with name " << m_ntupleName); + + m_ntMaker = new MuonCalibBranchNtuple(m_ntupleName.c_str(), m_fillTruth, m_doRawTgc); + ATH_MSG_DEBUG("Done building the MuonCalibBranchNtuple"); + m_ntMaker->setPrintLevel(m_printLevel); + + //Get StoreGateService + StatusCode sc = service("StoreGateSvc", m_storeGate); + if (sc.isFailure()) + { + ATH_MSG_FATAL("StoreGate service not found"); + return StatusCode::FAILURE; + } else ATH_MSG_DEBUG("retrieved Storegate"); + + return StatusCode::SUCCESS; + } + + StatusCode PatternNtupleMaker::finalize() + { + ATH_MSG_DEBUG("finalize "); + if(m_ntMaker) delete m_ntMaker; + return StatusCode::SUCCESS; + } + + + bool PatternNtupleMaker::handleEventInfo( const MuonCalibEventInfo* info, const MuonCalibTriggerTimeInfo* trigTimeInfo ) + { + + + ATH_MSG_DEBUG("handleEventInfo, "); + if (! info ) { + ATH_MSG_INFO( "Invalid EventInfo pointer not filled "); + return false; + }else{ + ATH_MSG_DEBUG("tagged with " << info->tag()); + m_ntMaker->fillEventToTree( *info, *trigTimeInfo ); + } + return true; + } + + bool PatternNtupleMaker::handleTruthCollection( const MuonCalibTruthCollection* truthCollection ) + { + if( !truthCollection ) return false; + + ATH_MSG_DEBUG("handleTruthCollection " << truthCollection->numberOfTruth()); + // loop over MuonCalibTruths + + MuonCalibTruthCollection::TruthVecCit truth_it = truthCollection->truthCollectionBegin(); + MuonCalibTruthCollection::TruthVecCit truth_it_end = truthCollection->truthCollectionEnd(); + for( ;truth_it!=truth_it_end; ++truth_it ){ + if( !(*truth_it) ) { + ATH_MSG_INFO( "Invalid MuonCalibTruth pointer not filled "); + return false; + }else{ +// (*truth_it)->dump(std::cout) ; + + //Do not store the numerous photons/neutrons on ntuple. + if( ( (*truth_it)->PDGCode() == 22) || ( fabs( (*truth_it)->PDGCode()) == 2112) ) continue ; + else m_ntMaker->fillTruthToTree( **truth_it ); + } + } + + ATH_MSG_DEBUG("filling MuonCalibMdtTruthHit "); + MuonCalibTruthCollection::MdtTruthVecCit mdt_truth_it = truthCollection->mdtTruthCollectionBegin(); + MuonCalibTruthCollection::MdtTruthVecCit mdt_truth_it_end = truthCollection->mdtTruthCollectionEnd(); + for( ;mdt_truth_it!=mdt_truth_it_end; ++mdt_truth_it ){ + if( !(*mdt_truth_it) ) { + ATH_MSG_INFO( "Invalid MuonCalibMdtTruthHit pointer not filled "); + return false; + }else{ + m_ntMaker->fillMdtTruthToTree( **mdt_truth_it ); + } + } + + ATH_MSG_DEBUG("filling MuonCalibRpcTruthHit "); + MuonCalibTruthCollection::RpcTruthVecCit rpc_truth_it = truthCollection->rpcTruthCollectionBegin(); + MuonCalibTruthCollection::RpcTruthVecCit rpc_truth_it_end = truthCollection->rpcTruthCollectionEnd(); + for( ;rpc_truth_it!=rpc_truth_it_end; ++rpc_truth_it ){ + if( !(*rpc_truth_it) ) { + ATH_MSG_INFO( "Invalid MuonCalibRpcTruthHit pointer not filled "); + return false; + }else{ + m_ntMaker->fillRpcTruthToTree( **rpc_truth_it ); + } + } + + ATH_MSG_DEBUG("filling MuonCalibTgcTruthHit "); + MuonCalibTruthCollection::TgcTruthVecCit tgc_truth_it = truthCollection->tgcTruthCollectionBegin(); + MuonCalibTruthCollection::TgcTruthVecCit tgc_truth_it_end = truthCollection->tgcTruthCollectionEnd(); + for( ;tgc_truth_it!=tgc_truth_it_end; ++tgc_truth_it ){ + if( !(*tgc_truth_it) ) { + ATH_MSG_INFO( "Invalid MuonCalibTgcTruthHit pointer not filled "); + return false; + }else{ + m_ntMaker->fillTgcTruthToTree( **tgc_truth_it ); + } + } + + ATH_MSG_DEBUG("filling MuonCalibCscTruthHit "); + MuonCalibTruthCollection::CscTruthVecCit csc_truth_it = truthCollection->cscTruthCollectionBegin(); + MuonCalibTruthCollection::CscTruthVecCit csc_truth_it_end = truthCollection->cscTruthCollectionEnd(); + for( ;csc_truth_it!=csc_truth_it_end; ++csc_truth_it ){ + if( !(*csc_truth_it) ) { + ATH_MSG_INFO( "Invalid MuonCalibCscTruthHit pointer not filled "); + return false; + }else{ + m_ntMaker->fillCscTruthToTree( **csc_truth_it ); + } + } + + + ATH_MSG_DEBUG("handleTruthCollection Done "); + + return true; + } + + bool PatternNtupleMaker::analyse() + { + // write ntuple to file + ATH_MSG_DEBUG("PatternNtupleMaker::analyse(), start writing tree "); + m_ntMaker->writeTree(); + ATH_MSG_DEBUG("PatternNtupleMaker::analyse(), Done writing tree "); + return true; + } + + bool PatternNtupleMaker::handleEvent( const MuonCalibEvent* event ) + { + bool handled = false; + ATH_MSG_DEBUG("PatternNtupleMaker::handleEvent( MuonCalibEvent ) "); + + handled = handleEventInfo( &(event->eventInfo()), event->triggerTimeInfo() ); + handled = handleTruthCollection( event->calibTruthCollection() ); + + MuonCalibEvent::MCPVecCit pat_it = event->patternBegin(); + MuonCalibEvent::MCPVecCit pat_it_end = event->patternEnd(); + for(; pat_it != pat_it_end; ++pat_it){ + handlePattern( *pat_it ); + } + handled = handleRawHits( event->rawHitCollection() ); + + if( event->rawTriggerHitCollection() ){ + m_ntMaker->handleRawTriggerHits(*event->rawTriggerHitCollection()); + } + + if( event->rpcSectorLogicContainer() ){ + m_ntMaker->fillRpcSectorLogic(*event->rpcSectorLogicContainer()); + } + + //When using the ExtraTreeAlg, the finishEvent causes the event to be written. + if(m_delayFinish==false) + m_ntMaker->finishEvent(); + + return handled; + } + + bool PatternNtupleMaker::handlePattern( const MuonCalibPattern* pattern ) + { + + if( ! pattern ) { + ATH_MSG_INFO( "Invalid Segment pointer not filled "); + }else{ + m_ntMaker->handlePattern( *pattern ); + ATH_MSG_DEBUG("New pattern with segments " << pattern->muonSegments()); + } + + ATH_MSG_DEBUG("handlePattern Done "); + return true; + } + + bool PatternNtupleMaker::handleRawHits( const MuonCalibRawHitCollection* rawHits ){ + + if( !rawHits ) + ATH_MSG_INFO( "Invalid MuonCalibRawHitCollection pointer: not filled "); + else m_ntMaker->handleRawHits( *rawHits ); + + return true; + } +} diff --git a/MuonSpectrometer/MuonCalib/MuonCalibTools/src/components/MuonCalibTools_entries.cxx b/MuonSpectrometer/MuonCalib/MuonCalibTools/src/components/MuonCalibTools_entries.cxx new file mode 100644 index 0000000000000000000000000000000000000000..7454a0abbd056922ef25c9fabc66230ce04de47b --- /dev/null +++ b/MuonSpectrometer/MuonCalib/MuonCalibTools/src/components/MuonCalibTools_entries.cxx @@ -0,0 +1,15 @@ +#include "GaudiKernel/DeclareFactoryEntries.h" +#include "MuonCalibTools/PatternNtupleMaker.h" +#include "MuonCalibTools/IdToFixedIdTool.h" + +using namespace MuonCalib; + +DECLARE_TOOL_FACTORY( PatternNtupleMaker ) +DECLARE_TOOL_FACTORY( IdToFixedIdTool ) + +/** factory entries need to have the name of the package */ +DECLARE_FACTORY_ENTRIES( MuonCalibTools ) +{ + DECLARE_TOOL( PatternNtupleMaker ) + DECLARE_TOOL( IdToFixedIdTool ) +} diff --git a/MuonSpectrometer/MuonCalib/MuonCalibTools/src/components/MuonCalibTools_load.cxx b/MuonSpectrometer/MuonCalib/MuonCalibTools/src/components/MuonCalibTools_load.cxx new file mode 100644 index 0000000000000000000000000000000000000000..267566a641d0f7e2282d9f9875252023bf79289c --- /dev/null +++ b/MuonSpectrometer/MuonCalib/MuonCalibTools/src/components/MuonCalibTools_load.cxx @@ -0,0 +1,3 @@ +#include "GaudiKernel/LoadFactoryEntries.h" + +LOAD_FACTORY_ENTRIES( MuonCalibTools )