Belle II Software development
background modules

Classes

class  BeamBkgGeneratorModule
 Beam background generator based on SAD files. More...
 
class  BeamBkgHitRateMonitorModule
 A module to monitor detector hit rates of beam background Output is to a flat ntuple. More...
 
class  BeamBkgMixerModule
 New beam background mixer; this one doesn't need ROF files. More...
 
class  BeamBkgNeutronModule
 BeamBkgNeutron module. More...
 
class  BeamBkgTagSetterModule
 A module that sets m_backgroundTag variable in SimHits (see BackgroundMetaData.h). More...
 
class  BGOverlayExecutorModule
 Overlay of measured background with simulated data (Digits or Clusters) More...
 
class  BGOverlayInputModule
 Beam BG data input, either in form of Digits or raw data. More...
 
class  EclBackgroundStudyModule
 EclBackgroundStudy module. More...
 

Functions

 REG_MODULE (BeamBkgNeutron)
 Register the Module.
 
 REG_MODULE (EclBackgroundStudy)
 Register the Module.
 
 BeamBkgNeutronModule ()
 Constructor.
 
virtual ~BeamBkgNeutronModule ()
 Destructor.
 
virtual void initialize ()
 Initialize the Module.
 
virtual void beginRun ()
 Called when entering a new run.
 
virtual void event ()
 Event processor.
 
virtual void endRun ()
 End-of-run action.
 
virtual void terminate ()
 Termination action.
 
 EclBackgroundStudyModule ()
 Constructor.
 
virtual ~EclBackgroundStudyModule ()
 Destructor.
 
virtual void initialize ()
 Initialize the Module.
 
virtual void beginRun ()
 Called when entering a new run.
 
virtual void event ()
 Event processor.
 
virtual void endRun ()
 End-of-run action.
 
virtual void terminate ()
 Termination action.
 
void printModuleParams () const
 Prints module parameters.
 

Detailed Description

Function Documentation

◆ BeamBkgNeutronModule()

Constructor.

Definition at line 55 of file BeamBkgNeutronModule.cc.

55 : Module(), m_iEntry(0), m_ff(NULL), m_tree1(NULL), m_tree2(NULL)
56 {
57 // Set description()
58 setDescription("BeamBkgNeutronModule module. Used to extract information relevant for the neutron background from background files");
59
60 // Add parameters
61 addParam("FileName", m_filename, "output file name", string("mytree.root"));
62 }

◆ beginRun() [1/2]

void beginRun ( void )
virtual

Called when entering a new run.

Set run dependent things like run header parameters, alignment, etc.

Reimplemented from Module.

Definition at line 114 of file BeamBkgNeutronModule.cc.

115 {
116 // Print run number
117 B2INFO("BeamBkgNeutron: Processing. ");
118 }

◆ beginRun() [2/2]

void beginRun ( void )
virtual

Called when entering a new run.

Set run dependent things like run header parameters, alignment, etc.

Reimplemented from Module.

Definition at line 72 of file EclBackgroundStudyModule.cc.

73 {
74 // Print run number
75 B2INFO("EclBackgroundStudy: Processing. ");
76 }

◆ EclBackgroundStudyModule()

Constructor.

Definition at line 30 of file EclBackgroundStudyModule.cc.

30 : Module(), m_iEntry(0), m_ff(NULL), m_tree1(NULL), m_tree2(NULL),
31 m_TCMap(NULL)
32 {
33 // Set description()
34 setDescription("EclBackgroundStudy module. Used to extract information relevant for the ECL background from background files");
35
36 // Add parameters
37 addParam("FileName", m_filename, "output file name", string("mytree.root"));
38 }

◆ endRun() [1/2]

void endRun ( void )
virtual

End-of-run action.

Save run-related stuff, such as statistics.

Reimplemented from Module.

Definition at line 359 of file BeamBkgNeutronModule.cc.

360 {
361 }

◆ endRun() [2/2]

void endRun ( void )
virtual

End-of-run action.

Save run-related stuff, such as statistics.

Reimplemented from Module.

