237 if (!
e.getByLabel(
"caldata",wireHandle))
return;
251 for (
size_t i_t0 = 0; i_t0 < t0Handle->size(); i_t0++)
260 std::vector<art::Ptr<raw::ExternalTrigger> > trigvec = triggers.at(i_t0);
263 std::vector<unsigned int> evtTriggers;
264 for (
auto const &trig : trigvec) evtTriggers.push_back(trig->GetTrigID());
270 std::vector<MCHit> MCHitVec;
272 if (
fVerbose) std::cout <<
"Found " << hitHandle->size() <<
" recob::Hits in total." <<
std::endl;
276 std::vector<raw::ChannelID_t> absentChannels;
281 absentChannels.push_back(chan);
285 for (
size_t i_hit = 0; i_hit < hitHandle->size(); ++i_hit)
289 if (cit != absentChannels.end()) absentChannels.erase(cit);
294 bool channelexists =
false;
295 for (
size_t i_wire = 0; i_wire < wireHandle->size(); ++i_wire)
298 if (pwire->Channel() == sc->Channel())
300 channelexists =
true;
304 if (!channelexists)
continue;
307 if (
fCSP->
IsBad(sc->Channel()))
continue;
310 if (cit != absentChannels.end()) absentChannels.erase(cit);
316 if (citopp != absentChannels.end()) absentChannels.erase(citopp);
320 auto const& tdcidemap = sc->TDCIDEMap();
322 for (
auto const& tdcIt : tdcidemap)
325 auto const& ideVec = tdcIt.second;
328 unsigned short tdc = tdcIt.first;
331 for (
auto const& ideIt : ideVec)
336 if (
abs(ideIt.trackID) != 1)
continue;
338 if (part->
Mother() != 0)
continue;
341 mchit.idevec.push_back(ideIt);
344 if (mchit.idevec.size() > 1 && mchit.channel != sc->Channel())
345 throw cet::exception(
"RobustMCAna") <<
"Channel IDs don't match!";
348 mchit.channel = sc->Channel();
349 if (mchit.idevec.size() > 1 && mchit.pdg != part->
PdgCode())
350 throw cet::exception(
"RobustMCAna") <<
"Pdg from previous IDE (" << mchit.pdg <<
") doesn't equal this IDE Pdg (" << part->
PdgCode() <<
")";
355 mchit.particlevec.push_back(part);
356 mchit.tdcvec.push_back(tdc);
359 mchit.chargevec.push_back(ideIt.numElectrons*
mcscale);
362 if (mchit.idevec.size()==0)
continue;
363 MCHitVec.push_back(mchit);
368 if (MCHitVec.size() == 0 && hitHandle->size() == 0)
continue;
376 std::map<size_t,art::Ptr<recob::Hit> > recoHitMap;
378 for (
size_t i_hit = 0; i_hit < hitHandle->size(); ++i_hit)
381 recoHitMap[i_hit] =
hit;
385 std::vector<double> chargeratios;
386 std::vector<double> dTs;
387 std::vector<double> dQs;
388 std::vector<art::Ptr<recob::Hit> > recoHits;
389 std::vector<art::Ptr<recob::Hit> > otherwiseHits;
393 for (
auto mchit : MCHitVec)
397 int numIDEs = mchit.idevec.size();
398 double meanSimTime = TMath::Mean(mchit.tdcvec.begin(),mchit.tdcvec.end(),mchit.chargevec.begin());
399 double sigmaSimTime = TMath::RMS(mchit.tdcvec.begin(),mchit.tdcvec.end(),mchit.chargevec.begin());
400 double totalSimCharge = std::accumulate(mchit.chargevec.begin(),mchit.chargevec.end(),0);
402 MCQ = totalSimCharge;
409 std::cout <<
" Channel: " << channel <<
", MeanIDETime: " << meanSimTime <<
", RMSTime: " << sigmaSimTime <<
", TotalCharge: " << totalSimCharge <<
", NumIDEs: " << numIDEs <<
std::endl;
410 std::cout <<
"::::::::::IDEs:::::::" <<
std::endl;
411 for (
size_t i = 0; i < mchit.idevec.size(); ++i)
413 std::cout <<
" TrackID: " << mchit.idevec[i].trackID <<
", numElectrons: " << mchit.chargevec[i] <<
", TDC: " << mchit.tdcvec[i] <<
", Channel: " << mchit.channel <<
", PDG: " << mchit.pdg <<
std::endl;
420 for (
auto hit = recoHitMap.begin();
hit != recoHitMap.end(); )
428 if (
fVerbose) std::cout <<
" Channel: " <<
hit->second->Channel() <<
", PeakTime: " <<
hit->second->PeakTime() <<
", RMS: " <<
hit->second->RMS() <<
", Integral: " <<
hit->second->Integral() <<
std::endl;
431 if (
hit->second->PeakTimePlusRMS() > meanSimTime &&
hit->second->PeakTimeMinusRMS() < meanSimTime)
435 recoHits.push_back(
hit->second);
436 double totalRecoCharge =
hit->second->Integral();
437 RecoQ = totalRecoCharge;
439 double chargeratio = totalRecoCharge / totalSimCharge;
443 chargeratios.push_back(chargeratio);
456 hit = recoHitMap.erase(
hit);
460 otherwiseHits.push_back(
hit->second);
471 tp = recoHits.size();
472 tn = absentChannels.size();
473 fp = recoHitMap.size();
474 fn = MCHitVec.size()-recoHits.size();
485 std::cout <<
"TP: " << tp <<
" FP: " << fp <<
" TN: " <<
tn <<
" FN: " << fn <<
std::endl;
486 std::cout <<
"recoHits.size()=" << tp <<
" MCHitVec.size()=" << MCHitVec.size() <<
" otherwiseHits.size()=" << otherwiseHits.size() <<
std::endl;
492 for (
auto h : recoHits)
tpc +=
h->Integral();
496 for (
auto h : recoHitMap)
fpc +=
h.second->Integral();
500 for (
auto h : MCHitVec)
fnc += std::accumulate(
h.chargevec.begin(),
h.chargevec.end(),0);
509 std::cout <<
"TPC: " << tpc <<
" FPC: " <<
fpc <<
" FNC: " <<
fnc <<
std::endl;
virtual bool IsBad(raw::ChannelID_t channel) const =0
Returns whether the specified channel is bad in the current run.
std::string fCounterT0ModuleLabel
const simb::MCParticle * TrackIdToParticle_P(int id) const
void SumADCTofC(double &input)
SigType_t SignalType(geo::PlaneID const &pid) const
Returns the type of signal on the channels of specified TPC plane.
double Efficiency(double tp, double fn)
double MCC(double tp, double fp, double fn, double tn)
unsigned int Nchannels() const
Returns the number of TPC readout channels in the detector.
bool ValidTrigger(std::vector< unsigned int > evtTriggers, unsigned int &c1arg, unsigned int &c2arg, unsigned int &trignumarg)
void NumElectronsTofC(double &input)
void fCToSumADC(double &input)
TH1D * hEventChargePurity
double Purity(double tp, double fp)
const lariov::ChannelStatusProvider * fCSP
Detector simulation of raw signals on wires.
double VMean(std::vector< double > v)
raw::ChannelID_t OppositeTPCChannel(raw::ChannelID_t)
const std::vector< art::Ptr< sim::SimChannel > > & SimChannels() const
TH1D * hEventChargeEfficiency
unsigned int ChannelID_t
Type representing the ID of a readout channel.
cet::coded_exception< error, detail::translate > exception
QTextStream & endl(QTextStream &s)
std::string fHitsModuleLabel
h
training ###############################
Signal from collection planes.