]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ITS/AliITSMultReconstructor.cxx
added fake OCDB object needed for QA
[u/mrichter/AliRoot.git] / ITS / AliITSMultReconstructor.cxx
CommitLineData
7ca4655f 1/**************************************************************************
eefb3acc 2 * Copyright(c) 2007-2009, ALICE Experiment at CERN, All rights reserved. *
7ca4655f 3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
7284b2b2 16//_________________________________________________________________________
ac903f1b 17//
7284b2b2 18// Implementation of the ITS-SPD trackleter class
ac903f1b 19//
fa9ed8e9 20// It retrieves clusters in the pixels (theta and phi) and finds tracklets.
21// These can be used to extract charged particle multiplicity from the ITS.
ac903f1b 22//
fa9ed8e9 23// A tracklet consists of two ITS clusters, one in the first pixel layer and
24// one in the second. The clusters are associated if the differences in
25// Phi (azimuth) and Theta (polar angle) are within fiducial windows.
26// In case of multiple candidates the candidate with minimum
27// distance is selected.
968e8539 28//
fa9ed8e9 29// Two methods return the number of tracklets and the number of unassociated
7284b2b2 30// clusters (i.e. not used in any tracklet) in the first SPD layer
31// (GetNTracklets and GetNSingleClusters)
32//
33// The cuts on phi and theta depend on the interacting system (p-p or Pb-Pb)
34// and can be set via AliITSRecoParam class
35// (SetPhiWindow and SetThetaWindow)
ac903f1b 36//
7284b2b2 37// Origin: Tiziano Virgili
38//
39// Current support and development:
40// Domenico Elia, Maria Nicassio (INFN Bari)
41// Domenico.Elia@ba.infn.it, Maria.Nicassio@ba.infn.it
42//
43// Most recent updates:
44// - multiple association forbidden (fOnlyOneTrackletPerC2 = kTRUE)
f606f16a 45// - phi definition changed to ALICE convention (0,2*TMath::pi())
46// - cluster coordinates taken with GetGlobalXYZ()
9b373e9a 47// - fGeometry removed
48// - number of fired chips on the two layers
fa9ed8e9 49// - option to cut duplicates in the overlaps
7b116aa1 50// - options and fiducial cuts via AliITSRecoParam
fa9ed8e9 51// - move from DeltaZeta to DeltaTheta cut
52// - update to the new algorithm by Mariella and Jan Fiete
53// - store also DeltaTheta in the ESD
54// - less new and delete calls when creating the needed arrays
1f9831ab 55//
56// - RS: to decrease the number of new/deletes the clusters data are stored
57// not in float[6] attached to float**, but in 1-D array.
58// - RS: Clusters are sorted in Z in roder to have the same numbering as in the ITS reco
59// - RS: Clusters used by ESDtrack are flagged, this information is passed to AliMulitiplicity object
60// when storing the tracklets and single cluster info
7284b2b2 61//_________________________________________________________________________
ac903f1b 62
7ca4655f 63#include <TClonesArray.h>
64#include <TH1F.h>
65#include <TH2F.h>
66#include <TTree.h>
1f9831ab 67#include <TBits.h>
68#include <TArrayI.h>
ac903f1b 69
7ca4655f 70#include "AliITSMultReconstructor.h"
7b116aa1 71#include "AliITSReconstructor.h"
9b373e9a 72#include "AliITSsegmentationSPD.h"
b51872de 73#include "AliITSRecPoint.h"
b21c1af0 74#include "AliITSRecPointContainer.h"
ac903f1b 75#include "AliITSgeom.h"
b21c1af0 76#include "AliITSgeomTGeo.h"
1f9831ab 77#include "AliITSDetTypeRec.h"
78#include "AliESDEvent.h"
79#include "AliESDVertex.h"
80#include "AliESDtrack.h"
81#include "AliMultiplicity.h"
ac903f1b 82#include "AliLog.h"
fa9ed8e9 83#include "TGeoGlobalMagField.h"
84#include "AliMagF.h"
6de485aa 85#include "AliESDv0.h"
86#include "AliV0.h"
87#include "AliKFParticle.h"
88#include "AliKFVertex.h"
ac903f1b 89
90//____________________________________________________________________
0762f3a8 91ClassImp(AliITSMultReconstructor)
ac903f1b 92
3ef75756 93
ac903f1b 94//____________________________________________________________________
7537d03c 95AliITSMultReconstructor::AliITSMultReconstructor():
1f9831ab 96fDetTypeRec(0),fESDEvent(0),fTreeRP(0),fUsedClusLay1(0),fUsedClusLay2(0),
7537d03c 97fClustersLay1(0),
98fClustersLay2(0),
7b116aa1 99fDetectorIndexClustersLay1(0),
100fDetectorIndexClustersLay2(0),
101fOverlapFlagClustersLay1(0),
102fOverlapFlagClustersLay2(0),
7537d03c 103fTracklets(0),
968e8539 104fSClusters(0),
7537d03c 105fNClustersLay1(0),
106fNClustersLay2(0),
107fNTracklets(0),
968e8539 108fNSingleCluster(0),
7537d03c 109fPhiWindow(0),
7284b2b2 110fThetaWindow(0),
fa9ed8e9 111fPhiShift(0),
7b116aa1 112fRemoveClustersFromOverlaps(0),
113fPhiOverlapCut(0),
114fZetaOverlapCut(0),
6de485aa 115//
116fCutPxDrSPDin(0.1),
117fCutPxDrSPDout(0.15),
118fCutPxDz(0.2),
119fCutDCArz(0.5),
120fCutMinElectronProbTPC(0.5),
121fCutMinElectronProbESD(0.1),
122fCutMinP(0.05),
123fCutMinRGamma(2.),
124fCutMinRK0(1.),
125fCutMinPointAngle(0.98),
126fCutMaxDCADauther(0.5),
127fCutMassGamma(0.03),
128fCutMassGammaNSigma(5.),
129fCutMassK0(0.03),
130fCutMassK0NSigma(5.),
131fCutChi2cGamma(2.),
132fCutChi2cK0(2.),
133fCutGammaSFromDecay(-10.),
134fCutK0SFromDecay(-10.),
135fCutMaxDCA(1.),
136//
7537d03c 137fHistOn(0),
138fhClustersDPhiAcc(0),
139fhClustersDThetaAcc(0),
7537d03c 140fhClustersDPhiAll(0),
141fhClustersDThetaAll(0),
7537d03c 142fhDPhiVsDThetaAll(0),
143fhDPhiVsDThetaAcc(0),
7537d03c 144fhetaTracklets(0),
145fhphiTracklets(0),
146fhetaClustersLay1(0),
147fhphiClustersLay1(0){
9b373e9a 148
149 fNFiredChips[0] = 0;
150 fNFiredChips[1] = 0;
3ef75756 151 // Method to reconstruct the charged particles multiplicity with the
152 // SPD (tracklets).
ac903f1b 153
ac903f1b 154 SetHistOn();
ac903f1b 155
7b116aa1 156 if(AliITSReconstructor::GetRecoParam()) {
7b116aa1 157 SetPhiWindow(AliITSReconstructor::GetRecoParam()->GetTrackleterPhiWindow());
7284b2b2 158 SetThetaWindow(AliITSReconstructor::GetRecoParam()->GetTrackleterThetaWindow());
fa9ed8e9 159 SetPhiShift(AliITSReconstructor::GetRecoParam()->GetTrackleterPhiShift());
7b116aa1 160 SetRemoveClustersFromOverlaps(AliITSReconstructor::GetRecoParam()->GetTrackleterRemoveClustersFromOverlaps());
161 SetPhiOverlapCut(AliITSReconstructor::GetRecoParam()->GetTrackleterPhiOverlapCut());
162 SetZetaOverlapCut(AliITSReconstructor::GetRecoParam()->GetTrackleterZetaOverlapCut());
6de485aa 163 //
164 SetCutPxDrSPDin(AliITSReconstructor::GetRecoParam()->GetMultCutPxDrSPDin());
165 SetCutPxDrSPDout(AliITSReconstructor::GetRecoParam()->GetMultCutPxDrSPDout());
166 SetCutPxDz(AliITSReconstructor::GetRecoParam()->GetMultCutPxDz());
167 SetCutDCArz(AliITSReconstructor::GetRecoParam()->GetMultCutDCArz());
168 SetCutMinElectronProbTPC(AliITSReconstructor::GetRecoParam()->GetMultCutMinElectronProbTPC());
169 SetCutMinElectronProbESD(AliITSReconstructor::GetRecoParam()->GetMultCutMinElectronProbESD());
170 SetCutMinP(AliITSReconstructor::GetRecoParam()->GetMultCutMinP());
171 SetCutMinRGamma(AliITSReconstructor::GetRecoParam()->GetMultCutMinRGamma());
172 SetCutMinRK0(AliITSReconstructor::GetRecoParam()->GetMultCutMinRK0());
173 SetCutMinPointAngle(AliITSReconstructor::GetRecoParam()->GetMultCutMinPointAngle());
174 SetCutMaxDCADauther(AliITSReconstructor::GetRecoParam()->GetMultCutMaxDCADauther());
175 SetCutMassGamma(AliITSReconstructor::GetRecoParam()->GetMultCutMassGamma());
176 SetCutMassGammaNSigma(AliITSReconstructor::GetRecoParam()->GetMultCutMassGammaNSigma());
177 SetCutMassK0(AliITSReconstructor::GetRecoParam()->GetMultCutMassK0());
178 SetCutMassK0NSigma(AliITSReconstructor::GetRecoParam()->GetMultCutMassK0NSigma());
179 SetCutChi2cGamma(AliITSReconstructor::GetRecoParam()->GetMultCutChi2cGamma());
180 SetCutChi2cK0(AliITSReconstructor::GetRecoParam()->GetMultCutChi2cK0());
181 SetCutGammaSFromDecay(AliITSReconstructor::GetRecoParam()->GetMultCutGammaSFromDecay());
182 SetCutK0SFromDecay(AliITSReconstructor::GetRecoParam()->GetMultCutK0SFromDecay());
183 SetCutMaxDCA(AliITSReconstructor::GetRecoParam()->GetMultCutMaxDCA());
184 //
7b116aa1 185 } else {
7b116aa1 186 SetPhiWindow();
7284b2b2 187 SetThetaWindow();
fa9ed8e9 188 SetPhiShift();
7b116aa1 189 SetRemoveClustersFromOverlaps();
190 SetPhiOverlapCut();
191 SetZetaOverlapCut();
6de485aa 192 //
193 SetCutPxDrSPDin();
194 SetCutPxDrSPDout();
195 SetCutPxDz();
196 SetCutDCArz();
197 SetCutMinElectronProbTPC();
198 SetCutMinElectronProbESD();
199 SetCutMinP();
200 SetCutMinRGamma();
201 SetCutMinRK0();
202 SetCutMinPointAngle();
203 SetCutMaxDCADauther();
204 SetCutMassGamma();
205 SetCutMassGammaNSigma();
206 SetCutMassK0();
207 SetCutMassK0NSigma();
208 SetCutChi2cGamma();
209 SetCutChi2cK0();
210 SetCutGammaSFromDecay();
211 SetCutK0SFromDecay();
212 SetCutMaxDCA();
7b116aa1 213 }
214
fa9ed8e9 215 fClustersLay1 = 0;
216 fClustersLay2 = 0;
217 fDetectorIndexClustersLay1 = 0;
218 fDetectorIndexClustersLay2 = 0;
219 fOverlapFlagClustersLay1 = 0;
220 fOverlapFlagClustersLay2 = 0;
221 fTracklets = 0;
222 fSClusters = 0;
ac903f1b 223
224 // definition of histograms
fa9ed8e9 225 Bool_t oldStatus = TH1::AddDirectoryStatus();
226 TH1::AddDirectory(kFALSE);
227
7284b2b2 228 fhClustersDPhiAcc = new TH1F("dphiacc", "dphi", 100,-0.1,0.1);
ddced3c8 229 fhClustersDThetaAcc = new TH1F("dthetaacc","dtheta",100,-0.1,0.1);
ddced3c8 230
7284b2b2 231 fhDPhiVsDThetaAcc = new TH2F("dphiVsDthetaAcc","",100,-0.1,0.1,100,-0.1,0.1);
ac903f1b 232
02a95988 233 fhClustersDPhiAll = new TH1F("dphiall", "dphi", 100,0.0,0.5);
7284b2b2 234 fhClustersDThetaAll = new TH1F("dthetaall","dtheta",100,0.0,0.5);
ddced3c8 235
7284b2b2 236 fhDPhiVsDThetaAll = new TH2F("dphiVsDthetaAll","",100,0.,0.5,100,0.,0.5);
ddced3c8 237
238 fhetaTracklets = new TH1F("etaTracklets", "eta", 100,-2.,2.);
f606f16a 239 fhphiTracklets = new TH1F("phiTracklets", "phi", 100, 0., 2*TMath::Pi());
ddced3c8 240 fhetaClustersLay1 = new TH1F("etaClustersLay1", "etaCl1", 100,-2.,2.);
f606f16a 241 fhphiClustersLay1 = new TH1F("phiClustersLay1", "phiCl1", 100, 0., 2*TMath::Pi());
fa9ed8e9 242
243 TH1::AddDirectory(oldStatus);
ac903f1b 244}
ddced3c8 245
3ef75756 246//______________________________________________________________________
1f9831ab 247AliITSMultReconstructor::AliITSMultReconstructor(const AliITSMultReconstructor &mr) :
248AliTrackleter(mr),
249fDetTypeRec(0),fESDEvent(0),fTreeRP(0),fUsedClusLay1(0),fUsedClusLay2(0),
250fClustersLay1(0),
251fClustersLay2(0),
252fDetectorIndexClustersLay1(0),
253fDetectorIndexClustersLay2(0),
254fOverlapFlagClustersLay1(0),
255fOverlapFlagClustersLay2(0),
256fTracklets(0),
257fSClusters(0),
258fNClustersLay1(0),
259fNClustersLay2(0),
260fNTracklets(0),
261fNSingleCluster(0),
262fPhiWindow(0),
263fThetaWindow(0),
264fPhiShift(0),
265fRemoveClustersFromOverlaps(0),
266fPhiOverlapCut(0),
267fZetaOverlapCut(0),
6de485aa 268//
269fCutPxDrSPDin(0.1),
270fCutPxDrSPDout(0.15),
271fCutPxDz(0.2),
272fCutDCArz(0.5),
273fCutMinElectronProbTPC(0.5),
274fCutMinElectronProbESD(0.1),
275fCutMinP(0.05),
276fCutMinRGamma(2.),
277fCutMinRK0(1.),
278fCutMinPointAngle(0.98),
279fCutMaxDCADauther(0.5),
280fCutMassGamma(0.03),
281fCutMassGammaNSigma(5.),
282fCutMassK0(0.03),
283fCutMassK0NSigma(5.),
284fCutChi2cGamma(2.),
285fCutChi2cK0(2.),
286fCutGammaSFromDecay(-10.),
287fCutK0SFromDecay(-10.),
288fCutMaxDCA(1.),
289//
1f9831ab 290fHistOn(0),
291fhClustersDPhiAcc(0),
292fhClustersDThetaAcc(0),
293fhClustersDPhiAll(0),
294fhClustersDThetaAll(0),
295fhDPhiVsDThetaAll(0),
296fhDPhiVsDThetaAcc(0),
297fhetaTracklets(0),
298fhphiTracklets(0),
299fhetaClustersLay1(0),
300fhphiClustersLay1(0)
301 {
302 // Copy constructor :!!! RS ATTENTION: old c-tor reassigned the pointers instead of creating a new copy -> would crash on delete
303 AliError("May not use");
3ef75756 304}
305
306//______________________________________________________________________
7537d03c 307AliITSMultReconstructor& AliITSMultReconstructor::operator=(const AliITSMultReconstructor& mr){
3ef75756 308 // Assignment operator
1f9831ab 309 if (this != &mr) {
310 this->~AliITSMultReconstructor();
311 new(this) AliITSMultReconstructor(mr);
312 }
3ef75756 313 return *this;
314}
315
316//______________________________________________________________________
317AliITSMultReconstructor::~AliITSMultReconstructor(){
318 // Destructor
1ba5b31c 319
320 // delete histograms
321 delete fhClustersDPhiAcc;
322 delete fhClustersDThetaAcc;
1ba5b31c 323 delete fhClustersDPhiAll;
324 delete fhClustersDThetaAll;
1ba5b31c 325 delete fhDPhiVsDThetaAll;
326 delete fhDPhiVsDThetaAcc;
1ba5b31c 327 delete fhetaTracklets;
328 delete fhphiTracklets;
329 delete fhetaClustersLay1;
330 delete fhphiClustersLay1;
1f9831ab 331 delete[] fUsedClusLay1;
332 delete[] fUsedClusLay2;
333 // delete arrays
fa9ed8e9 334 for(Int_t i=0; i<fNTracklets; i++)
1ba5b31c 335 delete [] fTracklets[i];
fa9ed8e9 336
337 for(Int_t i=0; i<fNSingleCluster; i++)
968e8539 338 delete [] fSClusters[i];
fa9ed8e9 339
1ba5b31c 340 delete [] fClustersLay1;
341 delete [] fClustersLay2;
7b116aa1 342 delete [] fDetectorIndexClustersLay1;
343 delete [] fDetectorIndexClustersLay2;
344 delete [] fOverlapFlagClustersLay1;
345 delete [] fOverlapFlagClustersLay2;
1ba5b31c 346 delete [] fTracklets;
968e8539 347 delete [] fSClusters;
ddced3c8 348}
ac903f1b 349
350//____________________________________________________________________
1f9831ab 351void AliITSMultReconstructor::Reconstruct(AliESDEvent* esd, TTree* treeRP)
352{
ac903f1b 353 //
1f9831ab 354 // - calls LoadClusterArrays that finds the position of the clusters
ac903f1b 355 // (in global coord)
356 // - convert the cluster coordinates to theta, phi (seen from the
7284b2b2 357 // interaction vertex).
ac903f1b 358 // - makes an array of tracklets
359 //
360 // After this method has been called, the clusters of the two layers
361 // and the tracklets can be retrieved by calling the Get'er methods.
362
6873ed43 363 if (!treeRP) { AliError(" Invalid ITS cluster tree !\n"); return; }
364 if (!esd) {AliError("ESDEvent is not available, use old reconstructor"); return;}
ac903f1b 365 // reset counters
1f9831ab 366 if (fMult) delete fMult; fMult = 0;
367 fNClustersLay1 = 0;
368 fNClustersLay2 = 0;
369 fNTracklets = 0;
370 fNSingleCluster = 0;
371 //
1f9831ab 372 fESDEvent = esd;
373 fTreeRP = treeRP;
374 //
375 // >>>> RS: this part is equivalent to former AliITSVertexer::FindMultiplicity
376 //
377 // see if there is a SPD vertex
378 Bool_t isVtxOK=kTRUE, isCosmics=kFALSE;
379 AliESDVertex* vtx = (AliESDVertex*)fESDEvent->GetPrimaryVertexSPD();
380 if (!vtx && vtx->GetNContributors()<0) isVtxOK = kFALSE;
381 if (vtx && strstr(vtx->GetTitle(),"cosmics")) {
382 isVtxOK = kFALSE;
383 isCosmics = kTRUE;
384 }
385 //
386 if (!isVtxOK) {
387 if (!isCosmics) {
388 AliDebug(1,"Tracklets multiplicity not determined because the primary vertex was not found");
389 AliDebug(1,"Just counting the number of cluster-fired chips on the SPD layers");
390 }
391 vtx = 0;
392 }
393 float vtxf[3] = {vtx->GetX(),vtx->GetY(),vtx->GetZ()};
394 FindTracklets(vtxf);
395 //
396 CreateMultiplicityObject();
397}
398
399//____________________________________________________________________
400void AliITSMultReconstructor::Reconstruct(TTree* clusterTree, Float_t* vtx, Float_t* /* vtxRes*/) {
401 //
402 // RS NOTE - this is old reconstructor invocation, to be used from VertexFinder
403 //
404 // - calls LoadClusterArray that finds the position of the clusters
405 // (in global coord)
406 // - convert the cluster coordinates to theta, phi (seen from the
407 // interaction vertex).
408 // - makes an array of tracklets
409 //
410 // After this method has been called, the clusters of the two layers
411 // and the tracklets can be retrieved by calling the Get'er methods.
412 if (fMult) delete fMult; fMult = 0;
ac903f1b 413 fNClustersLay1 = 0;
414 fNClustersLay2 = 0;
415 fNTracklets = 0;
7284b2b2 416 fNSingleCluster = 0;
1f9831ab 417 //
418 if (!clusterTree) { AliError(" Invalid ITS cluster tree !\n"); return; }
419 //
420 fESDEvent = 0;
421 fTreeRP = clusterTree;
422 //
423 FindTracklets(vtx);
424 //
425}
7284b2b2 426
1f9831ab 427//____________________________________________________________________
428void AliITSMultReconstructor::FindTracklets(const Float_t *vtx)
429{
430 // Find tracklets converging to vertex
431 //
432 LoadClusterArrays(fTreeRP);
433 // flag clusters used by ESD tracks
6873ed43 434 if (fESDEvent) ProcessESDTracks();
1f9831ab 435
436 if (!vtx) return;
3ef75756 437
7284b2b2 438 const Double_t pi = TMath::Pi();
fa9ed8e9 439
440 // dPhi shift is field dependent
441 // get average magnetic field
442 Float_t bz = 0;
443 AliMagF* field = 0;
1f9831ab 444 if (TGeoGlobalMagField::Instance()) field = dynamic_cast<AliMagF*>(TGeoGlobalMagField::Instance()->GetField());
fa9ed8e9 445 if (!field)
446 {
447 AliError("Could not retrieve magnetic field. Assuming no field. Delta Phi shift will be deactivated in AliITSMultReconstructor.")
448 }
449 else
450 bz = TMath::Abs(field->SolenoidField());
451
452 const Double_t dPhiShift = fPhiShift / 5 * bz;
453 AliDebug(1, Form("Using phi shift of %f", dPhiShift));
454
455 const Double_t dPhiWindow2 = fPhiWindow * fPhiWindow;
456 const Double_t dThetaWindow2 = fThetaWindow * fThetaWindow;
457
7284b2b2 458 Int_t* partners = new Int_t[fNClustersLay2];
459 Float_t* minDists = new Float_t[fNClustersLay2];
460 Int_t* associatedLay1 = new Int_t[fNClustersLay1];
461 TArrayI** blacklist = new TArrayI*[fNClustersLay1];
462
463 for (Int_t i=0; i<fNClustersLay2; i++) {
464 partners[i] = -1;
465 minDists[i] = 2;
466 }
467 for (Int_t i=0; i<fNClustersLay1; i++)
468 associatedLay1[i] = 0;
469 for (Int_t i=0; i<fNClustersLay1; i++)
470 blacklist[i] = 0;
471
ac903f1b 472 // find the tracklets
473 AliDebug(1,"Looking for tracklets... ");
fa9ed8e9 474
ac903f1b 475 //###########################################################
476 // Loop on layer 1 : finding theta, phi and z
477 for (Int_t iC1=0; iC1<fNClustersLay1; iC1++) {
1f9831ab 478 float *clPar = GetClusterLayer1(iC1);
479 Float_t x = clPar[kClTh] - vtx[0];
480 Float_t y = clPar[kClPh] - vtx[1];
481 Float_t z = clPar[kClZ] - vtx[2];
ddced3c8 482
fa9ed8e9 483 Float_t r = TMath::Sqrt(x*x + y*y + z*z);
ac903f1b 484
1f9831ab 485 clPar[kClTh] = TMath::ACos(z/r); // Store Theta
486 clPar[kClPh] = TMath::Pi() + TMath::ATan2(-y,-x); // Store Phi
fa9ed8e9 487
ddced3c8 488 if (fHistOn) {
1f9831ab 489 Float_t eta = clPar[kClTh];
ddced3c8 490 eta= TMath::Tan(eta/2.);
491 eta=-TMath::Log(eta);
492 fhetaClustersLay1->Fill(eta);
1f9831ab 493 fhphiClustersLay1->Fill(clPar[kClPh]);
ddced3c8 494 }
96c2c35d 495 }
ac903f1b 496
497 // Loop on layer 2 : finding theta, phi and r
498 for (Int_t iC2=0; iC2<fNClustersLay2; iC2++) {
1f9831ab 499 float *clPar = GetClusterLayer2(iC2);
500 Float_t x = clPar[kClTh] - vtx[0];
501 Float_t y = clPar[kClPh] - vtx[1];
502 Float_t z = clPar[kClZ] - vtx[2];
ddced3c8 503
fa9ed8e9 504 Float_t r = TMath::Sqrt(x*x + y*y + z*z);
1f9831ab 505
506 clPar[kClTh] = TMath::ACos(z/r); // Store Theta
507 clPar[kClPh] = TMath::Pi() + TMath::ATan2(-y,-x); // Store Phi
ac903f1b 508 }
509
510 //###########################################################
7284b2b2 511 Int_t found = 1;
512 while (found > 0) {
7284b2b2 513 found = 0;
514
515 // Step1: find all tracklets allowing double assocation
516 // Loop on layer 1
517 for (Int_t iC1=0; iC1<fNClustersLay1; iC1++) {
518
519 // already used or in the overlap ?
520 if (associatedLay1[iC1] != 0 || fOverlapFlagClustersLay1[iC1]) continue;
ac903f1b 521
7284b2b2 522 found++;
523
524 // reset of variables for multiple candidates
525 Int_t iC2WithBestDist = -1; // reset
526 Double_t minDist = 2; // reset
1f9831ab 527 float* clPar1 = GetClusterLayer1(iC1);
528
7284b2b2 529 // Loop on layer 2
530 for (Int_t iC2=0; iC2<fNClustersLay2; iC2++) {
531
532 // in the overlap ?
533 if (fOverlapFlagClustersLay2[iC2]) continue;
1f9831ab 534 float* clPar2 = GetClusterLayer2(iC2);
7284b2b2 535
536 if (blacklist[iC1]) {
537 Bool_t blacklisted = kFALSE;
1f9831ab 538 for (Int_t i=blacklist[iC1]->GetSize(); i--;) {
7284b2b2 539 if (blacklist[iC1]->At(i) == iC2) {
540 blacklisted = kTRUE;
541 break;
542 }
543 }
544 if (blacklisted) continue;
545 }
546
ac903f1b 547 // find the difference in angles
1f9831ab 548 Double_t dTheta = TMath::Abs(clPar2[kClTh] - clPar1[kClTh]);
549 Double_t dPhi = TMath::Abs(clPar2[kClPh] - clPar1[kClPh]);
02a95988 550 // take into account boundary condition
7284b2b2 551 if (dPhi>pi) dPhi=2.*pi-dPhi;
fa9ed8e9 552
ddced3c8 553 if (fHistOn) {
7284b2b2 554 fhClustersDPhiAll->Fill(dPhi);
ddced3c8 555 fhClustersDThetaAll->Fill(dTheta);
ac903f1b 556 fhDPhiVsDThetaAll->Fill(dTheta, dPhi);
557 }
fa9ed8e9 558
559 dPhi -= dPhiShift;
560
7284b2b2 561 // make "elliptical" cut in Phi and Theta!
fa9ed8e9 562 Float_t d = dPhi*dPhi/dPhiWindow2 + dTheta*dTheta/dThetaWindow2;
7284b2b2 563
564 // look for the minimum distance: the minimum is in iC2WithBestDist
fa9ed8e9 565 if (d<1 && d<minDist) {
7284b2b2 566 minDist=d;
ddced3c8 567 iC2WithBestDist = iC2;
ac903f1b 568 }
7284b2b2 569 } // end of loop over clusters in layer 2
ac903f1b 570
7284b2b2 571 if (minDist<1) { // This means that a cluster in layer 2 was found that matches with iC1
572
573 if (minDists[iC2WithBestDist] > minDist) {
574 Int_t oldPartner = partners[iC2WithBestDist];
575 partners[iC2WithBestDist] = iC1;
576 minDists[iC2WithBestDist] = minDist;
577
578 // mark as assigned
579 associatedLay1[iC1] = 1;
580
581 if (oldPartner != -1) {
fa9ed8e9 582 // redo partner search for cluster in L0 (oldPartner), putting this one (iC2WithBestDist) on its blacklist
7284b2b2 583 if (blacklist[oldPartner] == 0) {
584 blacklist[oldPartner] = new TArrayI(1);
585 } else blacklist[oldPartner]->Set(blacklist[oldPartner]->GetSize()+1);
586
587 blacklist[oldPartner]->AddAt(iC2WithBestDist, blacklist[oldPartner]->GetSize()-1);
588
589 // mark as free
fa9ed8e9 590 associatedLay1[oldPartner] = 0;
7284b2b2 591 }
592 } else {
593 // try again to find a cluster without considering iC2WithBestDist
594 if (blacklist[iC1] == 0) {
595 blacklist[iC1] = new TArrayI(1);
596 }
fa9ed8e9 597 else
598 blacklist[iC1]->Set(blacklist[iC1]->GetSize()+1);
7284b2b2 599
600 blacklist[iC1]->AddAt(iC2WithBestDist, blacklist[iC1]->GetSize()-1);
601 }
de4c520e 602
7284b2b2 603 } else // cluster has no partner; remove
604 associatedLay1[iC1] = 2;
605 } // end of loop over clusters in layer 1
606 }
607
608 // Step2: store tracklets; remove used clusters
609 for (Int_t iC2=0; iC2<fNClustersLay2; iC2++) {
de4c520e 610
7284b2b2 611 if (partners[iC2] == -1) continue;
7b116aa1 612
7284b2b2 613 if (fRemoveClustersFromOverlaps) FlagClustersInOverlapRegions (partners[iC2],iC2);
614
aba7fa71 615
616 if (fOverlapFlagClustersLay1[partners[iC2]] || fOverlapFlagClustersLay2[iC2]) continue;
617
1f9831ab 618 float* clPar2 = GetClusterLayer2(iC2);
619 float* clPar1 = GetClusterLayer1(partners[iC2]);
620
621 Float_t* tracklet = fTracklets[fNTracklets] = new Float_t[kTrNPar]; // RS Add also the cluster id's
fa9ed8e9 622
7284b2b2 623 // use the theta from the clusters in the first layer
1f9831ab 624 tracklet[kTrTheta] = clPar1[kClTh];
7284b2b2 625 // use the phi from the clusters in the first layer
1f9831ab 626 tracklet[kTrPhi] = clPar1[kClPh];
7284b2b2 627 // store the difference between phi1 and phi2
1f9831ab 628 tracklet[kTrDPhi] = clPar1[kClPh] - clPar2[kClPh];
7284b2b2 629
630 // define dphi in the range [0,pi] with proper sign (track charge correlated)
1f9831ab 631 if (tracklet[kTrDPhi] > TMath::Pi()) tracklet[kTrDPhi] = tracklet[kTrDPhi]-2.*TMath::Pi();
632 if (tracklet[kTrDPhi] < -TMath::Pi()) tracklet[kTrDPhi] = tracklet[kTrDPhi]+2.*TMath::Pi();
7b116aa1 633
7284b2b2 634 // store the difference between theta1 and theta2
1f9831ab 635 tracklet[kTrDTheta] = clPar1[kClTh] - clPar2[kClTh];
7284b2b2 636
637 if (fHistOn) {
1f9831ab 638 fhClustersDPhiAcc->Fill(tracklet[kTrDPhi]);
639 fhClustersDThetaAcc->Fill(tracklet[kTrDTheta]);
640 fhDPhiVsDThetaAcc->Fill(tracklet[kTrDTheta],tracklet[kTrDPhi]);
ac903f1b 641 }
3ef75756 642
7284b2b2 643 // find label
644 // if equal label in both clusters found this label is assigned
645 // if no equal label can be found the first labels of the L1 AND L2 cluster are assigned
646 Int_t label1 = 0;
647 Int_t label2 = 0;
648 while (label2 < 3) {
1f9831ab 649 if ((Int_t) clPar1[kClMC0+label1] != -2 && (Int_t) clPar1[kClMC0+label1] == (Int_t) clPar2[kClMC0+label2])
7284b2b2 650 break;
651 label1++;
652 if (label1 == 3) {
653 label1 = 0;
654 label2++;
655 }
656 }
657 if (label2 < 3) {
1f9831ab 658 AliDebug(AliLog::kDebug, Form("Found label %d == %d for tracklet candidate %d\n", (Int_t) clPar1[kClMC0+label1], (Int_t) clPar1[kClMC0+label2], fNTracklets));
659 tracklet[kTrLab1] = clPar1[kClMC0+label1];
660 tracklet[kTrLab2] = clPar2[kClMC0+label2];
7284b2b2 661 } else {
1f9831ab 662 AliDebug(AliLog::kDebug, Form("Did not find label %d %d %d %d %d %d for tracklet candidate %d\n", (Int_t) clPar1[kClMC0], (Int_t) clPar1[kClMC1], (Int_t) clPar1[kClMC2], (Int_t) clPar2[kClMC0], (Int_t) clPar2[kClMC1], (Int_t) clPar2[kClMC2], fNTracklets));
663 tracklet[kTrLab1] = clPar1[kClMC0];
664 tracklet[kTrLab2] = clPar2[kClMC0];
7284b2b2 665 }
666
667 if (fHistOn) {
1f9831ab 668 Float_t eta = tracklet[kTrTheta];
7284b2b2 669 eta= TMath::Tan(eta/2.);
670 eta=-TMath::Log(eta);
671 fhetaTracklets->Fill(eta);
1f9831ab 672 fhphiTracklets->Fill(tracklet[kTrPhi]);
7284b2b2 673 }
1f9831ab 674 //
675 tracklet[kClID1] = partners[iC2];
676 tracklet[kClID2] = iC2;
677 //
7284b2b2 678 AliDebug(1,Form(" Adding tracklet candidate %d ", fNTracklets));
679 AliDebug(1,Form(" Cl. %d of Layer 1 and %d of Layer 2", partners[iC2], iC2));
680 fNTracklets++;
3ef75756 681
7284b2b2 682 associatedLay1[partners[iC2]] = 1;
683 }
684
685 // Delete the following else if you do not want to save Clusters!
686 // store the cluster
687 for (Int_t iC1=0; iC1<fNClustersLay1; iC1++) {
1f9831ab 688
689 float* clPar1 = GetClusterLayer1(iC1);
690
7284b2b2 691 if (associatedLay1[iC1]==2||associatedLay1[iC1]==0) {
1f9831ab 692 fSClusters[fNSingleCluster] = new Float_t[kClNPar];
693 fSClusters[fNSingleCluster][kSCTh] = clPar1[kClTh];
694 fSClusters[fNSingleCluster][kSCPh] = clPar1[kClPh];
695 fSClusters[fNSingleCluster][kSCID] = iC1;
de4c520e 696 AliDebug(1,Form(" Adding a single cluster %d (cluster %d of layer 1)",
7284b2b2 697 fNSingleCluster, iC1));
968e8539 698 fNSingleCluster++;
3ef75756 699 }
7284b2b2 700 }
701
702 delete[] partners;
703 delete[] minDists;
704
705 for (Int_t i=0; i<fNClustersLay1; i++)
706 if (blacklist[i])
707 delete blacklist[i];
708 delete[] blacklist;
709
ac903f1b 710 AliDebug(1,Form("%d tracklets found", fNTracklets));
711}
712
713//____________________________________________________________________
1f9831ab 714void AliITSMultReconstructor::CreateMultiplicityObject()
715{
716 // create AliMultiplicity object and store it in the ESD event
717 //
718 TBits fastOrFiredMap,firedChipMap;
719 if (fDetTypeRec) {
720 fastOrFiredMap = fDetTypeRec->GetFastOrFiredMap();
721 firedChipMap = fDetTypeRec->GetFiredChipMap(fTreeRP);
722 }
723 //
724 fMult = new AliMultiplicity(fNTracklets,fNSingleCluster,fNFiredChips[0],fNFiredChips[1],fastOrFiredMap);
725 fMult->SetFiredChipMap(firedChipMap);
726 AliITSRecPointContainer* rcont = AliITSRecPointContainer::Instance();
727 fMult->SetITSClusters(0,rcont->GetNClustersInLayer(1,fTreeRP));
728 for(Int_t kk=2;kk<=6;kk++) fMult->SetITSClusters(kk-1,rcont->GetNClustersInLayerFast(kk));
729 //
730 for (int i=fNTracklets;i--;) {
731 float* tlInfo = fTracklets[i];
732 fMult->SetTrackletData(i,tlInfo, fUsedClusLay1[int(tlInfo[kClID1])]|fUsedClusLay2[int(tlInfo[kClID2])]);
733 }
734 //
735 for (int i=fNSingleCluster;i--;) {
736 float* clInfo = fSClusters[i];
737 fMult->SetSingleClusterData(i,clInfo,fUsedClusLay1[int(clInfo[kSCID])]);
738 }
739 fMult->CompactBits();
740 //
741}
742
743
744//____________________________________________________________________
745void AliITSMultReconstructor::LoadClusterArrays(TTree* itsClusterTree)
746{
ac903f1b 747 // This method
748 // - gets the clusters from the cluster tree
749 // - convert them into global coordinates
750 // - store them in the internal arrays
9b373e9a 751 // - count the number of cluster-fired chips
1f9831ab 752 //
753 // RS: This method was strongly modified wrt original by Jan Fiete. In order to have the same numbering
754 // of clusters as in the ITS reco I had to introduce sorting in Z
755 // Also note that now the clusters data are stored not in float[6] attached to float**, but in 1-D array
ac903f1b 756
9b373e9a 757 AliDebug(1,"Loading clusters and cluster-fired chips ...");
ac903f1b 758
759 fNClustersLay1 = 0;
760 fNClustersLay2 = 0;
9b373e9a 761 fNFiredChips[0] = 0;
762 fNFiredChips[1] = 0;
ac903f1b 763
b21c1af0 764 AliITSsegmentationSPD seg;
9b373e9a 765
b21c1af0 766 AliITSRecPointContainer* rpcont=AliITSRecPointContainer::Instance();
767 TClonesArray* itsClusters=rpcont->FetchClusters(0,itsClusterTree);
768 if(!rpcont->IsSPDActive()){
769 AliWarning("No SPD rec points found, multiplicity not calculated");
770 return;
771 }
1f9831ab 772 //
fa9ed8e9 773 // count clusters
b21c1af0 774 // loop over the SPD subdetectors
1f9831ab 775 TObjArray clArr(100);
776 for (int il=0;il<2;il++) {
777 int nclLayer = 0;
778 int detMin = AliITSgeomTGeo::GetModuleIndex(il+1,1,1);
779 int detMax = AliITSgeomTGeo::GetModuleIndex(il+2,1,1);
780 for (int idt=detMin;idt<detMax;idt++) {
781 itsClusters=rpcont->UncheckedGetClusters(idt);
782 int nClusters = itsClusters->GetEntriesFast();
783 if (!nClusters) continue;
784 Int_t nClustersInChip[5] = {0,0,0,0,0};
785 while(nClusters--) {
786 AliITSRecPoint* cluster = (AliITSRecPoint*)itsClusters->UncheckedAt(nClusters);
787 if (!cluster) continue;
1aa4b2f2 788 clArr.AddAtAndExpand(cluster,nclLayer++);
1f9831ab 789 nClustersInChip[ seg.GetChipFromLocal(0,cluster->GetDetLocalZ()) ]++;
ac903f1b 790 }
1f9831ab 791 for(Int_t ifChip=5;ifChip--;) if (nClustersInChip[ifChip]) fNFiredChips[il]++;
9b373e9a 792 }
1f9831ab 793 // sort the clusters in Z (to have the same numbering as in ITS reco
794 Float_t *z = new Float_t[nclLayer];
795 Int_t * index = new Int_t[nclLayer];
796 for (int ic=0;ic<nclLayer;ic++) z[ic] = ((AliITSRecPoint*)clArr[ic])->GetZ();
797 TMath::Sort(nclLayer,z,index,kFALSE);
798 Float_t* clustersLay = new Float_t[nclLayer*kClNPar];
799 Int_t* detectorIndexClustersLay = new Int_t[nclLayer];
800 Bool_t* overlapFlagClustersLay = new Bool_t[nclLayer];
801 Char_t* usedClusLay = new Char_t[nclLayer];
802 //
803 for (int ic=0;ic<nclLayer;ic++) {
804 AliITSRecPoint* cluster = (AliITSRecPoint*)clArr[index[ic]];
805 float* clPar = &clustersLay[ic*kClNPar];
806 //
807 cluster->GetGlobalXYZ( clPar );
808 detectorIndexClustersLay[ic] = cluster->GetDetectorIndex();
809 overlapFlagClustersLay[ic] = kFALSE;
810 usedClusLay[ic] = 0;
811 for (Int_t i=3;i--;) clPar[kClMC0+i] = cluster->GetLabel(i);
812 }
813 clArr.Clear();
814 delete[] z;
815 delete[] index;
816 //
817 if (il==0) {
818 fClustersLay1 = clustersLay;
819 fOverlapFlagClustersLay1 = overlapFlagClustersLay;
820 fDetectorIndexClustersLay1 = detectorIndexClustersLay;
821 fUsedClusLay1 = usedClusLay;
822 fNClustersLay1 = nclLayer;
823 }
824 else {
825 fClustersLay2 = clustersLay;
826 fOverlapFlagClustersLay2 = overlapFlagClustersLay;
827 fDetectorIndexClustersLay2 = detectorIndexClustersLay;
828 fUsedClusLay2 = usedClusLay;
829 fNClustersLay2 = nclLayer;
830 }
831 }
832 //
833 // no double association allowed
834 int nmaxT = TMath::Min(fNClustersLay1, fNClustersLay2);
835 fTracklets = new Float_t*[nmaxT];
836 fSClusters = new Float_t*[fNClustersLay1];
837 for (Int_t i=nmaxT;i--;) fTracklets[i] = 0;
838 //
ac903f1b 839 AliDebug(1,Form("(clusters in layer 1 : %d, layer 2: %d)",fNClustersLay1,fNClustersLay2));
9b373e9a 840 AliDebug(1,Form("(cluster-fired chips in layer 1 : %d, layer 2: %d)",fNFiredChips[0],fNFiredChips[1]));
841}
842//____________________________________________________________________
843void
844AliITSMultReconstructor::LoadClusterFiredChips(TTree* itsClusterTree) {
845 // This method
846 // - gets the clusters from the cluster tree
847 // - counts the number of (cluster)fired chips
848
849 AliDebug(1,"Loading cluster-fired chips ...");
850
851 fNFiredChips[0] = 0;
852 fNFiredChips[1] = 0;
853
b21c1af0 854 AliITSsegmentationSPD seg;
855 AliITSRecPointContainer* rpcont=AliITSRecPointContainer::Instance();
856 TClonesArray* itsClusters=rpcont->FetchClusters(0,itsClusterTree);
857 if(!rpcont->IsSPDActive()){
858 AliWarning("No SPD rec points found, multiplicity not calculated");
859 return;
860 }
9b373e9a 861
9b373e9a 862 // loop over the its subdetectors
b21c1af0 863 Int_t nSPDmodules=AliITSgeomTGeo::GetModuleIndex(3,1,1);
864 for (Int_t iIts=0; iIts < nSPDmodules; iIts++) {
865 itsClusters=rpcont->UncheckedGetClusters(iIts);
9b373e9a 866 Int_t nClusters = itsClusters->GetEntriesFast();
867
868 // number of clusters in each chip of the current module
869 Int_t nClustersInChip[5] = {0,0,0,0,0};
870 Int_t layer = 0;
871
872 // loop over clusters
873 while(nClusters--) {
874 AliITSRecPoint* cluster = (AliITSRecPoint*)itsClusters->UncheckedAt(nClusters);
875
876 layer = cluster->GetLayer();
877 if (layer>1) continue;
878
879 // find the chip for the current cluster
880 Float_t locz = cluster->GetDetLocalZ();
b21c1af0 881 Int_t iChip = seg.GetChipFromLocal(0,locz);
9b373e9a 882 nClustersInChip[iChip]++;
883
884 }// end of cluster loop
885
886 // get number of fired chips in the current module
9b373e9a 887 for(Int_t ifChip=0; ifChip<5; ifChip++) {
888 if(nClustersInChip[ifChip] >= 1) fNFiredChips[layer]++;
889 }
890
891 } // end of its "subdetector" loop
892
b21c1af0 893
9b373e9a 894 AliDebug(1,Form("(cluster-fired chips in layer 1 : %d, layer 2: %d)",fNFiredChips[0],fNFiredChips[1]));
ac903f1b 895}
896//____________________________________________________________________
897void
898AliITSMultReconstructor::SaveHists() {
3ef75756 899 // This method save the histograms on the output file
900 // (only if fHistOn is TRUE).
ac903f1b 901
902 if (!fHistOn)
903 return;
904
ddced3c8 905 fhClustersDPhiAll->Write();
906 fhClustersDThetaAll->Write();
ac903f1b 907 fhDPhiVsDThetaAll->Write();
ddced3c8 908
909 fhClustersDPhiAcc->Write();
910 fhClustersDThetaAcc->Write();
ac903f1b 911 fhDPhiVsDThetaAcc->Write();
ddced3c8 912
913 fhetaTracklets->Write();
914 fhphiTracklets->Write();
915 fhetaClustersLay1->Write();
916 fhphiClustersLay1->Write();
ac903f1b 917}
7b116aa1 918
919//____________________________________________________________________
920void
921AliITSMultReconstructor::FlagClustersInOverlapRegions (Int_t iC1, Int_t iC2WithBestDist) {
922
923 Float_t distClSameMod=0.;
924 Float_t distClSameModMin=0.;
925 Int_t iClOverlap =0;
926 Float_t meanRadiusLay1 = 3.99335; // average radius inner layer
927 Float_t meanRadiusLay2 = 7.37935; // average radius outer layer;
928
929 Float_t zproj1=0.;
930 Float_t zproj2=0.;
931 Float_t deZproj=0.;
1f9831ab 932 Float_t* clPar1 = GetClusterLayer1(iC1);
933 Float_t* clPar2B = GetClusterLayer2(iC2WithBestDist);
7b116aa1 934 // Loop on inner layer clusters
935 for (Int_t iiC1=0; iiC1<fNClustersLay1; iiC1++) {
936 if (!fOverlapFlagClustersLay1[iiC1]) {
937 // only for adjacent modules
938 if ((TMath::Abs(fDetectorIndexClustersLay1[iC1]-fDetectorIndexClustersLay1[iiC1])==4)||
939 (TMath::Abs(fDetectorIndexClustersLay1[iC1]-fDetectorIndexClustersLay1[iiC1])==76)) {
1f9831ab 940 Float_t *clPar11 = GetClusterLayer1(iiC1);
941 Float_t dePhi=TMath::Abs(clPar11[kClPh]-clPar1[kClPh]);
7b116aa1 942 if (dePhi>TMath::Pi()) dePhi=2.*TMath::Pi()-dePhi;
943
1f9831ab 944 zproj1=meanRadiusLay1/TMath::Tan(clPar1[kClTh]);
945 zproj2=meanRadiusLay1/TMath::Tan(clPar11[kClTh]);
7b116aa1 946
947 deZproj=TMath::Abs(zproj1-zproj2);
948
949 distClSameMod = TMath::Sqrt(TMath::Power(deZproj/fZetaOverlapCut,2)+TMath::Power(dePhi/fPhiOverlapCut,2));
950 if (distClSameMod<=1.) fOverlapFlagClustersLay1[iiC1]=kTRUE;
951
952// if (distClSameMod<=1.) {
953// if (distClSameModMin==0. || distClSameMod<distClSameModMin) {
954// distClSameModMin=distClSameMod;
955// iClOverlap=iiC1;
956// }
957// }
958
959
960 } // end adjacent modules
961 }
962 } // end Loop on inner layer clusters
963
964// if (distClSameModMin!=0.) fOverlapFlagClustersLay1[iClOverlap]=kTRUE;
965
966 distClSameMod=0.;
967 distClSameModMin=0.;
968 iClOverlap =0;
969 // Loop on outer layer clusters
970 for (Int_t iiC2=0; iiC2<fNClustersLay2; iiC2++) {
971 if (!fOverlapFlagClustersLay2[iiC2]) {
972 // only for adjacent modules
1f9831ab 973 Float_t *clPar2 = GetClusterLayer2(iiC2);
7b116aa1 974 if ((TMath::Abs(fDetectorIndexClustersLay2[iC2WithBestDist]-fDetectorIndexClustersLay2[iiC2])==4) ||
975 (TMath::Abs(fDetectorIndexClustersLay2[iC2WithBestDist]-fDetectorIndexClustersLay2[iiC2])==156)) {
1f9831ab 976 Float_t dePhi=TMath::Abs(clPar2[kClPh]-clPar2B[kClPh]);
7b116aa1 977 if (dePhi>TMath::Pi()) dePhi=2.*TMath::Pi()-dePhi;
978
1f9831ab 979 zproj1=meanRadiusLay2/TMath::Tan(clPar2B[kClTh]);
980 zproj2=meanRadiusLay2/TMath::Tan(clPar2[kClTh]);
7b116aa1 981
982 deZproj=TMath::Abs(zproj1-zproj2);
983 distClSameMod = TMath::Sqrt(TMath::Power(deZproj/fZetaOverlapCut,2)+TMath::Power(dePhi/fPhiOverlapCut,2));
984 if (distClSameMod<=1.) fOverlapFlagClustersLay2[iiC2]=kTRUE;
985
986// if (distClSameMod<=1.) {
987// if (distClSameModMin==0. || distClSameMod<distClSameModMin) {
988// distClSameModMin=distClSameMod;
989// iClOverlap=iiC2;
990// }
991// }
992
993 } // end adjacent modules
994 }
995 } // end Loop on outer layer clusters
996
997// if (distClSameModMin!=0.) fOverlapFlagClustersLay2[iClOverlap]=kTRUE;
998
6b489238 999}
1f9831ab 1000
1001//____________________________________________________________________
1002void AliITSMultReconstructor::ProcessESDTracks()
1003{
1004 // Flag the clusters used by ESD tracks
1005 // Flag primary tracks to be used for multiplicity counting
1006 //
6873ed43 1007 if (!fESDEvent) return;
1f9831ab 1008 AliESDVertex* vtx = (AliESDVertex*)fESDEvent->GetPrimaryVertexTracks();
1009 if (!vtx) vtx = (AliESDVertex*)fESDEvent->GetPrimaryVertexSPD();
1010 if (!vtx) {
1011 AliDebug(1,"No primary vertex: cannot flag primary tracks");
1012 return;
1013 }
1014 Int_t ntracks = fESDEvent->GetNumberOfTracks();
1015 for(Int_t itr=0; itr<ntracks; itr++) {
1016 AliESDtrack* track = fESDEvent->GetTrack(itr);
1017 if (!track->IsOn(AliESDtrack::kITSin)) continue; // use only tracks propagated in ITS to vtx
1018 FlagTrackClusters(track);
6de485aa 1019 FlagIfSecondary(track,vtx);
1f9831ab 1020 }
6de485aa 1021 FlagV0s(vtx);
1f9831ab 1022 //
1023}
1024
1025//____________________________________________________________________
1026void AliITSMultReconstructor::FlagTrackClusters(const AliESDtrack* track)
1027{
1028 // RS: flag the SPD clusters of the track if it is useful for the multiplicity estimation
1029 //
1030 Int_t idx[12];
1031 if ( track->GetITSclusters(idx)<3 ) return; // at least 3 clusters must be used in the fit
1032 //
1033 char mark = track->IsOn(AliESDtrack::kITSpureSA) ? kITSSAPBit : kITSTPCBit;
1034 char *uClus[2] = {fUsedClusLay1,fUsedClusLay2};
1035 for (int i=AliESDfriendTrack::kMaxITScluster;i--;) {
1036 // note: i>=6 is for extra clusters
1037 if (idx[i]<0) continue;
1038 int layID= (idx[i] & 0xf0000000) >> 28;
1039 if (layID>1) continue; // SPD only
1040 int clID = (idx[i] & 0x0fffffff);
1041 uClus[layID][clID] |= mark;
1042 }
1043 //
1044}
1045
1046//____________________________________________________________________
6de485aa 1047void AliITSMultReconstructor::FlagIfSecondary(AliESDtrack* track, const AliVertex* vtx)
1f9831ab 1048{
1049 // RS: check if the track is primary and set the flag
6de485aa 1050 double cut = (track->HasPointOnITSLayer(0)||track->HasPointOnITSLayer(1)) ? fCutPxDrSPDin:fCutPxDrSPDout;
1051 float xz[2];
1052 track->GetDZ(vtx->GetX(),vtx->GetY(),vtx->GetZ(), fESDEvent->GetMagneticField(), xz);
1053 if (TMath::Abs(xz[0]*track->P())>cut || TMath::Abs(xz[1]*track->P())>fCutPxDz ||
1054 TMath::Abs(xz[0])>fCutDCArz || TMath::Abs(xz[1])>fCutDCArz)
1055 track->SetStatus(AliESDtrack::kMultSec);
1056 else track->ResetStatus(AliESDtrack::kMultSec);
1057}
1058
1059//____________________________________________________________________
1060void AliITSMultReconstructor::FlagV0s(const AliESDVertex *vtx)
1061{
1062 // flag tracks belonging to v0s
1063 //
1064 const double kK0Mass = 0.4976;
1065 //
1066 AliV0 pvertex;
1067 AliKFVertex vertexKF;
1068 AliKFParticle epKF0,epKF1,pipmKF0,piKF0,piKF1,gammaKF,k0KF;
1069 Double_t mass,massErr,chi2c;
1070 enum {kKFIni=BIT(14)};
1071 //
1072 double recVtx[3];
1073 float recVtxF[3];
1074 vtx->GetXYZ(recVtx);
1075 for (int i=3;i--;) recVtxF[i] = recVtx[i];
1076 //
1077 int ntracks = fESDEvent->GetNumberOfTracks();
1078 if (ntracks<2) return;
1079 //
1080 vertexKF.X() = recVtx[0];
1081 vertexKF.Y() = recVtx[1];
1082 vertexKF.Z() = recVtx[2];
1083 vertexKF.Covariance(0,0) = vtx->GetXRes()*vtx->GetXRes();
1084 vertexKF.Covariance(1,2) = vtx->GetYRes()*vtx->GetYRes();
1085 vertexKF.Covariance(2,2) = vtx->GetZRes()*vtx->GetZRes();
1086 //
1087 AliESDtrack *trc0,*trc1;
1088 for (int it0=0;it0<ntracks;it0++) {
1089 trc0 = fESDEvent->GetTrack(it0);
1090 if (trc0->IsOn(AliESDtrack::kMultInV0)) continue;
1091 if (!trc0->IsOn(AliESDtrack::kITSin)) continue;
1092 Bool_t isSAP = trc0->IsPureITSStandalone();
1093 Int_t q0 = trc0->Charge();
1094 Bool_t testGamma = CanBeElectron(trc0);
1095 epKF0.ResetBit(kKFIni);
1096 piKF0.ResetBit(kKFIni);
1097 double bestChi2=1e16;
1098 int bestID = -1;
1099 //
1100 for (int it1=it0+1;it1<ntracks;it1++) {
1101 trc1 = fESDEvent->GetTrack(it1);
1102 if (trc1->IsOn(AliESDtrack::kMultInV0)) continue;
1103 if (!trc1->IsOn(AliESDtrack::kITSin)) continue;
1104 if (trc1->IsPureITSStandalone() != isSAP) continue; // pair separately ITS_SA_Pure tracks and TPC/ITS+ITS_SA
1105 if ( (q0+trc1->Charge())!=0 ) continue; // don't pair like signs
1106 //
1107 pvertex.SetParamN(q0<0 ? *trc0:*trc1);
1108 pvertex.SetParamP(q0>0 ? *trc0:*trc1);
1109 pvertex.Update(recVtxF);
1110 if (pvertex.P()<fCutMinP) continue;
1111 if (pvertex.GetV0CosineOfPointingAngle()<fCutMinPointAngle) continue;
1112 if (pvertex.GetDcaV0Daughters()>fCutMaxDCADauther) continue;
1113 double d = pvertex.GetD(recVtx[0],recVtx[1],recVtx[2]);
1114 if (d>fCutMaxDCA) continue;
1115 double dx=recVtx[0]-pvertex.Xv(), dy=recVtx[1]-pvertex.Yv();
1116 double rv = TMath::Sqrt(dx*dx+dy*dy);
1117 //
1118 // check gamma conversion hypothesis ----------------------------------------------------------->>>
1119 Bool_t gammaOK = kFALSE;
1120 while (testGamma && CanBeElectron(trc1)) {
1121 if (rv<fCutMinRGamma) break;
1122 if (!epKF0.TestBit(kKFIni)) {
1123 new(&epKF0) AliKFParticle(*trc0,q0>0 ? kPositron:kElectron);
1124 epKF0.SetBit(kKFIni);
1125 }
1126 new(&epKF1) AliKFParticle(*trc1,q0<0 ? kPositron:kElectron);
1127 gammaKF.Initialize();
1128 gammaKF += epKF0;
1129 gammaKF += epKF1;
1130 gammaKF.SetProductionVertex(vertexKF);
1131 gammaKF.GetMass(mass,massErr);
1132 if (mass>fCutMassGamma || (massErr>0&&(mass>massErr*fCutMassGammaNSigma))) break;
1133 if (gammaKF.GetS()<fCutGammaSFromDecay) break;
1134 gammaKF.SetMassConstraint(0.,0.001);
1135 chi2c = (gammaKF.GetNDF()!=0) ? gammaKF.GetChi2()/gammaKF.GetNDF() : 1000;
1136 if (chi2c>fCutChi2cGamma) break;
1137 gammaOK = kTRUE;
1138 if (chi2c>bestChi2) break;
1139 bestChi2 = chi2c;
1140 bestID = it1;
1141 break;
1142 }
1143 if (gammaOK) continue;
1144 // check gamma conversion hypothesis -----------------------------------------------------------<<<
1145 // check K0 conversion hypothesis ----------------------------------------------------------->>>
1146 while (1) {
1147 if (rv<fCutMinRK0) break;
1148 if (!piKF0.TestBit(kKFIni)) {
1149 new(&piKF0) AliKFParticle(*trc0,q0>0 ? kPiPlus:kPiMinus);
1150 piKF0.SetBit(kKFIni);
1151 }
1152 new(&piKF1) AliKFParticle(*trc1,q0<0 ? kPiPlus:kPiMinus);
1153 k0KF.Initialize();
1154 k0KF += piKF0;
1155 k0KF += piKF1;
1156 k0KF.SetProductionVertex(vertexKF);
1157 k0KF.GetMass(mass,massErr);
1158 mass -= kK0Mass;
1159 if (TMath::Abs(mass)>fCutMassK0 || (massErr>0&&(abs(mass)>massErr*fCutMassK0NSigma))) break;
1160 if (k0KF.GetS()<fCutK0SFromDecay) break;
1161 k0KF.SetMassConstraint(kK0Mass,0.001);
1162 chi2c = (k0KF.GetNDF()!=0) ? k0KF.GetChi2()/k0KF.GetNDF() : 1000;
1163 if (chi2c>fCutChi2cK0) break;
1164 if (chi2c>bestChi2) break;
1165 bestChi2 = chi2c;
1166 bestID = it1;
1167 break;
1168 }
1169 // check K0 conversion hypothesis -----------------------------------------------------------<<<
1170 }
1171 //
1172 if (bestID>=0) {
1173 trc0->SetStatus(AliESDtrack::kMultInV0);
1174 fESDEvent->GetTrack(bestID)->SetStatus(AliESDtrack::kMultInV0);
1175 }
1176 }
1177 //
1178}
1179
1180//____________________________________________________________________
1181Bool_t AliITSMultReconstructor::CanBeElectron(const AliESDtrack* trc) const
1182{
1183 // check if the track can be electron
1184 Double_t pid[AliPID::kSPECIES];
1185 if (!trc->IsOn(AliESDtrack::kESDpid)) return kTRUE;
1186 trc->GetESDpid(pid);
1187 return (trc->IsOn(AliESDtrack::kTPCpid)) ?
1188 pid[AliPID::kElectron]>fCutMinElectronProbTPC :
1189 pid[AliPID::kElectron]>fCutMinElectronProbESD;
1190 //
1f9831ab 1191}
6de485aa 1192