LArSoft  v06_85_00
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
61  void MakeTracks(art::Event &evt,
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<TVector3> xyz;
352  std::vector<TVector3> dircos;
353  std::vector< std::vector<double> > dQdx;
354  std::vector<double> mom(2, util::kBogusD);
355  std::vector<size_t> hits;
356  std::vector<size_t> spts;
357  for (int i = 0; i<npoints; ++i){
358  xyz.push_back(TVector3(x[i],y[i],z[i]));
359  dircos.push_back(TVector3(sin(theta[i])*cos(phi[i]),sin(theta[i])*sin(phi[i]),cos(theta[i])));
360  for (size_t j = 0; j<index.size(); ++j){
361  if (index[j]==msc_id[i]){
362  spts.push_back(j);
363  hits.push_back(3*j);
364  hits.push_back(3*j+1);
365  hits.push_back(3*j+2);
366  }
367  }
368  }
369  trk_coll->push_back(recob::Track(xyz, dircos, dQdx, mom, trackid));
370  // make associations between the track and space points
371  util::CreateAssn(*this, evt, *trk_coll, *spt_coll, *trksassn, spts);
372  // make associations between the track and hits
373  util::CreateAssn(*this, evt, *trk_coll, *hit_coll, *trkhassn, hits);
374  }
375 }
376 
378  std::unique_ptr<std::vector<recob::Shower>> &shw_coll,
379  std::unique_ptr<art::Assns<recob::Shower, recob::Hit>> &shwhassn,
380  std::unique_ptr<art::Assns<recob::Shower, recob::SpacePoint>> &shwsassn,
381  std::unique_ptr<std::vector<recob::Hit>> &hit_coll,
382  std::unique_ptr<std::vector<recob::SpacePoint>> &spt_coll,
383  std::vector<int> &index,
384  TTree *tree){
385  Int_t npoints;
386  Int_t showerid;
387  Int_t msc_id[1000]; //[npoints]
388 
389  tree->SetBranchAddress("npoints", &npoints);
390  tree->SetBranchAddress("showerid", &showerid);
391  tree->SetBranchAddress("msc_id", msc_id);
392 
393  Long64_t nentries = tree->GetEntriesFast();
394 
395  for (Long64_t i=0; i<nentries; ++i) {
396  tree->GetEntry(i);
397  TVector3 v1(0,0,0);
398  std::vector< double > tmp(2, util::kBogusD);
399  int bestplane = -1;
400  std::vector<size_t> hits;
401  std::vector<size_t> spts;
402  for (int i = 0; i<npoints; ++i){
403  for (size_t j = 0; j<index.size(); ++j){
404  if (index[j]==msc_id[i]){
405  spts.push_back(j);
406  hits.push_back(3*j);
407  hits.push_back(3*j+1);
408  hits.push_back(3*j+2);
409  }
410  }
411  }
412  shw_coll->push_back(recob::Shower(v1, v1, v1, v1, tmp, tmp, tmp, tmp, bestplane, showerid));
413  // make associations between the track and space points
414  util::CreateAssn(*this, evt, *shw_coll, *spt_coll, *shwsassn, spts);
415  // make associations between the track and hits
416  util::CreateAssn(*this, evt, *shw_coll, *hit_coll, *shwhassn, hits);
417  }
418 }
419 
421 {
422  // Implementation of optional member function here.
423 }
424 
426 {
427  // Implementation of optional member function here.
428 }
429 
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)
Declaration of signal hit object.
Float_t y
Definition: compare.C:6
Double_t z
Definition: plot.C:279
MergeWireCell(fhicl::ParameterSet const &p)
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
static constexpr float SqrtPi
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
Provides recob::Track data product.
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
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:51
Event finding and building.
MergeWireCell & operator=(MergeWireCell const &)=delete