1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
18 /////////////////////////////////////////////////////////////////////////////////////////
20 // Implementation of the TPC pulser calibration //
22 // Origin: Jens Wiechula, Marian Ivanov J.Wiechula@gsi.de, Marian.Ivanov@cern.ch //
24 /////////////////////////////////////////////////////////////////////////////////////////
25 /***************************************************************************
27 ***************************************************************************
29 The AliTPCCalibPulser class is used to get calibration data concerning the FEE using
30 runs performed with the calibration pulser.
32 The information retrieved is
34 - Signal width differences
35 - Amplification variations
37 the seen differences arise from the manufacturing tolerances of the PASAs and are very small within
38 one chip and somewhat large between different chips.
41 For each ROC three TH2S histos 'Reference Histograms' (ROC channel vs. [Time0, signal width, Q sum]) is created when
42 it is filled for the first time (GetHisto[T0,RMS,Q](ROC,kTRUE)). The histos are stored in the
43 TObjArrays fHistoT0Array, fHistoRMSArray and fHistoQArray.
48 Raw calibration pulser data is processed by calling one of the ProcessEvent(...) functions
49 (see below). These in the end call the Update(...) function.
51 - the Update(...) function:
52 In this function the array fPadSignal is filled with the adc signals between the specified range
53 fFirstTimeBin and fLastTimeBin for the current pad.
54 before going to the next pad the ProcessPad() function is called, which analyses the data for one pad
57 - the ProcessPad() function:
58 Find Pedestal and Noise information
59 - use database information which has to be set by calling
60 SetPedestalDatabase(AliTPCCalPad *pedestalTPC, AliTPCCalPad *padNoiseTPC)
61 - if no information from the pedestal data base
62 is available the informaion is calculated on the fly ( see FindPedestal() function )
64 Find the Pulser signal information
65 - calculate mean = T0, RMS = signal width and Q sum in a range of -2+7 timebins around Q max
66 the Q sum is scaled by pad area
67 (see FindPulserSignal(...) function)
69 Fill a temprary array for the T0 information (GetPadTimesEvent(fCurrentSector,kTRUE)) (why see below)
70 Fill the Q sum and RMS values in the histograms (GetHisto[RMS,Q](ROC,kTRUE)),
72 At the end of each event the EndEvent() function is called
74 - the EndEvent() function:
75 calculate the mean T0 for each ROC and fill the Time0 histogram with Time0-<Time0 for ROC>
76 This is done to overcome syncronisation problems between the trigger and the fec clock.
78 After accumulating the desired statistics the Analyse() function has to be called.
79 - the Analyse() function
80 Whithin this function the mean values of T0, RMS, Q are calculated for each pad, using
81 the AliMathBase::GetCOG(...) function, and the calibration
82 storage classes (AliTPCCalROC) are filled for each ROC.
83 The calibration information is stored in the TObjArrays fCalRocArrayT0, fCalRocArrayRMS and
88 User interface for filling data:
89 --------------------------------
91 To Fill information one of the following functions can be used:
93 Bool_t ProcessEvent(eventHeaderStruct *event);
95 - use AliTPCRawReaderDate and call ProcessEvent(AliRawReader *rawReader)
97 Bool_t ProcessEvent(AliRawReader *rawReader);
98 - process AliRawReader event
99 - use AliTPCRawStream to loop over data and call ProcessEvent(AliTPCRawStream *rawStream)
101 Bool_t ProcessEvent(AliTPCRawStream *rawStream);
102 - process event from AliTPCRawStream
103 - call Update function for signal filling
105 Int_t Update(const Int_t isector, const Int_t iRow, const Int_t
106 iPad, const Int_t iTimeBin, const Float_t signal);
107 - directly fill signal information (sector, row, pad, time bin, pad)
108 to the reference histograms
110 It is also possible to merge two independently taken calibrations using the function
112 void Merge(AliTPCCalibPulser *sig)
113 - copy histograms in 'sig' if the do not exist in this instance
114 - Add histograms in 'sig' to the histograms in this instance if the allready exist
115 - After merging call Analyse again!
119 -- example: filling data using root raw data:
120 void fillSignal(Char_t *filename)
122 rawReader = new AliRawReaderRoot(fileName);
123 if ( !rawReader ) return;
124 AliTPCCalibPulser *calib = new AliTPCCalibPulser;
125 while (rawReader->NextEvent()){
126 calib->ProcessEvent(rawReader);
129 calib->DumpToFile("SignalData.root");
135 What kind of information is stored and how to retrieve them:
136 ------------------------------------------------------------
138 - Accessing the 'Reference Histograms' (Time0, signal width and Q sum information pad by pad):
140 TH2F *GetHistoT0(Int_t sector);
141 TH2F *GetHistoRMS(Int_t sector);
142 TH2F *GetHistoQ(Int_t sector);
144 - Accessing the calibration storage objects:
146 AliTPCCalROC *GetCalRocT0(Int_t sector); // for the Time0 values
147 AliTPCCalROC *GetCalRocRMS(Int_t sector); // for the signal width values
148 AliTPCCalROC *GetCalRocQ(Int_t sector); // for the Q sum values
150 example for visualisation:
151 if the file "SignalData.root" was created using the above example one could do the following:
153 TFile fileSignal("SignalData.root")
154 AliTPCCalibPulser *sig = (AliTPCCalibPulser*)fileSignal->Get("AliTPCCalibPulser");
155 sig->GetCalRocT0(0)->Draw("colz");
156 sig->GetCalRocRMS(0)->Draw("colz");
158 or use the AliTPCCalPad functionality:
159 AliTPCCalPad padT0(ped->GetCalPadT0());
160 AliTPCCalPad padSigWidth(ped->GetCalPadRMS());
161 padT0->MakeHisto2D()->Draw("colz"); //Draw A-Side Time0 Information
162 padSigWidth->MakeHisto2D()->Draw("colz"); //Draw A-Side signal width Information
167 #include <TObjArray.h>
172 #include <TVectorF.h>
175 #include <TDirectory.h>
181 #include "AliRawReader.h"
182 #include "AliRawReaderRoot.h"
183 #include "AliRawReaderDate.h"
184 #include "AliTPCRawStream.h"
185 #include "AliTPCRawStreamFast.h"
186 #include "AliTPCCalROC.h"
187 #include "AliTPCCalPad.h"
188 #include "AliTPCROC.h"
189 #include "AliTPCParam.h"
190 #include "AliTPCCalibPulser.h"
191 #include "AliTPCcalibDB.h"
192 #include "AliMathBase.h"
194 #include "TTreeStream.h"
202 ClassImp(AliTPCCalibPulser)
204 AliTPCCalibPulser::AliTPCCalibPulser() :
205 AliTPCCalibRawBase(),
217 fIsZeroSuppressed(kFALSE),
219 fParam(new AliTPCParam),
228 fCalRocArrayOutliers(72),
232 fHMeanTimeSector(0x0),
233 fVMeanTimeSector(72),
234 fPadTimesArrayEvent(72),
236 fPadRMSArrayEvent(72),
237 fPadPedestalArrayEvent(72),
248 fVTime0OffsetCounter(72)
251 // AliTPCSignal default constructor
253 SetNameTitle("AliTPCCalibPulser","AliTPCCalibPulser");
258 //_____________________________________________________________________
259 AliTPCCalibPulser::AliTPCCalibPulser(const AliTPCCalibPulser &sig) :
260 AliTPCCalibRawBase(sig),
261 fNbinsT0(sig.fNbinsT0),
262 fXminT0(sig.fXminT0),
263 fXmaxT0(sig.fXmaxT0),
264 fNbinsQ(sig.fNbinsQ),
267 fNbinsRMS(sig.fNbinsRMS),
268 fXminRMS(sig.fXminRMS),
269 fXmaxRMS(sig.fXmaxRMS),
270 fPeakIntMinus(sig.fPeakIntMinus),
271 fPeakIntPlus(sig.fPeakIntPlus),
272 fIsZeroSuppressed(sig.fIsZeroSuppressed),
274 fParam(new AliTPCParam),
283 fCalRocArrayOutliers(72),
287 fHMeanTimeSector(0x0),
288 fVMeanTimeSector(72),
289 fPadTimesArrayEvent(72),
291 fPadRMSArrayEvent(72),
292 fPadPedestalArrayEvent(72),
303 fVTime0OffsetCounter(72)
306 // AliTPCSignal default constructor
309 for (Int_t iSec = 0; iSec < 72; ++iSec){
310 const AliTPCCalROC *calQ = (AliTPCCalROC*)sig.fCalRocArrayQ.UncheckedAt(iSec);
311 const AliTPCCalROC *calT0 = (AliTPCCalROC*)sig.fCalRocArrayT0.UncheckedAt(iSec);
312 const AliTPCCalROC *calRMS = (AliTPCCalROC*)sig.fCalRocArrayRMS.UncheckedAt(iSec);
313 const AliTPCCalROC *calOut = (AliTPCCalROC*)sig.fCalRocArrayOutliers.UncheckedAt(iSec);
315 const TH2S *hQ = (TH2S*)sig.fHistoQArray.UncheckedAt(iSec);
316 const TH2S *hT0 = (TH2S*)sig.fHistoT0Array.UncheckedAt(iSec);
317 const TH2S *hRMS = (TH2S*)sig.fHistoRMSArray.UncheckedAt(iSec);
319 if ( calQ != 0x0 ) fCalRocArrayQ.AddAt(new AliTPCCalROC(*calQ), iSec);
320 if ( calT0 != 0x0 ) fCalRocArrayT0.AddAt(new AliTPCCalROC(*calT0), iSec);
321 if ( calRMS != 0x0 ) fCalRocArrayRMS.AddAt(new AliTPCCalROC(*calRMS), iSec);
322 if ( calOut != 0x0 ) fCalRocArrayOutliers.AddAt(new AliTPCCalROC(*calOut), iSec);
325 TH2S *hNew = new TH2S(*hQ);
326 hNew->SetDirectory(0);
327 fHistoQArray.AddAt(hNew,iSec);
330 TH2S *hNew = new TH2S(*hT0);
331 hNew->SetDirectory(0);
332 fHistoQArray.AddAt(hNew,iSec);
335 TH2S *hNew = new TH2S(*hRMS);
336 hNew->SetDirectory(0);
337 fHistoQArray.AddAt(hNew,iSec);
339 fVMeanTimeSector[iSec]=sig.fVMeanTimeSector[iSec];
342 if ( sig.fHMeanTimeSector ) fHMeanTimeSector=(TH2F*)sig.fHMeanTimeSector->Clone();
345 AliTPCCalibPulser::AliTPCCalibPulser(const TMap *config) :
346 AliTPCCalibRawBase(),
358 fIsZeroSuppressed(kFALSE),
360 fParam(new AliTPCParam),
369 fCalRocArrayOutliers(72),
373 fHMeanTimeSector(0x0),
374 fVMeanTimeSector(72),
375 fPadTimesArrayEvent(72),
377 fPadRMSArrayEvent(72),
378 fPadPedestalArrayEvent(72),
389 fVTime0OffsetCounter(72)
392 // This constructor uses a TMap for setting some parametes
394 SetNameTitle("AliTPCCalibPulser","AliTPCCalibPulser");
397 if (config->GetValue("FirstTimeBin")) fFirstTimeBin = ((TObjString*)config->GetValue("FirstTimeBin"))->GetString().Atoi();
398 if (config->GetValue("LastTimeBin")) fLastTimeBin = ((TObjString*)config->GetValue("LastTimeBin"))->GetString().Atoi();
399 if (config->GetValue("NbinsT0")) fNbinsT0 = ((TObjString*)config->GetValue("NbinsT0"))->GetString().Atoi();
400 if (config->GetValue("XminT0")) fXminT0 = ((TObjString*)config->GetValue("XminT0"))->GetString().Atof();
401 if (config->GetValue("XmaxT0")) fXmaxT0 = ((TObjString*)config->GetValue("XmaxT0"))->GetString().Atof();
402 if (config->GetValue("NbinsQ")) fNbinsQ = ((TObjString*)config->GetValue("NbinsQ"))->GetString().Atoi();
403 if (config->GetValue("XminQ")) fXminQ = ((TObjString*)config->GetValue("XminQ"))->GetString().Atof();
404 if (config->GetValue("XmaxQ")) fXmaxQ = ((TObjString*)config->GetValue("XmaxQ"))->GetString().Atof();
405 if (config->GetValue("NbinsRMS")) fNbinsRMS = ((TObjString*)config->GetValue("NbinsRMS"))->GetString().Atoi();
406 if (config->GetValue("XminRMS")) fXminRMS = ((TObjString*)config->GetValue("XminRMS"))->GetString().Atof();
407 if (config->GetValue("XmaxRMS")) fXmaxRMS = ((TObjString*)config->GetValue("XmaxRMS"))->GetString().Atof();
408 if (config->GetValue("PeakIntMinus")) fPeakIntMinus = (Int_t)((TObjString*)config->GetValue("PeakIntMinus"))->GetString().Atof();
409 if (config->GetValue("PeakIntPlus")) fPeakIntPlus = (Int_t)((TObjString*)config->GetValue("PeakIntPlus"))->GetString().Atof();
410 if (config->GetValue("IsZeroSuppressed")) fIsZeroSuppressed = (Bool_t)((TObjString*)config->GetValue("IsZeroSuppressed"))->GetString().Atoi();
414 //_____________________________________________________________________
415 AliTPCCalibPulser& AliTPCCalibPulser::operator = (const AliTPCCalibPulser &source)
418 // assignment operator
420 if (&source == this) return *this;
421 new (this) AliTPCCalibPulser(source);
425 //_____________________________________________________________________
426 AliTPCCalibPulser::~AliTPCCalibPulser()
435 void AliTPCCalibPulser::Reset()
438 // Delete all information: Arrays, Histograms, CalRoc objects
440 fCalRocArrayT0.Delete();
441 fCalRocArrayQ.Delete();
442 fCalRocArrayRMS.Delete();
443 fCalRocArrayOutliers.Delete();
445 fHistoQArray.Delete();
446 fHistoT0Array.Delete();
447 fHistoRMSArray.Delete();
449 fPadTimesArrayEvent.Delete();
450 fPadQArrayEvent.Delete();
451 fPadRMSArrayEvent.Delete();
452 fPadPedestalArrayEvent.Delete();
454 if (fHMeanTimeSector) delete fHMeanTimeSector;
456 //_____________________________________________________________________
457 Int_t AliTPCCalibPulser::Update(const Int_t icsector,
460 const Int_t icTimeBin,
461 const Float_t csignal)
464 // Signal filling methode on the fly pedestal and time offset correction if necessary.
465 // no extra analysis necessary. Assumes knowledge of the signal shape!
466 // assumes that it is looped over consecutive time bins of one pad
469 if (icRow<0) return 0;
470 if (icPad<0) return 0;
471 if (icTimeBin<0) return 0;
472 if ( (icTimeBin>fLastTimeBin) || (icTimeBin<fFirstTimeBin) ) return 0;
474 if ( icRow<0 || icPad<0 ){
475 AliWarning("Wrong Pad or Row number, skipping!");
479 Int_t iChannel = fROC->GetRowIndexes(icsector)[icRow]+icPad; // global pad position in sector
481 //init first pad and sector in this event
482 if ( fCurrentChannel == -1 ) {
483 fCurrentChannel = iChannel;
484 fCurrentSector = icsector;
489 //process last pad if we change to a new one
490 if ( iChannel != fCurrentChannel ){
492 fLastSector=fCurrentSector;
493 fCurrentChannel = iChannel;
494 fCurrentSector = icsector;
499 //fill signals for current pad
500 fPadSignal[icTimeBin]=csignal;
501 if ( csignal > fMaxPadSignal ){
502 fMaxPadSignal = csignal;
503 fMaxTimeBin = icTimeBin;
507 //_____________________________________________________________________
508 void AliTPCCalibPulser::FindPedestal(Float_t part)
511 // find pedestal and noise for the current pad. Use either database or
512 // truncated mean with part*100%
514 Bool_t noPedestal = kTRUE;;
515 if (fPedestalTPC&&fPadNoiseTPC){
516 //use pedestal database
517 //only load new pedestals if the sector has changed
518 if ( fCurrentSector!=fLastSector ){
519 fPedestalROC = fPedestalTPC->GetCalROC(fCurrentSector);
520 fPadNoiseROC = fPadNoiseTPC->GetCalROC(fCurrentSector);
523 if ( fPedestalROC&&fPadNoiseROC ){
524 fPadPedestal = fPedestalROC->GetValue(fCurrentChannel);
525 fPadNoise = fPadNoiseROC->GetValue(fCurrentChannel);
531 //if we are not running with pedestal database, or for the current sector there is no information
532 //available, calculate the pedestal and noise on the fly
534 const Int_t kPedMax = 100; //maximum pedestal value
543 UShort_t histo[kPedMax];
544 memset(histo,0,kPedMax*sizeof(UShort_t));
546 for (Int_t i=fFirstTimeBin; i<=fLastTimeBin; ++i){
547 padSignal = fPadSignal.GetMatrixArray()[i];
548 if (padSignal<=0) continue;
549 if (padSignal>max && i>10) {
553 if (padSignal>kPedMax-1) continue;
554 histo[Int_t(padSignal+0.5)]++;
558 for (Int_t i=1; i<kPedMax; ++i){
559 if (count1<count0*0.5) median=i;
564 // what if by chance histo[median] == 0 ?!?
565 Float_t count=histo[median] ,mean=histo[median]*median, rms=histo[median]*median*median ;
567 for (Int_t idelta=1; idelta<10; ++idelta){
568 if (median-idelta<=0) continue;
569 if (median+idelta>kPedMax) continue;
570 if (count<part*count1){
571 count+=histo[median-idelta];
572 mean +=histo[median-idelta]*(median-idelta);
573 rms +=histo[median-idelta]*(median-idelta)*(median-idelta);
574 count+=histo[median+idelta];
575 mean +=histo[median+idelta]*(median+idelta);
576 rms +=histo[median+idelta]*(median+idelta)*(median+idelta);
583 rms = TMath::Sqrt(TMath::Abs(rms/count-mean*mean));
588 fPadPedestal*=(Float_t)(!fIsZeroSuppressed);
590 //_____________________________________________________________________
591 void AliTPCCalibPulser::FindPulserSignal(TVectorD ¶m, Float_t &qSum)
594 // Find position, signal width and height of the CE signal (last signal)
595 // param[0] = Qmax, param[1] = mean time, param[2] = rms;
596 // maxima: array of local maxima of the pad signal use the one closest to the mean CE position
599 Float_t ceQmax =0, ceQsum=0, ceTime=0, ceRMS=0;
600 Int_t cemaxpos = fMaxTimeBin;
601 Float_t ceSumThreshold = 10.*TMath::Max(fPadNoise,Float_t(1.)); // threshold for the signal sum
602 Float_t ceMaxThreshold = 5.*TMath::Max(fPadNoise,Float_t(1.)); // threshold for the signal max
603 const Int_t kCemin = fPeakIntMinus; // range for the analysis of the ce signal +- channels from the peak
604 const Int_t kCemax = fPeakIntPlus;
611 ceQmax = fPadSignal.GetMatrixArray()[cemaxpos]-fPadPedestal;
612 if ( ceQmax<ceMaxThreshold ) return;
613 for (Int_t i=cemaxpos-kCemin; i<=cemaxpos+kCemax; ++i){
614 Float_t signal = fPadSignal.GetMatrixArray()[i]-fPadPedestal;
615 if ( (i>fFirstTimeBin) && (i<fLastTimeBin) && (signal>0) ){
616 ceTime+=signal*(i+0.5);
617 ceRMS +=signal*(i+0.5)*(i+0.5);
622 if (ceQsum>ceSumThreshold) {
624 ceRMS = TMath::Sqrt(TMath::Abs(ceRMS/ceQsum-ceTime*ceTime));
625 ceTime-=GetL1PhaseTB();
626 //only fill the Time0Offset if pad was not marked as an outlier!
628 //skip edge pads for calculating the mean time
629 if ( !IsEdgePad(fCurrentSector,fCurrentRow,fCurrentPad) ){
630 fVTime0Offset.GetMatrixArray()[fCurrentSector]+=ceTime; // mean time for each sector
631 fVTime0OffsetCounter.GetMatrixArray()[fCurrentSector]++;
632 GetHistoTSec()->Fill(ceTime,fCurrentSector);
635 if ( !(fOutliers->GetCalROC(fCurrentSector)->GetValue(fCurrentChannel)) ){
636 fVTime0Offset.GetMatrixArray()[fCurrentSector]+=ceTime; // mean time for each sector
637 fVTime0OffsetCounter.GetMatrixArray()[fCurrentSector]++;
641 //Normalise Q to the 'cell-size': The wire density is the same in the IROC and OROC, therefore the
642 // the pick-up signal should scale with the pad area. In addition
643 // the signal should decrease with the wire distance (4mm in IROC, 6mm in OROC),
644 // ratio 2/3. The pad area we express in mm2 (factor 100). We normalise the signal
645 // to the OROC signal (factor 2/3 for the IROCs).
646 Float_t norm = fParam->GetPadPitchWidth(fCurrentSector)*fParam->GetPadPitchLength(fCurrentSector,fCurrentRow)*100;
647 if ( fCurrentSector<fParam->GetNInnerSector() ) norm*=3./2.;
661 //_____________________________________________________________________
662 void AliTPCCalibPulser::ProcessPad()
665 // Process data of current pad
671 FindPulserSignal(param, qSum);
673 Double_t meanT = param[1];
674 Double_t sigmaT = param[2];
677 //Fill Event T0 counter
678 (*GetPadTimesEvent(fCurrentSector,kTRUE)).GetMatrixArray()[fCurrentChannel] = meanT;
681 // GetHistoQ(fCurrentSector,kTRUE)->Fill( TMath::Sqrt(qSum), fCurrentChannel ); //use linear scale, needs also a change in the Analyse funciton.
682 GetHistoQ(fCurrentSector,kTRUE)->Fill( qSum, fCurrentChannel );
685 GetHistoRMS(fCurrentSector,kTRUE)->Fill( sigmaT, fCurrentChannel );
688 //Fill debugging info
689 if ( GetStreamLevel()>0 ){
690 TTreeSRedirector *streamer=GetDebugStreamer();
691 if ( GetStreamLevel() == 1 ){
693 Int_t padc = fCurrentPad-(fROC->GetNPads(fCurrentSector,fCurrentRow)/2);
694 (*streamer) << "PadSignals" <<
695 "Sector=" <<fCurrentSector<<
696 "Row=" <<fCurrentRow<<
697 "Pad=" <<fCurrentPad<<
699 "Channel="<<fCurrentChannel<<
702 "signal.=" <<&fPadSignal<<
706 (*GetPadPedestalEvent(fCurrentSector,kTRUE))[fCurrentChannel]=fPadPedestal;
707 (*GetPadRMSEvent(fCurrentSector,kTRUE))[fCurrentChannel]=sigmaT;
708 (*GetPadQEvent(fCurrentSector,kTRUE))[fCurrentChannel]=qSum;
713 //_____________________________________________________________________
714 void AliTPCCalibPulser::EndEvent()
717 // Process data of current event
720 //check if last pad has allready been processed, if not do so
721 if ( fMaxTimeBin>-1 ) ProcessPad();
723 //loop over all ROCs, fill Time0 histogram corrected for the mean Time0 of each ROC
724 for ( Int_t iSec = 0; iSec<72; ++iSec ){
725 TVectorF *vTimes = GetPadTimesEvent(iSec);
726 if ( !vTimes || fVTime0OffsetCounter[iSec]==0 ) continue;
727 Float_t time0 = fVTime0Offset[iSec]/fVTime0OffsetCounter[iSec];
728 for ( UInt_t iChannel=0; iChannel<fROC->GetNChannels(iSec); ++iChannel ){
729 Float_t time = (*vTimes).GetMatrixArray()[iChannel];
731 GetHistoT0(iSec,kTRUE)->Fill( time-time0,iChannel );
732 //GetHistoT0(iSec,kTRUE)->Fill( time,iChannel );
736 if ( GetStreamLevel()>1 ){
737 TTreeSRedirector *streamer=GetDebugStreamer();
743 Float_t q = (*GetPadQEvent(iSec)).GetMatrixArray()[iChannel];
744 Float_t rms = (*GetPadRMSEvent(iSec)).GetMatrixArray()[iChannel];
746 UInt_t channel=iChannel;
749 while ( channel > (fROC->GetRowIndexes(sector)[row]+fROC->GetNPads(sector,row)-1) ) row++;
750 pad = channel-fROC->GetRowIndexes(sector)[row];
751 padc = pad-(fROC->GetNPads(sector,row)/2);
753 (*streamer) << "DataPad" <<
754 // "Event=" << fEvent <<
755 "Sector="<< sector <<
759 "PadSec="<< channel <<
771 //_____________________________________________________________________
772 TH2S* AliTPCCalibPulser::GetHisto(Int_t sector, TObjArray *arr,
773 Int_t nbinsY, Float_t ymin, Float_t ymax,
774 const Char_t *type, Bool_t force)
777 // return pointer to Q histogram
778 // if force is true create a new histogram if it doesn't exist allready
780 if ( !force || arr->UncheckedAt(sector) )
781 return (TH2S*)arr->UncheckedAt(sector);
783 // if we are forced and histogram doesn't yes exist create it
784 Char_t name[255], title[255];
786 sprintf(name,"hCalib%s%.2d",type,sector);
787 sprintf(title,"%s calibration histogram sector %.2d",type,sector);
789 // new histogram with Q calib information. One value for each pad!
790 TH2S* hist = new TH2S(name,title,
792 fROC->GetNChannels(sector),0,fROC->GetNChannels(sector));
793 hist->SetDirectory(0);
794 arr->AddAt(hist,sector);
797 //_____________________________________________________________________
798 TH2S* AliTPCCalibPulser::GetHistoT0(Int_t sector, Bool_t force)
801 // return pointer to T0 histogram
802 // if force is true create a new histogram if it doesn't exist allready
804 TObjArray *arr = &fHistoT0Array;
805 return GetHisto(sector, arr, fNbinsT0, fXminT0, fXmaxT0, "T0", force);
807 //_____________________________________________________________________
808 TH2S* AliTPCCalibPulser::GetHistoQ(Int_t sector, Bool_t force)
811 // return pointer to Q histogram
812 // if force is true create a new histogram if it doesn't exist allready
814 TObjArray *arr = &fHistoQArray;
815 return GetHisto(sector, arr, fNbinsQ, fXminQ, fXmaxQ, "Q", force);
817 //_____________________________________________________________________
818 TH2S* AliTPCCalibPulser::GetHistoRMS(Int_t sector, Bool_t force)
821 // return pointer to Q histogram
822 // if force is true create a new histogram if it doesn't exist allready
824 TObjArray *arr = &fHistoRMSArray;
825 return GetHisto(sector, arr, fNbinsRMS, fXminRMS, fXmaxRMS, "RMS", force);
827 //_____________________________________________________________________
828 TH2F* AliTPCCalibPulser::GetHistoTSec()
831 // return the pointer to the abs time distribution per sector
832 // create it if it does not exist
834 if ( !fHMeanTimeSector ) //!!!if you change the binning here, you should also change it in the Analyse Function!!
835 fHMeanTimeSector = new TH2F("fHMeanTimeSector","Abs mean time per sector",
836 20*(fLastTimeBin-fFirstTimeBin), fFirstTimeBin, fLastTimeBin,
838 return fHMeanTimeSector;
840 //_____________________________________________________________________
841 TVectorF* AliTPCCalibPulser::GetPadInfoEvent(Int_t sector, TObjArray *arr, Bool_t force)
844 // return pointer to Pad Info from 'arr' for the current event and sector
845 // if force is true create it if it doesn't exist allready
847 if ( !force || arr->UncheckedAt(sector) )
848 return (TVectorF*)arr->UncheckedAt(sector);
850 TVectorF *vect = new TVectorF(fROC->GetNChannels(sector));
851 arr->AddAt(vect,sector);
854 //_____________________________________________________________________
855 TVectorF* AliTPCCalibPulser::GetPadTimesEvent(Int_t sector, Bool_t force)
858 // return pointer to Pad Times Array for the current event and sector
859 // if force is true create it if it doesn't exist allready
861 TObjArray *arr = &fPadTimesArrayEvent;
862 return GetPadInfoEvent(sector,arr,force);
864 //_____________________________________________________________________
865 TVectorF* AliTPCCalibPulser::GetPadQEvent(Int_t sector, Bool_t force)
868 // return pointer to Pad Q Array for the current event and sector
869 // if force is true create it if it doesn't exist allready
870 // for debugging purposes only
873 TObjArray *arr = &fPadQArrayEvent;
874 return GetPadInfoEvent(sector,arr,force);
876 //_____________________________________________________________________
877 TVectorF* AliTPCCalibPulser::GetPadRMSEvent(Int_t sector, Bool_t force)
880 // return pointer to Pad RMS Array for the current event and sector
881 // if force is true create it if it doesn't exist allready
882 // for debugging purposes only
884 TObjArray *arr = &fPadRMSArrayEvent;
885 return GetPadInfoEvent(sector,arr,force);
887 //_____________________________________________________________________
888 TVectorF* AliTPCCalibPulser::GetPadPedestalEvent(Int_t sector, Bool_t force)
891 // return pointer to Pad RMS Array for the current event and sector
892 // if force is true create it if it doesn't exist allready
893 // for debugging purposes only
895 TObjArray *arr = &fPadPedestalArrayEvent;
896 return GetPadInfoEvent(sector,arr,force);
898 //_____________________________________________________________________
899 AliTPCCalROC* AliTPCCalibPulser::GetCalRoc(Int_t sector, TObjArray* arr, Bool_t force) const
902 // return pointer to ROC Calibration
903 // if force is true create a new histogram if it doesn't exist allready
905 if ( !force || arr->UncheckedAt(sector) )
906 return (AliTPCCalROC*)arr->UncheckedAt(sector);
908 // if we are forced and histogram doesn't yes exist create it
910 // new AliTPCCalROC for T0 information. One value for each pad!
911 AliTPCCalROC *croc = new AliTPCCalROC(sector);
912 arr->AddAt(croc,sector);
915 //_____________________________________________________________________
916 AliTPCCalROC* AliTPCCalibPulser::GetCalRocT0(Int_t sector, Bool_t force)
919 // return pointer to Carge ROC Calibration
920 // if force is true create a new histogram if it doesn't exist allready
922 TObjArray *arr = &fCalRocArrayT0;
923 return GetCalRoc(sector, arr, force);
925 //_____________________________________________________________________
926 AliTPCCalROC* AliTPCCalibPulser::GetCalRocQ(Int_t sector, Bool_t force)
929 // return pointer to T0 ROC Calibration
930 // if force is true create a new histogram if it doesn't exist allready
932 TObjArray *arr = &fCalRocArrayQ;
933 return GetCalRoc(sector, arr, force);
935 //_____________________________________________________________________
936 AliTPCCalROC* AliTPCCalibPulser::GetCalRocRMS(Int_t sector, Bool_t force)
939 // return pointer to signal width ROC Calibration
940 // if force is true create a new histogram if it doesn't exist allready
942 TObjArray *arr = &fCalRocArrayRMS;
943 return GetCalRoc(sector, arr, force);
945 //_____________________________________________________________________
946 AliTPCCalROC* AliTPCCalibPulser::GetCalRocOutliers(Int_t sector, Bool_t force)
949 // return pointer to Outliers
950 // if force is true create a new histogram if it doesn't exist allready
952 TObjArray *arr = &fCalRocArrayOutliers;
953 return GetCalRoc(sector, arr, force);
955 //_____________________________________________________________________
956 void AliTPCCalibPulser::ResetEvent()
959 // Reset global counters -- Should be called before each event is processed
969 fPadTimesArrayEvent.Delete();
971 fPadQArrayEvent.Delete();
972 fPadRMSArrayEvent.Delete();
973 fPadPedestalArrayEvent.Delete();
975 for ( Int_t i=0; i<72; ++i ){
977 fVTime0OffsetCounter[i]=0;
980 //_____________________________________________________________________
981 void AliTPCCalibPulser::ResetPad()
984 // Reset pad infos -- Should be called after a pad has been processed
986 for (Int_t i=fFirstTimeBin; i<fLastTimeBin+1; ++i)
993 //_____________________________________________________________________
994 Bool_t AliTPCCalibPulser::IsEdgePad(Int_t sector, Int_t row, Int_t pad)
997 // return true if pad is on the edge of a row
1000 Int_t edge2 = fROC->GetNPads(sector,row)-1;
1001 if ( pad == edge1 || pad == edge2 ) return kTRUE;
1005 //_____________________________________________________________________
1006 void AliTPCCalibPulser::Merge(AliTPCCalibPulser *sig)
1009 // Merge reference histograms of sig to the current AliTPCCalibPulser
1013 for (Int_t iSec=0; iSec<72; ++iSec){
1014 TH2S *hRefQmerge = sig->GetHistoQ(iSec);
1015 TH2S *hRefT0merge = sig->GetHistoT0(iSec);
1016 TH2S *hRefRMSmerge = sig->GetHistoRMS(iSec);
1020 TDirectory *dir = hRefQmerge->GetDirectory(); hRefQmerge->SetDirectory(0);
1021 TH2S *hRefQ = GetHistoQ(iSec);
1022 if ( hRefQ ) hRefQ->Add(hRefQmerge);
1024 TH2S *hist = new TH2S(*hRefQmerge);
1025 hist->SetDirectory(0);
1026 fHistoQArray.AddAt(hist, iSec);
1028 hRefQmerge->SetDirectory(dir);
1031 TDirectory *dir = hRefT0merge->GetDirectory(); hRefT0merge->SetDirectory(0);
1032 TH2S *hRefT0 = GetHistoT0(iSec);
1033 if ( hRefT0 ) hRefT0->Add(hRefT0merge);
1035 TH2S *hist = new TH2S(*hRefT0merge);
1036 hist->SetDirectory(0);
1037 fHistoT0Array.AddAt(hist, iSec);
1039 hRefT0merge->SetDirectory(dir);
1041 if ( hRefRMSmerge ){
1042 TDirectory *dir = hRefRMSmerge->GetDirectory(); hRefRMSmerge->SetDirectory(0);
1043 TH2S *hRefRMS = GetHistoRMS(iSec);
1044 if ( hRefRMS ) hRefRMS->Add(hRefRMSmerge);
1046 TH2S *hist = new TH2S(*hRefRMSmerge);
1047 hist->SetDirectory(0);
1048 fHistoRMSArray.AddAt(hist, iSec);
1050 hRefRMSmerge->SetDirectory(dir);
1054 if ( sig->fHMeanTimeSector ){
1055 TDirectory *dir = sig->fHMeanTimeSector->GetDirectory(); sig->fHMeanTimeSector->SetDirectory(0);
1056 if ( fHMeanTimeSector ) fHMeanTimeSector->Add(sig->fHMeanTimeSector);
1058 fHMeanTimeSector = new TH2F(*sig->fHMeanTimeSector);
1059 fHMeanTimeSector->SetDirectory(0);
1061 sig->fHMeanTimeSector->SetDirectory(dir);
1064 //_____________________________________________________________________
1065 void AliTPCCalibPulser::Analyse()
1068 // Calculate calibration constants
1072 TVectorD paramT0(3);
1073 TVectorD paramRMS(3);
1074 TMatrixD dummy(3,3);
1075 //calculate mean time for each sector and mean time for each side
1076 TH1F hMeanTsec("hMeanTsec","hMeanTsec",20*(fLastTimeBin-fFirstTimeBin),fFirstTimeBin,fLastTimeBin);
1077 fVMeanTimeSector.Zero();
1079 for (Int_t iSec=0; iSec<72; ++iSec){
1080 TH2S *hT0 = GetHistoT0(iSec);
1081 if (!hT0 ) continue;
1082 //calculate sector mean T
1083 if ( fHMeanTimeSector ){
1084 Int_t nbinsT = fHMeanTimeSector->GetNbinsX();
1085 Int_t offset = (nbinsT+2)*(iSec+1);
1086 Float_t *arrP=fHMeanTimeSector->GetArray()+offset;
1088 for ( Int_t i=0; i<nbinsT; i++ ) entries+=(Int_t)arrP[i+1];
1089 hMeanTsec.Set(nbinsT+2,arrP);
1090 hMeanTsec.SetEntries(entries);
1092 // truncated mean: remove lower 5% and upper 5%
1093 if ( entries>0 ) AliMathBase::TruncatedMean(&hMeanTsec,¶mT0,0.05,.95);
1094 fVMeanTimeSector[iSec]=paramT0[1];
1097 AliTPCCalROC *rocQ = GetCalRocQ (iSec,kTRUE);
1098 AliTPCCalROC *rocT0 = GetCalRocT0 (iSec,kTRUE);
1099 AliTPCCalROC *rocRMS = GetCalRocRMS(iSec,kTRUE);
1100 AliTPCCalROC *rocOut = GetCalRocOutliers(iSec,kTRUE);
1102 TH2S *hQ = GetHistoQ(iSec);
1103 TH2S *hRMS = GetHistoRMS(iSec);
1105 Short_t *arrayhQ = hQ->GetArray();
1106 Short_t *arrayhT0 = hT0->GetArray();
1107 Short_t *arrayhRMS = hRMS->GetArray();
1109 UInt_t nChannels = fROC->GetNChannels(iSec);
1110 Float_t meanTsec = fVMeanTimeSector[iSec];
1118 for (UInt_t iChannel=0; iChannel<nChannels; ++iChannel){
1120 Float_t cogTime0 = -1000;
1121 Float_t cogQ = -1000;
1122 Float_t cogRMS = -1000;
1125 Int_t offsetQ = (fNbinsQ+2)*(iChannel+1)+1;
1126 Int_t offsetT0 = (fNbinsT0+2)*(iChannel+1)+1;
1127 Int_t offsetRMS = (fNbinsRMS+2)*(iChannel+1)+1;
1129 AliMathBase::FitGaus(arrayhQ+offsetQ,fNbinsQ,fXminQ,fXmaxQ,¶mQ,&dummy);
1130 AliMathBase::FitGaus(arrayhT0+offsetT0,fNbinsT0,fXminT0,fXmaxT0,¶mT0,&dummy);
1131 AliMathBase::FitGaus(arrayhRMS+offsetRMS,fNbinsRMS,fXminRMS,fXmaxRMS,¶mRMS,&dummy);
1133 cogTime0 = paramT0[1];
1134 cogRMS = paramRMS[1];
1136 cogQ = AliMathBase::GetCOG(arrayhQ+offsetQ,fNbinsQ,fXminQ,fXmaxQ);
1137 cogTime0 = AliMathBase::GetCOG(arrayhT0+offsetT0,fNbinsT0,fXminT0,fXmaxT0);
1138 cogRMS = AliMathBase::GetCOG(arrayhRMS+offsetRMS,fNbinsRMS,fXminRMS,fXmaxRMS);
1141 if ( (cogQ < ??) && (cogTime0 > ??) && (cogTime0<??) && ( cogRMS>??) ){
1148 // rocQ->SetValue(iChannel, cogQ*cogQ); // changed to linear scale again
1149 rocQ->SetValue(iChannel, cogQ);
1150 rocT0->SetValue(iChannel, cogTime0+meanTsec); //offset by mean time of the sector
1151 rocRMS->SetValue(iChannel, cogRMS);
1152 rocOut->SetValue(iChannel, cogOut);
1154 if ( GetStreamLevel() > 2 ){
1155 TTreeSRedirector *streamer=GetDebugStreamer();
1157 while ( iChannel > (fROC->GetRowIndexes(iSec)[row]+fROC->GetNPads(iSec,row)-1) ) row++;
1158 pad = iChannel-fROC->GetRowIndexes(iSec)[row];
1159 padc = pad-(fROC->GetNPads(iSec,row)/2);
1161 (*streamer) << "DataEnd" <<
1162 "Sector=" << iSec <<
1166 "PadSec=" << iChannel <<
1168 "T0=" << cogTime0 <<
1179 //_____________________________________________________________________
1180 //_________________________ Test Functions ___________________________
1181 //_____________________________________________________________________
1182 TObjArray* AliTPCCalibPulser::TestBinning()
1185 // Function to test the binning of the reference histograms
1186 // type: T0, Q or RMS
1187 // mode: 0 - number of filled bins per channel
1188 // 1 - number of empty bins between filled bins in one ROC
1189 // returns TObjArray with the test histograms type*2+mode:
1190 // position 0 = T0,0 ; 1 = T0,1 ; 2 = Q,0 ...
1193 TObjArray *histArray = new TObjArray(6);
1194 const Char_t *type[] = {"T0","Q","RMS"};
1195 Int_t fNbins[3] = {fNbinsT0,fNbinsQ,fNbinsRMS};
1197 for (Int_t itype = 0; itype<3; ++itype){
1198 for (Int_t imode=0; imode<2; ++imode){
1199 Int_t icount = itype*2+imode;
1200 histArray->AddAt(new TH1F(Form("hTestBinning%s%d",type[itype],imode),
1201 Form("Test Binning of '%s', mode - %d",type[itype],imode),
1210 for (Int_t itype = 0; itype<3; ++itype){
1211 for (Int_t iSec=0; iSec<72; ++iSec){
1212 if ( itype == 0 ) hRef = GetHistoT0(iSec);
1213 if ( itype == 1 ) hRef = GetHistoQ(iSec);
1214 if ( itype == 2 ) hRef = GetHistoRMS(iSec);
1215 if ( hRef == 0x0 ) continue;
1216 array = (hRef->GetArray());
1217 UInt_t nChannels = fROC->GetNChannels(iSec);
1220 for (UInt_t iChannel=0; iChannel<nChannels; ++iChannel){
1222 Int_t offset = (fNbins[itype]+2)*(iChannel+1)+1;
1225 for (Int_t iBin=0; iBin<fNbins[itype]; ++iBin){
1226 if ( array[offset+iBin]>0 ) {
1228 if ( c1 && c2 ) nempty++;
1231 else if ( c1 ) c2 = 1;
1234 ((TH1F*)histArray->At(itype*2))->Fill(nfilled);
1236 ((TH1F*)histArray->At(itype*2+1))->Fill(iSec,nempty);