]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - FMD/AliFMDBaseDigitizer.cxx
Important changes to the reconstructor classes. Complete elimination of the run-loade...
[u/mrichter/AliRoot.git] / FMD / AliFMDBaseDigitizer.cxx
index 30aa74df29029e4991e896644504ce3e40c76880..11c7056b100e458f863c5c320b436af6580b1330 100644 (file)
 //                    -1 + B + exp(-B)
 //
 
+#include <TMath.h>
 #include <TTree.h>             // ROOT_TTree
 //#include <TRandom.h>         // ROOT_TRandom
-#include <AliLog.h>            // ALILOG_H
+// #include <AliLog.h>         // ALILOG_H
+#include "AliFMDDebug.h" // Better debug macros
 #include "AliFMDBaseDigitizer.h" // ALIFMDDIGITIZER_H
 #include "AliFMD.h"            // ALIFMD_H
 #include "AliFMDGeometry.h"    // ALIFMDGEOMETRY_H
@@ -220,7 +222,12 @@ ClassImp(AliFMDBaseDigitizer)
 
 //____________________________________________________________________
 AliFMDBaseDigitizer::AliFMDBaseDigitizer()  
-  : fRunLoader(0)
+  : fRunLoader(0),
+    fEdep(AliFMDMap::kMaxDetectors, 
+         AliFMDMap::kMaxRings, 
+         AliFMDMap::kMaxSectors, 
+         AliFMDMap::kMaxStrips),
+    fShapingTime(0)
 {
   // Default ctor - don't use it
 }
@@ -232,10 +239,11 @@ AliFMDBaseDigitizer::AliFMDBaseDigitizer(AliRunDigitizer* manager)
     fEdep(AliFMDMap::kMaxDetectors, 
          AliFMDMap::kMaxRings, 
          AliFMDMap::kMaxSectors, 
-         AliFMDMap::kMaxStrips)
+         AliFMDMap::kMaxStrips), 
+    fShapingTime(0)
 {
   // Normal CTOR
-  AliDebug(1," processed");
+  AliFMDDebug(1, (" processed"));
   SetShapingTime();
 }
 
@@ -250,7 +258,7 @@ AliFMDBaseDigitizer::AliFMDBaseDigitizer(const Char_t* name,
          AliFMDMap::kMaxStrips)
 {
   // Normal CTOR
-  AliDebug(1," processed");
+  AliFMDDebug(1, (" processed"));
   SetShapingTime();
 }
 
@@ -340,21 +348,23 @@ AliFMDBaseDigitizer::SumContributions(AliFMD* fmd)
       // UShort_t minstrip = param->GetMinStrip(detector, ring, sector, strip);
       // UShort_t maxstrip = param->GetMaxStrip(detector, ring, sector, strip);
       // Check if strip is `dead' 
