Fixed Warnings in Reconstructioner and Prob
[u/mrichter/AliRoot.git] / TOF / AliTOFReconstructioner.cxx
index ce2eb4766703ea986034c88069e7bb56069bf09b..466eef1a431cca8baa78895ba0fa5714adac967c 100644 (file)
 //////////////////////////////////////////////////////////////////////////////
 
 
 //////////////////////////////////////////////////////////////////////////////
 
 
-#include "TTask.h"
-#include "TBenchmark.h"
-#include "TTree.h"
-#include "TSystem.h"
-#include "TFile.h"
-#include "TParticle.h"
-
 #include "AliConst.h"
 #include "AliRun.h"
 #include "AliTOFConstants.h"
 #include "AliConst.h"
 #include "AliRun.h"
 #include "AliTOFConstants.h"
 #include "AliDetector.h"
 #include "AliMC.h"
 
 #include "AliDetector.h"
 #include "AliMC.h"
 
-#include <TClonesArray.h>
-#include "../TGeant3/TGeant3.h"
-#include "TFile.h"
-#include <TF1.h>
-#include <TF2.h>
 #include "TTask.h"
 #include "TTask.h"
+#include "TBenchmark.h"
 #include "TTree.h"
 #include "TSystem.h"
 #include "TTree.h"
 #include "TSystem.h"
+#include "TFile.h"
+#include "TParticle.h"
+#include <TClonesArray.h>
+#include "TGeant3.h"
+#include "TVirtualMC.h"
+#include <TF1.h>
+#include <TF2.h>
 #include "TROOT.h"
 #include "TFolder.h"
 #include "TNtuple.h"
 #include "TROOT.h"
 #include "TFolder.h"
 #include "TNtuple.h"
@@ -86,7 +82,6 @@ ClassImp(AliTOFReconstructioner)
 {
   // default ctor
   fNevents = 0 ; 
 {
   // default ctor
   fNevents = 0 ; 
-  fg3      = 0;
   foutputfile  = 0; 
   foutputntuple= 0;
   fZnoise  = 0;
   foutputfile  = 0; 
   foutputntuple= 0;
   fZnoise  = 0;
@@ -100,7 +95,6 @@ ClassImp(AliTOFReconstructioner)
   // ctor
   //
   fNevents = 0 ;     // Number of events to reconstruct, 0 means all evens in current file
   // ctor
   //
   fNevents = 0 ;     // Number of events to reconstruct, 0 means all evens in current file
-  fg3      = 0;
   foutputfile  = 0; 
   foutputntuple= 0;
   fZnoise  = 0;
   foutputfile  = 0; 
   foutputntuple= 0;
   fZnoise  = 0;
@@ -122,9 +116,6 @@ ClassImp(AliTOFReconstructioner)
   gAlice->Init();
   gAlice->Print(); 
 
   gAlice->Init();
   gAlice->Print(); 
 
-  // set the fg3 pointer to geometry used by IsInsideThePad method
-  fg3 = (TGeant3*) gMC;         
-
   CreateNTuple();  
 
   // add Task to //root/Tasks folder
   CreateNTuple();  
 
   // add Task to //root/Tasks folder
@@ -221,11 +212,7 @@ void AliTOFReconstructioner::Init(Option_t* opt)
   //
   // dtor
   //
   //
   // dtor
   //
-  if (fg3)
-    {
-      delete fg3;
-      fg3 = 0;
-    }
+
   if (foutputfile)
     {
       delete foutputfile;
   if (foutputfile)
     {
       delete foutputfile;
@@ -385,11 +372,13 @@ void AliTOFReconstructioner::Exec(const char* datafile, Option_t *option)
       } 
     }
 
       } 
     }
 
-    Float_t toftime[fMaxAllTracks]; InitArray(toftime, fMaxAllTracks);
-    //Float_t tofMom[fMaxAllTracks]; InitArray(tofMom, fMaxAllTracks);
+    Float_t * toftime = new Float_t[fMaxAllTracks]; 
+    InitArray(toftime, fMaxAllTracks);
     AliTOFPad* pixelArray = new AliTOFPad[fMaxPixels];
     AliTOFPad* pixelArray = new AliTOFPad[fMaxPixels];
