6 #include "secondaries.hh" 15 #include "Constants.h" 17 #include "TTreeIndex.h" 26 #include "TPostScript.h" 31 #include "TGraphErrors.h" 36 #include "TRotation.h" 38 #include "icemc_random.h" 40 #include "EnvironmentVariable.h" 43 const string ICEMC_SECONDARY_DIR=ICEMC_SRC_DIR+
"/secondary/";
48 using std::stringstream;
49 using std::setprecision;
50 using std::accumulate;
51 using std::max_element;
52 using std::partial_sum;
55 Secondaries::Secondaries() {
61 B0=1.2*std::pow(10.,-7.);
62 B1=0.16*std::pow(10.,-7.);
81 tauolainfile.open((ICEMC_SRC_DIR+
"/data/tau_decay_tauola.dat").c_str(),ifstream::in);
90 secondary_e_noncons=0;
92 for (
int i=0;i<7;i++) {
93 Tools::Zero(dsdy_muon_brems[i],NPROB_MAX);
94 Tools::Zero(dsdy_muon_epair[i],NPROB_MAX);
95 Tools::Zero(dsdy_muon_pn[i],NPROB_MAX);
97 Tools::Zero(y_muon_brems[i],NPROB_MAX);
98 Tools::Zero(y_muon_epair[i],NPROB_MAX);
99 Tools::Zero(y_muon_pn[i],NPROB_MAX);
101 Tools::Zero(dsdy_tauon_brems[i],NPROB_MAX);
102 Tools::Zero(dsdy_tauon_epair[i],NPROB_MAX);
103 Tools::Zero(dsdy_tauon_pn[i],NPROB_MAX);
104 Tools::Zero(dsdy_tauon_hadrdecay[i],NPROB_MAX);
105 Tools::Zero(dsdy_tauon_edecay[i],NPROB_MAX);
106 Tools::Zero(dsdy_tauon_mudecay[i],NPROB_MAX);
110 Tools::Zero(y_tauon_brems[i],NPROB_MAX);
111 Tools::Zero(y_tauon_epair[i],NPROB_MAX);
112 Tools::Zero(y_tauon_pn[i],NPROB_MAX);
113 Tools::Zero(y_tauon_hadrdecay[i],NPROB_MAX);
114 Tools::Zero(y_tauon_edecay[i],NPROB_MAX);
115 Tools::Zero(y_tauon_mudecay[i],NPROB_MAX);
118 Tools::Zero(int_muon_brems,7);
119 Tools::Zero(int_muon_epair,7);
120 Tools::Zero(int_muon_pn,7);
122 Tools::Zero(int_tauon_brems,7);
123 Tools::Zero(int_tauon_epair,7);
124 Tools::Zero(int_tauon_pn,7);
125 Tools::Zero(int_tauon_hadrdecay,7);
126 Tools::Zero(int_tauon_edecay,7);
127 Tools::Zero(int_tauon_mudecay,7);
137 void Secondaries::readData(
string nuflavor,
string secndryType,
double (*y)[NPROB_MAX],
double (*dsdy)[NPROB_MAX])
140 stringstream senergy;
143 string suffix=
".vec";
144 if(nuflavor==
"tauon")
147 for(
int index=0;index<7;index++)
149 double energy=18+0.5*index;
150 int precision=(index%2==0)?2:3;
151 senergy << setprecision(precision) << energy;
152 string path=ICEMC_SECONDARY_DIR+
"/"+nuflavor+
"/dsdy_"+secndryType+
"_1e"+senergy.str()+suffix;
154 ifile.open(path.c_str());
158 ifile >> y[index][NPROB] >> dsdy[index][NPROB];
172 void Secondaries::ReadSecondaries() {
175 cout<<
"Reading in data on secondary interactions.\n";
177 readData(
"muons",
"brems",y_muon_brems,dsdy_muon_brems);
178 readData(
"muons",
"epair",y_muon_epair,dsdy_muon_epair);
179 readData(
"muons",
"pn",y_muon_pn,dsdy_muon_pn);
180 readData(
"tauon",
"brems",y_tauon_brems,dsdy_tauon_brems);
181 readData(
"tauon",
"epair",y_tauon_epair,dsdy_tauon_epair);
182 readData(
"tauon",
"pn",y_tauon_pn,dsdy_tauon_pn);
183 readData(
"tauon",
"hadrdecay",y_tauon_hadrdecay,dsdy_tauon_hadrdecay);
184 readData(
"tauon",
"edecay",y_tauon_edecay,dsdy_tauon_edecay);
185 readData(
"tauon",
"mudecay",y_tauon_mudecay,dsdy_tauon_mudecay);
187 for(
int j=0;j<7;j++) {
189 int_muon_brems[j]=accumulate(dsdy_muon_brems[j],dsdy_muon_brems[j]+NPROB_MAX,0.);
190 int_muon_epair[j]=accumulate(dsdy_muon_epair[j],dsdy_muon_epair[j]+NPROB_MAX,0.);
191 int_muon_pn[j]=accumulate(dsdy_muon_pn[j],dsdy_muon_pn[j]+NPROB_MAX,0.);
192 int_tauon_brems[j]=accumulate(dsdy_tauon_brems[j],dsdy_tauon_brems[j]+NPROB_MAX,0.);
193 int_tauon_epair[j]=accumulate(dsdy_tauon_epair[j],dsdy_tauon_epair[j]+NPROB_MAX,0.);
194 int_tauon_pn[j]=accumulate(dsdy_tauon_pn[j],dsdy_tauon_pn[j]+NPROB_MAX,0.);
195 int_tauon_hadrdecay[j]=accumulate(dsdy_tauon_hadrdecay[j],dsdy_tauon_hadrdecay[j]+NPROB_MAX,0.);
196 int_tauon_edecay[j]=accumulate(dsdy_tauon_edecay[j],dsdy_tauon_edecay[j]+NPROB_MAX,0.);
197 int_tauon_mudecay[j]=accumulate(dsdy_tauon_mudecay[j],dsdy_tauon_mudecay[j]+NPROB_MAX,0.);
200 max_muon_brems=*max_element(dsdy_muon_brems[j],dsdy_muon_brems[j]+NPROB_MAX);
202 max_muon_epair=*max_element(dsdy_muon_epair[j],dsdy_muon_epair[j]+NPROB_MAX);
203 max_muon_pn=*max_element(dsdy_muon_pn[j],dsdy_muon_pn[j]+NPROB_MAX);
204 max_tauon_brems=*max_element(dsdy_tauon_brems[j],dsdy_tauon_brems[j]+NPROB_MAX);
205 max_tauon_epair=*max_element(dsdy_tauon_epair[j],dsdy_tauon_epair[j]+NPROB_MAX);
206 max_tauon_pn=*max_element(dsdy_tauon_pn[j],dsdy_tauon_pn[j]+NPROB_MAX);
207 max_tauon_hadrdecay=*max_element(dsdy_tauon_hadrdecay[j],dsdy_tauon_hadrdecay[j]+NPROB_MAX);
208 max_tauon_edecay=*max_element(dsdy_tauon_edecay[j],dsdy_tauon_edecay[j]+NPROB_MAX);
209 max_tauon_mudecay=*max_element(dsdy_tauon_mudecay[j],dsdy_tauon_mudecay[j]+NPROB_MAX);
212 min_muon_brems=Tools::dMinNotZero(dsdy_muon_brems[j],NPROB_MAX);
213 min_muon_epair=Tools::dMinNotZero(dsdy_muon_epair[j],NPROB_MAX);
214 min_muon_pn=Tools::dMinNotZero(dsdy_muon_pn[j],NPROB_MAX);
215 min_tauon_brems=Tools::dMinNotZero(dsdy_tauon_brems[j],NPROB_MAX);
216 min_tauon_epair=Tools::dMinNotZero(dsdy_tauon_epair[j],NPROB_MAX);
217 min_tauon_pn=Tools::dMinNotZero(dsdy_tauon_pn[j],NPROB_MAX);
218 min_tauon_hadrdecay=Tools::dMinNotZero(dsdy_tauon_hadrdecay[j],NPROB_MAX);
219 min_tauon_edecay=Tools::dMinNotZero(dsdy_tauon_edecay[j],NPROB_MAX);
220 min_tauon_mudecay=Tools::dMinNotZero(dsdy_tauon_mudecay[j],NPROB_MAX);
222 if (min_muon_brems<=0)
223 cout <<
"Minimum probability is <=0!\n";
225 partial_sum(dsdy_muon_brems[j],dsdy_muon_brems[j]+NPROB_MAX,y_cumulative_muon_brems[j]);
226 partial_sum(dsdy_muon_epair[j],dsdy_muon_epair[j]+NPROB_MAX,y_cumulative_muon_epair[j]);
227 partial_sum(dsdy_muon_pn[j],dsdy_muon_pn[j]+NPROB_MAX,y_cumulative_muon_pn[j]);
228 partial_sum(dsdy_tauon_brems[j],dsdy_tauon_brems[j]+NPROB_MAX,y_cumulative_tauon_brems[j]);
229 partial_sum(dsdy_tauon_epair[j],dsdy_tauon_epair[j]+NPROB_MAX,y_cumulative_tauon_epair[j]);
230 partial_sum(dsdy_tauon_pn[j],dsdy_tauon_pn[j]+NPROB_MAX,y_cumulative_tauon_pn[j]);
231 partial_sum(dsdy_tauon_hadrdecay[j],dsdy_tauon_hadrdecay[j]+NPROB_MAX,y_cumulative_tauon_hadrdecay[j]);
232 partial_sum(dsdy_tauon_mudecay[j],dsdy_tauon_mudecay[j]+NPROB_MAX,y_cumulative_tauon_mudecay[j]);
233 partial_sum(dsdy_tauon_edecay[j],dsdy_tauon_edecay[j]+NPROB_MAX,y_cumulative_tauon_edecay[j]);
235 for (
int i=0;i<NPROB_MAX;i++) {
236 y_cumulative_muon_brems[j][i] /= y_cumulative_muon_brems[j][NPROB_MAX-1];
237 y_cumulative_muon_epair[j][i] /= y_cumulative_muon_epair[j][NPROB_MAX-1];
238 y_cumulative_muon_pn[j][i] /= y_cumulative_muon_pn[j][NPROB_MAX-1];
239 y_cumulative_tauon_brems[j][i] /= y_cumulative_tauon_brems[j][NPROB_MAX-1];
240 y_cumulative_tauon_epair[j][i] /= y_cumulative_tauon_epair[j][NPROB_MAX-1];
241 y_cumulative_tauon_pn[j][i] /= y_cumulative_tauon_pn[j][NPROB_MAX-1];
242 y_cumulative_tauon_hadrdecay[j][i] /= y_cumulative_tauon_hadrdecay[j][NPROB_MAX-1];
243 y_cumulative_tauon_mudecay[j][i] /= y_cumulative_tauon_mudecay[j][NPROB_MAX-1];
244 y_cumulative_tauon_edecay[j][i] /= y_cumulative_tauon_edecay[j][NPROB_MAX-1];
248 cout<<
"Finished reading secondary interaction data.\n";
254 void Secondaries::GetSecondaries(
Settings *settings1,
string nuflavor,
double plepton,
double &em_secondaries_max,
double &had_secondaries_max,
int &n_interactions,TH1F *hy) {
257 em_secondaries_max=0.;
258 had_secondaries_max=0.;
260 int i=(int)((log10(plepton)-18.)*2.);
266 int n_brems,n_epair,n_pn;
274 TRandom * rng = getRNG(RNG_SECONDARIES);
277 if (nuflavor==
"numu") {
278 n_brems=rng->Poisson(int_muon_brems[i]);
279 n_epair=rng->Poisson(int_muon_epair[i]);
280 n_pn=rng->Poisson(int_muon_pn[i]);
282 n_interactions+=(n_brems+n_epair+n_pn);
285 for (
int j=0;j<n_brems+n_epair+n_pn;j++) {
287 if (rnd1<=(
double)n_brems/(
double)(n_brems+n_epair+n_pn))
289 else if (rnd1<=(
double)(n_brems+n_epair)/(
double)(n_brems+n_epair+n_pn))
298 if (whichtype==
"brems") {
300 Picky(y_cumulative_muon_brems[i],NPROB,rnd1,y);
302 else if (whichtype==
"epair") {
304 Picky(y_cumulative_muon_epair[i],NPROB,rnd1,y);
306 else if (whichtype==
"pn") {
308 Picky(y_cumulative_muon_pn[i],NPROB,rnd1,y);
311 if (y*plepton>max(em_secondaries_max,had_secondaries_max)) {
312 if (whichtype==
"brems" || whichtype==
"epair") {
313 em_secondaries_max=y*plepton;
317 had_secondaries_max=y*plepton;
323 if (nuflavor==
"nutau") {
324 n_brems=rng->Poisson(int_tauon_brems[i]);
325 n_epair=rng->Poisson(int_tauon_epair[i]);
326 n_pn=rng->Poisson(int_tauon_pn[i]);
328 n_interactions+=(n_brems+n_epair+n_pn);
330 for (
int j=0;j<n_brems+n_epair+n_pn;j++) {
333 if (rnd1<=(
double)n_brems/(
double)(n_brems+n_epair+n_pn))
335 else if (rnd1<=(
double)(n_brems+n_epair)/(
double)(n_brems+n_epair+n_pn))
344 if (whichtype==
"brems") {
346 Picky(y_cumulative_tauon_brems[i],NPROB,rnd1,y);
348 if (whichtype==
"epair") {
350 Picky(y_cumulative_tauon_epair[i],NPROB,rnd1,y);
352 if (whichtype==
"pn") {
354 Picky(y_cumulative_tauon_pn[i],NPROB,rnd1,y);
357 if (settings1->HIST==1 && !settings1->ONLYFINAL && hy->GetEntries()<settings1->HIST_MAX_ENTRIES)
359 if (y*plepton>max(em_secondaries_max,had_secondaries_max)) {
360 if (whichtype==
"brems" || whichtype==
"epair")
361 em_secondaries_max=y*plepton;
363 had_secondaries_max=y*plepton;
373 whichtype=
"hadrdecay";
374 if (rnd1>=0.65011 && rnd1<0.8219)
383 if (whichtype==
"hadrdecay") {
385 Picky(y_cumulative_tauon_hadrdecay[i],NPROB,rnd1,y);
387 else if (whichtype==
"edecay") {
389 Picky(y_cumulative_tauon_edecay[i],NPROB,rnd1,y);
391 else if (whichtype==
"mudecay") {
393 Picky(y_cumulative_tauon_mudecay[i],NPROB,rnd1,y);
397 if (y*plepton>max(em_secondaries_max, had_secondaries_max)) {
398 if (whichtype==
"edecay")
399 em_secondaries_max=y*plepton;
400 if (whichtype==
"hadrdecay")
401 had_secondaries_max=y*plepton;
410 int Secondaries::GetEMFrac(
Settings *settings1,
string nuflavor,
421 int& n_interactions,
int taumodes1) {
431 if (nuflavor==
"nue" && current==
"cc") {
435 else if(nuflavor==
"numu" && current==
"cc") {
439 else if(nuflavor==
"nutau" && current==
"cc") {
442 this->GetEMFracDB(emfrac,hadfrac);
444 else if (taumodes1 == 0){
452 else if (current==
"nc") {
458 em_secondaries_max =emfrac;
459 had_secondaries_max=hadfrac;
463 if (SECONDARIES==1 && current==
"cc" && settings1->FORSECKEL!=1) {
467 GetSecondaries(settings1,nuflavor,plepton,em_secondaries_max,had_secondaries_max,n_interactions,hy);
469 if (em_secondaries_max+had_secondaries_max<=plepton*(1.+1.E-5))
472 secondary_e_noncons++;
473 em_secondaries_max=emfrac;
474 had_secondaries_max=hadfrac;
478 if ((em_secondaries_max+had_secondaries_max)>(emfrac+hadfrac)*pnu) {
480 emfrac=em_secondaries_max/pnu;
481 hadfrac=had_secondaries_max/pnu;
482 if (emfrac <= 1.E-10)
484 if (hadfrac<= 1.E-10)
489 if (nuflavor==
"numu" && current==
"cc" && n_interactions==0)
490 cout <<
"Look at this one. inu is " << inu <<
"\n";
494 if ((y<0 || y>1) && y != -999.)
495 cout <<
"illegal y=" << y <<
"\n";
497 if (emfrac+hadfrac>1.00001) {
498 cout <<
"error emfrac,hadfrac=" << emfrac <<
" " << hadfrac <<
" " << emfrac+hadfrac <<
"\n";
499 cout <<
"nuflavor,taudecay=" << nuflavor <<
" " << taudecay <<
"\n";
511 void Secondaries::InitTauola() {
513 tauolainfile >> tauola[0][k];
514 for(
int i=1;i<N_TAUOLA;i++)
516 tauolainfile >> tauola[i][j];
521 void Secondaries::GetTauDecay(
string nuflavor,
string current,
string& taudecay,
double& emfrac_db,
double& hadfrac_db) {
523 if (!(nuflavor==
"nutau" || current==
"cc" || interestedintaus))
528 TRandom * rng = getRNG(RNG_SECONDARIES);
529 double rnd = rng->Rndm();
530 int decay =
static_cast<int>(rnd*(N_TAUOLA-2)+1);
532 hadfrac_db=tauola[decay][3];
533 emfrac_db=tauola[decay][4];
535 if(tauola[decay][1]!=0)
545 double rnd=rng->Rndm();
560 void Secondaries::GetEMFracDB(
double& emfrac_db,
double& hadfrac_db) {
562 TRandom * rng = getRNG(RNG_SECONDARIES);
564 double rnd = rng->Rndm();
565 int decay =
static_cast<int>(rnd*(N_TAUOLA-2)+1);
567 hadfrac_db=tauola[decay][3];
568 emfrac_db=tauola[decay][4];
577 double Secondaries::GetDBViewAngle(
const Vector &refr,
const Vector &nnu) {
579 return ((nnu.ChangeCoord(refr)).Angle(z_axis));
622 double Secondaries::NFBWeight(
double ptau,
double taulength) {
624 double gamma=ptau/MTAU;
625 double D=TAUDECAY_TIME*CLIGHT*gamma;
627 return exp(-taulength/D);
630 void Secondaries::Picky(
double *y_cumulative,
int NPROB,
double rnd,
double& y) {
631 for (
int i=0;i<NPROB;i++) {
632 if (y_cumulative[i]<=rnd && y_cumulative[i+1]>rnd) {
633 y=(double)i/(
double)NPROB;
const char * ICEMC_SRC_DIR()
Reads in and stores input settings for the run.
This class represents a three-vector. Operators are overloaded to provide for the familiar operations...