Definition at line 122 of file EclBackgroundStudyModule.cc.

123 {
124 }

◆ event() [1/2]

void event ( void )
virtual

Event processor.

Convert reads information from BeamBackHits and writes tree file.

Reimplemented from Module.

Definition at line 120 of file BeamBkgNeutronModule.cc.

121 {
122 // MCParticles
123 StoreArray<MCParticle> McParticles;
124
125 // SimHits
126 StoreArray<PXDSimHit> PXDSimHits;
127 StoreArray<SVDSimHit> SVDSimHits;
128 StoreArray<CDCSimHit> CDCSimHits;
129 StoreArray<ARICHSimHit> ARICHSimHits;
130 StoreArray<TOPSimHit> TOPSimHits;
131 StoreArray<ECLSimHit> ECLSimHits;
132 StoreArray<KLMSimHit> KLMSimHits;
133
134 for (Int_t i = 0; i < 13; i++) {
135 m_nSimHits[i] = 0;
136 m_hitPDG[i] = 0;
137 m_momPDG[i] = 0;
138 }
139
140 m_nSimHits[1] = PXDSimHits.getEntries();
141 m_nSimHits[2] = SVDSimHits.getEntries();
142 m_nSimHits[3] = CDCSimHits.getEntries();
143 m_nSimHits[4] = ARICHSimHits.getEntries();
144 m_nSimHits[5] = TOPSimHits.getEntries();
145 m_nSimHits[6] = ECLSimHits.getEntries();
146 m_nSimHits[7] = KLMSimHits.getEntries();
147
148 // loop over KLM simHits
149 for (Int_t hit = 0; hit < m_nSimHits[7]; hit++) {
150 // get KLMSimHit
151// EKLMSimHit* simHit = EKLMSimHits[hit];
152 KLMSimHit* simHit = KLMSimHits[hit];
153 Float_t posZ = simHit->getPositionZ();
154 if (280.0 < posZ && posZ < 288.0) m_nSimHits[9]++; // FWD EKLM innermost layer
155 else if (400.0 < posZ && posZ < 406.0) m_nSimHits[10]++; // FWD EKLM outermost layer
156 else if (-194.0 < posZ && posZ < -186.0) m_nSimHits[11]++; // BWD EKLM innermost layer
157 else if (-294.0 < posZ && posZ < -286.0) m_nSimHits[12]++; // BWD EKLM outermost layer
158 }
159
160 RelationIndex<MCParticle, PXDSimHit> relPXDSimHitToMCParticle(McParticles, PXDSimHits);
161 RelationIndex<MCParticle, SVDSimHit> relSVDSimHitToMCParticle(McParticles, SVDSimHits);
162 RelationIndex<MCParticle, CDCSimHit> relCDCSimHitToMCParticle(McParticles, CDCSimHits);
163 RelationIndex<MCParticle, ARICHSimHit> relARICHSimHitToMCParticle(McParticles, ARICHSimHits);
164 RelationIndex<MCParticle, TOPSimHit> relTOPSimHitToMCParticle(McParticles, TOPSimHits);
165 RelationIndex<MCParticle, ECLSimHit> relECLSimHitToMCParticle(McParticles, ECLSimHits);
166 RelationIndex<MCParticle, KLMSimHit> relKLMSimHitToMCParticle(McParticles, KLMSimHits);
167
168 Int_t detID;
169
170 //--- PXD
171 detID = 1;
172 // loop over simhits
173 for (Int_t iHit = 0; iHit < m_nSimHits[detID]; iHit++) {
174 PXDSimHit* simHit = PXDSimHits[iHit];
175 // get related MCparticle
176 if (relPXDSimHitToMCParticle.getFirstElementTo(simHit)) {
177 const MCParticle* currParticle = relPXDSimHitToMCParticle.getFirstElementTo(simHit)->from;
178 m_hitPDG[detID] = currParticle->getPDG();
179 if (!currParticle->isPrimaryParticle()) {
180 const MCParticle* momParticle = currParticle->getMother();
181 m_momPDG[detID] = momParticle->getPDG();
182 }
183 }
184 }
185
186 //--- SVD
187 detID = 2;
188 // loop over simhits
189 for (Int_t iHit = 0; iHit < m_nSimHits[detID]; iHit++) {
190 SVDSimHit* simHit = SVDSimHits[iHit];
191 // get related MCparticle
192 if (relSVDSimHitToMCParticle.getFirstElementTo(simHit)) {
193 const MCParticle* currParticle = relSVDSimHitToMCParticle.getFirstElementTo(simHit)->from;
194 m_hitPDG[detID] = currParticle->getPDG();
195 if (!currParticle->isPrimaryParticle()) {
196 const MCParticle* momParticle = currParticle->getMother();
197 m_momPDG[detID] = momParticle->getPDG();
198 }
199 }
200 }
201
202 //--- CDC
203 detID = 3;
204 // loop over simhits
205 for (Int_t iHit = 0; iHit < m_nSimHits[detID]; iHit++) {
206 CDCSimHit* simHit = CDCSimHits[iHit];
207 // get related MCparticle
208 if (relCDCSimHitToMCParticle.getFirstElementTo(simHit)) {
209 const MCParticle* currParticle = relCDCSimHitToMCParticle.getFirstElementTo(simHit)->from;
210 m_hitPDG[detID] = currParticle->getPDG();
211 if (!currParticle->isPrimaryParticle()) {
212 const MCParticle* momParticle = currParticle->getMother();
213 m_momPDG[detID] = momParticle->getPDG();
214 }
215 }
216 }
217
218 //--- ARICH
219 detID = 4;
220 // loop over simhits
221 for (Int_t iHit = 0; iHit < m_nSimHits[detID]; iHit++) {
222 ARICHSimHit* simHit = ARICHSimHits[iHit];
223 // get related MCparticle
224 if (relARICHSimHitToMCParticle.getFirstElementTo(simHit)) {
225 const MCParticle* currParticle = relARICHSimHitToMCParticle.getFirstElementTo(simHit)->from;
226 m_hitPDG[detID] = currParticle->getPDG();
227 if (!currParticle->isPrimaryParticle()) {
228 const MCParticle* momParticle = currParticle->getMother();
229 m_momPDG[detID] = momParticle->getPDG();
230 }
231 }
232 }
233
234 //--- TOP
235 detID = 5;
236 // loop over simhits
237 for (Int_t iHit = 0; iHit < m_nSimHits[detID]; iHit++) {
238 TOPSimHit* simHit = TOPSimHits[iHit];
239 // get related MCparticle
240 if (relTOPSimHitToMCParticle.getFirstElementTo(simHit)) {
241 const MCParticle* currParticle = relTOPSimHitToMCParticle.getFirstElementTo(simHit)->from;
242 m_hitPDG[detID] = currParticle->getPDG();
243 if (!currParticle->isPrimaryParticle()) {
244 const MCParticle* momParticle = currParticle->getMother();
245 m_momPDG[detID] = momParticle->getPDG();
246 }
247 }
248 }
249
250 //--- ECL
251 detID = 6;
252 // loop over simhits
253 for (Int_t iHit = 0; iHit < m_nSimHits[detID]; iHit++) {
254 ECLSimHit* simHit = ECLSimHits[iHit];
255 // get related MCparticle
256 if (relECLSimHitToMCParticle.getFirstElementTo(simHit)) {
257 const MCParticle* currParticle = relECLSimHitToMCParticle.getFirstElementTo(simHit)->from;
258 m_hitPDG[detID] = currParticle->getPDG();
259 if (!currParticle->isPrimaryParticle()) {
260 const MCParticle* momParticle = currParticle->getMother();
261 m_momPDG[detID] = momParticle->getPDG();
262 }
263 }
264 }
265 //--- KLM
266 detID = 7;
267 // loop over simhits
268 for (Int_t iHit = 0; iHit < m_nSimHits[detID]; iHit++) {
269 KLMSimHit* simHit = KLMSimHits[iHit];
270 // get related MCparticle
271 if (relKLMSimHitToMCParticle.getFirstElementTo(simHit)) {
272 const MCParticle* currParticle = relKLMSimHitToMCParticle.getFirstElementTo(simHit)->from;
273 m_hitPDG[detID] = currParticle->getPDG();
274 if (!currParticle->isPrimaryParticle()) {
275 const MCParticle* momParticle = currParticle->getMother();
276 m_momPDG[detID] = momParticle->getPDG();
277 }
278 }
279 }
280
281 // fill the tree
282 m_tree2->Fill();
283
284 // BeamBkgHits
285 StoreArray<BeamBackHit> BeamBackHits;
286 RelationIndex<MCParticle, BeamBackHit> relBeamBackHitToMCParticle(McParticles, BeamBackHits);
287
288 Int_t nHits = BeamBackHits.getEntries();
289
290 // loop over bkgHits
291 for (Int_t iHit = 0; iHit < nHits; iHit++) {
292 // get one bkgHit
293 BeamBackHit* bkgHit = BeamBackHits[iHit];
294 if (bkgHit->getPDG() == 2112) { /*neutron*/
295 m_iEvent = m_iEntry;
296 m_iden = bkgHit->getIdentifier();
297 m_subDet = bkgHit->getSubDet();
298 m_PDG = bkgHit->getPDG();
299 m_trackID = bkgHit->getTrackID();
300 auto position = bkgHit->getPosition();
301 m_positionX = position.X();
302 m_positionY = position.Y();
303 m_positionZ = position.Z();
304 auto momentum = bkgHit->getMomentum();
305 m_momentumX = momentum.X();
306 m_momentumY = momentum.Y();
307 m_momentumZ = momentum.Z();
308 m_E_start = bkgHit->getEnergy();
309 m_E_end = bkgHit->getEnergyAtExit();
310 m_eDep = bkgHit->getEnergyDeposit();
311 m_trackLength = bkgHit->getTrackLength();
312 m_nWeight = bkgHit->getNeutronWeight();
313
314 m_trj_x.clear();
315 m_trj_y.clear();
316 m_trj_z.clear();
317 m_trj_px.clear();
318 m_trj_py.clear();
319 m_trj_pz.clear();
320
321 // get related MCparticle
322 if (relBeamBackHitToMCParticle.getFirstElementTo(bkgHit)) {
323 const MCParticle* currParticle = relBeamBackHitToMCParticle.getFirstElementTo(bkgHit)->from;
324 auto m_vtxProd = currParticle->getVertex();
325 m_E_init = currParticle->getEnergy();
326 m_mass = currParticle->getMass();
327 m_lifeTime = currParticle->getLifetime();
328 m_vtxProdX = m_vtxProd.X();
329 m_vtxProdY = m_vtxProd.Y();
330 m_vtxProdZ = m_vtxProd.Z();
331
332 // get trajectory stored for this particle
333 const auto mcTrajectories = currParticle->getRelationsTo<MCParticleTrajectory>();
334 for (auto rel : mcTrajectories.relations()) {
335 // the trajectories with negative weight are from secondary daughters which were ignored so we don't use them
336 if (rel.weight <= 0) continue;
337 // get the trajectory
338 const MCParticleTrajectory& trajectory = dynamic_cast<const MCParticleTrajectory&>(*rel.object);
339 // loop over each point
340 for (const MCTrajectoryPoint& pt : trajectory) {
341 m_trj_x.push_back(pt.x);
342 m_trj_y.push_back(pt.y);
343 m_trj_z.push_back(pt.z);
344 m_trj_px.push_back(pt.px);
345 m_trj_py.push_back(pt.py);
346 m_trj_pz.push_back(pt.pz);
347 }
348 }
349 }
350
351 // fill the tree
352 m_tree1->Fill();
353 }
354 }
355 // increase the entry counter
356 m_iEntry++;
357 }
ROOT::Math::XYZVector getVertex() const
Returns vertex position (POCA for charged, IP for neutral FS particles)
Definition Particle.h:651

