Public Member Functions | Private Attributes | List of all members
DAQToOffline::NoiseCorrelation Class Reference
Inheritance diagram for DAQToOffline::NoiseCorrelation:
art::EDAnalyzer art::detail::Analyzer art::detail::LegacyModule art::Observer art::ModuleBase

Public Member Functions

 NoiseCorrelation (fhicl::ParameterSet const &pset)
 
 NoiseCorrelation (NoiseCorrelation const &)=delete
 
 NoiseCorrelation (NoiseCorrelation &&)=delete
 
NoiseCorrelationoperator= (NoiseCorrelation const &)=delete
 
NoiseCorrelationoperator= (NoiseCorrelation &&)=delete
 
void analyze (art::Event const &evt) override
 
void reconfigure (const fhicl::ParameterSet &pset)
 
- Public Member Functions inherited from art::EDAnalyzer
 EDAnalyzer (fhicl::ParameterSet const &pset)
 
template<typename Config >
 EDAnalyzer (Table< Config > const &config)
 
std::string workerType () const
 
- Public Member Functions inherited from art::detail::Analyzer
virtual ~Analyzer () noexcept
 
 Analyzer (fhicl::ParameterSet const &pset)
 
template<typename Config >
 Analyzer (Table< Config > const &config)
 
void doBeginJob ()
 
void doEndJob ()
 
void doRespondToOpenInputFile (FileBlock const &fb)
 
void doRespondToCloseInputFile (FileBlock const &fb)
 
void doRespondToOpenOutputFiles (FileBlock const &fb)
 
void doRespondToCloseOutputFiles (FileBlock const &fb)
 
bool doBeginRun (RunPrincipal &rp, ModuleContext const &mc)
 
bool doEndRun (RunPrincipal &rp, ModuleContext const &mc)
 
bool doBeginSubRun (SubRunPrincipal &srp, ModuleContext const &mc)
 
bool doEndSubRun (SubRunPrincipal &srp, ModuleContext const &mc)
 
bool doEvent (EventPrincipal &ep, ModuleContext const &mc, std::atomic< std::size_t > &counts_run, std::atomic< std::size_t > &counts_passed, std::atomic< std::size_t > &counts_failed)
 
- Public Member Functions inherited from art::Observer
 ~Observer () noexcept
 
 Observer (Observer const &)=delete
 
 Observer (Observer &&)=delete
 
Observeroperator= (Observer const &)=delete
 
Observeroperator= (Observer &&)=delete
 
void registerProducts (ProductDescriptions &, ModuleDescription const &)
 
void fillDescriptions (ModuleDescription const &)
 
std::string const & processName () const
 
bool wantAllEvents () const
 
bool wantEvent (Event const &e)
 
fhicl::ParameterSetID selectorConfig () const
 
Handle< TriggerResultsgetTriggerResults (Event const &e) const
 
- Public Member Functions inherited from art::ModuleBase
virtual ~ModuleBase () noexcept
 
 ModuleBase ()
 
ModuleDescription const & moduleDescription () const
 
void setModuleDescription (ModuleDescription const &)
 
std::array< std::vector< ProductInfo >, NumBranchTypes > const & getConsumables () const
 
void sortConsumables (std::string const &current_process_name)
 
template<typename T , BranchType BT>
ViewToken< T > consumesView (InputTag const &tag)
 
template<typename T , BranchType BT>
ViewToken< T > mayConsumeView (InputTag const &tag)
 

Private Attributes

std::string fFragType
 
std::string fRawDataLabel
 
TTree * fCorrelationTree
 
TH2F * fCorrelationHist
 
float fCorrelation
 
int fChannel1
 
int fChannel2
 
const lariov::DetPedestalProviderfPedestalRetrievalAlg = *(lar::providerFrom<lariov::DetPedestalService>())
 

Additional Inherited Members

- Public Types inherited from art::EDAnalyzer
using WorkerType = WorkerT< EDAnalyzer >
 
using ModuleType = EDAnalyzer
 
- Protected Member Functions inherited from art::Observer
 Observer (fhicl::ParameterSet const &config)
 
 Observer (std::vector< std::string > const &paths, fhicl::ParameterSet const &config)
 
detail::ProcessAndEventSelectorsprocessAndEventSelectors ()
 
- Protected Member Functions inherited from art::ModuleBase
ConsumesCollectorconsumesCollector ()
 
template<typename T , BranchType = InEvent>
ProductToken< T > consumes (InputTag const &)
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > consumesView (InputTag const &)
 
template<typename T , BranchType = InEvent>
void consumesMany ()
 
template<typename T , BranchType = InEvent>
ProductToken< T > mayConsume (InputTag const &)
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > mayConsumeView (InputTag const &)
 
template<typename T , BranchType = InEvent>
void mayConsumeMany ()
 

Detailed Description

Definition at line 60 of file NoiseCorrelation_module.cc.

Constructor & Destructor Documentation

