eventAnalysis  7.0-49-g0ac7482
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
TBasicHeaderModule.cxx
Go to the documentation of this file.
1 ///
2 /// For questions or suggestions about this module please contact the
3 /// current responsible and CC in the eventAnalysis package manager.
4 ///
5 /// 23-May-2014: Current responsible for this module is,
6 /// Luke Pickering (lp208 [*a*t*] ic.ac.uk)
7 // include to get environment variables for software version
8 #include <cstdlib>
9 #include "TRegexp.h"
10 #include "TString.h"
11 #include "TBasicHeaderModule.hxx"
12 #include "TG4PrimaryParticle.hxx"
13 #include "TG4PrimaryVertex.hxx"
14 #include "TIntegerDatum.hxx"
15 #include "TND280MCHeader.hxx"
16 #include "TRealDatum.hxx"
17 #include <iostream> // std::cout
18 #include <fstream> // std::ifstream
19 #include "dirent.h"
20 
21 #include "../cvstags/TBasicHeaderModule.cxx"
22 
23 
25 
26  const char *title) {
27  SetNameTitle(name, title);
28  // Enable this module by default:
29  fIsEnabled = kTRUE;
30  fDescription =
31  "Standard module which fills the standard header information "
32  "about an event";
34  fCVSID = CVSID;
35  fSoftware = true;
37 
38  ND::TFieldManager::InitializeFieldManager();
39 }
41 
42 
43 
44 Bool_t ND::TBasicHeaderModule::Configure(std::string &option)
45 {
46  ND280NamedWarn("TBasicHeaderModule"," Configure");
47  ND280NamedWarn("TBasicHeaderModule"," options"<<option);
48 
49 
50  if (option == "noVersion") {
51  ND280NamedWarn("TBasicHeaderModule"," NOT storing software version number in output TTree");
52  fSoftware = false;
53  return true;
54  }
55 
56  if (option.find("OverrideSWVersion") == 0)
57  {
58  TRegexp OverrideVersionREGEXOld("^OverrideSWVersion_v[0-9]+r?[0-9]*p?[0-9]*$");
59  TRegexp OverrideVersionREGEXNew("^OverrideSWVersion_[0-9]+[.][0-9]+[.]*[0-9]*$");
60  TString optTS = option;
61  bool OldStyle=kFALSE;
62  bool NewStyle=kFALSE;
63  if (optTS.Contains(OverrideVersionREGEXOld) )OldStyle=kTRUE;
64  if (optTS.Contains(OverrideVersionREGEXNew) )NewStyle=kTRUE;
65  if(OldStyle || NewStyle) fSoftwareUseOverrideVersion = true;
66  // Call me paranoid but we wouldn't want to cause buffer overflows...
67  size_t len = (option.size() - option.find_first_of('_'));
68  if (len > 49) {
69  ND280NamedError(
70  "TBasicHeaderModule",
71  "The supplied option "
72  << option.substr(option.find_first_of('_'), std::string::npos)
73  << " is too long, please use a shorter version numb"
74  "er.");
75  return false;
76  }
77  if (fSoftwareUseOverrideVersion)
78  {
79  fSoftwareOverrideVersionString =
80  option.substr(option.find_first_of('_') + 1, std::string::npos);
81  ND280NamedLog("TBasicHeaderModule",
82  "Software Version override found version : " << fSoftwareOverrideVersionString);
83  return true;
84  }
85  else
86  {
87  ND280NamedError("TBasicHeaderModule",
88  "Found option \"" << option
89  << "\""
90  " which is malformed, should be "
91  "matched by ^OverrideVersion_v[0-9]+"
92  "r?[0-9]*p?[0-9]*$"
93  " or "
94  "^OverrideSWVersion_"
95  "[0-9]+[.][0-9]+[.]*[0-9]*$"
96  );
97  return false;
98  }
99 
100  }
101  if (option == "software_version") {
102  ND280NamedWarn("TBasicHeaderModule"," Storing software version deduced from environment variables");
103  fSoftware = true;
104  return true;
105  }
106 
107  // unrecognised option found
108  ND280Error(""<<"TBasicHeaderModule argument \""<<option<<"\" is not valid. "<<std::endl<<" Valid values are: noVersion, software_version ( uses environment variables) , or "<<std::endl<<
109  " matching regular expression: OverrideVersion_v[0-9]+r?[0-9]*p?[0-9] or OverrideSWVersion_[0-9]+[.][0-9]+[.]*[0-9]"
110  );
111  return false;
112 }
114 // HEADER INFO
115  fOutputTree->Branch("EventTime", &fEventTime, "EventTime/i", fBufferSize);
116  fOutputTree->Branch("TriggerWord", &fTriggerWord, "TriggerWord/l",
117  fBufferSize);
118  fOutputTree->Branch("FGDCosmicEvent", &fFGDCosmicEvent, "FGDCosmicEvent/O",
119  fBufferSize);
120  fOutputTree->Branch("TripTCosmicEvent", &fTripTCosmicEvent,
121  "TripTCosmicEvent/O", fBufferSize);
122  fOutputTree->Branch("CTMTriggerPattern", fCTMTriggerPattern,
123  "CTMTriggerPattern[3]/l", fBufferSize);
124  fOutputTree->Branch("TripTCosmicTriggerType", &fTripTCosmicTriggerType,
125  "TripTCosmicTriggerType/I", fBufferSize);
126  fOutputTree->Branch("TripTCosmicTriggerUpward", &fTripTCosmicTriggerUpward,
127  "TripTCosmicTriggerUpward/I", fBufferSize);
128  fOutputTree->Branch("CosmicPrescaleWeight", &fCosmicPrescaleWeight,
129  "CosmicPrescaleWeight/D", fBufferSize);
130  fOutputTree->Branch("SoftwareVersion", fSoftwareVersion, "SoftwareVersion/C",
131  fBufferSize);
132  fOutputTree->Branch("MagneticFieldStrength", &fMagneticFieldStrength,
133  "MagneticFieldStrength/D", fBufferSize);
134 // Get context info
135  fOutputTree->Branch("Partition", &fPartition, "Partition/I", fBufferSize);
136  fOutputTree->Branch("Spill", &fSpill, "Spill/I", fBufferSize);
137  fOutputTree->Branch("TimeStamp", &fTimeStamp, "TimeStamp/I", fBufferSize);
138  fOutputTree->Branch("IsDetector", &fIsDetector, "IsDetector/O", fBufferSize);
139  fOutputTree->Branch("IsMC", &fIsMC, "IsMC/O", fBufferSize);
140 // fOutputTree->Branch("IsSand", &fIsSand,
141 // "IsSand/O", fBufferSize);
142  fOutputTree->Branch("P0DWaterStatus", &fP0DWaterStatus, "P0DWaterStatus/O",
143  fBufferSize);
144  fOutputTree->Branch("GeometryHash", fGeometryHash, "GeometryHash[5]/i",
145  fBufferSize);
146  fOutputTree->Branch("AlignmentId", fAlignmentId, "fAlignmentId[5]/i",
147  fBufferSize);
148 // MC header information
149  fOutputTree->Branch("POTPerSpill", &fMCIntensity, "POTPerSpill/F",
150  fBufferSize);
151 }
152 
153 bool ND::TBasicHeaderModule::FillTree(ND::TND280Event &event) {
154 
155  ND280Warn(" entered ND::TBasicHeaderModule::FillTree ");
156  ND280NamedWarn("TBasicHeaderModule",
157  "Entered ND::TBasicHeaderModule::FillTree ");
158  ND::TND280Context context = event.GetContext();
159 
160  fPartition = context.GetPartition();
161  fSpill = context.GetSpill();
162  fTimeStamp = context.GetTimeStamp();
163  fIsDetector = context.IsDetector();
164  fIsMC = context.IsMC();
165  fIsSand = fIsMC && ((context.GetRun() / 1000) % 10 == 7);
166  fP0DWaterStatus = this->P0DWaterStatus();
167 
168  ND::TSHAHashValue geoHash = event.GetGeometryHash();
169  ND::TAlignmentId alignId = event.GetAlignmentId();
170  for (std::size_t i = 0; i < 5; ++i) {
171  fGeometryHash[i] = geoHash(i);
172  fAlignmentId[i] = alignId(i);
173  }
174 
175  fMCIntensity = 0;
176  if (event.Get<ND::TND280MCHeader>("truth/mcHeader")) {
177  fMCIntensity =
178  event.Get<ND::TND280MCHeader>("truth/mcHeader")->GetIntensity();
179  }
180 
181  if(fSoftware)
182  ND280NamedWarn("TBasicHeaderModule"," fSoftware is true ");
183  else
184  ND280NamedWarn("TBasicHeaderModule"," fSoftware is false ");
185  if(fSoftwareUseOverrideVersion)
186  ND280NamedWarn("TBasicHeaderModule",
187  " fSoftwareUseOverrideVersion is true - will use value from command line. ");
188  if (fSoftware)
189  {
190  if ( fSoftwareUseOverrideVersion){
191  strcpy(fSoftwareVersion, fSoftwareOverrideVersionString.c_str());
192  ND280NamedInfo("TBasicHeaderModule",
193  "SoftwareVersion branch will be set "
194  "as: "
195  << fSoftwareOverrideVersionString);
196  }
197  else
198  {
199  char *softwareVersionCharOld = getenv("ND280ROOT");
200  char *softwareVersionCharNew = getenv("ND280SOFTWAREMASTERROOT");
201 
202  if( softwareVersionCharNew != NULL )
203  {
204  std::string softwareVersionString = softwareVersionCharNew;
205  size_t lastUnderscore = softwareVersionString.find_last_of("_");
206  softwareVersionString = softwareVersionString.substr(lastUnderscore + 1);
207  // check format of softwareVersionString is valid n.n[.n]
208  TRegexp VersionREGEXNew("^[0-9]+[.][0-9]+[.]*[0-9]*$");
209  TString optTS(softwareVersionString);
210  if (optTS.Contains(VersionREGEXNew) )
211  {
212  strcpy(fSoftwareVersion, softwareVersionString.c_str());
213  ND280NamedInfo("TBasicHeaderModule",
214  "Software Version found from ND280SOFTWAREMASTERROOT : " << softwareVersionString);
215  }
216  else
217  {
218  strcpy(fSoftwareVersion, "NULL");
219  ND280NamedWarn("TBasicHeaderModule",
220  "Software version number "<<optTS<<" found from ND280SOFTWAREMASTERROOT is not correctly formatted "<<
221  "so setting fSoftwareVersion to \"NULL\"");
222  }
223  }
224  else if (softwareVersionCharOld != NULL )
225  {
226  std::string softwareVersionString = softwareVersionCharOld;
227  size_t lastSlash = softwareVersionString.find_last_of("/");
228  softwareVersionString = softwareVersionString.substr(lastSlash + 1);
229  strcpy(fSoftwareVersion, softwareVersionString.c_str());
230  ND280NamedInfo("TBasicHeaderModule",
231  "Software Version found from ND280ROOT: " << softwareVersionString);
232  }
233  else
234  {
235  strcpy(fSoftwareVersion, "NULL");
236  ND280NamedWarn("TBasicHeaderModule",
237  "Couldn't find ND280ROOT or ND280SOFTWAREMASTERROOT, setting "
238  "fSoftwareVersion to \"NULL\"");
239  }
240  }
241 }
242 else
243 {
244  strcpy(fSoftwareVersion, "NULL");
245  ND280NamedWarn("TBasicHeaderModule",
246  "Software version command line option noVersion "
247  "set so , setting fSoftwareVersion to \"NULL\"");
248 }
249 fEventTime = event.GetHeader().GetMCMSecond();
250 
251 fTriggerWord = event.GetHeader().GetTriggerWord();
252 ULong64_t one = 1;
253 ULong64_t shift = one << 55;
254 fTripTCosmicEvent = shift & fTriggerWord;
255 shift = one << 56;
256 fFGDCosmicEvent = shift & fTriggerWord;
257 
258 fMagneticFieldStrength =
259 ND::TFieldManager::GetFieldValue(TVector3(0, 0, -400.0)).Mag();
260 
261 for (int i = 0; i < 3; i++) {
262  fCTMTriggerPattern[i] = event.GetHeader().GetCTMTriggerPattern(i);
263 }
264 
265 fTripTCosmicTriggerType = -1;
266 if (event.Has<ND::TIntegerDatum>("triptCosmicTriggerType")) {
267  fTripTCosmicTriggerType =
268  event.Get<ND::TIntegerDatum>("triptCosmicTriggerType")->GetValue();
269 }
270 
271 fTripTCosmicTriggerUpward = -1;
272 if (event.Has<ND::TIntegerDatum>("triptCosmicTriggerUpward")) {
273  fTripTCosmicTriggerUpward =
274  event.Get<ND::TIntegerDatum>("triptCosmicTriggerUpward")->GetValue();
275 }
276 
277 fCosmicPrescaleWeight = 1;
278 if (event.Has<ND::TRealDatum>("CosmicPrescaleWeight")) {
279  fCosmicPrescaleWeight =
280  event.Get<ND::TRealDatum>("CosmicPrescaleWeight")->GetValue();
281 }
282 
283 return true;
284 
285 }
286 
287 Bool_t ND::TBasicHeaderModule::ProcessFirstEvent(ND::TND280Event &) {
288  return true;
289 }
291  double depth = ND::TGeomInfo::Get().P0D().TargetDepth();
292  if (depth < 1000.0) {
293  return false;
294  } else {
295  return true;
296  }
297 }
Bool_t fSoftwareUseOverrideVersion
Whether we are using a supplied software version. Will override fSoftware.
#define CVSID
virtual void InitializeBranches()
Initialize Branches. Don&#39;t do anything else in this function.
virtual Bool_t ProcessFirstEvent(ND::TND280Event &)
Is called after the first event is loaded in.
bool fSoftware
Whether we are saving the software version from $ND280ROOT.
std::string fDescription
A longish descrition of the analysis.
Bool_t Configure(std::string &)
A function that allows the module to be configured from an external class without any dependencies...
std::string fCVSID
Defined if an official tagged version.
void SetNameTitle(char const *name, char const *title)
std::string fCVSTagName
Defined if an official tagged version.
#define CVSTAG
TBasicHeaderModule(const char *name="BasicHeader", const char *title="Basic Header Module")
For questions or suggestions about this module please contact the current responsible and CC in the e...
virtual bool FillTree(ND::TND280Event &)
Fill all the stuff that goes in the output tree.

Package Summary
Package Name: eventAnalysis
Package Version: 7.0-49-g0ac7482
Package Manager:

Generated on Mon Mar 25 2024 14:43:58 for eventAnalysis by doxygen 1.8.5