Belle II Software  release-08-01-10
MasterClassModule.cc
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 
9 #include <masterclass/modules/MasterClassModule.h>
10 #include <mdst/dataobjects/PIDLikelihood.h>
11 #include <analysis/dataobjects/Particle.h>
12 
13 #include <TDirectory.h>
14 #include <iostream>
15 
16 using namespace Belle2;
17 
18 //-----------------------------------------------------------------
19 // Register the Module
20 //-----------------------------------------------------------------
21 REG_MODULE(MasterClass);
22 
23 //-----------------------------------------------------------------
24 // Implementation
25 //-----------------------------------------------------------------
26 
28 {
29  // Set module properties
30  setDescription(R"DOC(Module to write out data in a format for Belle II masterclasses)DOC");
31  addParam("outputFileName", m_filename, "File name of root ntuple output.", std::string("masterclass.root"));
32 }
33 
35 {
36  m_tracks.isRequired();
37  m_clusters.isRequired();
38 
39  m_event = new BEvent;
40  m_file = TFile::Open(m_filename.c_str(), "RECREATE");
41  m_tree = new TTree("T", "Event Tree");
42  m_tree->Branch("BEvent", &m_event);
43 }
44 
46 {
47  m_event->Clear();
49 
50  for (auto& track : m_tracks) {
51  auto pid = track.getRelated<PIDLikelihood>();
52  const double priors[] = {0.05, 0.05, 0.65, 0.24, 0.01, 0};
53  auto type = pid->getMostLikely(priors);
54 
56 
57  auto trackFit = track.getTrackFitResultWithClosestMass(type);
58  auto p = trackFit->getMomentum();
59  double m = type.getMass();
60  SIMPLEPID id = ALL;
61  switch (type.getPDGCode()) {
62  case 11: id = ELECTRON; break;
63  case 13: id = MUON; break;
64  case 211: id = PION; break;
65  case 321: id = KAON; break;
66  case 2212: id = PROTON; break;
67  default: id = ALL;
68  }
70  p.x(), p.y(), p.z(), sqrt(m * m + p.Mag2()),
71  trackFit->getChargeSign(), id,
72  pid->getLogL(Const::ChargedStable(11), detectorSet), // e
73  pid->getLogL(Const::ChargedStable(13), detectorSet), // mu
74  pid->getLogL(Const::ChargedStable(211), detectorSet), // pi
75  pid->getLogL(Const::ChargedStable(321), detectorSet), // K
76  pid->getLogL(Const::ChargedStable(2212), detectorSet), // p
77  pid->getLogL(Const::ChargedStable(1000010020), detectorSet) // d
78  );
79  }
80 
81  for (auto& cluster : m_clusters) {
82  if (!cluster.hasHypothesis(ECLCluster::EHypothesisBit::c_nPhotons)) continue;
83  double E = cluster.getEnergy(ECLCluster::EHypothesisBit::c_nPhotons);
84  if (E < 0.1) continue;
85  ROOT::Math::XYZVector p = cluster.getClusterPosition();
86  p *= (E / p.R());
88  p.x(), p.y(), p.z(), E,
89  0, PHOTON
90  );
91  }
92 
93  m_tree->Fill();
94 }
95 
97 {
98  m_file->cd();
99  m_tree->Write();
100  m_file->Close();
101  delete m_file;
102 }
R E
internal precision of FFTW codelets
The Class for Masterclass event parameters.
Definition: BEvent.h:19
virtual void Clear(Option_t *="")
Clear the array of particles.
Definition: BEvent.cc:57
void AddTrack(float px, float py, float pz, float e, float charge, SIMPLEPID pid)
Add the track to the event.
Definition: BEvent.cc:34
void EventNo(int evtno)
Set the current event number.
Definition: BEvent.cc:24
Provides a type-safe way to pass members of the chargedStableSet set.
Definition: Const.h:580
static DetectorSet set()
Accessor function for the set of valid detectors.
Definition: Const.h:365
A class for sets of detector IDs whose content is limited to restricted set of valid detector IDs.
Definition: Const.h:287
@ c_nPhotons
CR is split into n photons (N1)
TTree * m_tree
output tree
virtual void initialize() override
Register input and output data.
BEvent * m_event
output event object
StoreArray< ECLCluster > m_clusters
Cluster objects.
virtual void event() override
Write out particles.
virtual void terminate() override
Close ntuple.
StoreArray< Track > m_tracks
Track objects.
TFile * m_file
root ntuple file
MasterClassModule()
Constructor: Sets the description, the properties and the parameters of the module.
std::string m_filename
output file name
Base class for Modules.
Definition: Module.h:72
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
Class to collect log likelihoods from TOP, ARICH, dEdx, ECL and KLM aimed for output to mdst includes...
Definition: PIDLikelihood.h:26
REG_MODULE(arichBtest)
Register the Module.
void addParam(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
Definition: Module.h:560
double sqrt(double a)
sqrt for double
Definition: beamHelpers.h:28
Abstract base class for different kinds of events.