ProtoDUNEopdeteventdisplay_module.cc
Go to the documentation of this file.
1 // -*- mode: c++; c-basic-offset: 2; -*-
2 // This analyzer writes out a folder containing the
3 // PDS event display. For every OpFLsh, the OpHits are
4 // plotted.
5 //
6 //
7 
8 
9 #ifndef ProtoDUNE_opdet_eventdisplay_H
10 #define ProtoDUNE_opdet_eventdisplay_H
11 
12 // ROOT includes
13 #include "TH1.h"
14 #include "TH2.h"
15 #include "TLorentzVector.h"
16 #include "TVector3.h"
17 #include "TTree.h"
18 #include "TLine.h"
19 #include "TLegend.h"
20 
21 // C++ includes
22 #include <map>
23 #include <vector>
24 #include <iostream>
25 #include <cstring>
26 #include <sstream>
27 #include "math.h"
28 #include <climits>
29 #include <functional>
30 #include <algorithm>
31 #include <map>
32 
33 
34 // LArSoft includes
42 
44 //#include "OpticalDetector/OpDigiProperties.h"
45 
47 #include <numeric>
48 
49 // ART includes.
52 #include "fhiclcpp/ParameterSet.h"
57 #include "art_root_io/TFileService.h"
58 #include "art_root_io/TFileDirectory.h"
61 #include "canvas/Persistency/Common/FindManyP.h"
62 
63 namespace opdet {
64 
65  class ProtoDUNE_opdet_eventdisplay : public art::EDAnalyzer{
66  public:
67 
68  // Standard constructor and destructor for an ART module.
71 
72  // This method is called once, at the start of the job. In this
73  // example, it will define the histogram we'll write.
74  void beginJob();
75 
76  // The analyzer routine, called once per event.
77  void analyze (const art::Event&);
78 
79  private:
80 
81  // The stuff below is the part you'll most likely have to change to
82  // go from this custom example to your own task.
83 
84  // The parameters we'll read from the .fcl file.
85  std::string fOpFlashModuleLabel; // Input tag for OpFlash collection
86  std::string fOpHitModuleLabel; // Input tag for OpHit collection
87  float fSampleFreq; // in MHz
88  float fTimeBegin; // in us
89  float fTimeEnd; // in us
90 
91  float fYMin, fYMax, fZMin, fZMax;
92 
94 
95  Int_t fEventID;
96  Int_t fFlashID;
97  Int_t fHitID;
98  Float_t fFlashTime;
99 
100  Int_t fOpChannel;
101  Float_t fPeakTimeAbs;
102  Float_t fPeakTime;
103  Float_t fPE;
104 
105  Float_t fYOpCenter;
106  Float_t fZOpCenter;
107  Float_t fXOpCenter;
108 
109  std::vector< int > fFlashIDVector;
110  std::vector< float > fYCenterVector;
111  std::vector< float > fZCenterVector;
112  std::vector< float > fYWidthVector;
113  std::vector< float > fZWidthVector;
114  std::vector< float > fFlashTimeVector;
115  std::vector< float > fAbsTimeVector;
116  std::vector< int > fFlashFrameVector;
117  std::vector< bool > fInBeamFrameVector;
118  std::vector< int > fOnBeamTimeVector;
119  std::vector< float > fTotalPEVector;
120 
121  std::vector< float > fPEsPerFlashPerChannelVector;
122  };
123 
124 }
125 
126 #endif // ProtoDUNE_opdet_eventdisplay_H
127 
128 namespace opdet {
129 
130  //-----------------------------------------------------------------------
131  // Constructor
133  : EDAnalyzer(pset)
134  {
135 
136  // Indicate that the Input Module comes from .fcl
137  fOpFlashModuleLabel = pset.get<std::string>("OpFlashModuleLabel");
138  fOpHitModuleLabel = pset.get<std::string>("OpHitModuleLabel");
139 
140  auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataForJob();
141  fTimeBegin = clockData.OpticalClock().Time();
142  fTimeEnd = clockData.OpticalClock().FramePeriod();
143  fSampleFreq = clockData.OpticalClock().Frequency();
144 
145  fYMin = pset.get<float>("YMin");
146  fYMax = pset.get<float>("YMax");
147  fZMin = pset.get<float>("ZMin");
148  fZMax = pset.get<float>("ZMax");
149 
150  PosHistYRes = 20;
151  PosHistZRes = 42;
152 
154 
155  fFlashID = 0;
156  }
157 
158  //-----------------------------------------------------------------------
159  // Destructor
161  {}
162 
163  //-----------------------------------------------------------------------
165  {}
166 
167  //-----------------------------------------------------------------------
169  {
170 
171  float displace[288]={0};
172 
173  for(int j=0;j<287;j++) displace[j]=j;
174  for(int j=0;j<284;j+=4){
175  displace[j]=-100;
176  displace[j+1]=-40;
177  displace[j+2]=5;
178  displace[j+3]=60;
179  if((j>=132 && j<=143) || (j>=264 && j<=275)){
180  displace[j]=-100;
181  displace[j+1]=-75;
182  displace[j+2]=-60;
183  displace[j+3]=-40;
184  displace[j+4]=-20;
185  displace[j+5]=-5;
186  displace[j+6]=5;
187  displace[j+7]=20;
188  displace[j+8]=40;
189  displace[j+9]=60;
190  displace[j+10]=75;
191  displace[j+11]=100;
192  j+=8;
193  }
194 
195  }
196 
197  Float_t binsz[] = {0,10, 29, 48, 66, 84, 102, 120, 138, 156, 174, 192, 211, 230, 240, 257, 278, 296, 314, 332, 350, 368, 386, 404, 422, 441, 460, 470, 489, 508, 526, 544, 562, 580, 598, 616, 634, 650, 671, 690, 700};
198  Int_t binnumz = sizeof(binsz)/sizeof(Float_t) - 1;
199 
200  Float_t binsy[]={-600,-540, -480, -420, -360, -300, -240, -180, -120, -60, -.5,.5, 60, 120, 180, 240, 300, 360, 420, 480, 540, 600};
201  Int_t binnumy = sizeof(binsy)/sizeof(Float_t) - 1;
202 
203  // Get flashes from event
204  auto FlashHandle = evt.getHandle< std::vector< recob::OpFlash > >(fOpFlashModuleLabel);
205 
206  // Get assosciations between flashes and hits
207  art::FindManyP< recob::OpHit > Assns(FlashHandle, evt, fOpFlashModuleLabel);
208 
209  // Create string for histogram name
210  char HistName[50];
211  char HistTitle[100];
212 
213  fFlashID = 0;
214 
215  // Access ART's TFileService, which will handle creating and writing
216  // histograms for us.
218 
219  //std::vector<TH1D*> FlashHist;
220  std::vector<TH2D*> DispHist;
221 
222  fEventID = evt.id().event();
223 
224  sprintf(HistName, "Event_%d_Disps", fEventID);
225  sprintf(HistTitle, "PE from OpHits Event %d;z ;DaS RaS (y)", fEventID);
226 
228  //unsigned int NOpChannels = geom->NOpChannels();
229 
230  TH2D * ThisEventDisp = nullptr;
231  ThisEventDisp = tfs->make<TH2D>(HistName,HistTitle,
232  binnumz, binsz,
233  binnumy, binsy);
234 
235 
236  // For every OpFlash in the vector
237  for(unsigned int i = 0; i < FlashHandle->size(); ++i)
238  {
239 
240  // Get OpFlash
241  art::Ptr< recob::OpFlash > TheFlashPtr(FlashHandle, i);
242  recob::OpFlash TheFlash = *TheFlashPtr;
243 
244  fFlashTime = TheFlash.Time();
245  fFlashID = i; //++;
246 
247  double xyz[3];
248  auto OpHitHandle = evt.getHandle< std::vector< recob::OpHit > >(fOpHitModuleLabel);
249  char INFO[500];
250  for(size_t i=0; i!=OpHitHandle->size(); ++i)
251  {
252 
253 
254  fOpChannel = OpHitHandle->at(i).OpChannel();
255  if(fOpChannel == 75 || fOpChannel ==101 ||fOpChannel ==160) continue;
257  fXOpCenter = xyz[0];
258  fYOpCenter = xyz[1];
259  fZOpCenter = xyz[2];
260  fPeakTimeAbs = OpHitHandle->at(i).PeakTimeAbs();
261  fPeakTime = OpHitHandle->at(i).PeakTime();
262  fPE = OpHitHandle->at(i).PE();
263  fHitID = i;
264 
265 
266  sprintf(INFO," OpChannel: %i Center Position: %f %f %f PE: %f Hit no: %i", fOpChannel, fXOpCenter, fYOpCenter, fZOpCenter+displace[fOpChannel], fPE, fHitID);
267 
268  if(fXOpCenter >0){
269  if(fOpChannel>=132 && fOpChannel<=143)
270  ThisEventDisp->Fill(fZOpCenter+displace[fOpChannel], fYOpCenter,fPE);
271  else{
272  ThisEventDisp->Fill(fZOpCenter+displace[fOpChannel], fYOpCenter,fPE);
273  ThisEventDisp->Fill(fZOpCenter+displace[fOpChannel]+18, fYOpCenter,fPE);
274  ThisEventDisp->Fill(fZOpCenter+displace[fOpChannel]+36, fYOpCenter,fPE);
275  }
276  }
277  else if(fXOpCenter<0){
278  if(fOpChannel>=264 && fOpChannel<=275)
279  ThisEventDisp->Fill(fZOpCenter+displace[fOpChannel], fYOpCenter-600,fPE);
280  else{
281  ThisEventDisp->Fill(fZOpCenter+displace[fOpChannel], fYOpCenter-600,fPE);
282  ThisEventDisp->Fill(fZOpCenter+displace[fOpChannel]+18, fYOpCenter-600,fPE);
283  ThisEventDisp->Fill(fZOpCenter+displace[fOpChannel]+38, fYOpCenter-600,fPE);
284  }
285  }
286  TLine *line = new TLine(0,0,600,0);
287  line->SetLineColor(kBlack);
288  line->Draw();
289  }
290 
291  }
292 
293 
294  }
295 
296 } // namespace opdet
297 
298 namespace opdet {
300 }
Handle< PROD > getHandle(SelectorBase const &) const
Definition: DataViewImpl.h:382
std::string string
Definition: nybbler.cc:12
void GetCenter(double *xyz, double localz=0.0) const
Definition: OpDetGeo.cxx:40
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.h:25
art framework interface to geometry description
double Time() const
Definition: OpFlash.h:106
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
T get(std::string const &key) const
Definition: ParameterSet.h:271
Encapsulate the geometry of an optical detector.
void line(double t, double *p, double &x, double &y, double &z)
ProtoDUNE_opdet_eventdisplay(const fhicl::ParameterSet &)
EventNumber_t event() const
Definition: EventID.h:116
Access the description of detector geometry.
TCEvent evt
Definition: DataStructs.cxx:7
OpDetGeo const & OpDetGeoFromOpChannel(unsigned int OpChannel) const
Returns the geo::OpDetGeo object for the given channel number.
EventID id() const
Definition: Event.cc:34
pure virtual base interface for detector clocks