HighLAND
Header.cxx
1 #include "Header.hxx"
2 #include "CoreUtils.hxx"
3 #include <stdio.h>
4 #include <iostream>
5 
6 //********************************************************************
8 //********************************************************************
9  Reset();
10 }
11 
12 //********************************************************************
13 void Header::Reset() {
14 //********************************************************************
15 
17  _POT_NoCut = 0;
18  _POT_BadBeam = 0;
19  _POT_BadND280 = 0;
20  _POT_GoodBeamGoodND280 = 0;
21  _POT_0KA = 0;
22  _POT_200KA = 0;
23  _POT_250KA = 0;
24  _POT_m250KA = 0;
25  _POT_OtherKA = 0;
26  _Spill_NoCut = 0;
27  _Spill_BadBeam = 0;
28  _Spill_BadND280 = 0;
29  _Spill_GoodBeamGoodND280 = 0;
30 
32  _IsMC = false;
33  _isFirstFile=true;
34 }
35 
36 //********************************************************************
37 bool Header::AddHeader(TTree* tree, bool bySpillPOT){
38 //********************************************************************
39 
40  if (!tree) return false;
41 
42  double tmp_POT_NoCut, tmp_POT_BadBeam, tmp_POT_BadND280;
43  int tmp_Spill_NoCut, tmp_Spill_BadBeam, tmp_Spill_BadND280;
44  double tmp_POT_GoodBeamGoodND280;
45  int tmp_Spill_GoodBeamGoodND280;
46  double tmp_POT_0KA, tmp_POT_200KA, tmp_POT_250KA, tmp_POT_m250KA, tmp_POT_OtherKA;
47  char tmp_SoftwareVersion[100];
48 
49 
50  if (tree->FindLeaf("POT_NoCut")){
51  anaUtils::ConfigureTreeBranch(tree, "SoftwareVersion", tmp_SoftwareVersion);
52  anaUtils::ConfigureTreeBranch(tree, "POT_NoCut", &tmp_POT_NoCut);
53  anaUtils::ConfigureTreeBranch(tree, "POT_BadBeam", &tmp_POT_BadBeam);
54  anaUtils::ConfigureTreeBranch(tree, "POT_BadND280", &tmp_POT_BadND280);
55  anaUtils::ConfigureTreeBranch(tree, "POT_GoodBeamGoodND280", &tmp_POT_GoodBeamGoodND280);
56  anaUtils::ConfigureTreeBranch(tree, "POT_0KA", &tmp_POT_0KA);
57  anaUtils::ConfigureTreeBranch(tree, "POT_200KA", &tmp_POT_200KA);
58  anaUtils::ConfigureTreeBranch(tree, "POT_250KA", &tmp_POT_250KA);
59  anaUtils::ConfigureTreeBranch(tree, "POT_m250KA", &tmp_POT_m250KA);
60  anaUtils::ConfigureTreeBranch(tree, "POT_OtherKA", &tmp_POT_OtherKA);
61  anaUtils::ConfigureTreeBranch(tree, "Spill_NoCut", &tmp_Spill_NoCut);
62  anaUtils::ConfigureTreeBranch(tree, "Spill_BadBeam", &tmp_Spill_BadBeam);
63  anaUtils::ConfigureTreeBranch(tree, "Spill_BadND280", &tmp_Spill_BadND280);
64  anaUtils::ConfigureTreeBranch(tree, "Spill_GoodBeamGoodND280", &tmp_Spill_GoodBeamGoodND280);
65 
66  // There can be multiple entries in the "header" tree if the analyser has
67  // used hadd to merge multiple output trees. We sum the total POT in all
68  // entries.
69  for (int i = 0; i < tree->GetEntries(); i++) {
70  tree->GetEntry(i);
71  if (!SetSoftwareVersion(tmp_SoftwareVersion)) return false;
72  _POT_CountedPerFile += tmp_POT_NoCut;
73  _POT_NoCut += tmp_POT_NoCut;
74  _POT_BadBeam += tmp_POT_BadBeam;
75  _POT_BadND280 += tmp_POT_BadND280;
76  _POT_GoodBeamGoodND280 += tmp_POT_GoodBeamGoodND280;
77  _POT_0KA += tmp_POT_0KA;
78  _POT_200KA += tmp_POT_200KA;
79  _POT_250KA += tmp_POT_250KA;
80  _POT_m250KA += tmp_POT_m250KA;
81  _POT_OtherKA += tmp_POT_OtherKA;
82  _Spill_NoCut += tmp_Spill_NoCut;
83  _Spill_BadBeam += tmp_Spill_BadBeam;
84  _Spill_BadND280 += tmp_Spill_BadND280;
85  _Spill_GoodBeamGoodND280 += tmp_Spill_GoodBeamGoodND280;
86  }
87  }
88  else{
89  Header *header=0;
90  anaUtils::ConfigureTreeBranch(tree, "POTInfo", &header);
91 
92  // There can be multiple entries in the "header" tree if the analyser has
93  // used hadd to merge multiple output trees. We sum the total POT in all
94  // entries.
95  for (int i = 0; i < tree->GetEntries(); i++) {
96  tree->GetEntry(i);
97  if (!SetIsMC(header->GetIsMC())) return false;
98  if (!SetSoftwareVersion(header->GetSoftwareVersion())) return false;
99 
101  if (!bySpillPOT){
102  _POT_NoCut += header->GetPOTNoCut();
103  _POT_BadBeam += header->GetPOTBadBeam();
104  _POT_BadND280 += header->GetPOTBadND280();
105  _POT_GoodBeamGoodND280 += header->GetPOTGoodBeamGoodND280();
106  _POT_0KA += header->GetPOT0KA();
107  _POT_200KA += header->GetPOT200KA();
108  _POT_250KA += header->GetPOT250KA();
109  _POT_m250KA += header->GetPOTMinus250KA();
110  _POT_OtherKA += header->GetPOTOtherKA();
111  _Spill_NoCut += header->GetSpillNoCut();
112  _Spill_BadBeam += header->GetSpillBadBeam();
113  _Spill_BadND280 += header->GetSpillBadND280();
114  _Spill_GoodBeamGoodND280 += header->GetSpillGoodBeamGoodND280();
115  }
116  }
117  }
118 
119  return true;
120 }
121 
122 //********************************************************************
123 void Header::ReadHeader(TTree* tree){
124 //********************************************************************
125 
126  if (!tree) return;
127  Reset();
128  AddHeader(tree);
129 }
130 
131 //********************************************************************
132 bool Header::AddHeader(const std::string& file, bool bySpillPOT){
133 //********************************************************************
134 
135  TChain chain("header");
136  chain.AddFile(file.c_str());
137  return AddHeader(&chain, bySpillPOT);
138 }
139 
140 //********************************************************************
141 void Header::ReadHeader(const std::string& file){
142 //********************************************************************
143 
144  TChain chain("header");
145  chain.AddFile(file.c_str());
146  ReadHeader(&chain);
147 }
148 
149 //********************************************************************
150 void Header::IncrementPOTByFile(Double_t pot, bool bySpillPOT) {
151 //********************************************************************
152 
153  _POT_CountedPerFile += pot;
154 
155  // When no POT information by spill exists (prod5 MC) POT counting is done by file
156  if (!bySpillPOT){
157  _POT_NoCut += pot;
158  _POT_GoodBeamGoodND280 += pot;
159  }
160 }
161 
162 //********************************************************************
164 //********************************************************************
165 
166  (void)spill;
167 /*
168  const AnaBeamB& beam = *spill.Beam;
169  const AnaEventInfoB& info = *spill.EventInfo;
170 
171  if (beam.POTSincePreviousSavedSpill > 1e+16) {
172  std::cout << "WARNING: POT is suspiciously large for run " << info.Run << ", subrun " << info.SubRun << ", event " << info.Event << ": " << beam.POTSincePreviousSavedSpill << ". POT will not be counted for this event." << std::endl;
173  return;
174  }
175 
176  if (beam.POTSincePreviousSavedSpill < 0) {
177  std::cout << "WARNING: POT is negative for run " << info.Run << ", subrun " << info.SubRun << ", event " << info.Event << ": " << beam.POTSincePreviousSavedSpill << ". POT will not be counted for this event." << std::endl;
178  return;
179  }
180 
181  // For real data
182  if (!spill.GetIsMC()) {
183 
184  _POT_NoCut += beam.POTSincePreviousSavedSpill;
185  _Spill_NoCut += beam.SpillsSincePreviousSavedSpill;
186 
187  if (beam.GoodSpill == 0) {
188  _POT_BadBeam += beam.POTSincePreviousSavedSpill;
189  _Spill_BadBeam += beam.SpillsSincePreviousSavedSpill;
190  return;
191  }
192 
193  if (!spill.DataQuality->GoodDaq) {
194  _POT_BadND280 += beam.POTSincePreviousSavedSpill;
195  _Spill_BadND280 += beam.SpillsSincePreviousSavedSpill;
196  return;
197  }
198 
199  if (beam.GoodSpill == 100) {
200  _POT_0KA += beam.POTSincePreviousSavedSpill;
201  } else if (beam.GoodSpill == 1) {
202  _POT_250KA += beam.POTSincePreviousSavedSpill;
203  } else if (beam.GoodSpill == 2) {
204  _POT_200KA += beam.POTSincePreviousSavedSpill;
205  } else if (beam.GoodSpill == -1) {
206  _POT_m250KA += beam.POTSincePreviousSavedSpill;
207  } else {
208  _POT_OtherKA += beam.POTSincePreviousSavedSpill;
209  }
210 
211  _POT_GoodBeamGoodND280 += beam.POTSincePreviousSavedSpill;
212  _Spill_GoodBeamGoodND280 += beam.SpillsSincePreviousSavedSpill;
213  }
214  else{
215  // For MC there is no information about magnet current, Spill and DQ are always good
216  _Spill_NoCut += beam.SpillsSincePreviousSavedSpill;
217  _Spill_GoodBeamGoodND280 += beam.SpillsSincePreviousSavedSpill;
218 
219  _POT_NoCut += beam.POTSincePreviousSavedSpill;
220  _POT_GoodBeamGoodND280 += beam.POTSincePreviousSavedSpill;
221  }
222 */
223 }
224 
225 //********************************************************************
227 //********************************************************************
228  std::cout << "Initial POT (per File).. " << _POT_CountedPerFile << std::endl;
229  std::cout << "Initial POT............. " << _POT_NoCut << " Spills " << _Spill_NoCut << std::endl;
230  std::cout << "|-- Bad Beam............ " << _POT_BadBeam << " Spills " << _Spill_BadBeam << std::endl;
231  std::cout << "|-- Bad ND280........... " << _POT_BadND280 << " Spills " << _Spill_BadND280 << std::endl;
232  std::cout << "|-- Total Good POT...... " << _POT_GoodBeamGoodND280 << " Spills " << _Spill_GoodBeamGoodND280 << std::endl;
233  std::cout << " |-- @ 0KA............ " << _POT_0KA << std::endl;
234  std::cout << " |-- @ 200KA.......... " << _POT_200KA << std::endl;
235  std::cout << " |-- @ 250KA.......... " << _POT_250KA << std::endl;
236  std::cout << " |-- @ -250KA.......... " << _POT_m250KA << std::endl;
237  std::cout << " |-- @ Other power.... " << _POT_OtherKA << std::endl;
238 }
239 
240 
241 //********************************************************************
242 bool Header::SetIsMC(bool IsMC){
243 //********************************************************************
244 
245  if (!_isFirstFile && _IsMC != IsMC){
246  std::cout << "Header::SetIsMC(). New file with IsMC=" << IsMC << " differs from previous with IsMC=" << _IsMC << ". You cannot mix DATA and MC files !!!" << std::endl;
247  return false;
248  }
249 
250  _isFirstFile = false;
251  _IsMC = IsMC;
252 
253  return true;
254 }
255 
256 //********************************************************************
257 bool Header::SetSoftwareVersion(const std::string& ver){
258 //********************************************************************
259 
260  if (_SoftwareVersion!="" && ver != _SoftwareVersion){
261  std::cout << "Header::SetSoftwareVersion(). New version " << ver << " differs from previous " << _SoftwareVersion << std::endl;
262  return false;
263  }
264  _SoftwareVersion = ver;
265  return true;
266 }
Double_t GetPOTGoodBeamGoodND280()
Get the total POT that passed beam and ND280 quality cuts.
Definition: Header.hxx:54
Double_t GetPOTMinus250KA()
Get the total POT that passed beam and ND280 quality cuts, at -250KA horn current.
Definition: Header.hxx:69
Int_t _Spill_NoCut
Spill info.
Definition: Header.hxx:120
void Reset()
Reset all the information in the header.
Definition: Header.cxx:13
const std::string & GetSoftwareVersion()
Returns the software version.
Definition: Header.hxx:103
Double_t GetPOT0KA()
Get the total POT that passed beam and ND280 quality cuts, at 0KA horn current.
Definition: Header.hxx:60
bool SetSoftwareVersion(const std::string &ver)
Set the software version.
Definition: Header.cxx:257
Double_t GetPOTBadBeam()
Get the total POT that was removed due to bad beam quality.
Definition: Header.hxx:48
void IncrementPOTByFile(Double_t pot, bool bySpillPOT=true)
Definition: Header.cxx:150
Header()
constructor
Definition: Header.cxx:7
This class handles POT info, SoftwareVersion and IsMC.
Definition: Header.hxx:10
Int_t GetSpillBadBeam()
Get the total spills that was removed due to bad beam quality.
Definition: Header.hxx:79
Int_t GetSpillGoodBeamGoodND280()
Get the total spills that passed beam and ND280 quality cuts.
Definition: Header.hxx:85
Double_t _POT_CountedPerFile
POT info.
Definition: Header.hxx:108
std::string _SoftwareVersion
The software version used to create the original oaAnalysis file of the last input file...
Definition: Header.hxx:129
bool _isFirstFile
iternal variable that tell us whether a file has been added previously
Definition: Header.hxx:132
bool GetIsMC() const
returns the Data/MC mode
Definition: Header.hxx:97
void IncrementPOTBySpill(const AnaSpillC &spill)
Definition: Header.cxx:163
Double_t GetPOT200KA()
Get the total POT that passed beam and ND280 quality cuts, at 200KA horn current. ...
Definition: Header.hxx:63
bool _IsMC
data or MC mode
Definition: Header.hxx:126
Double_t GetPOTNoCut()
Get the total recorded POT, before any quality cuts.
Definition: Header.hxx:42
Double_t GetPOTCountedPerFile()
Get the total recorded POT counted per file.
Definition: Header.hxx:45
Double_t GetPOTBadND280()
Get the total POT that was removed due to bad ND280 quality.
Definition: Header.hxx:51
Int_t GetSpillBadND280()
Get the total spills that was removed due to bad ND280 quality.
Definition: Header.hxx:82
bool SetIsMC(bool isMC)
Set the Data/MC mode.
Definition: Header.cxx:242
Double_t GetPOT250KA()
Get the total POT that passed beam and ND280 quality cuts, at 250KA horn current. ...
Definition: Header.hxx:66
Int_t GetSpillNoCut()
Get the total recorded spills, before any quality cuts.
Definition: Header.hxx:76
Double_t GetPOTOtherKA()
Definition: Header.hxx:73
bool AddHeader(const std::string &file, bool bySpillPOT=false)
Read the "header" tree from the given file and increment the existing POT counting.
Definition: Header.cxx:132
void ReadHeader(const std::string &file)
Read the "header" tree from the given file, but reset POT counting first.
Definition: Header.cxx:141
void DumpPOT()
Print the POT information.
Definition: Header.cxx:226