Skip to content

Commit 33c82fc

Browse files
committed
Extend TOF detector class to behave both like barrel/forward
1 parent f0ae82a commit 33c82fc

File tree

4 files changed

+214
-3
lines changed

4 files changed

+214
-3
lines changed

examples/scripts/ftof.sh

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#! /usr/bin/env bash
2+
3+
NJOBS=5 # number of max parallel runs
4+
NRUNS=10 # number of runs
5+
NEVENTS=10000 # number of events in a run
6+
7+
BFIELD=5. # magnetic field [kG]
8+
SIGMAT=0.020 # time resolution [ns]
9+
TAILLX=1.0 # tail on left [q]
10+
TAILRX=1.3 # tail on right [q]
11+
TOFRAD=100. # TOF radius [cm]
12+
TOFRADIN=10. # TOF inner radius [cm]
13+
TOFLEN=200. # TOF half length [cm]
14+
TOFETA=1.443 # TOF max pseudorapidity
15+
16+
### calculate max eta from geometry
17+
TOFETA=`awk -v a=$TOFRADIN -v b=$TOFLEN 'BEGIN {th=atan2(a,b)*0.5; sth=sin(th); cth=cos(th); print -log(sth/cth)}'`
18+
echo "maxEta = $TOFETA"
19+
20+
### copy relevant files in the working directory
21+
cp $DELPHESO2_ROOT/examples/cards/propagate.2kG.tails.tcl propagate.tcl
22+
cp $DELPHESO2_ROOT/examples/pythia8/pythia8_inel.cfg .
23+
cp $DELPHESO2_ROOT/examples/smearing/ftof.C .
24+
25+
### set magnetic field
26+
sed -i -e "s/set barrel_Bz .*$/set barrel_Bz ${BFIELD}e\-1/" propagate.tcl
27+
### set TOF radius
28+
sed -i -e "s/set barrel_Radius .*$/set barrel_Radius ${TOFRAD}e\-2/" propagate.tcl
29+
sed -i -e "s/double tof_radius = .*$/double tof_radius = ${TOFRAD}\;/" ftof.C
30+
### set TOF length
31+
sed -i -e "s/set barrel_HalfLength .*$/set barrel_HalfLength ${TOFLEN}e\-2/" propagate.tcl
32+
sed -i -e "s/double tof_length = .*$/double tof_length = ${TOFLEN}\;/" ftof.C
33+
### set TOF acceptance
34+
sed -i -e "s/set barrel_Acceptance .*$/set barrel_Acceptance \{ 0.0 + 1.0 * fabs(eta) < ${TOFETA} \}/" propagate.tcl
35+
### set TOF time resolution and tails
36+
sed -i -e "s/set barrel_TimeResolution .*$/set barrel_TimeResolution ${SIGMAT}e\-9/" propagate.tcl
37+
sed -i -e "s/set barrel_TailRight .*$/set barrel_TailRight ${TAILRX}/" propagate.tcl
38+
sed -i -e "s/set barrel_TailLeft .*$/set barrel_TailLeft ${TAILLX}/" propagate.tcl
39+
sed -i -e "s/double tof_sigmat = .*$/double tof_sigmat = ${SIGMAT}\;/" ftof.C
40+
41+
### create LUTs
42+
BFIELDT=`awk -v a=$BFIELD 'BEGIN {print a*0.1}'`
43+
$DELPHESO2_ROOT/examples/scripts/create_luts.sh werner $BFIELDT $TOFRAD
44+
45+
### loop over runs
46+
rm -f .running.* delphes.*.root
47+
for I in $(seq 1 $NRUNS); do
48+
49+
### wait for a free slot
50+
while [ $(ls .running.* 2> /dev/null | wc -l) -ge $NJOBS ]; do
51+
echo " --- waiting for a free slot"
52+
sleep 1
53+
done
54+
55+
### book the slot
56+
echo " --- starting run $I"
57+
touch .running.$I
58+
59+
### copy pythia8 configuration and adjust it
60+
cp pythia8_inel.cfg pythia8.$I.cfg
61+
echo "Main:numberOfEvents $NEVENTS" >> pythia8.$I.cfg
62+
echo "Random:seed = $I" >> pythia8.$I.cfg
63+
echo "Beams:allowVertexSpread on " >> pythia8.$I.cfg
64+
echo "Beams:sigmaTime 60." >> pythia8.$I.cfg
65+
66+
### run Delphes and analysis
67+
DelphesPythia8 propagate.tcl pythia8.$I.cfg delphes.$I.root &> delphes.$I.log &&
68+
root -b -q -l "ftof.C(\"delphes.$I.root\", \"ftof.$I.root\")" &> ftof.$I.log &&
69+
rm -rf delphes.$I.root &&
70+
rm -rf .running.$I &&
71+
echo " --- complete run $I" &
72+
73+
done
74+
75+
### merge runs when all done
76+
wait
77+
hadd -f ftof.root ftof.*.root && rm -rf ftof.*.root

