ShowerCheater_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // ShowerCheater module
4 //
5 // brebel@fnal.gov
6 //
7 ////////////////////////////////////////////////////////////////////////
8 
9 #include <string>
10 
11 // LArSoft includes
21 
22 // Framework includes
28 #include "canvas/Persistency/Common/FindManyP.h"
29 #include "fhiclcpp/ParameterSet.h"
31 
32 namespace shwf {
33  class ShowerCheater : public art::EDProducer {
34  public:
35  explicit ShowerCheater(fhicl::ParameterSet const& pset);
36 
37  private:
38  void produce(art::Event& evt) override;
39 
40  std::string const fCheatedClusterLabel; ///< label for module creating
41  ///< recob::Cluster objects
42  std::string const fG4ModuleLabel; ///< label for module running G4 and making particles, etc
43  };
44 }
45 
46 namespace shwf {
47 
48  //--------------------------------------------------------------------
50  : EDProducer{pset}
51  , fCheatedClusterLabel{pset.get<std::string>("CheatedClusterLabel", "cluster")}
52  , fG4ModuleLabel{pset.get<std::string>("G4ModuleLabel", "largeant")}
53  {
54  produces<std::vector<recob::Shower>>();
55  produces<std::vector<recob::SpacePoint>>();
56  produces<art::Assns<recob::Shower, recob::Cluster>>();
57  produces<art::Assns<recob::Shower, recob::SpacePoint>>();
58  produces<art::Assns<recob::Shower, recob::Hit>>();
59  produces<art::Assns<recob::Hit, recob::SpacePoint>>();
60  }
61 
62  //--------------------------------------------------------------------
63  void
65  {
69 
70  // grab the clusters that have been reconstructed
72  evt.getByLabel(fCheatedClusterLabel, clustercol);
73 
74  art::FindManyP<recob::Hit> fmh(clustercol, evt, fCheatedClusterLabel);
75 
76  // make a vector of them - we aren't writing anything out to a file
77  // so no need for a art::PtrVector here
78  std::vector<art::Ptr<recob::Cluster>> clusters;
79  art::fill_ptr_vector(clusters, clustercol);
80 
81  // make a map of vectors of art::Ptrs keyed by eveID values
82  std::map<int, std::vector<std::pair<size_t, art::Ptr<recob::Cluster>>>> eveClusterMap;
83 
84  // loop over all clusters and fill in the map
85  for (size_t c = 0; c < clusters.size(); ++c) {
86 
87  // in the ClusterCheater module we set the cluster ID to be
88  // the eve particle track ID*1000 + plane*100 + tpc*10 + cryostat number. The
89  // floor function on the cluster ID / 1000 will give us
90  // the eve track ID
91  int eveID = floor(clusters[c]->ID() / 1000.);
92 
93  std::pair<size_t, art::Ptr<recob::Cluster>> indexPtr(c, clusters[c]);
94 
95  eveClusterMap[eveID].push_back(indexPtr);
96 
97  } // end loop over clusters
98 
99  // loop over the map and make prongs
100  std::unique_ptr<std::vector<recob::Shower>> showercol(new std::vector<recob::Shower>);
101  std::unique_ptr<std::vector<recob::SpacePoint>> spcol(new std::vector<recob::SpacePoint>);
102  std::unique_ptr<art::Assns<recob::Shower, recob::Cluster>> scassn(
104  std::unique_ptr<art::Assns<recob::Shower, recob::Hit>> shassn(
106  std::unique_ptr<art::Assns<recob::Shower, recob::SpacePoint>> sspassn(
108  std::unique_ptr<art::Assns<recob::Hit, recob::SpacePoint>> sphassn(
110 
111  auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(evt);
112 
113  for (auto const& clusterMapItr : eveClusterMap) {
114 
115  // separate out the hits for each particle into the different views
116  std::vector<std::pair<size_t, art::Ptr<recob::Cluster>>> const& eveClusters =
117  clusterMapItr.second;
118 
119  size_t startSPIndx = spcol->size();
120 
121  double totalCharge = 0.;
122 
123  std::vector<art::Ptr<recob::Cluster>> ptrvs;
124  std::vector<size_t> idxs;
125 
126  for (auto const& idxPtr : eveClusters) {
127  idxs.push_back(idxPtr.first);
128  ptrvs.push_back(idxPtr.second);
129 
130  // need to make the space points for this prong
131  // loop over the hits for this cluster and make
132  // a space point for each one
133  // set the SpacePoint ID to be the cluster ID*10000
134  // + the hit index in the cluster PtrVector of hits
135  std::vector<art::Ptr<recob::Hit>> const& hits = fmh.at(idxPtr.first);
136 
137  for (size_t h = 0; h < hits.size(); ++h) {
138  art::Ptr<recob::Hit> hit = hits[h];
139  // add up the charge from the hits on the collection plane
140  if (hit->SignalType() == geo::kCollection) totalCharge += hit->Integral();
141  std::vector<double> xyz = bt_serv->HitToXYZ(clockData, hit);
142  double sperr[6] = {0.01, 0.01, 0.1, 0.001, 0.001, 0.001};
143 
144  // make the space point and set its ID and XYZ
145  // the errors and chi^2 are set to "good" values as we know the information perfectly
146  recob::SpacePoint sp(&xyz[0], sperr, 0.9, idxPtr.second->ID() * 10000 + h);
147  spcol->push_back(sp);
148 
149  // associate the space point to the hit
150  util::CreateAssn(*this, evt, *spcol, hit, *sphassn);
151 
152  } // end loop over hits
153  } // end loop over pairs of index values and cluster Ptrs
154 
155  size_t endSPIndx = spcol->size();
156 
157  // is this prong electro-magnetic in nature or
158  // hadronic/muonic? EM --> shower, everything else is a track
159  if (std::abs(pi_serv->ParticleList()[clusterMapItr.first]->PdgCode()) == 11 ||
160  std::abs(pi_serv->ParticleList()[clusterMapItr.first]->PdgCode()) == 22 ||
161  std::abs(pi_serv->ParticleList()[clusterMapItr.first]->PdgCode()) == 111) {
162 
163  mf::LogInfo("ShowerCheater")
164  << "prong of " << clusterMapItr.first << " is a shower with pdg code "
165  << pi_serv->ParticleList()[clusterMapItr.first]->PdgCode();
166 
167  // get the direction cosine for the eve ID particle
168  // just use the same for both the start and end of the prong
169  const TLorentzVector initmom = pi_serv->ParticleList()[clusterMapItr.first]->Momentum();
170  TVector3 dcos(
171  initmom.Px() / initmom.Mag(), initmom.Py() / initmom.Mag(), initmom.Pz() / initmom.Mag());
172  TVector3 dcosErr(1.e-3, 1.e-3, 1.e-3);
173 
174  /// \todo figure out the max transverse width of the shower in the x and y directions
175  //double maxTransWidth[2] = { util::kBogusD, util::kBogusD };
176  //double distanceMaxWidth = util::kBogusD;
177 
178  // add a prong to the collection. Make the prong
179  // ID be the same as the track ID for the eve particle
181  s.set_id(showercol->size());
182  s.set_direction(dcos);
183  s.set_direction_err(dcosErr);
184  /*
185  showercol->push_back(recob::Shower(dcos, dcosErr, maxTransWidth,
186  distanceMaxWidth, totalCharge, clusterMapItr.first));
187  */
188  showercol->push_back(s);
189  // associate the shower with its clusters
190  util::CreateAssn(*this, evt, *showercol, ptrvs, *scassn);
191 
192  // get the hits associated with each cluster and associate those with the shower
193  for (size_t i = 0; i < idxs.size(); ++i) {
194  std::vector<art::Ptr<recob::Hit>> hits = fmh.at(i);
195  util::CreateAssn(*this, evt, *showercol, hits, *shassn);
196  }
197 
198  // associate the shower with the space points
199  util::CreateAssn(*this, evt, *showercol, *spcol, *sspassn, startSPIndx, endSPIndx);
200 
201  mf::LogInfo("ShowerCheater") << "adding shower: \n"
202  << showercol->back() << "\nto collection.";
203 
204  } // end if this is a shower
205  } // end loop over the map
206 
207  evt.put(std::move(showercol));
208  evt.put(std::move(spcol));
209  evt.put(std::move(scassn));
210  evt.put(std::move(shassn));
211  evt.put(std::move(sspassn));
212  evt.put(std::move(sphassn));
213  } // end produce
214 
215 } // end namespace
216 
void produce(art::Event &evt) override
void set_direction_err(const TVector3 &dir_e)
Definition: Shower.h:136
geo::SigType_t SignalType() const
Signal type for the plane of the hit.
Definition: Hit.h:231
std::string string
Definition: nybbler.cc:12
unsigned int ID
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
EDProducer(fhicl::ParameterSet const &pset)
Definition: EDProducer.h:20
shower finding
float Integral() const
Integral under the calibrated signal waveform of the hit, in tick x ADC units.
Definition: Hit.h:224
ShowerCheater(fhicl::ParameterSet const &pset)
std::vector< double > HitToXYZ(detinfo::DetectorClocksData const &clockData, const recob::Hit &hit) const
art framework interface to geometry description
void set_id(const int id)
Definition: Shower.h:128
T abs(T value)
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
Definition: DataViewImpl.h:633
void set_direction(const TVector3 &dir)
Definition: Shower.h:135
const double e
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
def move(depos, offset)
Definition: depos.py:107
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::string const fCheatedClusterLabel
Detector simulation of raw signals on wires.
const sim::ParticleList & ParticleList() const
Declaration of signal hit object.
std::string const fG4ModuleLabel
label for module running G4 and making particles, etc
TCEvent evt
Definition: DataStructs.cxx:7
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
Definition: Ptr.h:297
LArSoft geometry interface.
Definition: ChannelGeo.h:16
static QCString * s
Definition: config.cpp:1042
Signal from collection planes.
Definition: geo_types.h:146