diff --git a/DDG4/examples/CLICSidSimuMarkus.py b/DDG4/examples/CLICSidSimuMarkus.py index a929f349d5f1cca412df715b7018a7c1c11aadbe..d6a6056ed509beba143e255ed7e474efc1e0fef5 100644 --- a/DDG4/examples/CLICSidSimuMarkus.py +++ b/DDG4/examples/CLICSidSimuMarkus.py @@ -48,11 +48,12 @@ def run(): #VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV """ Generation of primary particles from LCIO input files + """ # First particle file reader gen = DDG4.GeneratorAction(kernel,"LCIOInputAction/LCIO1"); #gen.Input = "LCIOStdHepReader|/home/frankm/SW/data/e2e2nn_gen_1343_1.stdhep" - #gen.Input = "LCIOStdHepReader|/home/frankm/SW/data/qq_gen_128_999.stdhep" + gen.Input = "LCIOStdHepReader|/home/frankm/SW/data/qq_gen_128_999.stdhep" #gen.Input = "LCIOStdHepReader|/home/frankm/SW/data/smuonLR_PointK_3TeV_BS_noBkg_run0001.stdhep" #gen.Input = "LCIOStdHepReader|/home/frankm/SW/data/bbbb_3TeV.stdhep" #gen.Input = "LCIOFileReader|/home/frankm/SW/data/mcparticles_pi-_5GeV.slcio" @@ -61,7 +62,7 @@ def run(): #gen.Input = "LCIOStdHepReader|/home/frankm/SW/data/FCC-eh.stdhep" #gen.Input = "Geant4EventReaderHepMC|/home/frankm/SW/data/data.hepmc.txt" #gen.Input = "Geant4EventReaderHepMC|/home/frankm/SW/data/sherpa-2.1.1_zjets.hepmc2g" - gen.Input = "LCIOFileReader|/afs/cern.ch/user/n/nikiforo/public/Markus/muons.slcio" + #gen.Input = "LCIOFileReader|/afs/cern.ch/user/n/nikiforo/public/Markus/muons.slcio" #gen.Input = "LCIOFileReader|/afs/cern.ch/user/n/nikiforo/public/Markus/geantinos.slcio" gen.MomentumScale = 1.0 gen.Mask = 1 @@ -72,7 +73,8 @@ def run(): gen.isotrop = False gen.direction = (1,0,0) gen.OutputLevel = generator_output_level - + """ + """ # And handle the simulation particles. part = DDG4.GeneratorAction(kernel,"Geant4ParticleHandler/ParticleHandler") kernel.generatorAction().adopt(part) @@ -86,7 +88,7 @@ def run(): user.TrackingVolume_Rmax = DDG4.EcalBarrel_rmin user.enableUI() part.adopt(user) - + """ """ rdr = DDG4.GeneratorAction(kernel,"LcioGeneratorAction/Reader") rdr.zSpread = 0.0 @@ -97,8 +99,8 @@ def run(): kernel.generatorAction().adopt(rdr) """ - seq,act = simple.setupTracker('SiTrackerBarrel') - """ + #seq,act = simple.setupTracker('SiTrackerBarrel') + # First the tracking detectors seq,act = simple.setupTracker('SiVertexBarrel') seq,act = simple.setupTracker('SiVertexEndcap') @@ -115,11 +117,11 @@ def run(): seq,act = simple.setupCalorimeter('MuonEndcap') seq,act = simple.setupCalorimeter('LumiCal') seq,act = simple.setupCalorimeter('BeamCal') - """ - scan = DDG4.SteppingAction(kernel,'Geant4MaterialScanner/MaterialScan') kernel.steppingAction().adopt(scan) + """ + # Now build the physics list: phys = simple.setupPhysics('QGSP_BERT') diff --git a/DDG4/include/DDG4/Geant4OutputAction.h b/DDG4/include/DDG4/Geant4OutputAction.h index 82f20d5892f42746642a72e4a6e5656a3985d2f7..15b10d6c480ce036358761b763b6d01bfaf23af4 100644 --- a/DDG4/include/DDG4/Geant4OutputAction.h +++ b/DDG4/include/DDG4/Geant4OutputAction.h @@ -24,6 +24,9 @@ namespace DD4hep { /// Namespace for the Geant4 based simulation part of the AIDA detector description toolkit namespace Simulation { + // Forward declarations + class Geant4ParticleMap; + /// Base class to output Geant4 event data to persistent media /** * \author M.Frank @@ -47,7 +50,8 @@ namespace DD4hep { /// Property: output destination std::string m_output; - + /// Reference to MC truth object + Geant4ParticleMap* m_truth; public: /// Standard constructor Geant4OutputAction(Geant4Context* c, const std::string& nam); diff --git a/DDG4/include/DDG4/Geant4Particle.h b/DDG4/include/DDG4/Geant4Particle.h index bf4c030fbb7d744385aebea77cd757eabf8845b9..d7f9f1685bbf0a7f4a3dba7bbf7558886f4330ca 100644 --- a/DDG4/include/DDG4/Geant4Particle.h +++ b/DDG4/include/DDG4/Geant4Particle.h @@ -308,6 +308,8 @@ namespace DD4hep { Geant4ParticleMap() {} /// Default destructor virtual ~Geant4ParticleMap(); + /// Check if the particle map was ever filled (ie. some particle handler was present) + bool isValid() const; /// Dump content void dump() const; /// Clear particle maps diff --git a/DDG4/plugins/Geant4SDActions.cpp b/DDG4/plugins/Geant4SDActions.cpp index 31b37fcb74af78af504e6cf8bfe2124f71de7702..f309cb56689a7509ebb6cc7a933e52a17415ca24 100644 --- a/DDG4/plugins/Geant4SDActions.cpp +++ b/DDG4/plugins/Geant4SDActions.cpp @@ -43,31 +43,25 @@ namespace DD4hep { double new_len = mean_length(h.preMom(),h.postMom())/hit_len; direction *= new_len/hit_len; } - print("Geant4Tracker","%s> Add hit with deposit:%e MeV Pos:%8.2f %8.2f %8.2f", - c_name(),step->GetTotalEnergyDeposit(),position.X(),position.Y(),position.Z()); Hit* hit = new Hit(h.trkID(), h.trkPdgID(), h.deposit(), h.track->GetGlobalTime()); - if ( hit ) { - HitContribution contrib = Hit::extractContribution(step); - hit->cellID = cellID(step); - hit->energyDeposit = contrib.deposit; - hit->position = position; - hit->momentum = direction; - hit->length = hit_len; - collection(m_collectionID)->add(hit); - mark(h.track); - if ( 0 == hit->cellID ) { - hit->cellID = volumeID( step ) ; - except("+++ Invalid CELL ID for hit!"); - } - print("Geant4Tracker","%s> Hit with deposit:%f Pos:%f %f %f ID=%016X", - c_name(),step->GetTotalEnergyDeposit(),position.X(),position.Y(),position.Z(), - (void*)hit->cellID); - Geant4TouchableHandler handler(step); - print("Geant4Tracker","%s> Geant4 path:%s",c_name(),handler.path().c_str()); - return true; + HitContribution contrib = Hit::extractContribution(step); + hit->cellID = cellID(step); + hit->energyDeposit = contrib.deposit; + hit->position = position; + hit->momentum = direction; + hit->length = hit_len; + collection(m_collectionID)->add(hit); + mark(h.track); + if ( 0 == hit->cellID ) { + hit->cellID = volumeID( step ) ; + except("+++ Invalid CELL ID for hit!"); } - except("new() failed: Cannot allocate hit object"); - return false; + print("%s> Hit with deposit:%f Pos:%f %f %f ID=%016X", + c_name(),step->GetTotalEnergyDeposit(),position.X(),position.Y(),position.Z(), + (void*)hit->cellID); + Geant4TouchableHandler handler(step); + print("%s> Geant4 path:%s",c_name(),handler.path().c_str()); + return true; } typedef Geant4SensitiveAction<Geant4Tracker> Geant4TrackerAction; @@ -98,7 +92,7 @@ namespace DD4hep { hit = new Hit(global); hit->cellID = cell; coll->add(hit); - printM2("Geant4Calorimeter","%s> CREATE hit with deposit:%e MeV Pos:%8.2f %8.2f %8.2f %s", + printM2("%s> CREATE hit with deposit:%e MeV Pos:%8.2f %8.2f %8.2f %s", c_name(),contrib.deposit,pos.X,pos.Y,pos.Z,handler.path().c_str()); if ( 0 == hit->cellID ) { // for debugging only! hit->cellID = cellID(step); diff --git a/DDG4/src/Geant4Output2ROOT.cpp b/DDG4/src/Geant4Output2ROOT.cpp index b4c247be7af41ee1e9918079ec59dbe0a907ba59..48714113d46679c8b327ff0e2018f1de286e93ba 100644 --- a/DDG4/src/Geant4Output2ROOT.cpp +++ b/DDG4/src/Geant4Output2ROOT.cpp @@ -158,30 +158,29 @@ void Geant4Output2ROOT::saveCollection(OutputContext<G4Event>& /* ctxt */, G4VHi if (coll) { coll->getHitsUnchecked(hits); size_t nhits = coll->GetSize(); - Geant4ParticleMap* truth = context()->event().extension<Geant4ParticleMap>(); - if ( m_handleMCTruth && truth && nhits > 0 ) { + if ( m_handleMCTruth && m_truth && nhits > 0 ) { try { - for(size_t i=0; i<nhits; ++i) { - Geant4HitData* h = coll->hit(i); - Geant4Tracker::Hit* trk_hit = dynamic_cast<Geant4Tracker::Hit*>(h); - if ( 0 != trk_hit ) { - Geant4HitData::Contribution& t = trk_hit->truth; - int trackID = t.trackID; - t.trackID = truth->particleID(trackID); - } - Geant4Calorimeter::Hit* cal_hit = dynamic_cast<Geant4Calorimeter::Hit*>(h); - if ( 0 != cal_hit ) { - Geant4HitData::Contributions& c = cal_hit->truth; - for(Geant4HitData::Contributions::iterator j=c.begin(); j!=c.end(); ++j) { - Geant4HitData::Contribution& t = *j; - int trackID = t.trackID; - t.trackID = truth->particleID(trackID); - } - } - } + for(size_t i=0; i<nhits; ++i) { + Geant4HitData* h = coll->hit(i); + Geant4Tracker::Hit* trk_hit = dynamic_cast<Geant4Tracker::Hit*>(h); + if ( 0 != trk_hit ) { + Geant4HitData::Contribution& t = trk_hit->truth; + int trackID = t.trackID; + t.trackID = m_truth->particleID(trackID); + } + Geant4Calorimeter::Hit* cal_hit = dynamic_cast<Geant4Calorimeter::Hit*>(h); + if ( 0 != cal_hit ) { + Geant4HitData::Contributions& c = cal_hit->truth; + for(Geant4HitData::Contributions::iterator j=c.begin(); j!=c.end(); ++j) { + Geant4HitData::Contribution& t = *j; + int trackID = t.trackID; + t.trackID = m_truth->particleID(trackID); + } + } + } } catch(...) { - printout(ERROR,name(),"+++ Exception while saving collection %s.",hc_nam.c_str()); + printout(ERROR,name(),"+++ Exception while saving collection %s.",hc_nam.c_str()); } } fill(hc_nam, coll->vector_type(), &hits); diff --git a/DDG4/src/Geant4OutputAction.cpp b/DDG4/src/Geant4OutputAction.cpp index 0a0f91c5b400e47383f2a7ac2b0e16287b345ce4..e6c48c9fbb1ca62cc0fbb4aa26a9a88c97a5dc1a 100644 --- a/DDG4/src/Geant4OutputAction.cpp +++ b/DDG4/src/Geant4OutputAction.cpp @@ -10,6 +10,7 @@ // Framework include files #include "DD4hep/Printout.h" #include "DD4hep/InstanceCount.h" +#include "DDG4/Geant4Particle.h" #include "DDG4/Geant4RunAction.h" #include "DDG4/Geant4OutputAction.h" @@ -23,7 +24,7 @@ using namespace std; /// Standard constructor Geant4OutputAction::Geant4OutputAction(Geant4Context* ctxt, const string& nam) -: Geant4EventAction(ctxt, nam) +: Geant4EventAction(ctxt, nam), m_truth(0) { InstanceCount::increment(this); declareProperty("Output", m_output); @@ -46,12 +47,23 @@ void Geant4OutputAction::end(const G4Event* evt) { G4HCofThisEvent* hce = evt->GetHCofThisEvent(); if ( hce ) { int nCol = hce->GetNumberOfCollections(); - saveEvent(ctxt); - for (int i = 0; i < nCol; ++i) { - G4VHitsCollection* hc = hce->GetHC(i); - saveCollection(ctxt, hc); + try { + m_truth = context()->event().extension<Geant4ParticleMap>(false); + if ( m_truth && !m_truth->isValid() ) { + m_truth = 0; + printout(WARNING,name(),"+++ [Event:%d] No valid MC truth info present. " + "Is a Particle handler installed ?",evt->GetEventID()); + } + saveEvent(ctxt); + for (int i = 0; i < nCol; ++i) { + G4VHitsCollection* hc = hce->GetHC(i); + saveCollection(ctxt, hc); + } + commit(ctxt); } - commit(ctxt); + catch(...) { + } + m_truth = 0; return; } printout(WARNING,"Geant4OutputAction", diff --git a/DDG4/src/Geant4Particle.cpp b/DDG4/src/Geant4Particle.cpp index 7ba98359b5adec8988686fed4ee6a9be5faac82a..b9c7a7dda7dbcd469c6fbf082f7d26a27383ba00 100644 --- a/DDG4/src/Geant4Particle.cpp +++ b/DDG4/src/Geant4Particle.cpp @@ -428,6 +428,11 @@ void Geant4ParticleMap::adopt(ParticleMap& pm, TrackEquivalents& equiv) { //dump(); } +/// Check if the particle map was ever filled (ie. some particle handler was present) + bool Geant4ParticleMap::isValid() const { + return !equivalentTracks.empty(); +} + /// Access the equivalent track id (shortcut to the usage of TrackEquivalents) int Geant4ParticleMap::particleID(int g4_id, bool) const { TrackEquivalents::const_iterator iequiv = equivalentTracks.find(g4_id); diff --git a/examples/ClientTests/README.txt b/examples/ClientTests/README.txt new file mode 100644 index 0000000000000000000000000000000000000000..87a1ca100a9cfc452f0703f5a5f15f07d091fa10 --- /dev/null +++ b/examples/ClientTests/README.txt @@ -0,0 +1,44 @@ + +examples/ClientTests +==================== + +A set of example detectors used to debug special conditions +or problematic assemblies from users. + +FCC_Hcal: +-------- +by Carlos Solans +Detector constructor: src/FCC_Hcal.cpp +Compact XML: compact/FCC_HcalBarrel.xml + +FCC Hadron calorimeter +Comes together with the Geant4 simulation script scripts/FCC_Hcal.py +If you want to run Geant4 bootstrapped by a ROOT-AClick, have a look at +scripts/FCC_Hcal.C + +IronCylinder: +------------- +by Markus Frank +Detector constructor: src/IronCylinder_geo.cpp +Compact XML: compact/IronCylinder.xml + +Simple iron cylinder + +MiniTel: +-------- +Marco Clemecic & Anastasia Karachaliou +Detector constructor: src/MiniTel.cpp +Compact XML: compact/MiniTel.xml + +Simple telescope like detector setup with a number of silicon pixel detectors. +Comes together with the Geant4 simulation script scripts/MiniTel.py + +Assemblies_VXD: +-------------- +Frank Gade +Detector constructor: src/Assemblies_VXD_geo.cpp +Compact XML: compact/Assemblies.xml + +Test for nested assemblies using a mockup of the ILD vertex detector. +Test for the conversion of nested assemblies to Geant4 volumes. + diff --git a/examples/ClientTests/compact/MiniTel.xml b/examples/ClientTests/compact/MiniTel.xml new file mode 100644 index 0000000000000000000000000000000000000000..8296744e262283c8c2ee26f07c411007f59cbde1 --- /dev/null +++ b/examples/ClientTests/compact/MiniTel.xml @@ -0,0 +1,171 @@ +<?xml version="1.0" encoding="utf-8"?> +<lccdd xmlns:compact="http://www.lcsim.org/schemas/compact/1.0" + xmlns:xs="http://www.w3.org/2001/XMLSchema" + xs:noNamespaceSchemaLocation="http://www.lcsim.org/schemas/compact/1.0/compact.xsd"> + + <info name="Sensor" + title="Sensor for New experiment" + author="Anastasia Karachaliou" + status="development" + url="/afs/cern.ch/user/a/akaracha/workspace/MyExperiment/DetDesc/xmlDDescr/geometry_myexper.xml" + version= "v0r1"> + <comment>simple Detector as a small box</comment> + </info> + + <includes> + <gdmlFile ref="../../../DDDetectors/compact/elements.xml"/> + <gdmlFile ref="../../../DDDetectors/compact/materials.xml"/> + </includes> + + <define> + <constant name="world_side" value="2*m"/> + <constant name="world_x" value="world_side/2"/> + <constant name="world_y" value="world_side/2"/> + <constant name="world_z" value="world_side/2"/> + <constant name="CrossingAngle" value="0.020"/> + </define> + + <materials> + </materials> + + + <display> + <vis name="DetVis" alpha="1.0" r="0" g="1.0" b="0.0" showDaughters="true" visible="true" /> + <vis name="ModVis" alpha="1.0" r="1" g="0.0" b="0.0" showDaughters="true" visible="false" /> + + </display> + + + <detectors> + + <detector name="MyLHCBdetector1" type="MiniTelPixel" material="Silicon" vis="DetVis" id ="1" sensitive="true" readout="MyLHCBdetector1Hits"> + + <dimensions z="1*mm" y="10*cm" x="10*cm" /> + <position z="0*mm" y="0*cm" x="0*cm" /> + <module name="pixel" type="MiniTelPixel" material="Silicon" x="6*mm" y="6*mm" z="1*mm" vis="ModVis" alpha="-2.*radian" beta="-2.*radian" gamma="-0.*radian" /> + </detector> + + <detector name="MyLHCBdetector2" type="MiniTelPixel" material="Silicon" vis="DetVis" id ="2" sensitive="true" readout="MyLHCBdetector2Hits" > + + <dimensions z="1*mm" y="10*cm" x="10*cm" /> + <position z="10*mm" y="0*cm" x="0*cm" /> + <module name="pixel" type="MiniTelPixel" material="Silicon" x="6*mm" y="6*mm" z="1*mm" vis="ModVis" alpha="-2.*radian" beta="-2.*radian" gamma="-0.*radian" /> + </detector> + + <detector name="MyLHCBdetector3" type="MiniTelPixel" material="Silicon" vis="DetVis" id ="3" sensitive="true" readout="MyLHCBdetector3Hits"> + + <dimensions z="1*mm" y="10*cm" x="10*cm" /> + <position z="20*mm" y="0*cm" x="0*cm" /> + <module name="pixel" type="MiniTelPixel" material="Silicon" x="6*mm" y="6*mm" z="5*mm" vis="ModVis" alpha="-2.*radian" beta="-2.*radian" gamma="-0.*radian" /> + </detector> + + + <detector name="MyLHCBdetector4" type="MiniTelPixel" material="Silicon" vis="DetVis" id ="4" sensitive="true" readout="MyLHCBdetector4Hits"> + + <dimensions z="1*mm" y="10*cm" x="10*cm"/> + <position z="30*mm" y="0*cm" x="0*cm" /> + <module name="pixel" type="MiniTelPixel" material="Silicon" x="6*mm" y="6*mm" z="21*mm" vis="ModVis" alpha="-2.*radian" beta="-2.*radian" gamma="-0.*radian" /> + </detector> + + + <detector name="MyLHCBdetector5" type="MiniTelPixel" material="Silicon" vis="DetVis" id ="5" sensitive="true" readout="MyLHCBdetector5Hits"> + + <dimensions z="1*mm" y="10*cm" x="10*cm"/> + <position z="40*mm" y="0*cm" x="0*cm" /> + <module name="pixel" type="MiniTelPixel" material="Silicon" x="6*mm" y="6*mm" z="10*mm" vis="ModVis" alpha="-2.*radian" beta="-2.*radian" gamma="-0.*radian" /> + </detector> + + + <detector name="MyLHCBdetector6" type="MiniTelPixel" material="Silicon" vis="DetVis" id ="6" sensitive="true" readout="MyLHCBdetector7Hits"> + + <dimensions z="1*mm" y="10*cm" x="10*cm" /> + <position z="50*mm" y="0*cm" x="0*cm" /> + <module name="pixel" type="MiniTelPixel" material="Silicon" x="6*mm" y="6*mm" z="1*mm" vis="ModVis" alpha="-2.*radian" beta="-2.*radian" gamma="-0.*radian" /> + </detector> + + + <detector name="MyLHCBdetector7" type="MiniTelPixel" material="Silicon" vis="DetVis" id ="7" sensitive="true" readout="MyLHCBdetector7Hits"> + + <dimensions z="1*mm" y="10*cm" x="10*cm" /> + <position z="60*mm" y="0*cm" x="0*cm" /> + <module name="pixel" type="MiniTelPixel" material="Silicon" x="6*mm" y="6*mm" z="1*mm" vis="ModVis" alpha="-2.*radian" beta="-2.*radian" gamma="-0.*radian" /> + </detector> + + + <detector name="MyLHCBdetector8" type="MiniTelPixel" material="Silicon" vis="DetVis" id ="8" sensitive="true" readout="MyLHCBdetector8Hits"> + + <dimensions z="1*mm" y="10*cm" x="10*cm" /> + <position z="70*mm" y="0*cm" x="0*cm" /> + <module name="pixel" type="MiniTelPixel" material="Silicon" x="6*mm" y="6*mm" z="1*mm" vis="ModVis" alpha="-2.*radian" beta="-2.*radian" gamma="-0.*radian" /> + </detector> + + <detector name="MyLHCBdetector9" type="MiniTelPixel" material="Silicon" vis="DetVis" id ="9" sensitive="true" readout="MyLHCBdetector9Hits"> + + <dimensions z="1*mm" y="10*cm" x="10*cm" /> + <position z="80*mm" y="0*cm" x="0*cm" /> + <module name="pixel" type="MiniTelPixel" material="Silicon" x="6*mm" y="6*mm" z="1*mm" vis="ModVis" alpha="-2.*radian" beta="-2.*radian" gamma="-0.*radian" /> + </detector> + + <detector name="MyLHCBdetector10" type="MiniTelPixel" material="Silicon" vis="DetVis" id ="10" sensitive="true" readout="MyLHCBdetector10Hits"> + + <dimensions z="1*mm" y="10*cm" x="10*cm" /> + <position z="90*mm" y="0*cm" x="0*cm" /> + <module name="pixel" type="MiniTelPixel" material="Silicon" x="6*mm" y="6*mm" z="1*mm" vis="ModVis" alpha="-2.*radian" beta="-2.*radian" gamma="-0.*radian" /> + </detector> + + + </detectors> + + <readouts> + <readout name="MyLHCBdetector1Hits"> + <segmentation type="CartesianGridXY" grid_size_x="6*mm" grid_size_y="6*mm" /> + <id>system:6,x:32:-16,y:-16</id> + </readout> + <readout name="MyLHCBdetector2Hits"> + <segmentation type="CartesianGridXY" grid_size_x="6*mm" grid_size_y="6*mm" /> + <id>system:6,x:32:-16,y:-16</id> + </readout> + <readout name="MyLHCBdetector3Hits"> + <segmentation type="CartesianGridXY" grid_size_x="6*mm" grid_size_y="6*mm" /> + <id>system:6,x:32:-16,y:-16</id> + </readout> + <readout name="MyLHCBdetector4Hits"> + <segmentation type="CartesianGridXY" grid_size_x="6*mm" grid_size_y="6*mm" /> + <id>system:6,x:32:-16,y:-16</id> + </readout> + <readout name="MyLHCBdetector5Hits"> + <segmentation type="CartesianGridXY" grid_size_x="6*mm" grid_size_y="6*mm" /> + <id>system:6,x:32:-16,y:-16</id> + </readout> + <readout name="MyLHCBdetector6Hits"> + <segmentation type="CartesianGridXY" grid_size_x="6*mm" grid_size_y="6*mm" /> + <id>system:6,x:32:-16,y:-16</id> + </readout> + <readout name="MyLHCBdetector7Hits"> + <segmentation type="CartesianGridXY" grid_size_x="6*mm" grid_size_y="6*mm" /> + <id>system:6,x:32:-16,y:-16</id> + </readout> + <readout name="MyLHCBdetector8Hits"> + <segmentation type="CartesianGridXY" grid_size_x="6*mm" grid_size_y="6*mm" /> + <id>system:6,x:32:-16,y:-16</id> + </readout> + <readout name="MyLHCBdetector9Hits"> + <segmentation type="CartesianGridXY" grid_size_x="6*mm" grid_size_y="6*mm" /> + <id>system:6,x:32:-16,y:-16</id> + </readout> + <readout name="MyLHCBdetector10Hits"> + <segmentation type="CartesianGridXY" grid_size_x="6*mm" grid_size_y="6*mm" /> + <id>system:6,x:32:-16,y:-16</id> + </readout> + </readouts> + + <fields> + <field name="GlobalSolenoid" type="solenoid" + inner_field="0.0*tesla" + outer_field="0.0*tesla" + zmax="2*m" + outer_radius="2*m"> + </field> + </fields> + + </lccdd> diff --git a/examples/ClientTests/scripts/MiniTel.py b/examples/ClientTests/scripts/MiniTel.py new file mode 100644 index 0000000000000000000000000000000000000000..fcc39a7af6b19ae78ee512950f2aae1ccc9b9a2a --- /dev/null +++ b/examples/ClientTests/scripts/MiniTel.py @@ -0,0 +1,60 @@ +import os, time, DDG4 +from DDG4 import OutputLevel as Output +from SystemOfUnits import * +# +# +""" + + DD4hep example setup using the python configuration + + \author M.Frank + \version 1.0 + +""" +def run(): + kernel = DDG4.Kernel() + install_dir = os.environ['DD4hepINSTALL'] + example_dir = install_dir+'/examples/DDG4/examples'; + kernel.setOutputLevel('Geant4Converter',Output.DEBUG) + kernel.setOutputLevel('Gun',Output.INFO) + kernel.loadGeometry("file:"+install_dir+"/examples/ClientTests/compact/MiniTel.xml") + kernel.loadXML("file:"+example_dir+"/DDG4_field.xml") + + simple = DDG4.Simple(kernel) + simple.printDetectors() + simple.setupCshUI() + + # Configure I/O + evt_root = simple.setupROOTOutput('RootOutput','MiniTel_'+time.strftime('%Y-%m-%d_%H-%M'),mc_truth=False) + # Setup particle gun + simple.setupGun("Gun",particle='pi-',energy=100*GeV,multiplicity=1) + # Now the calorimeters + seq,act = simple.setupTracker('MyLHCBdetector1') + seq,act = simple.setupTracker('MyLHCBdetector2') + seq,act = simple.setupTracker('MyLHCBdetector3') + seq,act = simple.setupTracker('MyLHCBdetector4') + act.OutputLevel = 4 + seq,act = simple.setupTracker('MyLHCBdetector5') + seq,act = simple.setupTracker('MyLHCBdetector6') + seq,act = simple.setupTracker('MyLHCBdetector7') + seq,act = simple.setupTracker('MyLHCBdetector8') + seq,act = simple.setupTracker('MyLHCBdetector9') + + # And handle the simulation particles. + part = DDG4.GeneratorAction(kernel,"Geant4ParticleHandler/ParticleHandler") + kernel.generatorAction().adopt(part) + part.SaveProcesses = ['conv','Decay'] + part.MinimalKineticEnergy = 1*MeV + part.OutputLevel = 5 # generator_output_level + part.enableUI() + + # Now build the physics list: + phys = kernel.physicsList() + phys.extends = 'QGSP_BERT' + phys.enableUI() + phys.dump() + # and run + simple.execute() + +if __name__ == "__main__": + run() diff --git a/examples/ClientTests/src/MiniTel.cpp b/examples/ClientTests/src/MiniTel.cpp new file mode 100644 index 0000000000000000000000000000000000000000..563b9eabf8e8c2f9da33a64a9ee724e9a5ca2cf3 --- /dev/null +++ b/examples/ClientTests/src/MiniTel.cpp @@ -0,0 +1,117 @@ +// Include files +#include "DD4hep/DetFactoryHelper.h" +#include "DD4hep/Printout.h" +#include "DD4hep/LCDD.h" +//#include "DetDesc/MyDetExtension.h" + +#include <iostream> +#include <map> + +using namespace std; +using namespace DD4hep; +using namespace DD4hep::Geometry; + +namespace { + struct MyDetExtension { + int idD, Ni, Nj; + double posDX, posDY, posDZ; + double dimDX, dimDY, dimDZ; + double pixelX, pixelY, pixelZ; + DetElement detector; + + MyDetExtension(DetElement e) : detector(e) {} + MyDetExtension(const MyDetExtension& e, DetElement d) + : idD(e.idD), Ni(e.Ni), Nj(e.Nj), + posDX(e.posDX), posDY(e.posDY), posDZ(e.posDZ), + dimDX(e.dimDX), dimDY(e.dimDY), dimDZ(e.dimDZ), + pixelX(e.pixelX), pixelY(e.pixelY), pixelZ(e.pixelZ), + detector(d) + { + } + }; +} +typedef MyDetExtension DetectorExtension; + +static Ref_t create_detector(LCDD &lcdd, xml_h e, SensitiveDetector sens) { + xml_det_t x_det = e; //xml-detelemnt of the detector taken as an argument + string det_name = x_det.nameStr(); //det_name is the name of the xml-detelement + string det_type = x_det.typeStr(); //det_type is the type of the xml-detelement + Assembly assembly (det_name); + int detectors_id = x_det.id(); + + string visualisation = x_det.visStr(); + + + DetElement sdet(det_name,x_det.id()); //sdet is the detelement of the detector!!(actually is a Handle,already a pointer to m_element) + DetectorExtension* ext = new MyDetExtension(sdet); + sdet.addExtension<MyDetExtension>(ext); + ext->idD= detectors_id; + + + xml_coll_t mip(x_det, _U(position)); + xml_comp_t det_po = mip; + + double det_y = det_po.y(); // det_y is the y dimension of the xml-detelement + double det_x = det_po.x(); // det_x is the x dimension of the xml-detelement + double det_z = det_po.z(); // det_z is the z dimension of the xml-detelement + ext->posDY = det_y; + ext->posDX = det_x; + ext->posDZ = det_z; + + xml_coll_t dim(x_det, _U(dimensions)); + xml_comp_t det_dim = dim; + double dim_x = det_dim.x(); //det_x is the x dimension of the xml-detelement + double dim_y = det_dim.y(); //det_y is the y dimension of the xml-detelement + double dim_z = det_dim.z(); //det_z is the z dimension of the xml-detelement + + string det_vis = x_det.visStr(); + //Material air = lcdd.air(); //the material of the air of the lcdd detector + Material mat = lcdd.material("Silicon"); + + Volume motherVol = lcdd.pickMotherVolume(sdet); //the mothers volume of our detector + + //int mi_id = 0; //the id of the first pixel + PlacedVolume pv; //struct of Handle giving the volume id(ayto pou 8a kanw volume kai 8a to steilw me setplacement),dld o detector mou + + xml_coll_t mi(x_det, _U(module)); + xml_comp_t dtc_mod = mi; //considering the module-pixel of the detector + string mi_nam = dtc_mod.nameStr(); //the name of the module + + double pixelX = dtc_mod.x(); //The x dimension of the module + double pixelY = dtc_mod.y(); //The y dimension of the module + double pixelZ = dtc_mod.z(); //The z dimension of the module + + int Ni = dim_x/pixelX; //how many pixels in the x dimension + int Nj = dim_y/pixelY; + + ext->dimDX = dim_x; + ext->dimDY = dim_y; + ext->dimDZ = dim_z; + ext->pixelX = pixelX; + ext->pixelY = pixelY; + ext->pixelZ = pixelZ; + ext->Ni= Ni; + ext->Nj= Nj; + + + for (int i= 0; i<Ni; i++){ //lets start from 100 and when getting the x dimensions of the detector, use num_pixels + for (int j= 0; j<Nj; j++){ + //Position ppxl = Position(pixelX*i, pixelY*j, pixelZ); //The local position of its pixel + //mi_id = i+j +(Nj-1)*j ; //finding the id of the pixel according to its' position + //printout(INFO,det_name,"Giving to this pixel with position (%7.3f, %7.3f, %7.3f) id:%d",ppxl.x(),ppxl.y(),ppxl.z(),mi_id); + } + } + Volume m_volume(det_name, Box(dim_x, dim_y, dim_z), mat); //as parameters it needs name,solid,material + m_volume.setVisAttributes(lcdd.visAttributes(x_det.visStr())); //I DONT MIND ABOUT THIS! + pv = motherVol.placeVolume(m_volume,Transform3D(Position(det_x,det_y,det_z))); //det_x,det_y,det_z are the dimensions of the detector in space + + xml_comp_t dtctr = x_det; + if ( dtctr.isSensitive() ) { + sens.setType("tracker"); + pv.addPhysVolID("system",detectors_id); + m_volume.setSensitiveDetector(sens); + } + sdet.setPlacement(pv); + return sdet; +} +DECLARE_DETELEMENT(MiniTelPixel,create_detector)