examples/smearing/ftof.C

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
R__LOAD_LIBRARY(libDelphes)
2+
R__LOAD_LIBRARY(libDelphesO2)
3+
4+
double tof_radius = 100.; // [cm]
5+
double tof_length = 200.; // [cm]
6+
double tof_sigmat = 0.02; // [ns]
7+
8+
void
9+
ftof(const char *inputFile = "delphes.root",
10+
const char *outputFile = "ftof.root")
11+
{
12+
13+
// Create chain of root trees
14+
TChain chain("Delphes");
15+
chain.Add(inputFile);
16+
17+
// Create object of class ExRootTreeReader
18+
auto treeReader = new ExRootTreeReader(&chain);
19+
auto numberOfEntries = treeReader->GetEntries();
20+
21+
// Get pointers to branches used in this analysis
22+
auto events = treeReader->UseBranch("Event");
23+
auto tracks = treeReader->UseBranch("Track");
24+
auto particles = treeReader->UseBranch("Particle");
25+
26+
// TOF layer
27+
o2::delphes::TOFLayer toflayer;
28+
toflayer.setup(tof_radius, tof_length, tof_sigmat);
29+
toflayer.setType(o2::delphes::TOFLayer::kForward);
30+
toflayer.setRadiusIn(10.);
31+
32+
// smearer
33+
o2::delphes::TrackSmearer smearer;
34+
smearer.useEfficiency(true);
35+
smearer.loadTable(11, "lutCovm.el.dat");
36+
smearer.loadTable(13, "lutCovm.mu.dat");
37+
smearer.loadTable(211, "lutCovm.pi.dat");
38+
smearer.loadTable(321, "lutCovm.ka.dat");
39+
smearer.loadTable(2212, "lutCovm.pr.dat");
40+
41+
// logx binning
42+
const Int_t nbins = 80;
43+
double xmin = 1.e-2;
44+
double xmax = 1.e2;
45+
double logxmin = std::log10(xmin);
46+
double logxmax = std::log10(xmax);
47+
double binwidth = (logxmax - logxmin) / nbins;
48+
double xbins[nbins + 1];
49+
xbins[0] = xmin;
50+
for (Int_t i = 1; i <= nbins; ++i)
51+
xbins[i] = xmin + std::pow(10., logxmin + i * binwidth);
52+
53+
// histograms
54+
auto hTime0 = new TH1F("hTime0", ";t_{0} (ns)", 1000, -1., 1.);
55+
auto hBetaP = new TH2F("hBetaP", ";#it{p} (GeV/#it{c});#beta", nbins, xbins, 1000, 0.1, 1.1);
56+
TH2 *hNsigmaP[5];
57+
const char *pname[5] = {"el", "mu", "pi", "ka", "pr"};
58+
const char *plabel[5] = {"e", "#mu", "#pi", "K", "p"};
59+
for (int i = 0; i < 5; ++i)
60+
hNsigmaP[i] = new TH2F(Form("hNsigmaP_%s", pname[i]), Form("#it{p} (GeV/#it{c});n#sigma_{%s}", plabel[i]), nbins, xbins, 200, -10., 10.);
61+
62+
for (Int_t ientry = 0; ientry < numberOfEntries; ++ientry) {
63+
64+
// Load selected branches with data from specified event
65+
treeReader->ReadEntry(ientry);
66+
67+
// loop over tracks, smear and store TOF tracks
68+
std::vector<Track *> tof_tracks;
69+
for (Int_t itrack = 0; itrack < tracks->GetEntries(); ++itrack) {
70+
71+
// get track and corresponding particle
72+
auto track = (Track *)tracks->At(itrack);
73+
auto particle = (GenParticle *)track->Particle.GetObject();
74+
75+
// smear track
76+
if (!smearer.smearTrack(*track)) continue;
77+
78+
// select primaries based on 3 sigma DCA cuts
79+
if (fabs(track->D0 / track->ErrorD0) > 3.) continue;
80+
if (fabs(track->DZ / track->ErrorDZ) > 3.) continue;
81+
82+
// check if has TOF
83+
if (!toflayer.hasTOF(*track)) continue;
84+
85+
// push track
86+
tof_tracks.push_back(track);
87+
88+
}
89+
90+
// compute the event time
91+
std::array<float, 2> tzero;
92+
toflayer.eventTime(tof_tracks, tzero);
93+
hTime0->Fill(tzero[0]);
94+
95+
// loop over tracks and do PID
96+
for (auto track : tof_tracks) {
97+
98+
// fill beta-p
99+
auto p = track->P;
100+
auto beta = toflayer.getBeta(*track);
101+
hBetaP->Fill(p, beta);
102+
103+
// fill nsigma
104+
std::array<float, 5> deltat, nsigma;
105+
toflayer.makePID(*track, deltat, nsigma);
106+
for (int i = 0; i < 5; ++i)
107+
hNsigmaP[i]->Fill(p, nsigma[i]);
108+
109+
}
110+
}
111+
112+
auto fout = TFile::Open(outputFile, "RECREATE");
113+
hTime0->Write();
114+
hBetaP->Write();
115+
for (int i = 0; i < 5; ++i)
116+
hNsigmaP[i]->Write();
117+
fout->Close();
118+
119+
}

