All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
InfoTransfer.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 
11 
16 
17 #include "nuevdb/EventDisplayBase/NavState.h"
18 
19 // Framework includes
20 #include "art/Framework/Principal/Event.h"
21 #include "art/Framework/Principal/Handle.h"
22 #include "art/Framework/Services/Registry/ActivityRegistry.h"
23 #include "art/Framework/Services/Registry/ServiceHandle.h"
24 #include "canvas/Persistency/Common/Ptr.h"
25 #include "messagefacility/MessageLogger/MessageLogger.h"
26 
27 
28 namespace{
29  void WriteMsg(const char* fcn)
30  {
31  mf::LogWarning("InfoTransfer") << "InfoTransfer::" << fcn << " \n";
32  }
33 }
34 
35 namespace evd {
36 
37  //......................................................................
38  InfoTransfer::InfoTransfer(fhicl::ParameterSet const& pset,
39  art::ActivityRegistry& reg)
40  : evdb::Reconfigurable{pset}
41  {
42  this->reconfigure(pset);
43  testflag=-1;
44  fEvt=-1;
45  fRun=-1;
46  fSubRun=-1;
47  reg.sPreProcessEvent.watch(this, &InfoTransfer::Rebuild);
48  art::ServiceHandle<geo::Geometry const> geo;
49  unsigned int nplanes = geo->Nplanes();
50 
51  fSelectedHitlist.resize(nplanes);
52  fStartHit.resize(nplanes);
53  fRefStartHit.resize(nplanes);
54  fEndHit.resize(nplanes);
55  fRefEndHit.resize(nplanes);
56  starthitout.resize(nplanes);
57  endhitout.resize(nplanes);
58  refstarthitout.resize(nplanes);
59  refendhitout.resize(nplanes);
60  for(unsigned int i=0;i<nplanes;i++){
61  starthitout[i].resize(2);
62  endhitout[i].resize(2);
63  refstarthitout[i].resize(2);
64  refendhitout[i].resize(2);
65  }
66  // hitlist=NULL;
67  }
68 
69  //......................................................................
71  {
72  }
73 
74  //......................................................................
75  void InfoTransfer::reconfigure(fhicl::ParameterSet const& pset)
76  {
77  art::ServiceHandle<geo::Geometry const> geo;
78  unsigned int nplanes = geo->Nplanes();
79  //clear everything
80  fRefinedHitlist.resize(nplanes);
81  fSelectedHitlist.resize(nplanes);
82  for (unsigned int i=0;i<nplanes;i++){
83  fRefinedHitlist[i].clear();
84  fSelectedHitlist[i].clear();
85  }
86  fHitModuleLabel = pset.get<std::string>("HitModuleLabel", "ffthit");
87  }
88 
89 
90 
91  //......................................................................
92  void InfoTransfer::Rebuild(const art::Event& evt, art::ScheduleContext)
93  {
94  art::ServiceHandle<geo::Geometry const> geo;
95  unsigned int nplanes = geo->Nplanes();
96  unsigned int which_call=evdb::NavState::Which();
97  if(which_call!=2){
98  //unless we're reloading we want to clear all the selected and refined hits
99  fRefinedHitlist.resize(nplanes);
100  fSelectedHitlist.resize(nplanes);
101  for(unsigned int j=0; j<nplanes;j++){
102  fRefinedHitlist[j].clear();
103  fSelectedHitlist[j].clear();
104  starthitout[j].clear();
105  endhitout[j].clear();
106  starthitout[j].resize(2);
107  endhitout[j].resize(2);
108  refstarthitout[j].clear();
109  refendhitout[j].clear();
110  refstarthitout[j].resize(2);
111  refendhitout[j].resize(2);
112  }
113  //also clear start and end points
114  fRefStartHit.clear();
115  fRefEndHit.clear();
116  fFullHitlist.clear();
117  }
118  art::Handle< std::vector<recob::Hit> > hHandle;
119 
120  fEvt=evt.id().event();
121  fRun=evt.id().run();
122  fSubRun=evt.id().subRun();
123  evt.getByLabel(fHitModuleLabel, hHandle);
124 
125  if(hHandle.failedToGet()){
126 // mf::LogWarning("InfoTransfer") << "failed to get handle to std::vector<recob::Hit> from "<< fHitModuleLabel;
127  return;
128  }
129 
130  // Clear out anything remaining from previous calls to Rebuild
131 
132  fRefinedHitlist.resize(nplanes);
133 
134  for(unsigned int i=0;i<nplanes;i++){
135  fRefinedHitlist[i].clear(); ///< the refined hitlist after rebuild
136  }
137 
138 
139  fFullHitlist.clear();
140  for(unsigned int i=0; i<fRefStartHit.size(); i++){
141  fRefStartHit[i]=NULL;
142  fRefEndHit[i]=NULL;
143  }
144 
145  /////Store start and end hits in new lists and clear the old ones:
146  for(unsigned int i=0;i<nplanes;i++ )
147  { refstarthitout[i].clear();
148  refendhitout[i].clear();
149  refstarthitout[i].resize(2);
150  refendhitout[i].resize(2);
151 
153  refendhitout[i]=endhitout[i];
154 
155  starthitout[i].clear();
156  endhitout[i].clear();
157  starthitout[i].resize(2);
158  endhitout[i].resize(2);
159  }
160 
161  for(size_t p = 0; p < hHandle->size(); ++p){
162  art::Ptr<recob::Hit> hit(hHandle, p);
163  fFullHitlist.push_back(hit);
164  }
165 
166  // fill the selected Hits into the fRefinedHitList from the fSelectedHitList
167  char buf[200];
168  for(unsigned int j=0; j<nplanes; j++){
169  sprintf(buf," ++++rebuilding with %lu selected hits in plane %u \n", fSelectedHitlist[j].size(),j);
170  WriteMsg(buf);
171  }
172 
173  for(size_t t = 0; t < fFullHitlist.size(); ++t){
174  for(unsigned int ip=0;ip<nplanes;ip++) {
175  for(size_t xx = 0; xx < fSelectedHitlist[ip].size(); ++xx){
176  if(fFullHitlist[t]==fSelectedHitlist[ip][xx]) {
177  fRefinedHitlist[ip].push_back(fFullHitlist[t]);
178  break;
179  }
180  }
181 
182  if(fStartHit[ip] && fFullHitlist[t].get()==fStartHit[ip]){
183  fRefStartHit[ip]=const_cast<recob::Hit *>(fFullHitlist[t].get());
184  }
185 
186  if(fEndHit[ip] && fFullHitlist[t].get()==fEndHit[ip]){
187  fRefEndHit[ip]=const_cast<recob::Hit *>(fFullHitlist[t].get());
188  }
189 
190  }
191  }
192  //for(int ip=0;ip<nplanes;ip++)
193  // FillStartEndHitCoords(ip);
194 
195  fSelectedHitlist.clear();
197 
198  return;
199  }
200 
201  //......................................................................
202  void InfoTransfer::SetSeedList(std::vector < util::PxLine > seedlines)
203  {
204  fSeedList=seedlines;
205  }
206 
207 
208  //......................................................................
209  std::vector < util::PxLine > const& InfoTransfer::GetSeedList() const
210  {
211  return fSeedList;
212  }
213 
214 
215  //......................................................................
216  void InfoTransfer::FillStartEndHitCoords(unsigned int plane)
217  {
218 
219  art::ServiceHandle<geo::Geometry const> geo;
220  // std::vector <double> sthitout(2);
221  if(fRefStartHit[plane]){
222  starthitout[plane][1] = fRefStartHit[plane]->PeakTime() ;
223  try{
224  if(fRefStartHit[plane]->WireID().isValid){
225  starthitout[plane][0] = fRefStartHit[plane]->WireID().Wire;
226  }
227  else{
228  starthitout[plane][0]=0;
229  }
230  }
231  catch(cet::exception const& e) {
232  mf::LogWarning("GraphCluster") << "caught exception \n"
233  << e;
234  starthitout[plane][0]=0;
235  }
236  }
237  else{
238  starthitout[plane][1]=0.;
239  starthitout[plane][0]=0.;
240  }
241 
242 
243  if(fRefEndHit[plane]){
244  endhitout[plane][1] = fRefEndHit[plane]->PeakTime() ;
245  try{
246  if(fRefEndHit[plane]->WireID().isValid){
247  endhitout[plane][0] = fRefEndHit[plane]->WireID().Wire;
248  }
249  else{
250  endhitout[plane][0]=0;
251  }
252  }
253  catch(cet::exception const& e) {
254  mf::LogWarning("GraphCluster") << "caught exception \n"
255  << e;
256  endhitout[plane][0]=0;
257  }
258  }
259  else{
260  endhitout[plane][1]=0.;
261  endhitout[plane][0]=0.;
262  }
263 
264 
265  }
266 
267 }//namespace
268 ////////////////////////////////////////////////////////////////////////
void FillStartEndHitCoords(unsigned int plane)
InfoTransfer(fhicl::ParameterSet const &pset, art::ActivityRegistry &reg)
Definition: InfoTransfer.cc:38
Declaration of signal hit object.
std::vector< std::vector< double > > endhitout
Definition: InfoTransfer.h:146
pdgs p
Definition: selectors.fcl:22
std::size_t size(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:561
for pfile in ack l reconfigure(.*) override"` do echo "checking $
process_name hit
Definition: cheaterreco.fcl:51
std::vector< recob::Hit * > fStartHit
The Starthit.
Definition: InfoTransfer.h:137
std::vector< recob::Hit * > fRefStartHit
The Refined Starthit.
Definition: InfoTransfer.h:138
std::vector< std::vector< double > > refstarthitout
Definition: InfoTransfer.h:148
IDparameter< geo::WireID > WireID
Member type of validated geo::WireID parameter.
std::vector< recob::Hit * > fRefEndHit
The Refined Starthit.
Definition: InfoTransfer.h:141
std::vector< recob::Hit * > fEndHit
The Starthit.
Definition: InfoTransfer.h:140
std::vector< std::vector< art::Ptr< recob::Hit > > > fRefinedHitlist
the refined hitlist after rebuild (one for each plane)
Definition: InfoTransfer.h:133
std::string fHitModuleLabel
label for geant4 module
Definition: InfoTransfer.h:135
std::vector< std::vector< double > > starthitout
Definition: InfoTransfer.h:145
Definition of data types for geometry description.
std::vector< art::Ptr< recob::Hit > > fFullHitlist
the full Hit list from the Hitfinder.
Definition: InfoTransfer.h:134
void Rebuild(const art::Event &evt, art::ScheduleContext)
Definition: InfoTransfer.cc:92
std::vector< std::vector< art::Ptr< recob::Hit > > > fSelectedHitlist
the list selected by the GUI (one for each plane)
Definition: InfoTransfer.h:132
void SetSeedList(std::vector< util::PxLine > seedlines)
std::vector< std::vector< double > > refendhitout
Definition: InfoTransfer.h:149
do i e
std::vector< util::PxLine > const & GetSeedList() const
2D representation of charge deposited in the TDC/wire plane
Definition: Hit.h:48
TCEvent evt
Definition: DataStructs.cxx:8
void reconfigure(fhicl::ParameterSet const &pset)
Definition: InfoTransfer.cc:75
art framework interface to geometry description
std::vector< util::PxLine > fSeedList
Definition: InfoTransfer.h:143