// ---------------------------------------------------- // This file belongs to the ray tracing framework // for the use with Cherenkov detectors // // created 2007 //----------------------------------------------------- #include "PndDrcPhoton.h" #include "PndDrcOptMatAbs.h" #include "PndDrcOptDev.h" #include #include using std::cout; //using std::cerr; //using std::cin; using std::endl; #include using namespace TMath; #include // #include #include // system #include static TRandom grandi; // not a fine solution ? //---------------------------------------------------------------------- PndDrcPhoton::PndDrcPhoton() { fLambda = 0; fPosition = XYZPoint(0,0,0); fPositionOld = XYZPoint(0,0,0); fDirection = XYZPoint(0,0,0); fFate = Drc::kPhotFlying; fReflections = 0; fVerbosity = 0; fTime = 0; fDev = 0; fReflectionLimit = 1000; fPrintFlag = true; } //---------------------------------------------------------------------- void PndDrcPhoton::Copy(const PndDrcPhoton& ph) { fLambda = ph.fLambda; fPosition = ph.fPosition; fPositionOld = ph.fPositionOld; fDirection = ph.fDirection; fFate = ph.fFate; fReflections = ph.fReflections; fVerbosity = ph.fVerbosity; fTime = ph.fTime; fDev = ph.fDev; fReflectionLimit = ph.fReflectionLimit; fPrintFlag = ph.fPrintFlag; } //---------------------------------------------------------------------- PndDrcPhoton::PndDrcPhoton(const PndDrcPhoton& ph) { if (ph.fVerbosity>=1) cout<<" PndDrcPhoton::PndDrcPhoton" <<"(const PndDrcPhoton&)"<=1) cout<<" PndDrcPhoton::operator=" <<"(const PndDrcPhoton&) "<Radiator()) // no flat device { double n = (fDev->OptMaterial()).RefIndex(fLambda); double dndl = (fDev->OptMaterial()).RefIndexDeriv(fLambda); double len = sqrt((pos-fPosition).Mag2()); // mm double v_phase = 299.792/n; double v_group = v_phase * ( 1.0 - fLambda/n*dndl); double time = len/v_group; fTime += time; // pos in mm time in ns } fPositionOld = fPosition; fPosition = pos; }; //---------------------------------------------------------------------- bool PndDrcPhoton::Refract(XYZVector normal, double n1, double ex1, double n2, double ex2, bool fresnelFlag, double diffuseProb, bool test) { // cout << "VOLCHECK2: " << n1 << " " << ex1 << " " << n2 << " " << ex2 << " flag: " << fresnelFlag << " " << "diffuseProb: " << diffuseProb << endl; // fVerbosity =4; // cout << "******************** REFRACT ******************" << endl; static const double kEps = 1.0e-9; bool refract_flag; XYZVector dir1 = Direction(); // norm points outside. XYZVector norm = (dir1.Dot(normal)>0) ? normal : -normal; // // sin(alpha1) n2 // ----------- = -- (Snellius) // sin(alpha2) n1 // // alpaha1, alpha2 > 0 if (Verbosity()>=4) { cout<<" norm="<> angle.tmp"; system( shellString ); } bool reflect; if( fresnelFlag ) reflect = Fresnel( normal, n1, ex1, n2, ex2 ); else { if (sin(alpha1) * n1/n2 > 1) // only reflected for total internal reflection reflect = true; else reflect = false; } if( reflect ) // reflect photon { double random = grandi.Uniform(0.0,1.0); refract_flag = false; if( random <= diffuseProb && diffuseProb > 0 ) Diffuse( normal ); else Reflect( norm ); //ph.setDirection(dir1 - 2*(norm.Dot(dir1)*norm)); // new direction ??? if (Verbosity()>=4) cout<<" reflection"<=4) cout<<" alpha1,n1,n2 = "<=4) cout<<" x,alpha2 = "<=4) { cout<<" dir2 before unit = "<=4) { cout<<" refraction, brought it inside to " <0) ? normal : -normal; if (Verbosity()>=4) { cout<<" norm="< random.dat"); // ifstream in; // in.open( "random.dat" ); // double random; // if( !in ) // { // cout << "Error opening input stream" << endl; // return; // } // while ( true ) // { // in >> random; // if( !in.good() ) // break; // } // random = random/32767; random = grandi.Uniform(0.0,1.0); // cout << "refl. probability: " << reflProb << " random: " << random << " inci: " << (inci/TMath::Pi()*180) //<< endl; // << " refr: " << refr << " refl_s: " << refl_s << " refl_p: " << refl_p << endl; if (random <= reflProb ) { // cout << "fresnel reflected: " //<< endl; // << "refl. probability: " << reflProb << " random: " << random << " inci: " << (inci/TMath::Pi()*180) << endl; return true; } else return false; } //---------------------------------------------------------------------- int PndDrcPhoton::ColorNumber(double lambda) const { // the colors were taken from wikipedia entry about colors. if (lambda< 0.1) return 17; // grey if (lambda> 740) return 50; // dark red else if (lambda> 625) return 2; // red else if (lambda> 590) return 42; // orange else if (lambda> 565) return 5; // yellow else if (lambda> 520) return 3; // green else if (lambda> 500) return 7; // cyan else if (lambda> 450) return 4; // blue else if (lambda> 430) return 9; // indigo else if (lambda> 380) return 39; // violet return 33; // blue grey } //---------------------------------------------------------------------- void PndDrcPhoton::Print(fstream& stream) const { if (fPrintFlag) { stream<<" TPolyLine3D *l = new TPolyLine3D(2);"<SetPoint("<<0<<"," <SetPoint("<<1<<"," <SetLineColor("<Draw();"<