<!DOCTYPE HTML PUBLIC "-// IETF/DTD HTML 2.0// EN">
<html>
<!--                                             -->
<!-- Author: ROOT team (rootdev@hpsalo.cern.ch)  -->
<!--                                             -->
<!--   Date: Tue Apr  6 15:52:10 1999            -->
<!--                                             -->
<head>
<title>SmearTrack - source file</title>
<link rev=made href="mailto:rootdev@root.cern.ch">
<meta name="rating" content="General">
<meta name="objecttype" content="Manual">
<meta name="keywords" content="software development, oo, object oriented, unix, x11, motif, windows nt, c++, html, rene brun, fons rademakers">
<meta name="description" content="ROOT - An Object Oriented Framework For Large Scale Data Analysis.">
</head>
<body BGCOLOR="#ffffff" LINK="#0000ff" VLINK="#551a8b" ALINK="#ff0000" TEXT="#000000">
<a name="TopOfPage"></a>
<pre>
<b>// $Header: <a href=".././SmearTrack.html">SmearTrack</a>.cxx $</b>
<b>// algorithm from K.Riles 8.12.98</b>
<b>// Version 1.0 12-Aug-98 Richard incorporate K.Riles' algorithm.</b>
<b>// Version 1.1 06-Mar-99 Richard get start point from parent MC.</b>

#include "TString.h"
#include "<a href="../SmearTrack.h">SmearTrack.h</a>"
#include "<a href="../GetTrackLookups.h">GetTrackLookups.h</a>"
#include &lt;math.h&gt;
#include &lt;stdlib.h&gt;

<b>//______________________________________________________________________</b>
<b>//</b>
<b>// <a href=".././SmearTrack.html">SmearTrack</a></b>
<b>//</b>
<b>// Smears tracks via lookup tables on resolution      </b>

