Hall A ROOT/C++ Analyzer (podd)
Loading...
Searching...
No Matches
SimDecoder.cxx
Go to the documentation of this file.
1
2//
3// Podd::SimDecoder
4//
5// Generic simulation decoder interface
6//
8
9#include "SimDecoder.h"
10#include "THaVarList.h"
11#include "THaGlobals.h"
12#include <iostream>
13#include <algorithm>
14
15using namespace std;
16
17namespace Podd {
18
19// Prefix of our own global variables (MC truth data)
20const char* const MC_PREFIX = "MC.";
21
22// Default half-size of search window for reconstructed hits (m)
24
25//_____________________________________________________________________________
27 fWeight{1.0},
28 fMCHits{nullptr},
29 fMCTracks{nullptr},
30 fMCPoints{new TClonesArray("Podd::MCTrackPoint", 50)},
31 fIsSetup{false}
32{
33 // Constructor. Derived classes must allocate the track and hit
34 // TClonesArrays using their respective hit and track classes
35
36 const char* const here = "SimDecoder::SimDecoder";
37
38 // Register standard global variables for event header data
39 // (It is up to the actual implementation of SimDecoder to fill these)
40 if( gHaVars ) {
41 VarDef vars[] = {
42 { "runnum", "Run number", kInt, 0, &run_num },
43 { "runtype", "CODA run type", kInt, 0, &run_type },
44 { "runtime", "CODA run time", kULong, 0, &fRunTime },
45 { "evnum", "Event number", kInt, 0, &event_num },
46 { "evtyp", "Event type", kInt, 0, &event_type },
47 { "evlen", "Event Length", kInt, 0, &event_length },
48 { "evtime", "Event time", kULong, 0, &evt_time },
49 { nullptr }
50 };
51 TString prefix("g");
52 // Prevent global variable clash if there are several instances of us
53 if( fInstance > 1 )
54 prefix.Append(Form("%d",fInstance));
55 prefix.Append(".");
56 gHaVars->DefineVariables( vars, prefix, here );
57 } else
58 Warning(here,"No global variable list found. Variables not registered.");
59}
60
61//_____________________________________________________________________________
63{
64 // Destructor. Derived classes must either not delete their TClonesArrays or
65 // delete them and set the pointers to zero (using SafeDelete, for example),
66 // else we may double-delete.
67
71
72 // Unregister global variables registered in the constructor
73 if( gHaVars ) {
74 TString prefix("g");
75 if( fInstance > 1 )
76 prefix.Append(Form("%d",fInstance));
77 prefix.Append(".*");
78 gHaVars->RemoveRegexp( prefix );
79 }
80}
81
82//_____________________________________________________________________________
84{
85 // Clear the TClonesArrays, assuming their elements do not allocate any
86 // memory. If they do, derived classes must override this function
87 // to call either Clear("C") or Delete().
88
90
91 if( fMCHits )
92 fMCHits->Clear(opt);
93 if( fMCTracks )
94 fMCTracks->Clear(opt);
96}
97
98//_____________________________________________________________________________
100 Int_t /*chan*/ ) const
101{
102 // Return MCHitInfo for the given digitized hardware channel.
103 // This is a dummy function that derived classes should override if they
104 // need this functionality.
105
106 return MCHitInfo();
107}
108
109//_____________________________________________________________________________
111{
112 // Define generic global variables. Derived classes may override or extend
113 // this function. It is not automatically called.
114
115 const char* const here = "SimDecoder::DefineVariables";
116
120
121 RVarDef vars[] = {
122 // Event info
123 { "weight", "Event weight", "fWeight" },
124 // Generated hit and track info. Just report the sizes of the arrays.
125 // Anything beyond this requires the type of the actual hit and
126 // track classes.
127 { "tr.n", "Number of MC tracks", "GetNMCTracks()" },
128 { "hit.n", "Number of MC hits", "GetNMCHits()" },
129 // MCTrackPoints
130 { "pt.n", "Number of MC track points",
131 "GetNMCPoints()" },
132 { "pt.plane", "Plane number",
133 "fMCPoints.Podd::MCTrackPoint.fPlane" },
134 { "pt.type", "Plane type",
135 "fMCPoints.Podd::MCTrackPoint.fType" },
136 { "pt.status", "Reconstruction status",
137 "fMCPoints.Podd::MCTrackPoint.fStatus" },
138 { "pt.nfound", "# reconstructed hits found near this point",
139 "fMCPoints.Podd::MCTrackPoint.fNFound" },
140 { "pt.clustsz", "Size of closest reconstructed cluster",
141 "fMCPoints.Podd::MCTrackPoint.fClustSize" },
142 { "pt.time", "Track arrival time [s]",
143 "fMCPoints.Podd::MCTrackPoint.fMCTime" },
144 { "pt.p", "Track momentum [GeV]",
145 "fMCPoints.Podd::MCTrackPoint.P() "},
146 // MC point positions in Cartesian/TRANSPORT coordinates
147 { "pt.x", "Track pos lab x [m]",
148 "fMCPoints.Podd::MCTrackPoint.X()" },
149 { "pt.y", "Track pos lab y [m]",
150 "fMCPoints.Podd::MCTrackPoint.Y()" },
151 { "pt.th", "Track dir tan(theta)",
152 "fMCPoints.Podd::MCTrackPoint.ThetaT()" },
153 { "pt.ph", "Track dir tan(phi)",
154 "fMCPoints.Podd::MCTrackPoint.PhiT()" },
155 // MC point positions and directions in cylindrical/spherical coordinates
156 { "pt.r", "Track pos lab r_trans [m]",
157 "fMCPoints.Podd::MCTrackPoint.R()" },
158 { "pt.theta", "Track pos lab theta [rad]",
159 "fMCPoints.Podd::MCTrackPoint.Theta()" },
160 { "pt.phi", "Track pos lab phi [rad]",
161 "fMCPoints.Podd::MCTrackPoint.Phi()" },
162 { "pt.thdir", "Track dir theta [rad]",
163 "fMCPoints.Podd::MCTrackPoint.ThetaDir()" },
164 { "pt.phdir", "Track dir phi [rad]",
165 "fMCPoints.Podd::MCTrackPoint.PhiDir()" },
166 // MC point analysis results
167 { "pt.deltaE", "Eloss wrt prev plane (GeV)",
168 "fMCPoints.Podd::MCTrackPoint.fDeltaE" },
169 { "pt.deflect","Deflection wrt prev plane (rad)",
170 "fMCPoints.Podd::MCTrackPoint.fDeflect" },
171 { "pt.tof", "Time-of-flight from prev plane (s)",
172 "fMCPoints.Podd::MCTrackPoint.fToF" },
173 { "pt.hitres", "Hit residual (mm)",
174 "fMCPoints.Podd::MCTrackPoint.fHitResid" },
175 { "pt.trkres", "Track residual (mm)",
176 "fMCPoints.Podd::MCTrackPoint.fTrackResid" },
177 { nullptr }
178 };
179
182 mode, "", this, MC_PREFIX, here, "" );
183}
184
185//_____________________________________________________________________________
187 const TVector3& vertex, const TVector3& momentum )
188 : fNumber(number), fPID(pid), fOrigin(vertex),
189 fMomentum(momentum), fNHits(0), fHitBits(0), fNHitsFound(0), fFoundBits(0),
190 fReconFlags(0), fContamFlags(0), fMatchval(kBig), fFitRank(-1),
191 fTrackRank(-1), fMCFitPar{}, fRcFitPar{}
192{
193 fill_n( fMCFitPar, NFP, kBig );
194 fill_n( fRcFitPar, NFP, kBig );
195}
196
197//_____________________________________________________________________________
199 : fNumber(0), fPID(0), fNHits(0), fHitBits(0), fNHitsFound(0),
200 fFoundBits(0), fReconFlags(0), fContamFlags(0), fMatchval(kBig),
201 fFitRank(-1), fTrackRank(-1), fMCFitPar{}, fRcFitPar{}
202{
203 fill_n( fMCFitPar, NFP, kBig );
204 fill_n( fRcFitPar, NFP, kBig );
205}
206
207//_____________________________________________________________________________
208void MCTrack::Print( const Option_t* /*opt*/ ) const
209{
210 // Print MCTrack info
211
212 cout << "track: num = " << fNumber
213 << ", PID = " << fPID
214 << endl;
215 cout << " Origin = "; fOrigin.Print();
216 cout << " Momentum = "; fMomentum.Print();
217}
218
219//_____________________________________________________________________________
221{
222 // Print MC digitized hit info
223
224 cout << " MCtrack = " << fMCTrack
225 << ", MCpos = " << fMCPos
226 << ", MCtime = " << fMCTime
227 << ", num_bg = " << fContam
228 << endl;
229}
230
231//_____________________________________________________________________________
233{
234 // Sorting function for MCTrackPoints. Orders by fType, then fPlane.
235 // Returns -1 if this is smaller than rhs, 0 if equal, +1 if greater.
236
237 assert( dynamic_cast<const MCTrackPoint*>(obj) );
238 const auto* rhs = static_cast<const MCTrackPoint*>(obj);
239
240 if( fType < rhs->fType ) return -1;
241 if( fType > rhs->fType ) return 1;
242 if( fPlane < rhs->fPlane ) return -1;
243 if( fPlane > rhs->fPlane ) return 1;
244 return 0;
245}
246
247//_____________________________________________________________________________
249{
250 // Print MC track point info
251
252 cout << " MCtrack = " << fMCTrack
253 << ", plane = " << fPlane
254 << ", plane_type = " << fType
255 << ", status = " << fStatus << endl
256 << " coord = "; fMCPoint.Print();
257 cout << " P = "; fMCP.Print();
258 cout << " time = " << fMCTime << " s"
259 << ", deltaE = " << fDeltaE << " GeV"
260 << ", deflect = " << 1e3*fDeflect << " mrad"
261 << ", tof = " << 1e9*fToF << " ns"
262 << ", hit_resid = " << 1e3*fHitResid << " mm"
263 << ", trk_resid = " << 1e3*fTrackResid << " mm"
264 << endl;
265}
266
268
269} // end namespace Podd
270
int Int_t
const Data_t kBig
Definition DataType.h:15
#define SafeDelete(p)
#define e(i)
double Double_t
const char Option_t
Option_t Option_t TPoint TPoint const char mode
R__EXTERN class THaVarList * gHaVars
Definition THaGlobals.h:11
static const char *const here
Definition THaVar.cxx:64
char * Form(const char *fmt,...)
Double_t fMCTime
Definition SimDecoder.h:95
void MCPrint() const
Double_t fMCPos
Definition SimDecoder.h:94
static Double_t fgWindowSize
Definition SimDecoder.h:157
virtual Int_t Compare(const TObject *obj) const
virtual void Print(Option_t *opt) const
TVector3 fOrigin
Definition SimDecoder.h:49
Double_t fRcFitPar[NFP]
Definition SimDecoder.h:68
virtual void Print(const Option_t *opt="") const
static const Int_t NFP
Definition SimDecoder.h:66
Double_t fMCFitPar[NFP]
Definition SimDecoder.h:67
TVector3 fMomentum
Definition SimDecoder.h:50
virtual ~SimDecoder()
virtual void Clear(Option_t *opt="")
TClonesArray * fMCTracks
Definition SimDecoder.h:201
virtual MCHitInfo GetMCHitInfo(Int_t crate, Int_t slot, Int_t chan) const
TClonesArray * fMCPoints
Definition SimDecoder.h:202
TClonesArray * fMCHits
Definition SimDecoder.h:200
virtual Int_t DefineVariables(THaAnalysisObject::EMode mode=THaAnalysisObject::kDefine)
void Clear(Option_t *option="") override
static Int_t DefineVarsFromList(const void *list, EType type, EMode mode, const char *def_prefix, const TObject *obj, const char *prefix, const char *here, const char *comment_subst="")
UInt_t run_num
Definition THaEvData.h:206
UInt_t run_type
Definition THaEvData.h:207
ULong64_t fRunTime
Definition THaEvData.h:209
UInt_t event_type
Definition THaEvData.h:206
ULong64_t evt_time
Definition THaEvData.h:210
UInt_t fInstance
Definition THaEvData.h:218
UInt_t event_length
Definition THaEvData.h:206
UInt_t event_num
Definition THaEvData.h:206
virtual Int_t RemoveRegexp(const char *expr, Bool_t wildcard=true)
virtual Int_t DefineVariables(const VarDef *list, const char *prefix="", const char *caller="")
virtual void Clear(Option_t *="")
virtual void Warning(const char *method, const char *msgfmt,...) const
TString & Append(char c, Ssiz_t rep=1)
void Print(Option_t *option="") const override
const char *const MC_PREFIX
STL namespace.
ClassImp(TPyArg)
double * vertex