#include #include #include #include #include #include #include #include #include "Garfield/ViewCell.hh" #include "Garfield/ViewDrift.hh" #include "Garfield/ViewSignal.hh" #include "Garfield/ComponentAnalyticField.hh" #include "Garfield/MediumMagboltz.hh" #include "Garfield/Sensor.hh" #include "Garfield/DriftLineRKF.hh" #include "Garfield/AvalancheMC.hh" #include "Garfield/AvalancheMicroscopic.hh" #include "Garfield/SolidBox.hh" #include "Garfield/GeometrySimple.hh" #include "Garfield/ComponentConstant.hh" #include "Garfield/TrackSrim.hh" #include "Garfield/Random.hh" #include "Garfield/Plotting.hh" using namespace Garfield; //电流前端电子学卷积函数 double Transferfunction(double t){ constexpr double risistance= 100 ; //电阻设置 constexpr double capacitance= 100; //电容设置 constexpr double tau=risistance*capacitance; return exp(t/tau); } //电流视为delat冲击电流的响应函数 bool readTransferFunction(Sensor& sensor) { std::ifstream infile; infile.open("mdt_elx_delta.txt", std::ios::in); if (!infile) { std::cerr << "Could not read delta response function.\n"; return false; } std::vector times; std::vector values; while (!infile.eof()) { double t = 0., f = 0.; infile >> t >> f; if (infile.eof() || infile.fail()) break; times.push_back(1.e3 * t); values.push_back(f); } infile.close(); sensor.SetTransferFunction(times, values); return true; } //入射离子产生的cluster的位置,时刻沉积能量输出到txt文件 void printinformationofclusters(std::vector> informationofclusters,\ float name[]){ char title[60]; sprintf(title,"cluster information Ar_%.1f_CO2_%.1f_300K_%.2fAtm_%.0fV.txt",name[0],name[1],name[2],name[3]); std::ofstream outfile; outfile.open(title,std::ios::out); outfile << "the informations of every cluster in a track of projectile:\n"; outfile << "order X(cm) Y(cm) Z(cm) moment(ns) number of electrons desposited energy(eV) " " enenrgy before collision(Mev):\n"; const std::size_t numberofcluster=informationofclusters.size(); for(size_t i=0;i> primaryelectrons; //std::vector> avalancheions; //std::vector> primaryions; for (unsigned int n = 0; n < nTracks; ++n) { //对一个入射离子的径迹进行计算,得到多个clusters //设置入射粒子的位置方向,前三个参量为位置,后三个参量为方向 const bool notnewtrack= !tr.NewTrack(projectilex, projectiley, projectilez, projectileT, projectiledx, projectiledy, projectiledz); if (notnewtrack) { std::cerr << "Generating clusters failed; skipping this particle's track.\n"; continue; } //对单个入射粒子计算产生的clusters信息 unsigned int netot = 0; std::vector> informationofclusters; while (true) { int ne = 0; double xc, yc, zc, tc, ec, ekin; const bool done = tr.GetCluster(xc, yc, zc, tc, ne, ec, ekin); //GetCluster()为得到下一个cluster的信息:xc, yc, zc为cluster坐标, if(done) { //tc为时刻,ne为单次碰撞产生的电子数,ec为单次碰撞中能量损失,ekin为入射离子此时此位置的动能 informationofclusters.push_back({xc, yc, zc, tc, ne, ec,ekin}); //将每一个cluster的产生位置,时刻及沉积能量传到informationofclusters向量变量 netot += ne; //计算单个入射粒子产生的总的电子数 } if (!done) { hX->Fill(xc); //每一个入射离子最后一个cluster中的电子X位置 hY->Fill(yc); //每一个入射离子最后一个cluster中的电子Y位置 hZ->Fill(zc); //每一个入射离子最后一个cluster中的电子Z位置 hNe->Fill(netot); //每一个入射离子产生的总的电子数 std::cout << informationofclusters.size() << " clusters infornation is passed to file.\n\n"; break; //跳出while循环的控制 } } //对cluster产生的时刻进行修正 double MLi=6.9405*1.66053886e-27; //********** //Li离子的原子量换算为kg double Mev=1.602176565e-13; //1MeV等量焦耳能 for(int i=0;iDivide(2, 2); //将绘图平面变为2*2的布局绘图 c->cd(1); hX->Draw(); c->cd(2); hY->Draw(); c->cd(3); hZ->Draw(); c->cd(4); hNe->Draw(); c->Update(); // 漂移线绘制 if (plotDrift) { cD->Clear(); cellView.Plot2d(); //绘制二维探测器结构图 constexpr bool twod = true; constexpr bool drawaxis = false; driftView.Plot(twod, drawaxis); //绘制二维漂移线图 } // 信号计算 printsignaltotxt(sensor,"s",nbins,tstep,tmin,name); //打印原始总电流,电子电流,离子电流信号到txt文件 //sensor.ConvoluteSignals(); //开启电流传递函数,进行卷积积分计算 //printconvolutesignaltotxt(senor,"s",nbins,tstep); //打印卷积计算后的信号到txt文件 int nt = 0; //对记录越过阈值的信号数目计数器初始化 //if (!sensor.ComputeThresholdCrossings(-2., "s", nt)) continue; //设置“S”电极上的阈值,返回nt为越过阈值的信号数目 if (plotSignal) signalView.PlotSignal("s"); //绘制电极“s”上的信号 std::cout << "Calculation is finished.\n"; //计算完成标志 app.Run(kTRUE); }