Skip to content

Commit

Permalink
Sample scripts for validating future samples
Browse files Browse the repository at this point in the history
  • Loading branch information
Horoho committed Oct 5, 2023
1 parent 0476ccc commit e45118a
Show file tree
Hide file tree
Showing 3 changed files with 154 additions and 0 deletions.
38 changes: 38 additions & 0 deletions DQM/include/DQM/SampleValidation.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#ifndef DQM_SAMPLEVALIDATION_H
#define DQM_SAMPLEVALIDATION_H

//LDMX Framework
#include "Framework/Configure/Parameters.h"
#include "Framework/EventProcessor.h"

namespace dqm {

/**
* @class SampleValidation
* @brief
*/

class SampleValidation : public framework::Analyzer {
public:

SampleValidation(const std::string& name, framework::Process& process) : Analyzer(name, process) {}

virtual void configure(framework::config::Parameters& ps);

virtual void analyze(const framework::Event& event);

virtual void onFileOpen(framework::EventFile&);

virtual void onFileClose(framework::EventFile&);

virtual void onProcessStart();

virtual void onProcessEnd();

private:

};

}

#endif
19 changes: 19 additions & 0 deletions DQM/python/dqm.py
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,25 @@ def __init__(self,name='Trigger',coll='Trigger') :
self.trigger_name = coll
self.trigger_pass = ''


class SampleValidation(ldmxcfg.Analyzer) :
def __init__(self, name='SampleValidation') :
super().__init__(name, 'dqm::SampleValidation', 'DQM')

# primary histograms
self.build1DHistogram("pdgid_primaries", "PDG ID of primary particles", 2714, -500, 2213)
self.build1DHistogram("energy_primaries", "Energy of primary particles", 50, 0, 5000) # range applicable for 4 GeV beam
self.build2DHistogram("beam_smear", "x", 30, -150, 150, "y", 30, -150, 150)

# primary daughter of interest (brem / dark brem) histograms
self.build1DHistogram("pdgid_primarydaughters", "PDG ID of primary daughters", 2714, -500, 2213)
self.build1DHistogram("startZ_hardbrem", "Start z position of hard primary daughter", 100, -500, 500)
self.build1DHistogram("endZ_hardbrem", "End z position of hard primary daughter", 100, -500, 500)
self.build1DHistogram("energy_hardbrem", "Energy spectrum of hard primary daughter", 50, 2000, 4500)

# daughters of hard brem histograms
self.build1DHistogram("pdgid_hardbremdaughters", "PDG ID of hard brem daughters", 2714, -500, 2213)
self.build1DHistogram("startZ_hardbremdaughters", "Start z position of hard brem daughters", 200, -1000, 1000)


ecal_dqm = [
Expand Down
97 changes: 97 additions & 0 deletions DQM/src/DQM/SampleValidation.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
#include "DQM/SampleValidation.h"
#include "SimCore/Event/SimParticle.h"
#include "Framework/NtupleManager.h"
#include <iostream>
#include <fstream>
#include <algorithm>

namespace dqm {

void SampleValidation::configure(framework::config::Parameters& ps) {

return;
}

void SampleValidation::analyze(const framework::Event& event) {

//Grab the SimParticle Map
auto particle_map{event.getMap<int, ldmx::SimParticle>("SimParticles")};

std::vector<int> primary_daughters;

//Loop over all SimParticles
for (auto const& it : particle_map) {
ldmx::SimParticle p = it.second;
int pdgid = p.getPdgID();
std::vector<double> vertex = p.getVertex();
double energy = p.getEnergy();
std::vector<int> parents_track_ids = p.getParents();
std::vector<int> daughters = p.getDaughters();

for (auto const& parent_track_id: parents_track_ids) {
if (parent_track_id == 0) {
histograms_.fill("beam_smear", vertex[0], vertex[1]);
histograms_.fill("pdgid_primaries", pdgid);
histograms_.fill("energy_primaries", energy);
primary_daughters = daughters;
}
}
}

std::vector<std::vector<int>> hardbrem_daughters;

for (auto const& it : particle_map) {
int trackid = it.first;
ldmx::SimParticle p = it.second;
for (auto const& primary_daughter : primary_daughters) {
if (trackid == primary_daughter) {
histograms_.fill("pdgid_primarydaughters", p.getPdgID());
if (p.getEnergy() >= 2500) {
histograms_.fill("startZ_hardbrem", p.getVertex()[2]);
histograms_.fill("endZ_hardbrem", p.getEndPoint()[2]);
histograms_.fill("energy_hardbrem", p.getEnergy());
hardbrem_daughters.push_back(p.getDaughters());
}
}
}
}

for (auto const& it : particle_map) {
int trackid = it.first;
ldmx::SimParticle p = it.second;
for (const std::vector<int> &daughter_track_id : hardbrem_daughters){
for (const int &daughter_id : daughter_track_id) {
if (trackid == daughter_id) {
histograms_.fill("pdgid_hardbremdaughters", p.getPdgID());
histograms_.fill("startZ_hardbremdaughters", p.getVertex()[2]);
}
}
}
}


return;
}

void SampleValidation::onFileOpen(framework::EventFile&) {

return;
}

void SampleValidation::onFileClose(framework::EventFile&) {

return;
}

void SampleValidation::onProcessStart() {

return;
}

void SampleValidation::onProcessEnd() {

return;
}
}

DECLARE_ANALYZER_NS(dqm, SampleValidation)

0 comments on commit e45118a

Please sign in to comment.