Jpp
JDepthDependence.cc
Go to the documentation of this file.
1 #include <iomanip>
2 #include <iostream>
3 #include <sstream>
4 #include <string>
5 
6 #include "TFile.h"
7 #include "TH1D.h"
8 #include "TMath.h"
9 #include "TROOT.h"
10 
11 #include "TApplication.h"
12 #include "TLegend.h"
13 #include "TGraphErrors.h"
14 
16 #include "JDetector/JDetector.hh"
19 #include "Jeep/JParser.hh"
20 #include "Jeep/JMessage.hh"
21 #include "JLang/JString.hh"
23 #include "JSupport/JSupport.hh"
24 
25 
26 namespace {
27 
28  using namespace JPP;
29  using namespace std;
30 
31  double getCount (TH1D* hptr, int muon_threshold) {
32  double count = 0;
33  for (int i = hptr->GetXaxis()->FindBin(muon_threshold); i <= hptr->GetNbinsX(); i++) {
34  count += hptr->GetBinContent(i);
35  }
36  return count;
37  }
38 
39  double getLiveTime (TH1D* hptr, const JModule& module) {
40  string label = getModuleLabel(module);
41  double livetime = hptr->GetBinContent(hptr->GetXaxis()->FindBin(label.c_str()));
42  return livetime;
43  }
44 
45 }
46 
47 /**
48  * \file
49  *
50  * Auxiliary program to find depth dependence of multiplicity rates
51  * \author mlincetto
52  */
53 int main(int argc, char **argv)
54 {
55  using namespace std;
56  using namespace JPP;
57 
58  //-----------------------------------------------------------
59  // parameter interface
60  //-----------------------------------------------------------
61 
62 
63  string inputFile;
64  string outputFile;
65  string detectorFile;
66  int line;
67  int debug;
68  int minMultiplicity;
69  int minLiveTime_s;
70  // string summaryFile;
71 
72  try {
73 
74  JParser<> zap("Auxiliary program to find depth dependence of multiplicity rates");
75 
76  zap['f'] = make_field(inputFile, "JMM input file");
77  zap['o'] = make_field(outputFile, "output file") = "depthdependence.root";
78  // zap['s'] = make_field(summaryFile, "summary file") = "depthdependence.txt";
79  zap['a'] = make_field(detectorFile);
80  zap['d'] = make_field(debug) = 1;
81  zap['l'] = make_field(line) = 1;
82  zap['M'] = make_field(minMultiplicity, "Minimum multiplicity") = 8;
83  zap['T'] = make_field(minLiveTime_s, "Minimum DOM livetime [s] to be eligible for plotting") = 3600;
84 
85  zap(argc, argv);
86  }
87 
88  catch(const exception &error) {
89  FATAL(error.what() << endl);
90  }
91 
92  cout.tie(&cerr);
93 
94 
95  //----------------------
96  // loading detector file
97  //----------------------
98 
100 
101  try {
102  load(detectorFile, detector);
103  }
104  catch(const JException& error) {
105  FATAL(error);
106  }
107 
108  if (detector.empty())
109  FATAL("Empty detector." << endl);
110 
111  const JModuleRouter router(detector);
112 
113  double utm_z = detector.getUTMZ();
114 
115  NOTICE("Detector base UTM z [m]: " << utm_z << endl);
116 
117  //-----------------------------------------------------------
118  // load input files
119  //-----------------------------------------------------------
120 
121 
122  DEBUG("Loading input file " << inputFile << endl);
123 
124  TFile* in = TFile::Open(inputFile.c_str(), "exist");
125 
126  if (in == NULL || !in->IsOpen()) {
127  FATAL("File: " << inputFile << " not opened." << endl);
128  }
129 
130  //-----------------------------------------------------------
131  // recover rates from histograms
132  //-----------------------------------------------------------
133 
134 
135 
136  DEBUG("Loading livetime histogram from " << inputFile << endl);
137 
138  TH1D* liveTime = (TH1D*)in->Get("LiveTime");
139 
140  if (liveTime == NULL) {
141  FATAL("Missing live time histogram.");
142  }
143 
144  vector<double> depth;
145  vector<double> rate_val;
146  vector<double> rate_err;
147 
148  for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
149 
150  if (module->getString() != line) { continue; }
151 
152  STATUS("Loading data histogram for from input file: " << getModuleLabel(*module) << "\t ID = " << module->getID() << endl);
153 
154  TH1D* data_histogram = (TH1D*)in->Get(TString(getModuleLabel(*module)) + "_P");
155 
156  if (data_histogram != NULL) {
157 
158  double data_count = getCount(data_histogram, minMultiplicity);
159  double data_livetime = getLiveTime(liveTime, *module);
160 
161  double module_depth = - utm_z - module->getZ();
162 
163  if (data_livetime > minLiveTime_s) {
164 
165  double val = data_count / data_livetime;
166  double err = sqrt(data_count) / data_livetime;
167 
168  NOTICE(module_depth << " " << val << endl);
169 
170  rate_val.push_back(val);
171  rate_err.push_back(err);
172  depth.push_back( module_depth);
173 
174  }
175 
176  }
177 
178  }
179 
180 
181  TGraph* gr_data = new TGraphErrors(depth.size(), &depth[0], &rate_val[0], 0, &rate_err[0]);
182 
183  gr_data->SetTitle(TString("KM3NeT Preliminary; Depth [m]; Inclusive ") + Form("%d", minMultiplicity) + TString("-fold coincidence rate [Hz]"));
184 
185  TFile out(outputFile.c_str(), "recreate");
186 
187  gr_data->Write();
188 
189  out.Close();
190 
191  return 0;
192 
193 }
JDAQ.hh
JDETECTOR::getModuleLabel
std::string getModuleLabel(const JModuleLocation &location)
Get module label for monitoring and other applications.
Definition: JDetectorToolkit.hh:708
JMessage.hh
JGEOMETRY3D::JVector3D::getZ
double getZ() const
Get z position.
Definition: JVector3D.hh:114
JDETECTOR::load
void load(const JString &file_name, JDetector &detector)
Load detector from input file.
Definition: JDetectorToolkit.hh:476
std::vector< double >
JPARSER::JParser
Utility class to parse command line options.
Definition: JParser.hh:1493
NOTICE
#define NOTICE(A)
Definition: JMessage.hh:64
JString.hh
JSupport.hh
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
debug
int debug
debug level
Definition: JSirene.cc:59
main
int main(int argc, char **argv)
Definition: JDepthDependence.cc:53
JLANG::JObjectID::getID
int getID() const
Get identifier.
Definition: JObjectID.hh:55
JModuleRouter.hh
JDETECTOR::JModule
Data structure for a composite optical module.
Definition: JModule.hh:49
JMultipleFileScanner.hh
STATUS
#define STATUS(A)
Definition: JMessage.hh:63
JParser.hh
JDetectorToolkit.hh
JDETECTOR::JModuleRouter
Router for direct addressing of module data in detector data structure.
Definition: JModuleRouter.hh:34
make_field
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1954
JDETECTOR::JDetector
Detector data structure.
Definition: JDetector.hh:80
JAANET::detector
Detector file.
Definition: JHead.hh:130
DEBUG
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
std
Definition: jaanetDictionary.h:36
JAANET::livetime
Normalisation of MUPAGE events.
Definition: JHead.hh:594
JDetector.hh
FATAL
#define FATAL(A)
Definition: JMessage.hh:67
outputFile
string outputFile
Definition: JDAQTimesliceSelector.cc:37
JLANG::JException
General exception.
Definition: JException.hh:23
JDETECTOR::JModuleLocation::getString
int getString() const
Get string number.
Definition: JModuleLocation.hh:133
JFIT::getCount
int getCount(const JHitL0 &hit)
Get hit count.
Definition: JEvtToolkit.hh:728