DAQToOffline::NoiseCorrelation::NoiseCorrelation ( fhicl::ParameterSet const &  pset)
explicit

Definition at line 92 of file NoiseCorrelation_module.cc.

92  : art::EDAnalyzer(pset) {
93 
94  this->reconfigure(pset);
95  gStyle->SetOptStat(0);
96 
98  fCorrelationTree = tfs->make<TTree>("Correlations","Correlations");
99  fCorrelationHist = tfs->make<TH2F>("Correlation","Correlation;Online channel number;Online channel number;",2048,0,2048,2048,0,2048);
100  fCorrelationTree->Branch("Channel1",&fChannel1);
101  fCorrelationTree->Branch("Channel2",&fChannel2);
102  fCorrelationTree->Branch("Correlation",&fCorrelation);
103 
104 }
void reconfigure(const fhicl::ParameterSet &pset)
DAQToOffline::NoiseCorrelation::NoiseCorrelation ( NoiseCorrelation const &  )
delete
DAQToOffline::NoiseCorrelation::NoiseCorrelation ( NoiseCorrelation &&  )
delete

Member Function Documentation

void DAQToOffline::NoiseCorrelation::analyze ( art::Event const &  evt)
overridevirtual

Implements art::EDAnalyzer.

Definition at line 111 of file NoiseCorrelation_module.cc.

111  {
112 
113  art::Handle<artdaq::Fragments> rawFragments;
114  evt.getByLabel(fRawDataLabel, fFragType, rawFragments);
115 
116  art::EventNumber_t eventNumber = evt.event();
117 
118  // Check that the data are valid
119  if(!rawFragments.isValid()){
120  std::cerr << "Run: " << evt.run()
121  << ", SubRun: " << evt.subRun()
122  << ", Event: " << eventNumber
123  << " is NOT VALID" << std::endl;
124  throw cet::exception("rawFragments NOT VALID");
125  }
126 
127  // Create a map containing (fragmentID, fragIndex) for the event, will be used to check if each channel is present
128  std::map < unsigned int, unsigned int > mapFragID;
129  for(size_t fragIndex = 0; fragIndex < rawFragments->size(); fragIndex++){
130  const artdaq::Fragment &singleFragment = (*rawFragments)[fragIndex];
131  unsigned int fragmentID = singleFragment.fragmentID();
132  mapFragID.insert(std::pair<unsigned int, unsigned int>(fragmentID,fragIndex));
133  }
134 
135  // Create a 2D vector to save the correlations
136  std::vector<std::vector<float> > correlationArray(2048,std::vector<float>(2048,0));
137 
139  size_t numChannels = geometry->Nchannels();
140 
141  // Get the ADC vector for each channel
142  std::vector<std::vector<short> > adcVectors;
143 
144  for (size_t channel = 0; channel < numChannels; ++channel) {
145 
146  // Follow the steps written by J Davies in TpcDAQToOffline
147  unsigned int fragmentID = UnpackFragment::getFragIDForChan(channel);
148  unsigned int sample = UnpackFragment::getNanoSliceSampleForChan(channel);
149  std::vector<short> adcvec;
150  if (mapFragID.find(fragmentID) != mapFragID.end()) {
151  unsigned int fragIndex = mapFragID[fragmentID];
152  const artdaq::Fragment &singleFragment = (*rawFragments)[fragIndex];
153  lbne::TpcMilliSliceFragment millisliceFragment(singleFragment);
154  auto numMicroSlices = millisliceFragment.microSliceCount();
155  for(unsigned int i_micro = 0; i_micro < numMicroSlices; i_micro++) {
156  std::unique_ptr <const lbne::TpcMicroSlice> microSlice = millisliceFragment.microSlice(i_micro);
157  auto numNanoSlices = microSlice->nanoSliceCount();
158  for(uint32_t i_nano = 0; i_nano < numNanoSlices; i_nano++){
160  bool success = microSlice->nanosliceSampleValue(i_nano, sample, val);
161  if (success) {
162  float const pedestal = fPedestalRetrievalAlg.PedMean(channel);
163  short adc = short(val - pedestal);
164  if ((adc & 0x3F) == 0x0 || (adc & 0x3F) == 0x3F)
165  adcvec.push_back(short(-999));
166  else
167  adcvec.push_back(adc);
168  }
169  }
170  }
171  }
172 
173  adcVectors.push_back(adcvec);
174 
175  }
176 
177  // Look at all possible channel combinations
178  for (size_t chan1 = 0; chan1 < numChannels; ++chan1) {
179  for (size_t chan2 = chan1; chan2 < numChannels; ++chan2) {
180 
181  fChannel1 = chan1;
182  fChannel2 = chan2;
183  fCorrelation = -999;
184 
185  std::vector<short> adcvec1 = adcVectors[chan1];
186  std::vector<short> adcvec2 = adcVectors[chan2];
187 
188  if (fChannel1 % 50 == 0 and fChannel2 % 1000 == 0)
189  std::cout << "Looking at correlations between channel " << fChannel1 << " and " << fChannel2 << std::endl;
190 
191  // Now we have the ADC vectors, we can look at the correlations
192  // Use the Pearson Correlation Coefficient
193 
194  size_t n1 = adcvec1.size(), n2 = adcvec2.size();
195  if (n1 != n2)
196  continue;
197 
198  float sumxy = 0, sumx = 0, sumy = 0, sumx2 = 0, sumy2 = 0;
199  for (size_t tick = 0; tick < n1; ++tick) {
200  short adc1 = adcvec1[tick], adc2 = adcvec2[tick];
201  sumx += adc1;
202  sumy += adc2;
203  sumxy += adc1*adc2;
204  sumx2 += adc1*adc1;
205  sumy2 += adc2*adc2;
206  }
207 
208  float denom = ( (n1*sumx2) - (sumx*sumx) ) * ( (n1*sumy2) - (sumy*sumy) );
209  if (n1 > 0 and denom > 0) {
210  fCorrelation = ( (n1*sumxy) - (sumx*sumy) ) / ( TMath::Sqrt( denom ) );
211  correlationArray[fChannel1][fChannel2] = fCorrelation;
212  correlationArray[fChannel2][fChannel1] = fCorrelation;
213  }
214  //fCorrelationTree->Fill();
215 
216  }
217  } // channel loops
218 
219  for (unsigned int channel1 = 0; channel1 < correlationArray.size(); ++channel1)
220  for (unsigned int channel2 = 0; channel2 < correlationArray.size(); ++channel2)
221  fCorrelationHist->SetBinContent(channel1, channel2, correlationArray[channel1][channel2]);
222  fCorrelationHist->GetZaxis()->SetRangeUser(-1,1);
223 
224  return;
225 
226 }
unsigned int event
Definition: DataStructs.h:574
unsigned int run
Definition: DataStructs.h:575
unsigned int getNanoSliceSampleForChan(unsigned int channel)
unsigned short uint16_t
Definition: stdint.h:125
unsigned int Nchannels() const
Returns the number of TPC readout channels in the detector.
unsigned int getFragIDForChan(unsigned int channel)
bool isValid() const
Definition: Handle.h:183
unsigned int uint32_t
Definition: stdint.h:126
tick_as<> tick
Tick number, represented by std::ptrdiff_t.
Definition: electronics.h:74
static int max(int a, int b)
const lariov::DetPedestalProvider & fPedestalRetrievalAlg
IDNumber_t< Level::Event > EventNumber_t
Definition: IDNumber.h:118
virtual float PedMean(raw::ChannelID_t ch) const =0
Retrieve pedestal information.
unsigned int subRun
Definition: DataStructs.h:576
TCEvent evt
Definition: DataStructs.cxx:7
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
QTextStream & endl(QTextStream &s)
NoiseCorrelation& DAQToOffline::NoiseCorrelation::operator= ( NoiseCorrelation const &  )
delete
NoiseCorrelation& DAQToOffline::NoiseCorrelation::operator= ( NoiseCorrelation &&  )
delete
void DAQToOffline::NoiseCorrelation::reconfigure ( const fhicl::ParameterSet pset)