ClassImp(<a href=".././SmearTrack.html">SmearTrack</a>)
<a name="SmearTrack:makeTrack"> </a><a href="http://root.cern.ch/root/html/Track.html">Track</a>* <a href=".././SmearTrack.html#SmearTrack:makeTrack">SmearTrack::makeTrack</a>(<a href="http://root.cern.ch/root/html/McPart.html">McPart</a>* p, <a href="../ListOfTypes.html#Int_t">Int_t</a> index) {

<b>  // creates track for input <a href="http://root.cern.ch/root/html/McPart.html">McPart</a> if it passes acceptance cuts and</b>
<b>  // uses lookup tables for resolutions</b>

<b>// if MCParticle pointer is zero, it belongs to albedo shower particle. Ignore for now.</b>

    if (p == 0) return 0;
    
<b>    // get original momentum from MCParticle</b>
    
    <a href="../ListOfTypes.html#float">float</a>* pMC = p-&gt;GetMomentum();  
    <a href="../ListOfTypes.html#float">float</a> pTot = 0.;
    for ( <a href="../ListOfTypes.html#int">int</a> i=0; i &lt; 3; i++) {
      pTot += pMC[i]*pMC[i];
    }
    pTot = sqrt(pTot);

<b>    // convert to helical parameters</b>

    <a href="../ListOfTypes.html#float">float</a> ptsqr = pMC[0]*pMC[0] + pMC[1]*pMC[1];
    <a href="../ListOfTypes.html#float">float</a> pt = sqrt(ptsqr);
    <a href="../ListOfTypes.html#float">float</a> ptInv = 1./pt;

    <a href="../ListOfTypes.html#float">float</a> cos_theta = pMC[2]/pTot;
    <a href="../ListOfTypes.html#float">float</a> abscth = fabs(cos_theta);
    <a href="../ListOfTypes.html#float">float</a> theta = acos(cos_theta);
    <a href="../ListOfTypes.html#float">float</a> lambda = <a href="http://root.cern.ch/root/html/TMath.html#TMath:Pi">TMath::Pi</a>()/2. - theta;

    <a href="../ListOfTypes.html#float">float</a> phi = atan2(pMC[1],pMC[0]);
    if (phi &lt; 0.) phi += 2.* <a href="http://root.cern.ch/root/html/TMath.html#TMath:Pi">TMath::Pi</a>();

    <a href="http://root.cern.ch/root/html/McPart.html">McPart</a>* parent = p-&gt;GetParnt();
    <a href="../ListOfTypes.html#float">float</a>* xMC = parent-&gt;GetPosition();
    <a href="../ListOfTypes.html#float">float</a> r = sqrt(xMC[0]*xMC[0]+xMC[1]*xMC[1]);

    <a href="../ListOfTypes.html#int">int</a> rc;

<b>    // point at proper set of lookup tables</b>

    <a href=".././LookUp2d.html">LookUp2d</a>* par[5];

    if ( abscth &lt; <a href=".././SmearTrack.html#SmearTrack:m_parameters">m_parameters</a>-&gt;<a href="http://root.cern.ch/root/html/GetParameters.html#GetParameters:getPolarInner">getPolarInner</a>() ) {
      for (<a href="../ListOfTypes.html#int">int</a> in=0; in &lt; 5; in++) {
	par[in] = <a href="#SmearTrack:getBarrelTable">getBarrelTable</a>(in);
      }
    }
    else if (abscth &lt; <a href=".././SmearTrack.html#SmearTrack:m_parameters">m_parameters</a>-&gt;<a href="http://root.cern.ch/root/html/GetParameters.html#GetParameters:getPolarOuter">getPolarOuter</a>() ) {
      for (<a href="../ListOfTypes.html#int">int</a> o=0; o &lt; 5; o++) {
	par[o] = <a href="#SmearTrack:getEndcapTable">getEndcapTable</a>(o);
      }
    }

<b>    // get resolution values from interpolation and smear parameters</b>


    <a href="../ListOfTypes.html#float">float</a> ptInvDelta = par[<a href=".././SmearTrack.html#SmearTrack:ptI">ptI</a>]-&gt;interpolateVal(abscth,pTot,&amp;rc);
    <a href="../ListOfTypes.html#float">float</a> ptInvNew = ptInv + <a href=".././SmearTrack.html#SmearTrack:m_random">m_random</a>-&gt;<a href="http://root.cern.ch/root/html/TRandom.html#TRandom:Gaus">Gaus</a>(0.,ptInvDelta);
    <a href="../ListOfTypes.html#float">float</a> ptNew = fabs(1./ptInvNew);

    <a href="../ListOfTypes.html#float">float</a> lambdaDelta = par[<a href=".././SmearTrack.html#SmearTrack:lambdaI">lambdaI</a>]-&gt;interpolateVal(abscth,pTot,&amp;rc);
    <a href="../ListOfTypes.html#float">float</a> lambdaNew = lambda + <a href=".././SmearTrack.html#SmearTrack:m_random">m_random</a>-&gt;<a href="http://root.cern.ch/root/html/TRandom.html#TRandom:Gaus">Gaus</a>(0.,lambdaDelta);
    if (lambdaNew &lt; -<a href="http://root.cern.ch/root/html/TMath.html#TMath:Pi">TMath::Pi</a>()/2.) lambdaNew = -<a href="http://root.cern.ch/root/html/TMath.html#TMath:Pi">TMath::Pi</a>()/2.;
    if (lambdaNew &gt; <a href="http://root.cern.ch/root/html/TMath.html#TMath:Pi">TMath::Pi</a>()/2.) lambdaNew = <a href="http://root.cern.ch/root/html/TMath.html#TMath:Pi">TMath::Pi</a>()/2.;

    <a href="../ListOfTypes.html#float">float</a> rDelta = par[<a href=".././SmearTrack.html#SmearTrack:rI">rI</a>]-&gt;interpolateVal(abscth,pTot,&amp;rc);
    <a href="../ListOfTypes.html#float">float</a> rNew = r + <a href=".././SmearTrack.html#SmearTrack:m_random">m_random</a>-&gt;<a href="http://root.cern.ch/root/html/TRandom.html#TRandom:Gaus">Gaus</a>(0.,rDelta);

    <a href="../ListOfTypes.html#float">float</a> phiDelta = par[<a href=".././SmearTrack.html#SmearTrack:phiI">phiI</a>]-&gt;interpolateVal(abscth,pTot,&amp;rc);
    <a href="../ListOfTypes.html#float">float</a> phiNew = phi + <a href=".././SmearTrack.html#SmearTrack:m_random">m_random</a>-&gt;<a href="http://root.cern.ch/root/html/TRandom.html#TRandom:Gaus">Gaus</a>(0.,phiDelta);
    if (phiNew &lt; 0.) phiNew += 2.* <a href="http://root.cern.ch/root/html/TMath.html#TMath:Pi">TMath::Pi</a>();

    <a href="../ListOfTypes.html#float">float</a> zDelta = par[<a href=".././SmearTrack.html#SmearTrack:zI">zI</a>]-&gt;interpolateVal(abscth,pTot,&amp;rc);
    <a href="../ListOfTypes.html#float">float</a> zNew = xMC[2] + <a href=".././SmearTrack.html#SmearTrack:m_random">m_random</a>-&gt;<a href="http://root.cern.ch/root/html/TRandom.html#TRandom:Gaus">Gaus</a>(0.,zDelta);

<b>    // see if the charge sign has flipped</b>

    <a href="../ListOfTypes.html#float">float</a> newCharge = (ptInv * ptInvNew &lt; 0.) ? 
                        -p-&gt;GetCharge() : p-&gt;GetCharge();

    <a href="../ListOfTypes.html#float">float</a> thetaNew = <a href="http://root.cern.ch/root/html/TMath.html#TMath:Pi">TMath::Pi</a>()/2. - lambdaNew;
    <a href="../ListOfTypes.html#float">float</a> pNew = ptNew/sin(thetaNew);


<b>// get back to cartesian coordinates</b>

    <a href="../ListOfTypes.html#float">float</a> newP[3], newX[3];
    
    newP[0] = pNew * sin(thetaNew) * cos(phiNew);
    newP[1] = pNew * sin(thetaNew) * sin(phiNew);
    newP[2] = pNew * cos(thetaNew);

    newX[0] = rNew * cos(phiNew);
    newX[1] = rNew * sin(phiNew);
    newX[2] = zNew;

    <a href="http://root.cern.ch/root/html/Track.html">Track</a>* tk = new <a href="http://root.cern.ch/root/html/Track.html">Track</a>(&amp;newP[0],&amp;newX[0],newCharge,index);

    return tk;

}

