Public Member Functions | Private Attributes | List of all members
protoana::ProtoFlash Class Reference
Inheritance diagram for protoana::ProtoFlash:
art::EDAnalyzer art::detail::Analyzer art::detail::LegacyModule art::Observer art::ModuleBase

Public Member Functions

 ProtoFlash (const fhicl::ParameterSet &)
 
virtual ~ProtoFlash ()
 
void beginJob ()
 
void analyze (const art::Event &)
 
void ExtractTrueTimes (const std::string &moduleName, std::map< int, double > &timeMap, const art::Event &evt)
 
- Public Member Functions inherited from art::EDAnalyzer
 EDAnalyzer (fhicl::ParameterSet const &pset)
 
template<typename Config >
 EDAnalyzer (Table< Config > const &config)
 
std::string workerType () const
 
- Public Member Functions inherited from art::detail::Analyzer
virtual ~Analyzer () noexcept
 
 Analyzer (fhicl::ParameterSet const &pset)
 
template<typename Config >
 Analyzer (Table< Config > const &config)
 
void doBeginJob (SharedResources const &resources)
 
void doEndJob ()
 
void doRespondToOpenInputFile (FileBlock const &fb)
 
void doRespondToCloseInputFile (FileBlock const &fb)
 
void doRespondToOpenOutputFiles (FileBlock const &fb)
 
void doRespondToCloseOutputFiles (FileBlock const &fb)
 
bool doBeginRun (RunPrincipal &rp, ModuleContext const &mc)
 
bool doEndRun (RunPrincipal &rp, ModuleContext const &mc)
 
bool doBeginSubRun (SubRunPrincipal &srp, ModuleContext const &mc)
 
bool doEndSubRun (SubRunPrincipal &srp, ModuleContext const &mc)
 
bool doEvent (EventPrincipal &ep, ModuleContext const &mc, std::atomic< std::size_t > &counts_run, std::atomic< std::size_t > &counts_passed, std::atomic< std::size_t > &counts_failed)
 
- Public Member Functions inherited from art::Observer
 ~Observer () noexcept
 
 Observer (Observer const &)=delete
 
 Observer (Observer &&)=delete
 
Observeroperator= (Observer const &)=delete
 
Observeroperator= (Observer &&)=delete
 
void registerProducts (ProductDescriptions &, ModuleDescription const &)
 
void fillDescriptions (ModuleDescription const &)
 
fhicl::ParameterSetID selectorConfig () const
 
- Public Member Functions inherited from art::ModuleBase
virtual ~ModuleBase () noexcept
 
 ModuleBase ()
 
ModuleDescription const & moduleDescription () const
 
void setModuleDescription (ModuleDescription const &)
 
std::array< std::vector< ProductInfo >, NumBranchTypes > const & getConsumables () const
 
void sortConsumables (std::string const &current_process_name)
 
template<typename T , BranchType BT>
ViewToken< T > consumesView (InputTag const &tag)
 
template<typename T , BranchType BT>
ViewToken< T > mayConsumeView (InputTag const &tag)
 

Private Attributes

std::string fOpFlashModuleLabel
 
std::string fOpHitModuleLabel
 
std::string fSignalLabel
 
std::string fCosmicLabel
 
std::string fGeantLabel
 
std::string fParticleLabel
 
TH1D * hFlashToTrueTime
 
TH1D * hFlashPurity
 
TH2D * hPurityTimeDiff
 
TH1D * hFlashToRecoTime
 
TH1D * hFlashToRecoWide
 
TH1D * hFlashToRecoWider
 
TH1D * hFlashTimes
 
TH1D * hHitTimes
 
TH1D * hNFlash
 
TH1D * hNHitPerFlash
 

Additional Inherited Members

- Public Types inherited from art::EDAnalyzer
using WorkerType = WorkerT< EDAnalyzer >
 
using ModuleType = EDAnalyzer
 
- Protected Member Functions inherited from art::Observer
std::string const & processName () const
 
bool wantAllEvents () const noexcept
 
bool wantEvent (ScheduleID id, Event const &e) const
 
Handle< TriggerResultsgetTriggerResults (Event const &e) const
 
 Observer (fhicl::ParameterSet const &config)
 
 Observer (std::vector< std::string > const &select_paths, std::vector< std::string > const &reject_paths, fhicl::ParameterSet const &config)
 