◆ event() [2/2]

void event ( void )
virtual

Event processor.

Convert reads information from ECLHits/ECKSimHits and writes tree file.

Reimplemented from Module.

Definition at line 78 of file EclBackgroundStudyModule.cc.

79 {
80 m_CellId.clear();
81 m_TcId.clear();
82 m_Pdg.clear();
83 m_Edep.clear();
84 m_TimeAve.clear();
85 m_FlightTime.clear();
86 m_Hadronedep.clear();
87
88 // loop over ECLHits
89 for (const ECLHit& hit : m_ECLHits) {
90 m_CellId.push_back(hit.getCellId());
91 m_TcId.push_back(m_TCMap->getTCIdFromXtalId(hit.getCellId()));
92 m_Edep.push_back(hit.getEnergyDep());
93 m_TimeAve.push_back(hit.getTimeAve());
94 }
95 // fill the tree
96 m_tree1->Fill();
97
98 m_CellId.clear();
99 m_TcId.clear();
100 m_Pdg.clear();
101 m_Edep.clear();
102 m_TimeAve.clear();
103 m_FlightTime.clear();
104 m_Hadronedep.clear();
105
106 // loop over ECLSimHits
107 for (const ECLSimHit& hit : m_ECLSimHits) {
108 m_CellId.push_back(hit.getCellId());
109 m_TcId.push_back(m_TCMap->getTCIdFromXtalId(hit.getCellId()));
110 m_Pdg.push_back(hit.getPDGCode());
111 m_FlightTime.push_back(hit.getFlightTime());
112 m_Edep.push_back(hit.getEnergyDep());
113 m_Hadronedep.push_back(hit.getHadronEnergyDep());
114 }
115 // fill the tree
116 m_tree2->Fill();
117
118 // increase the entry counter
119 m_iEntry++;
120 }

