MergeDigits_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 /// \file MergeDigits.cxx
3 /// \brief A module to copy the original raw digits to a new label. Note that the new label is defined in the job file.
4 ///
5 /// \version $Id: MergeDigits.cxx,v 1.2 2012-09-20 22:01:37 greenc Exp $
6 /// \author ksachdev@physics.umn.edu
7 ////////////////////////////////////////////////////////////////////////
8 
9 // C/C++ includes
10 #include <iostream>
11 #include <vector>
12 
13 // Framework includes
22 
23 // NOvASoft includes
24 #include "RawData/RawDigit.h"
25 #include "Simulation/FLSHitList.h"
26 
27 
28 
29 namespace murem
30 {
31  namespace
32  {
33  struct MergeDigitsParams
34  {
35  template<class T> using Atom = fhicl::Atom<T>;
36  template<class T> using Table = fhicl::Table<T>;
37  using Comment = fhicl::Comment;
38  using Name = fhicl::Name;
39 
40  Atom<std::string> rawDigitModule
41  {
42  Name("RawDigitModule"),
43  Comment("MRCC raw digit module label.")
44  };
45  Atom<std::string> electronRawDigitModule
46  {
47  Name("ElectronRawDigitModule"),
48  Comment("MRE raw digit module label")
49  };
50  Atom<std::string> electronwnoiseRawDigitModule
51  {
52  Name("ElectronWNoiseRawDigitModule"),
53  Comment("MRE raw digit module label with noise")
54  };
55  };
56  }
57 
58  class MergeDigits : public art::EDProducer
59  {
60  public:
61  // Allows 'nova --print-description' to work
63 
64  explicit MergeDigits(const Parameters& params);
65  ~MergeDigits();
66 
67  void produce(art::Event& evt);
68 
69  private:
70 
71  MergeDigitsParams fParams;
72  };
73 }
74 
75 
76 namespace murem
77 {
78 
79  /*********************************************************************************************/
80  ////////////////////////////////////////////////////////////////////////
81 
83  :fParams(params())
84  {
85 
86  produces< std::vector <rawdata::RawDigit> >();
87 
88  mf::LogInfo("MergeDigits") <<"MergeDigits::MergeDigits()\n";
89 
90  }
91 
92  /*********************************************************************************************/
93  ////////////////////////////////////////////////////////////////////////
94 
96  {
97 
98  }
99 
100  /*********************************************************************************************/
101  ////////////////////////////////////////////////////////////////////////
102 
104  {
105  bool isMC = !evt.isRealData();
106 
107  std::unique_ptr< std::vector<rawdata::RawDigit> > origDigits(new std::vector<rawdata::RawDigit>);
108  std::vector< rawdata::RawDigit> newDigits;
109 
110  // Get the original set of raw digits in the event
111 
113  evt.getByLabel(fParams.rawDigitModule(), digitcol);
115 
116  for(unsigned int i = 0; i < digitcol->size(); ++i){
117  art::Ptr<rawdata::RawDigit> dig(digitcol, i);
118  digits.push_back(dig);
119  }
120  /// Get digits for the election without noise
122  evt.getByLabel(fParams.electronRawDigitModule(), edigitcol);
124 
125  for(unsigned int i = 0; i < edigitcol->size(); ++i){
126  art::Ptr<rawdata::RawDigit> edig(edigitcol, i);
127  edigits.push_back(edig);
128  }
129  /// Get digits for the election with noise
131  evt.getByLabel(fParams.electronwnoiseRawDigitModule(), ewndigitcol);
133 
134  for(unsigned int i = 0; i < ewndigitcol->size(); ++i){
135  art::Ptr<rawdata::RawDigit> ewndig(ewndigitcol, i);
136  ewndigits.push_back(ewndig);
137  }
138 
139  int nDigs = digits.size();
140  int nEDigs = edigits.size();
141  int nEWNDigs = ewndigits.size();
142  std::cout<<"Number of digits: mrcc "<<nDigs<<" elec w/o noise "<<nEDigs<<" elec with noise "<<nEWNDigs<<std::endl;
143 
144  //Inserting electron with physics noise cells (if they don't overlap with mrcc)
145  for(int kDig = 0; kDig < nEWNDigs; kDig++){
146  rawdata::RawDigit ewndig = *ewndigits[kDig];
147  bool samecell = false;
148  // check that electron and mrcc don't share the cell
149  for(int jDig = 0; jDig < nDigs; jDig++){
150  if (ewndig.Channel() == digits[jDig]->Channel() ) samecell = true;
151  }
152  if (!samecell){
153  ewndig.SetMC(isMC);
154  newDigits.push_back(ewndig);
155  }
156  }
157  std::cout<<"Merging electron digits outside mrcc: "<<newDigits.size()<<std::endl;
158  int counter = 0;
159  // now merge mrcc and mrcc with electrons in overlaped cells
160  for(int jDig = 0; jDig < nDigs; jDig++){
161  rawdata::RawDigit rd = *digits[jDig];
162  unsigned int pureADC = 0;
163  // merging case when mrcc and electron share the same cell
164  for(int iDig = 0; iDig < nEDigs; iDig++){
165  if (rd.Version() != edigits[iDig]->Version()) {std::cout<<"Issie with mrcc and electron Version()"<<std::endl; exit(1);}
166  if (rd.Channel() == edigits[iDig]->Channel()){
167  // leave pedestal as it is in order to avoid double counting
168  if (rd.Version() > 0){ // Do this only for multipoint era
169  for (unsigned int i = 1; i<rd.NADC(); i++){
170  // count pure signal above adc0 and add it to the mrcc adc1-3
171  pureADC = edigits[iDig]->ADC(i) - edigits[iDig]->ADC(0);
172  rd.SetADC(i, rd.ADC(i) + pureADC);
173  }
174  }
175  if (rd.Version() == 0) { // just sum amplitudes in case of signle-point
176  rd.SetADC(0, rd.ADC(0) + edigits[iDig]->ADC(0));
177  std::cout<<"NB: single-point "<<std::endl;
178  }
179  counter++; // use it to count overlapped cells
180  }
181  }//end loop over pure electron digits
182  rd.SetMC(isMC);
183  newDigits.push_back(rd);
184  }// end loop over digits
185 
186  std::cout<<"Overlapped region digits: "<<counter<<std::endl;
187  std::cout<<"NEW DIG SIZE "<<newDigits.size()<<std::endl;
188 
189  for(unsigned int digs = 0; digs<newDigits.size(); digs++ ){
190  origDigits->push_back( newDigits[digs] );
191  }
192  evt.put(std::move(origDigits));
193 
194  return;
195 
196  } // End of producer
197 
198 
200 
201 
202 /*********************************************************************************************/
203 ////////////////////////////////////////////////////////////////////////
204 
205 }//end of namespace murem
MergeDigits(const Parameters &params)
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
Atom< std::string > electronwnoiseRawDigitModule
bool isRealData() const
Definition: Event.h:83
DEFINE_ART_MODULE(TestTMapFile)
ProductID put(std::unique_ptr< PROD > &&product)
Definition: Event.h:102
Atom< std::string > electronRawDigitModule
void SetADC(uint32_t i, int16_t iADC)
Definition: RawDigit.cxx:108
void push_back(Ptr< U > const &p)
Definition: PtrVector.h:441
int evt
void produce(art::Event &evt)
uint8_t Version() const
Definition: RawDigit.h:87
size_type size() const
Definition: PtrVector.h:308
OStream cout
Definition: OStream.cxx:6
void SetMC(bool isMC=true)
Definition: RawDigit.h:106
Atom< std::string > rawDigitModule
int16_t ADC(uint32_t i) const
Definition: RawDigit.cxx:58
uint32_t NADC() const
Definition: RawDigit.h:81
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
Definition: DataViewImpl.h:344
exit(0)
uint32_t Channel() const
Definition: RawDigit.h:84
MergeDigitsParams fParams
Definition: fwd.h:28