12 #include "art/Framework/Core/EDAnalyzer.h"
13 #include "art/Framework/Core/ModuleMacros.h"
14 #include "art/Framework/Principal/Event.h"
15 #include "art/Framework/Principal/Handle.h"
16 #include "art/Framework/Principal/Run.h"
17 #include "art/Framework/Principal/SubRun.h"
18 #include "canvas/Utilities/InputTag.h"
19 #include "fhiclcpp/ParameterSet.h"
20 #include "messagefacility/MessageLogger/MessageLogger.h"
22 #include "canvas/Persistency/Common/FindMany.h"
23 #include "fhiclcpp/ParameterSet.h"
24 #include "art/Utilities/ToolMacros.h"
25 #include "art/Framework/Services/Registry/ServiceHandle.h"
26 #include "art_root_io/TFileService.h"
27 #include "art/Framework/Core/ModuleMacros.h"
28 #include "art_root_io/TFileDirectory.h"
43 #include "nusimdata/SimulationBase/MCParticle.h"
47 #include <Eigen/Dense>
53 #include "TProfile2D.h"
59 namespace thrugoingmuon {
205 mutable std::vector<float>
fPhi;
229 art::ServiceHandle< art::TFileService >
tfs;
250 std::cout <<
"In analyzer constructor" << std::endl;
253 fRawDigitProducerLabelVec = pset.get< std::vector<art::InputTag>>(
"RawDigitLabelVec", std::vector<art::InputTag>() = {
"rawdigitfilter"});
254 fWireProducerLabelVec = pset.get< std::vector<art::InputTag>>(
"WireModuleLabelVec", std::vector<art::InputTag>() = {
"decon1droi"});
255 fHitProducerLabelVec = pset.get< std::vector<art::InputTag>>(
"HitModuleLabelVec", std::vector<art::InputTag>() = {
"gaushit"});
256 fTrackProducerLabelVec = pset.get< std::vector<art::InputTag>>(
"TrackModuleLabelVec",std::vector<art::InputTag>() = {
"pandoraTrackGausCryo0"});
257 fMCParticleProducerLabel = pset.get< art::InputTag >(
"MCParticleLabel",
"largeant");
258 fSimChannelProducerLabel = pset.get< art::InputTag >(
"SimChannelLabel",
"largeant");
259 fSimEnergyProducerLabel = pset.get< art::InputTag >(
"SimEnergyLabel",
"ionization");
260 fBadChannelProducerLabel = pset.get< art::InputTag >(
"BadChannelLabel",
"simnfspl1:badchannels");
261 fUseBadChannelDB = pset.get<
bool >(
"UseBadChannelDB",
false);
262 fUseICARUSGeometry = pset.get<
bool >(
"UseICARUSGeometry",
false);
264 fOffsetVec = pset.get<std::vector<int> >(
"OffsetVec", std::vector<int>()={0,0,0});
265 fSigmaVec = pset.get<std::vector<float> >(
"SigmaVec", std::vector<float>()={1.,1.,1.});
266 fMinAllowedChanStatus = pset.get<
int >(
"MinAllowedChannelStatus");
267 ftotalelctroncut = pset.get<
float >(
"totalelctroncut", 10000.);
269 std::cout <<
"UseICARUSGeometry: " << fUseICARUSGeometry << std::endl;
270 std::cout <<
"Read the fhicl parameters, recovering services" << std::endl;
274 fGeometry = lar::providerFrom<geo::Geometry>();
276 art::TFileDirectory
dir =
tfs->mkdir(
"histos");
277 fHitEffvselecVec.resize(fGeometry->Nplanes());
278 for(
size_t plane = 0; plane < fGeometry->Nplanes(); plane++)
280 fHitEffvselecVec.at(plane) = dir.make<TProfile> ((
"HitEffvselec" +
std::to_string(plane)).c_str(),
"Hit Efficiency; Total # e-", 200, 0., 200000., 0., 1.);
283 std::cout <<
"Services recovered, setting up output tree" << std::endl;
285 fTree =
tfs->make<TTree>(
"Analysis",
"Analysis tree");
287 fTree->Branch(
"Event", &fEvent,
"Event/I");
288 fTree->Branch(
"SubRun", &fSubRun,
"SubRun/I");
289 fTree->Branch(
"Run", &fRun,
"Run/I");
290 fTree->Branch(
"TrackID", &fSimTrackID,
"TrackID/I");
291 fTree->Branch(
"PDG", &fSimPDG,
"PDG/I");
292 fTree->Branch(
"ntracks_reco", &fNtracks_reco,
"ntracks_reco/I");
293 fTree->Branch(
"ntracks_primary", &fNtracks_primary,
"ntracks_primary/I");
295 fTree->Branch(
"CryostataVec",
"std::vector<int>", &fCryoVec);
296 fTree->Branch(
"TPCVec",
"std::vector<int>", &fTPCVec);
297 fTree->Branch(
"PlaneVec",
"std::vector<int>", &fPlaneVec);
298 fTree->Branch(
"WireVec",
"std::vector<int>", &fWireVec);
300 fTree->Branch(
"mcpartvx",
"std::vector<float>", &fmcpartvx);
301 fTree->Branch(
"mcpartvy",
"std::vector<float>", &fmcpartvy);
302 fTree->Branch(
"mcpartvz",
"std::vector<float>", &fmcpartvz);
304 fTree->Branch(
"mcpartpx",
"std::vector<float>", &fmcpartpx);
305 fTree->Branch(
"mcpartpy",
"std::vector<float>", &fmcpartpy);
306 fTree->Branch(
"mcpartpz",
"std::vector<float>", &fmcpartpz);
307 fTree->Branch(
"mcparte",
"std::vector<float>", &fmcparte);
309 fTree->Branch(
"TotalElectronsVec",
"std::vector<float>", &fTotalElectronsVec);
310 fTree->Branch(
"TotalElecEnergyVec",
"std::vector<float>", &fTotalElecEnergyVec);
311 fTree->Branch(
"MaxElectronsVec",
"std::vector<float>", &fMaxElectronsVec);
312 fTree->Branch(
"StartTick",
"std::vector<int>", &fStartTickVec);
313 fTree->Branch(
"StopTick",
"std::vector<int>", &fStopTickVec);
314 fTree->Branch(
"MaxETick",
"std::vector<int>", &fMaxETickVec);
315 fTree->Branch(
"PartDirX",
"std::vector<float>", &fPartDirX);
316 fTree->Branch(
"PartDirY",
"std::vector<float>", &fPartDirY);
317 fTree->Branch(
"PartDirZ",
"std::vector<float>", &fPartDirZ);
319 fTree->Branch(
"NMatchedWires",
"std::vector<int>", &fNMatchedWires);
320 fTree->Branch(
"NMatchedHits",
"std::vector<int>", &fNMatchedHits);
322 fTree->Branch(
"HitPeakTimeVec",
"std::vector<float>", &fHitPeakTimeVec);
323 fTree->Branch(
"HitPeakAmpVec",
"std::vector<float>", &fHitPeakAmpVec);
324 fTree->Branch(
"HitPeakRMSVec",
"std::vector<float>", &fHitPeakRMSVec);
325 fTree->Branch(
"HitBaselineVec",
"std::vector<float>", &fHitBaselinevec);
326 fTree->Branch(
"HitSummedADCVec",
"std::vector<float>", &fHitSummedADCVec);
327 fTree->Branch(
"HitIntegralVec",
"std::vector<float>", &fHitIntegralVec);
328 fTree->Branch(
"HitStartTickVec",
"std::vector<int>", &fHitStartTickVec);
329 fTree->Branch(
"HitStopTickVec",
"std::vector<int>", &fHitStopTickVec);
330 fTree->Branch(
"HitMultiplicity",
"std::vector<int>", &fHitMultiplicityVec);
331 fTree->Branch(
"HitLocalIndex",
"std::vector<int>", &fHitLocalIndexVec);
332 fTree->Branch(
"HitGoodness",
"std::vector<float>", &fHitGoodnessVec);
333 fTree->Branch(
"HitNumDegrees",
"std::vector<int>", &fNumDegreesVec);
335 fTree->Branch(
"NSimChannelHitsVec",
"std::vector<float>", &fNSimChannelHitsVec);
336 fTree->Branch(
"NRecobHitVec",
"std::vector<float>", &fNRecobHitVec);
337 fTree->Branch(
"HitEfficiencyVec",
"std::vector<float>", &fHitEfficiencyVec);
338 fTree->Branch(
"NFakeHitVec",
"std::vector<float>", &fNFakeHitVec);
340 fTree->Branch(
"mcstartx",
"std::vector<float>", &fmcstartx);
341 fTree->Branch(
"mcstarty",
"std::vector<float>", &fmcstarty);
342 fTree->Branch(
"mcstartz",
"std::vector<float>", &fmcstartz);
343 fTree->Branch(
"mcendx",
"std::vector<float>", &fmcendx);
344 fTree->Branch(
"mcendy",
"std::vector<float>", &fmcendy);
345 fTree->Branch(
"mcendz",
"std::vector<float>", &fmcendz);
347 fTree->Branch(
"mcstartdirx",
"std::vector<float>", &fmcstartdirx);
348 fTree->Branch(
"mcstartdiry",
"std::vector<float>", &fmcstartdiry);
349 fTree->Branch(
"mcstartdirz",
"std::vector<float>", &fmcstartdirz);
350 fTree->Branch(
"mcenddirx",
"std::vector<float>", &fmcenddirx);
351 fTree->Branch(
"mcenddiry",
"std::vector<float>", &fmcenddiry);
352 fTree->Branch(
"mcenddirz",
"std::vector<float>", &fmcenddirz);
354 fTree->Branch(
"mctstartx",
"std::vector<float>", &fmctstartx);
355 fTree->Branch(
"mctstarty",
"std::vector<float>", &fmctstarty);
356 fTree->Branch(
"mctstartz",
"std::vector<float>", &fmctstartz);
357 fTree->Branch(
"mctendx",
"std::vector<float>", &fmctendx);
358 fTree->Branch(
"mctendy",
"std::vector<float>", &fmctendy);
359 fTree->Branch(
"mctendz",
"std::vector<float>", &fmctendz);
361 fTree->Branch(
"mctstartdirx",
"std::vector<float>", &fmctstartdirx);
362 fTree->Branch(
"mctstartdiry",
"std::vector<float>", &fmctstartdiry);
363 fTree->Branch(
"mctstartdirz",
"std::vector<float>", &fmctstartdirz);
364 fTree->Branch(
"mctenddirx",
"std::vector<float>", &fmctenddirx);
365 fTree->Branch(
"mctenddiry",
"std::vector<float>", &fmctenddiry);
366 fTree->Branch(
"mctenddirz",
"std::vector<float>", &fmctenddirz);
368 fTree->Branch(
"recostartx",
"std::vector<float>", &frecostartx);
369 fTree->Branch(
"recostarty",
"std::vector<float>", &frecostarty);
370 fTree->Branch(
"recostartz",
"std::vector<float>", &frecostartz);
371 fTree->Branch(
"recoendx",
"std::vector<float>", &frecoendx);
372 fTree->Branch(
"recoendy",
"std::vector<float>", &frecoendy);
373 fTree->Branch(
"recoendz",
"std::vector<float>", &frecoendz);
375 fTree->Branch(
"recostartdirx",
"std::vector<float>", &frecostartdirx);
376 fTree->Branch(
"recostartdiry",
"std::vector<float>", &frecostartdiry);
377 fTree->Branch(
"recostartdirz",
"std::vector<float>", &frecostartdirz);
378 fTree->Branch(
"recoenddirx",
"std::vector<float>", &frecoenddirx);
379 fTree->Branch(
"recoenddiry",
"std::vector<float>", &frecoenddiry);
380 fTree->Branch(
"recoenddirz",
"std::vector<float>", &frecoenddirz);
382 fTree->Branch(
"length",
"std::vector<float>", &fLength);
383 fTree->Branch(
"thetaxz",
"std::vector<float>", &fThetaXZ);
384 fTree->Branch(
"thetayz",
"std::vector<float>", &fThetaYZ);
385 fTree->Branch(
"theta",
"std::vector<float>", &fTheta);
386 fTree->Branch(
"phi",
"std::vector<float>", &fPhi);
387 fTree->Branch(
"mctheta",
"std::vector<float>", &fmcTheta);
388 fTree->Branch(
"mcphi",
"std::vector<float>", &fmcPhi);
389 fTree->Branch(
"mcthetaxz",
"std::vector<float>", &fmcThetaXZ);
390 fTree->Branch(
"mcthetayz",
"std::vector<float>", &fmcThetaYZ);
391 fTree->Branch(
"mcttheta",
"std::vector<float>", &fmctTheta);
392 fTree->Branch(
"mctphi",
"std::vector<float>", &fmctPhi);
393 fTree->Branch(
"mctthetaxz",
"std::vector<float>", &fmctThetaXZ);
394 fTree->Branch(
"mctthetayz",
"std::vector<float>", &fmctThetaYZ);
396 fTree->Branch(
"locx",
"std::vector<float>", &flocx);
397 fTree->Branch(
"locy",
"std::vector<float>", &flocy);
398 fTree->Branch(
"locz",
"std::vector<float>", &flocz);
513 fEvent = evt.id().event();
519 art::Handle< std::vector<sim::SimChannel>> simChannelHandle;
523 art::Handle< std::vector<simb::MCParticle>> mcParticleHandle;
526 art::Handle<std::vector<sim::SimEnergyDeposit>> simEnergyHandle;
532 if (!simChannelHandle.isValid() || simChannelHandle->empty() ||
533 !simEnergyHandle.isValid() || simEnergyHandle->empty() ||
534 !mcParticleHandle.isValid() )
return;
544 using TDCToIDEMap = std::map<unsigned short, sim::IDE>;
545 using ChanToTDCToIDEMap = std::map<raw::ChannelID_t, TDCToIDEMap>;
546 using PartToChanToTDCToIDEMap = std::unordered_map<int, ChanToTDCToIDEMap>;
548 PartToChanToTDCToIDEMap partToChanToTDCToIDEMap;
551 for(
const auto& simChannel : *simChannelHandle)
553 for(
const auto& tdcide : simChannel.TDCIDEMap())
555 for(
const auto& ide : tdcide.second) partToChanToTDCToIDEMap[ide.trackID][simChannel.Channel()][tdcide.first] = ide;
561 using SimEnergyDepositVec = std::vector<const sim::SimEnergyDeposit*>;
562 using PartToSimEnergyMap = std::unordered_map<int, SimEnergyDepositVec>;
564 PartToSimEnergyMap partToSimEnergyMap;
566 for(
const auto& simEnergy : *simEnergyHandle)
568 partToSimEnergyMap[simEnergy.TrackID()].push_back(&simEnergy);
572 using ChanToHitVecMap = std::unordered_map<raw::ChannelID_t,std::vector<const recob::Hit*>>;
574 ChanToHitVecMap channelToHitVec;
579 art::Handle<std::vector<recob::Hit>> hitHandle;
580 evt.getByLabel(hitLabel, hitHandle);
582 for(
const auto&
hit : *hitHandle)
583 channelToHitVec[
hit.Channel()].push_back(&
hit);
587 using MCParticleTrajIdxPair = std::pair<const simb::MCParticle*,size_t>;
588 using MCPartPointPairIdxVec = std::vector<MCParticleTrajIdxPair>;
589 using HitToMCPartToIdxMap = std::unordered_map<const recob::Hit*,MCPartPointPairIdxVec>;
591 HitToMCPartToIdxMap hitToMcPartToIdxMap;
594 using TrackIDToMCParticleMap = std::unordered_map<int, const simb::MCParticle*>;
596 TrackIDToMCParticleMap trackIDToMCParticleMap;
598 for(
const auto& mcParticle : *mcParticleHandle)
599 trackIDToMCParticleMap[mcParticle.TrackId()] = &mcParticle;
604 art::Handle< std::vector<int>> badChannelHandle;
607 std::vector<int> nSimChannelHitVec = {0,0,0};
608 std::vector<int> nRecobHitVec = {0,0,0};
609 std::vector<int> nFakeHitVec = {0,0,0};
610 std::vector<int> nSimulatedWiresVec = {0,0,0};
612 std::cout <<
"***************** EVENT " <<
fEvent <<
" ******************" << std::endl;
613 std::cout <<
"-- Looping over channels for hit efficiency, # MC Track IDs: " << partToChanToTDCToIDEMap.size() << std::endl;
615 auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(evt);
618 for(
const auto& partToChanInfo : partToChanToTDCToIDEMap)
620 TrackIDToMCParticleMap::const_iterator trackIDToMCPartItr = trackIDToMCParticleMap.find(partToChanInfo.first);
622 if (trackIDToMCPartItr == trackIDToMCParticleMap.end())
continue;
624 const simb::MCParticle* mcParticle = trackIDToMCPartItr->second;
626 int trackPDGCode = mcParticle->PdgCode();
627 std::string processName = mcParticle->Process();
631 if (fabs(trackPDGCode) != 13 || processName !=
"primary")
continue;
634 std::cout <<
">>>> Loop on MCParticle: " << mcParticle <<
", pdg: " << trackPDGCode <<
", process: " << processName << std::endl;
662 fmcparte.push_back(mcParticle->E());
665 Eigen::Vector3f partStartPos(mcParticle->Vx(),mcParticle->Vy(),mcParticle->Vz());
666 Eigen::Vector3f partStartDir(mcParticle->Px(),mcParticle->Py(),mcParticle->Pz());
668 partStartDir.normalize();
670 Eigen::Vector2f partStartDirVecXZ(partStartDir[0],partStartDir[2]);
672 partStartDirVecXZ.normalize();
676 std::vector<Eigen::Vector3f> lastPositionVec = {partStartPos,partStartPos,partStartPos};
678 std::cout <<
" *** Looping over channels, have " << partToChanInfo.second.size() <<
" channels" << std::endl;
680 for(
const auto& chanToTDCToIDEMap : partToChanInfo.second)
689 std::cout <<
"*** skipping bad channel with status: " << chanFilt.
Status(chanToTDCToIDEMap.first)
690 <<
" for channel: " << chanToTDCToIDEMap.first
691 <<
", plane: " << wids[0].Plane
692 <<
", wire: " << wids[0].Wire << std::endl;
699 if (badChannelHandle.isValid())
701 std::vector<int>::const_iterator badItr = std::find(badChannelHandle->begin(),badChannelHandle->end(),chanToTDCToIDEMap.first);
703 if (badItr != badChannelHandle->end())
continue;
706 TDCToIDEMap tdcToIDEMap = chanToTDCToIDEMap.second;
707 float totalElectrons(0.);
708 float totalEnergy(0.);
709 float maxElectrons(0.);
710 unsigned short maxElectronsTDC(0);
711 int nMatchedWires(0);
719 unsigned int plane = wids[0].Plane;
722 Eigen::Vector3f avePosition(0.,0.,0.);
724 nSimulatedWiresVec[plane]++;
726 for(
const auto& ideVal : tdcToIDEMap)
728 totalElectrons += ideVal.second.numElectrons;
729 totalEnergy += ideVal.second.energy;
731 if (maxElectrons < ideVal.second.numElectrons)
733 maxElectrons = ideVal.second.numElectrons;
734 maxElectronsTDC = ideVal.first;
737 avePosition += Eigen::Vector3f(ideVal.second.x,ideVal.second.y,ideVal.second.z);
742 avePosition /= float(tdcToIDEMap.size());
744 Eigen::Vector3f partDirVec = avePosition - lastPositionVec[plane];
746 partDirVec.normalize();
748 lastPositionVec[plane] = avePosition;
759 unsigned short startTDC = tdcToIDEMap.begin()->first;
760 unsigned short stopTDC = tdcToIDEMap.rbegin()->first;
763 unsigned short startTick = clockData.TPCTDC2Tick(startTDC) +
fOffsetVec[plane];
764 unsigned short stopTick = clockData.TPCTDC2Tick(stopTDC) +
fOffsetVec[plane];
765 unsigned short maxETick = clockData.TPCTDC2Tick(maxElectronsTDC) +
fOffsetVec[plane];
810 float nElectronsTotalBest(0.);
811 float hitSummedADCBest(0.);
812 float hitIntegralBest(0.);
813 float hitPeakTimeBest(0.);
814 float hitPeakAmpBest(-100.);
815 float hitRMSBest(0.);
816 int hitMultiplicityBest(0);
817 int hitLocalIndexBest(0);
818 float hitGoodnessBest(0.);
819 int hitNumDegreesBest(0);
820 float hitBaselineBest(0.);
822 unsigned short hitStopTickBest(0);
823 unsigned short hitStartTickBest(0);
829 ChanToHitVecMap::iterator hitIter = channelToHitVec.find(chanToTDCToIDEMap.first);
831 if (hitIter != channelToHitVec.end())
837 for(
const auto&
hit : hitIter->second)
840 unsigned short hitStartTick =
hit->PeakTime() -
fSigmaVec[plane] *
hit->RMS();
841 unsigned short hitStopTick =
hit->PeakTime() +
fSigmaVec[plane] *
hit->RMS();
843 if (hitStartTick > stopTick || hitStopTick < startTick)
845 nFakeHitVec[plane]++;
850 float hitHeight =
hit->PeakAmplitude();
853 if (hitHeight < hitPeakAmpBest)
continue;
855 hitPeakAmpBest = hitHeight;
857 hitStartTickBest = hitStartTick;
858 hitStopTickBest = hitStopTick;
863 nElectronsTotalBest = 0.;
864 hitPeakTimeBest = bestHit->
PeakTime();
865 hitIntegralBest = bestHit->
Integral();
867 hitRMSBest = bestHit->
RMS();
873 hitBaselineBest = 0.;
876 for(
unsigned short tick = hitStartTickBest;
tick <= hitStopTickBest;
tick++)
878 unsigned short hitTDC = clockData.TPCTick2TDC(
tick -
fOffsetVec[plane]);
880 TDCToIDEMap::iterator ideIterator = tdcToIDEMap.find(hitTDC);
882 if (ideIterator != tdcToIDEMap.end()) nElectronsTotalBest += ideIterator->second.numElectrons;
886 Eigen::Vector3f hitIDEPos(avePosition[0],avePosition[1],avePosition[2]);
888 float bestMatch(std::numeric_limits<float>::max());
890 for (
size_t idx = 0; idx < mcParticle->NumberTrajectoryPoints(); idx++)
892 const TLorentzVector& pos = mcParticle->Position(idx);
893 Eigen::Vector3f trackPos(pos.X(),pos.Y(),pos.Z());
894 float missDist = (trackPos - hitIDEPos).
norm();
895 if (missDist < bestMatch)
897 bestMatch = missDist;
910 if (bestMatch < std::numeric_limits<float>::max())
912 hitToMcPartToIdxMap[bestHit].push_back(MCParticleTrajIdxPair(mcParticle,matchIdx));
915 partDirVec = Eigen::Vector3f(mcParticle->Px(matchIdx),mcParticle->Py(matchIdx),mcParticle->Pz(matchIdx));
917 partDirVec.normalize();
921 if (nMatchedHits > 0)
928 else if (rejectedHit)
936 mf::LogDebug(
"ThroughgoingmuonAnalyzer") <<
"==> No match, TPC/Plane/Wire: "
937 <<
"/" << wids[0].TPC
938 <<
"/" << wids[0].Plane
939 <<
"/" << wids[0].Wire
940 <<
", # electrons: " << totalElectrons
941 <<
", startTick: " << startTick
942 <<
", stopTick: " << stopTick << std::endl;
946 float matchHit = std::min(nMatchedHits,1);
950 fCryoVec.push_back(wids[0].Cryostat);
982 std::cout <<
"-- Now starting loop over tracks" << std::endl;
983 std::cout <<
"-- Hit/MCParticle map size: " << hitToMcPartToIdxMap.size() << std::endl;
986 using MCPartToHitVecMap = std::unordered_map<const simb::MCParticle*,std::vector<const recob::Hit*>>;
987 using TrackToMCMap = std::unordered_map<const recob::Track*, MCPartToHitVecMap>;
989 TrackToMCMap trackToMCMap;
991 std::cout <<
"** Starting outer loop over all sets of tracks" << std::endl;
998 art::Handle<std::vector<recob::Track> > trackHandle;
1000 evt.getByLabel(trackLabel, trackHandle);
1001 if (!trackHandle.isValid())
return;
1004 ntrk_reco += trackHandle->size();
1008 art::FindMany<recob::Hit> trackHitAssns(trackHandle, evt, trackLabel);
1011 for(
size_t trackIdx = 0; trackIdx < trackHandle->size(); trackIdx++)
1013 art::Ptr<recob::Track> ptrack(trackHandle,trackIdx);
1016 const std::vector<const recob::Hit*>& trackHitVec = trackHitAssns.at(ptrack.key());
1019 MCPartToHitVecMap mcPartCountMap;
1021 std::cout <<
"- Track idx " << trackIdx <<
", ptr: " << ptrack.get() <<
" has " << trackHitVec.size() <<
" hits" << std::endl;
1024 for(
const auto&
hit : trackHitVec)
1027 HitToMCPartToIdxMap::iterator hitToMcPartIdxItr = hitToMcPartToIdxMap.find(
hit);
1029 if (hitToMcPartIdxItr != hitToMcPartToIdxMap.end())
1031 for(
const auto& mcPartIdxPair : hitToMcPartIdxItr->second)
1033 mcPartCountMap[mcPartIdxPair.first].push_back(
hit);
1037 mcPartCountMap[
nullptr].push_back(
hit);
1040 std::cout <<
" - associated to " << mcPartCountMap.size() <<
" MCParticles" << std::endl;
1042 for(
const auto& mcPair : mcPartCountMap)
1043 std::cout <<
" - MCParticle: " << mcPair.first <<
", # hits: " << mcPair.second.size() << std::endl;
1046 const simb::MCParticle* bestMCMatch(
nullptr);
1047 size_t bestCount(0);
1049 for(
const auto& pair : mcPartCountMap)
1052 if (pair.first && pair.second.size() > bestCount)
1054 bestMCMatch = pair.first;
1055 bestCount = pair.second.size();
1064 MCPartToHitVecMap::iterator bestItr = mcPartCountMap.find(bestMCMatch);
1066 trackToMCMap[ptrack.get()][bestItr->first] = bestItr->second;
1072 std::cout <<
"====> trackToMCMap size: " << trackToMCMap.size() << std::endl;
1076 std::cout <<
"==================================================================================> " << std::endl;
1082 for(
const auto& trackMCPair : trackToMCMap)
1090 if(ntraj <= 0)
continue;
1144 std::vector<double> posx, posy, posz;
1145 std::vector<double> dirx, diry, dirz;
1153 for (
unsigned int i= 0; i < ntraj; i++)
1162 if (!tpcGeom)
continue;
1163 if (tpcGeom->
ID() != C0id)
continue;
1167 posx.push_back( trackstartPoint.X() );
1168 posy.push_back( trackstartPoint.Y() );
1169 posz.push_back( trackstartPoint.Z() );
1171 dirx.push_back( mom.X() );
1172 diry.push_back( mom.Y() );
1173 dirz.push_back( mom.Z() );
1207 double theta_xz = std::atan2(dirx.front(), dirz.front());
1208 double theta_yz = std::atan2(diry.front(), dirz.front());
1227 fPhi. push_back( track.
Phi() );
1229 posx.clear(); posy.clear(); posz.clear();
1230 dirx.clear(); diry.clear(); dirz.clear();
1238 for(
const auto& mcPartHitVecPair : trackMCPair.second)
1240 const simb::MCParticle* mcParticle = mcPartHitVecPair.first;
1243 if (!mcParticle)
continue;
1246 geo::Point_t vtxPoint(mcParticle->Vx(), mcParticle->Vy(), mcParticle->Vz());
1250 if (!tpcGeo)
continue;
1251 if (tpcGeo->ID() != C0id)
continue;
1252 if (!tpcGeo->ActiveBoundingBox().ContainsPosition(vtxPoint))
continue;
1255 size_t minTrajIdx = std::numeric_limits<size_t>::max();
1256 size_t maxTrajIdx = 0;
1258 for(
const auto&
hit : mcPartHitVecPair.second)
1266 flocx.push_back(loc.X());
1267 flocy.push_back(loc.Y());
1268 flocz.push_back(loc.Z());
1273 size_t trajIdx = hitToMcPartToIdxMap[
hit].front().second;
1275 minTrajIdx = std::min(minTrajIdx,trajIdx);
1276 maxTrajIdx = std::max(maxTrajIdx,trajIdx);
1281 if (mcParticle->Px(maxTrajIdx) == 0 && mcParticle->Py(maxTrajIdx) == 0 && mcParticle->Pz(maxTrajIdx) == 0) maxTrajIdx -= 1;
1286 TVector3 minPointDir(mcParticle->Px(minTrajIdx),mcParticle->Py(minTrajIdx),mcParticle->Pz(minTrajIdx));
1287 TVector3 maxPointDir(mcParticle->Px(maxTrajIdx),mcParticle->Py(maxTrajIdx),mcParticle->Pz(maxTrajIdx));
1291 if (!(maxPointDir.Mag() > 0.)) {maxTrajIdx -= 1; maxPointDir=TVector3(mcParticle->Px(maxTrajIdx),mcParticle->Py(maxTrajIdx),mcParticle->Pz(maxTrajIdx));}
1292 if (!(minPointDir.Mag() > 0.)) {minTrajIdx -= 1; minPointDir=TVector3(mcParticle->Px(minTrajIdx),mcParticle->Py(minTrajIdx),mcParticle->Pz(minTrajIdx));}
1299 minPointDir.SetMag(1.);
1300 maxPointDir.SetMag(1.);
1302 fmctstartx.push_back(mcParticle->Vx(minTrajIdx));
1303 fmctstarty.push_back(mcParticle->Vy(minTrajIdx));
1304 fmctstartz.push_back(mcParticle->Vz(minTrajIdx));
1306 fmctendx.push_back(mcParticle->Vx(maxTrajIdx));
1307 fmctendy.push_back(mcParticle->Vy(maxTrajIdx));
1308 fmctendz.push_back(mcParticle->Vz(maxTrajIdx));
1318 fmctThetaXZ.push_back( std::atan2(minPointDir.X(), minPointDir.Z()) );
1319 fmctThetaYZ.push_back( std::atan2(minPointDir.Y(), minPointDir.Z()) );
1321 fmctTheta. push_back( minPointDir.Theta() );
1322 fmctPhi. push_back( minPointDir.Phi() );
1328 std::vector<double>
x,
y,
z, t;
1329 std::vector<double>
px,
py,
pz,
e;
1330 TLorentzVector dir_start;
1334 for (
unsigned int i=0; i<mcParticle->NumberTrajectoryPoints(); i++)
1336 const TLorentzVector& pos = mcParticle->Position(i);
1337 const TLorentzVector& mom = mcParticle->Momentum(i);
1348 if (!tpcGeo)
continue;
1349 if (tpcGeo->ID() != C0id)
continue;
1350 if (!tpcGeo->ActiveBoundingBox().ContainsPosition(trackPoint))
continue;
1356 x.push_back(pos.X());
1357 y.push_back(pos.Y());
1358 z.push_back(pos.Z());
1359 t.push_back(pos.T());
1361 px.push_back(mom.X());
1362 py.push_back(mom.Y());
1363 pz.push_back(mom.Z());
1364 e.push_back(mom.T());
1394 dir_start.SetPxPyPzE(px.front(),py.front(),pz.front(),e.front());
1396 fmcThetaXZ.push_back( std::atan2(px.front(), pz.front()) );
1397 fmcThetaYZ.push_back( std::atan2(py.front(), pz.front()) );
1399 fmcTheta. push_back( dir_start.Theta() );
1400 fmcPhi. push_back( dir_start.Phi() );
1403 x.clear(); y.clear(); z.clear(); t.clear();
1404 px.clear(); py.clear(); pz.clear(); e.clear();
1468 std::cout <<
"-- final quick loop to fill summary hists" << std::endl;
1472 if (nSimChannelHitVec[idx] > 10)
1474 float hitEfficiency = float(nRecobHitVec[idx]) / float(nSimChannelHitVec[idx]);
1480 fNFakeHitVec.push_back(nFakeHitVec[idx]/(
float)nSimulatedWiresVec[idx]);
1492 std::cout <<
"-- fill the tree" << std::endl;
geo::TPCID const & ID() const
Returns the identifier of this TPC.
short int LocalIndex() const
How well do we believe we know this hit?
std::vector< float > fmcenddiry
Store parameters for running LArG4.
process_name opflash particleana ie ie ie z
std::vector< float > frecoenddirx
std::vector< float > frecoendz
std::vector< float > fmcstartz
std::vector< float > fmcpartpz
std::vector< float > fmcendy
std::vector< int > fHitStopTickVec
art::ServiceHandle< art::TFileService > tfs
Utilities related to art service access.
BEGIN_PROLOG true icarus_rawdigitfilter FilterTools FilterPlane1 Plane
std::vector< float > fmcstartx
Encapsulate the construction of a single cyostat.
std::vector< float > fmctendz
std::vector< float > fmctThetaYZ
float ftotalelctroncut
Threshold for electron (10k)
process_name opflash particleana ie x
std::vector< float > flocy
std::vector< TProfile * > fHitEffvselecVec
art::InputTag fSimEnergyProducerLabel
std::vector< float > fmcparte
Vector_t const & MomentumVectorAtPoint(size_t i) const
geo::WireID WireID() const
float RMS() const
RMS of the hit shape, in tick units.
std::vector< float > fHitPeakRMSVec
std::vector< float > fmctendy
std::vector< float > frecostartz
std::vector< float > fmcPhi
Declaration of signal hit object.
std::vector< int > fHitStartTickVec
std::vector< float > frecoendx
Point_t const & LocationAtPoint(size_t i) const
Geometry information for a single TPC.
std::vector< float > frecostartdirz
const geo::GeometryCore * fGeometry
pointer to Geometry service
std::vector< float > fmctThetaXZ
std::vector< float > fLength
size_t NumberTrajectoryPoints() const
Various functions related to the presence and the number of (valid) points.
std::vector< float > fmctPhi
geo::BoxBoundedGeo const & ActiveBoundingBox() const
Returns the box of the active volume of this TPC.
geo::TPCGeo const * PositionToTPCptr(geo::Point_t const &point) const
Returns the TPC at specified location.
int DegreesOfFreedom() const
std::vector< geo::WireID > ChannelToWire(raw::ChannelID_t const channel) const
Returns a list of wires connected to the specified TPC channel.
std::vector< int > fHitLocalIndexVec
Definition of basic raw digits.
float Integral() const
Integral under the calibrated signal waveform of the hit, in tick x ADC units.
process_name use argoneut_mc_hitfinder track
std::vector< float > fNRecobHitVec
std::vector< float > frecostartdiry
std::vector< float > fmctstartdiry
float GoodnessOfFit() const
Degrees of freedom in the determination of the hit signal shape (-1 by default)
short int Multiplicity() const
How many hits could this one be shared with.
std::vector< float > fThetaXZ
std::vector< float > fPartDirZ
std::vector< float > fmctstartdirz
std::vector< float > fmcThetaXZ
std::vector< float > fmctenddirx
std::vector< float > fmcpartpy
std::vector< int > fPlaneVec
std::vector< art::InputTag > fWireProducerLabelVec
std::vector< int > fNumDegreesVec
float PeakAmplitude() const
The estimated amplitude of the hit at its peak, in ADC units.
std::vector< float > fHitSummedADCVec
std::vector< int > fHitMultiplicityVec
std::vector< float > fNFakeHitVec
ThroughgoingmuonAnalyzer & operator=(ThroughgoingmuonAnalyzer const &)=delete
std::vector< float > fmcTheta
std::vector< float > fmcstartdiry
unsigned int Nplanes(unsigned int tpc=0, unsigned int cstat=0) const
Returns the total number of wire planes in the specified TPC.
std::vector< float > fmcpartpx
std::vector< float > fmcendz
double Length(size_t p=0) const
Access to various track properties.
process_name opflash particleana ie ie y
std::vector< float > fmcThetaYZ
std::vector< int > fNMatchedHits
std::vector< float > fPartDirX
std::vector< float > fTheta
std::vector< float > frecoenddirz
art::InputTag fBadChannelProducerLabel
int fSimTrackID
GEANT ID of the particle being processed.
double Theta() const
Access to spherical or geographical angles at vertex or at any point.
ThroughgoingmuonAnalyzer(fhicl::ParameterSet const &pset)
std::vector< float > fSigmaVec
Window size for matching to SimChannels.
std::vector< int > fWireVec
std::vector< float > frecoenddiry
std::vector< int > fStopTickVec
std::vector< float > fmcpartvz
tick_as<> tick
Tick number, represented by std::ptrdiff_t.
virtual Status_t Status(raw::ChannelID_t channel) const
Returns a status integer with arbitrary meaning.
std::vector< int > fStartTickVec
std::vector< float > fTotalElecEnergyVec
Class providing information about the quality of channels.
PlaneID_t Plane
Index of the plane within its TPC.
Description of geometry of one entire detector.
std::vector< float > fThetaYZ
int fSimPDG
PDG ID of the particle being processed.
Provides recob::Track data product.
auto norm(Vector const &v)
Return norm of the specified vector.
std::vector< float > fmcstartdirx
std::vector< art::InputTag > fRawDigitProducerLabelVec
std::vector< float > fmctstartz
std::vector< float > fHitBaselinevec
std::vector< float > frecostartdirx
std::vector< float > fmcpartvx
std::vector< float > fNSimChannelHitsVec
float PeakTime() const
Time of the signal peak, in tick units.
std::vector< art::InputTag > fHitProducerLabelVec
std::vector< float > fmcenddirx
std::vector< float > frecostartx
std::vector< int > fMaxETickVec
std::vector< float > fPhi
std::vector< float > fmctendx
std::vector< art::InputTag > fTrackProducerLabelVec
process_name physics producers generator physics producers generator physics producers generator py
std::vector< float > fmcstartdirz
std::vector< float > fmctTheta
std::string to_string(WindowPattern const &pattern)
art::InputTag fMCParticleProducerLabel
contains information for a single step in the detector simulation
std::vector< float > fmcenddirz
int fMinAllowedChanStatus
Don't consider channels with lower status.
std::vector< float > flocx
std::vector< float > fHitIntegralVec
std::vector< float > fHitPeakAmpVec
object containing MC truth information necessary for making RawDigits and doing back tracking ...
std::vector< float > fmcstarty
std::vector< float > flocz
Interface for experiment-specific channel quality info provider.
float SummedADC() const
The sum of calibrated ADC counts of the hit (0. by default)
std::vector< float > fTotalElectronsVec
std::vector< int > fCryoVec
Declaration of basic channel signal object.
std::vector< float > fmctstartdirx
std::vector< float > fmctstartx
2D representation of charge deposited in the TDC/wire plane
art::ServiceHandle< art::TFileService > tfs
std::vector< float > fmctenddiry
std::vector< float > fPartDirY
std::vector< float > fHitGoodnessVec
Interface for experiment-specific service for channel quality info.
std::vector< float > fmctenddirz
std::vector< float > fHitEfficiencyVec
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Point_t
Type for representation of position in physical 3D space.
std::vector< float > fmcpartvy
int fRun
number of the run being processed
std::vector< int > fOffsetVec
Allow offsets for each plane.
int fEvent
number of the event being processed
std::vector< float > fMaxElectronsVec
std::vector< float > frecoendy
void analyze(art::Event const &evt) override
bool ContainsPosition(geo::Point_t const &point, double wiggle=1.0) const
Returns whether this volume contains the specified point.
std::vector< float > fmcendx
std::vector< int > fNMatchedWires
std::vector< float > fHitPeakTimeVec
art framework interface to geometry description
BEGIN_PROLOG could also be cout
Track from a non-cascading particle.A recob::Track consists of a recob::TrackTrajectory, plus additional members relevant for a "fitted" track:
std::vector< float > fmctstarty
The data type to uniquely identify a cryostat.
std::vector< float > frecostarty
std::vector< int > fTPCVec
art::InputTag fSimChannelProducerLabel