generated from key4hep/k4-project-template
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Port DDSimpleMuonDigi from DDMarlinPandora
- Loading branch information
Showing
7 changed files
with
663 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#[[ | ||
Copyright (c) 2020-2024 Key4hep-Project. | ||
This file is part of Key4hep. | ||
See https://key4hep.github.io/key4hep-doc/ for further info. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
]] | ||
|
||
set(_plugin_sources ${CMAKE_CURRENT_LIST_DIR}/src/DDSimpleMuonDigi.cc | ||
src/CalorimeterHitType.cc) | ||
|
||
gaudi_add_module(k4GaudiPandoraPlugins | ||
SOURCES ${_plugin_sources} | ||
LINK Gaudi::GaudiKernel | ||
k4FWCore::k4FWCore | ||
k4FWCore::k4Interface | ||
EDM4HEP::edm4hep | ||
DD4hep::DDRec | ||
DD4hep::DDCore | ||
) | ||
target_include_directories(k4GaudiPandoraPlugins PRIVATE include) | ||
install(TARGETS k4GaudiPandoraPlugins | ||
EXPORT ${CMAKE_PROJECT_NAME}Targets | ||
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" COMPONENT bin | ||
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT shlib | ||
PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/@{CMAKE_PROJECT_NAME}" | ||
COMPONENT dev) | ||
|
||
include(CTest) | ||
|
||
#--- The genConf directory has been renamed to genConfDir in Gaudi 35r1 | ||
#--- See https://gitlab.cern.ch/gaudi/Gaudi/-/merge_requests/1158 | ||
set(GAUDI_GENCONF_DIR "genConfDir") | ||
|
||
function(set_test_env _testname) | ||
set_property(TEST ${_testname} APPEND PROPERTY ENVIRONMENT | ||
LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}:$<TARGET_FILE_DIR:k4GaudiPandoraPlugins>:$<TARGET_FILE_DIR:ROOT::Core>:$<TARGET_FILE_DIR:k4FWCore::k4FWCore>:$<TARGET_FILE_DIR:EDM4HEP::edm4hep>:$<TARGET_FILE_DIR:podio::podio>:$ENV{LD_LIBRARY_PATH} | ||
PYTHONPATH=${CMAKE_BINARY_DIR}/${CMAKE_PROJECT_NAME}/${GAUDI_GENCONF_DIR}:$<TARGET_FILE_DIR:k4FWCore::k4FWCore>/../python:$ENV{PYTHONPATH} | ||
PATH=$<TARGET_FILE_DIR:k4FWCore::k4FWCore>/../bin:$ENV{PATH} | ||
K4PROJECTTEMPLATE=${CMAKE_CURRENT_LIST_DIR}/ | ||
) | ||
endfunction() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
/* | ||
* Copyright (c) 2020-2024 Key4hep-Project. | ||
* | ||
* This file is part of Key4hep. | ||
* See https://key4hep.github.io/key4hep-doc/ for further info. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
#ifndef CalorimeterHitType_h | ||
#define CalorimeterHitType_h 1 | ||
|
||
#include <iostream> | ||
|
||
/** Helper class for decoding/encoding lcio::CalorimeterHit types for the ILD | ||
* detector. The encoding is: caloType + 10 * caloID + 1000 * layout + 10000 * layerNum <br> | ||
* (see enums: CaloType, CaloID and Layout for possible values).<br> | ||
* Example usage: <br> | ||
* <pre> | ||
* lcio::CalorimeterHit* cHit = .... ; | ||
* | ||
* // set the type (e.g. in digitization ) | ||
* cHit->setType( CHT( CHT::em , CHT::ecal , CHT::plug , 12 ) ) ; | ||
* | ||
* ... | ||
* | ||
* CHT cht = cHit->getType() ; | ||
* | ||
* // sum energies for electromagentic, hadronic and tailcatcher: | ||
* if( cht.is( CHT::em ) ) | ||
* e_em += cHit->getEnergy() ; | ||
* else | ||
* if ( cht.is(CHT::had ) ) | ||
* e_had += cHit->getEnergy() ; | ||
* else | ||
* e_muon += cHit->getEnergy() ; | ||
* | ||
* // use only EcalPlug hits: | ||
* if( cht.is( CHT::ecal) && cht.is( CHT::plug) ) | ||
* | ||
* // get the layer number (e.g. for calibration or clustering) | ||
* unsigned l = cht.layer() ; | ||
* // or directly : | ||
* unsigned l = CHT( cHit->getType() ).layer() ; | ||
* | ||
* // detailed print: | ||
* std::cout << CHT( cHit->getType() ) << std::endl ; | ||
* | ||
* </pre> | ||
* | ||
* F.Gaede, DESY, 12/2008 | ||
*/ | ||
|
||
class CHT { | ||
public: | ||
/** calorimeter types */ | ||
enum class CaloType { em = 0, had = 1, muon = 2 }; | ||
|
||
/** calo ids - specific to ILD */ | ||
enum class CaloID { unknown = 0, ecal = 1, hcal = 2, yoke = 3, lcal = 4, lhcal = 5, bcal = 6 }; | ||
|
||
/** calo layout / subdetector */ | ||
enum class Layout { any = 0, barrel = 1, endcap = 2, plug = 3, ring = 4 }; | ||
|
||
/** C'tor for initialization from CalorimeterHit::getType() */ | ||
CHT(int type) : m_type(type) {} | ||
|
||
/** C'tor for encoding the calo type inforamtion */ | ||
CHT(CaloType c, CaloID n, Layout l, unsigned lay) | ||
: m_type(c * fCaloType + n * fCaloID + l * fLayout + lay * fLayer) {} | ||
|
||
/** calorimeter type: CHT::em , CHT::had, CHT::muon */ | ||
CaloType caloType() const { return (CaloType)(m_type % fCaloID); } | ||
|
||
/** calo ID - see enum CaloID for allowed values */ | ||
CaloID caloID() const { return (CaloID)((m_type % fLayout) / fCaloID); } | ||
|
||
/** calo layout - see enum layout for allowed values */ | ||
Layout layout() const { return (Layout)((m_type % fLayer) / fLayout); } | ||
|
||
/** calo layer of hit */ | ||
unsigned layer() const { return unsigned(m_type) / fLayer; } | ||
|
||
bool is(CaloType t) const { return caloType() == t; } | ||
|
||
bool is(CaloID n) const { return caloID() == n; } | ||
|
||
bool is(Layout l) const { return layout() == l; } | ||
|
||
/** automatic conversion to int */ | ||
operator int() const { return m_type; } | ||
|
||
/** explicit conversion to int */ | ||
int toInt() const { return m_type; } | ||
|
||
protected: | ||
int m_type; | ||
|
||
static const int fCaloType = 1; | ||
static const int fCaloID = 10; | ||
static const int fLayout = 1000; | ||
static const int fLayer = 10000; | ||
}; | ||
|
||
/** detailed string for calo type */ | ||
std::ostream& operator<<(std::ostream& os, const CHT& cht); | ||
|
||
/** Return Layout based on the collection name, e.g. if name contains tolower("endcap") CHT::endcap is returned. In case no known layout | ||
is found, CHT::any is returned.*/ | ||
CHT::Layout layoutFromString(const std::string& name); | ||
|
||
/** Return caloID based on the collection name, e.g. if name contains tolower("HCal") CHT::hcal is returned. In case no known type | ||
is found, CHT::unknown is returned.*/ | ||
CHT::CaloID caloIDFromString(const std::string& name); | ||
|
||
/** Return caloType from string, e.g. if name contains tolower("Had") CHT::had is returned. In case no known type | ||
is found, CHT::em is returned.*/ | ||
CHT::CaloType caloTypeFromString(const std::string& name); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
* Copyright (c) 2020-2024 Key4hep-Project. | ||
* | ||
* This file is part of Key4hep. | ||
* See https://key4hep.github.io/key4hep-doc/ for further info. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
#ifndef DDSimpleMuonDigi_H | ||
#define DDSimpleMuonDigi_H | ||
|
||
#include "Gaudi/Property.h" | ||
#include "edm4hep/CaloHitContributionCollection.h" | ||
#include "edm4hep/CaloHitSimCaloHitLinkCollection.h" | ||
#include "edm4hep/CalorimeterHitCollection.h" | ||
#include "edm4hep/EventHeaderCollection.h" | ||
#include "edm4hep/SimCalorimeterHitCollection.h" | ||
|
||
#include "CalorimeterHitType.h" | ||
#include "DDRec/SurfaceManager.h" | ||
#include "k4FWCore/Transformer.h" | ||
#include "k4Interface/IGeoSvc.h" | ||
#include "k4Interface/IUniqueIDGenSvc.h" | ||
|
||
#include <random> | ||
#include <string> | ||
#include <vector> | ||
|
||
struct DDSimpleMuonDigi final | ||
: k4FWCore::MultiTransformer< | ||
std::tuple<edm4hep::CalorimeterHitCollection, edm4hep::CaloHitSimCaloHitLinkCollection>( | ||
const edm4hep::SimCalorimeterHitCollection&, const edm4hep::EventHeaderCollection&)> { | ||
DDSimpleMuonDigi(const std::string& name, ISvcLocator* svcLoc); | ||
|
||
StatusCode initialize() override; | ||
//StatusCode finalize() override; | ||
|
||
std::tuple<edm4hep::CalorimeterHitCollection, edm4hep::CaloHitSimCaloHitLinkCollection> operator()( | ||
const edm4hep::SimCalorimeterHitCollection& simCaloHits, | ||
const edm4hep::EventHeaderCollection& headers) const override; | ||
|
||
private: | ||
Gaudi::Property<std::string> m_subDetName{this, "SubDetectorName", "VXD", "Name of the subdetector"}; | ||
Gaudi::Property<std::vector<int>> m_layersToKeepBarrelVec{ | ||
this, "KeepBarrelLayersVec", {0}, "Vector of Barrel layers to be kept. Layers start at 1!"}; | ||
Gaudi::Property<std::vector<int>> m_layersToKeepEndCapVec{ | ||
this, "KeepEndcapLayersVec", {0}, "Vector of Endcap layers to be kept. Layers start at 1!"}; | ||
//Gaudi::Property<std::vector<bool>> useLayersBarrelVec{this, "useBarrelLayerVector", false, "whether to use the endcap layer vector"}; | ||
//Gaudi::Property<std::vector<bool>> useLayersEndcapVec{this, "useEndCapLayerVector", false, "whether to use the EndCap layer vector"}; | ||
Gaudi::Property<std::string> m_muonCollections{this, "muonCollections", "muonCollections", | ||
"The input collection of Muons"}; | ||
Gaudi::Property<std::string> outputRelCollection{this, "outputRelCollection", "outputRelCollection", | ||
"The output collection of relations"}; | ||
Gaudi::Property<std::string> outputMuonCollection{this, "outputMuonCollection", "outputMuonCollection", | ||
"The output collection of muons"}; | ||
Gaudi::Property<std::string> m_encodingStringVariable{ | ||
this, "EncodingStringParameterName", "GlobalTrackerReadoutID", | ||
"The name of the DD4hep constant that contains the Encoding string for tracking detectors"}; | ||
Gaudi::Property<std::string> m_cellIDLayerString{this, "CellIDLayerString", "Layer", | ||
"Name of the part of the cellID that holds the layer"}; | ||
Gaudi::Property<float> m_thresholdMuon{this, "MuonThreshold", {0.025}, "Threshold for muon"}; | ||
Gaudi::Property<float> m_timeThresholdMuon{this, "timethresholdMuon", {0.025}, "time threshold for muons"}; | ||
Gaudi::Property<float> m_calibrCoeffMuon{ | ||
this, "calibrationCoeffmuon", {120000.0}, "Callibration coefficient of muons"}; | ||
Gaudi::Property<float> m_maxHitEnergyMuon{this, "maxMuonHitEnergy", {2.0}, "Threshold for maximum muon hit energy"}; | ||
Gaudi::Property<std::string> m_detectorNameBarrel{this, "detectornameB", "YokeBarrel", "Name of the subdetector"}; | ||
Gaudi::Property<std::string> m_detectorNameEndcap{this, "detectornameE", "YokeEndcap", | ||
"Name of the second subdetector"}; | ||
|
||
std::string m_collName; | ||
std::vector<bool> m_useLayersBarrelVec{}, m_useLayersEndcapVec{}; | ||
SmartIF<IGeoSvc> m_geoSvc; | ||
SmartIF<IUniqueIDGenSvc> m_uidSvc; | ||
|
||
bool useLayer(CHT::Layout caloLayout, unsigned int layer) const; | ||
float computeHitTime(const edm4hep::SimCalorimeterHit& h) const; | ||
}; | ||
DECLARE_COMPONENT(DDSimpleMuonDigi) | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# | ||
# Copyright (c) 2020-2024 Key4hep-Project. | ||
# | ||
# This file is part of Key4hep. | ||
# See https://key4hep.github.io/key4hep-doc/ for further info. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
from Gaudi.Configuration import INFO | ||
from k4FWCore import ApplicationMgr, IOSvc | ||
from Configurables import EventDataSvc | ||
from Configurables import DDSimpleMuonDigi | ||
|
||
from Configurables import GeoSvc | ||
from Configurables import UniqueIDGenSvc | ||
from Configurables import RootHistSvc | ||
from Configurables import Gaudi__Histograming__Sink__Root as RootHistoSink | ||
import os | ||
|
||
id_service = UniqueIDGenSvc("UniqueIDGenSvc") | ||
|
||
geoservice = GeoSvc("GeoSvc") | ||
geoservice.detectors = [os.environ["K4GEO"]+"/FCCee/CLD/compact/CLD_o2_v06/CLD_o2_v06.xml"] | ||
geoservice.OutputLevel = INFO | ||
geoservice.EnableGeant4Geo = False | ||
|
||
digi = DDSimpleMuonDigi() | ||
|
||
digi.SubDetectorName = "VXD" | ||
digi.KeepBarrelLayersVec = [] | ||
digi.KeepEndcapLayersVec = [] | ||
digi.muonCollections = "ECalBarrelCollection" # "ECalBarrelCollection","ECalEndcapCollection","HCalBarrelCollection","HCalEndcapCollection","HCalRingCollection","LumiCalCollection","YokeBarrelCollection","YokeEndcapCollection" | ||
digi.outputRelCollection = "RelationMuonHit" | ||
digi.outputMuonCollection = "CalorimeterHit" | ||
digi.EncodingStringParameterName = "GlobalTrackerReadoutID" | ||
digi.CellIDLayerString = "layer" | ||
digi.MuonThreshold = 0.025 | ||
digi.timethresholdMuon = 0.025 | ||
digi.calibrationCoeffmuon = 120000.0 | ||
digi.maxMuonHitEnergy = 2.0 | ||
digi.detectornameB = "YokeBarrel" | ||
digi.detectornameE = "YokeEndcap" | ||
|
||
iosvc = IOSvc() | ||
iosvc.input = "../simulation/sim_partgun_1000.root" | ||
iosvc.output = "../outputfiles/output_Gaudi.root" | ||
|
||
hps = RootHistSvc("HistogramPersistencySvc") | ||
root_hist_svc = RootHistoSink("RootHistoSink") | ||
root_hist_svc.FileName = "../outputfiles/ddmuondigi_hist.root" | ||
|
||
ApplicationMgr(TopAlg=[digi], | ||
EvtSel="NONE", | ||
EvtMax=-1, | ||
ExtSvc=[EventDataSvc("EventDataSvc"), root_hist_svc], | ||
OutputLevel=INFO, | ||
) |
Oops, something went wrong.