Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:18:31

0001 
0002 //
0003 // Template for this file generated with eicmkplugin.py
0004 // Author: Nilanga Wickramaarachchi
0005 //
0006 
0007 #include "hpDIRCsimHitsProcessor.h"
0008 #include "services/rootfile/RootFile_service.h"
0009 
0010 // Include appropriate class headers. e.g.
0011 #include <edm4hep/SimCalorimeterHitCollection.h>
0012 
0013 // The following just makes this a JANA plugin
0014 extern "C" {
0015     void InitPlugin(JApplication *app) {
0016         InitJANAPlugin(app);
0017         app->Add(new hpDIRCsimHitsProcessor);
0018     }
0019 }
0020 
0021 //-------------------------------------------
0022 // InitWithGlobalRootLock
0023 //-------------------------------------------
0024 void hpDIRCsimHitsProcessor::InitWithGlobalRootLock(){
0025     auto rootfile_svc = GetApplication()->GetService<RootFile_service>();
0026     auto rootfile = rootfile_svc->GetHistFile();
0027     rootfile->mkdir("hpDIRCsimHits")->cd();
0028 
0029     // Create histograms here. e.g.
0030     // hEraw  = new TH1D("Eraw",  "BEMC hit energy (raw)",  100, 0, 0.075);
0031     // hEdigi = new TH2D("Edigi", "BEMC hit energy (digi) vs. raw", 200, 0, 2000.0, 100, 0, 0.075);
0032     hHitposition_direct = new TH2D("Hitposition_direct", "hit position Y vs. hit position X; hit position x (mm); hit position y (mm)", 130, 600, 990, 130, -190, 200);
0033     hnhits = new TH1D("nhits","; no. of hits per event", 400, 0, 2000);
0034     htime = new TH1D("leadtime","; photon time (ns)", 2000, 0, 100);
0035     hwavelength = new TH1D("wavelength","; wavelength of photon (nm)", 500, 0, 1000);
0036     hist_parent_pdg = new TH1I("parent_pdg","; parent PDG", 10000, -5000, 5000);
0037 }
0038 
0039 //-------------------------------------------
0040 // ProcessSequential
0041 //-------------------------------------------
0042 void hpDIRCsimHitsProcessor::ProcessSequential(const std::shared_ptr<const JEvent>& event) {
0043     // Data objects we will need from JANA e.g.
0044   //const auto &rawhits = *static_cast<const edm4hep::SimCalorimeterHitCollection*>(event->GetCollectionBase("EcalBarrelScFiHits"));
0045 
0046     // Fill histograms here. e.g.
0047     // for (auto hit : rawhits) hEraw->Fill(hit.getEnergy());
0048 
0049   Int_t count = 0;
0050 
0051   for(auto hit : simhits())
0052     {
0053       int parent_pdg = hit->getMCParticle().getParents(0).getPDG();
0054       bool is_from_primary_track = hit->getMCParticle().getParents(0).getGeneratorStatus();
0055       
0056       if(!is_from_primary_track) continue;
0057       hist_parent_pdg->Fill(parent_pdg);
0058       
0059       hHitposition_direct->Fill(hit->getPosition()[0], hit->getPosition()[1]);
0060       count = count+1;
0061 
0062       // wavelength calculation
0063       double hit_energy = hit->getEDep() * 1e9; // convert to eV
0064       double wavelength = (1.2398 / hit_energy) * 1000;
0065       hwavelength->Fill(wavelength);
0066 
0067       // photon time
0068       double leadtime = hit->getTime(); // in ns
0069       htime->Fill(leadtime);
0070       
0071     }
0072   hnhits->Fill(count);
0073 }
0074 
0075 //-------------------------------------------
0076 // FinishWithGlobalRootLock
0077 //-------------------------------------------
0078 void hpDIRCsimHitsProcessor::FinishWithGlobalRootLock() {
0079 
0080     // Do any final calculations here.
0081 }
0082