Added Mu0 spin-flip process

This commit is contained in:
Thomas Prokscha
2016-02-17 14:22:21 +01:00
parent 352ac5db21
commit 1c31fc88d0
3 changed files with 700 additions and 483 deletions

View File

@ -1,382 +1,442 @@
/*************************************************************************** /***************************************************************************
PSimulateMuTransition.cpp PSimulateMuTransition.cpp
Author: Thomas Prokscha Author: Thomas Prokscha
Date: 25-Feb-2010 Date: 25-Feb-2010
$Id$ $Id$
Use root macros runMuSimulation.C and testAnalysis.C to run the simulation Use root macros runMuSimulation.C and testAnalysis.C to run the simulation
and to get a quick look on the data. Data are saved to a root histogram file and to get a quick look on the data. Data are saved to a root histogram file
with a structure similar to LEM histogram files; musrfit can be used to with a structure similar to LEM histogram files; musrfit can be used to
analyze the simulated data. analyze the simulated data.
Description: Description:
Root class to simulate muon spin phase under successive Mu+/Mu0 charge-exchange Root class to simulate muon spin phase under successive Mu+/Mu0 charge-exchange
processes by a Monte-Carlo method. Consider transverse field geometry, and assume processes by a Monte-Carlo method. Consider transverse field geometry, and assume
initial muon spin direction in x, and field applied along z. For PxMu(t) in initial muon spin direction in x, and field applied along z. For PxMu(t) in
muonium use the equation 8.22 of the muSR book of Yaounc and Dalmas de Réotier, in muonium use the equation 8.22 of the muSR book of Yaounc and Dalmas de Réotier, in
slightly modified form (see Senba, J. Phys. B 23, 1545 (1990)); note that PxMu(t) slightly modified form (see Senba, J. Phys. B 23, 1545 (1990)); note that PxMu(t)
is given by a superposition of the four frequencies "nu_12", "nu_34", "nu_23", "nu_14". is given by a superposition of the four frequencies "nu_12", "nu_34", "nu_23", "nu_14".
These frequencies and the corresponding probabilities ("SetMuFractionState12" for These frequencies and the corresponding probabilities ("SetMuFractionState12" for
transitions 12 and 34, "SetMuFractionState23" for states 23 and 14) can be calculated transitions 12 and 34, "SetMuFractionState23" for states 23 and 14) can be calculated
for a given field with the root macro AnisotropicMu.C for a given field with the root macro AnisotropicMu.C
Parameters: Parameters:
1) Precession frequencies of "nu_12", "nu_34", "nu_23", "nu_14" 1) Precession frequencies of "nu_12", "nu_34", "nu_23", "nu_14"
2) fractions of nu_12, nu_34; and nu_23 and nu_14 2) fractions of nu_12, nu_34; and nu_23 and nu_14
3) total Mu0 fraction 3) total Mu0 fraction
4) electron-capture rate 4) electron-capture rate
5) Mu ionization rate 5) Mu ionization rate
6) initial muon spin phase 6) initial muon spin phase
7) total muon decay asymmetry 7) total muon decay asymmetry
8) number of muon decays to be generated. 8) number of muon decays to be generated.
9) debug flag: if TRUE print capture/ionization events on screen 9) debug flag: if TRUE print capture/ionization events on screen
Output: Output:
Two histograms ("forward" and "backward") are written to a root file. Two histograms ("forward" and "backward") are written to a root file.
The muon event simulation with a sequence of charge-changing processes is The muon event simulation with a sequence of charge-changing processes is
done in Event(): done in Event():
simulate muon spin phase under charge-exchange with "4 Mu transitions" simulate muon spin phase under charge-exchange with "4 Mu transitions"
1) according to Mu+/Mu0 fraction begin either with a Mu+ state or Mu state 1) according to Mu+/Mu0 fraction begin either with a Mu+ state or Mu state
2) Mu+: determine next electron-capture time t_c. If t_c is larger than decay time t_d 2) Mu+: determine next electron-capture time t_c. If t_c is larger than decay time t_d
calculate muon spin precession for t_d; else calculate spin precession for t_c. calculate muon spin precession for t_d; else calculate spin precession for t_c.
3) Determine next ionization time t_i; calculate Px(t_i) in Muonium; calculate the 3) Determine next ionization time t_i; calculate Px(t_i) in Muonium; calculate the
muon spin phase by acos(Px(t_i)). muon spin phase by acos(Px(t_i)).
4) get the next electron capture time, continue until t_d is reached; accumulate muon spin 4) get the next electron capture time, continue until t_d is reached; accumulate muon spin
phase. phase.
***************************************************************************/ ***************************************************************************/
/*************************************************************************** /***************************************************************************
* Copyright (C) 2010 by Thomas Prokscha, Paul Scherrer Institut * * Copyright (C) 2010 by Thomas Prokscha, Paul Scherrer Institut *
* * * *
* This program is free software; you can redistribute it and/or modify * * This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by * * it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or * * the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. * * (at your option) any later version. *
* * * *
* This program is distributed in the hope that it will be useful, * * This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of * * but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. * * GNU General Public License for more details. *
* * * *
* You should have received a copy of the GNU General Public License * * You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the * * along with this program; if not, write to the *
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#include <iostream> #include <iostream>
using namespace std; using namespace std;
#include <TMath.h> #include <TMath.h>
#include "PSimulateMuTransition.h" #include "PSimulateMuTransition.h"
ClassImp(PSimulateMuTransition) ClassImp(PSimulateMuTransition)
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
// Constructor // Constructor
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
/** /**
* <p> Constructor. * <p> Constructor.
* *
* \param seed for the random number generator * \param seed for the random number generator
*/ */
PSimulateMuTransition::PSimulateMuTransition(UInt_t seed) PSimulateMuTransition::PSimulateMuTransition(UInt_t seed)
{ {
fValid = true; fValid = true;
fRandom = new TRandom2(seed); fRandom = new TRandom2(seed);
if (fRandom == 0) { if (fRandom == 0) {
fValid = false; fValid = false;
} }
fNmuons = 100; // number of muons to simulate fNmuons = 100; // number of muons to simulate
fMuPrecFreq34 = 4463.; // vacuum Mu hyperfine coupling constant fMuPrecFreq34 = 4463.; // vacuum Mu hyperfine coupling constant
fMuPrecFreq12 = 0.; // Mu precession frequency of a 12 transition fMuPrecFreq12 = 0.; // Mu precession frequency of a 12 transition
fMuPrecFreq23 = 0.; // Mu precession frequency of a 23 transition fMuPrecFreq23 = 0.; // Mu precession frequency of a 23 transition
fMuPrecFreq14 = 0.; // Mu precession frequency of a 14 transition fMuPrecFreq14 = 0.; // Mu precession frequency of a 14 transition
fMuonPrecFreq = 0.; // muon precession frequency fMuonPrecFreq = 0.; // muon precession frequency
fBfield = 0.01; // magnetic field (T) fBfield = 0.01; // magnetic field (T)
fCaptureRate = 0.01; // Mu+ capture rate (MHz) fCaptureRate = 0.01; // Mu+ capture rate (MHz)
fIonizationRate = 10.; // Mu0 ionization rate (MHz) fIonizationRate = 10.; // Mu0 ionization rate (MHz)
fInitialPhase = 0.; fSpinFlipRate = 0.001; // Mu0 spin flip rate (MHz)
fMuonPhase = fInitialPhase; fInitialPhase = 0.;
fMuonDecayTime = 0.; fMuonPhase = fInitialPhase;
fAsymmetry = 0.27; fMuonDecayTime = 0.;
fMuFraction = 0.; fAsymmetry = 0.27;
fMuFractionState12 = 0.; fMuFraction = 0.;
fMuFractionState23 = 0.; fMuFractionState12 = 0.;
fDebugFlag = kFALSE; fMuFractionState23 = 0.;
} fDebugFlag = kFALSE;
}
//--------------------------------------------------------------------------
// Destructor //--------------------------------------------------------------------------
//-------------------------------------------------------------------------- // Destructor
/** //--------------------------------------------------------------------------
* <p> Destructor. /**
* * <p> Destructor.
*/ *
PSimulateMuTransition::~PSimulateMuTransition() */
{ PSimulateMuTransition::~PSimulateMuTransition()
if (fRandom) { {
delete fRandom; if (fRandom) {
fRandom = 0; delete fRandom;
} fRandom = 0;
} }
//-------------------------------------------------------------------------- }
// Output of current settings //--------------------------------------------------------------------------
//-------------------------------------------------------------------------- // Output of current settings
/*! //--------------------------------------------------------------------------
* <p>Prints the current settings onto std output. /*!
*/ * <p>Prints the current settings onto std output.
void PSimulateMuTransition::PrintSettings() const */
{ void PSimulateMuTransition::PrintSettings() const
cout << endl << "Mu precession frequency 12 (MHz) = " << fMuPrecFreq12; {
cout << endl << "Mu precession frequency 34 (MHz) = " << fMuPrecFreq34; cout << endl << "Mu precession frequency 12 (MHz) = " << fMuPrecFreq12;
cout << endl << "Mu precession frequency 23 (MHz) = " << fMuPrecFreq23; cout << endl << "Mu precession frequency 34 (MHz) = " << fMuPrecFreq34;
cout << endl << "Mu precession frequency 14 (MHz) = " << fMuPrecFreq14; cout << endl << "Mu precession frequency 23 (MHz) = " << fMuPrecFreq23;
cout << endl << "B field (T) = " << fBfield; cout << endl << "Mu precession frequency 14 (MHz) = " << fMuPrecFreq14;
cout << endl << "Mu+ electron capture rate (MHz) = " << fCaptureRate; cout << endl << "B field (T) = " << fBfield;
cout << endl << "Mu ionizatioan rate (MHz) = " << fIonizationRate; cout << endl << "Mu+ electron capture rate (MHz) = " << fCaptureRate;
cout << endl << "Decay asymmetry = " << fAsymmetry; cout << endl << "Mu0 ionizatioan rate (MHz) = " << fIonizationRate;
cout << endl << "Muonium fraction = " << fMuFraction; cout << endl << "Mu0 spin-flip rate (MHz) = " << fSpinFlipRate;
cout << endl << "Muonium fraction state12 = " << fMuFractionState12; cout << endl << "!!! Note: if spin-flip rate > 0.001 only spin-flip process is considered!!!";
cout << endl << "Muonium fraction state23 = " << fMuFractionState23; cout << endl << "Decay asymmetry = " << fAsymmetry;
cout << endl << "Number of particles to simulate = " << fNmuons; cout << endl << "Muonium fraction = " << fMuFraction;
cout << endl << "Initial muon spin phase (degree) = " << fInitialPhase; cout << endl << "Muonium fraction state12 = " << fMuFractionState12;
cout << endl << "Debug flag = " << fDebugFlag; cout << endl << "Muonium fraction state23 = " << fMuFractionState23;
cout << endl << endl; cout << endl << "Number of particles to simulate = " << fNmuons;
} cout << endl << "Initial muon spin phase (degree) = " << fInitialPhase;
cout << endl << "Debug flag = " << fDebugFlag;
//-------------------------------------------------------------------------- cout << endl << endl;
// SetSeed (public) }
//--------------------------------------------------------------------------
/** //--------------------------------------------------------------------------
* <p>Sets the seed of the random generator. // SetSeed (public)
* //--------------------------------------------------------------------------
* \param seed for the random number generator /**
*/ * <p>Sets the seed of the random generator.
void PSimulateMuTransition::SetSeed(UInt_t seed) *
{ * \param seed for the random number generator
if (!fValid) */
return; void PSimulateMuTransition::SetSeed(UInt_t seed)
{
fRandom->SetSeed(seed); if (!fValid)
} return;
//-------------------------------------------------------------------------- fRandom->SetSeed(seed);
// Run (public) }
//--------------------------------------------------------------------------
/** //--------------------------------------------------------------------------
* \param histoForward // Run (public)
*/ //--------------------------------------------------------------------------
void PSimulateMuTransition::Run(TH1F *histoForward, TH1F *histoBackward) /**
{ * \param histoForward
Int_t i; */
if (histoForward == 0 || histoBackward == 0) void PSimulateMuTransition::Run(TH1F *histoForward, TH1F *histoBackward)
return; {
Int_t i;
for (i = 0; i<fNmuons; i++){ if (histoForward == 0 || histoBackward == 0)
fMuonPhase = TMath::TwoPi() * fInitialPhase/360.; // transform to radians return;
fMuonDecayTime = NextEventTime(fMuonDecayRate);
// initial muon state Mu+ or Mu0? for (i = 0; i<fNmuons; i++){
if (fRandom->Rndm() <= 1.-fMuFraction) fMuonPhase = TMath::TwoPi() * fInitialPhase/360.; // transform to radians
Event("Mu+"); fMuonDecayTime = NextEventTime(fMuonDecayRate);
else
Event(""); if (fSpinFlipRate > 0.001){// consider only Mu0 spin-flip in this case
fMuonPhase = TMath::ACos(GTSpinFlip(fMuonDecayTime));
// fill 50% in "forward", and 50% in "backward" detector to get independent }
// events in "forward" and "backward" histograms. This allows "normal" uSR else{
// analysis of the data // initial muon state Mu+ or Mu0?
// change muon decay time to ns if (fRandom->Rndm() <= 1.-fMuFraction)
if (fRandom->Rndm() <= 0.5) Event("Mu+");
histoForward->Fill(fMuonDecayTime*1000., 1. + fAsymmetry*TMath::Cos(fMuonPhase)); else
else Event("");
histoBackward->Fill(fMuonDecayTime*1000., 1. - fAsymmetry*TMath::Cos(fMuonPhase)); }
// fill 50% in "forward", and 50% in "backward" detector to get independent
if ( (i%100000) == 0) cout << "number of events processed: " << i << endl; // events in "forward" and "backward" histograms. This allows "normal" uSR
} // analysis of the data
cout << "number of events processed: " << i << endl; // change muon decay time to ns
return; if (fRandom->Rndm() <= 0.5)
} histoForward->Fill(fMuonDecayTime*1000., 1. + fAsymmetry*TMath::Cos(fMuonPhase));
else
//-------------------------------------------------------------------------- histoBackward->Fill(fMuonDecayTime*1000., 1. - fAsymmetry*TMath::Cos(fMuonPhase));
// NextEventTime (private)
//-------------------------------------------------------------------------- if ( (i%100000) == 0) cout << "number of events processed: " << i << endl;
/** }
* <p>Determine time of next event, assuming "Poisson" distribution in time cout << "number of events processed: " << i << endl;
* return;
* \param EventRate event rate in MHz; returns next event time in micro-seconds }
*/
Double_t PSimulateMuTransition::NextEventTime(const Double_t &EventRate) //--------------------------------------------------------------------------
{ // NextEventTime (private)
if (EventRate <= 0.) //--------------------------------------------------------------------------
return -1.; // signal error /**
* <p>Determine time of next event, assuming "Poisson" distribution in time
return -1./EventRate * TMath::Log(fRandom->Rndm()); *
} * \param EventRate event rate in MHz; returns next event time in micro-seconds
*/
//-------------------------------------------------------------------------- Double_t PSimulateMuTransition::NextEventTime(const Double_t &EventRate)
// Phase (private) {
//-------------------------------------------------------------------------- if (EventRate <= 0.)
/** return -1.; // signal error
* <p>Determines phase of the muon spin
* return -1./EventRate * TMath::Log(fRandom->Rndm());
* \param time duration of precession (us); }
* \param frequency muon spin precession frequency (MHz);
*/ //--------------------------------------------------------------------------
Double_t PSimulateMuTransition::PrecessionPhase(const Double_t &time, const TString chargeState) // Phase (private)
{ //--------------------------------------------------------------------------
Double_t muonPhaseX; /**
Double_t muoniumPolX = 0; * <p>Determines phase of the muon spin
*
if (chargeState == "Mu+") * \param time duration of precession (us);
muonPhaseX = TMath::TwoPi()*fMuonPrecFreq*time; * \param chargeState charge state of Mu ("Mu+" or "Mu0")
else if (chargeState == "Mu0"){ */
muoniumPolX = 0.5 * Double_t PSimulateMuTransition::PrecessionPhase(const Double_t &time, const TString chargeState)
(fMuFractionState12 * (TMath::Cos(TMath::TwoPi()*fMuPrecFreq12*time) + TMath::Cos(TMath::TwoPi()*fMuPrecFreq34*time)) + {
fMuFractionState23 * (TMath::Cos(TMath::TwoPi()*fMuPrecFreq23*time) + TMath::Cos(TMath::TwoPi()*fMuPrecFreq14*time))); Double_t muonPhaseX;
muonPhaseX = TMath::ACos(muoniumPolX); Double_t muoniumPolX = 0;
}
else if (chargeState == "Mu+")
muonPhaseX = 0.; muonPhaseX = TMath::TwoPi()*fMuonPrecFreq*time;
else if (chargeState == "Mu0"){
return muonPhaseX; muoniumPolX = GTFunction(time);
} muonPhaseX = TMath::ACos(muoniumPolX);
}
//-------------------------------------------------------------------------- else
// Event (private) muonPhaseX = 0.;
//--------------------------------------------------------------------------
/** return muonPhaseX;
* <p> Generates "muon event": simulate muon spin phase under charge-exchange with }
* a neutral muonium state in transverse field, where the polarization evolution
* PxMu(t) of the muon spin in muonium is determined by a superposition of the //--------------------------------------------------------------------------
* four "Mu transitions" nu_12, nu_34, nu_23, and nu_14. // Mu0 transverse field polarization function (private)
* 1) according to Mu+/Mu0 fraction begin either with a Mu+ state or Mu state //--------------------------------------------------------------------------
* 2) Mu+: determine next electron-capture time t_c. If t_c is larger than decay time t_d /**
* calculate muon spin precession for t_d; else calculate spin precession for t_c. * <p>Calculates Mu0 polarization in x direction by superposition of four Mu0 frequencies
* 3) Determine next ionization time t_i; calculate Px(t_i) in Muonium; calculate the *
* muon spin phase by acos(Px(t_i)). * \param time (us);
* 4) get the next electron capture time, continue until t_d is reached. */
* Double_t PSimulateMuTransition::GTFunction(const Double_t &time)
* <p> For isotropic muonium, TF: {
* nu_12 and nu_34 with equal probabilities, probability for both states fMuFractionState12 Double_t muoniumPolX = 0;
* ni_23 and nu_14 with equal probabilities, probability for both states fMuFractionState23
* muoniumPolX = 0.5 *
* \param muonString if eq. "Mu+" begin with Mu+ precession (fMuFractionState12 * (TMath::Cos(TMath::TwoPi()*fMuPrecFreq12*time) + TMath::Cos(TMath::TwoPi()*fMuPrecFreq34*time)) +
*/ fMuFractionState23 * (TMath::Cos(TMath::TwoPi()*fMuPrecFreq23*time) + TMath::Cos(TMath::TwoPi()*fMuPrecFreq14*time)));
void PSimulateMuTransition::Event(const TString muonString)
{ return muoniumPolX;
Double_t eventTime, eventDiffTime, captureTime, ionizationTime; }
// Double_t muonPrecessionFreq, muoniumPrecessionFreq; // MHz
// Double_t rndm, frac1, frac2; //--------------------------------------------------------------------------
// Mu0 transverse field polarization function after n spin-flip collisions (private)
fMuonPrecFreq = fMuonGyroRatio * fBfield; //--------------------------------------------------------------------------
/**
// charge-exchange loop until muon decay * <p>Calculates Mu0 polarization in x direction after n spin flip collisions.
eventTime = 0.; * See M. Senba, J.Phys. B24, 3531 (1991), equation (17)
eventDiffTime = 0.; *
* \param time (us);
if (fDebugFlag) cout << "Decay time = " << fMuonDecayTime << endl; */
//cout << muonString << endl; Double_t PSimulateMuTransition::GTSpinFlip(const Double_t &time)
while (1) { {
if (muonString == "Mu+"){ Double_t muoniumPolX = 1.0; //initial polarization in x direction
// Mu+ initial state; get next electron capture time Double_t eventTime = 0;
captureTime = NextEventTime(fCaptureRate); Double_t eventDiffTime = 0;
eventTime += captureTime; Double_t lastEventTime = 0;
if (fDebugFlag) cout << "Capture time = " << captureTime << " Phase = " << fMuonPhase << endl;
if (eventTime < fMuonDecayTime) eventTime += NextEventTime(fSpinFlipRate);
fMuonPhase += PrecessionPhase(captureTime, "Mu+"); if (eventTime >= time){
else{ //muon decays; handle precession prior to muon decay muoniumPolX = GTFunction(time);
eventDiffTime = fMuonDecayTime - (eventTime - captureTime); }
fMuonPhase += PrecessionPhase(eventDiffTime, "Mu+"); else{
break; while (eventTime < time){
} eventDiffTime = eventTime - lastEventTime;
muoniumPolX = muoniumPolX * GTFunction(eventDiffTime);
// now, we have Mu0; get next ionization time lastEventTime = eventTime;
ionizationTime = NextEventTime(fIonizationRate); eventTime += NextEventTime(fSpinFlipRate);
eventTime += ionizationTime; }
// determine Mu state // calculate for the last collision
// rndm = fRandom->Rndm(); eventDiffTime = time - lastEventTime;
// frac1 = 1. - fMuFractionState1 - fMuFractionState2; // non-precessing Mu states muoniumPolX = muoniumPolX * GTFunction(eventDiffTime);
// frac2 = 1. - fMuFractionState2; }
// if ( rndm < frac1 )
// muoniumPrecessionFreq = 0.; return muoniumPolX;
// else if (rndm >= frac1 && rndm <= frac2){ }
// if (fRandom->Rndm() <= 0.5)
// muoniumPrecessionFreq = fMuPrecFreq12; //--------------------------------------------------------------------------
// else // Event (private)
// muoniumPrecessionFreq = fMuPrecFreq34; //--------------------------------------------------------------------------
// } /**
// else{ * <p> Generates "muon event": simulate muon spin phase under charge-exchange with
// if (fRandom->Rndm() <= 0.5) * a neutral muonium state in transverse field, where the polarization evolution
// muoniumPrecessionFreq = fMuPrecFreq23; * PxMu(t) of the muon spin in muonium is determined by a superposition of the
// else * four "Mu transitions" nu_12, nu_34, nu_23, and nu_14.
// muoniumPrecessionFreq = fMuPrecFreq14; * 1) according to Mu+/Mu0 fraction begin either with a Mu+ state or Mu state
// } * 2) Mu+: determine next electron-capture time t_c. If t_c is larger than decay time t_d
* calculate muon spin precession for t_d; else calculate spin precession for t_c.
if (fDebugFlag) cout << "Ioniza. time = " << ionizationTime << " Phase = " << fMuonPhase << endl; * 3) Determine next ionization time t_i; calculate Px(t_i) in Muonium; calculate the
if (eventTime < fMuonDecayTime) * muon spin phase by acos(Px(t_i)).
fMuonPhase += PrecessionPhase(ionizationTime, "Mu0"); * 4) get the next electron capture time, continue until t_d is reached.
else{ //muon decays; handle precession prior to muon decay *
eventDiffTime = fMuonDecayTime - (eventTime - ionizationTime); * <p> For isotropic muonium, TF:
fMuonPhase += PrecessionPhase(eventDiffTime, "Mu0"); * nu_12 and nu_34 with equal probabilities, probability for both states fMuFractionState12
break; * ni_23 and nu_14 with equal probabilities, probability for both states fMuFractionState23
} *
} * \param muonString if eq. "Mu+" begin with Mu+ precession
else{ */
// Mu0 as initial state; get next ionization time void PSimulateMuTransition::Event(const TString muonString)
ionizationTime = NextEventTime(fIonizationRate); {
eventTime += ionizationTime; Double_t eventTime, eventDiffTime, captureTime, ionizationTime;
// determine Mu state // Double_t muonPrecessionFreq, muoniumPrecessionFreq; // MHz
// rndm = fRandom->Rndm(); // Double_t rndm, frac1, frac2;
// frac1 = 1. - fMuFractionState1 - fMuFractionState2; // non-precessing Mu states
// frac2 = 1. - fMuFractionState2; fMuonPrecFreq = fMuonGyroRatio * fBfield;
// if ( rndm < frac1 )
// muoniumPrecessionFreq = 0.; // charge-exchange loop until muon decay
// else if (rndm >= frac1 && rndm <= frac2){ eventTime = 0.;
// if (fRandom->Rndm() <= 0.5) eventDiffTime = 0.;
// muoniumPrecessionFreq = fMuPrecFreq12;
// else if (fDebugFlag) cout << "Decay time = " << fMuonDecayTime << endl;
// muoniumPrecessionFreq = fMuPrecFreq34; //cout << muonString << endl;
// } while (1) {
// else{ if (muonString == "Mu+"){
// if (fRandom->Rndm() <= 0.5) // Mu+ initial state; get next electron capture time
// muoniumPrecessionFreq = fMuPrecFreq23; captureTime = NextEventTime(fCaptureRate);
// else eventTime += captureTime;
// muoniumPrecessionFreq = fMuPrecFreq14; if (fDebugFlag) cout << "Capture time = " << captureTime << " Phase = " << fMuonPhase << endl;
// } if (eventTime < fMuonDecayTime)
fMuonPhase += PrecessionPhase(captureTime, "Mu+");
if (fDebugFlag) else{ //muon decays; handle precession prior to muon decay
cout << "Mu Ioniza. time = " << ionizationTime << " Phase = " << fMuonPhase << endl; eventDiffTime = fMuonDecayTime - (eventTime - captureTime);
if (eventTime < fMuonDecayTime) fMuonPhase += PrecessionPhase(eventDiffTime, "Mu+");
fMuonPhase += PrecessionPhase(ionizationTime, "Mu0"); break;
else{ //muon decays; handle precession prior to muon decay }
eventDiffTime = fMuonDecayTime - (eventTime - ionizationTime);
fMuonPhase += PrecessionPhase(eventDiffTime, "Mu0"); // now, we have Mu0; get next ionization time
break; ionizationTime = NextEventTime(fIonizationRate);
} eventTime += ionizationTime;
// determine Mu state
// Mu+ state; get next electron capture time // rndm = fRandom->Rndm();
captureTime = NextEventTime(fCaptureRate); // frac1 = 1. - fMuFractionState1 - fMuFractionState2; // non-precessing Mu states
eventTime += captureTime; // frac2 = 1. - fMuFractionState2;
if (fDebugFlag) cout << "Capture time = " << captureTime << " Phase = " << fMuonPhase << endl; // if ( rndm < frac1 )
if (eventTime < fMuonDecayTime) // muoniumPrecessionFreq = 0.;
fMuonPhase += PrecessionPhase(captureTime, "Mu+"); // else if (rndm >= frac1 && rndm <= frac2){
else{ //muon decays; handle precession prior to muon decay // if (fRandom->Rndm() <= 0.5)
eventDiffTime = fMuonDecayTime - (eventTime - captureTime); // muoniumPrecessionFreq = fMuPrecFreq12;
fMuonPhase += PrecessionPhase(eventDiffTime, "Mu+"); // else
break; // muoniumPrecessionFreq = fMuPrecFreq34;
} // }
} // else{
} // if (fRandom->Rndm() <= 0.5)
// muoniumPrecessionFreq = fMuPrecFreq23;
if (fDebugFlag) cout << " Final Phase = " << fMuonPhase << endl; // else
//fMuonPhase = TMath::ACos(TMath::Cos(fMuonPhase))*360./TMath::TwoPi(); //transform back to [0, 180] degree interval // muoniumPrecessionFreq = fMuPrecFreq14;
return; // }
}
if (fDebugFlag) cout << "Ioniza. time = " << ionizationTime << " Phase = " << fMuonPhase << endl;
if (eventTime < fMuonDecayTime)
fMuonPhase += PrecessionPhase(ionizationTime, "Mu0");
else{ //muon decays; handle precession prior to muon decay
eventDiffTime = fMuonDecayTime - (eventTime - ionizationTime);
fMuonPhase += PrecessionPhase(eventDiffTime, "Mu0");
break;
}
}
else{
// Mu0 as initial state; get next ionization time
ionizationTime = NextEventTime(fIonizationRate);
eventTime += ionizationTime;
// determine Mu state
// rndm = fRandom->Rndm();
// frac1 = 1. - fMuFractionState1 - fMuFractionState2; // non-precessing Mu states
// frac2 = 1. - fMuFractionState2;
// if ( rndm < frac1 )
// muoniumPrecessionFreq = 0.;
// else if (rndm >= frac1 && rndm <= frac2){
// if (fRandom->Rndm() <= 0.5)
// muoniumPrecessionFreq = fMuPrecFreq12;
// else
// muoniumPrecessionFreq = fMuPrecFreq34;
// }
// else{
// if (fRandom->Rndm() <= 0.5)
// muoniumPrecessionFreq = fMuPrecFreq23;
// else
// muoniumPrecessionFreq = fMuPrecFreq14;
// }
if (fDebugFlag)
cout << "Mu Ioniza. time = " << ionizationTime << " Phase = " << fMuonPhase << endl;
if (eventTime < fMuonDecayTime)
fMuonPhase += PrecessionPhase(ionizationTime, "Mu0");
else{ //muon decays; handle precession prior to muon decay
eventDiffTime = fMuonDecayTime - (eventTime - ionizationTime);
fMuonPhase += PrecessionPhase(eventDiffTime, "Mu0");
break;
}
// Mu+ state; get next electron capture time
captureTime = NextEventTime(fCaptureRate);
eventTime += captureTime;
if (fDebugFlag) cout << "Capture time = " << captureTime << " Phase = " << fMuonPhase << endl;
if (eventTime < fMuonDecayTime)
fMuonPhase += PrecessionPhase(captureTime, "Mu+");
else{ //muon decays; handle precession prior to muon decay
eventDiffTime = fMuonDecayTime - (eventTime - captureTime);
fMuonPhase += PrecessionPhase(eventDiffTime, "Mu+");
break;
}
}
}
if (fDebugFlag) cout << " Final Phase = " << fMuonPhase << endl;
//fMuonPhase = TMath::ACos(TMath::Cos(fMuonPhase))*360./TMath::TwoPi(); //transform back to [0, 180] degree interval
return;
}

View File

@ -1,101 +1,105 @@
/*************************************************************************** /***************************************************************************
PSimulateMuTransition.h PSimulateMuTransition.h
Author: Thomas Prokscha Author: Thomas Prokscha
Date: 25-Feb-2010 Date: 25-Feb-2010
$Id$ $Id$
***************************************************************************/ ***************************************************************************/
/*************************************************************************** /***************************************************************************
* Copyright (C) 2010 by Thomas Prokscha, Paul Scherrer Institut * * Copyright (C) 2010 by Thomas Prokscha, Paul Scherrer Institut *
* * * *
* This program is free software; you can redistribute it and/or modify * * This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by * * it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or * * the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. * * (at your option) any later version. *
* * * *
* This program is distributed in the hope that it will be useful, * * This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of * * but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. * * GNU General Public License for more details. *
* * * *
* You should have received a copy of the GNU General Public License * * You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the * * along with this program; if not, write to the *
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#ifndef _PSIMULATEMUTRANSITION_H_ #ifndef _PSIMULATEMUTRANSITION_H_
#define _PSIMULATEMUTRANSITION_H_ #define _PSIMULATEMUTRANSITION_H_
#include <TObject.h> #include <TObject.h>
#include <TH1F.h> #include <TH1F.h>
#include <TRandom2.h> #include <TRandom2.h>
// global constants // global constants
const Double_t fMuonGyroRatio = 135.54; //!< muon gyromagnetic ratio (MHz/T) const Double_t fMuonGyroRatio = 135.54; //!< muon gyromagnetic ratio (MHz/T)
const Double_t fMuonDecayRate = 0.4551; //!< muon decay rate (1/tau_mu, MHz) const Double_t fMuonDecayRate = 0.4551; //!< muon decay rate (1/tau_mu, MHz)
class PSimulateMuTransition : public TObject class PSimulateMuTransition : public TObject
{ {
public: public:
PSimulateMuTransition(UInt_t seed = 0); PSimulateMuTransition(UInt_t seed = 0);
virtual ~PSimulateMuTransition(); virtual ~PSimulateMuTransition();
virtual void PrintSettings() const; virtual void PrintSettings() const;
virtual void SetNmuons(Int_t value) { fNmuons = value; } //!< number of muons virtual void SetNmuons(Int_t value) { fNmuons = value; } //!< number of muons
virtual void SetDebugFlag(Bool_t value) { fDebugFlag = value; } //!< debug flag virtual void SetDebugFlag(Bool_t value) { fDebugFlag = value; } //!< debug flag
virtual void SetBfield(Double_t value) { fBfield = value; } //!< sets magnetic field (T) virtual void SetBfield(Double_t value) { fBfield = value; } //!< sets magnetic field (T)
virtual void SetMuPrecFreq12(Double_t value) { fMuPrecFreq12 = value; } //!< sets Mu transition frequency (MHz) virtual void SetMuPrecFreq12(Double_t value) { fMuPrecFreq12 = value; } //!< sets Mu transition frequency (MHz)
virtual void SetMuPrecFreq34(Double_t value) { fMuPrecFreq34 = value; } //!< sets Mu transition frequency (MHz) virtual void SetMuPrecFreq34(Double_t value) { fMuPrecFreq34 = value; } //!< sets Mu transition frequency (MHz)
virtual void SetMuPrecFreq23(Double_t value) { fMuPrecFreq23 = value; } //!< sets Mu transition frequency (MHz) virtual void SetMuPrecFreq23(Double_t value) { fMuPrecFreq23 = value; } //!< sets Mu transition frequency (MHz)
virtual void SetMuPrecFreq14(Double_t value) { fMuPrecFreq14 = value; } //!< sets Mu transition frequency (MHz) virtual void SetMuPrecFreq14(Double_t value) { fMuPrecFreq14 = value; } //!< sets Mu transition frequency (MHz)
virtual void SetCaptureRate(Double_t value){ fCaptureRate = value; } //!< sets Mu+ electron capture rate (MHz) virtual void SetCaptureRate(Double_t value){ fCaptureRate = value; } //!< sets Mu+ electron capture rate (MHz)
virtual void SetIonizationRate(Double_t value){ fIonizationRate = value; } //!< sets Mu0 ionization rate (MHz) virtual void SetIonizationRate(Double_t value){ fIonizationRate = value; } //!< sets Mu0 ionization rate (MHz)
virtual void SetDecayAsymmetry(Double_t value){ fAsymmetry = value; } //!< muon decay asymmetry virtual void SetSpinFlipRate(Double_t value){ fSpinFlipRate = value; } //!< sets Mu0 spin flip rate (MHz)
virtual void SetMuFraction(Double_t value){ fMuFraction = value; } //!< Muonium fraction virtual void SetDecayAsymmetry(Double_t value){ fAsymmetry = value; } //!< muon decay asymmetry
virtual void SetMuFractionState12(Double_t value){ fMuFractionState12 = value; } virtual void SetMuFraction(Double_t value){ fMuFraction = value; } //!< Muonium fraction
virtual void SetMuFractionState23(Double_t value){ fMuFractionState23 = value; } virtual void SetMuFractionState12(Double_t value){ fMuFractionState12 = value; }
virtual void SetMuFractionState23(Double_t value){ fMuFractionState23 = value; }
virtual Bool_t IsValid() { return fValid; }
virtual void SetSeed(UInt_t seed); virtual Bool_t IsValid() { return fValid; }
virtual void SetSeed(UInt_t seed);
virtual Double_t GetBfield() { return fBfield; } //!< returns the magnetic field (T)
virtual Double_t GetCaptureRate() { return fCaptureRate; } //!< returns Mu+ electron capture rate (MHz) virtual Double_t GetBfield() { return fBfield; } //!< returns the magnetic field (T)
virtual Double_t GetIonizationRate() { return fIonizationRate; } //!< returns Mu0 ionization rate (MHz) virtual Double_t GetCaptureRate() { return fCaptureRate; } //!< returns Mu+ electron capture rate (MHz)
virtual void Run(TH1F *histoForward, TH1F *histoBackward); virtual Double_t GetIonizationRate() { return fIonizationRate; } //!< returns Mu0 ionization rate (MHz)
virtual void Run(TH1F *histoForward, TH1F *histoBackward);
private:
Bool_t fValid; private:
TRandom2 *fRandom; Bool_t fValid;
TRandom2 *fRandom;
Double_t fBfield; //!< magnetic field (T)
Double_t fMuPrecFreq12; //!< Mu transition frequency 12 (MHz) Double_t fBfield; //!< magnetic field (T)
Double_t fMuPrecFreq34; //!< Mu transition frequency 34 (MHz) Double_t fMuPrecFreq12; //!< Mu transition frequency 12 (MHz)
Double_t fMuPrecFreq23; //!< Mu transition frequency 23 (MHz) Double_t fMuPrecFreq34; //!< Mu transition frequency 34 (MHz)
Double_t fMuPrecFreq14; //!< Mu transition frequency 14 (MHz) Double_t fMuPrecFreq23; //!< Mu transition frequency 23 (MHz)
Double_t fMuonPrecFreq; //!< muon precession frequency (MHz) Double_t fMuPrecFreq14; //!< Mu transition frequency 14 (MHz)
Double_t fCaptureRate; //!< Mu+ electron capture rate (MHz) Double_t fMuonPrecFreq; //!< muon precession frequency (MHz)
Double_t fIonizationRate; //!< Mu0 ionization rate (MHz) Double_t fCaptureRate; //!< Mu+ electron capture rate (MHz)
Double_t fInitialPhase; //!< initial muon spin phase Double_t fIonizationRate; //!< Mu0 ionization rate (MHz)
Double_t fMuonDecayTime; //!< muon decay time (us) Double_t fSpinFlipRate; //!< Mu0 spin-flip rate (MHz)
Double_t fMuonPhase; //!< phase of muon spin Double_t fInitialPhase; //!< initial muon spin phase
Double_t fAsymmetry; //!< muon decay asymmetry Double_t fMuonDecayTime; //!< muon decay time (us)
Double_t fMuFraction; //!< total Mu fraction [0,1] Double_t fMuonPhase; //!< phase of muon spin
Double_t fMuFractionState12; //!< fraction of Mu in state 12, 34 Double_t fAsymmetry; //!< muon decay asymmetry
Double_t fMuFractionState23; //!< fraction of Mu in state 23, 14 Double_t fMuFraction; //!< total Mu fraction [0,1]
Int_t fNmuons; //!< number of muons to simulate Double_t fMuFractionState12; //!< fraction of Mu in state 12, 34
Bool_t fDebugFlag; //!< debug flag Double_t fMuFractionState23; //!< fraction of Mu in state 23, 14
Int_t fNmuons; //!< number of muons to simulate
virtual Double_t NextEventTime(const Double_t &EventRate); Bool_t fDebugFlag; //!< debug flag
// virtual Double_t PrecessionPhase(const Double_t &time, const Double_t &frequency);
virtual Double_t PrecessionPhase(const Double_t &time, const TString chargeState); virtual Double_t NextEventTime(const Double_t &EventRate);
virtual void Event(const TString muonString); // virtual Double_t PrecessionPhase(const Double_t &time, const Double_t &frequency);
virtual Double_t PrecessionPhase(const Double_t &time, const TString chargeState);
ClassDef(PSimulateMuTransition, 0) virtual Double_t GTFunction(const Double_t &time); //!< transverse field polarization function of Mu0
}; virtual Double_t GTSpinFlip(const Double_t &time); //!< transverse field polarization function after spin-flip collisions
virtual void Event(const TString muonString);
#endif // _PSIMULATEMUTRANSITION_H_
ClassDef(PSimulateMuTransition, 0)
};
#endif // _PSIMULATEMUTRANSITION_H_

View File

@ -1,3 +1,155 @@
<<<<<<< HEAD
/***************************************************************************
runMuSimulation.C
Author: Thomas Prokscha
Date: 25-Feb-2010
$Id$
***************************************************************************/
/***************************************************************************
* Copyright (C) 2010 by Thomas Prokscha, Paul Scherrer Institut *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
void runMuSimulation()
{
// load library
gSystem->Load("$ROOTSYS/lib/libPSimulateMuTransition");
// generate data
TFolder *histosFolder;
TFolder *decayAnaModule;
TFolder *runInfo;
histosFolder = gROOT->GetRootFolder()->AddFolder("histos", "Histograms");
gROOT->GetListOfBrowsables()->Add(histosFolder, "histos");
decayAnaModule = histosFolder->AddFolder("DecayAnaModule", "muSR decay histograms");
//prepare to run simulation; here: isotropic Mu in Germanium
UInt_t runNo = 9903;
Double_t T = 300.; //temperature
Double_t capRate = 1.0;//*sqrt(T/200.);
Double_t spinFlipRate = 0.001;
//assume that capture rate varies as sqrt(T), capRate = sigma*v*p , v ~ sqrt(T)
Double_t ionRate; //assume Arrhenius behaviour ionRate = preFac*exp(-EA/kT)
Double_t EA = 100.; //activation energy (meV)
ionRate = 2.9e7 * exp(-EA/(0.08625*T)); // Ge: 2.9*10^7MHz "attempt" frequency; 1K = 0.08625 meV
Double_t B = 100.; //field in G
Double_t Freq12 = 4463; //Mu freq of the 12 transition
Double_t Freq34 = 4463; //Mu freq of the 34 transition
Double_t Freq23 = 4463; //Mu freq of the 23 transition
Double_t Freq14 = 4463; //Mu freq of the 14 transition
Double_t MuFrac = 1.0; //total Mu fraction
Double_t MuFrac12 = 0.5; //Mu in states 12 and 34
Double_t MuFrac23 = 0.5; //Mu in states 23 and 14
Int_t Nmuons = 1e7; //number of muons
Double_t Asym = 0.27; //muon decay asymmetry
// feed run info header
TString tstr;
runInfo = gROOT->GetRootFolder()->AddFolder("RunInfo", "LEM RunInfo");
gROOT->GetListOfBrowsables()->Add(runInfo, "RunInfo");
header = new TLemRunHeader();
tstr = TString("0");
tstr += runNo;
tstr += TString(" - Mu-frac 1.0, Mu12 -4463MHz (0.5), Mu34 -4463MHz(0.5), T=300K/EA=100meV, Cap. 1.0MHz, 10mT");
header->SetRunTitle(tstr.Data());
header->SetLemSetup("trivial");
header->SetRunNumber(runNo);
header->SetStartTime(0);
header->SetStopTime(1);
header->SetModeratorHV(32.0, 0.01);
header->SetSampleHV(0.0, 0.01);
header->SetImpEnergy(31.8);
header->SetSampleTemperature(T, 0.001);
header->SetSampleBField(B, 0.1);
header->SetTimeResolution(1.);
header->SetNChannels(12001);
header->SetNHist(2);
header->SetOffsetPPCHistograms(20);
header->SetCuts("none");
header->SetModerator("none");
Double_t tt0[2] = {0., 0.};
header->SetTimeZero(tt0);
runInfo->Add(header); //add header to RunInfo folder
TH1F *histo[4];
char str[128];
for (UInt_t i=0; i<2; i++) {
sprintf(str, "hDecay0%d", (Int_t)i);
histo[i] = new TH1F(str, str, 12001, -0.5, 12000.5);
sprintf(str, "hDecay2%d", (Int_t)i);
histo[i+2] = new TH1F(str, str, 12001, -0.5, 12000.5);
}
PSimulateMuTransition *simulateMuTransition = new PSimulateMuTransition();
if (!simulateMuTransition->IsValid()) {
cerr << endl << "**ERROR** while invoking PSimulateTransition" << endl;
return;
}
simulateMuTransition->SetMuPrecFreq12(Freq12); // MHz
simulateMuTransition->SetMuPrecFreq34(Freq34); // MHz
simulateMuTransition->SetMuPrecFreq23(Freq23); // MHz
simulateMuTransition->SetMuPrecFreq14(Freq14); // MHz
simulateMuTransition->SetMuFraction(MuFrac); // initial Mu fraction
simulateMuTransition->SetMuFractionState12(MuFrac12); // Mu in states 12, 34
simulateMuTransition->SetMuFractionState23(MuFrac23); // Mu in states 23, 14
simulateMuTransition->SetBfield(B/10000.); // Tesla
simulateMuTransition->SetCaptureRate(capRate); // MHz
simulateMuTransition->SetIonizationRate(ionRate); // MHz
simulateMuTransition->SetSpinFlipRate(spinFlipRate); // MHz
simulateMuTransition->SetNmuons(Nmuons);
simulateMuTransition->SetDecayAsymmetry(Asym);
simulateMuTransition->SetDebugFlag(kFALSE); // to print time and phase during charge-changing cycle
simulateMuTransition->PrintSettings();
simulateMuTransition->Run(histo[0], histo[1]);
for (UInt_t i=0; i<4; i++)
decayAnaModule->Add(histo[i]);
// write file
tstr = TString("0");
tstr += runNo;
tstr += TString(".root");
TFile *fout = new TFile(tstr.Data(), "RECREATE", "Midas Fake Histograms");
if (fout == 0) {
cout << endl << "**ERROR** Couldn't create ROOT file";
cout << endl << endl;
exit(0);
}
fout->cd();
runInfo->Write();
histosFolder->Write();
fout->Close();
cout << "Histograms written to " << tstr.Data() << endl;
delete fout;
delete [] histo;
}
=======
/*************************************************************************** /***************************************************************************
runMuSimulation.C runMuSimulation.C
@ -146,3 +298,4 @@ void runMuSimulation()
delete [] histo; delete [] histo;
} }
>>>>>>> 4fec25e423493c58fa21cedec161430f90ffc10d