16 #include "art_root_io/TFileService.h" 18 #include "canvas/Persistency/Common/FindManyP.h" 68 virtual void endJob()
override;
129 hCosmicMuonEff = tfs->make<TH1F>(
"hCosmicMuonEff",
";Efficiency",50,0,1.0001);
130 hCosmicMuonPur = tfs->make<TH1F>(
"hCosmicMuonPur",
";Purity",50,0,1.0001);
131 hCosmicEff = tfs->make<TH1F>(
"hCosmicEff",
";Efficiency",50,0,1.0001);
132 hCosmicPur = tfs->make<TH1F>(
"hCosmicPur",
";Purity",50,0,1.0001);
133 hTaggedPDG = tfs->make<TH1F>(
"hTaggedParticleType",
"",6,0.5,6.5);
134 hTrkLenAll = tfs->make<TH1F>(
"hTrkLenAll",
"",10,0,600);
135 hTrkLenTag = tfs->make<TH1F>(
"hTrkLenTag",
"",10,0,600);
136 hTrkLenEff = tfs->make<TH1F>(
"hTrkLenEff",
"",10,0,600);
137 hTagType = tfs->make<TH1F>(
"hTagType",
"",12,0,12);
148 hTagType->GetXaxis()->SetBinLabel(1,
"YY");
149 hTagType->GetXaxis()->SetBinLabel(2,
"YZ");
150 hTagType->GetXaxis()->SetBinLabel(3,
"ZZ");
151 hTagType->GetXaxis()->SetBinLabel(4,
"XX");
152 hTagType->GetXaxis()->SetBinLabel(5,
"XY");
153 hTagType->GetXaxis()->SetBinLabel(6,
"XZ");
154 hTagType->GetXaxis()->SetBinLabel(7,
"Y");
155 hTagType->GetXaxis()->SetBinLabel(8,
"Z");
156 hTagType->GetXaxis()->SetBinLabel(9,
"X");
157 hTagType->GetXaxis()->SetBinLabel(10,
"Outside Drift (Part)");
158 hTagType->GetXaxis()->SetBinLabel(11,
"Outside Drift (Full)");
159 hTagType->GetXaxis()->SetBinLabel(12,
"Beam Incompatible");
173 const art::FindManyP<recob::Hit> findTrackHits(recoTracks, evt,
fTrackerTag);
176 const art::FindManyP<anab::CosmicTag> findCosmicTags(recoTracks,evt,
fTrackerTag);
182 unsigned int local_TrueCosmicMuon = 0;
183 unsigned int local_TaggedCosmicMuon = 0;
184 unsigned int local_TrueOther = 0;
185 unsigned int local_TaggedOther = 0;
186 unsigned int local_TrueCosmicOrigin = 0;
187 unsigned int local_TaggedCosmicOrigin = 0;
188 unsigned int local_TrueOtherOrigin = 0;
189 unsigned int local_TaggedOtherOrigin = 0;
192 std::vector<int> matchedTruths;
196 for(
unsigned int t = 0;
t < recoTracks->size(); ++
t){
199 auto const& trackHits = findTrackHits.at(
t);
204 if(trueMatch == 0x0)
continue;
206 bool alreadyMatched =
false;
207 if(std::find(matchedTruths.begin(),matchedTruths.end(),trueMatch->
TrackId())==matchedTruths.end()){
208 matchedTruths.push_back(trueMatch->
TrackId());
211 alreadyMatched =
true;
215 bool isCosmic =
false;
216 bool isCosmicMuon =
false;
221 if(fabs(trueMatch->
PdgCode()) == 13){
222 ++local_TrueCosmicMuon;
229 ++local_TrueCosmicOrigin;
235 ++local_TrueOtherOrigin;
239 auto const& trackCosmicTag = findCosmicTags.at(
t);
257 if(trackCosmicTag.size() == 0){
260 std::cout <<
"We've found a cosmic muon but we don't have a tag for it" <<
std::endl;
265 std::cout <<
" - Track length = " << ((*recoTracks)[
t].Vertex()-(*recoTracks)[
t].End()).
R() <<
std::endl;
266 if((*recoTracks)[
t].Vertex().Y() < (*recoTracks)[
t].End().Y()){
267 std::cout <<
" - Track reconstructed with the vertex lower than the end point" <<
std::endl;
269 if((*recoTracks)[
t].Vertex().Y() < 550 && (*recoTracks)[
t].End().Y() < 550){
270 std::cout <<
" - This track was reconstructed away from the top of the detector... no way to tag it. " <<
std::endl;
273 std::cout <<
" - This true particle " << trueMatch->
TrackId() <<
"was already matched" <<
std::endl;
281 ++local_TaggedCosmicMuon;
289 ++local_TaggedCosmicOrigin;
292 ++local_TaggedOtherOrigin;
294 if(correctProcess ==
"primary"){
295 std::cout <<
" - Oops! Tagged a good beam particle (" << trueMatch->
PdgCode() <<
") as a cosmic (" <<
ConvertCosmicType(trackCosmicTag[0]->CosmicType()) <<
")" <<
std::endl;
297 else if(correctProcess ==
"primaryBackground"){
298 std::cout <<
" - Oops! Tagged a background beam particle (" << trueMatch->
PdgCode() <<
") as a cosmic (" <<
ConvertCosmicType(trackCosmicTag[0]->CosmicType()) <<
")" <<
std::endl;
301 std::cout <<
" - Oops! Tagged a non-primary beam particle (" << trueMatch->
PdgCode() <<
") as a cosmic (" <<
ConvertCosmicType(trackCosmicTag[0]->CosmicType()) <<
")" <<
std::endl;
303 (*recoTracks)[
t].Vertex<TVector3>().Print();
304 (*recoTracks)[
t].End<TVector3>().Print();
305 trueMatch->
Position().Vect().Print();
318 if(local_TrueCosmicMuon > 0){
319 hCosmicMuonEff->Fill(local_TaggedCosmicMuon/static_cast<float>(local_TrueCosmicMuon));
321 if(local_TaggedCosmicMuon+local_TaggedOther > 0){
322 hCosmicMuonPur->Fill(local_TaggedCosmicMuon/static_cast<float>(local_TaggedCosmicMuon + local_TaggedOther));
324 if(local_TrueCosmicOrigin > 0){
325 hCosmicEff->Fill(local_TaggedCosmicOrigin/static_cast<float>(local_TrueCosmicOrigin));
327 if(local_TaggedCosmicOrigin+local_TaggedOtherOrigin > 0){
328 hCosmicPur->Fill(local_TaggedCosmicOrigin/static_cast<float>(local_TaggedCosmicOrigin + local_TaggedOtherOrigin));
346 std::cout <<
" == Cosmic Efficiency Summary == " <<
std::endl;
347 std::cout <<
" - Looking for cosmic muons: " <<
std::endl;
351 std::cout <<
" - Looking for just cosmic origin: " <<
std::endl;
360 float eff = tag /
all;
362 float err = sqrt((eff*(1-eff))/all);
377 std::unordered_map<int, double> trkIDE;
378 for (
auto const &
h : hits)
382 trkIDE[ide.trackID] += ide.energy;
387 double tot_e = 0, max_e = 0;
388 for (
auto const & contrib : trkIDE)
390 tot_e += contrib.second;
391 if (contrib.second > max_e)
393 max_e = contrib.second;
394 best_id = contrib.first;
398 if ((max_e > 0) && (tot_e > 0))
CosmicEfficiency & operator=(CosmicEfficiency const &)=delete
const TLorentzVector & Position(const int i=0) const
const TLorentzVector & EndPosition() const
std::vector< sim::TrackIDE > HitToTrackIDEs(detinfo::DetectorClocksData const &clockData, recob::Hit const &hit) const
const simb::MCParticle * TrackIdToParticle_P(int id) const
enum anab::cosmic_tag_id CosmicTagID_t
simb::Origin_t Origin() const
art::InputTag fTrackerTag
const particleType ConvertPDGCode(int pdg) const
EDAnalyzer(fhicl::ParameterSet const &pset)
std::string Process() const
virtual void beginJob() override
#define DEFINE_ART_MODULE(klass)
const art::Ptr< simb::MCTruth > & TrackIdToMCTruth_P(int id) const
unsigned int fTaggedOther
int ConvertCosmicType(anab::CosmicTagID_t tag) const
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
unsigned int fTrueCosmicMuon
void err(const char *fmt,...)
unsigned int fTaggedCosmicOrigin
const simb::MCParticle & GetParticle(int i) const
Declaration of signal hit object.
static QInternalList< QTextCodec > * all
Contains all timing reference information for the detector.
virtual void endJob() override
Provides recob::Track data product.
void analyze(art::Event const &e) override
unsigned int fTaggedOtherOrigin
unsigned int fTaggedCosmicMuon
boost::graph_traits< ModuleGraph >::vertex_descriptor Vertex
auto const & get(AssnsNode< L, R, D > const &r)
unsigned int fTrueCosmicOrigin
const simb::MCParticle * GetTruthParticle(detinfo::DetectorClocksData const &clockData, const std::vector< art::Ptr< recob::Hit > > &hits) const
CosmicEfficiency(fhicl::ParameterSet const &p)
QTextStream & endl(QTextStream &s)
unsigned int fTrueOtherOrigin