26 #include "dune/OpticalDetector/OpFlashSort.h" 39 #include "art_root_io/TFileService.h" 40 #include "art_root_io/TFileDirectory.h" 43 #include "canvas/Persistency/Common/FindManyP.h" 91 #endif // FlashMatchAna_H 113 hFlashPurity = tfs->make<TH1D>(
"hFlashPurity",
"",50,0.499,1.001);
117 hNFlash = tfs->make<TH1D>(
"hNFlash",
"",50,0,400);
118 hNHitPerFlash = tfs->make<TH1D>(
"hNHitPerFlash",
"",50,0,100);
119 hFlashTimes = tfs->make<TH1D>(
"hFlashTimes",
"",100,-4000,4000);
120 hHitTimes = tfs->make<TH1D>(
"hHitTimes",
"",100,-4000,4000);
121 hPurityTimeDiff = tfs->make<TH2D>(
"hPurityTimeDiff",
"",25,-5,5,25,0.499,1.001);
142 std::vector<art::Ptr<recob::OpFlash> > flashlist;
154 std::map<int,double> trueTimeID;
171 hNFlash->Fill(FlashHandle->size());
177 std::map<int,double> flashMap;
180 for(
unsigned int i = 0; i < FlashHandle->size(); ++i)
187 std::vector< art::Ptr<recob::OpHit> > matchedHits = Assns.at(i);
190 flashMap.insert(std::make_pair(i,TheFlash.
Time() - clockData.TriggerOffsetTPC()));
195 for(
auto const h : matchedHits){
206 double bestPurity = 0;
207 double minTimeDiff = 1e20;
210 for(
auto &
m : trueTimeID){
212 double dist = fabs(
m.second - TheFlash.
Time());
213 if(dist < minTimeDiff){
215 std::set<int> trackIDs;
216 trackIDs.emplace(
m.first);
218 if(purity < 0.5)
continue;
226 if(minTimeDiff > 1000){
230 if(bestPurity >= 0.5) std::cout <<
"Best true time matched particle " << bestMatch <<
" has delta T = " << minTimeDiff <<
" and gives a purity " << bestPurity <<
std::endl;
245 for (
size_t p = 0;
p != particleHandle->size(); ++
p){
247 const auto thisParticle = (*particleHandle)[
p];
250 if(!(thisParticle.IsPrimary()))
continue;
253 std::vector<anab::T0> t0s = pfpUtil.GetPFParticleT0(thisParticle,evt,
fParticleLabel);
254 if(t0s.size() == 0)
continue;
257 double recoT0 = t0s[0].Time() / 1000.;
259 int bestRecoMatch = 0;
260 double minRecoTimeDiff = 1e20;
263 for(
auto &
m : flashMap){
264 double dist = fabs(recoT0 -
m.second);
265 if(dist < minRecoTimeDiff){
266 minRecoTimeDiff =
dist;
267 bestRecoMatch =
m.first;
271 std::cout <<
"Particle " <<
p <<
" has a TPC T0 = " << recoT0 <<
std::endl;
273 if(minRecoTimeDiff > 100){
274 std::cout <<
"No sensible reco match to flash " <<
p <<
std::endl;
276 std::cout <<
"Best matched flash " << bestRecoMatch <<
" has delta T = " << minRecoTimeDiff <<
std::endl;
288 auto MCTruthsHandle = evt.
getValidHandle<std::vector<simb::MCTruth> >(moduleName);
290 if (thisMCTruth->NParticles() == 0) {
291 mf::LogError(
"FlashMatchAna") <<
"No Cosmic MCTruth Particles";
293 else std::cout <<
"MCTruth from " << moduleName <<
" has " << thisMCTruth->NParticles() <<
" particles " <<
std::endl;
296 art::FindManyP<simb::MCParticle> geantAssns(MCTruthsHandle,evt,
fGeantLabel);
298 for (
size_t i = 0; i < geantAssns.size(); i++) {
299 auto parts = geantAssns.at(i);
301 for (
auto part = parts.begin(); part != parts.end(); part++) {
303 timeMap.insert(std::make_pair((*part)->TrackId(),(*part)->T()/1000.));
305 std::cout <<
"Found " << counter <<
" GEANT particles associated to " << moduleName <<
" MCTruth " << i <<
std::endl;
std::string fOpFlashModuleLabel
Handle< PROD > getHandle(SelectorBase const &) const
void ExtractTrueTimes(const std::string &moduleName, std::map< int, double > &timeMap, const art::Event &evt)
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
EDAnalyzer(fhicl::ParameterSet const &pset)
const double OpHitCollectionPurity(std::set< int > const &tkIds, std::vector< art::Ptr< recob::OpHit > > const &opHits_Ps)
std::string fParticleLabel
#define DEFINE_ART_MODULE(klass)
T get(std::string const &key) const
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
struct recob::OpFlashPtrSortByPE_t OpFlashPtrSortByPE
constexpr double dist(const TReal *x, const TReal *y, const unsigned int dimension)
void analyze(const art::Event &)
std::string fOpHitModuleLabel
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
ProtoFlash(const fhicl::ParameterSet &)
QTextStream & endl(QTextStream &s)