// Simplified calculation of magnetic field effect on propagation of particle with // wrong momentum assumption (background) in PANDA mag.field // Based on Runge-Kutta algorithm with 4 order // [refence to paper by I.Kisel & S.Gorbunov about this topic: // http://www-linux.gsi.de/~ikisel/reco/CBM/DOC-2005-Mar-212-1.pdf] // v.1.0: Bx=Bz=0, By!=0 // date: 23/09/2013 // v.2.0: Bx=Bz=0, By!=0, bug fixed //date: 25/11/2013 // code author: A. Karavdina #include "TMath.h" #include "TF1.h" #include "TVector3.h" #include #include #include "TH2D.h" #include "TTree.h" #include "TFile.h" #include "TString.h" #include "TRandom3.h" #include "TGraph.h" #include "TNtuple.h" using namespace std; const double kappa = 2.99792458e-4; // [(GeV/c)/(kG^{−1}*cm^{−1})] //Description for params in functions ay&by: //p[0] = momentum [GeV] //p[1] = charge [e] //x[0] = t_x, direction in x //x[1] = t_y, direction in y //TTree *Byintegttbl; double gl_z1[2641500],gl_z2[2641500],gl_By[2641500],gl_By1[2641500],gl_By2[2641500],gl_By3[2641500]; int stField; //TTree *T; int FieldTable(char inputFilename[500] ="15_GeV_FieldIntegTable.txt"){ ifstream inFile(inputFilename); // std::ifstream inFile; // inFile.open(inputFilename,std::ios::in | std::ios::binary); // char inputFilename[] = fname; // inFile.open(inputFilename, ios::in); // std::ifstream inFile(inputFilename, std::ifstream::in); int j=0; while (!inFile.eof()) { inFile >> gl_z1[j] >> gl_z2[j] >> gl_By[j] >> gl_By1[j] >> gl_By2[j] >> gl_By3[j] ; //cout<<"gl_z1["<ReadFile(fname,"z1:z2:By:By1:By2:By3"); // stField = nlines; // // T->Write(); // // T->Print(); // Tk->Print(); // // T->Draw("z1"); // printf(" found %lld points\n",nlines); // TBranch *br_z1 = Tk->GetBranch("z1"); // TBranch *br_z2 = Tk->GetBranch("z2"); // TBranch *br_By = Tk->GetBranch("By"); //field values // TBranch *br_By1 = Tk->GetBranch("By1");//integral values // TBranch *br_By2 = Tk->GetBranch("By2"); // TBranch *br_By3 = Tk->GetBranch("By3"); // double z1in,z2in,Byin,By1in,By2in,By3in; // br_z1->SetAddress(&z1in); // br_z2->SetAddress(&z2in); // br_By->SetAddress(&Byin); // br_By1->SetAddress(&By1in); // br_By2->SetAddress(&By2in); // br_By3->SetAddress(&By3in); // // T->SetBranchAddress("z1",&z1in); // // T->SetBranchAddress("z2",&z2in); // // T->SetBranchAddress("By",&Byin); // // T->SetBranchAddress("By1",&By1in); // // T->SetBranchAddress("By2",&By2in); // // T->SetBranchAddress("By3",&By3in); // // int nevent = T->GetEntries(); // for(int itree=0;itreeGetEvent(itree); // // br_z1->GetEvent(itree); // gl_z1[itree] = z1in; // gl_z2[itree] = z2in; // cout<<" z1in = "<SetParameters(0,0.01); fa3->SetParNames("step"); fa3->Draw(); } double By_integ_1(double *z){ if( (z[0]>324.9 && z[0]<621.8) || (z[1]>324.9 && z[1]<621.8)){ if(z[0]>324.9 && z[0]<621.8){ if(z[1]<324.9) z[1]=324.9; if(z[1]>621.8) z[1]=621.8; } if(z[1]>324.9 && z[1]<621.8){ if(z[0]<324.9) z[0]=324.9; if(z[0]>621.8) z[0]=621.8; } // double par[7]={101.276, -1.324.931, 0.00652559, // -1.54572e-05, 1.77642e-08, -7.99135e-12}; // double par[4]={-22.44, 0.133067, -0.00024342, 1.4136e-07}; double par[7] = {10*1022.18, 10*-13.5362, 10*0.0734285, 10*-0.000209178, 10*3.30658e-07, 10*-2.75369e-10, 10*9.44655e-14}; double fBy = 0; for(int i=0;i<7;i++) fBy +=(par[i]/(i+1))*(TMath::Power(z[1],i+1)-TMath::Power(z[0],i+1)); // if(z[0]==324.9 || z[0]==621.8 || z[1]==324.9 || z[1]==621.8) // cout<<"somebody called By_integ_1("<GetBranch("y_out"); TBranch *br_z_in = tByProp_in->GetBranch("z_out"); TBranch *br_th_in = tByProp_in->GetBranch("th_out"); TBranch *br_ph_in = tByProp_in->GetBranch("ph_out"); TBranch *br_x_sim = tByProp_in->GetBranch("x_in"); TBranch *br_y_sim = tByProp_in->GetBranch("y_in"); TBranch *br_z_sim = tByProp_in->GetBranch("z_in"); TBranch *br_th_sim = tByProp_in->GetBranch("th_in"); TBranch *br_ph_sim = tByProp_in->GetBranch("ph_in"); double x_in_b,y_in_b,z_in_b,th_in_b,ph_in_b; //input for backward propagation br_x_in->SetAddress(&x_in_b); br_y_in->SetAddress(&y_in_b); br_z_in->SetAddress(&z_in_b); br_th_in->SetAddress(&th_in_b); br_ph_in->SetAddress(&ph_in_b); //input for simulation br_x_sim->SetAddress(&x_sim); br_y_sim->SetAddress(&y_sim); br_z_sim->SetAddress(&z_sim); br_th_sim->SetAddress(&th_sim); br_ph_sim->SetAddress(&ph_sim); int nevent = tByProp_in->GetEntries(); if(itree>nevent){ cout<<"Tree has "<GetEvent(itree); x0=x_in_b; y0=y_in_b; z0=z_in_b; th_in = th_in_b; ph_in =ph_in_b; // if(ph_in_b>0) ph_in =ph_in_b-TMath::Pi(); // if(ph_in_b<0) ph_in =ph_in_b+TMath::Pi(); // cout<<"ph_in_b = "<racc2) ifPropxy=false; } // if(!ifPropxy && ifProp) cout<<" x0 = "<Branch("x_in", &x_in); tByProp->Branch("y_in", &y_in); tByProp->Branch("z_in", &z_in); tByProp->Branch("th_in", &th_in); tByProp->Branch("ph_in", &ph_in); tByProp->Branch("x_out", &x_out); tByProp->Branch("y_out", &y_out); tByProp->Branch("z_out", &z_out); tByProp->Branch("th_out", &th_out); tByProp->Branch("ph_out", &ph_out); Double_t x_sim,y_sim,z_sim,th_sim,ph_sim; Double_t rd_in, r_in; if(!fl_in_prop){ tByProp->Branch("x_sim", &x_sim); tByProp->Branch("y_sim", &y_sim); tByProp->Branch("z_sim", &z_sim); tByProp->Branch("th_sim", &th_sim); tByProp->Branch("ph_sim", &ph_sim); tByProp->Branch("rd_in", &rd_in); tByProp->Branch("r_in", &r_in); } const int nsampst = nEv;//number of th&ph samples // const int nsampst = 1e3;//number of th&ph samples if(fl_in_prop){ //forward extrapolation const double factor = TMath::Power((fabs(icharge)/momentum),0); // const int nsteps=factor*1e8; // const int nsteps=factor*1e4; const int nsteps=factor*5e3; double zst = 1124./nsteps; // cout<<"factor for number of internal steps = "<-1;i--){//backfward double z1 = z0+(i-1)*zst; double z2 = z0+i*zst; double zpair[2] = {z1,z2}; // gBy[i] = By(zpair); // zBy[i] = z1; // acst++; // if(By(zpair)!=0){ // cout.precision(15); // cout<0) ph_out = dirFin.Phi()-TMath::Pi(); // if(dirFin.Phi()<0) ph_out = dirFin.Phi()+TMath::Pi(); tByProp->Fill(); } } /// [END] Fill tree with results from forward propagation from ------------------ f_in->Write(); } else{ double mom; double q; if(forwAss){ //use true values mom=momentum;//GeV , q = icharge; //[e] } else{ //barp assumption for propagation mom=Pbeam;//GeV // mom=1.5;//GeV q = -1; //barp=-1!!! } const double factor = TMath::Power((fabs(q)/mom),0); const int nsteps=factor*5e3; // const int nsteps=factor*5e3; double zst = 1124./nsteps; cout<<"assumption for propagation: mom="<0) break; // cout<<"resread = "<1e3 || fabs(y_out)>1e3) break; // ///TEST!!!!!! --------------- // if((tx0*tx0+ty0*ty0)<1) tz0 = TMath::Sqrt(1-tx0*tx0-ty0*ty0); // else tz0 = -999; // if(tz0!=-999){ // TVector3 dirFin(tx0,ty0,tz0); // th_out = dirFin.Theta(); // //ph_out = dirFin.Phi(); // if(dirFin.Phi()>0) ph_out = dirFin.Phi()-TMath::Pi(); // if(dirFin.Phi()<0) ph_out = dirFin.Phi()+TMath::Pi(); // // x_out = x_out_tmp; // // y_out = y_out_tmp; // // z_out = z_out_tmp; // tByProp->Fill(); // } // ///[END] TEST!!!!!! --------------- } //[END]propagate ---------------------------- if((tx0*tx0+ty0*ty0)<1) tz0 = TMath::Sqrt(1-tx0*tx0-ty0*ty0); else tz0 = -999; if(tz0!=-999){ TVector3 dirFin(tx0,ty0,tz0); th_out = dirFin.Theta(); //ph_out = dirFin.Phi(); // if(dirFin.Phi()>0) ph_out = dirFin.Phi()-TMath::Pi(); // if(dirFin.Phi()<0) ph_out = dirFin.Phi()+TMath::Pi(); ph_out = dirFin.Phi(); // x_out = x_out_tmp; // y_out = y_out_tmp; // z_out = z_out_tmp; tByProp->Fill(); // if((isamp%1000)==0) cout<<"For sample#"<Write(); } // } //} }