All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Private Member Functions | Private Attributes | List of all members
trkf::TrackCheater Class Reference
Inheritance diagram for trkf::TrackCheater:

Public Member Functions

 TrackCheater (fhicl::ParameterSet const &pset)
 

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...
 

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 const fG4ModuleLabel
label for module running G4 and making particles, etc

Member Function Documentation

void trkf::TrackCheater::produce ( art::Event &  evt)
overrideprivate

Definition at line 68 of file TrackCheater_module.cc.

69  {
70  art::ServiceHandle<cheat::ParticleInventoryService const> pi_serv;
71  art::ServiceHandle<cheat::BackTrackerService const> bt_serv;
72  art::ServiceHandle<geo::Geometry const> geo;
73 
74  // grab the clusters that have been reconstructed
75  art::Handle<std::vector<recob::Cluster>> clustercol;
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(
110  new art::Assns<recob::Track, recob::SpacePoint>);
111  std::unique_ptr<art::Assns<recob::Track, recob::Cluster>> tcassn(
112  new art::Assns<recob::Track, recob::Cluster>);
113  std::unique_ptr<art::Assns<recob::Track, recob::Hit>> thassn(
114  new art::Assns<recob::Track, recob::Hit>);
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 
137  art::PtrVector<recob::Cluster> ptrvs;
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
std::string const fCheatedClusterLabel
ROOT::Math::SMatrix< Double32_t, 5, 5, ROOT::Math::MatRepSym< Double32_t, 5 > > SMatrixSym55
Definition: TrackingTypes.h:85
std::vector< Vector_t > convertCollToVector(std::vector< Vector > const &coll)
Definition: TrackingTypes.h:58
pdgs p
Definition: selectors.fcl:22
TrackTrajectory::Flags_t Flags_t
T abs(T value)
A trajectory in space reconstructed from hits.
std::vector< Point_t > convertCollToPoint(std::vector< Point > const &coll)
Definition: TrackingTypes.h:55
bool CreateAssn(art::Event &evt, std::vector< T > const &a, art::Ptr< U > const &b, art::Assns< U, T > &assn, std::string a_instance, size_t index=UINT_MAX)
Creates a single one-to-one association.
int sign(double val)
Definition: UtilFunc.cxx:104
TCEvent evt
Definition: DataStructs.cxx:8
Track from a non-cascading particle.A recob::Track consists of a recob::TrackTrajectory, plus additional members relevant for a &quot;fitted&quot; track:
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: