9 #include "art/Framework/Core/ModuleMacros.h"
10 #include "art/Framework/Core/EDFilter.h"
13 #include "art/Framework/Principal/Event.h"
14 #include "fhiclcpp/ParameterSet.h"
15 #include "art/Framework/Principal/Handle.h"
16 #include "art/Framework/Services/Registry/ServiceHandle.h"
17 #include "canvas/Persistency/Common/Ptr.h"
18 #include "canvas/Persistency/Common/PtrVector.h"
19 #include "cetlib_except/exception.h"
20 #include "canvas/Persistency/Common/FindManyP.h"
21 #include "canvas/Persistency/Common/FindOneP.h"
24 #include "nug4/ParticleNavigation/ParticleList.h"
25 #include "nusimdata/SimulationBase/MCTruth.h"
66 fMinKE (pset.get<
double > (
"MinEnergy" , 0.0) )
67 , fKeepOnlyMuons (pset.get<
bool > (
"KeepOnlyMuons",
false) )
68 , fMinT (pset.get<
double > (
"MinT",0.0) )
69 , fMaxT (pset.get<
double > (
"MaxT") )
70 , fSortParticles ( pset.get<
bool > (
"SortParticles",
false) )
71 , fAlwaysPass (pset.get<
bool>(
"AlwaysPass",
false))
74 produces< std::vector<simb::MCTruth> >(
"intime");
75 produces< std::vector<simb::MCTruth> >(
"outtime");
82 auto const& geom = *art::ServiceHandle<geo::Geometry const>();
83 for (
auto const &cryo: geom.IterateCryostats()) {
84 std::array<double, 6> this_cryo_boundaries {};
85 cryo.Boundaries(&this_cryo_boundaries[0]);
92 const TLorentzVector& v4 = part.Position();
93 const TLorentzVector& p4 = part.Momentum();
95 double x0[3] = {v4.X(), v4.Y(), v4.Z() };
97 double dx[3] = {p4.Px() / p4.Vect().Mag(), p4.Py() / p4.Vect().Mag(), p4.Pz() / p4.Vect().Mag()};
113 std::array<int, 3> quadrant {};
114 std::array<double, 3> candidatePlane {};
115 std::array<double, 3>
coord {};
117 std::array<double, 3> bound_lo = {{bound[0], bound[2], bound[4]}};
118 std::array<double, 3> bound_hi = {{bound[1], bound[3], bound[5]}};
124 for (
int i = 0; i < 3; i++) {
125 if (x0[i] < bound_lo[i]) {
127 candidatePlane[i] = bound_lo[i];
130 else if (x0[i] > bound_hi[i]) {
132 candidatePlane[i] = bound_hi[i];
141 inside_cryo[i_cryo] =
true;
143 intersects_cryo[i_cryo] =
true;
150 std::array<double, 3> maxT {};
151 for (
int i = 0; i < 3; i++) {
152 if (quadrant[i] != 2 &&
abs(dx[i]) > eps) {
153 maxT[i] = (candidatePlane[i] - x0[i]) / dx[i];
163 for (
int i = 1; i < 3; i++) {
164 if (maxT[whichPlane] < maxT[i]) whichPlane = i;
170 if (maxT[whichPlane] < 0.) {
171 intersects_cryo[i_cryo] =
false;
175 for (
int i = 0; i < 3; i++) {
176 if (whichPlane != i) {
177 coord[i] = x0[i] + maxT[whichPlane] * dx[i];
180 coord[i] = candidatePlane[i];
186 intersects_cryo[i_cryo] =
true;
187 for (
int i = 0; i < 3; i++) {
188 if (
coord[i] < bound_lo[i] ||
coord[i] > bound_hi[i]) {
189 intersects_cryo[i_cryo] =
false;
193 if (intersects_cryo[i_cryo]) {
194 distance_to_cryo[i_cryo] = maxT[whichPlane];
204 if (inside_cryo[i_cryo]) {
208 if (intersects_cryo[i_cryo]){
209 double ptime = (distance_to_cryo[i_cryo] * 1
e-2 ) / (TMath::C()*sqrt(1-pow(part.Mass()/part.E(),2))) ;
210 double totT=part.T()+ptime*1e9 ;
224 std::unique_ptr< std::vector<simb::MCTruth> > truthInTimePtr(
new std::vector<simb::MCTruth>(1));
225 std::unique_ptr< std::vector<simb::MCTruth> > truthOutOfTimePtr(
new std::vector<simb::MCTruth>(1));
227 simb::MCTruth & truthInTime = truthInTimePtr->at(0);
228 simb::MCTruth & truthOutOfTime = truthOutOfTimePtr->at(0);
232 art::ServiceHandle<geo::Geometry const> geom;
236 auto allmclists = evt.getMany< std::vector<simb::MCTruth> >();
237 bool keepEvent=
false;
238 for(
size_t mcl = 0; mcl < allmclists.size(); ++mcl){
239 art::Handle< std::vector<simb::MCTruth> > mclistHandle = allmclists[mcl];
240 for(
size_t m = 0;
m < mclistHandle->size(); ++
m){
241 art::Ptr<simb::MCTruth> mct(mclistHandle,
m);
243 for(
int ipart=0;ipart<mct->NParticles();ipart++){
248 && mct->GetParticle(ipart).E()-mct->GetParticle(ipart).Mass()>
fMinKE){
254 simb::MCParticle particle = mct->GetParticle(ipart);
255 if(kp) truthInTime.Add(particle);
256 if(!kp) truthOutOfTime.Add(particle);
270 evt.put(std::move(truthInTimePtr),
"intime");
271 evt.put(std::move(truthOutOfTimePtr),
"outtime");
279 namespace simfilter {
281 DEFINE_ART_MODULE(FilterGenInTime)
auto coord(Vector &v, unsigned int n) noexcept
Returns an object to manage the coordinate n of a vector.
std::vector< std::array< double, 6 > > fCryostatBoundaries
boundaries of each cryostat
tuple m
now if test mode generate materials, CRT shell, world, gdml header else just generate CRT shell for u...
FilterGenInTime(fhicl::ParameterSet const &pset)
bool filter(art::Event &)
bool KeepParticle(simb::MCParticle const &part) const
Tools and modules for checking out the basics of the Monte Carlo.
art framework interface to geometry description
BEGIN_PROLOG could also be cout