Compiler warnings and coding conventions
[u/mrichter/AliRoot.git] / HMPID / AliHMPIDReconHTA.cxx
CommitLineData
5a3482a0 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
16//////////////////////////////////////////////////////////////////////////
17// //
18// AliHMPIDReconHTA //
19// //
20// HMPID class to perfom pattern recognition based on Hough transfrom //
21// for single chamber //
22//////////////////////////////////////////////////////////////////////////
23
24#include "AliHMPIDReconHTA.h"//class header
25#include "AliHMPIDCluster.h" //CkovHiddenTrk()
26#include "AliHMPIDRecon.h" //FunMinPhot()
9785d5fb 27#include <TFile.h> //Database()
5a3482a0 28#include <TMinuit.h> //FitFree()
29#include <TClonesArray.h> //CkovHiddenTrk()
30#include <AliESDtrack.h> //CkovHiddenTrk()
9785d5fb 31#include <TH2F.h> //InitDatabase()
5a3482a0 32#include <TGraph.h> //ShapeModel()
5a3482a0 33#include <TSpline.h> //ShapeModel()
34#include "TStopwatch.h" //
35
5565f017 36TH2F* AliHMPIDReconHTA::fgDatabase = 0x0;
9785d5fb 37
5a3482a0 38
39//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
c61a7285 40AliHMPIDReconHTA::AliHMPIDReconHTA():
41 TTask("RichRec","RichPat"),
42 fMipX(-999),
43 fMipY(-999),
44 fMipQ(-999),
45 fRadX(-999),
46 fRadY(-999),
47 fIdxMip(0),
48 fNClu(0),
49 fXClu(0),
50 fYClu(0),
51 fClCk(0),
52 fThTrkFit(-999),
53 fPhTrkFit(-999),
54 fCkovFit(-999),
55 fCkovSig2(0),
56 fParam(AliHMPIDParam::Instance())
5a3482a0 57{
58//..
59//hidden algorithm
60//..
5a3482a0 61 fParam->SetRefIdx(fParam->MeanIdxRad()); // initialization of ref index to a default one
5565f017 62 InitDatabase();
5a3482a0 63}
64//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
65AliHMPIDReconHTA::~AliHMPIDReconHTA()
66{
67 DeleteVars();
68}
69//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
70void AliHMPIDReconHTA::InitVars(Int_t n)
71{
72//..
73//Init some variables
74//..
75 fXClu = new Double_t[n];
76 fYClu = new Double_t[n];
77 fClCk = new Bool_t[n];
78 for(Int_t i=0;i<n;i++) fClCk[i] = kTRUE;
79//
80}
81//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
aa00f952 82void AliHMPIDReconHTA::DeleteVars()const
5a3482a0 83{
84//..
85//Delete variables
86//..
87 if(fXClu) delete fXClu;
88 if(fYClu) delete fYClu;
89 if(fClCk) delete fClCk;
90}
91//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
9785d5fb 92Bool_t AliHMPIDReconHTA::CkovHiddenTrk(AliESDtrack *pTrk,TClonesArray *pCluLst,Int_t index, Double_t nmean)
5a3482a0 93{
94// Pattern recognition method without any infos from tracking:HTA (Hidden Track Algorithm)...
95// The method finds in the chmuber the cluster with the highest charge
96// compatibile with a MIP, then the strategy is applied
97// Arguments: pTrk - pointer to ESD track
98// pCluLs - list of clusters for a given chamber
9785d5fb 99// pNmean - pointer to ref. index
100// pQthre - pointer to qthre
5a3482a0 101// Returns: - 0=ok,1=not fitted
102
103 AliHMPIDParam *pParam = AliHMPIDParam::Instance();
5a3482a0 104
9785d5fb 105 if(!CluPreFilter(pCluLst)) return kFALSE;
106
5a3482a0 107 Int_t nCh=0;
43d3333b 108 Int_t sizeClu=0;
9785d5fb 109
110 fNClu = pCluLst->GetEntriesFast();
111
112 for (Int_t iClu=0;iClu<fNClu;iClu++){ //clusters loop
5a3482a0 113 AliHMPIDCluster *pClu=(AliHMPIDCluster*)pCluLst->UncheckedAt(iClu); //get pointer to current cluster
5a3482a0 114 fXClu[iClu] = pClu->X();fYClu[iClu] = pClu->Y(); //store x,y for fitting procedure
115 fClCk[iClu] = kTRUE; //all cluster are accepted at this stage to be reconstructed
9785d5fb 116
117 if(iClu == index) {
118
119 fMipX = pClu->X();
120 fMipY = pClu->Y();
121 fMipQ = pClu->Q();
122 sizeClu = pClu->Size();
123 nCh = pClu->Ch();
124 fClCk[index] = kFALSE;
125 fIdxMip = index;
126 // Printf(" n. %d x %f y %f Q %f",iClu,pClu->X(),pClu->Y(),pClu->Q());
127 }
5a3482a0 128 }//clusters loop
9785d5fb 129
130 pParam->SetRefIdx(nmean);
131
e56b695f 132 //
133 Float_t xra,yra,th,ph; pTrk->GetHMPIDtrk(xra,yra,th,ph);
134 Printf(" simulated phi %6.2f ",ph*TMath::RadToDeg());
135 //
136
9785d5fb 137 if(!DoRecHiddenTrk()) {
138 pTrk->SetHMPIDsignal(pParam->kNoPhotAccept);
139 return kFALSE;
140 } //Do track and ring reconstruction,if problems returns 1
e56b695f 141 Printf(" fitted phi %6.2f ",fPhTrkFit*TMath::RadToDeg());
9785d5fb 142
143 pTrk->SetHMPIDtrk(fRadX,fRadY,fThTrkFit,fPhTrkFit); //store track intersection info
144 pTrk->SetHMPIDmip(fMipX,fMipY,(Int_t)fMipQ,fNClu); //store mip info
145 pTrk->SetHMPIDcluIdx(nCh,fIdxMip+1000*sizeClu); //set cham number, index of cluster + cluster size
146 pTrk->SetHMPIDsignal(fCkovFit); //find best Theta ckov for ring i.e. track
147 pTrk->SetHMPIDchi2(fCkovSig2); //errors squared
5a3482a0 148// Printf(" n clusters tot %i accepted %i",pCluLst->GetEntriesFast(),fNClu);
149// Printf("CkovHiddenTrk: thetaC %f th %f ph %f",fCkovFit,fThTrkFit,fPhTrkFit);
5a3482a0 150
9785d5fb 151 return kTRUE;
152
5a3482a0 153}//CkovHiddenTrk()
154//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
155Bool_t AliHMPIDReconHTA::DoRecHiddenTrk()
156{
157// Pattern recognition method without any infos from tracking...
158// First a preclustering filter to avoid part of the noise
159// Then only ellipsed-rings are fitted (no possibility,
160// for the moment, to reconstruct very inclined tracks)
161// Finally a fitting with (th,ph) free, starting by very close values
162// previously evaluated.
163// Arguments: none
164// Returns: none
165 Double_t thTrkRec,phiTrkRec,thetaCRec;
166
167 if(!FindShape(thTrkRec,phiTrkRec,thetaCRec)) return kFALSE;
168
169 if(!FitFree(thTrkRec,phiTrkRec)) {return kFALSE;}
170
171 return kTRUE;
172}//DoRecHiddenTrk()
5a3482a0 173//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
174Bool_t AliHMPIDReconHTA::CluPreFilter(TClonesArray *pCluLst)
175{
aa00f952 176// Pre-filter of bkg clusters
177// Arguments: pSluLst - List of the clusters for a given chamber
178// Returns: status - TRUE if filtering leaves enough photons, FALSE if not
5a3482a0 179//
180 Int_t nClusTot = pCluLst->GetEntriesFast();
181 if(nClusTot<4||nClusTot>100) {
182 return kFALSE;
183 } else {
184 InitVars(nClusTot);
185 return kTRUE;
186 }
187}
188//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
189Bool_t AliHMPIDReconHTA::FindShape(Double_t &thTrkRec,Double_t &phiTrkRec,Double_t &thetaCRec)
190{
aa00f952 191// Finds the estimates for phi and theta of the track and the ThetaCerenkov
192// by using a database of the shapes of the rings
193// Arguments: none
194// Returns: thTrkRec - estimate of theta track
195// phiTrkRec - estimate of phi track
196// thetaCRec - estimate of ThetaCerenkov
197// status - TRUE if a good solution is found, FALSE if not
198
5a3482a0 199 Double_t *phiphot = new Double_t[fNClu];
200 Double_t *dist = new Double_t[fNClu];
201 Int_t *indphi = new Int_t[fNClu];
202
203 Bool_t status;
204
9785d5fb 205// Sort in phi angle...
206// Printf(" mipX %f mipy %f",fMipX,fMipY);
5a3482a0 207 for(Int_t i=0;i<fNClu;i++) {
9785d5fb 208 if(!fClCk[i]) {
209 phiphot[i] = 999.;
210 dist[i] = 999.;
211 continue;
212 }
5a3482a0 213 phiphot[i] = (TMath::ATan2(fMipY-fYClu[i],fMipX-fXClu[i])+TMath::Pi())*TMath::RadToDeg();
214 dist[i]=TMath::Sqrt((fMipX-fXClu[i])*(fMipX-fXClu[i])+(fMipY-fYClu[i])*(fMipY-fYClu[i]));
9785d5fb 215// Printf(" n.%3i phiphot %f dist %f check %i",i,phiphot[i],dist[i],fClCk[i]);
5a3482a0 216 }
217
218 TMath::Sort(fNClu,phiphot,indphi,kFALSE);
219
220// Purify with a truncated mean;
221 Int_t np=0;
222 Double_t dMean = 0;
223 Double_t dMean2 = 0;
224 for(Int_t i=0;i<fNClu;i++) {
225 if(!fClCk[indphi[i]]) continue; // Check if a good photon candidate or not
226 dMean +=dist[indphi[i]];
227 dMean2+=dist[indphi[i]]*dist[indphi[i]];
228 np++;
229 }
230
231 dMean /=(Double_t)np;
232 dMean2 /=(Double_t)np;
233 Double_t rms = TMath::Sqrt(dMean2 - dMean*dMean);
234
235 for(Int_t i=0;i<fNClu;i++) {
236 if(!fClCk[indphi[i]]) continue; // Check if a good photon candidate or not
237 if(TMath::Abs(dMean-dist[indphi[i]]) > 2*rms) {
238 fClCk[indphi[i]] = kFALSE;
239 continue;
240 }
241 }
242
243//
244// purify vectors for good photon candidates
245//
246 Int_t npeff=0;
247 Double_t *phiphotP = new Double_t[fNClu+1];
248 Double_t *distP = new Double_t[fNClu+1];
249 for(Int_t i=0;i<fNClu;i++) {
250 if(!fClCk[indphi[i]]) continue; // Check if a good photon candidate or not
251 phiphotP[npeff] = phiphot[indphi[i]];
252 distP[npeff] = dist[indphi[i]];
9785d5fb 253// Printf("n. %2i phi %f dist %f",npeff,phiphotP[npeff],distP[npeff]);
5a3482a0 254 npeff++;
255 }
256
257 delete [] phiphot;
258 delete [] dist;
259 delete [] indphi;
260
261 if(npeff<3) {
262 delete [] phiphotP;
263 delete [] distP;
264 return kFALSE;
265 }
266
267// for(Int_t i=0;i<npeff;i++) {Printf(" n. %d phiphot %f dist %f",i,phiphotP[i],distP[i]);}
268
269 Double_t xA,xB;
9785d5fb 270 status = kFALSE;
5a3482a0 271 if(ShapeModel(npeff,phiphotP,distP,xA,xB,phiTrkRec)) {
272
9785d5fb 273// Printf("FindShape: phi start %f xA %f yA %f",phiTrkRec*TMath::RadToDeg(),xA,xB);
274 if(xA < 50 && xB < 15) { // limits of the Database. See TH2F in InitDatabase()
5a3482a0 275
9785d5fb 276 Int_t bin = fgDatabase->FindBin(xA,xB);
277 if(bin>0) {
278 Int_t compact = (Int_t)fgDatabase->GetBinContent(bin);
279 thetaCRec = (Double_t)(compact%1000);
280 thTrkRec = (Double_t)(compact/1000);
5a3482a0 281
9785d5fb 282 thTrkRec *= TMath::DegToRad();
283 thetaCRec *= TMath::DegToRad();
5a3482a0 284
9785d5fb 285 // Printf("FindShape: xA %f xB %f compact %d thTrk %f thC %f",xA,xB,compact,thTrkRec*TMath::RadToDeg(),thetaCRec*TMath::RadToDeg());
286
287 status = kTRUE;
288 }
289 }
5a3482a0 290 }
291
292 delete [] phiphotP;
293 delete [] distP;
294
295 return status;
296}
297//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
298Bool_t AliHMPIDReconHTA::ShapeModel(Int_t np,Double_t *phiphot,Double_t *dist,Double_t &xA,Double_t &xB,Double_t &phiStart)
299{
aa00f952 300// Find a Spline curve to define dist. vs. phi angle
301// in order to estimate the phi of the track
302// Arguments: np - # points corresponding to # photon candidates
303// dist - distance of each photon from MIP
304// phiphot - phi of the photon in the DRS
305// Returns: xA - min. distance from MIP
306// xB - dist. from mip perpedicular to the major axis
307// phiStart- estimate of the track phi
308
5a3482a0 309 TGraph *phigr = new TGraph(np,phiphot,dist);
310 TSpline3 *sphi = new TSpline3("sphi",phigr);
311 if(!sphi) {Printf("Spline not created!Bye.");return kFALSE;}
312
313 Int_t locMin = TMath::LocMin(np,dist);
314 Int_t locMax = TMath::LocMax(np,dist);
315
316 Double_t minX = phiphot[locMin];
317// Double_t minY = dist[locMin];
318 Double_t maxX = phiphot[locMax];
319// Double_t maxY = dist[locMax];
320
321 Int_t ip[3] = {-1,0,1};
322 if(locMin==0 ) {ip[0]= 0;ip[1]= 1;ip[2]= 2;}
323 if(locMin==np-1) {ip[0]=-2;ip[1]=-1;ip[2]= 0;}
324
325 Double_t minXf = VertParab(phiphot[locMin+ip[0]],dist[locMin+ip[0]],
326 phiphot[locMin+ip[1]],dist[locMin+ip[1]],
327 phiphot[locMin+ip[2]],dist[locMin+ip[2]]);
328 if(minXf< phiphot[locMin+ip[0]] || minXf > phiphot[locMin+ip[2]]) minXf = minX;
329
330 ip[0]=-1;ip[1]=0;ip[2]=1;
331 if(locMax==0 ) {ip[0]= 0;ip[1]= 1;ip[2]= 2;}
332 if(locMax==np-1) {ip[0]=-2;ip[1]=-1;ip[2]= 0;}
333
334 Double_t maxXf = VertParab(phiphot[locMax+ip[0]],dist[locMax+ip[0]],
335 phiphot[locMax+ip[1]],dist[locMax+ip[1]],
336 phiphot[locMax+ip[2]],dist[locMax+ip[2]]);
337 if(maxXf< phiphot[locMax+ip[0]] || maxXf > phiphot[locMax+ip[2]]) maxXf = maxX;
338
5a3482a0 339//
340 if(TMath::Abs(maxXf-minXf)>30) {
341 xA = sphi->Eval(minXf);
342 if(xA < 0) xA = dist[sphi->FindX(xA)];
343 xB = sphi->Eval(minXf-90);
344 if(xB < 0) xB = dist[sphi->FindX(xB)];
345 phiStart = minXf-180; //open ring or acceptance effect...so believe to min phi angle!
346 } else {
347 phiStart = 0.5*(maxXf-180+minXf);
348 xA = sphi->Eval(phiStart+180);
349 if(xA < 0) xA = dist[sphi->FindX(xA)];
350 xB = sphi->Eval(phiStart+90);
351 if(xB < 0) xB = dist[sphi->FindX(xB)];
352 }
353 //
354// Printf("ShapeModel: phiStart %f xA %f xB %f",phiStart,xA,xB);
355
9a573d52 356
e56b695f 357 phiStart*=TMath::DegToRad();
9a573d52 358 Double_t phitest = FindSimmPhi();
e56b695f 359 //Double_t phiStart = phitest;
360 phiStart = phitest;
361 Printf(" started phi %6.2f ",phiStart*TMath::RadToDeg());
362
363// Printf("phiStart %f phiTest %f",phiStart*TMath::RadToDeg(),phitest*TMath::RadToDeg());
9785d5fb 364
5a3482a0 365 return kTRUE;
366}
367//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
aa00f952 368Double_t AliHMPIDReconHTA::VertParab(Double_t x1,Double_t y1,Double_t x2, Double_t y2, Double_t x3, Double_t y3)const
5a3482a0 369{
aa00f952 370// It uses parabola from 3 points to evaluate the x-coord of the parab
371// Arguments: xi,yi - points
372// Returns: x-coord of the vertex
373
5a3482a0 374 Double_t a = ((x1-x3)*(y1-y2)-(x1-x2)*(y1-y3))/((x1*x1-x2*x2)*(x1-x3)-(x1*x1-x3*x3)*(x1-x2));
375 Double_t b = (y1-y2 - a*(x1*x1-x2*x2))/(x1-x2);
376// Double_t c = y1 - a*x1*x1-b*x1;
377 return -0.5*b/a;
378}
379//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
380Bool_t AliHMPIDReconHTA::FitFree(Double_t thTrkRec,Double_t phiTrkRec)
381{
382// Fit performed by minimizing RMS/sqrt(n) of the
383// photons reconstructed. First phi is fixed and theta
384// is fouond, then (th,ph) of the track
385// as free parameters
386// Arguments: PhiRec phi of the track
387// Returns: none
388
5a3482a0 389 TMinuit *pMinuit = new TMinuit(2);
390 pMinuit->mncler();
391 gMinuit->SetObjectFit((TObject*)this); gMinuit->SetFCN(AliHMPIDReconHTA::FunMinPhot); //set fit function
392 Double_t aArg=-1,parStep,parLow,parHigh; Int_t iErrFlg; //tmp vars for TMinuit
393 Double_t d1,d2,d3;
394 TString sName;
395 Double_t th,ph;
396
397 pMinuit->mnexcm("SET PRI",&aArg,1,iErrFlg); //suspend all printout from TMinuit
398 pMinuit->mnexcm("SET NOW",&aArg,0,iErrFlg);
399
400 if(thTrkRec==0) thTrkRec = 3.*TMath::DegToRad(); // not to start from the edge...
401
402 pMinuit->mnparm(0," thTrk ",thTrkRec ,parStep=0.01,parLow=0,parHigh=TMath::PiOver4(),iErrFlg);
403 pMinuit->mnparm(1," phiTrk ",phiTrkRec,parStep=0.01,parLow=0,parHigh=TMath::TwoPi(),iErrFlg);
404
405 pMinuit->FixParameter(1);
406 pMinuit->mnexcm("SIMPLEX" ,&aArg,0,iErrFlg);
407 pMinuit->mnexcm("MIGRAD" ,&aArg,0,iErrFlg);
408 pMinuit->Release(1);
409 pMinuit->mnexcm("MIGRAD" ,&aArg,0,iErrFlg);
410
411 pMinuit->mnpout(0,sName,th,d1,d2,d3,iErrFlg);
412 pMinuit->mnpout(1,sName,ph,d1,d2,d3,iErrFlg);
413
414 Double_t f,par[2];
415 Double_t *grad=0x0;
416 par[0] = th;par[1] = ph;
417 pMinuit->Eval(2,grad,f,par,3);
418
419// Printf("FitFree: theta %f phi %f",th,ph);
420
421 SetTrkFit(th,ph);
422 return kTRUE;
423}
424//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
425void AliHMPIDReconHTA::FunMinPhot(Int_t &/* */,Double_t* /* */,Double_t &f,Double_t *par,Int_t iflag)
426{
427// Minimization function to find best track and thetaC parameters
428// Arguments: f = function value to minimize
429// par = list of parameter to find
430// iflag = flag status. See Minuit instructions
431// Returns: none
432//
433// Note: it is necessary to call an instance of AlihMPIDParam. Not possible to use fParam
434// because of the static instantiation of the function in Minuit
435
436 AliHMPIDParam *pParam=AliHMPIDParam::Instance();
437 AliHMPIDReconHTA *pRecHTA=(AliHMPIDReconHTA*)gMinuit->GetObjectFit();
438 AliHMPIDRecon pRec;
439 Double_t sizeCh = 0.5*pParam->RadThick()+pParam->WinThick()+pParam->GapThick();
440 Double_t thTrk = par[0];
441 Double_t phTrk = par[1];
442 Double_t xrad = pRecHTA->MipX() - sizeCh*TMath::Tan(thTrk)*TMath::Cos(phTrk);
443 Double_t yrad = pRecHTA->MipY() - sizeCh*TMath::Tan(thTrk)*TMath::Sin(phTrk);
444 pRecHTA->SetRadXY(xrad,yrad);
445 pRec.SetTrack(xrad,yrad,thTrk,phTrk);
446
447 Double_t meanCkov =0;
448 Double_t meanCkov2=0;
449 Double_t thetaCer,phiCer;
450 Int_t nClAcc = 0;
451 Int_t nClTot=pRecHTA->NClu();
452
453 for(Int_t i=0;i<nClTot;i++) {
454 if(!(pRecHTA->ClCk(i))) continue;
455 pRec.FindPhotCkov(pRecHTA->XClu(i),pRecHTA->YClu(i),thetaCer,phiCer);
456 meanCkov += thetaCer;
457 meanCkov2 += thetaCer*thetaCer;
458 nClAcc++;
459 }
460 if(nClAcc==0) {f=999;return;}
461 meanCkov /=(Double_t)nClAcc;
462 meanCkov2 /=(Double_t)nClAcc;
463 Double_t rms = TMath::Sqrt(TMath::Abs(meanCkov2 - meanCkov*meanCkov));
464 f = rms/TMath::Sqrt((Double_t)nClAcc);
465
466 if(iflag==3) {
467/*
468 Printf("FunMinPhot before: photons candidates %i used %i",nClTot,nClAcc);
469 nClAcc = 0;
470 Double_t meanCkov1=0;
471 Double_t meanCkov2=0;
472 for(Int_t i=0;i<nClTot;i++) {
473 if(!(pRec->ClCk(i))) continue;
474 pRec->FindPhotCkov(pRec->XClu(i),pRec->YClu(i),thetaCer,phiCer);
475 if(TMath::Abs(thetaCer-meanCkov)<2*rms) {
476 meanCkov1 += thetaCer;
477 meanCkov2 += thetaCer*thetaCer;
478 nClAcc++;
479 } else pRec->SetClCk(i,kFALSE);
480 }
481 meanCkov1/=nClAcc;
482 Double_t rms2 = (meanCkov2 - meanCkov*meanCkov*nClAcc)/nClAcc;
483 Printf("FunMinPhot after: photons candidates %i used %i thetaCer %f",nClTot,nClAcc,meanCkov1);
484 pRec->SetCkovFit(meanCkov1);
485 pRec->SetCkovSig2(rms2);
486 pRec->SetNClu(nClAcc);
487*/
488// Printf("FunMinPhot: reconstructed theta Cerenkov %f with %d photons",meanCkov,nClAcc);
489 pRecHTA->SetCkovFit(meanCkov);
490 pRecHTA->SetCkovSig2(rms*rms);
491 pRecHTA->SetNClu(nClAcc);
492 }
493}//FunMinPhot()
494//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
495void AliHMPIDReconHTA::InitDatabase()
496{
aa00f952 497// Construction a database of ring shapes on fly
498// Arguments: none
499// Returns : none
500// N.B. fgDatabase points to a TH2I with x-min dist from MIP
501// y-dist from the ring of the MIP perpendicular to major axis
502// The content is the packed info of track theta and thetaC in degrees
503// thetaC+1000*thTrk
504//
9785d5fb 505// TFile *pout = new TFile("./database.root","recreate");
506
5a3482a0 507 TStopwatch timer;
508 timer.Start();
5565f017 509
510
511 if(!fgDatabase) fgDatabase = new TH2F("deconv","database;d1;d2;thC+1000*thTrk",500,0,50,150,0,15);
512 if(fgDatabase->GetEntries()>=1) {
513 AliInfo("HTA database already built. ");
514 return;
515 }
5a3482a0 516 AliInfo(Form("database HTA is being built.Please, wait..."));
517//
c61a7285 518 Double_t x[3]={0,0,0},y[3];
5a3482a0 519
520 AliHMPIDRecon rec;
521
522 if(!fParam) fParam=AliHMPIDParam::Instance();
523 Double_t thetaMax = TMath::ACos(1./fParam->MeanIdxRad());
524 Double_t thTrkMax = 1./TMath::ASin(fParam->MeanIdxRad());
525
526 Int_t nstepx = 1000;
527 Int_t nstepy = 1000;
528
9785d5fb 529// TH2F *fgDatabase = new TH2F("deconv","database;d1;d2;thC+1000*thTrk",500,0,50,150,0,15);
5a3482a0 530 //
531 Double_t xrad = 0;
532 Double_t yrad = 0;
533 Double_t phTrk = 0;
534
535 for(Int_t i=0;i<nstepx;i++) { //loop on thetaC
536 for(Int_t j=0;j<nstepy;j++) { //loop on theta particle
537 Double_t thetaC = thetaMax/nstepx*((Double_t)i+0.5);
538 Double_t thTrk = thTrkMax/nstepy*((Double_t)j+0.5);
539 //
540 //mip position
541 //
fcaff63d 542 Double_t sizeCh = 0.5*fParam->RadThick()+fParam->WinThick()+fParam->GapThick();
5a3482a0 543 Double_t xmip = xrad + sizeCh*TMath::Tan(thTrk)*TMath::Cos(phTrk);
544 Double_t ymip = yrad + sizeCh*TMath::Tan(thTrk)*TMath::Sin(phTrk);
545
546 Double_t dist1,dist2;
547 //
548 //first point at phi=0
549 //
550 rec.SetTrack(xrad,yrad,thTrk,phTrk);
551 TVector2 pos;
552 pos=rec.TracePhot(thetaC,0);
553
554 if(pos.X()==-999) {
555 dist1 = 0; //open ring...anly the distance btw mip and point at 180 will be considered
556 } else {
557 x[0] = pos.X(); y[0] = pos.Y();
558 dist1 = TMath::Sqrt((x[0]-xmip)*(x[0]-xmip)+(y[0]-ymip)*(y[0]-ymip));
559 }
560 //
561 //second point at phi=180
562 //
563 rec.SetTrack(xrad,yrad,thTrk,phTrk);
564 pos=rec.TracePhot(thetaC,TMath::Pi());
565
566 if(pos.X()==-999) {Printf("it should not happens!Bye");return;}
567 x[1] = pos.X(); y[1] = pos.Y();
568 if((x[1]-xmip)*(x[0]-xmip)>0) continue; // to avoid circles out mips (for very low ThetaC)
569 dist2 = TMath::Sqrt((x[1]-xmip)*(x[1]-xmip)+(y[1]-ymip)*(y[1]-ymip));
570
571// Double_t distA = dist1+dist2;
572 Double_t distA = dist2; // only the minimum: problem of acceptance
573 //
574 //second point at phi=90
575 //
576 rec.SetTrack(xrad,yrad,thTrk,phTrk);
577 pos=rec.TracePhot(thetaC,TMath::PiOver2());
578
579 if(pos.X()==-999) continue;
580 x[2] = pos.X(); y[2] = pos.Y();
581 Double_t distB = TMath::Sqrt((x[2]-xmip)*(x[2]-xmip)+(y[2]-ymip)*(y[2]-ymip));
582// compact the infos...
583 Int_t compact = (Int_t)(thetaC*TMath::RadToDeg())+1000*(Int_t)(thTrk*TMath::RadToDeg());
9785d5fb 584 Int_t bin = fgDatabase->FindBin(distA,distB);
585 if(fgDatabase->GetBinContent(bin)==0) fgDatabase->Fill(distA,distB,compact);
5a3482a0 586 }
587 }
588
9785d5fb 589 FillZeroChan();
590// fgDatabase = deconv;
5a3482a0 591
592 timer.Stop();
593 Double_t nSecs = timer.CpuTime();
594 AliInfo(Form("database HTA successfully open in %3.1f sec.(CPU). Reconstruction is started.",nSecs));
9785d5fb 595
596// pout->Write();
597// pout->Close();
598
9a573d52 599}//InitDatabase()
5a3482a0 600//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
9785d5fb 601void AliHMPIDReconHTA::FillZeroChan()const
5a3482a0 602{
606697a8 603 //If fills eventually channel without entries
604 //inthe histo "database" jyst interpolating the neighboring cells
605 // Arguments: histogram pointer of the database
606 // Returns: none
607 //
9785d5fb 608 Int_t nbinx = fgDatabase->GetNbinsX();
609 Int_t nbiny = fgDatabase->GetNbinsY();
5a3482a0 610 for(Int_t i = 0;i<nbinx;i++) {
611 for(Int_t j = 0;j<nbiny;j++) {
9785d5fb 612 if(fgDatabase->GetBinContent(i,j) == 0) {
5a3482a0 613 Int_t nXmin = i-1; Int_t nXmax=i+1;
614 Int_t nYmin = j-1; Int_t nYmax=j+1;
615 Int_t nc = 0;
616 Double_t meanC =0;
617 Double_t meanTrk =0;
618 for(Int_t ix=nXmin;ix<=nXmax;ix++) {
619 if(ix<0||ix>nbinx) continue;
620 for(Int_t iy=nYmin;iy<=nYmax;iy++) {
621 if(iy<0||iy>nbiny) continue;
9785d5fb 622 meanC += (Int_t)fgDatabase->GetBinContent(ix,iy)%1000;
623 meanTrk+= (Int_t)fgDatabase->GetBinContent(ix,iy)/1000;
5a3482a0 624 nc++;
625 }
626 meanC/=nc; meanTrk/=nc;
627 Int_t compact = (Int_t)meanC+1000*(Int_t)meanTrk;
9785d5fb 628 if(compact>0)fgDatabase->SetCellContent(i,j,compact);
5a3482a0 629 }
630 }
631 }
632 }
9a573d52 633}//FillZeroChan()
5a3482a0 634//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
9a573d52 635
636// stima gli angoli con il metodo dei minimi quadrati che sfrutta le distanze...
637
638Double_t AliHMPIDReconHTA::FindSimmPhi()
639{
640 //It finds the phi of the ring
641 //by using the min. dist. algorithm
642 // Arguments: none
643 // Returns: phi
644 //
645
646 Float_t xrotsumm =0; Float_t yrotsumm =0; Float_t xx =0;
647 Float_t yy =0; Float_t xy =0;
648
649 Int_t np=0;
650
651 for(Int_t i=0;i<fNClu;i++) {
652 if(!fClCk[i]) continue;
653 np++;
654 xrotsumm+=fXClu[i]; // summ xi
655 yrotsumm+=fYClu[i]; // summ yi
656 xx+=fXClu[i]*fXClu[i]; // summ xixi
657 yy+=fYClu[i]*fYClu[i]; // summ yiyi
658 xy+=fXClu[i]*fYClu[i]; // summ yixi
659 }
660
661 //_____calc. met min quadr using effective distance _________________________________________________
662
663 Double_t coeff[3];
664 coeff[0]= xy-xrotsumm*yrotsumm/np;
665 coeff[1]= yrotsumm*yrotsumm/np - xrotsumm*xrotsumm/np - yy + xx;
666 coeff[2]= xrotsumm*yrotsumm/np- xy;
667
668 //____________________________________________________________________________________________________
669
670 Double_t m1=0, m2=0;
671 Double_t n1=0, n2=0;
672
673 r2(coeff,m1,m2);
674
675 n1=(yrotsumm-m1*xrotsumm)/np;
676 n2=(yrotsumm-m2*xrotsumm)/np;
677
678 // le due soluzioni.................
679
680 Double_t d1 =(1/(m1*m1+1))*(yy+m1*m1*xx+np*n1*n1-2*m1*xy-2*n1*yrotsumm+2*m1*n1*xrotsumm);
681 Double_t d2 =(1/(m2*m2+1))*(yy+m2*m2*xx+np*n2*n2-2*m2*xy-2*n2*yrotsumm+2*m2*n2*xrotsumm);
682 Double_t mMin;
683 if(d1 > d2) mMin = m2; else mMin = m1;
684
685 Double_t PhiTrk= TMath::ATan(mMin);
686
687 // positive angles...
688 if(PhiTrk<0) PhiTrk+=180*TMath::DegToRad();
689
690 return PhiTrk;
691}
692
693//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
694Int_t AliHMPIDReconHTA::r2(Double_t *coef, Double_t &x1, Double_t &x2)
695{
696 //2nd deg. equation
697 //solution
698 // Arguments: coef 2 1 0: ax^2+bx+c=0
699 // Returns: n. of solutions
700 // x1= 1st sol
701 // x2= 2nd sol
702 Double_t a,b,c;
703 a = coef[2];
704 b = coef[1];
705 c = coef[0];
706 Double_t delta = b*b-4*a*c;
707 if(delta<0) {return 0;}
708 if(delta==0) {
709 x1=x2=-b/(2*a);
710 return 1;
711 }
712 // delta>0
713 x1 = (-b+TMath::Sqrt(delta))/(2*a);
714 x2 = (-b-TMath::Sqrt(delta))/(2*a);
715 return 2;
716}//r2()