All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CRTMergePreProcessTrees.cxx
Go to the documentation of this file.
1 #ifndef CRTMergePreProcessTrees_CXX
2 #define CRTMergePreProcessTrees_CXX
3 
4 #include <TTree.h>
5 #include <TFile.h>
6 
7 #include <map>
8 
9 #include "./CRTPreProcessTree.h"
10 //#include "./CRTRawTree.h"
11 #include "./CRTTiming.h"
12 
13 //#include "icaruscode/CRT/CRTDecoder/CRTPreProcessTree.h"
14 //#include "icaruscode/CRT/CRTDecoder/CRTRawTree.h"
15 //#include "icaruscode/CRT/CRTDecoder/CRTTiming.h"
16 
17 
18 using namespace std;
19 
20 //takes 2 args
21 //to run: ./CRTMergePreProcessTrees <input file name>.root <output file name>.root
22 int main(int argc, char *argv[]) {
23 
24  cout << "Opening file for reading with name, '" << argv[1] << "'" << endl;
25 
26  cout << "Opening new file for writing with name, '" << argv[2] << "'" << endl;
27 
28  uint8_t fMac5;
29  bool fIsNoise;
30  uint8_t fMaxChan;
31  float fMaxPE;
32  float fTotPE;
33  float fPE[32];
34  uint8_t fNChanAbove;
35  bool fAbove[32];
36  bool fActive[32];
37  uint64_t fT0;
38  int fRegion;
39  int fLayer;
40  float fPollRate;
41  float fInstRate;
42 
43  TTree* fAnaTree = new TTree("anaTree","calibrated charge, trigger 'flag', and time ordered entries");
44 
45  fAnaTree->Branch("mac5", &fMac5, "mac5/b");
46  fAnaTree->Branch("pe", fPE, "pe[32]/F");
47  fAnaTree->Branch("active", fActive, "active[32]/O");
48  fAnaTree->Branch("maxChan", &fMaxChan, "maxChan/b");
49  fAnaTree->Branch("maxPE", &fMaxPE, "maxPE/F");
50  fAnaTree->Branch("totPE", &fTotPE, "totPE/F");
51  fAnaTree->Branch("nAbove", &fNChanAbove, "nAbove/b");
52  fAnaTree->Branch("above", fAbove, "above[32]/O");
53  fAnaTree->Branch("isNoise", &fIsNoise, "isNoise/O");
54  fAnaTree->Branch("region", &fRegion, "region/I");
55  fAnaTree->Branch("layer", &fLayer, "layer/I");
56  fAnaTree->Branch("t0", &fT0, "t0/l");
57  fAnaTree->Branch("pollRate", &fPollRate, "pollRate/F");
58  fAnaTree->Branch("instRate", &fInstRate, "instRate/F");
59 
60  TFile fin(argv[1],"READ");
61  TTree* intree = (TTree*)fin.FindObjectAny("anaTree");
63  icarus::crt::CRTTiming ct(cpt);
64 
65  const map<size_t,size_t>* sortedToRaw = ct.GetOrderedToRawMap();
66  std::cout << "done sorting " << sortedToRaw->size() << " entries" << std::endl;
67 
68 
69  TFile fout(argv[2],"RECREATE");
70 
71  std::cout << "filling new, sorted tree..." << std::endl;
72  const size_t nentries = cpt.GetNEntries();
73  for(size_t i=0; i<nentries; i++) {
74 
75  if(i%100000==0)
76  std::cout << 100.0*i/nentries << " % complete" << std::endl;
77 
78  cpt.Load(sortedToRaw->at(i));
79 
80  fMac5 = cpt.Mac5();
81  fIsNoise = cpt.IsNoise();
82  fMaxChan = cpt.MaxChan();
83  fMaxPE = cpt.MaxPE();
84  fTotPE = cpt.TotPE();
85  fNChanAbove = cpt.NChanAbove();
86  fT0 = cpt.T0();
87  fRegion = cpt.Region();
88  fLayer = cpt.Layer();
89  fPollRate = cpt.PollRate();
90  fInstRate = cpt.InstRate();
91 
92  for(size_t ch=0; ch<32; ch++){
93  fPE[ch] = cpt.PE(ch);
94  fAbove[ch] = cpt.Above(ch);
95  fActive[ch] = cpt.Active(ch);
96  }
97 
98  fAnaTree->Fill();
99  }
100  fin.Close();
101 
102  fAnaTree->Write();
103  fout.Close();
104 
105  return 0;
106 }
107 
108 #endif
double std(const std::vector< short > &wf, const double ped_mean, size_t start, size_t nsample)
Definition: UtilFunc.cxx:42
createEngine fT0
void Load(size_t ientry) const
bool Above(uint8_t chan) const
int main(int argc, char **argv)
bool Active(uint8_t chan) const
float PE(uint8_t chan) const
BEGIN_PROLOG could also be cout
const map< size_t, size_t > * GetOrderedToRawMap()
Definition: CRTTiming.cc:58