- if ( nsamples > 1 ) { // possibly something to fit
- FitRaw(first, last, amp, time);
- time += timebinOffset;
- }
-
- if ( amp>0 && time>0 ) { // brief sanity check of fit results
-
- // check fit results: should be consistent with initial estimates
- // more magic numbers, but very loose cuts, for now..
- // We have checked that amp and ampEstimate values are positive so division for assymmetry
- // calculation should be OK/safe
- Float_t ampAsymm = (amp - ampEstimate)/(amp + ampEstimate);
- if ( (TMath::Abs(ampAsymm) > 0.1) ) {
- AliDebug(2,Form("Fit results amp %f time %f not consistent with expectations ped %f max-ped %f time %d",
- amp, time, pedEstimate, ampEstimate, timeEstimate));
-
- // what should do we do then? skip this channel or assign the simple estimate?
- // for now just overwrite the fit results with the simple estimate
- amp = ampEstimate;
- time = timeEstimate;
- } // asymm check
- } // amp & time check
- } // ampEstimate check
- } // method selection
-
- if (amp > fNoiseThreshold && amp<fgkRawSignalOverflow) { // something to be stored
- Int_t id = fGeom->GetAbsCellIdFromCellIndexes(in.GetModule(), in.GetRow(), in.GetColumn()) ;
- lowGain = in.IsLowGain();
-
- // go from time-bin units to physical time fgtimetrigger
- time = time * GetRawFormatTimeBinWidth(); // skip subtraction of fgTimeTrigger?
-
- AliDebug(2,Form("id %d lowGain %d amp %g", id, lowGain, amp));
- // printf("Added tower: SM %d, row %d, column %d, amp %3.2f\n",in.GetModule(), in.GetRow(), in.GetColumn(),amp);
- // round off amplitude value to nearest integer
- AddDigit(digitsArr, id, lowGain, TMath::Nint(amp), time);
- }
-
- }//ALTRO
- else if(fUseFALTRO)
- {// Fake ALTRO
- // if (maxTimeBin && gSig->GetN() > maxTimeBin + 10) gSig->Set(maxTimeBin + 10); // set actual max size of TGraph
- Int_t hwAdd = in.GetHWAddress();
- UShort_t iRCU = in.GetDDLNumber() % 2; // 0/1
- UShort_t iBranch = ( hwAdd >> 11 ) & 0x1; // 0/1
-
- // Now find TRU number
- Int_t itru = 3 * in.GetModule() + ( (iRCU << 1) | iBranch ) - 1;
-
- AliDebug(1,Form("Found TRG digit in TRU: %2d ADC: %2d",itru,in.GetColumn()));
-
- Int_t idtrg;
-
- Bool_t isOK = fGeom->GetAbsFastORIndexFromTRU(itru, in.GetColumn(), idtrg);
-
- Int_t timeSamples[256]; for (Int_t j=0;j<256;j++) timeSamples[j] = 0;
- Int_t nSamples = 0;
-
- for (std::vector<AliCaloBunchInfo>::iterator itVectorData = bunchlist.begin(); itVectorData != bunchlist.end(); itVectorData++)
- {
- AliCaloBunchInfo bunch = *(itVectorData);
-
- const UShort_t* sig = bunch.GetData();
- Int_t startBin = bunch.GetStartBin();
-
- for (Int_t iS = 0; iS < bunch.GetLength(); iS++)
- {
- Int_t time = startBin--;
- Int_t amp = sig[iS];
-
- if ( amp ) timeSamples[nSamples++] = ( ( time << 12 ) & 0xFF000 ) | ( amp & 0xFFF );
- }
- }
-
- if (nSamples && isOK) AddDigit(digitsTRG, idtrg, timeSamples, nSamples);
- }//Fake ALTRO
- } // end while over channel
+ if ( fFittingAlgorithm == Algo::kFastFit || fFittingAlgorithm == Algo::kNeuralNet ||
+ fFittingAlgorithm == Algo::kLMS || fFittingAlgorithm == Algo::kPeakFinder ||
+ fFittingAlgorithm == Algo::kCrude) {
+ // all functionality to determine amp and time etc is encapsulated inside the Evaluate call for these methods
+ AliCaloFitResults fitResults = fRawAnalyzer->Evaluate( bunchlist, in.GetAltroCFG1(), in.GetAltroCFG2());
+
+ amp = fitResults.GetAmp();
+ time = fitResults.GetTime();
+ timeEstimate = fitResults.GetMaxTimebin();
+ ampEstimate = fitResults.GetMaxSig();
+ chi2 = fitResults.GetChi2();
+ ndf = fitResults.GetNdf();
+ if (fitResults.GetStatus() == Ret::kFitPar) {
+ fitDone = kTRUE;
+ }
+ }
+ else { // for the other methods we for now use the functionality of
+ // AliCaloRawAnalyzer as well, to select samples and prepare for fits,
+ // if it looks like there is something to fit
+
+ // parameters init.
+ Float_t pedEstimate = 0;
+ short maxADC = 0;
+ Int_t first = 0;
+ Int_t last = 0;
+ Int_t bunchIndex = 0;
+ //
+ // The PreFitEvaluateSamples + later call to FitRaw will hopefully
+ // be replaced by a single Evaluate call or so soon, like for the other
+ // methods, but this should be good enough for evaluation of
+ // the methods for now (Jan. 2010)
+ //
+ int nsamples = fRawAnalyzer->PreFitEvaluateSamples( bunchlist, in.GetAltroCFG1(), in.GetAltroCFG2(), bunchIndex, ampEstimate, maxADC, timeEstimate, pedEstimate, first, last);
+
+ if (ampEstimate >= fNoiseThreshold) { // something worth looking at
+
+ time = timeEstimate; // maxrev in AliCaloRawAnalyzer speak; comes with an offset w.r.t. real timebin
+ Int_t timebinOffset = bunchlist.at(bunchIndex).GetStartBin() - (bunchlist.at(bunchIndex).GetLength()-1);
+ amp = ampEstimate;
+
+ if ( nsamples > 1 && maxADC<fgkOverflowCut ) { // possibly something to fit
+ FitRaw(first, last, amp, time, chi2, fitDone);
+ time += timebinOffset;
+ timeEstimate += timebinOffset;
+ ndf = nsamples - 2;
+ }
+
+ } // ampEstimate check
+ } // method selection
+
+ if ( fitDone ) { // brief sanity check of fit results
+ Float_t ampAsymm = (amp - ampEstimate)/(amp + ampEstimate);
+ Float_t timeDiff = time - timeEstimate;
+ if ( (TMath::Abs(ampAsymm) > 0.1) || (TMath::Abs(timeDiff) > 2) ) {
+ // AliDebug(2,Form("Fit results amp %f time %f not consistent with expectations amp %f time %d", amp, time, ampEstimate, timeEstimate));
+
+ // for now just overwrite the fit results with the simple/initial estimate
+ amp = ampEstimate;
+ time = timeEstimate;
+ fitDone = kFALSE;
+ }
+ } // fitDone
+
+ if (amp >= fNoiseThreshold) { // something to be stored
+ if ( ! fitDone) { // smear ADC with +- 0.5 uniform (avoid discrete effects)
+ amp += (0.5 - gRandom->Rndm()); // Rndm generates a number in ]0,1]
+ }
+
+ Int_t id = fGeom->GetAbsCellIdFromCellIndexes(in.GetModule(), in.GetRow(), in.GetColumn()) ;
+ lowGain = in.IsLowGain();
+
+ // go from time-bin units to physical time fgtimetrigger
+ time = time * GetRawFormatTimeBinWidth(); // skip subtraction of fgTimeTrigger?
+ // subtract RCU L1 phase (L1Phase is in seconds) w.r.t. L0:
+ time -= in.GetL1Phase();
+
+ AliDebug(2,Form("id %d lowGain %d amp %g", id, lowGain, amp));
+ // printf("Added tower: SM %d, row %d, column %d, amp %3.2f\n",in.GetModule(), in.GetRow(), in.GetColumn(),amp);
+
+ AddDigit(digitsArr, id, lowGain, amp, time, chi2, ndf);
+ }
+
+ }//ALTRO
+ else if(fUseFALTRO)
+ {// Fake ALTRO
+ fTriggerRawDigitMaker->Add( bunchlist );
+ }//Fake ALTRO
+ } // end while over channel