Example #1
0
void ParticleCreatorLatticeBCC::createParticles()
{    
  //RandomNumberGenerator m_rng;
  point_t box_size, spacing, offset;
  //    cuboid_t box;
  // offset due to wall particles
  //    point_t offset = ((Boundary*) m_parent) -> offset();
  double density;
  //    gsl_rng *rng;

//   size_t seed;

  /* We need the manager to check which group a particle has. */
  ManagerCell *manager = M_PHASE->manager();

  box_size = M_BOUNDARY->boundingBox().size();
  MSG_DEBUG("ParticleCreatorLatticeBCC::createParticles", "box_size=" << box_size);
  
  if (m_nlattice_points[0] == -1 &&
      m_nlattice_points[1] == -1 &&
      m_nlattice_points[2] == -1) 
  { 
    for (int i = 0; i < SPACE_DIMS; i++) {
      int n = (int) (box_size[i] / m_distance + 0.5);
      if (n < 1)
        n = 1;
      m_nlattice_points[i] = n;
    }
  }

  offset = M_BOUNDARY->boundingBox().corner1;

  initTransform();

//   if (m_randomize) {
//     seed = 2*getpid() + 1;
//   } else {
//     seed = 1;
//     MSG_INFO("ParticleCreatorLatticeBCC::randomizeVels", "randomize = no --> Numbers won't be random.");
//   }

  //    rng = gsl_rng_alloc(gsl_rng_default);

  //    gsl_rng_set(rng, seed);

  /*    MSG_DEBUG("ParticleCreatorLatticeBCC::createParticles", "Box size for particles: (" <<
  ((Boundary*) m_parent)->wallBound().x << ", " <<
  ((Boundary*) m_parent)->wallBound().y << ", " <<
  ((Boundary*) m_parent)->wallBound().z << ")");*/

  density = 1;
  for (int i = 0; i < SPACE_DIMS; i++) {/*all this SPECIFIC*/
    
 //     bool dd_is_defined = adjustBoxSize(point_t &size, bool_point_t& frameRCfront,  bool_point_t& frameRCend):dd_defined;
//    spacing[i] = box_size[i]/(m_nlattice_points[i]-1);
    if(m_dd_defined){ /*all this SPECIFIC*/
      spacing[i] = 2*m_distance/(sqrt(3.));
      offset[i] += spacing[i]/4;
      density *= spacing[i];
    }
    else{      /*all this SPECIFIC*/
      // FIXME: the setting of m_distance in this case is a little bit of rubbish and could produce bugs, because m_distance is no array, but spacing is
      int n = m_nlattice_points[i];
      spacing[i] = (double) ((box_size[i] / n ));
      
      m_distance = spacing[i]*sqrt(3.)/2;
      offset[i] += spacing[i]/4;
      density *= spacing[i];
    }
  
  }
    
  MSG_DEBUG("ParticleCreatorLatticeBCC::createParticles", "spacing = " << spacing);

  /* The density that is generated may differ from the density wished in the configuration
  file because the particle are equally spaced in space and have the same distance from
  the boundaries (of the cube, of course). That means the REAL density can still differ
  from this value */
  
  /*SPECIFIC*/
  density = 2/density;

  MSG_DEBUG("ParticleCreatorLatticeBCC::createParticles", "density = " << density);

  MSG_DEBUG("ParticleCreatorLatticeBCC::createParticles", "lattice = " << m_nlattice_points);

  /* All particles sit in a surrounding box of identical size. This is of course assuming the
  Boundary is exactly as big as returnMaxBoxSize proposes. */

  // create the function list for m_properties.unknown()
  // fList will be deleted at the end of this function	
  list<FunctionFixed> fl;
  fList(fl);
  
  // creation of FREE particles
  MSG_DEBUG("ParticleCreatorLatticeBCC::createParticles", "Creating free particles." << ", spacing = " << spacing << ", offset = " << offset << ", m_nlattice_points = " << m_nlattice_points);
                
  for (int i = 0; i < m_nlattice_points[0]; i++)
    for (int j = 0; j < m_nlattice_points[1]; j++)
      for (int k = 0; k < m_nlattice_points[2]; k++)
        for (int l = 0; l < 2; l++) {
    point_t pos = { { {  /*SPECIFIC*/
      i*spacing[0]+offset[0]+l*spacing[0]/2.,
      j*spacing[1]+offset[1]+l*spacing[1]/2.,
      k*spacing[2]+offset[2]+l*spacing[2]/2.
    } } };
    Cell *c;
    Particle p;
	
    p.r = pos;
    p.setColour(m_colour);

    transformPos(p);

    c = manager->findCell(p.r);

    if (c) {
      if (M_BOUNDARY->isInside(p.r)) {
        p.g = c->group();

        for (int w = 0; w < SPACE_DIMS; w++)
          p.v[w] = m_rng.uniform() - 0.5;
        
        // compute all from m_properties.unknown()
        computeUnknown(fl.begin(), p);

        m_particles[p.g].newEntry() = p;
      }
//       else MSG_DEBUG("ParticleCreatorLatticeBCC::createParticles", "NOT INSIDE: " << p.r << ", i = " << i << ", j = " << j << ", k = " << k << ", l = " << l);
    }
//     else MSG_DEBUG("ParticleCreatorLatticeBCC::createParticles", "NO CELL: " << p.r << ", i = " << i << ", j = " << j << ", k = " << k << ", l = " << l);
    
      }
      scaleVels();

  // next will call the one in ParticleCreatorFree and then ParticleCreatorFreeF::transformVel
      flushParticles();
}
Example #2
0
bool PickAllAtoms::matches( const Particle& particle ) const
{
	return !particle.isDummy();
}
Example #3
0
  void
  ISquareWell::runEvent(Particle& p1, Particle& p2, const IntEvent& iEvent) const
  {
    ++Sim->eventCount;

    double d = (_diameter->getProperty(p1.getID())
		+ _diameter->getProperty(p2.getID())) * 0.5;
    double d2 = d * d;

    double e = (_e->getProperty(p1.getID())
		+ _e->getProperty(p2.getID())) * 0.5;

    double l = (_lambda->getProperty(p1.getID())
		+ _lambda->getProperty(p2.getID())) * 0.5;
    double ld2 = d * l * d * l;

    double wd = (_wellDepth->getProperty(p1.getID())
		 + _wellDepth->getProperty(p2.getID())) * 0.5;
    switch (iEvent.getType())
      {
      case CORE:
	{
	  PairEventData retVal(Sim->dynamics->SmoothSpheresColl(iEvent, e, d2, CORE));
	  Sim->signalParticleUpdate(retVal);
	
	  Sim->ptrScheduler->fullUpdate(p1, p2);
	
	  BOOST_FOREACH(shared_ptr<OutputPlugin> & Ptr, Sim->outputPlugins)
	    Ptr->eventUpdate(iEvent, retVal);

	  break;
	}
      case STEP_IN:
	{
	  PairEventData retVal(Sim->dynamics->SphereWellEvent(iEvent, wd, ld2));
	
	  if (retVal.getType() != BOUNCE)
	    addToCaptureMap(p1, p2);      
	
	  Sim->ptrScheduler->fullUpdate(p1, p2);
	  Sim->signalParticleUpdate(retVal);
	
	  BOOST_FOREACH(shared_ptr<OutputPlugin> & Ptr, Sim->outputPlugins)
	    Ptr->eventUpdate(iEvent, retVal);


	  break;
	}
      case STEP_OUT:
	{
	  PairEventData retVal(Sim->dynamics->SphereWellEvent(iEvent, -wd, ld2));
	
	  if (retVal.getType() != BOUNCE)
	    removeFromCaptureMap(p1, p2);      

	  Sim->signalParticleUpdate(retVal);

	  Sim->ptrScheduler->fullUpdate(p1, p2);
	
	  BOOST_FOREACH(shared_ptr<OutputPlugin> & Ptr, Sim->outputPlugins)
	    Ptr->eventUpdate(iEvent, retVal);
	  break;
	}
      default:
	M_throw() << "Unknown collision type";
      } 
  }
