Dear experts,
I have been reading through other forums on how to save pdfs, but nothing is helping my particular situation. I am attempting to save selected histograms into a pdf or png file format directly from a python file, in this manner so far:
def validateFits(inFile):
fit = ROOT.TFile.Open(inFile, "READ")
[...]
if nSigFail < 1.0:
#print(nSigPass, nSigFail)
print(inFile)
c = fit.Get(inFile.split('/')[-1][:-5]+'Canv')
#print(vars(inFile).__dict__)
#c.Draw()
if not os.path.exists('plots/'): os.makedirs('plots/')
#myfile = ROOT.TFile.Get(inFile)
filename = fit.Get(inFile.split('/')[-1][:-5])
c.SaveAs('plots/'+ str(filename) + '.png')
But, I get this error:
./UL_2018/fits_data/muon/generalTracks/Z/Run2018_UL/AltBkg/NUM_LooseID_DEN_genTracks/NUM_LooseID_DEN_genTracks_abseta_1_pt_2.root
*** Break *** segmentation violation
===========================================================
There was a crash.
This is the entire stack trace of all threads:
===========================================================
Thread 2 (Thread 0x7f39675ce700 (LWP 25110)):
#0 0x00007f3986703de2 in pthread_cond_timedwait
GLIBC_2.3.2 () from /lib64/libpthread.so.0
#1 0x00007f3986cb7069 in PyCOND_TIMEDWAIT (cond=<optimized out>, mut=<optimized out>, us=<optimized out>) at /workspace/build/externals/Python-3.7.6/src/Python/3.7.6/Python/condvar.h:90
#2 take_gil (tstate=tstate
entry=0x453fab0) at /workspace/build/externals/Python-3.7.6/src/Python/3.7.6/Python/ceval_gil.h:208
#3 0x00007f3986cb735f in PyEval_RestoreThread (tstate=tstate
entry=0x453fab0) at /workspace/build/externals/Python-3.7.6/src/Python/3.7.6/Python/ceval.c:271
#4 0x00007f3986d3cbf2 in pysleep (secs=<optimized out>) at /workspace/build/externals/Python-3.7.6/src/Python/3.7.6/Modules/timemodule.c:1844
#5 time_sleep (self=<optimized out>, obj=<optimized out>) at /workspace/build/externals/Python-3.7.6/src/Python/3.7.6/Modules/timemodule.c:371
#6 0x00007f3986be1e30 in _PyMethodDef_RawFastCallKeywords (method=0x7f3987053c20 <time_methods+288>, self=<optimized out>, args=<optimized out>, nargs=1, kwnames=0x0) at /workspace/build/externals/Python-3.7.6/src/Python/3.7.6/Objects/call.c:648
#7 0x00007f3986be1f05 in _PyCFunction_FastCallKeywords (func=0x7f397eeb73c0, args=<optimized out>, nargs=<optimized out>, kwnames=<optimized out>) at /workspace/build/externals/Python-3.7.6/src/Python/3.7.6/Objects/call.c:734
#8 0x00007f3986bbebd8 in call_function (kwnames=0x0, oparg=<optimized out>, pp_stack=<synthetic pointer>) at /workspace/build/externals/Python-3.7.6/src/Python/3.7.6/Python/ceval.c:4568
#9 _PyEval_EvalFrameDefault (f=<optimized out>, throwflag=<optimized out>) at /workspace/build/externals/Python-3.7.6/src/Python/3.7.6/Python/ceval.c:3093
#10 0x00007f3986bb5beb in function_code_fastcall (co=co
entry=0x7f395cdfaae0, args=<optimized out>, args
entry=0x7f397336d6e8, nargs=nargs
entry=1, globals=globals
entry=0x7f395cb8a2d0) at /workspace/build/externals/Python-3.7.6/src/Python/3.7.6/Objects/call.c:283
#11 0x00007f3986be1872 in _PyFunction_FastCallDict (func=0x7f3973360cb0, args=0x7f397336d6e8, nargs=1, kwargs=0x7f39733645f0) at /workspace/build/externals/Python-3.7.6/src/Python/3.7.6/Objects/call.c:322
#12 0x00007f3986bb9b3f in do_call_core (kwdict=0x7f39733645f0, callargs=0x7f397336d6d0, func=0x7f3973360cb0) at /workspace/build/externals/Python-3.7.6/src/Python/3.7.6/Python/ceval.c:4645
#13 _PyEval_EvalFrameDefault (f=<optimized out>, throwflag=<optimized out>) at /workspace/build/externals/Python-3.7.6/src/Python/3.7.6/Python/ceval.c:3191
#14 0x00007f3986bb5beb in function_code_fastcall (co=<optimized out>, args=<optimized out>, nargs=1, globals=<optimized out>) at /workspace/build/externals/Python-3.7.6/src/Python/3.7.6/Objects/call.c:283
#15 0x00007f3986be1a37 in _PyFunction_FastCallKeywords (func=<optimized out>, stack=<optimized out>, nargs=<optimized out>, kwnames=<optimized out>) at /workspace/build/externals/Python-3.7.6/src/Python/3.7.6/Objects/call.c:415
#16 0x00007f3986bbe715 in call_function (kwnames=0x0, oparg=<optimized out>, pp_stack=<synthetic pointer>) at /workspace/build/externals/Python-3.7.6/src/Python/3.7.6/Python/ceval.c:4616
#17 _PyEval_EvalFrameDefault (f=<optimized out>, throwflag=<optimized out>) at /workspace/build/externals/Python-3.7.6/src/Python/3.7.6/Python/ceval.c:3110
#18 0x00007f3986bb5beb in function_code_fastcall (co=<optimized out>, args=<optimized out>, nargs=1, globals=<optimized out>) at /workspace/build/externals/Python-3.7.6/src/Python/3.7.6/Objects/call.c:283
#19 0x00007f3986be1a37 in _PyFunction_FastCallKeywords (func=<optimized out>, stack=<optimized out>, nargs=<optimized out>, kwnames=<optimized out>) at /workspace/build/externals/Python-3.7.6/src/Python/3.7.6/Objects/call.c:415
#20 0x00007f3986bbe715 in call_function (kwnames=0x0, oparg=<optimized out>, pp_stack=<synthetic pointer>) at /workspace/build/externals/Python-3.7.6/src/Python/3.7.6/Python/ceval.c:4616
#21 _PyEval_EvalFrameDefault (f=<optimized out>, throwflag=<optimized out>) at /workspace/build/externals/Python-3.7.6/src/Python/3.7.6/Python/ceval.c:3110
#22 0x00007f3986bb5beb in function_code_fastcall (co=co
entry=0x7f397eeae300, args=<optimized out>, args
entry=0x7f39675cde10, nargs=nargs
entry=1, globals=globals
entry=0x7f397f12a550) at /workspace/build/externals/Python-3.7.6/src/Python/3.7.6/Objects/call.c:283
#23 0x00007f3986be1872 in _PyFunction_FastCallDict (func=0x7f397eed27a0, args=0x7f39675cde10, nargs=1, kwargs=0x0) at /workspace/build/externals/Python-3.7.6/src/Python/3.7.6/Objects/call.c:322
#24 0x00007f3986be295d in _PyObject_Call_Prepend (callable=0x7f397eed27a0, obj=<optimized out>, args=0x7f398722d050, kwargs=0x0) at /workspace/build/externals/Python-3.7.6/src/Python/3.7.6/Objects/call.c:908
#25 0x00007f3986be3b65 in PyObject_Call (callable=0x7f3987142320, args=0x7f398722d050, kwargs=0x0) at /workspace/build/externals/Python-3.7.6/src/Python/3.7.6/Objects/call.c:245
#26 0x00007f3986d3e063 in t_bootstrap (boot_raw=boot_raw
entry=0x7f395cbbb8d0) at /workspace/build/externals/Python-3.7.6/src/Python/3.7.6/Modules/_threadmodule.c:994
#27 0x00007f3986cf2c17 in pythread_wrapper (arg=<optimized out>) at /workspace/build/externals/Python-3.7.6/src/Python/3.7.6/Python/thread_pthread.h:174
#28 0x00007f39866ffea5 in start_thread () from /lib64/libpthread.so.0
#29 0x00007f3985d1fb0d in clone () from /lib64/libc.so.6
Thread 1 (Thread 0x7f398726d740 (LWP 25052)):
#0 0x00007f3985ce6659 in waitpid () from /lib64/libc.so.6
#1 0x00007f3985c63f62 in do_system () from /lib64/libc.so.6
#2 0x00007f3985c64311 in system () from /lib64/libc.so.6
#3 0x00007f395aaff663 in TUnixSystem::StackTrace() () from /cvmfs/sft.cern.ch/lcg/views/LCG_97apython3/x86_64-centos7-gcc8-opt/lib/libCore.so
#4 0x00007f395ab01eb4 in TUnixSystem::DispatchSignals(ESignals) () from /cvmfs/sft.cern.ch/lcg/views/LCG_97apython3/x86_64-centos7-gcc8-opt/lib/libCore.so
#5 <signal handler called>
#6 0x00007f395a9f9ce3 in cling::printValue[abi:cxx11](TObject*) () from /cvmfs/sft.cern.ch/lcg/views/LCG_97apython3/x86_64-centos7-gcc8-opt/lib/libCore.so
#7 0x00007f3977d1b02b in ?? ()
#8 0x0000000000000000 in ?? ()
===========================================================
The lines below might hint at the cause of the crash.
You may get help by asking at the ROOT forum http://root.cern.ch/forum
Only if you are really convinced it is a bug in ROOT then please submit a
report at http://root.cern.ch/bugs Please post the ENTIRE stack trace
from above as an attachment in addition to anything else
that might help us fixing this issue.
===========================================================
#6 0x00007f395a9f9ce3 in cling::printValue[abi:cxx11](TObject*) () from /cvmfs/sft.cern.ch/lcg/views/LCG_97apython3/x86_64-centos7-gcc8-opt/lib/libCore.so
#7 0x00007f3977d1b02b in ?? ()
#8 0x0000000000000000 in ?? ()
===========================================================
Curious if this means I need to submit a source command like here: AFS phaseout | EP-SFT (?)
Anyway, looking at the particular root files that should be printing in this loop, I see these keys:
KEY: TCanvas NUM_LooseID_DEN_genTracks_abseta_1_pt_2_Canv;1 c
KEY: RooFitResult NUM_LooseID_DEN_genTracks_abseta_1_pt_2_resP;1 Result of fit of p.d.f. pdfPass to dataset hPass
KEY: TProcessID ProcessID0;1 8c609ae0-cc6e-11ec-b0d3-0f3d8e80beef
KEY: RooFitResult NUM_LooseID_DEN_genTracks_abseta_1_pt_2_resF;1 Result of fit of p.d.f. pdfFail to dataset hFail
KEY: TTree NUM_LooseID_DEN_genTracks_abseta_1_pt_2_statTests;1 statTests
KEY: TH1D NUM_LooseID_DEN_genTracks_abseta_1_pt_2_GenPass;1
KEY: TH1D NUM_LooseID_DEN_genTracks_abseta_1_pt_2_GenFail;1
KEY: TH1D NUM_LooseID_DEN_genTracks_abseta_1_pt_2_Pass;1
KEY: TH1D NUM_LooseID_DEN_genTracks_abseta_1_pt_2_Fail;1
I am attempting to save the TCanvas into a pdf format, but within ROOT, I usually do:
NUM_LooseID_DEN_genTracks_abseta_1_pt_2_Canv->Draw()
and take a screenshot. It’s a very long procedure. What’s the best way to go about retrieving these canvases that meet the criteria I’ve set, and then turn them into individual pdfs so I can dump these plots into my analysis? Root on LXplus for me is ROOT 6.20/06.
Any help would be much appreciated! Thanks so much!
Tay