]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - EMCAL/AliEMCALRawUtils.cxx
Corrected bug, the histogram vector was not cleared properly
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALRawUtils.cxx
index 300afc9c762ac115f4e4045a2b2681ad88c41060..693821ec2dcc366c315b24af4f3a77356d134a88 100644 (file)
 
 //*-- Author: Marco van Leeuwen (LBL)
 #include "AliEMCALRawUtils.h"
-
+  
 #include "TF1.h"
 #include "TGraph.h"
 #include "TSystem.h"
-
+  
 #include "AliLog.h"
 #include "AliRun.h"
 #include "AliRunLoader.h"
 #include "AliRawReader.h"
 #include "AliCaloRawStream.h"
 #include "AliDAQ.h"
-
+  
 #include "AliEMCALRecParam.h"
 #include "AliEMCALLoader.h"
 #include "AliEMCALGeometry.h"
 #include "AliEMCALDigitizer.h"
 #include "AliEMCALDigit.h"
-
+#include "AliEMCAL.h"
+  
 ClassImp(AliEMCALRawUtils)
-
+  
 // Signal shape parameters
-Double_t AliEMCALRawUtils::fgTimeBinWidth  = 100E-9 ; // each sample is 100 ns
+ Double_t AliEMCALRawUtils::fgTimeBinWidth  = 100E-9 ; // each sample is 100 ns
 Double_t AliEMCALRawUtils::fgTimeTrigger = 1.5E-6 ;   // 15 time bins ~ 1.5 musec
 
 // some digitization constants
@@ -99,13 +100,14 @@ AliEMCALRawUtils::AliEMCALRawUtils()
   const TObjArray* maps = AliEMCALRecParam::GetMappings();
   if(!maps) AliFatal("Cannot retrieve ALTRO mappings!!");
 
-  for(Int_t i = 0; i < 2; i++) {
+  for(Int_t i = 0; i < 4; i++) {
     fMapping[i] = (AliAltroMapping*)maps->At(i);
   }
 
   //To make sure we match with the geometry in a simulation file,
   //let's try to get it first.  If not, take the default geometry
   AliRunLoader *rl = AliRunLoader::GetRunLoader();
+  if(!rl) AliError("Cannot find RunLoader!");
   if (rl->GetAliRun() && rl->GetAliRun()->GetDetector("EMCAL")) {
     fGeom = dynamic_cast<AliEMCAL*>(rl->GetAliRun()->GetDetector("EMCAL"))->GetGeometry();
   } else {
@@ -117,6 +119,38 @@ AliEMCALRawUtils::AliEMCALRawUtils()
 
 }
 
+//____________________________________________________________________________
+AliEMCALRawUtils::AliEMCALRawUtils(AliEMCALGeometry *pGeometry)
+  : fHighLowGainFactor(0.), fOrder(0), fTau(0.), fNoiseThreshold(0),
+    fNPedSamples(0), fGeom(pGeometry), fOption("")
+{
+  //
+  // Initialize with the given geometry - constructor required by HLT
+  // HLT does not use/support AliRunLoader(s) instances
+  // This is a minimum intervention solution
+  // Comment by MPloskon@lbl.gov
+  //
+
+  //These are default parameters. 
+  //Can be re-set from without with setter functions 
+  fHighLowGainFactor = 16. ;          // adjusted for a low gain range of 82 GeV (10 bits)
+  fOrder = 2;                         // order of gamma fn
+  fTau = 2.35;                        // in units of timebin, from CERN 2007 testbeam
+  fNoiseThreshold = 3;
+  fNPedSamples = 5;
+
+  //Get Mapping RCU files from the AliEMCALRecParam
+  const TObjArray* maps = AliEMCALRecParam::GetMappings();
+  if(!maps) AliFatal("Cannot retrieve ALTRO mappings!!");
+
+  for(Int_t i = 0; i < 4; i++) {
+    fMapping[i] = (AliAltroMapping*)maps->At(i);
+  }
+
+  if(!fGeom) AliFatal(Form("Could not get geometry!"));
+
+}
+
 //____________________________________________________________________________
 AliEMCALRawUtils::AliEMCALRawUtils(const AliEMCALRawUtils& rawU)
   : TObject(),
@@ -131,6 +165,8 @@ AliEMCALRawUtils::AliEMCALRawUtils(const AliEMCALRawUtils& rawU)
   //copy ctor
   fMapping[0] = rawU.fMapping[0];
   fMapping[1] = rawU.fMapping[1];
+  fMapping[2] = rawU.fMapping[2];
+  fMapping[3] = rawU.fMapping[3];
 }
 
 //____________________________________________________________________________
