From 0be80779e96d22ecb9c1cfc7be908867b3bb3611 Mon Sep 17 00:00:00 2001
From: Ivan Sayago Galvan <isayagog@lxplus712.cern.ch>
Date: Wed, 29 May 2019 12:43:42 +0200
Subject: [PATCH] Opt2 Felix

---
 .../TileRecUtils/TileRawChannelBuilder.h         |  3 ++-
 .../TileRawChannelBuilderFitFilter.h             |  1 -
 .../TileRecUtils/src/TileRawChannelBuilder.cxx   |  3 ++-
 .../src/TileRawChannelBuilderFitFilter.cxx       |  2 ++
 .../src/TileRawChannelBuilderOpt2Filter.cxx      |  7 ++++---
 .../TileByteStream/src/TileROD_Decoder.cxx       | 16 ++++++++++------
 6 files changed, 20 insertions(+), 12 deletions(-)

diff --git a/TileCalorimeter/TileRecUtils/TileRecUtils/TileRawChannelBuilder.h b/TileCalorimeter/TileRecUtils/TileRecUtils/TileRawChannelBuilder.h
index e9986c2c9447..6e373a574ed8 100644
--- a/TileCalorimeter/TileRecUtils/TileRecUtils/TileRawChannelBuilder.h
+++ b/TileCalorimeter/TileRecUtils/TileRecUtils/TileRawChannelBuilder.h
@@ -156,7 +156,8 @@ class TileRawChannelBuilder: public AthAlgTool {
     TileFragHash::TYPE m_rChType;
     TileRawChannelUnit::UNIT m_rChUnit;
     unsigned int m_bsflags;
-
+    // parameter to determine which sample to start with
+    int m_firstSample;
     // Should energy be calibrated
     bool m_calibrateEnergy;
 
diff --git a/TileCalorimeter/TileRecUtils/TileRecUtils/TileRawChannelBuilderFitFilter.h b/TileCalorimeter/TileRecUtils/TileRecUtils/TileRawChannelBuilderFitFilter.h
index 343cb5e8967f..fbfef1a773af 100644
--- a/TileCalorimeter/TileRecUtils/TileRecUtils/TileRawChannelBuilderFitFilter.h
+++ b/TileCalorimeter/TileRecUtils/TileRecUtils/TileRawChannelBuilderFitFilter.h
@@ -91,7 +91,6 @@ class TileRawChannelBuilderFitFilter: public TileRawChannelBuilder {
     int m_maxIterate;
     int m_extraSamplesLeft;
     int m_extraSamplesRight;
-
     double m_saturatedSample; // defines the saturated sample
     double m_saturatedSampleError; // which error in terms of RMS is assigned to the saturated sample
     double m_zeroSampleError;  // which error in terms of RMS is assigned to the zero sample (== 0)
diff --git a/TileCalorimeter/TileRecUtils/src/TileRawChannelBuilder.cxx b/TileCalorimeter/TileRecUtils/src/TileRawChannelBuilder.cxx
index ed64393ac8e2..60751862223b 100644
--- a/TileCalorimeter/TileRecUtils/src/TileRawChannelBuilder.cxx
+++ b/TileCalorimeter/TileRecUtils/src/TileRawChannelBuilder.cxx
@@ -87,6 +87,7 @@ TileRawChannelBuilder::TileRawChannelBuilder(const std::string& type
   declareProperty("RunType", m_runType = 0);
   declareProperty("DataPoolSize", m_dataPoollSize = -1);
   declareProperty("UseDSPCorrection", m_useDSP = true);
+  declareProperty("FirstSample",m_firstSample = 0); 
 
 }
 
@@ -115,7 +116,7 @@ StatusCode TileRawChannelBuilder::initialize() {
   m_rawChannelCnt = nullptr;
   m_nChL = m_nChH = 0;
   m_RChSumL = m_RChSumH = 0.0;
-
+  m_evtCounter = -1; 
   // retrieve TileID helpers and TileIfno from det store
   ATH_CHECK( detStore()->retrieve(m_tileID, "TileID") );
   ATH_CHECK( detStore()->retrieve(m_tileHWID, "TileHWID") );
diff --git a/TileCalorimeter/TileRecUtils/src/TileRawChannelBuilderFitFilter.cxx b/TileCalorimeter/TileRecUtils/src/TileRawChannelBuilderFitFilter.cxx
index 0e5fa447d16a..a4b5837a4a43 100644
--- a/TileCalorimeter/TileRecUtils/src/TileRawChannelBuilderFitFilter.cxx
+++ b/TileCalorimeter/TileRecUtils/src/TileRawChannelBuilderFitFilter.cxx
@@ -337,6 +337,8 @@ void TileRawChannelBuilderFitFilter::pulseFit(const TileDigits *digit
                   << " capdaq=" << m_capdaq );
 
   std::vector<float> samples = digit->samples();
+  samples.erase(samples.begin(),samples.begin()+m_firstSample);
+  samples.resize(m_frameLength); 
   double maxsamp = 0.0;
   double minsamp = m_saturatedSample;
 
diff --git a/TileCalorimeter/TileRecUtils/src/TileRawChannelBuilderOpt2Filter.cxx b/TileCalorimeter/TileRecUtils/src/TileRawChannelBuilderOpt2Filter.cxx
index de98ea372037..0126ac85dbbb 100644
--- a/TileCalorimeter/TileRecUtils/src/TileRawChannelBuilderOpt2Filter.cxx
+++ b/TileCalorimeter/TileRecUtils/src/TileRawChannelBuilderOpt2Filter.cxx
@@ -201,6 +201,8 @@ TileRawChannel * TileRawChannelBuilderOpt2Filter::rawChannel(const TileDigits* d
   double time = 0.;
   double chi2 = 0.;
   m_digits = digits->samples();
+  m_digits.erase(m_digits.begin(),m_digits.begin()+m_firstSample);
+  m_digits.resize(m_nSamples);
   const HWIdentifier adcId = digits->adc_HWID();
   int gain = m_tileHWID->adc(adcId);
   
@@ -575,7 +577,6 @@ double TileRawChannelBuilderOpt2Filter::compute(int ros, int drawer, int channel
   amplitude = 0.;
   time = 0.;
   float ofcPhase = (float) phase;
-
   unsigned int drawerIdx = TileCalibUtils::getDrawerIdx(ros, drawer);
   TileOfcWeightsStruct weights;
   if (m_tileCondToolOfc->getOfcWeights(drawerIdx, channel, gain, ofcPhase, m_of2, weights).isFailure())
@@ -609,7 +610,7 @@ double TileRawChannelBuilderOpt2Filter::compute(int ros, int drawer, int channel
     ofc2int(digits_size, b, b_int, bscale);
     calib = ascale + slope_scale;
   }
-  
+
   ATH_MSG_VERBOSE( "OptFilterPha=" << phase );
 
   if (m_of2) {
@@ -711,7 +712,7 @@ double TileRawChannelBuilderOpt2Filter::compute(int ros, int drawer, int channel
     }
     chi2 = 0.0;
   }
-
+  std::cout << " Hemos calculado chi2" << std::endl;
   return chi2;
 }
 
diff --git a/TileCalorimeter/TileSvc/TileByteStream/src/TileROD_Decoder.cxx b/TileCalorimeter/TileSvc/TileByteStream/src/TileROD_Decoder.cxx
index 39ca1ec0eb06..6f2df10fafd1 100644
--- a/TileCalorimeter/TileSvc/TileByteStream/src/TileROD_Decoder.cxx
+++ b/TileCalorimeter/TileSvc/TileByteStream/src/TileROD_Decoder.cxx
@@ -985,6 +985,8 @@ void TileROD_Decoder::unpack_frag6(uint32_t /*version*/,
                                    DigitsMetaData_t& digitsMetaData,
                                    const uint32_t* p, pDigiVec & pDigits) const
 {
+
+
   int size = *(p) - sizeOverhead;
 
   // second word is frag ID (0x100-0x4ff) and frag type
@@ -1041,9 +1043,9 @@ void TileROD_Decoder::unpack_frag6(uint32_t /*version*/,
 
   const uint32_t* const end_data = data + size;
   while (data < end_data) {
-    if ((*data & 0x00FFFF00) == 0x00BABE00) {
-      unsigned int miniDrawer = *data & 0xFF;
-
+    if ((*data & 0xFFFF0000) == 0xABCD0000) {
+      unsigned int miniDrawer = *(data+6) & 0xFF;
+     
       if ((++data < end_data) && (*data == 0x12345678) && (++data < end_data)) {
 
         unsigned int fragSize   = *data & 0xFF;
@@ -1061,10 +1063,10 @@ void TileROD_Decoder::unpack_frag6(uint32_t /*version*/,
         // check trailer
         const uint32_t* trailer = data + paramsSize + 3 + fragSize; // 2 = (BCID + L1ID)
 
-        if ((trailer + 3) <= end_data // 3 = (trailer size)
+
+        if ((trailer + 1) <= end_data // 3 = (trailer size)
             && *trailer == 0x87654321
-            && *(++trailer) == 0xBCBCBCDC
-            && *(++trailer) == (0x00DEAD00 | (miniDrawer) | (miniDrawer << 24))) {
+            ) {
 
           if (paramsSize == 3){
             runNumber[miniDrawer]  = *(++data);
@@ -1088,6 +1090,8 @@ void TileROD_Decoder::unpack_frag6(uint32_t /*version*/,
           l1id[miniDrawer] = *(++data);
 
 
+          
+
           if (msgLvl(MSG::VERBOSE)) {
             msg(MSG::VERBOSE) << "FRAG6: Found MD[" << miniDrawer << "] fragment"
                               << ", Run type: " << runType[miniDrawer]
-- 
GitLab