#include <TFile.h>
#include <TROOT.h>
#include <TMath.h>
#include "TH1.h"
#include "TGraphErrors.h"
#include "TObjArray.h"
#include "AliLog.h"
#include "AliTRDcalibDB.h"
#include "AliTRDgeometry.h"
#include "AliTRDCalTrkAttach.h"
ClassImp(AliTRDCalTrkAttach)
AliTRDCalTrkAttach::AliTRDCalTrkAttach()
:TNamed("AliTRDCalTrkAttach", "Calibration of AliTRDseedV1::AttachClusters")
,fRClikeLimit(0.65)
,fScaleCov(2.)
,fLike(NULL)
{
fNsgmDy[0] = 5; fNsgmDy[1] = 7;
fLikeMinRelDecrease[0] = .2; fLikeMinRelDecrease[1] = .3;
}
AliTRDCalTrkAttach::~AliTRDCalTrkAttach()
{
if(fLike) delete fLike;
}
Double_t AliTRDCalTrkAttach::CookLikelihood(Bool_t chg, Int_t ly, Float_t pt, Float_t phiTrk, Int_t n, Double_t dyr, Double_t dphi, Double_t sr) const
{
if(n<4){
AliDebug(4, Form("Failed basic cut[s] : n[%d] ...", n));
return 0.;
}
if (!fLike || fLike->GetEntries() != AliTRDgeometry::kNlayer*kNcharge*kNcalib) {
AliError("No usable AttachClusters calib object.");
return 0.;
}
Int_t offset(ly*kNcalib*kNcharge);
TGraphErrors *g(NULL);
if(!(g = (TGraphErrors*)fLike->At(offset+Int_t(kResPos)*kNcharge+Int_t(chg)))){
AliError("Failed retrieving AttachClusters graph.");
return 0.;
}
Int_t npts(g->GetN()), ip(0), jp(-1);
Double_t x0, y0, x1, y1, dd(0.), invdx(0.), f[4]={0., 0., 0., 0.};
for(Int_t kp(0); kp<npts; kp++){
g->GetPoint(kp, x1, y1);
if(x1>=pt){jp=kp; break;}
}
Bool_t boundary(kFALSE);
if(jp<0){
jp = npts-1;
g->GetPoint(jp, x1, y1);
ip = npts-1;
boundary = kTRUE;
}else if(jp==0){
ip = 0;
boundary = kTRUE;
}else{
ip = jp-1;
g->GetPoint(ip, x0, y0);
invdx = 1./(x0-x1);
}
Double_t dym = boundary?y1:((pt*(y0-y1) + (x0*y1-x1*y0))*invdx),
sym = 0.5*(g->GetErrorY(ip)+g->GetErrorY(jp));
dd = (dyr - dym)/sym; dd*=dd;
f[0] = TMath::Exp(-0.5*dd);
if(!(g = (TGraphErrors*)fLike->At(offset+Int_t(kResAng)*kNcharge+Int_t(chg)))){
AliError("Failed retrieving AttachClusters graph.");
return 0.;
}
g->GetPoint(ip, x0, y0);g->GetPoint(jp, x1, y1);
Double_t dpm = boundary?y1:((pt*(y0-y1) + (x0*y1-x1*y0))*invdx),
spm = 0.5*(g->GetErrorY(ip)+g->GetErrorY(jp));
dd = (dphi - dpm)/spm; dd*=dd;
f[1] = TMath::Exp(-0.5*dd);
if(!(g = (TGraphErrors*)fLike->At(offset+Int_t(kNclMean)*kNcharge+Int_t(chg)))){
AliError("Failed retrieving AttachClusters graph.");
return 0.;
}
g->GetPoint(ip, x0, y0);g->GetPoint(jp, x1, y1);
Double_t nm = boundary?y1:((pt*(y0-y1) + (x0*y1-x1*y0))*invdx);
f[2] = (nm-TMath::Abs(n-nm))/nm;
if(!(g = (TGraphErrors*)fLike->At(offset+Int_t(kSigma)*kNcharge+Int_t(chg)))){
AliError("Failed retrieving AttachClusters graph.");
return 0.;
}
npts=g->GetN(); jp=-1;
for(Int_t kp(0); kp<npts; kp++){
g->GetPoint(kp, x1, y1);
if(x1>=phiTrk){jp=kp; break;}
}
if(jp<0){
jp = npts-1;
g->GetPoint(jp, x1, y1);
ip = jp;
boundary = kTRUE;
}else if(jp==0){
ip = jp;
boundary = kTRUE;
}else{
ip = jp-1;
g->GetPoint(ip, x0, y0);
invdx = 1./(x0-x1);
boundary = kFALSE;
}
Double_t sm = boundary?y1:((phiTrk*(y0-y1) + (x0*y1-x1*y0))*invdx),
ssm = 0.5*(g->GetErrorY(ip)+g->GetErrorY(jp));
dd = (sr - sm)/ssm; dd*=dd;
f[3] = 1.;
Double_t length = f[0]*f[0]+f[1]*f[1]+f[2]*f[2]+f[3]*f[3];
length = TMath::Sqrt(length);
Double_t cosTht = f[0]+f[1]+f[2]+f[3];
cosTht /= (4.*length);
AliDebug(2, Form("Like[%5.3f] ThtLike[%6.2f](deg)\n"
" F_dy (%+6.2f)=%4.2f\n"
" F_phi(%+6.2f)=%4.2f\n"
" F_ncl(%+6d)=%4.2f\n"
" F_<s>(%+6.2f)=%4.2f",
length, TMath::ACos(cosTht)*TMath::RadToDeg(),
dyr, f[0], dphi, f[1], n, f[2], sr, f[3]));
return length;
}
void AliTRDCalTrkAttach::Help()
{
printf(
"Draw likelihood distribution. Possible options are of the form \"lt\"\n"
"where \"l\" is the layer number [0-5] and\n"
" \"t\" is the type. This is one of the following\n"
" \"y\" - r-phi roads\n"
" \"p\" - angular (deflection) roads\n"
" \"n\" - number of clusters\n"
" \"s\" - cluster spread\n");
}
void AliTRDCalTrkAttach::Draw(Option_t* opt)
{
if (!fLike || fLike->GetEntries() != AliTRDgeometry::kNlayer*kNcharge*kNcalib) {
AliError("No likelihood distributions stored");
return;
}
if(!opt){
Help();
return;
}
Int_t ly(-1); Char_t cly[] = {'0','1','2','3','4','5'};
for(Int_t ily(0); ily<AliTRDgeometry::kNlayer; ily++){
if(opt[0] == cly[ily]){
ly = ily; break;
}
}
if(ly<0){
Help();
return;
}
Int_t typ(-1); const Char_t ctyp[] = {'y', 'p', 's', 'n'};
for(Int_t it(0); it<kNcalib; it++){
if(opt[1] == ctyp[it]){
typ = it; break;
}
}
if(typ<0){
Help();
return;
}
Int_t offset(ly*kNcalib*kNcharge+typ*kNcharge);
TGraphErrors *g[2]={(TGraphErrors*)fLike->At(offset), (TGraphErrors*)fLike->At(offset+1)};
if(!g[0] || !g[1]){
AliError(Form("Failed retrieving graphs for Ly[%d] Typ[%c]", ly, ctyp[typ]));
return;
}
const Char_t *ttyp[] = {"#Deltay [cm]", "#Delta#phi [deg]", "#Delta#sigma/<#sigma>", "n_{cl}^{tracklet}"};
g[0]->Draw("apl"); g[0]->SetLineColor(kBlue); g[0]->SetMarkerColor(kBlue);
g[1]->Draw("pl"); g[1]->SetLineColor(kRed); g[1]->SetMarkerColor(kRed);
TH1 *h=g[0]->GetHistogram();
h->GetYaxis()->SetTitle(ttyp[typ]);
h->GetYaxis()->SetLabelFont(52);
h->GetYaxis()->SetTitleFont(62);
h->GetXaxis()->SetTitle("p_{t} [GeV/c]");
h->GetXaxis()->SetLabelFont(52);
h->GetXaxis()->SetTitleFont(62);
}
Bool_t AliTRDCalTrkAttach::LoadReferences(const Char_t *file)
{
if(!file || !TFile::Open(file)){
AliError("Parametrization file missing or unreadable.");
return kFALSE;
}
TGraphErrors *g(NULL);
Char_t co[kNcalib] = {'y', 'p', 's', 'n'},
cs[2] = {'n', 'p'};
if(fLike) fLike->Clear();
else fLike = new TObjArray(AliTRDgeometry::kNlayer*kNcharge*kNcalib);
for(Int_t ily(0); ily<AliTRDgeometry::kNlayer; ily++){
for(Int_t icalib(0); icalib<kNcalib; icalib++){
for(Int_t isgn(0); isgn<kNcharge; isgn++){
if(!(g = (TGraphErrors*)gFile->Get(Form("%c%c%d", co[icalib], cs[isgn], ily)))) return kFALSE;
fLike->AddAt(g, kNcharge*(ily*kNcalib+icalib)+isgn);
}
}
}
return kTRUE;
}
AliTRDCalTrkAttach.cxx:10 AliTRDCalTrkAttach.cxx:11 AliTRDCalTrkAttach.cxx:12 AliTRDCalTrkAttach.cxx:13 AliTRDCalTrkAttach.cxx:14 AliTRDCalTrkAttach.cxx:15 AliTRDCalTrkAttach.cxx:16 AliTRDCalTrkAttach.cxx:17 AliTRDCalTrkAttach.cxx:18 AliTRDCalTrkAttach.cxx:19 AliTRDCalTrkAttach.cxx:20 AliTRDCalTrkAttach.cxx:21 AliTRDCalTrkAttach.cxx:22 AliTRDCalTrkAttach.cxx:23 AliTRDCalTrkAttach.cxx:24 AliTRDCalTrkAttach.cxx:25 AliTRDCalTrkAttach.cxx:26 AliTRDCalTrkAttach.cxx:27 AliTRDCalTrkAttach.cxx:28 AliTRDCalTrkAttach.cxx:29 AliTRDCalTrkAttach.cxx:30 AliTRDCalTrkAttach.cxx:31 AliTRDCalTrkAttach.cxx:32 AliTRDCalTrkAttach.cxx:33 AliTRDCalTrkAttach.cxx:34 AliTRDCalTrkAttach.cxx:35 AliTRDCalTrkAttach.cxx:36 AliTRDCalTrkAttach.cxx:37 AliTRDCalTrkAttach.cxx:38 AliTRDCalTrkAttach.cxx:39 AliTRDCalTrkAttach.cxx:40 AliTRDCalTrkAttach.cxx:41 AliTRDCalTrkAttach.cxx:42 AliTRDCalTrkAttach.cxx:43 AliTRDCalTrkAttach.cxx:44 AliTRDCalTrkAttach.cxx:45 AliTRDCalTrkAttach.cxx:46 AliTRDCalTrkAttach.cxx:47 AliTRDCalTrkAttach.cxx:48 AliTRDCalTrkAttach.cxx:49 AliTRDCalTrkAttach.cxx:50 AliTRDCalTrkAttach.cxx:51 AliTRDCalTrkAttach.cxx:52 AliTRDCalTrkAttach.cxx:53 AliTRDCalTrkAttach.cxx:54 AliTRDCalTrkAttach.cxx:55 AliTRDCalTrkAttach.cxx:56 AliTRDCalTrkAttach.cxx:57 AliTRDCalTrkAttach.cxx:58 AliTRDCalTrkAttach.cxx:59 AliTRDCalTrkAttach.cxx:60 AliTRDCalTrkAttach.cxx:61 AliTRDCalTrkAttach.cxx:62 AliTRDCalTrkAttach.cxx:63 AliTRDCalTrkAttach.cxx:64 AliTRDCalTrkAttach.cxx:65 AliTRDCalTrkAttach.cxx:66 AliTRDCalTrkAttach.cxx:67 AliTRDCalTrkAttach.cxx:68 AliTRDCalTrkAttach.cxx:69 AliTRDCalTrkAttach.cxx:70 AliTRDCalTrkAttach.cxx:71 AliTRDCalTrkAttach.cxx:72 AliTRDCalTrkAttach.cxx:73 AliTRDCalTrkAttach.cxx:74 AliTRDCalTrkAttach.cxx:75 AliTRDCalTrkAttach.cxx:76 AliTRDCalTrkAttach.cxx:77 AliTRDCalTrkAttach.cxx:78 AliTRDCalTrkAttach.cxx:79 AliTRDCalTrkAttach.cxx:80 AliTRDCalTrkAttach.cxx:81 AliTRDCalTrkAttach.cxx:82 AliTRDCalTrkAttach.cxx:83 AliTRDCalTrkAttach.cxx:84 AliTRDCalTrkAttach.cxx:85 AliTRDCalTrkAttach.cxx:86 AliTRDCalTrkAttach.cxx:87 AliTRDCalTrkAttach.cxx:88 AliTRDCalTrkAttach.cxx:89 AliTRDCalTrkAttach.cxx:90 AliTRDCalTrkAttach.cxx:91 AliTRDCalTrkAttach.cxx:92 AliTRDCalTrkAttach.cxx:93 AliTRDCalTrkAttach.cxx:94 AliTRDCalTrkAttach.cxx:95 AliTRDCalTrkAttach.cxx:96 AliTRDCalTrkAttach.cxx:97 AliTRDCalTrkAttach.cxx:98 AliTRDCalTrkAttach.cxx:99 AliTRDCalTrkAttach.cxx:100 AliTRDCalTrkAttach.cxx:101 AliTRDCalTrkAttach.cxx:102 AliTRDCalTrkAttach.cxx:103 AliTRDCalTrkAttach.cxx:104 AliTRDCalTrkAttach.cxx:105 AliTRDCalTrkAttach.cxx:106 AliTRDCalTrkAttach.cxx:107 AliTRDCalTrkAttach.cxx:108 AliTRDCalTrkAttach.cxx:109 AliTRDCalTrkAttach.cxx:110 AliTRDCalTrkAttach.cxx:111 AliTRDCalTrkAttach.cxx:112 AliTRDCalTrkAttach.cxx:113 AliTRDCalTrkAttach.cxx:114 AliTRDCalTrkAttach.cxx:115 AliTRDCalTrkAttach.cxx:116 AliTRDCalTrkAttach.cxx:117 AliTRDCalTrkAttach.cxx:118 AliTRDCalTrkAttach.cxx:119 AliTRDCalTrkAttach.cxx:120 AliTRDCalTrkAttach.cxx:121 AliTRDCalTrkAttach.cxx:122 AliTRDCalTrkAttach.cxx:123 AliTRDCalTrkAttach.cxx:124 AliTRDCalTrkAttach.cxx:125 AliTRDCalTrkAttach.cxx:126 AliTRDCalTrkAttach.cxx:127 AliTRDCalTrkAttach.cxx:128 AliTRDCalTrkAttach.cxx:129 AliTRDCalTrkAttach.cxx:130 AliTRDCalTrkAttach.cxx:131 AliTRDCalTrkAttach.cxx:132 AliTRDCalTrkAttach.cxx:133 AliTRDCalTrkAttach.cxx:134 AliTRDCalTrkAttach.cxx:135 AliTRDCalTrkAttach.cxx:136 AliTRDCalTrkAttach.cxx:137 AliTRDCalTrkAttach.cxx:138 AliTRDCalTrkAttach.cxx:139 AliTRDCalTrkAttach.cxx:140 AliTRDCalTrkAttach.cxx:141 AliTRDCalTrkAttach.cxx:142 AliTRDCalTrkAttach.cxx:143 AliTRDCalTrkAttach.cxx:144 AliTRDCalTrkAttach.cxx:145 AliTRDCalTrkAttach.cxx:146 AliTRDCalTrkAttach.cxx:147 AliTRDCalTrkAttach.cxx:148 AliTRDCalTrkAttach.cxx:149 AliTRDCalTrkAttach.cxx:150 AliTRDCalTrkAttach.cxx:151 AliTRDCalTrkAttach.cxx:152 AliTRDCalTrkAttach.cxx:153 AliTRDCalTrkAttach.cxx:154 AliTRDCalTrkAttach.cxx:155 AliTRDCalTrkAttach.cxx:156 AliTRDCalTrkAttach.cxx:157 AliTRDCalTrkAttach.cxx:158 AliTRDCalTrkAttach.cxx:159 AliTRDCalTrkAttach.cxx:160 AliTRDCalTrkAttach.cxx:161 AliTRDCalTrkAttach.cxx:162 AliTRDCalTrkAttach.cxx:163 AliTRDCalTrkAttach.cxx:164 AliTRDCalTrkAttach.cxx:165 AliTRDCalTrkAttach.cxx:166 AliTRDCalTrkAttach.cxx:167 AliTRDCalTrkAttach.cxx:168 AliTRDCalTrkAttach.cxx:169 AliTRDCalTrkAttach.cxx:170 AliTRDCalTrkAttach.cxx:171 AliTRDCalTrkAttach.cxx:172 AliTRDCalTrkAttach.cxx:173 AliTRDCalTrkAttach.cxx:174 AliTRDCalTrkAttach.cxx:175 AliTRDCalTrkAttach.cxx:176 AliTRDCalTrkAttach.cxx:177 AliTRDCalTrkAttach.cxx:178 AliTRDCalTrkAttach.cxx:179 AliTRDCalTrkAttach.cxx:180 AliTRDCalTrkAttach.cxx:181 AliTRDCalTrkAttach.cxx:182 AliTRDCalTrkAttach.cxx:183 AliTRDCalTrkAttach.cxx:184 AliTRDCalTrkAttach.cxx:185 AliTRDCalTrkAttach.cxx:186 AliTRDCalTrkAttach.cxx:187 AliTRDCalTrkAttach.cxx:188 AliTRDCalTrkAttach.cxx:189 AliTRDCalTrkAttach.cxx:190 AliTRDCalTrkAttach.cxx:191 AliTRDCalTrkAttach.cxx:192 AliTRDCalTrkAttach.cxx:193 AliTRDCalTrkAttach.cxx:194 AliTRDCalTrkAttach.cxx:195 AliTRDCalTrkAttach.cxx:196 AliTRDCalTrkAttach.cxx:197 AliTRDCalTrkAttach.cxx:198 AliTRDCalTrkAttach.cxx:199 AliTRDCalTrkAttach.cxx:200 AliTRDCalTrkAttach.cxx:201 AliTRDCalTrkAttach.cxx:202 AliTRDCalTrkAttach.cxx:203 AliTRDCalTrkAttach.cxx:204 AliTRDCalTrkAttach.cxx:205 AliTRDCalTrkAttach.cxx:206 AliTRDCalTrkAttach.cxx:207 AliTRDCalTrkAttach.cxx:208 AliTRDCalTrkAttach.cxx:209 AliTRDCalTrkAttach.cxx:210 AliTRDCalTrkAttach.cxx:211 AliTRDCalTrkAttach.cxx:212 AliTRDCalTrkAttach.cxx:213 AliTRDCalTrkAttach.cxx:214 AliTRDCalTrkAttach.cxx:215 AliTRDCalTrkAttach.cxx:216 AliTRDCalTrkAttach.cxx:217 AliTRDCalTrkAttach.cxx:218 AliTRDCalTrkAttach.cxx:219 AliTRDCalTrkAttach.cxx:220 AliTRDCalTrkAttach.cxx:221 AliTRDCalTrkAttach.cxx:222 AliTRDCalTrkAttach.cxx:223 AliTRDCalTrkAttach.cxx:224 AliTRDCalTrkAttach.cxx:225 AliTRDCalTrkAttach.cxx:226 AliTRDCalTrkAttach.cxx:227 AliTRDCalTrkAttach.cxx:228 AliTRDCalTrkAttach.cxx:229 AliTRDCalTrkAttach.cxx:230 AliTRDCalTrkAttach.cxx:231 AliTRDCalTrkAttach.cxx:232 AliTRDCalTrkAttach.cxx:233 AliTRDCalTrkAttach.cxx:234 AliTRDCalTrkAttach.cxx:235 AliTRDCalTrkAttach.cxx:236 AliTRDCalTrkAttach.cxx:237 AliTRDCalTrkAttach.cxx:238 AliTRDCalTrkAttach.cxx:239 AliTRDCalTrkAttach.cxx:240 AliTRDCalTrkAttach.cxx:241 AliTRDCalTrkAttach.cxx:242 AliTRDCalTrkAttach.cxx:243 AliTRDCalTrkAttach.cxx:244 AliTRDCalTrkAttach.cxx:245 AliTRDCalTrkAttach.cxx:246 AliTRDCalTrkAttach.cxx:247 AliTRDCalTrkAttach.cxx:248 AliTRDCalTrkAttach.cxx:249 AliTRDCalTrkAttach.cxx:250 AliTRDCalTrkAttach.cxx:251 AliTRDCalTrkAttach.cxx:252 AliTRDCalTrkAttach.cxx:253 AliTRDCalTrkAttach.cxx:254 AliTRDCalTrkAttach.cxx:255 AliTRDCalTrkAttach.cxx:256 AliTRDCalTrkAttach.cxx:257 AliTRDCalTrkAttach.cxx:258 AliTRDCalTrkAttach.cxx:259 AliTRDCalTrkAttach.cxx:260 AliTRDCalTrkAttach.cxx:261 AliTRDCalTrkAttach.cxx:262 AliTRDCalTrkAttach.cxx:263 AliTRDCalTrkAttach.cxx:264 AliTRDCalTrkAttach.cxx:265 AliTRDCalTrkAttach.cxx:266 AliTRDCalTrkAttach.cxx:267 AliTRDCalTrkAttach.cxx:268 AliTRDCalTrkAttach.cxx:269 AliTRDCalTrkAttach.cxx:270 AliTRDCalTrkAttach.cxx:271 AliTRDCalTrkAttach.cxx:272 AliTRDCalTrkAttach.cxx:273 AliTRDCalTrkAttach.cxx:274 AliTRDCalTrkAttach.cxx:275