Fixing coverity 17819
[u/mrichter/AliRoot.git] / TRD / AliTRDCalibraFillHisto.cxx
CommitLineData
64942b85 1//**************************************************************************
2// * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3// * *
4// * Author: The ALICE Off-line Project. *
5// * Contributors are mentioned in the code where appropriate. *
6// * *
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//**************************************************************************/
55a288e5 15
16/* $Id$ */
17
18/////////////////////////////////////////////////////////////////////////////////
170c35f1 19//
55a288e5 20// AliTRDCalibraFillHisto
21//
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.
170c35f1 25// The user has to choose with the functions SetNz and SetNrphi the precision of the calibration (see AliTRDCalibraMode).
55a288e5 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.
30//
1785640c 31// Authors:
32// R. Bailhache (R.Bailhache@gsi.de, rbailhache@ikf.uni-frankfurt.de)
33// J. Book (jbook@ikf.uni-frankfurt.de)
55a288e5 34//
35//////////////////////////////////////////////////////////////////////////////////////
36
55a288e5 37#include <TProfile2D.h>
38#include <TProfile.h>
39#include <TFile.h>
55a288e5 40#include <TStyle.h>
41#include <TCanvas.h>
55a288e5 42#include <TObjArray.h>
d0569428 43#include <TObject.h>
55a288e5 44#include <TH1F.h>
45#include <TH2I.h>
46#include <TH2.h>
47#include <TStopwatch.h>
48#include <TMath.h>
49#include <TDirectory.h>
170c35f1 50#include <TTreeStream.h>
51#include <TVectorD.h>
6bbdc11a 52#include <TLinearFitter.h>
55a288e5 53
54#include "AliLog.h"
55a288e5 55
5f689709 56#include "AliESDtrack.h"
55a288e5 57#include "AliTRDCalibraFillHisto.h"
58#include "AliTRDCalibraMode.h"
59#include "AliTRDCalibraVector.h"
3a0f6479 60#include "AliTRDCalibraVdriftLinearFit.h"
a0bb5615 61#include "AliTRDCalibraExbAltFit.h"
55a288e5 62#include "AliTRDcalibDB.h"
63#include "AliTRDCommonParam.h"
55a288e5 64#include "AliTRDpadPlane.h"
65#include "AliTRDcluster.h"
bcb6fb78 66#include "AliTRDtrackV1.h"
3a0f6479 67#include "AliRawReader.h"
68#include "AliRawReaderDate.h"
f162af62 69#include "AliTRDgeometry.h"
a0bb5615 70#include "AliTRDfeeParam.h"
d0569428 71#include "./Cal/AliTRDCalROC.h"
a2a4ec8e 72#include "./Cal/AliTRDCalPad.h"
d0569428 73#include "./Cal/AliTRDCalDet.h"
170c35f1 74
1785640c 75#include "AliTRDdigitsManager.h"
76#include "AliTRDdigitsParam.h"
77#include "AliTRDSignalIndex.h"
78#include "AliTRDarrayADC.h"
79
fd50bb14 80#include "AliTRDrawStream.h"
81
a2a4ec8e 82#include "AliCDBEntry.h"
83#include "AliCDBManager.h"
fd50bb14 84
170c35f1 85#ifdef ALI_DATE
86#include "event.h"
87#endif
55a288e5 88
3a0f6479 89
55a288e5 90ClassImp(AliTRDCalibraFillHisto)
91
92AliTRDCalibraFillHisto* AliTRDCalibraFillHisto::fgInstance = 0;
93Bool_t AliTRDCalibraFillHisto::fgTerminated = kFALSE;
94
95//_____________singleton implementation_________________________________________________
96AliTRDCalibraFillHisto *AliTRDCalibraFillHisto::Instance()
97{
98 //
99 // Singleton implementation
100 //
101
102 if (fgTerminated != kFALSE) {
103 return 0;
104 }
105
106 if (fgInstance == 0) {
107 fgInstance = new AliTRDCalibraFillHisto();
108 }
109
110 return fgInstance;
111
112}
113
114//______________________________________________________________________________________
115void AliTRDCalibraFillHisto::Terminate()
116{
117 //
118 // Singleton implementation
119 // Deletes the instance of this class
120 //
121
122 fgTerminated = kTRUE;
123
124 if (fgInstance != 0) {
125 delete fgInstance;
126 fgInstance = 0;
127 }
128
129}
3a0f6479 130
55a288e5 131//______________________________________________________________________________________
132AliTRDCalibraFillHisto::AliTRDCalibraFillHisto()
133 :TObject()
f162af62 134 ,fGeo(0)
01239968 135 ,fCalibDB(0)
64942b85 136 ,fIsHLT(kFALSE)
55a288e5 137 ,fCH2dOn(kFALSE)
138 ,fPH2dOn(kFALSE)
139 ,fPRF2dOn(kFALSE)
140 ,fHisto2d(kFALSE)
141 ,fVector2d(kFALSE)
170c35f1 142 ,fLinearFitterOn(kFALSE)
143 ,fLinearFitterDebugOn(kFALSE)
a0bb5615 144 ,fExbAltFitOn(kFALSE)
55a288e5 145 ,fRelativeScale(0)
170c35f1 146 ,fThresholdClusterPRF2(15.0)
b70c68da 147 ,fLimitChargeIntegration(kFALSE)
f9ed5395 148 ,fFillWithZero(kFALSE)
64942b85 149 ,fNormalizeNbOfCluster(kFALSE)
150 ,fMaxCluster(0)
151 ,fNbMaxCluster(0)
5f689709 152 ,fCutWithVdriftCalib(kFALSE)
153 ,fMinNbTRDtracklets(0)
154 ,fMinTRDMomentum(0.0)
d085ba91 155 ,fFirstRunGain(0)
4c865c34 156 ,fVersionGainUsed(0)
157 ,fSubVersionGainUsed(0)
d085ba91 158 ,fFirstRunGainLocal(0)
a2a4ec8e 159 ,fVersionGainLocalUsed(0)
160 ,fSubVersionGainLocalUsed(0)
d085ba91 161 ,fFirstRunVdrift(0)
4c865c34 162 ,fVersionVdriftUsed(0)
163 ,fSubVersionVdriftUsed(0)
b2277aa2 164 ,fFirstRunExB(0)
165 ,fVersionExBUsed(0)
166 ,fSubVersionExBUsed(0)
170c35f1 167 ,fCalibraMode(new AliTRDCalibraMode())
168 ,fDebugStreamer(0)
169 ,fDebugLevel(0)
55a288e5 170 ,fDetectorPreviousTrack(-1)
e4db522f 171 ,fMCMPrevious(-1)
172 ,fROBPrevious(-1)
64942b85 173 ,fNumberClusters(1)
bcb6fb78 174 ,fNumberClustersf(30)
6aafa7ea 175 ,fNumberClustersProcent(0.5)
176 ,fThresholdClustersDAQ(120.0)
177 ,fNumberRowDAQ(2)
178 ,fNumberColDAQ(4)
170c35f1 179 ,fProcent(6.0)
180 ,fDifference(17)
181 ,fNumberTrack(0)
182 ,fTimeMax(0)
183 ,fSf(10.0)
e526983e 184 ,fNumberBinCharge(50)
185 ,fNumberBinPRF(10)
186 ,fNgroupprf(3)
55a288e5 187 ,fAmpTotal(0x0)
188 ,fPHPlace(0x0)
189 ,fPHValue(0x0)
170c35f1 190 ,fGoodTracklet(kTRUE)
1ca79a00 191 ,fLinearFitterTracklet(0x0)
170c35f1 192 ,fEntriesCH(0x0)
193 ,fEntriesLinearFitter(0x0)
194 ,fCalibraVector(0x0)
55a288e5 195 ,fPH2d(0x0)
196 ,fPRF2d(0x0)
197 ,fCH2d(0x0)
d0569428 198 ,fLinearFitterArray(540)
3a0f6479 199 ,fLinearVdriftFit(0x0)
a0bb5615 200 ,fExbAltFit(0x0)
d0569428 201 ,fCalDetGain(0x0)
202 ,fCalROCGain(0x0)
55a288e5 203{
204 //
205 // Default constructor
206 //
207
170c35f1 208 //
209 // Init some default values
210 //
55a288e5 211
170c35f1 212 fNumberUsedCh[0] = 0;
213 fNumberUsedCh[1] = 0;
214 fNumberUsedPh[0] = 0;
215 fNumberUsedPh[1] = 0;
3a0f6479 216
f162af62 217 fGeo = new AliTRDgeometry();
01239968 218 fCalibDB = AliTRDcalibDB::Instance();
55a288e5 219}
f162af62 220
55a288e5 221//______________________________________________________________________________________
222AliTRDCalibraFillHisto::AliTRDCalibraFillHisto(const AliTRDCalibraFillHisto &c)
f162af62 223 :TObject(c)
224 ,fGeo(0)
01239968 225 ,fCalibDB(0)
64942b85 226 ,fIsHLT(c.fIsHLT)
f162af62 227 ,fCH2dOn(c.fCH2dOn)
228 ,fPH2dOn(c.fPH2dOn)
229 ,fPRF2dOn(c.fPRF2dOn)
230 ,fHisto2d(c.fHisto2d)
231 ,fVector2d(c.fVector2d)
232 ,fLinearFitterOn(c.fLinearFitterOn)
233 ,fLinearFitterDebugOn(c.fLinearFitterDebugOn)
a0bb5615 234 ,fExbAltFitOn(c.fExbAltFitOn)
f162af62 235 ,fRelativeScale(c.fRelativeScale)
236 ,fThresholdClusterPRF2(c.fThresholdClusterPRF2)
b70c68da 237 ,fLimitChargeIntegration(c.fLimitChargeIntegration)
37b0cf5e 238 ,fFillWithZero(c.fFillWithZero)
64942b85 239 ,fNormalizeNbOfCluster(c.fNormalizeNbOfCluster)
240 ,fMaxCluster(c.fMaxCluster)
241 ,fNbMaxCluster(c.fNbMaxCluster)
5f689709 242 ,fCutWithVdriftCalib(c.fCutWithVdriftCalib)
243 ,fMinNbTRDtracklets(c.fMinNbTRDtracklets)
244 ,fMinTRDMomentum(c.fMinTRDMomentum)
d085ba91 245 ,fFirstRunGain(c.fFirstRunGain)
4c865c34 246 ,fVersionGainUsed(c.fVersionGainUsed)
247 ,fSubVersionGainUsed(c.fSubVersionGainUsed)
d085ba91 248 ,fFirstRunGainLocal(c.fFirstRunGainLocal)
a2a4ec8e 249 ,fVersionGainLocalUsed(c.fVersionGainLocalUsed)
250 ,fSubVersionGainLocalUsed(c.fSubVersionGainLocalUsed)
d085ba91 251 ,fFirstRunVdrift(c.fFirstRunVdrift)
4c865c34 252 ,fVersionVdriftUsed(c.fVersionVdriftUsed)
253 ,fSubVersionVdriftUsed(c.fSubVersionVdriftUsed)
b2277aa2 254 ,fFirstRunExB(c.fFirstRunExB)
255 ,fVersionExBUsed(c.fVersionExBUsed)
256 ,fSubVersionExBUsed(c.fSubVersionExBUsed)
f162af62 257 ,fCalibraMode(0x0)
258 ,fDebugStreamer(0)
259 ,fDebugLevel(c.fDebugLevel)
f162af62 260 ,fDetectorPreviousTrack(c.fDetectorPreviousTrack)
e4db522f 261 ,fMCMPrevious(c.fMCMPrevious)
262 ,fROBPrevious(c.fROBPrevious)
f162af62 263 ,fNumberClusters(c.fNumberClusters)
bcb6fb78 264 ,fNumberClustersf(c.fNumberClustersf)
6aafa7ea 265 ,fNumberClustersProcent(c.fNumberClustersProcent)
266 ,fThresholdClustersDAQ(c.fThresholdClustersDAQ)
267 ,fNumberRowDAQ(c.fNumberRowDAQ)
1785640c 268 ,fNumberColDAQ(c.fNumberColDAQ)
f162af62 269 ,fProcent(c.fProcent)
270 ,fDifference(c.fDifference)
271 ,fNumberTrack(c.fNumberTrack)
272 ,fTimeMax(c.fTimeMax)
273 ,fSf(c.fSf)
274 ,fNumberBinCharge(c.fNumberBinCharge)
275 ,fNumberBinPRF(c.fNumberBinPRF)
276 ,fNgroupprf(c.fNgroupprf)
3a0f6479 277 ,fAmpTotal(0x0)
278 ,fPHPlace(0x0)
279 ,fPHValue(0x0)
f162af62 280 ,fGoodTracklet(c.fGoodTracklet)
1ca79a00 281 ,fLinearFitterTracklet(0x0)
3a0f6479 282 ,fEntriesCH(0x0)
283 ,fEntriesLinearFitter(0x0)
f162af62 284 ,fCalibraVector(0x0)
285 ,fPH2d(0x0)
286 ,fPRF2d(0x0)
287 ,fCH2d(0x0)
d0569428 288 ,fLinearFitterArray(540)
3a0f6479 289 ,fLinearVdriftFit(0x0)
a0bb5615 290 ,fExbAltFit(0x0)
d0569428 291 ,fCalDetGain(0x0)
292 ,fCalROCGain(0x0)
55a288e5 293{
294 //
295 // Copy constructor
296 //
170c35f1 297 if(c.fCalibraMode) fCalibraMode = new AliTRDCalibraMode(*c.fCalibraMode);
298 if(c.fCalibraVector) fCalibraVector = new AliTRDCalibraVector(*c.fCalibraVector);
299 if(c.fPH2d) {
300 fPH2d = new TProfile2D(*c.fPH2d);
301 fPH2d->SetDirectory(0);
302 }
303 if(c.fPRF2d) {
304 fPRF2d = new TProfile2D(*c.fPRF2d);
305 fPRF2d->SetDirectory(0);
306 }
307 if(c.fCH2d) {
308 fCH2d = new TH2I(*c.fCH2d);
309 fCH2d->SetDirectory(0);
310 }
3a0f6479 311 if(c.fLinearVdriftFit){
312 fLinearVdriftFit = new AliTRDCalibraVdriftLinearFit(*c.fLinearVdriftFit);
170c35f1 313 }
a0bb5615 314 if(c.fExbAltFit){
315 fExbAltFit = new AliTRDCalibraExbAltFit(*c.fExbAltFit);
316 }
3a0f6479 317
d0569428 318 if(c.fCalDetGain) fCalDetGain = new AliTRDCalDet(*c.fCalDetGain);
d0569428 319 if(c.fCalROCGain) fCalROCGain = new AliTRDCalROC(*c.fCalROCGain);
d0569428 320
f162af62 321 if (fGeo) {
322 delete fGeo;
323 }
324 fGeo = new AliTRDgeometry();
01239968 325 fCalibDB = AliTRDcalibDB::Instance();
fdc15553 326
327 fNumberUsedCh[0] = 0;
328 fNumberUsedCh[1] = 0;
329 fNumberUsedPh[0] = 0;
330 fNumberUsedPh[1] = 0;
331
55a288e5 332}
f162af62 333
55a288e5 334//____________________________________________________________________________________
335AliTRDCalibraFillHisto::~AliTRDCalibraFillHisto()
336{
337 //
338 // AliTRDCalibraFillHisto destructor
339 //
340
341 ClearHistos();
170c35f1 342 if ( fDebugStreamer ) delete fDebugStreamer;
f162af62 343
d0569428 344 if ( fCalDetGain ) delete fCalDetGain;
d0569428 345 if ( fCalROCGain ) delete fCalROCGain;
d0569428 346
1ca79a00 347 if( fLinearFitterTracklet ) { delete fLinearFitterTracklet; }
348
349 delete [] fPHPlace;
350 delete [] fPHValue;
351 delete [] fEntriesCH;
352 delete [] fEntriesLinearFitter;
353 delete [] fAmpTotal;
354
355 for(Int_t idet=0; idet<AliTRDgeometry::kNdet; idet++){
356 TLinearFitter *f = (TLinearFitter*)fLinearFitterArray.At(idet);
357 if(f) { delete f;}
358 }
46c4871e 359 if(fLinearVdriftFit) delete fLinearVdriftFit;
a0bb5615 360 if(fExbAltFit) delete fExbAltFit;
f162af62 361 if (fGeo) {
362 delete fGeo;
363 }
55a288e5 364
365}
55a288e5 366//_____________________________________________________________________________
367void AliTRDCalibraFillHisto::Destroy()
368{
369 //
370 // Delete instance
371 //
372
373 if (fgInstance) {
374 delete fgInstance;
375 fgInstance = 0x0;
376 }
55a288e5 377}
bcb6fb78 378//_____________________________________________________________________________
379void AliTRDCalibraFillHisto::DestroyDebugStreamer()
380{
381 //
382 // Delete DebugStreamer
383 //
55a288e5 384
bcb6fb78 385 if ( fDebugStreamer ) delete fDebugStreamer;
64942b85 386 fDebugStreamer = 0x0;
bcb6fb78 387
388}
55a288e5 389//_____________________________________________________________________________
390void AliTRDCalibraFillHisto::ClearHistos()
391{
392 //
393 // Delete the histos
394 //
395
396 if (fPH2d) {
397 delete fPH2d;
398 fPH2d = 0x0;
399 }
400 if (fCH2d) {
401 delete fCH2d;
402 fCH2d = 0x0;
403 }
404 if (fPRF2d) {
405 delete fPRF2d;
406 fPRF2d = 0x0;
407 }
3a0f6479 408
55a288e5 409}
bcb6fb78 410//////////////////////////////////////////////////////////////////////////////////
411// calibration with AliTRDtrackV1: Init, Update
412//////////////////////////////////////////////////////////////////////////////////
55a288e5 413//____________Functions for initialising the AliTRDCalibraFillHisto in the code_________
9ff7be6d 414Bool_t AliTRDCalibraFillHisto::Init2Dhistos(Int_t nboftimebin)
55a288e5 415{
416 //
bcb6fb78 417 // Init the histograms and stuff to be filled
d0569428 418 //
419
55a288e5 420 // DB Setting
421 // Get cal
422 AliTRDcalibDB *cal = AliTRDcalibDB::Instance();
423 if (!cal) {
424 AliInfo("Could not get calibDB");
425 return kFALSE;
426 }
427 AliTRDCommonParam *parCom = AliTRDCommonParam::Instance();
428 if (!parCom) {
429 AliInfo("Could not get CommonParam");
430 return kFALSE;
431 }
432
433 // Some parameters
9ff7be6d 434 if(nboftimebin > 0) fTimeMax = nboftimebin;
c698a3d9 435 else fTimeMax = cal->GetNumberOfTimeBinsDCS();
5496295d 436 if(fTimeMax <= 0) fTimeMax = 30;
09ea3770 437 printf("////////////////////////////////////////////\n");
438 printf("Number of time bins in calibration component %d\n",fTimeMax);
439 printf("////////////////////////////////////////////\n");
d95484e4 440 fSf = parCom->GetSamplingFrequency();
64942b85 441 if(!fNormalizeNbOfCluster) fRelativeScale = 20.0;
442 else fRelativeScale = 1.18;
d95484e4 443 fNumberClustersf = fTimeMax;
6aafa7ea 444 fNumberClusters = (Int_t)(fNumberClustersProcent*fTimeMax);
d0569428 445
1ca79a00 446 // Init linear fitter
447 if(!fLinearFitterTracklet) {
448 fLinearFitterTracklet = new TLinearFitter(2,"pol1");
64942b85 449 fLinearFitterTracklet->StoreData(kTRUE);
1ca79a00 450 }
170c35f1 451
3a0f6479 452 // Calcul Xbins Chambd0, Chamb2
0c349049 453 Int_t ntotal0 = CalculateTotalNumberOfBins(0);
454 Int_t ntotal1 = CalculateTotalNumberOfBins(1);
455 Int_t ntotal2 = CalculateTotalNumberOfBins(2);
3a0f6479 456
457 // If vector method On initialised all the stuff
458 if(fVector2d){
55a288e5 459 fCalibraVector = new AliTRDCalibraVector();
170c35f1 460 fCalibraVector->SetNumberBinCharge(fNumberBinCharge);
461 fCalibraVector->SetTimeMax(fTimeMax);
462 if(fNgroupprf != 0) {
463 fCalibraVector->SetNumberBinPRF(2*fNgroupprf*fNumberBinPRF);
464 fCalibraVector->SetPRFRange((Float_t)(3.0*fNgroupprf));
465 }
466 else {
467 fCalibraVector->SetNumberBinPRF(fNumberBinPRF);
468 fCalibraVector->SetPRFRange(1.5);
469 }
3a0f6479 470 for(Int_t k = 0; k < 3; k++){
471 fCalibraVector->SetDetCha0(k,fCalibraMode->GetDetChamb0(k));
472 fCalibraVector->SetDetCha2(k,fCalibraMode->GetDetChamb2(k));
473 }
e526983e 474 fCalibraVector->SetNzNrphi(0,fCalibraMode->GetNz(0),fCalibraMode->GetNrphi(0));
475 fCalibraVector->SetNzNrphi(1,fCalibraMode->GetNz(1),fCalibraMode->GetNrphi(1));
476 fCalibraVector->SetNzNrphi(2,fCalibraMode->GetNz(2),fCalibraMode->GetNrphi(2));
477 fCalibraVector->SetNbGroupPRF(fNgroupprf);
55a288e5 478 }
170c35f1 479
55a288e5 480 // Create the 2D histos corresponding to the pad groupCalibration mode
481 if (fCH2dOn) {
482
483 AliInfo(Form("The pad calibration mode for the relative gain calibration: Nz %d, and Nrphi %d"
484 ,fCalibraMode->GetNz(0)
485 ,fCalibraMode->GetNrphi(0)));
486
55a288e5 487 // Create the 2D histo
488 if (fHisto2d) {
0c349049 489 CreateCH2d(ntotal0);
55a288e5 490 }
55a288e5 491 // Variable
492 fAmpTotal = new Float_t[TMath::Max(fCalibraMode->GetDetChamb2(0),fCalibraMode->GetDetChamb0(0))];
493 for (Int_t k = 0; k < TMath::Max(fCalibraMode->GetDetChamb2(0),fCalibraMode->GetDetChamb0(0)); k++) {
494 fAmpTotal[k] = 0.0;
495 }
170c35f1 496 //Statistics
0c349049 497 fEntriesCH = new Int_t[ntotal0];
498 for(Int_t k = 0; k < ntotal0; k++){
170c35f1 499 fEntriesCH[k] = 0;
500 }
3a0f6479 501
55a288e5 502 }
55a288e5 503 if (fPH2dOn) {
504
505 AliInfo(Form("The pad calibration mode for the drift velocity calibration: Nz %d, and Nrphi %d"
506 ,fCalibraMode->GetNz(1)
507 ,fCalibraMode->GetNrphi(1)));
508
55a288e5 509 // Create the 2D histo
510 if (fHisto2d) {
0c349049 511 CreatePH2d(ntotal1);
55a288e5 512 }
55a288e5 513 // Variable
514 fPHPlace = new Short_t[fTimeMax];
515 for (Int_t k = 0; k < fTimeMax; k++) {
516 fPHPlace[k] = -1;
517 }
518 fPHValue = new Float_t[fTimeMax];
519 for (Int_t k = 0; k < fTimeMax; k++) {
520 fPHValue[k] = 0.0;
521 }
170c35f1 522 }
523 if (fLinearFitterOn) {
46c4871e 524 if(fLinearFitterDebugOn) {
525 fLinearFitterArray.SetName("ArrayLinearFitters");
526 fEntriesLinearFitter = new Int_t[540];
527 for(Int_t k = 0; k < 540; k++){
528 fEntriesLinearFitter[k] = 0;
529 }
170c35f1 530 }
3a0f6479 531 fLinearVdriftFit = new AliTRDCalibraVdriftLinearFit();
b2277aa2 532 TString nameee("Ver");
533 nameee += fVersionExBUsed;
534 nameee += "Subver";
535 nameee += fSubVersionExBUsed;
536 nameee += "FirstRun";
537 nameee += fFirstRunExB;
538 nameee += "Nz";
539 fLinearVdriftFit->SetNameCalibUsed(nameee);
55a288e5 540 }
a0bb5615 541 if(fExbAltFitOn){
542 fExbAltFit = new AliTRDCalibraExbAltFit();
543 }
55a288e5 544
545 if (fPRF2dOn) {
546
547 AliInfo(Form("The pad calibration mode for the PRF calibration: Nz %d, and Nrphi %d"
548 ,fCalibraMode->GetNz(2)
549 ,fCalibraMode->GetNrphi(2)));
55a288e5 550 // Create the 2D histo
551 if (fHisto2d) {
0c349049 552 CreatePRF2d(ntotal2);
55a288e5 553 }
55a288e5 554 }
555
556 return kTRUE;
557
558}
a2a4ec8e 559///////////////////////////////////////////////////////////////////////////////////////////////////////////////
560Bool_t AliTRDCalibraFillHisto::InitCalDet()
561{
562 //
563 // Init the Gain Cal Det
564 //
565
566 // DB Setting
567 // Get cal
d085ba91 568 AliCDBEntry *entry = AliCDBManager::Instance()->Get("TRD/Calib/ChamberGainFactor",fFirstRunGain,fVersionGainUsed,fSubVersionGainUsed);
3b0c1edc 569 if(!entry) {
570 AliError("No gain det calibration entry found");
571 return kFALSE;
572 }
573 AliTRDCalDet *calDet = (AliTRDCalDet *)entry->GetObject();
574 if(!calDet) {
575 AliError("No calDet gain found");
a2a4ec8e 576 return kFALSE;
a2a4ec8e 577 }
3b0c1edc 578
579
580 if( fCalDetGain ){
581 fCalDetGain->~AliTRDCalDet();
582 new(fCalDetGain) AliTRDCalDet(*(calDet));
583 }else fCalDetGain = new AliTRDCalDet(*(calDet));
584
a2a4ec8e 585
586 // title CH2d
587 TString name("Ver");
588 name += fVersionGainUsed;
589 name += "Subver";
590 name += fSubVersionGainUsed;
ca7e6e64 591 name += "FirstRun";
592 name += fFirstRunGain;
a2a4ec8e 593 name += "Nz";
594 name += fCalibraMode->GetNz(0);
595 name += "Nrphi";
596 name += fCalibraMode->GetNrphi(0);
597
598 fCH2d->SetTitle(name);
599
600 // title PH2d
601 TString namee("Ver");
602 namee += fVersionVdriftUsed;
603 namee += "Subver";
604 namee += fSubVersionVdriftUsed;
ca7e6e64 605 namee += "FirstRun";
606 namee += fFirstRunVdrift;
a2a4ec8e 607 namee += "Nz";
608 namee += fCalibraMode->GetNz(1);
609 namee += "Nrphi";
610 namee += fCalibraMode->GetNrphi(1);
611
612 fPH2d->SetTitle(namee);
613
b2277aa2 614 // title AliTRDCalibraVdriftLinearFit
615 TString nameee("Ver");
616 nameee += fVersionExBUsed;
617 nameee += "Subver";
618 nameee += fSubVersionExBUsed;
619 nameee += "FirstRun";
620 nameee += fFirstRunExB;
621 nameee += "Nz";
622
623
624 fLinearVdriftFit->SetNameCalibUsed(nameee);
625
626
a2a4ec8e 627
628 return kTRUE;
629
630}
631///////////////////////////////////////////////////////////////////////////////////////////////////////////////
632Bool_t AliTRDCalibraFillHisto::InitCalPad(Int_t detector)
633{
634 //
635 // Init the Gain Cal Pad
636 //
637
638 // DB Setting
639 // Get cal
640 AliCDBEntry *entry = AliCDBManager::Instance()->Get("TRD/Calib/LocalGainFactor",AliCDBManager::Instance()->GetRun(),fVersionGainLocalUsed,fSubVersionGainLocalUsed);
3b0c1edc 641 if(!entry) {
642 AliError("No gain pad calibration entry found");
643 return kFALSE;
644 }
645 AliTRDCalPad *calPad = (AliTRDCalPad *)entry->GetObject();
646 if(!calPad) {
647 AliError("No calPad gain found");
648 return kFALSE;
649 }
650 AliTRDCalROC *calRoc = (AliTRDCalROC *)calPad->GetCalROC(detector);
651 if(!calRoc) {
652 AliError("No calRoc gain found");
653 return kFALSE;
654 }
a2a4ec8e 655
3b0c1edc 656 if( fCalROCGain ){
657 fCalROCGain->~AliTRDCalROC();
658 new(fCalROCGain) AliTRDCalROC(*(calRoc));
659 }else fCalROCGain = new AliTRDCalROC(*(calRoc));
a2a4ec8e 660
661
a2a4ec8e 662
3b0c1edc 663
a2a4ec8e 664
665 return kTRUE;
666
667}
d0569428 668//____________Offline tracking in the AliTRDtracker____________________________
5f689709 669Bool_t AliTRDCalibraFillHisto::UpdateHistogramsV1(const AliTRDtrackV1 *t,const AliESDtrack *esdtrack)
55a288e5 670{
671 //
bcb6fb78 672 // Use AliTRDtrackV1 for the calibration
55a288e5 673 //
674
bcb6fb78 675
676 const AliTRDseedV1 *tracklet = 0x0; // tracklet per plane
4aad967c 677 AliTRDcluster *cl = 0x0; // cluster attached now to the tracklet
1785640c 678 AliTRDcluster *cls = 0x0; // shared cluster attached now to the tracklet
4aad967c 679 Bool_t newtr = kTRUE; // new track
5f689709 680
681
682 //
683 // Cut on the number of TRD tracklets
684 //
685 Int_t numberoftrdtracklets = t->GetNumberOfTracklets();
686 if(numberoftrdtracklets < fMinNbTRDtracklets) return kFALSE;
687
688 //
01239968 689 if (!fCalibDB) {
690 AliInfo("Could not get calibDB");
691 return kFALSE;
692 }
693
bcb6fb78 694
695 ///////////////////////////
696 // loop over the tracklet
697 ///////////////////////////
698 for(Int_t itr = 0; itr < 6; itr++){
55a288e5 699
bcb6fb78 700 if(!(tracklet = t->GetTracklet(itr))) continue;
701 if(!tracklet->IsOK()) continue;
702 fNumberTrack++;
703 ResetfVariablestracklet();
5f689709 704 Float_t momentum = t->GetMomentum(itr);
705 if(TMath::Abs(momentum) < fMinTRDMomentum) continue;
706
bcb6fb78 707
708 //////////////////////////////////////////
709 // localisation of the tracklet and dqdl
710 //////////////////////////////////////////
053767a4 711 Int_t layer = tracklet->GetPlane();
bcb6fb78 712 Int_t ic = 0;
713 while(!(cl = tracklet->GetClusters(ic++))) continue;
714 Int_t detector = cl->GetDetector();
715 if (detector != fDetectorPreviousTrack) {
4aad967c 716 // if not a new track
717 if(!newtr){
718 // don't use the rest of this track if in the same plane
719 if (layer == GetLayer(fDetectorPreviousTrack)) {
720 //printf("bad tracklet, same layer for detector %d\n",detector);
721 break;
722 }
bcb6fb78 723 }
724 //Localise the detector bin
725 LocalisationDetectorXbins(detector);
bcb6fb78 726 // Get calib objects
a2a4ec8e 727 if(!fIsHLT) InitCalPad(detector);
728
bcb6fb78 729 // reset
730 fDetectorPreviousTrack = detector;
55a288e5 731 }
4aad967c 732 newtr = kFALSE;
55a288e5 733
bcb6fb78 734 ////////////////////////////
735 // loop over the clusters
736 ////////////////////////////
5f689709 737 Double_t chargeQ = 0.0;
bcb6fb78 738 Int_t nbclusters = 0;
e3cf3d02 739 for(int jc=0; jc<AliTRDseedV1::kNtb; jc++){
7bce990c 740 if(!(cl = tracklet->GetClusters(jc))) continue;
bcb6fb78 741 nbclusters++;
742
743 // Store the info bis of the tracklet
744 Int_t row = cl->GetPadRow();
745 Int_t col = cl->GetPadCol();
d95484e4 746 CheckGoodTrackletV1(cl);
bcb6fb78 747 Int_t group[2] = {0,0};
748 if(fCH2dOn) group[0] = CalculateCalibrationGroup(0,row,col);
749 if(fPH2dOn) group[1] = CalculateCalibrationGroup(1,row,col);
1785640c 750 // Add the charge if shared cluster
751 cls = tracklet->GetClusters(jc+AliTRDseedV1::kNtb);
752 //
5f689709 753 chargeQ += StoreInfoCHPHtrack(cl, tracklet->GetQperTB(jc),group,row,col,cls); //tracklet->GetdQdl(jc)
bcb6fb78 754 }
755
756 ////////////////////////////////////////
757 // Fill the stuffs if a good tracklet
758 ////////////////////////////////////////
759 if (fGoodTracklet) {
e526983e 760
bcb6fb78 761 // drift velocity unables to cut bad tracklets
762 Bool_t pass = FindP1TrackPHtrackletV1(tracklet, nbclusters);
763
e526983e 764 //printf("pass %d and nbclusters %d\n",pass,nbclusters);
765
55a288e5 766 // Gain calibration
767 if (fCH2dOn) {
5f689709 768 if(fCutWithVdriftCalib) {
769 if(pass) FillTheInfoOfTheTrackCH(nbclusters);
770 } else {
771 FillTheInfoOfTheTrackCH(nbclusters);
772 }
55a288e5 773 }
bcb6fb78 774
55a288e5 775 // PH calibration
776 if (fPH2dOn) {
5f689709 777 if(fCutWithVdriftCalib) {
778 if(pass) FillTheInfoOfTheTrackPH();
779 }
780 else {
781 FillTheInfoOfTheTrackPH();
782 }
55a288e5 783 }
bcb6fb78 784
785 if(pass && fPRF2dOn) HandlePRFtrackletV1(tracklet,nbclusters);
5f689709 786
787
788 /////////////////////////////////////////////////////////
789 // Debug
790 ////////////////////////////////////////////////////////
791 if(fDebugLevel > 0){
792 //printf("test\n");
793 if ( !fDebugStreamer ) {
794 //debug stream
795 TDirectory *backup = gDirectory;
796 fDebugStreamer = new TTreeSRedirector("TRDdebugCalibraFill.root");
797 if ( backup ) backup->cd(); //we don't want to be cd'd to the debug streamer
798 }
799
800 Int_t stacke = AliTRDgeometry::GetStack(detector);
801 Int_t sme = AliTRDgeometry::GetSector(detector);
802 Int_t layere = AliTRDgeometry::GetLayer(detector);
803 // Some variables
804 Float_t b[2] = {0.0,0.0};
805 Float_t bCov[3] = {0.0,0.0,0.0};
806 if(esdtrack) esdtrack->GetImpactParameters(b,bCov);
807 if (bCov[0]<=0 || bCov[2]<=0) {
808 bCov[0]=0; bCov[2]=0;
809 }
810 Float_t dcaxy = b[0];
811 Float_t dcaz = b[1];
812 Int_t tpcnbclusters = 0;
813 if(esdtrack) tpcnbclusters = esdtrack->GetTPCclusters(0);
814 Double_t tpcsignal = 0.0;
815 if(esdtrack) tpcsignal = esdtrack->GetTPCsignal();
816 Int_t cutvdriftlinear = 0;
817 if(!pass) cutvdriftlinear = 1;
818
819 (* fDebugStreamer) << "FillCharge"<<
820 "detector="<<detector<<
821 "stack="<<stacke<<
822 "sm="<<sme<<
823 "layere="<<layere<<
824 "dcaxy="<<dcaxy<<
825 "dcaz="<<dcaz<<
826 "nbtpccls="<<tpcnbclusters<<
827 "tpcsignal="<<tpcsignal<<
828 "cutvdriftlinear="<<cutvdriftlinear<<
829 "ptrd="<<momentum<<
830 "nbtrdtracklet="<<numberoftrdtracklets<<
831 "charge="<<chargeQ<<
832 "\n";
833 }
834
835
bcb6fb78 836 } // if a good tracklet
bcb6fb78 837 }
4aad967c 838
bcb6fb78 839 return kTRUE;
840
841}
842///////////////////////////////////////////////////////////////////////////////////
843// Routine inside the update with AliTRDtrack
844///////////////////////////////////////////////////////////////////////////////////
845//____________Offine tracking in the AliTRDtracker_____________________________
bcb6fb78 846Bool_t AliTRDCalibraFillHisto::FindP1TrackPHtrackletV1(const AliTRDseedV1 *tracklet, Int_t nbclusters)
55a288e5 847{
848 //
bcb6fb78 849 // Drift velocity calibration:
850 // Fit the clusters with a straight line
851 // From the slope find the drift velocity
55a288e5 852 //
bcb6fb78 853
854 ////////////////////////////////////////////////
855 //Number of points: if less than 3 return kFALSE
856 /////////////////////////////////////////////////
857 if(nbclusters <= 2) return kFALSE;
858
859 ////////////
860 //Variables
861 ////////////
bcb6fb78 862 // results of the linear fit
863 Double_t dydt = 0.0; // dydt tracklet after straight line fit
864 Double_t errorpar = 0.0; // error after straight line fit on dy/dt
865 Double_t pointError = 0.0; // error after straight line fit
866 // pad row problemes: avoid tracklet that cross pad rows, tilting angle in the constant
867 Int_t crossrow = 0; // if it crosses a pad row
868 Int_t rowp = -1; // if it crosses a pad row
869 Float_t tnt = tracklet->GetTilt(); // tan tiltingangle
1ca79a00 870 fLinearFitterTracklet->ClearPoints();
871
55a288e5 872
bcb6fb78 873 ///////////////////////////////////////////
874 // Take the parameters of the track
875 //////////////////////////////////////////
876 // take now the snp, tnp and tgl from the track
877 Double_t snp = tracklet->GetSnp(); // sin dy/dx at the end of the chamber
878 Double_t tnp = 0.0; // dy/dx at the end of the chamber
879 if( TMath::Abs(snp) < 1.){
60e55aee 880 tnp = snp / TMath::Sqrt((1.-snp)*(1.+snp));
bcb6fb78 881 }
882 Double_t tgl = tracklet->GetTgl(); // dz/dl
883 Double_t dzdx = tgl*TMath::Sqrt(1+tnp*tnp); // dz/dx calculated from dz/dl
884 // at the entrance
885 //Double_t tnp = tracklet->GetYref(1); // dy/dx at the entrance of the chamber
886 //Double_t tgl = tracklet->GetZref(1); // dz/dl at the entrance of the chamber
887 //Double_t dzdx = tgl; //*TMath::Sqrt(1+tnp*tnp); // dz/dx from dz/dl
888 // at the end with correction due to linear fit
889 //Double_t tnp = tracklet->GetYfit(1); // dy/dx at the end of the chamber after fit correction
890 //Double_t tgl = tracklet->GetZfit(1); // dz/dl at the end of the chamber after fit correction
891
892
893 ////////////////////////////
894 // loop over the clusters
895 ////////////////////////////
896 Int_t nbli = 0;
897 AliTRDcluster *cl = 0x0;
6aafa7ea 898 //////////////////////////////
899 // Check no shared clusters
900 //////////////////////////////
901 for(int icc=AliTRDseedV1::kNtb; icc<AliTRDseedV1::kNclusters; icc++){
3b0c1edc 902 cl = tracklet->GetClusters(icc);
903 if(cl) crossrow = 1;
6aafa7ea 904 }
905 //////////////////////////////////
906 // Loop clusters
907 //////////////////////////////////
a0bb5615 908
2a1a7b36 909 Float_t sigArr[AliTRDfeeParam::GetNcol()];
a0bb5615 910 memset(sigArr, 0, AliTRDfeeParam::GetNcol()*sizeof(sigArr[0]));
911 Int_t ncl=0, tbf=0, tbl=0;
912
e3cf3d02 913 for(int ic=0; ic<AliTRDseedV1::kNtb; ic++){
bcb6fb78 914 if(!(cl = tracklet->GetClusters(ic))) continue;
a0bb5615 915
916 if(!tbf) tbf=ic;
917 tbl=ic;
918 ncl++;
919 Int_t col = cl->GetPadCol();
920 for(int ip=-1, jp=2; jp<5; ip++, jp++){
921 Int_t idx=col+ip;
922 if(idx<0 || idx>=AliTRDfeeParam::GetNcol()) continue;
2a1a7b36 923 sigArr[idx]+=((Float_t)cl->GetSignals()[jp]);
a0bb5615 924 }
925
b70c68da 926 if((fLimitChargeIntegration) && (!cl->IsInChamber())) continue;
bcb6fb78 927
928 Double_t ycluster = cl->GetY();
929 Int_t time = cl->GetPadTime();
930 Double_t timeis = time/fSf;
931 //See if cross two pad rows
932 Int_t row = cl->GetPadRow();
933 if(rowp==-1) rowp = row;
934 if(row != rowp) crossrow = 1;
935
1ca79a00 936 fLinearFitterTracklet->AddPoint(&timeis,ycluster,1);
bcb6fb78 937 nbli++;
55a288e5 938
1785640c 939
55a288e5 940 }
170c35f1 941
bcb6fb78 942 ////////////////////////////////////
943 // Do the straight line fit now
944 ///////////////////////////////////
1ca79a00 945 if(nbli <= 2){
946 fLinearFitterTracklet->ClearPoints();
947 return kFALSE;
948 }
bcb6fb78 949 TVectorD pars;
1ca79a00 950 fLinearFitterTracklet->Eval();
951 fLinearFitterTracklet->GetParameters(pars);
2a1a7b36 952 pointError = TMath::Sqrt(TMath::Abs(fLinearFitterTracklet->GetChisquare()/(nbli-2)));
1ca79a00 953 errorpar = fLinearFitterTracklet->GetParError(1)*pointError;
bcb6fb78 954 dydt = pars[1];
64942b85 955 //printf("chis %f, nbli %d, pointError %f, parError %f, errorpar %f\n",fLinearFitterTracklet->GetChisquare(),nbli,pointError,fLinearFitterTracklet->GetParError(1),errorpar);
1ca79a00 956 fLinearFitterTracklet->ClearPoints();
a0bb5615 957
958 ////////////////////////////////////
959 // Calc the projection of the clusters on the y direction
960 ///////////////////////////////////
961
962 Float_t signalSum(0.);
2a1a7b36 963 Float_t mean = 0.0, rms = 0.0;
a0bb5615 964 Float_t dydx = tracklet->GetYref(1), tilt = tracklet->GetTilt(); // ,dzdx = tracklet->GetZref(1); (identical to the previous definition!)
965 Float_t dz = dzdx*(tbl-tbf)/10;
966 if(ncl>10){
967 for(Int_t ip(0); ip<AliTRDfeeParam::GetNcol(); ip++){
968 signalSum+=sigArr[ip];
969 mean+=ip*sigArr[ip];
970 }
2a1a7b36 971 if(signalSum > 0.0) mean/=signalSum;
a0bb5615 972
973 for(Int_t ip = 0; ip<AliTRDfeeParam::GetNcol(); ip++)
974 rms+=sigArr[ip]*(ip-mean)*(ip-mean);
2a1a7b36 975
976 if(signalSum > 0.0) rms = TMath::Sqrt(TMath::Abs(rms/signalSum));
a0bb5615 977
978 rms -= TMath::Abs(dz*tilt);
979 dydx -= dzdx*tilt;
980 }
bcb6fb78 981
982 ////////////////////////////////
983 // Debug stuff
984 ///////////////////////////////
985
986
5f689709 987 if(fDebugLevel > 1){
bcb6fb78 988 if ( !fDebugStreamer ) {
989 //debug stream
990 TDirectory *backup = gDirectory;
991 fDebugStreamer = new TTreeSRedirector("TRDdebugCalibraFill.root");
992 if ( backup ) backup->cd(); //we don't want to be cd'd to the debug streamer
993 }
994
a0bb5615 995 float xcoord = tnp-dzdx*tnt;
996 float pt = tracklet->GetPt();
053767a4 997 Int_t layer = GetLayer(fDetectorPreviousTrack);
64942b85 998
bcb6fb78 999 (* fDebugStreamer) << "FindP1TrackPHtrackletV1"<<
1000 //"snpright="<<snpright<<
64942b85 1001 "nbli="<<nbli<<
bcb6fb78 1002 "nbclusters="<<nbclusters<<
1003 "detector="<<fDetectorPreviousTrack<<
053767a4 1004 "layer="<<layer<<
bcb6fb78 1005 "snp="<<snp<<
1006 "tnp="<<tnp<<
1007 "tgl="<<tgl<<
1008 "tnt="<<tnt<<
1009 "dydt="<<dydt<<
1010 "dzdx="<<dzdx<<
1011 "crossrow="<<crossrow<<
1012 "errorpar="<<errorpar<<
1013 "pointError="<<pointError<<
a0bb5615 1014 "xcoord="<<xcoord<<
1015 "pt="<<pt<<
1016 "rms="<<rms<<
1017 "dydx="<<dydx<<
1018 "dz="<<dz<<
1019 "tilt="<<tilt<<
1020 "ncl="<<ncl<<
bcb6fb78 1021 "\n";
1022
4602df65 1023 }
bcb6fb78 1024
1025 /////////////////////////
1026 // Cuts quality
1027 ////////////////////////
c1105918 1028
bcb6fb78 1029 if(nbclusters < fNumberClusters) return kFALSE;
1030 if(nbclusters > fNumberClustersf) return kFALSE;
64942b85 1031 if(pointError >= 0.3) return kFALSE;
c1105918 1032 if(crossrow == 1) return kTRUE;
bcb6fb78 1033
1034 ///////////////////////
1035 // Fill
1036 //////////////////////
55a288e5 1037
bcb6fb78 1038 if(fLinearFitterOn){
1039 //Add to the linear fitter of the detector
1040 if( TMath::Abs(snp) < 1.){
1041 Double_t x = tnp-dzdx*tnt;
bcb6fb78 1042 if(fLinearFitterDebugOn) {
46c4871e 1043 (GetLinearFitter(fDetectorPreviousTrack,kTRUE))->AddPoint(&x,dydt);
1044 fEntriesLinearFitter[fDetectorPreviousTrack]++;
bcb6fb78 1045 }
46c4871e 1046 fLinearVdriftFit->Update(fDetectorPreviousTrack,x,pars[1]);
bcb6fb78 1047 }
1048 }
a0bb5615 1049 if(fExbAltFitOn){
1050 fExbAltFit->Update(fDetectorPreviousTrack,dydx,rms);
1051 }
bcb6fb78 1052
1053 return kTRUE;
1054}
1055//____________Offine tracking in the AliTRDtracker_____________________________
bcb6fb78 1056Bool_t AliTRDCalibraFillHisto::HandlePRFtrackletV1(const AliTRDseedV1 *tracklet, Int_t nbclusters)
170c35f1 1057{
1058 //
bcb6fb78 1059 // PRF width calibration
1060 // Assume a Gaussian shape: determinate the position of the three pad clusters
1061 // Fit with a straight line
1062 // Take the fitted values for all the clusters (3 or 2 pad clusters)
1063 // Fill the PRF as function of angle of the track
1064 //
170c35f1 1065 //
1066
4aad967c 1067 //printf("begin\n");
bcb6fb78 1068 ///////////////////////////////////////////
1069 // Take the parameters of the track
1070 //////////////////////////////////////////
1071 // take now the snp, tnp and tgl from the track
1072 Double_t snp = tracklet->GetSnp(); // sin dy/dx at the end of the chamber
1073 Double_t tnp = 0.0; // dy/dx at the end of the chamber
1074 if( TMath::Abs(snp) < 1.){
60e55aee 1075 tnp = snp / TMath::Sqrt((1.-snp)*(1.+snp));
bcb6fb78 1076 }
1077 Double_t tgl = tracklet->GetTgl(); // dz/dl
1078 Double_t dzdx = tgl*TMath::Sqrt(1+tnp*tnp); // dz/dx calculated from dz/dl
1079 // at the entrance
1080 //Double_t tnp = tracklet->GetYref(1); // dy/dx at the entrance of the chamber
1081 //Double_t tgl = tracklet->GetZref(1); // dz/dl at the entrance of the chamber
1082 //Double_t dzdx = tgl; //*TMath::Sqrt(1+tnp*tnp); // dz/dx from dz/dl
1083 // at the end with correction due to linear fit
1084 //Double_t tnp = tracklet->GetYfit(1); // dy/dx at the end of the chamber after fit correction
1085 //Double_t tgl = tracklet->GetZfit(1); // dz/dl at the end of the chamber after fit correction
1086
1087 ///////////////////////////////
1088 // Calculate tnp group shift
1089 ///////////////////////////////
1090 Bool_t echec = kFALSE;
1091 Double_t shift = 0.0;
1092 //Calculate the shift in x coresponding to this tnp
1093 if(fNgroupprf != 0.0){
1094 shift = -3.0*(fNgroupprf-1)-1.5;
1095 Double_t limithigh = -0.2*(fNgroupprf-1);
1096 if((tnp < (-0.2*fNgroupprf)) || (tnp > (0.2*fNgroupprf))) echec = kTRUE;
1097 else{
1098 while(tnp > limithigh){
1099 limithigh += 0.2;
1100 shift += 3.0;
1101 }
1102 }
1103 }
1104 // do nothing if out of tnp range
4aad967c 1105 //printf("echec %d\n",(Int_t)echec);
bcb6fb78 1106 if(echec) return kFALSE;
170c35f1 1107
bcb6fb78 1108 ///////////////////////
1109 // Variables
1110 //////////////////////
170c35f1 1111
bcb6fb78 1112 Int_t nb3pc = 0; // number of three pads clusters used for fit
e3cf3d02 1113 // to see the difference between the fit and the 3 pad clusters position
1114 Double_t padPositions[AliTRDseedV1::kNtb];
1115 memset(padPositions, 0, AliTRDseedV1::kNtb*sizeof(Double_t));
1ca79a00 1116 fLinearFitterTracklet->ClearPoints();
1117
4aad967c 1118 //printf("loop clusters \n");
bcb6fb78 1119 ////////////////////////////
1120 // loop over the clusters
1121 ////////////////////////////
1122 AliTRDcluster *cl = 0x0;
e3cf3d02 1123 for(int ic=0; ic<AliTRDseedV1::kNtb; ic++){
6cb3ebda 1124 // reject shared clusters on pad row
e526983e 1125 if((ic+AliTRDseedV1::kNtb) < AliTRDseedV1::kNclusters) {
35a82746 1126 cl = tracklet->GetClusters(ic+AliTRDseedV1::kNtb);
1127 if(cl) continue;
e526983e 1128 }
35a82746 1129 cl = tracklet->GetClusters(ic);
1130 if(!cl) continue;
e526983e 1131 Double_t time = cl->GetPadTime();
bcb6fb78 1132 if((time<=7) || (time>=21)) continue;
1133 Short_t *signals = cl->GetSignals();
1134 Float_t xcenter = 0.0;
7bce990c 1135 Bool_t echec1 = kTRUE;
170c35f1 1136
bcb6fb78 1137 /////////////////////////////////////////////////////////////
1138 // Center 3 balanced: position with the center of the pad
1139 /////////////////////////////////////////////////////////////
1140 if ((((Float_t) signals[3]) > 0.0) &&
1141 (((Float_t) signals[2]) > 0.0) &&
1142 (((Float_t) signals[4]) > 0.0)) {
7bce990c 1143 echec1 = kFALSE;
bcb6fb78 1144 // Security if the denomiateur is 0
1145 if ((((Float_t) (((Float_t) signals[3]) * ((Float_t) signals[3]))) /
1146 ((Float_t) (((Float_t) signals[2]) * ((Float_t) signals[4])))) != 1.0) {
1147 xcenter = 0.5 * (TMath::Log((Float_t) (((Float_t) signals[4]) / ((Float_t) signals[2]))))
1148 / (TMath::Log(((Float_t) (((Float_t) signals[3]) * ((Float_t) signals[3])))
1149 / ((Float_t) (((Float_t) signals[2]) * ((Float_t) signals[4])))));
1150 }
1151 else {
7bce990c 1152 echec1 = kTRUE;
bcb6fb78 1153 }
1154 }
7bce990c 1155 if(TMath::Abs(xcenter) > 0.5) echec1 = kTRUE;
1156 if(echec1) continue;
bcb6fb78 1157
1158 ////////////////////////////////////////////////////////
7bce990c 1159 //if no echec1: calculate with the position of the pad
bcb6fb78 1160 // Position of the cluster
1161 // fill the linear fitter
1162 ///////////////////////////////////////////////////////
1163 Double_t padPosition = xcenter + cl->GetPadCol();
1164 padPositions[ic] = padPosition;
1165 nb3pc++;
1ca79a00 1166 fLinearFitterTracklet->AddPoint(&time, padPosition,1);
170c35f1 1167
bcb6fb78 1168
1169 }//clusters loop
1170
4aad967c 1171 //printf("Fin loop clusters \n");
bcb6fb78 1172 //////////////////////////////
1173 // fit with a straight line
1174 /////////////////////////////
1ca79a00 1175 if(nb3pc < 3){
1ca79a00 1176 fLinearFitterTracklet->ClearPoints();
1ca79a00 1177 return kFALSE;
1178 }
1179 fLinearFitterTracklet->Eval();
bcb6fb78 1180 TVectorD line(2);
1ca79a00 1181 fLinearFitterTracklet->GetParameters(line);
bcb6fb78 1182 Float_t pointError = -1.0;
1ca79a00 1183 if( fLinearFitterTracklet->GetChisquare()>=0.0) {
1184 pointError = TMath::Sqrt( fLinearFitterTracklet->GetChisquare()/(nb3pc-2));
4aad967c 1185 }
1ca79a00 1186 fLinearFitterTracklet->ClearPoints();
1187
4aad967c 1188 //printf("PRF second loop \n");
bcb6fb78 1189 ////////////////////////////////////////////////
1190 // Fill the PRF: Second loop over clusters
1191 //////////////////////////////////////////////
e3cf3d02 1192 for(int ic=0; ic<AliTRDseedV1::kNtb; ic++){
6cb3ebda 1193 // reject shared clusters on pad row
3b0c1edc 1194 cl = tracklet->GetClusters(ic+AliTRDseedV1::kNtb);
1195 if(((ic+AliTRDseedV1::kNtb) < AliTRDseedV1::kNclusters) && (cl)) continue;
6cb3ebda 1196 //
3b0c1edc 1197 cl = tracklet->GetClusters(ic);
1198 if(!cl) continue;
bcb6fb78 1199
1200 Short_t *signals = cl->GetSignals(); // signal
e526983e 1201 Double_t time = cl->GetPadTime(); // time bin
bcb6fb78 1202 Float_t padPosTracklet = line[0]+line[1]*time; // reconstruct position from fit
1203 Float_t padPos = cl->GetPadCol(); // middle pad
1204 Double_t dpad = padPosTracklet - padPos; // reconstruct position relative to middle pad from fit
1205 Float_t ycenter = 0.0; // relative center charge
1206 Float_t ymin = 0.0; // relative left charge
1207 Float_t ymax = 0.0; // relative right charge
1208
1209 ////////////////////////////////////////////////////////////////
1210 // Calculate ycenter, ymin and ymax even for two pad clusters
1211 ////////////////////////////////////////////////////////////////
1212 if(((((Float_t) signals[3]) > 0.0) && (((Float_t) signals[2]) > 0.0)) ||
1213 ((((Float_t) signals[3]) > 0.0) && (((Float_t) signals[4]) > 0.0))){
1214 Float_t sum = ((Float_t) signals[2]) + ((Float_t) signals[3]) + ((Float_t) signals[4]);
1215 if(sum > 0.0) ycenter = ((Float_t) signals[3])/ sum;
1216 if(sum > 0.0) ymin = ((Float_t) signals[2])/ sum;
1217 if(sum > 0.0) ymax = ((Float_t) signals[4])/ sum;
1218 }
1219
1220 /////////////////////////
1221 // Calibration group
1222 ////////////////////////
1223 Int_t rowcl = cl->GetPadRow(); // row of cluster
1224 Int_t colcl = cl->GetPadCol(); // col of cluster
1225 Int_t grouplocal = CalculateCalibrationGroup(2,rowcl,colcl); // calcul the corresponding group
1226 Int_t caligroup = fCalibraMode->GetXbins(2)+ grouplocal; // calcul the corresponding group
1227 Float_t xcl = cl->GetY(); // y cluster
1228 Float_t qcl = cl->GetQ(); // charge cluster
053767a4 1229 Int_t layer = GetLayer(fDetectorPreviousTrack); // layer
1230 Int_t stack = GetStack(fDetectorPreviousTrack); // stack
bcb6fb78 1231 Double_t xdiff = dpad; // reconstructed position constant
1232 Double_t x = dpad; // reconstructed position moved
1233 Float_t ep = pointError; // error of fit
1234 Float_t signal1 = (Float_t)signals[1]; // signal at the border
1235 Float_t signal3 = (Float_t)signals[3]; // signal
1236 Float_t signal2 = (Float_t)signals[2]; // signal
1237 Float_t signal4 = (Float_t)signals[4]; // signal
1238 Float_t signal5 = (Float_t)signals[5]; // signal at the border
1239
1ca79a00 1240
1241
bcb6fb78 1242 /////////////////////
1243 // Debug stuff
1244 ////////////////////
1245
5f689709 1246 if(fDebugLevel > 1){
bcb6fb78 1247 if ( !fDebugStreamer ) {
1248 //debug stream
1249 TDirectory *backup = gDirectory;
1250 fDebugStreamer = new TTreeSRedirector("TRDdebugCalibraFill.root");
1251 if ( backup ) backup->cd(); //we don't want to be cd'd to the debug streamer
1252 }
1253
1254 x = xdiff;
1255 Int_t type=0;
1256 Float_t y = ycenter;
1257 (* fDebugStreamer) << "HandlePRFtrackletV1"<<
1258 "caligroup="<<caligroup<<
1259 "detector="<<fDetectorPreviousTrack<<
053767a4 1260 "layer="<<layer<<
1261 "stack="<<stack<<
bcb6fb78 1262 "npoints="<<nbclusters<<
1263 "Np="<<nb3pc<<
1264 "ep="<<ep<<
1265 "type="<<type<<
1266 "snp="<<snp<<
1267 "tnp="<<tnp<<
1268 "tgl="<<tgl<<
1269 "dzdx="<<dzdx<<
1270 "padPos="<<padPos<<
1271 "padPosition="<<padPositions[ic]<<
1272 "padPosTracklet="<<padPosTracklet<<
1273 "x="<<x<<
1274 "y="<<y<<
1275 "xcl="<<xcl<<
1276 "qcl="<<qcl<<
1277 "signal1="<<signal1<<
1278 "signal2="<<signal2<<
1279 "signal3="<<signal3<<
1280 "signal4="<<signal4<<
1281 "signal5="<<signal5<<
1282 "time="<<time<<
1283 "\n";
1284 x=-(xdiff+1);
1285 y = ymin;
1286 type=-1;
1287 (* fDebugStreamer) << "HandlePRFtrackletV1"<<
1288 "caligroup="<<caligroup<<
1289 "detector="<<fDetectorPreviousTrack<<
053767a4 1290 "layer="<<layer<<
1291 "stack="<<stack<<
bcb6fb78 1292 "npoints="<<nbclusters<<
1293 "Np="<<nb3pc<<
1294 "ep="<<ep<<
1295 "type="<<type<<
1296 "snp="<<snp<<
1297 "tnp="<<tnp<<
1298 "tgl="<<tgl<<
1299 "dzdx="<<dzdx<<
1300 "padPos="<<padPos<<
1301 "padPosition="<<padPositions[ic]<<
1302 "padPosTracklet="<<padPosTracklet<<
1303 "x="<<x<<
1304 "y="<<y<<
1305 "xcl="<<xcl<<
1306 "qcl="<<qcl<<
1307 "signal1="<<signal1<<
1308 "signal2="<<signal2<<
1309 "signal3="<<signal3<<
1310 "signal4="<<signal4<<
1311 "signal5="<<signal5<<
1312 "time="<<time<<
1313 "\n";
1314 x=1-xdiff;
1315 y = ymax;
1316 type=1;
1317 (* fDebugStreamer) << "HandlePRFtrackletV1"<<
1318 "caligroup="<<caligroup<<
1319 "detector="<<fDetectorPreviousTrack<<
053767a4 1320 "layer="<<layer<<
1321 "stack="<<stack<<
bcb6fb78 1322 "npoints="<<nbclusters<<
1323 "Np="<<nb3pc<<
1324 "ep="<<ep<<
1325 "type="<<type<<
1326 "snp="<<snp<<
1327 "tnp="<<tnp<<
1328 "tgl="<<tgl<<
1329 "dzdx="<<dzdx<<
1330 "padPos="<<padPos<<
1331 "padPosition="<<padPositions[ic]<<
1332 "padPosTracklet="<<padPosTracklet<<
1333 "x="<<x<<
1334 "y="<<y<<
1335 "xcl="<<xcl<<
1336 "qcl="<<qcl<<
1337 "signal1="<<signal1<<
1338 "signal2="<<signal2<<
1339 "signal3="<<signal3<<
1340 "signal4="<<signal4<<
1341 "signal5="<<signal5<<
1342 "time="<<time<<
1343 "\n";
1344
1345 }
1346
1347 /////////////////////
1348 // Cuts quality
1349 /////////////////////
1350 if(nbclusters < fNumberClusters) continue;
1351 if(nbclusters > fNumberClustersf) continue;
1352 if(nb3pc <= 5) continue;
1353 if((time >= 21) || (time < 7)) continue;
1354 if(TMath::Abs(qcl) < 80) continue;
1355 if( TMath::Abs(snp) > 1.) continue;
1356
1357
1358 ////////////////////////
1359 // Fill the histos
1360 ///////////////////////
1361 if (fHisto2d) {
1362 if(TMath::Abs(dpad) < 1.5) {
1363 fPRF2d->Fill(shift+dpad,(caligroup+0.5),ycenter);
1364 fPRF2d->Fill(shift-dpad,(caligroup+0.5),ycenter);
1365 //printf("place %f, ycenter %f\n",(shift+dpad),ycenter);
1366 }
1367 if((ymin > 0.0) && (TMath::Abs(dpad+1.0) < 1.5)) {
1368 fPRF2d->Fill(shift-(dpad+1.0),(caligroup+0.5),ymin);
1369 fPRF2d->Fill(shift+(dpad+1.0),(caligroup+0.5),ymin);
1370 }
1371 if((ymax > 0.0) && (TMath::Abs(dpad-1.0) < 1.5)) {
1372 fPRF2d->Fill(shift+1.0-dpad,(caligroup+0.5),ymax);
1373 fPRF2d->Fill(shift-1.0+dpad,(caligroup+0.5),ymax);
1374 }
1375 }
1376 // vector method
1377 if (fVector2d) {
1378 if(TMath::Abs(dpad) < 1.5) {
1379 fCalibraVector->UpdateVectorPRF(fDetectorPreviousTrack,grouplocal,shift+dpad,ycenter);
1380 fCalibraVector->UpdateVectorPRF(fDetectorPreviousTrack,grouplocal,shift-dpad,ycenter);
1381 }
1382 if((ymin > 0.0) && (TMath::Abs(dpad+1.0) < 1.5)) {
1383 fCalibraVector->UpdateVectorPRF(fDetectorPreviousTrack,grouplocal,shift-(dpad+1.0),ymin);
1384 fCalibraVector->UpdateVectorPRF(fDetectorPreviousTrack,grouplocal,shift+(dpad+1.0),ymin);
1385 }
1386 if((ymax > 0.0) && (TMath::Abs(dpad-1.0) < 1.5)) {
1387 fCalibraVector->UpdateVectorPRF(fDetectorPreviousTrack,grouplocal,shift+1.0-dpad,ymax);
1388 fCalibraVector->UpdateVectorPRF(fDetectorPreviousTrack,grouplocal,shift-1.0+dpad,ymax);
1389 }
1390 }
1391 } // second loop over clusters
1392
1393
1394 return kTRUE;
170c35f1 1395}
bcb6fb78 1396///////////////////////////////////////////////////////////////////////////////////////
1397// Pad row col stuff: see if masked or not
1398///////////////////////////////////////////////////////////////////////////////////////
170c35f1 1399//_____________________________________________________________________________
6bbdc11a 1400void AliTRDCalibraFillHisto::CheckGoodTrackletV1(const AliTRDcluster *cl)
d95484e4 1401{
1402 //
1403 // See if we are not near a masked pad
1404 //
1405
1406 if(cl->IsMasked()) fGoodTracklet = kFALSE;
1407
1408
1409}
1410//_____________________________________________________________________________
6bbdc11a 1411void AliTRDCalibraFillHisto::CheckGoodTrackletV0(const Int_t detector,const Int_t row,const Int_t col)
170c35f1 1412{
1413 //
1414 // See if we are not near a masked pad
1415 //
1416
170c35f1 1417 if (!IsPadOn(detector, col, row)) {
1418 fGoodTracklet = kFALSE;
1419 }
1420
1421 if (col > 0) {
1422 if (!IsPadOn(detector, col-1, row)) {
1423 fGoodTracklet = kFALSE;
1424 }
1425 }
1426
1427 if (col < 143) {
1428 if (!IsPadOn(detector, col+1, row)) {
1429 fGoodTracklet = kFALSE;
1430 }
1431 }
1432
1433}
55a288e5 1434//_____________________________________________________________________________
bcb6fb78 1435Bool_t AliTRDCalibraFillHisto::IsPadOn(Int_t detector, Int_t row, Int_t col) const
55a288e5 1436{
1437 //
1438 // Look in the choosen database if the pad is On.
1439 // If no the track will be "not good"
1440 //
1441
1442 // Get the parameter object
1443 AliTRDcalibDB *cal = AliTRDcalibDB::Instance();
1444 if (!cal) {
1445 AliInfo("Could not get calibDB");
1446 return kFALSE;
1447 }
1448
b2277aa2 1449 if (!cal->IsChamberGood(detector) ||
1450 cal->IsChamberNoData(detector) ||
55a288e5 1451 cal->IsPadMasked(detector,col,row)) {
1452 return kFALSE;
1453 }
1454 else {
1455 return kTRUE;
1456 }
1457
1458}
bcb6fb78 1459///////////////////////////////////////////////////////////////////////////////////////
1460// Calibration groups: calculate the number of groups, localise...
1461////////////////////////////////////////////////////////////////////////////////////////
170c35f1 1462//_____________________________________________________________________________
bcb6fb78 1463Int_t AliTRDCalibraFillHisto::CalculateCalibrationGroup(Int_t i, Int_t row, Int_t col) const
170c35f1 1464{
1465 //
1466 // Calculate the calibration group number for i
1467 //
1468
1469 // Row of the cluster and position in the pad groups
1470 Int_t posr = 0;
1471 if (fCalibraMode->GetNnZ(i) != 0) {
bcb6fb78 1472 posr = (Int_t) row / fCalibraMode->GetNnZ(i);
170c35f1 1473 }
1474
1475
1476 // Col of the cluster and position in the pad groups
1477 Int_t posc = 0;
1478 if (fCalibraMode->GetNnRphi(i) != 0) {
bcb6fb78 1479 posc = (Int_t) col / fCalibraMode->GetNnRphi(i);
170c35f1 1480 }
1481
1482 return posc*fCalibraMode->GetNfragZ(i)+posr;
1483
1484}
1485//____________________________________________________________________________________
1486Int_t AliTRDCalibraFillHisto::CalculateTotalNumberOfBins(Int_t i)
1487{
1488 //
1489 // Calculate the total number of calibration groups
1490 //
1491
0c349049 1492 Int_t ntotal = 0;
64942b85 1493
1494 // All together
1495 if((fCalibraMode->GetNz(i)==100) && (fCalibraMode->GetNrphi(i)==100)){
1496 ntotal = 1;
1497 AliInfo(Form("Total number of Xbins: %d for i %d",ntotal,i));
1498 return ntotal;
1499 }
1500
1501 // Per Supermodule
1502 if((fCalibraMode->GetNz(i)==10) && (fCalibraMode->GetNrphi(i)==10)){
1503 ntotal = 18;
1504 AliInfo(Form("Total number of Xbins: %d for i %d",ntotal,i));
1505 return ntotal;
1506 }
1507
1508 // More
170c35f1 1509 fCalibraMode->ModePadCalibration(2,i);
1510 fCalibraMode->ModePadFragmentation(0,2,0,i);
1511 fCalibraMode->SetDetChamb2(i);
0c349049 1512 ntotal += 6 * 18 * fCalibraMode->GetDetChamb2(i);
170c35f1 1513 fCalibraMode->ModePadCalibration(0,i);
1514 fCalibraMode->ModePadFragmentation(0,0,0,i);
1515 fCalibraMode->SetDetChamb0(i);
0c349049 1516 ntotal += 6 * 4 * 18 * fCalibraMode->GetDetChamb0(i);
1517 AliInfo(Form("Total number of Xbins: %d for i %d",ntotal,i));
1518 return ntotal;
170c35f1 1519
1520}
bcb6fb78 1521//_____________________________________________________________________________
1522void AliTRDCalibraFillHisto::SetNz(Int_t i, Short_t Nz)
1523{
1524 //
1525 // Set the mode of calibration group in the z direction for the parameter i
1526 //
1527
1528 if ((Nz >= 0) &&
1529 (Nz < 5)) {
1530 fCalibraMode->SetNz(i, Nz);
1531 }
1532 else {
1533 AliInfo("You have to choose between 0 and 4");
1534 }
1535
1536}
1537//_____________________________________________________________________________
1538void AliTRDCalibraFillHisto::SetNrphi(Int_t i, Short_t Nrphi)
1539{
1540 //
1541 // Set the mode of calibration group in the rphi direction for the parameter i
1542 //
1543
1544 if ((Nrphi >= 0) &&
1545 (Nrphi < 7)) {
1546 fCalibraMode->SetNrphi(i ,Nrphi);
1547 }
1548 else {
1549 AliInfo("You have to choose between 0 and 6");
1550 }
1551
1552}
64942b85 1553
1554//_____________________________________________________________________________
1555void AliTRDCalibraFillHisto::SetAllTogether(Int_t i)
1556{
1557 //
1558 // Set the mode of calibration group all together
1559 //
1560 if(fVector2d == kTRUE) {
1561 AliInfo("Can not work with the vector method");
1562 return;
1563 }
1564 fCalibraMode->SetAllTogether(i);
1565
1566}
1567
1568//_____________________________________________________________________________
1569void AliTRDCalibraFillHisto::SetPerSuperModule(Int_t i)
1570{
1571 //
1572 // Set the mode of calibration group per supermodule
1573 //
1574 if(fVector2d == kTRUE) {
1575 AliInfo("Can not work with the vector method");
1576 return;
1577 }
1578 fCalibraMode->SetPerSuperModule(i);
1579
1580}
1581
170c35f1 1582//____________Set the pad calibration variables for the detector_______________
1583Bool_t AliTRDCalibraFillHisto::LocalisationDetectorXbins(Int_t detector)
1584{
1585 //
1586 // For the detector calcul the first Xbins and set the number of row
1587 // and col pads per calibration groups, the number of calibration
1588 // groups in the detector.
1589 //
1590
1591 // first Xbins of the detector
1592 if (fCH2dOn) {
1593 fCalibraMode->CalculXBins(detector,0);
1594 }
1595 if (fPH2dOn) {
1596 fCalibraMode->CalculXBins(detector,1);
1597 }
1598 if (fPRF2dOn) {
1599 fCalibraMode->CalculXBins(detector,2);
1600 }
55a288e5 1601
170c35f1 1602 // fragmentation of idect
1603 for (Int_t i = 0; i < 3; i++) {
053767a4 1604 fCalibraMode->ModePadCalibration((Int_t) GetStack(detector),i);
1605 fCalibraMode->ModePadFragmentation((Int_t) GetLayer(detector)
1606 , (Int_t) GetStack(detector)
170c35f1 1607 , (Int_t) GetSector(detector),i);
1608 }
1609
1610 return kTRUE;
1611
1612}
1613//_____________________________________________________________________________
bcb6fb78 1614void AliTRDCalibraFillHisto::SetNumberGroupsPRF(Short_t numberGroupsPRF)
1615{
1616 //
1617 // Should be between 0 and 6
1618 //
1619
1620 if ((numberGroupsPRF < 0) || (numberGroupsPRF > 6)) {
1621 AliInfo("The number of groups must be between 0 and 6!");
1622 }
1623 else {
1624 fNgroupprf = numberGroupsPRF;
1625 }
1626
1627}
1628///////////////////////////////////////////////////////////////////////////////////////////
1629// Per tracklet: store or reset the info, fill the histos with the info
1630//////////////////////////////////////////////////////////////////////////////////////////
1631//_____________________________________________________________________________
5f689709 1632Float_t AliTRDCalibraFillHisto::StoreInfoCHPHtrack(const AliTRDcluster *cl,const Double_t dqdl,const Int_t *group,const Int_t row,const Int_t col,const AliTRDcluster *cls)
170c35f1 1633{
1634 //
1635 // Store the infos in fAmpTotal, fPHPlace and fPHValue
bcb6fb78 1636 // Correct from the gain correction before
1785640c 1637 // cls is shared cluster if any
5f689709 1638 // Return the charge
1639 //
170c35f1 1640 //
1641
09ea3770 1642 //printf("StoreInfoCHPHtrack\n");
1643
bcb6fb78 1644 // time bin of the cluster not corrected
1645 Int_t time = cl->GetPadTime();
e526983e 1646 Float_t charge = TMath::Abs(cl->GetQ());
09ea3770 1647 if(cls) {
1648 charge += TMath::Abs(cls->GetQ());
1649 //printf("AliTRDCalibraFillHisto::Add the cluster charge");
1650 }
e526983e 1651
1652 //printf("Store::time %d, amplitude %f\n",time,dqdl);
1653
d0569428 1654 //Correct for the gain coefficient used in the database for reconstruction
64942b85 1655 Float_t correctthegain = 1.0;
1656 if(fIsHLT) correctthegain = fCalDetGain->GetValue(fDetectorPreviousTrack);
1657 else correctthegain = fCalDetGain->GetValue(fDetectorPreviousTrack)*fCalROCGain->GetValue(col,row);
170c35f1 1658 Float_t correction = 1.0;
a0bb5615 1659 Float_t normalisation = 1.13; //org: 6.67; 1st: 1.056; 2nd: 1.13;
bcb6fb78 1660 // we divide with gain in AliTRDclusterizer::Transform...
d0569428 1661 if( correctthegain > 0 ) normalisation /= correctthegain;
bcb6fb78 1662
1663
1664 // take dd/dl corrected from the angle of the track
1665 correction = dqdl / (normalisation);
1666
170c35f1 1667
1668 // Fill the fAmpTotal with the charge
b70c68da 1669 if (fCH2dOn) {
e526983e 1670 if((!fLimitChargeIntegration) || (cl->IsInChamber())) {
1671 //printf("Store::group %d, amplitude %f\n",group[0],correction);
1672 fAmpTotal[(Int_t) group[0]] += correction;
1673 }
170c35f1 1674 }
1675
1676 // Fill the fPHPlace and value
1677 if (fPH2dOn) {
bcb6fb78 1678 fPHPlace[time] = group[1];
e526983e 1679 fPHValue[time] = charge;
d0569428 1680 }
5f689709 1681
1682 return correction;
d0569428 1683
1684}
bcb6fb78 1685//____________Offine tracking in the AliTRDtracker_____________________________
1686void AliTRDCalibraFillHisto::ResetfVariablestracklet()
d0569428 1687{
1688 //
bcb6fb78 1689 // Reset values per tracklet
d0569428 1690 //
d0569428 1691
bcb6fb78 1692 //Reset good tracklet
1693 fGoodTracklet = kTRUE;
1694
1695 // Reset the fPHValue
1696 if (fPH2dOn) {
1697 //Reset the fPHValue and fPHPlace
1698 for (Int_t k = 0; k < fTimeMax; k++) {
1699 fPHValue[k] = 0.0;
1700 fPHPlace[k] = -1;
1701 }
d0569428 1702 }
1703
bcb6fb78 1704 // Reset the fAmpTotal where we put value
d0569428 1705 if (fCH2dOn) {
bcb6fb78 1706 for (Int_t k = 0; k < fCalibraMode->GetNfragZ(0)*fCalibraMode->GetNfragRphi(0); k++) {
1707 fAmpTotal[k] = 0.0;
1708 }
d0569428 1709 }
bcb6fb78 1710}
1711//____________Offine tracking in the AliTRDtracker_____________________________
1712void AliTRDCalibraFillHisto::FillTheInfoOfTheTrackCH(Int_t nbclusters)
1713{
1714 //
1715 // For the offline tracking or mcm tracklets
1716 // This function will be called in the functions UpdateHistogram...
1717 // to fill the info of a track for the relativ gain calibration
1718 //
1719
1720 Int_t nb = 0; // Nombre de zones traversees
1721 Int_t fd = -1; // Premiere zone non nulle
1722 Float_t totalcharge = 0.0; // Total charge for the supermodule histo
d0569428 1723
e526983e 1724 //printf("CH2d nbclusters %d, fNumberClusters %d, fNumberClustersf %d\n",nbclusters,fNumberClusters,fNumberClustersf);
1725
bcb6fb78 1726 if(nbclusters < fNumberClusters) return;
1727 if(nbclusters > fNumberClustersf) return;
64942b85 1728
1729
1730 // Normalize with the number of clusters
1731 Double_t normalizeCst = fRelativeScale;
1732 if(fNormalizeNbOfCluster) normalizeCst = normalizeCst*nbclusters;
e526983e 1733
1734 //printf("Number of groups in one detector %d\n",fCalibraMode->GetNfragZ(0)*fCalibraMode->GetNfragRphi(0));
bcb6fb78 1735
1736 // See if the track goes through different zones
1737 for (Int_t k = 0; k < fCalibraMode->GetNfragZ(0)*fCalibraMode->GetNfragRphi(0); k++) {
e526983e 1738 //printf("fAmpTotal %f for %d\n",fAmpTotal[k],k);
bcb6fb78 1739 if (fAmpTotal[k] > 0.0) {
1740 totalcharge += fAmpTotal[k];
1741 nb++;
1742 if (nb == 1) {
1743 fd = k;
1744 }
1745 }
170c35f1 1746 }
bcb6fb78 1747
e526983e 1748 //printf("CH2d: nb %d, fd %d, calibration group %d, amplitude %f, detector %d\n",nb,fd,fCalibraMode->GetXbins(0),fAmpTotal[fd]/normalizeCst,fDetectorPreviousTrack);
bcb6fb78 1749
1750 switch (nb)
1751 {
1752 case 1:
1753 fNumberUsedCh[0]++;
1754 fEntriesCH[fCalibraMode->GetXbins(0)+fd]++;
1755 if (fHisto2d) {
64942b85 1756 FillCH2d(fCalibraMode->GetXbins(0)+fd,fAmpTotal[fd]/normalizeCst);
1757 //fCH2d->Fill(fAmpTotal[fd]/normalizeCst,fCalibraMode->GetXbins(0)+fd+0.5);
bcb6fb78 1758 }
1759 if (fVector2d) {
64942b85 1760 fCalibraVector->UpdateVectorCH(fDetectorPreviousTrack,fd,fAmpTotal[fd]/normalizeCst);
bcb6fb78 1761 }
1762 break;
1763 case 2:
1764 if ((fAmpTotal[fd] > 0.0) &&
1765 (fAmpTotal[fd+1] > 0.0)) {
1766 // One of the two very big
1767 if (fAmpTotal[fd] > fProcent*fAmpTotal[fd+1]) {
1768 if (fHisto2d) {
64942b85 1769 FillCH2d(fCalibraMode->GetXbins(0)+fd,fAmpTotal[fd]/normalizeCst);
1770 //fCH2d->Fill(fAmpTotal[fd]/normalizeCst,fCalibraMode->GetXbins(0)+fd+0.5);
bcb6fb78 1771 }
1772 if (fVector2d) {
64942b85 1773 fCalibraVector->UpdateVectorCH(fDetectorPreviousTrack,fd,fAmpTotal[fd]/normalizeCst);
bcb6fb78 1774 }
1775 fNumberUsedCh[1]++;
1776 fEntriesCH[fCalibraMode->GetXbins(0)+fd]++;
1777 }
1778 if (fAmpTotal[fd+1] > fProcent*fAmpTotal[fd]) {
1779 if (fHisto2d) {
64942b85 1780 FillCH2d(fCalibraMode->GetXbins(0)+fd+1,fAmpTotal[fd+1]/normalizeCst);
1781 //fCH2d->Fill(fAmpTotal[fd+1]/normalizeCst,fCalibraMode->GetXbins(0)+fd+1.5);
bcb6fb78 1782 }
1783 if (fVector2d) {
64942b85 1784 fCalibraVector->UpdateVectorCH(fDetectorPreviousTrack,fd+1,fAmpTotal[fd+1]/normalizeCst);
bcb6fb78 1785 }
1786 fNumberUsedCh[1]++;
1787 fEntriesCH[fCalibraMode->GetXbins(0)+fd+1]++;
1788 }
1789 }
1790 if (fCalibraMode->GetNfragZ(0) > 1) {
1791 if (fAmpTotal[fd] > 0.0) {
1792 if ((fd+fCalibraMode->GetNfragZ(0)) < (fCalibraMode->GetNfragZ(0)*fCalibraMode->GetNfragRphi(0))) {
1793 if (fAmpTotal[fd+fCalibraMode->GetNfragZ(0)] > 0.0) {
1794 // One of the two very big
1795 if (fAmpTotal[fd] > fProcent*fAmpTotal[fd+fCalibraMode->GetNfragZ(0)]) {
1796 if (fHisto2d) {
64942b85 1797 FillCH2d(fCalibraMode->GetXbins(0)+fd,fAmpTotal[fd]/normalizeCst);
1798 //fCH2d->Fill(fAmpTotal[fd]/normalizeCst,fCalibraMode->GetXbins(0)+fd+0.5);
bcb6fb78 1799 }
1800 if (fVector2d) {
64942b85 1801 fCalibraVector->UpdateVectorCH(fDetectorPreviousTrack,fd,fAmpTotal[fd]/normalizeCst);
bcb6fb78 1802 }
1803 fNumberUsedCh[1]++;
1804 fEntriesCH[fCalibraMode->GetXbins(0)+fd]++;
1805 }
1806 if (fAmpTotal[fd+fCalibraMode->GetNfragZ(0)] > fProcent*fAmpTotal[fd]) {
1807 if (fHisto2d) {
64942b85 1808 FillCH2d(fCalibraMode->GetXbins(0)+fd+fCalibraMode->GetNfragZ(0),fAmpTotal[fd+fCalibraMode->GetNfragZ(0)]/normalizeCst);
1809 //fCH2d->Fill(fAmpTotal[fd+fCalibraMode->GetNfragZ(0)]/normalizeCst,fCalibraMode->GetXbins(0)+fd+fCalibraMode->GetNfragZ(0)+0.5);
bcb6fb78 1810 }
1811 fNumberUsedCh[1]++;
1812 fEntriesCH[fCalibraMode->GetXbins(0)+fd+fCalibraMode->GetNfragZ(0)]++;
1813 if (fVector2d) {
64942b85 1814 fCalibraVector->UpdateVectorCH(fDetectorPreviousTrack,fd+fCalibraMode->GetNfragZ(0),fAmpTotal[fd+fCalibraMode->GetNfragZ(0)]/normalizeCst);
bcb6fb78 1815 }
1816 }
1817 }
1818 }
1819 }
1820 }
1821 break;
1822 default: break;
3d1ad7ac 1823 }
bcb6fb78 1824}
1825//____________Offine tracking in the AliTRDtracker_____________________________
1826void AliTRDCalibraFillHisto::FillTheInfoOfTheTrackPH()
1827{
1828 //
1829 // For the offline tracking or mcm tracklets
1830 // This function will be called in the functions UpdateHistogram...
1831 // to fill the info of a track for the drift velocity calibration
1832 //
1833
1834 Int_t nb = 1; // Nombre de zones traversees 1, 2 ou plus de 3
1835 Int_t fd1 = -1; // Premiere zone non nulle
1836 Int_t fd2 = -1; // Deuxieme zone non nulle
1837 Int_t k1 = -1; // Debut de la premiere zone
1838 Int_t k2 = -1; // Debut de la seconde zone
1839 Int_t nbclusters = 0; // number of clusters
1840
1841
1842
1843 // See if the track goes through different zones
1844 for (Int_t k = 0; k < fTimeMax; k++) {
1845 if (fPHValue[k] > 0.0) {
1846 nbclusters++;
1847 if (fd1 == -1) {
1848 fd1 = fPHPlace[k];
1849 k1 = k;
1850 }
1851 if (fPHPlace[k] != fd1) {
1852 if (fd2 == -1) {
1853 k2 = k;
1854 fd2 = fPHPlace[k];
1855 nb = 2;
1856 }
1857 if (fPHPlace[k] != fd2) {
1858 nb = 3;
1859 }
1860 }
1861 }
1862 }
1863
64942b85 1864 // See if noise before and after
1865 if(fMaxCluster > 0) {
1866 if(fPHValue[0] > fMaxCluster) return;
1867 if(fTimeMax > fNbMaxCluster) {
1868 for(Int_t k = (fTimeMax-fNbMaxCluster); k < fTimeMax; k++){
1869 if(fPHValue[k] > fMaxCluster) return;
1870 }
1871 }
1872 }
1873
4aad967c 1874 //printf("nbclusters %d, low limit %d, high limit %d\n",nbclusters,fNumberClusters,fNumberClustersf);
1875
bcb6fb78 1876 if(nbclusters < fNumberClusters) return;
1877 if(nbclusters > fNumberClustersf) return;
170c35f1 1878
bcb6fb78 1879 switch(nb)
1880 {
1881 case 1:
1882 fNumberUsedPh[0]++;
1883 for (Int_t i = 0; i < fTimeMax; i++) {
1884 if (fHisto2d) {
37b0cf5e 1885 if(fFillWithZero) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd1)+0.5,(Float_t) fPHValue[i]);
1886 else {
1887 if(((Float_t) fPHValue[i] > 0.0)) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd1)+0.5,(Float_t) fPHValue[i]);
1888 }
bcb6fb78 1889 //printf("Fill the time bin %d with %f\n",i,fPHValue[i]);
1890 }
1891 if (fVector2d) {
37b0cf5e 1892 if(fFillWithZero) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd1,i,fPHValue[i]);
1893 else {
1894 if(((Float_t) fPHValue[i] > 0.0)) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd1,i,fPHValue[i]);
1895 }
bcb6fb78 1896 }
1897 }
1898 break;
1899 case 2:
1900 if ((fd1 == fd2+1) ||
1901 (fd2 == fd1+1)) {
1902 // One of the two fast all the think
1903 if (k2 > (k1+fDifference)) {
1904 //we choose to fill the fd1 with all the values
1905 fNumberUsedPh[1]++;
1906 for (Int_t i = 0; i < fTimeMax; i++) {
1907 if (fHisto2d) {
37b0cf5e 1908 if(fFillWithZero) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd1)+0.5,(Float_t) fPHValue[i]);
1909 else {
1910 if(((Float_t) fPHValue[i] > 0.0)) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd1)+0.5,(Float_t) fPHValue[i]);
1911 }
bcb6fb78 1912 }
1913 if (fVector2d) {
37b0cf5e 1914 if(fFillWithZero) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd1,i,fPHValue[i]);
1915 else {
1916 if(((Float_t) fPHValue[i] > 0.0)) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd1,i,fPHValue[i]);
1917 }
bcb6fb78 1918 }
1919 }
1920 }
1921 if ((k2+fDifference) < fTimeMax) {
1922 //we choose to fill the fd2 with all the values
1923 fNumberUsedPh[1]++;
1924 for (Int_t i = 0; i < fTimeMax; i++) {
1925 if (fHisto2d) {
37b0cf5e 1926 if(fFillWithZero) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd2)+0.5,(Float_t) fPHValue[i]);
1927 else {
1928 if(((Float_t) fPHValue[i] > 0.0)) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd2)+0.5,(Float_t) fPHValue[i]);
1929 }
bcb6fb78 1930 }
1931 if (fVector2d) {
37b0cf5e 1932 if(fFillWithZero) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd2,i,fPHValue[i]);
1933 else {
1934 if(((Float_t) fPHValue[i] > 0.0)) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd2,i,fPHValue[i]);
1935 }
bcb6fb78 1936 }
1937 }
1938 }
1939 }
1940 // Two zones voisines sinon rien!
1941 if (fCalibraMode->GetNfragZ(1) > 1) {
1942 // Case 2
1943 if ((fd1+fCalibraMode->GetNfragZ(1)) < (fCalibraMode->GetNfragZ(1)*fCalibraMode->GetNfragRphi(1))) {
1944 if (fd2 == (fd1+fCalibraMode->GetNfragZ(1))) {
1945 // One of the two fast all the think
1946 if (k2 > (k1+fDifference)) {
1947 //we choose to fill the fd1 with all the values
1948 fNumberUsedPh[1]++;
1949 for (Int_t i = 0; i < fTimeMax; i++) {
1950 if (fHisto2d) {
37b0cf5e 1951 if(fFillWithZero) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd1)+0.5,(Float_t) fPHValue[i]);
1952 else {
1953 if(((Float_t) fPHValue[i] > 0.0)) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd1)+0.5,(Float_t) fPHValue[i]);
1954 }
bcb6fb78 1955 }
1956 if (fVector2d) {
37b0cf5e 1957 if(fFillWithZero) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd1,i,fPHValue[i]);
1958 else {
1959 if(((Float_t) fPHValue[i] > 0.0)) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd1,i,fPHValue[i]);
1960 }
bcb6fb78 1961 }
1962 }
1963 }
1964 if ((k2+fDifference) < fTimeMax) {
1965 //we choose to fill the fd2 with all the values
1966 fNumberUsedPh[1]++;
1967 for (Int_t i = 0; i < fTimeMax; i++) {
1968 if (fHisto2d) {
37b0cf5e 1969 if(fFillWithZero) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd2)+0.5,(Float_t) fPHValue[i]);
1970 else {
1971 if(((Float_t) fPHValue[i] > 0.0)) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd2)+0.5,(Float_t) fPHValue[i]);
1972 }
bcb6fb78 1973 }
1974 if (fVector2d) {
37b0cf5e 1975 if(fFillWithZero) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd2,i,fPHValue[i]);
1976 else {
1977 if(((Float_t) fPHValue[i] > 0.0)) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd2,i,fPHValue[i]);
1978 }
bcb6fb78 1979 }
1980 }
1981 }
1982 }
1983 }
1984 // Two zones voisines sinon rien!
1985 // Case 3
1986 if ((fd1 - fCalibraMode->GetNfragZ(1)) >= 0) {
1987 if (fd2 == (fd1 - fCalibraMode->GetNfragZ(1))) {
1988 // One of the two fast all the think
1989 if (k2 > (k1 + fDifference)) {
1990 //we choose to fill the fd1 with all the values
1991 fNumberUsedPh[1]++;
1992 for (Int_t i = 0; i < fTimeMax; i++) {
1993 if (fHisto2d) {
37b0cf5e 1994 if(fFillWithZero) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd1)+0.5,(Float_t) fPHValue[i]);
1995 else {
1996 if(((Float_t) fPHValue[i] > 0.0)) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd1)+0.5,(Float_t) fPHValue[i]);
1997 }
bcb6fb78 1998 }
1999 if (fVector2d) {
37b0cf5e 2000 if(fFillWithZero) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd1,i,fPHValue[i]);
2001 else {
2002 if(((Float_t) fPHValue[i] > 0.0)) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd1,i,fPHValue[i]);
2003 }
bcb6fb78 2004 }
2005 }
2006 }
2007 if ((k2+fDifference) < fTimeMax) {
2008 //we choose to fill the fd2 with all the values
2009 fNumberUsedPh[1]++;
2010 for (Int_t i = 0; i < fTimeMax; i++) {
2011 if (fHisto2d) {
37b0cf5e 2012 if(fFillWithZero) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd2)+0.5,(Float_t) fPHValue[i]);
2013 else {
2014 if(((Float_t) fPHValue[i] > 0.0)) fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd2)+0.5,(Float_t) fPHValue[i]);
2015 }
bcb6fb78 2016 }
2017 if (fVector2d) {
37b0cf5e 2018 if(fFillWithZero) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd2,i,fPHValue[i]);
2019 else {
2020 if(((Float_t) fPHValue[i] > 0.0)) fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd2,i,fPHValue[i]);
2021 }
bcb6fb78 2022 }
2023 }
2024 }
2025 }
2026 }
2027 }
2028 break;
2029 default: break;
2030 }
170c35f1 2031}
bcb6fb78 2032//////////////////////////////////////////////////////////////////////////////////////////
2033// DAQ process functions
2034/////////////////////////////////////////////////////////////////////////////////////////
170c35f1 2035//_____________________________________________________________________
8df1f8f5 2036Int_t AliTRDCalibraFillHisto::ProcessEventDAQ(AliRawReader *rawReader)
1785640c 2037 { //main
2038 //
fd50bb14 2039 // Event Processing loop - AliTRDrawStream
2040 //
2041 // 0 timebin problem
2042 // 1 no input
2043 // 2 input
2044 // Same algorithm as TestBeam but different reader
2045 //
2046
fd50bb14 2047 AliTRDrawStream *rawStream = new AliTRDrawStream(rawReader);
fd50bb14 2048
2049 AliTRDdigitsManager *digitsManager = new AliTRDdigitsManager(kTRUE);
2050 digitsManager->CreateArrays();
2051
2052 Int_t withInput = 1;
2053
2054 Double_t phvalue[16][144][36];
2055 for(Int_t k = 0; k < 36; k++){
2056 for(Int_t j = 0; j < 16; j++){
2057 for(Int_t c = 0; c < 144; c++){
2058 phvalue[j][c][k] = 0.0;
2059 }
2060 }
2061 }
2062
2063 fDetectorPreviousTrack = -1;
2064 fMCMPrevious = -1;
2065 fROBPrevious = -1;
2066
2067 Int_t nbtimebin = 0;
2068 Int_t baseline = 10;
2069
2070
2071 fTimeMax = 0;
2072
2073 Int_t det = 0;
2074 while ((det = rawStream->NextChamber(digitsManager, NULL, NULL)) >= 0) { //idetector
2075
2076 if (digitsManager->GetIndexes(det)->HasEntry()) {//QA
2077 // printf("there is ADC data on this chamber!\n");
2078
2079 AliTRDarrayADC *digits = (AliTRDarrayADC *) digitsManager->GetDigits(det); //mod
2080 if (digits->HasData()) { //array
2081
2082 AliTRDSignalIndex *indexes = digitsManager->GetIndexes(det);
2083 if (indexes->IsAllocated() == kFALSE) {
2084 AliError("Indexes do not exist!");
2085 break;
2086 }
2087 Int_t iRow = 0;
2088 Int_t iCol = 0;
2089 indexes->ResetCounters();
2090
2091 while (indexes->NextRCIndex(iRow, iCol)) { //column,row
2092 //printf(" det %d \t row %d \t col %d \t digit\n",det,iRow,iCol);
2093 //while (rawStream->Next()) {
2094
2095 Int_t idetector = det; // current detector
2096 //Int_t imcm = rawStream->GetMCM(); // current MCM
2097 //Int_t irob = rawStream->GetROB(); // current ROB
2098
2099
2100 if((fDetectorPreviousTrack != idetector) && (fDetectorPreviousTrack != -1)) {
2101 // Fill
2102 withInput = TMath::Max(FillDAQ(phvalue),withInput);
2103
2104 // reset
2105 for(Int_t k = 0; k < 36; k++){
2106 for(Int_t j = 0; j < 16; j++){
2107 for(Int_t c = 0; c < 144; c++){
2108 phvalue[j][c][k] = 0.0;
2109 }
2110 }
2111 }
2112 }
2113
2114 fDetectorPreviousTrack = idetector;
2115 //fMCMPrevious = imcm;
2116 //fROBPrevious = irob;
2117
2118 // nbtimebin = rawStream->GetNumberOfTimeBins(); // number of time bins read from data
2119 AliTRDdigitsParam *digitParam = (AliTRDdigitsParam *)digitsManager->GetDigitsParam();
2120 nbtimebin = digitParam->GetNTimeBins(det); // number of time bins read from data
2121 baseline = digitParam->GetADCbaseline(det); // baseline
2122
2123 if(nbtimebin == 0) return 0;
2124 if((fTimeMax != 0) && (nbtimebin != fTimeMax)) return 0;
2125 fTimeMax = nbtimebin;
2126
2127 fNumberClustersf = fTimeMax;
2128 fNumberClusters = (Int_t)(fNumberClustersProcent*fTimeMax);
2129
2130
2131 for(Int_t itime = 0; itime < nbtimebin; itime++) {
2132 // phvalue[row][col][itime] = signal[itime]-baseline;
2133 phvalue[iRow][iCol][itime] = (Short_t)(digits->GetData(iRow,iCol,itime) - baseline);
2134 /*if(phvalue[iRow][iCol][itime] >= 20) {
2135 printf("----------> phvalue[%d][%d][%d] %d baseline %d \n",
2136 iRow,
2137 iCol,
2138 itime,
2139 (Short_t)(digits->GetData(iRow,iCol,itime)),
2140 baseline);
2141 }*/
2142 }
2143
2144 }//column,row
2145
2146 // fill the last one
2147 if(fDetectorPreviousTrack != -1){
2148
2149 // Fill
2150 withInput = TMath::Max(FillDAQ(phvalue),withInput);
2151 // printf("\n ---> withinput %d\n\n",withInput);
2152 // reset
2153 for(Int_t k = 0; k < 36; k++){
2154 for(Int_t j = 0; j < 16; j++){
2155 for(Int_t c = 0; c < 144; c++){
2156 phvalue[j][c][k] = 0.0;
2157 }
2158 }
2159 }
2160 }
2161
2162 }//array
2163 }//QA
2164 digitsManager->ClearArrays(det);
2165 }//idetector
2166 delete digitsManager;
2167
2168 delete rawStream;
2169 return withInput;
2170 }//main
2171//_____________________________________________________________________
bcb6fb78 2172//////////////////////////////////////////////////////////////////////////////
2173// Routine inside the DAQ process
2174/////////////////////////////////////////////////////////////////////////////
2175//_______________________________________________________________________
bcb6fb78 2176Int_t AliTRDCalibraFillHisto::FillDAQ(Double_t phvalue[16][144][36]){
2177
2178 //
2179 // Look for the maximum by collapsing over the time
2180 // Sum over four pad col and two pad row
2181 //
2182
2183 Int_t used = 0;
2184
2185
2186 Int_t idect = fDetectorPreviousTrack;
d95484e4 2187 //printf("Enter Detector %d\n",fDetectorPreviousTrack);
bcb6fb78 2188 Double_t sum[36];
2189 for(Int_t tb = 0; tb < 36; tb++){
2190 sum[tb] = 0.0;
2191 }
2192
d95484e4 2193 //fGoodTracklet = kTRUE;
2194 //fDetectorPreviousTrack = 0;
bcb6fb78 2195
2196
2197 ///////////////////////////
2198 // look for maximum
2199 /////////////////////////
2200
2201 Int_t imaxRow = 0;
2202 Int_t imaxCol = 0;
2203 Double_t integralMax = -1;
170c35f1 2204
bcb6fb78 2205 for (Int_t ir = 1; ir <= 15; ir++)
2206 {
2207 for (Int_t ic = 2; ic <= 142; ic++)
2208 {
2209 Double_t integral = 0;
6aafa7ea 2210 for (Int_t ishiftR = 0; ishiftR < fNumberRowDAQ; ishiftR++)
bcb6fb78 2211 {
6aafa7ea 2212 for (Int_t ishiftC = -fNumberColDAQ; ishiftC < fNumberColDAQ; ishiftC++)
bcb6fb78 2213 {
2214 if (ir + ishiftR >= 1 && ir + ishiftR <= 16 &&
2215 ic + ishiftC >= 1 && ic + ishiftC <= 144)
2216 {
2217
2218 for(Int_t tb = 0; tb< fTimeMax; tb++){
2219 integral += phvalue[ir + ishiftR-1][ic + ishiftC-1][tb];
2220 }// addtb
2221 } //addsignal
2222 } //shiftC
2223 } // shiftR
bcb6fb78 2224 if (integralMax < integral)
2225 {
2226 imaxRow = ir;
2227 imaxCol = ic;
2228 integralMax = integral;
1785640c 2229
bcb6fb78 2230 } // check max integral
2231 } //ic
2232 } // ir
2233
1785640c 2234 // printf("imaxRow %d, imaxCol %d, fTimeMax %d, integralMax %f\n",imaxRow,imaxCol,fTimeMax, integralMax);
6aafa7ea 2235 //if((imaxRow == 0) || (imaxRow >= 15) || (imaxCol <= 3) || (imaxCol >= 140)) {
2236 // used=1;
2237 // return used;
2238 // }
1785640c 2239
6aafa7ea 2240 if(((imaxRow + fNumberRowDAQ) > 16) || (imaxRow == 0) || ((imaxCol - fNumberColDAQ) <= 1) || ((imaxCol + fNumberColDAQ) >= 144)) {
27b46d95 2241 used=1;
2242 return used;
2243 }
d95484e4 2244 //CheckGoodTrackletV0(fDetectorPreviousTrack,imaxRow,imaxCol);
2245 //if(!fGoodTracklet) used = 1;;
bcb6fb78 2246
2247 // /////////////////////////////////////////////////////
2248 // sum ober 2 row and 4 pad cols for each time bins
2249 // ////////////////////////////////////////////////////
2250
2251
1785640c 2252
6aafa7ea 2253 for (Int_t ishiftR = 0; ishiftR < fNumberRowDAQ; ishiftR++)
bcb6fb78 2254 {
6aafa7ea 2255 for (Int_t ishiftC = -fNumberColDAQ; ishiftC < fNumberColDAQ; ishiftC++)
bcb6fb78 2256 {
6aafa7ea 2257 if (imaxRow + ishiftR >= 1 && imaxRow + ishiftR <= 16 &&
2258 imaxCol + ishiftC >= 1 && imaxCol + ishiftC <= 144)
2259 {
2260 for(Int_t it = 0; it < fTimeMax; it++){
2261 sum[it] += phvalue[imaxRow + ishiftR-1][imaxCol + ishiftC-1][it];
2262 }
2263 }
2264 } // col shift
2265 }// row shift
bcb6fb78 2266
2267 Int_t nbcl = 0;
2268 Double_t sumcharge = 0.0;
2269 for(Int_t it = 0; it < fTimeMax; it++){
2270 sumcharge += sum[it];
1785640c 2271 if(sum[it] > fThresholdClustersDAQ) nbcl++;
bcb6fb78 2272 }
2273
2274
2275 /////////////////////////////////////////////////////////
2276 // Debug
2277 ////////////////////////////////////////////////////////
5f689709 2278 if(fDebugLevel > 1){
bcb6fb78 2279 if ( !fDebugStreamer ) {
2280 //debug stream
2281 TDirectory *backup = gDirectory;
2282 fDebugStreamer = new TTreeSRedirector("TRDdebugCalibraFill.root");
2283 if ( backup ) backup->cd(); //we don't want to be cd'd to the debug streamer
2284 }
2285
2286 Double_t amph0 = sum[0];
2287 Double_t amphlast = sum[fTimeMax-1];
2288 Double_t rms = TMath::RMS(fTimeMax,sum);
2289 Int_t goodtracklet = (Int_t) fGoodTracklet;
2290 for(Int_t it = 0; it < fTimeMax; it++){
2291 Double_t clustera = sum[it];
2292
2293 (* fDebugStreamer) << "FillDAQa"<<
2294 "ampTotal="<<sumcharge<<
2295 "row="<<imaxRow<<
2296 "col="<<imaxCol<<
2297 "detector="<<idect<<
2298 "amph0="<<amph0<<
2299 "amphlast="<<amphlast<<
2300 "goodtracklet="<<goodtracklet<<
2301 "clustera="<<clustera<<
2302 "it="<<it<<
2303 "rms="<<rms<<
6aafa7ea 2304 "nbcl="<<nbcl<<
bcb6fb78 2305 "\n";
2306 }
2307 }
2308
2309 ////////////////////////////////////////////////////////
2310 // fill
2311 ///////////////////////////////////////////////////////
6aafa7ea 2312 //printf("fNumberClusters %d, fNumberClustersf %d\n",fNumberClusters,fNumberClustersf);
bcb6fb78 2313 if(sum[0] > 100.0) used = 1;
2314 if(nbcl < fNumberClusters) used = 1;
2315 if(nbcl > fNumberClustersf) used = 1;
2316
2317 //if(fDetectorPreviousTrack == 15){
2318 // printf("rms %f and first time bin %f\n",TMath::RMS(fTimeMax,sum),sum[0]);
2319 //}
2320 //if((TMath::RMS(fTimeMax,sum) <= 10.0) && (sum[0] > 200.0)) return 1;
2321 if(used == 0){
2322 for(Int_t it = 0; it < fTimeMax; it++){
37b0cf5e 2323 if(fFillWithZero) UpdateDAQ(fDetectorPreviousTrack,0,0,it,sum[it],fTimeMax);
2324 else{
1785640c 2325 if(sum[it] > 0.0) UpdateDAQ(fDetectorPreviousTrack,0,0,it,sum[it],fTimeMax);
37b0cf5e 2326 }
1785640c 2327 //if(fFillWithZero) UpdateDAQ(0,0,0,it,sum[it],fTimeMax);
6aafa7ea 2328 //else{
1785640c 2329 // if(sum[it] > 0.0) UpdateDAQ(0,0,0,it,sum[it],fTimeMax);
2330 //}
bcb6fb78 2331 }
2332
2333
2334 //((TH2I *)GetCH2d()->Fill(sumcharge/30.0,fDetectorPreviousTrack));
2335 used = 2;
d95484e4 2336 //printf("Pass Detector %d\n",fDetectorPreviousTrack);
2337
bcb6fb78 2338 }
2339
2340 return used;
2341
2342}
2343//____________Online trackling in AliTRDtrigger________________________________
2344Bool_t AliTRDCalibraFillHisto::UpdateDAQ(Int_t det, Int_t /*row*/, Int_t /*col*/, Int_t timebin, Float_t signal, Int_t nbtimebins)
2345{
2346 //
2347 // For the DAQ
2348 // Fill a simple average pulse height
2349 //
2350
170c35f1 2351
bcb6fb78 2352 ((TProfile2D *)GetPH2d(nbtimebins,fSf))->Fill((Float_t) timebin/fSf,det+0.5,(Float_t) signal);
2353
2354
170c35f1 2355 return kTRUE;
2356
2357}
170c35f1 2358//____________Write_____________________________________________________
2359//_____________________________________________________________________
2360void AliTRDCalibraFillHisto::Write2d(const Char_t *filename, Bool_t append)
2361{
3a0f6479 2362 //
2363 // Write infos to file
2364 //
2365
170c35f1 2366 //For debugging
2367 if ( fDebugStreamer ) {
2368 delete fDebugStreamer;
2369 fDebugStreamer = 0x0;
55a288e5 2370 }
170c35f1 2371
55a288e5 2372 AliInfo(Form("Numbertrack: %d Numberusedch[0]: %d, Numberusedch[1]: %d Numberusedph[0]: %d, Numberusedph[1]: %d"
170c35f1 2373 ,fNumberTrack
2374 ,fNumberUsedCh[0]
2375 ,fNumberUsedCh[1]
2376 ,fNumberUsedPh[0]
2377 ,fNumberUsedPh[1]));
2378
2379 TDirectory *backup = gDirectory;
2380 TString option;
2381
2382 if ( append )
2383 option = "update";
2384 else
2385 option = "recreate";
2386
2387 TFile f(filename,option.Data());
55a288e5 2388
2389 TStopwatch stopwatch;
2390 stopwatch.Start();
3a0f6479 2391 if(fVector2d) {
2392 f.WriteTObject(fCalibraVector);
2393 }
55a288e5 2394
170c35f1 2395 if (fCH2dOn ) {
55a288e5 2396 if (fHisto2d) {
170c35f1 2397 f.WriteTObject(fCH2d);
55a288e5 2398 }
55a288e5 2399 }
170c35f1 2400 if (fPH2dOn ) {
55a288e5 2401 if (fHisto2d) {
170c35f1 2402 f.WriteTObject(fPH2d);
55a288e5 2403 }
55a288e5 2404 }
170c35f1 2405 if (fPRF2dOn) {
55a288e5 2406 if (fHisto2d) {
170c35f1 2407 f.WriteTObject(fPRF2d);
55a288e5 2408 }
55a288e5 2409 }
3a0f6479 2410 if(fLinearFitterOn){
46c4871e 2411 if(fLinearFitterDebugOn) AnalyseLinearFitter();
3a0f6479 2412 f.WriteTObject(fLinearVdriftFit);
170c35f1 2413 }
3a0f6479 2414
170c35f1 2415 f.Close();
55a288e5 2416
170c35f1 2417 if ( backup ) backup->cd();
55a288e5 2418
170c35f1 2419 AliInfo(Form("Execution time Write2d: R:%.2fs C:%.2fs"
2420 ,stopwatch.RealTime(),stopwatch.CpuTime()));
55a288e5 2421}
bcb6fb78 2422//////////////////////////////////////////////////////////////////////////////////////////////////////////////
2423// Stats stuff
2424//////////////////////////////////////////////////////////////////////////////////////////////////////////////
170c35f1 2425//___________________________________________probe the histos__________________________________________________
55a288e5 2426Double_t *AliTRDCalibraFillHisto::StatH(TH2 *h, Int_t i)
2427{
2428 //
2429 // Check the number of stats in h, 0 is TH2I 1 is TProfile2D
2430 // debug mode with 2 for TH2I and 3 for TProfile2D
2431 // It gives a pointer to a Double_t[7] with the info following...
2432 // [0] : number of calibration groups with entries
2433 // [1] : minimal number of entries found
2434 // [2] : calibration group number of the min
2435 // [3] : maximal number of entries found
2436 // [4] : calibration group number of the max
2437 // [5] : mean number of entries found
3a0f6479 2438 // [6] : mean relative error
55a288e5 2439 //
2440
2441 Double_t *info = new Double_t[7];
2442
2443 // Number of Xbins (detectors or groups of pads)
170c35f1 2444 Int_t nbins = h->GetNbinsY(); //number of calibration groups
2445 Int_t nxbins = h->GetNbinsX(); //number of bins per histo
55a288e5 2446
2447 // Initialise
2448 Double_t nbwe = 0; //number of calibration groups with entries
2449 Double_t minentries = 0; //minimal number of entries found
2450 Double_t maxentries = 0; //maximal number of entries found
2451 Double_t placemin = 0; //calibration group number of the min
2452 Double_t placemax = -1; //calibration group number of the max
2453 Double_t meanstats = 0.0; //mean number of entries over the calibration group with at least ome entry
2454 Double_t meanrelativerror = 0.0; //mean relativ error in the TProfile2D
2455
2456 Double_t counter = 0;
2457
2458 //Debug
0c349049 2459 TH1F *nbEntries = 0x0;//distribution of the number of entries
2460 TH1F *nbEntriesPerGroup = 0x0;//Number of entries per group
2461 TProfile *nbEntriesPerSp = 0x0;//Number of entries for one supermodule
55a288e5 2462
2463 // Beginning of the loop over the calibration groups
2464 for (Int_t idect = 0; idect < nbins; idect++) {
2465
170c35f1 2466 TH1I *projch = (TH1I *) h->ProjectionX("projch",idect+1,idect+1,(Option_t *)"e");
55a288e5 2467 projch->SetDirectory(0);
2468
2469 // Number of entries for this calibration group
2470 Double_t nentries = 0.0;
2471 if((i%2) == 0){
170c35f1 2472 for (Int_t k = 0; k < nxbins; k++) {
2473 nentries += h->GetBinContent(h->GetBin(k+1,idect+1));
55a288e5 2474 }
2475 }
2476 else{
170c35f1 2477 for (Int_t k = 0; k < nxbins; k++) {
2478 nentries += ((TProfile2D *)h)->GetBinEntries(h->GetBin(k+1,idect+1));
2479 if(h->GetBinContent(h->GetBin(k+1,idect+1)) != 0) {
2480 meanrelativerror += (h->GetBinError(h->GetBin(k+1,idect+1))/(TMath::Abs(h->GetBinContent(h->GetBin(k+1,idect+1)))));
55a288e5 2481 counter++;
2482 }
2483 }
2484 }
2485
2486 //Debug
2487 if(i > 1){
35a82746 2488 if(nentries > 0){
2489 if(!((Bool_t)nbEntries)) nbEntries = new TH1F("Number of entries","Number of entries",100,(Int_t)nentries/2,nentries*2);
0c349049 2490 nbEntries->SetDirectory(0);
35a82746 2491 nbEntries->Fill(nentries);
2492 if(!((Bool_t)nbEntriesPerGroup)) nbEntriesPerGroup = new TH1F("Number of entries per group","Number of entries per group",nbins,0,nbins);
0c349049 2493 nbEntriesPerGroup->SetDirectory(0);
0c349049 2494 nbEntriesPerGroup->Fill(idect+0.5,nentries);
35a82746 2495 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));
2496 nbEntriesPerSp->SetDirectory(0);
0c349049 2497 nbEntriesPerSp->Fill((idect%((Int_t)(nbins/18)))+0.5,nentries);
55a288e5 2498 }
2499 }
2500
2501 //min amd max
2502 if(nentries > maxentries){
2503 maxentries = nentries;
2504 placemax = idect;
2505 }
2506 if(idect == 0) {
2507 minentries = nentries;
2508 }
2509 if(nentries < minentries){
2510 minentries = nentries;
2511 placemin = idect;
2512 }
2513 //nbwe
2514 if(nentries > 0) {
2515 nbwe++;
2516 meanstats += nentries;
2517 }
55a288e5 2518 }//calibration groups loop
2519
2520 if(nbwe > 0) meanstats /= nbwe;
2521 if(counter > 0) meanrelativerror /= counter;
2522
2523 AliInfo(Form("There are %f calibration groups with entries",nbwe));
2524 AliInfo(Form("The minimum number of entries is %f for the group %f",minentries,placemin));
2525 AliInfo(Form("The maximum number of entries is %f for the group %f",maxentries,placemax));
2526 AliInfo(Form("The mean number of entries is %f",meanstats));
2527 if((i%2) == 1) AliInfo(Form("The mean relative error is %f",meanrelativerror));
2528
2529 info[0] = nbwe;
2530 info[1] = minentries;
2531 info[2] = placemin;
2532 info[3] = maxentries;
2533 info[4] = placemax;
2534 info[5] = meanstats;
2535 info[6] = meanrelativerror;
2536
35a82746 2537 if(nbEntries && nbEntriesPerSp && nbEntriesPerGroup){
55a288e5 2538 gStyle->SetPalette(1);
2539 gStyle->SetOptStat(1111);
2540 gStyle->SetPadBorderMode(0);
2541 gStyle->SetCanvasColor(10);
2542 gStyle->SetPadLeftMargin(0.13);
2543 gStyle->SetPadRightMargin(0.01);
2544 TCanvas *stat = new TCanvas("stat","",50,50,600,800);
2545 stat->Divide(2,1);
2546 stat->cd(1);
0c349049 2547 nbEntries->Draw("");
55a288e5 2548 stat->cd(2);
0c349049 2549 nbEntriesPerSp->SetStats(0);
2550 nbEntriesPerSp->Draw("");
55a288e5 2551 TCanvas *stat1 = new TCanvas("stat1","",50,50,600,800);
2552 stat1->cd();
0c349049 2553 nbEntriesPerGroup->SetStats(0);
2554 nbEntriesPerGroup->Draw("");
55a288e5 2555 }
2556
2557 return info;
2558
2559}
170c35f1 2560//____________________________________________________________________________
2561Double_t *AliTRDCalibraFillHisto::GetMeanMedianRMSNumberCH()
2562{
2563 //
2564 // Return a Int_t[4] with:
2565 // 0 Mean number of entries
2566 // 1 median of number of entries
2567 // 2 rms of number of entries
2568 // 3 number of group with entries
2569 //
2570
35a82746 2571 Double_t *stat = new Double_t[4];
170c35f1 2572 stat[3] = 0.0;
2573
2574 Int_t nbofgroups = CalculateTotalNumberOfBins(0);
35a82746 2575
2576 Double_t *weight = new Double_t[nbofgroups];
2577 Double_t *nonul = new Double_t[nbofgroups];
170c35f1 2578
2579 for(Int_t k = 0; k < nbofgroups; k++){
2580 if(fEntriesCH[k] > 0) {
2581 weight[k] = 1.0;
2582 nonul[(Int_t)stat[3]] = fEntriesCH[k];
2583 stat[3]++;
2584 }
2585 else weight[k] = 0.0;
2586 }
2587 stat[0] = TMath::Mean(nbofgroups,fEntriesCH,weight);
2588 stat[1] = TMath::Median(nbofgroups,fEntriesCH,weight);
2589 stat[2] = TMath::RMS((Int_t)stat[3],nonul);
2590
35a82746 2591 delete [] weight;
2592 delete [] nonul;
2593
170c35f1 2594 return stat;
2595
2596}
2597//____________________________________________________________________________
2598Double_t *AliTRDCalibraFillHisto::GetMeanMedianRMSNumberLinearFitter() const
2599{
2600 //
2601 // Return a Int_t[4] with:
2602 // 0 Mean number of entries
2603 // 1 median of number of entries
2604 // 2 rms of number of entries
2605 // 3 number of group with entries
2606 //
55a288e5 2607
170c35f1 2608 Double_t *stat = new Double_t[4];
2609 stat[3] = 0.0;
2610
2611 Int_t nbofgroups = 540;
2612 Double_t *weight = new Double_t[nbofgroups];
2613 Int_t *nonul = new Int_t[nbofgroups];
2614
2615 for(Int_t k = 0; k < nbofgroups; k++){
2616 if(fEntriesLinearFitter[k] > 0) {
2617 weight[k] = 1.0;
2618 nonul[(Int_t) stat[3]] = fEntriesLinearFitter[k];
2619 stat[3]++;
2620 }
2621 else weight[k] = 0.0;
2622 }
2623 stat[0] = TMath::Mean(nbofgroups,fEntriesLinearFitter,weight);
2624 stat[1] = TMath::Median(nbofgroups,fEntriesLinearFitter,weight);
2625 stat[2] = TMath::RMS((Int_t)stat[3],nonul);
2626
35a82746 2627 delete [] weight;
2628 delete [] nonul;
2629
170c35f1 2630 return stat;
2631
2632}
bcb6fb78 2633//////////////////////////////////////////////////////////////////////////////////////
2634// Create Histos
2635//////////////////////////////////////////////////////////////////////////////////////
55a288e5 2636//_____________________________________________________________________________
2637void AliTRDCalibraFillHisto::CreatePRF2d(Int_t nn)
2638{
2639 //
170c35f1 2640 // Create the 2D histos: here we have 2*fNgroupprf bins in tnp of 0.2 amplitude each
2641 // If fNgroupprf is zero then no binning in tnp
55a288e5 2642 //
2643
2644 TString name("Nz");
2645 name += fCalibraMode->GetNz(2);
2646 name += "Nrphi";
2647 name += fCalibraMode->GetNrphi(2);
170c35f1 2648 name += "Ngp";
2649 name += fNgroupprf;
55a288e5 2650
170c35f1 2651 if(fNgroupprf != 0){
2652
2653 fPRF2d = new TProfile2D("PRF2d",(const Char_t *) name
2654 ,2*fNgroupprf*fNumberBinPRF,-3.0*fNgroupprf,3.0*fNgroupprf,nn,0,nn);
2655 fPRF2d->SetYTitle("Det/pad groups");
2656 fPRF2d->SetXTitle("Position x/W [pad width units]");
2657 fPRF2d->SetZTitle("Q_{i}/Q_{total}");
2658 fPRF2d->SetStats(0);
2659 }
2660 else{
2661 fPRF2d = new TProfile2D("PRF2d",(const Char_t *) name
2662 ,fNumberBinPRF,-1.5,1.5,nn,0,nn);
2663 fPRF2d->SetYTitle("Det/pad groups");
2664 fPRF2d->SetXTitle("Position x/W [pad width units]");
2665 fPRF2d->SetZTitle("Q_{i}/Q_{total}");
2666 fPRF2d->SetStats(0);
2667 }
55a288e5 2668
2669}
2670
2671//_____________________________________________________________________________
2672void AliTRDCalibraFillHisto::CreatePH2d(Int_t nn)
2673{
2674 //
2675 // Create the 2D histos
2676 //
2677
4c865c34 2678 TString name("Ver");
2679 name += fVersionVdriftUsed;
2680 name += "Subver";
2681 name += fSubVersionVdriftUsed;
ca7e6e64 2682 name += "FirstRun";
2683 name += fFirstRunVdrift;
4c865c34 2684 name += "Nz";
55a288e5 2685 name += fCalibraMode->GetNz(1);
2686 name += "Nrphi";
2687 name += fCalibraMode->GetNrphi(1);
170c35f1 2688
55a288e5 2689 fPH2d = new TProfile2D("PH2d",(const Char_t *) name
170c35f1 2690 ,fTimeMax,-0.5/fSf,(Float_t) (fTimeMax-0.5)/fSf
2691 ,nn,0,nn);
2692 fPH2d->SetYTitle("Det/pad groups");
2693 fPH2d->SetXTitle("time [#mus]");
55a288e5 2694 fPH2d->SetZTitle("<PH> [a.u.]");
2695 fPH2d->SetStats(0);
2696
2697}
55a288e5 2698//_____________________________________________________________________________
2699void AliTRDCalibraFillHisto::CreateCH2d(Int_t nn)
2700{
2701 //
2702 // Create the 2D histos
2703 //
2704
4c865c34 2705 TString name("Ver");
2706 name += fVersionGainUsed;
2707 name += "Subver";
2708 name += fSubVersionGainUsed;
f558cb62 2709 name += "FirstRun";
2710 name += fFirstRunGain;
4c865c34 2711 name += "Nz";
55a288e5 2712 name += fCalibraMode->GetNz(0);
2713 name += "Nrphi";
2714 name += fCalibraMode->GetNrphi(0);
4c865c34 2715
55a288e5 2716 fCH2d = new TH2I("CH2d",(const Char_t *) name
170c35f1 2717 ,fNumberBinCharge,0,300,nn,0,nn);
2718 fCH2d->SetYTitle("Det/pad groups");
2719 fCH2d->SetXTitle("charge deposit [a.u]");
55a288e5 2720 fCH2d->SetZTitle("counts");
2721 fCH2d->SetStats(0);
2722 fCH2d->Sumw2();
2723
2724}
bcb6fb78 2725//////////////////////////////////////////////////////////////////////////////////
2726// Set relative scale
2727/////////////////////////////////////////////////////////////////////////////////
2728//_____________________________________________________________________________
2729void AliTRDCalibraFillHisto::SetRelativeScale(Float_t RelativeScale)
55a288e5 2730{
2731 //
bcb6fb78 2732 // Set the factor that will divide the deposited charge
2733 // to fit in the histo range [0,300]
55a288e5 2734 //
170c35f1 2735
bcb6fb78 2736 if (RelativeScale > 0.0) {
2737 fRelativeScale = RelativeScale;
170c35f1 2738 }
bcb6fb78 2739 else {
2740 AliInfo("RelativeScale must be strict positif!");
170c35f1 2741 }
170c35f1 2742
170c35f1 2743}
bcb6fb78 2744//////////////////////////////////////////////////////////////////////////////////
2745// Quick way to fill a histo
2746//////////////////////////////////////////////////////////////////////////////////
2747//_____________________________________________________________________
2748void AliTRDCalibraFillHisto::FillCH2d(Int_t x, Float_t y)
d0569428 2749{
2750 //
bcb6fb78 2751 // FillCH2d: Marian style
2752 //
d0569428 2753
bcb6fb78 2754 //skip simply the value out of range
2755 if((y>=300.0) || (y<0.0)) return;
d0569428 2756
bcb6fb78 2757 //Calcul the y place
2758 Int_t yplace = (Int_t) (fNumberBinCharge*y/300.0)+1;
2759 Int_t place = (fNumberBinCharge+2)*(x+1)+yplace;
d0569428 2760
bcb6fb78 2761 //Fill
2762 fCH2d->GetArray()[place]++;
d0569428 2763
2764}
d0569428 2765
bcb6fb78 2766//////////////////////////////////////////////////////////////////////////////////
2767// Geometrical functions
2768///////////////////////////////////////////////////////////////////////////////////
55a288e5 2769//_____________________________________________________________________________
053767a4 2770Int_t AliTRDCalibraFillHisto::GetLayer(Int_t d) const
55a288e5 2771{
2772 //
053767a4 2773 // Reconstruct the layer number from the detector number
55a288e5 2774 //
2775
2776 return ((Int_t) (d % 6));
2777
2778}
2779
2780//_____________________________________________________________________________
053767a4 2781Int_t AliTRDCalibraFillHisto::GetStack(Int_t d) const
55a288e5 2782{
2783 //
053767a4 2784 // Reconstruct the stack number from the detector number
55a288e5 2785 //
053767a4 2786 const Int_t kNlayer = 6;
55a288e5 2787
053767a4 2788 return ((Int_t) (d % 30) / kNlayer);
55a288e5 2789
2790}
2791
2792//_____________________________________________________________________________
2793Int_t AliTRDCalibraFillHisto::GetSector(Int_t d) const
2794{
2795 //
2796 // Reconstruct the sector number from the detector number
2797 //
2798 Int_t fg = 30;
2799
2800 return ((Int_t) (d / fg));
2801
2802}
bcb6fb78 2803///////////////////////////////////////////////////////////////////////////////////
2804// Getter functions for DAQ of the CH2d and the PH2d
2805//////////////////////////////////////////////////////////////////////////////////
170c35f1 2806//_____________________________________________________________________
3a0f6479 2807TProfile2D* AliTRDCalibraFillHisto::GetPH2d(Int_t nbtimebin, Float_t samplefrequency)
170c35f1 2808{
2809 //
2810 // return pointer to fPH2d TProfile2D
3a0f6479 2811 // create a new TProfile2D if it doesn't exist allready
170c35f1 2812 //
3a0f6479 2813 if ( fPH2d )
170c35f1 2814 return fPH2d;
2815
2816 // Some parameters
2817 fTimeMax = nbtimebin;
2818 fSf = samplefrequency;
2819
170c35f1 2820 CreatePH2d(540);
2821
2822 return fPH2d;
2823}
2824//_____________________________________________________________________
bcb6fb78 2825TH2I* AliTRDCalibraFillHisto::GetCH2d()
2826{
2827 //
2828 // return pointer to fCH2d TH2I
2829 // create a new TH2I if it doesn't exist allready
2830 //
2831 if ( fCH2d )
2832 return fCH2d;
2833
2834 CreateCH2d(540);
2835
2836 return fCH2d;
2837}
2838////////////////////////////////////////////////////////////////////////////////////////////
2839// Drift velocity calibration
2840///////////////////////////////////////////////////////////////////////////////////////////
2841//_____________________________________________________________________
170c35f1 2842TLinearFitter* AliTRDCalibraFillHisto::GetLinearFitter(Int_t detector, Bool_t force)
2843{
2844 //
2845 // return pointer to TLinearFitter Calibration
2846 // if force is true create a new TLinearFitter if it doesn't exist allready
2847 //
170c35f1 2848
d0569428 2849 if ((!force) || (fLinearFitterArray.UncheckedAt(detector))){
2850 return (TLinearFitter*)fLinearFitterArray.UncheckedAt(detector);
2851 }
170c35f1 2852
d0569428 2853 // if we are forced and TLinearFitter doesn't yet exist create it
2854
2855 // new TLinearFitter
2856 TLinearFitter *linearfitter = new TLinearFitter(2,"pol1");
2857 fLinearFitterArray.AddAt(linearfitter,detector);
2858 return linearfitter;
170c35f1 2859}
170c35f1 2860
3a0f6479 2861//____________________________________________________________________________
2862void AliTRDCalibraFillHisto::AnalyseLinearFitter()
2863{
2864 //
2865 // Analyse array of linear fitter because can not be written
2866 // Store two arrays: one with the param the other one with the error param + number of entries
2867 //
2868
2869 for(Int_t k = 0; k < 540; k++){
2870 TLinearFitter *linearfitter = GetLinearFitter(k);
2871 if((linearfitter!=0) && (fEntriesLinearFitter[k]>10)){
2872 TVectorD *par = new TVectorD(2);
2873 TVectorD pare = TVectorD(2);
2874 TVectorD *parE = new TVectorD(3);
c1105918 2875 if((linearfitter->EvalRobust(0.8)==0)) {
2876 //linearfitter->Eval();
2877 linearfitter->GetParameters(*par);
2878 //linearfitter->GetErrors(pare);
2879 //Float_t ppointError = TMath::Sqrt(TMath::Abs(linearfitter->GetChisquare())/fEntriesLinearFitter[k]);
2880 //(*parE)[0] = pare[0]*ppointError;
2881 //(*parE)[1] = pare[1]*ppointError;
2882
2883 (*parE)[0] = 0.0;
2884 (*parE)[1] = 0.0;
2885 (*parE)[2] = (Double_t) fEntriesLinearFitter[k];
2886 ((TObjArray *)fLinearVdriftFit->GetPArray())->AddAt(par,k);
2887 ((TObjArray *)fLinearVdriftFit->GetEArray())->AddAt(parE,k);
2888 }
3a0f6479 2889 }
2890 }
1f3c89d8 2891}
1785640c 2892
a2a4ec8e 2893
35a82746 2894