◆ initialize() [1/2]

void initialize ( void )
virtual

Initialize the Module.

This method is called at the beginning of data processing.

Reimplemented from Module.

Definition at line 68 of file BeamBkgNeutronModule.cc.

69 {
70 // create/open the file
71 m_ff = new TFile(m_filename.c_str(), "RECREATE");
72
73 // create trees
74 m_tree1 = new TTree("tree1", "BeamBackHit data");
75 m_tree2 = new TTree("tree2", "SimHits data");
76
77 // create branches
78 m_tree1->Branch("event", &m_iEvent, "event/I");
79 m_tree1->Branch("subDet", &m_subDet, "subDet/I");
80 m_tree1->Branch("iden", &m_iden, "iden/I");
81 m_tree1->Branch("PDG", &m_PDG, "PDG/I");
82 m_tree1->Branch("trackID", &m_trackID, "trackID/I");
83 m_tree1->Branch("momentumX", &m_momentumX, "momentumX/F");
84 m_tree1->Branch("momentumY", &m_momentumY, "momentumY/F");
85 m_tree1->Branch("momentumZ", &m_momentumZ, "momentumZ/F");
86 m_tree1->Branch("positionX", &m_positionX, "positionX/F");
87 m_tree1->Branch("positionY", &m_positionY, "positionY/F");
88 m_tree1->Branch("positionZ", &m_positionZ, "positionZ/F");
89 m_tree1->Branch("E_start", &m_E_start, "E_start/F");
90 m_tree1->Branch("E_end", &m_E_end, "E_end/F");
91 m_tree1->Branch("eDep", &m_eDep, "eDep/F");
92 m_tree1->Branch("trackLength", &m_trackLength, "trackLength/F");
93 m_tree1->Branch("nWeight", &m_nWeight, "nWeight/F");
94 m_tree1->Branch("E_init", &m_E_init, "E_init/F");
95 m_tree1->Branch("mass", &m_mass, "mass/F");
96 m_tree1->Branch("lifeTime", &m_lifeTime, "lifeTime/F");
97 m_tree1->Branch("vtxProdX", &m_vtxProdX, "vtxProdX/F");
98 m_tree1->Branch("vtxProdY", &m_vtxProdY, "vtxProdY/F");
99 m_tree1->Branch("vtxProdZ", &m_vtxProdZ, "vtxProdZ/F");
100 m_tree1->Branch("trj_x", &m_trj_x);
101 m_tree1->Branch("trj_y", &m_trj_y);
102 m_tree1->Branch("trj_z", &m_trj_z);
103 m_tree1->Branch("trj_px", &m_trj_px);
104 m_tree1->Branch("trj_py", &m_trj_py);
105 m_tree1->Branch("trj_pz", &m_trj_pz);
106
107 m_tree2->Branch("nSimHits", m_nSimHits, "nSimHits[13]/I");
108 m_tree2->Branch("hitPDG", m_hitPDG, "hitPDG[13]/I");
109 m_tree2->Branch("momPDG", m_momPDG, "momPDG[13]/I");
110// std::string xyzvector_typedef = "std::vector<ROOT::Math::DisplacementVector3D<ROOT::Math::Cartesian3D<double>,ROOT::Math::DefaultCoordinateSystemTag>>";
111// tt->Branch("vtxProd", "xyzvector_typedef.c_str()", &m_vtxProd);
112 }

