CRTSimValidation_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: CRTSimValidation
3 // Plugin Type: analyzer (art v2_11_02)
4 // File: CRTSimValidation_module.cc
5 //
6 // Generated at Thu Jul 26 11:49:48 2018 by Andrew Olivier using cetskelgen
7 // from cetlib version v3_03_01.
8 ////////////////////////////////////////////////////////////////////////
9 
10 //Framework includes
18 #include "fhiclcpp/ParameterSet.h"
21 #include "canvas/Persistency/Common/FindManyP.h"
22 #include "art_root_io/TFileService.h"
23 
24 //LArSoft includes
27 
28 //Local includes
30 
31 //ROOT includes
32 #include "TH1D.h"
33 
34 //c++ includes
35 #include <numeric> //std::accumulate was moved from <algorithm> to <numeric> in c++14
36 
37 namespace CRT {
38  class CRTSimValidation;
39 }
40 
41 //Take advantage of "backwards associations" between CRT::Trigger and
42 //sim::AuxDetSimChannel to make sure that CRTSim_module is behaving in
43 //a believable way. Produces plots by analyzing CRT::Triggers and the
44 //AuxDetSimChannels associated with them (thus only working with MC files).
45 
47 public:
48  explicit CRTSimValidation(fhicl::ParameterSet const & p);
49  // The compiler-generated destructor is fine for non-base
50  // classes without bare pointers or other resource use.
51 
52  // Plugins should not be copied or assigned.
53  CRTSimValidation(CRTSimValidation const &) = delete;
55  CRTSimValidation & operator = (CRTSimValidation const &) = delete;
57 
58  // Required functions.
59  void analyze(art::Event const & e) override;
60 
61  // Selected optional functions.
62  void beginJob() override;
63 
64 private:
65 
66  //Parameters for reading in CRT::Triggers and associated AuxDetSimChannels.
67  art::InputTag fCRTLabel; //Label for the module that produced CRT::Triggers I
68  //plan to analyze.
69 
70  //Histograms I plan to write. Some TFileService-managed resource owns them,
71  //so all data members here are observer pointers that will not be deleted.
72  TH1D* fDetsWithHits; //Histogram names of AuxDetGeos that have CRT::Triggers
73  TH1D* fAllADCs; //Histogram all CRT::Hit ADC values in a single plot. In
74  //particle gun, this will show me that DAC threshold parameter
75  //is having an effect. With background simulation, could compare with
76  //data to see how realistic background is.
77  TH1D* fDevWithinTrigger; //Similar to sample standard deviation of associated IDEs' times taking
78  //Trigger's timestamp as mean. Will show me that readout window is working.
79  TH1D* fDeltaTAssoc; //Time difference between each IDE associated with a Trigger and that Trigger's timestamp
80  TH1D* fTriggerDeltaT; //Times between Triggers on a given module. There should be no
81  //entries below simulated dead time.
82 };
83 
84 
86  :
87  EDAnalyzer(p), fCRTLabel(p.get<art::InputTag>("CRTLabel"))
88 {
89  consumes<std::vector<CRT::Trigger>>(fCRTLabel);
90  consumes<std::vector<art::Assns<sim::AuxDetSimChannel, CRT::Trigger>>>(fCRTLabel);
91 }
92 
94 {
95  //Get the data products I plan to work with
96  const auto& triggers = e.getValidHandle<std::vector<CRT::Trigger>>(fCRTLabel);
97 
98  art::FindManyP<sim::AuxDetSimChannel> trigToSim(triggers, e, fCRTLabel);
99 
100  //Get a handle to the Geometry service to look up AuxDetGeos from module numbers
102 
103  //Mapping from channel to previous Trigger time
104  std::unordered_map<size_t, double> prevTimes;
105  for(const auto& trigger: *triggers)
106  {
107  fDetsWithHits->Fill(geom->AuxDet(trigger.Channel()).Name().c_str(), 1.0);
108  const auto& hits = trigger.Hits();
109  for(const auto& hit: hits) fAllADCs->Fill(hit.ADC());
110 
111  const auto found = prevTimes.find(trigger.Channel());
112  if(found != prevTimes.end())
113  {
114  fTriggerDeltaT->Fill(trigger.Timestamp() - found->second);
115  found->second = trigger.Timestamp();
116  }
117  else prevTimes[trigger.Channel()] = trigger.Timestamp();
118  }
119 
120  for(size_t trigIt = 0; trigIt < trigToSim.size(); ++trigIt)
121  {
122  const auto& trig = (*triggers)[trigIt];
123  const auto& simChans = trigToSim.at(trigIt);
124 
125  size_t nIDEs = 0;
126  const auto sumSq = std::accumulate(simChans.begin(), simChans.end(), 0.,
127  [this, &trig, &nIDEs](double sum, const auto& channel)
128  {
129  const auto& ides = channel->AuxDetIDEs();
130  nIDEs += ides.size();
131  return sum + std::accumulate(ides.begin(), ides.end(), 0.,
132  [this, &trig](double subSum, const auto& ide)
133  {
134  const auto diff = trig.Timestamp() -
135  (ide.exitT + ide.entryT)/2.;
136  fDeltaTAssoc->Fill(diff);
137  if(fabs(diff) > 200) //TODO: Read pset from original module to use readout
138  // time here
139  {
140  mf::LogInfo("LargeDeltaT") << "Found large deltaT: " << diff << "\n"
141  << "Timestamp is " << trig.Timestamp() << "\n"
142  << "True time is " << (ide.exitT +
143  ide.entryT)/2. << ".\n";
144  }
145 
146  return subSum + diff*diff;
147  });
148  });
149  fDevWithinTrigger->Fill(std::sqrt(sumSq/(nIDEs-1))); //Root of the mean of squares
150  }
151 }
152 
154 {
155  //Register ROOT objects I want to write with the TFileService
157  fDetsWithHits = tfs->make<TH1D>("DetsWithHits", "AuxDetGeo Names that Had CRT::Triggers;AuxDetGeo Name;Events", 1, 0, -1);
158  //Trigger automatic binning since am plotting strings.
159  fAllADCs = tfs->make<TH1D>("AllADCs", "ADC Values from CRT::Hits on All Channels;ADC Value;Hits", 500, 0, 2000);
160  fDevWithinTrigger = tfs->make<TH1D>("DevWithinTrigger", "Deviation of True Times from Associated Trigger Timestamp;"
161  "True Time #sigma;Energy Deposits", 100, 0, 300);
162  fDeltaTAssoc = tfs->make<TH1D>("DeltaTAssoc", "Time Difference Between Associated IDEs and Trigger Timestamp;#DeltaT_{IDE};Energy Deposits",
163  200, -100, 100);
164  fTriggerDeltaT = tfs->make<TH1D>("TriggerDeltaT", "#DeltaT Between Consecutive Triggers in a Module;#DeltaT;Trigger Pairs", 20, 0, 30);
165 }
166 
void analyze(art::Event const &e) override
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
ChannelGroupService::Name Name
uint8_t channel
Definition: CRTFragment.hh:201
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.h:25
art framework interface to geometry description
CRTSimValidation(fhicl::ParameterSet const &p)
const double e
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
CRTSimValidation & operator=(CRTSimValidation const &)=delete
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
Definition: DataViewImpl.h:441
p
Definition: test.py:223
AuxDetGeo const & AuxDet(unsigned int const ad=0) const
Returns the specified auxiliary detector.
Detector simulation of raw signals on wires.
auto const & get(AssnsNode< L, R, D > const &r)
Definition: AssnsNode.h:115