Definition at line 106 of file NoiseCorrelation_module.cc.

106  {
107  fFragType = pset.get<std::string>("FragType");
108  fRawDataLabel = pset.get<std::string>("RawDataLabel");
109 }
std::string string
Definition: nybbler.cc:12
T get(std::string const &key) const
Definition: ParameterSet.h:231

Member Data Documentation

int DAQToOffline::NoiseCorrelation::fChannel1
private

Definition at line 85 of file NoiseCorrelation_module.cc.

int DAQToOffline::NoiseCorrelation::fChannel2
private

Definition at line 86 of file NoiseCorrelation_module.cc.

float DAQToOffline::NoiseCorrelation::fCorrelation
private

Definition at line 84 of file NoiseCorrelation_module.cc.

TH2F* DAQToOffline::NoiseCorrelation::fCorrelationHist
private

Definition at line 83 of file NoiseCorrelation_module.cc.

TTree* DAQToOffline::NoiseCorrelation::fCorrelationTree
private

Definition at line 82 of file NoiseCorrelation_module.cc.

std::string DAQToOffline::NoiseCorrelation::fFragType
private

Definition at line 78 of file NoiseCorrelation_module.cc.

const lariov::DetPedestalProvider& DAQToOffline::NoiseCorrelation::fPedestalRetrievalAlg = *(lar::providerFrom<lariov::DetPedestalService>())
private

Definition at line 88 of file NoiseCorrelation_module.cc.

std::string DAQToOffline::NoiseCorrelation::fRawDataLabel
private

Definition at line 79 of file NoiseCorrelation_module.cc.


The documentation for this class was generated from the following file: