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"
45 #include "AliTRDrecoTask.h"
46 #include "AliAnalysisManager.h"
48 #include "AliESDInputHandler.h"
49 #include "AliTRDtrackV1.h"
50 #include "AliTRDseedV1.h"
51 #include "AliTRDcluster.h"
52 #include "info/AliTRDtrackInfo.h"
53 #include "AliTRDcalibDB.h"
55 #include "AliTRDCalibraFillHisto.h"
56 #include "AliTRDCalibraFit.h"
57 #include "AliTRDCalibraVdriftLinearFit.h"
58 #include "AliTRDCalibraMode.h"
59 #include "AliTRDCalibraVector.h"
60 #include "./Cal/AliTRDCalPad.h"
61 #include "./Cal/AliTRDCalDet.h"
62 #include "AliCDBMetaData.h"
63 #include "AliCDBManager.h"
64 #include "AliCDBStorage.h"
68 #include "AliTRDcalibration.h"
71 ClassImp(AliTRDcalibration)
73 //________________________________________________________________________
74 AliTRDcalibration::AliTRDcalibration()
75 :AliTRDrecoTask("Calibration", "Calibration on tracks")
79 ,fTRDCalibraFillHisto(0)
81 ,fNbTRDTrackOffline(0)
82 ,fNbTRDTrackStandalone(0)
84 ,fNbTRDTrackletOffline(0)
85 ,fNbTRDTrackletStandalone(0)
87 ,fNbTimeBinOffline(0x0)
88 ,fNbTimeBinStandalone(0x0)
90 ,fNbClustersOffline(0)
91 ,fNbClustersStandalone(0)
103 ,fnormalizeNbOfCluster(kFALSE)
105 ,fOfflineTracks(kFALSE)
106 ,fStandaloneTracks(kFALSE)
107 ,fCompressPerDetector(kFALSE)
109 ,fkNameDirectory("local://.")
111 ,fPostProcess(kFALSE)
117 for(Int_t k = 0; k < 3; k++)
124 //________________________________________________________________________
125 AliTRDcalibration::~AliTRDcalibration()
127 // Default destructor
129 if(fNbTRDTrack) delete fNbTRDTrack;
130 if(fNbTRDTrackOffline) delete fNbTRDTrackOffline;
131 if(fNbTRDTrackStandalone) delete fNbTRDTrackStandalone;
132 if(fNbTRDTracklet) delete fNbTRDTracklet;
133 if(fNbTRDTrackletOffline) delete fNbTRDTrackletOffline;
134 if(fNbTRDTrackletStandalone) delete fNbTRDTrackletStandalone;
135 if(fNbTimeBin) delete fNbTimeBin;
136 if(fNbTimeBinOffline) delete fNbTimeBinOffline;
137 if(fNbTimeBinStandalone) delete fNbTimeBinStandalone;
138 if(fNbClusters) delete fNbClusters;
139 if(fNbClustersOffline) delete fNbClustersOffline;
140 if(fNbClustersStandalone) delete fNbClustersStandalone;
141 if(fPHSum) delete fPHSum;
142 if(fCHSum) delete fCHSum;
143 if(fDetSum) delete fDetSum;
144 if(fDetSumVector) delete fDetSumVector;
145 if(fkNameDirectory) delete fkNameDirectory;
146 if(fGraph){fGraph->Delete(); delete fGraph;}
149 //________________________________________________________________________
150 void AliTRDcalibration::CreateOutputObjects()
152 // Create output objects
154 OpenFile(0, "RECREATE");
156 // Number of time bins
157 AliTRDcalibDB *cal = AliTRDcalibDB::Instance();
158 fNbTimeBins = cal->GetNumberOfTimeBins();
160 // instance calibration: what to calibrate
161 fTRDCalibraFillHisto = AliTRDCalibraFillHisto::Instance();
162 fTRDCalibraFillHisto->SetHisto2d(fHisto2d); // choose to use histograms
163 fTRDCalibraFillHisto->SetVector2d(fVector2d); // choose to use vectors
164 fTRDCalibraFillHisto->SetCH2dOn(); // choose to calibrate the gain
165 fTRDCalibraFillHisto->SetPH2dOn(); // choose to calibrate the drift velocity
166 fTRDCalibraFillHisto->SetPRF2dOn(); // choose to look at the PRF
167 fTRDCalibraFillHisto->SetLinearFitterOn(fVdriftLinear); // Other possibility vdrift VDRIFT
168 fTRDCalibraFillHisto->SetLinearFitterDebugOn(fVdriftLinear); // Other possibility vdrift
170 // segmentation (should be per default the max and add at the end)
171 for(Int_t k = 0; k < 3; k++){
172 if(((fNz[k] != 10) && (fNrphi[k] != 10)) && ((fNz[k] != 100) && (fNrphi[k] != 100))) {
173 fTRDCalibraFillHisto->SetNz(k,fNz[k]); // Mode calibration
174 fTRDCalibraFillHisto->SetNrphi(k,fNrphi[k]); // Mode calibration
177 if((fNz[k] == 100) && (fNrphi[k] == 100)) {
178 if(fVector2d) AliInfo("The mode all together is not supported by the vector method");
179 fTRDCalibraFillHisto->SetAllTogether(k);
181 if((fNz[k] == 10) && (fNrphi[k] == 10)) {
182 if(fVector2d) AliInfo("The mode per supermodule is not supported by the vector method");
183 fTRDCalibraFillHisto->SetPerSuperModule(k);
189 fTRDCalibraFillHisto->SetDebugLevel(fDebugLevel); //debug stuff
192 fTRDCalibraFillHisto->Init2Dhistos(); // initialise the histos
195 fTRDCalibraFillHisto->SetNumberClusters(flow); // At least flow clusters
196 fTRDCalibraFillHisto->SetNumberClustersf(fhigh); // The more fhigh clusters
197 fTRDCalibraFillHisto->SetFillWithZero(ffillZero); // Fill zeros
198 fTRDCalibraFillHisto->SetNormalizeNbOfCluster(fnormalizeNbOfCluster); // For iterations
200 // Add them to the container
201 fContainer = new TObjArray();
203 fContainer->Add(fTRDCalibraFillHisto->GetCH2d()); //TH2I
204 fContainer->Add(fTRDCalibraFillHisto->GetPH2d()); //TProfile2D
205 fContainer->Add(fTRDCalibraFillHisto->GetPRF2d()); //TProfile2D
207 if(fVdriftLinear) fContainer->Add(fTRDCalibraFillHisto->GetVdriftLinearFit()); // Other drift velocity
208 if(fVector2d) fContainer->Add(fTRDCalibraFillHisto->GetCalibraVector()); //calibra vector
212 // Init the debug histos
213 fNbTRDTrack = new TH1F("TRDTrack","TRDTrack",500,0,500);
214 fNbTRDTrack->Sumw2();
215 fNbTRDTrackOffline = new TH1F("TRDTrackOffline","TRDTrackOffline",500,0,500);
216 fNbTRDTrackOffline->Sumw2();
217 fNbTRDTrackStandalone = new TH1F("TRDTrackStandalone","TRDTrackStandalone",500,0,500);
218 fNbTRDTrackStandalone->Sumw2();
220 fNbTRDTracklet = new TH1F("TRDTracklet","TRDTracklet",540,0.,540.);
221 fNbTRDTracklet->Sumw2();
222 fNbTRDTrackletOffline = new TH1F("TRDTrackletOffline","TRDTrackletOffline",540,0.,540.);
223 fNbTRDTrackletOffline->Sumw2();
224 fNbTRDTrackletStandalone = new TH1F("TRDTrackletStandalone","TRDTrackletStandalone",540,0.,540.);
225 fNbTRDTrackletStandalone->Sumw2();
227 fNbTimeBin = new TH1F("TimeBin","TimeBin",35,0,35);
229 fNbTimeBinOffline = new TH1F("TimeBinOffline","TimeBinOffline",35,0,35);
230 fNbTimeBinOffline->Sumw2();
231 fNbTimeBinStandalone = new TH1F("TimeBinStandalone","TimeBinStandalone",35,0,35);
232 fNbTimeBinStandalone->Sumw2();
234 fNbClusters = new TH1F("NbClusters","",35,0,35);
235 fNbClusters->Sumw2();
236 fNbClustersOffline = new TH1F("NbClustersOffline","",35,0,35);
237 fNbClustersOffline->Sumw2();
238 fNbClustersStandalone = new TH1F("NbClustersStandalone","",35,0,35);
239 fNbClustersStandalone->Sumw2();
241 fPHSum = new TProfile2D("PH2dSum","Nz0Nrphi0"
242 ,fNbTimeBins,-0.05,(Double_t)(fNbTimeBins/10.0)-0.05
244 fPHSum->SetYTitle("Det/pad groups");
245 fPHSum->SetXTitle("time [#mus]");
246 fPHSum->SetZTitle("<PH> [a.u.]");
249 fCHSum = new TH2I("CH2dSum","Nz0Nrphi0",100,0,300,540,0,540);
250 fCHSum->SetYTitle("Det/pad groups");
251 fCHSum->SetXTitle("charge deposit [a.u]");
252 fCHSum->SetZTitle("counts");
257 fContainer->Add(fNbTRDTrack);
258 fContainer->Add(fNbTRDTrackOffline);
259 fContainer->Add(fNbTRDTrackStandalone);
260 fContainer->Add(fNbTRDTracklet);
261 fContainer->Add(fNbTRDTrackletOffline);
262 fContainer->Add(fNbTRDTrackletStandalone);
263 fContainer->Add(fNbTimeBin);
264 fContainer->Add(fNbTimeBinOffline);
265 fContainer->Add(fNbTimeBinStandalone);
266 fContainer->Add(fNbClusters);
267 fContainer->Add(fNbClustersOffline);
268 fContainer->Add(fNbClustersStandalone);
269 fContainer->Add(fPHSum);
270 fContainer->Add(fCHSum);
276 //________________________________________________________________________
277 void AliTRDcalibration::Exec(Option_t *)
280 // Execute function where the reference data are filled
286 Int_t nbTrdTracks = 0;
288 Int_t nbTrdTracksStandalone = 0;
290 Int_t nbTrdTracksOffline = 0;
294 // Loop on track in the event
296 //printf("Total of %d\n",fTracks->GetEntriesFast());
297 for(Int_t itrk=0; itrk < fTracks->GetEntriesFast(); itrk++){
299 //printf("itrk %d\n",itrk);
301 fTrackInfo = (AliTRDtrackInfo*)fTracks->UncheckedAt(itrk);
302 ftrdTrack = fTrackInfo->GetTrack();
303 if(!ftrdTrack) continue;
307 fTRDCalibraFillHisto->UpdateHistogramsV1(ftrdTrack);
311 Bool_t standalonetracklet = kFALSE;
312 const AliTRDseedV1 *tracklet = 0x0;
314 // Loop on tracklet in the event
316 for(Int_t itr = 0; itr < 6; itr++){
317 //printf("itr %d\n",itr);
318 if(!(tracklet = ftrdTrack->GetTracklet(itr))) continue;
319 if(!tracklet->IsOK()) continue;
321 if(tracklet->IsStandAlone()) standalonetracklet = kTRUE;
322 Int_t nbclusters = 0;
324 Double_t phtb[AliTRDseedV1::kNtb];
325 memset(phtb, 0, AliTRDseedV1::kNtb*sizeof(Double_t));
329 Float_t normalisation = 6.67;
332 for(int ic=0; ic<AliTRDseedV1::kNtb; ic++){
333 // Check no shared clusters
334 for(int icc=AliTRDseedV1::kNtb; icc<AliTRDseedV1::kNclusters; icc++){
335 if((fcl = tracklet->GetClusters(icc))) crossrow = 1;
337 if(!(fcl = tracklet->GetClusters(ic))) continue;
339 Int_t time = fcl->GetPadTime();
340 Float_t ch = tracklet->GetdQdl(ic);
341 Float_t qcl = TMath::Abs(fcl->GetQ());
342 detector = fcl->GetDetector();
343 if((time>-1) && (time<fNbTimeBins)) phtb[time]=qcl;
344 sum += ch/normalisation;
345 fNbTimeBin->Fill(time);
346 if(tracklet->IsStandAlone()) fNbTimeBinStandalone->Fill(time);
347 else fNbTimeBinOffline->Fill(time);
350 fNbTRDTracklet->Fill(detector);
351 if(tracklet->IsStandAlone()) fNbTRDTrackletStandalone->Fill(detector);
352 else fNbTRDTrackletOffline->Fill(detector);
354 fNbClusters->Fill(nbclusters);
355 if(tracklet->IsStandAlone()) fNbClustersStandalone->Fill(nbclusters);
356 else fNbClustersOffline->Fill(nbclusters);
358 if((nbclusters > flow) && (nbclusters < fhigh)){
359 fCHSum->Fill(sum/20.0,0.0);
360 for(int ic=0; ic<fNbTimeBins; ic++){
361 //printf("ic %d and time %f and cluster %f \n",ic,(Double_t)(ic/10.0),(Double_t)phtb[ic]);
362 if(ffillZero) fPHSum->Fill((Double_t)(ic/10.0),0.0,(Double_t)phtb[ic]);
364 if(phtb[ic] > 0.0) fPHSum->Fill((Double_t)(ic/10.0),0.0,(Double_t)phtb[ic]);
370 if(standalonetracklet) nbTrdTracksStandalone++;
371 else nbTrdTracksOffline++;
380 fNbTRDTrack->Fill(nbTrdTracks);
381 fNbTRDTrackStandalone->Fill(nbTrdTracksStandalone);
382 fNbTRDTrackOffline->Fill(nbTrdTracksOffline);
386 //printf("Nbof tracks %d\n",nbTrdTracks);
388 TFile *file = TFile::Open("test.root","RECREATE");
393 PostData(0, fContainer);
395 //printf("post container\n");
398 //________________________________________________________________________
399 void AliTRDcalibration::Terminate(Option_t *)
401 // Draw result to the screen
402 // Called once at the end of the query
404 //printf("terminate\n");
406 if(fTRDCalibraFillHisto) fTRDCalibraFillHisto->DestroyDebugStreamer();
409 //________________________________________________________
410 Bool_t AliTRDcalibration::GetRefFigure(Int_t ifig)
413 // Draw filled histos
416 gStyle->SetPalette(1);
417 gStyle->SetOptStat(1111);
418 gStyle->SetPadBorderMode(0);
419 gStyle->SetCanvasColor(10);
420 gStyle->SetPadLeftMargin(0.13);
421 gStyle->SetPadRightMargin(0.13);
423 if(!fContainer) return kFALSE;
427 TCanvas *c0 = new TCanvas("c0","c0",10,10,510,510);
428 TLegend *legNbTrack = new TLegend(.7, .7, .98, .98);
429 legNbTrack->SetBorderSize(1);
433 if(!(h = (TH1F *)fContainer->FindObject("TRDTrack"))) break;
434 if(!(ho = (TH1F *)fContainer->FindObject("TRDTrackOffline"))) break;
435 if(!(hs = (TH1F *)fContainer->FindObject("TRDTrackStandalone"))) break;
443 legNbTrack->AddEntry(h, "all", "p");
444 legNbTrack->AddEntry(ho, "offline", "p");
445 legNbTrack->AddEntry(hs, "standalone", "p");
446 legNbTrack->Draw("same");
450 TLegend *legNbTracklet = new TLegend(.7, .7, .98, .98);
451 legNbTracklet->SetBorderSize(1);
455 if(!(h = (TH1F *)fContainer->FindObject("TRDTracklet"))) break;
456 if(!(ho = (TH1F *)fContainer->FindObject("TRDTrackletOffline"))) break;
457 if(!(hs = (TH1F *)fContainer->FindObject("TRDTrackletStandalone"))) break;
461 legNbTracklet->AddEntry(h, "all", "p");
462 legNbTracklet->AddEntry(ho, "offline", "p");
463 legNbTracklet->AddEntry(hs, "standalone", "p");
464 legNbTracklet->Draw("same");
471 TLegend *legNbTimeBin = new TLegend(.7, .7, .98, .98);
472 legNbTimeBin->SetBorderSize(1);
476 if(!(h = (TH1F *)fContainer->FindObject("TimeBin"))) break;
477 if(!(ho = (TH1F *)fContainer->FindObject("TimeBinOffline"))) break;
478 if(!(hs = (TH1F *)fContainer->FindObject("TimeBinStandalone"))) break;
482 legNbTimeBin->AddEntry(h, "all", "p");
483 legNbTimeBin->AddEntry(ho, "offline", "p");
484 legNbTimeBin->AddEntry(hs, "standalone", "p");
485 legNbTimeBin->Draw("same");
492 TLegend *legNbClusters = new TLegend(.7, .7, .98, .98);
493 legNbClusters->SetBorderSize(1);
497 if(!(h = (TH1F *)fContainer->FindObject("NbClusters"))) break;
498 if(!(ho = (TH1F *)fContainer->FindObject("NbClustersOffline"))) break;
499 if(!(hs = (TH1F *)fContainer->FindObject("NbClustersStandalone"))) break;
503 legNbClusters->AddEntry(h, "all", "p");
504 legNbClusters->AddEntry(ho, "offline", "p");
505 legNbClusters->AddEntry(hs, "standalone", "p");
506 legNbClusters->Draw("same");
514 if(!(h = (TProfile2D *)fContainer->FindObject("PH2dSum"))) break;
515 TH1D *projh = h->ProjectionX("projh",1,1,"e");
523 if(!(h = (TH2I *)fContainer->FindObject("CH2dSum"))) break;
524 TH1D *projh = h->ProjectionX("projhh",1,1,"e");
532 AliInfo("Histo was not filled!");
536 if(!(h = (TProfile2D *)fContainer->FindObject("PH2d"))) break;
542 AliInfo("Histo was not filled!");
546 if(!(h = (TH2I *)fContainer->FindObject("CH2d"))) break;
552 AliInfo("Histo was not filled!");
556 if(!(h = (TProfile2D *)fContainer->FindObject("PRF2d"))) break;
562 AliInfo("vector was not filled!");
565 AliTRDCalibraVector *v = 0x0;
566 TGraphErrors *vdet = 0x0;
567 if(!(v = (AliTRDCalibraVector *)fContainer->FindObject("AliTRDCalibraVector"))) break;
568 Int_t detectormax = -1;
570 if(!v->FindTheMaxEntries(1,detectormax,groupmax)) break;
571 if(!(vdet = v->ConvertVectorPHTGraphErrors((Int_t)detectormax,groupmax,"plotPH2dVector"))) break;
572 Int_t nbeentries = 0;
573 TH1F *ko = v->CorrectTheError(vdet,nbeentries);
575 AliInfo(Form("There are %d entries in the detector %d and group %d",nbeentries,detectormax,groupmax));
580 AliInfo("vector was not filled!");
583 AliTRDCalibraVector *v = 0x0;
585 if(!(v = (AliTRDCalibraVector *)fContainer->FindObject("AliTRDCalibraVector"))) break;
586 Int_t detectormax = -1;
588 if(!v->FindTheMaxEntries(0,detectormax,groupmax)) break;
589 if(!(vdet = v->ConvertVectorCHHisto((Int_t)detectormax,groupmax,"plotCH2dVector"))) break;
591 AliInfo(Form("The detectormax and groupmax are %d and %d",detectormax,groupmax));
596 AliInfo("vector was not filled!");
599 AliTRDCalibraVector *v = 0x0;
600 TGraphErrors *vdet = 0x0;
601 if(!(v = (AliTRDCalibraVector *)fContainer->FindObject("AliTRDCalibraVector"))) break;
602 Int_t detectormax = -1;
604 Int_t nbeentries = 0;
605 if(!v->FindTheMaxEntries(2,detectormax,groupmax)) break;
606 if(!(vdet = v->ConvertVectorPRFTGraphErrors((Int_t)detectormax,groupmax,"plotPRF2dVector"))) break;
607 TH1F *ko = v->CorrectTheError(vdet,nbeentries);
609 AliInfo(Form("The detectormax and groupmax are %d and %d",detectormax,groupmax));
614 AliInfo("vdrift linear was not filled!");
617 AliTRDCalibraVdriftLinearFit *h = 0x0;
618 TH2F *hdetector = 0x0;
619 if(!(h = (AliTRDCalibraVdriftLinearFit *)fContainer->FindObject("AliTRDCalibraVdriftLinearFit"))) break;
620 Double_t entries[540];
621 for(Int_t k = 0; k < 540; k++){
624 if(!(hdetector = h->GetLinearFitterHisto(k,kFALSE))) continue;
625 entries[k] = hdetector->GetEntries();
627 Double_t max = -10.0;
628 Double_t detectormax = -1;
629 for(Int_t k = 0; k < 540; k++){
630 if(entries[k] > max) {
636 if((max == 0.0) || (detectormax <0.0) || (detectormax >=540.0)) break;
637 if(!(hdetector = h->GetLinearFitterHisto((Int_t)detectormax,kFALSE))) break;
638 AliInfo(Form("The detector with the maximum of entries is %d",detectormax));
644 if(!PostProcess()) break;
646 TGraph *fgain = (TGraph *) fGraph->At(0);
651 case kVdriftT0Factor:{
653 if(!PostProcess()) break;
655 TCanvas *c = new TCanvas("c","c",10,10,510,510);
657 TGraph *fvd = (TGraph *) fGraph->At(1);
662 TGraph *ft0 = (TGraph *) fGraph->At(2);
669 case kVdriftLorentzAngleFactor:{
671 AliInfo("vdrift linear was not filled!");
675 if(!PostProcess()) break;
677 TCanvas *c = new TCanvas("c","c",10,10,510,510);
679 TGraph *fvdl = (TGraph *) fGraph->At(3);
684 TGraph *flal = (TGraph *) fGraph->At(4);
693 if(!PostProcess()) break;
695 TGraph *fprf = (TGraph *) fGraph->At(5);
705 //________________________________________________________________________
706 Bool_t AliTRDcalibration::PostProcess()
709 // Fit the filled histos
713 fGraph = new TObjArray(6);
721 Bool_t storage[3] = {kFALSE,kFALSE,kFALSE};
724 AliCDBManager *man = AliCDBManager::Instance();
725 man->SetDefaultStorage("local://$ALICE_ROOT");
726 AliCDBStorage* storLoc = man->GetStorage(fkNameDirectory);
729 man->SetRun(fRunNumber);
732 AliCDBMetaData mdDet;
733 mdDet.SetObjectClassName("AliTRDCalDet");
734 AliCDBMetaData mdPad;
735 mdPad.SetObjectClassName("AliTRDCalPad");
737 // Objects for fitting
738 AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
739 calibra->SetDebugLevel(2); // 0 rien, 1 fitvoir, 2 debug files, 3 one detector
743 Printf("ERROR: list not available");
747 if(fHisto2d && fVector2d) AliInfo("We will only look at histos. Set fHisto2d off if you don't want");
748 AliTRDCalibraVector *calibraVector = 0x0;
749 if(fVector2d) calibraVector = (AliTRDCalibraVector *) fContainer->FindObject("CalibraVector");
753 Bool_t pass = kFALSE;
754 AliTRDCalibraVector *vvect = 0x0;
756 TH2I *histogain = (TH2I *) fContainer->FindObject("CH2d");
758 histogain->SetDirectory(0);
759 calibra->SetMinEntries(20);
760 if(fCompressPerDetector){
761 if(AddStatsPerDetector(histogain)) pass = calibra->AnalyseCH(fCHSum);
763 else pass = calibra->AnalyseCH(histogain);
767 if(fVector2d && calibraVector) {
768 calibra->SetMinEntries(20);
769 if(fCompressPerDetector){
770 if(!(vvect = calibraVector->AddStatsPerDetectorCH())) return kFALSE;
771 pass = calibra->AnalyseCH(vvect);
773 else pass = calibra->AnalyseCH(calibraVector);
779 Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(0))
780 + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(0));
781 Int_t nbfit = calibra->GetNumberFit(); //Number of fits
782 Int_t nbE = calibra->GetNumberEnt(); //Number of detector mit entries
785 (nbfit >= 0.001*nbE))
787 // create the cal objects
788 calibra->PutMeanValueOtherVectorFit(1,kTRUE);
789 TObjArray object = calibra->GetVectorFit();
790 AliTRDCalDet *objgaindet = calibra->CreateDetObjectGain(&object);
791 TObject *objgainpad = calibra->CreatePadObjectGain();
793 AliCDBId id1("TRD/Calib/ChamberGainFactor",fRunNumber, AliCDBRunRange::Infinity());
794 storLoc->Put((TObject *)objgaindet, id1, &mdDet);
795 AliCDBId id2("TRD/Calib/LocalGainFactor",fRunNumber, AliCDBRunRange::Infinity());
796 storLoc->Put((TObject *)objgainpad, id2, &mdPad);
800 if(FillGraphIndex(&object,graph)){
801 fGraph->AddAt(graph,0);
803 }//if(enough statistics?)
804 calibra->ResetVectorFit();
809 // VDRIFT average pulse height
813 TProfile2D *histodriftvelocity = (TProfile2D *) fContainer->FindObject("PH2d");
814 if(histodriftvelocity) {
815 histodriftvelocity->SetDirectory(0);
816 calibra->SetMinEntries(20*20);
817 if(fCompressPerDetector){
818 if(AddStatsPerDetector(histodriftvelocity,1)) {
819 pass = calibra->AnalysePH(fDetSumVector);
822 else pass = calibra->AnalysePH(histodriftvelocity);
826 if(fVector2d && calibraVector) {
827 calibra->SetMinEntries(20*20);
828 if(fCompressPerDetector){
829 if(!(vvect = calibraVector->AddStatsPerDetectorPH())) return kFALSE;
830 pass = calibra->AnalysePH(vvect);
832 else pass = calibra->AnalysePH(calibraVector);
837 Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(1))
838 + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(1));
839 Int_t nbfit = calibra->GetNumberFit();
840 Int_t nbE = calibra->GetNumberEnt();
843 (nbfit >= 0.001*nbE))
845 // create the cal objects
846 calibra->PutMeanValueOtherVectorFit(1,kTRUE);
847 calibra->PutMeanValueOtherVectorFit2(1,kTRUE);
848 TObjArray object = calibra->GetVectorFit();
849 AliTRDCalDet *objdriftvelocitydet = calibra->CreateDetObjectVdrift(&object,kTRUE);
850 TObject *objdriftvelocitypad = calibra->CreatePadObjectVdrift();
851 TObjArray objectt = calibra->GetVectorFit2();
852 AliTRDCalDet *objtime0det = calibra->CreateDetObjectT0(&object,kTRUE);
853 TObject *objtime0pad = calibra->CreatePadObjectT0();
855 AliCDBId id1("TRD/Calib/ChamberVdrift",fRunNumber, AliCDBRunRange::Infinity());
856 storLoc->Put((TObject *)objdriftvelocitydet, id1, &mdDet);
857 AliCDBId id2("TRD/Calib/LocalVdrift",fRunNumber, AliCDBRunRange::Infinity());
858 storLoc->Put((TObject *)objdriftvelocitypad, id2, &mdPad);
860 AliCDBId idd1("TRD/Calib/ChamberT0",fRunNumber, AliCDBRunRange::Infinity());
861 storLoc->Put((TObject *)objtime0det, idd1, &mdDet);
862 AliCDBId idd2("TRD/Calib/LocalT0",fRunNumber, AliCDBRunRange::Infinity());
863 storLoc->Put((TObject *)objtime0pad, idd2, &mdPad);
866 if(FillGraphIndex(&object,graph)){
867 fGraph->AddAt(graph,1);
869 TGraph *graphh = 0x0;
870 if(FillGraphIndex(&objectt,graphh)){
871 fGraph->AddAt(graphh,2);
873 }//if(enough statistics)
874 calibra->ResetVectorFit();
883 TProfile2D *histoprf = (TProfile2D *) fContainer->FindObject("PRF2d");
885 histoprf->SetDirectory(0);
886 calibra->SetMinEntries(600);
887 if(fCompressPerDetector){
888 if(AddStatsPerDetector(histoprf,2)) pass = calibra->AnalysePRFMarianFit(fDetSumVector);
890 else pass = calibra->AnalysePRFMarianFit(histoprf);
894 if(fVector2d && calibraVector) {
895 calibra->SetMinEntries(600);
896 if(fCompressPerDetector){
897 if(!(vvect =calibraVector->AddStatsPerDetectorPRF())) return kFALSE;
898 pass = calibra->AnalysePRFMarianFit(vvect);
900 else pass = calibra->AnalysePRFMarianFit(calibraVector);
905 Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(2))
906 + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(2));
907 Int_t nbfit = calibra->GetNumberFit();
908 Int_t nbE = calibra->GetNumberEnt();
911 (nbfit >= 0.001*nbE)) {
912 TObjArray object = calibra->GetVectorFit();
913 TObject *objPRFpad = calibra->CreatePadObjectPRF(&object);
915 AliCDBId id2("TRD/Calib/PRFWidth",fRunNumber, AliCDBRunRange::Infinity());
916 storLoc->Put((TObject *)objPRFpad, id2, &mdPad);
919 if(FillGraphIndex(&object,graph)){
920 fGraph->AddAt(graph,5);
923 calibra->ResetVectorFit();
930 AliTRDCalibraVdriftLinearFit *vlinearfit = (AliTRDCalibraVdriftLinearFit *) fContainer->FindObject("LinearVdriftFit");
932 calibra->SetMinEntries(20*20);
933 if(calibra->AnalyseLinearFitters(vlinearfit)) {
935 Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(2))
936 + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(2));
937 Int_t nbfit = calibra->GetNumberFit();
938 Int_t nbE = calibra->GetNumberEnt();
941 (nbfit >= 0.001*nbE))
943 // create the cal objects
944 calibra->PutMeanValueOtherVectorFit(1,kTRUE);
945 calibra->PutMeanValueOtherVectorFit2(1,kTRUE);
946 TObjArray object = calibra->GetVectorFit();
947 AliTRDCalDet *objdriftvelocitydet = calibra->CreateDetObjectVdrift(&object,kTRUE);
948 TObject *objdriftvelocitypad = calibra->CreatePadObjectVdrift();
949 TObjArray objectt = calibra->GetVectorFit2();
950 AliTRDCalDet *objtime0det = calibra->CreateDetObjectT0(&object,kTRUE);
951 TObject *objtime0pad = calibra->CreatePadObjectT0();
953 AliCDBId id1("TRD/Calib/ChamberVdriftLinear",fRunNumber, AliCDBRunRange::Infinity());
954 storLoc->Put((TObject *)objdriftvelocitydet, id1, &mdDet);
955 AliCDBId id2("TRD/Calib/LocalVdriftLinear",fRunNumber, AliCDBRunRange::Infinity());
956 storLoc->Put((TObject *)objdriftvelocitypad, id2, &mdPad);
958 AliCDBId idd1("TRD/Calib/ChamberLorentzAngle",fRunNumber, AliCDBRunRange::Infinity());
959 storLoc->Put((TObject *)objtime0det, idd1, &mdDet);
960 AliCDBId idd2("TRD/Calib/LocalLorentzAngle",fRunNumber, AliCDBRunRange::Infinity());
961 storLoc->Put((TObject *)objtime0pad, idd2, &mdPad);
964 if(FillGraphIndex(&object,graph)){
965 fGraph->AddAt(graph,3);
967 TGraph *graphh = 0x0;
968 if(FillGraphIndex(&objectt,graphh)){
969 fGraph->AddAt(graphh,4);
971 }//if(enough statistics)
973 calibra->ResetVectorFit();
977 fPostProcess = kTRUE;
983 //________________________________________________________________________
984 Bool_t AliTRDcalibration::FillGraphIndex(const TObjArray *vectora,TGraph *graph) const
987 // Fill one value (the first one) per detector
990 Int_t loop = (Int_t) vectora->GetEntriesFast();
992 AliInfo("The Vector Fit is not complete!");
998 for (Int_t k = 0; k < loop; k++) {
1004 x[k] = ((AliTRDCalibraFit::AliTRDFitInfo *) vectora->At(k))->GetDetector();
1005 y[k] = ((Float_t *)((AliTRDCalibraFit::AliTRDFitInfo *) vectora->At(k))->GetCoef())[0];
1008 if(!graph) graph = new TGraph(540,&x[0],&y[0]);
1011 new(graph) TGraph(540,&x[0],&y[0]);
1017 //________________________________________________________________________
1018 Bool_t AliTRDcalibration::AddStatsPerDetector(const TH2I *ch)
1021 // Add statistic per detector
1024 AliTRDCalibraMode calibMode = AliTRDCalibraMode();
1025 const char *name = ch->GetTitle();
1026 if(!SetNzFromTObject(name,0,&calibMode)) return 0x0;
1027 if(!SetNrphiFromTObject(name,0,&calibMode)) return 0x0;
1028 if(((calibMode.GetNz(0) == 100) && (calibMode.GetNrphi(0) == 100)) || ((calibMode.GetNz(0) == 10) && (calibMode.GetNrphi(0) == 10))) return kFALSE;
1030 Int_t nybins = ch->GetNbinsY();// groups number
1031 Int_t nxbins = ch->GetNbinsX();// number of bins X
1032 TAxis *xaxis = ch->GetXaxis();
1033 Double_t lowedge = xaxis->GetBinLowEdge(1);
1034 Double_t upedge = xaxis->GetBinUpEdge(nxbins);
1036 // number per chamber 2
1037 calibMode.ModePadCalibration(2,0);
1038 calibMode.ModePadFragmentation(0,2,0,0);
1039 calibMode.SetDetChamb2(0);
1040 Int_t perChamber2 = (Int_t) calibMode.GetDetChamb2(0);
1042 // number per other chamber
1043 calibMode.ModePadCalibration(0,0);
1044 calibMode.ModePadFragmentation(0,0,0,0);
1045 calibMode.SetDetChamb0(0);
1046 Int_t perChamber0 = (Int_t) calibMode.GetDetChamb0(0);
1048 if(nybins != (6*18*perChamber2+6*4*18*perChamber0)) return kFALSE;
1051 TString nname((const char *)ch->GetName());
1052 nname += "PerDetector";
1053 TString title("Nz");
1057 if(!fCHSum) fCHSum = new TH2I((const char *)nname,(const char *)title
1058 ,nxbins,lowedge,upedge,540,0,540);
1061 new(fCHSum) TH2I((const Char_t *) nname,(const char *)title
1062 ,nxbins,lowedge,upedge,540,0,540);
1064 fCHSum->SetYTitle("Detector number");
1065 fCHSum->SetXTitle("charge deposit [a.u]");
1066 fCHSum->SetZTitle("counts");
1067 fCHSum->SetStats(0);
1072 for(Int_t det = 0; det < 540; det++){
1074 Int_t numberofgroup = 0;
1075 if(AliTRDgeometry::GetStack(det) == 2) numberofgroup = perChamber2;
1076 else numberofgroup = perChamber0;
1077 TH1I *projch = (TH1I *) ch->ProjectionX("projch",counter+1,counter+numberofgroup,(Option_t *)"e");
1078 projch->SetDirectory(0);
1080 for(Int_t nx = 0; nx <= nxbins; nx++) {
1081 fCHSum->SetBinContent(nx,det+1,projch->GetBinContent(nx));
1082 fCHSum->SetBinError(nx,det+1,projch->GetBinError(nx));
1085 counter += numberofgroup;
1094 //_____________________________________________________________________________________________________________________
1095 Bool_t AliTRDcalibration::AddStatsPerDetector(const TProfile2D *ph,Int_t i)
1098 // Add statistic per detector
1101 AliTRDCalibraMode calibMode = AliTRDCalibraMode();
1102 const char *name = ph->GetTitle();
1103 //printf("name %s\n",name);
1104 if(!SetNzFromTObject(name,0,&calibMode)) return kFALSE;
1105 if(!SetNrphiFromTObject(name,0,&calibMode)) return kFALSE;
1106 if(((calibMode.GetNz(0) == 100) && (calibMode.GetNrphi(0) == 100)) || ((calibMode.GetNz(0) == 10) && (calibMode.GetNrphi(0) == 10))) return kFALSE;
1107 //printf("Found mode Mz %d, Nrphi %d\n",calibMode.GetNz(0),calibMode.GetNrphi(0));
1110 Int_t nybins = ph->GetNbinsY();// groups number
1111 Int_t nxbins = ph->GetNbinsX();// number of bins X
1112 TAxis *xaxis = ph->GetXaxis();
1113 Double_t lowedge = xaxis->GetBinLowEdge(1);
1114 Double_t upedge = xaxis->GetBinUpEdge(nxbins);
1116 // number per chamber 2
1117 calibMode.ModePadCalibration(2,0);
1118 calibMode.ModePadFragmentation(0,2,0,0);
1119 calibMode.SetDetChamb2(0);
1120 Int_t perChamber2 = (Int_t) calibMode.GetDetChamb2(0);
1122 // number per other chamber
1123 calibMode.ModePadCalibration(0,0);
1124 calibMode.ModePadFragmentation(0,0,0,0);
1125 calibMode.SetDetChamb0(0);
1126 Int_t perChamber0 = (Int_t) calibMode.GetDetChamb0(0);
1128 if(nybins != (6*18*perChamber2+6*4*18*perChamber0)) return kFALSE;
1131 TString nbname((const char *)ph->GetName());
1132 nbname += "PerDetectorVector";
1133 if(!fDetSumVector) fDetSumVector = new AliTRDCalibraVector();
1135 fDetSumVector->~AliTRDCalibraVector();
1136 new(fDetSumVector) AliTRDCalibraVector();
1139 fDetSumVector->SetTimeMax(nxbins);
1142 fDetSumVector->SetNumberBinPRF(nxbins);
1143 fDetSumVector->SetPRFRange(TMath::Abs(lowedge));
1145 fDetSumVector->SetDetCha0(i,1);
1146 fDetSumVector->SetDetCha2(i,1);
1147 fDetSumVector->SetNzNrphi(i,0,0);
1149 Int_t nbg = GetNumberOfGroupsPRF((const char *)name);
1150 fDetSumVector->SetNbGroupPRF(nbg);
1154 TString nname((const char *)ph->GetName());
1155 nname += "PerDetector";
1156 TString title("Nz");
1160 if(!fDetSum) fDetSum = new TH2D((const char *)nname,(const Char_t *) title
1161 ,nxbins,lowedge,upedge,540,0,540);
1164 new(fDetSum) TH2D((const Char_t *) nname,(const Char_t *) title
1165 ,nxbins,lowedge,upedge,540,0,540);
1167 fDetSum->SetYTitle("Detector number");
1168 fDetSum->SetXTitle(xaxis->GetTitle());
1169 fDetSum->SetStats(0);
1173 for(Int_t det = 0; det < 540; det++){
1175 Int_t numberofgroup = 0;
1176 if(AliTRDgeometry::GetStack(det) == 2) numberofgroup = perChamber2;
1177 else numberofgroup = perChamber0;
1179 for(Int_t nx = 1; nx <= nxbins; nx++) {
1181 Double_t entries = 0.0;
1182 Double_t sumw2 = 0.0;
1183 Double_t sumw = 0.0;
1185 for(Int_t k = counter+1; k <= (counter+numberofgroup); k++){
1186 Int_t binnumber = ph->GetBin(nx,k);
1187 entries += ph->GetBinEntries(binnumber);
1188 sumw2 += (ph->GetBinError(binnumber)*ph->GetBinError(binnumber)+ph->GetBinContent(binnumber)*ph->GetBinContent(binnumber))*ph->GetBinEntries(binnumber);
1189 sumw += ph->GetBinContent(binnumber)*ph->GetBinEntries(binnumber);
1192 Double_t mean = 0.0;
1193 if(entries > 0.0) mean = sumw/entries;
1194 Double_t squaremean = 0.0;
1195 if(entries > 0.0) squaremean = sumw2/entries;
1196 Double_t errorf = squaremean - mean*mean;
1197 Double_t error = 0.0;
1198 if(entries > 0.0) error = TMath::Sqrt(TMath::Abs(errorf)/entries);
1200 fDetSum->SetBinContent(nx,det+1,mean);
1201 fDetSum->SetBinError(nx,det+1,error);
1203 if(i==1) fDetSumVector->FillVectorPH(det,0,nx-1,(Int_t)entries,(Float_t)mean,(Float_t)squaremean);
1204 if(i==2) fDetSumVector->FillVectorPRF(det,0,nx-1,(Int_t)entries,(Float_t)mean,(Float_t)squaremean);
1208 counter += numberofgroup;
1216 //_____________________________________________________________________________
1217 Bool_t AliTRDcalibration::SetNrphiFromTObject(const char *name, Int_t i, AliTRDCalibraMode *calibMode) const
1220 // Set the granularity from object
1223 const Char_t *patternrphi0 = "Nrphi0";
1224 const Char_t *patternrphi1 = "Nrphi1";
1225 const Char_t *patternrphi2 = "Nrphi2";
1226 const Char_t *patternrphi3 = "Nrphi3";
1227 const Char_t *patternrphi4 = "Nrphi4";
1228 const Char_t *patternrphi5 = "Nrphi5";
1229 const Char_t *patternrphi6 = "Nrphi6";
1232 const Char_t *patternrphi10 = "Nrphi10";
1233 const Char_t *patternrphi100 = "Nrphi100";
1234 const Char_t *patternz10 = "Nz10";
1235 const Char_t *patternz100 = "Nz100";
1238 if ((strstr(name,patternrphi100)) && (strstr(name,patternz100))) {
1239 calibMode->SetAllTogether(i);
1242 if ((strstr(name,patternrphi10)) && (strstr(name,patternz10))) {
1243 calibMode->SetPerSuperModule(i);
1247 if (strstr(name,patternrphi0)) {
1248 calibMode->SetNrphi(i ,0);
1251 if (strstr(name,patternrphi1)) {
1252 calibMode->SetNrphi(i, 1);
1255 if (strstr(name,patternrphi2)) {
1256 calibMode->SetNrphi(i, 2);
1259 if (strstr(name,patternrphi3)) {
1260 calibMode->SetNrphi(i, 3);
1263 if (strstr(name,patternrphi4)) {
1264 calibMode->SetNrphi(i, 4);
1267 if (strstr(name,patternrphi5)) {
1268 calibMode->SetNrphi(i, 5);
1271 if (strstr(name,patternrphi6)) {
1272 calibMode->SetNrphi(i, 6);
1276 calibMode->SetNrphi(i ,0);
1280 //_____________________________________________________________________________
1281 Bool_t AliTRDcalibration::SetNzFromTObject(const char *name, Int_t i, AliTRDCalibraMode *calibMode) const
1284 // Set fNz[i] of the AliTRDCalibraFit::Instance()
1285 // corresponding to the given TObject
1289 const Char_t *patternz0 = "Nz0";
1290 const Char_t *patternz1 = "Nz1";
1291 const Char_t *patternz2 = "Nz2";
1292 const Char_t *patternz3 = "Nz3";
1293 const Char_t *patternz4 = "Nz4";
1295 const Char_t *patternrphi10 = "Nrphi10";
1296 const Char_t *patternrphi100 = "Nrphi100";
1297 const Char_t *patternz10 = "Nz10";
1298 const Char_t *patternz100 = "Nz100";
1300 if ((strstr(name,patternrphi100)) && (strstr(name,patternz100))) {
1301 calibMode->SetAllTogether(i);
1304 if ((strstr(name,patternrphi10)) && (strstr(name,patternz10))) {
1305 calibMode->SetPerSuperModule(i);
1308 if (strstr(name,patternz0)) {
1309 calibMode->SetNz(i, 0);
1312 if (strstr(name,patternz1)) {
1313 calibMode->SetNz(i ,1);
1316 if (strstr(name,patternz2)) {
1317 calibMode->SetNz(i ,2);
1320 if (strstr(name,patternz3)) {
1321 calibMode->SetNz(i ,3);
1324 if (strstr(name,patternz4)) {
1325 calibMode->SetNz(i ,4);
1329 calibMode->SetNz(i ,0);
1332 //____________________________________________________________________________________________________
1333 Int_t AliTRDcalibration::GetNumberOfGroupsPRF(const char* nametitle) const
1336 // Get numberofgroupsprf
1340 const Char_t *pattern0 = "Ngp0";
1341 const Char_t *pattern1 = "Ngp1";
1342 const Char_t *pattern2 = "Ngp2";
1343 const Char_t *pattern3 = "Ngp3";
1344 const Char_t *pattern4 = "Ngp4";
1345 const Char_t *pattern5 = "Ngp5";
1346 const Char_t *pattern6 = "Ngp6";
1349 if (strstr(nametitle,pattern0)) {
1352 if (strstr(nametitle,pattern1)) {
1355 if (strstr(nametitle,pattern2)) {
1358 if (strstr(nametitle,pattern3)) {
1361 if (strstr(nametitle,pattern4)) {
1364 if (strstr(nametitle,pattern5)) {
1367 if (strstr(nametitle,pattern6)){