10 #include <klm/bklm/modules/bklmSimHistogrammer/BKLMSimHistogrammerModule.h>
13 #include <klm/dataobjects/bklm/BKLMSimHit.h>
14 #include <klm/dataobjects/KLMDigit.h>
17 #include <framework/dataobjects/EventMetaData.h>
18 #include <framework/datastore/StoreArray.h>
19 #include <framework/datastore/StoreObjPtr.h>
40 m_hSimHitPerChannelLayer(
nullptr),
42 m_hSimHitPhiRPC(
nullptr),
43 m_bgSourcePerLayer(
nullptr),
44 m_bgSourcePerLayer2D(
nullptr),
45 m_bgSourceVsPhi(
nullptr),
46 m_bgSourceVsTheta(
nullptr),
48 m_bgSource2D(
nullptr),
49 m_hSimHitPhiScinti(
nullptr),
50 m_hSimHitThetaRPC(
nullptr),
51 m_hSimHitThetaScinti(
nullptr),
52 m_hSimHit_layer(
nullptr),
53 m_hSimHit_layer2D(
nullptr),
54 m_hSimHitThetaPhiRPC(
nullptr),
55 m_hSimHitThetaPhiScinti(
nullptr),
60 setDescription(
"Analyzes bg");
62 addParam(
"filename", m_filename,
"Output root filename",
string(
"bg_output.root"));
63 addParam(
"realTime", m_realTime,
"Time the simulation corresponds to",
float(1.0));
68 BKLMSimHistogrammerModule::~BKLMSimHistogrammerModule()
72 void BKLMSimHistogrammerModule::initialize()
79 m_file =
new TFile(m_filename.c_str(),
"recreate");
81 m_hEvt =
new TH1D(
"hEvts",
"hEvts", 10001, -1, 10000);
83 m_hSimHitPhiRPC =
new TH1D(
"simhitPhiRPC",
"simHitPhiRPC", 100, -1 * TMath::Pi(), 1 * TMath::Pi());
84 m_hSimHitPhiScinti =
new TH1D(
"simhitPhiScinti",
"simHitPhiScinti", 100, -1 * TMath::Pi(), 1 * TMath::Pi());
85 m_hSimHitThetaRPC =
new TH1D(
"simhitThetaRPC",
"simHitThetaRPC", 100, 0, 1 * TMath::Pi());
86 m_hSimHitThetaScinti =
new TH1D(
"simhitThetaScinti",
"simHitThetaScinti", 100, 0, 1 * TMath::Pi());
88 m_hSimHit_layer =
new TH1I(
"simHitLayer",
"simHitLayer", 16, 0, 15);
89 m_hSimHit_layer2D =
new TH1I(
"simHitLayer2D",
"simHitLayer2D", 16, 0, 15);
91 m_bgSourcePerLayer =
new TH2D(
"bgSourcPerLayer",
"bgSourcePerLayer", 21, 0, 20, 16, 0, 15);
92 m_bgSourcePerLayer2D =
new TH2D(
"bgSourcPerLayer2D",
"bgSourcePerLayer2D", 21, 0, 20, 16, 0, 15);
93 m_bgSourceVsPhi =
new TH2D(
"bgSourceVsPhi",
"bgSourceVsPhi", 100, -1 * TMath::Pi(), TMath::Pi(), 21, 0, 20);
94 m_bgSourceVsTheta =
new TH2D(
"bgSourceVsTheta",
"bgSourceVsTheta", 100, 0, TMath::Pi(), 21, 0, 20);
96 m_bgSource =
new TH1D(
"bgSource",
"bgSource", 21, 0, 20);
97 m_bgSource2D =
new TH1D(
"bgSource2D",
"bgSource2D", 21, 0, 20);
99 m_hSimHitPerChannelLayer =
new TH2D(
"posPerChannelLayer",
"posPerChannelLayer", 5000, 0, 5000, 16, 0, 15);
105 void BKLMSimHistogrammerModule::beginRun()
108 B2INFO(
"BKLMSimHistogrammer: Experiment " << evtMetaData->getExperiment() <<
" run " << evtMetaData->getRun());
111 void BKLMSimHistogrammerModule::event()
117 int nSimHit = simHits.getEntries();
125 m_weight = 1.0 / m_realTime;
127 cout <<
"real time " << m_realTime <<
" weight: " << m_weight << endl;
129 int n2DHits = hits2D.getEntries();
130 int n1DHits = hits1D.getEntries();
131 cout <<
"we have " << nSimHit <<
" sim hits " << n1DHits <<
" 1D hits " << n2DHits <<
" 2D hits " << endl;
135 m_hEvt->Fill(n2DHits, m_weight);
136 for (
int i = 0; i < hits1D.getEntries(); i++) {
137 cout <<
"looking at 1DHit " << i << endl;
140 for (
const auto& bklmDigit : bklmDigits) {
142 for (
const auto& simHit : relatedSimHits) {
148 cout <<
"scaledTag: " << scaledTag << endl;
226 int channel = hits1D[i]->getSection() * 840 + hits1D[i]->getSector() * 105 + hits1D[i]->isPhiReadout() * 1680 +
227 hits1D[i]->getStripAve();
228 m_hSimHitPerChannelLayer->Fill(channel, hits1D[i]->getLayer(), m_weight);
229 m_bgSource->Fill(scaledTag, m_weight);
230 m_bgSourcePerLayer->Fill(scaledTag, hits1D[i]->getLayer(), m_weight);
231 cout <<
"filling layer with tag: " << scaledTag <<
" and layer " << hits1D[i]->getLayer() << endl;
234 for (
int i = 0; i < hits2D.getEntries(); i++) {
236 TVector3 gHitPos = hits2D[i]->getGlobalPosition();
238 for (
const auto& hit1d : related1DHits) {
240 for (
const auto& bklmDigit : bklmDigits) {
242 for (
const auto& simHit : relatedSimHits) {
250 m_bgSourcePerLayer2D->Fill(scaledTag, hits2D[i]->getLayer(), m_weight);
251 m_bgSource2D->Fill(scaledTag, m_weight);
252 m_bgSourceVsTheta->Fill(gHitPos.Theta(), scaledTag, m_weight);
253 m_bgSourceVsPhi->Fill(gHitPos.Phi(), scaledTag, m_weight);
290 for (
int i = 0; i < n2DHits; i++) {
293 if (hit2D->
inRPC()) {
294 m_hSimHitPhiRPC->Fill(gHitPos.Phi(), m_weight);
295 m_hSimHitThetaRPC->Fill(gHitPos.Theta(), m_weight);
297 m_hSimHitPhiScinti->Fill(gHitPos.Phi(), m_weight);
298 m_hSimHitThetaScinti->Fill(gHitPos.Theta(), m_weight);
305 for (
int h = 0; h < nSimHit; ++h) {
310 if (bklmMCParticles.
size() > 0) {
311 cout <<
"found MC particle!" << endl;
313 cout <<
"got " << bklmMCParticlesTo.
size() <<
" as relation to " << endl;
372 void BKLMSimHistogrammerModule::endRun()
376 void BKLMSimHistogrammerModule::terminate()
Store one reconstructed BKLM 1D hit as a ROOT object.
Store one BKLM strip hit as a ROOT object.
bool inRPC() const
Determine whether this 2D hit is in RPC or scintillator.
TVector3 getGlobalPosition(void) const
Get 3D hit position in global coordinates.
Convert BKLM raw simulation hits to digitizations.
Store one simulation hit as a ROOT object.
KLM digit (class representing a digitized hit in RPCs or scintillators).
A Class to store the Monte Carlo particle information.
Class for type safe access to objects that are referred to in relations.
size_t size() const
Get number of relations.
RelationVector< FROM > getRelationsFrom(const std::string &name="", const std::string &namedRelation="") const
Get the relations that point from another store array to this object.
RelationVector< TO > getRelationsTo(const std::string &name="", const std::string &namedRelation="") const
Get the relations that point from this object to another store array.
virtual unsigned short getBackgroundTag() const
Get background tag.
Type-safe access to single objects in the data store.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Abstract base class for different kinds of events.