10 #include <b2bii/modules/BelleMCOutput/BelleMCOutputModule.h> 
   13 #include <framework/gearbox/Unit.h> 
   14 #include <framework/logging/Logger.h> 
   17 #include <belle_legacy/tables/belletdf.h> 
   18 #include <belle_legacy/tables/hepevt.h> 
   19 #include <belle_legacy/tables/filespec.h> 
   23 #include <Math/RotationY.h> 
   24 #include <Math/Rotation3D.h> 
   36            "Output file name.", std::string(
"belle_mc.mdst"));
 
   38            "Decay K_S0 in generator.", 
false);
 
   40            "Decay Lambda in generator.", 
false);
 
   56     "************ ATTENTION! ************\n" 
   58     "  Belle MC generation differs from Belle II. In order to generate MC " 
   59     "correctly, you must do the following:\n" 
   61     "  1. Use global tag with smearing of beam parameters and generation " 
   62     "flags: b2bii_beamParameters_with_smearing (there are no smearing data " 
   63     "or generation flags in the tags B2BII or B2BII_MC).\n" 
   64     "  2. Disable smearing in Belle simulation by removing the module " 
   65     "\"bpsmear\" from basf gsim scripts.\n" 
   67     "It is also necessary to consider the following differences:\n" 
   69     "  1. When converting the simulation result back to Belle II format, " 
   70     "it is recommended to disable conversion of beam parameters " 
   71     "(convertBeamParameters = False). Since the format of the table " 
   72     "BELLE_NOMINAL_BEAM is not sufficient to store an arbitrary covariance " 
   73     "matrix, the covariance matrix of IP position (BeamSpot) is not guaranteed " 
   74     "to be exactly the same after conversion.\n" 
   75     "  2. By default, decays of long-lived particles are removed and particles " 
   76     "are declared to be stable in generator (ISTHEP == 1 in basf) because " 
   77     "such decays are simulated by GEANT3 in basf. However, you may choose " 
   78     "to decay such particles via module parameters. This results in direct " 
   79     "passing of the decay products to simulation, i.e. material effects are " 
   80     "ignored. In this case, you may need to perform an additional study " 
   81     "of the difference between data and MC.\n" 
   83     "************************************\n" 
   89   Belle::Belle_file_specification_Manager& fileManager =
 
   90     Belle::Belle_file_specification_Manager::get_manager();
 
   95     Belle::Belle_file_specification& file = fileManager.add();
 
  100   Belle::Belle_runhead_Manager& runheadManager =
 
  101     Belle::Belle_runhead_Manager::get_manager();
 
  102   runheadManager.remove();
 
  103   Belle::Belle_runhead& runhead = runheadManager.add();
 
  107   runhead.Time(time(
nullptr));
 
  111   runhead.ELER(momentumLER.E());
 
  112   runhead.EHER(momentumHER.E());
 
  113   Belle::Belle_nominal_beam_Manager& beamManager =
 
  114     Belle::Belle_nominal_beam_Manager::get_manager();
 
  115   beamManager.remove();
 
  116   Belle::Belle_nominal_beam& beam = beamManager.add();
 
  117   beam.px_high(momentumHER.X());
 
  118   beam.py_high(momentumHER.Y());
 
  119   beam.pz_high(momentumHER.Z());
 
  120   beam.px_low(momentumLER.X());
 
  121   beam.py_low(momentumLER.Y());
 
  122   beam.pz_low(momentumLER.Z());
 
  124   beam.sigma_p_high(sqrt(herCovariance[0][0]));
 
  126   beam.sigma_p_low(sqrt(lerCovariance[0][0]));
 
  132   beam.ip_x(vertex.X());
 
  133   beam.ip_y(vertex.Y());
 
  134   beam.ip_z(vertex.Z());
 
  136   beam.cang_high(momentumHER.Theta());
 
  137   beam.cang_low(M_PI - momentumLER.Theta());
 
  138   double angleIPZX = momentumHER.Theta() / 2;
 
  139   beam.angle_ip_zx(angleIPZX);
 
  144   ROOT::Math::RotationY rotationY(-angleIPZX);
 
  145   ROOT::Math::Rotation3D rotation(rotationY);
 
  146   TMatrixD rotationMatrix(3, 3);
 
  147   rotation.GetRotationMatrix(rotationMatrix);
 
  148   TMatrixDSym vertexCovariance2 = vertexCovariance.Similarity(rotationMatrix);
 
  149   beam.sigma_ip_x(sqrt(vertexCovariance2[0][0]));
 
  150   beam.sigma_ip_y(sqrt(vertexCovariance2[1][1]));
 
  151   beam.sigma_ip_z(sqrt(vertexCovariance2[2][2]));
 
  160   if (mother != 
nullptr)
 
  162   int pdg = abs(particle->
getPDG());
 
  178   std::vector<MCParticle*> daughters = particle->
