1 //**************************************************************************
2 // * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 // * Author: The ALICE Off-line Project. *
5 // * Contributors are mentioned in the code where appropriate. *
7 // * Permission to use, copy, modify and distribute this software and its *
8 // * documentation strictly for non-commercial purposes is hereby granted *
9 // * without fee, provided that the above copyright notice appears in all *
10 // * copies and that both the copyright notice and this permission notice *
11 //* appear in the supporting documentation. The authors make no claims *
12 //* about the suitability of this software for any purpose. It is *
13 //* provided "as is" without express or implied warranty. *
14 //**************************************************************************/
18 /////////////////////////////////////////////////////////////////////////////////
20 // AliTRDCalibraFillHisto
22 // This class is for the TRD calibration of the relative gain factor, the drift velocity,
23 // the time 0 and the pad response function. It fills histos or vectors.
24 // It can be used for the calibration per chamber but also per group of pads and eventually per pad.
25 // The user has to choose with the functions SetNz and SetNrphi the precision of the calibration (see AliTRDCalibraMode).
26 // 2D Histograms (Histo2d) or vectors (Vector2d), then converted in Trees, will be filled
27 // from RAW DATA in a run or from reconstructed TRD tracks during the offline tracking
28 // in the function "FollowBackProlongation" (AliTRDtracker)
29 // Per default the functions to fill are off.
32 // R. Bailhache (R.Bailhache@gsi.de, rbailhache@ikf.uni-frankfurt.de)
33 // J. Book (jbook@ikf.uni-frankfurt.de)
35 //////////////////////////////////////////////////////////////////////////////////////
37 #include <TProfile2D.h>
42 #include <TObjArray.h>
47 #include <TStopwatch.h>
49 #include <TDirectory.h>
50 #include <TTreeStream.h>
52 #include <TLinearFitter.h>
56 #include "AliTRDCalibraFillHisto.h"
57 #include "AliTRDCalibraMode.h"
58 #include "AliTRDCalibraVector.h"
59 #include "AliTRDCalibraVdriftLinearFit.h"
60 #include "AliTRDcalibDB.h"
61 #include "AliTRDCommonParam.h"
62 #include "AliTRDpadPlane.h"
63 #include "AliTRDcluster.h"
64 #include "AliTRDtrackV1.h"
65 #include "AliRawReader.h"
66 #include "AliRawReaderDate.h"
67 #include "AliTRDgeometry.h"
68 #include "./Cal/AliTRDCalROC.h"
69 #include "./Cal/AliTRDCalPad.h"
70 #include "./Cal/AliTRDCalDet.h"
72 #include "AliTRDdigitsManager.h"
73 #include "AliTRDdigitsParam.h"
74 #include "AliTRDSignalIndex.h"
75 #include "AliTRDarrayADC.h"
77 #include "AliTRDrawStream.h"
79 #include "AliCDBEntry.h"
80 #include "AliCDBManager.h"
87 ClassImp(AliTRDCalibraFillHisto)
89 AliTRDCalibraFillHisto* AliTRDCalibraFillHisto::fgInstance = 0;
90 Bool_t AliTRDCalibraFillHisto::fgTerminated = kFALSE;
92 //_____________singleton implementation_________________________________________________
93 AliTRDCalibraFillHisto *AliTRDCalibraFillHisto::Instance()
96 // Singleton implementation
99 if (fgTerminated != kFALSE) {
103 if (fgInstance == 0) {
104 fgInstance = new AliTRDCalibraFillHisto();
111 //______________________________________________________________________________________
112 void AliTRDCalibraFillHisto::Terminate()
115 // Singleton implementation
116 // Deletes the instance of this class
119 fgTerminated = kTRUE;
121 if (fgInstance != 0) {
128 //______________________________________________________________________________________
129 AliTRDCalibraFillHisto::AliTRDCalibraFillHisto()
139 ,fLinearFitterOn(kFALSE)
140 ,fLinearFitterDebugOn(kFALSE)
142 ,fThresholdClusterPRF2(15.0)
143 ,fLimitChargeIntegration(kFALSE)
144 ,fFillWithZero(kFALSE)
145 ,fNormalizeNbOfCluster(kFALSE)
150 ,fSubVersionGainUsed(0)
151 ,fFirstRunGainLocal(0)
152 ,fVersionGainLocalUsed(0)
153 ,fSubVersionGainLocalUsed(0)
155 ,fVersionVdriftUsed(0)
156 ,fSubVersionVdriftUsed(0)
159 ,fSubVersionExBUsed(0)
160 ,fCalibraMode(new AliTRDCalibraMode())
163 ,fDetectorPreviousTrack(-1)
167 ,fNumberClustersf(30)
168 ,fNumberClustersProcent(0.5)
169 ,fThresholdClustersDAQ(120.0)
177 ,fNumberBinCharge(50)
183 ,fGoodTracklet(kTRUE)
184 ,fLinearFitterTracklet(0x0)
186 ,fEntriesLinearFitter(0x0)
191 ,fLinearFitterArray(540)
192 ,fLinearVdriftFit(0x0)
197 // Default constructor
201 // Init some default values
204 fNumberUsedCh[0] = 0;
205 fNumberUsedCh[1] = 0;
206 fNumberUsedPh[0] = 0;
207 fNumberUsedPh[1] = 0;
209 fGeo = new AliTRDgeometry();
210 fCalibDB = AliTRDcalibDB::Instance();
213 //______________________________________________________________________________________
214 AliTRDCalibraFillHisto::AliTRDCalibraFillHisto(const AliTRDCalibraFillHisto &c)
221 ,fPRF2dOn(c.fPRF2dOn)
222 ,fHisto2d(c.fHisto2d)
223 ,fVector2d(c.fVector2d)
224 ,fLinearFitterOn(c.fLinearFitterOn)
225 ,fLinearFitterDebugOn(c.fLinearFitterDebugOn)
226 ,fRelativeScale(c.fRelativeScale)
227 ,fThresholdClusterPRF2(c.fThresholdClusterPRF2)
228 ,fLimitChargeIntegration(c.fLimitChargeIntegration)
229 ,fFillWithZero(c.fFillWithZero)
230 ,fNormalizeNbOfCluster(c.fNormalizeNbOfCluster)
231 ,fMaxCluster(c.fMaxCluster)
232 ,fNbMaxCluster(c.fNbMaxCluster)
233 ,fFirstRunGain(c.fFirstRunGain)
234 ,fVersionGainUsed(c.fVersionGainUsed)
235 ,fSubVersionGainUsed(c.fSubVersionGainUsed)
236 ,fFirstRunGainLocal(c.fFirstRunGainLocal)
237 ,fVersionGainLocalUsed(c.fVersionGainLocalUsed)
238 ,fSubVersionGainLocalUsed(c.fSubVersionGainLocalUsed)
239 ,fFirstRunVdrift(c.fFirstRunVdrift)
240 ,fVersionVdriftUsed(c.fVersionVdriftUsed)
241 ,fSubVersionVdriftUsed(c.fSubVersionVdriftUsed)
242 ,fFirstRunExB(c.fFirstRunExB)
243 ,fVersionExBUsed(c.fVersionExBUsed)
244 ,fSubVersionExBUsed(c.fSubVersionExBUsed)
247 ,fDebugLevel(c.fDebugLevel)
248 ,fDetectorPreviousTrack(c.fDetectorPreviousTrack)
249 ,fMCMPrevious(c.fMCMPrevious)
250 ,fROBPrevious(c.fROBPrevious)
251 ,fNumberClusters(c.fNumberClusters)
252 ,fNumberClustersf(c.fNumberClustersf)
253 ,fNumberClustersProcent(c.fNumberClustersProcent)
254 ,fThresholdClustersDAQ(c.fThresholdClustersDAQ)
255 ,fNumberRowDAQ(c.fNumberRowDAQ)
256 ,fNumberColDAQ(c.fNumberColDAQ)
257 ,fProcent(c.fProcent)
258 ,fDifference(c.fDifference)
259 ,fNumberTrack(c.fNumberTrack)
260 ,fTimeMax(c.fTimeMax)
262 ,fNumberBinCharge(c.fNumberBinCharge)
263 ,fNumberBinPRF(c.fNumberBinPRF)
264 ,fNgroupprf(c.fNgroupprf)
268 ,fGoodTracklet(c.fGoodTracklet)
269 ,fLinearFitterTracklet(0x0)
271 ,fEntriesLinearFitter(0x0)
276 ,fLinearFitterArray(540)
277 ,fLinearVdriftFit(0x0)
284 if(c.fCalibraMode) fCalibraMode = new AliTRDCalibraMode(*c.fCalibraMode);
285 if(c.fCalibraVector) fCalibraVector = new AliTRDCalibraVector(*c.fCalibraVector);
287 fPH2d = new TProfile2D(*c.fPH2d);
288 fPH2d->SetDirectory(0);
291 fPRF2d = new TProfile2D(*c.fPRF2d);
292 fPRF2d->SetDirectory(0);
295 fCH2d = new TH2I(*c.fCH2d);
296 fCH2d->SetDirectory(0);
298 if(c.fLinearVdriftFit){
299 fLinearVdriftFit = new AliTRDCalibraVdriftLinearFit(*c.fLinearVdriftFit);
302 if(c.fCalDetGain) fCalDetGain = new AliTRDCalDet(*c.fCalDetGain);
303 if(c.fCalROCGain) fCalROCGain = new AliTRDCalROC(*c.fCalROCGain);
308 fGeo = new AliTRDgeometry();
309 fCalibDB = AliTRDcalibDB::Instance();
311 fNumberUsedCh[0] = 0;
312 fNumberUsedCh[1] = 0;
313 fNumberUsedPh[0] = 0;
314 fNumberUsedPh[1] = 0;
318 //____________________________________________________________________________________
319 AliTRDCalibraFillHisto::~AliTRDCalibraFillHisto()
322 // AliTRDCalibraFillHisto destructor
326 if ( fDebugStreamer ) delete fDebugStreamer;
328 if ( fCalDetGain ) delete fCalDetGain;
329 if ( fCalROCGain ) delete fCalROCGain;
331 if( fLinearFitterTracklet ) { delete fLinearFitterTracklet; }
335 delete [] fEntriesCH;
336 delete [] fEntriesLinearFitter;
339 for(Int_t idet=0; idet<AliTRDgeometry::kNdet; idet++){
340 TLinearFitter *f = (TLinearFitter*)fLinearFitterArray.At(idet);
343 if(fLinearVdriftFit) delete fLinearVdriftFit;
349 //_____________________________________________________________________________
350 void AliTRDCalibraFillHisto::Destroy()
361 //_____________________________________________________________________________
362 void AliTRDCalibraFillHisto::DestroyDebugStreamer()
365 // Delete DebugStreamer
368 if ( fDebugStreamer ) delete fDebugStreamer;
369 fDebugStreamer = 0x0;
372 //_____________________________________________________________________________
373 void AliTRDCalibraFillHisto::ClearHistos()
393 //////////////////////////////////////////////////////////////////////////////////
394 // calibration with AliTRDtrackV1: Init, Update
395 //////////////////////////////////////////////////////////////////////////////////
396 //____________Functions for initialising the AliTRDCalibraFillHisto in the code_________
397 Bool_t AliTRDCalibraFillHisto::Init2Dhistos(Int_t nboftimebin)
400 // Init the histograms and stuff to be filled
405 AliTRDcalibDB *cal = AliTRDcalibDB::Instance();
407 AliInfo("Could not get calibDB");
410 AliTRDCommonParam *parCom = AliTRDCommonParam::Instance();
412 AliInfo("Could not get CommonParam");
417 if(nboftimebin > 0) fTimeMax = nboftimebin;
418 else fTimeMax = cal->GetNumberOfTimeBinsDCS();
419 if(fTimeMax <= 0) fTimeMax = 30;
420 printf("////////////////////////////////////////////\n");
421 printf("Number of time bins in calibration component %d\n",fTimeMax);
422 printf("////////////////////////////////////////////\n");
423 fSf = parCom->GetSamplingFrequency();
424 if(!fNormalizeNbOfCluster) fRelativeScale = 20.0;
425 else fRelativeScale = 1.18;
426 fNumberClustersf = fTimeMax;
427 fNumberClusters = (Int_t)(fNumberClustersProcent*fTimeMax);
429 // Init linear fitter
430 if(!fLinearFitterTracklet) {
431 fLinearFitterTracklet = new TLinearFitter(2,"pol1");
432 fLinearFitterTracklet->StoreData(kTRUE);
435 // Calcul Xbins Chambd0, Chamb2
436 Int_t ntotal0 = CalculateTotalNumberOfBins(0);
437 Int_t ntotal1 = CalculateTotalNumberOfBins(1);
438 Int_t ntotal2 = CalculateTotalNumberOfBins(2);
440 // If vector method On initialised all the stuff
442 fCalibraVector = new AliTRDCalibraVector();
443 fCalibraVector->SetNumberBinCharge(fNumberBinCharge);
444 fCalibraVector->SetTimeMax(fTimeMax);
445 if(fNgroupprf != 0) {
446 fCalibraVector->SetNumberBinPRF(2*fNgroupprf*fNumberBinPRF);
447 fCalibraVector->SetPRFRange((Float_t)(3.0*fNgroupprf));
450 fCalibraVector->SetNumberBinPRF(fNumberBinPRF);
451 fCalibraVector->SetPRFRange(1.5);
453 for(Int_t k = 0; k < 3; k++){
454 fCalibraVector->SetDetCha0(k,fCalibraMode->GetDetChamb0(k));
455 fCalibraVector->SetDetCha2(k,fCalibraMode->GetDetChamb2(k));
457 fCalibraVector->SetNzNrphi(0,fCalibraMode->GetNz(0),fCalibraMode->GetNrphi(0));
458 fCalibraVector->SetNzNrphi(1,fCalibraMode->GetNz(1),fCalibraMode->GetNrphi(1));
459 fCalibraVector->SetNzNrphi(2,fCalibraMode->GetNz(2),fCalibraMode->GetNrphi(2));
460 fCalibraVector->SetNbGroupPRF(fNgroupprf);
463 // Create the 2D histos corresponding to the pad groupCalibration mode
466 AliInfo(Form("The pad calibration mode for the relative gain calibration: Nz %d, and Nrphi %d"
467 ,fCalibraMode->GetNz(0)
468 ,fCalibraMode->GetNrphi(0)));
470 // Create the 2D histo
475 fAmpTotal = new Float_t[TMath::Max(fCalibraMode->GetDetChamb2(0),fCalibraMode->GetDetChamb0(0))];
476 for (Int_t k = 0; k < TMath::Max(fCalibraMode->GetDetChamb2(0),fCalibraMode->GetDetChamb0(0)); k++) {
480 fEntriesCH = new Int_t[ntotal0];
481 for(Int_t k = 0; k < ntotal0; k++){
488 AliInfo(Form("The pad calibration mode for the drift velocity calibration: Nz %d, and Nrphi %d"
489 ,fCalibraMode->GetNz(1)
490 ,fCalibraMode->GetNrphi(1)));
492 // Create the 2D histo
497 fPHPlace = new Short_t[fTimeMax];
498 for (Int_t k = 0; k < fTimeMax; k++) {
501 fPHValue = new Float_t[fTimeMax];
502 for (Int_t k = 0; k < fTimeMax; k++) {
506 if (fLinearFitterOn) {
507 if(fLinearFitterDebugOn) {
508 fLinearFitterArray.SetName("ArrayLinearFitters");
509 fEntriesLinearFitter = new Int_t[540];
510 for(Int_t k = 0; k < 540; k++){
511 fEntriesLinearFitter[k] = 0;
514 fLinearVdriftFit = new AliTRDCalibraVdriftLinearFit();
515 TString nameee("Ver");
516 nameee += fVersionExBUsed;
518 nameee += fSubVersionExBUsed;
519 nameee += "FirstRun";
520 nameee += fFirstRunExB;
522 fLinearVdriftFit->SetNameCalibUsed(nameee);
527 AliInfo(Form("The pad calibration mode for the PRF calibration: Nz %d, and Nrphi %d"
528 ,fCalibraMode->GetNz(2)
529 ,fCalibraMode->GetNrphi(2)));
530 // Create the 2D histo
532 CreatePRF2d(ntotal2);
539 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
540 Bool_t AliTRDCalibraFillHisto::InitCalDet()
543 // Init the Gain Cal Det
548 AliCDBEntry *entry = AliCDBManager::Instance()->Get("TRD/Calib/ChamberGainFactor",fFirstRunGain,fVersionGainUsed,fSubVersionGainUsed);
550 AliError("No gain det calibration entry found");
553 AliTRDCalDet *calDet = (AliTRDCalDet *)entry->GetObject();
555 AliError("No calDet gain found");
561 fCalDetGain->~AliTRDCalDet();
562 new(fCalDetGain) AliTRDCalDet(*(calDet));
563 }else fCalDetGain = new AliTRDCalDet(*(calDet));
568 name += fVersionGainUsed;
570 name += fSubVersionGainUsed;
572 name += fFirstRunGain;
574 name += fCalibraMode->GetNz(0);
576 name += fCalibraMode->GetNrphi(0);
578 fCH2d->SetTitle(name);
581 TString namee("Ver");
582 namee += fVersionVdriftUsed;
584 namee += fSubVersionVdriftUsed;
586 namee += fFirstRunVdrift;
588 namee += fCalibraMode->GetNz(1);
590 namee += fCalibraMode->GetNrphi(1);
592 fPH2d->SetTitle(namee);
594 // title AliTRDCalibraVdriftLinearFit
595 TString nameee("Ver");
596 nameee += fVersionExBUsed;
598 nameee += fSubVersionExBUsed;
599 nameee += "FirstRun";
600 nameee += fFirstRunExB;
604 fLinearVdriftFit->SetNameCalibUsed(nameee);
611 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
612 Bool_t AliTRDCalibraFillHisto::InitCalPad(Int_t detector)
615 // Init the Gain Cal Pad
620 AliCDBEntry *entry = AliCDBManager::Instance()->Get("TRD/Calib/LocalGainFactor",AliCDBManager::Instance()->GetRun(),fVersionGainLocalUsed,fSubVersionGainLocalUsed);
622 AliError("No gain pad calibration entry found");
625 AliTRDCalPad *calPad = (AliTRDCalPad *)entry->GetObject();
627 AliError("No calPad gain found");
630 AliTRDCalROC *calRoc = (AliTRDCalROC *)calPad->GetCalROC(detector);
632 AliError("No calRoc gain found");
637 fCalROCGain->~AliTRDCalROC();
638 new(fCalROCGain) AliTRDCalROC(*(calRoc));
639 }else fCalROCGain = new AliTRDCalROC(*(calRoc));
648 //____________Offline tracking in the AliTRDtracker____________________________
649 Bool_t AliTRDCalibraFillHisto::UpdateHistogramsV1(const AliTRDtrackV1 *t)
652 // Use AliTRDtrackV1 for the calibration
656 const AliTRDseedV1 *tracklet = 0x0; // tracklet per plane
657 AliTRDcluster *cl = 0x0; // cluster attached now to the tracklet
658 AliTRDcluster *cls = 0x0; // shared cluster attached now to the tracklet
659 Bool_t newtr = kTRUE; // new track
662 // AliTRDcalibDB *cal = AliTRDcalibDB::Instance();
665 AliInfo("Could not get calibDB");
670 AliInfo("Could not get calibDB");
675 ///////////////////////////
676 // loop over the tracklet
677 ///////////////////////////
678 for(Int_t itr = 0; itr < 6; itr++){
680 if(!(tracklet = t->GetTracklet(itr))) continue;
681 if(!tracklet->IsOK()) continue;
683 ResetfVariablestracklet();
685 //////////////////////////////////////////
686 // localisation of the tracklet and dqdl
687 //////////////////////////////////////////
688 Int_t layer = tracklet->GetPlane();
690 while(!(cl = tracklet->GetClusters(ic++))) continue;
691 Int_t detector = cl->GetDetector();
692 if (detector != fDetectorPreviousTrack) {
693 // if not a new track
695 // don't use the rest of this track if in the same plane
696 if (layer == GetLayer(fDetectorPreviousTrack)) {
697 //printf("bad tracklet, same layer for detector %d\n",detector);
701 //Localise the detector bin
702 LocalisationDetectorXbins(detector);
704 if(!fIsHLT) InitCalPad(detector);
707 fDetectorPreviousTrack = detector;
711 ////////////////////////////
712 // loop over the clusters
713 ////////////////////////////
714 Int_t nbclusters = 0;
715 for(int jc=0; jc<AliTRDseedV1::kNtb; jc++){
716 if(!(cl = tracklet->GetClusters(jc))) continue;
719 // Store the info bis of the tracklet
720 Int_t row = cl->GetPadRow();
721 Int_t col = cl->GetPadCol();
722 CheckGoodTrackletV1(cl);
723 Int_t group[2] = {0,0};
724 if(fCH2dOn) group[0] = CalculateCalibrationGroup(0,row,col);
725 if(fPH2dOn) group[1] = CalculateCalibrationGroup(1,row,col);
726 // Add the charge if shared cluster
727 cls = tracklet->GetClusters(jc+AliTRDseedV1::kNtb);
729 StoreInfoCHPHtrack(cl, tracklet->GetdQdl(jc),group,row,col,cls);
732 ////////////////////////////////////////
733 // Fill the stuffs if a good tracklet
734 ////////////////////////////////////////
737 // drift velocity unables to cut bad tracklets
738 Bool_t pass = FindP1TrackPHtrackletV1(tracklet, nbclusters);
740 //printf("pass %d and nbclusters %d\n",pass,nbclusters);
744 FillTheInfoOfTheTrackCH(nbclusters);
749 FillTheInfoOfTheTrackPH();
752 if(pass && fPRF2dOn) HandlePRFtrackletV1(tracklet,nbclusters);
754 } // if a good tracklet
760 ///////////////////////////////////////////////////////////////////////////////////
761 // Routine inside the update with AliTRDtrack
762 ///////////////////////////////////////////////////////////////////////////////////
763 //____________Offine tracking in the AliTRDtracker_____________________________
764 Bool_t AliTRDCalibraFillHisto::FindP1TrackPHtrackletV1(const AliTRDseedV1 *tracklet, Int_t nbclusters)
767 // Drift velocity calibration:
768 // Fit the clusters with a straight line
769 // From the slope find the drift velocity
772 ////////////////////////////////////////////////
773 //Number of points: if less than 3 return kFALSE
774 /////////////////////////////////////////////////
775 if(nbclusters <= 2) return kFALSE;
780 // results of the linear fit
781 Double_t dydt = 0.0; // dydt tracklet after straight line fit
782 Double_t errorpar = 0.0; // error after straight line fit on dy/dt
783 Double_t pointError = 0.0; // error after straight line fit
784 // pad row problemes: avoid tracklet that cross pad rows, tilting angle in the constant
785 Int_t crossrow = 0; // if it crosses a pad row
786 Int_t rowp = -1; // if it crosses a pad row
787 Float_t tnt = tracklet->GetTilt(); // tan tiltingangle
788 fLinearFitterTracklet->ClearPoints();
791 ///////////////////////////////////////////
792 // Take the parameters of the track
793 //////////////////////////////////////////
794 // take now the snp, tnp and tgl from the track
795 Double_t snp = tracklet->GetSnp(); // sin dy/dx at the end of the chamber
796 Double_t tnp = 0.0; // dy/dx at the end of the chamber
797 if( TMath::Abs(snp) < 1.){
798 tnp = snp / TMath::Sqrt((1.-snp)*(1.+snp));
800 Double_t tgl = tracklet->GetTgl(); // dz/dl
801 Double_t dzdx = tgl*TMath::Sqrt(1+tnp*tnp); // dz/dx calculated from dz/dl
803 //Double_t tnp = tracklet->GetYref(1); // dy/dx at the entrance of the chamber
804 //Double_t tgl = tracklet->GetZref(1); // dz/dl at the entrance of the chamber
805 //Double_t dzdx = tgl; //*TMath::Sqrt(1+tnp*tnp); // dz/dx from dz/dl
806 // at the end with correction due to linear fit
807 //Double_t tnp = tracklet->GetYfit(1); // dy/dx at the end of the chamber after fit correction
808 //Double_t tgl = tracklet->GetZfit(1); // dz/dl at the end of the chamber after fit correction
811 ////////////////////////////
812 // loop over the clusters
813 ////////////////////////////
815 AliTRDcluster *cl = 0x0;
816 //////////////////////////////
817 // Check no shared clusters
818 //////////////////////////////
819 for(int icc=AliTRDseedV1::kNtb; icc<AliTRDseedV1::kNclusters; icc++){
820 cl = tracklet->GetClusters(icc);
823 //////////////////////////////////
825 //////////////////////////////////
826 for(int ic=0; ic<AliTRDseedV1::kNtb; ic++){
827 if(!(cl = tracklet->GetClusters(ic))) continue;
828 if((fLimitChargeIntegration) && (!cl->IsInChamber())) continue;
830 Double_t ycluster = cl->GetY();
831 Int_t time = cl->GetPadTime();
832 Double_t timeis = time/fSf;
833 //See if cross two pad rows
834 Int_t row = cl->GetPadRow();
835 if(rowp==-1) rowp = row;
836 if(row != rowp) crossrow = 1;
838 fLinearFitterTracklet->AddPoint(&timeis,ycluster,1);
844 ////////////////////////////////////
845 // Do the straight line fit now
846 ///////////////////////////////////
848 fLinearFitterTracklet->ClearPoints();
852 fLinearFitterTracklet->Eval();
853 fLinearFitterTracklet->GetParameters(pars);
854 pointError = TMath::Sqrt(fLinearFitterTracklet->GetChisquare()/(nbli-2));
855 errorpar = fLinearFitterTracklet->GetParError(1)*pointError;
857 //printf("chis %f, nbli %d, pointError %f, parError %f, errorpar %f\n",fLinearFitterTracklet->GetChisquare(),nbli,pointError,fLinearFitterTracklet->GetParError(1),errorpar);
858 fLinearFitterTracklet->ClearPoints();
860 ////////////////////////////////
862 ///////////////////////////////
866 if ( !fDebugStreamer ) {
868 TDirectory *backup = gDirectory;
869 fDebugStreamer = new TTreeSRedirector("TRDdebugCalibraFill.root");
870 if ( backup ) backup->cd(); //we don't want to be cd'd to the debug streamer
874 Int_t layer = GetLayer(fDetectorPreviousTrack);
876 (* fDebugStreamer) << "FindP1TrackPHtrackletV1"<<
877 //"snpright="<<snpright<<
879 "nbclusters="<<nbclusters<<
880 "detector="<<fDetectorPreviousTrack<<
888 "crossrow="<<crossrow<<
889 "errorpar="<<errorpar<<
890 "pointError="<<pointError<<
895 /////////////////////////
897 ////////////////////////
899 if(nbclusters < fNumberClusters) return kFALSE;
900 if(nbclusters > fNumberClustersf) return kFALSE;
901 if(pointError >= 0.3) return kFALSE;
902 if(crossrow == 1) return kTRUE;
904 ///////////////////////
906 //////////////////////
909 //Add to the linear fitter of the detector
910 if( TMath::Abs(snp) < 1.){
911 Double_t x = tnp-dzdx*tnt;
912 if(fLinearFitterDebugOn) {
913 (GetLinearFitter(fDetectorPreviousTrack,kTRUE))->AddPoint(&x,dydt);
914 fEntriesLinearFitter[fDetectorPreviousTrack]++;
916 fLinearVdriftFit->Update(fDetectorPreviousTrack,x,pars[1]);
922 //____________Offine tracking in the AliTRDtracker_____________________________
923 Bool_t AliTRDCalibraFillHisto::HandlePRFtrackletV1(const AliTRDseedV1 *tracklet, Int_t nbclusters)
926 // PRF width calibration
927 // Assume a Gaussian shape: determinate the position of the three pad clusters
928 // Fit with a straight line
929 // Take the fitted values for all the clusters (3 or 2 pad clusters)
930 // Fill the PRF as function of angle of the track
935 ///////////////////////////////////////////
936 // Take the parameters of the track
937 //////////////////////////////////////////
938 // take now the snp, tnp and tgl from the track
939 Double_t snp = tracklet->GetSnp(); // sin dy/dx at the end of the chamber
940 Double_t tnp = 0.0; // dy/dx at the end of the chamber
941 if( TMath::Abs(snp) < 1.){
942 tnp = snp / TMath::Sqrt((1.-snp)*(1.+snp));
944 Double_t tgl = tracklet->GetTgl(); // dz/dl
945 Double_t dzdx = tgl*TMath::Sqrt(1+tnp*tnp); // dz/dx calculated from dz/dl
947 //Double_t tnp = tracklet->GetYref(1); // dy/dx at the entrance of the chamber
948 //Double_t tgl = tracklet->GetZref(1); // dz/dl at the entrance of the chamber
949 //Double_t dzdx = tgl; //*TMath::Sqrt(1+tnp*tnp); // dz/dx from dz/dl
950 // at the end with correction due to linear fit
951 //Double_t tnp = tracklet->GetYfit(1); // dy/dx at the end of the chamber after fit correction
952 //Double_t tgl = tracklet->GetZfit(1); // dz/dl at the end of the chamber after fit correction
954 ///////////////////////////////
955 // Calculate tnp group shift
956 ///////////////////////////////
957 Bool_t echec = kFALSE;
958 Double_t shift = 0.0;
959 //Calculate the shift in x coresponding to this tnp
960 if(fNgroupprf != 0.0){
961 shift = -3.0*(fNgroupprf-1)-1.5;
962 Double_t limithigh = -0.2*(fNgroupprf-1);
963 if((tnp < (-0.2*fNgroupprf)) || (tnp > (0.2*fNgroupprf))) echec = kTRUE;
965 while(tnp > limithigh){
971 // do nothing if out of tnp range
972 //printf("echec %d\n",(Int_t)echec);
973 if(echec) return kFALSE;
975 ///////////////////////
977 //////////////////////
979 Int_t nb3pc = 0; // number of three pads clusters used for fit
980 // to see the difference between the fit and the 3 pad clusters position
981 Double_t padPositions[AliTRDseedV1::kNtb];
982 memset(padPositions, 0, AliTRDseedV1::kNtb*sizeof(Double_t));
983 fLinearFitterTracklet->ClearPoints();
985 //printf("loop clusters \n");
986 ////////////////////////////
987 // loop over the clusters
988 ////////////////////////////
989 AliTRDcluster *cl = 0x0;
990 for(int ic=0; ic<AliTRDseedV1::kNtb; ic++){
991 // reject shared clusters on pad row
992 if((ic+AliTRDseedV1::kNtb) < AliTRDseedV1::kNclusters) {
993 cl = tracklet->GetClusters(ic+AliTRDseedV1::kNtb);
996 cl = tracklet->GetClusters(ic);
998 Double_t time = cl->GetPadTime();
999 if((time<=7) || (time>=21)) continue;
1000 Short_t *signals = cl->GetSignals();
1001 Float_t xcenter = 0.0;
1002 Bool_t echec1 = kTRUE;
1004 /////////////////////////////////////////////////////////////
1005 // Center 3 balanced: position with the center of the pad
1006 /////////////////////////////////////////////////////////////
1007 if ((((Float_t) signals[3]) > 0.0) &&
1008 (((Float_t) signals[2]) > 0.0) &&
1009 (((Float_t) signals[4]) > 0.0)) {
1011 // Security if the denomiateur is 0
1012 if ((((Float_t) (((Float_t) signals[3]) * ((Float_t) signals[3]))) /
1013 ((Float_t) (((Float_t) signals[2]) * ((Float_t) signals[4])))) != 1.0) {
1014 xcenter = 0.5 * (TMath::Log((Float_t) (((Float_t) signals[4]) / ((Float_t) signals[2]))))
1015 / (TMath::Log(((Float_t) (((Float_t) signals[3]) * ((Float_t) signals[3])))
1016 / ((Float_t) (((Float_t) signals[2]) * ((Float_t) signals[4])))));
1022 if(TMath::Abs(xcenter) > 0.5) echec1 = kTRUE;
1023 if(echec1) continue;
1025 ////////////////////////////////////////////////////////
1026 //if no echec1: calculate with the position of the pad
1027 // Position of the cluster
1028 // fill the linear fitter
1029 ///////////////////////////////////////////////////////
1030 Double_t padPosition = xcenter + cl->GetPadCol();
1031 padPositions[ic] = padPosition;
1033 fLinearFitterTracklet->AddPoint(&time, padPosition,1);
1038 //printf("Fin loop clusters \n");
1039 //////////////////////////////
1040 // fit with a straight line
1041 /////////////////////////////
1043 fLinearFitterTracklet->ClearPoints();
1046 fLinearFitterTracklet->Eval();
1048 fLinearFitterTracklet->GetParameters(line);
1049 Float_t pointError = -1.0;
1050 if( fLinearFitterTracklet->GetChisquare()>=0.0) {
1051 pointError = TMath::Sqrt( fLinearFitterTracklet->GetChisquare()/(nb3pc-2));
1053 fLinearFitterTracklet->ClearPoints();
1055 //printf("PRF second loop \n");
1056 ////////////////////////////////////////////////
1057 // Fill the PRF: Second loop over clusters
1058 //////////////////////////////////////////////
1059 for(int ic=0; ic<AliTRDseedV1::kNtb; ic++){
1060 // reject shared clusters on pad row
1061 cl = tracklet->GetClusters(ic+AliTRDseedV1::kNtb);
1062 if(((ic+AliTRDseedV1::kNtb) < AliTRDseedV1::kNclusters) && (cl)) continue;
1064 cl = tracklet->GetClusters(ic);
1067 Short_t *signals = cl->GetSignals(); // signal
1068 Double_t time = cl->GetPadTime(); // time bin
1069 Float_t padPosTracklet = line[0]+line[1]*time; // reconstruct position from fit
1070 Float_t padPos = cl->GetPadCol(); // middle pad
1071 Double_t dpad = padPosTracklet - padPos; // reconstruct position relative to middle pad from fit
1072 Float_t ycenter = 0.0; // relative center charge
1073 Float_t ymin = 0.0; // relative left charge
1074 Float_t ymax = 0.0; // relative right charge
1076 ////////////////////////////////////////////////////////////////
1077 // Calculate ycenter, ymin and ymax even for two pad clusters
1078 ////////////////////////////////////////////////////////////////
1079 if(((((Float_t) signals[3]) > 0.0) && (((Float_t) signals[2]) > 0.0)) ||
1080 ((((Float_t) signals[3]) > 0.0) && (((Float_t) signals[4]) > 0.0))){
1081 Float_t sum = ((Float_t) signals[2]) + ((Float_t) signals[3]) + ((Float_t) signals[4]);
1082 if(sum > 0.0) ycenter = ((Float_t) signals[3])/ sum;
1083 if(sum > 0.0) ymin = ((Float_t) signals[2])/ sum;
1084 if(sum > 0.0) ymax = ((Float_t) signals[4])/ sum;
1087 /////////////////////////
1088 // Calibration group
1089 ////////////////////////
1090 Int_t rowcl = cl->GetPadRow(); // row of cluster
1091 Int_t colcl = cl->GetPadCol(); // col of cluster
1092 Int_t grouplocal = CalculateCalibrationGroup(2,rowcl,colcl); // calcul the corresponding group
1093 Int_t caligroup = fCalibraMode->GetXbins(2)+ grouplocal; // calcul the corresponding group
1094 Float_t xcl = cl->GetY(); // y cluster
1095 Float_t qcl = cl->GetQ(); // charge cluster
1096 Int_t layer = GetLayer(fDetectorPreviousTrack); // layer
1097 Int_t stack = GetStack(fDetectorPreviousTrack); // stack
1098 Double_t xdiff = dpad; // reconstructed position constant
1099 Double_t x = dpad; // reconstructed position moved
1100 Float_t ep = pointError; // error of fit
1101 Float_t signal1 = (Float_t)signals[1]; // signal at the border
1102 Float_t signal3 = (Float_t)signals[3]; // signal
1103 Float_t signal2 = (Float_t)signals[2]; // signal
1104 Float_t signal4 = (Float_t)signals[4]; // signal
1105 Float_t signal5 = (Float_t)signals[5]; // signal at the border
1109 /////////////////////
1111 ////////////////////
1113 if(fDebugLevel > 0){
1114 if ( !fDebugStreamer ) {
1116 TDirectory *backup = gDirectory;
1117 fDebugStreamer = new TTreeSRedirector("TRDdebugCalibraFill.root");
1118 if ( backup ) backup->cd(); //we don't want to be cd'd to the debug streamer
1123 Float_t y = ycenter;
1124 (* fDebugStreamer) << "HandlePRFtrackletV1"<<
1125 "caligroup="<<caligroup<<
1126 "detector="<<fDetectorPreviousTrack<<
1129 "npoints="<<nbclusters<<
1138 "padPosition="<<padPositions[ic]<<
1139 "padPosTracklet="<<padPosTracklet<<
1144 "signal1="<<signal1<<
1145 "signal2="<<signal2<<
1146 "signal3="<<signal3<<
1147 "signal4="<<signal4<<
1148 "signal5="<<signal5<<
1154 (* fDebugStreamer) << "HandlePRFtrackletV1"<<
1155 "caligroup="<<caligroup<<
1156 "detector="<<fDetectorPreviousTrack<<
1159 "npoints="<<nbclusters<<
1168 "padPosition="<<padPositions[ic]<<
1169 "padPosTracklet="<<padPosTracklet<<
1174 "signal1="<<signal1<<
1175 "signal2="<<signal2<<
1176 "signal3="<<signal3<<
1177 "signal4="<<signal4<<
1178 "signal5="<<signal5<<
1184 (* fDebugStreamer) << "HandlePRFtrackletV1"<<
1185 "caligroup="<<caligroup<<
1186 "detector="<<fDetectorPreviousTrack<<
1189 "npoints="<<nbclusters<<
1198 "padPosition="<<padPositions[ic]<<
1199 "padPosTracklet="<<padPosTracklet<<
1204 "signal1="<<signal1<<
1205 "signal2="<<signal2<<
1206 "signal3="<<signal3<<
1207 "signal4="<<signal4<<
1208 "signal5="<<signal5<<
1214 /////////////////////
1216 /////////////////////
1217 if(nbclusters < fNumberClusters) continue;
1218 if(nbclusters > fNumberClustersf) continue;
1219 if(nb3pc <= 5) continue;
1220 if((time >= 21) || (time < 7)) continue;
1221 if(TMath::Abs(qcl) < 80) continue;
1222 if( TMath::Abs(snp) > 1.) continue;
1225 ////////////////////////
1227 ///////////////////////
1229 if(TMath::Abs(dpad) < 1.5) {
1230 fPRF2d->Fill(shift+dpad,(caligroup+0.5),ycenter);
1231 fPRF2d->Fill(shift-dpad,(caligroup+0.5),ycenter);
1232 //printf("place %f, ycenter %f\n",(shift+dpad),ycenter);
1234 if((ymin > 0.0) && (TMath::Abs(dpad+1.0) < 1.5)) {
1235 fPRF2d->Fill(shift-(dpad+1.0),(caligroup+0.5),ymin);
1236 fPRF2d->Fill(shift+(dpad+1.0),(caligroup+0.5),ymin);
1238 if((ymax > 0.0) && (TMath::Abs(dpad-1.0) < 1.5)) {
1239 fPRF2d->Fill(shift+1.0-dpad,(caligroup+0.5),ymax);
1240 fPRF2d->Fill(shift-1.0+dpad,(caligroup+0.5),ymax);
1245 if(TMath::Abs(dpad) < 1.5) {
1246 fCalibraVector->UpdateVectorPRF(fDetectorPreviousTrack,grouplocal,shift+dpad,ycenter);
1247 fCalibraVector->UpdateVectorPRF(fDetectorPreviousTrack,grouplocal,shift-dpad,ycenter);
1249 if((ymin > 0.0) && (TMath::Abs(dpad+1.0) < 1.5)) {
1250 fCalibraVector->UpdateVectorPRF(fDetectorPreviousTrack,grouplocal,shift-(dpad+1.0),ymin);
1251 fCalibraVector->UpdateVectorPRF(fDetectorPreviousTrack,grouplocal,shift+(dpad+1.0),ymin);
1253 if((ymax > 0.0) && (TMath::Abs(dpad-1.0) < 1.5)) {
1254 fCalibraVector->UpdateVectorPRF(fDetectorPreviousTrack,grouplocal,shift+1.0-dpad,ymax);
1255 fCalibraVector->UpdateVectorPRF(fDetectorPreviousTrack,grouplocal,shift-1.0+dpad,ymax);
1258 } // second loop over clusters
1263 ///////////////////////////////////////////////////////////////////////////////////////
1264 // Pad row col stuff: see if masked or not
1265 ///////////////////////////////////////////////////////////////////////////////////////
1266 //_____________________________________________________________________________
1267 void AliTRDCalibraFillHisto::CheckGoodTrackletV1(const AliTRDcluster *cl)
1270 // See if we are not near a masked pad
1273 if(cl->IsMasked()) fGoodTracklet = kFALSE;
1277 //_____________________________________________________________________________
1278 void AliTRDCalibraFillHisto::CheckGoodTrackletV0(const Int_t detector,const Int_t row,const Int_t col)
1281 // See if we are not near a masked pad
1284 if (!IsPadOn(detector, col, row)) {
1285 fGoodTracklet = kFALSE;
1289 if (!IsPadOn(detector, col-1, row)) {
1290 fGoodTracklet = kFALSE;
1295 if (!IsPadOn(detector, col+1, row)) {
1296 fGoodTracklet = kFALSE;
1301 //_____________________________________________________________________________
1302 Bool_t AliTRDCalibraFillHisto::IsPadOn(Int_t detector, Int_t row, Int_t col) const
1305 // Look in the choosen database if the pad is On.
1306 // If no the track will be "not good"
1309 // Get the parameter object
1310 AliTRDcalibDB *cal = AliTRDcalibDB::Instance();
1312 AliInfo("Could not get calibDB");
1316 if (!cal->IsChamberGood(detector) ||
1317 cal->IsChamberNoData(detector) ||
1318 cal->IsPadMasked(detector,col,row)) {
1326 ///////////////////////////////////////////////////////////////////////////////////////
1327 // Calibration groups: calculate the number of groups, localise...
1328 ////////////////////////////////////////////////////////////////////////////////////////
1329 //_____________________________________________________________________________
1330 Int_t AliTRDCalibraFillHisto::CalculateCalibrationGroup(Int_t i, Int_t row, Int_t col) const
1333 // Calculate the calibration group number for i
1336 // Row of the cluster and position in the pad groups
1338 if (fCalibraMode->GetNnZ(i) != 0) {
1339 posr = (Int_t) row / fCalibraMode->GetNnZ(i);
1343 // Col of the cluster and position in the pad groups
1345 if (fCalibraMode->GetNnRphi(i) != 0) {
1346 posc = (Int_t) col / fCalibraMode->GetNnRphi(i);
1349 return posc*fCalibraMode->GetNfragZ(i)+posr;
1352 //____________________________________________________________________________________
1353 Int_t AliTRDCalibraFillHisto::CalculateTotalNumberOfBins(Int_t i)
1356 // Calculate the total number of calibration groups
1362 if((fCalibraMode->GetNz(i)==100) && (fCalibraMode->GetNrphi(i)==100)){
1364 AliInfo(Form("Total number of Xbins: %d for i %d",ntotal,i));
1369 if((fCalibraMode->GetNz(i)==10) && (fCalibraMode->GetNrphi(i)==10)){
1371 AliInfo(Form("Total number of Xbins: %d for i %d",ntotal,i));
1376 fCalibraMode->ModePadCalibration(2,i);
1377 fCalibraMode->ModePadFragmentation(0,2,0,i);
1378 fCalibraMode->SetDetChamb2(i);
1379 ntotal += 6 * 18 * fCalibraMode->GetDetChamb2(i);
1380 fCalibraMode->ModePadCalibration(0,i);
1381 fCalibraMode->ModePadFragmentation(0,0,0,i);
1382 fCalibraMode->SetDetChamb0(i);
1383 ntotal += 6 * 4 * 18 * fCalibraMode->GetDetChamb0(i);
1384 AliInfo(Form("Total number of Xbins: %d for i %d",ntotal,i));
1388 //_____________________________________________________________________________
1389 void AliTRDCalibraFillHisto::SetNz(Int_t i, Short_t Nz)
1392 // Set the mode of calibration group in the z direction for the parameter i
1397 fCalibraMode->SetNz(i, Nz);
1400 AliInfo("You have to choose between 0 and 4");
1404 //_____________________________________________________________________________
1405 void AliTRDCalibraFillHisto::SetNrphi(Int_t i, Short_t Nrphi)
1408 // Set the mode of calibration group in the rphi direction for the parameter i
1413 fCalibraMode->SetNrphi(i ,Nrphi);
1416 AliInfo("You have to choose between 0 and 6");
1421 //_____________________________________________________________________________
1422 void AliTRDCalibraFillHisto::SetAllTogether(Int_t i)
1425 // Set the mode of calibration group all together
1427 if(fVector2d == kTRUE) {
1428 AliInfo("Can not work with the vector method");
1431 fCalibraMode->SetAllTogether(i);
1435 //_____________________________________________________________________________
1436 void AliTRDCalibraFillHisto::SetPerSuperModule(Int_t i)
1439 // Set the mode of calibration group per supermodule
1441 if(fVector2d == kTRUE) {
1442 AliInfo("Can not work with the vector method");
1445 fCalibraMode->SetPerSuperModule(i);
1449 //____________Set the pad calibration variables for the detector_______________
1450 Bool_t AliTRDCalibraFillHisto::LocalisationDetectorXbins(Int_t detector)
1453 // For the detector calcul the first Xbins and set the number of row
1454 // and col pads per calibration groups, the number of calibration
1455 // groups in the detector.
1458 // first Xbins of the detector
1460 fCalibraMode->CalculXBins(detector,0);
1463 fCalibraMode->CalculXBins(detector,1);
1466 fCalibraMode->CalculXBins(detector,2);
1469 // fragmentation of idect
1470 for (Int_t i = 0; i < 3; i++) {
1471 fCalibraMode->ModePadCalibration((Int_t) GetStack(detector),i);
1472 fCalibraMode->ModePadFragmentation((Int_t) GetLayer(detector)
1473 , (Int_t) GetStack(detector)
1474 , (Int_t) GetSector(detector),i);
1480 //_____________________________________________________________________________
1481 void AliTRDCalibraFillHisto::SetNumberGroupsPRF(Short_t numberGroupsPRF)
1484 // Should be between 0 and 6
1487 if ((numberGroupsPRF < 0) || (numberGroupsPRF > 6)) {
1488 AliInfo("The number of groups must be between 0 and 6!");
1491 fNgroupprf = numberGroupsPRF;
1495 ///////////////////////////////////////////////////////////////////////////////////////////
1496 // Per tracklet: store or reset the info, fill the histos with the info
1497 //////////////////////////////////////////////////////////////////////////////////////////
1498 //_____________________________________________________________________________
1499 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)
1502 // Store the infos in fAmpTotal, fPHPlace and fPHValue
1503 // Correct from the gain correction before
1504 // cls is shared cluster if any
1507 //printf("StoreInfoCHPHtrack\n");
1509 // time bin of the cluster not corrected
1510 Int_t time = cl->GetPadTime();
1511 Float_t charge = TMath::Abs(cl->GetQ());
1513 charge += TMath::Abs(cls->GetQ());
1514 //printf("AliTRDCalibraFillHisto::Add the cluster charge");
1517 //printf("Store::time %d, amplitude %f\n",time,dqdl);
1519 //Correct for the gain coefficient used in the database for reconstruction
1520 Float_t correctthegain = 1.0;
1521 if(fIsHLT) correctthegain = fCalDetGain->GetValue(fDetectorPreviousTrack);
1522 else correctthegain = fCalDetGain->GetValue(fDetectorPreviousTrack)*fCalROCGain->GetValue(col,row);
1523 Float_t correction = 1.0;
1524 Float_t normalisation = 6.67;
1525 // we divide with gain in AliTRDclusterizer::Transform...
1526 if( correctthegain > 0 ) normalisation /= correctthegain;
1529 // take dd/dl corrected from the angle of the track
1530 correction = dqdl / (normalisation);
1533 // Fill the fAmpTotal with the charge
1535 if((!fLimitChargeIntegration) || (cl->IsInChamber())) {
1536 //printf("Store::group %d, amplitude %f\n",group[0],correction);
1537 fAmpTotal[(Int_t) group[0]] += correction;
1541 // Fill the fPHPlace and value
1543 fPHPlace[time] = group[1];
1544 fPHValue[time] = charge;
1548 //____________Offine tracking in the AliTRDtracker_____________________________
1549 void AliTRDCalibraFillHisto::ResetfVariablestracklet()
1552 // Reset values per tracklet
1555 //Reset good tracklet
1556 fGoodTracklet = kTRUE;
1558 // Reset the fPHValue
1560 //Reset the fPHValue and fPHPlace
1561 for (Int_t k = 0; k < fTimeMax; k++) {
1567 // Reset the fAmpTotal where we put value
1569 for (Int_t k = 0; k < fCalibraMode->GetNfragZ(0)*fCalibraMode->GetNfragRphi(0); k++) {
1574 //____________Offine tracking in the AliTRDtracker_____________________________
1575 void AliTRDCalibraFillHisto::FillTheInfoOfTheTrackCH(Int_t nbclusters)
1578 // For the offline tracking or mcm tracklets
1579 // This function will be called in the functions UpdateHistogram...
1580 // to fill the info of a track for the relativ gain calibration
1583 Int_t nb = 0; // Nombre de zones traversees
1584 Int_t fd = -1; // Premiere zone non nulle
1585 Float_t totalcharge = 0.0; // Total charge for the supermodule histo
1587 //printf("CH2d nbclusters %d, fNumberClusters %d, fNumberClustersf %d\n",nbclusters,fNumberClusters,fNumberClustersf);
1589 if(nbclusters < fNumberClusters) return;
1590 if(nbclusters > fNumberClustersf) return;
1593 // Normalize with the number of clusters
1594 Double_t normalizeCst = fRelativeScale;
1595 if(fNormalizeNbOfCluster) normalizeCst = normalizeCst*nbclusters;
1597 //printf("Number of groups in one detector %d\n",fCalibraMode->GetNfragZ(0)*fCalibraMode->GetNfragRphi(0));
1599 // See if the track goes through different zones
1600 for (Int_t k = 0; k < fCalibraMode->GetNfragZ(0)*fCalibraMode->GetNfragRphi(0); k++) {
1601 //printf("fAmpTotal %f for %d\n",fAmpTotal[k],k);
1602 if (fAmpTotal[k] > 0.0) {
1603 totalcharge += fAmpTotal[k];
1611 //printf("CH2d: nb %d, fd %d, calibration group %d, amplitude %f, detector %d\n",nb,fd,fCalibraMode->GetXbins(0),fAmpTotal[fd]/normalizeCst,fDetectorPreviousTrack);
1617 fEntriesCH[fCalibraMode->GetXbins(0)+fd]++;
1619 FillCH2d(fCalibraMode->GetXbins(0)+fd,fAmpTotal[fd]/normalizeCst);
1620 //fCH2d->Fill(fAmpTotal[fd]/normalizeCst,fCalibraMode->GetXbins(0)+fd+0.5);
1623 fCalibraVector->UpdateVectorCH(fDetectorPreviousTrack,fd,fAmpTotal[fd]/normalizeCst);
1627 if ((fAmpTotal[fd] > 0.0) &&
1628 (fAmpTotal[fd+1] > 0.0)) {
1629 // One of the two very big
1630 if (fAmpTotal[fd] > fProcent*fAmpTotal[fd+1]) {
1632 FillCH2d(fCalibraMode->GetXbins(0)+fd,fAmpTotal[fd]/normalizeCst);
1633 //fCH2d->Fill(fAmpTotal[fd]/normalizeCst,fCalibraMode->GetXbins(0)+fd+0.5);
1636 fCalibraVector->UpdateVectorCH(fDetectorPreviousTrack,fd,fAmpTotal[fd]/normalizeCst);
1639 fEntriesCH[fCalibraMode->GetXbins(0)+fd]++;
1641 if (fAmpTotal[fd+1] > fProcent*fAmpTotal[fd]) {
1643 FillCH2d(fCalibraMode->GetXbins(0)+fd+1,fAmpTotal[fd+1]/normalizeCst);
1644 //fCH2d->Fill(fAmpTotal[fd+1]/normalizeCst,fCalibraMode->GetXbins(0)+fd+1.5);
1647 fCalibraVector->UpdateVectorCH(fDetectorPreviousTrack,fd+1,fAmpTotal[fd+1]/normalizeCst);
1650 fEntriesCH[fCalibraMode->GetXbins(0)+fd+1]++;
1653 if (fCalibraMode->GetNfragZ(0) > 1) {
1654 if (fAmpTotal[fd] > 0.0) {
1655 if ((fd+fCalibraMode->GetNfragZ(0)) < (fCalibraMode->GetNfragZ(0)*fCalibraMode->GetNfragRphi(0))) {
1656 if (fAmpTotal[fd+fCalibraMode->GetNfragZ(0)] > 0.0) {
1657 // One of the two very big
1658 if (fAmpTotal[fd] > fProcent*fAmpTotal[fd+fCalibraMode->GetNfragZ(0)]) {
1660 FillCH2d(fCalibraMode->GetXbins(0)+fd,fAmpTotal[fd]/normalizeCst);
1661 //fCH2d->Fill(fAmpTotal[fd]/normalizeCst,fCalibraMode->GetXbins(0)+fd+0.5);
1664 fCalibraVector->UpdateVectorCH(fDetectorPreviousTrack,fd,fAmpTotal[fd]/normalizeCst);
1667 fEntriesCH[fCalibraMode->GetXbins(0)+fd]++;
1669 if (fAmpTotal[fd+fCalibraMode->GetNfragZ(0)] > fProcent*fAmpTotal[fd]) {
1671 FillCH2d(fCalibraMode->GetXbins(0)+fd+fCalibraMode->GetNfragZ(0),fAmpTotal[fd+fCalibraMode->GetNfragZ(0)]/normalizeCst);
1672 //fCH2d->Fill(fAmpTotal[fd+fCalibraMode->GetNfragZ(0)]/normalizeCst,fCalibraMode->GetXbins(0)+fd+fCalibraMode->GetNfragZ(0)+0.5);
1675 fEntriesCH[fCalibraMode->GetXbins(0)+fd+fCalibraMode->GetNfragZ(0)]++;
1677 fCalibraVector->UpdateVectorCH(fDetectorPreviousTrack,fd+fCalibraMode->GetNfragZ(0),fAmpTotal[fd+fCalibraMode->GetNfragZ(0)]/normalizeCst);
1688 //____________Offine tracking in the AliTRDtracker_____________________________
1689 void AliTRDCalibraFillHisto::FillTheInfoOfTheTrackPH()
1692 // For the offline tracking or mcm tracklets
1693 // This function will be called in the functions UpdateHistogram...
1694 // to fill the info of a track for the drift velocity calibration
1697 Int_t nb = 1; // Nombre de zones traversees 1, 2 ou plus de 3
1698 Int_t fd1 = -1; // Premiere zone non nulle
1699 Int_t fd2 = -1; // Deuxieme zone non nulle
1700 Int_t k1 = -1; // Debut de la premiere zone
1701 Int_t k2 = -1; // Debut de la seconde zone
1702 Int_t nbclusters = 0; // number of clusters
1706 // See if the track goes through different zones
1707 for (Int_t k = 0; k < fTimeMax; k++) {
1708 if (fPHValue[k] > 0.0) {
1714 if (fPHPlace[k] != fd1) {
1720 if (fPHPlace[k] != fd2) {
1727 // See if noise before and after
1728 if(fMaxCluster > 0) {
1729 if(fPHValue[0] > fMaxCluster) return;
1730 if(fTimeMax > fNbMaxCluster) {
1731 for(Int_t k = (fTimeMax-fNbMaxCluster); k < fTimeMax; k++){
1732 if(fPHValue[k] > fMaxCluster) return;
1737 //printf("nbclusters %d, low limit %d, high limit %d\n",nbclusters,fNumberClusters,fNumberClustersf);
1739 if(nbclusters < fNumberClusters) return;
1740 if(nbclusters > fNumberClustersf) return;
1746 for (Int_t i = 0; i < fTimeMax; i++) {
1748 if(fFillWithZero) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd1)+0.5,(Float_t) fPHValue[i]);
1750 if(((Float_t) fPHValue[i] > 0.0)) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd1)+0.5,(Float_t) fPHValue[i]);
1752 //printf("Fill the time bin %d with %f\n",i,fPHValue[i]);
1755 if(fFillWithZero) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd1,i,fPHValue[i]);
1757 if(((Float_t) fPHValue[i] > 0.0)) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd1,i,fPHValue[i]);
1763 if ((fd1 == fd2+1) ||
1765 // One of the two fast all the think
1766 if (k2 > (k1+fDifference)) {
1767 //we choose to fill the fd1 with all the values
1769 for (Int_t i = 0; i < fTimeMax; i++) {
1771 if(fFillWithZero) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd1)+0.5,(Float_t) fPHValue[i]);
1773 if(((Float_t) fPHValue[i] > 0.0)) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd1)+0.5,(Float_t) fPHValue[i]);
1777 if(fFillWithZero) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd1,i,fPHValue[i]);
1779 if(((Float_t) fPHValue[i] > 0.0)) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd1,i,fPHValue[i]);
1784 if ((k2+fDifference) < fTimeMax) {
1785 //we choose to fill the fd2 with all the values
1787 for (Int_t i = 0; i < fTimeMax; i++) {
1789 if(fFillWithZero) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd2)+0.5,(Float_t) fPHValue[i]);
1791 if(((Float_t) fPHValue[i] > 0.0)) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd2)+0.5,(Float_t) fPHValue[i]);
1795 if(fFillWithZero) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd2,i,fPHValue[i]);
1797 if(((Float_t) fPHValue[i] > 0.0)) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd2,i,fPHValue[i]);
1803 // Two zones voisines sinon rien!
1804 if (fCalibraMode->GetNfragZ(1) > 1) {
1806 if ((fd1+fCalibraMode->GetNfragZ(1)) < (fCalibraMode->GetNfragZ(1)*fCalibraMode->GetNfragRphi(1))) {
1807 if (fd2 == (fd1+fCalibraMode->GetNfragZ(1))) {
1808 // One of the two fast all the think
1809 if (k2 > (k1+fDifference)) {
1810 //we choose to fill the fd1 with all the values
1812 for (Int_t i = 0; i < fTimeMax; i++) {
1814 if(fFillWithZero) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd1)+0.5,(Float_t) fPHValue[i]);
1816 if(((Float_t) fPHValue[i] > 0.0)) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd1)+0.5,(Float_t) fPHValue[i]);
1820 if(fFillWithZero) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd1,i,fPHValue[i]);
1822 if(((Float_t) fPHValue[i] > 0.0)) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd1,i,fPHValue[i]);
1827 if ((k2+fDifference) < fTimeMax) {
1828 //we choose to fill the fd2 with all the values
1830 for (Int_t i = 0; i < fTimeMax; i++) {
1832 if(fFillWithZero) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd2)+0.5,(Float_t) fPHValue[i]);
1834 if(((Float_t) fPHValue[i] > 0.0)) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd2)+0.5,(Float_t) fPHValue[i]);
1838 if(fFillWithZero) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd2,i,fPHValue[i]);
1840 if(((Float_t) fPHValue[i] > 0.0)) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd2,i,fPHValue[i]);
1847 // Two zones voisines sinon rien!
1849 if ((fd1 - fCalibraMode->GetNfragZ(1)) >= 0) {
1850 if (fd2 == (fd1 - fCalibraMode->GetNfragZ(1))) {
1851 // One of the two fast all the think
1852 if (k2 > (k1 + fDifference)) {
1853 //we choose to fill the fd1 with all the values
1855 for (Int_t i = 0; i < fTimeMax; i++) {
1857 if(fFillWithZero) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd1)+0.5,(Float_t) fPHValue[i]);
1859 if(((Float_t) fPHValue[i] > 0.0)) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd1)+0.5,(Float_t) fPHValue[i]);
1863 if(fFillWithZero) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd1,i,fPHValue[i]);
1865 if(((Float_t) fPHValue[i] > 0.0)) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd1,i,fPHValue[i]);
1870 if ((k2+fDifference) < fTimeMax) {
1871 //we choose to fill the fd2 with all the values
1873 for (Int_t i = 0; i < fTimeMax; i++) {
1875 if(fFillWithZero) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd2)+0.5,(Float_t) fPHValue[i]);
1877 if(((Float_t) fPHValue[i] > 0.0)) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd2)+0.5,(Float_t) fPHValue[i]);
1881 if(fFillWithZero) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd2,i,fPHValue[i]);
1883 if(((Float_t) fPHValue[i] > 0.0)) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd2,i,fPHValue[i]);
1895 //////////////////////////////////////////////////////////////////////////////////////////
1896 // DAQ process functions
1897 /////////////////////////////////////////////////////////////////////////////////////////
1898 //_____________________________________________________________________
1899 Int_t AliTRDCalibraFillHisto::ProcessEventDAQ(AliRawReader *rawReader)
1902 // Event Processing loop - AliTRDrawStream
1904 // 0 timebin problem
1907 // Same algorithm as TestBeam but different reader
1910 AliTRDrawStream *rawStream = new AliTRDrawStream(rawReader);
1912 AliTRDdigitsManager *digitsManager = new AliTRDdigitsManager(kTRUE);
1913 digitsManager->CreateArrays();
1915 Int_t withInput = 1;
1917 Double_t phvalue[16][144][36];
1918 for(Int_t k = 0; k < 36; k++){
1919 for(Int_t j = 0; j < 16; j++){
1920 for(Int_t c = 0; c < 144; c++){
1921 phvalue[j][c][k] = 0.0;
1926 fDetectorPreviousTrack = -1;
1930 Int_t nbtimebin = 0;
1931 Int_t baseline = 10;
1937 while ((det = rawStream->NextChamber(digitsManager, NULL, NULL)) >= 0) { //idetector
1939 if (digitsManager->GetIndexes(det)->HasEntry()) {//QA
1940 // printf("there is ADC data on this chamber!\n");
1942 AliTRDarrayADC *digits = (AliTRDarrayADC *) digitsManager->GetDigits(det); //mod
1943 if (digits->HasData()) { //array
1945 AliTRDSignalIndex *indexes = digitsManager->GetIndexes(det);
1946 if (indexes->IsAllocated() == kFALSE) {
1947 AliError("Indexes do not exist!");
1952 indexes->ResetCounters();
1954 while (indexes->NextRCIndex(iRow, iCol)) { //column,row
1955 //printf(" det %d \t row %d \t col %d \t digit\n",det,iRow,iCol);
1956 //while (rawStream->Next()) {
1958 Int_t idetector = det; // current detector
1959 //Int_t imcm = rawStream->GetMCM(); // current MCM
1960 //Int_t irob = rawStream->GetROB(); // current ROB
1963 if((fDetectorPreviousTrack != idetector) && (fDetectorPreviousTrack != -1)) {
1965 withInput = TMath::Max(FillDAQ(phvalue),withInput);
1968 for(Int_t k = 0; k < 36; k++){
1969 for(Int_t j = 0; j < 16; j++){
1970 for(Int_t c = 0; c < 144; c++){
1971 phvalue[j][c][k] = 0.0;
1977 fDetectorPreviousTrack = idetector;
1978 //fMCMPrevious = imcm;
1979 //fROBPrevious = irob;
1981 // nbtimebin = rawStream->GetNumberOfTimeBins(); // number of time bins read from data
1982 AliTRDdigitsParam *digitParam = (AliTRDdigitsParam *)digitsManager->GetDigitsParam();
1983 nbtimebin = digitParam->GetNTimeBins(det); // number of time bins read from data
1984 baseline = digitParam->GetADCbaseline(det); // baseline
1986 if(nbtimebin == 0) return 0;
1987 if((fTimeMax != 0) && (nbtimebin != fTimeMax)) return 0;
1988 fTimeMax = nbtimebin;
1990 fNumberClustersf = fTimeMax;
1991 fNumberClusters = (Int_t)(fNumberClustersProcent*fTimeMax);
1994 for(Int_t itime = 0; itime < nbtimebin; itime++) {
1995 // phvalue[row][col][itime] = signal[itime]-baseline;
1996 phvalue[iRow][iCol][itime] = (Short_t)(digits->GetData(iRow,iCol,itime) - baseline);
1997 /*if(phvalue[iRow][iCol][itime] >= 20) {
1998 printf("----------> phvalue[%d][%d][%d] %d baseline %d \n",
2002 (Short_t)(digits->GetData(iRow,iCol,itime)),
2009 // fill the last one
2010 if(fDetectorPreviousTrack != -1){
2013 withInput = TMath::Max(FillDAQ(phvalue),withInput);
2014 // printf("\n ---> withinput %d\n\n",withInput);
2016 for(Int_t k = 0; k < 36; k++){
2017 for(Int_t j = 0; j < 16; j++){
2018 for(Int_t c = 0; c < 144; c++){
2019 phvalue[j][c][k] = 0.0;
2027 digitsManager->ClearArrays(det);
2029 delete digitsManager;
2034 //_____________________________________________________________________
2035 //////////////////////////////////////////////////////////////////////////////
2036 // Routine inside the DAQ process
2037 /////////////////////////////////////////////////////////////////////////////
2038 //_______________________________________________________________________
2039 Int_t AliTRDCalibraFillHisto::FillDAQ(Double_t phvalue[16][144][36]){
2042 // Look for the maximum by collapsing over the time
2043 // Sum over four pad col and two pad row
2049 Int_t idect = fDetectorPreviousTrack;
2050 //printf("Enter Detector %d\n",fDetectorPreviousTrack);
2052 for(Int_t tb = 0; tb < 36; tb++){
2056 //fGoodTracklet = kTRUE;
2057 //fDetectorPreviousTrack = 0;
2060 ///////////////////////////
2062 /////////////////////////
2066 Double_t integralMax = -1;
2068 for (Int_t ir = 1; ir <= 15; ir++)
2070 for (Int_t ic = 2; ic <= 142; ic++)
2072 Double_t integral = 0;
2073 for (Int_t ishiftR = 0; ishiftR < fNumberRowDAQ; ishiftR++)
2075 for (Int_t ishiftC = -fNumberColDAQ; ishiftC < fNumberColDAQ; ishiftC++)
2077 if (ir + ishiftR >= 1 && ir + ishiftR <= 16 &&
2078 ic + ishiftC >= 1 && ic + ishiftC <= 144)
2081 for(Int_t tb = 0; tb< fTimeMax; tb++){
2082 integral += phvalue[ir + ishiftR-1][ic + ishiftC-1][tb];
2087 if (integralMax < integral)
2091 integralMax = integral;
2093 } // check max integral
2097 // printf("imaxRow %d, imaxCol %d, fTimeMax %d, integralMax %f\n",imaxRow,imaxCol,fTimeMax, integralMax);
2098 //if((imaxRow == 0) || (imaxRow >= 15) || (imaxCol <= 3) || (imaxCol >= 140)) {
2103 if(((imaxRow + fNumberRowDAQ) > 16) || (imaxRow == 0) || ((imaxCol - fNumberColDAQ) <= 1) || ((imaxCol + fNumberColDAQ) >= 144)) {
2107 //CheckGoodTrackletV0(fDetectorPreviousTrack,imaxRow,imaxCol);
2108 //if(!fGoodTracklet) used = 1;;
2110 // /////////////////////////////////////////////////////
2111 // sum ober 2 row and 4 pad cols for each time bins
2112 // ////////////////////////////////////////////////////
2116 for (Int_t ishiftR = 0; ishiftR < fNumberRowDAQ; ishiftR++)
2118 for (Int_t ishiftC = -fNumberColDAQ; ishiftC < fNumberColDAQ; ishiftC++)
2120 if (imaxRow + ishiftR >= 1 && imaxRow + ishiftR <= 16 &&
2121 imaxCol + ishiftC >= 1 && imaxCol + ishiftC <= 144)
2123 for(Int_t it = 0; it < fTimeMax; it++){
2124 sum[it] += phvalue[imaxRow + ishiftR-1][imaxCol + ishiftC-1][it];
2131 Double_t sumcharge = 0.0;
2132 for(Int_t it = 0; it < fTimeMax; it++){
2133 sumcharge += sum[it];
2134 if(sum[it] > fThresholdClustersDAQ) nbcl++;
2138 /////////////////////////////////////////////////////////
2140 ////////////////////////////////////////////////////////
2141 if(fDebugLevel > 0){
2142 if ( !fDebugStreamer ) {
2144 TDirectory *backup = gDirectory;
2145 fDebugStreamer = new TTreeSRedirector("TRDdebugCalibraFill.root");
2146 if ( backup ) backup->cd(); //we don't want to be cd'd to the debug streamer
2149 Double_t amph0 = sum[0];
2150 Double_t amphlast = sum[fTimeMax-1];
2151 Double_t rms = TMath::RMS(fTimeMax,sum);
2152 Int_t goodtracklet = (Int_t) fGoodTracklet;
2153 for(Int_t it = 0; it < fTimeMax; it++){
2154 Double_t clustera = sum[it];
2156 (* fDebugStreamer) << "FillDAQa"<<
2157 "ampTotal="<<sumcharge<<
2160 "detector="<<idect<<
2162 "amphlast="<<amphlast<<
2163 "goodtracklet="<<goodtracklet<<
2164 "clustera="<<clustera<<
2172 ////////////////////////////////////////////////////////
2174 ///////////////////////////////////////////////////////
2175 //printf("fNumberClusters %d, fNumberClustersf %d\n",fNumberClusters,fNumberClustersf);
2176 if(sum[0] > 100.0) used = 1;
2177 if(nbcl < fNumberClusters) used = 1;
2178 if(nbcl > fNumberClustersf) used = 1;
2180 //if(fDetectorPreviousTrack == 15){
2181 // printf("rms %f and first time bin %f\n",TMath::RMS(fTimeMax,sum),sum[0]);
2183 //if((TMath::RMS(fTimeMax,sum) <= 10.0) && (sum[0] > 200.0)) return 1;
2185 for(Int_t it = 0; it < fTimeMax; it++){
2186 if(fFillWithZero) UpdateDAQ(fDetectorPreviousTrack,0,0,it,sum[it],fTimeMax);
2188 if(sum[it] > 0.0) UpdateDAQ(fDetectorPreviousTrack,0,0,it,sum[it],fTimeMax);
2190 //if(fFillWithZero) UpdateDAQ(0,0,0,it,sum[it],fTimeMax);
2192 // if(sum[it] > 0.0) UpdateDAQ(0,0,0,it,sum[it],fTimeMax);
2197 //((TH2I *)GetCH2d()->Fill(sumcharge/30.0,fDetectorPreviousTrack));
2199 //printf("Pass Detector %d\n",fDetectorPreviousTrack);
2206 //____________Online trackling in AliTRDtrigger________________________________
2207 Bool_t AliTRDCalibraFillHisto::UpdateDAQ(Int_t det, Int_t /*row*/, Int_t /*col*/, Int_t timebin, Float_t signal, Int_t nbtimebins)
2211 // Fill a simple average pulse height
2215 ((TProfile2D *)GetPH2d(nbtimebins,fSf))->Fill((Float_t) timebin/fSf,det+0.5,(Float_t) signal);
2221 //____________Write_____________________________________________________
2222 //_____________________________________________________________________
2223 void AliTRDCalibraFillHisto::Write2d(const Char_t *filename, Bool_t append)
2226 // Write infos to file
2230 if ( fDebugStreamer ) {
2231 delete fDebugStreamer;
2232 fDebugStreamer = 0x0;
2235 AliInfo(Form("Numbertrack: %d Numberusedch[0]: %d, Numberusedch[1]: %d Numberusedph[0]: %d, Numberusedph[1]: %d"
2240 ,fNumberUsedPh[1]));
2242 TDirectory *backup = gDirectory;
2248 option = "recreate";
2250 TFile f(filename,option.Data());
2252 TStopwatch stopwatch;
2255 f.WriteTObject(fCalibraVector);
2260 f.WriteTObject(fCH2d);
2265 f.WriteTObject(fPH2d);
2270 f.WriteTObject(fPRF2d);
2273 if(fLinearFitterOn){
2274 if(fLinearFitterDebugOn) AnalyseLinearFitter();
2275 f.WriteTObject(fLinearVdriftFit);
2280 if ( backup ) backup->cd();
2282 AliInfo(Form("Execution time Write2d: R:%.2fs C:%.2fs"
2283 ,stopwatch.RealTime(),stopwatch.CpuTime()));
2285 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
2287 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
2288 //___________________________________________probe the histos__________________________________________________
2289 Double_t *AliTRDCalibraFillHisto::StatH(TH2 *h, Int_t i)
2292 // Check the number of stats in h, 0 is TH2I 1 is TProfile2D
2293 // debug mode with 2 for TH2I and 3 for TProfile2D
2294 // It gives a pointer to a Double_t[7] with the info following...
2295 // [0] : number of calibration groups with entries
2296 // [1] : minimal number of entries found
2297 // [2] : calibration group number of the min
2298 // [3] : maximal number of entries found
2299 // [4] : calibration group number of the max
2300 // [5] : mean number of entries found
2301 // [6] : mean relative error
2304 Double_t *info = new Double_t[7];
2306 // Number of Xbins (detectors or groups of pads)
2307 Int_t nbins = h->GetNbinsY(); //number of calibration groups
2308 Int_t nxbins = h->GetNbinsX(); //number of bins per histo
2311 Double_t nbwe = 0; //number of calibration groups with entries
2312 Double_t minentries = 0; //minimal number of entries found
2313 Double_t maxentries = 0; //maximal number of entries found
2314 Double_t placemin = 0; //calibration group number of the min
2315 Double_t placemax = -1; //calibration group number of the max
2316 Double_t meanstats = 0.0; //mean number of entries over the calibration group with at least ome entry
2317 Double_t meanrelativerror = 0.0; //mean relativ error in the TProfile2D
2319 Double_t counter = 0;
2322 TH1F *nbEntries = 0x0;//distribution of the number of entries
2323 TH1F *nbEntriesPerGroup = 0x0;//Number of entries per group
2324 TProfile *nbEntriesPerSp = 0x0;//Number of entries for one supermodule
2326 // Beginning of the loop over the calibration groups
2327 for (Int_t idect = 0; idect < nbins; idect++) {
2329 TH1I *projch = (TH1I *) h->ProjectionX("projch",idect+1,idect+1,(Option_t *)"e");
2330 projch->SetDirectory(0);
2332 // Number of entries for this calibration group
2333 Double_t nentries = 0.0;
2335 for (Int_t k = 0; k < nxbins; k++) {
2336 nentries += h->GetBinContent(h->GetBin(k+1,idect+1));
2340 for (Int_t k = 0; k < nxbins; k++) {
2341 nentries += ((TProfile2D *)h)->GetBinEntries(h->GetBin(k+1,idect+1));
2342 if(h->GetBinContent(h->GetBin(k+1,idect+1)) != 0) {
2343 meanrelativerror += (h->GetBinError(h->GetBin(k+1,idect+1))/(TMath::Abs(h->GetBinContent(h->GetBin(k+1,idect+1)))));
2352 if(!((Bool_t)nbEntries)) nbEntries = new TH1F("Number of entries","Number of entries",100,(Int_t)nentries/2,nentries*2);
2353 nbEntries->SetDirectory(0);
2354 nbEntries->Fill(nentries);
2355 if(!((Bool_t)nbEntriesPerGroup)) nbEntriesPerGroup = new TH1F("Number of entries per group","Number of entries per group",nbins,0,nbins);
2356 nbEntriesPerGroup->SetDirectory(0);
2357 nbEntriesPerGroup->Fill(idect+0.5,nentries);
2358 if(!((Bool_t)nbEntriesPerSp)) nbEntriesPerSp = new TProfile("Number of entries per supermodule","Number of entries per supermodule",(Int_t)(nbins/18),0,(Int_t)(nbins/18));
2359 nbEntriesPerSp->SetDirectory(0);
2360 nbEntriesPerSp->Fill((idect%((Int_t)(nbins/18)))+0.5,nentries);
2365 if(nentries > maxentries){
2366 maxentries = nentries;
2370 minentries = nentries;
2372 if(nentries < minentries){
2373 minentries = nentries;
2379 meanstats += nentries;
2381 }//calibration groups loop
2383 if(nbwe > 0) meanstats /= nbwe;
2384 if(counter > 0) meanrelativerror /= counter;
2386 AliInfo(Form("There are %f calibration groups with entries",nbwe));
2387 AliInfo(Form("The minimum number of entries is %f for the group %f",minentries,placemin));
2388 AliInfo(Form("The maximum number of entries is %f for the group %f",maxentries,placemax));
2389 AliInfo(Form("The mean number of entries is %f",meanstats));
2390 if((i%2) == 1) AliInfo(Form("The mean relative error is %f",meanrelativerror));
2393 info[1] = minentries;
2395 info[3] = maxentries;
2397 info[5] = meanstats;
2398 info[6] = meanrelativerror;
2400 if(nbEntries && nbEntriesPerSp && nbEntriesPerGroup){
2401 gStyle->SetPalette(1);
2402 gStyle->SetOptStat(1111);
2403 gStyle->SetPadBorderMode(0);
2404 gStyle->SetCanvasColor(10);
2405 gStyle->SetPadLeftMargin(0.13);
2406 gStyle->SetPadRightMargin(0.01);
2407 TCanvas *stat = new TCanvas("stat","",50,50,600,800);
2410 nbEntries->Draw("");
2412 nbEntriesPerSp->SetStats(0);
2413 nbEntriesPerSp->Draw("");
2414 TCanvas *stat1 = new TCanvas("stat1","",50,50,600,800);
2416 nbEntriesPerGroup->SetStats(0);
2417 nbEntriesPerGroup->Draw("");
2423 //____________________________________________________________________________
2424 Double_t *AliTRDCalibraFillHisto::GetMeanMedianRMSNumberCH()
2427 // Return a Int_t[4] with:
2428 // 0 Mean number of entries
2429 // 1 median of number of entries
2430 // 2 rms of number of entries
2431 // 3 number of group with entries
2434 Double_t *stat = new Double_t[4];
2437 Int_t nbofgroups = CalculateTotalNumberOfBins(0);
2439 Double_t *weight = new Double_t[nbofgroups];
2440 Double_t *nonul = new Double_t[nbofgroups];
2442 for(Int_t k = 0; k < nbofgroups; k++){
2443 if(fEntriesCH[k] > 0) {
2445 nonul[(Int_t)stat[3]] = fEntriesCH[k];
2448 else weight[k] = 0.0;
2450 stat[0] = TMath::Mean(nbofgroups,fEntriesCH,weight);
2451 stat[1] = TMath::Median(nbofgroups,fEntriesCH,weight);
2452 stat[2] = TMath::RMS((Int_t)stat[3],nonul);
2460 //____________________________________________________________________________
2461 Double_t *AliTRDCalibraFillHisto::GetMeanMedianRMSNumberLinearFitter() const
2464 // Return a Int_t[4] with:
2465 // 0 Mean number of entries
2466 // 1 median of number of entries
2467 // 2 rms of number of entries
2468 // 3 number of group with entries
2471 Double_t *stat = new Double_t[4];
2474 Int_t nbofgroups = 540;
2475 Double_t *weight = new Double_t[nbofgroups];
2476 Int_t *nonul = new Int_t[nbofgroups];
2478 for(Int_t k = 0; k < nbofgroups; k++){
2479 if(fEntriesLinearFitter[k] > 0) {
2481 nonul[(Int_t) stat[3]] = fEntriesLinearFitter[k];
2484 else weight[k] = 0.0;
2486 stat[0] = TMath::Mean(nbofgroups,fEntriesLinearFitter,weight);
2487 stat[1] = TMath::Median(nbofgroups,fEntriesLinearFitter,weight);
2488 stat[2] = TMath::RMS((Int_t)stat[3],nonul);
2496 //////////////////////////////////////////////////////////////////////////////////////
2498 //////////////////////////////////////////////////////////////////////////////////////
2499 //_____________________________________________________________________________
2500 void AliTRDCalibraFillHisto::CreatePRF2d(Int_t nn)
2503 // Create the 2D histos: here we have 2*fNgroupprf bins in tnp of 0.2 amplitude each
2504 // If fNgroupprf is zero then no binning in tnp
2508 name += fCalibraMode->GetNz(2);
2510 name += fCalibraMode->GetNrphi(2);
2514 if(fNgroupprf != 0){
2516 fPRF2d = new TProfile2D("PRF2d",(const Char_t *) name
2517 ,2*fNgroupprf*fNumberBinPRF,-3.0*fNgroupprf,3.0*fNgroupprf,nn,0,nn);
2518 fPRF2d->SetYTitle("Det/pad groups");
2519 fPRF2d->SetXTitle("Position x/W [pad width units]");
2520 fPRF2d->SetZTitle("Q_{i}/Q_{total}");
2521 fPRF2d->SetStats(0);
2524 fPRF2d = new TProfile2D("PRF2d",(const Char_t *) name
2525 ,fNumberBinPRF,-1.5,1.5,nn,0,nn);
2526 fPRF2d->SetYTitle("Det/pad groups");
2527 fPRF2d->SetXTitle("Position x/W [pad width units]");
2528 fPRF2d->SetZTitle("Q_{i}/Q_{total}");
2529 fPRF2d->SetStats(0);
2534 //_____________________________________________________________________________
2535 void AliTRDCalibraFillHisto::CreatePH2d(Int_t nn)
2538 // Create the 2D histos
2541 TString name("Ver");
2542 name += fVersionVdriftUsed;
2544 name += fSubVersionVdriftUsed;
2546 name += fFirstRunVdrift;
2548 name += fCalibraMode->GetNz(1);
2550 name += fCalibraMode->GetNrphi(1);
2552 fPH2d = new TProfile2D("PH2d",(const Char_t *) name
2553 ,fTimeMax,-0.5/fSf,(Float_t) (fTimeMax-0.5)/fSf
2555 fPH2d->SetYTitle("Det/pad groups");
2556 fPH2d->SetXTitle("time [#mus]");
2557 fPH2d->SetZTitle("<PH> [a.u.]");
2561 //_____________________________________________________________________________
2562 void AliTRDCalibraFillHisto::CreateCH2d(Int_t nn)
2565 // Create the 2D histos
2568 TString name("Ver");
2569 name += fVersionGainUsed;
2571 name += fSubVersionGainUsed;
2573 name += fFirstRunGain;
2575 name += fCalibraMode->GetNz(0);
2577 name += fCalibraMode->GetNrphi(0);
2579 fCH2d = new TH2I("CH2d",(const Char_t *) name
2580 ,fNumberBinCharge,0,300,nn,0,nn);
2581 fCH2d->SetYTitle("Det/pad groups");
2582 fCH2d->SetXTitle("charge deposit [a.u]");
2583 fCH2d->SetZTitle("counts");
2588 //////////////////////////////////////////////////////////////////////////////////
2589 // Set relative scale
2590 /////////////////////////////////////////////////////////////////////////////////
2591 //_____________________________________________________________________________
2592 void AliTRDCalibraFillHisto::SetRelativeScale(Float_t RelativeScale)
2595 // Set the factor that will divide the deposited charge
2596 // to fit in the histo range [0,300]
2599 if (RelativeScale > 0.0) {
2600 fRelativeScale = RelativeScale;
2603 AliInfo("RelativeScale must be strict positif!");
2607 //////////////////////////////////////////////////////////////////////////////////
2608 // Quick way to fill a histo
2609 //////////////////////////////////////////////////////////////////////////////////
2610 //_____________________________________________________________________
2611 void AliTRDCalibraFillHisto::FillCH2d(Int_t x, Float_t y)
2614 // FillCH2d: Marian style
2617 //skip simply the value out of range
2618 if((y>=300.0) || (y<0.0)) return;
2620 //Calcul the y place
2621 Int_t yplace = (Int_t) (fNumberBinCharge*y/300.0)+1;
2622 Int_t place = (fNumberBinCharge+2)*(x+1)+yplace;
2625 fCH2d->GetArray()[place]++;
2629 //////////////////////////////////////////////////////////////////////////////////
2630 // Geometrical functions
2631 ///////////////////////////////////////////////////////////////////////////////////
2632 //_____________________________________________________________________________
2633 Int_t AliTRDCalibraFillHisto::GetLayer(Int_t d) const
2636 // Reconstruct the layer number from the detector number
2639 return ((Int_t) (d % 6));
2643 //_____________________________________________________________________________
2644 Int_t AliTRDCalibraFillHisto::GetStack(Int_t d) const
2647 // Reconstruct the stack number from the detector number
2649 const Int_t kNlayer = 6;
2651 return ((Int_t) (d % 30) / kNlayer);
2655 //_____________________________________________________________________________
2656 Int_t AliTRDCalibraFillHisto::GetSector(Int_t d) const
2659 // Reconstruct the sector number from the detector number
2663 return ((Int_t) (d / fg));
2666 ///////////////////////////////////////////////////////////////////////////////////
2667 // Getter functions for DAQ of the CH2d and the PH2d
2668 //////////////////////////////////////////////////////////////////////////////////
2669 //_____________________________________________________________________
2670 TProfile2D* AliTRDCalibraFillHisto::GetPH2d(Int_t nbtimebin, Float_t samplefrequency)
2673 // return pointer to fPH2d TProfile2D
2674 // create a new TProfile2D if it doesn't exist allready
2680 fTimeMax = nbtimebin;
2681 fSf = samplefrequency;
2687 //_____________________________________________________________________
2688 TH2I* AliTRDCalibraFillHisto::GetCH2d()
2691 // return pointer to fCH2d TH2I
2692 // create a new TH2I if it doesn't exist allready
2701 ////////////////////////////////////////////////////////////////////////////////////////////
2702 // Drift velocity calibration
2703 ///////////////////////////////////////////////////////////////////////////////////////////
2704 //_____________________________________________________________________
2705 TLinearFitter* AliTRDCalibraFillHisto::GetLinearFitter(Int_t detector, Bool_t force)
2708 // return pointer to TLinearFitter Calibration
2709 // if force is true create a new TLinearFitter if it doesn't exist allready
2712 if ((!force) || (fLinearFitterArray.UncheckedAt(detector))){
2713 return (TLinearFitter*)fLinearFitterArray.UncheckedAt(detector);
2716 // if we are forced and TLinearFitter doesn't yet exist create it
2718 // new TLinearFitter
2719 TLinearFitter *linearfitter = new TLinearFitter(2,"pol1");
2720 fLinearFitterArray.AddAt(linearfitter,detector);
2721 return linearfitter;
2724 //____________________________________________________________________________
2725 void AliTRDCalibraFillHisto::AnalyseLinearFitter()
2728 // Analyse array of linear fitter because can not be written
2729 // Store two arrays: one with the param the other one with the error param + number of entries
2732 for(Int_t k = 0; k < 540; k++){
2733 TLinearFitter *linearfitter = GetLinearFitter(k);
2734 if((linearfitter!=0) && (fEntriesLinearFitter[k]>10)){
2735 TVectorD *par = new TVectorD(2);
2736 TVectorD pare = TVectorD(2);
2737 TVectorD *parE = new TVectorD(3);
2738 if((linearfitter->EvalRobust(0.8)==0)) {
2739 //linearfitter->Eval();
2740 linearfitter->GetParameters(*par);
2741 //linearfitter->GetErrors(pare);
2742 //Float_t ppointError = TMath::Sqrt(TMath::Abs(linearfitter->GetChisquare())/fEntriesLinearFitter[k]);
2743 //(*parE)[0] = pare[0]*ppointError;
2744 //(*parE)[1] = pare[1]*ppointError;
2748 (*parE)[2] = (Double_t) fEntriesLinearFitter[k];
2749 ((TObjArray *)fLinearVdriftFit->GetPArray())->AddAt(par,k);
2750 ((TObjArray *)fLinearVdriftFit->GetEArray())->AddAt(parE,k);