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