1 /**************************************************************************
2 * Copyright(c) 1998-2003, 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 **************************************************************************/
15 #include <AliITSVertexerPPZ.h>
16 #include <Riostream.h>
18 #include <TDirectory.h>
21 #include <TObjArray.h>
23 #include <TClonesArray.h>
26 #include "AliITSgeom.h"
27 #include "AliITSLoader.h"
28 #include "AliITSRecPoint.h"
29 /////////////////////////////////////////////////////////////////////////
31 // This class is intended to compute the Z coordinate of the //
32 // primary vertex for p-p interactions, or in general when the //
33 // number of secondaries is too slow to use the class //
34 // AliITSVertexerIons, which in turn is optimized for A-A collsions //
35 // Origin: masera@to.infn.it 9/12/2002 //
37 /////////////////////////////////////////////////////////////////////////
38 ClassImp(AliITSVertexerPPZ)
42 //______________________________________________________________________
43 AliITSVertexerPPZ::AliITSVertexerPPZ():AliITSVertexer() {
44 // Default Constructor
49 SetFirstLayerModules(0);
50 SetSecondLayerModules(0);
57 AliITSVertexerPPZ::AliITSVertexerPPZ(TString fn, Float_t x0, Float_t y0):AliITSVertexer(fn) {
58 // Standard constructor
62 SetFirstLayerModules();
63 SetSecondLayerModules();
70 //______________________________________________________________________
71 AliITSVertexerPPZ::~AliITSVertexerPPZ() {
76 //________________________________________________________
77 void AliITSVertexerPPZ::EvalZ(TH1F *hist,Int_t sepa, Int_t ncoinc, TArrayF *zval) {
78 Float_t DeltaVal = hist->GetBinWidth(1)*fWindow; // max window in Z for searching
86 for(Int_t i=1;i<=sepa;i++){
87 Float_t cont=hist->GetBinContent(i);
88 if(cont!=0)curz = hist->GetBinLowEdge(i)+0.5*hist->GetBinWidth(i);
92 if(cont!=0)NbinNotZero++;
94 if(NbinNotZero==0){fZFound=-100; fZsig=-100; return;}
98 fCurrentVertex = new AliESDVertex(fZFound,fZsig,NbinNotZero);
101 Float_t errsq = totst2/(N-1)-totst*totst/N/(N-1);
103 totst2=TMath::Sqrt(errsq);
106 Error("EvalZ","Negative variance: %d - %12.7f - %12.7f",N,totst2,totst);
112 Float_t cut = totst+totst2*2.;
113 if(fDebug>1)cout<<"totst, totst2, cut: "<<totst<<", "<<totst2<<", "<<cut<<endl;
114 Float_t val1=hist->GetBinLowEdge(sepa);
115 Float_t val2=hist->GetBinLowEdge(1);
118 for(Int_t i=1;i<=sepa;i++){
119 Float_t cont=hist->GetBinContent(i);
122 zmax = hist->GetBinLowEdge(i)+0.5*hist->GetBinWidth(1);
125 curz=hist->GetBinLowEdge(i);
126 if(curz<val1)val1=curz;
127 if(curz>val2)val2=curz;
130 val2+=hist->GetBinWidth(1);
131 if((val2-val1)>DeltaVal){
132 val1 = zmax-DeltaVal/2.;
133 val2 = zmax+DeltaVal/2.;
134 if(fDebug>0)cout<<"val1 and val2 recomputed\n";
136 if(fDebug>0)cout<<"Values for Z finding: "<<val1<<" "<<val2<<" "<<val2-val1<<endl;
140 for(Int_t i=0; i<ncoinc; i++){
141 Float_t z=zval->At(i);
147 /* weights defined by the curvature
148 Float_t wei = 1./curv->At(i);
154 if(N<1){fZFound=-110; fZsig=-110; return;}
157 fCurrentVertex = new AliESDVertex(fZFound,fZsig,N);
160 errsq = (fZsig/(N-1)-fZFound*fZFound/N/(N-1))/N;
162 fZsig=TMath::Sqrt(errsq);
165 Error("evalZ","Negative variance: %d - %12.7f %12.7f",N,fZsig,fZFound);
169 /* weights defined by the curvature
172 fZsig = TMath::Sqrt(fZsig);
174 fCurrentVertex = new AliESDVertex(fZFound,fZsig,N);
177 //______________________________________________________________________
178 AliESDVertex* AliITSVertexerPPZ::FindVertexForCurrentEvent(Int_t evnumber){
179 // Defines the AliESDVertex for the current event
183 AliRunLoader *rl =AliRunLoader::GetRunLoader();
184 AliITSLoader* ITSloader = (AliITSLoader*) rl->GetLoader("ITSLoader");
186 fITS = (AliITS*)gAlice->GetModule("ITS");
188 Error("FindVertexForCurrentEvent","AliITS object was not found");
189 return fCurrentVertex;
192 fITS->SetTreeAddress();
193 AliITSgeom *geom = fITS->GetITSgeom();
195 Error("FindVertexForCurrentEvent","ITS geometry is not defined");
196 return fCurrentVertex;
199 TClonesArray *itsRec = 0;
200 Float_t lc[3]; for(Int_t ii=0; ii<3; ii++) lc[ii]=0.;
201 Float_t gc[3]; for(Int_t ii=0; ii<3; ii++) gc[ii]=0.;
202 Float_t lc2[3]; for(Int_t ii=0; ii<3; ii++) lc2[ii]=0.;
203 Float_t gc2[3]; for(Int_t ii=0; ii<3; ii++) gc2[ii]=0.;
205 tR = ITSloader->TreeR();
207 Error("FindVertexForCurrentEvent","TreeR not found");
208 return fCurrentVertex;
210 itsRec = fITS->RecPoints(); // uses slow points or fast points if slow are
212 TClonesArray dummy("AliITSclusterV2",10000), *clusters=&dummy;
215 branch = tR->GetBranch("Clusters");
216 branch->SetAddress(&clusters);
219 branch = tR->GetBranch("ITSRecPoints");
221 branch = tR->GetBranch("ITSRecPointsF");
225 Error("FindVertexForCurrentEvent","branch for ITS rec points not found");
226 return fCurrentVertex;
232 for(Int_t module= fFirstL1; module<=fLastL1;module++){
233 branch->GetEvent(module);
235 Clusters2RecPoints(clusters,module,itsRec);
237 Int_t nrecp1 = itsRec->GetEntries();
238 for(Int_t i=0; i<nrecp1;i++){
239 AliITSRecPoint *current = (AliITSRecPoint*)itsRec->At(i);
240 lc[0]=current->GetX();
241 lc[2]=current->GetZ();
242 geom->LtoG(module,lc,gc);
247 fITS->ResetRecPoints();
250 rmszav=TMath::Sqrt(zave2/(firipixe-1)-zave*zave/firipixe/(firipixe-1));
252 if(fDebug>1)cout<<"++++++++++++++++++++++++++++++++++++++++++++++++++++++\n Number of firing pixels: "<<firipixe<<endl;
257 Warning("FindVertexForCurrentEvent","No rec points on first layer for this event");
258 return fCurrentVertex;
260 Float_t zlim1=zave-rmszav;
261 Float_t zlim2=zave+rmszav;
262 Int_t sepa=(Int_t)((zlim2-zlim1)*10.+1.);
263 zlim2=zlim1 + sepa/10.;
264 TH1F *zvdis = new TH1F("z_ev","zv distr",sepa,zlim1,zlim2);
266 cout<<"Z limits: "<<zlim1<<" "<<zlim2<<"; Bins= "<<sepa<<endl;
267 cout<<"Bin width: "<<zvdis->GetBinWidth(1)*10000.<<" micron\n";
270 TArrayF *zval = new TArrayF(sizarr);
271 // TArrayF *curv = new TArrayF(sizarr);
273 for(Int_t module= fFirstL1; module<=fLastL1;module++){
274 if(fDebug>0)cout<<"processing module "<<module<<" \r";
275 branch->GetEvent(module);
277 Clusters2RecPoints(clusters,module,itsRec);
279 Int_t nrecp1 = itsRec->GetEntries();
280 TObjArray *poiL1 = new TObjArray(nrecp1);
281 for(Int_t i=0; i<nrecp1;i++)poiL1->AddAt(itsRec->At(i),i);
282 fITS->ResetRecPoints();
283 for(Int_t i=0; i<nrecp1;i++){
284 AliITSRecPoint *current = (AliITSRecPoint*)poiL1->At(i);
285 lc[0]=current->GetX();
286 lc[2]=current->GetZ();
287 geom->LtoG(module,lc,gc);
290 Float_t r1=TMath::Sqrt(gc[0]*gc[0]+gc[1]*gc[1]);
291 Float_t phi1 = TMath::ATan2(gc[1],gc[0]);
292 if(phi1<0)phi1=2*TMath::Pi()+phi1;
293 if(fDebug>1)cout<<"module "<<module<<" "<<gc[0]<<" "<<gc[1]<<" "<<gc[2]<<" "<<phi1<<" \n";
294 for(Int_t modul2=fFirstL2; modul2<=fLastL2; modul2++){
295 branch->GetEvent(modul2);
297 Clusters2RecPoints(clusters,modul2,itsRec);
299 Int_t nrecp2 = itsRec->GetEntries();
300 for(Int_t j=0; j<nrecp2;j++){
301 AliITSRecPoint *recp = (AliITSRecPoint*)itsRec->At(j);
304 geom->LtoG(modul2,lc2,gc2);
307 Float_t r2=TMath::Sqrt(gc2[0]*gc2[0]+gc2[1]*gc2[1]);
308 Float_t zr0=(r2*gc[2]-r1*gc2[2])/(r2-r1);
309 Float_t phi2 = TMath::ATan2(gc2[1],gc2[0]);
310 if(phi2<0)phi2=2.*TMath::Pi()+phi2;
311 Float_t diff = TMath::Abs(phi2-phi1);
312 if(diff>TMath::Pi())diff=2.*TMath::Pi()-diff;
313 if(zr0>zlim1 && zr0<zlim2){
314 if(diff<fDiffPhiMax ){
316 zval->AddAt(zr0,ncoinc);
317 /* uncomment these lines to use curvature as a weight
318 Float_t cu = Curv(0.,0.,gc[0],gc[1],gc2[0],gc[1]);
319 curv->AddAt(cu,ncoinc);
322 if(ncoinc==(sizarr-1)){
325 //uncomment next line to use curvature as weight
326 // curv->Set(sizarr);
331 fITS->ResetRecPoints();
337 cout<<endl<<"Number of coincidences = "<<ncoinc<<endl;
339 // EvalZ(zvdis,sepa,ncoinc,zval,curv);
340 EvalZ(zvdis,sepa,ncoinc,zval);
346 sprintf(name,"Vertex_%d",evnumber);
347 // fCurrentVertex->SetName(name);
348 fCurrentVertex->SetTitle("vertexer: PPZ");
350 return fCurrentVertex;
353 //______________________________________________________________________
354 void AliITSVertexerPPZ::FindVertices(){
355 // computes the vertices of the events in the range FirstEvent - LastEvent
356 AliRunLoader *rl = AliRunLoader::GetRunLoader();
357 AliITSLoader* ITSloader = (AliITSLoader*) rl->GetLoader("ITSLoader");
358 ITSloader->ReloadRecPoints();
359 for(Int_t i=fFirstEvent;i<=fLastEvent;i++){
360 cout<<"Processing event "<<i<<endl;
362 FindVertexForCurrentEvent(i);
364 WriteCurrentVertex();
368 cout<<"Vertex not found for event "<<i<<endl;
369 cout<<"fZFound = "<<fZFound<<", fZsig= "<<fZsig<<endl;
375 //________________________________________________________
376 void AliITSVertexerPPZ::PrintStatus() const {
377 // Print current status
378 cout <<"=======================================================\n";
379 cout <<" First layer first and last modules: "<<fFirstL1<<", ";
380 cout <<fLastL1<<endl;
381 cout <<" Second layer first and last modules: "<<fFirstL2<<", ";
382 cout <<fLastL2<<endl;
383 cout <<" Max Phi difference: "<<fDiffPhiMax<<endl;
384 cout <<" Window for Z search: "<<fWindow<<endl;
385 cout <<" Current Z "<<fZFound<<"; Z sig "<<fZsig<<endl;
386 cout <<" Debug flag: "<<fDebug<<endl;
387 cout<<"First event to be processed "<<fFirstEvent;
388 cout<<"\n Last event to be processed "<<fLastEvent<<endl;
391 //________________________________________________________
392 Float_t AliITSVertexerPPZ::Curv(Double_t x1,Double_t y1,
393 Double_t x2,Double_t y2,
394 Double_t x3,Double_t y3)
396 //-----------------------------------------------------------------
397 // Initial approximation of the track curvature (Y. Belikov) squared
398 //-----------------------------------------------------------------
399 Double_t d=(x2-x1)*(y3-y2)-(x3-x2)*(y2-y1);
400 Double_t a=0.5*((y3-y2)*(y2*y2-y1*y1+x2*x2-x1*x1)-
401 (y2-y1)*(y3*y3-y2*y2+x3*x3-x2*x2));
402 Double_t b=0.5*((x2-x1)*(y3*y3-y2*y2+x3*x3-x2*x2)-
403 (x3-x2)*(y2*y2-y1*y1+x2*x2-x1*x1));
405 Double_t xr=TMath::Abs(d/(d*x1-a)), yr=d/(d*y1-b);
407 Float_t val = (Float_t)(( -xr*yr/TMath::Sqrt(xr*xr+yr*yr))
408 *( -xr*yr/TMath::Sqrt(xr*xr+yr*yr)));