def plotData(self, filename="temp-plot"): xLinspace = np.linspace(0, self.getDataLengthInSec(), self.data.size) Plotter.scatter( x=xLinspace, y=self.data, layout=go.Layout( title=self.dataSource, xaxis=dict( title='Czas trwania [s]' ), yaxis=dict( title='Wartość próbki' ) ), filename=filename )
selection = 'ee' #era = "2016" era = "2017" #era = "2018" config, pathMVA, path, figpath, pathSelections = setConfiguration( selection, era) figpath = dirStructure(figpath) Help = Helper(era) Help.SetPath(path) Help.figpath = figpath Plotter = Plotter() Plotter.SetFig(Help.figpath) Cut = Cuts(path=Help.path) # In[9]: Read = Reader(config) # In[ ]: data = Read.read(reduce=False) # In[ ]: # # Analyser
#bool_index = Testing_data_ndarray['Brho'] > 1.1 #Testing_data_ndarray_cut = Testing_data_ndarray[bool_index] #selection over all branches #ThetaLdeg = Testing_data_ndarray['ThetaLdeg'] #ThetaLdeg_index = np.where(ThetaLdeg > 0.0) #obtain the indices for this condition #ThetaLdeg = ThetaLdeg[ThetaLdeg > 0.0] #cut only one variable #Brho = Testing_data_ndarray['Brho'] #Brho = Brho[ThetaLdeg_index] #cut another variable ''' ----------------------------------------------------------------- Plot variables ------------------------------------------------------------------------------------------------------------------ ------------------------------------------------------------- Using "Plotter" Class --------------------------------------------------------------------------------------------------------------- ''' ################################################ Histo_1D() function ########################################################################################## Histo1D_object = Plotter([ Testing_data_hdf5['Brho'][()] ]) #Create the base with the variables in a Histo1D_object) ######### Some options Histo1D_object.SetFigSize(10, 7) Histo1D_object.SetBinX(100) Histo1D_object.SetFigTitle('Variable 1 histogram 1D', 20) Histo1D_object.SetLimX((0.0, 2.0)) Histo1D_object.SetLabelX('Variable 1', 15) ######### Generate the histogram Histo1D_object.Histo_1D() ######### Save and show the created figure Histo1D_object.SetOutDir(basepath + 'Modules/' + MODULE_name + '/Outputfiles/Figures/')
from Models.Models import * from Models.Scheduler import Scheduler # Definir se os dados if __name__ == '__main__': models = dict( NaiveBayes=NaiveBayes(), LightGbm=LightGbm(), #AdaBoost=AdaBoost(), #RandomForest=RandomForest(), #RegLogistica=Logistic(), ) handler = Handler() plot = Plotter() fe = FeatureEng() # Le dados de resmple - Só pra não demorar muito df_selected_features, df_target, X_test = handler.get_selected_features() df_target = np.ravel(df_target) # Feature Enge df_selected_features = fe.generate_feature(df=df_selected_features) X_test = fe.generate_feature(df=X_test) # Divisão do datset para validacao do modelo X_train, X_valid, y_train, y_valid = train_test_split( df_selected_features, df_target,
#componentList = bkgSamples + sigSamples #componentList = bkgSamples componentList = sigSamples for dataset in componentList: if dataset.isMC: dataset.lumi = 77.30 for component in dataset.componentList: component.maxEvents = nEvents xsWeighter = XSWeighter("XSWeighter") preskimmer = GENPreskimmer("Preskimmer") preskimCounter = GenWeightCounter("GenWeightCounter", postfix="Preskim") fidskimmer = FiducialSkimmer("FiducialSkimmer") fidCounter = GenWeightCounter("GenWeightCounter", postfix="FidicialCut") plotter = Plotter("Plotter", validation_plots) sequence = Sequence() sequence.add(xsWeighter) sequence.add(preskimmer) sequence.add(preskimCounter) sequence.add(fidskimmer) sequence.add(fidCounter) #sequence.add(plotter) cutflows = [ "Preskim", "FidicialCut", ] endModuleOutputDir = "/home/lucien/public_html/" + out_path
import numpy as np import pandas as pd from Handler.Handler import Handler from FE.FE import FeatureEng from Plotter.Plotter import Plotter # Feature Selection plot = Plotter() handler = Handler() fe = FeatureEng() # Le dados de resmple - Só pra não demorar muito df_train, df_target = handler.get_resample() df_target = np.ravel(df_target) # Usar metodos mais avançados df_selected_features, df_importances = fe.check_feature_importance(X=df_train, y=df_target) # Ordena dados df_importances.sort_values(by=['importance'], inplace=True) df_importances['threshold'] = df_importances['importance'].mean() plot.create_bar_plot_h(df=df_importances, x='variable', y='importance')
else: print('No assumed') # Generowanie wykresów if input("Do you want to generate charts? [y/n]:") not in ['no', 'n', 'nah']: generator.plotData(filename="plots/guitar.html") conn = sql.connect('plots/db/results.db') ### PSK result = conn.execute( """ SELECT * FROM results WHERE description=? """, ("PSK - BER to (order, snr)", )).fetchall() Plotter.OrderSnr(result, modType="PSK", filename="plots/PSK/OrderSnr.html") Plotter.OrderSnr2D(result, modType="PSK", filename="plots/PSK/OrderSnr2D.html") result = conn.execute( """ SELECT * FROM results WHERE description=? """, ("PSK - BER to (order, sample frequency)", )).fetchall() Plotter.OrderSampFreq(result, modType="PSK", filename="plots/PSK/OrderSampleFreq.html") Plotter.OrderSampFreq2D(result, modType="PSK", filename="plots/PSK/OrderSampleFreq2D.html")
histo, bin_edges = np.histogram(data_14_degrees['M_Q'][condition_mass_14_q], bins=bins) bin_edges = bin_edges[1:] fig = plt.figure(figsize=(12,7)) plt.plot(bin_edges, histo) peaks, _ = find_peaks(histo, distance = distance, height=height) plt.plot(bin_edges[peaks], histo[peaks], "x") texto = 'Selection:\n Z>0 \n Zi>0 \n 100<M<160 \n 2.6<M_Q<3.5 \n -100<Pf<100 \n -110<Yf<50 \n Xf>-1500 \n MW_Nr>=0 \n Qi==%i' %q plt.text(0.9, 0.8, s=texto, fontsize=12, color='black', transform=plt.gcf().transFigure, bbox=dict(facecolor='white', edgecolor='blue', pad=8.0), ha='center', va='center') plt.savefig(basepath + 'Modules/' + MODULE_name + '/Outputfiles/Figures/14_degrees_peaks/' + '14_degrees_peaks_q_%i.png' %q) print(q) plt.close('all') plt.close(fig) M_vs_M_Q_14_pattern_q = Plotter([data_14_degrees['M_Q'][condition_mass_14_q],data_14_degrees['M'][condition_mass_14_q]]) #Create the base with the variables in a object M_vs_M_Q_14_pattern_q.SetFigSize(12,7) M_vs_M_Q_14_pattern_q.SetBinX(500) M_vs_M_Q_14_pattern_q.SetBinY(500) M_vs_M_Q_14_pattern_q.SetFigTitle(r'M vs M_Q with pattern and q = %i 14$\degree$' %q, 20) M_vs_M_Q_14_pattern_q.SetLabelX('M_Q', 20) M_vs_M_Q_14_pattern_q.SetLabelY('M', 20) M_vs_M_Q_14_pattern_q.SetSizeTicksX(10) M_vs_M_Q_14_pattern_q.SetBoxText('Selection:\n Z>0 \n Zi>0 \n 100<M<160 \n 2.6<M_Q<3.5 \n -100<Pf<100 \n -110<Yf<50 \n Xf>-1500 \n MW_Nr>=0 \n Qi==%i' %q) M_vs_M_Q_14_pattern_q.SetLimX((2.4,3.6)) M_vs_M_Q_14_pattern_q.SetLimY((q*2.5,q*4.0)) M_vs_M_Q_14_pattern_q.Histo_2D() #Draw it #plot pattern charge plt.plot(q_x, q_y, '.-k', label='q = %i' %q) plt.legend()
LambdaFunc('x: x.m_asym_bl[0]')), Plot("m_ct_prop", ["TH1D", "m_ct_prop", "", 16, 0., 800.], LambdaFunc('x: x.m_ct[0]')), ] xsWeighter = XSWeighter("XSWeighter") mediumMuonProducer = PhysObjProducer("MediumMuonProducer", "Muon", "MediumMuons", "Moriond17MediumMuon") mediumElectronProducer = PhysObjProducer("MediumElectronProducer", "Electron", "MediumElectrons", "Moriond17MediumElectron") jetProducer = JetProducer("JetProducer", "Jet", ["MediumMuons", "MediumElectrons"], "LooseJets", "Moriond17LooseJet", 0.4) if ratio_switch: plotter = Plotter("Plotter", ratio_plots) else: plotter = Plotter("Plotter", mc_plots) anaProducer = AnalysisProducer("AnaProducer") sequence = Sequence() sequence.add(mediumMuonProducer) sequence.add(mediumElectronProducer) sequence.add(jetProducer) sequence.add(xsWeighter) sequence.add(anaProducer) sequence.add(plotter) endSequence = EndSequence(skipHadd=False) if not ratio_switch: endModuleOutputDir = "/home/kshi/public_html/mcPlot/"
from Plotter.Plotter import Plotter from Plotter.PlotEndModule import PlotEndModule from RA5.Config.Plotter.PlotDefinition import allPlots nCores = 8 outputDir = "/raid/raid7/lucien/SUSY/RA5/Log/MCDistributions/2018-05-15/AllMCSamples_v1/" nEvents = -1 disableProgressBar = False justEndSequence = False componentList = allMCSamples for dataset in componentList: dataset.lumi = 35.9 sequence = Sequence() xsWeighter = XSWeighter("XSWeighter") sequence.add(xsWeighter) sequence.add(mediumMuonProducer) sequence.add(looseMuonProducer) sequence.add(mediumElectronProducer) sequence.add(looseElectronProducer) sequence.add(jetProducer) sequence.add(Plotter("Plotter", allPlots)) endSequence = EndSequence() endModuleOutputDir = "/home/lucien/public_html/SUSY/RA5/Log/MCDistributions/2018-05-15/AllMCSamples_v1/" endSequence.add(PlotEndModule(endModuleOutputDir, allPlots)) outputInfo = OutputInfo("OutputInfo") outputInfo.outputDir = outputDir outputInfo.TFileName = "MCDistributions.root"
Pf_21 = data_21_degrees['Pf']; Tf_21 = data_21_degrees['Tf'] #mrad Pf_14_21 = data_14_21_degrees['Pf']; Tf_14_21 = data_14_21_degrees['Tf'] #mrad ###################################### conditions ######################################### ############################# original conditions: Z>0, Zi>0, M>0 ######################### condition_14 = (data_14_degrees['Xf'][:] > -1500) & (data_14_degrees['Yf'][:] > -1500) #it is a boolean index to apply in a dataset condition_21 = (data_21_degrees['Xf'][:] > -1500) & (data_21_degrees['Yf'][:] > -1500) #it is a boolean index to apply in a dataset condition_14_21 = (data_14_21_degrees['Xf'][:] > -1500) & (data_14_21_degrees['Yf'][:] > -1500) #it is a boolean index to apply in a dataset ''' ----------------------------------------------------------------- Plot variables ------------------------------------------------------------------------------------------------------------------ ------------------------------------------------------------- Using "Plotter" Class --------------------------------------------------------------------------------------------------------------- ''' ################################################################## 14 degrees Yf_vs_Xf_14 = Plotter([data_14_degrees['Xf'][condition_14], data_14_degrees['Yf'][condition_14]]) #Create the base with the variables in a object Yf_vs_Xf_14.SetFigSize(12,7) Yf_vs_Xf_14.SetBinX(500) Yf_vs_Xf_14.SetBinY(500) Yf_vs_Xf_14.SetFigTitle(r'Yf:Xf 14$\degree$', 20) Yf_vs_Xf_14.SetLabelX('Xf [mm]', 20) Yf_vs_Xf_14.SetLabelY('Yf [mm]', 20) Yf_vs_Xf_14.SetSizeTicksX(10) Yf_vs_Xf_14.SetBoxText('Selection:\n Z>0 \n Zi>0 \n M>0 \n Xf>-1500 \n Yf>-1500') Yf_vs_Xf_14.Histo_2D() #Draw it ######### Save and show the created figure Yf_vs_Xf_14.SetOutDir(basepath + 'Modules/' + MODULE_name + '/Outputfiles/Figures/') Yf_vs_Xf_14.SaveFig('Yf_vs_Xf_14') Yf_vs_Xf_14.Show(1) #show during 1 seconds, the close authomatically Yf_vs_Xf_14.Close() #close all windows, axes and figures running backend del Yf_vs_Xf_14 #erase Yf_vs_Xf_14 (is an object)
#'photonOneScRawE','photonOnePreShowerE','photonOneScBrem', #'genPhotonPt', #'vetoDY','genIsoPass', #'dileptonPt','dileptonEta','dileptonPhi','dileptonM', #'nMuons','nElectrons','nTaus','nPhotons','nJets','nBJets', #'ProbeIDPass','ProbeISOPass','ProbeWorstPass','ProbeSigPass','ProbeIsConv', ] path = "/home/jcordero/CMS/data_"+era+"/"+DataGen+"/SMP_ZG/Files/"+selection+"/"+SampleSet+"/" figpath = "/home/jcordero/CMS/JYCMCMS/SMP_ZG/figs/"+era+"/"+DataGen+"/"+selection+"/" pathSelections = path+"Reduced" Help = Helper(era) Help.figpath = figpath Plotter = Plotter(Help=Help) Plotter.SetFig(Help.figpath) # # Save the Ranges and Bins from Class # In[8]: var = 'ranges' df = pd.DataFrame(getattr(Help,var)) df['part'] = df.index path = "/home/jcordero/CMS/JYCMCMS/SMP_ZG/python/Plotter/" df.to_csv(path+var+'.csv')
############################################# Save ALL variables once cut it Group_name = 'All' #write "All" for all the variables. RAS.Save_hdf5_or_ndarray_object_as_hdf5(Path_to_tree, ['data_runs_14'], Group_name, data_14) #put directly the data array RAS.Save_hdf5_or_ndarray_object_as_hdf5(Path_to_tree, ['data_runs_21'], Group_name, data_21) #put directly the data array ''' ------------------------------------------------------------------------- Analysis --------------------------------------------------------------------------------------------------------------- ''' ################################################ 14 degrees ################################################################ data_hdf5_14 = RAS.Read_hdf5_file(Path_to_tree, 'data_runs_14') M_vs_M_Q_14 = Plotter([data_hdf5_14['M_Q'], data_hdf5_14['M'] ]) #Create the base with the variables in a object M_vs_M_Q_14.SetFigSize(12, 7) M_vs_M_Q_14.SetBinX(50) M_vs_M_Q_14.SetBinY(50) M_vs_M_Q_14.SetFigTitle(r'run97 M vs M_Q 14$\degree$', 20) M_vs_M_Q_14.SetLabelX('M_Q', 20) M_vs_M_Q_14.SetLabelY('M', 20) M_vs_M_Q_14.SetSizeTicksX(10) M_vs_M_Q_14.SetBoxText( 'Selection:\n Z>0 \n Zi>0 \n 70<M<180 \n 2.25<M_Q<4.0 \n -100<Pf<100 \n -110<Yf<50 \n Xf>-1500 \n MW_Nr>=0' ) M_vs_M_Q_14.Histo_2D() #Draw it ######### Save and show the created figure M_vs_M_Q_14.SetOutDir(basepath + 'Modules/' + MODULE_name + '/Outputfiles/Figures/') M_vs_M_Q_14.SaveFig('M_vs_M_Q_14_run97')
(data_21_degrees['Pf'][:] < 100)) condition_14_21 = ((data_14_21_degrees['Xf'][:] > -1500) & (data_14_21_degrees['Yf'][:] > -1500) & (data_14_21_degrees['Yf'][:] > -110) & (data_14_21_degrees['Yf'][:] < 50) & (data_14_21_degrees['Pf'][:] > -100) & (data_14_21_degrees['Pf'][:] < 100)) ''' ----------------------------------------------------------------- Plot variables ------------------------------------------------------------------------------------------------------------------ ------------------------------------------------------------- Using "Plotter" Class --------------------------------------------------------------------------------------------------------------- ''' ################################################################## 14 degrees M_vs_M_Q_14 = Plotter([ data_14_degrees['M_Q'][condition_14], data_14_degrees['M'][condition_14] ]) #Create the base with the variables in a object M_vs_M_Q_14.SetFigSize(12, 7) M_vs_M_Q_14.SetBinX(500) M_vs_M_Q_14.SetBinY(500) M_vs_M_Q_14.SetFigTitle(r'M:M_Q 14$\degree$', 20) M_vs_M_Q_14.SetLabelX('M_Q', 20) M_vs_M_Q_14.SetLabelY('M', 20) M_vs_M_Q_14.SetSizeTicksX(10) M_vs_M_Q_14.SetBoxText( 'Selection:\n Z>0 \n Zi>0 \n M>0 \n -100<Pf<100 \n -110<Yf<50 \n Xf>-1500' ) M_vs_M_Q_14.Histo_2D() #Draw it ######### Save and show the created figure M_vs_M_Q_14.SetOutDir(basepath + 'Modules/' + MODULE_name + '/Outputfiles/Figures/Raw_figures/')
"PUWeighter", os.environ["BASE_PATH"] + "/DataMC/Pileup/puWeightsRun2016_NTrueInt_FullDataset--Cert_271036-284044_13TeV_23Sep2016ReReco_Collisions16_JSON.txt", doNTrueInt=True, applySystVariation=True) xsWeighter = XSWeighter("XSWeighter") mediumMuonProducer = PhysObjProducer("MediumMuonProducer", "Muon", "MediumMuons", "Moriond17MediumMuon") mediumElectronProducer = PhysObjProducer("MediumElectronProducer", "Electron", "MediumElectrons", "Moriond17MediumElectron") jetProducer = JetProducer("JetProducer", "Jet", ["MediumMuons", "MediumElectrons"], "LooseJets", "Moriond17LooseJet", 0.4) if ratio_switch: plotter = Plotter("Plotter", ratio_plots) else: plotter = Plotter("Plotter", data_plots) anaProducer = AnalysisProducer("AnaProducer") eventSkimmer = EventSkimmer("StopToBLepSkim", cutflow="stCR") hltSkimmer = HLTSkimmer("HLTSkim", cutflow="stCR") jsonSkimmer = JSONSkimmer("JSONSkim") sequence = Sequence() sequence.add(jsonSkimmer) sequence.add(hltSkimmer) sequence.add(mediumMuonProducer) sequence.add(mediumElectronProducer) sequence.add(jetProducer) sequence.add(xsWeighter) sequence.add(puWeighter)
#Plot("nJet", ["TH1D","nJet","",5,-0.5,4.5], LambdaFunc('x: x.njets_pt30_eta2p5[0]'), ), ] #____________________________________________________________________________________________________ # plots = muon_plots + general_plots + jet_plots + signif_plots# big list of Plot objects #for plot in plots: #plot.plotSetting.divideByBinWidth = True for dataset in componentList: if dataset.isMC: dataset.lumi = lumi for component in dataset.componentList: component.maxEvents = nEvents plotter = Plotter("Plotter",plots) sequence = darkphoton_signal_unblind_sequence sequence.add(plotter) outputInfo = OutputInfo("OutputInfo") outputInfo.outputDir = outputDir outputInfo.TFileName = "DataMCDistribution_radiuscut"+radcutstr+"GeV.root" endSequence = EndSequence(skipHadd=justEndSequence) endModuleOutputDir = "/home/"+User+"/public_html/Higgs/HToZdZd/"+out_path endSequence.add(PlotEndModule(endModuleOutputDir,plots,skipSF=True)) ## Put an index.php file into Plots dir for easy visualization copyFile('/home/'+User+'/',phpFile,endModuleOutputDir)
import pandas as pd import numpy as np from Handler.Handler import Handler from EDA.EDA import Eda from Plotter.Plotter import Plotter plot = Plotter() handler = Handler() df_train, _, df_target = handler.get_data(frac=1.0) df_target = pd.DataFrame(df_target) df_train = pd.DataFrame(df_train) # EDA eda = Eda() # Análise básica d = eda.get_describe(df=df_train) eda.check_imbalance(var_name='target', df=df_target)