LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
Landed_module.cc
Go to the documentation of this file.
1 // Class: EventDisplay
3 // Module Type: analyzer
4 // File: EventDisplay_module.cc
5 //
6 // Generated at Fri Aug 28 14:45:48 2015 by Matt Robinson using artmod
7 // from cetpkgsupport v1_08_06.
9 
17 #include "fhiclcpp/ParameterSet.h"
20 
21 //root
22 #include "TDatabasePDG.h"
23 #include "THashList.h"
24 #include "TCollection.h"
25 
26 //larsoft
36 
37 
38 //geant4
39 #include "Geant4/G4UImanager.hh"
40 #include "Geant4/G4RunManager.hh"
41 #include "Geant4/G4VisExecutive.hh"
42 #include "Geant4/QGSP_BERT.hh"
43 
44 //nusoft
49 
50 //system
51 #include <iostream>
52 #include <fstream>
53 #include <sqlite3.h>
54 #include <zlib.h>
55 
56 //local
57 #include "LandedSocket.h"
58 
59 namespace evd {
60  class Landed;
61 }
62 
63 class evd::Landed : public art::EDAnalyzer {
64 public:
65  explicit Landed(fhicl::ParameterSet const & p);
66 
67  // Plugins should not be copied or assigned.
68  Landed(Landed const &) = delete;
69  Landed(Landed &&) = delete;
70  Landed & operator = (Landed const &) = delete;
71  Landed & operator = (Landed &&) = delete;
72 
73  // Required functions.
74  void analyze(art::Event const & e) override;
75 
76  //optional functions
77  void beginJob() override;
78  void endJob() override;
79 
80 private:
81 
82  // Declare member data here.
85  //string containing gdml having ben simplified through root
86  std::string vrml_;
87  std::string outputFilename_;
88  std::string which_;
89  sqlite3* ppDb_;
90  std::vector<int> events_;
91 };
92 
93 
95  EDAnalyzer(p),
96  // More initializers here.
97  geom_(art::ServiceHandle<geo::Geometry>()),
98  sock_(art::ServiceHandle<LandedSocket>()),
99  outputFilename_(p.get<std::string>("outputFilename", "")),
100  which_(p.get<std::string>("which", "truth")),
101  ppDb_(nullptr),
102  events_(p.get<std::vector<int> >("events", std::vector<int>()))
103 {
104 
105  if (outputFilename_.empty() && !sock_->connect())
106  {
107  throw cet::exception("Landed") << "no output filename specified and unable to connect to LANDED app using local socket\n" <<
108  "please either specify a filename, or check LANDED is running and that you have started the server\n";
109 
110  }
111  // sock_->hello();
112 
113  std::string gdml=geom_->GDMLFile();
114 
115  // g4b::G4Helper* g4helper=new g4b::G4Helper();
116  // g4helper->ConstructDetector(gdml_);
117  // g4helper->InitPhysics();
118  G4RunManager* runManager=new G4RunManager;
119  runManager->SetUserInitialization(new g4b::DetectorConstruction(gdml));
120  runManager->SetUserInitialization(new QGSP_BERT);
121  // Visualization manager construction
122  G4VisManager* visManager = new G4VisExecutive;
123  visManager->Initialize();
124 
125  char tmpdir[1024];
126  strcpy(tmpdir, "/tmp/vcXXXXXX");
127  mkdtemp(tmpdir);
128  strcat(tmpdir, "/");
129  char* vrmlviewer=getenv("G4VRMLFILE_VIEWER");
130  if (vrmlviewer)
131  unsetenv("G4VRMLFILE_VIEWER");
132  char* oldvrmldir=getenv("G4VRMLFILE_DEST_DIR");
133  setenv("G4VRMLFILE_DEST_DIR", tmpdir, 1);
134  G4UImanager* UImanager = G4UImanager::GetUIpointer();
135  UImanager->ApplyCommand("/run/initialize");
136  UImanager->ApplyCommand("/vis/open VRML2FILE");
137  UImanager->ApplyCommand("/vis/drawVolume");
138  UImanager->ApplyCommand("/vis/viewer/flush");
139  if (oldvrmldir)
140  setenv("G4VRMLFILE_DEST_DIR", oldvrmldir, 1);
141  else
142  unsetenv("G4VRMLFILE_DEST_DIR");
143  if (vrmlviewer)
144  setenv("G4VRMLFILE_VIEWER", vrmlviewer, 1);
145 
146  char tmpname[1024];
147  strcpy(tmpname, tmpdir);
148  strcat(tmpname, "g4_00.wrl");
149  std::ifstream geofile(tmpname);
150  std::stringstream geodata;
151  geodata << geofile.rdbuf();
152  geofile.close();
153  ::remove(tmpname);
154  ::remove(tmpdir);
155  vrml_=geodata.str();
156 
157  // std::cout << "!!!!!!! " << geodata.str().length() << std::endl;
158  // std::cout << geodata.str() << std::endl;
159 
160 }
161 
163 {
164 
165  if (!outputFilename_.empty())
166  {
167  //compress geometry
168  uLongf complen=compressBound(vrml_.length());
169  Bytef* comp=new Bytef[complen];
170  if (compress(comp, &complen, (const Bytef*)vrml_.c_str(), vrml_.length())!=Z_OK)
171  throw cet::exception("Landed") << "failed to compress geometry vrml\n";
172 
173  //create sqlite output file, compress and store gdml geometry
174  //create sqlite output file
175  ::remove(outputFilename_.c_str());
176  if (sqlite3_open_v2(outputFilename_.c_str(), &ppDb_, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, "unix")!=SQLITE_OK)
177  throw cet::exception("Landed") << "failed to create sqlite file\n";
178  sqlite3_stmt* stmt;
179  char * sErrMsg = 0;
180  sqlite3_exec(ppDb_, "PRAGMA synchronous = OFF", NULL, NULL, &sErrMsg);
181 
182 
183  //create geometry table
184  if (sqlite3_prepare(ppDb_, "CREATE TABLE Geometry ( vrml BLOB, size INT );", 100, &stmt, nullptr)!=SQLITE_OK)
185  throw cet::exception("Landed") << "failed to create geometry table on prepare\n";
186  if (sqlite3_step(stmt)!=SQLITE_DONE)
187  throw cet::exception("Landed") << "failed to create geometry table on step\n";
188  if (sqlite3_finalize(stmt)!=SQLITE_OK)
189  throw cet::exception("Landed") << "failed to create geometry table on finalize\n";
190  //store geometry
191  if (sqlite3_prepare(ppDb_, "INSERT INTO Geometry ( vrml, size ) VALUES ( ?, ? );", -1, &stmt, nullptr)!=SQLITE_OK)
192  throw cet::exception("Landed") << "failed to fill geometry table on prepare\n";
193  if (sqlite3_bind_blob(stmt, 1, comp, complen, SQLITE_STATIC)!=SQLITE_OK ||
194  sqlite3_bind_int(stmt, 2, vrml_.length())!=SQLITE_OK)
195  throw cet::exception("Landed") << "failed to fill geometry table on bind\n";
196  if (sqlite3_step(stmt)!=SQLITE_DONE)
197  throw cet::exception("Landed") << "failed to fill geometry table on step\n";
198  if (sqlite3_finalize(stmt)!=SQLITE_OK)
199  throw cet::exception("Landed") << "failed to fill geometry table on finalize\n";
200  delete[] comp;
201 
202  //create events table
203  if (sqlite3_prepare(ppDb_, "CREATE TABLE Events ( RunNumber INT, SubRunNumber INT, EventNumber INT);", 200, &stmt, nullptr)!=SQLITE_OK)
204  throw cet::exception("Landed") << "failed to create events table on prepare\n";
205  if (sqlite3_step(stmt)!=SQLITE_DONE)
206  throw cet::exception("Landed") << "failed to create events table on step\n";
207  if (sqlite3_finalize(stmt)!=SQLITE_OK)
208  throw cet::exception("Landed") << "failed to create events table on finalize\n";
209 
210  //create simchannel ide table
211  if (sqlite3_prepare(ppDb_, "CREATE TABLE Hits ( RunNumber INT, SubRunNumber INT, EventNumber INT, NumElectrons REAL, Energy REAL, X REAL, Y REAL, Z REAL, Track INT);", 200, &stmt, nullptr)!=SQLITE_OK)
212  throw cet::exception("Landed") << "failed to create hits table on prepare\n";
213  if (sqlite3_step(stmt)!=SQLITE_DONE)
214  throw cet::exception("Landed") << "failed to create hits table on step\n";
215  if (sqlite3_finalize(stmt)!=SQLITE_OK)
216  throw cet::exception("Landed") << "failed to create hits table on finalize\n";
217 
218  //create mcparticle table
219  if (sqlite3_prepare(ppDb_, "CREATE TABLE Tracks (RunNumber INT, SubRunNumber INT, EventNumber INT, ID INT, PDGCode INT, Segment INT, Energy REAL, X REAL, Y REAL, Z REAL);", 200, &stmt, nullptr)!=SQLITE_OK)
220  throw cet::exception("Landed") << "failed to create tracks table on prepare\n";
221  if (sqlite3_step(stmt)!=SQLITE_DONE)
222  throw cet::exception("Landed") << "failed to create tracks table on step\n";
223  if (sqlite3_finalize(stmt)!=SQLITE_OK)
224  throw cet::exception("Landed") << "failed to create tracks table on finalize\n";
225  }
226  else
227  {
228  //send geometry through landed service
229  sock_->sendGeometry(vrml_);
230  }
231 
232 }
234 {
235  sqlite3_close(ppDb_);
236 }
238 {
239  if (!events_.size() || outputFilename_.empty() || std::find(events_.begin(), events_.end(), event.event())!=events_.end())
240  {
241  sqlite3_stmt* stmt;
242  char * sErrMsg = 0;
243 
244  //mc truth
247  //reconstruction
249  //art::Handle<std::vector<recob::Track> > tracks;
250  //art::Handle<std::vector<recob::PFParticle> > particles;
253  std::map<size_t, int> pdgcodes;
254 
255  //get unique event id numbers
256  art::RunNumber_t runnum=event.run();
257  art::SubRunNumber_t subrunnum=event.subRun();
258  art::EventNumber_t eventnum=event.event();
259 
260  std::string whichcalo;
261  if (which_.substr(which_.length()-2, 2)=="dc")
262  whichcalo=which_.substr(0, which_.length()-2)+std::string("calodc");
263  else
264  whichcalo=which_+std::string("calo");
265 
266  if (which_=="truth")
267  {
268  event.getByLabel("largeant", mcparticles);
269  event.getByLabel("largeant", simchannels);
270  }
271  else
272  {
273  event.getByLabel(whichcalo, calorimetry);
274  //event.getByLabel(which_, tracks);
275  //event.getByLabel(which_, particles);
276  event.getByLabel(whichcalo, track2calo);
277  event.getByLabel(which_, particle2track);
278 
279  for (size_t i=0; i<particle2track->size(); i++)
280  {
281  //int pdgcode=particle2track->at(i).first->PdgCode();
282  for (size_t j=0; j<track2calo->size(); j++)
283  {
284  if (track2calo->at(j).first==particle2track->at(i).second)
285  {
286  for (size_t k=0; k<calorimetry->size(); k++)
287  {
288  if (track2calo->at(j).second==art::Ptr<anab::Calorimetry>(calorimetry, k))
289  {
290  pdgcodes[k]=particle2track->at(i).first->PdgCode();
291  }
292  }
293  }
294  }
295  }
296  }
297  // //determine available reconstructions
298  // std::cout << "looking for reco space point sets\n";
299  // std::vector<art::Handle<std::vector<recob::SpacePoint> > > recohits;
300  // event.getManyByType(recohits);
301  // std::cout << "reco hit sets: " << recohits.size() << std::endl;
302  // for (size_t i=0; i<recohits.size(); i++)
303  // {
304  // const art::Provenance* prov=recohits[i].provenance();
305  // std::cout << i << ": ";
306  // std::cout << prov->moduleLabel();
307  // std::cout << std::endl;
308  // }
309  // std::cout << "looking for reco track sets\n";
310  // std::vector<art::Handle<std::vector<recob::Track> > > recotracks;
311  // event.getManyByType(recotracks);
312  // std::cout << "reco track sets: " << recotracks.size() << std::endl;
313  // for (size_t i=0; i<recotracks.size(); i++)
314  // {
315  // const art::Provenance* prov=recotracks[i].provenance();
316  // std::cout << i << ": ";
317  // std::cout << prov->moduleLabel();
318  // std::cout << std::endl;
319  // }
320 
321  // std::cout << "Event: " << event.id() << std::endl;
322 
323  int hitcount=0;
324  int trajtotal=0;
325  if (which_=="truth")
326  {
327  //store sim channels and their ide's
328  for (auto const& simchannel:*simchannels)
329  if (geom_->SignalType(simchannel.Channel()) == geo::kCollection)
330  //ides
331  for (auto const& tdcide:simchannel.TDCIDEMap())
332  hitcount+=tdcide.second.size();
333  if (mcparticles->size())
334  {
335  //put first mctruth particle into database
336  for (auto const& part:*mcparticles)
337  {
338  for (size_t i=0; i<part.NumberTrajectoryPoints(); i++)
339  {
340  trajtotal++;
341  }
342  }
343  }
344  }
345  else
346  {
347  for (size_t tracknum=0; tracknum<calorimetry->size(); tracknum++)
348  {
349  hitcount+=calorimetry->at(tracknum).XYZ().size();
350  }
351  }
352 
353  if (!outputFilename_.empty())
354  {
355  if (sqlite3_prepare(ppDb_, "INSERT INTO Events (RunNumber, SubRunNumber, EventNumber) VALUES ( ?, ?, ? );", 200, &stmt, nullptr)!=SQLITE_OK)
356  throw cet::exception("Landed") << "failed to fill events table on prepare\n";
357  if (sqlite3_bind_int(stmt, 1, runnum)!=SQLITE_OK)
358  throw cet::exception("Landed") << "failed to fill events table on bind\n";
359  if (sqlite3_bind_int(stmt, 2, subrunnum)!=SQLITE_OK)
360  throw cet::exception("Landed") << "failed to fill events table on bind\n";
361  if (sqlite3_bind_int(stmt, 3, eventnum)!=SQLITE_OK)
362  throw cet::exception("Landed") << "failed to fill events table on bind\n";
363  if (sqlite3_step(stmt)!=SQLITE_DONE)
364  throw cet::exception("Landed") << "failed to fill events table on step\n";
365  if (sqlite3_finalize(stmt)!=SQLITE_OK)
366  throw cet::exception("Landed") << "failed to fill events table on finalize\n";
367 
368  if (which_=="truth")
369  {
370  //store sim channels and their ide's
371  for (auto const& simchannel:*simchannels)
372  if (geom_->SignalType(simchannel.Channel()) == geo::kCollection)
373  {
374  //ides
375  sqlite3_exec(ppDb_, "BEGIN TRANSACTION", NULL, NULL, &sErrMsg);
376  for (auto const& tdcide:simchannel.TDCIDEMap())
377  {
378  // unsigned int tdc=tdcide.first;
379  auto const& idevec=tdcide.second;
380  for (auto const& ide:idevec)
381  {
382  // SimChannelID INT, TDC INT, NumElectrons REAL, Energy REAL, X REAL, Y REAL, Z REAL
383  if (sqlite3_prepare(ppDb_, "INSERT INTO Hits (RunNumber, SubRunNumber, EventNumber, NumElectrons, Energy, X, Y, Z, Track ) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ? );", 200, &stmt, nullptr)!=SQLITE_OK)
384  throw cet::exception("Landed") << "failed to fill hits table on prepare\n";
385  if (sqlite3_bind_int(stmt, 1, runnum)!=SQLITE_OK)
386  throw cet::exception("Landed") << "failed to fill hits table on bind\n";
387  if (sqlite3_bind_int(stmt, 2, subrunnum)!=SQLITE_OK)
388  throw cet::exception("Landed") << "failed to fill hits table on bind\n";
389  if (sqlite3_bind_int(stmt, 3, eventnum)!=SQLITE_OK)
390  throw cet::exception("Landed") << "failed to fill hits table on bind\n";
391  if (sqlite3_bind_double(stmt, 4, ide.numElectrons)!=SQLITE_OK)
392  throw cet::exception("Landed") << "failed to fill hits table on bind\n";
393  if (sqlite3_bind_double(stmt, 5, ide.energy)!=SQLITE_OK)
394  throw cet::exception("Landed") << "failed to fill hits table on bind\n";
395  if (sqlite3_bind_double(stmt, 6, ide.x)!=SQLITE_OK)
396  throw cet::exception("Landed") << "failed to fill hits table on bind\n";
397  if (sqlite3_bind_double(stmt, 7, ide.y)!=SQLITE_OK)
398  throw cet::exception("Landed") << "failed to fill hits table on bind\n";
399  if (sqlite3_bind_double(stmt, 8, ide.z)!=SQLITE_OK)
400  throw cet::exception("Landed") << "failed to fill hits table on bind\n";
401  if (sqlite3_bind_int(stmt, 9, ide.trackID)!=SQLITE_OK)
402  throw cet::exception("Landed") << "failed to fill hits table on bind\n";
403  if (sqlite3_step(stmt)!=SQLITE_DONE)
404  throw cet::exception("Landed") << "failed to fill hits table on step\n";
405  if (sqlite3_finalize(stmt)!=SQLITE_OK)
406  throw cet::exception("Landed") << "failed to fill hits table on finalize\n";
407 
408  }
409  }
410  sqlite3_exec(ppDb_, "END TRANSACTION", NULL, NULL, &sErrMsg);
411  }
412 
413  //store mctruth tracks
414  sqlite3_exec(ppDb_, "BEGIN TRANSACTION", NULL, NULL, &sErrMsg);
415  for (auto const& part:*mcparticles)
416  {
417  for (size_t i=0; i<part.NumberTrajectoryPoints(); i++)
418  {
419  if (sqlite3_prepare(ppDb_, "INSERT INTO Tracks ( RunNumber, SubRunNumber, EventNumber, ID, PDGCode, Segment, Energy, X, Y, Z) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ? );", 200, &stmt, nullptr)!=SQLITE_OK)
420  throw cet::exception("Landed") << "failed to fill tracks table on prepare\n";
421  if (sqlite3_bind_int(stmt, 1, runnum)!=SQLITE_OK)
422  throw cet::exception("Landed") << "failed to fill tracks table on bind\n";
423  if (sqlite3_bind_int(stmt, 2, subrunnum)!=SQLITE_OK)
424  throw cet::exception("Landed") << "failed to fill tracks table on bind\n";
425  if (sqlite3_bind_int(stmt, 3, eventnum)!=SQLITE_OK)
426  throw cet::exception("Landed") << "failed to fill tracks table on bind\n";
427  if (sqlite3_bind_int(stmt, 4, part.TrackId())!=SQLITE_OK)
428  throw cet::exception("Landed") << "failed to fill tracks table on bind\n";
429  if (sqlite3_bind_int(stmt, 5, part.PdgCode())!=SQLITE_OK)
430  throw cet::exception("Landed") << "failed to fill tracks table on bind\n";
431  if (sqlite3_bind_int(stmt, 6, i)!=SQLITE_OK)
432  throw cet::exception("Landed") << "failed to fill tracks table on bind\n";
433  if (sqlite3_bind_double(stmt, 7, part.E(i))!=SQLITE_OK)
434  throw cet::exception("Landed") << "failed to fill tracks table on bind\n";
435  if (sqlite3_bind_double(stmt, 8, part.Vx(i))!=SQLITE_OK)
436  throw cet::exception("Landed") << "failed to fill tracks table on bind\n";
437  if (sqlite3_bind_double(stmt, 9, part.Vy(i))!=SQLITE_OK)
438  throw cet::exception("Landed") << "failed to fill tracks table on bind\n";
439  if (sqlite3_bind_double(stmt, 10, part.Vz(i))!=SQLITE_OK)
440  throw cet::exception("Landed") << "failed to fill tracks table on bind\n";
441  if (sqlite3_step(stmt)!=SQLITE_DONE)
442  throw cet::exception("Landed") << "failed to fill tracks table on step\n";
443  if (sqlite3_finalize(stmt)!=SQLITE_OK)
444  throw cet::exception("Landed") << "failed to fill tracks table on finalize\n";
445  }
446  }
447  sqlite3_exec(ppDb_, "END TRANSACTION", NULL, NULL, &sErrMsg);
448  }
449  //reconstruction rather than truth
450  else
451  {
452  sqlite3_exec(ppDb_, "BEGIN TRANSACTION", NULL, NULL, &sErrMsg);
453 
454  for (size_t tracknum=0; tracknum<calorimetry->size(); tracknum++)
455  {
456  auto const& calo=calorimetry->at(tracknum);
457  for (size_t hitnum=0; hitnum<calo.dEdx().size() && hitnum<calo.dQdx().size() && hitnum<calo.XYZ().size(); hitnum++)
458  {
459  if (sqlite3_prepare(ppDb_, "INSERT INTO Hits (RunNumber, SubRunNumber, EventNumber, NumElectrons, Energy, X, Y, Z, Track ) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ? );", 200, &stmt, nullptr)!=SQLITE_OK)
460  throw cet::exception("Landed") << "failed to fill hits table on prepare\n";
461  if (sqlite3_bind_int(stmt, 1, runnum)!=SQLITE_OK)
462  throw cet::exception("Landed") << "failed to fill hits table on bind\n";
463  if (sqlite3_bind_int(stmt, 2, subrunnum)!=SQLITE_OK)
464  throw cet::exception("Landed") << "failed to fill hits table on bind\n";
465  if (sqlite3_bind_int(stmt, 3, eventnum)!=SQLITE_OK)
466  throw cet::exception("Landed") << "failed to fill hits table on bind\n";
467  if (sqlite3_bind_double(stmt, 4, calo.TrkPitchVec().at(hitnum)*calo.dQdx().at(hitnum))!=SQLITE_OK)
468  throw cet::exception("Landed") << "failed to fill hits table on bind\n";
469  if (sqlite3_bind_double(stmt, 5, calo.TrkPitchVec().at(hitnum)*calo.dEdx().at(hitnum))!=SQLITE_OK)
470  throw cet::exception("Landed") << "failed to fill hits table on bind\n";
471  if (sqlite3_bind_double(stmt, 6, calo.XYZ().at(hitnum).X())!=SQLITE_OK)
472  throw cet::exception("Landed") << "failed to fill hits table on bind\n";
473  if (sqlite3_bind_double(stmt, 7, calo.XYZ().at(hitnum).Y())!=SQLITE_OK)
474  throw cet::exception("Landed") << "failed to fill hits table on bind\n";
475  if (sqlite3_bind_double(stmt, 8, calo.XYZ().at(hitnum).Z())!=SQLITE_OK)
476  throw cet::exception("Landed") << "failed to fill hits table on bind\n";
477  if (sqlite3_bind_int(stmt, 9, tracknum+1)!=SQLITE_OK)
478  throw cet::exception("Landed") << "failed to fill hits table on bind\n";
479  if (sqlite3_step(stmt)!=SQLITE_DONE)
480  throw cet::exception("Landed") << "failed to fill hits table on step\n";
481  if (sqlite3_finalize(stmt)!=SQLITE_OK)
482  throw cet::exception("Landed") << "failed to fill hits table on finalize\n";
483  }
484  }
485  sqlite3_exec(ppDb_, "END TRANSACTION", NULL, NULL, &sErrMsg);
486 
487  sqlite3_exec(ppDb_, "BEGIN TRANSACTION", NULL, NULL, &sErrMsg);
488  for (size_t tracknum=0; tracknum<calorimetry->size(); tracknum++)
489  {
490  auto const& calo=calorimetry->at(tracknum);
491  if (calo.dEdx().size()>1)
492  {
493  int pdgcode=0;
494  if (pdgcodes.find(tracknum)!=pdgcodes.end())
495  pdgcode=pdgcodes[tracknum];
496  double energy=calo.KineticEnergy();
497  for (size_t hitnum=0; hitnum<calo.dEdx().size() && hitnum<calo.dQdx().size() && hitnum<calo.XYZ().size(); hitnum++)
498  {
499  if (sqlite3_prepare(ppDb_, "INSERT INTO Tracks ( RunNumber, SubRunNumber, EventNumber, ID, PDGCode, Segment, Energy, X, Y, Z) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ? );", 200, &stmt, nullptr)!=SQLITE_OK)
500  throw cet::exception("Landed") << "failed to fill tracks table on prepare\n";
501  if (sqlite3_bind_int(stmt, 1, runnum)!=SQLITE_OK)
502  throw cet::exception("Landed") << "failed to fill tracks table on bind\n";
503  if (sqlite3_bind_int(stmt, 2, subrunnum)!=SQLITE_OK)
504  throw cet::exception("Landed") << "failed to fill tracks table on bind\n";
505  if (sqlite3_bind_int(stmt, 3, eventnum)!=SQLITE_OK)
506  throw cet::exception("Landed") << "failed to fill tracks table on bind\n";
507  if (sqlite3_bind_int(stmt, 4, tracknum+1)!=SQLITE_OK)
508  throw cet::exception("Landed") << "failed to fill tracks table on bind\n";
509  if (sqlite3_bind_int(stmt, 5, pdgcode)!=SQLITE_OK)
510  throw cet::exception("Landed") << "failed to fill tracks table on bind\n";
511  if (sqlite3_bind_int(stmt, 6, hitnum+1)!=SQLITE_OK)
512  throw cet::exception("Landed") << "failed to fill tracks table on bind\n";
513  if (sqlite3_bind_double(stmt, 7, energy)!=SQLITE_OK)
514  throw cet::exception("Landed") << "failed to fill tracks table on bind\n";
515  if (sqlite3_bind_double(stmt, 8, calo.XYZ().at(hitnum).X())!=SQLITE_OK)
516  throw cet::exception("Landed") << "failed to fill tracks table on bind\n";
517  if (sqlite3_bind_double(stmt, 9, calo.XYZ().at(hitnum).Y())!=SQLITE_OK)
518  throw cet::exception("Landed") << "failed to fill tracks table on bind\n";
519  if (sqlite3_bind_double(stmt, 10, calo.XYZ().at(hitnum).Z())!=SQLITE_OK)
520  throw cet::exception("Landed") << "failed to fill tracks table on bind\n";
521  if (sqlite3_step(stmt)!=SQLITE_DONE)
522  throw cet::exception("Landed") << "failed to fill tracks table on step\n";
523  if (sqlite3_finalize(stmt)!=SQLITE_OK)
524  throw cet::exception("Landed") << "failed to fill tracks table on finalize\n";
525  energy-=calo.TrkPitchVec().at(hitnum)*calo.dEdx().at(hitnum);
526  }
527  }
528  }
529  }
530  }
531  else
532  {
533  sock_->sendEvent(hitcount, trajtotal, runnum, subrunnum, eventnum);
534  if (which_=="truth")
535  {
536 
537  //store sim channels and their ide's
538  for (auto const& simchannel:*simchannels)
539  if (geom_->SignalType(simchannel.Channel()) == geo::kCollection)
540  //ides
541  for (auto const& tdcide:simchannel.TDCIDEMap())
542  {
543  auto const& idevec=tdcide.second;
544  for (auto const& ide:idevec)
545  {
546  sock_->sendHit(ide.x, ide.y, ide.z, ide.energy, ide.numElectrons, ide.trackID);
547  }
548  }
549  //store mctruth tracks
550  for (auto const& part:*mcparticles)
551  {
552  for (size_t i=0; i<part.NumberTrajectoryPoints(); i++)
553  {
554  sock_->sendVertex(part.Vx(i), part.Vy(i), part.Vz(i), part.E(i), part.TrackId(), part.PdgCode());
555  }
556  }
557  }
558  //reco rather than truth
559  else
560  {
561  for (size_t tracknum=0; tracknum<calorimetry->size(); tracknum++)
562  {
563  auto const& calo=calorimetry->at(tracknum);
564  for (size_t hitnum=0; hitnum<calo.dEdx().size() && hitnum<calo.dQdx().size() && hitnum<calo.XYZ().size(); hitnum++)
565  {
566  sock_->sendHit(calo.XYZ().at(hitnum).X(), calo.XYZ().at(hitnum).Y(), calo.XYZ().at(hitnum).Z(), calo.TrkPitchVec().at(hitnum)*calo.dEdx().at(hitnum), calo.TrkPitchVec().at(hitnum)*calo.dQdx().at(hitnum), tracknum+1);
567  }
568  }
569  for (size_t tracknum=0; tracknum<calorimetry->size(); tracknum++)
570  {
571  int pdgcode=0;
572  if (pdgcodes.find(tracknum)!=pdgcodes.end())
573  pdgcode=pdgcodes[tracknum];
574  auto const& calo=calorimetry->at(tracknum);
575  if (calo.dEdx().size()>1)
576  {
577  double energy=calo.KineticEnergy();
578  for (size_t hitnum=0; hitnum<calo.dEdx().size() && hitnum<calo.dQdx().size() && hitnum<calo.XYZ().size(); hitnum++)
579  {
580  sock_->sendVertex(calo.XYZ().at(hitnum).X(), calo.XYZ().at(hitnum).Y(), calo.XYZ().at(hitnum).Z(), energy, tracknum+1, pdgcode);
581  energy-=calo.TrkPitchVec().at(hitnum)*calo.dEdx().at(hitnum);
582  }
583  }
584  }
585  }
586  }
587  }
588 }
Build Geant4 geometry from GDML.
std::string which_
std::vector< int > events_
art::ServiceHandle< geo::Geometry > geom_
Landed & operator=(Landed const &)=delete
STL namespace.
Definition of basic raw digits.
void endJob() override
SigType_t SignalType(geo::PlaneID const &pid) const
Returns the type of signal on the channels of specified TPC plane.
Particle class.
std::string GDMLFile() const
Returns the full directory path to the GDML file source.
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:265
contains objects relating to OpDet hits
std::string vrml_
object containing MC truth information necessary for making RawDigits and doing back tracking ...
LArSoft includes.
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:42
void beginJob() override
sqlite3 * ppDb_
TString part[npart]
Definition: Style.C:32
Landed(fhicl::ParameterSet const &p)
double energy
Definition: plottest35.C:25
IDNumber_t< Level::SubRun > SubRunNumber_t
Definition: IDNumber.h:118
EDAnalyzer(Table< Config > const &config)
Definition: EDAnalyzer.h:100
Provides recob::Track data product.
std::string outputFilename_
object containing MC truth information necessary for making RawDigits and doing back tracking ...
IDNumber_t< Level::Event > EventNumber_t
Definition: IDNumber.h:117
HLT enums.
Float_t e
Definition: plot.C:34
void analyze(art::Event const &e) override
Namespace collecting geometry-related classes utilities.
Definition: fwd.h:25
art framework interface to geometry description
art::ServiceHandle< LandedSocket > sock_
calorimetry
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
Event finding and building.
Signal from collection planes.
Definition: geo_types.h:93
IDNumber_t< Level::Run > RunNumber_t
Definition: IDNumber.h:119