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();
127 // TClonesArray dummy("AliITSRecPoint",10000), *clusters=&dummy;
129 //if(fUseV2Clusters){
130 // branch = tR->GetBranch("ITSRecPoints");
131 // branch->SetAddress(&clusters);
134 branch = tR->GetBranch("ITSRecPoints");
137 Int_t nbinfine = static_cast<Int_t>((fHighLim-fLowLim)/fStepFine);
138 Int_t nbincoarse = static_cast<Int_t>((fHighLim-fLowLim)/fStepCoarse);
139 if(fZCombc)delete fZCombc;
140 fZCombc = new TH1F("fZCombc","Z",nbincoarse,fLowLim,fLowLim+nbincoarse*fStepCoarse);
141 if(fZCombf)delete fZCombf;
142 fZCombf = new TH1F("fZCombf","Z",nbinfine,fLowLim,fLowLim+nbinfine*fStepFine);
146 for(Int_t module= fFirstL1; module<=fLastL1;module++){
147 if(module%4==0 || module%4==3)continue;
148 // cout<<"Procesing module "<<module<<" ";
149 branch->GetEvent(module);
150 // cout<<"Number of clusters "<<clusters->GetEntries()<<endl;
151 //if(fUseV2Clusters){
152 // Clusters2RecPoints(clusters,module,itsRec);
154 nrpL1+= itsRec->GetEntries();
155 detTypeRec.ResetRecPoints();
157 for(Int_t module= fFirstL2; module<=fLastL2;module++){
158 branch->GetEvent(module);
159 //if(fUseV2Clusters){
160 // Clusters2RecPoints(clusters,module,itsRec);
162 nrpL2+= itsRec->GetEntries();
163 detTypeRec.ResetRecPoints();
165 if(nrpL1 == 0 || nrpL2 == 0){
167 return fCurrentVertex;
169 Float_t *xc1 = new Float_t [nrpL1];
170 Float_t *yc1 = new Float_t [nrpL1];
171 Float_t *zc1 = new Float_t [nrpL1];
172 Float_t *phi1 = new Float_t [nrpL1];
173 Float_t *xc2 = new Float_t [nrpL2];
174 Float_t *yc2 = new Float_t [nrpL2];
175 Float_t *zc2 = new Float_t [nrpL2];
176 Float_t *phi2 = new Float_t [nrpL2];
178 for(Int_t module= fFirstL1; module<=fLastL1;module++){
179 if(module%4==0 || module%4==3)continue;
180 branch->GetEvent(module);
181 //if(fUseV2Clusters){
182 // Clusters2RecPoints(clusters,module,itsRec);
184 Int_t nrecp1 = itsRec->GetEntries();
185 for(Int_t j=0;j<nrecp1;j++){
186 AliITSRecPoint *recp = (AliITSRecPoint*)itsRec->At(j);
187 lc[0]=recp->GetDetLocalX();
188 lc[2]=recp->GetDetLocalZ();
189 geom->LtoG(module,lc,gc);
195 phi1[ind] = TMath::ATan2(gc[1],gc[0]);
196 if(phi1[ind]<0)phi1[ind]=2*TMath::Pi()+phi1[ind];
199 detTypeRec.ResetRecPoints();
202 for(Int_t module= fFirstL2; module<=fLastL2;module++){
203 branch->GetEvent(module);
204 //if(fUseV2Clusters){
205 // Clusters2RecPoints(clusters,module,itsRec);
207 Int_t nrecp2 = itsRec->GetEntries();
208 for(Int_t j=0;j<nrecp2;j++){
209 AliITSRecPoint *recp = (AliITSRecPoint*)itsRec->At(j);
210 lc[0]=recp->GetDetLocalX();
211 lc[2]=recp->GetDetLocalZ();
212 geom->LtoG(module,lc,gc);
218 phi2[ind] = TMath::ATan2(gc[1],gc[0]);
219 if(phi2[ind]<0)phi2[ind]=2*TMath::Pi()+phi2[ind];
222 detTypeRec.ResetRecPoints();
224 for(Int_t i=0;i<nrpL1;i++){
225 Float_t r1=TMath::Sqrt(xc1[i]*xc1[i]+yc1[i]*yc1[i]);
226 for(Int_t j=0;j<nrpL2;j++){
227 Float_t diff = TMath::Abs(phi2[j]-phi1[i]);
228 if(diff>TMath::Pi())diff=2.*TMath::Pi()-diff;
229 if(diff<fDiffPhiMax){
230 Float_t r2=TMath::Sqrt(xc2[j]*xc2[j]+yc2[j]*yc2[j]);
231 Float_t zr0=(r2*zc1[i]-r1*zc2[j])/(r2-r1);
245 if(fZCombc->GetEntries()==0){
246 Warning("FindVertexForCurrentEvent","Insufficient number of rec. points\n");
248 return fCurrentVertex;
251 // cout<<"Number of entries in hist. "<<fZCombc->GetEntries()<<endl;
253 Int_t bi = fZCombc->GetMaximumBin();
254 Float_t centre = fZCombc->GetBinCenter(bi);
255 Int_t n1 = static_cast<Int_t>((centre-fZCombc->GetBinWidth(bi)-fZCombf->GetBinLowEdge(0))/fZCombf->GetBinWidth(0));
256 Int_t n2 = static_cast<Int_t>((centre+fZCombc->GetBinWidth(bi)-fZCombf->GetBinLowEdge(0))/fZCombf->GetBinWidth(0));
264 for(Int_t n=n1;n<=n2;n++){
265 fZFound+=fZCombf->GetBinCenter(n)*fZCombf->GetBinContent(n);
266 num+=static_cast<Int_t>(fZCombf->GetBinContent(n));
267 fZsig+=fZCombf->GetBinCenter(n)*fZCombf->GetBinCenter(n)*fZCombf->GetBinContent(n);
273 Float_t radi = fZsig/(num-1)-fZFound*fZFound/num/(num-1);
274 if(radi>0.)fZsig=TMath::Sqrt(radi);
278 goon = TMath::Abs(TMath::Abs(fZFound-fZCombf->GetBinCenter(n1))-TMath::Abs(fZFound-fZCombf->GetBinCenter(n2)))>fTolerance;
279 n1 = static_cast<Int_t>((fZFound-fZCombc->GetBinWidth(bi)-fZCombf->GetBinLowEdge(0))/fZCombf->GetBinWidth(0));
280 n2 = static_cast<Int_t>((fZFound+fZCombc->GetBinWidth(bi)-fZCombf->GetBinLowEdge(0))/fZCombf->GetBinWidth(0));
284 Warning("FindVertexForCurrentEvent","The procedure dows not converge\n");
287 // cout<<"Numer of Iterations "<<niter<<endl<<endl;
288 fCurrentVertex = new AliESDVertex(fZFound,fZsig,num);
289 fCurrentVertex->SetTitle("vertexer: B");
291 return fCurrentVertex;
294 //_____________________________________________________________________
295 void AliITSVertexerZ::ResetHistograms(){
296 // delete TH1 data members
297 if(fZCombc)delete fZCombc;
298 if(fZCombf)delete fZCombf;
303 //______________________________________________________________________
304 void AliITSVertexerZ::FindVertices(){
305 // computes the vertices of the events in the range FirstEvent - LastEvent
306 AliRunLoader *rl = AliRunLoader::GetRunLoader();
307 AliITSLoader* itsLoader = (AliITSLoader*) rl->GetLoader("ITSLoader");
308 itsLoader->ReloadRecPoints();
309 for(Int_t i=fFirstEvent;i<=fLastEvent;i++){
310 cout<<"Processing event "<<i<<endl;
312 FindVertexForCurrentEvent(i);
314 WriteCurrentVertex();
318 cout<<"Vertex not found for event "<<i<<endl;
319 cout<<"fZFound = "<<fZFound<<", fZsig= "<<fZsig<<endl;
325 //________________________________________________________
326 void AliITSVertexerZ::PrintStatus() const {
327 // Print current status
328 cout <<"=======================================================\n";
329 cout <<" First layer first and last modules: "<<fFirstL1<<", ";
330 cout <<fLastL1<<endl;
331 cout <<" Second layer first and last modules: "<<fFirstL2<<", ";
332 cout <<fLastL2<<endl;
333 cout <<" Max Phi difference: "<<fDiffPhiMax<<endl;
334 cout <<"Limits for Z histograms: "<<fLowLim<<"; "<<fHighLim<<endl;
335 cout <<"Bin sizes for coarse and fine z histos "<<fStepCoarse<<"; "<<fStepFine<<endl;
336 cout <<" Current Z "<<fZFound<<"; Z sig "<<fZsig<<endl;
337 cout <<" Debug flag: "<<fDebug<<endl;
338 cout <<"First event to be processed "<<fFirstEvent;
339 cout <<"\n Last event to be processed "<<fLastEvent<<endl;
342 cout <<"=======================================================\n";