Skip to content

Commit 845c9be

Browse files
author
Nathan A. Sparks
authored
Merge pull request #6 from JeffersonLab/new_bgtagonly_feature_rtj
New bgtagonly feature rtj
2 parents b1c9c16 + 5b2b2da commit 845c9be

File tree

3 files changed

+99
-47
lines changed

3 files changed

+99
-47
lines changed

src/GlueXPhotonBeamGenerator.cc

Lines changed: 53 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
// related to the GENBEAM control.in flag.
2828

2929
int GlueXPhotonBeamGenerator::fGenerateNotSimulate = 0;
30+
int GlueXPhotonBeamGenerator::fBeamBackgroundTagOnly = 0;
3031

3132
double GlueXPhotonBeamGenerator::fBeamBucketPeriod = 4. * ns;
3233
double GlueXPhotonBeamGenerator::fBeamStartZ = -24 * m;
@@ -71,15 +72,29 @@ GlueXPhotonBeamGenerator::GlueXPhotonBeamGenerator(CobremsGeneration *gen)
7172
}
7273
GlueXUserEventInformation::fWriteNoHitEvents = 1;
7374
}
74-
75-
prepareImportanceSamplingPDFs();
75+
std::map<int, int> bgratepars;
76+
std::map<int, int> bggatepars;
77+
std::map<int, int> bgtagonlypars;
78+
if (user_opts->Find("BEAM", beampars) &&
79+
user_opts->Find("BGRATE", bgratepars) &&
80+
user_opts->Find("BGGATE", bggatepars))
81+
{
82+
if (user_opts->Find("BGTAGONLY", bgtagonlypars)) {
83+
fBeamBackgroundTagOnly = bgtagonlypars[1];
84+
}
85+
else {
86+
fBeamBackgroundTagOnly = 0;
87+
}
88+
}
7689

7790
// These cutoffs should be set empirically, as low as possible
7891
// for good efficiency, but not too low so as to avoid excessive
7992
// warnings about Pcut violations.
8093

8194
fCoherentPDFx.Pcut = .003;
8295
fIncoherentPDFlogx.Pcut = .003;
96+
97+
prepareImportanceSamplingPDFs();
8398
}
8499

85100
GlueXPhotonBeamGenerator::~GlueXPhotonBeamGenerator()
@@ -103,6 +118,11 @@ void GlueXPhotonBeamGenerator::prepareImportanceSamplingPDFs()
103118
xarr[i] = xmin + (i + 0.5) * dx;
104119
yarr[i] = fCobrems->Rate_dNcdxdp(xarr[i], M_PI/4);
105120
yarr[i] = (yarr[i] > 0)? yarr[i] : 0;
121+
for (int j=1; j < 10; ++j) {
122+
double mfactor = 1 - j / 10.;
123+
if (i > j && yarr[i] < yarr[i-j] * mfactor)
124+
yarr[i] = yarr[i-j] * mfactor;
125+
}
106126
}
107127
fCobrems->applyBeamCrystalConvolution(Ndim, xarr, yarr);
108128
sum = 0;
@@ -116,6 +136,7 @@ void GlueXPhotonBeamGenerator::prepareImportanceSamplingPDFs()
116136
fCoherentPDFx.density[i] /= sum * dx;
117137
fCoherentPDFx.integral[i] /= sum;
118138
}
139+
fCoherentPDFx.Pcut = 4*M_PI * sum * dx;
119140

120141
// Compute approximate PDF for dNi/dlogx
121142
double logxmin = log(xmin);
@@ -387,7 +408,27 @@ void GlueXPhotonBeamGenerator::GenerateBeamPhoton(G4Event* anEvent, double t0)
387408
}
388409
}
389410

