LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
MergeWireCell_module.cc
Go to the documentation of this file.
1 // Class: MergeWireCell
3 // Module Type: producer
4 // File: MergeWireCell_module.cc
5 //
6 // Generated at Sat Sep 5 12:50:05 2015 by Tingjun Yang using artmod
7 // from cetpkgsupport v1_08_06.
9 
17 #include "fhiclcpp/ParameterSet.h"
19 
26 
27 #include "TTree.h"
28 #include "TBranch.h"
29 #include "TLeaf.h"
30 #include "TFile.h"
31 
32 #include <memory>
33 #include <string>
34 #include <dirent.h>
35 #include <iostream>
36 
37 namespace wc {
38  class MergeWireCell;
39 }
40 
42 public:
43  explicit MergeWireCell(fhicl::ParameterSet const & p);
44  // The destructor generated by the compiler is fine for classes
45  // without bare pointers or other resource use.
46 
47  // Plugins should not be copied or assigned.
48  MergeWireCell(MergeWireCell const &) = delete;
49  MergeWireCell(MergeWireCell &&) = delete;
50  MergeWireCell & operator = (MergeWireCell const &) = delete;
52 
53  // Required functions.
54  void produce(art::Event & e) override;
55 
56  // Selected optional functions.
57  void beginJob() override;
58  void reconfigure(fhicl::ParameterSet const & p) ;
59 
60  // Make recob::Tracks
62  std::unique_ptr<std::vector<recob::Track>> &trk_coll,
63  std::unique_ptr<art::Assns<recob::Track, recob::Hit>> &trkhassn,
64  std::unique_ptr<art::Assns<recob::Track, recob::SpacePoint>> &trksassn,
65  std::unique_ptr<std::vector<recob::Hit>> &hit_coll,
66  std::unique_ptr<std::vector<recob::SpacePoint>> &spt_coll,
67  std::vector<int> &index,
68  TTree *tree);
69 
70  // Make recob::Showers
71  void MakeShowers(art::Event &evt,
72  std::unique_ptr<std::vector<recob::Shower>> &shw_coll,
73  std::unique_ptr<art::Assns<recob::Shower, recob::Hit>> &shwhassn,
74  std::unique_ptr<art::Assns<recob::Shower, recob::SpacePoint>> &shwsassn,
75  std::unique_ptr<std::vector<recob::Hit>> &hit_coll,
76  std::unique_ptr<std::vector<recob::SpacePoint>> &spt_coll,
77  std::vector<int> &index,
78  TTree *tree);
79 
80 private:
81 
82  // Declare member data here.
83  std::string fInput;
84 
85  static constexpr float Sqrt2Pi = 2.5066;
86  static constexpr float SqrtPi = 1.7725;
87 
88 };
89 
90 
92  fInput(p.get<std::string>("WireCellInput"))
93 {
94  // Call appropriate produces<>() functions here.
95  produces<std::vector<recob::Hit> >();
96  produces<std::vector<recob::SpacePoint> >();
97  produces<art::Assns<recob::Hit, recob::SpacePoint> >();
98  produces<std::vector<recob::Track> >();
99  produces<std::vector<recob::Shower> >();
100  produces<art::Assns<recob::Track, recob::Hit> >();
101  produces<art::Assns<recob::Track, recob::SpacePoint> >();
102  produces<art::Assns<recob::Shower, recob::Hit> >();
103  produces<art::Assns<recob::Shower, recob::SpacePoint> >();
104 }
105 
107 
109 
110  int run = evt.run();
111  int subrun = evt.subRun();
112  int event = evt.id().event();
113 
114  std::unique_ptr<std::vector<recob::Hit>> hit_coll(new std::vector<recob::Hit>);
115  std::unique_ptr<std::vector<recob::SpacePoint>> spt_coll(new std::vector<recob::SpacePoint>);
116  std::unique_ptr<art::Assns<recob::SpacePoint, recob::Hit> > shassn(new art::Assns<recob::SpacePoint, recob::Hit>);
117  std::unique_ptr<std::vector<recob::Track>> trk_coll(new std::vector<recob::Track>);
118  std::unique_ptr<art::Assns<recob::Track, recob::Hit>> trkhassn(new art::Assns<recob::Track, recob::Hit>);
119  std::unique_ptr<art::Assns<recob::Track, recob::SpacePoint>> trksassn(new art::Assns<recob::Track, recob::SpacePoint>);
120  std::unique_ptr<std::vector<recob::Shower>> shw_coll(new std::vector<recob::Shower>);
121  std::unique_ptr<art::Assns<recob::Shower, recob::Hit>> shwhassn(new art::Assns<recob::Shower, recob::Hit>);
122  std::unique_ptr<art::Assns<recob::Shower, recob::SpacePoint>> shwsassn(new art::Assns<recob::Shower, recob::SpacePoint>);
123 
124  std::string path(fInput);
125  path=(path+"/");
126 
127  DIR *pDIR;
128  struct dirent *entry;
129  if( (pDIR=opendir(path.c_str())) != NULL ){
130 
131  while((entry = readdir(pDIR)) != NULL){
132 
133  if( strcmp(entry->d_name, ".")==0 || strcmp(entry->d_name, "..")==00) continue;
134 
135  std::string filename(entry->d_name);
136  if((int)filename.find(".root")==-1)
137  continue;
138 
139  std::string file = (path + entry->d_name);
140  TFile *f = new TFile(file.c_str());
141  TTree *Trun = (TTree*)f->Get("Trun");
142  int eventNo, runNo, subRunNo;
143  Trun->SetBranchAddress("eventNo",&eventNo);
144  Trun->SetBranchAddress("runNo",&runNo);
145  Trun->SetBranchAddress("subRunNo",&subRunNo);
146  if (!Trun->GetEntries()) continue;
147  Trun->GetEntry(0);
148  //std::cout<<run<<" "<<subrun<<" "<<event<<" "<<runNo<<" "<<subRunNo<<" "<<eventNo<<std::endl;
149  if (runNo!=run||eventNo!=event||subRunNo!=subrun) {
150  f->Close();
151  continue;
152  }
153  TTree *TC = (TTree*)f->Get("TC");
154  Int_t time_slice;
155  Double_t charge;
156  Double_t xx;
157  Double_t yy;
158  Double_t zz;
159  Int_t u_index;
160  Int_t v_index;
161  Int_t w_index;
162  Double_t u_charge;
163  Double_t v_charge;
164  Double_t w_charge;
165  Double_t u_charge_err;
166  Double_t v_charge_err;
167  Double_t w_charge_err;
168  Int_t tpc_no;
169  Int_t cryostat_no;
170  Int_t mcell_id;
171 
172  TC->SetBranchAddress("time_slice", &time_slice);
173  TC->SetBranchAddress("charge", &charge);
174  TC->SetBranchAddress("xx", &xx);
175  TC->SetBranchAddress("yy", &yy);
176  TC->SetBranchAddress("zz", &zz);
177  TC->SetBranchAddress("u_index", &u_index);
178  TC->SetBranchAddress("v_index", &v_index);
179  TC->SetBranchAddress("w_index", &w_index);
180  TC->SetBranchAddress("u_charge", &u_charge);
181  TC->SetBranchAddress("v_charge", &v_charge);
182  TC->SetBranchAddress("w_charge", &w_charge);
183  TC->SetBranchAddress("u_charge_err", &u_charge_err);
184  TC->SetBranchAddress("v_charge_err", &v_charge_err);
185  TC->SetBranchAddress("w_charge_err", &w_charge_err);
186  TC->SetBranchAddress("cryostat_no", &cryostat_no);
187  TC->SetBranchAddress("mcell_id",&mcell_id);
188 
189  TC->GetDirectory()->Print();
190 
191 // TC->SetBranchAddress("cell.tpc_no", &tpc_no);
192 
193  TObjArray* leafList = TC->GetListOfLeaves();
194 
195  for(int idx = 0; idx < leafList->GetEntries(); idx++)
196  {
197  leafList->At(idx)->Print();
198  }
199 
200  TObject* candObj = leafList->FindObject("tpc_no");
201 
202  std::cout << "candObj: " << candObj << std::endl;
203 
204  TLeaf* candLeaf = (TLeaf*)candObj;
205  candLeaf->Print();
206  candLeaf->SetAddress(&tpc_no);
207 
208  std::vector<int> vcell_id;
209 
210  for (int i = 0; i<TC->GetEntries(); ++i){
211  TC->GetEntry(i);
212 
213  tpc_no = candLeaf->GetTypedValue<Int_t>(i) - 1;
214 
215  vcell_id.push_back(mcell_id);
216  double xyz[3] = {xx,yy,zz};
217  double err[3] = {0,0,0};
218  spt_coll->push_back(recob::SpacePoint(xyz,err,charge));
219  geo::WireID wireu(cryostat_no,tpc_no,0,u_index);
220  raw::ChannelID_t chanu = geom->PlaneWireToChannel(wireu);
221  geo::WireID wirev(cryostat_no,tpc_no,1,v_index);
222  raw::ChannelID_t chanv = geom->PlaneWireToChannel(wirev);
223  geo::WireID wirew(cryostat_no,tpc_no,2,w_index);
224  raw::ChannelID_t chanw = geom->PlaneWireToChannel(wirew);
225  size_t hitStart = hit_coll->size();
226 // raw::TDCtick_t start_tick = time_slice*4;
227 // raw::TDCtick_t end_tick = (time_slice+1)*4;
228 // float peak_time = (time_slice+0.5)*4;
229 // float sigma_peak = 2.0;
230 // float rms = 2.0;
231 // float peak_ampu = u_charge/(Sqrt2Pi*2);
232 // float sigma_peak_a
233  hit_coll->push_back(recob::Hit(chanu,
234  time_slice*4,
235  (time_slice+1)*4,
236  (time_slice+0.5)*4,
237  2.,
238  2.,
239  u_charge/(Sqrt2Pi*2),
240  u_charge_err/(Sqrt2Pi*2),
241  u_charge,
242  u_charge,
243  u_charge_err,
244  1,
245  0,
246  0,
247  0,
248  geom->View(chanu),
249  geom->SignalType(chanu),
250  wireu));
251  hit_coll->push_back(recob::Hit(chanv,
252  time_slice*4,
253  (time_slice+1)*4,
254  (time_slice+0.5)*4,
255  2.,
256  2.,
257  v_charge/(Sqrt2Pi*2),
258  v_charge_err/(Sqrt2Pi*2),
259  v_charge,
260  v_charge,
261  v_charge_err,
262  1,
263  0,
264  0,
265  0,
266  geom->View(chanv),
267  geom->SignalType(chanv),
268  wirev));
269  hit_coll->push_back(recob::Hit(chanw,
270  time_slice*4,
271  (time_slice+1)*4,
272  (time_slice+0.5)*4,
273  2.,
274  2.,
275  w_charge/(Sqrt2Pi*2),
276  w_charge_err/(Sqrt2Pi*2),
277  w_charge,
278  w_charge,
279  w_charge_err,
280  1,
281  0,
282  0,
283  0,
284  geom->View(chanw),
285  geom->SignalType(chanw),
286  wirew));
287  size_t hitEnd = hit_coll->size();
288  util::CreateAssn(*this, evt, *spt_coll, *hit_coll, *shassn, hitStart, hitEnd);
289  }//Loop over TC
290 /*
291  TTree *T_goodtrack = (TTree*)f->Get("T_goodtrack");
292  MakeTracks(evt, trk_coll, trkhassn, trksassn, hit_coll, spt_coll, vcell_id, T_goodtrack);
293  TTree *T_shorttrack = (TTree*)f->Get("T_shorttrack");
294  MakeTracks(evt, trk_coll, trkhassn, trksassn, hit_coll, spt_coll, vcell_id, T_shorttrack);
295  TTree *T_paratrack = (TTree*)f->Get("T_paratrack");
296  MakeTracks(evt, trk_coll, trkhassn, trksassn, hit_coll, spt_coll, vcell_id, T_paratrack);
297 
298  TTree *T_shower = (TTree*)f->Get("T_shower");
299  MakeShowers(evt, shw_coll, shwhassn, shwsassn, hit_coll, spt_coll, vcell_id, T_shower);
300 */
301  f->Close();
302  break;
303  }
304  closedir(pDIR);
305 
306  }
307 
308  std::cout << "space point size: " << spt_coll->size() << ", hit coll size: " << hit_coll->size() << std::endl;
309 
310  evt.put(std::move(spt_coll));
311  evt.put(std::move(hit_coll));
312  evt.put(std::move(shassn));
313  evt.put(std::move(trk_coll));
314  evt.put(std::move(trkhassn));
315  evt.put(std::move(trksassn));
316  evt.put(std::move(shw_coll));
317  evt.put(std::move(shwhassn));
318  evt.put(std::move(shwsassn));
319 }
320 
322  std::unique_ptr<std::vector<recob::Track>> &trk_coll,
323  std::unique_ptr<art::Assns<recob::Track, recob::Hit>> &trkhassn,
324  std::unique_ptr<art::Assns<recob::Track, recob::SpacePoint>> &trksassn,
325  std::unique_ptr<std::vector<recob::Hit>> &hit_coll,
326  std::unique_ptr<std::vector<recob::SpacePoint>> &spt_coll,
327  std::vector<int> &index,
328  TTree *tree){
329  Int_t npoints;
330  Int_t trackid;
331  Int_t msc_id[1000]; //[npoints]
332  Double_t x[1000]; //[npoints]
333  Double_t y[1000]; //[npoints]
334  Double_t z[1000]; //[npoints]
335  Double_t theta[1000]; //[npoints]
336  Double_t phi[1000]; //[npoints]
337 
338  tree->SetBranchAddress("npoints", &npoints);
339  tree->SetBranchAddress("trackid", &trackid);
340  tree->SetBranchAddress("msc_id", msc_id);
341  tree->SetBranchAddress("x", x);
342  tree->SetBranchAddress("y", y);
343  tree->SetBranchAddress("z", z);
344  tree->SetBranchAddress("theta", theta);
345  tree->SetBranchAddress("phi", phi);
346 
347  Long64_t nentries = tree->GetEntriesFast();
348 
349  for (Long64_t i=0; i<nentries; ++i) {
350  tree->GetEntry(i);
351  std::vector<recob::tracking::Point_t> xyz;
352  std::vector<recob::tracking::Vector_t> dircos;
353  std::vector<size_t> hits;
354  std::vector<size_t> spts;
355  for (int i = 0; i<npoints; ++i){
356  xyz.emplace_back(x[i],y[i],z[i]);
357  dircos.emplace_back(sin(theta[i])*cos(phi[i]),sin(theta[i])*sin(phi[i]),cos(theta[i]));
358  for (size_t j = 0; j<index.size(); ++j){
359  if (index[j]==msc_id[i]){
360  spts.push_back(j);
361  hits.push_back(3*j);
362  hits.push_back(3*j+1);
363  hits.push_back(3*j+2);
364  }
365  }
366  }
367  trk_coll->push_back(recob::Track(recob::TrackTrajectory(std::move(xyz), std::move(dircos), recob::Track::Flags_t(xyz.size()), false),
369  // make associations between the track and space points
370  util::CreateAssn(*this, evt, *trk_coll, *spt_coll, *trksassn, spts);
371  // make associations between the track and hits
372  util::CreateAssn(*this, evt, *trk_coll, *hit_coll, *trkhassn, hits);
373  }
374 }
375 
377  std::unique_ptr<std::vector<recob::Shower>> &shw_coll,
378  std::unique_ptr<art::Assns<recob::Shower, recob::Hit>> &shwhassn,
379  std::unique_ptr<art::Assns<recob::Shower, recob::SpacePoint>> &shwsassn,
380  std::unique_ptr<std::vector<recob::Hit>> &hit_coll,
381  std::unique_ptr<std::vector<recob::SpacePoint>> &spt_coll,
382  std::vector<int> &index,
383  TTree *tree){
384  Int_t npoints;
385  Int_t showerid;
386  Int_t msc_id[1000]; //[npoints]
387 
388  tree->SetBranchAddress("npoints", &npoints);
389  tree->SetBranchAddress("showerid", &showerid);
390  tree->SetBranchAddress("msc_id", msc_id);
391 
392  Long64_t nentries = tree->GetEntriesFast();
393 
394  for (Long64_t i=0; i<nentries; ++i) {
395  tree->GetEntry(i);
396  TVector3 v1(0,0,0);
397  std::vector< double > tmp(2, util::kBogusD);
398  int bestplane = -1;
399  std::vector<size_t> hits;
400  std::vector<size_t> spts;
401  for (int i = 0; i<npoints; ++i){
402  for (size_t j = 0; j<index.size(); ++j){
403  if (index[j]==msc_id[i]){
404  spts.push_back(j);
405  hits.push_back(3*j);
406  hits.push_back(3*j+1);
407  hits.push_back(3*j+2);
408  }
409  }
410  }
411  shw_coll->push_back(recob::Shower(v1, v1, v1, v1, tmp, tmp, tmp, tmp, bestplane, showerid));
412  // make associations between the track and space points
413  util::CreateAssn(*this, evt, *shw_coll, *spt_coll, *shwsassn, spts);
414  // make associations between the track and hits
415  util::CreateAssn(*this, evt, *shw_coll, *hit_coll, *shwhassn, hits);
416  }
417 }
418 
420 {
421  // Implementation of optional member function here.
422 }
423 
425 {
426  // Implementation of optional member function here.
427 }
428 
Float_t x
Definition: compare.C:6
SubRunNumber_t subRun() const
Definition: Event.h:72
Double_t xx
Definition: macro.C:12
void MakeTracks(art::Event &evt, std::unique_ptr< std::vector< recob::Track >> &trk_coll, std::unique_ptr< art::Assns< recob::Track, recob::Hit >> &trkhassn, std::unique_ptr< art::Assns< recob::Track, recob::SpacePoint >> &trksassn, std::unique_ptr< std::vector< recob::Hit >> &hit_coll, std::unique_ptr< std::vector< recob::SpacePoint >> &spt_coll, std::vector< int > &index, TTree *tree)
ROOT::Math::SMatrix< Double32_t, 5, 5, ROOT::Math::MatRepSym< Double32_t, 5 > > SMatrixSym55
Definition: TrackingTypes.h:85
Declaration of signal hit object.
Float_t y
Definition: compare.C:6
Double_t z
Definition: plot.C:279
MergeWireCell(fhicl::ParameterSet const &p)
TrackTrajectory::Flags_t Flags_t
Definition: Track.h:71
STL namespace.
Double_t zz
Definition: plot.C:279
Float_t tmp
Definition: plot.C:37
SigType_t SignalType(geo::PlaneID const &pid) const
Returns the type of signal on the channels of specified TPC plane.
void beginJob() override
TFile f
Definition: plotHisto.C:6
void reconfigure(fhicl::ParameterSet const &p)
ProductID put(std::unique_ptr< PROD > &&product)
Definition: Event.h:102
void hits()
Definition: readHits.C:15
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:42
Provides recob::Track data product.
static constexpr float SqrtPi
A trajectory in space reconstructed from hits.
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.
void produce(art::Event &e) override
View_t View(geo::PlaneID const &pid) const
Returns the view (wire orientation) on the channels of specified TPC plane.
Int_t nentries
Definition: comparison.C:29
raw::ChannelID_t PlaneWireToChannel(WireID const &wireid) const
Returns the ID of the TPC channel connected to the specified wire.
Utility object to perform functions of association.
TFile * file
EventNumber_t event() const
Definition: EventID.h:117
constexpr double kBogusD
obviously bogus double value
2D representation of charge deposited in the TDC/wire plane
Definition: Hit.h:49
TCEvent evt
Definition: DataStructs.cxx:5
unsigned int ChannelID_t
Type representing the ID of a readout channel.
Definition: RawTypes.h:27
Float_t e
Definition: plot.C:34
RunNumber_t run() const
Definition: Event.h:77
static constexpr float Sqrt2Pi
EventID id() const
Definition: Event.h:56
void MakeShowers(art::Event &evt, std::unique_ptr< std::vector< recob::Shower >> &shw_coll, std::unique_ptr< art::Assns< recob::Shower, recob::Hit >> &shwhassn, std::unique_ptr< art::Assns< recob::Shower, recob::SpacePoint >> &shwsassn, std::unique_ptr< std::vector< recob::Hit >> &hit_coll, std::unique_ptr< std::vector< recob::SpacePoint >> &spt_coll, std::vector< int > &index, TTree *tree)
art framework interface to geometry description
Track from a non-cascading particle.A recob::Track consists of a recob::TrackTrajectory, plus additional members relevant for a "fitted" track:
Definition: Track.h:52
Event finding and building.
MergeWireCell & operator=(MergeWireCell const &)=delete