ndrockmacro.C
Go to the documentation of this file.
1 ///////////////////////////////////////////////////
2 //
3 // Macro to calculate the rock overlay rate,
4 // given a list of file names
5 //
6 // Original by R. Murphy, adapted by E. Smith
7 //
8 ///////////////////////////////////////////////////
9 
10 #pragma once
11 
12 #include <iostream>
13 #include <fstream>
14 
15 #include "TFile.h"
16 #include "TTree.h"
17 #include "TLeaf.h"
18 #include "TError.h"
19 #include "TH1.h"
20 
21 // initialize/declare
22 void ndrockmacro(std::string infile, std::string outfile, double desired_pot_per_spill=2.5e+13){
23 
24  TFile* out = new TFile(outfile.c_str(),"RECREATE");
25  TH1D* h_totpot = new TH1D("totpot", ";Total POT", 100, 545e+12, 585e+12);
26  TH1I* h_nevts = new TH1I("nevts", ";Events", 100, 0, 1000);
27  double rock_rate = -5;
28 
29  int nevts = 0;
30  double totpot = 0;
31 
32  gErrorIgnoreLevel = kError;
33 
34  //Create or Open output file and TTree
35 
36  std::cout<<"Reading file: "<<infile<<std::endl;
37  std::ifstream in;
38  in.open(infile.c_str());
39 
40  std::vector<std::string> newfiles;
42  while(in.good()){
43  in >> line;
44  newfiles.push_back(line);
45  }
46 
47  // we are pulling one number per file out
48  int n_entries = newfiles.size();
49 
50  std::cout<<"Looping over files:"<<std::endl;
51  for(int i = 0; i < n_entries; i++){
52  if ( i%(n_entries/100) == 1 ) std::cout<<"n = "<<i<<std::endl;
53 
54  TFile* f = TFile::Open(newfiles[i].c_str(),"READ");
55  TTree* subruns = (TTree*)gDirectory->Get("SubRuns");
56  subruns->GetEntry(0);
57  double pot = subruns->FindLeaf("sumdata::POTSum_generator__Genie.obj.totpot")->GetValue();
58  h_totpot->Fill(pot);
59  totpot += pot;
60 
61  TTree* metadata = (TTree*)gDirectory->Get("EventMetaData");
62  h_nevts->Fill(metadata->GetEntries());
63  nevts += metadata->GetEntries();
64 
65  f->Close();
66  }
67 
68  double avg_totpot = (double)totpot/(double)n_entries;
69  double avg_nevts = (double)nevts/(double)n_entries;
70  rock_rate = desired_pot_per_spill*(avg_nevts/avg_totpot);
71 
72  std::cout<<rock_rate<<std::endl;
73  out->Write();
74  return;
75 }
76 
nevts
Setup runNovaSAM #.
string infile
#define pot
OStream cout
Definition: OStream.cxx:6
void ndrockmacro(std::string infile, std::string outfile, double desired_pot_per_spill=2.5e+13)
Definition: ndrockmacro.C:22
ifstream in
Definition: comparison.C:7
Float_t e
Definition: plot.C:35
FILE * outfile
Definition: dump_event.C:13
enum BeamMode string