getDaughters();
 
  185   Belle::Gen_hepevt_Manager& hepevtManager =
 
  186     Belle::Gen_hepevt_Manager::get_manager();
 
  187   hepevtManager.remove();
 
  204     if (particle.getMother() == 
nullptr)
 
  211     Belle::Gen_hepevt& hepevt = hepevtManager.add();
 
  218     hepevt.idhep(particle.getPDG());
 
  219     hepevt.reset_mother();
 
  222     if (mother != 
nullptr)
 
  224     hepevt.moFirst(motherIndex);
 
  225     hepevt.moLast(motherIndex);
 
  226     hepevt.daFirst(particle.getFirstDaughter());
 
  227     hepevt.daLast(particle.getLastDaughter());
 
  228     ROOT::Math::PxPyPzEVector momentum = particle.get4Vector();
 
  229     hepevt.PX(momentum.Px());
 
  230     hepevt.PY(momentum.Py());
 
  231     hepevt.PZ(momentum.Pz());
 
  232     hepevt.E(momentum.E());
 
  233     hepevt.M(particle.getMass());
 
  234     ROOT::Math::XYZVector vertex = particle.getVertex();
 
void addParticle(const MCParticle *particle, MCParticleGraph::GraphParticle *mother)
Add particle to graph.
StoreObjPtr< MCInitialParticles > m_MCInitialParticles
Initial particles.
virtual void initialize() override
Initializer.
bool m_DecayKsInGenerator
Decay K_S0 in generator.
virtual void event() override
This method is called for each event.
Belle::Panther_FileIO * m_BelleFile
Belle file input-output handler.
virtual void endRun() override
This method is called if the current run ends.
virtual void terminate() override
This method is called at the end of the event processing.
virtual void beginRun() override
Called when entering a new run.
DBObjPtr< BeamParameters > m_BeamParameters
Beam parameters.
virtual ~BelleMCOutputModule()
Destructor.
bool m_DecayLambdaInGenerator
Decay Lambda in generator.
std::string m_OutputFileName
Output file name.
StoreObjPtr< EventMetaData > m_EventMetaData
Event metadata.
StoreArray< MCParticle > m_MCParticles
MC particles.
BelleMCOutputModule()
Constructor.
MCParticleGraph m_MCParticleGraph
MC particle graph.
static const ParticleType neutron
neutron particle
static const ParticleType Lambda
Lambda particle.
static const ChargedStable muon
muon particle
static const ChargedStable pion
charged pion particle
static const ParticleType Klong
K^0_L particle.
static const double speedOfLight
[cm/ns]
static const ParticleType Kshort
K^0_S particle.
static const ChargedStable kaon
charged kaon particle
Class to represent Particle data in graph.
void comesFrom(GraphParticle &mother)
Tells the graph that this particle is a decay product of mother.
@ c_checkCyclic
Check for cyclic dependencies.
@ c_clearParticles
Clear the particle list before adding the graph.
@ c_setDecayInfo
Set decay time and vertex.
void generateList(const std::string &name="", int options=c_setNothing)
Generates the MCParticle list and stores it in the StoreArray with the given name.
A Class to store the Monte Carlo particle information.
@ c_Initial
bit 5: Particle is initial such as e+ or e- and not going to Geant4
@ c_StableInGenerator
bit 1: Particle is stable, i.e., not decaying in the generator.
int getIndex() const
Get 1-based index of the particle in the corresponding MCParticle list.
void addStatus(unsigned short int bitmask)
Add bitmask to current status.
std::vector< Belle2::MCParticle * > getDaughters() const
Get vector of all daughter particles, empty vector if none.
int getPDG() const
Return PDG code of particle.
void setDescription(const std::string &description)
Sets the description of the module.
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
@ c_Output
This module is an output module (writes data).
static const double mm
[millimeters]
REG_MODULE(B2BIIConvertBeamParams)
Register the module.
void addParam(const std::string &name, T ¶mVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
MCParticle * getMother() const
Returns a pointer to the mother particle.
void clear()
Reset particles and decay information to make the class reusable.
GraphParticle & addParticle()
Add new particle to the graph.
Abstract base class for different kinds of events.