-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeadtime.cpp
More file actions
148 lines (130 loc) · 4.05 KB
/
deadtime.cpp
File metadata and controls
148 lines (130 loc) · 4.05 KB
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
/****************************************************************************************
* DANSS data analysis - calculate dead time *
****************************************************************************************/
#include <math.h>
#include <stdio.h>
#include <string.h>
#include "Riostream.h"
#include "TROOT.h"
#include "TMath.h"
#include "TFile.h"
#include "TChain.h"
#include "TNetFile.h"
#include "TRandom.h"
#include "TTree.h"
#include "TBranch.h"
#include "TCanvas.h"
#include "TPostScript.h"
#include "TStyle.h"
#include "TClonesArray.h"
#include "TStopwatch.h"
#include "TTreeCacheUnzip.h"
#include "TRandom.h"
#include "TDirectory.h"
#include "TProcessID.h"
#include "TObject.h"
#include "TClonesArray.h"
#include "TRefArray.h"
#include "TRef.h"
#include "TKey.h"
#include "TGraph.h"
#include "TF1.h"
#include "TH1.h"
#include "TH2.h"
#include "evtbuilder.h"
#define masterTrgRandom 2
#define GFREQ2US (GLOBALFREQ / 1000000.0)
#define AFTERVETO (long long) (90 * GFREQ2US)
#define AFTERTRIG (long long) (50 * GFREQ2US)
#define BEFORETRIG (long long) (80 * GFREQ2US)
int IsVeto(struct DanssEventStruct7 *Event)
{
if (Event->VetoCleanEnergy > 4 || Event->VetoCleanHits >= 2 ||
Event->PmtCleanEnergy + Event->SiPmCleanEnergy*1.08 > 40 || // UGLY !
Event->BottomLayersEnergy > 3) return 1;
return 0;
}
int IsPickUp(struct DanssEventStruct7 *DanssEvent, struct RawHitInfoStruct *RawHits)
{
if (DanssEvent->trigType == masterTrgRandom) return 1; // ignore 1 Hz trigger
if (DanssEvent->VetoCleanHits > 0) return 0;
if ((RawHits->PmtCnt > 0 && 1.0 * DanssEvent->PmtCleanHits / RawHits->PmtCnt < 0.3) ||
1.0 * DanssEvent->SiPmHits / RawHits->SiPmCnt < 0.3) return 1;
return 0;
}
void process(int run, const char *fmt, FILE *fOut)
{
struct DanssEventStruct7 DanssEvent;
struct RawHitInfoStruct RawHits;
TChain *EventChain = NULL;
TChain *RawChain = NULL;
long long GlobalFirst;
long long LiveCnt;
long long PrevEnd;
long long Delta;
int iEvt, nEvt, rEvt;
double RunTime;
double LiveTime;
char *ptr;
char str[1024];
int irc;
sprintf(str, fmt, run/1000, run);
irc = access(str, R_OK);
if (irc) goto fin; // no file
EventChain = new TChain("DanssEvent");
EventChain->SetBranchAddress("Data", &DanssEvent);
RawChain = new TChain("RawHits");
RawChain->SetBranchAddress("RawHits", &RawHits);
irc = EventChain->Add(str, 0);
if (!irc) goto fin; // no run
RawChain->Add(str, 0);
LiveCnt = 0;
nEvt = EventChain->GetEntries();
if (!nEvt) goto fin;
rEvt = (RawChain) ? RawChain->GetEntries() : 0;
if (RawChain && rEvt != nEvt) {
printf("Event chain (%d) and RawHits chain (%d) do not match\n", nEvt, rEvt);
goto fin;
}
EventChain->GetEntry(0);
RawChain->GetEntry(0);
GlobalFirst = DanssEvent.globalTime;
PrevEnd = DanssEvent.globalTime + ((IsVeto(&DanssEvent)) ? AFTERVETO : AFTERTRIG);
for (iEvt = 1; iEvt < nEvt; iEvt++) {
EventChain->GetEntry(iEvt);
RawChain->GetEntry(iEvt);
if (IsPickUp(&DanssEvent, &RawHits)) continue;
Delta = DanssEvent.globalTime - PrevEnd;
Delta -= BEFORETRIG;
if (Delta > 0) LiveCnt += Delta;
PrevEnd = DanssEvent.globalTime + ((IsVeto(&DanssEvent))? AFTERVETO : AFTERTRIG);
}
RunTime = (DanssEvent.globalTime - GlobalFirst) / GLOBALFREQ;
LiveTime = LiveCnt / GLOBALFREQ;
fprintf(fOut, "%6d %6.1f %6.1f %6.1f %7.5f\n",
run, RunTime, LiveTime, RunTime - LiveTime, (RunTime - LiveTime) / RunTime);
fin:
if (EventChain) delete EventChain;
if (RawChain) delete RawChain;
}
int main(int argc, char **argv)
{
int run, first, last;
char fmt[1024];
FILE *fOut;
if (argc < 4) {
printf("Usage: %s run_first run_last base_dir\n", argv[0]);
printf("Will process files and count time alive\n");
return 10;
}
first = strtol(argv[1], NULL, 10);
last = strtol(argv[2], NULL, 10);
sprintf(fmt, "%s/deadtime/dead_%6.6d_%6.6d.txt", argv[3], first, last);
fOut = fopen(fmt, "wt");
if (!fOut) return 20;
sprintf(fmt, "%s/%%3.3dxxx/danss_%%6.6d.root", argv[3]);
fprintf(fOut, "Run Total Alive Dead Fraction\n");
for (run=first; run <= last; run++) process(run, fmt, fOut);
fclose(fOut);
return 0;
}