Public Member Functions | Private Member Functions | Private Attributes | List of all members
trkf::TrackCheater Class Reference
Inheritance diagram for trkf::TrackCheater:
art::EDProducer art::detail::Producer art::detail::LegacyModule art::Modifier art::ModuleBase art::ProductRegistryHelper

Public Member Functions

 TrackCheater (fhicl::ParameterSet const &pset)
 
- Public Member Functions inherited from art::EDProducer
 EDProducer (fhicl::ParameterSet const &pset)
 
template<typename Config >
 EDProducer (Table< Config > const &config)
 
std::string workerType () const
 
- Public Member Functions inherited from art::detail::Producer
virtual ~Producer () noexcept
 
 Producer (fhicl::ParameterSet const &)
 
 Producer (Producer const &)=delete
 
 Producer (Producer &&)=delete
 
Produceroperator= (Producer const &)=delete
 
Produceroperator= (Producer &&)=delete
 
void doBeginJob (SharedResources const &resources)
 
void doEndJob ()
 
void doRespondToOpenInputFile (FileBlock const &fb)
 
void doRespondToCloseInputFile (FileBlock const &fb)
 
void doRespondToOpenOutputFiles (FileBlock const &fb)
 
void doRespondToCloseOutputFiles (FileBlock const &fb)
 
bool doBeginRun (RunPrincipal &rp, ModuleContext const &mc)
 
bool doEndRun (RunPrincipal &rp, ModuleContext const &mc)
 
bool doBeginSubRun (SubRunPrincipal &srp, ModuleContext const &mc)
 
bool doEndSubRun (SubRunPrincipal &srp, ModuleContext const &mc)
 
bool doEvent (EventPrincipal &ep, ModuleContext const &mc, std::atomic< std::size_t > &counts_run, std::atomic< std::size_t > &counts_passed, std::atomic< std::size_t > &counts_failed)
 
- Public Member Functions inherited from art::Modifier
 ~Modifier () noexcept
 
 Modifier ()
 
 Modifier (Modifier const &)=delete
 
 Modifier (Modifier &&)=delete
 
Modifieroperator= (Modifier const &)=delete
 
Modifieroperator= (Modifier &&)=delete
 
- Public Member Functions inherited from art::ModuleBase
virtual ~ModuleBase () noexcept
 
 ModuleBase ()
 
ModuleDescription const & moduleDescription () const
 
void setModuleDescription (ModuleDescription const &)
 
std::array< std::vector< ProductInfo >, NumBranchTypes > const & getConsumables () const
 
void sortConsumables (std::string const &current_process_name)
 
template<typename T , BranchType BT>
ViewToken< T > consumesView (InputTag const &tag)
 
template<typename T , BranchType BT>
ViewToken< T > mayConsumeView (InputTag const &tag)
 

Private Member Functions

void produce (art::Event &evt) override
 

Private Attributes

std::string const fCheatedClusterLabel
 
std::string const fG4ModuleLabel
 label for module running G4 and making particles, etc More...
 

Additional Inherited Members

- Public Types inherited from art::EDProducer
using ModuleType = EDProducer
 
using WorkerType = WorkerT< EDProducer >
 
- Public Types inherited from art::detail::Producer
template<typename UserConfig , typename KeysToIgnore = void>
using Table = Modifier::Table< UserConfig, KeysToIgnore >
 
- Public Types inherited from art::Modifier
template<typename UserConfig , typename UserKeysToIgnore = void>
using Table = ProducerTable< UserConfig, detail::ModuleConfig, UserKeysToIgnore >
 
- Static Public Member Functions inherited from art::EDProducer
static void commitEvent (EventPrincipal &ep, Event &e)
 
- Protected Member Functions inherited from art::ModuleBase
ConsumesCollectorconsumesCollector ()
 
template<typename T , BranchType = InEvent>
ProductToken< T > consumes (InputTag const &)
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > consumesView (InputTag const &)
 
template<typename T , BranchType = InEvent>
void consumesMany ()
 
