LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
MagDriftAna_module.cc
Go to the documentation of this file.
1 //
3 // MagDriftAna class
4 //
5 // dmckee@phys.ksu.edu
6 //
7 //
9 // C++ std library includes
10 #include <vector>
11 #include <string>
12 #include <algorithm>
13 #include <sstream>
14 #include <fstream>
15 #include <bitset>
16 // POSIX includes
17 extern "C" {
18 #include <sys/types.h>
19 #include <sys/stat.h>
20 }
21 // Framework includes
25 #include "fhiclcpp/ParameterSet.h"
33 // Root Includes
34 #include "TMath.h"
35 #include "TGraph.h"
36 #include "TFile.h"
37 #include "TLine.h"
38 #include "TComplex.h"
39 #include "TString.h"
40 #include "TGraph.h"
41 #include "TH2.h"
42 // LArSoft includes
52 
53 
54 namespace geo { class Geometry; }
55 
57 namespace hit {
58 
60  class MagDriftAna : public art::EDAnalyzer {
61 
62  public:
63 
64  explicit MagDriftAna(fhicl::ParameterSet const& pset);
65  virtual ~MagDriftAna();
66 
68  void analyze (const art::Event& evt);
69  void beginJob(){};
70  void endJob();
71  void reconfigure(fhicl::ParameterSet const& p);
72 
73  // intilize the histograms
74  //
75  // Can't be done in Begin job because I want to use LArProperties
76  // which used the database, so I test and run on each
77  // event. Wasteful and silly, but at least it *works*.
78  void ensureHists();
79 
80  private:
81 
84  std::string fLArG4ModuleLabel;
85 
86  // Flag for initialization done, because we set up histograms the
87  // first time through beginRun() so that we can use the
88  // database...
89  bool initDone;
90 
91  // Drift properties
92  double fDirCosY;
93  double fDirCosZ;
94 
95  TH1D * fChargeXpos; // << position of the MC Truth charge deposition
96  TH1D * fChargeYpos;
97  TH1D * fChargeZpos;
98  TH1D * fHitZpos; // << Z position of the recorded hit (from the
99  // z-sensitive wire)
100 
101  TH1D * fDriftDeltaZ; // << Difference in MC charge Z and recorded hit Z
102  TH1D * fDeltaZoverX; // << Delta Z as a function of drift distance
103  TH2D * fDeltaZvsX;
104 
105  // Same as above, but only for long drift distances (greater than
106  // 4/5 of the detector)
107  TH1D * fDriftDeltaZAway; // << Difference in MC charge Z and recorded hit Z
108  TH1D * fDeltaZoverXAway; // << Delta Z as a function of drift distance
109 
110  }; // class MagdriftAna
111 
112 
113  //-------------------------------------------------
114  MagDriftAna::MagDriftAna(fhicl::ParameterSet const& pset)
115  : EDAnalyzer(pset)
116  , initDone(false)
117  , fDirCosY(0.0)
118  , fDirCosZ(0.0)
119  , fChargeXpos()
120  , fChargeYpos()
121  , fChargeZpos()
122  , fHitZpos()
123  , fDriftDeltaZ()
124  , fDeltaZoverX()
125  , fDeltaZvsX()
126  , fDriftDeltaZAway()
127  , fDeltaZoverXAway()
128  {
129  this->reconfigure(pset);
130  }
131 
132  //-------------------------------------------------
134  {
135  }
136 
138  {
139  fFFTHitFinderModuleLabel = p.get< std::string >("HitsModuleLabel");
140 // fTrackFinderModuleLabel = p.get< std::string >("TracksModuleLabel");
141  fLArG4ModuleLabel = p.get< std::string >("LArGeantModuleLabel");
142  return;
143  }
144  //-------------------------------------------------
146  if (initDone) return; // Bail if we've already done this.
147  initDone = true; // Insure that we bail later on
148 
149  // get access to the TFile service
151  // Find magetic field related corrections
152  const detinfo::DetectorProperties* detprop = lar::providerFrom<detinfo::DetectorPropertiesService>();
153 
155  double Efield = detprop->Efield();
156  double Temperature = detprop->Temperature();
157  double DriftVelocity = detprop->DriftVelocity(Efield,Temperature)/1000.;
158 
159  // MagneticField::FieldAtPoint() returns (0, 0, 0) if there is no
160  // field at the requested point, so these direction cosines are
161  // 0 if there is no field
162  fDirCosY = -DriftVelocity * MagField->FieldAtPoint().z() / Efield;
163  fDirCosZ = +DriftVelocity * MagField->FieldAtPoint().y() / Efield;
164  LOG_VERBATIM("MagDriftAna")
165  << "Drift ratios: "
166  << "dY/dX = " << fDirCosY << ", "
167  << "dZ/dX = " << fDirCosZ;
168 
169  // geometry data.
171  // assumes all TPCs are the same
172  double width = 2 * geom->TPC(0).HalfWidth();
173  double halfHeight = geom->TPC(0).HalfHeight();
174  double length = geom->TPC(0).Length();
175 
176  double zScale = std::max(fDirCosZ/2.0,4e-4);
177 
178  // Assumes microboone dimensions. Ideally we'd fix this later...
179  fChargeXpos = tfs->make<TH1D>("hChargeXpos",
180  "MC X charge depositions; X (cm); Events",
181  101, 0.0, width);
182  fChargeYpos = tfs->make<TH1D>("hChargeYpos",
183  "MC Y charge depositions; Y (cm); Events",
184  101, -halfHeight, halfHeight);
185  fChargeZpos = tfs->make<TH1D>("hChargeZpos",
186  "MC Z charge depositions; Z (cm); Events",
187  101, 0.0, length);
188  fHitZpos = tfs->make<TH1D>("hHitZpos",
189  "Z charge collection; Z (cm); Events",
190  101, 0.0, length);
191 
192  fDriftDeltaZ = tfs->make<TH1D>("hDriftDeltaZ",
193  "Z drift of charge; delta Z (cm); Events",
194  101, -5*zScale*width, 5*zScale*width);
195  fDeltaZoverX = tfs->make<TH1D>("hDeltaZoverX",
196  "Z drift of charge; delta Z/X; Events",
197  51, -10*zScale, 10*zScale);
198  fDeltaZvsX = tfs->make<TH2D>("hDeltaZvsX",
199  "delta Z vs X; X (cm); delta Z (cm), Events",
200  51, 0.0, width,
201  51, -20*zScale, 20*zScale);
202 
203  // Some stats only when the Xdrift is large (more than 3/4)
205  tfs->make<TH1D>("hDriftDeltaZAway",
206  "Z drift of charge (long drift); delta Z (cm); Events",
207  101, -5*zScale*width, 5*zScale*width);
209  tfs->make<TH1D>("hDeltaZoverXAway",
210  "Z drift of charge (long drift); delta Z/X; Events",
211  51, -10*zScale, 10*zScale);
212 
213  return;
214 
215  }
216 
217  //-------------------------------------------------
219  {
220  // Add a line on the deltaZ/X graph to denote the calculated value
221  // of the drift ration
222  TLine *l = new TLine(fDirCosZ, 0,
223  fDirCosZ, 1.05*fDeltaZoverX->GetMaximum());
224  l->SetLineColor(kRed);
225  l->SetLineStyle(kDotted);
226  fDeltaZoverX->GetListOfFunctions()->Add(l);
227 
228  // I know this looks like a memory leak, but each historgram needs
229  // it's own copy of the line to prevent double freeing by the
230  // framework...
232  l = new TLine(fDirCosZ, 0,
233  fDirCosZ, 1.05*fDeltaZoverX->GetMaximum());
235  //
236  l->SetLineColor(kRed);
237  l->SetLineStyle(kDotted);
238  fDeltaZoverXAway->GetListOfFunctions()->Add(l);
239  }
240 
241  //-------------------------------------------------
243  {
244 
245  if (evt.isRealData()) {
246  throw cet::exception("MagDriftAna: ") << "Not for use on Data yet...\n";
247  }
248 
249  ensureHists();
250 
252  evt.getByLabel(fFFTHitFinderModuleLabel,hitHandle);
253 
254 // art::Handle< std::vector<recob::Track> > trackHandle;
255 // evt.getByLabel(fTrackFinderModuleLabel,trackHandle);
256 
258 
259  // We're going to want to compare the reconstructed Z with the
260  // simulted Z. For that purpose we use the simultion backtracking.
261  //
262 
264 
265  // art::PtrVector<recob::Hit> hits;
266  std::vector< art::Ptr<recob::Hit> > hits;
267  art::fill_ptr_vector(hits, hitHandle);
268 // std::vector< art::Ptr<recob::Track> > tracks;
269 // art::fill_ptr_vector(tracks, trackHandle);
270 
271  geo::WireID hitWireID;
272 
273  //++++++++++
274  // Loop over the hits (data) and fill histos
275  //++++++++++
276  for ( auto itr : hits) {
277 
278  hitWireID = itr->WireID();
279  // By assumption the drift occurs only in the z-direction, so
280  // we can get all the info we need from the z-measug plane.
281  if (hitWireID.Plane != (geom->Nplanes()-1)) continue;
282 
283  // Charge collected at the wire
284  //
285  // Exactly once for each recob::Hit
286  double w0pos[3] = {0.};
287  geom->TPC(hitWireID.TPC).Plane(hitWireID.Plane).Wire(0).GetCenter(w0pos);
288  double HitZpos = w0pos[2] + hitWireID.Wire * geom->TPC(hitWireID.TPC).WirePitch();
289  double Charge = itr->Integral();
290  fHitZpos->Fill(HitZpos,Charge);
291 
292  // Charge deposition in the detector
293  std::vector<double> xyz = bt_serv->HitToXYZ(itr);
294  fChargeXpos->Fill(xyz[0],Charge);
295  fChargeYpos->Fill(xyz[1],Charge);
296  double ChargeZpos = xyz[2];
297  fChargeZpos->Fill(ChargeZpos,Charge);
298 
299 // // Delta-Y
300 // fDriftDeltaY->Fill(HitYpos-ChargeYpos,Charge);
301 // // Delta Y correlation with X
302 // fDeltaYoverX->Fill((HitYpos-ChargeYpos)/xyz[0],Charge);
303 // fDeltaYvsX->Fill(xyz[0],HitYpos-ChargeZpos,Charge);
304 
305  // Delta-Z
306  //
307  // Compares the collected z position from the wire to the
308  // simulated z position
309  double DeltaZ = HitZpos-ChargeZpos;
310  fDriftDeltaZ->Fill(DeltaZ,Charge);
311  // Delta Z correlation with X
312  fDeltaZoverX->Fill(DeltaZ/xyz[0],Charge);
313  fDeltaZvsX->Fill(xyz[0],DeltaZ,Charge);
314  // The X related histograms know the dimensions of the
315  // detector, so we use them to set the "away" limit
316  if (xyz[0] > (fChargeYpos->GetXaxis()->GetXmax() * 0.80) ) {
317  fDriftDeltaZAway->Fill(DeltaZ,Charge);
318  fDeltaZoverXAway->Fill(DeltaZ/xyz[0],Charge);
319  }
320 
321  } // loop on Hits
322 
323  return;
324  }//end analyze method
325 
327 
328 } // end of hit namespace
329 
void analyze(const art::Event &evt)
read/write access to event
const std::vector< double > HitToXYZ(const recob::Hit &hit)
WireGeo const & Wire(unsigned int iwire) const
Definition: PlaneGeo.cxx:506
Declaration of signal hit object.
std::string fLArG4ModuleLabel
std::string fFFTHitFinderModuleLabel
void reconfigure(fhicl::ParameterSet const &p)
WireID_t Wire
Index of the wire within its plane.
Definition: geo_types.h:313
bool isRealData() const
Definition: Event.h:83
Describe the magnetic field structure of a detector.
double Length() const
Length is associated with z coordinate [cm].
Definition: TPCGeo.h:107
Base class for creation of raw signals on wires.
unsigned int Nplanes(unsigned int tpc=0, unsigned int cstat=0) const
Returns the total number of wire planes in the specified TPC.
Int_t max
Definition: plot.C:27
void hits()
Definition: readHits.C:15
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:42
Provides recob::Track data product.
virtual double Temperature() const =0
T get(std::string const &key) const
Definition: ParameterSet.h:231
double WirePitch(unsigned plane=0) const
Returns the center of the TPC volume in world coordinates [cm].
Definition: TPCGeo.cxx:427
PlaneID_t Plane
Index of the plane within its TPC.
Definition: geo_types.h:258
std::string fTrackFinderModuleLabel
Detector simulation of raw signals on wires.
Encapsulate the geometry of a wire.
double HalfHeight() const
Height is associated with y coordinate [cm].
Definition: TPCGeo.h:103
T * make(ARGS...args) const
Encapsulate the construction of a single detector plane.
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
Definition: DataViewImpl.h:344
virtual double DriftVelocity(double efield=0., double temperature=0.) const =0
TPCGeo const & TPC(unsigned int const tpc=0, unsigned int const cstat=0) const
Returns the specified TPC.
PlaneGeo const & Plane(geo::View_t view) const
Return the plane in the tpc with View_t view.
Definition: TPCGeo.cxx:299
#define LOG_VERBATIM(category)
void GetCenter(double *xyz, double localz=0.0) const
Fills the world coordinate of a point on the wire.
Definition: WireGeo.cxx:68
virtual double Efield(unsigned int planegap=0) const =0
Returns the nominal electric field in the specified volume.
TCEvent evt
Definition: DataStructs.cxx:5
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
Definition: Ptr.h:464
TPCID_t TPC
Index of the TPC within its cryostat.
Definition: geo_types.h:203
Float_t e
Definition: plot.C:34
WireID()=default
Default constructor: an invalid TPC ID.
Namespace collecting geometry-related classes utilities.
art framework interface to geometry description
double HalfWidth() const
Width is associated with x coordinate [cm].
Definition: TPCGeo.h:99
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
Encapsulate the construction of a single detector plane.