Skip to content
Snippets Groups Projects
emcal_electrons_reader.cxx 1.59 KiB
Newer Older
  • Learn to ignore specific revisions
  • //////////////////////////
    // Crystal EMCAL detector 
    // Electron dataset
    // J.KIM 07/20/2020
    //////////////////////////
    #include "HepMC3/GenEvent.h"
    #include "HepMC3/ReaderAscii.h"
    #include "HepMC3/WriterAscii.h"
    #include "HepMC3/Print.h"
    
    #include "TH1F.h"
    #include <iostream>
    using namespace HepMC3;
    
    void emcal_electrons_reader(){
    
    	ReaderAscii hepmc_input("./data/emcal_electrons.hepmc");
    	int        events_parsed = 0;
    	GenEvent   evt(Units::GEV, Units::MM);
    
    	// Histograms
    	TH1F* h_electrons_energy = new TH1F("electron energy","; E [GeV]",100,0,40);
    	TH1F* h_electrons_eta    = new TH1F("electron #eta","; #eta",20,-10,0);
    
    	while(!hepmc_input.failed()) {
    		// Read event from input file
    		hepmc_input.read_event(evt);
    		// If reading failed - exit loop
        		if( hepmc_input.failed() ) break;
    
        		for(const auto& v : evt.vertices() ) {
          			for(const auto& p : v->particles_out() ) {
            			if(p->pid() == 11) {
              			h_electrons_energy->Fill(p->momentum().e()); // Energy component of momentum
    				h_electrons_eta->Fill(p->momentum().eta());  // Pseudorapidity
            			}
          			}
        		}
        		evt.clear();
        		events_parsed++;
      	}
      	std::cout << "Events parsed and written: " << events_parsed << std::endl;
    
      	TCanvas* c = new TCanvas();
      	h_electrons_energy->Draw();
      	c->SaveAs("results/emcal_electrons_energy_reader.png");
      	c->SaveAs("results/emcal_electrons_energy_reader.pdf");
    
            TCanvas* c1 = new TCanvas();
            h_electrons_eta->Draw();
            c1->SaveAs("results/emcal_electrons_eta_reader.png");
            c1->SaveAs("results/emcal_electrons_eta_reader.pdf");
    
    }