ROOT logo
/**************************************************************************
 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
 *                                                                        *
 * Author: The ALICE Off-line Project.                                    *
 * Contributors are mentioned in the code where appropriate.              *
 *                                                                        *
 * Permission to use, copy, modify and distribute this software and its   *
 * documentation strictly for non-commercial purposes is hereby granted   *
 * without fee, provided that the above copyright notice appears in all   *
 * copies and that both the copyright notice and this permission notice   *
 * appear in the supporting documentation. The authors make no claims     *
 * about the suitability of this software for any purpose. It is          *
 * provided "as is" without express or implied warranty.                  *
 **************************************************************************/

/* $Id: */

// Implementation of AliFastResponse for the Muon Spectrometer resolution.
// The response depends on the charge of the muon and
// the background level.
// The class uses the instance of an object of type AliMUONFastTracking to 
// obtain the smearing parameters.
// Author: andreas.morsch@cern.ch

#include "AliFastMuonTrackingRes.h"
#include "AliMUONFastTracking.h"
#include <TRandom.h>
#include <TF1.h>

ClassImp(AliFastMuonTrackingRes)


AliFastMuonTrackingRes::AliFastMuonTrackingRes() :
    AliFastResponse("Resolution", "Muon Tracking Resolution"),
    fBackground(0.),
    fCharge(1.),
    fFastTracking(0)
{
// Default constructor
}

AliFastMuonTrackingRes::AliFastMuonTrackingRes(const AliFastMuonTrackingRes & res)
    :AliFastResponse(res),
    fBackground(0.),
    fCharge(1.),
    fFastTracking(0)
{
// Copy constructor
    res.Copy(*this);
}

void AliFastMuonTrackingRes::Init()
{
// Initialisation
    fFastTracking = AliMUONFastTracking::Instance();
    fFastTracking->Init(fBackground);
}



void AliFastMuonTrackingRes::Evaluate(Float_t   p,  Float_t  theta , Float_t   phi,
					 Float_t& pS,  Float_t& thetaS, Float_t&  phiS)
{
//
// Evaluate Gaussian smearing from given kinematics 
//

    Double_t meanp    = fFastTracking->MeanP  (p, theta, phi, Int_t(fCharge));
    Double_t sigmap   = fFastTracking->SigmaP (p, theta, phi, Int_t(fCharge));
    Double_t sigma1p  = fFastTracking->Sigma1P(p, theta, phi, Int_t(fCharge));
    Double_t normg2   = fFastTracking->NormG2 (p, theta, phi, Int_t(fCharge));
    Double_t meang2   = fFastTracking->MeanG2 (p, theta, phi, Int_t(fCharge));
    Double_t sigmag2  = fFastTracking->SigmaG2(p, theta, phi, Int_t(fCharge));
    
    Int_t ip,itheta,iphi;
    fFastTracking->GetIpIthetaIphi(p, theta, phi, Int_t(fCharge), ip, itheta, iphi);
    TF1* fitp = fFastTracking->GetFitP(ip,itheta,iphi);
    
    Float_t curmeanp   = fitp->GetParameter(0); 
    Float_t cursigmap  = fitp->GetParameter(1); 
    Float_t cursigma1p = fitp->GetParameter(2); 
    Float_t curnormg2  = fitp->GetParameter(3); 
    Float_t curmeang2  = fitp->GetParameter(4); 
    Float_t cursigmag2 = fitp->GetParameter(5); 
    if (curmeanp != meanp || cursigmap != sigmap || cursigma1p != sigma1p || 
	curnormg2 != normg2 || curmeang2 != meang2 || cursigmag2 != sigmag2){ 
      printf ("Setting new parameters for ip=%d itheta=%d iphi=%d\n",ip,itheta,iphi); 
      fitp->SetParameters(meanp,sigmap,sigma1p,normg2,meang2,sigmag2);
    }
  
    Double_t meantheta  = fFastTracking->MeanTheta (p, theta, phi, Int_t(fCharge));
    Double_t sigmatheta = fFastTracking->SigmaTheta(p, theta, phi, Int_t(fCharge));
    Double_t meanphi    = fFastTracking->MeanPhi   (p, theta, phi, Int_t(fCharge));
    Double_t sigmaphi   = fFastTracking->SigmaPhi  (p, theta, phi, Int_t(fCharge));
    
    if (sigmatheta<0 || sigmaphi<0) 
      printf ("bin %d %d %d sigmatheta = %f, sigmaphi = %f\n",
	      ip,itheta,iphi,sigmatheta,sigmaphi);
    // Components different from ip=0 have the RMS bigger than mean
    Float_t ptp[3]  =  { 1.219576,-0.354764,-0.690117 };
    Float_t ptph[3] =  { 0.977522, 0.016269, 0.023158 }; 
    Float_t pphp[3] =  { 1.303256,-0.464847,-0.869322 };

    // Smeared momentum
    pS = -1.;
    //    Float_t dpmax = 5. + ip * 2.5; 
    //    Float_t dpmax = 5. + ip * 2; 
    Float_t dpmax;
    if (sigmag2<999.) dpmax = 5. * TMath::Abs(sigmap + sigmag2); 
    else dpmax = 5. * TMath::Abs(sigmap);
    Float_t dp = 100;
    while (pS<0 || TMath::Abs(dp)>dpmax) { 
      pS = p + fitp->GetRandom();
      dp = pS - p; 
    }
    // Smeared phi
    Float_t sigmaphiold=sigmaphi;
    if (ip==0) sigmaphi *= pphp[0] + pphp[1] * dp + pphp[2] * dp*dp; 
    if (sigmaphi<0.5 * sigmaphiold) sigmaphi = 0.5 * sigmaphiold;
    if (sigmaphi>2.  * sigmaphiold) sigmaphi = 2.  * sigmaphiold;
    phiS = phi + gRandom->Gaus(meanphi, sigmaphi);
    Float_t dphi = phiS - phi; 
    // Smeared theta
    Float_t sigmathetaold=sigmatheta;
    if (ip==0) sigmatheta *= ptp[0] + ptp[1] * dp + ptp[2] * dp*dp; 
    if (ip==0) sigmatheta *= ptph[0] + ptph[1] * dphi + ptph[2] * dphi*dphi; 
    if (sigmatheta<0.5 * sigmathetaold) sigmatheta = 0.5 * sigmathetaold;
    if (sigmatheta>2.  * sigmathetaold) sigmatheta = 2.  * sigmathetaold;
    thetaS = theta + gRandom->Gaus(meantheta,sigmatheta);
}

