InfoTransfer_service.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // $Id: InfoTransfer.cxx,v 1.16 2010/08/30 21:33:24 andrzejs Exp $
3 //
4 // Transfer hitlist and run info into a producer module.
5 // Do not copy this code without contacting Andrzej Szelc and Brian Rebel first.
6 //
7 // \author andrzej.szelc@yale.edu
8 // ellen.klein@yale.edu
9 ////////////////////////////////////////////////////////////////////////
10 #include <iostream>
11 
12 // Framework includes
14 
15 #include "Utilities/AssociationUtil.h"
18 #include "nutools/EventDisplayBase/NavState.h"
19 
20 namespace{
21  void WriteMsg(const char* fcn)
22  {
23  mf::LogWarning("InfoTransfer") << "InfoTransfer::" << fcn << " \n";
24  }
25 }
26 
27 namespace evd {
28 
29  //......................................................................
32  {
33  this->reconfigure(pset);
34  testflag=-1;
35  fEvt=-1;
36  fRun=-1;
37  fSubRun=-1;
38  reg.sPreProcessEvent.watch(this, &InfoTransfer::Rebuild);
40  unsigned int nplanes = geo->Nplanes();
41 
42  fSelectedHitlist.resize(nplanes);
43  fStartHit.resize(nplanes);
44  fRefStartHit.resize(nplanes);
45  fEndHit.resize(nplanes);
46  fRefEndHit.resize(nplanes);
47  starthitout.resize(nplanes);
48  endhitout.resize(nplanes);
49  refstarthitout.resize(nplanes);
50  refendhitout.resize(nplanes);
51  for(unsigned int i=0;i<nplanes;i++){
52  starthitout[i].resize(2);
53  endhitout[i].resize(2);
54  refstarthitout[i].resize(2);
55  refendhitout[i].resize(2);
56  }
57  // hitlist=NULL;
58  }
59 
60  //......................................................................
62  {
63  }
64 
65  //......................................................................
67  {
69  unsigned int nplanes = geo->Nplanes();
70  //clear everything
71  fRefinedHitlist.resize(nplanes);
72  fSelectedHitlist.resize(nplanes);
73  for (unsigned int i=0;i<nplanes;i++){
74  fRefinedHitlist[i].clear();
75  fSelectedHitlist[i].clear();
76  }
77  fHitModuleLabel = pset.get<std::string>("HitModuleLabel", "ffthit");
78  }
79 
80 
81 
82  //......................................................................
84  {
86  unsigned int nplanes = geo->Nplanes();
87  unsigned int which_call=evdb::NavState::Which();
88  if(which_call!=2){
89  //unless we're reloading we want to clear all the selected and refined hits
90  fRefinedHitlist.resize(nplanes);
91  fSelectedHitlist.resize(nplanes);
92  for(unsigned int j=0; j<nplanes;j++){
93  fRefinedHitlist[j].clear();
94  fSelectedHitlist[j].clear();
95  starthitout[j].clear();
96  endhitout[j].clear();
97  starthitout[j].resize(2);
98  endhitout[j].resize(2);
99  refstarthitout[j].clear();
100  refendhitout[j].clear();
101  refstarthitout[j].resize(2);
102  refendhitout[j].resize(2);
103  }
104  //also clear start and end points
105  fRefStartHit.clear();
106  fRefEndHit.clear();
107  fFullHitlist.clear();
108  }
109 
110  fEvt=evt.id().event();
111  fRun=evt.id().run();
112  fSubRun=evt.id().subRun();
113 
114  auto hHandle = evt.getHandle< std::vector<recob::Hit> >(fHitModuleLabel);
115 
116  if(!hHandle){
117  mf::LogWarning("InfoTransfer") << "failed to get handle to std::vector<recob::Hit> from "
118  << fHitModuleLabel;
119  return;
120  }
121 
122  // Clear out anything remaining from previous calls to Rebuild
123 
124  fRefinedHitlist.resize(nplanes);
125 
126  for(unsigned int i=0;i<nplanes;i++){
127  fRefinedHitlist[i].clear(); ///< the refined hitlist after rebuild
128  }
129 
130 
131  fFullHitlist.clear();
132  for(unsigned int i=0; i<fRefStartHit.size(); i++){
133  fRefStartHit[i]=NULL;
134  fRefEndHit[i]=NULL;
135  }
136 
137  /////Store start and end hits in new lists and clear the old ones:
138  for(unsigned int i=0;i<nplanes;i++ )
139  { refstarthitout[i].clear();
140  refendhitout[i].clear();
141  refstarthitout[i].resize(2);
142  refendhitout[i].resize(2);
143 
145  refendhitout[i]=endhitout[i];
146 
147  starthitout[i].clear();
148  endhitout[i].clear();
149  starthitout[i].resize(2);
150  endhitout[i].resize(2);
151  }
152 
153  for(size_t p = 0; p < hHandle->size(); ++p){
154  art::Ptr<recob::Hit> hit(hHandle, p);
155  fFullHitlist.push_back(hit);
156  }
157 
158  // fill the selected Hits into the fRefinedHitList from the fSelectedHitList
159  char buf[200];
160  for(unsigned int j=0; j<nplanes; j++){
161  sprintf(buf," ++++rebuilding with %lu selected hits in plane %u \n", fSelectedHitlist[j].size(),j);
162  WriteMsg(buf);
163  }
164 
165  for(size_t t = 0; t < fFullHitlist.size(); ++t){
166  for(unsigned int ip=0;ip<nplanes;ip++) {
167  for(size_t xx = 0; xx < fSelectedHitlist[ip].size(); ++xx){
168  if(fFullHitlist[t]==fSelectedHitlist[ip][xx]) {
169  fRefinedHitlist[ip].push_back(fFullHitlist[t]);
170  break;
171  }
172  }
173 
174  if(fStartHit[ip] && fFullHitlist[t].get()==fStartHit[ip]){
175  fRefStartHit[ip]=const_cast<recob::Hit *>(fFullHitlist[t].get());
176  }
177 
178  if(fEndHit[ip] && fFullHitlist[t].get()==fEndHit[ip]){
179  fRefEndHit[ip]=const_cast<recob::Hit *>(fFullHitlist[t].get());
180  }
181 
182  }
183  }
184  //for(int ip=0;ip<nplanes;ip++)
185  // FillStartEndHitCoords(ip);
186 
187  fSelectedHitlist.clear();
189 
190  return;
191  }
192 
193  //......................................................................
194  void InfoTransfer::SetSeedList(std::vector < util::PxLine > seedlines)
195  {
196  fSeedList=seedlines;
197  }
198 
199 
200  //......................................................................
201  std::vector < util::PxLine > InfoTransfer::GetSeedList()
202  {
203  return fSeedList;
204  }
205 
206 
207  //......................................................................
208  void InfoTransfer::FillStartEndHitCoords(unsigned int plane)
209  {
210 
212  // std::vector <double> sthitout(2);
213  if(fRefStartHit[plane]){
214  starthitout[plane][1] = fRefStartHit[plane]->PeakTime() ;
215  try{
216  if(fRefStartHit[plane]->WireID().isValid){
217  starthitout[plane][0] = fRefStartHit[plane]->WireID().Wire;
218  }
219  else{
220  starthitout[plane][0]=0;
221  }
222  }
223  catch(cet::exception &e) {
224  mf::LogWarning("GraphCluster") << "caught exception \n"
225  << e;
226  starthitout[plane][0]=0;
227  }
228  }
229  else{
230  starthitout[plane][1]=0.;
231  starthitout[plane][0]=0.;
232  }
233 
234 
235  if(fRefEndHit[plane]){
236  endhitout[plane][1] = fRefEndHit[plane]->PeakTime() ;
237  try{
238  if(fRefEndHit[plane]->WireID().isValid){
239  endhitout[plane][0] = fRefEndHit[plane]->WireID().Wire;
240  }
241  else{
242  endhitout[plane][0]=0;
243  }
244  }
245  catch(cet::exception &e) {
246  mf::LogWarning("GraphCluster") << "caught exception \n"
247  << e;
248  endhitout[plane][0]=0;
249  }
250  }
251  else{
252  endhitout[plane][1]=0.;
253  endhitout[plane][0]=0.;
254  }
255 
256 
257  }
258 
259 }//namespace
260 
261 namespace evd {
262 
264 
265 } // namespace evd
266 ////////////////////////////////////////////////////////////////////////
267 
268 
269 ////////////////////////////////////////////////////////////////////////
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()
Handle< PROD > getHandle(SelectorBase const &) const
Definition: DataViewImpl.h:382
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
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
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
GlobalSignal< detail::SignalResponseType::FIFO, void(Event const &, ScheduleContext)> sPreProcessEvent
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
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
std::vector< util::PxLine > fSeedList
Definition: InfoTransfer.h:134