Hall C ROOT/C++ Analyzer (hcana)
Loading...
Searching...
No Matches
THcRFTime.cxx
Go to the documentation of this file.
1
15#include "THaEvData.h"
16#include "THaCutList.h"
17#include "THaDetMap.h"
18#include "THaApparatus.h"
19#include "VarDef.h"
20#include "VarType.h"
21#include "TClonesArray.h"
22
23#include <cstring>
24#include <cstdio>
25#include <cstdlib>
26#include <iostream>
27
28#include "THcRFTime.h"
29#include "THcTrigDet.h"
30#include "THcHodoHit.h"
31#include "THcGlobals.h"
32#include "THcParmList.h"
33#include "THcAnalyzer.h"
34
35using namespace std;
36
37//_____________________________________________________________________________
38THcRFTime::THcRFTime (const char *name, const char* description, const char* hadArmName,
39 const char* elecArmName, const char* RFname) :
40
41 THaPhysicsModule(name, description),
42 fCoinDetName(RFname),
43 fhadArmName(hadArmName), //initialize spectro names
44 felecArmName(elecArmName),
45 fhadSpectro(NULL), //initialize spectro objects
46 felecSpectro(NULL),
47 fCoinDet(NULL)
48{
49 Bunch_Spacing_Epics = 0.0001;
50}
51
52//_____________________________________________________________________________
54{
55 //Destructor
56
58
59}
60//_____________________________________________________________________________
62{
63 // Clear all event-by-event variables.
64 // Only need to clear variables that are actually used, will need to re-tweak this when the rest is set up
65 // THaPhysicsModule::Clear(opt);
68}
69
70//_____________________________________________________________________________
72// Clear event-by-event data
73{
74 Clear(opt);
75}
76
77
78//_____________________________________________________________________________
80{
81 // Initialize THcRFTime physics module
82
83 cout << "*************************************************" << endl;
84 cout << "Initializing THcRFTime Physics Modue" << endl;
85 cout << "Hadron Arm -------> " << fhadArmName << endl;
86 cout << "Electron Arm -------> " << felecArmName << endl;
87 cout << "TrigDet -------> " << fCoinDetName << endl;
88 fStatus = kOK;
89 // For now, read in both spectrometers by default
90 // In future, should be modified to read in one or the other (or both)
91 fhadSpectro = dynamic_cast<THcHallCSpectrometer*>
92 ( FindModule( fhadArmName.Data(), "THcHallCSpectrometer"));
93 if( !fhadSpectro ) {
94 cout << "THcRFTime module - Cannnot find Hadron Arm = " << fhadArmName.Data() << endl;
96 return fStatus;
97 }
98
99 felecSpectro = dynamic_cast<THcHallCSpectrometer*>
100 ( FindModule( felecArmName.Data(), "THcHallCSpectrometer"));
101 if( !felecSpectro ) {
102 cout << "THcRFTime module - Cannnot find Electron Arm = " << felecArmName.Data() << endl;
104 return fStatus;
105 }
106 // Switch to Trig Det
107 fCoinDet = dynamic_cast<THcTrigDet*>
108 ( FindModule( fCoinDetName.Data(), "THcTrigDet"));
109 if( !fCoinDet ) {
110 cout << "THcRFTime module - Cannnot find TrigDet = " << fCoinDetName.Data() << endl;
112 return fStatus;
113 }
114
115 if( (fStatus=THaPhysicsModule::Init( run_time )) != kOK ) {
116 return fStatus;
117 }
118
119 return fStatus;
120}
121
122//_____________________________________________________________________________
124{
125 // Read database. Gets variable needed for RFTime calculation
126
127 DBRequest list[]={
128 {"HMS_RF_Offset", &HMS_RF_Offset, kDouble, 0, 1}, // RF offset for HMS
129 {"SHMS_RF_Offset", &SHMS_RF_Offset, kDouble, 0, 1}, // RF offset for SHMS
130 {"Bunch_Spacing_Override", &Bunch_Spacing_Override, kDouble, 0, 1}, // Bunch spacing value, can be manually set to override the Epics read in
131 {0}
132 };
133
134 // Default values if not read from param file
135 Bunch_Spacing_Override = 1.5556; // Strangely specific value so we can check if it's set or not
136 HMS_RF_Offset = 0.0;
137 SHMS_RF_Offset = 0.0;
138 gHcParms->LoadParmValues((DBRequest*)&list, "");
139 // If the override value has been set (i.e. it is NOT the default value), set it to whatever the read in is
140 if ( Bunch_Spacing_Override != 1.5556){
142 }
143 // If override wasn't set, assume the bunch spacing has some default value (will be overriden by Epics if it looks OK)
144 else if (Bunch_Spacing_Override == 1.5556){
145 Bunch_Spacing = 4.008;
146 }
147
148 THcAnalyzer *analyzer = dynamic_cast<THcAnalyzer*>(THcAnalyzer::GetInstance());
149 fEpicsHandler = analyzer->GetEpicsEvtHandler();
150
151 return kOK;
152}
153
154//_____________________________________________________________________________
156{
157 // Define variables that this script will actually calculate
158 if( mode == kDefine && fIsSetup ) return kOK;
159 fIsSetup = ( mode == kDefine );
160 const RVarDef vars[] = {
161 {"HMS_RFtimeDist", "HMS RF Time Disttribution for PID", "fHMS_RFtimeDist"},
162 {"SHMS_RFtimeDist", "SHMS RF Time Disttribution for PID", "fSHMS_RFtimeDist"},
163 { 0 }
164 };
165
166 return DefineVarsFromList( vars, mode );
167
168}
169
170//_____________________________________________________________________________
172{
173 static const char* const epics_tag = "MOFC1FREQ";
174
175 if( !IsOK() || !gHaRun ) return -1;
176
177 if (Bunch_Spacing_Epics == 0.0001 && fEpicsHandler->IsLoaded(epics_tag)){ // If Bunch_Spacing_Epics is still the default value (0.0001), set it to the Epics read in, this is to ensure it is only set ONCE
178 Bunch_Spacing_Epics = (2.0/(atof(fEpicsHandler->GetString(epics_tag))))*(pow(10, 9)); // Calculation of Bunch Spacing, 2/f as we get every OTHER bucket typically, converted to ns
179 if (Bunch_Spacing_Epics > 0.1 && Bunch_Spacing_Epics < 4.5){ // If the value looks sensible, check if an override value has been set
180 if (Bunch_Spacing_Override == 1.5556){ // If the Bunch_Spacing_override has NOT been set by the user, set the bunch spacing to be the epics value
182 }
183 }
184 }
185
186 //Declare track information objects for hadron/electron arm
187 THaTrackInfo* had_trkifo = fhadSpectro->GetTrackInfo();
188 THaTrackInfo* elec_trkifo = felecSpectro->GetTrackInfo();
189
190 if( !had_trkifo) cout << " no hadron track " << endl;
191 if( !elec_trkifo) cout << " no electron track " << endl;
192 // Check if the hadron/electron arm had a track
193 // May want to consider dropping this condition
194 if( !had_trkifo || !had_trkifo->IsOK() ) return 1;
195 if( !elec_trkifo || !elec_trkifo->IsOK() ) return 1;
196
197 //Create THaTrack object for hadron/elec arms to get relevant golden track quantities
198 if (felecArmName=="H") {
201 } else{
204 }
205
206 //Check if Database is reading the correct elec-arm particle mass
207 // if (felecSpectro->GetParticleMass() > 0.00052) return 1;
208
211
212 if (SHMS_FPtime==-2000 || HMS_FPtime==-2000) return 1;
213 if (SHMS_FPtime==-1000 || HMS_FPtime==-1000) return 1;
214
215 SHMS_RFtime = fCoinDet->Get_RF_TrigTime(0); // SHMS is ID 0
216 HMS_RFtime = fCoinDet->Get_RF_TrigTime(1); // HMS is ID 1
217
218 // RF Time dist can be utilised for PID, offsets should be set in Standard.kinematics, these are just used to "center" the distribution at a desired point
219 // Typically, other PID info needs to be utilised to establish where the relevant peaks for each particle species are in the distribution
220 // Note, this expression looks a bit odd but this is to achieve the same results as the Python a % b operation
221 // The result of this calculation will ALWAYS be a POSITIVE number between 0 and Bunch_Spacing
222 // See - https://stackoverflow.com/questions/1907565/c-and-python-different-behaviour-of-the-modulo-operation for more
225
226 return 0;
227}
228
229//_____________________________________________________________________________
230
int Int_t
const Data_t kBig
double Double_t
const char Option_t
Option_t Option_t TPoint TPoint const char mode
R__EXTERN class THaRunBase * gHaRun
ClassImp(VDC::AnalyticTTDConv) using namespace std
R__EXTERN class THcParmList * gHcParms
Definition THcGlobals.h:11
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="")
THaAnalysisObject * FindModule(const char *name, const char *classname, bool do_error=true)
Bool_t IsOK() const
Int_t RemoveVariables()
static THaAnalyzer * GetInstance()
THaEpicsEvtHandler * GetEpicsEvtHandler() const
TString GetString(const char *tag, UInt_t event=0) const
Bool_t IsLoaded(const char *tag) const
THaTrack * GetGoldenTrack() const
Bool_t IsOK() const
Double_t GetFPTime() const
THaTrackInfo * GetTrackInfo()
Hall C analyzer class.
Definition THcAnalyzer.h:12
A standard Hall C spectrometer apparatus.
Int_t LoadParmValues(const DBRequest *list, const char *prefix="")
Retrieve parameter values from the parameter cache.
Double_t Bunch_Spacing_Override
Definition THcRFTime.h:74
Double_t SHMS_RFtime
Definition THcRFTime.h:79
THcRFTime(const char *name, const char *description, const char *hadArmName="", const char *elecArmName="", const char *RFname="")
Definition THcRFTime.cxx:38
THcTrigDet * fCoinDet
Definition THcRFTime.h:64
Double_t HMS_FPtime
Definition THcRFTime.h:80
Double_t SHMS_RF_Offset
Definition THcRFTime.h:73
Double_t HMS_RFtime
Definition THcRFTime.h:78
TString fhadArmName
Definition THcRFTime.h:58
Double_t fHMS_RFtimeDist
Definition THcRFTime.h:83
Double_t SHMS_FPtime
Definition THcRFTime.h:81
THaEpicsEvtHandler * fEpicsHandler
Definition THcRFTime.h:65
THaTrack * theSHMSTrack
Definition THcRFTime.h:67
virtual Int_t Process(const THaEvData &)
TString fCoinDetName
Definition THcRFTime.h:57
virtual Int_t DefineVariables(EMode mode=kDefine)
virtual ~THcRFTime()
Definition THcRFTime.cxx:53
virtual Int_t ReadDatabase(const TDatime &date)
Double_t Bunch_Spacing_Epics
Definition THcRFTime.h:77
void Reset(Option_t *opt="")
Definition THcRFTime.cxx:71
Double_t Bunch_Spacing
Definition THcRFTime.h:76
TString felecArmName
Definition THcRFTime.h:59
Double_t fSHMS_RFtimeDist
Definition THcRFTime.h:84
THcHallCSpectrometer * felecSpectro
Definition THcRFTime.h:63
THaTrack * theHMSTrack
Definition THcRFTime.h:68
Double_t HMS_RF_Offset
Definition THcRFTime.h:72
void Clear(Option_t *opt="")
Definition THcRFTime.cxx:61
THcHallCSpectrometer * fhadSpectro
Definition THcRFTime.h:62
A mock detector to hold trigger related data.
Definition THcTrigDet.h:16
Double_t Get_RF_TrigTime(Int_t ii)
Definition THcTrigDet.h:40
const char * Data() const
RVec< PromoteTypes< T0, T1 > > fmod(const RVec< T0 > &v, const T1 &y)
RVec< PromoteTypes< T0, T1 > > pow(const RVec< T0 > &v, const T1 &y)
STL namespace.