33 fG4ModuleLabel(config.G4ModuleLabel()),
34 fHitLabel(config.DefaultHitModuleLabel()),
35 fMinHitEnergyFraction(config.MinHitEnergyFraction())
45 fHitLabel (pSet.get<
art::InputTag>(
"DefaultHitModuleLabel",
"hitfd")),
58 std::vector< const sim::IDE* > ideps;
62 for(
auto mapitr = tdcidemap.begin(); mapitr != tdcidemap.end(); mapitr++){
64 const std::vector<sim::IDE>& idevec = (*mapitr).second;
65 for(
size_t iv = 0; iv < idevec.size(); ++iv){
69 if( abs(idevec[iv].trackID) == id) ideps.push_back(&(idevec[iv]));
80 std::vector<const sim::IDE*> ide_Ps;
82 if (
fGeom->
View(sc->Channel()) != view)
continue;
85 for(
const auto & item : sc->TDCIDEMap()){
88 for(
const sim::IDE & ide : item.second){
89 if (abs(ide.
trackID) == id) ide_Ps.push_back(&ide);
103 if ( (*ilb)->Channel() == channel) {chan = *ilb;}
105 throw cet::exception(
"BackTracker") <<
"No sim::SimChannel corresponding " 106 <<
"to channel: " << channel <<
"\n";
113 std::vector< sim::TrackIDE > trackIDEs;
122 if(start_tdc<0) start_tdc = 0;
123 if(end_tdc<0) end_tdc = 0;
128 for(
size_t e = 0;
e < simides.size(); ++
e)
133 if(totalE < 1.
e-5) totalE = 1.;
137 for(
size_t e = 0;
e < simides.size(); ++
e){
144 info.
energy = simides[
e].energy;
146 trackIDEs.push_back(info);
162 std::vector< sim::TrackIDE > trackIDEs;
172 std::vector< int > retVec;
174 retVec.push_back( trackIDE.trackID );
182 std::vector<sim::TrackIDE> eveIDEs;
184 std::map<int, double> eveToEMap;
186 for (
const auto& trackIDE : trackIDEs){
188 totalE+=trackIDE.energy;
190 eveIDEs.reserve(eveToEMap.size());
191 for(
const auto& eveToE : eveToEMap){
193 eveTrackIDE_tmp.
trackID = eveToE.first;
194 eveTrackIDE_tmp.
energy = eveToE.second;
196 eveIDEs.push_back(eveTrackIDE_tmp);
208 std::vector< art::Ptr<recob::Hit>> hitList;
209 std::vector<sim::TrackIDE> trackIDE;
210 for(
auto itr = hitsIn.begin(); itr != hitsIn.end(); ++itr) {
214 for(
auto itr_trakIDE = trackIDE.begin(); itr_trakIDE != trackIDE.end(); ++itr_trakIDE) {
216 hitList.push_back( hit);
231 std::vector<std::pair<int, art::Ptr<recob::Hit>>> hitList;
232 std::vector<sim::TrackIDE> tids;
233 for(
auto itr = hitsIn.begin(); itr != hitsIn.end(); ++itr) {
237 for(
auto itid = tids.begin(); itid != tids.end(); ++itid) {
238 for(
auto itkid = tkIds.begin(); itkid != tkIds.end(); ++itkid) {
239 if(itid->trackID == *itkid) {
241 hitList.push_back(std::make_pair(*itkid, hit));
248 std::vector<std::vector<art::Ptr<recob::Hit>>> truHits;
250 std::vector<art::Ptr<recob::Hit>> tmpHits;
251 for(
auto itkid = tkIds.begin(); itkid != tkIds.end(); ++itkid) {
253 for(
auto itr = hitList.begin(); itr != hitList.end(); ++itr) {
254 if(*itkid == (*itr).first) tmpHits.push_back((*itr).second);
256 truHits.push_back(tmpHits);
268 if(start_tdc<0) start_tdc = 0;
269 if(end_tdc<0) end_tdc = 0;
276 std::vector< const sim::IDE* > retVec;
281 if(start_tdc<0) start_tdc = 0;
282 if(end_tdc<0) end_tdc = 0;
284 if(start_tdc > end_tdc){
throw;}
290 const std::vector< std::pair<unsigned short, std::vector<sim::IDE>> >& tdcIDEMap = (this->
FindSimChannel(hit.
Channel()))->TDCIDEMap();
291 std::vector<const std::pair<unsigned short, std::vector<sim::IDE>>*> tdcIDEMap_SortedPointers;
292 for (
auto& pair : tdcIDEMap ){
293 tdcIDEMap_SortedPointers.push_back(&pair);
307 auto pairSort = [](
auto& a,
auto& b) {
return a->first < b->first ; } ;
308 if( !std::is_sorted( tdcIDEMap_SortedPointers.begin(), tdcIDEMap_SortedPointers.end(), pairSort)) {
309 std::sort (tdcIDEMap_SortedPointers.begin(), tdcIDEMap_SortedPointers.end(), pairSort);
313 std::vector<sim::IDE> dummyVec;
314 std::pair<double, std::vector<sim::IDE>> start_tdcPair = std::make_pair(start_tdc,dummyVec);
315 std::pair<double, std::vector<sim::IDE>> end_tdcPair = std::make_pair(end_tdc,dummyVec);
317 auto start_tdcPair_P = &start_tdcPair;
318 auto end_tdcPair_P = &end_tdcPair;
320 mapFirst = std::lower_bound(tdcIDEMap_SortedPointers.begin(), tdcIDEMap_SortedPointers.end(), start_tdcPair_P, pairSort);
324 mapLast = std::upper_bound(tdcIDEMap_SortedPointers.begin(), tdcIDEMap_SortedPointers.end(), end_tdcPair_P, pairSort);
325 for(
auto& mapitr = mapFirst; mapitr != mapLast; ++mapitr ){
326 for(
auto& ide : (*mapitr)->second){
327 retVec.push_back(&ide);
340 std::vector<double> xyz(3,0.0);
342 for(
auto const& ide : ides){
343 double weight=ide.numElectrons;
345 xyz[0] += (weight*ide.x);
346 xyz[1] += (weight*ide.y);
347 xyz[2] += (weight*ide.z);
350 throw cet::exception(
"BackTracker")<<
"No sim::IDEs providing non-zero number of electrons" 351 <<
" can't determine originating location from truth\n";
360 std::vector<sim::IDE> ides;
361 for(
auto ide_P : ide_Ps ){ ides.push_back(*ide_P);}
377 for(
const auto& tIDE : hitTrackIDEs){
378 if(trackIds.find(tIDE.trackID)!=trackIds.end()){
384 if(hits.size()>0){
return double(
double(desired)/
double(hits.size()));}
390 double totalCharge=0.,desired=0.;
392 totalCharge+=
hit->Integral();
394 for(
const auto& trackIDE : trackIDEs){
395 if(trackIds.find(trackIDE.trackID)!=trackIds.end()){
396 desired+=
hit->Integral();
401 if(totalCharge>0.0){
return (desired/totalCharge);}
411 int desired=0,total=0;
415 for(
const auto& trackIDE : hitTrackIDEs){
416 if( trackIds.find(trackIDE.trackID)!=trackIds.end() && trackIDE.energyFrac >=
fMinHitEnergyFraction){
423 for(
const auto&
hit : allHits){
424 if(
hit->View()!=view && view !=
geo::k3D) {
continue;}
426 for(
const auto& hitIDE : hitTrackIDEs){
433 if(total >= 0){
return double(
double(desired)/
double(total));}
442 double desired=0.,total=0.;
445 for(
const auto& hitIDE : hitTrackIDEs){
447 desired+=
hit->Integral();
453 for(
const auto&
hit : allHits ){
454 if(
hit->View() != view && view !=
geo::k3D){
continue; }
456 for(
const auto& hitIDE : hitTrackIDEs ){
458 total +=
hit->Integral();
464 if(total>0.) {
return desired/total;}
474 const double start =
hit->PeakTimeMinusRMS();
475 const double end =
hit->PeakTimePlusRMS();
477 for(
const auto& ide : trackIDEs) {
478 tids.insert(ide.trackID);
486 std::set<int> eveIds;
489 for(
const auto& ide : ides){eveIds.insert(ide.trackID);}
497 std::vector<double> xyz(3,-99999.9);
498 std::vector< std::vector<std::vector<int>>> numHits (
fGeom->
Ncryostats());
499 std::vector< std::vector<std::vector<double>>> hitWeight (
fGeom->
Ncryostats());
500 std::vector< std::vector<std::vector<std::vector<double>>>> hitPos (
fGeom->
Ncryostats());
502 for(
size_t c = 0; c < numHits.size(); ++c){
506 for(
size_t t = 0; t < numHits[c].size(); ++t){
519 std::vector<double> hitOrigin = this->
HitToXYZ(*ihit);
520 unsigned int cstat = 0;
521 unsigned int tpc = 0;
522 const double worldLoc[3] = {hitOrigin[0], hitOrigin[1], hitOrigin[2]};
528 hitPos[cstat][tpc][hit.
WireID().
Plane] = hitOrigin;
539 for(
size_t c = 0; c < numHits.size(); ++c){
540 for(
size_t t = 0; t < numHits[c].size(); ++t){
541 for(
size_t p = 0; p < numHits[c][t].size(); ++p){
543 if(numHits[c][t][p] == 1) {
545 xyz[0] += hitPos[c][t][p][0];
546 xyz[1] += hitPos[c][t][p][1];
547 xyz[2] += hitPos[c][t][p][2];
556 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.
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 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)