HONR269L
February 5th - Initial Meeting:
I met with Professor Jabeen, along with Matt Pearson and Nick Schaap, to discuss the research and what the process would generally require. I was moved from researching dark matter and extra dimensions using LHC data to researching new physics with W and Z bosons using LHC data in order to better align with my desire for further research opportunities in physics following this semester. I will be working alongside researchers who are already in the process with the topic. Professor Jabeen also provided resources for getting started with learning the technical aspects of the research and has gotten me in touch with the other researchers I will be working with.
February 11th - First ssh to the Cluster:
I was finally able to ssh into the cluster and set up my T3 LHS Access after receiving an email with instructions. I decided upon setting up a Virtual Box Linux Virtual Machine using Ubuntu 64-bit on my desktop. I had issues with my CPU not having "Virtualization" enabled by default and had to enter BIOS settings to enable it.
February 12th - First Meeting with Yashas and Jacques:
I met with Prof. Jabeen, Yashas and Jacques to discuss our progress with getting our space on the cluster set up. I was directed by Yashas to use the "Photon Analysis" tab under "Shabnam" on this site, and then follow the first github.com link to use the commands listed. These commands loaded codes onto my space on the cluster and will allow me to run the necessary code to use specific functions in my own programs. I had issues with nearly every command in which a "fatal error" occurred claiming "could not resolve host 'github.com.'" This is not a system error if you are in the right directory and running cmsenv, there is simply a chance it will work, and must be tried again if the first use does not work. Professor Jabeen also asked us to read the research paper found in the "W-Gamma" tab on this site.
February 14th - W-Gamma Charged Higgs Decay:
The suggested paper on Charged Higgs decay into W-Gamma indicated that the authors have a specific method of determining whether or not a Higgs event is relevant dependent on transverse momentum of decay particles, their pseudorapidity, and the mass of the Higgs boson. The mass distribution the paper specified was between 80 GeV and 200 GeV, which is significantly lower than the previously proposed 275 or even 300 minimum GeV required to detect a charged Higgs boson. It was not too highly technical, with the difficulty arising from unfamiliar equations used to find the desired mass along with other unknown variables like s_h.
February 19th - W-Gamma Analysis Paper:
In our meeting with Prof. Jabeen, Yashas, Jacques, and I were shown the current progress of the paper being worked on that presents current progress with the project. There were a ton of graphs explaining the specific conditions under which the Charged Higgs is most likely to be found, which allows the research to focus on a smaller set of items. I tried setting up a CERN account but had an issue with the site to which the link for registering took me was flagged as "insecure" on Chrome and Firefox.
February 25th - W-Gamma Analysis Meeting
I attended the weekly meeting with Prof. Jabeen, Prof. Belloni, and a few others. Francesca presented a new problem with the data that had already been analyzed. There were new standards for missing energy corrections released for 2016 data, which must be applied to the code and everything run again. The MET corrections were meant to correct for pileup in the LHC (defined here). We also discussed the error one would see if the beam was not in the exact location one expected as a function of the angle of produced particles. Particles produced and sent out perpendicularly from the beam to the expected beam location will have the highest error, while parallel particles the least. The beam position may change over time due to the CMS settling into the Earth, which can lower the whole thing over time. In effect, all of the analysis must be done again with the corrections for the highest likelihood of our results accepted by POGs (also defined here).
February 26th - Analysis Code Issues:
I bypassed the security warning given by Google Chrome after communicating with a CMS technology representative asked me to ignore the warning by clicking "proceed anyway." I also followed Francesca Rimi-Tan's instructions to try the first analysis by using the command "make wjets" but received an error:
[rwolle@hepcms-in1 Plotting]$ make wjets
#python MakeWJetsWS.py --baseDirMuGNoId /data/users/jkunkle/Resonances/LepGammaNoPhId_mug_2018_01_21 --baseDirElGNoId /data/users/jkunkle/Resonances/LepGammaNoPhId_elg_2018_01_21 --doClosure --outputDir ~/Plots/Resonance/Plots_2018_01_22/WJetsWS
python MakeWJetsWS.py --baseDirMuGNoId /data/users/jkunkle/Resonances/LepGammaNoPhId_mug_2018_01_21 --baseDirElGNoId /data/users/jkunkle/Resonances/LepGammaNoPhId_elg_2018_01_21 --outputDir ~/Plots/Resonance/Plots_2018_01_22/WJetsWS
Traceback (most recent call last):
File "MakeWJetsWS.py", line 9, in <module>
from uncertainties import ufloat
File "/cvmfs/cms.cern.ch/slc6_amd64_gcc530/lcg/root/6.06.00-ikhhed6/lib/ROOT.py", line 303, in _importhook
return _orig_ihook( name, *args, **kwds )
ImportError: No module named uncertainties
Makefile:24: recipe for target 'wjets' failed
make: *** [wjets] Error 1
This error was shared by Jaques as well on slack.
February 27th - Ntuple Making Issues:
Upon following the instructions found here, I received an error when trying to submit a job as a test:
[rwolle@hepcms-in1 RecoResonance]$ python scripts/scheduler.py
Traceback (most recent call last):
File "scripts/scheduler.py", line 4, in <module>
import scheduler_base
ImportError: No module named scheduler_base
It seems there is no header file named "scheduler_base" which may be needed for the scheduler to run. This was after I had created a directory in /data/users/rwolle called WGammaNtuple so that the setup.csh file would work properly.
I followed the next steps, thought there was no directory UMDNTuple/FilterInfoTree to edit the MET filter flags in.
Again trying to submit a job as a test within TreeFilter/FilterOverlap as the instructions say returns an error with the "scheduler_base" header:
[rwolle@hepcms-in1 FilterOverlap]$ python scripts/scheduler.py
Traceback (most recent call last):
File "scripts/scheduler.py", line 4, in <module>
import scheduler_base
ImportError: No module named scheduler_base
February 28th - Secure Copying File Issue:
I was attempting to copy the pdf discussed on February 19th's meeting but got the following error:
[rwolle@hepcms-in1 tmp]$ scp rwolle@hepcms.umd.edu:AN-16-332_temp.pdf /home/rob/Documents
ssh_exchange_identification: Connection closed by remote host
Google searches yield no appropriate course of action to take on a remote server I do not own myself.
March 4th - Meeting and "make wjets" Module Fixes:
I have figured out how to copy a file from a secure host to a local directory. I believe copying the file while inside the secure host does not work, so I navigated to the local home directory on my terminal and used this command:
[rwolle@hepcms-in1 tmp]$ scp rwolle@hepcms.umd.edu:/data/users/jabeen/GGA-redo/CMSSW_8_0_26_patch1/src/WGammaAnalysis/WGnote/notes/tmpAN-16-332_temp.pdf /home/rob/Documents
In order to fix the issue detailed under February 26th's "Analysis Code Issues" entry, namely the missing "uncertainties" module, I was instructed to download the file found here. I extracted the file on my own local directory, and then copied the file over to my directory on the secure host using the scp command:
scp -r uncertainties-3.0.1 rwolle@hepcms.umd.edu:/data/users/rwolle/CMSSW_8_0_26_patch1/python
I then navigated into the directory while on the remote host and ran the following command to set up the uncertainties directory:
python setup.py install --user
I then tried navigating to WG_Analysis/Plotting to run the "make wjets" command again, and found that another module was missing named "eos_utilities," but upon asking about the issue, I was notified that this appears if you do not run
"source setup.csh" before running the code. I still encountered an issue, but this seemed like a problem with the code or the input, not files I was missing:
File "MakeWJetsWS.py", line 227, in make_wjets_fit
fitMan_shape = FitManager( 'dijet', 2, 'wjets_shape', hist_shape, plot_var, eta_cut, xvar, label_shape, useRooFit=False )
TypeError: __init__() takes at most 6 arguments (10 given)
Makefile:24: recipe for target 'wjets' failed
make: *** [wjets] Error 1
Francesca said she would look into the "make_wjets_fit" code and work on fixing it this week, since she had not updated the github repository with her own code for a while.
March 5th - Commenting on "MakeWJetsWS.py" and "MakeFile:"
I went through the code in MakeWJetsWS.py within the CMSSW_8_0_26_patch1/src/WG_Analysis/Plotting and commented on sections I could understand. "..." means a skip in the code between sections I did not find lines to comment on.
...
def main() :
sampManMuGNoId = SampleManager( options.baseDirMuGNoId, _TREENAME, filename=_FILENAME, xsFile=_XSFILE, lumi=_LUMI )
sampManElGNoId = SampleManager( options.baseDirMuGNoId, _TREENAME, filename=_FILENAME, xsFile=_XSFILE, lumi=_LUMI )
sampManMuGNoId.ReadSamples( _SAMPCONF )
sampManElGNoId.ReadSamples( _SAMPCONF )
sampManMuGNoId.outputs = {}
sampManElGNoId.outputs = {}
# Includes events with 1 muon count with 30 (GeV?) transverse momentum
sel_base_mu = 'mu_pt30_n==1 && mu_n==1'
# Includes events with 1 electron count with 30 (GeV?) transverse momentum
sel_base_el = 'el_pt30_n==1 && el_n==1'
# Cuts events with certain pseudorapidities
#eta_cuts = ['EB', 'EE']
eta_cuts = ['EB']
workspaces_to_save = {}
# Histogram construction:
xmin_m = 160
xmax_m = 2000
bin_width_m = 20
xmin_pt = xmin_m/2
if xmin_pt < 50 :
xmin_pt = 50
xmax_pt = xmax_m/2
bin_width_pt = bin_width_m/2.
binning_m = ((xmax_m-xmin_m)/bin_width_m, xmin_m, xmax_m)
binning_pt = ( (xmax_pt - xmin_pt )/bin_width_pt, xmin_pt, xmax_pt )
...
# Opening workspaces in ROOT:
workspace_signal = ROOT.RooWorkspace( 'workspace_signal' )
workspace_wgamma = ROOT.RooWorkspace( 'workspace_wgamma' )
workspace_wgammalo = ROOT.RooWorkspace( 'workspace_wgammalo' )
workspace_top = ROOT.RooWorkspace( 'workspace_top' )
workspace_zgamma = ROOT.RooWorkspace( 'workspace_zgamma' )
wjets = ROOT.RooWorkspace( 'workspace_wjets' )
elefake = ROOT.RooWorkspace( 'elefake' )
for seltag, chdic in selections.iteritems() :
for ch, seldic in chdic.iteritems() :
for name, vardata in kine_vars.iteritems() :
# This next line may be the issue first given when trying to run "make wjets"
make_wjets_fit( sampManMuGNoId, 'Data', seldic['selection'], 'EB', vardata['var'], 'chIso', 'sigmaIEIE', vardata['binning'], vardata['xvar'], suffix='wjets_%s_EB_%s_%s' %(ch,name,seltag), closure=False, workspace=wjets)
if options.doClosure :
closure_res_mu = make_wjets_fit( sampManMuGNoId, 'Wjets', seldic['selection'], 'EB', 'mt_lep_met_ph', 'chIso', 'sigmaIEIE', binning_m, xvar_m, suffix='closure_%s_EB_%s' %( ch, seltag ), closure=True )
if options.outputDir is not None :
wjets.writeToFile( '%s/%s.root' %( options.outputDir,wjets.GetName() ) )
for fileid, ws_list in workspaces_to_save.iteritems() :
for idx, ws in enumerate(ws_list) :
if idx == 0 :
recreate = True
else :
recreate = False
ws.writeToFile( '%s/workspace_%s.root' %( options.outputDir, fileid ), recreate )
for key, can in sampManMuGNoId.outputs.iteritems() :
can.SaveAs('%s/%s.pdf' %( options.outputDir, key ) )
for key, can in sampManElGNoId.outputs.iteritems() :
can.SaveAs('%s/%s.pdf' %( options.outputDir, key ) )
# This defines the function that is giving errors:
def make_wjets_fit( sampMan, sample, sel_base, eta_cut, plot_var, shape_var, num_var, binning, xvar, suffix='', closure=False, workspace=None) :
...
I also went through the code found in MakeFile in the same directory and added some comments:
# Defines directory output
OUTPUTMAIN=~/Plots/Resonance/Plots_2018_01_22
# Defines event directories as variables in order to identify which events plotting code will use
DIR_MUG=/data/users/jkunkle/Resonances/LepGamma_mug_2018_01_21
DIR_ELG=/data/users/jkunkle/Resonances/LepGamma_elg_2018_01_21
DIR_MUGNoId=/data/users/jkunkle/Resonances/LepGammaNoPhId_mug_2018_01_21
DIR_ELGNoId=/data/users/jkunkle/Resonances/LepGammaNoPhId_elg_2018_01_21
DIR_MU=/data/users/jkunkle/Resonances/SingleLepNoPhID_mu_2018_01_21
DIR_EL=/data/users/jkunkle/Resonances/SingleLepNoPhID_el_2018_01_21
DIR_MUMU=/data/users/jkunkle/Resonances/LepLep_mumu_2018_01_21
DIR_ELEL=/data/users/jkunkle/Resonances/LepLep_elel_2018_01_21
DIR_SIGTruth=/data/users/jkunkle/Resonances/SigNoFilt_2018_01_21
all : plots workspaces limits
plots :
# This code runs "MakePlots.py" with every defined event directory
#python MakePlots.py --baseDirMu ${DIR_MU} --baseDirEl ${DIR_EL} --baseDirMuG ${DIR_MUG} --baseDirElG ${DIR_ELG} --baseDirMuGNoId ${DIR_MUGNoId} --baseDirElGNoId ${DIR_ELGNoId} --baseDirMuMu ${DIR_MUMU} --baseDirElEl ${DIR_ELEL} --baseDirNoFilt ${DIR_SIGTruth} --makeZCR --makeWCR --makeSR --makeJetBkg --makeEleBkg --outputDir ${OUTPUTMAIN}/Plots
python MakePlots.py --baseDirMu ${DIR_MU} --baseDirEl ${DIR_EL} --baseDirMuG ${DIR_MUG} --baseDirElG ${DIR_ELG} --baseDirMuGNoId ${DIR_MUGNoId} --baseDirElGNoId ${DIR_ELGNoId} --baseDirMuMu ${DIR_MUMU} --baseDirElEl ${DIR_ELEL} --baseDirNoFilt ${DIR_SIGTruth} --makeSR --outputDir ${OUTPUTMAIN}/Plots
#python MakePlots.py --baseDirMu ${DIR_MU} --baseDirEl ${DIR_EL} --baseDirMuG ${DIR_MUG} --baseDirElG ${DIR_ELG} --baseDirMuGNoId ${DIR_MUGNoId} --baseDirElGNoId ${DIR_ELGNoId} --baseDirMuMu ${DIR_MUMU} --baseDirElEl ${DIR_ELEL} --baseDirNoFilt ${DIR_SIGTruth} --makeSR --outputDir ${OUTPUTMAIN}/Plots
wjets :
# This code runs "MakeWJetsWS.py" code with events from the Muon-Gamma event directory (--baseDirMuG...) or the Electron-Gamma event directory
#python MakeWJetsWS.py --baseDirMuGNoId ${DIR_MUGNoId} --baseDirElGNoId ${DIR_ELGNoId} --doClosure --outputDir ${OUTPUTMAIN}/WJetsWS
python MakeWJetsWS.py --baseDirMuGNoId ${DIR_MUGNoId} --baseDirElGNoId ${DIR_ELGNoId} --outputDir ${OUTPUTMAIN}/WJetsWS
signal :
# This runs "MakeSignalWS.py" with Muon-Gamma and Electron-Gamma events
python MakeSignalWS.py --baseDirMuG ${DIR_MUG} --baseDirElG ${DIR_ELG} --outputDir ${OUTPUTMAIN}/SignalWS
mcbkg :
# This runs "MakeMCBkgWS" with Muon-Gamma and Electron-Gamma events
python MakeMCBkgWS.py --baseDirMuG ${DIR_MUG} --baseDirElG ${DIR_ELG} --outputDir ${OUTPUTMAIN}/MCBkgWS
efake :
# This runs "MakeEFakeWS" with Muon-Gamma and Electron-Gamma events
python MakeEFakeWS.py --baseDirMuG ${DIR_MUG} --baseDirElG ${DIR_ELG} --outputDir ${OUTPUTMAIN}/EFakeWS
workspaces :
# This code makes workspaces for Muon-Gamma and Electron-Gamma events
#python MakeWorkspaces.py --baseDirMuG ${DIR_MUG} --baseDirElG ${DIR_ELG} --baseDirMuGNoId ${DIR_MUGNoId} --baseDirElGNoId ${DIR_ELGNoId} --doSignal --doWGamma --doTop --doZGamma --doWJets --doEleFake --doClosure --outputDir ${OUTPUTMAIN}/Workspaces
#python MakeWorkspaces.py --baseDirMuG ${DIR_MUG} --baseDirElG ${DIR_ELG} --baseDirMuGNoId ${DIR_MUGNoId} --baseDirElGNoId ${DIR_ELGNoId} --doSignal --doWGamma --doTop --doZGamma --outputDir ${OUTPUTMAIN}/Workspaces
#python MakeWorkspaces.py --baseDirMuG ${DIR_MUG} --baseDirElG ${DIR_ELG} --baseDirMuGNoId ${DIR_MUGNoId} --baseDirElGNoId ${DIR_ELGNoId} --doWJets --doEleFake --doClosure --outputDir ${OUTPUTMAIN}/Workspaces
#python MakeWorkspaces.py --baseDirMuG ${DIR_MUG} --baseDirElG ${DIR_ELG} --baseDirMuGNoId ${DIR_MUGNoId} --baseDirElGNoId ${DIR_ELGNoId} --doWGamma --outputDir ${OUTPUTMAIN}/Workspaces
python MakeWorkspaces.py --baseDirMuG ${DIR_MUG} --baseDirElG ${DIR_ELG} --baseDirMuGNoId ${DIR_MUGNoId} --baseDirElGNoId ${DIR_ELGNoId} --doSignal --outputDir ${OUTPUTMAIN}/Workspaces
fits :
# This code makes fits that are output to the Workspaces directory, but look to be using an updated CMSSW version (8_1_0 instead of our 8_0_26_patch1)
python MakeFits.py --baseDir ${OUTPUTMAIN}/Workspaces/ --combineDir /home/jkunkle/WG_Analysis/CMSSW_8_1_0 --outputDir ${OUTPUTMAIN} --doVarOptimization --useHistTemplate --noRunCombine
#python MakeFits.py --baseDir ${OUTPUTMAIN}/Workspaces/ --combineDir ~/usercode/Plotting/LimitSetting/CMSSW_7_4_7/ --outputDir ${OUTPUTMAIN} --doVarOptimization --limitMethod MaxLikelihoodFit
#python MakeFits.py --baseDir ${OUTPUTMAIN}/Workspaces/ --combineDir ~/usercode/Plotting/LimitSetting/CMSSW_7_4_7/ --outputDir ${OUTPUTMAIN} --doVarOptimization --limitMethod HybridNew
#python MakeFits.py --baseDir ${OUTPUTMAIN}/Workspaces/ --combineDir /home/jkunkle/WG_Analysis/CMSSW_8_1_0 --outputDir ${OUTPUTMAIN} --doVarOptimization --limitMethod Asymptotic --useToySignal --useToyBackground
signalfits :
# This code makes resolution signal fits for Muon-Gamma and Electron-Gamma events
python MakeResSignalFits.py --baseDirMu ${DIR_MUG} --baseDirEl ${DIR_ELG} --outputDir ${OUTPUTMAIN}/SignalFits
I was unable to find information on what "MCBkg" was, though I assume it is some form of background. I am not sure of the significance of the event directories having or not having an ID (DIR_MUG vs. DIR_MUGNoId).
March 11th - Following the Event Directories:
The "MakeFile" code I commented on previously in the logbook under March 5th's entry displayed a directory where the events used in processing were stored:
# Defines event directories as variables in order to identify which events plotting code will use
DIR_MUG=/data/users/jkunkle/Resonances/LepGamma_mug_2018_01_21
DIR_ELG=/data/users/jkunkle/Resonances/LepGamma_elg_2018_01_21
DIR_MUGNoId=/data/users/jkunkle/Resonances/LepGammaNoPhId_mug_2018_01_21
DIR_ELGNoId=/data/users/jkunkle/Resonances/LepGammaNoPhId_elg_2018_01_21
DIR_MU=/data/users/jkunkle/Resonances/SingleLepNoPhID_mu_2018_01_21
DIR_EL=/data/users/jkunkle/Resonances/SingleLepNoPhID_el_2018_01_21
DIR_MUMU=/data/users/jkunkle/Resonances/LepLep_mumu_2018_01_21
DIR_ELEL=/data/users/jkunkle/Resonances/LepLep_elel_2018_01_21
I followed the path for DIR_MUG and found a large number of directories which look to be simulations of either Pythia or Madgraph using different widths (not sure of what yet) to classify them. I navigated to the directory "MadGraphChargedResonance_WGToLNu_M2800_width5"
Inside were a few files:
Job_0000 job_desc.txt MadGraphChargedResonance_WGToLNu_M2800_width5_Job_0000.txt
"job_desc.txt" contained information about output files, and the executable needed to run the job's location, among other information: "/home/jkunkle/WG_Analysis/Analysis/TreeFilter/RecoResonance/RunAnalysis_MC_mug.exe"
Contained in "MadGraphChargedResonance__M2800_width5_Job_0000.txt" was information that looked to be read into a file to provide information on the filters applied to this event:
# 2018/01/23 07:39:21
files : [/store/user/jkunkle///MadGraphChargedResonance_WGToLNu_M2800_width5/UMDNTuple_v4/180122_105646/0000/ntuple_1.root,/store/user/jkunkle///MadGraphChargedResonance_WGToLNu_M2800_width5/UMDNTuple_v4$
treeName : UMDNTuple/EventTree
outputDir : /data/users/jkunkle/Resonances/LepGamma_mug_2018_01_21/MadGraphChargedResonance_WGToLNu_M2800_width5
outputFile : tree.root
nPrint : 10000
__Modules__
FilterMuon : cut_abseta_tight [ < 2.4] ; cut_chi2_tight [ < 10] ; cut_corriso_tight [ < 0.25] ; cut_d0_tight [ < 0.2] ; cut_eta [ < 2.5] ; cut_isGlobalOrTk_loose [ == True ] ; cut_isGlobal_tight [ == Tru$
FilterElectron : cut_absdEtaIn_barrel_loose [ < 0.00477 ] ; cut_absdEtaIn_barrel_medium [ < 0.00311 ] ; cut_absdEtaIn_barrel_tight [ < 0.00308 ] ; cut_absdEtaIn_barrel_veryloose [ < 0.00749 ] ; cut_absdE$
FilterPhoton : cut_abseta [ < 2.5] ; cut_abseta_crack ![ > 1.44 & < 1.57 ] ; cut_chIsoCorr_barrel_loose [ < 1.295 ] ; cut_chIsoCorr_barrel_medium [ < 0.441 ] ; cut_chIsoCorr_barrel_tight [ < 0.202 ] ; cu$
FilterJet : cut_abseta [ < 4.5 ] ; cut_electron_dr [ > 0.4 ] ; cut_jet_CSV_Loose [ > 0.5426 ] ; cut_jet_CSV_Medium [ > 0.8484 ] ; cut_jet_CSV_Tight [ > 0.9535 ] ; cut_jet_cemf_central_loose [ < 0.99 ] ; $
FilterTrigger : cut_bits [ == 23 | == 31 ] ; init_triggerBits [23:HLT_IsoMu24,31:HLT_IsoTkMu24,60:HLT_Ele27_eta2p1_WPTight_Gsf] ;
FilterEvent : cut_el_n [ == 0 ] ; cut_mu_n [ == 1 ] ; cut_mu_pt30_n [ == 1 ] ; cut_ph_n [ > 0 ] ;
MakePhotonCountVars :
BuildEventVars :
BuildTruth : cut_lep_mother [ == 24 || == -24 || == 11 || == -11 || == 12 || == -12 || == 13 || == -13 || == 14 || == -14 || == 15 || == -15 || == 16 || == -16 ] ; cut_ph_IsPromptFinalState [ == True ] $
FilterBlind : cut_mt_lep_met_ph [ < 100 ] ; init_isData [ == False] ;
WeightEvent : init_sample_file [/data/users/jkunkle/Resonances/PileupHistograms//MadGraphChargedResonance_WGToLNu_M2800_width5/hist.root] ; init_data_file [/home/jkunkle/WG_Analysis/Analysis/TreeFilter/R$
Unfortunately long lines were cut off with a "$" due to their insane length which stretched dozens of values. This does not seem to be the file that is giving the "make wjets" code break with too many/not enough inputs.
I checked inside of the "Job_0000" directory and found three files:
stderr.txt stdout.txt tree.root
"tree.root" seemed to be encrypted or unreadable in some way, displaying random, changing characters instead of code.
Within "stderr.txt," the following error was placed:
Error in <TCling::RegisterModule>: cannot find dictionary module Dict_rdict.pcm
This could be the issue, though I know nothing of any directory or name mentioned in this line.
"stdout.txt" had no errors visible, and displayed the code's progress in creating the necessary output directories and how long running the events took (50,000 in about 22 seconds).
I am unsure about the technical difference between "DIR_MUG" and "DIR_MUGNoId" and will ask of this at the meeting.
March 13th - Tuesday Meeting:
We looked over our role in the processing and analysis of data: minuscule compared to completed work and coming after the data has already been thoroughly processed. We looked through the MakeFile code inside WG_Analysis/Plotting as well as the other programs it used. One such program used a SampleManager header file which contained thousands of lines of code needed to process and draw graphs and was used by other code to generate graphs for the specific properties of the event, such as the pseudorapidity of the particles generated. No progress towards affecting the code can be made until the updated version has been pushed to GitHub, which has not occurred yet.
March 26th - Tuesday Meeting:
After Francesca updated the code, I followed the steps again from this github repository in addition to her slides that may only be accessed with a CERN account but can be found here. She indicated that we must pay attention to lines within "Makefile" and change them where indicated in order for each step of the plotting code to generate new plots properly. In particular, we had to change the output directory to a spot inside of our folder on the cluster (the code will create the named directories if a new path is given) as well as the input directories which currently point to the old data directories that caused the code to require updating to begin with. This is the desired list of defined input directories from "Makefile:"
DIR_MUG=/data/users/jkunkle/Resonances/LepGamma_mug_2018_03_28
DIR_ELG=/data/users/jkunkle/Resonances/LepGamma_elg_2018_03_28
DIR_MUGNoId=/data/users/friccita/WGammaNtuple/LepGammaNoPhId_mug_2019_03_17/WithSF
DIR_ELGNoId=/data/users/friccita/WGammaNtuple/LepGammaNoPhId_elg_2019_03_17/WithSF
#DIR_MU=/data/users/jkunkle/Resonances/SingleLepNoPhID_mu_2018_03_28
DIR_MU=/data/users/friccita/WGammaNtuple/SingleLepNoPhId_mu_2019_03_17/WithSF
DIR_EL=/data/users/friccita/WGammaNtuple/SingleLepNoPhID_el_2019_03_17/WithSF
DIR_MUMU=/data/users/friccita/WGammaNtuple/LepLep_mumu_2018_11_30/WithSF
DIR_ELEL=/data/users/friccita/WGammaNtuple/LepLep_elel_2018_08_13
These directories only contain Monte Carlo simulations and "WithSF" means that those directories have the desired scale factors and a photon overlap filter applied.
Additionally, there is a typo in the input directory for the "make wjets" command in "Makefile." One of the specified base directories is identified as "MuNoG" instead of "MuGNoId." The corrected code is below:
wjets :
python MakeWJetsWS.py --baseDirMuGNoId ${DIR_MUGNoId} --baseDirElGNoId ${DIR_ELGNoId} --doClosure --outputDir ${OUTPUTMAIN}/WJetsWS
The directions then said to run the python script "MakePlots.py" which I ran using "python ./MakePlots.py" and no input parameters. The code finishes properly, but claims that none of the thousands of necessary parameters can be found and every process fails. I instead tried the directions Francesca gave before she had updated the code, which was to run "make wjets" which should make viewable histograms from data regarding their jets. The code fails before using any data and gives the following error:
('WARNING : Found zero samples matching criteria! Sample matching criteria were : ', {'name': 'Data'})
Could not locate old sample
new name = Data273d91cc-8512-4a5b-83e9-7f78c3ae5b2a
old name = Data
Traceback (most recent call last):
File "MakeWJetsWS.py", line 678, in <module>
main()
File "MakeWJetsWS.py", line 117, in main
make_wjets_fit( sampManMuGNoId, 'Data', seldic['selection'], 'EB', vardata['var'], 'chIso', 'sigmaIEIE', vardata['binning'], vardata['xvar'], suffix='wjets_%s_EB_%s_%s' %(ch,name,seltag), closure=False, workspace=wjets)
File "MakeWJetsWS.py", line 263, in make_wjets_fit
hist_shape = clone_sample_and_draw( sampMan, sample, plot_var, full_sel_shape, binning )
File "MakeWJetsWS.py", line 675, in clone_sample_and_draw
sampMan.create_hist( newSamp, var, sel, binning )
File "/data/users/rwolle/CMSSW_8_0_26_patch1/src/WG_Analysis/Plotting/SampleManager.py", line 3131, in create_hist
sampname = sample.name
AttributeError: 'NoneType' object has no attribute 'name'
Makefile:26: recipe for target 'wjets' failed
No obvious issue or typo can be found by following the "Traceback" to the source of the parameter which is giving the issue. The first mention of the "name" parameter seems to be a correctly identified function "name" of an object called "sample." I received an answer from Kak that the error is due to the code searching for data but the input directories only have Monte Carlo simulations. I tried changing the mention of the string 'Data' in line 117 of "MakeWJetsWS.py" as given in the error message to 'MC' for Monte Carlo, but the same error persisted.
April 1st - Trying Jacques' Solution:
I copied the command Jacques used to run MakePlots.py using the instructions and arguments found in "Makefile" under "make plots:"
python MakePlots.py --baseDirMuG /data/users/friccita/WGammaNtuple/LepGammaNoPhId_mug_2019_03_17/WithSF --baseDirElG /data/users/friccita/WGammaNtuple/LepGammaNoPhId_elg_2019_03_17/WithSF --makeJetBkg --outputDir /data/users/rwolle/WG_Analysis/Plotting/make_output/2019_03_17_WithSF/Plots
I ran the code and got the exact same, lengthy error detailed by Jacques' logbook entry for March 25th so there are no differences in code that are causing our issues with MakePlots.py
April 2nd - Working through Issues with Kak and Francesca:
In Tuesday's meeting, we sat with Kak and Francesca to work through the code and any errors. She taught us the proper way to run "MakePlots.py" which was to use "make plots," the command defined in "Makefile." Jacques used the ntuples found in some of the old input directories we had replaced with Francesca's in the Makefile, and got "make plots" to output four plots in his output directory. I copied the code from his location to my own using "cp /data/users/jareddi/CMSSW_8_0_26_patch1/src/WG_Analysis/Plotting/Outputs/Plots/WJetsPlots/Makefile ."
Unfortunately, this overwrit my own file and I should have saved my version as it would have enabled me to figure out exactly which directories he had reverted and which ones he had changed. After running "make plots" again on my end, I made four plots.
This was one of them:
ph_chIso_mu_EB_phpt_15_50.png
I was able to open this by copying it from the cluster to my own VM using "scp rwolle@hepcms.umd.edu:/data/users/rwolle/CMSSW_8_0_26_patch1/src/WG_Analysis/Plotting/Outputs/Plots/WJetsPlots/ph_chIso_mu_EB_phpt_15_50.png ."
This plot uses the older ntuples to display the number of events with differing values of charged hadron isolation. Charged hadron isolation accounts for the sum of the transverse momentum of all particles in a cone with DR < 0.4 around reconstructed photon candidates (definition taken from CERN wiki, which does not define "DR").
There should be many more than four plots, but there seems to be errors in their creation process.
New data still gives a long list of errors (it seems like one for every plot) due to a failure with the variable named "ph_mediumNoChIso_n" which appears to be missing from or broken in the updated ntuples. Francesca will be looking into the issue and update the ntuples soon.
April 9th - Kak's 2017 Plots:
Kak was able to create a script separate from Makefile called "MakeVarDist.py" which is found in kak's directory /data/users/kakw/MakeVarDist.py and should be copied to the Plotting directory of WG_Analysis using:
cp /data/users/kakw/MakeVarDist.py /data/users/*user_name*/CMSSW_8_0_26_patch1/src/WG_Analysis/Plotting
Additionally, the script needed to run on 2017 data, "Resonance2017.py," is found in /data/users/kakw/Resonance2017.py which can be copied to the "Modules" directory using:
cp /data/users/kakw/Resonance2017.py /data/users/*user_name*/CMSSW_8_0_26_patch1/src/WG_Analysis/Plotting/Modules
In order to make the MakeVarDist.py script versatile enough to run either Francesca's ntuples or kak's ntuples, I added a line on line 26. To run 2017 data, comment out _SAMPCONF = 'Modules/Resonance.py' and uncomment _SAMPCONF = 'Modules/Resonance2017.py' and to run 2016 ntuples, do the opposite.
### For 2017 Data:
_SAMPCONF = 'Modules/Resonance2017.py'
### For 2016 MonteCarlo:
#_SAMPCONF = 'Modules/Resonance.py'
Additionally, I added another line at line 40. Again, comment out whichever ntuple you do not want to run and uncomment the other:
### For 2017 Data:
if options.baseDirMuG is None: options.baseDirMuG = "/data/users/kakw/Resonances2017/LepGamma_mug_2019_04_04/"
if options.baseDirElG is None: options.baseDirElG = "/data/users/kakw/Resonances2017/LepGamma_elg_2019_04_04/"
### For 2016 Monte Carlo:
#if options.baseDirMuG is None: options.baseDirMuG = "/data/users/friccita/WGammaNtuple/LepGamma_mug_2019_04_02/"
#if options.baseDirElG is None: options.baseDirElG = "/data/users/firccita/WGammaNtuple/LepGamma_elg_2019_04_04/"
Running "./MakeVarDist.py" on Francesca's 2016 ntuples still give errors in SampleManager.py that cannot be easily fixed and do not generate any plots.
Running on Kak's 2017 ntuples does not give code-breaking errors (though there are some warnings) and generates many plots in a new "temp" directory within "Plotting." I zipped the plots together using:
tar -zcvf plots.tgz temp
and put the plots on my VM using
scp rwolle@hepcms.umd.edu:/data/users/rwolle/CMSSW_8_0_26_patch1/src/WG_Analysis/Plotting/plots.tgz .
I then unzipped the plots using
tar -zxvf plots.tgz
(This compresses and then uncompresses the files: -zcvf for compress, -zxvf for extract)
I could then view the plots by opening them as .png files using the Linux file explorer. The plot I first looked at only used two directories to make the stacked histograms such as the one below:
The legend is cut off and so only the teal directory is labeled. I am not sure if this error is caused by the plot construction, the compression of the files, or some other error.
April 10th - Scripts and Updated 2016 nTuples:
[This script causes "source setup.csh" to break] I wrote some small scripts to make navigating to my space on the cluster much easier. In order to securely access the cluster with access to colored emacs options, I wrote this script for my VM:
#!/bin/bash
ssh -XY rwolle@hepcms.umd.edu -t "cd /data/users/rwolle/CMSSW_8_0_26_patch1/src/WG_Analysis ; bash --login"
clear
[This script does not work, possibly due to above script] And wrote this script inside "WG_Analysis" to run the setup commands necessary for all scripts in the directory to run properly:
#!/bin/bash
source setup.csh
cmsenv
clear
After making each script I used chmod +x to give myself execute permissions.
Francesca fixed the ntuples she had made, so I was able to run "make plots" and get four plots in the output directory which are identical to the ones generated by the older data using "make plots" or did not change at all (the plot is identical to the one made in April 2nd's entry).
April 15th - Updated 2017 nTuples:
The most updated nTuples for 2017 data can now be found at /data2/users/kakw/Resonances2017/LepGamma_mug_2019_04_12/ and /data2/users/kakw/Resonances2017/LepGamma_mug_2019_04_12/
To reflect this change, I edited the input directories in "MakeVarDist.py" and replaced them with the updated directories.
I remade the plots, but every histogram only has diphoton events plotted:
el_pt0_SEL_basephEB_phpt50_log.pdf
This is no longer an issue with the legend displaying improperly, it is now an issue with the plot generation process.
April 16th - Adding Command-Line nTuple Selection:
I added to "MakeVarDist.py" so that a simple option will switch between using Kak's 2017 ntuples and Francesca's 2016 ntuples. With the edits detailed below, I can run the following commands:
./MakeVarDist.py --ntuple k
Which gives Kak's directories.
./MakeVarDist.py --ntuple f
Which gives Francesca's directories.
The additions to the code are given below:
In the "parser" class
parser = ArgumentParser()
parser.add_argument('--baseDirMuG', default=None, dest='baseDirMuG', required=False, help='Path to muon base directory')
...
parser.add_argument('--ntuple', default=None, dest='ntuple', required=False, help='Chooses ntuple directories')
In the "options" class
if options.ntuple is 'k':
### For 2017 Data:
_SAMPCONF = 'Modules/Resonance2017.py'
if options.ntuple is 'f':
### For 2016 MonteCarlo:
_SAMPCONF = 'Modules/Resonance.py'
...
if options.ntuple is 'k':
### For 2017 Data:
if options.baseDirMuG is None: options.baseDirMuG = "/data2/users/kakw/Resonances2017/LepGamma_mug_2019_04_12/"
if options.baseDirElG is None: options.baseDirElG = "/data2/users/kakw/Resonances2017/LepGamma_elg_2019_04_12/"
if options.ntuple is 'f':
### For 2016 Monte Carlo:
if options.baseDirMuG is None: options.baseDirMuG = "/data/users/friccita/WGammaNtuple/LepGamma_mug_2019_04_02/"
if options.baseDirElG is None: options.baseDirElG = "/data/users/firccita/WGammaNtuple/LepGamma_elg_2019_04_04/"
Proceeding every histogram file creation when running "MakeVarDist.py" was the following text, which seems to be an error:
['DiPhoton']
Scale GammaGamma by 1.000000
Scale __AllStack__ by 1.000000
stack_sum nan
('********************NOT FILLING SIGNAL ENTRY IN LEGEND**********************',)
skipped <Sample Data at 7f9e11eb80e0>
Which is likely why the histogram, while recognizing that there are relevant top-antitop, photon events and Z, Jet events, only plots diphoton events. This issue is most likely inherent to the ntuples, so I will have to wait for the ntuples to be remade.
April 22nd - Fixing the Histograms:
In a meeting with Kak, Jacques and I worked on fixing problems with the plots generated by MakeVarDist.py such as the plots containing only diphoton events and performed a few edits to the code to accomplish this.
First, I pulled a branch from GitHub with updated programs to work on called "legacy 2016" and changed my current branch to that one using the following commands:
To pull the files from GitHub with --force option to disregard differences between files:
git checkout --f legacy2016
To navigate to the new branch:
git branch legacy2016
I then opened MakeVarDist.py and used the text editor's search function to find the first occurrence of "legend" in the file. Three lines below this occurrence is the calling of the "makeplots" function with several parameters. The fifth parameter is legend_config along with its options. I replaced all of that parameter with {} to skip its use in the function.
Additionally write in the line above this use of makeplots, the value of hist_config is set. In its final option, remove the word "PLUWeight" to remove consideration of Pileup weights until they are fixed later.
In the end, those three lines of code should look like:
legend_config = {'legendLoc':"Double","legendTranslateX":0.3}
hist_config = {"logy":1,"blind":True "weight": "NLOWeight"}
makeplots(sampManELG,vararray, selarray, hist_config, {}, "log")
I then made more plots using 2017 nTuples and (./MakeVarDist.py --ntuple k) that were all filled with the proper event types and had every event type plotted listed in the legend.
In order to save time by avoiding packing and unpacking all of the plots every time the plots are made, one can view an individual plot using FireFox with the command:
xdg-open filename.png
& following this command will open the FireFox tab in a new window, allowing you to continue work on the Terminal.
el_pt0_SEL_basephEB_log.png
This histogram, though not currently using the correct Pile Up Weights or the full list of samples, is finally formatted correctly.
May 1st - Interactive Python:
In order to have more freedom with what I can plot and how I plot it, I started using interactive Python within the cluster.
In order to do a few basic commands, I did:
ipython
To initiate the framework, then:
%run interactiveStackTree.py --baseDir /data2/users/kakw/Resonances2017/LepGamma_elg_2019_04_12 --samplesConf Modules/Resonance2017.py --xsFile cross_sections/photon15.py --lumi 35900. --treeName UMDNTuple/EventTree --fileName tree.root
To get a sample to work with. Changing the option following "--baseDir" will change what samples are used and the option following "--samplesConf" must be "Modules/Resonance2017.py" for Kak's 2017 ntuples and "Modules/Resonance.py" for Francesca's 2016 ntuples. I then ran the following to get a simple histogram of transverse momentum for the leading electron in every event in the directory:
selection = "NLOWeight"
Then:
samples.Draw("el_pt", selection, (60,0,300), {"xlabel":"p_{T}","logy":1,"ymax":1e5,"blind":True},{"legendLoc":"Double",'legendTranslateX':0.25})
Which generated this plot:
The required format for plot options can be found by using:
samples.Draw?
An example of some commands (some of which don't seem to work at present) can be found at this site:
http://hepcms-hn.umd.edu/~kakw/2018_09_18_signal_region_check_echannel.html
HONR268N
Oct. 8th - HW 4:
Linux Shell Notes
find /usr/include/c++ -name "4*" - Lists versions of Linux available (4.4.4 and 4.4.7 on my machine)
g++ -dumpspecs - I'm using version 4.4.4
Hello World Code:
#include <iostream>
using namespace std;
int main() {
cout<<"Hello World!"<<endl;
return 0;
}
Line-by-Line Comments:
#include <iostream> //This and the following line allow the program to access external information such as commands for use within the file.
using namespace std; //See above
int main() { //Begins and initializes the function that will run the primary program.
cout<<"Hello World!"<<endl; //Prints the exact characters "Hello World!" and then ends the line, moving to a new one.
return 0; //This and the following line end the "main()" function by returning a null value.
} //See above
Compiling and running the program in the Linux Terminal:
[cms-opendata@localhost src]$ g++ -Wall main.cpp -o main //Compiling
[cms-opendata@localhost src]$ ./main //Running
Hello World! //Code output
First loop practice code with comments:
#include <iostream> //Initializing utilities
using namespace std;
int main() { //Initializes main function
int n=10; //Initializes integer type variable "n" with value=10
while(n>0) { //Begins loop that continues if the value of variable "n" is greater than 0.
cout<<"n is "<<n<<endl; //Prints "n is " followed by the value of variable n and ends the line
n--; //Subtracts 1 from the value of variable "n"
} //Ends (does not break) "while" loop
return 0; //Ends main function
}
Compiling and running:
[cms-opendata@localhost Programs]$ g++ -Wall loops.cpp -o loops
[cms-opendata@localhost Programs]$ ./loops
n is 10
n is 9
n is 8
n is 7
n is 6
n is 5
n is 4
n is 3
n is 2
n is 1
Uncommenting the line of code involving variable "n" outside of the loop generates an error because the variable is only used initialized within the loop.
Second loop practice code with comments:
#include <iostream> //Initializes utilities
using namespace std;
int main() { //Initializes main function
for (int n=10; n>0; n--) { //Starts "for" loop by initializing integer type variable "n" with value=10 inside the loop, continues the loop if the value of variable "n" is greater than 0, and subtracts 1 from the value of variable "n" at the start of each loop
cout<<"n is "<<n<<endl; //Prints "n is " followed by the value of variable "n" and ends the line
} //Ends (does not break) the "for" loop
return 0; //Ends main function
}
Compiling and running:
[cms-opendata@localhost Programs]$ g++ -Wall loops2.cpp -o loops2
[cms-opendata@localhost Programs]$ ./loops2
n is 10
n is 9
n is 8
n is 7
n is 6
n is 5
n is 4
n is 3
n is 2
n is 1
Third loop practice code with comments:
#include <iostream> //Initializes utilities
using namespace std;
int main() { //Initializes main function
for(int n=0; n<10; n++) { //Starts loop with integer counter variable "n" with value=0, continuing if the parameter "n<10" (variable "n" has a value less than 10"), and adds 1 to the value of "n" at the start of each loop
cout << "n is " << n << ": "; //Prints "n is " followed by the value of variable "n" followed by ": "
for(int m=0; m<=n; m++) { //Starts loop with integer counter variable "m" with value=0, continuing if the parameter "m<n" (variable "m" has a value less than that of variable "n"), and adds 1 to the value of "m" at the start of each loop
cout << m; //Prints the value of variable "m"
} //Ends (does not break) "for" loop within the primary "for" loop
cout << endl; //Ends the line
} //Ends (does not break) "for" loop
return 0 ; //Ends main function
}
Compiling and running:
[cms-opendata@localhost Programs]$ g++ -Wall loops3.cpp -o loops3
[cms-opendata@localhost Programs]$ ./loops3
n is 0: 0
n is 1: 01
n is 2: 012
n is 3: 0123
n is 4: 01234
n is 5: 012345
n is 6: 0123456
n is 7: 01234567
n is 8: 012345678
n is 9: 0123456789
1st variable & operations practice code with comments:
#include <iostream> //Initializing necessary information
using namespace std; //See above
int main() { //Initializing main function
cout << "hello world" << endl; //Prints "hello world" and carries on to the next line.
int i=2; //Initializes an integer type variable "i" with value=2
cout << "i = " <<i<<endl; //Prints the characters "i = " followed by the value of the variable "i" and carries on to the next line
double a=3.3; //Initializes a double type variable "a"
cout << "a = " <<a<<endl; //Prints characters "a = " followed by the value of the variable "a" and carries on to the next line
int j = a*i; //Initializes integer type variable "j" with value "a*i" or the product of the values of variables "i" and "a."
cout << "a*i = "<<j<<endl; //Prints characters "a*i = " followed by the value of variable "j" and carries on to the next line
return 0; //Main function ends
} //See above
Creating, compiling, and running the code:
[cms-opendata@localhost Programs]$ nano variables.cpp
[cms-opendata@localhost Programs]$ g++ -Wall variables.cpp -o variables
[cms-opendata@localhost Programs]$ ./variables
hello world
i = 2
a = 3.3
a*i = 6
As a note, the value of a*i is not printed as 6.6 because the variable "j," where the values of variables "a" and "i" are calculated, is of integer type and cannot have a non-integer value.
Second variable & operations code with comments:
#include <iostream> //Initializes c++ utilities
using namespace std; //See above
int main() { //Initializes main function
int n=10; //Initializes integer "n" with value=10
cout << "n is "<<n<<endl; //Prints characters "n is " followed by the value of variable "n" and ends the line.
n--; //Subtracts 1 from the value of variable "n"
cout<<"n is now "<<n<<endl; //Prints characters "n is now " followed by the value of variable "n" and ends the line.
n++; //Adds 1 to the value of variable "n"
cout<<"n is now "<<n<<endl; //Prints characters "n is now " followed by the value of variable "n" and ends the line.
return 0; //Ends main function
} //See above
Compiling and running code:
[cms-opendata@localhost Programs]$ g++ -Wall variables2.cpp -o variables2
[cms-opendata@localhost Programs]$ ./variables2n is 10
n is now 9
n is now 10
The "--" function subtracts 1 from the value of the variable, while "++" adds 1. It is funny that "++" is a function in the language "c++," but the function is present in the language's predecessor "c" as well.
Third variable & operations code with comments:
#include <iostream> //Initializes utilities
using namespace std; //^
int main() { //Initializes main function
bool prop; //Initializes bool type variable "prop"
prop = (5>1); //Sets the condition of bool type variable "prop" to true (value of 1) if "5>1" is true or false (value of 0) if "5>1" is not true
cout<<"prop is "<<prop<<endl; //Prints characters "prop is " followed by the value of variable "prop" and ends the line
prop = (1>5); //Sets the condition of bool type variable "prop" to true (value of 1) if "1>5" is true or false (value of 0) if "1>5" is not true
cout<<"prop is "<<prop<<endl; //Prints characters "prop is " followed by the value of variable "prop" and ends the line,
prop = (1 != 5); //Sets the condition of bool type variable "prop" to true (value of 1) if "1!=5" (1 does not equal 5) is true or false (value of 0) if "1!=5" is not true
cout << "prop is " <<prop<<endl; //Prints characters "prop is " followed by the value of variable "prop" and ends the line
return 0; //Ends main function
} //^
Compiling and running code:
[cms-opendata@localhost Programs]$ g++ -Wall variables3.cpp -o variables3
[cms-opendata@localhost Programs]$ ./variables3prop is 1
prop is 0
prop is 1
Oct. 14th - HW 5:
First practice code with comments:
#include <iostream> //Initializes utilities
using namespace std;
int main() { //Initializes main function
int n = 10; //Initializes integer type variable "n" with value=10
while (n>=10) { //Starts a loop that continues if the value of variable "n" is greater than or equal to 10
if(n>5) { //Begins the following code if the value of variable "n" is greater than 5
cout<<"n is "<<n<<endl;
} else {
cout<<"n = "<<n<<endl;
n--;
}
return 0;
}
Logic statement code and comments:
#include <iostream>
using namespace std;
int main() {
int n = 10; //Initializes integer variable "n" with value=10
while (n>=10) { //Starts and continues a loop as long as variable "n" has a value greater or equal to "10."
if(n>5) { //Continues to the line below if variable "n" has a value greater than 5
cout<<"n is "<<n<<endl; //Prints "n is " followed by the value of the variable "n" and then ends the line
} //Ends the lines of code only accessed by the "if" statement above
else { //Continues to the lines below if variable "n" does not match any above "if" statements, which in this case means if "n" has a value of 5 or lower.
cout<<"n = "<<n<<endl; //Prints "n = " followed by the value of variable "n" and then ends the line
n--; //Subtracts 1 from the value of "n"
} //Ends the lines of code only accessed by the "else" statement above
return 0; //Ends the program (and breaks the loop)
} //Ends (does not break) the "while" loop
} //Ends the program
Compiling and Output:
[cms-opendata@localhost Programs]$ g++ -Wall logic.cpp -o logic
[cms-opendata@localhost Programs]$ ./logic
n is 10
There seem to be a few unexpectedly placed lines of code so the loop only runs once and then the whole code ends due to what seems like a misplaced "return 0;"
Pointers code with comments:
#include <iostream>
using namespace std;
int main() {
int i = 10; //Declares integer variable "i" with value=10
cout << "The memory address of i is " << &i << "\n"; //Prints the written phrase followed by the memory address where variable "i" is stored on the machine and then ends the line
cout << "The data stored at memory address " << &i << " is " << i << "\n"; //Prints the written phrase followed by the memory address "i" is stored on followed by "is " followed by the value of variable "i" and then ends the line
int* p = &i; //Declares variable "p" as a pointer with the value of the memory address of variable "i"
cout << "The value of p is " << p << "\n"; //Prints the written phrase followed by value of pointer "p" and ends the line
cout << "We say that p 'points at' the memory location referenced by address " << p << "\n"; //Prints the written phrase followed by the value of the pointer pointer "p"
cout << "The data stored at memory address " << p << " is " << *p << "\n"; //Prints the written phrase followed by the value of pointer "p" followed by the value of the variable stored on the memory address stored in pointer "p," which is the variable "i" with value=10
return 0; //Ends the code
}
Code Compiling and Output:
[cms-opendata@localhost Programs]$ g++ -Wall pointers.cpp -o pointers
[cms-opendata@localhost Programs]$ ./pointers
The memory address of i is 0x7fffb6220d74
The data stored at memory address 0x7fffb6220d74 is 10
The value of p is 0x7fffb6220d74
We say that p 'points at' the memory location referenced by address 0x7fffb6220d74
The data stored at memory address 0x7fffb6220d74 is 10
If we wished to declare pointers that pointed to memory addresses storing variable other than integers, we would simply declare the pointer using the desired variable type. If one wanted to declare a pointer that pointed to a memory address storing a double, one would declare the pointer using "double*" instead of "int*"
First practice code with comments:
#include <iostream>
using namespace std;
int main(){
int i = 10; //Declares integer variable "i" with value=10
int j = i; //Declares integer variable "j" with value = the value of variable "i"
cout << "i= " << i << " and j= " << j << "\n"; //Prints "i= " followed by the value of variable "i" followed by " and j= " followed by the value of variable "j"
i=5; //Changes the value of declared variable "i" to 5
cout << "i= " << i << " and j= " << j << "\n"; //Prints "i= " followed by the value of variable "i" followed by " and j= " followed by the value of variable "j"
j=1; //Changes the value of declared variable "j" to 1
cout << "i= " << i << " and j= " << j << "\n"; //Prints "i= " followed by the value of variable "i" followed by " and j= " followed by the value of variable "j"
return 0; //Ends the code
}
Compiling and Running:
[cms-opendata@localhost Programs]$ g++ -Wall pointers2.cpp -o pointers2
[cms-opendata@localhost Programs]$ ./pointers2
i= 10 and j= 10
i= 5 and j= 10
i= 5 and j= 1
Second Practice code with comments:
#include <iostream>
using namespace std;
int main(){
int i = 10; //Declares integer variable "i" with value=10
int* p = &i; //Declares pointer variable "p" with value = the memory address where variable "i" is stored
cout << "i= " << i << " and *p= " << *p << "\n"; //Prints "i= " followed by the value of variable "i" followed by "and *p= " followed by the value of the variable stored at the memory address "p" points to which is variable "i" with value=10
i=5; //Changes the value of declared variable "i" to 5
cout << "i= " << i << " and *p= " << *p << "\n"; //Prints "i= " followed by the value of variable "i" followed by "and *p= " followed by the value of the variable stored at the memory address "p" points to which is variable "i" with value=5
*p=1; //Changes the value of the variable stored at the memory address pointer "p" points to, which is variable "i," to value=1
cout << "i= " << i << " and *p= " << *p << "\n"; //Prints "i= " followed by the value of variable "i" (which has been changed to 1) followed by "and *p= " followed by the value of the variable stored at the memory address "p" points to which is variable "i" with value=1
return 0; //Ends code
}
Compiling and running:
[cms-opendata@localhost Programs]$ g++ -Wall pointers3.cpp -o pointers3
[cms-opendata@localhost Programs]$ ./pointers3i= 10 and *p= 10
i= 5 and *p= 5
i= 1 and *p= 1
The behavior of the second program is different from the first because in the second program, an alternative method of manipulating the variable "i" is used before the last printed statement by changing the value of variable "i" by changing the value of the variable stored at the memory address pointer "p" points to, which is exactly "i." Each printed statement using "p" in the second program provides the value of the variable at the memory address "p" points to by using the "*p" tag.
Example pointer code with comments:
#include <iostream>
using namespace std;
int main(){
int* p = new int(5); //Declares a pointer that points to a memory address storing an integer and set the value stored at that memory address = 5
cout << "p points at address " << p << "\n"; // Prints the written phrase followed by the memory address represented by the pointer "p"
cout << "The data stored in address " << p << " is " << *p << "\n"; //Prints the written phrase followed by memory address represented by "p" followed by " is " followed by the value stored at the memory address "p" represents
*p = 10; //Changes the value stored at the memory address "p" points to from 5 to 10
cout << "Now the data stored in address " << p << " is " << *p << "\n"; //Prints the written phrase followed by the memory address represented by "p" followed by " is " followed by the value stored at the memory address "p" represents
return 0; //Ends code
}
Compiling and Running:
[cms-opendata@localhost Programs]$ g++ -Wall pointers4.cpp -o pointers4
[cms-opendata@localhost Programs]$ ./pointers4
p points at address 0xc95010
The data stored in address 0xc95010 is 5
Now the data stored in address 0xc95010 is 10
Practice pointers code with comments:
#include <iostream>
using namespace std;
int main(){
double* p1 = new double(3.14); //Declares a pointer that points to a memory address storing a double and sets the value stored at that memory address = 3.14
double* p2 = new double(*p1); //Declares a pointer that points to a memory address storing a double and sets the value stored at that memory address equal to the value stored at the memory address "p1" points to
cout << "p1 points at address " << p1 << " and p2 points at address" << p2<<"\n"; // Prints the written phrase followed by the memory address represented by the pointer "p1" followed by the written phrase followed by the memory address represented by the pointer "p2" and ends the line
cout << "The data stored in p1 is " << *p1 << " and in p2 is " << *p2 << "\n"; //Prints the written phrase followed by the value stored at the memory address pointer "p1" points to followed by " and in p2 is " followed by the value stored at the memory address "p2" points to
cout << "*p1 * *p2 = " << *p1**p2 << "\n"; //Prints "*p1 * *p2 = " followed by the product of the values stored at the memory addresses pointer "p1" and "p2" point to which is 3.14*3.14
cout << "The data stored in p1 is now " << *p1 << " and in p2 is " << *p2 << "\n"; //Prints the written phrase followed by the value stored at the memory address pointer "p1" points to followed by " and in p2 is " followed by the value stored at the memory address pointer "p2" points to and then ends the line
return 0; //Ends the code
}
Compiling and Running:
[cms-opendata@localhost Programs]$ g++ -Wall pointers4.cpp -o pointers4
[cms-opendata@localhost Programs]$ ./pointers4
p1 points at address 0xb25010 and p2 points at address0xb25030
The data stored in p1 is 3.14 and in p2 is 3.14
*p1 * *p2 = 9.8596
The data stored in p1 is now 3.14 and in p2 is 3.14
HW 5 Code prompts:
Logic statement practice code with comments:
#include <iostream>
using namespace std;
int main() {
int t = 6; //Declares the integer variable "t" with value=6
while (t>0) { //Begins and continues a loop if value of "t" is greater than 0
t--; //Subtracts 1 from the value of "t"
if (t>0) { //Continues to the next line of code if the value of "t" is greater than 0
cout<<"The value of t is "<<t<<endl; //Prints the written phrase followed by the value of "t" and ends the line
} else { //Ends the previous "if" statement and begins an "else" statement that continues to the next line of code if the previous "if" statements were not met, which means t=<0 in this case
cout<<"The value of t is 0 and the loop breaks"<<endl; //Prints the written statement and ends the line
} //Ends the "else" statement's lines of code
} //Ends, but does not break, the "while" loop
return 0; //Ends the code
}
Compiling and Running:
[cms-opendata@localhost Programs]$ g++ -Wall logic2.cpp -o logic2
[cms-opendata@localhost Programs]$ ./logic2
The value of t is 5
The value of t is 4
The value of t is 3
The value of t is 2
The value of t is 1
The value of t is 0 and the loop breaks
HW 5: Scripting Prompts:
Shell Scripting prompt:
Script with comments:
#!/bin/tcsh
set month = `date | awk '{print $2}'` #Sets and declares variable “month” with the value of the current month
echo $month #Prints the value of variable “month”
ls -lat | grep "$month" #Lists, with expanded details, the files created in the current month
Running:
[cms-opendata@localhost Programs]$ ./date.tchs
Oct
-rwxrwxr-x 1 cms-opendata cms-opendata 94 Oct 16 19:49 date.tchs
drwxrwxr-x 2 cms-opendata cms-opendata 4096 Oct 16 19:28 .
-rwxrwxr-x 1 cms-opendata cms-opendata 8463 Oct 16 19:20 logic2
-rw-rw-r-- 1 cms-opendata cms-opendata 230 Oct 16 19:20 logic2.cpp
-rwxrwxr-x 1 cms-opendata cms-opendata 9576 Oct 16 19:04 pointers4
-rw-rw-r-- 1 cms-opendata cms-opendata 456 Oct 16 19:02 pointers4.cpp
-rwxrwxr-x 1 cms-opendata cms-opendata 8212 Oct 16 18:43 pointers3
-rw-rw-r-- 1 cms-opendata cms-opendata 301 Oct 16 18:43 pointers3.cpp
-rwxrwxr-x 1 cms-opendata cms-opendata 8172 Oct 16 18:29 pointers2
...
Oct. 28th - HW 6:
Terminal commands:
[cms-opendata@localhost ~]$ cd CMSSW_5_3_32/src/
[cms-opendata@localhost src]$ cmsenv
[cms-opendata@localhost src]$ mkdir testRoot
Array code with comments:
#include <iostream>
using namespace std;
int main() {
int ii[3] = {1,2,3}; //Declares an array "ii" of 3 integers with values of 1, 2, and 3
int j=0; //Declares an integer variable "j" with value=0
while (j<3) { //Begins a while loop that continues if the value of variable "j" is less than 3
cout <<" ii of "<<j<<" is "<<ii[j]<<endl; //Prints " ii of " followed by the value of variable "j" followed by " is " followed by the value of array "ii" at position of the value of the variable "j"
j++; //Adds 1 to the value of "j"
} //Ends but does not break the "while" loop
int LL[2][3] = {1,2,3,4,5,6}; //Declares a multidimensional integer array "LL" with values of 1, 2, and 3 in [0][0], [0][1], and [0][2] positions respectively and values of 4, 5, and 6 in [1][0], [1][1], and [1][2] positions respectively
j=0; //Sets value of variable "j" to 0
int k; //Declares variable "k"
while (j<2) { //Begins while loop that continues if the value of "j" is less than 2
k=0; //Sets value of variable "k" to 0
while (k<3) { //Begins a while loop that continues if the value of "k" is less than 3
cout<<" LL of "<<j<<" "<<k<<" is "<<LL[j][k]<<endl; //Prints " LL of " followed by the value of "j" followed by a space followed by the value of "k" followed by " is " followed by the value of the array "LL" at the position of the value of "j" and the value of "k"
k++; //Adds 1 to the value of "k"
} //Ends but does not break the interior while loop
j++; //Adds 1 to the value of "j"
} //Ends but does not break the exterior while loop
return 0; //Ends the program
}
Compiling and running:
[cms-opendata@localhost Programs]$ g++ -Wall array.cpp -o array
array.cpp: In function 'int main()':
array.cpp:12: warning: missing braces around initializer for 'int [3]'
array.cpp:12: warning: missing braces around initializer for 'int [3]'
[cms-opendata@localhost Programs]$ ./array
ii of 0 is 1
ii of 1 is 2
ii of 2 is 3
LL of 0 0 is 1
LL of 0 1 is 2
LL of 0 2 is 3
LL of 1 0 is 4
LL of 1 1 is 5
LL of 1 2 is 6
The next sample code does not add anything to the code. It only demonstrates ways by which to place text on the code without disrupting the program by using "/* */" which comments (makes the text non-coding/functional text) what is between the asterisks or "//" which comments whatever text follows the slashes on that line.
Using exterior files in programs code with comments:
#include <iostream>
#include <fstream>
using namespace std;
int main() {
ofstream myfile; //Initializes an exterior file class that can be written to named "myfile"
myfile.open("example.txt"); //Creates a file named "example.txt"
myfile<<"write some junk."; //Places the text printed into the file "example.txt"
myfile.close(); //Closes the file "myfile"
return 0;
}
Running and reading the created file:
[cms-opendata@localhost Programs]$ ./ext_file
[cms-opendata@localhost Programs]$ nano example.txt
{Inside example.txt}
write some junk.
Using exterior files second example code with comments (additional comments bolded):
/* MAIN.CPP */
#include <iostream>
#include <fstream>
#include "dotprod.cpp" //include the program dotprod.cpp so that we can find the dot_prod function
using namespace std;
int main () {
// declare the vectors
double vector1[3];
double vector2[3];
// open the input file
ifstream infile;
infile.open("vectors.txt");
// store the input in the vectors and print the vectors for the user
infile>>vector1[0]>>vector1[1]>>vector1[2];
cout<<" Vector 1 is ("<<vector1[0]<<","<<vector1[1]<<","<<vector1[2]<<")"<<endl;
infile>>vector2[0]>>vector2[1]>>vector2[2];
cout<<" Vector 2 is ("<<vector2[0]<<","<<vector2[1]<<","<<vector2[2]<<")"<<endl;
// close the input file
infile.close();
// call the dot_prod function from dotprod.cpp
dot_prod(vector1,vector2);
return 0;
}
/* DOTPROD.CPP */
#include <iostream>
using namespace std;
//Declare the dot_prod function with inputs of double arrays v1[3] and v2[3]
double dot_prod(double v1[3],double v2[3]) {
//Declare, calculate, and print the dot product by multiplying each position of both arrays and adding their products
double dotdot;
dotdot = v1[0]*v2[0]+v1[1]*v2[1]+v1[2]*v2[2];
cout<<" The dot product is "<<dotdot<<endl;
return 0;
}
Running the code:
[cms-opendata@localhost Programs]$ ./main
Vector 1 is (1,2,3)
Vector 2 is (4,5,6)
The dot product is 32
Modified second example code with comments:
/* MAIN.CPP */
#include <iostream>
#include <fstream>
// include the program dotprod.cpp so that we can find the dot_prod function
#include "dotprod.cpp"
#include "scalarmult.cpp" //Includes newly created function to find the scalar multiple
using namespace std;
int main () {
// declare the vectors
double vector1[3];
double vector2[3];
//Declare the scalar
double scalar;
// open the input file
ifstream infile;
infile.open("vectors.txt");
// store the input in the vectors and print the vectors for the user
infile>>vector1[0]>>vector1[1]>>vector1[2];
cout<<" Vector 1 is ("<<vector1[0]<<","<<vector1[1]<<","<<vector1[2]<<")"<<endl;
infile>>vector2[0]>>vector2[1]>>vector2[2];
cout<<" Vector 2 is ("<<vector2[0]<<","<<vector2[1]<<","<<vector2[2]<<")"<<endl;
//Store the input in the scalar and print the scalar
infile>>scalar;
cout<<" The scalar is "<<scalar<<""<<endl;
// close the input file
infile.close();
// call the dot_prod function from dotprod.cpp
dot_prod(vector1,vector2);
//Call the scalar_mult function from scalarmult.cpp for each vector
scalar_mult(vector1, scalar);
scalar_mult(vector2, scalar);
return 0;
}
/*SCALARMULT.CPP*/
#include <iostream>
using namespace std;
double scalar_mult(double v[3], double scalar) {
//Declare the scalar multiple array
double v2[3];
//Multiply each array position by the scalar
for (int t=0; t<3; t++) {
v2[t]=scalar*v[t];
}
//Print the output
cout<<" The scalar multiple is ("<<v2[0]<<","<<v2[1]<<","<<v2[2]<<")"<<endl;
return 0;
}
Running the code:
[cms-opendata@localhost Programs]$ ./main
Vector 1 is (1,2,3)
Vector 2 is (4,5,6)
The scalar is 7
The dot product is 32
The scalar multiple is (7,14,21)
The scalar multiple is (28,35,42)
Pseudo-Random number example code with edits and comments(additional comments bolded):
#include <iostream>
#include <math.h>
using namespace std;
// this function is the actual random number generator
// this code is stolen from the book numerical recipes for fortran
// it relies on random generated from overflow of memory locations
// and is a pseudo random number generator
const int a = 7141; //Declares an intransigent constant "a" with value=7141
const int c = 54773; //Declares an intransigent constant "c" with value=54773
const int mmod=256200; //Declares an intransigent constant "mmod" with value=256200
double getFlatRandom(int& inew) {
double mranflat = 0.;
inew = inew%mmod; //Sets variable "inew" to the remainder of the quotient when "inew" is divided by "mmod"
double aa = double(inew)/double(mmod);
mranflat=aa; //Sets variable "mranflat" to the double value of "inew" divided by "mmod"
inew = a*inew+c; //Changes the value of inew linearly by multiplying by "a" and adding "c"
return mranflat; //Returns the value of "mranflat" to the code
}
// in this code, we will call the pseudo-random number generator and learn some things
// about its properties by filling and then displaying a histogram
int main() {
int num;
cout << "Enter the number of loop iterations: ";
cin >> num;
int inew = 2345; // This is the "seed" for the random number generator
// we will put the results from the call into a histogram that we can look at, to learn some of its
// properties. This histogram has 10 bins.
int histo[10] = {0,0,0,0,0,0,0,0,0,0};
double atmp; //
// call the random number generator 1000 times and fill a histogram
for (int i = 0; i<num; i++){
atmp=getFlatRandom(inew); // call the random number generator
histo[int(atmp*10)]++; // increment the histogram bin the number falls within
}
// print the histogram to the screen
for (int i = 0; i<10; i++){
cout<<i<<": ";
for (int j=0; j<int((double(100*histo[i])/double(num))+0.5); j++) {
cout << "=";
}
cout << endl;
}
return 0;
}
Running the code:
[cms-opendata@localhost Programs]$ ./random
Enter the number of loop iterations: 1000
0: ==========
1: ==========
2: =========
3: ==========
4: ==========
5: ==========
6: ===========
7: ==========
8: ==========
9: ==========
If you remove the & from “double getFlatRandom(int& inew) {“ the function returns its value when only using the “seed” value of inew=2345 and is never changed. This results in every iteration of the loop returning a value that is only placed in the first bin.
True random number code with comments:
#include <iostream> #include <stdio.h> #include <stdlib.h> //Includes all of the necessary functions to generate a random number #include <time.h> using namespace std; int main(){ cout << "Random Number " << rand()%100<<endl; //Prints a random number between [0,100) return 0; }
Compiling and running:
[cms-opendata@localhost Programs]$ g++ -Wall random2.cpp -o random2
[cms-opendata@localhost Programs]$ ./random2
Random Number 83
Subsequent attempts at running the above code return the same "random" number.
Nov. 12th - HW 7:
Parts of the CMS Detector:
Beam Pipe - The beam pipe is the 6.3 cm in diameter tube that protons are sped up in to prepare for a high energy collision
Tracker - The tracker records the positions of charged particles as they travel through the tracker in order to calculate useful information such as momentum. It is 2.2
meters in diameter.
Calorimeter - Two calorimeters make up the CMS, the first being the ECAL that measures the energy of photons and electrons, and the second being the HCAL that measures the energy of hadrons, or particles made up of quarks and gluons. The ECAL has a circumference of about 2.5m.
Solenoid - The solenoid is a large magnet that bends the path of charged particles generated from the collision. It is 13 meters long and 6 meters in diameter.
Muon tracker - The muon tracker uses three detectors, drift tubes, cathode strip chambers, and resistive plate chambers, to identify muons leaving the end of the experiment. It completes the CMS and has a diameter of 15 meters and a length of 21.6 meters.
Green color tracks are electrons, red color tracks are muons, and missing energy is represented with a pink dotted line. Jets are represented by yellow cones with their vertices at the point of collision. Bending counterclockwise represents a negative charge.
4lepton.ig Event 1
4 Muons
35 Jets (PF)
1 Missing energy (PF)
5 Vertices
4lepton.ig Event 2
4 Electrons
2 Muons
4 photons
62 Jets (PF)
1 Missing energy (PF)
11 Vertices
diphoton.ig Event 1
2 Photons
31 Jets (Reco)
1 Missing energy (Reco)
11 Vertices
diphoton.ig Event 2
2 Photons
29 Jets
1 Missing energy (Reco)
6 Vertices
MinimumBias.ig Event 1
14 Jets
3 Vertices
MinimumBias.ig Event 2
1 Vertex
Mu.ig Event 1
1 Vertex
Mu.ig Event 2
17 Jets
3 Vertices
Electron.ig Event 1
1 Electron
2 Photons
13 Jets (Reco)
1 Missing Energy (Reco)
1 Vertex
Electron.ig Event 2
1 Electron
1 Photon
18 Jets (Reco)
1 Missing energy (Reco)
3 Vertices
Nov. 11th - HW 8:
The command creates a .h/header file (HiggsAnalysis.h) that contains a class for use in a root file that was also created (HiggsAnalysis.C).
Code (My comments in bold):
#define HiggsAnalysis_cxx
#include "HiggsAnalysis.h" //Include necessary files
#include <TH2.h>
#include <TStyle.h>
#include <TCanvas.h>
void HiggsAnalysis::Loop() { //Declares the following code as the method “Loop()” of class “HiggsAnalysis”
// In a ROOT session, you can do:
// Root > .L HiggsAnalysis.C
// Root > HiggsAnalysis t
// Root > t.GetEntry(12); // Fill t data members with entry number 12
// Root > t.Show(); // Show values of entry 12
// Root > t.Show(16); // Read and show values of entry 16
// Root > t.Loop(); // Loop on all entries
// This is the loop skeleton where:
// jentry is the global entry number in the chain
// ientry is the entry number in the current Tree
// Note that the argument to GetEntry must be:
// jentry for TChain::GetEntry
// ientry for TTree::GetEntry and TBranch::GetEntry
// To read only selected branches, Insert statements like:
// METHOD1:
// fChain->SetBranchStatus("*",0); // disable all branches
// fChain->SetBranchStatus("branchname",1); // activate branchname
// METHOD2: replace line
// fChain->GetEntry(jentry); //read all branches
//by b_branchname->GetEntry(ientry); //read only this branch
if (fChain == 0) return; //If there is no data, end the method
Long64_t nentries = fChain->GetEntriesFast(); //Declares object “nentries” of class “Long64_t” with value of the output of method “GetEntriesFast()”
Long64_t nbytes = 0, nb = 0; //Declares both objects “nbytes” and “nb” of class “Long64_t” each with value=0
TFile* output = TFile::Open("Dielectron_MC.root", "RECREATE"); // "RECREATE" would produce a new root file with name Dielectron_MC.root every time you run the code
//Each of the following lines creates a histogram in “Dielectron_MC.root”
//Histogram for Higgs boson masses:
TH1F* H_zz = new TH1F("H_zz", "ZZ candidate invariant mass", 200, 0, 300);
//Histogram for first Z boson masses:
TH1F* Z_ee = new TH1F("Z_ee", "Di-electron candidate invariant mass", 200, 0, 200);
//Histogram for second Z boson masses:
TH1F* Z2_ee = new TH1F("Z2_ee", "Di-electron candidate invariant mass", 200, 0, 200);
//The following 3 lines create double variables “el1mt,” “el1pt,” and “el1eta” with all values=0.0
double el1mt = 0.0;
double el1pt = 0.0;
double el1eta = 0.0;
for (Long64_t jentry=0; jentry<nentries;jentry++) { //Begins a for loop; declares an object “jentry” of class “Long64_t”; continues the for loop if the object “jentry” is less than the object “nentries”; adds 1 to the value of “jentry” upon each looping
Long64_t ientry = LoadTree(jentry); //Declares the object “ientry” of class “Long64_t” with value=method “LoadTree()” with argument “jentry”
if (ientry < 0) break; //If the value of the method “LoadTree()” with argument “jentry” (the value of “ientry”) is negative, then break the for-loop.
nb = fChain->GetEntry(jentry); nbytes += nb; //Sets object “nb” to value of method “GetEntry()” with argument “jentry;” Sets the value of object “nybtes” to its value plus “nb”
// if (Cut(ientry) < 0) continue;
//The next section creates/sets characteristics of electron vectors and adds the vectors to get a Z boson vector.
//This occurs twice in order to perform the same operation for the Higgs boson vector.
//A calculation is done on the Z boson vectors and Higgs vector to end with their masses, which is plotted on appropriate histograms to find the most common/likely mass of each particle.
TLorentzVector el1, el2; //Creates two objects (electron vectors) “el1” and “el2” of class “TLorentzVector”
el1.SetPtEtaPhiM(f_lept1_pt, f_lept1_eta, f_lept1_phi, 0.0); //performs method “SetPtEtaPhiM” for object “el1” with arguments “f_lept1_pt,” “f_lept1_eta,” “f_lept1_phi,” and 0.0
el2.SetPtEtaPhiM(f_lept2_pt, f_lept2_eta, f_lept2_phi, 0.0); //performs method “SetPtEtaPhiM” for object “el2” with arguments “f_lept2_pt,” “f_lept2_eta,” “f_lept2_phi,” and 0.0
TLorentzVector zCandidate = el1 + el2; //Declares object “zCandidate” (a potential Z boson) of class “TLorentzVector” with value=object “el1” plus object “el2”
Z_ee->Fill(zCandidate.M()); //Adds the result of method “M()” performed under object “zCandidate,” to the histogram “Z_ee” as an entry
el1mt = el1.Mt(); //Sets variable “el1mt” to the result of method “Mt()” performed under object “el1”
cout << el1mt << endl; //Prints “el1mt”
TLorentzVector el3, el4; //Creates two objects (electron vectors) “el3” and “el4” of class “TLorentzVector”
el3.SetPtEtaPhiM(f_lept3_pt, f_lept3_eta, f_lept3_phi, 0.0); //performs method “SetPtEtaPhiM” for object “el3” with arguments “f_lept3_pt,” “f_lept3_eta,” “f_lept3_phi,” and 0.0
el4.SetPtEtaPhiM(f_lept4_pt, f_lept4_eta, f_lept4_phi, 0.0); //performs method “SetPtEtaPhiM” for object “el4” with arguments “f_lept4_pt,” “f_lept4_eta,” “f_lept4_phi,” and 0.0
TLorentzVector zCandidate2 = el3 + el4; //Declares object “zCandidate2” (another potential Z boson) of class “TLorentzVector” with value=object “el3” plus object “el4”
Z2_ee->Fill(zCandidate2.M()); //Adds the result of method “M()” performed under object “zCandidate,” to the histogram “Z2_ee” as an entry
TLorentzVector Higgs = zCandidate + zCandidate2; //Creates an object “Higgs” objects of class “TLorentzVector” with value=the sum of the 2 z boson vectors or of objects “zCandidate” and “zCandidate2”
H_zz->Fill(Higgs.M()); //Adds the result of method “M()” performed under object “Higgs” to the histogram “H_zz” as an entry
el3mt = el3.Mt(); //Sets variable “el3mt” to the result of method “Mt()” performed under object “el3”
cout<<el3mt<<endl; //Prints value of “el3mt”
} //Ends (does not break) the for-loop
Z_ee->Write(); //Writes the data of the histogram “Z_ee” to a file
Z2_ee->Write(); //Writes the data of the histogram “Z2_ee” to a file
H_zz->Write(); //Writes the data of the histogram “H_zz” to a file
output->Close(); //Ends access to the output file
} //Ends the method
Histogram for Z_ee (first Z boson):
Histogram for Z2_ee (second Z boson):
Histogram for H_zz (Higgs):
Nov. 19th - HW 9:
Difference between CPU and GPU:
The CPU (Central Processing Unit) carries out the tasks sent to it by a computer by performing mathematical operations using circuits.
A GPU (Graphics Processing Unit) takes tasks created by a computer specifically designed to display an image of some kind to a visual interface; a screen.
The CPU handles general tasks of the logic and mathematics behind the computer, while the GPU handles graphics-specific tasks to maximize efficiency and display complex images effectively.
First code:
pandas=10 #Declares variable "panda" with value=10
zebras=20 #Declares variable "zebras" with value=20
total_animals_in_zoo=pandas+zebras #Declares variable "total_animals_in_zoo" with value=value of variable "pandas" added to value of variable "zebras"
print(total_animals_in_zoo) #Print the value of variable "total_animals_in_zoo"
Code Output:
30
Second code:
pi=3.14159 #Declares approximate value of pi
diameter=10 #Declares a variable “diameter” with value=10
radius=diameter/2 #Declares a variable “radius” with value=one half of “diameter”
area=pi*radius*radius #Declares a variable “area with value=value of “pi” multiplied by the value of “radius,” multiplied by the value of “radius”
print(area) #Prints the value of variable “area”
Code Output:
78.53975
Third code:
#####Method 1########
a = [1, 2, 3]
b = ['cat', 'dog', 'fish']
a=b
b=a
print('Method 1')
print(a)
print(b)
#####Method 2########
a = [1, 2, 3]
b = ['cat', 'dog', 'fish']
temp = a
a = b
b = temp
print('Method 2')
print(a)
print(b)
Code Output:
Method 1
['cat', 'dog', 'fish']
['cat', 'dog', 'fish']
Method 2
['cat', 'dog', 'fish']
[1, 2, 3]
The first method doesn’t work because setting b=a after having just set a=b does not perform any operation since the two values are already equivalent.
Fourth Code:
dog_legs=0
human_legs=4
goldfish_legs=2
temp1 = dog_legs #Sets a temporary variable to the value of “dog_legs”
temp2 = human_legs #Sets 2nd temporary variable to the value of “human_legs”
temp3 = goldfish_legs #Sets 3rd temporary variable to the value of “goldfish_legs”
#This block Rearranges the variable values with the correct temporary variable values
dog_legs = temp2
human_legs = temp3
goldfish_legs = temp1
#This block prints the results
print('Dogs have', dog_legs, 'legs')
print('Humans have', human_legs, 'legs')
print('Goldfish have', goldfish_legs, 'legs')
Code Output:
Dogs have 4 legs
Humans have 2 legs
Goldfish have 0 legs
Fifth Code:
def round_to_n_places(num, places): #Creates a function that takes two arguments
return round(num, places) #Returns the value of variable “num” rounded to
#“places” number of places
print(round_to_n_places(4.325456463, 4)) #Prints the value of the function
#“round_to_n_places” when the “num” #variable is “4.325456463” and when #the “places” variable is 4
Code Output:
4.3255
Sixth Code:
a=[1,5435,324,3,645365,23,4,5665,435,31, -543]
b=-10
c='cat'
print(c)
print(abs(b)) #absolute value
print(min(a)) #min value
print(max(a)) #max value
print(sum(a)) #sum
print(len(c)) #length of a string
print(sorted(a)) #sorts a list
Code Output:
cat
10
-543
645365
656743
3
[-543, 1, 3, 4, 23, 31, 324, 435, 5435, 5665, 645365]
Seventh Code:
a=[3243,645645,54346]
b=[7,3,2]
def product_of_maxes(a, b): #Defines function with arguments list “a” and list “b”
max_a = max(a) #Declares variable “max_a” with value=maximum of list “a”
max_b = max(b) #Declares variable “max_b” with value=maximum of list “b”
return(max_a*max_b) #Returns the product of the maxes stored in variables
print(product_of_maxes(a, b)) #Prints the result of the function with argument lists
#“a” and “b”
Code Output:
4519515
Eighth Code:
print(3==10)
print(len('abc')==3)
print(max([10,40,53]) < 25)
print (5 != 3)
Code Output:
False
True
False
True
The code evaluates each equivalence for whether or not each statement is true (which prints “True”) or false (which prints “False”).
Practice Code:
a = [1,2,3,4,5,6,7,8,9,10] #Declares list “a” filled with integers 1-10
max_a = max(a) #Declares variable that has the value of the maximum value in list
#“a”
print(10==max_a) #Prints True if the maximum value of list “a” is 10
Code Output:
True
Ninth Code:
Original Code:
a=10
b=20
if(a>b):
print(a, 'is greater than', b)
elif(a<b):
print(b, 'is greater than', a)
else:
print("they're equal")
Code Output:
20 is greater than 10
In order to get the other two possible outcomes:
a>b code:
a=20
b=10
if(a>b):
print(a, 'is greater than', b)
elif(a<b):
print(b, 'is greater than', a)
else:
print("they're equal")
Code Output:
20 is greater than 10
a=b code:
a=10
b=10
if(a>b):
print(a, 'is greater than', b)
elif(a<b):
print(b, 'is greater than', a)
else:
print("they're equal")
Code Output:
they’re equal
Tenth Code:
def longer_string(string1, string2): #Defines the function “longer_string” with
#argument lists “string1” and “string2”
if(len(string1) > len(string2)): #If the number of terms in “string1” is greater than
#“string2,” return the value of string2
return string1
elif(len(string1) < len(string2)): #If the number of terms in string 1 is less than
#string2, return string2
return string2
else: #If neither are true, return nothing.
return
print(longer_string('abc', 'jfkdla;s')) #Print the result of “longer_string” with string
#arguments as listed (for each of these lines)
print(longer_string('abcfdsafdasg', 'jfkdla;s'))
print(longer_string('abc', 'def'))
Code Output:
jfkdla;s
abcfdsafdasg
None
Eleventh Code:
def can_make_cake(eggs, flour, milk, almond_milk):
#I can make cake if I have some kind of milk AND flour AND eggs
return (milk or almond_milk) and flour and eggs > 0 #If the value of “milk” or
#“almond_milk” is greater than 0, and the value of both “flour” and “eggs” is
#greater than 0, then the result of the function is “True”
print('Can I make cake?')
Code Output:
Can I make cake?
The line “print(can_make_cake(10, True, False, True))” prints the result of the function evaluated with “eggs”=10, “flour”=1, “milk”=0, and “almond_milk”=1, which satisfies the necessary conditions and returns “True.”
In order to call the function with 0 eggs, the line should be:
print(can_make_cake(10, True, False, True))
12th Code:
a = [-35423,-5432654,-352435,53252]
def abs_of_min_is_odd(min):
mod=min%2 #sets variable “mod”=function argument modulus 2
return mod #returns “mod” (1 if odd, 0 if even)
if(abs_of_min_is_odd(min(a))==0): #If the returned value of the function with
#argument of the minimum value of list “a” is 0, print even
print('even')
Else: #If the return value is not 0, print odd
print('odd')
Code Output:
even
13th Code:
def select_third_element(my_list):
if(len(my_list) < 3): #If the length of the argument list is under 3 items, return
#nothing
return None
else: #If the length is greater than 2, return the 3rd item of the list
return my_list[2] #remember index 0, so third element is index 2
foo = ['a', 'b', 'c', 'd']
print(select_third_element(foo)) #prints the third element of list “foo”
list1=[1,2,3]
list2=[4,5,6]
list_of_lists=[list1,list2] #Creates a list of list1 and list2 with
# form “list_of_lists[{Position of list in list_of_lists}][{position in
# indicated list}]”
print(list_of_lists[1][2]) #Prints the third element of the second list in “list_of_lists”
Code Output (Original):
c
6
Code Output w/ print(list_of_lists[0]):
c
6
[1,2,3]
Code Output w/ print(list_of_lists[1]):
c
6
[1,2,3]
[4,5,6]
Code Output w/ print(list_of_lists[0][1]):
c
6
[1,2,3]
[4,5,6]
2
Code Output w/ print(list_of_lists[0][2]):
c
6
[1,2,3]
[4,5,6]
2
3
Code Output w/ print(list_of_lists[1][0]):
c
6
[1,2,3]
[4,5,6]
2
3
4
14th Code:
real_madrid=['zidane', 'ramos', 'marcelo']
barcelona=['valverde', 'messi', 'pique']
teams = [real_madrid, barcelona]
def losing_team_captain(team_list):
return teams[1][1] #Return the worst team’s (teams[1]... is the second team in
#the list) captain (teams…[1] is the captain of the indicated team)
print(losing_team_captain(teams)) #prints result of function with argument
#“teams”
Code Output:
messi
15th Code:
standings=['mario', 'bowser', 'luigi','peach']
def purple_shell(racers):
first=racers[0] #Defines “first” as the first element of “standings”/”racers”
last=racers[3] #Defines “last” as the 4th element of “standings”/”racers”
racers[3]=first #Sets 4th element of “racers” to “first”
racers[0]=last #Sets first element of “racers” to “last”
return racers #Returns the edited list
print(purple_shell(standings)) #Prints the edited list resulting from function
#“purpe_shell” with list argument “standings”
Code Output:
['peach', 'bowser', 'luigi', 'mario']
15th Code (Non-homework):
def list_contains_seven(my_list):
for element in my_list: #Loops through every element of list “my_list”
if element ==7: #If an element==7, the function returns “True”
return True
return False #Otherwise, return “False
print(list_contains_seven([6,14,5,7]))
print(list_contains_seven([6,14,5,9]))
Code Output:
True
False
16th Code (Practice):
def count_to_10(num):
while(num<10): #Continues loop if the variable “num” is less than 10
num=num+1 #Adds 1 to the value of “num”
print(num) #Prints “num”
count_to_10(0) #Performs function starting at num=0
count_to_10(5) #Performs function starting at num=5
count_to_10(11) #Performs function starting at num=11 (Which gives no result)
Code Output:
1
2
3
4
5
6
7
8
9
10
6
7
8
9
10
17th Code:
list=[1,21,7,-14,49,74,700]
def seven_counter(my_list):
num=0
for element in my_list: #Continues loop for every element in “my_list”
if element%7==0: #If an element is perfectly divisible by 7, add 1 to a counter
#variable “num”
num+=1
return num #Return “num” (Count of elements divisible by 7)
print(seven_counter(list), 'out of', len(list)) #Prints result of function with argument
#“list followed by ”out of” followed by the length of “list”
Code Output:
5 out of 7
18th Code:
deck={} #represents a deck of cards where the keys are the suits and values are lists of card values
hearts=[]
clubs=[]
diamonds=[]
spades=[]
values=['ace', 'two', 'three', 'four', 'five', 'six','seven', 'eight', 'nine', 'jack', 'king', 'queen']
def create_cards(suit):
for value in values:
suit.append(value)
create_cards(hearts)
create_cards(clubs)
create_cards(diamonds)
create_cards(spades)
#Use the strings 'h', 's', 'c', 'd' as keys, and add the lists of values to the dictionary
deck.setdefault('h', hearts)
deck.setdefault('s', spades)
deck.setdefault('c', clubs)
deck.setdefault('d', diamonds)
#Print a view of dictionary (key, value) pairs
print(deck.items())
#Print a view of all of the keys
print(deck.keys())
#Print a view of all of the values
print(deck.values())
#Remove all of the spades from the deck
deck.pop('s')
#Add a new entry to the dictionary with key 'j' and values 'joker1' and 'joker2'
jokers=['joker1','joker2']
deck.setdefault('j', jokers)
#Clear the dictionary
deck.clear()
Code Output:
dict_items([('h', ['ace', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'jack', 'king', 'queen']), ('s', ['ace', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'jack', 'king', 'queen']), ('c', ['ace', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'jack', 'king', 'queen']), ('d', ['ace', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'jack', 'king', 'queen'])])
dict_keys(['h', 's', 'c', 'd'])
dict_values([['ace', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'jack', 'king', 'queen'], ['ace', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'jack', 'king', 'queen'], ['ace', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'jack', 'king', 'queen'], ['ace', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'jack', 'king', 'queen']])
19th Code:
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
data = {'a': np.arange(50),
'c': np.random.randint(0, 50, 50),
'd': np.random.randn(50)}
data['b'] = data['a'] + 10 * np.random.randn(50)
data['d'] = np.abs(data['d']) * 100
plt.scatter('a', 'b', c='c', s='d', data=data) #Each point is given an x coordinate “a”
#a y coordinate “b,” a color “c,” and a size “d”
#using numbers from the “data” dictionary
plt.xlabel('entry a')
plt.ylabel('entry b')
plt.show()
Code Output:
20th Code:
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
x = np.arange(0, np.pi/4, 0.01) #Sets the range of x values
y = np.tan(4 * np.pi * x) #Sets the y values on the x value range
fig, tan = plt.subplots() #Creates a plot called “tan”
tan.plot(x, y) #Plots points on plot “tan” with x value=”x” and y value=”y”
tan.set(xlabel='x axis', ylabel='y axis', #Creates graph labels
title='Graph of tan(4*pi*x)') #Creates graph title
plt.show() #Displays the created plot
Code Output:
CMS Code:
Each column heading represents different properties of one of two particles including type, energy, transverse momentum, and charge. The data set contains 475465 events.
Code Output: