Index: external/Hector/CREDITS
===================================================================
--- external/Hector/CREDITS	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
+++ external/Hector/CREDITS	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
@@ -0,0 +1,23 @@
+  /* * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ *                                                         *
+*                   --<--<--  A fast simulator --<--<--     *
+*                 / --<--<--     of particle   --<--<--     *
+*  ----HECTOR----<                                          *
+*                 \ -->-->-- transport through -->-->--     *
+*                   -->-->-- generic beamlines -->-->--     *
+*                                                           *
+* JINST 2:P09005 (2007)                                     *
+*      X Rouby, J de Favereau, K Piotrzkowski (CP3)         *
+*       http://www.fynu.ucl.ac.be/hector.html               *
+*                                                           *
+* Center for Cosmology, Particle Physics and Phenomenology  *
+*              Universite catholique de Louvain             *
+*                 Louvain-la-Neuve, Belgium                 *
+ *                                                         *
+   * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+   J. de Favereau, X. Rouby ~~~ cp3_hector_devel@listes.uclouvain.be
+	jerome.defavereau@uclouvain.be 
+	xavier.rouby@cern.ch
+
+   (C) All rights reserved
Index: external/Hector/H_AbstractBeamLine.cc
===================================================================
--- external/Hector/H_AbstractBeamLine.cc	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
+++ external/Hector/H_AbstractBeamLine.cc	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
@@ -0,0 +1,650 @@
+  /* * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ *                                                         *
+*                   --<--<--  A fast simulator --<--<--     *
+*                 / --<--<--     of particle   --<--<--     *
+*  ----HECTOR----<                                          *
+*                 \ -->-->-- transport through -->-->--     *
+*                   -->-->-- generic beamlines -->-->--     *
+*                                                           *
+* JINST 2:P09005 (2007)                                     *
+*      X Rouby, J de Favereau, K Piotrzkowski (CP3)         *
+*       http://www.fynu.ucl.ac.be/hector.html               *
+*                                                           *
+* Center for Cosmology, Particle Physics and Phenomenology  *
+*              Universite catholique de Louvain             *
+*                 Louvain-la-Neuve, Belgium                 *
+ *                                                         *
+   * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+/// \file H_AbstractBeamLine.cc
+/// \brief Class describing ideal beamline.
+///
+/// Units : angles [rad], distances [m], energies [GeV], c=[1].
+
+// c++ #includes
+#include <iostream>
+#include <cmath>
+
+// ROOT #includes
+#include "TPaveLabel.h"
+#include "TLine.h"
+#include "TGaxis.h"
+#include "TLegend.h"
+#include "TF1.h"
+#include "TROOT.h"
+
+// local #includes
+#include "H_Parameters.h"
+#include "H_TransportMatrices.h"
+#include "H_Drift.h"
+#include "H_AbstractBeamLine.h"
+#include "H_RomanPot.h"
+using namespace std;
+
+void H_AbstractBeamLine::init(const float length) {
+	beam_mat.ResizeTo(MDIM,MDIM);
+	beam_mat = driftmat(length);
+  	beam_length = length;
+	H_Drift * drift0 = new H_Drift("Drift0",0.,length);
+	add(drift0);
+	return;
+}
+
+H_AbstractBeamLine::H_AbstractBeamLine(const H_AbstractBeamLine& beamline) : 
+	matrices(beamline.matrices)   {
+	//elements = beamline.elements; //<-- bad ! the new vector contains the same pointers as the previous one
+	cloneElements(beamline);
+	beam_mat.ResizeTo(MDIM,MDIM);
+	beam_mat = beamline.beam_mat;
+	beam_length = beamline.beam_length;
+}
+
+H_AbstractBeamLine& H_AbstractBeamLine::operator=(const H_AbstractBeamLine& beamline) {
+	if(this== &beamline) return *this;
+	//elements = beamline.elements; //<-- bad ! the new vector contains the same pointers as the previous one
+	cloneElements(beamline);
+        matrices = beamline.matrices;
+        beam_mat = beamline.beam_mat;
+	beam_length = beamline.beam_length;
+	return *this;
+}
+
+H_AbstractBeamLine* H_AbstractBeamLine::clone() const {
+	H_AbstractBeamLine* temp_beam = new H_AbstractBeamLine(beam_length);
+	vector<H_OpticalElement*>::const_iterator element_i;
+	for (element_i = elements.begin(); element_i<elements.end(); element_i++) {
+		if((*element_i)->getType()!=DRIFT) {
+			H_OpticalElement* temp_el = (*element_i)->clone();
+			temp_beam->add(temp_el);
+		}
+	}
+	temp_beam->beam_mat = beam_mat;
+	temp_beam->matrices = matrices;
+	return temp_beam;
+}
+
+H_AbstractBeamLine::~H_AbstractBeamLine() {
+	vector<H_OpticalElement*>::iterator element_i;
+	for (element_i = elements.begin(); element_i<elements.end(); element_i++) {
+		delete (*element_i);
+	}
+	elements.clear(); 
+	matrices.clear(); 
+}
+
+void H_AbstractBeamLine::cloneElements(const H_AbstractBeamLine& beam) {
+	vector<H_OpticalElement*>::const_iterator element_i;
+        for (element_i = beam.elements.begin(); element_i< beam.elements.end(); element_i++) {
+        	H_OpticalElement* temp_el = (*element_i)->clone();
+                elements.push_back(temp_el);
+        }
+}
+
+void H_AbstractBeamLine::add(H_OpticalElement * newElement) {
+	/// @param newElement is added to the beamline
+//	H_OpticalElement * el = new H_OpticalElement(*newElement);
+//	H_OpticalElement * el = const_cast<H_OpticalElement*> newElement; 
+//	H_OpticalElement * el = newElement;
+	elements.push_back(newElement);
+ 	float a = newElement->getS()+newElement->getLength();
+	if (a > beam_length)	{
+		beam_length = a;
+		if(VERBOSE) cout<<"<H_AbstractBeamLine> WARNING : element ("<< newElement->getName()<<") too far away. The beam length has been extended to "<< beam_length << ". "<<endl;
+	}
+	calcSequence();
+	calcMatrix();
+	return;
+}
+
+const TMatrix H_AbstractBeamLine::getBeamMatrix() const {
+	return beam_mat;
+}
+
+const TMatrix H_AbstractBeamLine::getBeamMatrix(const float eloss,const float p_mass, const float p_charge) {
+
+	vector<H_OpticalElement*>::iterator element_i;
+    TMatrix calc_mat(MDIM,MDIM);
+
+    // initialization
+	calc_mat.UnitMatrix();
+	
+	// multiplies the matrix of each beam's element
+	// and add each product matrix to the list of matrices.
+	for(element_i = elements.begin(); element_i < elements.end(); element_i++) {
+		calc_mat *= (*element_i)->getMatrix(eloss,p_mass,p_charge);
+	}
+	return calc_mat;
+}
+
+const TMatrix H_AbstractBeamLine::getPartialMatrix(const string& elname, const float eloss, const float p_mass, const float p_charge) {
+
+	vector<H_OpticalElement*>::iterator element_i;
+	TMatrix calc_mat(MDIM,MDIM);
+
+	calc_mat.UnitMatrix();
+
+	for(element_i = elements.begin(); element_i < elements.end(); element_i++) {
+		calc_mat *= (*element_i)->getMatrix(eloss,p_mass,p_charge);
+		if(elname==(*element_i)->getName()) {
+			return calc_mat;
+		}
+	}
+	cout<<"<H_AbstractBeamLine> Element "<<elname<<" desn't exist. Returning full beam matrix"<<endl;
+	return calc_mat;
+}
+
+const TMatrix H_AbstractBeamLine::getPartialMatrix(const unsigned int element_position) const {
+ 	//const int N = (element_position<0)?0:(( (element_position)>elements.size()-1)?elements.size()-1:element_position);
+	const int N = (element_position>elements.size()-1)?elements.size()-1:element_position;
+	return *(matrices.begin()+N); // //for optimization of the code :same as return &matrices[N];
+}
+
+const TMatrix H_AbstractBeamLine::getPartialMatrix(const H_OpticalElement * element) const{
+	// returns the transport matrix to transport until the end of the specified element
+	// !!! 2 elements should never have the same name in "elements" !!!
+
+	vector<H_OpticalElement*>::const_iterator element_i;
+	vector<TMatrix>::const_iterator matrix_i;
+	TMatrix calc_mat(MDIM,MDIM);
+
+	// parses the list of optical elements and find the searched one
+	for(element_i = elements.begin(),matrix_i = matrices.begin(); element_i < elements.end(); element_i++, matrix_i++) {
+		if(element->getName() == (*element_i)->getName()) {
+			// element has been found
+			calc_mat = *matrix_i;
+        	}
+	}
+	return calc_mat;
+}
+
+H_OpticalElement * H_AbstractBeamLine::getElement(const unsigned int element_position) {
+	const unsigned int N = (element_position>elements.size())?elements.size():element_position;
+	return *(elements.begin()+N);//for optimization of the code :same as return &elements[N];
+}
+
+H_OpticalElement * H_AbstractBeamLine::getElement(const unsigned int element_position) const {
+	const unsigned int N = (element_position>elements.size())?elements.size():element_position;
+        return *(elements.begin()+N);//for optimization of the code :same as return &elements[N];
+}
+
+
+H_OpticalElement * H_AbstractBeamLine::getElement(const string& el_name) {
+	for(unsigned int i=0; i < elements.size(); i++) {
+		if( (*(elements.begin()+i))->getName() == el_name ) 
+			return *(elements.begin()+i);
+	} // if found -> return ; else : not found at all !	
+	cout<<"<H_AbstractBeamLine> Element "<<el_name<<" not found"<<endl;
+	return *(elements.begin()+1);
+}
+
+H_OpticalElement * H_AbstractBeamLine::getElement(const string& el_name) const {
+        for(unsigned int i=0; i < elements.size(); i++) {
+		if( (*(elements.begin()+i))->getName() == el_name)
+			return *(elements.begin()+i);
+	} // if found -> return ; else : not found at all !
+	cout<<"<H_AbstractBeamLine> Element "<<el_name<<" not found"<<endl;
+	return *(elements.begin()+1);
+}
+
+std::ostream& operator<< (std::ostream& os, const H_AbstractBeamLine& be) {
+        vector<H_OpticalElement*>::const_iterator element_i;
+        os << "Beamline content" << endl;
+        for (element_i = be.elements.begin(); element_i < be.elements.end(); element_i++) {
+                os << (int)(element_i - be.elements.begin()) << "\t" << (*element_i)->getName() << "\t" << (*element_i)->getS() << endl;
+        }
+  return os;
+}
+
+void H_AbstractBeamLine::printProperties() const { cout << *this; return; }
+
+void H_AbstractBeamLine::showElements() const{
+	vector<H_OpticalElement*>::const_iterator element_i;
+	for(element_i = elements.begin(); element_i < elements.end(); element_i++) {
+		(*element_i)->printProperties();
+	}
+	cout << "Beam length = " << beam_length << endl;
+	cout << "Number of elements (including drifts) = " << getNumberOfElements() << endl;
+	return;
+}
+
+void H_AbstractBeamLine::showElements(const int type_el) const{
+	vector<H_OpticalElement*>::const_iterator element_i;
+	for(element_i = elements.begin(); element_i < elements.end(); element_i++) {
+		if ((*element_i)->getType()==type_el)
+			(*element_i)->printProperties();
+	}
+	return;
+}
+
+void H_AbstractBeamLine::showMatrix() const {
+	cout << "Transport matrix for the whole beam : " << endl;
+	cout << "(x,x',...) = (x*,x'*,...) M " <<endl;
+  	printMatrix(beam_mat);
+	return;
+}
+
+void H_AbstractBeamLine::showMatrices() const{
+	// prints the list of all transport matrices, from the whole beam.
+
+	vector<TMatrix>::const_iterator matrix_i;
+	vector<H_OpticalElement*>::const_iterator element_i;
+	TMatrix temp(MDIM,MDIM);
+
+	for(matrix_i = matrices.begin(), element_i = elements.begin(); matrix_i < matrices.end(); matrix_i++, element_i++) {
+		temp = *matrix_i;
+		cout << "Matrix for transport until s=" << (*element_i)->getS() + (*element_i)->getLength() << "m (" << (*element_i)->getName() << "). " << endl;
+		printMatrix(temp);
+		cout << endl;
+	}
+	return ;
+}
+
+void H_AbstractBeamLine::calcSequence() {
+		// reorders the elements, computes the drifts;
+
+	vector<H_OpticalElement*> temp_elements;
+	vector<H_OpticalElement*>::iterator element_i;
+		// element_i is a pointer to elements[i]
+
+	if(elements.size()==1) { return; }
+
+	// getting rid of drifts before calculating
+	for(element_i = elements.begin(); element_i < elements.end(); element_i++) {
+		if((*element_i)->getType() == DRIFT) {delete (*element_i); elements.erase(element_i); }
+	}
+
+	// ordering the elements in position
+	sort(elements.begin(),elements.end(),ordering());
+	// inserting the drifts before the other elements
+	float current_pos = 0;
+	float drift_length=0;
+
+	for(element_i=elements.begin(); element_i < elements.end(); element_i++) {
+		drift_length = (*element_i)->getS() - current_pos;
+		if(drift_length>0) {
+  			H_Drift *dr = new H_Drift(current_pos,drift_length);
+			temp_elements.push_back(dr); 
+		}
+		temp_elements.push_back(*element_i);
+		current_pos = (*element_i)->getS() + (*element_i)->getLength();
+	}
+	
+	//adding the last drift
+	drift_length = beam_length - current_pos;
+	if (drift_length>0) {
+			H_Drift *dr = new H_Drift(current_pos,drift_length);
+			temp_elements.push_back(dr);
+	}
+	
+	// cleaning : avoid some memory leaks
+	elements.clear();
+
+	for(element_i=temp_elements.begin(); element_i < temp_elements.end(); element_i++) {
+		elements.push_back(*element_i);
+	}
+}
+
+void H_AbstractBeamLine::calcMatrix() {
+	// computes the transport matrix for the beam upto here...
+	vector<H_OpticalElement*>::iterator element_i;
+	TMatrix calc_mat(MDIM,MDIM);
+
+	// initialization
+	matrices.clear();
+	calc_mat.UnitMatrix();
+
+	// multiplies the matrix of each beam's element
+	// and add each product matrix to the list of matrices.
+	for(element_i = elements.begin(); element_i < elements.end(); element_i++) {
+		calc_mat *= (*element_i)->getMatrix();
+		matrices.push_back(calc_mat);
+  	}
+
+	beam_mat.ResizeTo(MDIM,MDIM);
+	beam_mat = calc_mat;
+	return;
+}
+
+float qh(float k) {
+        float beta = (log((float)10.0))/0.05;
+		// put (std::log((float)10.0)) instead of log(10) to avoid compilation errors
+        return 0.8*(1-exp(-beta*fabs(k)));
+}
+
+float dh(float k) {
+        float psi = (log((float)10.0))/0.002;
+		// put (std::log((float)10.0)) instead of log(10) to avoid compilation errors
+        return 0.8*(1-exp(-psi*fabs(k)));
+}
+
+void H_AbstractBeamLine::draw(const float xmin, const float ymin, const float xmax, const float ymax) const{
+	gROOT->SetStyle("Plain");
+	TLegend* leg = new TLegend(xmin,ymin,xmax,ymax,""); 
+	leg->SetBorderSize(1);
+	leg->SetFillColor(kWhite);
+	TBox* b1 = new TBox();
+	TBox* b2 = new TBox(0,0,10,10);
+	TBox* b3 = new TBox(0,0,0,0);
+	TBox* b4 = new TBox(0,0,0,0);
+	TBox* b5 = new TBox(0,0,0,0);
+	TBox* b6 = new TBox(0,0,0,0);
+	TBox* b7 = new TBox(0,0,0,0);
+	b1->SetFillColor(RDIPOLE);
+	b2->SetFillColor(SDIPOLE);
+	b3->SetFillColor(VQUADRUPOLE);
+	b4->SetFillColor(HQUADRUPOLE);
+	b5->SetFillColor(HKICKER);
+	b6->SetFillColor(VKICKER);
+	b7->SetFillColor(RCOLLIMATOR);
+	leg->AddEntry(b1,"R-Dipole");
+	leg->AddEntry(b2,"S-Dipole");
+	leg->AddEntry(b3,"V-Quadrupole");
+	leg->AddEntry(b4,"H-Quadrupole");
+	leg->AddEntry(b5,HKICKERNAME);
+	leg->AddEntry(b6,VKICKERNAME);
+	leg->AddEntry(b7,"RCollimator");
+	leg->Draw();
+/*	TLine* l1 = new TLine(0.05,0.5,0.95,0.5);
+	TLine* l2 = new TLine(0.1,0.1,0.1,0.9);
+	TLine* l3 = new TLine(0.9,0.1,0.9,0.9);
+	TPaveLabel* p1 = new TPaveLabel(0.05,0.5,0.1,0.6,"IP");
+	TPaveLabel* p2 = new TPaveLabel(0.9,0.5,0.95,0.6,"RP");
+	TGaxis* a1 = new TGaxis(0.1,0.1,0.9,0.1,0,beam_length);
+	a1->SetLabelSize(0.08);
+	p1->SetBorderSize(1);
+	p2->SetBorderSize(1);
+	p1->SetFillColor(0);
+	p2->SetFillColor(0);
+	l1->Draw();
+	l2->Draw();
+	l3->Draw();
+	p1->Draw();
+	p2->Draw();
+	float x1,x2,y1,y2;
+	vector<TPaveLabel*> boxes;
+	vector<H_OpticalElement*>::const_iterator element_i;
+	for(element_i = elements.begin(); element_i < elements.end(); element_i++) {
+		x1 = 0.1 + ((*element_i)->getS()/beam_length)*0.8;
+		x2 = x1 + ((*element_i)->getLength()/beam_length)*0.8;
+		if((*element_i)->getType()>5) {
+			y1 = 0.3;
+			y2 = 0.7;
+		}
+		else if((*element_i)->getType()>3) {
+			y1 = 0.5 - qh((*element_i)->getK()*(*element_i)->getLength())/2.;
+			y2 = 0.5 + qh((*element_i)->getK()*(*element_i)->getLength())/2.;
+		} else {
+			y1 = 0.5 - dh((*element_i)->getK()*(*element_i)->getLength())/2.;
+			y2 = 0.5 + dh((*element_i)->getK()*(*element_i)->getLength())/2.;
+		}
+		TPaveLabel* cur_box = new TPaveLabel(x1,y1,x2,y2,"");
+		cur_box->SetFillStyle(1);
+		cur_box->SetFillColor(((int)(*element_i)->getType()));
+		cur_box->SetBorderSize(1);
+		if((*element_i)->getType()!=DRIFT) boxes.push_back(cur_box);
+	}
+	vector<TPaveLabel*>::iterator box_i;
+	for(box_i = boxes.begin(); box_i < boxes.end(); box_i++) {
+		(*box_i)->Draw();
+	}
+	a1->Draw();
+*/	
+	return;
+}
+
+void H_AbstractBeamLine::drawX(const float a_min, const float a_max, const float scale) const{
+	/// @param a_min defines the size of the drawing
+	/// @param a_max defines the size of the drawing
+	/// @param scale allows to multiply the drawing, i.e. changing the units
+	const int N = getNumberOfElements();
+	for(int i=0;i<N;i++) {
+		float height = fabs(a_max);
+        	float meight = fabs(a_min);
+        	float size = (height>meight)?meight:height;
+		float middle = getElement(i)->getX()*URAD*scale;
+        	if(getElement(i)->getType()!=DRIFT) getElement(i)->draw(middle+size/2.,middle-size/2.);
+    	}
+}
+
+void H_AbstractBeamLine::drawY(const float a_min, const float a_max) const{
+        /// @param a_min defines the size of the drawing 
+        /// @param a_max defines the size of the drawing
+        const int N = getNumberOfElements();
+        for(int i=0;i<N;i++) {
+                float height = fabs(a_max);
+                float meight = fabs(a_min);
+                float size = (height>meight)?meight:height;
+                float middle = getElement(i)->getY()*URAD;
+                if(getElement(i)->getType()!=DRIFT) getElement(i)->draw(middle+size/2.,middle-size/2.);
+        }
+}
+
+void H_AbstractBeamLine::moveElement(const string& name, const float new_s) {
+	/// @param name identifies the element to move
+	/// @param new_s is where to put it
+       vector<H_OpticalElement*>::iterator element_i;
+       for(element_i = elements.begin(); element_i < elements.end(); element_i++) {
+	       if(name==(*element_i)->getName()) { (*element_i)->setS(new_s); }
+       }
+
+       calcSequence();
+       calcMatrix();
+       return;
+}
+
+void H_AbstractBeamLine::alignElement(const string& name, const float disp_x, const float disp_y) {
+	/// @param name identifies the element to move
+	/// @param disp_x identifies the displacement to add in x [\f$ \mu m \f$]
+	/// @param disp_y identifies the displacement to add in y [\f$ \mu m \f$]
+		vector<H_OpticalElement*>::iterator element_i;
+		for(element_i = elements.begin(); element_i < elements.end(); element_i++) {
+			if(name==(*element_i)->getName()) { 
+				(*element_i)->setX((*element_i)->getX()+disp_x);
+				(*element_i)->setY((*element_i)->getY()+disp_y);
+				return ;
+			}
+		}
+		cout<<"<H_AbstractBeamLine> WARNING : Element "<<name<<" not found."<<endl; 
+		return;
+}
+
+void H_AbstractBeamLine::tiltElement(const string& name, const float ang_x, const float ang_y) {
+	/// @param name identifies the element to move
+	/// @param ang_x identifies the angle to add in x
+	/// @param ang_y identifies the angle to add in y
+		vector<H_OpticalElement*>::iterator element_i;
+		for(element_i = elements.begin(); element_i < elements.end(); element_i++) {
+			if(name==(*element_i)->getName()) {
+				(*element_i)->setTX((*element_i)->getTX()+ang_x);
+				(*element_i)->setTY((*element_i)->getTY()+ang_y);
+				return ;
+			}
+		}
+		cout<<"<H_AbstractBeamLine> WARNING : Element "<<name<<" not found."<<endl; 
+		return;
+}
+
+void H_AbstractBeamLine::offsetElements(const float start, const float offset) {
+	/// @param start After this s [m] coordinate, all elements will be offset.
+	/// @param offset In meters
+
+	extern int relative_energy;
+	if(!relative_energy) {
+		vector<H_OpticalElement*>::iterator element_i;
+   	     for(element_i = elements.begin(); element_i < elements.end(); element_i++) {
+			if((*element_i)->getS() > start ) {
+    	       (*element_i)->setX(offset);
+       	    }
+		}
+	}
+}
+
+TGraph * H_AbstractBeamLine::getBetaX() const{
+        const int N = elements.size();
+        float * s = new float[N], * b = new float[N], temp;
+	int i=0, n=N;
+
+	vector<H_OpticalElement*>::const_iterator element_i;
+	for(element_i = elements.begin(); element_i < elements.end(); element_i++) {	
+		temp=(*element_i)->getBetaX();	
+		if (temp !=0) {
+			b[i] = (*element_i)->getBetaX();
+			s[i] = (*element_i)->getS();
+			i++;
+			n=i;
+		}
+	}
+
+        TGraph * betax = new TGraph(n,s,b);
+        betax->SetLineColor(1);
+	betax->SetLineStyle(2);
+	delete [] s;
+	delete [] b;
+        return betax;
+}
+
+TGraph * H_AbstractBeamLine::getBetaY() const{
+        const int N = elements.size();
+        float * s = new float[N], * b = new float[N], temp;
+        int i=0, n=N;
+
+        vector<H_OpticalElement*>::const_iterator element_i;
+        for(element_i = elements.begin(); element_i < elements.end(); element_i++) {
+                temp=(*element_i)->getBetaY();
+                if (temp !=0) {
+                        b[i] = (*element_i)->getBetaY();
+                        s[i] = (*element_i)->getS();
+                        i++;
+                        n=i;
+                }
+        }
+
+        TGraph * betay = new TGraph(n,s,b);
+        betay->SetLineColor(2);
+        betay->SetLineStyle(2);
+	delete [] s;
+	delete [] b;
+        return betay;
+}
+
+TGraph * H_AbstractBeamLine::getDX() const{
+        const int N = elements.size();
+        float * s = new float[N], * d = new float[N], temp;
+        int i=0, n=N;
+
+        vector<H_OpticalElement*>::const_iterator element_i;
+        for(element_i = elements.begin(); element_i < elements.end(); element_i++) {
+                temp=(*element_i)->getDX();
+                if (temp !=0) {
+                        d[i] = (*element_i)->getDX();
+                        s[i] = (*element_i)->getS();
+                        i++;
+                        n=i;
+                }
+        }
+
+        TGraph * dispx = new TGraph(n,s,d);
+        dispx->SetLineColor(8);
+        dispx->SetLineStyle(2);
+        delete [] s;
+        delete [] d;
+        return dispx;
+}
+
+TGraph * H_AbstractBeamLine::getDY() const{
+        const int N = elements.size();
+        float * s = new float[N], * d = new float[N], temp;
+        int i=0, n=N;
+ 
+        vector<H_OpticalElement*>::const_iterator element_i;
+        for(element_i = elements.begin(); element_i < elements.end(); element_i++) {
+                temp=(*element_i)->getDY();
+                if (temp !=0) {
+                        d[i] = (*element_i)->getDY();
+                        s[i] = (*element_i)->getS();
+                        i++;
+                        n=i;
+                }
+        }
+ 
+        TGraph * dispy = new TGraph(n,s,d);
+        dispy->SetLineColor(kBlue);
+        dispy->SetLineStyle(2);
+        delete [] s;
+        delete [] d;
+        return dispy;
+}
+
+
+TGraph * H_AbstractBeamLine::getRelX() const{
+        const int N = elements.size();
+        float * s = new float[N], * r = new float[N], temp;
+        int i=0, n=N;
+
+        vector<H_OpticalElement*>::const_iterator element_i;
+        for(element_i = elements.begin(); element_i < elements.end(); element_i++) {
+                temp=(*element_i)->getRelX();
+		if((*element_i)->getType() != DRIFT) {
+			r[i] = (*element_i)->getRelX();
+			s[i] = (*element_i)->getS();
+			i++;
+			n=i;
+		}
+	}
+
+        TGraph * relx = new TGraph(n,s,r);
+        relx->SetLineColor(kBlack);
+	relx->SetMarkerStyle(kOpenSquare);
+	relx->SetMarkerSize(0.6);
+        relx->SetLineStyle(2);
+        delete [] s;
+        delete [] r;
+        return relx;
+}
+
+TGraph * H_AbstractBeamLine::getRelY() const{
+        const int N = elements.size();
+        float * s = new float[N], * r = new float[N], temp;
+        int i=0, n=N;
+
+        vector<H_OpticalElement*>::const_iterator element_i;
+        for(element_i = elements.begin(); element_i < elements.end(); element_i++) {
+                temp=(*element_i)->getRelY();
+                if((*element_i)->getType() != DRIFT) {
+                        r[i] = (*element_i)->getRelY();
+                        s[i] = (*element_i)->getS();
+                        i++;
+                        n=i;
+                }
+        }
+
+        TGraph * rely = new TGraph(n,s,r);
+        rely->SetLineColor(kRed);
+	rely->SetMarkerStyle(kOpenSquare);
+	rely->SetMarkerSize(0.6);
+        rely->SetLineStyle(2);
+        delete [] s;
+        delete [] r;
+        return rely;
+}
+
Index: external/Hector/H_AbstractBeamLine.h
===================================================================
--- external/Hector/H_AbstractBeamLine.h	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
+++ external/Hector/H_AbstractBeamLine.h	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
@@ -0,0 +1,148 @@
+#ifndef _H_AbstractBeamLine_
+#define _H_AbstractBeamLine_
+
+  /* * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ *                                                         *
+*                   --<--<--  A fast simulator --<--<--     *
+*                 / --<--<--     of particle   --<--<--     *
+*  ----HECTOR----<                                          *
+*                 \ -->-->-- transport through -->-->--     *
+*                   -->-->-- generic beamlines -->-->--     *
+*                                                           *
+* JINST 2:P09005 (2007)                                     *
+*      X Rouby, J de Favereau, K Piotrzkowski (CP3)         *
+*	http://www.fynu.ucl.ac.be/hector.html               *
+*                                                           *
+* Center for Cosmology, Particle Physics and Phenomenology  *
+*              Universite catholique de Louvain             *
+*                 Louvain-la-Neuve, Belgium                 *
+ *                                                         *
+   * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+
+/// \file H_AbstractBeamLine.h
+/// \brief Class aiming at simulating the LHC beamline.
+///
+/// Units : angles [urad], distances [um], energies [GeV], c=[1].
+
+	/// default length of the beam line
+#define LENGTH_DEF 100
+
+// c++ #includes
+#include <vector>
+#include <algorithm>
+#include <string>
+
+
+// ROOT #includes
+#include "TMatrix.h"
+#include "TGraph.h"
+
+// local #includes
+#include "H_OpticalElement.h"
+using namespace std;
+
+/// Beamline made from a vector of H_OpticalElement.
+class H_AbstractBeamLine {
+
+	public:
+		///     Constructors, destructor and operator
+		//@{
+		H_AbstractBeamLine() {init(LENGTH_DEF);};
+		H_AbstractBeamLine(const float length) {init(length);};
+		H_AbstractBeamLine(const H_AbstractBeamLine &);
+		H_AbstractBeamLine& operator=(const H_AbstractBeamLine&);
+		H_AbstractBeamLine* clone() const ;
+		~H_AbstractBeamLine();
+		//@}
+		///     Adds an element to the beamline
+		void add(H_OpticalElement *);
+		///     Returns the (float) length of the beamline
+  		const float getLength() const { return beam_length;};
+		///     Returns the (int) number of optics element of the beamline, including drifts
+  		const unsigned int getNumberOfElements() const { return elements.size();}; 
+		///     Returns the transport matrix for the whole beam
+		const TMatrix getBeamMatrix() const;
+		///     Returns the transport matrix for the whole beam, for given energy loss/mass/charge
+		const TMatrix getBeamMatrix(const float , const float, const float ) ;
+		///     Returns the transport matrix for a part of the beam from the IP to a given element
+		const TMatrix getPartialMatrix(const H_OpticalElement *) const;
+		///     Returns the transport matrix for a part of the beam from the IP to the ith element
+		const TMatrix getPartialMatrix(const unsigned int ) const;
+		///     Returns the transport matrix for a part of the beam from the IP to a given element, given energy loss/mass/charge
+		const TMatrix getPartialMatrix(const string&, const float, const float, const float);
+		///     Returns the ith element of the beamline
+		//@{
+		H_OpticalElement * getElement(const unsigned int );
+		H_OpticalElement * getElement(const unsigned int ) const;
+		//@}
+		///	Returns a given element of the beamline, choosen by name 
+		//@{
+		H_OpticalElement * getElement(const string& );
+		H_OpticalElement * getElement(const string& ) const;
+		//@}
+		///	Print some info
+		void printProperties() const;
+		///     Prints the element list
+		void showElements() const;
+		///     Prints the list of elements of a give type
+		void showElements(const int) const;
+		///     Prints the transport matrix for the whole beam
+		void showMatrix() const;
+		///     Prints the transport matrix for each element of the beamline
+		void showMatrices() const;
+		/// 	Reorders elements and adds the drift sections
+		void calcSequence();
+		/// 	Computes global transport matrix
+		void calcMatrix();
+		/// 	Draws the legend of the elements of the beam
+		void draw(const float xmin =0.85, const float ymin=0.5, const float xmax=1, const float ymax=1) const;
+		/// 	Draws the elements of the beam in the (x,s) plane
+		void drawX(const float, const float, const float scale=1) const;
+		/// 	Draws the elements of the beam in the (y,s) plane
+		void drawY(const float, const float) const;
+		///	Moves an element in the list, reorders the lists and recomputes the transport matrix
+		void moveElement(const string&, const float ); 
+		/// Moves the given element tranversely by given amounts.
+		void alignElement(const string&, const float, const float);
+		/// Tilts the given element tranversely by given angles.
+		void tiltElement(const string&, const float, const float);
+		///	Offsets all element in X pos from the start position
+		void offsetElements(const float start, const float offset);
+		///	Draws the beta functions, from MAD
+		//@{
+		TGraph * getBetaX() const;
+		TGraph * getBetaY() const;
+		//@}
+                ///     Draws the dispersion functions, from MAD
+                //@{
+                TGraph * getDX() const;
+                TGraph * getDY() const;
+                //@}
+                ///     Draws the relative position functions, from MAD
+                //@{
+                TGraph * getRelX() const;
+                TGraph * getRelY() const;
+                //@}
+
+
+	private:
+        	/// list of matrices, 1 matrix = the transport till the end of each element
+		vector<TMatrix> matrices; 
+	        /// transport matrix for the whole beam
+		TMatrix beam_mat;
+                /// list of all optics elements, including drifts
+                vector<H_OpticalElement*> elements;
+		/// Orderting method for the vector of H_OpticalElement*
+		struct ordering{ bool operator()(const H_OpticalElement* el1, const H_OpticalElement* el2) const {return (*el1 < *el2);}};
+		// private method for copying the contents of "elements"
+		void cloneElements(const H_AbstractBeamLine&);
+
+	protected:
+		void init(const float );
+		/// total length of the beamline
+		float beam_length;
+	friend std::ostream& operator<< (std::ostream& os, const H_AbstractBeamLine& be);
+};
+
+#endif
Index: external/Hector/H_Aperture.cc
===================================================================
--- external/Hector/H_Aperture.cc	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
+++ external/Hector/H_Aperture.cc	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
@@ -0,0 +1,107 @@
+  /* * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ *                                                         *
+*                   --<--<--  A fast simulator --<--<--     *
+*                 / --<--<--     of particle   --<--<--     *
+*  ----HECTOR----<                                          *
+*                 \ -->-->-- transport through -->-->--     *
+*                   -->-->-- generic beamlines -->-->--     *
+*                                                           *
+* JINST 2:P09005 (2007)                                     *
+*      X Rouby, J de Favereau, K Piotrzkowski (CP3)         *
+*       http://www.fynu.ucl.ac.be/hector.html               *
+*                                                           *
+* Center for Cosmology, Particle Physics and Phenomenology  *
+*              Universite catholique de Louvain             *
+*                 Louvain-la-Neuve, Belgium                 *
+ *                                                         *
+   * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+/// \file H_Aperture.cc
+/// \brief Classes aiming at simulating the aperture of the LHC beamline elements.
+
+// C++ #includes
+#include <iostream>
+
+// local #includes
+#include "H_Aperture.h"
+using namespace std;
+
+H_Aperture::H_Aperture() :
+        type_(NONE), x1(0), x2(0), x3(0), x4(0), fx(0), fy(0),  aptypestring(getApertureString()) {
+}
+
+H_Aperture::H_Aperture(const int dtype, const float size1, const float size2, const float size3, const float size4, const float posx, const float posy) :
+        type_(dtype), x1(size1), x2(size2), x3(size3), x4(size4), fx(posx), fy(posy), aptypestring(getApertureString()) {
+    /// @param dtype defines the aperture shape
+        /// @param size1, size2, size3, size4 are the geometrical sizes (length/width or great/small radii) in m
+	/// @param posx, posy are the (x,y) coordinates of the center of the aperture [m]
+}
+
+H_Aperture::H_Aperture(const H_Aperture& ap) :
+        type_(ap.type_), x1(ap.x1), x2(ap.x2), x3(ap.x3), x4(ap.x4), fx(ap.fx), fy(ap.fy), aptypestring(ap.aptypestring) {
+}
+
+H_Aperture& H_Aperture::operator=(const H_Aperture& ap) {
+	if(this==&ap) return *this;
+	type_ = ap.type_;
+	x1 = ap.x1;
+	x2 = ap.x2;
+	x3 = ap.x3;
+	x4 = ap.x4;
+	fx = ap.fx;
+	fy = ap.fy;
+	aptypestring = ap.aptypestring;
+	return *this;
+}
+
+std::ostream& operator<< (std::ostream& os, const H_Aperture& ap) {
+	os << "Aperture shape:" << ap.aptypestring << ", parameters "<<ap.x1<<", "<<ap.x2<<", "<<ap.x3<<", "<<ap.x4<<endl;
+	os << " \t Center : " << ap.fx << "," << ap.fy << endl;
+	return os;
+}
+
+void H_Aperture::printProperties() const {
+	cout << *this;
+        return;
+}
+
+void H_Aperture::setPosition(const float posx, const float posy) {
+	/// @param posx, posy are the (x,y) coordinates of the center of the apertures [m]
+	// posx, posy, fx, fy = [m]
+	fx = posx;
+	fy = posy;
+	return;
+}
+
+bool H_Aperture::isInside(const float , const float ) const {
+        /// @param x, y are the (x,y) coordinates of the proton, in [m]
+        //cout << "aperture::isInside" << endl;
+        return false;
+}
+
+
+/*void H_Aperture::setApertureString() {
+	switch (type_) {
+		case NONE: aptypestring = NONENAME; break;
+ 		case RECTANGULAR: aptypestring = RECTANGULARNAME; break;
+ 		case ELLIPTIC: aptypestring = ELLIPTICNAME; break;
+ 		case CIRCULAR: aptypestring = CIRCULARNAME; break;
+ 		case RECTELLIPSE: aptypestring = RECTELLIPSENAME; break;
+		default: aptypestring = NONENAME; break;
+	}
+}
+*/
+
+const string H_Aperture::getApertureString() const {
+	string str;
+        switch (type_) {
+                case NONE: str = NONENAME; break;
+                case RECTANGULAR: str = RECTANGULARNAME; break;
+                case ELLIPTIC: str = ELLIPTICNAME; break;
+                case CIRCULAR: str = CIRCULARNAME; break;
+                case RECTELLIPSE: str = RECTELLIPSENAME; break;
+                default: str = NONENAME; break;
+        }
+	return str;
+}
+
Index: external/Hector/H_Aperture.h
===================================================================
--- external/Hector/H_Aperture.h	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
+++ external/Hector/H_Aperture.h	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
@@ -0,0 +1,89 @@
+#ifndef _H_Aperture_
+#define _H_Aperture_
+
+  /* * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ *                                                         *
+*                   --<--<--  A fast simulator --<--<--     *
+*                 / --<--<--     of particle   --<--<--     *
+*  ----HECTOR----<                                          *
+*                 \ -->-->-- transport through -->-->--     *
+*                   -->-->-- generic beamlines -->-->--     *
+*                                                           *
+* JINST 2:P09005 (2007)                                     *
+*      X Rouby, J de Favereau, K Piotrzkowski (CP3)         *
+*       http://www.fynu.ucl.ac.be/hector.html               *
+*                                                           *
+* Center for Cosmology, Particle Physics and Phenomenology  *
+*              Universite catholique de Louvain             *
+*                 Louvain-la-Neuve, Belgium                 *
+ *                                                         *
+   * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+/// \file H_Aperture.h
+/// \brief Defines the aperture of beamline elements.
+
+// C++ #defines
+#include <string>
+#include <iostream>
+using namespace std;
+
+// local #defines
+enum {NONE=0, RECTANGULAR, ELLIPTIC, CIRCULAR, RECTELLIPSE};
+#define NONENAME        "None       "
+#define RECTANGULARNAME "Rectangle  "
+#define ELLIPTICNAME    "Ellipse    "
+#define CIRCULARNAME    "Circle     "
+#define RECTELLIPSENAME "Rectellipse"
+
+/// Defines the aperture of any optics element.
+class H_Aperture {
+
+	public:
+		/// Constructors, destructor and operators
+		//@{
+		H_Aperture();
+		H_Aperture(const int, const float, const float, const float, const float, const float, const float);
+		H_Aperture(const H_Aperture&);
+		H_Aperture& operator=(const H_Aperture&);
+		virtual ~H_Aperture() { };
+		virtual H_Aperture* clone() const { return new H_Aperture(type_,x1,x2,x3,x4,fx,fy); };
+		//@}
+
+		/// Prints the aperture features
+		//virtual void printProperties() const;
+		void printProperties() const;
+		/// Draws the aperture shape
+		virtual void draw(const float) const {return;};
+		/// Sets the (x,y) position in [m]
+		void setPosition(const float,const float);
+		/// Checks whether the point is inside the aperture or not
+		virtual bool isInside(const float, const float) const; 
+		/// Returns the (int) type of aperture
+		inline int getType() const {return type_;};
+		/// Returns the (string) type of the aperture
+		inline const string getTypeString() const { return aptypestring; }
+		
+	
+	protected:
+		/// Aperture shape (either RECTANGULAR or ELLIPTIC or ...)
+		int type_;
+		/// Aperture geometrical sizes (length/width or great/small radii) [m]
+		//@{
+		float x1, x2, x3, x4; 
+		//@}
+		/// Horizontal coordinate of the aperture center [m] (from the nominal beam position).
+		//@{
+		float fx, fy;
+		//@}
+                /// Aperture shape string
+                string aptypestring;
+		// Sets the name of the aperture from its type.
+		//void setApertureString();
+		/// Gets the name of the aperture from its type.
+		const string getApertureString() const;
+
+	friend std::ostream& operator<< (std::ostream& os, const H_Aperture& ap);
+};
+
+
+#endif
Index: external/Hector/H_Beam.cc
===================================================================
--- external/Hector/H_Beam.cc	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
+++ external/Hector/H_Beam.cc	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
@@ -0,0 +1,520 @@
+  /* * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ *                                                         *
+*                   --<--<--  A fast simulator --<--<--     *
+*                 / --<--<--     of particle   --<--<--     *
+*  ----HECTOR----<                                          *
+*                 \ -->-->-- transport through -->-->--     *
+*                   -->-->-- generic beamlines -->-->--     *
+*                                                           *
+* JINST 2:P09005 (2007)                                     *
+*      X Rouby, J de Favereau, K Piotrzkowski (CP3)         *
+*       http://www.fynu.ucl.ac.be/hector.html               *
+*                                                           *
+* Center for Cosmology, Particle Physics and Phenomenology  *
+*              Universite catholique de Louvain             *
+*                 Louvain-la-Neuve, Belgium                 *
+ *                                                         *
+   * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+/// \file H_Beam.cc
+/// \brief Describes a set a particles as a beam
+///
+
+// ROOT #includes
+#include "TGraph.h"
+#include "TRandom.h"
+
+// local #includes
+#include "H_Beam.h"
+using namespace std;
+
+H_Beam::H_Beam() {
+        setPosition(PX,PY,TX+CRANG,TY,PS);
+        setE(BE);
+        setDispersion(SX,SY,STX,STY,SS);
+        setDE(SBE);
+	Nparticles=0;
+}
+
+H_Beam::H_Beam(const H_Beam& be) {
+	beamParticles = be.beamParticles;
+	setPosition(be.fx_ini,be.fy_ini,tx_ini,ty_ini,be.fs_ini);
+	setE(be.fe_ini);
+	setDispersion(be.x_disp,be.y_disp,be.tx_disp,be.ty_disp,be.s_disp);
+	setDE(be.e_disp);
+	Nparticles = be.Nparticles;
+}
+
+H_Beam& H_Beam::operator=(const H_Beam& be) {
+	if(this==&be) return *this;
+        beamParticles = be.beamParticles;
+        setPosition(be.fx_ini,be.fy_ini,tx_ini,ty_ini,be.fs_ini);
+        setE(be.fe_ini);
+        setDispersion(be.x_disp,be.y_disp,be.tx_disp,be.ty_disp,be.s_disp);
+        setDE(be.e_disp);
+        Nparticles = be.Nparticles; 
+        return *this;
+}
+
+H_Beam::~H_Beam() {
+	beamParticles.clear(); 
+	return;
+};
+
+void H_Beam::createBeamParticles(const unsigned int Number_of_particles, const double p_mass, const double p_charge, TRandom* r) {
+	beamParticles.clear();
+	Nparticles = (Number_of_particles<1) ? 1 : Number_of_particles;
+	for (unsigned int i=0; i<Nparticles; i++) {
+		H_BeamParticle p(p_mass,p_charge);
+		p.setPosition(fx_ini,fy_ini,tx_ini,ty_ini,fs_ini);
+		p.setE(fe_ini);
+		p.smearPos(x_disp,y_disp,r);
+		p.smearAng(tx_disp,ty_disp,r);
+		p.smearE(e_disp,r);
+		p.smearS(s_disp,r);
+		if (VERBOSE) {if (i==0) cout << " x_ini , tx_ini " << p.getX() << " " << p.getTX() << endl;}
+		beamParticles.push_back(p);
+	}
+}
+
+//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) {
+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) {
+        beamParticles.clear();
+        Nparticles = (Number_of_particles<2) ? 2 : Number_of_particles;
+        float gx,gy,gs,gtx,gty,gE;
+        for (unsigned int i=0; i<Nparticles; i++) {
+                H_BeamParticle p(p_mass,p_charge);
+                if (flat) {
+                        gx = r->Uniform(fx_min,fx_max);
+                        gy = r->Uniform(fy_min,fy_max);
+                        gs = r->Uniform(fs_min,fs_max);
+                        gtx = r->Uniform(tx_min,tx_max);
+                        gty = r->Uniform(ty_min,ty_max);
+                        gE = r->Uniform(E_min,E_max);
+                } else {
+                        gx = r->Gaus((fx_min+fx_max)/2,(-fx_min+fx_max)/2);
+                        gy = r->Gaus((fy_min+fy_max)/2,(-fy_min+fy_max)/2);
+                        gs = r->Gaus((fs_min+fs_max)/2,(-fs_min+fs_max)/2);
+                        gtx = r->Gaus((tx_min+tx_max)/2,(-tx_min+tx_max)/2);
+                        gty = r->Gaus((ty_min+ty_max)/2,(-ty_min+ty_max)/2);
+                        gE = r->Gaus ((E_min+E_max)/2,(-E_min+E_max)/2);
+                }
+                p.setPosition(gx,gy,gtx,gty,gs);
+                p.setE(gE);
+                beamParticles.push_back(p);
+        }
+        return;
+}
+
+
+void H_Beam::createXScanningBeamParticles(const unsigned int Number_of_particles, const float fx_max) {
+        beamParticles.clear();
+	Nparticles = (Number_of_particles<2) ? 2 : Number_of_particles;
+        for (unsigned int i=0; i<Nparticles; i++) {
+                H_BeamParticle p;
+		float fx = fx_ini + i/(float)(Nparticles-1) * (fx_max-fx_ini);
+                p.setPosition(fx,fy_ini,0,0,fs_ini);
+                p.setE(fe_ini);
+                beamParticles.push_back(p);
+        }
+}
+
+void H_Beam::createYScanningBeamParticles(const unsigned int Number_of_particles, const float fy_max) {
+
+        beamParticles.clear();
+	Nparticles = (Number_of_particles<2) ? 2 : Number_of_particles;
+        for (unsigned int i=0; i<Nparticles; i++) {
+                H_BeamParticle p;
+                float fy = fy_ini + i/(float)(Nparticles-1) * (fy_max-fy_ini);
+                p.setPosition(fx_ini,fy,0,0,fs_ini);
+                p.setE(fe_ini);
+                beamParticles.push_back(p);
+        }
+}
+
+void H_Beam::createTXScanningBeamParticles(const unsigned int Number_of_particles, const float tx_max) {
+        beamParticles.clear();
+	Nparticles = (Number_of_particles<2) ? 2 : Number_of_particles;
+        for (unsigned int i=0; i<Nparticles; i++) {
+                H_BeamParticle p;
+                float tx = tx_ini + i/(float)(Nparticles-1) * (tx_max-tx_ini);
+                p.setPosition(fx_ini,fy_ini,tx,ty_ini,fs_ini);
+                p.setE(fe_ini);
+                beamParticles.push_back(p);
+        }
+}
+
+void H_Beam::createTYScanningBeamParticles(const unsigned int Number_of_particles, const float ty_max) {
+        beamParticles.clear(); 
+        Nparticles = (Number_of_particles<2) ? 2 : Number_of_particles;
+        for (unsigned int i=0; i<Nparticles; i++) { 
+                H_BeamParticle p; 
+                float ty = ty_ini + i/(float)(Nparticles-1) * (ty_max-ty_ini);
+                p.setPosition(fx_ini,fy_ini,tx_ini,ty,fs_ini);
+                p.setE(fe_ini); 
+                beamParticles.push_back(p); 
+        } 
+}
+
+const H_BeamParticle * H_Beam::getBeamParticle(const unsigned int particle_index) const {
+//	const int N = (particle_index<0)?0:(( particle_index>Nparticles)?Nparticles:particle_index);
+	const int N = (particle_index>Nparticles)?Nparticles:particle_index;
+	return &(*(beamParticles.begin()+N));// same as "return &beamParticles[N];" but more efficient
+}
+
+H_BeamParticle * H_Beam::getBeamParticle(const unsigned int particle_index) {
+//        const int N = (particle_index<0)?0:(( particle_index>Nparticles)?Nparticles:particle_index);
+	const int N = (particle_index>Nparticles)?Nparticles:particle_index;
+        return &(*(beamParticles.begin()+N));// same as "return &beamParticles[N];" but more efficient
+}
+
+void H_Beam::add(const H_BeamParticle &p) {
+	beamParticles.push_back(p);
+	Nparticles++;
+}
+
+void H_Beam::computePath(const H_AbstractBeamLine * beamline, const bool NonLinear) {
+	vector<H_BeamParticle>::iterator particle_i;
+
+	for (particle_i = beamParticles.begin(); particle_i < beamParticles.end(); particle_i++) {
+		particle_i->computePath(beamline,NonLinear);	
+	}
+}
+
+/// Propagates the beam until a given s
+void H_Beam::propagate(const float position) {
+	vector<H_BeamParticle>::iterator particle_i;
+	for (particle_i = beamParticles.begin(); particle_i < beamParticles.end(); particle_i++) {
+                particle_i->propagate(position);
+        }
+}
+
+void H_Beam::emitGamma(const double gee, const double gq2, const double phimin, const double phimax) {
+	/// @param gee = \f$ E_{\gamma} \f$ is the photon energy
+	/// @param gq2 = \f$ Q^2 < 0 \f$ is virtuality of photon \f$ Q^{2} = E^{2}-\vec{k}^{2} \f$
+	/// @param phimin : lower bound for \f$ \phi \f$
+	/// @param phimax : higher bound for \f$ \phi \f$
+	vector<H_BeamParticle>::iterator particle_i;
+	for (particle_i = beamParticles.begin(); particle_i < beamParticles.end(); particle_i++)
+                particle_i->emitGamma(gee,gq2,phimin,phimax);
+}
+
+float H_Beam::getBetaX(const float s, float& error_on_betax) {
+	/// @param s is the position [m] to propagate to
+	/// @param error_on_betax : getBetaX(...) returns its error in this variable
+	/// not a const method because does a propagate to s!
+	vector<H_BeamParticle>::iterator particle_i;
+	float EX2=0,dummy, mean=getX(s,dummy), temp;
+
+	for (particle_i = beamParticles.begin(); particle_i < beamParticles.end(); particle_i++) {
+		particle_i->propagate(s);
+		temp = particle_i->getX()-mean;
+		EX2 += temp*temp;
+	}
+	EX2 /= (float)Nparticles;
+	float emitx = getEmittanceX();	
+	EX2 = (emitx==0)?0:(float) (EX2 /(float) (emitx*URAD))/URAD;
+	error_on_betax = EX2 / (float) sqrt((double)2*Nparticles);
+	return EX2;
+}
+
+float H_Beam::getBetaY(const float s, float& error_on_betay) {
+        /// @param s is the position [m] to propagate to
+        /// @param error_on_betay : getBetaY(...) returns its error in this variable
+	/// not a const method because does a propagate to s!
+ 	vector<H_BeamParticle>::iterator particle_i;
+	float EY2 =0, dummy, mean=getY(s,dummy), temp;
+
+        for (particle_i = beamParticles.begin(); particle_i < beamParticles.end(); particle_i++) {
+                particle_i->propagate(s);
+		temp = particle_i->getY() - mean;
+		EY2 += temp*temp;
+	}
+	EY2 /= (float)Nparticles;
+	float emity = getEmittanceY();
+	EY2 = (emity==0)?0:(float) (EY2 / (float) (emity*URAD))/URAD;
+	error_on_betay = EY2 / (float) sqrt((double)2*Nparticles);
+	return EY2;
+}
+
+TGraphErrors * H_Beam::getBetaX(const float length, const unsigned int number_of_points) {
+	/// @param length [m]
+	/// @number_of_points in the graph (typ. 200)
+	const unsigned int N = number_of_points;
+	float * s = new float[N], * b = new float[N], * es = new float[N], * eb = new float[N];
+	for (unsigned int i=0; i<N; i++) {
+		s[i] = (float) fs_ini + i/(float)(N-1) *length; 
+		b[i] = getBetaX(s[i],eb[i]);
+		es[i] = 0;
+	}
+	TGraphErrors * betax = new TGraphErrors(N,s,b,es,eb);
+	betax->SetLineColor(kBlack);
+	betax->SetFillColor(kYellow);
+	delete [] s;
+	delete [] b;
+	delete [] es;
+	delete [] eb;
+	return betax;
+}
+
+TGraphErrors * H_Beam::getBetaY(const float length, const unsigned int number_of_points) {
+        /// @param length [m] 
+        /// @number_of_points in the graph (typ. 200)
+        const unsigned int N = number_of_points;
+        float * s = new float[N], * b = new float[N], * es = new float[N], *eb = new float[N];
+        for (unsigned int i=0; i<N; i++) {
+                s[i] = (float) fs_ini + i/(float)(N-1) *length;
+                b[i] = getBetaY(s[i],eb[i]);
+		es[i]=0;
+        }
+        TGraphErrors * betay = new TGraphErrors(N,s,b,es,eb);
+        betay->SetLineColor(kRed);
+	betay->SetFillColor(kYellow);
+        delete [] s;
+        delete [] b;
+        delete [] es;
+        delete [] eb;
+	return betay;
+}
+
+float H_Beam::getX(const float s, float& error_on_posx) {
+	vector<H_BeamParticle>::iterator particle_i;
+	float mean=0;
+
+        for (particle_i = beamParticles.begin(); particle_i < beamParticles.end(); particle_i++) {
+                particle_i->propagate(s);
+                mean += particle_i->getX();
+        }
+	mean = mean / (float) Nparticles;
+	error_on_posx = mean / (float) sqrt((double)Nparticles);
+        return mean;
+}
+
+float H_Beam::getY(const float s, float& error_on_posy) {
+	vector<H_BeamParticle>::iterator particle_i;
+	float mean=0;
+
+        for (particle_i = beamParticles.begin(); particle_i < beamParticles.end(); particle_i++) {
+                particle_i->propagate(s);
+        	mean += particle_i->getY();
+	}
+	mean = mean / (float) Nparticles;
+	error_on_posy = mean / (float) sqrt((double)Nparticles);
+        return mean;
+}
+
+unsigned int H_Beam::getStoppedNumber(const H_AbstractBeamLine * beamline) {
+	int number =0;
+	vector<H_BeamParticle>::iterator particle_i;
+	for (particle_i = beamParticles.begin(); particle_i < beamParticles.end(); particle_i++) {
+		if(particle_i->stopped(beamline)) number++;
+	}
+	return number;
+}
+
+vector<TVectorD> H_Beam::getStoppingElements(const H_AbstractBeamLine * beamline, vector<H_OpticalElement>& list, vector<int>& numb) {
+
+		vector<TVectorD> stop_positions;
+        vector<H_BeamParticle>::iterator particle_i;
+        vector<H_OpticalElement>::iterator element_i;
+        H_OpticalElement temp_el;
+        vector<int>::iterator n_i;
+        int number =0;
+        bool found;
+
+        list.clear();
+        numb.clear();
+
+        // creates a list of elements where beamParticles have stopped
+        for (particle_i = beamParticles.begin(); particle_i < beamParticles.end(); particle_i++) {
+                found = false;
+                if(particle_i->stopped(beamline)) {
+                        temp_el = *(particle_i->getStoppingElement());
+						stop_positions.push_back(*(particle_i->getStopPosition()));
+                        if(list.size()==0) {
+                                number=1;
+                                list.push_back(temp_el);
+                                numb.push_back(number);
+
+                        } else {
+                                for (element_i = list.begin(), n_i = numb.begin(); element_i < list.end(); element_i++, n_i++) {
+                                        string el_i_name = element_i->getName();
+                                        string temp_el_name = temp_el.getName();
+                                        if(el_i_name == temp_el_name) {
+                                                number = *n_i;
+                                                number++;
+                                                *n_i = number;
+                                                found = true;
+                                        }
+                                }
+                                if(!found) {
+                                                number=1;
+                                                list.push_back(temp_el);
+                                                numb.push_back(number);
+                                }
+                        }
+                } // if particle_i->stopped
+        }// for particle_i
+		return stop_positions;
+} // H_Beam::getStoppingElements
+
+void H_Beam::printInitialState() const {
+	cout << "Initial parameters of the beam" << endl;
+	cout << "(x,y,s) = (" << fx_ini << "," << fy_ini << "," << fs_ini << ") ";
+	cout << "(theta_x, theta_y) = (" << tx_ini << "," << ty_ini << ") ";
+	cout << "energy = " << fe_ini << endl; 
+	cout << endl;
+	cout << "Dispersion on these values : " << endl;
+	cout << "(dx,dy,ds) = (" << x_disp << "," << y_disp << "," << s_disp << ") ";
+	cout << "(dtheta_x, dtheta_y) = (" << tx_disp << "," << ty_disp << ") ";
+	cout << "de = " << e_disp << endl << endl;
+
+	float mean_ini =0;
+	vector<H_BeamParticle>::const_iterator particle_i;
+	for (particle_i = beamParticles.begin(); particle_i < beamParticles.end(); particle_i++) {
+		mean_ini += particle_i->getX();
+	}
+	mean_ini /= (float) beamParticles.size();
+	cout << "Mean ini x = " << mean_ini << endl;
+}
+
+std::ostream& operator<< (std::ostream& os, const H_Beam& be) {
+	vector<H_BeamParticle>::const_iterator particle_i;
+	cout << "There are " << be.Nparticles << " in the beam." << endl;
+	for (particle_i = be.beamParticles.begin(); particle_i < be.beamParticles.end(); particle_i++) {
+		cout << *particle_i;
+	}
+   return os;
+}
+
+void H_Beam::printStoppingElements(const vector<H_OpticalElement>& list, const vector<int>& numb) const{
+	/// see also H_Beam::getStoppingElements
+	vector<H_OpticalElement>::const_iterator element_i;
+	vector<int>::const_iterator n_i;
+
+	// prints the list
+	for (element_i=list.begin(), n_i = numb.begin(); element_i < list.end(); element_i++, n_i++) {
+		cout << *n_i << " particules in " << element_i->getName();
+		cout <<  " (" << element_i->getTypeString() << ") at " << element_i->getS() << "m" << endl;
+		element_i->getAperture()->printProperties();
+	}
+} // H_Beam::printStoppingElements
+
+TH2F *  H_Beam::drawAngleProfile(const float s) {
+        /// not a const method because does a propagate to s!
+        char title[50];
+        sprintf(title,"Beam profile at %.2f m",s);
+        vector<H_BeamParticle>::iterator particle_i;
+        float xmax, xmin, ymax, ymin;
+        float xx, yy, xborder, yborder;
+
+        particle_i=beamParticles.begin();
+        xmin = particle_i->getTX();
+        xmax = particle_i->getTX();
+        ymin = particle_i->getTY();
+        ymax = particle_i->getTY();
+
+        for (particle_i = beamParticles.begin(); particle_i < beamParticles.end(); particle_i++) {
+                particle_i->propagate(s);
+                xx = particle_i->getTX();
+                yy = particle_i->getTY();
+
+                xmax = xx>xmax ? xx : xmax;
+                ymax = yy>ymax ? yy : ymax;
+                xmin = xx<xmin ? xx : xmin;
+                ymin = yy<ymin ? yy : ymin;
+        }
+
+        // in order to avoid some drawing problems, when the beam divergence is null
+        if(!(xmax || xmin)) xmax +=0.1;
+        if(!(ymax || ymin)) xmax +=0.1;
+
+        if(xmax == xmin) xmax *= 1.1;
+        if(ymax == ymin) ymax *= 1.1;
+
+        xborder = (xmax-xmin)*0.2;
+        yborder = (ymax-ymin)*0.2;
+
+        xmax += xborder;
+        xmin -= xborder;
+        ymax += yborder;
+        ymin -= yborder;
+
+        TH2F * profile = new TH2F("profile",title,10000,xmin,xmax,1000,ymin,ymax);
+        for (particle_i = beamParticles.begin(); particle_i < beamParticles.end(); particle_i++) {
+                profile->Fill(particle_i->getTX(), particle_i->getTY());
+        }
+        return profile;
+}
+
+
+TH2F *  H_Beam::drawProfile(const float s) {
+	/// not a const method because does a propagate to s!
+	char title[50];
+	sprintf(title,"Beam profile at %.2f m",s);
+	vector<H_BeamParticle>::iterator particle_i;
+	float xmax, xmin, ymax, ymin;
+	float xx, yy, xborder, yborder;
+
+	particle_i=beamParticles.begin();
+	xmin = particle_i->getX();
+	xmax = particle_i->getX();
+	ymin = particle_i->getY();
+        ymax = particle_i->getY();
+
+	for (particle_i = beamParticles.begin(); particle_i < beamParticles.end(); particle_i++) {
+                particle_i->propagate(s);
+		xx = particle_i->getX();
+		yy = particle_i->getY();
+
+                xmax = xx>xmax ? xx : xmax;
+		ymax = yy>ymax ? yy : ymax;
+		xmin = xx<xmin ? xx : xmin;
+		ymin = yy<ymin ? yy : ymin;
+        }
+
+	// in order to avoid some drawing problems, when the beam divergence is null
+        if(!(xmax || xmin)) xmax +=0.1;
+        if(!(ymax || ymin)) xmax +=0.1;
+
+	if(xmax == xmin) xmax += 0.1;
+	if(ymax == ymin) ymax += 0.1;
+	
+	xborder = (xmax-xmin)*0.2;
+	yborder = (ymax-ymin)*0.2;
+
+	xmax += xborder;
+	xmin -= xborder;
+	ymax += yborder;
+	ymin -= yborder;
+
+	TH2F * profile = new TH2F("profile",title,10000,xmin,xmax,1000,ymin,ymax);
+        for (particle_i = beamParticles.begin(); particle_i < beamParticles.end(); particle_i++) {
+		profile->Fill(particle_i->getX(), particle_i->getY());
+	}
+	return profile;
+}
+
+TMultiGraph * H_Beam::drawBeamX(const int color) const {
+	int mycolor = color;
+	vector<H_BeamParticle>::const_iterator particle_i;
+	TMultiGraph * beam_profile_x = new TMultiGraph("beam_profile_x","");
+	
+	for (particle_i = beamParticles.begin(); particle_i < beamParticles.end(); particle_i++) {
+		TGraph * ppath_x = particle_i->getPath(0,mycolor);
+		beam_profile_x->Add(ppath_x);
+	}
+	return beam_profile_x;
+}
+
+TMultiGraph * H_Beam::drawBeamY(const int color) const {
+	int mycolor = color;
+        vector<H_BeamParticle>::const_iterator particle_i;
+        TMultiGraph * beam_profile_y = new TMultiGraph("beam_profile_y","");
+
+        for (particle_i = beamParticles.begin(); particle_i < beamParticles.end(); particle_i++) {
+                TGraph * ppath_y = particle_i->getPath(1,mycolor);
+                beam_profile_y->Add(ppath_y);
+        }
+        return beam_profile_y;
+}
Index: external/Hector/H_Beam.h
===================================================================
--- external/Hector/H_Beam.h	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
+++ external/Hector/H_Beam.h	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
@@ -0,0 +1,189 @@
+#ifndef _H_Beam_
+#define _H_Beam_
+
+  /* * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ *                                                         *
+*                   --<--<--  A fast simulator --<--<--     *
+*                 / --<--<--     of particle   --<--<--     *
+*  ----HECTOR----<                                          *
+*                 \ -->-->-- transport through -->-->--     *
+*                   -->-->-- generic beamlines -->-->--     *
+*                                                           *
+* JINST 2:P09005 (2007)                                     *
+*      X Rouby, J de Favereau, K Piotrzkowski (CP3)         *
+*       http://www.fynu.ucl.ac.be/hector.html               *
+*                                                           *
+* Center for Cosmology, Particle Physics and Phenomenology  *
+*              Universite catholique de Louvain             *
+*                 Louvain-la-Neuve, Belgium                 *
+ *                                                         *
+   * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+/// \file H_Beam.h
+/// \brief Describes a set a particles as a beam
+///
+
+// c++ #includes
+//#include <iostream>
+#include <vector>
+#include <sstream>
+#include <cmath>
+
+// ROOT #includes
+#include "TH2F.h"
+#include "TGraphErrors.h"
+#include "TMultiGraph.h"
+#include "TMath.h"
+
+// local #includes
+#include "H_BeamParticle.h"
+#include "H_AbstractBeamLine.h"
+#include "H_Parameters.h"
+#include "H_OpticalElement.h"
+using namespace std;
+
+/// \brief Beam made from a STL vector of H_BeamParticle.
+///
+/// Example of usage :
+/// <PRE>
+///   H_Beam mybeam;
+///   mybeam.createBeamParticles(100);
+///   H_AbstractBeamLine * beamline = new H_AbstractBeamLine(200);
+///	... (<-- fills the beam)
+///   mybeam.computePath(beamline)
+/// </PRE>
+class H_Beam {
+
+	public:
+	/// Constructors, destructor and operator
+	//@{
+		H_Beam();
+		H_Beam(const H_Beam&);
+		H_Beam& operator=(const H_Beam&);
+		~H_Beam();
+	//@}
+        /// Fills the beam with particles in given position/angle/energy        intervals (flat distribution)
+                void 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=-TMath::Pi()/2., const float tx_max=TMath::Pi()/2., const float ty_min=-TMath::Pi()/2., const float ty_max=TMath::Pi()/2., const float p_mass=MP, const double p_charge=QP, const bool flat = true, TRandom* r=gRandom);
+
+	/// Fills the beam with particles
+		void createBeamParticles(const unsigned int Number_of_particles, const double p_mass=MP, const double p_charge=QP, TRandom* r=gRandom);
+	/// Fills the beam with particles with incremental offset and no initial transverse momentum
+	//@{
+		void createXScanningBeamParticles(const unsigned int, const float);
+		void createYScanningBeamParticles(const unsigned int, const float);
+	//@}
+	/// Fills the beam with particles with incremental initial angle and no offset.
+	//@{
+		void createTXScanningBeamParticles(const unsigned int, const float);
+		void createTYScanningBeamParticles(const unsigned int, const float);
+	//@}
+	/// Returns the ith particle
+	//@{
+		const H_BeamParticle * getBeamParticle(const unsigned int ) const;
+		H_BeamParticle * getBeamParticle(const unsigned int );
+	//@}
+	/// Adds a particle to the beam
+		void add(const H_BeamParticle&);
+	/// Compute the position of each particle in the beamline
+		void computePath(const H_AbstractBeamLine * beamline, const bool NonLinear=false);
+	// Photon emission by the particle
+                void emitGamma(const double gee, const double gq2, const double phimin=0, const double phimax=2*TMath::Pi());
+	// Propagates the beam until a given s
+		void propagate(const float );
+	/// Returns the \f$ \beta \f$ function of the beam
+	//@{
+		float getBetaX(const float , float& );
+                float getBetaY(const float , float& );
+	//@}
+	/// Draws the \f$ \beta \f$ function of the beam
+	//@{
+		TGraphErrors  * getBetaX(const float, const unsigned int);
+		TGraphErrors  * getBetaY(const float, const unsigned int);
+	//@}
+        /// Returns the position of the beam
+	//@{
+                float getX(const float , float& );
+                float getY(const float , float& );
+	//@}
+	/// Returns the emittance \f$ \epsilon \f$ of the beam in x and y
+	//@{
+	inline const float getEmittanceX() const {
+			if(!x_disp*tx_disp) cout<<"Warning : Degenerate Beam : x-emittance = 0"<<endl; 	
+			return x_disp * tan(tx_disp/URAD)/URAD;
+		}
+        inline const float getEmittanceY() const { 
+			if(!y_disp*ty_disp) cout<<"Warning : Degenerate Beam : y-emittance = 0"<<endl;
+			return y_disp * tan(ty_disp/URAD)/URAD;
+		}
+	//@}
+	/// Sets the initial parameters of the beam \f$ s , x , y , \theta_x , \theta_y \f$
+	//@{
+		void setS(const float fs) { fs_ini = fs;}
+		void setX(const float fx) { fx_ini = fx;}
+		void setY(const float fy) { fy_ini = fy;}
+		void setTX(const float tx) { tx_ini = tx;}
+		void setTY(const float ty) { ty_ini = ty;}
+		void setE(const float fe) {fe_ini = fe;}
+		void setPosition(const float fx, const float fy, const float tx, const float ty, const float fs) {setS(fs); setX(fx); setY(fy); setTX(tx); setTY(ty);}
+	//@}
+	/// Sets the initial divergence of the beam \f$ \sigma_x , \sigma_y , \sigma (\theta_x), \sigma(\theta_y) \f$
+	//@{
+		void setDS(const float ds) {s_disp = ds;}
+		void setDX(const float dx) {x_disp = dx;}
+		void setDY(const float dy) {y_disp = dy;}
+		void setDTX(const float dtx) {tx_disp = dtx;}
+		void setDTY(const float dty) {ty_disp = dty;}
+		void setDE(const float de) {e_disp = de;}
+		void setDispersion(const float dx, const float dy, const float dtx, const float dty, const float ds) {setDS(ds); setDX(dx); setDY(dy); setDTX(dtx); setDTY(dty);}
+	//@} 
+	/// Returns the number of particles which have been stopped
+		unsigned int getStoppedNumber(const H_AbstractBeamLine *);
+	/// Returns the list of the stopping elements in the beamline
+		vector<TVectorD> getStoppingElements(const H_AbstractBeamLine *, vector<H_OpticalElement>&, vector<int>&);
+	/// Prints the initial parameters
+		void printInitialState() const;
+	/// Prints the properties for each particle
+		void printProperties() const {cout << *this; return;}
+	/// Prints the list of the stopping elements in the beamline
+		void printStoppingElements(const vector<H_OpticalElement>&, const vector<int>&) const;
+	/// Returns the number of particle is this beam
+		const int getNumberOfBeamParticles() const {return Nparticles;}
+	/// Draws the beam profile at a given s
+		TH2F * drawProfile(const float);
+		TH2F * drawAngleProfile(const float);
+	/// Draws the beam width and height
+	//@{
+		TMultiGraph * drawBeamX(const int) const;
+		TMultiGraph * drawBeamY(const int) const ;
+	//@}
+
+	protected:
+	/// List of particles
+		vector<H_BeamParticle> beamParticles;
+	/// IP position
+	//@{
+		float fx_ini, fy_ini, fs_ini;
+	//@}
+	/// IP \f$ \theta \f$ (angular) position
+	//@{
+		float tx_ini, ty_ini;
+	//@}
+	/// nominal beam energy
+		float fe_ini;
+	/// dispersion in position
+	//@{
+		float x_disp, y_disp, s_disp;
+	//@}
+	/// dispersion in \f$ \theta \f$
+	//@{
+		float tx_disp, ty_disp;
+	//@}
+	/// dispersion in energy
+		float e_disp;
+	/// Number of particles in this beam
+		unsigned int Nparticles;
+
+	friend std::ostream& operator<< (std::ostream& os, const H_Beam& be);
+};
+
+#endif
Index: external/Hector/H_BeamLine.cc
===================================================================
--- external/Hector/H_BeamLine.cc	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
+++ external/Hector/H_BeamLine.cc	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
@@ -0,0 +1,252 @@
+  /* * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ *                                                         *
+*                   --<--<--  A fast simulator --<--<--     *
+*                 / --<--<--     of particle   --<--<--     *
+*  ----HECTOR----<                                          *
+*                 \ -->-->-- transport through -->-->--     *
+*                   -->-->-- generic beamlines -->-->--     *
+*                                                           *
+* JINST 2:P09005 (2007)                                     *
+*      X Rouby, J de Favereau, K Piotrzkowski (CP3)         *
+*       http://www.fynu.ucl.ac.be/hector.html               *
+*                                                           *
+* Center for Cosmology, Particle Physics and Phenomenology  *
+*              Universite catholique de Louvain             *
+*                 Louvain-la-Neuve, Belgium                 *
+ *                                                         *
+   * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+/// \file H_BeamLine.cc
+/// \brief Reads external files and retrieves features of the real beam optical elements
+
+// c++ #includes
+#include <iostream>
+#include <fstream>
+#include <sstream>
+#include <cstdlib>
+
+// local #includes
+#include "H_BeamLine.h"
+#include "H_BeamLineParser.h"
+#include "H_RectEllipticAperture.h"
+#include "H_RectangularAperture.h"
+#include "H_EllipticAperture.h"
+#include "H_CircularAperture.h"
+#include "H_RectangularDipole.h"
+#include "H_SectorDipole.h"
+#include "H_HorizontalQuadrupole.h"
+#include "H_VerticalQuadrupole.h"
+#include "H_HorizontalKicker.h"
+#include "H_VerticalKicker.h"
+#include "H_RectangularCollimator.h"
+#include "H_Marker.h"
+
+using namespace std;
+
+// Caution : mad conventions for vertically(horizontally) focusing quadrupoles
+// are opposite to Wille's. See fill() for more details.
+
+H_BeamLine::H_BeamLine(): H_AbstractBeamLine(), 
+	direction(1), ips(0), ipx(0), ipy(0), iptx(0), ipty(0) {
+}
+
+H_BeamLine::H_BeamLine(const int si, const float length) : H_AbstractBeamLine(length),
+	direction((si >= abs(si)) ? 1 : -1), ips(0), ipx(0), ipy(0), iptx(0), ipty(0) {
+}
+
+H_BeamLine::H_BeamLine(const H_BeamLine& beam) : H_AbstractBeamLine(beam),
+	direction(beam.direction), ips(beam.ips), ipx(beam.ipx), ipy(beam.ipy), iptx(beam.iptx), ipty(beam.ipty) {
+}
+
+H_BeamLine& H_BeamLine::operator=(const H_BeamLine& beam) {
+	if(this==&beam) return *this;
+	H_AbstractBeamLine::operator=(beam); // call the mother's operator=
+	direction = beam.direction;
+	ips = beam.ips;
+	ipx = beam.ipx;
+	ipy = beam.ipy;
+	iptx = beam.iptx;
+	ipty = beam.ipty;
+	return *this;
+}
+
+void H_BeamLine::findIP(const string& filename, const string& ipname) {
+	// searches for the IP position in the extended table.
+	ifstream tabfile(filename.c_str());
+		if (! tabfile.is_open()) cout << "<H_BeamLine> ERROR: I Can't open \"" << filename << "\"" << endl;
+	bool found = false;
+	int N_col=0;
+	string headers[40];  // table of all column headers
+	int header_type[40]; // table of all column types
+
+	string temp_string;
+	H_BeamLineParser e;
+	istringstream curstring;
+
+	while (	getline(tabfile,temp_string)) {
+		curstring.clear(); // needed when using istringstream::str(string) several times !
+		curstring.str(temp_string);
+
+		// gets the features of each element
+		if (found) {
+			for (int col=0; col < N_col; col++) e.setProperties(curstring,header_type[col]);
+			if(strstr(e.name.c_str(),ipname.c_str())) {
+				ips = e.s; //e.printProperties();
+				ipx = e.x;
+				ipy = e.y;
+				iptx = e.px*URAD;
+				ipty = e.py*URAD;
+			}
+		} else if (strstr(temp_string.c_str(),"K0L")) {  //searches for the beginning of the element list.
+			found = true;
+
+			// reads the title of each column
+			while(curstring.good()) { curstring >> headers[N_col]; if(headers[N_col]!="*") N_col++;}
+			if(VERBOSE) cout << N_col << " columns identified" << endl;
+
+			// identifies each column
+			for (int col=0; col< N_col; col++)	header_type[col] =  column_identification(headers[col]);
+			
+			getline(tabfile,temp_string); // skip one line
+		} // if(... "K0L")
+	} // while (!eof)
+
+	if (!found) cout << "<H_BeamLine> ERROR ! IP not found." << endl;
+	tabfile.close();
+}
+
+double* H_BeamLine::getIPProperties() {
+	double* temp = new double[4];
+	temp[0] = ipx;
+	temp[1] = ipy;
+	temp[2] = iptx;
+	temp[3] = ipty;
+	return temp;
+}
+
+
+void H_BeamLine::fill(const string& filename, const int dir, const string& ipname) {
+	string headers[40];  // table of all column headers
+	int header_type[40]; // table of all column types
+	findIP(filename,ipname);
+	ifstream tabfile(filename.c_str());
+		if (! tabfile.is_open()) cout << "<H_BeamLine> ERROR: I Can't open \"" << filename << "\"" << endl;
+	if(VERBOSE) {
+		cout<<"Using file : "<< filename <<" in the "<<((direction>0)?"positive":"negative")<<" direction."<<endl;
+		cout<<"IP was found at position : "<<ips<<endl<<endl;
+	}
+	bool found = false; // found = true when the beginning of the element list is reached
+	int type, N_col=0;
+	float previous_betax =0, previous_betay=0; // needed when direction ==1
+	float previous_dx =0, previous_dy=0; // needed when direction ==1
+	float previous_x =0, previous_y=0; // needed when direction ==1
+
+	string temp_string;
+	H_BeamLineParser e;
+	istringstream curstring;
+	H_OpticalElement *el = 0;
+	H_Aperture * ap = 0;
+
+
+	while (getline(tabfile,temp_string)) {
+		curstring.clear(); // needed when using several tims istringstream::str(string)
+		curstring.str(temp_string);
+
+        // gets the features of each element
+		if (found) {
+			// reads each column
+			for (int col=0; col < N_col; col++) {
+				e.setProperties(curstring,header_type[col]);
+			}
+			//e.printProperties();
+			
+			type =0; //init
+			if(e.k0l!=0) { if(strstr(e.name.c_str(),"MB.")) type = SDIPOLE; else type = RDIPOLE;} //all SBEND seems to be called MB.xxxxx.xx
+			else if(e.k1l!=0) type = (e.k1l>0)?HQUADRUPOLE:VQUADRUPOLE;
+			else if(e.hkick!=0) type = HKICKER;
+			else if(e.vkick!=0) type = VKICKER;
+			else if(strstr(e.name.c_str(),"DRIFT")) type=DRIFT;
+			else if((strstr(e.name.c_str(),"DFB"))||(strstr(e.name.c_str(),"TAS"))||(strstr(e.name.c_str(),"TAN"))||(strstr(e.name.c_str(),"TCL"))) type = RCOLLIMATOR;
+			else if(strstr(e.name.c_str(),ipname.c_str())) { type=IP; }
+			else type=MARKER;
+			
+			e.s = (e.s > ips) ? (e.s -ips - e.l)*(direction) : (e.s-ips)*(direction);
+			
+			el=0; //init
+			switch(type) {
+				case RDIPOLE:     { el = new H_RectangularDipole(e.name.c_str(),e.s,dir*e.k0l/e.l,e.l); } break;
+				case SDIPOLE:     { el = new H_SectorDipole(e.name.c_str(),e.s,dir*e.k0l/e.l,e.l); } break;
+				case VQUADRUPOLE: { el = new H_VerticalQuadrupole(e.name.c_str(),e.s,-(e.k1l/e.l),e.l); } break;
+				case HQUADRUPOLE: { el = new H_HorizontalQuadrupole(e.name.c_str(),e.s,-(e.k1l/e.l),e.l); } break;
+				case VKICKER:     { el = new H_VerticalKicker(e.name.c_str(),e.s,e.vkick,e.l); } break;
+				case HKICKER:     { el = new H_HorizontalKicker(e.name.c_str(),e.s,e.hkick,e.l); } break;
+				case RCOLLIMATOR: { el = new H_RectangularCollimator(e.name.c_str(),e.s,e.l); } break;
+				case DRIFT: {previous_betax = e.betx; previous_betay = e.bety; previous_dx = e.dx; previous_dy = e.dy; previous_x = e.x; previous_y = e.y;} break;
+				case IP: { el = new H_Marker(e.name.c_str(),e.s); } break;
+				default: break;
+			}
+
+			if(el!=0) {
+				ap = 0; //init
+				if(e.aper_1 !=0 || e.aper_2 !=0 || e.aper_3 !=0 || e.aper_4 != 0) {
+					e.aper_1 *= URAD;
+					e.aper_2 *= URAD;
+					e.aper_3 *= URAD;
+					e.aper_4 *= URAD; // in [m] in the tables !
+
+					if(strstr(e.apertype.c_str(),"RECTELLIPSE")) 
+						ap = new H_RectEllipticAperture(e.aper_1,e.aper_2,e.aper_3,e.aper_4,0,0);
+					else if(strstr(e.apertype.c_str(),"CIRCLE")) 
+						ap = new H_CircularAperture(e.aper_1,0,0);
+					else if(strstr(e.apertype.c_str(),"RECTANGLE")) 
+						ap = new H_RectangularAperture(e.aper_1,e.aper_2,0,0);
+					else if(strstr(e.apertype.c_str(),"ELLIPSE")) 
+						ap = new H_EllipticAperture(e.aper_1,e.aper_2,0,0);
+				}
+	
+				if (direction<0) {
+					el->setBetaX(e.betx);	el->setBetaY(e.bety);
+					el->setDX(e.dx);	el->setDY(e.dy);
+					el->setRelX(e.x);	el->setRelY(e.y);
+				} else {
+					el->setBetaX(previous_betax); 	el->setBetaY(previous_betay);
+					el->setDX(previous_dx);		el->setDY(previous_dy);
+					el->setRelX(previous_x);	el->setRelY(previous_y);
+				}
+				if(ap!=0) { 
+					el->setAperture(ap);
+					delete ap;
+					// if memory is allocated, i.e. if ap!=0,
+					// it wont be deallocated in H_OpticalElement::~H_OpticalElement
+					// ap should then be deleted here
+				} // memory leak-free!
+	
+				/// Parses all the elements from the beginning of the file, 
+				/// but only keeps the ones from the IP till the desired length
+				if(e.s>=0 && e.s<beam_length) add(el);
+				else { delete el;} 
+				// NB : if "el" is added to the beamline, it will be 
+				// deleted by H_AbstractBeamLine::~H_AbstractBeamLine
+				// Otherwise, it should be deleted explicitly
+
+			} // if(el!=0)
+		} // if (found)
+		else if(strstr(temp_string.c_str(),"K0L")) { // if (!found)
+		//searches for the beginning of the element list.
+			found = true;
+
+			// reads the title of each column
+			while(curstring.good()) { curstring >> headers[N_col]; if(headers[N_col]!="*") N_col++;}
+			if(VERBOSE) cout << N_col << " columns identified" << endl;
+
+			// identifies each column
+			for (int col=0; col< N_col; col++) {
+				header_type[col] =  column_identification(headers[col]);
+			}
+			getline(tabfile,temp_string);
+		} // if temp_string <-> "K0L"
+
+	} // while (!eof)
+	tabfile.close();
+}
+
Index: external/Hector/H_BeamLine.h
===================================================================
--- external/Hector/H_BeamLine.h	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
+++ external/Hector/H_BeamLine.h	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
@@ -0,0 +1,66 @@
+#ifndef _H_BeamLine_
+#define _H_BeamLine_
+
+  /* * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ *                                                         *
+*                   --<--<--  A fast simulator --<--<--     *
+*                 / --<--<--     of particle   --<--<--     *
+*  ----HECTOR----<                                          *
+*                 \ -->-->-- transport through -->-->--     *
+*                   -->-->-- generic beamlines -->-->--     *
+*                                                           *
+* JINST 2:P09005 (2007)                                     *
+*      X Rouby, J de Favereau, K Piotrzkowski (CP3)         *
+*       http://www.fynu.ucl.ac.be/hector.html               *
+*                                                           *
+* Center for Cosmology, Particle Physics and Phenomenology  *
+*              Universite catholique de Louvain             *
+*                 Louvain-la-Neuve, Belgium                 *
+ *                                                         *
+   * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+/// \file H_BeamLine.h
+/// \brief Class aiming at retrieving features of the real beam optical elements.
+
+// local #includes
+#include "H_AbstractBeamLine.h"
+
+// C++ #includes
+#include <string>
+using namespace std;
+
+// Caution : mad conventions for vertically(horizontally) focusing quadrupoles
+// are opposite to Wille's. See fill() for more details.
+
+/// Reads external files and retrieves features of the real beam optical elements.
+class H_BeamLine : public H_AbstractBeamLine {
+
+	public:
+	///     Constructors and destructor
+	//@{
+		H_BeamLine();
+		H_BeamLine(const H_BeamLine& );
+		H_BeamLine(const int, const float);
+		H_BeamLine& operator=(const H_BeamLine& );
+		~H_BeamLine() {};
+	//@
+		///     Finds the IP position (s) from the MAD table. Should be "IP5" or "IP1".
+		void findIP(const string& filename, const string& ipname="IP5");
+		///     Reader for the external MAD table
+		void fill(const string& filename, const int dir=1, const string& ipname="IP5");
+		///     Returns the IP position (s)
+		double getIP() const {return ips;};
+		///		Returns positions and angles of beam at IP
+		double* getIPProperties();
+
+	private:
+		int direction; // to or from the IP.
+		double ips; // s-position of the IP [m]
+		double ipx; // x-position of the IP [Âµm]
+		double ipy; // y-position of the IP [Âµm]
+		double iptx; // x-angle of momentum at IP [Âµrad]
+		double ipty; // y-angle of momentum at IP [Âµrad]
+};
+
+#endif
+
Index: external/Hector/H_BeamLineParser.cc
===================================================================
--- external/Hector/H_BeamLineParser.cc	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
+++ external/Hector/H_BeamLineParser.cc	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
@@ -0,0 +1,136 @@
+  /* * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ *                                                         *
+*                   --<--<--  A fast simulator --<--<--     *
+*                 / --<--<--     of particle   --<--<--     *
+*  ----HECTOR----<                                          *
+*                 \ -->-->-- transport through -->-->--     *
+*                   -->-->-- generic beamlines -->-->--     *
+*                                                           *
+* JINST 2:P09005 (2007)                                     *
+*      X Rouby, J de Favereau, K Piotrzkowski (CP3)         *
+*       http://www.fynu.ucl.ac.be/hector.html               *
+*                                                           *
+* Center for Cosmology, Particle Physics and Phenomenology  *
+*              Universite catholique de Louvain             *
+*                 Louvain-la-Neuve, Belgium                 *
+ *                                                         *
+   * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+/// \file H_BeamLineParser.cc
+/// \brief Reader for madx tables
+///
+/// Notes : Verifier que tous les SBEND sont toujours appeles MB. Et seulement comme ca !
+/// Verifier qu'il n'y a pas de problemes d'inversion H/V QUADRUPOLES
+/// no distinction between H and Vkickers ?
+/// The identification of the element is based on the values of k1l, k2l, hkick, vkick and on their name.
+/// x and y are put in m
+
+// c++ #includes
+#include <iostream>
+#include <fstream>
+#include <sstream>
+
+//local #includes
+#include "H_BeamLineParser.h"
+#include "H_Parameters.h"
+using namespace std;
+
+
+/// Identifies the column content from its header
+int column_identification(const string& header) {
+	// identifies the column type from its name
+
+	     if (header=="NAME")    {return MADX_NAME; }
+	else if (header=="KEYWORD") {return MADX_KEYWORD; }
+	else if (header=="S")       {return MADX_S; }
+	else if (header=="L")       {return MADX_L; }
+	else if (header=="K0L")     {return MADX_K0L; }
+	else if (header=="K1L")     {return MADX_K1L;}
+	else if (header=="K2L")     {return MADX_K2L;}
+	else if (header=="K3L")     {return MADX_K3L;}
+	else if (header=="HKICK")   {return MADX_HKICK;}
+	else if (header=="VKICK")   {return MADX_VKICK;}
+	else if (header=="KICK")    {return MADX_KICK;}
+	else if (header=="BETX")    {return MADX_BETX;}
+	else if (header=="BETY")    {return MADX_BETY;}
+	else if (header=="ALFX")    {return MADX_ALFX;}
+	else if (header=="ALFY")    {return MADX_ALFY;}
+	else if (header=="MUX")     {return MADX_MUX;}
+	else if (header=="MUY")     {return MADX_MUY;}
+	else if (header=="DX")      {return MADX_DX;}
+	else if (header=="DY")      {return MADX_DY;}
+	else if (header=="DPX")     {return MADX_DPX;}
+	else if (header=="DPY")     {return MADX_DPY;}
+	else if (header=="X")       {return MADX_X;}
+	else if (header=="Y")       {return MADX_Y;}
+	else if (header=="PX")      {return MADX_PX;}
+	else if (header=="PY")      {return MADX_PY;}
+	else if (header=="APERTYPE") {return MADX_APERTYPE;}
+	else if (header=="APER_1")  {return MADX_APER_1;}
+	else if (header=="APER_2")  {return MADX_APER_2;}
+	else if (header=="APER_3")  {return MADX_APER_3;}
+	else if (header=="APER_4")  {return MADX_APER_4;}
+	else if (header=="PARENT")  {return MADX_PARENT;}
+	return MADX_UNKNOWN;
+}
+
+void H_BeamLineParser::init() {
+	name=""; 
+	apertype="";
+	keyword="";
+	parent="";
+	s=0;  l=0;  k0l=0;  k1l=0;  k2l=0;  k3l=0;  hkick=0;  vkick=0;  betx=0;
+	alfx=0;  mux=0;  dx=0;  dpx=0;  x=0;  px=0;  bety=0;  alfy=0;  muy=0;
+	dy=0;  dpy=0;  y=0;  py=0;  aper_1=0;  aper_2=0;  aper_3=0;  aper_4=0;
+}
+
+void H_BeamLineParser::setProperties(istream& input, const unsigned int col_type) {
+
+	switch(col_type) {
+		case   MADX_NAME:    input >> name; break;
+		case   MADX_KEYWORD: input >> keyword; break;
+		case   MADX_S:       input >> s; break;
+		case   MADX_L:       input >> l;   break;
+		case   MADX_K0L:     input >> k0l; break;
+		case   MADX_K1L :    input >> k1l; break;
+		case   MADX_K2L:     input >> k2l; break;
+		case   MADX_K3L:     input >> k3l; break;
+		case   MADX_HKICK:   input >> hkick; break;
+		case   MADX_VKICK:   input >> vkick; break;
+		case   MADX_BETX:    input >> betx; break;
+		case   MADX_ALFX:    input >> alfx; break;
+		case   MADX_MUX:     input >> mux; break;
+		case   MADX_DX:      input >> dx; break;
+		case   MADX_DPX:     input >> dpx; break;
+		case   MADX_X:       input >> x; x *=URAD; break;
+		case   MADX_PX:      input >> px; break;
+		case   MADX_BETY:    input >> bety; break;
+		case   MADX_ALFY:    input >> alfy; break;
+		case   MADX_MUY:     input >> muy; break;
+		case   MADX_DY:      input >> dy; break;
+		case   MADX_DPY:     input >> dpy; break;
+		case   MADX_Y:       input >> y; y*=URAD; break;
+		case   MADX_PY:      input >> py; break;
+		case   MADX_APERTYPE: input >> apertype; break;
+		case   MADX_APER_1:  input >> aper_1; break;
+		case   MADX_APER_2:  input >> aper_2; break;
+		case   MADX_APER_3:  input >> aper_3; break;
+		case   MADX_APER_4:  input >> aper_4; break;
+ 		case   MADX_PARENT:  input >> parent; break;
+		default:break;
+	} // switch
+}
+
+
+void H_BeamLineParser::printProperties() const {
+//KEYWORD	NAME	PARENT	L	K0L	K1L	K2L	K3L	S	BETX	BETY	DX	DY	XC	YC	ALFX	ALFY	MUX	MUY	DPX	PXC	PYC
+	cout << " keyword = " << keyword;
+	cout << " name = " << name;
+	cout << " l = " << l;
+	cout << " k0l = " << k0l;
+	cout << " k1l = " << k1l;
+	cout << " k2l = " << k2l;
+	cout << " k3l = " << k3l;
+	cout << " s = " << s << endl;
+	cout << endl;
+}
Index: external/Hector/H_BeamLineParser.h
===================================================================
--- external/Hector/H_BeamLineParser.h	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
+++ external/Hector/H_BeamLineParser.h	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
@@ -0,0 +1,124 @@
+#ifndef _H_BeamLineParser_
+#define _H_BeamLineParser_
+
+  /* * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ *                                                         *
+*                   --<--<--  A fast simulator --<--<--     *
+*                 / --<--<--     of particle   --<--<--     *
+*  ----HECTOR----<                                          *
+*                 \ -->-->-- transport through -->-->--     *
+*                   -->-->-- generic beamlines -->-->--     *
+*                                                           *
+* JINST 2:P09005 (2007)                                     *
+*      X Rouby, J de Favereau, K Piotrzkowski (CP3)         *
+*       http://www.fynu.ucl.ac.be/hector.html               *
+*                                                           *
+* Center for Cosmology, Particle Physics and Phenomenology  *
+*              Universite catholique de Louvain             *
+*                 Louvain-la-Neuve, Belgium                 *
+ *                                                         *
+   * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+/// \file H_BeamLineParser.h
+/// \brief Reader for madx tables
+///
+/// Notes : Verifier que tous les SBEND sont toujours appeles MB. Et seulement comme ca !
+/// Verifier qu'il n'y a pas de probleme d'inversion H/V QUADRUPOLES
+/// no distinction between H and Vkickers ?
+/// The identification of the element is based on the values of k1l, k2l, hkick, vkick and on their name.
+
+// c++ #includes
+#include <iostream>
+#include <string>
+#include <fstream>
+#include <sstream>
+using namespace std;
+
+// local defines
+#define MADX_UNKNOWN 0
+#define MADX_NAME    1
+#define MADX_KEYWORD 2
+#define MADX_S       3
+#define MADX_L       4
+#define MADX_K0L     5
+#define MADX_K1L     6
+#define MADX_K2L     7
+#define MADX_K3L     8
+#define MADX_HKICK   9
+#define MADX_VKICK  10
+#define MADX_BETX   11
+#define MADX_ALFX   12
+#define MADX_MUX    13
+#define MADX_DX     14
+#define MADX_DPX    15
+#define MADX_X      16
+#define MADX_PX     17
+#define MADX_BETY   18
+#define MADX_ALFY   19
+#define MADX_MUY    20
+#define MADX_DY     21
+#define MADX_DPY    22
+#define MADX_Y      23
+#define MADX_PY     24
+#define MADX_APERTYPE 25
+#define MADX_APER_1 26
+#define MADX_APER_2 27
+#define MADX_APER_3 28
+#define MADX_APER_4 29
+#define MADX_KICK 30
+#define MADX_PARENT 31
+/* Apertures # parameters
+	CIRCLE 1
+	ELLIPSE	2
+	RECTANGLE	2
+	LHCSCREEN	3
+	MARGUERITE	3
+	RECTELLIPSE	4
+	RACETRACK	3
+*/
+
+extern int column_identification(const string& );
+
+/// \brief Reader for madx tables to use in H_BeamLine
+///
+/// More info on http://project-mad9.web.cern.ch/project-mad9/mad/mad9/user/index.html
+class H_BeamLineParser {
+
+	public:
+	/// Constructor and destructor
+	//@{
+		H_BeamLineParser() {init();}
+		~H_BeamLineParser() {}
+	//@}
+		void init();
+		/// Retrieve the data from the line it reads, and sets the corresponding variable.
+		void setProperties(istream& , const unsigned int );
+		void printProperties() const;
+		string name, apertype, keyword, parent;
+		/// Optical element longitudinal (co-moving) coordinate.
+		double s;
+		/// Length of the element.
+		double l;
+	/// Magnetic field strength.
+	//@{
+		double k0l, k1l, k2l, k3l, hkick, vkick;
+	//@}
+	/// Phase (mu), \f$ \alpha \f$(alf) and \f$ \beta \f$(bet) functions, given by MAD.
+	//@{
+		double mux, muy, betx, alfx, bety, alfy;
+	//@}
+	/// Positions and their dispersion
+	//@{ 
+		double x, y, dx, dy;
+	//@}
+	/// Momentum and their dispersion
+	//@{
+		double px, py, dpx, dpy;
+	//@}
+	/// Aperture parameters
+	//@{
+		double aper_1, aper_2, aper_3, aper_4;
+	//@}
+};
+
+#endif
Index: external/Hector/H_BeamParticle.cc
===================================================================
--- external/Hector/H_BeamParticle.cc	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
+++ external/Hector/H_BeamParticle.cc	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
@@ -0,0 +1,640 @@
+  /* * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ *                                                         *
+*                   --<--<--  A fast simulator --<--<--     *
+*                 / --<--<--     of particle   --<--<--     *
+*  ----HECTOR----<                                          *
+*                 \ -->-->-- transport through -->-->--     *
+*                   -->-->-- generic beamlines -->-->--     *
+*                                                           *
+* JINST 2:P09005 (2007)                                     *
+*      X Rouby, J de Favereau, K Piotrzkowski (CP3)         *
+*       http://www.fynu.ucl.ac.be/hector.html               *
+*                                                           *
+* Center for Cosmology, Particle Physics and Phenomenology  *
+*              Universite catholique de Louvain             *
+*                 Louvain-la-Neuve, Belgium                 *
+ *                                                         *
+   * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+/// \file H_BeamParticle.cc
+/// \brief Class aiming at simulating a particle in the LHC beam
+
+// from IP to RP, with emission of a photon of defined energy and Q.
+// Units : angles [rad], distances [m], energies [GeV], c=[1].
+// !!! no comment statement at the end of a #define line !!!
+
+// c++ #includes
+#include <iostream>
+#include <fstream>
+#include <iomanip>
+#include <vector>
+#include <string>
+#include <cmath>
+
+// ROOT #includes
+#include "H_Parameters.h"
+#include "TRandom.h"
+#include "TVectorD.h"
+#ifdef _include_pythia_
+#include "TPythia6.h"
+#endif
+
+// local #includes
+#include "H_OpticalElement.h"
+#include "H_BeamParticle.h"
+#include "H_Drift.h"
+
+using namespace std;
+
+void H_BeamParticle::init() { // for more efficiency, put the objects away from init!
+	mp = MP;
+	qp = QP;
+        fx = 0;
+        fy = 0;
+        thx = 0;
+        thy = 0;
+        fs = 0;
+        energy = BE;
+        hasstopped = false;
+        hasemitted = false;
+	isphysical = true;
+	addPosition(fx,thx,fy,thy,fs);
+	stop_position = new TVectorD(LENGTH_VEC);
+	for (int i=0; i<LENGTH_VEC; i++) (*stop_position)[i] = -1;
+	stop_element = 0;
+}
+
+H_BeamParticle::H_BeamParticle() { 
+	init();
+}
+
+H_BeamParticle::H_BeamParticle(const H_BeamParticle& p): 
+	mp(p.mp), qp(p.qp), fs(p.fs), fx(p.fx), fy(p.fy), thx(p.thx), thy(p.thy), 
+	energy(p.energy), hasstopped(p.hasstopped), hasemitted(p.hasemitted),
+	isphysical(p.isphysical), stop_position(new TVectorD(*(p.stop_position))),
+	stop_element(0), positions(p.positions) {
+	if(p.hasstopped) stop_element = new H_OpticalElement(*(p.stop_element)); 
+}
+
+H_BeamParticle::H_BeamParticle(const double mass, const double charge) {
+	init();
+	mp = mass;
+	qp = (mass==0) ? 0 : charge;
+	/// rejects particles with mass = 0 and charge != 0
+}
+
+H_BeamParticle& H_BeamParticle::operator=(const H_BeamParticle& p) {
+	if(this==&p) return *this;
+	mp = p.mp;
+	qp = p.qp;
+        fx = p.fx;
+        fy = p.fy;
+        thx = p.thx;
+        thy = p.thy;
+        fs = p.fs;
+        energy = p.energy;
+        hasstopped = p.hasstopped;
+        hasemitted = p.hasemitted;
+	isphysical = p.isphysical;
+        stop_position = new TVectorD(*(p.stop_position));
+	if(p.hasstopped) stop_element = new H_OpticalElement(*(p.stop_element));
+	else stop_element = 0;
+        positions = p.positions;
+	return *this;
+}
+
+const bool H_BeamParticle::stopped(const H_AbstractBeamLine * beamline) {
+	vector<TVectorD>::const_iterator position_i;
+	for(position_i = positions.begin(); position_i < positions.end()-1; position_i++) {
+		const unsigned int pos = position_i-positions.begin();
+		if(beamline->getElement(pos)->getAperture()->getType()!=NONE) {
+			bool has_passed_entrance = beamline->getElement(pos)->isInside((*position_i)[INDEX_X],(*position_i)[INDEX_Y]);
+			bool has_passed_exit     = beamline->getElement(pos)->isInside((*(position_i+1))[INDEX_X],(*(position_i+1))[INDEX_Y]);
+			// here we should distinguish between particles passing the input or not.
+			//  - particles not passing the input are logically stopped at the input position. period.
+			//  - particles passing the input but not the output are stopped somewhere in the element
+			//  - particles passing both the input and the output could have been stopped somewhere inside too (less likely)
+			if(!has_passed_entrance) {
+				if(VERBOSE) cout<<"Stopped at the entrance of "<<beamline->getElement(pos)->getName();
+				hasstopped=true;
+				stop_element = const_cast<H_OpticalElement*>(beamline->getElement(pos));
+				*stop_position = *position_i;
+				if(VERBOSE) cout<<" at s = "<<(*stop_position)[4]<<endl;
+				return hasstopped;
+			} else if (!has_passed_exit) {
+				if(VERBOSE) cout<<"Stopped inside "<<beamline->getElement(pos)->getName();
+				hasstopped=true;
+				stop_element = const_cast<H_OpticalElement*>(beamline->getElement(pos));
+				// this should be computed using the element-based method "H_OpticalElement::getHitPosition" (caution : always nonlinear).
+				*stop_position = beamline->getElement(pos)->getHitPosition(*position_i,BE-energy,mp,qp);
+				if(VERBOSE) cout<<" at s = "<<(*stop_position)[4]<<endl;
+				return hasstopped;
+			}
+/*
+			if(!(has_passed_entrance && has_passed_exit)) {
+				if(VERBOSE) cout<<"particle stopped at "<<(beamline->getElement(pos))->getName();
+				if(VERBOSE) cout<<" (s = "<<(*position_i)[4] << ")" << endl;
+				hasstopped=true;
+				stop_element = const_cast<H_OpticalElement*>(beamline->getElement(pos));
+				*stop_position = *position_i;
+				return hasstopped;
+			} // if
+*/
+		} // if
+	} // for
+	return hasstopped;
+}
+
+void H_BeamParticle::addPosition(const double x, const double tx, const double y, const double ty, const double s) {
+			// [x] = [y] = m ; [tx] = [ty] = rad; [s] = m
+		double xys[LENGTH_VEC];
+		xys[INDEX_X]=x;
+		xys[INDEX_TX]=tx;
+		xys[INDEX_Y]=y;
+		xys[INDEX_TY]=ty;
+		xys[INDEX_S]=s;
+		
+		TVectorD temp_vec(LENGTH_VEC,xys);
+		positions.push_back(temp_vec);
+}
+
+
+
+void H_BeamParticle::smearPos(const double dx,const double dy, TRandom* r) {
+  // the beam is centered on (fx,fy) at IP
+        fx = r->Gaus(fx,dx);
+        fy = r->Gaus(fy,dy);
+        positions.clear();
+        addPosition(fx,thx,fy,thy,fs);
+        return;
+}
+
+void H_BeamParticle::smearAng(const double tx, const double ty, TRandom* r) {
+  // the beam transverse direction is centered on (thx,thy) at IP
+        thx = r->Gaus(thx,tx);
+        thy = r->Gaus(thy,ty);
+	positions.clear();
+	addPosition(fx,thx,fy,thy,fs);
+	return;
+}
+
+void H_BeamParticle::smearE(const double erre, TRandom* r) {
+	energy = r->Gaus(energy,erre);
+	return;
+}
+
+void H_BeamParticle::smearS(const double errs, TRandom* r) {
+        fs= r->Gaus(fs,errs);
+	positions.clear();
+	addPosition(fx,thx,fy,thy,fs);
+        return;
+}
+
+
+void H_BeamParticle::set4Momentum(const double px, const double py, const double pz, const double ene) {
+	/// @param px, py, pz, ene is \f$ (\vec p , E) [GeV]\f$ 
+	///
+	/// Clears the H_BeamParticle::positions vector.
+	positions.clear();
+	if(pz==0) {
+		cout<<" ERROR in H_BeamParticle::set4Momentum : no momentum in the beamline direction !"<<endl;
+		return;
+	}
+        thx = thx + URAD*atan(px/pz);
+        thy = thy + URAD*atan(py/pz);
+        energy = ene;
+	positions.clear();
+        addPosition(fx,thx,fy,thy,fs);
+	return;
+}
+
+void H_BeamParticle::set4Momentum(const TLorentzVector& pmu) {
+	/// @param pmu is the particle 4-momentum \f$ p^\mu \f$
+	///
+	/// Clears the H_BeamParticle::positions vector.
+	set4Momentum(pmu.Px(), pmu.Py(), pmu.Pz(), pmu.E());
+}
+
+void H_BeamParticle::setE(const double ene) {
+	energy = ene;
+	return;
+}
+
+void H_BeamParticle::setPosition(const double x, const double y, const double tx, const double ty, const double s) {
+	/// @param x, y are the transverse positions in \f$ \mu \f$ m
+	/// @param tx, ty are the angles in \f$ \mu \f$ rad
+	/// @param s is the longitudinal coordinate in m
+	// clear positions and sets the initial one.
+		fx=x;
+		fy=y;
+		thx=tx;
+		thy=ty;
+		fs = s;
+		positions.clear();
+		addPosition(fx,thx,fy,thy,s);
+
+	return;
+}
+
+const H_OpticalElement* H_BeamParticle::getStoppingElement() const{
+	if(hasstopped) return stop_element;
+	else { H_OpticalElement * dummy_el = new H_Drift("",0,0); return dummy_el;}
+}
+
+void H_BeamParticle::emitGamma(const double gee, const double gq2, const double phimin, const double phimax) {
+	/// @param gee = \f$ E_{\gamma} \f$ is the photon energy
+	/// @param gq2 = Q < 0 is virtuality of photon \f$ Q^{2} = E^{2}-\vec{k}^{2} \f$
+	/// @param phimin : lower bound for \f$ phi \f$
+	/// @param phimax : higher bound for \f$ phi \f$
+
+	if(gq2==0) { 
+		if(VERBOSE) cout<<"No virtuality : only energy has changed"<<endl;
+		setE(energy-gee);
+	    return;	
+	}
+
+	double m1 = mp;
+
+	double e1 = energy , e2 = energy - gee; // particle energy : before (1) / after (2)
+
+	double p1 = sqrt(pow(e1,2) - pow(m1,2)), p2 = sqrt(pow(e2,2) - pow(m1,2)); // particle momentum : before (1) / after (2)
+	double q2min = pow(gee,2) - pow(p1+p2,2); // lower bound from kinematics E^2 - (p1 + p2)^2
+	double q2max = -2 * pow(m1*gee/(p1+p2),2) * (1 + (pow(e1,2) + pow(e2,2) -pow(m1,2))/(e1*e2 + p1*p2) );
+			// upper bound from kinematics ; E^2 - (p1-p2)^2; is bad for numerical computations
+
+
+	// if q2min < q2 < q2max is NOT true, there will be mathematical problems (like cos(eta) > 1).
+	// so if q2 > q2max, we force q2 = q2max (-> cos(eta) = 1)
+	// and if q2 < q2min, we force q2 = q2min (-> cos(eta) = 1)
+	// BUT the user knows something was wrong with the value of "H_BeamParticle::isphysical"
+	const double q2 = (gq2 > q2max ) ? q2max : (gq2 < q2min) ? q2min : gq2;
+	
+	if( (gq2>q2max) || (gq2<q2min)) {
+		if(VERBOSE) cout<<"<H_BeamParticle> WARNING : Non physical particle ! Q2 (" << q2 << ") and E ("<<gee << ") are not compatible." << endl; 
+		isphysical = false; 
+	}
+
+	if(hasemitted) { cout<<"<H_BeamParticle> WARNING : particle has already emitted at least one gamma !"<<endl;}
+	hasemitted = true;
+	energy = energy - gee;
+	// gkk is k
+	double gkk = sqrt(pow(gee,2)-q2);
+	// eta is the angle between gamma and initial direction of the gamma-emitting particle
+        // ceta = cos(eta) and seta = sin(eta)
+
+	double ceta = sqrt( pow(mp/p1,2) + 1  ) * sqrt( q2/pow(gkk,2) + 1 ) - q2/(2*p1*gkk);
+	double seta = sqrt(1 - ceta*ceta); 
+	// theta is the angle between particle and beam
+        double theta = URAD*atan(seta/(BE/gkk - ceta));
+        double phi = phimin + gRandom->Uniform(phimax-phimin);
+        thx = thx + theta*cos(phi);
+        thy = thy - theta*sin(phi);
+
+	// caution : emitting a photon erases all known positions !
+	positions.clear();
+	addPosition(fx,thx,fy,thy,fs);
+	return;
+}
+
+void H_BeamParticle::doInelastic() {
+#ifdef _include_pythia_
+//	if(!gROOT->GetClass("TPythia6")) {
+//		gROOT->Reset();
+//	        gSystem->Load("libPythia6");
+//	        gSystem->Load("libEG");
+//	        gSystem->Load("libEGPythia6");
+//	}
+	
+	TPythia6 gen;
+	// select AB -> AX process 
+        gen.SetMSEL(0);
+        gen.SetMSUB(93,1);
+	// no showers/decays
+	gen.SetMSTP(111,0);
+	// no printouts
+	gen.SetMSTP(122,0);
+	gen.SetMSTU(12,0);
+	// generator initialization
+        gen.Initialize("CMS","p","p",14000);
+	// event generation
+	gen.GenerateEvent();
+	// list particles
+//	gen.Pylist(1);
+	thx = thx + URAD*atan(gen.GetP(5,1)/gen.GetP(5,3));
+	thy = thy + URAD*atan(gen.GetP(5,2)/gen.GetP(5,3));
+	energy = gen.GetP(5,4);
+	positions.clear();
+	addPosition(fx,thx,fy,thy,fs);
+#endif
+	return;
+}
+
+std::ostream& operator<< (std::ostream& os, const H_BeamParticle& p) {
+        os << " M   = " << p.getM()  << "GeV ";
+        os << " Q   = " << p.getQ()  << "e";
+        os << " fx  = " << p.getX()  << "m   ";
+        os << " fy  = " << p.getY()  << "m   ";
+        os << " thx = " << p.getTX() << "rad ";
+        os << " thy = " << p.getTY() << "rad ";
+        os << endl;
+   return os;
+}
+
+/// The phase space vector is (x,x',y,y',E)
+/// [x] = [y] = meters
+/// [x'] = [y'] = 1  with x' = dx/ds = tan (thetaX)
+/// [E] = GeV
+const TMatrixD * H_BeamParticle::getV() const {
+	double vec[MDIM] = {fx/URAD, tan(thx/URAD), fy/URAD, tan(thy/URAD),energy};
+	TMatrixD * mat = new TMatrixD(1,MDIM,vec);
+	return mat;
+}	
+
+void H_BeamParticle::printV() const {
+	TMatrixD X(*getV());
+	cout << " x  = " << (X.GetMatrixArray())[0] << "m ";
+	cout << " x' = " << (X.GetMatrixArray())[1] << "  ";
+	cout << " y  = " << (X.GetMatrixArray())[2] << "m ";
+	cout << " y' = " << (X.GetMatrixArray())[3] << "  ";
+	cout << endl;
+	return;
+}
+
+void H_BeamParticle::propagate(const double position) {
+	/// @param position is the s coordinate in m to reach
+	/// Does not propagate if position is in the middle of an otics element of the beamline.
+        vector<TVectorD>::const_iterator position_i = positions.begin();
+	double l = 0.;
+	if(position != fs) { // avoid repeating the computation if already done at this position
+		if(position == (*position_i)[INDEX_S]) {
+			fs = position;
+			fx = (*position_i)[INDEX_X];
+			fy = (*position_i)[INDEX_Y];
+			thx= (*position_i)[INDEX_TX];
+			thy= (*position_i)[INDEX_TY]; 
+			return;
+		} else 
+        	for(position_i = positions.begin(); position_i < positions.end(); position_i++) {
+			if((*position_i)[INDEX_S]>=position) {
+				if(position_i==positions.begin()) {
+					if(VERBOSE) cout<<"<H_BeamParticle> ERROR : non reachable value"<<endl;
+					return;
+				}
+				l = (*position_i)[INDEX_S] - (*(position_i-1))[INDEX_S];
+				if(l==0) {
+					if(VERBOSE) cout<<"<H_BeamParticle> WARNING : no luck in choosing position, no propagation done"<<endl;
+					return;
+				}
+				fs = position;
+				fx = (*(position_i-1))[INDEX_X] + (position-(*(position_i-1))[INDEX_S])*((*position_i)[INDEX_X] - (*(position_i-1))[INDEX_X])/l;
+				fy = (*(position_i-1))[INDEX_Y] + (position-(*(position_i-1))[INDEX_S])*((*position_i)[INDEX_Y] - (*(position_i-1))[INDEX_Y])/l;
+				thx = (*(position_i-1))[INDEX_TX];
+				thy = (*(position_i-1))[INDEX_TY];
+				return;
+			}
+		}
+		position_i = positions.begin();
+		cout << "Desired position is : " << position << " & positions.begin() is " << (*position_i)[INDEX_S] << endl;
+		cout<<"<H_BeamParticle> ERROR : position not reachable"<<endl;	
+		return;
+	}
+}
+
+/// Caution : do not use this method (obsolete) !!!
+void H_BeamParticle::propagate(const H_AbstractBeamLine * beam, const H_OpticalElement * element) {
+	TMatrixD X(*getV());
+	X *= beam->getPartialMatrix(element);
+	fx = URAD*(X.GetMatrixArray())[0];
+	thx = URAD*atan((X.GetMatrixArray())[1]);
+	fy = URAD*(X.GetMatrixArray())[2];
+	thy = URAD*atan((X.GetMatrixArray())[3]);
+	return;
+}
+
+void H_BeamParticle::propagate(const H_AbstractBeamLine * beam, const string& el_name) {
+	propagate(beam->getElement(el_name)->getS()+beam->getElement(el_name)->getLength());
+	return;
+}
+
+void H_BeamParticle::propagate(const H_AbstractBeamLine * beam) {
+	TMatrixD X(*getV());
+	X  *= beam->getBeamMatrix();
+	fx  = URAD*(X.GetMatrixArray())[0];
+	thx = URAD*atan((X.GetMatrixArray())[1]);
+	fy  = URAD*(X.GetMatrixArray())[2];
+	thy = URAD*atan((X.GetMatrixArray())[3]);
+	return;
+}
+
+void H_BeamParticle::showPositions() const{
+	vector<TVectorD>::const_iterator position_i;
+	TVectorD temp_vec(LENGTH_VEC);
+
+	for(position_i = positions.begin(); position_i < positions.end(); position_i++) {
+		cout << "Vector (x,y,s) = (" << (*position_i)[INDEX_X] << ", " << (*position_i)[INDEX_Y] << ", " << (*position_i)[INDEX_S] << "). " << endl;
+	}
+	return ;
+}
+
+TGraph * H_BeamParticle::getPath(const int x_or_y, const int color) const{
+        /// @param x_or_y = 0(1) draws the x(y) component;
+
+        const int N = (int) positions.size();
+		int mycolor = color;
+        if(N<2) cout<<"<H_BeamParticle> WARNING : particle positions not calculated : please run computePath"<<endl; 
+        double * s = new double[N], * graph = new double[N];
+
+        int index;
+        if(x_or_y==0) {index = INDEX_X;} else {index = INDEX_Y;}
+
+        vector<TVectorD>::const_iterator position_i;
+        for(position_i = positions.begin(); position_i < positions.end(); position_i++) {
+                graph[(int)(position_i-positions.begin())] = (*position_i)[index];
+                s[(int)(position_i-positions.begin())] = (*position_i)[INDEX_S];
+        }
+
+        TGraph * ppath = new TGraph(N,s,graph);
+        ppath->SetLineColor(mycolor);
+	delete [] s;
+	delete [] graph;
+        return ppath;
+}
+
+void H_BeamParticle::getPath(const int x_or_y, const string& filename) const{
+        /// @param x_or_y = 0(1) draws the x(y) component;
+	ofstream outfile(filename.c_str());
+
+        int index;
+        if(x_or_y==0) {index = INDEX_X;} else {index = INDEX_Y;}
+
+        vector<TVectorD>::const_iterator position_i;
+        for(position_i = positions.begin(); position_i < positions.end(); position_i++) {
+		outfile << (*position_i)[index] << "\t" << (*position_i)[INDEX_S] << endl;
+        }
+	outfile.close();
+}
+
+
+// should be removed later, to keep only computePath(const H_AbstractBeamLine & , const bool)
+void H_BeamParticle::computePath(const H_AbstractBeamLine * beam, const bool NonLinear) {
+	TMatrixD temp_mat(MDIM,MDIM);
+	double temp_x, temp_y, temp_s, temp_tx, temp_ty;
+
+	temp_x = (positions.front())[INDEX_X];
+        temp_tx = (positions.front())[INDEX_TX];
+        temp_y = (positions.front())[INDEX_Y];
+        temp_ty = (positions.front())[INDEX_TY];
+        temp_s = (positions.front())[INDEX_S];
+
+		double vec[MDIM] = {temp_x/URAD, tan(temp_tx/URAD), temp_y/URAD, tan(temp_ty/URAD),energy,1};
+
+		extern bool relative_energy;
+		if(relative_energy) {
+        	vec[4] = energy-BE;
+		} else {
+        	vec[4] = energy;
+		}
+
+	TMatrixD mat(1,MDIM,vec);
+
+	const int N =beam->getNumberOfElements();
+	double xys[LENGTH_VEC];
+
+	double energy_loss = NonLinear?BE-energy:0;
+
+	for (int i=0; i<N; i++) {
+		const unsigned pos = i;
+		if(fs < beam->getElement(pos)->getS() && fs > beam->getElement(pos-1)->getS()) {
+			if(beam->getElement(pos-1)->getType()!=DRIFT) { 
+				cout<<"Path starts inside element "<<beam->getElement(pos-1)->getName()<<endl;
+			} else { 
+				cout<<"Path starts inside unnamed drift "<<endl;
+			}
+			H_OpticalElement* temp_el = beam->getElement(pos-1)->clone();
+			temp_el->setS(fs);
+			temp_el->setLength(beam->getElement(pos)->getS() - fs);
+			mat[0][0] = mat[0][0] - temp_el->getX();
+			mat[0][1] = mat[0][1] - tan(temp_el->getTX());
+			mat[0][2] = mat[0][2] - temp_el->getY();
+			mat[0][3] = mat[0][3] - tan(temp_el->getTY());
+			mat *= temp_el->getMatrix(energy_loss,mp,qp);
+			mat[0][0] = mat[0][0] + temp_el->getX();
+			mat[0][1] = mat[0][1] + tan(temp_el->getTX());
+			mat[0][2] = mat[0][2] + temp_el->getY();
+			mat[0][3] = mat[0][3] + tan(temp_el->getTY());
+			xys[0] = mat.GetMatrixArray()[0]*URAD;
+			xys[1] = atan(mat.GetMatrixArray()[1])*URAD;
+			xys[2] = mat.GetMatrixArray()[2]*URAD;
+			xys[3] = atan(mat.GetMatrixArray()[3])*URAD;
+			xys[4] = temp_el->getS()+temp_el->getLength();
+			addPosition(xys[0],xys[1],xys[2],xys[3],xys[4]);
+			if (temp_el) delete temp_el;
+		} 
+		if(fs <= beam->getElement(pos)->getS()) {
+			mat[0][0] = mat[0][0] - beam->getElement(pos)->getX();
+			mat[0][1] = mat[0][1] - tan(beam->getElement(pos)->getTX()/URAD)*URAD;
+			mat[0][2] = mat[0][2] - beam->getElement(pos)->getY();
+			mat[0][3] = mat[0][3] - tan(beam->getElement(pos)->getTY()/URAD)*URAD;
+			mat *= beam->getElement(pos)->getMatrix(energy_loss,mp,qp);
+			mat[0][0] = mat[0][0] + beam->getElement(pos)->getX();
+			mat[0][1] = mat[0][1] + tan(beam->getElement(pos)->getTX()/URAD)*URAD;
+			mat[0][2] = mat[0][2] + beam->getElement(pos)->getY();
+			mat[0][3] = mat[0][3] + tan(beam->getElement(pos)->getTY()/URAD)*URAD;
+			xys[0] = mat.GetMatrixArray()[0]*URAD;
+			xys[1] = atan(mat.GetMatrixArray()[1])*URAD;
+			xys[2] = mat.GetMatrixArray()[2]*URAD;
+			xys[3] = atan(mat.GetMatrixArray()[3])*URAD;
+			xys[4] = beam->getElement(pos)->getS()+beam->getElement(pos)->getLength();
+			addPosition(xys[0],xys[1],xys[2],xys[3],xys[4]);
+		}
+	}
+}
+
+// part about non-ip particle is not ready yet. use the above method in the meantime
+void H_BeamParticle::computePath(const H_AbstractBeamLine & beam, const bool NonLinear) {
+	TMatrixD temp_mat(MDIM,MDIM);
+	double temp_x, temp_y, temp_s, temp_tx, temp_ty;
+
+	temp_x = (positions.front())[INDEX_X];
+        temp_tx = (positions.front())[INDEX_TX];
+        temp_y = (positions.front())[INDEX_Y];
+        temp_ty = (positions.front())[INDEX_TY];
+        temp_s = (positions.front())[INDEX_S];
+
+		double vec[MDIM] = {temp_x/URAD, tan(temp_tx/URAD), temp_y/URAD, tan(temp_ty/URAD),energy,1};
+
+		extern bool relative_energy;
+		if(relative_energy) {
+        	vec[4] = energy-BE;
+		} else {
+        	vec[4] = energy;
+		}
+
+	TMatrixD mat(1,MDIM,vec);
+
+	const int N =beam.getNumberOfElements();
+	double xys[LENGTH_VEC];
+
+	double energy_loss = NonLinear?BE-energy:0;
+
+	// modify here to allow starting at non-IP positions
+	// s is distance to IP
+	// initial position is already in positions vector ?
+	for (int i=0; i<N; i++) {
+		const unsigned pos = i;
+		// if we are inside an element, we should start by adding the action
+		// of the rest of this element
+		if(pos > 0 && fs < beam.getElement(pos)->getS() && fs > beam.getElement(pos-1)->getS()) {
+			cout<<"Path starts inside element "<<beam.getElement(pos-1)->getName()<<endl;
+			H_OpticalElement* temp_el = new H_OpticalElement(*(beam.getElement(pos-1)));
+			temp_el->setS(fs);
+			temp_el->setLength(beam.getElement(pos)->getS() - fs);
+			mat[0][0] = mat[0][0] - temp_el->getX();
+			mat[0][1] = mat[0][1] - tan(temp_el->getTX());
+			mat[0][2] = mat[0][2] - temp_el->getY();
+			mat[0][3] = mat[0][3] - tan(temp_el->getTY());
+			mat *= temp_el->getMatrix(energy_loss,mp,qp);
+			mat[0][0] = mat[0][0] + temp_el->getX();
+			mat[0][1] = mat[0][1] + tan(temp_el->getTX());
+			mat[0][2] = mat[0][2] + temp_el->getY();
+			mat[0][3] = mat[0][3] + tan(temp_el->getTY());
+		} else if(fs >= beam.getElement(pos)->getS()) {
+			mat[0][0] = mat[0][0] - beam.getElement(pos)->getX();
+			mat[0][1] = mat[0][1] - tan(beam.getElement(pos)->getTX());
+			mat[0][2] = mat[0][2] - beam.getElement(pos)->getY();
+			mat[0][3] = mat[0][3] - tan(beam.getElement(pos)->getTY());
+			mat *= beam.getElement(pos)->getMatrix(energy_loss,mp,qp);
+			mat[0][0] = mat[0][0] + beam.getElement(pos)->getX();
+			mat[0][1] = mat[0][1] + tan(beam.getElement(pos)->getTX());
+			mat[0][2] = mat[0][2] + beam.getElement(pos)->getY();
+			mat[0][3] = mat[0][3] + tan(beam.getElement(pos)->getTY());
+		}
+		xys[0] = mat.GetMatrixArray()[0]*URAD;
+		xys[1] = atan(mat.GetMatrixArray()[1])*URAD;
+		xys[2] = mat.GetMatrixArray()[2]*URAD;
+		xys[3] = atan(mat.GetMatrixArray()[3])*URAD;
+		xys[4] = beam.getElement(pos)->getS()+beam.getElement(pos)->getLength();
+		addPosition(xys[0],xys[1],xys[2],xys[3],xys[4]);
+		fx = xys[0];
+		fy = xys[2];
+		thx = xys[1];
+		thy = xys[3];
+	}
+}
+
+void H_BeamParticle::resetPath() {
+	double temp_x, temp_y, temp_s, temp_tx, temp_ty;
+
+	temp_x = (positions.front())[INDEX_X];
+	temp_tx = (positions.front())[INDEX_TX];
+	temp_y = (positions.front())[INDEX_Y];
+	temp_ty = (positions.front())[INDEX_TY];
+	temp_s = (positions.front())[INDEX_S];
+	positions.clear();
+	addPosition(temp_x,temp_tx,temp_y,temp_ty,temp_s);
+}
+
+const TVectorD * H_BeamParticle::getPosition(const int element_position) const {
+ 	const int N = (element_position<0)?0:(( ((unsigned int) element_position)>positions.size()-1)?positions.size()-1:element_position);
+ 	return &(*(positions.begin()+N));// same as "return &positions[N];", but more efficient
+}
Index: external/Hector/H_BeamParticle.h
===================================================================
--- external/Hector/H_BeamParticle.h	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
+++ external/Hector/H_BeamParticle.h	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
@@ -0,0 +1,177 @@
+#ifndef _H_BeamParticle_
+#define _H_BeamParticle_
+
+  /* * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ *                                                         *
+*                   --<--<--  A fast simulator --<--<--     *
+*                 / --<--<--     of particle   --<--<--     *
+*  ----HECTOR----<                                          *
+*                 \ -->-->-- transport through -->-->--     *
+*                   -->-->-- generic beamlines -->-->--     *
+*                                                           *
+* JINST 2:P09005 (2007)                                     *
+*      X Rouby, J de Favereau, K Piotrzkowski (CP3)         *
+*       http://www.fynu.ucl.ac.be/hector.html               *
+*                                                           *
+* Center for Cosmology, Particle Physics and Phenomenology  *
+*              Universite catholique de Louvain             *
+*                 Louvain-la-Neuve, Belgium                 *
+ *                                                         *
+   * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+/// \file H_BeamParticle.h
+/// \brief Class aiming at simulating a particle in the beamline
+
+// from IP to RP, with emission of a photon of defined energy and Q.
+// Units : angles [rad], distances [m], energies [GeV], masses [GeV], c=[1].
+// !!! no comment statement at the end of a #define line !!!
+
+// c++ #includes
+#include <vector>
+
+// ROOT #includes
+#include "TMatrixD.h"
+#include "TVectorD.h"
+#include "TLorentzVector.h"
+#include "TRandom3.h"
+
+// local #includes
+#include "H_Parameters.h"
+#include "H_AbstractBeamLine.h"
+#include "H_OpticalElement.h"
+
+using namespace std;
+
+/// Defines a particle from the beam and its transport through the beamline
+class H_BeamParticle {
+
+	public:
+		/// Constructors and Destructor
+		//@{
+		H_BeamParticle();
+		H_BeamParticle(const H_BeamParticle&);
+		H_BeamParticle(const double, const double);
+		H_BeamParticle& operator=(const H_BeamParticle&);
+		~H_BeamParticle() {if(stop_position) delete stop_position; if(!stop_element) delete stop_element; positions.clear();}
+		//@}
+		/// Smears the (x,y) coordinates of the particle [\f$ \mu m \f$]
+		void smearPos(const double dx=SX,const double dy=SY, TRandom* r=gRandom);
+		/// Smears the (x,y) angular coordinates of the particle [\f$ \mu rad \f$]
+		void smearAng(const double tx=STX, const double ty=STY, TRandom* r=gRandom);
+		/// Smears the Energy of the particle [GeV]
+		void smearE(const double erre=SBE, TRandom* r=gRandom);
+		/// Smears the longitudinal position of the particle [\f$ \mu m \f$]
+		void smearS(const double errs=SS, TRandom* r=gRandom);
+		/// Sets the energy [GeV].
+		void setE(const double);
+		/// Sets the particle 4-momentum \f$ P^\mu \f$
+		void set4Momentum(const double, const double, const double, const double);	
+		/// Sets the particle 4-momentum \f$ P^\mu \f$
+		void set4Momentum(const TLorentzVector&);	
+		/// Clears H_BeamParticle::positions and sets the initial one.
+		void setPosition(const double , const double , const double , const double , const double );
+		/// Returns the particle mass [GeV]
+		const double getM() const {return mp;};
+		/// Returns the particle charge [e]
+		const double getQ() const {return qp;};
+		/// Returns the current x coordinate [\f$ \mu \f$m]
+		const double getX() const {return fx;};
+		/// Returns the current y coordinate [\f$ \mu \f$m]
+		const double getY() const {return fy;};
+		/// Returns the current s coordinate [m]
+		const double getS() const {return fs;};
+		/// Returns the current \f$ \theta_x \f$ angular coordinate [\f$ \mu \f$rad]
+		const double getTX() const {return thx;};
+		/// Returns the current \f$ \theta_y \f$ angular coordinate [\f$ \mu \f$rad]
+		const double getTY() const {return thy;};
+		/// Returns the current particle energy [GeV]
+		const double getE() const {return energy;};
+		/// Returns all the positions 
+		vector<TVectorD> getPositions() const {return positions;};
+		const bool isPhysical() const {return isphysical;};
+		/// \brief Simulates the emission of a photon in a random direction
+		///
+	        /// For \f$ p_{1} \rightarrow p_{2} \gamma \f$, kinematics imposes that
+	        /// \f$ Q^{2} = E^{2}_{\gamma} -p^{2}_{1} -p^{2}_{2} + 2p_{1}p_{2} cos(\theta)  \f$ where \f$ \theta \f$ is the particle scattering angle and \f$ p_{i} = \|\vec{p_{i}}\| \f$. <BR>
+        	/// So, \f$ Q^{2}_{min} = E^{2}_{\gamma} - (p_{1}+p_{2})^{2} \f$ and \f$ Q^{2}_{max} = E^{2}_{\gamma} - (p_{1}-p_{2})^{2} \f$.<BR>
+	        /// As \f$ E^{2}_{\gamma} - (p_{1}-p_{2})^{2} \f$ could be numerically instable, we use here another form of this formula : <BR>
+        	/// \f$ Q^{2}_{max} = -2 * \big( \frac{M_{p} E_{\gamma}}{p_{1}+p_{2}} \big) \big[ 1 + \frac{E^{2}_{1} + E^{2}_{2} - M^{2}_{p} }{ E_{1} E_{2} + p_{1} p_{2}} \big]    \f$
+		//@{
+		void emitGamma(const double gee, const double gq2, const double phimin=0, const double phimax=2*TMath::Pi());
+		//@}
+                /// uses Pythia to generate some inelastic pp->pX collision as background
+		void doInelastic();
+		/// \brief Propagates the particule across the beamline until the s coordinate is reached
+		///
+		/// Caution : "computePath" should be used before any "propagate" call <BR>
+		/// Caution : "stopped" is not included in "propagate" : please run it afterward if needed 
+		void propagate(const double ) ;
+		/// Propagates the particle accross the beamline until a given element
+		void propagate(const H_AbstractBeamLine *, const H_OpticalElement *);
+		/// Propagates the particle accross the beamline until a given element
+		void propagate(const H_AbstractBeamLine *, const string&);
+		/// Propagates the particle until the end of the beamline
+		void propagate(const H_AbstractBeamLine *);
+		/// Returns the phase vector of the particle
+		const TMatrixD * getV() const;
+		/// Returns the current phase vector of the particle (in H_BeamParticle::positions)
+		const TVectorD * getPosition(const int ) const;
+		/// Prints the properties of the particle
+		void printProperties() const {cout << *this; return;};
+		/// Prints the phase vector of the particle
+		void printV() const;
+		/// Returns the element where the particle has been stopped
+		const H_OpticalElement * getStoppingElement() const;
+		/// Checks if the particle has been stopped in any element of the beamline
+		const bool stopped(const H_AbstractBeamLine *);
+		/// Returns the StopPosition vector
+		inline const TVectorD * getStopPosition() const { return stop_position; };
+		// returns (-1,-1,-1,-1,-1) if not stopped (and then hasstopped is false)
+		/// Shows all the vectors \f$ (x, \theta_x, y, \theta_y ,s) \f$ in H_BeamParticle::positions
+		void showPositions() const; 
+		/// Returns the particle path in the beamline
+		TGraph * getPath(const int , const int ) const;
+		void getPath(const int x_or_y, const string& filename) const;
+		/// Computes the position of the particle at the end of each element of the beam.
+		void computePath(const H_AbstractBeamLine * beam, const bool NonLinear=true);
+		/// Computes the position of the particle at the end of each element of the beam.
+		void computePath(const H_AbstractBeamLine & beam, const bool NonLinear=true);
+		/// Clears H_BeamParticle::positions but keeps the initial vector.
+		void resetPath();
+
+	private:
+		void init();
+		/// Particle mass [GeV]
+		double mp;
+		/// Particle charge [e]
+		double qp;
+		/// Longitudinal co-moving coordinate [m]
+		double fs;
+		/// Transverse (horizontal) coordinate [m]
+		double fx;
+		/// Transverse (vertical) coordinate [m]
+		double fy;
+		/// Direction of the 3-momentum in the horizontal plane [rad]
+		double thx;
+		/// Direction of the 3-momentum in the vertical plane [rad]
+		double thy;
+		/// Kinetic energy of the particle [GeV]
+		double energy;
+		/// True if the particle has stopped (i.e. : if the particle transverse position has been out of any optics element aperture). <BR> See H_BeamParticle::stopped method. <BR>Default = false.
+		bool hasstopped;
+		/// True if the particle has lost some (E,Q), i.e. if H_BeamParticle::emitGamma was used. Default = false.
+		bool hasemitted;
+		/// False if the particle has emitted a photon with impossible (E,Q). Default = true.
+		bool isphysical;
+		/// Vector (x,tx,y,ty,s) where the particle has stopped.
+		TVectorD * stop_position; 
+		/// Element of the beamline (H_OpticalElement) where the particle has stopped. 
+		H_OpticalElement * stop_element;
+		/// List of (x,tx,y,ty,s) vectors, after each optical element of the beam
+		vector<TVectorD> positions; // vector (x,tx,y,ty,s) after each optical element of the beam ([m],[rad],[m],[rad],[m])
+		/// Adds a new vector (x,tx,y,ty,s) at the end of H_BeamParticle::positions
+  		void addPosition(const double , const double , const double , const double , const double );
+
+	friend std::ostream& operator<< (std::ostream& os, const H_BeamParticle& p);
+};
+#endif
Index: external/Hector/H_CircularAperture.cc
===================================================================
--- external/Hector/H_CircularAperture.cc	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
+++ external/Hector/H_CircularAperture.cc	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
@@ -0,0 +1,40 @@
+  /* * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ *                                                         *
+*                   --<--<--  A fast simulator --<--<--     *
+*                 / --<--<--     of particle   --<--<--     *
+*  ----HECTOR----<                                          *
+*                 \ -->-->-- transport through -->-->--     *
+*                   -->-->-- generic beamlines -->-->--     *
+*                                                           *
+* JINST 2:P09005 (2007)                                     *
+*      X Rouby, J de Favereau, K Piotrzkowski (CP3)         *
+*       http://www.fynu.ucl.ac.be/hector.html               *
+*                                                           *
+* Center for Cosmology, Particle Physics and Phenomenology  *
+*              Universite catholique de Louvain             *
+*                 Louvain-la-Neuve, Belgium                 *
+ *                                                         *
+   * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+/// \file H_CircularAperture.cc
+/// \brief Defines the circular aperture of beamline elements.
+
+// C++ #includes
+#include <iostream>
+
+// C #includes
+#include <cmath> // needed for fabs and log
+
+// local #includes
+#include "H_CircularAperture.h"
+using namespace std;
+
+H_CircularAperture* H_CircularAperture::clone() const {
+	return new H_CircularAperture(x1,fx,fy);
+}
+
+std::ostream& operator<< (std::ostream& os, const H_CircularAperture& ap) {
+        os     << "Aperture shape:" << ap.aptypestring << ", aperture radius : " << ap.x1 << endl;
+        os     << " \t Center : " << ap.fx << "," << ap.fy << endl;
+        return os;
+}
Index: external/Hector/H_CircularAperture.h
===================================================================
--- external/Hector/H_CircularAperture.h	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
+++ external/Hector/H_CircularAperture.h	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
@@ -0,0 +1,45 @@
+#ifndef _H_CircularAperture_
+#define _H_CircularAperture_
+
+  /* * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ *                                                         *
+*                   --<--<--  A fast simulator --<--<--     *
+*                 / --<--<--     of particle   --<--<--     *
+*  ----HECTOR----<                                          *
+*                 \ -->-->-- transport through -->-->--     *
+*                   -->-->-- generic beamlines -->-->--     *
+*                                                           *
+* JINST 2:P09005 (2007)                                     *
+*      X Rouby, J de Favereau, K Piotrzkowski (CP3)         *
+*       http://www.fynu.ucl.ac.be/hector.html               *
+*                                                           *
+* Center for Cosmology, Particle Physics and Phenomenology  *
+*              Universite catholique de Louvain             *
+*                 Louvain-la-Neuve, Belgium                 *
+ *                                                         *
+   * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+/// \file H_CircularAperture.h
+/// \brief Defines the circular aperture of beamline elements.
+
+// local #includes
+#include "H_EllipticAperture.h"
+
+
+/// Circular apertures
+class H_CircularAperture: public H_EllipticAperture {
+
+	public:
+		/// Constructors and destructor
+		//@{
+		H_CircularAperture():H_EllipticAperture(CIRCULAR,0,0,0,0) {};
+		H_CircularAperture(const float r, const float posx, const float posy) : H_EllipticAperture(CIRCULAR,r,r,posx,posy) {};
+		/// @param r is the radius of the circular shape
+        	/// @param posx, posy are the (x,y) coordinates of the center of the circle
+		~H_CircularAperture() {};
+		H_CircularAperture* clone() const;
+		//@}
+	friend std::ostream& operator<< (std::ostream& os, const H_CircularAperture& ap);
+};
+
+#endif
Index: external/Hector/H_Dipole.cc
===================================================================
--- external/Hector/H_Dipole.cc	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
+++ external/Hector/H_Dipole.cc	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
@@ -0,0 +1,43 @@
+  /* * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ *                                                         *
+*                   --<--<--  A fast simulator --<--<--     *
+*                 / --<--<--     of particle   --<--<--     *
+*  ----HECTOR----<                                          *
+*                 \ -->-->-- transport through -->-->--     *
+*                   -->-->-- generic beamlines -->-->--     *
+*                                                           *
+* JINST 2:P09005 (2007)                                     *
+*      X Rouby, J de Favereau, K Piotrzkowski (CP3)         *
+*       http://www.fynu.ucl.ac.be/hector.html               *
+*                                                           *
+* Center for Cosmology, Particle Physics and Phenomenology  *
+*              Universite catholique de Louvain             *
+*                 Louvain-la-Neuve, Belgium                 *
+ *                                                         *
+   * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+/// \file H_Dipole.cc
+/// \brief Class aiming at simulating LHC beam dipoles
+
+//local includes
+#include "H_Dipole.h"
+
+void H_Dipole::init() {
+	// needed for call from R- and S-Dipoles constructor
+	// must be in public section
+	    element_mat.ResizeTo(MDIM,MDIM);
+		setTypeString();
+		if (fk !=0 ) setMatrix(0,MP,QP);
+	return;
+}
+
+std::ostream& operator<< (std::ostream& os, const H_Dipole& el) {
+	os << el.typestring << el.name <<"\t at s = "<< el.fs <<"\t length = "<< el.element_length <<"\t k0 = "<<el.fk << endl;
+        if(el.element_aperture->getType()!=NONE) {
+                os << *(el.element_aperture) << endl;
+	}
+
+	if(el.element_length<0)  { if(VERBOSE) os <<"<H_Dipole> ERROR : Interpenetration of elements !"<<endl; }
+	if(el.element_length==0) { if(VERBOSE) os <<"<H_Dipole> WARNING : 0-length "<< el.name << " !" << endl; }
+   return os;
+}
Index: external/Hector/H_Dipole.h
===================================================================
--- external/Hector/H_Dipole.h	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
+++ external/Hector/H_Dipole.h	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
@@ -0,0 +1,50 @@
+/// \file H_Dipole.h
+/// \brief Class aiming at simulating LHC beam dipoles.
+
+  /* * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ *                                                         *
+*                   --<--<--  A fast simulator --<--<--     *
+*                 / --<--<--     of particle   --<--<--     *
+*  ----HECTOR----<                                          *
+*                 \ -->-->-- transport through -->-->--     *
+*                   -->-->-- generic beamlines -->-->--     *
+*                                                           *
+* JINST 2:P09005 (2007)                                     *
+*      X Rouby, J de Favereau, K Piotrzkowski (CP3)         *
+*       http://www.fynu.ucl.ac.be/hector.html               *
+*                                                           *
+* Center for Cosmology, Particle Physics and Phenomenology  *
+*              Universite catholique de Louvain             *
+*                 Louvain-la-Neuve, Belgium                 *
+ *                                                         *
+   * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+#ifndef _H_Dipole_
+#define _H_Dipole_
+
+#include "H_OpticalElement.h"
+
+/// Abstract class aiming at simulating dipoles.
+class H_Dipole : public H_OpticalElement {
+
+	public:
+		/// Constructors and destructor
+		//@{
+		H_Dipole():H_OpticalElement() {}
+		H_Dipole(const int dtype, const double s, const double k, const double l):H_OpticalElement(dtype,s,k,l){}
+		H_Dipole(const string& nameE, const int dtype, const double s, const double k, const double l):H_OpticalElement(nameE,dtype,s,k,l){}
+	        virtual ~H_Dipole() {};
+		//@}
+		/// Prints the properties of the element
+		virtual void printProperties() const { cout << *this; return;};
+		virtual H_Dipole* clone() const =0;
+		void init();
+
+ 	protected:
+    		virtual void setTypeString() =0;
+	    	virtual void setMatrix(const float, const float, const float) = 0;
+    
+	friend std::ostream& operator<< (std::ostream& os, const H_Dipole& el);
+};
+
+#endif
Index: external/Hector/H_Drift.cc
===================================================================
--- external/Hector/H_Drift.cc	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
+++ external/Hector/H_Drift.cc	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
@@ -0,0 +1,61 @@
+  /* * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ *                                                         *
+*                   --<--<--  A fast simulator --<--<--     *
+*                 / --<--<--     of particle   --<--<--     *
+*  ----HECTOR----<                                          *
+*                 \ -->-->-- transport through -->-->--     *
+*                   -->-->-- generic beamlines -->-->--     *
+*                                                           *
+* JINST 2:P09005 (2007)                                     *
+*      X Rouby, J de Favereau, K Piotrzkowski (CP3)         *
+*       http://www.fynu.ucl.ac.be/hector.html               *
+*                                                           *
+* Center for Cosmology, Particle Physics and Phenomenology  *
+*              Universite catholique de Louvain             *
+*                 Louvain-la-Neuve, Belgium                 *
+ *                                                         *
+   * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+/// \file H_Drift.cc
+/// \brief Class aiming at simulating LHC beam drift.
+
+// local includes
+#include "H_Drift.h"
+#include "H_TransportMatrices.h"
+
+
+void H_Drift::init() {
+	// must be in public section
+	element_mat.ResizeTo(MDIM,MDIM);
+	setTypeString();
+	setMatrix(0,MP,QP);
+	return;
+}
+
+std::ostream& operator<< (std::ostream& os, const H_Drift& el) {
+	os << el.typestring << el.name << "\t\t at s = " << el.fs << "\t length = " << el.element_length <<endl;
+	if(el.element_aperture->getType()!=NONE) {
+		os << *(el.element_aperture) << endl;
+        }
+	if(el.element_length<0 && VERBOSE) os <<"<H_Drift> ERROR : Interpenetration of elements !"<<endl;
+	else if(el.element_length==0 && VERBOSE) os <<"<H_Drift> WARNING : 0-length "<< el.name << " !" << endl;
+   return os;
+}
+
+//void H_Drift::setMatrix(const float eloss, const float p_mass, const float p_charge) {
+void H_Drift::setMatrix(const float , const float , const float ) {
+	element_mat = driftmat(element_length);
+	return ;
+}
+
+H_Drift* H_Drift::clone() const {
+	H_Drift* temp_drift = new H_Drift(name,fs,element_length);
+	temp_drift->setX(xpos);
+	temp_drift->setY(ypos);
+	temp_drift->setTX(txpos);
+	temp_drift->setTY(typos);
+	temp_drift->setBetaX(betax);
+	temp_drift->setBetaY(betay); 
+	return temp_drift;
+}
+
Index: external/Hector/H_Drift.h
===================================================================
--- external/Hector/H_Drift.h	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
+++ external/Hector/H_Drift.h	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
@@ -0,0 +1,49 @@
+#ifndef _H_Drift_
+#define _H_Drift_
+
+  /* * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ *                                                         *
+*                   --<--<--  A fast simulator --<--<--     *
+*                 / --<--<--     of particle   --<--<--     *
+*  ----HECTOR----<                                          *
+*                 \ -->-->-- transport through -->-->--     *
+*                   -->-->-- generic beamlines -->-->--     *
+*                                                           *
+* JINST 2:P09005 (2007)                                     *
+*      X Rouby, J de Favereau, K Piotrzkowski (CP3)         *
+*       http://www.fynu.ucl.ac.be/hector.html               *
+*                                                           *
+* Center for Cosmology, Particle Physics and Phenomenology  *
+*              Universite catholique de Louvain             *
+*                 Louvain-la-Neuve, Belgium                 *
+ *                                                         *
+   * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+/// \file H_Drift.h
+/// \brief Class aiming at simulating LHC beam drift.
+
+// local includes
+#include "H_OpticalElement.h"
+
+/// \brief Class aiming at simulating LHC beam drift. 
+class H_Drift : public H_OpticalElement {
+
+	public:
+	/// Constructors and destructor
+	//@{
+		H_Drift():H_OpticalElement(DRIFT,0.,0.,0.) {init();}
+        	H_Drift(const double s, const double l):H_OpticalElement(DRIFT,s,0.,l){init();}
+	        H_Drift(const string& nameE, const double s, const double l):H_OpticalElement(nameE,DRIFT,s,0.,l){init();}
+	        ~H_Drift() { };
+	//@}
+	        void init();
+		virtual void printProperties() const { cout << *this; return;};
+		H_Drift* clone() const;
+
+	protected:
+        	virtual void setTypeString() {typestring = DRIFTNAME;};
+	        virtual void setMatrix(const float, const float, const float) ;
+	friend std::ostream& operator<< (std::ostream& os, const H_Drift& el);
+};
+
+#endif
Index: external/Hector/H_EllipticAperture.cc
===================================================================
--- external/Hector/H_EllipticAperture.cc	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
+++ external/Hector/H_EllipticAperture.cc	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
@@ -0,0 +1,76 @@
+  /* * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ *                                                         *
+*                   --<--<--  A fast simulator --<--<--     *
+*                 / --<--<--     of particle   --<--<--     *
+*  ----HECTOR----<                                          *
+*                 \ -->-->-- transport through -->-->--     *
+*                   -->-->-- generic beamlines -->-->--     *
+*                                                           *
+* JINST 2:P09005 (2007)                                     *
+*      X Rouby, J de Favereau, K Piotrzkowski (CP3)         *
+*       http://www.fynu.ucl.ac.be/hector.html               *
+*                                                           *
+* Center for Cosmology, Particle Physics and Phenomenology  *
+*              Universite catholique de Louvain             *
+*                 Louvain-la-Neuve, Belgium                 *
+ *                                                         *
+   * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+/// \file H_EllipticAperture.cc
+/// \brief Defines the elliptic aperture of beamline elements.
+
+// C++ #includes
+#include <iostream>
+
+// ROOT #includes
+#include "TEllipse.h"
+
+// local #includes
+#include "H_Parameters.h"
+#include "H_Aperture.h"
+#include "H_EllipticAperture.h"
+using namespace std;
+
+H_EllipticAperture::H_EllipticAperture(const int type, const float l, const float h, const float posx, const float posy) :
+	H_Aperture(type,l,h,0,0,posx,posy) {
+        /// @param type is the aperture type (ELLIPTIC or CIRCULAR)
+        /// @param l, h are the length and height of the elliptic shape
+        /// @param posx, posy are the (x,y) coordinates of the center of the ellipse
+
+	if (type!= ELLIPTIC && type != CIRCULAR) { 
+		cout << "Warning: trying to define an EllipticalAperture which is neither elliptical nor circular." << endl;
+		cout << "'Elliptical' type forced\n"; 
+		type_ = ELLIPTIC; 
+		aptypestring = getApertureString(); 
+	}
+}
+
+H_EllipticAperture::H_EllipticAperture(const float l, const float h, const float posx, const float posy) :
+	H_Aperture(ELLIPTIC,l,h,0,0,posx,posy) {
+        /// @param l, h are the length and height of the elliptic shape
+        /// @param posx, posy are the (x,y) coordinates of the center of the ellipse
+}
+
+H_EllipticAperture* H_EllipticAperture::clone() const {
+	return new H_EllipticAperture(x1,x2,fx,fy);
+}
+
+bool H_EllipticAperture::isInside(const float x, const float y) const {
+        /// @param x, y are the (x,y) coordinates of the proton
+	return (((x-fx)/x1)*((x-fx)/x1) + ((y-fy)/x2)*((y-fy)/x2) < 1);
+}
+
+void H_EllipticAperture::draw(const float scale) const {
+	TEllipse* te = new TEllipse(fx*scale,fy*scale,x1*scale,x2*scale);
+	te->SetFillStyle(3003);
+	te->SetLineColor(39);
+	te->SetFillColor(39);
+	te->Draw("f");
+	return;
+}
+
+std::ostream& operator<< (std::ostream& os, const H_EllipticAperture& ap) {
+	os<< "Aperture shape:" << ap.aptypestring << ", ellipse axes : "<< ap.x1 <<", " << ap.x2 << endl;
+	os << " \t Center : "  << ap.fx << "," << ap.fy << endl;
+	return os;
+}
Index: external/Hector/H_EllipticAperture.h
===================================================================
--- external/Hector/H_EllipticAperture.h	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
+++ external/Hector/H_EllipticAperture.h	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
@@ -0,0 +1,47 @@
+#ifndef _H_EllipticAperture_
+#define _H_EllipticAperture_
+
+  /* * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ *                                                         *
+*                   --<--<--  A fast simulator --<--<--     *
+*                 / --<--<--     of particle   --<--<--     *
+*  ----HECTOR----<                                          *
+*                 \ -->-->-- transport through -->-->--     *
+*                   -->-->-- generic beamlines -->-->--     *
+*                                                           *
+* JINST 2:P09005 (2007)                                     *
+*      X Rouby, J de Favereau, K Piotrzkowski (CP3)         *
+*       http://www.fynu.ucl.ac.be/hector.html               *
+*                                                           *
+* Center for Cosmology, Particle Physics and Phenomenology  *
+*              Universite catholique de Louvain             *
+*                 Louvain-la-Neuve, Belgium                 *
+ *                                                         *
+   * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+/// \file H_EllipticAperture.h
+/// \brief Defines the elliptic aperture of beamline elements.
+
+// local #includes
+#include "H_Aperture.h"
+
+/// Elliptic apertures
+class H_EllipticAperture: public H_Aperture {
+
+	public:
+		/// Constructors and destructors
+		//@{
+		H_EllipticAperture():H_Aperture(ELLIPTIC,0,0,0,0,0,0) {}
+		H_EllipticAperture(const int, const float, const float, const float, const float);
+		H_EllipticAperture(const float, const float, const float, const float);
+		~H_EllipticAperture() {};
+		virtual H_EllipticAperture* clone() const;
+		//@}
+		/// Checks whether the point is inside the aperture or not
+		virtual bool isInside(const float, const float) const;
+		/// Draws the aperture shape.
+		virtual void draw(const float scale=1) const;
+	friend std::ostream& operator<< (std::ostream& os, const H_EllipticAperture& ap);
+};
+
+#endif
Index: external/Hector/H_HorizontalKicker.cc
===================================================================
--- external/Hector/H_HorizontalKicker.cc	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
+++ external/Hector/H_HorizontalKicker.cc	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
@@ -0,0 +1,51 @@
+  /* * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ *                                                         *
+*                   --<--<--  A fast simulator --<--<--     *
+*                 / --<--<--     of particle   --<--<--     *
+*  ----HECTOR----<                                          *
+*                 \ -->-->-- transport through -->-->--     *
+*                   -->-->-- generic beamlines -->-->--     *
+*                                                           *
+* JINST 2:P09005 (2007)                                     *
+*      X Rouby, J de Favereau, K Piotrzkowski (CP3)         *
+*       http://www.fynu.ucl.ac.be/hector.html               *
+*                                                           *
+* Center for Cosmology, Particle Physics and Phenomenology  *
+*              Universite catholique de Louvain             *
+*                 Louvain-la-Neuve, Belgium                 *
+ *                                                         *
+   * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+/// \file H_HorizontalKicker.cc
+/// \brief Classes aiming at simulating horizontal kickers in beamline
+
+// fk [rad] for kickers !!!!
+
+// local #includes
+#include "H_HorizontalKicker.h"
+#include "H_TransportMatrices.h"
+
+int kickers_on = 0;
+
+void H_HorizontalKicker::setMatrix(const float eloss, const float p_mass, const float p_charge) {
+	extern int kickers_on;
+	if(kickers_on) {
+		element_mat = hkickmat(element_length,fk,eloss,p_mass,p_charge);
+	} else {
+		element_mat = driftmat(element_length);
+	}
+	return ;
+}
+
+H_HorizontalKicker* H_HorizontalKicker::clone() const {
+	H_HorizontalKicker* temp_kick = new H_HorizontalKicker(name,fs,fk,element_length);
+	temp_kick->setAperture(element_aperture);
+	temp_kick->setX(xpos);
+	temp_kick->setY(ypos);
+	temp_kick->setTX(txpos);
+	temp_kick->setTY(typos);
+	temp_kick->setBetaX(betax);
+	temp_kick->setBetaY(betay);
+	return temp_kick;
+}
+
Index: external/Hector/H_HorizontalKicker.h
===================================================================
--- external/Hector/H_HorizontalKicker.h	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
+++ external/Hector/H_HorizontalKicker.h	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
@@ -0,0 +1,47 @@
+#ifndef _H_HorizontalKicker_
+#define _H_HorizontalKicker_
+
+  /* * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ *                                                         *
+*                   --<--<--  A fast simulator --<--<--     *
+*                 / --<--<--     of particle   --<--<--     *
+*  ----HECTOR----<                                          *
+*                 \ -->-->-- transport through -->-->--     *
+*                   -->-->-- generic beamlines -->-->--     *
+*                                                           *
+* JINST 2:P09005 (2007)                                     *
+*      X Rouby, J de Favereau, K Piotrzkowski (CP3)         *
+*       http://www.fynu.ucl.ac.be/hector.html               *
+*                                                           *
+* Center for Cosmology, Particle Physics and Phenomenology  *
+*              Universite catholique de Louvain             *
+*                 Louvain-la-Neuve, Belgium                 *
+ *                                                         *
+   * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+/// \file H_HorizontalKicker.h
+/// \brief Classes aiming at simulating horizontal kickers in beamline.
+///
+/// fk [rad] for kickers !!!!
+
+// local #includes
+#include "H_Kicker.h"
+
+/// Horizontal kickers for the beamline.
+class H_HorizontalKicker : public H_Kicker {
+
+	public:
+	/// Constructors and destructor
+	//@{
+		H_HorizontalKicker():H_Kicker(HKICKER,0.,0.,0.) {init();}
+		H_HorizontalKicker(const double s, const double k, const double l) :H_Kicker(HKICKER,s,k,l){init();}
+		H_HorizontalKicker(const string &nameE, const double s, const double k, const double l) :H_Kicker(nameE,HKICKER,s,k,l){init();}
+		~H_HorizontalKicker() {};
+	//@}
+		H_HorizontalKicker* clone() const;
+	private:
+		virtual void setTypeString() {typestring=HKICKERNAME;};
+		virtual void setMatrix(const float, const float, const float) ;
+};
+
+#endif
Index: external/Hector/H_HorizontalQuadrupole.cc
===================================================================
--- external/Hector/H_HorizontalQuadrupole.cc	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
+++ external/Hector/H_HorizontalQuadrupole.cc	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
@@ -0,0 +1,45 @@
+  /* * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ *                                                         *
+*                   --<--<--  A fast simulator --<--<--     *
+*                 / --<--<--     of particle   --<--<--     *
+*  ----HECTOR----<                                          *
+*                 \ -->-->-- transport through -->-->--     *
+*                   -->-->-- generic beamlines -->-->--     *
+*                                                           *
+* JINST 2:P09005 (2007)                                     *
+*      X Rouby, J de Favereau, K Piotrzkowski (CP3)         *
+*       http://www.fynu.ucl.ac.be/hector.html               *
+*                                                           *
+* Center for Cosmology, Particle Physics and Phenomenology  *
+*              Universite catholique de Louvain             *
+*                 Louvain-la-Neuve, Belgium                 *
+ *                                                         *
+   * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+/// \file H_HorizontalQuadrupole.cc
+/// \brief Classes aiming at simulating horizontal quadrupoles in beamline
+
+// local #includes
+#include "H_HorizontalQuadrupole.h"
+
+void H_HorizontalQuadrupole::setMatrix(const float eloss, const float p_mass, const float p_charge) {
+	if (fk>0)  { if(VERBOSE) cout<<"<H_HorizontalQuadrupole> ERROR : k1 should be < 0 (" << name << ")!"<<endl; }
+		if (fk !=0 ) element_mat = hquadmat(element_length,fk,eloss, p_mass, p_charge);
+		else  {
+			element_mat = driftmat(element_length);
+			if(VERBOSE) cout<<"<H_HorizontalQuadrupole> WARNING : k1= 0 ; drift-like quadrupole (" << name << ") !" << endl;
+   		}
+	return ;
+}
+
+H_HorizontalQuadrupole* H_HorizontalQuadrupole::clone() const {
+	H_HorizontalQuadrupole* temp_quad = new H_HorizontalQuadrupole(name,fs,fk,element_length);
+	temp_quad->setAperture(element_aperture);
+	temp_quad->setX(xpos);
+	temp_quad->setY(ypos);
+	temp_quad->setTX(txpos);
+	temp_quad->setTY(typos);
+	temp_quad->setBetaX(betax);
+	temp_quad->setBetaY(betay);
+	return temp_quad;
+}
Index: external/Hector/H_HorizontalQuadrupole.h
===================================================================
--- external/Hector/H_HorizontalQuadrupole.h	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
+++ external/Hector/H_HorizontalQuadrupole.h	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
@@ -0,0 +1,45 @@
+#ifndef _H_HorizontalQuadrupole_
+#define _H_HorizontalQuadrupole_
+
+  /* * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ *                                                         *
+*                   --<--<--  A fast simulator --<--<--     *
+*                 / --<--<--     of particle   --<--<--     *
+*  ----HECTOR----<                                          *
+*                 \ -->-->-- transport through -->-->--     *
+*                   -->-->-- generic beamlines -->-->--     *
+*                                                           *
+* JINST 2:P09005 (2007)                                     *
+*      X Rouby, J de Favereau, K Piotrzkowski (CP3)         *
+*       http://www.fynu.ucl.ac.be/hector.html               *
+*                                                           *
+* Center for Cosmology, Particle Physics and Phenomenology  *
+*              Universite catholique de Louvain             *
+*                 Louvain-la-Neuve, Belgium                 *
+ *                                                         *
+   * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+/// \file H_HorizontalQuadrupole.h
+/// \brief Class describing horizontally focussing quadrupoles.
+
+// local #includes
+#include "H_Quadrupole.h"
+
+/// Horizontally focussing quadrupoles.
+class H_HorizontalQuadrupole : public H_Quadrupole {
+
+	public:
+	///     Constructors and destructor
+	//@{
+		H_HorizontalQuadrupole():H_Quadrupole(HQUADRUPOLE,0.,0.,0.) {init();}
+		H_HorizontalQuadrupole(const double s, const double k, const double l) : H_Quadrupole(HQUADRUPOLE,s,k,l){init();}
+		H_HorizontalQuadrupole(const string& nameE, const double s, const double k, const double l) : H_Quadrupole(nameE,HQUADRUPOLE,s,k,l){init();}
+		~H_HorizontalQuadrupole() {};
+	//@}
+		H_HorizontalQuadrupole* clone() const ;
+	private:
+		virtual void setTypeString() {typestring = HQUADRUPOLENAME;};
+		virtual void setMatrix(const float, const float, const float) ;
+};
+
+#endif
Index: external/Hector/H_Kicker.cc
===================================================================
--- external/Hector/H_Kicker.cc	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
+++ external/Hector/H_Kicker.cc	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
@@ -0,0 +1,46 @@
+  /* * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ *                                                         *
+*                   --<--<--  A fast simulator --<--<--     *
+*                 / --<--<--     of particle   --<--<--     *
+*  ----HECTOR----<                                          *
+*                 \ -->-->-- transport through -->-->--     *
+*                   -->-->-- generic beamlines -->-->--     *
+*                                                           *
+* JINST 2:P09005 (2007)                                     *
+*      X Rouby, J de Favereau, K Piotrzkowski (CP3)         *
+*       http://www.fynu.ucl.ac.be/hector.html               *
+*                                                           *
+* Center for Cosmology, Particle Physics and Phenomenology  *
+*              Universite catholique de Louvain             *
+*                 Louvain-la-Neuve, Belgium                 *
+ *                                                         *
+   * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+/// \file H_Kicker.cc
+/// \brief Classes aiming at simulating kickers in LHC beamline.
+
+// local #includes
+#include "H_OpticalElement.h"
+#include "H_Kicker.h"
+
+void H_Kicker::init() {
+	// needed for call from H- and V-Kickers constructor
+	// must be in public section
+		setTypeString();
+		if (fk !=0 ) {
+			setMatrix(0,MP,QP); 
+		}
+	return;
+}
+
+std::ostream& operator<< (std::ostream& os, const H_Kicker& el) {
+	os << el.typestring << el.name <<"\t at s = "<< el.fs <<"\t length = "<< el.element_length;
+	os<<"\t k0 = "<< el.fk <<endl;
+	if(el.element_aperture->getType()!=NONE) {
+		os << *(el.element_aperture) << endl;
+        }
+
+	if(el.element_length<0 && VERBOSE) os<<"<H_Kicker> ERROR : Interpenetration of elements !"<<endl; 
+	else if(el.element_length==0 && VERBOSE) os<<"<H_Kicker> WARNING : 0-length "<< el.name << " !" << endl; 
+  return os;
+}
Index: external/Hector/H_Kicker.h
===================================================================
--- external/Hector/H_Kicker.h	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
+++ external/Hector/H_Kicker.h	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
@@ -0,0 +1,50 @@
+#ifndef _H_Kicker_
+#define _H_Kicker_
+
+  /* * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ *                                                         *
+*                   --<--<--  A fast simulator --<--<--     *
+*                 / --<--<--     of particle   --<--<--     *
+*  ----HECTOR----<                                          *
+*                 \ -->-->-- transport through -->-->--     *
+*                   -->-->-- generic beamlines -->-->--     *
+*                                                           *
+* JINST 2:P09005 (2007)                                     *
+*      X Rouby, J de Favereau, K Piotrzkowski (CP3)         *
+*       http://www.fynu.ucl.ac.be/hector.html               *
+*                                                           *
+* Center for Cosmology, Particle Physics and Phenomenology  *
+*              Universite catholique de Louvain             *
+*                 Louvain-la-Neuve, Belgium                 *
+ *                                                         *
+   * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+/// \file H_Kicker.h
+/// \brief Classes aiming at simulating kickers in LHC beamline.
+/// fk [rad] for kickers !!!!
+
+// local #includes
+#include "H_OpticalElement.h"
+
+/// Abstract class aiming at simulating kickers in LHC beamline.
+class H_Kicker : public H_OpticalElement {
+
+public:
+	/// Constructors and destructor
+	//@{
+		H_Kicker():H_OpticalElement() {}
+		H_Kicker(const int dtype, const double s, const double k, const double l):H_OpticalElement(dtype,s,k,l){}
+		H_Kicker(const string& nameE, const int dtype, const double s, const double k, const double l):H_OpticalElement(nameE,dtype,s,k,l){}
+		virtual ~H_Kicker() {};
+	//@}
+		virtual H_Kicker* clone() const = 0;
+		virtual void printProperties() const { cout << *this; return;};
+		void init();
+
+ 	protected:
+		virtual void setTypeString() = 0;
+		virtual void setMatrix(const float, const float, const float) = 0;
+	friend std::ostream& operator<< (std::ostream& os, const H_Kicker& el);
+};
+
+#endif
Index: external/Hector/H_Marker.cc
===================================================================
--- external/Hector/H_Marker.cc	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
+++ external/Hector/H_Marker.cc	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
@@ -0,0 +1,57 @@
+  /* * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ *                                                         *
+*                   --<--<--  A fast simulator --<--<--     *
+*                 / --<--<--     of particle   --<--<--     *
+*  ----HECTOR----<                                          *
+*                 \ -->-->-- transport through -->-->--     *
+*                   -->-->-- generic beamlines -->-->--     *
+*                                                           *
+* JINST 2:P09005 (2007)                                     *
+*      X Rouby, J de Favereau, K Piotrzkowski (CP3)         *
+*       http://www.fynu.ucl.ac.be/hector.html               *
+*                                                           *
+* Center for Cosmology, Particle Physics and Phenomenology  *
+*              Universite catholique de Louvain             *
+*                 Louvain-la-Neuve, Belgium                 *
+ *                                                         *
+   * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+/// \file H_Marker.cc
+/// \brief Class defining a marker in the beamline (e.g. for interaction point)
+
+// local includes
+#include "H_Marker.h"
+#include "H_TransportMatrices.h"
+
+void H_Marker::init() {
+	// must be in public section
+	setTypeString();
+	setMatrix(0,MP,QP);
+	return;
+}
+
+std::ostream& operator<< (std::ostream& os, const H_Marker& el) {
+	os << el.typestring << el.name << "\t\t at s = " << el.fs;
+	if(el.element_aperture->getType()!=NONE) {
+                os << *(el.element_aperture) << endl;
+        }
+   return os;
+}
+
+//void H_Marker::setMatrix(const float eloss, const float p_mass, const float p_charge) {
+void H_Marker::setMatrix(const float , const float , const float ) {
+		element_mat = driftmat(0);
+	return ;
+}
+
+H_Marker* H_Marker::clone() const {
+	H_Marker* temp_mkr = new H_Marker(name,fs);
+	temp_mkr->setAperture(element_aperture);
+	temp_mkr->setX(xpos);
+	temp_mkr->setY(ypos);
+	temp_mkr->setTX(txpos);
+	temp_mkr->setTY(typos);
+	temp_mkr->setBetaX(betax);
+	temp_mkr->setBetaY(betay);
+	return temp_mkr;
+}
Index: external/Hector/H_Marker.h
===================================================================
--- external/Hector/H_Marker.h	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
+++ external/Hector/H_Marker.h	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
@@ -0,0 +1,48 @@
+#ifndef _H_Marker_
+#define _H_Marker_
+
+  /* * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ *                                                         *
+*                   --<--<--  A fast simulator --<--<--     *
+*                 / --<--<--     of particle   --<--<--     *
+*  ----HECTOR----<                                          *
+*                 \ -->-->-- transport through -->-->--     *
+*                   -->-->-- generic beamlines -->-->--     *
+*                                                           *
+* JINST 2:P09005 (2007)                                     *
+*      X Rouby, J de Favereau, K Piotrzkowski (CP3)         *
+*       http://www.fynu.ucl.ac.be/hector.html               *
+*                                                           *
+* Center for Cosmology, Particle Physics and Phenomenology  *
+*              Universite catholique de Louvain             *
+*                 Louvain-la-Neuve, Belgium                 *
+ *                                                         *
+   * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+/// \file H_Marker.h
+/// \brief Class defining a marker in the beamline (e.g. for interaction point)
+
+// local includes
+#include "H_Drift.h"
+
+/// \brief Class defining a marker in the beamline (e.g. for interaction point)
+class H_Marker : public H_Drift {
+
+	public:
+	/// Constructors and destructor
+	//@{
+		H_Marker():H_Drift() { type = MARKER; init();}
+        	H_Marker(const double s):H_Drift(s,0.) { type =MARKER; init();}
+	        H_Marker(const string& nameE, const double s):H_Drift(nameE,s,0.) { type=MARKER; init();}
+	        ~H_Marker() { };
+	//@}
+		H_Marker* clone() const ;
+	        void init();
+
+	private:
+        	virtual void setTypeString() {typestring = MARKERNAME;};
+	        virtual void setMatrix(const float , const float, const float) ;
+	friend std::ostream& operator<< (std::ostream& os, const H_Marker& el);
+};
+
+#endif
Index: external/Hector/H_OpticalElement.cc
===================================================================
--- external/Hector/H_OpticalElement.cc	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
+++ external/Hector/H_OpticalElement.cc	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
@@ -0,0 +1,315 @@
+  /* * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ *                                                         *
+*                   --<--<--  A fast simulator --<--<--     *
+*                 / --<--<--     of particle   --<--<--     *
+*  ----HECTOR----<                                          *
+*                 \ -->-->-- transport through -->-->--     *
+*                   -->-->-- generic beamlines -->-->--     *
+*                                                           *
+* JINST 2:P09005 (2007)                                     *
+*      X Rouby, J de Favereau, K Piotrzkowski (CP3)         *
+*       http://www.fynu.ucl.ac.be/hector.html               *
+*                                                           *
+* Center for Cosmology, Particle Physics and Phenomenology  *
+*              Universite catholique de Louvain             *
+*                 Louvain-la-Neuve, Belgium                 *
+ *                                                         *
+   * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+/// \file H_OpticalElement.cc
+/// \brief Class aiming at describing any beam optical element.
+
+// c++ #includes
+#include <iostream>
+#include <string>
+
+// ROOT #includes
+#include "TPaveLabel.h"
+
+// local #includes
+#include "H_Parameters.h"
+#include "H_TransportMatrices.h"
+#include "H_Aperture.h"
+#include "H_OpticalElement.h"
+using namespace std;
+
+/// called by the constructors
+void H_OpticalElement::init(const string& nameE, const int typeE, const double s, const double k, const double l) {
+	// this is called by the constructors
+	// must be in public section !
+	// xpos and ypos are vectors with n point. They define the aperture shape of the optical element.
+	name = nameE;
+	fs = s;
+ 	fk = k;
+	xpos = 0;
+	ypos = 0;
+	txpos = 0;
+	typos = 0;
+ 	element_length = l;
+ 	type = typeE;
+	element_mat.ResizeTo(MDIM,MDIM);
+ 	element_mat = driftmat(l);
+
+	// do NOT use setAperture for the initialisation ! there are protections there
+	
+	if(element_length<0)  { if(VERBOSE) cout<<"<H_OpticalElement> ERROR : Interpenetration of elements !"<<endl; }
+	if(element_length==0) { if(VERBOSE) cout<<"<H_OpticalElement> WARNING : 0-length element ! (" << name << ") " << " at " << fs << endl; }
+	betax =0;
+	betay =0;
+}
+
+H_OpticalElement::H_OpticalElement() : element_aperture(new H_Aperture()) {
+	init("",DRIFT,0.,0.,0.1);
+}
+
+H_OpticalElement::H_OpticalElement(const string& nameE, const int typeE, const double s, const double k, const double l) : element_aperture(new H_Aperture()) {
+	init(nameE,typeE,s,k,l);
+}
+
+H_OpticalElement::H_OpticalElement(const string& nameE, const int typeE, const double s, const double k, const double l, H_Aperture* the_app) : element_aperture(the_app->clone()) {
+	init(nameE,typeE,s,k,l);
+}
+
+H_OpticalElement::H_OpticalElement(const int typeE, const double s, const double k, const double l, H_Aperture* the_app) : element_aperture(the_app->clone()) {
+	init("",typeE,s,k,l);
+}
+
+H_OpticalElement::H_OpticalElement(const int typeE, const double s, const double k, const double l) : element_aperture(new H_Aperture()) {
+	init("",typeE,s,k,l);
+}
+
+H_OpticalElement::H_OpticalElement(const H_OpticalElement& el) {
+	fs = el.fs;
+	element_length = el.element_length;
+	fk = el.fk;
+	xpos = el.xpos;
+	ypos = el.ypos;
+	txpos = el.txpos;
+	typos = el.typos;
+	betax = el.betax;
+	betay = el.betay;
+	type = el.type;
+	name = el.name;
+	typestring = el.typestring;
+	element_mat.ResizeTo(MDIM,MDIM);
+	element_mat = el.element_mat;
+	element_aperture = el.element_aperture->clone();
+}
+
+H_OpticalElement& H_OpticalElement::operator=(const H_OpticalElement& el) {
+	if(this==&el) return *this;
+        fs = el.fs;
+        element_length = el.element_length;
+        fk = el.fk;
+        xpos = el.xpos;
+        ypos = el.ypos;
+	txpos = el.txpos;
+	typos = el.typos;
+        betax = el.betax;
+        betay = el.betay;
+        type = el.type;
+        name = el.name;
+        typestring = el.typestring;
+	element_mat.ResizeTo(MDIM,MDIM);
+        element_mat = el.element_mat;
+        element_aperture = el.element_aperture->clone();
+	return *this;
+}
+
+void H_OpticalElement::setAperture(const H_Aperture* ap) {
+	// do NOT use setAperture in your constructor, as element_aperture is not initialized
+	// this function do not take into account ap if ap=0
+	// do nothing if element_mat = ap
+		if (!ap) {cout << "<H_OpticalElement> Trying to set an empty pointer for the aperture ! Nothing done.\n"; return;}
+		if (element_aperture != ap) {
+			delete element_aperture;
+			element_aperture = ap->clone();
+		}
+	return;
+}
+/*
+void H_OpticalElement::setAperture(H_Aperture* ap) {
+        // do NOT use setAperture in your constructor, as element_aperture is not initialized
+        // this function do not take into account ap if ap=0
+        // do nothing if element_mat = ap
+                if (!ap) {cout << "<H_OpticalElement> Trying to set an empty pointer for the aperture ! Nothing done.\n"; return;}
+                if (element_aperture != ap) {
+                        delete element_aperture;
+                        element_aperture = ap; //->clone();
+                }
+        return;
+}
+*/
+
+std::ostream& operator<< (std::ostream& os, const H_OpticalElement& el) {
+        os << el.typestring << el.name << "\t at s = " << el.fs << "\t length = "<< el.element_length;
+        if(el.fk!=0) os <<"\t strength = " << el.fk;
+        if(el.element_aperture->getType()!=NONE) {
+                os << *(el.element_aperture) << endl;
+        }
+        os<<endl;
+        if(el.element_length<0 && VERBOSE) 
+		os <<"<H_OpticalElement> ERROR : Interpenetration of elements !"<<endl; 
+        else if(el.element_length==0 && VERBOSE) 
+		os <<"<H_OpticalElement> WARNING : 0-length "<< el.typestring << " !" << endl;
+  return os;
+}
+
+void H_OpticalElement::showMatrix() const {
+	printMatrix(element_mat);
+	return;
+}
+
+void H_OpticalElement::drawAperture() const {
+	element_aperture->draw(1);
+	return;
+}
+
+TMatrix H_OpticalElement::getMatrix() {
+	setMatrix(0,MP,1);
+	return element_mat;
+}
+
+TMatrix H_OpticalElement::getMatrix(const float eloss, const float p_mass, const float p_charge) {
+	setMatrix(eloss,p_mass,p_charge);
+	return element_mat;
+}
+
+void H_OpticalElement::draw(const float meight, const float height) const{
+	/// @param meight is the minimal extend of the graph
+	/// @param height is the maximal extend of the graph
+	float x1 = getS();
+	float x2 = getS() + getLength();
+	float y1 = meight;
+	float y2 = height;
+	TPaveLabel* cur_box = new TPaveLabel(x1,y1,x2,y2,"");
+	cur_box->SetBorderSize(1);
+	cur_box->SetFillStyle(1001);
+	cur_box->SetFillColor((int)getType());
+	cur_box->Draw();
+}
+
+TVectorD H_OpticalElement::getHitPosition(const TVectorD& init_pos, const double energy_loss, const double mp, const double qp) {
+	if(!element_length) {
+		// cout<<"O-length element ("<<getName()<<"), should not appear here !"<<endl;
+		return init_pos;
+	}
+	// some declarations
+	bool inside = false;
+	double vec[MDIM] = {init_pos[INDEX_X]/URAD,  tan(init_pos[INDEX_TX]/URAD),
+                            init_pos[INDEX_Y]/URAD,  tan(init_pos[INDEX_TY]/URAD), 
+			    -energy_loss,            1};
+	TMatrixD mat_init(1,MDIM,vec);
+	TMatrixD mat_min(1,MDIM,vec);
+	TMatrixD mat_max(1,MDIM,vec);
+	TMatrixD mat_stop(1,MDIM,vec);
+	H_OpticalElement* temp_el = clone();
+	// initialasing boundaries
+	double min_pos = 0;
+	double max_pos = element_length/2.;
+	double max_old = element_length/2.;
+	// number of iterations 
+	// (idea : fix precision instead of number of iterations + add security)
+	// (idea : interpolate between max and min and give the error)
+	const int N = 10;
+	// starting search loop
+	for(int i = 0; i < N; i++) {
+		// fixing position to be investigated 
+		temp_el->setLength(max_pos);
+		// initialising the vector at the initial vector + possible shift/tilt
+		mat_max[0][0] = mat_init[0][0] - temp_el->getX();
+		mat_max[0][1] = mat_init[0][1] - tan(temp_el->getTX());
+		mat_max[0][2] = mat_init[0][2] - temp_el->getY();
+		mat_max[0][3] = mat_init[0][3] - tan(temp_el->getTY());
+		// propagating
+		mat_max *= temp_el->getMatrix(energy_loss,mp,qp);
+		// compensating for the previously stated shifts/tilts
+		mat_max[0][0] = mat_max[0][0] + temp_el->getX();
+		mat_max[0][1] = mat_max[0][1] + tan(temp_el->getTX());
+		mat_max[0][2] = mat_max[0][2] + temp_el->getY();
+		mat_max[0][3] = mat_max[0][3] + tan(temp_el->getTY());
+		// fixing new boundaries 
+		if(temp_el->isInside(mat_max.GetMatrixArray()[0]*URAD,mat_max.GetMatrixArray()[2]*URAD)) {
+			max_old = max_pos;
+			max_pos = max_pos + (max_pos - min_pos)/2.;
+			min_pos = max_old;
+			inside = true;
+		} else {
+			max_pos = min_pos + (max_pos - min_pos)/2.;
+			inside = false;
+		}
+		// end of loop
+	}
+	// if it passes at the last iteration, choosing the other rangeÂ²
+	if(inside) min_pos = max_old;
+	// here the interpolation method : now we are sure that the intercept is between min_pos and max_pos
+	// getting vector at min_pos (for first boundary) :
+	bool precision_estimate = false;
+	if(precision_estimate) {
+		temp_el->setLength(min_pos);
+		mat_min[0][0] = mat_init[0][0] - temp_el->getX();
+		mat_min[0][1] = mat_init[0][1] - tan(temp_el->getTX());
+		mat_min[0][2] = mat_init[0][2] - temp_el->getY();
+		mat_min[0][3] = mat_init[0][3] - tan(temp_el->getTY());
+		mat_min *= temp_el->getMatrix(energy_loss,mp,qp);
+		mat_min[0][0] = mat_min[0][0] + temp_el->getX();
+   		mat_min[0][1] = mat_min[0][1] + tan(temp_el->getTX());
+ 	  	mat_min[0][2] = mat_min[0][2] + temp_el->getY();
+		mat_min[0][3] = mat_min[0][3] + tan(temp_el->getTY());
+		mat_min[0][4] = min_pos + init_pos[4];
+		// getting vector at max_pos (for second boundary) :
+		temp_el->setLength(max_pos);
+	   	mat_max[0][0] = mat_init[0][0] - temp_el->getX();
+		mat_max[0][1] = mat_init[0][1] - tan(temp_el->getTX());
+		mat_max[0][2] = mat_init[0][2] - temp_el->getY();
+		mat_max[0][3] = mat_init[0][3] - tan(temp_el->getTY());
+		mat_max *= temp_el->getMatrix(energy_loss,mp,qp);
+		mat_max[0][0] = mat_max[0][0] + temp_el->getX();
+		mat_max[0][1] = mat_max[0][1] + tan(temp_el->getTX());
+		mat_max[0][2] = mat_max[0][2] + temp_el->getY();
+		mat_max[0][3] = mat_max[0][3] + tan(temp_el->getTY());
+		mat_max[0][4] = max_pos + init_pos[4];
+	}
+	// getting vector in the middle (for estimate) :
+	temp_el->setLength((max_pos+min_pos)/2.);
+	mat_stop[0][0] = mat_init[0][0] - temp_el->getX();
+	mat_stop[0][1] = mat_init[0][1] - tan(temp_el->getTX());
+	mat_stop[0][2] = mat_init[0][2] - temp_el->getY();
+	mat_stop[0][3] = mat_init[0][3] - tan(temp_el->getTY());
+	mat_stop *= temp_el->getMatrix(energy_loss,mp,qp);
+	mat_stop[0][0] = mat_stop[0][0] + temp_el->getX();
+	mat_stop[0][1] = mat_stop[0][1] + tan(temp_el->getTX());
+	mat_stop[0][2] = mat_stop[0][2] + temp_el->getY();
+	mat_stop[0][3] = mat_stop[0][3] + tan(temp_el->getTY());
+	mat_stop[0][4] = (max_pos+min_pos)/2. + init_pos[4];
+
+	double xys[LENGTH_VEC];
+	xys[INDEX_X]=  mat_stop[0][0]*URAD;
+	xys[INDEX_TX]= atan(mat_stop[0][1])*URAD;
+	xys[INDEX_Y]=  mat_stop[0][2]*URAD;
+	xys[INDEX_TY]= atan(mat_stop[0][3])*URAD;
+	xys[INDEX_S]=  mat_stop[0][4] ;
+	TVectorD temp_vec(LENGTH_VEC,xys);
+
+	if(precision_estimate) {
+		cout<<"--- Results and precision estimates ---"<<endl;
+		cout<<"\t Stopping element : "<<getName()<<endl;
+		cout<<"\t hit point s  : "<<mat_stop[0][4]<<" m +- "<<(mat_max[0][4]-mat_stop[0][4])*1000.<<" mm"<<endl;
+		cout<<"\t hit point x  : "<<mat_stop[0][0]*URAD;
+		cout<<" + "<<fabs(((mat_min[0][0]<mat_max[0][0])?(mat_max[0][0]-mat_stop[0][0])*URAD:(mat_min[0][0]-mat_stop[0][0])*URAD));
+		cout<<" - "<<fabs(((mat_min[0][0]<mat_max[0][0])?(mat_stop[0][0]-mat_min[0][0])*URAD:(mat_stop[0][0]-mat_max[0][0])*URAD))<<" Âµm"<<endl;
+		cout<<"\t hit point y  : "<<mat_stop[0][2]*URAD;
+		cout<<" + "<<fabs(((mat_min[0][0]<mat_max[0][2])?(mat_max[0][2]-mat_stop[0][2])*URAD:(mat_min[0][2]-mat_stop[0][2])*URAD));
+		cout<<" - "<<fabs(((mat_min[0][0]<mat_max[0][2])?(mat_stop[0][2]-mat_min[0][2])*URAD:(mat_stop[0][2]-mat_max[0][2])*URAD))<<" Âµm"<<endl;
+		cout<<"\t hit point tx : "<<mat_stop[0][1]*URAD;
+		cout<<" + "<<fabs(((mat_min[0][0]<mat_max[0][1])?(mat_max[0][1]-mat_stop[0][1])*URAD:(mat_min[0][1]-mat_stop[0][1])*URAD));
+		cout<<" - "<<fabs(((mat_min[0][0]<mat_max[0][1])?(mat_stop[0][1]-mat_min[0][1])*URAD:(mat_stop[0][1]-mat_max[0][1])*URAD))<<" Âµrad"<<endl;
+		cout<<"\t hit point ty : "<<mat_stop[0][3]*URAD;
+		cout<<" + "<<fabs(((mat_min[0][0]<mat_max[0][3])?(mat_max[0][3]-mat_stop[0][3])*URAD:(mat_min[0][3]-mat_stop[0][3])*URAD));
+		cout<<" - "<<fabs(((mat_min[0][0]<mat_max[0][3])?(mat_stop[0][3]-mat_min[0][3])*URAD:(mat_stop[0][3]-mat_max[0][3])*URAD))<<" Âµrad"<<endl;
+
+	}
+
+	delete temp_el;
+	return temp_vec;
+}
Index: external/Hector/H_OpticalElement.h
===================================================================
--- external/Hector/H_OpticalElement.h	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
+++ external/Hector/H_OpticalElement.h	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
@@ -0,0 +1,216 @@
+#ifndef _H_OpticalElement_
+#define _H_OpticalElement_
+
+  /* * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ *                                                         *
+*                   --<--<--  A fast simulator --<--<--     *
+*                 / --<--<--     of particle   --<--<--     *
+*  ----HECTOR----<                                          *
+*                 \ -->-->-- transport through -->-->--     *
+*                   -->-->-- generic beamlines -->-->--     *
+*                                                           *
+* JINST 2:P09005 (2007)                                     *
+*      X Rouby, J de Favereau, K Piotrzkowski (CP3)         *
+*       http://www.fynu.ucl.ac.be/hector.html               *
+*                                                           *
+* Center for Cosmology, Particle Physics and Phenomenology  *
+*              Universite catholique de Louvain             *
+*                 Louvain-la-Neuve, Belgium                 *
+ *                                                         *
+   * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+/// \file H_OpticalElement.h
+/// \brief Class aiming at describing any beam optical element.
+///
+/// This is an abstract base class
+/// subclass must define setTypeString() and setMatrix() methods.
+/// Quadrupole, Dipole, Kickers and Drift inherit from this class.
+
+// c++ #includes
+#include <iostream>
+#include <string>
+
+// ROOT #includes
+#include "TMatrix.h"
+#include "TVectorD.h"
+
+// local #includes
+#include "H_TransportMatrices.h"
+#include "H_Parameters.h"
+#include "H_Aperture.h"
+
+using namespace std;
+
+	// type #defines
+enum {DRIFT=1, RDIPOLE, SDIPOLE, VQUADRUPOLE, HQUADRUPOLE, VKICKER, HKICKER, RCOLLIMATOR, ECOLLIMATOR, CCOLLIMATOR, RP, IP, MARKER};
+
+	// typestring[30] #defines
+#define DRIFTNAME	"Drift        "
+#define RDIPOLENAME	"R-Dipole     "
+#define SDIPOLENAME	"S-Dipole     "
+#define VQUADRUPOLENAME	"V-Quadrupole "
+#define HQUADRUPOLENAME	"H-Quadrupole "
+#define VKICKERNAME     "V-Kicker     "
+#define HKICKERNAME     "H-Kicker     "
+#define RCOLLIMATORNAME "R-Collimator "
+#define ECOLLIMATORNAME "E-Collimator "
+#define CCOLLIMATORNAME "C-Collimator "
+#define RPNAME          "Roman Pot    "
+#define IPNAME          "IP           "
+#define MARKERNAME      "Marker       "
+
+/// Describes any beam optical element.
+class H_OpticalElement {
+
+	public:
+        ///     init method for constructors
+                void init(const string&, const int , const double , const double , const double);
+		/// Constructors and destructor
+		//@{
+		H_OpticalElement(const string&, const int, const double, const double, const double, H_Aperture*);
+		H_OpticalElement(const int, const double, const double, const double, H_Aperture*);
+		H_OpticalElement(const string&, const int, const double, const double, const double);
+		H_OpticalElement(const int, const double, const double, const double);
+		H_OpticalElement();
+		H_OpticalElement(const H_OpticalElement&);
+		virtual ~H_OpticalElement() { delete element_aperture;};
+		//@}
+		///     Prints the element features
+	        virtual void printProperties() const { cout << *this; return;};
+		///     Shows the element transport matrix
+	        void showMatrix() const ;
+		///     Draws the aperture shape
+	        void drawAperture() const ;
+		///     Sets the aperture of the element
+		void setAperture(const H_Aperture*);
+		///     Ordering operator acting on the s coordinate
+		inline bool operator>(const H_OpticalElement& tocomp) const {return ( fs>tocomp.getS() ); };
+		///     Ordering operator acting on the s coordinate
+		inline bool operator<(const H_OpticalElement& tocomp) const {return ( fs<tocomp.getS() ); };
+		/// 	Copy operator
+		H_OpticalElement& operator=(const H_OpticalElement&); 
+		///     Sets the element longitudinal (s), and horizontal (x) and vertical (y) coordinates.
+		//@{
+		inline void setS(const double new_s) {fs=new_s;};
+		inline void setLength(const double new_l) { element_length = new_l;};
+		inline void setX(const double new_pos) {
+		        /// @param new_pos in [m]
+	        	element_aperture->setPosition(new_pos*URAD,ypos);
+		        xpos = new_pos;
+		};
+		inline void setY(const double new_pos) {
+		        /// @param new_pos in [m]
+		        element_aperture->setPosition(xpos,new_pos*URAD);
+		        ypos = new_pos;
+		};
+		inline void setTX(const double new_ang) {
+			txpos = new_ang;
+		};
+		inline void setTY(const double new_ang) {
+			typos = new_ang;
+		}
+		//@}
+		///     Returns the element longitudinal (s), horizontal (x) and vertical (y) coordinates, and corresponding angles.
+		//@{
+	        inline double getS() const {return fs;};
+		inline double getX() const {return xpos;};
+		inline double getY() const {return ypos;};
+		inline double getTX() const {return txpos;};
+		inline double getTY() const {return typos;};
+		//@}
+		///     Returns the element length
+	        inline double getLength() const { return element_length; };
+		///     Returns the element magnetic strength
+	        inline double getK() const { return fk; };
+		///     Returns the element type, as (int)  or (string)
+		//@{
+	        inline int getType() const { return type; };
+		inline const string getTypeString() const { return typestring; };
+		//@}
+		///     Returns the element (string) name
+		inline const string getName() const { return name; };
+		///     Draws the element from min to max in the current pad
+		void draw(const float, const float) const;
+		///     Checks if the (x,y) coordinates are within the aperture acceptance
+		inline bool isInside(const double x, const double y) const { return (bool) element_aperture->isInside(x,y);};
+		///     Returns the element transport matrix
+		//@{
+		TMatrix getMatrix() ;
+		TMatrix getMatrix(const float, const float, const float) ;
+		//@}
+		///     Returns the element aperture
+		H_Aperture* getAperture() const {return element_aperture;};
+		///	Sets the beta functions
+		//@{
+		inline void setBetaX(const double beta) { betax = beta;};
+		inline void setBetaY(const double beta) { betay = beta;};
+		//@}
+		///	Returns the beta functions
+		//@{
+		inline double getBetaX() const {return betax;};
+		inline double getBetaY() const {return betay;};
+		//@}
+                ///     Sets the dispersion functions
+                //@{
+                inline void setDX(const double disp) { dx = disp;};
+                inline void setDY(const double disp) { dy = disp;};
+                //@}
+                ///     Returns the dispersion functions
+                //@{
+                inline double getDX() const {return dx;};
+                inline double getDY() const {return dy;};
+                //@}
+                //@}
+                ///     Sets the relative position functions (from MAD), relative to the beamline reference frame
+                //@{
+                inline void setRelX(const double rel_x) { relx = rel_x;};
+                inline void setRelY(const double rel_y) { rely = rel_y;};
+                //@}
+                ///     Returns the position functions (from MAD), relative to the beamline reference frame
+                //@{
+                inline double getRelX() const {return relx;};
+                inline double getRelY() const {return rely;};
+                //@}
+		virtual H_OpticalElement* clone() const { return new H_OpticalElement();};
+		TVectorD getHitPosition(const TVectorD& , const double, const double, const double);
+
+
+	protected:
+		/// Optical element coordinates : fs [m], xpos [m], ypos [m], txpos [rad], typos [rad].
+		//@{
+        	double fs, xpos, ypos, txpos, typos;
+		//@}
+		/// Optical element lenght.
+		double element_length;
+		/// Magnetic field strength.
+		double fk;
+		/// Beam \f$ \beta \f$ functions.
+		//@{
+		double betax, betay;
+		//@}
+		/// Beam dispersion in position 
+		//@{
+		double dx, dy;
+		//@}
+		/// Beam position, relative to the beam ideal path, from MAD
+		//@{
+		double relx, rely;
+		//@}
+		/// Optical element type (Dipole, drift, etc).
+     		int type;
+		/// Optical element name and type.
+		//@{
+		string name, typestring;
+		//@}
+		virtual void setTypeString() {return;};
+		/// Optical element transport matrix.
+		virtual void setMatrix(const float, const float, const float) { cout<<"dummy setmatrix"<<endl; return;};
+		/// Optical element transport matrix.
+ 		TMatrix element_mat;
+		/// Optical element aperture. 
+	    	H_Aperture* element_aperture;
+
+	friend std::ostream& operator<< (std::ostream& os, const H_OpticalElement& el);
+};
+
+#endif
Index: external/Hector/H_Parameters.cc
===================================================================
--- external/Hector/H_Parameters.cc	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
+++ external/Hector/H_Parameters.cc	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
@@ -0,0 +1,23 @@
+  /* * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ *                                                         *
+*                   --<--<--  A fast simulator --<--<--     *
+*                 / --<--<--     of particle   --<--<--     *
+*  ----HECTOR----<                                          *
+*                 \ -->-->-- transport through -->-->--     *
+*                   -->-->-- generic beamlines -->-->--     *
+*                                                           *
+* JINST 2:P09005 (2007)                                     *
+*      X Rouby, J de Favereau, K Piotrzkowski (CP3)         *
+*       http://www.fynu.ucl.ac.be/hector.html               *
+*                                                           *
+* Center for Cosmology, Particle Physics and Phenomenology  *
+*              Universite catholique de Louvain             *
+*                 Louvain-la-Neuve, Belgium                 *
+ *                                                         *
+   * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+///\file H_Parameters.cc
+///\brief Class aiming at gathering all parameters that must be defined
+
+#include "H_Parameters.h"
+ //Needed for the compilator of H_Parameters into an object (.o) file
Index: external/Hector/H_Parameters.h
===================================================================
--- external/Hector/H_Parameters.h	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
+++ external/Hector/H_Parameters.h	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
@@ -0,0 +1,83 @@
+#ifndef _Hector_parameters_
+#define _Hector_parameters_
+
+  /* * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ *                                                         *
+*                   --<--<--  A fast simulator --<--<--     *
+*                 / --<--<--     of particle   --<--<--     *
+*  ----HECTOR----<                                          *
+*                 \ -->-->-- transport through -->-->--     *
+*                   -->-->-- generic beamlines -->-->--     *
+*                                                           *
+* JINST 2:P09005 (2007)                                     *
+*      X Rouby, J de Favereau, K Piotrzkowski (CP3)         *
+*       http://www.fynu.ucl.ac.be/hector.html               *
+*                                                           *
+* Center for Cosmology, Particle Physics and Phenomenology  *
+*              Universite catholique de Louvain             *
+*                 Louvain-la-Neuve, Belgium                 *
+ *                                                         *
+   * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+/// \file H_Parameters.h
+/// \brief Class aiming at gathering all parameters that must be defined.
+///
+/// Units : angles [\f$ \mu \f$rad], distances [\f$ \mu \f$m], energies [GeV], c=[1].
+
+#include <cmath>
+
+/* from physics and maths */
+   /// proton mass [GeV]
+const double MP=0.93827;
+   /// proton charge [e]
+const double QP=1.;
+   /// conversion factor for \f$\mu\f$rad <-> rad
+const double URAD=1000000.;
+
+/* beam parameters */
+   /// beam nominal energy in GeV
+const double BE=7000.;
+   /// beam energy divergence, in GeV
+const double SBE=0.79;
+   /// beam nominal energy in TeV
+const double BETEV=7.;
+   /// beam S @ IP
+const double PS=0.;
+   /// beam X @ IP
+const double PX=-500.;    
+   /// beam Y @ IP
+const double PY=0.;
+   /// beam longitudinal dispersion
+const double SS=0.;
+   /// beam lateral width SX @ IP
+const double SX=16.63;
+   /// beam lateral width SY @ IP
+const double SY=16.63;
+   /// beam transverse direction angle TX @ IP
+const double TX=0.;
+   /// beam transverse direction angle TY @ IP
+const double TY=0.;
+   /// beam angular divergence STX @ IP
+const double STX=30.23;
+   /// beam angular divergence STY @ IP
+const double STY=30.23;
+	/// half crossing angle at IP [\f$ \mu \f$RAD]
+const double CRANG=142.5;
+
+// local defines, used in H_BeamParticle & H_OpticalElements
+enum {INDEX_X=0, INDEX_TX, INDEX_Y, INDEX_TY, INDEX_S, LENGTH_VEC};
+// (x,theta_x,y,theta_y,s)
+
+/// include Pythia libraries ? (not included on some ROOT installations)
+//#define _include_pythia_
+
+const unsigned int TM = 0; // not used anymore. left for backward compatibility
+const unsigned int AM = 1; // not used anymore. left for backward compatibility
+
+
+/* display parameters */
+   /// Verbose mode ?
+const bool VERBOSE=false; 
+
+#endif
+
Index: external/Hector/H_Quadrupole.cc
===================================================================
--- external/Hector/H_Quadrupole.cc	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
+++ external/Hector/H_Quadrupole.cc	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
@@ -0,0 +1,42 @@
+  /* * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ *                                                         *
+*                   --<--<--  A fast simulator --<--<--     *
+*                 / --<--<--     of particle   --<--<--     *
+*  ----HECTOR----<                                          *
+*                 \ -->-->-- transport through -->-->--     *
+*                   -->-->-- generic beamlines -->-->--     *
+*                                                           *
+* JINST 2:P09005 (2007)                                     *
+*      X Rouby, J de Favereau, K Piotrzkowski (CP3)         *
+*       http://www.fynu.ucl.ac.be/hector.html               *
+*                                                           *
+* Center for Cosmology, Particle Physics and Phenomenology  *
+*              Universite catholique de Louvain             *
+*                 Louvain-la-Neuve, Belgium                 *
+ *                                                         *
+   * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+/// \file H_Quadrupole.cc
+/// \brief Classes aiming at simulating LHC beam quadrupoles.
+
+#include "H_Quadrupole.h"
+
+void H_Quadrupole::init() {
+	// needed for call from H- and V-Quadrupoles constructor
+	// must be in public section
+		element_mat.ResizeTo(MDIM,MDIM);
+		setTypeString();
+		setMatrix(0,MP,QP);
+	return;
+}
+
+std::ostream& operator<< (std::ostream& os, const H_Quadrupole& el) {
+	os << el.typestring  << el.name  << "\t at s = " << el.fs << "\t length = " << el.element_length << "\t k1 = " << el.fk <<endl;
+        if(el.element_aperture->getType()!=NONE) {
+        	os << *(el.element_aperture) << endl;
+	}
+
+	if(el.element_length<0 && VERBOSE) os<<"<H_Quadrupole> ERROR : Interpenetration of elements !"<<endl; 
+	else if(el.element_length==0 && VERBOSE) os<<"<H_Quadrupole> WARNING : 0-length "<< el.typestring << " !" << endl; 
+   return os;
+}
Index: external/Hector/H_Quadrupole.h
===================================================================
--- external/Hector/H_Quadrupole.h	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
+++ external/Hector/H_Quadrupole.h	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
@@ -0,0 +1,50 @@
+#ifndef _H_Quadrupole_
+#define _H_Quadrupole_
+
+  /* * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ *                                                         *
+*                   --<--<--  A fast simulator --<--<--     *
+*                 / --<--<--     of particle   --<--<--     *
+*  ----HECTOR----<                                          *
+*                 \ -->-->-- transport through -->-->--     *
+*                   -->-->-- generic beamlines -->-->--     *
+*                                                           *
+* JINST 2:P09005 (2007)                                     *
+*      X Rouby, J de Favereau, K Piotrzkowski (CP3)         *
+*       http://www.fynu.ucl.ac.be/hector.html               *
+*                                                           *
+* Center for Cosmology, Particle Physics and Phenomenology  *
+*              Universite catholique de Louvain             *
+*                 Louvain-la-Neuve, Belgium                 *
+ *                                                         *
+   * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+/// \file H_Quadrupole.h
+/// \brief Class describing quadrupoles.
+
+// local #includes
+#include "H_OpticalElement.h"
+
+/// Abstract class aiming at simulating LHC beam quadrupoles.
+class H_Quadrupole : public H_OpticalElement {
+
+	public:
+	///     Constructors and destructor
+	//@{
+		H_Quadrupole():H_OpticalElement() {}
+		H_Quadrupole(const int dtype, const double s, const double k, const double l) : H_OpticalElement(dtype,s,k,l) {}
+		H_Quadrupole(const string& nameE, const int dtype, const double s, const double k, const double l) : H_OpticalElement(nameE,dtype,s,k,l) {}
+		virtual ~H_Quadrupole() {};
+	//@}	
+		virtual H_Quadrupole* clone() const =0 ;
+		virtual void printProperties() const { cout << *this; return;};
+		void init();
+
+ 	protected:
+		virtual void setTypeString() =0;
+		virtual void setMatrix(const float, const float, const float) = 0;
+	   	
+	friend std::ostream& operator<< (std::ostream& os, const H_Quadrupole& el);
+};
+
+#endif
Index: external/Hector/H_RecRPObject.cc
===================================================================
--- external/Hector/H_RecRPObject.cc	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
+++ external/Hector/H_RecRPObject.cc	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
@@ -0,0 +1,371 @@
+  /* * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ *                                                         *
+*                   --<--<--  A fast simulator --<--<--     *
+*                 / --<--<--     of particle   --<--<--     *
+*  ----HECTOR----<                                          *
+*                 \ -->-->-- transport through -->-->--     *
+*                   -->-->-- generic beamlines -->-->--     *
+*                                                           *
+* JINST 2:P09005 (2007)                                     *
+*      X Rouby, J de Favereau, K Piotrzkowski (CP3)         *
+*       http://www.fynu.ucl.ac.be/hector.html               *
+*                                                           *
+* Center for Cosmology, Particle Physics and Phenomenology  *
+*              Universite catholique de Louvain             *
+*                 Louvain-la-Neuve, Belgium                 *
+ *                                                         *
+   * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+/// \file H_RecRPObject.cc
+/// \brief Class performing the reconstruction based on forward detector measurements
+///
+/// Units : angles [rad], distances [m], energies [GeV], c=[1].
+
+// local #includes
+#include "H_RecRPObject.h"
+#include "H_RomanPot.h"
+#include "H_BeamParticle.h"
+using namespace std;
+
+// reconstruction class for forward detectors.
+// Featuring the brand-new reco method from the 
+// louvain group !
+
+#define MEGA 1000000.
+
+H_RecRPObject::H_RecRPObject(): emin(0), emax(-1), x1(0), x2(0), y1(0), y2(0), s1(0), s2(0), 
+				txip(NOT_YET_COMPUTED), tyip(NOT_YET_COMPUTED), energy(NOT_YET_COMPUTED), q2(NOT_YET_COMPUTED), pt(NOT_YET_COMPUTED), 
+				thebeam(new H_AbstractBeamLine()),
+				f_1(new TF1("f_1","[0] + [1]*x + [2]*x*x ",emin,emax)), 
+				f_2(new TF1("f_2","[0] + [1]*x + [2]*x*x ",emin,emax)), 
+				g_1(new TF1("g_1","[0] + [1]*x + [2]*x*x ",emin,emax)), 
+				g_2(new TF1("g_2","[0] + [1]*x + [2]*x*x ",emin,emax)), 
+				d_1(new TF1("d_1","[0] + [1]*x + [2]*x*x ",emin,emax)), 
+				d_2(new TF1("d_2","[0] + [1]*x + [2]*x*x ",emin,emax)), 
+				k_1(new TF1("k_1","[0] + [1]*x + [2]*x*x ",emin,emax)), 
+				k_2(new TF1("k_2","[0] + [1]*x + [2]*x*x ",emin,emax)), 
+				l_1(new TF1("l_1","[0] + [1]*x + [2]*x*x ",emin,emax)), 
+				l_2(new TF1("l_2","[0] + [1]*x + [2]*x*x ",emin,emax)) 
+{}
+
+H_RecRPObject::H_RecRPObject(const float ss1, const float ss2, const H_AbstractBeamLine* beam) : emin(0), emax(-1), x1(0), x2(0), y1(0), y2(0), s1(ss1), s2(ss2), 
+				txip(NOT_YET_COMPUTED), tyip(NOT_YET_COMPUTED), energy(NOT_YET_COMPUTED), q2(NOT_YET_COMPUTED), pt(NOT_YET_COMPUTED), 
+				thebeam(beam->clone()),
+				f_1(new TF1("f_1","[0] + [1]*x + [2]*x*x ",emin,emax)), 
+				f_2(new TF1("f_2","[0] + [1]*x + [2]*x*x ",emin,emax)), 
+				g_1(new TF1("g_1","[0] + [1]*x + [2]*x*x ",emin,emax)), 
+				g_2(new TF1("g_2","[0] + [1]*x + [2]*x*x ",emin,emax)), 
+				d_1(new TF1("d_1","[0] + [1]*x + [2]*x*x ",emin,emax)), 
+				d_2(new TF1("d_2","[0] + [1]*x + [2]*x*x ",emin,emax)), 
+				k_1(new TF1("k_1","[0] + [1]*x + [2]*x*x ",emin,emax)), 
+				k_2(new TF1("k_2","[0] + [1]*x + [2]*x*x ",emin,emax)), 
+				l_1(new TF1("l_1","[0] + [1]*x + [2]*x*x ",emin,emax)), 
+				l_2(new TF1("l_2","[0] + [1]*x + [2]*x*x ",emin,emax))
+	{if(ss1==ss2) cout<<"<H_RecRPObject> WARNING : detectors are on same position"<<endl;
+}
+
+
+H_RecRPObject::H_RecRPObject(const float ss1, const float ss2, const H_AbstractBeamLine& beam) : emin(0), emax(-1), x1(0), x2(0), y1(0), y2(0), s1(ss1), s2(ss2),
+                                txip(NOT_YET_COMPUTED), tyip(NOT_YET_COMPUTED), energy(NOT_YET_COMPUTED), q2(NOT_YET_COMPUTED), pt(NOT_YET_COMPUTED),
+                                thebeam(beam.clone()),
+                                f_1(new TF1("f_1","[0] + [1]*x + [2]*x*x ",emin,emax)),
+                                f_2(new TF1("f_2","[0] + [1]*x + [2]*x*x ",emin,emax)),
+                                g_1(new TF1("g_1","[0] + [1]*x + [2]*x*x ",emin,emax)),
+                                g_2(new TF1("g_2","[0] + [1]*x + [2]*x*x ",emin,emax)),
+                                d_1(new TF1("d_1","[0] + [1]*x + [2]*x*x ",emin,emax)),
+                                d_2(new TF1("d_2","[0] + [1]*x + [2]*x*x ",emin,emax)),
+                                k_1(new TF1("k_1","[0] + [1]*x + [2]*x*x ",emin,emax)),
+                                k_2(new TF1("k_2","[0] + [1]*x + [2]*x*x ",emin,emax)),
+                                l_1(new TF1("l_1","[0] + [1]*x + [2]*x*x ",emin,emax)),
+                                l_2(new TF1("l_2","[0] + [1]*x + [2]*x*x ",emin,emax))
+        {if(ss1==ss2) cout<<"<H_RecRPObject> WARNING : detectors are on same position"<<endl;
+}
+
+
+H_RecRPObject::H_RecRPObject(const H_RecRPObject& r):
+   emin(r.emin), emax(r.emax), x1(r.x1), x2(r.x2), y1(r.y1), y2(r.y2), s1(r.s1), s2(r.s2),
+   txip(r.txip), tyip(r.tyip), energy(r.energy), q2(r.q2),  pt(r.pt), 
+   //thebeam(r.thebeam->clone()),
+   thebeam(new H_AbstractBeamLine(*(r.thebeam))),
+   f_1(new TF1(*(r.f_1))),  f_2(new TF1(*(r.f_2))),  g_1(new TF1(*(r.g_1))),  g_2(new TF1(*(r.g_2))),
+   d_1(new TF1(*(r.d_1))),  d_2(new TF1(*(r.d_2))),  k_1(new TF1(*(r.k_1))),  k_2(new TF1(*(r.k_2))),
+   l_1(new TF1(*(r.l_1))),  l_2(new TF1(*(r.l_2)))
+ {}
+
+H_RecRPObject& H_RecRPObject::operator=(const H_RecRPObject& r) {
+  if (this == &r) return *this;
+   emin = r.emin, emax = r.emax;
+   x1 = r.x1;   x2 = r.x2; 
+   y1 = r.y1;   y2 = r.y2; 
+   s1 = r.s1;   s2 = r.s2;
+   txip= r.txip; tyip=r.tyip;
+   energy= r.energy; q2= r.q2;  pt= r.pt;
+   //thebeam = r.thebeam->clone();
+   thebeam = new H_AbstractBeamLine(*(r.thebeam));
+   f_1 = new TF1(*(r.f_1));
+   f_2 = new TF1(*(r.f_2));
+   g_1 = new TF1(*(r.g_1));
+   g_2 = new TF1(*(r.g_2));
+   d_1 = new TF1(*(r.d_1));
+   d_2 = new TF1(*(r.d_2));
+   k_1 = new TF1(*(r.k_1));
+   k_2 = new TF1(*(r.k_2));
+   l_1 = new TF1(*(r.l_1));
+   l_2 = new TF1(*(r.l_2));
+  return *this;
+}
+
+void H_RecRPObject::initialize() {
+	// this method sets the functions that will be used for reco later
+	// it should be used only once per beamline after the energy range was fixed. 
+	// copying beamline and adding detectors
+	
+	if(emax<0) {
+		cout<<"<H_RecRPObject> ERROR : energy range has to be set first !"<<endl;
+		cout<<"<H_RecRPObject> Please run setERange() or computeERange()"<<endl;
+		cout<<"<H_RecRPObject> initialization aborted"<<endl;
+		return;
+	}
+
+	if(emax<emin) {
+		cout<<"<H_RecRPObject> ERROR : maximum energy lower than minimum !"<<endl;
+		cout<<"<H_RecRPObject> Please (re-)do setERange()"<<endl;
+		cout<<"<H_RecRPObject> initialization aborted"<<endl;
+		return;
+	}
+
+	H_AbstractBeamLine * b1 = thebeam->clone();
+	H_RomanPot * rp1 = new H_RomanPot("rp1",s1,0);
+	H_RomanPot * rp2 = new H_RomanPot("rp2",s2,0);
+	b1->add(rp1);
+	b1->add(rp2);
+
+	// fitting parameters
+	const int N = 20;
+	double e_i[N];
+	double f_1i[N], f_2i[N], g_1i[N], g_2i[N], d_1i[N], d_2i[N];
+	double k_1i[N], k_2i[N], l_1i[N], l_2i[N];
+	for(int i = 0; i < N; i++) {
+		e_i[i] = emin + i * (emax - emin)/((double)N-1);
+		// 
+		// the bug seems to be linked to the delete operator of the TMatrixT class in root.
+		// valgrind shows memory problems at that point.
+		// for unknwown reasons, copying the matrix gets around this bug.
+		// valgrind (related) ouptut :
+		//
+		// ==13029== Invalid read of size 4
+		// ==13029==    at 0x5E75DB6: H_RecRPObject::initialize() (in /home/jdf/GGamma/Hector/lib/libHector.so)
+		// ==13029==    by 0x804A2D8: intelligentreco_rpo(double, double, double, double, std::string, int) (H_IntelligentReco.cpp:314)
+		// ==13029==    by 0x804A937: main (H_IntelligentReco.cpp:542)
+		// ==13029==  Address 0x64AC740 is 80 bytes inside a block of size 144 free'd
+		// ==13029==    at 0x4021D18: operator delete[](void*) (vg_replace_malloc.c:256)
+		// ==13029==    by 0x5651F57: TMatrixT<float>::Delete_m(int, float*&) (in /home/jdf/root/5.12/lib/libMatrix.so)
+		// ==13029==    by 0x565CC5D: TMatrixT<float>::~TMatrixT() (in /home/jdf/root/5.12/lib/libMatrix.so)
+		// ==13029==    by 0x5E75D25: H_RecRPObject::initialize() (in /home/jdf/GGamma/Hector/lib/libHector.so)
+		//
+		//
+		TMatrix el_mattt(b1->getPartialMatrix("rp1",e_i[i],MP,QP));
+		const float *el_mat1 = el_mattt.GetMatrixArray();
+		// 
+		// conclusion : first line of el_mat1 is completely messed-up if it is taken directly from 
+		// the return of getpartialmatrix like this : 
+		// const float *el_mat1 = (b1->getPartialMatrix("rp1",e_i[i],MP,QP)).GetMatrixArray()
+		//
+		// long-term solution (apart noticing root staff) : replacing el_mat1[i] by the equivalent el_mattt(j,k)
+		// which is anyway more transparent for the reader.
+		//
+		f_1i[i] = el_mat1[0];
+		g_1i[i] = el_mat1[1*MDIM];
+		d_1i[i] = MEGA*el_mat1[4*MDIM];
+		k_1i[i] = el_mat1[2*MDIM+2];
+		l_1i[i] = el_mat1[3*MDIM+2];
+		const float* el_mat2 = (b1->getPartialMatrix("rp2",e_i[i],MP,QP).GetMatrixArray());
+		f_2i[i] = el_mat2[0];
+		g_2i[i] = el_mat2[1*MDIM];
+		d_2i[i] = MEGA*el_mat2[4*MDIM];
+		k_2i[i] = el_mat2[2*MDIM+2];
+		l_2i[i] = el_mat2[3*MDIM+2];
+	}
+	TGraph gf_1(N,e_i,f_1i);
+	TGraph gg_1(N,e_i,g_1i);
+	TGraph gd_1(N,e_i,d_1i);
+	TGraph gf_2(N,e_i,f_2i);
+	TGraph gg_2(N,e_i,g_2i);
+	TGraph gd_2(N,e_i,d_2i);
+	TGraph gk_1(N,e_i,k_1i);
+	TGraph gl_1(N,e_i,l_1i);
+	TGraph gk_2(N,e_i,k_2i);
+	TGraph gl_2(N,e_i,l_2i);
+
+    // functions get their final shape	
+	gf_1.Fit("f_1","Q");
+	gg_1.Fit("g_1","Q");
+	gd_1.Fit("d_1","Q");
+	gf_2.Fit("f_2","Q");
+	gg_2.Fit("g_2","Q");
+	gd_2.Fit("d_2","Q");
+	gk_1.Fit("k_1","Q");
+	gl_1.Fit("l_1","Q");
+	gk_2.Fit("k_2","Q");
+	gl_2.Fit("l_2","Q");
+
+	// cleaning the rest
+	delete b1;
+
+	// the end
+	return;
+}
+
+void H_RecRPObject::setDetPos(const float ss1, const float ss2) {
+	energy = NOT_YET_COMPUTED;
+	s1 = ss1;
+	s2 = ss2;
+	if(ss1==ss2) cout<<"<H_RecRPObject> WARNING : detectors are on same position"<<endl;
+	return;
+}
+
+void H_RecRPObject::setPositions(const float xx1, const float xx2, const float yy1, const float yy2) {
+	energy = NOT_YET_COMPUTED;
+	x1 = xx1;
+	x2 = xx2;
+	y1 = yy1;
+	y2 = yy2;
+	return;
+}
+
+void H_RecRPObject::setPosition_det1(const float xx1, const float yy1) {
+	energy = NOT_YET_COMPUTED;
+	x1 = xx1;
+	y1 = yy1;
+}
+
+void H_RecRPObject::setPosition_det2(const float xx2, const float yy2) {
+	energy = NOT_YET_COMPUTED;
+	x2 = xx2;
+	y2 = yy2;
+}
+
+void H_RecRPObject::setERange(const float eemin, const float eemax) {
+	energy = NOT_YET_COMPUTED;
+	emin = eemin;
+	emax = eemax;
+	f_1->SetRange(emin,emax);
+	f_2->SetRange(emin,emax);
+	g_1->SetRange(emin,emax);
+	g_2->SetRange(emin,emax);
+	d_1->SetRange(emin,emax);
+	d_2->SetRange(emin,emax);
+	k_1->SetRange(emin,emax);
+	k_2->SetRange(emin,emax);
+	l_1->SetRange(emin,emax);
+	l_2->SetRange(emin,emax);
+    return;
+}
+
+
+void H_RecRPObject::computeERange() {
+	// optional method to determine the energy range of the FIRST detector 
+	// in order to refine the fits and get maximum precision.
+	energy = NOT_YET_COMPUTED;
+	H_AbstractBeamLine * b1 = thebeam->clone();
+	H_RomanPot * rp1 = new H_RomanPot("rp1",s1,0);
+	b1->add(rp1);
+	float max = 1;
+	// number of energies to check 
+	const int N = 1000;
+	for(int i=0; i<N; i++) {
+		H_BeamParticle p;
+		p.setE(BE - (emin + i*(BE-emin)/((float)N)));
+		p.computePath(b1);
+		if(p.stopped(b1)) {
+			if(p.getStoppingElement()->getName()=="rp1") {
+				max = emin + i*(BE-emin)/((float)N);
+			}
+		}
+	}
+	cout<<"<H_RecRPObject> Valid energy losses run from 0 (default) to "<<max+20.<<" GeV"<<endl;
+	setERange(0,max+20.);
+	delete b1;
+	return;
+}
+
+void H_RecRPObject::computeAll() {
+	// The big game :
+	// computing E, tx, ty, Q2 and Pt and filling the variables.
+	//
+	// The root TF1 class features nice bugs, which explains the
+	// seemingly-dumb structures happening sometimes here as
+	// workarounds for these bugs. The overall thing works very
+	// well but will be cleaned later anyway.
+
+	if(energy!=NOT_YET_COMPUTED) {
+		cout<<"<H_RecRPObject> already computed variables, skipping ..."<<endl;
+		return;
+	}
+
+	TF1 par0("par0","[0]",emin,emax);
+	par0.SetParameter(0,-x1);
+	TF1 par2("par2","[0]",emin,emax);
+	par2.SetParameter(0,-y1);
+	TF1 par1("par1","[0]",emin,emax);
+	par1.SetParameter(0,-x2);
+	TF1 par3("par3","[0]",emin,emax);
+	par3.SetParameter(0,-y2);
+
+	// angle compensating method :
+	TF1 xx_E("xx_E","(g_2*(par0-d_1*x)-g_1*(par1-d_2*x))/(f_2*g_1-f_1*g_2)",emin,emax);
+	TF1 yy_E("yy_E","(par2*l_2 - par3*l_1) / (k_2*l_1 - k_1*l_2)",emin,emax);
+	TF1 xp_E("xp_E","(f_2*(par0-d_1*x)-f_1*(par1-d_2*x))/(g_2*f_1-g_1*f_2)",emin,emax);
+	TF1 yp_E("yp_E","(par2*k_2-par3*k_1)/(l_2*k_1-l_1*k_2)",emin,emax);
+	// it is possible to refine study using y info, but effect was not tested.	
+	// TF1 p_xy_E("p_xy_E","(-xx_E*xx_E-yy_E*yy_E)",emin,emax);
+	TF1 p_xy_E("p_xy_E","(-xx_E*xx_E)",emin,emax);
+
+	energy = p_xy_E.GetMaximumX(emin,emax);
+	txip = xp_E.Eval(energy);
+	tyip = yp_E.Eval(energy);
+	pt = sqrt(BE*(BE-energy)*(txip*txip+tyip*tyip)/(MEGA*MEGA));
+
+	return;
+}
+
+float H_RecRPObject::getE(int ) {
+// put for backward compatibility
+        if(energy==NOT_YET_COMPUTED) { computeAll(); };
+        return energy;
+}  // to be removed !!!!!
+
+float H_RecRPObject::getE() {
+	if(energy==NOT_YET_COMPUTED) { computeAll(); };
+	return energy;
+}
+
+float H_RecRPObject::getTX() {
+	if(energy==NOT_YET_COMPUTED) { computeAll(); };
+	return txip;
+}
+
+float H_RecRPObject::getTY() {
+	if(energy==NOT_YET_COMPUTED) { computeAll(); };
+	return tyip;
+}
+
+float H_RecRPObject::getQ2() {
+	if(energy==NOT_YET_COMPUTED) { computeAll(); };
+	cout<<"<H_RecRPObject::getQ2> Not implemented yet"<<endl;
+	return 0;
+}
+
+float H_RecRPObject::getPt() {
+	if(energy==NOT_YET_COMPUTED) { computeAll(); };
+	return pt;
+}
+
+std::ostream& operator<< (std::ostream& os, const H_RecRPObject& rp) {
+	os << "e_min=" <<  rp.emin << "\t e_max= " << rp.emax << endl;
+	os << "x1="    << rp.x1 << "\t x2= " << rp.x2 << "\t y1=" << rp.y1 << "\t y2=" << rp.y2 
+	   << "\t s1=" << rp.s1 << "\t s2=" << rp.s2 << endl;
+	os << "txip=" << rp.txip << "\t tyip=" << rp.tyip << "\t energy=" << rp.energy << "\t q2=" << rp.q2 << "\t pt=" << rp.pt << endl;
+   return os;
+}
+
Index: external/Hector/H_RecRPObject.h
===================================================================
--- external/Hector/H_RecRPObject.h	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
+++ external/Hector/H_RecRPObject.h	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
@@ -0,0 +1,83 @@
+#ifndef _H_RecRPObject_
+#define _H_RecRPObject_
+
+  /* * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ *                                                         *
+*                   --<--<--  A fast simulator --<--<--     *
+*                 / --<--<--     of particle   --<--<--     *
+*  ----HECTOR----<                                          *
+*                 \ -->-->-- transport through -->-->--     *
+*                   -->-->-- generic beamlines -->-->--     *
+*                                                           *
+* JINST 2:P09005 (2007)                                     *
+*      X Rouby, J de Favereau, K Piotrzkowski (CP3)         *
+*       http://www.fynu.ucl.ac.be/hector.html               *
+*                                                           *
+* Center for Cosmology, Particle Physics and Phenomenology  *
+*              Universite catholique de Louvain             *
+*                 Louvain-la-Neuve, Belgium                 *
+ *                                                         *
+   * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+/// \file H_RecRPObject.h
+/// \brief Reconstructed information from objects detected by two roman pots
+
+#include "TF1.h"
+#include <cmath>
+
+#include "H_BeamLine.h"
+
+#define NOT_YET_COMPUTED -666
+
+/// Reconstruction of parameters at IP using measurements with roman pots
+class H_RecRPObject {
+	public:
+		H_RecRPObject();
+		H_RecRPObject(const float, const float, const H_AbstractBeamLine* );
+		H_RecRPObject(const float, const float, const H_AbstractBeamLine& ); // old-fashioned -- to be deleted
+		H_RecRPObject(const H_RecRPObject&);
+		H_RecRPObject& operator=(const H_RecRPObject&);
+		~H_RecRPObject() {delete f_1; delete f_2; delete g_1; delete g_2; 
+				  delete d_1; delete d_2; delete k_1; delete k_2; 
+				  delete l_1; delete l_2; 
+				  delete thebeam;};
+
+		inline float getX1() const {return x1;};
+		inline float getX2() const {return x2;};
+		inline float getY1() const {return y1;};
+		inline float getY2() const {return y2;};
+		inline float getS1() const {return s1;};
+		inline float getS2() const {return s2;};
+
+		float getTX();
+		float getTY();
+		float getE();
+		float getE(int );
+		float getQ2();
+		float getPt();
+
+		void setPositions(const float, const float, const float, const float);
+		void setPosition_det1(const float, const float);
+		void setPosition_det2(const float, const float);
+		void setDetPos(const float, const float);
+		void setERange(const float, const float);
+		void computeERange();
+		void initialize();
+		void computeAll();
+
+	protected:
+
+		float emin, emax;
+		float x1, x2, y1, y2, s1, s2;
+		float txip, tyip, energy, q2, pt;
+		H_AbstractBeamLine* thebeam;
+		TF1* f_1, *f_2;
+		TF1* g_1, *g_2;
+		TF1* d_1, *d_2;
+		TF1* k_1, *k_2;
+		TF1* l_1, *l_2;
+	friend std::ostream& operator<< (std::ostream& os, const H_RecRPObject& rp);
+};
+
+#endif
+
Index: external/Hector/H_RectEllipticAperture.cc
===================================================================
--- external/Hector/H_RectEllipticAperture.cc	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
+++ external/Hector/H_RectEllipticAperture.cc	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
@@ -0,0 +1,139 @@
+  /* * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ *                                                         *
+*                   --<--<--  A fast simulator --<--<--     *
+*                 / --<--<--     of particle   --<--<--     *
+*  ----HECTOR----<                                          *
+*                 \ -->-->-- transport through -->-->--     *
+*                   -->-->-- generic beamlines -->-->--     *
+*                                                           *
+* JINST 2:P09005 (2007)                                     *
+*      X Rouby, J de Favereau, K Piotrzkowski (CP3)         *
+*       http://www.fynu.ucl.ac.be/hector.html               *
+*                                                           *
+* Center for Cosmology, Particle Physics and Phenomenology  *
+*              Universite catholique de Louvain             *
+*                 Louvain-la-Neuve, Belgium                 *
+ *                                                         *
+   * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+/// \file H_RectEllipticAperture.cc
+/// \brief Defines the Rect-Elliptic aperture of beamline elements.
+
+// C++ #includes
+#include <iostream>
+
+// C #includes
+#include <cmath> // needed for fabs
+
+// ROOT #includes
+#include "TPolyLine.h"
+
+// local #includes
+#include "H_RectEllipticAperture.h"
+using namespace std;
+
+H_RectEllipticAperture::H_RectEllipticAperture(const float l, const float h, const float L, const float H, const float posx, const float posy) :H_Aperture(RECTELLIPSE,((l==0)?L:l),((h==0)?H:h),L,H,posx,posy) {
+	/// @param l, h, L, H are the geometrical parameters of the rect-ellipse shape
+	/// @param posx, posy defines the (x,y) of the center of the shape
+}
+
+H_RectEllipticAperture* H_RectEllipticAperture::clone() const {
+	return new H_RectEllipticAperture(x1,x2,x3,x4,fx,fy);
+}
+
+
+TPolyLine * rectellipse(const float a_e = 2, const float b_e = 1, const float a_r = 1, const float b_r = 2, const float center_x = 0, const float center_y =0) {
+        const int n = 20;  // number of points per segment
+        const int N = 4*n; // there are 4 segments
+        float x[N+1], y[N+1];
+
+   if(a_e>a_r) {
+        // a rectellipse has 4 segments
+        // 1) upper one
+        for (int i=0; i<n; i++) {
+                x[i] = -a_r + i*(2*a_r)/(float)n;
+                y[i] =  b_e * sqrt(1-pow(x[i]/a_e,2));
+        }
+
+        // 2) right vertical segment
+        // upper right corner
+        const float y2 = b_e * sqrt(1-pow(a_r/a_e,2));
+        // lower right corner
+        const float y3 = -b_e * sqrt(1-pow(a_r/a_e,2));
+        for (int i=n; i<2*n; i++) {
+                x[i] = a_r;
+                y[i] = y2 - (i-n)*(2*y2)/(float)n;
+        }
+
+        // 3) lower side
+        for (int i=2*n; i<3*n; i++) {
+                x[i] = a_r - (i-2*n)*(2*a_r)/(float)n;
+                y[i] = -b_e * sqrt(1-pow(x[i]/a_e,2));
+        }
+
+        // 4) left vertical segment
+        // lower left corner
+        const float y4 = y3;
+        for (int i=3*n; i<4*n; i++) {
+                x[i] = -a_r;
+                y[i] = y4 + (i-3*n)*(2*y2)/(float)n;
+        }
+   } else {
+	// 1) upper one : flat
+	const float x1 = -a_e * sqrt(1-pow(b_r/b_e,2));
+	const float x2 = -x1;
+	for (int i=0; i<n; i++) {
+		y[i] = b_r;
+		x[i] = x1 + i * (x2-x1)/(float)n;
+	}
+	
+	// 2) right curved border
+	for (int i=n; i<2*n; i++) {
+		y[i] = b_r - (i-n) * (2*b_r)/(float)n;
+		x[i] = a_e * sqrt(1-pow(y[i]/b_e,2));
+	}
+
+	// 3) lower side : flat
+	for (int i=2*n; i<3*n; i++) {
+		y[i] = -b_r;
+		x[i] = x2 - (i-2*n) * (2*x2)/(float)n;
+	}
+	
+	// 4) left curved border
+	for (int i=3*n; i<4*n; i++) {
+		y[i] = -b_r + (i-3*n) * (2*b_r)/(float)n;
+		x[i] = -a_e * sqrt(1-pow(y[i]/b_e,2));
+	}
+   }
+
+	// closing the polyline
+        x[N] = x[0];
+        y[N] = y[0];
+
+	// shifting the center
+        for (int i=0; i<N+1; i++) {
+                x[i] += center_x;
+                y[i] += center_y;
+        }
+
+        return new TPolyLine(N+1,x,y);
+}
+
+
+void H_RectEllipticAperture::draw(const float scale) const {
+	TPolyLine * re = rectellipse(x3*scale, x4*scale, x1*scale, x2*scale, fx*scale, fy*scale);
+	re->SetLineColor(39);
+	re->SetLineWidth(2);
+	re->Draw("l");
+	return;
+}
+
+bool H_RectEllipticAperture::isInside(const float x, const float y) const {
+	return((fabs(fx-x)<x1)&&(fabs(fy-y)<x2)&&(((x-fx)/x3)*((x-fx)/x3)+((y-fy)/x4)*((y-fy)/x4)<1));
+}
+
+std::ostream& operator<< (std::ostream& os, const H_RectEllipticAperture& ap) {
+	os << "Aperture shape:" << ap.aptypestring << ", parameters " << ap.x1 <<", "<< ap.x2 <<", "<< ap.x3 <<", "<< ap.x4 << endl;
+	os << " \t Center : " << ap.fx <<", "<< ap.fy <<endl;
+	return os;
+}
Index: external/Hector/H_RectEllipticAperture.h
===================================================================
--- external/Hector/H_RectEllipticAperture.h	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
+++ external/Hector/H_RectEllipticAperture.h	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
@@ -0,0 +1,46 @@
+#ifndef _H_RectEllipticAperture_
+#define _H_RectEllipticAperture_
+
+  /* * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ *                                                         *
+*                   --<--<--  A fast simulator --<--<--     *
+*                 / --<--<--     of particle   --<--<--     *
+*  ----HECTOR----<                                          *
+*                 \ -->-->-- transport through -->-->--     *
+*                   -->-->-- generic beamlines -->-->--     *
+*                                                           *
+* JINST 2:P09005 (2007)                                     *
+*      X Rouby, J de Favereau, K Piotrzkowski (CP3)         *
+*       http://www.fynu.ucl.ac.be/hector.html               *
+*                                                           *
+* Center for Cosmology, Particle Physics and Phenomenology  *
+*              Universite catholique de Louvain             *
+*                 Louvain-la-Neuve, Belgium                 *
+ *                                                         *
+   * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+/// \file H_RectEllipticAperture.h
+/// \brief Defines the Rect-Elliptic aperture of beamline elements.
+
+// local #includes
+#include "H_Aperture.h"
+
+/// Rect-ellipse apertures
+class H_RectEllipticAperture: public H_Aperture {
+
+	public:
+		///     Constructors and Destructor
+		//@{
+		H_RectEllipticAperture():H_Aperture(RECTELLIPSE,0,0,0,0,0,0) {}
+		H_RectEllipticAperture(const float,const float,const float,const float, const float, const float);
+		~H_RectEllipticAperture() {};
+		H_RectEllipticAperture* clone() const;
+		//@}
+		/// Checks whether the point is inside the aperture or not
+		virtual bool isInside(const float, const float) const;
+		/// Draws the aperture shape.
+		virtual void draw(const float scale=1) const;
+	friend std::ostream& operator<< (std::ostream& os, const H_RectEllipticAperture& ap);
+};
+
+#endif
Index: external/Hector/H_RectangularAperture.cc
===================================================================
--- external/Hector/H_RectangularAperture.cc	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
+++ external/Hector/H_RectangularAperture.cc	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
@@ -0,0 +1,63 @@
+  /* * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ *                                                         *
+*                   --<--<--  A fast simulator --<--<--     *
+*                 / --<--<--     of particle   --<--<--     *
+*  ----HECTOR----<                                          *
+*                 \ -->-->-- transport through -->-->--     *
+*                   -->-->-- generic beamlines -->-->--     *
+*                                                           *
+* JINST 2:P09005 (2007)                                     *
+*      X Rouby, J de Favereau, K Piotrzkowski (CP3)         *
+*       http://www.fynu.ucl.ac.be/hector.html               *
+*                                                           *
+* Center for Cosmology, Particle Physics and Phenomenology  *
+*              Universite catholique de Louvain             *
+*                 Louvain-la-Neuve, Belgium                 *
+ *                                                         *
+   * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+/// \file H_RectangularAperture.cc
+/// \brief Defines the rectangular aperture of beamline elements.
+
+// C++ #includes
+#include <iostream>
+
+// C #includes
+#include <cmath> // needed for fabs
+
+// ROOT #includes
+#include "TPave.h"
+
+// local #includes
+#include "H_RectangularAperture.h"
+using namespace std;
+
+H_RectangularAperture::H_RectangularAperture(const float l, const float h, const float posx, const float posy) :H_Aperture(RECTANGULAR,l,h,0,0,posx,posy) {
+	/// @param l, h are the length and height of the rectangular shape
+	/// @param posx, posy are the (x,y) coordinates of the center of the rectangular shape
+}
+
+H_RectangularAperture* H_RectangularAperture::clone() const {
+	return new H_RectangularAperture(x1,x2,fx,fy);
+}
+
+bool H_RectangularAperture::isInside(const float x, const float y) const {
+	/// @param x, y are the (x,y) coordinates of the proton, in [m]
+	return (fabs(x-fx)<x1&&fabs(y-fy)<x2);
+}
+
+void H_RectangularAperture::draw(const float scale) const {
+	TPave* tp = new TPave((fx-x1)*scale,(fy-x2)*scale,(fx+x1)*scale,(fy+x2)*scale,1);
+	tp->SetFillStyle(3003);
+	tp->SetLineColor(2);
+	tp->SetFillColor(2);
+	tp->Draw();
+	return;
+}
+
+std::ostream& operator<< (std::ostream& os, const H_RectangularAperture& ap) {
+	os << "Aperture shape:" << ap.aptypestring << ", rectangle sides : " << ap. x1 <<", " << ap.x2 <<endl;
+	os << " \t Center : " << ap.fx << "," << ap.fy << endl;
+        return os;
+}
+
Index: external/Hector/H_RectangularAperture.h
===================================================================
--- external/Hector/H_RectangularAperture.h	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
+++ external/Hector/H_RectangularAperture.h	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
@@ -0,0 +1,46 @@
+#ifndef _H_RectangularAperture_
+#define _H_RectangularAperture_
+
+  /* * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ *                                                         *
+*                   --<--<--  A fast simulator --<--<--     *
+*                 / --<--<--     of particle   --<--<--     *
+*  ----HECTOR----<                                          *
+*                 \ -->-->-- transport through -->-->--     *
+*                   -->-->-- generic beamlines -->-->--     *
+*                                                           *
+* JINST 2:P09005 (2007)                                     *
+*      X Rouby, J de Favereau, K Piotrzkowski (CP3)         *
+*       http://www.fynu.ucl.ac.be/hector.html               *
+*                                                           *
+* Center for Cosmology, Particle Physics and Phenomenology  *
+*              Universite catholique de Louvain             *
+*                 Louvain-la-Neuve, Belgium                 *
+ *                                                         *
+   * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+/// \file H_RectangularAperture.h
+/// \brief Defines the rectangular aperture of beamline elements.
+
+// local #includes
+#include "H_Aperture.h"
+
+/// Rectangular apertures
+class H_RectangularAperture : public H_Aperture {
+
+	public:
+		/// Constructors and destructor
+		//@{
+		H_RectangularAperture():H_Aperture(RECTANGULAR,0,0,0,0,0,0) {}
+		H_RectangularAperture(const float,const float,const float,const float);
+		~H_RectangularAperture() {};
+		H_RectangularAperture* clone() const;
+		//@}
+		/// Checks whether the point is inside the aperture or not 
+		virtual bool isInside(const float, const float) const;
+		/// Draws the aperture shape.
+		virtual void draw(const float scale=1) const;
+	friend std::ostream& operator<< (std::ostream& os, const H_RectangularAperture& ap);
+};
+
+#endif
Index: external/Hector/H_RectangularCollimator.cc
===================================================================
--- external/Hector/H_RectangularCollimator.cc	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
+++ external/Hector/H_RectangularCollimator.cc	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
@@ -0,0 +1,73 @@
+  /* * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ *                                                         *
+*                   --<--<--  A fast simulator --<--<--     *
+*                 / --<--<--     of particle   --<--<--     *
+*  ----HECTOR----<                                          *
+*                 \ -->-->-- transport through -->-->--     *
+*                   -->-->-- generic beamlines -->-->--     *
+*                                                           *
+* JINST 2:P09005 (2007)                                     *
+*      X Rouby, J de Favereau, K Piotrzkowski (CP3)         *
+*       http://www.fynu.ucl.ac.be/hector.html               *
+*                                                           *
+* Center for Cosmology, Particle Physics and Phenomenology  *
+*              Universite catholique de Louvain             *
+*                 Louvain-la-Neuve, Belgium                 *
+ *                                                         *
+   * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+/// \file H_RectangularCollimator.cc
+/// \brief R-Collimators for the LHC beamline.
+
+// local #includes
+#include "H_RectangularCollimator.h"
+#include "H_TransportMatrices.h"
+
+void H_RectangularCollimator::init() {
+	// must be in public section
+		setTypeString();
+		setMatrix(0,MP,QP);
+	return;
+}
+
+H_RectangularCollimator::H_RectangularCollimator(const double s, const double l) :H_Drift(s,l){
+	type = RCOLLIMATOR;
+	init();
+	return;
+}
+
+H_RectangularCollimator::H_RectangularCollimator(const string& nameE, const double s, const double l) :H_Drift(nameE,s,l){
+	type = RCOLLIMATOR;
+	init();
+	return;
+}
+
+std::ostream& operator<< (std::ostream& os, const H_RectangularCollimator& el) {
+	os << el.typestring << el.name << "\t\t at s = " << el.fs << "\t length = " << el.element_length <<endl;
+	if(el.element_aperture->getType()!=NONE) {
+        	os << *(el.element_aperture) << endl;
+	}
+
+	if(el.element_length<0 && VERBOSE) os <<"<H_RectangularCollimator> ERROR : Interpenetration of elements !"<<endl; 
+	else if(el.element_length==0 && VERBOSE) os <<"<H_RectangularCollimator> WARNING : 0-length "<< el.name << " !" << endl;
+   return os;
+}
+
+//void H_RectangularCollimator::setMatrix(const float eloss, const float p_mass, const float p_charge) {
+void H_RectangularCollimator::setMatrix(const float , const float , const float ) {
+	element_mat = driftmat(element_length);
+	return ;
+}
+
+H_RectangularCollimator* H_RectangularCollimator::clone() const {
+	H_RectangularCollimator* temp_coll = new H_RectangularCollimator(name,fs,element_length);
+	temp_coll->setAperture(element_aperture);
+	temp_coll->setX(xpos);
+	temp_coll->setY(ypos);
+	temp_coll->setTX(txpos);
+	temp_coll->setTY(typos);
+	temp_coll->setBetaX(betax);
+	temp_coll->setBetaY(betay);
+	return temp_coll;
+}
+
Index: external/Hector/H_RectangularCollimator.h
===================================================================
--- external/Hector/H_RectangularCollimator.h	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
+++ external/Hector/H_RectangularCollimator.h	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
@@ -0,0 +1,48 @@
+#ifndef _H_RectangularCollimator_
+#define _H_RectangularCollimator_
+
+  /* * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ *                                                         *
+*                   --<--<--  A fast simulator --<--<--     *
+*                 / --<--<--     of particle   --<--<--     *
+*  ----HECTOR----<                                          *
+*                 \ -->-->-- transport through -->-->--     *
+*                   -->-->-- generic beamlines -->-->--     *
+*                                                           *
+* JINST 2:P09005 (2007)                                     *
+*      X Rouby, J de Favereau, K Piotrzkowski (CP3)         *
+*       http://www.fynu.ucl.ac.be/hector.html               *
+*                                                           *
+* Center for Cosmology, Particle Physics and Phenomenology  *
+*              Universite catholique de Louvain             *
+*                 Louvain-la-Neuve, Belgium                 *
+ *                                                         *
+   * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+/// \file H_RectangularCollimator.h
+/// \brief Class describing Rectangular Collimators
+
+// local #includes
+#include "H_Drift.h"
+
+/// R-Collimators for the LHC beamline.
+class H_RectangularCollimator : public H_Drift {
+
+	public:
+	/// Constructors and destructor
+	//@{
+		H_RectangularCollimator():H_Drift() {type = RCOLLIMATOR; init();}
+		H_RectangularCollimator(const double, const double );
+		H_RectangularCollimator(const string&, const double, const double );
+		~H_RectangularCollimator() {};
+	//@}
+		H_RectangularCollimator* clone() const;
+		void init();
+	private:
+	 	virtual void setTypeString() {typestring=RCOLLIMATORNAME;};
+		virtual void setMatrix(const float, const float, const float) ;
+	
+	friend std::ostream& operator<< (std::ostream& os, const H_RectangularCollimator& el);
+};
+
+#endif
Index: external/Hector/H_RectangularDipole.cc
===================================================================
--- external/Hector/H_RectangularDipole.cc	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
+++ external/Hector/H_RectangularDipole.cc	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
@@ -0,0 +1,45 @@
+  /* * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ *                                                         *
+*                   --<--<--  A fast simulator --<--<--     *
+*                 / --<--<--     of particle   --<--<--     *
+*  ----HECTOR----<                                          *
+*                 \ -->-->-- transport through -->-->--     *
+*                   -->-->-- generic beamlines -->-->--     *
+*                                                           *
+* JINST 2:P09005 (2007)                                     *
+*      X Rouby, J de Favereau, K Piotrzkowski (CP3)         *
+*       http://www.fynu.ucl.ac.be/hector.html               *
+*                                                           *
+* Center for Cosmology, Particle Physics and Phenomenology  *
+*              Universite catholique de Louvain             *
+*                 Louvain-la-Neuve, Belgium                 *
+ *                                                         *
+   * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+/// \file H_RectangularDipole.cc
+/// \brief Classes aiming at simulating LHC beam rectangular dipoles
+
+#include "H_RectangularDipole.h"
+#include "H_TransportMatrices.h"
+
+void H_RectangularDipole::setMatrix(const float eloss, const float p_mass, const float p_charge) {
+	if (fk !=0 ) element_mat = rdipmat(element_length,fk,eloss,p_mass,p_charge);
+	else  {
+		element_mat = driftmat(element_length);
+		if(VERBOSE) cout<<"<H_RectangularDipole> WARNING : k0= 0, drift-like dipole (" << name << ") !" << endl;
+	}
+	return ;
+}
+
+H_RectangularDipole* H_RectangularDipole::clone() const {
+	H_RectangularDipole* temp_dip = new H_RectangularDipole(name,fs,fk,element_length);
+	temp_dip->setAperture(element_aperture);
+	temp_dip->setX(xpos);
+	temp_dip->setY(ypos);
+	temp_dip->setTX(txpos);
+	temp_dip->setTY(typos);
+	temp_dip->setBetaX(betax);
+	temp_dip->setBetaY(betay);
+	return temp_dip;
+}
+
Index: external/Hector/H_RectangularDipole.h
===================================================================
--- external/Hector/H_RectangularDipole.h	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
+++ external/Hector/H_RectangularDipole.h	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
@@ -0,0 +1,44 @@
+#ifndef _H_RectangularDipole_
+#define _H_RectangularDipole_
+
+  /* * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ *                                                         *
+*                   --<--<--  A fast simulator --<--<--     *
+*                 / --<--<--     of particle   --<--<--     *
+*  ----HECTOR----<                                          *
+*                 \ -->-->-- transport through -->-->--     *
+*                   -->-->-- generic beamlines -->-->--     *
+*                                                           *
+* JINST 2:P09005 (2007)                                     *
+*      X Rouby, J de Favereau, K Piotrzkowski (CP3)         *
+*       http://www.fynu.ucl.ac.be/hector.html               *
+*                                                           *
+* Center for Cosmology, Particle Physics and Phenomenology  *
+*              Universite catholique de Louvain             *
+*                 Louvain-la-Neuve, Belgium                 *
+ *                                                         *
+   * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+/// \file H_RectangularDipole.h
+/// \brief Classes aiming at simulating LHC beam rectangular dipoles.
+
+#include "H_Dipole.h"
+
+/// Rectangle dipoles.
+class H_RectangularDipole : public H_Dipole {
+
+	public:
+		/// constructor
+		//@{
+		H_RectangularDipole():H_Dipole(RDIPOLE,0.,0.,0.) {init();}
+		H_RectangularDipole(const double s, const double k, const double l) :H_Dipole(RDIPOLE,s,k,l){init();}
+		H_RectangularDipole(const string& nameE, const double s, const double k, const double l) :H_Dipole(nameE,RDIPOLE,s,k,l){init();}
+		~H_RectangularDipole() {};
+		//@}
+		H_RectangularDipole* clone() const ;
+	private:
+		virtual void setTypeString() { typestring = RDIPOLENAME;};
+		virtual void setMatrix(const float, const float, const float) ;
+};
+
+#endif
Index: external/Hector/H_RomanPot.cc
===================================================================
--- external/Hector/H_RomanPot.cc	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
+++ external/Hector/H_RomanPot.cc	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
@@ -0,0 +1,72 @@
+  /* * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ *                                                         *
+*                   --<--<--  A fast simulator --<--<--     *
+*                 / --<--<--     of particle   --<--<--     *
+*  ----HECTOR----<                                          *
+*                 \ -->-->-- transport through -->-->--     *
+*                   -->-->-- generic beamlines -->-->--     *
+*                                                           *
+* JINST 2:P09005 (2007)                                     *
+*      X Rouby, J de Favereau, K Piotrzkowski (CP3)         *
+*       http://www.fynu.ucl.ac.be/hector.html               *
+*                                                           *
+* Center for Cosmology, Particle Physics and Phenomenology  *
+*              Universite catholique de Louvain             *
+*                 Louvain-la-Neuve, Belgium                 *
+ *                                                         *
+   * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+/// \file H_RomanPot.cc
+/// \brief Roman pot class
+
+// local #includes
+#include "H_RomanPot.h"
+#include "H_RectangularAperture.h"
+#include "H_TransportMatrices.h"
+
+void H_RomanPot::init() {
+	// must be in public section
+		setTypeString();
+		setMatrix(0,MP,QP);
+	return;
+}
+
+H_RomanPot::H_RomanPot(const double s, const double app) :H_Drift(s,RP_LENGTH){
+		type = RP;
+		init();
+		if(element_aperture) delete element_aperture;
+		element_aperture = new H_RectangularAperture(app,RP_HEIGHT,0,0);
+}
+
+H_RomanPot::H_RomanPot(const string& nameE, const double s, const double app) :H_Drift(nameE,s,RP_LENGTH){
+		type = RP;
+		init();
+		if(element_aperture) delete element_aperture;
+		element_aperture = new H_RectangularAperture(app,RP_HEIGHT,0,0);
+}
+
+std::ostream& operator<< (std::ostream& os, const H_RomanPot& el) {
+	os << el.typestring << el.name << "\t\t at s = " << el.fs;
+	if(el.element_aperture->getType()!=NONE) {
+		os << *(el.element_aperture) << endl;
+	}
+   return os;
+}
+
+void H_RomanPot::setMatrix(const float eloss, const float p_mass, const float p_charge) {
+		element_mat = driftmat(0);
+	return ;
+}
+
+H_RomanPot* H_RomanPot::clone() const {
+	H_RomanPot* temp_rp = new H_RomanPot(name,fs,element_length);
+	temp_rp->setAperture(element_aperture);
+	temp_rp->setX(xpos);
+	temp_rp->setY(ypos);
+	temp_rp->setTX(txpos);
+	temp_rp->setTY(typos);
+	temp_rp->setBetaX(betax);
+	temp_rp->setBetaY(betay);
+	return temp_rp;
+}
+
Index: external/Hector/H_RomanPot.h
===================================================================
--- external/Hector/H_RomanPot.h	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
+++ external/Hector/H_RomanPot.h	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
@@ -0,0 +1,49 @@
+#ifndef _H_RomanPot_
+#define _H_RomanPot_
+
+  /* * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ *                                                         *
+*                   --<--<--  A fast simulator --<--<--     *
+*                 / --<--<--     of particle   --<--<--     *
+*  ----HECTOR----<                                          *
+*                 \ -->-->-- transport through -->-->--     *
+*                   -->-->-- generic beamlines -->-->--     *
+*                                                           *
+* JINST 2:P09005 (2007)                                     *
+*      X Rouby, J de Favereau, K Piotrzkowski (CP3)         *
+*       http://www.fynu.ucl.ac.be/hector.html               *
+*                                                           *
+* Center for Cosmology, Particle Physics and Phenomenology  *
+*              Universite catholique de Louvain             *
+*                 Louvain-la-Neuve, Belgium                 *
+ *                                                         *
+   * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+/// \file H_RomanPot.h
+/// \brief Roman pot class
+
+// local #includes
+#include "H_Drift.h"
+
+#define RP_LENGTH 0.0001
+#define RP_HEIGHT 10000
+/// Roman pot as an optics element.
+class H_RomanPot : public H_Drift {
+
+	public:
+	///     Constructors and destructor
+	//@{
+		H_RomanPot():H_Drift() {type = RP; init();}
+		H_RomanPot(const string&, const double, const double);
+		H_RomanPot(const double, const double);
+		~H_RomanPot() {};
+	//@}
+		H_RomanPot* clone() const ;
+		void init();
+	private:
+		virtual void setTypeString() {typestring=RPNAME;};
+		virtual void setMatrix(const float, const float, const float) ;
+	friend std::ostream& operator<< (std::ostream& os, const H_RomanPot& el);
+};
+
+#endif
Index: external/Hector/H_SectorDipole.cc
===================================================================
--- external/Hector/H_SectorDipole.cc	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
+++ external/Hector/H_SectorDipole.cc	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
@@ -0,0 +1,45 @@
+  /* * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ *                                                         *
+*                   --<--<--  A fast simulator --<--<--     *
+*                 / --<--<--     of particle   --<--<--     *
+*  ----HECTOR----<                                          *
+*                 \ -->-->-- transport through -->-->--     *
+*                   -->-->-- generic beamlines -->-->--     *
+*                                                           *
+* JINST 2:P09005 (2007)                                     *
+*      X Rouby, J de Favereau, K Piotrzkowski (CP3)         *
+*       http://www.fynu.ucl.ac.be/hector.html               *
+*                                                           *
+* Center for Cosmology, Particle Physics and Phenomenology  *
+*              Universite catholique de Louvain             *
+*                 Louvain-la-Neuve, Belgium                 *
+ *                                                         *
+   * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+/// \file H_SectorDipole.cc
+/// \brief Classes aiming at simulating sector dipoles
+
+#include "H_SectorDipole.h"
+#include "H_TransportMatrices.h"
+
+void H_SectorDipole::setMatrix(const float eloss, const float p_mass, const float p_charge) {
+	if (fk !=0 ) element_mat = sdipmat(element_length,fk,eloss,p_mass,p_charge);
+	else  {
+		element_mat = driftmat(element_length);
+		if(VERBOSE) cout<<"<H_SectorDipole> WARNING : k0= 0, drift-like dipole (" << name << ") !" << endl;
+   		}
+	return ;
+}
+
+H_SectorDipole* H_SectorDipole::clone() const {
+	H_SectorDipole* temp_dip = new H_SectorDipole(name,fs,fk,element_length);
+	temp_dip->setAperture(element_aperture);
+	temp_dip->setX(xpos);
+	temp_dip->setY(ypos);
+	temp_dip->setTX(txpos);
+	temp_dip->setTY(typos);
+	temp_dip->setBetaX(betax);
+	temp_dip->setBetaY(betay);
+	return temp_dip;
+}
+
Index: external/Hector/H_SectorDipole.h
===================================================================
--- external/Hector/H_SectorDipole.h	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
+++ external/Hector/H_SectorDipole.h	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
@@ -0,0 +1,44 @@
+#ifndef _H_SectorDipole_
+#define _H_SectorDipole_
+
+  /* * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ *                                                         *
+*                   --<--<--  A fast simulator --<--<--     *
+*                 / --<--<--     of particle   --<--<--     *
+*  ----HECTOR----<                                          *
+*                 \ -->-->-- transport through -->-->--     *
+*                   -->-->-- generic beamlines -->-->--     *
+*                                                           *
+* JINST 2:P09005 (2007)                                     *
+*      X Rouby, J de Favereau, K Piotrzkowski (CP3)         *
+*       http://www.fynu.ucl.ac.be/hector.html               *
+*                                                           *
+* Center for Cosmology, Particle Physics and Phenomenology  *
+*              Universite catholique de Louvain             *
+*                 Louvain-la-Neuve, Belgium                 *
+ *                                                         *
+   * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+/// \file H_SectorDipole.h
+/// \brief Classes aiming at simulating sector dipoles.
+
+#include "H_Dipole.h"
+
+/// Sector dipoles.
+class H_SectorDipole : public H_Dipole {
+
+	public:
+		/// Constructors and destructor
+		//@{
+		H_SectorDipole():H_Dipole(SDIPOLE,0.,0.,0.) {init();}
+		H_SectorDipole(const double s, const double k, const double l) :H_Dipole(SDIPOLE,s,k,l){init();}
+		H_SectorDipole(const string& nameE, const double s, const double k, const double l) :H_Dipole(nameE,SDIPOLE,s,k,l){init();}
+		~H_SectorDipole() {};
+		//@}
+		H_SectorDipole* clone() const ;
+	private:
+		virtual void setTypeString() { typestring = SDIPOLENAME;};
+		virtual void setMatrix(const float ,const float, const float) ;
+};
+
+#endif
Index: external/Hector/H_TransportMatrices.cc
===================================================================
--- external/Hector/H_TransportMatrices.cc	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
+++ external/Hector/H_TransportMatrices.cc	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
@@ -0,0 +1,302 @@
+  /* * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ *                                                         *
+*                   --<--<--  A fast simulator --<--<--     *
+*                 / --<--<--     of particle   --<--<--     *
+*  ----HECTOR----<                                          *
+*                 \ -->-->-- transport through -->-->--     *
+*                   -->-->-- generic beamlines -->-->--     *
+*                                                           *
+* JINST 2:P09005 (2007)                                     *
+*      X Rouby, J de Favereau, K Piotrzkowski (CP3)         *
+*       http://www.fynu.ucl.ac.be/hector.html               *
+*                                                           *
+* Center for Cosmology, Particle Physics and Phenomenology  *
+*              Universite catholique de Louvain             *
+*                 Louvain-la-Neuve, Belgium                 *
+ *                                                         *
+   * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+/// \file H_TransportMatrices.cc
+/// \brief Includes the implementation of every transport matrix.
+
+// c++ #includes
+#include <iostream>
+
+// C #includes
+#include <cmath>
+
+// local #includes
+#include "H_Parameters.h"
+#include "H_TransportMatrices.h"
+using namespace std;
+
+bool relative_energy = 1;
+
+// caution : do not change particle mass, not implemented yet.
+
+extern double omega(const double k, const double l) {
+		// [l] = [m] and [k] = [1/m^2] for quadrupoles
+		// [omega] = [1]
+	return sqrt(fabs(k))*l;
+}
+
+extern double radius(const double k) {
+		// [k] = [1/m^2] for quadrupoles
+		// [k] = [1/m]  for dipoles
+		// [radius(k)] = [m]
+	if(k==0 && VERBOSE) cout<<"<H_TransportMatrices> ERROR : Dipole has no effect : results will be corrupted"<<endl; 
+	// this is protected by the "if(k==0) -> driftmat" in every matrix below (ex vquatmat)
+	return (k==0) ? 1 : 1/k;
+}
+
+extern void printMatrix(TMatrix TMat) {
+	char temp[20];
+	float * el = new float[MDIM*MDIM];
+	el = (TMat.GetMatrixArray());
+
+	cout << endl << "\t";
+	for(int i=0;i<MDIM*MDIM;i++) {
+		if (el[i]<0)
+  			 {sprintf(temp,"%.5e",el[i]);}
+		else if (el[i]>0)
+   			 {sprintf(temp," %.5e",el[i]);}
+   		else {sprintf(temp,"       0    ");}
+   		
+		cout << temp << " ";
+		if((i+1)%MDIM == 0) { cout << endl << "\t"; }
+	}
+	cout << endl;
+}
+
+extern TMatrix vquadmat(const float l, const float k, const float eloss = 0., const float p_mass=MP, const float p_charge=QP) {
+		// the length l is in [m]
+		// the strength k is in [1/mï¿œ] for quadrupoles
+		// eloss in [GeV]
+		// ke is the modified field with respect to the eloss
+                //  k = e/p * dB/dx with p = mv (and m = MP)
+                //  k -> ke = k * p/ (p - dp) <- chromacity
+                //  ke -> ke * p_charge / QP <- if not a proton
+                //  ke = 0 if charge = 0, whatever the mass
+                
+	const double p0 = sqrt( (BE-MP)*(BE+MP) );
+	const double E  = BE - eloss;
+	const double p  = sqrt( (E-p_mass)*(E+p_mass) );
+	const float ke = (p_charge==0) ? 0 : k* p0/p  *p_charge/QP;
+	if (ke==0) {
+		TMatrix drift(driftmat(l));		
+		return drift;
+	}
+	// else... : 
+	float om = omega(ke,l);
+	float * mat = new float[MDIM*MDIM];
+	float tmat[MDIM*MDIM] =  {cosh(om),sqrt(ke)*sinh(om),0.,0., 0.,0.,
+                           (1/sqrt(ke))*sinh(om),cosh(om),0.,0., 0.,0.,
+                           0.,0.,cos(om),-sqrt(ke)*sin(om), 0.,0.,
+                           0.,0.,(1/sqrt(ke))*sin(om),cos(om), 0.,0.,
+                           0., 0., 0., 0., 1., 0.,
+			   0., 0., 0., 0., 0., 1.
+	};
+	for (int i=0; i<MDIM*MDIM; i++) {mat[i] = tmat[i];}
+	TMatrix TMat(MDIM,MDIM,mat);
+	delete [] mat;
+    return TMat;
+}
+
+extern TMatrix hquadmat(const float l, const float k, const float eloss = 0., const float p_mass=MP, const float p_charge=QP) {
+		// the length l is in [m]
+		// the strength k is in [1/mï¿œ] for quadrupoles
+		// ke is the modified field with respect to the eloss
+                //  k = e/p * dB/dx with p = mv (and m = MP)
+                //  k -> ke = k * p/ (p- dp) <- chromacity
+                //  ke -> ke *p_charge/QP <- if not a proton
+        const double p0 = sqrt( (BE-MP)*(BE+MP) );
+        const double E  = BE - eloss;
+        const double p  = sqrt( (E-p_mass)*(E+p_mass) );
+        const float ke = (p_charge==0) ? 0 : fabs(k* p0/p)  *p_charge/QP;
+
+        if (ke==0) {
+		TMatrix drift(driftmat(l));
+		return drift;
+	}
+	float om = omega(ke,l);
+	float * mat = new float[MDIM*MDIM];
+	float tmat[MDIM*MDIM] =  {cos(om),-sqrt(ke)*sin(om),0.,0., 0., 0.,
+                           (1/sqrt(ke))*sin(om),cos(om),0.,0., 0., 0.,
+                           0.,0.,cosh(om),sqrt(ke)*sinh(om), 0., 0., 
+                           0.,0.,(1/sqrt(ke))*sinh(om),cosh(om), 0., 0.,
+                    	    0., 0., 0., 0., 1., 0.,
+                           0., 0., 0., 0., 0., 1. 
+	};
+	for(int i=0;i<MDIM*MDIM;i++) { mat[i] = tmat[i]; }
+	TMatrix TMat(MDIM,MDIM,mat);
+	delete [] mat;
+    return TMat;
+}
+
+extern TMatrix rdipmat(const float l, const float k, const float eloss = 0., const float p_mass=MP, const float p_charge=QP) {
+		// the length l is in [m]
+		// the strength k is in [1/m] for dipoles
+		// ke is the modified field with respect to the eloss
+                //  k = e/p * dB/dx with p = mv (and m = MP)
+                //  k -> ke = k * p/ (p- dp) <- chromacity
+                //  ke -> ke * q_mass/QP <- if not a proton
+
+        const double p0 = sqrt( (BE-MP)*(BE+MP) );
+        const double E  = BE - eloss;
+        const double p  = sqrt( (E-p_mass)*(E+p_mass) );
+        const float ke = (p_charge==0) ? 0 : k* p0/p  *p_charge/QP;
+ 
+        if (ke==0) {
+ 		TMatrix drift(driftmat(l));
+		return drift;
+	}
+	float r = radius(ke);
+	float * mat = new float[MDIM*MDIM];
+	float * efmat = new float[MDIM*MDIM];
+	double simp = r*2*sin(l/(2*r))*sin(l/(2*r))/BE;
+	double psy = ke*l/2.;
+	float tefmat[MDIM*MDIM] = {1., tan(psy)*ke, 0., 0., 0., 0.,
+	                            0., 1., 0., 0., 0., 0.,
+	                            0., 0., 1., -tan(psy)*ke, 0., 0.,
+	                            0., 0., 0., 1., 0., 0.,
+	                            0., 0., 0., 0., 1., 0.,
+	                            0., 0., 0., 0., 0., 1. };
+ 
+	float tmat[MDIM*MDIM] =  {cos(l/r),(-1/r)*sin(l/r),0.,0., 0., 0.,
+	             	           r*sin(l/r),cos(l/r),0.,0., 0., 0.,
+   		           	           0.,0.,1.,0., 0., 0.,
+   	            	           0.,0.,l,1., 0., 0., 
+   	                        simp, sin(l/r)/BE, 0., 0., 1., 0.,
+   	                        0., 0., 0., 0., 0., 1. };
+	for(int i=0;i<MDIM*MDIM;i++) { 
+		mat[i] = tmat[i];
+	    efmat[i] = tefmat[i];	
+	}
+	TMatrix TMat(MDIM,MDIM,mat);
+	TMatrix TEfmat(MDIM,MDIM,efmat);
+    if(relative_energy) {
+        TMat *= TEfmat;
+        TEfmat *= TMat;
+    }
+
+//	if(VERBOSE) cout<<"\t WARNING : RDipoles not implemented and replaced by SDipoles" << endl;
+	delete [] mat;
+	delete [] efmat;
+    if(relative_energy) {
+        return TEfmat;
+    } else {
+        return TMat;
+    }
+}
+
+extern TMatrix sdipmat(const float l, const float k, const float eloss = 0., const float p_mass=MP, const float p_charge=QP) {
+		// the length l is in [m]
+		// the strength k is in [1/m] for dipoles
+		// ke is the modified field with respect to the eloss
+                //  k = e/p * dB/dx with p = mv (and m = MP)
+                //  k -> ke = k * p/ (p- dp) <- chromacity
+                //  ke -> ke * q_mass/QP <- if not a proton
+                
+        const double p0 = sqrt( (BE-MP)*(BE+MP) );
+        const double E  = BE - eloss;
+        const double p  = sqrt( (E-p_mass)*(E+p_mass) );
+        const float ke = (p_charge==0) ? 0 : k* p0/p  *p_charge/QP;
+
+        if (ke==0) {
+		TMatrix drift(driftmat(l));
+		return drift;
+	}
+	extern bool relative_energy;
+	float r = radius(ke);
+  	float * mat = new float[MDIM*MDIM];
+
+	float simp = 2*r*sin(l/(2*r))*sin(l/(2*r))/BE;
+	float tmat[MDIM*MDIM] =  {cos(l/r),(-1/r)*sin(l/r),0.,0., 0., 0.,
+		                      r*sin(l/r),cos(l/r),0.,0., 0., 0.,
+			                  0.,0.,1.,0., 0., 0.,
+			                  0.,0.,l,1., 0., 0.,
+			                  simp, sin(l/r)/BE, 0., 0., 1., 0.,
+			                  0., 0., 0., 0., 0., 1.
+				           };
+	if(!relative_energy) {
+		tmat[24] = 0;
+		tmat[25] = 0;
+	} 
+
+	for(int i=0;i<MDIM*MDIM;i++) { mat[i] = tmat[i]; }
+	TMatrix TMat(MDIM,MDIM,mat);
+	delete [] mat;
+    return TMat;
+}
+
+extern TMatrix driftmat(const float l) {
+		// the length l is in [m]
+	float * mat = new float[MDIM*MDIM];
+	float tmat[MDIM*MDIM] =  {1.,0.,0.,0.,0.,0.,
+                           l ,1.,0.,0.,0.,0.,
+                           0.,0.,1.,0.,0.,0.,
+                           0.,0.,l ,1.,0.,0.,
+                           0.,0.,0.,0.,1.,0.,
+                           0., 0., 0., 0., 0., 1. 
+	};
+	for(int i=0;i<MDIM*MDIM;i++) { mat[i] = tmat[i]; }
+	TMatrix TMat(MDIM,MDIM,mat);
+	delete [] mat;
+	return TMat;
+}
+
+
+extern TMatrix hkickmat(const float l, const float k, const float eloss =0., const float p_mass=MP, const float p_charge=QP) {
+                // the length l is in [m]
+                // the strength k is in [rad]
+        const double p0 = sqrt( (BE-MP)*(BE+MP) );
+        const double E  = BE - eloss;
+        const double p  = sqrt( (E-p_mass)*(E+p_mass) );
+        const float ke = (p_charge==0) ? 0 : -k* p0/p  *p_charge/QP;
+
+        if (ke==0) {
+		TMatrix drift(driftmat(l));
+		return drift;
+	}
+	float * mat = new float[MDIM*MDIM];
+	float tmat[MDIM*MDIM] =  {1.,0.,0.,0.,0.,0.,
+                           l ,1.,0.,0.,0.,0.,
+                           0.,0.,1.,0.,0.,0.,
+                           0.,0.,l ,1.,0.,0.,
+                           0.,0.,0.,0.,1.,0.,
+                           l*tan(ke)/2.,ke, 0., 0., 0., 1. 
+	};
+
+	for(int i=0;i<MDIM*MDIM;i++) { mat[i] = tmat[i]; }
+	TMatrix TMat(MDIM,MDIM,mat);
+	delete [] mat;
+	return TMat;
+}
+
+extern TMatrix vkickmat(const float l, const float k, const float eloss=0., const float p_mass=MP, const float p_charge=QP) {
+                // the length l is in [m]
+                // the strength k is in [rad]
+        const double p0 = sqrt( (BE-MP)*(BE+MP) );
+        const double E  = BE - eloss;
+        const double p  = sqrt( (E-p_mass)*(E+p_mass) );
+        const float ke = (p_charge==0) ? 0 : -k* p0/p  *p_charge/QP;
+
+        if (ke==0) {
+		TMatrix drift(driftmat(l));
+		return drift;
+	}
+	float * mat = new float[MDIM*MDIM];
+	float tmat[MDIM*MDIM] =  {1.,0.,0.,0.,0.,0.,
+                           l ,1.,0.,0.,0.,0.,
+                           0.,0.,1.,0.,0.,0.,
+                           0.,0.,l ,1.,0.,0.,
+                           0.,0.,0.,0.,1.,0.,
+                           0.,0.,l*tan(ke)/2.,ke, 0., 1. 
+	};
+
+	for(int i=0;i<MDIM*MDIM;i++) { mat[i] = tmat[i]; }
+	TMatrix TMat(MDIM,MDIM,mat);
+	delete [] mat;
+	return TMat;
+}
+
Index: external/Hector/H_TransportMatrices.h
===================================================================
--- external/Hector/H_TransportMatrices.h	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
+++ external/Hector/H_TransportMatrices.h	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
@@ -0,0 +1,219 @@
+#ifndef _H_TransportMatrices_
+#define _H_TransportMatrices_
+
+  /* * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ *                                                         *
+*                   --<--<--  A fast simulator --<--<--     *
+*                 / --<--<--     of particle   --<--<--     *
+*  ----HECTOR----<                                          *
+*                 \ -->-->-- transport through -->-->--     *
+*                   -->-->-- generic beamlines -->-->--     *
+*                                                           *
+* JINST 2:P09005 (2007)                                     *
+*      X Rouby, J de Favereau, K Piotrzkowski (CP3)         *
+*       http://www.fynu.ucl.ac.be/hector.html               *
+*                                                           *
+* Center for Cosmology, Particle Physics and Phenomenology  *
+*              Universite catholique de Louvain             *
+*                 Louvain-la-Neuve, Belgium                 *
+ *                                                         *
+   * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+/** \file H_TransportMatrices.h
+ * \brief Contains the matrices defining the propagation of the beam.
+ * 
+ * The matrices should have the following units :
+ *	\f$
+ *	\mathbf{M} =
+ *	\left(
+ *	\begin{array}{cccccc}
+ *	    1 & 1/m & 1 & 1/m & GeV/m & 1 \\
+ *	    m & 1 & m & 1 & GeV & 1 \\
+ *	    1 & 1/m & 1 & 1/m & GeV/m & 1\\
+ *	    m & 1 & m & 1 & GeV & 1 \\
+ *	  m/GeV & 1/GeV & m/GeV & 1/GeV & 1 & 1\\
+ *	    1 & 1 & 1 & 1 & 1  & 1 \\	
+ *	\end{array}
+ *	\right)
+ *	\f$
+ *
+ *	Note : convention is transposed compared to ref : x0.M = x1
+ * 	instead of x1 = M.x0 so the matrices should be transposed.
+ */
+
+// ROOT #includes
+#include "TMatrix.h"
+using namespace std;
+
+	/// transport matrix dimension
+#define MDIM 6
+
+/// \f$ \omega(k,l) = l \sqrt{|k|} \f$ is needed for the quadrupole matrices
+extern double omega(const double , const double );
+
+/// \f$ r(k) \f$ is needed for the dipole matrices
+extern double radius(const double );
+
+/// Prints the matrix
+extern void printMatrix(TMatrix);
+
+/// \brief Returns the matrix for a vertically focussing quadrupole (H_VerticalQuadrupole)
+
+/*! \f$
+ \mathbf{M} =
+ \left(
+ \begin{array}{cccccc}
+ \cosh(\omega) & \sqrt{k}\sinh(\omega) & 0 & 0 & 0 & 0\\
+ (1/\sqrt{k})sinh(\omega) & \cosh(\omega) & 0 & 0 & 0 &0\\
+ 0 & 0 & \cos(\omega) & -\sqrt{k}sin(\omega) & 0 &0\\
+ 0 & 0 & (1/\sqrt{k})*sin(\omega) & \cos(\omega) & 0 &0\\
+ 0 & 0 & 0 & 0 & 1 &0\\
+ 0 & 0 & 0 & 0 & 0 &1 \\
+ \end{array}
+ \right)
+ \f$
+
+ assuming \f$ k =  k_{0} \times \frac{p_{0}}{p_{0} - dp} \times \frac{q_{particle}}{q_{proton}} \f$ and \f$ \omega(k,l) = l \sqrt{|k|} \f$
+*/
+
+extern TMatrix vquadmat(const float , const float , const float , const float , const float);
+
+/// \brief Returns the matrix for a horizontally focussing quadrupole (H_HorizontalQuadrupole)
+
+/*! \f$
+ \mathbf{M} =
+ \left(
+ \begin{array}{cccccc}
+ \cos(\omega) & -\sqrt{k}\sin(\omega) & 0 & 0 & 0 & 0\\
+ (1/\sqrt{k})sin(\omega) & \cos(\omega) & 0 & 0 & 0 & 0\\
+ 0 & 0 & \cosh(\omega) & \sqrt{k}sinh(\omega) & 0 & 0\\
+ 0 & 0 & (1/\sqrt{k})sinh(\omega) & \cosh(\omega) & 0 & 0\\
+ 0 & 0 & 0 & 0 & 1 & 0\\
+ 0 & 0 & 0 & 0 & 0 & 1 \\
+ \end{array}
+ \right)
+ \f$
+
+ assuming \f$ k =  k_{0} \times \frac{p_{0}}{p_{0} - dp} \times \frac{q_{particle}}{q_{proton}} \f$ and \f$ \omega(k,l) = l \sqrt{|k|} \f$
+*/
+extern TMatrix hquadmat(const float , const float , const float , const float , const float);
+
+/// \brief Returns the matrix for a rectangle dipole (H_RectangularDipole)
+
+/*! \f$
+ \mathbf{M} =
+ \left(
+ \begin{array}{cccccc}
+ \cos(l/r) & \frac{-1}{r} \sin(l/r) & 0 & 0 & 0 & 0\\
+ r \sin(l/r) & \cos(l/r) & 0 & 0 & 0 & 0\\
+ 0 & 0 & 1 & 0 & 0 &0\\
+ 0 & 0 & l & 1 & 0 &0\\
+ 2r \sin^2(l/2r)/BE & \sin(l/r)/BE & 0 & 0 & 1 &0\\
+ 0 & 0 & 0 & 0 & 0 & 1\\
+ \end{array}
+ \right)
+ \f$
+
+ assuming \f$ 1/r = k =  k_{0} \times \frac{p_{0}}{p_{0} - dp} \times \frac{q_{particle}}{q_{proton}} \f$ and \f$ BE = 7000 GeV \f$.
+
+Attention : numerical sensitivity with \f$ r*(1-\cos(l/r))/BE\f$. \\
+Using \f$ 2\sin^2(x/2) = 1-\cos(x)\f$ instead (see the variable called "simp")
+*/
+extern TMatrix rdipmat(const float, const float , const float , const float , const float);
+
+/// \brief Returns the matrix for a sector dipole (H_SectorDipole)
+
+/*! The matrix is different if the bending is on or off.
+ 
+ \f$
+ \mathbf{M_{bending-off}} =
+ \left(
+ \begin{array}{cccccc}
+ \cos(l/r) & \frac{-1}{r} \sin(l/r) & 0 & 0 & 0 & 0\\
+ r \sin(l/r) & \cos(l/r) & 0 & 0 & 0 & 0\\
+ 0 & 0 & 1 & 0 & 0 & 0\\
+ 0 & 0 & l & 1 & 0 & 0\\
+ 0 & 0 & 0 & 0 & 1 & 0\\
+ 0 & 0 & 0 & 0 & 0 & 1\\
+ \end{array}
+ \right)
+ \f$
+
+ \f$
+ \mathbf{M_{bending-on}} =
+ \left( 
+ \begin{array}{cccccc} 
+ \cos(l/r) & \frac{-1}{r} \sin(l/r) & 0 & 0 & 0 & 0\\
+ r \sin(l/r) & \cos(l/r) & 0 & 0 & 0 & 0\\
+ 0 & 0 & 1 & 0 & 0 &0\\ 
+ 0 & 0 & l & 1 & 0 &0\\ 
+ 2r \sin^2(l/2r)/BE & \sin(l/r)/BE & 0 & 0 & 1 & 0\\ 
+ 0 & 0 & 0 & 0 & 0 & 1\\
+ \end{array} 
+ \right) 
+ \f$ 
+ 
+ assuming \f$ 1/r = k =  k_{0} \times \frac{p_{0}}{p_{0} - dp} \times \frac{q_{particle}}{q_{proton}} \f$
+
+*/
+extern TMatrix sdipmat(const float, const float , const float , const float , const float );
+
+/// \brief Returns the matrix for a drift (H_Drift)
+
+/*! \f$
+ \mathbf{M} =
+ \left(
+ \begin{array}{cccccc}
+ 1 & 0 & 0 & 0 & 0 & 0\\
+ l & 1 & 0 & 0 & 0 & 0\\
+ 0 & 0 & 1 & 0 & 0 & 0\\
+ 0 & 0 & l & 1 & 0 & 0\\
+ 0 & 0 & 0 & 0 & 1 & 0\\
+ 0 & 0 & 0 & 0 & 0 & 1\\
+ \end{array}
+ \right)
+ \f$
+*/
+extern TMatrix driftmat(const float );
+
+/// \brief Returns the matrix for a horizontal kicker (H_HorizontalKicker)
+/*! \f$
+ \mathbf{M} =
+ \left(
+ \begin{array}{cccccc}
+ 1 & 0 & 0 & 0 & 0 & 0\\
+ l & 1 & 0 & 0 & 0 & 0 \\
+ 0 & 0 & 1 & 0 & 0 & 0\\
+ 0 & 0 & l & 1 & 0 & 0\\
+ 0 & 0 & 0 & 0 & 1 & 0\\
+ l \tan(k) /2 & k & 0 & 0 & 0 & 1\\
+ \end{array}
+ \right) 
+ \f$
+ 
+ assuming \f$ k =  k_{0} \times \frac{p_{0}}{p_{0} - dp} \times \frac{q_{particle}}{q_{proton}} \f$
+*/
+extern TMatrix hkickmat(const float, const float , const float , const float, const float);
+
+/// \brief Returns the matrix for a vertical kicker (H_VerticalKicker)
+/*! \f$
+ \mathbf{M} =
+ \left(
+ \begin{array}{cccccc}
+ 1 & 0 & 0 & 0 & 0 & 0\\
+ l & 1 & 0 & 0 & 0 & 0 \\
+ 0 & 0 & 1 & 0 & 0 & 0\\
+ 0 & 0 & l & 1 & 0 & 0\\
+ 0 & 0 & 0 & 0 & 1 & 0\\
+ 0 & 0 & l \tan(k) /2 & k & 0 & 1\\
+ \end{array}
+ \right) 
+ \f$
+
+ assuming \f$ k =  k_{0} \times \frac{p_{0}}{p_{0} - dp} \times \frac{q_{particle}}{q_{proton}} \f$
+*/
+extern TMatrix vkickmat(const float, const float , const float , const float , const float);
+
+
+
+#endif
Index: external/Hector/H_VerticalKicker.cc
===================================================================
--- external/Hector/H_VerticalKicker.cc	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
+++ external/Hector/H_VerticalKicker.cc	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
@@ -0,0 +1,50 @@
+  /* * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ *                                                         *
+*                   --<--<--  A fast simulator --<--<--     *
+*                 / --<--<--     of particle   --<--<--     *
+*  ----HECTOR----<                                          *
+*                 \ -->-->-- transport through -->-->--     *
+*                   -->-->-- generic beamlines -->-->--     *
+*                                                           *
+* JINST 2:P09005 (2007)                                     *
+*      X Rouby, J de Favereau, K Piotrzkowski (CP3)         *
+*       http://www.fynu.ucl.ac.be/hector.html               *
+*                                                           *
+* Center for Cosmology, Particle Physics and Phenomenology  *
+*              Universite catholique de Louvain             *
+*                 Louvain-la-Neuve, Belgium                 *
+ *                                                         *
+   * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+/// \file H_VerticalKicker.cc
+/// \brief Classes aiming at simulating vertical kickers in the beamline
+
+// fk [rad] for kickers !!!!
+
+// local #includes
+#include "H_VerticalKicker.h"
+#include "H_TransportMatrices.h"
+
+void H_VerticalKicker::setMatrix(const float eloss, const float p_mass, const float p_charge) {
+	extern int kickers_on;
+	if(kickers_on) {
+		element_mat = vkickmat(element_length,fk,eloss,p_mass,p_charge);
+	} else{
+		element_mat = driftmat(element_length);
+	}
+	return ;
+}
+
+H_VerticalKicker* H_VerticalKicker::clone() const {
+	H_VerticalKicker* temp_kick = new H_VerticalKicker(name,fs,fk,element_length);
+	temp_kick->setAperture(element_aperture);
+	temp_kick->setX(xpos);
+	temp_kick->setY(ypos);
+	temp_kick->setTX(txpos);
+	temp_kick->setTY(typos);
+	temp_kick->setBetaX(betax);
+	temp_kick->setBetaY(betay);
+	return temp_kick;
+}
+
+
Index: external/Hector/H_VerticalKicker.h
===================================================================
--- external/Hector/H_VerticalKicker.h	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
+++ external/Hector/H_VerticalKicker.h	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
@@ -0,0 +1,48 @@
+#ifndef _H_VerticalKicker_
+#define _H_VerticalKicker_
+
+  /* * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ *                                                         *
+*                   --<--<--  A fast simulator --<--<--     *
+*                 / --<--<--     of particle   --<--<--     *
+*  ----HECTOR----<                                          *
+*                 \ -->-->-- transport through -->-->--     *
+*                   -->-->-- generic beamlines -->-->--     *
+*                                                           *
+* JINST 2:P09005 (2007)                                     *
+*      X Rouby, J de Favereau, K Piotrzkowski (CP3)         *
+*       http://www.fynu.ucl.ac.be/hector.html               *
+*                                                           *
+* Center for Cosmology, Particle Physics and Phenomenology  *
+*              Universite catholique de Louvain             *
+*                 Louvain-la-Neuve, Belgium                 *
+ *                                                         *
+   * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+/// \file H_VerticalKicker.h
+/// \brief Classes aiming at simulating vertical kickers in the beamline.
+///
+/// fk [rad] for kickers !!!!
+
+
+// local #includes
+#include "H_Kicker.h"
+
+/// Vertical kickers for the beamline.
+class H_VerticalKicker : public H_Kicker {
+
+	public:
+	/// Constructors and destructor
+	//@{
+		H_VerticalKicker():H_Kicker(VKICKER,0.,0.,0.) {init();}
+		H_VerticalKicker(const double s, const double k, const double l) :H_Kicker(VKICKER,s,k,l){init();}
+		H_VerticalKicker(const string& nameE, const double s, const double k, const double l) :H_Kicker(nameE,VKICKER,s,k,l){init();}
+		~H_VerticalKicker() {};
+	//@}
+		H_VerticalKicker* clone() const ;
+	private:
+		virtual void setTypeString() {typestring=VKICKERNAME;};
+		virtual void setMatrix(const float, const float, const float) ;
+};
+
+#endif
Index: external/Hector/H_VerticalQuadrupole.cc
===================================================================
--- external/Hector/H_VerticalQuadrupole.cc	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
+++ external/Hector/H_VerticalQuadrupole.cc	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
@@ -0,0 +1,45 @@
+  /* * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ *                                                         *
+*                   --<--<--  A fast simulator --<--<--     *
+*                 / --<--<--     of particle   --<--<--     *
+*  ----HECTOR----<                                          *
+*                 \ -->-->-- transport through -->-->--     *
+*                   -->-->-- generic beamlines -->-->--     *
+*                                                           *
+* JINST 2:P09005 (2007)                                     *
+*      X Rouby, J de Favereau, K Piotrzkowski (CP3)         *
+*       http://www.fynu.ucl.ac.be/hector.html               *
+*                                                           *
+* Center for Cosmology, Particle Physics and Phenomenology  *
+*              Universite catholique de Louvain             *
+*                 Louvain-la-Neuve, Belgium                 *
+ *                                                         *
+   * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+/// \file H_VerticalQuadrupole.cc
+/// \brief Vertically focussing quadrupoles
+
+// local #includes
+#include "H_VerticalQuadrupole.h"
+
+void H_VerticalQuadrupole::setMatrix(const float eloss, const float p_mass, const float p_charge) {
+	if (fk<0)  { if(VERBOSE) cout<<"<H_VerticalQuadrupole> ERROR : k1 should be > 0 for H_VerticalQuadrupole (" << name << ")!"<<endl; }
+		if (fk !=0 ) element_mat = vquadmat(element_length,fk,eloss, p_mass,p_charge);
+		else  {
+			element_mat = driftmat(element_length);
+			if(VERBOSE) cout<<"<H_VerticalQuadrupole> WARNING : k1= 0, drift-like quadrupole (" << name << ") !" << endl;
+   		}
+	return ;
+}
+
+H_VerticalQuadrupole* H_VerticalQuadrupole::clone() const {
+	H_VerticalQuadrupole* temp_quad = new H_VerticalQuadrupole(name,fs,fk,element_length);
+	temp_quad->setAperture(element_aperture);
+	temp_quad->setX(xpos);
+	temp_quad->setY(ypos);
+	temp_quad->setTX(txpos);
+	temp_quad->setTY(typos);
+	temp_quad->setBetaX(betax);
+	temp_quad->setBetaY(betay);
+	return temp_quad;
+}
Index: external/Hector/H_VerticalQuadrupole.h
===================================================================
--- external/Hector/H_VerticalQuadrupole.h	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
+++ external/Hector/H_VerticalQuadrupole.h	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
@@ -0,0 +1,46 @@
+#ifndef _H_VerticalQuadrupole_
+#define _H_VerticalQuadrupole_
+
+  /* * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ *                                                         *
+*                   --<--<--  A fast simulator --<--<--     *
+*                 / --<--<--     of particle   --<--<--     *
+*  ----HECTOR----<                                          *
+*                 \ -->-->-- transport through -->-->--     *
+*                   -->-->-- generic beamlines -->-->--     *
+*                                                           *
+* JINST 2:P09005 (2007)                                     *
+*      X Rouby, J de Favereau, K Piotrzkowski (CP3)         *
+*       http://www.fynu.ucl.ac.be/hector.html               *
+*                                                           *
+* Center for Cosmology, Particle Physics and Phenomenology  *
+*              Universite catholique de Louvain             *
+*                 Louvain-la-Neuve, Belgium                 *
+ *                                                         *
+   * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+
+/// \file H_VerticalQuadrupole.h
+/// \brief Vertically focussing quadrupoles.
+
+// local #includes
+#include "H_Quadrupole.h"
+
+/// Vertically focussing quadrupoles.
+class H_VerticalQuadrupole : public H_Quadrupole {
+
+	public:
+	///     Constructors and destructor
+	//@{
+		H_VerticalQuadrupole():H_Quadrupole(VQUADRUPOLE,0.,0.,0.) {init();}
+		H_VerticalQuadrupole(const double s, const double k, const double l):H_Quadrupole(VQUADRUPOLE,s,k,l) {init();}
+		H_VerticalQuadrupole(const string& nameE, const double s, const double k, const double l):H_Quadrupole(nameE,VQUADRUPOLE,s,k,l) {init();}
+	~H_VerticalQuadrupole() {};
+//@}
+	H_VerticalQuadrupole* clone() const ;
+private:
+		virtual void setTypeString() {typestring = VQUADRUPOLENAME;} ;
+		virtual void setMatrix(const float, const float, const float) ;
+};
+
+#endif
Index: external/Hector/VERSION
===================================================================
--- external/Hector/VERSION	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
+++ external/Hector/VERSION	(revision 5b822e567e81b047f743b282d78eaae9b7c4fb20)
@@ -0,0 +1,1 @@
+_1_5_2