<a name="SmearTrack:SmearTrack"> </a><a href=".././SmearTrack.html#SmearTrack:SmearTrack">SmearTrack::SmearTrack</a>(<a href="http://root.cern.ch/root/html/GetParameters.html">GetParameters</a>* gp){

<b>  // constructor: sets up lookups tables, etc.</b>

  <a href=".././SmearTrack.html#SmearTrack:m_random">m_random</a> = new <a href="http://root.cern.ch/root/html/TRandom.html">TRandom</a>();
  <a href=".././SmearTrack.html#SmearTrack:m_parameters">m_parameters</a> = gp;


  FILE* LTBFile;
  LTBFile = fopen(gp-&gt;getBarrelTableFile()-&gt;Data(),"r");


  <a href=".././GetTrackLookups.html">GetTrackLookups</a>* TkLookBarrel = new <a href=".././GetTrackLookups.html">GetTrackLookups</a>(LTBFile);
  <a href="http://root.cern.ch/root/html/TObjArray.html">TObjArray</a>* barrelArray = TkLookBarrel-&gt;getLookupsArray();

  <a href="../ListOfTypes.html#Int_t">Int_t</a> numPar = barrelArray-&gt;GetEntries();
  
  for (<a href="../ListOfTypes.html#int">int</a> i=0; i&lt;numPar ; i++) {
    <a href="http://root.cern.ch/root/html/TString.html">TString</a>* parName = ((<a href=".././LookUp2d.html">LookUp2d</a>*)barrelArray-&gt;At(i))-&gt;getName();
    if ( parName-&gt;CompareTo("lambda",<a href="http://root.cern.ch/root/html/TString.html#TString:kExact">TString::kExact</a>) == 0) {
      <a href=".././SmearTrack.html#SmearTrack:barrel_parNum">barrel_parNum</a>[<a href=".././SmearTrack.html#SmearTrack:lambdaI">lambdaI</a>] =((<a href=".././LookUp2d.html">LookUp2d</a>*)barrelArray-&gt;At(i));
    }
    else if ( parName-&gt;CompareTo("1/p_t",<a href="http://root.cern.ch/root/html/TString.html#TString:kExact">TString::kExact</a>) == 0) {
      <a href=".././SmearTrack.html#SmearTrack:barrel_parNum">barrel_parNum</a>[<a href=".././SmearTrack.html#SmearTrack:ptI">ptI</a>]=((<a href=".././LookUp2d.html">LookUp2d</a>*)barrelArray-&gt;At(i));
    }
    else if ( parName-&gt;CompareTo("phi",<a href="http://root.cern.ch/root/html/TString.html#TString:kExact">TString::kExact</a>) == 0) {
      <a href=".././SmearTrack.html#SmearTrack:barrel_parNum">barrel_parNum</a>[<a href=".././SmearTrack.html#SmearTrack:phiI">phiI</a>]=((<a href=".././LookUp2d.html">LookUp2d</a>*)barrelArray-&gt;At(i));
    }
    else if ( parName-&gt;CompareTo("z",<a href="http://root.cern.ch/root/html/TString.html#TString:kExact">TString::kExact</a>) == 0) {
      <a href=".././SmearTrack.html#SmearTrack:barrel_parNum">barrel_parNum</a>[<a href=".././SmearTrack.html#SmearTrack:zI">zI</a>]=((<a href=".././LookUp2d.html">LookUp2d</a>*)barrelArray-&gt;At(i));
    }
    else if ( parName-&gt;CompareTo("r",<a href="http://root.cern.ch/root/html/TString.html#TString:kExact">TString::kExact</a>) == 0) {
      <a href=".././SmearTrack.html#SmearTrack:barrel_parNum">barrel_parNum</a>[<a href=".././SmearTrack.html#SmearTrack:rI">rI</a>]=((<a href=".././LookUp2d.html">LookUp2d</a>*)barrelArray-&gt;At(i));
    }
    
  };

  printf("Barrel Smear parameters initialized n");
  
  if (!gp-&gt;getEndcapTableFile()-&gt;Contains("none")) {
    FILE* LTEFile;
    LTEFile = fopen(gp-&gt;getEndcapTableFile()-&gt;Data(),"r");
    
    <a href=".././GetTrackLookups.html">GetTrackLookups</a>* TkLookEndcap = new <a href=".././GetTrackLookups.html">GetTrackLookups</a>(LTEFile);
    <a href="http://root.cern.ch/root/html/TObjArray.html">TObjArray</a>* endcapArray = TkLookEndcap-&gt;getLookupsArray();
    
    for (<a href="../ListOfTypes.html#int">int</a> j=0; j&lt;numPar ; j++) {
      <a href="http://root.cern.ch/root/html/TString.html">TString</a>* parName = ((<a href=".././LookUp2d.html">LookUp2d</a>*)endcapArray-&gt;At(j))-&gt;getName();
      if ( parName-&gt;CompareTo("lambda",<a href="http://root.cern.ch/root/html/TString.html#TString:kExact">TString::kExact</a>) == 0) {
	<a href=".././SmearTrack.html#SmearTrack:endcap_parNum">endcap_parNum</a>[<a href=".././SmearTrack.html#SmearTrack:lambdaI">lambdaI</a>]=((<a href=".././LookUp2d.html">LookUp2d</a>*)endcapArray-&gt;At(j));
      }
      else if ( parName-&gt;CompareTo("1/p_t",<a href="http://root.cern.ch/root/html/TString.html#TString:kExact">TString::kExact</a>) == 0) {
	<a href=".././SmearTrack.html#SmearTrack:endcap_parNum">endcap_parNum</a>[<a href=".././SmearTrack.html#SmearTrack:ptI">ptI</a>]=((<a href=".././LookUp2d.html">LookUp2d</a>*)endcapArray-&gt;At(j));
      }
      else if ( parName-&gt;CompareTo("phi",<a href="http://root.cern.ch/root/html/TString.html#TString:kExact">TString::kExact</a>) == 0) {
	<a href=".././SmearTrack.html#SmearTrack:endcap_parNum">endcap_parNum</a>[<a href=".././SmearTrack.html#SmearTrack:phiI">phiI</a>]=((<a href=".././LookUp2d.html">LookUp2d</a>*)endcapArray-&gt;At(j));
      }
      else if ( parName-&gt;CompareTo("z",<a href="http://root.cern.ch/root/html/TString.html#TString:kExact">TString::kExact</a>) == 0) {
	<a href=".././SmearTrack.html#SmearTrack:endcap_parNum">endcap_parNum</a>[<a href=".././SmearTrack.html#SmearTrack:zI">zI</a>]=((<a href=".././LookUp2d.html">LookUp2d</a>*)endcapArray-&gt;At(j));
      }
      else if ( parName-&gt;CompareTo("r",<a href="http://root.cern.ch/root/html/TString.html#TString:kExact">TString::kExact</a>) == 0) {
	<a href=".././SmearTrack.html#SmearTrack:endcap_parNum">endcap_parNum</a>[<a href=".././SmearTrack.html#SmearTrack:rI">rI</a>]=((<a href=".././LookUp2d.html">LookUp2d</a>*)endcapArray-&gt;At(j));
      }
      
    }
    printf("Endcap Smear parameters initialized n");
  }

};

