1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
16 /* $Id: AliTRDpidRefMakerLQ.cxx 34163 2009-08-07 11:28:51Z cblume $ */
18 ///////////////////////////////////////////////////////////////////////////////
21 // TRD calibration class for building reference data for PID
22 // - 2D reference histograms (responsible A.Bercuci)
23 // - 3D reference histograms (not yet implemented) (responsible A.Bercuci)
24 // - Neural Network (responsible A.Wilk)
27 // Alex Bercuci (A.Bercuci@gsi.de)
29 ///////////////////////////////////////////////////////////////////////////////
35 #include <TEventList.h>
38 #include <TPrincipal.h>
40 #include <TLinearFitter.h>
46 #include "../../STAT/TKDPDF.h"
47 #include "AliTRDpidRefMakerLQ.h"
48 #include "../Cal/AliTRDCalPID.h"
49 #include "AliTRDseedV1.h"
50 #include "AliTRDcalibDB.h"
51 #include "AliTRDgeometry.h"
53 ClassImp(AliTRDpidRefMakerLQ)
55 //__________________________________________________________________
56 AliTRDpidRefMakerLQ::AliTRDpidRefMakerLQ()
57 :AliTRDpidRefMaker("PidRefMakerLQ", "PID(LQ) Reference Maker")
62 // AliTRDpidRefMakerLQ default constructor
65 memset(fH2dEdx, 0x0, AliPID::kSPECIES*sizeof(TH2*));
68 //__________________________________________________________________
69 AliTRDpidRefMakerLQ::~AliTRDpidRefMakerLQ()
72 // AliTRDCalPIDQRef destructor
75 for(int ispec=0; ispec<AliPID::kSPECIES; ispec++){
76 if(fH2dEdx[ispec]) delete fH2dEdx[ispec];
80 //________________________________________________________________________
81 void AliTRDpidRefMakerLQ::CreateOutputObjects()
86 AliTRDpidRefMaker::CreateOutputObjects();
88 fData = new TTree(GetName(), Form("Reference data for %s", GetName()));
89 fData->Branch("s", &fSbin, "l/b");
90 fData->Branch("p", &fPbin, "p/b");
91 fData->Branch("dEdx" , fdEdx , Form("dEdx[%d]/F", GetNslices()));
95 //________________________________________________________________________
96 Float_t* AliTRDpidRefMakerLQ::GetdEdx(AliTRDseedV1 *trklt)
98 trklt->CookdEdx(AliTRDpidUtil::kLQslices);
99 const Float_t *dedx = trklt->GetdEdx();
100 if(dedx[0]+dedx[1] <= 0.) return 0x0;
101 if(dedx[2] <= 0.) return 0x0;
103 fdEdx[0] = TMath::Log(dedx[0]+dedx[1]);
104 fdEdx[1] = TMath::Log(dedx[2]);
109 //________________________________________________________________________
110 void AliTRDpidRefMakerLQ::Fill()
113 fSbin = TMath::LocMax(AliPID::kSPECIES, fPID);
115 fPbin = AliTRDpidUtil::GetMomentumBin(fP);
120 //________________________________________________________________________
121 Bool_t AliTRDpidRefMakerLQ::PostProcess()
123 TFile::Open(Form("TRD.Calib%s.root", GetName()));
124 fData = dynamic_cast<TTree*>(gFile->Get(GetName()));
126 AliError("Tree not available");
129 AliDebug(2, Form("Data[%d]", fData->GetEntries()));
131 Float_t *data[] = {0x0, 0x0};
132 TPrincipal principal(2, "ND");
134 TCanvas *cc = new TCanvas("cc", "", 500, 500);
136 for(Int_t ip=AliTRDCalPID::kNMom; ip--;){
137 for(Int_t is=AliPID::kSPECIES; is--;) {
139 Int_t n = fData->Draw("dEdx[0]:dEdx[1]", Form("p==%d&&s==%d", ip, is), "goff");
140 AliDebug(2, Form("pBin[%d] sBin[%d] n[%d]", ip, is, n));
142 AliWarning(Form("Not enough data for %s[%d].", AliPID::ParticleShortName(is), ip));
146 data[0] = new Float_t[n];data[1] = new Float_t[n];
148 // fill and make principal
149 Double_t *v1 = fData->GetV1(), *v2 = fData->GetV2();
151 Double_t dedx[] = {v1[n], v2[n]};
152 principal.AddRow(dedx);
154 principal.MakePrincipals();
156 // // calculate covariance ellipse
157 // eValues = principal.GetEigenValues();
160 // rx = 3.5*sqrt((*eValues)[0]);
161 // ry = 3.5*sqrt((*eValues)[1]);
163 // rotate to principal axis
164 const Double_t *xx; Double_t rxy[2];
165 while((xx = principal.GetRow(++n))){
166 principal.X2P(xx, rxy);
167 data[0][n]=rxy[0]; data[1][n]=rxy[1];
168 //hProj->Fill(rxy[0], rxy[1]);
171 // estimate acceptable statistical error per bucket
173 // estimate number of buckets
176 TKDPDF pdf(n, 2, 10, data);
177 printf("PDF nodes[%d]\n", pdf.GetNTNodes());
180 Float_t *c, v, ve; Double_t r, e;
181 for(Int_t in=pdf.GetNTNodes(); in--;){
182 pdf.GetCOGPoint(in, c, v, ve);
183 rxy[0] = (Double_t)c[0];rxy[1] = (Double_t)c[1];
184 printf("%2d x[%f] y[%f]\n", in, rxy[0], rxy[1]);
185 pdf.Eval(rxy, r, e, kTRUE);
187 pdf.DrawBins(0,1,-6,6,-6,6);cc->Modified(); cc->Update();
188 AliDebug(2, Form("n[%d]", n));
190 //pdf.Write(Form("%s[%d]", AliPID::ParticleShortName(is), ip));
193 delete [] data[0]; delete [] data[1];
197 return kTRUE; // testing protection
201 //__________________________________________________________________
202 void AliTRDpidRefMakerLQ::Reset()
205 // Reset reference histograms
208 for(int ispec=0; ispec<AliPID::kSPECIES; ispec++){
209 if(fH2dEdx[ispec]) fH2dEdx[ispec]->Reset();
213 //__________________________________________________________________
214 void AliTRDpidRefMakerLQ::SaveReferences(const Int_t mom, const char *fn)
217 // Save the reference histograms
221 TListIter it((TList*)gROOT->GetListOfFiles());
222 Bool_t kFOUND = kFALSE;
223 TDirectory *pwd = gDirectory;
224 while((fSave=(TFile*)it.Next()))
225 if(strcmp(fn, fSave->GetName())==0){
229 if(!kFOUND) fSave = TFile::Open(fn, "RECREATE");
232 // save dE/dx references
234 for(int ispec=0; ispec<AliPID::kSPECIES; ispec++){
235 h2 = (TH2D*)fH2dEdx[ispec]->Clone(Form("h2dEdx%s%d", AliTRDCalPID::GetPartSymb(ispec), mom));
236 h2->SetTitle(Form("2D dEdx for particle %s @ %d", AliTRDCalPID::GetPartName(ispec), mom));
237 h2->GetXaxis()->SetTitle("dE/dx_{TRD}^{amplif} [au]");
238 h2->GetYaxis()->SetTitle("dE/dx_{TRD}^{drift} [au]");
239 h2->GetZaxis()->SetTitle("Entries");