@@ -148,6 +184,8 @@ AliEMCALRawUtils& AliEMCALRawUtils::operator =(const AliEMCALRawUtils &rawU)
     fOption = rawU.fOption;
     fMapping[0] = rawU.fMapping[0];
     fMapping[1] = rawU.fMapping[1];
+    fMapping[2] = rawU.fMapping[2];
+    fMapping[3] = rawU.fMapping[3];
   }
 
   return *this;
@@ -201,7 +239,7 @@ void AliEMCALRawUtils::Digits2Raw()
     fGeom->GetCellIndex(digit->GetId(), nSM, nModule, nIphi, nIeta);
     fGeom->GetCellPhiEtaIndexInSModule(nSM, nModule, nIphi, nIeta,iphi, ieta) ;
     
-    //Check which is the RCU of the cell.
+    //Check which is the RCU, 0 or 1, of the cell.
     Int_t iRCU = -111;
     //RCU0
     if (0<=iphi&&iphi<8) iRCU=0; // first cable row
@@ -211,6 +249,9 @@ void AliEMCALRawUtils::Digits2Raw()
     else if(8<=iphi&&iphi<16 && 24<=ieta&&ieta<48) iRCU=1; // second half; 
     //second cable row
     else if(16<=iphi&&iphi<24) iRCU=1; // third cable row
+
+    if (nSM%2==1) iRCU = 1 - iRCU; // swap for odd=C side, to allow us to cable both sides the same
+
     if (iRCU<0) 
       Fatal("Digits2Raw()","Non-existent RCU number: %d", iRCU);
     
@@ -222,7 +263,14 @@ void AliEMCALRawUtils::Digits2Raw()
     if (buffers[iDDL] == 0) {      
       // open new file and write dummy header
       TString fileName = AliDAQ::DdlFileName("EMCAL",iDDL);
-      buffers[iDDL] = new AliAltroBuffer(fileName.Data(),fMapping[iRCU]);
+      //Select mapping file RCU0A, RCU0C, RCU1A, RCU1C
+      Int_t iRCUside=iRCU+(nSM%2)*2;
+      //iRCU=0 and even (0) SM -> RCU0A.data   0
+      //iRCU=1 and even (0) SM -> RCU1A.data   1
+      //iRCU=0 and odd  (1) SM -> RCU0C.data   2
+      //iRCU=1 and odd  (1) SM -> RCU1C.data   3
+      //cout<<" nSM "<<nSM<<"; iRCU "<<iRCU<<"; iRCUside "<<iRCUside<<endl;
+      buffers[iDDL] = new AliAltroBuffer(fileName.Data(),fMapping[iRCUside]);
       buffers[iDDL]->WriteDataHeader(kTRUE, kFALSE);  //Dummy;
     }
     
@@ -275,12 +323,6 @@ void AliEMCALRawUtils::Raw2Digits(AliRawReader* reader,TClonesArray *digitsArr)
   // Select EMCAL DDL's;
   reader->Select("EMCAL");
 
-  TString option = GetOption();
-  if (option.Contains("OldRCUFormat"))
-    in.SetOldRCUFormat(kTRUE); // Needed for testbeam data
-  else
-    in.SetOldRCUFormat(kFALSE);
-
   //Updated fitting routine from 2007 beam test takes into account
   //possibility of two peaks in data and selects first one for fitting
   //Also sets some of the starting parameters based on the shape of the
@@ -312,6 +354,7 @@ void AliEMCALRawUtils::Raw2Digits(AliRawReader* reader,TClonesArray *digitsArr)
   Int_t row = 0;
 
   while (readOk) { 
+
     id =  fGeom->GetAbsCellIdFromCellIndexes(in.GetModule(), in.GetRow(), in.GetColumn()) ;
     lowGain = in.IsLowGain();
     Int_t maxTime = in.GetTime();  // timebins come in reverse order
@@ -344,10 +387,9 @@ void AliEMCALRawUtils::Raw2Digits(AliRawReader* reader,TClonesArray *digitsArr)
 
     FitRaw(gSig, signalF, amp, time) ; 
     
-    if (amp > 0 && amp < 10000) {  //check both high and low end of
-                                  //result, 10000 is somewhat arbitrary
+    if (amp > 0 && amp < 2000) {  //check both high and low end of
+                                  //result, 2000 is somewhat arbitrary
       AliDebug(2,Form("id %d lowGain %d amp %g", id, lowGain, amp));
-      //cout << "col " << col-40 << " row " << row-8 << " lowGain " << lowGain << " amp " << amp << endl;
 
       AddDigit(digitsArr, id, lowGain, (Int_t)amp, time);
     }
@@ -439,6 +481,7 @@ void AliEMCALRawUtils::FitRaw(TGraph * gSig, TF1* signalF, Float_t & amp, Float_
   Int_t n_ped_after_sig = 0;
   Int_t plateau_width = 0;
   Int_t plateau_start = 9999;
+  Float_t Cut = 0.3;
 
   for (Int_t i=fNPedSamples; i < gSig->GetN(); i++) {
     Double_t ttime, signal;
@@ -461,6 +504,10 @@ void AliEMCALRawUtils::FitRaw(TGraph * gSig, TF1* signalF, Float_t & amp, Float_
         max_fit = tmin_after_sig;
         break;
       }
+      if ( signal < Cut*max){   //stop fit at 30% amplitude(avoid the pulse shape falling edge)
+        max_fit = i;
+        break;
+      }
       if ( signal < ped + fNoiseThreshold)
         n_ped_after_sig++;
       if (n_ped_after_sig >= 5) {  // include 5 pedestal bins after peak
@@ -476,11 +523,10 @@ void AliEMCALRawUtils::FitRaw(TGraph * gSig, TF1* signalF, Float_t & amp, Float_
   }
 
   if(plateau_width > 0) {
-    for(int j = 0; j < plateau_width-2; j++) {
+    for(int j = 0; j < plateau_width; j++) {
       //Note, have to remove the same point N times because after each
       //remove, the positions of all subsequent points have shifted down
-      //We leave the first and last as anchor points
-      gSig->RemovePoint(plateau_start+1);
+      gSig->RemovePoint(plateau_start);
     }
   }
 
@@ -549,16 +595,15 @@ const Double_t dtime, const Double_t damp, Int_t * adcH, Int_t * adcL) const
   // N:   par[3]                            
   // ped: par[4]
 
-  TF1 signalF("signal", RawResponseFunction, 0, GetRawFormatTimeMax(), 5);
+  TF1 signalF("signal", RawResponseFunction, 0, GetRawFormatTimeBins(), 5);
   signalF.SetParameter(0, damp) ; 
-  signalF.SetParameter(1, dtime + fgTimeTrigger) ; 
+  signalF.SetParameter(1, (dtime + fgTimeTrigger)/fgTimeBinWidth) ; 
   signalF.SetParameter(2, fTau) ; 
   signalF.SetParameter(3, fOrder);
   signalF.SetParameter(4, fgPedestalValue);
 
   for (Int_t iTime = 0; iTime < GetRawFormatTimeBins(); iTime++) {
-    Double_t time = iTime * GetRawFormatTimeBinWidth() ;
-    Double_t signal = signalF.Eval(time) ;     
+    Double_t signal = signalF.Eval(iTime) ;     
 
     //According to Terry Awes, 13-Apr-2008
     //add gaussian noise in quadrature to each sample