<a href="../ListOfTypes.html#int">int</a> <a href=".././SmearTrack.html#SmearTrack:lambdaI">SmearTrack::lambdaI</a>=0;
<a href="../ListOfTypes.html#int">int</a> <a href=".././SmearTrack.html#SmearTrack:ptI">SmearTrack::ptI</a> = 1;
<a href="../ListOfTypes.html#int">int</a> <a href=".././SmearTrack.html#SmearTrack:phiI">SmearTrack::phiI</a> =2;
<a href="../ListOfTypes.html#int">int</a> <a href=".././SmearTrack.html#SmearTrack:zI">SmearTrack::zI</a> = 3;
<a href="../ListOfTypes.html#int">int</a> <a href=".././SmearTrack.html#SmearTrack:rI">SmearTrack::rI</a> = 4;

</pre>

<!--SIGNATURE-->
<br>
<address>
<hr>
<center>
<a href="http://root.cern.ch/root/Welcome.html">ROOT page</a> - <a href="../ClassIndex.html">Class index</a> - <a href="#TopOfPage">Top of the page</a><br>
</center>
<hr>This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to <a href="mailto:rootdev@root.cern.ch">ROOT support</a>, or contact <a href="mailto:rootdev@root.cern.ch">the developers</a> with any questions or problems regarding ROOT.
</address>
</body>
</html>
