15 #define DDG4_MAKE_INSTANTIATIONS
27 #include <IMPL/LCCollectionVec.h>
29 #include <IMPL/LCEventImpl.h>
30 #include <IMPL/ClusterImpl.h>
31 #include <IMPL/SimTrackerHitImpl.h>
32 #include <IMPL/SimCalorimeterHitImpl.h>
33 #include <IMPL/MCParticleImpl.h>
35 #include <UTIL/Operators.h>
36 #include <UTIL/ILDConf.h>
38 #include <CLHEP/Units/SystemOfUnits.h>
41 using namespace lcio ;
76 template <> lcio::LCCollectionVec*
77 Geant4DataConversion<lcio::LCCollectionVec,
78 pair<const Geant4Context*,G4VHitsCollection*>,
83 typedef pair<arg_t::first_type,Geant4HitCollection*> _A;
85 const _C& cnv= _C::converter(coll->
type().type());
86 return cnv(_A(args.first,coll));
89 "Cannot save the collection entries of:"+c->GetName());
102 template <> lcio::LCCollectionVec*
103 Geant4DataConversion<lcio::LCCollectionVec,
104 pair<const Geant4Context*,Geant4HitCollection*>,
108 string hc_nam = coll->GetName();
110 size_t nhits = coll->
GetSize();
113 lcio::LCEventImpl* lc_evt = args.first->event().extension<lcio::LCEventImpl>();
114 EVENT::LCCollection* lc_part = lc_evt->getCollection(lcio::LCIO::MCPARTICLE);
115 lcio::LCCollectionVec* lc_coll =
nullptr;
116 bool isNewCollection =
false;
118 lc_coll =
static_cast<lcio::LCCollectionVec*
>(lc_evt->getCollection(hc_nam));
119 }
catch (lcio::DataNotAvailableException &e) {
120 lc_coll =
new lcio::LCCollectionVec(lcio::LCIO::SIMTRACKERHIT);
121 isNewCollection =
true;
123 UTIL::CellIDEncoder<SimTrackerHit> decoder(dsc,lc_coll);
126 if ( hit_creation_mode == Geant4Sensitive::DETAILED_MODE )
127 lc_coll->setFlag(UTIL::make_bitset32(LCIO::THBIT_MOMENTUM,LCIO::THBIT_ID1));
129 lc_coll->setFlag(LCIO::THBIT_ID1);
131 lc_coll->reserve(nhits + lc_coll->getNumberOfElements());
132 for(
size_t i=0; i<nhits; ++i) {
133 const Geant4Tracker::Hit* hit = coll->
hit(i);
134 const Geant4Tracker::Hit::Contribution& t = hit->truth;
136 EVENT::MCParticle* lc_mcp = (EVENT::MCParticle*)lc_part->getElementAt(trackID);
137 double pos[3] = {hit->position.x()/CLHEP::mm, hit->position.y()/CLHEP::mm, hit->position.z()/CLHEP::mm};
138 lcio::SimTrackerHitImpl* lc_hit =
new lcio::SimTrackerHitImpl;
139 lc_hit->setCellID0((hit->cellID >> 0 ) & 0xFFFFFFFF);
140 lc_hit->setCellID1((hit->cellID >>
sizeof(
int)*8) & 0xFFFFFFFF);
141 lc_hit->setEDep(hit->energyDeposit/CLHEP::GeV);
142 lc_hit->setPathLength(hit->length/CLHEP::mm);
143 lc_hit->setTime(hit->truth.time/CLHEP::ns);
144 lc_hit->setMCParticle(lc_mcp);
145 lc_hit->setPosition(pos);
146 lc_hit->setMomentum(hit->momentum.x()/CLHEP::GeV,hit->momentum.y()/CLHEP::GeV,hit->momentum.z()/CLHEP::GeV);
148 #if LCIO_VERSION_GE( 2, 8 )
149 auto particleIt = pm->
particles().find(trackID);
150 if( ( particleIt != pm->
particles().end()) ){
154 lc_hit->setProducedBySecondary( (particleIt->second->originalG4ID != t.trackID) );
157 lc_coll->addElement(lc_hit);
160 if(isNewCollection) {
161 lc_evt->addCollection(lc_coll, hc_nam);
176 template <> lcio::LCCollectionVec*
177 Geant4DataConversion<lcio::LCCollectionVec,
178 pair<const Geant4Context*,Geant4HitCollection*>,
179 Geant4Calorimeter::Hit>::operator()(
const arg_t& args)
const {
180 typedef Geant4HitData::Contributions Contributions;
181 Geant4HitCollection* coll = args.second;
182 string hc_nam = coll->GetName();
183 Geant4Sensitive* sd = coll->sensitive();
184 size_t nhits = coll->GetSize();
185 string dsc = encoding(sd->sensitiveDetector());
186 Geant4ParticleMap* pm = args.first->event().extension<Geant4ParticleMap>();
187 lcio::LCEventImpl* lc_evt = args.first->event().extension<lcio::LCEventImpl>();
188 EVENT::LCCollection* lc_parts = lc_evt->getCollection(lcio::LCIO::MCPARTICLE);
189 lcio::LCCollectionVec* lc_coll =
nullptr;
190 bool isNewCollection =
false;
192 lc_coll =
static_cast<lcio::LCCollectionVec*
>(lc_evt->getCollection(hc_nam));
193 }
catch (lcio::DataNotAvailableException &e) {
194 lc_coll =
new lcio::LCCollectionVec(lcio::LCIO::SIMCALORIMETERHIT);
195 isNewCollection =
true;
197 UTIL::CellIDEncoder<SimCalorimeterHit> decoder(dsc,lc_coll);
198 int hit_creation_mode = sd->hitCreationMode();
200 if ( hit_creation_mode == Geant4Sensitive::DETAILED_MODE )
201 lc_coll->setFlag(UTIL::make_bitset32(LCIO::CHBIT_LONG,LCIO::CHBIT_STEP,LCIO::CHBIT_ID1));
203 lc_coll->setFlag(UTIL::make_bitset32(LCIO::CHBIT_LONG,LCIO::CHBIT_ID1));
205 lc_coll->reserve(nhits + lc_coll->getNumberOfElements());
206 if ( sd->hasProperty(
"HitCreationMode") ) {
207 hit_creation_mode = sd->property(
"HitCreationMode").value<
int>();
209 for(
size_t i=0; i<nhits; ++i) {
210 const Geant4Calorimeter::Hit* hit = coll->hit(i);
211 float pos[3] = {float(hit->position.x()/CLHEP::mm), float(hit->position.y()/CLHEP::mm), float(hit->position.z()/CLHEP::mm)};
212 lcio::SimCalorimeterHitImpl* lc_hit =
new lcio::SimCalorimeterHitImpl;
213 lc_hit->setCellID0((hit->cellID >> 0 ) & 0xFFFFFFFF);
214 lc_hit->setCellID1((hit->cellID >>
sizeof(
int)*8) & 0xFFFFFFFF);
215 lc_hit->setPosition(pos);
217 lc_coll->addElement(lc_hit);
219 for(Contributions::const_iterator j=hit->truth.begin(); j!=hit->truth.end(); ++j) {
220 const Geant4HitData::Contribution& c = *j;
221 int trackID = pm->particleID(c.trackID);
222 EVENT::MCParticle* lc_mcp = (EVENT::MCParticle*)lc_parts->getElementAt(trackID);
223 if ( hit_creation_mode == Geant4Sensitive::DETAILED_MODE ) {
224 float contrib_pos[] = {float(c.x/CLHEP::mm), float(c.y/CLHEP::mm), float(c.z/CLHEP::mm)};
225 #if LCIO_VERSION_GE( 2, 11 )
226 lc_hit->addMCParticleContribution(lc_mcp, c.deposit/CLHEP::GeV, c.time/CLHEP::ns, c.length/CLHEP::mm, c.pdgID, contrib_pos);
228 lc_hit->addMCParticleContribution(lc_mcp, c.deposit/CLHEP::GeV, c.time/CLHEP::ns, c.pdgID, contrib_pos);
232 lc_hit->addMCParticleContribution(lc_mcp, c.deposit/CLHEP::GeV, c.time/CLHEP::ns);
236 if(isNewCollection) {
237 lc_evt->addCollection(lc_coll, hc_nam);
242 template <
typename T>
244 lcio::LCCollectionVec* lc_coll)
246 size_t nhits = coll->
GetSize();
247 lc_coll->reserve(nhits);
248 for(
size_t i=0; i<nhits; ++i) {
252 lc_coll->addElement(lc_hit);
271 template <> lcio::LCCollectionVec*
272 Geant4DataConversion<lcio::LCCollectionVec,
273 pair<const Geant4Context*,Geant4HitCollection*>,
274 lcio::SimTrackerHitImpl>::operator()(
const arg_t& args)
const
278 output_t* lc =
new lcio::LCCollectionVec(lcio::LCIO::SIMTRACKERHIT);
281 if ( hit_creation_mode == Geant4Sensitive::DETAILED_MODE )
282 lc->setFlag(UTIL::make_bitset32(LCIO::CHBIT_LONG,LCIO::CHBIT_STEP,LCIO::CHBIT_ID1));
284 lc->setFlag(UTIL::make_bitset32(LCIO::CHBIT_LONG,LCIO::CHBIT_ID1));
285 UTIL::CellIDEncoder<SimTrackerHit> decoder(dsc,lc);
286 return moveEntries<lcio::SimTrackerHitImpl>(args.second,lc);
302 template <> lcio::LCCollectionVec*
303 Geant4DataConversion<lcio::LCCollectionVec,
304 pair<const Geant4Context*,Geant4HitCollection*>,
305 lcio::SimCalorimeterHitImpl>::operator()(
const arg_t& args)
const
307 Geant4Sensitive* sd = args.second->sensitive();
309 output_t* lc =
new lcio::LCCollectionVec(lcio::LCIO::SIMCALORIMETERHIT);
310 int hit_creation_mode = sd->hitCreationMode();
312 if ( hit_creation_mode == Geant4Sensitive::DETAILED_MODE )
313 lc->setFlag(UTIL::make_bitset32(LCIO::CHBIT_LONG,LCIO::CHBIT_STEP,LCIO::CHBIT_ID1));
315 lc->setFlag(UTIL::make_bitset32(LCIO::CHBIT_LONG,LCIO::CHBIT_ID1));
316 return moveEntries<tag_t>(args.second,lc);
325 template <> lcio::LCCollectionVec*
326 Geant4DataConversion<lcio::LCCollectionVec,
327 pair<const Geant4Context*,Geant4HitCollection*>,
328 lcio::ClusterImpl>::operator()(
const arg_t& args)
const
330 output_t* lc =
new lcio::LCCollectionVec(lcio::LCIO::CLUSTER);
331 return moveEntries<tag_t>(args.second,lc);
344 DECLARE_GEANT4_HITCONVERTER(lcio::LCCollectionVec,
CONVERSION_ARGS,lcio::SimTrackerHitImpl)
345 DECLARE_GEANT4_HITCONVERTER(lcio::LCCollectionVec,
CONVERSION_ARGS,lcio::SimCalorimeterHitImpl)
346 DECLARE_GEANT4_HITCONVERTER(lcio::LCCollectionVec,
CONVERSION_ARGS,lcio::ClusterImpl)