Exemple #1
0
//_____________________________________________________________________________
void THaSpectrometer::LabToTransport( const TVector3& vertex, 
				      const TVector3& pvect,
				      TVector3& tvertex, Double_t* ray ) const
{
  // Convert lab coordinates to TRANSPORT coordinates in the spectrometer
  // coordinate system.
  // Inputs:
  //  vertex:  Reaction point in lab system
  //  pvect:   Momentum vector in lab
  // Outputs:
  //  tvertex: The vertex point in the TRANSPORT system, without any
  //           coordinate projections applied
  //  ray:     The TRANSPORT ray according to TRANSPORT conventions.
  //           This is an array of size 6 with elements x, tan(theta),
  //           y, tan(y), z, and delta.
  //           z is set to 0, and accordingly x and y are the TRANSPORT 
  //           coordinates in the z=0 plane. delta is computed with respect 
  //           to the present spectrometer's central momentum.
  //           Units are the same as of the input vectors.

  tvertex = fToTraRot * ( vertex - fPointingOffset );
  TVector3 pt = fToTraRot * pvect;
  if( pt.Z() != 0.0 ) {
    ray[1] = pt.X() / pt.Z();
    ray[3] = pt.Y() / pt.Z();
    // In the "ray", project the vertex to z=0
    ray[0] = tvertex.X() - tvertex.Z() * ray[1];
    ray[2] = tvertex.Y() - tvertex.Z() * ray[3];
  } else
    ray[0] = ray[1] = ray[2] = ray[3] = 0.0;
  
  ray[4] = 0.0;   // By definition for this ray, TRANSPORT z=0
  ray[5] = pt.Mag() / fPcentral - 1.0;
}
/*Given the impact point on the front face (vin) and the incoming particle LorentzVector (chi for invisible decay, A' for visible),
 *  determine the interaction point within the fiducial volume and save it in vhit.
 Use a random distribution along the chi flight path, with uniform probability
 This function returns the length (in m) of the trajectory within the fiducial volume.
 Displacement is the lateral displacement (in m) of the detector, along x
 */
double KinUtils::findInteractionPoint(const TLorentzVector &chi, const TVector3 &fiducialV, const TVector3 &vin, TVector3 &vout, TVector3 &vhit) {

	double tz, tx, ty, tout, L;
	int sigPx, sigPy;

	sigPx = (chi.Px() > 0 ? 1 : -1);
	sigPy = (chi.Py() > 0 ? 1 : -1);

	tz = fiducialV.Z() / chi.Pz();
	tx = (sigPx * fiducialV.X() / 2 - vin.X()) / chi.Px();
	ty = (sigPy * fiducialV.Y() / 2 - vin.Y()) / chi.Py();
	tout = 0;

	if ((tz < tx) && (tz < ty)) {
		tout = tz;
	} else if ((tx < ty) && (tx < tz)) {
		tout = tx;
	} else if ((ty < tx) && (ty < tz)) {
		tout = ty;
	}
	vout.SetXYZ(tout * chi.Px() + vin.X(), tout * chi.Py() + vin.Y(), tout * chi.Pz() + vin.Z());
	vhit.SetXYZ(Rand.Uniform(vin.X(), vout.X()), Rand.Uniform(vin.Y(), vout.Y()), Rand.Uniform(vin.Z(), vout.Z()));
	L = (vout - vin).Mag();

	return L;
}
Exemple #3
0
	  void qaVtxDiff(TString pre="", RhoCandidate * c, RhoTuple * n){

		  if(n==0) return;
		  if(c==0) return;

		  RhoCandidate * mct = c->GetMcTruth();

		  if(mct){
			  TVector3 v = c->DecayVtx();
			  TVector3 mcv = mct->Daughter(0)->Pos();
			  TVector3 vdiff = v-mcv;
			  TMatrixD cov7 = c->Cov7();

			  n->Column(pre + "diffvx", (Float_t) vdiff.X(), 0.0f );
			  n->Column(pre + "diffvy", (Float_t) vdiff.Y(), 0.0f );
			  n->Column(pre + "diffvz", (Float_t) vdiff.Z(), 0.0f );

			  n->Column(pre + "pullvx", (Float_t) (vdiff.X()/TMath::Sqrt(cov7(0,0))), 0.0f);
			  n->Column(pre + "pullvy", (Float_t) (vdiff.Y()/TMath::Sqrt(cov7(1,1))), 0.0f);
			  n->Column(pre + "pullvz", (Float_t) (vdiff.Z()/TMath::Sqrt(cov7(2,2))), 0.0f);

		  }
		  else{
			  n->Column(pre + "diffvx", (Float_t) -999.0, 0.0f );
			  n->Column(pre + "diffvy", (Float_t) -999.0, 0.0f );
			  n->Column(pre + "diffvz", (Float_t) -999.0, 0.0f );

			  n->Column(pre + "pullvx", (Float_t) -999.0, 0.0f);
			  n->Column(pre + "pullvy", (Float_t) -999.0, 0.0f);
			  n->Column(pre + "pullvz", (Float_t) -999.0, 0.0f);

		  }
	  }
Exemple #4
0
void THisHandler::FillHists()
{
   fTree->SetBranchStatus("*", 0);

   TVector3 position;
   fTree->SetBranchStatus("x", 1);
   fTree->SetBranchStatus("y", 1);
   fTree->SetBranchStatus("z", 1);
   fTree->SetBranchAddress("x", &position[0]);
   fTree->SetBranchAddress("y", &position[1]);
   fTree->SetBranchAddress("z", &position[2]);
   
   Char_t volumeName[256]; // Array size is enough?
   fTree->SetBranchStatus("VolumeName", 1);
   fTree->SetBranchAddress("VolumeName", volumeName);

   Double_t ene;
   fTree->SetBranchStatus("DepositEnergy", 1);
   fTree->SetBranchAddress("DepositEnergy", &ene);

   const Int_t kEntries = fTree->GetEntries();
   for(Int_t iEntry = 0; iEntry < kEntries; iEntry++){
      //if(iEntry%100000 == 0) cout << iEntry <<" / "<< kEntries << endl;
      fTree->GetEntry(iEntry);
      if(!(ene > 0.)) continue;
      
      fHisAll->Fill(position.X(), position.Y(), position.Z(), ene);

      if(TString(volumeName) == "Sealing")
         fHisSealing->Fill(position.X(), position.Y(), position.Z(), ene);
      else if(TString(volumeName) == "Window")
         fHisWindow->Fill(position.X(), position.Y(), position.Z(), ene);
      else if(TString(volumeName) == "Foil")
         fHisFoil->Fill(position.X(), position.Y(), position.Z(), ene);
      else if(TString(volumeName) == "Holder")
         fHisHolder->Fill(position.X(), position.Y(), position.Z(), ene);
      else if(TString(volumeName) == "Cassette")
         fHisCassette->Fill(position.X(), position.Y(), position.Z(), ene);
      else if(TString(volumeName) == "Air")
         fHisAir->Fill(position.X(), position.Y(), position.Z(), ene);
      else if(TString(volumeName) == "Plate" ||
              TString(volumeName) == "Well" ||
              TString(volumeName) == "Outer")
         fHisPlate->Fill(position.X(), position.Y(), position.Z(), ene);
      else if(TString(volumeName) == "Film")
         fHisFilm->Fill(position.X(), position.Y(), position.Z(), ene);
      else if(TString(volumeName) == "Stuff")
         fHisWell->Fill(position.X(), position.Y(), position.Z(), ene);

      else if(TString(volumeName) == "Cell"){
         Int_t wellID = XYtoIndex(position.X(), position.Y());
         fHisEachCell20[wellID]->Fill(position.X(), position.Y(), ene);
         fHisEachCell50[wellID]->Fill(position.X(), position.Y(), ene);
      }

   }

}
Exemple #5
0
int getSurfacePoint(TVector3 intPos, TVector3 &intDir, TVector3 &surfPos) {
    Double_t b=intDir.X()*intPos.X() + intDir.Y()*intPos.Y() + intDir.Z()*intPos.Z();
    Double_t c = intPos.X()*intPos.X() + intPos.Y()*intPos.Y() + intPos.Z()*intPos.Z() - rEarth*rEarth;
    if(b*b < c)
        return 0;


    Double_t l1=-1*b + TMath::Sqrt(b*b - c);
    Double_t l2=-1*b - TMath::Sqrt(b*b - c);


    if(intPos.Mag2()> rEarth*rEarth) {
        //Start outside take l1
        //return 0;
        //    cout << "Outside:\t" << l1 << "\t" << l2 << endl;
        intDir*=-1;
        l1*=-1;
        surfPos.SetX(intPos.X() + l1*intDir.X());
        surfPos.SetY(intPos.Y() + l1*intDir.Y());
        surfPos.SetZ(intPos.Z() + l1*intDir.Z());
        //    cout << surfPos.Mag() << endl;
    }
    else {
        //Start inside take l2
        //    cout << "Inside:\t" << l1 << "\t" << l2 <<  endl;
        //    cout << l2 << endl;
        //    return 0;
        surfPos.SetX(intPos.X() + l2*intDir.X());
        surfPos.SetY(intPos.Y() + l2*intDir.Y());
        surfPos.SetZ(intPos.Z() + l2*intDir.Z());
        //    cout << surfPos.Mag() << endl;
    }

    return 1;
}
Exemple #6
0
  static TVector3 toLocal(const TVector3 &global){

    TVector3 local = global;

    if(TMath::Abs(global.Z()) < EC_DIV){ //CC
      local.SetX(local.X()-CC_XSHIFT);
      local.SetY(local.Y()-CC_YSHIFT);
      local.SetZ(local.Z()-CC_ZSHIFT);
    }else{
      if (global.Z() < 0) local.SetX(local.X()-EC_XSHIFT_NORTH);
      local.SetZ( (global.Z()>0) ? EC_3Z : -EC_3Z );
    }

    return local;
  }
Exemple #7
0
  static TVector3 toGlobal(const TVector3 &local){

    TVector3 global = local;

    if(TMath::Abs(local.Z()) < EC_DIV){ //CC
      global.SetX(global.X()+CC_XSHIFT);
      global.SetY(global.Y()+CC_YSHIFT);
      global.SetZ(global.Z()+CC_ZSHIFT);
    }else{
      if (local.Z() < 0) global.SetX(local.X()+EC_XSHIFT_NORTH);
      global.SetZ( (local.Z()>0) ? EC_3Z_SOUTH : EC_3Z_NORTH );
    }

    return global;
  }
