Hall A ROOT/C++ Analyzer (podd)
Loading...
Searching...
No Matches
THaS2CoincTime.cxx
Go to the documentation of this file.
1//*-- Author : Rob Feuerbach 9-Sep-03 */
2
4//
5// THaS2CoincTime
6//
7// Calculate coincidence time between tracks in two spectrometers.
8// Differs from THaCoincTime in that here the specific detectors to use
9// to get the time tracks in the spectrometers can be named.
10// The default is "s2".
11//
12// Loop through all combinations of tracks in the two spectrometers.
13// Here we assume that the time difference+fixed delay between the
14// common TDC starts is measured.
15//
17
18#include "TLorentzVector.h"
19#include "TMath.h"
20#include "THaS2CoincTime.h"
21#include "THaTrack.h"
22#include "THaDetMap.h"
23#include "THaSpectrometer.h"
24#include "THaEvData.h"
25#include "THaVarList.h"
26#include "THaGlobals.h"
27#include <vector>
28#include <cassert>
29
30using namespace std;
31
32//_____________________________________________________________________________
34 const char* description,
35 const char* spec1, const char* spec2,
36 Double_t m1, Double_t m2,
37 const char* ch_name1, const char* ch_name2,
38 const char* detname1, const char* detname2)
39 : THaCoincTime(name,description,spec1,spec2,m1,m2,ch_name1,ch_name2),
40 fTrPads1(nullptr), fS2TrPath1(nullptr), fS2Times1(nullptr), fTrPath1(nullptr),
41 fTrPads2(nullptr), fS2TrPath2(nullptr), fS2Times2(nullptr), fTrPath2(nullptr),
42 fDetName1(detname1)
43{
44 // To construct, specify the name of the module (usually "CT"),
45 // a description ("Coincidence time calculation between L and R HRS"),
46 // the FIRST and SECOND source of tracks ("L" and "R"),
47 // the MASSES in GeV/c^2 of the particles in FIRST and SECOND spectrometers.
48 //
49 // The rest of the parameters are usually not used.
50 //
51 // The next two are thes name of the TDC channels in the database for this
52 // object measuring the difference between the COMMON STARTS of the FIRST
53 // and SECOND spectrometers, such that:
54 //
55 // * ch_name1 measures COMMON_START<sub>2</sub> - COMMON_START<sub>1</sub>,
56 // * ch_name2 measures COMMON_START<sub>1</sub> - COMMON_START<sub>2</sub>.
57 //
58 // These default to "ct_(spec2 name)by(spec1 name)" and
59 // "ct_(spec1 name)by(spec2 name)", respectively.
60 //
61 // * detname1 is the name of the timing plane in the FIRST spectrometer to
62 // use to measure the time of the track in this spectrometer.
63 // * detname2 is likewise the name of the timing plane in the SECOND
64 // spectrometer. If not specified, detname1 is used.
65 //
66 // The default arguments are detname1="s2", and detname2 be assigned to
67 // match detname1.
68
69 if( detname2 && *detname2 ) {
70 fDetName2=detname2;
71 } else {
73 }
74}
75
76//_____________________________________________________________________________
78
79//_____________________________________________________________________________
81{
82 // Initialize the module. Grab the global variables containing the tracking
83 // results (including calculated pathlengths) and the times and pads from the
84 // THaScintillator planes.
85
86 // first do the standard initialization
88
89 if (stat != kOK) return stat;
90
91 if (!fSpect1 || !fSpect2) return kInitError;
92
93 fTrPads1 = gHaVars->Find(Form("%s.%s.trpad",fSpect1->GetName(),
94 fDetName1.Data()));
95 fS2TrPath1= gHaVars->Find(Form("%s.%s.trpath",fSpect1->GetName(),
96 fDetName1.Data()));
97 fS2Times1 = gHaVars->Find(Form("%s.%s.time",fSpect1->GetName(),
98 fDetName1.Data()));
99 fTrPath1 = gHaVars->Find(Form("%s.tr.pathl",fSpect1->GetName()));
100 if (!fTrPads1 || !fS2TrPath1 || !fS2Times1 || !fTrPath1) {
101 Error(Here("Init"),"Cannot get variables for spectrometer %s detector %s",
103 return kInitError;
104 }
105
106 fTrPads2 = gHaVars->Find(Form("%s.%s.trpad",fSpect2->GetName(),
107 fDetName2.Data()));
108 fS2TrPath2= gHaVars->Find(Form("%s.%s.trpath",fSpect2->GetName(),
109 fDetName2.Data()));
110 fS2Times2 = gHaVars->Find(Form("%s.%s.time",fSpect2->GetName(),
111 fDetName2.Data()));
112 fTrPath2 = gHaVars->Find(Form("%s.tr.pathl",fSpect2->GetName()));
113
114 if (!fTrPads2 || !fS2TrPath2 || !fS2Times2 || !fTrPath2) {
115 Error(Here("Init"),"Cannot get variables for spectrometer %s detector %s",
117 return kInitError;
118 }
119
120 return kOK;
121}
122
123//_____________________________________________________________________________
125{
126 // Read in coincidence TDC's, calculate the time of the tracks at the
127 // target vertex, and then assemble the time-difference between when the
128 // tracks left the target for every possible combination.
129
130 if( !IsOK() ) return -1;
131
132 if (!fDetMap) return -1;
133
134 // read in the two relevant channels
135 // Use of the logical channel number ensures matching of the TDC with
136 // the correct difference (1by2 vs 2by1)
137 for ( UInt_t i=0; i < fDetMap->GetSize(); i++ ) {
138 THaDetMap::Module* d = fDetMap->GetModule(i);
139 if (fTdcRes[d->first] != 0.) {
140 // grab only the first hit in a TDC
141 if( evdata.GetNumHits(d->crate, d->slot, d->lo) > 0 ) {
142 fTdcData[d->first] =
143 evdata.GetData(d->crate, d->slot, d->lo, 0) * fTdcRes[d->first]
144 - fTdcOff[d->first];
145 }
146 }
147 }
148
149 // Calculate the time at the vertex (relative to the trigger time)
150 // for each track in each spectrometer
151 // Use the Beta of the assumed particle type.
152 class Spec_short {
153 public:
154 THaSpectrometer* Sp;
155 vector<Double_t>& Vxtime;
156 Double_t Mass;
157 THaVar* trpads;
158 THaVar* s2trpath;
159 THaVar* s2times;
160 THaVar* trpath;
161 };
162
163 const vector<Spec_short> SpList = {
166 };
167
168 for( const auto& sp : SpList ) {
169 Int_t Ntr = sp.Sp->GetNTracks();
170 if( Ntr <= 0) continue; // no tracks, skip
171
172 TClonesArray* tracks = sp.Sp->GetTracks();
173 THaVar* tr_pads = sp.trpads;
174 THaVar* s2trpath = sp.s2trpath;
175 THaVar* s2times = sp.s2times;
176 THaVar* trpath = sp.trpath;
177
178 if (!tr_pads || !s2trpath || !s2times || !trpath) continue;
179
180 for ( Int_t i=0; i<Ntr; i++ ) {
181 assert(sp.Vxtime.empty()); // else Clear() not called in order
182 auto* tr = dynamic_cast<THaTrack*>(tracks->At(i));
183 // this should be safe to assume -- only THaTrack's go into the tracks array
184 if( !tr ) {
185 Warning(Here("Process"),"non-THaTrack in %s's tracks array at %d.",
186 sp.Sp->GetName(),i);
187 continue;
188 }
189 // get time of the track at S2
190 Double_t p = tr->GetP();
191 if( p > 0. ) {
192 int pad = static_cast<int>(tr_pads->GetValue(i));
193 if( pad < 0 ) {
194 // Using (i+1)*kBig prevents differences of large numbers to be zero
195 sp.Vxtime.push_back((i + 1) * kBig);
196 continue;
197 }
198 Double_t s2t = s2times->GetValue(pad);
199
200 Double_t beta = p / TMath::Sqrt(p * p + sp.Mass * sp.Mass);
201 Double_t c = TMath::C();
202 sp.Vxtime.push_back(
203 s2t - (trpath->GetValue(i) + s2trpath->GetValue(i)) / (beta * c)
204 );
205 } else {
206 sp.Vxtime.push_back((i + 1) * kBig);
207 }
208 }
209 }
210
211 // now, we have the vertex times -- go through the combinations
212
213 // Take the tracks and the coincidence TDC and construct
214 // the coincidence time
215 assert(fTimeCombos.empty()); // else Clear() not called in order
216 for( size_t i = 0; i < fVxTime1.size(); i++ ) {
217 for( size_t j = 0; j < fVxTime2.size(); j++ ) {
218 fTimeCombos.emplace_back( i, j,
219 fVxTime2[j] - fVxTime1[i] + fTdcData[0],
220 fVxTime1[i] - fVxTime2[j] + fTdcData[1]
221 );
222 }
223 }
224
225 fDataValid = true;
226 return 0;
227}
228
230
231
int Int_t
unsigned int UInt_t
const Data_t kBig
Definition DataType.h:15
#define d(i)
#define c(i)
double Double_t
winID h TVirtualViewer3D TVirtualGLPainter p
char name[80]
R__EXTERN class THaVarList * gHaVars
Definition THaGlobals.h:11
char * Form(const char *fmt,...)
virtual const char * Here(const char *) const
Bool_t IsOK() const
THaSpectrometer * fSpect2
std::vector< Double_t > fVxTime2
Double_t fTdcRes[2]
Double_t fTdcOff[2]
std::vector< TimeCombo > fTimeCombos
std::unique_ptr< THaDetMap > fDetMap
Double_t fpmass2
Double_t fpmass1
THaSpectrometer * fSpect1
std::vector< Double_t > fVxTime1
Double_t fTdcData[2]
UInt_t GetNumHits(UInt_t crate, UInt_t slot, UInt_t chan) const
Definition THaEvData.h:264
UInt_t GetData(UInt_t crate, UInt_t slot, UInt_t chan, UInt_t hit) const
Definition THaEvData.h:273
virtual Int_t Process(const THaEvData &)
virtual ~THaS2CoincTime()
THaS2CoincTime(const char *name, const char *description, const char *spec1="L", const char *spec2="R", Double_t mass1=.938272, Double_t mass2=0.000511, const char *ch_name1=nullptr, const char *ch_name2=nullptr, const char *detname1="s2", const char *detname2="")
THaVar * fS2TrPath2
THaVar * fS2TrPath1
virtual THaVar * Find(const char *name) const
Double_t GetValue(Int_t i=0) const
Definition THaVar.h:48
const char * GetName() const override
virtual void Warning(const char *method, const char *msgfmt,...) const
virtual void Error(const char *method, const char *msgfmt,...) const
const char * Data() const
double beta(double x, double y)
constexpr Double_t C()
Double_t Sqrt(Double_t x)
STL namespace.
ClassImp(TPyArg)
void tracks()