Fix range and binning on histograms
[u/mrichter/AliRoot.git] / FMD / AliFMDBaseDigitizer.cxx
index 06fec44..9ae092c 100644 (file)
@@ -230,7 +230,9 @@ AliFMDBaseDigitizer::AliFMDBaseDigitizer()
          AliFMDMap::kMaxRings, 
          AliFMDMap::kMaxSectors, 
          AliFMDMap::kMaxStrips),
-    fShapingTime(6)
+    fShapingTime(6),
+    fStoreTrackRefs(kTRUE), 
+    fIgnoredLabels(0)
 {
   AliFMDDebug(1, ("Constructed"));
   // Default ctor - don't use it
@@ -241,11 +243,10 @@ AliFMDBaseDigitizer::AliFMDBaseDigitizer(AliRunDigitizer* manager)
   : AliDigitizer(manager, "AliFMDBaseDigitizer", "FMD Digitizer base class"), 
     fFMD(0),
     fRunLoader(0),
-    fEdep(AliFMDMap::kMaxDetectors, 
-         AliFMDMap::kMaxRings, 
-         AliFMDMap::kMaxSectors, 
-         AliFMDMap::kMaxStrips), 
-    fShapingTime(6)
+    fEdep(0),        // nDet==0 means 51200 slots
+    fShapingTime(6),
+    fStoreTrackRefs(kTRUE), 
+    fIgnoredLabels(0)
 {
   // Normal CTOR
   AliFMDDebug(1, ("Constructed"));
@@ -258,11 +259,10 @@ AliFMDBaseDigitizer::AliFMDBaseDigitizer(const Char_t* name,
   : AliDigitizer(name, title),
     fFMD(0),
     fRunLoader(0),
-    fEdep(AliFMDMap::kMaxDetectors, 
-         AliFMDMap::kMaxRings, 
-         AliFMDMap::kMaxSectors, 
-         AliFMDMap::kMaxStrips),
-    fShapingTime(6)
+    fEdep(0),        // nDet==0 means 51200 slots
+    fShapingTime(6),
+    fStoreTrackRefs(kTRUE), 
+    fIgnoredLabels(0)
 {
   // Normal CTOR
   AliFMDDebug(1, (" Constructed"));
@@ -276,6 +276,25 @@ AliFMDBaseDigitizer::~AliFMDBaseDigitizer()
 }
 
 //____________________________________________________________________
+AliFMDBaseDigitizer&
+AliFMDBaseDigitizer::operator=(const AliFMDBaseDigitizer& o) 
+{ 
+  // 
+  // Assignment operator
+  // 
+  // Return:
+  //    Reference to this object 
+  //
+  AliDigitizer::operator=(o);
+  fRunLoader      = o.fRunLoader;
+  fEdep           = o.fEdep;
+  fShapingTime    = o.fShapingTime;
+  fStoreTrackRefs = o.fStoreTrackRefs;
+  fIgnoredLabels  = o.fIgnoredLabels;
+  return *this; 
+}
+
+//____________________________________________________________________
 Bool_t 
 AliFMDBaseDigitizer::Init()
 {
@@ -309,11 +328,22 @@ AliFMDBaseDigitizer::AddContribution(UShort_t detector,
                                     Char_t   ring, 
                                     UShort_t sector, 
                                     UShort_t strip, 
-                                    Float_t  edep)
+                                    Float_t  edep, 
+                                    Bool_t   isPrimary,
+                                    Int_t    nTrack,
+                                    Int_t*   tracknos)
 {
   // Add edep contribution from (detector,ring,sector,strip) to cache
   AliFMDParameters* param = AliFMDParameters::Instance();
-
+  AliFMDDebug(10, ("Adding contribution %7.5f for FMD%d%c[%2d,%3d] "
+                 " from %d tracks (%s)", 
+                 edep,
+                 detector, 
+                 ring,
+                 sector, 
+                 strip, 
+                 nTrack, 
+                 (isPrimary ? "primary" : "secondary")));
   // Check if strip is `dead' 
   if (param->IsDead(detector, ring, sector, strip)) { 
     AliFMDDebug(5, ("FMD%d%c[%2d,%3d] is marked as dead", 
@@ -327,14 +357,34 @@ AliFMDBaseDigitizer::AddContribution(UShort_t detector,
   //   continue;
   // }
   
+  AliFMDEdepHitPair& entry = fEdep(detector, ring, sector, strip);
+
   // Give warning in case of double sdigit 
-  if (fEdep(detector, ring, sector, strip).fEdep != 0)
-    AliFMDDebug(5, ("Double digit in %d%c(%d,%d)", 
+  if (entry.fEdep != 0)
+    AliFMDDebug(5, ("Double digit in FMD%d%c[%2d,%3d]", 
                    detector, ring, sector, strip));
       
   // Sum energy deposition
-  fEdep(detector, ring, sector, strip).fEdep  += edep;
-  fEdep(detector, ring, sector, strip).fN     += 1;
+  Int_t oldN  =  entry.fN;
+  entry.fEdep += edep;
+  entry.fN    += nTrack;
+  if (isPrimary) entry.fNPrim += nTrack;
+  if (fStoreTrackRefs) { 
+    if (entry.fLabels.fN < entry.fN) {
+      AliFMDDebug(15, ("== New label array size %d, was %d, added %d", 
+                      entry.fN, entry.fLabels.fN, nTrack));
+      entry.fLabels.Set(entry.fN);
+    }
+    for (Int_t i = 0; i < nTrack; i++) {
+      AliFMDDebug(15, ("=> Setting track label # %d", oldN+i));
+      entry.fLabels[oldN + i] = tracknos[i];
+      AliFMDDebug(15, ("<= Setting track label # %d", oldN+i));
+    }
+  }
+  AliFMDDebug(15,("Adding contribution %f to FMD%d%c[%2d,%3d] (%f) track %d", 
+                 edep, detector, ring, sector, strip,
+                 entry.fEdep, (nTrack > 0 ? tracknos[0] : -1)));
+  
 }
 
 //____________________________________________________________________
@@ -346,6 +396,7 @@ AliFMDBaseDigitizer::DigitizeHits() const
   // the digits array (AliFMD::fDigits)
   //
   AliFMDDebug(5, ("Will now digitize all the summed signals"));
+  fIgnoredLabels = 0;
   AliFMDGeometry* geometry = AliFMDGeometry::Instance();
   
   TArrayI counts(4);
@@ -378,10 +429,18 @@ AliFMDBaseDigitizer::DigitizeHits() const
          // VA1_ALICE channel. 
          if (strip % 128 == 0) last = 0;
          
-         Float_t edep = fEdep(detector, ring, sector, strip).fEdep;
+         const AliFMDEdepHitPair& entry  = fEdep(detector,ring,sector,strip);
+         Float_t                  edep   = entry.fEdep;
+         UShort_t                 ntot   = entry.fN;
+         UShort_t                 nprim  = entry.fNPrim;
+         const TArrayI&           labels = entry.fLabels;
+         if (edep > 0)
+           AliFMDDebug(15, ("Edep = %f for FMD%d%c[%2d,%3d]", 
+                            edep, detector, ring, sector, strip));
          ConvertToCount(edep, last, detector, ring, sector, strip, counts);
          last = edep;
          
+
          // The following line was introduced - wrongly - by Peter
          // Hristov.  It _will_ break the digitisation and the
          // following reconstruction.  The behviour of the
@@ -401,9 +460,10 @@ AliFMDBaseDigitizer::DigitizeHits() const
          //   if (edep<=0) continue;
          AddDigit(detector, ring, sector, strip, edep, 
                   UShort_t(counts[0]), Short_t(counts[1]), 
-                  Short_t(counts[2]), Short_t(counts[3]));
+                  Short_t(counts[2]), Short_t(counts[3]), 
+                  ntot, nprim, labels);
          AliFMDDebug(15, ("   Adding digit in FMD%d%c[%2d,%3d]=%d", 
-                         detector,ring,sector,strip,counts[0]));
+                          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
@@ -416,6 +476,10 @@ AliFMDBaseDigitizer::DigitizeHits() const
       } // Sector 
     } // Ring 
   } // Detector 
+  if (fIgnoredLabels > 0) 
+    AliWarning(Form("%d track labels could not be associated with digits "
+                   "due to limited storage facilities in AliDigit", 
+                   fIgnoredLabels));
 }
 
 //____________________________________________________________________
@@ -466,7 +530,8 @@ 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);
+  Float_t  convF          = (param->GetDACPerMIP() / param->GetEdepMip() *
+                            param->GetPulseGain(detector,ring,sector,strip));
   Int_t    ped            = MakePedestal(detector,ring,sector,strip);
   Int_t    maxAdc         = param->GetAltroChannelSize()-1;
   if (maxAdc < 0) {
@@ -475,7 +540,7 @@ AliFMDBaseDigitizer::ConvertToCount(Float_t   edep,
   }
   UShort_t rate           = param->GetSampleRate(detector,ring,sector,strip);
   AliFMDDebug(15, ("Sample rate for FMD%d%c[%2d,%3d] = %d", 
-                 detector, ring, sector, strip, rate));
+                  detector, ring, sector, strip, rate));
   if (rate < 1 || rate > 4) {
     AliWarning(Form("Invalid sample rate for for FMD%d%c[%2d,%3d] = %d", 
                    detector, ring, sector, strip, rate));
@@ -492,6 +557,7 @@ AliFMDBaseDigitizer::ConvertToCount(Float_t   edep,
                     detector,ring,sector,strip,edep,counts[0],convF,ped));
     return;
   }
+
   
   // Create a pedestal 
   Float_t b = fShapingTime;
@@ -502,24 +568,34 @@ AliFMDBaseDigitizer::ConvertToCount(Float_t   edep,
     if (a < 0) a = 0;
     counts[i]  = UShort_t(TMath::Min(a, Float_t(maxAdc)));
   }
+  AliFMDDebug(15, ("Converted edep = %f to ADC (%x,%x,%x,%x) "
+                  "[gain: %f=(%f/%f*%f), pedestal: %d, rate: %d]", 
+                  edep, counts[0], counts[1], counts[2], counts[3], 
+                  convF, param->GetDACPerMIP(),param->GetEdepMip(),
+                  param->GetPulseGain(detector,ring,sector,strip), 
+                  ped, rate));
 }
 
 //____________________________________________________________________
 void
