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/AliTRDCalDet.h"
73 #include "AliTRDrawFastStream.h"
74 #include "AliTRDdigitsManager.h"
75 #include "AliTRDdigitsParam.h"
76 #include "AliTRDSignalIndex.h"
77 #include "AliTRDarrayADC.h"
79 #include "AliTRDrawStream.h"
87 ClassImp(AliTRDCalibraFillHisto)
89 AliTRDCalibraFillHisto* AliTRDCalibraFillHisto::fgInstance = 0;
90 Bool_t AliTRDCalibraFillHisto::fgTerminated = kFALSE;
92 //_____________singleton implementation_________________________________________________
93 AliTRDCalibraFillHisto *AliTRDCalibraFillHisto::Instance()
96 // Singleton implementation
99 if (fgTerminated != kFALSE) {
103 if (fgInstance == 0) {
104 fgInstance = new AliTRDCalibraFillHisto();
111 //______________________________________________________________________________________
112 void AliTRDCalibraFillHisto::Terminate()
115 // Singleton implementation
116 // Deletes the instance of this class
119 fgTerminated = kTRUE;
121 if (fgInstance != 0) {
128 //______________________________________________________________________________________
129 AliTRDCalibraFillHisto::AliTRDCalibraFillHisto()
139 ,fLinearFitterOn(kFALSE)
140 ,fLinearFitterDebugOn(kFALSE)
142 ,fThresholdClusterPRF2(15.0)
143 ,fLimitChargeIntegration(kFALSE)
144 ,fFillWithZero(kFALSE)
145 ,fNormalizeNbOfCluster(kFALSE)
149 ,fSubVersionGainUsed(0)
150 ,fVersionVdriftUsed(0)
151 ,fSubVersionVdriftUsed(0)
152 ,fCalibraMode(new AliTRDCalibraMode())
155 ,fDetectorPreviousTrack(-1)
159 ,fNumberClustersf(30)
160 ,fNumberClustersProcent(0.5)
161 ,fThresholdClustersDAQ(120.0)
169 ,fNumberBinCharge(50)
175 ,fGoodTracklet(kTRUE)
176 ,fLinearFitterTracklet(0x0)
178 ,fEntriesLinearFitter(0x0)
183 ,fLinearFitterArray(540)
184 ,fLinearVdriftFit(0x0)
189 // Default constructor
193 // Init some default values
196 fNumberUsedCh[0] = 0;
197 fNumberUsedCh[1] = 0;
198 fNumberUsedPh[0] = 0;
199 fNumberUsedPh[1] = 0;
201 fGeo = new AliTRDgeometry();
202 fCalibDB = AliTRDcalibDB::Instance();
205 //______________________________________________________________________________________
206 AliTRDCalibraFillHisto::AliTRDCalibraFillHisto(const AliTRDCalibraFillHisto &c)
213 ,fPRF2dOn(c.fPRF2dOn)
214 ,fHisto2d(c.fHisto2d)
215 ,fVector2d(c.fVector2d)
216 ,fLinearFitterOn(c.fLinearFitterOn)
217 ,fLinearFitterDebugOn(c.fLinearFitterDebugOn)
218 ,fRelativeScale(c.fRelativeScale)
219 ,fThresholdClusterPRF2(c.fThresholdClusterPRF2)
220 ,fLimitChargeIntegration(c.fLimitChargeIntegration)
221 ,fFillWithZero(c.fFillWithZero)
222 ,fNormalizeNbOfCluster(c.fNormalizeNbOfCluster)
223 ,fMaxCluster(c.fMaxCluster)
224 ,fNbMaxCluster(c.fNbMaxCluster)
225 ,fVersionGainUsed(c.fVersionGainUsed)
226 ,fSubVersionGainUsed(c.fSubVersionGainUsed)
227 ,fVersionVdriftUsed(c.fVersionVdriftUsed)
228 ,fSubVersionVdriftUsed(c.fSubVersionVdriftUsed)
231 ,fDebugLevel(c.fDebugLevel)
232 ,fDetectorPreviousTrack(c.fDetectorPreviousTrack)
233 ,fMCMPrevious(c.fMCMPrevious)
234 ,fROBPrevious(c.fROBPrevious)
235 ,fNumberClusters(c.fNumberClusters)
236 ,fNumberClustersf(c.fNumberClustersf)
237 ,fNumberClustersProcent(c.fNumberClustersProcent)
238 ,fThresholdClustersDAQ(c.fThresholdClustersDAQ)
239 ,fNumberRowDAQ(c.fNumberRowDAQ)
240 ,fNumberColDAQ(c.fNumberColDAQ)
241 ,fProcent(c.fProcent)
242 ,fDifference(c.fDifference)
243 ,fNumberTrack(c.fNumberTrack)
244 ,fTimeMax(c.fTimeMax)
246 ,fNumberBinCharge(c.fNumberBinCharge)
247 ,fNumberBinPRF(c.fNumberBinPRF)
248 ,fNgroupprf(c.fNgroupprf)
252 ,fGoodTracklet(c.fGoodTracklet)
253 ,fLinearFitterTracklet(0x0)
255 ,fEntriesLinearFitter(0x0)
260 ,fLinearFitterArray(540)
261 ,fLinearVdriftFit(0x0)
268 if(c.fCalibraMode) fCalibraMode = new AliTRDCalibraMode(*c.fCalibraMode);
269 if(c.fCalibraVector) fCalibraVector = new AliTRDCalibraVector(*c.fCalibraVector);
271 fPH2d = new TProfile2D(*c.fPH2d);
272 fPH2d->SetDirectory(0);
275 fPRF2d = new TProfile2D(*c.fPRF2d);
276 fPRF2d->SetDirectory(0);
279 fCH2d = new TH2I(*c.fCH2d);
280 fCH2d->SetDirectory(0);
282 if(c.fLinearVdriftFit){
283 fLinearVdriftFit = new AliTRDCalibraVdriftLinearFit(*c.fLinearVdriftFit);
286 if(c.fCalDetGain) fCalDetGain = new AliTRDCalDet(*c.fCalDetGain);
287 if(c.fCalROCGain) fCalROCGain = new AliTRDCalROC(*c.fCalROCGain);
292 fGeo = new AliTRDgeometry();
293 fCalibDB = AliTRDcalibDB::Instance();
296 //____________________________________________________________________________________
297 AliTRDCalibraFillHisto::~AliTRDCalibraFillHisto()
300 // AliTRDCalibraFillHisto destructor
304 if ( fDebugStreamer ) delete fDebugStreamer;
306 if ( fCalDetGain ) delete fCalDetGain;
307 if ( fCalROCGain ) delete fCalROCGain;
309 if( fLinearFitterTracklet ) { delete fLinearFitterTracklet; }
313 delete [] fEntriesCH;
314 delete [] fEntriesLinearFitter;
317 for(Int_t idet=0; idet<AliTRDgeometry::kNdet; idet++){
318 TLinearFitter *f = (TLinearFitter*)fLinearFitterArray.At(idet);
321 if(fLinearVdriftFit) delete fLinearVdriftFit;
327 //_____________________________________________________________________________
328 void AliTRDCalibraFillHisto::Destroy()
339 //_____________________________________________________________________________
340 void AliTRDCalibraFillHisto::DestroyDebugStreamer()
343 // Delete DebugStreamer
346 if ( fDebugStreamer ) delete fDebugStreamer;
347 fDebugStreamer = 0x0;
350 //_____________________________________________________________________________
351 void AliTRDCalibraFillHisto::ClearHistos()
371 //////////////////////////////////////////////////////////////////////////////////
372 // calibration with AliTRDtrackV1: Init, Update
373 //////////////////////////////////////////////////////////////////////////////////
374 //____________Functions for initialising the AliTRDCalibraFillHisto in the code_________
375 Bool_t AliTRDCalibraFillHisto::Init2Dhistos(Int_t nboftimebin)
378 // Init the histograms and stuff to be filled
383 AliTRDcalibDB *cal = AliTRDcalibDB::Instance();
385 AliInfo("Could not get calibDB");
388 AliTRDCommonParam *parCom = AliTRDCommonParam::Instance();
390 AliInfo("Could not get CommonParam");
395 if(nboftimebin > 0) fTimeMax = nboftimebin;
396 else fTimeMax = cal->GetNumberOfTimeBinsDCS();
397 if(fTimeMax <= 0) fTimeMax = 30;
398 printf("////////////////////////////////////////////\n");
399 printf("Number of time bins in calibration component %d\n",fTimeMax);
400 printf("////////////////////////////////////////////\n");
401 fSf = parCom->GetSamplingFrequency();
402 if(!fNormalizeNbOfCluster) fRelativeScale = 20.0;
403 else fRelativeScale = 1.18;
404 fNumberClustersf = fTimeMax;
405 fNumberClusters = (Int_t)(fNumberClustersProcent*fTimeMax);
407 // Init linear fitter
408 if(!fLinearFitterTracklet) {
409 fLinearFitterTracklet = new TLinearFitter(2,"pol1");
410 fLinearFitterTracklet->StoreData(kTRUE);
413 //calib object from database used for reconstruction
415 fCalDetGain->~AliTRDCalDet();
416 new(fCalDetGain) AliTRDCalDet(*(cal->GetGainFactorDet()));
417 }else fCalDetGain = new AliTRDCalDet(*(cal->GetGainFactorDet()));
419 // Calcul Xbins Chambd0, Chamb2
420 Int_t ntotal0 = CalculateTotalNumberOfBins(0);
421 Int_t ntotal1 = CalculateTotalNumberOfBins(1);
422 Int_t ntotal2 = CalculateTotalNumberOfBins(2);
424 // If vector method On initialised all the stuff
426 fCalibraVector = new AliTRDCalibraVector();
427 fCalibraVector->SetNumberBinCharge(fNumberBinCharge);
428 fCalibraVector->SetTimeMax(fTimeMax);
429 if(fNgroupprf != 0) {
430 fCalibraVector->SetNumberBinPRF(2*fNgroupprf*fNumberBinPRF);
431 fCalibraVector->SetPRFRange((Float_t)(3.0*fNgroupprf));
434 fCalibraVector->SetNumberBinPRF(fNumberBinPRF);
435 fCalibraVector->SetPRFRange(1.5);
437 for(Int_t k = 0; k < 3; k++){
438 fCalibraVector->SetDetCha0(k,fCalibraMode->GetDetChamb0(k));
439 fCalibraVector->SetDetCha2(k,fCalibraMode->GetDetChamb2(k));
441 fCalibraVector->SetNzNrphi(0,fCalibraMode->GetNz(0),fCalibraMode->GetNrphi(0));
442 fCalibraVector->SetNzNrphi(1,fCalibraMode->GetNz(1),fCalibraMode->GetNrphi(1));
443 fCalibraVector->SetNzNrphi(2,fCalibraMode->GetNz(2),fCalibraMode->GetNrphi(2));
444 fCalibraVector->SetNbGroupPRF(fNgroupprf);
447 // Create the 2D histos corresponding to the pad groupCalibration mode
450 AliInfo(Form("The pad calibration mode for the relative gain calibration: Nz %d, and Nrphi %d"
451 ,fCalibraMode->GetNz(0)
452 ,fCalibraMode->GetNrphi(0)));
454 // Create the 2D histo
459 fAmpTotal = new Float_t[TMath::Max(fCalibraMode->GetDetChamb2(0),fCalibraMode->GetDetChamb0(0))];
460 for (Int_t k = 0; k < TMath::Max(fCalibraMode->GetDetChamb2(0),fCalibraMode->GetDetChamb0(0)); k++) {
464 fEntriesCH = new Int_t[ntotal0];
465 for(Int_t k = 0; k < ntotal0; k++){
472 AliInfo(Form("The pad calibration mode for the drift velocity calibration: Nz %d, and Nrphi %d"
473 ,fCalibraMode->GetNz(1)
474 ,fCalibraMode->GetNrphi(1)));
476 // Create the 2D histo
481 fPHPlace = new Short_t[fTimeMax];
482 for (Int_t k = 0; k < fTimeMax; k++) {
485 fPHValue = new Float_t[fTimeMax];
486 for (Int_t k = 0; k < fTimeMax; k++) {
490 if (fLinearFitterOn) {
491 if(fLinearFitterDebugOn) {
492 fLinearFitterArray.SetName("ArrayLinearFitters");
493 fEntriesLinearFitter = new Int_t[540];
494 for(Int_t k = 0; k < 540; k++){
495 fEntriesLinearFitter[k] = 0;
498 fLinearVdriftFit = new AliTRDCalibraVdriftLinearFit();
503 AliInfo(Form("The pad calibration mode for the PRF calibration: Nz %d, and Nrphi %d"
504 ,fCalibraMode->GetNz(2)
505 ,fCalibraMode->GetNrphi(2)));
506 // Create the 2D histo
508 CreatePRF2d(ntotal2);
515 //____________Offline tracking in the AliTRDtracker____________________________
516 Bool_t AliTRDCalibraFillHisto::UpdateHistograms(const AliTRDtrack *t)
519 // Use AliTRDtrack for the calibration
523 AliTRDcluster *cl = 0x0; // pointeur to cluster
524 Int_t index0 = 0; // index of the first cluster in the current chamber
525 Int_t index1 = 0; // index of the current cluster in the current chamber
527 //////////////////////////////
528 // loop over the clusters
529 ///////////////////////////////
530 while((cl = t->GetCluster(index1))){
532 /////////////////////////////////////////////////////////////////////////
533 // Fill the infos for the previous clusters if not the same detector
534 ////////////////////////////////////////////////////////////////////////
535 Int_t detector = cl->GetDetector();
536 if ((detector != fDetectorPreviousTrack) &&
537 (index0 != index1)) {
541 //If the same track, then look if the previous detector is in
542 //the same plane, if yes: not a good track
543 if ((GetLayer(detector) == GetLayer(fDetectorPreviousTrack))) {
547 // Fill only if the track doesn't touch a masked pad or doesn't
550 // drift velocity unables to cut bad tracklets
551 Bool_t pass = FindP1TrackPHtracklet(t,index0,index1);
555 FillTheInfoOfTheTrackCH(index1-index0);
560 FillTheInfoOfTheTrackPH();
563 if(pass && fPRF2dOn) HandlePRFtracklet(t,index0,index1);
566 } // if a good tracklet
569 ResetfVariablestracklet();
572 } // Fill at the end the charge
575 /////////////////////////////////////////////////////////////
576 // Localise and take the calib gain object for the detector
577 ////////////////////////////////////////////////////////////
578 if (detector != fDetectorPreviousTrack) {
580 //Localise the detector
581 LocalisationDetectorXbins(detector);
584 AliTRDcalibDB *cal = AliTRDcalibDB::Instance();
586 AliInfo("Could not get calibDB");
593 fCalROCGain->~AliTRDCalROC();
594 new(fCalROCGain) AliTRDCalROC(*(cal->GetGainFactorROC(detector)));
596 }else fCalROCGain = new AliTRDCalROC(*(cal->GetGainFactorROC(detector)));
600 // Reset the detectbjobsor
601 fDetectorPreviousTrack = detector;
603 ///////////////////////////////////////
604 // Store the info of the cluster
605 ///////////////////////////////////////
606 Int_t row = cl->GetPadRow();
607 Int_t col = cl->GetPadCol();
608 CheckGoodTrackletV1(cl);
609 Int_t group[2] = {0,0};
610 if(fCH2dOn) group[0] = CalculateCalibrationGroup(0,row,col);
611 if(fPH2dOn) group[1] = CalculateCalibrationGroup(1,row,col);
612 StoreInfoCHPHtrack(cl,t->GetClusterdQdl(index1),group,row,col);
616 } // while on clusters
618 ///////////////////////////
619 // Fill the last plane
620 //////////////////////////
621 if( index0 != index1 ){
627 // drift velocity unables to cut bad tracklets
628 Bool_t pass = FindP1TrackPHtracklet(t,index0,index1);
632 FillTheInfoOfTheTrackCH(index1-index0);
637 FillTheInfoOfTheTrackPH();
640 if(pass && fPRF2dOn) HandlePRFtracklet(t,index0,index1);
642 } // if a good tracklet
647 ResetfVariablestracklet();
652 //____________Offline tracking in the AliTRDtracker____________________________
653 Bool_t AliTRDCalibraFillHisto::UpdateHistogramsV1(const AliTRDtrackV1 *t)
656 // Use AliTRDtrackV1 for the calibration
660 const AliTRDseedV1 *tracklet = 0x0; // tracklet per plane
661 AliTRDcluster *cl = 0x0; // cluster attached now to the tracklet
662 AliTRDcluster *cls = 0x0; // shared cluster attached now to the tracklet
663 Bool_t newtr = kTRUE; // new track
666 // AliTRDcalibDB *cal = AliTRDcalibDB::Instance();
669 AliInfo("Could not get calibDB");
674 AliInfo("Could not get calibDB");
679 ///////////////////////////
680 // loop over the tracklet
681 ///////////////////////////
682 for(Int_t itr = 0; itr < 6; itr++){
684 if(!(tracklet = t->GetTracklet(itr))) continue;
685 if(!tracklet->IsOK()) continue;
687 ResetfVariablestracklet();
689 //////////////////////////////////////////
690 // localisation of the tracklet and dqdl
691 //////////////////////////////////////////
692 Int_t layer = tracklet->GetPlane();
694 while(!(cl = tracklet->GetClusters(ic++))) continue;
695 Int_t detector = cl->GetDetector();
696 if (detector != fDetectorPreviousTrack) {
697 // if not a new track
699 // don't use the rest of this track if in the same plane
700 if (layer == GetLayer(fDetectorPreviousTrack)) {
701 //printf("bad tracklet, same layer for detector %d\n",detector);
705 //Localise the detector bin
706 LocalisationDetectorXbins(detector);
710 fCalROCGain->~AliTRDCalROC();
711 new(fCalROCGain) AliTRDCalROC(*(fCalibDB->GetGainFactorROC(detector)));
713 }else fCalROCGain = new AliTRDCalROC(*(fCalibDB->GetGainFactorROC(detector)));
716 fDetectorPreviousTrack = detector;
720 ////////////////////////////
721 // loop over the clusters
722 ////////////////////////////
723 Int_t nbclusters = 0;
724 for(int jc=0; jc<AliTRDseedV1::kNtb; jc++){
725 if(!(cl = tracklet->GetClusters(jc))) continue;
728 // Store the info bis of the tracklet
729 Int_t row = cl->GetPadRow();
730 Int_t col = cl->GetPadCol();
731 CheckGoodTrackletV1(cl);
732 Int_t group[2] = {0,0};
733 if(fCH2dOn) group[0] = CalculateCalibrationGroup(0,row,col);
734 if(fPH2dOn) group[1] = CalculateCalibrationGroup(1,row,col);
735 // Add the charge if shared cluster
736 cls = tracklet->GetClusters(jc+AliTRDseedV1::kNtb);
738 StoreInfoCHPHtrack(cl, tracklet->GetdQdl(jc),group,row,col,cls);
741 ////////////////////////////////////////
742 // Fill the stuffs if a good tracklet
743 ////////////////////////////////////////
746 // drift velocity unables to cut bad tracklets
747 Bool_t pass = FindP1TrackPHtrackletV1(tracklet, nbclusters);
749 //printf("pass %d and nbclusters %d\n",pass,nbclusters);
753 FillTheInfoOfTheTrackCH(nbclusters);
758 FillTheInfoOfTheTrackPH();
761 if(pass && fPRF2dOn) HandlePRFtrackletV1(tracklet,nbclusters);
763 } // if a good tracklet
769 ///////////////////////////////////////////////////////////////////////////////////
770 // Routine inside the update with AliTRDtrack
771 ///////////////////////////////////////////////////////////////////////////////////
772 //____________Offine tracking in the AliTRDtracker_____________________________
773 Bool_t AliTRDCalibraFillHisto::FindP1TrackPHtracklet(const AliTRDtrack *t, Int_t index0, Int_t index1)
776 // Drift velocity calibration:
777 // Fit the clusters with a straight line
778 // From the slope find the drift velocity
781 //Number of points: if less than 3 return kFALSE
782 Int_t npoints = index1-index0;
783 if(npoints <= 2) return kFALSE;
788 Int_t detector = ((AliTRDcluster *) t->GetCluster(index0))->GetDetector(); //detector
789 // parameters of the track
790 Double_t snp = t->GetSnpPlane(GetLayer(detector)); // sin angle in the plan yx track
791 Double_t tgl = t->GetTglPlane(GetLayer(detector)); // dz/dl and not dz/dx!
792 Double_t tnp = 0.0; // tan angle in the plan xy track
793 if( TMath::Abs(snp) < 1.){
794 tnp = snp / TMath::Sqrt((1.-snp)*(1.+snp));
796 Float_t dzdx = tgl*TMath::Sqrt(1+tnp*tnp); // dz/dx now from dz/dl
797 // tilting pad and cross row
798 Int_t crossrow = 0; // if it crosses a pad row
799 Int_t rowp = -1; // if it crosses a pad row
800 AliTRDpadPlane *padplane = fGeo->GetPadPlane(GetLayer(detector),GetStack(detector));
801 Double_t tiltingangle = padplane->GetTiltingAngle(); // tiltingangle of the pad
802 Float_t tnt = TMath::Tan(tiltingangle/180.*TMath::Pi()); // tan tiltingangle
804 fLinearFitterTracklet->ClearPoints();
805 Double_t dydt = 0.0; // dydt tracklet after straight line fit
806 Double_t errorpar = 0.0; // error after straight line fit on dy/dt
807 Double_t pointError = 0.0; // error after straight line fit
808 Int_t nbli = 0; // number linear fitter points
810 //////////////////////////////
811 // loop over clusters
812 ////////////////////////////
813 for(Int_t k = 0; k < npoints; k++){
815 AliTRDcluster *cl = (AliTRDcluster *) t->GetCluster(k+index0);
816 if((fLimitChargeIntegration) && (!cl->IsInChamber())) continue;
817 Double_t ycluster = cl->GetY();
818 Int_t time = cl->GetPadTime();
819 Double_t timeis = time/fSf;
820 //Double_t q = cl->GetQ();
821 //See if cross two pad rows
822 Int_t row = cl->GetPadRow();
824 if(row != rowp) crossrow = 1;
826 fLinearFitterTracklet->AddPoint(&timeis,ycluster,1);
831 //////////////////////////////
833 //////////////////////////////
835 fLinearFitterTracklet->ClearPoints();
839 fLinearFitterTracklet->Eval();
840 fLinearFitterTracklet->GetParameters(pars);
841 pointError = TMath::Sqrt(fLinearFitterTracklet->GetChisquare()/(nbli-2));
842 errorpar = fLinearFitterTracklet->GetParError(1)*pointError;
844 fLinearFitterTracklet->ClearPoints();
846 /////////////////////////////
848 ////////////////////////////
850 if ( !fDebugStreamer ) {
852 TDirectory *backup = gDirectory;
853 fDebugStreamer = new TTreeSRedirector("TRDdebugCalibraFill.root");
854 if ( backup ) backup->cd(); //we don't want to be cd'd to the debug streamer
858 (* fDebugStreamer) << "FindP1TrackPHtracklet0"<<
859 //"snpright="<<snpright<<
860 "npoints="<<npoints<<
862 "detector="<<detector<<
869 "crossrow="<<crossrow<<
870 "errorpar="<<errorpar<<
871 "pointError="<<pointError<<
875 Int_t nbclusters = index1-index0;
876 Int_t layer = GetLayer(fDetectorPreviousTrack);
878 (* fDebugStreamer) << "FindP1TrackPHtracklet1"<<
879 //"snpright="<<snpright<<
880 "nbclusters="<<nbclusters<<
881 "detector="<<fDetectorPreviousTrack<<
887 ///////////////////////////
889 ///////////////////////////
890 if(npoints < fNumberClusters) return kFALSE;
891 if(npoints > fNumberClustersf) return kFALSE;
892 if(pointError >= 0.1) return kFALSE;
893 if(crossrow == 1) return kFALSE;
895 ////////////////////////////
897 ////////////////////////////
899 //Add to the linear fitter of the detector
900 if( TMath::Abs(snp) < 1.){
901 Double_t x = tnp-dzdx*tnt;
902 if(fLinearFitterDebugOn) {
903 (GetLinearFitter(detector,kTRUE))->AddPoint(&x,dydt);
904 fEntriesLinearFitter[detector]++;
906 fLinearVdriftFit->Update(detector,x,pars[1]);
912 //____________Offine tracking in the AliTRDtracker_____________________________
913 Bool_t AliTRDCalibraFillHisto::FindP1TrackPHtrackletV1(const AliTRDseedV1 *tracklet, Int_t nbclusters)
916 // Drift velocity calibration:
917 // Fit the clusters with a straight line
918 // From the slope find the drift velocity
921 ////////////////////////////////////////////////
922 //Number of points: if less than 3 return kFALSE
923 /////////////////////////////////////////////////
924 if(nbclusters <= 2) return kFALSE;
929 // results of the linear fit
930 Double_t dydt = 0.0; // dydt tracklet after straight line fit
931 Double_t errorpar = 0.0; // error after straight line fit on dy/dt
932 Double_t pointError = 0.0; // error after straight line fit
933 // pad row problemes: avoid tracklet that cross pad rows, tilting angle in the constant
934 Int_t crossrow = 0; // if it crosses a pad row
935 Int_t rowp = -1; // if it crosses a pad row
936 Float_t tnt = tracklet->GetTilt(); // tan tiltingangle
937 fLinearFitterTracklet->ClearPoints();
940 ///////////////////////////////////////////
941 // Take the parameters of the track
942 //////////////////////////////////////////
943 // take now the snp, tnp and tgl from the track
944 Double_t snp = tracklet->GetSnp(); // sin dy/dx at the end of the chamber
945 Double_t tnp = 0.0; // dy/dx at the end of the chamber
946 if( TMath::Abs(snp) < 1.){
947 tnp = snp / TMath::Sqrt((1.-snp)*(1.+snp));
949 Double_t tgl = tracklet->GetTgl(); // dz/dl
950 Double_t dzdx = tgl*TMath::Sqrt(1+tnp*tnp); // dz/dx calculated from dz/dl
952 //Double_t tnp = tracklet->GetYref(1); // dy/dx at the entrance of the chamber
953 //Double_t tgl = tracklet->GetZref(1); // dz/dl at the entrance of the chamber
954 //Double_t dzdx = tgl; //*TMath::Sqrt(1+tnp*tnp); // dz/dx from dz/dl
955 // at the end with correction due to linear fit
956 //Double_t tnp = tracklet->GetYfit(1); // dy/dx at the end of the chamber after fit correction
957 //Double_t tgl = tracklet->GetZfit(1); // dz/dl at the end of the chamber after fit correction
960 ////////////////////////////
961 // loop over the clusters
962 ////////////////////////////
964 AliTRDcluster *cl = 0x0;
965 //////////////////////////////
966 // Check no shared clusters
967 //////////////////////////////
968 for(int icc=AliTRDseedV1::kNtb; icc<AliTRDseedV1::kNclusters; icc++){
969 if((cl = tracklet->GetClusters(icc))) crossrow = 1;
971 //////////////////////////////////
973 //////////////////////////////////
974 for(int ic=0; ic<AliTRDseedV1::kNtb; ic++){
975 if(!(cl = tracklet->GetClusters(ic))) continue;
976 if((fLimitChargeIntegration) && (!cl->IsInChamber())) continue;
978 Double_t ycluster = cl->GetY();
979 Int_t time = cl->GetPadTime();
980 Double_t timeis = time/fSf;
981 //See if cross two pad rows
982 Int_t row = cl->GetPadRow();
983 if(rowp==-1) rowp = row;
984 if(row != rowp) crossrow = 1;
986 fLinearFitterTracklet->AddPoint(&timeis,ycluster,1);
992 ////////////////////////////////////
993 // Do the straight line fit now
994 ///////////////////////////////////
996 fLinearFitterTracklet->ClearPoints();
1000 fLinearFitterTracklet->Eval();
1001 fLinearFitterTracklet->GetParameters(pars);
1002 pointError = TMath::Sqrt(fLinearFitterTracklet->GetChisquare()/(nbli-2));
1003 errorpar = fLinearFitterTracklet->GetParError(1)*pointError;
1005 //printf("chis %f, nbli %d, pointError %f, parError %f, errorpar %f\n",fLinearFitterTracklet->GetChisquare(),nbli,pointError,fLinearFitterTracklet->GetParError(1),errorpar);
1006 fLinearFitterTracklet->ClearPoints();
1008 ////////////////////////////////
1010 ///////////////////////////////
1013 if(fDebugLevel > 0){
1014 if ( !fDebugStreamer ) {
1016 TDirectory *backup = gDirectory;
1017 fDebugStreamer = new TTreeSRedirector("TRDdebugCalibraFill.root");
1018 if ( backup ) backup->cd(); //we don't want to be cd'd to the debug streamer
1022 Int_t layer = GetLayer(fDetectorPreviousTrack);
1024 (* fDebugStreamer) << "FindP1TrackPHtrackletV1"<<
1025 //"snpright="<<snpright<<
1027 "nbclusters="<<nbclusters<<
1028 "detector="<<fDetectorPreviousTrack<<
1036 "crossrow="<<crossrow<<
1037 "errorpar="<<errorpar<<
1038 "pointError="<<pointError<<
1043 /////////////////////////
1045 ////////////////////////
1047 if(nbclusters < fNumberClusters) return kFALSE;
1048 if(nbclusters > fNumberClustersf) return kFALSE;
1049 if(pointError >= 0.3) return kFALSE;
1050 if(crossrow == 1) return kFALSE;
1052 ///////////////////////
1054 //////////////////////
1056 if(fLinearFitterOn){
1057 //Add to the linear fitter of the detector
1058 if( TMath::Abs(snp) < 1.){
1059 Double_t x = tnp-dzdx*tnt;
1060 if(fLinearFitterDebugOn) {
1061 (GetLinearFitter(fDetectorPreviousTrack,kTRUE))->AddPoint(&x,dydt);
1062 fEntriesLinearFitter[fDetectorPreviousTrack]++;
1064 fLinearVdriftFit->Update(fDetectorPreviousTrack,x,pars[1]);
1070 //____________Offine tracking in the AliTRDtracker_____________________________
1071 Bool_t AliTRDCalibraFillHisto::HandlePRFtracklet(const AliTRDtrack *t, Int_t index0, Int_t index1)
1074 // PRF width calibration
1075 // Assume a Gaussian shape: determinate the position of the three pad clusters
1076 // Fit with a straight line
1077 // Take the fitted values for all the clusters (3 or 2 pad clusters)
1078 // Fill the PRF as function of angle of the track
1083 //////////////////////////
1085 /////////////////////////
1086 Int_t npoints = index1-index0; // number of total points
1087 Int_t nb3pc = 0; // number of three pads clusters used for fit
1088 Int_t detector = ((AliTRDcluster *) t->GetCluster(index0))->GetDetector(); // detector
1089 // To see the difference due to the fit
1090 Double_t *padPositions;
1091 padPositions = new Double_t[npoints];
1092 for(Int_t k = 0; k < npoints; k++){
1093 padPositions[k] = 0.0;
1095 // Take the tgl and snp with the track t now
1096 Double_t tgl = t->GetTglPlane(GetLayer(detector)); //dz/dl and not dz/dx
1097 Double_t snp = t->GetSnpPlane(GetLayer(detector)); // sin angle in xy plan
1098 Float_t dzdx = 0.0; // dzdx
1100 if(TMath::Abs(snp) < 1.0){
1101 tnp = snp / TMath::Sqrt((1.-snp)*(1.+snp));
1102 dzdx = tgl*TMath::Sqrt(1+tnp*tnp);
1105 fLinearFitterTracklet->ClearPoints();
1107 ///////////////////////////
1108 // calcul the tnp group
1109 ///////////////////////////
1110 Bool_t echec = kFALSE;
1111 Double_t shift = 0.0;
1112 //Calculate the shift in x coresponding to this tnp
1113 if(fNgroupprf != 0.0){
1114 shift = -3.0*(fNgroupprf-1)-1.5;
1115 Double_t limithigh = -0.2*(fNgroupprf-1);
1116 if((tnp < (-0.2*fNgroupprf)) || (tnp > (0.2*fNgroupprf))) echec = kTRUE;
1118 while(tnp > limithigh){
1125 delete [] padPositions;
1129 //////////////////////
1131 /////////////////////
1132 for(Int_t k = 0; k < npoints; k++){
1134 AliTRDcluster *cl = (AliTRDcluster *) t->GetCluster(k+index0);
1136 Short_t *signals = cl->GetSignals();
1137 Double_t time = cl->GetPadTime();
1138 //Calculate x if possible
1139 Float_t xcenter = 0.0;
1140 Bool_t echec1 = kTRUE;
1141 if((time<=7) || (time>=21)) continue;
1142 // Center 3 balanced: position with the center of the pad
1143 if ((((Float_t) signals[3]) > 0.0) &&
1144 (((Float_t) signals[2]) > 0.0) &&
1145 (((Float_t) signals[4]) > 0.0)) {
1147 // Security if the denomiateur is 0
1148 if ((((Float_t) (((Float_t) signals[3]) * ((Float_t) signals[3]))) /
1149 ((Float_t) (((Float_t) signals[2]) * ((Float_t) signals[4])))) != 1.0) {
1150 xcenter = 0.5 * (TMath::Log((Float_t) (((Float_t) signals[4]) / ((Float_t) signals[2]))))
1151 / (TMath::Log(((Float_t) (((Float_t) signals[3]) * ((Float_t) signals[3])))
1152 / ((Float_t) (((Float_t) signals[2]) * ((Float_t) signals[4])))));
1158 if(TMath::Abs(xcenter) > 0.5) echec = kTRUE;
1160 //if no echec: calculate with the position of the pad
1161 // Position of the cluster
1162 Double_t padPosition = xcenter + cl->GetPadCol();
1163 padPositions[k] = padPosition;
1165 fLinearFitterTracklet->AddPoint(&time, padPosition,1);
1169 /////////////////////////////
1171 ////////////////////////////
1173 delete [] padPositions;
1174 fLinearFitterTracklet->ClearPoints();
1177 fLinearFitterTracklet->Eval();
1179 fLinearFitterTracklet->GetParameters(line);
1180 Float_t pointError = -1.0;
1181 if( fLinearFitterTracklet->GetChisquare()>=0.0) {
1182 pointError = TMath::Sqrt( fLinearFitterTracklet->GetChisquare()/(nb3pc-2));
1184 fLinearFitterTracklet->ClearPoints();
1186 /////////////////////////////////////////////////////
1187 // Now fill the PRF: second loop over clusters
1188 /////////////////////////////////////////////////////
1189 for(Int_t k = 0; k < npoints; k++){
1191 AliTRDcluster *cl = (AliTRDcluster *) t->GetCluster(k+index0);
1192 Short_t *signals = cl->GetSignals(); // signal
1193 Double_t time = cl->GetPadTime(); // time bin
1194 Float_t padPosTracklet = line[0]+line[1]*time; // reconstruct position from fit
1195 Float_t padPos = cl->GetPadCol(); // middle pad
1196 Double_t dpad = padPosTracklet - padPos; // reconstruct position relative to middle pad from fit
1197 Float_t ycenter = 0.0; // relative center charge
1198 Float_t ymin = 0.0; // relative left charge
1199 Float_t ymax = 0.0; // relative right charge
1201 //Requiere simply two pads clusters at least
1202 if(((((Float_t) signals[3]) > 0.0) && (((Float_t) signals[2]) > 0.0)) ||
1203 ((((Float_t) signals[3]) > 0.0) && (((Float_t) signals[4]) > 0.0))){
1204 Float_t sum = ((Float_t) signals[2]) + ((Float_t) signals[3]) + ((Float_t) signals[4]);
1205 if(sum > 0.0) ycenter = ((Float_t) signals[3])/ sum;
1206 if(sum > 0.0) ymin = ((Float_t) signals[2])/ sum;
1207 if(sum > 0.0) ymax = ((Float_t) signals[4])/ sum;
1211 Int_t rowcl = cl->GetPadRow(); // row of cluster
1212 Int_t colcl = cl->GetPadCol(); // col of cluster
1213 Int_t grouplocal = CalculateCalibrationGroup(2,rowcl,colcl); // calcul the corresponding group
1214 Int_t caligroup = fCalibraMode->GetXbins(2)+ grouplocal; // calcul the corresponding group
1215 Float_t xcl = cl->GetY(); // y cluster
1216 Float_t qcl = cl->GetQ(); // charge cluster
1217 Int_t layer = GetLayer(detector); // layer
1218 Int_t stack = GetStack(detector); // stack
1219 Double_t xdiff = dpad; // reconstructed position constant
1220 Double_t x = dpad; // reconstructed position moved
1221 Float_t ep = pointError; // error of fit
1222 Float_t signal1 = (Float_t)signals[1]; // signal at the border
1223 Float_t signal3 = (Float_t)signals[3]; // signal
1224 Float_t signal2 = (Float_t)signals[2]; // signal
1225 Float_t signal4 = (Float_t)signals[4]; // signal
1226 Float_t signal5 = (Float_t)signals[5]; // signal at the border
1228 //////////////////////////////
1230 /////////////////////////////
1231 if(fDebugLevel > 0){
1232 if ( !fDebugStreamer ) {
1234 TDirectory *backup = gDirectory;
1235 fDebugStreamer = new TTreeSRedirector("TRDdebugCalibraFill.root");
1236 if ( backup ) backup->cd(); //we don't want to be cd'd to the debug streamer
1242 Float_t y = ycenter;
1243 (* fDebugStreamer) << "HandlePRFtracklet"<<
1244 "caligroup="<<caligroup<<
1245 "detector="<<detector<<
1248 "npoints="<<npoints<<
1257 "padPosition="<<padPositions[k]<<
1258 "padPosTracklet="<<padPosTracklet<<
1263 "signal1="<<signal1<<
1264 "signal2="<<signal2<<
1265 "signal3="<<signal3<<
1266 "signal4="<<signal4<<
1267 "signal5="<<signal5<<
1273 (* fDebugStreamer) << "HandlePRFtracklet"<<
1274 "caligroup="<<caligroup<<
1275 "detector="<<detector<<
1278 "npoints="<<npoints<<
1287 "padPosition="<<padPositions[k]<<
1288 "padPosTracklet="<<padPosTracklet<<
1293 "signal1="<<signal1<<
1294 "signal2="<<signal2<<
1295 "signal3="<<signal3<<
1296 "signal4="<<signal4<<
1297 "signal5="<<signal5<<
1303 (* fDebugStreamer) << "HandlePRFtracklet"<<
1304 "caligroup="<<caligroup<<
1305 "detector="<<detector<<
1308 "npoints="<<npoints<<
1317 "padPosition="<<padPositions[k]<<
1318 "padPosTracklet="<<padPosTracklet<<
1323 "signal1="<<signal1<<
1324 "signal2="<<signal2<<
1325 "signal3="<<signal3<<
1326 "signal4="<<signal4<<
1327 "signal5="<<signal5<<
1333 ////////////////////////////
1335 ///////////////////////////
1336 if(npoints < fNumberClusters) continue;
1337 if(npoints > fNumberClustersf) continue;
1338 if(nb3pc <= 5) continue;
1339 if((time >= 21) || (time < 7)) continue;
1340 if(TMath::Abs(snp) >= 1.0) continue;
1341 if(TMath::Abs(qcl) < 80) continue;
1343 ////////////////////////////
1345 ///////////////////////////
1347 if(TMath::Abs(dpad) < 1.5) {
1348 fPRF2d->Fill(shift+dpad,(caligroup+0.5),ycenter);
1349 fPRF2d->Fill(shift-dpad,(caligroup+0.5),ycenter);
1351 if((ymin > 0.0) && (TMath::Abs(dpad+1.0) < 1.5)) {
1352 fPRF2d->Fill(shift-(dpad+1.0),(caligroup+0.5),ymin);
1353 fPRF2d->Fill(shift+(dpad+1.0),(caligroup+0.5),ymin);
1355 if((ymax > 0.0) && (TMath::Abs(dpad-1.0) < 1.5)) {
1356 fPRF2d->Fill(shift+1.0-dpad,(caligroup+0.5),ymax);
1357 fPRF2d->Fill(shift-1.0+dpad,(caligroup+0.5),ymax);
1361 if(TMath::Abs(dpad) < 1.5) {
1362 fCalibraVector->UpdateVectorPRF(fDetectorPreviousTrack,grouplocal,shift+dpad,ycenter);
1363 fCalibraVector->UpdateVectorPRF(fDetectorPreviousTrack,grouplocal,shift-dpad,ycenter);
1365 if((ymin > 0.0) && (TMath::Abs(dpad+1.0) < 1.5)) {
1366 fCalibraVector->UpdateVectorPRF(fDetectorPreviousTrack,grouplocal,shift-(dpad+1.0),ymin);
1367 fCalibraVector->UpdateVectorPRF(fDetectorPreviousTrack,grouplocal,shift+(dpad+1.0),ymin);
1369 if((ymax > 0.0) && (TMath::Abs(dpad-1.0) < 1.5)) {
1370 fCalibraVector->UpdateVectorPRF(fDetectorPreviousTrack,grouplocal,shift+1.0-dpad,ymax);
1371 fCalibraVector->UpdateVectorPRF(fDetectorPreviousTrack,grouplocal,shift-1.0+dpad,ymax);
1375 delete [] padPositions;
1379 //____________Offine tracking in the AliTRDtracker_____________________________
1380 Bool_t AliTRDCalibraFillHisto::HandlePRFtrackletV1(const AliTRDseedV1 *tracklet, Int_t nbclusters)
1383 // PRF width calibration
1384 // Assume a Gaussian shape: determinate the position of the three pad clusters
1385 // Fit with a straight line
1386 // Take the fitted values for all the clusters (3 or 2 pad clusters)
1387 // Fill the PRF as function of angle of the track
1391 //printf("begin\n");
1392 ///////////////////////////////////////////
1393 // Take the parameters of the track
1394 //////////////////////////////////////////
1395 // take now the snp, tnp and tgl from the track
1396 Double_t snp = tracklet->GetSnp(); // sin dy/dx at the end of the chamber
1397 Double_t tnp = 0.0; // dy/dx at the end of the chamber
1398 if( TMath::Abs(snp) < 1.){
1399 tnp = snp / TMath::Sqrt((1.-snp)*(1.+snp));
1401 Double_t tgl = tracklet->GetTgl(); // dz/dl
1402 Double_t dzdx = tgl*TMath::Sqrt(1+tnp*tnp); // dz/dx calculated from dz/dl
1404 //Double_t tnp = tracklet->GetYref(1); // dy/dx at the entrance of the chamber
1405 //Double_t tgl = tracklet->GetZref(1); // dz/dl at the entrance of the chamber
1406 //Double_t dzdx = tgl; //*TMath::Sqrt(1+tnp*tnp); // dz/dx from dz/dl
1407 // at the end with correction due to linear fit
1408 //Double_t tnp = tracklet->GetYfit(1); // dy/dx at the end of the chamber after fit correction
1409 //Double_t tgl = tracklet->GetZfit(1); // dz/dl at the end of the chamber after fit correction
1411 ///////////////////////////////
1412 // Calculate tnp group shift
1413 ///////////////////////////////
1414 Bool_t echec = kFALSE;
1415 Double_t shift = 0.0;
1416 //Calculate the shift in x coresponding to this tnp
1417 if(fNgroupprf != 0.0){
1418 shift = -3.0*(fNgroupprf-1)-1.5;
1419 Double_t limithigh = -0.2*(fNgroupprf-1);
1420 if((tnp < (-0.2*fNgroupprf)) || (tnp > (0.2*fNgroupprf))) echec = kTRUE;
1422 while(tnp > limithigh){
1428 // do nothing if out of tnp range
1429 //printf("echec %d\n",(Int_t)echec);
1430 if(echec) return kFALSE;
1432 ///////////////////////
1434 //////////////////////
1436 Int_t nb3pc = 0; // number of three pads clusters used for fit
1437 // to see the difference between the fit and the 3 pad clusters position
1438 Double_t padPositions[AliTRDseedV1::kNtb];
1439 memset(padPositions, 0, AliTRDseedV1::kNtb*sizeof(Double_t));
1440 fLinearFitterTracklet->ClearPoints();
1442 //printf("loop clusters \n");
1443 ////////////////////////////
1444 // loop over the clusters
1445 ////////////////////////////
1446 AliTRDcluster *cl = 0x0;
1447 for(int ic=0; ic<AliTRDseedV1::kNtb; ic++){
1448 // reject shared clusters on pad row
1449 if((ic+AliTRDseedV1::kNtb) < AliTRDseedV1::kNclusters) {
1450 if((cl = tracklet->GetClusters(ic+AliTRDseedV1::kNtb))) continue;
1452 if(!(cl = tracklet->GetClusters(ic))) continue;
1453 Double_t time = cl->GetPadTime();
1454 if((time<=7) || (time>=21)) continue;
1455 Short_t *signals = cl->GetSignals();
1456 Float_t xcenter = 0.0;
1457 Bool_t echec1 = kTRUE;
1459 /////////////////////////////////////////////////////////////
1460 // Center 3 balanced: position with the center of the pad
1461 /////////////////////////////////////////////////////////////
1462 if ((((Float_t) signals[3]) > 0.0) &&
1463 (((Float_t) signals[2]) > 0.0) &&
1464 (((Float_t) signals[4]) > 0.0)) {
1466 // Security if the denomiateur is 0
1467 if ((((Float_t) (((Float_t) signals[3]) * ((Float_t) signals[3]))) /
1468 ((Float_t) (((Float_t) signals[2]) * ((Float_t) signals[4])))) != 1.0) {
1469 xcenter = 0.5 * (TMath::Log((Float_t) (((Float_t) signals[4]) / ((Float_t) signals[2]))))
1470 / (TMath::Log(((Float_t) (((Float_t) signals[3]) * ((Float_t) signals[3])))
1471 / ((Float_t) (((Float_t) signals[2]) * ((Float_t) signals[4])))));
1477 if(TMath::Abs(xcenter) > 0.5) echec1 = kTRUE;
1478 if(echec1) continue;
1480 ////////////////////////////////////////////////////////
1481 //if no echec1: calculate with the position of the pad
1482 // Position of the cluster
1483 // fill the linear fitter
1484 ///////////////////////////////////////////////////////
1485 Double_t padPosition = xcenter + cl->GetPadCol();
1486 padPositions[ic] = padPosition;
1488 fLinearFitterTracklet->AddPoint(&time, padPosition,1);
1493 //printf("Fin loop clusters \n");
1494 //////////////////////////////
1495 // fit with a straight line
1496 /////////////////////////////
1498 fLinearFitterTracklet->ClearPoints();
1501 fLinearFitterTracklet->Eval();
1503 fLinearFitterTracklet->GetParameters(line);
1504 Float_t pointError = -1.0;
1505 if( fLinearFitterTracklet->GetChisquare()>=0.0) {
1506 pointError = TMath::Sqrt( fLinearFitterTracklet->GetChisquare()/(nb3pc-2));
1508 fLinearFitterTracklet->ClearPoints();
1510 //printf("PRF second loop \n");
1511 ////////////////////////////////////////////////
1512 // Fill the PRF: Second loop over clusters
1513 //////////////////////////////////////////////
1514 for(int ic=0; ic<AliTRDseedV1::kNtb; ic++){
1515 // reject shared clusters on pad row
1516 if(((ic+AliTRDseedV1::kNtb) < AliTRDseedV1::kNclusters) && (cl = tracklet->GetClusters(ic+AliTRDseedV1::kNtb))) continue;
1518 if(!(cl = tracklet->GetClusters(ic))) continue;
1520 Short_t *signals = cl->GetSignals(); // signal
1521 Double_t time = cl->GetPadTime(); // time bin
1522 Float_t padPosTracklet = line[0]+line[1]*time; // reconstruct position from fit
1523 Float_t padPos = cl->GetPadCol(); // middle pad
1524 Double_t dpad = padPosTracklet - padPos; // reconstruct position relative to middle pad from fit
1525 Float_t ycenter = 0.0; // relative center charge
1526 Float_t ymin = 0.0; // relative left charge
1527 Float_t ymax = 0.0; // relative right charge
1529 ////////////////////////////////////////////////////////////////
1530 // Calculate ycenter, ymin and ymax even for two pad clusters
1531 ////////////////////////////////////////////////////////////////
1532 if(((((Float_t) signals[3]) > 0.0) && (((Float_t) signals[2]) > 0.0)) ||
1533 ((((Float_t) signals[3]) > 0.0) && (((Float_t) signals[4]) > 0.0))){
1534 Float_t sum = ((Float_t) signals[2]) + ((Float_t) signals[3]) + ((Float_t) signals[4]);
1535 if(sum > 0.0) ycenter = ((Float_t) signals[3])/ sum;
1536 if(sum > 0.0) ymin = ((Float_t) signals[2])/ sum;
1537 if(sum > 0.0) ymax = ((Float_t) signals[4])/ sum;
1540 /////////////////////////
1541 // Calibration group
1542 ////////////////////////
1543 Int_t rowcl = cl->GetPadRow(); // row of cluster
1544 Int_t colcl = cl->GetPadCol(); // col of cluster
1545 Int_t grouplocal = CalculateCalibrationGroup(2,rowcl,colcl); // calcul the corresponding group
1546 Int_t caligroup = fCalibraMode->GetXbins(2)+ grouplocal; // calcul the corresponding group
1547 Float_t xcl = cl->GetY(); // y cluster
1548 Float_t qcl = cl->GetQ(); // charge cluster
1549 Int_t layer = GetLayer(fDetectorPreviousTrack); // layer
1550 Int_t stack = GetStack(fDetectorPreviousTrack); // stack
1551 Double_t xdiff = dpad; // reconstructed position constant
1552 Double_t x = dpad; // reconstructed position moved
1553 Float_t ep = pointError; // error of fit
1554 Float_t signal1 = (Float_t)signals[1]; // signal at the border
1555 Float_t signal3 = (Float_t)signals[3]; // signal
1556 Float_t signal2 = (Float_t)signals[2]; // signal
1557 Float_t signal4 = (Float_t)signals[4]; // signal
1558 Float_t signal5 = (Float_t)signals[5]; // signal at the border
1562 /////////////////////
1564 ////////////////////
1566 if(fDebugLevel > 0){
1567 if ( !fDebugStreamer ) {
1569 TDirectory *backup = gDirectory;
1570 fDebugStreamer = new TTreeSRedirector("TRDdebugCalibraFill.root");
1571 if ( backup ) backup->cd(); //we don't want to be cd'd to the debug streamer
1576 Float_t y = ycenter;
1577 (* fDebugStreamer) << "HandlePRFtrackletV1"<<
1578 "caligroup="<<caligroup<<
1579 "detector="<<fDetectorPreviousTrack<<
1582 "npoints="<<nbclusters<<
1591 "padPosition="<<padPositions[ic]<<
1592 "padPosTracklet="<<padPosTracklet<<
1597 "signal1="<<signal1<<
1598 "signal2="<<signal2<<
1599 "signal3="<<signal3<<
1600 "signal4="<<signal4<<
1601 "signal5="<<signal5<<
1607 (* fDebugStreamer) << "HandlePRFtrackletV1"<<
1608 "caligroup="<<caligroup<<
1609 "detector="<<fDetectorPreviousTrack<<
1612 "npoints="<<nbclusters<<
1621 "padPosition="<<padPositions[ic]<<
1622 "padPosTracklet="<<padPosTracklet<<
1627 "signal1="<<signal1<<
1628 "signal2="<<signal2<<
1629 "signal3="<<signal3<<
1630 "signal4="<<signal4<<
1631 "signal5="<<signal5<<
1637 (* fDebugStreamer) << "HandlePRFtrackletV1"<<
1638 "caligroup="<<caligroup<<
1639 "detector="<<fDetectorPreviousTrack<<
1642 "npoints="<<nbclusters<<
1651 "padPosition="<<padPositions[ic]<<
1652 "padPosTracklet="<<padPosTracklet<<
1657 "signal1="<<signal1<<
1658 "signal2="<<signal2<<
1659 "signal3="<<signal3<<
1660 "signal4="<<signal4<<
1661 "signal5="<<signal5<<
1667 /////////////////////
1669 /////////////////////
1670 if(nbclusters < fNumberClusters) continue;
1671 if(nbclusters > fNumberClustersf) continue;
1672 if(nb3pc <= 5) continue;
1673 if((time >= 21) || (time < 7)) continue;
1674 if(TMath::Abs(qcl) < 80) continue;
1675 if( TMath::Abs(snp) > 1.) continue;
1678 ////////////////////////
1680 ///////////////////////
1682 if(TMath::Abs(dpad) < 1.5) {
1683 fPRF2d->Fill(shift+dpad,(caligroup+0.5),ycenter);
1684 fPRF2d->Fill(shift-dpad,(caligroup+0.5),ycenter);
1685 //printf("place %f, ycenter %f\n",(shift+dpad),ycenter);
1687 if((ymin > 0.0) && (TMath::Abs(dpad+1.0) < 1.5)) {
1688 fPRF2d->Fill(shift-(dpad+1.0),(caligroup+0.5),ymin);
1689 fPRF2d->Fill(shift+(dpad+1.0),(caligroup+0.5),ymin);
1691 if((ymax > 0.0) && (TMath::Abs(dpad-1.0) < 1.5)) {
1692 fPRF2d->Fill(shift+1.0-dpad,(caligroup+0.5),ymax);
1693 fPRF2d->Fill(shift-1.0+dpad,(caligroup+0.5),ymax);
1698 if(TMath::Abs(dpad) < 1.5) {
1699 fCalibraVector->UpdateVectorPRF(fDetectorPreviousTrack,grouplocal,shift+dpad,ycenter);
1700 fCalibraVector->UpdateVectorPRF(fDetectorPreviousTrack,grouplocal,shift-dpad,ycenter);
1702 if((ymin > 0.0) && (TMath::Abs(dpad+1.0) < 1.5)) {
1703 fCalibraVector->UpdateVectorPRF(fDetectorPreviousTrack,grouplocal,shift-(dpad+1.0),ymin);
1704 fCalibraVector->UpdateVectorPRF(fDetectorPreviousTrack,grouplocal,shift+(dpad+1.0),ymin);
1706 if((ymax > 0.0) && (TMath::Abs(dpad-1.0) < 1.5)) {
1707 fCalibraVector->UpdateVectorPRF(fDetectorPreviousTrack,grouplocal,shift+1.0-dpad,ymax);
1708 fCalibraVector->UpdateVectorPRF(fDetectorPreviousTrack,grouplocal,shift-1.0+dpad,ymax);
1711 } // second loop over clusters
1716 ///////////////////////////////////////////////////////////////////////////////////////
1717 // Pad row col stuff: see if masked or not
1718 ///////////////////////////////////////////////////////////////////////////////////////
1719 //_____________________________________________________________________________
1720 void AliTRDCalibraFillHisto::CheckGoodTrackletV1(const AliTRDcluster *cl)
1723 // See if we are not near a masked pad
1726 if(cl->IsMasked()) fGoodTracklet = kFALSE;
1730 //_____________________________________________________________________________
1731 void AliTRDCalibraFillHisto::CheckGoodTrackletV0(const Int_t detector,const Int_t row,const Int_t col)
1734 // See if we are not near a masked pad
1737 if (!IsPadOn(detector, col, row)) {
1738 fGoodTracklet = kFALSE;
1742 if (!IsPadOn(detector, col-1, row)) {
1743 fGoodTracklet = kFALSE;
1748 if (!IsPadOn(detector, col+1, row)) {
1749 fGoodTracklet = kFALSE;
1754 //_____________________________________________________________________________
1755 Bool_t AliTRDCalibraFillHisto::IsPadOn(Int_t detector, Int_t row, Int_t col) const
1758 // Look in the choosen database if the pad is On.
1759 // If no the track will be "not good"
1762 // Get the parameter object
1763 AliTRDcalibDB *cal = AliTRDcalibDB::Instance();
1765 AliInfo("Could not get calibDB");
1769 if (!cal->IsChamberInstalled(detector) ||
1770 cal->IsChamberMasked(detector) ||
1771 cal->IsPadMasked(detector,col,row)) {
1779 ///////////////////////////////////////////////////////////////////////////////////////
1780 // Calibration groups: calculate the number of groups, localise...
1781 ////////////////////////////////////////////////////////////////////////////////////////
1782 //_____________________________________________________________________________
1783 Int_t AliTRDCalibraFillHisto::CalculateCalibrationGroup(Int_t i, Int_t row, Int_t col) const
1786 // Calculate the calibration group number for i
1789 // Row of the cluster and position in the pad groups
1791 if (fCalibraMode->GetNnZ(i) != 0) {
1792 posr = (Int_t) row / fCalibraMode->GetNnZ(i);
1796 // Col of the cluster and position in the pad groups
1798 if (fCalibraMode->GetNnRphi(i) != 0) {
1799 posc = (Int_t) col / fCalibraMode->GetNnRphi(i);
1802 return posc*fCalibraMode->GetNfragZ(i)+posr;
1805 //____________________________________________________________________________________
1806 Int_t AliTRDCalibraFillHisto::CalculateTotalNumberOfBins(Int_t i)
1809 // Calculate the total number of calibration groups
1815 if((fCalibraMode->GetNz(i)==100) && (fCalibraMode->GetNrphi(i)==100)){
1817 AliInfo(Form("Total number of Xbins: %d for i %d",ntotal,i));
1822 if((fCalibraMode->GetNz(i)==10) && (fCalibraMode->GetNrphi(i)==10)){
1824 AliInfo(Form("Total number of Xbins: %d for i %d",ntotal,i));
1829 fCalibraMode->ModePadCalibration(2,i);
1830 fCalibraMode->ModePadFragmentation(0,2,0,i);
1831 fCalibraMode->SetDetChamb2(i);
1832 ntotal += 6 * 18 * fCalibraMode->GetDetChamb2(i);
1833 fCalibraMode->ModePadCalibration(0,i);
1834 fCalibraMode->ModePadFragmentation(0,0,0,i);
1835 fCalibraMode->SetDetChamb0(i);
1836 ntotal += 6 * 4 * 18 * fCalibraMode->GetDetChamb0(i);
1837 AliInfo(Form("Total number of Xbins: %d for i %d",ntotal,i));
1841 //_____________________________________________________________________________
1842 void AliTRDCalibraFillHisto::SetNz(Int_t i, Short_t Nz)
1845 // Set the mode of calibration group in the z direction for the parameter i
1850 fCalibraMode->SetNz(i, Nz);
1853 AliInfo("You have to choose between 0 and 4");
1857 //_____________________________________________________________________________
1858 void AliTRDCalibraFillHisto::SetNrphi(Int_t i, Short_t Nrphi)
1861 // Set the mode of calibration group in the rphi direction for the parameter i
1866 fCalibraMode->SetNrphi(i ,Nrphi);
1869 AliInfo("You have to choose between 0 and 6");
1874 //_____________________________________________________________________________
1875 void AliTRDCalibraFillHisto::SetAllTogether(Int_t i)
1878 // Set the mode of calibration group all together
1880 if(fVector2d == kTRUE) {
1881 AliInfo("Can not work with the vector method");
1884 fCalibraMode->SetAllTogether(i);
1888 //_____________________________________________________________________________
1889 void AliTRDCalibraFillHisto::SetPerSuperModule(Int_t i)
1892 // Set the mode of calibration group per supermodule
1894 if(fVector2d == kTRUE) {
1895 AliInfo("Can not work with the vector method");
1898 fCalibraMode->SetPerSuperModule(i);
1902 //____________Set the pad calibration variables for the detector_______________
1903 Bool_t AliTRDCalibraFillHisto::LocalisationDetectorXbins(Int_t detector)
1906 // For the detector calcul the first Xbins and set the number of row
1907 // and col pads per calibration groups, the number of calibration
1908 // groups in the detector.
1911 // first Xbins of the detector
1913 fCalibraMode->CalculXBins(detector,0);
1916 fCalibraMode->CalculXBins(detector,1);
1919 fCalibraMode->CalculXBins(detector,2);
1922 // fragmentation of idect
1923 for (Int_t i = 0; i < 3; i++) {
1924 fCalibraMode->ModePadCalibration((Int_t) GetStack(detector),i);
1925 fCalibraMode->ModePadFragmentation((Int_t) GetLayer(detector)
1926 , (Int_t) GetStack(detector)
1927 , (Int_t) GetSector(detector),i);
1933 //_____________________________________________________________________________
1934 void AliTRDCalibraFillHisto::SetNumberGroupsPRF(Short_t numberGroupsPRF)
1937 // Should be between 0 and 6
1940 if ((numberGroupsPRF < 0) || (numberGroupsPRF > 6)) {
1941 AliInfo("The number of groups must be between 0 and 6!");
1944 fNgroupprf = numberGroupsPRF;
1948 ///////////////////////////////////////////////////////////////////////////////////////////
1949 // Per tracklet: store or reset the info, fill the histos with the info
1950 //////////////////////////////////////////////////////////////////////////////////////////
1951 //_____________________________________________________________________________
1952 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)
1955 // Store the infos in fAmpTotal, fPHPlace and fPHValue
1956 // Correct from the gain correction before
1957 // cls is shared cluster if any
1960 //printf("StoreInfoCHPHtrack\n");
1962 // time bin of the cluster not corrected
1963 Int_t time = cl->GetPadTime();
1964 Float_t charge = TMath::Abs(cl->GetQ());
1966 charge += TMath::Abs(cls->GetQ());
1967 //printf("AliTRDCalibraFillHisto::Add the cluster charge");
1970 //printf("Store::time %d, amplitude %f\n",time,dqdl);
1972 //Correct for the gain coefficient used in the database for reconstruction
1973 Float_t correctthegain = 1.0;
1974 if(fIsHLT) correctthegain = fCalDetGain->GetValue(fDetectorPreviousTrack);
1975 else correctthegain = fCalDetGain->GetValue(fDetectorPreviousTrack)*fCalROCGain->GetValue(col,row);
1976 Float_t correction = 1.0;
1977 Float_t normalisation = 6.67;
1978 // we divide with gain in AliTRDclusterizer::Transform...
1979 if( correctthegain > 0 ) normalisation /= correctthegain;
1982 // take dd/dl corrected from the angle of the track
1983 correction = dqdl / (normalisation);
1986 // Fill the fAmpTotal with the charge
1988 if((!fLimitChargeIntegration) || (cl->IsInChamber())) {
1989 //printf("Store::group %d, amplitude %f\n",group[0],correction);
1990 fAmpTotal[(Int_t) group[0]] += correction;
1994 // Fill the fPHPlace and value
1996 fPHPlace[time] = group[1];
1997 fPHValue[time] = charge;
2001 //____________Offine tracking in the AliTRDtracker_____________________________
2002 void AliTRDCalibraFillHisto::ResetfVariablestracklet()
2005 // Reset values per tracklet
2008 //Reset good tracklet
2009 fGoodTracklet = kTRUE;
2011 // Reset the fPHValue
2013 //Reset the fPHValue and fPHPlace
2014 for (Int_t k = 0; k < fTimeMax; k++) {
2020 // Reset the fAmpTotal where we put value
2022 for (Int_t k = 0; k < fCalibraMode->GetNfragZ(0)*fCalibraMode->GetNfragRphi(0); k++) {
2027 //____________Offine tracking in the AliTRDtracker_____________________________
2028 void AliTRDCalibraFillHisto::FillTheInfoOfTheTrackCH(Int_t nbclusters)
2031 // For the offline tracking or mcm tracklets
2032 // This function will be called in the functions UpdateHistogram...
2033 // to fill the info of a track for the relativ gain calibration
2036 Int_t nb = 0; // Nombre de zones traversees
2037 Int_t fd = -1; // Premiere zone non nulle
2038 Float_t totalcharge = 0.0; // Total charge for the supermodule histo
2040 //printf("CH2d nbclusters %d, fNumberClusters %d, fNumberClustersf %d\n",nbclusters,fNumberClusters,fNumberClustersf);
2042 if(nbclusters < fNumberClusters) return;
2043 if(nbclusters > fNumberClustersf) return;
2046 // Normalize with the number of clusters
2047 Double_t normalizeCst = fRelativeScale;
2048 if(fNormalizeNbOfCluster) normalizeCst = normalizeCst*nbclusters;
2050 //printf("Number of groups in one detector %d\n",fCalibraMode->GetNfragZ(0)*fCalibraMode->GetNfragRphi(0));
2052 // See if the track goes through different zones
2053 for (Int_t k = 0; k < fCalibraMode->GetNfragZ(0)*fCalibraMode->GetNfragRphi(0); k++) {
2054 //printf("fAmpTotal %f for %d\n",fAmpTotal[k],k);
2055 if (fAmpTotal[k] > 0.0) {
2056 totalcharge += fAmpTotal[k];
2064 //printf("CH2d: nb %d, fd %d, calibration group %d, amplitude %f, detector %d\n",nb,fd,fCalibraMode->GetXbins(0),fAmpTotal[fd]/normalizeCst,fDetectorPreviousTrack);
2070 fEntriesCH[fCalibraMode->GetXbins(0)+fd]++;
2072 FillCH2d(fCalibraMode->GetXbins(0)+fd,fAmpTotal[fd]/normalizeCst);
2073 //fCH2d->Fill(fAmpTotal[fd]/normalizeCst,fCalibraMode->GetXbins(0)+fd+0.5);
2076 fCalibraVector->UpdateVectorCH(fDetectorPreviousTrack,fd,fAmpTotal[fd]/normalizeCst);
2080 if ((fAmpTotal[fd] > 0.0) &&
2081 (fAmpTotal[fd+1] > 0.0)) {
2082 // One of the two very big
2083 if (fAmpTotal[fd] > fProcent*fAmpTotal[fd+1]) {
2085 FillCH2d(fCalibraMode->GetXbins(0)+fd,fAmpTotal[fd]/normalizeCst);
2086 //fCH2d->Fill(fAmpTotal[fd]/normalizeCst,fCalibraMode->GetXbins(0)+fd+0.5);
2089 fCalibraVector->UpdateVectorCH(fDetectorPreviousTrack,fd,fAmpTotal[fd]/normalizeCst);
2092 fEntriesCH[fCalibraMode->GetXbins(0)+fd]++;
2094 if (fAmpTotal[fd+1] > fProcent*fAmpTotal[fd]) {
2096 FillCH2d(fCalibraMode->GetXbins(0)+fd+1,fAmpTotal[fd+1]/normalizeCst);
2097 //fCH2d->Fill(fAmpTotal[fd+1]/normalizeCst,fCalibraMode->GetXbins(0)+fd+1.5);
2100 fCalibraVector->UpdateVectorCH(fDetectorPreviousTrack,fd+1,fAmpTotal[fd+1]/normalizeCst);
2103 fEntriesCH[fCalibraMode->GetXbins(0)+fd+1]++;
2106 if (fCalibraMode->GetNfragZ(0) > 1) {
2107 if (fAmpTotal[fd] > 0.0) {
2108 if ((fd+fCalibraMode->GetNfragZ(0)) < (fCalibraMode->GetNfragZ(0)*fCalibraMode->GetNfragRphi(0))) {
2109 if (fAmpTotal[fd+fCalibraMode->GetNfragZ(0)] > 0.0) {
2110 // One of the two very big
2111 if (fAmpTotal[fd] > fProcent*fAmpTotal[fd+fCalibraMode->GetNfragZ(0)]) {
2113 FillCH2d(fCalibraMode->GetXbins(0)+fd,fAmpTotal[fd]/normalizeCst);
2114 //fCH2d->Fill(fAmpTotal[fd]/normalizeCst,fCalibraMode->GetXbins(0)+fd+0.5);
2117 fCalibraVector->UpdateVectorCH(fDetectorPreviousTrack,fd,fAmpTotal[fd]/normalizeCst);
2120 fEntriesCH[fCalibraMode->GetXbins(0)+fd]++;
2122 if (fAmpTotal[fd+fCalibraMode->GetNfragZ(0)] > fProcent*fAmpTotal[fd]) {
2124 FillCH2d(fCalibraMode->GetXbins(0)+fd+fCalibraMode->GetNfragZ(0),fAmpTotal[fd+fCalibraMode->GetNfragZ(0)]/normalizeCst);
2125 //fCH2d->Fill(fAmpTotal[fd+fCalibraMode->GetNfragZ(0)]/normalizeCst,fCalibraMode->GetXbins(0)+fd+fCalibraMode->GetNfragZ(0)+0.5);
2128 fEntriesCH[fCalibraMode->GetXbins(0)+fd+fCalibraMode->GetNfragZ(0)]++;
2130 fCalibraVector->UpdateVectorCH(fDetectorPreviousTrack,fd+fCalibraMode->GetNfragZ(0),fAmpTotal[fd+fCalibraMode->GetNfragZ(0)]/normalizeCst);
2141 //____________Offine tracking in the AliTRDtracker_____________________________
2142 void AliTRDCalibraFillHisto::FillTheInfoOfTheTrackPH()
2145 // For the offline tracking or mcm tracklets
2146 // This function will be called in the functions UpdateHistogram...
2147 // to fill the info of a track for the drift velocity calibration
2150 Int_t nb = 1; // Nombre de zones traversees 1, 2 ou plus de 3
2151 Int_t fd1 = -1; // Premiere zone non nulle
2152 Int_t fd2 = -1; // Deuxieme zone non nulle
2153 Int_t k1 = -1; // Debut de la premiere zone
2154 Int_t k2 = -1; // Debut de la seconde zone
2155 Int_t nbclusters = 0; // number of clusters
2159 // See if the track goes through different zones
2160 for (Int_t k = 0; k < fTimeMax; k++) {
2161 if (fPHValue[k] > 0.0) {
2167 if (fPHPlace[k] != fd1) {
2173 if (fPHPlace[k] != fd2) {
2180 // See if noise before and after
2181 if(fMaxCluster > 0) {
2182 if(fPHValue[0] > fMaxCluster) return;
2183 if(fTimeMax > fNbMaxCluster) {
2184 for(Int_t k = (fTimeMax-fNbMaxCluster); k < fTimeMax; k++){
2185 if(fPHValue[k] > fMaxCluster) return;
2190 //printf("nbclusters %d, low limit %d, high limit %d\n",nbclusters,fNumberClusters,fNumberClustersf);
2192 if(nbclusters < fNumberClusters) return;
2193 if(nbclusters > fNumberClustersf) return;
2199 for (Int_t i = 0; i < fTimeMax; i++) {
2201 if(fFillWithZero) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd1)+0.5,(Float_t) fPHValue[i]);
2203 if(((Float_t) fPHValue[i] > 0.0)) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd1)+0.5,(Float_t) fPHValue[i]);
2205 //printf("Fill the time bin %d with %f\n",i,fPHValue[i]);
2208 if(fFillWithZero) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd1,i,fPHValue[i]);
2210 if(((Float_t) fPHValue[i] > 0.0)) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd1,i,fPHValue[i]);
2216 if ((fd1 == fd2+1) ||
2218 // One of the two fast all the think
2219 if (k2 > (k1+fDifference)) {
2220 //we choose to fill the fd1 with all the values
2222 for (Int_t i = 0; i < fTimeMax; i++) {
2224 if(fFillWithZero) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd1)+0.5,(Float_t) fPHValue[i]);
2226 if(((Float_t) fPHValue[i] > 0.0)) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd1)+0.5,(Float_t) fPHValue[i]);
2230 if(fFillWithZero) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd1,i,fPHValue[i]);
2232 if(((Float_t) fPHValue[i] > 0.0)) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd1,i,fPHValue[i]);
2237 if ((k2+fDifference) < fTimeMax) {
2238 //we choose to fill the fd2 with all the values
2240 for (Int_t i = 0; i < fTimeMax; i++) {
2242 if(fFillWithZero) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd2)+0.5,(Float_t) fPHValue[i]);
2244 if(((Float_t) fPHValue[i] > 0.0)) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd2)+0.5,(Float_t) fPHValue[i]);
2248 if(fFillWithZero) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd2,i,fPHValue[i]);
2250 if(((Float_t) fPHValue[i] > 0.0)) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd2,i,fPHValue[i]);
2256 // Two zones voisines sinon rien!
2257 if (fCalibraMode->GetNfragZ(1) > 1) {
2259 if ((fd1+fCalibraMode->GetNfragZ(1)) < (fCalibraMode->GetNfragZ(1)*fCalibraMode->GetNfragRphi(1))) {
2260 if (fd2 == (fd1+fCalibraMode->GetNfragZ(1))) {
2261 // One of the two fast all the think
2262 if (k2 > (k1+fDifference)) {
2263 //we choose to fill the fd1 with all the values
2265 for (Int_t i = 0; i < fTimeMax; i++) {
2267 if(fFillWithZero) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd1)+0.5,(Float_t) fPHValue[i]);
2269 if(((Float_t) fPHValue[i] > 0.0)) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd1)+0.5,(Float_t) fPHValue[i]);
2273 if(fFillWithZero) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd1,i,fPHValue[i]);
2275 if(((Float_t) fPHValue[i] > 0.0)) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd1,i,fPHValue[i]);
2280 if ((k2+fDifference) < fTimeMax) {
2281 //we choose to fill the fd2 with all the values
2283 for (Int_t i = 0; i < fTimeMax; i++) {
2285 if(fFillWithZero) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd2)+0.5,(Float_t) fPHValue[i]);
2287 if(((Float_t) fPHValue[i] > 0.0)) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd2)+0.5,(Float_t) fPHValue[i]);
2291 if(fFillWithZero) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd2,i,fPHValue[i]);
2293 if(((Float_t) fPHValue[i] > 0.0)) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd2,i,fPHValue[i]);
2300 // Two zones voisines sinon rien!
2302 if ((fd1 - fCalibraMode->GetNfragZ(1)) >= 0) {
2303 if (fd2 == (fd1 - fCalibraMode->GetNfragZ(1))) {
2304 // One of the two fast all the think
2305 if (k2 > (k1 + fDifference)) {
2306 //we choose to fill the fd1 with all the values
2308 for (Int_t i = 0; i < fTimeMax; i++) {
2310 if(fFillWithZero) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd1)+0.5,(Float_t) fPHValue[i]);
2312 if(((Float_t) fPHValue[i] > 0.0)) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd1)+0.5,(Float_t) fPHValue[i]);
2316 if(fFillWithZero) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd1,i,fPHValue[i]);
2318 if(((Float_t) fPHValue[i] > 0.0)) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd1,i,fPHValue[i]);
2323 if ((k2+fDifference) < fTimeMax) {
2324 //we choose to fill the fd2 with all the values
2326 for (Int_t i = 0; i < fTimeMax; i++) {
2328 if(fFillWithZero) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd2)+0.5,(Float_t) fPHValue[i]);
2330 if(((Float_t) fPHValue[i] > 0.0)) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd2)+0.5,(Float_t) fPHValue[i]);
2334 if(fFillWithZero) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd2,i,fPHValue[i]);
2336 if(((Float_t) fPHValue[i] > 0.0)) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd2,i,fPHValue[i]);
2348 //////////////////////////////////////////////////////////////////////////////////////////
2349 // DAQ process functions
2350 /////////////////////////////////////////////////////////////////////////////////////////
2351 //_____________________________________________________________________
2352 Int_t AliTRDCalibraFillHisto::ProcessEventDAQ(AliTRDrawStreamBase *rawStream, Bool_t nocheck)
2355 // Event Processing loop - AliTRDrawStreamBase
2356 // TestBeam 2007 version
2357 // 0 timebin problem
2360 // Same algorithm as TestBeam but different reader
2363 rawStream->SetSharedPadReadout(kFALSE);
2365 Int_t withInput = 1;
2367 Double_t phvalue[16][144][36];
2368 for(Int_t k = 0; k < 36; k++){
2369 for(Int_t j = 0; j < 16; j++){
2370 for(Int_t c = 0; c < 144; c++){
2371 phvalue[j][c][k] = 0.0;
2376 fDetectorPreviousTrack = -1;
2379 Int_t nbtimebin = 0;
2380 Int_t baseline = 10;
2381 //printf("------------Detector\n");
2387 while (rawStream->Next()) {
2389 Int_t idetector = rawStream->GetDet(); // current detector
2390 Int_t imcm = rawStream->GetMCM(); // current MCM
2391 Int_t irob = rawStream->GetROB(); // current ROB
2393 //printf("Detector %d\n",idetector);
2395 if((fDetectorPreviousTrack != idetector) && (fDetectorPreviousTrack != -1)){
2398 withInput = TMath::Max(FillDAQ(phvalue),withInput);
2402 for(Int_t k = 0; k < 36; k++){
2403 for(Int_t j = 0; j < 16; j++){
2404 for(Int_t c = 0; c < 144; c++){
2405 phvalue[j][c][k] = 0.0;
2411 fDetectorPreviousTrack = idetector;
2412 fMCMPrevious = imcm;
2413 fROBPrevious = irob;
2415 nbtimebin = rawStream->GetNumberOfTimeBins(); // number of time bins read from data
2416 if(nbtimebin == 0) return 0;
2417 if((fTimeMax != 0) && (nbtimebin != fTimeMax)) return 0;
2418 fTimeMax = nbtimebin;
2420 //baseline = rawStream->GetCommonAdditive(); // common additive baseline
2421 fNumberClustersf = fTimeMax;
2422 fNumberClusters = (Int_t)(fNumberClustersProcent*fTimeMax);
2425 Int_t *signal = rawStream->GetSignals(); // current ADC signal
2426 Int_t col = rawStream->GetCol();
2427 Int_t row = rawStream->GetRow();
2430 // printf("detector %d, signal[0] %d, signal[1] %d, signal[2] %d, baseline %d\n",idetector,signal[0],signal[1],signal[2], baseline);
2433 for(Int_t itime = 0; itime < nbtimebin; itime++){
2434 phvalue[row][col][itime] = signal[itime]-baseline;
2438 // fill the last one
2439 if(fDetectorPreviousTrack != -1){
2442 withInput = TMath::Max(FillDAQ(phvalue),withInput);
2445 for(Int_t k = 0; k < 36; k++){
2446 for(Int_t j = 0; j < 16; j++){
2447 for(Int_t c = 0; c < 144; c++){
2448 phvalue[j][c][k] = 0.0;
2457 while (rawStream->Next()) { //iddetecte
2459 Int_t idetector = rawStream->GetDet(); // current detector
2460 Int_t imcm = rawStream->GetMCM(); // current MCM
2461 Int_t irob = rawStream->GetROB(); // current ROB
2463 //printf("Detector %d\n",idetector);
2465 if((fDetectorPreviousTrack != idetector) && (fDetectorPreviousTrack != -1)){
2468 withInput = TMath::Max(FillDAQ(phvalue),withInput);
2471 for(Int_t k = 0; k < 36; k++){
2472 for(Int_t j = 0; j < 16; j++){
2473 for(Int_t c = 0; c < 144; c++){
2474 phvalue[j][c][k] = 0.0;
2480 fDetectorPreviousTrack = idetector;
2481 fMCMPrevious = imcm;
2482 fROBPrevious = irob;
2484 //baseline = rawStream->GetCommonAdditive(); // common baseline
2486 fTimeMax = rawStream->GetNumberOfTimeBins(); // number of time bins read from data
2487 fNumberClustersf = fTimeMax;
2488 fNumberClusters = (Int_t)(fNumberClustersProcent*fTimeMax);
2489 Int_t *signal = rawStream->GetSignals(); // current ADC signal
2490 Int_t col = rawStream->GetCol();
2491 Int_t row = rawStream->GetRow();
2494 //printf("detector %d, signal[0] %d, signal[1] %d, signal[2] %d, baseline %d\n",idetector,signal[0],signal[1],signal[2], baseline);
2496 for(Int_t itime = 0; itime < fTimeMax; itime++){
2497 phvalue[row][col][itime] = signal[itime]-baseline;
2498 /*if(phvalue[row][col][itime] >= 20) {
2499 printf("----------> phvalue[%d][%d][%d] %d baseline %d \n",
2509 // fill the last one
2510 if(fDetectorPreviousTrack != -1){
2513 withInput = TMath::Max(FillDAQ(phvalue),withInput);
2516 for(Int_t k = 0; k < 36; k++){
2517 for(Int_t j = 0; j < 16; j++){
2518 for(Int_t c = 0; c < 144; c++){
2519 phvalue[j][c][k] = 0.0;
2529 //_____________________________________________________________________
2530 Int_t AliTRDCalibraFillHisto::ProcessEventDAQ(AliRawReader *rawReader, Bool_t nocheck)
2533 // Event processing loop - AliRawReader
2534 // Testbeam 2007 version
2537 AliTRDrawStreamBase rawStream(rawReader);
2539 rawReader->Select("TRD");
2541 return ProcessEventDAQ(&rawStream, nocheck);
2544 //_________________________________________________________________________
2545 Int_t AliTRDCalibraFillHisto::ProcessEventDAQ(
2547 const eventHeaderStruct *event,
2550 const eventHeaderStruct* /*event*/,
2557 // process date event
2558 // Testbeam 2007 version
2561 AliRawReader *rawReader = new AliRawReaderDate((void*)event);
2562 Int_t result=ProcessEventDAQ(rawReader, nocheck);
2566 Fatal("AliTRDCalibraFillHisto", "this class was compiled without DATE");
2571 //_____________________________________________________________________
2572 Int_t AliTRDCalibraFillHisto::ProcessEventDAQ2(AliRawReader *rawReader)
2575 // Event Processing loop - AliTRDrawFastStream
2577 // 0 timebin problem
2580 // Same algorithm as TestBeam but different reader
2583 // AliTRDrawFastStream *rawStream = AliTRDrawFastStream::GetRawStream(rawReader);
2584 AliTRDrawFastStream *rawStream = new AliTRDrawFastStream(rawReader);
2585 rawStream->SetNoErrorWarning();
2586 rawStream->SetSharedPadReadout(kFALSE);
2588 AliTRDdigitsManager *digitsManager = new AliTRDdigitsManager(kTRUE);
2589 digitsManager->CreateArrays();
2591 Int_t withInput = 1;
2593 Double_t phvalue[16][144][36];
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;
2602 fDetectorPreviousTrack = -1;
2606 Int_t nbtimebin = 0;
2607 Int_t baseline = 10;
2613 while ((det = rawStream->NextChamber(digitsManager, NULL, NULL)) >= 0) { //idetector
2615 if (digitsManager->GetIndexes(det)->HasEntry()) {//QA
2616 // printf("there is ADC data on this chamber!\n");
2618 AliTRDarrayADC *digits = (AliTRDarrayADC *) digitsManager->GetDigits(det); //mod
2619 if (digits->HasData()) { //array
2621 AliTRDSignalIndex *indexes = digitsManager->GetIndexes(det);
2622 if (indexes->IsAllocated() == kFALSE) {
2623 AliError("Indexes do not exist!");
2628 indexes->ResetCounters();
2630 while (indexes->NextRCIndex(iRow, iCol)) { //column,row
2631 //printf(" det %d \t row %d \t col %d \t digit\n",det,iRow,iCol);
2632 //while (rawStream->Next()) {
2634 Int_t idetector = det; // current detector
2635 //Int_t imcm = rawStream->GetMCM(); // current MCM
2636 //Int_t irob = rawStream->GetROB(); // current ROB
2639 if((fDetectorPreviousTrack != idetector) && (fDetectorPreviousTrack != -1)) {
2641 withInput = TMath::Max(FillDAQ(phvalue),withInput);
2644 for(Int_t k = 0; k < 36; k++){
2645 for(Int_t j = 0; j < 16; j++){
2646 for(Int_t c = 0; c < 144; c++){
2647 phvalue[j][c][k] = 0.0;
2653 fDetectorPreviousTrack = idetector;
2654 //fMCMPrevious = imcm;
2655 //fROBPrevious = irob;
2657 // nbtimebin = rawStream->GetNumberOfTimeBins(); // number of time bins read from data
2658 AliTRDdigitsParam *digitParam = (AliTRDdigitsParam *)digitsManager->GetDigitsParam();
2659 nbtimebin = digitParam->GetNTimeBins(det); // number of time bins read from data
2660 baseline = digitParam->GetADCbaseline(det); // baseline
2662 if(nbtimebin == 0) return 0;
2663 if((fTimeMax != 0) && (nbtimebin != fTimeMax)) return 0;
2664 fTimeMax = nbtimebin;
2666 fNumberClustersf = fTimeMax;
2667 fNumberClusters = (Int_t)(fNumberClustersProcent*fTimeMax);
2670 for(Int_t itime = 0; itime < nbtimebin; itime++) {
2671 // phvalue[row][col][itime] = signal[itime]-baseline;
2672 phvalue[iRow][iCol][itime] = (Short_t)(digits->GetData(iRow,iCol,itime) - baseline);
2673 /*if(phvalue[iRow][iCol][itime] >= 20) {
2674 printf("----------> phvalue[%d][%d][%d] %d baseline %d \n",
2678 (Short_t)(digits->GetData(iRow,iCol,itime)),
2685 // fill the last one
2686 if(fDetectorPreviousTrack != -1){
2689 withInput = TMath::Max(FillDAQ(phvalue),withInput);
2690 // printf("\n ---> withinput %d\n\n",withInput);
2692 for(Int_t k = 0; k < 36; k++){
2693 for(Int_t j = 0; j < 16; j++){
2694 for(Int_t c = 0; c < 144; c++){
2695 phvalue[j][c][k] = 0.0;
2703 digitsManager->ClearArrays(det);
2705 delete digitsManager;
2710 //_____________________________________________________________________
2711 Int_t AliTRDCalibraFillHisto::ProcessEventDAQ3(AliRawReader *rawReader)
2714 // Event Processing loop - AliTRDrawStream
2716 // 0 timebin problem
2719 // Same algorithm as TestBeam but different reader
2722 // AliTRDrawFastStream *rawStream = AliTRDrawFastStream::GetRawStream(rawReader);
2723 AliTRDrawStream *rawStream = new AliTRDrawStream(rawReader);
2724 rawStream->SetNoErrorWarning();
2725 rawStream->SetSharedPadReadout(kFALSE);
2727 AliTRDdigitsManager *digitsManager = new AliTRDdigitsManager(kTRUE);
2728 digitsManager->CreateArrays();
2730 Int_t withInput = 1;
2732 Double_t phvalue[16][144][36];
2733 for(Int_t k = 0; k < 36; k++){
2734 for(Int_t j = 0; j < 16; j++){
2735 for(Int_t c = 0; c < 144; c++){
2736 phvalue[j][c][k] = 0.0;
2741 fDetectorPreviousTrack = -1;
2745 Int_t nbtimebin = 0;
2746 Int_t baseline = 10;
2752 while ((det = rawStream->NextChamber(digitsManager, NULL, NULL)) >= 0) { //idetector
2754 if (digitsManager->GetIndexes(det)->HasEntry()) {//QA
2755 // printf("there is ADC data on this chamber!\n");
2757 AliTRDarrayADC *digits = (AliTRDarrayADC *) digitsManager->GetDigits(det); //mod
2758 if (digits->HasData()) { //array
2760 AliTRDSignalIndex *indexes = digitsManager->GetIndexes(det);
2761 if (indexes->IsAllocated() == kFALSE) {
2762 AliError("Indexes do not exist!");
2767 indexes->ResetCounters();
2769 while (indexes->NextRCIndex(iRow, iCol)) { //column,row
2770 //printf(" det %d \t row %d \t col %d \t digit\n",det,iRow,iCol);
2771 //while (rawStream->Next()) {
2773 Int_t idetector = det; // current detector
2774 //Int_t imcm = rawStream->GetMCM(); // current MCM
2775 //Int_t irob = rawStream->GetROB(); // current ROB
2778 if((fDetectorPreviousTrack != idetector) && (fDetectorPreviousTrack != -1)) {
2780 withInput = TMath::Max(FillDAQ(phvalue),withInput);
2783 for(Int_t k = 0; k < 36; k++){
2784 for(Int_t j = 0; j < 16; j++){
2785 for(Int_t c = 0; c < 144; c++){
2786 phvalue[j][c][k] = 0.0;
2792 fDetectorPreviousTrack = idetector;
2793 //fMCMPrevious = imcm;
2794 //fROBPrevious = irob;
2796 // nbtimebin = rawStream->GetNumberOfTimeBins(); // number of time bins read from data
2797 AliTRDdigitsParam *digitParam = (AliTRDdigitsParam *)digitsManager->GetDigitsParam();
2798 nbtimebin = digitParam->GetNTimeBins(det); // number of time bins read from data
2799 baseline = digitParam->GetADCbaseline(det); // baseline
2801 if(nbtimebin == 0) return 0;
2802 if((fTimeMax != 0) && (nbtimebin != fTimeMax)) return 0;
2803 fTimeMax = nbtimebin;
2805 fNumberClustersf = fTimeMax;
2806 fNumberClusters = (Int_t)(fNumberClustersProcent*fTimeMax);
2809 for(Int_t itime = 0; itime < nbtimebin; itime++) {
2810 // phvalue[row][col][itime] = signal[itime]-baseline;
2811 phvalue[iRow][iCol][itime] = (Short_t)(digits->GetData(iRow,iCol,itime) - baseline);
2812 /*if(phvalue[iRow][iCol][itime] >= 20) {
2813 printf("----------> phvalue[%d][%d][%d] %d baseline %d \n",
2817 (Short_t)(digits->GetData(iRow,iCol,itime)),
2824 // fill the last one
2825 if(fDetectorPreviousTrack != -1){
2828 withInput = TMath::Max(FillDAQ(phvalue),withInput);
2829 // printf("\n ---> withinput %d\n\n",withInput);
2831 for(Int_t k = 0; k < 36; k++){
2832 for(Int_t j = 0; j < 16; j++){
2833 for(Int_t c = 0; c < 144; c++){
2834 phvalue[j][c][k] = 0.0;
2842 digitsManager->ClearArrays(det);
2844 delete digitsManager;
2849 //_____________________________________________________________________
2850 //////////////////////////////////////////////////////////////////////////////
2851 // Routine inside the DAQ process
2852 /////////////////////////////////////////////////////////////////////////////
2853 //_______________________________________________________________________
2854 Int_t AliTRDCalibraFillHisto::FillDAQ(Double_t phvalue[16][144][36]){
2857 // Look for the maximum by collapsing over the time
2858 // Sum over four pad col and two pad row
2864 Int_t idect = fDetectorPreviousTrack;
2865 //printf("Enter Detector %d\n",fDetectorPreviousTrack);
2867 for(Int_t tb = 0; tb < 36; tb++){
2871 //fGoodTracklet = kTRUE;
2872 //fDetectorPreviousTrack = 0;
2875 ///////////////////////////
2877 /////////////////////////
2881 Double_t integralMax = -1;
2883 for (Int_t ir = 1; ir <= 15; ir++)
2885 for (Int_t ic = 2; ic <= 142; ic++)
2887 Double_t integral = 0;
2888 for (Int_t ishiftR = 0; ishiftR < fNumberRowDAQ; ishiftR++)
2890 for (Int_t ishiftC = -fNumberColDAQ; ishiftC < fNumberColDAQ; ishiftC++)
2892 if (ir + ishiftR >= 1 && ir + ishiftR <= 16 &&
2893 ic + ishiftC >= 1 && ic + ishiftC <= 144)
2896 for(Int_t tb = 0; tb< fTimeMax; tb++){
2897 integral += phvalue[ir + ishiftR-1][ic + ishiftC-1][tb];
2902 if (integralMax < integral)
2906 integralMax = integral;
2908 } // check max integral
2912 // printf("imaxRow %d, imaxCol %d, fTimeMax %d, integralMax %f\n",imaxRow,imaxCol,fTimeMax, integralMax);
2913 //if((imaxRow == 0) || (imaxRow >= 15) || (imaxCol <= 3) || (imaxCol >= 140)) {
2918 if(((imaxRow + fNumberRowDAQ) > 16) || (imaxRow == 0) || ((imaxCol - fNumberColDAQ) <= 1) || ((imaxCol + fNumberColDAQ) >= 144)) {
2922 //CheckGoodTrackletV0(fDetectorPreviousTrack,imaxRow,imaxCol);
2923 //if(!fGoodTracklet) used = 1;;
2925 // /////////////////////////////////////////////////////
2926 // sum ober 2 row and 4 pad cols for each time bins
2927 // ////////////////////////////////////////////////////
2931 for (Int_t ishiftR = 0; ishiftR < fNumberRowDAQ; ishiftR++)
2933 for (Int_t ishiftC = -fNumberColDAQ; ishiftC < fNumberColDAQ; ishiftC++)
2935 if (imaxRow + ishiftR >= 1 && imaxRow + ishiftR <= 16 &&
2936 imaxCol + ishiftC >= 1 && imaxCol + ishiftC <= 144)
2938 for(Int_t it = 0; it < fTimeMax; it++){
2939 sum[it] += phvalue[imaxRow + ishiftR-1][imaxCol + ishiftC-1][it];
2946 Double_t sumcharge = 0.0;
2947 for(Int_t it = 0; it < fTimeMax; it++){
2948 sumcharge += sum[it];
2949 if(sum[it] > fThresholdClustersDAQ) nbcl++;
2953 /////////////////////////////////////////////////////////
2955 ////////////////////////////////////////////////////////
2956 if(fDebugLevel > 0){
2957 if ( !fDebugStreamer ) {
2959 TDirectory *backup = gDirectory;
2960 fDebugStreamer = new TTreeSRedirector("TRDdebugCalibraFill.root");
2961 if ( backup ) backup->cd(); //we don't want to be cd'd to the debug streamer
2964 Double_t amph0 = sum[0];
2965 Double_t amphlast = sum[fTimeMax-1];
2966 Double_t rms = TMath::RMS(fTimeMax,sum);
2967 Int_t goodtracklet = (Int_t) fGoodTracklet;
2968 for(Int_t it = 0; it < fTimeMax; it++){
2969 Double_t clustera = sum[it];
2971 (* fDebugStreamer) << "FillDAQa"<<
2972 "ampTotal="<<sumcharge<<
2975 "detector="<<idect<<
2977 "amphlast="<<amphlast<<
2978 "goodtracklet="<<goodtracklet<<
2979 "clustera="<<clustera<<
2987 ////////////////////////////////////////////////////////
2989 ///////////////////////////////////////////////////////
2990 //printf("fNumberClusters %d, fNumberClustersf %d\n",fNumberClusters,fNumberClustersf);
2991 if(sum[0] > 100.0) used = 1;
2992 if(nbcl < fNumberClusters) used = 1;
2993 if(nbcl > fNumberClustersf) used = 1;
2995 //if(fDetectorPreviousTrack == 15){
2996 // printf("rms %f and first time bin %f\n",TMath::RMS(fTimeMax,sum),sum[0]);
2998 //if((TMath::RMS(fTimeMax,sum) <= 10.0) && (sum[0] > 200.0)) return 1;
3000 for(Int_t it = 0; it < fTimeMax; it++){
3001 if(fFillWithZero) UpdateDAQ(fDetectorPreviousTrack,0,0,it,sum[it],fTimeMax);
3003 if(sum[it] > 0.0) UpdateDAQ(fDetectorPreviousTrack,0,0,it,sum[it],fTimeMax);
3005 //if(fFillWithZero) UpdateDAQ(0,0,0,it,sum[it],fTimeMax);
3007 // if(sum[it] > 0.0) UpdateDAQ(0,0,0,it,sum[it],fTimeMax);
3012 //((TH2I *)GetCH2d()->Fill(sumcharge/30.0,fDetectorPreviousTrack));
3014 //printf("Pass Detector %d\n",fDetectorPreviousTrack);
3021 //____________Online trackling in AliTRDtrigger________________________________
3022 Bool_t AliTRDCalibraFillHisto::UpdateDAQ(Int_t det, Int_t /*row*/, Int_t /*col*/, Int_t timebin, Float_t signal, Int_t nbtimebins)
3026 // Fill a simple average pulse height
3030 ((TProfile2D *)GetPH2d(nbtimebins,fSf))->Fill((Float_t) timebin/fSf,det+0.5,(Float_t) signal);
3036 //____________Write_____________________________________________________
3037 //_____________________________________________________________________
3038 void AliTRDCalibraFillHisto::Write2d(const Char_t *filename, Bool_t append)
3041 // Write infos to file
3045 if ( fDebugStreamer ) {
3046 delete fDebugStreamer;
3047 fDebugStreamer = 0x0;
3050 AliInfo(Form("Numbertrack: %d Numberusedch[0]: %d, Numberusedch[1]: %d Numberusedph[0]: %d, Numberusedph[1]: %d"
3055 ,fNumberUsedPh[1]));
3057 TDirectory *backup = gDirectory;
3063 option = "recreate";
3065 TFile f(filename,option.Data());
3067 TStopwatch stopwatch;
3070 f.WriteTObject(fCalibraVector);
3075 f.WriteTObject(fCH2d);
3080 f.WriteTObject(fPH2d);
3085 f.WriteTObject(fPRF2d);
3088 if(fLinearFitterOn){
3089 if(fLinearFitterDebugOn) AnalyseLinearFitter();
3090 f.WriteTObject(fLinearVdriftFit);
3095 if ( backup ) backup->cd();
3097 AliInfo(Form("Execution time Write2d: R:%.2fs C:%.2fs"
3098 ,stopwatch.RealTime(),stopwatch.CpuTime()));
3100 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
3102 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
3103 //___________________________________________probe the histos__________________________________________________
3104 Double_t *AliTRDCalibraFillHisto::StatH(TH2 *h, Int_t i)
3107 // Check the number of stats in h, 0 is TH2I 1 is TProfile2D
3108 // debug mode with 2 for TH2I and 3 for TProfile2D
3109 // It gives a pointer to a Double_t[7] with the info following...
3110 // [0] : number of calibration groups with entries
3111 // [1] : minimal number of entries found
3112 // [2] : calibration group number of the min
3113 // [3] : maximal number of entries found
3114 // [4] : calibration group number of the max
3115 // [5] : mean number of entries found
3116 // [6] : mean relative error
3119 Double_t *info = new Double_t[7];
3121 // Number of Xbins (detectors or groups of pads)
3122 Int_t nbins = h->GetNbinsY(); //number of calibration groups
3123 Int_t nxbins = h->GetNbinsX(); //number of bins per histo
3126 Double_t nbwe = 0; //number of calibration groups with entries
3127 Double_t minentries = 0; //minimal number of entries found
3128 Double_t maxentries = 0; //maximal number of entries found
3129 Double_t placemin = 0; //calibration group number of the min
3130 Double_t placemax = -1; //calibration group number of the max
3131 Double_t meanstats = 0.0; //mean number of entries over the calibration group with at least ome entry
3132 Double_t meanrelativerror = 0.0; //mean relativ error in the TProfile2D
3134 Double_t counter = 0;
3137 TH1F *nbEntries = 0x0;//distribution of the number of entries
3138 TH1F *nbEntriesPerGroup = 0x0;//Number of entries per group
3139 TProfile *nbEntriesPerSp = 0x0;//Number of entries for one supermodule
3141 // Beginning of the loop over the calibration groups
3142 for (Int_t idect = 0; idect < nbins; idect++) {
3144 TH1I *projch = (TH1I *) h->ProjectionX("projch",idect+1,idect+1,(Option_t *)"e");
3145 projch->SetDirectory(0);
3147 // Number of entries for this calibration group
3148 Double_t nentries = 0.0;
3150 for (Int_t k = 0; k < nxbins; k++) {
3151 nentries += h->GetBinContent(h->GetBin(k+1,idect+1));
3155 for (Int_t k = 0; k < nxbins; k++) {
3156 nentries += ((TProfile2D *)h)->GetBinEntries(h->GetBin(k+1,idect+1));
3157 if(h->GetBinContent(h->GetBin(k+1,idect+1)) != 0) {
3158 meanrelativerror += (h->GetBinError(h->GetBin(k+1,idect+1))/(TMath::Abs(h->GetBinContent(h->GetBin(k+1,idect+1)))));
3166 if((!((Bool_t)nbEntries)) && (nentries > 0)){
3167 nbEntries = new TH1F("Number of entries","Number of entries"
3168 ,100,(Int_t)nentries/2,nentries*2);
3169 nbEntries->SetDirectory(0);
3170 nbEntriesPerGroup = new TH1F("Number of entries per group","Number of entries per group"
3172 nbEntriesPerGroup->SetDirectory(0);
3173 nbEntriesPerSp = new TProfile("Number of entries per supermodule","Number of entries per supermodule"
3174 ,(Int_t)(nbins/18),0,(Int_t)(nbins/18));
3175 nbEntriesPerSp->SetDirectory(0);
3178 if(nentries > 0) nbEntries->Fill(nentries);
3179 nbEntriesPerGroup->Fill(idect+0.5,nentries);
3180 nbEntriesPerSp->Fill((idect%((Int_t)(nbins/18)))+0.5,nentries);
3185 if(nentries > maxentries){
3186 maxentries = nentries;
3190 minentries = nentries;
3192 if(nentries < minentries){
3193 minentries = nentries;
3199 meanstats += nentries;
3201 }//calibration groups loop
3203 if(nbwe > 0) meanstats /= nbwe;
3204 if(counter > 0) meanrelativerror /= counter;
3206 AliInfo(Form("There are %f calibration groups with entries",nbwe));
3207 AliInfo(Form("The minimum number of entries is %f for the group %f",minentries,placemin));
3208 AliInfo(Form("The maximum number of entries is %f for the group %f",maxentries,placemax));
3209 AliInfo(Form("The mean number of entries is %f",meanstats));
3210 if((i%2) == 1) AliInfo(Form("The mean relative error is %f",meanrelativerror));
3213 info[1] = minentries;
3215 info[3] = maxentries;
3217 info[5] = meanstats;
3218 info[6] = meanrelativerror;
3221 gStyle->SetPalette(1);
3222 gStyle->SetOptStat(1111);
3223 gStyle->SetPadBorderMode(0);
3224 gStyle->SetCanvasColor(10);
3225 gStyle->SetPadLeftMargin(0.13);
3226 gStyle->SetPadRightMargin(0.01);
3227 TCanvas *stat = new TCanvas("stat","",50,50,600,800);
3230 nbEntries->Draw("");
3232 nbEntriesPerSp->SetStats(0);
3233 nbEntriesPerSp->Draw("");
3234 TCanvas *stat1 = new TCanvas("stat1","",50,50,600,800);
3236 nbEntriesPerGroup->SetStats(0);
3237 nbEntriesPerGroup->Draw("");
3243 //____________________________________________________________________________
3244 Double_t *AliTRDCalibraFillHisto::GetMeanMedianRMSNumberCH()
3247 // Return a Int_t[4] with:
3248 // 0 Mean number of entries
3249 // 1 median of number of entries
3250 // 2 rms of number of entries
3251 // 3 number of group with entries
3254 Double_t *stat = new Double_t[4];
3257 Int_t nbofgroups = CalculateTotalNumberOfBins(0);
3258 Double_t *weight = new Double_t[nbofgroups];
3259 Int_t *nonul = new Int_t[nbofgroups];
3261 for(Int_t k = 0; k < nbofgroups; k++){
3262 if(fEntriesCH[k] > 0) {
3264 nonul[(Int_t)stat[3]] = fEntriesCH[k];
3267 else weight[k] = 0.0;
3269 stat[0] = TMath::Mean(nbofgroups,fEntriesCH,weight);
3270 stat[1] = TMath::Median(nbofgroups,fEntriesCH,weight);
3271 stat[2] = TMath::RMS((Int_t)stat[3],nonul);
3276 //____________________________________________________________________________
3277 Double_t *AliTRDCalibraFillHisto::GetMeanMedianRMSNumberLinearFitter() const
3280 // Return a Int_t[4] with:
3281 // 0 Mean number of entries
3282 // 1 median of number of entries
3283 // 2 rms of number of entries
3284 // 3 number of group with entries
3287 Double_t *stat = new Double_t[4];
3290 Int_t nbofgroups = 540;
3291 Double_t *weight = new Double_t[nbofgroups];
3292 Int_t *nonul = new Int_t[nbofgroups];
3294 for(Int_t k = 0; k < nbofgroups; k++){
3295 if(fEntriesLinearFitter[k] > 0) {
3297 nonul[(Int_t) stat[3]] = fEntriesLinearFitter[k];
3300 else weight[k] = 0.0;
3302 stat[0] = TMath::Mean(nbofgroups,fEntriesLinearFitter,weight);
3303 stat[1] = TMath::Median(nbofgroups,fEntriesLinearFitter,weight);
3304 stat[2] = TMath::RMS((Int_t)stat[3],nonul);
3309 //////////////////////////////////////////////////////////////////////////////////////
3311 //////////////////////////////////////////////////////////////////////////////////////
3312 //_____________________________________________________________________________
3313 void AliTRDCalibraFillHisto::CreatePRF2d(Int_t nn)
3316 // Create the 2D histos: here we have 2*fNgroupprf bins in tnp of 0.2 amplitude each
3317 // If fNgroupprf is zero then no binning in tnp
3321 name += fCalibraMode->GetNz(2);
3323 name += fCalibraMode->GetNrphi(2);
3327 if(fNgroupprf != 0){
3329 fPRF2d = new TProfile2D("PRF2d",(const Char_t *) name
3330 ,2*fNgroupprf*fNumberBinPRF,-3.0*fNgroupprf,3.0*fNgroupprf,nn,0,nn);
3331 fPRF2d->SetYTitle("Det/pad groups");
3332 fPRF2d->SetXTitle("Position x/W [pad width units]");
3333 fPRF2d->SetZTitle("Q_{i}/Q_{total}");
3334 fPRF2d->SetStats(0);
3337 fPRF2d = new TProfile2D("PRF2d",(const Char_t *) name
3338 ,fNumberBinPRF,-1.5,1.5,nn,0,nn);
3339 fPRF2d->SetYTitle("Det/pad groups");
3340 fPRF2d->SetXTitle("Position x/W [pad width units]");
3341 fPRF2d->SetZTitle("Q_{i}/Q_{total}");
3342 fPRF2d->SetStats(0);
3347 //_____________________________________________________________________________
3348 void AliTRDCalibraFillHisto::CreatePH2d(Int_t nn)
3351 // Create the 2D histos
3354 TString name("Ver");
3355 name += fVersionVdriftUsed;
3357 name += fSubVersionVdriftUsed;
3359 name += fCalibraMode->GetNz(1);
3361 name += fCalibraMode->GetNrphi(1);
3363 fPH2d = new TProfile2D("PH2d",(const Char_t *) name
3364 ,fTimeMax,-0.5/fSf,(Float_t) (fTimeMax-0.5)/fSf
3366 fPH2d->SetYTitle("Det/pad groups");
3367 fPH2d->SetXTitle("time [#mus]");
3368 fPH2d->SetZTitle("<PH> [a.u.]");
3372 //_____________________________________________________________________________
3373 void AliTRDCalibraFillHisto::CreateCH2d(Int_t nn)
3376 // Create the 2D histos
3379 TString name("Ver");
3380 name += fVersionGainUsed;
3382 name += fSubVersionGainUsed;
3384 name += fCalibraMode->GetNz(0);
3386 name += fCalibraMode->GetNrphi(0);
3388 fCH2d = new TH2I("CH2d",(const Char_t *) name
3389 ,fNumberBinCharge,0,300,nn,0,nn);
3390 fCH2d->SetYTitle("Det/pad groups");
3391 fCH2d->SetXTitle("charge deposit [a.u]");
3392 fCH2d->SetZTitle("counts");
3397 //////////////////////////////////////////////////////////////////////////////////
3398 // Set relative scale
3399 /////////////////////////////////////////////////////////////////////////////////
3400 //_____________________________________________________________________________
3401 void AliTRDCalibraFillHisto::SetRelativeScale(Float_t RelativeScale)
3404 // Set the factor that will divide the deposited charge
3405 // to fit in the histo range [0,300]
3408 if (RelativeScale > 0.0) {
3409 fRelativeScale = RelativeScale;
3412 AliInfo("RelativeScale must be strict positif!");
3416 //////////////////////////////////////////////////////////////////////////////////
3417 // Quick way to fill a histo
3418 //////////////////////////////////////////////////////////////////////////////////
3419 //_____________________________________________________________________
3420 void AliTRDCalibraFillHisto::FillCH2d(Int_t x, Float_t y)
3423 // FillCH2d: Marian style
3426 //skip simply the value out of range
3427 if((y>=300.0) || (y<0.0)) return;
3429 //Calcul the y place
3430 Int_t yplace = (Int_t) (fNumberBinCharge*y/300.0)+1;
3431 Int_t place = (fNumberBinCharge+2)*(x+1)+yplace;
3434 fCH2d->GetArray()[place]++;
3438 //////////////////////////////////////////////////////////////////////////////////
3439 // Geometrical functions
3440 ///////////////////////////////////////////////////////////////////////////////////
3441 //_____________________________________________________________________________
3442 Int_t AliTRDCalibraFillHisto::GetLayer(Int_t d) const
3445 // Reconstruct the layer number from the detector number
3448 return ((Int_t) (d % 6));
3452 //_____________________________________________________________________________
3453 Int_t AliTRDCalibraFillHisto::GetStack(Int_t d) const
3456 // Reconstruct the stack number from the detector number
3458 const Int_t kNlayer = 6;
3460 return ((Int_t) (d % 30) / kNlayer);
3464 //_____________________________________________________________________________
3465 Int_t AliTRDCalibraFillHisto::GetSector(Int_t d) const
3468 // Reconstruct the sector number from the detector number
3472 return ((Int_t) (d / fg));
3475 ///////////////////////////////////////////////////////////////////////////////////
3476 // Getter functions for DAQ of the CH2d and the PH2d
3477 //////////////////////////////////////////////////////////////////////////////////
3478 //_____________________________________________________________________
3479 TProfile2D* AliTRDCalibraFillHisto::GetPH2d(Int_t nbtimebin, Float_t samplefrequency)
3482 // return pointer to fPH2d TProfile2D
3483 // create a new TProfile2D if it doesn't exist allready
3489 fTimeMax = nbtimebin;
3490 fSf = samplefrequency;
3496 //_____________________________________________________________________
3497 TH2I* AliTRDCalibraFillHisto::GetCH2d()
3500 // return pointer to fCH2d TH2I
3501 // create a new TH2I if it doesn't exist allready
3510 ////////////////////////////////////////////////////////////////////////////////////////////
3511 // Drift velocity calibration
3512 ///////////////////////////////////////////////////////////////////////////////////////////
3513 //_____________________________________________________________________
3514 TLinearFitter* AliTRDCalibraFillHisto::GetLinearFitter(Int_t detector, Bool_t force)
3517 // return pointer to TLinearFitter Calibration
3518 // if force is true create a new TLinearFitter if it doesn't exist allready
3521 if ((!force) || (fLinearFitterArray.UncheckedAt(detector))){
3522 return (TLinearFitter*)fLinearFitterArray.UncheckedAt(detector);
3525 // if we are forced and TLinearFitter doesn't yet exist create it
3527 // new TLinearFitter
3528 TLinearFitter *linearfitter = new TLinearFitter(2,"pol1");
3529 fLinearFitterArray.AddAt(linearfitter,detector);
3530 return linearfitter;
3533 //____________________________________________________________________________
3534 void AliTRDCalibraFillHisto::AnalyseLinearFitter()
3537 // Analyse array of linear fitter because can not be written
3538 // Store two arrays: one with the param the other one with the error param + number of entries
3541 for(Int_t k = 0; k < 540; k++){
3542 TLinearFitter *linearfitter = GetLinearFitter(k);
3543 if((linearfitter!=0) && (fEntriesLinearFitter[k]>10)){
3544 TVectorD *par = new TVectorD(2);
3545 TVectorD pare = TVectorD(2);
3546 TVectorD *parE = new TVectorD(3);
3547 linearfitter->Eval();
3548 linearfitter->GetParameters(*par);
3549 linearfitter->GetErrors(pare);
3550 Float_t ppointError = TMath::Sqrt(TMath::Abs(linearfitter->GetChisquare())/fEntriesLinearFitter[k]);
3551 (*parE)[0] = pare[0]*ppointError;
3552 (*parE)[1] = pare[1]*ppointError;
3553 (*parE)[2] = (Double_t) fEntriesLinearFitter[k];
3554 ((TObjArray *)fLinearVdriftFit->GetPArray())->AddAt(par,k);
3555 ((TObjArray *)fLinearVdriftFit->GetEArray())->AddAt(parE,k);