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 "AliESDtrack.h"
57 #include "AliTRDCalibraFillHisto.h"
58 #include "AliTRDCalibraMode.h"
59 #include "AliTRDCalibraVector.h"
60 #include "AliTRDCalibraVdriftLinearFit.h"
61 #include "AliTRDCalibraExbAltFit.h"
62 #include "AliTRDcalibDB.h"
63 #include "AliTRDCommonParam.h"
64 #include "AliTRDpadPlane.h"
65 #include "AliTRDcluster.h"
66 #include "AliTRDtrackV1.h"
67 #include "AliRawReader.h"
68 #include "AliRawReaderDate.h"
69 #include "AliTRDgeometry.h"
70 #include "AliTRDfeeParam.h"
71 #include "./Cal/AliTRDCalROC.h"
72 #include "./Cal/AliTRDCalPad.h"
73 #include "./Cal/AliTRDCalDet.h"
75 #include "AliTRDdigitsManager.h"
76 #include "AliTRDdigitsParam.h"
77 #include "AliTRDSignalIndex.h"
78 #include "AliTRDarrayADC.h"
80 #include "AliTRDrawStream.h"
82 #include "AliCDBEntry.h"
83 #include "AliCDBManager.h"
90 ClassImp(AliTRDCalibraFillHisto)
92 AliTRDCalibraFillHisto* AliTRDCalibraFillHisto::fgInstance = 0;
93 Bool_t AliTRDCalibraFillHisto::fgTerminated = kFALSE;
95 //_____________singleton implementation_________________________________________________
96 AliTRDCalibraFillHisto *AliTRDCalibraFillHisto::Instance()
99 // Singleton implementation
102 if (fgTerminated != kFALSE) {
106 if (fgInstance == 0) {
107 fgInstance = new AliTRDCalibraFillHisto();
114 //______________________________________________________________________________________
115 void AliTRDCalibraFillHisto::Terminate()
118 // Singleton implementation
119 // Deletes the instance of this class
122 fgTerminated = kTRUE;
124 if (fgInstance != 0) {
131 //______________________________________________________________________________________
132 AliTRDCalibraFillHisto::AliTRDCalibraFillHisto()
142 ,fLinearFitterOn(kFALSE)
143 ,fLinearFitterDebugOn(kFALSE)
144 ,fExbAltFitOn(kFALSE)
145 ,fScaleWithTPCSignal(kFALSE)
147 ,fThresholdClusterPRF2(15.0)
148 ,fLimitChargeIntegration(kFALSE)
149 ,fFillWithZero(kFALSE)
150 ,fNormalizeNbOfCluster(kFALSE)
153 ,fCutWithVdriftCalib(kFALSE)
154 ,fMinNbTRDtracklets(0)
155 ,fMinTRDMomentum(0.0)
156 ,fTakeSnapshot(kTRUE)
159 ,fSubVersionGainUsed(0)
160 ,fFirstRunGainLocal(0)
161 ,fVersionGainLocalUsed(0)
162 ,fSubVersionGainLocalUsed(0)
164 ,fVersionVdriftUsed(0)
165 ,fSubVersionVdriftUsed(0)
168 ,fSubVersionExBUsed(0)
169 ,fCalibraMode(new AliTRDCalibraMode())
172 ,fDetectorPreviousTrack(-1)
176 ,fNumberClustersf(30)
177 ,fNumberClustersProcent(0.5)
178 ,fThresholdClustersDAQ(120.0)
186 ,fRangeHistoCharge(150)
187 ,fNumberBinCharge(50)
193 ,fGoodTracklet(kTRUE)
194 ,fLinearFitterTracklet(0x0)
196 ,fEntriesLinearFitter(0x0)
201 ,fLinearFitterArray(540)
202 ,fLinearVdriftFit(0x0)
208 // Default constructor
212 // Init some default values
215 fNumberUsedCh[0] = 0;
216 fNumberUsedCh[1] = 0;
217 fNumberUsedPh[0] = 0;
218 fNumberUsedPh[1] = 0;
220 fGeo = new AliTRDgeometry();
221 fCalibDB = AliTRDcalibDB::Instance();
224 //______________________________________________________________________________________
225 AliTRDCalibraFillHisto::AliTRDCalibraFillHisto(const AliTRDCalibraFillHisto &c)
232 ,fPRF2dOn(c.fPRF2dOn)
233 ,fHisto2d(c.fHisto2d)
234 ,fVector2d(c.fVector2d)
235 ,fLinearFitterOn(c.fLinearFitterOn)
236 ,fLinearFitterDebugOn(c.fLinearFitterDebugOn)
237 ,fExbAltFitOn(c.fExbAltFitOn)
238 ,fScaleWithTPCSignal(c.fScaleWithTPCSignal)
239 ,fRelativeScale(c.fRelativeScale)
240 ,fThresholdClusterPRF2(c.fThresholdClusterPRF2)
241 ,fLimitChargeIntegration(c.fLimitChargeIntegration)
242 ,fFillWithZero(c.fFillWithZero)
243 ,fNormalizeNbOfCluster(c.fNormalizeNbOfCluster)
244 ,fMaxCluster(c.fMaxCluster)
245 ,fNbMaxCluster(c.fNbMaxCluster)
246 ,fCutWithVdriftCalib(c.fCutWithVdriftCalib)
247 ,fMinNbTRDtracklets(c.fMinNbTRDtracklets)
248 ,fMinTRDMomentum(c.fMinTRDMomentum)
249 ,fTakeSnapshot(c.fTakeSnapshot)
250 ,fFirstRunGain(c.fFirstRunGain)
251 ,fVersionGainUsed(c.fVersionGainUsed)
252 ,fSubVersionGainUsed(c.fSubVersionGainUsed)
253 ,fFirstRunGainLocal(c.fFirstRunGainLocal)
254 ,fVersionGainLocalUsed(c.fVersionGainLocalUsed)
255 ,fSubVersionGainLocalUsed(c.fSubVersionGainLocalUsed)
256 ,fFirstRunVdrift(c.fFirstRunVdrift)
257 ,fVersionVdriftUsed(c.fVersionVdriftUsed)
258 ,fSubVersionVdriftUsed(c.fSubVersionVdriftUsed)
259 ,fFirstRunExB(c.fFirstRunExB)
260 ,fVersionExBUsed(c.fVersionExBUsed)
261 ,fSubVersionExBUsed(c.fSubVersionExBUsed)
264 ,fDebugLevel(c.fDebugLevel)
265 ,fDetectorPreviousTrack(c.fDetectorPreviousTrack)
266 ,fMCMPrevious(c.fMCMPrevious)
267 ,fROBPrevious(c.fROBPrevious)
268 ,fNumberClusters(c.fNumberClusters)
269 ,fNumberClustersf(c.fNumberClustersf)
270 ,fNumberClustersProcent(c.fNumberClustersProcent)
271 ,fThresholdClustersDAQ(c.fThresholdClustersDAQ)
272 ,fNumberRowDAQ(c.fNumberRowDAQ)
273 ,fNumberColDAQ(c.fNumberColDAQ)
274 ,fProcent(c.fProcent)
275 ,fDifference(c.fDifference)
276 ,fNumberTrack(c.fNumberTrack)
277 ,fTimeMax(c.fTimeMax)
279 ,fRangeHistoCharge(c.fRangeHistoCharge)
280 ,fNumberBinCharge(c.fNumberBinCharge)
281 ,fNumberBinPRF(c.fNumberBinPRF)
282 ,fNgroupprf(c.fNgroupprf)
286 ,fGoodTracklet(c.fGoodTracklet)
287 ,fLinearFitterTracklet(0x0)
289 ,fEntriesLinearFitter(0x0)
294 ,fLinearFitterArray(540)
295 ,fLinearVdriftFit(0x0)
303 if(c.fCalibraMode) fCalibraMode = new AliTRDCalibraMode(*c.fCalibraMode);
304 if(c.fCalibraVector) fCalibraVector = new AliTRDCalibraVector(*c.fCalibraVector);
306 fPH2d = new TProfile2D(*c.fPH2d);
307 fPH2d->SetDirectory(0);
310 fPRF2d = new TProfile2D(*c.fPRF2d);
311 fPRF2d->SetDirectory(0);
314 fCH2d = new TH2I(*c.fCH2d);
315 fCH2d->SetDirectory(0);
317 if(c.fLinearVdriftFit){
318 fLinearVdriftFit = new AliTRDCalibraVdriftLinearFit(*c.fLinearVdriftFit);
321 fExbAltFit = new AliTRDCalibraExbAltFit(*c.fExbAltFit);
324 if(c.fCalDetGain) fCalDetGain = new AliTRDCalDet(*c.fCalDetGain);
325 if(c.fCalROCGain) fCalROCGain = new AliTRDCalROC(*c.fCalROCGain);
330 fGeo = new AliTRDgeometry();
331 fCalibDB = AliTRDcalibDB::Instance();
333 fNumberUsedCh[0] = 0;
334 fNumberUsedCh[1] = 0;
335 fNumberUsedPh[0] = 0;
336 fNumberUsedPh[1] = 0;
340 //____________________________________________________________________________________
341 AliTRDCalibraFillHisto::~AliTRDCalibraFillHisto()
344 // AliTRDCalibraFillHisto destructor
348 if ( fDebugStreamer ) delete fDebugStreamer;
350 if ( fCalDetGain ) delete fCalDetGain;
351 if ( fCalROCGain ) delete fCalROCGain;
353 if( fLinearFitterTracklet ) { delete fLinearFitterTracklet; }
357 delete [] fEntriesCH;
358 delete [] fEntriesLinearFitter;
361 for(Int_t idet=0; idet<AliTRDgeometry::kNdet; idet++){
362 TLinearFitter *f = (TLinearFitter*)fLinearFitterArray.At(idet);
365 if(fLinearVdriftFit) delete fLinearVdriftFit;
366 if(fExbAltFit) delete fExbAltFit;
372 //_____________________________________________________________________________
373 void AliTRDCalibraFillHisto::Destroy()
384 //_____________________________________________________________________________
385 void AliTRDCalibraFillHisto::DestroyDebugStreamer()
388 // Delete DebugStreamer
391 if ( fDebugStreamer ) delete fDebugStreamer;
392 fDebugStreamer = 0x0;
395 //_____________________________________________________________________________
396 void AliTRDCalibraFillHisto::ClearHistos()
416 //////////////////////////////////////////////////////////////////////////////////
417 // calibration with AliTRDtrackV1: Init, Update
418 //////////////////////////////////////////////////////////////////////////////////
419 //____________Functions for initialising the AliTRDCalibraFillHisto in the code_________
420 Bool_t AliTRDCalibraFillHisto::Init2Dhistos(Int_t nboftimebin)
423 // Init the histograms and stuff to be filled
428 AliTRDcalibDB *cal = AliTRDcalibDB::Instance();
430 AliInfo("Could not get calibDB");
433 AliTRDCommonParam *parCom = AliTRDCommonParam::Instance();
435 AliInfo("Could not get CommonParam");
440 if(nboftimebin > 0) fTimeMax = nboftimebin;
441 else fTimeMax = cal->GetNumberOfTimeBinsDCS();
442 if(fTimeMax <= 0) fTimeMax = 30;
443 printf("////////////////////////////////////////////\n");
444 printf("Number of time bins in calibration component %d\n",fTimeMax);
445 printf("////////////////////////////////////////////\n");
446 fSf = parCom->GetSamplingFrequency();
447 if(!fNormalizeNbOfCluster) fRelativeScale = 20.0;
448 else fRelativeScale = 1.18;
449 fNumberClustersf = fTimeMax;
450 fNumberClusters = (Int_t)(fNumberClustersProcent*fTimeMax);
452 // Init linear fitter
453 if(!fLinearFitterTracklet) {
454 fLinearFitterTracklet = new TLinearFitter(2,"pol1");
455 fLinearFitterTracklet->StoreData(kTRUE);
458 // Calcul Xbins Chambd0, Chamb2
459 Int_t ntotal0 = CalculateTotalNumberOfBins(0);
460 Int_t ntotal1 = CalculateTotalNumberOfBins(1);
461 Int_t ntotal2 = CalculateTotalNumberOfBins(2);
463 // If vector method On initialised all the stuff
465 fCalibraVector = new AliTRDCalibraVector();
466 fCalibraVector->SetNumberBinCharge(fNumberBinCharge);
467 fCalibraVector->SetTimeMax(fTimeMax);
468 if(fNgroupprf != 0) {
469 fCalibraVector->SetNumberBinPRF(2*fNgroupprf*fNumberBinPRF);
470 fCalibraVector->SetPRFRange((Float_t)(3.0*fNgroupprf));
473 fCalibraVector->SetNumberBinPRF(fNumberBinPRF);
474 fCalibraVector->SetPRFRange(1.5);
476 for(Int_t k = 0; k < 3; k++){
477 fCalibraVector->SetDetCha0(k,fCalibraMode->GetDetChamb0(k));
478 fCalibraVector->SetDetCha2(k,fCalibraMode->GetDetChamb2(k));
480 fCalibraVector->SetNzNrphi(0,fCalibraMode->GetNz(0),fCalibraMode->GetNrphi(0));
481 fCalibraVector->SetNzNrphi(1,fCalibraMode->GetNz(1),fCalibraMode->GetNrphi(1));
482 fCalibraVector->SetNzNrphi(2,fCalibraMode->GetNz(2),fCalibraMode->GetNrphi(2));
483 fCalibraVector->SetNbGroupPRF(fNgroupprf);
486 // Create the 2D histos corresponding to the pad groupCalibration mode
489 AliInfo(Form("The pad calibration mode for the relative gain calibration: Nz %d, and Nrphi %d"
490 ,fCalibraMode->GetNz(0)
491 ,fCalibraMode->GetNrphi(0)));
493 // Create the 2D histo
498 fAmpTotal = new Float_t[TMath::Max(fCalibraMode->GetDetChamb2(0),fCalibraMode->GetDetChamb0(0))];
499 for (Int_t k = 0; k < TMath::Max(fCalibraMode->GetDetChamb2(0),fCalibraMode->GetDetChamb0(0)); k++) {
503 fEntriesCH = new Int_t[ntotal0];
504 for(Int_t k = 0; k < ntotal0; k++){
511 AliInfo(Form("The pad calibration mode for the drift velocity calibration: Nz %d, and Nrphi %d"
512 ,fCalibraMode->GetNz(1)
513 ,fCalibraMode->GetNrphi(1)));
515 // Create the 2D histo
520 fPHPlace = new Short_t[fTimeMax];
521 for (Int_t k = 0; k < fTimeMax; k++) {
524 fPHValue = new Float_t[fTimeMax];
525 for (Int_t k = 0; k < fTimeMax; k++) {
529 if (fLinearFitterOn) {
530 if(fLinearFitterDebugOn) {
531 fLinearFitterArray.SetName("ArrayLinearFitters");
532 fEntriesLinearFitter = new Int_t[540];
533 for(Int_t k = 0; k < 540; k++){
534 fEntriesLinearFitter[k] = 0;
537 fLinearVdriftFit = new AliTRDCalibraVdriftLinearFit();
538 TString nameee("Ver");
539 nameee += fVersionExBUsed;
541 nameee += fSubVersionExBUsed;
542 nameee += "FirstRun";
543 nameee += fFirstRunExB;
545 fLinearVdriftFit->SetNameCalibUsed(nameee);
548 fExbAltFit = new AliTRDCalibraExbAltFit();
553 AliInfo(Form("The pad calibration mode for the PRF calibration: Nz %d, and Nrphi %d"
554 ,fCalibraMode->GetNz(2)
555 ,fCalibraMode->GetNrphi(2)));
556 // Create the 2D histo
558 CreatePRF2d(ntotal2);
565 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
566 Bool_t AliTRDCalibraFillHisto::InitCalDet()
569 // Init the Gain Cal Det
574 AliCDBEntry *entry = 0x0;
576 entry = AliCDBManager::Instance()->Get("TRD/Calib/ChamberGainFactor");
579 entry = AliCDBManager::Instance()->Get("TRD/Calib/ChamberGainFactor",fFirstRunGain,fVersionGainUsed,fSubVersionGainUsed);
582 AliError("No gain det calibration entry found");
585 AliTRDCalDet *calDet = (AliTRDCalDet *)entry->GetObject();
587 AliError("No calDet gain found");
593 fCalDetGain->~AliTRDCalDet();
594 new(fCalDetGain) AliTRDCalDet(*(calDet));
595 }else fCalDetGain = new AliTRDCalDet(*(calDet));
600 name += fVersionGainUsed;
602 name += fSubVersionGainUsed;
604 name += fFirstRunGain;
606 name += fCalibraMode->GetNz(0);
608 name += fCalibraMode->GetNrphi(0);
610 fCH2d->SetTitle(name);
613 TString namee("Ver");
614 namee += fVersionVdriftUsed;
616 namee += fSubVersionVdriftUsed;
618 namee += fFirstRunVdrift;
620 namee += fCalibraMode->GetNz(1);
622 namee += fCalibraMode->GetNrphi(1);
624 fPH2d->SetTitle(namee);
626 // title AliTRDCalibraVdriftLinearFit
627 TString nameee("Ver");
628 nameee += fVersionExBUsed;
630 nameee += fSubVersionExBUsed;
631 nameee += "FirstRun";
632 nameee += fFirstRunExB;
636 fLinearVdriftFit->SetNameCalibUsed(nameee);
643 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
644 Bool_t AliTRDCalibraFillHisto::InitCalPad(Int_t detector)
647 // Init the Gain Cal Pad
652 AliCDBEntry *entry = AliCDBManager::Instance()->Get("TRD/Calib/LocalGainFactor",AliCDBManager::Instance()->GetRun(),fVersionGainLocalUsed,fSubVersionGainLocalUsed);
654 AliError("No gain pad calibration entry found");
657 AliTRDCalPad *calPad = (AliTRDCalPad *)entry->GetObject();
659 AliError("No calPad gain found");
662 AliTRDCalROC *calRoc = (AliTRDCalROC *)calPad->GetCalROC(detector);
664 AliError("No calRoc gain found");
669 fCalROCGain->~AliTRDCalROC();
670 new(fCalROCGain) AliTRDCalROC(*(calRoc));
671 }else fCalROCGain = new AliTRDCalROC(*(calRoc));
680 //____________Offline tracking in the AliTRDtracker____________________________
681 Bool_t AliTRDCalibraFillHisto::UpdateHistogramsV1(const AliTRDtrackV1 *t,const AliESDtrack *esdtrack)
684 // Use AliTRDtrackV1 for the calibration
688 const AliTRDseedV1 *tracklet = 0x0; // tracklet per plane
689 AliTRDcluster *cl = 0x0; // cluster attached now to the tracklet
690 AliTRDcluster *cls = 0x0; // shared cluster attached now to the tracklet
691 Bool_t newtr = kTRUE; // new track
695 // Cut on the number of TRD tracklets
697 Int_t numberoftrdtracklets = t->GetNumberOfTracklets();
698 if(numberoftrdtracklets < fMinNbTRDtracklets) return kFALSE;
700 Double_t tpcsignal = 1.0;
701 if(esdtrack) tpcsignal = esdtrack->GetTPCsignal()/50.0;
702 if(fScaleWithTPCSignal && tpcsignal <0.00001) return kFALSE;
706 AliInfo("Could not get calibDB");
711 ///////////////////////////
712 // loop over the tracklet
713 ///////////////////////////
714 for(Int_t itr = 0; itr < 6; itr++){
716 if(!(tracklet = t->GetTracklet(itr))) continue;
717 if(!tracklet->IsOK()) continue;
719 ResetfVariablestracklet();
720 Float_t momentum = t->GetMomentum(itr);
721 if(TMath::Abs(momentum) < fMinTRDMomentum) continue;
724 //////////////////////////////////////////
725 // localisation of the tracklet and dqdl
726 //////////////////////////////////////////
727 Int_t layer = tracklet->GetPlane();
729 while(!(cl = tracklet->GetClusters(ic++))) continue;
730 Int_t detector = cl->GetDetector();
731 if (detector != fDetectorPreviousTrack) {
732 // if not a new track
734 // don't use the rest of this track if in the same plane
735 if (layer == GetLayer(fDetectorPreviousTrack)) {
736 //printf("bad tracklet, same layer for detector %d\n",detector);
740 //Localise the detector bin
741 LocalisationDetectorXbins(detector);
743 if(!fIsHLT) InitCalPad(detector);
746 fDetectorPreviousTrack = detector;
750 ////////////////////////////
751 // loop over the clusters
752 ////////////////////////////
753 Double_t chargeQ = 0.0;
754 Int_t nbclusters = 0;
755 for(int jc=0; jc<AliTRDseedV1::kNtb; jc++){
756 if(!(cl = tracklet->GetClusters(jc))) continue;
759 // Store the info bis of the tracklet
760 Int_t row = cl->GetPadRow();
761 Int_t col = cl->GetPadCol();
762 CheckGoodTrackletV1(cl);
763 Int_t group[2] = {0,0};
764 if(fCH2dOn) group[0] = CalculateCalibrationGroup(0,row,col);
765 if(fPH2dOn) group[1] = CalculateCalibrationGroup(1,row,col);
766 // Add the charge if shared cluster
767 cls = tracklet->GetClusters(jc+AliTRDseedV1::kNtb);
769 //Scale with TPC signal or not
770 if(!fScaleWithTPCSignal) {
771 chargeQ += StoreInfoCHPHtrack(cl, tracklet->GetQperTB(jc),group,row,col,cls); //tracklet->GetdQdl(jc)
772 //printf("Do not scale now\n");
775 chargeQ += StoreInfoCHPHtrack(cl, tracklet->GetQperTB(jc)/tpcsignal,group,row,col,cls); //tracklet->GetdQdl(jc)
780 ////////////////////////////////////////
781 // Fill the stuffs if a good tracklet
782 ////////////////////////////////////////
785 // drift velocity unables to cut bad tracklets
786 Bool_t pass = FindP1TrackPHtrackletV1(tracklet, nbclusters);
788 //printf("pass %d and nbclusters %d\n",pass,nbclusters);
792 if(fCutWithVdriftCalib) {
793 if(pass) FillTheInfoOfTheTrackCH(nbclusters);
795 FillTheInfoOfTheTrackCH(nbclusters);
801 if(fCutWithVdriftCalib) {
802 if(pass) FillTheInfoOfTheTrackPH();
805 FillTheInfoOfTheTrackPH();
809 if(pass && fPRF2dOn) HandlePRFtrackletV1(tracklet,nbclusters);
812 /////////////////////////////////////////////////////////
814 ////////////////////////////////////////////////////////
817 if ( !fDebugStreamer ) {
819 TDirectory *backup = gDirectory;
820 fDebugStreamer = new TTreeSRedirector("TRDdebugCalibraFill.root");
821 if ( backup ) backup->cd(); //we don't want to be cd'd to the debug streamer
824 Int_t stacke = AliTRDgeometry::GetStack(detector);
825 Int_t sme = AliTRDgeometry::GetSector(detector);
826 Int_t layere = AliTRDgeometry::GetLayer(detector);
828 Float_t b[2] = {0.0,0.0};
829 Float_t bCov[3] = {0.0,0.0,0.0};
830 if(esdtrack) esdtrack->GetImpactParameters(b,bCov);
831 if (bCov[0]<=0 || bCov[2]<=0) {
832 bCov[0]=0; bCov[2]=0;
834 Float_t dcaxy = b[0];
836 Int_t tpcnbclusters = 0;
837 if(esdtrack) tpcnbclusters = esdtrack->GetTPCclusters(0);
838 Double_t ttpcsignal = 0.0;
839 if(esdtrack) ttpcsignal = esdtrack->GetTPCsignal();
840 Int_t cutvdriftlinear = 0;
841 if(!pass) cutvdriftlinear = 1;
843 (* fDebugStreamer) << "FillCharge"<<
844 "detector="<<detector<<
850 "nbtpccls="<<tpcnbclusters<<
851 "tpcsignal="<<ttpcsignal<<
852 "cutvdriftlinear="<<cutvdriftlinear<<
854 "nbtrdtracklet="<<numberoftrdtracklets<<
860 } // if a good tracklet
866 ///////////////////////////////////////////////////////////////////////////////////
867 // Routine inside the update with AliTRDtrack
868 ///////////////////////////////////////////////////////////////////////////////////
869 //____________Offine tracking in the AliTRDtracker_____________________________
870 Bool_t AliTRDCalibraFillHisto::FindP1TrackPHtrackletV1(const AliTRDseedV1 *tracklet, Int_t nbclusters)
873 // Drift velocity calibration:
874 // Fit the clusters with a straight line
875 // From the slope find the drift velocity
878 ////////////////////////////////////////////////
879 //Number of points: if less than 3 return kFALSE
880 /////////////////////////////////////////////////
881 if(nbclusters <= 2) return kFALSE;
886 // results of the linear fit
887 Double_t dydt = 0.0; // dydt tracklet after straight line fit
888 Double_t errorpar = 0.0; // error after straight line fit on dy/dt
889 Double_t pointError = 0.0; // error after straight line fit
890 // pad row problemes: avoid tracklet that cross pad rows, tilting angle in the constant
891 Int_t crossrow = 0; // if it crosses a pad row
892 Int_t rowp = -1; // if it crosses a pad row
893 Float_t tnt = tracklet->GetTilt(); // tan tiltingangle
894 fLinearFitterTracklet->ClearPoints();
897 ///////////////////////////////////////////
898 // Take the parameters of the track
899 //////////////////////////////////////////
900 // take now the snp, tnp and tgl from the track
901 Double_t snp = tracklet->GetSnp(); // sin dy/dx at the end of the chamber
902 Double_t tnp = 0.0; // dy/dx at the end of the chamber
903 if( TMath::Abs(snp) < 1.){
904 tnp = snp / TMath::Sqrt((1.-snp)*(1.+snp));
906 Double_t tgl = tracklet->GetTgl(); // dz/dl
907 Double_t dzdx = tgl*TMath::Sqrt(1+tnp*tnp); // dz/dx calculated from dz/dl
909 //Double_t tnp = tracklet->GetYref(1); // dy/dx at the entrance of the chamber
910 //Double_t tgl = tracklet->GetZref(1); // dz/dl at the entrance of the chamber
911 //Double_t dzdx = tgl; //*TMath::Sqrt(1+tnp*tnp); // dz/dx from dz/dl
912 // at the end with correction due to linear fit
913 //Double_t tnp = tracklet->GetYfit(1); // dy/dx at the end of the chamber after fit correction
914 //Double_t tgl = tracklet->GetZfit(1); // dz/dl at the end of the chamber after fit correction
917 ////////////////////////////
918 // loop over the clusters
919 ////////////////////////////
921 AliTRDcluster *cl = 0x0;
922 //////////////////////////////
923 // Check no shared clusters
924 //////////////////////////////
925 for(int icc=AliTRDseedV1::kNtb; icc<AliTRDseedV1::kNclusters; icc++){
926 cl = tracklet->GetClusters(icc);
929 //////////////////////////////////
931 //////////////////////////////////
933 Float_t sigArr[AliTRDfeeParam::GetNcol()];
934 memset(sigArr, 0, AliTRDfeeParam::GetNcol()*sizeof(sigArr[0]));
935 Int_t ncl=0, tbf=0, tbl=0;
937 for(int ic=0; ic<AliTRDseedV1::kNtb; ic++){
938 if(!(cl = tracklet->GetClusters(ic))) continue;
943 Int_t col = cl->GetPadCol();
944 for(int ip=-1, jp=2; jp<5; ip++, jp++){
946 if(idx<0 || idx>=AliTRDfeeParam::GetNcol()) continue;
947 sigArr[idx]+=((Float_t)cl->GetSignals()[jp]);
950 if((fLimitChargeIntegration) && (!cl->IsInChamber())) continue;
952 Double_t ycluster = cl->GetY();
953 Int_t time = cl->GetPadTime();
954 Double_t timeis = time/fSf;
955 //See if cross two pad rows
956 Int_t row = cl->GetPadRow();
957 if(rowp==-1) rowp = row;
958 if(row != rowp) crossrow = 1;
960 fLinearFitterTracklet->AddPoint(&timeis,ycluster,1);
966 ////////////////////////////////////
967 // Do the straight line fit now
968 ///////////////////////////////////
970 fLinearFitterTracklet->ClearPoints();
974 fLinearFitterTracklet->Eval();
975 fLinearFitterTracklet->GetParameters(pars);
976 pointError = TMath::Sqrt(TMath::Abs(fLinearFitterTracklet->GetChisquare()/(nbli-2)));
977 errorpar = fLinearFitterTracklet->GetParError(1)*pointError;
979 //printf("chis %f, nbli %d, pointError %f, parError %f, errorpar %f\n",fLinearFitterTracklet->GetChisquare(),nbli,pointError,fLinearFitterTracklet->GetParError(1),errorpar);
980 fLinearFitterTracklet->ClearPoints();
982 ////////////////////////////////////
983 // Calc the projection of the clusters on the y direction
984 ///////////////////////////////////
986 Float_t signalSum(0.);
987 Float_t mean = 0.0, rms = 0.0;
988 Float_t dydx = tracklet->GetYref(1), tilt = tracklet->GetTilt(); // ,dzdx = tracklet->GetZref(1); (identical to the previous definition!)
989 Float_t dz = dzdx*(tbl-tbf)/10;
991 for(Int_t ip(0); ip<AliTRDfeeParam::GetNcol(); ip++){
992 signalSum+=sigArr[ip];
995 if(signalSum > 0.0) mean/=signalSum;
997 for(Int_t ip = 0; ip<AliTRDfeeParam::GetNcol(); ip++)
998 rms+=sigArr[ip]*(ip-mean)*(ip-mean);
1000 if(signalSum > 0.0) rms = TMath::Sqrt(TMath::Abs(rms/signalSum));
1002 rms -= TMath::Abs(dz*tilt);
1006 ////////////////////////////////
1008 ///////////////////////////////
1011 if(fDebugLevel > 1){
1012 if ( !fDebugStreamer ) {
1014 TDirectory *backup = gDirectory;
1015 fDebugStreamer = new TTreeSRedirector("TRDdebugCalibraFill.root");
1016 if ( backup ) backup->cd(); //we don't want to be cd'd to the debug streamer
1019 float xcoord = tnp-dzdx*tnt;
1020 float pt = tracklet->GetPt();
1021 Int_t layer = GetLayer(fDetectorPreviousTrack);
1023 (* fDebugStreamer) << "FindP1TrackPHtrackletV1"<<
1024 //"snpright="<<snpright<<
1026 "nbclusters="<<nbclusters<<
1027 "detector="<<fDetectorPreviousTrack<<
1035 "crossrow="<<crossrow<<
1036 "errorpar="<<errorpar<<
1037 "pointError="<<pointError<<
1049 /////////////////////////
1051 ////////////////////////
1053 if(nbclusters < fNumberClusters) return kFALSE;
1054 if(nbclusters > fNumberClustersf) return kFALSE;
1055 if(pointError >= 0.3) return kFALSE;
1056 if(crossrow == 1) return kTRUE;
1058 ///////////////////////
1060 //////////////////////
1062 if(fLinearFitterOn){
1063 //Add to the linear fitter of the detector
1064 if( TMath::Abs(snp) < 1.){
1065 Double_t x = tnp-dzdx*tnt;
1066 if(fLinearFitterDebugOn) {
1067 (GetLinearFitter(fDetectorPreviousTrack,kTRUE))->AddPoint(&x,dydt);
1068 fEntriesLinearFitter[fDetectorPreviousTrack]++;
1070 fLinearVdriftFit->Update(fDetectorPreviousTrack,x,pars[1]);
1074 fExbAltFit->Update(fDetectorPreviousTrack,dydx,rms);
1079 //____________Offine tracking in the AliTRDtracker_____________________________
1080 Bool_t AliTRDCalibraFillHisto::HandlePRFtrackletV1(const AliTRDseedV1 *tracklet, Int_t nbclusters)
1083 // PRF width calibration
1084 // Assume a Gaussian shape: determinate the position of the three pad clusters
1085 // Fit with a straight line
1086 // Take the fitted values for all the clusters (3 or 2 pad clusters)
1087 // Fill the PRF as function of angle of the track
1091 //printf("begin\n");
1092 ///////////////////////////////////////////
1093 // Take the parameters of the track
1094 //////////////////////////////////////////
1095 // take now the snp, tnp and tgl from the track
1096 Double_t snp = tracklet->GetSnp(); // sin dy/dx at the end of the chamber
1097 Double_t tnp = 0.0; // dy/dx at the end of the chamber
1098 if( TMath::Abs(snp) < 1.){
1099 tnp = snp / TMath::Sqrt((1.-snp)*(1.+snp));
1101 Double_t tgl = tracklet->GetTgl(); // dz/dl
1102 Double_t dzdx = tgl*TMath::Sqrt(1+tnp*tnp); // dz/dx calculated from dz/dl
1104 //Double_t tnp = tracklet->GetYref(1); // dy/dx at the entrance of the chamber
1105 //Double_t tgl = tracklet->GetZref(1); // dz/dl at the entrance of the chamber
1106 //Double_t dzdx = tgl; //*TMath::Sqrt(1+tnp*tnp); // dz/dx from dz/dl
1107 // at the end with correction due to linear fit
1108 //Double_t tnp = tracklet->GetYfit(1); // dy/dx at the end of the chamber after fit correction
1109 //Double_t tgl = tracklet->GetZfit(1); // dz/dl at the end of the chamber after fit correction
1111 ///////////////////////////////
1112 // Calculate tnp group shift
1113 ///////////////////////////////
1114 Bool_t echec = kFALSE;
1115 Double_t shift = 0.0;
1116 //Calculate the shift in x coresponding to this tnp
1117 if(fNgroupprf != 0.0){
1118 shift = -3.0*(fNgroupprf-1)-1.5;
1119 Double_t limithigh = -0.2*(fNgroupprf-1);
1120 if((tnp < (-0.2*fNgroupprf)) || (tnp > (0.2*fNgroupprf))) echec = kTRUE;
1122 while(tnp > limithigh){
1128 // do nothing if out of tnp range
1129 //printf("echec %d\n",(Int_t)echec);
1130 if(echec) return kFALSE;
1132 ///////////////////////
1134 //////////////////////
1136 Int_t nb3pc = 0; // number of three pads clusters used for fit
1137 // to see the difference between the fit and the 3 pad clusters position
1138 Double_t padPositions[AliTRDseedV1::kNtb];
1139 memset(padPositions, 0, AliTRDseedV1::kNtb*sizeof(Double_t));
1140 fLinearFitterTracklet->ClearPoints();
1142 //printf("loop clusters \n");
1143 ////////////////////////////
1144 // loop over the clusters
1145 ////////////////////////////
1146 AliTRDcluster *cl = 0x0;
1147 for(int ic=0; ic<AliTRDseedV1::kNtb; ic++){
1148 // reject shared clusters on pad row
1149 if((ic+AliTRDseedV1::kNtb) < AliTRDseedV1::kNclusters) {
1150 cl = tracklet->GetClusters(ic+AliTRDseedV1::kNtb);
1153 cl = tracklet->GetClusters(ic);
1155 Double_t time = cl->GetPadTime();
1156 if((time<=7) || (time>=21)) continue;
1157 Short_t *signals = cl->GetSignals();
1158 Float_t xcenter = 0.0;
1159 Bool_t echec1 = kTRUE;
1161 /////////////////////////////////////////////////////////////
1162 // Center 3 balanced: position with the center of the pad
1163 /////////////////////////////////////////////////////////////
1164 if ((((Float_t) signals[3]) > 0.0) &&
1165 (((Float_t) signals[2]) > 0.0) &&
1166 (((Float_t) signals[4]) > 0.0)) {
1168 // Security if the denomiateur is 0
1169 if ((((Float_t) (((Float_t) signals[3]) * ((Float_t) signals[3]))) /
1170 ((Float_t) (((Float_t) signals[2]) * ((Float_t) signals[4])))) != 1.0) {
1171 xcenter = 0.5 * (TMath::Log((Float_t) (((Float_t) signals[4]) / ((Float_t) signals[2]))))
1172 / (TMath::Log(((Float_t) (((Float_t) signals[3]) * ((Float_t) signals[3])))
1173 / ((Float_t) (((Float_t) signals[2]) * ((Float_t) signals[4])))));
1179 if(TMath::Abs(xcenter) > 0.5) echec1 = kTRUE;
1180 if(echec1) continue;
1182 ////////////////////////////////////////////////////////
1183 //if no echec1: calculate with the position of the pad
1184 // Position of the cluster
1185 // fill the linear fitter
1186 ///////////////////////////////////////////////////////
1187 Double_t padPosition = xcenter + cl->GetPadCol();
1188 padPositions[ic] = padPosition;
1190 fLinearFitterTracklet->AddPoint(&time, padPosition,1);
1195 //printf("Fin loop clusters \n");
1196 //////////////////////////////
1197 // fit with a straight line
1198 /////////////////////////////
1200 fLinearFitterTracklet->ClearPoints();
1203 fLinearFitterTracklet->Eval();
1205 fLinearFitterTracklet->GetParameters(line);
1206 Float_t pointError = -1.0;
1207 if( fLinearFitterTracklet->GetChisquare()>=0.0) {
1208 pointError = TMath::Sqrt( fLinearFitterTracklet->GetChisquare()/(nb3pc-2));
1210 fLinearFitterTracklet->ClearPoints();
1212 //printf("PRF second loop \n");
1213 ////////////////////////////////////////////////
1214 // Fill the PRF: Second loop over clusters
1215 //////////////////////////////////////////////
1216 for(int ic=0; ic<AliTRDseedV1::kNtb; ic++){
1217 // reject shared clusters on pad row
1218 cl = tracklet->GetClusters(ic+AliTRDseedV1::kNtb);
1219 if(((ic+AliTRDseedV1::kNtb) < AliTRDseedV1::kNclusters) && (cl)) continue;
1221 cl = tracklet->GetClusters(ic);
1224 Short_t *signals = cl->GetSignals(); // signal
1225 Double_t time = cl->GetPadTime(); // time bin
1226 Float_t padPosTracklet = line[0]+line[1]*time; // reconstruct position from fit
1227 Float_t padPos = cl->GetPadCol(); // middle pad
1228 Double_t dpad = padPosTracklet - padPos; // reconstruct position relative to middle pad from fit
1229 Float_t ycenter = 0.0; // relative center charge
1230 Float_t ymin = 0.0; // relative left charge
1231 Float_t ymax = 0.0; // relative right charge
1233 ////////////////////////////////////////////////////////////////
1234 // Calculate ycenter, ymin and ymax even for two pad clusters
1235 ////////////////////////////////////////////////////////////////
1236 if(((((Float_t) signals[3]) > 0.0) && (((Float_t) signals[2]) > 0.0)) ||
1237 ((((Float_t) signals[3]) > 0.0) && (((Float_t) signals[4]) > 0.0))){
1238 Float_t sum = ((Float_t) signals[2]) + ((Float_t) signals[3]) + ((Float_t) signals[4]);
1239 if(sum > 0.0) ycenter = ((Float_t) signals[3])/ sum;
1240 if(sum > 0.0) ymin = ((Float_t) signals[2])/ sum;
1241 if(sum > 0.0) ymax = ((Float_t) signals[4])/ sum;
1244 /////////////////////////
1245 // Calibration group
1246 ////////////////////////
1247 Int_t rowcl = cl->GetPadRow(); // row of cluster
1248 Int_t colcl = cl->GetPadCol(); // col of cluster
1249 Int_t grouplocal = CalculateCalibrationGroup(2,rowcl,colcl); // calcul the corresponding group
1250 Int_t caligroup = fCalibraMode->GetXbins(2)+ grouplocal; // calcul the corresponding group
1251 Float_t xcl = cl->GetY(); // y cluster
1252 Float_t qcl = cl->GetQ(); // charge cluster
1253 Int_t layer = GetLayer(fDetectorPreviousTrack); // layer
1254 Int_t stack = GetStack(fDetectorPreviousTrack); // stack
1255 Double_t xdiff = dpad; // reconstructed position constant
1256 Double_t x = dpad; // reconstructed position moved
1257 Float_t ep = pointError; // error of fit
1258 Float_t signal1 = (Float_t)signals[1]; // signal at the border
1259 Float_t signal3 = (Float_t)signals[3]; // signal
1260 Float_t signal2 = (Float_t)signals[2]; // signal
1261 Float_t signal4 = (Float_t)signals[4]; // signal
1262 Float_t signal5 = (Float_t)signals[5]; // signal at the border
1266 /////////////////////
1268 ////////////////////
1270 if(fDebugLevel > 1){
1271 if ( !fDebugStreamer ) {
1273 TDirectory *backup = gDirectory;
1274 fDebugStreamer = new TTreeSRedirector("TRDdebugCalibraFill.root");
1275 if ( backup ) backup->cd(); //we don't want to be cd'd to the debug streamer
1280 Float_t y = ycenter;
1281 (* fDebugStreamer) << "HandlePRFtrackletV1"<<
1282 "caligroup="<<caligroup<<
1283 "detector="<<fDetectorPreviousTrack<<
1286 "npoints="<<nbclusters<<
1295 "padPosition="<<padPositions[ic]<<
1296 "padPosTracklet="<<padPosTracklet<<
1301 "signal1="<<signal1<<
1302 "signal2="<<signal2<<
1303 "signal3="<<signal3<<
1304 "signal4="<<signal4<<
1305 "signal5="<<signal5<<
1311 (* fDebugStreamer) << "HandlePRFtrackletV1"<<
1312 "caligroup="<<caligroup<<
1313 "detector="<<fDetectorPreviousTrack<<
1316 "npoints="<<nbclusters<<
1325 "padPosition="<<padPositions[ic]<<
1326 "padPosTracklet="<<padPosTracklet<<
1331 "signal1="<<signal1<<
1332 "signal2="<<signal2<<
1333 "signal3="<<signal3<<
1334 "signal4="<<signal4<<
1335 "signal5="<<signal5<<
1341 (* fDebugStreamer) << "HandlePRFtrackletV1"<<
1342 "caligroup="<<caligroup<<
1343 "detector="<<fDetectorPreviousTrack<<
1346 "npoints="<<nbclusters<<
1355 "padPosition="<<padPositions[ic]<<
1356 "padPosTracklet="<<padPosTracklet<<
1361 "signal1="<<signal1<<
1362 "signal2="<<signal2<<
1363 "signal3="<<signal3<<
1364 "signal4="<<signal4<<
1365 "signal5="<<signal5<<
1371 /////////////////////
1373 /////////////////////
1374 if(nbclusters < fNumberClusters) continue;
1375 if(nbclusters > fNumberClustersf) continue;
1376 if(nb3pc <= 5) continue;
1377 if((time >= 21) || (time < 7)) continue;
1378 if(TMath::Abs(qcl) < 80) continue;
1379 if( TMath::Abs(snp) > 1.) continue;
1382 ////////////////////////
1384 ///////////////////////
1386 if(TMath::Abs(dpad) < 1.5) {
1387 fPRF2d->Fill(shift+dpad,(caligroup+0.5),ycenter);
1388 fPRF2d->Fill(shift-dpad,(caligroup+0.5),ycenter);
1389 //printf("place %f, ycenter %f\n",(shift+dpad),ycenter);
1391 if((ymin > 0.0) && (TMath::Abs(dpad+1.0) < 1.5)) {
1392 fPRF2d->Fill(shift-(dpad+1.0),(caligroup+0.5),ymin);
1393 fPRF2d->Fill(shift+(dpad+1.0),(caligroup+0.5),ymin);
1395 if((ymax > 0.0) && (TMath::Abs(dpad-1.0) < 1.5)) {
1396 fPRF2d->Fill(shift+1.0-dpad,(caligroup+0.5),ymax);
1397 fPRF2d->Fill(shift-1.0+dpad,(caligroup+0.5),ymax);
1402 if(TMath::Abs(dpad) < 1.5) {
1403 fCalibraVector->UpdateVectorPRF(fDetectorPreviousTrack,grouplocal,shift+dpad,ycenter);
1404 fCalibraVector->UpdateVectorPRF(fDetectorPreviousTrack,grouplocal,shift-dpad,ycenter);
1406 if((ymin > 0.0) && (TMath::Abs(dpad+1.0) < 1.5)) {
1407 fCalibraVector->UpdateVectorPRF(fDetectorPreviousTrack,grouplocal,shift-(dpad+1.0),ymin);
1408 fCalibraVector->UpdateVectorPRF(fDetectorPreviousTrack,grouplocal,shift+(dpad+1.0),ymin);
1410 if((ymax > 0.0) && (TMath::Abs(dpad-1.0) < 1.5)) {
1411 fCalibraVector->UpdateVectorPRF(fDetectorPreviousTrack,grouplocal,shift+1.0-dpad,ymax);
1412 fCalibraVector->UpdateVectorPRF(fDetectorPreviousTrack,grouplocal,shift-1.0+dpad,ymax);
1415 } // second loop over clusters
1420 ///////////////////////////////////////////////////////////////////////////////////////
1421 // Pad row col stuff: see if masked or not
1422 ///////////////////////////////////////////////////////////////////////////////////////
1423 //_____________________________________________________________________________
1424 void AliTRDCalibraFillHisto::CheckGoodTrackletV1(const AliTRDcluster *cl)
1427 // See if we are not near a masked pad
1430 if(cl->IsMasked()) fGoodTracklet = kFALSE;
1434 //_____________________________________________________________________________
1435 void AliTRDCalibraFillHisto::CheckGoodTrackletV0(const Int_t detector,const Int_t row,const Int_t col)
1438 // See if we are not near a masked pad
1441 if (!IsPadOn(detector, col, row)) {
1442 fGoodTracklet = kFALSE;
1446 if (!IsPadOn(detector, col-1, row)) {
1447 fGoodTracklet = kFALSE;
1452 if (!IsPadOn(detector, col+1, row)) {
1453 fGoodTracklet = kFALSE;
1458 //_____________________________________________________________________________
1459 Bool_t AliTRDCalibraFillHisto::IsPadOn(Int_t detector, Int_t row, Int_t col) const
1462 // Look in the choosen database if the pad is On.
1463 // If no the track will be "not good"
1466 // Get the parameter object
1467 AliTRDcalibDB *cal = AliTRDcalibDB::Instance();
1469 AliInfo("Could not get calibDB");
1473 if (!cal->IsChamberGood(detector) ||
1474 cal->IsChamberNoData(detector) ||
1475 cal->IsPadMasked(detector,col,row)) {
1483 ///////////////////////////////////////////////////////////////////////////////////////
1484 // Calibration groups: calculate the number of groups, localise...
1485 ////////////////////////////////////////////////////////////////////////////////////////
1486 //_____________________________________________________________________________
1487 Int_t AliTRDCalibraFillHisto::CalculateCalibrationGroup(Int_t i, Int_t row, Int_t col) const
1490 // Calculate the calibration group number for i
1493 // Row of the cluster and position in the pad groups
1495 if (fCalibraMode->GetNnZ(i) != 0) {
1496 posr = (Int_t) row / fCalibraMode->GetNnZ(i);
1500 // Col of the cluster and position in the pad groups
1502 if (fCalibraMode->GetNnRphi(i) != 0) {
1503 posc = (Int_t) col / fCalibraMode->GetNnRphi(i);
1506 return posc*fCalibraMode->GetNfragZ(i)+posr;
1509 //____________________________________________________________________________________
1510 Int_t AliTRDCalibraFillHisto::CalculateTotalNumberOfBins(Int_t i)
1513 // Calculate the total number of calibration groups
1519 if((fCalibraMode->GetNz(i)==100) && (fCalibraMode->GetNrphi(i)==100)){
1521 AliInfo(Form("Total number of Xbins: %d for i %d",ntotal,i));
1526 if((fCalibraMode->GetNz(i)==10) && (fCalibraMode->GetNrphi(i)==10)){
1528 AliInfo(Form("Total number of Xbins: %d for i %d",ntotal,i));
1533 fCalibraMode->ModePadCalibration(2,i);
1534 fCalibraMode->ModePadFragmentation(0,2,0,i);
1535 fCalibraMode->SetDetChamb2(i);
1536 ntotal += 6 * 18 * fCalibraMode->GetDetChamb2(i);
1537 fCalibraMode->ModePadCalibration(0,i);
1538 fCalibraMode->ModePadFragmentation(0,0,0,i);
1539 fCalibraMode->SetDetChamb0(i);
1540 ntotal += 6 * 4 * 18 * fCalibraMode->GetDetChamb0(i);
1541 AliInfo(Form("Total number of Xbins: %d for i %d",ntotal,i));
1545 //_____________________________________________________________________________
1546 void AliTRDCalibraFillHisto::SetNz(Int_t i, Short_t Nz)
1549 // Set the mode of calibration group in the z direction for the parameter i
1554 fCalibraMode->SetNz(i, Nz);
1557 AliInfo("You have to choose between 0 and 4");
1561 //_____________________________________________________________________________
1562 void AliTRDCalibraFillHisto::SetNrphi(Int_t i, Short_t Nrphi)
1565 // Set the mode of calibration group in the rphi direction for the parameter i
1570 fCalibraMode->SetNrphi(i ,Nrphi);
1573 AliInfo("You have to choose between 0 and 6");
1578 //_____________________________________________________________________________
1579 void AliTRDCalibraFillHisto::SetAllTogether(Int_t i)
1582 // Set the mode of calibration group all together
1584 if(fVector2d == kTRUE) {
1585 AliInfo("Can not work with the vector method");
1588 fCalibraMode->SetAllTogether(i);
1592 //_____________________________________________________________________________
1593 void AliTRDCalibraFillHisto::SetPerSuperModule(Int_t i)
1596 // Set the mode of calibration group per supermodule
1598 if(fVector2d == kTRUE) {
1599 AliInfo("Can not work with the vector method");
1602 fCalibraMode->SetPerSuperModule(i);
1606 //____________Set the pad calibration variables for the detector_______________
1607 Bool_t AliTRDCalibraFillHisto::LocalisationDetectorXbins(Int_t detector)
1610 // For the detector calcul the first Xbins and set the number of row
1611 // and col pads per calibration groups, the number of calibration
1612 // groups in the detector.
1615 // first Xbins of the detector
1617 fCalibraMode->CalculXBins(detector,0);
1620 fCalibraMode->CalculXBins(detector,1);
1623 fCalibraMode->CalculXBins(detector,2);
1626 // fragmentation of idect
1627 for (Int_t i = 0; i < 3; i++) {
1628 fCalibraMode->ModePadCalibration((Int_t) GetStack(detector),i);
1629 fCalibraMode->ModePadFragmentation((Int_t) GetLayer(detector)
1630 , (Int_t) GetStack(detector)
1631 , (Int_t) GetSector(detector),i);
1637 //_____________________________________________________________________________
1638 void AliTRDCalibraFillHisto::SetNumberGroupsPRF(Short_t numberGroupsPRF)
1641 // Should be between 0 and 6
1644 if ((numberGroupsPRF < 0) || (numberGroupsPRF > 6)) {
1645 AliInfo("The number of groups must be between 0 and 6!");
1648 fNgroupprf = numberGroupsPRF;
1652 ///////////////////////////////////////////////////////////////////////////////////////////
1653 // Per tracklet: store or reset the info, fill the histos with the info
1654 //////////////////////////////////////////////////////////////////////////////////////////
1655 //_____________________________________________________________________________
1656 Float_t AliTRDCalibraFillHisto::StoreInfoCHPHtrack(const AliTRDcluster *cl,const Double_t dqdl,const Int_t *group,const Int_t row,const Int_t col,const AliTRDcluster *cls)
1659 // Store the infos in fAmpTotal, fPHPlace and fPHValue
1660 // Correct from the gain correction before
1661 // cls is shared cluster if any
1662 // Return the charge
1666 //printf("StoreInfoCHPHtrack\n");
1668 // time bin of the cluster not corrected
1669 Int_t time = cl->GetPadTime();
1670 Float_t charge = TMath::Abs(cl->GetQ());
1672 charge += TMath::Abs(cls->GetQ());
1673 //printf("AliTRDCalibraFillHisto::Add the cluster charge");
1676 //printf("Store::time %d, amplitude %f\n",time,dqdl);
1678 //Correct for the gain coefficient used in the database for reconstruction
1679 Float_t correctthegain = 1.0;
1680 if(fIsHLT) correctthegain = fCalDetGain->GetValue(fDetectorPreviousTrack);
1681 else correctthegain = fCalDetGain->GetValue(fDetectorPreviousTrack)*fCalROCGain->GetValue(col,row);
1682 Float_t correction = 1.0;
1683 Float_t normalisation = 1.13; //org: 6.67; 1st: 1.056; 2nd: 1.13;
1684 // we divide with gain in AliTRDclusterizer::Transform...
1685 if( correctthegain > 0 ) normalisation /= correctthegain;
1688 // take dd/dl corrected from the angle of the track
1689 correction = dqdl / (normalisation);
1692 // Fill the fAmpTotal with the charge
1694 if((!fLimitChargeIntegration) || (cl->IsInChamber())) {
1695 //printf("Store::group %d, amplitude %f\n",group[0],correction);
1696 fAmpTotal[(Int_t) group[0]] += correction;
1700 // Fill the fPHPlace and value
1702 if (time>=0 && time<fTimeMax) {
1703 fPHPlace[time] = group[1];
1704 fPHValue[time] = charge;
1711 //____________Offine tracking in the AliTRDtracker_____________________________
1712 void AliTRDCalibraFillHisto::ResetfVariablestracklet()
1715 // Reset values per tracklet
1718 //Reset good tracklet
1719 fGoodTracklet = kTRUE;
1721 // Reset the fPHValue
1723 //Reset the fPHValue and fPHPlace
1724 for (Int_t k = 0; k < fTimeMax; k++) {
1730 // Reset the fAmpTotal where we put value
1732 for (Int_t k = 0; k < fCalibraMode->GetNfragZ(0)*fCalibraMode->GetNfragRphi(0); k++) {
1737 //____________Offine tracking in the AliTRDtracker_____________________________
1738 void AliTRDCalibraFillHisto::FillTheInfoOfTheTrackCH(Int_t nbclusters)
1741 // For the offline tracking or mcm tracklets
1742 // This function will be called in the functions UpdateHistogram...
1743 // to fill the info of a track for the relativ gain calibration
1746 Int_t nb = 0; // Nombre de zones traversees
1747 Int_t fd = -1; // Premiere zone non nulle
1748 Float_t totalcharge = 0.0; // Total charge for the supermodule histo
1750 //printf("CH2d nbclusters %d, fNumberClusters %d, fNumberClustersf %d\n",nbclusters,fNumberClusters,fNumberClustersf);
1752 if(nbclusters < fNumberClusters) return;
1753 if(nbclusters > fNumberClustersf) return;
1756 // Normalize with the number of clusters
1757 Double_t normalizeCst = fRelativeScale;
1758 if(fNormalizeNbOfCluster) normalizeCst = normalizeCst*nbclusters;
1760 //printf("Number of groups in one detector %d\n",fCalibraMode->GetNfragZ(0)*fCalibraMode->GetNfragRphi(0));
1762 // See if the track goes through different zones
1763 for (Int_t k = 0; k < fCalibraMode->GetNfragZ(0)*fCalibraMode->GetNfragRphi(0); k++) {
1764 //printf("fAmpTotal %f for %d\n",fAmpTotal[k],k);
1765 if (fAmpTotal[k] > 0.0) {
1766 totalcharge += fAmpTotal[k];
1774 //printf("CH2d: nb %d, fd %d, calibration group %d, amplitude %f, detector %d\n",nb,fd,fCalibraMode->GetXbins(0),fAmpTotal[fd]/normalizeCst,fDetectorPreviousTrack);
1780 fEntriesCH[fCalibraMode->GetXbins(0)+fd]++;
1782 FillCH2d(fCalibraMode->GetXbins(0)+fd,fAmpTotal[fd]/normalizeCst);
1783 //fCH2d->Fill(fAmpTotal[fd]/normalizeCst,fCalibraMode->GetXbins(0)+fd+0.5);
1786 fCalibraVector->UpdateVectorCH(fDetectorPreviousTrack,fd,fAmpTotal[fd]/normalizeCst);
1790 if ((fAmpTotal[fd] > 0.0) &&
1791 (fAmpTotal[fd+1] > 0.0)) {
1792 // One of the two very big
1793 if (fAmpTotal[fd] > fProcent*fAmpTotal[fd+1]) {
1795 FillCH2d(fCalibraMode->GetXbins(0)+fd,fAmpTotal[fd]/normalizeCst);
1796 //fCH2d->Fill(fAmpTotal[fd]/normalizeCst,fCalibraMode->GetXbins(0)+fd+0.5);
1799 fCalibraVector->UpdateVectorCH(fDetectorPreviousTrack,fd,fAmpTotal[fd]/normalizeCst);
1802 fEntriesCH[fCalibraMode->GetXbins(0)+fd]++;
1804 if (fAmpTotal[fd+1] > fProcent*fAmpTotal[fd]) {
1806 FillCH2d(fCalibraMode->GetXbins(0)+fd+1,fAmpTotal[fd+1]/normalizeCst);
1807 //fCH2d->Fill(fAmpTotal[fd+1]/normalizeCst,fCalibraMode->GetXbins(0)+fd+1.5);
1810 fCalibraVector->UpdateVectorCH(fDetectorPreviousTrack,fd+1,fAmpTotal[fd+1]/normalizeCst);
1813 fEntriesCH[fCalibraMode->GetXbins(0)+fd+1]++;
1816 if (fCalibraMode->GetNfragZ(0) > 1) {
1817 if (fAmpTotal[fd] > 0.0) {
1818 if ((fd+fCalibraMode->GetNfragZ(0)) < (fCalibraMode->GetNfragZ(0)*fCalibraMode->GetNfragRphi(0))) {
1819 if (fAmpTotal[fd+fCalibraMode->GetNfragZ(0)] > 0.0) {
1820 // One of the two very big
1821 if (fAmpTotal[fd] > fProcent*fAmpTotal[fd+fCalibraMode->GetNfragZ(0)]) {
1823 FillCH2d(fCalibraMode->GetXbins(0)+fd,fAmpTotal[fd]/normalizeCst);
1824 //fCH2d->Fill(fAmpTotal[fd]/normalizeCst,fCalibraMode->GetXbins(0)+fd+0.5);
1827 fCalibraVector->UpdateVectorCH(fDetectorPreviousTrack,fd,fAmpTotal[fd]/normalizeCst);
1830 fEntriesCH[fCalibraMode->GetXbins(0)+fd]++;
1832 if (fAmpTotal[fd+fCalibraMode->GetNfragZ(0)] > fProcent*fAmpTotal[fd]) {
1834 FillCH2d(fCalibraMode->GetXbins(0)+fd+fCalibraMode->GetNfragZ(0),fAmpTotal[fd+fCalibraMode->GetNfragZ(0)]/normalizeCst);
1835 //fCH2d->Fill(fAmpTotal[fd+fCalibraMode->GetNfragZ(0)]/normalizeCst,fCalibraMode->GetXbins(0)+fd+fCalibraMode->GetNfragZ(0)+0.5);
1838 fEntriesCH[fCalibraMode->GetXbins(0)+fd+fCalibraMode->GetNfragZ(0)]++;
1840 fCalibraVector->UpdateVectorCH(fDetectorPreviousTrack,fd+fCalibraMode->GetNfragZ(0),fAmpTotal[fd+fCalibraMode->GetNfragZ(0)]/normalizeCst);
1851 //____________Offine tracking in the AliTRDtracker_____________________________
1852 void AliTRDCalibraFillHisto::FillTheInfoOfTheTrackPH()
1855 // For the offline tracking or mcm tracklets
1856 // This function will be called in the functions UpdateHistogram...
1857 // to fill the info of a track for the drift velocity calibration
1860 Int_t nb = 1; // Nombre de zones traversees 1, 2 ou plus de 3
1861 Int_t fd1 = -1; // Premiere zone non nulle
1862 Int_t fd2 = -1; // Deuxieme zone non nulle
1863 Int_t k1 = -1; // Debut de la premiere zone
1864 Int_t k2 = -1; // Debut de la seconde zone
1865 Int_t nbclusters = 0; // number of clusters
1869 // See if the track goes through different zones
1870 for (Int_t k = 0; k < fTimeMax; k++) {
1871 if (fPHValue[k] > 0.0) {
1877 if (fPHPlace[k] != fd1) {
1883 if (fPHPlace[k] != fd2) {
1890 // See if noise before and after
1891 if(fMaxCluster > 0) {
1892 if(fPHValue[0] > fMaxCluster) return;
1893 if(fTimeMax > fNbMaxCluster) {
1894 for(Int_t k = (fTimeMax-fNbMaxCluster); k < fTimeMax; k++){
1895 if(fPHValue[k] > fMaxCluster) return;
1900 //printf("nbclusters %d, low limit %d, high limit %d\n",nbclusters,fNumberClusters,fNumberClustersf);
1902 if(nbclusters < fNumberClusters) return;
1903 if(nbclusters > fNumberClustersf) return;
1909 for (Int_t i = 0; i < fTimeMax; i++) {
1911 if(fFillWithZero) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd1)+0.5,(Float_t) fPHValue[i]);
1913 if(((Float_t) fPHValue[i] > 0.0)) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd1)+0.5,(Float_t) fPHValue[i]);
1915 //printf("Fill the time bin %d with %f\n",i,fPHValue[i]);
1918 if(fFillWithZero) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd1,i,fPHValue[i]);
1920 if(((Float_t) fPHValue[i] > 0.0)) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd1,i,fPHValue[i]);
1926 if ((fd1 == fd2+1) ||
1928 // One of the two fast all the think
1929 if (k2 > (k1+fDifference)) {
1930 //we choose to fill the fd1 with all the values
1932 for (Int_t i = 0; i < fTimeMax; i++) {
1934 if(fFillWithZero) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd1)+0.5,(Float_t) fPHValue[i]);
1936 if(((Float_t) fPHValue[i] > 0.0)) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd1)+0.5,(Float_t) fPHValue[i]);
1940 if(fFillWithZero) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd1,i,fPHValue[i]);
1942 if(((Float_t) fPHValue[i] > 0.0)) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd1,i,fPHValue[i]);
1947 if ((k2+fDifference) < fTimeMax) {
1948 //we choose to fill the fd2 with all the values
1950 for (Int_t i = 0; i < fTimeMax; i++) {
1952 if(fFillWithZero) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd2)+0.5,(Float_t) fPHValue[i]);
1954 if(((Float_t) fPHValue[i] > 0.0)) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd2)+0.5,(Float_t) fPHValue[i]);
1958 if(fFillWithZero) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd2,i,fPHValue[i]);
1960 if(((Float_t) fPHValue[i] > 0.0)) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd2,i,fPHValue[i]);
1966 // Two zones voisines sinon rien!
1967 if (fCalibraMode->GetNfragZ(1) > 1) {
1969 if ((fd1+fCalibraMode->GetNfragZ(1)) < (fCalibraMode->GetNfragZ(1)*fCalibraMode->GetNfragRphi(1))) {
1970 if (fd2 == (fd1+fCalibraMode->GetNfragZ(1))) {
1971 // One of the two fast all the think
1972 if (k2 > (k1+fDifference)) {
1973 //we choose to fill the fd1 with all the values
1975 for (Int_t i = 0; i < fTimeMax; i++) {
1977 if(fFillWithZero) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd1)+0.5,(Float_t) fPHValue[i]);
1979 if(((Float_t) fPHValue[i] > 0.0)) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd1)+0.5,(Float_t) fPHValue[i]);
1983 if(fFillWithZero) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd1,i,fPHValue[i]);
1985 if(((Float_t) fPHValue[i] > 0.0)) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd1,i,fPHValue[i]);
1990 if ((k2+fDifference) < fTimeMax) {
1991 //we choose to fill the fd2 with all the values
1993 for (Int_t i = 0; i < fTimeMax; i++) {
1995 if(fFillWithZero) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd2)+0.5,(Float_t) fPHValue[i]);
1997 if(((Float_t) fPHValue[i] > 0.0)) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd2)+0.5,(Float_t) fPHValue[i]);
2001 if(fFillWithZero) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd2,i,fPHValue[i]);
2003 if(((Float_t) fPHValue[i] > 0.0)) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd2,i,fPHValue[i]);
2010 // Two zones voisines sinon rien!
2012 if ((fd1 - fCalibraMode->GetNfragZ(1)) >= 0) {
2013 if (fd2 == (fd1 - fCalibraMode->GetNfragZ(1))) {
2014 // One of the two fast all the think
2015 if (k2 > (k1 + fDifference)) {
2016 //we choose to fill the fd1 with all the values
2018 for (Int_t i = 0; i < fTimeMax; i++) {
2020 if(fFillWithZero) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd1)+0.5,(Float_t) fPHValue[i]);
2022 if(((Float_t) fPHValue[i] > 0.0)) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd1)+0.5,(Float_t) fPHValue[i]);
2026 if(fFillWithZero) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd1,i,fPHValue[i]);
2028 if(((Float_t) fPHValue[i] > 0.0)) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd1,i,fPHValue[i]);
2033 if ((k2+fDifference) < fTimeMax) {
2034 //we choose to fill the fd2 with all the values
2036 for (Int_t i = 0; i < fTimeMax; i++) {
2038 if(fFillWithZero) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd2)+0.5,(Float_t) fPHValue[i]);
2040 if(((Float_t) fPHValue[i] > 0.0)) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd2)+0.5,(Float_t) fPHValue[i]);
2044 if(fFillWithZero) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd2,i,fPHValue[i]);
2046 if(((Float_t) fPHValue[i] > 0.0)) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd2,i,fPHValue[i]);
2058 //////////////////////////////////////////////////////////////////////////////////////////
2059 // DAQ process functions
2060 /////////////////////////////////////////////////////////////////////////////////////////
2061 //_____________________________________________________________________
2062 Int_t AliTRDCalibraFillHisto::ProcessEventDAQ(AliRawReader *rawReader)
2065 // Event Processing loop - AliTRDrawStream
2067 // 0 timebin problem
2070 // Same algorithm as TestBeam but different reader
2073 AliTRDrawStream *rawStream = new AliTRDrawStream(rawReader);
2075 AliTRDdigitsManager *digitsManager = new AliTRDdigitsManager(kTRUE);
2076 digitsManager->CreateArrays();
2078 Int_t withInput = 1;
2080 Double_t phvalue[16][144][36];
2081 for(Int_t k = 0; k < 36; k++){
2082 for(Int_t j = 0; j < 16; j++){
2083 for(Int_t c = 0; c < 144; c++){
2084 phvalue[j][c][k] = 0.0;
2089 fDetectorPreviousTrack = -1;
2093 Int_t nbtimebin = 0;
2094 Int_t baseline = 10;
2100 while ((det = rawStream->NextChamber(digitsManager, NULL, NULL)) >= 0) { //idetector
2102 if (digitsManager->GetIndexes(det)->HasEntry()) {//QA
2103 // printf("there is ADC data on this chamber!\n");
2105 AliTRDarrayADC *digits = (AliTRDarrayADC *) digitsManager->GetDigits(det); //mod
2106 if (digits->HasData()) { //array
2108 AliTRDSignalIndex *indexes = digitsManager->GetIndexes(det);
2109 if (indexes->IsAllocated() == kFALSE) {
2110 AliError("Indexes do not exist!");
2115 indexes->ResetCounters();
2117 while (indexes->NextRCIndex(iRow, iCol)) { //column,row
2118 //printf(" det %d \t row %d \t col %d \t digit\n",det,iRow,iCol);
2119 //while (rawStream->Next()) {
2121 Int_t idetector = det; // current detector
2122 //Int_t imcm = rawStream->GetMCM(); // current MCM
2123 //Int_t irob = rawStream->GetROB(); // current ROB
2126 if((fDetectorPreviousTrack != idetector) && (fDetectorPreviousTrack != -1)) {
2128 withInput = TMath::Max(FillDAQ(phvalue),withInput);
2131 for(Int_t k = 0; k < 36; k++){
2132 for(Int_t j = 0; j < 16; j++){
2133 for(Int_t c = 0; c < 144; c++){
2134 phvalue[j][c][k] = 0.0;
2140 fDetectorPreviousTrack = idetector;
2141 //fMCMPrevious = imcm;
2142 //fROBPrevious = irob;
2144 // nbtimebin = rawStream->GetNumberOfTimeBins(); // number of time bins read from data
2145 AliTRDdigitsParam *digitParam = (AliTRDdigitsParam *)digitsManager->GetDigitsParam();
2146 nbtimebin = digitParam->GetNTimeBins(det); // number of time bins read from data
2147 baseline = digitParam->GetADCbaseline(det); // baseline
2149 if(nbtimebin == 0) return 0;
2150 if((fTimeMax != 0) && (nbtimebin != fTimeMax)) return 0;
2151 fTimeMax = nbtimebin;
2153 fNumberClustersf = fTimeMax;
2154 fNumberClusters = (Int_t)(fNumberClustersProcent*fTimeMax);
2157 for(Int_t itime = 0; itime < nbtimebin; itime++) {
2158 // phvalue[row][col][itime] = signal[itime]-baseline;
2159 phvalue[iRow][iCol][itime] = (Short_t)(digits->GetData(iRow,iCol,itime) - baseline);
2160 /*if(phvalue[iRow][iCol][itime] >= 20) {
2161 printf("----------> phvalue[%d][%d][%d] %d baseline %d \n",
2165 (Short_t)(digits->GetData(iRow,iCol,itime)),
2172 // fill the last one
2173 if(fDetectorPreviousTrack != -1){
2176 withInput = TMath::Max(FillDAQ(phvalue),withInput);
2177 // printf("\n ---> withinput %d\n\n",withInput);
2179 for(Int_t k = 0; k < 36; k++){
2180 for(Int_t j = 0; j < 16; j++){
2181 for(Int_t c = 0; c < 144; c++){
2182 phvalue[j][c][k] = 0.0;
2190 digitsManager->ClearArrays(det);
2192 delete digitsManager;
2197 //_____________________________________________________________________
2198 //////////////////////////////////////////////////////////////////////////////
2199 // Routine inside the DAQ process
2200 /////////////////////////////////////////////////////////////////////////////
2201 //_______________________________________________________________________
2202 Int_t AliTRDCalibraFillHisto::FillDAQ(Double_t phvalue[16][144][36]){
2205 // Look for the maximum by collapsing over the time
2206 // Sum over four pad col and two pad row
2212 Int_t idect = fDetectorPreviousTrack;
2213 //printf("Enter Detector %d\n",fDetectorPreviousTrack);
2215 for(Int_t tb = 0; tb < 36; tb++){
2219 //fGoodTracklet = kTRUE;
2220 //fDetectorPreviousTrack = 0;
2223 ///////////////////////////
2225 /////////////////////////
2229 Double_t integralMax = -1;
2231 for (Int_t ir = 1; ir <= 15; ir++)
2233 for (Int_t ic = 2; ic <= 142; ic++)
2235 Double_t integral = 0;
2236 for (Int_t ishiftR = 0; ishiftR < fNumberRowDAQ; ishiftR++)
2238 for (Int_t ishiftC = -fNumberColDAQ; ishiftC < fNumberColDAQ; ishiftC++)
2240 if (ir + ishiftR >= 1 && ir + ishiftR <= 16 &&
2241 ic + ishiftC >= 1 && ic + ishiftC <= 144)
2244 for(Int_t tb = 0; tb< fTimeMax; tb++){
2245 integral += phvalue[ir + ishiftR-1][ic + ishiftC-1][tb];
2250 if (integralMax < integral)
2254 integralMax = integral;
2256 } // check max integral
2260 // printf("imaxRow %d, imaxCol %d, fTimeMax %d, integralMax %f\n",imaxRow,imaxCol,fTimeMax, integralMax);
2261 //if((imaxRow == 0) || (imaxRow >= 15) || (imaxCol <= 3) || (imaxCol >= 140)) {
2266 if(((imaxRow + fNumberRowDAQ) > 16) || (imaxRow == 0) || ((imaxCol - fNumberColDAQ) <= 1) || ((imaxCol + fNumberColDAQ) >= 144)) {
2270 //CheckGoodTrackletV0(fDetectorPreviousTrack,imaxRow,imaxCol);
2271 //if(!fGoodTracklet) used = 1;;
2273 // /////////////////////////////////////////////////////
2274 // sum ober 2 row and 4 pad cols for each time bins
2275 // ////////////////////////////////////////////////////
2279 for (Int_t ishiftR = 0; ishiftR < fNumberRowDAQ; ishiftR++)
2281 for (Int_t ishiftC = -fNumberColDAQ; ishiftC < fNumberColDAQ; ishiftC++)
2283 if (imaxRow + ishiftR >= 1 && imaxRow + ishiftR <= 16 &&
2284 imaxCol + ishiftC >= 1 && imaxCol + ishiftC <= 144)
2286 for(Int_t it = 0; it < fTimeMax; it++){
2287 sum[it] += phvalue[imaxRow + ishiftR-1][imaxCol + ishiftC-1][it];
2294 Double_t sumcharge = 0.0;
2295 for(Int_t it = 0; it < fTimeMax; it++){
2296 sumcharge += sum[it];
2297 if(sum[it] > fThresholdClustersDAQ) nbcl++;
2301 /////////////////////////////////////////////////////////
2303 ////////////////////////////////////////////////////////
2304 if(fDebugLevel > 1){
2305 if ( !fDebugStreamer ) {
2307 TDirectory *backup = gDirectory;
2308 fDebugStreamer = new TTreeSRedirector("TRDdebugCalibraFill.root");
2309 if ( backup ) backup->cd(); //we don't want to be cd'd to the debug streamer
2312 Double_t amph0 = sum[0];
2313 Double_t amphlast = sum[fTimeMax-1];
2314 Double_t rms = TMath::RMS(fTimeMax,sum);
2315 Int_t goodtracklet = (Int_t) fGoodTracklet;
2316 for(Int_t it = 0; it < fTimeMax; it++){
2317 Double_t clustera = sum[it];
2319 (* fDebugStreamer) << "FillDAQa"<<
2320 "ampTotal="<<sumcharge<<
2323 "detector="<<idect<<
2325 "amphlast="<<amphlast<<
2326 "goodtracklet="<<goodtracklet<<
2327 "clustera="<<clustera<<
2335 ////////////////////////////////////////////////////////
2337 ///////////////////////////////////////////////////////
2338 //printf("fNumberClusters %d, fNumberClustersf %d\n",fNumberClusters,fNumberClustersf);
2339 if(sum[0] > 100.0) used = 1;
2340 if(nbcl < fNumberClusters) used = 1;
2341 if(nbcl > fNumberClustersf) used = 1;
2343 //if(fDetectorPreviousTrack == 15){
2344 // printf("rms %f and first time bin %f\n",TMath::RMS(fTimeMax,sum),sum[0]);
2346 //if((TMath::RMS(fTimeMax,sum) <= 10.0) && (sum[0] > 200.0)) return 1;
2348 for(Int_t it = 0; it < fTimeMax; it++){
2349 if(fFillWithZero) UpdateDAQ(fDetectorPreviousTrack,0,0,it,sum[it],fTimeMax);
2351 if(sum[it] > 0.0) UpdateDAQ(fDetectorPreviousTrack,0,0,it,sum[it],fTimeMax);
2353 //if(fFillWithZero) UpdateDAQ(0,0,0,it,sum[it],fTimeMax);
2355 // if(sum[it] > 0.0) UpdateDAQ(0,0,0,it,sum[it],fTimeMax);
2360 //((TH2I *)GetCH2d()->Fill(sumcharge/30.0,fDetectorPreviousTrack));
2362 //printf("Pass Detector %d\n",fDetectorPreviousTrack);
2369 //____________Online trackling in AliTRDtrigger________________________________
2370 Bool_t AliTRDCalibraFillHisto::UpdateDAQ(Int_t det, Int_t /*row*/, Int_t /*col*/, Int_t timebin, Float_t signal, Int_t nbtimebins)
2374 // Fill a simple average pulse height
2378 ((TProfile2D *)GetPH2d(nbtimebins,fSf))->Fill((Float_t) timebin/fSf,det+0.5,(Float_t) signal);
2384 //____________Write_____________________________________________________
2385 //_____________________________________________________________________
2386 void AliTRDCalibraFillHisto::Write2d(const Char_t *filename, Bool_t append)
2389 // Write infos to file
2393 if ( fDebugStreamer ) {
2394 delete fDebugStreamer;
2395 fDebugStreamer = 0x0;
2398 AliInfo(Form("Numbertrack: %d Numberusedch[0]: %d, Numberusedch[1]: %d Numberusedph[0]: %d, Numberusedph[1]: %d"
2403 ,fNumberUsedPh[1]));
2405 TDirectory *backup = gDirectory;
2411 option = "recreate";
2413 TFile f(filename,option.Data());
2415 TStopwatch stopwatch;
2418 f.WriteTObject(fCalibraVector);
2423 f.WriteTObject(fCH2d);
2428 f.WriteTObject(fPH2d);
2433 f.WriteTObject(fPRF2d);
2436 if(fLinearFitterOn){
2437 if(fLinearFitterDebugOn) AnalyseLinearFitter();
2438 f.WriteTObject(fLinearVdriftFit);
2443 if ( backup ) backup->cd();
2445 AliInfo(Form("Execution time Write2d: R:%.2fs C:%.2fs"
2446 ,stopwatch.RealTime(),stopwatch.CpuTime()));
2448 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
2450 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
2451 //___________________________________________probe the histos__________________________________________________
2452 Double_t *AliTRDCalibraFillHisto::StatH(TH2 *h, Int_t i)
2455 // Check the number of stats in h, 0 is TH2I 1 is TProfile2D
2456 // debug mode with 2 for TH2I and 3 for TProfile2D
2457 // It gives a pointer to a Double_t[7] with the info following...
2458 // [0] : number of calibration groups with entries
2459 // [1] : minimal number of entries found
2460 // [2] : calibration group number of the min
2461 // [3] : maximal number of entries found
2462 // [4] : calibration group number of the max
2463 // [5] : mean number of entries found
2464 // [6] : mean relative error
2467 Double_t *info = new Double_t[7];
2469 // Number of Xbins (detectors or groups of pads)
2470 Int_t nbins = h->GetNbinsY(); //number of calibration groups
2471 Int_t nxbins = h->GetNbinsX(); //number of bins per histo
2474 Double_t nbwe = 0; //number of calibration groups with entries
2475 Double_t minentries = 0; //minimal number of entries found
2476 Double_t maxentries = 0; //maximal number of entries found
2477 Double_t placemin = 0; //calibration group number of the min
2478 Double_t placemax = -1; //calibration group number of the max
2479 Double_t meanstats = 0.0; //mean number of entries over the calibration group with at least ome entry
2480 Double_t meanrelativerror = 0.0; //mean relativ error in the TProfile2D
2482 Double_t counter = 0;
2485 TH1F *nbEntries = 0x0;//distribution of the number of entries
2486 TH1F *nbEntriesPerGroup = 0x0;//Number of entries per group
2487 TProfile *nbEntriesPerSp = 0x0;//Number of entries for one supermodule
2489 // Beginning of the loop over the calibration groups
2490 for (Int_t idect = 0; idect < nbins; idect++) {
2492 TH1I *projch = (TH1I *) h->ProjectionX("projch",idect+1,idect+1,(Option_t *)"e");
2493 projch->SetDirectory(0);
2495 // Number of entries for this calibration group
2496 Double_t nentries = 0.0;
2498 for (Int_t k = 0; k < nxbins; k++) {
2499 nentries += h->GetBinContent(h->GetBin(k+1,idect+1));
2503 for (Int_t k = 0; k < nxbins; k++) {
2504 nentries += ((TProfile2D *)h)->GetBinEntries(h->GetBin(k+1,idect+1));
2505 if(h->GetBinContent(h->GetBin(k+1,idect+1)) != 0) {
2506 meanrelativerror += (h->GetBinError(h->GetBin(k+1,idect+1))/(TMath::Abs(h->GetBinContent(h->GetBin(k+1,idect+1)))));
2515 if(!((Bool_t)nbEntries)) nbEntries = new TH1F("Number of entries","Number of entries",100,(Int_t)nentries/2,nentries*2);
2516 nbEntries->SetDirectory(0);
2517 nbEntries->Fill(nentries);
2518 if(!((Bool_t)nbEntriesPerGroup)) nbEntriesPerGroup = new TH1F("Number of entries per group","Number of entries per group",nbins,0,nbins);
2519 nbEntriesPerGroup->SetDirectory(0);
2520 nbEntriesPerGroup->Fill(idect+0.5,nentries);
2521 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));
2522 nbEntriesPerSp->SetDirectory(0);
2523 nbEntriesPerSp->Fill((idect%((Int_t)(nbins/18)))+0.5,nentries);
2528 if(nentries > maxentries){
2529 maxentries = nentries;
2533 minentries = nentries;
2535 if(nentries < minentries){
2536 minentries = nentries;
2542 meanstats += nentries;
2544 }//calibration groups loop
2546 if(nbwe > 0) meanstats /= nbwe;
2547 if(counter > 0) meanrelativerror /= counter;
2549 AliInfo(Form("There are %f calibration groups with entries",nbwe));
2550 AliInfo(Form("The minimum number of entries is %f for the group %f",minentries,placemin));
2551 AliInfo(Form("The maximum number of entries is %f for the group %f",maxentries,placemax));
2552 AliInfo(Form("The mean number of entries is %f",meanstats));
2553 if((i%2) == 1) AliInfo(Form("The mean relative error is %f",meanrelativerror));
2556 info[1] = minentries;
2558 info[3] = maxentries;
2560 info[5] = meanstats;
2561 info[6] = meanrelativerror;
2563 if(nbEntries && nbEntriesPerSp && nbEntriesPerGroup){
2564 gStyle->SetPalette(1);
2565 gStyle->SetOptStat(1111);
2566 gStyle->SetPadBorderMode(0);
2567 gStyle->SetCanvasColor(10);
2568 gStyle->SetPadLeftMargin(0.13);
2569 gStyle->SetPadRightMargin(0.01);
2570 TCanvas *stat = new TCanvas("stat","",50,50,600,800);
2573 nbEntries->Draw("");
2575 nbEntriesPerSp->SetStats(0);
2576 nbEntriesPerSp->Draw("");
2577 TCanvas *stat1 = new TCanvas("stat1","",50,50,600,800);
2579 nbEntriesPerGroup->SetStats(0);
2580 nbEntriesPerGroup->Draw("");
2586 //____________________________________________________________________________
2587 Double_t *AliTRDCalibraFillHisto::GetMeanMedianRMSNumberCH()
2590 // Return a Int_t[4] with:
2591 // 0 Mean number of entries
2592 // 1 median of number of entries
2593 // 2 rms of number of entries
2594 // 3 number of group with entries
2597 Double_t *stat = new Double_t[4];
2600 Int_t nbofgroups = CalculateTotalNumberOfBins(0);
2602 Double_t *weight = new Double_t[nbofgroups];
2603 Double_t *nonul = new Double_t[nbofgroups];
2605 for(Int_t k = 0; k < nbofgroups; k++){
2606 if(fEntriesCH[k] > 0) {
2608 nonul[(Int_t)stat[3]] = fEntriesCH[k];
2611 else weight[k] = 0.0;
2613 stat[0] = TMath::Mean(nbofgroups,fEntriesCH,weight);
2614 stat[1] = TMath::Median(nbofgroups,fEntriesCH,weight);
2615 stat[2] = TMath::RMS((Int_t)stat[3],nonul);
2623 //____________________________________________________________________________
2624 Double_t *AliTRDCalibraFillHisto::GetMeanMedianRMSNumberLinearFitter() const
2627 // Return a Int_t[4] with:
2628 // 0 Mean number of entries
2629 // 1 median of number of entries
2630 // 2 rms of number of entries
2631 // 3 number of group with entries
2634 Double_t *stat = new Double_t[4];
2637 Int_t nbofgroups = 540;
2638 Double_t *weight = new Double_t[nbofgroups];
2639 Int_t *nonul = new Int_t[nbofgroups];
2641 for(Int_t k = 0; k < nbofgroups; k++){
2642 if(fEntriesLinearFitter[k] > 0) {
2644 nonul[(Int_t) stat[3]] = fEntriesLinearFitter[k];
2647 else weight[k] = 0.0;
2649 stat[0] = TMath::Mean(nbofgroups,fEntriesLinearFitter,weight);
2650 stat[1] = TMath::Median(nbofgroups,fEntriesLinearFitter,weight);
2651 stat[2] = TMath::RMS((Int_t)stat[3],nonul);
2659 //////////////////////////////////////////////////////////////////////////////////////
2661 //////////////////////////////////////////////////////////////////////////////////////
2662 //_____________________________________________________________________________
2663 void AliTRDCalibraFillHisto::CreatePRF2d(Int_t nn)
2666 // Create the 2D histos: here we have 2*fNgroupprf bins in tnp of 0.2 amplitude each
2667 // If fNgroupprf is zero then no binning in tnp
2671 name += fCalibraMode->GetNz(2);
2673 name += fCalibraMode->GetNrphi(2);
2677 if(fNgroupprf != 0){
2679 fPRF2d = new TProfile2D("PRF2d",(const Char_t *) name
2680 ,2*fNgroupprf*fNumberBinPRF,-3.0*fNgroupprf,3.0*fNgroupprf,nn,0,nn);
2681 fPRF2d->SetYTitle("Det/pad groups");
2682 fPRF2d->SetXTitle("Position x/W [pad width units]");
2683 fPRF2d->SetZTitle("Q_{i}/Q_{total}");
2684 fPRF2d->SetStats(0);
2687 fPRF2d = new TProfile2D("PRF2d",(const Char_t *) name
2688 ,fNumberBinPRF,-1.5,1.5,nn,0,nn);
2689 fPRF2d->SetYTitle("Det/pad groups");
2690 fPRF2d->SetXTitle("Position x/W [pad width units]");
2691 fPRF2d->SetZTitle("Q_{i}/Q_{total}");
2692 fPRF2d->SetStats(0);
2697 //_____________________________________________________________________________
2698 void AliTRDCalibraFillHisto::CreatePH2d(Int_t nn)
2701 // Create the 2D histos
2704 TString name("Ver");
2705 name += fVersionVdriftUsed;
2707 name += fSubVersionVdriftUsed;
2709 name += fFirstRunVdrift;
2711 name += fCalibraMode->GetNz(1);
2713 name += fCalibraMode->GetNrphi(1);
2715 fPH2d = new TProfile2D("PH2d",(const Char_t *) name
2716 ,fTimeMax,-0.5/fSf,(Float_t) (fTimeMax-0.5)/fSf
2718 fPH2d->SetYTitle("Det/pad groups");
2719 fPH2d->SetXTitle("time [#mus]");
2720 fPH2d->SetZTitle("<PH> [a.u.]");
2724 //_____________________________________________________________________________
2725 void AliTRDCalibraFillHisto::CreateCH2d(Int_t nn)
2728 // Create the 2D histos
2731 TString name("Ver");
2732 name += fVersionGainUsed;
2734 name += fSubVersionGainUsed;
2736 name += fFirstRunGain;
2738 name += fCalibraMode->GetNz(0);
2740 name += fCalibraMode->GetNrphi(0);
2742 fCH2d = new TH2I("CH2d",(const Char_t *) name
2743 ,(Int_t)fNumberBinCharge,0,fRangeHistoCharge,nn,0,nn);
2744 fCH2d->SetYTitle("Det/pad groups");
2745 fCH2d->SetXTitle("charge deposit [a.u]");
2746 fCH2d->SetZTitle("counts");
2751 //////////////////////////////////////////////////////////////////////////////////
2752 // Set relative scale
2753 /////////////////////////////////////////////////////////////////////////////////
2754 //_____________________________________________________________________________
2755 void AliTRDCalibraFillHisto::SetRelativeScale(Float_t RelativeScale)
2758 // Set the factor that will divide the deposited charge
2759 // to fit in the histo range [0,fRangeHistoCharge]
2762 if (RelativeScale > 0.0) {
2763 fRelativeScale = RelativeScale;
2766 AliInfo("RelativeScale must be strict positif!");
2770 //////////////////////////////////////////////////////////////////////////////////
2771 // Quick way to fill a histo
2772 //////////////////////////////////////////////////////////////////////////////////
2773 //_____________________________________________________________________
2774 void AliTRDCalibraFillHisto::FillCH2d(Int_t x, Float_t y)
2777 // FillCH2d: Marian style
2780 //skip simply the value out of range
2781 if((y>=fRangeHistoCharge) || (y<0.0)) return;
2782 if(fRangeHistoCharge < 0.0) return;
2784 //Calcul the y place
2785 Int_t yplace = (Int_t) (fNumberBinCharge*y/fRangeHistoCharge)+1;
2786 Int_t place = (fNumberBinCharge+2)*(x+1)+yplace;
2789 fCH2d->GetArray()[place]++;
2793 //////////////////////////////////////////////////////////////////////////////////
2794 // Geometrical functions
2795 ///////////////////////////////////////////////////////////////////////////////////
2796 //_____________________________________________________________________________
2797 Int_t AliTRDCalibraFillHisto::GetLayer(Int_t d) const
2800 // Reconstruct the layer number from the detector number
2803 return ((Int_t) (d % 6));
2807 //_____________________________________________________________________________
2808 Int_t AliTRDCalibraFillHisto::GetStack(Int_t d) const
2811 // Reconstruct the stack number from the detector number
2813 const Int_t kNlayer = 6;
2815 return ((Int_t) (d % 30) / kNlayer);
2819 //_____________________________________________________________________________
2820 Int_t AliTRDCalibraFillHisto::GetSector(Int_t d) const
2823 // Reconstruct the sector number from the detector number
2827 return ((Int_t) (d / fg));
2830 ///////////////////////////////////////////////////////////////////////////////////
2831 // Getter functions for DAQ of the CH2d and the PH2d
2832 //////////////////////////////////////////////////////////////////////////////////
2833 //_____________________________________________________________________
2834 TProfile2D* AliTRDCalibraFillHisto::GetPH2d(Int_t nbtimebin, Float_t samplefrequency)
2837 // return pointer to fPH2d TProfile2D
2838 // create a new TProfile2D if it doesn't exist allready
2844 fTimeMax = nbtimebin;
2845 fSf = samplefrequency;
2851 //_____________________________________________________________________
2852 TH2I* AliTRDCalibraFillHisto::GetCH2d()
2855 // return pointer to fCH2d TH2I
2856 // create a new TH2I if it doesn't exist allready
2865 ////////////////////////////////////////////////////////////////////////////////////////////
2866 // Drift velocity calibration
2867 ///////////////////////////////////////////////////////////////////////////////////////////
2868 //_____________________________________________________________________
2869 TLinearFitter* AliTRDCalibraFillHisto::GetLinearFitter(Int_t detector, Bool_t force)
2872 // return pointer to TLinearFitter Calibration
2873 // if force is true create a new TLinearFitter if it doesn't exist allready
2876 if ((!force) || (fLinearFitterArray.UncheckedAt(detector))){
2877 return (TLinearFitter*)fLinearFitterArray.UncheckedAt(detector);
2880 // if we are forced and TLinearFitter doesn't yet exist create it
2882 // new TLinearFitter
2883 TLinearFitter *linearfitter = new TLinearFitter(2,"pol1");
2884 fLinearFitterArray.AddAt(linearfitter,detector);
2885 return linearfitter;
2888 //____________________________________________________________________________
2889 void AliTRDCalibraFillHisto::AnalyseLinearFitter()
2892 // Analyse array of linear fitter because can not be written
2893 // Store two arrays: one with the param the other one with the error param + number of entries
2896 for(Int_t k = 0; k < 540; k++){
2897 TLinearFitter *linearfitter = GetLinearFitter(k);
2898 if((linearfitter!=0) && (fEntriesLinearFitter[k]>10)){
2899 TVectorD *par = new TVectorD(2);
2900 TVectorD pare = TVectorD(2);
2901 TVectorD *parE = new TVectorD(3);
2902 if((linearfitter->EvalRobust(0.8)==0)) {
2903 //linearfitter->Eval();
2904 linearfitter->GetParameters(*par);
2905 //linearfitter->GetErrors(pare);
2906 //Float_t ppointError = TMath::Sqrt(TMath::Abs(linearfitter->GetChisquare())/fEntriesLinearFitter[k]);
2907 //(*parE)[0] = pare[0]*ppointError;
2908 //(*parE)[1] = pare[1]*ppointError;
2912 (*parE)[2] = (Double_t) fEntriesLinearFitter[k];
2913 ((TObjArray *)fLinearVdriftFit->GetPArray())->AddAt(par,k);
2914 ((TObjArray *)fLinearVdriftFit->GetEArray())->AddAt(parE,k);