Skip to content

Commit

Permalink
small changes towards pf candidate based tagger
Browse files Browse the repository at this point in the history
  • Loading branch information
jkiesele committed Apr 10, 2017
1 parent 3088398 commit 6df1236
Show file tree
Hide file tree
Showing 10 changed files with 90 additions and 85 deletions.
8 changes: 3 additions & 5 deletions Train/DeepJetTrain_PF.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@
startlearnrate=0.0005
from DeepJet_callbacks import DeepJet_callbacks

callbacks=DeepJet_callbacks(stop_patience=100,
callbacks=DeepJet_callbacks(stop_patience=300,

lr_factor=0.5,
lr_patience=3,
lr_epsilon=0.003,
lr_cooldown=6,
lr_minimum=0.00001,
lr_minimum=0.000001,

outputDir=outputDir)
useweights=False
Expand All @@ -76,8 +76,6 @@


from DataCollection import DataCollection
from TrainData_deepCSV_ST import TrainData_deepCSV_ST
from TrainData_deepCSV import TrainData_deepCSV

traind=DataCollection()
traind.readFromFile(inputData)
Expand Down Expand Up @@ -118,7 +116,7 @@
print(traind.getTruthShape()[0])
from DeepJet_models import Dense_model_broad, Dense_model_broad_flat
#model = Dense_model_Rec(inputs,traind.getTruthShape()[0],shapes,0.3)
model = Dense_model_broad_flat(inputs,traind.getTruthShape()[0],shapes,0.1)
model = Dense_model_broad(inputs,traind.getTruthShape()[0],shapes,0.1)
#model = Dense_model_broad(inputs,traind.getTruthShape()[0],shapes,0.1)
print('compiling')

Expand Down
3 changes: 3 additions & 0 deletions convertFromRoot/convertFromRoot.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ def main(argv=None):

from TrainData import TrainData
from TrainData_deepCSV import TrainData_deepCSV
from TrainData_deepConvCSV import TrainData_deepConvCSV
from TrainData_deepCMVA import TrainData_deepCMVA
from TrainData_deepCSV_PF import TrainData_deepCSV_PF,TrainData_deepCSV_miniPF,TrainData_deepCSV_microPF
from TrainData_deepConvCSV import TrainData_deepConvCSV
Expand All @@ -83,6 +84,8 @@ def main(argv=None):
traind=TrainData
if Class == 'TrainData_deepCSV':
traind=TrainData_deepCSV
elif Class == 'TrainData_deepConvCSV':
traind=TrainData_deepConvCSV
elif Class == 'TrainData_deepJet_Reg':
traind=TrainData_deepJet_Reg
elif Class == 'TrainData_deepCSV_PF':
Expand Down
2 changes: 2 additions & 0 deletions modules/DataCollection.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
'''
#from tensorflow.contrib.labeled_tensor import batch
#from builtins import list
from __future__ import print_function

from Weighter import Weighter
from TrainData import TrainData, fileTimeOut
#for convenience
Expand Down
1 change: 1 addition & 0 deletions modules/DeepJet_callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
@author: jkiesele
'''
from __future__ import print_function

from ReduceLROnPlateau import ReduceLROnPlateau
from keras.callbacks import Callback, EarlyStopping,History,ModelCheckpoint #, ReduceLROnPlateau # , TensorBoard
Expand Down
57 changes: 21 additions & 36 deletions modules/DeepJet_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,47 +164,35 @@ def Dense_model_broad(Inputs,nclasses,Inputshapes,dropoutRate=-1):

cpf = Convolution1D(64, 1, kernel_initializer='lecun_uniform', activation='relu')(Inputs[1])
cpf = Dropout(dropoutRate)(cpf)
cpf = Convolution1D(64, 1, kernel_initializer='lecun_uniform', activation='relu')(cpf)
cpf = Dropout(dropoutRate)(cpf)
cpf = Convolution1D(32, 1, kernel_initializer='lecun_uniform', activation='relu')(cpf)
cpf = Dropout(dropoutRate)(cpf)
cpf = Convolution1D(32, 1, kernel_initializer='lecun_uniform', activation='relu')(cpf)
cpf = Dropout(dropoutRate)(cpf)
cpf = Convolution1D(32, 1, kernel_initializer='lecun_uniform', activation='relu')(cpf)
cpf = Dropout(dropoutRate)(cpf)
cpf = Convolution1D(16, 1, kernel_initializer='lecun_uniform', activation='relu')(cpf)
cpf = Convolution1D(8, 1, kernel_initializer='lecun_uniform', activation='relu')(cpf)
cpf = Flatten()(cpf)


npf = Convolution1D(32, 1, kernel_initializer='lecun_uniform', activation='relu',input_shape=Inputshapes[2])(Inputs[2])
npf = Dropout(dropoutRate)(npf)
npf = Convolution1D(16, 1, kernel_initializer='lecun_uniform', activation='relu')(npf)
npf = Dropout(dropoutRate)(npf)
npf = Convolution1D(16, 1, kernel_initializer='lecun_uniform', activation='relu')(npf)
npf = Dropout(dropoutRate)(npf)
npf = Convolution1D(8, 1, kernel_initializer='lecun_uniform', activation='relu')(npf)
npf = Convolution1D(4, 1, kernel_initializer='lecun_uniform', activation='relu')(npf)
npf = Flatten()(npf)

vtx = Convolution1D(64, 1, kernel_initializer='lecun_uniform', activation='relu',input_shape=Inputshapes[3])(Inputs[3])
vtx = Dropout(dropoutRate)(vtx)
vtx = Convolution1D(64, 1, kernel_initializer='lecun_uniform', activation='relu')(vtx)
vtx = Dropout(dropoutRate)(vtx)
vtx = Convolution1D(32, 1, kernel_initializer='lecun_uniform', activation='relu')(vtx)
vtx = Dropout(dropoutRate)(vtx)
vtx = Convolution1D(32, 1, kernel_initializer='lecun_uniform', activation='relu')(vtx)
vtx = Dropout(dropoutRate)(vtx)
vtx = Convolution1D(32, 1, kernel_initializer='lecun_uniform', activation='relu')(vtx)
vtx = Dropout(dropoutRate)(vtx)
vtx = Convolution1D(16, 1, kernel_initializer='lecun_uniform', activation='relu')(vtx)
vtx = Convolution1D(8, 1, kernel_initializer='lecun_uniform', activation='relu')(vtx)
vtx = Flatten()(vtx)


x = merge( [Inputs[0],cpf,npf,vtx ] , mode='concat')


x= Dense(600, activation='relu',kernel_initializer='lecun_uniform')(x)
x = Dropout(dropoutRate)(x)
x= Dense(300, activation='relu',kernel_initializer='lecun_uniform')(x)
x= Dense(350, activation='relu',kernel_initializer='lecun_uniform')(x)
x = Dropout(dropoutRate)(x)
x= Dense(100, activation='relu',kernel_initializer='lecun_uniform')(x)
x = Dropout(dropoutRate)(x)
Expand All @@ -214,7 +202,6 @@ def Dense_model_broad(Inputs,nclasses,Inputshapes,dropoutRate=-1):
x = Dropout(dropoutRate)(x)
x= Dense(100, activation='relu',kernel_initializer='lecun_uniform')(x)
x = Dropout(dropoutRate)(x)
x= Dense(100, activation='relu',kernel_initializer='lecun_uniform')(x)
predictions = Dense(nclasses, activation='softmax',kernel_initializer='lecun_uniform')(x)
model = Model(inputs=Inputs, outputs=predictions)
return model
Expand Down Expand Up @@ -282,22 +269,22 @@ def Dense_model_microPF(Inputs,nclasses,Inputshapes,dropoutRate=-1):

from keras.layers.local import LocallyConnected1D

npf = Convolution1D(32, 1, kernel_initializer='lecun_uniform', activation='relu')(Inputs[1])
npf = Dropout(dropoutRate)(npf)
npf = Convolution1D(8, 1, kernel_initializer='lecun_uniform', activation='relu')(npf)
npf = Dropout(dropoutRate)(npf)
npf = Convolution1D(4, 1, kernel_initializer='lecun_uniform', activation='relu')(npf)
npf = Dropout(dropoutRate)(npf)
npf = Flatten()(npf)
#npf = Convolution1D(32, 1, kernel_initializer='lecun_uniform', activation='relu')(Inputs[1])
#npf = Dropout(dropoutRate)(npf)
#npf = Convolution1D(8, 1, kernel_initializer='lecun_uniform', activation='relu')(npf)
#npf = Dropout(dropoutRate)(npf)
#npf = Convolution1D(4, 1, kernel_initializer='lecun_uniform', activation='relu')(npf)
#npf = Dropout(dropoutRate)(npf)
npf = Flatten()(Inputs[1])



x = merge( [Inputs[0],npf,Inputs[2] ] , mode='concat')
x = merge( [Inputs[0],npf] , mode='concat')


x= Dense(150, activation='relu',kernel_initializer='lecun_uniform')(x)
x= Dense(250, activation='relu',kernel_initializer='lecun_uniform')(x)
x = Dropout(dropoutRate)(x)
x= Dense(100, activation='relu',kernel_initializer='lecun_uniform')(x)
x= Dense(200, activation='relu',kernel_initializer='lecun_uniform')(x)
x = Dropout(dropoutRate)(x)
x= Dense(100, activation='relu',kernel_initializer='lecun_uniform')(x)
x = Dropout(dropoutRate)(x)
Expand All @@ -314,34 +301,32 @@ def Dense_model_ConvCSV(Inputs,nclasses,Inputshape,dropoutRate=0.25):
Inputs similar to 2016 training, but with covolutional layers on each track and sv
"""

a = Convolution1D(32, 1, kernel_initializer='lecun_uniform', activation='relu')(Inputs[1])
a = Convolution1D(8, 1, kernel_initializer='lecun_uniform', activation='relu')(Inputs[1])
a = Dropout(dropoutRate)(a)
a = Convolution1D(32, 1, kernel_initializer='lecun_uniform', activation='relu')(a)
a = Convolution1D(8, 1, kernel_initializer='lecun_uniform', activation='relu')(a)
a = Dropout(dropoutRate)(a)
a = Convolution1D(8, 1, kernel_initializer='lecun_uniform', activation='relu')(a)
a = Dropout(dropoutRate)(a)
a=Flatten()(a)

b = Convolution1D(1, 1, kernel_initializer='lecun_uniform', activation='relu')(Inputs[2])
b = Dropout(dropoutRate)(b)
b =Flatten()(b)

c = Convolution1D(32, 1, kernel_initializer='lecun_uniform', activation='relu')(Inputs[3])
c = Convolution1D(8, 1, kernel_initializer='lecun_uniform', activation='relu')(Inputs[2])
c = Dropout(dropoutRate)(c)
c = Convolution1D(32, 1, kernel_initializer='lecun_uniform', activation='relu')(c)
c = Convolution1D(8, 1, kernel_initializer='lecun_uniform', activation='relu')(c)
c = Dropout(dropoutRate)(c)
c = Convolution1D(8, 1, kernel_initializer='lecun_uniform', activation='relu')(c)
c = Dropout(dropoutRate)(c)
c=Flatten()(c)

x = merge( [Inputs[0],a,b,c] , mode='concat')
x = merge( [Inputs[0],a,c] , mode='concat')

x = Dense(100, activation='relu',kernel_initializer='lecun_uniform')(x)
x = Dropout(dropoutRate)(x)
x = Dense(100, activation='relu',kernel_initializer='lecun_uniform')(x)
x = Dropout(dropoutRate)(x)
x = Dense(100, activation='relu',kernel_initializer='lecun_uniform')(x)
x = Dropout(dropoutRate)(x)
x = Dense(100, activation='relu',kernel_initializer='lecun_uniform')(x)
x = Dropout(dropoutRate)(x)
x= Dense(100, activation='relu',kernel_initializer='lecun_uniform')(x)
predictions = Dense(nclasses, activation='softmax',kernel_initializer='lecun_uniform')(x)
model = Model(inputs=Inputs, outputs=predictions)
Expand Down
1 change: 1 addition & 0 deletions modules/TrainData.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
@author: jkiesele
'''

from __future__ import print_function

from Weighter import Weighter

Expand Down
54 changes: 20 additions & 34 deletions modules/TrainData_deepCSV_PF.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,42 +351,22 @@ def __init__(self):
TrainData.__init__(self)


self.addBranches(['jet_pt', 'jet_eta','nCpfcand','nNpfcand','nsv','npv'])




self.addBranches(['Npfcan_pt',
'Npfcan_ptrel',
'Npfcan_erel',
'Npfcan_phirel',
'Npfcan_etarel',
'Npfcan_deltaR',
'Npfcan_isGamma',
'Npfcan_HadFrac',
'Npfcan_drminsv',
],
15)




#b-tag vars
self.addBranches([ 'TagVarCSV_jetNSecondaryVertices',
self.addBranches(['jet_pt', 'jet_eta','nNpfcand',#'npv',
'TagVarCSV_jetNSecondaryVertices',
'TagVarCSV_trackSumJetEtRatio', 'TagVarCSV_trackSumJetDeltaR',
'TagVarCSV_vertexCategory', 'TagVarCSV_trackSip2dValAboveCharm',
'TagVarCSV_trackSip2dSigAboveCharm', 'TagVarCSV_trackSip3dValAboveCharm',
'TagVarCSV_trackSip3dSigAboveCharm', 'TagVarCSV_jetNSelectedTracks',
'TagVarCSV_jetNTracksEtaRel'])

self.addBranches(['TagVarCSVTrk_trackJetDistVal',
'TagVarCSVTrk_trackPtRel',
'TagVarCSVTrk_trackDeltaR',
'TagVarCSVTrk_trackPtRatio',
'TagVarCSVTrk_trackSip3dSig',
'TagVarCSVTrk_trackSip2dSig',
'TagVarCSVTrk_trackDecayLenVal'],
7)
6)


self.addBranches(['TagVarCSV_trackEtaRel'],4)
Expand All @@ -403,6 +383,17 @@ def __init__(self):



self.addBranches(['Npfcan_pt',
'Npfcan_ptrel',
'Npfcan_erel',
'Npfcan_phirel',
'Npfcan_etarel',
'Npfcan_deltaR',
'Npfcan_isGamma',
'Npfcan_HadFrac',
'Npfcan_drminsv',
],
15)


def readFromRootFile(self,filename,TupleMeanStd, weighter):
Expand All @@ -426,20 +417,16 @@ def readFromRootFile(self,filename,TupleMeanStd, weighter):
# split for convolutional network

x_global = MeanNormZeroPad(filename,TupleMeanStd,
[self.branches[0]],
[self.branchcutoffs[0]],self.nsamples)
self.branches[0:4],
self.branchcutoffs[0:4],self.nsamples)


x_npf = MeanNormZeroPadParticles(filename,TupleMeanStd,
self.branches[1],
self.branchcutoffs[1],self.nsamples)
self.branches[4],
self.branchcutoffs[4],self.nsamples)



x_global_csv = MeanNormZeroPad(filename,TupleMeanStd,
self.branches[2:],
self.branchcutoffs[2:],self.nsamples)



print('took ', sw.getAndReset(), ' seconds for mean norm and zero padding (C module)')
Expand Down Expand Up @@ -471,7 +458,6 @@ def readFromRootFile(self,filename,TupleMeanStd, weighter):
weights=weights[notremoves > 0]
x_global=x_global[notremoves > 0]
x_npf=x_npf[notremoves > 0]
x_global_csv=x_global_csv[notremoves > 0]
alltruth=alltruth[notremoves > 0]

newnsamp=x_global.shape[0]
Expand All @@ -481,7 +467,7 @@ def readFromRootFile(self,filename,TupleMeanStd, weighter):
print(x_global.shape,self.nsamples)

self.w=[weights]
self.x=[x_global,x_npf,x_global_csv]
self.x=[x_global,x_npf]
self.y=[alltruth]


Expand Down
Loading

0 comments on commit 6df1236

Please sign in to comment.