QwAnalysis
QwMockDataAnalysis.cc File Reference

Parity mock data analysis, test code. More...

#include <iostream>
#include <boost/random.hpp>
#include <TROOT.h>
#include <TFile.h>
#include <TTree.h>
#include "QwBeamLine.h"
#include "QwOptionsParity.h"
#include "QwEventBuffer.h"
#include "QwParityDB.h"
#include "QwHelicity.h"
#include "QwHelicityPattern.h"
#include "QwHistogramHelper.h"
#include "QwMainCerenkovDetector.h"
#include "QwLumi.h"
#include "QwSubsystemArrayParity.h"
+ Include dependency graph for QwMockDataAnalysis.cc:

Go to the source code of this file.

Macros

#define NEVENTS   1000
 
#define NVARS   4
 

Functions

int main (int argc, char *argv[])
 

Variables

static const int kMultiplet = 4
 
static bool bDebug = false
 
static bool bTree = true
 
static bool bHisto = true
 
static bool bHelicity = true
 
static bool bDatabase = false
 

Detailed Description

Parity mock data analysis, test code.

Definition in file QwMockDataAnalysis.cc.

Macro Definition Documentation

#define NEVENTS   1000

Definition at line 35 of file QwMockDataAnalysis.cc.

#define NVARS   4

Definition at line 37 of file QwMockDataAnalysis.cc.

Function Documentation

int main ( int  argc,
char *  argv[] 
)

Fill the search paths for the parameter files; this sets a static variable within the QwParameterFile class which will be used by all instances. The "scratch" directory should be first.

Definition at line 52 of file QwMockDataAnalysis.cc.

References QwHelicityPattern::AccumulateRunningBurstSum(), QwSubsystemArrayParity::AccumulateRunningSum(), QwParameterFile::AppendToSearchPath(), bDatabase, bDebug, bHelicity, bHisto, bTree, QwHelicityPattern::CalculateAsymmetry(), QwHelicityPattern::CalculateBurstAverage(), QwSubsystemArrayParity::CalculateRunningAverage(), QwHelicityPattern::CalculateRunningAverage(), QwHelicityPattern::CalculateRunningBurstAverage(), QwHelicityPattern::ClearBurstSum(), QwHelicityPattern::ClearEventData(), QwEventBuffer::CloseDataFile(), QwSubsystemArrayParity::ConstructBranchAndVector(), QwHelicityPattern::ConstructBranchAndVector(), QwHelicityPattern::ConstructHistograms(), QwSubsystemArray::ConstructHistograms(), DefineOptionsParity(), QwLog::endl(), QwHelicityPattern::FillDB(), QwSubsystemArrayParity::FillHistograms(), QwHelicityPattern::FillHistograms(), QwEventBuffer::FillSubsystemConfigurationData(), QwEventBuffer::FillSubsystemData(), QwSubsystemArrayParity::FillTreeVector(), QwHelicityPattern::FillTreeVector(), QwParityDB::GetAnalysisID(), getenv_safe_string(), getenv_safe_TString(), QwEventBuffer::GetEvent(), QwEventBuffer::GetEventNumber(), QwHelicity::GetHelicityActual(), QwHelicity::GetHelicityDelayed(), QwOptions::GetIntValuePairFirst(), QwOptions::GetIntValuePairLast(), QwParityDB::GetLumiDetectorID(), QwParityDB::GetMainDetectorID(), QwParityDB::GetMonitorID(), QwHelicity::GetPhaseNumber(), QwHelicity::GetRandomSeedActual(), QwHelicity::GetRandomSeedDelayed(), QwParityDB::GetRunID(), QwEventBuffer::GetRunNumber(), QwSubsystemArrayParity::GetSubsystemByName(), QwDatabase::GetVersion(), gQwHists, gQwOptions, QwSubsystemArrayParity::IncrementErrorCounters(), QwHelicityPattern::IsCompletePattern(), QwEventBuffer::IsPhysicsEvent(), QwEventBuffer::IsROCConfigurationEvent(), Qw::kBoldMagenta, kMultiplet, Qw::kNormal, QwHelicityPattern::LoadEventData(), QwHistogramHelper::LoadHistParamsFromFile(), QwEventBuffer::OpenDataFile(), QwSubsystemArray::ProcessEvent(), QwHelicityPattern::ProcessOptions(), QwSubsystemArray::ProcessOptions(), QwMessage, MQwCodaControlEvent::ReportRunSummary(), QwOptions::SetCommandLine(), and QwOptions::SetConfigFile().

