All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CosmicIdUtils.cc
Go to the documentation of this file.
1 #include "CosmicIdUtils.h"
2 
3 namespace sbnd{
4 
5 // =============================== UTILITY FUNCTIONS ==============================
6 
7  // Create fake PDS optical flashes from true particle energy deposits
8  std::pair<std::vector<double>, std::vector<double>> CosmicIdUtils::FakeTpcFlashes(std::vector<simb::MCParticle> particles){
9  //
10  TPCGeoAlg fTpcGeo;
11 
12  // Create fake flashes in each tpc
13  std::vector<double> fakeTpc0Flashes;
14  std::vector<double> fakeTpc1Flashes;
15 
16  // FIXME probably shouldn't be here
17  //double readoutWindowMuS = fDetectorClocks->TPCTick2Time((double)fDetectorProperties->ReadOutWindowSize()); // [us]
18  //double driftTimeMuS = fTpcGeo.MaxX()/fDetectorProperties->DriftVelocity(); // [us]
19 
20  // Loop over all true particles
21  for (auto const particle: particles){
22 
23  // Get particle info
24  int pdg = std::abs(particle.PdgCode());
25  double time = particle.T() * 1e-3;
26 
27  //Check if time is in reconstructible window
28  //if(time < -driftTimeMuS || time > readoutWindowMuS) continue;
29  //Check if particle is visible, electron, muon, proton, pion, kaon, photon
30  if(!(pdg==13||pdg==11||pdg==22||pdg==2212||pdg==211||pdg==321||pdg==111)) continue;
31 
32  //Loop over the trajectory
33  int npts = particle.NumberTrajectoryPoints();
34  double TPC0Energy = 0;
35  double TPC1Energy = 0;
36  for(int i = 1; i < npts; i++){
37  geo::Point_t pt;
38  pt.SetX(particle.Vx(i)); pt.SetY(particle.Vy(i)); pt.SetZ(particle.Vz(i));
39  if(!fTpcGeo.InFiducial(pt, 0, 0)) continue;
40  // Add up the energy deposited in each tpc
41  if(pt.X() <= 0) TPC0Energy += particle.E(i-1) - particle.E(i);
42  else TPC1Energy += particle.E(i-1) - particle.E(i);
43  }
44  // If the total energy deposited is > 10 MeV then create fake flash
45  if(TPC0Energy > 0.01) fakeTpc0Flashes.push_back(time);
46  else if(TPC1Energy > 0.01) fakeTpc1Flashes.push_back(time);
47  }
48 
49  std::sort(fakeTpc0Flashes.begin(), fakeTpc0Flashes.end());
50  double previousTime = -99999;
51  // Loop over flashes in tpc 0
52  for(size_t i = 0; i < fakeTpc0Flashes.size(); i++){
53  double time = fakeTpc0Flashes[i];
54  // Combine flashes within 0.01 us
55  if(std::abs(time-previousTime) < 0.01){
56  fakeTpc0Flashes.erase(fakeTpc0Flashes.begin()+i);
57  }
58  else previousTime = time;
59  }
60 
61  std::sort(fakeTpc1Flashes.begin(), fakeTpc1Flashes.end());
62  previousTime = -99999;
63  // Loop over flashes in tpc 1
64  for(size_t i = 0; i < fakeTpc1Flashes.size(); i++){
65  double time = fakeTpc1Flashes[i];
66  // Combine flashes within 0.01 us
67  if(std::abs(time-previousTime) < 0.01){
68  fakeTpc1Flashes.erase(fakeTpc1Flashes.begin()+i);
69  }
70  else previousTime = time;
71  }
72 
73  return std::make_pair(fakeTpc0Flashes, fakeTpc1Flashes);
74  }
75 
76  // Determine if there is a PDS flash in time with the neutrino beam
77  bool CosmicIdUtils::BeamFlash(std::vector<double> flashes, double beamTimeMin, double beamTimeMax){
78  //
79  bool beamFlash = false;
80  std::sort(flashes.begin(), flashes.end());
81  // Loop over flashes in tpc 0
82  for(size_t i = 0; i < flashes.size(); i++){
83  double time = flashes[i];
84  if(time > beamTimeMin && time < beamTimeMax) beamFlash = true;
85  }
86 
87  return beamFlash;
88  }
89 
90 }
var pdg
Definition: selectors.fcl:14
bool BeamFlash(std::vector< double > flashes, double beamTimeMin, double beamTimeMax)
T abs(T value)
do i e
std::pair< std::vector< double >, std::vector< double > > FakeTpcFlashes(std::vector< simb::MCParticle > particles)
Definition: CosmicIdUtils.cc:8
stream1 can override from command line with o or output services user sbnd
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Point_t
Type for representation of position in physical 3D space.
Definition: geo_vectors.h:184
bool InFiducial(geo::Point_t point, double fiducial)