Example #4
0
bool PickCoreBackbone::matches( const Particle& particle ) const
{
	return particle.isBackbone() && !particle.isHydrogen();
}
Example #5
0
bool PickRebuildRequired::matches( const Particle& particle ) const
{
	return particle.isRebuildRequired();
}
bool Localization::getSuccessParticle(Particle part1, Particle part2)
{
	// Return the Best (first) Particle.
	return part1.getBelief() > part2.getBelief();
}
Example #7
0
bool PickCAAtoms::matches( const Particle& particle ) const
{
	return particle.isCAlpha();
}
Example #8
0
void RunElasticCut(TString inputfile, TString outputfile, Int_t energy)
{
	TFile *input_rootfile = new TFile(inputfile);
	TTree* input_tree = (TTree*)input_rootfile->Get("events");

	ParticleTree output_tree(outputfile);

	Event *event = new Event();
	Particle *particle;
	input_tree->SetBranchAddress("event",&event);

	const Long64_t treeNentries = input_tree->GetEntries();
	Long64_t ev;
	Long_t particles_in = 0, particles_out = 0, events_out = 0;
	UInt_t part, Npa;

	Float_t p;

	for(ev=0; ev<treeNentries; ++ev)
	{
		if(!(ev%500))
			cout << "Event: " << ev << endl;

		input_tree->GetEntry(ev);
		Npa = event->GetNpa();

		//If, after cuts before, we left only with one positively charged particle with momentum close to beam momentum, I assume that it is a proton from beam which interacted elastically with target. I reject this proton and therefore whole event.
		if(Npa == 1)
		{
			particle = event->GetParticle(0);
			p = TMath::Sqrt(TMath::Power(particle->GetPx(),2)+TMath::Power(particle->GetPy(),2)+TMath::Power(particle->GetPz(),2));
			if((particle->isPositive()) && (p > energy - 3))
			{
				particles_in++;
				continue;
			}
		}

		particles_in+=Npa;
		events_out++;
		
		output_tree.BeginEvent();

		for(part=0; part<Npa; part++)
		{
			particle = event->GetParticle(part);
			
			output_tree.AddParticle(particle->GetCharge(),
					particle->GetBx(), particle->GetBy(),
					particle->GetPx(), particle->GetPy(), particle->GetPz(),
					particle->GetdEdx(), particle->GetdEdxVtpc1(), particle->GetdEdxVtpc2(), particle->GetdEdxMtpc(),
					particle->GetNdEdx(), particle->GetNdEdxVtpc1(), particle->GetNdEdxVtpc2(), particle->GetNdEdxMtpc());
		}
		output_tree.EndEvent();
		particles_out+=Npa;
	}

	output_tree.Close();
	input_rootfile->Close();

	cout << "Elastic cut summary\n------------" << endl
		<< "Events before cut: " << treeNentries  << endl
		<< "Events after cut: " << events_out << endl
		<< "Cutted events: " << (treeNentries-events_out) << endl
		<< "Ratio: " << ((Double_t)events_out/treeNentries) << "\n------------" << endl
		<< "Particles before cut: " << particles_in << endl
		<< "Particles after cut: " << particles_out << endl
		<< "Cutted particles: " << (particles_in-particles_out) << endl
		<< "Ratio: " << ((Double_t)particles_out/particles_in) << endl;
}
Example #9
0
//pT cut. Default value is 1.5 GeV/c. Which means it takes everything between 0 and 1.5.
//For ptcut values lower than 0, the cut will take everything between abs(ptcut) and infinity.
void RunPtCut(TString inputfile, TString outputfile, const Float_t ptcut=1.5)
{
	TFile *input_rootfile = new TFile(inputfile);
	TTree* input_tree = (TTree*)input_rootfile->Get("events");

	ParticleTree output_tree(outputfile);

	Event *event = new Event();
	Particle *particle;
	input_tree->SetBranchAddress("event",&event);

	const Long64_t treeNentries = input_tree->GetEntries();
	Long_t particles_in = 0, particles_out = 0;
	Long64_t ev;
	UInt_t Npa;
	UInt_t part;

	Double_t pt;

	for(ev=0; ev<treeNentries; ++ev)
	{
		if(!(ev%1000))
			cout << "Event: " << ev << endl;

		input_tree->GetEntry(ev);
		Npa = event->GetNpa();
		output_tree.BeginEvent();

		particles_in += Npa;
		for(part=0; part<Npa; part++)
		{
			particle = event->GetParticle(part);
			pt = TMath::Sqrt(TMath::Power(particle->GetPx(),2)+TMath::Power(particle->GetPy(),2));

			if(ptcut >= 0)
			{
				if(pt > ptcut)
					continue;
			}
			else if(ptcut < 0)
			{
				if(pt < TMath::Abs(ptcut))
					continue;
			}
			

			++particles_out;
			
			output_tree.AddParticle(particle->GetCharge(),
					particle->GetBx(), particle->GetBy(),
					particle->GetPx(), particle->GetPy(), particle->GetPz(),
					particle->GetdEdx(), particle->GetdEdxVtpc1(), particle->GetdEdxVtpc2(), particle->GetdEdxMtpc(),
					particle->GetNdEdx(), particle->GetNdEdxVtpc1(), particle->GetNdEdxVtpc2(), particle->GetNdEdxMtpc());
		}
		output_tree.EndEvent();
	}

	output_tree.Close();
	input_rootfile->Close();

	cout << "pT cut summary\n------------" << endl
		<< "Particles before cut: " << particles_in << endl
		<< "Particles after cut: " << particles_out << endl
		<< "Cutted particles: " << (particles_in-particles_out) << endl
		<< "Ratio: " << ((Double_t)particles_out/particles_in) << endl;
}
Example #10
0
//dEdx cut based on graphical cut defined in dEdxCut.cpp
void RunDedxCut(TString inputfile, TString outputfile, TString system, Int_t energy)
{
	cout << "Running dE/dx mode with energy " << energy << endl;
	TCutG* cutg = initialise_dedx_cutg(system, energy);
	cout << "Graphcut intialized" << endl;
	
	TFile *input_rootfile = new TFile(inputfile);
	TTree* input_tree = (TTree*)input_rootfile->Get("events");

	ParticleTree output_tree(outputfile);

	Event *event = new Event();
	Particle *particle;
	input_tree->SetBranchAddress("event",&event);

	const Long64_t treeNentries = input_tree->GetEntries();
	Long64_t ev;
	UInt_t Npa;
	UInt_t part;

	Float_t local_dedx;
	Float_t dedx_uppercut = 3.;

	if(!(system.CompareTo("PbPb")))
	{	
		if((energy == 158 ) || (energy == 160))
			dedx_uppercut = 1.65;
		else if(energy == 20)
			dedx_uppercut = 1.6;
	}

	float p;

	cout << "Cut dE/dx > " << dedx_uppercut << " applied" << endl;

	for(ev=0; ev<treeNentries; ++ev)
	{
		if(!(ev%500))
			cout << "Event: " << ev << endl;

		input_tree->GetEntry(ev);
		Npa = event->GetNpa();
		output_tree.BeginEvent();

		for(part=0; part<Npa; part++)
		{
			particle = event->GetParticle(part);
			p = TMath::Sqrt(TMath::Power(particle->GetPx(),2)+TMath::Power(particle->GetPy(),2)+TMath::Power(particle->GetPz(),2));
			local_dedx = choose_dedx(particle, system);
			if(cutg->IsInside(p,local_dedx))
				continue;

			if(local_dedx > dedx_uppercut)
				continue;

			output_tree.AddParticle(particle->GetCharge(),
					particle->GetBx(), particle->GetBy(),
					particle->GetPx(), particle->GetPy(), particle->GetPz(),
					particle->GetdEdx(), particle->GetdEdxVtpc1(), particle->GetdEdxVtpc2(), particle->GetdEdxMtpc(),
					particle->GetNdEdx(), particle->GetNdEdxVtpc1(), particle->GetNdEdxVtpc2(), particle->GetNdEdxMtpc());
		}
		output_tree.EndEvent();
	}

	output_tree.Close();
	input_rootfile->Close();
}
Example #11
0
//dEdx cut based on parametrized curves defined in "is_electron" function
void RunDedxCut2(TString inputfile, TString outputfile)
{
	TFile *input_rootfile = new TFile(inputfile);
	TTree* input_tree = (TTree*)input_rootfile->Get("events");

	ParticleTree output_tree(outputfile);

	Event *event = new Event();
	Particle *particle;
	input_tree->SetBranchAddress("event",&event);

	const Long64_t treeNentries = input_tree->GetEntries();
	Long_t particles_in = 0, particles_out = 0;
	Long64_t ev;
	UInt_t Npa;
	UInt_t part;

	//Float_t dedx_uppercut = 3.;

	float p;

	//cout << "Cut dE/dx > " << dedx_uppercut << " applied" << endl;

	for(ev=0; ev<treeNentries; ++ev)
	{
		if(!(ev%500))
			cout << "Event: " << ev << endl;

		input_tree->GetEntry(ev);
		Npa = event->GetNpa();
		output_tree.BeginEvent();

		particles_in += Npa;
		for(part=0; part<Npa; part++)
		{
			particle = event->GetParticle(part);
			p = TMath::Sqrt(TMath::Power(particle->GetPx(),2)+TMath::Power(particle->GetPy(),2)+TMath::Power(particle->GetPz(),2));

			if(is_electron(TMath::Log10(p),particle->GetdEdx()))
				continue;

			++particles_out;
			
			output_tree.AddParticle(particle->GetCharge(),
					particle->GetBx(), particle->GetBy(),
					particle->GetPx(), particle->GetPy(), particle->GetPz(),
					particle->GetdEdx(), particle->GetdEdxVtpc1(), particle->GetdEdxVtpc2(), particle->GetdEdxMtpc(),
					particle->GetNdEdx(), particle->GetNdEdxVtpc1(), particle->GetNdEdxVtpc2(), particle->GetNdEdxMtpc());
		}
		output_tree.EndEvent();
	}

	output_tree.Close();
	input_rootfile->Close();

	cout << "dEdx cut summary\n------------" << endl
		<< "Particles before cut: " << particles_in << endl
		<< "Particles after cut: " << particles_out << endl
		<< "Cutted particles: " << (particles_in-particles_out) << endl
		<< "Ratio: " << ((Double_t)particles_out/particles_in) << endl;
}
Example #12
0
//Multiplicity splitter to multiplicity bins analysis
void RunMultSplit(TString inputfile, TString outputfile, const TString mult_string)
{
	cout << "Running multiplicity splitter (" << mult_string << ") mode" << endl;
	const UInt_t multiplicity = atoi(mult_string);

	TFile *input_rootfile = new TFile(inputfile);
	TTree* input_tree = (TTree*)input_rootfile->Get("events");

//Three output files of all, positively and negatively charged particles
	ParticleTree output_tree_all(outputfile + "_all.root");
	ParticleTree output_tree_pos(outputfile + "_pos.root");
	ParticleTree output_tree_neg(outputfile + "_neg.root");

	Event *event = new Event();
	Particle *particle;
	input_tree->SetBranchAddress("event",&event);

	const Long64_t treeNentries = input_tree->GetEntries();
	Long64_t ev;
	UInt_t Npa;
	UInt_t Npos;
	UInt_t Nneg;
	UInt_t part;
	UInt_t all_count = 0;
	UInt_t pos_count = 0;
	UInt_t neg_count = 0;
	
	//cout << "Event\t\tAll\tPos\tNeg" << endl;

	for(ev=0; ev<treeNentries; ++ev)
	{
		if(!(ev%10000))
			cout << "Event: " << ev << endl;
		input_tree->GetEntry(ev);
		Npa = event->GetNpa();
		Npos = event->GetNpos();
		Nneg = event->GetNneg();

		if(Npa==multiplicity)
		{
			output_tree_all.BeginEvent();
			for(part=0; part<Npa; part++)
			{
				particle = event->GetParticle(part);
				output_tree_all.AddParticle(particle->GetCharge(),
						particle->GetBx(), particle->GetBy(),
						particle->GetPx(), particle->GetPy(), particle->GetPz(),
						particle->GetdEdx(), particle->GetdEdxVtpc1(), particle->GetdEdxVtpc2(), particle->GetdEdxMtpc(),
						particle->GetNdEdx(), particle->GetNdEdxVtpc1(), particle->GetNdEdxVtpc2(), particle->GetNdEdxMtpc());
			}
			++all_count;
			output_tree_all.EndEvent();
		}

		if(Npos==multiplicity)
		{
			output_tree_pos.BeginEvent();
			for(part=0; part<Npa; part++)
			{
				particle = event->GetParticle(part);

				if(!(particle->isPositive()))
					continue;

				output_tree_pos.AddParticle(particle->GetCharge(),
						particle->GetBx(), particle->GetBy(),
						particle->GetPx(), particle->GetPy(), particle->GetPz(),
						particle->GetdEdx(), particle->GetdEdxVtpc1(), particle->GetdEdxVtpc2(), particle->GetdEdxMtpc(),
						particle->GetNdEdx(), particle->GetNdEdxVtpc1(), particle->GetNdEdxVtpc2(), particle->GetNdEdxMtpc());
			}
			++pos_count;
			output_tree_pos.EndEvent();
		}

		if(Nneg==multiplicity)
		{
			output_tree_neg.BeginEvent();
			for(part=0; part<Npa; part++)
			{
				particle = event->GetParticle(part);

				if(particle->isPositive())
					continue;

				output_tree_neg.AddParticle(particle->GetCharge(),
						particle->GetBx(), particle->GetBy(),
						particle->GetPx(), particle->GetPy(), particle->GetPz(),
						particle->GetdEdx(), particle->GetdEdxVtpc1(), particle->GetdEdxVtpc2(), particle->GetdEdxMtpc(),
						particle->GetNdEdx(), particle->GetNdEdxVtpc1(), particle->GetNdEdxVtpc2(), particle->GetNdEdxMtpc());
			}
			++neg_count;
			output_tree_neg.EndEvent();
		}
		//cout << "\r" << ev << "\t\t" << all_count << "\t" << pos_count << "\t" << neg_count;
	}
	
	cout << "\nEvents\t\tAll\tPos\tNeg" << endl << ev << "\t\t" << all_count << "\t" << pos_count << "\t" << neg_count << endl;

	output_tree_all.Close();
	output_tree_pos.Close();
	output_tree_neg.Close();
	input_rootfile->Close();
}
Example #13
0
void RunAccCut(const TString inputfile, const TString outputfile, const int momentum)
{
	cout << "Running acceptance mode" << endl;

//Input ParticleTree file
	TFile *input_rootfile = new TFile(inputfile);
	TTree* input_tree = (TTree*)input_rootfile->Get("events");

//Output ParticleTree file
	ParticleTree output_tree(outputfile);

	Event *event = new Event();
	Particle *particle;
	input_tree->SetBranchAddress("event",&event);

	const Long64_t treeNentries = input_tree->GetEntries();
	Long64_t ev;
	UInt_t Npa;
	UInt_t part;

	AccCut acc_map("acceptance-map.root",momentum);

	float pt, E, p, y, angle;
	const float pion_mass = 0.13957018; //GeV/c^2
	const float nucleon_mass = 0.9389186795; //GeV/c^2
	const float beta = momentum/(TMath::Sqrt(momentum*momentum+nucleon_mass*nucleon_mass)+nucleon_mass);
	const float y_cms = 0.5*TMath::Log((1+beta)/(1-beta));
	
	cout << "beta = " << beta << endl << "y_cms=" << y_cms << endl;

	UInt_t particles_in = 0, particles_out = 0;

	for(ev=0; ev<treeNentries; ++ev)
	{
		if(!(ev%5000))
			cout << "Event: " << ev << endl;

			input_tree->GetEntry(ev);
			Npa = event->GetNpa();
			output_tree.BeginEvent();

			for(part=0; part<Npa; part++)
			{
				++particles_in;

				particle = event->GetParticle(part);
				pt = TMath::Sqrt(TMath::Power(particle->GetPx(),2)+TMath::Power(particle->GetPy(),2));
				p = TMath::Sqrt(TMath::Power(particle->GetPx(),2)+TMath::Power(particle->GetPy(),2)+TMath::Power(particle->GetPz(),2));
				E = TMath::Sqrt(pion_mass*pion_mass+p*p);
				y = 0.5*TMath::Log((E+particle->GetPz())/(E-particle->GetPz())) - y_cms;
				angle = TMath::ATan2(particle->GetPy(), particle->GetPx());

				if(acc_map.acceptanceCut(particle->GetCharge(),y,angle,pt))
				{
					output_tree.AddParticle(particle->GetCharge(),
					particle->GetBx(), particle->GetBy(),
					particle->GetPx(), particle->GetPy(), particle->GetPz(),
					particle->GetdEdx(), particle->GetdEdxVtpc1(), particle->GetdEdxVtpc2(), particle->GetdEdxMtpc(),
					particle->GetNdEdx(), particle->GetNdEdxVtpc1(), particle->GetNdEdxVtpc2(), particle->GetNdEdxMtpc());

					++particles_out;
				}
			}

			output_tree.EndEvent();
	}

	output_tree.Close();
	input_rootfile->Close();

	cout << "Acceptance map cut summary\n------------" << endl
		<< "Particles before cut: " << particles_in << endl
		<< "Particles after cut: " << particles_out << endl
		<< "Cutted particles: " << (particles_in-particles_out) << endl
		<< "Ratio: " << ((Double_t)particles_out/particles_in) << endl;
}
Example #14
0
  void 
  GCellsShearing::runEvent(const Particle& part, const double) const
  {
    Sim->dynamics.getLiouvillean().updateParticle(part);

    size_t oldCell(partCellData[part.getID()]);
    magnet::math::MortonNumber<3> oldCellCoords(oldCell);
    Vector oldCellPosition(calcPosition(oldCellCoords));

    //Determine the cell transition direction, its saved
    int cellDirectionInt(Sim->dynamics.getLiouvillean().
			 getSquareCellCollision3(part, oldCellPosition, cellDimension));
  
    size_t cellDirection = abs(cellDirectionInt) - 1;

    magnet::math::MortonNumber<3> endCell = oldCellCoords; //The ID of the cell the particle enters

    if ((cellDirection == 1) &&
	(oldCellCoords[1] == ((cellDirectionInt < 0) ? 0 : (cellCount[1] - 1))))
      {
	//We're wrapping in the y direction, we have to compute
	//which cell its entering
	endCell[1] = (endCell[1].getRealValue() + cellCount[1] 
		      + ((cellDirectionInt < 0) ?  -1 : 1)) % cellCount[1];

	//Remove the old x contribution
	//Calculate the final x value
	//Time till transition, assumes the particle is up to date
	double dt = Sim->dynamics.getLiouvillean().getSquareCellCollision2(part, oldCellPosition, cellDimension);
     
	//Predict the position of the particle in the x dimension
	Sim->dynamics.getLiouvillean().advanceUpdateParticle(part, dt);
	Vector tmpPos = part.getPosition();
	//This rewinds the particle again
	Sim->dynamics.getLiouvillean().updateParticle(part);

	//Adding this extra half cell ensures we get into the next
	//simulation image, to calculate the position of the new cell
	tmpPos[1] += ((cellDirectionInt < 0) ? -0.5 : 0.5) * cellDimension[1];

	//Determine the x position (in cell coords) of the particle and
	//add it to the endCellID
	Sim->dynamics.BCs().applyBC(tmpPos, dt);
      
	endCell[0] = getCellID(tmpPos)[0];

	removeFromCell(part.getID());
	addToCell(part.getID(), endCell.getMortonNum());
      
	//Get rid of the virtual event that is next, update is delayed till
	//after all events are added
	Sim->ptrScheduler->popNextEvent();

	//Check the entire neighbourhood, could check just the new
	//neighbours and the extra LE neighbourhood strip but its a lot
	//of code
	if (isUsedInScheduler)
	  getParticleNeighbourhood(part, magnet::function::MakeDelegate(&(*Sim->ptrScheduler), 
									&Scheduler::addInteractionEvent));
      
	BOOST_FOREACH(const nbHoodSlot& nbs, sigNewNeighbourNotify)
	  getParticleNeighbourhood(part, nbs.second);
      }
Example #15
0
Particle *Particle::addEffect(const std::string &particleEffectFile,
                              int pixelX, int pixelY, int rotation)
{
    Particle *newParticle = NULL;

    XML::Document doc(particleEffectFile);
    xmlNodePtr rootNode = doc.rootNode();

    if (!rootNode || !xmlStrEqual(rootNode->name, BAD_CAST "effect"))
    {
        logger->log("Error loading particle: %s", particleEffectFile.c_str());
        return NULL;
    }

    ResourceManager *resman = ResourceManager::getInstance();

    // Parse particles
    for_each_xml_child_node(effectChildNode, rootNode)
    {
        // We're only interested in particles
        if (!xmlStrEqual(effectChildNode->name, BAD_CAST "particle"))
            continue;

        // Determine the exact particle type
        xmlNodePtr node;

        // Animation
        if ((node = XML::findFirstChildByName(effectChildNode, "animation")))
        {
            newParticle = new AnimationParticle(mMap, node);
        }
        // Rotational
        else if ((node = XML::findFirstChildByName(effectChildNode, "rotation")))
        {
            newParticle = new RotationalParticle(mMap, node);
        }
        // Image
        else if ((node = XML::findFirstChildByName(effectChildNode, "image")))
        {
            Image *img= resman->getImage((const char*)
                    node->xmlChildrenNode->content);

            newParticle = new ImageParticle(mMap, img);
        }
        // Other
        else
        {
            newParticle = new Particle(mMap);
        }

        // Read and set the basic properties of the particle
        float offsetX = XML::getFloatProperty(effectChildNode, "position-x", 0);
        float offsetY = XML::getFloatProperty(effectChildNode, "position-y", 0);
        float offsetZ = XML::getFloatProperty(effectChildNode, "position-z", 0);
        Vector position (mPos.x + (float)pixelX + offsetX,
                         mPos.y + (float)pixelY + offsetY,
                         mPos.z + offsetZ);
        newParticle->moveTo(position);

        int lifetime = XML::getProperty(effectChildNode, "lifetime", -1);
        newParticle->setLifetime(lifetime);

        // Look for additional emitters for this particle
        for_each_xml_child_node(emitterNode, effectChildNode)
        {
            if (!xmlStrEqual(emitterNode->name, BAD_CAST "emitter"))
                continue;

            ParticleEmitter *newEmitter;
            newEmitter = new ParticleEmitter(emitterNode, newParticle, mMap,
                                             rotation);
            newParticle->addEmitter(newEmitter);
        }

        mChildParticles.push_back(newParticle);
    }

    return newParticle;
}
Example #16
0
//Particle Population Matrix cut
void RunPPMCut(TString inputfile, TString outputfile, TString system, TString energy)
{
	cout << "Running particle population matrix mode" << endl;

	TFile *input_rootfile = new TFile(inputfile);
	TTree* input_tree = (TTree*)input_rootfile->Get("events");

	ParticleTree output_tree(outputfile);

	Event *event = new Event();
	Particle *particle;
	input_tree->SetBranchAddress("event",&event);

	const Long64_t treeNentries = input_tree->GetEntries();
	Long64_t ev;
	UInt_t Npa;
	UInt_t part;
	UInt_t particles_in, particles_out;

//PPMCut class defined in PPMCut.h
	PPMCut partpopmatrix("PartPopMatrix.root",system, energy);

	float pt, p, angle;

	particles_in = particles_out = 0;

	for(ev=0; ev<treeNentries; ++ev)
	{
		if(!(ev%5000))
			cout << "Event: " << ev << endl;

			input_tree->GetEntry(ev);
			Npa = event->GetNpa();
			output_tree.BeginEvent();

			particles_in += Npa;

			for(part=0; part<Npa; part++)
			{
				particle = event->GetParticle(part);
				pt = TMath::Sqrt(TMath::Power(particle->GetPx(),2)+TMath::Power(particle->GetPy(),2));
				p = TMath::Sqrt(TMath::Power(particle->GetPx(),2)+TMath::Power(particle->GetPy(),2)+TMath::Power(particle->GetPz(),2));
				angle = TMath::ATan2(particle->GetPy(), particle->GetPx());

//The cut itself
				if(partpopmatrix.PartPopMatrixCut(particle->GetCharge(),p,pt,angle))
				{
					output_tree.AddParticle(particle->GetCharge(),
					particle->GetBx(), particle->GetBy(),
					particle->GetPx(), particle->GetPy(), particle->GetPz(),
					particle->GetdEdx(), particle->GetdEdxVtpc1(), particle->GetdEdxVtpc2(), particle->GetdEdxMtpc(),
					particle->GetNdEdx(), particle->GetNdEdxVtpc1(), particle->GetNdEdxVtpc2(), particle->GetNdEdxMtpc());

					particles_out++;
				}
			}

			output_tree.EndEvent();
	}

	output_tree.Close();
	input_rootfile->Close();

	cout << "Particle population matrix cut summary\n------------" << endl
		<< "Particles before cut: " << particles_in << endl
		<< "Particles after cut: " << particles_out << endl
		<< "Cutted particles: " << (particles_in-particles_out) << endl
		<< "Ratio: " << ((Double_t)particles_out/particles_in) << endl;
}
Example #17
0
void Seaweed::animate(int reset)
{
	if(reset)
	{
		particles = vector<Particle *>();
		springs = vector<Spring *>();
		 createSystemScene();
	}
	//======== 1. Compute all forces
	// map to accumulate the forces to apply on each particle
	map<const Particle *, Vec> forces;
	
	// weights
	vector<Particle *>::iterator itP;
	for (itP = particles.begin(); itP != particles.end(); ++itP) {
		Particle *p = *itP;
		forces[p] = gravity * p->getMass();
		forces[p] += push * p->getRadius() * p->getRadius()* 3.14 * 103.2 ;
		if(p->getVelocity().y < 0)
			forces[p] -= wave;
		else
			forces[p] -= wave;
		forces[p] -= mediumViscosity * p->getVelocity(); // Damping force applied by the viscosity
		// viscosity is applied against the velocity and to all particles
	}
	// damped springs
	vector<Spring *>::iterator itS;
	for (itS = springs.begin(); itS != springs.end(); ++itS) {
		Spring *s = *itS;
		Vec f12 = s->getCurrentForce();
		forces[s->getParticle1()] += f12;
		forces[s->getParticle2()] -= f12; // opposite force
	}
	
	
	//======== 2. Integration scheme
	// Here the velocity is changed... But... Need it to be cyclic
	
	for (itP = particles.begin(); itP != particles.end(); ++itP) {
		Particle *p = *itP;
		p->incrVelocity(forces[p] * p->getInvMass() * dt);
	}
	
	// update particles positions
	for (itP = particles.begin(); itP != particles.end(); ++itP) {
		Particle *p = *itP;
		// q = q + dt * v, explicit euler.
		
		Vec origin = Vec(0.0,0.30,0.0);
		Vec upper = Vec(1.0,0.70,2.0);
		if( ( /*->getPosition().x < origin.x || */p->getPosition().y < origin.y /*|| p->getPosition().z < origin.z */) ||
			(/*p->getPosition().x > upper.x || */p->getPosition().y > upper.y/* || p->getPosition().z > upper.z */) )
		{
			float dist = ( p->getPosition().y - origin.y)*( p->getPosition().y - origin.y);
			p->incrVelocity(-p->getVelocity() * resist * dist);
			//Vec veltmp = - p->getVelocity() * resist;
			//p->setVelocity(veltmp);
		}
		p->incrPosition(dt * p->getVelocity());
		
	}
	
	
	//======== 3. Collisions
		//TO DO: discuss multi-collisions and order!
		for (itP = particles.begin(); itP != particles.end(); ++itP) {
			collisionParticleGround(*itP);
		}
		bool collide = true;
		while(collide)
		{
			collide = false;
			for(unsigned int i = 1; i < particles.size(); ++i) {
				Particle *p1 = particles[i - 1];
				Particle *p2 = particles[i];
				collide |= collisionParticleParticle(p1, p2);
			}
		}
}
Example #18
0
double FitRestraint::unprotected_evaluate(DerivativeAccumulator *accum) const {
  Float escore;
  bool calc_deriv = accum ? true : false;
  IMP_LOG_VERBOSE("before resample\n");
  resample();
  IMP_LOG_VERBOSE("after resample\n");
  /*
  static int kkk=0;
  std::stringstream name;
  name<<"resample."<<kkk<<".mrc";
  em::write_map(model_dens_map_,name.str());
  std::stringstream name1;
  name1<<"resample."<<kkk<<".pdb";
  std::ofstream f (name1.str().c_str());
  for(int i=0;i<all_ps_.size();i++){
    f<<atom::get_pdb_string(core::XYZ(all_ps_[i]).get_coordinates(),i,
                            atom::AT_CA,atom::ALA,'A',i);
  }
  f.close();
  kkk=kkk+1;
  */
  // In many optimization scenarios particles are can be found outside of
  // the density. When all particles are outside of the density the
  // cross-correlation score is zero and the derivatives are meaningless.
  // To handle these cases we return a huge score and do not calculate
  // derivatives. The CG algorithm should adjust accordingly.
  // Another option [CURRENTLY NOT IMPLEMENTED] is to guide the particles
  // back into the
  // density by using a simple distance restraint between the centroids
  // of the density and the particles. Once the particles are back
  //(at least partly) in the density, the CC score is back on.
  // To smooth the score,
  // we start considering centroids distance once 80% of the particles
  // are outside of the density.
  escore = CoarseCC::calc_score(
      const_cast<DensityMap *>(target_dens_map_.get()),
      const_cast<SampledDensityMap *>(model_dens_map_.get()), scalefac_, true,
      false, norm_factors_);
  if (calc_deriv) {
    // calculate the derivatives for non rigid bodies
    IMP_LOG_VERBOSE("Going to calc derivatives for none_rb_model_dens_map_\n");
    const_cast<FitRestraint *>(this)->dv_ =
        CoarseCC::calc_derivatives(target_dens_map_, model_dens_map_, all_ps_,
                                   weight_key_, kernel_params_, scalefac_, dv_);

    IMP_LOG_VERBOSE(
        "Finish calculating derivatives for none_rb_model_dens_map_\n");
  }
  Float score = escore;
  // now update the derivatives
  FloatKeys xyz_keys = IMP::core::XYZR::get_xyz_keys();
  if (calc_deriv) {
    for (unsigned int i = 0; i < all_ps_.size(); i++) {
      Particle *p = all_ps_[i];
      p->add_to_derivative(xyz_keys[0], dv_[i][0], *accum);
      p->add_to_derivative(xyz_keys[1], dv_[i][1], *accum);
      p->add_to_derivative(xyz_keys[2], dv_[i][2], *accum);
    }
  }
  IMP_LOG_VERBOSE("Finish calculating fit restraint with emscore of : "
                  << score << std::endl);
  //  std::cout<< "Finish calculating fit restraint with emscore of : "
  //         << score << std::endl;
  return score;
}
 inline
 typename boost::enable_if<
   typename md::particle::meta::is_rotatable<Particle>::type,
 void>::type decrease_global_torque(Particle& particle, Torque const& tau)
 { particle.global_torque() -= tau; }
Particle::Particle(const Particle& particle) 
 : m_position(particle.getPosition()), m_velocity(particle.getVelocity()), m_acceleration(particle.getAcceleration()), m_forceAccumulated(particle.getForceAccumulated()), 
   m_normal(particle.getNormal()), m_damping(particle.getDamping()), m_inverseMass(particle.getInverseMass()), m_stationary(particle.getStationary())
{
}
Example #21
0
bool PickBackbone::matches( const Particle& particle ) const
{
	return particle.isBackbone();
}
void LocalizationManager::update(double deltaX, double deltaY, double deltaYaw, LaserProxy* laser)
{

	Particle* current;
	list<Particle*> newParticales;
	list<Particle*> delParticales;
	deltaX 	 *= ConfigurationManager::getInstance()->getDMapRes();
	deltaY 	 *= ConfigurationManager::getInstance()->getDMapRes();
	for (list<Particle*>::iterator it = this->_particlesList.begin(); it != this->_particlesList.end(); ){
		current = *it;
		//cout << " x = " << current->getX() / 4 << " y = " << current->getY() / 4 << " yaw = " << current->getYaw() << " bel " << current->getBelief()<< endl ;
		current->update(deltaX,deltaY,deltaYaw,laser);
		//cout <<" check create new particles. bel = " << current->getBelief() << endl;
		if (current->getBelief() > 0.7){
			//cout << "create!" << endl;
			//	cout << "Create from Particle (" << current->getX()<< "," << current->getY() << "," << current->getYaw() << "," << current->getBelief() << ")" << endl;
			createNewParticles(current, newParticales);
			it++;
			//cout << "belief = " << current->getBelief() << endl;
		}
		else if (current->getBelief() <= 0.3){

	        it = this->_particlesList.erase(it);
	        delParticales.push_back(current);
		} else
		{
			it++;
		}

	}
	//cout << "there are " << newIndx << " new particles" << endl;
	/*if (!_particlesList.empty()){
		this->map->printParticle(this->convertParticleList());
	}*/
	/*if (_particlesList.size() < 20){
		cout << "less then 20!! " << _particlesList.size() << endl;
		//cout << "add paarticles" << endl;
		delParticales.sort(compare_particle);
		while (_particlesList.size() < 20 && delParticales.size() > 0)
		{
			Particle *addPar = delParticales.front();
			delParticales.pop_front();
			_particlesList.push_back(addPar);
		}
		this->map->printParticle(this->convertParticleList());

	}*/
	bool check = false;
	if (_particlesList.empty()){
			delParticales.sort(compare_particle);

			Particle *addPar = delParticales.front();
			delParticales.pop_front();
			Particle* p = new Particle(addPar->getX(),addPar->getY(),addPar->getYaw(),1,addPar->getMap());
			createNewParticles(p, newParticales);
			check = true;

	}

	_particlesList.splice(_particlesList.end(),newParticales);

	if (check){
		//this->map->printParticle(this->convertParticleList());
	}

	if (_particlesList.size() > 200)
	{
		_particlesList.sort(compare_particle);
		while(_particlesList.size() != 200)
		{
			_particlesList.pop_back();
		}
	}
	while(!delParticales.empty()){
		Particle *dellPar = delParticales.front();
		delParticales.pop_front();
		delete dellPar;
	}
}
Example #23
0
bool PickHydrogens::matches( const Particle& particle ) const
{
	return particle.isHydrogen();
}
Example #24
0
void Emitter::update(float duration) {
    if (!alive) {
        return;
    }

    pos = pos + speed * duration;

    while (!particles.empty() && particles.front()->life <= 0) {
        pPool->recycle(particles.front());
        particles.pop_front();
    }

    for (Particle*& it : particles) {
        it->colorIndex = (1 - it->life / plife) * 256;
        if (it->colorIndex < 0) {
            it->colorIndex = 0;
        } else if (it->colorIndex >= colorIndexLength) {
            it->colorIndex = colorIndexLength - 1;
        }
        it->pos = it->pos + it->dir * duration;
        it->pos.x += randF() * it->randLevel * duration;
        it->pos.y += randF() * it->randLevel * duration;
        it->pos.z += randF() * it->randLevel * duration;
        if (forceType & Lorentz) {
            Vector v = it->dir * mag;
            it->pos = it->pos + v;
        }
        if (forceType & Gravity) {
            it->dir = it->dir + force * duration;
        }
        if (forceType & Center) {
            Vector t = center - it->pos;
            t.unit();
            it->dir = it->dir + t * centripetal * duration;
        } else if (forceType & Z_Axle) {
            float l = sqrt(it->pos.x * it->pos.x + it->pos.y * it->pos.y);
            Vector t = {0, 0, 0};
            if (l > 0) {
                t.x = it->pos.x / l;
                t.y = it->pos.y / l;
            }
            it->dir = it->dir + t * centripetal * duration;
        }


        it->life -= duration;
    }

    if (life > 0) {
        for (int i = 0; i < emitsPerFrame; i++) {

            float _yaw, _pitch, _speed;
            //      Vector _speed = {0, 0, 0};
            Vector _particleSpeed =  Vector::RotationToDirection(yaw + yawVar * randF(), pitch + pitchVar * randF()) * particleSpeed ;

            Particle* p = pPool->getParticle();
            p->init(pos, 4, _particleSpeed , plife + plifeVar * randF());

            particles.push_back(p);
        }
        life -= duration;
    } else {
        if (particles.empty()) {
            alive = false;
        }
    }
	if (g2e||forceType & Gravity) {
		speed = speed + force * duration;
	}

}
Example #25
0
bool PickSidechains::matches( const Particle& particle ) const
{
	return !particle.isBackbone();
}
	Constraint(Particle *p1, Particle *p2) :  p1(p1),p2(p2)
	{
		Vec3 vec = p1->getPos()-p2->getPos();
		rest_distance = vec.length();
	}
Example #27
0
bool PickHeavyAtoms::matches( const Particle& particle ) const
{
	return !particle.isHydrogen() && !particle.isDummy();
}
int main(int argc, char *args[]) {
    
    PetscErrorCode ierr;
    ierr=PetscInitialize(&argc,&args,(char *) 0, help); CHKERRQ(ierr);
    { 
    //  Get MPI rank
    int rank; MPI_Comm_rank(PETSC_COMM_WORLD, &rank);

    // Read in configuration file
    char configfn[200]; 
    PetscBool flg; 

    // See if we need help
    PetscOptionsHasName(NULL, "-help", &flg);
    if (flg) exit(0);
    PetscOptionsGetString(NULL, "-configfn", configfn, 200, &flg);
    if (!flg) RAISE_ERR(99,"Specify configuration file");
    // Read in parameters
    LasDamasParams pars(string(configfn), "LDzspace"); 

    /****************************
     * Define seeds
     ****************************/
    int const_seed=2147; int randompart_seed=8271;

    /******************************************
     * Define the mask and delta
     ******************************************/
    Mask3D dummymask;
    Particle pm;
    pm.AsciiReadWeightedSerial(pars.mask.fn.c_str());
    VecShift(pm.px, pars.recon.origin[0]);
    VecShift(pm.py, pars.recon.origin[1]);
    VecShift(pm.pz, pars.recon.origin[2]);
    Delta del1(pars.Ngrid, pars.Lbox, 1, pars.mask.thresh, dummymask, pm, pars.recon.smooth);
   
    /********************************************
     * Read in pk prior 
     *******************************************/
    vector<double> kvec, pkvec;
    int nk;
    // Rank 0 job reads in pk function and broadcasts to everyone
    if (rank == 0) {
      double k1, pk1;
      double bias2 = pars.pkprior.bias * pars.pkprior.bias;
      ifstream fp(pars.pkprior.fn.c_str());
      do {
        fp >> k1 >> pk1;
        if (fp) {
          kvec.push_back(k1); 
          pkvec.push_back(bias2*pk1 + pars.pkprior.noise);
        }  
      } while (fp);
      fp.close();
      nk = kvec.size();
    }
    MPI_Bcast(&nk, 1, MPI_INT, 0, PETSC_COMM_WORLD);
    if (rank !=0) {kvec.resize(nk, 0.0); pkvec.resize(nk, 0.0);}
    MPI_Bcast(&kvec[0], nk, MPI_DOUBLE, 0, PETSC_COMM_WORLD);
    MPI_Bcast(&pkvec[0], nk, MPI_DOUBLE, 0, PETSC_COMM_WORLD);
    PetscPrintf(PETSC_COMM_WORLD, "%d lines read in from %s...\n",nk, pars.pkprior.fn.c_str());

    // Define the potential solver 
    PotentialSolve psolve(pars.Ngrid, pars.Lbox, pars.recon.maxit);
    if (pars.recon.planeparallel == 1) {
      psolve.SetupOperator(CARTPBC, pars.recon.beta);
      PetscPrintf(PETSC_COMM_WORLD, "Using the plane parallel approximation\n");
    } else {
      psolve.SetupOperator(RADIAL, pars.recon.beta, pars.recon.origin);
      PetscPrintf(PETSC_COMM_WORLD, "Using the wide angle approximation\n");
    }

    // Loop over files
    list<LasDamasParams::fn>::iterator files;
    for (files = pars.fnlist.begin(); files !=pars.fnlist.end(); ++files) 
    {
      /* ******************************
       * First we get the various options and print out useful information 
       * ********************************/
      ostringstream hdr;
      hdr << "# Input data file is " << files->indata << endl; 
      hdr << "# Output data file is " << files->outdata << endl;
      hdr << "# Input random file is " << files->inrand << endl; 
      hdr << "# Output rand file is " << files->outrand << endl;
      hdr << "# Ngrid=" << setw(5) << pars.Ngrid << endl;
      hdr << "# boxsize=" << setw(8) << fixed << setprecision(2) << pars.Lbox << endl;
      hdr << "# bias=" << setw(8) << setprecision(2) << pars.recon.bias << endl;
      hdr << "# fval=" << setw(8) << setprecision(2) << pars.recon.fval << endl;
      hdr << "# beta=" << setw(8) << setprecision(2) << pars.recon.beta << endl;
      hdr << "# smooth=" << setw(8) << setprecision(2) << pars.recon.smooth << endl;
      hdr << "# Mask threshold =" << pars.mask.thresh << endl;
      hdr << "# Mask random file =" << pars.mask.fn << endl;
      hdr << "# " << "Origin at " << setprecision(3) << pars.recon.origin[0] 
                                  << ", " << pars.recon.origin[1] << ", " 
                                  << pars.recon.origin[2] << endl;
      PetscPrintf(PETSC_COMM_WORLD, (hdr.str()).c_str()); 
      
      
      /****************************************
       * Read in the particle data here and slab decompose
       ****************************************/
      Particle pp, pr;
      DensityGrid dg(pars.Ngrid, pars.Lbox);
      pp.AsciiReadWeightedSerial(files->indata.c_str());
      // Translate for reconstruction
      VecShift(pp.px, pars.recon.origin[0]);
      VecShift(pp.py, pars.recon.origin[1]);
      VecShift(pp.pz, pars.recon.origin[2]);
      PetscPrintf(PETSC_COMM_WORLD,"Read in %i particles.....\n",pp.npart);
      pr.AsciiReadWeightedSerial(files->inrand.c_str());
      // Translate for reconstruction
      VecShift(pr.px, pars.recon.origin[0]);
      VecShift(pr.py, pars.recon.origin[1]);
      VecShift(pr.pz, pars.recon.origin[2]);
      PetscPrintf(PETSC_COMM_WORLD,"Read in %i randoms.....\n",pr.npart);
      pp.SlabDecompose(dg);
      pr.SlabDecompose(dg);


      /*************************************************
       * Generate the density field and constrained realization
       *************************************************/
      Vec grid=PETSC_NULL;
      del1.BuildDensityGrid(pp, grid);
      PetscPrintf(PETSC_COMM_WORLD, "Density grid computed.....\n");
      del1.HoffmanRibak(grid, kvec, pkvec, const_seed, pars.pkprior.dorandom); const_seed+=1;
      PetscPrintf(PETSC_COMM_WORLD, "Constrained realization computed.....\n");

      /************************************************
       * Now we solve for the potential 
       ************************************************/
      // Allocate potential solver
      Vec pot;
      pot = dg.Allocate();
      if (psolve.Solve(grid, pot, pars.recon.bias)) {
        // If the potential calculation converged
        PetscPrintf(PETSC_COMM_WORLD,"Potential calculated....\n");
        
        /************************************************
         * Now we shift data and randoms
         ************************************************/
        // Generate random particles
        Vec dp, qx, qy, qz;
        
        // Compute derivatives at data positions and shift
        dp = dg.Deriv(pot, 0); qx = dg.Interp3d(dp, pp); _mydestroy(dp);
        dp = dg.Deriv(pot, 1); qy = dg.Interp3d(dp, pp); _mydestroy(dp);
        dp = dg.Deriv(pot, 2); qz = dg.Interp3d(dp, pp); _mydestroy(dp);
        // Print some statistics
        double sum[3];
        VecSum(qx,&sum[0]); VecSum(qy, &sum[1]); VecSum(qz, &sum[2]);
        for (int ii=0; ii < 3; ++ii) sum[ii] /= pp.npart;
        PetscPrintf(PETSC_COMM_WORLD, "Mean x,y,z displacements on particles is : %10.4f,%10.4f,%10.4f\n",sum[0],sum[1],sum[2]);
        VecNorm(qx,NORM_2,&sum[0]); VecNorm(qy, NORM_2,&sum[1]); VecNorm(qz, NORM_2,&sum[2]);
        for (int ii=0; ii < 3; ++ii) sum[ii] /= sqrt(pp.npart);
        PetscPrintf(PETSC_COMM_WORLD, "RMS x,y,z displacements on particles is : %10.4f,%10.4f,%10.4f\n",sum[0],sum[1],sum[2]);
        
        // Shift the particles
        VecAXPY(pp.px, -1.0, qx);
        VecAXPY(pp.py, -1.0, qy);
        VecAXPY(pp.pz, -1.0, qz);
	PetscPrintf(PETSC_COMM_WORLD, "Standard displacements complete\n");


        if (pars.recon.planeparallel == 1) {
          // This case is simple!
          VecAXPY(pp.pz, -1.0, qz);
	  PetscPrintf(PETSC_COMM_WORLD, "plane parallel zspace displacements complete\n");
        } else {
          // Now shift to remove redshift distortions - this requires a little coordinate geometry
          // We need q.p/|r|
          pp.RadialDisplace(qx, qy, qz, pars.recon.origin, -pars.recon.fval);
	  PetscPrintf(PETSC_COMM_WORLD, "radial zspace displacements complete\n");
        }

        // Cleanup
        _mydestroy(qx); _mydestroy(qy); _mydestroy(qz);
        
        // Do the same for the randoms
        dp = dg.Deriv(pot, 0); qx = dg.Interp3d(dp, pr); _mydestroy(dp);
        dp = dg.Deriv(pot, 1); qy = dg.Interp3d(dp, pr); _mydestroy(dp);
        dp = dg.Deriv(pot, 2); qz = dg.Interp3d(dp, pr); _mydestroy(dp);
        VecSum(qx,&sum[0]); VecSum(qy, &sum[1]); VecSum(qz, &sum[2]);
        for (int ii=0; ii < 3; ++ii) sum[ii] /= pr.npart;
        PetscPrintf(PETSC_COMM_WORLD, "Mean x,y,z displacements on randoms is : %10.4f,%10.4f,%10.4f\n",sum[0],sum[1],sum[2]);
        VecNorm(qx,NORM_2,&sum[0]); VecNorm(qy, NORM_2,&sum[1]); VecNorm(qz, NORM_2,&sum[2]);
        for (int ii=0; ii < 3; ++ii) sum[ii] /= sqrt(pr.npart);
        PetscPrintf(PETSC_COMM_WORLD, "RMS x,y,z displacements on randoms is : %10.4f,%10.4f,%10.4f\n",sum[0],sum[1],sum[2]);
        VecAXPY(pr.px, -1.0, qx);
        VecAXPY(pr.py, -1.0, qy);
        VecAXPY(pr.pz, -1.0, qz);
        PetscPrintf(PETSC_COMM_WORLD,"Displacements calculated....\n");
        // Clean up
        _mydestroy(qx); _mydestroy(qy); _mydestroy(qz);

        // Before writing the particles out, shift them to such that the observer is at (0,0,0)
        // This simplifies calculating perpendicular and parallel correlation functions
        VecShift(pp.px, -pars.recon.origin[0]);
        VecShift(pp.py, -pars.recon.origin[1]);
        VecShift(pp.pz, -pars.recon.origin[2]);
        // Do the same to the shifted randoms
        VecShift(pr.px, -pars.recon.origin[0]);
        VecShift(pr.py, -pars.recon.origin[1]);
        VecShift(pr.pz, -pars.recon.origin[2]);
        


        
        // Write out files
        pp.AsciiWriteWeightedSerial(files->outdata.c_str());
        pr.AsciiWriteWeightedSerial(files->outrand.c_str());
      }
      // Cleanup
      _mydestroy(grid); _mydestroy(pot);

    }

    }
  void VerletListTriple::checkTriple(Particle& pt1, Particle& pt2, Particle& pt3){
    // check if central particle is in the exclusion list
    if (exList.count(pt2.id()) > 0) return;
    
    Real3D d1 = pt1.position() - pt2.position();
    Real3D d2 = pt2.position() - pt3.position();
    
    real distsq1 = d1.sqr();
    real distsq2 = d2.sqr();

    LOG4ESPP_TRACE(theLogger, "p1: " << pt1.id()
                   << " @ " << pt1.position() 
		   << " - p2: " << pt2.id() << " @ " << pt2.position()
		   << " - p3: " << pt3.id() << " @ " << pt3.position()
		   << " -> distsq1 = " << distsq1
		   << " -> distsq2 = " << distsq2);

    if (distsq1>cutsq || distsq2>cutsq) return;
    
    vlTriples.add(pt1, pt2, pt3); // add triple to Verlet List
  }
Example #30
0
void Hadron_Decay_Handler::SetPosition(ATOOLS::Blob* blob)
{
  Particle* inpart = blob->InParticle(0);
  if(inpart->Flav().Kfcode()==kf_K) {
    blob->SetPosition(inpart->XProd());
    return;
  }
  
  // boost lifetime into lab
  double gamma = 1./rpa->gen.Accu();
  if (inpart->Flav().HadMass()>rpa->gen.Accu()) {
    gamma = inpart->E()/inpart->Flav().HadMass();
  }
  else {
    double q2    = dabs(inpart->Momentum().Abs2());
    if (q2>rpa->gen.Accu()) gamma = inpart->E()/sqrt(q2);
  }
  double lifetime_boosted = gamma * inpart->Time();
  
  Vec3D      spatial = inpart->Distance( lifetime_boosted );
  Vec4D     position = Vec4D( lifetime_boosted*rpa->c(), spatial );
  blob->SetPosition( inpart->XProd() + position ); // in mm
}