]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ITS/AliITSVertexerPPZ.cxx
for non-miscalibrated digits, set an ad-hoc conversion factor fAdC->fToT to have...
[u/mrichter/AliRoot.git] / ITS / AliITSVertexerPPZ.cxx
CommitLineData
c95d6417 1/**************************************************************************
2 * Copyright(c) 1998-2003, 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 **************************************************************************/
c5f0f3c1 15#include <AliITSVertexerPPZ.h>
c5f0f3c1 16#include <TArrayF.h>
c5f0f3c1 17#include <TH1F.h>
c5f0f3c1 18#include <TObjArray.h>
19#include <TTree.h>
20#include <TClonesArray.h>
7d62fb64 21#include "AliITSDetTypeRec.h"
c5f0f3c1 22#include "AliITSgeom.h"
88cb7938 23#include "AliITSLoader.h"
c5f0f3c1 24#include "AliITSRecPoint.h"
25/////////////////////////////////////////////////////////////////////////
26// //
27// This class is intended to compute the Z coordinate of the //
28// primary vertex for p-p interactions, or in general when the //
29// number of secondaries is too slow to use the class //
30// AliITSVertexerIons, which in turn is optimized for A-A collsions //
31// Origin: masera@to.infn.it 9/12/2002 //
32// //
33/////////////////////////////////////////////////////////////////////////
34ClassImp(AliITSVertexerPPZ)
35
36
37
38//______________________________________________________________________
8221b41b 39AliITSVertexerPPZ::AliITSVertexerPPZ():AliITSVertexer(),
40fFirstL1(0),
41fLastL1(0),
42fFirstL2(0),
43fLastL2(0),
44fDiffPhiMax(0),
45fX0(0),
46fY0(0),
47fZFound(0),
48fZsig(0),
49fWindow(0){
c5f0f3c1 50 // Default Constructor
51
52 SetDiffPhiMax(0);
c5f0f3c1 53 SetFirstLayerModules(0);
54 SetSecondLayerModules(0);
7d62fb64 55 //fITS = 0;
c95d6417 56 SetWindow(0);
c5f0f3c1 57}
58
8221b41b 59AliITSVertexerPPZ::AliITSVertexerPPZ(TString fn, Float_t x0, Float_t y0):AliITSVertexer(fn),
60fFirstL1(0),
61fLastL1(0),
62fFirstL2(0),
63fLastL2(0),
64fDiffPhiMax(0),
65fX0(x0),
66fY0(y0),
67fZFound(0),
68fZsig(0),
69fWindow(0) {
c5f0f3c1 70 // Standard constructor
c5f0f3c1 71 SetDiffPhiMax();
72 fX0 = x0;
73 fY0 = y0;
74 SetFirstLayerModules();
75 SetSecondLayerModules();
7d62fb64 76 //fITS = 0;
c95d6417 77 SetWindow();
c5f0f3c1 78}
79
80//______________________________________________________________________
81AliITSVertexerPPZ::~AliITSVertexerPPZ() {
82 // Default Destructor
7d62fb64 83 //fITS = 0;
c5f0f3c1 84}
85
86//________________________________________________________
87void AliITSVertexerPPZ::EvalZ(TH1F *hist,Int_t sepa, Int_t ncoinc, TArrayF *zval) {
7d62fb64 88
89 //Evaluation of Z
90 Float_t deltaVal = hist->GetBinWidth(1)*fWindow; // max window in Z for searching
c5f0f3c1 91 fZFound=0;
92 fZsig=0;
7d62fb64 93 Int_t nN=0;
94 Int_t nbinNotZero=0;
c5f0f3c1 95 Float_t totst = 0.;
96 Float_t totst2 = 0.;
97 Float_t curz = 0.;
98 for(Int_t i=1;i<=sepa;i++){
99 Float_t cont=hist->GetBinContent(i);
c95d6417 100 if(cont!=0)curz = hist->GetBinLowEdge(i)+0.5*hist->GetBinWidth(i);
c5f0f3c1 101 totst+=cont;
102 totst2+=cont*cont;
7d62fb64 103 nN++;
104 if(cont!=0)nbinNotZero++;
c5f0f3c1 105 }
7d62fb64 106 if(nbinNotZero==0){fZFound=-100; fZsig=-100; return;}
107 if(nbinNotZero==1){
c95d6417 108 fZFound = curz;
109 fZsig=0;
7d62fb64 110 fCurrentVertex = new AliESDVertex(fZFound,fZsig,nbinNotZero);
c95d6417 111 return;
112 }
7d62fb64 113 Float_t errsq = totst2/(nN-1)-totst*totst/nN/(nN-1);
c95d6417 114 if(errsq>=0){
115 totst2=TMath::Sqrt(errsq);
116 }
117 else {
7d62fb64 118 Error("EvalZ","Negative variance: %d - %12.7f - %12.7f",nN,totst2,totst);
c95d6417 119 fZFound=-100;
120 fZsig=-100;
121 return;
122 }
7d62fb64 123 totst /= nN;
c95d6417 124 Float_t cut = totst+totst2*2.;
27167524 125 // if(fDebug>1)cout<<"totst, totst2, cut: "<<totst<<", "<<totst2<<", "<<cut<<endl;
c5f0f3c1 126 Float_t val1=hist->GetBinLowEdge(sepa);
127 Float_t val2=hist->GetBinLowEdge(1);
c95d6417 128 Float_t valm = 0.;
129 Float_t zmax = 0.;
c5f0f3c1 130 for(Int_t i=1;i<=sepa;i++){
131 Float_t cont=hist->GetBinContent(i);
c95d6417 132 if(cont>valm){
133 valm = cont;
134 zmax = hist->GetBinLowEdge(i)+0.5*hist->GetBinWidth(1);
135 }
136 if(cont>cut){
c5f0f3c1 137 curz=hist->GetBinLowEdge(i);
138 if(curz<val1)val1=curz;
139 if(curz>val2)val2=curz;
140 }
141 }
142 val2+=hist->GetBinWidth(1);
7d62fb64 143 if((val2-val1)>deltaVal){
144 val1 = zmax-deltaVal/2.;
145 val2 = zmax+deltaVal/2.;
27167524 146 // if(fDebug>0)cout<<"val1 and val2 recomputed\n";
c95d6417 147 }
27167524 148 // if(fDebug>0)cout<<"Values for Z finding: "<<val1<<" "<<val2<<" "<<val2-val1<<endl;
c5f0f3c1 149 fZFound=0;
150 fZsig=0;
7d62fb64 151 nN=0;
c5f0f3c1 152 for(Int_t i=0; i<ncoinc; i++){
153 Float_t z=zval->At(i);
154 if(z<val1)continue;
155 if(z>val2)continue;
c95d6417 156
c5f0f3c1 157 fZFound+=z;
158 fZsig+=z*z;
c95d6417 159 /* weights defined by the curvature
160 Float_t wei = 1./curv->At(i);
161 fZFound+=z*wei;
162 fZsig+=wei;
163 */
7d62fb64 164 nN++;
c5f0f3c1 165 }
7d62fb64 166 if(nN<1){fZFound=-110; fZsig=-110; return;}
167 if(nN==1){
c95d6417 168 fZsig = 0;
7d62fb64 169 fCurrentVertex = new AliESDVertex(fZFound,fZsig,nN);
c95d6417 170 return;
171 }
7d62fb64 172 errsq = (fZsig/(nN-1)-fZFound*fZFound/nN/(nN-1))/nN;
c95d6417 173 if(errsq>=0.){
174 fZsig=TMath::Sqrt(errsq);
175 }
176 else {
7d62fb64 177 Error("evalZ","Negative variance: %d - %12.7f %12.7f",nN,fZsig,fZFound);
c95d6417 178 fZsig=0;
179 }
7d62fb64 180 fZFound=fZFound/nN;
c95d6417 181 /* weights defined by the curvature
182 fZsig=1./fZsig;
183 fZFound*=fZsig;
184 fZsig = TMath::Sqrt(fZsig);
185 */
7d62fb64 186 fCurrentVertex = new AliESDVertex(fZFound,fZsig,nN);
c5f0f3c1 187}
188
189//______________________________________________________________________
d681bb2d 190AliESDVertex* AliITSVertexerPPZ::FindVertexForCurrentEvent(Int_t evnumber){
191 // Defines the AliESDVertex for the current event
c5f0f3c1 192 fCurrentVertex = 0;
193 fZFound = -999;
194 fZsig = -999;
88cb7938 195 AliRunLoader *rl =AliRunLoader::GetRunLoader();
7d62fb64 196 AliITSLoader* iTSloader = (AliITSLoader*)rl->GetLoader("ITSLoader");
197 TDirectory * olddir = gDirectory;
198 rl->CdGAFile();
199 AliITSgeom* geom = (AliITSgeom*)gDirectory->Get("AliITSgeom");
200 olddir->cd();
201
202 AliITSDetTypeRec detTypeRec;
203
c5f0f3c1 204 if(!geom) {
205 Error("FindVertexForCurrentEvent","ITS geometry is not defined");
206 return fCurrentVertex;
207 }
2257f27e 208 TTree *tR=0;
209 TClonesArray *itsRec = 0;
c5f0f3c1 210 Float_t lc[3]; for(Int_t ii=0; ii<3; ii++) lc[ii]=0.;
211 Float_t gc[3]; for(Int_t ii=0; ii<3; ii++) gc[ii]=0.;
212 Float_t lc2[3]; for(Int_t ii=0; ii<3; ii++) lc2[ii]=0.;
213 Float_t gc2[3]; for(Int_t ii=0; ii<3; ii++) gc2[ii]=0.;
214
7d62fb64 215 tR = iTSloader->TreeR();
2257f27e 216 if(!tR){
c5f0f3c1 217 Error("FindVertexForCurrentEvent","TreeR not found");
218 return fCurrentVertex;
219 }
7d62fb64 220 detTypeRec.SetTreeAddressR(tR);
221 itsRec = detTypeRec.RecPoints();
c5f0f3c1 222 // missing
00a7cc50 223 // TClonesArray dummy("AliITSRecPoint",10000), *clusters=&dummy;
2257f27e 224 TBranch *branch;
00a7cc50 225 branch = tR->GetBranch("ITSRecPoints");
226 if(!branch){
227 branch = tR->GetBranch("ITSRecPointsF");
c5f0f3c1 228 }
00a7cc50 229 //}
c5f0f3c1 230 if(!branch){
231 Error("FindVertexForCurrentEvent","branch for ITS rec points not found");
232 return fCurrentVertex;
233 }
234 Float_t zave=0;
235 Float_t rmszav=0;
236 Float_t zave2=0;
237 Int_t firipixe=0;
238 for(Int_t module= fFirstL1; module<=fLastL1;module++){
239 branch->GetEvent(module);
2257f27e 240 Int_t nrecp1 = itsRec->GetEntries();
c5f0f3c1 241 for(Int_t i=0; i<nrecp1;i++){
2257f27e 242 AliITSRecPoint *current = (AliITSRecPoint*)itsRec->At(i);
00a7cc50 243 lc[0]=current->GetDetLocalX();
244 lc[2]=current->GetDetLocalZ();
c5f0f3c1 245 geom->LtoG(module,lc,gc);
246 zave+=gc[2];
247 zave2+=gc[2]*gc[2];
248 firipixe++;
249 }
7d62fb64 250 detTypeRec.ResetRecPoints();
c5f0f3c1 251 }
252 if(firipixe>1){
253 rmszav=TMath::Sqrt(zave2/(firipixe-1)-zave*zave/firipixe/(firipixe-1));
254 zave=zave/firipixe;
27167524 255 // if(fDebug>1)cout<<"++++++++++++++++++++++++++++++++++++++++++++++++++++++\n Number of firing pixels: "<<firipixe<<endl;
c5f0f3c1 256 }
257 else {
258 fZFound = -200;
259 fZsig = -200;
260 Warning("FindVertexForCurrentEvent","No rec points on first layer for this event");
261 return fCurrentVertex;
262 }
263 Float_t zlim1=zave-rmszav;
264 Float_t zlim2=zave+rmszav;
265 Int_t sepa=(Int_t)((zlim2-zlim1)*10.+1.);
266 zlim2=zlim1 + sepa/10.;
267 TH1F *zvdis = new TH1F("z_ev","zv distr",sepa,zlim1,zlim2);
27167524 268 /*
269 if(fDebug>0){
270 cout<<"Z limits: "<<zlim1<<" "<<zlim2<<"; Bins= "<<sepa<<endl;
271 cout<<"Bin width: "<<zvdis->GetBinWidth(1)*10000.<<" micron\n";
272 }
273 */
c5f0f3c1 274 Int_t sizarr=100;
275 TArrayF *zval = new TArrayF(sizarr);
c95d6417 276 // TArrayF *curv = new TArrayF(sizarr);
c5f0f3c1 277 Int_t ncoinc=0;
278 for(Int_t module= fFirstL1; module<=fLastL1;module++){
27167524 279 // if(fDebug>0)cout<<"processing module "<<module<<" \r";
c5f0f3c1 280 branch->GetEvent(module);
2257f27e 281 Int_t nrecp1 = itsRec->GetEntries();
c5f0f3c1 282 TObjArray *poiL1 = new TObjArray(nrecp1);
2257f27e 283 for(Int_t i=0; i<nrecp1;i++)poiL1->AddAt(itsRec->At(i),i);
7d62fb64 284 detTypeRec.ResetRecPoints();
c5f0f3c1 285 for(Int_t i=0; i<nrecp1;i++){
286 AliITSRecPoint *current = (AliITSRecPoint*)poiL1->At(i);
00a7cc50 287 lc[0]=current->GetDetLocalX();
288 lc[2]=current->GetDetLocalZ();
c5f0f3c1 289 geom->LtoG(module,lc,gc);
290 gc[0]-=fX0;
291 gc[1]-=fY0;
292 Float_t r1=TMath::Sqrt(gc[0]*gc[0]+gc[1]*gc[1]);
293 Float_t phi1 = TMath::ATan2(gc[1],gc[0]);
294 if(phi1<0)phi1=2*TMath::Pi()+phi1;
27167524 295 // if(fDebug>1)cout<<"module "<<module<<" "<<gc[0]<<" "<<gc[1]<<" "<<gc[2]<<" "<<phi1<<" \n";
c5f0f3c1 296 for(Int_t modul2=fFirstL2; modul2<=fLastL2; modul2++){
297 branch->GetEvent(modul2);
2257f27e 298 Int_t nrecp2 = itsRec->GetEntries();
c5f0f3c1 299 for(Int_t j=0; j<nrecp2;j++){
2257f27e 300 AliITSRecPoint *recp = (AliITSRecPoint*)itsRec->At(j);
00a7cc50 301 lc2[0]=recp->GetDetLocalX();
302 lc2[2]=recp->GetDetLocalZ();
c5f0f3c1 303 geom->LtoG(modul2,lc2,gc2);
304 gc2[0]-=fX0;
305 gc2[1]-=fY0;
306 Float_t r2=TMath::Sqrt(gc2[0]*gc2[0]+gc2[1]*gc2[1]);
307 Float_t zr0=(r2*gc[2]-r1*gc2[2])/(r2-r1);
308 Float_t phi2 = TMath::ATan2(gc2[1],gc2[0]);
309 if(phi2<0)phi2=2.*TMath::Pi()+phi2;
310 Float_t diff = TMath::Abs(phi2-phi1);
311 if(diff>TMath::Pi())diff=2.*TMath::Pi()-diff;
312 if(zr0>zlim1 && zr0<zlim2){
313 if(diff<fDiffPhiMax ){
314 zvdis->Fill(zr0);
315 zval->AddAt(zr0,ncoinc);
c95d6417 316 /* uncomment these lines to use curvature as a weight
317 Float_t cu = Curv(0.,0.,gc[0],gc[1],gc2[0],gc[1]);
318 curv->AddAt(cu,ncoinc);
319 */
c5f0f3c1 320 ncoinc++;
321 if(ncoinc==(sizarr-1)){
322 sizarr+=100;
323 zval->Set(sizarr);
c95d6417 324 //uncomment next line to use curvature as weight
325 // curv->Set(sizarr);
c5f0f3c1 326 }
327 }
328 }
329 }
7d62fb64 330 detTypeRec.ResetRecPoints();
c5f0f3c1 331 }
332 }
333 delete poiL1;
334 } // loop on modules
27167524 335 /*
336 if(fDebug>0){
337 cout<<endl<<"Number of coincidences = "<<ncoinc<<endl;
338 }
339 */
c95d6417 340 // EvalZ(zvdis,sepa,ncoinc,zval,curv);
c5f0f3c1 341 EvalZ(zvdis,sepa,ncoinc,zval);
342 delete zvdis;
343 delete zval;
c95d6417 344 // delete curv;
c5f0f3c1 345 if(fCurrentVertex){
346 char name[30];
347 sprintf(name,"Vertex_%d",evnumber);
88cb7938 348 // fCurrentVertex->SetName(name);
c5f0f3c1 349 fCurrentVertex->SetTitle("vertexer: PPZ");
350 }
7d62fb64 351
c5f0f3c1 352 return fCurrentVertex;
353}
354
355//______________________________________________________________________
356void AliITSVertexerPPZ::FindVertices(){
357 // computes the vertices of the events in the range FirstEvent - LastEvent
88cb7938 358 AliRunLoader *rl = AliRunLoader::GetRunLoader();
7d62fb64 359 AliITSLoader* iTSloader = (AliITSLoader*) rl->GetLoader("ITSLoader");
360 iTSloader->ReloadRecPoints();
ab6a6f40 361 for(Int_t i=fFirstEvent;i<=fLastEvent;i++){
88cb7938 362 cout<<"Processing event "<<i<<endl;
363 rl->GetEvent(i);
c5f0f3c1 364 FindVertexForCurrentEvent(i);
365 if(fCurrentVertex){
366 WriteCurrentVertex();
367 }
368 else {
27167524 369 /*
370 if(fDebug>0){
371 cout<<"Vertex not found for event "<<i<<endl;
372 cout<<"fZFound = "<<fZFound<<", fZsig= "<<fZsig<<endl;
373 }
374 */
c5f0f3c1 375 }
376 }
c5f0f3c1 377}
378
379//________________________________________________________
380void AliITSVertexerPPZ::PrintStatus() const {
381 // Print current status
382 cout <<"=======================================================\n";
383 cout <<" First layer first and last modules: "<<fFirstL1<<", ";
384 cout <<fLastL1<<endl;
385 cout <<" Second layer first and last modules: "<<fFirstL2<<", ";
386 cout <<fLastL2<<endl;
387 cout <<" Max Phi difference: "<<fDiffPhiMax<<endl;
c95d6417 388 cout <<" Window for Z search: "<<fWindow<<endl;
c5f0f3c1 389 cout <<" Current Z "<<fZFound<<"; Z sig "<<fZsig<<endl;
c5f0f3c1 390 cout<<"First event to be processed "<<fFirstEvent;
391 cout<<"\n Last event to be processed "<<fLastEvent<<endl;
392}
c95d6417 393
394//________________________________________________________
395Float_t AliITSVertexerPPZ::Curv(Double_t x1,Double_t y1,
396 Double_t x2,Double_t y2,
397 Double_t x3,Double_t y3)
398{
399 //-----------------------------------------------------------------
400 // Initial approximation of the track curvature (Y. Belikov) squared
401 //-----------------------------------------------------------------
402 Double_t d=(x2-x1)*(y3-y2)-(x3-x2)*(y2-y1);
403 Double_t a=0.5*((y3-y2)*(y2*y2-y1*y1+x2*x2-x1*x1)-
404 (y2-y1)*(y3*y3-y2*y2+x3*x3-x2*x2));
405 Double_t b=0.5*((x2-x1)*(y3*y3-y2*y2+x3*x3-x2*x2)-
406 (x3-x2)*(y2*y2-y1*y1+x2*x2-x1*x1));
407
408 Double_t xr=TMath::Abs(d/(d*x1-a)), yr=d/(d*y1-b);
409
410 Float_t val = (Float_t)(( -xr*yr/TMath::Sqrt(xr*xr+yr*yr))
411 *( -xr*yr/TMath::Sqrt(xr*xr+yr*yr)));
412 return val;
413}