]>
Commit | Line | Data |
---|---|---|
a3a3a28f | 1 | #include <TFile.h> |
37add1d1 | 2 | #include <TH1.h> |
3 | #include <TH2.h> | |
a3a3a28f | 4 | #include "AliGeomManager.h" |
a3a3a28f | 5 | #include "AliITSDetTypeRec.h" |
6 | #include "AliITSInitGeometry.h" | |
7 | #include "AliITSMeanVertexer.h" | |
d5eae813 | 8 | #include "AliITSRecPointContainer.h" |
a3a3a28f | 9 | #include "AliITSLoader.h" |
10 | #include "AliLog.h" | |
11 | #include "AliRawReader.h" | |
12 | #include "AliRawReaderDate.h" | |
13 | #include "AliRawReaderRoot.h" | |
14 | #include "AliRunLoader.h" | |
15 | #include "AliITSVertexer3D.h" | |
37add1d1 | 16 | #include "AliITSVertexer3DTapan.h" |
a3a3a28f | 17 | #include "AliESDVertex.h" |
18 | #include "AliMeanVertex.h" | |
19 | #include "AliMultiplicity.h" | |
20 | ||
a3a3a28f | 21 | ClassImp(AliITSMeanVertexer) |
22 | ||
23 | /////////////////////////////////////////////////////////////////////// | |
24 | // // | |
25 | // Class to compute vertex position using SPD local reconstruction // | |
26 | // An average vertex position using all the events // | |
27 | // is built and saved // | |
28 | // Individual vertices can be optionally stored // | |
29 | // Origin: M.Masera (masera@to.infn.it) // | |
30 | // Usage: | |
31 | // AliITSMeanVertexer mv("RawDataFileName"); | |
32 | // mv.SetGeometryFileName("FileWithGeometry.root"); // def. geometry.root | |
33 | // .... optional setters .... | |
34 | // mv.Reconstruct(); // SPD local reconstruction | |
35 | // mv.DoVertices(); | |
36 | // Resulting AliMeanVertex object is stored in a file named fMVFileName | |
37 | /////////////////////////////////////////////////////////////////////// | |
38 | ||
39 | /* $Id$ */ | |
40 | ||
41 | //______________________________________________________________________ | |
d5eae813 | 42 | AliITSMeanVertexer::AliITSMeanVertexer(Bool_t mode):TObject(), |
37add1d1 | 43 | fDetTypeRec(NULL), |
44 | fVertexXY(NULL), | |
45 | fVertexZ(NULL), | |
a3a3a28f | 46 | fNoEventsContr(0), |
47 | fTotTracklets(0.), | |
48 | fAverTracklets(0.), | |
762133f4 | 49 | fTotTrackletsSq(0.), |
a3a3a28f | 50 | fSigmaOnAverTracks(0.), |
51 | fFilterOnContributors(0), | |
d5eae813 | 52 | fFilterOnTracklets(0), |
53 | fMode(mode), | |
54 | fVertexer(NULL) | |
a3a3a28f | 55 | { |
56 | // Default Constructor | |
57 | for(Int_t i=0;i<3;i++){ | |
762133f4 | 58 | fWeighPosSum[i] = 0.; |
59 | fWeighSigSum[i] = 0.; | |
60 | fAverPosSum[i] = 0.; | |
a3a3a28f | 61 | fWeighPos[i] = 0.; |
62 | fWeighSig[i] = 0.; | |
63 | fAverPos[i] = 0.; | |
64 | for(Int_t j=0; j<3;j++)fAverPosSq[i][j] = 0.; | |
762133f4 | 65 | for(Int_t j=0; j<3;j++)fAverPosSqSum[i][j] = 0.; |
a3a3a28f | 66 | } |
a3a3a28f | 67 | |
37add1d1 | 68 | // Histograms initialization |
8d7f6205 | 69 | const Float_t xLimit = 5.0, yLimit = 5.0, zLimit = 50.0; |
37add1d1 | 70 | const Float_t xDelta = 0.02, yDelta = 0.02, zDelta = 0.2; |
71 | fVertexXY = new TH2F("VertexXY","Vertex Diamond (Y vs X)", | |
72 | 2*(Int_t)(xLimit/xDelta),-xLimit,xLimit, | |
73 | 2*(Int_t)(yLimit/yDelta),-yLimit,yLimit); | |
63845149 | 74 | fVertexXY->SetXTitle("X , cm"); |
75 | fVertexXY->SetYTitle("Y , cm"); | |
76 | fVertexXY->SetOption("colz"); | |
37add1d1 | 77 | fVertexZ = new TH1F("VertexZ"," Longitudinal Vertex Profile", |
78 | 2*(Int_t)(zLimit/zDelta),-zLimit,zLimit); | |
63845149 | 79 | fVertexZ->SetXTitle("Z , cm"); |
a3a3a28f | 80 | } |
81 | ||
82 | //______________________________________________________________________ | |
37add1d1 | 83 | Bool_t AliITSMeanVertexer::Init() { |
84 | // Initialize filters | |
a3a3a28f | 85 | // Initialize geometry |
37add1d1 | 86 | // Initialize ITS classes |
a3a3a28f | 87 | |
37add1d1 | 88 | AliGeomManager::LoadGeometry(); |
89 | if (!AliGeomManager::ApplyAlignObjsFromCDB("ITS")) return kFALSE; | |
a3a3a28f | 90 | |
91 | AliITSInitGeometry initgeom; | |
92 | AliITSgeom *geom = initgeom.CreateAliITSgeom(); | |
37add1d1 | 93 | if (!geom) return kFALSE; |
a3a3a28f | 94 | printf("Geometry name: %s \n",(initgeom.GetGeometryName()).Data()); |
37add1d1 | 95 | |
cf0b1cea | 96 | fDetTypeRec = new AliITSDetTypeRec(); |
762133f4 | 97 | fDetTypeRec->SetLoadOnlySPDCalib(kTRUE); |
37add1d1 | 98 | fDetTypeRec->SetITSgeom(geom); |
99 | fDetTypeRec->SetDefaults(); | |
100 | fDetTypeRec->SetDefaultClusterFindersV2(kTRUE); | |
101 | ||
a3a3a28f | 102 | // Initialize filter values to their defaults |
103 | SetFilterOnContributors(); | |
104 | SetFilterOnTracklets(); | |
a3a3a28f | 105 | |
d5eae813 | 106 | // Instatiate vertexer |
107 | if (!fMode) { | |
108 | fVertexer = new AliITSVertexer3DTapan(1000); | |
109 | } | |
110 | else { | |
111 | fVertexer = new AliITSVertexer3D(); | |
112 | fVertexer->SetDetTypeRec(fDetTypeRec); | |
113 | fVertexer->SetComputeMultiplicity(kTRUE); | |
114 | } | |
37add1d1 | 115 | return kTRUE; |
a3a3a28f | 116 | } |
117 | ||
118 | //______________________________________________________________________ | |
119 | AliITSMeanVertexer::~AliITSMeanVertexer() { | |
120 | // Destructor | |
37add1d1 | 121 | delete fDetTypeRec; |
122 | delete fVertexXY; | |
123 | delete fVertexZ; | |
d5eae813 | 124 | delete fVertexer; |
a3a3a28f | 125 | } |
126 | ||
127 | //______________________________________________________________________ | |
d5eae813 | 128 | Bool_t AliITSMeanVertexer::Reconstruct(AliRawReader *rawReader){ |
a3a3a28f | 129 | // Performs SPD local reconstruction |
37add1d1 | 130 | // and vertex finding |
131 | // returns true in case a vertex is found | |
132 | ||
133 | // Run SPD cluster finder | |
d5eae813 | 134 | AliITSRecPointContainer::Instance()->PrepareToRead(); |
37add1d1 | 135 | TTree* clustersTree = new TTree("TreeR", "Reconstructed Points Container"); //make a tree |
136 | fDetTypeRec->DigitsToRecPoints(rawReader,clustersTree,"SPD"); | |
137 | ||
138 | Bool_t vtxOK = kFALSE; | |
d5eae813 | 139 | AliESDVertex *vtx = fVertexer->FindVertexForCurrentEvent(clustersTree); |
140 | if (!fMode) { | |
37add1d1 | 141 | if (TMath::Abs(vtx->GetChi2()) < 0.1) vtxOK = kTRUE; |
a3a3a28f | 142 | } |
37add1d1 | 143 | else { |
d5eae813 | 144 | AliMultiplicity *mult = fVertexer->GetMultiplicity(); |
37add1d1 | 145 | if(Filter(vtx,mult)) vtxOK = kTRUE; |
a3a3a28f | 146 | } |
37add1d1 | 147 | delete clustersTree; |
148 | if (vtxOK) AddToMean(vtx); | |
149 | if (vtx) delete vtx; | |
a3a3a28f | 150 | |
37add1d1 | 151 | return vtxOK; |
a3a3a28f | 152 | } |
153 | ||
154 | //______________________________________________________________________ | |
37add1d1 | 155 | void AliITSMeanVertexer::WriteVertices(const char *filename){ |
156 | // Compute mean vertex and | |
157 | // store it along with the histograms | |
158 | // in a file | |
159 | ||
160 | TFile fmv(filename,"update"); | |
161 | ||
a3a3a28f | 162 | if(ComputeMean()){ |
163 | Double_t cov[6]; | |
164 | cov[0] = fAverPosSq[0][0]; // variance x | |
165 | cov[1] = fAverPosSq[0][1]; // cov xy | |
166 | cov[2] = fAverPosSq[1][1]; // variance y | |
167 | cov[3] = fAverPosSq[0][2]; // cov xz | |
168 | cov[4] = fAverPosSq[1][2]; // cov yz | |
169 | cov[5] = fAverPosSq[2][2]; // variance z | |
37add1d1 | 170 | AliMeanVertex mv(fWeighPos,fWeighSig,cov,fNoEventsContr,fTotTracklets,fAverTracklets,fSigmaOnAverTracks); |
a3a3a28f | 171 | mv.SetTitle("Mean Vertex"); |
37add1d1 | 172 | mv.SetName("MeanVertex"); |
a3a3a28f | 173 | AliDebug(1,Form("Contrib av. trk = %10.2f ",mv.GetAverageNumbOfTracklets())); |
174 | AliDebug(1,Form("Sigma %10.4f ",mv.GetSigmaOnAvNumbOfTracks())); | |
37add1d1 | 175 | // we have to add chi2 here |
762133f4 | 176 | AliESDVertex vtx(fWeighPos,cov,0,TMath::Nint(fAverTracklets),"MeanVertexPos"); |
37add1d1 | 177 | |
178 | mv.Write(mv.GetName(),TObject::kOverwrite); | |
179 | vtx.Write(vtx.GetName(),TObject::kOverwrite); | |
a3a3a28f | 180 | } |
181 | else { | |
182 | AliError(Form("Evaluation of mean vertex not possible. Number of used events = %d",fNoEventsContr)); | |
183 | } | |
37add1d1 | 184 | |
185 | fVertexXY->Write(fVertexXY->GetName(),TObject::kOverwrite); | |
186 | fVertexZ->Write(fVertexZ->GetName(),TObject::kOverwrite); | |
187 | fmv.Close(); | |
a3a3a28f | 188 | } |
189 | ||
190 | //______________________________________________________________________ | |
191 | Bool_t AliITSMeanVertexer::Filter(AliESDVertex *vert,AliMultiplicity *mult){ | |
192 | // Apply selection criteria to events | |
193 | Bool_t status = kFALSE; | |
194 | if(!vert || !mult)return status; | |
8d7f6205 | 195 | // Remove vertices reconstructed with vertexerZ |
196 | if(strcmp(vert->GetName(),"SPDVertexZ") == 0) return status; | |
a3a3a28f | 197 | Int_t ncontr = vert->GetNContributors(); |
198 | Int_t ntracklets = mult->GetNumberOfTracklets(); | |
199 | AliDebug(1,Form("Number of contributors = %d",ncontr)); | |
200 | AliDebug(1,Form("Number of tracklets = %d",ntracklets)); | |
201 | if(ncontr>fFilterOnContributors && ntracklets > fFilterOnTracklets) status = kTRUE; | |
762133f4 | 202 | fTotTracklets += ntracklets; |
203 | fTotTrackletsSq += ntracklets*ntracklets; | |
a3a3a28f | 204 | return status; |
205 | } | |
206 | ||
207 | //______________________________________________________________________ | |
208 | void AliITSMeanVertexer::AddToMean(AliESDVertex *vert){ | |
209 | // update mean vertex | |
210 | Double_t currentPos[3],currentSigma[3]; | |
211 | vert->GetXYZ(currentPos); | |
212 | vert->GetSigmaXYZ(currentSigma); | |
213 | Bool_t goon = kTRUE; | |
214 | for(Int_t i=0;i<3;i++)if(currentSigma[i] == 0.)goon = kFALSE; | |
215 | if(!goon)return; | |
216 | for(Int_t i=0;i<3;i++){ | |
762133f4 | 217 | fWeighPosSum[i]+=currentPos[i]/currentSigma[i]/currentSigma[i]; |
218 | fWeighSigSum[i]+=1./currentSigma[i]/currentSigma[i]; | |
219 | fAverPosSum[i]+=currentPos[i]; | |
a3a3a28f | 220 | } |
221 | for(Int_t i=0;i<3;i++){ | |
222 | for(Int_t j=i;j<3;j++){ | |
762133f4 | 223 | fAverPosSqSum[i][j] += currentPos[i] * currentPos[j]; |
a3a3a28f | 224 | } |
225 | } | |
37add1d1 | 226 | |
227 | fVertexXY->Fill(currentPos[0],currentPos[1]); | |
228 | fVertexZ->Fill(currentPos[2]); | |
229 | ||
a3a3a28f | 230 | fNoEventsContr++; |
231 | } | |
232 | ||
233 | //______________________________________________________________________ | |
234 | Bool_t AliITSMeanVertexer::ComputeMean(){ | |
235 | // compute mean vertex | |
236 | if(fNoEventsContr < 2) return kFALSE; | |
237 | Double_t nevents = fNoEventsContr; | |
238 | for(Int_t i=0;i<3;i++){ | |
762133f4 | 239 | fWeighPos[i] = fWeighPosSum[i]/fWeighSigSum[i]; |
240 | fWeighSig[i] = 1./TMath::Sqrt(fWeighSigSum[i]); | |
241 | fAverPos[i] = fAverPosSum[i]/nevents; | |
a3a3a28f | 242 | } |
243 | for(Int_t i=0;i<3;i++){ | |
244 | for(Int_t j=i;j<3;j++){ | |
762133f4 | 245 | fAverPosSq[i][j] = fAverPosSqSum[i][j]/(nevents -1.); |
a3a3a28f | 246 | fAverPosSq[i][j] -= nevents/(nevents -1.)*fAverPos[i]*fAverPos[j]; |
247 | } | |
248 | } | |
762133f4 | 249 | |
250 | fAverTracklets = fTotTracklets/nevents; | |
251 | fSigmaOnAverTracks = fTotTrackletsSq/(nevents - 1); | |
252 | fSigmaOnAverTracks -= nevents/(nevents -1.)*fAverTracklets*fAverTracklets; | |
a3a3a28f | 253 | fSigmaOnAverTracks = TMath::Sqrt(fSigmaOnAverTracks); |
254 | return kTRUE; | |
255 | } |