-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetLeptonJetsRamData.m
91 lines (79 loc) · 2.44 KB
/
getLeptonJetsRamData.m
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
function [ data, weight ] = getLeptonJetsRamData(muoEle,lepJetType, varargin)
% [ data, weight ] = getLeptonJetsRamData(muoEle, lepJetType, varargin)
%
% Loads mixture of specified sets of leptonJetTypes.
%
% muoEle: 'muo', 'ele'
% lepJetType: leptonJetType, [leptonJetType1,leptonJetType2,...] or [2:18]
%
% VARARGIN:
% val: 0... yield
% 1... train
% 2... test
% 3... data
% njets: 2, 3, 4==(4,5,...)
% type: 0... background ?
% 1... signal ?
%
% EXAMPLE: getLeptonJetsRamData('muo',2:18, 'njets', 2:4, 'val', 0)
% loads all of the channels of muon, all jets (2,3,4) and gets only
% yield sample
%
% getLeptonJetsRamData('muo',2:18, 'njets', 2:4, 'val', [0,1,2])
% loads whole MC.
try leptonJetData = evalin( 'base', 'leptonJetData' );
catch
leptonJetData = leptonJetsMat2Ram();
assignin('base', 'leptonJetData', leptonJetData);
end
Y = getfield(leptonJetData,muoEle);
if ~isreal(lepJetType)
lepJetType = lepJetType.abs;
end
if length(lepJetType) ~= leptonJetType.numTypes
Y = Y(ismember(Y(:,end-4),lepJetType),:);
end
paramStruct = nameValuePairToStruct(struct,varargin);
validStruct = struct('val',0,'njets',0,'type',0);
if (sum(ismember(fieldnames(paramStruct),fieldnames(validStruct))) ~= length(fieldnames(paramStruct)))
error('Fieldnames of structures do not correspond. Check Name-value pairs in the function input.')
end
dataDim = 24;
% last columns of X: "", "NJets","type","Weight","train","val"
try njets = getfield(paramStruct,'njets');
if (length(njets)==1 && njets >=4)
Y = Y(Y(:,end-3)>=njets,:);
else
yFlagsCol = Y(:,end-3);
logic = njets;
Y = filterRows(Y, yFlagsCol, logic);
end
end
% try train = getfield(paramStruct, 'train');
% yFlagsCol = Y(:,end-1);
% logic = train;
% Y = filterRows(Y, yFlagsCol, logic);
%end
try val = getfield(paramStruct,'val');
yFlagsCol = Y(:,end);
logic = val;
Y = filterRows(Y, yFlagsCol, logic);
end
try type = getfield(paramStruct,'type');
yFlagsCol = Y(:,end-2);
logic = type;
Y = filterRows(Y, yFlagsCol, logic);
end
data = Y(:,1:dataDim);
weight = Y(:, end-1);
end
function Y = filterRows(Y, yFlagsCol, logic)
logic = logic(:)';
if length(logic) > 1
YFlagsRep = repmat(yFlagsCol,1,length(logic));
logicRep = repmat(logic, size(YFlagsRep,1),1);
Y = Y(sum(YFlagsRep==logicRep,2)>0,:);
else
Y = Y(yFlagsCol==logic,:);
end
end