- Protected Member Functions inherited from art::ModuleBase
ConsumesCollectorconsumesCollector ()
 
template<typename T , BranchType = InEvent>
ProductToken< T > consumes (InputTag const &)
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > consumesView (InputTag const &)
 
template<typename T , BranchType = InEvent>
void consumesMany ()
 
template<typename T , BranchType = InEvent>
ProductToken< T > mayConsume (InputTag const &)
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > mayConsumeView (InputTag const &)
 
template<typename T , BranchType = InEvent>
void mayConsumeMany ()
 

Detailed Description

Definition at line 47 of file ProtoFlash_module.cc.

Constructor & Destructor Documentation

protoana::ProtoFlash::ProtoFlash ( const fhicl::ParameterSet )

Definition at line 97 of file ProtoFlash_module.cc.

98  : EDAnalyzer(pset)
99  {
100 
101  // Indicate that the Input Module comes from .fcl
102  fOpFlashModuleLabel = pset.get<std::string>("OpFlashModuleLabel");
103  fOpHitModuleLabel = pset.get<std::string>("OpHitModuleLabel");
104  fSignalLabel = pset.get<std::string>("SignalLabel");
105  fCosmicLabel = pset.get<std::string>("CosmicLabel");
106  fGeantLabel = pset.get<std::string>("GeantLabel");
107  fParticleLabel = pset.get<std::string>("ParticleLabel");
108 
110 
111  // Make a few plots
112  hFlashToTrueTime = tfs->make<TH1D>("hFlashToTrueTime","",50,-5,5);
113  hFlashPurity = tfs->make<TH1D>("hFlashPurity","",50,0.499,1.001);
114  hFlashToRecoTime = tfs->make<TH1D>("hFlashToRecoTime","",50,-5,5);
115  hFlashToRecoWide = tfs->make<TH1D>("hFlashToRecoWide","",100,-10,10);
116  hFlashToRecoWider = tfs->make<TH1D>("hFlashToRecoWider","",100,-50,50);
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);
122  }
std::string fOpFlashModuleLabel
std::string string
Definition: nybbler.cc:12
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.h:25
protoana::ProtoFlash::~ProtoFlash ( )
virtual

Definition at line 126 of file ProtoFlash_module.cc.

127  {}

Member Function Documentation

void protoana::ProtoFlash::analyze ( const art::Event evt)

Definition at line 134 of file ProtoFlash_module.cc.

