]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - EMCAL/AliEMCALQADataMakerRec.cxx
OCDB calib data: removal of gain values. Will be put in a separate OCDB entry as...
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALQADataMakerRec.cxx
index 6d3b269dc81fd28f8d1d5080fdaa91a7a97929bc..0a00d6d530d3b4f6208a944854d9b1a285a55e13 100644 (file)
@@ -17,6 +17,11 @@ Based on the QA code for PHOS written by Yves Schutz July 2007
 
 Authors:  J.Klay (Cal Poly) May 2008
           S. Salur LBL April 2008
+Created one histogram for QA shifter;
+The idea:average counts for all the towers should be flat 
+Change all existing histograms as experts
+ --By Yaxian Mao 
 
 */
 
@@ -46,33 +51,76 @@ Authors:  J.Klay (Cal Poly) May 2008
 #include "AliRawReader.h"
 #include "AliCaloRawStreamV3.h"
 #include "AliEMCALGeoParams.h"
+#include "AliRawEventHeaderBase.h"
+
+#include "AliCaloBunchInfo.h"
+#include "AliCaloFitResults.h"
+#include "AliCaloRawAnalyzerFastFit.h"
+#include "AliCaloRawAnalyzerNN.h"
+#include "AliCaloRawAnalyzerLMS.h"
+#include "AliCaloRawAnalyzerPeakFinder.h"
+#include "AliCaloRawAnalyzerCrude.h"
 
 ClassImp(AliEMCALQADataMakerRec)
            
 //____________________________________________________________________________ 
-  AliEMCALQADataMakerRec::AliEMCALQADataMakerRec() : 
-    AliQADataMakerRec(AliQAv1::GetDetName(AliQAv1::kEMCAL), "EMCAL Quality Assurance Data Maker"),
-    fSuperModules(4), // FIXME!!! number of SuperModules; 4 for 2009; update default to 12 for later runs..
-    fFirstPedestalSample(0),
-    fLastPedestalSample(15),
-    fMinSignalHG(0),
-    fMaxSignalHG(AliEMCALGeoParams::fgkSampleMax)
+AliEMCALQADataMakerRec::AliEMCALQADataMakerRec(fitAlgorithm fitAlgo) : 
+  AliQADataMakerRec(AliQAv1::GetDetName(AliQAv1::kEMCAL), "EMCAL Quality Assurance Data Maker"),
+  fFittingAlgorithm(0),
+  fRawAnalyzer(0),
+  fRawAnalyzerTRU(0),
+  fSuperModules(4), // FIXME!!! number of SuperModules; 4 for 2009; update default to 12 for later runs..
+  fFirstPedestalSample(0),
+  fLastPedestalSample(3),
+  fFirstPedestalSampleTRU(0),
+  fLastPedestalSampleTRU(3),
+  fMinSignalLG(0),
+  fMaxSignalLG(AliEMCALGeoParams::fgkSampleMax),
+  fMinSignalHG(0),
+  fMaxSignalHG(AliEMCALGeoParams::fgkSampleMax),
+  fMinSignalTRU(0),
+  fMaxSignalTRU(AliEMCALGeoParams::fgkSampleMax),
+  fMinSignalLGLEDMon(0),
+  fMaxSignalLGLEDMon(AliEMCALGeoParams::fgkSampleMax),
+  fMinSignalHGLEDMon(0),
+  fMaxSignalHGLEDMon(AliEMCALGeoParams::fgkSampleMax)
 {
   // ctor
+  SetFittingAlgorithm(fitAlgo);
+  fRawAnalyzerTRU = new AliCaloRawAnalyzerLMS();
+  fRawAnalyzerTRU->SetFixTau(kTRUE); 
+  fRawAnalyzerTRU->SetTau(2.5); // default for TRU shaper
 }
 
 //____________________________________________________________________________ 
 AliEMCALQADataMakerRec::AliEMCALQADataMakerRec(const AliEMCALQADataMakerRec& qadm) :
   AliQADataMakerRec(), 
+  fFittingAlgorithm(0),
+  fRawAnalyzer(0),
+  fRawAnalyzerTRU(0),
   fSuperModules(qadm.GetSuperModules()), 
   fFirstPedestalSample(qadm.GetFirstPedestalSample()), 
   fLastPedestalSample(qadm.GetLastPedestalSample()),  
+  fFirstPedestalSampleTRU(qadm.GetFirstPedestalSampleTRU()), 
+  fLastPedestalSampleTRU(qadm.GetLastPedestalSampleTRU()),  
+  fMinSignalLG(qadm.GetMinSignalLG()),
+  fMaxSignalLG(qadm.GetMaxSignalLG()),
   fMinSignalHG(qadm.GetMinSignalHG()),
-  fMaxSignalHG(qadm.GetMaxSignalHG())
+  fMaxSignalHG(qadm.GetMaxSignalHG()),
+  fMinSignalTRU(qadm.GetMinSignalTRU()),
+  fMaxSignalTRU(qadm.GetMaxSignalTRU()),
+  fMinSignalLGLEDMon(qadm.GetMinSignalLGLEDMon()),
+  fMaxSignalLGLEDMon(qadm.GetMaxSignalLGLEDMon()),
+  fMinSignalHGLEDMon(qadm.GetMinSignalHGLEDMon()),
+  fMaxSignalHGLEDMon(qadm.GetMaxSignalHGLEDMon())
 {
   //copy ctor 
   SetName((const char*)qadm.GetName()) ; 
   SetTitle((const char*)qadm.GetTitle()); 
+  SetFittingAlgorithm(qadm.GetFittingAlgorithm());
+  fRawAnalyzerTRU = new AliCaloRawAnalyzerLMS();
+  fRawAnalyzerTRU->SetFixTau(kTRUE); 
+  fRawAnalyzerTRU->SetTau(2.5); // default for TRU shaper
 }
 
 //__________________________________________________________________
