]> 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 2ac0c9b7e84e076c62ca8190874853a2e6644635..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
@@ -100,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 {
@@ -142,7 +143,7 @@ AliEMCALRawUtils::AliEMCALRawUtils(AliEMCALGeometry *pGeometry)
   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);
   }
 
@@ -164,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];
 }
 
 //____________________________________________________________________________
@@ -181,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;
@@ -234,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
@@ -244,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);
     
@@ -255,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;
     }
     
@@ -339,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
@@ -371,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);
     }
@@ -466,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;
@@ -488,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
@@ -503,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);
     }
   }