135  {
136 
137  // Make sure we can use this on data and MC
138  bool isMC = !(evt.isRealData());
139 // isMC = false;
140 
141  // Get flashes from event
142  std::vector<art::Ptr<recob::OpFlash> > flashlist;
143  auto FlashHandle = evt.getHandle< std::vector< recob::OpFlash > >(fOpFlashModuleLabel);
144  if (FlashHandle) {
145  art::fill_ptr_vector(flashlist, FlashHandle);
146  std::sort(flashlist.begin(), flashlist.end(), recob::OpFlashPtrSortByPE);
147  }
148 
149  // Get assosciations between flashes and hits
150  art::FindManyP< recob::OpHit > Assns(FlashHandle, evt, fOpFlashModuleLabel);
151 
152  // We want to store a map of track time to track id
153  // This will later allow us to check how much of a flash comes from the best matched time
154  std::map<int,double> trueTimeID;
155  if(isMC){
156  // Check for generator inputs - particle gun or protoDUNE beam
157  if(fSignalLabel!=""){
158  ExtractTrueTimes(fSignalLabel,trueTimeID,evt);
159  }
160 
161  // Check for cosmic generator inputs
162  if(fCosmicLabel!=""){
163  ExtractTrueTimes(fCosmicLabel,trueTimeID,evt);
164  }
165  }
166 
167  //////////////////////////////////////
168  // Access all the Flash Information //
169  //////////////////////////////////////
170 
171  hNFlash->Fill(FlashHandle->size());
172 
173  // Use the clocks service to make sure to account for the offset between true times and the electronics clocks
174  auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService>()->DataFor(evt);
175 
176  // Store a map of flash times
177  std::map<int,double> flashMap;
178 
179  // For every OpFlash in the vector
180  for(unsigned int i = 0; i < FlashHandle->size(); ++i)
181  {
182 
183  // Get OpFlash and associated hits
184  art::Ptr< recob::OpFlash > TheFlashPtr(FlashHandle, i);
185  recob::OpFlash TheFlash = *TheFlashPtr;
186  art::FindManyP< recob::OpHit > Assns(FlashHandle, evt, fOpFlashModuleLabel);
187  std::vector< art::Ptr<recob::OpHit> > matchedHits = Assns.at(i);
188 
189  // Account for the time offset in the TPC
190  flashMap.insert(std::make_pair(i,TheFlash.Time() - clockData.TriggerOffsetTPC()));
191 
192  hNHitPerFlash->Fill(matchedHits.size());
193  hFlashTimes->Fill(TheFlash.Time());
194 
195  for(auto const h : matchedHits){
196  hHitTimes->Fill(h->PeakTime());
197  }
198 
199  // Truth level code
200  if(isMC){
202 
203  // Get the best match in time, then check how much of the light comes from
204  // the best matched particle
205  int bestMatch = 0;
206  double bestPurity = 0;
207  double minTimeDiff = 1e20;
208 
209  // Iterate over the map
210  for(auto &m : trueTimeID){
211 
212  double dist = fabs(m.second - TheFlash.Time());
213  if(dist < minTimeDiff){
214  // Does this track give us purity > 0.5?
215  std::set<int> trackIDs;
216  trackIDs.emplace(m.first);
217  double purity = pbt->OpHitCollectionPurity(trackIDs,matchedHits);
218  if(purity < 0.5) continue;
219 
220  // If purity is good enough, this is a success
221  minTimeDiff = dist;
222  bestMatch = m.first;
223  bestPurity = purity;
224  }
225  }
226  if(minTimeDiff > 1000){
227  // std::cout << "No sensible true match to flash " << i << std::endl;
228  }
229 
230  if(bestPurity >= 0.5) std::cout << "Best true time matched particle " << bestMatch << " has delta T = " << minTimeDiff << " and gives a purity " << bestPurity << std::endl;
231 
232  hFlashToTrueTime->Fill(trueTimeID[bestMatch] - TheFlash.Time());
233  hPurityTimeDiff->Fill(trueTimeID[bestMatch] - TheFlash.Time(),bestPurity);
234  hFlashPurity->Fill(bestPurity);
235  }
236  } // End loop over flashes
237 
238  // Get reconstruction information from particles with a measured T0
239  // Try finding some particles
241  = evt.getValidHandle<std::vector<recob::PFParticle> >(fParticleLabel);
242 
244 
245  for (size_t p = 0; p != particleHandle->size(); ++p){
246 
247  const auto thisParticle = (*particleHandle)[p];
248 
249  // Only consider primaries so we don't include deltas etc
250  if(!(thisParticle.IsPrimary())) continue;
251 
252  // Did this particle have an associated T0?
253  std::vector<anab::T0> t0s = pfpUtil.GetPFParticleT0(thisParticle,evt,fParticleLabel);
254  if(t0s.size() == 0) continue;
255 
256  // Pandora gives us times in ns
257  double recoT0 = t0s[0].Time() / 1000.;
258 
259  int bestRecoMatch = 0;
260  double minRecoTimeDiff = 1e20;
261 
262  // Now loop over the flashes
263  for(auto &m : flashMap){
264  double dist = fabs(recoT0 - m.second);
265  if(dist < minRecoTimeDiff){
266  minRecoTimeDiff = dist;
267  bestRecoMatch = m.first;
268  }
269  }
270 
271  std::cout << "Particle " << p << " has a TPC T0 = " << recoT0 << std::endl;
272 
273  if(minRecoTimeDiff > 100){
274  std::cout << "No sensible reco match to flash " << p << std::endl;
275  }
276  std::cout << "Best matched flash " << bestRecoMatch << " has delta T = " << minRecoTimeDiff << std::endl;
277 
278  hFlashToRecoTime->Fill(recoT0 - flashMap[bestRecoMatch]);
279  hFlashToRecoWide->Fill(recoT0 - flashMap[bestRecoMatch]);
280  hFlashToRecoWider->Fill(recoT0 - flashMap[bestRecoMatch]);
281  }
282 
283  }
std::string fOpFlashModuleLabel
Handle< PROD > getHandle(SelectorBase const &) const
Definition: DataViewImpl.h:382
void ExtractTrueTimes(const std::string &moduleName, std::map< int, double > &timeMap, const art::Event &evt)
const double OpHitCollectionPurity(std::set< int > const &tkIds, std::vector< art::Ptr< recob::OpHit > > const &opHits_Ps)
bool isRealData() const
double Time() const
Definition: OpFlash.h:106
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
Definition: DataViewImpl.h:441
p
Definition: test.py:223
struct recob::OpFlashPtrSortByPE_t OpFlashPtrSortByPE
constexpr double dist(const TReal *x, const TReal *y, const unsigned int dimension)
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
Definition: Ptr.h:297
QTextStream & endl(QTextStream &s)
void protoana::ProtoFlash::beginJob ( )
virtual

