-
Notifications
You must be signed in to change notification settings - Fork 30
Subrun ntuple #391
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
AndrewEdmonds11
wants to merge
16
commits into
Mu2e:main
Choose a base branch
from
AndrewEdmonds11:subrun-ntuple
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Subrun ntuple #391
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
73995f7
Initial bits of the subrun stuff
AndrewEdmonds11 544be2f
Add SubRun info
AndrewEdmonds11 08e28bf
First version of fcl configuration
AndrewEdmonds11 c6ab3e7
Make sure genEventCount branch respects switch
AndrewEdmonds11 b2bc6a8
Add totals histogram for GenEventCount
AndrewEdmonds11 a11ce84
Add an include flag for the subrun quantities
AndrewEdmonds11 a125da9
Add number of processed events to subrun ntuple. Also move filling to…
AndrewEdmonds11 07b6689
Add cosmic livetime to subrun ntuple
AndrewEdmonds11 581b8ef
Don't try to fill histograms if they weren't originally made
AndrewEdmonds11 d66f47c
Add a printout of the totals histograms into checkEventNtuple script
AndrewEdmonds11 bedf0db
Update README
AndrewEdmonds11 ae86e0c
Update fcls with new parameters
AndrewEdmonds11 bdbabf9
Add genEventCount and cosmicLivetime counting to extracted datasets
AndrewEdmonds11 5e844f2
Add copilots work for implementing subrun accessing into rooutil
AndrewEdmonds11 3ca6b61
Update subrun counting example
AndrewEdmonds11 e3c487e
Add a couple more examples showing how to cut on subruns, find a subr…
AndrewEdmonds11 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| #include "EventNtuple/fcl/from_mcs-mockdata.fcl" | ||
|
|
||
| physics.EventNtupleEndPath : [ @sequence::EventNtuple.EndPath ] # adds back genCountLogger | ||
| physics.analyzers.EventNtuple.subruns.genEventCount.include : true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| // | ||
| // SubRunInfo: subrun information | ||
| // Andy Edmonds (2026) | ||
| // | ||
| #ifndef SubRunInfo_HH | ||
| #define SubRunInfo_HH | ||
| #include <string> | ||
| namespace mu2e | ||
| { | ||
| struct SubRunInfo { | ||
| int run = 0; // run number | ||
| int subrun = 0; // subrun number | ||
| void reset() {*this = SubRunInfo(); } | ||
| }; | ||
| } | ||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
rooutil/examples/PlotCosmicTrackCrvZResidual_LivetimeNormalized.C
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| #include "EventNtuple/rooutil/inc/RooUtil.hh" | ||
| #include "EventNtuple/rooutil/inc/common_cuts.hh" | ||
|
|
||
| #include "TCanvas.h" | ||
| #include "TH1F.h" | ||
|
|
||
| #include <iostream> | ||
|
|
||
| using namespace rooutil; | ||
|
|
||
| bool crv_top_surface(TrackSegment& segment) { | ||
| if (segment.trkseg == nullptr) return false; | ||
|
|
||
| const int surface_id = segment.trkseg->sid; | ||
| return surface_id == mu2e::SurfaceIdDetail::TCRV; // note: this is a deprecated surface id, but it is what is in the file I'm testing | ||
| } | ||
|
|
||
| void PlotCosmicTrackCrvZResidual_LivetimeNormalized(std::string filename) { | ||
| RooUtil util(filename); | ||
| TH1F* crv_track_z_residual = new TH1F("crv_track_z_residual", "CRV coincidence-track z residual;z_{CRV coincidence} - z_{track} [mm];tracks / s", 100, -500, 500); | ||
|
|
||
| for (int i_event = 0; i_event < util.GetNEvents(); ++i_event) { | ||
| auto& event = util.GetEvent(i_event); | ||
| const auto tracks = event.GetTracks(); | ||
| auto crv_coincs = event.GetCrvCoincs(); | ||
| for (auto track : tracks) { | ||
| auto crv_top_segments = track.GetSegments([](TrackSegment& segment) { | ||
| return crv_top_surface(segment) && has_reco_step(segment); | ||
| }); | ||
| for (auto& segment : crv_top_segments) { | ||
| for (auto& crv_coinc : crv_coincs) { | ||
| if (track_crv_coincidence(segment, crv_coinc)) { | ||
| crv_track_z_residual->Fill(crv_coinc.reco->pos.z() - segment.trkseg->pos.z()); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| const auto entries = crv_track_z_residual->Integral(); | ||
| if (entries > 0.0) { | ||
| if (const auto rate = util.GetRate(entries)) { | ||
| crv_track_z_residual->Scale(*rate / entries); | ||
| } else { | ||
| std::cout << "Cannot normalize histogram: cosmic livetime is unavailable." << std::endl; | ||
| } | ||
| } | ||
|
|
||
| TCanvas* canvas = new TCanvas("canvas", "CRV coincidence-track z residual"); | ||
| crv_track_z_residual->Draw("HIST"); | ||
| canvas->SaveAs("crv_track_z_residual_rate.pdf"); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| #include "EventNtuple/rooutil/inc/RooUtil.hh" | ||
|
|
||
| #include <iostream> | ||
|
|
||
| using namespace rooutil; | ||
|
|
||
| bool has_more_than_100_processed_events(const SubRun& subrun) { | ||
| return subrun.has_proc_event_count && subrun.procEventCount > 100; | ||
| } | ||
|
|
||
| void SelectSubRuns(std::string filename) { | ||
| RooUtil util(filename); | ||
|
|
||
| const auto selected_subruns = util.GetSubRunIndices(has_more_than_100_processed_events); | ||
| std::cout << "SubRuns with more than 100 processed events:" << std::endl; | ||
| for (const auto i_subrun : selected_subruns) { | ||
| const auto& subrun = util.GetSubRun(i_subrun); | ||
| std::cout << subrun.srinfo->run << ":" << subrun.srinfo->subrun | ||
| << " has " << subrun.procEventCount << " processed events" << std::endl; | ||
| } | ||
|
|
||
| if (util.GetNEvents() == 0) return; | ||
|
|
||
| const auto& event = util.GetEvent(0); | ||
| const auto* event_subrun = util.FindSubRun(event.evtinfo->run, event.evtinfo->subrun); | ||
| if (event_subrun == nullptr) { | ||
| std::cout << "No SubRun information is available for the first event." << std::endl; | ||
| return; | ||
| } | ||
|
|
||
| std::cout << "First event belongs to " << event_subrun->srinfo->run << ":" | ||
| << event_subrun->srinfo->subrun; | ||
| if (event_subrun->has_cosmic_livetime) { | ||
| std::cout << " with " << event_subrun->cosmicLivetime << " s of cosmic livetime"; | ||
| } | ||
| std::cout << std::endl; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| #include "EventNtuple/rooutil/inc/RooUtil.hh" | ||
|
|
||
| #include <iostream> | ||
|
|
||
| using namespace rooutil; | ||
|
|
||
| void SubRunCounting(std::string filename) { | ||
| RooUtil util(filename); | ||
|
|
||
| std::cout << filename << " contains " << util.GetNSubRuns() << " subruns" << std::endl; | ||
| for (int i_subrun = 0; i_subrun < util.GetNSubRuns(); ++i_subrun) { | ||
| const auto& subrun = util.GetSubRun(i_subrun); | ||
| std::cout << "run " << subrun.srinfo->run << ", subrun " << subrun.srinfo->subrun; | ||
| if (subrun.has_gen_event_count) { std::cout << ": " << subrun.genEventCount << " generated events"; } | ||
| if (subrun.has_proc_event_count) { std::cout << ", " << subrun.procEventCount << " processed events"; } | ||
| if (subrun.has_cosmic_livetime) { std::cout << ", " << subrun.cosmicLivetime << " s of cosmic livetime"; } | ||
| std::cout << std::endl; | ||
| } | ||
|
|
||
| if (const auto generated_events = util.GetGeneratedEvents()) { | ||
| std::cout << "Total generated events: " << *generated_events << std::endl; | ||
| } | ||
| if (const auto processed_events = util.GetProcessedEvents()) { | ||
| std::cout << "Total processed events: " << *processed_events << std::endl; | ||
| } | ||
| if (const auto cosmic_livetime = util.GetCosmicLivetime()) { | ||
| std::cout << "Total cosmic livetime: " << *cosmic_livetime << " s" << std::endl; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| #ifndef BranchUtils_hh_ | ||
| #define BranchUtils_hh_ | ||
|
|
||
| #include "TChain.h" | ||
|
|
||
| namespace rooutil { | ||
| inline bool CheckForBranch(TChain* ntuple, const char* branch_name, void* address = nullptr) { | ||
| if (ntuple->GetBranch(branch_name) == nullptr || ntuple->GetBranchStatus(branch_name) == 0) return false; | ||
| if (address != nullptr) ntuple->SetBranchAddress(branch_name, address); | ||
| return true; | ||
| } | ||
| } // namespace rooutil | ||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for MDS cosmicLivetime would be useful