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 // AliTRDCalibraFillHisto
22 // This class is for the TRD calibration of the relative gain factor, the drift velocity,
23 // the time 0 and the pad response function. It fills histos or vectors.
24 // It can be used for the calibration per chamber but also per group of pads and eventually per pad.
25 // The user has to choose with the functions SetNz and SetNrphi the precision of the calibration (see AliTRDCalibraMode).
26 // 2D Histograms (Histo2d) or vectors (Vector2d), then converted in Trees, will be filled
27 // from RAW DATA in a run or from reconstructed TRD tracks during the offline tracking
28 // in the function "FollowBackProlongation" (AliTRDtracker)
29 // Per default the functions to fill are off.
32 // R. Bailhache (R.Bailhache@gsi.de, rbailhache@ikf.uni-frankfurt.de)
33 // J. Book (jbook@ikf.uni-frankfurt.de)
35 //////////////////////////////////////////////////////////////////////////////////////
37 #include <TProfile2D.h>
42 #include <TObjArray.h>
47 #include <TStopwatch.h>
49 #include <TDirectory.h>
50 #include <TTreeStream.h>
52 #include <TLinearFitter.h>
56 #include "AliTRDCalibraFillHisto.h"
57 #include "AliTRDCalibraMode.h"
58 #include "AliTRDCalibraVector.h"
59 #include "AliTRDCalibraVdriftLinearFit.h"
60 #include "AliTRDcalibDB.h"
61 #include "AliTRDCommonParam.h"
62 #include "AliTRDpadPlane.h"
63 #include "AliTRDcluster.h"
64 #include "AliTRDtrackV1.h"
65 #include "AliRawReader.h"
66 #include "AliRawReaderDate.h"
67 #include "AliTRDgeometry.h"
68 #include "./Cal/AliTRDCalROC.h"
69 #include "./Cal/AliTRDCalPad.h"
70 #include "./Cal/AliTRDCalDet.h"
72 #include "AliTRDdigitsManager.h"
73 #include "AliTRDdigitsParam.h"
74 #include "AliTRDSignalIndex.h"
75 #include "AliTRDarrayADC.h"
77 #include "AliTRDrawStream.h"
79 #include "AliCDBEntry.h"
80 #include "AliCDBManager.h"
87 ClassImp(AliTRDCalibraFillHisto)
89 AliTRDCalibraFillHisto* AliTRDCalibraFillHisto::fgInstance = 0;
90 Bool_t AliTRDCalibraFillHisto::fgTerminated = kFALSE;
92 //_____________singleton implementation_________________________________________________
93 AliTRDCalibraFillHisto *AliTRDCalibraFillHisto::Instance()
96 // Singleton implementation
99 if (fgTerminated != kFALSE) {
103 if (fgInstance == 0) {
104 fgInstance = new AliTRDCalibraFillHisto();
111 //______________________________________________________________________________________
112 void AliTRDCalibraFillHisto::Terminate()
115 // Singleton implementation
116 // Deletes the instance of this class
119 fgTerminated = kTRUE;
121 if (fgInstance != 0) {
128 //______________________________________________________________________________________
129 AliTRDCalibraFillHisto::AliTRDCalibraFillHisto()
139 ,fLinearFitterOn(kFALSE)
140 ,fLinearFitterDebugOn(kFALSE)
142 ,fThresholdClusterPRF2(15.0)
143 ,fLimitChargeIntegration(kFALSE)
144 ,fFillWithZero(kFALSE)
145 ,fNormalizeNbOfCluster(kFALSE)
149 ,fSubVersionGainUsed(0)
150 ,fVersionGainLocalUsed(0)
151 ,fSubVersionGainLocalUsed(0)
152 ,fVersionVdriftUsed(0)
153 ,fSubVersionVdriftUsed(0)
154 ,fCalibraMode(new AliTRDCalibraMode())
157 ,fDetectorPreviousTrack(-1)
161 ,fNumberClustersf(30)
162 ,fNumberClustersProcent(0.5)
163 ,fThresholdClustersDAQ(120.0)
171 ,fNumberBinCharge(50)
177 ,fGoodTracklet(kTRUE)
178 ,fLinearFitterTracklet(0x0)
180 ,fEntriesLinearFitter(0x0)
185 ,fLinearFitterArray(540)
186 ,fLinearVdriftFit(0x0)
191 // Default constructor
195 // Init some default values
198 fNumberUsedCh[0] = 0;
199 fNumberUsedCh[1] = 0;
200 fNumberUsedPh[0] = 0;
201 fNumberUsedPh[1] = 0;
203 fGeo = new AliTRDgeometry();
204 fCalibDB = AliTRDcalibDB::Instance();
207 //______________________________________________________________________________________
208 AliTRDCalibraFillHisto::AliTRDCalibraFillHisto(const AliTRDCalibraFillHisto &c)
215 ,fPRF2dOn(c.fPRF2dOn)
216 ,fHisto2d(c.fHisto2d)
217 ,fVector2d(c.fVector2d)
218 ,fLinearFitterOn(c.fLinearFitterOn)
219 ,fLinearFitterDebugOn(c.fLinearFitterDebugOn)
220 ,fRelativeScale(c.fRelativeScale)
221 ,fThresholdClusterPRF2(c.fThresholdClusterPRF2)
222 ,fLimitChargeIntegration(c.fLimitChargeIntegration)
223 ,fFillWithZero(c.fFillWithZero)
224 ,fNormalizeNbOfCluster(c.fNormalizeNbOfCluster)
225 ,fMaxCluster(c.fMaxCluster)
226 ,fNbMaxCluster(c.fNbMaxCluster)
227 ,fVersionGainUsed(c.fVersionGainUsed)
228 ,fSubVersionGainUsed(c.fSubVersionGainUsed)
229 ,fVersionGainLocalUsed(c.fVersionGainLocalUsed)
230 ,fSubVersionGainLocalUsed(c.fSubVersionGainLocalUsed)
231 ,fVersionVdriftUsed(c.fVersionVdriftUsed)
232 ,fSubVersionVdriftUsed(c.fSubVersionVdriftUsed)
235 ,fDebugLevel(c.fDebugLevel)
236 ,fDetectorPreviousTrack(c.fDetectorPreviousTrack)
237 ,fMCMPrevious(c.fMCMPrevious)
238 ,fROBPrevious(c.fROBPrevious)
239 ,fNumberClusters(c.fNumberClusters)
240 ,fNumberClustersf(c.fNumberClustersf)
241 ,fNumberClustersProcent(c.fNumberClustersProcent)
242 ,fThresholdClustersDAQ(c.fThresholdClustersDAQ)
243 ,fNumberRowDAQ(c.fNumberRowDAQ)
244 ,fNumberColDAQ(c.fNumberColDAQ)
245 ,fProcent(c.fProcent)
246 ,fDifference(c.fDifference)
247 ,fNumberTrack(c.fNumberTrack)
248 ,fTimeMax(c.fTimeMax)
250 ,fNumberBinCharge(c.fNumberBinCharge)
251 ,fNumberBinPRF(c.fNumberBinPRF)
252 ,fNgroupprf(c.fNgroupprf)
256 ,fGoodTracklet(c.fGoodTracklet)
257 ,fLinearFitterTracklet(0x0)
259 ,fEntriesLinearFitter(0x0)
264 ,fLinearFitterArray(540)
265 ,fLinearVdriftFit(0x0)
272 if(c.fCalibraMode) fCalibraMode = new AliTRDCalibraMode(*c.fCalibraMode);
273 if(c.fCalibraVector) fCalibraVector = new AliTRDCalibraVector(*c.fCalibraVector);
275 fPH2d = new TProfile2D(*c.fPH2d);
276 fPH2d->SetDirectory(0);
279 fPRF2d = new TProfile2D(*c.fPRF2d);
280 fPRF2d->SetDirectory(0);
283 fCH2d = new TH2I(*c.fCH2d);
284 fCH2d->SetDirectory(0);
286 if(c.fLinearVdriftFit){
287 fLinearVdriftFit = new AliTRDCalibraVdriftLinearFit(*c.fLinearVdriftFit);
290 if(c.fCalDetGain) fCalDetGain = new AliTRDCalDet(*c.fCalDetGain);
291 if(c.fCalROCGain) fCalROCGain = new AliTRDCalROC(*c.fCalROCGain);
296 fGeo = new AliTRDgeometry();
297 fCalibDB = AliTRDcalibDB::Instance();
299 fNumberUsedCh[0] = 0;
300 fNumberUsedCh[1] = 0;
301 fNumberUsedPh[0] = 0;
302 fNumberUsedPh[1] = 0;
306 //____________________________________________________________________________________
307 AliTRDCalibraFillHisto::~AliTRDCalibraFillHisto()
310 // AliTRDCalibraFillHisto destructor
314 if ( fDebugStreamer ) delete fDebugStreamer;
316 if ( fCalDetGain ) delete fCalDetGain;
317 if ( fCalROCGain ) delete fCalROCGain;
319 if( fLinearFitterTracklet ) { delete fLinearFitterTracklet; }
323 delete [] fEntriesCH;
324 delete [] fEntriesLinearFitter;
327 for(Int_t idet=0; idet<AliTRDgeometry::kNdet; idet++){
328 TLinearFitter *f = (TLinearFitter*)fLinearFitterArray.At(idet);
331 if(fLinearVdriftFit) delete fLinearVdriftFit;
337 //_____________________________________________________________________________
338 void AliTRDCalibraFillHisto::Destroy()
349 //_____________________________________________________________________________
350 void AliTRDCalibraFillHisto::DestroyDebugStreamer()
353 // Delete DebugStreamer
356 if ( fDebugStreamer ) delete fDebugStreamer;
357 fDebugStreamer = 0x0;
360 //_____________________________________________________________________________
361 void AliTRDCalibraFillHisto::ClearHistos()
381 //////////////////////////////////////////////////////////////////////////////////
382 // calibration with AliTRDtrackV1: Init, Update
383 //////////////////////////////////////////////////////////////////////////////////
384 //____________Functions for initialising the AliTRDCalibraFillHisto in the code_________
385 Bool_t AliTRDCalibraFillHisto::Init2Dhistos(Int_t nboftimebin)
388 // Init the histograms and stuff to be filled
393 AliTRDcalibDB *cal = AliTRDcalibDB::Instance();
395 AliInfo("Could not get calibDB");
398 AliTRDCommonParam *parCom = AliTRDCommonParam::Instance();
400 AliInfo("Could not get CommonParam");
405 if(nboftimebin > 0) fTimeMax = nboftimebin;
406 else fTimeMax = cal->GetNumberOfTimeBinsDCS();
407 if(fTimeMax <= 0) fTimeMax = 30;
408 printf("////////////////////////////////////////////\n");
409 printf("Number of time bins in calibration component %d\n",fTimeMax);
410 printf("////////////////////////////////////////////\n");
411 fSf = parCom->GetSamplingFrequency();
412 if(!fNormalizeNbOfCluster) fRelativeScale = 20.0;
413 else fRelativeScale = 1.18;
414 fNumberClustersf = fTimeMax;
415 fNumberClusters = (Int_t)(fNumberClustersProcent*fTimeMax);
417 // Init linear fitter
418 if(!fLinearFitterTracklet) {
419 fLinearFitterTracklet = new TLinearFitter(2,"pol1");
420 fLinearFitterTracklet->StoreData(kTRUE);
423 // Calcul Xbins Chambd0, Chamb2
424 Int_t ntotal0 = CalculateTotalNumberOfBins(0);
425 Int_t ntotal1 = CalculateTotalNumberOfBins(1);
426 Int_t ntotal2 = CalculateTotalNumberOfBins(2);
428 // If vector method On initialised all the stuff
430 fCalibraVector = new AliTRDCalibraVector();
431 fCalibraVector->SetNumberBinCharge(fNumberBinCharge);
432 fCalibraVector->SetTimeMax(fTimeMax);
433 if(fNgroupprf != 0) {
434 fCalibraVector->SetNumberBinPRF(2*fNgroupprf*fNumberBinPRF);
435 fCalibraVector->SetPRFRange((Float_t)(3.0*fNgroupprf));
438 fCalibraVector->SetNumberBinPRF(fNumberBinPRF);
439 fCalibraVector->SetPRFRange(1.5);
441 for(Int_t k = 0; k < 3; k++){
442 fCalibraVector->SetDetCha0(k,fCalibraMode->GetDetChamb0(k));
443 fCalibraVector->SetDetCha2(k,fCalibraMode->GetDetChamb2(k));
445 fCalibraVector->SetNzNrphi(0,fCalibraMode->GetNz(0),fCalibraMode->GetNrphi(0));
446 fCalibraVector->SetNzNrphi(1,fCalibraMode->GetNz(1),fCalibraMode->GetNrphi(1));
447 fCalibraVector->SetNzNrphi(2,fCalibraMode->GetNz(2),fCalibraMode->GetNrphi(2));
448 fCalibraVector->SetNbGroupPRF(fNgroupprf);
451 // Create the 2D histos corresponding to the pad groupCalibration mode
454 AliInfo(Form("The pad calibration mode for the relative gain calibration: Nz %d, and Nrphi %d"
455 ,fCalibraMode->GetNz(0)
456 ,fCalibraMode->GetNrphi(0)));
458 // Create the 2D histo
463 fAmpTotal = new Float_t[TMath::Max(fCalibraMode->GetDetChamb2(0),fCalibraMode->GetDetChamb0(0))];
464 for (Int_t k = 0; k < TMath::Max(fCalibraMode->GetDetChamb2(0),fCalibraMode->GetDetChamb0(0)); k++) {
468 fEntriesCH = new Int_t[ntotal0];
469 for(Int_t k = 0; k < ntotal0; k++){
476 AliInfo(Form("The pad calibration mode for the drift velocity calibration: Nz %d, and Nrphi %d"
477 ,fCalibraMode->GetNz(1)
478 ,fCalibraMode->GetNrphi(1)));
480 // Create the 2D histo
485 fPHPlace = new Short_t[fTimeMax];
486 for (Int_t k = 0; k < fTimeMax; k++) {
489 fPHValue = new Float_t[fTimeMax];
490 for (Int_t k = 0; k < fTimeMax; k++) {
494 if (fLinearFitterOn) {
495 if(fLinearFitterDebugOn) {
496 fLinearFitterArray.SetName("ArrayLinearFitters");
497 fEntriesLinearFitter = new Int_t[540];
498 for(Int_t k = 0; k < 540; k++){
499 fEntriesLinearFitter[k] = 0;
502 fLinearVdriftFit = new AliTRDCalibraVdriftLinearFit();
507 AliInfo(Form("The pad calibration mode for the PRF calibration: Nz %d, and Nrphi %d"
508 ,fCalibraMode->GetNz(2)
509 ,fCalibraMode->GetNrphi(2)));
510 // Create the 2D histo
512 CreatePRF2d(ntotal2);
519 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
520 Bool_t AliTRDCalibraFillHisto::InitCalDet()
523 // Init the Gain Cal Det
528 AliCDBEntry *entry = AliCDBManager::Instance()->Get("TRD/Calib/ChamberGainFactor",AliCDBManager::Instance()->GetRun(),fVersionGainUsed,fSubVersionGainUsed);
530 AliError("No gain det calibration entry found");
533 AliTRDCalDet *calDet = (AliTRDCalDet *)entry->GetObject();
535 AliError("No calDet gain found");
541 fCalDetGain->~AliTRDCalDet();
542 new(fCalDetGain) AliTRDCalDet(*(calDet));
543 }else fCalDetGain = new AliTRDCalDet(*(calDet));
548 name += fVersionGainUsed;
550 name += fSubVersionGainUsed;
552 name += fCalibraMode->GetNz(0);
554 name += fCalibraMode->GetNrphi(0);
556 fCH2d->SetTitle(name);
559 TString namee("Ver");
560 namee += fVersionVdriftUsed;
562 namee += fSubVersionVdriftUsed;
564 namee += fCalibraMode->GetNz(1);
566 namee += fCalibraMode->GetNrphi(1);
568 fPH2d->SetTitle(namee);
574 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
575 Bool_t AliTRDCalibraFillHisto::InitCalPad(Int_t detector)
578 // Init the Gain Cal Pad
583 AliCDBEntry *entry = AliCDBManager::Instance()->Get("TRD/Calib/LocalGainFactor",AliCDBManager::Instance()->GetRun(),fVersionGainLocalUsed,fSubVersionGainLocalUsed);
585 AliError("No gain pad calibration entry found");
588 AliTRDCalPad *calPad = (AliTRDCalPad *)entry->GetObject();
590 AliError("No calPad gain found");
593 AliTRDCalROC *calRoc = (AliTRDCalROC *)calPad->GetCalROC(detector);
595 AliError("No calRoc gain found");
600 fCalROCGain->~AliTRDCalROC();
601 new(fCalROCGain) AliTRDCalROC(*(calRoc));
602 }else fCalROCGain = new AliTRDCalROC(*(calRoc));
611 //____________Offline tracking in the AliTRDtracker____________________________
612 Bool_t AliTRDCalibraFillHisto::UpdateHistogramsV1(const AliTRDtrackV1 *t)
615 // Use AliTRDtrackV1 for the calibration
619 const AliTRDseedV1 *tracklet = 0x0; // tracklet per plane
620 AliTRDcluster *cl = 0x0; // cluster attached now to the tracklet
621 AliTRDcluster *cls = 0x0; // shared cluster attached now to the tracklet
622 Bool_t newtr = kTRUE; // new track
625 // AliTRDcalibDB *cal = AliTRDcalibDB::Instance();
628 AliInfo("Could not get calibDB");
633 AliInfo("Could not get calibDB");
638 ///////////////////////////
639 // loop over the tracklet
640 ///////////////////////////
641 for(Int_t itr = 0; itr < 6; itr++){
643 if(!(tracklet = t->GetTracklet(itr))) continue;
644 if(!tracklet->IsOK()) continue;
646 ResetfVariablestracklet();
648 //////////////////////////////////////////
649 // localisation of the tracklet and dqdl
650 //////////////////////////////////////////
651 Int_t layer = tracklet->GetPlane();
653 while(!(cl = tracklet->GetClusters(ic++))) continue;
654 Int_t detector = cl->GetDetector();
655 if (detector != fDetectorPreviousTrack) {
656 // if not a new track
658 // don't use the rest of this track if in the same plane
659 if (layer == GetLayer(fDetectorPreviousTrack)) {
660 //printf("bad tracklet, same layer for detector %d\n",detector);
664 //Localise the detector bin
665 LocalisationDetectorXbins(detector);
667 if(!fIsHLT) InitCalPad(detector);
670 fDetectorPreviousTrack = detector;
674 ////////////////////////////
675 // loop over the clusters
676 ////////////////////////////
677 Int_t nbclusters = 0;
678 for(int jc=0; jc<AliTRDseedV1::kNtb; jc++){
679 if(!(cl = tracklet->GetClusters(jc))) continue;
682 // Store the info bis of the tracklet
683 Int_t row = cl->GetPadRow();
684 Int_t col = cl->GetPadCol();
685 CheckGoodTrackletV1(cl);
686 Int_t group[2] = {0,0};
687 if(fCH2dOn) group[0] = CalculateCalibrationGroup(0,row,col);
688 if(fPH2dOn) group[1] = CalculateCalibrationGroup(1,row,col);
689 // Add the charge if shared cluster
690 cls = tracklet->GetClusters(jc+AliTRDseedV1::kNtb);
692 StoreInfoCHPHtrack(cl, tracklet->GetdQdl(jc),group,row,col,cls);
695 ////////////////////////////////////////
696 // Fill the stuffs if a good tracklet
697 ////////////////////////////////////////
700 // drift velocity unables to cut bad tracklets
701 Bool_t pass = FindP1TrackPHtrackletV1(tracklet, nbclusters);
703 //printf("pass %d and nbclusters %d\n",pass,nbclusters);
707 FillTheInfoOfTheTrackCH(nbclusters);
712 FillTheInfoOfTheTrackPH();
715 if(pass && fPRF2dOn) HandlePRFtrackletV1(tracklet,nbclusters);
717 } // if a good tracklet
723 ///////////////////////////////////////////////////////////////////////////////////
724 // Routine inside the update with AliTRDtrack
725 ///////////////////////////////////////////////////////////////////////////////////
726 //____________Offine tracking in the AliTRDtracker_____________________________
727 Bool_t AliTRDCalibraFillHisto::FindP1TrackPHtrackletV1(const AliTRDseedV1 *tracklet, Int_t nbclusters)
730 // Drift velocity calibration:
731 // Fit the clusters with a straight line
732 // From the slope find the drift velocity
735 ////////////////////////////////////////////////
736 //Number of points: if less than 3 return kFALSE
737 /////////////////////////////////////////////////
738 if(nbclusters <= 2) return kFALSE;
743 // results of the linear fit
744 Double_t dydt = 0.0; // dydt tracklet after straight line fit
745 Double_t errorpar = 0.0; // error after straight line fit on dy/dt
746 Double_t pointError = 0.0; // error after straight line fit
747 // pad row problemes: avoid tracklet that cross pad rows, tilting angle in the constant
748 Int_t crossrow = 0; // if it crosses a pad row
749 Int_t rowp = -1; // if it crosses a pad row
750 Float_t tnt = tracklet->GetTilt(); // tan tiltingangle
751 fLinearFitterTracklet->ClearPoints();
754 ///////////////////////////////////////////
755 // Take the parameters of the track
756 //////////////////////////////////////////
757 // take now the snp, tnp and tgl from the track
758 Double_t snp = tracklet->GetSnp(); // sin dy/dx at the end of the chamber
759 Double_t tnp = 0.0; // dy/dx at the end of the chamber
760 if( TMath::Abs(snp) < 1.){
761 tnp = snp / TMath::Sqrt((1.-snp)*(1.+snp));
763 Double_t tgl = tracklet->GetTgl(); // dz/dl
764 Double_t dzdx = tgl*TMath::Sqrt(1+tnp*tnp); // dz/dx calculated from dz/dl
766 //Double_t tnp = tracklet->GetYref(1); // dy/dx at the entrance of the chamber
767 //Double_t tgl = tracklet->GetZref(1); // dz/dl at the entrance of the chamber
768 //Double_t dzdx = tgl; //*TMath::Sqrt(1+tnp*tnp); // dz/dx from dz/dl
769 // at the end with correction due to linear fit
770 //Double_t tnp = tracklet->GetYfit(1); // dy/dx at the end of the chamber after fit correction
771 //Double_t tgl = tracklet->GetZfit(1); // dz/dl at the end of the chamber after fit correction
774 ////////////////////////////
775 // loop over the clusters
776 ////////////////////////////
778 AliTRDcluster *cl = 0x0;
779 //////////////////////////////
780 // Check no shared clusters
781 //////////////////////////////
782 for(int icc=AliTRDseedV1::kNtb; icc<AliTRDseedV1::kNclusters; icc++){
783 cl = tracklet->GetClusters(icc);
786 //////////////////////////////////
788 //////////////////////////////////
789 for(int ic=0; ic<AliTRDseedV1::kNtb; ic++){
790 if(!(cl = tracklet->GetClusters(ic))) continue;
791 if((fLimitChargeIntegration) && (!cl->IsInChamber())) continue;
793 Double_t ycluster = cl->GetY();
794 Int_t time = cl->GetPadTime();
795 Double_t timeis = time/fSf;
796 //See if cross two pad rows
797 Int_t row = cl->GetPadRow();
798 if(rowp==-1) rowp = row;
799 if(row != rowp) crossrow = 1;
801 fLinearFitterTracklet->AddPoint(&timeis,ycluster,1);
807 ////////////////////////////////////
808 // Do the straight line fit now
809 ///////////////////////////////////
811 fLinearFitterTracklet->ClearPoints();
815 fLinearFitterTracklet->Eval();
816 fLinearFitterTracklet->GetParameters(pars);
817 pointError = TMath::Sqrt(fLinearFitterTracklet->GetChisquare()/(nbli-2));
818 errorpar = fLinearFitterTracklet->GetParError(1)*pointError;
820 //printf("chis %f, nbli %d, pointError %f, parError %f, errorpar %f\n",fLinearFitterTracklet->GetChisquare(),nbli,pointError,fLinearFitterTracklet->GetParError(1),errorpar);
821 fLinearFitterTracklet->ClearPoints();
823 ////////////////////////////////
825 ///////////////////////////////
829 if ( !fDebugStreamer ) {
831 TDirectory *backup = gDirectory;
832 fDebugStreamer = new TTreeSRedirector("TRDdebugCalibraFill.root");
833 if ( backup ) backup->cd(); //we don't want to be cd'd to the debug streamer
837 Int_t layer = GetLayer(fDetectorPreviousTrack);
839 (* fDebugStreamer) << "FindP1TrackPHtrackletV1"<<
840 //"snpright="<<snpright<<
842 "nbclusters="<<nbclusters<<
843 "detector="<<fDetectorPreviousTrack<<
851 "crossrow="<<crossrow<<
852 "errorpar="<<errorpar<<
853 "pointError="<<pointError<<
858 /////////////////////////
860 ////////////////////////
862 if(nbclusters < fNumberClusters) return kFALSE;
863 if(nbclusters > fNumberClustersf) return kFALSE;
864 if(pointError >= 0.3) return kFALSE;
865 if(crossrow == 1) return kTRUE;
867 ///////////////////////
869 //////////////////////
872 //Add to the linear fitter of the detector
873 if( TMath::Abs(snp) < 1.){
874 Double_t x = tnp-dzdx*tnt;
875 if(fLinearFitterDebugOn) {
876 (GetLinearFitter(fDetectorPreviousTrack,kTRUE))->AddPoint(&x,dydt);
877 fEntriesLinearFitter[fDetectorPreviousTrack]++;
879 fLinearVdriftFit->Update(fDetectorPreviousTrack,x,pars[1]);
885 //____________Offine tracking in the AliTRDtracker_____________________________
886 Bool_t AliTRDCalibraFillHisto::HandlePRFtrackletV1(const AliTRDseedV1 *tracklet, Int_t nbclusters)
889 // PRF width calibration
890 // Assume a Gaussian shape: determinate the position of the three pad clusters
891 // Fit with a straight line
892 // Take the fitted values for all the clusters (3 or 2 pad clusters)
893 // Fill the PRF as function of angle of the track
898 ///////////////////////////////////////////
899 // Take the parameters of the track
900 //////////////////////////////////////////
901 // take now the snp, tnp and tgl from the track
902 Double_t snp = tracklet->GetSnp(); // sin dy/dx at the end of the chamber
903 Double_t tnp = 0.0; // dy/dx at the end of the chamber
904 if( TMath::Abs(snp) < 1.){
905 tnp = snp / TMath::Sqrt((1.-snp)*(1.+snp));
907 Double_t tgl = tracklet->GetTgl(); // dz/dl
908 Double_t dzdx = tgl*TMath::Sqrt(1+tnp*tnp); // dz/dx calculated from dz/dl
910 //Double_t tnp = tracklet->GetYref(1); // dy/dx at the entrance of the chamber
911 //Double_t tgl = tracklet->GetZref(1); // dz/dl at the entrance of the chamber
912 //Double_t dzdx = tgl; //*TMath::Sqrt(1+tnp*tnp); // dz/dx from dz/dl
913 // at the end with correction due to linear fit
914 //Double_t tnp = tracklet->GetYfit(1); // dy/dx at the end of the chamber after fit correction
915 //Double_t tgl = tracklet->GetZfit(1); // dz/dl at the end of the chamber after fit correction
917 ///////////////////////////////
918 // Calculate tnp group shift
919 ///////////////////////////////
920 Bool_t echec = kFALSE;
921 Double_t shift = 0.0;
922 //Calculate the shift in x coresponding to this tnp
923 if(fNgroupprf != 0.0){
924 shift = -3.0*(fNgroupprf-1)-1.5;
925 Double_t limithigh = -0.2*(fNgroupprf-1);
926 if((tnp < (-0.2*fNgroupprf)) || (tnp > (0.2*fNgroupprf))) echec = kTRUE;
928 while(tnp > limithigh){
934 // do nothing if out of tnp range
935 //printf("echec %d\n",(Int_t)echec);
936 if(echec) return kFALSE;
938 ///////////////////////
940 //////////////////////
942 Int_t nb3pc = 0; // number of three pads clusters used for fit
943 // to see the difference between the fit and the 3 pad clusters position
944 Double_t padPositions[AliTRDseedV1::kNtb];
945 memset(padPositions, 0, AliTRDseedV1::kNtb*sizeof(Double_t));
946 fLinearFitterTracklet->ClearPoints();
948 //printf("loop clusters \n");
949 ////////////////////////////
950 // loop over the clusters
951 ////////////////////////////
952 AliTRDcluster *cl = 0x0;
953 for(int ic=0; ic<AliTRDseedV1::kNtb; ic++){
954 // reject shared clusters on pad row
955 if((ic+AliTRDseedV1::kNtb) < AliTRDseedV1::kNclusters) {
956 cl = tracklet->GetClusters(ic+AliTRDseedV1::kNtb);
959 cl = tracklet->GetClusters(ic);
961 Double_t time = cl->GetPadTime();
962 if((time<=7) || (time>=21)) continue;
963 Short_t *signals = cl->GetSignals();
964 Float_t xcenter = 0.0;
965 Bool_t echec1 = kTRUE;
967 /////////////////////////////////////////////////////////////
968 // Center 3 balanced: position with the center of the pad
969 /////////////////////////////////////////////////////////////
970 if ((((Float_t) signals[3]) > 0.0) &&
971 (((Float_t) signals[2]) > 0.0) &&
972 (((Float_t) signals[4]) > 0.0)) {
974 // Security if the denomiateur is 0
975 if ((((Float_t) (((Float_t) signals[3]) * ((Float_t) signals[3]))) /
976 ((Float_t) (((Float_t) signals[2]) * ((Float_t) signals[4])))) != 1.0) {
977 xcenter = 0.5 * (TMath::Log((Float_t) (((Float_t) signals[4]) / ((Float_t) signals[2]))))
978 / (TMath::Log(((Float_t) (((Float_t) signals[3]) * ((Float_t) signals[3])))
979 / ((Float_t) (((Float_t) signals[2]) * ((Float_t) signals[4])))));
985 if(TMath::Abs(xcenter) > 0.5) echec1 = kTRUE;
988 ////////////////////////////////////////////////////////
989 //if no echec1: calculate with the position of the pad
990 // Position of the cluster
991 // fill the linear fitter
992 ///////////////////////////////////////////////////////
993 Double_t padPosition = xcenter + cl->GetPadCol();
994 padPositions[ic] = padPosition;
996 fLinearFitterTracklet->AddPoint(&time, padPosition,1);
1001 //printf("Fin loop clusters \n");
1002 //////////////////////////////
1003 // fit with a straight line
1004 /////////////////////////////
1006 fLinearFitterTracklet->ClearPoints();
1009 fLinearFitterTracklet->Eval();
1011 fLinearFitterTracklet->GetParameters(line);
1012 Float_t pointError = -1.0;
1013 if( fLinearFitterTracklet->GetChisquare()>=0.0) {
1014 pointError = TMath::Sqrt( fLinearFitterTracklet->GetChisquare()/(nb3pc-2));
1016 fLinearFitterTracklet->ClearPoints();
1018 //printf("PRF second loop \n");
1019 ////////////////////////////////////////////////
1020 // Fill the PRF: Second loop over clusters
1021 //////////////////////////////////////////////
1022 for(int ic=0; ic<AliTRDseedV1::kNtb; ic++){
1023 // reject shared clusters on pad row
1024 cl = tracklet->GetClusters(ic+AliTRDseedV1::kNtb);
1025 if(((ic+AliTRDseedV1::kNtb) < AliTRDseedV1::kNclusters) && (cl)) continue;
1027 cl = tracklet->GetClusters(ic);
1030 Short_t *signals = cl->GetSignals(); // signal
1031 Double_t time = cl->GetPadTime(); // time bin
1032 Float_t padPosTracklet = line[0]+line[1]*time; // reconstruct position from fit
1033 Float_t padPos = cl->GetPadCol(); // middle pad
1034 Double_t dpad = padPosTracklet - padPos; // reconstruct position relative to middle pad from fit
1035 Float_t ycenter = 0.0; // relative center charge
1036 Float_t ymin = 0.0; // relative left charge
1037 Float_t ymax = 0.0; // relative right charge
1039 ////////////////////////////////////////////////////////////////
1040 // Calculate ycenter, ymin and ymax even for two pad clusters
1041 ////////////////////////////////////////////////////////////////
1042 if(((((Float_t) signals[3]) > 0.0) && (((Float_t) signals[2]) > 0.0)) ||
1043 ((((Float_t) signals[3]) > 0.0) && (((Float_t) signals[4]) > 0.0))){
1044 Float_t sum = ((Float_t) signals[2]) + ((Float_t) signals[3]) + ((Float_t) signals[4]);
1045 if(sum > 0.0) ycenter = ((Float_t) signals[3])/ sum;
1046 if(sum > 0.0) ymin = ((Float_t) signals[2])/ sum;
1047 if(sum > 0.0) ymax = ((Float_t) signals[4])/ sum;
1050 /////////////////////////
1051 // Calibration group
1052 ////////////////////////
1053 Int_t rowcl = cl->GetPadRow(); // row of cluster
1054 Int_t colcl = cl->GetPadCol(); // col of cluster
1055 Int_t grouplocal = CalculateCalibrationGroup(2,rowcl,colcl); // calcul the corresponding group
1056 Int_t caligroup = fCalibraMode->GetXbins(2)+ grouplocal; // calcul the corresponding group
1057 Float_t xcl = cl->GetY(); // y cluster
1058 Float_t qcl = cl->GetQ(); // charge cluster
1059 Int_t layer = GetLayer(fDetectorPreviousTrack); // layer
1060 Int_t stack = GetStack(fDetectorPreviousTrack); // stack
1061 Double_t xdiff = dpad; // reconstructed position constant
1062 Double_t x = dpad; // reconstructed position moved
1063 Float_t ep = pointError; // error of fit
1064 Float_t signal1 = (Float_t)signals[1]; // signal at the border
1065 Float_t signal3 = (Float_t)signals[3]; // signal
1066 Float_t signal2 = (Float_t)signals[2]; // signal
1067 Float_t signal4 = (Float_t)signals[4]; // signal
1068 Float_t signal5 = (Float_t)signals[5]; // signal at the border
1072 /////////////////////
1074 ////////////////////
1076 if(fDebugLevel > 0){
1077 if ( !fDebugStreamer ) {
1079 TDirectory *backup = gDirectory;
1080 fDebugStreamer = new TTreeSRedirector("TRDdebugCalibraFill.root");
1081 if ( backup ) backup->cd(); //we don't want to be cd'd to the debug streamer
1086 Float_t y = ycenter;
1087 (* fDebugStreamer) << "HandlePRFtrackletV1"<<
1088 "caligroup="<<caligroup<<
1089 "detector="<<fDetectorPreviousTrack<<
1092 "npoints="<<nbclusters<<
1101 "padPosition="<<padPositions[ic]<<
1102 "padPosTracklet="<<padPosTracklet<<
1107 "signal1="<<signal1<<
1108 "signal2="<<signal2<<
1109 "signal3="<<signal3<<
1110 "signal4="<<signal4<<
1111 "signal5="<<signal5<<
1117 (* fDebugStreamer) << "HandlePRFtrackletV1"<<
1118 "caligroup="<<caligroup<<
1119 "detector="<<fDetectorPreviousTrack<<
1122 "npoints="<<nbclusters<<
1131 "padPosition="<<padPositions[ic]<<
1132 "padPosTracklet="<<padPosTracklet<<
1137 "signal1="<<signal1<<
1138 "signal2="<<signal2<<
1139 "signal3="<<signal3<<
1140 "signal4="<<signal4<<
1141 "signal5="<<signal5<<
1147 (* fDebugStreamer) << "HandlePRFtrackletV1"<<
1148 "caligroup="<<caligroup<<
1149 "detector="<<fDetectorPreviousTrack<<
1152 "npoints="<<nbclusters<<
1161 "padPosition="<<padPositions[ic]<<
1162 "padPosTracklet="<<padPosTracklet<<
1167 "signal1="<<signal1<<
1168 "signal2="<<signal2<<
1169 "signal3="<<signal3<<
1170 "signal4="<<signal4<<
1171 "signal5="<<signal5<<
1177 /////////////////////
1179 /////////////////////
1180 if(nbclusters < fNumberClusters) continue;
1181 if(nbclusters > fNumberClustersf) continue;
1182 if(nb3pc <= 5) continue;
1183 if((time >= 21) || (time < 7)) continue;
1184 if(TMath::Abs(qcl) < 80) continue;
1185 if( TMath::Abs(snp) > 1.) continue;
1188 ////////////////////////
1190 ///////////////////////
1192 if(TMath::Abs(dpad) < 1.5) {
1193 fPRF2d->Fill(shift+dpad,(caligroup+0.5),ycenter);
1194 fPRF2d->Fill(shift-dpad,(caligroup+0.5),ycenter);
1195 //printf("place %f, ycenter %f\n",(shift+dpad),ycenter);
1197 if((ymin > 0.0) && (TMath::Abs(dpad+1.0) < 1.5)) {
1198 fPRF2d->Fill(shift-(dpad+1.0),(caligroup+0.5),ymin);
1199 fPRF2d->Fill(shift+(dpad+1.0),(caligroup+0.5),ymin);
1201 if((ymax > 0.0) && (TMath::Abs(dpad-1.0) < 1.5)) {
1202 fPRF2d->Fill(shift+1.0-dpad,(caligroup+0.5),ymax);
1203 fPRF2d->Fill(shift-1.0+dpad,(caligroup+0.5),ymax);
1208 if(TMath::Abs(dpad) < 1.5) {
1209 fCalibraVector->UpdateVectorPRF(fDetectorPreviousTrack,grouplocal,shift+dpad,ycenter);
1210 fCalibraVector->UpdateVectorPRF(fDetectorPreviousTrack,grouplocal,shift-dpad,ycenter);
1212 if((ymin > 0.0) && (TMath::Abs(dpad+1.0) < 1.5)) {
1213 fCalibraVector->UpdateVectorPRF(fDetectorPreviousTrack,grouplocal,shift-(dpad+1.0),ymin);
1214 fCalibraVector->UpdateVectorPRF(fDetectorPreviousTrack,grouplocal,shift+(dpad+1.0),ymin);
1216 if((ymax > 0.0) && (TMath::Abs(dpad-1.0) < 1.5)) {
1217 fCalibraVector->UpdateVectorPRF(fDetectorPreviousTrack,grouplocal,shift+1.0-dpad,ymax);
1218 fCalibraVector->UpdateVectorPRF(fDetectorPreviousTrack,grouplocal,shift-1.0+dpad,ymax);
1221 } // second loop over clusters
1226 ///////////////////////////////////////////////////////////////////////////////////////
1227 // Pad row col stuff: see if masked or not
1228 ///////////////////////////////////////////////////////////////////////////////////////
1229 //_____________________________________________________________________________
1230 void AliTRDCalibraFillHisto::CheckGoodTrackletV1(const AliTRDcluster *cl)
1233 // See if we are not near a masked pad
1236 if(cl->IsMasked()) fGoodTracklet = kFALSE;
1240 //_____________________________________________________________________________
1241 void AliTRDCalibraFillHisto::CheckGoodTrackletV0(const Int_t detector,const Int_t row,const Int_t col)
1244 // See if we are not near a masked pad
1247 if (!IsPadOn(detector, col, row)) {
1248 fGoodTracklet = kFALSE;
1252 if (!IsPadOn(detector, col-1, row)) {
1253 fGoodTracklet = kFALSE;
1258 if (!IsPadOn(detector, col+1, row)) {
1259 fGoodTracklet = kFALSE;
1264 //_____________________________________________________________________________
1265 Bool_t AliTRDCalibraFillHisto::IsPadOn(Int_t detector, Int_t row, Int_t col) const
1268 // Look in the choosen database if the pad is On.
1269 // If no the track will be "not good"
1272 // Get the parameter object
1273 AliTRDcalibDB *cal = AliTRDcalibDB::Instance();
1275 AliInfo("Could not get calibDB");
1279 if (!cal->IsChamberInstalled(detector) ||
1280 cal->IsChamberMasked(detector) ||
1281 cal->IsPadMasked(detector,col,row)) {
1289 ///////////////////////////////////////////////////////////////////////////////////////
1290 // Calibration groups: calculate the number of groups, localise...
1291 ////////////////////////////////////////////////////////////////////////////////////////
1292 //_____________________________________________________________________________
1293 Int_t AliTRDCalibraFillHisto::CalculateCalibrationGroup(Int_t i, Int_t row, Int_t col) const
1296 // Calculate the calibration group number for i
1299 // Row of the cluster and position in the pad groups
1301 if (fCalibraMode->GetNnZ(i) != 0) {
1302 posr = (Int_t) row / fCalibraMode->GetNnZ(i);
1306 // Col of the cluster and position in the pad groups
1308 if (fCalibraMode->GetNnRphi(i) != 0) {
1309 posc = (Int_t) col / fCalibraMode->GetNnRphi(i);
1312 return posc*fCalibraMode->GetNfragZ(i)+posr;
1315 //____________________________________________________________________________________
1316 Int_t AliTRDCalibraFillHisto::CalculateTotalNumberOfBins(Int_t i)
1319 // Calculate the total number of calibration groups
1325 if((fCalibraMode->GetNz(i)==100) && (fCalibraMode->GetNrphi(i)==100)){
1327 AliInfo(Form("Total number of Xbins: %d for i %d",ntotal,i));
1332 if((fCalibraMode->GetNz(i)==10) && (fCalibraMode->GetNrphi(i)==10)){
1334 AliInfo(Form("Total number of Xbins: %d for i %d",ntotal,i));
1339 fCalibraMode->ModePadCalibration(2,i);
1340 fCalibraMode->ModePadFragmentation(0,2,0,i);
1341 fCalibraMode->SetDetChamb2(i);
1342 ntotal += 6 * 18 * fCalibraMode->GetDetChamb2(i);
1343 fCalibraMode->ModePadCalibration(0,i);
1344 fCalibraMode->ModePadFragmentation(0,0,0,i);
1345 fCalibraMode->SetDetChamb0(i);
1346 ntotal += 6 * 4 * 18 * fCalibraMode->GetDetChamb0(i);
1347 AliInfo(Form("Total number of Xbins: %d for i %d",ntotal,i));
1351 //_____________________________________________________________________________
1352 void AliTRDCalibraFillHisto::SetNz(Int_t i, Short_t Nz)
1355 // Set the mode of calibration group in the z direction for the parameter i
1360 fCalibraMode->SetNz(i, Nz);
1363 AliInfo("You have to choose between 0 and 4");
1367 //_____________________________________________________________________________
1368 void AliTRDCalibraFillHisto::SetNrphi(Int_t i, Short_t Nrphi)
1371 // Set the mode of calibration group in the rphi direction for the parameter i
1376 fCalibraMode->SetNrphi(i ,Nrphi);
1379 AliInfo("You have to choose between 0 and 6");
1384 //_____________________________________________________________________________
1385 void AliTRDCalibraFillHisto::SetAllTogether(Int_t i)
1388 // Set the mode of calibration group all together
1390 if(fVector2d == kTRUE) {
1391 AliInfo("Can not work with the vector method");
1394 fCalibraMode->SetAllTogether(i);
1398 //_____________________________________________________________________________
1399 void AliTRDCalibraFillHisto::SetPerSuperModule(Int_t i)
1402 // Set the mode of calibration group per supermodule
1404 if(fVector2d == kTRUE) {
1405 AliInfo("Can not work with the vector method");
1408 fCalibraMode->SetPerSuperModule(i);
1412 //____________Set the pad calibration variables for the detector_______________
1413 Bool_t AliTRDCalibraFillHisto::LocalisationDetectorXbins(Int_t detector)
1416 // For the detector calcul the first Xbins and set the number of row
1417 // and col pads per calibration groups, the number of calibration
1418 // groups in the detector.
1421 // first Xbins of the detector
1423 fCalibraMode->CalculXBins(detector,0);
1426 fCalibraMode->CalculXBins(detector,1);
1429 fCalibraMode->CalculXBins(detector,2);
1432 // fragmentation of idect
1433 for (Int_t i = 0; i < 3; i++) {
1434 fCalibraMode->ModePadCalibration((Int_t) GetStack(detector),i);
1435 fCalibraMode->ModePadFragmentation((Int_t) GetLayer(detector)
1436 , (Int_t) GetStack(detector)
1437 , (Int_t) GetSector(detector),i);
1443 //_____________________________________________________________________________
1444 void AliTRDCalibraFillHisto::SetNumberGroupsPRF(Short_t numberGroupsPRF)
1447 // Should be between 0 and 6
1450 if ((numberGroupsPRF < 0) || (numberGroupsPRF > 6)) {
1451 AliInfo("The number of groups must be between 0 and 6!");
1454 fNgroupprf = numberGroupsPRF;
1458 ///////////////////////////////////////////////////////////////////////////////////////////
1459 // Per tracklet: store or reset the info, fill the histos with the info
1460 //////////////////////////////////////////////////////////////////////////////////////////
1461 //_____________________________________________________________________________
1462 void AliTRDCalibraFillHisto::StoreInfoCHPHtrack(const AliTRDcluster *cl,const Double_t dqdl,const Int_t *group,const Int_t row,const Int_t col,const AliTRDcluster *cls)
1465 // Store the infos in fAmpTotal, fPHPlace and fPHValue
1466 // Correct from the gain correction before
1467 // cls is shared cluster if any
1470 //printf("StoreInfoCHPHtrack\n");
1472 // time bin of the cluster not corrected
1473 Int_t time = cl->GetPadTime();
1474 Float_t charge = TMath::Abs(cl->GetQ());
1476 charge += TMath::Abs(cls->GetQ());
1477 //printf("AliTRDCalibraFillHisto::Add the cluster charge");
1480 //printf("Store::time %d, amplitude %f\n",time,dqdl);
1482 //Correct for the gain coefficient used in the database for reconstruction
1483 Float_t correctthegain = 1.0;
1484 if(fIsHLT) correctthegain = fCalDetGain->GetValue(fDetectorPreviousTrack);
1485 else correctthegain = fCalDetGain->GetValue(fDetectorPreviousTrack)*fCalROCGain->GetValue(col,row);
1486 Float_t correction = 1.0;
1487 Float_t normalisation = 6.67;
1488 // we divide with gain in AliTRDclusterizer::Transform...
1489 if( correctthegain > 0 ) normalisation /= correctthegain;
1492 // take dd/dl corrected from the angle of the track
1493 correction = dqdl / (normalisation);
1496 // Fill the fAmpTotal with the charge
1498 if((!fLimitChargeIntegration) || (cl->IsInChamber())) {
1499 //printf("Store::group %d, amplitude %f\n",group[0],correction);
1500 fAmpTotal[(Int_t) group[0]] += correction;
1504 // Fill the fPHPlace and value
1506 fPHPlace[time] = group[1];
1507 fPHValue[time] = charge;
1511 //____________Offine tracking in the AliTRDtracker_____________________________
1512 void AliTRDCalibraFillHisto::ResetfVariablestracklet()
1515 // Reset values per tracklet
1518 //Reset good tracklet
1519 fGoodTracklet = kTRUE;
1521 // Reset the fPHValue
1523 //Reset the fPHValue and fPHPlace
1524 for (Int_t k = 0; k < fTimeMax; k++) {
1530 // Reset the fAmpTotal where we put value
1532 for (Int_t k = 0; k < fCalibraMode->GetNfragZ(0)*fCalibraMode->GetNfragRphi(0); k++) {
1537 //____________Offine tracking in the AliTRDtracker_____________________________
1538 void AliTRDCalibraFillHisto::FillTheInfoOfTheTrackCH(Int_t nbclusters)
1541 // For the offline tracking or mcm tracklets
1542 // This function will be called in the functions UpdateHistogram...
1543 // to fill the info of a track for the relativ gain calibration
1546 Int_t nb = 0; // Nombre de zones traversees
1547 Int_t fd = -1; // Premiere zone non nulle
1548 Float_t totalcharge = 0.0; // Total charge for the supermodule histo
1550 //printf("CH2d nbclusters %d, fNumberClusters %d, fNumberClustersf %d\n",nbclusters,fNumberClusters,fNumberClustersf);
1552 if(nbclusters < fNumberClusters) return;
1553 if(nbclusters > fNumberClustersf) return;
1556 // Normalize with the number of clusters
1557 Double_t normalizeCst = fRelativeScale;
1558 if(fNormalizeNbOfCluster) normalizeCst = normalizeCst*nbclusters;
1560 //printf("Number of groups in one detector %d\n",fCalibraMode->GetNfragZ(0)*fCalibraMode->GetNfragRphi(0));
1562 // See if the track goes through different zones
1563 for (Int_t k = 0; k < fCalibraMode->GetNfragZ(0)*fCalibraMode->GetNfragRphi(0); k++) {
1564 //printf("fAmpTotal %f for %d\n",fAmpTotal[k],k);
1565 if (fAmpTotal[k] > 0.0) {
1566 totalcharge += fAmpTotal[k];
1574 //printf("CH2d: nb %d, fd %d, calibration group %d, amplitude %f, detector %d\n",nb,fd,fCalibraMode->GetXbins(0),fAmpTotal[fd]/normalizeCst,fDetectorPreviousTrack);
1580 fEntriesCH[fCalibraMode->GetXbins(0)+fd]++;
1582 FillCH2d(fCalibraMode->GetXbins(0)+fd,fAmpTotal[fd]/normalizeCst);
1583 //fCH2d->Fill(fAmpTotal[fd]/normalizeCst,fCalibraMode->GetXbins(0)+fd+0.5);
1586 fCalibraVector->UpdateVectorCH(fDetectorPreviousTrack,fd,fAmpTotal[fd]/normalizeCst);
1590 if ((fAmpTotal[fd] > 0.0) &&
1591 (fAmpTotal[fd+1] > 0.0)) {
1592 // One of the two very big
1593 if (fAmpTotal[fd] > fProcent*fAmpTotal[fd+1]) {
1595 FillCH2d(fCalibraMode->GetXbins(0)+fd,fAmpTotal[fd]/normalizeCst);
1596 //fCH2d->Fill(fAmpTotal[fd]/normalizeCst,fCalibraMode->GetXbins(0)+fd+0.5);
1599 fCalibraVector->UpdateVectorCH(fDetectorPreviousTrack,fd,fAmpTotal[fd]/normalizeCst);
1602 fEntriesCH[fCalibraMode->GetXbins(0)+fd]++;
1604 if (fAmpTotal[fd+1] > fProcent*fAmpTotal[fd]) {
1606 FillCH2d(fCalibraMode->GetXbins(0)+fd+1,fAmpTotal[fd+1]/normalizeCst);
1607 //fCH2d->Fill(fAmpTotal[fd+1]/normalizeCst,fCalibraMode->GetXbins(0)+fd+1.5);
1610 fCalibraVector->UpdateVectorCH(fDetectorPreviousTrack,fd+1,fAmpTotal[fd+1]/normalizeCst);
1613 fEntriesCH[fCalibraMode->GetXbins(0)+fd+1]++;
1616 if (fCalibraMode->GetNfragZ(0) > 1) {
1617 if (fAmpTotal[fd] > 0.0) {
1618 if ((fd+fCalibraMode->GetNfragZ(0)) < (fCalibraMode->GetNfragZ(0)*fCalibraMode->GetNfragRphi(0))) {
1619 if (fAmpTotal[fd+fCalibraMode->GetNfragZ(0)] > 0.0) {
1620 // One of the two very big
1621 if (fAmpTotal[fd] > fProcent*fAmpTotal[fd+fCalibraMode->GetNfragZ(0)]) {
1623 FillCH2d(fCalibraMode->GetXbins(0)+fd,fAmpTotal[fd]/normalizeCst);
1624 //fCH2d->Fill(fAmpTotal[fd]/normalizeCst,fCalibraMode->GetXbins(0)+fd+0.5);
1627 fCalibraVector->UpdateVectorCH(fDetectorPreviousTrack,fd,fAmpTotal[fd]/normalizeCst);
1630 fEntriesCH[fCalibraMode->GetXbins(0)+fd]++;
1632 if (fAmpTotal[fd+fCalibraMode->GetNfragZ(0)] > fProcent*fAmpTotal[fd]) {
1634 FillCH2d(fCalibraMode->GetXbins(0)+fd+fCalibraMode->GetNfragZ(0),fAmpTotal[fd+fCalibraMode->GetNfragZ(0)]/normalizeCst);
1635 //fCH2d->Fill(fAmpTotal[fd+fCalibraMode->GetNfragZ(0)]/normalizeCst,fCalibraMode->GetXbins(0)+fd+fCalibraMode->GetNfragZ(0)+0.5);
1638 fEntriesCH[fCalibraMode->GetXbins(0)+fd+fCalibraMode->GetNfragZ(0)]++;
1640 fCalibraVector->UpdateVectorCH(fDetectorPreviousTrack,fd+fCalibraMode->GetNfragZ(0),fAmpTotal[fd+fCalibraMode->GetNfragZ(0)]/normalizeCst);
1651 //____________Offine tracking in the AliTRDtracker_____________________________
1652 void AliTRDCalibraFillHisto::FillTheInfoOfTheTrackPH()
1655 // For the offline tracking or mcm tracklets
1656 // This function will be called in the functions UpdateHistogram...
1657 // to fill the info of a track for the drift velocity calibration
1660 Int_t nb = 1; // Nombre de zones traversees 1, 2 ou plus de 3
1661 Int_t fd1 = -1; // Premiere zone non nulle
1662 Int_t fd2 = -1; // Deuxieme zone non nulle
1663 Int_t k1 = -1; // Debut de la premiere zone
1664 Int_t k2 = -1; // Debut de la seconde zone
1665 Int_t nbclusters = 0; // number of clusters
1669 // See if the track goes through different zones
1670 for (Int_t k = 0; k < fTimeMax; k++) {
1671 if (fPHValue[k] > 0.0) {
1677 if (fPHPlace[k] != fd1) {
1683 if (fPHPlace[k] != fd2) {
1690 // See if noise before and after
1691 if(fMaxCluster > 0) {
1692 if(fPHValue[0] > fMaxCluster) return;
1693 if(fTimeMax > fNbMaxCluster) {
1694 for(Int_t k = (fTimeMax-fNbMaxCluster); k < fTimeMax; k++){
1695 if(fPHValue[k] > fMaxCluster) return;
1700 //printf("nbclusters %d, low limit %d, high limit %d\n",nbclusters,fNumberClusters,fNumberClustersf);
1702 if(nbclusters < fNumberClusters) return;
1703 if(nbclusters > fNumberClustersf) return;
1709 for (Int_t i = 0; i < fTimeMax; i++) {
1711 if(fFillWithZero) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd1)+0.5,(Float_t) fPHValue[i]);
1713 if(((Float_t) fPHValue[i] > 0.0)) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd1)+0.5,(Float_t) fPHValue[i]);
1715 //printf("Fill the time bin %d with %f\n",i,fPHValue[i]);
1718 if(fFillWithZero) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd1,i,fPHValue[i]);
1720 if(((Float_t) fPHValue[i] > 0.0)) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd1,i,fPHValue[i]);
1726 if ((fd1 == fd2+1) ||
1728 // One of the two fast all the think
1729 if (k2 > (k1+fDifference)) {
1730 //we choose to fill the fd1 with all the values
1732 for (Int_t i = 0; i < fTimeMax; i++) {
1734 if(fFillWithZero) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd1)+0.5,(Float_t) fPHValue[i]);
1736 if(((Float_t) fPHValue[i] > 0.0)) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd1)+0.5,(Float_t) fPHValue[i]);
1740 if(fFillWithZero) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd1,i,fPHValue[i]);
1742 if(((Float_t) fPHValue[i] > 0.0)) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd1,i,fPHValue[i]);
1747 if ((k2+fDifference) < fTimeMax) {
1748 //we choose to fill the fd2 with all the values
1750 for (Int_t i = 0; i < fTimeMax; i++) {
1752 if(fFillWithZero) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd2)+0.5,(Float_t) fPHValue[i]);
1754 if(((Float_t) fPHValue[i] > 0.0)) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd2)+0.5,(Float_t) fPHValue[i]);
1758 if(fFillWithZero) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd2,i,fPHValue[i]);
1760 if(((Float_t) fPHValue[i] > 0.0)) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd2,i,fPHValue[i]);
1766 // Two zones voisines sinon rien!
1767 if (fCalibraMode->GetNfragZ(1) > 1) {
1769 if ((fd1+fCalibraMode->GetNfragZ(1)) < (fCalibraMode->GetNfragZ(1)*fCalibraMode->GetNfragRphi(1))) {
1770 if (fd2 == (fd1+fCalibraMode->GetNfragZ(1))) {
1771 // One of the two fast all the think
1772 if (k2 > (k1+fDifference)) {
1773 //we choose to fill the fd1 with all the values
1775 for (Int_t i = 0; i < fTimeMax; i++) {
1777 if(fFillWithZero) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd1)+0.5,(Float_t) fPHValue[i]);
1779 if(((Float_t) fPHValue[i] > 0.0)) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd1)+0.5,(Float_t) fPHValue[i]);
1783 if(fFillWithZero) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd1,i,fPHValue[i]);
1785 if(((Float_t) fPHValue[i] > 0.0)) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd1,i,fPHValue[i]);
1790 if ((k2+fDifference) < fTimeMax) {
1791 //we choose to fill the fd2 with all the values
1793 for (Int_t i = 0; i < fTimeMax; i++) {
1795 if(fFillWithZero) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd2)+0.5,(Float_t) fPHValue[i]);
1797 if(((Float_t) fPHValue[i] > 0.0)) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd2)+0.5,(Float_t) fPHValue[i]);
1801 if(fFillWithZero) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd2,i,fPHValue[i]);
1803 if(((Float_t) fPHValue[i] > 0.0)) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd2,i,fPHValue[i]);
1810 // Two zones voisines sinon rien!
1812 if ((fd1 - fCalibraMode->GetNfragZ(1)) >= 0) {
1813 if (fd2 == (fd1 - fCalibraMode->GetNfragZ(1))) {
1814 // One of the two fast all the think
1815 if (k2 > (k1 + fDifference)) {
1816 //we choose to fill the fd1 with all the values
1818 for (Int_t i = 0; i < fTimeMax; i++) {
1820 if(fFillWithZero) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd1)+0.5,(Float_t) fPHValue[i]);
1822 if(((Float_t) fPHValue[i] > 0.0)) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd1)+0.5,(Float_t) fPHValue[i]);
1826 if(fFillWithZero) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd1,i,fPHValue[i]);
1828 if(((Float_t) fPHValue[i] > 0.0)) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd1,i,fPHValue[i]);
1833 if ((k2+fDifference) < fTimeMax) {
1834 //we choose to fill the fd2 with all the values
1836 for (Int_t i = 0; i < fTimeMax; i++) {
1838 if(fFillWithZero) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd2)+0.5,(Float_t) fPHValue[i]);
1840 if(((Float_t) fPHValue[i] > 0.0)) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd2)+0.5,(Float_t) fPHValue[i]);
1844 if(fFillWithZero) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd2,i,fPHValue[i]);
1846 if(((Float_t) fPHValue[i] > 0.0)) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd2,i,fPHValue[i]);
1858 //////////////////////////////////////////////////////////////////////////////////////////
1859 // DAQ process functions
1860 /////////////////////////////////////////////////////////////////////////////////////////
1861 //_____________________________________________________________________
1862 Int_t AliTRDCalibraFillHisto::ProcessEventDAQ(AliRawReader *rawReader)
1865 // Event Processing loop - AliTRDrawStream
1867 // 0 timebin problem
1870 // Same algorithm as TestBeam but different reader
1873 AliTRDrawStream *rawStream = new AliTRDrawStream(rawReader);
1875 AliTRDdigitsManager *digitsManager = new AliTRDdigitsManager(kTRUE);
1876 digitsManager->CreateArrays();
1878 Int_t withInput = 1;
1880 Double_t phvalue[16][144][36];
1881 for(Int_t k = 0; k < 36; k++){
1882 for(Int_t j = 0; j < 16; j++){
1883 for(Int_t c = 0; c < 144; c++){
1884 phvalue[j][c][k] = 0.0;
1889 fDetectorPreviousTrack = -1;
1893 Int_t nbtimebin = 0;
1894 Int_t baseline = 10;
1900 while ((det = rawStream->NextChamber(digitsManager, NULL, NULL)) >= 0) { //idetector
1902 if (digitsManager->GetIndexes(det)->HasEntry()) {//QA
1903 // printf("there is ADC data on this chamber!\n");
1905 AliTRDarrayADC *digits = (AliTRDarrayADC *) digitsManager->GetDigits(det); //mod
1906 if (digits->HasData()) { //array
1908 AliTRDSignalIndex *indexes = digitsManager->GetIndexes(det);
1909 if (indexes->IsAllocated() == kFALSE) {
1910 AliError("Indexes do not exist!");
1915 indexes->ResetCounters();
1917 while (indexes->NextRCIndex(iRow, iCol)) { //column,row
1918 //printf(" det %d \t row %d \t col %d \t digit\n",det,iRow,iCol);
1919 //while (rawStream->Next()) {
1921 Int_t idetector = det; // current detector
1922 //Int_t imcm = rawStream->GetMCM(); // current MCM
1923 //Int_t irob = rawStream->GetROB(); // current ROB
1926 if((fDetectorPreviousTrack != idetector) && (fDetectorPreviousTrack != -1)) {
1928 withInput = TMath::Max(FillDAQ(phvalue),withInput);
1931 for(Int_t k = 0; k < 36; k++){
1932 for(Int_t j = 0; j < 16; j++){
1933 for(Int_t c = 0; c < 144; c++){
1934 phvalue[j][c][k] = 0.0;
1940 fDetectorPreviousTrack = idetector;
1941 //fMCMPrevious = imcm;
1942 //fROBPrevious = irob;
1944 // nbtimebin = rawStream->GetNumberOfTimeBins(); // number of time bins read from data
1945 AliTRDdigitsParam *digitParam = (AliTRDdigitsParam *)digitsManager->GetDigitsParam();
1946 nbtimebin = digitParam->GetNTimeBins(det); // number of time bins read from data
1947 baseline = digitParam->GetADCbaseline(det); // baseline
1949 if(nbtimebin == 0) return 0;
1950 if((fTimeMax != 0) && (nbtimebin != fTimeMax)) return 0;
1951 fTimeMax = nbtimebin;
1953 fNumberClustersf = fTimeMax;
1954 fNumberClusters = (Int_t)(fNumberClustersProcent*fTimeMax);
1957 for(Int_t itime = 0; itime < nbtimebin; itime++) {
1958 // phvalue[row][col][itime] = signal[itime]-baseline;
1959 phvalue[iRow][iCol][itime] = (Short_t)(digits->GetData(iRow,iCol,itime) - baseline);
1960 /*if(phvalue[iRow][iCol][itime] >= 20) {
1961 printf("----------> phvalue[%d][%d][%d] %d baseline %d \n",
1965 (Short_t)(digits->GetData(iRow,iCol,itime)),
1972 // fill the last one
1973 if(fDetectorPreviousTrack != -1){
1976 withInput = TMath::Max(FillDAQ(phvalue),withInput);
1977 // printf("\n ---> withinput %d\n\n",withInput);
1979 for(Int_t k = 0; k < 36; k++){
1980 for(Int_t j = 0; j < 16; j++){
1981 for(Int_t c = 0; c < 144; c++){
1982 phvalue[j][c][k] = 0.0;
1990 digitsManager->ClearArrays(det);
1992 delete digitsManager;
1997 //_____________________________________________________________________
1998 //////////////////////////////////////////////////////////////////////////////
1999 // Routine inside the DAQ process
2000 /////////////////////////////////////////////////////////////////////////////
2001 //_______________________________________________________________________
2002 Int_t AliTRDCalibraFillHisto::FillDAQ(Double_t phvalue[16][144][36]){
2005 // Look for the maximum by collapsing over the time
2006 // Sum over four pad col and two pad row
2012 Int_t idect = fDetectorPreviousTrack;
2013 //printf("Enter Detector %d\n",fDetectorPreviousTrack);
2015 for(Int_t tb = 0; tb < 36; tb++){
2019 //fGoodTracklet = kTRUE;
2020 //fDetectorPreviousTrack = 0;
2023 ///////////////////////////
2025 /////////////////////////
2029 Double_t integralMax = -1;
2031 for (Int_t ir = 1; ir <= 15; ir++)
2033 for (Int_t ic = 2; ic <= 142; ic++)
2035 Double_t integral = 0;
2036 for (Int_t ishiftR = 0; ishiftR < fNumberRowDAQ; ishiftR++)
2038 for (Int_t ishiftC = -fNumberColDAQ; ishiftC < fNumberColDAQ; ishiftC++)
2040 if (ir + ishiftR >= 1 && ir + ishiftR <= 16 &&
2041 ic + ishiftC >= 1 && ic + ishiftC <= 144)
2044 for(Int_t tb = 0; tb< fTimeMax; tb++){
2045 integral += phvalue[ir + ishiftR-1][ic + ishiftC-1][tb];
2050 if (integralMax < integral)
2054 integralMax = integral;
2056 } // check max integral
2060 // printf("imaxRow %d, imaxCol %d, fTimeMax %d, integralMax %f\n",imaxRow,imaxCol,fTimeMax, integralMax);
2061 //if((imaxRow == 0) || (imaxRow >= 15) || (imaxCol <= 3) || (imaxCol >= 140)) {
2066 if(((imaxRow + fNumberRowDAQ) > 16) || (imaxRow == 0) || ((imaxCol - fNumberColDAQ) <= 1) || ((imaxCol + fNumberColDAQ) >= 144)) {
2070 //CheckGoodTrackletV0(fDetectorPreviousTrack,imaxRow,imaxCol);
2071 //if(!fGoodTracklet) used = 1;;
2073 // /////////////////////////////////////////////////////
2074 // sum ober 2 row and 4 pad cols for each time bins
2075 // ////////////////////////////////////////////////////
2079 for (Int_t ishiftR = 0; ishiftR < fNumberRowDAQ; ishiftR++)
2081 for (Int_t ishiftC = -fNumberColDAQ; ishiftC < fNumberColDAQ; ishiftC++)
2083 if (imaxRow + ishiftR >= 1 && imaxRow + ishiftR <= 16 &&
2084 imaxCol + ishiftC >= 1 && imaxCol + ishiftC <= 144)
2086 for(Int_t it = 0; it < fTimeMax; it++){
2087 sum[it] += phvalue[imaxRow + ishiftR-1][imaxCol + ishiftC-1][it];
2094 Double_t sumcharge = 0.0;
2095 for(Int_t it = 0; it < fTimeMax; it++){
2096 sumcharge += sum[it];
2097 if(sum[it] > fThresholdClustersDAQ) nbcl++;
2101 /////////////////////////////////////////////////////////
2103 ////////////////////////////////////////////////////////
2104 if(fDebugLevel > 0){
2105 if ( !fDebugStreamer ) {
2107 TDirectory *backup = gDirectory;
2108 fDebugStreamer = new TTreeSRedirector("TRDdebugCalibraFill.root");
2109 if ( backup ) backup->cd(); //we don't want to be cd'd to the debug streamer
2112 Double_t amph0 = sum[0];
2113 Double_t amphlast = sum[fTimeMax-1];
2114 Double_t rms = TMath::RMS(fTimeMax,sum);
2115 Int_t goodtracklet = (Int_t) fGoodTracklet;
2116 for(Int_t it = 0; it < fTimeMax; it++){
2117 Double_t clustera = sum[it];
2119 (* fDebugStreamer) << "FillDAQa"<<
2120 "ampTotal="<<sumcharge<<
2123 "detector="<<idect<<
2125 "amphlast="<<amphlast<<
2126 "goodtracklet="<<goodtracklet<<
2127 "clustera="<<clustera<<
2135 ////////////////////////////////////////////////////////
2137 ///////////////////////////////////////////////////////
2138 //printf("fNumberClusters %d, fNumberClustersf %d\n",fNumberClusters,fNumberClustersf);
2139 if(sum[0] > 100.0) used = 1;
2140 if(nbcl < fNumberClusters) used = 1;
2141 if(nbcl > fNumberClustersf) used = 1;
2143 //if(fDetectorPreviousTrack == 15){
2144 // printf("rms %f and first time bin %f\n",TMath::RMS(fTimeMax,sum),sum[0]);
2146 //if((TMath::RMS(fTimeMax,sum) <= 10.0) && (sum[0] > 200.0)) return 1;
2148 for(Int_t it = 0; it < fTimeMax; it++){
2149 if(fFillWithZero) UpdateDAQ(fDetectorPreviousTrack,0,0,it,sum[it],fTimeMax);
2151 if(sum[it] > 0.0) UpdateDAQ(fDetectorPreviousTrack,0,0,it,sum[it],fTimeMax);
2153 //if(fFillWithZero) UpdateDAQ(0,0,0,it,sum[it],fTimeMax);
2155 // if(sum[it] > 0.0) UpdateDAQ(0,0,0,it,sum[it],fTimeMax);
2160 //((TH2I *)GetCH2d()->Fill(sumcharge/30.0,fDetectorPreviousTrack));
2162 //printf("Pass Detector %d\n",fDetectorPreviousTrack);
2169 //____________Online trackling in AliTRDtrigger________________________________
2170 Bool_t AliTRDCalibraFillHisto::UpdateDAQ(Int_t det, Int_t /*row*/, Int_t /*col*/, Int_t timebin, Float_t signal, Int_t nbtimebins)
2174 // Fill a simple average pulse height
2178 ((TProfile2D *)GetPH2d(nbtimebins,fSf))->Fill((Float_t) timebin/fSf,det+0.5,(Float_t) signal);
2184 //____________Write_____________________________________________________
2185 //_____________________________________________________________________
2186 void AliTRDCalibraFillHisto::Write2d(const Char_t *filename, Bool_t append)
2189 // Write infos to file
2193 if ( fDebugStreamer ) {
2194 delete fDebugStreamer;
2195 fDebugStreamer = 0x0;
2198 AliInfo(Form("Numbertrack: %d Numberusedch[0]: %d, Numberusedch[1]: %d Numberusedph[0]: %d, Numberusedph[1]: %d"
2203 ,fNumberUsedPh[1]));
2205 TDirectory *backup = gDirectory;
2211 option = "recreate";
2213 TFile f(filename,option.Data());
2215 TStopwatch stopwatch;
2218 f.WriteTObject(fCalibraVector);
2223 f.WriteTObject(fCH2d);
2228 f.WriteTObject(fPH2d);
2233 f.WriteTObject(fPRF2d);
2236 if(fLinearFitterOn){
2237 if(fLinearFitterDebugOn) AnalyseLinearFitter();
2238 f.WriteTObject(fLinearVdriftFit);
2243 if ( backup ) backup->cd();
2245 AliInfo(Form("Execution time Write2d: R:%.2fs C:%.2fs"
2246 ,stopwatch.RealTime(),stopwatch.CpuTime()));
2248 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
2250 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
2251 //___________________________________________probe the histos__________________________________________________
2252 Double_t *AliTRDCalibraFillHisto::StatH(TH2 *h, Int_t i)
2255 // Check the number of stats in h, 0 is TH2I 1 is TProfile2D
2256 // debug mode with 2 for TH2I and 3 for TProfile2D
2257 // It gives a pointer to a Double_t[7] with the info following...
2258 // [0] : number of calibration groups with entries
2259 // [1] : minimal number of entries found
2260 // [2] : calibration group number of the min
2261 // [3] : maximal number of entries found
2262 // [4] : calibration group number of the max
2263 // [5] : mean number of entries found
2264 // [6] : mean relative error
2267 Double_t *info = new Double_t[7];
2269 // Number of Xbins (detectors or groups of pads)
2270 Int_t nbins = h->GetNbinsY(); //number of calibration groups
2271 Int_t nxbins = h->GetNbinsX(); //number of bins per histo
2274 Double_t nbwe = 0; //number of calibration groups with entries
2275 Double_t minentries = 0; //minimal number of entries found
2276 Double_t maxentries = 0; //maximal number of entries found
2277 Double_t placemin = 0; //calibration group number of the min
2278 Double_t placemax = -1; //calibration group number of the max
2279 Double_t meanstats = 0.0; //mean number of entries over the calibration group with at least ome entry
2280 Double_t meanrelativerror = 0.0; //mean relativ error in the TProfile2D
2282 Double_t counter = 0;
2285 TH1F *nbEntries = 0x0;//distribution of the number of entries
2286 TH1F *nbEntriesPerGroup = 0x0;//Number of entries per group
2287 TProfile *nbEntriesPerSp = 0x0;//Number of entries for one supermodule
2289 // Beginning of the loop over the calibration groups
2290 for (Int_t idect = 0; idect < nbins; idect++) {
2292 TH1I *projch = (TH1I *) h->ProjectionX("projch",idect+1,idect+1,(Option_t *)"e");
2293 projch->SetDirectory(0);
2295 // Number of entries for this calibration group
2296 Double_t nentries = 0.0;
2298 for (Int_t k = 0; k < nxbins; k++) {
2299 nentries += h->GetBinContent(h->GetBin(k+1,idect+1));
2303 for (Int_t k = 0; k < nxbins; k++) {
2304 nentries += ((TProfile2D *)h)->GetBinEntries(h->GetBin(k+1,idect+1));
2305 if(h->GetBinContent(h->GetBin(k+1,idect+1)) != 0) {
2306 meanrelativerror += (h->GetBinError(h->GetBin(k+1,idect+1))/(TMath::Abs(h->GetBinContent(h->GetBin(k+1,idect+1)))));
2315 if(!((Bool_t)nbEntries)) nbEntries = new TH1F("Number of entries","Number of entries",100,(Int_t)nentries/2,nentries*2);
2316 nbEntries->SetDirectory(0);
2317 nbEntries->Fill(nentries);
2318 if(!((Bool_t)nbEntriesPerGroup)) nbEntriesPerGroup = new TH1F("Number of entries per group","Number of entries per group",nbins,0,nbins);
2319 nbEntriesPerGroup->SetDirectory(0);
2320 nbEntriesPerGroup->Fill(idect+0.5,nentries);
2321 if(!((Bool_t)nbEntriesPerSp)) nbEntriesPerSp = new TProfile("Number of entries per supermodule","Number of entries per supermodule",(Int_t)(nbins/18),0,(Int_t)(nbins/18));
2322 nbEntriesPerSp->SetDirectory(0);
2323 nbEntriesPerSp->Fill((idect%((Int_t)(nbins/18)))+0.5,nentries);
2328 if(nentries > maxentries){
2329 maxentries = nentries;
2333 minentries = nentries;
2335 if(nentries < minentries){
2336 minentries = nentries;
2342 meanstats += nentries;
2344 }//calibration groups loop
2346 if(nbwe > 0) meanstats /= nbwe;
2347 if(counter > 0) meanrelativerror /= counter;
2349 AliInfo(Form("There are %f calibration groups with entries",nbwe));
2350 AliInfo(Form("The minimum number of entries is %f for the group %f",minentries,placemin));
2351 AliInfo(Form("The maximum number of entries is %f for the group %f",maxentries,placemax));
2352 AliInfo(Form("The mean number of entries is %f",meanstats));
2353 if((i%2) == 1) AliInfo(Form("The mean relative error is %f",meanrelativerror));
2356 info[1] = minentries;
2358 info[3] = maxentries;
2360 info[5] = meanstats;
2361 info[6] = meanrelativerror;
2363 if(nbEntries && nbEntriesPerSp && nbEntriesPerGroup){
2364 gStyle->SetPalette(1);
2365 gStyle->SetOptStat(1111);
2366 gStyle->SetPadBorderMode(0);
2367 gStyle->SetCanvasColor(10);
2368 gStyle->SetPadLeftMargin(0.13);
2369 gStyle->SetPadRightMargin(0.01);
2370 TCanvas *stat = new TCanvas("stat","",50,50,600,800);
2373 nbEntries->Draw("");
2375 nbEntriesPerSp->SetStats(0);
2376 nbEntriesPerSp->Draw("");
2377 TCanvas *stat1 = new TCanvas("stat1","",50,50,600,800);
2379 nbEntriesPerGroup->SetStats(0);
2380 nbEntriesPerGroup->Draw("");
2386 //____________________________________________________________________________
2387 Double_t *AliTRDCalibraFillHisto::GetMeanMedianRMSNumberCH()
2390 // Return a Int_t[4] with:
2391 // 0 Mean number of entries
2392 // 1 median of number of entries
2393 // 2 rms of number of entries
2394 // 3 number of group with entries
2397 Double_t *stat = new Double_t[4];
2400 Int_t nbofgroups = CalculateTotalNumberOfBins(0);
2402 Double_t *weight = new Double_t[nbofgroups];
2403 Double_t *nonul = new Double_t[nbofgroups];
2405 for(Int_t k = 0; k < nbofgroups; k++){
2406 if(fEntriesCH[k] > 0) {
2408 nonul[(Int_t)stat[3]] = fEntriesCH[k];
2411 else weight[k] = 0.0;
2413 stat[0] = TMath::Mean(nbofgroups,fEntriesCH,weight);
2414 stat[1] = TMath::Median(nbofgroups,fEntriesCH,weight);
2415 stat[2] = TMath::RMS((Int_t)stat[3],nonul);
2423 //____________________________________________________________________________
2424 Double_t *AliTRDCalibraFillHisto::GetMeanMedianRMSNumberLinearFitter() const
2427 // Return a Int_t[4] with:
2428 // 0 Mean number of entries
2429 // 1 median of number of entries
2430 // 2 rms of number of entries
2431 // 3 number of group with entries
2434 Double_t *stat = new Double_t[4];
2437 Int_t nbofgroups = 540;
2438 Double_t *weight = new Double_t[nbofgroups];
2439 Int_t *nonul = new Int_t[nbofgroups];
2441 for(Int_t k = 0; k < nbofgroups; k++){
2442 if(fEntriesLinearFitter[k] > 0) {
2444 nonul[(Int_t) stat[3]] = fEntriesLinearFitter[k];
2447 else weight[k] = 0.0;
2449 stat[0] = TMath::Mean(nbofgroups,fEntriesLinearFitter,weight);
2450 stat[1] = TMath::Median(nbofgroups,fEntriesLinearFitter,weight);
2451 stat[2] = TMath::RMS((Int_t)stat[3],nonul);
2459 //////////////////////////////////////////////////////////////////////////////////////
2461 //////////////////////////////////////////////////////////////////////////////////////
2462 //_____________________________________________________________________________
2463 void AliTRDCalibraFillHisto::CreatePRF2d(Int_t nn)
2466 // Create the 2D histos: here we have 2*fNgroupprf bins in tnp of 0.2 amplitude each
2467 // If fNgroupprf is zero then no binning in tnp
2471 name += fCalibraMode->GetNz(2);
2473 name += fCalibraMode->GetNrphi(2);
2477 if(fNgroupprf != 0){
2479 fPRF2d = new TProfile2D("PRF2d",(const Char_t *) name
2480 ,2*fNgroupprf*fNumberBinPRF,-3.0*fNgroupprf,3.0*fNgroupprf,nn,0,nn);
2481 fPRF2d->SetYTitle("Det/pad groups");
2482 fPRF2d->SetXTitle("Position x/W [pad width units]");
2483 fPRF2d->SetZTitle("Q_{i}/Q_{total}");
2484 fPRF2d->SetStats(0);
2487 fPRF2d = new TProfile2D("PRF2d",(const Char_t *) name
2488 ,fNumberBinPRF,-1.5,1.5,nn,0,nn);
2489 fPRF2d->SetYTitle("Det/pad groups");
2490 fPRF2d->SetXTitle("Position x/W [pad width units]");
2491 fPRF2d->SetZTitle("Q_{i}/Q_{total}");
2492 fPRF2d->SetStats(0);
2497 //_____________________________________________________________________________
2498 void AliTRDCalibraFillHisto::CreatePH2d(Int_t nn)
2501 // Create the 2D histos
2504 TString name("Ver");
2505 name += fVersionVdriftUsed;
2507 name += fSubVersionVdriftUsed;
2509 name += fCalibraMode->GetNz(1);
2511 name += fCalibraMode->GetNrphi(1);
2513 fPH2d = new TProfile2D("PH2d",(const Char_t *) name
2514 ,fTimeMax,-0.5/fSf,(Float_t) (fTimeMax-0.5)/fSf
2516 fPH2d->SetYTitle("Det/pad groups");
2517 fPH2d->SetXTitle("time [#mus]");
2518 fPH2d->SetZTitle("<PH> [a.u.]");
2522 //_____________________________________________________________________________
2523 void AliTRDCalibraFillHisto::CreateCH2d(Int_t nn)
2526 // Create the 2D histos
2529 TString name("Ver");
2530 name += fVersionGainUsed;
2532 name += fSubVersionGainUsed;
2534 name += fCalibraMode->GetNz(0);
2536 name += fCalibraMode->GetNrphi(0);
2538 fCH2d = new TH2I("CH2d",(const Char_t *) name
2539 ,fNumberBinCharge,0,300,nn,0,nn);
2540 fCH2d->SetYTitle("Det/pad groups");
2541 fCH2d->SetXTitle("charge deposit [a.u]");
2542 fCH2d->SetZTitle("counts");
2547 //////////////////////////////////////////////////////////////////////////////////
2548 // Set relative scale
2549 /////////////////////////////////////////////////////////////////////////////////
2550 //_____________________________________________________________________________
2551 void AliTRDCalibraFillHisto::SetRelativeScale(Float_t RelativeScale)
2554 // Set the factor that will divide the deposited charge
2555 // to fit in the histo range [0,300]
2558 if (RelativeScale > 0.0) {
2559 fRelativeScale = RelativeScale;
2562 AliInfo("RelativeScale must be strict positif!");
2566 //////////////////////////////////////////////////////////////////////////////////
2567 // Quick way to fill a histo
2568 //////////////////////////////////////////////////////////////////////////////////
2569 //_____________________________________________________________________
2570 void AliTRDCalibraFillHisto::FillCH2d(Int_t x, Float_t y)
2573 // FillCH2d: Marian style
2576 //skip simply the value out of range
2577 if((y>=300.0) || (y<0.0)) return;
2579 //Calcul the y place
2580 Int_t yplace = (Int_t) (fNumberBinCharge*y/300.0)+1;
2581 Int_t place = (fNumberBinCharge+2)*(x+1)+yplace;
2584 fCH2d->GetArray()[place]++;
2588 //////////////////////////////////////////////////////////////////////////////////
2589 // Geometrical functions
2590 ///////////////////////////////////////////////////////////////////////////////////
2591 //_____________________________________________________________________________
2592 Int_t AliTRDCalibraFillHisto::GetLayer(Int_t d) const
2595 // Reconstruct the layer number from the detector number
2598 return ((Int_t) (d % 6));
2602 //_____________________________________________________________________________
2603 Int_t AliTRDCalibraFillHisto::GetStack(Int_t d) const
2606 // Reconstruct the stack number from the detector number
2608 const Int_t kNlayer = 6;
2610 return ((Int_t) (d % 30) / kNlayer);
2614 //_____________________________________________________________________________
2615 Int_t AliTRDCalibraFillHisto::GetSector(Int_t d) const
2618 // Reconstruct the sector number from the detector number
2622 return ((Int_t) (d / fg));
2625 ///////////////////////////////////////////////////////////////////////////////////
2626 // Getter functions for DAQ of the CH2d and the PH2d
2627 //////////////////////////////////////////////////////////////////////////////////
2628 //_____________________________________________________________________
2629 TProfile2D* AliTRDCalibraFillHisto::GetPH2d(Int_t nbtimebin, Float_t samplefrequency)
2632 // return pointer to fPH2d TProfile2D
2633 // create a new TProfile2D if it doesn't exist allready
2639 fTimeMax = nbtimebin;
2640 fSf = samplefrequency;
2646 //_____________________________________________________________________
2647 TH2I* AliTRDCalibraFillHisto::GetCH2d()
2650 // return pointer to fCH2d TH2I
2651 // create a new TH2I if it doesn't exist allready
2660 ////////////////////////////////////////////////////////////////////////////////////////////
2661 // Drift velocity calibration
2662 ///////////////////////////////////////////////////////////////////////////////////////////
2663 //_____________________________________________________________________
2664 TLinearFitter* AliTRDCalibraFillHisto::GetLinearFitter(Int_t detector, Bool_t force)
2667 // return pointer to TLinearFitter Calibration
2668 // if force is true create a new TLinearFitter if it doesn't exist allready
2671 if ((!force) || (fLinearFitterArray.UncheckedAt(detector))){
2672 return (TLinearFitter*)fLinearFitterArray.UncheckedAt(detector);
2675 // if we are forced and TLinearFitter doesn't yet exist create it
2677 // new TLinearFitter
2678 TLinearFitter *linearfitter = new TLinearFitter(2,"pol1");
2679 fLinearFitterArray.AddAt(linearfitter,detector);
2680 return linearfitter;
2683 //____________________________________________________________________________
2684 void AliTRDCalibraFillHisto::AnalyseLinearFitter()
2687 // Analyse array of linear fitter because can not be written
2688 // Store two arrays: one with the param the other one with the error param + number of entries
2691 for(Int_t k = 0; k < 540; k++){
2692 TLinearFitter *linearfitter = GetLinearFitter(k);
2693 if((linearfitter!=0) && (fEntriesLinearFitter[k]>10)){
2694 TVectorD *par = new TVectorD(2);
2695 TVectorD pare = TVectorD(2);
2696 TVectorD *parE = new TVectorD(3);
2697 if((linearfitter->EvalRobust(0.8)==0)) {
2698 //linearfitter->Eval();
2699 linearfitter->GetParameters(*par);
2700 //linearfitter->GetErrors(pare);
2701 //Float_t ppointError = TMath::Sqrt(TMath::Abs(linearfitter->GetChisquare())/fEntriesLinearFitter[k]);
2702 //(*parE)[0] = pare[0]*ppointError;
2703 //(*parE)[1] = pare[1]*ppointError;
2707 (*parE)[2] = (Double_t) fEntriesLinearFitter[k];
2708 ((TObjArray *)fLinearVdriftFit->GetPArray())->AddAt(par,k);
2709 ((TObjArray *)fLinearVdriftFit->GetEArray())->AddAt(parE,k);