390-
// Put the radiator back the way your found it
411+
#if VERBOSE_COBREMS_SPLITTING
412+
if (fIncoherentPDFlogx.Npassed / 100 * 100 == fIncoherentPDFlogx.Npassed) {
413+
G4cout << "coherent rate is "
414+
<< fCoherentPDFx.Psum / (fCoherentPDFx.Ntested + 1e-99)
415+
<< ", efficiency is "
416+
<< fCoherentPDFx.Npassed / (fCoherentPDFx.Ntested + 1e-99)
417+
<< G4endl
418+
<< "incoherent rate is "
419+
<< fIncoherentPDFlogx.Psum / (fIncoherentPDFlogx.Ntested + 1e-99)
420+
<< ", efficiency is "
421+
<< fIncoherentPDFlogx.Npassed / (fIncoherentPDFlogx.Ntested + 1e-99)
422+
<< G4endl
423+
<< "counts are "
424+
<< fCoherentPDFx.Npassed << " / " << fIncoherentPDFlogx.Npassed
425+
<< " = "
426+
<< fCoherentPDFx.Npassed / (fIncoherentPDFlogx.Npassed + 1e-99)
427+
<< G4endl;
428+
}
429+
#endif
430+
431+
// Put the radiator back the way you found it
391432
fCobrems->setTargetOrientation(targetThetax,
392433
targetThetay,
393434
targetThetaz);
@@ -426,20 +467,25 @@ void GlueXPhotonBeamGenerator::GenerateBeamPhoton(G4Event* anEvent, double t0)
426467
int bg = 1;
427468
double tvtx;
428469
if (t0 == 0) {
429-
event_info = new GlueXUserEventInformation();
430-
anEvent->SetUserInformation(event_info);
431470
tvtx = (vtx[2] - targetCenterZ) / fBeamVelocity;
432471
tvtx -= GenerateTriggerTime(anEvent);
472+
event_info = new GlueXUserEventInformation();
473+
anEvent->SetUserInformation(event_info);
433474
if (fGenerateNotSimulate == 0) {
434475
event_info->AddBeamParticle(1, tvtx, vtx, mom, pol);
435476
}
436477
bg = 0;
437478
}
438479
else {
439-
event_info = (GlueXUserEventInformation*)anEvent->GetUserInformation();
440-
assert (event_info != 0);
441480
tvtx = fBeamBucketPeriod * floor(t0 / fBeamBucketPeriod + 0.5);
442481
tvtx += (vtx[2] - targetCenterZ) / fBeamVelocity;
482+
if (fBeamBackgroundTagOnly) {
483+
double ttag = tvtx + (targetCenterZ - vtx[2]) / fBeamVelocity;
484+
fTagger->addTaggerPhoton(anEvent, pabs, ttag, bg);
485+
return;
486+
}
487+
event_info = (GlueXUserEventInformation*)anEvent->GetUserInformation();
488+
assert (event_info != 0);
443489
}
444490

445491
// Generate new primary for the beam photon
@@ -478,26 +524,6 @@ void GlueXPhotonBeamGenerator::GenerateBeamPhoton(G4Event* anEvent, double t0)
478524
double ttag = tvtx + (targetCenterZ - vtx[2]) / fBeamVelocity;
479525
fTagger->addTaggerPhoton(anEvent, pabs, ttag, bg);
480526
}
481-
482-
#if VERBOSE_COBREMS_SPLITTING
483-
if (fIncoherentPDFlogx.Npassed / 100 * 100 == fIncoherentPDFlogx.Npassed) {
484-
G4cout << "coherent rate is "
485-
<< fCoherentPDFx.Psum / (fCoherentPDFx.Ntested + 1e-99)
486-
<< ", efficiency is "
487-
<< fCoherentPDFx.Npassed / (fCoherentPDFx.Ntested + 1e-99)
488-
<< G4endl
489-
<< "incoherent rate is "
490-
<< fIncoherentPDFlogx.Psum / (fIncoherentPDFlogx.Ntested + 1e-99)
491-
<< ", efficiency is "
492-
<< fIncoherentPDFlogx.Npassed / (fIncoherentPDFlogx.Ntested + 1e-99)
493-
<< G4endl
494-
<< "counts are "
495-
<< fCoherentPDFx.Npassed << " / " << fIncoherentPDFlogx.Npassed
496-
<< " = "
497-
<< fCoherentPDFx.Npassed / (fIncoherentPDFlogx.Npassed + 1e-99)
498-
<< G4endl;
499-
}
500-
#endif
501527
}
502528

503529
double GlueXPhotonBeamGenerator::GenerateTriggerTime(const G4Event *event)

src/GlueXPhotonBeamGenerator.hh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class GlueXPhotonBeamGenerator: public G4VPrimaryGenerator
3636
CobremsGeneration *fCobrems;
3737
static GlueXPseudoDetectorTAG *fTagger;
3838
static int fGenerateNotSimulate;
39+
static int fBeamBackgroundTagOnly;
3940

4041
static double fBeamBucketPeriod;
4142
static double fBeamStartZ;

test/control.in

