Jpp  pmt_effective_area_update
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JMergeCalibrateToT.cc File Reference
#include <string>
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include "TROOT.h"
#include "TFile.h"
#include "TH1D.h"
#include "TH2D.h"
#include "TKey.h"
#include "TString.h"
#include "TMath.h"
#include "JROOT/JRootFileReader.hh"
#include "JSupport/JMeta.hh"
#include "JCalibrate/JCalibrateToT.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Function Documentation

int main ( int  argc,
char **  argv 
)
Author
mdejong Auxiliary program to merge time-over-threshold data.

Definition at line 28 of file JMergeCalibrateToT.cc.

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  gErrorIgnoreLevel = kError;
53 
54  typedef map<TString, TH1*> map_type;
55 
56  map_type zmap;
57 
58 
59  for (vector<string>::const_iterator i = inputFile.begin(); i != inputFile.end(); ++i) {
60 
61  DEBUG("Processing " << *i << endl) ;
62 
63  TFile in(i->c_str(), "read");
64 
65  TIter iter(in.GetListOfKeys());
66 
67  for (TKey* key; (key = (TKey*) iter.Next()) != NULL; ) {
68 
69  if (TString(key->GetName()).EndsWith(_2SToT)) {
70 
71  TH2* h2 = dynamic_cast<TH2*>(key->ReadObj());
72 
73  map_type::iterator p = zmap.find(h2->GetName());
74 
75  if (p == zmap.end()) {
76 
77  DEBUG("Clone " << h2->GetName() << endl);
78 
79  p = zmap.insert(make_pair(h2->GetName(), (TH2*) h2->Clone())).first;
80 
81  } else {
82 
83  DEBUG("Add " << h2->GetName() << endl);
84 
85  p->second->Add(h2);
86  }
87  }
88  }
89 
90  for (map_type::iterator i = zmap.begin(); i != zmap.end(); ++i) {
91  i->second->SetDirectory(0);
92  }
93 
94  in.Close();
95  }
96 
97  // write file
98 
99  TFile out(outputFile.c_str(), "recreate");
100 
101  for (map_type::iterator i = zmap.begin(); i != zmap.end(); ++i) {
102 
103  if (i->first.EndsWith(_2SToT)) {
104 
105  TH2D* h2s = (TH2D*) i->second;
106 
107  h2s->Write();
108  }
109  }
110 
111  putObject(&out, JMeta(argc, argv));
112 
113  for (vector<string>::const_iterator i = inputFile.begin(); i != inputFile.end(); ++i) {
114  JMeta::copy(i->c_str(), out);
115  }
116 
117  out.Write();
118  out.Close();
119 }
Utility class to parse command line options.
Definition: JParser.hh:1500
bool putObject(TDirectory *dir, const TObject &object)
Write object to ROOT directory.
string outputFile
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
int debug
debug level
Definition: JSirene.cc:63
#define FATAL(A)
Definition: JMessage.hh:67
then usage $script< input_file >< detector_file > fi set_variable OUTPUT_DIR set_variable SELECTOR JDAQTimesliceL1 set_variable DEBUG case set_variable DEBUG
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 CHECK_EXIT_CODE typeset A TRIPODS get_tripods $WORKDIR tripod txt TRIPODS for EMITTER in
Definition: JCanberra.sh:40