2 /**************************************************************************
3 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
5 * Author: The ALICE Off-line Project. *
6 * Contributors are mentioned in the code where appropriate. *
8 * Permission to use, copy, modify and distribute this software and its *
9 * documentation strictly for non-commercial purposes is hereby granted *
10 * without fee, provided that the above copyright notice appears in all *
11 * copies and that both the copyright notice and this permission notice *
12 * appear in the supporting documentation. The authors make no claims *
13 * about the suitability of this software for any purpose. It is *
14 * provided "as is" without express or implied warranty. *
15 **************************************************************************/
17 /////////////////////////////////////////////////////////////////////////////////
21 // Task to run the calibration offline.
23 // R. Bailhache (rbailhache@ikf.uni-frankfurt.de, R.Bailhache@gsi.de)
25 //////////////////////////////////////////////////////////////////////////////////
28 #include "Riostream.h"
31 #include "TProfile2D.h"
39 #include "TObjArray.h"
43 #include "TGraphErrors.h"
44 #include "THnSparse.h"
46 #include "AliTRDrecoTask.h"
47 #include "AliAnalysisManager.h"
49 #include "AliESDInputHandler.h"
50 #include "AliTRDtrackV1.h"
51 #include "AliTRDseedV1.h"
52 #include "AliTRDcluster.h"
53 #include "info/AliTRDtrackInfo.h"
54 #include "AliTRDcalibDB.h"
56 #include "AliTRDCalibraFillHisto.h"
57 #include "AliTRDCalibraFit.h"
58 #include "AliTRDCalibraVdriftLinearFit.h"
59 #include "AliTRDCalibraMode.h"
60 #include "AliTRDCalibraVector.h"
61 #include "./Cal/AliTRDCalPad.h"
62 #include "./Cal/AliTRDCalDet.h"
63 #include "AliCDBMetaData.h"
64 #include "AliCDBManager.h"
65 #include "AliCDBStorage.h"
69 #include "AliTRDcalibration.h"
72 ClassImp(AliTRDcalibration)
74 //________________________________________________________________________
75 AliTRDcalibration::AliTRDcalibration()
76 :AliTRDrecoTask("Calibration", "Calibration on tracks")
80 ,fTRDCalibraFillHisto(0)
82 ,fNbTRDTrackOffline(0)
83 ,fNbTRDTrackStandalone(0)
85 ,fNbTRDTrackletOffline(0)
86 ,fNbTRDTrackletStandalone(0)
88 ,fNbTimeBinOffline(0x0)
89 ,fNbTimeBinStandalone(0x0)
91 ,fNbClustersOffline(0)
92 ,fNbClustersStandalone(0)
104 ,fnormalizeNbOfCluster(kFALSE)
106 ,fOfflineTracks(kFALSE)
107 ,fStandaloneTracks(kFALSE)
108 ,fCompressPerDetector(kFALSE)
110 ,fkNameDirectory("local://.")
112 ,fPostProcess(kFALSE)
118 for(Int_t k = 0; k < 3; k++)
125 //________________________________________________________________________
126 AliTRDcalibration::~AliTRDcalibration()
128 // Default destructor
130 if(fNbTRDTrack) delete fNbTRDTrack;
131 if(fNbTRDTrackOffline) delete fNbTRDTrackOffline;
132 if(fNbTRDTrackStandalone) delete fNbTRDTrackStandalone;
133 if(fNbTRDTracklet) delete fNbTRDTracklet;
134 if(fNbTRDTrackletOffline) delete fNbTRDTrackletOffline;
135 if(fNbTRDTrackletStandalone) delete fNbTRDTrackletStandalone;
136 if(fNbTimeBin) delete fNbTimeBin;
137 if(fNbTimeBinOffline) delete fNbTimeBinOffline;
138 if(fNbTimeBinStandalone) delete fNbTimeBinStandalone;
139 if(fNbClusters) delete fNbClusters;
140 if(fNbClustersOffline) delete fNbClustersOffline;
141 if(fNbClustersStandalone) delete fNbClustersStandalone;
142 if(fPHSum) delete fPHSum;
143 if(fCHSum) delete fCHSum;
144 if(fDetSum) delete fDetSum;
145 if(fDetSumVector) delete fDetSumVector;
146 if(fkNameDirectory) delete fkNameDirectory;
147 if(fGraph){fGraph->Delete(); delete fGraph;}
150 //________________________________________________________________________
151 void AliTRDcalibration::CreateOutputObjects()
153 // Create output objects
155 OpenFile(0, "RECREATE");
157 // Number of time bins
158 AliTRDcalibDB *cal = AliTRDcalibDB::Instance();
159 fNbTimeBins = cal->GetNumberOfTimeBins();
161 // instance calibration: what to calibrate
162 fTRDCalibraFillHisto = AliTRDCalibraFillHisto::Instance();
163 fTRDCalibraFillHisto->SetHisto2d(fHisto2d); // choose to use histograms
164 fTRDCalibraFillHisto->SetVector2d(fVector2d); // choose to use vectors
165 fTRDCalibraFillHisto->SetCH2dOn(); // choose to calibrate the gain
166 fTRDCalibraFillHisto->SetPH2dOn(); // choose to calibrate the drift velocity
167 fTRDCalibraFillHisto->SetPRF2dOn(); // choose to look at the PRF
168 fTRDCalibraFillHisto->SetLinearFitterOn(fVdriftLinear); // Other possibility vdrift VDRIFT
169 fTRDCalibraFillHisto->SetLinearFitterDebugOn(fVdriftLinear); // Other possibility vdrift
171 // segmentation (should be per default the max and add at the end)
172 for(Int_t k = 0; k < 3; k++){
173 if(((fNz[k] != 10) && (fNrphi[k] != 10)) && ((fNz[k] != 100) && (fNrphi[k] != 100))) {
174 fTRDCalibraFillHisto->SetNz(k,fNz[k]); // Mode calibration
175 fTRDCalibraFillHisto->SetNrphi(k,fNrphi[k]); // Mode calibration
178 if((fNz[k] == 100) && (fNrphi[k] == 100)) {
179 if(fVector2d) AliInfo("The mode all together is not supported by the vector method");
180 fTRDCalibraFillHisto->SetAllTogether(k);
182 if((fNz[k] == 10) && (fNrphi[k] == 10)) {
183 if(fVector2d) AliInfo("The mode per supermodule is not supported by the vector method");
184 fTRDCalibraFillHisto->SetPerSuperModule(k);
190 fTRDCalibraFillHisto->SetDebugLevel(fDebugLevel); //debug stuff
193 fTRDCalibraFillHisto->Init2Dhistos(); // initialise the histos
196 fTRDCalibraFillHisto->SetNumberClusters(flow); // At least flow clusters
197 fTRDCalibraFillHisto->SetNumberClustersf(fhigh); // The more fhigh clusters
198 fTRDCalibraFillHisto->SetFillWithZero(ffillZero); // Fill zeros
199 fTRDCalibraFillHisto->SetNormalizeNbOfCluster(fnormalizeNbOfCluster); // For iterations
201 // Add them to the container
202 fContainer = new TObjArray();
204 fContainer->Add(fTRDCalibraFillHisto->GetCH2d()); //TH2I
205 fContainer->Add(fTRDCalibraFillHisto->GetPH2d()); //TProfile2D
206 fContainer->Add(fTRDCalibraFillHisto->GetPRF2d()); //TProfile2D
208 if(fVdriftLinear) fContainer->Add(fTRDCalibraFillHisto->GetVdriftLinearFit()); // Other drift velocity
209 if(fVector2d) fContainer->Add(fTRDCalibraFillHisto->GetCalibraVector()); //calibra vector
213 // Init the debug histos
214 fNbTRDTrack = new TH1F("TRDTrack","TRDTrack",500,0,500);
215 fNbTRDTrack->Sumw2();
216 fNbTRDTrackOffline = new TH1F("TRDTrackOffline","TRDTrackOffline",500,0,500);
217 fNbTRDTrackOffline->Sumw2();
218 fNbTRDTrackStandalone = new TH1F("TRDTrackStandalone","TRDTrackStandalone",500,0,500);
219 fNbTRDTrackStandalone->Sumw2();
221 fNbTRDTracklet = new TH1F("TRDTracklet","TRDTracklet",540,0.,540.);
222 fNbTRDTracklet->Sumw2();
223 fNbTRDTrackletOffline = new TH1F("TRDTrackletOffline","TRDTrackletOffline",540,0.,540.);
224 fNbTRDTrackletOffline->Sumw2();
225 fNbTRDTrackletStandalone = new TH1F("TRDTrackletStandalone","TRDTrackletStandalone",540,0.,540.);
226 fNbTRDTrackletStandalone->Sumw2();
228 fNbTimeBin = new TH1F("TimeBin","TimeBin",35,0,35);
230 fNbTimeBinOffline = new TH1F("TimeBinOffline","TimeBinOffline",35,0,35);
231 fNbTimeBinOffline->Sumw2();
232 fNbTimeBinStandalone = new TH1F("TimeBinStandalone","TimeBinStandalone",35,0,35);
233 fNbTimeBinStandalone->Sumw2();
235 fNbClusters = new TH1F("NbClusters","",35,0,35);
236 fNbClusters->Sumw2();
237 fNbClustersOffline = new TH1F("NbClustersOffline","",35,0,35);
238 fNbClustersOffline->Sumw2();
239 fNbClustersStandalone = new TH1F("NbClustersStandalone","",35,0,35);
240 fNbClustersStandalone->Sumw2();
242 fPHSum = new TProfile2D("PH2dSum","Nz0Nrphi0"
243 ,fNbTimeBins,-0.05,(Double_t)(fNbTimeBins/10.0)-0.05
245 fPHSum->SetYTitle("Det/pad groups");
246 fPHSum->SetXTitle("time [#mus]");
247 fPHSum->SetZTitle("<PH> [a.u.]");
250 fCHSum = new TH2I("CH2dSum","Nz0Nrphi0",100,0,300,540,0,540);
251 fCHSum->SetYTitle("Det/pad groups");
252 fCHSum->SetXTitle("charge deposit [a.u]");
253 fCHSum->SetZTitle("counts");
258 fContainer->Add(fNbTRDTrack);
259 fContainer->Add(fNbTRDTrackOffline);
260 fContainer->Add(fNbTRDTrackStandalone);
261 fContainer->Add(fNbTRDTracklet);
262 fContainer->Add(fNbTRDTrackletOffline);
263 fContainer->Add(fNbTRDTrackletStandalone);
264 fContainer->Add(fNbTimeBin);
265 fContainer->Add(fNbTimeBinOffline);
266 fContainer->Add(fNbTimeBinStandalone);
267 fContainer->Add(fNbClusters);
268 fContainer->Add(fNbClustersOffline);
269 fContainer->Add(fNbClustersStandalone);
270 fContainer->Add(fPHSum);
271 fContainer->Add(fCHSum);
277 //________________________________________________________________________
278 void AliTRDcalibration::Exec(Option_t *)
281 // Execute function where the reference data are filled
287 Int_t nbTrdTracks = 0;
289 Int_t nbTrdTracksStandalone = 0;
291 Int_t nbTrdTracksOffline = 0;
295 // Loop on track in the event
297 //printf("Total of %d\n",fTracks->GetEntriesFast());
298 for(Int_t itrk=0; itrk < fTracks->GetEntriesFast(); itrk++){
300 //printf("itrk %d\n",itrk);
302 fTrackInfo = (AliTRDtrackInfo*)fTracks->UncheckedAt(itrk);
303 ftrdTrack = fTrackInfo->GetTrack();
304 if(!ftrdTrack) continue;
308 fTRDCalibraFillHisto->UpdateHistogramsV1(ftrdTrack);
312 Bool_t standalonetracklet = kFALSE;
313 const AliTRDseedV1 *tracklet = 0x0;
315 // Loop on tracklet in the event
317 for(Int_t itr = 0; itr < 6; itr++){
318 //printf("itr %d\n",itr);
319 if(!(tracklet = ftrdTrack->GetTracklet(itr))) continue;
320 if(!tracklet->IsOK()) continue;
322 if(tracklet->IsStandAlone()) standalonetracklet = kTRUE;
323 Int_t nbclusters = 0;
325 Double_t phtb[AliTRDseedV1::kNtb];
326 memset(phtb, 0, AliTRDseedV1::kNtb*sizeof(Double_t));
330 Float_t normalisation = 6.67;
333 for(int ic=0; ic<AliTRDseedV1::kNtb; ic++){
334 // Check no shared clusters
335 for(int icc=AliTRDseedV1::kNtb; icc<AliTRDseedV1::kNclusters; icc++){
336 if((fcl = tracklet->GetClusters(icc))) crossrow = 1;
338 if(!(fcl = tracklet->GetClusters(ic))) continue;
340 Int_t time = fcl->GetPadTime();
341 Float_t ch = tracklet->GetdQdl(ic);
342 Float_t qcl = TMath::Abs(fcl->GetQ());
343 detector = fcl->GetDetector();
344 if((time>-1) && (time<fNbTimeBins)) phtb[time]=qcl;
345 sum += ch/normalisation;
346 fNbTimeBin->Fill(time);
347 if(tracklet->IsStandAlone()) fNbTimeBinStandalone->Fill(time);
348 else fNbTimeBinOffline->Fill(time);
351 fNbTRDTracklet->Fill(detector);
352 if(tracklet->IsStandAlone()) fNbTRDTrackletStandalone->Fill(detector);
353 else fNbTRDTrackletOffline->Fill(detector);
355 fNbClusters->Fill(nbclusters);
356 if(tracklet->IsStandAlone()) fNbClustersStandalone->Fill(nbclusters);
357 else fNbClustersOffline->Fill(nbclusters);
359 if((nbclusters > flow) && (nbclusters < fhigh)){
360 fCHSum->Fill(sum/20.0,0.0);
361 for(int ic=0; ic<fNbTimeBins; ic++){
362 //printf("ic %d and time %f and cluster %f \n",ic,(Double_t)(ic/10.0),(Double_t)phtb[ic]);
363 if(ffillZero) fPHSum->Fill((Double_t)(ic/10.0),0.0,(Double_t)phtb[ic]);
365 if(phtb[ic] > 0.0) fPHSum->Fill((Double_t)(ic/10.0),0.0,(Double_t)phtb[ic]);
371 if(standalonetracklet) nbTrdTracksStandalone++;
372 else nbTrdTracksOffline++;
381 fNbTRDTrack->Fill(nbTrdTracks);
382 fNbTRDTrackStandalone->Fill(nbTrdTracksStandalone);
383 fNbTRDTrackOffline->Fill(nbTrdTracksOffline);
387 //printf("Nbof tracks %d\n",nbTrdTracks);
389 TFile *file = TFile::Open("test.root","RECREATE");
394 PostData(0, fContainer);
396 //printf("post container\n");
399 //________________________________________________________________________
400 void AliTRDcalibration::Terminate(Option_t *)
402 // Draw result to the screen
403 // Called once at the end of the query
405 //printf("terminate\n");
407 if(fTRDCalibraFillHisto) fTRDCalibraFillHisto->DestroyDebugStreamer();
410 //________________________________________________________
411 Bool_t AliTRDcalibration::GetRefFigure(Int_t ifig)
414 // Draw filled histos
417 gStyle->SetPalette(1);
418 gStyle->SetOptStat(1111);
419 gStyle->SetPadBorderMode(0);
420 gStyle->SetCanvasColor(10);
421 gStyle->SetPadLeftMargin(0.13);
422 gStyle->SetPadRightMargin(0.13);
424 if(!fContainer) return kFALSE;
428 TCanvas *c0 = new TCanvas("c0","c0",10,10,510,510);
429 TLegend *legNbTrack = new TLegend(.7, .7, .98, .98);
430 legNbTrack->SetBorderSize(1);
434 if(!(h = (TH1F *)fContainer->FindObject("TRDTrack"))) break;
435 if(!(ho = (TH1F *)fContainer->FindObject("TRDTrackOffline"))) break;
436 if(!(hs = (TH1F *)fContainer->FindObject("TRDTrackStandalone"))) break;
444 legNbTrack->AddEntry(h, "all", "p");
445 legNbTrack->AddEntry(ho, "offline", "p");
446 legNbTrack->AddEntry(hs, "standalone", "p");
447 legNbTrack->Draw("same");
451 TLegend *legNbTracklet = new TLegend(.7, .7, .98, .98);
452 legNbTracklet->SetBorderSize(1);
456 if(!(h = (TH1F *)fContainer->FindObject("TRDTracklet"))) break;
457 if(!(ho = (TH1F *)fContainer->FindObject("TRDTrackletOffline"))) break;
458 if(!(hs = (TH1F *)fContainer->FindObject("TRDTrackletStandalone"))) break;
462 legNbTracklet->AddEntry(h, "all", "p");
463 legNbTracklet->AddEntry(ho, "offline", "p");
464 legNbTracklet->AddEntry(hs, "standalone", "p");
465 legNbTracklet->Draw("same");
472 TLegend *legNbTimeBin = new TLegend(.7, .7, .98, .98);
473 legNbTimeBin->SetBorderSize(1);
477 if(!(h = (TH1F *)fContainer->FindObject("TimeBin"))) break;
478 if(!(ho = (TH1F *)fContainer->FindObject("TimeBinOffline"))) break;
479 if(!(hs = (TH1F *)fContainer->FindObject("TimeBinStandalone"))) break;
483 legNbTimeBin->AddEntry(h, "all", "p");
484 legNbTimeBin->AddEntry(ho, "offline", "p");
485 legNbTimeBin->AddEntry(hs, "standalone", "p");
486 legNbTimeBin->Draw("same");
493 TLegend *legNbClusters = new TLegend(.7, .7, .98, .98);
494 legNbClusters->SetBorderSize(1);
498 if(!(h = (TH1F *)fContainer->FindObject("NbClusters"))) break;
499 if(!(ho = (TH1F *)fContainer->FindObject("NbClustersOffline"))) break;
500 if(!(hs = (TH1F *)fContainer->FindObject("NbClustersStandalone"))) break;
504 legNbClusters->AddEntry(h, "all", "p");
505 legNbClusters->AddEntry(ho, "offline", "p");
506 legNbClusters->AddEntry(hs, "standalone", "p");
507 legNbClusters->Draw("same");
515 if(!(h = (TProfile2D *)fContainer->FindObject("PH2dSum"))) break;
516 TH1D *projh = h->ProjectionX("projh",1,1,"e");
524 if(!(h = (TH2I *)fContainer->FindObject("CH2dSum"))) break;
525 TH1D *projh = h->ProjectionX("projhh",1,1,"e");
533 AliInfo("Histo was not filled!");
537 if(!(h = (TProfile2D *)fContainer->FindObject("PH2d"))) break;
543 AliInfo("Histo was not filled!");
547 if(!(h = (TH2I *)fContainer->FindObject("CH2d"))) break;
553 AliInfo("Histo was not filled!");
557 if(!(h = (TProfile2D *)fContainer->FindObject("PRF2d"))) break;
563 AliInfo("vector was not filled!");
566 AliTRDCalibraVector *v = 0x0;
567 TGraphErrors *vdet = 0x0;
568 if(!(v = (AliTRDCalibraVector *)fContainer->FindObject("AliTRDCalibraVector"))) break;
569 Int_t detectormax = -1;
571 if(!v->FindTheMaxEntries(1,detectormax,groupmax)) break;
572 if(!(vdet = v->ConvertVectorPHTGraphErrors((Int_t)detectormax,groupmax,"plotPH2dVector"))) break;
573 Int_t nbeentries = 0;
574 TH1F *ko = v->CorrectTheError(vdet,nbeentries);
576 AliInfo(Form("There are %d entries in the detector %d and group %d",nbeentries,detectormax,groupmax));
581 AliInfo("vector was not filled!");
584 AliTRDCalibraVector *v = 0x0;
586 if(!(v = (AliTRDCalibraVector *)fContainer->FindObject("AliTRDCalibraVector"))) break;
587 Int_t detectormax = -1;
589 if(!v->FindTheMaxEntries(0,detectormax,groupmax)) break;
590 if(!(vdet = v->ConvertVectorCHHisto((Int_t)detectormax,groupmax,"plotCH2dVector"))) break;
592 AliInfo(Form("The detectormax and groupmax are %d and %d",detectormax,groupmax));
597 AliInfo("vector was not filled!");
600 AliTRDCalibraVector *v = 0x0;
601 TGraphErrors *vdet = 0x0;
602 if(!(v = (AliTRDCalibraVector *)fContainer->FindObject("AliTRDCalibraVector"))) break;
603 Int_t detectormax = -1;
605 Int_t nbeentries = 0;
606 if(!v->FindTheMaxEntries(2,detectormax,groupmax)) break;
607 if(!(vdet = v->ConvertVectorPRFTGraphErrors((Int_t)detectormax,groupmax,"plotPRF2dVector"))) break;
608 TH1F *ko = v->CorrectTheError(vdet,nbeentries);
610 AliInfo(Form("The detectormax and groupmax are %d and %d",detectormax,groupmax));
615 AliInfo("vdrift linear was not filled!");
618 AliTRDCalibraVdriftLinearFit *h = 0x0;
619 THnSparseS *hdetector = 0x0;
620 if(!(h = (AliTRDCalibraVdriftLinearFit *)fContainer->FindObject("AliTRDCalibraVdriftLinearFit"))) break;
621 Double_t entries[540];
622 for(Int_t k = 0; k < 540; k++){
625 if(!(hdetector = (THnSparseS *)h->GetLinearFitterHisto(k,kFALSE))) continue;
626 entries[k] = hdetector->GetEntries();
628 Double_t max = -10.0;
629 Double_t detectormax = -1;
630 for(Int_t k = 0; k < 540; k++){
631 if(entries[k] > max) {
637 if((max == 0.0) || (detectormax <0.0) || (detectormax >=540.0)) break;
638 if(!(hdetector = (THnSparseS *)h->GetLinearFitterHisto((Int_t)detectormax,kFALSE))) break;
639 AliInfo(Form("The detector with the maximum of entries is %d",detectormax));
645 if(!PostProcess()) break;
647 TGraph *fgain = (TGraph *) fGraph->At(0);
652 case kVdriftT0Factor:{
654 if(!PostProcess()) break;
656 TCanvas *c = new TCanvas("c","c",10,10,510,510);
658 TGraph *fvd = (TGraph *) fGraph->At(1);
663 TGraph *ft0 = (TGraph *) fGraph->At(2);
670 case kVdriftLorentzAngleFactor:{
672 AliInfo("vdrift linear was not filled!");
676 if(!PostProcess()) break;
678 TCanvas *c = new TCanvas("c","c",10,10,510,510);
680 TGraph *fvdl = (TGraph *) fGraph->At(3);
685 TGraph *flal = (TGraph *) fGraph->At(4);
694 if(!PostProcess()) break;
696 TGraph *fprf = (TGraph *) fGraph->At(5);
706 //________________________________________________________________________
707 Bool_t AliTRDcalibration::PostProcess()
710 // Fit the filled histos
714 fGraph = new TObjArray(6);
722 Bool_t storage[3] = {kFALSE,kFALSE,kFALSE};
725 AliCDBManager *man = AliCDBManager::Instance();
726 man->SetDefaultStorage("local://$ALICE_ROOT");
727 AliCDBStorage* storLoc = man->GetStorage(fkNameDirectory);
730 man->SetRun(fRunNumber);
733 AliCDBMetaData mdDet;
734 mdDet.SetObjectClassName("AliTRDCalDet");
735 AliCDBMetaData mdPad;
736 mdPad.SetObjectClassName("AliTRDCalPad");
738 // Objects for fitting
739 AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
740 calibra->SetDebugLevel(2); // 0 rien, 1 fitvoir, 2 debug files, 3 one detector
744 Printf("ERROR: list not available");
748 if(fHisto2d && fVector2d) AliInfo("We will only look at histos. Set fHisto2d off if you don't want");
749 AliTRDCalibraVector *calibraVector = 0x0;
750 if(fVector2d) calibraVector = (AliTRDCalibraVector *) fContainer->FindObject("CalibraVector");
754 Bool_t pass = kFALSE;
755 AliTRDCalibraVector *vvect = 0x0;
757 TH2I *histogain = (TH2I *) fContainer->FindObject("CH2d");
759 histogain->SetDirectory(0);
760 calibra->SetMinEntries(20);
761 if(fCompressPerDetector){
762 if(AddStatsPerDetector(histogain)) pass = calibra->AnalyseCH(fCHSum);
764 else pass = calibra->AnalyseCH(histogain);
768 if(fVector2d && calibraVector) {
769 calibra->SetMinEntries(20);
770 if(fCompressPerDetector){
771 if(!(vvect = calibraVector->AddStatsPerDetectorCH())) return kFALSE;
772 pass = calibra->AnalyseCH(vvect);
774 else pass = calibra->AnalyseCH(calibraVector);
780 Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(0))
781 + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(0));
782 Int_t nbfit = calibra->GetNumberFit(); //Number of fits
783 Int_t nbE = calibra->GetNumberEnt(); //Number of detector mit entries
786 (nbfit >= 0.001*nbE))
788 // create the cal objects
789 calibra->PutMeanValueOtherVectorFit(1,kTRUE);
790 TObjArray object = calibra->GetVectorFit();
791 AliTRDCalDet *objgaindet = calibra->CreateDetObjectGain(&object);
792 TObject *objgainpad = calibra->CreatePadObjectGain();
794 AliCDBId id1("TRD/Calib/ChamberGainFactor",fRunNumber, AliCDBRunRange::Infinity());
795 storLoc->Put((TObject *)objgaindet, id1, &mdDet);
796 AliCDBId id2("TRD/Calib/LocalGainFactor",fRunNumber, AliCDBRunRange::Infinity());
797 storLoc->Put((TObject *)objgainpad, id2, &mdPad);
801 if(FillGraphIndex(&object,graph)){
802 fGraph->AddAt(graph,0);
804 }//if(enough statistics?)
805 calibra->ResetVectorFit();
810 // VDRIFT average pulse height
814 TProfile2D *histodriftvelocity = (TProfile2D *) fContainer->FindObject("PH2d");
815 if(histodriftvelocity) {
816 histodriftvelocity->SetDirectory(0);
817 calibra->SetMinEntries(20*20);
818 if(fCompressPerDetector){
819 if(AddStatsPerDetector(histodriftvelocity,1)) {
820 pass = calibra->AnalysePH(fDetSumVector);
823 else pass = calibra->AnalysePH(histodriftvelocity);
827 if(fVector2d && calibraVector) {
828 calibra->SetMinEntries(20*20);
829 if(fCompressPerDetector){
830 if(!(vvect = calibraVector->AddStatsPerDetectorPH())) return kFALSE;
831 pass = calibra->AnalysePH(vvect);
833 else pass = calibra->AnalysePH(calibraVector);
838 Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(1))
839 + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(1));
840 Int_t nbfit = calibra->GetNumberFit();
841 Int_t nbE = calibra->GetNumberEnt();
844 (nbfit >= 0.001*nbE))
846 // create the cal objects
847 calibra->PutMeanValueOtherVectorFit(1,kTRUE);
848 calibra->PutMeanValueOtherVectorFit2(1,kTRUE);
849 TObjArray object = calibra->GetVectorFit();
850 AliTRDCalDet *objdriftvelocitydet = calibra->CreateDetObjectVdrift(&object,kTRUE);
851 TObject *objdriftvelocitypad = calibra->CreatePadObjectVdrift();
852 TObjArray objectt = calibra->GetVectorFit2();
853 AliTRDCalDet *objtime0det = calibra->CreateDetObjectT0(&object,kTRUE);
854 TObject *objtime0pad = calibra->CreatePadObjectT0();
856 AliCDBId id1("TRD/Calib/ChamberVdrift",fRunNumber, AliCDBRunRange::Infinity());
857 storLoc->Put((TObject *)objdriftvelocitydet, id1, &mdDet);
858 AliCDBId id2("TRD/Calib/LocalVdrift",fRunNumber, AliCDBRunRange::Infinity());
859 storLoc->Put((TObject *)objdriftvelocitypad, id2, &mdPad);
861 AliCDBId idd1("TRD/Calib/ChamberT0",fRunNumber, AliCDBRunRange::Infinity());
862 storLoc->Put((TObject *)objtime0det, idd1, &mdDet);
863 AliCDBId idd2("TRD/Calib/LocalT0",fRunNumber, AliCDBRunRange::Infinity());
864 storLoc->Put((TObject *)objtime0pad, idd2, &mdPad);
867 if(FillGraphIndex(&object,graph)){
868 fGraph->AddAt(graph,1);
870 TGraph *graphh = 0x0;
871 if(FillGraphIndex(&objectt,graphh)){
872 fGraph->AddAt(graphh,2);
874 }//if(enough statistics)
875 calibra->ResetVectorFit();
884 TProfile2D *histoprf = (TProfile2D *) fContainer->FindObject("PRF2d");
886 histoprf->SetDirectory(0);
887 calibra->SetMinEntries(600);
888 if(fCompressPerDetector){
889 if(AddStatsPerDetector(histoprf,2)) pass = calibra->AnalysePRFMarianFit(fDetSumVector);
891 else pass = calibra->AnalysePRFMarianFit(histoprf);
895 if(fVector2d && calibraVector) {
896 calibra->SetMinEntries(600);
897 if(fCompressPerDetector){
898 if(!(vvect =calibraVector->AddStatsPerDetectorPRF())) return kFALSE;
899 pass = calibra->AnalysePRFMarianFit(vvect);
901 else pass = calibra->AnalysePRFMarianFit(calibraVector);
906 Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(2))
907 + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(2));
908 Int_t nbfit = calibra->GetNumberFit();
909 Int_t nbE = calibra->GetNumberEnt();
912 (nbfit >= 0.001*nbE)) {
913 TObjArray object = calibra->GetVectorFit();
914 TObject *objPRFpad = calibra->CreatePadObjectPRF(&object);
916 AliCDBId id2("TRD/Calib/PRFWidth",fRunNumber, AliCDBRunRange::Infinity());
917 storLoc->Put((TObject *)objPRFpad, id2, &mdPad);
920 if(FillGraphIndex(&object,graph)){
921 fGraph->AddAt(graph,5);
924 calibra->ResetVectorFit();
931 AliTRDCalibraVdriftLinearFit *vlinearfit = (AliTRDCalibraVdriftLinearFit *) fContainer->FindObject("LinearVdriftFit");
933 calibra->SetMinEntries(20*20);
934 if(calibra->AnalyseLinearFitters(vlinearfit)) {
936 Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(2))
937 + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(2));
938 Int_t nbfit = calibra->GetNumberFit();
939 Int_t nbE = calibra->GetNumberEnt();
942 (nbfit >= 0.001*nbE))
944 // create the cal objects
945 calibra->PutMeanValueOtherVectorFit(1,kTRUE);
946 calibra->PutMeanValueOtherVectorFit2(1,kTRUE);
947 TObjArray object = calibra->GetVectorFit();
948 AliTRDCalDet *objdriftvelocitydet = calibra->CreateDetObjectVdrift(&object,kTRUE);
949 TObject *objdriftvelocitypad = calibra->CreatePadObjectVdrift();
950 TObjArray objectt = calibra->GetVectorFit2();
951 AliTRDCalDet *objtime0det = calibra->CreateDetObjectT0(&object,kTRUE);
952 TObject *objtime0pad = calibra->CreatePadObjectT0();
954 AliCDBId id1("TRD/Calib/ChamberVdriftLinear",fRunNumber, AliCDBRunRange::Infinity());
955 storLoc->Put((TObject *)objdriftvelocitydet, id1, &mdDet);
956 AliCDBId id2("TRD/Calib/LocalVdriftLinear",fRunNumber, AliCDBRunRange::Infinity());
957 storLoc->Put((TObject *)objdriftvelocitypad, id2, &mdPad);
959 AliCDBId idd1("TRD/Calib/ChamberLorentzAngle",fRunNumber, AliCDBRunRange::Infinity());
960 storLoc->Put((TObject *)objtime0det, idd1, &mdDet);
961 AliCDBId idd2("TRD/Calib/LocalLorentzAngle",fRunNumber, AliCDBRunRange::Infinity());
962 storLoc->Put((TObject *)objtime0pad, idd2, &mdPad);
965 if(FillGraphIndex(&object,graph)){
966 fGraph->AddAt(graph,3);
968 TGraph *graphh = 0x0;
969 if(FillGraphIndex(&objectt,graphh)){
970 fGraph->AddAt(graphh,4);
972 }//if(enough statistics)
974 calibra->ResetVectorFit();
978 fPostProcess = kTRUE;
984 //________________________________________________________________________
985 Bool_t AliTRDcalibration::FillGraphIndex(const TObjArray *vectora,TGraph *graph) const
988 // Fill one value (the first one) per detector
991 Int_t loop = (Int_t) vectora->GetEntriesFast();
993 AliInfo("The Vector Fit is not complete!");
999 for (Int_t k = 0; k < loop; k++) {
1000 if(!vectora->At(k)){
1005 x[k] = ((AliTRDCalibraFit::AliTRDFitInfo *) vectora->At(k))->GetDetector();
1006 y[k] = ((Float_t *)((AliTRDCalibraFit::AliTRDFitInfo *) vectora->At(k))->GetCoef())[0];
1009 if(!graph) graph = new TGraph(540,&x[0],&y[0]);
1012 new(graph) TGraph(540,&x[0],&y[0]);
1018 //________________________________________________________________________
1019 Bool_t AliTRDcalibration::AddStatsPerDetector(const TH2I *ch)
1022 // Add statistic per detector
1025 AliTRDCalibraMode calibMode = AliTRDCalibraMode();
1026 const char *name = ch->GetTitle();
1027 if(!SetNzFromTObject(name,0,&calibMode)) return 0x0;
1028 if(!SetNrphiFromTObject(name,0,&calibMode)) return 0x0;
1029 if(((calibMode.GetNz(0) == 100) && (calibMode.GetNrphi(0) == 100)) || ((calibMode.GetNz(0) == 10) && (calibMode.GetNrphi(0) == 10))) return kFALSE;
1031 Int_t nybins = ch->GetNbinsY();// groups number
1032 Int_t nxbins = ch->GetNbinsX();// number of bins X
1033 TAxis *xaxis = ch->GetXaxis();
1034 Double_t lowedge = xaxis->GetBinLowEdge(1);
1035 Double_t upedge = xaxis->GetBinUpEdge(nxbins);
1037 // number per chamber 2
1038 calibMode.ModePadCalibration(2,0);
1039 calibMode.ModePadFragmentation(0,2,0,0);
1040 calibMode.SetDetChamb2(0);
1041 Int_t perChamber2 = (Int_t) calibMode.GetDetChamb2(0);
1043 // number per other chamber
1044 calibMode.ModePadCalibration(0,0);
1045 calibMode.ModePadFragmentation(0,0,0,0);
1046 calibMode.SetDetChamb0(0);
1047 Int_t perChamber0 = (Int_t) calibMode.GetDetChamb0(0);
1049 if(nybins != (6*18*perChamber2+6*4*18*perChamber0)) return kFALSE;
1052 TString nname((const char *)ch->GetName());
1053 nname += "PerDetector";
1054 TString title("Nz");
1058 if(!fCHSum) fCHSum = new TH2I((const char *)nname,(const char *)title
1059 ,nxbins,lowedge,upedge,540,0,540);
1062 new(fCHSum) TH2I((const Char_t *) nname,(const char *)title
1063 ,nxbins,lowedge,upedge,540,0,540);
1065 fCHSum->SetYTitle("Detector number");
1066 fCHSum->SetXTitle("charge deposit [a.u]");
1067 fCHSum->SetZTitle("counts");
1068 fCHSum->SetStats(0);
1073 for(Int_t det = 0; det < 540; det++){
1075 Int_t numberofgroup = 0;
1076 if(AliTRDgeometry::GetStack(det) == 2) numberofgroup = perChamber2;
1077 else numberofgroup = perChamber0;
1078 TH1I *projch = (TH1I *) ch->ProjectionX("projch",counter+1,counter+numberofgroup,(Option_t *)"e");
1079 projch->SetDirectory(0);
1081 for(Int_t nx = 0; nx <= nxbins; nx++) {
1082 fCHSum->SetBinContent(nx,det+1,projch->GetBinContent(nx));
1083 fCHSum->SetBinError(nx,det+1,projch->GetBinError(nx));
1086 counter += numberofgroup;
1095 //_____________________________________________________________________________________________________________________
1096 Bool_t AliTRDcalibration::AddStatsPerDetector(const TProfile2D *ph,Int_t i)
1099 // Add statistic per detector
1102 AliTRDCalibraMode calibMode = AliTRDCalibraMode();
1103 const char *name = ph->GetTitle();
1104 //printf("name %s\n",name);
1105 if(!SetNzFromTObject(name,0,&calibMode)) return kFALSE;
1106 if(!SetNrphiFromTObject(name,0,&calibMode)) return kFALSE;
1107 if(((calibMode.GetNz(0) == 100) && (calibMode.GetNrphi(0) == 100)) || ((calibMode.GetNz(0) == 10) && (calibMode.GetNrphi(0) == 10))) return kFALSE;
1108 //printf("Found mode Mz %d, Nrphi %d\n",calibMode.GetNz(0),calibMode.GetNrphi(0));
1111 Int_t nybins = ph->GetNbinsY();// groups number
1112 Int_t nxbins = ph->GetNbinsX();// number of bins X
1113 TAxis *xaxis = ph->GetXaxis();
1114 Double_t lowedge = xaxis->GetBinLowEdge(1);
1115 Double_t upedge = xaxis->GetBinUpEdge(nxbins);
1117 // number per chamber 2
1118 calibMode.ModePadCalibration(2,0);
1119 calibMode.ModePadFragmentation(0,2,0,0);
1120 calibMode.SetDetChamb2(0);
1121 Int_t perChamber2 = (Int_t) calibMode.GetDetChamb2(0);
1123 // number per other chamber
1124 calibMode.ModePadCalibration(0,0);
1125 calibMode.ModePadFragmentation(0,0,0,0);
1126 calibMode.SetDetChamb0(0);
1127 Int_t perChamber0 = (Int_t) calibMode.GetDetChamb0(0);
1129 if(nybins != (6*18*perChamber2+6*4*18*perChamber0)) return kFALSE;
1132 TString nbname((const char *)ph->GetName());
1133 nbname += "PerDetectorVector";
1134 if(!fDetSumVector) fDetSumVector = new AliTRDCalibraVector();
1136 fDetSumVector->~AliTRDCalibraVector();
1137 new(fDetSumVector) AliTRDCalibraVector();
1140 fDetSumVector->SetTimeMax(nxbins);
1143 fDetSumVector->SetNumberBinPRF(nxbins);
1144 fDetSumVector->SetPRFRange(TMath::Abs(lowedge));
1146 fDetSumVector->SetDetCha0(i,1);
1147 fDetSumVector->SetDetCha2(i,1);
1148 fDetSumVector->SetNzNrphi(i,0,0);
1150 Int_t nbg = GetNumberOfGroupsPRF((const char *)name);
1151 fDetSumVector->SetNbGroupPRF(nbg);
1155 TString nname((const char *)ph->GetName());
1156 nname += "PerDetector";
1157 TString title("Nz");
1161 if(!fDetSum) fDetSum = new TH2D((const char *)nname,(const Char_t *) title
1162 ,nxbins,lowedge,upedge,540,0,540);
1165 new(fDetSum) TH2D((const Char_t *) nname,(const Char_t *) title
1166 ,nxbins,lowedge,upedge,540,0,540);
1168 fDetSum->SetYTitle("Detector number");
1169 fDetSum->SetXTitle(xaxis->GetTitle());
1170 fDetSum->SetStats(0);
1174 for(Int_t det = 0; det < 540; det++){
1176 Int_t numberofgroup = 0;
1177 if(AliTRDgeometry::GetStack(det) == 2) numberofgroup = perChamber2;
1178 else numberofgroup = perChamber0;
1180 for(Int_t nx = 1; nx <= nxbins; nx++) {
1182 Double_t entries = 0.0;
1183 Double_t sumw2 = 0.0;
1184 Double_t sumw = 0.0;
1186 for(Int_t k = counter+1; k <= (counter+numberofgroup); k++){
1187 Int_t binnumber = ph->GetBin(nx,k);
1188 entries += ph->GetBinEntries(binnumber);
1189 sumw2 += (ph->GetBinError(binnumber)*ph->GetBinError(binnumber)+ph->GetBinContent(binnumber)*ph->GetBinContent(binnumber))*ph->GetBinEntries(binnumber);
1190 sumw += ph->GetBinContent(binnumber)*ph->GetBinEntries(binnumber);
1193 Double_t mean = 0.0;
1194 if(entries > 0.0) mean = sumw/entries;
1195 Double_t squaremean = 0.0;
1196 if(entries > 0.0) squaremean = sumw2/entries;
1197 Double_t errorf = squaremean - mean*mean;
1198 Double_t error = 0.0;
1199 if(entries > 0.0) error = TMath::Sqrt(TMath::Abs(errorf)/entries);
1201 fDetSum->SetBinContent(nx,det+1,mean);
1202 fDetSum->SetBinError(nx,det+1,error);
1204 if(i==1) fDetSumVector->FillVectorPH(det,0,nx-1,(Int_t)entries,(Float_t)mean,(Float_t)squaremean);
1205 if(i==2) fDetSumVector->FillVectorPRF(det,0,nx-1,(Int_t)entries,(Float_t)mean,(Float_t)squaremean);
1209 counter += numberofgroup;
1217 //_____________________________________________________________________________
1218 Bool_t AliTRDcalibration::SetNrphiFromTObject(const char *name, Int_t i, AliTRDCalibraMode *calibMode) const
1221 // Set the granularity from object
1224 const Char_t *patternrphi0 = "Nrphi0";
1225 const Char_t *patternrphi1 = "Nrphi1";
1226 const Char_t *patternrphi2 = "Nrphi2";
1227 const Char_t *patternrphi3 = "Nrphi3";
1228 const Char_t *patternrphi4 = "Nrphi4";
1229 const Char_t *patternrphi5 = "Nrphi5";
1230 const Char_t *patternrphi6 = "Nrphi6";
1233 const Char_t *patternrphi10 = "Nrphi10";
1234 const Char_t *patternrphi100 = "Nrphi100";
1235 const Char_t *patternz10 = "Nz10";
1236 const Char_t *patternz100 = "Nz100";
1239 if ((strstr(name,patternrphi100)) && (strstr(name,patternz100))) {
1240 calibMode->SetAllTogether(i);
1243 if ((strstr(name,patternrphi10)) && (strstr(name,patternz10))) {
1244 calibMode->SetPerSuperModule(i);
1248 if (strstr(name,patternrphi0)) {
1249 calibMode->SetNrphi(i ,0);
1252 if (strstr(name,patternrphi1)) {
1253 calibMode->SetNrphi(i, 1);
1256 if (strstr(name,patternrphi2)) {
1257 calibMode->SetNrphi(i, 2);
1260 if (strstr(name,patternrphi3)) {
1261 calibMode->SetNrphi(i, 3);
1264 if (strstr(name,patternrphi4)) {
1265 calibMode->SetNrphi(i, 4);
1268 if (strstr(name,patternrphi5)) {
1269 calibMode->SetNrphi(i, 5);
1272 if (strstr(name,patternrphi6)) {
1273 calibMode->SetNrphi(i, 6);
1277 calibMode->SetNrphi(i ,0);
1281 //_____________________________________________________________________________
1282 Bool_t AliTRDcalibration::SetNzFromTObject(const char *name, Int_t i, AliTRDCalibraMode *calibMode) const
1285 // Set fNz[i] of the AliTRDCalibraFit::Instance()
1286 // corresponding to the given TObject
1290 const Char_t *patternz0 = "Nz0";
1291 const Char_t *patternz1 = "Nz1";
1292 const Char_t *patternz2 = "Nz2";
1293 const Char_t *patternz3 = "Nz3";
1294 const Char_t *patternz4 = "Nz4";
1296 const Char_t *patternrphi10 = "Nrphi10";
1297 const Char_t *patternrphi100 = "Nrphi100";
1298 const Char_t *patternz10 = "Nz10";
1299 const Char_t *patternz100 = "Nz100";
1301 if ((strstr(name,patternrphi100)) && (strstr(name,patternz100))) {
1302 calibMode->SetAllTogether(i);
1305 if ((strstr(name,patternrphi10)) && (strstr(name,patternz10))) {
1306 calibMode->SetPerSuperModule(i);
1309 if (strstr(name,patternz0)) {
1310 calibMode->SetNz(i, 0);
1313 if (strstr(name,patternz1)) {
1314 calibMode->SetNz(i ,1);
1317 if (strstr(name,patternz2)) {
1318 calibMode->SetNz(i ,2);
1321 if (strstr(name,patternz3)) {
1322 calibMode->SetNz(i ,3);
1325 if (strstr(name,patternz4)) {
1326 calibMode->SetNz(i ,4);
1330 calibMode->SetNz(i ,0);
1333 //____________________________________________________________________________________________________
1334 Int_t AliTRDcalibration::GetNumberOfGroupsPRF(const char* nametitle) const
1337 // Get numberofgroupsprf
1341 const Char_t *pattern0 = "Ngp0";
1342 const Char_t *pattern1 = "Ngp1";
1343 const Char_t *pattern2 = "Ngp2";
1344 const Char_t *pattern3 = "Ngp3";
1345 const Char_t *pattern4 = "Ngp4";
1346 const Char_t *pattern5 = "Ngp5";
1347 const Char_t *pattern6 = "Ngp6";
1350 if (strstr(nametitle,pattern0)) {
1353 if (strstr(nametitle,pattern1)) {
1356 if (strstr(nametitle,pattern2)) {
1359 if (strstr(nametitle,pattern3)) {
1362 if (strstr(nametitle,pattern4)) {
1365 if (strstr(nametitle,pattern5)) {
1368 if (strstr(nametitle,pattern6)){