16 #include "art_root_io/TFileService.h" 18 #include "canvas/Persistency/Common/FindManyP.h" 71 bool ValidTrigger(std::vector<unsigned int> evtTriggers,
unsigned int & c1arg,
unsigned int & c2arg,
unsigned int & trignumarg);
77 double MCC(
double tp,
double fp,
double fn,
double tn);
78 double VMean(std::vector<double> v);
176 hEventPurity = fTfs->make<TH1D>(
"hEventPurity",
"Purity of Reco Hit Selection; TP/(TP+FP); # Events",200,0,1.1);
177 hEventEfficiency = fTfs->make<TH1D>(
"hEventEfficiency",
"Efficiency of Reco Hit Selection; TP/(TP+FN); # Events",200,0,1.1);
178 hEventChargePurity = fTfs->make<TH1D>(
"hEventChargePurity",
"Purity of Reco Hit Charge Selection; ChgTP/(ChgTP+ChgFP); # Events",200,0,1.1);
179 hEventChargeEfficiency = fTfs->make<TH1D>(
"hEventChargeEfficiency",
"Efficiency of Reco Hit Charge Selection; ChgTP/(ChgTP+ChgFN); # Events",200,0,1.1);
180 hHitChargeRatio = fTfs->make<TH1D>(
"hHitChargeRatio",
"Ratio of reco hit charge to MC hit charge; Reco Charge / MC Charge; # Events",200,0,3);
181 hdQ = fTfs->make<TH1D>(
"hdQ",
"; Charge Residual, RecoQ-MCQ; # Events",200,-3000,3000);
182 hChargeComp = fTfs->make<TH2D>(
"hChargeComp",
"Comparison of reco and MC charges; MC Charge (fC); Reco Charge (fC)",400,0,30000,400,0,30000);
183 hdT = fTfs->make<TH1D>(
"hdT",
"#DeltaT between MC hit and Reco Hit; Reco Hit Time - MC Hit Time (TDC ticks); # Events",200,-30,30);
184 hMCC = fTfs->make<TH1D>(
"hMCC",
"Matthew's Correlation Coefficient; MCC; # Events",201,-1.1,1.1);
187 fHitTree = fTfs->make<TTree>(
"mcanahits",
"mcanahits");
201 fEventTree = fTfs->make<TTree>(
"mcanaevents",
"mcanaevents");
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!";
350 throw cet::exception(
"RobustMCAna") <<
"Pdg from previous IDE (" << mchit.
pdg <<
") doesn't equal this IDE Pdg (" << part->
PdgCode() <<
")";
356 mchit.
tdcvec.push_back(tdc);
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();
478 eventMCC =
MCC( (
double)tp, (
double)fp, (
double)fn, (
double)
tn );
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;
529 return (tp+fp<=0) ? -1.0 : tp/(tp+
fp);
535 return (tp+fn<=0) ? -1.0 : tp/(tp+
fn);
542 return ((tp+fp)*(tp+fn)*(tn+fp)*(tn+fn)<=0) ? -2.0 : ((tp*
tn)-(fp*fn))/sqrt((tp+fp)*(tp+
fn)*(tn+fp)*(tn+
fn));
568 return (v.size()==0) ? -999 : TMath::Mean(v.size(),v.data());
576 std::vector<geo::WireID> attachedWires = fGeom->
ChannelToWire(chan);
577 for (
auto const &
w : attachedWires)
581 if (tpc % 2 == 0) tpc++;
596 c1arg=999; c2arg=999;
597 int contains_111 = 0, contains_112 = 0, contains_113 = 0;
598 int contains_Ntrigs = 0, contains_NU = 0, contains_NL = 0, contains_SU = 0, contains_SL = 0;
599 int contains_EL = 0, contains_WU = 0, contains_TEL = 0;
600 for (
size_t i_c = 0; i_c < evtTriggers.size(); i_c++)
602 unsigned int trigID = evtTriggers[i_c];
605 if (trigID <= 5) contains_SL++;
606 if (trigID >= 6 && trigID <= 15) contains_EL++;
607 if (trigID >= 16 && trigID <= 21) contains_NL++;
608 if (trigID >= 22 && trigID <= 27) contains_NU++;
609 if (trigID >= 28 && trigID <= 37) contains_WU++;
610 if (trigID >= 38 && trigID <= 43) contains_SU++;
611 if (trigID >= 44 && trigID <= 92) contains_TEL++;
612 if (trigID == 111) contains_111++;
613 if (trigID == 112) contains_112++;
614 if (trigID == 113) contains_113++;
617 if (contains_111 + contains_112 + contains_113 != 1)
return false;
619 (contains_NU || contains_NL || contains_SU || contains_SL || contains_EL || contains_WU))
return false;
620 if (contains_Ntrigs != 3)
return false;
621 if (contains_111 && (contains_NU || contains_NL || contains_SU || contains_SL))
return false;
622 if (contains_112 && (contains_EL || contains_WU || contains_SU || contains_NL))
return false;
623 if (contains_113 && (contains_EL || contains_WU || contains_NU || contains_SL))
return false;
624 if (contains_111 && (!contains_EL || !contains_WU))
return false;
625 if (contains_112 && (!contains_NU || !contains_SL))
return false;
626 if (contains_113 && (!contains_SU || !contains_NL))
return false;
628 std::vector<unsigned int> counterIDs;
630 for (
size_t i_c = 0; i_c < evtTriggers.size(); i_c++)
632 unsigned int trigID = evtTriggers[i_c];
633 if (trigID >= 44 && trigID <= 100)
continue;
634 if (trigID >= 111 && trigID <= 113)
639 counterIDs.push_back(trigID);
641 if (counterIDs.size() != 2)
return false;
642 if (trignumarg == 0)
return false;
644 if (trignumarg == 112 || trignumarg == 113)
648 c1arg = counterIDs[0];
649 c2arg = counterIDs[1];
653 c1arg = counterIDs[1];
654 c2arg = counterIDs[0];
657 else if (trignumarg == 111)
661 c1arg = counterIDs[0];
662 c2arg = counterIDs[1];
666 c1arg = counterIDs[1];
667 c2arg = counterIDs[0];
670 if (c1arg == c2arg)
return false;
671 if (c1arg == 999 || c2arg == 999)
return false;
virtual bool IsBad(raw::ChannelID_t channel) const =0
Returns whether the specified channel is bad in the current run.
std::map< unsigned int, std::pair< TVector3, std::vector< TVector3 > > > fCounterPositionMap
std::string fCounterT0ModuleLabel
EventNumber_t event() const
T::provider_type const * providerFrom()
Returns a constant pointer to the provider of specified service.
const simb::MCParticle * TrackIdToParticle_P(int id) const
Declaration of signal hit object.
std::vector< geo::WireID > ChannelToWire(raw::ChannelID_t const channel) const
Returns a list of wires connected to the specified TPC channel.
void SumADCTofC(double &input)
SigType_t SignalType(geo::PlaneID const &pid) const
Returns the type of signal on the channels of specified TPC plane.
detinfo::DetectorProperties const * fDetProp
EDAnalyzer(fhicl::ParameterSet const &pset)
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)
std::vector< sim::IDE > idevec
void NumElectronsTofC(double &input)
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
void fCToSumADC(double &input)
#define DEFINE_ART_MODULE(klass)
std::vector< const simb::MCParticle * > particlevec
raw::ChannelID_t Channel() const
Returns the ID of the channel (or InvalidChannelID)
TH1D * hEventChargePurity
double Purity(double tp, double fp)
const lariov::ChannelStatusProvider * fCSP
T get(std::string const &key) const
SubRunNumber_t subRun() const
Class providing information about the quality of channels.
General LArSoft Utilities.
Definition of data types for geometry description.
std::vector< unsigned short > tdcvec
Detector simulation of raw signals on wires.
Conversion of times between different formats and references.
Encapsulate the geometry of a wire.
std::vector< double > chargevec
raw::ChannelID_t PlaneWireToChannel(WireID const &wireid) const
Returns the ID of the TPC channel connected to the specified wire.
unsigned int TPCID_t
Type for the ID number.
double VMean(std::vector< double > v)
LArSoft-specific namespace.
object containing MC truth information necessary for making RawDigits and doing back tracking ...
detinfo::DetectorClocks const * fClks
Interface for experiment-specific channel quality info provider.
raw::ChannelID_t OppositeTPCChannel(raw::ChannelID_t)
RobustMCAna(fhicl::ParameterSet const &p)
const std::vector< art::Ptr< sim::SimChannel > > & SimChannels() const
Declaration of basic channel signal object.
void MakeCounterPositionMap(std::string CounterDir, std::string CounterFile, std::map< unsigned int, std::pair< TVector3, std::vector< TVector3 > > > &CounterPositionMap, double fExtendCountersX=0, double fExtendCountersY=0, double fExtendCountersZ=0)
TH1D * hEventChargeEfficiency
unsigned int ChannelID_t
Type representing the ID of a readout channel.
Interface for experiment-specific service for channel quality info.
RobustMCAna & operator=(RobustMCAna const &)=delete
void analyze(art::Event const &e) override
raw::ChannelID_t Channel() const
ID of the readout channel the hit was extracted from.
Tools and modules for checking out the basics of the Monte Carlo.
cet::coded_exception< error, detail::translate > exception
QTextStream & endl(QTextStream &s)
Event finding and building.
std::string fHitsModuleLabel
h
training ###############################
Signal from collection planes.