-AliFMDBaseDigitizer::AddDigit(UShort_t  detector, 
-                             Char_t    ring,
-                             UShort_t  sector, 
-                             UShort_t  strip, 
-                             Float_t   /* edep */, 
-                             UShort_t  count1, 
-                             Short_t   count2, 
-                             Short_t   count3,
-                             Short_t   count4) const
+AliFMDBaseDigitizer::AddDigit(UShort_t        detector, 
+                             Char_t          ring,
+                             UShort_t        sector, 
+                             UShort_t        strip, 
+                             Float_t         /* edep */, 
+                             UShort_t        count1, 
+                             Short_t         count2, 
+                             Short_t         count3,
+                             Short_t         count4,
+                             UShort_t        ntot, 
+                             UShort_t        /* nprim */,
+                             const TArrayI&  refs) const
 {
   // Add a digit or summable digit
-  
   fFMD->AddDigitByFields(detector, ring, sector, strip, 
-                        count1, count2, count3, count4);
+                        count1, count2, count3, count4, 
+                        ntot, fStoreTrackRefs ? refs.fArray : 0);
+  if (fStoreTrackRefs && ntot > 3) fIgnoredLabels += ntot - 3;
 }
 
 //____________________________________________________________________
@@ -546,7 +622,7 @@ AliFMDBaseDigitizer::MakeOutputTree(AliLoader* loader)
 
 //____________________________________________________________________
 void
-AliFMDBaseDigitizer::StoreDigits(AliLoader* loader)
+AliFMDBaseDigitizer::StoreDigits(const AliLoader* loader)
 {
   // Write the digits to disk 
   AliFMDDebug(5, ("Storing %d digits",   fFMD->Digits()->GetEntries()));