MakeDQValidityCSV.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 
21  int pass_cut[7], ngoodcdb, pass_all;
22  double midmiprate, numslc, trkfrac2D;
23 
24  tree->SetBranchAddress("run",&run);
25  tree->SetBranchAddress("subrun",&subrun);
26  tree->SetBranchAddress("dbencoded",&dbencoded);
27  tree->SetBranchAddress("pass_empty",&pass_cut[0]);
28  tree->SetBranchAddress("pass_time",&pass_cut[1]);
29  tree->SetBranchAddress("pass_runlen",&pass_cut[2]);
30  tree->SetBranchAddress("pass_hits",&pass_cut[3]);
31  tree->SetBranchAddress("pass_db",&pass_cut[4]);
32  tree->SetBranchAddress("pass_slc",&pass_cut[5]);
33  tree->SetBranchAddress("pass_trk",&pass_cut[6]);
34  tree->SetBranchAddress("pass_all",&pass_all);
35  tree->SetBranchAddress("ngoodcdb",&ngoodcdb);
36  tree->SetBranchAddress("midmiprate",&midmiprate);
37  tree->SetBranchAddress("numslc",&numslc);
38  tree->SetBranchAddress("trkfrac2D",&trkfrac2D);
39  tree->SetBranchAddress("preliminary",&preliminary);
40 
41  ifstream infile("ManBadRuns.txt");
42 
43  int badrun;
44  set<int> runset;
45  string runcom, runstr;
46  map<int, TString> commap;
47 
48  while(infile.good()){
49  std::getline(infile, runstr, ',');
50  std::getline(infile, runcom, '\n');
51  badrun = TString(runstr).Atoi();
52  runset.insert(badrun);
53  commap[badrun] = runcom;
54  }
55 
56  ofstream procfile;
57  procfile.open("DQValidityTable.csv");
58 
59  vector<TString> comstr;
60  comstr.push_back("Good");
61  comstr.push_back("Empty");
62  comstr.push_back("Bad Timing");
63  comstr.push_back("Short Subrun");
64  comstr.push_back("Bad MIP Hit Rate");
65  comstr.push_back("Bad Diblocks");
66  comstr.push_back("Bad Slicing Rate");
67  comstr.push_back("Bad 3D Tracking Rate");
68 
69  int nentries = tree->GetEntries();
70 
71  TString omFileName;
72 
73 // procfile << "Run,Subrun,Flag,Comment" << endl;
74 
75  for(int i = 0; i < nentries; i++){
76 
77  if(i%(nentries/10)==0) cout << int(100.0*i/nentries+0.5) << "% done" << endl;
78 
79  tree->GetEntry(i);
80 
81  if(preliminary) continue;
82 
83  int flag = 0;
84  int flaglo = 0;
85  TString thiscom = "";
86 
87  if(runset.count(run)!=0 && pass_all){
88  flag = 1 << 7;
89  thiscom = commap[run];
90  }
91  else{
92  for(int j = 6; j >= 0; j--){
93  if(!pass_cut[j]){
94  flag += 1 << j;
95  flaglo = j+1;
96  }
97  }
98  thiscom = comstr[flaglo];
99  }
100 
101  float myslc = numslc;
102  float mytrk = 100*trkfrac2D;
103 
104  if(numslc<0) myslc = -999;
105  if(trkfrac2D<0) mytrk = -999;
106 
107  omFileName = TString::Format("%d,%d,%s,%2.1f,%d,%1.2f,%2.1f,%d,%d",
108  dbencoded, flag, thiscom.Data(),
109  midmiprate, ngoodcdb, myslc, mytrk, 0, run*100 + subrun);
110 
111  procfile << omFileName.Data() << endl;
112 
113  }
114 
115  procfile.close();
116 
117 }
Double_t numslc
Definition: SimpleIterate.C:61
Int_t pass_all
Definition: SimpleIterate.C:42
Double_t trkfrac2D
Definition: SimpleIterate.C:62
Int_t dbencoded
Definition: SimpleIterate.C:54
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
void MakeDQValidityCSV()
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