-
Notifications
You must be signed in to change notification settings - Fork 2
/
chargeSum.cpp
73 lines (53 loc) · 1.85 KB
/
chargeSum.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// calculate total analyzed charge for an example event loop
// with QA cuts enabled
// - you must specify a hipo file as an argument
#include <iostream>
// clas12root headers
#include "hipo4/reader.h"
#include "clas12reader.h"
// QADB header and namespace
#include "QADB.h"
using namespace QA;
using namespace clas12; // for clas12root
using namespace std;
int main(int argc, char** argv) {
// instantiate clas12reader object for specified hipo file
string infileN;
if(argc<=1) {
cerr << "USAGE: " << argv[0] << " [hipo file]" << endl;
exit(0);
};
clas12reader * c12 = new clas12reader(string(argv[1]));
// instantiate QADB
QADB * qa = new QADB("latest");
// alternatively, specify run range to restrict QADB (may be more efficient)
//QADB * qa = new QADB("latest",5000,5500);
// define variables
int runnum,evnum;
int evCount = 0;
// event loop
cout << "begin event loop..." << endl;
while(c12->next()==true) {
if(evCount%10000==0) cout << evCount << " events analyzed" << endl;
// truncate event loop (for quick testing)
if(evCount>1e5) { cout << "event loop truncated!" << endl; break; };
// get run number and event number
runnum = c12->runconfig()->getRun();
evnum = c12->runconfig()->getEvent();
// QA cuts
if(qa->OkForAsymmetry(runnum,evnum)) {
// accumulate charge; note that although the call to
// QADB::accumulateCharge() charge happens for each
// event within a QA bin that passed the QA cuts, that
// bin's charge will only be accumulated once, so
// overcounting is not possible
qa->AccumulateCharge();
/* continue your analysis here */
};
evCount++;
};
// print charge
cout << "\ntotal accumulated charge analyzed: " << endl;
cout << "run=" << runnum << " charge=" <<
qa->GetAccumulatedCharge() << " nC" << endl;
};