◆ initialize() [2/2]

void initialize ( void )
virtual

Initialize the Module.

This method is called at the beginning of data processing.

Reimplemented from Module.

Definition at line 44 of file EclBackgroundStudyModule.cc.

45 {
46 // Print set parameters
47 printModuleParams();
48
49 // create/open the file
50 m_ff = new TFile(m_filename.c_str(), "RECREATE");
51
52 // create trees
53 m_tree1 = new TTree("tree1", "ECLHits data");
54 m_tree2 = new TTree("tree2", "ECLSimHits data");
55
56 // create branches
57 m_tree1->Branch("CellId", &m_CellId);
58 m_tree1->Branch("TcId", &m_TcId);
59 m_tree1->Branch("Edep", &m_Edep);
60 m_tree1->Branch("TimeAve", &m_TimeAve);
61
62 m_tree2->Branch("CellId", &m_CellId);
63 m_tree2->Branch("TcId", &m_TcId);
64 m_tree2->Branch("Pdg", &m_Pdg);
65 m_tree2->Branch("FlightTime", &m_FlightTime);
66 m_tree2->Branch("Edep", &m_Edep);
67 m_tree2->Branch("Hadronedep", &m_Hadronedep);
68
69 m_TCMap = new TrgEclMapping();
70 }

◆ printModuleParams()

