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),
87 fNSecTime(600), //default 10 minutes
88 fNBinsTime(60), //default 60*10 minutes = 10 hours
89 fPadProcessed(kFALSE),
101 fArrCurrentPhaseDist(4),
102 fArrCurrentPhase(kNRCU),
103 fArrFailEventNumber(100),
104 fArrALTROL1Phase(100000),
105 fArrALTROL1PhaseEvent(kNRCU),
106 fArrALTROL1PhaseFailEvent(kNRCU),
108 fVOccupancyEvent(100000),
109 fVSignalSumEvent(100000),
110 fVOccupancySenEvent(100000),
111 fVSignalSumSenEvent(100000),
112 fVNfiredPadsSenEvent(100000),
113 fVTimeStampEvent(100000)
118 SetNameTitle("AliTPCCalibRaw","AliTPCCalibRaw");
120 for (Int_t ircu=0;ircu<kNRCU;++ircu) fArrCurrentPhase.GetMatrixArray()[ircu]=-1;
124 //_____________________________________________________________________
125 AliTPCCalibRaw::AliTPCCalibRaw(const TMap *config) :
126 AliTPCCalibRawBase(),
130 fNFailL1PhaseEvent(0),
131 fNSecTime(600), //default 10 minutes
132 fNBinsTime(60), //default 60*10 minutes = 10 hours
133 fPadProcessed(kFALSE),
145 fArrCurrentPhaseDist(4),
146 fArrCurrentPhase(kNRCU),
147 fArrFailEventNumber(100),
148 fArrALTROL1Phase(100000),
149 fArrALTROL1PhaseEvent(kNRCU),
150 fArrALTROL1PhaseFailEvent(kNRCU),
152 fVOccupancyEvent(100000),
153 fVSignalSumEvent(100000),
154 fVOccupancySenEvent(100000),
155 fVSignalSumSenEvent(100000),
156 fVNfiredPadsSenEvent(100000),
157 fVTimeStampEvent(100000)
162 SetNameTitle("AliTPCCalibRaw","AliTPCCalibRaw");
164 for (Int_t ircu=0;ircu<kNRCU;++ircu) fArrCurrentPhase.GetMatrixArray()[ircu]=-1;
167 if (config->GetValue("FirstTimeBin")) fFirstTimeBin = ((TObjString*)config->GetValue("FirstTimeBin"))->GetString().Atoi();
168 if (config->GetValue("LastTimeBin")) fLastTimeBin = ((TObjString*)config->GetValue("LastTimeBin"))->GetString().Atoi();
169 if (config->GetValue("DebugLevel")) fDebugLevel = ((TObjString*)config->GetValue("DebugLevel"))->GetString().Atoi();
172 //_____________________________________________________________________
173 AliTPCCalibRaw::~AliTPCCalibRaw()
180 //_____________________________________________________________________
181 // AliTPCCalibRaw& AliTPCCalibRaw::operator = (const AliTPCCalibRaw &source)
184 // // assignment operator
186 // if (&source == this) return *this;
187 // new (this) AliTPCCalibRaw(source);
192 //_____________________________________________________________________
193 Int_t AliTPCCalibRaw::Update(const Int_t isector, const Int_t iRow, const Int_t iPad,
194 const Int_t iTimeBin, const Float_t signal)
197 // Data filling method
199 if (iRow<0) return 0;
200 if (iPad<0) return 0;
201 if (iTimeBin<0) return 0;
203 Int_t iChannel = fROC->GetRowIndexes(isector)[iRow]+iPad; // global pad position in sector
205 fVOccupancyEvent.GetMatrixArray()[GetNevents()]++;
206 fVSignalSumEvent.GetMatrixArray()[GetNevents()]+=signal;
207 //occupancy in sensitive regions
208 Int_t npads=(Int_t)fROC->GetNPads(isector,iRow);
209 Int_t cpad=iPad-npads/2;
210 if (isector<(Int_t)fROC->GetNInnerSector()){
212 if ( iRow>19 && iRow<46 ){
213 if ( TMath::Abs(cpad)<7 ){
214 fVOccupancySenEvent.GetMatrixArray()[GetNevents()]++;
215 fVSignalSumSenEvent.GetMatrixArray()[GetNevents()]+=signal;
216 if (iChannel!=fCurrentChannel) fVNfiredPadsSenEvent.GetMatrixArray()[GetNevents()]++;
219 } else if ( iRow>75 ){
220 //OROC case (outer corners and last three rows are sensitive)
221 Int_t padEdge=(Int_t)TMath::Min(iPad,npads-iPad);
222 Int_t nrows=(Int_t)fROC->GetNRows(isector);
223 if ((nrows-iRow-1)<3 || padEdge<((((Int_t)iRow-76)/4+1))*2){
224 fVOccupancySenEvent.GetMatrixArray()[GetNevents()]++;
225 fVSignalSumSenEvent.GetMatrixArray()[GetNevents()]+=signal;
226 if (iChannel!=fCurrentChannel) fVNfiredPadsSenEvent.GetMatrixArray()[GetNevents()]++;
230 if ( (iTimeBin>fLastTimeBin) || (iTimeBin<fFirstTimeBin) ) return 0;
231 //don't process edge pads
232 if (IsEdgePad(isector,iRow,iPad)) return 0;
233 // Double_t x[kHnBinsDV]={1,isector,0};
234 // fHnDrift->Fill(x);
235 if (fCurrentChannel==iChannel){
236 if (fPadProcessed) return 0;
238 fPadProcessed=kFALSE;
244 // Double_t x2[kHnBinsDV]={2,isector,0};
245 // fHnDrift->Fill(x2);
248 if (signal>fLastSignal) ++fNOkPlus;
249 else if(signal<fLastSignal && fNOkPlus>=fPeakDetPlus){
251 if (!fPeakTimeBin) fPeakTimeBin=fLastTimeBinProc;
252 if ( fNOkMinus>=fPeakDetMinus ) {
253 Double_t x[kHnBinsDV]={fPeakTimeBin,isector,(fTimeStamp-fFirstTimeStamp)/fNSecTime};
263 fLastTimeBinProc=iTimeBin;
264 fLastSignal=TMath::Nint(signal);
265 fCurrentChannel = iChannel;
268 //_____________________________________________________________________
269 void AliTPCCalibRaw::UpdateDDL(){
271 // fill ALTRO L1 information
277 fNanoSec=s.GetNanoSec();
280 Int_t phase=(Int_t)(GetL1PhaseTB()*4.);
281 //Fill pahse information of current rcu and event
282 fArrCurrentPhase.GetMatrixArray()[fCurrDDLNum]=phase;
283 //increase phase counter
284 ++((fArrCurrentPhaseDist.GetMatrixArray())[phase]);
287 //_____________________________________________________________________
288 void AliTPCCalibRaw::ResetEvent()
291 // Reset event counters
297 fArrCurrentPhaseDist.Zero();
299 //_____________________________________________________________________
300 void AliTPCCalibRaw::EndEvent()
303 // End event analysis
307 //find phase of the current event
308 Int_t phaseMaxEntries=-1;
310 for (Int_t i=0;i<fArrCurrentPhaseDist.GetNrows();++i){
311 Int_t entries=(Int_t)fArrCurrentPhaseDist[i];
312 if (maxEntries<entries) {
317 // store phase of current event
318 if (fArrALTROL1Phase.GetNrows()-1<=GetNevents())
319 fArrALTROL1Phase.ResizeTo(GetNevents()+10000);
320 (fArrALTROL1Phase.GetMatrixArray())[GetNevents()]=phaseMaxEntries;
322 //loop over RCUs and test failures
324 for (Int_t ircu=0;ircu<kNRCU;++ircu){
325 Int_t phase=(Int_t)fArrCurrentPhase[ircu];
326 if (phase<0) continue;
327 if (phase!=phaseMaxEntries){
328 TVectorF *arr=MakeArrL1PhaseRCU(fCurrDDLNum,kTRUE);
329 if (arr->GetNrows()-1<=(Int_t)fNFailL1PhaseEvent) arr->ResizeTo(arr->GetNrows()+100);
330 (arr->GetMatrixArray())[fNFailL1PhaseEvent]=phase;
334 //reset current phase information
335 fArrCurrentPhase[ircu]=-1;
338 if (fArrFailEventNumber.GetNrows()-1<=(Int_t)fNFailL1PhaseEvent) fArrFailEventNumber.ResizeTo(fArrFailEventNumber.GetNrows()+100);
339 fArrFailEventNumber.GetMatrixArray()[fNFailL1PhaseEvent]=GetNevents();
341 fNFailL1PhaseEvent+=fail;
343 fVTimeStampEvent.GetMatrixArray()[GetNevents()]=GetTimeStamp()-fFirstTimeStamp+fNanoSec*1e-9;
346 if (fVOccupancyEvent.GetNrows()-1<=GetNevents()){
347 fVOccupancyEvent.ResizeTo(GetNevents()+10000);
348 fVSignalSumEvent.ResizeTo(GetNevents()+10000);
349 fVOccupancySenEvent.ResizeTo(GetNevents()+10000);
350 fVSignalSumSenEvent.ResizeTo(GetNevents()+10000);
351 fVTimeStampEvent.ResizeTo(GetNevents()+10000);
352 fVNfiredPadsSenEvent.ResizeTo(GetNevents()+10000);
356 //_____________________________________________________________________
357 TH2C *AliTPCCalibRaw::MakeHistL1RCUEvents(Int_t type)
359 // Create a 2D histo RCU:Events indicating the there was a deviation
360 // from the mean L1 phase of the event
362 //type: 0=Failures, 1=Phases
364 //number of relavant events, depending on version
365 Int_t nevents=GetNevents();
367 Bool_t newVersion=kFALSE;
368 for (Int_t ircu=0; ircu<kNRCU; ++ircu){
369 const TVectorF *v=GetALTROL1PhaseEventsRCU(ircu);
371 if ((UInt_t)(v->GetNrows())==fNFailL1PhaseEvent){
373 nevents=fNFailL1PhaseEvent;
377 TH2C *h2 = new TH2C("hL1FailRCUEvents","L1 Failures;RCU;Event",kNRCU,0,kNRCU,nevents,0,nevents);
379 for (Int_t ircu=0;ircu<kNRCU;++ircu) {
380 const TVectorF *v=GetALTROL1PhaseEventsRCU(ircu);
385 } else if (type==1) {
391 for (Int_t iev=0;iev<nevents;++iev) {
392 Float_t val=(*v)(iev);
393 Float_t phase=fArrALTROL1Phase.GetMatrixArray()[iev];
395 Int_t event=(Int_t)fArrFailEventNumber.GetMatrixArray()[iev];
396 phase=fArrALTROL1Phase.GetMatrixArray()[event];
398 if (type==0) val=(val!=phase);
399 h2->SetBinContent(ircu+1,iev+1,val+add);
404 //_____________________________________________________________________
405 TH1F *AliTPCCalibRaw::MakeHistL1PhaseDist()
408 // L1 phase distribution. Should be flat in ideal case
410 TH1F *h=new TH1F("L1phaseDist","Normalized L1 phase distribution;phase;fraction of events",4,0,4);
412 for (Int_t iev=0;iev<GetNevents();++iev) h->Fill(fArrALTROL1Phase.GetMatrixArray()[iev]);
413 if (GetNevents()>0) h->Scale(1./GetNevents());
418 //_____________________________________________________________________
419 TVectorF *AliTPCCalibRaw::MakeVectL1PhaseDist()
422 // L1 phase distribution. Should be flat in ideal case
424 TVectorF *v=new TVectorF(4);
425 for (Int_t iev=0;iev<GetNevents();++iev) {
426 Int_t phase=(Int_t)fArrALTROL1Phase.GetMatrixArray()[iev];
427 ((v->GetMatrixArray())[phase])+=1./GetNevents();
431 //_____________________________________________________________________
432 TH2C *AliTPCCalibRaw::MakeHistL1RCUEventsIROC(Int_t type)
435 // Create a 2D histo RCU:Events indicating the there was a deviation
436 // from the mean L1 phase of the event
438 TH2C *h2 = new TH2C("hL1FailRCUEventsIROC","L1 Failures IROCs;RCU;Event",72,0,36,GetNevents(),0,GetNevents());
439 for (Int_t ircu=0;ircu<72;++ircu) {
441 if (type==0) v=GetALTROL1PhaseFailEventsRCU(ircu);
442 else if (type==1) v=GetALTROL1PhaseEventsRCU(ircu);
444 for (Int_t iev=0;iev<GetNevents();++iev) {
445 h2->SetBinContent(ircu+1,iev+1,(*v)(iev));
450 //_____________________________________________________________________
451 TH2C *AliTPCCalibRaw::MakeHistL1RCUEventsOROC(Int_t type)
454 // Create a 2D histo RCU:Events indicating the there was a deviation
455 // from the mean L1 phase of the event
457 TH2C *h2 = new TH2C("hL1FailRCUEventsOROC","L1 Failures OROCs;RCU;Event",144,0,36,GetNevents(),0,GetNevents());
458 for (Int_t ircu=72;ircu<kNRCU;++ircu) {
460 if (type==0) v=GetALTROL1PhaseFailEventsRCU(ircu);
461 else if (type==1) v=GetALTROL1PhaseEventsRCU(ircu);
463 for (Int_t iev=0;iev<GetNevents();++iev) {
464 h2->SetBinContent(ircu-72+1,iev+1,(*v)(iev));
469 //_____________________________________________________________________
470 void AliTPCCalibRaw::CreateDVhist()
473 // Setup the HnSparse for the drift velocity determination
475 if (fHnDrift) return;
477 //time bin, roc, time
478 Int_t bins[kHnBinsDV] = {fLastTimeBin-fFirstTimeBin, 72, fNBinsTime};
479 Double_t xmin[kHnBinsDV] = {fFirstTimeBin,0,0};
480 Double_t xmax[kHnBinsDV] = {fLastTimeBin,72,fNBinsTime};
481 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);
484 //_____________________________________________________________________
485 void AliTPCCalibRaw::Analyse()
492 fArrALTROL1Phase.ResizeTo(GetNevents());
493 for (Int_t ircu=0;ircu<kNRCU;++ircu){
494 TVectorF *arr=MakeArrL1PhaseRCU(ircu);//MakeArrL1PhaseRCU(ircu);
496 arr->ResizeTo(fNFailL1PhaseEvent);
497 fArrFailEventNumber.ResizeTo(fNFailL1PhaseEvent);
498 // TVectorF *arrF=MakeArrL1PhaseFailRCU(ircu);
499 // arrF->ResizeTo(1);
501 //resize occupancy arrays only save event occupancy in sensitive regions by default
502 //save the rest in debub mode
503 fVOccupancySenEvent.ResizeTo(GetNevents());
505 fVOccupancyEvent.ResizeTo(GetNevents());
506 fVSignalSumEvent.ResizeTo(GetNevents());
507 fVSignalSumSenEvent.ResizeTo(GetNevents());
508 fVNfiredPadsSenEvent.ResizeTo(GetNevents());
509 fVTimeStampEvent.ResizeTo(GetNevents());
511 fVOccupancyEvent.ResizeTo(0);
512 fVSignalSumEvent.ResizeTo(0);
513 fVSignalSumSenEvent.ResizeTo(0);
514 fVNfiredPadsSenEvent.ResizeTo(0);
515 fVTimeStampEvent.ResizeTo(0);
517 //Analyse drift velocity TODO
520 //_____________________________________________________________________
521 TGraph* AliTPCCalibRaw::MakeGraphOccupancy(const Int_t type, const Int_t xType)
524 // create occupancy graph (of samples abouve threshold)
525 // type=0: number of samples
526 // type=1: mean data volume (ADC counts/sample)
527 // type=2: data volume (ADC counts)
528 // type=3: samples per ADC count
529 // type=4: sample occupancy
531 // type=5: number of sample sensitive / number of samples
533 // same in sensitive regions:
534 // type=10: number of samples
535 // type=11: mean data volume (ADC counts/sample)
536 // type=12: data volume (ADC counts)
537 // type=13: samples per ADC count
538 // type=14: sample occupancy
540 // type=16: number of samples sensitive / number of pads sensitive
541 // type=17: pad occupancy in sensitive regions
542 // xType=0: vs. time stamp
543 // xType=1: vs. event counter
546 TString title("Event occupancy");
547 TString xTitle("Time");
548 TString yTitle("number of samples");
549 TGraph *gr=new TGraph(GetNevents());
550 if (fVSignalSumEvent.GetNrows()==0&&!(type==10||type==14)) return 0;
551 TVectorF *vOcc=&fVOccupancyEvent;
552 TVectorF *vSum=&fVSignalSumEvent;
553 TVectorF *vPads=&fVNfiredPadsSenEvent;
554 Double_t norm=557568.;
555 if (type!=14&&fVOccupancyEvent.GetNrows()==0){
556 AliWarning("In non debug mode only occupancy in sensitive regions vs. event awailable!!!");
560 vOcc=&fVOccupancySenEvent;
561 vSum=&fVSignalSumSenEvent;
562 vPads=&fVNfiredPadsSenEvent;
565 for (Int_t i=0;i<GetNevents(); ++i){
566 Double_t nAboveThreshold=vOcc->GetMatrixArray()[i];
569 Double_t timestamp =1;
572 if (fVOccupancyEvent.GetNrows()>0){
573 nSumADC =vSum->GetMatrixArray()[i];
574 timestamp =fVTimeStampEvent.GetMatrixArray()[i]+fFirstTimeStamp;
575 nPads =vPads->GetMatrixArray()[i];
577 Double_t x=timestamp;
582 if (type%10==0) y=nAboveThreshold;
583 if (type%10==1&&nAboveThreshold>0) y=nSumADC/nAboveThreshold;
584 if (type%10==2) y=nSumADC;
585 if (type%10==3&&nSumADC>0) y=nAboveThreshold/nSumADC;
586 if (type%10==4) y=nAboveThreshold/(norm*(fLastTimeBin-fFirstTimeBin));
587 if (type==5) y=fVOccupancySenEvent.GetMatrixArray()[i]/fVOccupancyEvent.GetMatrixArray()[i];
588 if (type==16&&nPads>0) y=nAboveThreshold/nPads;
589 if (type==17) y=nPads/norm;
593 if (xType==1) xTitle="Event";
594 if (type%10==1) yTitle="Mean ADC counts/sample";
595 else if (type%10==2) yTitle="Data volume [ADC counts]";
596 else if (type%10==3) yTitle="samples per ADC count";
597 else if (type%10==4) yTitle="sample occupancy";
598 if (type==5) yTitle="N samples (sensitive) / N samples";
599 if (type%10==6) yTitle="N samples / N pads";
600 if (type==17) yTitle="Pad Occupancy";
601 if (type>=10) yTitle+=" (sensitive)";
602 title=yTitle+":"+xTitle;
603 title+=";"+xTitle+";"+yTitle;
604 gr->SetTitle(title.Data());
605 gr->SetEditable(kFALSE);
608 //_____________________________________________________________________
609 // TGraph* AliTPCCalibRaw::MakeGraphNoiseEvents()
612 // Not implemented for the moment
616 //_____________________________________________________________________
617 TCanvas* AliTPCCalibRaw::MakeCanvasOccupancy(const Int_t xType, Bool_t sen)
620 // Create a canvas with occupancy information of all 'type's (see MakeGraphOccupancy)
621 // xType=0: vs. timestamp
622 // xType=1: vs. event number
624 // sen=kTRUE: for sensitive regions
627 TString name("RawOccupancy_");
628 TString title("Raw Occupancy vs. ");
632 } else if (xType==1){
638 title+=" (sensitive)";
640 TCanvas *c=(TCanvas*)gROOT->GetListOfCanvases()->FindObject(name.Data());
641 if (!c) c=new TCanvas(name.Data(),title.Data());
644 for (Int_t i=0;i<4;++i){
646 TGraph *gr=MakeGraphOccupancy(i+10*(Int_t)sen,xType);
652 //_____________________________________________________________________
653 void AliTPCCalibRaw::Merge(AliTPCCalibRaw * const sig)
656 // Merge sig with this instance
661 //Add last time bin distribution histogram
662 fHnDrift->Add(sig->fHnDrift);
668 //_____________________________________________________________________
669 Long64_t AliTPCCalibRaw::Merge(TCollection * const list)
672 // Merge all objects of this type in list
678 AliTPCCalibRaw *ce=0;
681 while ( (o=next()) ){
682 ce=dynamic_cast<AliTPCCalibRaw*>(o);