AliRoot Core  edcc906 (edcc906)
AliEMCALRawUtils.cxx
Go to the documentation of this file.
1 // -*- mode: c++ -*-
2 /**************************************************************************
3  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4  * *
5  * Author: The ALICE Off-line Project. *
6  * Contributors are mentioned in the code where appropriate. *
7  * *
8  * Permission to use, copy, modify and distribute this software and its *
9  * documentation strictly for non-commercial purposes is hereby granted *
10  * without fee, provided that the above copyright notice appears in all *
11  * copies and that both the copyright notice and this permission notice *
12  * appear in the supporting documentation. The authors make no claims *
13  * about the suitability of this software for any purpose. It is *
14  * provided "as is" without express or implied warranty. *
15  **************************************************************************/
16 
17 //#include "AliCDBManager.h"
18 #include "AliEMCALRawUtils.h"
19 #include "AliRun.h"
20 #include "AliRunLoader.h"
21 #include "AliAltroBuffer.h"
22 #include "AliRawReader.h"
23 #include "AliCaloRawStreamV3.h"
24 #include "AliDAQ.h"
25 #include "AliEMCALRecParam.h"
26 #include "AliEMCALLoader.h"
27 #include "AliEMCALGeometry.h"
28 #include "AliEMCALDigit.h"
29 #include "AliEMCALRawDigit.h"
30 #include "AliEMCAL.h"
31 #include "AliCaloCalibPedestal.h"
32 #include "AliCaloBunchInfo.h"
33 #include "AliCaloFitResults.h"
36 #include "AliEMCALTriggerData.h"
37 #include "AliCaloConstants.h"
38 #include "AliCaloRawAnalyzer.h"
40 #include "AliEMCALRawResponse.h"
41 
42 using namespace CALO;
43 using namespace EMCAL;
44 
45 using std::vector;
46 
48 ClassImp(AliEMCALRawUtils) ;
50 
56  fNPedSamples(4),
57  fGeom(0),
58  fOption(""),
59  fRemoveBadChannels(kFALSE),
60  fFittingAlgorithm(fitAlgo),
61  fTimeMin(-1.),
62  fTimeMax(1.),
63  fUseFALTRO(kTRUE),
64  fUseL1Phase(kTRUE),
65  fRawAnalyzer(0),
66  fTriggerRawDigitMaker(0x0)
67 {
68  SetFittingAlgorithm(fitAlgo);
69 
71 
72  if(!maps) AliFatal("Cannot retrieve ALTRO mappings!!");
73 
74  for(Int_t i = 0; i < 4; i++)
75  {
76  fMapping[i] = (AliAltroMapping*)maps->At(i);
77  }
78 
80  if (rl && rl->GetAliRun())
81  {
82  AliEMCAL * emcal = dynamic_cast<AliEMCAL*>(rl->GetAliRun()->GetDetector("EMCAL"));
83  if(emcal)
84  {
85  fGeom = emcal->GetGeometry();
86  }
87  else
88  {
89  AliDebug(1, Form("Using default geometry in raw reco"));
91  }
92  }
93  else
94  {
95  AliDebug(1, Form("Using default geometry in raw reco"));
97  }
98 
99  if(!fGeom) AliFatal(Form("Could not get geometry!"));
101 }
102 
107 {
108  delete fRawAnalyzer;
109  delete fTriggerRawDigitMaker;
110 }
111 
116 {
118 
119  AliEMCALLoader *loader = dynamic_cast<AliEMCALLoader*>(rl->GetDetectorLoader("EMCAL"));
120  loader->LoadDigits("EMCAL");
121  loader->GetEvent();
122 
123  TClonesArray* digits = loader->Digits() ;
124 
125  if (!digits)
126  {
127  AliWarning("No digits found !");
128  return;
129  }
130 
131  static const Int_t nDDL = 20*2; // 20 SM for EMCal + DCal hardcoded for now. Buffers allocated dynamically, when needed, so just need an upper limit here
132 
133  AliAltroBuffer* buffers[nDDL];
134  for (Int_t i=0; i < nDDL; i++)
135  buffers[i] = 0;
136 
137  TArrayI adcValuesLow ( TIMEBINS );
138  TArrayI adcValuesHigh( TIMEBINS );
139 
140  // Loop over digits (assume ordered digits)
141  for (Int_t iDigit = 0; iDigit < digits->GetEntries(); iDigit++)
142  {
143  AliEMCALDigit* digit = dynamic_cast<AliEMCALDigit *>(digits->At(iDigit)) ;
144 
145  if(!digit)
146  {
147  AliFatal("NULL Digit");
148  }
149  else
150  {
152  {
153  continue;
154  }
155 
156  // Get cell indices
157  Int_t nSM = 0;
158  Int_t nIphi = 0;
159  Int_t nIeta = 0;
160  Int_t iphi = 0;
161  Int_t ieta = 0;
162  Int_t nModule = 0;
163 
164  fGeom->GetCellIndex(digit->GetId(), nSM, nModule, nIphi, nIeta);
165  fGeom->GetCellPhiEtaIndexInSModule(nSM, nModule, nIphi, nIeta,iphi, ieta) ;
166 
167  //----------------------------------------------------------------------
168  //
169  // Online mapping and numbering is the same for EMCal and DCal SMs but:
170  // - DCal odd SM (13,15,17) has online cols: 16-47; offline cols 0-31.
171  // - Even DCal SMs have the same numbering online and offline 0-31.
172  // - DCal 1/3 SM (18,19), online rows 16-23; offline rows 0-7
173  //
174  // In the next lines shift the online cols or rows depending on the
175  // SM to match the offline mapping.
176  // Apply the shifts (inverse to those in Raw2Digits):
177 
178  fGeom->ShiftOfflineToOnlineCellIndexes(nSM, iphi, ieta);
179 
180  //
181  //----------------------------------------------------------------------
182 
183  // Check which is the RCU, 0 or 1, of the cell.
184  // *** RCU corresponds to DDL in a SuperModule ***
185  Int_t iRCU = -111;
186  if ( 0<=iphi&&iphi< 8 ) iRCU=0; // first cable row
187  else if ( 8<=iphi&&iphi<16 && 0<=ieta&&ieta<24 ) iRCU=0; // first half;
188  else if ( 8<=iphi&&iphi<16 && 24<=ieta&&ieta<48 ) iRCU=1; // second half;
189  else if ( 16<=iphi&&iphi<24 ) iRCU=1; // third cable row
190 
191  if (nSM%2==1) iRCU = 1 - iRCU; // swap for odd=C side, to allow us to cable both sides the same
192 
193  if (iRCU<0)
194  Fatal("Digits2Raw()","Non-existent RCU/DDL number: %d", iRCU);
195 
196  // Which DDL?
197  Int_t iDDL = NRCUSPERMODULE*nSM + iRCU;
198 
199  if (iDDL < 0 || iDDL >= nDDL)
200  {
201  Fatal("Digits2Raw()","Non-existent DDL board number: %d", iDDL);
202  }
203  else
204  {
205  if (buffers[iDDL] == 0)
206  {
207  // open new file and write dummy header
208  TString fileName = AliDAQ::DdlFileName("EMCAL",iDDL);
209  //Select mapping file RCU0A, RCU0C, RCU1A, RCU1C
210  Int_t iRCUside=iRCU+(nSM%2)*2;
211  //iRCU=0 and even (0) SM -> RCU0A.data 0
212  //iRCU=1 and even (0) SM -> RCU1A.data 1
213  //iRCU=0 and odd (1) SM -> RCU0C.data 2
214  //iRCU=1 and odd (1) SM -> RCU1C.data 3
215  buffers[iDDL] = new AliAltroBuffer(fileName.Data(),fMapping[iRCUside]);
216  buffers[iDDL]->WriteDataHeader(kTRUE, kFALSE); //Dummy;
217  }
218 
219  // out of time range signal (?)
220  if ( digit->GetTime() > TIMEBINMAX )
221  {
222  AliInfo("Signal is out of time range.\n");
223  buffers[iDDL]->FillBuffer((Int_t)digit->GetAmplitude());
224  buffers[iDDL]->FillBuffer( TIMEBINS ); // time bin
225  buffers[iDDL]->FillBuffer(3); // bunch length
226  buffers[iDDL]->WriteTrailer(3, ieta, iphi, nSM); // trailer
227  // calculate the time response function
228  }
229  else
230  {
231  Bool_t lowgain = AliEMCALRawResponse::RawSampledResponse(digit->GetTime(), digit->GetAmplitude(),
232  adcValuesHigh.GetArray(), adcValuesLow.GetArray()) ;
233 
234  buffers[iDDL]->WriteChannel(ieta, iphi, 1, TIMEBINS, adcValuesHigh.GetArray(), AliEMCALRawResponse::GetRawFormatThreshold() );
235 
236  if (lowgain)
237  buffers[iDDL]->WriteChannel(ieta, iphi, 0, TIMEBINS, adcValuesLow .GetArray(), AliEMCALRawResponse::GetRawFormatThreshold() );
238 
239  }
240  }// iDDL under the limits
241  }// Digit exists
242  }// Digit loop
243 
244  // Write headers and close files
245  for (Int_t i=0; i < nDDL; i++)
246  {
247  if (buffers[i])
248  {
249  buffers[i]->Flush();
250  buffers[i]->WriteDataHeader(kFALSE, kFALSE);
251  delete buffers[i];
252  }
253  }
254 
255  loader->UnloadDigits();
256 }
257 
261 void AliEMCALRawUtils::AddDigit(TClonesArray *digitsArr, Int_t id, Int_t lowGain,
262  Float_t amp, Float_t time, Float_t chi2, Int_t ndf)
263 {
264  AliEMCALDigit *digit = 0, *tmpdigit = 0;
265  TIter nextdigit(digitsArr);
266 
267  while (digit == 0 && (tmpdigit = (AliEMCALDigit*) nextdigit()))
268  {
269  if (tmpdigit->GetId() == id) digit = tmpdigit;
270  }
271 
272  // No digit existed for this tower; create one.
273  if (!digit)
274  {
275  Int_t type = AliEMCALDigit::kHG; // use enum in AliEMCALDigit
276 
277  if (lowGain)
278  {
279  amp *= HGLGFACTOR;
280  type = AliEMCALDigit::kLGnoHG;
281  }
282 
283  Int_t idigit = digitsArr->GetEntries();
284 
285  new((*digitsArr)[idigit]) AliEMCALDigit( -1, -1, id, amp, time, type, idigit, chi2, ndf);
286 
287  AliDebug(2,Form("Add digit Id %d for the first time, type %d", id, type));
288  }// digit added first time.
289 
290  // A digit already exists, check range
291  // (use high gain if signal < cut value, otherwise low gain)
292  else
293  {
294  if (lowGain)
295  {
296  // New digit is low gain
297  if ( digit->GetAmplitude() > OVERFLOWCUT )
298  {
299  // Use if previously stored (HG) digit is out of range
300  digit->SetAmplitude( HGLGFACTOR * amp);
301  digit->SetTime(time);
302  digit->SetType(AliEMCALDigit::kLG);
303 
304  AliDebug(2,Form("Add LG digit ID %d for the second time, type %d", digit->GetId(), digit->GetType()));
305  }
306  } // New low gain digit
307  else
308  {
309  // New digit is high gain
310  if ( amp < OVERFLOWCUT )
311  {
312  // New digit is high gain; use if not out of range
313  digit->SetAmplitude(amp);
314  digit->SetTime(time);
315  digit->SetType(AliEMCALDigit::kHG);
316 
317  AliDebug(2,Form("Add HG digit ID %d for the second time, type %d", digit->GetId(), digit->GetType()));
318  }
319  else
320  {
321  // HG out of range, just change flag value to show that HG did exist
322  digit->SetType(AliEMCALDigit::kLG);
323 
324  AliDebug(2,Form("Change LG digit to HG, ID %d, type %d", digit->GetId(), digit->GetType()));
325  }
326  } // New high gain digit
327  }// Digit existed replace it
328 }
329 
333 void AliEMCALRawUtils::Raw2Digits(AliRawReader* reader,TClonesArray *digitsArr, const AliCaloCalibPedestal* pedbadmap,
334  TClonesArray *digitsTRG, TClonesArray *trgData)
335 {
336  if ( digitsArr) digitsArr->Clear("C");
337 
338  if (!digitsArr) { Error("Raw2Digits", "no digits found !") ; return ; }
339 
340  if (!reader) { Error("Raw2Digits", "no raw reader found !"); return ; }
341 
342  AliEMCALTriggerSTURawStream inSTU(reader);
343 
344  AliCaloRawStreamV3 in(reader,"EMCAL",fMapping);
345 
346  reader->Select("EMCAL",0,AliDAQ::GetFirstSTUDDL()-1);
347 
349  fTriggerRawDigitMaker->SetIO(reader, in, inSTU, digitsTRG, trgData);
350 
351  fRawAnalyzer->SetIsZeroSuppressed(true); // TMP - should use stream->IsZeroSuppressed(), or altro cfg registers later
352 
353  Int_t lowGain = 0;
354  Int_t caloFlag = 0; // low, high gain, or TRU, or LED ref.
355 
356  Float_t bcTimePhaseCorr = 0; // for BC-based L1 phase correction, Run1 data
357  Int_t bcMod4 = (reader->GetBCID() % 4); // LHC uses 40 MHz, EMCal uses 10 MHz clock
358 
359  //AliCDBManager* man = AliCDBManager::Instance();
360  //Int_t runNumber = man->GetRun();
361 
362  Int_t runNumber = reader->GetRunNumber();
363 
364  // Apply this shift for Run1 data
365  if ((runNumber > 130850 && runNumber < 200000) && (bcMod4==0 || bcMod4==1))
366  bcTimePhaseCorr = -1e-7; // subtract 100 ns for certain BC values
367 
368  while (in.NextDDL())
369  {
370  while (in.NextChannel())
371  {
372  caloFlag = in.GetCaloFlag();
373 
374  if ( caloFlag > 2 ) continue; // Work with ALTRO and FALTRO
375 
376 
377  Int_t sm = in.GetModule() ;
378  Int_t row = in.GetRow () ;
379  Int_t column = in.GetColumn() ;
380 
381  //----------------------------------------------------------------------
382  //
383  // Online mapping and numbering is the same for EMCal and DCal SMs but:
384  // - DCal odd SM (13,15,17) has online cols: 16-47; offline cols 0-31.
385  // - Even DCal SMs have the same numbering online and offline 0-31.
386  // - DCal 1/3 SM (18,19), online rows 16-23; offline rows 0-7
387  //
388  // In the next lines shift the online cols or rows depending on the
389  // SM to match the offline mapping.
390  //
391 
392  fGeom->ShiftOnlineToOfflineCellIndexes(sm, row, column);
393 
394  //
395  //---------------------------------------------------------------------
396 
397  if ( caloFlag < 2 && fRemoveBadChannels && pedbadmap->IsBadChannel(sm, column, row) )
398  {
399  continue;
400  }
401 
402  vector<AliCaloBunchInfo> bunchlist;
403 
404  while (in.NextBunch())
405  {
406  bunchlist.push_back( AliCaloBunchInfo(in.GetStartTimeBin(), in.GetBunchLength(), in.GetSignals() ) );
407  }
408 
409  if (bunchlist.size() == 0) continue;
410 
411  if ( caloFlag < 2 )
412  {
413  // ALTRO
414 
415  Int_t id = fGeom->GetAbsCellIdFromCellIndexes(sm, row, column) ;
416 
417  lowGain = in.IsLowGain();
418 
419  if(fUseL1Phase)
420  fRawAnalyzer->SetL1Phase( in.GetL1Phase() );
421  else
422  fRawAnalyzer->SetL1Phase( 0 );
423 
424  AliCaloFitResults res = fRawAnalyzer->Evaluate( bunchlist, in.GetAltroCFG1(), in.GetAltroCFG2());
425 
426  if(res.GetAmp() >= fNoiseThreshold )
427  {
428  AddDigit(digitsArr, id, lowGain, res.GetAmp(), res.GetTime()+bcTimePhaseCorr, res.GetChi2(), res.GetNdf() );
429  }
430  }// ALTRO
431  else if ( fUseFALTRO )
432  {// Fake ALTRO
433  fTriggerRawDigitMaker->Add( bunchlist );
434  }// Fake ALTRO
435  } // End while over channel
436  } // End while over DDL's, of input stream
437 
439 
440  TrimDigits(digitsArr);
441 }
442 
446 void AliEMCALRawUtils::TrimDigits(TClonesArray *digitsArr)
447 {
448  AliEMCALDigit *digit = 0;
449 
450  Int_t n = 0;
451  Int_t nDigits = digitsArr->GetEntriesFast();
452 
453  TIter nextdigit(digitsArr);
454 
455  while ((digit = (AliEMCALDigit*) nextdigit()))
456  {
457  if (digit->GetType() == AliEMCALDigit::kLGnoHG)
458  {
459  AliDebug(1,Form("Remove digit with id %d, LGnoHG",digit->GetId()));
460  digitsArr->Remove(digit);
461  }
462  else if(fTimeMin > digit->GetTime() || fTimeMax < digit->GetTime())
463  {
464  digitsArr->Remove(digit);
465  AliDebug(1,Form("Remove digit with id %d, Bad Time %e",digit->GetId(), digit->GetTime()));
466  }
467  else if (0 > digit->GetChi2())
468  {
469  digitsArr->Remove(digit);
470  AliDebug(1,Form("Remove digit with id %d, Bad Chi2 %e",digit->GetId(), digit->GetChi2()));
471  }
472  else
473  {
474  digit->SetIndexInList(n);
475  n++;
476  }
477  }//while
478 
479  digitsArr->Compress();
480 
481  AliDebug(1,Form("N Digits before trimming : %d; after array compression %d",nDigits,digitsArr->GetEntriesFast()));
482 }
483 
488 {
489  delete fRawAnalyzer; // delete doesn't do anything if the pointer is 0x0
490 
492  fRawAnalyzer->SetNsampleCut(5); // requirement for fits to be done, for the new methods
496 }
497 
498 
499 
static const char * DdlFileName(const char *detectorName, Int_t ddlIndex)
Definition: AliDAQ.cxx:329
static AliRunLoader * Instance()
Definition: AliRunLoader.h:176
provides access to EMCAL/DCAL STU DDL raw data.
void AddDigit(TClonesArray *digitsArr, Int_t id, Int_t lowGain, Float_t amp, Float_t time, Float_t chi2, Int_t ndf)
virtual void PostProcess()
Post process digits.
Bool_t fUseL1Phase
Use L1Phase time shift.
double GetTime() const
void SetType(Int_t t)
Definition: AliEMCALDigit.h:78
Int_t GetAbsCellIdFromCellIndexes(Int_t nSupMod, Int_t iphi, Int_t ieta) const
static Int_t GetFirstSTUDDL()
Definition: AliDAQ.h:74
Float_t fTimeMin
Minimum threshold for the time of the signal.
void ShiftOnlineToOfflineCellIndexes(Int_t sm, Int_t &iphi, Int_t &ieta) const
#define TObjArray
Float_t GetTime(void) const
Definition: AliEMCALDigit.h:64
static const Char_t * GetDefaultGeometryName()
virtual Int_t GetEvent()
void SetNsampleCut(Int_t cut)
Float_t GetChi2(void) const
Definition: AliEMCALDigit.h:66
AliLoader * GetDetectorLoader(const char *detname)
AliEMCALRawUtils(Algo::fitAlgorithm fitAlgo=Algo::kStandard)
AliEMCALGeometry * fGeom
Geometry.
void SetOverflowCut(Int_t cut)
void SetAmpCut(Float_t cut)
void TrimDigits(TClonesArray *digitsArr)
EMCal digits object.
Definition: AliEMCALDigit.h:30
TClonesArray * Digits()
TString fileName(const char *dir, int runNumber, const char *da, int i, const char *type)
Container class to hold results from fitting.
#define AliWarning(message)
Definition: AliLog.h:541
Container of ALTRO information.
Give access to hits, digits, recpoints arrays and OCDB.
void GetCellPhiEtaIndexInSModule(Int_t nSupMod, Int_t nModule, Int_t nIphi, Int_t nIeta, Int_t &iphi, Int_t &ieta) const
static Int_t GetRawFormatThreshold()
void SetTime(Float_t time)
Definition: AliEMCALDigit.h:74
AliCaloRawAnalyzer * fRawAnalyzer
e.g. for sample selection for fits.
virtual void SetIO(AliRawReader *reader, AliCaloRawStreamV3 &in, AliEMCALTriggerSTURawStream &inSTU, TClonesArray *digits, TClonesArray *data)
Connect I/O.
Double_t chi2
Definition: AnalyzeLaser.C:7
void SetL1Phase(Double_t phase)
static AliCaloRawAnalyzer * CreateAnalyzer(const int algo)
void UnloadDigits() const
Definition: AliLoader.h:131
Int_t fNoiseThreshold
Threshold to consider signal or noise.
virtual void Add(const std::vector< AliCaloBunchInfo > &bunchlist)
Add bunch list of type AliCaloBunchInfo.
const double HGLGFACTOR
energy transion low/high gaing
#define AliInfo(message)
Definition: AliLog.h:484
Bool_t GetCellIndex(Int_t absId, Int_t &nSupMod, Int_t &nModule, Int_t &nIphi, Int_t &nIeta) const
AliAltroMapping * fMapping[4]
What is the array size?
virtual AliCaloFitResults Evaluate(const std::vector< AliCaloBunchInfo > &, UInt_t, UInt_t)=0
void SetFitArrayCut(Int_t cut)
Float_t GetChi2() const
UShort_t GetNdf() const
virtual AliEMCALGeometry * GetGeometry() const
Definition: AliEMCAL.cxx:466
Int_t GetType() const
Definition: AliEMCALDigit.h:69
Base Class for EMCAL description.
Definition: AliEMCAL.h:35
pedestal/bad map monitoring and calibration tools
void SetIndexInList(Int_t val)
Definition: AliDigitNew.h:25
#define AliFatal(message)
Definition: AliLog.h:640
void Raw2Digits(AliRawReader *reader, TClonesArray *digitsArr, const AliCaloCalibPedestal *pedbadmap, TClonesArray *digitsTRG=0x0, TClonesArray *trgData=0x0)
void SetFittingAlgorithm(Int_t val)
const double TIMEBINMAX
maximum bin in time sample
static Bool_t RawSampledResponse(Double_t dtime, Double_t damp, Int_t *adcH, Int_t *adcL, Int_t keyErr=0)
const int NRCUSPERMODULE
Number of RCUs per Module.
#define AliDebug(logLevel, message)
Definition: AliLog.h:300
AliEMCALTriggerRawDigitMaker * fTriggerRawDigitMaker
Trigger raw digit info.
Float_t GetAmp() const
Int_t GetId() const
Definition: AliDigitNew.h:23
static Int_t runNumber
Definition: pdc06_config.C:126
const int TIMEBINS
number of sampling bins of the raw RO signal (we typically use 15-50; max is 1k+) ...
Handling of raw data.
AliDetector * GetDetector(const char *name) const
Definition: AliRun.cxx:200
static AliEMCALGeometry * GetInstance()
Int_t LoadDigits(Option_t *opt="")
Definition: AliLoader.h:106
void res(Char_t i)
Definition: Resolution.C:2
void ShiftOfflineToOnlineCellIndexes(Int_t sm, Int_t &iphi, Int_t &ieta) const
void SetIsZeroSuppressed(bool iszs=true)
Float_t GetAmplitude() const
Definition: AliEMCALDigit.h:55
fitAlgorithm
< fitting alorithms tag numbers
const int OVERFLOWCUT
sample overflow
EMCal trigger raw digits maker.
static const TObjArray * GetMappings()
Bool_t fUseFALTRO
Use FALTRO and pass it to the digits.
AliRun * GetAliRun() const
Float_t fTimeMax
Maximum threshold for the time of the signal.
void SetAmplitude(Float_t amp)
Definition: AliEMCALDigit.h:72