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 <AliITSVertexerZ.h>
16 #include <Riostream.h>
19 #include "AliITSLoader.h"
22 #include<TClonesArray.h>
26 #include <AliITSgeom.h>
27 #include <AliITSRecPoint.h>
29 /////////////////////////////////////////////////////////////////
30 // this class implements a fast method to determine
31 // the Z coordinate of the primary vertex
32 // for p-p collisions it seems to give comparable or better results
33 // with respect to what obtained with AliITSVertexerPPZ
34 // It can be used successfully with Pb-Pb collisions
35 ////////////////////////////////////////////////////////////////
37 ClassImp(AliITSVertexerZ)
41 //______________________________________________________________________
42 AliITSVertexerZ::AliITSVertexerZ():AliITSVertexer() {
43 // Default constructor
47 SetFirstLayerModules(0);
48 SetSecondLayerModules(0);
56 SetBinWidthCoarse(0.);
61 //______________________________________________________________________
62 AliITSVertexerZ::AliITSVertexerZ(TString fn, Float_t x0, Float_t y0):AliITSVertexer(fn) {
63 // Standard Constructor
67 SetFirstLayerModules();
68 SetSecondLayerModules();
82 //______________________________________________________________________
83 AliITSVertexerZ::AliITSVertexerZ(const AliITSVertexerZ &vtxr) : AliITSVertexer(vtxr) {
85 // Copies are not allowed. The method is protected to avoid misuse.
86 Error("AliITSVertexerZ","Copy constructor not allowed\n");
89 //______________________________________________________________________
90 AliITSVertexerZ& AliITSVertexerZ::operator=(const AliITSVertexerZ& /* vtxr */){
91 // Assignment operator
92 // Assignment is not allowed. The method is protected to avoid misuse.
93 Error("= operator","Assignment operator not allowed\n");
98 //______________________________________________________________________
99 AliITSVertexerZ::~AliITSVertexerZ() {
100 // Default Destructor
102 if(fZCombc)delete fZCombc;
103 if(fZCombf)delete fZCombf;
106 //______________________________________________________________________
107 AliESDVertex* AliITSVertexerZ::FindVertexForCurrentEvent(Int_t evnumber){
108 // Defines the AliESDVertex for the current event
111 AliRunLoader *rl =AliRunLoader::GetRunLoader();
112 AliITSLoader* itsLoader = (AliITSLoader*) rl->GetLoader("ITSLoader");
113 itsLoader->LoadRecPoints();
114 rl->GetEvent(evnumber);
117 fITS = (AliITS*)gAlice->GetModule("ITS");
119 Error("FindVertexForCurrentEvent","AliITS object was not found");
120 return fCurrentVertex;
124 fITS->SetTreeAddress();
126 AliITSgeom *geom = fITS->GetITSgeom();
128 TTree *tR = itsLoader->TreeR();
129 TClonesArray *itsRec = 0;
130 Float_t lc[3]; for(Int_t ii=0; ii<3; ii++) lc[ii]=0.;
131 Float_t gc[3]; for(Int_t ii=0; ii<3; ii++) gc[ii]=0.;
132 Float_t lc2[3]; for(Int_t ii=0; ii<3; ii++) lc2[ii]=0.;
133 Float_t gc2[3]; for(Int_t ii=0; ii<3; ii++) gc2[ii]=0.;
135 itsRec = fITS->RecPoints();
137 //cout<<"Address of itsRec = "<<itsRec<<endl;
138 TClonesArray dummy("AliITSclusterV2",10000), *clusters=&dummy;
141 branch = tR->GetBranch("Clusters");
142 branch->SetAddress(&clusters);
145 branch = tR->GetBranch("ITSRecPoints");
148 Int_t nbinfine = static_cast<Int_t>((fHighLim-fLowLim)/fStepFine);
149 Int_t nbincoarse = static_cast<Int_t>((fHighLim-fLowLim)/fStepCoarse);
150 if(fZCombc)delete fZCombc;
151 fZCombc = new TH1F("fZCombc","Z",nbincoarse,fLowLim,fLowLim+nbincoarse*fStepCoarse);
152 if(fZCombf)delete fZCombf;
153 fZCombf = new TH1F("fZCombf","Z",nbinfine,fLowLim,fLowLim+nbinfine*fStepFine);
157 for(Int_t module= fFirstL1; module<=fLastL1;module++){
158 if(module%4==0 || module%4==3)continue;
159 // cout<<"Procesing module "<<module<<" ";
160 branch->GetEvent(module);
161 // cout<<"Number of clusters "<<clusters->GetEntries()<<endl;
163 Clusters2RecPoints(clusters,module,itsRec);
165 nrpL1+= itsRec->GetEntries();
166 fITS->ResetRecPoints();
168 for(Int_t module= fFirstL2; module<=fLastL2;module++){
169 branch->GetEvent(module);
171 Clusters2RecPoints(clusters,module,itsRec);
173 nrpL2+= itsRec->GetEntries();
174 fITS->ResetRecPoints();
176 if(nrpL1 == 0 || nrpL2 == 0){
178 return fCurrentVertex;
180 Float_t *xc1 = new Float_t [nrpL1];
181 Float_t *yc1 = new Float_t [nrpL1];
182 Float_t *zc1 = new Float_t [nrpL1];
183 Float_t *phi1 = new Float_t [nrpL1];
184 Float_t *xc2 = new Float_t [nrpL2];
185 Float_t *yc2 = new Float_t [nrpL2];
186 Float_t *zc2 = new Float_t [nrpL2];
187 Float_t *phi2 = new Float_t [nrpL2];
189 for(Int_t module= fFirstL1; module<=fLastL1;module++){
190 if(module%4==0 || module%4==3)continue;
191 branch->GetEvent(module);
193 Clusters2RecPoints(clusters,module,itsRec);
195 Int_t nrecp1 = itsRec->GetEntries();
196 for(Int_t j=0;j<nrecp1;j++){
197 AliITSRecPoint *recp = (AliITSRecPoint*)itsRec->At(j);
200 geom->LtoG(module,lc,gc);
206 phi1[ind] = TMath::ATan2(gc[1],gc[0]);
207 if(phi1[ind]<0)phi1[ind]=2*TMath::Pi()+phi1[ind];
210 fITS->ResetRecPoints();
213 for(Int_t module= fFirstL2; module<=fLastL2;module++){
214 branch->GetEvent(module);
216 Clusters2RecPoints(clusters,module,itsRec);
218 Int_t nrecp2 = itsRec->GetEntries();
219 for(Int_t j=0;j<nrecp2;j++){
220 AliITSRecPoint *recp = (AliITSRecPoint*)itsRec->At(j);
223 geom->LtoG(module,lc,gc);
229 phi2[ind] = TMath::ATan2(gc[1],gc[0]);
230 if(phi2[ind]<0)phi2[ind]=2*TMath::Pi()+phi2[ind];
233 fITS->ResetRecPoints();
235 for(Int_t i=0;i<nrpL1;i++){
236 Float_t r1=TMath::Sqrt(xc1[i]*xc1[i]+yc1[i]*yc1[i]);
237 for(Int_t j=0;j<nrpL2;j++){
238 Float_t diff = TMath::Abs(phi2[j]-phi1[i]);
239 if(diff>TMath::Pi())diff=2.*TMath::Pi()-diff;
240 if(diff<fDiffPhiMax){
241 Float_t r2=TMath::Sqrt(xc2[j]*xc2[j]+yc2[j]*yc2[j]);
242 Float_t zr0=(r2*zc1[i]-r1*zc2[j])/(r2-r1);
256 if(fZCombc->GetEntries()==0){
257 Warning("FindVertexForCurrentEvent","Insufficient number of rec. points\n");
259 return fCurrentVertex;
262 // cout<<"Number of entries in hist. "<<fZCombc->GetEntries()<<endl;
264 Int_t bi = fZCombc->GetMaximumBin();
265 Float_t centre = fZCombc->GetBinCenter(bi);
266 Int_t n1 = static_cast<Int_t>((centre-fZCombc->GetBinWidth(bi)-fZCombf->GetBinLowEdge(0))/fZCombf->GetBinWidth(0));
267 Int_t n2 = static_cast<Int_t>((centre+fZCombc->GetBinWidth(bi)-fZCombf->GetBinLowEdge(0))/fZCombf->GetBinWidth(0));
275 for(Int_t n=n1;n<=n2;n++){
276 fZFound+=fZCombf->GetBinCenter(n)*fZCombf->GetBinContent(n);
277 num+=static_cast<Int_t>(fZCombf->GetBinContent(n));
278 fZsig+=fZCombf->GetBinCenter(n)*fZCombf->GetBinCenter(n)*fZCombf->GetBinContent(n);
284 Float_t radi = fZsig/(num-1)-fZFound*fZFound/num/(num-1);
285 if(radi>0.)fZsig=TMath::Sqrt(radi);
289 goon = TMath::Abs(TMath::Abs(fZFound-fZCombf->GetBinCenter(n1))-TMath::Abs(fZFound-fZCombf->GetBinCenter(n2)))>fTolerance;
290 n1 = static_cast<Int_t>((fZFound-fZCombc->GetBinWidth(bi)-fZCombf->GetBinLowEdge(0))/fZCombf->GetBinWidth(0));
291 n2 = static_cast<Int_t>((fZFound+fZCombc->GetBinWidth(bi)-fZCombf->GetBinLowEdge(0))/fZCombf->GetBinWidth(0));
295 Warning("FindVertexForCurrentEvent","The procedure dows not converge\n");
298 // cout<<"Numer of Iterations "<<niter<<endl<<endl;
299 fCurrentVertex = new AliESDVertex(fZFound,fZsig,num);
300 fCurrentVertex->SetTitle("vertexer: B");
302 return fCurrentVertex;
305 //_____________________________________________________________________
306 void AliITSVertexerZ::ResetHistograms(){
307 // delete TH1 data members
308 if(fZCombc)delete fZCombc;
309 if(fZCombf)delete fZCombf;
314 //______________________________________________________________________
315 void AliITSVertexerZ::FindVertices(){
316 // computes the vertices of the events in the range FirstEvent - LastEvent
317 AliRunLoader *rl = AliRunLoader::GetRunLoader();
318 AliITSLoader* itsLoader = (AliITSLoader*) rl->GetLoader("ITSLoader");
319 itsLoader->ReloadRecPoints();
320 for(Int_t i=fFirstEvent;i<=fLastEvent;i++){
321 cout<<"Processing event "<<i<<endl;
323 FindVertexForCurrentEvent(i);
325 WriteCurrentVertex();
329 cout<<"Vertex not found for event "<<i<<endl;
330 cout<<"fZFound = "<<fZFound<<", fZsig= "<<fZsig<<endl;
336 //________________________________________________________
337 void AliITSVertexerZ::PrintStatus() const {
338 // Print current status
339 cout <<"=======================================================\n";
340 cout <<" First layer first and last modules: "<<fFirstL1<<", ";
341 cout <<fLastL1<<endl;
342 cout <<" Second layer first and last modules: "<<fFirstL2<<", ";
343 cout <<fLastL2<<endl;
344 cout <<" Max Phi difference: "<<fDiffPhiMax<<endl;
345 cout <<"Limits for Z histograms: "<<fLowLim<<"; "<<fHighLim<<endl;
346 cout <<"Bin sizes for coarse and fine z histos "<<fStepCoarse<<"; "<<fStepFine<<endl;
347 cout <<" Current Z "<<fZFound<<"; Z sig "<<fZsig<<endl;
348 cout <<" Debug flag: "<<fDebug<<endl;
349 cout <<"First event to be processed "<<fFirstEvent;
350 cout <<"\n Last event to be processed "<<fLastEvent<<endl;
353 cout <<"=======================================================\n";