Exemple #8
0
double coeff_of_t(TVector3 &efield, TVector3 &vel, int dir)
{
  //returns A C(t), the coefficient of each waveguide mode in +x-direction
  // in units of C*Ohm/s or volts
  efield.SetZ( dir * efield.Z() );//only effect TM modes
  return Echarge * tl_data.Zw / 2 * ( efield * vel ) / US2S;
}
vector<TParticle*> LMCphysGen::GenCerPhotons(TParticle *part, LMCstep *step, Int_t N) {

  const Double_t hbarc = 0.197326960277E-6; //GeV.nm 
  vector <TParticle*> v;
  //rotation matrix to transform vectors from geom -> part
  TRotation rm;
  TVector3 vt(part->Px(), part->Py(), part->Pz());
  rm.RotateX(vt.Theta()); //rotate on X
  rm.RotateZ(vt.Phi()); //rotate on Z
  TVector3 pdir = vt.Unit();
  // rotation matrix from part->geom
  TRotation im = rm.Inverse();
  //generate photons
  Double_t Emin = 2.*TMath::Pi()* hbarc / 200.; //GeV
  Double_t Emax = 2.*TMath::Pi()* hbarc / 700.; //GeV

  TVector3 InitPoint = step->GetInitPoint(); 
  Double_t stepLength = step->GetStepLength();
  for (int i=0; i< N; i++) {
    Double_t thetaCer = step->GetCerAngle();
    Double_t phi = (RandGen->Rndm())*2.*TMath::Pi();  
    TVector3 photonDir(sin(thetaCer)*cos(phi), sin(thetaCer)*sin(phi), cos(thetaCer));
    TVector3 photonDirDet = im*photonDir;                         //transform photon direction from particle to detector frame
    Double_t photonE      = Emin + (RandGen->Rndm())*(Emax-Emin); //cerenkov photon flat on energy (GeV)
    TVector3 photonMomDet = photonE*photonDirDet;                 //on detector frame
    TVector3 GenPoint     = InitPoint + stepLength*(RandGen->Rndm())*pdir;
    v.push_back(new TParticle(22,0,0,0,0,0,photonMomDet.X(),photonMomDet.Y(),photonMomDet.Z(),photonE,GenPoint.X(),GenPoint.Y(),GenPoint.Z(),0));
  }

  return v;

}
Exemple #10
0
Path::Path(const TLorentzVector& p4, const TVector3& origin, double field)
    : m_unitDirection(p4.Vect().Unit()),
      m_speed(p4.Beta() * gconstc),
      m_origin(origin.X(), origin.Y(), origin.Z()),
      m_field(field) {
  m_points[papas::Position::kVertex] = m_origin;
}
Exemple #11
0
  static TVector3 floorXYZ(double zvtx, double physeta, double physphi) {
    // Function to calculate detector position when particle is extrapolated
    // to 3rd layer of em calorimeter.

    // Note that we assume an x,y vertex position of zero.
    // Also, the x,y cal shifts are not implemented...yet.

    TVector3 v;
    
    double phi = physphi;  
    double eta = physeta;
    double theta = PTools::etaToTheta(eta);
    double ztmp = zvtx + CC_3R/TMath::Tan(theta);
    
    if( TMath::Abs(ztmp) >= EC_DIV ){ // in EC
      (eta>=0) ? v.SetZ(EC_3Z_SOUTH) : v.SetZ(EC_3Z_NORTH);
      v.SetX( (v.Z()-zvtx) * TMath::Tan(theta) * TMath::Cos(phi));
      v.SetY( (v.Z()-zvtx) * TMath::Tan(theta) * TMath::Sin(phi));
      
    }
    else{ // in CC
      v.SetZ(ztmp);
      v.SetX( CC_3R * TMath::Cos(phi));
      v.SetY( CC_3R * TMath::Sin(phi));
      
    }
    
    return v;
  }
Exemple #12
0
void KVParticle::SetFrame(const Char_t* frame, const TVector3& boost,
                          Bool_t beta)
{
   //Define a Lorentz-boosted frame in which to calculate the particle's momentum and energy.
   //
   //The new frame will have the name given in the string "frame", which can then be used to
   //access the kinematics of the particle in different frames using GetFrame().
   //
   //The boost velocity vector is that of the boosted frame with respect to the original frame of the particles in the event.
   //The velocity vector can be given either in cm/ns units (default) or in units of 'c' (beta=kTRUE).
   //
   //E.g. to define a frame moving at 0.1c in the +ve z-direction with respect to the original
   //event frame:
   //
   //      (...supposing a valid pointer KVParticle* my_part...)
   //      TVector3 vframe(0,0,0.1);
   //      my_part->SetFrame("my_frame", vframe, kTRUE);
   //
   //In order to access the kinematics of the particle in the new frame:
   //
   //      my_part->GetFrame("my_frame")->GetTransverseEnergy();// transverse energy in "my_frame"

   //set up TLorentzRotation corresponding to boosted frame
   TLorentzRotation tmp;
   if (beta) {
      tmp.Boost(boost);
   } else {
      tmp.Boost(boost.X() / kSpeedOfLight, boost.Y() / kSpeedOfLight,
                boost.Z() / kSpeedOfLight);
   }
   SetFrame(frame, tmp);
}
Exemple #13
0
void drawFocalPlane(TString infile="../build/hits.root", Double_t r1 = 48.8, Double_t r2 = 29.1, Int_t it1=0, Int_t it2=0, Double_t energy=3){
  gSystem->Load("../build/libprtdirclib.so");
  PrtInit(infile,0);
  gStyle->SetOptStat(0);

  Double_t radiatorL(1250); //bar
  // Double_t radiatorL(1224.9); //plate
  TVector3 res;
  TH2F *hFp1 = new TH2F("hFp1",Form("r_{1}=%2.2f    r_{2}=%2.2f;x, [cm];y, [cm]",r1,r2),500,0,50,500,0,30 );
  TH2F *hFp2 = new TH2F("hFp2",Form("r_{1}=%2.2f    r_{2}=%2.2f;z, [cm];y, [cm]",r1,r2),500,-30,30,500,-30,50 );

  PrtHit hit[2];
  Int_t nevents = fCh->GetEntries();
  Int_t count(0);
  for (Int_t ievent=0; ievent<nevents; ievent++){
    PrtNextEvent(ievent,1000);
    Int_t nhits = prt_event->GetHitSize(); //fEvent->GetHitSize();
    if(nhits!=2) continue;
    for(Int_t h=0; h<nhits; h++) hit[h] = prt_event->GetHit(h); //fEvent->GetHit(h);
    Double_t d = findVertex(hit[0].GetGlobalPos(),hit[0].GetMomentum().Unit(),hit[1].GetGlobalPos(),hit[1].GetMomentum().Unit(), &res);
    if(d<1){
      Double_t x = -(res.X()+radiatorL/2.)/10.;
      if(x>6){
	hFp1->Fill(x,res.Z()/10.);
	hFp2->Fill(res.Y()/10.,res.Z()/10.);
      }
      count++;
    }
  } 
  Double_t eff = 100*count/(Double_t)nevents;

  TString senergy = "";
    if(energy>-1){
      Double_t m = 1, cm = 0.01, nanometer = 0.000000001, GeV = 1000000000;
      Double_t LambdaE = 2.0 * 3.14159265358979323846 * 1.973269602e-16 * m * GeV;
      Double_t lam = LambdaE/(energy*nanometer);

      senergy = Form("   E=%2.2f [eV] / #lambda=%2.0f [nm]",energy,lam);
    }
  hFp1->SetTitle(Form("r_{1}=%2.2f    r_{2}=%2.2f   #varepsilon=%2.0f",r1,r2,eff)+senergy);
  canvasAdd(Form("fp_%d_%d",it1,it2),800,500);
  hFp1->Draw("colz");
  canvasAdd(Form("fp2_%d_%d",it1,it2),600,800);
  hFp2->Draw("colz");
  //canvasSave(0,"drawFocalPlane.C",1,"fp");
  
}
Exemple #14
0
  static Bool_t is_in_eta_fiducial(const TVector3 &pos) {
    // converted from emid::is_in_eta_fiducial

    // NOTE: this routine assumes pos is in local coordinates!
    //convert pos to local coordinate system
    //TVector3 v = toLocal(pos);

    // cryostat edges
    bool is_at_edge;
    if (TMath::Abs(pos.Z())>150.) {
      is_at_edge=pos.Perp()>EC_R_MAX;
    } else {
      is_at_edge=fabs(pos.Z())>CC_Z_MAX;
    }
    return (!is_at_edge);
    
  }
Exemple #15
0
void KVParticle::SetFrame(const Char_t* frame, const TVector3& boost,
                          TRotation& rot, Bool_t beta)
{
   //Define a Lorentz-boosted and rotated frame in which to calculate the particle's momentum and energy.
   //
   //The new frame will have the name given in the string "frame", which can then be used to
   //access the kinematics of the particle in different frames using GetFrame().
   //
   //E.g. if you want to define a new frame whose coordinate axes are rotated with respect
   //to the original axes, you can set up a TRotation like so:
   //
   //      TRotation rot;
   //      TVector3 newX, newY, newZ; // the new coordinate axes
   //      rot.RotateAxes(newX, newY, newZ);
   //
   //If you are using one of the two global variables which calculate the event tensor
   //(KVTensP and KVTensPCM) you can obtain the transformation to the tensor frame
   //using:
   //
   //      TRotation rot;
   //      KVTensP* tens_gv;// pointer to tensor global variable
   //      tens_gv->GetTensor()->GetRotation(rot);// see KVTenseur3::GetRotation
   //
   //N.B. you do not need to invert the transformation matrix (cf. TRotation), this is handled by
   //SetFrame(const Char_t* frame, TLorentzRotation& rot)
   //
   //The boost velocity vector is that of the boosted frame with respect to the original frame of the particles in the event.
   //The velocity vector can be given either in cm/ns units (default) or in units of 'c' (beta=kTRUE).
   //
   //E.g. to define a frame moving at 0.1c in the +ve z-direction with respect to the original
   //event frame:
   //
   //      (...supposing a valid pointer KVParticle* my_part...)
   //      TVector3 vframe(0,0,0.1);
   //      my_part->SetFrame("my_frame", vframe, kTRUE);
   //
   //In order to access the kinematics of the particle in the new frame:
   //
   //      my_part->GetFrame("my_frame")->GetTransverseEnergy();// transverse energy in "my_frame"

   //set up corresponding TLorentzRotation
   TLorentzRotation tmp(rot);
   if (beta) {
      tmp.Boost(boost);
   } else {
      tmp.Boost(boost.X() / kSpeedOfLight, boost.Y() / kSpeedOfLight,
                boost.Z() / kSpeedOfLight);
   }
   SetFrame(frame, tmp);
}
Exemple #16
0
//_________________________________________________________________
Double_t KVTenseur3::GetPhiPlan(void)
{
   // Obtention du Phi du plan de reaction (en degrès).
   // Cet angle suit les conventions de KaliVeda i.e. il est entre 0 et 360 degrees
   if (is_diago == 0)
      Diago();

   TVector3 vp = GetVep(3);

   if (vp.Z() < 0)
      vp = -vp;
   Double_t phi = vp.Phi() * TMath::RadToDeg();
   return (phi < 0 ? 360. + phi : phi);
}
Exemple #17
0
  static Bool_t is_in_phi_fiducial(const TVector3 &v) {
    // converted from emid::is_in_phi_fiducial
    
    const double PHI_CRACK_WIDTH=0.02; 
    
    double phi = v.Phi()>=0 ? v.Phi() : (v.Phi()+TMath::TwoPi()); 
    
    // CC phi cracks
    Bool_t outside_phi_crack=true;
    if (TMath::Abs(v.Z()) < 150.) {
      double phimod=fmod(phi+0.1,TMath::Pi()/16.);
      outside_phi_crack=(phimod<0.1-PHI_CRACK_WIDTH) || 
	(phimod>0.1+PHI_CRACK_WIDTH);
    }
    return outside_phi_crack;
  }