src/TOFLayer.cc

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,15 @@ TOFLayer::hasTOF(const Track &track)
2727
auto x = track.XOuter * 0.1; // [cm]
2828
auto y = track.YOuter * 0.1; // [cm]
2929
auto z = track.ZOuter * 0.1; // [cm]
30-
return (fabs(hypot(x, y) - mRadius) < 0.001 && fabs(z) < mLength);
30+
if (mType == kBarrel) {
31+
auto r = hypot(x, y);
32+
return fabs(r - mRadius) < 0.001 && fabs(z) < mLength);
33+
}
34+
if (mType = kForward) {
35+
auto r = hypot(x, y)
36+
return (r > mRadiusIn) && (r < mRadius) && (fabs(fabs(z) - mLength) < 0.001);
37+
}
38+
return false;
3139
}
3240

3341
/*****************************************************************/

src/TOFLayer.hh

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,22 @@ public:
1717
TOFLayer() = default;
1818
~TOFLayer() = default;
1919

20-
void setup(float radius, float length, float sigmat);
20+
enum { kBarrel, kForward }; // type of TOF detector
21+
22+
void setup(float radius, float length, float sigmat);
2123
bool hasTOF(const Track &track);
2224
float getBeta(const Track &track);
2325
void makePID(const Track &track, std::array<float, 5> &deltat, std::array<float, 5> &nsigma);
2426
bool eventTime(std::vector<Track *> &tracks, std::array<float, 2> &tzero);
27+
28+
void setType(int val) { mType = val; };
29+
void setRadiusIn(float val) { mRadiusIn = val; };
2530

2631
protected:
27-
32+
33+
int mType = kBarrel;
2834
float mRadius = 100.; // [cm]
35+
float mRadiusIn = 10.; // [cm]
2936
float mLength = 200.; // [cm]
3037
float mSigmaT = 0.02; // [ns]
3138

0 commit comments

Comments
 (0)