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