MakeDQValidityCSVND.C
Go to the documentation of this file.
1 #include <map>
2 #include <set>
3 #include <algorithm>
4 #include <iostream>
5 #include <fstream>
6 #include <string>
7 
8 #include <TFile.h>
9 #include <TString.h>
10 #include <TMath.h>
11 #include <TTree.h>
12 
13 using namespace std;
14 
16 
17  TFile file("MetricsTree_All.root","read");
18  TTree *tree = (TTree*)file.Get("mytree");
19  int beam =1;
21  int pass_cut[9], ngoodcdb, pass_all, firstsec, lastsec;
22  double midmiprate, numslc, trkfrac2D;
23  double emptyspillfract, timingpeakstart, timingpeakend;
24 
25  tree->SetBranchAddress("run",&run);
26  tree->SetBranchAddress("subrun",&subrun);
27  tree->SetBranchAddress("nevents",&nevents);
28  tree->SetBranchAddress("pass_duration",&pass_cut[0]);
29  tree->SetBranchAddress("pass_time",&pass_cut[1]);
30  tree->SetBranchAddress("pass_timingpeak",&pass_cut[2]);
31  tree->SetBranchAddress("pass_hits",&pass_cut[3]);
32  tree->SetBranchAddress("pass_db",&pass_cut[4]);
33  tree->SetBranchAddress("passemptyspill",&pass_cut[5]);
34  tree->SetBranchAddress("pass_slc",&pass_cut[7]);
35  tree->SetBranchAddress("pass_trk3D",&pass_cut[8]);
36  tree->SetBranchAddress("pass_reco",&pass_cut[6]);
37  tree->SetBranchAddress("pass_all",&pass_all);
38  tree->SetBranchAddress("ngoodcdb",&ngoodcdb);
39  tree->SetBranchAddress("midmipratePoTscaled",&midmiprate);
40  tree->SetBranchAddress("numslc",&numslc);
41  tree->SetBranchAddress("trkfrac3D",&trkfrac2D);
42  tree->SetBranchAddress("emptyspillfract",&emptyspillfract);
43  tree->SetBranchAddress("timingPeakStart",&timingpeakstart);
44  tree->SetBranchAddress("timingPeakEnd",&timingpeakend);
45  tree->SetBranchAddress("firstsec",&firstsec);
46  tree->SetBranchAddress("lastsec",&lastsec);
47  tree->SetBranchAddress("preliminary",&preliminary);
48 
49  ifstream infile("ListOfBadSubruns_Manual.txt");
50 
51  int badrun;
52  set<int> runset;
53  string runstr;
54 
55  while(infile.good()){
56  std::getline(infile, runstr);
57  badrun = TString(runstr).Atoi();
58  runset.insert(badrun);
59  }
60 
61  ofstream procfile;
62  procfile.open("DQValidityTableND.csv");
63 
64  vector<TString> comstr;
65  comstr.push_back("Good");
66  comstr.push_back("Failed NuMI Live Time");
67  comstr.push_back("Bad Timestamp");
68  comstr.push_back("Bad Timing Peak");
69  comstr.push_back("Bad MIP Hit Rate");
70  comstr.push_back("Bad Diblocks");
71  comstr.push_back("Failed Empty Spill");
72  comstr.push_back("Failed Reco");
73  comstr.push_back("Bad Slicing Rate");
74  comstr.push_back("Bad 3D Tracking Rate");
75  comstr.push_back("Manual Bad Run");
76 
77  int nentries = tree->GetEntries();
78 
79  TString omFileName;
80 
81  for(int i = 0; i < nentries; i++){
82 
83  if(i%(nentries/10)==0) cout << int(100.0*i/nentries+0.5) << "% done" << endl;
84 
85  tree->GetEntry(i);
86 
87  if(preliminary) continue;
88 
89  int flag = 0;
90  int flaglo = 0;
91  TString thiscom = "";
92 
93  if(runset.count((run*1000)+subrun)!=0 && pass_all){
94  flag = 1 << 9;
95  thiscom = comstr[10];
96  }
97  else if(pass_all){
98  flag = 0;
99  thiscom = comstr[0];
100  }
101  else{
102  for(int j = 7; j >= 0; j--){
103  if(!pass_cut[j]){
104  flag += 1 << j;
105  flaglo = j+1;
106  }
107  }
108  thiscom = comstr[flaglo];
109  }
110 
111  float myslc = numslc;
112  float mytrk = 100*trkfrac2D;
113  float mystrt = timingpeakstart;
114  float myend = timingpeakend;
115  int myfsec = firstsec;
116  int mylsec = lastsec;
117  float myempty = emptyspillfract;
118  float mymip = midmiprate;
119 
120  if(numslc<0) myslc = -999;
121  if(trkfrac2D<0) mytrk = -999;
122  if(timingpeakstart < 0) mystrt = -999;
123  if(timingpeakend < 0) myend = -999;
124  if(firstsec<0) myfsec = -999;
125  if(lastsec<0) mylsec = -999;
126  if(emptyspillfract<0) myempty = -999;
127 
128  omFileName = TString::Format("%d,%s,%d,%1.2f,%2.1f,%d,%1.2f,%2.1f,%1.0f,%1.0f,%d,%d,%d,0,%d",
129  flag, thiscom.Data(),nevents,
130  myempty,
131  midmiprate, ngoodcdb, myslc, mytrk, mystrt, myend, myfsec, mylsec, beam, run*100 + subrun);
132 
133  procfile << omFileName.Data() << endl;
134 
135  }
136 
137  procfile.close();
138 
139 }
140 
Int_t lastsec
Definition: SimpleIterate.C:27
Double_t numslc
Definition: SimpleIterate.C:61
Int_t pass_all
Definition: SimpleIterate.C:42
Double_t trkfrac2D
Definition: SimpleIterate.C:62
Int_t nevents
Definition: SimpleIterate.C:25
string infile
Long64_t nentries
Int_t preliminary
Definition: SimpleIterate.C:63
const double j
Definition: BetheBloch.cxx:29
Int_t ngoodcdb
Definition: SimpleIterate.C:33
Double_t midmiprate
Definition: SimpleIterate.C:49
OStream cout
Definition: OStream.cxx:6
Int_t firstsec
Definition: SimpleIterate.C:26
ofstream procfile
TFile * file
Definition: cellShifts.C:17
void Format(TGraph *gr, int lcol, int lsty, int lwid, int mcol, int msty, double msiz)
Definition: Style.cxx:154
void MakeDQValidityCSVND()