LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
ShowerCheater_module.cc
Go to the documentation of this file.
1 //
3 // ShowerCheater module
4 //
5 // brebel@fnal.gov
6 //
8 #ifndef SHWF_SHOWERCHEATER_H
9 #define SHWF_SHOWERCHEATER_H
10 #include <string>
11 #include <vector>
12 
13 // ROOT includes
14 
15 // LArSoft includes
25 
26 
27 // Framework includes
32 #include "fhiclcpp/ParameterSet.h"
39 
40 namespace shwf {
41  class ShowerCheater : public art::EDProducer {
42  public:
43  explicit ShowerCheater(fhicl::ParameterSet const& pset);
44  virtual ~ShowerCheater();
45 
46  void produce(art::Event& evt);
47 
48  void reconfigure(fhicl::ParameterSet const& pset);
49 
50  private:
51 
52  std::string fCheatedClusterLabel;
53  std::string fG4ModuleLabel;
54 
55  };
56 }
57 
58 namespace shwf{
59 
60  //--------------------------------------------------------------------
62  {
63  this->reconfigure(pset);
64 
65  produces< std::vector<recob::Shower> >();
66  produces< std::vector<recob::SpacePoint> >();
67  produces< art::Assns<recob::Shower, recob::Cluster> >();
68  produces< art::Assns<recob::Shower, recob::SpacePoint> >();
69  produces< art::Assns<recob::Shower, recob::Hit> >();
70  produces< art::Assns<recob::Hit, recob::SpacePoint> >();
71  }
72 
73  //--------------------------------------------------------------------
75  {
76  }
77 
78  //--------------------------------------------------------------------
80  {
81  fCheatedClusterLabel = pset.get< std::string >("CheatedClusterLabel", "cluster" );
82  fG4ModuleLabel = pset.get< std::string >("G4ModuleLabel", "largeant");
83 
84  return;
85  }
86 
87  //--------------------------------------------------------------------
89  {
93 
94  // grab the clusters that have been reconstructed
96  evt.getByLabel(fCheatedClusterLabel, clustercol);
97 
99 
100  // make a vector of them - we aren't writing anything out to a file
101  // so no need for a art::PtrVector here
102  std::vector< art::Ptr<recob::Cluster> > clusters;
103  art::fill_ptr_vector(clusters, clustercol);
104 
105  // make a map of vectors of art::Ptrs keyed by eveID values
106  std::map< int, std::vector<std::pair<size_t, art::Ptr<recob::Cluster> > > > eveClusterMap;
107 
108  // loop over all clusters and fill in the map
109  for(size_t c = 0; c < clusters.size(); ++c){
110 
111  // in the ClusterCheater module we set the cluster ID to be
112  // the eve particle track ID*1000 + plane*100 + tpc*10 + cryostat number. The
113  // floor function on the cluster ID / 1000 will give us
114  // the eve track ID
115  int eveID = floor(clusters[c]->ID()/1000.);
116 
117  std::pair<size_t, art::Ptr<recob::Cluster> > indexPtr(c, clusters[c]);
118 
119  eveClusterMap[eveID].push_back(indexPtr);
120 
121  }// end loop over clusters
122 
123  // loop over the map and make prongs
124  std::unique_ptr< std::vector<recob::Shower> > showercol(new std::vector<recob::Shower>);
125  std::unique_ptr< std::vector<recob::SpacePoint> > spcol(new std::vector<recob::SpacePoint>);
126  std::unique_ptr< art::Assns<recob::Shower, recob::Cluster> > scassn(new art::Assns<recob::Shower, recob::Cluster>);
127  std::unique_ptr< art::Assns<recob::Shower, recob::Hit> > shassn(new art::Assns<recob::Shower, recob::Hit>);
128  std::unique_ptr< art::Assns<recob::Shower, recob::SpacePoint> > sspassn(new art::Assns<recob::Shower, recob::SpacePoint>);
129  std::unique_ptr< art::Assns<recob::Hit, recob::SpacePoint> > sphassn(new art::Assns<recob::Hit, recob::SpacePoint>);
130 
131  for(auto const& clusterMapItr : eveClusterMap){
132 
133  // separate out the hits for each particle into the different views
134  std::vector< std::pair<size_t, art::Ptr<recob::Cluster> > > const& eveClusters = clusterMapItr.second;
135 
136  size_t startSPIndx = spcol->size();
137 
138  double totalCharge = 0.;
139 
140  std::vector< art::Ptr<recob::Cluster> > ptrvs;
141  std::vector< size_t > idxs;
142 
143  for(auto const& idxPtr : eveClusters){
144  idxs.push_back(idxPtr.first);
145  ptrvs.push_back(idxPtr.second);
146 
147  // need to make the space points for this prong
148  // loop over the hits for this cluster and make
149  // a space point for each one
150  // set the SpacePoint ID to be the cluster ID*10000
151  // + the hit index in the cluster PtrVector of hits
152  std::vector< art::Ptr<recob::Hit> > const& hits = fmh.at(idxPtr.first);
153 
154  for(size_t h = 0; h < hits.size(); ++h){
155  art::Ptr<recob::Hit> hit = hits[h];
156  // add up the charge from the hits on the collection plane
157  if(hit->SignalType() == geo::kCollection) totalCharge += hit->Integral();
158  std::vector<double> xyz = bt_serv->HitToXYZ(hit);
159  double sperr[6] = {0.01, 0.01, 0.1, 0.001, 0.001, 0.001};
160 
161  // make the space point and set its ID and XYZ
162  // the errors and chi^2 are set to "good" values as we know the information perfectly
163  recob::SpacePoint sp(&xyz[0],
164  sperr,
165  0.9,
166  idxPtr.second->ID()*10000 + h);
167  spcol->push_back(sp);
168 
169  // associate the space point to the hit
170  util::CreateAssn(*this, evt, *spcol, hit, *sphassn);
171 
172  }// end loop over hits
173  } // end loop over pairs of index values and cluster Ptrs
174 
175  size_t endSPIndx = spcol->size();
176 
177  // is this prong electro-magnetic in nature or
178  // hadronic/muonic? EM --> shower, everything else is a track
179  if( std::abs(pi_serv->ParticleList()[clusterMapItr.first]->PdgCode()) == 11 ||
180  std::abs(pi_serv->ParticleList()[clusterMapItr.first]->PdgCode()) == 22 ||
181  std::abs(pi_serv->ParticleList()[clusterMapItr.first]->PdgCode()) == 111 ){
182 
183  mf::LogInfo("ShowerCheater") << "prong of " << clusterMapItr.first
184  << " is a shower with pdg code "
185  << pi_serv->ParticleList()[clusterMapItr.first]->PdgCode();
186 
187  // get the direction cosine for the eve ID particle
188  // just use the same for both the start and end of the prong
189  const TLorentzVector initmom = pi_serv->ParticleList()[clusterMapItr.first]->Momentum();
190  TVector3 dcos( initmom.Px()/initmom.Mag(),
191  initmom.Py()/initmom.Mag(),
192  initmom.Pz()/initmom.Mag() );
193  TVector3 dcosErr(1.e-3, 1.e-3, 1.e-3 );
194 
196  //double maxTransWidth[2] = { util::kBogusD, util::kBogusD };
197  //double distanceMaxWidth = util::kBogusD;
198 
199  // add a prong to the collection. Make the prong
200  // ID be the same as the track ID for the eve particle
202  s.set_id(showercol->size());
203  s.set_direction(dcos);
204  s.set_direction_err(dcosErr);
205  /*
206  showercol->push_back(recob::Shower(dcos, dcosErr, maxTransWidth,
207  distanceMaxWidth, totalCharge, clusterMapItr.first));
208  */
209  showercol->push_back(s);
210  // associate the shower with its clusters
211  util::CreateAssn(*this, evt, *showercol, ptrvs, *scassn);
212 
213  // get the hits associated with each cluster and associate those with the shower
214  for(size_t i = 0; i < idxs.size(); ++i){
215  std::vector< art::Ptr<recob::Hit> > hits = fmh.at(i);
216  util::CreateAssn(*this, evt, *showercol, hits, *shassn);
217  }
218 
219  // associate the shower with the space points
220  util::CreateAssn(*this, evt, *showercol, *spcol, *sspassn, startSPIndx, endSPIndx);
221 
222  mf::LogInfo("ShowerCheater") << "adding shower: \n"
223  << showercol->back()
224  << "\nto collection.";
225 
226  }// end if this is a shower
227  } // end loop over the map
228 
229  evt.put(std::move(showercol));
230  evt.put(std::move(spcol));
231  evt.put(std::move(scassn));
232  evt.put(std::move(shassn));
233  evt.put(std::move(sspassn));
234  evt.put(std::move(sphassn));
235 
236  return;
237 
238  } // end produce
239 
240 } // end namespace
241 
242 namespace shwf{
243 
245 
246 }
247 
248 #endif
Float_t s
Definition: plot.C:23
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:232
const std::vector< double > HitToXYZ(const recob::Hit &hit)
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
Declaration of signal hit object.
void reconfigure(fhicl::ParameterSet const &pset)
shower finding
float Integral() const
Integral under the calibrated signal waveform of the hit, in tick x ADC units.
Definition: Hit.h:225
ShowerCheater(fhicl::ParameterSet const &pset)
void produce(art::Event &evt)
ProductID put(std::unique_ptr< PROD > &&product)
Definition: Event.h:102
std::string fCheatedClusterLabel
label for module creating recob::Cluster objects
void set_id(const int id)
Definition: Shower.h:128
void hits()
Definition: readHits.C:15
void set_direction(const TVector3 &dir)
Definition: Shower.h:135
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:42
T get(std::string const &key) const
Definition: ParameterSet.h:231
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.
Declaration of cluster object.
Detector simulation of raw signals on wires.
Utility object to perform functions of association.
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
Definition: DataViewImpl.h:344
std::string fG4ModuleLabel
label for module running G4 and making particles, etc
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
Definition: Ptr.h:464
Float_t e
Definition: plot.C:34
Namespace collecting geometry-related classes utilities.
art framework interface to geometry description
Signal from collection planes.
Definition: geo_types.h:93