Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JMergeCalibrateToT.cc
Go to the documentation of this file.
1 
2 #include <string>
3 #include <iostream>
4 #include <iomanip>
5 #include <vector>
6 #include <map>
7 
8 #include "TROOT.h"
9 #include "TFile.h"
10 #include "TH1D.h"
11 #include "TH2D.h"
12 #include "TKey.h"
13 #include "TString.h"
14 #include "TMath.h"
15 
16 #include "JROOT/JRootFileReader.hh"
17 #include "JSupport/JMeta.hh"
18 
20 
21 #include "Jeep/JParser.hh"
22 #include "Jeep/JMessage.hh"
23 
24 /**
25  * \author mdejong
26  * Auxiliary program to merge time-over-threshold data.
27  */
28 int main(int argc, char **argv)
29 {
30  using namespace std;
31  using namespace JPP;
32 
33  vector<string> inputFile;
34  string outputFile;
35  int debug;
36 
37  try {
38 
39  JParser<> zap("Auxiliary program to merge time-over-threshold data.");
40 
41  zap['f'] = make_field(inputFile, "input file (output from JCalibrateToT).");
42  zap['o'] = make_field(outputFile, "output file (input to JFitToT).") = "merge-tot.root";
43  zap['d'] = make_field(debug, "debug.") = 1;
44 
45  zap(argc, argv);
46  }
47  catch(const exception &error) {
48  FATAL(error.what() << endl);
49  }
50 
51 
52  typedef map<TString, TH1*> map_type;
53 
54  map_type zmap;
55 
56 
57  for (vector<string>::const_iterator i = inputFile.begin(); i != inputFile.end(); ++i) {
58 
59  DEBUG("Processing " << *i << endl) ;
60 
61  TFile in(i->c_str(), "read");
62 
63  TIter iter(in.GetListOfKeys());
64 
65  for (TKey* key; (key = (TKey*) iter.Next()) != NULL; ) {
66 
67  TH2* h2 = dynamic_cast<TH2*>(key->ReadObj());
68 
69  if (h2 != NULL) {
70 
71  map_type::iterator p = zmap.find(h2->GetName());
72 
73  if (p == zmap.end()) {
74 
75  DEBUG("Clone " << h2->GetName() << endl);
76 
77  p = zmap.insert(make_pair(h2->GetName(), (TH2*) h2->Clone())).first;
78 
79  } else {
80 
81  DEBUG("Add " << h2->GetName() << endl);
82 
83  p->second->Add(h2);
84  }
85  }
86  }
87 
88  for (map_type::iterator i = zmap.begin(); i != zmap.end(); ++i) {
89  i->second->SetDirectory(0);
90  }
91 
92  in.Close();
93  }
94 
95  // write file
96 
97  TFile out(outputFile.c_str(), "recreate");
98 
99  for (map_type::iterator i = zmap.begin(); i != zmap.end(); ++i) {
100 
101  if (i->first.EndsWith(_2SToT)) {
102 
103  TH2D* h2s = (TH2D*) i->second;
104 
105  h2s->Write();
106  }
107  }
108 
109  putObject(&out, JMeta(argc, argv));
110 
111  for (vector<string>::const_iterator i = inputFile.begin(); i != inputFile.end(); ++i) {
112  JMeta::copy(i->c_str(), out);
113  }
114 
115  out.Write();
116  out.Close();
117 }
Utility class to parse command line options.
Definition: JParser.hh:1500
int main(int argc, char *argv[])
Definition: Main.cc:15
string outputFile
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
ROOT I/O of application specific meta data.
int debug
debug level
Definition: JSirene.cc:63
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:67
Utility class to parse command line options.
void copy(const Head &from, JHead &to)
Copy header from from to to.
Definition: JHead.cc:139
static const char *const _2SToT
Histogram naming.
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY source JAcoustics sh $DETECTOR_ID typeset A TRIPODS get_tripods $WORKDIR tripod txt TRIPODS for EMITTER in
Definition: JCanberra.sh:36
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
bool putObject(TDirectory *dir, const T &object)
Write object to ROOT directory.