Hi,
I am trying to understand why CMSSW/python does not write the root output file onto the disk after processing the analyzer/job.
If I use the method:
TFile* output = new TFile(“output.root”,“RECREATE”);
output->cd();
for(map<string,TH1F*>::iterator it_histo = histosTH1F.begin();it_histo != histosTH1F.end(); ++it_histo)(*it_histo).second->Write();
output->Close();
it gives segmentation violation, no output.
If I use:
process.out = cms.OutputModule(“PoolOutputModule”,
fileName = cms.untracked.string(“data_55.root”)
)
process.ep = cms.EndPath(process.out)
it gives an inaccessible huge root file:
3112960 -rw-r–r--. 1 lregisem zh 3187671040 Dec 13 15:00 data_55.root
Here is an excerpt of the code:
// ----------member data ---------------------------
…
map<string,TH1F*> histosTH1F;
map<string,TH2F*> histosTH2F;
…
// ------------ method called for each event ------------
void PromptAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
{
// using namespace edm;
edm::Handle tracks;
…
double pt = itTrack->pt();
histosTH1F[“hpt”]->Fill(pt);
…
}
// ------------ method called once each job just before starting event loop ------------
void PromptAnalyzer::beginJob()
{
histosTH1F[“hpt”] = new TH1F(“hpt”,“p_{T}”,100,0,5);
//--------------end of my histograms
}
// ------------ method called once each job just after ending the event loop ------------
void PromptAnalyzer::endJob()
{
// Output file
TFile* output = new TFile(“output.root”,“RECREATE”);
output->cd();
for(map<string,TH1F*>::iterator it_histo = histosTH1F.begin();it_histo != histosTH1F.end(); ++it_histo)(it_histo).second->Write();
for(map<string,TH2F>::iterator it_histo = histosTH2F.begin();it_histo != histosTH2F.end(); ++it_histo)(*it_histo).second->Write();
output->Close();
}
What is the right method of writing histograms into a file when using CMSSW/python?
histosTH1F[“hpt”] = new TH1F(“hpt”,“p_{T}”,100,0,5);
histosTH1F[“hm4”] = new TH1F(“hm4”, "M_{#pi^{+}#pi^{+}#pi^{-}#pi^{-}}
histosTH1F[“hpt”]->Fill(pt);
histosTH1F[“hm4”]->Fill(mrec4);
Is this ROOT method below valid with Python modules?
void PromptAnalyzer::endJob()
{
// Output file
TFile* output = new TFile(“output.root”,“RECREATE”);
output->cd();
for(map<string,TH1F*>::iterator it_histo = histosTH1F.begin();it_histo != histosTH1F.end(); ++it_histo)(it_histo).second->Write();
for(map<string,TH2F>::iterator it_histo = histosTH2F.begin();it_histo != histosTH2F.end(); ++it_histo)(*it_histo).second->Write();
output->Close();
}
Would you please advise?
I appreciate,
Luiz
ps: detailed information of the code and python config file is in the attachment.
Please read tips for efficient and successful posting and posting code
ROOT Version: 6.14/09
Platform: LXPLUS7
Compiler: gcc (GCC) 8.3.1 20190225
___output-please.txt (7.1 KB)