]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITSVertexer.cxx
Updates concerning the SPD QA (D. Elia)
[u/mrichter/AliRoot.git] / ITS / AliITSVertexer.cxx
1 #include "AliLog.h"
2 #include "AliMultiplicity.h"
3 #include "AliITSgeomTGeo.h"
4 #include "AliITSVertexer.h"
5 #include "AliITSLoader.h"
6 #include "AliITSMultReconstructor.h"
7
8 const Float_t AliITSVertexer::fgkPipeRadius = 3.0;
9
10 ClassImp(AliITSVertexer)
11
12 //////////////////////////////////////////////////////////////////////
13 // Base class for primary vertex reconstruction                     //
14 // AliESDVertexer is a class for full 3D primary vertex finding     //
15 // derived classes: AliITSVertexerIons AliITSvertexer3D             //
16 //                  AliITSVertexerCosmics                           //
17 //////////////////////////////////////////////////////////////////////
18
19 /* $Id$ */
20
21 //______________________________________________________________________
22 AliITSVertexer::AliITSVertexer():AliVertexer(),
23 fLadders(), 
24 fLadOnLay2(0),
25 fDetTypeRec(NULL),
26 fMinTrackletsForPilup(0),
27 fIsPileup(0),
28 fNTrpuv(-2),
29 fZpuv(-9999999.),
30 fNoVertices(0),
31 fVertArray(NULL),
32 fFirstEvent(0),
33 fLastEvent(-1)
34 {
35   // Default Constructor
36   SetLaddersOnLayer2();
37   SetMinTrackletsForPilup();
38   for(Int_t i=0; i<kNSPDMod;i++) fUseModule[i]=kTRUE;
39 }
40
41 //______________________________________________________________________
42 AliITSVertexer::~AliITSVertexer() {
43   // Destructor
44   if(fLadders) delete [] fLadders;
45   if (fNoVertices > 0){
46     delete []fVertArray;
47     fVertArray = NULL;
48     fNoVertices = 0;
49   }
50 }
51
52 //______________________________________________________________________
53 void AliITSVertexer::ResetVertex(){
54   // Resets vertex related data members
55   if(fNoVertices > 0){
56     if(fVertArray) delete []fVertArray;
57     fVertArray = NULL;
58     fNoVertices = 0;
59   }
60   fIsPileup=kFALSE;
61   fNTrpuv=-2;
62   fZpuv=-99999.;
63
64 }
65 //______________________________________________________________________
66 void AliITSVertexer::FindMultiplicity(TTree *itsClusterTree){
67   // Invokes AliITSMultReconstructor to determine the
68   // charged multiplicity in the pixel layers
69   if(fMult){delete fMult; fMult = 0;}
70   Bool_t success=kTRUE;
71   if(!fCurrentVertex)success=kFALSE;
72   if(fCurrentVertex && fCurrentVertex->GetNContributors()<1)success=kFALSE;
73
74   // get the FastOr bit mask
75   TBits fastOrFiredMap = fDetTypeRec->GetFastOrFiredMap();
76
77   AliITSMultReconstructor multReco;
78
79   if(!success){
80     AliWarning("Tracklets multiplicity not determined because the primary vertex was not found");
81     AliWarning("Just counting the number of cluster-fired chips on the SPD layers");
82     if (!itsClusterTree) {
83       AliError(" Invalid ITS cluster tree !\n");
84       return;
85     }
86     multReco.LoadClusterFiredChips(itsClusterTree);
87     Short_t nfcL1 = multReco.GetNFiredChips(0);
88     Short_t nfcL2 = multReco.GetNFiredChips(1);
89     fMult = new AliMultiplicity(0,0,0,0,0,0,0,0,0,0,nfcL1,nfcL2,fastOrFiredMap);
90     return;
91   }
92
93   if (!itsClusterTree) {
94     AliError(" Invalid ITS cluster tree !\n");
95     return;
96   }
97   Double_t vtx[3];
98   fCurrentVertex->GetXYZ(vtx);
99   Float_t vtxf[3];
100   for(Int_t i=0;i<3;i++)vtxf[i]=vtx[i];
101   multReco.SetHistOn(kFALSE);
102   multReco.Reconstruct(itsClusterTree,vtxf,vtxf);
103   Int_t notracks=multReco.GetNTracklets();
104   Float_t *tht = new Float_t [notracks];
105   Float_t *phi = new Float_t [notracks];
106   Float_t *dtht = new Float_t [notracks];
107   Float_t *dphi = new Float_t [notracks];
108   Int_t *labels = new Int_t[notracks];
109   Int_t *labelsL2 = new Int_t[notracks];
110   for(Int_t i=0;i<multReco.GetNTracklets();i++){
111     tht[i] = multReco.GetTracklet(i)[0];
112     phi[i] =  multReco.GetTracklet(i)[1];
113     dtht[i] = multReco.GetTracklet(i)[3];
114     dphi[i] = multReco.GetTracklet(i)[2];
115     labels[i] = static_cast<Int_t>(multReco.GetTracklet(i)[4]);
116     labelsL2[i] = static_cast<Int_t>(multReco.GetTracklet(i)[5]);
117   }
118   Int_t nosingleclus=multReco.GetNSingleClusters();
119   Float_t *ths = new Float_t [nosingleclus];
120   Float_t *phs = new Float_t [nosingleclus];
121   for(Int_t i=0;i<nosingleclus;i++){
122     ths[i] = multReco.GetCluster(i)[0];
123     phs[i] = multReco.GetCluster(i)[1];
124   }
125   Short_t nfcL1 = multReco.GetNFiredChips(0);
126   Short_t nfcL2 = multReco.GetNFiredChips(1);
127   fMult = new AliMultiplicity(notracks,tht,phi,dtht,dphi,labels,labelsL2,nosingleclus,ths,phs,nfcL1,nfcL2,fastOrFiredMap);
128
129   delete [] tht;
130   delete [] phi;
131   delete [] dtht;
132   delete [] dphi;
133   delete [] ths;
134   delete [] phs;
135   delete [] labels;
136   delete [] labelsL2;
137
138   return;
139 }
140
141 //______________________________________________________________________
142 void AliITSVertexer::SetLaddersOnLayer2(Int_t ladwid){
143   // Calculates the array of ladders on layer 2 to be used with a 
144   // given ladder on layer 1
145   fLadOnLay2=ladwid;
146   Int_t ladtot1=AliITSgeomTGeo::GetNLadders(1);
147   if(fLadders) delete [] fLadders;
148   fLadders=new UShort_t[ladtot1];
149
150
151   Double_t pos1[3],pos2[3];
152   Int_t mod1=AliITSgeomTGeo::GetModuleIndex(2,1,1);
153   AliITSgeomTGeo::GetTranslation(mod1,pos1);  // position of the module in the MRS 
154   Double_t phi0=TMath::ATan2(pos1[1],pos1[0]);
155   if(phi0<0) phi0+=2*TMath::Pi();
156   Int_t mod2=AliITSgeomTGeo::GetModuleIndex(2,2,1);
157   AliITSgeomTGeo::GetTranslation(mod2,pos2);
158   Double_t phi2=TMath::ATan2(pos2[1],pos2[0]); 
159   if(phi2<0) phi2+=2*TMath::Pi();
160   Double_t deltaPhi= phi0-phi2; // phi width of a layer2 module
161
162   for(Int_t i= 0; i<ladtot1;i++){
163     Int_t modlad= AliITSgeomTGeo::GetModuleIndex(1,i+1,1);
164     Double_t posmod[3];
165     AliITSgeomTGeo::GetTranslation(modlad,posmod);
166     Double_t phimod=TMath::ATan2(posmod[1],posmod[0]); 
167     if(phimod<0) phimod+=2*TMath::Pi();
168     Double_t phi1= phimod+deltaPhi*double(fLadOnLay2);
169     if(phi1<0) phi1+=2*TMath::Pi();
170     if(phi1>2*TMath::Pi()) phi1-=2*TMath::Pi();
171     Double_t philad1=phi0-phi1;
172     UShort_t lad1;
173     Double_t ladder1=(philad1)/(deltaPhi) +1.; 
174     if(ladder1<1){ladder1=40+ladder1;}
175     lad1=int(ladder1+0.5);
176     fLadders[i]=lad1;
177   }
178 }
179
180 #include "AliRunLoader.h"
181
182 //______________________________________________________________________
183 void AliITSVertexer::Init(TString filename){
184   // Initialize the vertexer in case of
185   // analysis of an entire file
186   AliRunLoader *rl = AliRunLoader::Instance();
187   if(!rl){
188     Fatal("AliITSVertexer","Run Loader not found");
189   }
190   if (fLastEvent < 0) SetLastEvent(rl->GetNumberOfEvents()-1);
191
192   AliITSLoader* itsloader =  (AliITSLoader*) rl->GetLoader("ITSLoader");
193   if(!filename.Contains("default"))itsloader->SetVerticesFileName(filename);
194   if(!filename.Contains("null"))itsloader->LoadVertices("recreate");
195 }
196
197 //______________________________________________________________________
198 void AliITSVertexer::WriteCurrentVertex(){
199   // Write the current AliVertex object to file fOutFile
200   AliRunLoader *rl = AliRunLoader::Instance();
201   AliITSLoader* itsLoader =  (AliITSLoader*) rl->GetLoader("ITSLoader");
202   fCurrentVertex->SetName("Vertex");
203   //  const char * name = fCurrentVertex->GetName();
204   //  itsLoader->SetVerticesContName(name);
205   Int_t rc = itsLoader->PostVertex(fCurrentVertex);
206   rc = itsLoader->WriteVertices();
207 }
208
209 //______________________________________________________________________
210 void AliITSVertexer::FindVertices(){
211   // computes the vertices of the events in the range FirstEvent - LastEvent
212
213   AliRunLoader *rl = AliRunLoader::Instance();
214   AliITSLoader* itsloader =  (AliITSLoader*) rl->GetLoader("ITSLoader");
215   itsloader->LoadRecPoints("read");
216   for(Int_t i=fFirstEvent;i<=fLastEvent;i++){
217     rl->GetEvent(i);
218     TTree* cltree = itsloader->TreeR();
219     FindVertexForCurrentEvent(cltree);
220     if(fCurrentVertex){
221       WriteCurrentVertex();
222     }
223     else {
224       AliDebug(1,Form("Vertex not found for event %d",i));
225     }
226   }
227 }