forked from alopez8/MJVetoAnalysis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuiltVetoSimple.C
221 lines (179 loc) · 7.74 KB
/
builtVetoSimple.C
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
/*
builtVetoSimple.C
Clint Wiseman, USC/Majorana
June 2015.
=> This code is run on local data files.
=> The user specifies the input text file of runs inside the code.
=> Makes a TGraph of corruption in the scaler as an example.
=> The main purpose of this code was to develop the "sorting" of separate
QDC cards into one consistent structure, VEvent. This helps to separate processing
from analysis in the code.
=> The veto data should always come out from ORCA in groups of 3: Scaler, QDC1, QDC2.
Once it goes through the MJOR event builder, the scaler data is merged into the QDC entries.
The built data (usually/always) contains TWO QDC entries associated with the same veto event.
In this code, the sorting method checks to see if the "previous" QDC event is the same
as the current one, using the variable "EventCount".
=> There have been difficulties with the eventCount variable. Usually
it goes like 0,0,1,1,2,2,3,3 etc. The QEvent structure has in the past been used
to *force* matching when eventCount goes like 0,1,0,2,1,3... or similar, by saving a
std::list of un-matched QEvents in memory, and using a "fifo" queue for sorting.
Usage:
CINT: root[0] .X builtVetoSimple.C
bash: root -b -q -l builtVetoSimple.C
*/
const int numPanels = 32;
// Structure to hold a complete matched veto event
struct VEvent {
Int_t run; // run number
Int_t vEnt; // qdc eventCount (i.e. entry)
Int_t sEnt; // scaler entry
Int_t card[3]; // 0: scaler ID, 1: qdc card 1 (panels 1-16), 2: qdc card 2 (panels 17-32)
Float_t sTime; // scaler time
Bool_t sTimeBad; // bad scaler entry
Float_t lTime; // LED time
Float_t eTime; // entry time
Int_t QDC[numPanels]; // store qdc values for both cards in the same array
Int_t IsUnderThreshold[numPanels];
Int_t IsOverflow[numPanels];
};
// Structure to hold a qdc entry
struct QEvent{
Int_t runNumber;
UInt_t crate;
UInt_t card;
UInt_t EventCount;
Int_t QDC[16];
Int_t IsUnderThreshold[16];
Int_t IsOverflow[16];
};
void builtVeto(){
// Input a list of run numbers
Char_t InputFile[200] = "builtVeto_DebugList.txt";
ifstream InputList;
InputList.open(InputFile);
Int_t run;
Char_t TheFile[200];
//=== Global counters / variables / plots ===
// get number of files in dataset for the TGraph
Int_t filesToScan = 0;
Int_t filesScanned = 0;
while(!InputList.eof()) { InputList >> run; filesToScan++; }
cout << "Scanning " << filesToScan << " files." << endl;
InputList.close();
InputList.open(InputFile);
run=0;
TGraph *SCorruption = new TGraph(filesToScan);
//=== End ===
// Loop over files
while(!InputList.eof()){
//=== Single-file counters / variables / plots
QEvent qdc = {0};
QEvent prevqdc = {0};
prevqdc.EventCount=-1;
VEvent veto = {0};
Bool_t EventMatch = false;
//=== End ===
InputList >> run;
sprintf(TheFile,"~/dev/datasets/builtVeto/OR_run%i.root",run);
TFile *f = new TFile(TheFile);
TTree *VetoTree = (TTree*)f->Get("VetoTree");
MGTBasicEvent *b = 0;
VetoTree->SetBranchAddress("vetoEvent",&b);
Long64_t nentries = VetoTree->GetEntries();
cout << "Found " << nentries << " entries." << endl;
const int vd_size = 16;
MJTVetoData *vd[vd_size];
VetoTree->GetEntry(0);
for (int i=0; i<vd_size; i++) { vd[i] = dynamic_cast<MJTVetoData*>(b->GetDetectorData()->At(i)); }
cout << "Initialized MJTVetoData" << endl;
// Loop over VetoTree entries
for (int i = 0; i < nentries; i++) {
VetoTree->GetEntry(i);
// move data into QEvent structure
qdc.runNumber=run;
qdc.crate=vd[0]->GetCrate();
qdc.card=vd[0]->GetCard();
qdc.EventCount=vd[0]->GetEventCount();
int k = 0;
for (int j = 0; j<16; j++) {
k = vd[j]->GetChannel();
qdc.QDC[k]=vd[j]->GetAmplitude();
qdc.IsUnderThreshold[k]=vd[j]->IsUnderThreshold();
qdc.IsOverflow[k]=vd[j]->IsOverflow();
}
// check qdc data after moving into QEvent structure
//printf("QDC -- run: %i Entry: %i crate: %i card: %i EventCount: %i \n",qdc.runNumber,i,qdc.crate,qdc.card,qdc.EventCount);
//cout << "QDC: "; for (int k = 0; k<16; ++k) { cout << qdc.QDC[k] << " "; } cout << endl;
//cout << "UTh: "; for (int k = 0; k<16; ++k) { cout << qdc.IsUnderThreshold[k] << " "; } cout << endl;
//cout << "Ovr: "; for (int k = 0; k<16; ++k) { cout << qdc.IsOverflow[k] << " "; } cout << endl;
// check entry numbers
//printf("Entry: %i card: %i EventCount: %i",i,qdc.card,qdc.EventCount);
//printf(" || ScalerCount: %i TimeStamp: %.5f IsBadTs: %i \n",
// vd[0]->GetScalerCount(),vd[0]->GetTimeStamp()/1E8,vd[0]->IsBadTS());
// set flag if current qdc entry has same EventCount as previous one.
EventMatch = false;
if (qdc.EventCount == prevqdc.EventCount) {
EventMatch = true;
//printf("EventMatch true. qdc.EventCount:%i prevqdc.EventCount:%i \n",qdc.EventCount,prevqdc.EventCount);
}
else if (abs(qdc.EventCount - prevqdc.EventCount) > 1 && i > 2) {
printf(" EventCount mismatch! Run:%i current:%i previous:%i card:%i prev.card:%i Breaking at %.0f%% through file.\n",run,i,qdc.card,prevqdc.card,((Float_t)i/nentries)*100);
break;
}
if (EventMatch) {
// move matching events into VEvent structure and incorporate scaler info.
veto.run = qdc.runNumber;
veto.vEnt = qdc.EventCount;
veto.sEnt = vd[0]->GetScalerCount();
veto.sTime = vd[0]->GetTimeStamp()/1E8;
veto.sTimeBad = vd[0]->IsBadTS();
veto.eTime = (Float_t)i/nentries; // needs the duration: pull in fStopTime-fStartTime from MGTEventTree.
// case 1
if (prevqdc.card==11 && qdc.card==18) {
veto.card[0]=vd[0]->GetScalerID();
veto.card[1]=prevqdc.card;
veto.card[2]=qdc.card;
for (int k = 0; k<16; k++) {
veto.QDC[k]=prevqdc.QDC[k];
veto.QDC[16+k]=qdc.QDC[k];
veto.IsUnderThreshold[k]=prevqdc.IsUnderThreshold[k];
veto.IsUnderThreshold[16+k]=qdc.IsUnderThreshold[k];
veto.IsOverflow[k]=prevqdc.IsOverflow[k];
veto.IsOverflow[16+k]=qdc.IsOverflow[k];
}
}
// case 2
else if (prevqdc.card==18 && qdc.card==11) {
veto.card[0]=vd[0]->GetScalerID();
veto.card[1]=qdc.card;
veto.card[2]=prevqdc.card;
for (int k = 0; k<16; k++) {
veto.QDC[k]=qdc.QDC[k];
veto.QDC[16+k]=prevqdc.QDC[k];
veto.IsUnderThreshold[k]=qdc.IsUnderThreshold[k];
veto.IsUnderThreshold[16+k]=prevqdc.IsUnderThreshold[k];
veto.IsOverflow[k]=qdc.IsOverflow[k];
veto.IsOverflow[16+k]=prevqdc.IsOverflow[k];
}
}
else if (prevqdc.card==-1) { cout << "Previous Card was 0, EventMatch: " << EventMatch << endl; continue; }
else { printf("Failed to match! VetoTree entry: %lli Card:%i Prev.Card:%i \n",i,qdc.card,prevqdc.card); break; }
// check VEvent data
printf("run:%i vEnt:%i sEnt:%i card0:%i card1:%i card2:%i sTime:%.5f sTimeBad:%i\n",
veto.run,veto.vEnt,veto.sEnt,veto.card[0],veto.card[1],veto.card[2],veto.sTime,veto.sTimeBad);
//cout << "QDC: "; for (int k = 0; k<numPanels; ++k) { cout << veto.QDC[k] << " "; } cout << endl;
//cout << "UTh: "; for (int k = 0; k<numPanels; ++k) { cout << veto.IsUnderThreshold[k] << " "; } cout << endl;
//cout << "Ovr: "; for (int k = 0; k<numPanels; ++k) { cout << veto.IsOverflow[k] << " "; } cout << endl;
//=====================BEGIN ANALYSIS=================
//=====================END ANALYSIS===================
} // end EventMatch condition
// Save qdc into prevqdc before getting next VetoTree entry.
prevqdc = qdc;
EventMatch = false;
} // End loop over VetoTree entries.
filesScanned++;
} // End loop over files.
// === END OF SCAN Output & Plotting ===
// ==========================
// Close input/output files.
}