DriftAna_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: DriftAna
3 // Plugin Type: analyzer (art v3_03_01)
4 // File: DriftAna_module.cc
5 //
6 // Generated at Sun Dec 1 22:31:29 2019 by Tingjun Yang using cetskelgen
7 // from cetlib version v3_08_00.
8 ////////////////////////////////////////////////////////////////////////
9 
16 #include "art_root_io/TFileService.h"
18 #include "fhiclcpp/ParameterSet.h"
20 
24 
25 #include "TH1D.h"
26 #include "TGraph.h"
27 
28 class DriftAna;
29 
30 class DriftAna : public art::EDAnalyzer {
31 public:
32  explicit DriftAna(fhicl::ParameterSet const& p);
33  // The compiler-generated destructor is fine for non-base
34  // classes without bare pointers or other resource use.
35 
36  // Plugins should not be copied or assigned.
37  DriftAna(DriftAna const&) = delete;
38  DriftAna(DriftAna&&) = delete;
39  DriftAna& operator=(DriftAna const&) = delete;
40  DriftAna& operator=(DriftAna&&) = delete;
41 
42  // Required functions.
43  void analyze(art::Event const& e) override;
44 
45  // Selected optional functions.
46  void beginJob() override;
47 
48 private:
49 
51  TH1D *drifttimeave;
52  TH1D *drifttimeint;
53  TH1D *fEfield;
54 
55  TH1D *fdeltatnosce;
56  TH1D *fdeltatave;
57  TH1D *fdeltatint;
58 
59  TH1D *fdriftvnosce;
60  TH1D *fdriftvave;
61  TH1D *fdriftvint;
62 
63  TH1D *fefieldnosce;
64  TH1D *fefieldave;
65  TH1D *fefieldint;
66 };
67 
68 
70  : EDAnalyzer{p} // ,
71  // More initializers here.
72 {
73  // Call appropriate consumes<>() for any products to be retrieved by this module.
74 }
75 
77 {
78  auto const detProp = art::ServiceHandle<detinfo::DetectorPropertiesService>()->DataFor(e);
79  double driftv = detProp.DriftVelocity(detProp.Efield(),
80  detProp.Temperature());
81  double efield = detProp.Efield();
82  std::cout<<"E field = "<<efield<<" Nominal drift velocity = "<<driftv<<std::endl;
83 
84  const int n = 100;
85  const double e0 = 0.4;
86  const double e1 = 0.7;
87  std::vector<double> vecv;
88  std::vector<double> vece;
89  for (int i = 0; i<n; ++i){
90  double e_field = e0 + i*(e1-e0)/n;
91  double drift_v = detProp.DriftVelocity(e_field,
92  detProp.Temperature());
93  vecv.push_back(drift_v);
94  vece.push_back(e_field);
95  }
96  TGraph *gr = new TGraph(n, &vecv[0], &vece[0]);
97  for (int i = 1; i<=drifttimeave->GetNbinsX(); ++i){
98  double xyz[3] = {0};
99  xyz[0] = drifttimeave->GetBinCenter(i);
100  xyz[1] = 300;
101  xyz[2] = 350;
102  std::cout<<xyz[0]<<" "<<xyz[1]<<" "<<xyz[2]<<std::endl;
103  double driftdis = 358.6 - std::abs(xyz[0]);
104  double drifttime = driftdis/driftv;
105  drifttimenosce->SetBinContent(i, drifttime);
106  geo::Vector_t posOffsets;
107  auto const* SCE = lar::providerFrom<spacecharge::SpaceChargeService>();
108  if (SCE->EnableSimSpatialSCE() == true){
109  posOffsets = SCE->GetPosOffsets({ xyz[0], xyz[1], xyz[2] });
110  }
111  posOffsets.SetX(-posOffsets.X());
112  driftdis += posOffsets.X();
113  drifttime = driftdis/driftv;
114  drifttimeave->SetBinContent(i, drifttime);
115 
116  double dir = 1;
117  if (xyz[0]<0) dir = -1;
118  double xyz1[3];
119  xyz1[0] = xyz[0];
120  xyz1[1] = 300;
121  xyz1[2] = 350;
122  double deltax = 1;
123  double dt = 0;
124  while (std::abs(xyz1[0])<358.6){
125  geo::Vector_t fEfieldOffsets = SCE->GetEfieldOffsets({ xyz1[0], xyz1[1], xyz1[2] });
126  double EField = std::sqrt( (efield + efield*fEfieldOffsets.X())*(efield + efield*fEfieldOffsets.X()) +
127  (efield*fEfieldOffsets.Y()*efield*fEfieldOffsets.Y()) +
128  (efield*fEfieldOffsets.Z()*efield*fEfieldOffsets.Z()) );
129  double v = detProp.DriftVelocity(EField,
130  detProp.Temperature());
131  dt += deltax/v;
132  xyz1[0] += deltax*dir;
133  }
134  drifttimeint->SetBinContent(i, dt);
135 
136  geo::Vector_t fEfieldOffsets = SCE->GetEfieldOffsets({ xyz[0], xyz[1], xyz[2] });
137  double EField = std::sqrt( (efield + efield*fEfieldOffsets.X())*(efield + efield*fEfieldOffsets.X()) +
138  (efield*fEfieldOffsets.Y()*efield*fEfieldOffsets.Y()) +
139  (efield*fEfieldOffsets.Z()*efield*fEfieldOffsets.Z()) );
140  fEfield->SetBinContent(i, EField);
141  }
142 
143  for (int i = 1; i<=drifttimeave->GetNbinsX() - 1; ++i){
144  double x = drifttimeave->GetBinCenter(i);
145  if (x<0){
146  fdeltatnosce->SetBinContent(i, drifttimenosce->GetBinContent(i) - drifttimenosce->GetBinContent(i-1));
147  fdeltatave->SetBinContent(i, drifttimeave->GetBinContent(i) - drifttimeave->GetBinContent(i-1));
148  fdeltatint->SetBinContent(i, drifttimeint->GetBinContent(i) - drifttimeint->GetBinContent(i-1));
149  }
150  else{
151  fdeltatnosce->SetBinContent(i, drifttimenosce->GetBinContent(i) - drifttimenosce->GetBinContent(i+1));
152  fdeltatave->SetBinContent(i, drifttimeave->GetBinContent(i) - drifttimeave->GetBinContent(i+1));
153  fdeltatint->SetBinContent(i, drifttimeint->GetBinContent(i) - drifttimeint->GetBinContent(i+1));
154  }
155  fdriftvnosce->SetBinContent(i, fdeltatnosce->GetBinWidth(i)/fdeltatnosce->GetBinContent(i));
156  fdriftvave->SetBinContent(i, fdeltatave->GetBinWidth(i)/fdeltatave->GetBinContent(i));
157  fdriftvint->SetBinContent(i, fdeltatint->GetBinWidth(i)/fdeltatint->GetBinContent(i));
158  fefieldnosce->SetBinContent(i, gr->Eval(fdeltatnosce->GetBinWidth(i)/fdeltatnosce->GetBinContent(i)));
159  fefieldave->SetBinContent(i, gr->Eval(fdeltatave->GetBinWidth(i)/fdeltatave->GetBinContent(i)));
160  fefieldint->SetBinContent(i, gr->Eval(fdeltatint->GetBinWidth(i)/fdeltatint->GetBinContent(i)));
161  }
162 }
163 
165 {
167  drifttimenosce = tfs->make<TH1D>("drifttimenosce",";x (cm);Drift time (#mus)",120,-360,360);
168  drifttimeave = tfs->make<TH1D>("drifttimeave",";x (cm);Drift time (#mus)",120,-360,360);
169  drifttimeint = tfs->make<TH1D>("drifttimeint",";x (cm);Drift time (#mus)",120,-360,360);
170  fEfield = tfs->make<TH1D>("fEfield","E field; x (cm);E field (kV/cm)",120,-360,360);
171 
172  fdeltatnosce = tfs->make<TH1D>("fdeltatnosce",";x (cm);#Delta t (#mus)", 120, -360, 360);
173  fdeltatave = tfs->make<TH1D>("fdeltatave",";x (cm);#Delta t (#mus)", 120, -360, 360);
174  fdeltatint = tfs->make<TH1D>("fdeltatint",";x (cm);#Delta t (#mus)", 120, -360, 360);
175 
176  fdriftvnosce = tfs->make<TH1D>("fdriftvnosce",";x (cm);Drift velocity (cm/#mus)", 120, -360, 360);
177  fdriftvave = tfs->make<TH1D>("fdriftvave",";x (cm);Drift velocity (cm/#mus)", 120, -360, 360);
178  fdriftvint = tfs->make<TH1D>("fdriftvint",";x (cm);Drift velocity (cm/#mus)", 120, -360, 360);
179 
180  fefieldnosce = tfs->make<TH1D>("fefieldnosce",";x (cm);E field (kV/cm)", 120, -360, 360);
181  fefieldave = tfs->make<TH1D>("fefieldave",";x (cm);E field (kV/cm)", 120, -360, 360);
182  fefieldint = tfs->make<TH1D>("fefieldint",";x (cm);E field (kV/cm)", 120, -360, 360);
183 
184 }
185 
TH1D * drifttimenosce
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Vector_t
Type for representation of momenta in 3D space.
Definition: geo_vectors.h:164
string dir
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.h:25
TH1D * fdriftvnosce
TH1D * fdeltatave
TH1D * fefieldint
T abs(T value)
TH1D * fefieldave
const double e
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
TH1D * fdeltatint
std::void_t< T > n
TH1D * fdeltatnosce
TH1D * fefieldnosce
DriftAna & operator=(DriftAna const &)=delete
TH1D * fEfield
p
Definition: test.py:223
void analyze(art::Event const &e) override
DriftAna(fhicl::ParameterSet const &p)
void beginJob() override
TH1D * drifttimeint
TH1D * fdriftvave
TH1D * fdriftvint
TH1D * drifttimeave
list x
Definition: train.py:276
QTextStream & endl(QTextStream &s)