template<typename T , BranchType = InEvent>
ProductToken< T > mayConsume (InputTag const &)
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > mayConsumeView (InputTag const &)
 
template<typename T , BranchType = InEvent>
void mayConsumeMany ()
 

Detailed Description

Definition at line 38 of file TrackCheater_module.cc.

Constructor & Destructor Documentation

trkf::TrackCheater::TrackCheater ( fhicl::ParameterSet const &  pset)
explicit

Definition at line 54 of file TrackCheater_module.cc.

55  : EDProducer{pset}
56  , fCheatedClusterLabel{pset.get<std::string>("CheatedClusterLabel", "cluster")}
57  , fG4ModuleLabel{pset.get<std::string>("G4ModuleLabel", "largeant")}
58  {
59  produces<std::vector<recob::Track>>();
60  produces<std::vector<recob::SpacePoint>>();
61  produces<art::Assns<recob::Track, recob::Cluster>>();
62  produces<art::Assns<recob::Track, recob::SpacePoint>>();
63  produces<art::Assns<recob::Track, recob::Hit>>();
64  }
std::string const fCheatedClusterLabel
std::string string
Definition: nybbler.cc:12
EDProducer(fhicl::ParameterSet const &pset)
Definition: EDProducer.h:20
std::string const fG4ModuleLabel
label for module running G4 and making particles, etc

Member Function Documentation

void trkf::TrackCheater::produce ( art::Event evt)
overrideprivatevirtual

Implements art::EDProducer.

Definition at line 68 of file TrackCheater_module.cc.

