jpata / tthbb13

2 stars 5 forks source link

speed up ttH code #92

Open jpata opened 8 years ago

jpata commented 8 years ago

the tthbb13 code has gotten really slow, processing only around 1.5 ev/s even without the MEM.

I ran the profiles, here are some of the worst offenders.

     5000    0.430    0.000  131.720    0.026 JetAnalyzer.py:37(variateJets)
     1000    0.180    0.000  336.690    0.337 JetAnalyzer.py:70(process)
     1000    0.810    0.001  203.060    0.203 vhbb_utils.py:54(__init__)
     1000    0.600    0.001  219.230    0.219 VHbbTree.py:2120(process)
1154532/864377   12.990    0.000  361.370    0.000 copy.py:283(_deepcopy_inst)

VHbbTree.py could be sped up with using a buffer (like rootpy TreeBuffer) that doesn't reread the branch every time you do tree.leps_pt[n].

JetAnalyzer.py is slow because there we copy the jets, we could perhaps instead make a shallow copy and change only the p4. Additionally, it's slow because there we deepcopy the Event to a FakeEvent, which is variated.

jpata commented 8 years ago

Need to get rid of deepcopy: https://github.com/jpata/tthbb13/blob/meanalysis-80x-V24/MEAnalysis/python/vhbb_utils.py#L55 https://github.com/jpata/tthbb13/blob/meanalysis-80x-V24/MEAnalysis/python/JetAnalyzer.py#L38 but causes ntuplization crash with

AttributeError: 'Event' object has no attribute 'mem_tth_SL_0w2h2t_nominal'

Need to disentangle why this collection does not get produced in MEMAnalyzer in case of shallow copy.

d-salerno commented 8 years ago

Hi Joosep, What were the timing of these modules in 76x? What would have caused them to go slower?

jpata commented 8 years ago

I don't think it's 76X vs 80X, it's just that we've not been paying close attention to runtime speed (preferring ease of development), and now it's rather slow as a result. When running with MEM, it's not so relevant, because the MEM itself is quite a bit slower. I think now it's time to step back for a moment and re-optimize these slower parts, like the treatment of the systematics. For example, we don't need to copy the whole event (or whole jet), just a few branches.

jpata commented 8 years ago

Another thing is that we keep adding new branches to objects (like Jet), each of which brings the speed of de-ntuplization in VHbbTree.py down faster than linear due to not caching the TTree accessors (like I do in #98).