Subject: CMSSW/Python won't write the root output file 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::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 a inaccessible huge root file: 3112960 -rw-r--r--. 1 lregisem zh 3187671040 Dec 13 15:00 data_55.root class PromptAnalyzer : public edm::one::EDAnalyzer { public: explicit PromptAnalyzer(const edm::ParameterSet&); ~PromptAnalyzer(); static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); private: virtual void beginJob() override; virtual void analyze(const edm::Event&, const edm::EventSetup&) override; virtual void endJob() override; virtual void beginRun(edm::Run const&, edm::EventSetup const&); virtual void endRun(edm::Run const&, edm::EventSetup const&); bool jsonLocal(int r, int ls); // ----------member data --------------------------- edm::EDGetTokenT trkToken_; edm::EDGetTokenT > RPtrkToken_; edm::EDGetTokenT vtxToken_; edm::EDGetTokenT beamspotToken_; edm::EDGetTokenT trigToken_; HLTConfigProvider hltConfig_; map histosTH1F; map histosTH2F; }; // constructor PromptAnalyzer::PromptAnalyzer(const edm::ParameterSet& iConfig) : trkToken_(consumes(iConfig.getParameter("tracks"))) ,RPtrkToken_(consumes >(iConfig.getParameter("RPtracks"))) ,vtxToken_(consumes(iConfig.getParameter("vertices"))) ,beamspotToken_(consumes(iConfig.getParameter("beamspot"))) ,trigToken_(consumes(iConfig.getParameter("triggers"))) { } // ------------ method called for each event ------------ void PromptAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) { // using namespace edm; edm::Handle tracks; edm::Handle > RPtracks; edm::Handle vertices; edm::Handle beamspot; edm::Handle triggers; iEvent.getByToken(trkToken_,tracks); iEvent.getByToken(RPtrkToken_,RPtracks); iEvent.getByToken(vtxToken_,vertices); iEvent.getByToken(beamspotToken_,beamspot); iEvent.getByToken(trigToken_,triggers); ... for(TrackCollection::const_iterator itTrack = tracks->begin();itTrack != tracks->end();++itTrack) { ... double pt = itTrack->pt(); double pz = itTrack->pz(); double eta = itTrack->eta(); double phi = itTrack->phi(); int charge = itTrack->charge(); histosTH1F["hpt"]->Fill(pt); ... totcharge += charge; // pions double ene=TMath::Sqrt(pt*pt+pz*pz+m_pi*m_pi); TLorentzVector trk_lorentz(itTrack->px(),itTrack->py(),itTrack->pz(),ene); // 4trk pi4Rec += trk_lorentz; if(charge>0){ if(ntrk4pos==0) pi4pos1 = trk_lorentz; if(ntrk4pos==1) pi4pos2 = trk_lorentz; ntrk4pos++; } } //end tracks double mrec4=pi4Rec.M(); histosTH1F["hm4"]->Fill(mrec4); } //end analyze // ------------ method called once each job just before starting event loop ------------ void PromptAnalyzer::beginJob() { histosTH1F["hpt"] = new TH1F("hpt","p_{T}",100,0,5); histosTH1F["hm4"] = new TH1F("hm4", "M_{#pi^{+}#pi^{+}#pi^{-}#pi^{-}} (GeV)",1000,0.,10.); //--------------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::iterator it_histo = histosTH1F.begin();it_histo != histosTH1F.end(); ++it_histo)(*it_histo).second->Write(); for(map::iterator it_histo = histosTH2F.begin();it_histo != histosTH2F.end(); ++it_histo)(*it_histo).second->Write(); output->Close(); } Here is my python file: import FWCore.ParameterSet.Config as cms from Configuration.StandardSequences.Eras import eras process = cms.Process("Demo",eras.Run2_2018_highBetaStar) process.load('Configuration.StandardSequences.Services_cff') process.load('FWCore.MessageService.MessageLogger_cfi') process.MessageLogger.cerr.FwkReport.reportEvery = 1000 process.load('Configuration.EventContent.EventContent_cff') process.load('Configuration.StandardSequences.GeometryRecoDB_cff') process.load('Configuration.StandardSequences.MagneticField_AutoFromDBCurrent_cff') process.load('Configuration.StandardSequences.RawToDigi_Data_cff') process.load('Configuration.StandardSequences.Reconstruction_Data_cff') process.load('Configuration.StandardSequences.FrontierConditions_GlobalTag_cff') from Configuration.AlCa.GlobalTag import GlobalTag process.GlobalTag.globaltag = "101X_dataRun2_Prompt_v11" process.maxEvents = cms.untracked.PSet( input = cms.untracked.int32(-1) ) process.source = cms.Source("PoolSource", fileNames = cms.untracked.vstring(XXX) ) process.demo = cms.EDAnalyzer('PromptAnalyzer' ,tracks = cms.InputTag('generalTracks') ,dedxs = cms.InputTag('dedxHarmonic2') ,dedxPIXs = cms.InputTag('dedxPixelHarmonic2') ,dedxpixels = cms.InputTag('dedxHitInfo') ,RPtracks = cms.InputTag('ctppsLocalTrackLiteProducer') ,vertices = cms.InputTag('offlinePrimaryVertices') ,beamspot = cms.InputTag('offlineBeamSpot') ,triggers = cms.InputTag('TriggerResults','','HLT') ,pflows = cms.InputTag('particleFlow') ,muons = cms.InputTag('muons') ) process.out = cms.OutputModule("PoolOutputModule", fileName = cms.untracked.string("data_55.root") ) process.Tracer = cms.Service("Tracer") process.p = cms.Path( process.demo ) process.ep = cms.EndPath(process.out) process.schedule = cms.Schedule(process.p,process.ep) What is the right method of writing histograms into a file? 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 correct? void PromptAnalyzer::endJob() { // Output file TFile* output = new TFile("output.root","RECREATE"); output->cd(); for(map::iterator it_histo = histosTH1F.begin();it_histo != histosTH1F.end(); ++it_histo)(*it_histo).second->Write(); for(map::iterator it_histo = histosTH2F.begin();it_histo != histosTH2F.end(); ++it_histo)(*it_histo).second->Write(); output->Close(); } Would you please give me a guiding light? I appreciate, Luiz