37 #include "canvas/Persistency/Common/FindManyP.h" 43 #include "art_root_io/TFileService.h" 80 void endJob()
override;
87 bool insideFidVol(
double pos[3]);
91 double radius,
double end[3],
96 int trackMatching (
int trackIndex,
97 art::FindManyP<recob::Hit> hitsFromTracks);
101 std::vector<simb::MCParticle> particles);
106 const std::vector<recob::Hit> & hits );
120 int fNumberCloseHitsStart[3];
121 int fNumberCloseHitsEnd[3];
140 fCalorimetryAlg(p.
get<
fhicl::ParameterSet>(
"CalorimetryAlg"))
150 void MichelReco::endJob()
154 std::ofstream michelRecoOut;
155 michelRecoOut.open(
"test.txt");
156 michelRecoOut <<
"nMichel Purity Efficiency" <<
std::endl;
158 double purity = fYesSelected / ( fYesSelected + fNoSelected );
159 double efficiency = fYesSelected/ fNMichel;
161 michelRecoOut << fNMichel <<
" " << purity <<
" " << efficiency <<
std::endl;
162 michelRecoOut.close();
174 std::cout <<
"Michel event selection is on event " << fEvNumber <<
std::endl;
177 auto const & particles = *evt.
getValidHandle<std::vector<simb::MCParticle>>( fParticleModuleLabel );
178 for (
auto const & particle : particles ) {
179 if (
abs(particle.PdgCode()) == 13 ) {
180 double mcEnd[3] = { particle.EndX(), particle.EndY(), particle.EndZ() };
181 if ( isMuonDecaying( particle, particles ) && insideFidVol( mcEnd ) ) {
188 auto const & trackHandle = evt.
getValidHandle<std::vector<recob::Track>>( fTrackModuleLabel );
189 auto const &
tracks = * trackHandle;
190 art::FindManyP<recob::Hit> hitsFromTracks( trackHandle, evt, fTrackModuleLabel );
196 for (
auto const & track : tracks) {
202 auto const & trackStart = track.Vertex<TVector3>();
203 double start[3] = { trackStart.X(), trackStart.Y(), trackStart.Z() };
204 auto const & trackEnd = track.End<TVector3>();
205 double end[3] = { trackEnd.X(), trackEnd.Y(), trackEnd.Z() };
208 bool startInFidVol = insideFidVol( start );
209 bool endInFidVol = insideFidVol( end );
210 if ( startInFidVol || endInFidVol ) {
213 for (
int plane = 0; plane < 3; plane++) {
214 fNumberCloseHitsStart[ plane ] = 0; fNumberCloseHitsEnd[ plane ] = 0;
221 std::vector< recob::Hit > taggedHitsStart;
222 std::vector< recob::Hit > taggedHitsEnd;
223 for (
size_t h = 0;
h < hitResults.
size(); ++
h ) {
226 std::array<float,4> cnn_out = hitResults.
getOutput(
h );
229 if ( cnn_out[hitResults.
getIndex(
"michel")] > fCNNThreshold ) {
232 if ( startInFidVol ) {
235 for (
int plane = 0; plane < 3; plane++ ) {
240 double start2D[2] = {trackStart2D.X(), trackStart2D.Y()};
244 if (hit.
View() == plane) {
248 if ( hitCloseToTrackEnd( detProp, fRadiusThreshold, start, start2D, hit, geom ) ) {
249 fNumberCloseHitsStart[ plane ] += 1;
250 if ( plane == 2 ) { taggedHitsStart.push_back( hit ); };
261 for (
int plane = 0; plane < 3; plane++ ) {
266 double end2D[2] = {trackEnd2D.X(), trackEnd2D.Y()};
270 if (hit.
View() == plane) {
274 if ( hitCloseToTrackEnd( detProp, fRadiusThreshold, end, end2D, hit, geom ) ) {
275 fNumberCloseHitsEnd[ plane ] += 1;
276 if ( plane == 2 ) { taggedHitsEnd.push_back( hit ); }
290 bool startSelected = ( fNumberCloseHitsStart[0] > fNumberThreshold && fNumberCloseHitsStart[1] > fNumberThreshold && fNumberCloseHitsStart[2] > fNumberThreshold );
291 bool endSelected = ( fNumberCloseHitsEnd[0] > fNumberThreshold && fNumberCloseHitsEnd[1] > fNumberThreshold && fNumberCloseHitsEnd[2] > fNumberThreshold );
292 bool eventSelected = ( startSelected || endSelected );
293 if ( startSelected && endSelected ) { eventSelected =
false; }
297 bool particleIsMichel(
false);
299 if ( startSelected ) { particleIsMichel = areHitsMichel(clockData, taggedHitsStart); }
300 if ( endSelected ) { particleIsMichel = areHitsMichel(clockData, taggedHitsEnd); }
304 if ( particleIsMichel && eventSelected ) {
372 if ( !particleIsMichel && eventSelected ) {
484 bool MichelReco::isMuonDecaying (
simb::MCParticle particle, std::vector<simb::MCParticle> particles ) {
486 bool hasElectron =
false, hasNuMu =
false, hasNuE =
false;
489 for (
size_t d = 0;
d < nSec; ++
d)
491 for (
auto const & daughter : particles)
493 if (daughter.Mother() == particle.
TrackId())
495 int d_pdg =
abs(daughter.PdgCode());
496 if (d_pdg == 11) hasElectron =
true;
497 else if (d_pdg == 14) hasNuMu =
true;
498 else if (d_pdg == 12) hasNuE =
true;
502 return (hasElectron && hasNuMu && hasNuE);
507 bool MichelReco::insideFidVol(
double pos[3] ) {
517 double minx = tpcgeo.
MinX();
double maxx = tpcgeo.
MaxX();
518 double miny = tpcgeo.
MinY();
double maxy = tpcgeo.
MaxY();
519 double minz = tpcgeo.
MinZ();
double maxz = tpcgeo.
MaxZ();
521 for (
size_t cryo = 0; cryo < geom.
Ncryostats(); cryo++) {
523 for (
size_t tpc = 0; tpc < cryostat.
NTPC(); tpc++) {
525 if (tpcg.
MinX() < minx) minx = tpcg.
MinX();
526 if (tpcg.
MaxX() > maxx) maxx = tpcg.
MaxX();
527 if (tpcg.
MinY() < miny) miny = tpcg.
MinY();
528 if (tpcg.
MaxY() > maxy) maxy = tpcg.
MaxY();
529 if (tpcg.
MinZ() < minz) minz = tpcg.
MinZ();
530 if (tpcg.
MaxZ() > maxz) maxz = tpcg.
MaxZ();
534 double dista = fabs(minx - pos[0]);
535 double distb = fabs(pos[0] - maxx);
536 if ((pos[0] > minx) && (pos[0] < maxx) &&
537 (dista > fFidVolCut) && (distb > fFidVolCut)) inside =
true;
539 dista = fabs(miny - pos[1]);
540 distb = fabs(pos[1]-maxy);
541 if (inside && (pos[1] > miny) && (pos[1] < maxy) &&
542 (dista > fFidVolCut) && (distb > fFidVolCut)) inside =
true;
545 dista = fabs(minz - pos[2]);
546 distb = fabs(pos[2] - maxz);
547 if (inside && (pos[2] > minz) && (pos[2] < maxz) &&
548 (dista > fFidVolCut) && (distb > fFidVolCut)) inside =
true;
564 double deltaXToHit = hitLocation.X() - end2D[0];
565 double deltaYToHit = hitLocation.Y() - end2D[1];
567 double displacementToHit =
pow(
pow(deltaXToHit,2)+
pow(deltaYToHit,2),0.5);
569 if (displacementToHit < radius) close =
true;
577 const std::vector< recob::Hit > & hits ) {
583 std::unordered_map< int, double > trkIDE;
584 for (
auto const &
hit : hits ) {
585 for (
auto const & ide : bt_serv->
HitToTrackIDEs(clockData,
hit) ) { trkIDE[ide.trackID] += ide.energy; }
589 double tot_e(0), max_e(0);
590 for (
auto const & contrib : trkIDE ) {
592 tot_e += contrib.second;
593 if ( contrib.second > max_e ) {
594 max_e = contrib.second;
595 best_id = contrib.first;
599 if ( (max_e > 0) && (tot_e > 0) ) {
606 if (mcParticle != 0) {
607 return (
abs(mcParticle->
PdgCode()) && ( mcParticle->
Process() ==
"Decay" || mcParticle->
Process() ==
"muMinusCaptureAtRest") ) ;
610 std::cout <<
"No match found" << hits.size() <<
std::endl;
618 c =
new TCanvas(
"canv",
"canv" );
624 fBestview = p.
get<
int>(
"Bestview");
626 fRadiusThreshold = p.
get<
double>(
"MichelCloseHitRadius");
627 fNumberThreshold = p.
get<
int>(
"CloseHitsThreshold");
628 fCNNThreshold = p.
get<
double>(
"CNNThreshSelect");
629 fFidVolCut = p.
get<
double>(
"FidVolCut");
631 for (
int plane = 0; plane < 3; plane++ ) {
632 fNumberCloseHitsStart[ plane ] = 0; fNumberCloseHitsEnd[ plane ] = 0;
def analyze(root, level, gtrees, gbranches, doprint)
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
Store parameters for running LArG4.
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
CryostatGeo const & GetElement(geo::CryostatID const &cryoid) const
std::vector< sim::TrackIDE > HitToTrackIDEs(detinfo::DetectorClocksData const &clockData, recob::Hit const &hit) const
Container of LAr voxel information.
const simb::MCParticle * TrackIdToParticle_P(int id) const
geo::WireID WireID() const
double MinX() const
Returns the world x coordinate of the start of the box.
Geometry information for a single TPC.
art::InputTag fNNetModuleLabel
int getIndex(const std::string &name) const
Index of column with given name, or -1 if name not found.
TVector2 WireDriftToCm(detinfo::DetectorPropertiesData const &detProp, unsigned int wire, float drift, unsigned int plane, unsigned int tpc, unsigned int cryo)
double MaxX() const
Returns the world x coordinate of the end of the box.
geo::View_t View() const
View for the plane of the hit.
WireID_t Wire
Index of the wire within its plane.
Geometry information for a single cryostat.
unsigned int Ncryostats() const
Returns the number of cryostats in the detector.
std::string Process() const
T const & item(size_t key) const
Access data product at index "key".
int NumberDaughters() const
art framework interface to geometry description
geo::TPCID FindTPCAtPosition(double const worldLoc[3]) const
Returns the ID of the TPC at specified location.
int close(int)
Closes the file descriptor fd.
Encapsulates the information we want store for a voxel.
#define DEFINE_ART_MODULE(klass)
virtual void reconfigure(fhicl::ParameterSet const &pset)
art::InputTag fParticleModuleLabel
T get(std::string const &key) const
double MinZ() const
Returns the world z coordinate of the start of the box.
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
unsigned int NTPC() const
Number of TPCs in this cryostat.
CryostatGeo const & Cryostat(geo::CryostatID const &cryoid) const
Returns the specified cryostat.
art::InputTag fTrackModuleLabel
size_t size() const
Get the number of contained items (no. of data product objects equal to no. of feature vectors)...
The data type to uniquely identify a TPC.
Description of geometry of one entire detector.
calo::CalorimetryAlg fCalorimetryAlg
Detector simulation of raw signals on wires.
double MaxY() const
Returns the world y coordinate of the end of the box.
bool HasTPC(geo::TPCID const &tpcid) const
Returns whether we have the specified TPC.
Implementation of the Projection Matching Algorithm.
float PeakTime() const
Time of the signal peak, in tick units.
Declaration of signal hit object.
Contains all timing reference information for the detector.
const TPCGeo & TPC(unsigned int itpc) const
Return the itpc'th TPC in the cryostat.
double MaxZ() const
Returns the world z coordinate of the end of the box.
TVector2 GetProjectionToPlane(const TVector3 &p, unsigned int plane, unsigned int tpc, unsigned int cryo)
Provides recob::Track data product.
EventNumber_t event() const
2D representation of charge deposited in the TDC/wire plane
auto const & get(AssnsNode< L, R, D > const &r)
TPCID_t TPC
Index of the TPC within its cryostat.
Collection of Physical constants used in LArSoft.
double MinY() const
Returns the world y coordinate of the start of the box.
geo::CryostatID::CryostatID_t FindCryostatAtPosition(geo::Point_t const &worldLoc) const
Returns the index of the cryostat at specified location.
std::array< float, N > getOutput(size_t key) const
Get copy of the MVA output vector at index "key".
QTextStream & endl(QTextStream &s)