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