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>
17 #include "AliITSLoader.h"
19 #include<TClonesArray.h>
22 #include <AliITSgeom.h>
23 #include "AliITSDetTypeRec.h"
24 #include <AliITSRecPoint.h>
26 /////////////////////////////////////////////////////////////////
27 // this class implements a fast method to determine
28 // the Z coordinate of the primary vertex
29 // for p-p collisions it seems to give comparable or better results
30 // with respect to what obtained with AliITSVertexerPPZ
31 // It can be used successfully with Pb-Pb collisions
32 ////////////////////////////////////////////////////////////////
34 ClassImp(AliITSVertexerZ)
38 //______________________________________________________________________
39 AliITSVertexerZ::AliITSVertexerZ():AliITSVertexer() {
40 // Default constructor
44 SetFirstLayerModules(0);
45 SetSecondLayerModules(0);
52 SetBinWidthCoarse(0.);
57 //______________________________________________________________________
58 AliITSVertexerZ::AliITSVertexerZ(TString fn, Float_t x0, Float_t y0):AliITSVertexer(fn) {
59 // Standard Constructor
63 SetFirstLayerModules();
64 SetSecondLayerModules();
77 //______________________________________________________________________
78 AliITSVertexerZ::AliITSVertexerZ(const AliITSVertexerZ &vtxr) : AliITSVertexer(vtxr) {
80 // Copies are not allowed. The method is protected to avoid misuse.
81 Error("AliITSVertexerZ","Copy constructor not allowed\n");
84 //______________________________________________________________________
85 AliITSVertexerZ& AliITSVertexerZ::operator=(const AliITSVertexerZ& /* vtxr */){
86 // Assignment operator
87 // Assignment is not allowed. The method is protected to avoid misuse.
88 Error("= operator","Assignment operator not allowed\n");
93 //______________________________________________________________________
94 AliITSVertexerZ::~AliITSVertexerZ() {
97 if(fZCombc)delete fZCombc;
98 if(fZCombf)delete fZCombf;
101 //______________________________________________________________________
102 AliESDVertex* AliITSVertexerZ::FindVertexForCurrentEvent(Int_t evnumber){
103 // Defines the AliESDVertex for the current event
106 AliRunLoader *rl =AliRunLoader::GetRunLoader();
107 AliITSLoader* itsLoader = (AliITSLoader*)rl->GetLoader("ITSLoader");
108 TDirectory * olddir = gDirectory;
110 AliITSgeom* geom = (AliITSgeom*)gDirectory->Get("AliITSgeom");
113 itsLoader->LoadRecPoints();
114 rl->GetEvent(evnumber);
116 AliITSDetTypeRec detTypeRec;
118 TTree *tR = itsLoader->TreeR();
119 detTypeRec.SetTreeAddressR(tR);
120 TClonesArray *itsRec = 0;
121 Float_t lc[3]; for(Int_t ii=0; ii<3; ii++) lc[ii]=0.;
122 Float_t gc[3]; for(Int_t ii=0; ii<3; ii++) gc[ii]=0.;
123 Float_t lc2[3]; for(Int_t ii=0; ii<3; ii++) lc2[ii]=0.;
124 Float_t gc2[3]; for(Int_t ii=0; ii<3; ii++) gc2[ii]=0.;
126 itsRec = detTypeRec.RecPoints();
128 branch = tR->GetBranch("ITSRecPoints");
130 Int_t nbinfine = static_cast<Int_t>((fHighLim-fLowLim)/fStepFine);
131 Int_t nbincoarse = static_cast<Int_t>((fHighLim-fLowLim)/fStepCoarse);
132 if(fZCombc)delete fZCombc;
133 fZCombc = new TH1F("fZCombc","Z",nbincoarse,fLowLim,fLowLim+nbincoarse*fStepCoarse);
134 if(fZCombf)delete fZCombf;
135 fZCombf = new TH1F("fZCombf","Z",nbinfine,fLowLim,fLowLim+nbinfine*fStepFine);
139 for(Int_t module= fFirstL1; module<=fLastL1;module++){
140 if(module%4==0 || module%4==3)continue;
141 branch->GetEvent(module);
142 nrpL1+= itsRec->GetEntries();
143 detTypeRec.ResetRecPoints();
145 for(Int_t module= fFirstL2; module<=fLastL2;module++){
146 branch->GetEvent(module);
147 nrpL2+= itsRec->GetEntries();
148 detTypeRec.ResetRecPoints();
150 if(nrpL1 == 0 || nrpL2 == 0){
152 return fCurrentVertex;
154 Float_t *xc1 = new Float_t [nrpL1];
155 Float_t *yc1 = new Float_t [nrpL1];
156 Float_t *zc1 = new Float_t [nrpL1];
157 Float_t *phi1 = new Float_t [nrpL1];
158 Float_t *xc2 = new Float_t [nrpL2];
159 Float_t *yc2 = new Float_t [nrpL2];
160 Float_t *zc2 = new Float_t [nrpL2];
161 Float_t *phi2 = new Float_t [nrpL2];
163 for(Int_t module= fFirstL1; module<=fLastL1;module++){
164 if(module%4==0 || module%4==3)continue;
165 branch->GetEvent(module);
166 Int_t nrecp1 = itsRec->GetEntries();
167 for(Int_t j=0;j<nrecp1;j++){
168 AliITSRecPoint *recp = (AliITSRecPoint*)itsRec->At(j);
169 lc[0]=recp->GetDetLocalX();
170 lc[2]=recp->GetDetLocalZ();
171 geom->LtoG(module,lc,gc);
177 phi1[ind] = TMath::ATan2(gc[1],gc[0]);
178 if(phi1[ind]<0)phi1[ind]=2*TMath::Pi()+phi1[ind];
181 detTypeRec.ResetRecPoints();
184 for(Int_t module= fFirstL2; module<=fLastL2;module++){
185 branch->GetEvent(module);
186 Int_t nrecp2 = itsRec->GetEntries();
187 for(Int_t j=0;j<nrecp2;j++){
188 AliITSRecPoint *recp = (AliITSRecPoint*)itsRec->At(j);
189 lc[0]=recp->GetDetLocalX();
190 lc[2]=recp->GetDetLocalZ();
191 geom->LtoG(module,lc,gc);
197 phi2[ind] = TMath::ATan2(gc[1],gc[0]);
198 if(phi2[ind]<0)phi2[ind]=2*TMath::Pi()+phi2[ind];
201 detTypeRec.ResetRecPoints();
203 for(Int_t i=0;i<nrpL1;i++){
204 Float_t r1=TMath::Sqrt(xc1[i]*xc1[i]+yc1[i]*yc1[i]);
205 for(Int_t j=0;j<nrpL2;j++){
206 Float_t diff = TMath::Abs(phi2[j]-phi1[i]);
207 if(diff>TMath::Pi())diff=2.*TMath::Pi()-diff;
208 if(diff<fDiffPhiMax){
209 Float_t r2=TMath::Sqrt(xc2[j]*xc2[j]+yc2[j]*yc2[j]);
210 Float_t zr0=(r2*zc1[i]-r1*zc2[j])/(r2-r1);
224 if(fZCombc->GetEntries()==0){
225 Warning("FindVertexForCurrentEvent","Insufficient number of rec. points\n");
227 return fCurrentVertex;
230 // cout<<"Number of entries in hist. "<<fZCombc->GetEntries()<<endl;
232 Int_t bi = fZCombc->GetMaximumBin();
233 Float_t centre = fZCombc->GetBinCenter(bi);
234 Int_t n1 = static_cast<Int_t>((centre-fZCombc->GetBinWidth(bi)-fZCombf->GetBinLowEdge(0))/fZCombf->GetBinWidth(0));
235 Int_t n2 = static_cast<Int_t>((centre+fZCombc->GetBinWidth(bi)-fZCombf->GetBinLowEdge(0))/fZCombf->GetBinWidth(0));
243 for(Int_t n=n1;n<=n2;n++){
244 fZFound+=fZCombf->GetBinCenter(n)*fZCombf->GetBinContent(n);
245 num+=static_cast<Int_t>(fZCombf->GetBinContent(n));
246 fZsig+=fZCombf->GetBinCenter(n)*fZCombf->GetBinCenter(n)*fZCombf->GetBinContent(n);
252 Float_t radi = fZsig/(num-1)-fZFound*fZFound/num/(num-1);
253 if(radi>0.)fZsig=TMath::Sqrt(radi);
257 goon = TMath::Abs(TMath::Abs(fZFound-fZCombf->GetBinCenter(n1))-TMath::Abs(fZFound-fZCombf->GetBinCenter(n2)))>fTolerance;
258 n1 = static_cast<Int_t>((fZFound-fZCombc->GetBinWidth(bi)-fZCombf->GetBinLowEdge(0))/fZCombf->GetBinWidth(0));
259 n2 = static_cast<Int_t>((fZFound+fZCombc->GetBinWidth(bi)-fZCombf->GetBinLowEdge(0))/fZCombf->GetBinWidth(0));
263 Warning("FindVertexForCurrentEvent","The procedure dows not converge\n");
266 // cout<<"Numer of Iterations "<<niter<<endl<<endl;
267 fCurrentVertex = new AliESDVertex(fZFound,fZsig,num);
268 fCurrentVertex->SetTitle("vertexer: B");
270 return fCurrentVertex;
273 //_____________________________________________________________________
274 void AliITSVertexerZ::ResetHistograms(){
275 // delete TH1 data members
276 if(fZCombc)delete fZCombc;
277 if(fZCombf)delete fZCombf;
282 //______________________________________________________________________
283 void AliITSVertexerZ::FindVertices(){
284 // computes the vertices of the events in the range FirstEvent - LastEvent
285 AliRunLoader *rl = AliRunLoader::GetRunLoader();
286 AliITSLoader* itsLoader = (AliITSLoader*) rl->GetLoader("ITSLoader");
287 itsLoader->ReloadRecPoints();
288 for(Int_t i=fFirstEvent;i<=fLastEvent;i++){
289 cout<<"Processing event "<<i<<endl;
291 FindVertexForCurrentEvent(i);
293 WriteCurrentVertex();
297 cout<<"Vertex not found for event "<<i<<endl;
298 cout<<"fZFound = "<<fZFound<<", fZsig= "<<fZsig<<endl;
304 //________________________________________________________
305 void AliITSVertexerZ::PrintStatus() const {
306 // Print current status
307 cout <<"=======================================================\n";
308 cout <<" First layer first and last modules: "<<fFirstL1<<", ";
309 cout <<fLastL1<<endl;
310 cout <<" Second layer first and last modules: "<<fFirstL2<<", ";
311 cout <<fLastL2<<endl;
312 cout <<" Max Phi difference: "<<fDiffPhiMax<<endl;
313 cout <<"Limits for Z histograms: "<<fLowLim<<"; "<<fHighLim<<endl;
314 cout <<"Bin sizes for coarse and fine z histos "<<fStepCoarse<<"; "<<fStepFine<<endl;
315 cout <<" Current Z "<<fZFound<<"; Z sig "<<fZsig<<endl;
316 cout <<" Debug flag: "<<fDebug<<endl;
317 cout <<"First event to be processed "<<fFirstEvent;
318 cout <<"\n Last event to be processed "<<fLastEvent<<endl;
321 cout <<"=======================================================\n";