forked from JeffersonLab/clas12_monitoring
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBAND.java
More file actions
248 lines (225 loc) · 10.8 KB
/
BAND.java
File metadata and controls
248 lines (225 loc) · 10.8 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
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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
import java.io.*;
import java.util.*;
import org.jlab.groot.math.*;
import org.jlab.groot.data.H1F;
import org.jlab.groot.data.H2F;
import org.jlab.groot.math.F1D;
import org.jlab.groot.fitter.DataFitter;
import org.jlab.io.base.DataBank;
import org.jlab.io.base.DataEvent;
import org.jlab.io.hipo.HipoDataSource;
import org.jlab.groot.fitter.ParallelSliceFitter;
import org.jlab.groot.graphics.EmbeddedCanvas;
import org.jlab.groot.data.GraphErrors;
import org.jlab.groot.data.TDirectory;
import org.jlab.clas.physics.Vector3;
import org.jlab.clas.physics.LorentzVector;
import org.jlab.groot.base.GStyle;
public class BAND{
boolean userTimeBased, write_volatile;
int runNum;
boolean[] trigger_bits;
public float EBeam;
public int e_part_ind, e_sect, e_track_ind, pip_part_ind, pipm_part_ind, pip_sect, pim_sect;
public float RFtime, e_mom, e_theta, e_phi, e_vx, e_vy, e_vz, e_ecal_X, e_ecal_Y, e_ecal_Z, e_ecal_E, e_track_chi2, e_vert_time, e_vert_time_RF, e_Q2, e_xB, e_W;
public H1F[] H_BAND_adcCor, H_BAND_meantimeadc, H_BAND_meantimetdc;
public float speedoflight;
public BAND(int reqR, float reqEb, boolean reqTimeBased, boolean reqwrite_volatile){
runNum = reqR;userTimeBased=reqTimeBased;
write_volatile = reqwrite_volatile;
EBeam = 2.2f;
if(reqEb>0 && reqEb<4)EBeam=2.22f;
if(reqEb>4 && reqEb<7.1)EBeam=6.42f;
if(reqEb>7.1 && reqEb<9)EBeam=7.55f;
if(reqEb>9)EBeam=10.6f;
EBeam = reqEb;
trigger_bits = new boolean[32];
H_BAND_adcCor = new H1F[2];
H_BAND_meantimeadc = new H1F[2];
H_BAND_meantimetdc = new H1F[2];
speedoflight = 29.9792458f;
for(int s=0;s<2;s++){
H_BAND_adcCor[s] = new H1F(String.format("H_BAND_ADC_LR_SectorCombination%d",s+1),String.format("H_BAND_ADC_LR_SectorCombination %d",s+1),200,0.,6000.);
H_BAND_adcCor[s].setTitleX("sqrt( adcLcorr * adcRcorr )");
H_BAND_adcCor[s].setTitleY("events");
H_BAND_meantimeadc[s] = new H1F(String.format("H_BAND_MeanTimeFADC_SectorCombination%d",s+1),String.format("H_BAND_MeanTimeFADC_SectorCombination %d",s+1),200,0.,500.);
H_BAND_meantimeadc[s].setTitleX("meantimeFadc – sqrt(x^2+y^2+z^2)/c (ns)");
H_BAND_meantimeadc[s].setTitleY("events");
H_BAND_meantimetdc[s] = new H1F(String.format("H_BAND_MeanTimeTDC_SectorCombination%d",s+1),String.format("H_BAND_MeanTimeTDC_SectorCombination %d",s+1),200,400.,900.);
H_BAND_meantimetdc[s].setTitleX("meantimeTDC – sqrt(x^2+y^2+z^2)/c (ns)");
H_BAND_meantimetdc[s].setTitleY("events");
}
}
public void fill_Histograms_Hits(DataBank bankhits) {
for(int k = 0; k < bankhits.rows(); k++){
float adcL;
float adcR;
float time_fadc;
float time_tdc;
float x, y, z, L;
int sect = 0;
float histo1, histo2, histo3;
sect = bankhits.getInt("sector",k);
adcL = bankhits.getFloat("adcLcorr",k);
adcR = bankhits.getFloat("adcRcorr",k);
histo1 = (float)Math.sqrt(adcL*adcR);
x = bankhits.getFloat("x",k);
y = bankhits.getFloat("y",k);
z = bankhits.getFloat("z",k);
time_fadc = bankhits.getFloat("meantimeFadc",k);
time_tdc = bankhits.getFloat("meantimeTdc",k);
L = (float)Math.sqrt(x*x+y*y+z*z);
histo2 = time_fadc - L/speedoflight;
histo3 = time_tdc - L/speedoflight;
if (sect == 3 || sect == 4) {
H_BAND_adcCor[0].fill(histo1);
H_BAND_meantimeadc[0].fill(histo2);
H_BAND_meantimetdc[0].fill(histo3);
}
if (sect == 1 || sect == 2 || sect == 5) {
H_BAND_adcCor[1].fill(histo1);
H_BAND_meantimeadc[1].fill(histo2);
H_BAND_meantimetdc[1].fill(histo3);
}
}
}
public void processEvent(DataEvent event){
e_part_ind = -1;
RFtime=0;
//DataBank bandhits = null;
//if(event.hasBank("BAND::hits")) {
// bandhits = event.getBank("BAND::hits");
// fill_Histograms_Hits(bandhits);
// }
if(event.hasBank("RUN::config")){
DataBank confbank = event.getBank("RUN::config");
long TriggerWord = confbank.getLong("trigger",0);
for (int i = 31; i >= 0; i--) {trigger_bits[i] = (TriggerWord & (1 << i)) != 0;}
if(event.hasBank("RUN::rf")){
for(int r=0;r<event.getBank("RUN::rf").rows();r++){
if(event.getBank("RUN::rf").getInt("id",r)==1)RFtime=event.getBank("RUN::rf").getFloat("time",r);
}
}
DataBank partBank = null, trackBank = null, trackDetBank = null, ecalBank = null, cherenkovBank = null, scintillBank = null;
DataBank trajBank = null, ltccadcBank = null, ltccClusters = null, bandhits = null;
if(userTimeBased){
if(event.hasBank("REC::Particle"))partBank = event.getBank("REC::Particle");
if(event.hasBank("REC::Track"))trackBank = event.getBank("REC::Track");
if(event.hasBank("TimeBasedTrkg::TBTracks"))trackDetBank = event.getBank("TimeBasedTrkg::TBTracks");
if(event.hasBank("REC::Calorimeter")) ecalBank = event.getBank("REC::Calorimeter");
if(event.hasBank("REC::Cherenkov"))cherenkovBank = event.getBank("REC::Cherenkov");
if(event.hasBank("REC::Scintillator"))scintillBank = event.getBank("REC::Scintillator");
if(event.hasBank("REC::Traj"))trajBank = event.getBank("REC::Traj");
if(event.hasBank("LTCC::adc"))ltccadcBank = event.getBank("LTCC::adc");
if(event.hasBank("LTCC::clusters"))ltccClusters = event.getBank("LTCC::clusters");
if(event.hasBank("BAND::hits")) {
bandhits = event.getBank("BAND::hits");
}
}
if(!userTimeBased){
if(event.hasBank("RECHB::Particle"))partBank = event.getBank("RECHB::Particle");
if(event.hasBank("RECHB::Track"))trackBank = event.getBank("RECHB::Track");
if(event.hasBank("HitBasedTrkg::HBTracks"))trackDetBank = event.getBank("HitBasedTrkg::HBTracks");
if(event.hasBank("RECHB::Calorimeter")) ecalBank = event.getBank("RECHB::Calorimeter");
if(event.hasBank("RECHB::Cherenkov"))cherenkovBank = event.getBank("RECHB::Cherenkov");
if(event.hasBank("RECHB::Scintillator"))scintillBank = event.getBank("RECHB::Scintillator");
if(event.hasBank("RECHB::Traj"))trajBank = event.getBank("RECHB::Traj");
if(event.hasBank("LTCC::adc"))ltccadcBank = event.getBank("LTCC::adc");
if(event.hasBank("LTCC::clusters"))ltccClusters = event.getBank("LTCC::clusters");
if(event.hasBank("BAND::hits")) bandhits = event.getBank("BAND::hits");
}
if(bandhits!=null) {
fill_Histograms_Hits(bandhits);
}
}
}
public void plot() {
EmbeddedCanvas can_BAND = new EmbeddedCanvas();
can_BAND.setSize(2500,1500);
can_BAND.divide(3,1);
can_BAND.setAxisTitleSize(24);
can_BAND.setAxisFontSize(30);
can_BAND.setTitleSize(24);
H_BAND_adcCor[0].setLineColor(2);
H_BAND_meantimeadc[0].setLineColor(2);
H_BAND_meantimetdc[0].setLineColor(2);
H_BAND_adcCor[1].setLineColor(4);
H_BAND_meantimeadc[1].setLineColor(4);
H_BAND_meantimetdc[1].setLineColor(4);
can_BAND.cd(0);can_BAND.draw(H_BAND_adcCor[0]);can_BAND.draw(H_BAND_adcCor[1],"same");
can_BAND.cd(1);can_BAND.draw(H_BAND_meantimeadc[0]);can_BAND.draw(H_BAND_meantimeadc[1],"same");
can_BAND.cd(2);can_BAND.draw(H_BAND_meantimetdc[0]);can_BAND.draw(H_BAND_meantimetdc[1],"same");
if(runNum>0){
if(!write_volatile)can_BAND.save(String.format("plots"+runNum+"/BAND.png"));
if(write_volatile)can_BAND.save(String.format("/volatile/clas12/rga/spring18/plots"+runNum+"/BAND.png"));
System.out.println(String.format("saved plots"+runNum+"/BAND.png"));
}
else{
can_BAND.save(String.format("plots/BAND.png"));
System.out.println(String.format("saved plots/BAND.png"));
}
}
public static void main(String[] args) {
System.setProperty("java.awt.headless", "true");
GStyle.setPalette("kRainBow");
int count = 0;
int runNum = 0;
boolean useTB = true;
boolean useVolatile = false;
String filelist = "list_of_files.txt";
if(args.length>0)runNum=Integer.parseInt(args[0]);
if(args.length>1)filelist = args[1];
int maxevents = 20000000;
if(args.length>2)maxevents=Integer.parseInt(args[2]);
float Eb =6.42f;//10.6f;
if(args.length>3)Eb=Float.parseFloat(args[3]);
if(args.length>4)if(Integer.parseInt(args[4])==0)useTB=false;
BAND ana = new BAND(runNum,Eb,useTB,useVolatile);
List<String> toProcessFileNames = new ArrayList<String>();
File file = new File(filelist);
Scanner read;
try {
read = new Scanner(file);
do {
String filename = read.next();
toProcessFileNames.add(filename);
}while (read.hasNext());
read.close();
}catch(IOException e){
e.printStackTrace();
}
int progresscount=0;int filetot = toProcessFileNames.size();
for (String runstrg : toProcessFileNames) if( count<maxevents ){
progresscount++;
System.out.println(String.format(">>>>>>>>>>>>>>>> %s",runstrg));
File varTmpDir = new File(runstrg);
if(!varTmpDir.exists()){System.out.println("FILE DOES NOT EXIST");continue;}
System.out.println("READING NOW "+runstrg);
HipoDataSource reader = new HipoDataSource();
reader.open(runstrg);
int filecount = 0;
while(reader.hasEvent()&& count<maxevents ) {
DataEvent event = reader.getNextEvent();
ana.processEvent(event);
filecount++;count++;
if(count%10000 == 0) System.out.println(count/1000 + "k events (this is BAND analysis on "+runstrg+") ; progress : "+progresscount+"/"+filetot);
}
reader.close();
}
System.out.println("Total : " + count + " events");
ana.plot();
ana.write();
}
public void write() {
TDirectory dirout = new TDirectory();
dirout.mkdir("/BAND/");
dirout.cd("/BAND/");
for(int j=0;j<2;j++){
dirout.addDataSet(H_BAND_adcCor[j], H_BAND_meantimeadc[j], H_BAND_meantimetdc[j]);
}
if(!write_volatile){
if(runNum>0)dirout.writeFile("plots"+runNum+"/out_BAND_"+runNum+".hipo");
else dirout.writeFile("plots/out_BAND.hipo");
}
}
}