QwAnalysis
QwSimTracking.cc File Reference

Example of the QwTreeEventBuffer class to read QweakSimG4 events. More...

#include <iostream>
#include <cstdlib>
#include <TFile.h>
#include <TTree.h>
#include "QwOptionsTracking.h"
#include "QwLog.h"
#include "QwRootFile.h"
#include "QwParameterFile.h"
#include "QwTreeEventBuffer.h"
#include "QwHitRootContainer.h"
#include "QwTrackingWorker.h"
#include "QwPartialTrack.h"
#include "QwEvent.h"
#include "QwSubsystemArrayTracking.h"
#include "QwDriftChamberHDC.h"
#include "QwDriftChamberVDC.h"
#include "QwTriggerScintillator.h"
#include "QwMainDetector.h"
#include <TStopwatch.h>
+ Include dependency graph for QwSimTracking.cc:

Go to the source code of this file.

Functions

void PrintInfo (TStopwatch &timer)
 
int main (int argc, char *argv[])
 

Detailed Description

Example of the QwTreeEventBuffer class to read QweakSimG4 events.

This example illustrates the use of the QwTreeEventBuffer class. It loads the file Tracking/prminput/QweakSim.root, which was produced with a 3-fold trigger in QweakSimG4 (hits in all of HDC, VDC-front, and VDC-back). For every event a QwHitContainer is filled, which is then printed to QwMessage.

Definition in file QwSimTracking.cc.

Function Documentation

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

First, we fill the search paths for the parameter files.

We set the command line arguments and the configuration filename, and we define the options that can be used in them (using QwOptions).

Setup screen and file logging

Load the tracking detectors from file

Create a timer

Start timer

Next, we create the tracking worker that will pull coordinate the tracking.

Stop timer

Create the event buffer

Start loop over all runs

Start timer

We loop over all requested events.

Create the original event

Create the to-be-reconstructed event

We process the hit list through the tracking worker

Stop timer

Definition at line 55 of file QwSimTracking.cc.

References QwParameterFile::AppendToSearchPath(), QwRootFile::Close(), QwTreeEventBuffer::CloseFile(), DefineOptionsTracking(), QwLog::endl(), QwRootFile::FillTree(), QwTreeEventBuffer::GetCurrentEvent(), getenv_safe_string(), QwTreeEventBuffer::GetEventNumber(), QwSubsystemArrayTracking::GetGeometry(), QwTreeEventBuffer::GetNextEvent(), QwTreeEventBuffer::GetOriginalEvent(), QwTreeEventBuffer::GetRunLabel(), QwRootFile::GetTree(), gQwLog, gQwOptions, QwTrackingWorker::nbridged, QwRootFile::NewTree(), QwTreeEventBuffer::OpenNextFile(), PrintInfo(), QwTreeEventBuffer::PrintStatInfo(), QwTrackingWorker::ProcessEvent(), QwTreeEventBuffer::ProcessOptions(), QwLog::ProcessOptions(), QwSubsystemArray::ProcessOptions(), QwError, QwMessage, QwTrackingWorker::R2Good, QwTrackingWorker::R3Good, QwEvent::Reset(), QwOptions::SetCommandLine(), QwRootFile::SetDefaultRootFileStem(), QwTreeEventBuffer::SetEntriesPerEvent(), QwRootFile::Write(), and QwRootFile::WriteParamFileList().