53 {
54  // First, we set the command line arguments and the configuration filename,
55  // and we define the options that can be used in them (using QwOptions).
56  gQwOptions.SetCommandLine(argc, argv);
57  // gQwOptions.SetConfigFile("qwmockdataanalysis.conf");
58  gQwOptions.SetConfigFile("Parity/prminput/qwanalysis_beamline.conf");
59  gQwOptions.SetConfigFile("Parity/prminput/qweak_mysql.conf");
60  // Define the command line options
62 
63  /// Fill the search paths for the parameter files; this sets a static
64  /// variable within the QwParameterFile class which will be used by
65  /// all instances.
66  /// The "scratch" directory should be first.
68  QwParameterFile::AppendToSearchPath(getenv_safe_string("QWANALYSIS")+"/Parity/prminput");
69  QwParameterFile::AppendToSearchPath(getenv_safe_string("QWANALYSIS") + "/Analysis/prminput");
70 
71  // Load histogram definitions
72  gQwHists.LoadHistParamsFromFile("qweak_parity_hists.in");
73 
74  // Detector array
76  detectors.ProcessOptions(gQwOptions);
77 
78  // Helicity pattern
79  QwHelicityPattern helicitypattern(detectors);
80  helicitypattern.ProcessOptions(gQwOptions);
81 
82  // Running sum
83  QwSubsystemArrayParity runningsum(detectors);
84 
85  // Get the helicity
86  QwHelicity* helicity = dynamic_cast<QwHelicity*>(detectors.GetSubsystemByName("Helicity info"));
87 
88  // Event buffer
89  QwEventBuffer eventbuffer;
90 
91 
92  // Loop over all runs
93  UInt_t runnumber_min = (UInt_t) gQwOptions.GetIntValuePairFirst("run");
94  UInt_t runnumber_max = (UInt_t) gQwOptions.GetIntValuePairLast("run");
95  for (UInt_t run = runnumber_min;
96  run <= runnumber_max;
97  run++) {
98 
99  // Data file (input)
100  TString datafilename = TString("QwMock_") + Form("%d.log",run);
101  if (eventbuffer.OpenDataFile(datafilename,"R") != CODA_OK) {
102  std::cout << "Error: could not open file!" << std::endl;
103  return 0;
104  }
105 
106 
107  // ROOT file output (histograms)
108  TString rootfilename = getenv_safe_TString("QW_ROOTFILES") + TString("/QwMock_") + Form("%d.root",run);
109  TFile rootfile(rootfilename, "RECREATE", "QWeak ROOT file");
110  if (bHisto) {
111  rootfile.cd();
112  detectors.ConstructHistograms(rootfile.mkdir("mps_histo"));
113  if (bHelicity) {
114  rootfile.cd();
115  helicitypattern.ConstructHistograms(rootfile.mkdir("hel_histo"));
116  }
117  }
118 
119  // ROOT file output (trees)
120  TTree *mpstree;
121  TTree *heltree;
122  Int_t eventnumber;
123  std::vector <Double_t> mpsvector;
124  std::vector <Double_t> helvector;
125  if (bTree) {
126  rootfile.cd();
127  mpstree = new TTree("MPS_Tree","MPS event data tree");
128  mpsvector.reserve(6000);
129  mpstree->Branch("eventnumber",&eventnumber,"eventnumber/F");
130  TString dummystr="";
131  detectors.ConstructBranchAndVector(mpstree, dummystr, mpsvector);
132  rootfile.cd();
133  if (bHelicity) {
134  rootfile.cd();
135  heltree = new TTree("HEL_Tree","Helicity event data tree");
136  helvector.reserve(6000);
137  TString dummystr="";
138  helicitypattern.ConstructBranchAndVector(heltree, dummystr, helvector);
139  }
140  }
141 
142 
143  // Loop over events in this CODA file
144  Int_t eventnumber_min = gQwOptions.GetIntValuePairFirst("event");
145  Int_t eventnumber_max = gQwOptions.GetIntValuePairLast("event");
146  while (eventbuffer.GetEvent() == CODA_OK) {
147 
148  // First, do processing of non-physics events...
149  if (eventbuffer.IsROCConfigurationEvent()) {
150  // Send ROC configuration event data to the subsystem objects.
151  eventbuffer.FillSubsystemConfigurationData(detectors);
152  }
153 
154  // Now, if this is not a physics event, go back and get a new event.
155  if (! eventbuffer.IsPhysicsEvent()) continue;
156 
157  // Check to see if we want to process this event.
158  eventnumber = eventbuffer.GetEventNumber();
159  if (eventnumber < eventnumber_min) continue;
160  else if (eventnumber > eventnumber_max) break;
161 
162  // Fill the subsystem objects with their respective data for this event.
163  eventbuffer.FillSubsystemData(detectors);
164 
165  // Process this events
166  detectors.ProcessEvent();
167  detectors.IncrementErrorCounters();
168 
169  // Helicity pattern
170  if (bHelicity)
171  helicitypattern.LoadEventData(detectors);
172 
173  // Print the helicity information
174  if (bHelicity && bDebug) {
175  // - actual helicity
176  if (helicity->GetHelicityActual() == 0) std::cout << "-";
177  else if (helicity->GetHelicityActual() == 1) std::cout << "+";
178  else std::cout << "?";
179  // - delayed helicity
180  if (helicity->GetHelicityDelayed() == 0) std::cout << "(-) ";
181  else if (helicity->GetHelicityDelayed() == 1) std::cout << "(+) ";
182  else std::cout << "(?) ";
183  if (helicity->GetPhaseNumber() == kMultiplet) {
184  std::cout << std::hex << helicity->GetRandomSeedActual() << std::dec << ", \t";
185  std::cout << std::hex << helicity->GetRandomSeedDelayed() << std::dec << std::endl;
186  }
187  }
188 
189  // Check for helicity validity (TODO I'd prefer to use kUndefinedHelicity)
190  if (bHelicity && helicity->GetHelicityDelayed() == -9999) continue;
191 
192  // Fill the histograms
193  if (bHisto) detectors.FillHistograms();
194 
195  // Accumulate the running sum to calculate the event based running average
196  runningsum.AccumulateRunningSum(detectors);
197 
198  // Fill the MPS tree
199  if (bTree) {
200  eventnumber = eventbuffer.GetEventNumber();
201  detectors.FillTreeVector(mpsvector);
202  mpstree->Fill();
203  }
204  // Fill the helicity tree
205  if (bHelicity && helicitypattern.IsCompletePattern()) {
206  helicitypattern.CalculateAsymmetry();
207  if (bHisto) helicitypattern.FillHistograms();
208  if (bTree) {
209  helicitypattern.FillTreeVector(helvector);
210  heltree->Fill();
211  }
212  helicitypattern.ClearEventData();
213  }
214 
215  // Periodically print event number
216  if ((bDebug && eventbuffer.GetEventNumber() % 1000 == 0)
217  || eventbuffer.GetEventNumber() % 10000 == 0)
218  std::cout << "Number of events processed so far: "
219  << eventbuffer.GetEventNumber() << std::endl;
220 
221  // TODO (wdc) QwEventBuffer should have Bool_t AtEndOfBurst()
222  //if (QwEvt.AtEndOfBurst()){
223  if (eventbuffer.GetEventNumber() % 1000 == 0) {
224  {
225  helicitypattern.AccumulateRunningBurstSum();
226  helicitypattern.CalculateBurstAverage();
227  helicitypattern.ClearBurstSum();
228  }
229  }
230 
231  } // end of loop over events
232 
233  // Calculate the running averages
234  helicitypattern.CalculateRunningAverage();
235  helicitypattern.CalculateRunningBurstAverage();
236  runningsum.CalculateRunningAverage();
237 
238  // Close ROOT file
239  rootfile.Write(0,TObject::kOverwrite);
240 
241  // Close data file and print run summary
242  eventbuffer.CloseDataFile();
243  eventbuffer.ReportRunSummary();
244 
245  // Write to database
246  if (bDatabase) {
247  QwParityDB* qweak_database = new QwParityDB();
248  QwMessage << "GetMonitorID(qwk_batext2) = " << qweak_database->GetMonitorID("qwk_batext2") << QwLog::endl;
249  QwMessage << "GetMonitorID(phasemonitor) = " << qweak_database->GetMonitorID("phasemonitor") << QwLog::endl;
250  QwMessage << "GetMonitorID(qwk_junk) = " << qweak_database->GetMonitorID("qwk_junk") << QwLog::endl;
251  QwMessage << "GetMainDetectorID(md1neg) = " << qweak_database->GetMainDetectorID("md1neg") << QwLog::endl;
252  QwMessage << "GetMainDetectorID(spare3) = " << qweak_database->GetMainDetectorID("spare3") << QwLog::endl;
253  QwMessage << "GetMainDetectorID(combinationallmd) = " << qweak_database->GetMainDetectorID("combinationallmd") << QwLog::endl;
254  QwMessage << "GetLumiDetectorID(dlumi8) = " << qweak_database->GetLumiDetectorID("dlumi8") << QwLog::endl;
255  QwMessage << "GetVersion() = " << qweak_database->GetVersion() << QwLog::endl;
256  // GetRunID() and GetAnalysisID have their own Connect() and Disconnect() functions.
257  UInt_t run_id = qweak_database->GetRunID(eventbuffer);
258  UInt_t analysis_id = qweak_database->GetAnalysisID(eventbuffer);
259 
260  QwMessage << "QwMockDataAnalysis.cc::"
261  << " Run Number " << QwColor(Qw::kBoldMagenta) << eventbuffer.GetRunNumber() << QwColor(Qw::kNormal)
262  << " Run ID " << QwColor(Qw::kBoldMagenta) << run_id<< QwColor(Qw::kNormal)
263  << " Analysis ID " << QwColor(Qw::kBoldMagenta) << analysis_id
264  << QwLog::endl;
265 
266  // Each sussystem has its own Connect() and Disconnect() functions.
267  helicitypattern.FillDB(qweak_database);
268 
269  delete qweak_database; qweak_database = NULL;
270 
271  } // end of database write
272 
273 
274  } // end of loop over runs
275 
276 
277 }
int GetIntValuePairFirst(const std::string &key)
Get the first of a pair of integer values.
Definition: QwOptions.h:266
#define QwMessage
Predefined log drain for regular messages.
Definition: QwLog.h:50
UInt_t GetMonitorID(const string &name, Bool_t zero_id_is_error=kTRUE)
Definition: QwParityDB.cc:618
Int_t GetPhaseNumber()
Definition: QwHelicity.cc:1084
static void AppendToSearchPath(const TString &searchdir)
Add a directory to the search path.
Bool_t FillSubsystemConfigurationData(QwSubsystemArray &subsystems)
static bool bHisto
UInt_t GetMainDetectorID(const string &name, Bool_t zero_id_is_error=kTRUE)
Definition: QwParityDB.cc:661
static bool bHelicity
void DefineOptionsParity(QwOptions &options)
const TString getenv_safe_TString(const char *name)
Definition: QwOptions.h:40
UInt_t GetLumiDetectorID(const string &name, Bool_t zero_id_is_error=kTRUE)
Definition: QwParityDB.cc:790
QwOptions gQwOptions
Definition: QwOptions.cc:27
UInt_t GetAnalysisID()
Definition: QwParityDB.h:71
const string GetVersion()
Definition: QwDatabase.cc:304
UInt_t GetRandomSeedActual()
Definition: QwHelicity.h:86
Int_t OpenDataFile(UInt_t current_run, Short_t seg)
Int_t GetEventNumber()
Int_t GetHelicityDelayed()
Definition: QwHelicity.cc:1069
Virtual base class for the parity subsystems.
UInt_t GetRunID()
Definition: QwParityDB.h:69
void SetConfigFile(const std::string &configfile)
Set a configuration file.
Definition: QwOptions.h:192
static bool bTree
Int_t GetRunNumber() const
Return CODA file run number.
Definition: QwEventBuffer.h:80
QwHistogramHelper gQwHists
Globally defined instance of the QwHistogramHelper class.
Bool_t FillSubsystemData(QwSubsystemArray &subsystems)
A color changing class for the output stream.
Definition: QwColor.h:98
UInt_t GetRandomSeedDelayed()
Definition: QwHelicity.h:87
static std::ostream & endl(std::ostream &)
End of the line.
Definition: QwLog.cc:299
Int_t CloseDataFile()
const std::string getenv_safe_string(const char *name)
Definition: QwOptions.h:37
Bool_t IsPhysicsEvent()
static const int kMultiplet
static bool bDatabase
static bool bDebug
Int_t GetHelicityActual()
Definition: QwHelicity.cc:1064
void LoadHistParamsFromFile(const std::string &filename)
int GetIntValuePairLast(const std::string &key)
Get the last of a pair of integer values.
Definition: QwOptions.h:271
Bool_t IsROCConfigurationEvent()
void SetCommandLine(int argc, char *argv[], bool default_config_file=true)
Set the command line arguments.
Definition: QwOptions.cc:112

Variable Documentation

bool bDatabase = false
static

Definition at line 50 of file QwMockDataAnalysis.cc.

Referenced by main().

bool bDebug = false
static

Definition at line 44 of file QwMockDataAnalysis.cc.

Referenced by main().

bool bHelicity = true
static

Definition at line 49 of file QwMockDataAnalysis.cc.

Referenced by main().

bool bHisto = true
static

Definition at line 48 of file QwMockDataAnalysis.cc.

Referenced by main().

bool bTree = true
static

Definition at line 47 of file QwMockDataAnalysis.cc.

Referenced by main().

const int kMultiplet = 4
static

Definition at line 41 of file QwMockDataAnalysis.cc.

Referenced by main().