Skip to content

Commit

Permalink
Separate paths for data and MC in NtuplizeHgcrocDigiCollection
Browse files Browse the repository at this point in the history
  • Loading branch information
Skelpdar committed Oct 29, 2024
1 parent 96f6980 commit a93e484
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 51 deletions.
30 changes: 18 additions & 12 deletions DQM/python/dqm.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,23 +391,29 @@ def __init__(self, input_name) :

class NtuplizeHgcrocDigiCollection(ldmxcfg.Analyzer) :
def __init__(self,input_name, pedestal_table = None, input_pass = '',
using_eid = None, already_aligned = False,
using_eid = None, already_aligned = False, is_simulation = False,
name = 'ntuplizehgcroc') :
super().__init__(name,'dqm::NtuplizeHgcrocDigiCollection','DQM')
self.input_name = input_name
self.input_pass = input_pass

if using_eid is None :
# deduce if using eid based on presence of HcalDetectorMap in conditions system
from LDMX.Framework import ldmxcfg
from LDMX.Hcal.DetectorMap import HcalDetectorMap
using_eid = True
for cop in ldmxcfg.Process.lastProcess.conditionsObjectProviders :
if isinstance(cop,HcalDetectorMap) :
using_eid = False
break
self.using_eid = using_eid
self.already_aligned = already_aligned
self.is_simulation = is_simulation

if is_simulation:
self.using_eid = False
self.already_aligned = True
else:
if using_eid is None :
# deduce if using eid based on presence of HcalDetectorMap in conditions system
from LDMX.Framework import ldmxcfg
from LDMX.Hcal.DetectorMap import HcalDetectorMap
using_eid = True
for cop in ldmxcfg.Process.lastProcess.conditionsObjectProviders :
if isinstance(cop,HcalDetectorMap) :
using_eid = False
break
self.using_eid = using_eid
self.already_aligned = already_aligned

