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 "AliTRDtrack.h"
65 #include "AliTRDtrackV1.h"
66 #include "AliTRDrawStreamBase.h"
67 #include "AliRawReader.h"
68 #include "AliRawReaderDate.h"
69 #include "AliTRDgeometry.h"
70 #include "./Cal/AliTRDCalROC.h"
71 #include "./Cal/AliTRDCalPad.h"
72 #include "./Cal/AliTRDCalDet.h"
74 #include "AliTRDrawFastStream.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)
145 ,fThresholdClusterPRF2(15.0)
146 ,fLimitChargeIntegration(kFALSE)
147 ,fFillWithZero(kFALSE)
148 ,fNormalizeNbOfCluster(kFALSE)
152 ,fSubVersionGainUsed(0)
153 ,fVersionGainLocalUsed(0)
154 ,fSubVersionGainLocalUsed(0)
155 ,fVersionVdriftUsed(0)
156 ,fSubVersionVdriftUsed(0)
157 ,fCalibraMode(new AliTRDCalibraMode())
160 ,fDetectorPreviousTrack(-1)
164 ,fNumberClustersf(30)
165 ,fNumberClustersProcent(0.5)
166 ,fThresholdClustersDAQ(120.0)
174 ,fNumberBinCharge(50)
180 ,fGoodTracklet(kTRUE)
181 ,fLinearFitterTracklet(0x0)
183 ,fEntriesLinearFitter(0x0)
188 ,fLinearFitterArray(540)
189 ,fLinearVdriftFit(0x0)
194 // Default constructor
198 // Init some default values
201 fNumberUsedCh[0] = 0;
202 fNumberUsedCh[1] = 0;
203 fNumberUsedPh[0] = 0;
204 fNumberUsedPh[1] = 0;
206 fGeo = new AliTRDgeometry();
207 fCalibDB = AliTRDcalibDB::Instance();
210 //______________________________________________________________________________________
211 AliTRDCalibraFillHisto::AliTRDCalibraFillHisto(const AliTRDCalibraFillHisto &c)
218 ,fPRF2dOn(c.fPRF2dOn)
219 ,fHisto2d(c.fHisto2d)
220 ,fVector2d(c.fVector2d)
221 ,fLinearFitterOn(c.fLinearFitterOn)
222 ,fLinearFitterDebugOn(c.fLinearFitterDebugOn)
223 ,fRelativeScale(c.fRelativeScale)
224 ,fThresholdClusterPRF2(c.fThresholdClusterPRF2)
225 ,fLimitChargeIntegration(c.fLimitChargeIntegration)
226 ,fFillWithZero(c.fFillWithZero)
227 ,fNormalizeNbOfCluster(c.fNormalizeNbOfCluster)
228 ,fMaxCluster(c.fMaxCluster)
229 ,fNbMaxCluster(c.fNbMaxCluster)
230 ,fVersionGainUsed(c.fVersionGainUsed)
231 ,fSubVersionGainUsed(c.fSubVersionGainUsed)
232 ,fVersionGainLocalUsed(c.fVersionGainLocalUsed)
233 ,fSubVersionGainLocalUsed(c.fSubVersionGainLocalUsed)
234 ,fVersionVdriftUsed(c.fVersionVdriftUsed)
235 ,fSubVersionVdriftUsed(c.fSubVersionVdriftUsed)
238 ,fDebugLevel(c.fDebugLevel)
239 ,fDetectorPreviousTrack(c.fDetectorPreviousTrack)
240 ,fMCMPrevious(c.fMCMPrevious)
241 ,fROBPrevious(c.fROBPrevious)
242 ,fNumberClusters(c.fNumberClusters)
243 ,fNumberClustersf(c.fNumberClustersf)
244 ,fNumberClustersProcent(c.fNumberClustersProcent)
245 ,fThresholdClustersDAQ(c.fThresholdClustersDAQ)
246 ,fNumberRowDAQ(c.fNumberRowDAQ)
247 ,fNumberColDAQ(c.fNumberColDAQ)
248 ,fProcent(c.fProcent)
249 ,fDifference(c.fDifference)
250 ,fNumberTrack(c.fNumberTrack)
251 ,fTimeMax(c.fTimeMax)
253 ,fNumberBinCharge(c.fNumberBinCharge)
254 ,fNumberBinPRF(c.fNumberBinPRF)
255 ,fNgroupprf(c.fNgroupprf)
259 ,fGoodTracklet(c.fGoodTracklet)
260 ,fLinearFitterTracklet(0x0)
262 ,fEntriesLinearFitter(0x0)
267 ,fLinearFitterArray(540)
268 ,fLinearVdriftFit(0x0)
275 if(c.fCalibraMode) fCalibraMode = new AliTRDCalibraMode(*c.fCalibraMode);
276 if(c.fCalibraVector) fCalibraVector = new AliTRDCalibraVector(*c.fCalibraVector);
278 fPH2d = new TProfile2D(*c.fPH2d);
279 fPH2d->SetDirectory(0);
282 fPRF2d = new TProfile2D(*c.fPRF2d);
283 fPRF2d->SetDirectory(0);
286 fCH2d = new TH2I(*c.fCH2d);
287 fCH2d->SetDirectory(0);
289 if(c.fLinearVdriftFit){
290 fLinearVdriftFit = new AliTRDCalibraVdriftLinearFit(*c.fLinearVdriftFit);
293 if(c.fCalDetGain) fCalDetGain = new AliTRDCalDet(*c.fCalDetGain);
294 if(c.fCalROCGain) fCalROCGain = new AliTRDCalROC(*c.fCalROCGain);
299 fGeo = new AliTRDgeometry();
300 fCalibDB = AliTRDcalibDB::Instance();
302 fNumberUsedCh[0] = 0;
303 fNumberUsedCh[1] = 0;
304 fNumberUsedPh[0] = 0;
305 fNumberUsedPh[1] = 0;
309 //____________________________________________________________________________________
310 AliTRDCalibraFillHisto::~AliTRDCalibraFillHisto()
313 // AliTRDCalibraFillHisto destructor
317 if ( fDebugStreamer ) delete fDebugStreamer;
319 if ( fCalDetGain ) delete fCalDetGain;
320 if ( fCalROCGain ) delete fCalROCGain;
322 if( fLinearFitterTracklet ) { delete fLinearFitterTracklet; }
326 delete [] fEntriesCH;
327 delete [] fEntriesLinearFitter;
330 for(Int_t idet=0; idet<AliTRDgeometry::kNdet; idet++){
331 TLinearFitter *f = (TLinearFitter*)fLinearFitterArray.At(idet);
334 if(fLinearVdriftFit) delete fLinearVdriftFit;
340 //_____________________________________________________________________________
341 void AliTRDCalibraFillHisto::Destroy()
352 //_____________________________________________________________________________
353 void AliTRDCalibraFillHisto::DestroyDebugStreamer()
356 // Delete DebugStreamer
359 if ( fDebugStreamer ) delete fDebugStreamer;
360 fDebugStreamer = 0x0;
363 //_____________________________________________________________________________
364 void AliTRDCalibraFillHisto::ClearHistos()
384 //////////////////////////////////////////////////////////////////////////////////
385 // calibration with AliTRDtrackV1: Init, Update
386 //////////////////////////////////////////////////////////////////////////////////
387 //____________Functions for initialising the AliTRDCalibraFillHisto in the code_________
388 Bool_t AliTRDCalibraFillHisto::Init2Dhistos(Int_t nboftimebin)
391 // Init the histograms and stuff to be filled
396 AliTRDcalibDB *cal = AliTRDcalibDB::Instance();
398 AliInfo("Could not get calibDB");
401 AliTRDCommonParam *parCom = AliTRDCommonParam::Instance();
403 AliInfo("Could not get CommonParam");
408 if(nboftimebin > 0) fTimeMax = nboftimebin;
409 else fTimeMax = cal->GetNumberOfTimeBinsDCS();
410 if(fTimeMax <= 0) fTimeMax = 30;
411 printf("////////////////////////////////////////////\n");
412 printf("Number of time bins in calibration component %d\n",fTimeMax);
413 printf("////////////////////////////////////////////\n");
414 fSf = parCom->GetSamplingFrequency();
415 if(!fNormalizeNbOfCluster) fRelativeScale = 20.0;
416 else fRelativeScale = 1.18;
417 fNumberClustersf = fTimeMax;
418 fNumberClusters = (Int_t)(fNumberClustersProcent*fTimeMax);
420 // Init linear fitter
421 if(!fLinearFitterTracklet) {
422 fLinearFitterTracklet = new TLinearFitter(2,"pol1");
423 fLinearFitterTracklet->StoreData(kTRUE);
426 // Calcul Xbins Chambd0, Chamb2
427 Int_t ntotal0 = CalculateTotalNumberOfBins(0);
428 Int_t ntotal1 = CalculateTotalNumberOfBins(1);
429 Int_t ntotal2 = CalculateTotalNumberOfBins(2);
431 // If vector method On initialised all the stuff
433 fCalibraVector = new AliTRDCalibraVector();
434 fCalibraVector->SetNumberBinCharge(fNumberBinCharge);
435 fCalibraVector->SetTimeMax(fTimeMax);
436 if(fNgroupprf != 0) {
437 fCalibraVector->SetNumberBinPRF(2*fNgroupprf*fNumberBinPRF);
438 fCalibraVector->SetPRFRange((Float_t)(3.0*fNgroupprf));
441 fCalibraVector->SetNumberBinPRF(fNumberBinPRF);
442 fCalibraVector->SetPRFRange(1.5);
444 for(Int_t k = 0; k < 3; k++){
445 fCalibraVector->SetDetCha0(k,fCalibraMode->GetDetChamb0(k));
446 fCalibraVector->SetDetCha2(k,fCalibraMode->GetDetChamb2(k));
448 fCalibraVector->SetNzNrphi(0,fCalibraMode->GetNz(0),fCalibraMode->GetNrphi(0));
449 fCalibraVector->SetNzNrphi(1,fCalibraMode->GetNz(1),fCalibraMode->GetNrphi(1));
450 fCalibraVector->SetNzNrphi(2,fCalibraMode->GetNz(2),fCalibraMode->GetNrphi(2));
451 fCalibraVector->SetNbGroupPRF(fNgroupprf);
454 // Create the 2D histos corresponding to the pad groupCalibration mode
457 AliInfo(Form("The pad calibration mode for the relative gain calibration: Nz %d, and Nrphi %d"
458 ,fCalibraMode->GetNz(0)
459 ,fCalibraMode->GetNrphi(0)));
461 // Create the 2D histo
466 fAmpTotal = new Float_t[TMath::Max(fCalibraMode->GetDetChamb2(0),fCalibraMode->GetDetChamb0(0))];
467 for (Int_t k = 0; k < TMath::Max(fCalibraMode->GetDetChamb2(0),fCalibraMode->GetDetChamb0(0)); k++) {
471 fEntriesCH = new Int_t[ntotal0];
472 for(Int_t k = 0; k < ntotal0; k++){
479 AliInfo(Form("The pad calibration mode for the drift velocity calibration: Nz %d, and Nrphi %d"
480 ,fCalibraMode->GetNz(1)
481 ,fCalibraMode->GetNrphi(1)));
483 // Create the 2D histo
488 fPHPlace = new Short_t[fTimeMax];
489 for (Int_t k = 0; k < fTimeMax; k++) {
492 fPHValue = new Float_t[fTimeMax];
493 for (Int_t k = 0; k < fTimeMax; k++) {
497 if (fLinearFitterOn) {
498 if(fLinearFitterDebugOn) {
499 fLinearFitterArray.SetName("ArrayLinearFitters");
500 fEntriesLinearFitter = new Int_t[540];
501 for(Int_t k = 0; k < 540; k++){
502 fEntriesLinearFitter[k] = 0;
505 fLinearVdriftFit = new AliTRDCalibraVdriftLinearFit();
510 AliInfo(Form("The pad calibration mode for the PRF calibration: Nz %d, and Nrphi %d"
511 ,fCalibraMode->GetNz(2)
512 ,fCalibraMode->GetNrphi(2)));
513 // Create the 2D histo
515 CreatePRF2d(ntotal2);
522 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
523 Bool_t AliTRDCalibraFillHisto::InitCalDet()
526 // Init the Gain Cal Det
531 AliCDBEntry *entry = AliCDBManager::Instance()->Get("TRD/Calib/ChamberGainFactor",AliCDBManager::Instance()->GetRun(),fVersionGainUsed,fSubVersionGainUsed);
533 AliError("No gain det calibration entry found");
536 AliTRDCalDet *calDet = (AliTRDCalDet *)entry->GetObject();
538 AliError("No calDet gain found");
544 fCalDetGain->~AliTRDCalDet();
545 new(fCalDetGain) AliTRDCalDet(*(calDet));
546 }else fCalDetGain = new AliTRDCalDet(*(calDet));
551 name += fVersionGainUsed;
553 name += fSubVersionGainUsed;
555 name += fCalibraMode->GetNz(0);
557 name += fCalibraMode->GetNrphi(0);
559 fCH2d->SetTitle(name);
562 TString namee("Ver");
563 namee += fVersionVdriftUsed;
565 namee += fSubVersionVdriftUsed;
567 namee += fCalibraMode->GetNz(1);
569 namee += fCalibraMode->GetNrphi(1);
571 fPH2d->SetTitle(namee);
577 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
578 Bool_t AliTRDCalibraFillHisto::InitCalPad(Int_t detector)
581 // Init the Gain Cal Pad
586 AliCDBEntry *entry = AliCDBManager::Instance()->Get("TRD/Calib/LocalGainFactor",AliCDBManager::Instance()->GetRun(),fVersionGainLocalUsed,fSubVersionGainLocalUsed);
588 AliError("No gain pad calibration entry found");
591 AliTRDCalPad *calPad = (AliTRDCalPad *)entry->GetObject();
593 AliError("No calPad gain found");
596 AliTRDCalROC *calRoc = (AliTRDCalROC *)calPad->GetCalROC(detector);
598 AliError("No calRoc gain found");
603 fCalROCGain->~AliTRDCalROC();
604 new(fCalROCGain) AliTRDCalROC(*(calRoc));
605 }else fCalROCGain = new AliTRDCalROC(*(calRoc));
614 //____________Offline tracking in the AliTRDtracker____________________________
615 Bool_t AliTRDCalibraFillHisto::UpdateHistograms(const AliTRDtrack *t)
618 // Use AliTRDtrack for the calibration
622 AliTRDcluster *cl = 0x0; // pointeur to cluster
623 Int_t index0 = 0; // index of the first cluster in the current chamber
624 Int_t index1 = 0; // index of the current cluster in the current chamber
626 //////////////////////////////
627 // loop over the clusters
628 ///////////////////////////////
629 while((cl = t->GetCluster(index1))){
631 /////////////////////////////////////////////////////////////////////////
632 // Fill the infos for the previous clusters if not the same detector
633 ////////////////////////////////////////////////////////////////////////
634 Int_t detector = cl->GetDetector();
635 if ((detector != fDetectorPreviousTrack) &&
636 (index0 != index1)) {
640 //If the same track, then look if the previous detector is in
641 //the same plane, if yes: not a good track
642 if ((GetLayer(detector) == GetLayer(fDetectorPreviousTrack))) {
646 // Fill only if the track doesn't touch a masked pad or doesn't
649 // drift velocity unables to cut bad tracklets
650 Bool_t pass = FindP1TrackPHtracklet(t,index0,index1);
654 FillTheInfoOfTheTrackCH(index1-index0);
659 FillTheInfoOfTheTrackPH();
662 if(pass && fPRF2dOn) HandlePRFtracklet(t,index0,index1);
665 } // if a good tracklet
668 ResetfVariablestracklet();
671 } // Fill at the end the charge
674 /////////////////////////////////////////////////////////////
675 // Localise and take the calib gain object for the detector
676 ////////////////////////////////////////////////////////////
677 if (detector != fDetectorPreviousTrack) {
679 //Localise the detector
680 LocalisationDetectorXbins(detector);
683 AliTRDcalibDB *cal = AliTRDcalibDB::Instance();
685 AliInfo("Could not get calibDB");
690 if(!fIsHLT) InitCalPad(detector);
694 // Reset the detectbjobsor
695 fDetectorPreviousTrack = detector;
697 ///////////////////////////////////////
698 // Store the info of the cluster
699 ///////////////////////////////////////
700 Int_t row = cl->GetPadRow();
701 Int_t col = cl->GetPadCol();
702 CheckGoodTrackletV1(cl);
703 Int_t group[2] = {0,0};
704 if(fCH2dOn) group[0] = CalculateCalibrationGroup(0,row,col);
705 if(fPH2dOn) group[1] = CalculateCalibrationGroup(1,row,col);
706 StoreInfoCHPHtrack(cl,t->GetClusterdQdl(index1),group,row,col);
710 } // while on clusters
712 ///////////////////////////
713 // Fill the last plane
714 //////////////////////////
715 if( index0 != index1 ){
721 // drift velocity unables to cut bad tracklets
722 Bool_t pass = FindP1TrackPHtracklet(t,index0,index1);
726 FillTheInfoOfTheTrackCH(index1-index0);
731 FillTheInfoOfTheTrackPH();
734 if(pass && fPRF2dOn) HandlePRFtracklet(t,index0,index1);
736 } // if a good tracklet
741 ResetfVariablestracklet();
746 //____________Offline tracking in the AliTRDtracker____________________________
747 Bool_t AliTRDCalibraFillHisto::UpdateHistogramsV1(const AliTRDtrackV1 *t)
750 // Use AliTRDtrackV1 for the calibration
754 const AliTRDseedV1 *tracklet = 0x0; // tracklet per plane
755 AliTRDcluster *cl = 0x0; // cluster attached now to the tracklet
756 AliTRDcluster *cls = 0x0; // shared cluster attached now to the tracklet
757 Bool_t newtr = kTRUE; // new track
760 // AliTRDcalibDB *cal = AliTRDcalibDB::Instance();
763 AliInfo("Could not get calibDB");
768 AliInfo("Could not get calibDB");
773 ///////////////////////////
774 // loop over the tracklet
775 ///////////////////////////
776 for(Int_t itr = 0; itr < 6; itr++){
778 if(!(tracklet = t->GetTracklet(itr))) continue;
779 if(!tracklet->IsOK()) continue;
781 ResetfVariablestracklet();
783 //////////////////////////////////////////
784 // localisation of the tracklet and dqdl
785 //////////////////////////////////////////
786 Int_t layer = tracklet->GetPlane();
788 while(!(cl = tracklet->GetClusters(ic++))) continue;
789 Int_t detector = cl->GetDetector();
790 if (detector != fDetectorPreviousTrack) {
791 // if not a new track
793 // don't use the rest of this track if in the same plane
794 if (layer == GetLayer(fDetectorPreviousTrack)) {
795 //printf("bad tracklet, same layer for detector %d\n",detector);
799 //Localise the detector bin
800 LocalisationDetectorXbins(detector);
802 if(!fIsHLT) InitCalPad(detector);
805 fDetectorPreviousTrack = detector;
809 ////////////////////////////
810 // loop over the clusters
811 ////////////////////////////
812 Int_t nbclusters = 0;
813 for(int jc=0; jc<AliTRDseedV1::kNtb; jc++){
814 if(!(cl = tracklet->GetClusters(jc))) continue;
817 // Store the info bis of the tracklet
818 Int_t row = cl->GetPadRow();
819 Int_t col = cl->GetPadCol();
820 CheckGoodTrackletV1(cl);
821 Int_t group[2] = {0,0};
822 if(fCH2dOn) group[0] = CalculateCalibrationGroup(0,row,col);
823 if(fPH2dOn) group[1] = CalculateCalibrationGroup(1,row,col);
824 // Add the charge if shared cluster
825 cls = tracklet->GetClusters(jc+AliTRDseedV1::kNtb);
827 StoreInfoCHPHtrack(cl, tracklet->GetdQdl(jc),group,row,col,cls);
830 ////////////////////////////////////////
831 // Fill the stuffs if a good tracklet
832 ////////////////////////////////////////
835 // drift velocity unables to cut bad tracklets
836 Bool_t pass = FindP1TrackPHtrackletV1(tracklet, nbclusters);
838 //printf("pass %d and nbclusters %d\n",pass,nbclusters);
842 FillTheInfoOfTheTrackCH(nbclusters);
847 FillTheInfoOfTheTrackPH();
850 if(pass && fPRF2dOn) HandlePRFtrackletV1(tracklet,nbclusters);
852 } // if a good tracklet
858 ///////////////////////////////////////////////////////////////////////////////////
859 // Routine inside the update with AliTRDtrack
860 ///////////////////////////////////////////////////////////////////////////////////
861 //____________Offine tracking in the AliTRDtracker_____________________________
862 Bool_t AliTRDCalibraFillHisto::FindP1TrackPHtracklet(const AliTRDtrack *t, Int_t index0, Int_t index1)
865 // Drift velocity calibration:
866 // Fit the clusters with a straight line
867 // From the slope find the drift velocity
870 //Number of points: if less than 3 return kFALSE
871 Int_t npoints = index1-index0;
872 if(npoints <= 2) return kFALSE;
877 Int_t detector = ((AliTRDcluster *) t->GetCluster(index0))->GetDetector(); //detector
878 // parameters of the track
879 Double_t snp = t->GetSnpPlane(GetLayer(detector)); // sin angle in the plan yx track
880 Double_t tgl = t->GetTglPlane(GetLayer(detector)); // dz/dl and not dz/dx!
881 Double_t tnp = 0.0; // tan angle in the plan xy track
882 if( TMath::Abs(snp) < 1.){
883 tnp = snp / TMath::Sqrt((1.-snp)*(1.+snp));
885 Float_t dzdx = tgl*TMath::Sqrt(1+tnp*tnp); // dz/dx now from dz/dl
886 // tilting pad and cross row
887 Int_t crossrow = 0; // if it crosses a pad row
888 Int_t rowp = -1; // if it crosses a pad row
889 AliTRDpadPlane *padplane = fGeo->GetPadPlane(GetLayer(detector),GetStack(detector));
890 Double_t tiltingangle = padplane->GetTiltingAngle(); // tiltingangle of the pad
891 Float_t tnt = TMath::Tan(tiltingangle/180.*TMath::Pi()); // tan tiltingangle
893 fLinearFitterTracklet->ClearPoints();
894 Double_t dydt = 0.0; // dydt tracklet after straight line fit
895 Double_t errorpar = 0.0; // error after straight line fit on dy/dt
896 Double_t pointError = 0.0; // error after straight line fit
897 Int_t nbli = 0; // number linear fitter points
899 //////////////////////////////
900 // loop over clusters
901 ////////////////////////////
902 for(Int_t k = 0; k < npoints; k++){
904 AliTRDcluster *cl = (AliTRDcluster *) t->GetCluster(k+index0);
905 if((fLimitChargeIntegration) && (!cl->IsInChamber())) continue;
906 Double_t ycluster = cl->GetY();
907 Int_t time = cl->GetPadTime();
908 Double_t timeis = time/fSf;
909 //Double_t q = cl->GetQ();
910 //See if cross two pad rows
911 Int_t row = cl->GetPadRow();
913 if(row != rowp) crossrow = 1;
915 fLinearFitterTracklet->AddPoint(&timeis,ycluster,1);
920 //////////////////////////////
922 //////////////////////////////
924 fLinearFitterTracklet->ClearPoints();
928 fLinearFitterTracklet->Eval();
929 fLinearFitterTracklet->GetParameters(pars);
930 pointError = TMath::Sqrt(fLinearFitterTracklet->GetChisquare()/(nbli-2));
931 errorpar = fLinearFitterTracklet->GetParError(1)*pointError;
933 fLinearFitterTracklet->ClearPoints();
935 /////////////////////////////
937 ////////////////////////////
939 if ( !fDebugStreamer ) {
941 TDirectory *backup = gDirectory;
942 fDebugStreamer = new TTreeSRedirector("TRDdebugCalibraFill.root");
943 if ( backup ) backup->cd(); //we don't want to be cd'd to the debug streamer
947 (* fDebugStreamer) << "FindP1TrackPHtracklet0"<<
948 //"snpright="<<snpright<<
949 "npoints="<<npoints<<
951 "detector="<<detector<<
958 "crossrow="<<crossrow<<
959 "errorpar="<<errorpar<<
960 "pointError="<<pointError<<
964 Int_t nbclusters = index1-index0;
965 Int_t layer = GetLayer(fDetectorPreviousTrack);
967 (* fDebugStreamer) << "FindP1TrackPHtracklet1"<<
968 //"snpright="<<snpright<<
969 "nbclusters="<<nbclusters<<
970 "detector="<<fDetectorPreviousTrack<<
976 ///////////////////////////
978 ///////////////////////////
979 if(npoints < fNumberClusters) return kFALSE;
980 if(npoints > fNumberClustersf) return kFALSE;
981 if(pointError >= 0.1) return kFALSE;
982 if(crossrow == 1) return kFALSE;
984 ////////////////////////////
986 ////////////////////////////
988 //Add to the linear fitter of the detector
989 if( TMath::Abs(snp) < 1.){
990 Double_t x = tnp-dzdx*tnt;
991 if(fLinearFitterDebugOn) {
992 (GetLinearFitter(detector,kTRUE))->AddPoint(&x,dydt);
993 fEntriesLinearFitter[detector]++;
995 fLinearVdriftFit->Update(detector,x,pars[1]);
1001 //____________Offine tracking in the AliTRDtracker_____________________________
1002 Bool_t AliTRDCalibraFillHisto::FindP1TrackPHtrackletV1(const AliTRDseedV1 *tracklet, Int_t nbclusters)
1005 // Drift velocity calibration:
1006 // Fit the clusters with a straight line
1007 // From the slope find the drift velocity
1010 ////////////////////////////////////////////////
1011 //Number of points: if less than 3 return kFALSE
1012 /////////////////////////////////////////////////
1013 if(nbclusters <= 2) return kFALSE;
1018 // results of the linear fit
1019 Double_t dydt = 0.0; // dydt tracklet after straight line fit
1020 Double_t errorpar = 0.0; // error after straight line fit on dy/dt
1021 Double_t pointError = 0.0; // error after straight line fit
1022 // pad row problemes: avoid tracklet that cross pad rows, tilting angle in the constant
1023 Int_t crossrow = 0; // if it crosses a pad row
1024 Int_t rowp = -1; // if it crosses a pad row
1025 Float_t tnt = tracklet->GetTilt(); // tan tiltingangle
1026 fLinearFitterTracklet->ClearPoints();
1029 ///////////////////////////////////////////
1030 // Take the parameters of the track
1031 //////////////////////////////////////////
1032 // take now the snp, tnp and tgl from the track
1033 Double_t snp = tracklet->GetSnp(); // sin dy/dx at the end of the chamber
1034 Double_t tnp = 0.0; // dy/dx at the end of the chamber
1035 if( TMath::Abs(snp) < 1.){
1036 tnp = snp / TMath::Sqrt((1.-snp)*(1.+snp));
1038 Double_t tgl = tracklet->GetTgl(); // dz/dl
1039 Double_t dzdx = tgl*TMath::Sqrt(1+tnp*tnp); // dz/dx calculated from dz/dl
1041 //Double_t tnp = tracklet->GetYref(1); // dy/dx at the entrance of the chamber
1042 //Double_t tgl = tracklet->GetZref(1); // dz/dl at the entrance of the chamber
1043 //Double_t dzdx = tgl; //*TMath::Sqrt(1+tnp*tnp); // dz/dx from dz/dl
1044 // at the end with correction due to linear fit
1045 //Double_t tnp = tracklet->GetYfit(1); // dy/dx at the end of the chamber after fit correction
1046 //Double_t tgl = tracklet->GetZfit(1); // dz/dl at the end of the chamber after fit correction
1049 ////////////////////////////
1050 // loop over the clusters
1051 ////////////////////////////
1053 AliTRDcluster *cl = 0x0;
1054 //////////////////////////////
1055 // Check no shared clusters
1056 //////////////////////////////
1057 for(int icc=AliTRDseedV1::kNtb; icc<AliTRDseedV1::kNclusters; icc++){
1058 cl = tracklet->GetClusters(icc);
1059 if(cl) crossrow = 1;
1061 //////////////////////////////////
1063 //////////////////////////////////
1064 for(int ic=0; ic<AliTRDseedV1::kNtb; ic++){
1065 if(!(cl = tracklet->GetClusters(ic))) continue;
1066 if((fLimitChargeIntegration) && (!cl->IsInChamber())) continue;
1068 Double_t ycluster = cl->GetY();
1069 Int_t time = cl->GetPadTime();
1070 Double_t timeis = time/fSf;
1071 //See if cross two pad rows
1072 Int_t row = cl->GetPadRow();
1073 if(rowp==-1) rowp = row;
1074 if(row != rowp) crossrow = 1;
1076 fLinearFitterTracklet->AddPoint(&timeis,ycluster,1);
1082 ////////////////////////////////////
1083 // Do the straight line fit now
1084 ///////////////////////////////////
1086 fLinearFitterTracklet->ClearPoints();
1090 fLinearFitterTracklet->Eval();
1091 fLinearFitterTracklet->GetParameters(pars);
1092 pointError = TMath::Sqrt(fLinearFitterTracklet->GetChisquare()/(nbli-2));
1093 errorpar = fLinearFitterTracklet->GetParError(1)*pointError;
1095 //printf("chis %f, nbli %d, pointError %f, parError %f, errorpar %f\n",fLinearFitterTracklet->GetChisquare(),nbli,pointError,fLinearFitterTracklet->GetParError(1),errorpar);
1096 fLinearFitterTracklet->ClearPoints();
1098 ////////////////////////////////
1100 ///////////////////////////////
1103 if(fDebugLevel > 0){
1104 if ( !fDebugStreamer ) {
1106 TDirectory *backup = gDirectory;
1107 fDebugStreamer = new TTreeSRedirector("TRDdebugCalibraFill.root");
1108 if ( backup ) backup->cd(); //we don't want to be cd'd to the debug streamer
1112 Int_t layer = GetLayer(fDetectorPreviousTrack);
1114 (* fDebugStreamer) << "FindP1TrackPHtrackletV1"<<
1115 //"snpright="<<snpright<<
1117 "nbclusters="<<nbclusters<<
1118 "detector="<<fDetectorPreviousTrack<<
1126 "crossrow="<<crossrow<<
1127 "errorpar="<<errorpar<<
1128 "pointError="<<pointError<<
1133 /////////////////////////
1135 ////////////////////////
1137 if(nbclusters < fNumberClusters) return kFALSE;
1138 if(nbclusters > fNumberClustersf) return kFALSE;
1139 if(pointError >= 0.3) return kFALSE;
1140 if(crossrow == 1) return kFALSE;
1142 ///////////////////////
1144 //////////////////////
1146 if(fLinearFitterOn){
1147 //Add to the linear fitter of the detector
1148 if( TMath::Abs(snp) < 1.){
1149 Double_t x = tnp-dzdx*tnt;
1150 if(fLinearFitterDebugOn) {
1151 (GetLinearFitter(fDetectorPreviousTrack,kTRUE))->AddPoint(&x,dydt);
1152 fEntriesLinearFitter[fDetectorPreviousTrack]++;
1154 fLinearVdriftFit->Update(fDetectorPreviousTrack,x,pars[1]);
1160 //____________Offine tracking in the AliTRDtracker_____________________________
1161 Bool_t AliTRDCalibraFillHisto::HandlePRFtracklet(const AliTRDtrack *t, Int_t index0, Int_t index1)
1164 // PRF width calibration
1165 // Assume a Gaussian shape: determinate the position of the three pad clusters
1166 // Fit with a straight line
1167 // Take the fitted values for all the clusters (3 or 2 pad clusters)
1168 // Fill the PRF as function of angle of the track
1173 //////////////////////////
1175 /////////////////////////
1176 Int_t npoints = index1-index0; // number of total points
1177 Int_t nb3pc = 0; // number of three pads clusters used for fit
1178 Int_t detector = ((AliTRDcluster *) t->GetCluster(index0))->GetDetector(); // detector
1179 // To see the difference due to the fit
1180 Double_t *padPositions;
1181 padPositions = new Double_t[npoints];
1182 for(Int_t k = 0; k < npoints; k++){
1183 padPositions[k] = 0.0;
1185 // Take the tgl and snp with the track t now
1186 Double_t tgl = t->GetTglPlane(GetLayer(detector)); //dz/dl and not dz/dx
1187 Double_t snp = t->GetSnpPlane(GetLayer(detector)); // sin angle in xy plan
1188 Float_t dzdx = 0.0; // dzdx
1190 if(TMath::Abs(snp) < 1.0){
1191 tnp = snp / TMath::Sqrt((1.-snp)*(1.+snp));
1192 dzdx = tgl*TMath::Sqrt(1+tnp*tnp);
1195 fLinearFitterTracklet->ClearPoints();
1197 ///////////////////////////
1198 // calcul the tnp group
1199 ///////////////////////////
1200 Bool_t echec = kFALSE;
1201 Double_t shift = 0.0;
1202 //Calculate the shift in x coresponding to this tnp
1203 if(fNgroupprf != 0.0){
1204 shift = -3.0*(fNgroupprf-1)-1.5;
1205 Double_t limithigh = -0.2*(fNgroupprf-1);
1206 if((tnp < (-0.2*fNgroupprf)) || (tnp > (0.2*fNgroupprf))) echec = kTRUE;
1208 while(tnp > limithigh){
1215 delete [] padPositions;
1219 //////////////////////
1221 /////////////////////
1222 for(Int_t k = 0; k < npoints; k++){
1224 AliTRDcluster *cl = (AliTRDcluster *) t->GetCluster(k+index0);
1226 Short_t *signals = cl->GetSignals();
1227 Double_t time = cl->GetPadTime();
1228 //Calculate x if possible
1229 Float_t xcenter = 0.0;
1230 Bool_t echec1 = kTRUE;
1231 if((time<=7) || (time>=21)) continue;
1232 // Center 3 balanced: position with the center of the pad
1233 if ((((Float_t) signals[3]) > 0.0) &&
1234 (((Float_t) signals[2]) > 0.0) &&
1235 (((Float_t) signals[4]) > 0.0)) {
1237 // Security if the denomiateur is 0
1238 if ((((Float_t) (((Float_t) signals[3]) * ((Float_t) signals[3]))) /
1239 ((Float_t) (((Float_t) signals[2]) * ((Float_t) signals[4])))) != 1.0) {
1240 xcenter = 0.5 * (TMath::Log((Float_t) (((Float_t) signals[4]) / ((Float_t) signals[2]))))
1241 / (TMath::Log(((Float_t) (((Float_t) signals[3]) * ((Float_t) signals[3])))
1242 / ((Float_t) (((Float_t) signals[2]) * ((Float_t) signals[4])))));
1248 if(TMath::Abs(xcenter) > 0.5) echec = kTRUE;
1250 //if no echec: calculate with the position of the pad
1251 // Position of the cluster
1252 Double_t padPosition = xcenter + cl->GetPadCol();
1253 padPositions[k] = padPosition;
1255 fLinearFitterTracklet->AddPoint(&time, padPosition,1);
1259 /////////////////////////////
1261 ////////////////////////////
1263 delete [] padPositions;
1264 fLinearFitterTracklet->ClearPoints();
1267 fLinearFitterTracklet->Eval();
1269 fLinearFitterTracklet->GetParameters(line);
1270 Float_t pointError = -1.0;
1271 if( fLinearFitterTracklet->GetChisquare()>=0.0) {
1272 pointError = TMath::Sqrt( fLinearFitterTracklet->GetChisquare()/(nb3pc-2));
1274 fLinearFitterTracklet->ClearPoints();
1276 /////////////////////////////////////////////////////
1277 // Now fill the PRF: second loop over clusters
1278 /////////////////////////////////////////////////////
1279 for(Int_t k = 0; k < npoints; k++){
1281 AliTRDcluster *cl = (AliTRDcluster *) t->GetCluster(k+index0);
1282 Short_t *signals = cl->GetSignals(); // signal
1283 Double_t time = cl->GetPadTime(); // time bin
1284 Float_t padPosTracklet = line[0]+line[1]*time; // reconstruct position from fit
1285 Float_t padPos = cl->GetPadCol(); // middle pad
1286 Double_t dpad = padPosTracklet - padPos; // reconstruct position relative to middle pad from fit
1287 Float_t ycenter = 0.0; // relative center charge
1288 Float_t ymin = 0.0; // relative left charge
1289 Float_t ymax = 0.0; // relative right charge
1291 //Requiere simply two pads clusters at least
1292 if(((((Float_t) signals[3]) > 0.0) && (((Float_t) signals[2]) > 0.0)) ||
1293 ((((Float_t) signals[3]) > 0.0) && (((Float_t) signals[4]) > 0.0))){
1294 Float_t sum = ((Float_t) signals[2]) + ((Float_t) signals[3]) + ((Float_t) signals[4]);
1295 if(sum > 0.0) ycenter = ((Float_t) signals[3])/ sum;
1296 if(sum > 0.0) ymin = ((Float_t) signals[2])/ sum;
1297 if(sum > 0.0) ymax = ((Float_t) signals[4])/ sum;
1301 Int_t rowcl = cl->GetPadRow(); // row of cluster
1302 Int_t colcl = cl->GetPadCol(); // col of cluster
1303 Int_t grouplocal = CalculateCalibrationGroup(2,rowcl,colcl); // calcul the corresponding group
1304 Int_t caligroup = fCalibraMode->GetXbins(2)+ grouplocal; // calcul the corresponding group
1305 Float_t xcl = cl->GetY(); // y cluster
1306 Float_t qcl = cl->GetQ(); // charge cluster
1307 Int_t layer = GetLayer(detector); // layer
1308 Int_t stack = GetStack(detector); // stack
1309 Double_t xdiff = dpad; // reconstructed position constant
1310 Double_t x = dpad; // reconstructed position moved
1311 Float_t ep = pointError; // error of fit
1312 Float_t signal1 = (Float_t)signals[1]; // signal at the border
1313 Float_t signal3 = (Float_t)signals[3]; // signal
1314 Float_t signal2 = (Float_t)signals[2]; // signal
1315 Float_t signal4 = (Float_t)signals[4]; // signal
1316 Float_t signal5 = (Float_t)signals[5]; // signal at the border
1318 //////////////////////////////
1320 /////////////////////////////
1321 if(fDebugLevel > 0){
1322 if ( !fDebugStreamer ) {
1324 TDirectory *backup = gDirectory;
1325 fDebugStreamer = new TTreeSRedirector("TRDdebugCalibraFill.root");
1326 if ( backup ) backup->cd(); //we don't want to be cd'd to the debug streamer
1332 Float_t y = ycenter;
1333 (* fDebugStreamer) << "HandlePRFtracklet"<<
1334 "caligroup="<<caligroup<<
1335 "detector="<<detector<<
1338 "npoints="<<npoints<<
1347 "padPosition="<<padPositions[k]<<
1348 "padPosTracklet="<<padPosTracklet<<
1353 "signal1="<<signal1<<
1354 "signal2="<<signal2<<
1355 "signal3="<<signal3<<
1356 "signal4="<<signal4<<
1357 "signal5="<<signal5<<
1363 (* fDebugStreamer) << "HandlePRFtracklet"<<
1364 "caligroup="<<caligroup<<
1365 "detector="<<detector<<
1368 "npoints="<<npoints<<
1377 "padPosition="<<padPositions[k]<<
1378 "padPosTracklet="<<padPosTracklet<<
1383 "signal1="<<signal1<<
1384 "signal2="<<signal2<<
1385 "signal3="<<signal3<<
1386 "signal4="<<signal4<<
1387 "signal5="<<signal5<<
1393 (* fDebugStreamer) << "HandlePRFtracklet"<<
1394 "caligroup="<<caligroup<<
1395 "detector="<<detector<<
1398 "npoints="<<npoints<<
1407 "padPosition="<<padPositions[k]<<
1408 "padPosTracklet="<<padPosTracklet<<
1413 "signal1="<<signal1<<
1414 "signal2="<<signal2<<
1415 "signal3="<<signal3<<
1416 "signal4="<<signal4<<
1417 "signal5="<<signal5<<
1423 ////////////////////////////
1425 ///////////////////////////
1426 if(npoints < fNumberClusters) continue;
1427 if(npoints > fNumberClustersf) continue;
1428 if(nb3pc <= 5) continue;
1429 if((time >= 21) || (time < 7)) continue;
1430 if(TMath::Abs(snp) >= 1.0) continue;
1431 if(TMath::Abs(qcl) < 80) continue;
1433 ////////////////////////////
1435 ///////////////////////////
1437 if(TMath::Abs(dpad) < 1.5) {
1438 fPRF2d->Fill(shift+dpad,(caligroup+0.5),ycenter);
1439 fPRF2d->Fill(shift-dpad,(caligroup+0.5),ycenter);
1441 if((ymin > 0.0) && (TMath::Abs(dpad+1.0) < 1.5)) {
1442 fPRF2d->Fill(shift-(dpad+1.0),(caligroup+0.5),ymin);
1443 fPRF2d->Fill(shift+(dpad+1.0),(caligroup+0.5),ymin);
1445 if((ymax > 0.0) && (TMath::Abs(dpad-1.0) < 1.5)) {
1446 fPRF2d->Fill(shift+1.0-dpad,(caligroup+0.5),ymax);
1447 fPRF2d->Fill(shift-1.0+dpad,(caligroup+0.5),ymax);
1451 if(TMath::Abs(dpad) < 1.5) {
1452 fCalibraVector->UpdateVectorPRF(fDetectorPreviousTrack,grouplocal,shift+dpad,ycenter);
1453 fCalibraVector->UpdateVectorPRF(fDetectorPreviousTrack,grouplocal,shift-dpad,ycenter);
1455 if((ymin > 0.0) && (TMath::Abs(dpad+1.0) < 1.5)) {
1456 fCalibraVector->UpdateVectorPRF(fDetectorPreviousTrack,grouplocal,shift-(dpad+1.0),ymin);
1457 fCalibraVector->UpdateVectorPRF(fDetectorPreviousTrack,grouplocal,shift+(dpad+1.0),ymin);
1459 if((ymax > 0.0) && (TMath::Abs(dpad-1.0) < 1.5)) {
1460 fCalibraVector->UpdateVectorPRF(fDetectorPreviousTrack,grouplocal,shift+1.0-dpad,ymax);
1461 fCalibraVector->UpdateVectorPRF(fDetectorPreviousTrack,grouplocal,shift-1.0+dpad,ymax);
1465 delete [] padPositions;
1469 //____________Offine tracking in the AliTRDtracker_____________________________
1470 Bool_t AliTRDCalibraFillHisto::HandlePRFtrackletV1(const AliTRDseedV1 *tracklet, Int_t nbclusters)
1473 // PRF width calibration
1474 // Assume a Gaussian shape: determinate the position of the three pad clusters
1475 // Fit with a straight line
1476 // Take the fitted values for all the clusters (3 or 2 pad clusters)
1477 // Fill the PRF as function of angle of the track
1481 //printf("begin\n");
1482 ///////////////////////////////////////////
1483 // Take the parameters of the track
1484 //////////////////////////////////////////
1485 // take now the snp, tnp and tgl from the track
1486 Double_t snp = tracklet->GetSnp(); // sin dy/dx at the end of the chamber
1487 Double_t tnp = 0.0; // dy/dx at the end of the chamber
1488 if( TMath::Abs(snp) < 1.){
1489 tnp = snp / TMath::Sqrt((1.-snp)*(1.+snp));
1491 Double_t tgl = tracklet->GetTgl(); // dz/dl
1492 Double_t dzdx = tgl*TMath::Sqrt(1+tnp*tnp); // dz/dx calculated from dz/dl
1494 //Double_t tnp = tracklet->GetYref(1); // dy/dx at the entrance of the chamber
1495 //Double_t tgl = tracklet->GetZref(1); // dz/dl at the entrance of the chamber
1496 //Double_t dzdx = tgl; //*TMath::Sqrt(1+tnp*tnp); // dz/dx from dz/dl
1497 // at the end with correction due to linear fit
1498 //Double_t tnp = tracklet->GetYfit(1); // dy/dx at the end of the chamber after fit correction
1499 //Double_t tgl = tracklet->GetZfit(1); // dz/dl at the end of the chamber after fit correction
1501 ///////////////////////////////
1502 // Calculate tnp group shift
1503 ///////////////////////////////
1504 Bool_t echec = kFALSE;
1505 Double_t shift = 0.0;
1506 //Calculate the shift in x coresponding to this tnp
1507 if(fNgroupprf != 0.0){
1508 shift = -3.0*(fNgroupprf-1)-1.5;
1509 Double_t limithigh = -0.2*(fNgroupprf-1);
1510 if((tnp < (-0.2*fNgroupprf)) || (tnp > (0.2*fNgroupprf))) echec = kTRUE;
1512 while(tnp > limithigh){
1518 // do nothing if out of tnp range
1519 //printf("echec %d\n",(Int_t)echec);
1520 if(echec) return kFALSE;
1522 ///////////////////////
1524 //////////////////////
1526 Int_t nb3pc = 0; // number of three pads clusters used for fit
1527 // to see the difference between the fit and the 3 pad clusters position
1528 Double_t padPositions[AliTRDseedV1::kNtb];
1529 memset(padPositions, 0, AliTRDseedV1::kNtb*sizeof(Double_t));
1530 fLinearFitterTracklet->ClearPoints();
1532 //printf("loop clusters \n");
1533 ////////////////////////////
1534 // loop over the clusters
1535 ////////////////////////////
1536 AliTRDcluster *cl = 0x0;
1537 for(int ic=0; ic<AliTRDseedV1::kNtb; ic++){
1538 // reject shared clusters on pad row
1539 if((ic+AliTRDseedV1::kNtb) < AliTRDseedV1::kNclusters) {
1540 if((cl = tracklet->GetClusters(ic+AliTRDseedV1::kNtb))) continue;
1542 if(!(cl = tracklet->GetClusters(ic))) continue;
1543 Double_t time = cl->GetPadTime();
1544 if((time<=7) || (time>=21)) continue;
1545 Short_t *signals = cl->GetSignals();
1546 Float_t xcenter = 0.0;
1547 Bool_t echec1 = kTRUE;
1549 /////////////////////////////////////////////////////////////
1550 // Center 3 balanced: position with the center of the pad
1551 /////////////////////////////////////////////////////////////
1552 if ((((Float_t) signals[3]) > 0.0) &&
1553 (((Float_t) signals[2]) > 0.0) &&
1554 (((Float_t) signals[4]) > 0.0)) {
1556 // Security if the denomiateur is 0
1557 if ((((Float_t) (((Float_t) signals[3]) * ((Float_t) signals[3]))) /
1558 ((Float_t) (((Float_t) signals[2]) * ((Float_t) signals[4])))) != 1.0) {
1559 xcenter = 0.5 * (TMath::Log((Float_t) (((Float_t) signals[4]) / ((Float_t) signals[2]))))
1560 / (TMath::Log(((Float_t) (((Float_t) signals[3]) * ((Float_t) signals[3])))
1561 / ((Float_t) (((Float_t) signals[2]) * ((Float_t) signals[4])))));
1567 if(TMath::Abs(xcenter) > 0.5) echec1 = kTRUE;
1568 if(echec1) continue;
1570 ////////////////////////////////////////////////////////
1571 //if no echec1: calculate with the position of the pad
1572 // Position of the cluster
1573 // fill the linear fitter
1574 ///////////////////////////////////////////////////////
1575 Double_t padPosition = xcenter + cl->GetPadCol();
1576 padPositions[ic] = padPosition;
1578 fLinearFitterTracklet->AddPoint(&time, padPosition,1);
1583 //printf("Fin loop clusters \n");
1584 //////////////////////////////
1585 // fit with a straight line
1586 /////////////////////////////
1588 fLinearFitterTracklet->ClearPoints();
1591 fLinearFitterTracklet->Eval();
1593 fLinearFitterTracklet->GetParameters(line);
1594 Float_t pointError = -1.0;
1595 if( fLinearFitterTracklet->GetChisquare()>=0.0) {
1596 pointError = TMath::Sqrt( fLinearFitterTracklet->GetChisquare()/(nb3pc-2));
1598 fLinearFitterTracklet->ClearPoints();
1600 //printf("PRF second loop \n");
1601 ////////////////////////////////////////////////
1602 // Fill the PRF: Second loop over clusters
1603 //////////////////////////////////////////////
1604 for(int ic=0; ic<AliTRDseedV1::kNtb; ic++){
1605 // reject shared clusters on pad row
1606 cl = tracklet->GetClusters(ic+AliTRDseedV1::kNtb);
1607 if(((ic+AliTRDseedV1::kNtb) < AliTRDseedV1::kNclusters) && (cl)) continue;
1609 cl = tracklet->GetClusters(ic);
1612 Short_t *signals = cl->GetSignals(); // signal
1613 Double_t time = cl->GetPadTime(); // time bin
1614 Float_t padPosTracklet = line[0]+line[1]*time; // reconstruct position from fit
1615 Float_t padPos = cl->GetPadCol(); // middle pad
1616 Double_t dpad = padPosTracklet - padPos; // reconstruct position relative to middle pad from fit
1617 Float_t ycenter = 0.0; // relative center charge
1618 Float_t ymin = 0.0; // relative left charge
1619 Float_t ymax = 0.0; // relative right charge
1621 ////////////////////////////////////////////////////////////////
1622 // Calculate ycenter, ymin and ymax even for two pad clusters
1623 ////////////////////////////////////////////////////////////////
1624 if(((((Float_t) signals[3]) > 0.0) && (((Float_t) signals[2]) > 0.0)) ||
1625 ((((Float_t) signals[3]) > 0.0) && (((Float_t) signals[4]) > 0.0))){
1626 Float_t sum = ((Float_t) signals[2]) + ((Float_t) signals[3]) + ((Float_t) signals[4]);
1627 if(sum > 0.0) ycenter = ((Float_t) signals[3])/ sum;
1628 if(sum > 0.0) ymin = ((Float_t) signals[2])/ sum;
1629 if(sum > 0.0) ymax = ((Float_t) signals[4])/ sum;
1632 /////////////////////////
1633 // Calibration group
1634 ////////////////////////
1635 Int_t rowcl = cl->GetPadRow(); // row of cluster
1636 Int_t colcl = cl->GetPadCol(); // col of cluster
1637 Int_t grouplocal = CalculateCalibrationGroup(2,rowcl,colcl); // calcul the corresponding group
1638 Int_t caligroup = fCalibraMode->GetXbins(2)+ grouplocal; // calcul the corresponding group
1639 Float_t xcl = cl->GetY(); // y cluster
1640 Float_t qcl = cl->GetQ(); // charge cluster
1641 Int_t layer = GetLayer(fDetectorPreviousTrack); // layer
1642 Int_t stack = GetStack(fDetectorPreviousTrack); // stack
1643 Double_t xdiff = dpad; // reconstructed position constant
1644 Double_t x = dpad; // reconstructed position moved
1645 Float_t ep = pointError; // error of fit
1646 Float_t signal1 = (Float_t)signals[1]; // signal at the border
1647 Float_t signal3 = (Float_t)signals[3]; // signal
1648 Float_t signal2 = (Float_t)signals[2]; // signal
1649 Float_t signal4 = (Float_t)signals[4]; // signal
1650 Float_t signal5 = (Float_t)signals[5]; // signal at the border
1654 /////////////////////
1656 ////////////////////
1658 if(fDebugLevel > 0){
1659 if ( !fDebugStreamer ) {
1661 TDirectory *backup = gDirectory;
1662 fDebugStreamer = new TTreeSRedirector("TRDdebugCalibraFill.root");
1663 if ( backup ) backup->cd(); //we don't want to be cd'd to the debug streamer
1668 Float_t y = ycenter;
1669 (* fDebugStreamer) << "HandlePRFtrackletV1"<<
1670 "caligroup="<<caligroup<<
1671 "detector="<<fDetectorPreviousTrack<<
1674 "npoints="<<nbclusters<<
1683 "padPosition="<<padPositions[ic]<<
1684 "padPosTracklet="<<padPosTracklet<<
1689 "signal1="<<signal1<<
1690 "signal2="<<signal2<<
1691 "signal3="<<signal3<<
1692 "signal4="<<signal4<<
1693 "signal5="<<signal5<<
1699 (* fDebugStreamer) << "HandlePRFtrackletV1"<<
1700 "caligroup="<<caligroup<<
1701 "detector="<<fDetectorPreviousTrack<<
1704 "npoints="<<nbclusters<<
1713 "padPosition="<<padPositions[ic]<<
1714 "padPosTracklet="<<padPosTracklet<<
1719 "signal1="<<signal1<<
1720 "signal2="<<signal2<<
1721 "signal3="<<signal3<<
1722 "signal4="<<signal4<<
1723 "signal5="<<signal5<<
1729 (* fDebugStreamer) << "HandlePRFtrackletV1"<<
1730 "caligroup="<<caligroup<<
1731 "detector="<<fDetectorPreviousTrack<<
1734 "npoints="<<nbclusters<<
1743 "padPosition="<<padPositions[ic]<<
1744 "padPosTracklet="<<padPosTracklet<<
1749 "signal1="<<signal1<<
1750 "signal2="<<signal2<<
1751 "signal3="<<signal3<<
1752 "signal4="<<signal4<<
1753 "signal5="<<signal5<<
1759 /////////////////////
1761 /////////////////////
1762 if(nbclusters < fNumberClusters) continue;
1763 if(nbclusters > fNumberClustersf) continue;
1764 if(nb3pc <= 5) continue;
1765 if((time >= 21) || (time < 7)) continue;
1766 if(TMath::Abs(qcl) < 80) continue;
1767 if( TMath::Abs(snp) > 1.) continue;
1770 ////////////////////////
1772 ///////////////////////
1774 if(TMath::Abs(dpad) < 1.5) {
1775 fPRF2d->Fill(shift+dpad,(caligroup+0.5),ycenter);
1776 fPRF2d->Fill(shift-dpad,(caligroup+0.5),ycenter);
1777 //printf("place %f, ycenter %f\n",(shift+dpad),ycenter);
1779 if((ymin > 0.0) && (TMath::Abs(dpad+1.0) < 1.5)) {
1780 fPRF2d->Fill(shift-(dpad+1.0),(caligroup+0.5),ymin);
1781 fPRF2d->Fill(shift+(dpad+1.0),(caligroup+0.5),ymin);
1783 if((ymax > 0.0) && (TMath::Abs(dpad-1.0) < 1.5)) {
1784 fPRF2d->Fill(shift+1.0-dpad,(caligroup+0.5),ymax);
1785 fPRF2d->Fill(shift-1.0+dpad,(caligroup+0.5),ymax);
1790 if(TMath::Abs(dpad) < 1.5) {
1791 fCalibraVector->UpdateVectorPRF(fDetectorPreviousTrack,grouplocal,shift+dpad,ycenter);
1792 fCalibraVector->UpdateVectorPRF(fDetectorPreviousTrack,grouplocal,shift-dpad,ycenter);
1794 if((ymin > 0.0) && (TMath::Abs(dpad+1.0) < 1.5)) {
1795 fCalibraVector->UpdateVectorPRF(fDetectorPreviousTrack,grouplocal,shift-(dpad+1.0),ymin);
1796 fCalibraVector->UpdateVectorPRF(fDetectorPreviousTrack,grouplocal,shift+(dpad+1.0),ymin);
1798 if((ymax > 0.0) && (TMath::Abs(dpad-1.0) < 1.5)) {
1799 fCalibraVector->UpdateVectorPRF(fDetectorPreviousTrack,grouplocal,shift+1.0-dpad,ymax);
1800 fCalibraVector->UpdateVectorPRF(fDetectorPreviousTrack,grouplocal,shift-1.0+dpad,ymax);
1803 } // second loop over clusters
1808 ///////////////////////////////////////////////////////////////////////////////////////
1809 // Pad row col stuff: see if masked or not
1810 ///////////////////////////////////////////////////////////////////////////////////////
1811 //_____________________________________________________________________________
1812 void AliTRDCalibraFillHisto::CheckGoodTrackletV1(const AliTRDcluster *cl)
1815 // See if we are not near a masked pad
1818 if(cl->IsMasked()) fGoodTracklet = kFALSE;
1822 //_____________________________________________________________________________
1823 void AliTRDCalibraFillHisto::CheckGoodTrackletV0(const Int_t detector,const Int_t row,const Int_t col)
1826 // See if we are not near a masked pad
1829 if (!IsPadOn(detector, col, row)) {
1830 fGoodTracklet = kFALSE;
1834 if (!IsPadOn(detector, col-1, row)) {
1835 fGoodTracklet = kFALSE;
1840 if (!IsPadOn(detector, col+1, row)) {
1841 fGoodTracklet = kFALSE;
1846 //_____________________________________________________________________________
1847 Bool_t AliTRDCalibraFillHisto::IsPadOn(Int_t detector, Int_t row, Int_t col) const
1850 // Look in the choosen database if the pad is On.
1851 // If no the track will be "not good"
1854 // Get the parameter object
1855 AliTRDcalibDB *cal = AliTRDcalibDB::Instance();
1857 AliInfo("Could not get calibDB");
1861 if (!cal->IsChamberInstalled(detector) ||
1862 cal->IsChamberMasked(detector) ||
1863 cal->IsPadMasked(detector,col,row)) {
1871 ///////////////////////////////////////////////////////////////////////////////////////
1872 // Calibration groups: calculate the number of groups, localise...
1873 ////////////////////////////////////////////////////////////////////////////////////////
1874 //_____________________________________________________________________________
1875 Int_t AliTRDCalibraFillHisto::CalculateCalibrationGroup(Int_t i, Int_t row, Int_t col) const
1878 // Calculate the calibration group number for i
1881 // Row of the cluster and position in the pad groups
1883 if (fCalibraMode->GetNnZ(i) != 0) {
1884 posr = (Int_t) row / fCalibraMode->GetNnZ(i);
1888 // Col of the cluster and position in the pad groups
1890 if (fCalibraMode->GetNnRphi(i) != 0) {
1891 posc = (Int_t) col / fCalibraMode->GetNnRphi(i);
1894 return posc*fCalibraMode->GetNfragZ(i)+posr;
1897 //____________________________________________________________________________________
1898 Int_t AliTRDCalibraFillHisto::CalculateTotalNumberOfBins(Int_t i)
1901 // Calculate the total number of calibration groups
1907 if((fCalibraMode->GetNz(i)==100) && (fCalibraMode->GetNrphi(i)==100)){
1909 AliInfo(Form("Total number of Xbins: %d for i %d",ntotal,i));
1914 if((fCalibraMode->GetNz(i)==10) && (fCalibraMode->GetNrphi(i)==10)){
1916 AliInfo(Form("Total number of Xbins: %d for i %d",ntotal,i));
1921 fCalibraMode->ModePadCalibration(2,i);
1922 fCalibraMode->ModePadFragmentation(0,2,0,i);
1923 fCalibraMode->SetDetChamb2(i);
1924 ntotal += 6 * 18 * fCalibraMode->GetDetChamb2(i);
1925 fCalibraMode->ModePadCalibration(0,i);
1926 fCalibraMode->ModePadFragmentation(0,0,0,i);
1927 fCalibraMode->SetDetChamb0(i);
1928 ntotal += 6 * 4 * 18 * fCalibraMode->GetDetChamb0(i);
1929 AliInfo(Form("Total number of Xbins: %d for i %d",ntotal,i));
1933 //_____________________________________________________________________________
1934 void AliTRDCalibraFillHisto::SetNz(Int_t i, Short_t Nz)
1937 // Set the mode of calibration group in the z direction for the parameter i
1942 fCalibraMode->SetNz(i, Nz);
1945 AliInfo("You have to choose between 0 and 4");
1949 //_____________________________________________________________________________
1950 void AliTRDCalibraFillHisto::SetNrphi(Int_t i, Short_t Nrphi)
1953 // Set the mode of calibration group in the rphi direction for the parameter i
1958 fCalibraMode->SetNrphi(i ,Nrphi);
1961 AliInfo("You have to choose between 0 and 6");
1966 //_____________________________________________________________________________
1967 void AliTRDCalibraFillHisto::SetAllTogether(Int_t i)
1970 // Set the mode of calibration group all together
1972 if(fVector2d == kTRUE) {
1973 AliInfo("Can not work with the vector method");
1976 fCalibraMode->SetAllTogether(i);
1980 //_____________________________________________________________________________
1981 void AliTRDCalibraFillHisto::SetPerSuperModule(Int_t i)
1984 // Set the mode of calibration group per supermodule
1986 if(fVector2d == kTRUE) {
1987 AliInfo("Can not work with the vector method");
1990 fCalibraMode->SetPerSuperModule(i);
1994 //____________Set the pad calibration variables for the detector_______________
1995 Bool_t AliTRDCalibraFillHisto::LocalisationDetectorXbins(Int_t detector)
1998 // For the detector calcul the first Xbins and set the number of row
1999 // and col pads per calibration groups, the number of calibration
2000 // groups in the detector.
2003 // first Xbins of the detector
2005 fCalibraMode->CalculXBins(detector,0);
2008 fCalibraMode->CalculXBins(detector,1);
2011 fCalibraMode->CalculXBins(detector,2);
2014 // fragmentation of idect
2015 for (Int_t i = 0; i < 3; i++) {
2016 fCalibraMode->ModePadCalibration((Int_t) GetStack(detector),i);
2017 fCalibraMode->ModePadFragmentation((Int_t) GetLayer(detector)
2018 , (Int_t) GetStack(detector)
2019 , (Int_t) GetSector(detector),i);
2025 //_____________________________________________________________________________
2026 void AliTRDCalibraFillHisto::SetNumberGroupsPRF(Short_t numberGroupsPRF)
2029 // Should be between 0 and 6
2032 if ((numberGroupsPRF < 0) || (numberGroupsPRF > 6)) {
2033 AliInfo("The number of groups must be between 0 and 6!");
2036 fNgroupprf = numberGroupsPRF;
2040 ///////////////////////////////////////////////////////////////////////////////////////////
2041 // Per tracklet: store or reset the info, fill the histos with the info
2042 //////////////////////////////////////////////////////////////////////////////////////////
2043 //_____________________________________________________________________________
2044 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)
2047 // Store the infos in fAmpTotal, fPHPlace and fPHValue
2048 // Correct from the gain correction before
2049 // cls is shared cluster if any
2052 //printf("StoreInfoCHPHtrack\n");
2054 // time bin of the cluster not corrected
2055 Int_t time = cl->GetPadTime();
2056 Float_t charge = TMath::Abs(cl->GetQ());
2058 charge += TMath::Abs(cls->GetQ());
2059 //printf("AliTRDCalibraFillHisto::Add the cluster charge");
2062 //printf("Store::time %d, amplitude %f\n",time,dqdl);
2064 //Correct for the gain coefficient used in the database for reconstruction
2065 Float_t correctthegain = 1.0;
2066 if(fIsHLT) correctthegain = fCalDetGain->GetValue(fDetectorPreviousTrack);
2067 else correctthegain = fCalDetGain->GetValue(fDetectorPreviousTrack)*fCalROCGain->GetValue(col,row);
2068 Float_t correction = 1.0;
2069 Float_t normalisation = 6.67;
2070 // we divide with gain in AliTRDclusterizer::Transform...
2071 if( correctthegain > 0 ) normalisation /= correctthegain;
2074 // take dd/dl corrected from the angle of the track
2075 correction = dqdl / (normalisation);
2078 // Fill the fAmpTotal with the charge
2080 if((!fLimitChargeIntegration) || (cl->IsInChamber())) {
2081 //printf("Store::group %d, amplitude %f\n",group[0],correction);
2082 fAmpTotal[(Int_t) group[0]] += correction;
2086 // Fill the fPHPlace and value
2088 fPHPlace[time] = group[1];
2089 fPHValue[time] = charge;
2093 //____________Offine tracking in the AliTRDtracker_____________________________
2094 void AliTRDCalibraFillHisto::ResetfVariablestracklet()
2097 // Reset values per tracklet
2100 //Reset good tracklet
2101 fGoodTracklet = kTRUE;
2103 // Reset the fPHValue
2105 //Reset the fPHValue and fPHPlace
2106 for (Int_t k = 0; k < fTimeMax; k++) {
2112 // Reset the fAmpTotal where we put value
2114 for (Int_t k = 0; k < fCalibraMode->GetNfragZ(0)*fCalibraMode->GetNfragRphi(0); k++) {
2119 //____________Offine tracking in the AliTRDtracker_____________________________
2120 void AliTRDCalibraFillHisto::FillTheInfoOfTheTrackCH(Int_t nbclusters)
2123 // For the offline tracking or mcm tracklets
2124 // This function will be called in the functions UpdateHistogram...
2125 // to fill the info of a track for the relativ gain calibration
2128 Int_t nb = 0; // Nombre de zones traversees
2129 Int_t fd = -1; // Premiere zone non nulle
2130 Float_t totalcharge = 0.0; // Total charge for the supermodule histo
2132 //printf("CH2d nbclusters %d, fNumberClusters %d, fNumberClustersf %d\n",nbclusters,fNumberClusters,fNumberClustersf);
2134 if(nbclusters < fNumberClusters) return;
2135 if(nbclusters > fNumberClustersf) return;
2138 // Normalize with the number of clusters
2139 Double_t normalizeCst = fRelativeScale;
2140 if(fNormalizeNbOfCluster) normalizeCst = normalizeCst*nbclusters;
2142 //printf("Number of groups in one detector %d\n",fCalibraMode->GetNfragZ(0)*fCalibraMode->GetNfragRphi(0));
2144 // See if the track goes through different zones
2145 for (Int_t k = 0; k < fCalibraMode->GetNfragZ(0)*fCalibraMode->GetNfragRphi(0); k++) {
2146 //printf("fAmpTotal %f for %d\n",fAmpTotal[k],k);
2147 if (fAmpTotal[k] > 0.0) {
2148 totalcharge += fAmpTotal[k];
2156 //printf("CH2d: nb %d, fd %d, calibration group %d, amplitude %f, detector %d\n",nb,fd,fCalibraMode->GetXbins(0),fAmpTotal[fd]/normalizeCst,fDetectorPreviousTrack);
2162 fEntriesCH[fCalibraMode->GetXbins(0)+fd]++;
2164 FillCH2d(fCalibraMode->GetXbins(0)+fd,fAmpTotal[fd]/normalizeCst);
2165 //fCH2d->Fill(fAmpTotal[fd]/normalizeCst,fCalibraMode->GetXbins(0)+fd+0.5);
2168 fCalibraVector->UpdateVectorCH(fDetectorPreviousTrack,fd,fAmpTotal[fd]/normalizeCst);
2172 if ((fAmpTotal[fd] > 0.0) &&
2173 (fAmpTotal[fd+1] > 0.0)) {
2174 // One of the two very big
2175 if (fAmpTotal[fd] > fProcent*fAmpTotal[fd+1]) {
2177 FillCH2d(fCalibraMode->GetXbins(0)+fd,fAmpTotal[fd]/normalizeCst);
2178 //fCH2d->Fill(fAmpTotal[fd]/normalizeCst,fCalibraMode->GetXbins(0)+fd+0.5);
2181 fCalibraVector->UpdateVectorCH(fDetectorPreviousTrack,fd,fAmpTotal[fd]/normalizeCst);
2184 fEntriesCH[fCalibraMode->GetXbins(0)+fd]++;
2186 if (fAmpTotal[fd+1] > fProcent*fAmpTotal[fd]) {
2188 FillCH2d(fCalibraMode->GetXbins(0)+fd+1,fAmpTotal[fd+1]/normalizeCst);
2189 //fCH2d->Fill(fAmpTotal[fd+1]/normalizeCst,fCalibraMode->GetXbins(0)+fd+1.5);
2192 fCalibraVector->UpdateVectorCH(fDetectorPreviousTrack,fd+1,fAmpTotal[fd+1]/normalizeCst);
2195 fEntriesCH[fCalibraMode->GetXbins(0)+fd+1]++;
2198 if (fCalibraMode->GetNfragZ(0) > 1) {
2199 if (fAmpTotal[fd] > 0.0) {
2200 if ((fd+fCalibraMode->GetNfragZ(0)) < (fCalibraMode->GetNfragZ(0)*fCalibraMode->GetNfragRphi(0))) {
2201 if (fAmpTotal[fd+fCalibraMode->GetNfragZ(0)] > 0.0) {
2202 // One of the two very big
2203 if (fAmpTotal[fd] > fProcent*fAmpTotal[fd+fCalibraMode->GetNfragZ(0)]) {
2205 FillCH2d(fCalibraMode->GetXbins(0)+fd,fAmpTotal[fd]/normalizeCst);
2206 //fCH2d->Fill(fAmpTotal[fd]/normalizeCst,fCalibraMode->GetXbins(0)+fd+0.5);
2209 fCalibraVector->UpdateVectorCH(fDetectorPreviousTrack,fd,fAmpTotal[fd]/normalizeCst);
2212 fEntriesCH[fCalibraMode->GetXbins(0)+fd]++;
2214 if (fAmpTotal[fd+fCalibraMode->GetNfragZ(0)] > fProcent*fAmpTotal[fd]) {
2216 FillCH2d(fCalibraMode->GetXbins(0)+fd+fCalibraMode->GetNfragZ(0),fAmpTotal[fd+fCalibraMode->GetNfragZ(0)]/normalizeCst);
2217 //fCH2d->Fill(fAmpTotal[fd+fCalibraMode->GetNfragZ(0)]/normalizeCst,fCalibraMode->GetXbins(0)+fd+fCalibraMode->GetNfragZ(0)+0.5);
2220 fEntriesCH[fCalibraMode->GetXbins(0)+fd+fCalibraMode->GetNfragZ(0)]++;
2222 fCalibraVector->UpdateVectorCH(fDetectorPreviousTrack,fd+fCalibraMode->GetNfragZ(0),fAmpTotal[fd+fCalibraMode->GetNfragZ(0)]/normalizeCst);
2233 //____________Offine tracking in the AliTRDtracker_____________________________
2234 void AliTRDCalibraFillHisto::FillTheInfoOfTheTrackPH()
2237 // For the offline tracking or mcm tracklets
2238 // This function will be called in the functions UpdateHistogram...
2239 // to fill the info of a track for the drift velocity calibration
2242 Int_t nb = 1; // Nombre de zones traversees 1, 2 ou plus de 3
2243 Int_t fd1 = -1; // Premiere zone non nulle
2244 Int_t fd2 = -1; // Deuxieme zone non nulle
2245 Int_t k1 = -1; // Debut de la premiere zone
2246 Int_t k2 = -1; // Debut de la seconde zone
2247 Int_t nbclusters = 0; // number of clusters
2251 // See if the track goes through different zones
2252 for (Int_t k = 0; k < fTimeMax; k++) {
2253 if (fPHValue[k] > 0.0) {
2259 if (fPHPlace[k] != fd1) {
2265 if (fPHPlace[k] != fd2) {
2272 // See if noise before and after
2273 if(fMaxCluster > 0) {
2274 if(fPHValue[0] > fMaxCluster) return;
2275 if(fTimeMax > fNbMaxCluster) {
2276 for(Int_t k = (fTimeMax-fNbMaxCluster); k < fTimeMax; k++){
2277 if(fPHValue[k] > fMaxCluster) return;
2282 //printf("nbclusters %d, low limit %d, high limit %d\n",nbclusters,fNumberClusters,fNumberClustersf);
2284 if(nbclusters < fNumberClusters) return;
2285 if(nbclusters > fNumberClustersf) return;
2291 for (Int_t i = 0; i < fTimeMax; i++) {
2293 if(fFillWithZero) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd1)+0.5,(Float_t) fPHValue[i]);
2295 if(((Float_t) fPHValue[i] > 0.0)) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd1)+0.5,(Float_t) fPHValue[i]);
2297 //printf("Fill the time bin %d with %f\n",i,fPHValue[i]);
2300 if(fFillWithZero) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd1,i,fPHValue[i]);
2302 if(((Float_t) fPHValue[i] > 0.0)) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd1,i,fPHValue[i]);
2308 if ((fd1 == fd2+1) ||
2310 // One of the two fast all the think
2311 if (k2 > (k1+fDifference)) {
2312 //we choose to fill the fd1 with all the values
2314 for (Int_t i = 0; i < fTimeMax; i++) {
2316 if(fFillWithZero) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd1)+0.5,(Float_t) fPHValue[i]);
2318 if(((Float_t) fPHValue[i] > 0.0)) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd1)+0.5,(Float_t) fPHValue[i]);
2322 if(fFillWithZero) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd1,i,fPHValue[i]);
2324 if(((Float_t) fPHValue[i] > 0.0)) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd1,i,fPHValue[i]);
2329 if ((k2+fDifference) < fTimeMax) {
2330 //we choose to fill the fd2 with all the values
2332 for (Int_t i = 0; i < fTimeMax; i++) {
2334 if(fFillWithZero) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd2)+0.5,(Float_t) fPHValue[i]);
2336 if(((Float_t) fPHValue[i] > 0.0)) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd2)+0.5,(Float_t) fPHValue[i]);
2340 if(fFillWithZero) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd2,i,fPHValue[i]);
2342 if(((Float_t) fPHValue[i] > 0.0)) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd2,i,fPHValue[i]);
2348 // Two zones voisines sinon rien!
2349 if (fCalibraMode->GetNfragZ(1) > 1) {
2351 if ((fd1+fCalibraMode->GetNfragZ(1)) < (fCalibraMode->GetNfragZ(1)*fCalibraMode->GetNfragRphi(1))) {
2352 if (fd2 == (fd1+fCalibraMode->GetNfragZ(1))) {
2353 // One of the two fast all the think
2354 if (k2 > (k1+fDifference)) {
2355 //we choose to fill the fd1 with all the values
2357 for (Int_t i = 0; i < fTimeMax; i++) {
2359 if(fFillWithZero) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd1)+0.5,(Float_t) fPHValue[i]);
2361 if(((Float_t) fPHValue[i] > 0.0)) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd1)+0.5,(Float_t) fPHValue[i]);
2365 if(fFillWithZero) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd1,i,fPHValue[i]);
2367 if(((Float_t) fPHValue[i] > 0.0)) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd1,i,fPHValue[i]);
2372 if ((k2+fDifference) < fTimeMax) {
2373 //we choose to fill the fd2 with all the values
2375 for (Int_t i = 0; i < fTimeMax; i++) {
2377 if(fFillWithZero) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd2)+0.5,(Float_t) fPHValue[i]);
2379 if(((Float_t) fPHValue[i] > 0.0)) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd2)+0.5,(Float_t) fPHValue[i]);
2383 if(fFillWithZero) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd2,i,fPHValue[i]);
2385 if(((Float_t) fPHValue[i] > 0.0)) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd2,i,fPHValue[i]);
2392 // Two zones voisines sinon rien!
2394 if ((fd1 - fCalibraMode->GetNfragZ(1)) >= 0) {
2395 if (fd2 == (fd1 - fCalibraMode->GetNfragZ(1))) {
2396 // One of the two fast all the think
2397 if (k2 > (k1 + fDifference)) {
2398 //we choose to fill the fd1 with all the values
2400 for (Int_t i = 0; i < fTimeMax; i++) {
2402 if(fFillWithZero) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd1)+0.5,(Float_t) fPHValue[i]);
2404 if(((Float_t) fPHValue[i] > 0.0)) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd1)+0.5,(Float_t) fPHValue[i]);
2408 if(fFillWithZero) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd1,i,fPHValue[i]);
2410 if(((Float_t) fPHValue[i] > 0.0)) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd1,i,fPHValue[i]);
2415 if ((k2+fDifference) < fTimeMax) {
2416 //we choose to fill the fd2 with all the values
2418 for (Int_t i = 0; i < fTimeMax; i++) {
2420 if(fFillWithZero) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd2)+0.5,(Float_t) fPHValue[i]);
2422 if(((Float_t) fPHValue[i] > 0.0)) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd2)+0.5,(Float_t) fPHValue[i]);
2426 if(fFillWithZero) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd2,i,fPHValue[i]);
2428 if(((Float_t) fPHValue[i] > 0.0)) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd2,i,fPHValue[i]);
2440 //////////////////////////////////////////////////////////////////////////////////////////
2441 // DAQ process functions
2442 /////////////////////////////////////////////////////////////////////////////////////////
2443 //_____________________________________________________________________
2444 Int_t AliTRDCalibraFillHisto::ProcessEventDAQ(AliTRDrawStreamBase *rawStream, Bool_t nocheck)
2447 // Event Processing loop - AliTRDrawStreamBase
2448 // TestBeam 2007 version
2449 // 0 timebin problem
2452 // Same algorithm as TestBeam but different reader
2455 rawStream->SetSharedPadReadout(kFALSE);
2457 Int_t withInput = 1;
2459 Double_t phvalue[16][144][36];
2460 for(Int_t k = 0; k < 36; k++){
2461 for(Int_t j = 0; j < 16; j++){
2462 for(Int_t c = 0; c < 144; c++){
2463 phvalue[j][c][k] = 0.0;
2468 fDetectorPreviousTrack = -1;
2471 Int_t nbtimebin = 0;
2472 Int_t baseline = 10;
2473 //printf("------------Detector\n");
2479 while (rawStream->Next()) {
2481 Int_t idetector = rawStream->GetDet(); // current detector
2482 Int_t imcm = rawStream->GetMCM(); // current MCM
2483 Int_t irob = rawStream->GetROB(); // current ROB
2485 //printf("Detector %d\n",idetector);
2487 if((fDetectorPreviousTrack != idetector) && (fDetectorPreviousTrack != -1)){
2490 withInput = TMath::Max(FillDAQ(phvalue),withInput);
2494 for(Int_t k = 0; k < 36; k++){
2495 for(Int_t j = 0; j < 16; j++){
2496 for(Int_t c = 0; c < 144; c++){
2497 phvalue[j][c][k] = 0.0;
2503 fDetectorPreviousTrack = idetector;
2504 fMCMPrevious = imcm;
2505 fROBPrevious = irob;
2507 nbtimebin = rawStream->GetNumberOfTimeBins(); // number of time bins read from data
2508 if(nbtimebin == 0) return 0;
2509 if((fTimeMax != 0) && (nbtimebin != fTimeMax)) return 0;
2510 fTimeMax = nbtimebin;
2512 //baseline = rawStream->GetCommonAdditive(); // common additive baseline
2513 fNumberClustersf = fTimeMax;
2514 fNumberClusters = (Int_t)(fNumberClustersProcent*fTimeMax);
2517 Int_t *signal = rawStream->GetSignals(); // current ADC signal
2518 Int_t col = rawStream->GetCol();
2519 Int_t row = rawStream->GetRow();
2522 // printf("detector %d, signal[0] %d, signal[1] %d, signal[2] %d, baseline %d\n",idetector,signal[0],signal[1],signal[2], baseline);
2525 for(Int_t itime = 0; itime < nbtimebin; itime++){
2526 phvalue[row][col][itime] = signal[itime]-baseline;
2530 // fill the last one
2531 if(fDetectorPreviousTrack != -1){
2534 withInput = TMath::Max(FillDAQ(phvalue),withInput);
2537 for(Int_t k = 0; k < 36; k++){
2538 for(Int_t j = 0; j < 16; j++){
2539 for(Int_t c = 0; c < 144; c++){
2540 phvalue[j][c][k] = 0.0;
2549 while (rawStream->Next()) { //iddetecte
2551 Int_t idetector = rawStream->GetDet(); // current detector
2552 Int_t imcm = rawStream->GetMCM(); // current MCM
2553 Int_t irob = rawStream->GetROB(); // current ROB
2555 //printf("Detector %d\n",idetector);
2557 if((fDetectorPreviousTrack != idetector) && (fDetectorPreviousTrack != -1)){
2560 withInput = TMath::Max(FillDAQ(phvalue),withInput);
2563 for(Int_t k = 0; k < 36; k++){
2564 for(Int_t j = 0; j < 16; j++){
2565 for(Int_t c = 0; c < 144; c++){
2566 phvalue[j][c][k] = 0.0;
2572 fDetectorPreviousTrack = idetector;
2573 fMCMPrevious = imcm;
2574 fROBPrevious = irob;
2576 //baseline = rawStream->GetCommonAdditive(); // common baseline
2578 fTimeMax = rawStream->GetNumberOfTimeBins(); // number of time bins read from data
2579 fNumberClustersf = fTimeMax;
2580 fNumberClusters = (Int_t)(fNumberClustersProcent*fTimeMax);
2581 Int_t *signal = rawStream->GetSignals(); // current ADC signal
2582 Int_t col = rawStream->GetCol();
2583 Int_t row = rawStream->GetRow();
2586 //printf("detector %d, signal[0] %d, signal[1] %d, signal[2] %d, baseline %d\n",idetector,signal[0],signal[1],signal[2], baseline);
2588 for(Int_t itime = 0; itime < fTimeMax; itime++){
2589 phvalue[row][col][itime] = signal[itime]-baseline;
2590 /*if(phvalue[row][col][itime] >= 20) {
2591 printf("----------> phvalue[%d][%d][%d] %d baseline %d \n",
2601 // fill the last one
2602 if(fDetectorPreviousTrack != -1){
2605 withInput = TMath::Max(FillDAQ(phvalue),withInput);
2608 for(Int_t k = 0; k < 36; k++){
2609 for(Int_t j = 0; j < 16; j++){
2610 for(Int_t c = 0; c < 144; c++){
2611 phvalue[j][c][k] = 0.0;
2621 //_____________________________________________________________________
2622 Int_t AliTRDCalibraFillHisto::ProcessEventDAQ(AliRawReader *rawReader, Bool_t nocheck)
2625 // Event processing loop - AliRawReader
2626 // Testbeam 2007 version
2629 AliTRDrawStreamBase rawStream(rawReader);
2631 rawReader->Select("TRD");
2633 return ProcessEventDAQ(&rawStream, nocheck);
2636 //_________________________________________________________________________
2637 Int_t AliTRDCalibraFillHisto::ProcessEventDAQ(
2639 const eventHeaderStruct *event,
2642 const eventHeaderStruct* /*event*/,
2649 // process date event
2650 // Testbeam 2007 version
2653 AliRawReader *rawReader = new AliRawReaderDate((void*)event);
2654 Int_t result=ProcessEventDAQ(rawReader, nocheck);
2658 Fatal("AliTRDCalibraFillHisto", "this class was compiled without DATE");
2663 //_____________________________________________________________________
2664 Int_t AliTRDCalibraFillHisto::ProcessEventDAQ2(AliRawReader *rawReader)
2667 // Event Processing loop - AliTRDrawFastStream
2669 // 0 timebin problem
2672 // Same algorithm as TestBeam but different reader
2675 // AliTRDrawFastStream *rawStream = AliTRDrawFastStream::GetRawStream(rawReader);
2676 AliTRDrawFastStream *rawStream = new AliTRDrawFastStream(rawReader);
2677 rawStream->SetNoErrorWarning();
2678 rawStream->SetSharedPadReadout(kFALSE);
2680 AliTRDdigitsManager *digitsManager = new AliTRDdigitsManager(kTRUE);
2681 digitsManager->CreateArrays();
2683 Int_t withInput = 1;
2685 Double_t phvalue[16][144][36];
2686 for(Int_t k = 0; k < 36; k++){
2687 for(Int_t j = 0; j < 16; j++){
2688 for(Int_t c = 0; c < 144; c++){
2689 phvalue[j][c][k] = 0.0;
2694 fDetectorPreviousTrack = -1;
2698 Int_t nbtimebin = 0;
2699 Int_t baseline = 10;
2705 while ((det = rawStream->NextChamber(digitsManager, NULL, NULL)) >= 0) { //idetector
2707 if (digitsManager->GetIndexes(det)->HasEntry()) {//QA
2708 // printf("there is ADC data on this chamber!\n");
2710 AliTRDarrayADC *digits = (AliTRDarrayADC *) digitsManager->GetDigits(det); //mod
2711 if (digits->HasData()) { //array
2713 AliTRDSignalIndex *indexes = digitsManager->GetIndexes(det);
2714 if (indexes->IsAllocated() == kFALSE) {
2715 AliError("Indexes do not exist!");
2720 indexes->ResetCounters();
2722 while (indexes->NextRCIndex(iRow, iCol)) { //column,row
2723 //printf(" det %d \t row %d \t col %d \t digit\n",det,iRow,iCol);
2724 //while (rawStream->Next()) {
2726 Int_t idetector = det; // current detector
2727 //Int_t imcm = rawStream->GetMCM(); // current MCM
2728 //Int_t irob = rawStream->GetROB(); // current ROB
2731 if((fDetectorPreviousTrack != idetector) && (fDetectorPreviousTrack != -1)) {
2733 withInput = TMath::Max(FillDAQ(phvalue),withInput);
2736 for(Int_t k = 0; k < 36; k++){
2737 for(Int_t j = 0; j < 16; j++){
2738 for(Int_t c = 0; c < 144; c++){
2739 phvalue[j][c][k] = 0.0;
2745 fDetectorPreviousTrack = idetector;
2746 //fMCMPrevious = imcm;
2747 //fROBPrevious = irob;
2749 // nbtimebin = rawStream->GetNumberOfTimeBins(); // number of time bins read from data
2750 AliTRDdigitsParam *digitParam = (AliTRDdigitsParam *)digitsManager->GetDigitsParam();
2751 nbtimebin = digitParam->GetNTimeBins(det); // number of time bins read from data
2752 baseline = digitParam->GetADCbaseline(det); // baseline
2754 if(nbtimebin == 0) return 0;
2755 if((fTimeMax != 0) && (nbtimebin != fTimeMax)) return 0;
2756 fTimeMax = nbtimebin;
2758 fNumberClustersf = fTimeMax;
2759 fNumberClusters = (Int_t)(fNumberClustersProcent*fTimeMax);
2762 for(Int_t itime = 0; itime < nbtimebin; itime++) {
2763 // phvalue[row][col][itime] = signal[itime]-baseline;
2764 phvalue[iRow][iCol][itime] = (Short_t)(digits->GetData(iRow,iCol,itime) - baseline);
2765 /*if(phvalue[iRow][iCol][itime] >= 20) {
2766 printf("----------> phvalue[%d][%d][%d] %d baseline %d \n",
2770 (Short_t)(digits->GetData(iRow,iCol,itime)),
2777 // fill the last one
2778 if(fDetectorPreviousTrack != -1){
2781 withInput = TMath::Max(FillDAQ(phvalue),withInput);
2782 // printf("\n ---> withinput %d\n\n",withInput);
2784 for(Int_t k = 0; k < 36; k++){
2785 for(Int_t j = 0; j < 16; j++){
2786 for(Int_t c = 0; c < 144; c++){
2787 phvalue[j][c][k] = 0.0;
2795 digitsManager->ClearArrays(det);
2797 delete digitsManager;
2802 //_____________________________________________________________________
2803 Int_t AliTRDCalibraFillHisto::ProcessEventDAQ3(AliRawReader *rawReader)
2806 // Event Processing loop - AliTRDrawStream
2808 // 0 timebin problem
2811 // Same algorithm as TestBeam but different reader
2814 // AliTRDrawFastStream *rawStream = AliTRDrawFastStream::GetRawStream(rawReader);
2815 AliTRDrawStream *rawStream = new AliTRDrawStream(rawReader);
2816 rawStream->SetNoErrorWarning();
2817 rawStream->SetSharedPadReadout(kFALSE);
2819 AliTRDdigitsManager *digitsManager = new AliTRDdigitsManager(kTRUE);
2820 digitsManager->CreateArrays();
2822 Int_t withInput = 1;
2824 Double_t phvalue[16][144][36];
2825 for(Int_t k = 0; k < 36; k++){
2826 for(Int_t j = 0; j < 16; j++){
2827 for(Int_t c = 0; c < 144; c++){
2828 phvalue[j][c][k] = 0.0;
2833 fDetectorPreviousTrack = -1;
2837 Int_t nbtimebin = 0;
2838 Int_t baseline = 10;
2844 while ((det = rawStream->NextChamber(digitsManager, NULL, NULL)) >= 0) { //idetector
2846 if (digitsManager->GetIndexes(det)->HasEntry()) {//QA
2847 // printf("there is ADC data on this chamber!\n");
2849 AliTRDarrayADC *digits = (AliTRDarrayADC *) digitsManager->GetDigits(det); //mod
2850 if (digits->HasData()) { //array
2852 AliTRDSignalIndex *indexes = digitsManager->GetIndexes(det);
2853 if (indexes->IsAllocated() == kFALSE) {
2854 AliError("Indexes do not exist!");
2859 indexes->ResetCounters();
2861 while (indexes->NextRCIndex(iRow, iCol)) { //column,row
2862 //printf(" det %d \t row %d \t col %d \t digit\n",det,iRow,iCol);
2863 //while (rawStream->Next()) {
2865 Int_t idetector = det; // current detector
2866 //Int_t imcm = rawStream->GetMCM(); // current MCM
2867 //Int_t irob = rawStream->GetROB(); // current ROB
2870 if((fDetectorPreviousTrack != idetector) && (fDetectorPreviousTrack != -1)) {
2872 withInput = TMath::Max(FillDAQ(phvalue),withInput);
2875 for(Int_t k = 0; k < 36; k++){
2876 for(Int_t j = 0; j < 16; j++){
2877 for(Int_t c = 0; c < 144; c++){
2878 phvalue[j][c][k] = 0.0;
2884 fDetectorPreviousTrack = idetector;
2885 //fMCMPrevious = imcm;
2886 //fROBPrevious = irob;
2888 // nbtimebin = rawStream->GetNumberOfTimeBins(); // number of time bins read from data
2889 AliTRDdigitsParam *digitParam = (AliTRDdigitsParam *)digitsManager->GetDigitsParam();
2890 nbtimebin = digitParam->GetNTimeBins(det); // number of time bins read from data
2891 baseline = digitParam->GetADCbaseline(det); // baseline
2893 if(nbtimebin == 0) return 0;
2894 if((fTimeMax != 0) && (nbtimebin != fTimeMax)) return 0;
2895 fTimeMax = nbtimebin;
2897 fNumberClustersf = fTimeMax;
2898 fNumberClusters = (Int_t)(fNumberClustersProcent*fTimeMax);
2901 for(Int_t itime = 0; itime < nbtimebin; itime++) {
2902 // phvalue[row][col][itime] = signal[itime]-baseline;
2903 phvalue[iRow][iCol][itime] = (Short_t)(digits->GetData(iRow,iCol,itime) - baseline);
2904 /*if(phvalue[iRow][iCol][itime] >= 20) {
2905 printf("----------> phvalue[%d][%d][%d] %d baseline %d \n",
2909 (Short_t)(digits->GetData(iRow,iCol,itime)),
2916 // fill the last one
2917 if(fDetectorPreviousTrack != -1){
2920 withInput = TMath::Max(FillDAQ(phvalue),withInput);
2921 // printf("\n ---> withinput %d\n\n",withInput);
2923 for(Int_t k = 0; k < 36; k++){
2924 for(Int_t j = 0; j < 16; j++){
2925 for(Int_t c = 0; c < 144; c++){
2926 phvalue[j][c][k] = 0.0;
2934 digitsManager->ClearArrays(det);
2936 delete digitsManager;
2941 //_____________________________________________________________________
2942 //////////////////////////////////////////////////////////////////////////////
2943 // Routine inside the DAQ process
2944 /////////////////////////////////////////////////////////////////////////////
2945 //_______________________________________________________________________
2946 Int_t AliTRDCalibraFillHisto::FillDAQ(Double_t phvalue[16][144][36]){
2949 // Look for the maximum by collapsing over the time
2950 // Sum over four pad col and two pad row
2956 Int_t idect = fDetectorPreviousTrack;
2957 //printf("Enter Detector %d\n",fDetectorPreviousTrack);
2959 for(Int_t tb = 0; tb < 36; tb++){
2963 //fGoodTracklet = kTRUE;
2964 //fDetectorPreviousTrack = 0;
2967 ///////////////////////////
2969 /////////////////////////
2973 Double_t integralMax = -1;
2975 for (Int_t ir = 1; ir <= 15; ir++)
2977 for (Int_t ic = 2; ic <= 142; ic++)
2979 Double_t integral = 0;
2980 for (Int_t ishiftR = 0; ishiftR < fNumberRowDAQ; ishiftR++)
2982 for (Int_t ishiftC = -fNumberColDAQ; ishiftC < fNumberColDAQ; ishiftC++)
2984 if (ir + ishiftR >= 1 && ir + ishiftR <= 16 &&
2985 ic + ishiftC >= 1 && ic + ishiftC <= 144)
2988 for(Int_t tb = 0; tb< fTimeMax; tb++){
2989 integral += phvalue[ir + ishiftR-1][ic + ishiftC-1][tb];
2994 if (integralMax < integral)
2998 integralMax = integral;
3000 } // check max integral
3004 // printf("imaxRow %d, imaxCol %d, fTimeMax %d, integralMax %f\n",imaxRow,imaxCol,fTimeMax, integralMax);
3005 //if((imaxRow == 0) || (imaxRow >= 15) || (imaxCol <= 3) || (imaxCol >= 140)) {
3010 if(((imaxRow + fNumberRowDAQ) > 16) || (imaxRow == 0) || ((imaxCol - fNumberColDAQ) <= 1) || ((imaxCol + fNumberColDAQ) >= 144)) {
3014 //CheckGoodTrackletV0(fDetectorPreviousTrack,imaxRow,imaxCol);
3015 //if(!fGoodTracklet) used = 1;;
3017 // /////////////////////////////////////////////////////
3018 // sum ober 2 row and 4 pad cols for each time bins
3019 // ////////////////////////////////////////////////////
3023 for (Int_t ishiftR = 0; ishiftR < fNumberRowDAQ; ishiftR++)
3025 for (Int_t ishiftC = -fNumberColDAQ; ishiftC < fNumberColDAQ; ishiftC++)
3027 if (imaxRow + ishiftR >= 1 && imaxRow + ishiftR <= 16 &&
3028 imaxCol + ishiftC >= 1 && imaxCol + ishiftC <= 144)
3030 for(Int_t it = 0; it < fTimeMax; it++){
3031 sum[it] += phvalue[imaxRow + ishiftR-1][imaxCol + ishiftC-1][it];
3038 Double_t sumcharge = 0.0;
3039 for(Int_t it = 0; it < fTimeMax; it++){
3040 sumcharge += sum[it];
3041 if(sum[it] > fThresholdClustersDAQ) nbcl++;
3045 /////////////////////////////////////////////////////////
3047 ////////////////////////////////////////////////////////
3048 if(fDebugLevel > 0){
3049 if ( !fDebugStreamer ) {
3051 TDirectory *backup = gDirectory;
3052 fDebugStreamer = new TTreeSRedirector("TRDdebugCalibraFill.root");
3053 if ( backup ) backup->cd(); //we don't want to be cd'd to the debug streamer
3056 Double_t amph0 = sum[0];
3057 Double_t amphlast = sum[fTimeMax-1];
3058 Double_t rms = TMath::RMS(fTimeMax,sum);
3059 Int_t goodtracklet = (Int_t) fGoodTracklet;
3060 for(Int_t it = 0; it < fTimeMax; it++){
3061 Double_t clustera = sum[it];
3063 (* fDebugStreamer) << "FillDAQa"<<
3064 "ampTotal="<<sumcharge<<
3067 "detector="<<idect<<
3069 "amphlast="<<amphlast<<
3070 "goodtracklet="<<goodtracklet<<
3071 "clustera="<<clustera<<
3079 ////////////////////////////////////////////////////////
3081 ///////////////////////////////////////////////////////
3082 //printf("fNumberClusters %d, fNumberClustersf %d\n",fNumberClusters,fNumberClustersf);
3083 if(sum[0] > 100.0) used = 1;
3084 if(nbcl < fNumberClusters) used = 1;
3085 if(nbcl > fNumberClustersf) used = 1;
3087 //if(fDetectorPreviousTrack == 15){
3088 // printf("rms %f and first time bin %f\n",TMath::RMS(fTimeMax,sum),sum[0]);
3090 //if((TMath::RMS(fTimeMax,sum) <= 10.0) && (sum[0] > 200.0)) return 1;
3092 for(Int_t it = 0; it < fTimeMax; it++){
3093 if(fFillWithZero) UpdateDAQ(fDetectorPreviousTrack,0,0,it,sum[it],fTimeMax);
3095 if(sum[it] > 0.0) UpdateDAQ(fDetectorPreviousTrack,0,0,it,sum[it],fTimeMax);
3097 //if(fFillWithZero) UpdateDAQ(0,0,0,it,sum[it],fTimeMax);
3099 // if(sum[it] > 0.0) UpdateDAQ(0,0,0,it,sum[it],fTimeMax);
3104 //((TH2I *)GetCH2d()->Fill(sumcharge/30.0,fDetectorPreviousTrack));
3106 //printf("Pass Detector %d\n",fDetectorPreviousTrack);
3113 //____________Online trackling in AliTRDtrigger________________________________
3114 Bool_t AliTRDCalibraFillHisto::UpdateDAQ(Int_t det, Int_t /*row*/, Int_t /*col*/, Int_t timebin, Float_t signal, Int_t nbtimebins)
3118 // Fill a simple average pulse height
3122 ((TProfile2D *)GetPH2d(nbtimebins,fSf))->Fill((Float_t) timebin/fSf,det+0.5,(Float_t) signal);
3128 //____________Write_____________________________________________________
3129 //_____________________________________________________________________
3130 void AliTRDCalibraFillHisto::Write2d(const Char_t *filename, Bool_t append)
3133 // Write infos to file
3137 if ( fDebugStreamer ) {
3138 delete fDebugStreamer;
3139 fDebugStreamer = 0x0;
3142 AliInfo(Form("Numbertrack: %d Numberusedch[0]: %d, Numberusedch[1]: %d Numberusedph[0]: %d, Numberusedph[1]: %d"
3147 ,fNumberUsedPh[1]));
3149 TDirectory *backup = gDirectory;
3155 option = "recreate";
3157 TFile f(filename,option.Data());
3159 TStopwatch stopwatch;
3162 f.WriteTObject(fCalibraVector);
3167 f.WriteTObject(fCH2d);
3172 f.WriteTObject(fPH2d);
3177 f.WriteTObject(fPRF2d);
3180 if(fLinearFitterOn){
3181 if(fLinearFitterDebugOn) AnalyseLinearFitter();
3182 f.WriteTObject(fLinearVdriftFit);
3187 if ( backup ) backup->cd();
3189 AliInfo(Form("Execution time Write2d: R:%.2fs C:%.2fs"
3190 ,stopwatch.RealTime(),stopwatch.CpuTime()));
3192 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
3194 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
3195 //___________________________________________probe the histos__________________________________________________
3196 Double_t *AliTRDCalibraFillHisto::StatH(TH2 *h, Int_t i)
3199 // Check the number of stats in h, 0 is TH2I 1 is TProfile2D
3200 // debug mode with 2 for TH2I and 3 for TProfile2D
3201 // It gives a pointer to a Double_t[7] with the info following...
3202 // [0] : number of calibration groups with entries
3203 // [1] : minimal number of entries found
3204 // [2] : calibration group number of the min
3205 // [3] : maximal number of entries found
3206 // [4] : calibration group number of the max
3207 // [5] : mean number of entries found
3208 // [6] : mean relative error
3211 Double_t *info = new Double_t[7];
3213 // Number of Xbins (detectors or groups of pads)
3214 Int_t nbins = h->GetNbinsY(); //number of calibration groups
3215 Int_t nxbins = h->GetNbinsX(); //number of bins per histo
3218 Double_t nbwe = 0; //number of calibration groups with entries
3219 Double_t minentries = 0; //minimal number of entries found
3220 Double_t maxentries = 0; //maximal number of entries found
3221 Double_t placemin = 0; //calibration group number of the min
3222 Double_t placemax = -1; //calibration group number of the max
3223 Double_t meanstats = 0.0; //mean number of entries over the calibration group with at least ome entry
3224 Double_t meanrelativerror = 0.0; //mean relativ error in the TProfile2D
3226 Double_t counter = 0;
3229 TH1F *nbEntries = 0x0;//distribution of the number of entries
3230 TH1F *nbEntriesPerGroup = 0x0;//Number of entries per group
3231 TProfile *nbEntriesPerSp = 0x0;//Number of entries for one supermodule
3233 // Beginning of the loop over the calibration groups
3234 for (Int_t idect = 0; idect < nbins; idect++) {
3236 TH1I *projch = (TH1I *) h->ProjectionX("projch",idect+1,idect+1,(Option_t *)"e");
3237 projch->SetDirectory(0);
3239 // Number of entries for this calibration group
3240 Double_t nentries = 0.0;
3242 for (Int_t k = 0; k < nxbins; k++) {
3243 nentries += h->GetBinContent(h->GetBin(k+1,idect+1));
3247 for (Int_t k = 0; k < nxbins; k++) {
3248 nentries += ((TProfile2D *)h)->GetBinEntries(h->GetBin(k+1,idect+1));
3249 if(h->GetBinContent(h->GetBin(k+1,idect+1)) != 0) {
3250 meanrelativerror += (h->GetBinError(h->GetBin(k+1,idect+1))/(TMath::Abs(h->GetBinContent(h->GetBin(k+1,idect+1)))));
3258 if((!((Bool_t)nbEntries)) && (nentries > 0)){
3259 nbEntries = new TH1F("Number of entries","Number of entries"
3260 ,100,(Int_t)nentries/2,nentries*2);
3261 nbEntries->SetDirectory(0);
3262 nbEntriesPerGroup = new TH1F("Number of entries per group","Number of entries per group"
3264 nbEntriesPerGroup->SetDirectory(0);
3265 nbEntriesPerSp = new TProfile("Number of entries per supermodule","Number of entries per supermodule"
3266 ,(Int_t)(nbins/18),0,(Int_t)(nbins/18));
3267 nbEntriesPerSp->SetDirectory(0);
3270 if(nentries > 0) nbEntries->Fill(nentries);
3271 nbEntriesPerGroup->Fill(idect+0.5,nentries);
3272 nbEntriesPerSp->Fill((idect%((Int_t)(nbins/18)))+0.5,nentries);
3277 if(nentries > maxentries){
3278 maxentries = nentries;
3282 minentries = nentries;
3284 if(nentries < minentries){
3285 minentries = nentries;
3291 meanstats += nentries;
3293 }//calibration groups loop
3295 if(nbwe > 0) meanstats /= nbwe;
3296 if(counter > 0) meanrelativerror /= counter;
3298 AliInfo(Form("There are %f calibration groups with entries",nbwe));
3299 AliInfo(Form("The minimum number of entries is %f for the group %f",minentries,placemin));
3300 AliInfo(Form("The maximum number of entries is %f for the group %f",maxentries,placemax));
3301 AliInfo(Form("The mean number of entries is %f",meanstats));
3302 if((i%2) == 1) AliInfo(Form("The mean relative error is %f",meanrelativerror));
3305 info[1] = minentries;
3307 info[3] = maxentries;
3309 info[5] = meanstats;
3310 info[6] = meanrelativerror;
3313 gStyle->SetPalette(1);
3314 gStyle->SetOptStat(1111);
3315 gStyle->SetPadBorderMode(0);
3316 gStyle->SetCanvasColor(10);
3317 gStyle->SetPadLeftMargin(0.13);
3318 gStyle->SetPadRightMargin(0.01);
3319 TCanvas *stat = new TCanvas("stat","",50,50,600,800);
3322 nbEntries->Draw("");
3324 nbEntriesPerSp->SetStats(0);
3325 nbEntriesPerSp->Draw("");
3326 TCanvas *stat1 = new TCanvas("stat1","",50,50,600,800);
3328 nbEntriesPerGroup->SetStats(0);
3329 nbEntriesPerGroup->Draw("");
3335 //____________________________________________________________________________
3336 Double_t *AliTRDCalibraFillHisto::GetMeanMedianRMSNumberCH()
3339 // Return a Int_t[4] with:
3340 // 0 Mean number of entries
3341 // 1 median of number of entries
3342 // 2 rms of number of entries
3343 // 3 number of group with entries
3346 Double_t *stat = new Double_t[4];
3349 Int_t nbofgroups = CalculateTotalNumberOfBins(0);
3350 Double_t *weight = new Double_t[nbofgroups];
3351 Int_t *nonul = new Int_t[nbofgroups];
3353 for(Int_t k = 0; k < nbofgroups; k++){
3354 if(fEntriesCH[k] > 0) {
3356 nonul[(Int_t)stat[3]] = fEntriesCH[k];
3359 else weight[k] = 0.0;
3361 stat[0] = TMath::Mean(nbofgroups,fEntriesCH,weight);
3362 stat[1] = TMath::Median(nbofgroups,fEntriesCH,weight);
3363 stat[2] = TMath::RMS((Int_t)stat[3],nonul);
3368 //____________________________________________________________________________
3369 Double_t *AliTRDCalibraFillHisto::GetMeanMedianRMSNumberLinearFitter() const
3372 // Return a Int_t[4] with:
3373 // 0 Mean number of entries
3374 // 1 median of number of entries
3375 // 2 rms of number of entries
3376 // 3 number of group with entries
3379 Double_t *stat = new Double_t[4];
3382 Int_t nbofgroups = 540;
3383 Double_t *weight = new Double_t[nbofgroups];
3384 Int_t *nonul = new Int_t[nbofgroups];
3386 for(Int_t k = 0; k < nbofgroups; k++){
3387 if(fEntriesLinearFitter[k] > 0) {
3389 nonul[(Int_t) stat[3]] = fEntriesLinearFitter[k];
3392 else weight[k] = 0.0;
3394 stat[0] = TMath::Mean(nbofgroups,fEntriesLinearFitter,weight);
3395 stat[1] = TMath::Median(nbofgroups,fEntriesLinearFitter,weight);
3396 stat[2] = TMath::RMS((Int_t)stat[3],nonul);
3401 //////////////////////////////////////////////////////////////////////////////////////
3403 //////////////////////////////////////////////////////////////////////////////////////
3404 //_____________________________________________________________________________
3405 void AliTRDCalibraFillHisto::CreatePRF2d(Int_t nn)
3408 // Create the 2D histos: here we have 2*fNgroupprf bins in tnp of 0.2 amplitude each
3409 // If fNgroupprf is zero then no binning in tnp
3413 name += fCalibraMode->GetNz(2);
3415 name += fCalibraMode->GetNrphi(2);
3419 if(fNgroupprf != 0){
3421 fPRF2d = new TProfile2D("PRF2d",(const Char_t *) name
3422 ,2*fNgroupprf*fNumberBinPRF,-3.0*fNgroupprf,3.0*fNgroupprf,nn,0,nn);
3423 fPRF2d->SetYTitle("Det/pad groups");
3424 fPRF2d->SetXTitle("Position x/W [pad width units]");
3425 fPRF2d->SetZTitle("Q_{i}/Q_{total}");
3426 fPRF2d->SetStats(0);
3429 fPRF2d = new TProfile2D("PRF2d",(const Char_t *) name
3430 ,fNumberBinPRF,-1.5,1.5,nn,0,nn);
3431 fPRF2d->SetYTitle("Det/pad groups");
3432 fPRF2d->SetXTitle("Position x/W [pad width units]");
3433 fPRF2d->SetZTitle("Q_{i}/Q_{total}");
3434 fPRF2d->SetStats(0);
3439 //_____________________________________________________________________________
3440 void AliTRDCalibraFillHisto::CreatePH2d(Int_t nn)
3443 // Create the 2D histos
3446 TString name("Ver");
3447 name += fVersionVdriftUsed;
3449 name += fSubVersionVdriftUsed;
3451 name += fCalibraMode->GetNz(1);
3453 name += fCalibraMode->GetNrphi(1);
3455 fPH2d = new TProfile2D("PH2d",(const Char_t *) name
3456 ,fTimeMax,-0.5/fSf,(Float_t) (fTimeMax-0.5)/fSf
3458 fPH2d->SetYTitle("Det/pad groups");
3459 fPH2d->SetXTitle("time [#mus]");
3460 fPH2d->SetZTitle("<PH> [a.u.]");
3464 //_____________________________________________________________________________
3465 void AliTRDCalibraFillHisto::CreateCH2d(Int_t nn)
3468 // Create the 2D histos
3471 TString name("Ver");
3472 name += fVersionGainUsed;
3474 name += fSubVersionGainUsed;
3476 name += fCalibraMode->GetNz(0);
3478 name += fCalibraMode->GetNrphi(0);
3480 fCH2d = new TH2I("CH2d",(const Char_t *) name
3481 ,fNumberBinCharge,0,300,nn,0,nn);
3482 fCH2d->SetYTitle("Det/pad groups");
3483 fCH2d->SetXTitle("charge deposit [a.u]");
3484 fCH2d->SetZTitle("counts");
3489 //////////////////////////////////////////////////////////////////////////////////
3490 // Set relative scale
3491 /////////////////////////////////////////////////////////////////////////////////
3492 //_____________________________________________________________________________
3493 void AliTRDCalibraFillHisto::SetRelativeScale(Float_t RelativeScale)
3496 // Set the factor that will divide the deposited charge
3497 // to fit in the histo range [0,300]
3500 if (RelativeScale > 0.0) {
3501 fRelativeScale = RelativeScale;
3504 AliInfo("RelativeScale must be strict positif!");
3508 //////////////////////////////////////////////////////////////////////////////////
3509 // Quick way to fill a histo
3510 //////////////////////////////////////////////////////////////////////////////////
3511 //_____________________________________________________________________
3512 void AliTRDCalibraFillHisto::FillCH2d(Int_t x, Float_t y)
3515 // FillCH2d: Marian style
3518 //skip simply the value out of range
3519 if((y>=300.0) || (y<0.0)) return;
3521 //Calcul the y place
3522 Int_t yplace = (Int_t) (fNumberBinCharge*y/300.0)+1;
3523 Int_t place = (fNumberBinCharge+2)*(x+1)+yplace;
3526 fCH2d->GetArray()[place]++;
3530 //////////////////////////////////////////////////////////////////////////////////
3531 // Geometrical functions
3532 ///////////////////////////////////////////////////////////////////////////////////
3533 //_____________________________________________________________________________
3534 Int_t AliTRDCalibraFillHisto::GetLayer(Int_t d) const
3537 // Reconstruct the layer number from the detector number
3540 return ((Int_t) (d % 6));
3544 //_____________________________________________________________________________
3545 Int_t AliTRDCalibraFillHisto::GetStack(Int_t d) const
3548 // Reconstruct the stack number from the detector number
3550 const Int_t kNlayer = 6;
3552 return ((Int_t) (d % 30) / kNlayer);
3556 //_____________________________________________________________________________
3557 Int_t AliTRDCalibraFillHisto::GetSector(Int_t d) const
3560 // Reconstruct the sector number from the detector number
3564 return ((Int_t) (d / fg));
3567 ///////////////////////////////////////////////////////////////////////////////////
3568 // Getter functions for DAQ of the CH2d and the PH2d
3569 //////////////////////////////////////////////////////////////////////////////////
3570 //_____________________________________________________________________
3571 TProfile2D* AliTRDCalibraFillHisto::GetPH2d(Int_t nbtimebin, Float_t samplefrequency)
3574 // return pointer to fPH2d TProfile2D
3575 // create a new TProfile2D if it doesn't exist allready
3581 fTimeMax = nbtimebin;
3582 fSf = samplefrequency;
3588 //_____________________________________________________________________
3589 TH2I* AliTRDCalibraFillHisto::GetCH2d()
3592 // return pointer to fCH2d TH2I
3593 // create a new TH2I if it doesn't exist allready
3602 ////////////////////////////////////////////////////////////////////////////////////////////
3603 // Drift velocity calibration
3604 ///////////////////////////////////////////////////////////////////////////////////////////
3605 //_____________________________________________________________________
3606 TLinearFitter* AliTRDCalibraFillHisto::GetLinearFitter(Int_t detector, Bool_t force)
3609 // return pointer to TLinearFitter Calibration
3610 // if force is true create a new TLinearFitter if it doesn't exist allready
3613 if ((!force) || (fLinearFitterArray.UncheckedAt(detector))){
3614 return (TLinearFitter*)fLinearFitterArray.UncheckedAt(detector);
3617 // if we are forced and TLinearFitter doesn't yet exist create it
3619 // new TLinearFitter
3620 TLinearFitter *linearfitter = new TLinearFitter(2,"pol1");
3621 fLinearFitterArray.AddAt(linearfitter,detector);
3622 return linearfitter;
3625 //____________________________________________________________________________
3626 void AliTRDCalibraFillHisto::AnalyseLinearFitter()
3629 // Analyse array of linear fitter because can not be written
3630 // Store two arrays: one with the param the other one with the error param + number of entries
3633 for(Int_t k = 0; k < 540; k++){
3634 TLinearFitter *linearfitter = GetLinearFitter(k);
3635 if((linearfitter!=0) && (fEntriesLinearFitter[k]>10)){
3636 TVectorD *par = new TVectorD(2);
3637 TVectorD pare = TVectorD(2);
3638 TVectorD *parE = new TVectorD(3);
3639 linearfitter->Eval();
3640 linearfitter->GetParameters(*par);
3641 linearfitter->GetErrors(pare);
3642 Float_t ppointError = TMath::Sqrt(TMath::Abs(linearfitter->GetChisquare())/fEntriesLinearFitter[k]);
3643 (*parE)[0] = pare[0]*ppointError;
3644 (*parE)[1] = pare[1]*ppointError;
3645 (*parE)[2] = (Double_t) fEntriesLinearFitter[k];
3646 ((TObjArray *)fLinearVdriftFit->GetPArray())->AddAt(par,k);
3647 ((TObjArray *)fLinearVdriftFit->GetEArray())->AddAt(parE,k);