33 fG4ModuleLabel(config.G4ModuleLabel()),
34 fHitLabel(config.DefaultHitModuleLabel()),
35 fMinHitEnergyFraction(config.MinHitEnergyFraction()),
36 fOverrideRealData(config.OverrideRealData())
46 fHitLabel (pSet.get<
art::InputTag>(
"DefaultHitModuleLabel",
"hitfd")),
60 std::vector< const sim::IDE* > ideps;
64 for(
auto mapitr = tdcidemap.begin(); mapitr != tdcidemap.end(); mapitr++){
66 const std::vector<sim::IDE>& idevec = (*mapitr).second;
67 for(
size_t iv = 0; iv < idevec.size(); ++iv){
71 if( abs(idevec[iv].trackID) == id) ideps.push_back(&(idevec[iv]));
82 std::vector<const sim::IDE*> ide_Ps;
84 if (
fGeom->
View(sc->Channel()) != view)
continue;
87 for(
const auto & item : sc->TDCIDEMap()){
90 for(
const sim::IDE & ide : item.second){
91 if (abs(ide.
trackID) == id) ide_Ps.push_back(&ide);
105 if ( (*ilb)->Channel() == channel) {chan = *ilb;}
107 throw cet::exception(
"BackTracker") <<
"No sim::SimChannel corresponding " 108 <<
"to channel: " << channel <<
"\n";
115 std::vector< sim::TrackIDE > trackIDEs;
124 if(start_tdc<0) start_tdc = 0;
125 if(end_tdc<0) end_tdc = 0;
130 for(
size_t e = 0;
e < simides.size(); ++
e)
135 if(totalE < 1.
e-5) totalE = 1.;
139 for(
size_t e = 0;
e < simides.size(); ++
e){
146 info.
energy = simides[
e].energy;
149 trackIDEs.push_back(info);
165 std::vector< sim::TrackIDE > trackIDEs;
175 std::vector< int > retVec;
177 retVec.push_back( trackIDE.trackID );
186 std::vector<sim::TrackIDE> eveIDEs;
188 std::map<int, std::pair<double,double>> eveToEMap;
190 for (
const auto& trackIDE : trackIDEs){
191 auto check = eveToEMap.emplace(
193 std::make_pair(trackIDE.energy,trackIDE.numElectrons));
194 if(check.second==
false)
196 check.first->second.first +=trackIDE.energy;
197 check.first->second.second +=trackIDE.numElectrons;
201 totalE+=trackIDE.energy;
203 eveIDEs.reserve(eveToEMap.size());
204 for(
const auto& eveToE : eveToEMap){
207 eveTrackIDE_tmp.
trackID = eveToE.first;
208 eveTrackIDE_tmp.
energy = eveToE.second.first;
212 eveIDEs.push_back(eveTrackIDE_tmp);
224 std::vector< art::Ptr<recob::Hit>> hitList;
225 std::vector<sim::TrackIDE> trackIDE;
226 for(
auto itr = hitsIn.begin(); itr != hitsIn.end(); ++itr) {
230 for(
auto itr_trakIDE = trackIDE.begin(); itr_trakIDE != trackIDE.end(); ++itr_trakIDE) {
232 hitList.push_back( hit);
247 std::vector<std::pair<int, art::Ptr<recob::Hit>>> hitList;
248 std::vector<sim::TrackIDE> tids;
249 for(
auto itr = hitsIn.begin(); itr != hitsIn.end(); ++itr) {
253 for(
auto itid = tids.begin(); itid != tids.end(); ++itid) {
254 for(
auto itkid = tkIds.begin(); itkid != tkIds.end(); ++itkid) {
255 if(itid->trackID == *itkid) {
257 hitList.push_back(std::make_pair(*itkid, hit));
264 std::vector<std::vector<art::Ptr<recob::Hit>>> truHits;
266 std::vector<art::Ptr<recob::Hit>> tmpHits;
267 for(
auto itkid = tkIds.begin(); itkid != tkIds.end(); ++itkid) {
269 for(
auto itr = hitList.begin(); itr != hitList.end(); ++itr) {
270 if(*itkid == (*itr).first) tmpHits.push_back((*itr).second);
272 truHits.push_back(tmpHits);
284 if(start_tdc<0) start_tdc = 0;
285 if(end_tdc<0) end_tdc = 0;
292 std::vector< const sim::IDE* > retVec;
297 if(start_tdc<0) start_tdc = 0;
298 if(end_tdc<0) end_tdc = 0;
300 if(start_tdc > end_tdc){
throw;}
306 const std::vector< std::pair<unsigned short, std::vector<sim::IDE>> >& tdcIDEMap = (this->
FindSimChannel(hit.
Channel()))->TDCIDEMap();
307 std::vector<const std::pair<unsigned short, std::vector<sim::IDE>>*> tdcIDEMap_SortedPointers;
308 for (
auto& pair : tdcIDEMap ){
309 tdcIDEMap_SortedPointers.push_back(&pair);
323 auto pairSort = [](
auto& a,
auto& b) {
return a->first < b->first ; } ;
324 if( !std::is_sorted( tdcIDEMap_SortedPointers.begin(), tdcIDEMap_SortedPointers.end(), pairSort)) {
325 std::sort (tdcIDEMap_SortedPointers.begin(), tdcIDEMap_SortedPointers.end(), pairSort);
329 std::vector<sim::IDE> dummyVec;
330 std::pair<double, std::vector<sim::IDE>> start_tdcPair = std::make_pair(start_tdc,dummyVec);
331 std::pair<double, std::vector<sim::IDE>> end_tdcPair = std::make_pair(end_tdc,dummyVec);
333 auto start_tdcPair_P = &start_tdcPair;
334 auto end_tdcPair_P = &end_tdcPair;
336 mapFirst = std::lower_bound(tdcIDEMap_SortedPointers.begin(), tdcIDEMap_SortedPointers.end(), start_tdcPair_P, pairSort);
340 mapLast = std::upper_bound(tdcIDEMap_SortedPointers.begin(), tdcIDEMap_SortedPointers.end(), end_tdcPair_P, pairSort);
341 for(
auto& mapitr = mapFirst; mapitr != mapLast; ++mapitr ){
342 for(
auto& ide : (*mapitr)->second){
343 retVec.push_back(&ide);
356 std::vector<double> xyz(3,0.0);
358 for(
auto const& ide : ides){
359 double weight=ide.numElectrons;
361 xyz[0] += (weight*ide.x);
362 xyz[1] += (weight*ide.y);
363 xyz[2] += (weight*ide.z);
366 throw cet::exception(
"BackTracker")<<
"No sim::IDEs providing non-zero number of electrons" 367 <<
" can't determine originating location from truth\n";
376 std::vector<sim::IDE> ides;
377 for(
auto ide_P : ide_Ps ){ ides.push_back(*ide_P);}
393 for(
const auto& tIDE : hitTrackIDEs){
394 if(trackIds.find(tIDE.trackID)!=trackIds.end()){
400 if(hits.size()>0){
return double(
double(desired)/
double(hits.size()));}
406 double totalCharge=0.,desired=0.;
408 totalCharge+=
hit->Integral();
410 for(
const auto& trackIDE : trackIDEs){
411 if(trackIds.find(trackIDE.trackID)!=trackIds.end()){
412 desired+=
hit->Integral();
417 if(totalCharge>0.0){
return (desired/totalCharge);}
427 int desired=0,total=0;
431 for(
const auto& trackIDE : hitTrackIDEs){
432 if( trackIds.find(trackIDE.trackID)!=trackIds.end() && trackIDE.energyFrac >=
fMinHitEnergyFraction){
439 for(
const auto&
hit : allHits){
440 if(
hit->View()!=view && view !=
geo::k3D) {
continue;}
442 for(
const auto& hitIDE : hitTrackIDEs){
449 if(total >= 0){
return double(
double(desired)/
double(total));}
458 double desired=0.,total=0.;
461 for(
const auto& hitIDE : hitTrackIDEs){
463 desired+=
hit->Integral();
469 for(
const auto&
hit : allHits ){
470 if(
hit->View() != view && view !=
geo::k3D){
continue; }
472 for(
const auto& hitIDE : hitTrackIDEs ){
474 total +=
hit->Integral();
480 if(total>0.) {
return desired/total;}
490 const double start =
hit->PeakTimeMinusRMS();
491 const double end =
hit->PeakTimePlusRMS();
493 for(
const auto& ide : trackIDEs) {
494 tids.insert(ide.trackID);
502 std::set<int> eveIds;
505 for(
const auto& ide : ides){eveIds.insert(ide.trackID);}
513 std::vector<double> xyz(3,-99999.9);
514 std::vector< std::vector<std::vector<int>>> numHits (
fGeom->
Ncryostats());
515 std::vector< std::vector<std::vector<double>>> hitWeight (
fGeom->
Ncryostats());
516 std::vector< std::vector<std::vector<std::vector<double>>>> hitPos (
fGeom->
Ncryostats());
518 for(
size_t c = 0; c < numHits.size(); ++c){
522 for(
size_t t = 0; t < numHits[c].size(); ++t){
535 std::vector<double> hitOrigin = this->
HitToXYZ(*ihit);
536 unsigned int cstat = 0;
537 unsigned int tpc = 0;
538 const double worldLoc[3] = {hitOrigin[0], hitOrigin[1], hitOrigin[2]};
544 hitPos[cstat][tpc][hit.
WireID().
Plane] = hitOrigin;
555 for(
size_t c = 0; c < numHits.size(); ++c){
556 for(
size_t t = 0; t < numHits[c].size(); ++t){
557 for(
size_t p = 0; p < numHits[c][t].size(); ++p){
559 if(numHits[c][t][p] == 1) {
561 xyz[0] += hitPos[c][t][p][0];
562 xyz[1] += hitPos[c][t][p][1];
563 xyz[2] += hitPos[c][t][p][2];
572 throw cet::exception(
"BackTracker") <<
"No hits to determine originating location from truth\n";
TrackID_t trackID
Geant4 supplied track ID.
const art::InputTag fHitLabel
const std::vector< double > SpacePointHitsToWeightedXYZ(std::vector< art::Ptr< recob::Hit >> const &hits) const
Utilities related to art service access.
const geo::GeometryCore * fGeom
std::vector< art::Ptr< sim::SimChannel > > fSimChannels
enum geo::_plane_proj View_t
Enumerate the possible plane projections.
const detinfo::DetectorClocks * fDetClocks
geo::WireID WireID() const
Initial tdc tick for hit.
float numElectrons
number of electrons from the particle detected on the wires
const std::set< int > GetSetOfEveIds() const
const std::vector< sim::TrackIDE > ChannelToTrackIDEs(raw::ChannelID_t channel, const double hit_start_time, const double hit_end_time) const
const double fMinHitEnergyFraction
CryostatID_t Cryostat
Index of cryostat.
float Integral() const
Integral under the calibrated signal waveform of the hit, in tick x ADC units.
float energy
energy from the particle with this trackID [MeV]
unsigned int Ncryostats() const
Returns the number of cryostats in the detector.
const std::vector< sim::TrackIDE > HitToTrackIDEs(recob::Hit const &hit) const
const double HitCollectionEfficiency(std::set< int > const &trackIds, std::vector< art::Ptr< recob::Hit > > const &hits, std::vector< art::Ptr< recob::Hit > > const &allhits, geo::View_t const &view) const
geo::TPCGeo const & PositionToTPC(geo::Point_t const &point) const
Returns the TPC at specified location.
3-dimensional objects, potentially hits, clusters, prongs, etc.
const std::vector< int > HitToTrackIds(recob::Hit const &hit) const
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Access the description of detector geometry.
const std::vector< const sim::IDE * > TrackIdToSimIDEs_Ps(int const &id) const
unsigned int Nplanes(unsigned int tpc=0, unsigned int cstat=0) const
Returns the total number of wire planes in the specified TPC.
Ionization at a point of the TPC sensitive volume.
static const int NoParticleId
art::Ptr< sim::SimChannel > FindSimChannel(raw::ChannelID_t channel) const
const std::vector< double > HitToXYZ(const recob::Hit &hit) const
float energyFrac
fraction of hit energy from the particle with this trackID
std::vector< std::vector< art::Ptr< recob::Hit > > > TrackIdsToHits_Ps(std::vector< int > const &tkIds, std::vector< art::Ptr< recob::Hit > > const &hitsIn) const
const double HitChargeCollectionPurity(std::set< int > const &trackIds, std::vector< art::Ptr< recob::Hit > > const &hits) const
const cheat::ParticleInventory * fPartInv
const std::vector< const sim::IDE * > HitToSimIDEs_Ps(recob::Hit const &hit) const
const std::vector< sim::TrackIDE > HitToEveTrackIDEs(recob::Hit const &hit) const
PlaneID_t Plane
Index of the plane within its TPC.
Description of geometry of one entire detector.
View_t View(geo::PlaneID const &pid) const
Returns the view (wire orientation) on the channels of specified TPC plane.
Definition of data types for geometry description.
float PeakTimeMinusRMS(float sigmas=+1.) const
Returns a time sigmas RMS away from the peak time.
Detector simulation of raw signals on wires.
Conversion of times between different formats and references.
Encapsulate the geometry of a wire.
unsigned int NTPC(unsigned int cstat=0) const
Returns the total number of TPCs in the specified cryostat.
data_t::const_iterator const_iterator
code to link reconstructed objects back to the MC truth information
int trackID
Geant4 supplied trackID.
virtual double TPCTick2TDC(double tick) const =0
Converts a TPC time tick into a electronics time tick.
const double HitChargeCollectionEfficiency(std::set< int > trackIds, std::vector< art::Ptr< recob::Hit > > const &hits, std::vector< art::Ptr< recob::Hit > > const &allhits, geo::View_t const &view) const
const bool fOverrideRealData
const std::set< int > GetSetOfTrackIds() const
std::vector< sim::IDE > TrackIDsAndEnergies(TDC_t startTDC, TDC_t endTDC) const
Return all the recorded energy deposition within a time interval.
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
const std::vector< sim::IDE > HitToAvgSimIDEs(recob::Hit const &hit) const
const art::InputTag fG4ModuleLabel
const std::vector< double > SimIDEsToXYZ(std::vector< sim::IDE > const &ides) const
std::vector< evd::details::RawDigitInfo_t >::const_iterator end(RawDigitCacheDataClass const &cache)
2D representation of charge deposited in the TDC/wire plane
float PeakTimePlusRMS(float sigmas=+1.) const
Returns a time sigmas RMS away from the peak time.
unsigned int ChannelID_t
Type representing the ID of a readout channel.
TPCID_t TPC
Index of the TPC within its cryostat.
int TrackIdToEveTrackId(const int &tid) const
std::vector< art::Ptr< recob::Hit > > TrackIdToHits_Ps(const int &tkId, std::vector< art::Ptr< recob::Hit > > const &hitsIn) const
Ionization energy from a Geant4 track.
raw::ChannelID_t Channel() const
ID of the readout channel the hit was extracted from.
Tools and modules for checking out the basics of the Monte Carlo.
const double HitCollectionPurity(std::set< int > const &trackIds, std::vector< art::Ptr< recob::Hit > > const &hits) const
art framework interface to geometry description
cet::coded_exception< error, detail::translate > exception
Encapsulate the construction of a single detector plane.
BackTracker(const fhiclConfig &config, const cheat::ParticleInventory *partInv, const geo::GeometryCore *geom, const detinfo::DetectorClocks *detClock)