Changeset 3c40083 in git for external/Hector/H_Beam.cc
- Timestamp:
- Apr 16, 2014, 3:56:14 PM (11 years ago)
- Branches:
- ImprovedOutputFile, Timing, dual_readout, llp, master
- Children:
- 64a4950
- Parents:
- f6b9fec
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
external/Hector/H_Beam.cc
rf6b9fec r3c40083 1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * 2 * * 3 * --<--<-- A fast simulator --<--<-- * 4 * / --<--<-- of particle --<--<-- * 5 * ----HECTOR----< * 6 * \ -->-->-- transport through -->-->-- * 7 * -->-->-- generic beamlines -->-->-- * 8 * * 9 * JINST 2:P09005 (2007) * 10 * X Rouby, J de Favereau, K Piotrzkowski (CP3) * 11 * http://www.fynu.ucl.ac.be/hector.html * 12 * * 13 * Center for Cosmology, Particle Physics and Phenomenology * 14 * Universite catholique de Louvain * 15 * Louvain-la-Neuve, Belgium * 16 * * 17 * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 1 /* 2 ---- Hector the simulator ---- 3 A fast simulator of particles through generic beamlines. 4 J. de Favereau, X. Rouby ~~~ hector_devel@cp3.phys.ucl.ac.be 5 6 http://www.fynu.ucl.ac.be/hector.html 7 8 Centre de Physique des Particules et de Phénoménologie (CP3) 9 Université Catholique de Louvain (UCL) 10 */ 18 11 19 12 /// \file H_Beam.cc … … 22 15 23 16 // ROOT #includes 24 #include "TGraph.h"17 //#include "TGraph.h" 25 18 #include "TRandom.h" 26 19 … … 62 55 }; 63 56 64 void H_Beam::createBeamParticles(const unsigned int Number_of_particles, const double p_mass, const double p_charge, TRandom* r) { 57 void H_Beam::createBeamParticles(const unsigned int Number_of_particles) { 58 createBeamParticles(Number_of_particles,MP,QP); 59 } 60 61 void H_Beam::createBeamParticles(const unsigned int Number_of_particles, const double p_mass, const double p_charge) { 65 62 beamParticles.clear(); 66 63 Nparticles = (Number_of_particles<1) ? 1 : Number_of_particles; … … 69 66 p.setPosition(fx_ini,fy_ini,tx_ini,ty_ini,fs_ini); 70 67 p.setE(fe_ini); 71 p.smearPos(x_disp,y_disp ,r);72 p.smearAng(tx_disp,ty_disp ,r);73 p.smearE(e_disp ,r);74 p.smearS(s_disp ,r);68 p.smearPos(x_disp,y_disp); 69 p.smearAng(tx_disp,ty_disp); 70 p.smearE(e_disp); 71 p.smearS(s_disp); 75 72 if (VERBOSE) {if (i==0) cout << " x_ini , tx_ini " << p.getX() << " " << p.getTX() << endl;} 76 73 beamParticles.push_back(p); 77 74 } 78 75 } 79 80 //void H_Beam::particleGun(const unsigned int Number_of_particles, const float E_min=BE, const float E_max=BE, const float fs_min=0, const float fs_max=0, const float fx_min=0, const float fx_max=0, const float fy_min=0, const float fy_max=0, const float tx_min=-PI/2., const float tx_max=PI/2., const float ty_min=-PI/2., const float ty_max=PI/2., const float p_mass=MP, const double p_charge=QP) {81 void H_Beam::particleGun(const unsigned int Number_of_particles, const float E_min, const float E_max, const float fs_min, const float fs_max, const float fx_min, const float fx_max, const float fy_min, const float fy_max, const float tx_min, const float tx_max, const float ty_min, const float ty_max, const float p_mass, const double p_charge, const bool flat, TRandom* r) {82 beamParticles.clear();83 Nparticles = (Number_of_particles<2) ? 2 : Number_of_particles;84 float gx,gy,gs,gtx,gty,gE;85 for (unsigned int i=0; i<Nparticles; i++) {86 H_BeamParticle p(p_mass,p_charge);87 if (flat) {88 gx = r->Uniform(fx_min,fx_max);89 gy = r->Uniform(fy_min,fy_max);90 gs = r->Uniform(fs_min,fs_max);91 gtx = r->Uniform(tx_min,tx_max);92 gty = r->Uniform(ty_min,ty_max);93 gE = r->Uniform(E_min,E_max);94 } else {95 gx = r->Gaus((fx_min+fx_max)/2,(-fx_min+fx_max)/2);96 gy = r->Gaus((fy_min+fy_max)/2,(-fy_min+fy_max)/2);97 gs = r->Gaus((fs_min+fs_max)/2,(-fs_min+fs_max)/2);98 gtx = r->Gaus((tx_min+tx_max)/2,(-tx_min+tx_max)/2);99 gty = r->Gaus((ty_min+ty_max)/2,(-ty_min+ty_max)/2);100 gE = r->Gaus ((E_min+E_max)/2,(-E_min+E_max)/2);101 }102 p.setPosition(gx,gy,gtx,gty,gs);103 p.setE(gE);104 beamParticles.push_back(p);105 }106 return;107 }108 109 76 110 77 void H_Beam::createXScanningBeamParticles(const unsigned int Number_of_particles, const float fx_max) { … … 182 149 } 183 150 151 void H_Beam::computePath(const H_AbstractBeamLine * beamline) { 152 computePath(beamline,false); 153 } 154 184 155 /// Propagates the beam until a given s 185 156 void H_Beam::propagate(const float position) { … … 188 159 particle_i->propagate(position); 189 160 } 161 } 162 163 void H_Beam::emitGamma(const double gee, const double gq2) { 164 /// @param gee = \f$ E_{\gamma} \f$ is the photon energy 165 /// @param gq2 = \f$ Q^2 < 0 \f$ is virtuality of photon \f$ Q^{2} = E^{2}-\vec{k}^{2} \f$ 166 emitGamma(gee,gq2,0,2*PI); 190 167 } 191 168 … … 237 214 return EY2; 238 215 } 239 216 /* 240 217 TGraphErrors * H_Beam::getBetaX(const float length, const unsigned int number_of_points) { 241 218 /// @param length [m] … … 277 254 return betay; 278 255 } 256 */ 279 257 280 258 float H_Beam::getX(const float s, float& error_on_posx) { … … 313 291 } 314 292 315 vector<TVectorD> H_Beam::getStoppingElements(const H_AbstractBeamLine * beamline, vector<H_OpticalElement>& list, vector<int>& numb) { 316 317 vector<TVectorD> stop_positions; 293 void H_Beam::getStoppingElements(const H_AbstractBeamLine * beamline, vector<H_OpticalElement>& list, vector<int>& numb) { 318 294 vector<H_BeamParticle>::iterator particle_i; 319 295 vector<H_OpticalElement>::iterator element_i; … … 331 307 if(particle_i->stopped(beamline)) { 332 308 temp_el = *(particle_i->getStoppingElement()); 333 stop_positions.push_back(*(particle_i->getStopPosition()));334 309 if(list.size()==0) { 335 310 number=1; 336 311 list.push_back(temp_el); 337 312 numb.push_back(number); 338 339 313 } else { 340 314 for (element_i = list.begin(), n_i = numb.begin(); element_i < list.end(); element_i++, n_i++) { … … 356 330 } // if particle_i->stopped 357 331 }// for particle_i 358 return stop_positions;359 332 } // H_Beam::getStoppingElements 360 333 … … 379 352 } 380 353 381 std::ostream& operator<< (std::ostream& os, const H_Beam& be){354 void H_Beam::printProperties() const { 382 355 vector<H_BeamParticle>::const_iterator particle_i; 383 cout << "There are " << be.Nparticles << " in the beam." << endl; 384 for (particle_i = be.beamParticles.begin(); particle_i < be.beamParticles.end(); particle_i++) { 385 cout << *particle_i; 386 } 387 return os; 356 cout << "There are " << Nparticles << " in the beam." << endl; 357 for (particle_i = beamParticles.begin();particle_i < beamParticles.end(); particle_i++) { 358 particle_i->printProperties(); 359 } 388 360 } 389 361 … … 400 372 } 401 373 } // H_Beam::printStoppingElements 402 403 TH2F * H_Beam::drawAngleProfile(const float s) { 404 /// not a const method because does a propagate to s! 405 char title[50]; 406 sprintf(title,"Beam profile at %.2f m",s); 407 vector<H_BeamParticle>::iterator particle_i; 408 float xmax, xmin, ymax, ymin; 409 float xx, yy, xborder, yborder; 410 411 particle_i=beamParticles.begin(); 412 xmin = particle_i->getTX(); 413 xmax = particle_i->getTX(); 414 ymin = particle_i->getTY(); 415 ymax = particle_i->getTY(); 416 417 for (particle_i = beamParticles.begin(); particle_i < beamParticles.end(); particle_i++) { 418 particle_i->propagate(s); 419 xx = particle_i->getTX(); 420 yy = particle_i->getTY(); 421 422 xmax = xx>xmax ? xx : xmax; 423 ymax = yy>ymax ? yy : ymax; 424 xmin = xx<xmin ? xx : xmin; 425 ymin = yy<ymin ? yy : ymin; 426 } 427 428 // in order to avoid some drawing problems, when the beam divergence is null 429 if(!(xmax || xmin)) xmax +=0.1; 430 if(!(ymax || ymin)) xmax +=0.1; 431 432 if(xmax == xmin) xmax *= 1.1; 433 if(ymax == ymin) ymax *= 1.1; 434 435 xborder = (xmax-xmin)*0.2; 436 yborder = (ymax-ymin)*0.2; 437 438 xmax += xborder; 439 xmin -= xborder; 440 ymax += yborder; 441 ymin -= yborder; 442 443 TH2F * profile = new TH2F("profile",title,10000,xmin,xmax,1000,ymin,ymax); 444 for (particle_i = beamParticles.begin(); particle_i < beamParticles.end(); particle_i++) { 445 profile->Fill(particle_i->getTX(), particle_i->getTY()); 446 } 447 return profile; 448 } 449 450 374 /* 451 375 TH2F * H_Beam::drawProfile(const float s) { 452 376 /// not a const method because does a propagate to s! … … 475 399 476 400 // in order to avoid some drawing problems, when the beam divergence is null 477 if(!(xmax || xmin)) xmax +=0.1;478 if(!(ymax || ymin)) xmax +=0.1;479 480 401 if(xmax == xmin) xmax += 0.1; 481 402 if(ymax == ymin) ymax += 0.1; … … 494 415 } 495 416 return profile; 496 } 497 417 }*/ 418 /* 498 419 TMultiGraph * H_Beam::drawBeamX(const int color) const { 499 420 int mycolor = color; … … 519 440 return beam_profile_y; 520 441 } 442 */
Note:
See TracChangeset
for help on using the changeset viewer.