Lines changed: 45 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -146,26 +146,51 @@ HALO 5e-5
146146

147147
c The following lines control the rate (GHz) of background beam photons
148148
c that are overlayed on each event in the simulation, in addition to the
149-
c particles produced by the standard generation mechanism. A value of
150-
c 1.10 corresponds to nominal GlueX running conditions at an intensity of
151-
c 10^7 tagged photons on target per second. To disable the generation of
152-
c random beam background, comment this line out or set the value of BGRATE
153-
c to zero. Background beam photons are generated during the time interval
154-
c given by the BGGATE card, whose two arguments specify the earliest and
155-
c latest times (ns relative to the time of the original photon that caused
156-
c the event) that a random beam photon could produce background hits
157-
c somewhere in the detector. Note that for this to work, the BEAM card
158-
c must be present (see above). This means that background generation is
159-
c disabled when the simulation operates in particle gun mode.
160-
c If Emin is set in the BEAM card (see above), the rate of background photons
161-
c is automatically rescaled as follows:
162-
c Rate(E_gamma > Thr) = Rate(E_gamma > 0.12 GeV) * K,
163-
c where K is a scale factor calculated inside uginit.F:
164-
c K = 1 for Thr = 0.12 GeV,
165-
c K > 1 for Thr < 0.12 GeV.
166-
c Note, K is calculated assuming the beam energies Emax = 12, Epeak = 9.
167-
cBGRATE 1.10
168-
cBGGATE -200. 200.
149+
c particles produced by the standard generation mechanism. BGGATE expects
150+
c two values in ns, which define the window around the trigger time that
151+
c background beam photons are overlaid on the simulation. The value you
152+
c should enter for BGRATE depends on many details of the photon beam: the
153+
c endpoint energy, the low-energy cutoff to be used in generating beam
154+
c photons, the location of coherent edge, the electron beam spot size and
155+
c emittance at the primary collimator, the electron beam current, etc. To
156+
c find the setting that is right for you, follow these steps in order.
157+
c 1) Check the BEAM card above that it has correct values for the electron
158+
c beam energy (field 1) and the low-energy cutoff that you want to use
159+
c in your simulation (field 3). Remember these values.
160+
c 2) Open a new tab in a web browser and enter the following URL,
161+
c http://zeus.phys.uconn.edu/halld/cobrems/ratetool.cgi which displays
162+
c a form containing many fields describing the electron beam and the
163+
c photon beamline. Enter the correct values in all fields in the
164+
c left-most column of parameters. The right column of parameters
165+
c defines the windows over which the tool will compute integrals of
166+
c the beam rate. Set the "end-point" window to span the full range
167+
c from your beamEmin (see step 1 above) to the electron beam endpoint,
168+
c Then click the Plot Spectrum button. After a few seconds, the form will
169+
c respond with a few plots and rate numbers in bold text. Record the
170+
c value given for the "end-point rate". This is your BGRATE value.
171+
c 3) Enter your BGRATE value found in step 2 after BGRATE in the line
172+
c below, and remove any characters before the BGRATE keyword. You are
173+
c now ready to go. If you ever change anything in the beamline geometry
174+
c eg. the collimator diameter, the coherent edge position, or the value
175+
c of beamEmin, do not forget to come back and change your BGRATE.
176+
BGGATE -200. 200.
177+
BGRATE 4.80
178+
179+
c The above cards BGRATE, BGGATE normally cause the simulation to add
180+
c accidental tagger hits to the simulated output record, in addition to
181+
c adding these beam photons to the list of particles to be tracked through
182+
c the detector. If you want the accidental tagger hits to be added to the
183+
c simulated output record but you do not want to track the background
184+
c beam photons, remove the comment in front of BGTAGONLY below.
185+
c NOTICE: If you turn on BGTAGONLY then you might as well raise the
186+
c minimum energy of beam photons being generated to the lower bound of
187+
c the tagger energy range you are interested in, which might be 3 GeV for
188+
c low-intensity running, 7 GeV for high-intensity running, or even 8 GeV
189+
c if you are only interested in the region of the coherent peak. This
190+
c minimum is the third field of the BEAM card above. Remember that if
191+
c you change beamEmin, you also need to change BGRATE to match, as
192+
c described above.
193+
BGTAGONLY 1
169194

170195
c The following line controls the uncertainty of the event time reference
171196
c relative to the RF structure of the beam. The event time reference is

0 commit comments

Comments
 (0)