KIT-CMS / CROWN

C++ based ROOT Workflow for N-tuples (CROWN)
https://crown.readthedocs.io
MIT License
4 stars 21 forks source link

[BUG] No "ntuple" tree in ntuples if 0 events selected #268

Closed nshadskiy closed 2 weeks ago

nshadskiy commented 3 months ago

It might happen that no events are selected during ntupling. e.g. here for a data nanoAOD

[2024-05-25 13:25:33.386]   Starting Evaluation                                                                   CROWNRun.py:187
[13:25:52] [2024-05-25 13:25:52.076]   10000 / 56973 (17.55 %) Events processed ...                                          CROWNRun.py:187
         [2024-05-25 13:25:52.123]   et:                                                                                   CROWNRun.py:187
           GoldenJSONFilter: pass=0          all=56973      -- eff=0.00 % cumulative eff=0.00 %                              CROWNRun.py:187
           Flag_goodVertices: pass=0          all=0          -- eff=-nan % cumulative eff=0.00 %                             CROWNRun.py:187
           Flag_globalSuperTightHalo2016Filter: pass=0          all=0          -- eff=-nan % cumulative eff=0.00 %           CROWNRun.py:187
           Flag_HBHENoiseFilter: pass=0          all=0          -- eff=-nan % cumulative eff=0.00 %                          CROWNRun.py:187
           Flag_HBHENoiseIsoFilter: pass=0          all=0          -- eff=-nan % cumulative eff=0.00 %                       CROWNRun.py:187
           Flag_EcalDeadCellTriggerPrimitiveFilter: pass=0          all=0          -- eff=-nan % cumulative eff=0.00 %       CROWNRun.py:187
           Flag_BadPFMuonFilter: pass=0          all=0          -- eff=-nan % cumulative eff=0.00 %                          CROWNRun.py:187
           Flag_eeBadScFilter: pass=0          all=0          -- eff=-nan % cumulative eff=0.00 %                            CROWNRun.py:187
           Flag_ecalBadCalibFilter: pass=0          all=0          -- eff=-nan % cumulative eff=0.00 %                       CROWNRun.py:187
           GoodElTauPairs: pass=0          all=0          -- eff=-nan % cumulative eff=0.00 %                                CROWNRun.py:187

The output ntuple is still saved with all the information but since no events are selected no "ntuple" tree is saved. e.g.

root [1] .ls
TNetXNGFile**       root://cmsdcache-kit-disk.gridka.de//store/user/nshadskiy/CROWN/ntuples/nmssm_all_systs_05_2024_v2/CROWNRun/2018/SingleMuon_Run2018B-UL2018_GT36/et/SingleMuon_Run2018B-UL2018_GT36_0.root  SingleMuon_Run2018B-UL2018_GT36_0_et.root
 TNetXNGFile*       root://cmsdcache-kit-disk.gridka.de//store/user/nshadskiy/CROWN/ntuples/nmssm_all_systs_05_2024_v2/CROWNRun/2018/SingleMuon_Run2018B-UL2018_GT36/et/SingleMuon_Run2018B-UL2018_GT36_0.root  SingleMuon_Run2018B-UL2018_GT36_0_et.root
  KEY: TTree    quantities;1    quantities
  KEY: TTree    variations;1    variations
  KEY: TTree    conditions;1    conditions
  KEY: TTree    commit;1    commit
  KEY: TTree    analysis_commit;1   analysis_commit
  KEY: TH1D cutflow;1   cutflow
  KEY: map<string,vector<string> >  shift_quantities_map;1  object title
  KEY: map<string,vector<string> >  quantities_shift_map;1  object title

If now a friend should be generated the code is checking if the "ntuple" tree is present: https://github.com/KIT-CMS/CROWN/blob/78bd17644e7ab0ecbde54cf4d1f45c67ca076a9a/code_generation/analysis_template_friends.cxx#L45-L65 If this is not the case a error is thrown and no friend tree file is generated.

Maybe this could be handled by introducing a check for the last bin of the cutflow additionally to the check of the "ntuple" tree.

harrypuuter commented 3 months ago

I propose ths following solution:

  1. adapt the return codes here (https://github.com/KIT-CMS/CROWN/blob/78bd17644e7ab0ecbde54cf4d1f45c67ca076a9a/code_generation/analysis_template_friends.cxx#L117) and here (https://github.com/KIT-CMS/CROWN/blob/78bd17644e7ab0ecbde54cf4d1f45c67ca076a9a/code_generation/analysis_template_friends.cxx#L110) to some special value (e.g. 55)

  2. Catch this return code in Kingmaker to treat CROWN executables with this return code in a special way, so the jobs to not fail, and its okay that they do not produce any output (or produce some dummy output for the TChain)

harrypuuter commented 1 month ago

@ralfschmieder was working on a solution to this if i remember correctly ?

nshadskiy commented 2 weeks ago

resolved in https://github.com/KIT-CMS/CROWN/pull/281