Skip to content

Commit 34ac112

Browse files
Merge pull request #355 from AndrewEdmonds11/rooutil-calohitmc
Add CaloHitMC to RooUtil analyzer class
2 parents 2ea9768 + 3104a59 commit 34ac112

6 files changed

Lines changed: 81 additions & 5 deletions

File tree

rooutil/README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ The ```EventNtupleTimeCluster``` class contains all information related to a sin
106106
The ```CaloCluster``` class contains all information related to a single calorimeter cluster
107107

108108
* single objects: ```calocluster```, ```caloclustermc```
109-
* vector objects: ```calohits```, ```calomcsim```
109+
* vector objects: ```calohits```, ```calomcsim```, ```calohitsmc```
110110

111111
Examples: [PlotCaloClusterEnergy.C](./examples/PlotCaloClusterEnergy.C), [PlotCaloClusterEnergy_RecoVsTrue.C](./examples/PlotCaloClusterEnergy_RecoVsTrue.C), [PlotCaloClusterAndHits.C](./examples/PlotCaloClusterAndHits.C), [PlotCaloCluster_SimParticles.C](./examples/PlotCaloCluster_SimParticles.C)
112112

@@ -125,10 +125,12 @@ Some branches are not contained in any of the above classes:
125125
Reach out to the developers on the #analysis-tools Slack channel if you need to have these added somewhere.
126126

127127
## Accessing User-Friendly Classes
128-
The ```Event``` class provides access to ```Tracks``` and ```CrvCoincs```:
128+
The ```Event``` class provides access to ```Tracks```, ```CaloClusters``` and ```CrvCoincs```:
129129

130130
* ```CountTracks()```: counts the number of tracks in the event
131131
* ```GetTracks()```: gets the tracks (passes you a copy)
132+
* ```CountCaloClusters()```: counts the number of calo clusters in the event
133+
* ```GetCaloClusters()```: gets the calo clusters (passes you a copy)
132134
* ```CountCrvCoincs()```: counts the number of CRV coincidences in the event
133135
* ```GetCrvCoincs()```: gets the CRV coincidences
134136

@@ -137,6 +139,10 @@ The ```Track``` class provides access to the ```TrackSegments```, the ```TrackHi
137139
* ```GetHits()```, ```CountHits()```
138140
* ```GetMCParticles()```, ```CountMCParticles()```
139141

142+
The ```CaloCluster``` class provides access to the ```CaloHits``` and the ```MCParticles```:
143+
* ```GetHits()```, ```CountHits()```
144+
* ```GetMCParticles()```, ```CountMCParticles()```
145+
140146
All of these can be passed a cut function (see below) to count / select just a subset of the objects
141147

142148
## Cut Functions
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
//
2+
// An example of how to plot reco vs true
3+
// This uses cut functions defined in common_cuts.hh
4+
//
5+
6+
#include "EventNtuple/rooutil/inc/RooUtil.hh"
7+
#include "EventNtuple/rooutil/inc/common_cuts.hh"
8+
9+
#include "TCanvas.h"
10+
#include "TH2F.h"
11+
12+
using namespace rooutil;
13+
14+
void PlotCaloHits_RecoVsTrue(std::string filename) {
15+
16+
// Set up RooUtil
17+
RooUtil util(filename);
18+
19+
TH2F* hCaloHits_RecoVsTrue = new TH2F("hCaloHits_RecoVsTrue", "Reco vs True (Calo Hits)", 110,0,110, 110,0,110);
20+
hCaloHits_RecoVsTrue->SetXTitle("Reco EDep [MeV]");
21+
hCaloHits_RecoVsTrue->SetYTitle("True EDep [MeV]");
22+
23+
// Loop through the events
24+
int n_events = util.GetNEvents();
25+
for (int i_event = 0; i_event < n_events; ++i_event) {
26+
// Get the next event
27+
auto& event = util.GetEvent(i_event);
28+
29+
// Get the e_minus tracks from the event
30+
auto calo_clusters = event.GetCaloClusters();
31+
32+
// Loop through the calo clusters
33+
int i_cluster = 0;
34+
for (auto& calo_cluster : calo_clusters) {
35+
36+
// Get the calohits for this cluster
37+
auto calohits = calo_cluster.GetHits([](CaloHit& hit){ return has_mc_hit(hit) && has_reco_hit(hit); });
38+
39+
// Loop through the calo hits
40+
for (auto& calohit : calohits) {
41+
hCaloHits_RecoVsTrue->Fill(calohit.reco->eDep_, calohit.mc->eDep);
42+
}
43+
}
44+
}
45+
46+
TCanvas* c1 = new TCanvas();
47+
hCaloHits_RecoVsTrue->Draw("COLZ");
48+
}

rooutil/examples/PrintEvents.C

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,13 @@ void PrintEvents(std::string filename) {
287287
}
288288
}
289289

290+
// calohitsmc branch
291+
if (event.calohitsmc != nullptr) {
292+
for (const auto& calohitmc : *(event.calohitsmc)) {
293+
std::cout << "calohitmc: " << calohitmc.nsim << ", " << calohitmc.eDep << ", " << calohitmc.eDepG4 << ", " << calohitmc.clusterIdx_ << std::endl;
294+
}
295+
}
296+
290297

291298
// trigger branches
292299
for (const auto& pair : event.trigger.NameToIndexMap()) {

rooutil/inc/CaloHit.hh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22
#define CaloHit_hh_
33

44
#include <functional>
5-
#include "EventNtuple/inc/TrkStrawHitInfo.hh"
6-
#include "EventNtuple/inc/TrkStrawHitInfoMC.hh"
7-
#include "EventNtuple/inc/TrkStrawHitCalibInfo.hh"
5+
#include "EventNtuple/inc/CaloHitInfo.hh"
6+
#include "EventNtuple/inc/CaloHitInfoMC.hh"
87

98
namespace rooutil {
109
struct CaloHit {
1110
CaloHit() { }
1211

1312
// Pointers to the data
1413
mu2e::CaloHitInfo* reco = nullptr;
14+
mu2e::CaloHitInfoMC* mc = nullptr;
1515
};
1616

1717
typedef std::function<bool(CaloHit&)> CaloHitCut;

rooutil/inc/Event.hh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,10 @@ namespace rooutil {
185185
CaloHit calohit;
186186
calohit.reco = &(calohits->at(calohit_Idx)); // passing the addresses of the underlying structs
187187

188+
if (calohitsmc != nullptr) { // 1-to-1 matching of calohits and calohitsmc
189+
calohit.mc = &(calohitsmc->at(calohit_Idx));
190+
}
191+
188192
calo_cluster.hits.emplace_back(calohit);
189193
}
190194
}

rooutil/inc/common_cuts.hh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,4 +317,15 @@ bool has_reco_cluster(CaloCluster& cluster) { // CaloCluster has a reco object
317317
else { return false; }
318318
}
319319

320+
//+ Calo Hit Cuts - Other
321+
bool has_mc_hit(CaloHit& hit) { // calo hit has MC truth info
322+
if (hit.mc != nullptr) { return true; }
323+
else { return false; }
324+
}
325+
bool has_reco_hit(CaloHit& hit) { // calo hit has reco info
326+
if (hit.reco != nullptr) { return true; }
327+
else { return false; }
328+
}
329+
330+
320331
#endif

0 commit comments

Comments
 (0)