69  {
73 
74  // grab the clusters that have been reconstructed
76  evt.getByLabel(fCheatedClusterLabel, clustercol);
77 
78  art::FindManyP<recob::Hit> fmh(clustercol, evt, fCheatedClusterLabel);
79 
80  // make a vector of them - we aren't writing anything out to a file
81  // so no need for a art::PtrVector here
82  std::vector<art::Ptr<recob::Cluster>> clusters;
83  art::fill_ptr_vector(clusters, clustercol);
84 
85  // loop over the clusters and figure out which particle contributed to each one
86  std::vector<art::Ptr<recob::Cluster>>::iterator itr = clusters.begin();
87 
88  // make a map of vectors of art::Ptrs keyed by eveID values
89  std::map<int, std::vector<std::pair<size_t, art::Ptr<recob::Cluster>>>> eveClusterMap;
90 
91  // loop over all clusters and fill in the map
92  for (size_t c = 0; c < clusters.size(); ++c) {
93 
94  std::pair<size_t, art::Ptr<recob::Cluster>> idxPtr(c, clusters[c]);
95 
96  // in the ClusterCheater module we set the cluster ID to be
97  // the eve particle track ID*1000 + plane*100 + tpc*10 + cryostat number. The
98  // floor function on the cluster ID / 1000 will give us
99  // the eve track ID
100  int eveID = floor((*itr)->ID() / 1000.);
101 
102  eveClusterMap[eveID].push_back(idxPtr);
103  ++itr;
104  } // end loop over clusters
105 
106  // loop over the map and make prongs
107  std::unique_ptr<std::vector<recob::Track>> trackcol(new std::vector<recob::Track>);
108  std::unique_ptr<std::vector<recob::SpacePoint>> spcol(new std::vector<recob::SpacePoint>);
109  std::unique_ptr<art::Assns<recob::Track, recob::SpacePoint>> tspassn(
111  std::unique_ptr<art::Assns<recob::Track, recob::Cluster>> tcassn(
113  std::unique_ptr<art::Assns<recob::Track, recob::Hit>> thassn(
115 
116  auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(evt);
117 
118  for (auto const& clusterMapItr : eveClusterMap) {
119 
120  // separate out the hits for each particle into the different views
121  std::vector<std::pair<size_t, art::Ptr<recob::Cluster>>> const& eveClusters =
122  clusterMapItr.second;
123 
124  simb::MCParticle* part = pi_serv->ParticleList()[clusterMapItr.first];
125 
126  // is this prong electro-magnetic in nature or
127  // hadronic/muonic? EM --> shower, everything else is a track
128  if (abs(part->PdgCode()) != 11 && abs(part->PdgCode()) != 22 && abs(part->PdgCode()) != 111) {
129 
130  // vectors to hold the positions and directions of the track
131  std::vector<TVector3> points;
132  std::vector<TVector3> moms;
133 
134  mf::LogInfo("TrackCheater")
135  << "G4 id " << clusterMapItr.first << " is a track with pdg code " << part->PdgCode();
136 
138  std::vector<size_t> idxs;
139  for (auto const& idxPtr : eveClusters) {
140  ptrvs.push_back(idxPtr.second);
141  idxs.push_back(idxPtr.first);
142  }
143 
144  // grab the hits associated with the collection plane
145  std::vector<art::Ptr<recob::Hit>> hits;
146  for (size_t p = 0; p < ptrvs.size(); ++p) {
147  std::vector<art::Ptr<recob::Hit>> chits = fmh.at(idxs[p]);
148  if (!chits.size()) continue;
149  if (chits[0]->SignalType() != geo::kCollection) continue;
150  hits.insert(hits.end(), chits.begin(), chits.end());
151  }
152 
153  // need at least 2 hits to make a track
154  if (hits.size() < 2) continue;
155 
156  // loop over the hits to get the positions and directions
157  size_t spStart = spcol->size();
158  for (size_t t = 0; t < hits.size(); ++t) {
159  std::vector<double> xyz = bt_serv->HitToXYZ(clockData, hits[t]);
160  TVector3 point(xyz[0], xyz[1], xyz[2]);
161  points.push_back(point);
162 
163  std::vector<double> xyz1;
164  double dx = 0.;
165  double sign = 1.;
166 
167  if (t < hits.size() - 1) { xyz1 = bt_serv->HitToXYZ(clockData, hits[t + 1]); }
168  else {
169  xyz1 = bt_serv->HitToXYZ(clockData, hits[t - 1]);
170  sign = -1.;
171  }
172 
173  // dx is always positive
174  dx = std::sqrt(std::pow(xyz1[0] - xyz[0], 2) + std::pow(xyz1[1] - xyz[1], 2) +
175  std::pow(xyz1[2] - xyz[2], 2));
176 
177  // figure out momentum
178  double mom = 0;
179  double drmin = std::numeric_limits<double>::max();
180  for (unsigned int itp = 0; itp < part->NumberTrajectoryPoints(); itp++) {
181  TVector3 p(part->Vx(itp), part->Vy(itp), part->Vz(itp));
182  double dr = (p - point).Mag();
183  if (dr < drmin) {
184  mom = part->P(itp);
185  drmin = dr;
186  }
187  }
188 
189  // direction is always from the previous point along track to
190  // the next point, that is why sign is there
191  moms.push_back(TVector3(mom * sign * (xyz1[0] - xyz[0]) / dx,
192  mom * sign * (xyz1[1] - xyz[1]) / dx,
193  mom * sign * (xyz1[2] - xyz[2]) / dx));
194 
195  /*************************************************************/
196  /* WARNING */
197  /*************************************************************/
198  /* The dQdx information in recob::Track has been deprecated */
199  /* since 2016 and in 11/2018 the recob::Track interface was */
200  /* changed and DQdxAtPoint and NumberdQdx were removed. */
201  /* Therefore the code below is now commented out */
202  /* (note that it was most likely not functional anyways). */
203  /* For any issue please contact: larsoft-team@fnal.gov */
204  /*************************************************************/
205  /*
206  dQdx[0].push_back(charge/dx);
207  dQdx[1].push_back(charge/dx);
208  dQdx[2].push_back(charge/dx);
209  */
210  /*************************************************************/
211 
212  // make the space point and set its ID and XYZ
213  double xyzerr[6] = {1.e-3};
214  double chisqr = 0.9;
215  recob::SpacePoint sp(&xyz[0], xyzerr, chisqr, clusterMapItr.first * 10000 + t);
216  spcol->push_back(sp);
217  }
218 
219  size_t spEnd = spcol->size();
220 
221  // add a track to the collection. Make the track
222  // ID be the same as the track ID for the eve particle
223  trackcol->push_back(
226  recob::Track::Flags_t(points.size()),
227  true),
228  0,
229  -1.,
230  0,
233  clusterMapItr.first));
234 
235  // associate the track with its clusters
236  util::CreateAssn(*this, evt, *trackcol, ptrvs, *tcassn);
237 
238  // assume the input tracks were previously associated with hits
239  hits.clear();
240  for (size_t p = 0; p < ptrvs.size(); ++p) {
241  hits = fmh.at(idxs[p]);
242  util::CreateAssn(*this, evt, *trackcol, hits, *thassn);
243  }
244 
245  // associate the track to the space points
246  util::CreateAssn(*this, evt, *trackcol, *spcol, *tspassn, spStart, spEnd);
247 
248  mf::LogInfo("TrackCheater") << "adding track: \n" << trackcol->back() << "\nto collection.";
249 
250  } //end if this is a track
251 
252  } // end loop over the map
253 
254  evt.put(std::move(trackcol));
255  evt.put(std::move(spcol));
256  evt.put(std::move(tcassn));
257  evt.put(std::move(thassn));
258  evt.put(std::move(tspassn));
259 
260  return;
261 
262  } // end produce
unsigned int NumberTrajectoryPoints() const
Definition: MCParticle.h:218
int PdgCode() const
Definition: MCParticle.h:212
std::string const fCheatedClusterLabel
ROOT::Math::SMatrix< Double32_t, 5, 5, ROOT::Math::MatRepSym< Double32_t, 5 > > SMatrixSym55
Definition: TrackingTypes.h:85
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
std::vector< Vector_t > convertCollToVector(std::vector< Vector > const &coll)
Definition: TrackingTypes.h:58
constexpr T pow(T x)
Definition: pow.h:72
TrackTrajectory::Flags_t Flags_t
Definition: Track.h:68
std::vector< double > HitToXYZ(detinfo::DetectorClocksData const &clockData, const recob::Hit &hit) const
T abs(T value)
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
Definition: DataViewImpl.h:633
void push_back(Ptr< U > const &p)
Definition: PtrVector.h:435
A trajectory in space reconstructed from hits.
def move(depos, offset)
Definition: depos.py:107
double P(const int i=0) const
Definition: MCParticle.h:234
p
Definition: test.py:223
ProductID put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
Definition: DataViewImpl.h:686
bool CreateAssn(PRODUCER const &prod, art::Event &evt, std::vector< T > const &a, art::Ptr< U > const &b, art::Assns< U, T > &assn, std::string a_instance, size_t indx=UINT_MAX)
Creates a single one-to-one association.
std::vector< Point_t > convertCollToPoint(std::vector< Point > const &coll)
Definition: TrackingTypes.h:55
static int max(int a, int b)
size_type size() const
Definition: PtrVector.h:302
const sim::ParticleList & ParticleList() const
int sign(double val)
Definition: UtilFunc.cxx:104
double Vx(const int i=0) const
Definition: MCParticle.h:221
double Vz(const int i=0) const
Definition: MCParticle.h:223
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
Definition: Ptr.h:297
LArSoft geometry interface.
Definition: ChannelGeo.h:16
double Vy(const int i=0) const
Definition: MCParticle.h:222
Track from a non-cascading particle.A recob::Track consists of a recob::TrackTrajectory, plus additional members relevant for a "fitted" track:
Definition: Track.h:49
Signal from collection planes.
Definition: geo_types.h:146

Member Data Documentation

std::string const trkf::TrackCheater::fCheatedClusterLabel
private

label for module creating recob::Cluster objects

Definition at line 45 of file TrackCheater_module.cc.

std::string const trkf::TrackCheater::fG4ModuleLabel
private

label for module running G4 and making particles, etc

Definition at line 47 of file TrackCheater_module.cc.


The documentation for this class was generated from the following file: