]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITSVertexer.cxx
29aa88bb6f8134e3d9bb3cedc5daf84d5b8d2dec
[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 //______________________________________________________________________
20 AliITSVertexer::AliITSVertexer():AliVertexer(),
21 fLadders(), 
22 fLadOnLay2(0),
23 fFirstEvent(0),
24 fLastEvent(-1)
25 {
26   // Default Constructor
27   SetLaddersOnLayer2();
28 }
29
30 //______________________________________________________________________
31 AliITSVertexer::~AliITSVertexer() {
32   // Destructor
33  if(fLadders) delete [] fLadders;
34 }
35
36 //______________________________________________________________________
37 void AliITSVertexer::FindMultiplicity(TTree *itsClusterTree){
38   // Invokes AliITSMultReconstructor to determine the
39   // charged multiplicity in the pixel layers
40   if(fMult){delete fMult; fMult = 0;}
41   Bool_t success=kTRUE;
42   if(!fCurrentVertex)success=kFALSE;
43   if(fCurrentVertex && fCurrentVertex->GetNContributors()<1)success=kFALSE;
44
45   AliITSMultReconstructor multReco;
46
47   if(!success){
48     AliWarning("Tracklets multiplicity not determined because the primary vertex was not found");
49     AliWarning("Just counting the number of cluster-fired chips on the SPD layers");
50     if (!itsClusterTree) {
51       AliError(" Invalid ITS cluster tree !\n");
52       return;
53     }
54     multReco.LoadClusterFiredChips(itsClusterTree);
55     Short_t nfcL1 = multReco.GetNFiredChips(0);
56     Short_t nfcL2 = multReco.GetNFiredChips(1);
57     fMult = new AliMultiplicity(0,0,0,0,0,0,0,0,0,nfcL1,nfcL2);
58     return;
59   }
60
61   if (!itsClusterTree) {
62     AliError(" Invalid ITS cluster tree !\n");
63     return;
64   }
65   Double_t vtx[3];
66   fCurrentVertex->GetXYZ(vtx);
67   Float_t vtxf[3];
68   for(Int_t i=0;i<3;i++)vtxf[i]=vtx[i];
69   multReco.SetHistOn(kFALSE);
70   multReco.Reconstruct(itsClusterTree,vtxf,vtxf);
71   Int_t notracks=multReco.GetNTracklets();
72   Float_t *tht = new Float_t [notracks];
73   Float_t *phi = new Float_t [notracks];
74   Float_t *dphi = new Float_t [notracks];
75   Int_t *labels = new Int_t[notracks];
76   Int_t *labelsL2 = new Int_t[notracks];
77   for(Int_t i=0;i<multReco.GetNTracklets();i++){
78     tht[i] = multReco.GetTracklet(i)[0];
79     phi[i] =  multReco.GetTracklet(i)[1];
80     dphi[i] = multReco.GetTracklet(i)[2];
81     labels[i] = static_cast<Int_t>(multReco.GetTracklet(i)[3]);
82     labelsL2[i] = static_cast<Int_t>(multReco.GetTracklet(i)[4]);
83   }
84   Int_t nosingleclus=multReco.GetNSingleClusters();
85   Float_t *ths = new Float_t [nosingleclus];
86   Float_t *phs = new Float_t [nosingleclus];
87   for(Int_t i=0;i<nosingleclus;i++){
88     ths[i] = multReco.GetCluster(i)[0];
89     phs[i] = multReco.GetCluster(i)[1];
90   }
91   Short_t nfcL1 = multReco.GetNFiredChips(0);
92   Short_t nfcL2 = multReco.GetNFiredChips(1);
93   multReco.Dump();
94   fMult = new AliMultiplicity(notracks,tht,phi,dphi,labels,labelsL2,nosingleclus,ths,phs,nfcL1,nfcL2);
95
96   delete [] tht;
97   delete [] phi;
98   delete [] dphi;
99   delete [] ths;
100   delete [] phs;
101   delete [] labels;
102   delete [] labelsL2;
103
104   return;
105 }
106
107 //______________________________________________________________________
108 void AliITSVertexer::SetLaddersOnLayer2(Int_t ladwid){
109   // Calculates the array of ladders on layer 2 to be used with a 
110   // given ladder on layer 1
111   fLadOnLay2=ladwid;
112   Int_t ladtot1=AliITSgeomTGeo::GetNLadders(1);
113   if(fLadders) delete [] fLadders;
114   fLadders=new UShort_t[ladtot1];
115
116
117   Double_t pos1[3],pos2[3];
118   Int_t mod1=AliITSgeomTGeo::GetModuleIndex(2,1,1);
119   AliITSgeomTGeo::GetTranslation(mod1,pos1);  // position of the module in the MRS 
120   Double_t phi0=TMath::ATan2(pos1[1],pos1[0]);
121   if(phi0<0) phi0+=2*TMath::Pi();
122   Int_t mod2=AliITSgeomTGeo::GetModuleIndex(2,2,1);
123   AliITSgeomTGeo::GetTranslation(mod2,pos2);
124   Double_t phi2=TMath::ATan2(pos2[1],pos2[0]); 
125   if(phi2<0) phi2+=2*TMath::Pi();
126   Double_t deltaPhi= phi0-phi2; // phi width of a layer2 module
127
128   for(Int_t i= 0; i<ladtot1;i++){
129     Int_t modlad= AliITSgeomTGeo::GetModuleIndex(1,i+1,1);
130     Double_t posmod[3];
131     AliITSgeomTGeo::GetTranslation(modlad,posmod);
132     Double_t phimod=TMath::ATan2(posmod[1],posmod[0]); 
133     if(phimod<0) phimod+=2*TMath::Pi();
134     Double_t phi1= phimod+deltaPhi*double(fLadOnLay2);
135     if(phi1<0) phi1+=2*TMath::Pi();
136     if(phi1>2*TMath::Pi()) phi1-=2*TMath::Pi();
137     Double_t philad1=phi0-phi1;
138     UShort_t lad1;
139     Double_t ladder1=(philad1)/(deltaPhi) +1.; 
140     if(ladder1<1){ladder1=40+ladder1;}
141     lad1=int(ladder1+0.5);
142     fLadders[i]=lad1;
143   }
144 }
145
146 #include "AliRunLoader.h"
147
148 //______________________________________________________________________
149 void AliITSVertexer::Init(TString filename){
150   // Initialize the vertexer in case of
151   // analysis of an entire file
152   AliRunLoader *rl = AliRunLoader::GetRunLoader();
153   if(!rl){
154     Fatal("AliITSVertexer","Run Loader not found");
155   }
156   if (fLastEvent < 0) SetLastEvent(rl->GetNumberOfEvents()-1);
157
158   AliITSLoader* itsloader =  (AliITSLoader*) rl->GetLoader("ITSLoader");
159   if(!filename.Contains("default"))itsloader->SetVerticesFileName(filename);
160   if(!filename.Contains("null"))itsloader->LoadVertices("recreate");
161 }
162
163 //______________________________________________________________________
164 void AliITSVertexer::WriteCurrentVertex(){
165   // Write the current AliVertex object to file fOutFile
166   AliRunLoader *rl = AliRunLoader::GetRunLoader();
167   AliITSLoader* itsLoader =  (AliITSLoader*) rl->GetLoader("ITSLoader");
168   fCurrentVertex->SetName("Vertex");
169   //  const char * name = fCurrentVertex->GetName();
170   //  itsLoader->SetVerticesContName(name);
171   Int_t rc = itsLoader->PostVertex(fCurrentVertex);
172   rc = itsLoader->WriteVertices();
173 }
174
175 //______________________________________________________________________
176 void AliITSVertexer::FindVertices(){
177   // computes the vertices of the events in the range FirstEvent - LastEvent
178
179   AliRunLoader *rl = AliRunLoader::GetRunLoader();
180   AliITSLoader* itsloader =  (AliITSLoader*) rl->GetLoader("ITSLoader");
181   itsloader->LoadRecPoints("read");
182   for(Int_t i=fFirstEvent;i<=fLastEvent;i++){
183     rl->GetEvent(i);
184     TTree* cltree = itsloader->TreeR();
185     FindVertexForCurrentEvent(cltree);
186     if(fCurrentVertex){
187       WriteCurrentVertex();
188     }
189     else {
190       AliDebug(1,Form("Vertex not found for event %d",i));
191     }
192   }
193 }