+      AliFMDDebug(2, ("Hit in FMD%d%c[%2d,%3d]=%f",
+                     detector, ring, sector, strip, edep));
       if (param->IsDead(detector, ring, sector, strip)) { 
-       AliDebug(5, Form("FMD%d%c[%2d,%3d] is marked as dead", 
+       AliFMDDebug(1, ("FMD%d%c[%2d,%3d] is marked as dead", 
                         detector, ring, sector, strip));
        continue;
       }
       // Check if strip is out-side read-out range 
       // if (strip < minstrip || strip > maxstrip) {
-      //   AliDebug(5, Form("FMD%d%c[%2d,%3d] is outside range [%3d,%3d]", 
+      //   AliFMDDebug(5, ("FMD%d%c[%2d,%3d] is outside range [%3d,%3d]", 
       //                   detector,ring,sector,strip,minstrip,maxstrip));
       //   continue;
       // }
        
       // Give warning in case of double hit 
       if (fEdep(detector, ring, sector, strip).fEdep != 0)
-       AliDebug(5, Form("Double hit in %d%c(%d,%d)", 
+       AliFMDDebug(5, ("Double hit in %d%c(%d,%d)", 
                         detector, ring, sector, strip));
       
       // Sum energy deposition
@@ -363,7 +373,7 @@ AliFMDBaseDigitizer::SumContributions(AliFMD* fmd)
       // Add this to the energy deposited for this strip
     }  // hit loop
   } // track loop
-  AliDebug(1, Form("Size of cache: %d bytes, read %d bytes", 
+  AliFMDDebug(1, ("Size of cache: %d bytes, read %d bytes", 
                   sizeof(fEdep), read));
 }
 
@@ -379,11 +389,13 @@ AliFMDBaseDigitizer::DigitizeHits(AliFMD* fmd) const
   
   TArrayI counts(3);
   for (UShort_t detector=1; detector <= 3; detector++) {
+    AliFMDDebug(5, ("Processing hits in FMD%d", detector));
     // Get pointer to subdetector 
     AliFMDDetector* det = geometry->GetDetector(detector);
     if (!det) continue;
     for (UShort_t ringi = 0; ringi <= 1; ringi++) {
       Char_t ring = ringi == 0 ? 'I' : 'O';
+      AliFMDDebug(5, (" Processing hits in FMD%d%c", detector,ring));
       // Get pointer to Ring
       AliFMDRing* r = det->GetRing(ring);
       if (!r) continue;
@@ -392,6 +404,8 @@ AliFMDBaseDigitizer::DigitizeHits(AliFMD* fmd) const
       UShort_t nSectors = UShort_t(360. / r->GetTheta());
       // Loop over the number of sectors 
       for (UShort_t sector = 0; sector < nSectors; sector++) {
+       AliFMDDebug(5, ("  Processing hits in FMD%d%c[%2d]", 
+                       detector,ring,sector));
        // Get number of strips 
        UShort_t nStrips = r->GetNStrips();
        // Loop over the stips 
@@ -409,6 +423,8 @@ AliFMDBaseDigitizer::DigitizeHits(AliFMD* fmd) const
          AddDigit(fmd, detector, ring, sector, strip, edep, 
                   UShort_t(counts[0]), Short_t(counts[1]), 
                   Short_t(counts[2]));
+         AliFMDDebug(10, ("   Adding digit in FMD%d%c[%2d,%3d]=%d", 
+                         detector,ring,sector,strip,counts[0]));
 #if 0
          // This checks if the digit created will give the `right'
          // number of particles when reconstructed, using a naiive
@@ -471,25 +487,35 @@ AliFMDBaseDigitizer::ConvertToCount(Float_t   edep,
   //                  = E + (l - E) * ext(-B * t)
   // 
   AliFMDParameters* param = AliFMDParameters::Instance();
-  Float_t  convF          = 1/param->GetPulseGain(detector,ring,sector,strip);
-  UShort_t ped            = MakePedestal(detector,ring,sector,strip);
-  UInt_t   maxAdc         = param->GetAltroChannelSize()-1;
+  Float_t  convF          = 1./param->GetPulseGain(detector,ring,sector,strip);
+  Int_t    ped            = MakePedestal(detector,ring,sector,strip);
+  Int_t    maxAdc         = param->GetAltroChannelSize()-1;
+  if (maxAdc < 0) {
+    AliWarning(Form("Maximum ADC is %d < 0, forcing it to 1023", maxAdc));
+    maxAdc = 1023;
+  }
   UShort_t rate           = param->GetSampleRate(detector,ring,sector,strip);
+  if (rate < 1 || rate > 3) rate = 1;
   
   // In case we don't oversample, just return the end value. 
   if (rate == 1) {
-    counts[0] = UShort_t(TMath::Min(edep * convF + ped, Float_t(maxAdc)));
-    AliDebug(2, Form("FMD%d%c[%2d,%3d]: converting ELoss %f to ADC %d (%f)", 
-                    detector,ring,sector,strip,edep,counts[0],convF));
+    Float_t    a = edep * convF + ped;
+    if (a < 0) a = 0;
+    counts[0]    = UShort_t(TMath::Min(a, Float_t(maxAdc)));
+    AliFMDDebug(2, ("FMD%d%c[%2d,%3d]: converting ELoss %f to "
+                    "ADC %4d (%f,%d)",
+                    detector,ring,sector,strip,edep,counts[0],convF,ped));
     return;
   }
   
   // Create a pedestal 
   Float_t b = fShapingTime;
   for (Ssiz_t i = 0; i < rate;  i++) {
-    Float_t t = Float_t(i) / rate;
-    Float_t s = edep + (last - edep) * TMath::Exp(-b * t);
-    counts[i] = UShort_t(TMath::Min(s * convF + ped, Float_t(maxAdc)));
+    Float_t t  = Float_t(i) / rate;
+    Float_t s  = edep + (last - edep) * TMath::Exp(-b * t);
+    Float_t a  = Int_t(s * convF + ped);
+    if (a < 0) a = 0;
+    counts[i]  = UShort_t(TMath::Min(a, Float_t(maxAdc)));
   }
 }