Reimplemented from art::EDAnalyzer.

Definition at line 130 of file ProtoFlash_module.cc.

131  {}
void protoana::ProtoFlash::ExtractTrueTimes ( const std::string moduleName,
std::map< int, double > &  timeMap,
const art::Event evt 
)

Definition at line 285 of file ProtoFlash_module.cc.

285  {
286 
287 
288  auto MCTruthsHandle = evt.getValidHandle<std::vector<simb::MCTruth> >(moduleName);
289  art::Ptr<simb::MCTruth> thisMCTruth(MCTruthsHandle, 0);
290  if (thisMCTruth->NParticles() == 0) {
291  mf::LogError("FlashMatchAna") << "No Cosmic MCTruth Particles";
292  }
293  else std::cout << "MCTruth from " << moduleName << " has " << thisMCTruth->NParticles() << " particles " << std::endl;
294 
295  // Get all the track ids associated with the cosmic events.
296  art::FindManyP<simb::MCParticle> geantAssns(MCTruthsHandle,evt,fGeantLabel);
297 
298  for ( size_t i = 0; i < geantAssns.size(); i++) {
299  auto parts = geantAssns.at(i);
300  int counter = 0;
301  for (auto part = parts.begin(); part != parts.end(); part++) {
302  ++counter;
303  timeMap.insert(std::make_pair((*part)->TrackId(),(*part)->T()/1000.));
304  }
305  std::cout << "Found " << counter << " GEANT particles associated to " << moduleName << " MCTruth " << i << std::endl;
306  }
307 
308  }
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
Definition: DataViewImpl.h:441
QTextStream & endl(QTextStream &s)

Member Data Documentation

std::string protoana::ProtoFlash::fCosmicLabel
private

Definition at line 73 of file ProtoFlash_module.cc.

std::string protoana::ProtoFlash::fGeantLabel
private

Definition at line 74 of file ProtoFlash_module.cc.

std::string protoana::ProtoFlash::fOpFlashModuleLabel
private

Definition at line 70 of file ProtoFlash_module.cc.

std::string protoana::ProtoFlash::fOpHitModuleLabel
private

Definition at line 71 of file ProtoFlash_module.cc.

std::string protoana::ProtoFlash::fParticleLabel
private

Definition at line 75 of file ProtoFlash_module.cc.

std::string protoana::ProtoFlash::fSignalLabel
private

Definition at line 72 of file ProtoFlash_module.cc.

TH1D* protoana::ProtoFlash::hFlashPurity
private

Definition at line 78 of file ProtoFlash_module.cc.

TH1D* protoana::ProtoFlash::hFlashTimes
private

Definition at line 83 of file ProtoFlash_module.cc.

TH1D* protoana::ProtoFlash::hFlashToRecoTime
private

Definition at line 80 of file ProtoFlash_module.cc.

TH1D* protoana::ProtoFlash::hFlashToRecoWide
private

Definition at line 81 of file ProtoFlash_module.cc.

TH1D* protoana::ProtoFlash::hFlashToRecoWider
private

Definition at line 82 of file ProtoFlash_module.cc.

TH1D* protoana::ProtoFlash::hFlashToTrueTime
private

Definition at line 77 of file ProtoFlash_module.cc.

TH1D* protoana::ProtoFlash::hHitTimes
private

Definition at line 84 of file ProtoFlash_module.cc.

TH1D* protoana::ProtoFlash::hNFlash
private

Definition at line 85 of file ProtoFlash_module.cc.

TH1D* protoana::ProtoFlash::hNHitPerFlash
private

Definition at line 86 of file ProtoFlash_module.cc.

TH2D* protoana::ProtoFlash::hPurityTimeDiff
private

Definition at line 79 of file ProtoFlash_module.cc.


The documentation for this class was generated from the following file: