10 Rho(pset.
get<double>(
"Rho")),
15 X_correction_name(pset.
get<
std::
string>(
"X_correction")),
16 YZ_correction_name(pset.
get<
std::
string>(
"YZ_correction")),
17 E_field_correction_name(pset.
get<
std::
string>(
"E_field_correction")) {
29 std::vector<fhicl::ParameterSet> PlaneParameters =
30 pset.
get<std::vector<fhicl::ParameterSet>>(
"PlaneParameters");
32 for (
size_t i = 0; i < PlaneParameters.size(); ++i) {
33 size_t planeID = PlaneParameters[i].get<
size_t>(
"PlaneID");
34 norm_factors[planeID] = PlaneParameters[i].get<
double>(
"norm_factor");
35 calib_factors[planeID] = PlaneParameters[i].get<
double>(
"calib_factor");
40 std::string YZ_neg_name =
"correction_dqdx_ZvsY_negativeX_hist_" +
44 std::string YZ_pos_name =
"correction_dqdx_ZvsY_positiveX_hist_" +
71 size_t planeID,
double negativeZFix) {
73 std::vector<float> calibrated_dEdx;
77 return calibrated_dEdx;
83 bool found_plane =
false;
84 for(
size_t i = 0; i < caloVector.size(); ++i ){
85 unsigned int thePlane = caloVector.at(i).PlaneID().Plane;
86 if( thePlane == planeID ){
94 std::cout <<
"Could not find the correct plane in the calorimetry vector" <<
std::endl;
95 return calibrated_dEdx;
98 std::vector< float > dQdX = caloVector.at( calo_position).dQdx();
99 auto theXYZPoints = caloVector.at( calo_position).XYZ();
100 std::vector< float > resRange = caloVector.at( calo_position ).ResidualRange();
104 if( hits.size() == 0 ){
105 std::cout <<
"Got empty hits vector" <<
std::endl;
106 return calibrated_dEdx;
109 if (negativeZFix > 0.) {
110 return calibrated_dEdx;
113 double z_check = negativeZFix;
116 for(
size_t i = 0; i < dQdX.size(); ++i ){
117 float hit_x = theXYZPoints[i].X();
118 float hit_y = theXYZPoints[i].Y();
119 float hit_z = theXYZPoints[i].Z();
123 if (hit_y < 0. || hit_y > 600. || hit_z < z_check || hit_z > 695.) {
124 calibrated_dEdx.push_back(-999.);
129 if (negativeZFix < hit_z && hit_z < 0.) {
138 TH2F * YZ_hist = (hit_x < 0 ?
141 int YZ_bin = YZ_hist->FindBin(hit_z, hit_y);
142 double YZ_correction = YZ_hist->GetBinContent(YZ_bin);
145 float corrected_dq_dx = dQdX[i] * X_correction *
147 float scaled_corrected_dq_dx = corrected_dq_dx /
calib_factors[planeID];
149 double Efield =
tot_Ef( hit_x, hit_y, hit_z );
154 calibrated_dEdx.push_back( cal_de_dx );
158 return calibrated_dEdx;
164 size_t planeID,
double negativeZFix) {
165 std::vector<double> calibrated_dQdX;
169 return calibrated_dQdX;
174 size_t calo_position;
175 bool found_plane =
false;
176 for(
size_t i = 0; i < caloVector.size(); ++i ){
177 unsigned int thePlane = caloVector.at(i).PlaneID().Plane;
178 if( thePlane == planeID ){
186 std::cout <<
"Could not find the correct plane in the calorimetry vector" <<
std::endl;
187 return calibrated_dQdX;
190 std::vector< float > dQdX = caloVector.at( calo_position).dQdx();
191 auto theXYZPoints = caloVector.at( calo_position).XYZ();
195 if( hits.size() == 0 ){
196 std::cout <<
"Got empty hits vector" <<
std::endl;
197 return calibrated_dQdX;
200 if (negativeZFix > 0.) {
201 return calibrated_dQdX;
204 double z_check = negativeZFix;
207 for(
size_t i = 0; i < dQdX.size(); ++i ){
208 double hit_x = theXYZPoints[i].X();
209 double hit_y = theXYZPoints[i].Y();
210 double hit_z = theXYZPoints[i].Z();
214 if (hit_y < 0. || hit_y > 600. || hit_z < z_check || hit_z > 695.) {
215 calibrated_dQdX.push_back(-999.);
220 if (negativeZFix < hit_z && hit_z < 0.) {
228 TH2F * YZ_hist = (hit_x < 0 ?
231 int YZ_bin = YZ_hist->FindBin(hit_z, hit_y);
232 double YZ_correction = YZ_hist->GetBinContent(YZ_bin);
235 double corrected_dq_dx = dQdX[i] * X_correction *
237 double scaled_corrected_dq_dx = corrected_dq_dx /
calib_factors[planeID];
239 calibrated_dQdX.push_back(scaled_corrected_dq_dx);
241 return calibrated_dQdX;
245 return ( exp( dqdx * ( betap / ( Rho * Efield ) * Wion ) ) -alpha ) / ( betap / ( Rho*Efield ) );
251 double ex = 0.5 + 0.5 *
ex_pos->GetBinContent(
ex_pos->FindBin( x, y, z ) );
252 double ey = 0.5 *
ey_pos->GetBinContent(
ey_pos->FindBin( x, y, z ) );
253 double ez = 0.5 *
ez_pos->GetBinContent(
ez_pos->FindBin( x, y, z ) );
254 return sqrt( (ex*ex) + (ey*ey) + (ez*ez) );
257 double ex= 0.5 + 0.5 *
ex_neg->GetBinContent(
ex_neg->FindBin( x, y, z ) );
258 double ey= 0.5 *
ey_neg->GetBinContent(
ey_neg->FindBin( x, y, z ) );
259 double ez= 0.5 *
ez_neg->GetBinContent(
ez_neg->FindBin( x, y, z ) );
260 return sqrt( (ex*ex) + (ey*ey) + (ez*ez) );
268 size_t planeID,
double negativeZFix) {
269 std::vector<double> results;
274 size_t calo_position;
275 bool found_plane =
false;
276 for(
size_t i = 0; i < caloVector.size(); ++i ){
277 unsigned int thePlane = caloVector.at(i).PlaneID().Plane;
278 if( thePlane == planeID ){
286 std::cout <<
"Could not find the correct plane in the calorimetry vector" <<
std::endl;
290 auto theXYZPoints = caloVector.at( calo_position).XYZ();
294 if( hits.size() == 0 ){
295 std::cout <<
"Got empty hits vector" <<
std::endl;
299 if (negativeZFix > 0.) {
303 double z_check = negativeZFix;
305 for(
size_t i = 0; i < theXYZPoints.size(); ++i ){
306 float hit_x = theXYZPoints[i].X();
307 float hit_y = theXYZPoints[i].Y();
308 float hit_z = theXYZPoints[i].Z();
310 if( hit_y < 0. || hit_y > 600. || hit_z < z_check || hit_z > 695.) {
311 results.push_back(-999.);
316 if (negativeZFix < hit_z && hit_z < 0.) {
320 results.push_back(
tot_Ef( hit_x, hit_y, hit_z ));
328 double recomb_factor) {
332 size_t planeID = hit->
View();
338 double YZ_factor = 1.;
341 YZ_factor =
YZ_neg_hists[planeID]->GetBinContent(YZ_bin);
345 YZ_factor =
YZ_pos_hists[planeID]->GetBinContent(YZ_bin);
354 energy /= recomb_factor;
361 TFile * theFile = 0x0;
364 mf::LogInfo(
"protoana::ProtoDUNECalibration::OpenFile") <<
"File exists. Opening " <<
filename;
365 theFile =
new TFile(filename.c_str());
366 if (!theFile ||theFile->IsZombie() || !theFile->IsOpen()) {
373 mf::LogInfo(
"protoana::ProtoDUNECalibration::OpenFile") <<
"File does not exist here. Searching FW_SEARCH_PATH";
376 auto found = sp.find_file(filename, found_filename);
381 mf::LogInfo(
"protoana::ProtoDUNECalibration::OpenFile") <<
"Found file " << found_filename;
382 theFile =
new TFile(found_filename.c_str());
383 if (!theFile ||theFile->IsZombie() || !theFile->IsOpen()) {
386 throw cet::exception(
"ProtoDUNECalibration.cxx") <<
"Could not open " << found_filename;
ProtoDUNETrackUtils trackUtil
std::vector< double > GetEFieldVector(const recob::Track &track, art::Event const &evt, const std::string trackModule, const std::string caloModule, size_t planeID, double negativeZFix=0.)
std::string YZ_correction_name
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
std::map< size_t, TH2F * > YZ_neg_hists
std::vector< anab::Calorimetry > GetRecoTrackCalorimetry(const recob::Track &track, art::Event const &evt, const std::string trackModule, const std::string caloModule) const
Get the Calorimetry(s) from a given reco track.
float calc_dEdX(double dqdx, double betap, double Rho, double Efield, double Wion, double alpha)
float Integral() const
Integral under the calibrated signal waveform of the hit, in tick x ADC units.
geo::View_t View() const
View for the plane of the hit.
std::map< size_t, TH1F * > X_correction_hists
std::map< size_t, double > calib_factors
std::string E_field_correction_name
double HitToEnergy(const art::Ptr< recob::Hit > hit, double X, double Y, double Z, double recomb_factor=.6417)
std::vector< double > CalibratedQdX(const recob::Track &track, art::Event const &evt, const std::string trackModule, const std::string caloModule, size_t planeID, double negativeZFix)
T get(std::string const &key) const
TFile * YZ_correction_file
TFile * X_correction_file
Detector simulation of raw signals on wires.
std::map< size_t, TH2F * > YZ_pos_hists
const std::vector< const recob::Hit * > GetRecoTrackHitsFromPlane(const recob::Track &track, art::Event const &evt, const std::string trackModule, unsigned int planeID) const
Get the hits from a given reco track from a specific plane.
std::map< size_t, double > norm_factors
double tot_Ef(double, double, double)
bool file_exists(std::string const &qualified_filename)
std::string X_correction_name
auto const & get(AssnsNode< L, R, D > const &r)
std::vector< float > GetCalibratedCalorimetry(const recob::Track &track, art::Event const &evt, const std::string trackModule, const std::string caloModule, size_t planeID, double negativeZFix=0.)
TFile * OpenFile(const std::string filename)
std::string to_string(ModuleType const mt)
Track from a non-cascading particle.A recob::Track consists of a recob::TrackTrajectory, plus additional members relevant for a "fitted" track:
cet::coded_exception< error, detail::translate > exception
QTextStream & endl(QTextStream &s)