253 std::map<size_t, int> pdgcodes;
260 std::string whichcalo;
262 whichcalo=
which_.substr(0,
which_.length()-2)+std::string(
"calodc");
264 whichcalo=
which_+std::string(
"calo");
268 event.getByLabel(
"largeant", mcparticles);
269 event.getByLabel(
"largeant", simchannels);
273 event.getByLabel(whichcalo, calorimetry);
276 event.getByLabel(whichcalo, track2calo);
277 event.getByLabel(
which_, particle2track);
279 for (
size_t i=0; i<particle2track->size(); i++)
282 for (
size_t j=0; j<track2calo->size(); j++)
284 if (track2calo->at(j).first==particle2track->at(i).second)
286 for (
size_t k=0; k<calorimetry->size(); k++)
290 pdgcodes[k]=particle2track->at(i).first->PdgCode();
328 for (
auto const& simchannel:*simchannels)
331 for (
auto const& tdcide:simchannel.TDCIDEMap())
332 hitcount+=tdcide.second.size();
333 if (mcparticles->size())
336 for (
auto const&
part:*mcparticles)
338 for (
size_t i=0; i<
part.NumberTrajectoryPoints(); i++)
347 for (
size_t tracknum=0; tracknum<calorimetry->size(); tracknum++)
349 hitcount+=calorimetry->at(tracknum).XYZ().size();
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";
371 for (
auto const& simchannel:*simchannels)
375 sqlite3_exec(
ppDb_,
"BEGIN TRANSACTION", NULL, NULL, &sErrMsg);
376 for (
auto const& tdcide:simchannel.TDCIDEMap())
379 auto const& idevec=tdcide.second;
380 for (
auto const& ide:idevec)
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";
410 sqlite3_exec(
ppDb_,
"END TRANSACTION", NULL, NULL, &sErrMsg);
414 sqlite3_exec(
ppDb_,
"BEGIN TRANSACTION", NULL, NULL, &sErrMsg);
415 for (
auto const&
part:*mcparticles)
417 for (
size_t i=0; i<
part.NumberTrajectoryPoints(); i++)
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";
447 sqlite3_exec(
ppDb_,
"END TRANSACTION", NULL, NULL, &sErrMsg);
452 sqlite3_exec(
ppDb_,
"BEGIN TRANSACTION", NULL, NULL, &sErrMsg);
454 for (
size_t tracknum=0; tracknum<calorimetry->size(); tracknum++)
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++)
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";
485 sqlite3_exec(
ppDb_,
"END TRANSACTION", NULL, NULL, &sErrMsg);
487 sqlite3_exec(
ppDb_,
"BEGIN TRANSACTION", NULL, NULL, &sErrMsg);
488 for (
size_t tracknum=0; tracknum<calorimetry->size(); tracknum++)
490 auto const&
calo=calorimetry->at(tracknum);
491 if (
calo.dEdx().size()>1)
494 if (pdgcodes.find(tracknum)!=pdgcodes.end())
495 pdgcode=pdgcodes[tracknum];
497 for (
size_t hitnum=0; hitnum<
calo.dEdx().size() && hitnum<
calo.dQdx().size() && hitnum<
calo.XYZ().size(); hitnum++)
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);
533 sock_->sendEvent(hitcount, trajtotal, runnum, subrunnum, eventnum);
538 for (
auto const& simchannel:*simchannels)
541 for (
auto const& tdcide:simchannel.TDCIDEMap())
543 auto const& idevec=tdcide.second;
544 for (
auto const& ide:idevec)
546 sock_->sendHit(ide.x, ide.y, ide.z, ide.energy, ide.numElectrons, ide.trackID);
550 for (
auto const&
part:*mcparticles)
552 for (
size_t i=0; i<
part.NumberTrajectoryPoints(); i++)
561 for (
size_t tracknum=0; tracknum<calorimetry->size(); tracknum++)
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++)
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);
569 for (
size_t tracknum=0; tracknum<calorimetry->size(); tracknum++)
572 if (pdgcodes.find(tracknum)!=pdgcodes.end())
573 pdgcode=pdgcodes[tracknum];
574 auto const&
calo=calorimetry->at(tracknum);
575 if (
calo.dEdx().size()>1)
577 double energy=
calo.KineticEnergy();
578 for (
size_t hitnum=0; hitnum<
calo.dEdx().size() && hitnum<
calo.dQdx().size() && hitnum<
calo.XYZ().size(); hitnum++)
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);
std::vector< int > events_
art::ServiceHandle< geo::Geometry > geom_
SigType_t SignalType(geo::PlaneID const &pid) const
Returns the type of signal on the channels of specified TPC plane.
IDNumber_t< Level::SubRun > SubRunNumber_t
std::string outputFilename_
IDNumber_t< Level::Event > EventNumber_t
art::ServiceHandle< LandedSocket > sock_
cet::coded_exception< error, detail::translate > exception
Signal from collection planes.
IDNumber_t< Level::Run > RunNumber_t