MuonCounterTimes_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: Muoncountertimes
3 // Module Type: analyzer
4 // File: Muoncountertimes_module.cc
5 //
6 // Generated at Sun Mar 24 09:05:02 2013 by Tingjun Yang using artmod
7 // from art v1_02_06.
8 ////////////////////////////////////////////////////////////////////////
9 #ifndef Muoncountertimes_Module
10 #define Muoncountertimes_Module
11 
12 // Framework includes
16 #include "fhiclcpp/ParameterSet.h"
21 #include "art_root_io/TFileService.h"
22 #include "art_root_io/TFileDirectory.h"
24 
25 // LArSoft includes
37 
38 // ROOT includes
39 #include "TTree.h"
40 #include "TTimeStamp.h"
41 #include "TH1D.h"
42 #include "TString.h"
43 
44 //PTB online to offline converter alg
45 
46 
47 //const int kMaxHits = 10000; //maximum number of hits // unused
48 //const int kMaxAuxDets = 100; // unused
49 //const unsigned short kMaxTkIDs = 100;
50 namespace MyMuoncountertimes {
51 
53 public:
54  explicit Muoncountertimes(fhicl::ParameterSet const & p);
55  virtual ~Muoncountertimes();
56 
57  // This method is called once, at the start of the job. In this
58  // example, it will define the histograms and n-tuples we'll write.
59  void beginJob();
60  void endJob();
61 
62  // This method is called once, at the start of each run. It's a
63  // good place to read databases or files that may have
64  // run-dependent information.
65  // void beginRun(const art::Run& run);
66 
67  // This method reads in any parameters from the .fcl files. This
68  // method is called 'reconfigure' because it might be called in the
69  // middle of a job; e.g., if the user changes parameter values in an
70  // interactive event display.
71  void reconfigure(fhicl::ParameterSet const& pset);
72 
73  // The analysis routine, called once per event.
74  void analyze (const art::Event& evt);
75 
76 private:
77 
78  void ResetVars();
79 
80  //int total_Hits; // unused
81  int run;
82  int subrun;
83  int event;
84  int event_Count = 0;
85  //double event_Length = 10e-3; // unused
86 
87  std::vector<TH1D*> fHist_Vec;
88 
100 
101  std::map<int,int> fPTBMap;
102 };
103 
105  : EDAnalyzer(pset)
106 {
107  // Read in the parameters from the .fcl file.
108  this->reconfigure(pset);
109 }
110 
112 { // Read parameters from the .fcl file. The names in the arguments
113  // to p.get<TYPE> must match names in the .fcl file.
114 
115  fLower_Block1 = p.get<int>("LowerBlock1");
116  fUpper_Block1 = p.get<int>("UpperBlock1");
117  fLower_Block2 = p.get<int>("LowerBlock2");
118  fUpper_Block2 = p.get<int>("UpperBlock2");
119  fCoincidence_Window = p.get<int>("CoincidenceWindow");
120  fCounterModuleLabel = p.get< std::string >("CounterModuleLabel");
121  // fLArG4ModuleLabel(p.get< std::string >("LArGeantModuleLabel", "largeant"));
122  fCombinedTimeDelay = p.get< double >("CombinedTimeDelay");
123  fFragType = p.get<std::string>("FragType");
124  fRawDataLabel = p.get<std::string>("DataLabel");
125  fPTBMapFile = p.get<std::string>("PTBMapFile");
126  fPTBMapDir = p.get<std::string>("PTBMapDir");
127 
128  DAQToOffline::BuildPTBChannelMap(fPTBMapDir, fPTBMapFile, fPTBMap);
129 
130  return;
131 }
132 
134 {
135  // Clean up dynamic memory and other resources here.
136 }
137 
139 {
140  // Implementation of required member function here.
141  ResetVars();
142 
144 
145  run = evt.run();
146  subrun = evt.subRun();
147  event = evt.id().event();
148 
149  // New way to get counter hits
150  /*
151  art::Handle< std::vector< raw::ExternalTrigger> > externalTriggerListHandle;
152  evt.getByLabel(fCounterModuleLabel, externalTriggerListHandle);
153  std::vector< art::Ptr< raw::ExternalTrigger> > trigs;
154  art::fill_ptr_vector(trigs,externalTriggerListHandle);
155  */
156 
158 
159  evt.getByLabel(fRawDataLabel, fFragType, fragment);
160 
161  // Check if there is PTB data in this event
162  // Don't crash code if not present, just don't save anything
163  try { fragment->size(); }
164  catch(std::exception const&) {
165  mf::LogWarning("MuonCounterTimes") << "WARNING: Raw PTB data not found in event " << evt.event();
166  return;
167  }
168 
169  // Check that the data is valid
170  if(!fragment.isValid()){
171  mf::LogError("MuonCounterTimes") << "Run: " << evt.run()
172  << ", SubRun: " << evt.subRun()
173  << ", Event: " << evt.event()
174  << " is NOT VALID";
175  throw cet::exception("raw NOT VALID");
176  return;
177  }
178 
179  std::vector<std::vector<int>> coincidences(2);
180  std::vector<std::vector<int>> trig_ID_Vec(2);
181  std::vector<std::vector<long long>> trig_Times_Vec(2);
182  lbne::PennMicroSlice::Payload_Timestamp *FirstPTBTimestamp = nullptr;
183  auto trigs = DAQToOffline::PennFragmentToExternalTrigger(*fragment, fPTBMap, FirstPTBTimestamp);
184 
185  unsigned int total_Hits = trigs.size();
186 
187  for(unsigned int i = 0; i < total_Hits; i++)
188  {
189  int auxdetid = trigs.at(i).GetTrigID();
190  long long trig_Time = trigs.at(i).GetTrigTime();
191 
192  if(auxdetid>=fLower_Block1 && auxdetid<=fUpper_Block1)
193  {
194  trig_ID_Vec.at(0).push_back(auxdetid);
195  trig_Times_Vec.at(0).push_back(trig_Time);
196  }
197  else if(auxdetid>=fLower_Block2 && auxdetid<=fUpper_Block2)
198  {
199  trig_ID_Vec.at(1).push_back(auxdetid);
200  trig_Times_Vec.at(1).push_back(trig_Time);
201  }
202  }
203 
204  for(unsigned int i = 0; i < trig_ID_Vec.at(0).size(); i++)
205  {
206  for(unsigned int j = 0; j < trig_ID_Vec.at(1).size(); j++)
207  {
208  if(j<=i)
209  {
210  if(std::abs(trig_Times_Vec.at(0).at(i)-trig_Times_Vec.at(1).at(j))<fCoincidence_Window)
211  {
212  coincidences.at(0).push_back(trig_ID_Vec.at(0).at(i));
213  coincidences.at(1).push_back(trig_ID_Vec.at(1).at(j));
214  }
215  }
216  }
217  }
218 
219  for(unsigned int i = 0; i < coincidences.at(0).size(); i++)
220  {
221  fHist_Vec.at(coincidences.at(0).at(i)-fLower_Block1)->Fill(coincidences.at(1).at(i));
222  }
223  event_Count+=1;
224 }
225 
227 {
228  // Implementation of optional member function here.
229 
231 
233 
234  for(unsigned int i = 0; i < fHist_Vec.size(); i++)
235  {
236  TString key = Form("h%i", i);
237  TH1D *tempHist = tfs->make<TH1D>(key, key, fUpper_Block2-fLower_Block2+1, fLower_Block2, fUpper_Block2+1);
238  fHist_Vec.at(i) = tempHist;
239  }
240 }
241 
243 {
244  for(unsigned int i = 0; i < fHist_Vec.size(); i++)
245  {
246  TString fHist_Title1 = Form("Coincidence Plots, run %i, ", run);
247  TString fHist_Title2 = Form("counter %i.", i+fLower_Block1);
248  TString fHist_Title = fHist_Title1 + fHist_Title2;
249 
250  TString fHist_Name1 = Form("Run%i", run);
251  TString fHist_Name2 = Form("Counter%i", i+fLower_Block1);
252  TString fHist_Name = fHist_Name1 + fHist_Name2;
253 
254  fHist_Vec.at(i)->GetXaxis()->SetTitle("Coincidence Partner");
255  fHist_Vec.at(i)->GetYaxis()->SetTitle("Frequency");
256  fHist_Vec.at(i)->GetYaxis()->SetTitleOffset(1.);
257 
258  fHist_Vec.at(i)->SetTitle(fHist_Title);
259  fHist_Vec.at(i)->SetName(fHist_Name);
260 
261  fHist_Vec.at(i)->Sumw2();
262  }
263 }
264 
266 
267  run = -99999;
268  subrun = -99999;
269  event = -99999;
270 }
271 
273 
274  } // namespace Muoncountertimes
275 
276 #endif // Muoncountertimes_Module
EventNumber_t event() const
Definition: DataViewImpl.cc:96
std::string string
Definition: nybbler.cc:12
Declaration of signal hit object.
void BuildPTBChannelMap(std::string MapDir, std::string MapFile, std::map< int, int > &channelMap)
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.h:27
bool isValid() const
Definition: Handle.h:183
T abs(T value)
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
Definition: DataViewImpl.h:446
object containing MC truth information necessary for making RawDigits and doing back tracking ...
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:69
def key(type, name=None)
Definition: graph.py:13
T get(std::string const &key) const
Definition: ParameterSet.h:231
SubRunNumber_t subRun() const
Definition: DataViewImpl.cc:89
RunNumber_t run() const
Definition: DataViewImpl.cc:82
Encapsulate the geometry of a wire.
p
Definition: test.py:223
Utility object to perform functions of association.
Encapsulate the construction of a single detector plane.
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
EventNumber_t event() const
Definition: EventID.h:116
Muoncountertimes(fhicl::ParameterSet const &p)
TCEvent evt
Definition: DataStructs.cxx:7
std::vector< raw::ExternalTrigger > PennFragmentToExternalTrigger(artdaq::Fragments const &Fragments, std::map< int, int > &channelMap, lbne::PennMicroSlice::Payload_Timestamp *&FirstPTBTimestamp)
EventID id() const
Definition: Event.cc:37
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
void reconfigure(fhicl::ParameterSet const &pset)