4 #include "AliGeomManager.h"
5 #include "AliITSDetTypeRec.h"
6 #include "AliITSInitGeometry.h"
7 #include "AliITSMeanVertexer.h"
8 #include "AliITSLoader.h"
10 #include "AliRawReader.h"
11 #include "AliRawReaderDate.h"
12 #include "AliRawReaderRoot.h"
13 #include "AliRunLoader.h"
14 #include "AliITSVertexer3D.h"
15 #include "AliITSVertexer3DTapan.h"
16 #include "AliESDVertex.h"
17 #include "AliMeanVertex.h"
18 #include "AliMultiplicity.h"
20 ClassImp(AliITSMeanVertexer)
22 ///////////////////////////////////////////////////////////////////////
24 // Class to compute vertex position using SPD local reconstruction //
25 // An average vertex position using all the events //
26 // is built and saved //
27 // Individual vertices can be optionally stored //
28 // Origin: M.Masera (masera@to.infn.it) //
30 // AliITSMeanVertexer mv("RawDataFileName");
31 // mv.SetGeometryFileName("FileWithGeometry.root"); // def. geometry.root
32 // .... optional setters ....
33 // mv.Reconstruct(); // SPD local reconstruction
35 // Resulting AliMeanVertex object is stored in a file named fMVFileName
36 ///////////////////////////////////////////////////////////////////////
40 //______________________________________________________________________
41 AliITSMeanVertexer::AliITSMeanVertexer():TObject(),
48 fSigmaOnAverTracks(0.),
49 fFilterOnContributors(0),
52 // Default Constructor
53 for(Int_t i=0;i<3;i++){
57 for(Int_t j=0; j<3;j++)fAverPosSq[i][j] = 0.;
60 // Histograms initialization
61 const Float_t xLimit = 2.0, yLimit = 2.0, zLimit = 50.0;
62 const Float_t xDelta = 0.02, yDelta = 0.02, zDelta = 0.2;
63 fVertexXY = new TH2F("VertexXY","Vertex Diamond (Y vs X)",
64 2*(Int_t)(xLimit/xDelta),-xLimit,xLimit,
65 2*(Int_t)(yLimit/yDelta),-yLimit,yLimit);
66 fVertexZ = new TH1F("VertexZ"," Longitudinal Vertex Profile",
67 2*(Int_t)(zLimit/zDelta),-zLimit,zLimit);
70 //______________________________________________________________________
71 Bool_t AliITSMeanVertexer::Init() {
73 // Initialize geometry
74 // Initialize ITS classes
76 AliGeomManager::LoadGeometry();
77 if (!AliGeomManager::ApplyAlignObjsFromCDB("ITS")) return kFALSE;
79 AliITSInitGeometry initgeom;
80 AliITSgeom *geom = initgeom.CreateAliITSgeom();
81 if (!geom) return kFALSE;
82 printf("Geometry name: %s \n",(initgeom.GetGeometryName()).Data());
84 fDetTypeRec = new AliITSDetTypeRec();
85 fDetTypeRec->SetITSgeom(geom);
86 fDetTypeRec->SetDefaults();
87 fDetTypeRec->SetDefaultClusterFindersV2(kTRUE);
89 // Initialize filter values to their defaults
90 SetFilterOnContributors();
91 SetFilterOnTracklets();
96 //______________________________________________________________________
97 AliITSMeanVertexer::~AliITSMeanVertexer() {
104 //______________________________________________________________________
105 Bool_t AliITSMeanVertexer::Reconstruct(AliRawReader *rawReader, Bool_t mode){
106 // Performs SPD local reconstruction
107 // and vertex finding
108 // returns true in case a vertex is found
110 // Run SPD cluster finder
111 TTree* clustersTree = new TTree("TreeR", "Reconstructed Points Container"); //make a tree
112 fDetTypeRec->DigitsToRecPoints(rawReader,clustersTree,"SPD");
114 Bool_t vtxOK = kFALSE;
115 AliESDVertex *vtx = NULL;
116 // Run Tapan's vertex-finder
118 AliITSVertexer3DTapan *vertexer1 = new AliITSVertexer3DTapan(1000);
119 vtx = vertexer1->FindVertexForCurrentEvent(clustersTree);
121 if (TMath::Abs(vtx->GetChi2()) < 0.1) vtxOK = kTRUE;
124 // Run standard vertexer3d
125 AliITSVertexer3D *vertexer2 = new AliITSVertexer3D();
126 vtx = vertexer2->FindVertexForCurrentEvent(clustersTree);
127 AliMultiplicity *mult = vertexer2->GetMultiplicity();
129 if(Filter(vtx,mult)) vtxOK = kTRUE;
132 if (vtxOK) AddToMean(vtx);
138 //______________________________________________________________________
139 void AliITSMeanVertexer::WriteVertices(const char *filename){
140 // Compute mean vertex and
141 // store it along with the histograms
144 TFile fmv(filename,"update");
148 cov[0] = fAverPosSq[0][0]; // variance x
149 cov[1] = fAverPosSq[0][1]; // cov xy
150 cov[2] = fAverPosSq[1][1]; // variance y
151 cov[3] = fAverPosSq[0][2]; // cov xz
152 cov[4] = fAverPosSq[1][2]; // cov yz
153 cov[5] = fAverPosSq[2][2]; // variance z
154 AliMeanVertex mv(fWeighPos,fWeighSig,cov,fNoEventsContr,fTotTracklets,fAverTracklets,fSigmaOnAverTracks);
155 mv.SetTitle("Mean Vertex");
156 mv.SetName("MeanVertex");
157 AliDebug(1,Form("Contrib av. trk = %10.2f ",mv.GetAverageNumbOfTracklets()));
158 AliDebug(1,Form("Sigma %10.4f ",mv.GetSigmaOnAvNumbOfTracks()));
159 // we have to add chi2 here
160 AliESDVertex vtx(fWeighPos,cov,0,fAverTracklets,"MeanVertexPos");
162 mv.Write(mv.GetName(),TObject::kOverwrite);
163 vtx.Write(vtx.GetName(),TObject::kOverwrite);
166 AliError(Form("Evaluation of mean vertex not possible. Number of used events = %d",fNoEventsContr));
169 fVertexXY->Write(fVertexXY->GetName(),TObject::kOverwrite);
170 fVertexZ->Write(fVertexZ->GetName(),TObject::kOverwrite);
174 //______________________________________________________________________
175 Bool_t AliITSMeanVertexer::Filter(AliESDVertex *vert,AliMultiplicity *mult){
176 // Apply selection criteria to events
177 Bool_t status = kFALSE;
178 if(!vert || !mult)return status;
179 Int_t ncontr = vert->GetNContributors();
180 Int_t ntracklets = mult->GetNumberOfTracklets();
181 AliDebug(1,Form("Number of contributors = %d",ncontr));
182 AliDebug(1,Form("Number of tracklets = %d",ntracklets));
183 if(ncontr>fFilterOnContributors && ntracklets > fFilterOnTracklets) status = kTRUE;
184 fAverTracklets += ntracklets;
185 fSigmaOnAverTracks += ntracklets*ntracklets;
189 //______________________________________________________________________
190 void AliITSMeanVertexer::AddToMean(AliESDVertex *vert){
191 // update mean vertex
192 Double_t currentPos[3],currentSigma[3];
193 vert->GetXYZ(currentPos);
194 vert->GetSigmaXYZ(currentSigma);
196 for(Int_t i=0;i<3;i++)if(currentSigma[i] == 0.)goon = kFALSE;
198 for(Int_t i=0;i<3;i++){
199 fWeighPos[i]+=currentPos[i]/currentSigma[i]/currentSigma[i];
200 fWeighSig[i]+=1./currentSigma[i]/currentSigma[i];
201 fAverPos[i]+=currentPos[i];
203 for(Int_t i=0;i<3;i++){
204 for(Int_t j=i;j<3;j++){
205 fAverPosSq[i][j] += currentPos[i] * currentPos[j];
209 fVertexXY->Fill(currentPos[0],currentPos[1]);
210 fVertexZ->Fill(currentPos[2]);
215 //______________________________________________________________________
216 Bool_t AliITSMeanVertexer::ComputeMean(){
217 // compute mean vertex
218 if(fNoEventsContr < 2) return kFALSE;
219 Double_t nevents = fNoEventsContr;
220 for(Int_t i=0;i<3;i++){
221 fWeighPos[i] /= fWeighSig[i];
222 fWeighSig[i] = 1./TMath::Sqrt(fWeighSig[i]);
223 fAverPos[i] /= nevents;
225 for(Int_t i=0;i<3;i++){
226 for(Int_t j=i;j<3;j++){
227 fAverPosSq[i][j] /= (nevents -1.);
228 fAverPosSq[i][j] -= nevents/(nevents -1.)*fAverPos[i]*fAverPos[j];
231 fTotTracklets = fAverTracklets; // total number of tracklets used
232 fAverTracklets /= nevents;
233 fSigmaOnAverTracks /= (nevents - 1);
234 Double_t tmp = nevents/(nevents -1.)*fAverTracklets*fAverTracklets;
235 fSigmaOnAverTracks -= tmp;
236 fSigmaOnAverTracks = TMath::Sqrt(fSigmaOnAverTracks);