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 Raw drift velocity and Altro L1 Phase calibration //
22 // Origin: Jens Wiechula, J.Wiechula@gsi.de //
24 ////////////////////////////////////////////////////////////////////////////////////////
27 // *************************************************************************************
28 // * Class Description *
29 // *************************************************************************************
33 TFile f("CalibAltro.root");
34 AliTPCCalibRaw *al=(AliTPCCalibRaw*)f.Get(f.GetListOfKeys()->At(0)->GetName())
36 TCanvas *c1=(TCanvas*)gROOT->FindObject("c1");
37 if (!c1) c1=new TCanvas("c1","c1");
40 TH2F h2f("h2","h2;RCU;fail",216,0,216,al->GetNevents(),0,al->GetNevents());
44 TVectorF *v=al->GetALTROL1PhaseFailEventsRCU(i);
46 for (iev=0;iev<al->GetNevents();++iev) {
47 h2f->SetBinContent(i+1,iev+1,(*v)(iev));
50 // h.SetLineColor(i/216.*50+50);
51 // ((TH1F*)h.Clone(Form("h%d",i)))->Draw(first?"":"same");
69 #include <TObjString.h>
70 #include <TTimeStamp.h>
73 #include "AliTPCCalROC.h"
74 #include "AliAltroRawStream.h"
77 #include "AliTPCCalibRaw.h"
79 ClassImp(AliTPCCalibRaw)
81 AliTPCCalibRaw::AliTPCCalibRaw() :
86 fNFailL1PhaseEvent(0),
88 fNSecTime(600), //default 10 minutes
89 fNBinsTime(60), //default 60*10 minutes = 10 hours
90 fPadProcessed(kFALSE),
102 fArrCurrentPhaseDist(4),
103 fArrCurrentPhase(kNRCU),
104 fArrFailEventNumber(100),
105 fArrALTROL1Phase(100000),
106 fArrALTROL1PhaseEvent(kNRCU),
107 fArrALTROL1PhaseFailEvent(kNRCU),
109 fVOccupancyEvent(100000),
110 fVSignalSumEvent(100000),
111 fVOccupancySenEvent(100000),
112 fVSignalSumSenEvent(100000),
113 fVNfiredPadsSenEvent(100000),
114 fVTimeStampEvent(100000)
119 SetNameTitle("AliTPCCalibRaw","AliTPCCalibRaw");
121 for (Int_t ircu=0;ircu<kNRCU;++ircu) fArrCurrentPhase.GetMatrixArray()[ircu]=-1;
125 //_____________________________________________________________________
126 AliTPCCalibRaw::AliTPCCalibRaw(const TMap *config) :
127 AliTPCCalibRawBase(),
131 fNFailL1PhaseEvent(0),
133 fNSecTime(600), //default 10 minutes
134 fNBinsTime(60), //default 60*10 minutes = 10 hours
135 fPadProcessed(kFALSE),
147 fArrCurrentPhaseDist(4),
148 fArrCurrentPhase(kNRCU),
149 fArrFailEventNumber(100),
150 fArrALTROL1Phase(100000),
151 fArrALTROL1PhaseEvent(kNRCU),
152 fArrALTROL1PhaseFailEvent(kNRCU),
154 fVOccupancyEvent(100000),
155 fVSignalSumEvent(100000),
156 fVOccupancySenEvent(100000),
157 fVSignalSumSenEvent(100000),
158 fVNfiredPadsSenEvent(100000),
159 fVTimeStampEvent(100000)
164 SetNameTitle("AliTPCCalibRaw","AliTPCCalibRaw");
166 for (Int_t ircu=0;ircu<kNRCU;++ircu) fArrCurrentPhase.GetMatrixArray()[ircu]=-1;
169 if (config->GetValue("FirstTimeBin")) fFirstTimeBin = ((TObjString*)config->GetValue("FirstTimeBin"))->GetString().Atoi();
170 if (config->GetValue("LastTimeBin")) fLastTimeBin = ((TObjString*)config->GetValue("LastTimeBin"))->GetString().Atoi();
173 //_____________________________________________________________________
174 AliTPCCalibRaw::~AliTPCCalibRaw()
181 //_____________________________________________________________________
182 // AliTPCCalibRaw& AliTPCCalibRaw::operator = (const AliTPCCalibRaw &source)
185 // // assignment operator
187 // if (&source == this) return *this;
188 // new (this) AliTPCCalibRaw(source);
193 //_____________________________________________________________________
194 Int_t AliTPCCalibRaw::Update(const Int_t isector, const Int_t iRow, const Int_t iPad,
195 const Int_t iTimeBin, const Float_t signal)
198 // Data filling method
200 if (iRow<0) return 0;
201 if (iPad<0) return 0;
202 if (iTimeBin<0) return 0;
203 if (!fFirstTimeStamp) fFirstTimeStamp=GetTimeStamp();
205 Int_t iChannel = fROC->GetRowIndexes(isector)[iRow]+iPad; // global pad position in sector
207 fVOccupancyEvent.GetMatrixArray()[GetNevents()]++;
208 fVSignalSumEvent.GetMatrixArray()[GetNevents()]+=signal;
209 //occupancy in sensitive regions
210 Int_t npads=(Int_t)fROC->GetNPads(isector,iRow);
211 Int_t cpad=iPad-npads/2;
212 if (isector<(Int_t)fROC->GetNInnerSector()){
214 if ( iRow>19 && iRow<46 ){
215 if ( TMath::Abs(cpad)<7 ){
216 fVOccupancySenEvent.GetMatrixArray()[GetNevents()]++;
217 fVSignalSumSenEvent.GetMatrixArray()[GetNevents()]+=signal;
218 if (iChannel!=fCurrentChannel) fVNfiredPadsSenEvent.GetMatrixArray()[GetNevents()]++;
221 } else if ( iRow>75 ){
222 //OROC case (outer corners and last three rows are sensitive)
223 Int_t padEdge=(Int_t)TMath::Min(iPad,npads-iPad);
224 Int_t nrows=(Int_t)fROC->GetNRows(isector);
225 if ((nrows-iRow-1)<3 || padEdge<((((Int_t)iRow-76)/4+1))*2){
226 fVOccupancySenEvent.GetMatrixArray()[GetNevents()]++;
227 fVSignalSumSenEvent.GetMatrixArray()[GetNevents()]+=signal;
228 if (iChannel!=fCurrentChannel) fVNfiredPadsSenEvent.GetMatrixArray()[GetNevents()]++;
232 if ( (iTimeBin>fLastTimeBin) || (iTimeBin<fFirstTimeBin) ) return 0;
233 //don't process edge pads
234 if (IsEdgePad(isector,iRow,iPad)) return 0;
235 // Double_t x[kHnBinsDV]={1,isector,0};
236 // fHnDrift->Fill(x);
237 if (fCurrentChannel==iChannel){
238 if (fPadProcessed) return 0;
240 fPadProcessed=kFALSE;
246 // Double_t x2[kHnBinsDV]={2,isector,0};
247 // fHnDrift->Fill(x2);
250 if (signal>fLastSignal) ++fNOkPlus;
251 else if(signal<fLastSignal && fNOkPlus>=fPeakDetPlus){
253 if (!fPeakTimeBin) fPeakTimeBin=fLastTimeBinProc;
254 if ( fNOkMinus>=fPeakDetMinus ) {
255 Double_t x[kHnBinsDV]={fPeakTimeBin,isector,(fTimeStamp-fFirstTimeStamp)/fNSecTime};
265 fLastTimeBinProc=iTimeBin;
266 fLastSignal=TMath::Nint(signal);
267 fCurrentChannel = iChannel;
270 //_____________________________________________________________________
271 void AliTPCCalibRaw::UpdateDDL(){
273 // fill ALTRO L1 information
279 fNanoSec=s.GetNanoSec();
282 Int_t phase=(Int_t)(GetL1PhaseTB()*4.);
283 //Fill pahse information of current rcu and event
284 fArrCurrentPhase.GetMatrixArray()[fCurrDDLNum]=phase;
285 //increase phase counter
286 ++((fArrCurrentPhaseDist.GetMatrixArray())[phase]);
289 //_____________________________________________________________________
290 void AliTPCCalibRaw::ResetEvent()
293 // Reset event counters
299 fArrCurrentPhaseDist.Zero();
301 //_____________________________________________________________________
302 void AliTPCCalibRaw::EndEvent()
305 // End event analysis
309 //find phase of the current event
310 Int_t phaseMaxEntries=-1;
312 for (Int_t i=0;i<fArrCurrentPhaseDist.GetNrows();++i){
313 Int_t entries=(Int_t)fArrCurrentPhaseDist[i];
314 if (maxEntries<entries) {
319 // store phase of current event
320 if (fArrALTROL1Phase.GetNrows()<=GetNevents())
321 fArrALTROL1Phase.ResizeTo(GetNevents()+10000);
322 (fArrALTROL1Phase.GetMatrixArray())[GetNevents()]=phaseMaxEntries;
324 //loop over RCUs and test failures
326 for (Int_t ircu=0;ircu<kNRCU;++ircu){
327 Int_t phase=(Int_t)fArrCurrentPhase[ircu];
328 if (phase<0) continue;
329 if (phase!=phaseMaxEntries){
330 TVectorF *arr=MakeArrL1PhaseRCU(fCurrDDLNum,kTRUE);
331 if (arr->GetNrows()<=(Int_t)fNFailL1PhaseEvent) arr->ResizeTo(arr->GetNrows()+100);
332 (arr->GetMatrixArray())[fNFailL1PhaseEvent]=phase;
336 //reset current phase information
337 fArrCurrentPhase[ircu]=-1;
340 if (fArrFailEventNumber.GetNrows()<=(Int_t)fNFailL1PhaseEvent) fArrFailEventNumber.ResizeTo(fArrFailEventNumber.GetNrows()+100);
341 fArrFailEventNumber.GetMatrixArray()[fNFailL1PhaseEvent]=GetNevents();
343 fNFailL1PhaseEvent+=fail;
345 fVTimeStampEvent.GetMatrixArray()[GetNevents()]=GetTimeStamp()-fFirstTimeStamp+fNanoSec*1e-9;
348 if (fVOccupancyEvent.GetNrows()<=GetNevents()){
349 fVOccupancyEvent.ResizeTo(GetNevents()+10000);
350 fVSignalSumEvent.ResizeTo(GetNevents()+10000);
351 fVOccupancySenEvent.ResizeTo(GetNevents()+10000);
352 fVSignalSumSenEvent.ResizeTo(GetNevents()+10000);
353 fVTimeStampEvent.ResizeTo(GetNevents()+10000);
354 fVNfiredPadsSenEvent.ResizeTo(GetNevents()+10000);
358 //_____________________________________________________________________
359 TH2C *AliTPCCalibRaw::MakeHistL1RCUEvents(Int_t type)
361 // Create a 2D histo RCU:Events indicating the there was a deviation
362 // from the mean L1 phase of the event
364 //type: 0=Failures, 1=Phases
366 //number of relavant events, depending on version
367 Int_t nevents=GetNevents();
369 Bool_t newVersion=kFALSE;
370 for (Int_t ircu=0; ircu<kNRCU; ++ircu){
371 const TVectorF *v=GetALTROL1PhaseEventsRCU(ircu);
373 if ((UInt_t)(v->GetNrows())==fNFailL1PhaseEvent){
375 nevents=fNFailL1PhaseEvent;
379 TH2C *h2 = new TH2C("hL1FailRCUEvents","L1 Failures;RCU;Event",kNRCU,0,kNRCU,nevents,0,nevents);
381 for (Int_t ircu=0;ircu<kNRCU;++ircu) {
382 const TVectorF *v=GetALTROL1PhaseEventsRCU(ircu);
387 } else if (type==1) {
393 for (Int_t iev=0;iev<nevents;++iev) {
394 Float_t val=(*v)(iev);
395 Float_t phase=fArrALTROL1Phase.GetMatrixArray()[iev];
397 Int_t event=(Int_t)fArrFailEventNumber.GetMatrixArray()[iev];
398 phase=fArrALTROL1Phase.GetMatrixArray()[event];
400 if (type==0) val=(val!=phase);
401 h2->SetBinContent(ircu+1,iev+1,val+add);
406 //_____________________________________________________________________
407 TH1F *AliTPCCalibRaw::MakeHistL1PhaseDist()
410 // L1 phase distribution. Should be flat in ideal case
412 TH1F *h=new TH1F("L1phaseDist","Normalized L1 phase distribution;phase;fraction of events",4,0,4);
414 for (Int_t iev=0;iev<GetNevents();++iev) h->Fill(fArrALTROL1Phase.GetMatrixArray()[iev]);
415 if (GetNevents()>0) h->Scale(1./GetNevents());
420 //_____________________________________________________________________
421 TVectorF *AliTPCCalibRaw::MakeVectL1PhaseDist()
424 // L1 phase distribution. Should be flat in ideal case
426 TVectorF *v=new TVectorF(4);
427 for (Int_t iev=0;iev<GetNevents();++iev) {
428 Int_t phase=(Int_t)fArrALTROL1Phase.GetMatrixArray()[iev];
429 ((v->GetMatrixArray())[phase])+=1./GetNevents();
433 //_____________________________________________________________________
434 TH2C *AliTPCCalibRaw::MakeHistL1RCUEventsIROC(Int_t type)
437 // Create a 2D histo RCU:Events indicating the there was a deviation
438 // from the mean L1 phase of the event
440 TH2C *h2 = new TH2C("hL1FailRCUEventsIROC","L1 Failures IROCs;RCU;Event",72,0,36,GetNevents(),0,GetNevents());
441 for (Int_t ircu=0;ircu<72;++ircu) {
443 if (type==0) v=GetALTROL1PhaseFailEventsRCU(ircu);
444 else if (type==1) v=GetALTROL1PhaseEventsRCU(ircu);
446 for (Int_t iev=0;iev<GetNevents();++iev) {
447 h2->SetBinContent(ircu+1,iev+1,(*v)(iev));
452 //_____________________________________________________________________
453 TH2C *AliTPCCalibRaw::MakeHistL1RCUEventsOROC(Int_t type)
456 // Create a 2D histo RCU:Events indicating the there was a deviation
457 // from the mean L1 phase of the event
459 TH2C *h2 = new TH2C("hL1FailRCUEventsOROC","L1 Failures OROCs;RCU;Event",144,0,36,GetNevents(),0,GetNevents());
460 for (Int_t ircu=72;ircu<kNRCU;++ircu) {
462 if (type==0) v=GetALTROL1PhaseFailEventsRCU(ircu);
463 else if (type==1) v=GetALTROL1PhaseEventsRCU(ircu);
465 for (Int_t iev=0;iev<GetNevents();++iev) {
466 h2->SetBinContent(ircu-72+1,iev+1,(*v)(iev));
471 //_____________________________________________________________________
472 void AliTPCCalibRaw::CreateDVhist()
475 // Setup the HnSparse for the drift velocity determination
477 if (fHnDrift) return;
479 //time bin, roc, time
480 Int_t bins[kHnBinsDV] = {fLastTimeBin-fFirstTimeBin, 72, fNBinsTime};
481 Double_t xmin[kHnBinsDV] = {fFirstTimeBin,0,0};
482 Double_t xmax[kHnBinsDV] = {fLastTimeBin,72,fNBinsTime};
483 fHnDrift=new THnSparseI("fHnDrift",Form("Drift velocity using last time bin;time bin[#times 100ns];ROC;Time bin [#times %us]",fNSecTime),kHnBinsDV, bins, xmin, xmax);
486 //_____________________________________________________________________
487 void AliTPCCalibRaw::Analyse()
494 fArrALTROL1Phase.ResizeTo(GetNevents());
495 for (Int_t ircu=0;ircu<kNRCU;++ircu){
496 TVectorF *arr=MakeArrL1PhaseRCU(ircu);//MakeArrL1PhaseRCU(ircu);
498 arr->ResizeTo(fNFailL1PhaseEvent);
499 fArrFailEventNumber.ResizeTo(fNFailL1PhaseEvent);
500 // TVectorF *arrF=MakeArrL1PhaseFailRCU(ircu);
501 // arrF->ResizeTo(1);
503 //resize occupancy arrays
504 fVTimeStampEvent.ResizeTo(GetNevents());
505 fVOccupancyEvent.ResizeTo(GetNevents());
506 fVOccupancySenEvent.ResizeTo(GetNevents());
507 fVSignalSumEvent.ResizeTo(GetNevents());
508 fVSignalSumSenEvent.ResizeTo(GetNevents());
509 fVNfiredPadsSenEvent.ResizeTo(GetNevents());
510 //Analyse drift velocity TODO
513 //_____________________________________________________________________
514 TGraph* AliTPCCalibRaw::MakeGraphOccupancy(const Int_t type, const Int_t xType)
517 // create occupancy graph (of samples abouve threshold)
518 // type=0: number of samples
519 // type=1: mean data volume (ADC counts/sample)
520 // type=2: data volume (ADC counts)
521 // type=3: samples per ADC count
522 // type=4: sample occupancy
524 // type=5: number of sample sensitive / number of samples
526 // same in sensitive regions:
527 // type=10: number of samples
528 // type=11: mean data volume (ADC counts/sample)
529 // type=12: data volume (ADC counts)
530 // type=13: samples per ADC count
531 // type=14: sample occupancy
533 // type=16: number of samples sensitive / number of pads sensitive
534 // type=17: pad occupancy in sensitive regions
535 // xType=0: vs. time stamp
536 // xType=1: vs. event counter
539 TString title("Event occupancy");
540 TString xTitle("Time");
541 TString yTitle("number of samples");
542 TGraph *gr=new TGraph(GetNevents());
543 TVectorF *vOcc=&fVOccupancyEvent;
544 TVectorF *vSum=&fVSignalSumEvent;
545 TVectorF *vPads=&fVNfiredPadsSenEvent;
546 Double_t norm=557568.;
548 vOcc=&fVOccupancySenEvent;
549 vSum=&fVSignalSumSenEvent;
550 vPads=&fVNfiredPadsSenEvent;
553 for (Int_t i=0;i<GetNevents(); ++i){
554 Double_t nAboveThreshold=vOcc->GetMatrixArray()[i];
555 Double_t nSumADC =vSum->GetMatrixArray()[i];
556 Double_t timestamp =fVTimeStampEvent.GetMatrixArray()[i]+fFirstTimeStamp;
557 Double_t nPads =vPads->GetMatrixArray()[i];
558 Double_t x=timestamp;
563 if (type%10==0) y=nAboveThreshold;
564 if (type%10==1&&nAboveThreshold>0) y=nSumADC/nAboveThreshold;
565 if (type%10==2) y=nSumADC;
566 if (type%10==3&&nSumADC>0) y=nAboveThreshold/nSumADC;
567 if (type%10==4) y=nAboveThreshold/(norm*(fLastTimeBin-fFirstTimeBin));
568 if (type==5) y=fVOccupancySenEvent.GetMatrixArray()[i]/fVOccupancyEvent.GetMatrixArray()[i];
569 if (type==16&&nPads>0) y=nAboveThreshold/nPads;
570 if (type==17) y=nPads/norm;
574 if (xType==1) xTitle="Event";
575 if (type%10==1) yTitle="Mean ADC counts/sample";
576 else if (type%10==2) yTitle="Data volume [ADC counts]";
577 else if (type%10==3) yTitle="samples per ADC count";
578 else if (type%10==4) yTitle="sample occupancy";
579 if (type==5) yTitle="N samples (sensitive) / N samples";
580 if (type%10==6) yTitle="N samples / N pads";
581 if (type==17) yTitle="Pad Occupancy";
582 if (type>=10) yTitle+=" (sensitive)";
583 title=yTitle+":"+xTitle;
584 title+=";"+xTitle+";"+yTitle;
585 gr->SetTitle(title.Data());
586 gr->SetEditable(kFALSE);
589 //_____________________________________________________________________
590 TGraph* AliTPCCalibRaw::MakeGraphNoiseEvents()
597 //_____________________________________________________________________
598 TCanvas* AliTPCCalibRaw::MakeCanvasOccupancy(const Int_t xType, Bool_t sen)
601 // Create a canvas with occupancy information of all 'type's (see MakeGraphOccupancy)
602 // xType=0: vs. timestamp
603 // xType=1: vs. event number
605 // sen=kTRUE: for sensitive regions
608 TString name("RawOccupancy_");
609 TString title("Raw Occupancy vs. ");
613 } else if (xType==1){
619 title+=" (sensitive)";
621 TCanvas *c=(TCanvas*)gROOT->GetListOfCanvases()->FindObject(name.Data());
622 if (!c) c=new TCanvas(name.Data(),title.Data());
625 for (Int_t i=0;i<4;++i){
627 TGraph *gr=MakeGraphOccupancy(i+10*(Int_t)sen,xType);