from LDMX.Conditions.SimpleCSVTableProvider import SimpleCSVIntegerTableProvider
if pedestal_table is None :
Expand Down
117 changes: 78 additions & 39 deletions DQM/src/DQM/NtuplizeHgcrocDigiCollection.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class NtuplizeHgcrocDigiCollection : public framework::Analyzer {
int fpga_, link_, channel_, index_;
int section_, layer_, strip_, end_;
bool tot_prog_, tot_comp_, aligned_;
bool using_eid_, already_aligned_;
bool using_eid_, already_aligned_, is_simulation_;
bool good_link_;
TTree* flat_tree_;

Expand All @@ -30,6 +30,7 @@ class NtuplizeHgcrocDigiCollection : public framework::Analyzer {
pedestal_table_ = ps.getParameter<std::string>("pedestal_table");
using_eid_ = ps.getParameter<bool>("using_eid");
already_aligned_ = ps.getParameter<bool>("already_aligned");
is_simulation_ = ps.getParameter<bool>("is_simulation");
}

void onProcessStart() final override {
Expand All @@ -45,7 +46,7 @@ class NtuplizeHgcrocDigiCollection : public framework::Analyzer {
flat_tree_->Branch("raw_adc", &raw_adc_);
flat_tree_->Branch("i_sample", &i_sample_);
flat_tree_->Branch("ldmxsw_event", &ldmxsw_event_);
if (not already_aligned_) {
if (not already_aligned_ || is_simulation_ ) {
flat_tree_->Branch("pf_event", &pf_event_);
flat_tree_->Branch("pf_spill", &pf_spill_);
flat_tree_->Branch("pf_ticks", &pf_ticks_);
Expand Down Expand Up @@ -77,53 +78,91 @@ void NtuplizeHgcrocDigiCollection::analyze(const framework::Event& event) {
hcal::HcalDetectorMap::CONDITIONS_OBJECT_NAME)};

ldmxsw_event_ = event.getEventNumber();
if (already_aligned_) {
aligned_ = event.getObject<bool>(input_name_ + "Aligned", input_pass_);
} else {
aligned_ = false;
version_ = event.getObject<int>(input_name_ + "Version", input_pass_);
pf_event_ = event.getObject<int>(input_name_ + "Number", input_pass_);
pf_ticks_ = event.getObject<int>(input_name_ + "Ticks", input_pass_);
pf_spill_ = event.getObject<int>(input_name_ + "Spill", input_pass_);
if(not is_simulation_){
if (already_aligned_) {
aligned_ = event.getObject<bool>(input_name_ + "Aligned", input_pass_);
} else {
aligned_ = false;
version_ = event.getObject<int>(input_name_ + "Version", input_pass_);
pf_event_ = event.getObject<int>(input_name_ + "Number", input_pass_);
pf_ticks_ = event.getObject<int>(input_name_ + "Ticks", input_pass_);
pf_spill_ = event.getObject<int>(input_name_ + "Spill", input_pass_);
}
}
else{
aligned_ = true;
version_ = 0;
pf_event_ = ldmxsw_event_;
pf_ticks_ = 0;
pf_spill_ = 0;
}

const auto& good_bxheader{
event.getCollection<bool>(input_name_ + "GoodLinkHeader", input_pass_)};
const auto& good_trailer{
event.getCollection<bool>(input_name_ + "GoodLinkTrailer", input_pass_)};
if(not is_simulation_){
const auto& good_bxheader{
event.getCollection<bool>(input_name_ + "GoodLinkHeader", input_pass_)};
const auto& good_trailer{
event.getCollection<bool>(input_name_ + "GoodLinkTrailer", input_pass_)};

auto const& digis{
event.getObject<ldmx::HgcrocDigiCollection>(input_name_, input_pass_)};
for (std::size_t i_digi{0}; i_digi < digis.size(); i_digi++) {
auto d{digis.getDigi(i_digi)};
raw_id_ = static_cast<int>(d.id());
if (using_eid_) {
ldmx::HcalElectronicsID eid(d.id());
fpga_ = eid.fiber();
link_ = eid.elink();
good_link_ = (good_bxheader.at(link_) and good_trailer.at(link_));
channel_ = eid.channel();
index_ = eid.index();
} else {
auto const& digis{
event.getObject<ldmx::HgcrocDigiCollection>(input_name_, input_pass_)};
for (std::size_t i_digi{0}; i_digi < digis.size(); i_digi++) {
auto d{digis.getDigi(i_digi)};
raw_id_ = static_cast<int>(d.id());
if (using_eid_ ) {
ldmx::HcalElectronicsID eid(d.id());
fpga_ = eid.fiber();
link_ = eid.elink();
good_link_ = (good_bxheader.at(link_) and good_trailer.at(link_));
channel_ = eid.channel();
index_ = eid.index();
} else {
ldmx::HcalDigiID detid(d.id());
ldmx::HcalElectronicsID eid = detmap.get(detid);
int link = eid.elink();
good_link_ = (good_bxheader.at(link) and good_trailer.at(link));
section_ = detid.section();
layer_ = detid.layer();
strip_ = detid.strip();
end_ = detid.end();
}

for (i_sample_ = 0; i_sample_ < digis.getNumSamplesPerDigi(); i_sample_++) {
tot_prog_ = d.at(i_sample_).isTOTinProgress();
tot_comp_ = d.at(i_sample_).isTOTComplete();
tot_ = d.at(i_sample_).tot();
toa_ = d.at(i_sample_).toa();
int adc_t = d.at(i_sample_).adc_t();
raw_adc_ = adc_t;
adc_ = adc_t - pedestal_table.get(d.id(), 0);
flat_tree_->Fill();
}
}
}
//For simulated digis
else{
auto const& digis{
event.getObject<ldmx::HgcrocDigiCollection>(input_name_, input_pass_)};
for (std::size_t i_digi{0}; i_digi < digis.size(); i_digi++) {
auto d{digis.getDigi(i_digi)};
raw_id_ = static_cast<int>(d.id());
ldmx::HcalDigiID detid(d.id());
ldmx::HcalElectronicsID eid = detmap.get(detid);
int link = eid.elink();
good_link_ = (good_bxheader.at(link) and good_trailer.at(link));
good_link_ = true;
section_ = detid.section();
layer_ = detid.layer();
strip_ = detid.strip();
end_ = detid.end();
}

for (i_sample_ = 0; i_sample_ < digis.getNumSamplesPerDigi(); i_sample_++) {
tot_prog_ = d.at(i_sample_).isTOTinProgress();
tot_comp_ = d.at(i_sample_).isTOTComplete();
tot_ = d.at(i_sample_).tot();
toa_ = d.at(i_sample_).toa();
int adc_t = d.at(i_sample_).adc_t();
raw_adc_ = adc_t;
adc_ = adc_t - pedestal_table.get(d.id(), 0);
flat_tree_->Fill();
for (i_sample_ = 0; i_sample_ < digis.getNumSamplesPerDigi(); i_sample_++) {
tot_prog_ = d.at(i_sample_).isTOTinProgress();
tot_comp_ = d.at(i_sample_).isTOTComplete();
tot_ = d.at(i_sample_).tot();
toa_ = d.at(i_sample_).toa();
int adc_t = d.at(i_sample_).adc_t();
raw_adc_ = adc_t;
adc_ = adc_t - pedestal_table.get(d.id(), 0);
flat_tree_->Fill();
}
}
}
}
Expand Down

0 comments on commit a93e484

Please sign in to comment.