Skip to content

Commit 2e219b7

Browse files
committed
update LightCaloProducer to conditionally fill TTree and enhance logging messages; avoid hardcoded TPC tick
1 parent 916b861 commit 2e219b7

1 file changed

Lines changed: 33 additions & 32 deletions

File tree

sbndcode/Calorimetry/LightCaloProducer_module.cc

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -269,21 +269,22 @@ sbnd::LightCaloProducer::LightCaloProducer(fhicl::ParameterSet const& p)
269269
geom = lar::providerFrom<geo::Geometry>();
270270

271271
art::ServiceHandle<art::TFileService> fs;
272-
_tree = fs->make<TTree>("lightcalo","");
273-
_tree->Branch("run", &_run, "run/I");
274-
_tree->Branch("subrun", &_subrun, "subrun/I");
275-
_tree->Branch("event", &_event, "event/I");
276-
_tree->Branch("pfpid", &_pfpid, "pfpid/I");
277-
_tree->Branch("opflash_time", &_opflash_time, "opflash_time/D");
278-
279-
_tree->Branch("rec_gamma", "std::vector<double>", &_rec_gamma);
280-
_tree->Branch("dep_pe", "std::vector<double>", &_dep_pe);
281-
_tree->Branch("visibility", "std::vector<double>", &_visibility);
282-
283-
_tree->Branch("slice_Q", &_slice_Q, "slice_Q/D");
284-
_tree->Branch("slice_L", &_slice_L, "slice_L/D");
285-
_tree->Branch("slice_E", &_slice_E, "slice_E/D");
286-
272+
if (ffill_tree){
273+
_tree = fs->make<TTree>("lightcalo","");
274+
_tree->Branch("run", &_run, "run/I");
275+
_tree->Branch("subrun", &_subrun, "subrun/I");
276+
_tree->Branch("event", &_event, "event/I");
277+
_tree->Branch("pfpid", &_pfpid, "pfpid/I");
278+
_tree->Branch("opflash_time", &_opflash_time, "opflash_time/D");
279+
280+
_tree->Branch("rec_gamma", "std::vector<double>", &_rec_gamma);
281+
_tree->Branch("dep_pe", "std::vector<double>", &_dep_pe);
282+
_tree->Branch("visibility", "std::vector<double>", &_visibility);
283+
284+
_tree->Branch("slice_Q", &_slice_Q, "slice_Q/D");
285+
_tree->Branch("slice_L", &_slice_L, "slice_L/D");
286+
_tree->Branch("slice_E", &_slice_E, "slice_E/D");
287+
}
287288
// Call appropriate produces<>() functions here.
288289
produces<std::vector<sbn::LightCalo>>();
289290
produces<art::Assns<recob::Slice, sbn::LightCalo>>();
@@ -325,21 +326,21 @@ void sbnd::LightCaloProducer::CalculateCalorimetry(art::Event& e,
325326
::art::Handle<std::vector<recob::Slice>> slice_h;
326327
e.getByLabel(fslice_producer, slice_h);
327328
if(!slice_h.isValid() || slice_h->empty()){
328-
std::cout << "don't have good slices!" << std::endl;
329+
std::cout << "[LightCaloProducer] : " << fslice_producer << " doesn't have good slices!" << std::endl;
329330
return;
330331
}
331332

332333
::art::Handle<std::vector<recob::PFParticle>> pfp_h;
333334
e.getByLabel(fslice_producer, pfp_h);
334335
if(!pfp_h.isValid() || pfp_h->empty()) {
335-
std::cout << "don't have good PFParticle!" << std::endl;
336+
std::cout << "[LightCaloProducer] : " << fslice_producer << " doesn't have good PFParticles!" << std::endl;
336337
return;
337338
}
338339

339340
::art::Handle<std::vector<recob::SpacePoint>> spacepoint_h;
340341
e.getByLabel(fslice_producer, spacepoint_h);
341342
if(!spacepoint_h.isValid() || spacepoint_h->empty()) {
342-
std::cout << "don't have good SpacePoints!" << std::endl;
343+
std::cout << "[LightCaloProducer] : " << fslice_producer << " don't have good SpacePoints!" << std::endl;
343344
return;
344345
}
345346

@@ -350,7 +351,7 @@ void sbnd::LightCaloProducer::CalculateCalorimetry(art::Event& e,
350351
::art::Handle<std::vector<recob::OpFlash>> flash_h;
351352
e.getByLabel(fopflash_producer_v[i], flash_h);
352353
if (!flash_h.isValid() || flash_h->empty()) {
353-
std::cout << "don't have good PMT flashes from producer " << fopflash_producer_v[i] << std::endl;
354+
std::cout << "[LightCaloProducer] : " << "don't have good PMT flashes from producer " << fopflash_producer_v[i] << std::endl;
354355
}
355356
else{
356357
if (fopflash_producer_v[i].find("tpc0") != std::string::npos)
@@ -376,7 +377,7 @@ void sbnd::LightCaloProducer::CalculateCalorimetry(art::Event& e,
376377
::art::Handle<std::vector<sbn::TPCPMTBarycenterMatch>> bcfm_h;
377378
e.getByLabel(fbcfm_producer, bcfm_h);
378379
if(!bcfm_h.isValid() || bcfm_h->empty()) {
379-
std::cout << "don't have good barycenter matches!" << std::endl;
380+
std::cout << "[LightCaloProducer] : " << "don't have good barycenter matches!" << std::endl;
380381
return;
381382
}
382383
std::vector<art::Ptr<sbn::TPCPMTBarycenterMatch>> bcfm_v;
@@ -385,15 +386,15 @@ void sbnd::LightCaloProducer::CalculateCalorimetry(art::Event& e,
385386
CollectMatches(bcfm_h, bcfm_v, fbcfm_producer, e, match_slices_v, match_op0, match_op1,
386387
[this](art::Ptr<sbn::TPCPMTBarycenterMatch> bcfm) {
387388
if (bcfm->flashTime > fopflash_max || bcfm->flashTime < fopflash_min) return false;
388-
if (bcfm->score < 0.02) return false;
389+
if (bcfm->score < fbcfmscore_cut) return false;
389390
return true;
390391
});
391392
}
392393
else if (fuse_opt0){
393394
::art::Handle<std::vector<sbn::OpT0Finder>> opt0_h;
394395
e.getByLabel(fopt0_producer, opt0_h);
395396
if(!opt0_h.isValid() || opt0_h->empty()) {
396-
std::cout << "don't have good OpT0Finder matches!" << std::endl;
397+
std::cout << "[LightCaloProducer] : " << "don't have good OpT0Finder matches!" << std::endl;
397398
return;
398399
}
399400
std::vector<art::Ptr<sbn::OpT0Finder>> opt0_v;
@@ -430,7 +431,7 @@ void sbnd::LightCaloProducer::CalculateCalorimetry(art::Event& e,
430431
::art::Handle<std::vector<recob::OpFlash>> flash_ara_h;
431432
e.getByLabel(fopflash_ara_producer_v[i], flash_ara_h);
432433
if (!flash_ara_h.isValid() || flash_ara_h->empty()) {
433-
std::cout << "don't have good X-ARAPUCA flashes from producer " << fopflash_ara_producer_v[i] << std::endl;
434+
std::cout << "[LightCaloProducer] : " << "don't have good X-ARAPUCA flashes from producer " << fopflash_ara_producer_v[i] << std::endl;
434435
}
435436
else{
436437
if (fopflash_ara_producer_v[i].find("tpc0") != std::string::npos)
@@ -467,7 +468,7 @@ void sbnd::LightCaloProducer::CalculateCalorimetry(art::Event& e,
467468

468469
for (size_t i=0; i < slice_hits_v.size(); i++){
469470
auto hit = slice_hits_v[i];
470-
auto drift_time = hit->PeakTime()*0.5 - clock_data.TriggerOffsetTPC();
471+
auto drift_time = clock_data.TPCTick2TrigTime(hit->PeakTime());
471472
double atten_correction = std::exp(drift_time/det_prop.ElectronLifetime()); // exp(us/us)
472473
auto hit_plane = hit->View();
473474
plane_charge.at(hit_plane) += hit->Integral()*atten_correction*(1/fcal_area_const.at(hit_plane));
@@ -495,7 +496,7 @@ void sbnd::LightCaloProducer::CalculateCalorimetry(art::Event& e,
495496
const auto &position(sp->XYZ());
496497
geo::Point_t xyz(position[0],position[1],position[2]);
497498
// correct for e- attenuation
498-
auto drift_time = hit->PeakTime()*0.5 - clock_data.TriggerOffsetTPC();
499+
auto drift_time = clock_data.TPCTick2TrigTime(hit->PeakTime());
499500
double atten_correction = std::exp(drift_time/det_prop.ElectronLifetime()); // exp(us/us)
500501
double charge = (1/fcal_area_const.at(hit->View()))*atten_correction*hit->Integral();
501502
if (xyz.X() < 0) has_sp0 = true;
@@ -515,7 +516,7 @@ void sbnd::LightCaloProducer::CalculateCalorimetry(art::Event& e,
515516
// find matching flashes if slice has reco spacepoints in both TPCs
516517
if ((has_sp0 && has_sp1) && (opflash0.isNull() || opflash1.isNull())){
517518
if (opflash0.isNull() && opflash1.isNull()){
518-
if (fverbose) std::cout << "No opflashes found for slice with spacepoints in both TPCs." << std::endl;
519+
if (fverbose) std::cout << "[LightCaloProducer] : " << "No opflashes found for slice with spacepoints in both TPCs." << std::endl;
519520
return;
520521
}
521522
else if (opflash0.isNull()) opflash0 = FindMatchingFlash(flash0_v, opflash1->Time());
@@ -531,7 +532,7 @@ void sbnd::LightCaloProducer::CalculateCalorimetry(art::Event& e,
531532
flash_time = opflash1->Time();
532533
}
533534

534-
if (flash_in_0==false && flash_in_1==false && fverbose)
535+
if (flash_in_0==false && flash_in_1==false)
535536
return;
536537

537538
// get total L count
@@ -597,9 +598,9 @@ void sbnd::LightCaloProducer::CalculateCalorimetry(art::Event& e,
597598
_slice_E = (_slice_L + _slice_Q)*1e-9*g4param->Wph(); // GeV, Wph = 19.5 eV
598599

599600
if (fverbose){
600-
std::cout << "charge: " << _slice_Q << std::endl;
601-
std::cout << "light: " << _slice_L << std::endl;
602-
std::cout << "energy: " << _slice_E << std::endl;
601+
std::cout << "[LightCaloProducer] : " << "charge: " << _slice_Q << std::endl;
602+
std::cout << "[LightCaloProducer] : " << "light: " << _slice_L << std::endl;
603+
std::cout << "[LightCaloProducer] : " << "energy: " << _slice_E << std::endl;
603604
}
604605

605606
sbn::LightCalo lightcalo{_slice_Q,_slice_L,_slice_E,bestHits};
@@ -657,7 +658,7 @@ void sbnd::LightCaloProducer::CollectMatches(const art::Handle<std::vector<Match
657658
auto slice = it->first;
658659
auto flash_v = it->second;
659660
if (flash_v.size() > 2){
660-
std::cout << "more than two opflash matched to this slice!" << std::endl;
661+
std::cout << "[LightCaloProducer] : " << "more than two opflash matched to this slice!" << std::endl;
661662
continue;
662663
}
663664
bool found_opflash0 = false;
@@ -692,7 +693,7 @@ void sbnd::LightCaloProducer::CollectMatches(const art::Handle<std::vector<Match
692693
art::Ptr<recob::OpFlash> sbnd::LightCaloProducer::FindMatchingFlash(const std::vector<art::Ptr<recob::OpFlash>> &flash_v,
693694
double ref_time)
694695
{
695-
double best_dt = 1.e9;
696+
double best_dt = std::numeric_limits<double>::max();
696697
art::Ptr<recob::OpFlash> best;
697698
for (size_t i = 0; i < flash_v.size(); ++i) {
698699
art::Ptr<recob::OpFlash> cand = flash_v[i];

0 commit comments

Comments
 (0)