20 #include "art_root_io/TFileService.h" 42 #include "CoreUtils/ServiceUtil.h" 43 #include "MCCheater/BackTracker.h" 50 #include <TDatabasePDG.h> 51 #include <TParticlePDG.h> 117 cheat::BackTrackerCore*
fBt;
132 fVeeLabel =
p.get<
string>(
"VeeLabel",
"veefinder1");
138 consumesMany<vector<simb::MCTruth> >();
139 consumesMany<vector<simb::GTruth> >();
142 consumes<art::Assns<simb::MCTruth, simb::MCParticle, void> >(
fGeantLabel);
144 consumes<vector<sdp::EnergyDeposit> >(
fGeantLabel);
146 consumes<vector<sdp::CaloDeposit> >(ecalgeanttag);
154 consumes<art::Assns<rec::Track, rec::Vertex, void> >(
fVertexLabel);
156 consumes<art::Assns<rec::Track, rec::Vee, void> >(
fVeeLabel);
158 consumes<art::Assns<rec::TrackIoniz, rec::Track, void>>(
fTrackLabel);
162 fGeo = providerFrom<geo::GeometryGAr>();
170 fHistGenDiff = tfs->make<TH1F>(
"hGenDiff",
"gen stage;E_{final} - E_{initial} [MeV]",101,-500,500);
171 fHistG4Diff = tfs->make<TH1F>(
"hG4Diff",
"G4 stage;E_{final} - E_{initial} [GeV]",301,-1000,2000);
172 fHistEdeps = tfs->make<TH1F>(
"hEdeps",
"G4 stage - sdp::EnergyDeposit; remaining MCParticle KE [GeV]",200,-10,10);
173 fHistHitCompleteE = tfs->make<TH1F>(
"hHitCompleteE",
"reco stage: TPC hit;remaining MCParticle energy [GeV]",200,-10,10);
174 fHistHitCompleteKE = tfs->make<TH1F>(
"hHitCompleteKE",
"reco stage: TPC hit;remaining MCParticle energy [GeV]",200,-10,10);
175 fHistHitEnergy = tfs->make<TH1F>(
"hHitEnergy",
"TPC Hit -> deposited energy; energy per hit [MeV]",1000,0,10);
176 fHistTrackHitDiff = tfs->make<TH1F>(
"hTrackHitDiff",
"reco stage: TPC track vs. hit;track - sum hit energy [GeV]",51,-2,2);
178 fHistTrackHitMult = tfs->make<TH1F>(
"hTrackHitMult",
"reco stage: TPC Track #rightarrow hit;hit duplication",30,-0.5,29.5);
179 fHistClustHitMult = tfs->make<TH1F>(
"hClustHitMult",
"reco stage: TPC cluster #rightarrow hit;hit duplication",30,-0.5,29.5);
180 fHistClustMult = tfs->make<TH1F>(
"hClustMult",
"reco stage: TPC track #rightarrow cluster;cluster duplication",30,-0.5,29.5);
181 fHistNHitAssocTrackNHitTotDiff = tfs->make<TH1F>(
"hNHitAssocTrackNHitTotDiff",
"TPC Track #rightarrow hit;total N^{0} hits - total N^{0} hits assoc'd to tracks",11001,-1000,10000);
183 fHistEdepRelKE = tfs->make<TH1F>(
"hEdepRelKE",
"Track -> MCParticles;E_{dep}/KE_{initial}",29,0,29.001);
184 fHistG4Diff2d = tfs->make<TH2F>(
"hG4Diff2d",
"G4 stage;E_{initial} [GeV]; E_{final} [GeV]",100,0,1000,100,0,1000);
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>1e-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) {
def analyze(root, level, gtrees, gbranches, doprint)
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
string fVeeLabel
module label for conversion/decay vertexes rec:Vee
TH1F * fHistHitCompleteKE
MCParticle kinetic energy remaining after all hits accounted for.
string fGeantInstanceCalo
Instance name ECAL for sdp::CaloDeposit.
string fVertexLabel
module label for vertexes rec:Vertex
virtual void beginJob() override
string fHitLabel
module label for reco TPC hits rec::Hit
TH1F * fHistEdeps
total energy deposited by MCParticle via sdp::EnergyDeposit
cheat::BackTrackerCore * fBt
string fCaloHitLabel
module label for reco calo hits rec::CaloHit
#define DEFINE_ART_MODULE(klass)
std::vector< Handle< PROD > > getMany(SelectorBase const &selector=MatchAllSelector{}) const
BackTrackerAna(fhicl::ParameterSet const &p)
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
Description of geometry of one entire detector.
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
void analyze(art::Event const &e) override
General GArSoft Utilities.
string fTPCClusterLabel
module label for TPC Clusters rec::TPCCluster
string fCaloHitInstanceCalo
Instance name ECAL for rec::CaloHit.
string fClusterLabel
module label for calo clusters rec::Cluster
TH1F * fHistNHitAssocTrackNHitTotDiff
art framework interface to geometry description
QTextStream & endl(QTextStream &s)