All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CoherentNoiseFactorProvider.cxx
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 /// \file icaruscode/TPC/Simulation/DetSim/tools/CoherentNoiseFactorProvider.cxx
3 /// \author T. Usher (factorized by Gianluca Petrillo, petrillo@slac.stanford.edu)
4 /// \see icaruscode/TPC/Simulation/DetSim/tools/CoherentNoiseFactorProvider.h
5 ////////////////////////////////////////////////////////////////////////
6 
7 // library header
9 
11 #include "art/Framework/Services/Registry/ServiceHandle.h"
12 #include "art/Framework/Services/Registry/ServiceDefinitionMacros.h"
13 #include "messagefacility/MessageLogger/MessageLogger.h"
14 #include "fhiclcpp/ParameterSet.h"
15 #include "cetlib_except/exception.h"
16 #include "cetlib/cpu_timer.h"
17 
20 
21 #include "TH1D.h"
22 
23 #include <string>
24 #include <iostream>
25 
26 namespace Noise
27 {
28 
29 //----------------------------------------------------------------------
30 // Constructor.
32 
33  mf::LogInfo("CoherentNoiseFactorProvider") << "Recover the channel map" ;
34 
35  fDiagnosticOutput = pset.get<bool>("DiagnosticOutput", false);
36 
37  // Set up the board->correlated factors map
38  const auto& channelMap = art::ServiceHandle<icarusDB::IICARUSChannelMap const>{}.get();
39 
40  const icarusDB::TPCReadoutBoardToChannelMap& readoutBoardToChannelMap = channelMap->getReadoutBoardToChannelMap();
41 
42  for(const auto& boardPair : readoutBoardToChannelMap)
43  {
44  fCorrFactorsMap.insert({boardPair.first,std::vector<float>(4,0.)});
45  }
46 
47 
48  mf::LogInfo("CoherentNoiseFactorProvider") << "==> FragmentID map size: " << fCorrFactorsMap.size() << std::endl;
49 
50  return;
51 }
52 
53 
54  // Reset factors
56 {
57  for(size_t index = 0; index < 4; index++)
58  {
59  float meanVal = noiseHist->GetMean();
60 
61  for(auto& correction : fCorrFactorsMap)
62  {
63  float corVal = noiseHist->GetRandom() / meanVal;
64 
65  correction.second[index] = corVal;
66  }
67  }
68 
69  return;
70 }
71 
72  // Recover the coherent noise factor
73 float CoherentNoiseFactorProvider::getCoherentNoiseFactor(unsigned int board, unsigned int index) const
74 {
75  CorrFactorsMap::const_iterator cohFactorsItr = fCorrFactorsMap.find(board);
76 
77  if (cohFactorsItr == fCorrFactorsMap.end())
78  throw cet::exception("CoherentNoiseFactorService")
79  << "Readout board " << board << ", with index " << index << "'\n"
80  << "This is considered a fatal issue!\n";
81 
82  float cf = cohFactorsItr->second[index];
83 
84  return cf;
85 }
86 
87 
88 } // end namespace
89 
Utilities related to art service access.
CoherentNoiseFactorProvider(const fhicl::ParameterSet &pset)
void resetCoherentNoiseFactors(const TH1D *) override
float getCoherentNoiseFactor(unsigned int, unsigned int) const override
std::map< unsigned int, SlotChannelVecPair > TPCReadoutBoardToChannelMap