InfoTransfer_service.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Transfer hitlist and run info into a producer module.
4 // Do not copy this code without contacting Andrzej Szelc and Brian Rebel first.
5 //
6 // \author andrzej.szelc@yale.edu
7 // ellen.klein@yale.edu
8 ////////////////////////////////////////////////////////////////////////
9 
10 // Framework includes
16 
22 #include "nuevdb/EventDisplayBase/NavState.h"
23 
24 namespace{
25  void WriteMsg(const char* fcn)
26  {
27  mf::LogWarning("InfoTransfer") << "InfoTransfer::" << fcn << " \n";
28  }
29 }
30 
31 namespace evd {
32 
33  //......................................................................
36  : evdb::Reconfigurable{pset}
37  {
38  this->reconfigure(pset);
39  testflag=-1;
40  fEvt=-1;
41  fRun=-1;
42  fSubRun=-1;
43  reg.sPreProcessEvent.watch(this, &InfoTransfer::Rebuild);
45  unsigned int nplanes = geo->Nplanes();
46 
47  fSelectedHitlist.resize(nplanes);
48  fStartHit.resize(nplanes);
49  fRefStartHit.resize(nplanes);
50  fEndHit.resize(nplanes);
51  fRefEndHit.resize(nplanes);
52  starthitout.resize(nplanes);
53  endhitout.resize(nplanes);
54  refstarthitout.resize(nplanes);
55  refendhitout.resize(nplanes);
56  for(unsigned int i=0;i<nplanes;i++){
57  starthitout[i].resize(2);
58  endhitout[i].resize(2);
59  refstarthitout[i].resize(2);
60  refendhitout[i].resize(2);
61  }
62  // hitlist=NULL;
63  }
64 
65  //......................................................................
67  {
68  }
69 
70  //......................................................................
72  {
74  unsigned int nplanes = geo->Nplanes();
75  //clear everything
76  fRefinedHitlist.resize(nplanes);
77  fSelectedHitlist.resize(nplanes);
78  for (unsigned int i=0;i<nplanes;i++){
79  fRefinedHitlist[i].clear();
80  fSelectedHitlist[i].clear();
81  }
82  fHitModuleLabel = pset.get<std::string>("HitModuleLabel", "ffthit");
83  }
84 
85 
86 
87  //......................................................................
89  {
91  unsigned int nplanes = geo->Nplanes();
92  unsigned int which_call=evdb::NavState::Which();
93  if(which_call!=2){
94  //unless we're reloading we want to clear all the selected and refined hits
95  fRefinedHitlist.resize(nplanes);
96  fSelectedHitlist.resize(nplanes);
97  for(unsigned int j=0; j<nplanes;j++){
98  fRefinedHitlist[j].clear();
99  fSelectedHitlist[j].clear();
100  starthitout[j].clear();
101  endhitout[j].clear();
102  starthitout[j].resize(2);
103  endhitout[j].resize(2);
104  refstarthitout[j].clear();
105  refendhitout[j].clear();
106  refstarthitout[j].resize(2);
107  refendhitout[j].resize(2);
108  }
109  //also clear start and end points
110  fRefStartHit.clear();
111  fRefEndHit.clear();
112  fFullHitlist.clear();
113  }
115 
116  fEvt=evt.id().event();
117  fRun=evt.id().run();
118  fSubRun=evt.id().subRun();
119  evt.getByLabel(fHitModuleLabel, hHandle);
120 
121  if(hHandle.failedToGet()){
122 // mf::LogWarning("InfoTransfer") << "failed to get handle to std::vector<recob::Hit> from "<< fHitModuleLabel;
123  return;
124  }
125 
126  // Clear out anything remaining from previous calls to Rebuild
127 
128  fRefinedHitlist.resize(nplanes);
129 
130  for(unsigned int i=0;i<nplanes;i++){
131  fRefinedHitlist[i].clear(); ///< the refined hitlist after rebuild
132  }
133 
134 
135  fFullHitlist.clear();
136  for(unsigned int i=0; i<fRefStartHit.size(); i++){
137  fRefStartHit[i]=NULL;
138  fRefEndHit[i]=NULL;
139  }
140 
141  /////Store start and end hits in new lists and clear the old ones:
142  for(unsigned int i=0;i<nplanes;i++ )
143  { refstarthitout[i].clear();
144  refendhitout[i].clear();
145  refstarthitout[i].resize(2);
146  refendhitout[i].resize(2);
147 
149  refendhitout[i]=endhitout[i];
150 
151  starthitout[i].clear();
152  endhitout[i].clear();
153  starthitout[i].resize(2);
154  endhitout[i].resize(2);
155  }
156 
157  for(size_t p = 0; p < hHandle->size(); ++p){
158  art::Ptr<recob::Hit> hit(hHandle, p);
159  fFullHitlist.push_back(hit);
160  }
161 
162  // fill the selected Hits into the fRefinedHitList from the fSelectedHitList
163  char buf[200];
164  for(unsigned int j=0; j<nplanes; j++){
165  sprintf(buf," ++++rebuilding with %lu selected hits in plane %u \n", fSelectedHitlist[j].size(),j);
166  WriteMsg(buf);
167  }
168 
169  for(size_t t = 0; t < fFullHitlist.size(); ++t){
170  for(unsigned int ip=0;ip<nplanes;ip++) {
171  for(size_t xx = 0; xx < fSelectedHitlist[ip].size(); ++xx){
172  if(fFullHitlist[t]==fSelectedHitlist[ip][xx]) {
173  fRefinedHitlist[ip].push_back(fFullHitlist[t]);
174  break;
175  }
176  }
177 
178  if(fStartHit[ip] && fFullHitlist[t].get()==fStartHit[ip]){
179  fRefStartHit[ip]=const_cast<recob::Hit *>(fFullHitlist[t].get());
180  }
181 
182  if(fEndHit[ip] && fFullHitlist[t].get()==fEndHit[ip]){
183  fRefEndHit[ip]=const_cast<recob::Hit *>(fFullHitlist[t].get());
184  }
185 
186  }
187  }
188  //for(int ip=0;ip<nplanes;ip++)
189  // FillStartEndHitCoords(ip);
190 
191  fSelectedHitlist.clear();
193 
194  return;
195  }
196 
197  //......................................................................
198  void InfoTransfer::SetSeedList(std::vector < util::PxLine > seedlines)
199  {
200  fSeedList=seedlines;
201  }
202 
203 
204  //......................................................................
205  std::vector < util::PxLine > const& InfoTransfer::GetSeedList() const
206  {
207  return fSeedList;
208  }
209 
210 
211  //......................................................................
212  void InfoTransfer::FillStartEndHitCoords(unsigned int plane)
213  {
214 
216  // std::vector <double> sthitout(2);
217  if(fRefStartHit[plane]){
218  starthitout[plane][1] = fRefStartHit[plane]->PeakTime() ;
219  try{
220  if(fRefStartHit[plane]->WireID().isValid){
221  starthitout[plane][0] = fRefStartHit[plane]->WireID().Wire;
222  }
223  else{
224  starthitout[plane][0]=0;
225  }
226  }
227  catch(cet::exception const& e) {
228  mf::LogWarning("GraphCluster") << "caught exception \n"
229  << e;
230  starthitout[plane][0]=0;
231  }
232  }
233  else{
234  starthitout[plane][1]=0.;
235  starthitout[plane][0]=0.;
236  }
237 
238 
239  if(fRefEndHit[plane]){
240  endhitout[plane][1] = fRefEndHit[plane]->PeakTime() ;
241  try{
242  if(fRefEndHit[plane]->WireID().isValid){
243  endhitout[plane][0] = fRefEndHit[plane]->WireID().Wire;
244  }
245  else{
246  endhitout[plane][0]=0;
247  }
248  }
249  catch(cet::exception const& e) {
250  mf::LogWarning("GraphCluster") << "caught exception \n"
251  << e;
252  endhitout[plane][0]=0;
253  }
254  }
255  else{
256  endhitout[plane][1]=0.;
257  endhitout[plane][0]=0.;
258  }
259 
260 
261  }
262 
263 }//namespace
264 
265 namespace evd {
266 
268 
269 } // namespace evd
270 ////////////////////////////////////////////////////////////////////////
271 
272 
273 ////////////////////////////////////////////////////////////////////////
std::vector< std::vector< art::Ptr< recob::Hit > > > fRefinedHitlist
the refined hitlist after rebuild (one for each plane)
Definition: InfoTransfer.h:124
std::vector< std::vector< double > > refendhitout
Definition: InfoTransfer.h:140
void FillStartEndHitCoords(unsigned int plane)
std::vector< util::PxLine > GetSeedList()
std::string string
Definition: nybbler.cc:12
InfoTransfer(fhicl::ParameterSet const &pset, art::ActivityRegistry &reg)
std::vector< art::Ptr< recob::Hit > > fFullHitlist
the full Hit list from the Hitfinder.
Definition: InfoTransfer.h:125
std::vector< recob::Hit * > fStartHit
The Starthit.
Definition: InfoTransfer.h:128
RunNumber_t run() const
Definition: EventID.h:98
art framework interface to geometry description
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:92
void Rebuild(const art::Event &evt)
std::vector< recob::Hit * > fRefStartHit
The Refined Starthit.
Definition: InfoTransfer.h:129
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
Definition: DataViewImpl.h:633
unsigned int Nplanes(unsigned int tpc=0, unsigned int cstat=0) const
Returns the total number of wire planes in the specified TPC.
const double e
LArSoft includes.
Definition: InfoTransfer.h:33
IDparameter< geo::WireID > WireID
Member type of validated geo::WireID parameter.
T get(std::string const &key) const
Definition: ParameterSet.h:271
std::vector< recob::Hit * > fRefEndHit
The Refined Starthit.
Definition: InfoTransfer.h:132
std::vector< recob::Hit * > fEndHit
The Starthit.
Definition: InfoTransfer.h:131
p
Definition: test.py:223
std::vector< std::vector< double > > starthitout
Definition: InfoTransfer.h:136
std::string fHitModuleLabel
label for geant4 module
Definition: InfoTransfer.h:126
Definition of data types for geometry description.
std::vector< std::vector< double > > endhitout
Definition: InfoTransfer.h:137
#define DEFINE_ART_SERVICE(svc)
std::vector< std::vector< art::Ptr< recob::Hit > > > fSelectedHitlist
the list selected by the GUI (one for each plane)
Definition: InfoTransfer.h:123
Declaration of signal hit object.
void SetSeedList(std::vector< util::PxLine > seedlines)
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
EventNumber_t event() const
Definition: EventID.h:116
2D representation of charge deposited in the TDC/wire plane
Definition: Hit.h:48
TCEvent evt
Definition: DataStructs.cxx:7
void reconfigure(fhicl::ParameterSet const &pset)
LArSoft geometry interface.
Definition: ChannelGeo.h:16
std::vector< std::vector< double > > refstarthitout
Definition: InfoTransfer.h:139
SubRunNumber_t subRun() const
Definition: EventID.h:110
EventID id() const
Definition: Event.cc:34
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
bool failedToGet() const
Definition: Handle.h:198
std::vector< util::PxLine > fSeedList
Definition: InfoTransfer.h:134