]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - ITS/AliITSMultReconstructor.cxx
Adding the correction for wrongly simulated pid TOF signal
[u/mrichter/AliRoot.git] / ITS / AliITSMultReconstructor.cxx
index 8cf5b753e7dba8b46d2a7f36ef688b481a94c9f0..88cb54ae516942ebaf9af7d51aa540e6dc09e43d 100644 (file)
@@ -100,6 +100,7 @@ fTracklets(0),
 fSClusters(0),
 fNTracklets(0),
 fNSingleCluster(0),
+fNSingleClusterSPD2(0),
 fDPhiWindow(0),
 fDThetaWindow(0),
 fPhiShift(0),
@@ -155,6 +156,8 @@ fhphiClustersLay1(0),
   fCreateClustersCopy(0),
   fClustersLoaded(0),
   fRecoDone(0),
+  fBuildRefs(kTRUE),
+  fStoreSPD2SingleCl(kFALSE),
   fSPDSeg()
 {
   // default c-tor
@@ -163,6 +166,7 @@ fhphiClustersLay1(0),
     fClArr[i] = 0;
     for (int j=0;j<2;j++) fUsedClusLay[i][j] = 0;
     fDetectorIndexClustersLay[i] = 0;
+    fClusterCopyIndex[i] = 0;
     fOverlapFlagClustersLay[i] = 0;
     fNClustersLay[i] = 0;
     fClustersLay[i] = 0;
@@ -172,7 +176,7 @@ fhphiClustersLay1(0),
   
   SetHistOn();
 
-  if(AliITSReconstructor::GetRecoParam()) { 
+  if (AliITSReconstructor::GetRecoParam()) { 
     SetPhiWindow(AliITSReconstructor::GetRecoParam()->GetTrackleterPhiWindow());
     SetThetaWindow(AliITSReconstructor::GetRecoParam()->GetTrackleterThetaWindow());
     SetPhiShift(AliITSReconstructor::GetRecoParam()->GetTrackleterPhiShift());
@@ -182,6 +186,8 @@ fhphiClustersLay1(0),
     SetPhiRotationAngle(AliITSReconstructor::GetRecoParam()->GetTrackleterPhiRotationAngle());
     SetNStdDev(AliITSReconstructor::GetRecoParam()->GetTrackleterNStdDevCut());
     SetScaleDThetaBySin2T(AliITSReconstructor::GetRecoParam()->GetTrackleterScaleDThetaBySin2T());
+    SetBuildRefs(AliITSReconstructor::GetRecoParam()->GetTrackleterBuildCl2TrkRefs());
+    SetStoreSPD2SingleCl(AliITSReconstructor::GetRecoParam()->GetTrackleterStoreSPD2SingleCl());
     //
     SetCutPxDrSPDin(AliITSReconstructor::GetRecoParam()->GetMultCutPxDrSPDin());
     SetCutPxDrSPDout(AliITSReconstructor::GetRecoParam()->GetMultCutPxDrSPDout());
@@ -269,6 +275,7 @@ fTracklets(0),
 fSClusters(0),
 fNTracklets(0),
 fNSingleCluster(0),
+fNSingleClusterSPD2(0),
 fDPhiWindow(0),
 fDThetaWindow(0),
 fPhiShift(0),
@@ -323,6 +330,8 @@ fBlackList(0),
 fCreateClustersCopy(0),
 fClustersLoaded(0),
 fRecoDone(0),
+fBuildRefs(kTRUE),
+fStoreSPD2SingleCl(kFALSE),
 fSPDSeg()
  {
   // Copy constructor :!!! RS ATTENTION: old c-tor reassigned the pointers instead of creating a new copy -> would crash on delete
@@ -364,6 +373,7 @@ AliITSMultReconstructor::~AliITSMultReconstructor(){
   for (int i=0;i<2;i++) {
     delete[] fClustersLay[i];
     delete[] fDetectorIndexClustersLay[i];
+    delete[] fClusterCopyIndex[i];
     delete[] fOverlapFlagClustersLay[i];
     delete   fClArr[i];
     for (int j=0;j<2;j++) delete fUsedClusLay[i][j];
@@ -388,6 +398,7 @@ void AliITSMultReconstructor::Reconstruct(AliESDEvent* esd, TTree* treeRP)
   fNClustersLay[1] = 0;
   fNTracklets = 0; 
   fNSingleCluster = 0;
+  fNSingleClusterSPD2 = 0;
   //
   fESDEvent = esd;
   fTreeRP = treeRP;
@@ -431,6 +442,7 @@ void AliITSMultReconstructor::Reconstruct(TTree* clusterTree, Float_t* vtx, Floa
   fNClustersLay[1] = 0;
   fNTracklets = 0; 
   fNSingleCluster = 0;
+  fNSingleClusterSPD2 = 0;
   //
   if (!clusterTree) { AliError(" Invalid ITS cluster tree !\n"); return; }
   //
@@ -453,6 +465,7 @@ void AliITSMultReconstructor::ReconstructMix(TTree* clusterTree, TTree* clusterT
   fNClustersLay[1] = 0;
   fNTracklets = 0; 
   fNSingleCluster = 0;
+  fNSingleClusterSPD2 = 0;
   //
   if (!clusterTree) { AliError(" Invalid ITS cluster tree !\n"); return; }
   if (!clusterTreeMix) { AliError(" Invalid ITS cluster tree 2nd event !\n"); return; }
@@ -507,7 +520,7 @@ void AliITSMultReconstructor::FindTracklets(const Float_t *vtx)
   // Step2: store tracklets; remove used clusters 
   for (Int_t iC2=0; iC2<fNClustersLay[1]; iC2++) StoreTrackletForL2Cluster(iC2);
   //
-  // store unused single clusters of L1
+  // store unused single clusters of L1 (optionally for L2 too)
   StoreL1Singles();
   //
   AliDebug(1,Form("%d tracklets found", fNTracklets));
@@ -525,7 +538,9 @@ void AliITSMultReconstructor::CreateMultiplicityObject()
   }
   //
   fMult = new AliMultiplicity(fNTracklets,fNSingleCluster,fNFiredChips[0],fNFiredChips[1],fastOrFiredMap);
-  fMult->SetMultTrackRefs(kTRUE);
+  fMult->SetMultTrackRefs( fBuildRefs );
+  fMult->SetSPD2SinglesStored(fStoreSPD2SingleCl);
+  fMult->SetNumberOfSingleClustersSPD2(fNSingleClusterSPD2);
   // store some details of reco:
   fMult->SetScaleDThetaBySin2T(fScaleDTBySin2T);
   fMult->SetDPhiWindow2(fDPhiWindow2);
@@ -540,13 +555,17 @@ void AliITSMultReconstructor::CreateMultiplicityObject()
   //
   UInt_t shared[100]; 
   AliRefArray *refs[2][2] = {{0,0},{0,0}};
-  for (int il=2;il--;) 
-    for (int it=2;it--;)  // tracklet_clusters->track references to stor
-      if (fStoreRefs[il][it]) refs[il][it] = new AliRefArray(fNTracklets,0);
+  if (fBuildRefs) {
+    for (int il=2;il--;) 
+      for (int it=2;it--;)  // tracklet_clusters->track references to stor
+       if (fStoreRefs[il][it]) refs[il][it] = new AliRefArray(fNTracklets,0);
+  }
   //
   for (int i=fNTracklets;i--;)  {
     float* tlInfo = fTracklets[i];
     fMult->SetTrackletData(i,tlInfo);
+    //
+    if (!fBuildRefs) continue; // do we need references?
     for (int itp=0;itp<2;itp++) {      
       for (int ilr=0;ilr<2;ilr++) {
        if (!fStoreRefs[ilr][itp]) continue; // nothing to store
@@ -558,23 +577,27 @@ void AliITSMultReconstructor::CreateMultiplicityObject()
       }
     }
   }
-  fMult->AttachTracklet2TrackRefs(refs[0][0],refs[0][1],refs[1][0],refs[1][1]); 
+  if (fBuildRefs) fMult->AttachTracklet2TrackRefs(refs[0][0],refs[0][1],refs[1][0],refs[1][1]); 
   //
   AliRefArray *refsc[2] = {0,0};
-  for (int it=2;it--;) if (fStoreRefs[0][it]) refsc[it] = new AliRefArray(fNClustersLay[0]);
+  if (fBuildRefs) for (int it=2;it--;) if (fStoreRefs[0][it]) refsc[it] = new AliRefArray(fNClustersLay[0]);
   for (int i=fNSingleCluster;i--;) {
     float* clInfo = fSClusters[i];
     fMult->SetSingleClusterData(i,clInfo); 
+    //
+    if (!fBuildRefs) continue; // do we need references?
+    int ilr = i>=(fNSingleCluster-fNSingleClusterSPD2) ? 1:0;
     int clID = int(clInfo[kSCID]);
     for (int itp=0;itp<2;itp++) {
-      if (!fStoreRefs[0][itp]) continue;
-      int nref = fUsedClusLay[0][itp]->GetReferences(clID,shared,100);
+      if (!fStoreRefs[ilr][itp]) continue;
+      int nref = fUsedClusLay[ilr][itp]->GetReferences(clID,shared,100);
       if (!nref) continue;
       else if (nref==1) refsc[itp]->AddReference(i,shared[0]);
       else refsc[itp]->AddReferences(i,shared,nref);
     }
   }
-  fMult->AttachCluster2TrackRefs(refsc[0],refsc[1]); 
+  //
+  if (fBuildRefs) fMult->AttachCluster2TrackRefs(refsc[0],refsc[1]); 
   fMult->CompactBits();
   //
 }
@@ -594,8 +617,9 @@ void AliITSMultReconstructor::LoadClusterArrays(TTree* tree, TTree* treeMix)
   memset(fTracklets,0,nmaxT*sizeof(Float_t*));
   //
   if (fSClusters) delete[] fSClusters;
-  fSClusters = new Float_t*[fNClustersLay[0]]; 
-  memset(fSClusters,0,fNClustersLay[0]*sizeof(Float_t*));
+  int nSlots = GetStoreSPD2SingleCl() ? fNClustersLay[0]+fNClustersLay[1] : fNClustersLay[0];
+  fSClusters = new Float_t*[nSlots]; 
+  memset(fSClusters,0,nSlots*sizeof(Float_t*));
   //
   AliDebug(1,Form("(clusters in layer 1 : %d,  layer 2: %d)",fNClustersLay[0],fNClustersLay[1]));
   AliDebug(1,Form("(cluster-fired chips in layer 1 : %d,  layer 2: %d)",fNFiredChips[0],fNFiredChips[1]));
@@ -639,6 +663,7 @@ void AliITSMultReconstructor::LoadClusterArrays(TTree* itsClusterTree, int il)
     branch = itsClusterTree->GetBranch("ITSRecPoints");
     branch->SetAddress(&itsClusters);
     if (!fClArr[il]) fClArr[il] = new TClonesArray("AliITSRecPoint",100);
+    delete[] fClusterCopyIndex[il];
   }    
   //
   // count clusters
@@ -670,6 +695,7 @@ void AliITSMultReconstructor::LoadClusterArrays(TTree* itsClusterTree, int il)
   Float_t*   clustersLay              = new Float_t[nclLayer*kClNPar];
   Int_t*     detectorIndexClustersLay = new Int_t[nclLayer];
   Bool_t*    overlapFlagClustersLay   = new Bool_t[nclLayer];
+  if (fCreateClustersCopy) fClusterCopyIndex[il] = new Int_t[nclLayer];
   //
   for (int ic=0;ic<nclLayer;ic++) {
     AliITSRecPoint* cluster = (AliITSRecPoint*)clArr[index[ic]];
@@ -679,6 +705,7 @@ void AliITSMultReconstructor::LoadClusterArrays(TTree* itsClusterTree, int il)
     detectorIndexClustersLay[ic] = cluster->GetDetectorIndex(); 
     overlapFlagClustersLay[ic]   = kFALSE;
     for (Int_t i=3;i--;) clPar[kClMC0+i] = cluster->GetLabel(i);
+    if (fCreateClustersCopy) fClusterCopyIndex[il][ic] = index[ic];
   }
   clArr.Clear();
   delete[] z;
@@ -690,9 +717,11 @@ void AliITSMultReconstructor::LoadClusterArrays(TTree* itsClusterTree, int il)
   if (fDetectorIndexClustersLay[il]) delete[] fDetectorIndexClustersLay[il]; 
   fDetectorIndexClustersLay[il] = detectorIndexClustersLay;
   //
-  for (int it=0;it<2;it++) {
-    if (fUsedClusLay[il][it]) delete fUsedClusLay[il][it];
-    fUsedClusLay[il][it] = new AliRefArray(nclLayer);
+  if (fBuildRefs) {
+    for (int it=0;it<2;it++) {
+      if (fUsedClusLay[il][it]) delete fUsedClusLay[il][it];
+      fUsedClusLay[il][it] = new AliRefArray(nclLayer);
+    }
   }
   //
   if (fClustersLay[il]) delete[] fClustersLay[il]; 
@@ -729,14 +758,16 @@ void AliITSMultReconstructor::LoadClusterFiredChips(TTree* itsClusterTree) {
     // number of clusters in each chip of the current module
     Int_t nClustersInChip[5] = {0,0,0,0,0};
     Int_t layer = 0;
+    Int_t ladder=0;
+    Int_t det=0;
+    AliITSgeomTGeo::GetModuleId(iIts,layer,ladder,det);
+    --layer;  // layer is from 1 to 6 in AliITSgeomTGeo, but from 0 to 5 here
+    if(layer<0 || layer >1)continue;
     
     // loop over clusters
     while(nClusters--) {
       AliITSRecPoint* cluster = (AliITSRecPoint*)itsClusters->UncheckedAt(nClusters);
-      
-      layer = cluster->GetLayer();
-      if (layer>1) continue;            
-
+          
       // find the chip for the current cluster
       Float_t locz = cluster->GetDetLocalZ();
       Int_t iChip = fSPDSeg.GetChipFromLocal(0,locz);
@@ -1055,6 +1086,23 @@ void AliITSMultReconstructor::StoreL1Singles()
     }
   }
   //
+  if (GetStoreSPD2SingleCl()) {
+    for (Int_t iC2=0; iC2<fNClustersLay[1]; iC2++) {
+      if (fPartners[iC2]<0 || (fOverlapFlagClustersLay[0][fPartners[iC2]] || fOverlapFlagClustersLay[1][iC2])) {
+       float* clPar2 = GetClusterLayer2(iC2);
+       fSClusters[fNSingleCluster] = new Float_t[kClNPar];
+       fSClusters[fNSingleCluster][kSCTh] = clPar2[kClTh];
+       fSClusters[fNSingleCluster][kSCPh] = clPar2[kClPh];
+       fSClusters[fNSingleCluster][kSCLab] = clPar2[kClMC0]; 
+       fSClusters[fNSingleCluster][kSCID] = iC2;
+       AliDebug(1,Form(" Adding a single cluster %d (cluster %d  of layer 2)",
+                       fNSingleCluster, iC2));
+       fNSingleCluster++;
+       fNSingleClusterSPD2++;
+      }
+    }
+  }
+  //
 }
 
 //____________________________________________________________________
@@ -1063,7 +1111,7 @@ void AliITSMultReconstructor::ProcessESDTracks()
   // Flag the clusters used by ESD tracks
   // Flag primary tracks to be used for multiplicity counting 
   //
-  if (!fESDEvent) return;
+  if (!fESDEvent || !fBuildRefs) return;
   AliESDVertex* vtx = (AliESDVertex*)fESDEvent->GetPrimaryVertexTracks();
   if (!vtx || vtx->GetNContributors()<1) vtx = (AliESDVertex*)fESDEvent->GetPrimaryVertexSPD();
   if (!vtx || vtx->GetNContributors()<1) {
@@ -1248,3 +1296,15 @@ Bool_t AliITSMultReconstructor::CanBeElectron(const AliESDtrack* trc) const
     pid[AliPID::kElectron]>fCutMinElectronProbESD;
   //
 }
+
+//____________________________________________________________________
+AliITSRecPoint* AliITSMultReconstructor::GetRecPoint(Int_t lr, Int_t n) const
+{
+  // return a cluster of lr corresponding to orderer cluster index n
+  if (fClArr[lr] && fClusterCopyIndex[lr] && n<fNClustersLay[lr]) 
+    return (AliITSRecPoint*) fClArr[lr]->At(fClusterCopyIndex[lr][n]);
+  else {
+    AliError("To access the clusters SetCreateClustersCopy should have been called");
+    return 0;
+  }
+}