Exemple #18
0
//_________________________________________________________________
Double_t KVTenseur3::GetThetaFlot(void)
{
//
// Obtention du Theta Flot (en degrès). NB. valeur entre 0 et +90 deg.
//
   Double_t tf;

   if (is_diago == 0)
      Diago();

   TVector3 vp = GetVep(3);

   if (vp.Z() < 0)
      vp = -vp;
   tf = vp.Theta() * 180. / TMath::Pi();
   return tf;
}
void esd_kink_fill_pointset(TEvePointSet* ps)
{
  IlcESDEvent* esd = IlcEveEventManager::AssertESD();

  for (Int_t n=0; n<esd->GetNumberOfTracks(); ++n)
  { 
      IlcESDtrack* track = esd->GetTrack(n);
      if(track->GetKinkIndex(0)<0){
    
          IlcESDkink *kink = esd->GetKink(TMath::Abs(track->GetKinkIndex(0))-1);
	  const TVector3 Position(kink->GetPosition());
	  ps->SetNextPoint(Position.X(), Position.Y(), Position.Z());
          ps->SetPointId(kink);
      }
  }

}
Exemple #20
0
int main(int argc, char* argv[]){
   
   
   

   SuperTree<int> supertree;
   
   supertree.AddParentChild(1,2);
   supertree.AddParentChild(1,3);
    supertree.AddParentChild(2,4);
   supertree.AddParentChild(3,5);
    supertree.AddParentChild(3,6);
  B b;
    b.foo();
   
   // all new
   TApplication theApp("App", &argc, argv);
   if (gROOT->IsBatch()) {
      fprintf(stderr, "%s: cannot run in batch mode\n", argv[0]);
      return 1;
   }
   //testing();
   //theApp.Run();
   
   
   
    std::cout << "Try base classes\n";
    
    Material M("test",1,1);
    SurfaceCylinder S("empty");
    VolumeCylinder V("new", 4, 6, 3, 6);
    
    CMS CMSDetector;
    TLorentzVector tlv(1.,1. , 1., .7);
    Particle ppp(22,.5,tlv,1);
    
    std::cout<<ppp.StringDescription()<<"\n";
    
   
   //dispay tests
   
   
  
   Proj A=Proj::xy;
   cout<<A;
   cout<<to_str(A);
   
   
   
   
   TLorentzVector p4 = TLorentzVector();
   p4.SetPtEtaPhiM(1, 0, 0, 5.11e-4);
   //std::shared_ptr<TVector3> tvect = std::shared_ptr<TVector3>{new TVector3(0,0,0)};
   //Helix helix(3.8, 1, p4,tvect );
   Helix helix(3.8, 1, p4,TVector3(0,0,0));
   double length = helix.getPathLength(1.0e-9);
   
   
   TVector3 junk = helix.getPointAtTime(1e-9);
   std::cout<<"HElix point: " <<junk.X() << " " << junk.Y() << " " << junk.Z()<<" ";
   std::cout<< "\nlength"<<length<< " " << helix.getDeltaT(length)<<std::endl;
   
       // test from pfobjects
   
    TVector3 vpos(1.,.5,.3);
    Cluster cluster=  Cluster(10., vpos, 1., "ecaltest");
    std::cout <<"cluster "<< cluster.getPt()<<"\n";
    
    //cluster.setEnergy(5.);
    //std::cout << cluster.getPt()<<"\n";
    
    Simulator sim{CMSDetector};
    //SimParticle photon(22,  M_PI/2., M_PI/2.+0.0, 10.);
    
    //ptc = pfsimparticle()
    TLorentzVector tlvphoton=MakeParticleLorentzVector(22,  M_PI/2., M_PI/2.+0.0, 10.);
    SimParticle photon(22, tlvphoton);
     sim.simulatePhoton(photon);
   
   
   std::vector<TVector3> tvec;
   tvec.push_back(TVector3(0.,0.,0.));
   tvec.push_back(TVector3(1.,1.,1.));
   tvec.push_back(TVector3(2.,2.,2.));
   
   
   Display display = Display({Projection::xy,Projection::yz});
   //Display display = Display({Projection::xy,Projection::yz,Projection::ECAL_thetaphi ,Projection::HCAL_thetaphi });
   
   std::shared_ptr<GDetector> gdetector (new GDetector(CMSDetector));
   
   display.Register(gdetector, 0);

   std::shared_ptr<GTrajectories> gtrajectories (new GTrajectories(tvec)) ;// simulator.ptcs)
   std::shared_ptr<GTrajectories> gcluster (new GTrajectories(cluster)) ;
   display.Register(gtrajectories,1);
   display.Register(gcluster,2);
   display.Draw();
   

   
  return EXIT_SUCCESS;
}
Exemple #21
0
void algo_test() {
  
  // Vector A starts at (0.0,0.5,0.5) and points along (1,1,1) (too simple ?)
  // Vector B starts at (2,1,1) and points along (0.5, 0.5, 4)
  TVector3 dir_a(1.0,1.0,1.0);  // (1.0,1.0,1.0)
  TVector3 dir_b(0.5, 0.5, 4.0); // (0.5, 0.5, 4.0) 

  TVector3 unit_a = dir_a.Unit();
  TVector3 unit_b = dir_b.Unit();

  // check for parallel vectors and bow out if they are
  TVector3 cross = unit_a.Cross(unit_b);
  // account for floats
  if (cross.Mag() < 0.01)  {
    cout << "These vectors seem to be parallel, there won't be a vertex !" << endl; 
    exit(0);
  }


  TVector3 start_a(0.0, 0.5, 0.5);  
  TVector3 start_b(2.0, 1.0, 1.0); 
  TVector3 start_diff = start_a - start_b;

  float ta = ( -(start_diff*unit_a) + (start_diff *  unit_b) * (unit_a * unit_b) )/ 
    ( 1.0 - ( (unit_a * unit_b) *  (unit_a * unit_b)) );
  float tb =   ( (start_diff*unit_b) - (start_diff *  unit_a) * (unit_a * unit_b) )/ 
    ( 1.0 - ( (unit_a * unit_b) *  (unit_a * unit_b)) );

  TVector3 close_a = start_a + (ta *  unit_a);
  TVector3 close_b = start_b + (tb * unit_b);
  
  // now what I really want to store as a vertex is the middle of the Vector going from close_a to close_b
  

  cout << "Closest point on Vector A = " << close_a.X() << ", " << close_a.Y() << " ," << close_a.Z() << endl;
  cout << "Closest point on Vector B = " << close_b.X() << ", " << close_b.Y() << " ," << close_b.Z() << endl;

  TVector3 from_a_to_b = close_b - close_a;
  // conceptually that's more of a point than a vector
  TVector3 vertex = close_a + 0.5 * from_a_to_b;
  cout << "The vertex is here:  " << vertex.X() << ", " <<  vertex.Y() << ", " <<  vertex.Z() << endl;

  // now try this with the find_vertex function
  line_vec line_a(start_a, start_a+dir_a);
  line_vec line_b(start_b, start_b+dir_b);
  
  TVector3 vertex_again = find_vertex(line_a, line_b);
  

  // test the clustering algorithm
  TVector3 vec_a(1.0, 1.0, 1.0);
  TVector3 vec_b(2.0, 2.0, 2.0);
  TVector3 vec_c(3.0, 3.0, 3.0);
  TVector3 vec_a1(1.1, 1.0, 1.0);
  TVector3 vec_b1(2.1, 2.0, 2.0);
  TVector3 vec_c1(3.1, 3.0, 3.0);
  TVector3 vec_a2(1.1, 1.2, 1.0);
  TVector3 vec_b2(2.1, 2.2, 2.0);
  TVector3 vec_c2(3.1, 3.0, 3.2);
  TVector3 vec_a3(3.1, 1.2, 1.0);
  TVector3 vec_b3(3.1, 2.3, 2.0);
  TVector3 vec_c3(3.4, 3.4, 3.4);
  TVector3 vec_a4(2.1, 2.2, 2.0);
  TVector3 vec_b4(2.1, 2.3, 2.0);
  TVector3 vec_c4(2.4, 2.4, 2.4);

  vector<TVector3> points;
  points.push_back(vec_a);  points.push_back(vec_b);  points.push_back(vec_c);
  points.push_back(vec_a1);  points.push_back(vec_b1);  points.push_back(vec_c1);
  points.push_back(vec_a2);  points.push_back(vec_b2);  points.push_back(vec_c2);
  points.push_back(vec_a3);  points.push_back(vec_b3);  points.push_back(vec_c3);
  points.push_back(vec_a4);  points.push_back(vec_b4);  points.push_back(vec_c4);

  vector<TVector3> good_points = find_cluster(points, 1.0);
  cout << good_points.size() << endl;
  TVector3 vertex_av = vertex_ave(good_points);
  cout << "Cluster average: " << vertex_av.X() << " " << vertex_av.Y() << " " << vertex_av.Z() << endl; 


  vector<TVector3> test_ave;
  test_ave.push_back(vec_a);
  test_ave.push_back(vec_b);
  test_ave.push_back(vec_c);
  TVector3 av = vertex_ave(test_ave);
  cout << "vertex_ave test: " <<  av.X() << " " << av.Y() << " " << av.Z() << endl; 


  // Line defined by two points - how far is the third point away ?
  TVector3 point_one(1.0, 1.0, 1.0);
  TVector3 point_two(2.0, 1.0, 1.0);
  TVector3 point_three(1.5, 1.5, 1.0);
  TVector3 point_four(1.5, 1.0, 1.0);
  TVector3 point_five(3.0, 1.7, 1.0);
  // thanks to Wolfram Alpha
  // line is x1, x2, point is x0
  // x = cross prduct
  // d = |(x2 - x1) x (x1 - x0)| / | x2-x1 |

  Float_t d1 =  ((point_two - point_one).Cross(point_one - point_three)).Mag() /
    (point_two - point_one).Mag();
  cout << "d1: " << d1 << endl;
  Float_t d2 =  ((point_two - point_one).Cross(point_one - point_four)).Mag() /
      (point_two - point_one).Mag();
  cout << "d2: " << d2 << endl;
  Float_t d3 =  ((point_two - point_one).Cross(point_one - point_five)).Mag() /
    (point_two - point_one).Mag();
  cout << "d3: " << d3 << endl;


}
Exemple #22
0
TVector3 find_vertex(line_vec track_a, line_vec track_b) {
  
  TVector3 start_diff = track_a.start() - track_b.start();
  TVector3 unit_a = track_a.dir_unit();
  TVector3 unit_b = track_b.dir_unit();

  float ta = ( -(start_diff*unit_a) + (start_diff *  unit_b) * (unit_a * unit_b) )/ 
    ( 1.0 - ( (unit_a * unit_b) *  (unit_a * unit_b)) );
  float tb =   ( (start_diff*unit_b) - (start_diff *  unit_a) * (unit_a * unit_b) )/ 
    ( 1.0 - ( (unit_a * unit_b) *  (unit_a * unit_b)) );

  TVector3 close_a = track_a.start()  + (ta *  unit_a);
  TVector3 close_b = track_b.start()  + (tb * unit_b);
  
  // now what I really want to store as a vertex is the middle of the Vector going from close_a to close_b
  
  cout << "find_vertex::Closest point on Vector A = " << close_a.X() << ", " << close_a.Y() << " ," << close_a.Z() << endl;
  cout << "find_vertex::Closest point on Vector B = " << close_b.X() << ", " << close_b.Y() << " ," << close_b.Z() << endl;

  TVector3 from_a_to_b = close_b - close_a;
  // conceptually that's more of a point than a vector
  TVector3 vertex = close_a + 0.5 * from_a_to_b;
  cout << "find_vertex::The vertex is here:  " << vertex.X() << ", " <<  vertex.Y() << ", " <<  vertex.Z() << endl;

  return vertex;
}
vector <double> NonCollisionBG::outerIntersectionTs(const TVector3& X, const TVector3& P, double timeDCA){
  // get limits of t inside which the outer intersection solutions must exist
  double x0 = X.X();
  double y0 = X.Y();
  double z0 = X.Z();
  double px = P.X();
  double py = P.Y();
  double pz = P.Z();
  
  //vector <double> tLimits = innerIntersectionTs(155.,X,P);
  vector <double> tLimits = innerIntersectionTs(155.,X,P);
  // make steps of 1cm
  TVector3 startPoint = tLimits[0]*P + X;
  TVector3 endPoint   = tLimits[1]*P + X;
  
  double pathLength = sqrt( (endPoint.X()-startPoint.X())*(endPoint.X()-startPoint.X())
			    + (endPoint.Y()-startPoint.Y())*(endPoint.Y()-startPoint.Y())
			    + (endPoint.Z()-startPoint.Z())*(endPoint.Z()-startPoint.Z()) );
  
  double timeStep = (tLimits[1]-tLimits[0])/pathLength;
  double testTime = tLimits[0];
  double t1 = testTime;
  double smallestDiff1 = 1000.;
  double t2 = testTime;
  double smallestDiff2 = 1000.;
  
  while(1){
    testTime+=timeStep;
    if(testTime>tLimits[1]) break;
    // look at quadratic form for t described in innerIntersectionTs
    // here R is no longer a constant, but varies with z. We now scan
    // t to make this equation as close to 0 as possible.
    double testZ = pz*testTime + z0;
    //cout << "testZ " << testZ << "z0 "<< z0<< "y0" << y0 << "z0 "<< z0 <<endl;
    double testR = OuterEBRho(testZ);
    double testDiff = fabs(  testTime*testTime * (px*px + py*py)
			     + testTime          * 2.*(px*x0 + py*y0)
			     + x0*x0 + y0*y0 - testR*testR
			     );
    
    if(testTime<timeDCA){
      if(testDiff<smallestDiff1){
	smallestDiff1 = testDiff;
	
	t1 = testTime;
	
      }
    }else{ 
      if(testDiff<smallestDiff2){
	smallestDiff2 = testDiff;
	t2 = testTime;
	
      }
    }//else timeDCA
  }//while
  
  vector<double> t;
  t.push_back(t1);
  t.push_back(t2);
  return t;
}
Exemple #24
0
void run_ana_8He(TString FileNameHead = "output_proto_reco",
                 Int_t num_ev=3000000, Int_t file_ini=0, Int_t file_end=0, Int_t runnum=250, Float_t HoughDist=2.0,
                 Bool_t debug=kTRUE, Bool_t stdhough=kFALSE, TString file="../Kinematics/Decay_kinematics/Kine.txt")
{

    //gStyle->SetCanvasPreferGL(1);
    //gStyle->SetPalette(1);
    if(!debug)	gErrorIgnoreLevel=kFatal; //Avoid printing Minuit errors

    TCanvas *ctest = new TCanvas("ctest","ctest",200,10,700,700);

    TCanvas *c1 = new TCanvas("c1","c1",200,10,700,700);
    c1->Divide(2,2);
    TCanvas *c2 = new TCanvas("c2","c2",200,10,700,700);
    c2->Divide(2,3);
    TCanvas *c3 = new TCanvas("c3","c3",200,10,700,700);
    c3->Divide(2,1);
    TCanvas *c4 = new TCanvas("c4","c4",200,10,700,700);
    c4->Divide(2,2);

    TH2F* fQuadrant[4];
    for (Int_t i=0; i<4; i++) {
        fQuadrant[i] = new TH2F(Form("fQuadrant[%i]",i),Form("fQuadrant%i",i),500,0,3.15,2500,0,1000);
        fQuadrant[i]->SetFillColor(2);
    }


    TH1I* DistHist[4];
    for (Int_t i=0; i<4; i++) DistHist[i] = new TH1I(Form("DistHist[%i]",i),Form("DistHit%i",i),100,0,1000);



    TF1 *HoughFit[4];
    TF1 *HoughFitSTD[4];
    TF1 *fitResult[4];
    TF1 *fitResultSTD[4];
    TGraph *HitPattern[4];
    TGraph *HitPatternSTD[4];
    TGraph *HitPatternFilter[4];
    TGraph *HitPatternFilterSTD[4];


    for (Int_t i=0; i<4; i++) {
        HoughFit[i] =new TF1(Form("HoughFit%i",i)," (  (-TMath::Cos([0])/TMath::Sin([0]))*x ) + [1]/TMath::Sin([0])",0,120);
        HoughFit[i]->SetLineColor(kRed);
        HoughFitSTD[i] =new TF1(Form("HoughFitSTD%i",i)," (  (-TMath::Cos([0])/TMath::Sin([0]))*x ) + [1]/TMath::Sin([0])",0,120);
        HoughFitSTD[i]->SetLineColor(kBlue);
        HitPatternFilter[i] = new TGraph();
        HitPatternFilter[i]->SetMarkerStyle(22);
        HitPatternFilter[i]->SetMarkerSize(0.7);
        HitPatternFilterSTD[i] = new TGraph();
        HitPatternFilterSTD[i]->SetMarkerStyle(21);
        HitPatternFilterSTD[i]->SetMarkerSize(0.7);

    }

    TH2D* Q02_Kine = new TH2D("Q02_Kine","Q02_Kine",1000,0,180,1000,0,180);
    Q02_Kine->SetMarkerColor(2);
    Q02_Kine->SetMarkerStyle(20);
    Q02_Kine->SetMarkerSize(0.7);
    TH2D* Q13_Kine = new TH2D("Q13_Kine","Q13_Kine",1000,0,180,1000,0,180);
    Q13_Kine->SetMarkerColor(2);
    Q13_Kine->SetMarkerStyle(20);
    Q13_Kine->SetMarkerSize(0.7);

    TH2D* Q02_Kine_buff = new TH2D("Q02_Kine_buff","Q02_Kine_buff",1000,0,180,1000,0,180);
    Q02_Kine_buff->SetMarkerColor(4);
    Q02_Kine_buff->SetMarkerStyle(20);
    Q02_Kine_buff->SetMarkerSize(0.7);
    TH2D* Q13_Kine_buff = new TH2D("Q13_Kine_buff","Q13_Kine_buff",1000,0,180,1000,0,180);
    Q13_Kine_buff->SetMarkerColor(4);
    Q13_Kine_buff->SetMarkerStyle(20);
    Q13_Kine_buff->SetMarkerSize(0.7);


    TH2F* fQuadHist[4];
    for (Int_t i=0; i<4; i++) {
        fQuadHist[i] = new TH2F(Form("fQuadHist[%i]",i),Form("fQuadHist%i",i),100,0,130,200,0,500);
        fQuadHist[i]->SetFillColor(2);
    }


    Int_t    tTreeEv=0;
    Double_t tHoughPar0[4]= {0};
    Double_t tHoughPar1[4]= {0};
    Double_t tFitPar0[4]= {0};
    Double_t tFitPar1[4]= {0};
    Double_t tAngleHough[4]= {0};
    Double_t tAngleFit[4]= {0};

    TFile *f = new TFile("analysis_8He.root","RECREATE");
    TTree *treeOut = new TTree("AnalysisTree","AnalysisTree");
    treeOut->Branch("tTreeEv",&tTreeEv,"tTreeEv/I");
    treeOut->Branch("tHoughPar0",&tHoughPar0,"tHoughPar0[4]/D");
    treeOut->Branch("tHoughPar1",&tHoughPar1,"tHoughPar1[4]/D");
    treeOut->Branch("tFitPar0",&tFitPar0,"tFitPar0[4]/D");
    treeOut->Branch("tFitPar1",&tFitPar1,"tFitPar1[4]/D");
    treeOut->Branch("tAngleHough",&tAngleHough,"tAngleHough[4]/D");
    treeOut->Branch("tAngleFit",&tAngleFit,"tAngleFit[4]/D");




    TChain *chain = new TChain("cbmsim");
    TFileCollection *filecol = new TFileCollection();
    TString FileNameHead_num;
    TString FileNameHead_chain;

    for(Int_t i=0; i<=file_end; i++) {
        if(i<10) FileNameHead_num.Form("%i_000%i",runnum,i);
        else if(i<100) FileNameHead_num.Form("%i_00%i",runnum,i);
        else if(i<1000) FileNameHead_num.Form("%i_0%i",runnum,i);
        FileNameHead_chain = "../run"+FileNameHead_num+".root";
        std::cout<<" File : "<<FileNameHead_chain<<" added"<<std::endl;
        //filecol->Add(FileNameHead_chain);
        //chain->Add(FileNameHead_chain);





        //TString FileNameHead = "../run571_0003";
        TString workdir = getenv("VMCWORKDIR");
        //TString FilePath = workdir + "/macro/data/pATTPC/TRIUMF_ISAC_2015/";
        TString FilePath = workdir + "/macro/Unpack_GETDecoder2/";
        TString FileNameTail = ".root";
        TString FileName     = FilePath + FileNameHead + FileNameTail;
        //TString outFileNameHead = "data/";
        //TString outFileNameTail = ".root";
        //TString outFileName     = outFileNameHead + reactionName + outFileNameTail;
        std::cout<<" Opening File : "<<FileName.Data()<<std::endl;
        TFile* file = new TFile(FileName.Data(),"READ");
        //TFile* file = new TFile(FileNameHead_chain.Data(),"READ");
        TTree* tree = (TTree*) file -> Get("cbmsim");
        Int_t nEvents = tree -> GetEntriesFast();
        std::cout<<" Number of events : "<<nEvents<<std::endl;

        TTreeReader Reader1("cbmsim", file);
        //TTreeReaderValue<TClonesArray> eventArray(Reader1, "ATEventH");
        TTreeReaderValue<TClonesArray> protoeventArray(Reader1, "ATProtoEvent");
        TTreeReaderValue<TClonesArray> houghArray(Reader1, "ATHough");
        Bool_t fIsLinear=kFALSE;
        Bool_t fIsCircular=kFALSE;

        Int_t value;
        Int_t nEve=0;

        while (Reader1.Next() && nEve<num_ev) {
            tTreeEv=nEve;

            if(debug) mypause();
            Q02_Kine_buff->Reset(0);
            Q13_Kine_buff->Reset(0);
            for (Int_t i=0; i<4; i++) {
                fQuadHist[i]->Reset();
                HitPatternFilter[i]->Set(0);
                HitPatternFilterSTD[i]->Set(0);
            }


            ATProtoEvent* protoevent = (ATProtoEvent*) protoeventArray->At(0);
            std::vector<ATProtoQuadrant> quadrantArray;
            ATProtoQuadrant* quadrant;
            std::vector<Int_t> qNumHits;
            std::vector<Double_t> qRad;

            //ATEvent* event = (ATEvent*) eventArray->At(0);
            //Int_t nHits = event->GetNumHits();
            //std::cout<<" ==================================================================================="<<std::endl;
            //if(nEve%100==0) std::cout<<" Event number : "<<protoevent->GetEventID()<<" - Number of Hits : "<<nHits<<std::endl;
            //if(nEve%100==0)
            std::cout<<cRED<<" Event Number : "<<nEve<<cNORMAL<<std::endl;
            if(debug) for (Int_t i=0; i<4; i++) DistHist[i]->Reset(0);



            ATHoughSpaceLine* fHoughSpaceLine_buff  = dynamic_cast<ATHoughSpaceLine*> (houghArray->At(0));

            //  ATHoughSpaceCircle* fHoughSpaceCircle_buff;
            /*   if( (fHoughSpaceLine_buff = dynamic_cast<ATHoughSpaceLine*> (houghArray->At(0)) )){
            	//std::cout<<" Linear Hough Space Found!"<<std::endl;
            	fIsLinear=kTRUE;
            	   }else if( (fHoughSpaceCircle_buff = dynamic_cast<ATHoughSpaceCircle*> (houghArray->At(0)) )){
            	//std::cout<<"Circular Hough Space Found!"<<std::endl;
            	fIsCircular=kTRUE;
            }else std::cout<<"Hough Space Type NOT Found!"<<std::endl;*/





            std::vector<std::pair<Double_t,Double_t>> HoughPar = fHoughSpaceLine_buff->GetHoughPar(); //No argument retrieve parameters from Hough Histogram
            std::vector<std::pair<Double_t,Double_t>> HoughParSTD;
            if(stdhough) HoughParSTD = fHoughSpaceLine_buff->GetHoughPar("STD");

            std::vector<Double_t> par0_fit;
            std::vector<Double_t> par1_fit;
            std::vector<Double_t> Angle;
            std::vector<Double_t> Angle_fit;

            std::vector<Double_t> par0_fitSTD;
            std::vector<Double_t> par1_fitSTD;
            std::vector<Double_t> AngleSTD;
            std::vector<Double_t> Angle_fitSTD;
            //par0_fit.resize(4);
            //par1_fit.resize(4);

            for(Int_t i=0; i<HoughPar.size(); i++) {

                Angle.push_back(180-HoughPar.at(i).first*180/TMath::Pi());

                tHoughPar0[i]=HoughPar.at(i).first;
                tHoughPar1[i]=HoughPar.at(i).second;
                tAngleHough[i]=180-HoughPar.at(i).first*180/TMath::Pi();




                if(debug) {
                    std::cout<<" ------ Hough Parameters for Quadrant : "<<i<<std::endl;
                    std::cout<<" Angle HIST : "<<180-HoughPar.at(i).first*180/TMath::Pi()<<std::endl;
                    std::cout<<" Distance HIST : "<<HoughPar.at(i).second<<std::endl;

                    if(stdhough  && debug) {
                        std::cout<<" Angle STD : "<<180-HoughParSTD.at(i).first*180/TMath::Pi()<<std::endl;
                        std::cout<<" Distance STD : "<<HoughParSTD.at(i).second<<std::endl;
                    }


                    HoughFit[i]->SetParameter(0,HoughPar.at(i).first);
                    HoughFit[i]->SetParameter(1,HoughPar.at(i).second);
                    //HoughFit[i]->SetRange(0,qRad.at(i));

                    if(stdhough) {

                        HoughFitSTD[i]->SetParameter(0,HoughParSTD.at(i).first);
                        HoughFitSTD[i]->SetParameter(1,HoughParSTD.at(i).second);
                        //HoughFitSTD[i]->SetRange(0,qRad.at(i));

                    }
                }

            }// HoughPar Loop




            for (Int_t i=0; i<4; i++) {
                //fQuadrant[i]  = fHoughSpaceLine_buff->GetHoughQuadrant(i); //Obsolete
                quadrant = &protoevent->GetQuadrantArray()->at(i);
                qNumHits.push_back(quadrant->GetNumHits());
                Int_t qNumHit = quadrant->GetNumHits();
                Double_t *rad_graph = new Double_t[qNumHit];
                Double_t *posz_graph = new Double_t[qNumHit];



                Double_t rad_max=0.0;

                for(Int_t j=0; j<qNumHit; j++) {
                    ATHit* qhit = quadrant->GetHit(j);
                    TVector3 position = qhit->GetPosition();
                    //position.SetZ( (qhit->GetTimeStamp()-390)*2.8*80/10.0 );
                    //position.SetZ( (390-qhit->GetTimeStamp())*2.8*80.0/100.0 );
                    Double_t radius = TMath::Sqrt( TMath::Power(position.X(),2) + TMath::Power(position.Y(),2) );
                    if(radius>rad_max) rad_max=radius;
                    fQuadHist[i]->Fill(radius,position.Z(),qhit->GetCharge());
                    rad_graph[j] = radius;
                    posz_graph[j] = position.Z();


                    Int_t pixelY = ctest->YtoAbsPixel(position.Z());
                    Int_t pixelX = ctest->XtoAbsPixel(radius);
                    Int_t pixelYback = ctest->AbsPixeltoY(pixelY);
                    Int_t pixelXback = ctest->AbsPixeltoX(pixelX);

                    Int_t mda = HoughFit[i]->DistancetoPrimitive(-pixelX,pixelY); //Minimum Distance of Approach in Pixels
                    DistHist[i]->Fill(mda);

                    Double_t geo_dist_STD = 0.0;
                    Double_t geo_dist = TMath::Abs (TMath::Cos(HoughPar.at(i).first)*radius  + TMath::Sin(HoughPar.at(i).first)*position.Z()  - HoughPar.at(i).second);
                    if(stdhough)  geo_dist_STD = TMath::Abs (TMath::Cos(HoughParSTD.at(i).first)*radius  + TMath::Sin(HoughParSTD.at(i).first)*position.Z()  - HoughParSTD.at(i).second);

                    // An example to make annotations to each one of the TGraph points
                    /*	TLatex *latex = new TLatex(gr->GetX()[5], gr->GetY()[5],"my annotation");
                    gr->GetListOfFunctions()->Add(latex);
                    gr->Draw("alp");
                    latex->SetTextSize(0.07);
                    latex->SetTextColor(kRed);*/


                    /*if(debug){
                    	    std::cout<<" ___________________________________________________________________________________________________"<<std::endl;
                    		  std::cout<<" Hit : "<<j<<" - Radius : "<<radius<<" - Z pos : "<<position.Z()<<"        -  Distance to Hough Space : "<<mda<<" Geomtrical Distance : "<<geo_dist<<std::endl;
                    			//std::cout<<" Pixel X : "<<pixelX<<" Pixel Y : "<<pixelY<<std::endl;
                    			//std::cout<<" Pixel Back X : "<<pixelXback<<" Pixel Back Y : "<<pixelYback<<std::endl;

                    }*/

                    if(geo_dist<HoughDist) HitPatternFilter[i]->SetPoint(HitPatternFilter[i]->GetN(),radius,position.Z());
                    if(stdhough)
                        if(geo_dist_STD<HoughDist) HitPatternFilterSTD[i]->SetPoint(HitPatternFilterSTD[i]->GetN(),radius,position.Z());

                }//NumHit loop

                Double_t par0=0.0;
                Double_t par1=0.0;
                Double_t afit=0.0;
                Double_t par0STD=0.0;
                Double_t par1STD=0.0;
                Double_t afitSTD=0.0;



                qRad.push_back(rad_max);
                //HoughFit[i]->SetRange(0,rad_max);

                if(debug) HitPattern[i] = new TGraph(qNumHit,rad_graph,posz_graph);
                if(debug && stdhough) HitPatternSTD[i] = new TGraph(qNumHit,rad_graph,posz_graph);

                if(debug)std::cout<<cYELLOW<<" Fitting Quadrant : "<<i<<cNORMAL<<std::endl;

                if(HitPatternFilter[i]->GetN()>3) {
                    //if(qNumHit>3){
                    HitPatternFilter[i]->Fit("pol1","FQ");
                    fitResult[i] = HitPatternFilter[i]->GetFunction("pol1");

                    if(stdhough) {
                        HitPatternFilterSTD[i]->Fit("pol1","FQ");
                        fitResultSTD[i] = HitPatternFilterSTD[i]->GetFunction("pol1");

                    }

                    //if(!fitResult[i]) std::cout<<" NULL "<<std::endl;

                    if(fitResult[i]) {
                        Bool_t IsValid = fitResult[i]->IsValid();
                        fitResult[i] ->SetName(Form("fitResult%i",i));
                        fitResult[i] ->SetLineColor(kRed);
                        fitResult[i] ->SetLineWidth(1);
                        par0 = fitResult[i]->GetParameter(0);
                        par1 = fitResult[i]->GetParameter(1);

                        if(par1>=0) afit = TMath::ATan2(1,TMath::Abs(par1));
                        else if(par1<0)  afit = TMath::Pi()-TMath::ATan2(1,TMath::Abs(par1));

                        //std::cout<<" Par 0 : "<<par0<<std::endl;
                        //std::cout<<" Par 1 : "<<par1<<std::endl;
                        //if(gMinuit && debug) std::cout<<gMinuit->fCstatu<<std::endl;


                    }


                    if(fitResultSTD[i] && stdhough) {
                        Bool_t IsValid = fitResultSTD[i]->IsValid();
                        fitResultSTD[i] ->SetName(Form("fitResultSTD%i",i));
                        fitResultSTD[i] ->SetLineColor(kRed);
                        fitResultSTD[i] ->SetLineWidth(1);
                        par0STD = fitResultSTD[i]->GetParameter(0);
                        par1STD = fitResultSTD[i]->GetParameter(1);

                        if(par1STD>=0) afitSTD = TMath::ATan2(1,TMath::Abs(par1));
                        else if(par1STD<0)  afitSTD = TMath::Pi()-TMath::ATan2(1,TMath::Abs(par1));


                    }


                }

                par0_fit.push_back(par0);
                par1_fit.push_back(par1);
                Angle_fit.push_back(afit*180/TMath::Pi());


                tFitPar0[i]=par0;
                tFitPar1[i]=par1;
                tAngleFit[i]=afit*180/TMath::Pi();


                if(stdhough) {
                    par0_fitSTD.push_back(par0STD);
                    par1_fitSTD.push_back(par1STD);
                    Angle_fitSTD.push_back(afitSTD*180/TMath::Pi());
                }



            }// Quadrant Loop







            /*std::cout<<" Radius Q0 : "<<qRad.at(0)<<std::endl;
            std::cout<<" Radius Q1 : "<<qRad.at(1)<<std::endl;
            std::cout<<" Radius Q2 : "<<qRad.at(2)<<std::endl;
            std::cout<<" Radius Q3 : "<<qRad.at(3)<<std::endl;*/


            if((qRad.at(0)>5 && qRad.at(2)>5)  && (qNumHits.at(0)>5 && qNumHits.at(2)>5) && TMath::Abs(par0_fit.at(0)-par0_fit.at(2))<50 ) {
                Q02_Kine->Fill(Angle_fit.at(0),Angle_fit.at(2));
                Q02_Kine_buff->Fill(Angle_fit.at(0),Angle_fit.at(2));
                if(debug) {
                    std::cout<<" Vertex difference : "<<TMath::Abs(par0_fit.at(0)-par0_fit.at(2))<<std::endl;
                    std::cout<<" Quadrant 0 - Par 0 : "<<par0_fit.at(0)<<" Par 1 : "<<par1_fit.at(0)<<std::endl;
                    std::cout<<" Quadrant 2 - Par 0 : "<<par0_fit.at(2)<<" Par 1 : "<<par1_fit.at(2)<<std::endl;
                    std::cout<<" Angle from Hough Space Quadrant 0 : "<<Angle.at(0)<<" Angle from Hough Space Quadrant 2 : "<<Angle.at(2)<<std::endl;
                    std::cout<<" Angle from Fit Quadrant 0 : "<<Angle_fit.at(0)<<" Angle from Fit Quadrant 2 : "<<Angle_fit.at(2)<<std::endl;
                }
            }
            if((qRad.at(1)>5 && qRad.at(3)>5)  && (qNumHits.at(1)>5 && qNumHits.at(3)>5) && TMath::Abs(par0_fit.at(1)-par0_fit.at(3))<50) {
                Q02_Kine->Fill(Angle_fit.at(1),Angle_fit.at(3));
                Q02_Kine_buff->Fill(Angle_fit.at(1),Angle_fit.at(3));
                if(debug) {
                    std::cout<<" Vertex difference : "<<TMath::Abs(par0_fit.at(1)-par0_fit.at(3))<<std::endl;
                    std::cout<<" Quadrant 1 - Par 0 : "<<par0_fit.at(1)<<" Par 1 : "<<par1_fit.at(1)<<std::endl;
                    std::cout<<" Quadrant 3 - Par 0 : "<<par0_fit.at(3)<<" Par 1 : "<<par1_fit.at(3)<<std::endl;
                    std::cout<<" Angle from Hough Space Quadrant 1 : "<<Angle.at(1)<<" Angle from Hough Space Quadrant 3 : "<<Angle.at(3)<<std::endl;
                    std::cout<<" Angle from Fit Quadrant 1 : "<<Angle_fit.at(1)<<" Angle from Fit Quadrant 3 : "<<Angle_fit.at(3)<<std::endl;
                }
            }


            if(stdhough) {
                if((qRad.at(0)>5 && qRad.at(2)>5)  && (qNumHits.at(0)>5 && qNumHits.at(2)>5) && TMath::Abs(par0_fitSTD.at(0)-par0_fitSTD.at(2))<50 ) {
                    Q13_Kine->Fill(Angle_fitSTD.at(0),Angle_fitSTD.at(2));
                    Q13_Kine_buff->Fill(Angle_fitSTD.at(0),Angle_fitSTD.at(2));

                }
                if((qRad.at(1)>5 && qRad.at(3)>5)  && (qNumHits.at(1)>5 && qNumHits.at(3)>5) && TMath::Abs(par0_fitSTD.at(1)-par0_fitSTD.at(3))<50) {
                    Q13_Kine->Fill(Angle_fitSTD.at(1),Angle_fitSTD.at(3));
                    Q13_Kine_buff->Fill(Angle_fitSTD.at(1),Angle_fitSTD.at(3));

                }
            }




            /*for(Int_t iHit=0; iHit<nHits; iHit++)
            	{

            			ATHit hit = event->GetHitArray()->at(iHit);

            	}*/

            if(debug) {
                c1->cd(1);
                HitPattern[0]->Draw("A*");
                //HitPatternFilter[0]->Draw("A*");
                HoughFit[0]->Draw("SAME");
                if(stdhough) HoughFitSTD[0]->Draw("SAME");

                c1->cd(2);
                HitPattern[1]->Draw("A*");
                HoughFit[1]->Draw("SAME");
                if(stdhough) HoughFitSTD[1]->Draw("SAME");

                c1->cd(3);
                HitPattern[2]->Draw("A*");
                HoughFit[2]->Draw("SAME");
                if(stdhough) HoughFitSTD[2]->Draw("SAME");

                c1->cd(4);
                HitPattern[3]->Draw("A*");
                HoughFit[3]->Draw("SAME");
                if(stdhough) HoughFitSTD[3]->Draw("SAME");

                c1->Modified();
                c1->Update();

                c4->cd(1);
                //DistHist[0]->Draw();
                HitPatternFilter[0]->Draw("A*");
                c4->cd(2);
                //DistHist[1]->Draw();
                HitPatternFilter[1]->Draw("A*");
                c4->cd(3);
                //DistHist[2]->Draw();
                HitPatternFilter[2]->Draw("A*");
                c4->cd(4);
                //DistHist[3]->Draw();
                HitPatternFilter[3]->Draw("A*");
                c4->Modified();
                c4->Update();


                c2->cd(1);
                fQuadHist[0]->Draw("contz");
                c2->cd(2);
                fQuadHist[1]->Draw("contz");
                c2->cd(3);
                fQuadHist[2]->Draw("contz");
                c2->cd(4);
                fQuadHist[3]->Draw("contz");
                c2->cd(5);
                Q02_Kine->Draw("");
                Q02_Kine_buff->Draw("SAME");
                c2->cd(6);
                Q13_Kine->Draw("");
                Q13_Kine_buff->Draw("SAME");
                c2->Modified();
                c2->Update();


                ctest->cd();
                HitPattern[0]->Draw("A*");
                HoughFit[0]->Draw("SAMES");
                ctest->Modified();
                ctest->Update();

                std::cout<<cRED<<" Here"<<cNORMAL<<std::endl;

            }

            /*c1->cd(1); //Obsolete
            fQuadrant[0]->Draw("zcol");
            c1->cd(2);
            fQuadrant[1]->Draw("zcol");
            c1->cd(3);
            fQuadrant[2]->Draw("zcol");
            c1->cd(4);
            fQuadrant[3]->Draw("zcol");
            c1->Modified();
            c1->Update();	*/

            //myflush ( std::cin );
            //mypause();
            //std::cin.get();

            nEve++;
            treeOut->Fill();


        }//While

        file->Close();

    }//for files

    f->cd();
    treeOut->Write();
    f->Close();


    Double_t *ThetaCMS = new Double_t[20000];
    Double_t *ThetaLabRec = new Double_t[20000];
    Double_t *EnerLabRec = new Double_t[20000];
    Double_t *ThetaLabSca = new Double_t[20000];
    Double_t *EnerLabSca = new Double_t[20000];

    std::ifstream *kineStr = new std::ifstream(file.Data());
    Int_t numKin=0;

    if(!kineStr->fail()) {
        while(!kineStr->eof()) {
            *kineStr>>ThetaCMS[numKin]>>ThetaLabRec[numKin]>>EnerLabRec[numKin]>>ThetaLabSca[numKin]>>EnerLabSca[numKin];
            numKin++;
        }
    } else if(kineStr->fail()) std::cout<<" Warning : No Kinematics file found for this reaction! Please run the macro on $SIMPATH/macro/Kinematics/Decay_kinematics/Mainrel.cxx"<<std::endl;
void fill(int const kf, TLorentzVector* b, double weight, TLorentzVector const& p1Mom, TLorentzVector const& p2Mom, TVector3 v00)
{
   int const centrality = floor(nCent * gRandom->Rndm());

   TVector3 const vertex = getVertex(centrality);
   // smear primary vertex
   // float const sigmaVertex = sigmaVertexCent[cent];
   // TVector3 const vertex(gRandom->Gaus(0, sigmaVertex), gRandom->Gaus(0, sigmaVertex), gRandom->Gaus(0, sigmaVertex));

   v00 += vertex;

   // smear momentum
   TLorentzVector const p1RMom = smearMom(0, p1Mom);
   TLorentzVector const p2RMom = smearMom(0, p2Mom);

   // smear position
   TVector3 const p1RPos = smearPosData(0, vertex.z(), centrality, p1RMom, v00);
   TVector3 const p2RPos = smearPosData(0, vertex.z(), centrality, p2RMom, v00);
   // TVector3 const kRPos = smearPos(kMom, kRMom, v00);
   // TVector3 const pRPos = smearPos(pMom, pRMom, v00);

   // reconstruct
   TLorentzVector const rMom = p1RMom + p2RMom;
   float const p1Dca = dca(p1Mom.Vect(), v00, vertex);
   float const p2Dca = dca(p2Mom.Vect(), v00, vertex);
   float const p1RDca = dca(p1RMom.Vect(), p1RPos, vertex);
   float const p2RDca = dca(p2RMom.Vect(), p2RPos, vertex);

   TVector3 v0;
   float const dca12 = dca1To2(p1RMom.Vect(), p1RPos, p2RMom.Vect(), p2RPos, v0);
   float const decayLength = (v0 - vertex).Mag();
   float const dcaD0ToPv = dca(rMom.Vect(), v0, vertex);
   float const cosTheta = (v0 - vertex).Unit().Dot(rMom.Vect().Unit());
   float const angle12 = p1RMom.Vect().Angle(p2RMom.Vect());

   TLorentzVector p1RMomRest = p1RMom;
   TVector3 beta;
   beta.SetMagThetaPhi(rMom.Beta(), rMom.Theta(), rMom.Phi());
   p1RMomRest.Boost(-beta);
   float const cosThetaStar = rMom.Vect().Unit().Dot(p1RMomRest.Vect().Unit());

   // save
   float arr[100];
   int iArr = 0;
   arr[iArr++] = centrality;
   arr[iArr++] = vertex.X();
   arr[iArr++] = vertex.Y();
   arr[iArr++] = vertex.Z();

   arr[iArr++] = kf;
   arr[iArr++] = b->M();
   arr[iArr++] = b->Perp();
   arr[iArr++] = b->PseudoRapidity();
   arr[iArr++] = b->Rapidity();
   arr[iArr++] = b->Phi();
   arr[iArr++] = v00.X();
   arr[iArr++] = v00.Y();
   arr[iArr++] = v00.Z();

   arr[iArr++] = rMom.M();
   arr[iArr++] = rMom.Perp();
   arr[iArr++] = rMom.PseudoRapidity();
   arr[iArr++] = rMom.Rapidity();
   arr[iArr++] = rMom.Phi();
   arr[iArr++] = v0.X();
   arr[iArr++] = v0.Y();
   arr[iArr++] = v0.Z();

   arr[iArr++] = dca12;
   arr[iArr++] = decayLength;
   arr[iArr++] = dcaD0ToPv;
   arr[iArr++] = cosTheta;
   arr[iArr++] = angle12;
   arr[iArr++] = cosThetaStar;

   arr[iArr++] = p1Mom.M();
   arr[iArr++] = p1Mom.Perp();
   arr[iArr++] = p1Mom.PseudoRapidity();
   arr[iArr++] = p1Mom.Rapidity();
   arr[iArr++] = p1Mom.Phi();
   arr[iArr++] = p1Dca;

   arr[iArr++] = p1RMom.M();
   arr[iArr++] = p1RMom.Perp();
   arr[iArr++] = p1RMom.PseudoRapidity();
   arr[iArr++] = p1RMom.Rapidity();
   arr[iArr++] = p1RMom.Phi();
   arr[iArr++] = p1RPos.X();
   arr[iArr++] = p1RPos.Y();
   arr[iArr++] = p1RPos.Z();
   arr[iArr++] = p1RDca;
   arr[iArr++] = tpcReconstructed(0,1,centrality,p1RMom);

   arr[iArr++] = p2Mom.M();
   arr[iArr++] = p2Mom.Perp();
   arr[iArr++] = p2Mom.PseudoRapidity();
   arr[iArr++] = p2Mom.Rapidity();
   arr[iArr++] = p2Mom.Phi();
   arr[iArr++] = p2Dca;

   arr[iArr++] = p2RMom.M();
   arr[iArr++] = p2RMom.Perp();
   arr[iArr++] = p2RMom.PseudoRapidity();
   arr[iArr++] = p2RMom.Rapidity();
   arr[iArr++] = p2RMom.Phi();
   arr[iArr++] = p2RPos.X();
   arr[iArr++] = p2RPos.Y();
   arr[iArr++] = p2RPos.Z();
   arr[iArr++] = p2RDca;
   arr[iArr++] = tpcReconstructed(0,-1,centrality,p2RMom);

   arr[iArr++] = matchHft(1, vertex.z(), centrality, p1RMom);
   arr[iArr++] = matchHft(0, vertex.z(), centrality, p2RMom);

   nt->Fill(arr);
}
Exemple #26
0
KVFAZIABlock::KVFAZIABlock() : TGeoVolumeAssembly("STRUCT_BLOCK")
{
   // Default constructor

   SetMedium(gGeoManager->GetMedium("Vacuum"));//to avoid warnings about STRUCT_BLOCK has dummy medium

   KVMaterial mat_si("Si");
   TGeoMedium *Silicon = mat_si.GetGeoMedium();

   KVMaterial mat_csi("CsI");
   TGeoMedium *CesiumIodide = mat_csi.GetGeoMedium();

   KVMaterial mat_plomb("Lead");
   TGeoMedium *Plomb = mat_plomb.GetGeoMedium();

   TGeoVolumeAssembly* quartet = gGeoManager->MakeVolumeAssembly("STRUCT_QUARTET");
   quartet->SetMedium(gGeoManager->GetMedium("Vacuum"));//to avoid warnings about STRUCT_QUARTET has dummy medium

   TGeoVolume* si = 0;
   TGeoVolume* csi = 0;

   Double_t distance_si2_si1 = 0.220;
   Double_t distance_csi_si2 = 0.434;

   Double_t side_si = 2;
   Double_t side_csi_front = 2.050;
   Double_t side_csi_back = 2.272;

   Double_t inter_si = 0.24;

   Double_t thick_si1 = 300 * KVUnits::um;
   Double_t thick_si2 = 500 * KVUnits::um;
   Double_t thick_csi = 10;

   Double_t adjust_csi = 0.0165;

   Int_t ndet = 1;;
   TGeoTranslation* tr = 0;

   Double_t shift = side_si / 2 + inter_si / 2;
   //printf("%lf\n", shift);

   Double_t coefx[4] = { -1., -1., 1., 1.};
   Double_t coefy[4] = {1., -1., -1., 1.};

   for (Int_t nt = 1; nt <= 4; nt += 1) {

      shift = side_si / 2 + inter_si / 2;

      si = gGeoManager->MakeBox(Form("DET_SI1-T%d", nt), Silicon, side_si / 2, side_si / 2, thick_si1 / 2.);
      tr = new TGeoTranslation(coefx[nt - 1]*shift, coefy[nt - 1]*shift, thick_si1 / 2.);

      quartet->AddNode(si, ndet++, tr);
      ((TGeoNodeMatrix*)quartet->GetNodes()->Last())->SetName(Form("DET_SI1-T%d", nt));

      si = gGeoManager->MakeBox(Form("DET_SI2-T%d", nt), Silicon, side_si / 2, side_si / 2, thick_si2 / 2.);
      tr = new TGeoTranslation(coefx[nt - 1]*shift, coefy[nt - 1]*shift, thick_si2 / 2. + distance_si2_si1);
      quartet->AddNode(si, ndet++, tr);
      ((TGeoNodeMatrix*)quartet->GetNodes()->Last())->SetName(Form("DET_SI2-T%d", nt));

      shift = side_si / 2 + inter_si / 2 + adjust_csi;

      csi = gGeoManager->MakeTrd2(Form("DET_CSI-T%d", nt), CesiumIodide, side_csi_front / 2, side_csi_back / 2, side_csi_front / 2, side_csi_back / 2, thick_csi / 2.);
      tr = new TGeoTranslation(coefx[nt - 1]*shift, coefy[nt - 1]*shift, thick_csi / 2. + distance_csi_si2);
      quartet->AddNode(csi, ndet++, tr);
      ((TGeoNodeMatrix*)quartet->GetNodes()->Last())->SetName(Form("DET_CSI-T%d", nt));

   }

   Int_t nbl = 1;
   TGeoVolume* blindage = 0;
//Double_t thick_bld = thick_si1+distance_si2_si1+thick_si2;
   /* l'epaisseur du si1 est compris dans la distance_si2_si1 */
   Double_t thick_bld = distance_si2_si1 + thick_si2;
   Double_t shift_bld = (side_si + inter_si) / 2.;
///Croix inter quartet
//
// Separation des 4 télescopes
//
//
   blindage = gGeoManager->MakeBox("DEADZONE_BLINDAGE_1", Plomb, inter_si / 2, (side_si + inter_si / 2), thick_bld / 2.);
   //printf("%s\n", blindage->GetMaterial()->GetTitle());
   tr = new TGeoTranslation(0, 0, thick_bld / 2.);
   quartet->AddNode(blindage, nbl++, tr);

   blindage = gGeoManager->MakeBox("DEADZONE_BLINDAGE_2", Plomb, (side_si / 2), inter_si / 2, thick_bld / 2.);
   tr = new TGeoTranslation(-1 * shift_bld, 0, thick_bld / 2.);
   quartet->AddNode(blindage, nbl++, tr);
   tr = new TGeoTranslation(+1 * shift_bld, 0, thick_bld / 2.);
   quartet->AddNode(blindage, nbl++, tr);

///Contour de l ensemble du quartet
//
//Délimiation des bords exterieurs
//
//
   shift_bld = (side_si + inter_si);

   blindage = gGeoManager->MakeBox("DEADZONE_BLINDAGE_3", Plomb, (side_si + inter_si / 2), inter_si / 2, thick_bld / 2.);
   tr = new TGeoTranslation(0, shift_bld, thick_bld / 2.);
   quartet->AddNode(blindage, nbl++, tr);
   tr = new TGeoTranslation(0, -1 * shift_bld, thick_bld / 2.);
   quartet->AddNode(blindage, nbl++, tr);
///
   blindage = gGeoManager->MakeBox("DEADZONE_BLINDAGE_4", Plomb, inter_si / 2, (side_si + inter_si * 1.5), thick_bld / 2.);
   tr = new TGeoTranslation(shift_bld, 0, thick_bld / 2.);
   quartet->AddNode(blindage, nbl++, tr);
   tr = new TGeoTranslation(-1 * shift_bld, 0, thick_bld / 2.);
   quartet->AddNode(blindage, nbl++, tr);

   fTotSidWBlind = 4 * side_si + 5 * inter_si;
//Coordonnées extraite des côtes données par Yvan M.
//vecteur pointant le milieu d un quartet
//X=-2.231625
//Y=-2.230525
//Z=99.950350
// Mag=100.000139
// Theta=1.808104
// Phi = -135.014124
   TVector3* placement = new TVector3(-2.231625, -2.230525, 99.950350);
   TVector3* Centre = new TVector3();

   TGeoRotation rot1, rot2;
   TGeoTranslation trans;
   TGeoTranslation invZtrans(0, 0, -100);

   TGeoHMatrix h;
   TGeoHMatrix* ph = 0;

//Boucle sur les 4 quartets d un block
   Double_t tx[4] = {1, -1, -1, 1};
   Double_t ty[4] = {1, 1, -1, -1};

   Double_t theta = 0;
   Double_t phi = 0;
   Double_t trans_z = 0;

   for (Int_t nq = 1; nq <= 4; nq += 1) {

      Centre->SetXYZ(placement->X()*tx[nq - 1], placement->Y()*ty[nq - 1], placement->Z());

      theta = Centre->Theta() * TMath::RadToDeg();
      phi = Centre->Phi() * TMath::RadToDeg();

      trans_z = Centre->Mag() + thick_si1 / 2.;

      rot2.SetAngles(phi + 90., theta, 0.);
      rot1.SetAngles(-1.*phi, 0., 0.);
      trans.SetDz(trans_z);

      h = invZtrans * rot2 * trans * rot1;
      ph = new TGeoHMatrix(h);

      AddNode(quartet, nq, ph);
   }
}
Exemple #27
0
Mpdshape* initDrawLayer(ofstream* f, TVector3 rot, TVector3 pos, Double_t alpha) {
    
    points.str(""); position.str(""); rotation.str("");
    // straw layer helpers 
    points << 0.0 << " " << 0.0 << " " << -layerThickness/2.0 << endl;
    points << innerRadius << " " << outerRadius << endl;
    points << 0.0 << " " << 0.0 << " " << layerThickness/2.0;
    position << 0.0 << " " << 0.0 << " " << (initDist+layerThickness/2.0);

    // straw layer definition
    std::ostringstream layername;
    layername << "stt01layer";
    if (alpha > 0) {
	layername << "right";
    } else if (alpha < 0) {
	layername << "left";
    } else {
	layername << "radial";
    }

    Mpdshape* layerR = new Mpdshape(f, (layername.str()).c_str(), "cave", "TUBE", "air",                                                                        
	points.str(),                                     
	position.str());                                                                                                                                 
    layerR->SetSegment(1);

    // straw tube helpers
    points.str(""); position.str(""); rotation.str("");
    points << 0.0 << " " << 0.0 << " " << -(outerRadius-innerRadius)/2. << endl;
    points << 0.0 << " " << tubeRadius << endl;
    points << 0.0 << " " << 0.0 << " " << (outerRadius-innerRadius)/2.;


    std::ostringstream tubename;
    tubename << "stt01tube";
    if (alpha > 0) {
	tubename << "right";
    } else if (alpha < 0) {
	tubename << "left";
    } else {
	tubename << "radial";
    }
    // straw tube definition
    Mpdshape* tube = new Mpdshape(f, (tubename.str()).c_str(), (layername.str()).c_str(), "TUBE", "kapton", points.str());
    tube->SetSegment(1);
    tube->SetMotherSegment(1);

    // straw gas helpers
    points.str(""); position.str(""); rotation.str("");
    points << 0.0 << " " << 0.0 << " " << -(outerRadius-innerRadius)/2. << endl;
    points << 0.0 << " " << gasRadius << endl;
    points << 0.0 << " " << 0.0 << " " << (outerRadius-innerRadius)/2.;

    std::ostringstream gasname;
    gasname << "stt01gas";
    if (alpha > 0) {
	gasname << "right";
    } else if (alpha < 0) {
	gasname << "left";
    } else {
	gasname << "radial";
    }
    // straw gas definition
    Mpdshape* gas = new Mpdshape(f, (gasname.str()).c_str(), (tubename.str()).c_str(), "TUBE", "DCHmixture",
    points.str());
    gas->SetSegment(1);
    gas->SetMotherSegment(1);

    // straw wire helpers
    points.str(""); position.str(""); rotation.str("");
    points << 0.0 << " " << 0.0 << " " << -(outerRadius-innerRadius)/2. << endl;
    points << 0.0 << " " << wireRadius << endl;
    points << 0.0 << " " << 0.0 << " " << (outerRadius-innerRadius)/2.;

    std::ostringstream wirename;
    wirename << "stt01wire";
    if (alpha > 0) {
	wirename << "right";
    } else if (alpha < 0) {
	wirename << "left";
    } else {
	wirename << "radial";
    }
    // straw wire definition
    Mpdshape* wire = new Mpdshape(f, (wirename.str()).c_str(), (gasname.str()).c_str(), "TUBE", "copper",
    points.str());
    wire->SetSegment(1);
    wire->SetMotherSegment(1);

    // output first layer definition, moved to initial position and rotated(!)
    layerR->SetRotation(rot.X(), rot.Y(), rot.Z());
    layerR->SetPosition(pos.X(), pos.Y(), pos.Z());
    layerR->DumpWithIncrement();
    
    // output first tube definition
    // first tube should be rotated too !!
    tube->SetRotation(alpha+angleStraws, 90, 0); 
    TVector3 pos = getPosition(angleStraws);
    tube->SetPosition(pos.X(), pos.Y(), pos.Z());
    tube->DumpWithIncrement();

    // output first gas chamber definition
    gas->DumpWithIncrement();

    // output first wire definition
    wire->DumpWithIncrement();


    // output tubes for first layer, starting from 2 to numStrawsPerLayer, rotate each tube
    for (Int_t i = 2; i <= numStrawsPerLayer; i++) {
	tube->SetRotation(alpha+i*angleStraws, 90, 0);
	TVector3 pos = getPosition(i*angleStraws);
	tube->SetPosition(pos.X(), pos.Y(), pos.Z());
	tube->DumpWithIncrement();
    }

    return layerR;
}
Exemple #28
0
void drawLayer(Mpdshape* layer, TVector3 rot, TVector3 pos) {
    layer->SetRotation(rot.X(), rot.Y(), rot.Z());
    layer->SetPosition(pos.X(), pos.Y(), pos.Z());
    layer->DumpWithIncrement();
}
/*
 * Make SvtxTrack from PHGenFit::Track and SvtxTrack
 */
SvtxTrack* PHG4TrackKalmanFitter::MakeSvtxTrack(const SvtxTrack* svtx_track,
		const PHGenFit::Track* phgf_track) {

	double chi2 = phgf_track->get_chi2();
	double ndf = phgf_track->get_ndf();

	genfit::MeasuredStateOnPlane* gf_state = phgf_track->extrapolateToLine(TVector3(0.,0.,0.), TVector3(0.,0.,1.));
	TVector3 mom = gf_state->getMom();
	TVector3 pos = gf_state->getPos();
	TMatrixDSym cov = gf_state->get6DCov();


	//const SvtxTrack_v1* temp_track = static_cast<const SvtxTrack_v1*> (svtx_track);
	SvtxTrack_v1* out_track = new SvtxTrack_v1(*static_cast<const SvtxTrack_v1*> (svtx_track));

	/*!
	 *  1/p, u'/z', v'/z', u, v
	 *  u is defined as mom X beam line at POCA
	 *  so u is the dca2d direction
	 */
	double dca2d = gf_state->getState()[3];
	out_track->set_dca2d(dca2d);
	if(gf_state->getCov()[3][3] > 0)
		out_track->set_dca2d_error(sqrt(gf_state->getCov()[3][3]));
	else {
		out_track->set_dca2d_error(-9999);
		if(verbosity >= 1)
			LogWarning("gf_state->getCov()[3][3] <= 0");
	}
	double dca3d = sqrt(
			dca2d*dca2d +
			gf_state->getState()[4]*gf_state->getState()[4]);
	out_track->set_dca(dca3d);


	out_track->set_chisq(chi2);
	out_track->set_ndf(ndf);
	out_track->set_charge((_reverse_mag_field) ? -1.*phgf_track->get_charge() : phgf_track->get_charge());

	out_track->set_px(mom.Px());
	out_track->set_py(mom.Py());
	out_track->set_pz(mom.Pz());

	out_track->set_x(pos.X());
	out_track->set_y(pos.Y());
	out_track->set_z(pos.Z());

	for(int i=0;i<6;i++)
	{
		for(int j=i;j<6;j++)
		{
			out_track->set_error(i,j,cov[i][j]);
		}
	}

	for (SvtxTrack::ConstClusterIter iter = svtx_track->begin_clusters();
			iter != svtx_track->end_clusters(); ++iter) {
		unsigned int cluster_id = *iter;
		SvtxCluster* cluster = _clustermap->get(cluster_id);
		if(!cluster)
		{
			LogError("No cluster Found!");
			continue;
		}
		//cluster->identify(); //DEBUG

		//unsigned int l = cluster->get_layer();

		TVector3 pos(cluster->get_x(), cluster->get_y(), cluster->get_z());

		double radius = pos.Pt();

		//TODO add exception handling
		genfit::MeasuredStateOnPlane* gf_state = phgf_track->extrapolateToCylinder(radius,TVector3(0,0,0),TVector3(0,0,1), 0);

		if (!gf_state) {
			if (verbosity > 1)
				LogWarning("Exrapolation failed!");
			continue;
		}

		SvtxTrackState* state = new SvtxTrackState_v1(radius);
		state->set_x(gf_state->getPos().x());
		state->set_y(gf_state->getPos().y());
		state->set_z(gf_state->getPos().z());

		state->set_px(gf_state->getMom().x());
		state->set_py(gf_state->getMom().y());
		state->set_pz(gf_state->getMom().z());

		//gf_state->getCov().Print();

		for(int i=0;i<6;i++)
		{
			for(int j=i;j<6;j++)
			{
				out_track->set_error(i,j, gf_state->get6DCov()[i][j]);
			}
		}

		out_track->insert_state(state);

//		std::cout<<"===============\n";
//		LogDebug(radius);
//		std::cout<<"---------------\n";
//		TVector3 temp_vec(state->get_x(),state->get_y(),state->get_z());
//		LogDebug(temp_vec.Pt());
//		//state->identify();
//		std::cout<<"---------------\n";
//		//out_track->get_state(radius)->identify();
	}

	return out_track;
}
Exemple #30
0
void eventDirGenerator() {


    double xVals[10000],yVals[10000],zVals[10000];

    double rV=25000;
    double thetaV,phiV;

    double thetaMom,phiMom;

    int numPoints=0;

    TCanvas * can = new TCanvas("can","can");
    TH1F *framey = can->DrawFrame(-7e6,-7e6,+7e6,+7e6);

    TEllipse *elipsey = new TEllipse(0,0,6378.1e3,6378.1e3);
    elipsey->SetLineColor(8);
    elipsey->SetLineWidth(3);
    elipsey->Draw();//Ellipse(0,0,6378.1e3,6378.1e3);

    TLine *liney = new TLine();
    liney->SetLineColor(9);
    liney->SetLineWidth(1);
    liney->SetLineStyle(2);

    for(int i=0; i<10000; i++) {
        pickRandomThetaPhiOnSphere(phiV,thetaV);
        pickRandomDowngoingDirection(phiMom,thetaMom);
        double dxp=-1*TMath::Cos(phiMom)*TMath::Sin(thetaMom);
        double dyp=-1*TMath::Sin(phiMom)*TMath::Sin(thetaMom);
        double dzp=-1*TMath::Cos(thetaMom);

        TVector3 veccy(dxp,dyp,dzp);
        veccy.RotateZ(phiV);
        veccy.RotateX(thetaV);

//     double cosphi=TMath::Cos(phiV);
//     double sinphi=TMath::Sin(phiV);
//     double costheta=TMath::Cos(thetaV);
//     double sintheta=TMath::Sin(thetaV);

//     double dx=cosphi*dxp-sinphi*dyp;
//     double dy=costheta*sinphi*dxp + costheta*cosphi*dyp - sintheta*dzp;
//     double dz=sintheta*sinphi*dxp + sintheta*cosphi*dxp + costheta*dzp;


//    cout << veccy.X() << "\t" << veccy.Y() << "\t" << veccy.Z() << endl;
        //    cout << dx << "\t" << dy << "\t" << dz << endl;
        //    cout << veccy.Mag() << endl;


        //cout << phiV << "\t" << thetaV << endl;
        //    cout <<rEarth*rEarth << "\t" << rV*rV << "\t" <<  2*rEarth*rV*TMath::Cos(TMath::Pi()-thetaV) << endl;
        double rNew=TMath::Sqrt(rEarth*rEarth + rV*rV - 2*rEarth*rV*TMath::Cos(TMath::Pi()-thetaV));
        double thetaNew=TMath::ASin(TMath::Sin(TMath::Pi()-thetaV)*rV/rNew);
        double phiNew=phiV;

//     if(rNew>rEarth) {
//       cout << "Above:\t" <<  endl;
//     }
//     else {
//       cout << "Below:\t" <<  endl;
//     }


        double z=rNew*TMath::Cos(thetaNew);
        double x=rNew*TMath::Sin(thetaNew)*TMath::Cos(phiNew);
        double y=rNew*TMath::Sin(thetaNew)*TMath::Sin(phiNew);

        TVector3 intPos(x,y,z);
        TVector3 surfPos;

        int isValid=getSurfacePoint(intPos,veccy,surfPos);
        //    cout << isValid << endl;


        double x2=surfPos.X();
        double y2=surfPos.Y();
        double z2=surfPos.Z();



        if(isValid) {
            double x3=surfPos.X()+veccy.X()*1e6;
            double z3=surfPos.Z()+veccy.Z()*1e6;
            liney->DrawLine(x2,z2,x3,z3);
            xVals[numPoints]=surfPos.X();
            yVals[numPoints]=surfPos.Y();
            zVals[numPoints]=surfPos.Z();

            numPoints++;
        }
    }
    cout << numPoints << endl;
    TGraph *grxz= new TGraph(numPoints,xVals,yVals);
    grxz->Draw("p");




}