Hall A ROOT/C++ Analyzer (podd)
Loading...
Searching...
No Matches
THaTotalShower.cxx
Go to the documentation of this file.
1
2// //
3// THaTotalShower //
4// //
5// A total shower counter, consisting of a shower and a preshower. //
6// Calculates the total energy deposited in Shower+Preshower. //
7// //
9
10#include "THaTotalShower.h"
11#include "THaShower.h"
12#include "VarType.h"
13#include "VarDef.h"
14#include "TMath.h"
15#include <string>
16
17class THaEvData;
18class TClonesArray;
19class TDatime;
20
21using namespace std;
22
24
25//_____________________________________________________________________________
26THaTotalShower::THaTotalShower( const char* name, const char* description,
27 THaApparatus* apparatus ) :
28 THaPidDetector(name,description,apparatus),
29 fShower(nullptr), fPreShower(nullptr), fMaxDx(0.0), fMaxDy(0.0),
30 fE(kBig), fID(-1)
31{
32 // Constructor. With this method, the subdetectors are created using
33 // this detector's prefix followed by "sh" and "ps", respectively,
34 // and variable names like "L.ts.sh.nhits".
35
36 Setup( name, "sh", "ps", description, apparatus, true );
37}
38
39//_____________________________________________________________________________
41 const char* shower_name,
42 const char* preshower_name,
43 const char* description,
44 THaApparatus* apparatus ) :
45 THaPidDetector(name,description,apparatus),
46 fShower(nullptr), fPreShower(nullptr), fMaxDx(0.0), fMaxDy(0.0),
47 fE(kBig), fID(-1)
48{
49 // Constructor. With this method, the subdetectors are created using
50 // the given names 'shower_name' and 'preshower_name', and variable
51 // names like "L.sh.nhits".
52
53 Setup( name, shower_name, preshower_name, description, apparatus, false );
54}
55
56//_____________________________________________________________________________
57void THaTotalShower::Setup( const char* name,
58 const char* shower_name,
59 const char* preshower_name,
60 const char* description,
61 THaApparatus* apparatus,
62 bool subnames )
63{
64 // Set up the total shower counter. Called by constructor.
65
66 static const char* const here = "Setup()";
67 static const char* const message =
68 "Must construct %s detector with valid name! Object construction failed.";
69
70 // Base class constructor failed?
71 if( IsZombie()) return;
72
73 if( !shower_name || !*shower_name ) {
74 Error( Here(here), message, "shower" );
75 MakeZombie();
76 return;
77 }
78 if( !preshower_name || !*preshower_name ) {
79 Error( Here(here), message, "preshower" );
80 MakeZombie();
81 return;
82 }
83
84 string sname, psname;
85 if( subnames ) {
86 sname = string(name) + "." + shower_name;
87 psname = string(name) + "." + preshower_name;
88 } else {
89 sname = shower_name;
90 psname = preshower_name;
91 }
92
93 if( !description || !*description ) {
94 description = "Total shower counter";
95 SetTitle( description );
96 }
97 string desc(description), sdesc(desc), psdesc(desc);
98 sdesc.append(" shower subdetector" );
99 psdesc.append(" preshower subdetector");
100
101 fShower = new THaShower( sname.c_str(), sdesc.c_str(), apparatus );
102 if( !fShower || fShower->IsZombie() ) {
103 MakeZombie();
104 return;
105 }
106 fPreShower = new THaShower( psname.c_str(), psdesc.c_str(), apparatus );
107 if( !fPreShower || fPreShower->IsZombie() ) {
108 MakeZombie();
109 return;
110 }
111}
112
113//_____________________________________________________________________________
115{
116 // Destructor. Remove variables from global list.
117
118 delete fPreShower;
119 delete fShower;
121}
122
123//_____________________________________________________________________________
125{
126 // Set up total shower counter. This function
127 // reads the total shower parameters from a local database file
128 // (e.g. "db_ts.dat"), then calls Init() for
129 // the shower and preshower subdetectors, respectively.
130
131 if( IsZombie() || !fShower || !fPreShower )
132 return fStatus = kInitError;
133
134 if( (fStatus = THaPidDetector::Init(run_time )) ||
135 (fStatus = fShower->Init(run_time )) ||
136 (fStatus = fPreShower->Init(run_time )) )
137 return fStatus;
138
139 return fStatus = kOK;
140}
141
142//_____________________________________________________________________________
144{
145 // Clear event data
146
148 fE = kBig;
149 fID = -1;
150}
151
152//_____________________________________________________________________________
154{
155 // Read this detector's parameters from the database.
156 // 'date' contains the date/time of the run being analyzed.
157
158 FILE* fi = OpenFile( date );
159 if( !fi ) return kFileError;
160
161 // Read configuration parameters
162 Double_t dxdy[2];
163 DBRequest request[] = {
164 { "max_dxdy", dxdy, kDouble, 2 },
165 { nullptr }
166 };
167 Int_t err = LoadDB( fi, date, request, fPrefix );
168 fclose(fi);
169 if( err )
170 return err;
171
172 fMaxDx = dxdy[0];
173 fMaxDy = dxdy[1];
174
175 fIsInit = true;
176 return kOK;
177}
178
179//_____________________________________________________________________________
181{
182 // Initialize global variables and lookup table for decoder
183
184 // Register global variables
185
186 RVarDef vars[] = {
187 { "e", "Energy (MeV) of largest cluster", "fE" },
188 { "id", "ID of Psh&Sh coincidence (1==good)", "fID" },
189 { nullptr }
190 };
191 return DefineVarsFromList( vars, mode );
192}
193
194//_____________________________________________________________________________
196{
197 // Decode total shower detector. Calls Decode() of fPreShower and fShower.
198 // Return the return value of fShower->Decode().
199
200 if( !IsOK() )
201 return -1;
202
203 fPreShower->Decode( evdata );
204 return fShower->Decode( evdata );
205}
206
207//_____________________________________________________________________________
209{
210 // Reconstruct Clusters in shower and preshower detectors.
211 // Then compute total shower energy and cluster ID.
212 //
213 // Valid fIDs:
214 // 1 Matching clusters found.
215 // 0 Clusters found, but separated too far
216 // -1 No cluster found in either shower or preshower or both
217 //
218
219 if( !IsOK() )
220 return -1;
221
224
225 if( fShower->GetNhits() == 0 || fPreShower->GetNhits() == 0 )
226 fID = -1;
227 else {
228 fE = fShower->GetE() + fPreShower->GetE();
229 Data_t dx = fPreShower->GetX() - fShower->GetX();
230 Data_t dy = fPreShower->GetY() - fShower->GetY();
231 if( TMath::Abs(dx) < fMaxDx && TMath::Abs(dy) < fMaxDy )
232 fID = 1;
233 }
234 return 0;
235}
236//_____________________________________________________________________________
238{
239 // Fine processing.
240 // Call fPreShower->FineProcess() and fShower->FineProcess() in turn.
241 // Return return value of fShower->FineProcess().
242
243 if( !IsOK() )
244 return -1;
245
247 return fShower->FineProcess( tracks );
248}
249
250//_____________________________________________________________________________
252{
253 // Set the apparatus of this detector as well as the subdetectors
254
256 fShower->SetApparatus( app );
257 fPreShower->SetApparatus( app );
258}
259
#define kOK
Definition BdataLoc.cxx:40
#define kInitError
Definition BdataLoc.cxx:41
int Int_t
Double_t Data_t
Definition DataType.h:13
const Data_t kBig
Definition DataType.h:15
Int_t fID
double Double_t
const char Option_t
Option_t Option_t TPoint TPoint const char mode
char name[80]
static const char *const here
Definition THaVar.cxx:64
static Int_t LoadDB(FILE *file, const TDatime &date, const DBRequest *request, const char *prefix, Int_t search=0, const char *here="THaAnalysisObject::LoadDB")
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="")
virtual const char * Here(const char *) const
Bool_t IsOK() const
virtual FILE * OpenFile(const TDatime &date)
virtual Int_t Decode(const THaEvData &)
virtual void SetApparatus(THaApparatus *)
Data_t GetX() const
Definition THaShower.h:32
Data_t GetE() const
Definition THaShower.h:31
virtual Int_t FineProcess(TClonesArray &tracks)
Data_t GetY() const
Definition THaShower.h:33
UInt_t GetNhits() const
Definition THaShower.h:30
virtual Int_t CoarseProcess(TClonesArray &tracks)
virtual Int_t ReadDatabase(const TDatime &date)
virtual void Clear(Option_t *="")
virtual Int_t DefineVariables(EMode mode=kDefine)
virtual Int_t Decode(const THaEvData &)
virtual Int_t FineProcess(TClonesArray &tracks)
void Setup(const char *name, const char *desc, const char *shnam, const char *psnam, THaApparatus *app, bool mode)
THaShower * fShower
virtual void SetApparatus(THaApparatus *)
virtual Int_t CoarseProcess(TClonesArray &tracks)
THaShower * fPreShower
THaTotalShower(const char *name, const char *description="", THaApparatus *a=nullptr)
virtual ~THaTotalShower()
virtual void SetTitle(const char *title="")
void Clear(Option_t *option="") override
R__ALWAYS_INLINE Bool_t IsZombie() const
virtual void Error(const char *method, const char *msgfmt,...) const
void MakeZombie()
Double_t Abs(Double_t d)
STL namespace.
const char * Setup
ClassImp(TPyArg)
void tracks()