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 "AliTPCCalROC.h"
186 #include "AliTPCCalPad.h"
187 #include "AliTPCROC.h"
188 #include "AliTPCParam.h"
189 #include "AliTPCCalibPulser.h"
190 #include "AliTPCcalibDB.h"
191 #include "AliMathBase.h"
193 #include "TTreeStream.h"
201 ClassImp(AliTPCCalibPulser)
203 AliTPCCalibPulser::AliTPCCalibPulser() :
204 AliTPCCalibRawBase(),
216 fIsZeroSuppressed(kFALSE),
218 fParam(new AliTPCParam),
227 fCalRocArrayOutliers(72),
231 fHMeanTimeSector(0x0),
232 fVMeanTimeSector(72),
233 fPadTimesArrayEvent(72),
235 fPadRMSArrayEvent(72),
236 fPadPedestalArrayEvent(72),
247 fVTime0OffsetCounter(72)
250 // AliTPCSignal default constructor
252 SetNameTitle("AliTPCCalibPulser","AliTPCCalibPulser");
257 //_____________________________________________________________________
258 AliTPCCalibPulser::AliTPCCalibPulser(const AliTPCCalibPulser &sig) :
259 AliTPCCalibRawBase(sig),
260 fNbinsT0(sig.fNbinsT0),
261 fXminT0(sig.fXminT0),
262 fXmaxT0(sig.fXmaxT0),
263 fNbinsQ(sig.fNbinsQ),
266 fNbinsRMS(sig.fNbinsRMS),
267 fXminRMS(sig.fXminRMS),
268 fXmaxRMS(sig.fXmaxRMS),
269 fPeakIntMinus(sig.fPeakIntMinus),
270 fPeakIntPlus(sig.fPeakIntPlus),
271 fIsZeroSuppressed(sig.fIsZeroSuppressed),
273 fParam(new AliTPCParam),
282 fCalRocArrayOutliers(72),
286 fHMeanTimeSector(0x0),
287 fVMeanTimeSector(72),
288 fPadTimesArrayEvent(72),
290 fPadRMSArrayEvent(72),
291 fPadPedestalArrayEvent(72),
302 fVTime0OffsetCounter(72)
305 // AliTPCSignal default constructor
308 for (Int_t iSec = 0; iSec < 72; ++iSec){
309 const AliTPCCalROC *calQ = (AliTPCCalROC*)sig.fCalRocArrayQ.UncheckedAt(iSec);
310 const AliTPCCalROC *calT0 = (AliTPCCalROC*)sig.fCalRocArrayT0.UncheckedAt(iSec);
311 const AliTPCCalROC *calRMS = (AliTPCCalROC*)sig.fCalRocArrayRMS.UncheckedAt(iSec);
312 const AliTPCCalROC *calOut = (AliTPCCalROC*)sig.fCalRocArrayOutliers.UncheckedAt(iSec);
314 const TH2S *hQ = (TH2S*)sig.fHistoQArray.UncheckedAt(iSec);
315 const TH2S *hT0 = (TH2S*)sig.fHistoT0Array.UncheckedAt(iSec);
316 const TH2S *hRMS = (TH2S*)sig.fHistoRMSArray.UncheckedAt(iSec);
318 if ( calQ != 0x0 ) fCalRocArrayQ.AddAt(new AliTPCCalROC(*calQ), iSec);
319 if ( calT0 != 0x0 ) fCalRocArrayT0.AddAt(new AliTPCCalROC(*calT0), iSec);
320 if ( calRMS != 0x0 ) fCalRocArrayRMS.AddAt(new AliTPCCalROC(*calRMS), iSec);
321 if ( calOut != 0x0 ) fCalRocArrayOutliers.AddAt(new AliTPCCalROC(*calOut), iSec);
324 TH2S *hNew = new TH2S(*hQ);
325 hNew->SetDirectory(0);
326 fHistoQArray.AddAt(hNew,iSec);
329 TH2S *hNew = new TH2S(*hT0);
330 hNew->SetDirectory(0);
331 fHistoQArray.AddAt(hNew,iSec);
334 TH2S *hNew = new TH2S(*hRMS);
335 hNew->SetDirectory(0);
336 fHistoQArray.AddAt(hNew,iSec);
338 fVMeanTimeSector[iSec]=sig.fVMeanTimeSector[iSec];
341 if ( sig.fHMeanTimeSector ) fHMeanTimeSector=(TH2F*)sig.fHMeanTimeSector->Clone();
344 AliTPCCalibPulser::AliTPCCalibPulser(const TMap *config) :
345 AliTPCCalibRawBase(),
357 fIsZeroSuppressed(kFALSE),
359 fParam(new AliTPCParam),
368 fCalRocArrayOutliers(72),
372 fHMeanTimeSector(0x0),
373 fVMeanTimeSector(72),
374 fPadTimesArrayEvent(72),
376 fPadRMSArrayEvent(72),
377 fPadPedestalArrayEvent(72),
388 fVTime0OffsetCounter(72)
391 // This constructor uses a TMap for setting some parametes
393 SetNameTitle("AliTPCCalibPulser","AliTPCCalibPulser");
396 if (config->GetValue("FirstTimeBin")) fFirstTimeBin = ((TObjString*)config->GetValue("FirstTimeBin"))->GetString().Atoi();
397 if (config->GetValue("LastTimeBin")) fLastTimeBin = ((TObjString*)config->GetValue("LastTimeBin"))->GetString().Atoi();
398 if (config->GetValue("NbinsT0")) fNbinsT0 = ((TObjString*)config->GetValue("NbinsT0"))->GetString().Atoi();
399 if (config->GetValue("XminT0")) fXminT0 = ((TObjString*)config->GetValue("XminT0"))->GetString().Atof();
400 if (config->GetValue("XmaxT0")) fXmaxT0 = ((TObjString*)config->GetValue("XmaxT0"))->GetString().Atof();
401 if (config->GetValue("NbinsQ")) fNbinsQ = ((TObjString*)config->GetValue("NbinsQ"))->GetString().Atoi();
402 if (config->GetValue("XminQ")) fXminQ = ((TObjString*)config->GetValue("XminQ"))->GetString().Atof();
403 if (config->GetValue("XmaxQ")) fXmaxQ = ((TObjString*)config->GetValue("XmaxQ"))->GetString().Atof();
404 if (config->GetValue("NbinsRMS")) fNbinsRMS = ((TObjString*)config->GetValue("NbinsRMS"))->GetString().Atoi();
405 if (config->GetValue("XminRMS")) fXminRMS = ((TObjString*)config->GetValue("XminRMS"))->GetString().Atof();
406 if (config->GetValue("XmaxRMS")) fXmaxRMS = ((TObjString*)config->GetValue("XmaxRMS"))->GetString().Atof();
407 if (config->GetValue("PeakIntMinus")) fPeakIntMinus = (Int_t)((TObjString*)config->GetValue("PeakIntMinus"))->GetString().Atof();
408 if (config->GetValue("PeakIntPlus")) fPeakIntPlus = (Int_t)((TObjString*)config->GetValue("PeakIntPlus"))->GetString().Atof();
409 if (config->GetValue("IsZeroSuppressed")) fIsZeroSuppressed = (Bool_t)((TObjString*)config->GetValue("IsZeroSuppressed"))->GetString().Atoi();
413 //_____________________________________________________________________
414 AliTPCCalibPulser& AliTPCCalibPulser::operator = (const AliTPCCalibPulser &source)
417 // assignment operator
419 if (&source == this) return *this;
420 new (this) AliTPCCalibPulser(source);
424 //_____________________________________________________________________
425 AliTPCCalibPulser::~AliTPCCalibPulser()
434 void AliTPCCalibPulser::Reset()
437 // Delete all information: Arrays, Histograms, CalRoc objects
439 fCalRocArrayT0.Delete();
440 fCalRocArrayQ.Delete();
441 fCalRocArrayRMS.Delete();
442 fCalRocArrayOutliers.Delete();
444 fHistoQArray.Delete();
445 fHistoT0Array.Delete();
446 fHistoRMSArray.Delete();
448 fPadTimesArrayEvent.Delete();
449 fPadQArrayEvent.Delete();
450 fPadRMSArrayEvent.Delete();
451 fPadPedestalArrayEvent.Delete();
453 if (fHMeanTimeSector) delete fHMeanTimeSector;
455 //_____________________________________________________________________
456 Int_t AliTPCCalibPulser::Update(const Int_t icsector,
459 const Int_t icTimeBin,
460 const Float_t csignal)
463 // Signal filling methode on the fly pedestal and time offset correction if necessary.
464 // no extra analysis necessary. Assumes knowledge of the signal shape!
465 // assumes that it is looped over consecutive time bins of one pad
468 if (icRow<0) return 0;
469 if (icPad<0) return 0;
470 if (icTimeBin<0) return 0;
471 if ( (icTimeBin>fLastTimeBin) || (icTimeBin<fFirstTimeBin) ) return 0;
473 if ( icRow<0 || icPad<0 ){
474 AliWarning("Wrong Pad or Row number, skipping!");
478 Int_t iChannel = fROC->GetRowIndexes(icsector)[icRow]+icPad; // global pad position in sector
480 //init first pad and sector in this event
481 if ( fCurrentChannel == -1 ) {
482 fCurrentChannel = iChannel;
483 fCurrentSector = icsector;
488 //process last pad if we change to a new one
489 if ( iChannel != fCurrentChannel ){
491 fLastSector=fCurrentSector;
492 fCurrentChannel = iChannel;
493 fCurrentSector = icsector;
498 //fill signals for current pad
499 fPadSignal[icTimeBin]=csignal;
500 if ( csignal > fMaxPadSignal ){
501 fMaxPadSignal = csignal;
502 fMaxTimeBin = icTimeBin;
506 //_____________________________________________________________________
507 void AliTPCCalibPulser::FindPedestal(Float_t part)
510 // find pedestal and noise for the current pad. Use either database or
511 // truncated mean with part*100%
513 Bool_t noPedestal = kTRUE;;
514 if (fPedestalTPC&&fPadNoiseTPC){
515 //use pedestal database
516 //only load new pedestals if the sector has changed
517 if ( fCurrentSector!=fLastSector ){
518 fPedestalROC = fPedestalTPC->GetCalROC(fCurrentSector);
519 fPadNoiseROC = fPadNoiseTPC->GetCalROC(fCurrentSector);
522 if ( fPedestalROC&&fPadNoiseROC ){
523 fPadPedestal = fPedestalROC->GetValue(fCurrentChannel);
524 fPadNoise = fPadNoiseROC->GetValue(fCurrentChannel);
530 //if we are not running with pedestal database, or for the current sector there is no information
531 //available, calculate the pedestal and noise on the fly
533 const Int_t kPedMax = 100; //maximum pedestal value
542 UShort_t histo[kPedMax];
543 memset(histo,0,kPedMax*sizeof(UShort_t));
545 for (Int_t i=fFirstTimeBin; i<=fLastTimeBin; ++i){
546 padSignal = fPadSignal.GetMatrixArray()[i];
547 if (padSignal<=0) continue;
548 if (padSignal>max && i>10) {
552 if (padSignal>kPedMax-1) continue;
553 histo[Int_t(padSignal+0.5)]++;
557 for (Int_t i=1; i<kPedMax; ++i){
558 if (count1<count0*0.5) median=i;
563 // what if by chance histo[median] == 0 ?!?
564 Float_t count=histo[median] ,mean=histo[median]*median, rms=histo[median]*median*median ;
566 for (Int_t idelta=1; idelta<10; ++idelta){
567 if (median-idelta<=0) continue;
568 if (median+idelta>kPedMax) continue;
569 if (count<part*count1){
570 count+=histo[median-idelta];
571 mean +=histo[median-idelta]*(median-idelta);
572 rms +=histo[median-idelta]*(median-idelta)*(median-idelta);
573 count+=histo[median+idelta];
574 mean +=histo[median+idelta]*(median+idelta);
575 rms +=histo[median+idelta]*(median+idelta)*(median+idelta);
582 rms = TMath::Sqrt(TMath::Abs(rms/count-mean*mean));
587 fPadPedestal*=(Float_t)(!fIsZeroSuppressed);
589 //_____________________________________________________________________
590 void AliTPCCalibPulser::FindPulserSignal(TVectorD ¶m, Float_t &qSum)
593 // Find position, signal width and height of the CE signal (last signal)
594 // param[0] = Qmax, param[1] = mean time, param[2] = rms;
595 // maxima: array of local maxima of the pad signal use the one closest to the mean CE position
598 Float_t ceQmax =0, ceQsum=0, ceTime=0, ceRMS=0;
599 Int_t cemaxpos = fMaxTimeBin;
600 Float_t ceSumThreshold = 10.*TMath::Max(fPadNoise,Float_t(1.)); // threshold for the signal sum
601 Float_t ceMaxThreshold = 5.*TMath::Max(fPadNoise,Float_t(1.)); // threshold for the signal max
602 const Int_t kCemin = fPeakIntMinus; // range for the analysis of the ce signal +- channels from the peak
603 const Int_t kCemax = fPeakIntPlus;
610 ceQmax = fPadSignal.GetMatrixArray()[cemaxpos]-fPadPedestal;
611 if ( ceQmax<ceMaxThreshold ) return;
612 for (Int_t i=cemaxpos-kCemin; i<=cemaxpos+kCemax; ++i){
613 Float_t signal = fPadSignal.GetMatrixArray()[i]-fPadPedestal;
614 if ( (i>fFirstTimeBin) && (i<fLastTimeBin) && (signal>0) ){
615 ceTime+=signal*(i+0.5);
616 ceRMS +=signal*(i+0.5)*(i+0.5);
621 if (ceQsum>ceSumThreshold) {
623 ceRMS = TMath::Sqrt(TMath::Abs(ceRMS/ceQsum-ceTime*ceTime));
624 ceTime-=GetL1PhaseTB();
625 //only fill the Time0Offset if pad was not marked as an outlier!
627 //skip edge pads for calculating the mean time
628 if ( !IsEdgePad(fCurrentSector,fCurrentRow,fCurrentPad) ){
629 fVTime0Offset.GetMatrixArray()[fCurrentSector]+=ceTime; // mean time for each sector
630 fVTime0OffsetCounter.GetMatrixArray()[fCurrentSector]++;
631 GetHistoTSec()->Fill(ceTime,fCurrentSector);
634 if ( !(fOutliers->GetCalROC(fCurrentSector)->GetValue(fCurrentChannel)) ){
635 fVTime0Offset.GetMatrixArray()[fCurrentSector]+=ceTime; // mean time for each sector
636 fVTime0OffsetCounter.GetMatrixArray()[fCurrentSector]++;
640 //Normalise Q to the 'cell-size': The wire density is the same in the IROC and OROC, therefore the
641 // the pick-up signal should scale with the pad area. In addition
642 // the signal should decrease with the wire distance (4mm in IROC, 6mm in OROC),
643 // ratio 2/3. The pad area we express in mm2 (factor 100). We normalise the signal
644 // to the OROC signal (factor 2/3 for the IROCs).
645 Float_t norm = fParam->GetPadPitchWidth(fCurrentSector)*fParam->GetPadPitchLength(fCurrentSector,fCurrentRow)*100;
646 if ( fCurrentSector<fParam->GetNInnerSector() ) norm*=3./2.;
660 //_____________________________________________________________________
661 void AliTPCCalibPulser::ProcessPad()
664 // Process data of current pad
670 FindPulserSignal(param, qSum);
672 Double_t meanT = param[1];
673 Double_t sigmaT = param[2];
676 //Fill Event T0 counter
677 (*GetPadTimesEvent(fCurrentSector,kTRUE)).GetMatrixArray()[fCurrentChannel] = meanT;
680 // GetHistoQ(fCurrentSector,kTRUE)->Fill( TMath::Sqrt(qSum), fCurrentChannel ); //use linear scale, needs also a change in the Analyse funciton.
681 GetHistoQ(fCurrentSector,kTRUE)->Fill( qSum, fCurrentChannel );
684 GetHistoRMS(fCurrentSector,kTRUE)->Fill( sigmaT, fCurrentChannel );
687 //Fill debugging info
688 if ( GetStreamLevel()>0 ){
689 TTreeSRedirector *streamer=GetDebugStreamer();
690 if ( GetStreamLevel() == 1 ){
692 Int_t padc = fCurrentPad-(fROC->GetNPads(fCurrentSector,fCurrentRow)/2);
693 (*streamer) << "PadSignals" <<
694 "Event=" <<fNevents <<
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=" << fNevents <<
755 "Sector="<< sector <<
759 "PadSec="<< channel <<
772 //_____________________________________________________________________
773 TH2S* AliTPCCalibPulser::GetHisto(Int_t sector, TObjArray *arr,
774 Int_t nbinsY, Float_t ymin, Float_t ymax,
775 const Char_t *type, Bool_t force)
778 // return pointer to Q histogram
779 // if force is true create a new histogram if it doesn't exist allready
781 if ( !force || arr->UncheckedAt(sector) )
782 return (TH2S*)arr->UncheckedAt(sector);
784 // if we are forced and histogram doesn't yes exist create it
785 // new histogram with Q calib information. One value for each pad!
786 TH2S* hist = new TH2S(Form("hCalib%s%.2d",type,sector),Form("%s calibration histogram sector %.2d",type,sector),
788 fROC->GetNChannels(sector),0,fROC->GetNChannels(sector));
789 hist->SetDirectory(0);
790 arr->AddAt(hist,sector);
793 //_____________________________________________________________________
794 TH2S* AliTPCCalibPulser::GetHistoT0(Int_t sector, Bool_t force)
797 // return pointer to T0 histogram
798 // if force is true create a new histogram if it doesn't exist allready
800 TObjArray *arr = &fHistoT0Array;
801 return GetHisto(sector, arr, fNbinsT0, fXminT0, fXmaxT0, "T0", force);
803 //_____________________________________________________________________
804 TH2S* AliTPCCalibPulser::GetHistoQ(Int_t sector, Bool_t force)
807 // return pointer to Q histogram
808 // if force is true create a new histogram if it doesn't exist allready
810 TObjArray *arr = &fHistoQArray;
811 return GetHisto(sector, arr, fNbinsQ, fXminQ, fXmaxQ, "Q", force);
813 //_____________________________________________________________________
814 TH2S* AliTPCCalibPulser::GetHistoRMS(Int_t sector, Bool_t force)
817 // return pointer to Q histogram
818 // if force is true create a new histogram if it doesn't exist allready
820 TObjArray *arr = &fHistoRMSArray;
821 return GetHisto(sector, arr, fNbinsRMS, fXminRMS, fXmaxRMS, "RMS", force);
823 //_____________________________________________________________________
824 TH2F* AliTPCCalibPulser::GetHistoTSec()
827 // return the pointer to the abs time distribution per sector
828 // create it if it does not exist
830 if ( !fHMeanTimeSector ) //!!!if you change the binning here, you should also change it in the Analyse Function!!
831 fHMeanTimeSector = new TH2F("fHMeanTimeSector","Abs mean time per sector",
832 20*(fLastTimeBin-fFirstTimeBin), fFirstTimeBin, fLastTimeBin,
834 return fHMeanTimeSector;
836 //_____________________________________________________________________
837 TVectorF* AliTPCCalibPulser::GetPadInfoEvent(Int_t sector, TObjArray *arr, Bool_t force)
840 // return pointer to Pad Info from 'arr' for the current event and sector
841 // if force is true create it if it doesn't exist allready
843 if ( !force || arr->UncheckedAt(sector) )
844 return (TVectorF*)arr->UncheckedAt(sector);
846 TVectorF *vect = new TVectorF(fROC->GetNChannels(sector));
847 arr->AddAt(vect,sector);
850 //_____________________________________________________________________
851 TVectorF* AliTPCCalibPulser::GetPadTimesEvent(Int_t sector, Bool_t force)
854 // return pointer to Pad Times Array for the current event and sector
855 // if force is true create it if it doesn't exist allready
857 TObjArray *arr = &fPadTimesArrayEvent;
858 return GetPadInfoEvent(sector,arr,force);
860 //_____________________________________________________________________
861 TVectorF* AliTPCCalibPulser::GetPadQEvent(Int_t sector, Bool_t force)
864 // return pointer to Pad Q Array for the current event and sector
865 // if force is true create it if it doesn't exist allready
866 // for debugging purposes only
869 TObjArray *arr = &fPadQArrayEvent;
870 return GetPadInfoEvent(sector,arr,force);
872 //_____________________________________________________________________
873 TVectorF* AliTPCCalibPulser::GetPadRMSEvent(Int_t sector, Bool_t force)
876 // return pointer to Pad RMS Array for the current event and sector
877 // if force is true create it if it doesn't exist allready
878 // for debugging purposes only
880 TObjArray *arr = &fPadRMSArrayEvent;
881 return GetPadInfoEvent(sector,arr,force);
883 //_____________________________________________________________________
884 TVectorF* AliTPCCalibPulser::GetPadPedestalEvent(Int_t sector, Bool_t force)
887 // return pointer to Pad RMS Array for the current event and sector
888 // if force is true create it if it doesn't exist allready
889 // for debugging purposes only
891 TObjArray *arr = &fPadPedestalArrayEvent;
892 return GetPadInfoEvent(sector,arr,force);
894 //_____________________________________________________________________
895 AliTPCCalROC* AliTPCCalibPulser::GetCalRoc(Int_t sector, TObjArray* arr, Bool_t force) const
898 // return pointer to ROC Calibration
899 // if force is true create a new histogram if it doesn't exist allready
901 if ( !force || arr->UncheckedAt(sector) )
902 return (AliTPCCalROC*)arr->UncheckedAt(sector);
904 // if we are forced and histogram doesn't yes exist create it
906 // new AliTPCCalROC for T0 information. One value for each pad!
907 AliTPCCalROC *croc = new AliTPCCalROC(sector);
908 arr->AddAt(croc,sector);
911 //_____________________________________________________________________
912 AliTPCCalROC* AliTPCCalibPulser::GetCalRocT0(Int_t sector, Bool_t force)
915 // return pointer to Carge ROC Calibration
916 // if force is true create a new histogram if it doesn't exist allready
918 TObjArray *arr = &fCalRocArrayT0;
919 return GetCalRoc(sector, arr, force);
921 //_____________________________________________________________________
922 AliTPCCalROC* AliTPCCalibPulser::GetCalRocQ(Int_t sector, Bool_t force)
925 // return pointer to T0 ROC Calibration
926 // if force is true create a new histogram if it doesn't exist allready
928 TObjArray *arr = &fCalRocArrayQ;
929 return GetCalRoc(sector, arr, force);
931 //_____________________________________________________________________
932 AliTPCCalROC* AliTPCCalibPulser::GetCalRocRMS(Int_t sector, Bool_t force)
935 // return pointer to signal width ROC Calibration
936 // if force is true create a new histogram if it doesn't exist allready
938 TObjArray *arr = &fCalRocArrayRMS;
939 return GetCalRoc(sector, arr, force);
941 //_____________________________________________________________________
942 AliTPCCalROC* AliTPCCalibPulser::GetCalRocOutliers(Int_t sector, Bool_t force)
945 // return pointer to Outliers
946 // if force is true create a new histogram if it doesn't exist allready
948 TObjArray *arr = &fCalRocArrayOutliers;
949 return GetCalRoc(sector, arr, force);
951 //_____________________________________________________________________
952 void AliTPCCalibPulser::ResetEvent()
955 // Reset global counters -- Should be called before each event is processed
965 fPadTimesArrayEvent.Delete();
967 fPadQArrayEvent.Delete();
968 fPadRMSArrayEvent.Delete();
969 fPadPedestalArrayEvent.Delete();
971 for ( Int_t i=0; i<72; ++i ){
973 fVTime0OffsetCounter[i]=0;
976 //_____________________________________________________________________
977 void AliTPCCalibPulser::ResetPad()
980 // Reset pad infos -- Should be called after a pad has been processed
982 for (Int_t i=fFirstTimeBin; i<fLastTimeBin+1; ++i)
989 //_____________________________________________________________________
990 Bool_t AliTPCCalibPulser::IsEdgePad(Int_t sector, Int_t row, Int_t pad)
993 // return true if pad is on the edge of a row
996 Int_t edge2 = fROC->GetNPads(sector,row)-1;
997 if ( pad == edge1 || pad == edge2 ) return kTRUE;
1001 //_____________________________________________________________________
1002 void AliTPCCalibPulser::Merge(AliTPCCalibPulser * const sig)
1005 // Merge reference histograms of sig to the current AliTPCCalibPulser
1010 for (Int_t iSec=0; iSec<72; ++iSec){
1011 TH2S *hRefQmerge = sig->GetHistoQ(iSec);
1012 TH2S *hRefT0merge = sig->GetHistoT0(iSec);
1013 TH2S *hRefRMSmerge = sig->GetHistoRMS(iSec);
1017 TDirectory *dir = hRefQmerge->GetDirectory(); hRefQmerge->SetDirectory(0);
1018 TH2S *hRefQ = GetHistoQ(iSec);
1019 if ( hRefQ ) hRefQ->Add(hRefQmerge);
1021 TH2S *hist = new TH2S(*hRefQmerge);
1022 hist->SetDirectory(0);
1023 fHistoQArray.AddAt(hist, iSec);
1025 hRefQmerge->SetDirectory(dir);
1028 TDirectory *dir = hRefT0merge->GetDirectory(); hRefT0merge->SetDirectory(0);
1029 TH2S *hRefT0 = GetHistoT0(iSec);
1030 if ( hRefT0 ) hRefT0->Add(hRefT0merge);
1032 TH2S *hist = new TH2S(*hRefT0merge);
1033 hist->SetDirectory(0);
1034 fHistoT0Array.AddAt(hist, iSec);
1036 hRefT0merge->SetDirectory(dir);
1038 if ( hRefRMSmerge ){
1039 TDirectory *dir = hRefRMSmerge->GetDirectory(); hRefRMSmerge->SetDirectory(0);
1040 TH2S *hRefRMS = GetHistoRMS(iSec);
1041 if ( hRefRMS ) hRefRMS->Add(hRefRMSmerge);
1043 TH2S *hist = new TH2S(*hRefRMSmerge);
1044 hist->SetDirectory(0);
1045 fHistoRMSArray.AddAt(hist, iSec);
1047 hRefRMSmerge->SetDirectory(dir);
1051 if ( sig->fHMeanTimeSector ){
1052 TDirectory *dir = sig->fHMeanTimeSector->GetDirectory(); sig->fHMeanTimeSector->SetDirectory(0);
1053 if ( fHMeanTimeSector ) fHMeanTimeSector->Add(sig->fHMeanTimeSector);
1055 fHMeanTimeSector = new TH2F(*sig->fHMeanTimeSector);
1056 fHMeanTimeSector->SetDirectory(0);
1058 sig->fHMeanTimeSector->SetDirectory(dir);
1063 //_____________________________________________________________________
1064 Long64_t AliTPCCalibPulser::Merge(TCollection * const list)
1067 // Merge all objects of this type in list
1073 AliTPCCalibPulser *ce=0;
1076 while ( (o=next()) ){
1077 ce=dynamic_cast<AliTPCCalibPulser*>(o);
1087 //_____________________________________________________________________
1088 void AliTPCCalibPulser::Analyse()
1091 // Calculate calibration constants
1095 TVectorD paramT0(3);
1096 TVectorD paramRMS(3);
1097 TMatrixD dummy(3,3);
1098 //calculate mean time for each sector and mean time for each side
1099 TH1F hMeanTsec("hMeanTsec","hMeanTsec",20*(fLastTimeBin-fFirstTimeBin),fFirstTimeBin,fLastTimeBin);
1100 fVMeanTimeSector.Zero();
1102 for (Int_t iSec=0; iSec<72; ++iSec){
1103 TH2S *hT0 = GetHistoT0(iSec);
1104 if (!hT0 ) continue;
1105 //calculate sector mean T
1106 if ( fHMeanTimeSector ){
1107 Int_t nbinsT = fHMeanTimeSector->GetNbinsX();
1108 Int_t offset = (nbinsT+2)*(iSec+1);
1109 Float_t *arrP=fHMeanTimeSector->GetArray()+offset;
1111 for ( Int_t i=0; i<nbinsT; i++ ) entries+=(Int_t)arrP[i+1];
1112 hMeanTsec.Set(nbinsT+2,arrP);
1113 hMeanTsec.SetEntries(entries);
1115 // truncated mean: remove lower 5% and upper 5%
1116 if ( entries>0 ) AliMathBase::TruncatedMean(&hMeanTsec,¶mT0,0.05,.95);
1117 fVMeanTimeSector[iSec]=paramT0[1];
1120 AliTPCCalROC *rocQ = GetCalRocQ (iSec,kTRUE);
1121 AliTPCCalROC *rocT0 = GetCalRocT0 (iSec,kTRUE);
1122 AliTPCCalROC *rocRMS = GetCalRocRMS(iSec,kTRUE);
1123 AliTPCCalROC *rocOut = GetCalRocOutliers(iSec,kTRUE);
1125 TH2S *hQ = GetHistoQ(iSec);
1126 TH2S *hRMS = GetHistoRMS(iSec);
1128 Short_t *arrayhQ = hQ->GetArray();
1129 Short_t *arrayhT0 = hT0->GetArray();
1130 Short_t *arrayhRMS = hRMS->GetArray();
1132 UInt_t nChannels = fROC->GetNChannels(iSec);
1133 Float_t meanTsec = fVMeanTimeSector[iSec];
1141 for (UInt_t iChannel=0; iChannel<nChannels; ++iChannel){
1143 Float_t cogTime0 = -1000;
1144 Float_t cogQ = -1000;
1145 Float_t cogRMS = -1000;
1148 Int_t offsetQ = (fNbinsQ+2)*(iChannel+1)+1;
1149 Int_t offsetT0 = (fNbinsT0+2)*(iChannel+1)+1;
1150 Int_t offsetRMS = (fNbinsRMS+2)*(iChannel+1)+1;
1152 AliMathBase::FitGaus(arrayhQ+offsetQ,fNbinsQ,fXminQ,fXmaxQ,¶mQ,&dummy);
1153 AliMathBase::FitGaus(arrayhT0+offsetT0,fNbinsT0,fXminT0,fXmaxT0,¶mT0,&dummy);
1154 AliMathBase::FitGaus(arrayhRMS+offsetRMS,fNbinsRMS,fXminRMS,fXmaxRMS,¶mRMS,&dummy);
1156 cogTime0 = paramT0[1];
1157 cogRMS = paramRMS[1];
1159 cogQ = AliMathBase::GetCOG(arrayhQ+offsetQ,fNbinsQ,fXminQ,fXmaxQ);
1160 cogTime0 = AliMathBase::GetCOG(arrayhT0+offsetT0,fNbinsT0,fXminT0,fXmaxT0);
1161 cogRMS = AliMathBase::GetCOG(arrayhRMS+offsetRMS,fNbinsRMS,fXminRMS,fXmaxRMS);
1164 if ( (cogQ < ??) && (cogTime0 > ??) && (cogTime0<??) && ( cogRMS>??) ){
1171 // rocQ->SetValue(iChannel, cogQ*cogQ); // changed to linear scale again
1172 rocQ->SetValue(iChannel, cogQ);
1173 rocT0->SetValue(iChannel, cogTime0+meanTsec); //offset by mean time of the sector
1174 rocRMS->SetValue(iChannel, cogRMS);
1175 rocOut->SetValue(iChannel, cogOut);
1177 // in case a channel has no data set the value to 0
1178 if (TMath::Abs(cogTime0-fXminT0)<1e-10){
1179 rocQ->SetValue(iChannel, 0);
1180 rocT0->SetValue(iChannel, 0); //offset by mean time of the sector
1181 rocRMS->SetValue(iChannel, 0);
1185 if ( GetStreamLevel() > 2 ){
1186 TTreeSRedirector *streamer=GetDebugStreamer();
1188 while ( iChannel > (fROC->GetRowIndexes(iSec)[row]+fROC->GetNPads(iSec,row)-1) ) row++;
1189 pad = iChannel-fROC->GetRowIndexes(iSec)[row];
1190 padc = pad-(fROC->GetNPads(iSec,row)/2);
1192 (*streamer) << "DataEnd" <<
1193 "Sector=" << iSec <<
1197 "PadSec=" << iChannel <<
1199 "T0=" << cogTime0 <<
1210 //_____________________________________________________________________
1211 //_________________________ Test Functions ___________________________
1212 //_____________________________________________________________________
1213 TObjArray* AliTPCCalibPulser::TestBinning()
1216 // Function to test the binning of the reference histograms
1217 // type: T0, Q or RMS
1218 // mode: 0 - number of filled bins per channel
1219 // 1 - number of empty bins between filled bins in one ROC
1220 // returns TObjArray with the test histograms type*2+mode:
1221 // position 0 = T0,0 ; 1 = T0,1 ; 2 = Q,0 ...
1224 TObjArray *histArray = new TObjArray(6);
1225 const Char_t *type[] = {"T0","Q","RMS"};
1226 Int_t fNbins[3] = {fNbinsT0,fNbinsQ,fNbinsRMS};
1228 for (Int_t itype = 0; itype<3; ++itype){
1229 for (Int_t imode=0; imode<2; ++imode){
1230 Int_t icount = itype*2+imode;
1231 histArray->AddAt(new TH1F(Form("hTestBinning%s%d",type[itype],imode),
1232 Form("Test Binning of '%s', mode - %d",type[itype],imode),
1241 for (Int_t itype = 0; itype<3; ++itype){
1242 for (Int_t iSec=0; iSec<72; ++iSec){
1243 if ( itype == 0 ) hRef = GetHistoT0(iSec);
1244 if ( itype == 1 ) hRef = GetHistoQ(iSec);
1245 if ( itype == 2 ) hRef = GetHistoRMS(iSec);
1246 if ( hRef == 0x0 ) continue;
1247 array = (hRef->GetArray());
1248 UInt_t nChannels = fROC->GetNChannels(iSec);
1251 for (UInt_t iChannel=0; iChannel<nChannels; ++iChannel){
1253 Int_t offset = (fNbins[itype]+2)*(iChannel+1)+1;
1256 for (Int_t iBin=0; iBin<fNbins[itype]; ++iBin){
1257 if ( array[offset+iBin]>0 ) {
1259 if ( c1 && c2 ) nempty++;
1262 else if ( c1 ) c2 = 1;
1265 ((TH1F*)histArray->At(itype*2))->Fill(nfilled);
1267 ((TH1F*)histArray->At(itype*2+1))->Fill(iSec,nempty);