#include #include #include #include #include #include #include "TROOT.h" #include "TFile.h" #include "TH1D.h" #include "TProfile.h" #include "TRandom3.h" #include "JTools/JFunction1D_t.hh" #include "JTools/JFunctionalMap_t.hh" #include "JTools/JAbstractHistogram.hh" #include "JPhysics/JCDFTable.hh" #include "JPhysics/JPDFTypes.hh" #include "JPhysics/JPDFToolkit.hh" #include "JGeometry3D/JAngle3D.hh" #include "JROOT/JRootToolkit.hh" #include "JROOT/JManager.hh" #include "Jeep/JTimer.hh" #include "Jeep/JParser.hh" #include "Jeep/JMessage.hh" /** * \file * * Program to verify generation of arrival times of Cherenkov photons from a muon using tabulated CDF. * \author mdejong */ int main(int argc, char **argv) { using namespace std; using namespace JPP; typedef JAbstractHistogram JHistogram_t; vector inputFile; string outputFile; double E; double R; JAngle3D dir; int numberOfEvents; JHistogram_t histogram; int debug; try { JParser<> zap("Program to verify generation of arrival times of Cherenkov photons from a muon using tabulated CDF."); zap['f'] = make_field(inputFile); zap['o'] = make_field(outputFile) = ""; zap['E'] = make_field(E, "muon energy [GeV]") = 1.0; zap['R'] = make_field(R, "distance of approach [m]"); zap['D'] = make_field(dir, "(theta, phi) of PMT [rad]"); zap['n'] = make_field(numberOfEvents) = 0; zap['H'] = make_field(histogram, "histogram binning") = JHistogram_t(); zap['d'] = make_field(debug) = 2; zap(argc, argv); } catch(const exception& error) { FATAL(error.what() << endl); } typedef JHermiteSplineFunction1D_t JFunction1D_t; //typedef JSplineFunction1D_t JFunction1D_t; //typedef JPolint1Function1D_t JFunction1D_t; typedef JMAPLIST::maplist JMapList_t; typedef JCDFTable JCDF_t; const int N = inputFile.size(); int type[N]; JCDF_t cdf [N]; try { for (int i = 0; i != N; ++i) { NOTICE("loading input from file " << inputFile[i] << "... " << flush); type[i] = getPDFType(inputFile[i]); cdf [i].load(inputFile[i].c_str()); NOTICE("OK" << endl); } } catch(const JException& error) { FATAL(error.what() << endl); } if (outputFile == "") { for ( ; ; ) { double x; cout << "> " << flush; cin >> x; cout << " --> "; for (int i = 0; i != N; ++i) { try { double npe = cdf[i].getNPE (R, dir.getTheta(), dir.getPhi()); double t = cdf[i].getTime(R, dir.getTheta(), dir.getPhi(), x); if (is_bremsstrahlung(type[i])) { npe *= E; } else if (is_deltarays(type[i])) { npe *= getDeltaRaysFromMuon(E); } cout << ' ' << FIXED(6,2) << t << ' ' << FIXED(5,2) << npe; } catch(const exception& error) { ERROR(error.what() << endl); } } cout << endl; } return 0; } int function = 0; if (inputFile.size() == 1 && getPDFType(inputFile[0]) == DIRECT_LIGHT_FROM_MUON) { function = 1; } //const double z0 = -100.0; // [m] //const double t0 = (-z0 + R * getTanThetaC()) / C; // time [ns] const double t0 = 0.0; // time [ns] if (!histogram.is_valid()) { if (function == 1) { histogram = JHistogram_t(t0 - 20.0, t0 + 50.0); histogram.setBinWidth(0.5); } else { histogram = JHistogram_t(t0 - 20.0, t0 + 500.0); histogram.setBinWidth(2.0); } } TH1D h0("h0", NULL, histogram.getNumberOfBins(), histogram.getLowerLimit(), histogram.getUpperLimit()); h0.Sumw2(); JManager H1(new TH1D("h1[%]", NULL, 100000, 0.0, +1.0)); for (int i = 0; i != N; ++i) { for (int j = 1; j <= H1->GetNbinsX(); ++j) { try { const double x = H1->GetBinCenter(j); const double t = cdf[i].getTime(R, dir.getTheta(), dir.getPhi(), x); H1[i]->SetBinContent(j, t); } catch(const exception& error) { ERROR(error.what() << endl); } } } if (numberOfEvents > 0) { JTimer timer; timer.reset(); for (int counter = 0; counter != numberOfEvents; ++counter) { if (counter%1000== 0) { STATUS(setw(10) << counter << '\r'); DEBUG(endl); } timer.start(); for (int i = 0; i != N; ++i) { try { double npe = cdf[i].getNPE(R, dir.getTheta(), dir.getPhi()); if (is_bremsstrahlung(type[i])) { npe *= E; } else if (is_deltarays(type[i])) { npe *= getDeltaRaysFromMuon(E); } for (int j = gRandom->Poisson(npe); j != 0; --j) { const double x = gRandom->Rndm(); const double t = cdf[i].getTime(R, dir.getTheta(), dir.getPhi(), x); h0.Fill(t + t0); } } catch(const exception& error) { NOTICE(error.what() << endl); } } timer.stop(); } STATUS(endl); const double w = 1.0 / (double) numberOfEvents; if (debug > JEEP::status_t) { timer.print(cout, w); } // normalise histogram (dP/dt) for (int j = 1; j <= h0.GetNbinsX(); ++j) { const double y = h0.GetBinContent(j); const double z = h0.GetBinError (j); const double dx = h0.GetBinWidth (j); h0.SetBinContent(j, y / (dx*numberOfEvents)); h0.SetBinError (j, z / (dx*numberOfEvents)); } } TFile out(outputFile.c_str(), "recreate"); out << h0 << H1; out.Write(); out.Close(); }