@@ -88,6 +136,10 @@ AliEMCALQADataMakerRec& AliEMCALQADataMakerRec::operator = (const AliEMCALQAData
 void AliEMCALQADataMakerRec::EndOfDetectorCycle(AliQAv1::TASKINDEX_t task, TObjArray ** list)
 {
   //Detector specific actions at end of cycle
+       
+//  if(fCycleCounter)
+//       GetRawsData(kNEventsPerTower)->Scale(1./fCycleCounter);
+
   // do the QA checking
   AliQAChecker::Instance()->Run(AliQAv1::kEMCAL, task, list) ;  
 }
@@ -99,7 +151,7 @@ void AliEMCALQADataMakerRec::InitESDs()
   const Bool_t expert   = kTRUE ; 
   const Bool_t image    = kTRUE ; 
   
-  TH1F * h1 = new TH1F("hESDCaloClusterE",  "ESDs CaloCluster energy in EMCAL;Energy [MeV];Counts",    200, 0., 20.) ; 
+  TH1F * h1 = new TH1F("hESDCaloClusterE",  "ESDs CaloCluster energy in EMCAL;Energy [GeV];Counts",    200, 0., 100.) ; 
   h1->Sumw2() ;
   Add2ESDsList(h1, kESDCaloClusE, !expert, image)  ;                                                     
 
@@ -107,7 +159,7 @@ void AliEMCALQADataMakerRec::InitESDs()
   h2->Sumw2() ;
   Add2ESDsList(h2, kESDCaloClusM, !expert, image)  ;
 
-  TH1F * h3 = new TH1F("hESDCaloCellA",  "ESDs CaloCell amplitude in EMCAL;Energy [MeV];Counts",    500, 0., 250.) ; 
+  TH1F * h3 = new TH1F("hESDCaloCellA",  "ESDs CaloCell amplitude in EMCAL;Energy [GeV];Counts",    500, 0., 50.) ; 
   h3->Sumw2() ;
   Add2ESDsList(h3, kESDCaloCellA, !expert, image)  ;  
  
@@ -139,7 +191,7 @@ void AliEMCALQADataMakerRec::InitRecPoints()
   const Bool_t expert   = kTRUE ; 
   const Bool_t image    = kTRUE ; 
   
-  TH1F* h0 = new TH1F("hEMCALRpE","EMCAL RecPoint energies;Energy [MeV];Counts",200, 0.,20.); //GeV
+  TH1F* h0 = new TH1F("hEMCALRpE","EMCAL RecPoint energies;Energy [GeV];Counts",200, 0.,20.); //GeV
   h0->Sumw2();
   Add2RecPointsList(h0,kRecPE, !expert, image);
 
@@ -167,51 +219,50 @@ void AliEMCALQADataMakerRec::InitRaws()
   // counter info: number of channels per event (bins are SM index)
   TProfile * h0 = new TProfile("hLowEmcalSupermodules", "Low Gain EMC: # of towers vs SuperMod;SM Id;# of towers",
                               fSuperModules, -0.5, fSuperModules-0.5) ;
-  Add2RawsList(h0, kNsmodLG, !expert, image, !saveCorr) ;
+  Add2RawsList(h0, kNsmodLG, expert, image, !saveCorr) ;
   TProfile * h1 = new TProfile("hHighEmcalSupermodules", "High Gain EMC: # of towers vs SuperMod;SM Id;# of towers",  
                               fSuperModules, -0.5, fSuperModules-0.5) ; 
-  Add2RawsList(h1, kNsmodHG, !expert, image, !saveCorr) ;
+  Add2RawsList(h1, kNsmodHG, expert, image, !saveCorr) ;
 
   // where did max sample occur? (bins are towers)
   TProfile * h2 = new TProfile("hLowEmcalRawtime", "Low Gain EMC: Time at Max vs towerId;Tower Id;Time [ticks]", 
                               nTot, -0.5, nTot-0.5) ;
-  Add2RawsList(h2, kTimeLG, !expert, image, !saveCorr) ;
+  Add2RawsList(h2, kTimeLG, expert, image, !saveCorr) ;
   TProfile * h3 = new TProfile("hHighEmcalRawtime", "High Gain EMC: Time at Max vs towerId;Tower Id;Time [ticks]", 
                               nTot, -0.5, nTot-0.5) ;
-  Add2RawsList(h3, kTimeHG, !expert, image, !saveCorr) ;
+  Add2RawsList(h3, kTimeHG, expert, image, !saveCorr) ;
 
   // how much above pedestal was the max sample?  (bins are towers)
   TProfile * h4 = new TProfile("hLowEmcalRawMaxMinusMin", "Low Gain EMC: Max - Min vs towerId;Tower Id;Max-Min [ADC counts]", 
                               nTot, -0.5, nTot-0.5) ;
-  Add2RawsList(h4, kSigLG, !expert, image, !saveCorr) ;
+  Add2RawsList(h4, kSigLG, expert, image, !saveCorr) ;
   TProfile * h5 = new TProfile("hHighEmcalRawMaxMinusMin", "High Gain EMC: Max - Min vs towerId;Tower Id;Max-Min [ADC counts]",
                               nTot, -0.5, nTot-0.5) ;
-  Add2RawsList(h5, kSigHG, !expert, image, !saveCorr) ;
+  Add2RawsList(h5, kSigHG, expert, image, !saveCorr) ;
 
   // total counter: channels per event
   TH1I * h6 = new TH1I("hLowNtot", "Low Gain EMC: Total Number of found towers;# of Towers;Counts", 200, 0, nTot) ;
   h6->Sumw2() ;
-  Add2RawsList(h6, kNtotLG, !expert, image, !saveCorr) ;
+  Add2RawsList(h6, kNtotLG, expert, image, !saveCorr) ;
   TH1I * h7 = new TH1I("hHighNtot", "High Gain EMC: Total Number of found towers;# of Towers;Counts", 200,0, nTot) ;
   h7->Sumw2() ;
-  Add2RawsList(h7, kNtotHG, !expert, image, !saveCorr) ;
+  Add2RawsList(h7, kNtotHG, expert, image, !saveCorr) ;
 
   // pedestal (bins are towers)
   TProfile * h8 = new TProfile("hLowEmcalRawPed", "Low Gain EMC: Pedestal vs towerId;Tower Id;Pedestal [ADC counts]", 
                               nTot, -0.5, nTot-0.5) ;
-  Add2RawsList(h8, kPedLG, !expert, image, !saveCorr) ;
+  Add2RawsList(h8, kPedLG, expert, image, !saveCorr) ;
   TProfile * h9 = new TProfile("hHighEmcalRawPed", "High Gain EMC: Pedestal vs towerId;Tower Id;Pedestal [ADC counts]",
                               nTot, -0.5, nTot-0.5) ;
-  Add2RawsList(h9, kPedHG, !expert, image, !saveCorr) ;
-
-  // pedestal rms (standard dev = sqrt of variance estimator for pedestal) (bins are towers)
-  TProfile * h10 = new TProfile("hLowEmcalRawPedRMS", "Low Gain EMC: Pedestal RMS vs towerId;Tower Id;Width [ADC counts]", 
-                               nTot, -0.5, nTot-0.5) ;
-  Add2RawsList(h10, kPedRMSLG, !expert, image, !saveCorr) ;
-  TProfile * h11 = new TProfile("hHighEmcalRawPedRMS", "High Gain EMC: Pedestal RMS vs towerId;Tower Id;Width [ADC counts]",
-                               nTot, -0.5, nTot-0.5) ;
-  Add2RawsList(h11, kPedRMSHG, !expert, image, !saveCorr) ;
-
+  Add2RawsList(h9, kPedHG, expert, image, !saveCorr) ;
+       
+ //number of events per tower, for shifter fast check          
+  TH1I * h12 = new TH1I("hTowerHG", "High Gains on the Tower;Tower", nTot,0, nTot) ;
+  h12->Sumw2() ;
+  Add2RawsList(h12, kTowerHG, !expert, image, !saveCorr) ;
+  TH1I * h13 = new TH1I("hTowerLG", "Low Gains on the Tower;Tower", nTot,0, nTot) ;
+  h13->Sumw2() ;
+  Add2RawsList(h13, kTowerLG, !expert, image, !saveCorr) ;             
 
   // now repeat the same for TRU and LEDMon data
   int nTot2x2 = fSuperModules * AliEMCALGeoParams::fgkEMCALTRUsPerSM * AliEMCALGeoParams::fgkEMCAL2x2PerTRU; // max number of TRU channels for all SuperModules
@@ -219,85 +270,81 @@ void AliEMCALQADataMakerRec::InitRaws()
   // counter info: number of channels per event (bins are SM index)
   TProfile * hT0 = new TProfile("hTRUEmcalSupermodules", "TRU EMC: # of TRU channels vs SuperMod;SM Id;# of TRU channels",
                                fSuperModules, -0.5, fSuperModules-0.5) ;
-  Add2RawsList(hT0, kNsmodTRU, !expert, image, !saveCorr) ;
+  Add2RawsList(hT0, kNsmodTRU, expert, image, !saveCorr) ;
 
   // where did max sample occur? (bins are TRU channels)
   TProfile * hT1 = new TProfile("hTRUEmcalRawtime", "TRU EMC: Time at Max vs 2x2Id;2x2 Id;Time [ticks]", 
                                nTot2x2, -0.5, nTot2x2-0.5) ;
-  Add2RawsList(hT1, kTimeTRU, !expert, image, !saveCorr) ;
+  Add2RawsList(hT1, kTimeTRU, expert, image, !saveCorr) ;
 
   // how much above pedestal was the max sample?  (bins are TRU channels)
   TProfile * hT2 = new TProfile("hTRUEmcalRawMaxMinusMin", "TRU EMC: Max - Min vs 2x2Id;2x2 Id;Max-Min [ADC counts]", 
                                nTot2x2, -0.5, nTot2x2-0.5) ;
-  Add2RawsList(hT2, kSigTRU, !expert, image, !saveCorr) ;
+  Add2RawsList(hT2, kSigTRU, expert, image, !saveCorr) ;
 
   // total counter: channels per event
   TH1I * hT3 = new TH1I("hTRUNtot", "TRU EMC: Total Number of found TRU channels;# of TRU Channels;Counts", 200, 0, nTot2x2) ;
   hT3->Sumw2() ;
-  Add2RawsList(hT3, kNtotTRU, !expert, image, !saveCorr) ;
+  Add2RawsList(hT3, kNtotTRU, expert, image, !saveCorr) ;
 
   // pedestal (bins are TRU channels)
   TProfile * hT4 = new TProfile("hTRUEmcalRawPed", "TRU EMC: Pedestal vs 2x2Id;2x2 Id;Pedestal [ADC counts]", 
                                nTot2x2, -0.5, nTot2x2-0.5) ;
-  Add2RawsList(hT4, kPedTRU, !expert, image, !saveCorr) ;
+  Add2RawsList(hT4, kPedTRU, expert, image, !saveCorr) ;
 
-  // pedestal rms (standard dev = sqrt of variance estimator for pedestal) (bins are TRU channels)
-  TProfile * hT5 = new TProfile("hTRUEmcalRawPedRMS", "TRU EMC: Pedestal RMS vs 2x2Id;2x2 Id;Width [ADC counts]", 
-                               nTot2x2, -0.5, nTot2x2-0.5) ;
-  Add2RawsList(hT5, kPedRMSTRU, !expert, image, !saveCorr) ;
+  // L0 trigger hits: # of hits (bins are TRU channels)
+  TH1I * hT5 = new TH1I("hTRUEmcalL0hits", "L0 trigger hits: Total number of 2x2 L0 generated", nTot2x2, -0.5, nTot2x2);
+  hT5->Sumw2();
+  Add2RawsList(hT5, kNL0TRU, expert, image, !saveCorr);
+
+  // L0 trigger hits: average time (bins are TRU channels)
+  TProfile * hT6 = new TProfile("hTRUEmcalL0hitsAvgTime", "L0 trigger hits: average time bin", nTot2x2, -0.5, nTot2x2); 
+  Add2RawsList(hT6, kTimeL0TRU, expert, image, !saveCorr);
 
   // and also LED Mon..
   // LEDMon has both high and low gain channels, just as regular FEE/towers
   int nTotLEDMon = fSuperModules * AliEMCALGeoParams::fgkEMCALLEDRefs; // max number of LEDMon channels for all SuperModules
 
   // counter info: number of channels per event (bins are SM index)
-  TProfile * hL0 = new TProfile("hLowLEDMONEmcalSupermodules", "LowLEDMON Gain EMC: # of strips vs SuperMod;SM Id;# of strips",
+  TProfile * hL0 = new TProfile("hLowLEDMonEmcalSupermodules", "LowLEDMon Gain EMC: # of strips vs SuperMod;SM Id;# of strips",
                               fSuperModules, -0.5, fSuperModules-0.5) ;
-  Add2RawsList(hL0, kNsmodLGLEDMon, !expert, image, !saveCorr) ;
+  Add2RawsList(hL0, kNsmodLGLEDMon, expert, image, !saveCorr) ;
   TProfile * hL1 = new TProfile("hHighLEDMonEmcalSupermodules", "HighLEDMon Gain EMC: # of strips vs SuperMod;SM Id;# of strips",  
                               fSuperModules, -0.5, fSuperModules-0.5) ; 
-  Add2RawsList(hL1, kNsmodHGLEDMon, !expert, image, !saveCorr) ;
+  Add2RawsList(hL1, kNsmodHGLEDMon, expert, image, !saveCorr) ;
 
   // where did max sample occur? (bins are strips)
-  TProfile * hL2 = new TProfile("hLowLEDMONEmcalRawtime", "LowLEDMON Gain EMC: Time at Max vs stripId;Strip Id;Time [ticks]", 
+  TProfile * hL2 = new TProfile("hLowLEDMonEmcalRawtime", "LowLEDMon Gain EMC: Time at Max vs stripId;Strip Id;Time [ticks]", 
                               nTotLEDMon, -0.5, nTotLEDMon-0.5) ;
-  Add2RawsList(hL2, kTimeLGLEDMon, !expert, image, !saveCorr) ;
+  Add2RawsList(hL2, kTimeLGLEDMon, expert, image, !saveCorr) ;
   TProfile * hL3 = new TProfile("hHighLEDMonEmcalRawtime", "HighLEDMon Gain EMC: Time at Max vs stripId;Strip Id;Time [ticks]", 
                               nTotLEDMon, -0.5, nTotLEDMon-0.5) ;
-  Add2RawsList(hL3, kTimeHGLEDMon, !expert, image, !saveCorr) ;
+  Add2RawsList(hL3, kTimeHGLEDMon, expert, image, !saveCorr) ;
 
   // how much above pedestal was the max sample?  (bins are strips)
-  TProfile * hL4 = new TProfile("hLowLEDMONEmcalRawMaxMinusMin", "LowLEDMON Gain EMC: Max - Min vs stripId;Strip Id;Max-Min [ADC counts]", 
+  TProfile * hL4 = new TProfile("hLowLEDMonEmcalRawMaxMinusMin", "LowLEDMon Gain EMC: Max - Min vs stripId;Strip Id;Max-Min [ADC counts]", 
                               nTotLEDMon, -0.5, nTotLEDMon-0.5) ;
-  Add2RawsList(hL4, kSigLGLEDMon, !expert, image, !saveCorr) ;
+  Add2RawsList(hL4, kSigLGLEDMon, expert, image, !saveCorr) ;
   TProfile * hL5 = new TProfile("hHighLEDMonEmcalRawMaxMinusMin", "HighLEDMon Gain EMC: Max - Min vs stripId;Strip Id;Max-Min [ADC counts]",
                               nTotLEDMon, -0.5, nTotLEDMon-0.5) ;
-  Add2RawsList(hL5, kSigHGLEDMon, !expert, image, !saveCorr) ;
+  Add2RawsList(hL5, kSigHGLEDMon, expert, image, !saveCorr) ;
 
   // total counter: channels per event
-  TH1I * hL6 = new TH1I("hLowLEDMONNtot", "LowLEDMON Gain EMC: Total Number of found strips;# of Strips;Counts", 200, 0, nTotLEDMon) ;
+  TH1I * hL6 = new TH1I("hLowLEDMonNtot", "LowLEDMon Gain EMC: Total Number of found strips;# of Strips;Counts", 200, 0, nTotLEDMon) ;
   hL6->Sumw2() ;
-  Add2RawsList(hL6, kNtotLGLEDMon, !expert, image, !saveCorr) ;
+  Add2RawsList(hL6, kNtotLGLEDMon, expert, image, !saveCorr) ;
   TH1I * hL7 = new TH1I("hHighLEDMonNtot", "HighLEDMon Gain EMC: Total Number of found strips;# of Strips;Counts", 200,0, nTotLEDMon) ;
   hL7->Sumw2() ;
-  Add2RawsList(hL7, kNtotHGLEDMon, !expert, image, !saveCorr) ;
+  Add2RawsList(hL7, kNtotHGLEDMon, expert, image, !saveCorr) ;
 
   // pedestal (bins are strips)
-  TProfile * hL8 = new TProfile("hLowLEDMONEmcalRawPed", "LowLEDMON Gain EMC: Pedestal vs stripId;Strip Id;Pedestal [ADC counts]", 
+  TProfile * hL8 = new TProfile("hLowLEDMonEmcalRawPed", "LowLEDMon Gain EMC: Pedestal vs stripId;Strip Id;Pedestal [ADC counts]", 
                               nTotLEDMon, -0.5, nTotLEDMon-0.5) ;
-  Add2RawsList(hL8, kPedLGLEDMon, !expert, image, !saveCorr) ;
+  Add2RawsList(hL8, kPedLGLEDMon, expert, image, !saveCorr) ;
   TProfile * hL9 = new TProfile("hHighLEDMonEmcalRawPed", "HighLEDMon Gain EMC: Pedestal vs stripId;Strip Id;Pedestal [ADC counts]",
                               nTotLEDMon, -0.5, nTotLEDMon-0.5) ;
-  Add2RawsList(hL9, kPedHGLEDMon, !expert, image, !saveCorr) ;
-
-  // pedestal rms (standard dev = sqrt of variance estimator for pedestal) (bins are strips)
-  TProfile * hL10 = new TProfile("hLowLEDMONEmcalRawPedRMS", "LowLEDMON Gain EMC: Pedestal RMS vs stripId;Strip Id;Width [ADC counts]", 
-                               nTotLEDMon, -0.5, nTotLEDMon-0.5) ;
-  Add2RawsList(hL10, kPedRMSLGLEDMon, !expert, image, !saveCorr) ;
-  TProfile * hL11 = new TProfile("hHighLEDMonEmcalRawPedRMS", "HighLEDMon Gain EMC: Pedestal RMS vs stripId;Strip Id;Width [ADC counts]",
-                               nTotLEDMon, -0.5, nTotLEDMon-0.5) ;
-  Add2RawsList(hL11, kPedRMSHGLEDMon, !expert, image, !saveCorr) ;
-  
+  Add2RawsList(hL9, kPedHGLEDMon, expert, image, !saveCorr) ;
+
 }
 
 //____________________________________________________________________________
@@ -329,33 +376,24 @@ void AliEMCALQADataMakerRec::MakeESDs(AliESDEvent * esd)
 void AliEMCALQADataMakerRec::MakeRaws(AliRawReader* rawReader)
 {
   //Fill prepared histograms with Raw digit properties
-
-  //Raw histogram filling not yet implemented
-  //
-  //Need to figure out how to get the info we want without having to
-  //actually run Raw2Digits twice.
-  //I suspect what we actually want is a raw digits method, not a true
-  //emcal raw data method, but this doesn't seem to be allowed in
-  //AliQADataMakerRec.h
-
-  // For now, to avoid redoing the expensive signal fits we just
-  // look at max vs min of the signal spextra, a la online usage in
-  // AliCaloCalibPedestal
-
+  // setup
   rawReader->Reset() ;
   AliCaloRawStreamV3 in(rawReader,"EMCAL"); 
+  rawReader->Select("EMCAL", 0, AliEMCALGeoParams::fgkLastAltroDDL) ; //select EMCAL DDL's 
+
+  AliRecoParam::EventSpecie_t saveSpecie = fEventSpecie ;
+
+  if (rawReader->GetType() == AliRawEventHeaderBase::kCalibrationEvent) { 
+    SetEventSpecie(AliRecoParam::kCalib) ;
+  }
+  
+  fRawAnalyzer->SetIsZeroSuppressed(true); // TMP - should use stream->IsZeroSuppressed(), or altro cfg registers later
 
-  // setup
   int nTowersPerSM = AliEMCALGeoParams::fgkEMCALRows * AliEMCALGeoParams::fgkEMCALCols; // number of towers in a SuperModule; 24x48
   int nRows = AliEMCALGeoParams::fgkEMCALRows; // number of rows per SuperModule
   int nStripsPerSM = AliEMCALGeoParams::fgkEMCALLEDRefs; // number of strips per SuperModule
   int n2x2PerSM = AliEMCALGeoParams::fgkEMCALTRUsPerSM * AliEMCALGeoParams::fgkEMCAL2x2PerTRU; // number of TRU 2x2's per SuperModule
-
-  int sampleMin = 0; 
-  int sampleMax = AliEMCALGeoParams::fgkSampleMax; // 0x3ff = 1023 = 10-bit range
-
-  // for the pedestal calculation
-  Bool_t selectPedestalSamples = kTRUE;
+  int n2x2PerTRU = AliEMCALGeoParams::fgkEMCAL2x2PerTRU;
 
   // SM counters; decl. should be safe, assuming we don't get more than expected SuperModules..
   int nTotalSMLG[AliEMCALGeoParams::fgkEMCALModules] = {0};
@@ -364,151 +402,186 @@ void AliEMCALQADataMakerRec::MakeRaws(AliRawReader* rawReader)
   int nTotalSMLGLEDMon[AliEMCALGeoParams::fgkEMCALModules] = {0};
   int nTotalSMHGLEDMon[AliEMCALGeoParams::fgkEMCALModules] = {0};
 
-  // indices for the reading
-  int iSM = 0;
-  int sample = 0;
-  int time = 0;
-  // counters, on sample level
-  int i = 0; // the sample number in current event.
-  int maxTime = 0;
-  int startBin = 0;
-
-  // calc. quantities
-  double meanPed = 0, squaredMean = 0, rmsPed = 0;
+  int nTRUL0ChannelBits = 10; // used for L0 trigger bits checks
 
   // start loop over input stream  
+  int iSM = 0;
   while (in.NextDDL()) {
     int iRCU = in.GetDDLNumber() % 2; // RCU0 or RCU1, within SuperModule
-    while (in.NextChannel()) {
-
-      // counters
-      int max = sampleMin, min = sampleMax; // min and max sample values
-      
-      // for the pedestal calculation
-      int sampleSum = 0; // sum of samples
-      int squaredSampleSum = 0; // sum of samples squared
-      int nSum = 0; // number of samples in sum
-      
-      while (in.NextBunch()) {
-       const UShort_t *sig = in.GetSignals();
-       startBin = in.GetStartTimeBin();
-       for (i = 0; i < in.GetBunchLength(); i++) {
-         sample = sig[i];
-         time = startBin--;
-
-         // check if it's a min or max value
-         if (sample < min) min = sample;
-         if (sample > max) {
-           max = sample;
-           maxTime = time;
-         }
 
-         // should we add it for the pedestal calculation?
-         if ( (fFirstPedestalSample<=time && time<=fLastPedestalSample) || // sample time in range
-              !selectPedestalSamples ) { // or we don't restrict the sample range.. - then we'll take all 
-           sampleSum += sample;
-           squaredSampleSum += sample*sample;
-           nSum++;
+    while (in.NextChannel()) {
+      iSM = in.GetModule(); // SuperModule
+      //printf("iSM %d DDL %d", iSM, in.GetDDLNumber()); 
+      if (iSM>=0 && iSM<fSuperModules) { // valid module reading
+
+       int nsamples = 0;
+       vector<AliCaloBunchInfo> bunchlist; 
+       while (in.NextBunch()) {
+         nsamples += in.GetBunchLength();
+         bunchlist.push_back( AliCaloBunchInfo(in.GetStartTimeBin(), in.GetBunchLength(), in.GetSignals() ) );
+       } 
+       
+       if (nsamples > 0) { // this check is needed for when we have zero-supp. on, but not sparse readout
+         Float_t time = 0; 
+         Float_t amp = 0; 
+         // indices for pedestal calc.
+         int firstPedSample = 0;
+         int lastPedSample = 0;
+         bool isTRUL0IdData = false;
+
+         if (! in.IsTRUData() ) { // high gain, low gain, LED Mon data - all have the same shaper/sampling 
+           AliCaloFitResults fitResults = fRawAnalyzer->Evaluate( bunchlist, in.GetAltroCFG1(), in.GetAltroCFG2()); 
+           amp = fitResults.GetAmp();
+           time = fitResults.GetTof(); 
+           firstPedSample = fFirstPedestalSample;
+           lastPedSample = fLastPedestalSample;
          }
-         
-       } // loop over samples in bunch
-      } // loop over bunches
-
-      // calculate pedesstal estimate: mean of possibly selected samples
-      if (nSum > 0) {
-       meanPed = sampleSum / (1.0 * nSum);
-       squaredMean = squaredSampleSum / (1.0 * nSum);
-       // The variance (rms squared) is equal to the mean of the squares minus the square of the mean..
-       rmsPed = sqrt(squaredMean - meanPed*meanPed); 
-      }
-      else {
-       meanPed = 0;
-       squaredMean = 0;
-       rmsPed  = 0;
-      }
-
-      // it should be enough to check the SuperModule info for each DDL really, but let's keep it here for now
-      iSM = in.GetModule(); //The modules are numbered starting from 0
-
-      if (iSM>=0 && iSM<fSuperModules) { // valid module reading, can go on with filling
-
-       if ( in.IsLowGain() || in.IsHighGain() ) { // regular towers
-         int towerId = iSM*nTowersPerSM + in.GetColumn()*nRows + in.GetRow();
-
-         if ( in.IsLowGain() ) { 
-           //fill the low gain histograms, and counters
-           nTotalSMLG[iSM]++; // one more channel found
-           GetRawsData(kSigLG)->Fill(towerId, max - min);
-           GetRawsData(kTimeLG)->Fill(towerId, maxTime);
-           if (nSum>0) { // only fill pedestal info in case it could be calculated
-             GetRawsData(kPedLG)->Fill(towerId, meanPed);
-             GetRawsData(kPedRMSLG)->Fill(towerId, rmsPed);
+         else { // TRU data is special, needs its own analyzer
+           AliCaloFitResults fitResults = fRawAnalyzerTRU->Evaluate( bunchlist, in.GetAltroCFG1(), in.GetAltroCFG2()); 
+           amp = fitResults.GetAmp();
+           time = fitResults.GetTof(); 
+           firstPedSample = fFirstPedestalSampleTRU;
+           lastPedSample = fLastPedestalSampleTRU;
+           if (in.GetColumn() > n2x2PerTRU) {
+             isTRUL0IdData = true;
            }
-         } // gain==0
-         else if ( in.IsHighGain() ) {         
-           //fill the high gain ones
-           nTotalSMHG[iSM]++; // one more channel found
-           int signal = max - min;
-           // only fill the max-min signal info and maxTime, if the
-           // signal was in the selected range 
-           if ( (signal > fMinSignalHG) && (signal < fMaxSignalHG) ) { 
-             GetRawsData(kSigHG)->Fill(towerId, signal);
-             GetRawsData(kTimeHG)->Fill(towerId, maxTime);
-           } // signal
-           if (nSum>0) { // only fill pedestal info in case it could be calculated
-             GetRawsData(kPedHG)->Fill(towerId, meanPed);
-             GetRawsData(kPedRMSHG)->Fill(towerId, rmsPed);
+         }
+  
+         // pedestal samples
+         int nPed = 0;
+         vector<int> pedSamples; 
+       
+         // select earliest bunch 
+         unsigned int bunchIndex = 0;
+         unsigned int startBin = bunchlist.at(0).GetStartBin();
+         if (bunchlist.size() > 0) {
+           for(unsigned int ui=1; ui < bunchlist.size(); ui++ ) {
+             if (startBin > bunchlist.at(ui).GetStartBin() ) {
+               startBin = bunchlist.at(ui).GetStartBin();
+               bunchIndex = ui;
+             }
            }
          }
-       } // low or high gain
-       // TRU
-       else if ( in.IsTRUData() ) {
-         // for TRU data, the mapping class holds the TRU internal 2x2 number (0..95) in the Column var..
-         int iTRU = iRCU; //TRU0 is from RCU0, TRU1 from RCU1
-         if (iRCU>0 && in.GetBranch()>0) iTRU=2; // TRU2 is from branch B on RCU1
-         int TRU2x2Id = iSM*n2x2PerSM + iTRU*AliEMCALGeoParams::fgkEMCAL2x2PerTRU 
-           + in.GetColumn();
-         
-         //fill the low gain histograms, and counters
-         nTotalSMTRU[iSM]++; // one more channel found
-         GetRawsData(kSigTRU)->Fill(TRU2x2Id, max - min);
-         GetRawsData(kTimeTRU)->Fill(TRU2x2Id, maxTime);
-         if (nSum>0) { // only fill pedestal info in case it could be calculated
-           GetRawsData(kPedTRU)->Fill(TRU2x2Id, meanPed);
-           GetRawsData(kPedRMSTRU)->Fill(TRU2x2Id, rmsPed);
+
+         // check bunch for entries in the pedestal sample range
+         int bunchLength = bunchlist.at(bunchIndex).GetLength(); 
+         const UShort_t *sig = bunchlist.at(bunchIndex).GetData();
+         int timebin = 0;
+
+         if (! isTRUL0IdData) { // regular data, can look at pedestals
+           for (int i = 0; i<bunchLength; i++) {
+             timebin = startBin--;
+             if ( firstPedSample<=timebin && timebin<=lastPedSample ) {
+               pedSamples.push_back( sig[i] );
+               nPed++;
+             }     
+           } // i
+         //      printf("nPed %d\n", nPed);
          }
-       }
-       // LED Mon
-       else if ( in.IsLEDMonData() ) {
-         // for LED Mon data, the mapping class holds the gain info in the Row variable
-         // and the Strip number in the Column..
-         int gain = in.GetRow(); 
-         int stripId = iSM*nStripsPerSM + in.GetColumn();
-         
-         if ( gain == 0 ) { 
-           //fill the low gain histograms, and counters
-           nTotalSMLGLEDMon[iSM]++; // one more channel found
-           GetRawsData(kSigLGLEDMon)->Fill(stripId, max - min);
-           GetRawsData(kTimeLGLEDMon)->Fill(stripId, maxTime);
-           if (nSum>0) { // only fill pedestal info in case it could be calculated
-             GetRawsData(kPedLGLEDMon)->Fill(stripId, meanPed);
-             GetRawsData(kPedRMSLGLEDMon)->Fill(stripId, rmsPed);
+         else { // TRU L0 Id Data
+           // which TRU the channel belongs to?
+           int TRUId = in.GetModule()*3 + (iRCU*in.GetBranch() + iRCU);
+
+           for (int i = 0; i< bunchLength; i++) {
+             for( int j = 0; j < nTRUL0ChannelBits; j++ ){
+               // check if the bit j is 1
+               if( (sig[i] & ( 1 << j )) > 0 ){
+                 int TRUIdInSM = (in.GetColumn() - n2x2PerTRU)*nTRUL0ChannelBits+j;
+                 if(TRUIdInSM < n2x2PerTRU) {
+                   int TRUAbsId = TRUIdInSM + n2x2PerTRU * TRUId;
+                   // Fill the histograms
+                   GetRawsData(kNL0TRU)->Fill(TRUAbsId);
+                   GetRawsData(kTimeL0TRU)->Fill(TRUAbsId, startBin);
+                 }
+               }
+             }
+             startBin--;
+           } // i      
+         } // TRU L0 Id data                   
+
+         // fill histograms
+         if ( in.IsLowGain() || in.IsHighGain() ) { // regular towers
+           int towerId = iSM*nTowersPerSM + in.GetColumn()*nRows + in.GetRow();
+           if ( in.IsLowGain() ) { 
+             nTotalSMLG[iSM]++; 
+             GetRawsData(kTowerLG)->Fill(towerId);
+             if ( (amp > fMinSignalLG) && (amp < fMaxSignalLG) ) { 
+               GetRawsData(kSigLG)->Fill(towerId, amp);
+               GetRawsData(kTimeLG)->Fill(towerId, time);
+             }
+             if (nPed > 0) {
+               for (int i=0; i<nPed; i++) {
+                 GetRawsData(kPedLG)->Fill(towerId, pedSamples[i]);
+               }
+             }
+           } // gain==0
+           else if ( in.IsHighGain() ) {               
+             nTotalSMHG[iSM]++; 
+             GetRawsData(kTowerHG)->Fill(towerId);
+             if ( (amp > fMinSignalHG) && (amp < fMaxSignalHG) ) { 
+               GetRawsData(kSigHG)->Fill(towerId, amp);
+               GetRawsData(kTimeHG)->Fill(towerId, time);
+             } 
+             if (nPed > 0) {
+               for (int i=0; i<nPed; i++) {
+                 GetRawsData(kPedHG)->Fill(towerId, pedSamples[i]);
+               }
+             }
+           } // gain==1
+         } // low or high gain
+         // TRU
+         else if ( in.IsTRUData() && in.GetColumn()<AliEMCALGeoParams::fgkEMCAL2x2PerTRU) {
+           // for TRU data, the mapping class holds the TRU internal 2x2 number (0..95) in the Column var..
+           int iTRU = (iRCU*in.GetBranch() + iRCU); //TRU0 is from RCU0, TRU1 from RCU1, TRU2 is from branch B on RCU1
+           int iTRU2x2Id = iSM*n2x2PerSM + iTRU*AliEMCALGeoParams::fgkEMCAL2x2PerTRU 
+             + in.GetColumn();
+           nTotalSMTRU[iSM]++; 
+           if ( (amp > fMinSignalTRU) && (amp < fMaxSignalTRU) ) { 
+             GetRawsData(kSigTRU)->Fill(iTRU2x2Id, amp);
+             GetRawsData(kTimeTRU)->Fill(iTRU2x2Id, time);
            }
-         } // gain==0
-         else if ( gain == 1 ) {               
-           //fill the high gain ones
-           nTotalSMHGLEDMon[iSM]++; // one more channel found
-           GetRawsData(kSigHGLEDMon)->Fill(stripId, max - min);
-           GetRawsData(kTimeHGLEDMon)->Fill(stripId, maxTime);
-           if (nSum>0) { // only fill pedestal info in case it could be calculated
-             GetRawsData(kPedHGLEDMon)->Fill(stripId, meanPed);
-             GetRawsData(kPedRMSHGLEDMon)->Fill(stripId, rmsPed);
+           if (nPed > 0) {
+             for (int i=0; i<nPed; i++) {
+               GetRawsData(kPedTRU)->Fill(iTRU2x2Id, pedSamples[i]);
+             }
            }
-         } // low or high gain
-       } // LEDMon
-
-      } // SM index OK
-
+         }
+         // LED Mon
+         else if ( in.IsLEDMonData() ) {
+           // for LED Mon data, the mapping class holds the gain info in the Row variable
+           // and the Strip number in the Column..
+           int gain = in.GetRow(); 
+           int stripId = iSM*nStripsPerSM + in.GetColumn();
+         
+           if ( gain == 0 ) { 
+             nTotalSMLGLEDMon[iSM]++; 
+             if ( (amp > fMinSignalLGLEDMon) && (amp < fMaxSignalLGLEDMon) ) { 
+               GetRawsData(kSigLGLEDMon)->Fill(stripId, amp);
+               GetRawsData(kTimeLGLEDMon)->Fill(stripId, time);
+             }
+             if (nPed > 0) {
+               for (int i=0; i<nPed; i++) {
+                 GetRawsData(kPedLGLEDMon)->Fill(stripId, pedSamples[i]);
+               }
+             }
+           } // gain==0
+           else if ( gain == 1 ) {             
+             nTotalSMHGLEDMon[iSM]++; 
+             if ( (amp > fMinSignalHGLEDMon) && (amp < fMaxSignalHGLEDMon) ) { 
+               GetRawsData(kSigHGLEDMon)->Fill(stripId, amp);
+               GetRawsData(kTimeHGLEDMon)->Fill(stripId, time);
+             }
+             if (nPed > 0) {
+               for (int i=0; i<nPed; i++) {
+                 GetRawsData(kPedHGLEDMon)->Fill(stripId, pedSamples[i]);
+               }
+             }
+           } // low or high gain
+         } // LEDMon
+
+       } // SM index OK
+
+      } // nsamples>0 check, some data found for this channel; not only trailer/header
     }// end while over channel 
    
   }//end while over DDL's, of input stream 
@@ -523,20 +596,23 @@ void AliEMCALQADataMakerRec::MakeRaws(AliRawReader* rawReader)
     nTotalLG += nTotalSMLG[iSM]; 
     nTotalHG += nTotalSMHG[iSM]; 
     nTotalTRU += nTotalSMTRU[iSM]; 
-    nTotalLG += nTotalSMLGLEDMon[iSM]; 
-    nTotalHG += nTotalSMHGLEDMon[iSM]; 
+    nTotalLGLEDMon += nTotalSMLGLEDMon[iSM]; 
+    nTotalHGLEDMon += nTotalSMHGLEDMon[iSM]; 
     GetRawsData(kNsmodLG)->Fill(iSM, nTotalSMLG[iSM]); 
     GetRawsData(kNsmodHG)->Fill(iSM, nTotalSMHG[iSM]); 
     GetRawsData(kNsmodTRU)->Fill(iSM, nTotalSMTRU[iSM]); 
     GetRawsData(kNsmodLGLEDMon)->Fill(iSM, nTotalSMLGLEDMon[iSM]); 
     GetRawsData(kNsmodHGLEDMon)->Fill(iSM, nTotalSMHGLEDMon[iSM]); 
   }
+  
   GetRawsData(kNtotLG)->Fill(nTotalLG);
   GetRawsData(kNtotHG)->Fill(nTotalHG);
   GetRawsData(kNtotTRU)->Fill(nTotalTRU);
   GetRawsData(kNtotLGLEDMon)->Fill(nTotalLGLEDMon);
   GetRawsData(kNtotHGLEDMon)->Fill(nTotalHGLEDMon);
 
+  SetEventSpecie(saveSpecie) ; 
   // just in case the next rawreader consumer forgets to reset; let's do it here again..
   rawReader->Reset() ;
 
@@ -610,3 +686,44 @@ void AliEMCALQADataMakerRec::StartOfDetectorCycle()
   
 }
 
+//____________________________________________________________________________ 
+void AliEMCALQADataMakerRec::SetFittingAlgorithm(Int_t fitAlgo)              
+{
+  //Set fitting algorithm and initialize it if this same algorithm was not set before.
+  //printf("**** Set Algorithm , number %d ****\n",fitAlgo);
+  
+  if(fitAlgo == fFittingAlgorithm && fRawAnalyzer) {
+    //Do nothing, this same algorithm already set before.
+    //printf("**** Algorithm already set before, number %d, %s ****\n",fitAlgo, fRawAnalyzer->GetName());
+    return;
+  }
+  //Initialize the requested algorithm
+  if(fitAlgo != fFittingAlgorithm || !fRawAnalyzer) {
+    //printf("**** Init Algorithm , number %d ****\n",fitAlgo);
+               
+    fFittingAlgorithm = fitAlgo; 
+    if (fRawAnalyzer) delete fRawAnalyzer;  // delete prev. analyzer if existed.
+               
+    if (fitAlgo == kFastFit) {
+      fRawAnalyzer = new AliCaloRawAnalyzerFastFit();
+    }
+    else if (fitAlgo == kNeuralNet) {
+      fRawAnalyzer = new AliCaloRawAnalyzerNN();
+    }
+    else if (fitAlgo == kLMS) {
+      fRawAnalyzer = new AliCaloRawAnalyzerLMS();
+    }
+    else if (fitAlgo == kPeakFinder) {
+      fRawAnalyzer = new AliCaloRawAnalyzerPeakFinder();
+    }
+    else if (fitAlgo == kCrude) {
+      fRawAnalyzer = new AliCaloRawAnalyzerCrude();
+    }
+    else {
+      AliWarning("EMCAL QA invalid fit algorithm choice") ; 
+    }
+
+  }
+  return;
+}
+