190 cheat::BackTrackerCore
const* const_bt = providerFrom<cheat::BackTracker>();
191 fBt =
const_cast<cheat::BackTrackerCore*
>(const_bt);
195 bool warnClusterHitNotFound =
true, warnTrackHitNotFound =
true;
200 auto gthandlelist =
e.getMany< vector<simb::GTruth> >();
206 for(
auto const& gth : gthandlelist) {
209 for(
auto const&
gt : *gth) {
239 auto MCPHandle =
e.getValidHandle<vector<simb::MCParticle>>(mcptag);
240 auto MCDepHandle =
e.getValidHandle<vector<sdp::EnergyDeposit>>(mcptag);
241 double eprim = 0., efinal = 0.;
243 map<int,double> mcpIdToKE, trkIdToERemain, trkIdToKERemain, trkIdToEdep;
247 trkIdToEdep[ed.TrackID()] += ed.Energy();
251 for (
auto mcp : *MCPHandle ) {
253 mcpIdToKE[mcp.TrackId()] = mcp.E()-mcp.Momentum().M();
255 if(mcp.PdgCode()>1e9)
continue;
258 if(mcp.Process()==
"primary"){
262 if(
fGeo->PointInGArTPC(mcp.Position().Vect())) {
263 trkIdToKERemain[mcp.TrackId()] = mcp.E()-mcp.Momentum().M();
264 trkIdToERemain[mcp.TrackId()] = mcp.E();
267 efinal += mcp.EndE();
269 if(mcp.E() < mcp.EndE())
270 std::cout <<
"MCParticle with final energy > intial energy ??? Ef-Ei = " << mcp.EndE()-mcp.E() <<
std::endl;
272 double deltaEDep = mcp.E()-mcp.Momentum().M()-trkIdToEdep[mcp.TrackId()];
273 if(deltaEDep <0 && deltaEDep>1
e-11)
277 cout <<
"negative remaining energy from EnergyDeposit subtraction" 278 <<
"\n\ttrackID = " << mcp.TrackId()
279 <<
"\n\tPDG = " << mcp.PdgCode()
280 <<
"\n\tinitial KE = " << mcp.E()-mcp.Momentum().M()
281 <<
"\n\tMCP remaining energy = " << mcp.E()-mcp.Momentum().M()-trkIdToEdep[mcp.TrackId()]
292 auto TPCHitHandle =
e.getValidHandle< vector<rec::Hit> >(tpchittag);
293 size_t nhit = TPCHitHandle->size();
294 map<rec::Hit,int> track_hitcounts, cluster_hitcounts;
303 for(cheat::HitIDE
const& ide : fBt->HitToHitIDEs(
hit)) {
304 trkIdToERemain[ide.trackID] -= ide.energyTot;
305 trkIdToKERemain[ide.trackID] -= ide.energyTot;
309 if(track_hitcounts.find(
hit)!=track_hitcounts.end()){
310 cout <<
"duplicate hits found in hit list" <<
endl;
313 track_hitcounts[
hit] = 0;
314 cluster_hitcounts[
hit] = 0;
319 for(
auto const& pair : trkIdToERemain) {
322 for(
auto const& pair : trkIdToKERemain) {
328 auto TPCClusterHandle =
e.getValidHandle< vector<rec::TPCCluster> >(tpcclustag);
329 map<const rec::IDNumber,int> tpcclustcounts;
330 int nclusterhit =0, nclusterhit_notfound = 0;
331 for(
auto clust : *TPCClusterHandle) {
333 if(tpcclustcounts.find(clust.getIDNumber())!=tpcclustcounts.end())
334 cout <<
"duplicate TPCClusters found!" <<
endl;
335 tpcclustcounts[clust.getIDNumber()] = 0;
340 if(cluster_hitcounts.find(*
hit)==cluster_hitcounts.end()) {
341 nclusterhit_notfound++;
342 if(warnClusterHitNotFound) {
343 cout <<
"TPC hit associated to TPC cluster not found in hit list" <<
endl;
344 warnClusterHitNotFound =
false;
348 cluster_hitcounts[*
hit] += 1;
354 auto TrackHandle =
e.getValidHandle< vector<rec::Track> >(tracktag);
355 size_t ntrackhit = 0;
356 for(
auto track : *TrackHandle ) {
359 for(
auto const& clust : fBt->TrackToClusters(&track) ) {
360 if(tpcclustcounts.find(clust->getIDNumber())==tpcclustcounts.end()) {
362 cout <<
"TPCCluster associated to track not found in cluster list" <<
endl;
367 tpcclustcounts[clust->getIDNumber()] += 1;
370 std::vector<std::pair<simb::MCParticle*,float>> trkmcps = fBt->TrackToMCParticles(&track);
371 double etot = fBt->TrackToTotalEnergy(&track);
373 vector<art::Ptr<rec::Hit>>
const hits = fBt->TrackToHits(&track);
374 ntrackhit += hits.size();
376 for(std::pair<simb::MCParticle*,float>
const& mcp : trkmcps) {
377 if(mcpIdToKE.find(mcp.first->TrackId())==mcpIdToKE.end()){
378 std::cout <<
"MCParticle matched to track not found in MCParticle list" <<
std::endl;
381 double eratio = mcp.second*etot/mcpIdToKE[mcp.first->TrackId()];
384 cout <<
"bad true contributed energy to track:MCParticle initial KE ratio!" 385 <<
"\n\ttrackID = " << mcp.first->TrackId()
386 <<
"\n\tPDG = " << mcp.first->PdgCode()
387 <<
"\n\tTotal energy = " << mcp.first->E() <<
" GeV" 388 <<
"\n\tKE0 = " << mcpIdToKE[mcp.first->TrackId()] <<
" GeV" 389 <<
"\n\tTotal track length = " << mcp.first->Trajectory().TotalLength() <<
" cm" 390 <<
"\n\tAvg. dE/dx = " << (mcp.first->E()-mcp.first->EndE())*1e3/mcp.first->Trajectory().TotalLength()<<
" MeV/cm" 391 <<
"\n\ttotal true track energy = " << etot <<
" GeV" 392 <<
"\n\ttrue energy contributed = " << mcp.second*etot <<
" GeV" 393 <<
"\n\tFraction of total true track energy contributed = " << mcp.second
394 <<
"\n\tratio = " << eratio
398 for(
auto const&
hit : hits) {
400 if(track_hitcounts.find(*
hit)==track_hitcounts.end()) {
401 if(warnTrackHitNotFound){
402 cout <<
"TPC hit associated to track not found in hit list" <<
endl;
404 warnTrackHitNotFound =
false;
409 track_hitcounts[*
hit] += 1;
411 for(
auto const& ide : fBt->HitToHitIDEs(
hit)) {
412 ehits += ide.energyTot;
418 for(
auto const& cts : track_hitcounts) {
422 for(
auto const& cts : cluster_hitcounts) {
425 for(
auto const& cts : tpcclustcounts) {
const geo::GeometryCore * fGeo
pointer to the geometry service
TH1F * fHistHitCompleteE
MCParticle total energy remaining after all hits accounted for.
string fTrackLabel
module label for TPC Tracks rec:Track
TH1F * fHistHitCompleteKE
MCParticle kinetic energy remaining after all hits accounted for.
string fHitLabel
module label for reco TPC hits rec::Hit
TH1F * fHistEdeps
total energy deposited by MCParticle via sdp::EnergyDeposit
cheat::BackTrackerCore * fBt
TH1F * fHistHitEnergy
total energy contributed from each MCParticle to hits
Detector simulation of raw signals on wires.
string fGeantLabel
module label for geant4 simulated hits
string fTPCClusterLabel
module label for TPC Clusters rec::TPCCluster
TH1F * fHistNHitAssocTrackNHitTotDiff
QTextStream & endl(QTextStream &s)