Hall C ROOT/C++ Analyzer (hcana)
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 
35 using namespace std;
36 
37 //_____________________________________________________________________________
38 THcRFTime::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 
57  RemoveVariables();
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 //_____________________________________________________________________________
79 THaAnalysisObject::EStatus THcRFTime::Init( const TDatime& run_time )
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;
95  fStatus = kInitError;
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;
103  fStatus = kInitError;
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;
111  fStatus = kInitError;
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  if( !IsOK() || !gHaRun ) return -1;
174 
175  if (Bunch_Spacing_Epics == 0.0001){ // 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
176  Bunch_Spacing_Epics = (2.0/(atof(fEpicsHandler->GetString("MOFC1FREQ"))))*(pow(10, 9)); // Calculation of Bunch Spacing, 2/f as we get every OTHER bucket typically, converted to ns
177  if (Bunch_Spacing_Epics > 0.1 && Bunch_Spacing_Epics < 4.5){ // If the value looks sensible, check if an override value has been set
178  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
180  }
181  }
182  }
183 
184  //Declare track information objects for hadron/electron arm
185  THaTrackInfo* had_trkifo = fhadSpectro->GetTrackInfo();
186  THaTrackInfo* elec_trkifo = felecSpectro->GetTrackInfo();
187 
188  if( !had_trkifo) cout << " no hadron track " << endl;
189  if( !elec_trkifo) cout << " no electron track " << endl;
190  // Check if the hadron/electron arm had a track
191  // May want to consider dropping this condition
192  if( !had_trkifo || !had_trkifo->IsOK() ) return 1;
193  if( !elec_trkifo || !elec_trkifo->IsOK() ) return 1;
194 
195  //Create THaTrack object for hadron/elec arms to get relevant golden track quantities
196  if (felecArmName=="H") {
197  theSHMSTrack = (fhadSpectro->GetGoldenTrack());
198  theHMSTrack = (felecSpectro->GetGoldenTrack());
199  } else{
200  theSHMSTrack = (felecSpectro->GetGoldenTrack());
201  theHMSTrack = (fhadSpectro->GetGoldenTrack());
202  }
203 
204  //Check if Database is reading the correct elec-arm particle mass
205  // if (felecSpectro->GetParticleMass() > 0.00052) return 1;
206 
207  Double_t SHMS_FPtime = theSHMSTrack->GetFPTime();// SHMS arm
208  Double_t HMS_FPtime = theHMSTrack->GetFPTime(); // HMS arm
209 
210  if (SHMS_FPtime==-2000 || HMS_FPtime==-2000) return 1;
211  if (SHMS_FPtime==-1000 || HMS_FPtime==-1000) return 1;
212 
213  SHMS_RFtime = fCoinDet->Get_RF_TrigTime(0); // SHMS is ID 0
214  HMS_RFtime = fCoinDet->Get_RF_TrigTime(1); // HMS is ID 1
215 
216  // 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
217  // Typically, other PID info needs to be utilised to establish where the relevant peaks for each particle species are in the distribution
218  // Note, this expression looks a bit odd but this is to achieve the same results as the Python a % b operation
219  // The result of this calculation will ALWAYS be a POSITIVE number between 0 and Bunch_Spacing
220  // See - https://stackoverflow.com/questions/1907565/c-and-python-different-behaviour-of-the-modulo-operation for more
223 
224  return 0;
225 }
226 
227 //_____________________________________________________________________________
228 
const char Option_t
TString fCoinDetName
Definition: THcRFTime.h:57
Double_t fSHMS_RFtimeDist
Definition: THcRFTime.h:84
THcHallCSpectrometer * felecSpectro
Definition: THcRFTime.h:63
Double_t SHMS_RF_Offset
Definition: THcRFTime.h:73
Double_t HMS_RF_Offset
Definition: THcRFTime.h:72
Hall C analyzer class.
Definition: THcAnalyzer.h:12
int Int_t
Double_t SHMS_RFtime
Definition: THcRFTime.h:79
STL namespace.
virtual Int_t DefineVariables(EMode mode=kDefine)
Definition: THcRFTime.cxx:155
const char * Data() const
Double_t fHMS_RFtimeDist
Definition: THcRFTime.h:83
THcTrigDet * fCoinDet
Definition: THcRFTime.h:64
double pow(double, double)
TString felecArmName
Definition: THcRFTime.h:59
virtual Int_t ReadDatabase(const TDatime &date)
Definition: THcRFTime.cxx:123
Double_t Get_RF_TrigTime(Int_t ii)
Definition: THcTrigDet.h:39
A mock detector to hold trigger related data.
Definition: THcTrigDet.h:16
virtual EStatus Init(const TDatime &run_time)
Definition: THcRFTime.cxx:79
Double_t SHMS_FPtime
Definition: THcRFTime.h:81
TString fhadArmName
Definition: THcRFTime.h:58
THcRFTime(const char *name, const char *description, const char *hadArmName="", const char *elecArmName="", const char *RFname="")
Definition: THcRFTime.cxx:38
THcHallCSpectrometer * fhadSpectro
Definition: THcRFTime.h:62
tuple list
Definition: SConscript.py:9
THaTrack * theHMSTrack
Definition: THcRFTime.h:68
Double_t HMS_RFtime
Definition: THcRFTime.h:78
void Clear(Option_t *opt="")
Definition: THcRFTime.cxx:61
Double_t Bunch_Spacing_Override
Definition: THcRFTime.h:74
Int_t LoadParmValues(const DBRequest *list, const char *prefix="")
Retrieve parameter values from the parameter cache.
double Double_t
virtual Int_t Process(const THaEvData &)
Definition: THcRFTime.cxx:171
THaTrack * theSHMSTrack
Definition: THcRFTime.h:67
ClassImp(THcDCLookupTTDConv) THcDCLookupTTDConv
THaEpicsEvtHandler * fEpicsHandler
Definition: THcRFTime.h:65
Double_t HMS_FPtime
Definition: THcRFTime.h:80
void Reset(Option_t *opt="")
Definition: THcRFTime.cxx:71
R__EXTERN class THcParmList * gHcParms
Definition: THcGlobals.h:11
virtual ~THcRFTime()
Definition: THcRFTime.cxx:53
static const Double_t kBig
Definition: THcFormula.cxx:31
Double_t Bunch_Spacing_Epics
Definition: THcRFTime.h:77
Double_t Bunch_Spacing
Definition: THcRFTime.h:76
A standard Hall C spectrometer apparatus.