CaloStripSplitter_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: CaloStripSplitter
3 // Plugin Type: producer (art v2_11_02)
4 // File: CaloStripSplitter_module.cc
5 //
6 ////////////////////////////////////////////////////////////////////////
7 
15 
17 #include "fhiclcpp/ParameterSet.h"
19 
21 
22 #include "Geometry/GeometryGAr.h"
24 
26 
27 #include "CLHEP/Units/SystemOfUnits.h"
28 
29 #include <memory>
30 
31 namespace gar {
32  namespace rec {
33 
34  namespace alg{
35  class StripSplitterAlg;
36  }
37 
39  public:
40  explicit CaloStripSplitter(fhicl::ParameterSet const & p);
41  // The compiler-generated destructor is fine for non-base
42  // classes without bare pointers or other resource use.
43 
44  // Plugins should not be copied or assigned.
45  CaloStripSplitter(CaloStripSplitter const &) = delete;
47  CaloStripSplitter & operator = (CaloStripSplitter const &) = delete;
48  CaloStripSplitter & operator = (CaloStripSplitter &&) = delete;
49 
50  // Required functions.
51  void produce(art::Event & e) override;
52 
53  private:
54 
55  // Declare member data here.
56  void CollectHits(const art::Event &evt, const std::string &label, const std::string &instance, std::vector< art::Ptr<gar::rec::CaloHit> > &hitVector);
57  std::array<double, 3> CalculateStripHitPosition(float x, float y, float z, std::pair<float, float> time, raw::CellID_t cID);
58  float CorrectStripHitTime(float x, float y, float z, std::pair<float, float> hitTime, raw::CellID_t cID);
59 
60  std::string fCaloHitLabel; ///< label to find the right reco calo hits
61  std::string fInstanceName; ///< product instance name
62 
66 
67  const detinfo::DetectorProperties* fDetProp; ///< detector properties
68  const geo::GeometryCore* fGeo; ///< pointer to the geometry
69 
70  std::unique_ptr<rec::alg::StripSplitterAlg> fSSAAlgo; //Cluster algorithm
71  };
72 
73  //----------------------------------------------------------------------------
75  {
76  fCaloHitLabel = p.get<std::string>("CaloHitLabel", "calohit");
77  fInstanceName = p.get<std::string >("InstanceLabelName", "");
78 
79  fGeo = gar::providerFrom<geo::GeometryGAr>();
80  fDetProp = gar::providerFrom<detinfo::DetectorPropertiesService>();
81  fSaveStripEndsOnly = p.get<bool>("SaveStripEndsOnly", false);
82  fSaveUnsplitHits = p.get<bool>("SaveUnsplitHits", true);
83 
84  //configure the cluster algorithm
85  auto fSSAAlgoPars = p.get<fhicl::ParameterSet>("SSAAlgPars");
86  fSSAAlgo = std::make_unique<rec::alg::StripSplitterAlg>(fSSAAlgoPars);
87  fSaveStripEnds = fSSAAlgo->GetSaveStripEndsFlag();
88 
89  if(fSaveStripEnds) {
90  MF_LOG_INFO("CaloStripSplitter_module")
91  << " Saving Strip ends flag turned on! ";
92  }
93 
94  art::InputTag tag(fCaloHitLabel, fInstanceName);
95  consumes<std::vector<gar::rec::CaloHit>>(tag);
96  produces<std::vector<gar::rec::CaloHit>>(fInstanceName);
97  }
98 
99  //----------------------------------------------------------------------------
101  {
102  //Collect the hits to be passed to the algo
103  std::vector< art::Ptr<gar::rec::CaloHit> > artHits;
104  this->CollectHits(e, fCaloHitLabel, fInstanceName, artHits);
105 
106  //Prepare the hits for SSA
107  fSSAAlgo->PrepareAlgo(artHits);
108  //Perform the SS
109  fSSAAlgo->DoStripSplitting();
110  //Get back the vector of split hits
111  std::vector<const gar::rec::CaloHit*> splitHits = fSSAAlgo->getSplitHits();
112  //Get back the vector of unsplit hits
113  std::vector<const gar::rec::CaloHit*> unsplitHits = fSSAAlgo->getUnSplitHits();
114 
115  // make an art::PtrVector of the hits
116  std::unique_ptr< std::vector<gar::rec::CaloHit> > HitCol(new std::vector<gar::rec::CaloHit>);
117 
118  if(not fSaveStripEndsOnly) {
119  //Copy the split hits to the collection
120  for(auto const &it : splitHits) {
121 
122  //Need to correct the time for the strips
123  float energy = it->Energy();
124  std::pair<float, float> time = it->Time();
125  raw::CellID_t cellID = it->CellID();
126  const float *pos = it->Position();
127  float newpos[3] = { pos[0], pos[1], pos[2] };
128  float newtime = time.first;
129  unsigned int layer = it->Layer();
130  const std::array<double, 3> point = { pos[0], pos[1], pos[2] };
131 
132  if(not fGeo->isTile(point, cellID)) {
133  newtime = this->CorrectStripHitTime(newpos[0], newpos[1], newpos[2], time, cellID);
134  }
135 
136  rec::CaloHit hit(energy, newtime, newpos, cellID, layer);
137  HitCol->emplace_back(hit);
138  }
139 
140  if( fSaveUnsplitHits ) {
141  //Copy the unsplit hits to the collection
142  for(auto const &it : unsplitHits) {
143 
144  //Need to correct the position of the un-used strips
145  float energy = it->Energy();
146  std::pair<float, float> time = it->Time();
147  raw::CellID_t cellID = it->CellID();
148  const float *pos = it->Position();
149  float newpos[3] = { pos[0], pos[1], pos[2] };
150  float newtime = time.first;
151  unsigned int layer = it->Layer();
152  const std::array<double, 3> point = { pos[0], pos[1], pos[2] };
153 
154  if(not fGeo->isTile(point, cellID)) {
155  // Need to correct for the position of these based on time information
156  std::array<double, 3> strip_pos = this->CalculateStripHitPosition(newpos[0], newpos[1], newpos[2], time, cellID);
157  newpos[0] = strip_pos[0];
158  newpos[1] = strip_pos[1];
159  newpos[2] = strip_pos[2];
160  newtime = this->CorrectStripHitTime(newpos[0], newpos[1], newpos[2], time, cellID);
161  }
162 
163  rec::CaloHit hit(energy, newtime, newpos, cellID, layer);
164 
165  HitCol->emplace_back(hit);
166  }
167  }
168  }
169 
170  //Copy the strip end hits to the collection
171  if(fSaveStripEnds) {
172  std::vector<const gar::rec::CaloHit*> stripEndsHits = fSSAAlgo->getStripEndsHits();
173  for(auto const &it : stripEndsHits)
174  HitCol->emplace_back(*it);
175 
176  std::vector<const gar::rec::CaloHit*> stripInterHits = fSSAAlgo->getIntersectionHits();
177  for(auto const &it : stripInterHits)
178  HitCol->emplace_back(*it);
179  }
180 
181  e.put(std::move(HitCol), fInstanceName);
182 
183  return;
184  }
185 
186  //----------------------------------------------------------------------------
188  {
189  art::InputTag itag(label,instance);
190  auto theHits = evt.getHandle< std::vector<gar::rec::CaloHit> >(itag);
191  if (!theHits) return;
192 
193  for (unsigned int i = 0; i < theHits->size(); ++i)
194  {
195  const art::Ptr<gar::rec::CaloHit> hit(theHits, i);
196  hitVector.push_back(hit);
197  }
198  }
199 
200  //----------------------------------------------------------------------------
201  std::array<double, 3> CaloStripSplitter::CalculateStripHitPosition(float x, float y, float z, std::pair<float, float> time, raw::CellID_t cID)
202  {
203  std::array<double, 3> point = {x, y, z};
204  std::array<double, 3> pointLocal;
206  fGeo->WorldToLocal(point, pointLocal, trans);
207 
208  //Calculate the position of the hit based on the corrected time along the strip
209  float c = (CLHEP::c_light * CLHEP::mm / CLHEP::ns) / CLHEP::cm; // in cm/ns
210  float xlocal = c * ( time.first - time.second ) / 2.;
211 
212  std::array<double, 3> local_back = fGeo->ReconstructStripHitPosition(point, pointLocal, xlocal, cID);
213  std::array<double, 3> world_back;
214  fGeo->LocalToWorld(local_back, world_back, trans);
215 
216  return world_back;
217  }
218 
219  //----------------------------------------------------------------------------
220  float CaloStripSplitter::CorrectStripHitTime(float x, float y, float z, std::pair<float, float> hitTime, raw::CellID_t cID)
221  {
222  std::array<double, 3> point = {x, y, z};
223  double stripLength = fGeo->getStripLength(point, cID); // in cm
224 
225  float c = (CLHEP::c_light * CLHEP::mm / CLHEP::ns) / CLHEP::cm; // in cm/ns
226  float time = (hitTime.first + hitTime.second) / 2. - (stripLength / (2 * c));
227 
228  return time;
229  }
230 
232 
233  } // namespace rec
234 } // namespace gar
static constexpr double cm
Definition: Units.h:68
std::array< double, 3 > CalculateStripHitPosition(float x, float y, float z, std::pair< float, float > time, raw::CellID_t cID)
rec
Definition: tracks.py:88
bool WorldToLocal(std::array< double, 3 > const &world, std::array< double, 3 > &local, gar::geo::LocalTransformation< TGeoHMatrix > &trans) const
std::string fInstanceName
product instance name
void produce(art::Event &e) override
Handle< PROD > getHandle(SelectorBase const &) const
Definition: DataViewImpl.h:382
const geo::GeometryCore * fGeo
pointer to the geometry
std::string string
Definition: nybbler.cc:12
CaloStripSplitter(fhicl::ParameterSet const &p)
std::unique_ptr< rec::alg::StripSplitterAlg > fSSAAlgo
struct vector vector
const std::string instance
void CollectHits(const art::Event &evt, const std::string &label, const std::string &instance, std::vector< art::Ptr< gar::rec::CaloHit > > &hitVector)
Description of geometry of one entire detector.
Definition: GeometryCore.h:436
double getStripLength(const std::array< double, 3 > &point, const gar::raw::CellID_t &cID) const
Class to transform between world and local coordinates.
const detinfo::DetectorProperties * fDetProp
detector properties
bool isTile(const std::array< double, 3 > &point, const gar::raw::CellID_t &cID) const
const double e
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
def move(depos, offset)
Definition: depos.py:107
bool LocalToWorld(std::array< double, 3 > const &local, std::array< double, 3 > &world, gar::geo::LocalTransformation< TGeoHMatrix > const &trans) const
p
Definition: test.py:223
ProductID put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
Definition: DataViewImpl.h:686
float CorrectStripHitTime(float x, float y, float z, std::pair< float, float > hitTime, raw::CellID_t cID)
long long int CellID_t
Definition: CaloRawDigit.h:24
#define MF_LOG_INFO(category)
std::string fCaloHitLabel
label to find the right reco calo hits
General GArSoft Utilities.
std::array< double, 3 > ReconstructStripHitPosition(const std::array< double, 3 > &point, const std::array< double, 3 > &local, const float &xlocal, const gar::raw::CellID_t &cID) const
static constexpr double mm
Definition: Units.h:65
list x
Definition: train.py:276
TCEvent evt
Definition: DataStructs.cxx:7
art framework interface to geometry description
QAsciiDict< Entry > ns