Bug in storage manager making possible to delete permanent event fixed
[u/mrichter/AliRoot.git] / MFT / AliMFTPlane.cxx
index be9ac7a..bad7caa 100644 (file)
@@ -34,7 +34,6 @@
 #include "AliMFTConstants.h"
 #include "AliMFTPlane.h"
 
-const Double_t AliMFTPlane::fRadiusMin           = AliMFTConstants::fRadiusMin;
 const Double_t AliMFTPlane::fActiveSuperposition = AliMFTConstants::fActiveSuperposition;
 const Double_t AliMFTPlane::fHeightActive        = AliMFTConstants::fHeightActive;
 const Double_t AliMFTPlane::fHeightReadout       = AliMFTConstants::fHeightReadout;
@@ -64,7 +63,8 @@ AliMFTPlane::AliMFTPlane():
   fActiveElements(0),
   fReadoutElements(0),
   fSupportElements(0),
-  fHasPixelRectangularPatternAlongY(kFALSE)
+  fHasPixelRectangularPatternAlongY(kFALSE),
+  fPlaneIsOdd(kFALSE)
 {
 
   // default constructor
@@ -90,14 +90,21 @@ AliMFTPlane::AliMFTPlane(const Char_t *name, const Char_t *title):
   fEquivalentSilicon(0),
   fEquivalentSiliconBeforeFront(0),
   fEquivalentSiliconBeforeBack(0),
-  fActiveElements(new TClonesArray("THnSparseC")),
-  fReadoutElements(new TClonesArray("THnSparseC")),
-  fSupportElements(new TClonesArray("THnSparseC")),
-  fHasPixelRectangularPatternAlongY(kFALSE)
+  fActiveElements(0),
+  fReadoutElements(0),
+  fSupportElements(0),
+  fHasPixelRectangularPatternAlongY(kFALSE),
+  fPlaneIsOdd(kFALSE)
 {
 
   // constructor
-
+  fActiveElements  = new TClonesArray("THnSparseC");
+  fReadoutElements = new TClonesArray("THnSparseC");
+  fSupportElements = new TClonesArray("THnSparseC");
+  fActiveElements->SetOwner(kTRUE);
+  fReadoutElements->SetOwner(kTRUE);
+  fSupportElements->SetOwner(kTRUE);
+  
 }
 
 //====================================================================================================================================================
@@ -119,18 +126,50 @@ AliMFTPlane::AliMFTPlane(const AliMFTPlane& plane):
   fEquivalentSilicon(plane.fEquivalentSilicon),
   fEquivalentSiliconBeforeFront(plane.fEquivalentSiliconBeforeFront),
   fEquivalentSiliconBeforeBack(plane.fEquivalentSiliconBeforeBack),
-  fActiveElements(new TClonesArray("THnSparseC")),
-  fReadoutElements(new TClonesArray("THnSparseC")),
-  fSupportElements(new TClonesArray("THnSparseC")),
-  fHasPixelRectangularPatternAlongY(plane.fHasPixelRectangularPatternAlongY)
+  fActiveElements(0),
+  fReadoutElements(0),
+  fSupportElements(0),
+  fHasPixelRectangularPatternAlongY(plane.fHasPixelRectangularPatternAlongY),
+  fPlaneIsOdd(plane.fPlaneIsOdd)
 {
 
   // copy constructor
+  fActiveElements  = new TClonesArray(*(plane.fActiveElements));
+  fActiveElements  -> SetOwner(kTRUE);
+  fReadoutElements = new TClonesArray(*(plane.fReadoutElements));
+  fReadoutElements -> SetOwner(kTRUE);
+  fSupportElements = new TClonesArray(*(plane.fSupportElements));
+  fSupportElements -> SetOwner(kTRUE);
+
+       
+}
+
+//====================================================================================================================================================
+
+AliMFTPlane::~AliMFTPlane() {
+
+  AliInfo("Delete AliMFTPlane");
+  if(fActiveElements) fActiveElements->Delete();
+  delete fActiveElements; 
+  if(fReadoutElements) fReadoutElements->Delete();
+  delete fReadoutElements; 
+  if(fSupportElements) fSupportElements->Delete();
+  delete fSupportElements; 
+
+}
+
+//====================================================================================================================================================
+
+void AliMFTPlane::Clear(const Option_t* /*opt*/) {
+
+  AliInfo("Clear AliMFTPlane");
+  if(fActiveElements) fActiveElements->Delete();
+  delete fActiveElements; fActiveElements=NULL;
+  if(fReadoutElements) fReadoutElements->Delete();
+  delete fReadoutElements;  fReadoutElements=NULL; 
+  if(fSupportElements) fSupportElements->Delete();
+  delete fSupportElements;   fSupportElements=NULL;
 
-  *fActiveElements  = *plane.fActiveElements;
-  *fReadoutElements = *plane.fReadoutElements;
-  *fSupportElements = *plane.fSupportElements;
-  
 }
 
 //====================================================================================================================================================
@@ -138,13 +177,16 @@ AliMFTPlane::AliMFTPlane(const AliMFTPlane& plane):
 AliMFTPlane& AliMFTPlane::operator=(const AliMFTPlane& plane) {
 
   // Assignment operator
-
+  
   // check assignement to self
   if (this != &plane) {
-
+    
     // base class assignement
     TNamed::operator=(plane);
     
+    // clear memory
+    Clear("");
+    
     fPlaneNumber                      = plane.fPlaneNumber;
     fZCenter                          = plane.fZCenter; 
     fRMinSupport                      = plane.fRMinSupport; 
@@ -160,12 +202,17 @@ AliMFTPlane& AliMFTPlane::operator=(const AliMFTPlane& plane) {
     fEquivalentSilicon                = plane.fEquivalentSilicon;
     fEquivalentSiliconBeforeFront     = plane.fEquivalentSiliconBeforeFront;
     fEquivalentSiliconBeforeBack      = plane.fEquivalentSiliconBeforeBack;
-    *fActiveElements                  = *plane.fActiveElements;
-    *fReadoutElements                 = *plane.fReadoutElements;
-    *fSupportElements                 = *plane.fSupportElements;
+    fActiveElements = new TClonesArray(*(plane.fActiveElements));
+    fActiveElements -> SetOwner(kTRUE);
+    fReadoutElements = new TClonesArray(*(plane.fReadoutElements));
+    fReadoutElements -> SetOwner(kTRUE);
+    fSupportElements = new TClonesArray(*(plane.fSupportElements));
+    fSupportElements -> SetOwner(kTRUE);
     fHasPixelRectangularPatternAlongY = plane.fHasPixelRectangularPatternAlongY;
-  }
+    fPlaneIsOdd                       = plane.fPlaneIsOdd;
 
+  }
+  
   return *this;
   
 }
@@ -200,18 +247,17 @@ Bool_t AliMFTPlane::Init(Int_t    planeNumber,
   fZCenterActiveFront = fZCenter - 0.5*fThicknessSupport - 0.5*fThicknessActive;
   fZCenterActiveBack  = fZCenter + 0.5*fThicknessSupport + 0.5*fThicknessActive;
 
-//   if (fRMinSupport <= fRadiusMin) fRMinSupport = fRadiusMin;
-//   else {
-//     fRMinSupport = fRadiusMin + (fHeightActive-fActiveSuperposition) * Int_t((fRMinSupport-fRadiusMin)/(fHeightActive-fActiveSuperposition));
-//   }
-  
   if (fRMax < fRMinSupport+fHeightActive) fRMax = fRMinSupport + fHeightActive;
-  
+
+  Int_t nLaddersWithinPipe = Int_t(fRMinSupport/(fHeightActive-fActiveSuperposition));
+  if (fRMinSupport-nLaddersWithinPipe*(fHeightActive-fActiveSuperposition) > 0.5*(fHeightActive-2*fActiveSuperposition)) fPlaneIsOdd = kTRUE;
+  else fPlaneIsOdd = kFALSE;
+
   fRMax = fRMinSupport + (fHeightActive-fActiveSuperposition) * 
     (Int_t((fRMax-fRMinSupport-fHeightActive)/(fHeightActive-fActiveSuperposition))+1) + fHeightActive;
-  
+
   fRMaxSupport = TMath::Sqrt(fHeightActive*(2.*rMax-fHeightActive) + fRMax*fRMax) + fSupportExtMargin;
+   
   return kTRUE;
  
 }
@@ -223,39 +269,20 @@ Bool_t AliMFTPlane::CreateStructure() {
   Int_t nBins[3]={0};
   Double_t minPosition[3]={0}, maxPosition[3]={0};
   
-  // ------------------- support element -------------------------------------------------
-  
-  nBins[0] = 1;
-  nBins[1] = 1;
-  nBins[2] = 1;
-  
-  minPosition[0] = -1.*fRMaxSupport;
-  minPosition[1] = -1.*fRMaxSupport;
-  minPosition[2] = fZCenter - 0.5*fThicknessSupport;
-  
-  maxPosition[0] = +1.*fRMaxSupport;
-  maxPosition[1] = +1.*fRMaxSupport;
-  maxPosition[2] = fZCenter + 0.5*fThicknessSupport;
-  
-  new ((*fSupportElements)[fSupportElements->GetEntries()]) THnSparseC(Form("MFTSupportElemHist_%02d%03d", fPlaneNumber, fSupportElements->GetEntries()), 
-                                                                      Form("MFTSupportElemHist_%02d%03d", fPlaneNumber, fSupportElements->GetEntries()), 
-                                                                      3, nBins, minPosition, maxPosition);
-
   // ------------------- det elements: active + readout ----------------------------------
-  
+
   Double_t lowEdgeActive = -1.*fRMax;
   Double_t supEdgeActive = lowEdgeActive + fHeightActive;
+  Double_t zMinFront = fZCenter - 0.5*fThicknessSupport - fThicknessActive;
+  Double_t zMinBack  = fZCenter + 0.5*fThicknessSupport;
   Double_t zMin = 0.;
   Bool_t isFront = kTRUE;
   
-  while (supEdgeActive < fRMax+0.01) {
-    
-    if (isFront) zMin = fZCenter - 0.5*fThicknessSupport - fThicknessActive;
-    else         zMin = fZCenter + 0.5*fThicknessSupport;
+  while (supEdgeActive < 0.5*(fHeightActive+fHeightReadout)) {
     
     Double_t extLimitAtLowEdgeActive = TMath::Sqrt((fRMax-TMath::Abs(lowEdgeActive)) * TMath::Abs(2*fRMax - (fRMax-TMath::Abs(lowEdgeActive))));
     Double_t extLimitAtSupEdgeActive = TMath::Sqrt((fRMax-TMath::Abs(supEdgeActive)) * TMath::Abs(2*fRMax - (fRMax-TMath::Abs(supEdgeActive))));
-    
+
     // creating new det element: active + readout
     
     Double_t extLimitDetElem = TMath::Max(extLimitAtLowEdgeActive, extLimitAtSupEdgeActive);
@@ -265,7 +292,12 @@ Bool_t AliMFTPlane::CreateStructure() {
       nBins[0] = TMath::Nint(2.*extLimitDetElem/fPixelSizeX);
       nBins[1] = TMath::Nint(fHeightActive/fPixelSizeY);
       nBins[2] = 1;
+
+      // element below the pipe
       
+      if (isFront) zMin = zMinFront;
+      else         zMin = zMinBack;
+
       minPosition[0] = -1.*extLimitDetElem;
       minPosition[1] = lowEdgeActive;
       minPosition[2] = zMin;
@@ -277,20 +309,40 @@ Bool_t AliMFTPlane::CreateStructure() {
       new ((*fActiveElements)[fActiveElements->GetEntries()]) THnSparseC(Form("MFTActiveElemHist_%02d%03d", fPlaneNumber, fActiveElements->GetEntries()), 
                                                                         Form("MFTActiveElemHist_%02d%03d", fPlaneNumber, fActiveElements->GetEntries()), 
                                                                         3, nBins, minPosition, maxPosition);
+
+      minPosition[1] = lowEdgeActive-fHeightReadout;
+      maxPosition[1] = lowEdgeActive;
       
-      if (supEdgeActive>0.) {
-       minPosition[1] = supEdgeActive;
-       maxPosition[1] = supEdgeActive+fHeightReadout;
-      }
-      else {
-       minPosition[1] = lowEdgeActive-fHeightReadout;
-       maxPosition[1] = lowEdgeActive;
+      new ((*fReadoutElements)[fReadoutElements->GetEntries()]) THnSparseC(Form("MFTReadoutElemHist_%02d%03d", fPlaneNumber, fReadoutElements->GetEntries()), 
+                                                                          Form("MFTReadoutElemHist_%02d%03d", fPlaneNumber, fReadoutElements->GetEntries()), 
+                                                                          3, nBins, minPosition, maxPosition);
+
+      // specular element above the pipe
+
+      if (fPlaneIsOdd) {
+       if (isFront) zMin = zMinBack;
+       else         zMin = zMinFront;
       }
+
+      minPosition[0] = -1.*extLimitDetElem;
+      minPosition[1] = -1.*supEdgeActive;
+      minPosition[2] = zMin;
+      
+      maxPosition[0] = +1.*extLimitDetElem;
+      maxPosition[1] = -1.*lowEdgeActive;
+      maxPosition[2] = zMin+fThicknessActive; 
       
+      new ((*fActiveElements)[fActiveElements->GetEntries()]) THnSparseC(Form("MFTActiveElemHist_%02d%03d", fPlaneNumber, fActiveElements->GetEntries()), 
+                                                                        Form("MFTActiveElemHist_%02d%03d", fPlaneNumber, fActiveElements->GetEntries()), 
+                                                                        3, nBins, minPosition, maxPosition);
+
+      minPosition[1] = -1.*lowEdgeActive;
+      maxPosition[1] = -1.*(lowEdgeActive-fHeightReadout);
+
       new ((*fReadoutElements)[fReadoutElements->GetEntries()]) THnSparseC(Form("MFTReadoutElemHist_%02d%03d", fPlaneNumber, fReadoutElements->GetEntries()), 
                                                                           Form("MFTReadoutElemHist_%02d%03d", fPlaneNumber, fReadoutElements->GetEntries()), 
                                                                           3, nBins, minPosition, maxPosition);
-      
+
     }
     
     else {     // two elements covering the row
@@ -304,8 +356,11 @@ Bool_t AliMFTPlane::CreateStructure() {
       nBins[1] = TMath::Nint(fHeightActive/fPixelSizeY);
       nBins[2] = 1;
       
-      // left element
+      // left element: y < 0
       
+      if (isFront) zMin = zMinFront;
+      else         zMin = zMinBack;
+
       minPosition[0] = -1.*extLimitDetElem;
       minPosition[1] = lowEdgeActive;
       minPosition[2] = zMin;
@@ -318,21 +373,48 @@ Bool_t AliMFTPlane::CreateStructure() {
                                                                         Form("MFTActiveElemHist_%02d%03d", fPlaneNumber, fActiveElements->GetEntries()), 
                                                                         3, nBins, minPosition, maxPosition);   
       
-      if (supEdgeActive>0.) {
-       minPosition[1] = supEdgeActive;
-       maxPosition[1] = supEdgeActive+fHeightReadout;
-      }
-      else {
-       minPosition[1] = lowEdgeActive-fHeightReadout;
-       maxPosition[1] = lowEdgeActive;
-      }
+      minPosition[1] = lowEdgeActive-fHeightReadout;
+      maxPosition[1] = lowEdgeActive;
       
       new ((*fReadoutElements)[fReadoutElements->GetEntries()]) THnSparseC(Form("MFTReadoutElemHist_%02d%03d", fPlaneNumber, fReadoutElements->GetEntries()), 
                                                                           Form("MFTReadoutElemHist_%02d%03d", fPlaneNumber, fReadoutElements->GetEntries()), 
                                                                           3, nBins, minPosition, maxPosition);
+
+      // left element: y > 0
       
-      // right element
+      if (supEdgeActive < 0.5*fHeightActive) {
+       
+       if (fPlaneIsOdd) {
+         if (isFront) zMin = zMinBack;
+         else         zMin = zMinFront;
+       }
+       
+       minPosition[0] = -1.*extLimitDetElem;
+       minPosition[1] = -1.*supEdgeActive;
+       minPosition[2] = zMin;
+       
+       maxPosition[0] = -1.*intLimitDetElem;
+       maxPosition[1] = -1.*lowEdgeActive;
+       maxPosition[2] = zMin+fThicknessActive; 
+       
+       new ((*fActiveElements)[fActiveElements->GetEntries()]) THnSparseC(Form("MFTActiveElemHist_%02d%03d", fPlaneNumber, fActiveElements->GetEntries()), 
+                                                                          Form("MFTActiveElemHist_%02d%03d", fPlaneNumber, fActiveElements->GetEntries()), 
+                                                                          3, nBins, minPosition, maxPosition); 
+       
+       minPosition[1] = -1.*lowEdgeActive;
+       maxPosition[1] = -1.*(lowEdgeActive-fHeightReadout);
+       
+       new ((*fReadoutElements)[fReadoutElements->GetEntries()]) THnSparseC(Form("MFTReadoutElemHist_%02d%03d", fPlaneNumber, fReadoutElements->GetEntries()), 
+                                                                            Form("MFTReadoutElemHist_%02d%03d", fPlaneNumber, fReadoutElements->GetEntries()), 
+                                                                            3, nBins, minPosition, maxPosition);
+      
+      }
+
+      // right element: y < 0
       
+      if (isFront) zMin = zMinFront;
+      else         zMin = zMinBack;
+
       minPosition[0] = +1.*intLimitDetElem;
       minPosition[1] = lowEdgeActive;
       minPosition[2] = zMin;
@@ -345,18 +427,42 @@ Bool_t AliMFTPlane::CreateStructure() {
                                                                         Form("MFTActiveElemHist_%02d%03d", fPlaneNumber, fActiveElements->GetEntries()), 
                                                                         3, nBins, minPosition, maxPosition);   
       
-      if (supEdgeActive>0.) {
-       minPosition[1] = supEdgeActive;
-       maxPosition[1] = supEdgeActive+fHeightReadout;
-      }
-      else {
-       minPosition[1] = lowEdgeActive-fHeightReadout;
-       maxPosition[1] = lowEdgeActive;
-      }
-      
+      minPosition[1] = lowEdgeActive-fHeightReadout;
+      maxPosition[1] = lowEdgeActive;
+
       new ((*fReadoutElements)[fReadoutElements->GetEntries()]) THnSparseC(Form("MFTReadoutElemHist_%02d%03d", fPlaneNumber, fReadoutElements->GetEntries()), 
                                                                           Form("MFTReadoutElemHist_%02d%03d", fPlaneNumber, fReadoutElements->GetEntries()), 
                                                                           3, nBins, minPosition, maxPosition);
+
+      // right element: y > 0
+      
+      if (supEdgeActive < 0.5*fHeightActive) {
+
+       if (fPlaneIsOdd) {
+         if (isFront) zMin = zMinBack;
+         else         zMin = zMinFront;
+       }
+       
+       minPosition[0] = +1.*intLimitDetElem;
+       minPosition[1] = -1.*supEdgeActive;
+       minPosition[2] = zMin;
+       
+       maxPosition[0] = +1.*extLimitDetElem;
+       maxPosition[1] = -1.*lowEdgeActive;
+       maxPosition[2] = zMin+fThicknessActive; 
+       
+       new ((*fActiveElements)[fActiveElements->GetEntries()]) THnSparseC(Form("MFTActiveElemHist_%02d%03d", fPlaneNumber, fActiveElements->GetEntries()), 
+                                                                          Form("MFTActiveElemHist_%02d%03d", fPlaneNumber, fActiveElements->GetEntries()), 
+                                                                          3, nBins, minPosition, maxPosition); 
+       
+       minPosition[1] = -1.*lowEdgeActive;
+       maxPosition[1] = -1.*(lowEdgeActive-fHeightReadout);
+       
+       new ((*fReadoutElements)[fReadoutElements->GetEntries()]) THnSparseC(Form("MFTReadoutElemHist_%02d%03d", fPlaneNumber, fReadoutElements->GetEntries()), 
+                                                                            Form("MFTReadoutElemHist_%02d%03d", fPlaneNumber, fReadoutElements->GetEntries()), 
+                                                                            3, nBins, minPosition, maxPosition);
+
+      }
       
     }
     
@@ -366,6 +472,26 @@ Bool_t AliMFTPlane::CreateStructure() {
     
   }
   
+  // ------------------- support element -------------------------------------------------
+  
+  nBins[0] = 1;
+  nBins[1] = 1;
+  nBins[2] = 1;
+  
+  minPosition[0] = -1.*fRMaxSupport;
+  minPosition[1] = -1.*fRMaxSupport;
+  minPosition[2] = fZCenter - 0.5*fThicknessSupport;
+  
+  maxPosition[0] = +1.*fRMaxSupport;
+  maxPosition[1] = +1.*fRMaxSupport;
+  maxPosition[2] = fZCenter + 0.5*fThicknessSupport;
+  
+  new ((*fSupportElements)[fSupportElements->GetEntries()]) THnSparseC(Form("MFTSupportElemHist_%02d%03d", fPlaneNumber, fSupportElements->GetEntries()), 
+                                                                      Form("MFTSupportElemHist_%02d%03d", fPlaneNumber, fSupportElements->GetEntries()), 
+                                                                      3, nBins, minPosition, maxPosition);
+
+  // --------------------------------------------------------------------------------------
+
   AliDebug(1, Form("Structure completed for MFT plane %s", GetName()));
 
   return kTRUE;