diff --git a/Detector/DetCRD/compact/CRD_common_v01/Muon_Barrel_v01_01.xml b/Detector/DetCRD/compact/CRD_common_v01/Muon_Barrel_v01_01.xml index 5afc3dd9e15237c80ece17397fa6b9a48bd78b91..a5dc0d51ca8a73f446e883c0456897adb590b8fe 100644 --- a/Detector/DetCRD/compact/CRD_common_v01/Muon_Barrel_v01_01.xml +++ b/Detector/DetCRD/compact/CRD_common_v01/Muon_Barrel_v01_01.xml @@ -49,7 +49,7 @@ </define> <detectors> - <detector id="201" name="MuonBarrel" type="Muon_Barrel_v01_01" readout="MuonBarrelCollection" vis="WhiteVis"> + <detector id="DetID_MUON" name="MuonBarrel" type="Muon_Barrel_v01_01" readout="MuonBarrelCollection" vis="WhiteVis"> <position x="0" y="0" z="0"/> <barrel id="Muon_barrel_iron_part_num" name="Muon_barrel_barrel" type="Muon_barrel_barrel" vis="SeeThrough"> <position x="0" y="Muon_barrel_barrel_posy" z="0"/> @@ -107,6 +107,7 @@ <readouts> <readout name="MuonBarrelCollection"> + <segmentation type="NoSegmentation"/> <id>system:5,Env:5,Fe:5,Superlayer:4,Layer:2,Stripe:9,SiPM:2</id> </readout> </readouts> diff --git a/Detector/DetCRD/compact/CRD_common_v01/Muon_Endcap_v01_01.xml b/Detector/DetCRD/compact/CRD_common_v01/Muon_Endcap_v01_01.xml index f4ab0c7c7b4ee72ad749ca901c4c55f58fc6099d..f4d7521a95021eeecc3d7e00b39ce5f046ce7756 100644 --- a/Detector/DetCRD/compact/CRD_common_v01/Muon_Endcap_v01_01.xml +++ b/Detector/DetCRD/compact/CRD_common_v01/Muon_Endcap_v01_01.xml @@ -27,7 +27,7 @@ </define> <detectors> - <detector id="202" name="Muon_Endcap_v01_01" type="Muon_Endcap_v01_01" readout="MuonEndcapCollection" vis="GrayVis" material="Iron"> + <detector id="DetID_MUON_ENDCAP" name="Muon_Endcap_v01_01" type="Muon_Endcap_v01_01" readout="MuonEndcapCollection" vis="GrayVis" material="Iron"> <material name="Iron"/> <position x="0" y="Muon_endcap_endcap_posy" z="0"/> <dimensions rmin="Muon_endcap_endcap_rmin" dz="0.5*Muon_endcap_endcap_z"/> @@ -74,6 +74,7 @@ <readouts> <readout name="MuonEndcapCollection"> + <segmentation type="NoSegmentation"/> <id>system:5,Env:5,Endcap:2,Superlayer:15:4,Layer:2,Stripe:9,SiPM:2</id> <!--id>Endcap:2,Superlayer:2,Env:2,Layer:2,Stripe:10:3,SiPM:2</id--> </readout> diff --git a/Detector/DetCRD/compact/CRD_common_v01/Muon_Endcap_v01_02.xml b/Detector/DetCRD/compact/CRD_common_v01/Muon_Endcap_v01_02.xml index 6cc84482c585fcaba6f76b04a9d8d16f907391bb..9825031c3ecfc89893f22eaf60a1836a34189114 100644 --- a/Detector/DetCRD/compact/CRD_common_v01/Muon_Endcap_v01_02.xml +++ b/Detector/DetCRD/compact/CRD_common_v01/Muon_Endcap_v01_02.xml @@ -32,7 +32,7 @@ </define> <detectors> - <detector id="20211" name="MuonEndcap" type="Muon_Endcap_v01_02" readout="MuonEndcapCollection" vis="GrayVis" material="Iron"> + <detector id="DetID_MUON_ENDCAP" name="MuonEndcap" type="Muon_Endcap_v01_02" readout="MuonEndcapCollection" vis="GrayVis" material="Iron"> <material name="Iron"/> <position x="0" y="Muon_endcap_endcap_posy" z="0"/> <dimensions rmin="Muon_endcap_endcap_rmin" dz="0.5*Muon_endcap_endcap_z"/> @@ -79,6 +79,7 @@ <readouts> <readout name="MuonEndcapCollection"> + <segmentation type="NoSegmentation"/> <id>system:5,Env:5,Endcap:2,Superlayer:15:4,Layer:2,Stripe:9,SiPM:2</id> <!--id>Endcap:2,Superlayer:2,Env:2,Layer:2,Stripe:10:3,SiPM:2</id--> </readout> diff --git a/Detector/DetCRD/compact/TDR_o1_v01/TDR_Dimensions_v01_01.xml b/Detector/DetCRD/compact/TDR_o1_v01/TDR_Dimensions_v01_01.xml index 010a501909a47d0e974cebaf2d2d5557ce34ccef..263b3642e13a3dfbfdc9fe7f56cb762f709d9daf 100644 --- a/Detector/DetCRD/compact/TDR_o1_v01/TDR_Dimensions_v01_01.xml +++ b/Detector/DetCRD/compact/TDR_o1_v01/TDR_Dimensions_v01_01.xml @@ -51,6 +51,8 @@ <constant name="DetID_ECAL_ENDCAP" value=" 29"/> <constant name="DetID_HCAL_ENDCAP" value=" 30"/> <constant name="DetID_YOKE_ENDCAP" value=" 31"/> + <constant name="DetID_MUON" value=" 10"/> + <constant name="DetID_MUON_ENDCAP" value=" 11"/> <constant name="DetID_bwd" value="-1"/> <constant name="DetID_barrel" value=" 0"/> diff --git a/Detector/DetCRD/scripts/TDR_o1_v01/tracking.py b/Detector/DetCRD/scripts/TDR_o1_v01/tracking.py index 8f8b262c87b1ce7e9567f32f4db5d1da6e9fc666..5e7ac32a458e18b5059d864bec26b0064bfc7a73 100644 --- a/Detector/DetCRD/scripts/TDR_o1_v01/tracking.py +++ b/Detector/DetCRD/scripts/TDR_o1_v01/tracking.py @@ -53,10 +53,16 @@ podioinput = PodioInput("PodioReader", collections=[ "TPCCollection", # "SETCollection", "OTKBarrelCollection", - "FTDCollection" + "FTDCollection", + "MuonBarrelCollection" ]) -# digitization + +################## +# Digitization +################## + +## Config ## vxdhitname = "VXDTrackerHits" sithitname = "SITTrackerHits" gashitname = "TPCTrackerHits" @@ -74,6 +80,8 @@ vxdtool.ParametersU = [5.60959e-03, 5.74913e-03, 7.03433e-03, 1.99516, -663.952, vxdtool.ParametersV = [5.60959e-03, 5.74913e-03, 7.03433e-03, 1.99516, -663.952, 3.752e-03, 0, -0.0704734, 0.0454867e-03, 1.07359] #vxdtool.OutputLevel = DEBUG + +## VXD ## from Configurables import SiTrackerDigiAlg digiVXD = SiTrackerDigiAlg("VXDDigi") digiVXD.SimTrackHitCollection = "VXDCollection" @@ -82,6 +90,8 @@ digiVXD.TrackerHitAssociationCollection = "VXDTrackerHitAssociation" digiVXD.DigiTool = "SmearDigiTool/VXD" #digiVXD.OutputLevel = DEBUG + +## SIT ## from Configurables import PlanarDigiAlg digiSIT = PlanarDigiAlg("SITDigi") digiSIT.IsStrip = False @@ -96,6 +106,8 @@ digiSIT.ParametersU = [2.29655e-03, 0.965899e-03, 0.584699e-03, 17.0856, 84.566, digiSIT.ParametersV = [1.44629e-02, 2.20108e-03, 1.03044e-02, 4.39195e+00, 3.29641e+00, 1.55167e+18, -5.41954e+01, 5.72986e+00, -6.80699e-03, 5.04095e-01] #digiSIT.OutputLevel = DEBUG + +## SET ## digiSET = PlanarDigiAlg("SETDigi") digiSET.IsStrip = False digiSET.SimTrackHitCollection = "OTKBarrelCollection" @@ -109,6 +121,8 @@ digiSET.ParametersU = [2.29655e-03, 0.965899e-03, 0.584699e-03, 17.0856, 84.566, digiSET.ParametersV = [1.44629e-02, 2.20108e-03, 1.03044e-02, 4.39195e+00, 3.29641e+00, 1.55167e+18, -5.41954e+01, 5.72986e+00, -6.80699e-03, 5.04095e-01] #digiSET.OutputLevel = DEBUG + +## FTD ## digiFTD = PlanarDigiAlg("FTDDigi") digiFTD.IsStrip = False digiFTD.SimTrackHitCollection = "FTDCollection" @@ -122,6 +136,7 @@ digiFTD.ParametersU = [2.29655e-03, 0.965899e-03, 0.584699e-03, 17.0856, 84.566, digiFTD.ParametersV = [1.44629e-02, 2.20108e-03, 1.03044e-02, 4.39195e+00, 3.29641e+00, 1.55167e+18, -5.41954e+01, 5.72986e+00, -6.80699e-03, 5.04095e-01] #digiFTD.OutputLevel = DEBUG +## TPC ## from Configurables import TPCDigiAlg digiTPC = TPCDigiAlg("TPCDigi") digiTPC.TPCCollection = "TPCCollection" @@ -136,7 +151,19 @@ digiTPC.TPCTrackerHitsCol = gashitname #digiTPC.N_eff = 30 #digiTPC.OutputLevel = DEBUG -# tracking + +## Muon Detector ## +from Configurables import MuonDigiAlg +digiMuon = MuonDigiAlg("MuonDigiAlg") +digiMuon.MuonBarrelHitsCollection = "MuonBarrelCollection" +digiMuon.MuonBarrelTrackerHits = "MuonBarrelTrackerHits" +digiMuon.WriteNtuple = 0 +digiMuon.OutFileName = "Digi_MUON.root" +######################################### + +################ +# Tracking +################ from Configurables import KalTestTool # Close multiple scattering and smooth, used by clupatra kt010 = KalTestTool("KalTest010") @@ -258,7 +285,7 @@ out.outputCommands = ["keep *"] # ApplicationMgr from Configurables import ApplicationMgr mgr = ApplicationMgr( - TopAlg = [podioinput, digiVXD, digiSIT, digiSET, digiFTD, digiTPC, tracking, forward, subset, clupatra, full, tpr, tpc_dndx, tmt, out], + TopAlg = [podioinput, digiVXD, digiSIT, digiSET, digiFTD, digiTPC, digiMuon, tracking, forward, subset, clupatra, full, tpr, tpc_dndx, tmt, out], EvtSel = 'NONE', EvtMax = 5, ExtSvc = [rndmengine, rndmgensvc, dsvc, evtseeder, geosvc, gearsvc, tracksystemsvc, pidsvc], diff --git a/Detector/DetIdentifier/include/DetIdentifier/CEPCConf.h b/Detector/DetIdentifier/include/DetIdentifier/CEPCConf.h index a6e47b6b987d3fd81836735bbb3ed76f28d30709..a4c0ec33309b7b753f8e9c4696de6b4fb80fe700 100644 --- a/Detector/DetIdentifier/include/DetIdentifier/CEPCConf.h +++ b/Detector/DetIdentifier/include/DetIdentifier/CEPCConf.h @@ -27,6 +27,8 @@ namespace CEPCConf{ static const int ECAL_ENDCAP = 29; static const int HCAL_ENDCAP = 30; static const int YOKE_ENDCAP = 31; + static const int MUON = 10; + static const int MUON_ENDCAP = 11; static const int bwd = -1; static const int barrel = 0; diff --git a/Digitization/CMakeLists.txt b/Digitization/CMakeLists.txt index 53f9bdc53e2b9d5aa34244a73ad438d8b6cada43..960adbed116613f898c1d20925391df27539cbf2 100644 --- a/Digitization/CMakeLists.txt +++ b/Digitization/CMakeLists.txt @@ -5,3 +5,4 @@ add_subdirectory(SimHitMerge) add_subdirectory(DigiSimple) add_subdirectory(DigiCalo) add_subdirectory(Digi_Calo) +add_subdirectory(DigiMuon) diff --git a/Digitization/DigiMuon/CMakeLists.txt b/Digitization/DigiMuon/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..396908f69f20d315fa755e9455eab5a813b5e431 --- /dev/null +++ b/Digitization/DigiMuon/CMakeLists.txt @@ -0,0 +1,21 @@ +# Modules +gaudi_add_module(MuonDigi + SOURCES src/MuonDigiAlg.cpp + LINK k4FWCore::k4FWCore + GearSvc + DetInterface + Gaudi::GaudiKernel + Gaudi::GaudiAlgLib + ${CLHEP_LIBRARIES} + ${GEAR_LIBRARIES} + ${GSL_LIBRARIES} + ${LCIO_LIBRARIES} + ${ROOT_LIBRARIES} + EDM4HEP::edm4hep EDM4HEP::edm4hepDict +) +install(TARGETS MuonDigi + EXPORT CEPCSWTargets + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" COMPONENT bin + LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT shlib + COMPONENT dev) + diff --git a/Digitization/DigiMuon/src/MuonDigiAlg.cpp b/Digitization/DigiMuon/src/MuonDigiAlg.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4e860338d20f63bacfb920c6ce4f3a0e814fdfd5 --- /dev/null +++ b/Digitization/DigiMuon/src/MuonDigiAlg.cpp @@ -0,0 +1,270 @@ +#include "MuonDigiAlg.h" + +#include "edm4hep/Vector3f.h" + +#include "DD4hep/Detector.h" +#include <DD4hep/Objects.h> +#include "DD4hep/DD4hepUnits.h" +#include "DDRec/Vector3D.h" + +#include "GaudiKernel/INTupleSvc.h" +#include "GaudiKernel/MsgStream.h" +#include "GaudiKernel/IRndmGen.h" +#include "GaudiKernel/IRndmGenSvc.h" +#include "GaudiKernel/RndmGenerators.h" + +#include "edm4hep/SimCalorimeterHit.h" +#include "edm4hep/CalorimeterHit.h" +#include "edm4hep/Vector3f.h" +#include "edm4hep/Cluster.h" + +#include "DD4hep/Detector.h" +#include <DD4hep/Objects.h> +#include <DDRec/CellIDPositionConverter.h> + +#include "TVector3.h" +//#include "TRandom3.h" +//#include <TRandom.h> +#include <math.h> +#include <cmath> +#include <iostream> +#include <algorithm> +#include <map> +#include <random> +#include <iostream> +#include <vector> + + +using namespace std ; + +DECLARE_COMPONENT( MuonDigiAlg ) + +MuonDigiAlg::MuonDigiAlg(const std::string& name, ISvcLocator* svcLoc) +: GaudiAlgorithm(name, svcLoc) +{ + // Input collections + declareProperty("MuonBarrelHitsCollection", m_inputMuonBarrel, "Handle of the Input SimTrackerHit collection"); + + // Output collections + declareProperty("MuonBarrelTrackerHits", m_outputMuonBarrel, "Handle of the output TrackerHit collection"); + //declareProperty("MuonBarrelTrackerHitAssociationCollection", m_assMuonBarrel, "Handle of the Association collection between SimTrackerHit and TrackerHit"); +} + + +StatusCode MuonDigiAlg::initialize() +{ + // set rand seed; + rand_muon.SetSeed(123456); + + // + if(_writeNtuple) + { + std::string s_outfile = _filename; + m_wfile = new TFile(s_outfile.c_str(), "recreate"); + hitloop = new TTree("h1", "muonbarreldigi_hitloop"); + eventloop = new TTree("e1", "muonbarreldigi_eventloop"); + hitloop->Branch("MuonBarrel_cellid", &MuonBarrel_cellid); + hitloop->Branch("MuonBarrel_posx", &MuonBarrel_posx); + hitloop->Branch("MuonBarrel_posy", &MuonBarrel_posy); + hitloop->Branch("MuonBarrel_posz", &MuonBarrel_posz); + eventloop->Branch("MuonBarrel_stripcellid", &MuonBarrel_stripcellid); + eventloop->Branch("MuonBarrel_stripedep", &MuonBarrel_stripedep); + } + + + m_geosvc = service<IGeomSvc>("GeomSvc"); + if(!m_geosvc) + { + error() << "Failed to get the GeomSvc" << endmsg; + return StatusCode::FAILURE; + } + auto m_dd4hep = m_geosvc->lcdd(); + if(!m_dd4hep) + { + error() << "Failed to get the Detector from GeomSvc" << endmsg; + return StatusCode::FAILURE; + } + std::string readout_name = m_inputMuonBarrel.objKey(); + debug() << "Readout name: " << readout_name << endmsg; + m_cellIDConverter = new dd4hep::rec::CellIDPositionConverter(*m_dd4hep); + + if(!m_cellIDConverter) + { + error() << "Failed to get the m_cellIDConverter." << endmsg; + return StatusCode::FAILURE; + } + m_decoder = m_geosvc->getDecoder(readout_name); + if(!m_decoder) + { + error() << "Failed to get the decoder. " << endmsg; + return StatusCode::FAILURE; + } + + info() << "MuonDigiAlg::initialized" << endmsg; + return GaudiAlgorithm::initialize(); +} + + +StatusCode MuonDigiAlg::execute() +{ + + + Clear(); + trkhitVec = m_outputMuonBarrel.createAndPut(); + //auto assVec = m_assMuonBarrel.createAndPut(); + + + const edm4hep::SimTrackerHitCollection* STHCol = nullptr; + try + { + STHCol = m_inputMuonBarrel.get(); + } + catch(GaudiException &e) + { + debug() << "Collection " << m_inputMuonBarrel.fullKey() << " is unavailable in event " << m_nEvt << endmsg; + return StatusCode::SUCCESS; + } + if(STHCol->size()==0) return StatusCode::SUCCESS; + debug() << m_inputMuonBarrel.fullKey() << " has SimTrackerHit "<< STHCol->size() << endmsg; + + + int strip_length[8] = {17, 29, 41, 53, 65, 77, 89, 101}; + + for(auto simhit : *STHCol) + { + auto cellid = simhit.getCellID(); + auto Edep = simhit.getEDep();//GeV + int layer = m_decoder->get(cellid, "Layer"); + int slayer = m_decoder->get(cellid, "Superlayer"); + int strip = m_decoder->get(cellid, "Stripe"); + int Fe = m_decoder->get(cellid, "Fe"); + int Env = m_decoder->get(cellid, "Env"); + auto& pos = simhit.getPosition(); + + dd4hep::Position hitpos = m_cellIDConverter->position(cellid); + debug() << "Position:: " << hitpos.x() << " " << hitpos.y() << " " << hitpos.z() << endmsg; + + int testtemp = 0; + if(Edep<0.01&&Edep>0.0001) + { + double hit_strip_length = std::sqrt((hitpos.x()-pos[0]*0.1)*(hitpos.x()-pos[0]*0.1)+(hitpos.y()-pos[1]*0.1)*(hitpos.y()-pos[1]*0.1)+(hitpos.z()-pos[2]*0.1)*(hitpos.z()-pos[2]*0.1)); + double hit_sipm_length; + if(layer == 1) + { + int tempnum = Env + slayer; + if(tempnum%2 == 0) + { + hit_sipm_length = 115 * 2 - hit_strip_length; + } + else + { + hit_sipm_length = 106 * 2 - hit_strip_length; + } + } + if(layer == 2) + { + hit_sipm_length = strip_length[slayer-1] * 2 - hit_strip_length; + } + + double ADCmean = 34*Edep*47.09/(23*0.00141);//mV + if(hit_sipm_length>10) + { + ADCmean = (16.0813*std::exp(-1*hit_sipm_length/50.8147)+19.5474)*Edep*47.09/(23*0.00141);//mV + } + double ADC = rand_muon.Landau(ADCmean,7.922); + if(ADC<0) + { + ADC = 0; + } + //std::cout<<hit_sipm_length<<" "<<Edep<<" "<<ADCmean<<" "<<ADC<<std::endl; + + if(cellidtemp.size()>0) + { + for(int i=0; i<cellidtemp.size(); i++) + { + if(cellid == cellidtemp[i]) + { + edeptemp[i]+=Edep; + ADCtemp[i]+=ADC; + testtemp++; + break; + } + } + } + if(testtemp==0) + { + cellidtemp.push_back(cellid); + edeptemp.push_back(Edep); + ADCtemp.push_back(ADC); + } + if(_writeNtuple) + { + MuonBarrel_cellid.push_back(cellid); + MuonBarrel_posx.push_back(pos[0]); + MuonBarrel_posy.push_back(pos[1]); + MuonBarrel_posz.push_back(pos[2]); + } + } + } + + for(int i=0; i<cellidtemp.size(); i++) + { + if(edeptemp[i]>0.0005&&edeptemp[i]<0.005&&ADCtemp[i]<1000) + { + double random_num = rand_muon.Uniform(0, 1); + if(random_num>0.1) + { + if(_writeNtuple) + { + MuonBarrel_stripcellid.push_back(cellidtemp[i]); + MuonBarrel_stripedep.push_back(edeptemp[i]); + } + edm4hep::MutableTrackerHit trkHit; + dd4hep::Position hitpos1 = m_cellIDConverter->position(cellidtemp[i]); + edm4hep::Vector3d position_strip(hitpos1.x(),hitpos1.y(),hitpos1.z()); + //std::cout<<"Position:: "<<hitpos.x()<<" "<<hitpos.y()<<" "<<hitpos.z()<<std::endl; + trkHit.setEDep(ADCtemp[i]); + trkHit.setCellID(cellidtemp[i]); + trkHit.setPosition(position_strip); + trkhitVec->push_back( trkHit ); + } + } + } + + if(_writeNtuple) + { + hitloop->Fill(); + eventloop->Fill(); + } + + m_nEvt++; + return StatusCode::SUCCESS; +} + +StatusCode MuonDigiAlg::finalize() +{ + + if(_writeNtuple) + { + m_wfile->cd(); + hitloop->Write(); + eventloop->Write(); + m_wfile->Close(); + delete m_wfile, hitloop, eventloop; + } + info() << "Processed " << m_nEvt << " events " << endmsg; + return GaudiAlgorithm::finalize(); +} + +void MuonDigiAlg::Clear() +{ + MuonBarrel_cellid.clear(); + MuonBarrel_posx.clear(); + MuonBarrel_posy.clear(); + MuonBarrel_posz.clear(); + MuonBarrel_stripcellid.clear(); + MuonBarrel_stripedep.clear(); + cellidtemp.clear(); + edeptemp.clear(); + ADCtemp.clear(); +} diff --git a/Digitization/DigiMuon/src/MuonDigiAlg.h b/Digitization/DigiMuon/src/MuonDigiAlg.h new file mode 100644 index 0000000000000000000000000000000000000000..1ebae24da24db1748b53c39fd287e6af663330f7 --- /dev/null +++ b/Digitization/DigiMuon/src/MuonDigiAlg.h @@ -0,0 +1,114 @@ +#ifndef MuonDigiAlg_H +#define MuonDigiAlg_H + +#include "k4FWCore/DataHandle.h" +#include "GaudiKernel/NTuple.h" +#include "GaudiAlg/GaudiAlgorithm.h" +#include "edm4hep/SimTrackerHitCollection.h" +#include "edm4hep/TrackerHitCollection.h" +#include "edm4hep/MCRecoTrackerAssociationCollection.h" + +#include <DDRec/DetectorData.h> +#include "DetInterface/IGeomSvc.h" + +#include "k4FWCore/DataHandle.h" +#include "GaudiAlg/GaudiAlgorithm.h" +#include "edm4hep/MutableCaloHitContribution.h" +#include "edm4hep/MutableSimCalorimeterHit.h" +#include "edm4hep/SimCalorimeterHit.h" +#include "edm4hep/CalorimeterHit.h" +#include "edm4hep/CalorimeterHitCollection.h" +#include "edm4hep/SimCalorimeterHitCollection.h" +#include "edm4hep/MCRecoCaloAssociationCollection.h" +#include "edm4hep/MCRecoCaloParticleAssociationCollection.h" + +#include <DDRec/DetectorData.h> +#include <DDRec/CellIDPositionConverter.h> +#include <DD4hep/Segmentations.h> +#include "DetInterface/IGeomSvc.h" +#include "TVector3.h" +#include "TRandom3.h" +#include "TFile.h" +#include "TString.h" +#include "TH3.h" +#include "TH1.h" + +#include <cstdlib> +#include "time.h" +#include <TTimeStamp.h> +#include <ctime> +#include <iostream> +//#include <TRandom.h> +#include <TMath.h> +#define PI 3.141592653 +class MuonDigiAlg : public GaudiAlgorithm +{ + public: + + MuonDigiAlg(const std::string& name, ISvcLocator* svcLoc); + + virtual StatusCode initialize() ; + virtual StatusCode execute() ; + virtual StatusCode finalize() ; + void Clear(); + + + // double EDepConvertADC(double edep){ + // rand.SetSeed(0); + // randGen.SetSeed(0); + // double adc = 0; + // Double_t random_num = rand.Uniform(0, 1); + // if(random_num>0.1){ + // double LandauRandom = randGen.Landau(47.09,7.922); + // adc = LandauRandom * edep / 0.00141; + // } + // return random_num; + // } + + + + protected: + + + TRandom3 rand_muon; + + TTree* hitloop; + TTree* eventloop; + TFile* m_wfile; + + SmartIF<IGeomSvc> m_geosvc; + dd4hep::DDSegmentation::BitFieldCoder* m_decoder; + dd4hep::rec::CellIDPositionConverter* m_cellIDConverter; + dd4hep::Detector* m_dd4hep; + + std::vector<unsigned long long> MuonBarrel_cellid; + std::vector<double> MuonBarrel_posx; + std::vector<double> MuonBarrel_posy; + std::vector<double> MuonBarrel_posz; + std::vector<unsigned long long> cellidtemp; + std::vector<double> edeptemp; + std::vector<double> ADCtemp; + std::vector<unsigned long long> MuonBarrel_stripcellid; + std::vector<double> MuonBarrel_stripedep; + + + + + + mutable Gaudi::Property<int> _writeNtuple{this, "WriteNtuple", 1, "Write ntuple"}; + mutable Gaudi::Property<std::string> _filename{this, "OutFileName", "testout.root", "Output file name"}; + + // Input collections + DataHandle<edm4hep::SimTrackerHitCollection> m_inputMuonBarrel{"MuonBarrelHitsCollection", Gaudi::DataHandle::Reader, this}; + // Output collections + DataHandle<edm4hep::TrackerHitCollection> m_outputMuonBarrel{"MuonBarrelTrackerHits", Gaudi::DataHandle::Writer, this}; + //DataHandle<edm4hep::MCRecoTrackerAssociationCollection> m_assMuonBarrel{"MuonBarrelTrackerHitAssociationCollection", Gaudi::DataHandle::Writer, this}; + + edm4hep::TrackerHitCollection* trkhitVec; + + int m_nEvt=0; +}; +#endif + + +