-    Int_t* iTOFpixel        = new Int_t[fMaxAllTracks]; InitArray(iTOFpixel   , fMaxAllTracks);
-    Int_t* kTOFhitFirst     = new Int_t[fMaxAllTracks]; InitArray(kTOFhitFirst, fMaxAllTracks);
+    Int_t* iTOFpixel        = new Int_t[fMaxAllTracks];
+    InitArray(iTOFpixel   , fMaxAllTracks);
+    Int_t* kTOFhitFirst     = new Int_t[fMaxAllTracks];
+    InitArray(kTOFhitFirst, fMaxAllTracks);
     AliTOFRecHit* hitArray  = new AliTOFRecHit[fMaxTOFHits];
     Int_t isHitOnFiredPad=0; // index used to fill hitArray (array used to store informations
                              // about pads that contains an hit)
     AliTOFRecHit* hitArray  = new AliTOFRecHit[fMaxTOFHits];
     Int_t isHitOnFiredPad=0; // index used to fill hitArray (array used to store informations
                              // about pads that contains an hit)
@@ -397,9 +386,12 @@ void AliTOFReconstructioner::Exec(const char* datafile, Option_t *option)
 
     // TPC arrays
     AliTOFTrack* trackArray = new AliTOFTrack[fMaxTracks];
 
     // TPC arrays
     AliTOFTrack* trackArray = new AliTOFTrack[fMaxTracks];
-    Int_t   iparticle[fMaxAllTracks]; InitArray(iparticle,fMaxAllTracks); 
-    Int_t   iTrackPt[fMaxTracks];     InitArray(iTrackPt, fMaxTracks);  // array 
-    Float_t ptTrack[fMaxTracks];      InitArray( ptTrack, fMaxTracks);  // array for selected track pt  
+    Int_t * iparticle = new Int_t[fMaxAllTracks];
+    InitArray(iparticle,fMaxAllTracks); 
+    Int_t * iTrackPt  = new Int_t[fMaxTracks];
+    InitArray(iTrackPt, fMaxTracks);  // array 
+    Float_t * ptTrack = new Float_t[fMaxTracks];
+    InitArray( ptTrack, fMaxTracks);  // array for selected track pt  
     Int_t   ntotTPCtracks=0; // total number of selected TPC tracks
 
     
     Int_t   ntotTPCtracks=0; // total number of selected TPC tracks
 
     
@@ -432,12 +424,15 @@ void AliTOFReconstructioner::Exec(const char* datafile, Option_t *option)
     
 
     // free used memory
     
 
     // free used memory
-    delete [] pixelArray;   pixelArray=0;
-    delete [] iTOFpixel;    iTOFpixel=0;
-    delete [] kTOFhitFirst; kTOFhitFirst=0;
-    delete [] hitArray;     hitArray=0;
-    delete [] trackArray;   trackArray=0;
-
+    delete [] toftime;
+    delete [] pixelArray;
+    delete [] iTOFpixel;
+    delete [] kTOFhitFirst;
+    delete [] hitArray;
+    delete [] trackArray;
+    delete [] iparticle;
+    delete [] iTrackPt;
+    delete [] ptTrack;
 
    for (Int_t i=0; i<AliTOFConstants::fgkNSectors*AliTOFConstants::fgkNPlates; i++) {
       for (Int_t j=0; j<AliTOFConstants::fgkNStripC; j++) {
 
    for (Int_t i=0; i<AliTOFConstants::fgkNSectors*AliTOFConstants::fgkNPlates; i++) {
       for (Int_t j=0; j<AliTOFConstants::fgkNStripC; j++) {
@@ -583,7 +578,7 @@ void AliTOFReconstructioner::PrintParameters()const
 }
 
 //__________________________________________________________________
 }
 
 //__________________________________________________________________
-void AliTOFReconstructioner::IsInsideThePad(TGeant3 *g3, Float_t x, Float_t y, Float_t z, Int_t *nGeom, Float_t& zPad, Float_t& xPad) 
+void AliTOFReconstructioner::IsInsideThePad(TVirtualMC *vmc, Float_t x, Float_t y, Float_t z, Int_t *nGeom, Float_t& zPad, Float_t& xPad) 
 {
   //   input: x,y,z - coordinates of a hit
   //   output: array  nGeom[]
 {
   //   input: x,y,z - coordinates of a hit
   //   output: array  nGeom[]
@@ -624,6 +619,8 @@ void AliTOFReconstructioner::IsInsideThePad(TGeant3 *g3, Float_t x, Float_t y, F
   xTOF[1]=y;
   xTOF[2]=z;
   
   xTOF[1]=y;
   xTOF[2]=z;
   
+  TGeant3 * g3 = (TGeant3*) vmc;
+
   g3->Gmedia(xTOF, numed);
   gcvolu=g3->Gcvolu();
   nLevel=gcvolu->nlevel;
   g3->Gmedia(xTOF, numed);
   gcvolu=g3->Gcvolu();
   nLevel=gcvolu->nlevel;
@@ -1504,18 +1501,24 @@ Bool_t AliTOFReconstructioner::operator==( AliTOFReconstructioner const & tofrec
   // split the member variables in analogous categories
   
   // time resolution and edge effect parameters
   // split the member variables in analogous categories
   
   // time resolution and edge effect parameters
-  Bool_t dummy0=(fTimeResolution==tofrec.fTimeResolution)&&(fpadefficiency==tofrec.fpadefficiency)&&(fEdgeEffect==tofrec.fEdgeEffect)&&(fEdgeTails==tofrec.fEdgeTails)&&(fHparameter==tofrec.fHparameter)&&(fH2parameter==tofrec.fH2parameter)&&(fKparameter==tofrec.fKparameter)&&(fK2parameter==tofrec.fK2parameter);
+  Bool_t dummy0=(fTimeResolution==tofrec.fTimeResolution)&&(fpadefficiency==tofrec.fpadefficiency)&&(fEdgeEffect==tofrec.fEdgeEffect)&&(fEdgeTails==tofrec.fEdgeTails)&&(fHparameter==tofrec.fHparameter)&&(fH2parameter==tofrec.fH2parameter)&&(fKparameter==t
+ofrec.fKparameter)&&(fK2parameter==tofrec.fK2parameter);
   
   // pad efficiency parameters
   
   // pad efficiency parameters
-  Bool_t dummy1=(fEffCenter==tofrec.fEffCenter)&&(fEffBoundary==tofrec.fEffBoundary)&&(fEff2Boundary==tofrec.fEff2Boundary)&&(fEff3Boundary==tofrec.fEff3Boundary)&&(fResCenter==tofrec.fResCenter)&&(fResBoundary==tofrec.fResBoundary)&&(fResSlope==tofrec.fResSlope);
+  Bool_t dummy1=(fEffCenter==tofrec.fEffCenter)&&(fEffBoundary==tofrec.fEffBoundary)&&(fEff2Boundary==tofrec.fEff2Boundary)&&(fEff3Boundary==tofrec.fEff3Boundary)&&(fResCenter==tofrec.fResCenter)&&(fResBoundary==tofrec.fResBoundary)&&(fResSlope==tofrec.fR
+esSlope);
 
   // time walk parameters
 
   // time walk parameters
-  Bool_t dummy2=(fTimeWalkCenter==tofrec.fTimeWalkCenter)&&(fTimeWalkBoundary==tofrec.fTimeWalkBoundary)&&(fTimeWalkSlope==tofrec.fTimeWalkSlope)&&(fTimeDelayFlag==tofrec.fTimeDelayFlag)&&(fPulseHeightSlope==tofrec.fPulseHeightSlope)&&(fTimeDelaySlope==tofrec.fTimeDelaySlope);
+  Bool_t dummy2=(fTimeWalkCenter==tofrec.fTimeWalkCenter)&&(fTimeWalkBoundary==tofrec.fTimeWalkBoundary)&&(fTimeWalkSlope==tofrec.fTimeWalkSlope)&&(fTimeDelayFlag==tofrec.fTimeDelayFlag)&&(fPulseHeightSlope==tofrec.fPulseHeightSlope)&&(fTimeDelaySlope==to
+frec.fTimeDelaySlope);
 
   // ADC-TDC correlation parameters
 
   // ADC-TDC correlation parameters
-  Bool_t dummy3=(fMinimumCharge==tofrec.fMinimumCharge)&&(fChargeSmearing==tofrec.fChargeSmearing )&&(fLogChargeSmearing==tofrec.fLogChargeSmearing )&&(fTimeSmearing==tofrec.fTimeSmearing )&&(fAverageTimeFlag==tofrec.fAverageTimeFlag)&&(fChargeFactorForMatching==tofrec.fChargeFactorForMatching)&&(fMatchingStyle==tofrec.fMatchingStyle);
+  Bool_t dummy3=(fMinimumCharge==tofrec.fMinimumCharge)&&(fChargeSmearing==tofrec.fChargeSmearing )&&(fLogChargeSmearing==tofrec.fLogChargeSmearing )&&(fTimeSmearing==tofrec.fTimeSmearing )&&(fAverageTimeFlag==tofrec.fAverageTimeFlag)&&(fChargeFactorForMa
+tching==tofrec.fChargeFactorForMatching)&&(fMatchingStyle==tofrec.fMatchingStyle);
   
   
-  Bool_t dummy4=(fTrackingEfficiency==tofrec.fTrackingEfficiency)&&(fSigmavsp==tofrec.fSigmavsp)&&(fSigmaZ==tofrec.fSigmaZ)&&(fSigmarphi==tofrec.fSigmarphi)&&(fSigmap==tofrec.fSigmap)&&(fSigmaPhi==tofrec.fSigmaPhi)&&(fSigmaTheta==tofrec.fSigmaTheta)&&(fNoise==tofrec.fNoise)&&(fNoiseSlope==tofrec.fNoiseSlope)&&(fField==tofrec.fField)&&(fRadLenTPC==tofrec.fRadLenTPC)&&(fCorrectionTRD==tofrec.fCorrectionTRD)&&(fLastTPCRow==tofrec.fLastTPCRow)&&(fRadiusvtxBound==tofrec.fRadiusvtxBound)&&(fMaxTestTracks==tofrec.fMaxTestTracks)&&(fStep==tofrec.fStep)&&(fMaxPixels==tofrec.fMaxPixels)&&(fMaxAllTracks==tofrec.fMaxAllTracks)&&(fMaxTracks==tofrec.fMaxTracks)&&(fMaxTOFHits==tofrec.fMaxTOFHits)&&(fPBound==tofrec.fPBound);
+  Bool_t dummy4=(fTrackingEfficiency==tofrec.fTrackingEfficiency)&&(fSigmavsp==tofrec.fSigmavsp)&&(fSigmaZ==tofrec.fSigmaZ)&&(fSigmarphi==tofrec.fSigmarphi)&&(fSigmap==tofrec.fSigmap)&&(fSigmaPhi==tofrec.fSigmaPhi)&&(fSigmaTheta==tofrec.fSigmaTheta)&&(fNo
+ise==tofrec.fNoise)&&(fNoiseSlope==tofrec.fNoiseSlope)&&(fField==tofrec.fField)&&(fRadLenTPC==tofrec.fRadLenTPC)&&(fCorrectionTRD==tofrec.fCorrectionTRD)&&(fLastTPCRow==tofrec.fLastTPCRow)&&(fRadiusvtxBound==tofrec.fRadiusvtxBound)&&(fMaxTestTracks==tofre
+c.fMaxTestTracks)&&(fStep==tofrec.fStep)&&(fMaxPixels==tofrec.fMaxPixels)&&(fMaxAllTracks==tofrec.fMaxAllTracks)&&(fMaxTracks==tofrec.fMaxTracks)&&(fMaxTOFHits==tofrec.fMaxTOFHits)&&(fPBound==tofrec.fPBound);
 
   if( dummy0 && dummy1 && dummy2 && dummy3 && dummy4)
     return kTRUE ;
 
   if( dummy0 && dummy1 && dummy2 && dummy3 && dummy4)
     return kTRUE ;
@@ -1555,7 +1558,8 @@ void AliTOFReconstructioner::InitArray(Int_t array[], Int_t nlocations)
 
 
 //____________________________________________________________________________
 
 
 //____________________________________________________________________________
-void AliTOFReconstructioner::ReadTOFHits(Int_t ntracks, TTree* treehits, TClonesArray* tofhits, Int_t ***MapPixels, Int_t* kTOFhitFirst, AliTOFPad* pixelArray , Int_t* iTOFpixel, Float_t* toftime, AliTOFRecHit* hitArray, Int_t& isHitOnFiredPad, Int_t& ipixel)
+void AliTOFReconstructioner::ReadTOFHits(Int_t ntracks, TTree* treehits, TClonesArray* tofhits, Int_t ***MapPixels, Int_t* kTOFhitFirst, AliTOFPad* pixelArray , Int_t* iTOFpixel, Float_t* toftime, AliTOFRecHit* hitArray, Int_t& isHitOnFiredPad, Int_t& ipi
+xel)
 {
   //
   // Read TOF hits for the current event and fill arrays
 {
   //
   // Read TOF hits for the current event and fill arrays
@@ -1573,7 +1577,7 @@ void AliTOFReconstructioner::ReadTOFHits(Int_t ntracks, TTree* treehits, TClones
   TParticle *particle;
   Int_t nHitOutofTofVolumes; // number of hits out of TOF GEANT volumes (it happens in very
                              // few cases)
   TParticle *particle;
   Int_t nHitOutofTofVolumes; // number of hits out of TOF GEANT volumes (it happens in very
                              // few cases)
-  Int_t npixel[AliTOFConstants::fgkmaxtoftree]; // array used by TOFRecon for check on TOF geometry
+  Int_t * npixel = new Int_t[AliTOFConstants::fgkmaxtoftree]; // array used by TOFRecon for check on TOF geometry
   Int_t npions=0;    // number of pions for the current event
   Int_t nkaons=0;    // number of kaons for the current event
   Int_t nprotons=0;  // number of protons for the current event
   Int_t npions=0;    // number of pions for the current event
   Int_t nkaons=0;    // number of kaons for the current event
   Int_t nprotons=0;  // number of protons for the current event
@@ -1647,15 +1651,18 @@ void AliTOFReconstructioner::ReadTOFHits(Int_t ntracks, TTree* treehits, TClones
        Float_t x = tofHit->X(); tofpos[0]=x;
        Float_t y = tofHit->Y(); tofpos[1]=y;
        Float_t z = tofHit->Z(); tofpos[2]=z;
        Float_t x = tofHit->X(); tofpos[0]=x;
        Float_t y = tofHit->Y(); tofpos[1]=y;
        Float_t z = tofHit->Z(); tofpos[2]=z;
-       
+       /* var used for QA
        Float_t tofradius = TMath::Sqrt(x*x+y*y); // radius cilindrical coordinate of the TOF hit
        Float_t tofradius = TMath::Sqrt(x*x+y*y); // radius cilindrical coordinate of the TOF hit
+       */
        // momentum components (cosine) when striking the TOF
        Float_t pxtof = tofHit->GetPx();
        Float_t pytof = tofHit->GetPy();
        Float_t pztof = tofHit->GetPz();
        // scalar product indicating the direction of the particle when striking the TOF 
        // momentum components (cosine) when striking the TOF
        Float_t pxtof = tofHit->GetPx();
        Float_t pytof = tofHit->GetPy();
        Float_t pztof = tofHit->GetPz();
        // scalar product indicating the direction of the particle when striking the TOF 
+       /* var used for QA
        // (>0 for outgoing particles)
        Float_t isGoingOut = (x*pxtof+y*pytof+z*pztof)/TMath::Sqrt(x*x+y*y+z*z);
        // (>0 for outgoing particles)
        Float_t isGoingOut = (x*pxtof+y*pytof+z*pztof)/TMath::Sqrt(x*x+y*y+z*z);
+       */
        Float_t momtof = tofHit->GetMom();
        // now momentum components when striking the TOF
        pxtof *= momtof;
        Float_t momtof = tofHit->GetMom();
        // now momentum components when striking the TOF
        pxtof *= momtof;
@@ -1715,7 +1722,7 @@ void AliTOFReconstructioner::ReadTOFHits(Int_t ntracks, TTree* treehits, TClones
          }
        } //end if(ipart!=ipartLast)
 
          }
        } //end if(ipart!=ipartLast)
 
-       IsInsideThePad(fg3,x,y,z,npixel,zPad,xPad);
+       IsInsideThePad(gMC,x,y,z,npixel,zPad,xPad);
 
        Int_t sec  = tofHit->GetSector();
        Int_t pla  = tofHit->GetPlate();
 
        Int_t sec  = tofHit->GetSector();
        Int_t pla  = tofHit->GetPlate();
@@ -1733,7 +1740,7 @@ void AliTOFReconstructioner::ReadTOFHits(Int_t ntracks, TTree* treehits, TClones
        
        
        if (npixel[4]==0){
        
        
        if (npixel[4]==0){
-         IsInsideThePad(fg3,x,y,z,npixel,zPad,xPad);
+         IsInsideThePad(gMC,x,y,z,npixel,zPad,xPad);
          if (npixel[4]==0){          
            nHitOutofTofVolumes++;
          }
          if (npixel[4]==0){          
            nHitOutofTofVolumes++;
          }
@@ -1856,6 +1863,7 @@ void AliTOFReconstructioner::ReadTOFHits(Int_t ntracks, TTree* treehits, TClones
     cout << " Reading TOF hits done" << endl;
   }
 
     cout << " Reading TOF hits done" << endl;
   }
 
+  delete [] npixel;
 }
 
 //____________________________________________________________________________
 }
 
 //____________________________________________________________________________
@@ -1866,7 +1874,8 @@ void AliTOFReconstructioner::AddNoiseFromOuter(Option_t *option, Int_t ***MapPix
   // to parameterized fZNoise distribution (to be used with events 
   // generated in the barrel region)
 
   // to parameterized fZNoise distribution (to be used with events 
   // generated in the barrel region)
 
-  Float_t zLen[AliTOFConstants::fgkNPlates+1],zStrips[AliTOFConstants::fgkNPlates];
+  Float_t * zLen = new Float_t[AliTOFConstants::fgkNPlates+1];
+  Float_t * zStrips = new Float_t[AliTOFConstants::fgkNPlates];
   zStrips[0]=(Float_t) (AliTOFConstants::fgkNStripC);
   zStrips[1]=(Float_t) (AliTOFConstants::fgkNStripB);
   zStrips[2]=(Float_t) (AliTOFConstants::fgkNStripA);
   zStrips[0]=(Float_t) (AliTOFConstants::fgkNStripC);
   zStrips[1]=(Float_t) (AliTOFConstants::fgkNStripB);
   zStrips[2]=(Float_t) (AliTOFConstants::fgkNStripA);
@@ -1944,7 +1953,7 @@ void AliTOFReconstructioner::AddNoiseFromOuter(Option_t *option, Int_t ***MapPix
        }
       }
 
        }
       }
 
-      istrip=(Int_t)(zNoise-zLen[iplate-1])/((zLen[iplate]-zLen[iplate-1])/zStrips[iplate-1]); //the strip number in the plate
+      istrip=(Int_t)((zNoise-zLen[iplate-1])/((zLen[iplate]-zLen[iplate-1])/zStrips[iplate-1])); //the strip number in the plate
       istrip++;
 
       ipadAlongX = (Int_t)(AliTOFConstants::fgkNpadX*gRandom->Rndm())+1;
       istrip++;
 
       ipadAlongX = (Int_t)(AliTOFConstants::fgkNpadX*gRandom->Rndm())+1;
@@ -2038,6 +2047,8 @@ void AliTOFReconstructioner::AddNoiseFromOuter(Option_t *option, Int_t ***MapPix
   Float_t numberOfPads=AliTOFConstants::fgkPadXSector*AliTOFConstants::fgkNSectors;
   occupancy=100.*ipixel/numberOfPads;   // percentage of fired pads
   printf(" Overall TOF occupancy (percentage of fired pads after adding noise) = %f\n",occupancy); 
   Float_t numberOfPads=AliTOFConstants::fgkPadXSector*AliTOFConstants::fgkNSectors;
   occupancy=100.*ipixel/numberOfPads;   // percentage of fired pads
   printf(" Overall TOF occupancy (percentage of fired pads after adding noise) = %f\n",occupancy); 
+  delete [] zLen;
+  delete [] zStrips;
   
 }
 
   
 }
 
@@ -2275,9 +2286,15 @@ void cylcor(Float_t& x, Float_t& y) {
 //____________________________________________________________________________
 void AliTOFReconstructioner::Matching(AliTOFTrack* trackArray, AliTOFRecHit* hitArray, Int_t ***mapPixels, AliTOFPad* pixelArray, Int_t* kTOFhitFirst, Int_t& ipixel, Int_t* iTrackPt, Int_t* iTOFpixel, Int_t ntotTpcTracks)
 {
 //____________________________________________________________________________
 void AliTOFReconstructioner::Matching(AliTOFTrack* trackArray, AliTOFRecHit* hitArray, Int_t ***mapPixels, AliTOFPad* pixelArray, Int_t* kTOFhitFirst, Int_t& ipixel, Int_t* iTrackPt, Int_t* iTOFpixel, Int_t ntotTpcTracks)
 {
-  Int_t TestTracks,iTestTrack,itest,ntest[fMaxTestTracks],testPixel[fMaxTestTracks],wPixel=0,itestc;
-  Float_t testLength[fMaxTestTracks],wLength=0.,testRho[fMaxTestTracks],testZ[fMaxTestTracks],wRho=0.,wZ=0.;
-  Float_t weight,testWeight[fMaxTestTracks];
+  Int_t TestTracks,iTestTrack,itest,wPixel=0,itestc;
+  Int_t * ntest = new Int_t[fMaxTestTracks];
+  Int_t * testPixel = new Int_t[fMaxTestTracks];
+  Float_t wLength=0.,wRho=0.,wZ=0.;
+  Float_t * testLength = new Float_t[fMaxTestTracks];
+  Float_t * testRho = new Float_t[fMaxTestTracks];
+  Float_t * testZ = new Float_t[fMaxTestTracks];
+  Float_t weight;
+  Float_t * testWeight = new Float_t[fMaxTestTracks];
   Float_t rotationFactor,phi0,coslam,sinlam,helixRadius,xHelixCenter,yHelixCenter,zHelixCenter,helixFactor;
   Int_t npixel[5],iMapValue,iwork1,iwork2,iwork3,iwork4,ihit=0;
   Int_t charge[48]={ 0, 1,-1, 0, 1,-1, 0, 1,-1, 0,
   Float_t rotationFactor,phi0,coslam,sinlam,helixRadius,xHelixCenter,yHelixCenter,zHelixCenter,helixFactor;
   Int_t npixel[5],iMapValue,iwork1,iwork2,iwork3,iwork4,ihit=0;
   Int_t charge[48]={ 0, 1,-1, 0, 1,-1, 0, 1,-1, 0,
@@ -2331,27 +2348,33 @@ void AliTOFReconstructioner::Matching(AliTOFTrack* trackArray, AliTOFRecHit* hit
     Float_t x=trackArray[itrack-1].GetRxTPC();
     Float_t y=trackArray[itrack-1].GetRyTPC();
     Float_t z=trackArray[itrack-1].GetRzTPC();
     Float_t x=trackArray[itrack-1].GetRxTPC();
     Float_t y=trackArray[itrack-1].GetRyTPC();
     Float_t z=trackArray[itrack-1].GetRzTPC();
+    /* vars used for QA
     Float_t RxTPC=x;
     Float_t RyTPC=y;
     Float_t RzTPC=z;
     Float_t RxTPC=x;
     Float_t RyTPC=y;
     Float_t RzTPC=z;
+    */
     Float_t Wx=x;
     Float_t Wy=y;
     Float_t Wz=z;
     Float_t px=trackArray[itrack-1].GetPxTPC();
     Float_t py=trackArray[itrack-1].GetPyTPC();
     Float_t pz=trackArray[itrack-1].GetPzTPC();
     Float_t Wx=x;
     Float_t Wy=y;
     Float_t Wz=z;
     Float_t px=trackArray[itrack-1].GetPxTPC();
     Float_t py=trackArray[itrack-1].GetPyTPC();
     Float_t pz=trackArray[itrack-1].GetPzTPC();
+    /* vars used for QA
     Float_t pxTPC=px;
     Float_t pyTPC=py;
     Float_t pzTPC=pz;
     Float_t pxTPC=px;
     Float_t pyTPC=py;
     Float_t pzTPC=pz;
-
+    */
     Float_t p = TMath::Sqrt(px*px+py*py+pz*pz);
     Float_t p = TMath::Sqrt(px*px+py*py+pz*pz);
+    /* var used for QA
     Float_t pTPC=p;
     Float_t pTPC=p;
-
+    */
     Float_t rho = TMath::Sqrt(x*x+y*y);
     Float_t phi=0.;
     if(TMath::Abs(x)>0. || TMath::Abs(y)>0.) phi=TMath::ATan2(y,x);
     if(phi<0.) phi=phi+2.*TMath::Pi();
     Float_t rho = TMath::Sqrt(x*x+y*y);
     Float_t phi=0.;
     if(TMath::Abs(x)>0. || TMath::Abs(y)>0.) phi=TMath::ATan2(y,x);
     if(phi<0.) phi=phi+2.*TMath::Pi();
+    /* var used for QA
     Float_t phiTPC=phi*kRaddeg;
     Float_t phiTPC=phi*kRaddeg;
+    */
     if(fSigmavsp) {
       if(p==0) printf(" p=%f in g=0.022/p\n",p);
       g=0.022/p;
     if(fSigmavsp) {
       if(p==0) printf(" p=%f in g=0.022/p\n",p);
       g=0.022/p;
@@ -2364,7 +2387,9 @@ void AliTOFReconstructioner::Matching(AliTOFTrack* trackArray, AliTOFRecHit* hit
     }
     x=rho*TMath::Cos(phi);
     y=rho*TMath::Sin(phi);
     }
     x=rho*TMath::Cos(phi);
     y=rho*TMath::Sin(phi);
+    /* var used for QA
     Float_t zTPC=z;
     Float_t zTPC=z;
+    */
     if(fSigmavsp) {
       if(p==0) printf(" p=%f in g=0.0275/p\n",p);
       g=0.0275/p;
     if(fSigmavsp) {
       if(p==0) printf(" p=%f in g=0.0275/p\n",p);
       g=0.0275/p;
@@ -2562,7 +2587,7 @@ void AliTOFReconstructioner::Matching(AliTOFTrack* trackArray, AliTOFRecHit* hit
        gz=zHelixCenter+s*sinlam;
        rho=TMath::Sqrt(gx*gx+gy*gy);
        
        gz=zHelixCenter+s*sinlam;
        rho=TMath::Sqrt(gx*gx+gy*gy);
        
-       IsInsideThePad(fg3,gx,gy,gz,npixel,zPad,xPad);
+       IsInsideThePad(gMC,gx,gy,gz,npixel,zPad,xPad);
        
        iplate += npixel[1];
        iPadAlongX += npixel[4];
        
        iplate += npixel[1];
        iPadAlongX += npixel[4];
@@ -2694,7 +2719,7 @@ void AliTOFReconstructioner::Matching(AliTOFTrack* trackArray, AliTOFRecHit* hit
          testZ[itest-1]=wZ;
          testWeight[itest-1]=weight;
        } else {
          testZ[itest-1]=wZ;
          testWeight[itest-1]=weight;
        } else {
-         Int_t k;
+         Int_t k=0;
          for(Int_t i=0;i<itest;i++) {
            k=0;
            if(testPixel[i]==wPixel) {
          for(Int_t i=0;i<itest;i++) {
            k=0;
            if(testPixel[i]==wPixel) {
@@ -2926,11 +2951,14 @@ void AliTOFReconstructioner::Matching(AliTOFTrack* trackArray, AliTOFRecHit* hit
       if(iTOFpixel[ipart] && match!=3) {
        particle = (TParticle*)gAlice->Particle(ipart);  //for V3.05
 
       if(iTOFpixel[ipart] && match!=3) {
        particle = (TParticle*)gAlice->Particle(ipart);  //for V3.05
 
-       printf("          ipixel=%i (Sector=%i, Plate=%i, Strip=%i, Pixel=%i), fired by %i track\n",iTOFpixel[ipart],pixelArray[iTOFpixel[ipart]-1].GetSector(),pixelArray[iTOFpixel[ipart]-1].GetPlate(),pixelArray[iTOFpixel[ipart]-1].GetStrip(),pixelArray[iTOFpixel[ipart]-1].GetPixel(),pixelArray[iTOFpixel[ipart]-1].GetTrack());   
-       printf("     indexOfTestTrack=%i itest=%i weightTestTracksOutTof[4]=%f weightTestTracksOutTof[2]=%f weightTestTracksOutTof[1]=%f weightTestTracksOutTof[0]=%f\n",indexOfTestTrack,itest,weightTestTracksOutTof[3],weightTestTracksOutTof[2],weightTestTracksOutTof[1],weightTestTracksOutTof[0]);
+       printf("          ipixel=%i (Sector=%i, Plate=%i, Strip=%i, Pixel=%i), fired by %i track\n",iTOFpixel[ipart],pixelArray[iTOFpixel[ipart]-1].GetSector(),pixelArray[iTOFpixel[ipart]-1].GetPlate(),pixelArray[iTOFpixel[ipart]-1].GetStrip(),pixelArray[iTOFpix
+el[ipart]-1].GetPixel(),pixelArray[iTOFpixel[ipart]-1].GetTrack());   
+       printf("     indexOfTestTrack=%i itest=%i weightTestTracksOutTof[4]=%f weightTestTracksOutTof[2]=%f weightTestTracksOutTof[1]=%f weightTestTracksOutTof[0]=%f\n",indexOfTestTrack,itest,weightTestTracksOutTof[3],weightTestTracksOutTof[2],weightTestTracksOu
+tTof[1],weightTestTracksOutTof[0]);
        if(itest) {
 
        if(itest) {
 
-         printf("     take ipixel=%i (Sector=%i, Plate=%i, Strip=%i, Pixel=%i), (fired by %i track), match=%i\n",wPixel,pixelArray[wPixel-1].GetSector(),pixelArray[wPixel-1].GetPlate(),pixelArray[wPixel-1].GetStrip(),pixelArray[wPixel-1].GetPixel(),pixelArray[wPixel-1].GetTrack(),match);   
+         printf("     take ipixel=%i (Sector=%i, Plate=%i, Strip=%i, Pixel=%i), (fired by %i track), match=%i\n",wPixel,pixelArray[wPixel-1].GetSector(),pixelArray[wPixel-1].GetPlate(),pixelArray[wPixel-1].GetStrip(),pixelArray[wPixel-1].GetPixel(),pixelArray[w
+Pixel-1].GetTrack(),match);   
        }
       }
     }
        }
       }
     }
@@ -2975,6 +3003,12 @@ void AliTOFReconstructioner::Matching(AliTOFTrack* trackArray, AliTOFRecHit* hit
   }
   
   cout << " ********************  End of matching **********" << endl;
   }
   
   cout << " ********************  End of matching **********" << endl;
+  delete [] ntest;
+  delete [] testPixel;
+  delete [] testLength;
+  delete [] testRho;
+  delete [] testZ;
+  delete [] testWeight;
 }
 
 //____________________________________________________________________________
 }
 
 //____________________________________________________________________________