Hello,
I am trying to simulate a drift chamber, but I am facing some issues:
- The guard wires are not producing any drift lines.
- Some drift lines lie outside the chamber geometry.
The code I am using:
#include <iostream>
#include <cstdlib>
#include <math.h>
#include <fstream>
#include <TCanvas.h>
#include <TROOT.h>
#include <TApplication.h>
#include "Garfield/ViewField.hh"
#include "Garfield/ViewCell.hh"
#include "Garfield/ComponentAnalyticField.hh"
#include "Garfield/MediumMagboltz.hh"
#include "Garfield/Plotting.hh"
#include "Garfield/GeometrySimple.hh"
#include "Garfield/SolidBox.hh"
#include "Garfield/ViewSignal.hh"
#include "Garfield/DriftLineRKF.hh"
#include "Garfield/TrackHeed.hh"
#include "Garfield/Sensor.hh"
#include "Garfield/ViewDrift.hh"
#include "Garfield/AvalancheMicroscopic.hh"
#include "Garfield/AvalancheMC.hh"
#include "Garfield/ViewMedium.hh"
#include "Garfield/ViewGeometry.hh"
#include <TH1F.h>
#include <TH2F.h>
#define PI 3.14159265
using namespace Garfield;
using namespace std;
double transfer(double t) {
const double tau = 61.1;// time constant
return exp(- t / tau);
}
int main(int argc, char * argv[]) {
TApplication app("app", &argc, argv);
plottingEngine.SetDefaultStyle();
// Gas mixture.
MediumMagboltz gas;
gas.LoadGasFile("ar_94_co2_6.gas");
const string path = getenv("GARFIELD_INSTALL");
gas.LoadIonMobility(path + "/share/Garfield/Data/IonMobility_Ar+_Ar.txt");
// Create the geometry.
GeometrySimple( geo);
SolidBox* chamber = new SolidBox(0,11.2/2,400.0/2,50.8/2,11.2/2,400.0/2);
geo.AddSolid(chamber, &gas);
ComponentAnalyticField cmp;
cmp.SetMedium(&gas);
cmp.SetGeometry(&geo);
// Wire diameters [cm].
constexpr double ds = 0.006400; // sense wires
constexpr double dc = 0.0200000; // cathode wires
constexpr double dg = 0.0200000; // gate wires
constexpr double df = 0.0200000; // field forming wires
// Voltage settings [V].
constexpr double vs = 2200.; // sense wires
constexpr double vg = 2200; // gate wires
constexpr double vc = 0000.; // cathode wires
// Add the sense (anode) wires.
float x_wires[4] = {0.075,-0.075,0.075,-0.075};
float z_wires[4] = {4.10,5.10,6.10,7.10};
cmp.AddWire(x_wires[0], z_wires[0], ds, vs, "s1", 370);
cmp.AddReadout("s1");
cmp.AddWire(x_wires[1], z_wires[1], ds, vs, "s2", 370);
cmp.AddReadout("s2");
cmp.AddWire(x_wires[2], z_wires[2], ds, vs, "s3", 370);
cmp.AddReadout("s3");
cmp.AddWire(x_wires[3], z_wires[3], ds, vs, "s4", 370);
cmp.AddReadout("s4");
// Add the cathode wires.
for (int i=0;i<5;i++){
cmp.AddWire(0.3, 3.6+1.0*i, dc, vc, "c", 400);
cmp.AddWire(-0.3, 3.6+1.0*i, dc, vc, "c", 400);
}
cmp.AddReadout("c");
// Add the gate wires.
constexpr double yg1 = 3.10;
constexpr double yg2 = 8.10;//5 * period;
constexpr double xg1 =-0.075;// 2. * gap + 0.3;
constexpr double xg2 =0.075;
cmp.AddWire(xg1, yg1, dg, vg, "g1", 370);
cmp.AddWire(xg2, yg2, dg, vg, "g2", 370);
cmp.AddReadout("g1");
cmp.AddReadout("g2");
for (int i=0;i<50;i++){
cmp.AddWire(0+0.5*i, 5.6-3.0, 0.02, -250*i, "q", 400);
cmp.AddWire(0+0.5*i, 5.6+3.0, 0.02, -250*i, "q", 400);
cmp.AddWire(0-0.5*i, 5.6-3.0, 0.02, -250*i, "q", 400);
cmp.AddWire(0-0.5*i, 5.6+3.0, 0.02, -250*i, "q", 400);
}
for (int i=0;i<21;i++){
cmp.AddWire(-25, 5.6-3.0+0.3*i, 0.02, -12000, "q", 400);
cmp.AddWire( 25, 5.6-3.0+0.3*i, 0.02, -12000, "q", 400);
}
// Make a sensor.
cmp.AddReadout("q");
// Calculate the electric field using the Component object cmp.
Sensor sensor;
sensor.AddComponent(&cmp);
sensor.AddElectrode(&cmp, "s1");
sensor.AddElectrode(&cmp, "s2");
sensor.AddElectrode(&cmp, "s3");
sensor.AddElectrode(&cmp, "s4");
sensor.AddElectrode(&cmp, "g1");
sensor.AddElectrode(&cmp, "g2");
sensor.AddElectrode(&cmp, "c");
sensor.AddElectrode(&cmp, "q");
const double tstep = 1;//0.5;
const double tmin = 0;//-0.5 * tstep;
const unsigned int nbins = 6000;
sensor.SetTimeWindow(tmin, tstep, nbins);
ViewDrift driftView;
driftView.SetArea(-50.,-12,-400,50,12,400);
TrackHeed track;
track.EnablePlotting(&driftView);
track.SetParticle("muon");
track.SetEnergy(1.e9);//170.e9);
track.SetSensor(&sensor);
for (int a =0;a<1;a++)//Events
{
DriftLineRKF drift;
drift.SetSensor(&sensor);
drift.EnableSignalCalculation();
drift.EnablePlotting(&driftView);
sensor.SetTransferFunction(transfer);
sensor.ClearSignal();
sensor.NewSignal();
{
track.NewTrack(double(a), 11.2, 0, double(a), double(a), -11.2, 0); //b_pos_x
// Loop over the clusters along the track.
double xc = 0., yc = 0., zc = 0., tc = 0., ec = 0., extra = 0.;
int nc = 0;
while (track.GetCluster(xc, yc, zc, tc, nc, ec, extra)) {
// Loop over the electrons in the cluster.
for (int k = 0; k < nc; ++k) {
double xe = 0., ye = 0., ze = 0., te = 0., ee = 0.;
double dx = 0., dy = 0., dz = 0.;
track.GetElectron(k, xe, ye, ze, te, ee, dx, dy, dz);
drift.DriftElectron(xe, ye, ze, te);
}
}
}
ViewSignal signalView;
signalView.SetSensor(&sensor);
sensor.ConvoluteSignal("s1",false);
TCanvas* S1 = new TCanvas("s1","s1",1600,800);
signalView.SetCanvas(S1);
signalView.PlotSignal("s1");
S1->SaveAs("S1.png");
sensor.ConvoluteSignal("s2",false);
TCanvas* S2 = new TCanvas("s2","s2",1600,800);
signalView.SetCanvas(S2);
signalView.PlotSignal("s2");
S2->SaveAs("S2.png");
sensor.ConvoluteSignal("s3",false);
TCanvas* S3 = new TCanvas("s3","s3",1600,800);
signalView.SetCanvas(S3);
signalView.PlotSignal("s3");
S3->SaveAs("S3.png");
sensor.ConvoluteSignal("s4",false);
TCanvas* S4 = new TCanvas("s4","s4",1600,800);
signalView.SetCanvas(S4);
signalView.PlotSignal("s4");
S4->SaveAs("S4.png");
ViewCell cellView;
TCanvas* myCanvas = new TCanvas();
cellView.SetComponent(&cmp);
cellView.SetArea(-50.8 / 2., -11.2/2,-400/2, 50.8 / 2., 11.2,400);
cellView.SetCanvas(myCanvas);
cellView.Plot2d();
driftView.SetCanvas(myCanvas);
driftView.Plot(true, false);
myCanvas->SaveAs("drift.png");
}
ViewField fieldView;
fieldView.SetComponent(&cmp);
fieldView.SetArea(-55.8/2, 0, 55.8/2, 11.2);
fieldView.SetVoltageRange(-12000., 14200.);
fieldView.SetNumberOfContours(100);
fieldView.Plot("v", "CONT1");
// Plot field lines.
vector<double> xf;
vector<double> yf;
vector<double> zf;
fieldView.EqualFluxIntervals(48.8/2,-0.5,0, 48.8/2, 11.2, 0.,
xf, yf, zf, 100);
fieldView.PlotFieldLines(xf, yf, zf, true, false);
// Plot the cell layout.
//ViewCell cellView;
cellView.SetCanvas(fieldView.GetCanvas());
cellView.SetComponent(&cmp);
//cellView.SetArea(-50.8/2,-11.2, 50.8/2, 11.2);
cellView.Plot2d();
app.Run(true);
}
This are the outputs I am getting when I am considering only one event:
Please help me solve these issues.