QwAnalysis
QwSimRayTracer.cc
Go to the documentation of this file.
1 // This is an example for testing the bridging code
2 
3 // Qweak tracking headers
4 #include "QwOptionsTracking.h"
5 #include "QwParameterFile.h"
7 #include "QwRayTracer.h"
8 #include "QwMatrixLookup.h"
9 
10 #include "QwTreeEventBuffer.h"
12 //#include "QwGasElectronMultiplier.h"
13 #include "QwDriftChamberHDC.h"
14 #include "QwDriftChamberVDC.h"
15 
16 // Qweak event
17 #include "QwEvent.h"
18 
19 
20 /**
21  * Main function
22  * @param argc Number of arguments
23  * @param argv[] List of arguments
24  * @return Return code
25  */
26 int main (int argc, char* argv[])
27 {
28  // Debug flag
29  bool debug = true;
30 
31  // Create a timer
32  TStopwatch timer;
33 
34  /// Command line options
35  gQwOptions.SetCommandLine(argc, argv);
36  gQwOptions.SetConfigFile("qwsimtracking.conf");
37  // Define the command line options
39 
40  QwParameterFile::AppendToSearchPath(getenv_safe_string("QWSCRATCH") + "/setupfiles");
41  QwParameterFile::AppendToSearchPath(getenv_safe_string("QWANALYSIS") + "/Tracking/prminput");
42 
43  /// Load the tracking detectors from file
45  detectors->ProcessOptions(gQwOptions);
46 
47  // Get detector geometry
48  QwGeometry geometry = detectors->GetGeometry();
49 
50  /// Create a track filter
51  QwBridgingTrackFilter* trackfilter = new QwBridgingTrackFilter();
52 
53  /// Create a lookup table bridging method
54  QwMatrixLookup* matrixlookup = new QwMatrixLookup(gQwOptions);
55  // Determine lookup table file from environment variables
56  std::string trajmatrix = "";
57  if (getenv("QW_LOOKUP"))
58  trajmatrix = std::string(getenv("QW_LOOKUP")) + "/QwTrajMatrix.root";
59  else
60  QwWarning << "Environment variable QW_LOOKUP not defined." << QwLog::endl;
61  // Load lookup table
62  if (! matrixlookup->LoadTrajMatrix(trajmatrix))
63  QwError << "Could not load trajectory lookup table!" << QwLog::endl;
64 
65  /// Create a ray tracer bridging method
66  QwRayTracer* raytracer = new QwRayTracer(gQwOptions);
67 
68  /// Load the simulated event file
69  QwTreeEventBuffer* treebuffer = new QwTreeEventBuffer(geometry);
70  treebuffer->ProcessOptions(gQwOptions);
71 
72  /// Start loop over all runs
73  while (treebuffer->OpenNextFile() == 0) {
74 
75  // Setup the output file for bridgingresults
76  TString outputfilename = Form(getenv_safe_TString("QWSCRATCH") + "/rootfiles/QwSimBridge_%d.root", treebuffer->GetRunNumber());
77  TFile *file = new TFile(outputfilename, "RECREATE", "Bridging result");
78  file->cd();
79  TTree *tree = new TTree("tree", "Bridging");
80 
81  QwEvent* event = 0;
82  tree->Branch("events", "QwEvent", &event);
83 
84  /// We loop over all requested events.
85  while (treebuffer->GetNextEvent() == 0) {
86 
87  /// Get the generated event
88  event = treebuffer->GetCurrentEvent();
89  QwEventHeader header(treebuffer->GetRunNumber(),treebuffer->GetEventNumber());
90  event->SetEventHeader(header);
91 
92  /// Get the partial tracks in the front and back region
93  std::vector<boost::shared_ptr<QwPartialTrack> > tracks_r2 = treebuffer->CreatePartialTracks(kRegionID2);
94  std::vector<boost::shared_ptr<QwPartialTrack> > tracks_r3 = treebuffer->CreatePartialTracks(kRegionID3);
95 
96  // Process the partial tracks in region 2 and region 3
97  for (size_t i = 0; i < tracks_r2.size(); i++) {
98  for (size_t j = 0; j < tracks_r3.size(); j++) {
99 
100  // Filter tracks based on parameters (TODO filter should go somewhere else)
101  int status = trackfilter->Filter(tracks_r2.at(i).get(), tracks_r3.at(j).get());
102  if (status != 0) {
103  QwMessage << "Track did not pass filter." << QwLog::endl;
104  continue;
105  }
106 
107  // Bridge using the lookup table
108  timer.Start();
109  const QwTrack* track1 = matrixlookup->Bridge(tracks_r2.at(i).get(), tracks_r3.at(j).get());
110  timer.Stop();
111  timer.Reset();
112  if (track1) {
113  event->AddTrack(track1);
114  continue;
115  } else QwMessage << "Matrix lookup failed." << QwLog::endl;
116 
117  // Bridge using the ray tracer
118  timer.Start();
119  const QwTrack* track2 = raytracer->Bridge(tracks_r2.at(i).get(), tracks_r3.at(j).get());
120  timer.Stop();
121  timer.Reset();
122  if (track2) {
123  event->AddTrack(track2);
124  continue;
125  } else QwMessage << "Ray tracer failed." << QwLog::endl;
126 
127  } // end of back track loop
128  } // end of front track loop
129 
130 
131  // Print the event
132  if (debug) event->Print();
133 
134  // Write event to tree
135  tree->Fill();
136 
137 
138  } // end of the loop over events
139 
140  // Write output root file
141  file->Write(0, TObject::kOverwrite);
142  file->Close();
143  delete file;
144 
145  } // end of the loop over runs
146 
147  // Delete objects
148  delete raytracer;
149  delete matrixlookup;
150 
151  return 0;
152 
153 }
154 
#define QwMessage
Predefined log drain for regular messages.
Definition: QwLog.h:50
int GetRunNumber() const
Get the current run number.
static void AppendToSearchPath(const TString &searchdir)
Add a directory to the search path.
QwEvent * GetCurrentEvent() const
Get the current event.
Read simulated QweakSimG4 events and generate hit lists.
Definition of the ray-tracing bridging method for R2/R3 partial tracks.
const TString getenv_safe_TString(const char *name)
Definition: QwOptions.h:40
Contains header information of a tracked event.
Definition: QwEvent.h:37
Load the options for the tracking subsystems.
unsigned int OpenNextFile()
Open the next event file.
Definition of the class that reads simulated QweakSimG4 events.
Definition of the matrix lookup bridging method.
QwOptions gQwOptions
Definition: QwOptions.cc:27
void ProcessOptions(QwOptions &options)
Process configuration options (default behavior)
EStatus Filter(const QwPartialTrack *front, const QwPartialTrack *back) const
Filter front and back track combinations.
Track filter for the bridging methods.
Contains a tracked event, i.e. all information from hits to tracks.
Definition: QwEvent.h:156
void SetConfigFile(const std::string &configfile)
Set a configuration file.
Definition: QwOptions.h:192
Contains the complete track as a concatenation of partial tracks.
Definition: QwTrack.h:30
unsigned int GetNextEvent()
Read the next event.
const QwTrack * Bridge(const QwPartialTrack *front, const QwPartialTrack *back)
Bridge from the front to back partial track.
Definition: QwRayTracer.cc:178
const QwGeometry GetGeometry()
Get the detector info for all detectors.
static std::ostream & endl(std::ostream &)
End of the line.
Definition: QwLog.cc:299
std::vector< boost::shared_ptr< QwPartialTrack > > CreatePartialTracks(EQwRegionID region) const
Get the partial tracks.
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
Definition of the track filter for the bridging methods.
bool LoadTrajMatrix(const std::string filename)
Load the trajectory matrix from disk.
#define QwWarning
Predefined log drain for warnings.
Definition: QwLog.h:45
void ProcessOptions(QwOptions &options)
Process command line and config file options.
int main(int argc, char **argv)
Definition: QwRoot.cc:20
int GetEventNumber() const
Get the current event number.
const QwTrack * Bridge(const QwPartialTrack *front, const QwPartialTrack *back)
Bridge from the front to back partial track.
void DefineOptionsTracking(QwOptions &options)
#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