void printModuleParams ( ) const

Prints module parameters.

Definition at line 142 of file EclBackgroundStudyModule.cc.

143 {
144 B2INFO("EclBackgroundStudy: output file name = " << m_filename);
145 }

◆ terminate() [1/2]

void terminate ( void )
virtual

Termination action.

Clean-up, close files, summarize statistics, etc.

Reimplemented from Module.

Definition at line 363 of file BeamBkgNeutronModule.cc.

364 {
365 // CPU time end
366
367 // Announce
368 B2INFO("BeamBkgNeutron finished.");
369
370 // write
371 m_ff->cd();
372 m_tree1->Write();
373 m_tree2->Write();
374 // close the tree
375 m_ff->Close();
376 }

◆ terminate() [2/2]

void terminate ( void )
virtual

Termination action.

Clean-up, close files, summarize statistics, etc.

Reimplemented from Module.

Definition at line 126 of file EclBackgroundStudyModule.cc.

127 {
128 // CPU time end
129
130 // Announce
131 B2INFO("EclBackgroundStudy finished.");
132 B2INFO("nEntries = " << m_iEntry);
133
134 // write
135 m_ff->cd();
136 m_tree1->Write();
137 m_tree2->Write();
138 // close the tree
139 m_ff->Close();
140 }

◆ ~BeamBkgNeutronModule()

~BeamBkgNeutronModule ( )
virtual

Destructor.

Definition at line 64 of file BeamBkgNeutronModule.cc.

65 {
66 }

◆ ~EclBackgroundStudyModule()

Destructor.

Definition at line 40 of file EclBackgroundStudyModule.cc.

41 {
42 }