AliFastMuonTrackingRes& AliFastMuonTrackingRes::operator=(const  AliFastMuonTrackingRes& rhs)
{
// Assignment operator
    rhs.Copy(*this);
    return *this;
}




 AliFastMuonTrackingRes.cxx:1
 AliFastMuonTrackingRes.cxx:2
 AliFastMuonTrackingRes.cxx:3
 AliFastMuonTrackingRes.cxx:4
 AliFastMuonTrackingRes.cxx:5
 AliFastMuonTrackingRes.cxx:6
 AliFastMuonTrackingRes.cxx:7
 AliFastMuonTrackingRes.cxx:8
 AliFastMuonTrackingRes.cxx:9
 AliFastMuonTrackingRes.cxx:10
 AliFastMuonTrackingRes.cxx:11
 AliFastMuonTrackingRes.cxx:12
 AliFastMuonTrackingRes.cxx:13
 AliFastMuonTrackingRes.cxx:14
 AliFastMuonTrackingRes.cxx:15
 AliFastMuonTrackingRes.cxx:16
 AliFastMuonTrackingRes.cxx:17
 AliFastMuonTrackingRes.cxx:18
 AliFastMuonTrackingRes.cxx:19
 AliFastMuonTrackingRes.cxx:20
 AliFastMuonTrackingRes.cxx:21
 AliFastMuonTrackingRes.cxx:22
 AliFastMuonTrackingRes.cxx:23
 AliFastMuonTrackingRes.cxx:24
 AliFastMuonTrackingRes.cxx:25
 AliFastMuonTrackingRes.cxx:26
 AliFastMuonTrackingRes.cxx:27
 AliFastMuonTrackingRes.cxx:28
 AliFastMuonTrackingRes.cxx:29
 AliFastMuonTrackingRes.cxx:30
 AliFastMuonTrackingRes.cxx:31
 AliFastMuonTrackingRes.cxx:32
 AliFastMuonTrackingRes.cxx:33
 AliFastMuonTrackingRes.cxx:34
 AliFastMuonTrackingRes.cxx:35
 AliFastMuonTrackingRes.cxx:36
 AliFastMuonTrackingRes.cxx:37
 AliFastMuonTrackingRes.cxx:38
 AliFastMuonTrackingRes.cxx:39
 AliFastMuonTrackingRes.cxx:40
 AliFastMuonTrackingRes.cxx:41
 AliFastMuonTrackingRes.cxx:42
 AliFastMuonTrackingRes.cxx:43
 AliFastMuonTrackingRes.cxx:44
 AliFastMuonTrackingRes.cxx:45
 AliFastMuonTrackingRes.cxx:46
 AliFastMuonTrackingRes.cxx:47
 AliFastMuonTrackingRes.cxx:48
 AliFastMuonTrackingRes.cxx:49
 AliFastMuonTrackingRes.cxx:50
 AliFastMuonTrackingRes.cxx:51
 AliFastMuonTrackingRes.cxx:52
 AliFastMuonTrackingRes.cxx:53
 AliFastMuonTrackingRes.cxx:54
 AliFastMuonTrackingRes.cxx:55
 AliFastMuonTrackingRes.cxx:56
 AliFastMuonTrackingRes.cxx:57
 AliFastMuonTrackingRes.cxx:58
 AliFastMuonTrackingRes.cxx:59
 AliFastMuonTrackingRes.cxx:60
 AliFastMuonTrackingRes.cxx:61
 AliFastMuonTrackingRes.cxx:62
 AliFastMuonTrackingRes.cxx:63
 AliFastMuonTrackingRes.cxx:64
 AliFastMuonTrackingRes.cxx:65
 AliFastMuonTrackingRes.cxx:66
 AliFastMuonTrackingRes.cxx:67
 AliFastMuonTrackingRes.cxx:68
 AliFastMuonTrackingRes.cxx:69
 AliFastMuonTrackingRes.cxx:70
 AliFastMuonTrackingRes.cxx:71
 AliFastMuonTrackingRes.cxx:72
 AliFastMuonTrackingRes.cxx:73
 AliFastMuonTrackingRes.cxx:74
 AliFastMuonTrackingRes.cxx:75
 AliFastMuonTrackingRes.cxx:76
 AliFastMuonTrackingRes.cxx:77
 AliFastMuonTrackingRes.cxx:78
 AliFastMuonTrackingRes.cxx:79
 AliFastMuonTrackingRes.cxx:80
 AliFastMuonTrackingRes.cxx:81
 AliFastMuonTrackingRes.cxx:82
 AliFastMuonTrackingRes.cxx:83
 AliFastMuonTrackingRes.cxx:84
 AliFastMuonTrackingRes.cxx:85
 AliFastMuonTrackingRes.cxx:86
 AliFastMuonTrackingRes.cxx:87
 AliFastMuonTrackingRes.cxx:88
 AliFastMuonTrackingRes.cxx:89
 AliFastMuonTrackingRes.cxx:90
 AliFastMuonTrackingRes.cxx:91
 AliFastMuonTrackingRes.cxx:92
 AliFastMuonTrackingRes.cxx:93
 AliFastMuonTrackingRes.cxx:94
 AliFastMuonTrackingRes.cxx:95
 AliFastMuonTrackingRes.cxx:96
 AliFastMuonTrackingRes.cxx:97
 AliFastMuonTrackingRes.cxx:98
 AliFastMuonTrackingRes.cxx:99
 AliFastMuonTrackingRes.cxx:100
 AliFastMuonTrackingRes.cxx:101
 AliFastMuonTrackingRes.cxx:102
 AliFastMuonTrackingRes.cxx:103
 AliFastMuonTrackingRes.cxx:104
 AliFastMuonTrackingRes.cxx:105
 AliFastMuonTrackingRes.cxx:106
 AliFastMuonTrackingRes.cxx:107
 AliFastMuonTrackingRes.cxx:108
 AliFastMuonTrackingRes.cxx:109
 AliFastMuonTrackingRes.cxx:110
 AliFastMuonTrackingRes.cxx:111
 AliFastMuonTrackingRes.cxx:112
 AliFastMuonTrackingRes.cxx:113
 AliFastMuonTrackingRes.cxx:114
 AliFastMuonTrackingRes.cxx:115
 AliFastMuonTrackingRes.cxx:116
 AliFastMuonTrackingRes.cxx:117
 AliFastMuonTrackingRes.cxx:118
 AliFastMuonTrackingRes.cxx:119
 AliFastMuonTrackingRes.cxx:120
 AliFastMuonTrackingRes.cxx:121
 AliFastMuonTrackingRes.cxx:122
 AliFastMuonTrackingRes.cxx:123
 AliFastMuonTrackingRes.cxx:124
 AliFastMuonTrackingRes.cxx:125
 AliFastMuonTrackingRes.cxx:126
 AliFastMuonTrackingRes.cxx:127
 AliFastMuonTrackingRes.cxx:128
 AliFastMuonTrackingRes.cxx:129
 AliFastMuonTrackingRes.cxx:130
 AliFastMuonTrackingRes.cxx:131
 AliFastMuonTrackingRes.cxx:132
 AliFastMuonTrackingRes.cxx:133
 AliFastMuonTrackingRes.cxx:134
 AliFastMuonTrackingRes.cxx:135
 AliFastMuonTrackingRes.cxx:136
 AliFastMuonTrackingRes.cxx:137
 AliFastMuonTrackingRes.cxx:138
 AliFastMuonTrackingRes.cxx:139
 AliFastMuonTrackingRes.cxx:140
 AliFastMuonTrackingRes.cxx:141