56 {
57  // Set default ROOT file stem
59 
60  /// First, we fill the search paths for the parameter files.
62  QwParameterFile::AppendToSearchPath(getenv_safe_string("QWANALYSIS") + "/Tracking/prminput");
63  QwParameterFile::AppendToSearchPath(getenv_safe_string("QWANALYSIS") + "/Analysis/prminput");
64 
65  /// We set the command line arguments and the configuration filename,
66  /// and we define the options that can be used in them (using QwOptions).
67  gQwOptions.SetCommandLine(argc, argv);
68  // Define the command line options
70 
71  /// Setup screen and file logging
73 
74  /// Load the tracking detectors from file
76  detectors.ProcessOptions(gQwOptions);
77 
78  // Get detector geometry
79  QwGeometry geometry = detectors.GetGeometry();
80 
81  /// Create a timer
82  TStopwatch timer;
83 
84  /// Start timer
85  timer.Reset();
86  timer.Start();
87 
88  /// Next, we create the tracking worker that will pull coordinate the tracking.
89  QwTrackingWorker trackingworker(gQwOptions, geometry);
90 
91  /// Stop timer
92  timer.Stop();
93  // Print timer info
94  PrintInfo(timer);
95 
96  /// Create the event buffer
97  QwTreeEventBuffer treebuffer(geometry);
98  treebuffer.ProcessOptions(gQwOptions);
99  treebuffer.SetEntriesPerEvent(1);
100 
101  /// Start loop over all runs
102  while (treebuffer.OpenNextFile() == 0) {
103 
104  // Open the ROOT file
105  QwRootFile* rootfile = new QwRootFile(treebuffer.GetRunLabel());
106  if (! rootfile) QwError << "QwAnalysis made a boo boo!" << QwLog::endl;
107 
108  // Construct a Tree which contains map file names which are used to analyze data
109  rootfile->WriteParamFileList("mapfiles", detectors);
110 
111  // Create dummy events for branch creation (memory leak when using null)
112  QwEvent* event = new QwEvent();
113  QwEvent* original = new QwEvent();
114 
115  // Create the tracking object branches
116  rootfile->NewTree("event_tree", "QwTracking Event-based Tree");
117  rootfile->GetTree("event_tree")->Branch("events", "QwEvent", &event);
118  rootfile->GetTree("event_tree")->Branch("originals", "QwEvent", &original);
119 
120  // Delete dummy events again
121  delete event; event = 0;
122  delete original; original = 0;
123 
124  /// Start timer
125  timer.Reset();
126  timer.Start();
127 
128  /// We loop over all requested events.
129  Int_t nevents = 0;
130  while (treebuffer.GetNextEvent() == 0) {
131 
132 
133  /// Create the original event
134  original = treebuffer.GetOriginalEvent();
135 
136  /// Create the to-be-reconstructed event
137  event = treebuffer.GetCurrentEvent();
138 
139  /// We process the hit list through the tracking worker
140  trackingworker.ProcessEvent(&detectors, event);
141 
142  // Fill the tree
143  rootfile->FillTree("event_tree");
144 
145  // Event has been processed
146  nevents++;
147 
148  } // end of loop over events
149 
150  /// Stop timer
151  timer.Stop();
152  // Print timer info
153  PrintInfo(timer);
154 
155  QwMessage << "\nNumber of events processed at end of run: "
156  << treebuffer.GetEventNumber() << QwLog::endl;
157 
158  treebuffer.PrintStatInfo(trackingworker.R2Good, trackingworker.R3Good, trackingworker.nbridged);
159 
160  // Write and close file (after last access to ROOT tree)
161  rootfile->Write(0, TObject::kOverwrite);
162 
163  // Close ROOT file
164  rootfile->Close();
165 
166  // Delete objects (this is confusing: the if only applies to the delete)
167  if (rootfile) delete rootfile; rootfile = 0;
168 
169  // Close input file
170  treebuffer.CloseFile();
171 
172  } // end of loop over runs
173 
174  return 0;
175 }
#define QwMessage
Predefined log drain for regular messages.
Definition: QwLog.h:50
static void AppendToSearchPath(const TString &searchdir)
Add a directory to the search path.
Read simulated QweakSimG4 events and generate hit lists.
Int_t WriteParamFileList(const TString &name, T &object)
Definition: QwRootFile.h:736
TTree * GetTree(const std::string &name)
Get the tree with name.
Definition: QwRootFile.h:353
void Close()
Definition: QwRootFile.h:416
QwOptions gQwOptions
Definition: QwOptions.cc:27
void ProcessOptions(QwOptions *options)
Process class options for QwOptions.
Definition: QwLog.cc:108
Int_t FillTree(const std::string &name)
Fill the tree with name.
Definition: QwRootFile.h:359
Controls all the routines involved in finding tracks in an event.
Contains a tracked event, i.e. all information from hits to tracks.
Definition: QwEvent.h:156
A wrapper class for a ROOT file or memory mapped file.
Definition: QwRootFile.h:281
Int_t Write(const char *name=0, Int_t option=0, Int_t bufsize=0)
Definition: QwRootFile.h:437
void PrintInfo(TStopwatch &timer)
void NewTree(const std::string &name, const std::string &desc)
Create a new tree with name and description.
Definition: QwRootFile.h:341
void Reset(Option_t *option="")
Definition: QwEvent.cc:86
static void SetDefaultRootFileStem(const std::string &stem)
Set default ROOT file stem.
Definition: QwRootFile.h:296
static std::ostream & endl(std::ostream &)
End of the line.
Definition: QwLog.cc:299
const std::string getenv_safe_string(const char *name)
Definition: QwOptions.h:37
Collection of QwDetectorInfo pointers that specifies an experimental geometry.
Definition: QwGeometry.h:27
void DefineOptionsTracking(QwOptions &options)
QwLog gQwLog
Definition: QwLog.cc:22
#define QwError
Predefined log drain for errors.
Definition: QwLog.h:40
void SetCommandLine(int argc, char *argv[], bool default_config_file=true)
Set the command line arguments.
Definition: QwOptions.cc:112

+ Here is the call graph for this function:

void PrintInfo ( TStopwatch &  timer)

Definition at line 45 of file QwSimTracking.cc.

References QwLog::endl(), and QwMessage.

Referenced by main(), and QwBPMStripline< T >::PrintInfo().

46 {
47  QwMessage << "CPU time used: " << timer.CpuTime() << " s"
48  << QwLog::endl
49  << "Real time used: " << timer.RealTime() << " s"
51  return;
52 }
#define QwMessage
Predefined log drain for regular messages.
Definition: QwLog.h:50
static std::ostream & endl(std::ostream &)
End of the line.
Definition: QwLog.cc:299

+ Here is the call graph for this function:

+ Here is the caller graph for this function: