]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TOF/AliTOFSDigitizer.cxx
Coverity RESOURCE_LEAK fixes
[u/mrichter/AliRoot.git] / TOF / AliTOFSDigitizer.cxx
index 910b55d0aa5b7c9bc8480fd170727768aab6918c..11bc1455f315bae7cfc40d53466c9245c05cbe64 100644 (file)
@@ -41,6 +41,8 @@
 #include "AliRunLoader.h"
 #include "AliRun.h"
 
+#include "AliTOFcalib.h"
+#include "AliTOFRecoParam.h"
 #include "AliTOFGeometry.h"
 #include "AliTOFHitMap.h"
 #include "AliTOFhitT0.h"
@@ -64,7 +66,7 @@ AliTOFSDigitizer::AliTOFSDigitizer():
   fTOFLoader(0x0),
   fSelectedSector(-1), 
   fSelectedPlate(-1),
-  fTimeResolution(0),
+  fTimeResolution(100.),
   fpadefficiency(0),
   fEdgeEffect(-1),
   fEdgeTails(-1),
@@ -93,9 +95,11 @@ AliTOFSDigitizer::AliTOFSDigitizer():
   fAverageTimeFlag(-1),
   fAdcBin(0),
   fAdcMean(0),
-  fAdcRms(0)
+  fAdcRms(0),
+  fCalib(new AliTOFcalib())
 {
   // ctor
+
 }
 
 //------------------------------------------------------------------------
@@ -109,7 +113,7 @@ AliTOFSDigitizer::AliTOFSDigitizer(const AliTOFSDigitizer &source):
   fTOFLoader(0x0),
   fSelectedSector(-1), 
   fSelectedPlate(-1),
-  fTimeResolution(0),
+  fTimeResolution(100.),
   fpadefficiency(0),
   fEdgeEffect(-1),
   fEdgeTails(-1),
@@ -138,7 +142,8 @@ AliTOFSDigitizer::AliTOFSDigitizer(const AliTOFSDigitizer &source):
   fAverageTimeFlag(-1),
   fAdcBin(0),
   fAdcMean(0),
-  fAdcRms(0)
+  fAdcRms(0),
+  fCalib(new AliTOFcalib())
 {
   // copy constructor
   //this->fTOFGeometry=source.fTOFGeometry;
@@ -164,7 +169,7 @@ AliTOFSDigitizer::AliTOFSDigitizer(const char* HeaderFile, Int_t evNumber1, Int_
   fTOFLoader(0x0),
   fSelectedSector(-1), // by default we sdigitize all sectors
   fSelectedPlate(-1),  // by default we sdigitize all plates in all sectors
-  fTimeResolution(0),
+  fTimeResolution(100.),
   fpadefficiency(0),
   fEdgeEffect(-1),
   fEdgeTails(-1),
@@ -193,7 +198,8 @@ AliTOFSDigitizer::AliTOFSDigitizer(const char* HeaderFile, Int_t evNumber1, Int_
   fAverageTimeFlag(-1),
   fAdcBin(0),
   fAdcMean(0),
-  fAdcRms(0)
+  fAdcRms(0),
+  fCalib(new AliTOFcalib())
 {
   //ctor, reading from input file 
   
@@ -260,6 +266,7 @@ AliTOFSDigitizer::AliTOFSDigitizer(const char* HeaderFile, Int_t evNumber1, Int_
       return;
     }
   fTOFLoader->PostSDigitizer(this);
+
 }
 
 //____________________________________________________________________________ 
@@ -268,6 +275,8 @@ AliTOFSDigitizer::~AliTOFSDigitizer()
   // dtor
   fTOFLoader->CleanSDigitizer();
 
+  if (fCalib) delete fCalib;
+
 }
 
 //____________________________________________________________________________ 
@@ -275,9 +284,20 @@ void AliTOFSDigitizer::InitParameters()
 {
   // set parameters for detector simulation
   
-  fTimeResolution = 0.080; //0.120; OLD
+  fCalib->Init();
+
+  //fTimeResolution = 80.; //120.; OLD
+  AliTOFRecoParam *recoParams = (AliTOFRecoParam*)fCalib->ReadRecParFromCDB("TOF/Calib",fRunLoader->GetRunNumber());
+  fTimeResolution = recoParams->GetTimeResolution(); // now from OCDB
+  if (fTimeResolution==0.) {
+    AliWarning("In OCDB found 0ps for TOF time resolution. It is set to 100ps.");
+    fTimeResolution = 100.;
+  }
+  AliDebug(1,Form(" TOF time resolution read from OCDB = %f ps",fTimeResolution));
   fpadefficiency  = 0.99 ;
-  fEdgeEffect     = 2   ;
+  //fEdgeEffect   = 2   ; // edge effects according to test beam results
+  fEdgeEffect     = 1   ; // edge effects according to test beam results
+                          // but with fixed time resolution, i.e. fTimeResolution
   fEdgeTails      = 0   ;
   fHparameter     = 0.4 ;
   fH2parameter    = 0.15;
@@ -314,7 +334,7 @@ void AliTOFSDigitizer::InitParameters()
 }
 
 //__________________________________________________________________
-Double_t TimeWithTail(Double_t* x, Double_t* par)
+Double_t TimeWithTail(const Double_t * const x, const Double_t * const par)
 {
   // sigma - par[0], alpha - par[1], part - par[2]
   //  at x<part*sigma - gauss
@@ -359,17 +379,26 @@ void AliTOFSDigitizer::Exec(Option_t *verboseOption) {
     AliError("TOF not found");
     return;
   }
-  
+
   fTOFLoader->LoadHits("read");
   fTOFLoader->LoadSDigits("recreate");
+
+  Int_t vol[5]={-1,-1,-1,-1,-1}; // location for a digit
+  Int_t digit[2]={0,0};          // TOF digit variables
   
+  Int_t nselectedHitsinEv=0;
+  Int_t ntotalsdigitsinEv=0;
+  Int_t ntotalupdatesinEv=0;
+  Int_t nnoisesdigitsinEv=0;
+  Int_t nsignalsdigitsinEv=0;
+
   for (Int_t iEvent=fEvent1; iEvent<fEvent2; iEvent++) {
     //AliInfo(Form("------------------- %s -------------", GetName()));
     //AliInfo(Form("Sdigitizing event %i", iEvent));
 
     fRunLoader->GetEvent(iEvent);
 
-    TTree *hitTree = fTOFLoader->TreeH ();
+    TTree *hitTree = fTOFLoader->TreeH();
     if (!hitTree) return;
 
     if (fTOFLoader->TreeS () == 0) fTOFLoader->MakeTree ("S");
@@ -388,18 +417,18 @@ void AliTOFSDigitizer::Exec(Option_t *verboseOption) {
 
     Int_t version=tof->IsVersion();
 
-    Int_t nselectedHitsinEv=0;
-    Int_t ntotalsdigitsinEv=0;
-    Int_t ntotalupdatesinEv=0;
-    Int_t nnoisesdigitsinEv=0;
-    Int_t nsignalsdigitsinEv=0;
+    nselectedHitsinEv=0;
+    ntotalsdigitsinEv=0;
+    ntotalupdatesinEv=0;
+    nnoisesdigitsinEv=0;
+    nsignalsdigitsinEv=0;
 
     TParticle *particle;
     //AliTOFhit *tofHit;
     TClonesArray *tofHitArray = tof->Hits();
 
     // create hit map
-    //    AliTOFHitMap *hitMap = new AliTOFHitMap(tof->SDigits(), fTOFGeometry);
+    //AliTOFHitMap *hitMap = new AliTOFHitMap(tof->SDigits(), fTOFGeometry);
     AliTOFHitMap *hitMap = new AliTOFHitMap(tof->SDigits());
 
     TBranch * tofHitsBranch = hitTree->GetBranch("TOF");
@@ -407,12 +436,12 @@ void AliTOFSDigitizer::Exec(Option_t *verboseOption) {
     Int_t ntracks = static_cast<Int_t>(hitTree->GetEntries());
     for (Int_t track = 0; track < ntracks; track++)
     {
-      gAlice->ResetHits();
+      gAlice->GetMCApp()->ResetHits();
       tofHitsBranch->GetEvent(track);
 
       AliMC *mcApplication = (AliMC*)gAlice->GetMCApp();
 
-      particle = mcApplication->Particle(track);
+      particle = (TParticle*)mcApplication->Particle(track);
       Int_t nhits = tofHitArray->GetEntriesFast();
       // cleaning all hits of the same track in the same pad volume
       // it is a rare event, however it happens
@@ -425,9 +454,9 @@ void AliTOFSDigitizer::Exec(Option_t *verboseOption) {
       Int_t previousPadZ  =-1;
 
       for (Int_t hit = 0; hit < nhits; hit++) {
-       Int_t    vol[5];       // location for a digit
-       Int_t  digit[2];     // TOF digit variables
-       Int_t tracknum;
+       for (Int_t aa=0; aa<5;aa++) vol[aa]=-1;  // location for a digit
+       for (Int_t aa=0; aa<2;aa++) digit[aa]=0; // TOF digit variables
+       Int_t   tracknum;
        Float_t dxPad;
        Float_t dzPad;
        Float_t geantTime;
@@ -444,7 +473,7 @@ void AliTOFSDigitizer::Exec(Option_t *verboseOption) {
          vol[4] = tofHit->GetPadz();
          dxPad = tofHit->GetDx();
          dzPad = tofHit->GetDz();
-         geantTime = tofHit->GetTof(); // unit [s]
+         geantTime = tofHit->GetTof(); // unit [s] // already corrected per event_time smearing
        } else {
          AliTOFhitT0 *tofHit = (AliTOFhitT0 *) tofHitArray->UncheckedAt(hit);
          tracknum = tofHit->GetTrack();
@@ -455,11 +484,17 @@ void AliTOFSDigitizer::Exec(Option_t *verboseOption) {
          vol[4] = tofHit->GetPadz();
          dxPad = tofHit->GetDx();
          dzPad = tofHit->GetDz();
-         geantTime = tofHit->GetTof(); // unit [s]
+         geantTime = tofHit->GetTof(); // unit [s] // already corrected per event_time_smearing
        }
        
        geantTime *= 1.e+09;  // conversion from [s] to [ns]
-       
+       // TOF matching window (~200ns) control
+       if (geantTime>=AliTOFGeometry::MatchingWindow()*1E-3) {
+         AliDebug(2,Form("Time measurement (%f) greater than the matching window (%f)",
+                         geantTime, AliTOFGeometry::MatchingWindow()*1E-3));
+         continue;
+       }
+
        // selection case for sdigitizing only hits in a given plate of a given sector
        if(thereIsNotASelection || (vol[0]==fSelectedSector && vol[1]==fSelectedPlate)){
          
@@ -497,8 +532,15 @@ void AliTOFSDigitizer::Exec(Option_t *verboseOption) {
              for(Int_t indexOfPad=0; indexOfPad<nActivatedPads; indexOfPad++) {
                if(isFired[indexOfPad]){ // the pad has fired
                  Float_t timediff=geantTime-tofAfterSimul[indexOfPad];
-                 
-                 if(timediff>=0.2) nlargeTofDiff++;
+
+                 // TOF matching window (~200ns) control
+                 if (tofAfterSimul[indexOfPad]>=AliTOFGeometry::MatchingWindow()*1E-3) {
+                   AliDebug(2,Form("Time measurement (%f) greater than the matching window (%f)",
+                                   tofAfterSimul[indexOfPad], AliTOFGeometry::MatchingWindow()*1E-3));
+                   continue;
+                 }
+
+                 if(timediff>=0.2) nlargeTofDiff++; // greater than 200ps
                  
                  digit[0] = (Int_t) ((tofAfterSimul[indexOfPad]*1.e+03)/AliTOFGeometry::TdcBinWidth()); // TDC bin number (each bin -> 24.4 ps)
                  
@@ -550,15 +592,14 @@ void AliTOFSDigitizer::Exec(Option_t *verboseOption) {
     
     if (tof->SDigits()) tof->ResetSDigits();
     
-    if (strstr(verboseOption,"all")) {
-      AliInfo("----------------------------------------");
-      AliInfo("       <AliTOFSDigitizer>    ");
-      AliInfo(Form("After sdigitizing %d hits in event %d", nselectedHitsinEv, iEvent));
+    if (strstr(verboseOption,"all") || strstr(verboseOption,"partial")) {
+      AliDebug(2,"----------------------------------------");
+      AliDebug(2,Form("After sdigitizing %d hits in event %d", nselectedHitsinEv, iEvent));
       //" (" << nHitsFromPrim << " from primaries and " << nHitsFromSec << " from secondaries) TOF hits, " 
-      AliInfo(Form("%d digits have been created", ntotalsdigitsinEv));
-      AliInfo(Form("(%d due to signals and %d due to border effect)", nsignalsdigitsinEv, nnoisesdigitsinEv));
-      AliInfo(Form("%d total updates of the hit map have been performed in current event", ntotalupdatesinEv));
-      AliInfo("----------------------------------------");
+      AliDebug(1,Form("%d sdigits have been created", ntotalsdigitsinEv));
+      AliDebug(2,Form("(%d due to signals and %d due to border effect)", nsignalsdigitsinEv, nnoisesdigitsinEv));
+      AliDebug(2,Form("%d total updates of the hit map have been performed in current event", ntotalupdatesinEv));
+      AliDebug(2,"----------------------------------------");
     }
 
   } //event loop on events
@@ -575,19 +616,15 @@ void AliTOFSDigitizer::Exec(Option_t *verboseOption) {
   }
   
   nHitsFromSec=nselectedHits-nHitsFromPrim;
-  if(strstr(verboseOption,"all")){
-    AliInfo("----------------------------------------");
-    AliInfo("----------------------------------------");
-    AliInfo("-----------SDigitization Summary--------");
-    AliInfo("       <AliTOFSDigitizer>     ");
-    AliInfo(Form("After sdigitizing %d hits", nselectedHits));
-    AliInfo(Form("in %d events", fEvent2-fEvent1));
-//" (" << nHitsFromPrim << " from primaries and " << nHitsFromSec << " from secondaries) TOF hits, " 
-    AliInfo(Form("%d sdigits have been created", ntotalsdigits));
-    AliInfo(Form("(%d due to signals and " 
-                "%d due to border effect)", nsignalsdigits, nnoisesdigits));
-    AliInfo(Form("%d total updates of the hit map have been performed", ntotalupdates));
-    AliInfo(Form("in %d cases the time of flight difference is greater than 200 ps", nlargeTofDiff));
+  if (strstr(verboseOption,"all") || strstr(verboseOption,"partial")) {
+    AliDebug(2,"----------------------------------------");
+    AliDebug(2,Form("After sdigitizing %d hits in %d events ", nselectedHits, fEvent2-fEvent1));
+    //" (" << nHitsFromPrim << " from primaries and " << nHitsFromSec << " from secondaries) TOF hits, " 
+    AliDebug(2,Form("%d sdigits have been created", ntotalsdigits));
+    AliDebug(2,Form("(%d due to signals and %d due to border effect)", nsignalsdigits, nnoisesdigits));
+    AliDebug(2,Form("%d total updates of the hit map have been performed", ntotalupdates));
+    AliDebug(2,Form("in %d cases the time of flight difference is greater than 200 ps", nlargeTofDiff));
+    AliDebug(2,"----------------------------------------");
   }
 
 
@@ -698,20 +735,26 @@ void AliTOFSDigitizer::SimulateDetectorResponse(Float_t z0, Float_t x0, Float_t
       tofTime[nActivatedPads-1] = gRandom->Gaus(geantTime + fTimeWalkCenter, res[0]);
       averageTime = tofTime[nActivatedPads-1];
     }
-  } else {
-     
+  } else { // if (fEdgeEffet!=0)
+
     if(z < h) {
       if(z < h2) {
        effZ = fEffBoundary + (fEff2Boundary - fEffBoundary) * z / h2;
       } else {
        effZ = fEff2Boundary + (fEffCenter - fEff2Boundary) * (z - h2) / (h - h2);
       }
-      resZ = fResBoundary + (fResCenter - fResBoundary) * z / h;
+      if (fEdgeEffect==1)
+       resZ = fTimeResolution;
+      else if (fEdgeEffect==2)
+       resZ = fResBoundary + (fResCenter - fResBoundary) * z / h;
       timeWalkZ = fTimeWalkBoundary + (fTimeWalkCenter - fTimeWalkBoundary) * z / h;
       nTail[nActivatedPads-1] = 1;
     } else {
       effZ = fEffCenter;
-      resZ = fResCenter;
+      if (fEdgeEffect==1)
+       resZ = fTimeResolution;
+      else if (fEdgeEffect==2)
+       resZ = fResCenter;
       timeWalkZ = fTimeWalkCenter;
     }
     
@@ -721,12 +764,18 @@ void AliTOFSDigitizer::SimulateDetectorResponse(Float_t z0, Float_t x0, Float_t
       } else {
        effX = fEff2Boundary + (fEffCenter - fEff2Boundary) * (x - h2) / (h - h2);
       }
-      resX = fResBoundary + (fResCenter - fResBoundary) * x / h;
+      if (fEdgeEffect==1)
+       resX = fTimeResolution;
+      else if (fEdgeEffect==2)
+       resX = fResBoundary + (fResCenter - fResBoundary) * x / h;
       timeWalkX = fTimeWalkBoundary + (fTimeWalkCenter - fTimeWalkBoundary) * x / h;
       nTail[nActivatedPads-1] = 1;
     } else {
       effX = fEffCenter;
-      resX = fResCenter;
+      if (fEdgeEffect==1)
+       resX = fTimeResolution;
+      else if (fEdgeEffect==2)
+       resX = fResCenter;
       timeWalkX = fTimeWalkCenter;
     }
     
@@ -741,7 +790,10 @@ void AliTOFSDigitizer::SimulateDetectorResponse(Float_t z0, Float_t x0, Float_t
     } else {
       effZ = fEff3Boundary * (k - z) / (k - k2);
     }
-    resZ = fResBoundary + fResSlope * z / k;
+    if (fEdgeEffect==1)
+      resZ = fTimeResolution;
+    else if (fEdgeEffect==2)
+      resZ = fResBoundary + fResSlope * z / k;
     timeWalkZ = fTimeWalkBoundary + fTimeWalkSlope * z / k;
     
     if(z < k && z > 0) {
@@ -772,7 +824,10 @@ void AliTOFSDigitizer::SimulateDetectorResponse(Float_t z0, Float_t x0, Float_t
     } else {
       effX = fEff3Boundary * (k - x) / (k - k2);
     }
-    resX = fResBoundary + fResSlope*x/k;
+    if (fEdgeEffect==1)
+      resX = fTimeResolution;
+    else if (fEdgeEffect==2)
+      resX = fResBoundary + fResSlope*x/k;
     timeWalkX = fTimeWalkBoundary + fTimeWalkSlope*x/k;
     
     if(x < k && x > 0) {
@@ -879,7 +934,7 @@ void AliTOFSDigitizer::SimulateDetectorResponse(Float_t z0, Float_t x0, Float_t
 
 
     for (Int_t iPad = 0; iPad < nActivatedPads; iPad++) {
-      if (res[iPad] < fTimeResolution) res[iPad] = fTimeResolution;
+      if (fEdgeEffect==2 && res[iPad] < fTimeResolution) res[iPad] = fTimeResolution;
       if(gRandom->Rndm() < eff[iPad]) {
        isFired[iPad] = kTRUE;
        nFiredPads++;
@@ -892,6 +947,7 @@ void AliTOFSDigitizer::SimulateDetectorResponse(Float_t z0, Float_t x0, Float_t
            tofTime[iPad] = geantTime + timeWalk[iPad] + timeDelay[iPad] + timeAB;
          }
        } else {
+         AliDebug(1,Form(" ----------------- TOF time resolution = %f",res[iPad]));
          tofTime[iPad] = gRandom->Gaus(geantTime + timeWalk[iPad] + timeDelay[iPad], res[iPad]);
        }
        if (fAverageTimeFlag) {
@@ -919,29 +975,29 @@ void AliTOFSDigitizer::PrintParameters()const
   
   AliInfo(Form(" Number of events:                       %i ", (fEvent2-fEvent1)));
   AliInfo(Form(" from event %i to event %i", fEvent1, (fEvent2-1)));
-  AliInfo(Form(" Time Resolution (ns) %d  Pad Efficiency: %d ", fTimeResolution, fpadefficiency));
+  AliInfo(Form(" Time Resolution (ps) %f  Pad Efficiency: %f ", fTimeResolution, fpadefficiency));
   AliInfo(Form(" Edge Effect option:  %d", fEdgeEffect));
 
   AliInfo(" Boundary Effect Simulation Parameters ");
-  AliInfo(Form(" Hparameter: %d  H2parameter: %d  Kparameter: %d  K2parameter: %d", fHparameter, fH2parameter, fKparameter, fK2parameter));
-  AliInfo(Form(" Efficiency in the central region of the pad: %d", fEffCenter));
-  AliInfo(Form(" Efficiency at the boundary region of the pad: %d", fEffBoundary));
-  AliInfo(Form(" Efficiency value at H2parameter %d", fEff2Boundary));
-  AliInfo(Form(" Efficiency value at K2parameter %d", fEff3Boundary));
-  AliInfo(Form(" Resolution (ps) in the central region of the pad: %d", fResCenter));
-  AliInfo(Form(" Resolution (ps) at the boundary of the pad      : %d", fResBoundary));
-  AliInfo(Form(" Slope (ps/K) for neighbouring pad               : %d", fResSlope));
-  AliInfo(Form(" Time walk (ps) in the central region of the pad : %d", fTimeWalkCenter));
-  AliInfo(Form(" Time walk (ps) at the boundary of the pad       : %d", fTimeWalkBoundary));
-  AliInfo(Form(" Slope (ps/K) for neighbouring pad               : %d", fTimeWalkSlope));
+  AliInfo(Form(" Hparameter: %f  H2parameter: %f  Kparameter: %f  K2parameter: %f", fHparameter, fH2parameter, fKparameter, fK2parameter));
+  AliInfo(Form(" Efficiency in the central region of the pad: %f", fEffCenter));
+  AliInfo(Form(" Efficiency at the boundary region of the pad: %f", fEffBoundary));
+  AliInfo(Form(" Efficiency value at H2parameter %f", fEff2Boundary));
+  AliInfo(Form(" Efficiency value at K2parameter %f", fEff3Boundary));
+  AliInfo(Form(" Resolution (ps) in the central region of the pad: %f", fResCenter));
+  AliInfo(Form(" Resolution (ps) at the boundary of the pad      : %f", fResBoundary));
+  AliInfo(Form(" Slope (ps/K) for neighbouring pad               : %f", fResSlope));
+  AliInfo(Form(" Time walk (ps) in the central region of the pad : %f", fTimeWalkCenter));
+  AliInfo(Form(" Time walk (ps) at the boundary of the pad       : %f", fTimeWalkBoundary));
+  AliInfo(Form(" Slope (ps/K) for neighbouring pad               : %f", fTimeWalkSlope));
   AliInfo(" Pulse Heigth Simulation Parameters ");
   AliInfo(Form(" Flag for delay due to the PulseHeightEffect  : %d", fTimeDelayFlag));
-  AliInfo(Form(" Pulse Height Slope                           : %d", fPulseHeightSlope));
-  AliInfo(Form(" Time Delay Slope                             : %d", fTimeDelaySlope));
-  AliInfo(Form(" Minimum charge amount which could be induced : %d", fMinimumCharge));
-  AliInfo(Form(" Smearing in charge in (q1/q2) vs x plot      : %d", fChargeSmearing));
-  AliInfo(Form(" Smearing in log of charge ratio              : %d", fLogChargeSmearing));
-  AliInfo(Form(" Smearing in time in time vs log(q1/q2) plot  : %d", fTimeSmearing));
+  AliInfo(Form(" Pulse Height Slope                           : %f", fPulseHeightSlope));
+  AliInfo(Form(" Time Delay Slope                             : %f", fTimeDelaySlope));
+  AliInfo(Form(" Minimum charge amount which could be induced : %f", fMinimumCharge));
+  AliInfo(Form(" Smearing in charge in (q1/q2) vs x plot      : %f", fChargeSmearing));
+  AliInfo(Form(" Smearing in log of charge ratio              : %f", fLogChargeSmearing));
+  AliInfo(Form(" Smearing in time in time vs log(q1/q2) plot  : %f", fTimeSmearing));
   AliInfo(Form(" Flag for average time                        : %d", fAverageTimeFlag));
   AliInfo(Form(" Edge tails option                            : %d", fEdgeTails));