Neutral Particle Spectrometer analysis code
Loading...
Searching...
No Matches
THcNPSAnalyzer.cxx
Go to the documentation of this file.
1
12#include "THcNPSAnalyzer.h"
13#include "THcAnalyzer.h"
14#include "THaAnalyzer.h"
15#include "THaRunBase.h"
16#include "THaEvent.h"
17#include "THaOutput.h"
18#include "THaSpectrometer.h"
19#include "THaPhysicsModule.h"
20#include "InterStageModule.h"
21#include "THaBenchmark.h"
22
23#include <iostream>
24#include <iomanip>
25#include <exception>
26#include <stdexcept>
27#include <vector>
28
29using namespace std;
30
31
32// Pointer to single instance of this object
33//THcNPSAnalyzer* THcNPSAnalyzer::fgAnalyzer = 0;
34
35//FIXME:
36// do we need to "close" scalers/EPICS analysis if we reach the event limit?
37
38//_____________________________________________________________________________
43
44//_____________________________________________________________________________
46{
47 // Destructor.
48
49}
50
51//_____________________________________________________________________________
53{
54 // Analysis of physics events
55
56 static const char* const here = "PhysicsAnalysis";
57
58 // Don't analyze events that did not pass RawDecode cuts
59 if( code != kOK )
60 return code;
61
62 //--- Skip physics events until we reach the first requested event
63 if( fNev < fRun->GetFirstEvent() )
64 return kSkip;
65
66 if( fFirstPhysics ) {
67 fFirstPhysics = false;
68 if( fVerbose>2 )
69 cout << "Starting physics analysis at event " << GetCount(kNevPhysics)
70 << endl;
71 }
72 // Update counters
75
76 //--- Process all apparatuses that are defined in fApps
77 // First Decode(), then Reconstruct()
78
79 const char* stage = "";
80 THaAnalysisObject* obj = nullptr; // current module, for exception error message
81
82 try {
83 stage = "Decode";
84 if( fDoBench ) fBench->Begin(stage);
85 for( auto* mod : fAnalysisModules ) {
86 obj = mod;
87 if(GetClearThisEvent()) // clear only after merging fNevMerge events
88 mod->Clear();
89 }
90 for( auto* app : fApps ) {
91 obj = app;
92 app->Decode(*fEvData);
93 }
94 for( auto* mod : fInterStage ) {
95 if( mod->GetStage() == kDecode ) {
96 obj = mod;
97 mod->Process(*fEvData);
98 }
99 }
100 if( fDoBench ) fBench->Stop(stage);
101 if( !EvalStage(kDecode) ) return kSkip;
102
103 //--- Main physics analysis. Calls the following for each defined apparatus
104 // THaSpectrometer::CoarseTrack (only for spectrometers)
105 // THaApparatus::CoarseReconstruct
106 // THaSpectrometer::Track (only for spectrometers)
107 // THaApparatus::Reconstruct
108 //
109 // Test blocks are evaluated after each of these stages
110
111
112 if(! GetProcessThisEvent()) // Only process every fNevMerge events
113 return kSkip;
114 //-- Coarse processing
115
116 stage = "CoarseTracking";
117 if( fDoBench ) fBench->Begin(stage);
118 for( auto* spectro : fSpectrometers ) {
119 obj = spectro;
120 spectro->CoarseTrack();
121 }
122 for( auto* mod : fInterStage ) {
123 if( mod->GetStage() == kCoarseTrack ) {
124 obj = mod;
125 mod->Process(*fEvData);
126 }
127 }
128 if( fDoBench ) fBench->Stop(stage);
129 if( !EvalStage(kCoarseTrack) ) return kSkip;
130
131
132 stage = "CoarseReconstruct";
133 if( fDoBench ) fBench->Begin(stage);
134 for( auto* app : fApps ) {
135 obj = app;
136 app->CoarseReconstruct();
137 }
138 for( auto* mod : fInterStage ) {
139 if( mod->GetStage() == kCoarseRecon ) {
140 obj = mod;
141 mod->Process(*fEvData);
142 }
143 }
144 if( fDoBench ) fBench->Stop(stage);
145 if( !EvalStage(kCoarseRecon) ) return kSkip;
146
147 //-- Fine (Full) Reconstruct().
148
149 stage = "Tracking";
150 if( fDoBench ) fBench->Begin(stage);
151 for( auto* spectro : fSpectrometers ) {
152 obj = spectro;
153 spectro->Track();
154 }
155 for( auto* mod : fInterStage ) {
156 if( mod->GetStage() == kTracking ) {
157 obj = mod;
158 mod->Process(*fEvData);
159 }
160 }
161 if( fDoBench ) fBench->Stop(stage);
162 if( !EvalStage(kTracking) ) return kSkip;
163
164
165 stage = "Reconstruct";
166 if( fDoBench ) fBench->Begin(stage);
167 for( auto* app : fApps ) {
168 obj = app;
169 app->Reconstruct();
170 }
171 for( auto* mod : fInterStage ) {
172 if( mod->GetStage() == kReconstruct ) {
173 obj = mod;
174 mod->Process(*fEvData);
175 }
176 }
177 if( fDoBench ) fBench->Stop(stage);
178 if( !EvalStage(kReconstruct) ) return kSkip;
179
180 //--- Process the list of physics modules
181
182 stage = "Physics";
183 if( fDoBench ) fBench->Begin(stage);
184 for( auto* physmod : fPhysics ) {
185 obj = physmod;
186 Int_t err = physmod->Process( *fEvData );
188 code = kTerminate;
189 else if( err == THaPhysicsModule::kFatal ) {
190 code = kFatal;
191 break;
192 }
193 }
194 for( auto* mod : fInterStage ) {
195 if( mod->GetStage() == kPhysics ) {
196 obj = mod;
197 mod->Process(*fEvData);
198 }
199 }
200 if( fDoBench ) fBench->Stop(stage);
201 if( code == kFatal ) return kFatal;
202
203 //--- Evaluate "Physics" test block
204
205 if( !EvalStage(kPhysics) )
206 // any status code form the physics analysis overrides skip code
207 return (code == kOK) ? kSkip : code;
208
209 } // end try
210 catch( exception& e ) {
211 TString module_name = (obj != nullptr) ? obj->GetName() : "unknown";
212 TString module_desc = (obj != nullptr) ? obj->GetTitle() : "unknown";
213 Error( here, "Caught exception %s in module %s (%s) during %s analysis "
214 "stage. Terminating analysis.", e.what(), module_name.Data(),
215 module_desc.Data(), stage );
216 if( fDoBench ) fBench->Stop(stage);
217 code = kFatal;
218 goto errexit;
219 }
220
221 //--- Process output
222 if( fDoBench ) fBench->Begin("Output");
223 try {
224 //--- If Event defined, fill it.
225 if( fEvent ) {
231 0,
232 fRun->GetNumber()
233 );
234 fEvent->Fill();
235 }
236 // Write to output file
237 if( fOutput ) fOutput->Process();
238 }
239 catch( exception& e ) {
240 Error( here, "Caught exception %s during output of event %u. "
241 "Terminating analysis.", e.what(), fNev );
242 code = kFatal;
243 }
244 if( fDoBench ) fBench->Stop("Output");
245
246 errexit:
247 return code;
248}
249
251
int Int_t
#define e(i)
ClassImp(VDC::AnalyticTTDConv) using namespace std
virtual void Stop(const char *name)
virtual void Clear(Option_t *="")
THaBenchmark * fBench
virtual bool EvalStage(int n)
UInt_t GetCount(Int_t which) const
std::vector< THaApparatus * > fApps
Bool_t fFirstPhysics
std::vector< THaAnalysisObject * > fAnalysisModules
THaEvData * fEvData
THaEvent * fEvent
UInt_t Incr(Int_t which)
std::vector< THaPhysicsModule * > fPhysics
Bool_t fDoBench
THaOutput * fOutput
THaRunBase * fRun
std::vector< Podd::InterStageModule * > fInterStage
std::vector< THaSpectrometer * > fSpectrometers
Int_t fVerbose
virtual void Begin(const char *name)
virtual ULong64_t GetEvTime() const
UInt_t GetEvType() const
UInt_t GetEvNum() const
virtual Int_t GetHelicity() const
UInt_t GetEvLength() const
void Set(UInt_t num, UInt_t type, UInt_t len, ULong64_t time, Int_t hel, UInt_t tbits, UInt_t run)
THaEventHeader * GetHeader()
virtual Int_t Fill()
virtual Int_t Process()
UInt_t GetNumber() const
void IncrNumAnalyzed(Int_t n=1)
virtual ~THcNPSAnalyzer()
Int_t PhysicsAnalysis(Int_t code)
Bool_t GetClearThisEvent()
Bool_t GetProcessThisEvent()
const char * GetName() const override
const char * GetTitle() const override
virtual void Error(const char *method, const char *msgfmt,...) const
STL namespace.