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();
303 //____________________________________________________________________________________
304 AliTRDCalibraFillHisto::~AliTRDCalibraFillHisto()
307 // AliTRDCalibraFillHisto destructor
311 if ( fDebugStreamer ) delete fDebugStreamer;
313 if ( fCalDetGain ) delete fCalDetGain;
314 if ( fCalROCGain ) delete fCalROCGain;
316 if( fLinearFitterTracklet ) { delete fLinearFitterTracklet; }
320 delete [] fEntriesCH;
321 delete [] fEntriesLinearFitter;
324 for(Int_t idet=0; idet<AliTRDgeometry::kNdet; idet++){
325 TLinearFitter *f = (TLinearFitter*)fLinearFitterArray.At(idet);
328 if(fLinearVdriftFit) delete fLinearVdriftFit;
334 //_____________________________________________________________________________
335 void AliTRDCalibraFillHisto::Destroy()
346 //_____________________________________________________________________________
347 void AliTRDCalibraFillHisto::DestroyDebugStreamer()
350 // Delete DebugStreamer
353 if ( fDebugStreamer ) delete fDebugStreamer;
354 fDebugStreamer = 0x0;
357 //_____________________________________________________________________________
358 void AliTRDCalibraFillHisto::ClearHistos()
378 //////////////////////////////////////////////////////////////////////////////////
379 // calibration with AliTRDtrackV1: Init, Update
380 //////////////////////////////////////////////////////////////////////////////////
381 //____________Functions for initialising the AliTRDCalibraFillHisto in the code_________
382 Bool_t AliTRDCalibraFillHisto::Init2Dhistos(Int_t nboftimebin)
385 // Init the histograms and stuff to be filled
390 AliTRDcalibDB *cal = AliTRDcalibDB::Instance();
392 AliInfo("Could not get calibDB");
395 AliTRDCommonParam *parCom = AliTRDCommonParam::Instance();
397 AliInfo("Could not get CommonParam");
402 if(nboftimebin > 0) fTimeMax = nboftimebin;
403 else fTimeMax = cal->GetNumberOfTimeBinsDCS();
404 if(fTimeMax <= 0) fTimeMax = 30;
405 printf("////////////////////////////////////////////\n");
406 printf("Number of time bins in calibration component %d\n",fTimeMax);
407 printf("////////////////////////////////////////////\n");
408 fSf = parCom->GetSamplingFrequency();
409 if(!fNormalizeNbOfCluster) fRelativeScale = 20.0;
410 else fRelativeScale = 1.18;
411 fNumberClustersf = fTimeMax;
412 fNumberClusters = (Int_t)(fNumberClustersProcent*fTimeMax);
414 // Init linear fitter
415 if(!fLinearFitterTracklet) {
416 fLinearFitterTracklet = new TLinearFitter(2,"pol1");
417 fLinearFitterTracklet->StoreData(kTRUE);
420 // Calcul Xbins Chambd0, Chamb2
421 Int_t ntotal0 = CalculateTotalNumberOfBins(0);
422 Int_t ntotal1 = CalculateTotalNumberOfBins(1);
423 Int_t ntotal2 = CalculateTotalNumberOfBins(2);
425 // If vector method On initialised all the stuff
427 fCalibraVector = new AliTRDCalibraVector();
428 fCalibraVector->SetNumberBinCharge(fNumberBinCharge);
429 fCalibraVector->SetTimeMax(fTimeMax);
430 if(fNgroupprf != 0) {
431 fCalibraVector->SetNumberBinPRF(2*fNgroupprf*fNumberBinPRF);
432 fCalibraVector->SetPRFRange((Float_t)(3.0*fNgroupprf));
435 fCalibraVector->SetNumberBinPRF(fNumberBinPRF);
436 fCalibraVector->SetPRFRange(1.5);
438 for(Int_t k = 0; k < 3; k++){
439 fCalibraVector->SetDetCha0(k,fCalibraMode->GetDetChamb0(k));
440 fCalibraVector->SetDetCha2(k,fCalibraMode->GetDetChamb2(k));
442 fCalibraVector->SetNzNrphi(0,fCalibraMode->GetNz(0),fCalibraMode->GetNrphi(0));
443 fCalibraVector->SetNzNrphi(1,fCalibraMode->GetNz(1),fCalibraMode->GetNrphi(1));
444 fCalibraVector->SetNzNrphi(2,fCalibraMode->GetNz(2),fCalibraMode->GetNrphi(2));
445 fCalibraVector->SetNbGroupPRF(fNgroupprf);
448 // Create the 2D histos corresponding to the pad groupCalibration mode
451 AliInfo(Form("The pad calibration mode for the relative gain calibration: Nz %d, and Nrphi %d"
452 ,fCalibraMode->GetNz(0)
453 ,fCalibraMode->GetNrphi(0)));
455 // Create the 2D histo
460 fAmpTotal = new Float_t[TMath::Max(fCalibraMode->GetDetChamb2(0),fCalibraMode->GetDetChamb0(0))];
461 for (Int_t k = 0; k < TMath::Max(fCalibraMode->GetDetChamb2(0),fCalibraMode->GetDetChamb0(0)); k++) {
465 fEntriesCH = new Int_t[ntotal0];
466 for(Int_t k = 0; k < ntotal0; k++){
473 AliInfo(Form("The pad calibration mode for the drift velocity calibration: Nz %d, and Nrphi %d"
474 ,fCalibraMode->GetNz(1)
475 ,fCalibraMode->GetNrphi(1)));
477 // Create the 2D histo
482 fPHPlace = new Short_t[fTimeMax];
483 for (Int_t k = 0; k < fTimeMax; k++) {
486 fPHValue = new Float_t[fTimeMax];
487 for (Int_t k = 0; k < fTimeMax; k++) {
491 if (fLinearFitterOn) {
492 if(fLinearFitterDebugOn) {
493 fLinearFitterArray.SetName("ArrayLinearFitters");
494 fEntriesLinearFitter = new Int_t[540];
495 for(Int_t k = 0; k < 540; k++){
496 fEntriesLinearFitter[k] = 0;
499 fLinearVdriftFit = new AliTRDCalibraVdriftLinearFit();
504 AliInfo(Form("The pad calibration mode for the PRF calibration: Nz %d, and Nrphi %d"
505 ,fCalibraMode->GetNz(2)
506 ,fCalibraMode->GetNrphi(2)));
507 // Create the 2D histo
509 CreatePRF2d(ntotal2);
516 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
517 Bool_t AliTRDCalibraFillHisto::InitCalDet()
520 // Init the Gain Cal Det
525 AliCDBEntry *entry = AliCDBManager::Instance()->Get("TRD/Calib/ChamberGainFactor",AliCDBManager::Instance()->GetRun(),fVersionGainUsed,fSubVersionGainUsed);
531 fCalDetGain->~AliTRDCalDet();
532 new(fCalDetGain) AliTRDCalDet(*(dynamic_cast<AliTRDCalDet *>(entry->GetObject())));
533 }else fCalDetGain = new AliTRDCalDet(*(dynamic_cast<AliTRDCalDet *>(entry->GetObject())));
539 AliError("No new gain calibration entry found");
546 name += fVersionGainUsed;
548 name += fSubVersionGainUsed;
550 name += fCalibraMode->GetNz(0);
552 name += fCalibraMode->GetNrphi(0);
554 fCH2d->SetTitle(name);
557 TString namee("Ver");
558 namee += fVersionVdriftUsed;
560 namee += fSubVersionVdriftUsed;
562 namee += fCalibraMode->GetNz(1);
564 namee += fCalibraMode->GetNrphi(1);
566 fPH2d->SetTitle(namee);
572 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
573 Bool_t AliTRDCalibraFillHisto::InitCalPad(Int_t detector)
576 // Init the Gain Cal Pad
581 AliCDBEntry *entry = AliCDBManager::Instance()->Get("TRD/Calib/LocalGainFactor",AliCDBManager::Instance()->GetRun(),fVersionGainLocalUsed,fSubVersionGainLocalUsed);
587 fCalROCGain->~AliTRDCalROC();
588 new(fCalROCGain) AliTRDCalROC(*((dynamic_cast<AliTRDCalPad *>(entry->GetObject()))->GetCalROC(detector)));
589 }else fCalROCGain = new AliTRDCalROC(*((dynamic_cast<AliTRDCalPad *>(entry->GetObject()))->GetCalROC(detector)));
595 AliError("No new gain calibration entry found");
603 //____________Offline tracking in the AliTRDtracker____________________________
604 Bool_t AliTRDCalibraFillHisto::UpdateHistograms(const AliTRDtrack *t)
607 // Use AliTRDtrack for the calibration
611 AliTRDcluster *cl = 0x0; // pointeur to cluster
612 Int_t index0 = 0; // index of the first cluster in the current chamber
613 Int_t index1 = 0; // index of the current cluster in the current chamber
615 //////////////////////////////
616 // loop over the clusters
617 ///////////////////////////////
618 while((cl = t->GetCluster(index1))){
620 /////////////////////////////////////////////////////////////////////////
621 // Fill the infos for the previous clusters if not the same detector
622 ////////////////////////////////////////////////////////////////////////
623 Int_t detector = cl->GetDetector();
624 if ((detector != fDetectorPreviousTrack) &&
625 (index0 != index1)) {
629 //If the same track, then look if the previous detector is in
630 //the same plane, if yes: not a good track
631 if ((GetLayer(detector) == GetLayer(fDetectorPreviousTrack))) {
635 // Fill only if the track doesn't touch a masked pad or doesn't
638 // drift velocity unables to cut bad tracklets
639 Bool_t pass = FindP1TrackPHtracklet(t,index0,index1);
643 FillTheInfoOfTheTrackCH(index1-index0);
648 FillTheInfoOfTheTrackPH();
651 if(pass && fPRF2dOn) HandlePRFtracklet(t,index0,index1);
654 } // if a good tracklet
657 ResetfVariablestracklet();
660 } // Fill at the end the charge
663 /////////////////////////////////////////////////////////////
664 // Localise and take the calib gain object for the detector
665 ////////////////////////////////////////////////////////////
666 if (detector != fDetectorPreviousTrack) {
668 //Localise the detector
669 LocalisationDetectorXbins(detector);
672 AliTRDcalibDB *cal = AliTRDcalibDB::Instance();
674 AliInfo("Could not get calibDB");
679 if(!fIsHLT) InitCalPad(detector);
683 // Reset the detectbjobsor
684 fDetectorPreviousTrack = detector;
686 ///////////////////////////////////////
687 // Store the info of the cluster
688 ///////////////////////////////////////
689 Int_t row = cl->GetPadRow();
690 Int_t col = cl->GetPadCol();
691 CheckGoodTrackletV1(cl);
692 Int_t group[2] = {0,0};
693 if(fCH2dOn) group[0] = CalculateCalibrationGroup(0,row,col);
694 if(fPH2dOn) group[1] = CalculateCalibrationGroup(1,row,col);
695 StoreInfoCHPHtrack(cl,t->GetClusterdQdl(index1),group,row,col);
699 } // while on clusters
701 ///////////////////////////
702 // Fill the last plane
703 //////////////////////////
704 if( index0 != index1 ){
710 // drift velocity unables to cut bad tracklets
711 Bool_t pass = FindP1TrackPHtracklet(t,index0,index1);
715 FillTheInfoOfTheTrackCH(index1-index0);
720 FillTheInfoOfTheTrackPH();
723 if(pass && fPRF2dOn) HandlePRFtracklet(t,index0,index1);
725 } // if a good tracklet
730 ResetfVariablestracklet();
735 //____________Offline tracking in the AliTRDtracker____________________________
736 Bool_t AliTRDCalibraFillHisto::UpdateHistogramsV1(const AliTRDtrackV1 *t)
739 // Use AliTRDtrackV1 for the calibration
743 const AliTRDseedV1 *tracklet = 0x0; // tracklet per plane
744 AliTRDcluster *cl = 0x0; // cluster attached now to the tracklet
745 AliTRDcluster *cls = 0x0; // shared cluster attached now to the tracklet
746 Bool_t newtr = kTRUE; // new track
749 // AliTRDcalibDB *cal = AliTRDcalibDB::Instance();
752 AliInfo("Could not get calibDB");
757 AliInfo("Could not get calibDB");
762 ///////////////////////////
763 // loop over the tracklet
764 ///////////////////////////
765 for(Int_t itr = 0; itr < 6; itr++){
767 if(!(tracklet = t->GetTracklet(itr))) continue;
768 if(!tracklet->IsOK()) continue;
770 ResetfVariablestracklet();
772 //////////////////////////////////////////
773 // localisation of the tracklet and dqdl
774 //////////////////////////////////////////
775 Int_t layer = tracklet->GetPlane();
777 while(!(cl = tracklet->GetClusters(ic++))) continue;
778 Int_t detector = cl->GetDetector();
779 if (detector != fDetectorPreviousTrack) {
780 // if not a new track
782 // don't use the rest of this track if in the same plane
783 if (layer == GetLayer(fDetectorPreviousTrack)) {
784 //printf("bad tracklet, same layer for detector %d\n",detector);
788 //Localise the detector bin
789 LocalisationDetectorXbins(detector);
791 if(!fIsHLT) InitCalPad(detector);
794 fDetectorPreviousTrack = detector;
798 ////////////////////////////
799 // loop over the clusters
800 ////////////////////////////
801 Int_t nbclusters = 0;
802 for(int jc=0; jc<AliTRDseedV1::kNtb; jc++){
803 if(!(cl = tracklet->GetClusters(jc))) continue;
806 // Store the info bis of the tracklet
807 Int_t row = cl->GetPadRow();
808 Int_t col = cl->GetPadCol();
809 CheckGoodTrackletV1(cl);
810 Int_t group[2] = {0,0};
811 if(fCH2dOn) group[0] = CalculateCalibrationGroup(0,row,col);
812 if(fPH2dOn) group[1] = CalculateCalibrationGroup(1,row,col);
813 // Add the charge if shared cluster
814 cls = tracklet->GetClusters(jc+AliTRDseedV1::kNtb);
816 StoreInfoCHPHtrack(cl, tracklet->GetdQdl(jc),group,row,col,cls);
819 ////////////////////////////////////////
820 // Fill the stuffs if a good tracklet
821 ////////////////////////////////////////
824 // drift velocity unables to cut bad tracklets
825 Bool_t pass = FindP1TrackPHtrackletV1(tracklet, nbclusters);
827 //printf("pass %d and nbclusters %d\n",pass,nbclusters);
831 FillTheInfoOfTheTrackCH(nbclusters);
836 FillTheInfoOfTheTrackPH();
839 if(pass && fPRF2dOn) HandlePRFtrackletV1(tracklet,nbclusters);
841 } // if a good tracklet
847 ///////////////////////////////////////////////////////////////////////////////////
848 // Routine inside the update with AliTRDtrack
849 ///////////////////////////////////////////////////////////////////////////////////
850 //____________Offine tracking in the AliTRDtracker_____________________________
851 Bool_t AliTRDCalibraFillHisto::FindP1TrackPHtracklet(const AliTRDtrack *t, Int_t index0, Int_t index1)
854 // Drift velocity calibration:
855 // Fit the clusters with a straight line
856 // From the slope find the drift velocity
859 //Number of points: if less than 3 return kFALSE
860 Int_t npoints = index1-index0;
861 if(npoints <= 2) return kFALSE;
866 Int_t detector = ((AliTRDcluster *) t->GetCluster(index0))->GetDetector(); //detector
867 // parameters of the track
868 Double_t snp = t->GetSnpPlane(GetLayer(detector)); // sin angle in the plan yx track
869 Double_t tgl = t->GetTglPlane(GetLayer(detector)); // dz/dl and not dz/dx!
870 Double_t tnp = 0.0; // tan angle in the plan xy track
871 if( TMath::Abs(snp) < 1.){
872 tnp = snp / TMath::Sqrt((1.-snp)*(1.+snp));
874 Float_t dzdx = tgl*TMath::Sqrt(1+tnp*tnp); // dz/dx now from dz/dl
875 // tilting pad and cross row
876 Int_t crossrow = 0; // if it crosses a pad row
877 Int_t rowp = -1; // if it crosses a pad row
878 AliTRDpadPlane *padplane = fGeo->GetPadPlane(GetLayer(detector),GetStack(detector));
879 Double_t tiltingangle = padplane->GetTiltingAngle(); // tiltingangle of the pad
880 Float_t tnt = TMath::Tan(tiltingangle/180.*TMath::Pi()); // tan tiltingangle
882 fLinearFitterTracklet->ClearPoints();
883 Double_t dydt = 0.0; // dydt tracklet after straight line fit
884 Double_t errorpar = 0.0; // error after straight line fit on dy/dt
885 Double_t pointError = 0.0; // error after straight line fit
886 Int_t nbli = 0; // number linear fitter points
888 //////////////////////////////
889 // loop over clusters
890 ////////////////////////////
891 for(Int_t k = 0; k < npoints; k++){
893 AliTRDcluster *cl = (AliTRDcluster *) t->GetCluster(k+index0);
894 if((fLimitChargeIntegration) && (!cl->IsInChamber())) continue;
895 Double_t ycluster = cl->GetY();
896 Int_t time = cl->GetPadTime();
897 Double_t timeis = time/fSf;
898 //Double_t q = cl->GetQ();
899 //See if cross two pad rows
900 Int_t row = cl->GetPadRow();
902 if(row != rowp) crossrow = 1;
904 fLinearFitterTracklet->AddPoint(&timeis,ycluster,1);
909 //////////////////////////////
911 //////////////////////////////
913 fLinearFitterTracklet->ClearPoints();
917 fLinearFitterTracklet->Eval();
918 fLinearFitterTracklet->GetParameters(pars);
919 pointError = TMath::Sqrt(fLinearFitterTracklet->GetChisquare()/(nbli-2));
920 errorpar = fLinearFitterTracklet->GetParError(1)*pointError;
922 fLinearFitterTracklet->ClearPoints();
924 /////////////////////////////
926 ////////////////////////////
928 if ( !fDebugStreamer ) {
930 TDirectory *backup = gDirectory;
931 fDebugStreamer = new TTreeSRedirector("TRDdebugCalibraFill.root");
932 if ( backup ) backup->cd(); //we don't want to be cd'd to the debug streamer
936 (* fDebugStreamer) << "FindP1TrackPHtracklet0"<<
937 //"snpright="<<snpright<<
938 "npoints="<<npoints<<
940 "detector="<<detector<<
947 "crossrow="<<crossrow<<
948 "errorpar="<<errorpar<<
949 "pointError="<<pointError<<
953 Int_t nbclusters = index1-index0;
954 Int_t layer = GetLayer(fDetectorPreviousTrack);
956 (* fDebugStreamer) << "FindP1TrackPHtracklet1"<<
957 //"snpright="<<snpright<<
958 "nbclusters="<<nbclusters<<
959 "detector="<<fDetectorPreviousTrack<<
965 ///////////////////////////
967 ///////////////////////////
968 if(npoints < fNumberClusters) return kFALSE;
969 if(npoints > fNumberClustersf) return kFALSE;
970 if(pointError >= 0.1) return kFALSE;
971 if(crossrow == 1) return kFALSE;
973 ////////////////////////////
975 ////////////////////////////
977 //Add to the linear fitter of the detector
978 if( TMath::Abs(snp) < 1.){
979 Double_t x = tnp-dzdx*tnt;
980 if(fLinearFitterDebugOn) {
981 (GetLinearFitter(detector,kTRUE))->AddPoint(&x,dydt);
982 fEntriesLinearFitter[detector]++;
984 fLinearVdriftFit->Update(detector,x,pars[1]);
990 //____________Offine tracking in the AliTRDtracker_____________________________
991 Bool_t AliTRDCalibraFillHisto::FindP1TrackPHtrackletV1(const AliTRDseedV1 *tracklet, Int_t nbclusters)
994 // Drift velocity calibration:
995 // Fit the clusters with a straight line
996 // From the slope find the drift velocity
999 ////////////////////////////////////////////////
1000 //Number of points: if less than 3 return kFALSE
1001 /////////////////////////////////////////////////
1002 if(nbclusters <= 2) return kFALSE;
1007 // results of the linear fit
1008 Double_t dydt = 0.0; // dydt tracklet after straight line fit
1009 Double_t errorpar = 0.0; // error after straight line fit on dy/dt
1010 Double_t pointError = 0.0; // error after straight line fit
1011 // pad row problemes: avoid tracklet that cross pad rows, tilting angle in the constant
1012 Int_t crossrow = 0; // if it crosses a pad row
1013 Int_t rowp = -1; // if it crosses a pad row
1014 Float_t tnt = tracklet->GetTilt(); // tan tiltingangle
1015 fLinearFitterTracklet->ClearPoints();
1018 ///////////////////////////////////////////
1019 // Take the parameters of the track
1020 //////////////////////////////////////////
1021 // take now the snp, tnp and tgl from the track
1022 Double_t snp = tracklet->GetSnp(); // sin dy/dx at the end of the chamber
1023 Double_t tnp = 0.0; // dy/dx at the end of the chamber
1024 if( TMath::Abs(snp) < 1.){
1025 tnp = snp / TMath::Sqrt((1.-snp)*(1.+snp));
1027 Double_t tgl = tracklet->GetTgl(); // dz/dl
1028 Double_t dzdx = tgl*TMath::Sqrt(1+tnp*tnp); // dz/dx calculated from dz/dl
1030 //Double_t tnp = tracklet->GetYref(1); // dy/dx at the entrance of the chamber
1031 //Double_t tgl = tracklet->GetZref(1); // dz/dl at the entrance of the chamber
1032 //Double_t dzdx = tgl; //*TMath::Sqrt(1+tnp*tnp); // dz/dx from dz/dl
1033 // at the end with correction due to linear fit
1034 //Double_t tnp = tracklet->GetYfit(1); // dy/dx at the end of the chamber after fit correction
1035 //Double_t tgl = tracklet->GetZfit(1); // dz/dl at the end of the chamber after fit correction
1038 ////////////////////////////
1039 // loop over the clusters
1040 ////////////////////////////
1042 AliTRDcluster *cl = 0x0;
1043 //////////////////////////////
1044 // Check no shared clusters
1045 //////////////////////////////
1046 for(int icc=AliTRDseedV1::kNtb; icc<AliTRDseedV1::kNclusters; icc++){
1047 if((cl = tracklet->GetClusters(icc))) crossrow = 1;
1049 //////////////////////////////////
1051 //////////////////////////////////
1052 for(int ic=0; ic<AliTRDseedV1::kNtb; ic++){
1053 if(!(cl = tracklet->GetClusters(ic))) continue;
1054 if((fLimitChargeIntegration) && (!cl->IsInChamber())) continue;
1056 Double_t ycluster = cl->GetY();
1057 Int_t time = cl->GetPadTime();
1058 Double_t timeis = time/fSf;
1059 //See if cross two pad rows
1060 Int_t row = cl->GetPadRow();
1061 if(rowp==-1) rowp = row;
1062 if(row != rowp) crossrow = 1;
1064 fLinearFitterTracklet->AddPoint(&timeis,ycluster,1);
1070 ////////////////////////////////////
1071 // Do the straight line fit now
1072 ///////////////////////////////////
1074 fLinearFitterTracklet->ClearPoints();
1078 fLinearFitterTracklet->Eval();
1079 fLinearFitterTracklet->GetParameters(pars);
1080 pointError = TMath::Sqrt(fLinearFitterTracklet->GetChisquare()/(nbli-2));
1081 errorpar = fLinearFitterTracklet->GetParError(1)*pointError;
1083 //printf("chis %f, nbli %d, pointError %f, parError %f, errorpar %f\n",fLinearFitterTracklet->GetChisquare(),nbli,pointError,fLinearFitterTracklet->GetParError(1),errorpar);
1084 fLinearFitterTracklet->ClearPoints();
1086 ////////////////////////////////
1088 ///////////////////////////////
1091 if(fDebugLevel > 0){
1092 if ( !fDebugStreamer ) {
1094 TDirectory *backup = gDirectory;
1095 fDebugStreamer = new TTreeSRedirector("TRDdebugCalibraFill.root");
1096 if ( backup ) backup->cd(); //we don't want to be cd'd to the debug streamer
1100 Int_t layer = GetLayer(fDetectorPreviousTrack);
1102 (* fDebugStreamer) << "FindP1TrackPHtrackletV1"<<
1103 //"snpright="<<snpright<<
1105 "nbclusters="<<nbclusters<<
1106 "detector="<<fDetectorPreviousTrack<<
1114 "crossrow="<<crossrow<<
1115 "errorpar="<<errorpar<<
1116 "pointError="<<pointError<<
1121 /////////////////////////
1123 ////////////////////////
1125 if(nbclusters < fNumberClusters) return kFALSE;
1126 if(nbclusters > fNumberClustersf) return kFALSE;
1127 if(pointError >= 0.3) return kFALSE;
1128 if(crossrow == 1) return kFALSE;
1130 ///////////////////////
1132 //////////////////////
1134 if(fLinearFitterOn){
1135 //Add to the linear fitter of the detector
1136 if( TMath::Abs(snp) < 1.){
1137 Double_t x = tnp-dzdx*tnt;
1138 if(fLinearFitterDebugOn) {
1139 (GetLinearFitter(fDetectorPreviousTrack,kTRUE))->AddPoint(&x,dydt);
1140 fEntriesLinearFitter[fDetectorPreviousTrack]++;
1142 fLinearVdriftFit->Update(fDetectorPreviousTrack,x,pars[1]);
1148 //____________Offine tracking in the AliTRDtracker_____________________________
1149 Bool_t AliTRDCalibraFillHisto::HandlePRFtracklet(const AliTRDtrack *t, Int_t index0, Int_t index1)
1152 // PRF width calibration
1153 // Assume a Gaussian shape: determinate the position of the three pad clusters
1154 // Fit with a straight line
1155 // Take the fitted values for all the clusters (3 or 2 pad clusters)
1156 // Fill the PRF as function of angle of the track
1161 //////////////////////////
1163 /////////////////////////
1164 Int_t npoints = index1-index0; // number of total points
1165 Int_t nb3pc = 0; // number of three pads clusters used for fit
1166 Int_t detector = ((AliTRDcluster *) t->GetCluster(index0))->GetDetector(); // detector
1167 // To see the difference due to the fit
1168 Double_t *padPositions;
1169 padPositions = new Double_t[npoints];
1170 for(Int_t k = 0; k < npoints; k++){
1171 padPositions[k] = 0.0;
1173 // Take the tgl and snp with the track t now
1174 Double_t tgl = t->GetTglPlane(GetLayer(detector)); //dz/dl and not dz/dx
1175 Double_t snp = t->GetSnpPlane(GetLayer(detector)); // sin angle in xy plan
1176 Float_t dzdx = 0.0; // dzdx
1178 if(TMath::Abs(snp) < 1.0){
1179 tnp = snp / TMath::Sqrt((1.-snp)*(1.+snp));
1180 dzdx = tgl*TMath::Sqrt(1+tnp*tnp);
1183 fLinearFitterTracklet->ClearPoints();
1185 ///////////////////////////
1186 // calcul the tnp group
1187 ///////////////////////////
1188 Bool_t echec = kFALSE;
1189 Double_t shift = 0.0;
1190 //Calculate the shift in x coresponding to this tnp
1191 if(fNgroupprf != 0.0){
1192 shift = -3.0*(fNgroupprf-1)-1.5;
1193 Double_t limithigh = -0.2*(fNgroupprf-1);
1194 if((tnp < (-0.2*fNgroupprf)) || (tnp > (0.2*fNgroupprf))) echec = kTRUE;
1196 while(tnp > limithigh){
1203 delete [] padPositions;
1207 //////////////////////
1209 /////////////////////
1210 for(Int_t k = 0; k < npoints; k++){
1212 AliTRDcluster *cl = (AliTRDcluster *) t->GetCluster(k+index0);
1214 Short_t *signals = cl->GetSignals();
1215 Double_t time = cl->GetPadTime();
1216 //Calculate x if possible
1217 Float_t xcenter = 0.0;
1218 Bool_t echec1 = kTRUE;
1219 if((time<=7) || (time>=21)) continue;
1220 // Center 3 balanced: position with the center of the pad
1221 if ((((Float_t) signals[3]) > 0.0) &&
1222 (((Float_t) signals[2]) > 0.0) &&
1223 (((Float_t) signals[4]) > 0.0)) {
1225 // Security if the denomiateur is 0
1226 if ((((Float_t) (((Float_t) signals[3]) * ((Float_t) signals[3]))) /
1227 ((Float_t) (((Float_t) signals[2]) * ((Float_t) signals[4])))) != 1.0) {
1228 xcenter = 0.5 * (TMath::Log((Float_t) (((Float_t) signals[4]) / ((Float_t) signals[2]))))
1229 / (TMath::Log(((Float_t) (((Float_t) signals[3]) * ((Float_t) signals[3])))
1230 / ((Float_t) (((Float_t) signals[2]) * ((Float_t) signals[4])))));
1236 if(TMath::Abs(xcenter) > 0.5) echec = kTRUE;
1238 //if no echec: calculate with the position of the pad
1239 // Position of the cluster
1240 Double_t padPosition = xcenter + cl->GetPadCol();
1241 padPositions[k] = padPosition;
1243 fLinearFitterTracklet->AddPoint(&time, padPosition,1);
1247 /////////////////////////////
1249 ////////////////////////////
1251 delete [] padPositions;
1252 fLinearFitterTracklet->ClearPoints();
1255 fLinearFitterTracklet->Eval();
1257 fLinearFitterTracklet->GetParameters(line);
1258 Float_t pointError = -1.0;
1259 if( fLinearFitterTracklet->GetChisquare()>=0.0) {
1260 pointError = TMath::Sqrt( fLinearFitterTracklet->GetChisquare()/(nb3pc-2));
1262 fLinearFitterTracklet->ClearPoints();
1264 /////////////////////////////////////////////////////
1265 // Now fill the PRF: second loop over clusters
1266 /////////////////////////////////////////////////////
1267 for(Int_t k = 0; k < npoints; k++){
1269 AliTRDcluster *cl = (AliTRDcluster *) t->GetCluster(k+index0);
1270 Short_t *signals = cl->GetSignals(); // signal
1271 Double_t time = cl->GetPadTime(); // time bin
1272 Float_t padPosTracklet = line[0]+line[1]*time; // reconstruct position from fit
1273 Float_t padPos = cl->GetPadCol(); // middle pad
1274 Double_t dpad = padPosTracklet - padPos; // reconstruct position relative to middle pad from fit
1275 Float_t ycenter = 0.0; // relative center charge
1276 Float_t ymin = 0.0; // relative left charge
1277 Float_t ymax = 0.0; // relative right charge
1279 //Requiere simply two pads clusters at least
1280 if(((((Float_t) signals[3]) > 0.0) && (((Float_t) signals[2]) > 0.0)) ||
1281 ((((Float_t) signals[3]) > 0.0) && (((Float_t) signals[4]) > 0.0))){
1282 Float_t sum = ((Float_t) signals[2]) + ((Float_t) signals[3]) + ((Float_t) signals[4]);
1283 if(sum > 0.0) ycenter = ((Float_t) signals[3])/ sum;
1284 if(sum > 0.0) ymin = ((Float_t) signals[2])/ sum;
1285 if(sum > 0.0) ymax = ((Float_t) signals[4])/ sum;
1289 Int_t rowcl = cl->GetPadRow(); // row of cluster
1290 Int_t colcl = cl->GetPadCol(); // col of cluster
1291 Int_t grouplocal = CalculateCalibrationGroup(2,rowcl,colcl); // calcul the corresponding group
1292 Int_t caligroup = fCalibraMode->GetXbins(2)+ grouplocal; // calcul the corresponding group
1293 Float_t xcl = cl->GetY(); // y cluster
1294 Float_t qcl = cl->GetQ(); // charge cluster
1295 Int_t layer = GetLayer(detector); // layer
1296 Int_t stack = GetStack(detector); // stack
1297 Double_t xdiff = dpad; // reconstructed position constant
1298 Double_t x = dpad; // reconstructed position moved
1299 Float_t ep = pointError; // error of fit
1300 Float_t signal1 = (Float_t)signals[1]; // signal at the border
1301 Float_t signal3 = (Float_t)signals[3]; // signal
1302 Float_t signal2 = (Float_t)signals[2]; // signal
1303 Float_t signal4 = (Float_t)signals[4]; // signal
1304 Float_t signal5 = (Float_t)signals[5]; // signal at the border
1306 //////////////////////////////
1308 /////////////////////////////
1309 if(fDebugLevel > 0){
1310 if ( !fDebugStreamer ) {
1312 TDirectory *backup = gDirectory;
1313 fDebugStreamer = new TTreeSRedirector("TRDdebugCalibraFill.root");
1314 if ( backup ) backup->cd(); //we don't want to be cd'd to the debug streamer
1320 Float_t y = ycenter;
1321 (* fDebugStreamer) << "HandlePRFtracklet"<<
1322 "caligroup="<<caligroup<<
1323 "detector="<<detector<<
1326 "npoints="<<npoints<<
1335 "padPosition="<<padPositions[k]<<
1336 "padPosTracklet="<<padPosTracklet<<
1341 "signal1="<<signal1<<
1342 "signal2="<<signal2<<
1343 "signal3="<<signal3<<
1344 "signal4="<<signal4<<
1345 "signal5="<<signal5<<
1351 (* fDebugStreamer) << "HandlePRFtracklet"<<
1352 "caligroup="<<caligroup<<
1353 "detector="<<detector<<
1356 "npoints="<<npoints<<
1365 "padPosition="<<padPositions[k]<<
1366 "padPosTracklet="<<padPosTracklet<<
1371 "signal1="<<signal1<<
1372 "signal2="<<signal2<<
1373 "signal3="<<signal3<<
1374 "signal4="<<signal4<<
1375 "signal5="<<signal5<<
1381 (* fDebugStreamer) << "HandlePRFtracklet"<<
1382 "caligroup="<<caligroup<<
1383 "detector="<<detector<<
1386 "npoints="<<npoints<<
1395 "padPosition="<<padPositions[k]<<
1396 "padPosTracklet="<<padPosTracklet<<
1401 "signal1="<<signal1<<
1402 "signal2="<<signal2<<
1403 "signal3="<<signal3<<
1404 "signal4="<<signal4<<
1405 "signal5="<<signal5<<
1411 ////////////////////////////
1413 ///////////////////////////
1414 if(npoints < fNumberClusters) continue;
1415 if(npoints > fNumberClustersf) continue;
1416 if(nb3pc <= 5) continue;
1417 if((time >= 21) || (time < 7)) continue;
1418 if(TMath::Abs(snp) >= 1.0) continue;
1419 if(TMath::Abs(qcl) < 80) continue;
1421 ////////////////////////////
1423 ///////////////////////////
1425 if(TMath::Abs(dpad) < 1.5) {
1426 fPRF2d->Fill(shift+dpad,(caligroup+0.5),ycenter);
1427 fPRF2d->Fill(shift-dpad,(caligroup+0.5),ycenter);
1429 if((ymin > 0.0) && (TMath::Abs(dpad+1.0) < 1.5)) {
1430 fPRF2d->Fill(shift-(dpad+1.0),(caligroup+0.5),ymin);
1431 fPRF2d->Fill(shift+(dpad+1.0),(caligroup+0.5),ymin);
1433 if((ymax > 0.0) && (TMath::Abs(dpad-1.0) < 1.5)) {
1434 fPRF2d->Fill(shift+1.0-dpad,(caligroup+0.5),ymax);
1435 fPRF2d->Fill(shift-1.0+dpad,(caligroup+0.5),ymax);
1439 if(TMath::Abs(dpad) < 1.5) {
1440 fCalibraVector->UpdateVectorPRF(fDetectorPreviousTrack,grouplocal,shift+dpad,ycenter);
1441 fCalibraVector->UpdateVectorPRF(fDetectorPreviousTrack,grouplocal,shift-dpad,ycenter);
1443 if((ymin > 0.0) && (TMath::Abs(dpad+1.0) < 1.5)) {
1444 fCalibraVector->UpdateVectorPRF(fDetectorPreviousTrack,grouplocal,shift-(dpad+1.0),ymin);
1445 fCalibraVector->UpdateVectorPRF(fDetectorPreviousTrack,grouplocal,shift+(dpad+1.0),ymin);
1447 if((ymax > 0.0) && (TMath::Abs(dpad-1.0) < 1.5)) {
1448 fCalibraVector->UpdateVectorPRF(fDetectorPreviousTrack,grouplocal,shift+1.0-dpad,ymax);
1449 fCalibraVector->UpdateVectorPRF(fDetectorPreviousTrack,grouplocal,shift-1.0+dpad,ymax);
1453 delete [] padPositions;
1457 //____________Offine tracking in the AliTRDtracker_____________________________
1458 Bool_t AliTRDCalibraFillHisto::HandlePRFtrackletV1(const AliTRDseedV1 *tracklet, Int_t nbclusters)
1461 // PRF width calibration
1462 // Assume a Gaussian shape: determinate the position of the three pad clusters
1463 // Fit with a straight line
1464 // Take the fitted values for all the clusters (3 or 2 pad clusters)
1465 // Fill the PRF as function of angle of the track
1469 //printf("begin\n");
1470 ///////////////////////////////////////////
1471 // Take the parameters of the track
1472 //////////////////////////////////////////
1473 // take now the snp, tnp and tgl from the track
1474 Double_t snp = tracklet->GetSnp(); // sin dy/dx at the end of the chamber
1475 Double_t tnp = 0.0; // dy/dx at the end of the chamber
1476 if( TMath::Abs(snp) < 1.){
1477 tnp = snp / TMath::Sqrt((1.-snp)*(1.+snp));
1479 Double_t tgl = tracklet->GetTgl(); // dz/dl
1480 Double_t dzdx = tgl*TMath::Sqrt(1+tnp*tnp); // dz/dx calculated from dz/dl
1482 //Double_t tnp = tracklet->GetYref(1); // dy/dx at the entrance of the chamber
1483 //Double_t tgl = tracklet->GetZref(1); // dz/dl at the entrance of the chamber
1484 //Double_t dzdx = tgl; //*TMath::Sqrt(1+tnp*tnp); // dz/dx from dz/dl
1485 // at the end with correction due to linear fit
1486 //Double_t tnp = tracklet->GetYfit(1); // dy/dx at the end of the chamber after fit correction
1487 //Double_t tgl = tracklet->GetZfit(1); // dz/dl at the end of the chamber after fit correction
1489 ///////////////////////////////
1490 // Calculate tnp group shift
1491 ///////////////////////////////
1492 Bool_t echec = kFALSE;
1493 Double_t shift = 0.0;
1494 //Calculate the shift in x coresponding to this tnp
1495 if(fNgroupprf != 0.0){
1496 shift = -3.0*(fNgroupprf-1)-1.5;
1497 Double_t limithigh = -0.2*(fNgroupprf-1);
1498 if((tnp < (-0.2*fNgroupprf)) || (tnp > (0.2*fNgroupprf))) echec = kTRUE;
1500 while(tnp > limithigh){
1506 // do nothing if out of tnp range
1507 //printf("echec %d\n",(Int_t)echec);
1508 if(echec) return kFALSE;
1510 ///////////////////////
1512 //////////////////////
1514 Int_t nb3pc = 0; // number of three pads clusters used for fit
1515 // to see the difference between the fit and the 3 pad clusters position
1516 Double_t padPositions[AliTRDseedV1::kNtb];
1517 memset(padPositions, 0, AliTRDseedV1::kNtb*sizeof(Double_t));
1518 fLinearFitterTracklet->ClearPoints();
1520 //printf("loop clusters \n");
1521 ////////////////////////////
1522 // loop over the clusters
1523 ////////////////////////////
1524 AliTRDcluster *cl = 0x0;
1525 for(int ic=0; ic<AliTRDseedV1::kNtb; ic++){
1526 // reject shared clusters on pad row
1527 if((ic+AliTRDseedV1::kNtb) < AliTRDseedV1::kNclusters) {
1528 if((cl = tracklet->GetClusters(ic+AliTRDseedV1::kNtb))) continue;
1530 if(!(cl = tracklet->GetClusters(ic))) continue;
1531 Double_t time = cl->GetPadTime();
1532 if((time<=7) || (time>=21)) continue;
1533 Short_t *signals = cl->GetSignals();
1534 Float_t xcenter = 0.0;
1535 Bool_t echec1 = kTRUE;
1537 /////////////////////////////////////////////////////////////
1538 // Center 3 balanced: position with the center of the pad
1539 /////////////////////////////////////////////////////////////
1540 if ((((Float_t) signals[3]) > 0.0) &&
1541 (((Float_t) signals[2]) > 0.0) &&
1542 (((Float_t) signals[4]) > 0.0)) {
1544 // Security if the denomiateur is 0
1545 if ((((Float_t) (((Float_t) signals[3]) * ((Float_t) signals[3]))) /
1546 ((Float_t) (((Float_t) signals[2]) * ((Float_t) signals[4])))) != 1.0) {
1547 xcenter = 0.5 * (TMath::Log((Float_t) (((Float_t) signals[4]) / ((Float_t) signals[2]))))
1548 / (TMath::Log(((Float_t) (((Float_t) signals[3]) * ((Float_t) signals[3])))
1549 / ((Float_t) (((Float_t) signals[2]) * ((Float_t) signals[4])))));
1555 if(TMath::Abs(xcenter) > 0.5) echec1 = kTRUE;
1556 if(echec1) continue;
1558 ////////////////////////////////////////////////////////
1559 //if no echec1: calculate with the position of the pad
1560 // Position of the cluster
1561 // fill the linear fitter
1562 ///////////////////////////////////////////////////////
1563 Double_t padPosition = xcenter + cl->GetPadCol();
1564 padPositions[ic] = padPosition;
1566 fLinearFitterTracklet->AddPoint(&time, padPosition,1);
1571 //printf("Fin loop clusters \n");
1572 //////////////////////////////
1573 // fit with a straight line
1574 /////////////////////////////
1576 fLinearFitterTracklet->ClearPoints();
1579 fLinearFitterTracklet->Eval();
1581 fLinearFitterTracklet->GetParameters(line);
1582 Float_t pointError = -1.0;
1583 if( fLinearFitterTracklet->GetChisquare()>=0.0) {
1584 pointError = TMath::Sqrt( fLinearFitterTracklet->GetChisquare()/(nb3pc-2));
1586 fLinearFitterTracklet->ClearPoints();
1588 //printf("PRF second loop \n");
1589 ////////////////////////////////////////////////
1590 // Fill the PRF: Second loop over clusters
1591 //////////////////////////////////////////////
1592 for(int ic=0; ic<AliTRDseedV1::kNtb; ic++){
1593 // reject shared clusters on pad row
1594 if(((ic+AliTRDseedV1::kNtb) < AliTRDseedV1::kNclusters) && (cl = tracklet->GetClusters(ic+AliTRDseedV1::kNtb))) continue;
1596 if(!(cl = tracklet->GetClusters(ic))) continue;
1598 Short_t *signals = cl->GetSignals(); // signal
1599 Double_t time = cl->GetPadTime(); // time bin
1600 Float_t padPosTracklet = line[0]+line[1]*time; // reconstruct position from fit
1601 Float_t padPos = cl->GetPadCol(); // middle pad
1602 Double_t dpad = padPosTracklet - padPos; // reconstruct position relative to middle pad from fit
1603 Float_t ycenter = 0.0; // relative center charge
1604 Float_t ymin = 0.0; // relative left charge
1605 Float_t ymax = 0.0; // relative right charge
1607 ////////////////////////////////////////////////////////////////
1608 // Calculate ycenter, ymin and ymax even for two pad clusters
1609 ////////////////////////////////////////////////////////////////
1610 if(((((Float_t) signals[3]) > 0.0) && (((Float_t) signals[2]) > 0.0)) ||
1611 ((((Float_t) signals[3]) > 0.0) && (((Float_t) signals[4]) > 0.0))){
1612 Float_t sum = ((Float_t) signals[2]) + ((Float_t) signals[3]) + ((Float_t) signals[4]);
1613 if(sum > 0.0) ycenter = ((Float_t) signals[3])/ sum;
1614 if(sum > 0.0) ymin = ((Float_t) signals[2])/ sum;
1615 if(sum > 0.0) ymax = ((Float_t) signals[4])/ sum;
1618 /////////////////////////
1619 // Calibration group
1620 ////////////////////////
1621 Int_t rowcl = cl->GetPadRow(); // row of cluster
1622 Int_t colcl = cl->GetPadCol(); // col of cluster
1623 Int_t grouplocal = CalculateCalibrationGroup(2,rowcl,colcl); // calcul the corresponding group
1624 Int_t caligroup = fCalibraMode->GetXbins(2)+ grouplocal; // calcul the corresponding group
1625 Float_t xcl = cl->GetY(); // y cluster
1626 Float_t qcl = cl->GetQ(); // charge cluster
1627 Int_t layer = GetLayer(fDetectorPreviousTrack); // layer
1628 Int_t stack = GetStack(fDetectorPreviousTrack); // stack
1629 Double_t xdiff = dpad; // reconstructed position constant
1630 Double_t x = dpad; // reconstructed position moved
1631 Float_t ep = pointError; // error of fit
1632 Float_t signal1 = (Float_t)signals[1]; // signal at the border
1633 Float_t signal3 = (Float_t)signals[3]; // signal
1634 Float_t signal2 = (Float_t)signals[2]; // signal
1635 Float_t signal4 = (Float_t)signals[4]; // signal
1636 Float_t signal5 = (Float_t)signals[5]; // signal at the border
1640 /////////////////////
1642 ////////////////////
1644 if(fDebugLevel > 0){
1645 if ( !fDebugStreamer ) {
1647 TDirectory *backup = gDirectory;
1648 fDebugStreamer = new TTreeSRedirector("TRDdebugCalibraFill.root");
1649 if ( backup ) backup->cd(); //we don't want to be cd'd to the debug streamer
1654 Float_t y = ycenter;
1655 (* fDebugStreamer) << "HandlePRFtrackletV1"<<
1656 "caligroup="<<caligroup<<
1657 "detector="<<fDetectorPreviousTrack<<
1660 "npoints="<<nbclusters<<
1669 "padPosition="<<padPositions[ic]<<
1670 "padPosTracklet="<<padPosTracklet<<
1675 "signal1="<<signal1<<
1676 "signal2="<<signal2<<
1677 "signal3="<<signal3<<
1678 "signal4="<<signal4<<
1679 "signal5="<<signal5<<
1685 (* fDebugStreamer) << "HandlePRFtrackletV1"<<
1686 "caligroup="<<caligroup<<
1687 "detector="<<fDetectorPreviousTrack<<
1690 "npoints="<<nbclusters<<
1699 "padPosition="<<padPositions[ic]<<
1700 "padPosTracklet="<<padPosTracklet<<
1705 "signal1="<<signal1<<
1706 "signal2="<<signal2<<
1707 "signal3="<<signal3<<
1708 "signal4="<<signal4<<
1709 "signal5="<<signal5<<
1715 (* fDebugStreamer) << "HandlePRFtrackletV1"<<
1716 "caligroup="<<caligroup<<
1717 "detector="<<fDetectorPreviousTrack<<
1720 "npoints="<<nbclusters<<
1729 "padPosition="<<padPositions[ic]<<
1730 "padPosTracklet="<<padPosTracklet<<
1735 "signal1="<<signal1<<
1736 "signal2="<<signal2<<
1737 "signal3="<<signal3<<
1738 "signal4="<<signal4<<
1739 "signal5="<<signal5<<
1745 /////////////////////
1747 /////////////////////
1748 if(nbclusters < fNumberClusters) continue;
1749 if(nbclusters > fNumberClustersf) continue;
1750 if(nb3pc <= 5) continue;
1751 if((time >= 21) || (time < 7)) continue;
1752 if(TMath::Abs(qcl) < 80) continue;
1753 if( TMath::Abs(snp) > 1.) continue;
1756 ////////////////////////
1758 ///////////////////////
1760 if(TMath::Abs(dpad) < 1.5) {
1761 fPRF2d->Fill(shift+dpad,(caligroup+0.5),ycenter);
1762 fPRF2d->Fill(shift-dpad,(caligroup+0.5),ycenter);
1763 //printf("place %f, ycenter %f\n",(shift+dpad),ycenter);
1765 if((ymin > 0.0) && (TMath::Abs(dpad+1.0) < 1.5)) {
1766 fPRF2d->Fill(shift-(dpad+1.0),(caligroup+0.5),ymin);
1767 fPRF2d->Fill(shift+(dpad+1.0),(caligroup+0.5),ymin);
1769 if((ymax > 0.0) && (TMath::Abs(dpad-1.0) < 1.5)) {
1770 fPRF2d->Fill(shift+1.0-dpad,(caligroup+0.5),ymax);
1771 fPRF2d->Fill(shift-1.0+dpad,(caligroup+0.5),ymax);
1776 if(TMath::Abs(dpad) < 1.5) {
1777 fCalibraVector->UpdateVectorPRF(fDetectorPreviousTrack,grouplocal,shift+dpad,ycenter);
1778 fCalibraVector->UpdateVectorPRF(fDetectorPreviousTrack,grouplocal,shift-dpad,ycenter);
1780 if((ymin > 0.0) && (TMath::Abs(dpad+1.0) < 1.5)) {
1781 fCalibraVector->UpdateVectorPRF(fDetectorPreviousTrack,grouplocal,shift-(dpad+1.0),ymin);
1782 fCalibraVector->UpdateVectorPRF(fDetectorPreviousTrack,grouplocal,shift+(dpad+1.0),ymin);
1784 if((ymax > 0.0) && (TMath::Abs(dpad-1.0) < 1.5)) {
1785 fCalibraVector->UpdateVectorPRF(fDetectorPreviousTrack,grouplocal,shift+1.0-dpad,ymax);
1786 fCalibraVector->UpdateVectorPRF(fDetectorPreviousTrack,grouplocal,shift-1.0+dpad,ymax);
1789 } // second loop over clusters
1794 ///////////////////////////////////////////////////////////////////////////////////////
1795 // Pad row col stuff: see if masked or not
1796 ///////////////////////////////////////////////////////////////////////////////////////
1797 //_____________________________________________________________________________
1798 void AliTRDCalibraFillHisto::CheckGoodTrackletV1(const AliTRDcluster *cl)
1801 // See if we are not near a masked pad
1804 if(cl->IsMasked()) fGoodTracklet = kFALSE;
1808 //_____________________________________________________________________________
1809 void AliTRDCalibraFillHisto::CheckGoodTrackletV0(const Int_t detector,const Int_t row,const Int_t col)
1812 // See if we are not near a masked pad
1815 if (!IsPadOn(detector, col, row)) {
1816 fGoodTracklet = kFALSE;
1820 if (!IsPadOn(detector, col-1, row)) {
1821 fGoodTracklet = kFALSE;
1826 if (!IsPadOn(detector, col+1, row)) {
1827 fGoodTracklet = kFALSE;
1832 //_____________________________________________________________________________
1833 Bool_t AliTRDCalibraFillHisto::IsPadOn(Int_t detector, Int_t row, Int_t col) const
1836 // Look in the choosen database if the pad is On.
1837 // If no the track will be "not good"
1840 // Get the parameter object
1841 AliTRDcalibDB *cal = AliTRDcalibDB::Instance();
1843 AliInfo("Could not get calibDB");
1847 if (!cal->IsChamberInstalled(detector) ||
1848 cal->IsChamberMasked(detector) ||
1849 cal->IsPadMasked(detector,col,row)) {
1857 ///////////////////////////////////////////////////////////////////////////////////////
1858 // Calibration groups: calculate the number of groups, localise...
1859 ////////////////////////////////////////////////////////////////////////////////////////
1860 //_____________________________________________________________________________
1861 Int_t AliTRDCalibraFillHisto::CalculateCalibrationGroup(Int_t i, Int_t row, Int_t col) const
1864 // Calculate the calibration group number for i
1867 // Row of the cluster and position in the pad groups
1869 if (fCalibraMode->GetNnZ(i) != 0) {
1870 posr = (Int_t) row / fCalibraMode->GetNnZ(i);
1874 // Col of the cluster and position in the pad groups
1876 if (fCalibraMode->GetNnRphi(i) != 0) {
1877 posc = (Int_t) col / fCalibraMode->GetNnRphi(i);
1880 return posc*fCalibraMode->GetNfragZ(i)+posr;
1883 //____________________________________________________________________________________
1884 Int_t AliTRDCalibraFillHisto::CalculateTotalNumberOfBins(Int_t i)
1887 // Calculate the total number of calibration groups
1893 if((fCalibraMode->GetNz(i)==100) && (fCalibraMode->GetNrphi(i)==100)){
1895 AliInfo(Form("Total number of Xbins: %d for i %d",ntotal,i));
1900 if((fCalibraMode->GetNz(i)==10) && (fCalibraMode->GetNrphi(i)==10)){
1902 AliInfo(Form("Total number of Xbins: %d for i %d",ntotal,i));
1907 fCalibraMode->ModePadCalibration(2,i);
1908 fCalibraMode->ModePadFragmentation(0,2,0,i);
1909 fCalibraMode->SetDetChamb2(i);
1910 ntotal += 6 * 18 * fCalibraMode->GetDetChamb2(i);
1911 fCalibraMode->ModePadCalibration(0,i);
1912 fCalibraMode->ModePadFragmentation(0,0,0,i);
1913 fCalibraMode->SetDetChamb0(i);
1914 ntotal += 6 * 4 * 18 * fCalibraMode->GetDetChamb0(i);
1915 AliInfo(Form("Total number of Xbins: %d for i %d",ntotal,i));
1919 //_____________________________________________________________________________
1920 void AliTRDCalibraFillHisto::SetNz(Int_t i, Short_t Nz)
1923 // Set the mode of calibration group in the z direction for the parameter i
1928 fCalibraMode->SetNz(i, Nz);
1931 AliInfo("You have to choose between 0 and 4");
1935 //_____________________________________________________________________________
1936 void AliTRDCalibraFillHisto::SetNrphi(Int_t i, Short_t Nrphi)
1939 // Set the mode of calibration group in the rphi direction for the parameter i
1944 fCalibraMode->SetNrphi(i ,Nrphi);
1947 AliInfo("You have to choose between 0 and 6");
1952 //_____________________________________________________________________________
1953 void AliTRDCalibraFillHisto::SetAllTogether(Int_t i)
1956 // Set the mode of calibration group all together
1958 if(fVector2d == kTRUE) {
1959 AliInfo("Can not work with the vector method");
1962 fCalibraMode->SetAllTogether(i);
1966 //_____________________________________________________________________________
1967 void AliTRDCalibraFillHisto::SetPerSuperModule(Int_t i)
1970 // Set the mode of calibration group per supermodule
1972 if(fVector2d == kTRUE) {
1973 AliInfo("Can not work with the vector method");
1976 fCalibraMode->SetPerSuperModule(i);
1980 //____________Set the pad calibration variables for the detector_______________
1981 Bool_t AliTRDCalibraFillHisto::LocalisationDetectorXbins(Int_t detector)
1984 // For the detector calcul the first Xbins and set the number of row
1985 // and col pads per calibration groups, the number of calibration
1986 // groups in the detector.
1989 // first Xbins of the detector
1991 fCalibraMode->CalculXBins(detector,0);
1994 fCalibraMode->CalculXBins(detector,1);
1997 fCalibraMode->CalculXBins(detector,2);
2000 // fragmentation of idect
2001 for (Int_t i = 0; i < 3; i++) {
2002 fCalibraMode->ModePadCalibration((Int_t) GetStack(detector),i);
2003 fCalibraMode->ModePadFragmentation((Int_t) GetLayer(detector)
2004 , (Int_t) GetStack(detector)
2005 , (Int_t) GetSector(detector),i);
2011 //_____________________________________________________________________________
2012 void AliTRDCalibraFillHisto::SetNumberGroupsPRF(Short_t numberGroupsPRF)
2015 // Should be between 0 and 6
2018 if ((numberGroupsPRF < 0) || (numberGroupsPRF > 6)) {
2019 AliInfo("The number of groups must be between 0 and 6!");
2022 fNgroupprf = numberGroupsPRF;
2026 ///////////////////////////////////////////////////////////////////////////////////////////
2027 // Per tracklet: store or reset the info, fill the histos with the info
2028 //////////////////////////////////////////////////////////////////////////////////////////
2029 //_____________________________________________________________________________
2030 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)
2033 // Store the infos in fAmpTotal, fPHPlace and fPHValue
2034 // Correct from the gain correction before
2035 // cls is shared cluster if any
2038 //printf("StoreInfoCHPHtrack\n");
2040 // time bin of the cluster not corrected
2041 Int_t time = cl->GetPadTime();
2042 Float_t charge = TMath::Abs(cl->GetQ());
2044 charge += TMath::Abs(cls->GetQ());
2045 //printf("AliTRDCalibraFillHisto::Add the cluster charge");
2048 //printf("Store::time %d, amplitude %f\n",time,dqdl);
2050 //Correct for the gain coefficient used in the database for reconstruction
2051 Float_t correctthegain = 1.0;
2052 if(fIsHLT) correctthegain = fCalDetGain->GetValue(fDetectorPreviousTrack);
2053 else correctthegain = fCalDetGain->GetValue(fDetectorPreviousTrack)*fCalROCGain->GetValue(col,row);
2054 Float_t correction = 1.0;
2055 Float_t normalisation = 6.67;
2056 // we divide with gain in AliTRDclusterizer::Transform...
2057 if( correctthegain > 0 ) normalisation /= correctthegain;
2060 // take dd/dl corrected from the angle of the track
2061 correction = dqdl / (normalisation);
2064 // Fill the fAmpTotal with the charge
2066 if((!fLimitChargeIntegration) || (cl->IsInChamber())) {
2067 //printf("Store::group %d, amplitude %f\n",group[0],correction);
2068 fAmpTotal[(Int_t) group[0]] += correction;
2072 // Fill the fPHPlace and value
2074 fPHPlace[time] = group[1];
2075 fPHValue[time] = charge;
2079 //____________Offine tracking in the AliTRDtracker_____________________________
2080 void AliTRDCalibraFillHisto::ResetfVariablestracklet()
2083 // Reset values per tracklet
2086 //Reset good tracklet
2087 fGoodTracklet = kTRUE;
2089 // Reset the fPHValue
2091 //Reset the fPHValue and fPHPlace
2092 for (Int_t k = 0; k < fTimeMax; k++) {
2098 // Reset the fAmpTotal where we put value
2100 for (Int_t k = 0; k < fCalibraMode->GetNfragZ(0)*fCalibraMode->GetNfragRphi(0); k++) {
2105 //____________Offine tracking in the AliTRDtracker_____________________________
2106 void AliTRDCalibraFillHisto::FillTheInfoOfTheTrackCH(Int_t nbclusters)
2109 // For the offline tracking or mcm tracklets
2110 // This function will be called in the functions UpdateHistogram...
2111 // to fill the info of a track for the relativ gain calibration
2114 Int_t nb = 0; // Nombre de zones traversees
2115 Int_t fd = -1; // Premiere zone non nulle
2116 Float_t totalcharge = 0.0; // Total charge for the supermodule histo
2118 //printf("CH2d nbclusters %d, fNumberClusters %d, fNumberClustersf %d\n",nbclusters,fNumberClusters,fNumberClustersf);
2120 if(nbclusters < fNumberClusters) return;
2121 if(nbclusters > fNumberClustersf) return;
2124 // Normalize with the number of clusters
2125 Double_t normalizeCst = fRelativeScale;
2126 if(fNormalizeNbOfCluster) normalizeCst = normalizeCst*nbclusters;
2128 //printf("Number of groups in one detector %d\n",fCalibraMode->GetNfragZ(0)*fCalibraMode->GetNfragRphi(0));
2130 // See if the track goes through different zones
2131 for (Int_t k = 0; k < fCalibraMode->GetNfragZ(0)*fCalibraMode->GetNfragRphi(0); k++) {
2132 //printf("fAmpTotal %f for %d\n",fAmpTotal[k],k);
2133 if (fAmpTotal[k] > 0.0) {
2134 totalcharge += fAmpTotal[k];
2142 //printf("CH2d: nb %d, fd %d, calibration group %d, amplitude %f, detector %d\n",nb,fd,fCalibraMode->GetXbins(0),fAmpTotal[fd]/normalizeCst,fDetectorPreviousTrack);
2148 fEntriesCH[fCalibraMode->GetXbins(0)+fd]++;
2150 FillCH2d(fCalibraMode->GetXbins(0)+fd,fAmpTotal[fd]/normalizeCst);
2151 //fCH2d->Fill(fAmpTotal[fd]/normalizeCst,fCalibraMode->GetXbins(0)+fd+0.5);
2154 fCalibraVector->UpdateVectorCH(fDetectorPreviousTrack,fd,fAmpTotal[fd]/normalizeCst);
2158 if ((fAmpTotal[fd] > 0.0) &&
2159 (fAmpTotal[fd+1] > 0.0)) {
2160 // One of the two very big
2161 if (fAmpTotal[fd] > fProcent*fAmpTotal[fd+1]) {
2163 FillCH2d(fCalibraMode->GetXbins(0)+fd,fAmpTotal[fd]/normalizeCst);
2164 //fCH2d->Fill(fAmpTotal[fd]/normalizeCst,fCalibraMode->GetXbins(0)+fd+0.5);
2167 fCalibraVector->UpdateVectorCH(fDetectorPreviousTrack,fd,fAmpTotal[fd]/normalizeCst);
2170 fEntriesCH[fCalibraMode->GetXbins(0)+fd]++;
2172 if (fAmpTotal[fd+1] > fProcent*fAmpTotal[fd]) {
2174 FillCH2d(fCalibraMode->GetXbins(0)+fd+1,fAmpTotal[fd+1]/normalizeCst);
2175 //fCH2d->Fill(fAmpTotal[fd+1]/normalizeCst,fCalibraMode->GetXbins(0)+fd+1.5);
2178 fCalibraVector->UpdateVectorCH(fDetectorPreviousTrack,fd+1,fAmpTotal[fd+1]/normalizeCst);
2181 fEntriesCH[fCalibraMode->GetXbins(0)+fd+1]++;
2184 if (fCalibraMode->GetNfragZ(0) > 1) {
2185 if (fAmpTotal[fd] > 0.0) {
2186 if ((fd+fCalibraMode->GetNfragZ(0)) < (fCalibraMode->GetNfragZ(0)*fCalibraMode->GetNfragRphi(0))) {
2187 if (fAmpTotal[fd+fCalibraMode->GetNfragZ(0)] > 0.0) {
2188 // One of the two very big
2189 if (fAmpTotal[fd] > fProcent*fAmpTotal[fd+fCalibraMode->GetNfragZ(0)]) {
2191 FillCH2d(fCalibraMode->GetXbins(0)+fd,fAmpTotal[fd]/normalizeCst);
2192 //fCH2d->Fill(fAmpTotal[fd]/normalizeCst,fCalibraMode->GetXbins(0)+fd+0.5);
2195 fCalibraVector->UpdateVectorCH(fDetectorPreviousTrack,fd,fAmpTotal[fd]/normalizeCst);
2198 fEntriesCH[fCalibraMode->GetXbins(0)+fd]++;
2200 if (fAmpTotal[fd+fCalibraMode->GetNfragZ(0)] > fProcent*fAmpTotal[fd]) {
2202 FillCH2d(fCalibraMode->GetXbins(0)+fd+fCalibraMode->GetNfragZ(0),fAmpTotal[fd+fCalibraMode->GetNfragZ(0)]/normalizeCst);
2203 //fCH2d->Fill(fAmpTotal[fd+fCalibraMode->GetNfragZ(0)]/normalizeCst,fCalibraMode->GetXbins(0)+fd+fCalibraMode->GetNfragZ(0)+0.5);
2206 fEntriesCH[fCalibraMode->GetXbins(0)+fd+fCalibraMode->GetNfragZ(0)]++;
2208 fCalibraVector->UpdateVectorCH(fDetectorPreviousTrack,fd+fCalibraMode->GetNfragZ(0),fAmpTotal[fd+fCalibraMode->GetNfragZ(0)]/normalizeCst);
2219 //____________Offine tracking in the AliTRDtracker_____________________________
2220 void AliTRDCalibraFillHisto::FillTheInfoOfTheTrackPH()
2223 // For the offline tracking or mcm tracklets
2224 // This function will be called in the functions UpdateHistogram...
2225 // to fill the info of a track for the drift velocity calibration
2228 Int_t nb = 1; // Nombre de zones traversees 1, 2 ou plus de 3
2229 Int_t fd1 = -1; // Premiere zone non nulle
2230 Int_t fd2 = -1; // Deuxieme zone non nulle
2231 Int_t k1 = -1; // Debut de la premiere zone
2232 Int_t k2 = -1; // Debut de la seconde zone
2233 Int_t nbclusters = 0; // number of clusters
2237 // See if the track goes through different zones
2238 for (Int_t k = 0; k < fTimeMax; k++) {
2239 if (fPHValue[k] > 0.0) {
2245 if (fPHPlace[k] != fd1) {
2251 if (fPHPlace[k] != fd2) {
2258 // See if noise before and after
2259 if(fMaxCluster > 0) {
2260 if(fPHValue[0] > fMaxCluster) return;
2261 if(fTimeMax > fNbMaxCluster) {
2262 for(Int_t k = (fTimeMax-fNbMaxCluster); k < fTimeMax; k++){
2263 if(fPHValue[k] > fMaxCluster) return;
2268 //printf("nbclusters %d, low limit %d, high limit %d\n",nbclusters,fNumberClusters,fNumberClustersf);
2270 if(nbclusters < fNumberClusters) return;
2271 if(nbclusters > fNumberClustersf) return;
2277 for (Int_t i = 0; i < fTimeMax; i++) {
2279 if(fFillWithZero) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd1)+0.5,(Float_t) fPHValue[i]);
2281 if(((Float_t) fPHValue[i] > 0.0)) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd1)+0.5,(Float_t) fPHValue[i]);
2283 //printf("Fill the time bin %d with %f\n",i,fPHValue[i]);
2286 if(fFillWithZero) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd1,i,fPHValue[i]);
2288 if(((Float_t) fPHValue[i] > 0.0)) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd1,i,fPHValue[i]);
2294 if ((fd1 == fd2+1) ||
2296 // One of the two fast all the think
2297 if (k2 > (k1+fDifference)) {
2298 //we choose to fill the fd1 with all the values
2300 for (Int_t i = 0; i < fTimeMax; i++) {
2302 if(fFillWithZero) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd1)+0.5,(Float_t) fPHValue[i]);
2304 if(((Float_t) fPHValue[i] > 0.0)) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd1)+0.5,(Float_t) fPHValue[i]);
2308 if(fFillWithZero) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd1,i,fPHValue[i]);
2310 if(((Float_t) fPHValue[i] > 0.0)) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd1,i,fPHValue[i]);
2315 if ((k2+fDifference) < fTimeMax) {
2316 //we choose to fill the fd2 with all the values
2318 for (Int_t i = 0; i < fTimeMax; i++) {
2320 if(fFillWithZero) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd2)+0.5,(Float_t) fPHValue[i]);
2322 if(((Float_t) fPHValue[i] > 0.0)) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd2)+0.5,(Float_t) fPHValue[i]);
2326 if(fFillWithZero) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd2,i,fPHValue[i]);
2328 if(((Float_t) fPHValue[i] > 0.0)) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd2,i,fPHValue[i]);
2334 // Two zones voisines sinon rien!
2335 if (fCalibraMode->GetNfragZ(1) > 1) {
2337 if ((fd1+fCalibraMode->GetNfragZ(1)) < (fCalibraMode->GetNfragZ(1)*fCalibraMode->GetNfragRphi(1))) {
2338 if (fd2 == (fd1+fCalibraMode->GetNfragZ(1))) {
2339 // One of the two fast all the think
2340 if (k2 > (k1+fDifference)) {
2341 //we choose to fill the fd1 with all the values
2343 for (Int_t i = 0; i < fTimeMax; i++) {
2345 if(fFillWithZero) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd1)+0.5,(Float_t) fPHValue[i]);
2347 if(((Float_t) fPHValue[i] > 0.0)) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd1)+0.5,(Float_t) fPHValue[i]);
2351 if(fFillWithZero) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd1,i,fPHValue[i]);
2353 if(((Float_t) fPHValue[i] > 0.0)) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd1,i,fPHValue[i]);
2358 if ((k2+fDifference) < fTimeMax) {
2359 //we choose to fill the fd2 with all the values
2361 for (Int_t i = 0; i < fTimeMax; i++) {
2363 if(fFillWithZero) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd2)+0.5,(Float_t) fPHValue[i]);
2365 if(((Float_t) fPHValue[i] > 0.0)) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd2)+0.5,(Float_t) fPHValue[i]);
2369 if(fFillWithZero) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd2,i,fPHValue[i]);
2371 if(((Float_t) fPHValue[i] > 0.0)) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd2,i,fPHValue[i]);
2378 // Two zones voisines sinon rien!
2380 if ((fd1 - fCalibraMode->GetNfragZ(1)) >= 0) {
2381 if (fd2 == (fd1 - fCalibraMode->GetNfragZ(1))) {
2382 // One of the two fast all the think
2383 if (k2 > (k1 + fDifference)) {
2384 //we choose to fill the fd1 with all the values
2386 for (Int_t i = 0; i < fTimeMax; i++) {
2388 if(fFillWithZero) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd1)+0.5,(Float_t) fPHValue[i]);
2390 if(((Float_t) fPHValue[i] > 0.0)) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd1)+0.5,(Float_t) fPHValue[i]);
2394 if(fFillWithZero) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd1,i,fPHValue[i]);
2396 if(((Float_t) fPHValue[i] > 0.0)) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd1,i,fPHValue[i]);
2401 if ((k2+fDifference) < fTimeMax) {
2402 //we choose to fill the fd2 with all the values
2404 for (Int_t i = 0; i < fTimeMax; i++) {
2406 if(fFillWithZero) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd2)+0.5,(Float_t) fPHValue[i]);
2408 if(((Float_t) fPHValue[i] > 0.0)) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd2)+0.5,(Float_t) fPHValue[i]);
2412 if(fFillWithZero) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd2,i,fPHValue[i]);
2414 if(((Float_t) fPHValue[i] > 0.0)) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd2,i,fPHValue[i]);
2426 //////////////////////////////////////////////////////////////////////////////////////////
2427 // DAQ process functions
2428 /////////////////////////////////////////////////////////////////////////////////////////
2429 //_____________________________________________________________________
2430 Int_t AliTRDCalibraFillHisto::ProcessEventDAQ(AliTRDrawStreamBase *rawStream, Bool_t nocheck)
2433 // Event Processing loop - AliTRDrawStreamBase
2434 // TestBeam 2007 version
2435 // 0 timebin problem
2438 // Same algorithm as TestBeam but different reader
2441 rawStream->SetSharedPadReadout(kFALSE);
2443 Int_t withInput = 1;
2445 Double_t phvalue[16][144][36];
2446 for(Int_t k = 0; k < 36; k++){
2447 for(Int_t j = 0; j < 16; j++){
2448 for(Int_t c = 0; c < 144; c++){
2449 phvalue[j][c][k] = 0.0;
2454 fDetectorPreviousTrack = -1;
2457 Int_t nbtimebin = 0;
2458 Int_t baseline = 10;
2459 //printf("------------Detector\n");
2465 while (rawStream->Next()) {
2467 Int_t idetector = rawStream->GetDet(); // current detector
2468 Int_t imcm = rawStream->GetMCM(); // current MCM
2469 Int_t irob = rawStream->GetROB(); // current ROB
2471 //printf("Detector %d\n",idetector);
2473 if((fDetectorPreviousTrack != idetector) && (fDetectorPreviousTrack != -1)){
2476 withInput = TMath::Max(FillDAQ(phvalue),withInput);
2480 for(Int_t k = 0; k < 36; k++){
2481 for(Int_t j = 0; j < 16; j++){
2482 for(Int_t c = 0; c < 144; c++){
2483 phvalue[j][c][k] = 0.0;
2489 fDetectorPreviousTrack = idetector;
2490 fMCMPrevious = imcm;
2491 fROBPrevious = irob;
2493 nbtimebin = rawStream->GetNumberOfTimeBins(); // number of time bins read from data
2494 if(nbtimebin == 0) return 0;
2495 if((fTimeMax != 0) && (nbtimebin != fTimeMax)) return 0;
2496 fTimeMax = nbtimebin;
2498 //baseline = rawStream->GetCommonAdditive(); // common additive baseline
2499 fNumberClustersf = fTimeMax;
2500 fNumberClusters = (Int_t)(fNumberClustersProcent*fTimeMax);
2503 Int_t *signal = rawStream->GetSignals(); // current ADC signal
2504 Int_t col = rawStream->GetCol();
2505 Int_t row = rawStream->GetRow();
2508 // printf("detector %d, signal[0] %d, signal[1] %d, signal[2] %d, baseline %d\n",idetector,signal[0],signal[1],signal[2], baseline);
2511 for(Int_t itime = 0; itime < nbtimebin; itime++){
2512 phvalue[row][col][itime] = signal[itime]-baseline;
2516 // fill the last one
2517 if(fDetectorPreviousTrack != -1){
2520 withInput = TMath::Max(FillDAQ(phvalue),withInput);
2523 for(Int_t k = 0; k < 36; k++){
2524 for(Int_t j = 0; j < 16; j++){
2525 for(Int_t c = 0; c < 144; c++){
2526 phvalue[j][c][k] = 0.0;
2535 while (rawStream->Next()) { //iddetecte
2537 Int_t idetector = rawStream->GetDet(); // current detector
2538 Int_t imcm = rawStream->GetMCM(); // current MCM
2539 Int_t irob = rawStream->GetROB(); // current ROB
2541 //printf("Detector %d\n",idetector);
2543 if((fDetectorPreviousTrack != idetector) && (fDetectorPreviousTrack != -1)){
2546 withInput = TMath::Max(FillDAQ(phvalue),withInput);
2549 for(Int_t k = 0; k < 36; k++){
2550 for(Int_t j = 0; j < 16; j++){
2551 for(Int_t c = 0; c < 144; c++){
2552 phvalue[j][c][k] = 0.0;
2558 fDetectorPreviousTrack = idetector;
2559 fMCMPrevious = imcm;
2560 fROBPrevious = irob;
2562 //baseline = rawStream->GetCommonAdditive(); // common baseline
2564 fTimeMax = rawStream->GetNumberOfTimeBins(); // number of time bins read from data
2565 fNumberClustersf = fTimeMax;
2566 fNumberClusters = (Int_t)(fNumberClustersProcent*fTimeMax);
2567 Int_t *signal = rawStream->GetSignals(); // current ADC signal
2568 Int_t col = rawStream->GetCol();
2569 Int_t row = rawStream->GetRow();
2572 //printf("detector %d, signal[0] %d, signal[1] %d, signal[2] %d, baseline %d\n",idetector,signal[0],signal[1],signal[2], baseline);
2574 for(Int_t itime = 0; itime < fTimeMax; itime++){
2575 phvalue[row][col][itime] = signal[itime]-baseline;
2576 /*if(phvalue[row][col][itime] >= 20) {
2577 printf("----------> phvalue[%d][%d][%d] %d baseline %d \n",
2587 // fill the last one
2588 if(fDetectorPreviousTrack != -1){
2591 withInput = TMath::Max(FillDAQ(phvalue),withInput);
2594 for(Int_t k = 0; k < 36; k++){
2595 for(Int_t j = 0; j < 16; j++){
2596 for(Int_t c = 0; c < 144; c++){
2597 phvalue[j][c][k] = 0.0;
2607 //_____________________________________________________________________
2608 Int_t AliTRDCalibraFillHisto::ProcessEventDAQ(AliRawReader *rawReader, Bool_t nocheck)
2611 // Event processing loop - AliRawReader
2612 // Testbeam 2007 version
2615 AliTRDrawStreamBase rawStream(rawReader);
2617 rawReader->Select("TRD");
2619 return ProcessEventDAQ(&rawStream, nocheck);
2622 //_________________________________________________________________________
2623 Int_t AliTRDCalibraFillHisto::ProcessEventDAQ(
2625 const eventHeaderStruct *event,
2628 const eventHeaderStruct* /*event*/,
2635 // process date event
2636 // Testbeam 2007 version
2639 AliRawReader *rawReader = new AliRawReaderDate((void*)event);
2640 Int_t result=ProcessEventDAQ(rawReader, nocheck);
2644 Fatal("AliTRDCalibraFillHisto", "this class was compiled without DATE");
2649 //_____________________________________________________________________
2650 Int_t AliTRDCalibraFillHisto::ProcessEventDAQ2(AliRawReader *rawReader)
2653 // Event Processing loop - AliTRDrawFastStream
2655 // 0 timebin problem
2658 // Same algorithm as TestBeam but different reader
2661 // AliTRDrawFastStream *rawStream = AliTRDrawFastStream::GetRawStream(rawReader);
2662 AliTRDrawFastStream *rawStream = new AliTRDrawFastStream(rawReader);
2663 rawStream->SetNoErrorWarning();
2664 rawStream->SetSharedPadReadout(kFALSE);
2666 AliTRDdigitsManager *digitsManager = new AliTRDdigitsManager(kTRUE);
2667 digitsManager->CreateArrays();
2669 Int_t withInput = 1;
2671 Double_t phvalue[16][144][36];
2672 for(Int_t k = 0; k < 36; k++){
2673 for(Int_t j = 0; j < 16; j++){
2674 for(Int_t c = 0; c < 144; c++){
2675 phvalue[j][c][k] = 0.0;
2680 fDetectorPreviousTrack = -1;
2684 Int_t nbtimebin = 0;
2685 Int_t baseline = 10;
2691 while ((det = rawStream->NextChamber(digitsManager, NULL, NULL)) >= 0) { //idetector
2693 if (digitsManager->GetIndexes(det)->HasEntry()) {//QA
2694 // printf("there is ADC data on this chamber!\n");
2696 AliTRDarrayADC *digits = (AliTRDarrayADC *) digitsManager->GetDigits(det); //mod
2697 if (digits->HasData()) { //array
2699 AliTRDSignalIndex *indexes = digitsManager->GetIndexes(det);
2700 if (indexes->IsAllocated() == kFALSE) {
2701 AliError("Indexes do not exist!");
2706 indexes->ResetCounters();
2708 while (indexes->NextRCIndex(iRow, iCol)) { //column,row
2709 //printf(" det %d \t row %d \t col %d \t digit\n",det,iRow,iCol);
2710 //while (rawStream->Next()) {
2712 Int_t idetector = det; // current detector
2713 //Int_t imcm = rawStream->GetMCM(); // current MCM
2714 //Int_t irob = rawStream->GetROB(); // current ROB
2717 if((fDetectorPreviousTrack != idetector) && (fDetectorPreviousTrack != -1)) {
2719 withInput = TMath::Max(FillDAQ(phvalue),withInput);
2722 for(Int_t k = 0; k < 36; k++){
2723 for(Int_t j = 0; j < 16; j++){
2724 for(Int_t c = 0; c < 144; c++){
2725 phvalue[j][c][k] = 0.0;
2731 fDetectorPreviousTrack = idetector;
2732 //fMCMPrevious = imcm;
2733 //fROBPrevious = irob;
2735 // nbtimebin = rawStream->GetNumberOfTimeBins(); // number of time bins read from data
2736 AliTRDdigitsParam *digitParam = (AliTRDdigitsParam *)digitsManager->GetDigitsParam();
2737 nbtimebin = digitParam->GetNTimeBins(det); // number of time bins read from data
2738 baseline = digitParam->GetADCbaseline(det); // baseline
2740 if(nbtimebin == 0) return 0;
2741 if((fTimeMax != 0) && (nbtimebin != fTimeMax)) return 0;
2742 fTimeMax = nbtimebin;
2744 fNumberClustersf = fTimeMax;
2745 fNumberClusters = (Int_t)(fNumberClustersProcent*fTimeMax);
2748 for(Int_t itime = 0; itime < nbtimebin; itime++) {
2749 // phvalue[row][col][itime] = signal[itime]-baseline;
2750 phvalue[iRow][iCol][itime] = (Short_t)(digits->GetData(iRow,iCol,itime) - baseline);
2751 /*if(phvalue[iRow][iCol][itime] >= 20) {
2752 printf("----------> phvalue[%d][%d][%d] %d baseline %d \n",
2756 (Short_t)(digits->GetData(iRow,iCol,itime)),
2763 // fill the last one
2764 if(fDetectorPreviousTrack != -1){
2767 withInput = TMath::Max(FillDAQ(phvalue),withInput);
2768 // printf("\n ---> withinput %d\n\n",withInput);
2770 for(Int_t k = 0; k < 36; k++){
2771 for(Int_t j = 0; j < 16; j++){
2772 for(Int_t c = 0; c < 144; c++){
2773 phvalue[j][c][k] = 0.0;
2781 digitsManager->ClearArrays(det);
2783 delete digitsManager;
2788 //_____________________________________________________________________
2789 Int_t AliTRDCalibraFillHisto::ProcessEventDAQ3(AliRawReader *rawReader)
2792 // Event Processing loop - AliTRDrawStream
2794 // 0 timebin problem
2797 // Same algorithm as TestBeam but different reader
2800 // AliTRDrawFastStream *rawStream = AliTRDrawFastStream::GetRawStream(rawReader);
2801 AliTRDrawStream *rawStream = new AliTRDrawStream(rawReader);
2802 rawStream->SetNoErrorWarning();
2803 rawStream->SetSharedPadReadout(kFALSE);
2805 AliTRDdigitsManager *digitsManager = new AliTRDdigitsManager(kTRUE);
2806 digitsManager->CreateArrays();
2808 Int_t withInput = 1;
2810 Double_t phvalue[16][144][36];
2811 for(Int_t k = 0; k < 36; k++){
2812 for(Int_t j = 0; j < 16; j++){
2813 for(Int_t c = 0; c < 144; c++){
2814 phvalue[j][c][k] = 0.0;
2819 fDetectorPreviousTrack = -1;
2823 Int_t nbtimebin = 0;
2824 Int_t baseline = 10;
2830 while ((det = rawStream->NextChamber(digitsManager, NULL, NULL)) >= 0) { //idetector
2832 if (digitsManager->GetIndexes(det)->HasEntry()) {//QA
2833 // printf("there is ADC data on this chamber!\n");
2835 AliTRDarrayADC *digits = (AliTRDarrayADC *) digitsManager->GetDigits(det); //mod
2836 if (digits->HasData()) { //array
2838 AliTRDSignalIndex *indexes = digitsManager->GetIndexes(det);
2839 if (indexes->IsAllocated() == kFALSE) {
2840 AliError("Indexes do not exist!");
2845 indexes->ResetCounters();
2847 while (indexes->NextRCIndex(iRow, iCol)) { //column,row
2848 //printf(" det %d \t row %d \t col %d \t digit\n",det,iRow,iCol);
2849 //while (rawStream->Next()) {
2851 Int_t idetector = det; // current detector
2852 //Int_t imcm = rawStream->GetMCM(); // current MCM
2853 //Int_t irob = rawStream->GetROB(); // current ROB
2856 if((fDetectorPreviousTrack != idetector) && (fDetectorPreviousTrack != -1)) {
2858 withInput = TMath::Max(FillDAQ(phvalue),withInput);
2861 for(Int_t k = 0; k < 36; k++){
2862 for(Int_t j = 0; j < 16; j++){
2863 for(Int_t c = 0; c < 144; c++){
2864 phvalue[j][c][k] = 0.0;
2870 fDetectorPreviousTrack = idetector;
2871 //fMCMPrevious = imcm;
2872 //fROBPrevious = irob;
2874 // nbtimebin = rawStream->GetNumberOfTimeBins(); // number of time bins read from data
2875 AliTRDdigitsParam *digitParam = (AliTRDdigitsParam *)digitsManager->GetDigitsParam();
2876 nbtimebin = digitParam->GetNTimeBins(det); // number of time bins read from data
2877 baseline = digitParam->GetADCbaseline(det); // baseline
2879 if(nbtimebin == 0) return 0;
2880 if((fTimeMax != 0) && (nbtimebin != fTimeMax)) return 0;
2881 fTimeMax = nbtimebin;
2883 fNumberClustersf = fTimeMax;
2884 fNumberClusters = (Int_t)(fNumberClustersProcent*fTimeMax);
2887 for(Int_t itime = 0; itime < nbtimebin; itime++) {
2888 // phvalue[row][col][itime] = signal[itime]-baseline;
2889 phvalue[iRow][iCol][itime] = (Short_t)(digits->GetData(iRow,iCol,itime) - baseline);
2890 /*if(phvalue[iRow][iCol][itime] >= 20) {
2891 printf("----------> phvalue[%d][%d][%d] %d baseline %d \n",
2895 (Short_t)(digits->GetData(iRow,iCol,itime)),
2902 // fill the last one
2903 if(fDetectorPreviousTrack != -1){
2906 withInput = TMath::Max(FillDAQ(phvalue),withInput);
2907 // printf("\n ---> withinput %d\n\n",withInput);
2909 for(Int_t k = 0; k < 36; k++){
2910 for(Int_t j = 0; j < 16; j++){
2911 for(Int_t c = 0; c < 144; c++){
2912 phvalue[j][c][k] = 0.0;
2920 digitsManager->ClearArrays(det);
2922 delete digitsManager;
2927 //_____________________________________________________________________
2928 //////////////////////////////////////////////////////////////////////////////
2929 // Routine inside the DAQ process
2930 /////////////////////////////////////////////////////////////////////////////
2931 //_______________________________________________________________________
2932 Int_t AliTRDCalibraFillHisto::FillDAQ(Double_t phvalue[16][144][36]){
2935 // Look for the maximum by collapsing over the time
2936 // Sum over four pad col and two pad row
2942 Int_t idect = fDetectorPreviousTrack;
2943 //printf("Enter Detector %d\n",fDetectorPreviousTrack);
2945 for(Int_t tb = 0; tb < 36; tb++){
2949 //fGoodTracklet = kTRUE;
2950 //fDetectorPreviousTrack = 0;
2953 ///////////////////////////
2955 /////////////////////////
2959 Double_t integralMax = -1;
2961 for (Int_t ir = 1; ir <= 15; ir++)
2963 for (Int_t ic = 2; ic <= 142; ic++)
2965 Double_t integral = 0;
2966 for (Int_t ishiftR = 0; ishiftR < fNumberRowDAQ; ishiftR++)
2968 for (Int_t ishiftC = -fNumberColDAQ; ishiftC < fNumberColDAQ; ishiftC++)
2970 if (ir + ishiftR >= 1 && ir + ishiftR <= 16 &&
2971 ic + ishiftC >= 1 && ic + ishiftC <= 144)
2974 for(Int_t tb = 0; tb< fTimeMax; tb++){
2975 integral += phvalue[ir + ishiftR-1][ic + ishiftC-1][tb];
2980 if (integralMax < integral)
2984 integralMax = integral;
2986 } // check max integral
2990 // printf("imaxRow %d, imaxCol %d, fTimeMax %d, integralMax %f\n",imaxRow,imaxCol,fTimeMax, integralMax);
2991 //if((imaxRow == 0) || (imaxRow >= 15) || (imaxCol <= 3) || (imaxCol >= 140)) {
2996 if(((imaxRow + fNumberRowDAQ) > 16) || (imaxRow == 0) || ((imaxCol - fNumberColDAQ) <= 1) || ((imaxCol + fNumberColDAQ) >= 144)) {
3000 //CheckGoodTrackletV0(fDetectorPreviousTrack,imaxRow,imaxCol);
3001 //if(!fGoodTracklet) used = 1;;
3003 // /////////////////////////////////////////////////////
3004 // sum ober 2 row and 4 pad cols for each time bins
3005 // ////////////////////////////////////////////////////
3009 for (Int_t ishiftR = 0; ishiftR < fNumberRowDAQ; ishiftR++)
3011 for (Int_t ishiftC = -fNumberColDAQ; ishiftC < fNumberColDAQ; ishiftC++)
3013 if (imaxRow + ishiftR >= 1 && imaxRow + ishiftR <= 16 &&
3014 imaxCol + ishiftC >= 1 && imaxCol + ishiftC <= 144)
3016 for(Int_t it = 0; it < fTimeMax; it++){
3017 sum[it] += phvalue[imaxRow + ishiftR-1][imaxCol + ishiftC-1][it];
3024 Double_t sumcharge = 0.0;
3025 for(Int_t it = 0; it < fTimeMax; it++){
3026 sumcharge += sum[it];
3027 if(sum[it] > fThresholdClustersDAQ) nbcl++;
3031 /////////////////////////////////////////////////////////
3033 ////////////////////////////////////////////////////////
3034 if(fDebugLevel > 0){
3035 if ( !fDebugStreamer ) {
3037 TDirectory *backup = gDirectory;
3038 fDebugStreamer = new TTreeSRedirector("TRDdebugCalibraFill.root");
3039 if ( backup ) backup->cd(); //we don't want to be cd'd to the debug streamer
3042 Double_t amph0 = sum[0];
3043 Double_t amphlast = sum[fTimeMax-1];
3044 Double_t rms = TMath::RMS(fTimeMax,sum);
3045 Int_t goodtracklet = (Int_t) fGoodTracklet;
3046 for(Int_t it = 0; it < fTimeMax; it++){
3047 Double_t clustera = sum[it];
3049 (* fDebugStreamer) << "FillDAQa"<<
3050 "ampTotal="<<sumcharge<<
3053 "detector="<<idect<<
3055 "amphlast="<<amphlast<<
3056 "goodtracklet="<<goodtracklet<<
3057 "clustera="<<clustera<<
3065 ////////////////////////////////////////////////////////
3067 ///////////////////////////////////////////////////////
3068 //printf("fNumberClusters %d, fNumberClustersf %d\n",fNumberClusters,fNumberClustersf);
3069 if(sum[0] > 100.0) used = 1;
3070 if(nbcl < fNumberClusters) used = 1;
3071 if(nbcl > fNumberClustersf) used = 1;
3073 //if(fDetectorPreviousTrack == 15){
3074 // printf("rms %f and first time bin %f\n",TMath::RMS(fTimeMax,sum),sum[0]);
3076 //if((TMath::RMS(fTimeMax,sum) <= 10.0) && (sum[0] > 200.0)) return 1;
3078 for(Int_t it = 0; it < fTimeMax; it++){
3079 if(fFillWithZero) UpdateDAQ(fDetectorPreviousTrack,0,0,it,sum[it],fTimeMax);
3081 if(sum[it] > 0.0) UpdateDAQ(fDetectorPreviousTrack,0,0,it,sum[it],fTimeMax);
3083 //if(fFillWithZero) UpdateDAQ(0,0,0,it,sum[it],fTimeMax);
3085 // if(sum[it] > 0.0) UpdateDAQ(0,0,0,it,sum[it],fTimeMax);
3090 //((TH2I *)GetCH2d()->Fill(sumcharge/30.0,fDetectorPreviousTrack));
3092 //printf("Pass Detector %d\n",fDetectorPreviousTrack);
3099 //____________Online trackling in AliTRDtrigger________________________________
3100 Bool_t AliTRDCalibraFillHisto::UpdateDAQ(Int_t det, Int_t /*row*/, Int_t /*col*/, Int_t timebin, Float_t signal, Int_t nbtimebins)
3104 // Fill a simple average pulse height
3108 ((TProfile2D *)GetPH2d(nbtimebins,fSf))->Fill((Float_t) timebin/fSf,det+0.5,(Float_t) signal);
3114 //____________Write_____________________________________________________
3115 //_____________________________________________________________________
3116 void AliTRDCalibraFillHisto::Write2d(const Char_t *filename, Bool_t append)
3119 // Write infos to file
3123 if ( fDebugStreamer ) {
3124 delete fDebugStreamer;
3125 fDebugStreamer = 0x0;
3128 AliInfo(Form("Numbertrack: %d Numberusedch[0]: %d, Numberusedch[1]: %d Numberusedph[0]: %d, Numberusedph[1]: %d"
3133 ,fNumberUsedPh[1]));
3135 TDirectory *backup = gDirectory;
3141 option = "recreate";
3143 TFile f(filename,option.Data());
3145 TStopwatch stopwatch;
3148 f.WriteTObject(fCalibraVector);
3153 f.WriteTObject(fCH2d);
3158 f.WriteTObject(fPH2d);
3163 f.WriteTObject(fPRF2d);
3166 if(fLinearFitterOn){
3167 if(fLinearFitterDebugOn) AnalyseLinearFitter();
3168 f.WriteTObject(fLinearVdriftFit);
3173 if ( backup ) backup->cd();
3175 AliInfo(Form("Execution time Write2d: R:%.2fs C:%.2fs"
3176 ,stopwatch.RealTime(),stopwatch.CpuTime()));
3178 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
3180 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
3181 //___________________________________________probe the histos__________________________________________________
3182 Double_t *AliTRDCalibraFillHisto::StatH(TH2 *h, Int_t i)
3185 // Check the number of stats in h, 0 is TH2I 1 is TProfile2D
3186 // debug mode with 2 for TH2I and 3 for TProfile2D
3187 // It gives a pointer to a Double_t[7] with the info following...
3188 // [0] : number of calibration groups with entries
3189 // [1] : minimal number of entries found
3190 // [2] : calibration group number of the min
3191 // [3] : maximal number of entries found
3192 // [4] : calibration group number of the max
3193 // [5] : mean number of entries found
3194 // [6] : mean relative error
3197 Double_t *info = new Double_t[7];
3199 // Number of Xbins (detectors or groups of pads)
3200 Int_t nbins = h->GetNbinsY(); //number of calibration groups
3201 Int_t nxbins = h->GetNbinsX(); //number of bins per histo
3204 Double_t nbwe = 0; //number of calibration groups with entries
3205 Double_t minentries = 0; //minimal number of entries found
3206 Double_t maxentries = 0; //maximal number of entries found
3207 Double_t placemin = 0; //calibration group number of the min
3208 Double_t placemax = -1; //calibration group number of the max
3209 Double_t meanstats = 0.0; //mean number of entries over the calibration group with at least ome entry
3210 Double_t meanrelativerror = 0.0; //mean relativ error in the TProfile2D
3212 Double_t counter = 0;
3215 TH1F *nbEntries = 0x0;//distribution of the number of entries
3216 TH1F *nbEntriesPerGroup = 0x0;//Number of entries per group
3217 TProfile *nbEntriesPerSp = 0x0;//Number of entries for one supermodule
3219 // Beginning of the loop over the calibration groups
3220 for (Int_t idect = 0; idect < nbins; idect++) {
3222 TH1I *projch = (TH1I *) h->ProjectionX("projch",idect+1,idect+1,(Option_t *)"e");
3223 projch->SetDirectory(0);
3225 // Number of entries for this calibration group
3226 Double_t nentries = 0.0;
3228 for (Int_t k = 0; k < nxbins; k++) {
3229 nentries += h->GetBinContent(h->GetBin(k+1,idect+1));
3233 for (Int_t k = 0; k < nxbins; k++) {
3234 nentries += ((TProfile2D *)h)->GetBinEntries(h->GetBin(k+1,idect+1));
3235 if(h->GetBinContent(h->GetBin(k+1,idect+1)) != 0) {
3236 meanrelativerror += (h->GetBinError(h->GetBin(k+1,idect+1))/(TMath::Abs(h->GetBinContent(h->GetBin(k+1,idect+1)))));
3244 if((!((Bool_t)nbEntries)) && (nentries > 0)){
3245 nbEntries = new TH1F("Number of entries","Number of entries"
3246 ,100,(Int_t)nentries/2,nentries*2);
3247 nbEntries->SetDirectory(0);
3248 nbEntriesPerGroup = new TH1F("Number of entries per group","Number of entries per group"
3250 nbEntriesPerGroup->SetDirectory(0);
3251 nbEntriesPerSp = new TProfile("Number of entries per supermodule","Number of entries per supermodule"
3252 ,(Int_t)(nbins/18),0,(Int_t)(nbins/18));
3253 nbEntriesPerSp->SetDirectory(0);
3256 if(nentries > 0) nbEntries->Fill(nentries);
3257 nbEntriesPerGroup->Fill(idect+0.5,nentries);
3258 nbEntriesPerSp->Fill((idect%((Int_t)(nbins/18)))+0.5,nentries);
3263 if(nentries > maxentries){
3264 maxentries = nentries;
3268 minentries = nentries;
3270 if(nentries < minentries){
3271 minentries = nentries;
3277 meanstats += nentries;
3279 }//calibration groups loop
3281 if(nbwe > 0) meanstats /= nbwe;
3282 if(counter > 0) meanrelativerror /= counter;
3284 AliInfo(Form("There are %f calibration groups with entries",nbwe));
3285 AliInfo(Form("The minimum number of entries is %f for the group %f",minentries,placemin));
3286 AliInfo(Form("The maximum number of entries is %f for the group %f",maxentries,placemax));
3287 AliInfo(Form("The mean number of entries is %f",meanstats));
3288 if((i%2) == 1) AliInfo(Form("The mean relative error is %f",meanrelativerror));
3291 info[1] = minentries;
3293 info[3] = maxentries;
3295 info[5] = meanstats;
3296 info[6] = meanrelativerror;
3299 gStyle->SetPalette(1);
3300 gStyle->SetOptStat(1111);
3301 gStyle->SetPadBorderMode(0);
3302 gStyle->SetCanvasColor(10);
3303 gStyle->SetPadLeftMargin(0.13);
3304 gStyle->SetPadRightMargin(0.01);
3305 TCanvas *stat = new TCanvas("stat","",50,50,600,800);
3308 nbEntries->Draw("");
3310 nbEntriesPerSp->SetStats(0);
3311 nbEntriesPerSp->Draw("");
3312 TCanvas *stat1 = new TCanvas("stat1","",50,50,600,800);
3314 nbEntriesPerGroup->SetStats(0);
3315 nbEntriesPerGroup->Draw("");
3321 //____________________________________________________________________________
3322 Double_t *AliTRDCalibraFillHisto::GetMeanMedianRMSNumberCH()
3325 // Return a Int_t[4] with:
3326 // 0 Mean number of entries
3327 // 1 median of number of entries
3328 // 2 rms of number of entries
3329 // 3 number of group with entries
3332 Double_t *stat = new Double_t[4];
3335 Int_t nbofgroups = CalculateTotalNumberOfBins(0);
3336 Double_t *weight = new Double_t[nbofgroups];
3337 Int_t *nonul = new Int_t[nbofgroups];
3339 for(Int_t k = 0; k < nbofgroups; k++){
3340 if(fEntriesCH[k] > 0) {
3342 nonul[(Int_t)stat[3]] = fEntriesCH[k];
3345 else weight[k] = 0.0;
3347 stat[0] = TMath::Mean(nbofgroups,fEntriesCH,weight);
3348 stat[1] = TMath::Median(nbofgroups,fEntriesCH,weight);
3349 stat[2] = TMath::RMS((Int_t)stat[3],nonul);
3354 //____________________________________________________________________________
3355 Double_t *AliTRDCalibraFillHisto::GetMeanMedianRMSNumberLinearFitter() const
3358 // Return a Int_t[4] with:
3359 // 0 Mean number of entries
3360 // 1 median of number of entries
3361 // 2 rms of number of entries
3362 // 3 number of group with entries
3365 Double_t *stat = new Double_t[4];
3368 Int_t nbofgroups = 540;
3369 Double_t *weight = new Double_t[nbofgroups];
3370 Int_t *nonul = new Int_t[nbofgroups];
3372 for(Int_t k = 0; k < nbofgroups; k++){
3373 if(fEntriesLinearFitter[k] > 0) {
3375 nonul[(Int_t) stat[3]] = fEntriesLinearFitter[k];
3378 else weight[k] = 0.0;
3380 stat[0] = TMath::Mean(nbofgroups,fEntriesLinearFitter,weight);
3381 stat[1] = TMath::Median(nbofgroups,fEntriesLinearFitter,weight);
3382 stat[2] = TMath::RMS((Int_t)stat[3],nonul);
3387 //////////////////////////////////////////////////////////////////////////////////////
3389 //////////////////////////////////////////////////////////////////////////////////////
3390 //_____________________________________________________________________________
3391 void AliTRDCalibraFillHisto::CreatePRF2d(Int_t nn)
3394 // Create the 2D histos: here we have 2*fNgroupprf bins in tnp of 0.2 amplitude each
3395 // If fNgroupprf is zero then no binning in tnp
3399 name += fCalibraMode->GetNz(2);
3401 name += fCalibraMode->GetNrphi(2);
3405 if(fNgroupprf != 0){
3407 fPRF2d = new TProfile2D("PRF2d",(const Char_t *) name
3408 ,2*fNgroupprf*fNumberBinPRF,-3.0*fNgroupprf,3.0*fNgroupprf,nn,0,nn);
3409 fPRF2d->SetYTitle("Det/pad groups");
3410 fPRF2d->SetXTitle("Position x/W [pad width units]");
3411 fPRF2d->SetZTitle("Q_{i}/Q_{total}");
3412 fPRF2d->SetStats(0);
3415 fPRF2d = new TProfile2D("PRF2d",(const Char_t *) name
3416 ,fNumberBinPRF,-1.5,1.5,nn,0,nn);
3417 fPRF2d->SetYTitle("Det/pad groups");
3418 fPRF2d->SetXTitle("Position x/W [pad width units]");
3419 fPRF2d->SetZTitle("Q_{i}/Q_{total}");
3420 fPRF2d->SetStats(0);
3425 //_____________________________________________________________________________
3426 void AliTRDCalibraFillHisto::CreatePH2d(Int_t nn)
3429 // Create the 2D histos
3432 TString name("Ver");
3433 name += fVersionVdriftUsed;
3435 name += fSubVersionVdriftUsed;
3437 name += fCalibraMode->GetNz(1);
3439 name += fCalibraMode->GetNrphi(1);
3441 fPH2d = new TProfile2D("PH2d",(const Char_t *) name
3442 ,fTimeMax,-0.5/fSf,(Float_t) (fTimeMax-0.5)/fSf
3444 fPH2d->SetYTitle("Det/pad groups");
3445 fPH2d->SetXTitle("time [#mus]");
3446 fPH2d->SetZTitle("<PH> [a.u.]");
3450 //_____________________________________________________________________________
3451 void AliTRDCalibraFillHisto::CreateCH2d(Int_t nn)
3454 // Create the 2D histos
3457 TString name("Ver");
3458 name += fVersionGainUsed;
3460 name += fSubVersionGainUsed;
3462 name += fCalibraMode->GetNz(0);
3464 name += fCalibraMode->GetNrphi(0);
3466 fCH2d = new TH2I("CH2d",(const Char_t *) name
3467 ,fNumberBinCharge,0,300,nn,0,nn);
3468 fCH2d->SetYTitle("Det/pad groups");
3469 fCH2d->SetXTitle("charge deposit [a.u]");
3470 fCH2d->SetZTitle("counts");
3475 //////////////////////////////////////////////////////////////////////////////////
3476 // Set relative scale
3477 /////////////////////////////////////////////////////////////////////////////////
3478 //_____________________________________________________________________________
3479 void AliTRDCalibraFillHisto::SetRelativeScale(Float_t RelativeScale)
3482 // Set the factor that will divide the deposited charge
3483 // to fit in the histo range [0,300]
3486 if (RelativeScale > 0.0) {
3487 fRelativeScale = RelativeScale;
3490 AliInfo("RelativeScale must be strict positif!");
3494 //////////////////////////////////////////////////////////////////////////////////
3495 // Quick way to fill a histo
3496 //////////////////////////////////////////////////////////////////////////////////
3497 //_____________________________________________________________________
3498 void AliTRDCalibraFillHisto::FillCH2d(Int_t x, Float_t y)
3501 // FillCH2d: Marian style
3504 //skip simply the value out of range
3505 if((y>=300.0) || (y<0.0)) return;
3507 //Calcul the y place
3508 Int_t yplace = (Int_t) (fNumberBinCharge*y/300.0)+1;
3509 Int_t place = (fNumberBinCharge+2)*(x+1)+yplace;
3512 fCH2d->GetArray()[place]++;
3516 //////////////////////////////////////////////////////////////////////////////////
3517 // Geometrical functions
3518 ///////////////////////////////////////////////////////////////////////////////////
3519 //_____________________________________________________________________________
3520 Int_t AliTRDCalibraFillHisto::GetLayer(Int_t d) const
3523 // Reconstruct the layer number from the detector number
3526 return ((Int_t) (d % 6));
3530 //_____________________________________________________________________________
3531 Int_t AliTRDCalibraFillHisto::GetStack(Int_t d) const
3534 // Reconstruct the stack number from the detector number
3536 const Int_t kNlayer = 6;
3538 return ((Int_t) (d % 30) / kNlayer);
3542 //_____________________________________________________________________________
3543 Int_t AliTRDCalibraFillHisto::GetSector(Int_t d) const
3546 // Reconstruct the sector number from the detector number
3550 return ((Int_t) (d / fg));
3553 ///////////////////////////////////////////////////////////////////////////////////
3554 // Getter functions for DAQ of the CH2d and the PH2d
3555 //////////////////////////////////////////////////////////////////////////////////
3556 //_____________________________________________________________________
3557 TProfile2D* AliTRDCalibraFillHisto::GetPH2d(Int_t nbtimebin, Float_t samplefrequency)
3560 // return pointer to fPH2d TProfile2D
3561 // create a new TProfile2D if it doesn't exist allready
3567 fTimeMax = nbtimebin;
3568 fSf = samplefrequency;
3574 //_____________________________________________________________________
3575 TH2I* AliTRDCalibraFillHisto::GetCH2d()
3578 // return pointer to fCH2d TH2I
3579 // create a new TH2I if it doesn't exist allready
3588 ////////////////////////////////////////////////////////////////////////////////////////////
3589 // Drift velocity calibration
3590 ///////////////////////////////////////////////////////////////////////////////////////////
3591 //_____________________________________________________________________
3592 TLinearFitter* AliTRDCalibraFillHisto::GetLinearFitter(Int_t detector, Bool_t force)
3595 // return pointer to TLinearFitter Calibration
3596 // if force is true create a new TLinearFitter if it doesn't exist allready
3599 if ((!force) || (fLinearFitterArray.UncheckedAt(detector))){
3600 return (TLinearFitter*)fLinearFitterArray.UncheckedAt(detector);
3603 // if we are forced and TLinearFitter doesn't yet exist create it
3605 // new TLinearFitter
3606 TLinearFitter *linearfitter = new TLinearFitter(2,"pol1");
3607 fLinearFitterArray.AddAt(linearfitter,detector);
3608 return linearfitter;
3611 //____________________________________________________________________________
3612 void AliTRDCalibraFillHisto::AnalyseLinearFitter()
3615 // Analyse array of linear fitter because can not be written
3616 // Store two arrays: one with the param the other one with the error param + number of entries
3619 for(Int_t k = 0; k < 540; k++){
3620 TLinearFitter *linearfitter = GetLinearFitter(k);
3621 if((linearfitter!=0) && (fEntriesLinearFitter[k]>10)){
3622 TVectorD *par = new TVectorD(2);
3623 TVectorD pare = TVectorD(2);
3624 TVectorD *parE = new TVectorD(3);
3625 linearfitter->Eval();
3626 linearfitter->GetParameters(*par);
3627 linearfitter->GetErrors(pare);
3628 Float_t ppointError = TMath::Sqrt(TMath::Abs(linearfitter->GetChisquare())/fEntriesLinearFitter[k]);
3629 (*parE)[0] = pare[0]*ppointError;
3630 (*parE)[1] = pare[1]*ppointError;
3631 (*parE)[2] = (Double_t) fEntriesLinearFitter[k];
3632 ((TObjArray *)fLinearVdriftFit->GetPArray())->AddAt(par,k);
3633 ((TObjArray *)fLinearVdriftFit->GetEArray())->AddAt(parE,k);