]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TRD/AliTRDCalibra.cxx
Add Raphaelles calibration class
[u/mrichter/AliRoot.git] / TRD / AliTRDCalibra.cxx
CommitLineData
77566f2a 1
2/////////////////////////////////////////////////////////////////////////////////
3//
4// AliTRDCalibra
5//
6// This class is for the TRD calibration of the relative gain factor, the drift velocity,
7// the time 0 and the pad response function.
8// It can be used for the calibration per chamber but also per group of pads and eventually per pad.
9// The user has to choose with the functions SetNz and SetNrphi the precision of the calibration.
10//Begin_Html
11//<br>
12//<CENTER>
13//<TABLE border=1>
14//<TR><TD><center>Nz</center></TD><TD><center> 0 </center></TD><TD><center> 1 </center></TD><TD><center> 2 </center></TD><TD><center> 3 </center></TD><TD><center> 4 </center></TD></TR>
15//<TR><TD><CENTER>group of row pads per detector</CENTER></TD><TD><CENTER>1</CENTER></TD><TD><CENTER>2</CENTER></TD><TD><CENTER>4</CENTER></TD><TD><CENTER>6(chamb2)<br> 8(others chambers)</CENTER></TD><TD><CENTER>12 (chamb2)<br> 16 (chamb0)</CENTER></TD></TR>
16//<TR><TD><CENTER>row pads per group</CENTER></TD><TD><CENTER>12 (chamb2)<br> 16 (chamb0)</CENTER></TD><TD><CENTER>6 (chamb2)<br> 8 (chamb0)</CENTER></TD><TD><CENTER>3 (chamb2)<br> 4 (chamb0)</CENTER></TD><TD><CENTER>2</CENTER></TD><TD><CENTER>1</CENTER></TD></TR>
17//<TR><TD><CENTER>~distance [cm]</CENTER></TD><TD><CENTER>106 (chamb2)<br> 130 (chamb0)</CENTER></TD><TD><CENTER>53 (chamb2)<br> 65 (chamb0)</CENTER></TD><TD><CENTER>26.5 (chamb2)<br> 32.5 (chamb0)</CENTER></TD><TD><CENTER>17 (chamb2)<br> 17 (chamb0)</CENTER></TD><TD><CENTER>9 (chamb2)<br> 9 (chamb0)</CENTER></TD></TR>
18//<CAPTION>In the z direction</CAPTION>
19//</TABLE>
20//</CENTER>
21//<CENTER>
22//<br>
23//<TABLE border=1>
24//<TR><TD><center>Nrphi</center></TD><TD><center> 0 </center></TD><TD><center> 1 </center></TD><TD><center> 2 </center></TD><TD><center> 3 </center></TD><TD><center> 4 </center></TD><TD><center> 5 </center></TD><TD><center> 6 </center></TD></TR>
25//<TR><TD><CENTER>group of col pads per detector</CENTER></TD><TD><CENTER>1</CENTER></TD><TD><CENTER>2</CENTER></TD><TD><CENTER>4</CENTER></TD><TD><CENTER>8</CENTER></TD><TD><CENTER>16</CENTER></TD><TD><center>36</center></TD><TD><center>144</center></TD></TR>
26//<TR><TD><CENTER>col pads per group</CENTER></TD><TD><CENTER>144</CENTER></TD><TD><CENTER>72</CENTER></TD><TD><CENTER>36</CENTER></TD><TD><CENTER>18</CENTER></TD><TD><CENTER>9</CENTER></TD><TD><center>4</center></TD><TD><center>1</center></TD></TR>
27//<TR><TD><CENTER>~distance [cm]</CENTER></TD><TD><CENTER>113.4</CENTER></TD><TD><CENTER>56.7</CENTER></TD><TD><CENTER>25.3</CENTER></TD><TD><CENTER>14.3</CENTER></TD><TD><CENTER>7.25</CENTER></TD><TD><center>3.2</center></TD><TD><center>0.8</center></TD></TR>
28//<CAPTION>In the rphi direction</CAPTION>
29//</TABLE>
30//</CENTER>
31//<br>
32//End_Html
33//
34// Fill histograms or vectors
35//----------------------------
36//
37// 2D Histograms (Histo2d) or vectors (Vector2d), then converted in Trees, will be filled
38// from RAW DATA in a run or from reconstructed TRD tracks during the offline tracking
39// in the function "FollowBackProlongation" (AliTRDtracker)
40// Per default the functions to fill are off.
41//
42//Begin_Html
43//Example of 2D histos for the relative gain (left) and the drift velocity (right) calibration of the sector 13 <br>
44//<center>
45//<img src="./gif/2dhisto.gif" width="600" height="350"><br>
46//</center>
47//End_Html
48//
49// Fit the histograms to find the coefficients
50//---------------------------------------------
51//
52// These 2D histograms or vectors (first converted in 1D histos) will be fitted
53// if they have enough entries, otherwise the (default) value of the choosen database
54// will be put. For the relative gain calibration the resulted factors will be globally
55// normalized to the gain factors of the choosen database. It unables to precise
56// previous calibration procedure.
57// The function SetDebug enables the user to see:
58// _fDebug = 0: nothing, only the values are written in the tree if wanted
59// _fDebug = 1: a comparaison of the coefficients found and the default values
60// in the choosen database.
61// fCoef , histogram of the coefs as function of the calibration group number
62// fDelta , histogram of the relative difference of the coef with the default
63// value in the database as function of the calibration group number
64// fError , dirstribution of this relative difference
65// _fDebug = 2: only the fit of the choosen calibration group fFitVoir (SetFitVoir)
66// _fDebug = 3: The coefficients in the choosen detector fDet (SetDet) as function of the
67// pad row and col number
68// _fDebug = 4; The coeffcicients in the choosen detector fDet (SetDet) like in the 3 but with
69// also the comparaison histograms of the 1 for this detector
70//
71//Begin_Html
72//Example of fCoef for the relative gain calibration of the sector 13 <br>
73//<center>
74//<img src="./gif/coef.gif" width="400" height="460">
75//</center><br>
76//Example of fDelta (right) and fError (left) for the relative gain calibration of the sector 13 <br>
77//<center>
78//<img src="./gif/detlaerror.gif" width="550" height="380"><br>
79//</center>
80//End_Html
81//
82// Author:
83// R. Bailhache (R.Bailhache@gsi.de)
84//
85//////////////////////////////////////////////////////////////////////////////////////
86
87
88#include "AliTRDCalibra.h"
89
90using namespace std;
91
92
93ClassImp(AliTRDCalibra)
94
95AliTRDCalibra* AliTRDCalibra::fgInstance = 0;
96Bool_t AliTRDCalibra::fgTerminated = kFALSE;
97
98//_____________singleton implementation_________________________________________________
99AliTRDCalibra* AliTRDCalibra::Instance()
100{
101 //
102 // Singleton implementation
103 //
104
105 if(fgTerminated != kFALSE)
106 return 0;
107
108 if (fgInstance == 0)
109 fgInstance = new AliTRDCalibra();
110
111 return fgInstance;
112
113}
114
115//______________________________________________________________________________________
116void AliTRDCalibra::Terminate()
117{
118 //
119 // Singleton implementation
120 // Deletes the instance of this class
121 //
122
123 fgTerminated = kTRUE;
124
125 if (fgInstance != 0) {
126 delete fgInstance;
127 fgInstance = 0;
128 }
129
130}
131
132//______________________________________________________________________________________
133AliTRDCalibra::AliTRDCalibra()
134 :TObject()
135 ,fMItracking(kFALSE)
136 ,fmcmtracking(kFALSE)
137 ,fmcmcorrectangle(kFALSE)
138 ,fCH2dOn(kFALSE)
139 ,fPH2dOn(kFALSE)
140 ,fPRF2dOn(kFALSE)
141 ,fHisto2d(kFALSE)
142 ,fVector2d(kFALSE)
143 ,fRelativeScale(0)
144 ,fCountRelativeScale(0)
145 ,fRelativeScaleAuto(kFALSE)
146 ,fThresholddigit(0)
147 ,fThresholdClusterPRF1(0.0)
148 ,fThresholdClusterPRF2(0.0)
149 ,fCenterOfflineCluster(kFALSE)
150 ,fTraMaxPad(kFALSE)
151 ,fWriteNameCoef(0)
152 ,fWriteName(0)
153 ,fFitPHOn(kFALSE)
154 ,fFitPHPeriode(0)
155 ,fBeginFitCharge(0.0)
156 ,fRangeFitPRF(0.0)
157 ,fMeanChargeOn(kFALSE)
158 ,fFitChargeBisOn(kFALSE)
159 ,fT0Shift(0.0)
160 ,fDebug(0)
161 ,fFitVoir(0)
162 ,fPRF(0)
163 ,fGain(0)
164 ,fT0(0)
165 ,fVdrift(0)
166 ,fVdriftDetector(0)
167 ,fVdriftPad(0x0)
168 ,fT0Detector(0)
169 ,fT0Pad(0x0)
170 ,fPRFDetector(0)
171 ,fPRFPad(0x0)
172 ,fcoefCH(0x0)
173 ,fDetectorAliTRDtrack(kFALSE)
174 ,fChamberAliTRDtrack(-1)
175 ,fDetectorprevioustrack(-1)
176 ,fGoodTrack(kTRUE)
177 ,famptotal(0x0)
178 ,fPHplace(0x0)
179 ,fPHvalue(0x0)
180 ,fNumberClusters(0)
181 ,fprocent(0.0)
182 ,fdifference(0)
183 ,fNumbertrack(0)
184 ,fDeltaPRF(0)
185 ,fErrorPRF(0)
186 ,fCoefPRFDB(0)
187 ,fTimeMax(0)
188 ,fSf(0.0)
189 ,fScalefitfactor(0.0)
190 ,fMinEntries(0)
191 ,fEntriesCurrent(0)
192 ,fl3P0(0.0)
193 ,fl3P2(0.0)
194 ,fg3P2(0.0)
195 ,fVectorPH(0)
196 ,fPlaPH(0)
197 ,fNumberBinCharge(0)
198 ,fVectorCH(0)
199 ,fPlaCH(0)
200 ,fVectorFitCH(0)
201 ,fNumberBinPRF(0)
202 ,fVectorPRF(0)
203 ,fPlaPRF(0)
204 ,fPH2d(0x0)
205 ,fPRF2d(0x0)
206 ,fCH2d(0x0)
207 ,fRebin(0)
208{
209 //
210 // Default constructor
211 //
212
213 for (Int_t i = 0; i < 3; i++) {
214 fNz[i] = 0;
215 fNrphi[i] = 0;
216 }
217
218 for (Int_t k = 0; k < 3; k++) {
219 fNtotal[k] = 0;
220 fdetChamb2[k] = 0;
221 fdetChamb0[k] = 0;
222 }
223
224 // Write
225 for (Int_t i = 0; i < 3; i++) {
226 fWriteCoef[i] = kFALSE;
227 fWrite[i] = kFALSE;
228 }
229
230 // Debug Mode
231 for (Int_t k = 0; k < 3; k++) {
232 fDet[k] = 0;
233 }
234
235 for (Int_t i = 0; i < 2; i++) {
236 fPhd[i] = 0.0;
237 }
238 fPhd[3] = 0.0;
239
240 // Init
241 Init();
242
243}
244
245//______________________________________________________________________________________
246AliTRDCalibra::AliTRDCalibra(const AliTRDCalibra &c)
247 :TObject(c)
248 ,fMItracking(kFALSE)
249 ,fmcmtracking(kFALSE)
250 ,fmcmcorrectangle(kFALSE)
251 ,fCH2dOn(kFALSE)
252 ,fPH2dOn(kFALSE)
253 ,fPRF2dOn(kFALSE)
254 ,fHisto2d(kFALSE)
255 ,fVector2d(kFALSE)
256 ,fRelativeScale(0)
257 ,fCountRelativeScale(0)
258 ,fRelativeScaleAuto(kFALSE)
259 ,fThresholddigit(0)
260 ,fThresholdClusterPRF1(0.0)
261 ,fThresholdClusterPRF2(0.0)
262 ,fCenterOfflineCluster(kFALSE)
263 ,fTraMaxPad(kFALSE)
264 ,fWriteNameCoef(0)
265 ,fWriteName(0)
266 ,fFitPHOn(kFALSE)
267 ,fFitPHPeriode(0)
268 ,fBeginFitCharge(0.0)
269 ,fRangeFitPRF(0.0)
270 ,fMeanChargeOn(kFALSE)
271 ,fFitChargeBisOn(kFALSE)
272 ,fT0Shift(0.0)
273 ,fDebug(0)
274 ,fFitVoir(0)
275 ,fPRF(0)
276 ,fGain(0)
277 ,fT0(0)
278 ,fVdrift(0)
279 ,fVdriftDetector(0)
280 ,fVdriftPad(0x0)
281 ,fT0Detector(0)
282 ,fT0Pad(0x0)
283 ,fPRFDetector(0)
284 ,fPRFPad(0x0)
285 ,fcoefCH(0x0)
286 ,fDetectorAliTRDtrack(kFALSE)
287 ,fChamberAliTRDtrack(-1)
288 ,fDetectorprevioustrack(-1)
289 ,fGoodTrack(kTRUE)
290 ,famptotal(0x0)
291 ,fPHplace(0x0)
292 ,fPHvalue(0x0)
293 ,fNumberClusters(0)
294 ,fprocent(0.0)
295 ,fdifference(0)
296 ,fNumbertrack(0)
297 ,fDeltaPRF(0)
298 ,fErrorPRF(0)
299 ,fCoefPRFDB(0)
300 ,fTimeMax(0)
301 ,fSf(0.0)
302 ,fScalefitfactor(0.0)
303 ,fMinEntries(0)
304 ,fEntriesCurrent(0)
305 ,fl3P0(0.0)
306 ,fl3P2(0.0)
307 ,fg3P2(0.0)
308 ,fVectorPH(0)
309 ,fPlaPH(0)
310 ,fNumberBinCharge(0)
311 ,fVectorCH(0)
312 ,fPlaCH(0)
313 ,fVectorFitCH(0)
314 ,fNumberBinPRF(0)
315 ,fVectorPRF(0)
316 ,fPlaPRF(0)
317 ,fPH2d(0x0)
318 ,fPRF2d(0x0)
319 ,fCH2d(0x0)
320 ,fRebin(0)
321{
322 //
323 // Copy constructor
324 //
325
326}
327
328//____________________________________________________________________________________
329AliTRDCalibra::~AliTRDCalibra()
330{
331 //
332 // AliTRDCalibra destructor
333 //
334
335 ClearHistos();
336 ClearTree();
337 ClearFile();
338
339}
340
341//_____________________________________________________________________________
342void AliTRDCalibra::Destroy()
343{
344 //
345 // delete instance
346 //
347
348 if (fgInstance) {
349 //fgInstance->Delete();
350 delete fgInstance;
351 fgInstance = 0x0;
352 }
353}
354
355//_____________________________________________________________________________
356void AliTRDCalibra::ClearHistos()
357{
358 //
359 // delete the histos
360 //
361
362 if (fPH2dOn && fPH2d) {
363 delete fPH2d;
364 fPH2d = 0x0;
365 }
366 if (fCH2dOn && fCH2d) {
367 delete fCH2d;
368 fCH2d = 0x0;
369 }
370 if (fPRF2dOn && fPRF2d) {
371 delete fPRF2d;
372 fPRF2d = 0x0;
373 }
374
375}
376
377//_____________________________________________________________________________
378void AliTRDCalibra::ClearTree()
379{
380 //
381 // delete the trees
382 //
383
384 if (fPRF2dOn && fPRF && fWriteCoef[3]) {
385 delete fPRF;
386 fPRF = 0x0;
387 }
388 if (fCH2dOn && fGain && fWriteCoef[0]) {
389 delete fGain;
390 fGain = 0x0;
391 }
392 if (fPH2dOn && fT0 && fWriteCoef[2]) {
393 delete fT0;
394 fT0 = 0x0;
395 }
396 if (fPH2dOn && fVdrift && fWriteCoef[1]) {
397 delete fVdrift;
398 fVdrift = 0x0;
399 }
400
401}
402
403//_____________________________________________________________________________
404void AliTRDCalibra::Init()
405{
406 //
407 // Init some default values
408 //
409
410 //How to fill the 2D
411 fThresholddigit = 5;
412 fThresholdClusterPRF1 = 2.0;
413 fThresholdClusterPRF2 = 20.0;
414
415
416 //Store the Info
417 fNumberBinCharge = 100;
418 fNumberBinPRF = 20;
419
420 //write
421 fWriteName = "TRD.calibration.root";
422 fWriteNameCoef = "TRD.coefficient.root";
423
424 //Fit
425 fFitPHPeriode = 1;
426 fBeginFitCharge = 3.5;
427 fRangeFitPRF = 0.5;
428 fMinEntries = 800;
429 fT0Shift = 0.143397;
430
431
432 //Internal variables************************
433
434
435 //Fill the 2D histos in the offline tracking
436 fDetectorprevioustrack = -1;
437 fChamberAliTRDtrack = -1;
438 fGoodTrack = kTRUE;
439
440 fprocent = 6.0;
441 fdifference = 17;
442 fNumberClusters = 18;
443 fNumbertrack = 0;
444 fNumberusedch[0] = 0;
445 fNumberusedch[1] = 0;
446 fNumberusedph[0] = 0;
447 fNumberusedph[1] = 0;
448
449 //For debugging in ClearHistos()
450
451 //variables in the loop
452 for(Int_t k = 0; k < 4; k++){
453 fChargeCoef[k] = 1.0;
454 fVdriftCoef[k] = 1.5;
455 fT0Coef[k] = -1.0;
456 }
457 for(Int_t i = 0; i < 2; i++){
458 fPRFCoef[i] = -1.0;
459 }
460
461
462 //pad calibration
463 for(Int_t i = 0; i < 3; i++){
464 frowmin[i] = -1;
465 frowmax[i] = -1;
466 fcolmax[i] = -1;
467 fcolmin[i] = -1;
468 fNnz[i] = -1;
469 fNnrphi[i] = -1;
470 fNfragz[i] = -1;
471 fNfragrphi[i] = -1;
472 fXbins[i] = -1;
473 }
474
475
476 //local database to be changed
477 fRebin = 1;
478
479}
480
481//_______________________Functions fit Online___________________________________________
482
483//____________Functions fit Online CH2d___________________________________________________________
484
485Bool_t AliTRDCalibra::FitCHOnline( TH2I * ch)
486{
487 //
488 // Fit the 1D histos, projections of the 2D ch on the Xaxis, for each calibration group
489 // normalized the resulted coefficients (to 1 normally) and write the results in a tree
490 //
491
492
493 //Number of Xbins(detectors or groups of pads)*******************************
494 TAxis *xch = ch->GetXaxis();
495 Int_t Nbins = xch->GetNbins();
496 TAxis *yph = ch->GetYaxis();
497 Int_t NYbins = yph->GetNbins();
498 Double_t lowedge = xch->GetBinLowEdge(1);
499 Double_t upedge = xch->GetBinUpEdge(xch->GetNbins());
500 if(!InitFit(Nbins,lowedge,upedge,0)) return kFALSE;
501 Double_t statisticmean = 0.0;
502 Int_t numberfit = 0;
503
504
505
506 //DB Setting************************************************************************
507 //DB and so one****************************************
508
509 //DB setting
510 AliCDBManager *man = AliCDBManager::Instance();
511 if (!man) {
512 AliInfo("Could not get CDB Manager");
513 return kFALSE;
514 }
515
516 // Get the parameter object
517 AliTRDcalibDB *cal = AliTRDcalibDB::Instance();
518 if (!cal) {
519 AliInfo("Could not get calibDB");
520 return kFALSE;
521 }
522
523 // Get the parameter object
524 AliTRDCommonParam *parCom = AliTRDCommonParam::Instance();
525 if (!parCom) {
526 AliInfo(Form("Could not get CommonParam Manager"));
527 return kFALSE;
528 }
529
530 //Init fcountdet and fcount***************************************
531 Initfcountdetandfcount(0);
532
533 //Beginning of the loop betwwen dect1 and dect2**************************************************************
534 for (Int_t idect = fdect1[0]; idect < fdect2[0]; idect++) {
535
536
537 TH1I* projch = (TH1I*)ch->ProjectionY("projch",idect+1,idect+1,(Option_t *)"e");
538 projch->SetDirectory(0);
539
540
541 //Determination of fNnz, fNnrphi, fNfragz and fNfragrphi***********
542 Updatefcountdetandfcount(idect,0);
543
544 //Reconstruction of the row and pad group: rowmin, row max..**********************
545 Reconstructfitrowminrowmax(idect, 0);
546
547
548 //Number of entries for this calibration group
549 Double_t nentries = 0.0;
550 for(Int_t k = 0; k < NYbins; k++){
551 nentries += ch->GetBinContent(ch->GetBin(idect+1,k+1));
552 }
553
554 //Rebin and statistic stuff**********************************
555 //Rebin
556 if(fRebin > 1) projch = ReBin((TH1I *)projch);
557 //This detector has not enough statistics or was off
558 if(nentries < fMinEntries) {
559
560 //Fill with the default infos***********************************
561 NotEnoughStatistic(idect,0);
562 //Memory!!!**************************************************
563 if(fDebug != 2){
564 delete projch;
565 }
566 continue;
567 }
568
569 //Statistic of the group fitted************************************
570 AliInfo(Form("For the group number %d there are %f stats", idect, nentries));
571 statisticmean += nentries;
572 numberfit ++;
573
574 //Method Mean and fit*****************************************
575 //idect is egal for fDebug = 0 and 2, only to fill the hist
576 FitCH((TH1 *) projch, (Int_t) (idect-fdect1[0]));
577 //Method fit bis*********************************************
578 //idect is egal for fDebug = 0 and 2, only to fill the hist
579 if(fFitChargeBisOn) {
580 FitBisCH((TH1 *) projch, (Int_t) (idect-fdect1[0]));
581 }
582
583 //Visualise the detector for fDebug 3 or 4*******************************
584 //here is the reconstruction of the pad and row group is used!
585 if(fDebug >= 3) FillCoefChargeDB();
586 //Fill Infos Fit********************************************
587 FillInfosFit(idect,0);
588
589 //Memory!!!**************************************************
590 if(fDebug != 2){
591 delete projch;
592 }
593
594
595 }//boucle object
596
597
598 //Normierungcharge************************************************
599 if(fDebug != 2) NormierungCharge();
600
601 //Error*******************************************************
602 if((fDebug == 1) || (fDebug == 4)) ErrorCH();
603
604
605 //Plot***********************************************************
606 //0 no plot, 1 and 4 error plot, 3 and 4 DB plot
607 if((fDebug == 1) || (fDebug == 4)){
608 PlotCH();
609 }
610 if((fDebug == 4) || (fDebug == 3)){
611 PlotCHDB();
612 }
613
614 //Mean Statistic********************************************************
615 if(numberfit > 0) {
616 AliInfo(Form("There is a mean statistic of: %d", (Int_t)statisticmean/numberfit));
617 }
618 else {
619 AliInfo("There is no fit!");
620 }
621
622 //Write the things!**************************************************
623 ConvertVectorFitCHTree();
624 if(fWriteCoef[0]){
625 WriteFitInfos(0);
626 }
627 return kTRUE;
628
629}
630//____________Functions fit Online CH2d___________________________________________________________
631
632Bool_t AliTRDCalibra::FitCHOnline()
633{
634 //
635 // Reconstruct a 1D histo from the vectorCH for each calibration group, fit the histo,
636 // normalized the resulted coefficients (to 1 normally) and write the results in a tree
637 //
638
639
640
641 //Number of Xbins(detectors or groups of pads)*******************************
642 if(!InitFit(0,0,0,0)) return kFALSE;
643 Double_t statisticmean = 0.0;
644 Int_t numberfit = 0;
645
646 //DB Setting************************************************************************
647 //DB and so one****************************************
648
649 //DB setting
650 AliCDBManager *man = AliCDBManager::Instance();
651 if (!man) {
652 AliInfo("Could not get CDB Manager");
653 return kFALSE;
654 }
655
656
657 // Get the parameter object
658 AliTRDcalibDB *cal = AliTRDcalibDB::Instance();
659 if (!cal) {
660 AliInfo("Could not get calibDB");
661 return kFALSE;
662 }
663
664 // Get the parameter object
665 AliTRDCommonParam *parCom = AliTRDCommonParam::Instance();
666 if (!parCom) {
667 AliInfo("Could not get CommonParam Manager");
668 return kFALSE;
669 }
670
671 //Init fcountdet and fcount*************************************************
672 Initfcountdetandfcount(0);
673
674 //Beginning of the loop betwwen dect1 and dect2**************************************************************
675 for (Int_t idect = fdect1[0]; idect < fdect2[0]; idect++) {
676
677 //Search if the group is in the VectorCH
678 Int_t place = SearchInVector(idect,0);
679
680 //Is in
681 TH1F* projch = 0x0;
682 TString name("CH");
683 name += idect;
684 if(place != -1){
685 //Variable
686 TCTInfo *fCHInfo = new TCTInfo();
687 fCHInfo->fentries = new UShort_t[fNumberBinCharge];
688 //retrieve
689 fCHInfo = fVectorCH[place];
690 projch = ConvertVectorCTHisto(fCHInfo,(const char *)name);
691 projch->SetDirectory(0);
692 delete fCHInfo;
693 }
694
695 //Determination of fNnz, fNnrphi, fNfragz and fNfragrphi***********
696 Updatefcountdetandfcount(idect,0);
697
698 //Reconstruction of the row and pad group: rowmin, row max..**********************
699 Reconstructfitrowminrowmax(idect, 0);
700
701 //Number of entries
702 Double_t nentries = 0.0;
703 for(Int_t k = 0; k < fNumberBinCharge; k++){
704 nentries += projch->GetBinContent(k+1);
705 }
706
707
708 //Rebin and statistic stuff**********************************
709 //Rebin
710 if((fRebin > 1) && (place != -1)) projch = ReBin((TH1F *) projch);
711 //This detector has not enough statistics or was not found in VectorCH
712 if((place == -1) || ((place != -1) && (nentries < fMinEntries))) {
713
714 //Fill with the default infos**************************************
715 NotEnoughStatistic(idect,0);
716
717 //Memory!!!**************************************************
718 if(fDebug != 2){
719 delete projch;
720 }
721
722 continue;
723 }
724
725 //Statistic of the histos fitted*********************************************
726 AliInfo(Form("For the group number %d there are %f stats", idect, nentries));
727 numberfit ++;
728 statisticmean += nentries;
729
730
731 //Method Mean and fit*****************************************
732 //idect is egal for fDebug = 0 and 2, only to fill the hist
733 FitCH((TH1 *) projch, (Int_t) (idect-fdect1[0]));
734
735 //Method fit bis*********************************************
736 //idect is egal for fDebug = 0 and 2, only to fill the hist
737 if(fFitChargeBisOn) {
738 FitBisCH((TH1 *) projch, (Int_t) (idect-fdect1[0]));
739 }
740
741
742 //Visualise the detector for fDebug 3 or 4*******************************
743 //here is the reconstruction of the pad and row group is used!
744 if(fDebug >= 3) FillCoefChargeDB();
745
746 //Fill Infos Fit****************************************************
747 FillInfosFit(idect,0);
748
749 //Memory!!!**************************************************
750 if(fDebug != 2){
751 delete projch;
752 }
753
754
755 }//boucle object
756
757
758 //Normierungcharge************************************************
759 if(fDebug != 2) NormierungCharge();
760
761 //Error*******************************************************
762 if((fDebug == 1) || (fDebug == 4)) ErrorCH();
763
764
765 //Plot***********************************************************
766 //0 no plot, 1 and 4 error plot, 3 and 4 DB plot
767 if((fDebug == 1) || (fDebug == 4)){
768 PlotCH();
769 }
770 if((fDebug == 4) || (fDebug == 3)){
771 PlotCHDB();
772 }
773
774 //Mean Statistic********************************************************
775 if(numberfit > 0) {
776 AliInfo(Form("There is a mean statistic of: %d", (Int_t)statisticmean/numberfit));
777 }
778 else {
779 AliInfo("There is no fit!");
780 }
781
782
783 //Write the things!**************************************************
784 ConvertVectorFitCHTree();
785 if(fWriteCoef[0]){
786 WriteFitInfos(0);
787 }
788 return kTRUE;
789
790}
791//____________Functions fit Online CH2d___________________________________________________________
792
793Bool_t AliTRDCalibra::FitCHOnline(TTree *tree)
794{
795 //
796 // Look if the calibration group can be found in the tree, if yes take the histo, fit it,
797 // normalized the resulted coefficients (to 1 normally) and write the results in a tree
798 //
799
800 //Number of Xbins(detectors or groups of pads)*******************************
801 if(!InitFit(0,0,0,0)) return kFALSE;
802 Double_t statisticmean = 0.0;
803 Int_t numberfit = 0;
804
805
806 //DB Setting************************************************************************
807 //DB and so one****************************************
808
809 //DB setting
810 AliCDBManager *man = AliCDBManager::Instance();
811 if (!man) {
812 AliInfo("Could not get CDB Manager");
813 return kFALSE;
814 }
815
816
817 // Get the parameter object
818 AliTRDcalibDB *cal = AliTRDcalibDB::Instance();
819 if (!cal) {
820 AliInfo("Could not get calibDB");
821 return kFALSE;
822 }
823
824 // Get the parameter object
825 AliTRDCommonParam *parCom = AliTRDCommonParam::Instance();
826 if (!parCom) {
827 AliInfo("Could not get CommonParam Manager");
828 return kFALSE;
829 }
830
831 //Init fcountdet and fcount*************************************************
832 Initfcountdetandfcount(0);
833 TH1F* projch = 0x0;
834 tree->SetBranchAddress("histo",&projch);
835 std::vector<Int_t> vectorplace = ConvertTreeVector(tree);
836
837 //Beginning of the loop betwwen dect1 and dect2**************************************************************
838 for (Int_t idect = fdect1[0]; idect < fdect2[0]; idect++) {
839
840 //Search if the group is in the VectorCH
841 Int_t place = SearchInTreeVector(vectorplace,idect);
842
843 //Is in
844 if(place != -1){
845 //Variable
846 tree->GetEntry(place);
847 }
848
849
850 //Determination of fNnz, fNnrphi, fNfragz and fNfragrphi***********
851 Updatefcountdetandfcount(idect,0);
852
853 //Reconstruction of the row and pad group: rowmin, row max..**********************
854 Reconstructfitrowminrowmax(idect, 0);
855
856 //Number of entries
857 Double_t nentries = 0.0;
858 for(Int_t k = 0; k < fNumberBinCharge; k++){
859 nentries += projch->GetBinContent(k+1);
860 }
861
862 //Rebin and statistic stuff**********************************
863 //Rebin
864 if((fRebin > 1) && (place != -1)) projch = ReBin((TH1F *) projch);
865 //This detector has not enough statistics or was not found in VectorCH
866 if((place == -1) || ((place != -1) && (nentries < fMinEntries))) {
867
868 //Fill with the default infos**************************************
869 NotEnoughStatistic(idect,0);
870
871 continue;
872 }
873
874
875 //Statistic of the group fitted***************************************
876 AliInfo(Form("For the group number %d there are %f stats", idect, nentries));
877 numberfit ++;
878 statisticmean += nentries;
879
880
881 //Method Mean and fit*****************************************
882 //idect is egal for fDebug = 0 and 2, only to fill the hist
883 FitCH((TH1 *) projch, (Int_t) (idect-fdect1[0]));
884
885 //Method fit bis*********************************************
886 //idect is egal for fDebug = 0 and 2, only to fill the hist
887 if(fFitChargeBisOn) {
888 FitBisCH((TH1 *) projch, (Int_t) (idect-fdect1[0]));
889 }
890
891
892 //Visualise the detector for fDebug 3 or 4*******************************
893 //here is the reconstruction of the pad and row group is used!
894 if(fDebug >= 3) FillCoefChargeDB();
895
896 //Fill Infos Fit****************************************************
897 FillInfosFit(idect,0);
898
899
900 }//boucle object
901
902
903 //Normierungcharge************************************************
904 if(fDebug != 2) NormierungCharge();
905
906 //Error*******************************************************
907 if((fDebug == 1) || (fDebug == 4)) ErrorCH();
908
909
910 //Plot***********************************************************
911 //0 no plot, 1 and 4 error plot, 3 and 4 DB plot
912 if((fDebug == 1) || (fDebug == 4)){
913 PlotCH();
914 }
915 if((fDebug == 4) || (fDebug == 3)){
916 PlotCHDB();
917 }
918
919 //Mean Statistic********************************************************
920 if(numberfit > 0) {
921 AliInfo(Form("There is a mean statistic of: %d", (Int_t)statisticmean/numberfit));
922 }
923 else {
924 AliInfo("There is no fit!");
925 }
926
927
928 //Write the things!**************************************************
929 ConvertVectorFitCHTree();
930 if(fWriteCoef[0]){
931 WriteFitInfos(0);
932 }
933 return kTRUE;
934
935}
936//________________functions fit Online PH2d____________________________________________________________________
937
938Bool_t AliTRDCalibra::FitPHOnline( TProfile2D *PH)
939{
940 //
941 // Take the 1D profiles (average pulse height), projections of the 2D PH on the Xaxis, for each calibration group
942 // Fit or use the slope of the average pulse height to reconstruct the drift velocity
943 // write the results in a tree
944 // A first calibration of T0 is also made using the same method (slope method)
945 //
946
947 //Number of Xbins(detectors or groups of pads)********************************
948 TAxis *xph = PH->GetXaxis();
949 TAxis *yph = PH->GetYaxis();
950 Int_t Nbins = xph->GetNbins();
951 Int_t NYbins = yph->GetNbins();
952 Double_t lowedge = xph->GetBinLowEdge(1);
953 Double_t upedge = xph->GetBinUpEdge(xph->GetNbins());
954 if(!InitFit(Nbins,lowedge,upedge,1)) return kFALSE;
955 Double_t statisticmean = 0.0;
956 Int_t numberfit = 0;
957
958
959
960 //DB Setting************************************************************************
961 //DB and so one****************************************
962
963 //DB setting
964 AliCDBManager *man = AliCDBManager::Instance();
965 if (!man) {
966 AliInfo("Could not get CDB Manager");
967 return kFALSE;
968 }
969
970
971 // Get the parameter object
972 AliTRDcalibDB *cal = AliTRDcalibDB::Instance();
973 if (!cal) {
974 AliInfo("Could not get calibDB");
975 return kFALSE;
976 }
977
978 // Get the parameter object
979 AliTRDCommonParam *parCom = AliTRDCommonParam::Instance();
980 if (!parCom) {
981 AliInfo("Could not get CommonParam Manager");
982 return kFALSE;
983 }
984 //Init fcountdet and fcount***************************************************
985 Initfcountdetandfcount(1);
986
987
988 //beginning of the loop***************************************************************
989
990 for (Int_t idect = fdect1[1]; idect < fdect2[1]; idect++) {
991
992
993 TH1D* projph = (TH1D *)PH->ProjectionY("projph",idect+1,idect+1,(Option_t *) "e");
994 projph->SetDirectory(0);
995
996 //Number of entries for this calibration group
997 Double_t nentries = 0;
998 for(Int_t k = 0; k < NYbins; k++){
999 nentries += PH->GetBinEntries(PH->GetBin(idect+1,k+1));
1000 }
1001
1002
1003
1004 //Determination of fNnz, fNnrphi, fNfragz and fNfragrphi***********
1005 Updatefcountdetandfcount(idect,1);
1006
1007 //Reconstruction of the row and pad group: rowmin, row max..**********************
1008 Reconstructfitrowminrowmax(idect, 1);
1009
1010
1011 //Rebin and statistic stuff*********************************
1012 //This detector has not enough statistics or was off
1013 if(nentries < fMinEntries) {
1014
1015 //Fill with the default values**************************************
1016 NotEnoughStatistic(idect,1);
1017
1018 //Memory!!!**************************************************
1019 if(fDebug != 2){
1020 delete projph;
1021 }
1022
1023 continue;
1024 }
1025
1026 //Statistic of the histos fitted*********************************************
1027 AliInfo(Form("For the group number %d there are %f stats", idect, nentries));
1028 numberfit ++;
1029 statisticmean += nentries;
1030
1031
1032 //Calcul of "real" coef****************************************
1033 CalculVdriftCoefMean(fcountdet[1],(Int_t) (idect-fdect1[1]));
1034 CalculT0CoefMean(fcountdet[1],(Int_t) (idect-fdect1[1]));
1035
1036
1037 //Method Mean and fit*****************************************
1038 //idect is egal for fDebug = 0 and 2, only to fill the hist
1039 FitPente((TH1 *) projph, (Int_t) (idect-fdect1[1]));
1040
1041 //Method fit bis*********************************************
1042 //idect is egal for fDebug = 0 and 2, only to fill the hist
1043 if(fFitPHOn) {
1044 FitPH((TH1 *) projph, (Int_t) (idect-fdect1[1]));
1045 }
1046
1047 //Visualise the detector for fDebug 3 or 4*******************************
1048 //here is the reconstruction of the pad and row group is used!
1049 if(fDebug >= 3) {
1050 FillCoefVdriftDB();
1051 FillCoefT0DB();
1052 }
1053
1054 //Fill the tree if end of a detector or only the pointer to the branch!!!*******************************************
1055 FillInfosFit(idect, 1);
1056
1057
1058
1059 //Memory!!!**************************************************
1060 if(fDebug != 2){
1061 delete projph;
1062 }
1063
1064
1065 }//boucle object
1066
1067
1068
1069 //Error*******************************************************
1070 if((fDebug == 1) || (fDebug == 4)) {
1071 ErrorPH();
1072 ErrorT0();
1073 }
1074
1075
1076 //Plot***********************************************************
1077 //0 no plot, 1 and 4 error plot, 3 and 4 DB plot
1078 if((fDebug == 1) || (fDebug == 4)){
1079 PlotPH();
1080 PlotT0();
1081 }
1082 if((fDebug == 4) || (fDebug == 3)){
1083 PlotPHDB();
1084 PlotT0DB();
1085 }
1086
1087 //Mean Statistic********************************************************
1088 if(numberfit > 0) {
1089 AliInfo(Form("There is a mean statistic of: %d", (Int_t)statisticmean/numberfit));
1090 }
1091 else {
1092 AliInfo("There is no fit!");
1093 }
1094
1095
1096
1097 //Write the things!**************************************************
1098 if(fWriteCoef[1]){
1099 WriteFitInfos(1);
1100 }
1101 return kTRUE;
1102
1103}
1104//________________functions fit Online PH2d____________________________________________________________________
1105
1106Bool_t AliTRDCalibra::FitPHOnline()
1107{
1108 //
1109 // Reconstruct the average pulse height from the vectorPH for each calibration group
1110 // Fit or use the slope of the average pulse height to reconstruct the drift velocity
1111 // write the results in a tree
1112 // A first calibration of T0 is also made using the same method (slope method)
1113 //
1114
1115
1116 //Number of Xbins(detectors or groups of pads)********************************
1117 if(!InitFit(0,0,0,1)) return kFALSE;
1118 Double_t statisticmean = 0.0;
1119 Int_t numberfit = 0;
1120
1121
1122
1123 //DB Setting************************************************************************
1124 //DB and so one****************************************
1125
1126 //DB setting
1127 AliCDBManager *man = AliCDBManager::Instance();
1128 if (!man) {
1129 AliInfo("Could not get CDB Manager");
1130 return kFALSE;
1131 }
1132
1133
1134 // Get the parameter object
1135 AliTRDcalibDB *cal = AliTRDcalibDB::Instance();
1136 if (!cal) {
1137 AliInfo("Could not get calibDB");
1138 return kFALSE;
1139 }
1140
1141 // Get the parameter object
1142 AliTRDCommonParam *parCom = AliTRDCommonParam::Instance();
1143 if (!parCom) {
1144 AliInfo("Could not get CommonParam Manager");
1145 return kFALSE;
1146 }
1147 //Init fcountdet and fcount********************************************************
1148 Initfcountdetandfcount(1);
1149
1150 //beginning of the loop***************************************************************
1151
1152 for (Int_t idect = fdect1[1]; idect < fdect2[1]; idect++) {
1153
1154
1155 //Search if the group is in the VectorCH
1156 Int_t place = SearchInVector(idect,1);
1157
1158 //Is in
1159 TH1F* projph = 0x0;
1160 TString name("PH");
1161 name += idect;
1162 if(place != -1){
1163 //Variable
1164 TPInfo *fPHInfo = new TPInfo();
1165 fPHInfo->fsum = new Float_t[fTimeMax];
1166 fPHInfo->fsumsquare = new Float_t[fTimeMax];
1167 fPHInfo->fentries = new UShort_t[fTimeMax];
1168 //retrieve
1169 fPHInfo = fVectorPH[place];
1170 projph = CorrectTheError((TGraphErrors *) ConvertVectorPHisto(fPHInfo,(const char *)name));
1171 projph->SetDirectory(0);
1172 delete fPHInfo;
1173 }
1174
1175
1176 //Determination of fNnz, fNnrphi, fNfragz and fNfragrphi***********
1177 Updatefcountdetandfcount(idect,1);
1178
1179 //Reconstruction of the row and pad group: rowmin, row max..**********************
1180 Reconstructfitrowminrowmax(idect, 1);
1181
1182 //Rebin and statistic stuff*********************************
1183 //This detector has not enough statistics or was off
1184 if((place == -1) || ((place != -1) && (fEntriesCurrent < fMinEntries))) {
1185
1186 //Fill with the default values*******************************************
1187 NotEnoughStatistic(idect,1);
1188
1189 //Memory!!!**************************************************
1190 if(fDebug != 2){
1191 delete projph;
1192 }
1193 continue;
1194 }
1195
1196 //Statistic of the histos fitted*********************************************
1197 AliInfo(Form("For the group number %d there are %d stats", idect, fEntriesCurrent));
1198 numberfit ++;
1199 statisticmean += fEntriesCurrent;
1200
1201 //Calcul of "real" coef****************************************
1202 CalculVdriftCoefMean(fcountdet[1],(Int_t) (idect-fdect1[1]));
1203 CalculT0CoefMean(fcountdet[1],(Int_t) (idect-fdect1[1]));
1204
1205
1206 //Method Mean and fit*****************************************
1207 //idect is egal for fDebug = 0 and 2, only to fill the hist
1208 FitPente((TH1 *) projph, (Int_t) (idect-fdect1[1]));
1209
1210 //Method fit bis*********************************************
1211 //idect is egal for fDebug = 0 and 2, only to fill the hist
1212 if(fFitPHOn) {
1213 FitPH((TH1 *) projph, (Int_t) (idect-fdect1[1]));
1214 }
1215
1216
1217 //Visualise the detector for fDebug 3 or 4*******************************
1218 //here is the reconstruction of the pad and row group is used!
1219 if(fDebug >= 3) {
1220 FillCoefVdriftDB();
1221 FillCoefT0DB();
1222 }
1223
1224 //Fill the tree if end of a detector or only the pointer to the branch!!!*******************************************
1225 FillInfosFit(idect,1);
1226
1227
1228 //Memory!!!**************************************************
1229 if(fDebug != 2){
1230 delete projph;
1231 }
1232
1233
1234 }//boucle object
1235
1236
1237
1238 //Error*******************************************************
1239 if((fDebug == 1) || (fDebug == 4)) {
1240 ErrorPH();
1241 ErrorT0();
1242 }
1243
1244
1245 //Plot***********************************************************
1246 //0 no plot, 1 and 4 error plot, 3 and 4 DB plot
1247 if((fDebug == 1) || (fDebug == 4)){
1248 PlotPH();
1249 PlotT0();
1250 }
1251 if((fDebug == 4) || (fDebug == 3)){
1252 PlotPHDB();
1253 PlotT0DB();
1254 }
1255
1256 //Mean Statistic********************************************************
1257 if(numberfit > 0) {
1258 AliInfo(Form("There is a mean statistic of: %d", (Int_t)statisticmean/numberfit));
1259 }
1260 else {
1261 AliInfo("There is no fit!");
1262 }
1263
1264
1265 //Write the things!**************************************************
1266 if(fWriteCoef[1]){
1267 WriteFitInfos(1);
1268 }
1269 return kTRUE;
1270
1271}
1272
1273//________________functions fit Online PH2d____________________________________________________________________
1274
1275Bool_t AliTRDCalibra::FitPHOnline(TTree *tree)
1276{
1277 //
1278 // Look if the calibration group can be found in the tree, if yes take the histo, fit it,
1279 // and write the results in a tree
1280 // A first calibration of T0 is also made using the same method (slope method)
1281 //
1282
1283
1284
1285 //Number of Xbins(detectors or groups of pads)********************************
1286 if(!InitFit(0,0,0,1)) return kFALSE;
1287 Double_t statisticmean = 0.0;
1288 Int_t numberfit = 0;
1289
1290
1291
1292 //DB Setting************************************************************************
1293 //DB and so one****************************************
1294
1295 //DB setting
1296 AliCDBManager *man = AliCDBManager::Instance();
1297 if (!man) {
1298 AliInfo("Could not get CDB Manager");
1299 return kFALSE;
1300 }
1301
1302
1303 // Get the parameter object
1304 AliTRDcalibDB *cal = AliTRDcalibDB::Instance();
1305 if (!cal) {
1306 AliInfo("Could not get calibDB");
1307 return kFALSE;
1308 }
1309
1310 // Get the parameter object
1311 AliTRDCommonParam *parCom = AliTRDCommonParam::Instance();
1312 if (!parCom) {
1313 AliInfo("Could not get CommonParam Manager");
1314 return kFALSE;
1315 }
1316
1317 //Init fcountdet and fcount********************************************************
1318 Initfcountdetandfcount(1);
1319 TGraphErrors* projphtree = 0x0;
1320 tree->SetBranchAddress("histo",&projphtree);
1321 std::vector<Int_t> vectorplace = ConvertTreeVector(tree);
1322
1323 //beginning of the loop***************************************************************
1324
1325 for (Int_t idect = fdect1[1]; idect < fdect2[1]; idect++) {
1326
1327
1328 //Search if the group is in the VectorCH
1329 Int_t place = SearchInTreeVector(vectorplace,idect);
1330
1331 TH1F *projph = 0x0;
1332 //Is in
1333 if(place != -1){
1334 //Variable
1335 tree->GetEntry(place);
1336 projph = CorrectTheError(projphtree);
1337 }
1338
1339
1340 //Determination of fNnz, fNnrphi, fNfragz and fNfragrphi***********
1341 Updatefcountdetandfcount(idect,1);
1342
1343 //Reconstruction of the row and pad group: rowmin, row max..**********************
1344 Reconstructfitrowminrowmax(idect, 1);
1345
1346 //Rebin and statistic stuff*********************************
1347 //This detector has not enough statistics or was off
1348 if((place == -1) || ((place != -1) && (fEntriesCurrent < fMinEntries))) {
1349
1350 //Fill with the default values*******************************************
1351 NotEnoughStatistic(idect,1);
1352
1353 //Memory!!!**************************************************
1354 if(fDebug != 2){
1355 delete projph;
1356 }
1357
1358 continue;
1359 }
1360
1361 //Statistic of the histos fitted*********************************************
1362 AliInfo(Form("For the group number %d there are %d stats", idect, fEntriesCurrent));
1363 numberfit ++;
1364 statisticmean += fEntriesCurrent;
1365
1366
1367 //Calcul of "real" coef****************************************
1368 CalculVdriftCoefMean(fcountdet[1],(Int_t) (idect-fdect1[1]));
1369 CalculT0CoefMean(fcountdet[1],(Int_t) (idect-fdect1[1]));
1370
1371 //Method Mean and fit*****************************************
1372 //idect is egal for fDebug = 0 and 2, only to fill the hist
1373 FitPente((TH1 *) projph, (Int_t) (idect-fdect1[1]));
1374 //Method fit bis*********************************************
1375 //idect is egal for fDebug = 0 and 2, only to fill the hist
1376 if(fFitPHOn) {
1377 FitPH((TH1 *) projph, (Int_t) (idect-fdect1[1]));
1378 }
1379
1380
1381 //Visualise the detector for fDebug 3 or 4*******************************
1382 //here is the reconstruction of the pad and row group is used!
1383 if(fDebug >= 3) {
1384 FillCoefVdriftDB();
1385 FillCoefT0DB();
1386 }
1387
1388 //Fill the tree if end of a detector or only the pointer to the branch!!!*******************************************
1389 FillInfosFit(idect,1);
1390
1391
1392 //Memory!!!**************************************************
1393 if(fDebug != 2){
1394 delete projph;
1395 }
1396
1397
1398 }//boucle object
1399
1400
1401
1402 //Error*******************************************************
1403 if((fDebug == 1) || (fDebug == 4)) {
1404 ErrorPH();
1405 ErrorT0();
1406 }
1407
1408
1409 //Plot***********************************************************
1410 //0 no plot, 1 and 4 error plot, 3 and 4 DB plot
1411 if((fDebug == 1) || (fDebug == 4)){
1412 PlotPH();
1413 PlotT0();
1414 }
1415 if((fDebug == 4) || (fDebug == 3)){
1416 PlotPHDB();
1417 PlotT0DB();
1418 }
1419
1420
1421 //Mean Statistic********************************************************
1422 if(numberfit > 0) {
1423 AliInfo(Form("There is a mean statistic of: %d", (Int_t)statisticmean/numberfit));
1424 }
1425 else {
1426 AliInfo("There is no fit!");
1427 }
1428
1429
1430
1431 //Write the things!**************************************************
1432 if(fWriteCoef[1]){
1433 WriteFitInfos(1);
1434 }
1435 return kTRUE;
1436
1437}
1438//________________Functions fit Online PRF2d____________________________________________________________________
1439
1440Bool_t AliTRDCalibra::FitPRFOnline( TProfile2D *Prf)
1441{
1442 //
1443 //Take the 1D profiles (pad response function), projections of the 2D PRF on the Xaxis, for each calibration group
1444 //Fit with a gaussian to reconstruct the sigma of the pad response function
1445 //write the results in a tree
1446 //
1447
1448
1449 //Number of Xbins(detectors or groups of pads)*********************************
1450 TAxis *xprf = Prf->GetXaxis();
1451 TAxis *yprf = Prf->GetYaxis();
1452 Int_t NYbins = yprf->GetNbins();
1453 Int_t Nbins = xprf->GetNbins();
1454 Double_t lowedge = xprf->GetBinLowEdge(1);
1455 Double_t upedge = xprf->GetBinUpEdge(xprf->GetNbins());
1456 if(!InitFit(Nbins,lowedge,upedge,2)) return kFALSE;
1457 Double_t statisticmean = 0.0;
1458 Int_t numberfit = 0;
1459
1460
1461
1462 //DB and so one****************************************
1463
1464 //DB setting
1465 AliCDBManager *man = AliCDBManager::Instance();
1466 if (!man) {
1467 AliInfo("Could not get CDB Manager");
1468 return kFALSE;
1469 }
1470
1471
1472 // Get the parameter object
1473 AliTRDcalibDB *cal = AliTRDcalibDB::Instance();
1474 if (!cal) {
1475 AliInfo("Could not get calibDB");
1476 return kFALSE;
1477 }
1478
1479 // Get the parameter object
1480 AliTRDCommonParam *parCom = AliTRDCommonParam::Instance();
1481 if (!parCom) {
1482 AliInfo("Could not get CommonParam Manager");
1483 return kFALSE;
1484 }
1485 //Init fcountdet and fcount*****************************************************
1486 Initfcountdetandfcount(2);
1487
1488 //beginning of the loop***************************************************************
1489
1490 for (Int_t idect = fdect1[2]; idect < fdect2[2]; idect++) {
1491
1492
1493 TH1D* projprf = (TH1D*)Prf->ProjectionY("projprf",idect+1,idect+1,(Option_t *) "e");
1494 projprf->SetDirectory(0);
1495
1496 //Number of entries for this calibration group
1497 Double_t nentries = 0;
1498 for(Int_t k = 0; k < NYbins; k++){
1499 nentries += Prf->GetBinEntries(Prf->GetBin(idect+1,k+1));
1500 }
1501
1502
1503 //Determination of fNnz, fNnrphi, fNfragz and fNfragrphi***********
1504 Updatefcountdetandfcount(idect,2);
1505
1506 //Reconstruction of the row and pad group: rowmin, row max..**********************
1507 Reconstructfitrowminrowmax(idect, 2);
1508
1509
1510 //Rebin and statistic stuff*********************************
1511 //This detector has not enough statistics or was off
1512 if(nentries < fMinEntries) {
1513
1514 //Fill with the default values******************************
1515 NotEnoughStatistic(idect,2);
1516
1517 //Memory!
1518 if(fDebug != 2){
1519 delete projprf;
1520 }
1521
1522 continue;
1523 }
1524
1525
1526 //Statistic of the histos fitted*********************************************
1527 AliInfo(Form("For the group number %d there are %f stats", idect, nentries));
1528 numberfit ++;
1529 statisticmean += nentries;
1530
1531
1532 //Calcul of "real" coef****************************************
1533 if((fDebug == 1) || (fDebug == 4)){
1534 CalculPRFCoefMean(fcountdet[2],(Int_t) (idect-fdect1[2]));
1535 }
1536
1537 //Method Mean and fit*****************************************
1538 //idect is egal for fDebug = 0 and 2, only to fill the hist
1539 FitPRF((TH1 *) projprf, (Int_t) (idect-fdect1[2]));
1540
1541 //Visualise the detector for fDebug 3 or 4*******************************
1542 //here is the reconstruction of the pad and row group is used!
1543 if(fDebug >= 3) FillCoefPRFDB();
1544
1545 //Fill the tree if end of a detector or only the pointer to the branch!!!*******************************************
1546 FillInfosFit(idect,2);
1547
1548 //Memory!!!**************************************************
1549 if(fDebug != 2){
1550 delete projprf;
1551 }
1552
1553 }//boucle object
1554
1555
1556 //Error*******************************************************
1557 if((fDebug == 1) || (fDebug == 4)) ErrorPRF();
1558
1559
1560 //Plot***********************************************************
1561 //no plot, 1 and 4 error plot, 3 and 4 DB plot
1562 if((fDebug == 1) || (fDebug == 4)){
1563 PlotPRF();
1564 }
1565 if((fDebug == 4) || (fDebug == 3)){
1566 PlotPRFDB();
1567 }
1568
1569 //Mean Statistic********************************************************
1570 if(numberfit > 0) {
1571 AliInfo(Form("There is a mean statistic of: %d", (Int_t)statisticmean/numberfit));
1572 }
1573 else {
1574 AliInfo("There is no fit!");
1575 }
1576
1577
1578 //Write the things!**************************************************
1579 if(fWriteCoef[2]){
1580 WriteFitInfos(2);
1581 }
1582 return kTRUE;
1583
1584}
1585//________________Functions fit Online PRF2d____________________________________________________________________
1586
1587Bool_t AliTRDCalibra::FitPRFOnline(TTree *tree)
1588{
1589 //
1590 //Look if the calibration group can be found in the tree, if yes take the histo, fit it,
1591 //and write the results in a tree
1592 //
1593
1594 //Number of Xbins(detectors or groups of pads)*********************************
1595 if(!InitFit(0,0,0,2)) return kFALSE;
1596 Double_t statisticmean = 0.0;
1597 Int_t numberfit = 0;
1598
1599
1600 //DB and so one****************************************
1601
1602 //DB setting
1603 AliCDBManager *man = AliCDBManager::Instance();
1604 if (!man) {
1605 AliInfo("Could not get CDB Manager");
1606 return kFALSE;
1607 }
1608
1609 // Get the parameter object
1610 AliTRDcalibDB *cal = AliTRDcalibDB::Instance();
1611 if (!cal) {
1612 AliInfo("Could not get calibDB");
1613 return kFALSE;
1614 }
1615
1616 // Get the parameter object
1617 AliTRDCommonParam *parCom = AliTRDCommonParam::Instance();
1618 if (!parCom) {
1619 AliInfo("Could not get CommonParam Manager");
1620 return kFALSE;
1621 }
1622
1623 //Init fcountdet and fcount*********************************************************
1624 Initfcountdetandfcount(2);
1625 TGraphErrors* projprftree = 0x0;
1626 tree->SetBranchAddress("histo",&projprftree);
1627 std::vector<Int_t> vectorplace = ConvertTreeVector(tree);
1628
1629 //beginning of the loop***************************************************************
1630
1631 for (Int_t idect = fdect1[2]; idect < fdect2[2]; idect++) {
1632
1633 //Search if the group is in the VectorCH
1634 Int_t place = SearchInTreeVector(vectorplace,idect);
1635
1636
1637 //Is in
1638 TH1F *projprf = 0x0;
1639 if(place != -1){
1640 //Variable
1641 tree->GetEntry(place);
1642 projprf = CorrectTheError(projprftree);
1643 }
1644
1645 //Determination of fNnz, fNnrphi, fNfragz and fNfragrphi***********
1646 Updatefcountdetandfcount(idect,2);
1647
1648 //Reconstruction of the row and pad group: rowmin, row max..**********************
1649 Reconstructfitrowminrowmax(idect, 2);
1650
1651
1652 //Rebin and statistic stuff*********************************
1653 //This detector has not enough statistics or was off
1654 if((place == -1) ||((place != -1) &&(fEntriesCurrent < fMinEntries))) {
1655
1656 //Fill with the default values*******************************
1657 NotEnoughStatistic(idect,2);
1658
1659 //Memory!!!**************************************************
1660 if(fDebug != 2){
1661 delete projprf;
1662 }
1663
1664 continue;
1665 }
1666
1667 //Statistic of the histos fitted*********************************************
1668 AliInfo(Form("For the group number %d there are %d stats", idect, fEntriesCurrent));
1669 numberfit ++;
1670 statisticmean += fEntriesCurrent;
1671
1672 //Calcul of "real" coef****************************************
1673 if((fDebug == 1) || (fDebug == 4)){
1674 CalculPRFCoefMean(fcountdet[2],(Int_t) (idect-fdect1[2]));
1675 }
1676
1677 //Method Mean and fit*****************************************
1678 //idect is egal for fDebug = 0 and 2, only to fill the hist
1679 FitPRF((TH1 *) projprf, (Int_t) (idect-fdect1[2]));
1680 //Visualise the detector for fDebug 3 or 4*******************************
1681 //here is the reconstruction of the pad and row group is used!
1682 if(fDebug >= 3) FillCoefPRFDB();
1683 //Fill the tree if end of a detector or only the pointer to the branch!!!*******************************************
1684 FillInfosFit(idect,2);
1685
1686
1687 //Memory!!!**************************************************
1688 if(fDebug != 2){
1689 delete projprf;
1690 }
1691
1692 }//boucle object
1693
1694
1695 //Error*******************************************************
1696 if((fDebug == 1) || (fDebug == 4)) ErrorPRF();
1697
1698
1699 //Plot***********************************************************
1700 //no plot, 1 and 4 error plot, 3 and 4 DB plot
1701 if((fDebug == 1) || (fDebug == 4)){
1702 PlotPRF();
1703 }
1704 if((fDebug == 4) || (fDebug == 3)){
1705 PlotPRFDB();
1706 }
1707
1708 //Mean Statistic********************************************************
1709 if(numberfit > 0) {
1710 AliInfo(Form("There is a mean statistic of: %d", (Int_t)statisticmean/numberfit));
1711 }
1712 else {
1713 AliInfo("There is no fit!");
1714 }
1715
1716
1717 //Write the things!**************************************************
1718 if(fWriteCoef[2]){
1719 WriteFitInfos(2);
1720 }
1721 return kTRUE;
1722
1723}
1724//________________Functions fit Online PRF2d____________________________________________________________________
1725
1726Bool_t AliTRDCalibra::FitPRFOnline()
1727{
1728 //
1729 //Reconstruct the 1D histo (pad response function) from the vectorPRD for each calibration group
1730 //Fit with a gaussian to reconstruct the sigma of the pad response function
1731 //write the results in a tree
1732 //
1733
1734
1735
1736 //Number of Xbins(detectors or groups of pads)*********************************
1737 if(!InitFit(0,0,0,2)) return kFALSE;
1738 Double_t statisticmean = 0.0;
1739 Int_t numberfit = 0;
1740
1741
1742 //DB and so one****************************************
1743
1744 //DB setting
1745 AliCDBManager *man = AliCDBManager::Instance();
1746 if (!man) {
1747 AliInfo("Could not get CDB Manager");
1748 return kFALSE;
1749 }
1750
1751
1752 // Get the parameter object
1753 AliTRDcalibDB *cal = AliTRDcalibDB::Instance();
1754 if (!cal) {
1755 AliInfo("Could not get calibDB");
1756 return kFALSE;
1757 }
1758
1759 // Get the parameter object
1760 AliTRDCommonParam *parCom = AliTRDCommonParam::Instance();
1761 if (!parCom) {
1762 AliInfo("Could not get CommonParam Manager");
1763 return kFALSE;
1764 }
1765 //Init fcountdet and fcount*********************************************************
1766 Initfcountdetandfcount(2);
1767
1768 //beginning of the loop***************************************************************
1769
1770 for (Int_t idect = fdect1[2]; idect < fdect2[2]; idect++) {
1771
1772 //Search if the group is in the VectorCH
1773 Int_t place = SearchInVector(idect,2);
1774
1775
1776 //Is in
1777 TH1F* projprf = 0x0;
1778 TString name("PRF");
1779 name += idect;
1780 if(place != -1){
1781 //Variable
1782 TPInfo *fPRFInfo = new TPInfo();
1783 fPRFInfo->fsum = new Float_t[fNumberBinPRF];
1784 fPRFInfo->fsumsquare = new Float_t[fNumberBinPRF];
1785 fPRFInfo->fentries = new UShort_t[fNumberBinPRF];
1786 //retrieve
1787 fPRFInfo = fVectorPRF[place];
1788 projprf = CorrectTheError((TGraphErrors *) ConvertVectorPHisto(fPRFInfo, (const char *)name));
1789 projprf->SetDirectory(0);
1790 delete fPRFInfo;
1791 }
1792
1793 //Determination of fNnz, fNnrphi, fNfragz and fNfragrphi***********
1794 Updatefcountdetandfcount(idect,2);
1795
1796 //Reconstruction of the row and pad group: rowmin, row max..**********************
1797 Reconstructfitrowminrowmax(idect, 2);
1798
1799
1800 //Rebin and statistic stuff*********************************
1801 //This detector has not enough statistics or was off
1802 if((place == -1) ||((place != -1) &&(fEntriesCurrent < fMinEntries))) {
1803
1804 //Fill with the default values*******************************
1805 NotEnoughStatistic(idect,2);
1806
1807 //Memory************************
1808 if(fDebug != 2){
1809 delete projprf;
1810 }
1811
1812
1813 continue;
1814 }
1815
1816
1817 //Statistic of the histos fitted*********************************************
1818 AliInfo(Form("For the group number %d there are %d stats", idect, fEntriesCurrent));
1819 numberfit ++;
1820 statisticmean += fEntriesCurrent;
1821
1822
1823 //Calcul of "real" coef****************************************
1824 if((fDebug == 1) || (fDebug == 4)){
1825 CalculPRFCoefMean(fcountdet[2],(Int_t) (idect-fdect1[2]));
1826 }
1827 //Method Mean and fit*****************************************
1828 //idect is egal for fDebug = 0 and 2, only to fill the hist
1829 FitPRF((TH1 *) projprf, (Int_t) (idect-fdect1[2]));
1830 //Visualise the detector for fDebug 3 or 4*******************************
1831 //here is the reconstruction of the pad and row group is used!
1832 if(fDebug >= 3) FillCoefPRFDB();
1833 //Fill the tree if end of a detector or only the pointer to the branch!!!*******************************************
1834 FillInfosFit(idect,2);
1835
1836 //Memory!!!**************************************************
1837 if(fDebug != 2){
1838 delete projprf;
1839 }
1840
1841 }//boucle object
1842
1843
1844
1845 //Error*******************************************************
1846 if((fDebug == 1) || (fDebug == 4)) ErrorPRF();
1847
1848
1849 //Plot***********************************************************
1850 //no plot, 1 and 4 error plot, 3 and 4 DB plot
1851 if((fDebug == 1) || (fDebug == 4)){
1852 PlotPRF();
1853 }
1854 if((fDebug == 4) || (fDebug == 3)){
1855 PlotPRFDB();
1856 }
1857
1858 //Mean Statistic********************************************************
1859 if(numberfit > 0) {
1860 AliInfo(Form("There is a mean statistic of: %d", (Int_t)statisticmean/numberfit));
1861 }
1862 else {
1863 AliInfo("There is no fit!");
1864 }
1865
1866
1867 //Write the things!**************************************************
1868 if(fWriteCoef[2]){
1869 WriteFitInfos(2);
1870 }
1871 return kTRUE;
1872
1873}
1874
1875
1876//____________Functions for initialising the AliTRDCalibra in the code_________________________________________________________________________-
1877
1878Bool_t AliTRDCalibra::Init2Dhistos()
1879{
1880//
1881//For the offline tracking
1882//This function will be called in the function AliReconstruction::Run()
1883//Init the calibration mode (Nz, Nrphi), the 2D histograms if fHisto2d = kTRUE,
1884//
1885
1886
1887
1888 //DB Setting **************************************************************************************
1889 //Get cal
1890 AliTRDcalibDB *cal = AliTRDcalibDB::Instance();
1891 if (!cal) {
1892 AliInfo("Could not get calibDB");
1893 return kFALSE;
1894 }
1895
1896
1897
1898 // Some parameters
1899 fTimeMax = cal->GetNumberOfTimeBins();
1900 fSf = cal->GetSamplingFrequency();
1901 if(fRelativeScaleAuto) fRelativeScale = 0;
1902 else fRelativeScale = 20;
1903
1904
1905
1906
1907 //Create the 2D histos corresponding to the pad groupCalibration mode***************************************************************
1908 if(fCH2dOn) {
1909 AliInfo(Form("The pad calibration mode for the relative gain calibration: Nz %d, and Nrphi %d", fNz[0], fNrphi[0]));
1910
1911 //Calcul the number of Xbins
1912 fNtotal[0] = 0;
1913 ModePadCalibration(2,0);
1914 ModePadFragmentation(0,2,0,0);
1915 fdetChamb2[0] = fNfragz[0]*fNfragrphi[0];
1916 if(fDebug == 4) {
1917 AliInfo(Form("For the chamber 2: %d", fdetChamb2[0]));
1918 }
1919 fNtotal[0] += 6*18*fdetChamb2[0];
1920 ModePadCalibration(0,0);
1921 ModePadFragmentation(0,0,0,0);
1922 fdetChamb0[0] = fNfragz[0]*fNfragrphi[0];
1923 if(fDebug == 4) {
1924 AliInfo(Form("For the other chamber 0: %d", fdetChamb0[0]));
1925 }
1926 fNtotal[0] += 6*4*18*fdetChamb0[0];
1927 AliInfo(Form("Total number of Xbins: %d", fNtotal[0]));
1928
1929
1930 //Create the 2D histo
1931 if(fHisto2d) CreateCH2d(fNtotal[0]);
1932
1933 //Variable
1934 famptotal = new Float_t[TMath::Max(fdetChamb2[0],fdetChamb0[0])];
1935 for(Int_t k = 0; k < TMath::Max(fdetChamb2[0],fdetChamb0[0]); k++){
1936 famptotal[k] = 0.0;
1937 }
1938
1939
1940 }
1941
1942 if(fPH2dOn) {
1943 AliInfo(Form("The pad calibration mode for the drift velocity calibration: Nz %d, and Nrphi %d", fNz[1], fNrphi[1]));
1944
1945 //Calcul the number of Xbins
1946 fNtotal[1] = 0;
1947 ModePadCalibration(2,1);
1948 ModePadFragmentation(0,2,0,1);
1949 fdetChamb2[1] = fNfragz[1]*fNfragrphi[1];
1950 if(fDebug == 4) {
1951 AliInfo(Form("For the chamber 2: %d", fdetChamb2[1]));
1952 }
1953 fNtotal[1] += 6*18*fdetChamb2[1];
1954 ModePadCalibration(0,1);
1955 ModePadFragmentation(0,0,0,1);
1956 fdetChamb0[1] = fNfragz[1]*fNfragrphi[1];
1957 if(fDebug == 4) {
1958 AliInfo(Form("For the chamber 0: %d", fdetChamb0[1]));
1959 }
1960 fNtotal[1] += 6*4*18*fdetChamb0[1];
1961 AliInfo(Form("Total number of Xbins: %d", fNtotal[1]));
1962
1963
1964 //Create the 2D histo
1965 if(fHisto2d) CreatePH2d(fNtotal[1]);
1966
1967
1968 //Variable
1969 fPHplace = new Short_t[fTimeMax];
1970 for(Int_t k = 0; k < fTimeMax; k++){
1971 fPHplace[k] = -1;
1972 }
1973 fPHvalue = new Float_t[fTimeMax];
1974 for(Int_t k = 0; k < fTimeMax; k++){
1975 fPHvalue[k] = -1.0;
1976 }
1977
1978
1979
1980
1981
1982 }
1983
1984 if(fPRF2dOn) {
1985 AliInfo(Form("The pad calibration mode for the PRF calibration: Nz %d, and Nrphi %d", fNz[2], fNrphi[2]));
1986
1987 //Calcul the number of Xbins
1988 fNtotal[2] = 0;
1989 ModePadCalibration(2,2);
1990 ModePadFragmentation(0,2,0,2);
1991 fdetChamb2[2] = fNfragz[2]*fNfragrphi[2];
1992 if(fDebug == 4) {
1993 AliInfo(Form("For the chamber 2: %d", fdetChamb2[2]));
1994 }
1995 fNtotal[2] += 6*18*fdetChamb2[2];
1996 ModePadCalibration(0,2);
1997 ModePadFragmentation(0,0,0,2);
1998 fdetChamb0[2] = fNfragz[2]*fNfragrphi[2];
1999 if(fDebug == 4) {
2000 AliInfo(Form("For the chamber 0: %d", fdetChamb0[2]));
2001 }
2002 fNtotal[2] += 6*4*18*fdetChamb0[2];
2003 AliInfo(Form("Total number of Xbins: %d", fNtotal[2]));
2004
2005
2006 //Create the 2D histo
2007 if(fHisto2d) CreatePRF2d(fNtotal[2]);
2008
2009
2010 }
2011
2012 return kTRUE;
2013
2014}
2015
2016
2017//__________Functions for filling the histos in the code_____________________________________________________________________________
2018
2019//_______Offine tracking in the AliTRDtracker_________________________________________________
2020Bool_t AliTRDCalibra::Resettrack()
2021{
2022 //
2023 //For the offline tracking
2024 //This function will be called in the function AliTRDtracker::FollowBackPropagation() at the beginning
2025 //Reset the parameter to know we have a new TRD track
2026 //
2027
2028 fDetectorAliTRDtrack = kFALSE;
2029 return kTRUE;
2030}
2031
2032
2033//______________Offline tracking in the AliTRDtracker_________________________________________________________________________________
2034
2035Bool_t AliTRDCalibra::UpdateHistograms(AliTRDcluster *cl, AliTRDtrack *t)
2036{
2037 //
2038 //For the offline tracking
2039 //This function will be called in the function AliTRDtracker::FollowBackPropagation()
2040 //in the loop over the clusters of TRD tracks
2041 //Fill the 2D histos or the vectors with the info of the clusters at the end of a detectors
2042 //if the track is "good"
2043 //
2044
2045
2046 // Get the parameter object****************************************************
2047 AliTRDCommonParam *parCom = AliTRDCommonParam::Instance();
2048 if (!parCom) {
2049 AliInfo("Could not get CommonParam");
2050 return kFALSE;
2051 }
2052
2053 // Get the parameter object
2054 AliTRDcalibDB *cal = AliTRDcalibDB::Instance();
2055 if (!cal) {
2056 AliInfo("Could not get calibDB");
2057 return kFALSE;
2058 }
2059
2060 //Localisation of the detector**************************************************
2061 Int_t detector = cl->GetDetector();
2062 Int_t chamber = GetChamber(detector);
2063 Int_t plane = GetPlane(detector);
2064
2065
2066 //Fill the infos for the previous clusters if not the same detector anymore or if not the same track***********
2067 if(((detector != fDetectorprevioustrack) || (!fDetectorAliTRDtrack)) && (fDetectorprevioustrack != -1)) {
2068
2069 fNumbertrack++;
2070
2071 //If the same track, then look if the previous detector is in the same plane, if yes: not a good track
2072 if(fDetectorAliTRDtrack && (GetPlane(detector) <= GetPlane(fDetectorprevioustrack))) {
2073 fGoodTrack = kFALSE;
2074 }
2075
2076 //Fill only if the track doesn't touch a masked pad or doesn't appear in the middle (fGoodTrack)***************************
2077 if(fGoodTrack){
2078
2079
2080 //gain calibration************************************
2081 if(fCH2dOn){
2082 FillTheInfoOfTheTrackCH();
2083 }//if CH2dOn
2084
2085
2086 //PH calibration************************************
2087 if(fPH2dOn){
2088 FillTheInfoOfTheTrackPH();
2089 }//if PH2dOn
2090
2091 }//if a good track
2092
2093 Resetfvariables();
2094
2095
2096 }//fill at the end the charge
2097
2098
2099 //Calcul the position of the detector*********************************************************
2100 if(detector != fDetectorprevioustrack) {
2101 LocalisationdetectorXbins(detector);
2102 }
2103
2104 //Reset the good track for the PRF***********************************************************8
2105 Bool_t good = kTRUE;
2106
2107
2108 //Localisation of the cluster**************************************************************
2109 Double_t pos[3] = {0.0,0.0,0.0};
2110 pos[0] = cl->GetX();
2111 pos[1] = cl->GetY();
2112 pos[2] = cl->GetZ();
2113 Int_t time = cl->GetLocalTimeBin();
2114
2115 //Reset the detector ***********************************************************************
2116 fDetectorprevioustrack = detector;
2117 fDetectorAliTRDtrack = kTRUE;
2118
2119
2120 //Position of the cluster***********************************************************************
2121 AliTRDpadPlane *Padplane = parCom->GetPadPlane(plane,chamber);
2122 Int_t row = Padplane->GetPadRowNumber(pos[2]);
2123 Double_t OffsetZ = Padplane->GetPadRowOffset(row,pos[2]);
2124 Double_t OffsetTilt = Padplane->GetTiltOffset(OffsetZ);
2125 Int_t col = Padplane->GetPadColNumber(pos[1]+OffsetTilt,OffsetZ);
2126
2127
2128 //See if we are not near a masked pad******************************************************************
2129 if(!IsPadOn(detector,col,row)){
2130 good = kFALSE;
2131 fGoodTrack = kFALSE;
2132 }
2133
2134 if(col > 0){
2135 if(!IsPadOn(detector,col-1,row)){
2136 fGoodTrack = kFALSE;
2137 good = kFALSE;
2138 }
2139 }
2140
2141 if(col < 143){
2142 if(!IsPadOn(detector,col+1,row)){
2143 fGoodTrack = kFALSE;
2144 good = kFALSE;
2145 }
2146 }
2147
2148 //row of the cluster and position in the pad groups***********************************************
2149 Int_t posr[3] = {0,0,0};
2150 if((fCH2dOn) && (fNnz[0] != 0)) posr[0] = (Int_t) row/fNnz[0];
2151 if((fPH2dOn) && (fNnz[1] != 0)) posr[1] = (Int_t) row/fNnz[1];
2152 if((fPRF2dOn) && (fNnz[2] != 0)) posr[2] = (Int_t) row/fNnz[2];
2153
2154
2155 //col of the cluster and position in the pad groups************************************************
2156 Int_t posc[3] = {0,0,0};
2157 if((fCH2dOn) && (fNnrphi[0] != 0)) posc[0] = (Int_t) col/fNnrphi[0];
2158 if((fPH2dOn) && (fNnrphi[1] != 0)) posc[1] = (Int_t) col/fNnrphi[1];
2159 if((fPRF2dOn) && (fNnrphi[2] != 0)) posc[2] = (Int_t) col/fNnrphi[2];
2160
2161
2162 //Charge in the cluster***************************************************************************
2163 //For the moment take the abs
2164 Float_t Q = TMath::Abs(cl->GetQ());
2165 Short_t* signals = cl->GetSignals();
2166
2167
2168
2169 //Correction due to the track angle*************************************************************************
2170 Float_t correction = 1.0;
2171 Float_t normalisation = 6.67;
2172 if((Q >0) && (t->GetNdedx() > 0)){
2173 correction = t->GetClusterdQdl((t->GetNdedx() - 1))/(Q*normalisation);
2174 }
2175
2176 //Fill the famptotal with the charge*****************************************************************
2177 if(fCH2dOn) {
2178 if(!fTraMaxPad){
2179 famptotal[(Int_t) (posc[0]*fNfragz[0]+posr[0])] += Q*correction;
2180 }//fTraMaxPad
2181 else{
2182 famptotal[(Int_t) (posc[0]*fNfragz[0]+posr[0])] += ((Float_t) signals[3])*correction;
2183 }//no fTraMaxPad
2184 }//CH2dOn
2185
2186
2187 //Fill the fPHplace and value *********************************************************************
2188 if(fPH2dOn) {
2189 fPHplace[time] = posc[1]*fNfragz[1]+posr[1];
2190 if(!fTraMaxPad) {
2191 fPHvalue[time] = Q*correction;
2192 }//fTraMaxPad
2193
2194 else fPHvalue[time] = ((Float_t) signals[3])*correction;
2195
2196 }//PH2dOn
2197
2198
2199
2200 //Fill direct the PRF*******************************************************************************
2201 if((fPRF2dOn) && (good)){
2202 Float_t yminus = 0.0;
2203 Float_t xcenter = 0.0;
2204 Float_t ycenter = 0.0;
2205 Float_t ymax = 0.0;
2206 Bool_t echec = kFALSE;
2207
2208
2209 if((cl->From3pad()) && (!cl->IsUsed())){
2210
2211 //center 3 balanced
2212 if((((Float_t)signals[3]) > fThresholdClusterPRF2) && (((Float_t)signals[2]) > fThresholdClusterPRF2) && (((Float_t)signals[4]) > fThresholdClusterPRF2) && (((Float_t)signals[1]) < fThresholdClusterPRF1) && (((Float_t)signals[5]) < fThresholdClusterPRF1) && (Q*correction > 130.0)){
2213 //col correspond to signals[3]
2214 if(fCenterOfflineCluster) xcenter = cl->GetCenter();
2215 else{
2216 //security of the denomiateur is 0
2217 if((((Float_t)(((Float_t)signals[3])*((Float_t)signals[3])))/((Float_t)(((Float_t)signals[2])*((Float_t)signals[4])))) != 1.0){
2218 xcenter = 0.5*(TMath::Log((Float_t)(((Float_t)signals[4])/((Float_t)signals[2]))))/(TMath::Log(((Float_t)(((Float_t)signals[3])*((Float_t)signals[3])))/((Float_t)(((Float_t)signals[2])*((Float_t)signals[4])))));
2219 }
2220 else xcenter = -100.0;
2221 }
2222 if((xcenter > -0.5) && (xcenter < 0.5)) {
2223 ycenter = (Float_t)(((Float_t)signals[3])/(((Float_t)signals[2])+((Float_t)signals[3])+(((Float_t)signals[4]))));
2224 yminus = (Float_t)(((Float_t)signals[2])/(((Float_t)signals[2])+((Float_t)signals[3])+(((Float_t)signals[4]))));
2225 ymax = (Float_t)(((Float_t)signals[4])/(((Float_t)signals[2])+((Float_t)signals[3])+(((Float_t)signals[4]))));
2226 if((ycenter > 0.485) && (TMath::Abs(((Float_t)signals[2])+((Float_t)signals[3])+(((Float_t)signals[4])) - Q) < 8.0)) echec = kTRUE;
2227 }
2228 }
2229
2230 //fill only if it is in the drift region!
2231 if((((Float_t)(((Float_t)time)/fSf)) > 0.3) && (echec)) {
2232 if(fHisto2d) {
2233 fPRF2d->Fill((fXbins[2]+posc[2]*fNfragz[2]+posr[2]+0.5),xcenter,ycenter);
2234 if(xcenter < 0.0) fPRF2d->Fill((fXbins[2]+posc[2]*fNfragz[2]+posr[2]+0.5),-(xcenter+1.0),yminus);
2235 if(xcenter > 0.0) fPRF2d->Fill((fXbins[2]+posc[2]*fNfragz[2]+posr[2]+0.5),1.0-xcenter,ymax);
2236 }
2237 if(fVector2d) {
2238 UpdateVectorPRF(fXbins[2]+posc[2]*fNfragz[2]+posr[2],xcenter,ycenter);
2239 if(xcenter < 0.0) UpdateVectorPRF(fXbins[2]+posc[2]*fNfragz[2]+posr[2],-(xcenter+1.0),yminus);
2240 if(xcenter > 0.0) UpdateVectorPRF(fXbins[2]+posc[2]*fNfragz[2]+posr[2],1.0-xcenter,ymax);
2241 }
2242
2243 }//If in the drift region
2244 }//cluster isole
2245 }//PRF2dOn
2246
2247 return kTRUE;
2248
2249}
2250
2251//___________________________________Online trackling in AliTRDtrigger________________________________________________________________________________________________________________________________________
2252
2253Bool_t AliTRDCalibra::UpdateHistogramcm(AliTRDmcmTracklet *fTrk)
2254{
2255 //
2256 //For the tracking
2257 //This function will be called in the function AliTRDtrigger::TestTracklet before applying the pt cut on the tracklets
2258 //Fill the infos for the tracklets fTrkTest if the tracklets is "good"
2259 //
2260
2261 //Localisation of the Xbins involved********************************************
2262 Int_t idect = fTrk->GetDetector();
2263 LocalisationdetectorXbins(idect);
2264
2265 // Get the parameter object
2266 AliTRDcalibDB *cal = AliTRDcalibDB::Instance();
2267 if (!cal) {
2268 AliInfo("Could not get calibDB");
2269 return kFALSE;
2270 }
2271
2272 //Reset************************************************************************8
2273 Resetfvariables();
2274
2275
2276 //row of the tracklet and position in the pad groups******************************
2277 Int_t row = fTrk->GetRow();
2278 Int_t posr[3] = {0,0,0};
2279 if((fCH2dOn) && (fNnz[0] != 0)) posr[0] = (Int_t) row/fNnz[0];
2280 if((fPH2dOn) && (fNnz[1] != 0)) posr[1] = (Int_t) row/fNnz[1];
2281 if((fPRF2dOn) && (fNnz[2] != 0)) posr[2] = (Int_t) row/fNnz[2];
2282
2283 //Eventuelle correction due to track angle in z direction**********************************
2284 Float_t correction = 1.0;
2285 if(fmcmcorrectangle){
2286 Float_t z = fTrk->GetRowz();
2287 Float_t r = fTrk->GetTime0();
2288 correction = r/TMath::Sqrt((r*r+z*z));
2289 }
2290
2291
2292 //boucle sur les clusters*********************************************************
2293 //Condition on number of cluster: don't come from the middle of the detector******************************************************
2294 if(fTrk->GetNclusters() >= fNumberClusters){
2295
2296 for (Int_t icl = 0; icl < fTrk->GetNclusters(); icl++) {
2297 Float_t amp[3] = {0.0,0.0,0.0};
2298 Int_t time = fTrk->GetClusterTime(icl);
2299 Int_t col = fTrk->GetClusterCol(icl);
2300
2301 amp[0] = fTrk->GetClusterADC(icl)[0]*correction;
2302 amp[1] = fTrk->GetClusterADC(icl)[1]*correction;
2303 amp[2] = fTrk->GetClusterADC(icl)[2]*correction;
2304
2305 if (amp[0] < 0.0 || amp[1] < 0.0 || amp[2] < 0.0) continue;
2306
2307 //col of cluster and position in the pad groups**********************************
2308 Int_t posc[3] = {0,0,0};
2309 if((fCH2dOn) && (fNnrphi[0] != 0)) posc[0] = (Int_t) col/fNnrphi[0];
2310 if((fPH2dOn) && (fNnrphi[1] != 0)) posc[1] = (Int_t) col/fNnrphi[1];
2311 if((fPRF2dOn) && (fNnrphi[2] != 0)) posc[2] = (Int_t) col/fNnrphi[2];
2312
2313
2314 //See if we are not near a masked pad**********************************************
2315 Bool_t good = kTRUE;
2316 if(!IsPadOn(idect,col,row)){
2317
2318 fGoodTrack = kFALSE;
2319 good = kFALSE;
2320
2321 }
2322
2323 if(col > 0){
2324 if(!IsPadOn(idect,col-1,row)){
2325 fGoodTrack = kFALSE;
2326 good = kFALSE;
2327 }
2328 }
2329
2330 if(col < 143){
2331 if(!IsPadOn(idect,col+1,row)){
2332 fGoodTrack = kFALSE;
2333 good = kFALSE;
2334 }
2335 }
2336
2337
2338 // Total spectrum********************************************************************************
2339 if(fPH2dOn) fPHplace[time] = posc[1]*fNfragz[1]+posr[1];
2340 if(!fTraMaxPad){
2341
2342 if(fCH2dOn) famptotal[(Int_t) (posc[0]*fNfragz[0]+posr[0])] += (Float_t) (amp[0]+amp[1]+amp[2]);
2343
2344 if(fPH2dOn) fPHvalue[time] = (Float_t)(amp[0]+amp[1]+amp[2]);
2345
2346 }
2347
2348 else{
2349
2350 if(fCH2dOn) famptotal[(Int_t) (posc[0]*fNfragz[0]+posr[0])] += (Float_t) amp[1];
2351
2352 if(fPH2dOn) fPHvalue[time] = amp[1];
2353
2354 }
2355
2356 //Fill PRF direct**********************************************************************************8
2357 if(fPRF2dOn && good){
2358 if((amp[0] > fThresholdClusterPRF2) && (amp[1] > fThresholdClusterPRF2) && (amp[2] > fThresholdClusterPRF2) && ((amp[0]+amp[1]+amp[2]) > 130.0)){
2359 //security of the denomiateur is 0
2360 if((((Float_t)(((Float_t)amp[1])*((Float_t)amp[1])))/((Float_t)(((Float_t)amp[0])*((Float_t)amp[2])))) != 1.0){
2361 Float_t xcenter = 0.5*(TMath::Log(amp[2]/amp[0]))/(TMath::Log((amp[1]*amp[1])/(amp[0]*amp[2])));
2362 Float_t ycenter = amp[1]/(amp[0]+amp[1]+amp[2]);
2363 if((xcenter > -0.5) && (xcenter < 0.5) && (ycenter > 0.485)) {
2364 Float_t yminus = amp[0]/(amp[0]+amp[1]+amp[2]);
2365 Float_t ymax = amp[2]/(amp[0]+amp[1]+amp[2]);
2366
2367 //fill only if it is in the drift region!
2368 if(((Float_t)time/fSf) > 0.3) {
2369 if(fHisto2d)
2370 {
2371 fPRF2d->Fill((fXbins[2]+posc[2]*fNfragz[2]+posr[2]+0.5),xcenter,ycenter);
2372 if(xcenter < 0.0) fPRF2d->Fill((fXbins[2]+posc[2]*fNfragz[2]+posr[2]+0.5),-(xcenter+1.0),yminus);
2373 if(xcenter > 0.0) fPRF2d->Fill((fXbins[2]+posc[2]*fNfragz[2]+posr[2]+0.5),(1.0-xcenter),ymax);
2374 }
2375 if(fVector2d) {
2376 UpdateVectorPRF((fXbins[2]+posc[2]*fNfragz[2]+posr[2]),xcenter,ycenter);
2377 if(xcenter < 0.0) UpdateVectorPRF(fXbins[2]+posc[2]*fNfragz[2]+posr[2],-(xcenter+1.0),yminus);
2378 if(xcenter > 0.0) UpdateVectorPRF(fXbins[2]+posc[2]*fNfragz[2]+posr[2],(1.0-xcenter),ymax);
2379 }
2380 }
2381 }
2382 }
2383 }
2384 }
2385
2386 }//boucle clusters
2387
2388
2389 //Fill the charge************************************************************************************
2390 if(fCH2dOn && fGoodTrack){
2391 FillTheInfoOfTheTrackCH();
2392 }//if CH2don
2393
2394 //PH calibration************************************
2395 if(fPH2dOn && fGoodTrack){
2396 FillTheInfoOfTheTrackPH();
2397 }//if PH2dOn
2398
2399 }//condition on number of clusters
2400 return kTRUE;
2401
2402}
2403
2404//______________Functions for seeing if the pad is really okey__________________________________________________________________________________________
2405
2406//___________________________________________________________________________
2407Bool_t AliTRDCalibra::IsPadOn( Int_t detector, Int_t col, Int_t row)
2408{
2409 //
2410 //look in the choosen database if the pad is On. If no the track will be "not good"
2411 //
2412
2413
2414 // Get the parameter object
2415 AliTRDcalibDB *cal = AliTRDcalibDB::Instance();
2416 if (!cal) {
2417 AliInfo("Could not get calibDB");
2418 return kFALSE;
2419 }
2420
2421 Int_t npads = 18;
2422 Int_t colmcm = (Int_t) col/npads;
2423
2424 if(!cal->IsSuperModuleInstalled(GetSector(detector)) || !cal->IsChamberInstalled(detector) || cal->IsSuperModuleMasked(GetSector(detector)) || cal->IsChamberMasked(detector) || cal->IsMCMMasked(detector,colmcm,row) || cal->IsPadMasked(detector,col,row)){
2425
2426 return kFALSE;
2427 }
2428
2429 else return kTRUE;
2430
2431}
2432
2433//______________Functions for plotting the 2D__________________________________________________________________________________________
2434
2435//___________________________________________________________________________
2436void AliTRDCalibra::Plot2d()
2437{
2438 //
2439 // Plot the 2D histos
2440 //
2441
2442 if(fCH2dOn) PlotCH2d();
2443 if(fPH2dOn) PlotPH2d();
2444 if(fPRF2dOn) PlotPRF2d();
2445
2446}
2447//____________________Writing the 2D_________________________________________________________________________________________________
2448
2449//________________________________________________________________________________
2450Bool_t AliTRDCalibra::Write2d()
2451{
2452 //
2453 //Write the 2D histograms or the vectors converted in trees in the file "TRD.calibration.root"
2454 //
2455
2456 TFile *fout = TFile::Open(fWriteName,"RECREATE");
2457 //Check if the file could be opened
2458 if (!fout || !fout->IsOpen()) {
2459 AliInfo("No File found!");
2460 return kFALSE;
2461 }
2462 AliInfo(Form(" Numbertrack: %d Numberusedch[0]: %d, Numberusedch[1]: %d Numberusedph[0]: %d, Numberusedph[1]: %d"
2463 ,fNumbertrack,fNumberusedch[0],fNumberusedch[1],fNumberusedph[0],fNumberusedph[1]));
2464
2465
2466 TStopwatch stopwatch;
2467 stopwatch.Start();
2468 AliInfo("Write2d");
2469
2470 if((fCH2dOn ) && (fWrite[0])) {
2471 if(fHisto2d) fout->WriteTObject(fCH2d);
2472 if(fVector2d){
2473 TTree *treeCH2d = ConvertVectorCTTreeHisto(fVectorCH,fPlaCH,"treeCH2d");
2474 fout->WriteTObject(treeCH2d);
2475 }
2476 }
2477 if((fPH2dOn ) && (fWrite[1])) {
2478 if(fHisto2d) fout->WriteTObject(fPH2d);
2479 if(fVector2d){
2480 TTree *treePH2d = ConvertVectorPTreeHisto(fVectorPH,fPlaPH,"treePH2d");
2481 fout->WriteTObject(treePH2d);
2482 }
2483 }
2484 if((fPRF2dOn ) && (fWrite[2])) {
2485 if(fHisto2d) fout->WriteTObject(fPRF2d);
2486 if(fVector2d){
2487 TTree *treePRF2d = ConvertVectorPTreeHisto(fVectorPRF,fPlaPRF,"treePRF2d");
2488 fout->WriteTObject(treePRF2d);
2489 }
2490 }
2491
2492 fout->Close();
2493
2494 AliInfo(Form("Execution time Write2d: R:%.2fs C:%.2fs",
2495 stopwatch.RealTime(),stopwatch.CpuTime()));
2496
2497
2498 return kTRUE;
2499
2500}
2501//______________________________________________________________________________________________________
2502AliTRDCalDet* AliTRDCalibra::CreateDetObjectTree(TTree *tree, Int_t i)
2503{
2504 //
2505 // It Creates the AliTRDCalDet object from the tree of the coefficient for the calibration i (i != 2)
2506 // It takes the mean value of the coefficients per detector
2507 // This object has to be written in the database
2508 //
2509
2510 //Create the DetObject
2511 AliTRDCalDet *object = 0x0;
2512 if(i == 0) object = new AliTRDCalDet("ChamberGainFactor","GainFactor (detector value)");
2513 if(i == 1) object = new AliTRDCalDet("ChamberVdrift","TRD drift velocities (detector value)");
2514 else object = new AliTRDCalDet("ChamberT0","T0 (detector value)");
2515
2516 //Read the Tree
2517 Int_t detector = -1;
2518 Float_t values[2304];
2519 tree->SetBranchAddress("detector",&detector);
2520 if(i == 0) tree->SetBranchAddress("gainPad",values);
2521 if(i == 1) tree->SetBranchAddress("vdrift",values);
2522 if(i == 3) tree->SetBranchAddress("t0",values);
2523
2524 //For calculating the mean
2525 Float_t mean = 0.0;
2526 Int_t Nto = 0;
2527 Int_t numberofentries = tree->GetEntries();
2528
2529 if(numberofentries != 540) AliInfo("The tree is not complete");
2530
2531 for (Int_t det= 0; det < numberofentries; ++det){
2532 tree->GetEntry(det);
2533 if(GetChamber(detector) == 2) Nto = 1728;
2534 else Nto = 2304;
2535 mean = 0.0;
2536 for(Int_t k = 0; k < Nto; k++){
2537 mean += TMath::Abs(values[k])/Nto;
2538 }
2539 object->SetValue(detector,mean);
2540 }
2541 return object;
2542}
2543//______________________________________________________________________________________________________
2544TObject* AliTRDCalibra::CreatePadObjectTree(TTree *tree, Int_t i, AliTRDCalDet *detobject)
2545{
2546 //
2547 // It Creates the AliTRDCalPad object from the tree of the coefficient for the calibration i (i != 2)
2548 // You need first to create the object for the detectors, where the mean value is put.
2549 // This object has to be written in the database
2550 //
2551
2552
2553 //Create the DetObject
2554 AliTRDCalPad *object = 0x0;
2555 if(i == 0) object = new AliTRDCalPad("GainFactor","GainFactor (local variations)");
2556 if(i == 1) object = new AliTRDCalPad("LocalVdrift","TRD drift velocities (local variations)");
2557 else object = new AliTRDCalPad("LocalT0","T0 (local variations)");
2558
2559 //Read the Tree
2560 Int_t detector = -1;
2561 Float_t values[2304];
2562 tree->SetBranchAddress("detector",&detector);
2563 if(i == 0) tree->SetBranchAddress("gainPad",values);
2564 if(i == 1) tree->SetBranchAddress("vdrift",values);
2565 if(i == 3) tree->SetBranchAddress("t0",values);
2566
2567 //Variables
2568 Float_t mean = 0.0;
2569 Int_t numberofentries = tree->GetEntries();
2570
2571 if(numberofentries != 540) AliInfo("The tree is not complete");
2572
2573 for (Int_t det= 0; det < numberofentries; ++det){
2574 tree->GetEntry(det);
2575 AliTRDCalROC *calROC = object->GetCalROC(detector);
2576 mean = detobject->GetValue(detector);
2577 if(mean == 0) continue;
2578 Int_t rowMax = calROC->GetNrows();
2579 Int_t colMax = calROC->GetNcols();
2580 for(Int_t row = 0; row < rowMax; ++row){
2581 for(Int_t col = 0; col < colMax; ++col){
2582 calROC->SetValue(col,row,TMath::Abs(values[(Int_t) (col*rowMax+row)])/mean);
2583 }//col
2584 }//row
2585 }
2586 return object;
2587}
2588//______________________________________________________________________________________________________
2589TObject* AliTRDCalibra::CreatePadObjectTree(TTree *tree)
2590{
2591 //
2592 // It Creates the AliTRDCalPad object from the tree of the coefficient for the calibration PRF (i = 2)
2593 // This object has to be written in the database
2594 //
2595
2596
2597 //Create the DetObject
2598 AliTRDCalPad *object = new AliTRDCalPad("PRFWidth","PRFWidth");
2599
2600 //Read the Tree
2601 Int_t detector = -1;
2602 Float_t values[2304];
2603 tree->SetBranchAddress("detector",&detector);
2604 tree->SetBranchAddress("width",values);
2605
2606 //Variables
2607 Int_t numberofentries = tree->GetEntries();
2608
2609 if(numberofentries != 540) AliInfo("The tree is not complete");
2610
2611 for (Int_t det= 0; det < numberofentries; ++det){
2612 tree->GetEntry(det);
2613 AliTRDCalROC *calROC = object->GetCalROC(detector);
2614 Int_t rowMax = calROC->GetNrows();
2615 Int_t colMax = calROC->GetNcols();
2616 for(Int_t row = 0; row < rowMax; ++row){
2617 for(Int_t col = 0; col < colMax; ++col){
2618 calROC->SetValue(col,row,TMath::Abs(values[(Int_t) (col*rowMax+row)]));
2619 }//col
2620 }//row
2621 }
2622 return object;
2623}
2624//______________________________________________________________________________________________________
2625TTree* AliTRDCalibra::Sum2Trees(const char* filename1, const char* filename2, const char *variablecali)
2626{
2627 //
2628 // It returns the sum of two trees with the name variablecali in the files filenam1 and filename2
2629 // equivalent of merging two 2D histos
2630 // The name of the resulting tree is the same as the two input trees
2631 // variablecali can be treeCH2d, treePH2d or treePRF2d
2632 //
2633
2634
2635 //Variables
2636 TChain *treeChain = new TChain(variablecali);
2637 std::vector<Int_t> vectorplace;
2638 std::vector<std::vector<Int_t> > where;
2639
2640
2641
2642 //first tree*****************************
2643 //Take the tree
2644 TFile *file1 = (TFile *) TFile::Open(filename1,"READ");
2645 TTree *tree1 = (TTree *) file1->Get(variablecali);
2646 //Take the places
2647 vectorplace = ConvertTreeVector(tree1);
2648 //Say where it is in tree 1
2649 for(Int_t jui = 0; jui < (Int_t) vectorplace.size(); jui++){
2650 std::vector<Int_t> chainplace;
2651 chainplace.push_back((Int_t) jui);
2652 where.push_back(chainplace);
2653 }
2654 //Add to the chain
2655 treeChain->Add(filename1);
2656 delete file1;
2657
2658
2659
2660
2661 //second tree*****************************
2662 //Take the tree
2663 TFile *file2 = (TFile *) TFile::Open(filename2,"READ");
2664 TTree *tree2 = (TTree *) file2->Get(variablecali);
2665 //Take the places
2666 std::vector<Int_t> vector2 = ConvertTreeVector(tree2);
2667 Int_t j = treeChain->GetEntries();
2668 for(Int_t jui = 0; jui < (Int_t) vector2.size(); jui++){
2669 //Search if already found
2670 Int_t place = SearchInTreeVector(vectorplace,vector2[jui]);
2671 //Create a new element in the two std vectors
2672 if(place == -1){
2673 std::vector<Int_t> chainplace;
2674 chainplace.push_back((Int_t) (j+jui));
2675 vectorplace.push_back((Int_t) (vector2[jui]));
2676 where.push_back(chainplace);
2677
2678 }
2679 //Update the element at the place "place" in the std vector whereinthechain
2680 else {
2681 std::vector<Int_t> chainplace = where[place];
2682 chainplace.push_back((Int_t) (j+jui));
2683 std::vector<std::vector<Int_t> >::iterator it = where.begin()+place;
2684 where.erase(it);
2685 where.insert(it,chainplace);
2686 }
2687 }
2688 //Add to the Chain
2689 treeChain->Add(filename2);
2690 delete file2;
2691
2692
2693 //Take care of the profile
2694 const char* pattern = "P";
2695 TTree *tree = 0x0;
2696
2697 if(!strstr(variablecali,pattern)){
2698 //Ready to read the chain
2699 TH1F *his = 0x0;
2700 treeChain->SetBranchAddress("histo",&his);
2701
2702 //Initialise the final tree
2703 Int_t group = -1;
2704 TH1F *histsum = 0x0;
2705
2706 tree = new TTree(variablecali,variablecali);
2707 tree->Branch("groupnumber",&group,"groupnumber/I");
2708 tree->Branch("histo","TH1F",&histsum,32000,0);
2709
2710 //Init histsum
2711 if(treeChain->GetEntries() < 1) return tree1;
2712
2713 for(Int_t h = 0; h < (Int_t) vectorplace.size(); h++){
2714 group = vectorplace[h];
2715 std::vector<Int_t> chainplace = where[h];
2716 treeChain->GetEntry(chainplace[0]);
2717 //Init for the first time
2718 if(h == 0) {
2719 histsum = new TH1F("","",his->GetXaxis()->GetNbins(),his->GetXaxis()->GetBinLowEdge(1),his->GetXaxis()->GetBinUpEdge(his->GetXaxis()->GetNbins()));
2720 histsum->Sumw2();
2721 }
2722 //Reset for each new group
2723 histsum->SetEntries(0.0);
2724 for(Int_t l = 0; l <= histsum->GetXaxis()->GetNbins(); l++){
2725 histsum->SetBinContent(l,0.0);
2726 histsum->SetBinError(l,0.0);
2727 }
2728 histsum->Add(his,1);
2729 if((Int_t) chainplace.size() > 1){
2730 for(Int_t s = 1; s < (Int_t)chainplace.size(); s++){
2731 treeChain->GetEntry(chainplace[s]);
2732 histsum->Add(his,1);
2733 }
2734 }
2735 tree->Fill();
2736 }
2737 }
2738 else{
2739 //Ready to read the chain
2740 TGraphErrors *his = 0x0;
2741 treeChain->SetBranchAddress("histo",&his);
2742
2743 //Initialise the final tree
2744 Int_t group = -1;
2745 TGraphErrors *histsum = 0x0;
2746 Double_t *xref = 0x0;
2747
2748 tree = new TTree(variablecali,variablecali);
2749 tree->Branch("groupnumber",&group,"groupnumber/I");
2750 tree->Branch("histo","TGraphErrors",&histsum,32000,0);
2751
2752 //Init histsum
2753 if(treeChain->GetEntries() < 1) return tree1;
2754
2755 for(Int_t h = 0; h < (Int_t) vectorplace.size(); h++){
2756 group = vectorplace[h];
2757 std::vector<Int_t> chainplace = where[h];
2758 treeChain->GetEntry(chainplace[0]);
2759 //Init or reset for a new group
2760 Int_t nbins = his->GetN();
2761 Double_t *x;
2762 x = new Double_t[nbins];
2763 xref = his->GetX();
2764 Double_t *ex;
2765 ex = new Double_t[nbins];
2766 Double_t *y;
2767 y = new Double_t[nbins];
2768 Double_t *ey;
2769 ey = new Double_t[nbins];
2770
2771 for(Int_t lo = 0; lo < nbins; lo++){
2772 x[lo] = xref[lo];
2773 ex[lo] = 0.0;
2774 y[lo] = 0.0;
2775 ey[lo] = 0.0;
2776 }
2777 delete histsum;
2778 histsum = new TGraphErrors(nbins,x,y,ex,ey);
2779
2780
2781 //Add the first
2782 histsum = AddProfiles(his,histsum);
2783 if((Int_t) chainplace.size() > 1){
2784 for(Int_t s = 1; s < (Int_t)chainplace.size(); s++){
2785 treeChain->GetEntry(chainplace[s]);
2786 histsum = AddProfiles(his,histsum);
2787 }
2788 }
2789 tree->Fill();
2790 }
2791 }
2792
2793
2794 return tree;
2795}
2796//____________Function fill 2D for the moment out of the code_____________________________________________________________________________________________
2797
2798//____________Function fill 2D all objects from digits_________________________________________________________________________
2799
2800 Bool_t AliTRDCalibra::Create2DDiSimOnline(Int_t iev1, Int_t iev2)
2801{
2802 //
2803 // Only for simulations, after the simulation, create the 2D histos from the digits stored in the file "TRD.Digits.root"
2804 // Only for CH and PH
2805 //
2806
2807
2808 const Int_t kNplan = 6;
2809 const Int_t kNcham = 5;
2810
2811
2812 //RunLoader and so on*****************************************************************
2813 if (gAlice) {
2814 delete gAlice->GetRunLoader();
2815 delete gAlice;
2816 gAlice=0;
2817 }
2818
2819
2820 AliRunLoader* rl = AliRunLoader::Open("TRD_test.root");
2821 if (!rl) {
2822 return kFALSE;
2823 }
2824
2825 rl->LoadgAlice();
2826 gAlice = rl->GetAliRun();
2827 if (!gAlice) {
2828 return kFALSE;
2829 }
2830
2831 // Import the Trees for the event nEvent in the file
2832 rl->LoadKinematics();
2833 rl->GetEvent(0);
2834 rl->LoadHeader();
2835
2836 AliLoader* loader = rl->GetLoader("TRDLoader");
2837 if (!loader) {
2838 AliInfo("No TRDLLoader found!");
2839 return kFALSE;
2840 }
2841
2842 // Get the pointer to the TRD detector
2843 AliTRD *trd = (AliTRD *) gAlice->GetDetector("TRD");
2844 if (!trd) {
2845 AliInfo("No TRD detector found");
2846 return kFALSE;
2847 }
2848 // Get the pointer to the geometry object
2849 AliTRDgeometry *geo;
2850 if (trd) {
2851 geo = trd->GetGeometry();
2852 }
2853 else {
2854 AliInfo("No TRD geometry found");
2855 return kFALSE;
2856 }
2857
2858
2859 //DB Setting********************************************************************************
2860 //DB setting
2861 AliCDBManager *man = AliCDBManager::Instance();
2862 if (!man) {
2863 AliInfo("Could not get CDB Manager");
2864 return kFALSE;
2865 }
2866
2867
2868 // Get the parameter object
2869 AliTRDCommonParam *parCom = AliTRDCommonParam::Instance();
2870 if (!parCom) {
2871 AliInfo("Could not get CommonParam");
2872 return kFALSE;
2873 }
2874 AliTRDcalibDB *cal = AliTRDcalibDB::Instance();
2875 if (!cal) {
2876 AliInfo("Could not get calibDB");
2877 return kFALSE;
2878 }
2879
2880
2881 // Some parameters*****************************************************************
2882 fTimeMax = cal->GetNumberOfTimeBins();
2883 fSf = (Float_t) cal->GetSamplingFrequency();
2884
2885
2886 //Create the 2D histos corresponding to the pad group calibration mode***********************************************************************
2887 if(fCH2dOn) {
2888 AliInfo(Form("We will fill the CH2d histo with the pad calibration mode: Nz %d, and Nrphi %d", fNz[0], fNrphi[0]));
2889
2890 //Calcul the number of Xbins
2891 fNtotal[0] = 0;
2892 ModePadCalibration(2,0);
2893 ModePadFragmentation(0,2,0,0);
2894 fdetChamb2[0] = fNfragz[0]*fNfragrphi[0];
2895 fNtotal[0] += 6*18*fdetChamb2[0];
2896 ModePadCalibration(0,0);
2897 ModePadFragmentation(0,0,0,0);
2898 fdetChamb0[0] = fNfragz[0]*fNfragrphi[0];
2899 fNtotal[0] += 6*4*18*fdetChamb0[0];
2900 AliInfo(Form("Total number of Xbins: %d", fNtotal[0]));
2901
2902
2903 //Create the 2D histo
2904 if(fHisto2d) CreateCH2d(fNtotal[0]);
2905
2906 }
2907
2908 if(fPH2dOn) {
2909 AliInfo(Form("We will fill the PH2d histo with the pad calibration mode: Nz %d, and Nrphi %d", fNz[1], fNrphi[1]));
2910
2911 //Calcul the number of Xbins
2912 fNtotal[1] = 0;
2913 ModePadCalibration(2,1);
2914 ModePadFragmentation(0,2,0,1);
2915 fdetChamb2[1] = fNfragz[1]*fNfragrphi[1];
2916 fNtotal[1] += 6*18*fdetChamb2[1];
2917 ModePadCalibration(0,1);
2918 ModePadFragmentation(0,0,0,1);
2919 fdetChamb0[1] = fNfragz[1]*fNfragrphi[1];
2920 fNtotal[1] += 6*4*18*fdetChamb0[1];
2921 AliInfo(Form("Total number of Xbins: %d", fNtotal[1]));
2922
2923
2924 //Create the 2D histo
2925 if(fHisto2d) CreatePH2d(fNtotal[1]);
2926
2927 }
2928
2929 loader->LoadDigits();
2930 AliInfo("LoadDigits ");
2931 AliTRDdigitsManager *digitsManager = new AliTRDdigitsManager();
2932 //digitsManager->SetDebug(1);
2933
2934 //Loop on event**************************************************************************************
2935 for (Int_t ievent = iev1; ievent < iev2; ievent++) {
2936 AliInfo(Form("Process event %d",ievent));
2937 rl->GetEvent(ievent);
2938 if (!loader->TreeD()){
2939 AliInfo("loader Loading Digits ... ");
2940 loader->LoadDigits();
2941 }
2942 digitsManager->ReadDigits(loader->TreeD());
2943 AliInfo("digitsManager Read Digits Done");
2944 // Read the digits from the file
2945 if (!(digitsManager->ReadDigits(loader->TreeD()))) {
2946 return kFALSE;
2947 }
2948
2949
2950 //Loop on detector************************************************************************
2951 for(Int_t iSect = 0; iSect < 18; iSect++){
2952 for(Int_t iPlane = 0; iPlane < kNplan; iPlane++){
2953 for(Int_t iChamb = 0; iChamb < kNcham; iChamb++){
2954
2955 //A little geometry:
2956 Int_t iDet = geo->GetDetector(iPlane,iChamb,iSect);
2957 Int_t rowMax = parCom->GetRowMax(iPlane,iChamb,iSect);
2958 Int_t colMax = parCom->GetColMax(iPlane);
2959
2960 //first Xbins of the detector
2961 if(fCH2dOn) CalculXBins(iDet,0);
2962 if(fPH2dOn) CalculXBins(iDet,1);
2963 //fragmentation of idect
2964 for(Int_t i = 0; i < 2; i++){
2965 ModePadCalibration(iChamb,i);
2966 ModePadFragmentation(iPlane, iChamb, iSect,i);
2967 }
2968 //In the cas of charge
2969 Float_t *amptotal;
2970 amptotal = new Float_t[fNfragrphi[0]*fNfragz[0]];
2971 if(fCH2dOn){
2972 for(Int_t k = 0; k < fNfragrphi[0]*fNfragz[0]; k++){
2973 amptotal[k] = 0.0;
2974 }
2975 }
2976
2977
2978 // Loop through the detector pixel*****************************************
2979 for (Int_t time = 0; time < fTimeMax; time++) {
2980 for (Int_t col = 0; col < colMax; col++) {
2981 for (Int_t row = 0; row < rowMax; row++) {
2982
2983
2984 //amplitude and position in pad group
2985 AliTRDdigit *digit = digitsManager->GetDigit(row,col,time,iDet);
2986 Int_t amp = digit->GetAmp();
2987 Int_t posr[2] = {0,0};
2988 Int_t posc[2] = {0,0};
2989 if((fCH2dOn) && (fNnz[0] != 0)) posr[0] = (Int_t) row/fNnz[0];
2990 if((fCH2dOn) && (fNnrphi[0] != 0)) posc[0] = (Int_t) col/fNnrphi[0];
2991 if((fPH2dOn) && (fNnz[1] != 0)) posr[1] = (Int_t) row/fNnz[1];
2992 if((fPH2dOn) && (fNnrphi[1] != 0)) posc[1] = (Int_t) col/fNnrphi[1];
2993
2994
2995 // Total spectrum
2996 if(fCH2dOn){
2997 if(amp < fThresholddigit) amp = 0;
2998 amptotal[(Int_t) (fXbins[0]+posc[0]*fNfragz[0]+posr[0])] += amp;
2999 }
3000 if(fPH2dOn ) {
3001 if(fHisto2d) fPH2d->Fill((fXbins[1]+posc[1]*fNfragz[1]+posr[1])+0.5,(Float_t)time/fSf,amp);
3002 if(fVector2d) UpdateVectorPH((fXbins[1]+posc[1]*fNfragz[1]+posr[1]), time, amp);
3003
3004 }
3005
3006
3007 //memory stuff
3008 delete digit;
3009
3010 }//boucle row
3011 }//boucle col
3012 }//boucle time
3013
3014
3015 if(fCH2dOn ){
3016 for(Int_t k = 0; k < fNfragz[0]*fNfragrphi[0]; k++){
3017 if(fHisto2d) fCH2d->Fill(fXbins[0]+k+0.5, amptotal[k]/fRelativeScale);
3018 if(fVector2d) UpdateVectorCH(fXbins[0]+k, amptotal[k]/fRelativeScale);
3019 }
3020 }
3021
3022 delete amptotal;
3023
3024
3025
3026 }//boucle chamber
3027 }//boucle plane
3028 }//boucle sect
3029
3030
3031 loader->UnloadDigits();
3032
3033 }//boucle event
3034
3035 if(fDebug == 1){
3036
3037 if(fPH2dOn && fHisto2d) PlotPH2d();
3038 if(fCH2dOn && fHisto2d) PlotCH2d();
3039
3040
3041 }
3042
3043 if(fWrite[0] || fWrite[1]) {
3044
3045 TFile *fout = TFile::Open(fWriteName,"UPDATE");
3046 //Check if the file could be opened
3047 if (!fout || !fout->IsOpen()) {
3048 AliInfo("<No File found!");
3049 return kFALSE;
3050 }
3051
3052
3053 if(fCH2dOn && fHisto2d && fWrite[0]) fout->WriteTObject(fCH2d);
3054 if(fPH2dOn && fHisto2d && fWrite[1]) fout->WriteTObject(fPH2d);
3055
3056 if(fVector2d && fCH2dOn && fWrite[0]){
3057 TTree *treeCH2d = ConvertVectorCTTreeHisto(fVectorCH,fPlaCH,"treeCH2d");
3058 fout->WriteTObject(treeCH2d);
3059 }
3060
3061 if(fVector2d && fPH2dOn && fWrite[1]){
3062 TTree *treePH2d = ConvertVectorPTreeHisto(fVectorPH,fPlaPH,"treePH2d");
3063 fout->WriteTObject(treePH2d);
3064 }
3065
3066 }
3067
3068 return kTRUE;
3069
3070}
3071//_______________Function fill 2D all objects from Raw Data______________________________________________________________________
3072
3073Bool_t AliTRDCalibra::Create2DRaDaOnline(Int_t iev1, Int_t iev2)
3074{
3075 //
3076 // After having written the RAW DATA in the current directory, create the 2D histos from these RAW DATA
3077 // Only for CH and PH
3078 //
3079
3080 const Int_t kNplan = 6;
3081 const Int_t kNcham = 5;
3082 TString dirname(".");
3083
3084 //DB Setting***************************************************************
3085 //CDB setting
3086 AliCDBManager *man = AliCDBManager::Instance();
3087 if (!man) {
3088 AliInfo("Could not get CDB Manager");
3089 return kFALSE;
3090 }
3091
3092
3093 // Get the parameter object
3094 AliTRDCommonParam *parCom = AliTRDCommonParam::Instance();
3095 if (!parCom) {
3096 AliInfo("Could not get CommonParam");
3097 return kFALSE;
3098 }
3099 AliTRDcalibDB *cal = AliTRDcalibDB::Instance();
3100 if (!cal) {
3101 AliInfo("Could not get calibDB");
3102 return kFALSE;
3103 }
3104
3105
3106 // Some parameters
3107 fTimeMax = cal->GetNumberOfTimeBins();
3108 fSf = (Float_t) cal->GetSamplingFrequency();
3109
3110
3111 //Create the 2D histo corresponding to the pad group calibration mode***************************************************************
3112 if(fCH2dOn) {
3113 AliInfo(Form("We will fill the CH2d histo with the pad calibration mode: Nz %d, and Nrphi %d", fNz[0], fNrphi[0]));
3114
3115 //Calcul the number of Xbins
3116 fNtotal[0] = 0;
3117 ModePadCalibration(2,0);
3118 ModePadFragmentation(0,2,0,0);
3119 fdetChamb2[0] = fNfragz[0]*fNfragrphi[0];
3120 fNtotal[0] += 6*18*fdetChamb2[0];
3121 ModePadCalibration(0,0);
3122 ModePadFragmentation(0,0,0,0);
3123 fdetChamb0[0] = fNfragz[0]*fNfragrphi[0];
3124 fNtotal[0] += 6*4*18*fdetChamb0[0];
3125 AliInfo(Form("Total number of Xbins: %d", fNtotal[0]));
3126
3127
3128 //Create the 2D histo
3129 if(fHisto2d) CreateCH2d(fNtotal[0]);
3130
3131 }
3132
3133 if(fPH2dOn) {
3134 AliInfo(Form("We will fill the PH2d histo with the pad calibration mode: Nz %d, and Nrphi %d", fNz[1], fNrphi[1]));
3135
3136 //Calcul the number of Xbins
3137 fNtotal[1] = 0;
3138 ModePadCalibration(2,1);
3139 ModePadFragmentation(0,2,0,1);
3140 fdetChamb2[1] = fNfragz[1]*fNfragrphi[1];
3141 fNtotal[1] += 6*18*fdetChamb2[1];
3142 ModePadCalibration(0,1);
3143 ModePadFragmentation(0,0,0,1);
3144 fdetChamb0[1] = fNfragz[1]*fNfragrphi[1];
3145 fNtotal[1] += 6*4*18*fdetChamb0[1];
3146 AliInfo(Form("Total number of Xbins: %d", fNtotal[1]));
3147
3148
3149 //Create the 2D histo
3150 if(fHisto2d) CreatePH2d(fNtotal[1]);
3151
3152 }
3153
3154
3155 AliTRDrawData *rawdata = new AliTRDrawData();
3156 AliInfo("AliTRDrawData object created ");
3157
3158
3159 //Loop on events*************************************************************
3160 for (Int_t ievent = iev1; ievent < iev2; ievent++) {
3161
3162
3163 //AliRawReaderFile
3164 AliRawReaderFile *readerfile = new AliRawReaderFile(dirname,ievent);
3165 if(!readerfile) {
3166 AliInfo("No readerfile found!");
3167 return kFALSE;
3168 }
3169
3170
3171 AliTRDdigitsManager *digitsManager = rawdata->Raw2Digits((AliRawReader *) readerfile);
3172 if(!digitsManager) {
3173 AliInfo("No DigitsManager done!");
3174 return kFALSE;
3175 }
3176
3177 //Loop on detectors**********************************************************
3178 for(Int_t iSect = 0; iSect < 18; iSect++){
3179 for(Int_t iPlane = 0; iPlane < kNplan; iPlane++){
3180 for(Int_t iChamb = 0; iChamb < kNcham; iChamb++){
3181
3182 //A little geometry:
3183 Int_t iDet = AliTRDgeometry::GetDetector(iPlane,iChamb,iSect);
3184 Int_t rowMax = parCom->GetRowMax(iPlane,iChamb,iSect);
3185 Int_t colMax = parCom->GetColMax(iPlane);
3186
3187 //first Xbins of the detector
3188 if(fCH2dOn) CalculXBins(iDet,0);
3189 if(fPH2dOn) CalculXBins(iDet,1);
3190 //fragmentation of idect
3191 for(Int_t i = 0; i < 2; i++){
3192 ModePadCalibration(iChamb,i);
3193 ModePadFragmentation(iPlane, iChamb, iSect,i);
3194 }
3195 //In the cas of charge
3196 Float_t *amptotal;
3197 amptotal = new Float_t[fNfragrphi[0]*fNfragz[0]];
3198 if(fCH2dOn){
3199 for(Int_t k = 0; k < fNfragrphi[0]*fNfragz[0]; k++){
3200 amptotal[k] = 0.0;
3201 }
3202 }
3203
3204
3205
3206
3207 // Loop through the detector pixel*****************************************
3208 for (Int_t time = 0; time < fTimeMax; time++) {
3209 for (Int_t col = 0; col < colMax; col++) {
3210 for (Int_t row = 0; row < rowMax; row++) {
3211
3212 //amplitude and position of the digit
3213 AliTRDdigit *digit = digitsManager->GetDigit(row,col,time,iDet);
3214 Int_t amp = digit->GetAmp();
3215 Int_t posr[2] = {0,0};
3216 Int_t posc[2] = {0,0};
3217 if((fCH2dOn) && (fNnz[0] != 0)) posr[0] = (Int_t) row/fNnz[0];
3218 if((fCH2dOn) && (fNnrphi[0] != 0)) posc[0] = (Int_t) col/fNnrphi[0];
3219 if((fPH2dOn) && (fNnz[1] != 0)) posr[1] = (Int_t) row/fNnz[1];
3220 if((fPH2dOn) && (fNnrphi[1] != 0)) posc[1] = (Int_t) col/fNnrphi[1];
3221
3222
3223 // Total spectrum
3224 if(fCH2dOn){
3225 if(amp < fThresholddigit) amp = 0;
3226 amptotal[(Int_t) (fXbins[0]+posc[0]*fNfragz[0]+posr[0])] += amp;
3227 }
3228 if(fPH2dOn ) {
3229 if(fHisto2d) fPH2d->Fill((fXbins[1]+posc[1]*fNfragz[1]+posr[1])+0.5,(Float_t)time/fSf,amp);
3230 if(fVector2d) UpdateVectorPH(fXbins[1]+posc[1]*fNfragz[1]+posr[1], time, amp);
3231 }
3232
3233
3234 delete digit;
3235 }//boucle row
3236 }//boucle col
3237 }//boucle time
3238
3239
3240
3241 if(fCH2dOn ){
3242 for(Int_t k = 0; k < fNfragz[0]*fNfragrphi[0]; k++){
3243 if(fHisto2d) fCH2d->Fill(fXbins[0]+k+0.5, amptotal[k]/fRelativeScale);
3244 if(fVector2d) UpdateVectorCH(fXbins[0]+k, amptotal[k]/fRelativeScale);
3245 }
3246 }
3247
3248 delete amptotal;
3249
3250
3251 }//boucle chamber
3252 }//boucle plane
3253 }//boucle sect
3254
3255 delete digitsManager;
3256 delete readerfile;
3257
3258 }//boucle event
3259
3260 if(fDebug == 1){
3261
3262 if(fPH2dOn && fHisto2d) PlotPH2d();
3263 if(fCH2dOn && fHisto2d) PlotCH2d();
3264
3265 }
3266
3267
3268 if(fWrite[0] || fWrite[1]) {
3269
3270 TFile *fout = TFile::Open(fWriteName,"UPDATE");
3271 //Check if the file could be opened
3272 if (!fout || !fout->IsOpen()) {
3273 AliInfo("<No File found!");
3274 return kFALSE;
3275 }
3276
3277
3278 if(fCH2dOn && fHisto2d && fWrite[0]) fout->WriteTObject(fCH2d);
3279 if(fPH2dOn && fHisto2d && fWrite[1]) fout->WriteTObject(fPH2d);
3280
3281 if(fVector2d && fCH2dOn && fWrite[0]){
3282 TTree *treeCH2d = ConvertVectorCTTreeHisto(fVectorCH,fPlaCH,"treeCH2d");
3283 fout->WriteTObject(treeCH2d);
3284 }
3285
3286 if(fVector2d && fPH2dOn && fWrite[1]){
3287 TTree *treePH2d = ConvertVectorPTreeHisto(fVectorPH,fPlaPH,"treePH2d");
3288 fout->WriteTObject(treePH2d);
3289 }
3290
3291 }
3292
3293 return kTRUE;
3294
3295}
3296//_________________________________Pad Calibration Public____________________________________________________
3297
3298//________________Define the number of pads per group for one detector and one calibration________________________________________________________________
3299void AliTRDCalibra::ModePadCalibration(Int_t iChamb, Int_t i)
3300{
3301 //
3302 // Definition of the calibration mode
3303 // from Nz and Nrphi, the number of row and col pads per calibration groups are setted
3304 //
3305
3306
3307 fNnz[i] = 0;
3308 fNnrphi[i] = 0;
3309
3310 if((fNz[i] == 0) && (iChamb == 2)) {
3311 fNnz[i] = 12;
3312 }
3313 if((fNz[i] == 0) && (iChamb != 2)) {
3314 fNnz[i] = 16;
3315 }
3316
3317 if((fNz[i] == 1) && (iChamb == 2)) {
3318 fNnz[i] = 6;
3319 }
3320 if((fNz[i] == 1) && (iChamb != 2)) {
3321 fNnz[i] = 8;
3322 }
3323
3324 if((fNz[i] == 2) && (iChamb == 2)) {
3325 fNnz[i] = 3;
3326 }
3327 if((fNz[i] == 2) && (iChamb != 2)) {
3328 fNnz[i] = 4;
3329 }
3330 if(fNz[i] == 3) {
3331 fNnz[i] = 2;
3332 }
3333 if(fNz[i] == 4) {
3334 fNnz[i] = 1;
3335 }
3336
3337 if(fNrphi[i] == 0) {
3338 fNnrphi[i] = 144;
3339 }
3340 if(fNrphi[i] == 1) {
3341 fNnrphi[i] = 72;
3342 }
3343
3344 if(fNrphi[i] == 2) {
3345 fNnrphi[i] = 36;
3346 }
3347
3348 if(fNrphi[i] == 3) {
3349 fNnrphi[i] = 18;
3350 }
3351
3352 if(fNrphi[i] == 4) {
3353 fNnrphi[i] = 9;
3354 }
3355 if(fNrphi[i] == 5) {
3356 fNnrphi[i] = 4;
3357 }
3358 if(fNrphi[i] == 6) {
3359 fNnrphi[i] = 1;
3360 }
3361}
3362//__________Define the number of pad groups in one detector for one calibration___________________________________________________________________________________________
3363Bool_t AliTRDCalibra::ModePadFragmentation(Int_t iPlane,Int_t iChamb, Int_t iSect, Int_t i)
3364{
3365 //
3366 // Definition of the calibration mode
3367 // from the number of row and col pads per calibration groups the number of calibration groups are setted
3368 //
3369
3370 fNfragz[i] = 0;
3371 fNfragrphi[i] = 0;
3372
3373 AliTRDCommonParam *parCom = AliTRDCommonParam::Instance();
3374 if (!parCom) {
3375 AliInfo("Could not get CommonParam Manager");
3376 return kFALSE;
3377 }
3378
3379 //A little geometry:
3380 Int_t rowMax = parCom->GetRowMax(iPlane,iChamb,iSect);
3381 Int_t colMax = parCom->GetColMax(iPlane);
3382
3383
3384 //The fragmentation
3385 if (fNnz[i] != 0) fNfragz[i] = (Int_t) rowMax/fNnz[i];
3386
3387
3388 if(fNnrphi[i] != 0) fNfragrphi[i] = (Int_t) colMax/fNnrphi[i];
3389
3390
3391 return kTRUE;
3392}
3393
3394//______________________________________________________________________________________________________
3395//______________Protected Functions____________________________________________________________________________________
3396
3397//_______________________Create the 2D histo to be filled online__________________________________________________
3398
3399//_________________________________________________________________________________
3400void AliTRDCalibra::CreatePRF2d(Int_t Nn)
3401{
3402 //
3403 // Create the 2D histos
3404 //
3405
3406 fPRF2d = new TProfile2D("PRF2d","", Nn, 0, Nn, fNumberBinPRF, -1.0, 1.0);
3407 fPRF2d->SetXTitle("Det/pad groups");
3408 fPRF2d->SetYTitle("Position x/W [pad width units]");
3409 fPRF2d->SetZTitle("Q_{i}/Q_{total}");
3410 fPRF2d->SetStats(0);
3411 fPRF2d->Sumw2();
3412
3413}
3414
3415//_________________________________________________________________________________
3416void AliTRDCalibra::CreatePH2d(Int_t Nn)
3417{
3418 //
3419 // Create the 2D histos
3420 //
3421
3422 fPH2d = new TProfile2D("PH2d","", Nn, 0, Nn, fTimeMax, -0.5/fSf,(Float_t)(fTimeMax-0.5)/fSf);
3423 fPH2d->SetXTitle("Det/pad groups");
3424 fPH2d->SetYTitle("time [#mus]");
3425 fPH2d->SetZTitle("<PH> [a.u.]");
3426 fPH2d->SetStats(0);
3427 fPH2d->Sumw2();
3428
3429}
3430
3431//__________________________________________________________________________________
3432void AliTRDCalibra::CreateCH2d(Int_t Nn)
3433{
3434 //
3435 // Create the 2D histos
3436 //
3437
3438 fCH2d = new TH2I("CH2d", "", Nn, 0, Nn, fNumberBinCharge, 0, 300);
3439 fCH2d->SetXTitle("Det/pad groups");
3440 fCH2d->SetYTitle("charge deposit [a.u]");
3441 fCH2d->SetZTitle("counts");
3442 fCH2d->SetStats(0);
3443 fCH2d->Sumw2();
3444
3445}
3446//_______Offine tracking in the AliTRDtracker_________________________________________________
3447void AliTRDCalibra::FillTheInfoOfTheTrackCH()
3448{
3449 //
3450 // For the offline tracking or mcm tracklets
3451 // This function will be called in the functions UpdateHistogram...
3452 // to fill the info of a track for the relativ gain calibration
3453 //
3454
3455 Int_t Nb = 0;//nombre de zones traversees
3456 Int_t fd = -1;//premiere zone non nulle
3457
3458
3459 //See if the track goes through different zones
3460 for(Int_t k = 0; k < fNfragz[0]*fNfragrphi[0]; k++){
3461 if(famptotal[k] > 0.0) {
3462 Nb++;
3463 if(Nb == 1) fd = k;
3464 }
3465 }
3466
3467 //if automatic scale
3468 if((fCountRelativeScale < 100) && (fRelativeScaleAuto)) {
3469 //Take only the one zone track
3470 if(Nb == 1){
3471 fRelativeScale += famptotal[fd]*0.014*0.01;
3472 fCountRelativeScale ++;
3473 }
3474 }
3475
3476
3477 //We fill the CH2d after having scale with the first 100
3478 if((fCountRelativeScale >= 100) && (fRelativeScaleAuto)){
3479 //case of track with only one zone
3480 if(Nb == 1){
3481 if(fHisto2d) fCH2d->Fill(fXbins[0]+fd+0.5, famptotal[fd]/fRelativeScale);
3482 if(fVector2d) UpdateVectorCH(fXbins[0]+fd,famptotal[fd]/fRelativeScale);
3483 }//case 1 zone
3484 //case of track with two zones
3485 if(Nb == 2){
3486 //two zones voisines sinon rien!
3487 if(famptotal[fd] > 0.0 && famptotal[fd+1] > 0.0){
3488 //one of the two very big
3489 if(famptotal[fd] > fprocent*famptotal[fd+1]) {
3490 if(fHisto2d) fCH2d->Fill(fXbins[0]+fd+0.5, famptotal[fd]/fRelativeScale);
3491 if(fVector2d) UpdateVectorCH(fXbins[0]+fd,famptotal[fd]/fRelativeScale);
3492 }
3493 if(famptotal[fd+1] > fprocent*famptotal[fd]) {
3494 if(fHisto2d) fCH2d->Fill(fXbins[0]+fd+1.5, famptotal[fd+1]/fRelativeScale);
3495 if(fVector2d) UpdateVectorCH(fXbins[0]+fd,famptotal[fd+1]/fRelativeScale);
3496 }
3497 }
3498 }//case 2 zones
3499 }
3500
3501
3502 //Fill with no automatic scale
3503 if(!fRelativeScaleAuto){
3504 //case of track with only one zone
3505 if(Nb == 1){
3506 fNumberusedch[0]++;
3507 if(fHisto2d) fCH2d->Fill(fXbins[0]+fd+0.5, famptotal[fd]/fRelativeScale);
3508 if(fVector2d) UpdateVectorCH(fXbins[0]+fd,famptotal[fd]/fRelativeScale);
3509 }//case 1 zone
3510 //case of track with two zones
3511 if(Nb == 2){
3512 //two zones voisines sinon rien!
3513 //case 1
3514 if(famptotal[fd] > 0.0 && famptotal[fd+1] > 0.0){
3515 //one of the two very big
3516 if(famptotal[fd] > fprocent*famptotal[fd+1]) {
3517 if(fHisto2d) fCH2d->Fill(fXbins[0]+fd+0.5, famptotal[fd]/fRelativeScale);
3518 if(fVector2d) UpdateVectorCH(fXbins[0]+fd,famptotal[fd]/fRelativeScale);
3519 fNumberusedch[1]++;
3520 }
3521 if(famptotal[fd+1] > fprocent*famptotal[fd]) {
3522 if(fHisto2d) fCH2d->Fill(fXbins[0]+fd+1.5, famptotal[fd+1]/fRelativeScale);
3523 if(fVector2d) UpdateVectorCH(fXbins[0]+fd+1,famptotal[fd+1]/fRelativeScale);
3524 fNumberusedch[1]++;
3525 }
3526 }
3527 //case 2
3528 if(fNfragz[0] > 1){
3529 if(famptotal[fd] > 0.0){
3530 if((fd+fNfragz[0])< (fNfragz[0]*fNfragrphi[0])){
3531 if(famptotal[fd+fNfragz[0]] > 0.0){
3532
3533 //one of the two very big
3534 if(famptotal[fd] > fprocent*famptotal[fd+fNfragz[0]]) {
3535 if(fHisto2d) fCH2d->Fill(fXbins[0]+fd+0.5, famptotal[fd]/fRelativeScale);
3536 if(fVector2d) UpdateVectorCH(fXbins[0]+fd,famptotal[fd]/fRelativeScale);
3537 fNumberusedch[1]++;
3538 }
3539 if(famptotal[fd+fNfragz[0]] > fprocent*famptotal[fd]) {
3540 if(fHisto2d) fCH2d->Fill(fXbins[0]+fd+fNfragz[0]+0.5, famptotal[fd+fNfragz[0]]/fRelativeScale);
3541 fNumberusedch[1]++;
3542 if(fVector2d) UpdateVectorCH(fXbins[0]+fd+fNfragz[0],famptotal[fd+fNfragz[0]]/fRelativeScale);
3543 }
3544 }
3545 }
3546 }
3547 }
3548 }//case 2 zones
3549 }
3550}
3551//_______Offine tracking in the AliTRDtracker_________________________________________________
3552void AliTRDCalibra::Resetfvariables()
3553{
3554 //
3555 // Reset values of famptotal, fPHvalue and fPHplace for the updateHistogram... functions
3556 //
3557
3558 //Reset the good track******************************************************************
3559 fGoodTrack = kTRUE;
3560
3561 //Reset the famptotal where we put value*****************************************************************
3562 if(fCH2dOn){
3563 for(Int_t k = 0; k < fNfragz[0]*fNfragrphi[0]; k++){
3564 famptotal[k] = 0.0;
3565 }//for
3566 }//if
3567
3568 //Reset the fPHvalue*****************************************************************
3569 if(fPH2dOn){
3570 for(Int_t k = 0; k < fTimeMax; k++){
3571 fPHvalue[k] = -1.0;
3572 fPHplace[k] = -1;
3573 }//for
3574 }//if
3575}
3576//_______Offine tracking in the AliTRDtracker_________________________________________________
3577void AliTRDCalibra::FillTheInfoOfTheTrackPH()
3578{
3579 //
3580 // For the offline tracking or mcm tracklets
3581 // This function will be called in the functions UpdateHistogram...
3582 // to fill the info of a track for the drift velocity calibration
3583 //
3584
3585 Int_t Nb = 1;//nombre de zones traversees 1, 2 ou plus de 3
3586 Int_t fd1 = -1;//premiere zone non nulle
3587 Int_t fd2 = -1;//deuxieme zone non nulle
3588 Int_t k1 = -1;//debut de la premiere zone
3589 Int_t k2 = -1;//debut de la seconde zone
3590
3591
3592 //See if the track goes through different zones
3593 for(Int_t k = 0; k < fTimeMax; k++){
3594 if(fPHvalue[k] > 0.0) {
3595 if(fd1 == -1) {
3596 fd1 = fPHplace[k];
3597 k1 = k;
3598 }
3599 if(fPHplace[k] != fd1) {
3600 if(fd2 == -1) {
3601 k2 = k;
3602 fd2 = fPHplace[k];
3603 Nb = 2;
3604 }
3605 if(fPHplace[k] != fd2) Nb = 3;
3606 }
3607 }
3608 }
3609
3610 //Fill
3611 //case of track with only one zone
3612 if(Nb == 1){
3613 fNumberusedph[0]++;
3614 for(Int_t i = 0; i < fTimeMax; i++){
3615 if(fPHvalue[i] > 0.0) {
3616 if(fHisto2d) fPH2d->Fill((fXbins[1]+fPHplace[i])+0.5,(Float_t)i/fSf,(Float_t) fPHvalue[i]);
3617 if(fDebug == 13) {
3618 AliInfo(Form("WRITE Nb %d ,place final: %d, fPHplace[i]: %d, i: %d, fPHvalue[i]: %f", Nb, fXbins[1]+fPHplace[i], fPHplace[i], i, fPHvalue[i]));
3619 }
3620 if(fVector2d) UpdateVectorPH(fXbins[1]+fPHplace[i],i,fPHvalue[i]);
3621 }
3622 }
3623 }//case 1 zone
3624 //case of track with two zones
3625 if(Nb == 2){
3626 //two zones voisines sinon rien!
3627 //case 1
3628 if((fd1 == fd2+1) || (fd2 == fd1+1)){
3629 //one of the two fast all the think
3630 if(k2 > (k1+fdifference)){
3631 fNumberusedph[1]++;
3632 for(Int_t i = k1; i < k2; i++){
3633 if(fPHvalue[i] > 0.0) {
3634 if(fHisto2d) fPH2d->Fill((fXbins[1]+fPHplace[i])+0.5,(Float_t)i/fSf,(Float_t) fPHvalue[i]);
3635 if(fVector2d) UpdateVectorPH(fXbins[1]+fPHplace[i],i,fPHvalue[i]);
3636 }
3637 }
3638 }
3639 if((k2+fdifference) < fTimeMax){
3640 fNumberusedph[1]++;
3641 for(Int_t i = k2; i < fTimeMax; i++){
3642 if(fPHvalue[i] > 0.0) {
3643 if(fHisto2d) fPH2d->Fill((fXbins[1]+fPHplace[i])+0.5,(Float_t)i/fSf,(Float_t) fPHvalue[i]);
3644 if(fVector2d) UpdateVectorPH(fXbins[1]+fPHplace[i],i,fPHvalue[i]);
3645 }
3646 }
3647 }
3648 }
3649 //two zones voisines sinon rien!
3650 if(fNfragz[1] > 1){
3651 //case 2
3652 if((fd1+fNfragz[1]) < (fNfragz[1]*fNfragrphi[1])){
3653 if(fd2 == (fd1+fNfragz[1])){
3654 //one of the two fast all the think
3655 if(k2 > (k1+fdifference)){
3656 fNumberusedph[1]++;
3657 for(Int_t i = k1; i < k2; i++){
3658 if(fPHvalue[i] > 0.0) {
3659 if(fHisto2d) fPH2d->Fill((fXbins[1]+fPHplace[i])+0.5,(Float_t)i/fSf,(Float_t) fPHvalue[i]);
3660 if(fVector2d) UpdateVectorPH(fXbins[1]+fPHplace[i],i,fPHvalue[i]);
3661 }
3662 }
3663 }
3664 if((k2+fdifference) < fTimeMax){
3665 fNumberusedph[1]++;
3666 for(Int_t i = k2; i < fTimeMax; i++){
3667 if(fPHvalue[i] > 0.0) {
3668 if(fHisto2d) fPH2d->Fill((fXbins[1]+fPHplace[i])+0.5,(Float_t)i/fSf,(Float_t) fPHvalue[i]);
3669 if(fVector2d) UpdateVectorPH(fXbins[1]+fPHplace[i],i,fPHvalue[i]);
3670 }
3671 }
3672 }
3673 }
3674 }
3675 //two zones voisines sinon rien!
3676 //case 3
3677 if((fd1-fNfragz[1]) >= 0){
3678 if(fd2 == (fd1-fNfragz[1])){
3679 //one of the two fast all the think
3680 if(k2 > (k1+fdifference)){
3681 fNumberusedph[1]++;
3682 for(Int_t i = k1; i < k2; i++){
3683 if(fPHvalue[i] > 0.0) {
3684 if(fHisto2d) fPH2d->Fill((fXbins[1]+fPHplace[i])+0.5,(Float_t)i/fSf,(Float_t) fPHvalue[i]);
3685 if(fVector2d) UpdateVectorPH(fXbins[1]+fPHplace[i],i,fPHvalue[i]);
3686 }
3687 }
3688 }
3689 if((k2+fdifference) < fTimeMax){
3690 fNumberusedph[1]++;
3691 for(Int_t i = k2; i < fTimeMax; i++){
3692 if(fPHvalue[i] > 0.0) {
3693 if(fHisto2d) fPH2d->Fill((fXbins[1]+fPHplace[i])+0.5,(Float_t)i/fSf,(Float_t) fPHvalue[i]);
3694 if(fVector2d) UpdateVectorPH(fXbins[1]+fPHplace[i],i,fPHvalue[i]);
3695 }
3696 }
3697 }
3698 }
3699 }
3700 }
3701 }//case 2 zones
3702}
3703
3704//_____________Set the pad calibration variables for the detector_____________________________________________________________________
3705
3706Bool_t AliTRDCalibra::LocalisationdetectorXbins(Int_t detector)
3707{
3708 //
3709 //For the detector calcul the first Xbins and set the number of row and col pads per calibration groups, the number of calibration groups in the detector.
3710 //
3711
3712 //first Xbins of the detector
3713 if(fCH2dOn) CalculXBins(detector,0);
3714 if(fPH2dOn) CalculXBins(detector,1);
3715 if(fPRF2dOn) CalculXBins(detector,2);
3716 //fragmentation of idect
3717 for(Int_t i = 0; i < 3; i++){
3718 ModePadCalibration((Int_t) GetChamber(detector),i);
3719 ModePadFragmentation((Int_t) GetPlane(detector), (Int_t) GetChamber(detector), (Int_t) GetSector(detector),i);
3720 }
3721
3722 return kTRUE;
3723}
3724
3725//____________________________Plot the 2D histos filled Online______________________________________________________________________
3726
3727//___________________________________________________________________________________________
3728void AliTRDCalibra::PlotPH2d()
3729{
3730 //
3731 // Plot the 2D histo
3732 //
3733
3734 TCanvas *cph2d = new TCanvas("cph2d","",50,50,600,800);
3735 cph2d->cd();
3736 fPH2d->Draw("LEGO");
3737
3738}
3739
3740//______________________________________________________________________________________________
3741void AliTRDCalibra::PlotCH2d()
3742{
3743 //
3744 // Plot the 2D histos
3745 //
3746
3747 TCanvas *cch2d = new TCanvas("cch2d","",50,50,600,800);
3748 cch2d->cd();
3749 fCH2d->Draw("LEGO");
3750
3751}
3752
3753//______________________________________________________________________________________________
3754void AliTRDCalibra::PlotPRF2d()
3755{
3756 //
3757 // Plot the 2D histos
3758 //
3759
3760 TCanvas *cPRF2d = new TCanvas("cPRF2d","",50,50,600,800);
3761 cPRF2d->cd();
3762 fPRF2d->Draw("LEGO");
3763
3764}
3765
3766//_________Fit_______________________________________________________________________
3767
3768//______________________Create histos if fDebug == 1 or fDebug >= 3_____________________________________________________________________
3769
3770//___________________________________________________________________________________________
3771void AliTRDCalibra::CreateFitHistoPH(Int_t Nbins, Double_t Low, Double_t High)
3772{
3773 //
3774 // Create the histos for fDebug = 1 and fDebug = 4 (Fit functions)
3775 //
3776
3777 //****Histograms to store the coef
3778 fCoefVdrift[0] = new TH1F("coefvdrift0","",Nbins,Low,High);
3779 fCoefVdrift[1] = new TH1F("coefvdrift1","",Nbins,Low,High);
3780 fCoefVdrift[2] = new TH1F("coefvdrift2","",Nbins,Low,High);
3781
3782
3783 //Histograms for Debug
3784 fDeltaVdrift[0] = new TH1F("deltavdrift0","",Nbins,Low,High);
3785 fDeltaVdrift[1] = new TH1F("deltavdrift1","",Nbins,Low,High);
3786 fErrorVdrift[0] = new TH1I("errorvdrift0","",300,-0.5,0.5);
3787 fErrorVdrift[1] = new TH1I("errorvdrift1","",300,-0.5,0.5);
3788
3789
3790
3791
3792 fCoefVdrift[0]->SetXTitle("Det/pad groups");
3793 fCoefVdrift[0]->SetYTitle("Vdrift [cm/#mus]");
3794 fCoefVdrift[1]->SetXTitle("Det/pad groups");
3795 fCoefVdrift[1]->SetYTitle("Vdrift [cm/#mus]");
3796 fCoefVdrift[2]->SetXTitle("Det/pad groups");
3797 fCoefVdrift[2]->SetYTitle("Vdrift [cm/#mus]");
3798
3799
3800 fDeltaVdrift[0]->SetXTitle("Det/pad groups");
3801 fDeltaVdrift[0]->SetYTitle("#Deltav/v_{sim}");
3802 fDeltaVdrift[1]->SetXTitle("Det/pad groups");
3803 fDeltaVdrift[1]->SetYTitle("#Deltav/v_{sim}");
3804
3805
3806 fErrorVdrift[0]->SetXTitle("#Deltav/v_{sim}");
3807 fErrorVdrift[0]->SetYTitle("counts");
3808 fErrorVdrift[1]->SetXTitle("#Deltav/v_{sim}");
3809 fErrorVdrift[1]->SetYTitle("counts");
3810
3811
3812 fCoefVdrift[0]->SetStats(0);
3813 fCoefVdrift[1]->SetStats(0);
3814 fCoefVdrift[2]->SetStats(0);
3815 fDeltaVdrift[0]->SetStats(0);
3816 fDeltaVdrift[1]->SetStats(0);
3817 fErrorVdrift[0]->SetStats(0);
3818 fErrorVdrift[1]->SetStats(0);
3819
3820 fCoefVdrift[0]->SetMarkerColor(6);
3821 fCoefVdrift[0]->SetMarkerStyle(26);
3822 fCoefVdrift[0]->SetLineColor(6);
3823 fCoefVdrift[1]->SetMarkerColor(2);
3824 fCoefVdrift[1]->SetMarkerStyle(24);
3825 fCoefVdrift[1]->SetLineColor(2);
3826 fCoefVdrift[2]->SetLineColor(4);
3827
3828
3829 fDeltaVdrift[1]->SetMarkerColor(2);
3830 fDeltaVdrift[1]->SetMarkerStyle(24);
3831 fDeltaVdrift[1]->SetLineColor(2);
3832 fDeltaVdrift[0]->SetMarkerColor(6);
3833 fDeltaVdrift[0]->SetMarkerStyle(26);
3834 fDeltaVdrift[0]->SetLineColor(6);
3835
3836
3837 fErrorVdrift[1]->SetLineColor(2);
3838 fErrorVdrift[1]->SetLineStyle(2);
3839 fErrorVdrift[0]->SetLineColor(6);
3840 fErrorVdrift[0]->SetLineStyle(1);
3841
3842
3843}
3844//___________________________________________________________________________________________
3845void AliTRDCalibra::CreateFitHistoT0(Int_t Nbins, Double_t Low, Double_t High)
3846{
3847 //
3848 // Create the histos for fDebug = 1 and fDebug = 4 (Fit functions)
3849 //
3850
3851 //****Histograms to store the coef
3852 fCoefT0[0] = new TH1F("coefT00","",Nbins,Low,High);
3853 fCoefT0[1] = new TH1F("coefT01","",Nbins,Low,High);
3854 fCoefT0[2] = new TH1F("coefT02","",Nbins,Low,High);
3855
3856
3857 //Histograms for Debug
3858 fDeltaT0[0] = new TH1F("deltaT00","",Nbins,Low,High);
3859 fDeltaT0[1] = new TH1F("deltaT01","",Nbins,Low,High);
3860 fErrorT0[0] = new TH1I("errorT00","",300,-0.1,0.1);
3861 fErrorT0[1] = new TH1I("errorT01","",300,-0.1,0.1);
3862
3863
3864
3865
3866 fCoefT0[0]->SetXTitle("Det/pad groups");
3867 fCoefT0[0]->SetYTitle("t0 [#mus]");
3868 fCoefT0[1]->SetXTitle("Det/pad groups");
3869 fCoefT0[1]->SetYTitle("t0 [#mus]");
3870 fCoefT0[2]->SetXTitle("Det/pad groups");
3871 fCoefT0[2]->SetYTitle("t0 [#mus]");
3872
3873
3874 fDeltaT0[0]->SetXTitle("Det/pad groups");
3875 fDeltaT0[0]->SetYTitle("#Deltat0 [#mus]");
3876 fDeltaT0[1]->SetXTitle("Det/pad groups");
3877 fDeltaT0[1]->SetYTitle("#Deltat0 [#mus]");
3878
3879
3880 fErrorT0[0]->SetXTitle("#Deltat0 [#mus]");
3881 fErrorT0[0]->SetYTitle("counts");
3882 fErrorT0[1]->SetXTitle("#Deltat0 [#mus]");
3883 fErrorT0[1]->SetYTitle("counts");
3884
3885
3886 fCoefT0[0]->SetStats(0);
3887 fCoefT0[1]->SetStats(0);
3888 fCoefT0[2]->SetStats(0);
3889 fDeltaT0[0]->SetStats(0);
3890 fDeltaT0[1]->SetStats(0);
3891 fErrorT0[0]->SetStats(0);
3892 fErrorT0[1]->SetStats(0);
3893
3894 fCoefT0[0]->SetMarkerColor(6);
3895 fCoefT0[0]->SetMarkerStyle(26);
3896 fCoefT0[0]->SetLineColor(6);
3897 fCoefT0[1]->SetMarkerColor(2);
3898 fCoefT0[1]->SetMarkerStyle(24);
3899 fCoefT0[1]->SetLineColor(2);
3900 fCoefT0[2]->SetLineColor(4);
3901
3902
3903 fDeltaT0[1]->SetMarkerColor(2);
3904 fDeltaT0[1]->SetMarkerStyle(24);
3905 fDeltaT0[1]->SetLineColor(2);
3906 fDeltaT0[0]->SetMarkerColor(6);
3907 fDeltaT0[0]->SetMarkerStyle(26);
3908 fDeltaT0[0]->SetLineColor(6);
3909
3910
3911 fErrorT0[1]->SetLineColor(2);
3912 fErrorT0[1]->SetLineStyle(2);
3913 fErrorT0[0]->SetLineColor(6);
3914 fErrorT0[0]->SetLineStyle(1);
3915
3916
3917}
3918
3919//___________________________________________________________________________________________
3920void AliTRDCalibra::CreateFitHistoCH(Int_t Nbins, Double_t Low, Double_t High)
3921{
3922 //
3923 // Create the histos for fDebug = 1 and fDebug = 4 (Fit functions)
3924 //
3925
3926 //Histograms to store the coef
3927 fCoefCharge[0] = new TH1F("coefcharge0","",Nbins, Low, High);
3928 fCoefCharge[1] = new TH1F("coefcharge1","",Nbins, Low, High);
3929 fCoefCharge[2] = new TH1F("coefcharge2","",Nbins, Low, High);
3930 fCoefCharge[3] = new TH1F("coefcharge3","",Nbins, Low, High);
3931
3932
3933 //Histograms for Debug
3934 fDeltaCharge[0] = new TH1F("deltacharge0","",Nbins, Low, High);
3935 fDeltaCharge[1] = new TH1F("deltacharge1","",Nbins, Low, High);
3936 fDeltaCharge[2] = new TH1F("deltacharge2","",Nbins, Low, High);
3937
3938
3939 fErrorCharge[0] = new TH1I("errorcharge0","",100,-0.5,0.5);
3940 fErrorCharge[1] = new TH1I("errorcharge1","",100,-0.5,0.5);
3941 fErrorCharge[2] = new TH1I("errorcharge2","",100,-0.5,0.5);
3942
3943
3944 fCoefCharge[0]->SetXTitle("Det/Pad groups");
3945 fCoefCharge[0]->SetYTitle("gain factor");
3946 fCoefCharge[1]->SetXTitle("Det/Pad groups");
3947 fCoefCharge[1]->SetYTitle("gain factor");
3948 fCoefCharge[2]->SetXTitle("Det/Pad groups");
3949 fCoefCharge[2]->SetYTitle("gain factor");
3950 fCoefCharge[3]->SetXTitle("Det/Pad groups");
3951 fCoefCharge[3]->SetYTitle("gain factor");
3952
3953 fDeltaCharge[0]->SetXTitle("Det/Pad groups");
3954 fDeltaCharge[0]->SetYTitle("#Deltag/g_{sim}");
3955 fDeltaCharge[1]->SetXTitle("Det/Pad groups");
3956 fDeltaCharge[1]->SetYTitle("#Deltag/g_{sim}");
3957 fDeltaCharge[2]->SetXTitle("Det/Pad groups");
3958 fDeltaCharge[2]->SetYTitle("#Deltag/g_{sim}");
3959 fDeltaCharge[0]->SetAxisRange(-0.5,0.5,"Y");
3960 fDeltaCharge[1]->SetAxisRange(-0.5,0.5,"Y");
3961 fDeltaCharge[2]->SetAxisRange(-0.5,0.5,"Y");
3962
3963 fErrorCharge[0]->SetXTitle("#Deltag/g_{sim}");
3964 fErrorCharge[0]->SetYTitle("counts");
3965 fErrorCharge[1]->SetXTitle("#Deltag/g_{sim}");
3966 fErrorCharge[1]->SetYTitle("counts");
3967 fErrorCharge[2]->SetXTitle("#Deltag/g_{sim}");
3968 fErrorCharge[2]->SetYTitle("counts");
3969
3970
3971 fDeltaCharge[1]->SetMarkerColor(2);
3972 fDeltaCharge[1]->SetMarkerStyle(24);
3973 fDeltaCharge[1]->SetLineColor(2);
3974 fErrorCharge[1]->SetLineColor(2);
3975 fErrorCharge[1]->SetLineStyle(2);
3976 fDeltaCharge[2]->SetMarkerColor(8);
3977 fDeltaCharge[2]->SetLineColor(8);
3978 fDeltaCharge[2]->SetMarkerStyle(9);
3979 fErrorCharge[2]->SetLineColor(8);
3980 fErrorCharge[2]->SetLineStyle(5);
3981 fDeltaCharge[0]->SetMarkerColor(6);
3982 fDeltaCharge[0]->SetLineColor(6);
3983 fDeltaCharge[0]->SetMarkerStyle(26);
3984 fErrorCharge[0]->SetLineColor(6);
3985 fErrorCharge[0]->SetLineStyle(1);
3986
3987 fCoefCharge[3]->SetLineColor(4);
3988 fCoefCharge[1]->SetMarkerColor(2);
3989 fCoefCharge[1]->SetLineColor(2);
3990 fCoefCharge[1]->SetMarkerStyle(24);
3991 fCoefCharge[2]->SetMarkerColor(8);
3992 fCoefCharge[2]->SetLineColor(8);
3993 fCoefCharge[2]->SetMarkerStyle(9);
3994 fCoefCharge[0]->SetMarkerColor(6);
3995 fCoefCharge[0]->SetLineColor(6);
3996 fCoefCharge[0]->SetMarkerStyle(26);
3997
3998 fErrorCharge[2]->SetLineWidth(3);
3999
4000
4001 fDeltaCharge[1]->SetStats(0);
4002 fDeltaCharge[2]->SetStats(0);
4003 fDeltaCharge[0]->SetStats(0);
4004 fErrorCharge[1]->SetStats(0);
4005 fErrorCharge[2]->SetStats(0);
4006 fErrorCharge[0]->SetStats(0);
4007 fCoefCharge[1]->SetStats(0);
4008 fCoefCharge[0]->SetStats(0);
4009 fCoefCharge[3]->SetStats(0);
4010 fCoefCharge[2]->SetStats(0);
4011
4012
4013}
4014//___________________________________________________________________________________________
4015void AliTRDCalibra::CreateFitHistoPRF(Int_t Nbins, Double_t Low, Double_t High)
4016{
4017 //
4018 // Create the histos for fDebug = 1 and fDebug = 4 (Fit functions)
4019 //
4020
4021 //Histograms to store the coef
4022 fCoefPRF[0] = new TH1F("coefPRF0","",Nbins, Low, High);
4023 fCoefPRF[1] = new TH1F("coefPRF1","",Nbins, Low, High);
4024
4025 //Histograms for Debug
4026 fDeltaPRF = new TH1F("deltaPRF","",Nbins, Low, High);
4027
4028 fErrorPRF = new TH1I("errorPRF","",300,-0.5,0.5);
4029
4030 fDeltaPRF->SetMarkerColor(6);
4031 fDeltaPRF->SetMarkerStyle(26);
4032 fDeltaPRF->SetLineColor(6);
4033 fErrorPRF->SetLineColor(6);
4034 fErrorPRF->SetLineStyle(2);
4035
4036 fCoefPRF[1]->SetLineColor(4);
4037 fCoefPRF[0]->SetMarkerColor(6);
4038 fCoefPRF[0]->SetMarkerStyle(26);
4039 fCoefPRF[0]->SetLineColor(6);
4040
4041 fCoefPRF[0]->SetXTitle("Det/Pad groups");
4042 fCoefPRF[0]->SetYTitle("#sigma_{PRF}");
4043 fCoefPRF[1]->SetXTitle("Det/Pad groups");
4044 fCoefPRF[1]->SetYTitle("#sigma_{PRF}");
4045
4046 fDeltaPRF->SetXTitle("Det/Pad groups");
4047 fDeltaPRF->SetYTitle("#Delta#sigma/#sigma_{sim}");
4048
4049 fErrorPRF->SetXTitle("#Delta#sigma/#sigma_{sim}");
4050 fErrorPRF->SetYTitle("counts");
4051
4052
4053 fDeltaPRF->SetStats(0);
4054 fErrorPRF->SetStats(0);
4055 fCoefPRF[1]->SetStats(0);
4056 fCoefPRF[0]->SetStats(0);
4057
4058}
4059//_________________________________________________________________________________________
4060void AliTRDCalibra::CreateFitHistoPRFDB(Int_t rowMax, Int_t colMax)
4061{
4062 //
4063 // Create the histos for fDebug = 3 and fDebug = 4 (Fit functions)
4064 //
4065 fCoefPRFDB = new TH2F("coefPRF","", rowMax, 0,rowMax, colMax, 0, colMax);
4066
4067 fCoefPRFDB->SetStats(0);
4068 fCoefPRFDB->SetXTitle("row Number");
4069 fCoefPRFDB->SetYTitle("col Number");
4070 fCoefPRFDB->SetZTitle("PRF width [pad width units]");
4071
4072
4073 fCoefPRFDB->SetFillColor(6);
4074 fCoefPRFDB->SetLineColor(6);
4075
4076
4077}
4078
4079//_________________________________________________________________________________________
4080void AliTRDCalibra::CreateFitHistoCHDB(Int_t rowMax, Int_t colMax){
4081 //
4082 // Create the histos for fDebug = 3 and fDebug = 4 (Fit functions)
4083 //
4084
4085 fCoefChargeDB[0] = new TH2F("coefchargedb0","", rowMax, 0,rowMax, colMax, 0, colMax);
4086 fCoefChargeDB[1] = new TH2F("coefchargedb1","", rowMax, 0,rowMax, colMax, 0, colMax);
4087 fCoefChargeDB[2] = new TH2F("coefchargedb2","", rowMax, 0,rowMax, colMax, 0, colMax);
4088
4089 fCoefChargeDB[0]->SetStats(0);
4090 fCoefChargeDB[1]->SetStats(0);
4091 fCoefChargeDB[2]->SetStats(0);
4092 fCoefChargeDB[0]->SetXTitle("row Number");
4093 fCoefChargeDB[0]->SetYTitle("col Number");
4094 fCoefChargeDB[1]->SetXTitle("row Number");
4095 fCoefChargeDB[1]->SetYTitle("col Number");
4096 fCoefChargeDB[2]->SetXTitle("row Number");
4097 fCoefChargeDB[2]->SetYTitle("col Number");
4098 fCoefChargeDB[0]->SetZTitle("f_{g} Fit method");
4099 fCoefChargeDB[1]->SetZTitle("f_{g} Mean method");
4100 fCoefChargeDB[2]->SetZTitle("f_{g} Fitbis method");
4101
4102
4103
4104 fCoefChargeDB[0]->SetFillColor(6);
4105 fCoefChargeDB[0]->SetLineColor(6);
4106 fCoefChargeDB[0]->SetLineColor(6);
4107 fCoefChargeDB[1]->SetFillColor(2);
4108 fCoefChargeDB[1]->SetLineColor(2);
4109 fCoefChargeDB[1]->SetLineColor(2);
4110 fCoefChargeDB[2]->SetFillColor(8);
4111 fCoefChargeDB[2]->SetLineColor(8);
4112 fCoefChargeDB[2]->SetLineColor(8);
4113
4114}
4115
4116//_________________________________________________________________________________________
4117void AliTRDCalibra::CreateFitHistoPHDB(Int_t rowMax, Int_t colMax)
4118{
4119 //
4120 // Create the histos for fDebug = 3 and fDebug = 4 (Fit functions)
4121 //
4122
4123 fCoefVdriftDB[0] = new TH2F("coefvdriftdb0","", rowMax, 0,rowMax, colMax, 0, colMax);
4124 fCoefVdriftDB[1] = new TH2F("coefvdriftdb1","", rowMax, 0,rowMax, colMax, 0, colMax);
4125
4126
4127 fCoefVdriftDB[0]->SetStats(0);
4128 fCoefVdriftDB[1]->SetStats(0);
4129 fCoefVdriftDB[0]->SetXTitle("row Number");
4130 fCoefVdriftDB[0]->SetYTitle("col Number");
4131 fCoefVdriftDB[1]->SetXTitle("row Number");
4132 fCoefVdriftDB[1]->SetYTitle("col Number");
4133 fCoefVdriftDB[0]->SetZTitle("v_{drift} Fit method");
4134 fCoefVdriftDB[1]->SetZTitle("v_{drift} slope method");
4135
4136 fCoefVdriftDB[0]->SetFillColor(6);
4137 fCoefVdriftDB[0]->SetLineColor(6);
4138 fCoefVdriftDB[0]->SetLineColor(6);
4139 fCoefVdriftDB[1]->SetFillColor(2);
4140 fCoefVdriftDB[1]->SetLineColor(2);
4141 fCoefVdriftDB[1]->SetLineColor(2);
4142
4143}
4144//_________________________________________________________________________________________
4145void AliTRDCalibra::CreateFitHistoT0DB(Int_t rowMax, Int_t colMax)
4146{
4147 //
4148 // Create the histos for fDebug = 3 and fDebug = 4 (Fit functions)
4149 //
4150
4151 fCoefT0DB[0] = new TH2F("coefT0db0","", rowMax, 0,rowMax, colMax, 0, colMax);
4152 fCoefT0DB[1] = new TH2F("coefT0db1","", rowMax, 0,rowMax, colMax, 0, colMax);
4153
4154
4155 fCoefT0DB[0]->SetStats(0);
4156 fCoefT0DB[1]->SetStats(0);
4157 fCoefT0DB[0]->SetXTitle("row Number");
4158 fCoefT0DB[0]->SetYTitle("col Number");
4159 fCoefT0DB[1]->SetXTitle("row Number");
4160 fCoefT0DB[1]->SetYTitle("col Number");
4161 fCoefT0DB[0]->SetZTitle("t0 Fit method");
4162 fCoefT0DB[1]->SetZTitle("t0 slope method");
4163
4164 fCoefT0DB[0]->SetFillColor(6);
4165 fCoefT0DB[0]->SetLineColor(6);
4166 fCoefT0DB[0]->SetLineColor(6);
4167 fCoefT0DB[1]->SetFillColor(2);
4168 fCoefT0DB[1]->SetLineColor(2);
4169 fCoefT0DB[1]->SetLineColor(2);
4170
4171}
4172//_____________________________________________________________________________
4173Bool_t AliTRDCalibra::FillVectorFitCH(Int_t countdet)
4174{
4175 //
4176 // For the Fit functions fill the vector FitCH special for the gain calibration
4177 //
4178 TFitCHInfo *fFitCHInfo = new TFitCHInfo();
4179 Int_t Ntotal = 1;
4180 if(GetChamber(countdet) == 2) Ntotal = 1728;
4181 else Ntotal = 2304;
4182 fFitCHInfo->fcoef = new Float_t[Ntotal];
4183 for(Int_t i = 0; i < Ntotal; i++){
4184 fFitCHInfo->fcoef[i] = fcoefCH[i];
4185 }
4186 fFitCHInfo->fDetector = countdet;
4187 fVectorFitCH.push_back(fFitCHInfo);
4188
4189 return kTRUE;
4190}
4191//____________Functions for initialising the AliTRDCalibra in the code_________________________________________________________________________
4192
4193Bool_t AliTRDCalibra::InitFit(Int_t Nbins, Double_t lowedge, Double_t upedge, Int_t i)
4194{
4195 //
4196 //Init the calibration mode (Nz, Nrphi), the histograms for debugging the fit methods if fDebug > 0,
4197 //
4198
4199
4200 gStyle->SetPalette(1);
4201 gStyle->SetOptStat(1111);
4202 gStyle->SetPadBorderMode(0);
4203 gStyle->SetCanvasColor(10);
4204 gStyle->SetPadLeftMargin(0.13);
4205 gStyle->SetPadRightMargin(0.01);
4206
4207 //DB Setting **************************************************************************************
4208 AliCDBManager *man = AliCDBManager::Instance();
4209 if (!man) {
4210 AliInfo("Could not get CDB Manager");
4211 return kFALSE;
4212 }
4213
4214
4215 //Get cal
4216 AliTRDcalibDB *cal = AliTRDcalibDB::Instance();
4217 if (!cal) {
4218 AliInfo("Could not get calibDB");
4219 return kFALSE;
4220 }
4221
4222 // Get the parameter object
4223 AliTRDCommonParam *parCom = AliTRDCommonParam::Instance();
4224 if (!parCom) {
4225 AliInfo("Could not get CommonParam Manager");
4226 return kFALSE;
4227 }
4228
4229
4230
4231
4232 // Some parameters
4233 fTimeMax = cal->GetNumberOfTimeBins();
4234 fSf = cal->GetSamplingFrequency();
4235
4236
4237 //Mode groups of pads: the total number of bins!*******************************************************
4238 Int_t numberofbinsexpected = 0;
4239 ModePadCalibration(2,i);
4240 ModePadFragmentation(0,2,0,i);
4241 fdetChamb2[i] = fNfragz[i]*fNfragrphi[i];
4242 if(fDebug == 1) AliInfo(Form("For the chamber 2: %d", fdetChamb2[i]));
4243 numberofbinsexpected += 6*18*fdetChamb2[i];
4244 ModePadCalibration(0,i);
4245 ModePadFragmentation(0,0,0,i);
4246 fdetChamb0[i] = fNfragz[i]*fNfragrphi[i];
4247 if(fDebug == 1) AliInfo(Form("For the other chamber 0: %d", fdetChamb0[i]));
4248 numberofbinsexpected += 6*4*18*fdetChamb0[i];
4249
4250
4251 //Quick verification that we have the good pad calibration mode if 2D histos!
4252 if(Nbins != 0){
4253 if(numberofbinsexpected != Nbins){
4254 AliInfo("It doesn't correspond to the mode of pad group calibration!");
4255 return kFALSE;
4256 }
4257 }
4258
4259 //Security for fDebug 3 and 4
4260 if((fDebug >= 3) && ((fDet[0] > 5) || (fDet[1] > 4) || (fDet[2] > 17))){
4261 AliInfo("This detector doesn't exit!");
4262 return kFALSE;
4263
4264 }
4265
4266
4267 //Determine fDet1 and fDet2***************************************************************
4268 fdect1[i] = -1;
4269 fdect2[i] = -1;
4270 if(fDebug == 2) {
4271 fdect1[i] = fFitVoir;
4272 fdect2[i] = fdect1[i] +1;
4273 }
4274 if(fDebug <= 1){
4275 fdect1[i] = 0;
4276 fdect2[i] = numberofbinsexpected;
4277 }
4278 if(fDebug >= 3){
4279 CalculXBins(AliTRDgeometry::GetDetector(fDet[0],fDet[1],fDet[2]),i);
4280 fdect1[i] = fXbins[i];
4281 CalculXBins((AliTRDgeometry::GetDetector(fDet[0],fDet[1],fDet[2])+1),i);
4282 fdect2[i] = fXbins[i];
4283 }
4284
4285 //Create the histos for debugging***************************************************************
4286
4287 //CH
4288 if(i == 0) {
4289
4290 //Init the VectorFitCH********************************************************
4291 fcoefCH = new Float_t[2304];
4292 for(Int_t k = 0; k < 2304; k++){
4293 fcoefCH[k] = 0.0;
4294 }
4295 fScalefitfactor = 0.0;
4296
4297 //Number of Xbins(detectors or groups of pads) if Vector2d*******************************
4298 //Quick verification that we are not out of range!
4299 if(Nbins == 0){
4300 if((Int_t) fVectorCH.size() > numberofbinsexpected){
4301 AliInfo("ch doesn't correspond to the mode of pad group calibration!");
4302 return kFALSE;
4303 }
4304
4305 if((Int_t) fVectorCH.size() != (Int_t) fPlaCH.size()){
4306 AliInfo("VectorCH doesn't correspond to PlaCH!");
4307 return kFALSE;
4308 }
4309 }
4310
4311 //Debugging____Create the histos********************************************
4312
4313 //fDebug == 0 nothing
4314
4315 //fDebug == 1
4316 if(fDebug == 1){
4317 if(Nbins != 0){
4318 //create the histos replique de ch if histos2D
4319 CreateFitHistoCH(Nbins, lowedge, upedge);
4320 }
4321 else{
4322 //create the histos replique de ch vector2d
4323 CreateFitHistoCH(numberofbinsexpected, 0, numberofbinsexpected);
4324 }
4325 }
4326
4327
4328 //fDebug == 2 and fFitVoir no histo
4329 if(fDebug == 2){
4330 if(fFitVoir < numberofbinsexpected) {
4331 AliInfo(Form("We will see the fit of the object %d",fFitVoir));
4332 }
4333 else {
4334 AliInfo("fFitVoir is out of range of the histo!");
4335 return kFALSE;
4336 }
4337 }
4338
4339
4340 //fDebug == 3 or 4 and fDet
4341 if(fDebug >= 3){
4342 if((fNz[0] == 0) && (fNrphi[0] == 0)) {
4343 AliInfo("Do you really want to see one detector without pad groups?");
4344 return kFALSE;
4345 }
4346 else {
4347 AliInfo(Form("You will see the detector: iPlane %d, iChamb %d, iSect %d",fDet[0], fDet[1], fDet[2]));
4348
4349
4350
4351
4352 //A little geometry:
4353 Int_t rowMax = parCom->GetRowMax(fDet[0],fDet[1],fDet[2]);
4354 Int_t colMax = parCom->GetColMax(fDet[0]);
4355
4356
4357 //Create the histos to visualise
4358 CreateFitHistoCHDB(rowMax, colMax);
4359 if(fDebug == 4) CreateFitHistoCH((Int_t) (fdect2[0]-fdect1[0]), fdect1[0], fdect2[0]);
4360
4361 }
4362 }
4363 }
4364
4365
4366 //PH and T0
4367 if(i == 1) {
4368
4369 //Number of Xbins(detectors or groups of pads) if vector2d*******************************
4370 //Quick verification that we are not out of range!
4371 if(Nbins == 0){
4372 if((Int_t) fVectorPH.size() > numberofbinsexpected){
4373 AliInfo("ch doesn't correspond to the mode of pad group calibration!");
4374 return kFALSE;
4375 }
4376 if((Int_t) fVectorPH.size() != (Int_t) fPlaPH.size()){
4377 AliInfo("VectorPH doesn't correspond to PlaPH!");
4378 return kFALSE;
4379 }
4380 }
4381
4382 //init tree**********************************************
4383
4384 InittreePH();
4385 InittreeT0();
4386
4387
4388
4389 //Debugging____Create the histos********************************************
4390
4391 //fDebug == 0 nothing
4392
4393 //fDebug == 1
4394 if(fDebug == 1){
4395 if(Nbins != 0){
4396 //create the histos replique de ch
4397 CreateFitHistoPH(Nbins,lowedge,upedge);
4398 CreateFitHistoT0(Nbins,lowedge,upedge);
4399 }
4400 else {
4401 //create the histos replique de ch if vector2d
4402 CreateFitHistoPH(numberofbinsexpected,0,numberofbinsexpected);
4403 CreateFitHistoT0(numberofbinsexpected,0,numberofbinsexpected);
4404 }
4405 }
4406
4407
4408 //fDebug == 2 and fFitVoir no histo
4409 if(fDebug == 2){
4410 if(fFitVoir < numberofbinsexpected) {
4411 AliInfo(Form("We will see the fit of the object %d",fFitVoir));
4412 }
4413 else {
4414 AliInfo("fFitVoir is out of range of the histo!");
4415 return kFALSE;
4416 }
4417 }
4418
4419
4420
4421 //fDebug == 3 or 4 and fDet
4422 if(fDebug >= 3){
4423 if((fNz[1] == 0) && (fNrphi[1] == 0)) {
4424 AliInfo("Do you really want to see one detector without pad groups?");
4425 return kFALSE;
4426 }
4427 else {
4428 AliInfo(Form("You will see the detector: iPlane %d, iChamb %d, iSect %d",fDet[0], fDet[1], fDet[2]));
4429
4430 //A little geometry:
4431 Int_t rowMax = parCom->GetRowMax(fDet[0],fDet[1],fDet[2]);
4432 Int_t colMax = parCom->GetColMax(fDet[0]);
4433
4434 //Create the histos to visualise
4435 CreateFitHistoPHDB(rowMax, colMax);
4436 CreateFitHistoT0DB(rowMax, colMax);
4437 if(fDebug == 4) {
4438 CreateFitHistoPH((Int_t) (fdect2[1]-fdect1[1]), fdect1[1], fdect2[1]);
4439 CreateFitHistoT0((Int_t) (fdect2[1]-fdect1[1]), fdect1[1], fdect2[1]);
4440 }
4441
4442 }
4443 }
4444 }
4445 //PRF
4446 if(i == 2) {
4447
4448 //Number of Xbins(detectors or groups of pads) if vector2d*******************************
4449 if(Nbins == 0){
4450 //Quick verification that we are not out of range!
4451 if((Int_t) fVectorPRF.size() > numberofbinsexpected){
4452 AliInfo("ch doesn't correspond to the mode of pad group calibration!");
4453 return kFALSE;
4454 }
4455 if((Int_t) fVectorPRF.size() != (Int_t) fPlaPRF.size()){
4456 AliInfo("VectorPRF doesn't correspond to PlaCH!");
4457 return kFALSE;
4458 }
4459 }
4460
4461
4462 //init tree**********************************************
4463 InittreePRF();
4464
4465
4466
4467 //Debugging____Create the histos********************************************
4468
4469 //fDebug == 0 nothing
4470
4471 //fDebug == 1
4472 if(fDebug == 1){
4473 if(Nbins != 0){
4474 //create the histos replique de ch
4475 CreateFitHistoPRF(Nbins,lowedge,upedge);
4476 }
4477 else {
4478 //create the histos replique de ch
4479 CreateFitHistoPRF(numberofbinsexpected,0,numberofbinsexpected);
4480 }
4481 }
4482
4483
4484 //fDebug == 2 and fFitVoir no histo
4485 if(fDebug == 2){
4486 if(fFitVoir < numberofbinsexpected) {
4487 AliInfo(Form("We will see the fit of the object %d",fFitVoir));
4488 }
4489 else {
4490 AliInfo("fFitVoir is out of range of the histo!");
4491 return kFALSE;
4492 }
4493 }
4494
4495
4496
4497 //fDebug == 3 or 4 and fDet
4498 if(fDebug >= 3){
4499 if((fNz[2] == 0) && (fNrphi[2] == 0)) {
4500 AliInfo("Do you really want to see one detector without pad groups?");
4501 return kFALSE;
4502 }
4503 else {
4504 AliInfo(Form("You will see the detector: iPlane %d, iChamb %d, iSect %d",fDet[0], fDet[1], fDet[2]));
4505
4506 //A little geometry:
4507 Int_t rowMax = parCom->GetRowMax(fDet[0],fDet[1],fDet[2]);
4508 Int_t colMax = parCom->GetColMax(fDet[0]);
4509
4510 //Create the histos to visualise
4511 CreateFitHistoPRFDB(rowMax, colMax);
4512 if(fDebug == 4) CreateFitHistoPRF((Int_t) (fdect2[2]-fdect1[2]), fdect1[2], fdect2[2]);
4513
4514 }
4515 }
4516 }
4517
4518 return kTRUE;
4519
4520}
4521
4522//____________Functions for initialising the AliTRDCalibra in the code_________________________________________________________________________
4523
4524void AliTRDCalibra::Initfcountdetandfcount(Int_t i)
4525{
4526 //
4527 //Init the current detector where we are fcountdet and the next fcount for the functions Fit...
4528 //
4529
4530 //loop on the Xbins of ch!!**********************************************************************
4531 fcountdet[i] = -1;//current detector
4532 fcount[i] = 0;//to find the next detector
4533
4534 //if fDebug >= 3*******************************************************************
4535 if(fDebug >= 3){
4536
4537 //Set countdet to the detector
4538 fcountdet[i] = AliTRDgeometry::GetDetector(fDet[0],fDet[1], fDet[2]);
4539
4540
4541 //Determination of fNnz, fNnrphi, fNfragz and fNfragrphi
4542 ModePadCalibration(fDet[1], i);
4543 ModePadFragmentation(fDet[0],fDet[1],fDet[2],i);
4544
4545
4546 //Set counter to write at the end of the detector
4547 fcount[i] = fdect1[i] + fNfragz[i]*fNfragrphi[i];
4548
4549
4550 }
4551}
4552
4553//____________Functions for initialising the AliTRDCalibra in the code_________________________________________________________________________
4554
4555void AliTRDCalibra::Updatefcountdetandfcount(Int_t idect, Int_t i)
4556{
4557 //
4558 //See if we are in a new detector and update the variables fNfragz and fNfragrphi if yes
4559 //
4560
4561
4562 //Determination of fNnz, fNnrphi, fNfragz and fNfragrphi***********
4563 //if fDebug == 1 or 0
4564 if((fDebug == 0) || (fDebug == 1)){
4565 if(fcount[i] == idect) {
4566
4567 //on en est au detector
4568 fcountdet[i] += 1;
4569
4570 //Determination of fNnz, fNnrphi, fNfragz and fNfragrphi
4571 ModePadCalibration((Int_t) GetChamber(fcountdet[i]), i);
4572 ModePadFragmentation((Int_t) GetPlane(fcountdet[i]),(Int_t) GetChamber(fcountdet[i]),(Int_t) GetSector(fcountdet[i]),i);
4573
4574
4575 //Set for the next detector
4576 fcount[i] += fNfragz[i]*fNfragrphi[i];
4577
4578 }
4579 }
4580
4581}
4582//____________Functions for initialising the AliTRDCalibra in the code_________________________________________________________________________
4583
4584void AliTRDCalibra::Reconstructfitrowminrowmax(Int_t idect, Int_t i)
4585{
4586 //
4587 // Reconstruct the min pad row, max pad row, min pad col and max pad col of the calibration group for the Fit functions
4588 //
4589
4590 if(fDebug < 2) {
4591 ReconstructionRowPadGroup((Int_t) (idect-(fcount[i]-(fNfragz[i]*fNfragrphi[i]))), i);
4592 }
4593 if(fDebug >= 3){
4594 ReconstructionRowPadGroup((Int_t) (idect - fdect1[i]), i);
4595 }
4596}
4597
4598
4599//____________Functions for initialising the AliTRDCalibra in the code_________________________________________________________________________
4600
4601Bool_t AliTRDCalibra::NotEnoughStatistic(Int_t idect, Int_t i)
4602{
4603 //
4604 // For the case where there are not enough entries in the histograms of the calibration group, the value present in the choosen database will be put. A negativ sign enables to know that a fit was not possible.
4605 //
4606
4607
4608 // Get the parameter object
4609 AliTRDCommonParam *parCom = AliTRDCommonParam::Instance();
4610 if (!parCom) {
4611 AliInfo("Could not get CommonParam Manager");
4612 return kFALSE;
4613 }
4614
4615 //Get cal
4616 AliTRDcalibDB *cal = AliTRDcalibDB::Instance();
4617 if (!cal) {
4618 AliInfo("Could not get calibDB");
4619 return kFALSE;
4620 }
4621
4622
4623 if(fDebug != 2) {
4624 AliInfo(Form("The element %d in this detector %d has not enough statistic to be fitted",idect-(fcount[i]-(fNfragz[i]*fNfragrphi[i])),fcountdet[i]));
4625 }
4626 if(fDebug == 2) {
4627 AliInfo("The element has not enough statistic to be fitted");
4628 }
4629
4630 if( (i == 0) && (fDebug != 2)){
4631
4632 //Calcul the coef from the database choosen
4633 CalculChargeCoefMean(fcountdet[0],(Int_t) (idect-fdect1[0]), kFALSE);
4634
4635 //Fill the coefCH[2304] with negative value to say: not fitted
4636 for(Int_t k = frowmin[0]; k < frowmax[0]; k++){
4637 for(Int_t j = fcolmin[0]; j < fcolmax[0]; j++){
4638 if(GetChamber(fcountdet[0]) == 2) fcoefCH[(Int_t)(j*12+k)]=-TMath::Abs(fChargeCoef[3]);
4639 if(GetChamber(fcountdet[0]) != 2) fcoefCH[(Int_t)(j*16+k)]=-TMath::Abs(fChargeCoef[3]);
4640 }
4641 }
4642 //end of one detector
4643 if((idect == (fcount[0]-1))) {
4644 FillVectorFitCH((Int_t) fcountdet[0]);
4645 //Reset
4646 for(Int_t k = 0; k < 2304; k++){
4647 fcoefCH[k] = 0.0;
4648 }
4649 }
4650 }
4651
4652 if((i == 1) && (fDebug != 2)){
4653
4654 CalculVdriftCoefMean(fcountdet[1],(Int_t) (idect-fdect1[1]));
4655 CalculT0CoefMean(fcountdet[1],(Int_t) (idect-fdect1[1]));
4656
4657
4658 //Put the default value
4659 if((fDebug == 1) || (fDebug == 4)) {
4660 if(fFitPHOn) {
4661 fCoefVdrift[0]->SetBinContent(idect-fdect1[1]+1,fVdriftCoef[2]);
4662 fCoefT0[0]->SetBinContent(idect-fdect1[1]+1,fT0Coef[2]);
4663 }
4664 fCoefVdrift[1]->SetBinContent(idect-fdect1[1]+1,fVdriftCoef[2]);
4665 fCoefT0[1]->SetBinContent(idect-fdect1[1]+1,fT0Coef[2]);
4666 }
4667
4668 //Put the default value
4669 if(fDebug >= 3){
4670 fVdriftCoef[0] = fVdriftCoef[2];
4671 fVdriftCoef[1] = fVdriftCoef[2];
4672 FillCoefVdriftDB();
4673 fT0Coef[0] = fT0Coef[2];
4674 fT0Coef[1] = fT0Coef[2];
4675 FillCoefT0DB();
4676 }
4677
4678
4679 //Fill the tree if end of a detector. The pointer to the branch stays with the default value 1.5!!!*******
4680 //PH*******************************
4681 //pointer to the branch
4682 for(Int_t k = frowmin[1]; k < frowmax[1]; k++){
4683 for(Int_t j = fcolmin[1]; j < fcolmax[1]; j++){
4684 if(GetChamber(fcountdet[1]) == 2) fVdriftPad[(Int_t)(j*12+k)]=-TMath::Abs(fVdriftCoef[2]);
4685 if(GetChamber(fcountdet[1]) != 2) fVdriftPad[(Int_t)(j*16+k)]=-TMath::Abs(fVdriftCoef[2]);
4686 }
4687 }
4688 //end of one detector
4689 if((idect == (fcount[1]-1)) && (fDebug != 2)) FilltreeVdrift((Int_t) fcountdet[1]);
4690
4691
4692 //T0************************************
4693 //Fill the tree if end of a detector. The pointer to the branch stays with the default value 1.5!!!*******
4694 //pointer to the branch
4695 for(Int_t k = frowmin[1]; k < frowmax[1]; k++){
4696 for(Int_t j = fcolmin[1]; j < fcolmax[1]; j++){
4697 if(GetChamber(fcountdet[1]) == 2) fT0Pad[(Int_t)(j*12+k)]=-TMath::Abs(fT0Coef[2]);
4698 if(GetChamber(fcountdet[1]) != 2) fT0Pad[(Int_t)(j*16+k)]=-TMath::Abs(fT0Coef[2]);
4699 }
4700 }
4701 //end of one detector
4702 if((idect == (fcount[1]-1)) && (fDebug != 2)) FilltreeT0((Int_t) fcountdet[1]);
4703 }
4704
4705
4706 if((i == 2) && (fDebug != 2)){
4707
4708 CalculPRFCoefMean(fcountdet[2],(Int_t) (idect-fdect1[2]));
4709
4710 if((fDebug == 1) || (fDebug == 4)){
4711 fCoefPRF[0]->SetBinContent(idect-fdect1[2]+1,fPRFCoef[1]);
4712 }
4713 if(fDebug >= 3){
4714 fPRFCoef[0] = fPRFCoef[1];
4715 FillCoefPRFDB();
4716 }
4717
4718 //Fill the tree if end of a detector. The pointer to the branch stays with the default value 1.5!!!*******
4719 //pointer to the branch
4720 for(Int_t k = frowmin[2]; k < frowmax[2]; k++){
4721 for(Int_t j = fcolmin[2]; j < fcolmax[2]; j++){
4722 if((parCom->GetColMax(GetPlane(fcountdet[2])) != (j+1)) && (j != 0)){
4723 if(GetChamber(fcountdet[2]) == 2) fPRFPad[(Int_t)(j*12+k)]=-fPRFCoef[1];
4724 if(GetChamber(fcountdet[2]) != 2) fPRFPad[(Int_t)(j*16+k)]=-fPRFCoef[1];
4725 }
4726 else{
4727 if(GetChamber(fcountdet[2]) == 2) fPRFPad[(Int_t)(j*12+k)]=-((Float_t)cal->GetPRFWidth(fcountdet[2],j,k));
4728 if(GetChamber(fcountdet[2]) != 2) fPRFPad[(Int_t)(j*16+k)]=-((Float_t) cal->GetPRFWidth(fcountdet[2],j,k));
4729 }
4730 }
4731 }
4732 //end of one detector
4733 if((idect == (fcount[2]-1)) && (fDebug != 2)) FilltreePRF((Int_t) fcountdet[2]);
4734 }
4735
4736 return kTRUE;
4737
4738}
4739
4740//____________Functions for initialising the AliTRDCalibra in the code_________________________________________________________________________
4741Bool_t AliTRDCalibra::FillInfosFit(Int_t idect, Int_t i)
4742{
4743 //
4744 // Fill the coefficients found with the fits or other methods from the Fit functions
4745 //
4746
4747
4748
4749
4750 // Get the parameter object
4751 AliTRDCommonParam *parCom = AliTRDCommonParam::Instance();
4752 if (!parCom) {
4753 AliInfo("Could not get CommonParam Manager");
4754 return kFALSE;
4755 }
4756
4757 //Get cal
4758 AliTRDcalibDB *cal = AliTRDcalibDB::Instance();
4759 if (!cal) {
4760 AliInfo("Could not get calibDB");
4761 return kFALSE;
4762 }
4763
4764 if((i == 0) && (fDebug != 2)){
4765 //Fill the coefCH[2304] with fChargeCoef[0] that would be negativ only if the fit failed totally*******************************
4766 for(Int_t k = frowmin[0]; k < frowmax[0]; k++){
4767 for(Int_t j = fcolmin[0]; j < fcolmax[0]; j++){
4768 if(GetChamber(fcountdet[0]) == 2) fcoefCH[(Int_t)(j*12+k)]= fChargeCoef[0];
4769 if(GetChamber(fcountdet[0]) != 2) fcoefCH[(Int_t)(j*16+k)]= fChargeCoef[0];
4770 }
4771 }
4772 //end of one detector
4773 if((idect == (fcount[0]-1))) {
4774 FillVectorFitCH((Int_t) fcountdet[0]);
4775 //Reset
4776 for(Int_t k = 0; k < 2304; k++){
4777 fcoefCH[k] = 0.0;
4778 }
4779 }
4780 }
4781 if((i == 1) && (fDebug != 2)){
4782
4783 //PH*****************************************************************
4784 //pointer to the branch: fVdriftCoef[1] will ne negativ only if the fit failed totally
4785 for(Int_t k = frowmin[1]; k < frowmax[1]; k++){
4786 for(Int_t j = fcolmin[1]; j < fcolmax[1]; j++){
4787 if(GetChamber(fcountdet[1]) == 2) fVdriftPad[(Int_t)(j*12+k)]=fVdriftCoef[1];
4788 if(GetChamber(fcountdet[1]) != 2) fVdriftPad[(Int_t)(j*16+k)]=fVdriftCoef[1];
4789 }
4790 }
4791 //end of one detector
4792 if((idect == (fcount[1]-1)) && (fDebug != 2)) FilltreeVdrift((Int_t) fcountdet[1]);
4793
4794
4795
4796
4797 //T0*****************************************************************8
4798 //pointer to the branch: fT0Coef[1] will ne negativ only if the fit failed totally
4799 for(Int_t k = frowmin[1]; k < frowmax[1]; k++){
4800 for(Int_t j = fcolmin[1]; j < fcolmax[1]; j++){
4801 if(GetChamber(fcountdet[1]) == 2) fT0Pad[(Int_t)(j*12+k)]=fT0Coef[1];
4802 if(GetChamber(fcountdet[1]) != 2) fT0Pad[(Int_t)(j*16+k)]=fT0Coef[1];
4803 }
4804 }
4805 //end of one detector
4806 if((idect == (fcount[1]-1)) && (fDebug != 2)) FilltreeT0((Int_t) fcountdet[1]);
4807
4808 }
4809 if((i == 2) && (fDebug != 2)){
4810 //pointer to the branch
4811 for(Int_t k = frowmin[2]; k < frowmax[2]; k++){
4812 for(Int_t j = fcolmin[2]; j < fcolmax[2]; j++){
4813 if((parCom->GetColMax(GetPlane(fcountdet[2])) != (j+1)) && (j != 0) && (parCom->GetRowMax(GetPlane(fcountdet[2]), GetChamber(fcountdet[2]),GetSector(fcountdet[2])) != (k+1)) && (k != 0)){
4814 if(GetChamber(fcountdet[2]) == 2) fPRFPad[(Int_t)(j*12+k)]=fPRFCoef[0];
4815 if(GetChamber(fcountdet[2]) != 2) fPRFPad[(Int_t)(j*16+k)]=fPRFCoef[0];
4816
4817 }
4818 else{
4819 if(GetChamber(fcountdet[2]) == 2) fPRFPad[(Int_t)(j*12+k)]=(Float_t) cal->GetPRFWidth(fcountdet[2],j,k);
4820 if(GetChamber(fcountdet[2]) != 2) fPRFPad[(Int_t)(j*16+k)]=(Float_t) cal->GetPRFWidth(fcountdet[2],j,k);
4821 }
4822 }
4823 }
4824 //end of one detector
4825 if((idect == (fcount[2]-1)) && (fDebug != 2)) FilltreePRF((Int_t) fcountdet[2]);
4826 }
4827 return kTRUE;
4828
4829}
4830//____________Functions for initialising the AliTRDCalibra in the code_________________________________________________________________________
4831
4832Bool_t AliTRDCalibra::WriteFitInfos(Int_t i)
4833{
4834 //
4835 // In the case the user wants to write a file with a tree of the found coefficients for the calibration before putting them in the database
4836 //
4837
4838
4839
4840 TFile *fout = TFile::Open(fWriteNameCoef,"UPDATE");
4841 //Check if the file could be opened
4842 if (!fout || !fout->IsOpen()) {
4843 AliInfo("No File found!");
4844 return kFALSE;
4845 }
4846 if((i == 0) && (fDebug != 2)){
4847 //The error stuff
4848 if((fDebug == 1) || (fDebug == 4)) WriteCH(fout);
4849 //The DB stuff
4850 if((fDebug == 4) || (fDebug == 3)) WriteCHDB(fout);
4851 //The tree
4852 fout->WriteTObject(fGain, fGain->GetName(), (Option_t *) "writedelete");
4853 }
4854 if((i == 1) && (fDebug != 2)){
4855 //PH********************************************
4856 //The error stuff
4857 if((fDebug == 1) || (fDebug == 4)) WritePH(fout);
4858 //The DB stuff
4859 if((fDebug == 4) || (fDebug == 3)) WritePHDB(fout);
4860 //The tree
4861 fout->WriteTObject(fVdrift, fVdrift->GetName(), (Option_t *) "writedelete");
4862 //T0********************************************
4863 //The error stuff
4864 if((fDebug == 1) || (fDebug == 4)) WriteT0(fout);
4865 //The DB stuff
4866 if((fDebug == 4) || (fDebug == 3)) WriteT0DB(fout);
4867 //The tree
4868 fout->WriteTObject(fT0, fT0->GetName(), (Option_t *) "writedelete");
4869 }
4870 if((i == 2) && (fDebug != 2)){
4871 //The error stuff
4872 if((fDebug == 1) || (fDebug == 4)) WritePRF(fout);
4873 //The DB stuff
4874 if((fDebug == 4) || (fDebug == 3)) WritePRFDB(fout);
4875 //The tree
4876 fout->WriteTObject(fPRF, fPRF->GetName(), (Option_t *) "writedelete");
4877 }
4878 fout->Close();
4879 return kTRUE;
4880}
4881//____Fill the Error histos in case of fDebug == 1________________________________________________________________________________
4882
4883//__________________________________________________________________________________________
4884void AliTRDCalibra::ErrorPRF()
4885{
4886 //
4887 // Fill the error histos for fDebug = 1 and fDebug = 4 from the delta histos
4888 //
4889
4890 for(Int_t k= 0; k < fDeltaPRF->GetNbinsX(); k++){
4891 if(fDeltaPRF->GetBinContent(k+1) != 0.0) fErrorPRF->Fill(fDeltaPRF->GetBinContent(k+1));
4892 }
4893
4894}
4895//__________________________________________________________________________________________
4896void AliTRDCalibra::ErrorCH()
4897{
4898 //
4899 // Fill the error histos for fDebug = 1 and fDebug = 4 from the delta histos
4900 //
4901 for(Int_t k= 0; k < fDeltaCharge[0]->GetNbinsX(); k++){
4902 if(fDeltaCharge[0]->GetBinContent(k+1) != 0.0) fErrorCharge[0]->Fill(fDeltaCharge[0]->GetBinContent(k+1));
4903 }
4904 if(fMeanChargeOn){
4905 for(Int_t k= 0; k < fDeltaCharge[1]->GetNbinsX(); k++){
4906 if(fDeltaCharge[1]->GetBinContent(k+1) != 0.0) fErrorCharge[1]->Fill(fDeltaCharge[1]->GetBinContent(k+1));
4907 }
4908 }
4909 if(fFitChargeBisOn ){
4910 for(Int_t k= 0; k < fDeltaCharge[2]->GetNbinsX(); k++){
4911 if(fDeltaCharge[2]->GetBinContent(k+1) != 0.0) fErrorCharge[2]->Fill(fDeltaCharge[2]->GetBinContent(k+1));
4912 }
4913 }
4914
4915}
4916//______________________________________________________________________________________________
4917void AliTRDCalibra::ErrorPH()
4918{
4919 //
4920 // Fill the error histos for fDebug = 1 and fDebug = 4 from the delta histos
4921 //
4922 if(fFitPHOn ){
4923 for(Int_t k= 0; k < fDeltaVdrift[0]->GetNbinsX(); k++){
4924 if(fDeltaVdrift[0]->GetBinContent(k+1) != 0.0) fErrorVdrift[0]->Fill(fDeltaVdrift[0]->GetBinContent(k+1));
4925 }
4926 }
4927 for(Int_t k= 0; k < fDeltaVdrift[1]->GetNbinsX(); k++){
4928 if(fDeltaVdrift[1]->GetBinContent(k+1) != 0.0) fErrorVdrift[1]->Fill(fDeltaVdrift[1]->GetBinContent(k+1));
4929 }
4930}
4931//______________________________________________________________________________________________
4932void AliTRDCalibra::ErrorT0()
4933{
4934 //
4935 // Fill the error histos for fDebug = 1 and fDebug = 4 from the delta histos
4936 //
4937 if(fFitPHOn ){
4938 for(Int_t k= 0; k < fDeltaT0[0]->GetNbinsX(); k++){
4939 if(fDeltaT0[0]->GetBinContent(k+1) != 0.0) fErrorT0[0]->Fill(fDeltaT0[0]->GetBinContent(k+1));
4940 }
4941 }
4942 for(Int_t k= 0; k < fDeltaT0[1]->GetNbinsX(); k++){
4943 if(fDeltaT0[1]->GetBinContent(k+1) != 0.0) fErrorT0[1]->Fill(fDeltaT0[1]->GetBinContent(k+1));
4944 }
4945}
4946//_____Fill Coef DB in case of visualisation of one detector________________________________________________________________________
4947
4948//________________________________________________________________________________________
4949void AliTRDCalibra::FillCoefVdriftDB()
4950{
4951 //
4952 // Fill the histos for fDebug = 3 and fDebug = 4 to visualise the detector
4953 //
4954
4955 for(Int_t row = frowmin[1]; row < frowmax[1]; row++){
4956 for(Int_t col = fcolmin[1]; col < fcolmax[1]; col++){
4957 fCoefVdriftDB[1]->SetBinContent(row+1,col+1,TMath::Abs(fVdriftCoef[1]));
4958 if(fFitPHOn ) fCoefVdriftDB[0]->SetBinContent(row+1,col+1,TMath::Abs(fVdriftCoef[0]));
4959 }
4960 }
4961}
4962//________________________________________________________________________________________
4963void AliTRDCalibra::FillCoefT0DB()
4964{
4965 //
4966 // Fill the histos for fDebug = 3 and fDebug = 4 to visualise the detector
4967 //
4968
4969 for(Int_t row = frowmin[1]; row < frowmax[1]; row++){
4970 for(Int_t col = fcolmin[1]; col < fcolmax[1]; col++){
4971 fCoefT0DB[1]->SetBinContent(row+1,col+1,TMath::Abs(fT0Coef[1]));
4972 if(fFitPHOn ) fCoefT0DB[0]->SetBinContent(row+1,col+1,TMath::Abs(fT0Coef[0]));
4973 }
4974 }
4975}
4976//__________________________________________________________________________________________
4977void AliTRDCalibra::FillCoefChargeDB()
4978{
4979 //
4980 // Fill the histos for fDebug = 3 and fDebug = 4 to visualise the detector
4981 //
4982
4983 for(Int_t row = frowmin[0]; row < frowmax[0]; row++){
4984 for(Int_t col = fcolmin[0]; col < fcolmax[0]; col++){
4985 if(fMeanChargeOn) fCoefChargeDB[1]->SetBinContent(row+1,col+1,TMath::Abs(fChargeCoef[1]));
4986 if(fFitChargeBisOn ) fCoefChargeDB[2]->SetBinContent(row+1,col+1,TMath::Abs(fChargeCoef[2]));
4987 fCoefChargeDB[0]->SetBinContent(row+1,col+1,TMath::Abs(fChargeCoef[0]));
4988 }
4989 }
4990}
4991//__________________________________________________________________________________________
4992void AliTRDCalibra::FillCoefPRFDB()
4993{
4994 //
4995 // Fill the histos for fDebug = 3 and fDebug = 4 to visualise the detector
4996 //
4997 for(Int_t row = frowmin[2]; row < frowmax[2]; row++){
4998 for(Int_t col = fcolmin[2]; col < fcolmax[2]; col++){
4999 fCoefPRFDB->SetBinContent(row+1,col+1,fPRFCoef[0]);
5000
5001 }
5002 }
5003}
5004
5005//_________Plot histos CoefPRF....__________________________________________________________________________________________
5006
5007
5008//___________________________________________________________________________________________
5009void AliTRDCalibra::PlotCH()
5010{
5011 //
5012 // Plot the histos for fDebug = 1 and fDebug = 4 for the errors
5013 //
5014 TLatex t;
5015 t.SetTextAlign(22);
5016 t.SetTextSize(0.1);
5017 TCanvas *cch1 = new TCanvas("cch1","",50,50,600,800);
5018 cch1->cd();
5019 TLegend *legch1 = new TLegend(0.4,0.6,0.89,0.89);
5020 legch1->AddEntry(fCoefCharge[3],"f_{g} simulated","l");
5021 if(fMeanChargeOn) legch1->AddEntry(fCoefCharge[1],"f_{g} mean","p");
5022 legch1->AddEntry(fCoefCharge[0],"f_{g} fit","p");
5023 if(fFitChargeBisOn ) legch1->AddEntry(fCoefCharge[2],"f_{g} fitbis","p");
5024
5025 fCoefCharge[0]->Draw("E2");
5026 if(fMeanChargeOn) fCoefCharge[1]->Draw("E2 same");
5027 if(fFitChargeBisOn ) fCoefCharge[2]->Draw("E2 same");
5028 fCoefCharge[3]->Draw("same");
5029 legch1->Draw("same");
5030
5031
5032
5033 TCanvas *cch2 = new TCanvas("cch2","",50,50,600,800);
5034 cch2->Divide(2,1);
5035 cch2->cd(1);
5036 TLegend *legch2 = new TLegend(0.4,0.6,0.89,0.89);
5037 if(fMeanChargeOn) legch2->AddEntry(fErrorCharge[1],"f_{g} mean","l");
5038 legch2->AddEntry(fErrorCharge[0],"f_{g} fit","l");
5039 if(fFitChargeBisOn ) legch2->AddEntry(fErrorCharge[2],"f_{g} fitbis","l");
5040 fErrorCharge[0]->Draw();
5041 if(fMeanChargeOn) fErrorCharge[1]->Draw("same");
5042 if(fFitChargeBisOn ) fErrorCharge[2]->Draw("same");
5043 legch2->Draw("same");
5044 cch2->cd(2);
5045 TLegend *legch3 = new TLegend(0.4,0.6,0.89,0.89);
5046 if(fMeanChargeOn) legch3->AddEntry(fDeltaCharge[1],"mean","p");
5047 legch3->AddEntry(fDeltaCharge[0],"fit","p");
5048 if(fFitChargeBisOn ) legch3->AddEntry(fDeltaCharge[2],"fit","p");
5049 fDeltaCharge[0]->Draw("E2");
5050 if(fMeanChargeOn) fDeltaCharge[1]->Draw("E2 same");
5051 if(fFitChargeBisOn ) fDeltaCharge[2]->Draw("E2 same");
5052 legch3->Draw("same");
5053
5054}
5055//__________________________________________________________________________
5056void AliTRDCalibra::PlotPH()
5057{
5058 //
5059 // Plot the histos for fDebug = 1 and fDebug = 4 for the errors
5060 //
5061
5062 TCanvas *cph1 = new TCanvas("cph1","",50,50,600,800);
5063 cph1->cd();
5064 TLegend *legph1 = new TLegend(0.4,0.6,0.89,0.89);
5065 legph1->AddEntry(fCoefVdrift[2],"v_{real} simulated","l");
5066 legph1->AddEntry(fCoefVdrift[1],"v_{sm} slope 1 method","p");
5067
5068 if(fFitPHOn ) legph1->AddEntry(fCoefVdrift[0],"v_{fit} fit","p");
5069 fCoefVdrift[1]->Draw("E2");
5070 fCoefVdrift[2]->Draw("same");
5071 if(fFitPHOn )fCoefVdrift[0]->Draw("E2 same");
5072 legph1->Draw("same");
5073
5074
5075
5076
5077 TCanvas *cph2 = new TCanvas("cph2","",50,50,600,800);
5078 cph2->Divide(2,1);
5079 cph2->cd(1);
5080 TLegend *legph2 = new TLegend(0.4,0.6,0.89,0.89);
5081 legph2->AddEntry(fErrorVdrift[1],"v_{sm} slope 1 method","l");
5082 if(fFitPHOn ) legph2->AddEntry(fErrorVdrift[0],"v_{fit} fit","l");
5083 fErrorVdrift[1]->Draw();
5084 if(fFitPHOn ) fErrorVdrift[0]->Draw("l,same");
5085 legph2->Draw("same");
5086 cph2->cd(2);
5087 TLegend *legph3 = new TLegend(0.4,0.6,0.89,0.89);
5088 legph3->AddEntry(fDeltaVdrift[1],"v_{sm} slope 1 method","p");
5089 if(fFitPHOn ) legph3->AddEntry(fDeltaVdrift[0],"v_{fit} fit","p");
5090 fDeltaVdrift[1]->Draw("E2");
5091 if(fFitPHOn ) fDeltaVdrift[0]->Draw("E2 same");
5092 legph3->Draw("same");
5093}
5094//__________________________________________________________________________
5095void AliTRDCalibra::PlotT0()
5096{
5097 //
5098 // Plot the histos for fDebug = 1 and fDebug = 4 for the errors
5099 //
5100
5101 TCanvas *ct01 = new TCanvas("ct01","",50,50,600,800);
5102 ct01->cd();
5103 TLegend *legt01 = new TLegend(0.4,0.6,0.89,0.89);
5104 legt01->AddEntry(fCoefT0[2],"t0 simulated","l");
5105 legt01->AddEntry(fCoefT0[1],"t0 slope 1 method","p");
5106
5107 if(fFitPHOn ) legt01->AddEntry(fCoefT0[0],"t0 fit","p");
5108 fCoefT0[1]->Draw("E2");
5109 fCoefT0[2]->Draw("same");
5110 if(fFitPHOn )fCoefT0[0]->Draw("E2 same");
5111 legt01->Draw("same");
5112
5113
5114 TCanvas *ct02 = new TCanvas("ct02","",50,50,600,800);
5115 ct02->Divide(2,1);
5116 ct02->cd(1);
5117 TLegend *legt02 = new TLegend(0.4,0.6,0.89,0.89);
5118 legt02->AddEntry(fErrorT0[1],"t0 slope 1 method","l");
5119 if(fFitPHOn ) legt02->AddEntry(fErrorT0[0],"t0 fit","l");
5120 fErrorT0[1]->Draw();
5121 if(fFitPHOn ) fErrorT0[0]->Draw("l,same");
5122 legt02->Draw("same");
5123 ct02->cd(2);
5124 TLegend *legt03 = new TLegend(0.4,0.6,0.89,0.89);
5125 legt03->AddEntry(fDeltaT0[1],"t0 slope 1 method","p");
5126 if(fFitPHOn ) legt03->AddEntry(fDeltaT0[0],"t0 fit","p");
5127 fDeltaT0[1]->Draw("E2");
5128 if(fFitPHOn ) fDeltaT0[0]->Draw("E2 same");
5129 legt03->Draw("same");
5130}
5131
5132//___________________________________________________________________________
5133void AliTRDCalibra::PlotPRF()
5134{
5135 //
5136 // Plot the histos for fDebug = 1 and fDebug = 4 for the errors
5137 //
5138
5139 TCanvas *cprf1 = new TCanvas("cprf1","",50,50,600,800);
5140 cprf1->cd();
5141 TLegend *legprf1 = new TLegend(0.4,0.6,0.89,0.89);
5142 legprf1->AddEntry(fCoefPRF[1],"#sigma_{real} simulated","l");
5143 legprf1->AddEntry(fCoefPRF[0],"#sigma_{fit} reconstructed","p");
5144
5145 fCoefPRF[0]->Draw("E2");
5146 fCoefPRF[1]->Draw("same");
5147 legprf1->Draw("same");
5148
5149
5150
5151
5152 TCanvas *cprf2 = new TCanvas("cprf2","",50,50,600,800);
5153 cprf2->Divide(2,1);
5154 cprf2->cd(1);
5155 TLegend *legprf2 = new TLegend(0.4,0.6,0.89,0.89);
5156 legprf2->AddEntry(fErrorPRF,"#sigma_{fit} reconstructed","l");
5157 fErrorPRF->Draw("");
5158 legprf2->Draw("same");
5159 cprf2->cd(2);
5160 TLegend *legprf3 = new TLegend(0.4,0.6,0.89,0.89);
5161 legprf3->AddEntry(fDeltaPRF,"#sigma_{fit} reconstructed","p");
5162 fDeltaPRF->Draw("E2");
5163 legprf3->Draw("same");
5164
5165}
5166
5167//___________Plot histos DB ___________________________________________________________________________________________________
5168//___________________________________________________________________________________________
5169void AliTRDCalibra::PlotCHDB()
5170{
5171 //
5172 // Plot the histos for fDebug = 3 and fDebug = 4 to visualise the detector
5173 //
5174
5175 TCanvas *cchdb = new TCanvas("cchdb","",50,50,600,800);
5176 if((fFitChargeBisOn) && (fMeanChargeOn)){
5177 cchdb->Divide(3,1);
5178 cchdb->cd(1);
5179 fCoefChargeDB[0]->Draw("LEGO");
5180 cchdb->cd(2);
5181 fCoefChargeDB[1]->Draw("LEGO");
5182 cchdb->cd(3);
5183 fCoefChargeDB[2]->Draw("LEGO");
5184 }
5185 if((!fFitChargeBisOn) && (fMeanChargeOn)){
5186 cchdb->Divide(2,1);
5187 cchdb->cd(1);
5188 fCoefChargeDB[0]->Draw("LEGO");
5189 cchdb->cd(2);
5190 fCoefChargeDB[1]->Draw("LEGO");
5191 }
5192 else{
5193 cchdb->cd();
5194 fCoefChargeDB[0]->Draw("LEGO");
5195 }
5196
5197}
5198//_______________________________________________________________________________________
5199
5200void AliTRDCalibra::PlotPHDB()
5201{
5202 //
5203 // Plot the histos for fDebug = 3 and fDebug = 4 to visualise the detector
5204 //
5205
5206 TCanvas *cphdb = new TCanvas("cphdb","",50,50,600,800);
5207 if(fFitPHOn ){
5208 cphdb->Divide(2,1);
5209 cphdb->cd(1);
5210 fCoefVdriftDB[0]->Draw("LEGO");
5211 cphdb->cd(2);
5212 fCoefVdriftDB[1]->Draw("LEGO");
5213 }
5214 else{
5215 cphdb->cd();
5216 fCoefVdriftDB[1]->Draw("LEGO");
5217 }
5218}
5219//_______________________________________________________________________________________
5220
5221void AliTRDCalibra::PlotT0DB()
5222{
5223 //
5224 // Plot the histos for fDebug = 3 and fDebug = 4 to visualise the detector
5225 //
5226
5227 TCanvas *ct0db = new TCanvas("ct0db","",50,50,600,800);
5228 if(fFitPHOn ){
5229 ct0db->Divide(2,1);
5230 ct0db->cd(1);
5231 fCoefT0DB[0]->Draw("LEGO");
5232 ct0db->cd(2);
5233 fCoefT0DB[1]->Draw("LEGO");
5234 }
5235 else{
5236 ct0db->cd();
5237 fCoefT0DB[1]->Draw("LEGO");
5238 }
5239}
5240//_______________________________________________________________________________________
5241
5242void AliTRDCalibra::PlotPRFDB()
5243{
5244 //
5245 // Plot the histos for fDebug = 3 and fDebug = 4 to visualise the detector
5246 //
5247
5248 TCanvas *cprfdb = new TCanvas("cprfdb","",50,50,600,800);
5249 cprfdb->cd();
5250 fCoefPRFDB->Draw("LEGO");
5251}
5252
5253//______________Write histos Coef________________________________________________________________________________________________________
5254
5255//________________________________________________________________________________
5256void AliTRDCalibra::WriteCH(TFile *fout)
5257{
5258 //
5259 // If wanted, write the debug histos for fDebug = 1 and fDebug = 4
5260 //
5261
5262 fout->WriteTObject(fCoefCharge[0], fCoefCharge[0]->GetName(),(Option_t *)"OverWrite");
5263 if(fMeanChargeOn) fout->WriteTObject(fCoefCharge[1], fCoefCharge[1]->GetName(),(Option_t *)"OverWrite");
5264 if(fFitChargeBisOn ) fout->WriteTObject(fCoefCharge[2], fCoefCharge[2]->GetName(),(Option_t *)"OverWrite");
5265
5266 fout->WriteTObject(fCoefCharge[3], fCoefCharge[3]->GetName(),(Option_t *)"OverWrite");
5267
5268 fout->WriteTObject(fDeltaCharge[0], fDeltaCharge[0]->GetName(),(Option_t *)"OverWrite");
5269 if(fMeanChargeOn) fout->WriteTObject(fDeltaCharge[1], fDeltaCharge[1]->GetName(),(Option_t *)"OverWrite");
5270 if(fFitChargeBisOn ) fout->WriteTObject(fDeltaCharge[2], fDeltaCharge[2]->GetName(),(Option_t *)"OverWrite");
5271
5272
5273 fout->WriteTObject(fErrorCharge[0], fErrorCharge[0]->GetName(),(Option_t *)"OverWrite");
5274 if(fMeanChargeOn) fout->WriteTObject(fErrorCharge[1], fErrorCharge[1]->GetName(),(Option_t *)"OverWrite");
5275 if(fFitChargeBisOn ) fout->WriteTObject(fErrorCharge[2], fErrorCharge[2]->GetName(),(Option_t *)"OverWrite");
5276
5277
5278}
5279//________________________________________________________________________________
5280void AliTRDCalibra::WritePH(TFile *fout)
5281{
5282 //
5283 // If wanted, write the debug histos for fDebug = 1 and fDebug = 4
5284 //
5285
5286 if (fFitPHOn )fout->WriteTObject(fCoefVdrift[0], fCoefVdrift[0]->GetName(),(Option_t *)"OverWrite");
5287 fout->WriteTObject(fCoefVdrift[1], fCoefVdrift[1]->GetName(),(Option_t *)"OverWrite");
5288 fout->WriteTObject(fCoefVdrift[2], fCoefVdrift[2]->GetName(),(Option_t *)"OverWrite");
5289
5290
5291 if(fFitPHOn ) fout->WriteTObject(fDeltaVdrift[0], fDeltaVdrift[0]->GetName(),(Option_t *)"OverWrite");
5292 fout->WriteTObject(fDeltaVdrift[1], fDeltaVdrift[1]->GetName(),(Option_t *)"OverWrite");
5293
5294
5295 if(fFitPHOn ) fout->WriteTObject(fErrorVdrift[0], fErrorVdrift[0]->GetName(),(Option_t *)"OverWrite");
5296 fout->WriteTObject(fErrorVdrift[1], fErrorVdrift[1]->GetName(),(Option_t *)"OverWrite");
5297
5298
5299}
5300//________________________________________________________________________________
5301void AliTRDCalibra::WriteT0(TFile *fout)
5302{
5303 //
5304 // If wanted, write the debug histos for fDebug = 1 and fDebug = 4
5305 //
5306
5307 if (fFitPHOn )fout->WriteTObject(fCoefT0[0], fCoefT0[0]->GetName(),(Option_t *)"OverWrite");
5308 fout->WriteTObject(fCoefT0[1], fCoefT0[1]->GetName(),(Option_t *)"OverWrite");
5309 fout->WriteTObject(fCoefT0[2], fCoefT0[2]->GetName(),(Option_t *)"OverWrite");
5310
5311
5312 if(fFitPHOn ) fout->WriteTObject(fDeltaT0[0], fDeltaT0[0]->GetName(),(Option_t *)"OverWrite");
5313 fout->WriteTObject(fDeltaT0[1], fDeltaT0[1]->GetName(),(Option_t *)"OverWrite");
5314
5315
5316 if(fFitPHOn ) fout->WriteTObject(fErrorT0[0], fErrorT0[0]->GetName(),(Option_t *)"OverWrite");
5317 fout->WriteTObject(fErrorT0[1], fErrorT0[1]->GetName(),(Option_t *)"OverWrite");
5318
5319
5320}
5321//________________________________________________________________________________
5322void AliTRDCalibra::WritePRF(TFile *fout)
5323{
5324 //
5325 // If wanted, write the debug histos for fDebug = 1 and fDebug = 4
5326 //
5327
5328 fout->WriteTObject(fCoefPRF[0], fCoefPRF[0]->GetName(),(Option_t *)"OverWrite");
5329
5330 fout->WriteTObject(fCoefPRF[1], fCoefPRF[1]->GetName(),(Option_t *)"OverWrite");
5331
5332 fout->WriteTObject(fDeltaPRF, fDeltaPRF->GetName(),(Option_t *)"OverWrite");
5333
5334 fout->WriteTObject(fErrorPRF, fErrorPRF->GetName(),(Option_t *)"OverWrite");
5335}
5336
5337
5338//_________________________Write DB Histos____________________________________________________________________________________
5339
5340
5341//________________________________________________________________________________
5342void AliTRDCalibra::WriteCHDB(TFile *fout)
5343{
5344 //
5345 // If wanted, write the debug histos for fDebug = 3 and fDebug = 4
5346 //
5347
5348 fout->WriteTObject(fCoefChargeDB[0], fCoefChargeDB[0]->GetName(),(Option_t *)"OverWrite");
5349 if(fMeanChargeOn) fout->WriteTObject(fCoefChargeDB[1], fCoefChargeDB[1]->GetName(),(Option_t *)"OverWrite");
5350 if(fFitChargeBisOn ) fout->WriteTObject(fCoefChargeDB[2], fCoefChargeDB[2]->GetName(),(Option_t *)"OverWrite");
5351
5352
5353}
5354//________________________________________________________________________________
5355void AliTRDCalibra::WritePHDB(TFile *fout)
5356{
5357 //
5358 // If wanted, write the debug histos for fDebug = 3 and fDebug = 4
5359 //
5360
5361 if (fFitPHOn )fout->WriteTObject(fCoefVdriftDB[0], fCoefVdriftDB[0]->GetName(),(Option_t *)"OverWrite");
5362 fout->WriteTObject(fCoefVdriftDB[1], fCoefVdriftDB[1]->GetName(),(Option_t *)"OverWrite");
5363
5364
5365
5366}
5367//________________________________________________________________________________
5368void AliTRDCalibra::WriteT0DB(TFile *fout)
5369{
5370 //
5371 // If wanted, write the debug histos for fDebug = 3 and fDebug = 4
5372 //
5373
5374 if (fFitPHOn )fout->WriteTObject(fCoefT0DB[0], fCoefT0DB[0]->GetName(),(Option_t *)"OverWrite");
5375 fout->WriteTObject(fCoefT0DB[1], fCoefT0DB[1]->GetName(),(Option_t *)"OverWrite");
5376
5377
5378
5379}
5380//________________________________________________________________________________
5381void AliTRDCalibra::WritePRFDB(TFile *fout)
5382{
5383 //
5384 // If wanted, write the debug histos for fDebug = 3 and fDebug = 4
5385 //
5386
5387 fout->WriteTObject(fCoefPRFDB, fCoefPRFDB->GetName(),(Option_t *)"OverWrite");
5388
5389}
5390
5391
5392//_______________Calcul Coef Mean__________________________________________________________________________________________________
5393
5394
5395//__________________________________________________________________________________________
5396Bool_t AliTRDCalibra::CalculT0CoefMean(Int_t Dect, Int_t idect)
5397{
5398 //
5399 // For the detector Dect calcul the mean time 0 for the calibration group idect from the choosen database
5400 //
5401
5402 AliTRDcalibDB *cal = AliTRDcalibDB::Instance();
5403 if (!cal) {
5404 AliInfo("Could not get calibDB Manager");
5405 return kFALSE;
5406 }
5407
5408 fT0Coef[2] = 0.0;
5409
5410 if(fDebug != 2){
5411
5412 for(Int_t row = frowmin[1]; row < frowmax[1]; row++){
5413 for(Int_t col = fcolmin[1]; col< fcolmax[1]; col++){
5414 //groups of pads
5415 if((fNz[1] > 0) && (fNrphi[1] > 0)) {
5416 fT0Coef[2] += (Float_t) cal->GetT0(Dect,col,row);
5417 }
5418 //per detectors
5419 else fT0Coef[2] += (Float_t) cal->GetT0Average(Dect);
5420 }
5421 }
5422 fT0Coef[2] = fT0Coef[2]/((fcolmax[1]-fcolmin[1])*(frowmax[1]-frowmin[1]));
5423 if((fDebug == 1) || (fDebug == 4)) fCoefT0[2]->SetBinContent(idect+1,fT0Coef[2]);
5424 }
5425 return kTRUE;
5426
5427}
5428//__________________________________________________________________________________________
5429Bool_t AliTRDCalibra::CalculChargeCoefMean(Int_t Dect, Int_t idect, Bool_t vrai)
5430{
5431 //
5432 // For the detector Dect calcul the mean gain factor for the calibration group idect from the choosen database
5433 //
5434
5435
5436 AliTRDcalibDB *cal = AliTRDcalibDB::Instance();
5437 if (!cal) {
5438 AliInfo("Could not get calibDB Manager");
5439 return kFALSE;
5440 }
5441 AliTRDCommonParam *parCom = AliTRDCommonParam::Instance();
5442 if (!parCom) {
5443 AliInfo("Could not get CommonParam Manager");
5444 return kFALSE;
5445 }
5446
5447 fChargeCoef[3] = 0.0;
5448 if(fDebug != 2){
5449
5450 for(Int_t row = frowmin[0]; row < frowmax[0]; row++){
5451 for(Int_t col = fcolmin[0]; col< fcolmax[0]; col++){
5452 //groups of pads
5453 if((fNz[0] > 0) || (fNrphi[0] > 0)) {
5454 fChargeCoef[3] += (Float_t) cal->GetGainFactor(Dect,col,row);
5455 if(vrai) fScalefitfactor += (Float_t) cal->GetGainFactor(Dect,col,row);
5456 }
5457 //per detectors
5458 else {
5459 fChargeCoef[3] += (Float_t) cal->GetGainFactorAverage(Dect);
5460 if(vrai) fScalefitfactor += ((Float_t) cal->GetGainFactorAverage(Dect));
5461 }
5462 }
5463 }
5464 fChargeCoef[3] = fChargeCoef[3]/((fcolmax[0]-fcolmin[0])*(frowmax[0]-frowmin[0]));
5465 if((fDebug == 1) || (fDebug == 4)) fCoefCharge[3]->SetBinContent(idect+1,fChargeCoef[3]);
5466 }
5467 return kTRUE;
5468
5469
5470
5471}
5472//__________________________________________________________________________________________
5473Bool_t AliTRDCalibra::CalculPRFCoefMean(Int_t Dect, Int_t idect)
5474{
5475 //
5476 // For the detector Dect calcul the mean sigma of pad response function for the calibration group idect from the choosen database
5477 //
5478
5479
5480 AliTRDcalibDB *cal = AliTRDcalibDB::Instance();
5481 if (!cal) {
5482 AliInfo("Could not get calibDB Manager");
5483 return kFALSE;
5484 }
5485
5486 AliTRDCommonParam *parCom = AliTRDCommonParam::Instance();
5487 if (!parCom) {
5488 AliInfo("Could not get CommonParam Manager");
5489 return kFALSE;
5490 }
5491
5492
5493 fPRFCoef[1] = 0.0;
5494 Int_t cot = 0;
5495 if(fDebug != 2){
5496
5497 for(Int_t row = frowmin[2]; row < frowmax[2]; row++){
5498 for(Int_t col = fcolmin[2]; col< fcolmax[2]; col++){
5499 if((parCom->GetColMax(GetPlane(Dect)) != (col+1)) && (col != 0)){
5500 cot++;
5501 fPRFCoef[1] += (Float_t) cal->GetPRFWidth(Dect,col,row);
5502 }
5503 }
5504 }
5505 if(cot > 0){
5506 fPRFCoef[1] = fPRFCoef[1]/cot;
5507 if((fDebug == 1) ||(fDebug == 4)) fCoefPRF[1]->SetBinContent(idect+1,fPRFCoef[1]);
5508 }
5509 else{
5510 if((fDebug == 1) ||(fDebug == 4)) fCoefPRF[1]->SetBinContent(idect+1, cal->GetPRFWidth(Dect,fcolmin[2],frowmin[2]));
5511 }
5512 }
5513 return kTRUE;
5514
5515}
5516//__________________________________________________________________________________________
5517Bool_t AliTRDCalibra::CalculVdriftCoefMean(Int_t Dect, Int_t idect)
5518{
5519 //
5520 // For the detector Dect calcul the mean drift velocity for the calibration group idect from the choosen database
5521 //
5522
5523
5524 AliTRDcalibDB *cal = AliTRDcalibDB::Instance();
5525 if (!cal) {
5526 AliInfo("Could not get calibDB Manager");
5527 return kFALSE;
5528 }
5529
5530
5531 fVdriftCoef[2] = 0.0;
5532
5533 if(fDebug != 2){
5534 for(Int_t row = frowmin[1]; row < frowmax[1]; row++){
5535 for(Int_t col = fcolmin[1]; col< fcolmax[1]; col++){
5536 //groups of pads
5537 if((fNz[1] > 0) || (fNrphi[1] > 0)) {
5538 fVdriftCoef[2] += (Float_t) cal->GetVdrift(Dect,col,row);
5539 }
5540 //per detectors
5541 else fVdriftCoef[2] += (Float_t) cal->GetVdriftAverage(Dect);
5542 }
5543 }
5544 fVdriftCoef[2] = fVdriftCoef[2]/((fcolmax[1]-fcolmin[1])*(frowmax[1]-frowmin[1]));
5545 if((fDebug == 1) || (fDebug == 4)) fCoefVdrift[2]->SetBinContent(idect+1,fVdriftCoef[2]);
5546 }
5547 return kTRUE;
5548
5549}
5550
5551//_________Pad group calibration mode____________________________________________________________________________________________________________
5552//________________________________________________________________________________________
5553void AliTRDCalibra::ReconstructionRowPadGroup(Int_t idect, Int_t i)
5554{
5555 //
5556 // For the calibration group idect in a detector calculate the first and last row pad and col pad.
5557 // The pads in the interval will have the same calibrated coefficients
5558 //
5559
5560
5561 Int_t posc = -1;
5562 Int_t posr = -1;
5563 frowmin[i] = -1;
5564 frowmax[i] = -1;
5565 fcolmin[i] = -1;
5566 fcolmax[i] = -1;
5567
5568 if(fNfragz[i]!= 0) posc = (Int_t) idect/fNfragz[i];
5569 if(fNfragrphi[i] != 0) posr = (Int_t) idect%fNfragz[i];
5570 frowmin[i] = posr*fNnz[i];
5571 frowmax[i] = (posr+1)*fNnz[i];
5572 fcolmin[i] = posc*fNnrphi[i];
5573 fcolmax[i] = (posc+1)*fNnrphi[i];
5574}
5575
5576//_____________________________________________________________________________
5577void AliTRDCalibra::CalculXBins(Int_t idect, Int_t i)
5578{
5579 //
5580 // For the detector idect calcul the first Xbins
5581 //
5582
5583
5584 fXbins[i] = 0;
5585 if(fDebug == 4) {
5586 AliInfo(Form("detector: %d", idect));
5587 }
5588
5589 //In which sector?
5590 Int_t sector = GetSector(idect);
5591 fXbins[i] += sector*(6*fdetChamb2[i]+6*4*fdetChamb0[i]);
5592
5593 //In which chamber?
5594 Int_t chamber = GetChamber(idect);
5595 Int_t kc = 0;
5596 while(kc < chamber){
5597 if(kc == 2) fXbins[i] += 6*fdetChamb2[i];
5598 else fXbins[i] += 6*fdetChamb0[i];
5599 kc ++;
5600 }
5601
5602 //In wich plane?
5603 Int_t plane = GetPlane(idect);
5604 if(chamber == 2) fXbins[i] += plane*fdetChamb2[i];
5605 else fXbins[i] += plane*fdetChamb0[i];
5606
5607}
5608//_____________________________________________________________________________
5609Int_t AliTRDCalibra::SearchInVector(Int_t group, Int_t i)
5610{
5611 //
5612 // Search if the calibration group "group" has already been initialised by a previous track in the vector
5613 //
5614
5615
5616
5617 if(i == 0){
5618 for(Int_t k = 0; k < (Int_t) fPlaCH.size(); k++){
5619 if(fPlaCH[k] == group) return k;
5620 }
5621 return -1;
5622 }
5623
5624 if(i == 1){
5625 for(Int_t k = 0; k < (Int_t) fPlaPH.size(); k++){
5626 if(fPlaPH[k] == group) return k;
5627 }
5628 return -1;
5629 }
5630
5631 if(i == 2){
5632 for(Int_t k = 0; k < (Int_t) fPlaPRF.size(); k++){
5633 if(fPlaPRF[k] == group) return k;
5634 }
5635 return -1;
5636 }
5637 return -1;
5638}
5639//_____________________________________________________________________________
5640Int_t AliTRDCalibra::SearchInTreeVector(std::vector<Int_t> vectorplace, Int_t group)
5641{
5642 //
5643 // Search if the calibration group "group" is present in the tree
5644 //
5645
5646 for(Int_t k = 0; k < (Int_t) vectorplace.size(); k++){
5647 if(vectorplace[k] == group) return k;
5648 }
5649 return -1;
5650
5651}
5652//_____________________________________________________________________________
5653Int_t AliTRDCalibra::SearchBin(Float_t value, Int_t i)
5654{
5655 //
5656 // Search the bin
5657 //
5658
5659 Int_t reponse = 0;
5660 Int_t fbinmin = 0;
5661 Int_t fbinmax = (Int_t) value;
5662 Int_t fNumberOfBin = -1;
5663
5664 //charge
5665 if(i == 0){
5666 fbinmax = 300;
5667 fbinmin = 0;
5668 fNumberOfBin = fNumberBinCharge;
5669 }
5670
5671 //PRF
5672 if(i == 2){
5673 fbinmax = 1;
5674 fbinmin = -1;
5675 fNumberOfBin = fNumberBinPRF;
5676 }
5677
5678 //return -1 if out
5679 if((value >= fbinmax) || (value < fbinmin)) return -1;
5680 //sinon
5681 else{
5682 reponse = (Int_t)((fNumberOfBin*(value-fbinmin))/(fbinmax-fbinmin));
5683 }
5684
5685 return reponse;
5686
5687}
5688//_____________________________________________________________________________
5689Bool_t AliTRDCalibra::UpdateVectorCH(Int_t group, Float_t value)
5690{
5691 //
5692 // Fill the vector if a new calibration group "group" or update the values of the calibration group "group" if already here
5693 //
5694
5695
5696 //Search bin
5697 Int_t bin = SearchBin(value,0);
5698 //out
5699 if((bin < 0) || (bin >= fNumberBinCharge)) return kFALSE;
5700 //Search place
5701 Int_t place = SearchInVector(group,0);
5702 //new group
5703 if(place == -1){
5704 fPlaCH.push_back(group);
5705 //Variable
5706 TCTInfo *fCHInfo = new TCTInfo();
5707 fCHInfo->fentries = new UShort_t[fNumberBinCharge];
5708 //Initialise first
5709 for(Int_t k = 0; k < fNumberBinCharge; k++){
5710 fCHInfo->fentries[k] = 0;
5711 }
5712 //Add the value
5713 fCHInfo->fentries[bin]= 1;
5714
5715 //Set in the vector
5716 fVectorCH.push_back(fCHInfo);
5717
5718
5719 }
5720 //group already exits
5721 else{
5722 //Variable
5723 TCTInfo *fCHInfo = new TCTInfo();
5724 fCHInfo->fentries = new UShort_t[fNumberBinCharge];
5725 //retrieve
5726 fCHInfo = fVectorCH[place];
5727 //add
5728 fCHInfo->fentries[bin]++;
5729 //update the vector
5730 std::vector<TCTInfo *>::iterator it = fVectorCH.begin()+place;
5731 fVectorCH.erase(it);
5732 fVectorCH.insert(it,fCHInfo);
5733
5734
5735 }
5736
5737 return kTRUE;
5738}
5739
5740//_____________________________________________________________________________
5741Bool_t AliTRDCalibra::UpdateVectorPRF(Int_t group, Float_t x, Float_t y)
5742{
5743 //
5744 // Fill the vector if a new calibration group "group" or update the values of the calibration group "group" if already here
5745 //
5746
5747 //Search bin
5748 Int_t bin = SearchBin(x,2);
5749 //out
5750 if((bin < 0) || (bin >= fNumberBinPRF)) return kFALSE;
5751 //Search place
5752 Int_t place = SearchInVector(group,2);
5753 //new group
5754 if(place == -1){
5755 fPlaPRF.push_back(group);
5756 TPInfo *fPRFInfo = new TPInfo();
5757 fPRFInfo->fsum = new Float_t[fNumberBinPRF];
5758 fPRFInfo->fsumsquare = new Float_t[fNumberBinPRF];
5759 fPRFInfo->fentries = new UShort_t[fNumberBinPRF];
5760 //Initialise first
5761 for(Int_t k = 0; k < fNumberBinPRF; k++){
5762 fPRFInfo->fsum[k] = 0.0;
5763 fPRFInfo->fsumsquare[k] = 0.0;
5764 fPRFInfo->fentries[k] = 0;
5765 }
5766 //Add the value
5767 fPRFInfo->fsum[bin]+= y;
5768 fPRFInfo->fsumsquare[bin] += y*y;
5769 fPRFInfo->fentries[bin]++;
5770
5771 //Set in the vector
5772 fVectorPRF.push_back(fPRFInfo);
5773
5774 }
5775 //group already exits
5776 else{
5777 TPInfo *fPRFInfo = new TPInfo();
5778 fPRFInfo->fsum = new Float_t[fNumberBinPRF];
5779 fPRFInfo->fsumsquare = new Float_t[fNumberBinPRF];
5780 fPRFInfo->fentries = new UShort_t[fNumberBinPRF];
5781 //retrieve
5782 fPRFInfo = fVectorPRF[place];
5783 //add
5784 Double_t calcul = (((Double_t)fPRFInfo->fentries[bin])*((Double_t)fPRFInfo->fsum[bin])+(Double_t)y)/(((Double_t)fPRFInfo->fentries[bin])+1);
5785 fPRFInfo->fsum[bin] = (Float_t) calcul;
5786 Double_t calculsquare = (((Double_t)fPRFInfo->fsumsquare[bin])*((Double_t)fPRFInfo->fentries[bin])+((Double_t)y)*((Double_t)y))/(((Double_t)fPRFInfo->fentries[bin])+1);
5787 fPRFInfo->fsumsquare[bin] = (Float_t)calculsquare;
5788 fPRFInfo->fentries[bin]++;
5789
5790 //update the vector
5791 std::vector<TPInfo *>::iterator it = fVectorPRF.begin()+place;
5792 fVectorPRF.erase(it);
5793 fVectorPRF.insert(it,fPRFInfo);
5794
5795 }
5796
5797 return kTRUE;
5798}
5799
5800//_____________________________________________________________________________
5801Bool_t AliTRDCalibra::UpdateVectorPH(Int_t group, Int_t time, Float_t value)
5802{
5803 //
5804 // Fill the vector if a new calibration group "group" or update the values of the calibration group "group" if already here
5805 //
5806
5807 //Search bin
5808 Int_t bin = time;
5809 //out
5810 if((bin < 0) || (bin >= fTimeMax)) return kFALSE;
5811 //Search place
5812 Int_t place = SearchInVector(group,1);
5813 //new group
5814 if(place == -1){
5815 fPlaPH.push_back(group);
5816 TPInfo *fPHInfo = new TPInfo();
5817 fPHInfo->fsum = new Float_t[fTimeMax];
5818 fPHInfo->fsumsquare = new Float_t[fTimeMax];
5819 fPHInfo->fentries = new UShort_t[fTimeMax];
5820 //Initialise first
5821 for(Int_t k = 0; k < fTimeMax; k++){
5822 fPHInfo->fsum[k] = 0.0;
5823 fPHInfo->fsumsquare[k] = 0.0;
5824 fPHInfo->fentries[k] = 0;
5825 }
5826 //Add the value
5827 fPHInfo->fsum[bin]+= value;
5828 fPHInfo->fsumsquare[bin] += value*value;
5829 fPHInfo->fentries[bin]++;
5830
5831 //Set in the vector
5832 fVectorPH.push_back(fPHInfo);
5833
5834 }
5835 //group already exits
5836 else{
5837 TPInfo *fPHInfo = new TPInfo();
5838 fPHInfo->fsum = new Float_t[fTimeMax];
5839 fPHInfo->fsumsquare = new Float_t[fTimeMax];
5840 fPHInfo->fentries = new UShort_t[fTimeMax];
5841 //retrieve
5842 fPHInfo = fVectorPH[place];
5843 //add
5844
5845 Double_t calcul = (((Double_t)fPHInfo->fentries[bin])*((Double_t)fPHInfo->fsum[bin])+(Double_t)value)/(((Double_t)fPHInfo->fentries[bin])+1);
5846 fPHInfo->fsum[bin] = (Float_t) calcul;
5847 Double_t calculsquare = ((((Double_t)fPHInfo->fsumsquare[bin])*((Double_t)fPHInfo->fentries[bin]))+(((Double_t)value)*((Double_t)value)))/(((Double_t)fPHInfo->fentries[bin])+1);
5848 fPHInfo->fsumsquare[bin] = (Float_t)calculsquare;
5849 fPHInfo->fentries[bin]++;
5850 //update the vector
5851 std::vector<TPInfo *>::iterator it = fVectorPH.begin()+place;
5852 fVectorPH.erase(it);
5853 fVectorPH.insert(it,fPHInfo);
5854 }
5855
5856 return kTRUE;
5857
5858}
5859
5860//_____________________________________________________________________________
5861TGraphErrors *AliTRDCalibra::ConvertVectorPHisto(TPInfo *fPInfo, const char* name)
5862{
5863 //
5864 // Convert the PInfo in a 1D grapherror, name must contains "PRF" if PRF calibration and not "PRF" for Vdrift calibration
5865 //
5866
5867 TGraphErrors *histo;
5868 const char *pattern1="PRF";
5869
5870 //Axis
5871 Double_t *x;
5872 Double_t *y;
5873 Double_t *ex;
5874 Double_t *ey;
5875 Double_t step = 0.0;
5876 Double_t min = 0.0;
5877
5878 //Ntimes
5879 Int_t Ntimes = 0;
5880 if(strstr(name,pattern1)) Ntimes = fNumberBinPRF;
5881 else Ntimes = fTimeMax;
5882 x = new Double_t[Ntimes];// xaxis
5883 y = new Double_t[Ntimes]; // mean
5884 ex = new Double_t[Ntimes]; // nentries
5885 ey = new Double_t[Ntimes]; // sum of square/nentries
5886
5887
5888 //init histo
5889 if(!strstr(name,pattern1)){
5890 step = 1/fSf;
5891 min = 0.0;
5892 }
5893 else {
5894 step = (1.0-(-1.0))/fNumberBinPRF;
5895 min = -1.0+step/2;
5896 }
5897
5898 //Fill histo
5899 for(Int_t k = 0; k < Ntimes; k++){
5900 x[k] = min + k*step;
5901 y[k] = 0.0;
5902 ex[k] = 0.0;
5903 ey[k] = 0.0;
5904 //fill only if there is more than 0 something
5905 if(fPInfo->fentries[k] > 0){
5906 ex[k] = fPInfo->fentries[k];
5907 y[k] = fPInfo->fsum[k];
5908 ey[k] = fPInfo->fsumsquare[k];
5909 }
5910
5911 }
5912
5913 //Define the TGraphErrors
5914 histo = new TGraphErrors(Ntimes, x, y, ex, ey);
5915 histo->SetTitle(name);
5916 return histo;
5917
5918
5919
5920}
5921
5922
5923//_____________________________________________________________________________
5924TH1F *AliTRDCalibra::ConvertVectorCTHisto(TCTInfo *fCTInfo, const char* name)
5925{
5926 //
5927 // Convert the CTInfo in a 1D histo
5928 //
5929
5930 TH1F *histo;
5931
5932 Int_t Ntimes = 0;
5933 Ntimes = fNumberBinCharge;
5934
5935
5936 //init histo
5937 histo = new TH1F(name,name,fNumberBinCharge,0,300);
5938 histo->Sumw2();
5939 //Fill histo
5940 for(Int_t k = 0; k < Ntimes; k++){
5941 histo->SetBinContent(k+1,fCTInfo->fentries[k]);
5942 histo->SetBinError(k+1,TMath::Sqrt(TMath::Abs(fCTInfo->fentries[k])));
5943 }
5944
5945
5946
5947 return histo;
5948
5949
5950
5951}
5952//_____________________________________________________________________________
5953TTree *AliTRDCalibra::ConvertVectorCTTreeHisto(std::vector<TCTInfo *> VectorCT, std::vector<Int_t> PlaCT, const char* name)
5954{
5955 //
5956 // Convert the vector in a tree with two branchs: the group number and the TH1F histo reconstructed from the vector
5957 //
5958
5959 //Size of the things
5960 Int_t Ntotal = (Int_t) PlaCT.size();
5961 if(Ntotal == 0) {
5962 AliInfo("nothing to write!");
5963 TTree *TreeCT = new TTree(name,name);
5964 return TreeCT;
5965 }
5966
5967
5968 //Variable of the tree
5969 Int_t groupnumber = -1; //group calibration
5970 TH1F* histo = 0x0;
5971
5972
5973
5974
5975 //Init the tree
5976 TTree *TreeCT = new TTree(name,name);
5977 TreeCT->Branch("groupnumber",&groupnumber,"groupnumber/I");
5978 TreeCT->Branch("histo","TH1F",&histo,32000,0);
5979
5980
5981
5982 //Fill
5983 Int_t k = 0;
5984 while(k < Ntotal){
5985 TString nome(name);
5986 groupnumber = PlaCT[0];
5987 nome += groupnumber;
5988 histo = ConvertVectorCTHisto(VectorCT[0],nome);
5989
5990 TreeCT->Fill();
5991 std::vector<TCTInfo* >::iterator it = VectorCT.begin();
5992 VectorCT.erase(it);
5993 std::vector<Int_t>::iterator it2 = PlaCT.begin();
5994 PlaCT.erase(it2);
5995 k++;
5996
5997 }
5998
5999
6000 return TreeCT;
6001
6002
6003
6004}
6005
6006//_____________________________________________________________________________
6007TTree *AliTRDCalibra::ConvertVectorPTreeHisto(std::vector<TPInfo *> VectorP, std::vector<Int_t> PlaP, const char* name)
6008{
6009 //
6010 // Convert the vector in a tree with two branch: the group number and the TGraphErrors histo reconstructed from the vector.The name must contain "PRF" for PRF calibration and not "PRF" for Vdrift calibration
6011 //
6012
6013 //Size of the things
6014 Int_t Ntotal = (Int_t) PlaP.size();
6015 if(Ntotal == 0) {
6016 AliInfo("nothing to write!");
6017 TTree *TreeP = new TTree(name,name);
6018 return TreeP;
6019 }
6020
6021
6022 //Variable of the tree
6023 Int_t groupnumber = -1; //group calibration
6024 TGraphErrors* histo = 0x0;
6025
6026
6027
6028
6029 //Init the tree
6030 TTree *TreeP = new TTree(name,name);
6031 TreeP->Branch("groupnumber",&groupnumber,"groupnumber/I");
6032 TreeP->Branch("histo","TGraphErrors",&histo,32000,0);
6033
6034
6035
6036 //Fill
6037 Int_t k = 0;
6038 while(k < Ntotal){
6039 TString nome(name);
6040 groupnumber = PlaP[0];
6041 nome += groupnumber;
6042 histo = ConvertVectorPHisto(VectorP[0],nome);
6043
6044 TreeP->Fill();
6045 std::vector<TPInfo*>::iterator it = VectorP.begin();
6046 VectorP.erase(it);
6047 std::vector<Int_t>::iterator it2 = PlaP.begin();
6048 PlaP.erase(it2);
6049 k++;
6050
6051 }
6052
6053
6054 return TreeP;
6055
6056
6057
6058}
6059
6060//_____________________________________________________________________________
6061std::vector<Int_t> AliTRDCalibra::ConvertTreeVector(TTree *tree)
6062{
6063 //
6064 // Convert the branch groupnumber of the tree taken from TRD.calibration.root in case of vector method in a std::vector to be faster
6065 //
6066
6067 //initialise
6068 std::vector<Int_t> vectorplace;
6069
6070
6071
6072 //Variable of the tree
6073 Int_t groupnumber = -1; //group calibration
6074
6075
6076 //Set the branch
6077 tree->SetBranchAddress("groupnumber",&groupnumber);
6078
6079
6080 //Fill
6081 Int_t Ntotal = tree->GetEntries();
6082 for(Int_t k = 0; k < Ntotal; k++){
6083 tree->GetEntry(k);
6084 vectorplace.push_back(groupnumber);
6085 }
6086
6087
6088 return vectorplace;
6089
6090}
6091
6092//_____________________________________________________________________________
6093Bool_t AliTRDCalibra::MergeVectorCT(std::vector<TCTInfo *> VectorCT2, std::vector<Int_t> PlaCT2)
6094{
6095 //
6096 // Add the two vectors and place the result in the first
6097 //
6098
6099
6100 if(((Int_t) PlaCT2.size()) != ((Int_t) VectorCT2.size())){
6101 AliInfo("VectorCT2 doesn't correspond to PlaCT2!");
6102 return kFALSE;
6103 }
6104
6105
6106 //CH case
6107 for(Int_t k = 0; k < (Int_t) fPlaCH.size(); k++){
6108
6109 //Look if PlaCT1[k] it is also in the second vector
6110 Int_t place = -1;
6111 for(Int_t j = 0; j < (Int_t) PlaCT2.size(); j++){
6112 if(PlaCT2[j] == fPlaCH[k]) {
6113 place = j;
6114 break;
6115 }
6116 }
6117
6118 //If not in the second vector nothing to do
6119
6120
6121
6122 //If in the second vector
6123 if(place != -1){
6124
6125
6126 TCTInfo *fCTInfo = new TCTInfo();
6127 fCTInfo->fentries = new UShort_t[fNumberBinCharge];
6128
6129
6130 for(Int_t nu = 0; nu < fNumberBinCharge; nu++){
6131 fCTInfo->fentries[nu] = fVectorCH[fPlaCH[k]]->fentries[nu]+VectorCT2[fPlaCH[k]]->fentries[nu];
6132 }
6133
6134 //nothing to do on PlaCT1
6135
6136 //update the vector
6137 std::vector<TCTInfo *>::iterator it = fVectorCH.begin()+fPlaCH[k];
6138
6139 fVectorCH.erase(it);
6140 fVectorCH.insert(it,fCTInfo);
6141
6142 }
6143
6144 }
6145
6146
6147 //And at the end the vector in CT2 but not in CH1
6148 for(Int_t k = 0; k < (Int_t) PlaCT2.size(); k++){
6149
6150 //Look if PlaCT2[k] it is also in the second vector
6151 Int_t place = -1;
6152 for(Int_t j = 0; j < (Int_t) fPlaCH.size(); j++){
6153 if(fPlaCH[j] == PlaCT2[k]) {
6154 place = j;
6155 break;
6156 }
6157 }
6158
6159 //If not in the first vector
6160 if(place == -1){
6161
6162 TCTInfo *fCTInfo = new TCTInfo();
6163 fCTInfo->fentries = new UShort_t[fNumberBinCharge];
6164
6165 fCTInfo = VectorCT2[PlaCT2[k]];
6166
6167 //Add at the end
6168 fPlaCH.push_back(PlaCT2[k]);
6169 fVectorCH.push_back(fCTInfo);
6170
6171 }
6172
6173 }
6174
6175
6176 return kTRUE;
6177
6178
6179}
6180
6181//_____________________________________________________________________________
6182Bool_t AliTRDCalibra::MergeVectorP(std::vector<TPInfo *> VectorP2, std::vector<Int_t> PlaP2, Int_t i)
6183{
6184 //
6185 // Add the two vectors and place the result in the first
6186 //
6187
6188
6189 if(((Int_t) PlaP2.size()) != ((Int_t) VectorP2.size())){
6190 AliInfo("VectorP2 doesn't correspond to PlaP2!");
6191 return kFALSE;
6192 }
6193
6194 //PH case
6195 if(i == 1){
6196 for(Int_t k = 0; k < (Int_t) fPlaPH.size(); k++){
6197
6198 //Look if fPlaPH[k] it is also in the second vector
6199 Int_t place = -1;
6200 for(Int_t j = 0; j < (Int_t) PlaP2.size(); j++){
6201 if(PlaP2[j] == fPlaPH[k]) {
6202 place = j;
6203 break;
6204 }
6205 }
6206
6207 //If not in the second vector nothing to do
6208
6209
6210 //If in the second vector
6211 if(place != -1){
6212
6213 TPInfo *fPInfo = new TPInfo();
6214 fPInfo->fentries = new UShort_t[fTimeMax];
6215 fPInfo->fsum = new Float_t[fTimeMax];
6216 fPInfo->fsumsquare = new Float_t[fTimeMax];
6217
6218
6219 for(Int_t nu = 0; nu < fTimeMax; nu++){
6220
6221 fPInfo->fentries[nu] = fVectorPH[fPlaPH[k]]->fentries[nu]+VectorP2[fPlaPH[k]]->fentries[nu];
6222
6223 Double_t calcul = ((((Double_t)fVectorPH[fPlaPH[k]]->fsum[nu])*((Double_t)fVectorPH[fPlaPH[k]]->fentries[nu]))+(((Double_t)VectorP2[fPlaPH[k]]->fsum[nu])*((Double_t)VectorP2[fPlaPH[k]]->fentries[nu])))/((Double_t)fPInfo->fentries[nu]);
6224
6225 fPInfo->fsum[nu] = (Float_t) calcul;
6226
6227 Double_t calculsquare = ((((Double_t)fVectorPH[fPlaPH[k]]->fsumsquare[nu])*((Double_t)fVectorPH[fPlaPH[k]]->fentries[nu]))+(((Double_t)VectorP2[fPlaPH[k]]->fsumsquare[nu])*((Double_t)VectorP2[fPlaPH[k]]->fentries[nu])))/((Double_t)fPInfo->fentries[nu]);
6228
6229
6230 fPInfo->fsumsquare[nu] = calculsquare;
6231 }
6232
6233 //nothing to do on PlaCT1
6234
6235 //update the vector VectorCT1
6236 std::vector<TPInfo *>::iterator it = fVectorPH.begin()+fPlaPH[k];
6237 fVectorPH.erase(it);
6238 fVectorPH.insert(it,fPInfo);
6239
6240 }
6241
6242 }
6243
6244
6245 //And at the end the vector in P2 but not in CH1
6246 for(Int_t k = 0; k < (Int_t) PlaP2.size(); k++){
6247
6248 //Look if PlaCT2[k] it is also in the second vector
6249 Int_t place = -1;
6250 for(Int_t j = 0; j < (Int_t) fPlaPH.size(); j++){
6251 if(fPlaPH[j] == PlaP2[k]) {
6252 place = j;
6253 break;
6254 }
6255 }
6256
6257 //If not in the first vector
6258 if(place == -1){
6259
6260 TPInfo *fPInfo = new TPInfo();
6261 fPInfo->fentries = new UShort_t[fTimeMax];
6262 fPInfo->fsum = new Float_t[fTimeMax];
6263 fPInfo->fsumsquare = new Float_t[fTimeMax];
6264
6265 fPInfo = VectorP2[PlaP2[k]];
6266
6267 //Add at the end of CH1
6268 fPlaPH.push_back(PlaP2[k]);
6269 fVectorPH.push_back(fPInfo);
6270
6271 }
6272 }
6273 }
6274
6275
6276 //PRF case
6277 if(i == 1){
6278 for(Int_t k = 0; k < (Int_t) fPlaPRF.size(); k++){
6279
6280 //Look if fPlaPRF[k] it is also in the second vector
6281 Int_t place = -1;
6282 for(Int_t j = 0; j < (Int_t) PlaP2.size(); j++){
6283 if(PlaP2[j] == fPlaPRF[k]) {
6284 place = j;
6285 break;
6286 }
6287 }
6288
6289 //If not in the second vector nothing to do
6290
6291
6292
6293 //If in the second vector
6294 if(place != -1){
6295
6296 TPInfo *fPInfo = new TPInfo();
6297 fPInfo->fentries = new UShort_t[fNumberBinPRF];
6298 fPInfo->fsum = new Float_t[fNumberBinPRF];
6299 fPInfo->fsumsquare = new Float_t[fNumberBinPRF];
6300
6301
6302 for(Int_t nu = 0; nu < fNumberBinPRF; nu++){
6303
6304 fPInfo->fentries[nu] = fVectorPRF[fPlaPRF[k]]->fentries[nu]+VectorP2[fPlaPRF[k]]->fentries[nu];
6305
6306 Double_t calcul = ((((Double_t)fVectorPRF[fPlaPRF[k]]->fsum[nu])*((Double_t)fVectorPRF[fPlaPRF[k]]->fentries[nu]))+(((Double_t)VectorP2[fPlaPRF[k]]->fsum[nu])*((Double_t)VectorP2[fPlaPRF[k]]->fentries[nu])))/((Double_t)fPInfo->fentries[nu]);
6307
6308 fPInfo->fsum[nu] = (Float_t) calcul;
6309
6310 Double_t calculsquare = ((((Double_t)fVectorPRF[fPlaPRF[k]]->fsumsquare[nu])*((Double_t)fVectorPRF[fPlaPRF[k]]->fentries[nu]))+(((Double_t)VectorP2[fPlaPRF[k]]->fsumsquare[nu])*((Double_t)VectorP2[fPlaPRF[k]]->fentries[nu])))/((Double_t)fPInfo->fentries[nu]);
6311
6312
6313 fPInfo->fsumsquare[nu] = calculsquare;
6314 }
6315
6316 //nothing to do on PlaCT1
6317
6318 //update the vector VectorCT1
6319 std::vector<TPInfo *>::iterator it = fVectorPRF.begin()+fPlaPRF[k];
6320 fVectorPRF.erase(it);
6321 fVectorPRF.insert(it,fPInfo);
6322
6323 }
6324
6325 }
6326
6327
6328 //And at the end the vector in P2 but not in CH1
6329 for(Int_t k = 0; k < (Int_t) PlaP2.size(); k++){
6330
6331 //Look if PlaCT2[k] it is also in the second vector
6332 Int_t place = -1;
6333 for(Int_t j = 0; j < (Int_t) fPlaPRF.size(); j++){
6334 if(fPlaPRF[j] == PlaP2[k]) {
6335 place = j;
6336 break;
6337 }
6338 }
6339
6340 //If not in the first vector
6341 if(place == -1){
6342
6343 TPInfo *fPInfo = new TPInfo();
6344 fPInfo->fentries = new UShort_t[fNumberBinPRF];
6345 fPInfo->fsum = new Float_t[fNumberBinPRF];
6346 fPInfo->fsumsquare = new Float_t[fNumberBinPRF];
6347
6348 fPInfo = VectorP2[PlaP2[k]];
6349
6350 //Add at the end of CH1
6351 fPlaPRF.push_back(PlaP2[k]);
6352 fVectorPRF.push_back(fPInfo);
6353
6354 }
6355
6356 }
6357 }
6358
6359
6360 return kTRUE;
6361
6362
6363}
6364//_____________Fit Methods______________________________________________________________________________________________________________________
6365
6366//______________________________________________________________________________________________________
6367void AliTRDCalibra::FitPente(TH1* projPH, Int_t idect)
6368{
6369 //
6370 // Slope methode for the drift velocity
6371 //
6372
6373 //constants
6374 const Float_t kDrWidth = AliTRDgeometry::DrThick();
6375 Int_t binmax = 0;
6376 Int_t binmin = 0;
6377 fPhd[0] = 0.0;
6378 fPhd[1] = 0.0;
6379 fPhd[2] = 0.0;
6380 Int_t ju = 0;
6381 fVdriftCoef[1] = 0.0;
6382 fT0Coef[1] = 0.0;
6383 TLine *line = new TLine();
6384
6385
6386
6387 //beginning of the signal
6388 TH1D *pentea = new TH1D("pentea", "pentea", projPH->GetNbinsX(),0,(Float_t)(fTimeMax)/fSf);
6389 for(Int_t k = 1; k < projPH->GetNbinsX(); k++){
6390 pentea->SetBinContent(k,(Double_t)(projPH->GetBinContent(k+1)-projPH->GetBinContent(k)));
6391 }
6392
6393 binmax = (Int_t)pentea->GetMaximumBin();
6394 if(binmax == 1) {
6395 binmax = 2;
6396 AliInfo("Put the binmax from 1 to 2 to enable the fit");
6397 }
6398 pentea->Fit("pol2","0MR","",TMath::Max(pentea->GetBinCenter(binmax-1),0.0),pentea->GetBinCenter(binmax+1));
6399 Float_t l3P1am = pentea->GetFunction("pol2")->GetParameter(1);
6400 Float_t l3P2am = pentea->GetFunction("pol2")->GetParameter(2);
6401
6402 if(l3P2am != 0) fPhd[0] = -(l3P1am/(2*l3P2am));
6403
6404 //amplification region
6405 binmax = 0;
6406 ju = 0;
6407 for(Int_t kbin = 1; kbin < projPH->GetNbinsX(); kbin ++){
6408 if(((projPH->GetBinContent(kbin+1)-projPH->GetBinContent(kbin)) <= 0.0) && (ju == 0)){
6409 binmax = kbin;
6410 ju = 1;
6411 }
6412 }
6413 if(binmax == 1) {
6414 binmax = 2;
6415 AliInfo("Put the binmax from 1 to 2 to enable the fit");
6416 }
6417 projPH->Fit("pol2","0MR","",TMath::Max(projPH->GetBinCenter(binmax-1),0.0),projPH->GetBinCenter(binmax+1));
6418 Float_t l3P1amf = projPH->GetFunction("pol2")->GetParameter(1);
6419 Float_t l3P2amf = projPH->GetFunction("pol2")->GetParameter(2);
6420
6421 if(l3P2amf != 0) fPhd[1] = -(l3P1amf/(2*l3P2amf));
6422
6423
6424 //Drift region
6425 TH1D *pente = new TH1D("pente", "pente", projPH->GetNbinsX(),0,(Float_t)(fTimeMax)/fSf);
6426 for(Int_t k = binmax+4; k < projPH->GetNbinsX(); k++){
6427 pente->SetBinContent(k,(Double_t)(projPH->GetBinContent(k+1)-projPH->GetBinContent(k)));
6428 }
6429 binmin = (Int_t)pente->GetMinimumBin();
6430 if(binmin == 1) {
6431 binmin = 2;
6432 AliInfo("Put the binmax from 1 to 2 to enable the fit");
6433 }
6434 pente->Fit("pol2","0MR","",TMath::Max(pente->GetBinCenter(binmin-1),0.0),TMath::Min(pente->GetBinCenter(binmin+2),(Double_t)(fTimeMax)/fSf));
6435 Float_t l3P1dr = pente->GetFunction("pol2")->GetParameter(1);
6436 Float_t l3P2dr = pente->GetFunction("pol2")->GetParameter(2);
6437 if(l3P2dr != 0) fPhd[2] = -(l3P1dr/(2*l3P2dr));
6438
6439
6440 if((fPhd[2] > fPhd[0]) && (fPhd[2] > fPhd[1])){
6441 fVdriftCoef[1] = (kDrWidth)/(fPhd[2]-fPhd[1]);
6442 if(fPhd[0] >= 0.0) fT0Coef[1] = fPhd[0]-fT0Shift;
6443 else fT0Coef[1] = -TMath::Abs(fT0Coef[2]);
6444 }
6445 else{
6446 fVdriftCoef[1] = -TMath::Abs(fVdriftCoef[2]);
6447 fT0Coef[1] = -TMath::Abs(fT0Coef[2]);
6448 }
6449
6450 if((fDebug == 1) || (fDebug == 4)){
6451
6452 fCoefVdrift[1]->SetBinContent(idect+1,TMath::Abs(fVdriftCoef[1]));
6453 fCoefT0[1]->SetBinContent(idect+1,TMath::Abs(fT0Coef[1]));
6454 if(fVdriftCoef[1] > 0.0){
6455 if(fVdriftCoef[2] != 0.0) fDeltaVdrift[1]->SetBinContent(idect+1,(fVdriftCoef[1]-fVdriftCoef[2])/fVdriftCoef[2]);
6456 fDeltaT0[1]->SetBinContent(idect+1,(fT0Coef[1]-fT0Coef[2]));
6457 }
6458 }
6459
6460
6461 if(fDebug == 2){
6462 TCanvas *cpentei = new TCanvas("cpentei","cpentei",50,50,600,800);
6463 cpentei->cd();
6464 projPH->Draw();
6465 line->SetLineColor(2);
6466 line->DrawLine(fPhd[0],0,fPhd[0],projPH->GetMaximum());
6467 line->DrawLine(fPhd[1],0,fPhd[1],projPH->GetMaximum());
6468 line->DrawLine(fPhd[2],0,fPhd[2],projPH->GetMaximum());
6469
6470 AliInfo(Form("fPhd[0] (beginning of the signal): %f fPhd[1] (end of the amplification region): %f fPhd[2] (end of the drift region): %f fVriftCoef[1] (with only the drift region(default)): %f",(Float_t) fPhd[0], (Float_t) fPhd[1],(Float_t) fPhd[2], (Float_t) fVdriftCoef[1]));
6471
6472 }
6473 if(fDebug != 2) delete pentea;
6474 if(fDebug != 2) delete pente;
6475
6476}
6477
6478//__________________________________________________________________________________________
6479void AliTRDCalibra::FitPH(TH1* projPH, Int_t idect)
6480{
6481 //
6482 // Fit methode for the drift velocity
6483 //
6484
6485 //constants
6486 const Float_t kDrWidth = AliTRDgeometry::DrThick();
6487
6488 TF1 *fPH = new TF1("fPH", AliTRDCalibra::PH,-0.05,3.2,6);
6489 fPH->SetParameter(0,0.469); // scaling
6490 fPH->SetParameter(1,0.18); // start
6491 fPH->SetParameter(2,0.0857325); // AR
6492 fPH->SetParameter(3,1.89); // DR
6493 fPH->SetParameter(4,0.08); // QA/QD
6494 fPH->SetParameter(5,0.0);//baseline
6495
6496 TLine *line = new TLine();
6497
6498 fVdriftCoef[0] = 0.0;
6499 fT0Coef[0] = 0.0;
6500
6501 if(idect%fFitPHPeriode == 0){
6502 AliInfo(Form("<AliTRDCalibra::FitPH> The detector %d will be fitted", idect));
6503 fPH->SetParameter(0,(projPH->Integral()-(projPH->GetBinContent(1)*projPH->GetNbinsX()))*0.00028); // scaling
6504 fPH->SetParameter(1,fPhd[0]-0.1); // start
6505 fPH->SetParameter(2,fPhd[1]-fPhd[0]); // AR
6506 fPH->SetParameter(3,fPhd[2]-fPhd[1]); // DR
6507 fPH->SetParameter(4,0.225); // QA/QD
6508 fPH->SetParameter(5,(Float_t) projPH->GetBinContent(1));
6509
6510 if(fDebug != 2){
6511 projPH->Fit(fPH,"0M","",0.0,(Float_t)fTimeMax/fSf);
6512 }
6513
6514 if(fDebug == 2){
6515 TCanvas *cpente = new TCanvas("cpente","cpente",50,50,600,800);
6516 cpente->cd();
6517 projPH->Fit(fPH,"M+","",0.0,(Float_t)fTimeMax/fSf);
6518 projPH->Draw("E0");
6519 line->SetLineColor(4);
6520 line->DrawLine(fPH->GetParameter(1),0,fPH->GetParameter(1),projPH->GetMaximum());
6521 line->DrawLine(fPH->GetParameter(1)+fPH->GetParameter(2),0,fPH->GetParameter(1)+fPH->GetParameter(2),projPH->GetMaximum());
6522 line->DrawLine(fPH->GetParameter(1)+fPH->GetParameter(2)+fPH->GetParameter(3),0,fPH->GetParameter(1)+fPH->GetParameter(2)+fPH->GetParameter(3),projPH->GetMaximum());
6523 }
6524
6525
6526 if(fPH->GetParameter(3) !=0){
6527 fVdriftCoef[0] = kDrWidth/(fPH->GetParameter(3));
6528 fT0Coef[0] = fPH->GetParameter(1);
6529 }
6530 else {
6531 fVdriftCoef[0] = -TMath::Abs(fVdriftCoef[2]);
6532 fT0Coef[0] = -TMath::Abs(fT0Coef[2]);
6533 }
6534 if((fDebug == 1) || (fDebug == 4)) {
6535 fCoefVdrift[0]->SetBinContent(idect+1,TMath::Abs(fVdriftCoef[0]));
6536 fCoefT0[0]->SetBinContent(idect+1,TMath::Abs(fT0Coef[0]));
6537 if(fVdriftCoef[0] > 0.0){
6538 if(fVdriftCoef[2] != 0.0) fDeltaVdrift[0]->SetBinContent(idect+1,(fVdriftCoef[0]-fVdriftCoef[2])/fVdriftCoef[2]);
6539 fDeltaT0[0]->SetBinContent(idect+1,(fT0Coef[0]-fT0Coef[2]));
6540 }
6541 }
6542 if(fDebug == 2){
6543 AliInfo(Form("fVdriftCoef[0]: %f", (Float_t) fVdriftCoef[0]));
6544 }
6545
6546 }
6547
6548 else{
6549 //Put the default value
6550 if((fDebug <= 1) || (fDebug = 4)) {
6551 fCoefVdrift[0]->SetBinContent(idect+1,fVdriftCoef[2]);
6552 fCoefT0[0]->SetBinContent(idect+1,fT0Coef[2]);
6553 }
6554
6555 }
6556
6557 if(fDebug != 2) delete fPH;
6558
6559}
6560//__________________________________________________________________________________________
6561void AliTRDCalibra::FitPRF(TH1* projPRF, Int_t idect)
6562{
6563 //
6564 // Fit methode for the sigma of the pad response function
6565 //
6566
6567 fPRFCoef[0] = 0.0;
6568
6569
6570
6571 if(fDebug != 2){
6572 projPRF->Fit("gaus","0M","", -fRangeFitPRF, fRangeFitPRF);
6573 }
6574
6575 if(fDebug == 2){
6576 TCanvas *cfit = new TCanvas("cfit","cfit",50,50,600,800);
6577 cfit->cd();
6578 projPRF->Fit("gaus","M+","", -fRangeFitPRF, fRangeFitPRF);
6579 projPRF->Draw();
6580
6581 }
6582
6583
6584 fPRFCoef[0] = projPRF->GetFunction("gaus")->GetParameter(2);
6585
6586
6587 if((fDebug == 1) || (fDebug == 4)){
6588 fCoefPRF[0]->SetBinContent(idect+1,fPRFCoef[0]);
6589 if(fPRFCoef[1] != 0.0){
6590 fDeltaPRF->SetBinContent(idect+1,(fPRFCoef[0]-fPRFCoef[1])/fPRFCoef[1]);
6591 }
6592 }
6593 if(fDebug == 2){
6594 AliInfo(Form("fPRFCoef[0]: %f", (Float_t) fPRFCoef[0]));
6595 }
6596
6597}
6598//________________________________________________________________________________________
6599void AliTRDCalibra::FitCH( TH1* projch, Int_t idect)
6600{
6601 //
6602 // Fit methode for the gain factor
6603 //
6604
6605 fChargeCoef[0] = 0.0;
6606 fChargeCoef[1] = 0.0;
6607 TF1 *fLandauGaus = new TF1("fLandauGaus",funcLandauGaus,0,300,5);
6608
6609 fChargeCoef[1] = projch->GetMean();
6610 projch->Fit("landau","0","",(Float_t) fChargeCoef[1]/fBeginFitCharge,projch->GetBinCenter(projch->GetNbinsX()));
6611 fl3P0 = projch->GetFunction("landau")->GetParameter(0);
6612 Double_t l3P1 = projch->GetFunction("landau")->GetParameter(1);
6613 fl3P2 = projch->GetFunction("landau")->GetParameter(2);
6614
6615 projch->Fit("gaus","0","",(Float_t) fChargeCoef[1]/fBeginFitCharge,projch->GetBinCenter(projch->GetNbinsX()));
6616 Double_t g3P0 = projch->GetFunction("gaus")->GetParameter(0);
6617 fg3P2 = projch->GetFunction("gaus")->GetParameter(2);
6618
6619
6620 fLandauGaus->SetParameters(fl3P0,l3P1,fl3P2,g3P0,fg3P2);
6621 if((fDebug <= 1) || (fDebug >= 3)){
6622 projch->Fit("fLandauGaus","0","",(Float_t) fChargeCoef[1]/fBeginFitCharge,projch->GetBinCenter(projch->GetNbinsX()));
6623 }
6624 if(fDebug == 2){
6625 TCanvas *cp = new TCanvas("cp","cp",50,50,600,800);
6626 cp->cd();
6627 projch->Fit("fLandauGaus","+","",(Float_t) fChargeCoef[1]/fBeginFitCharge,projch->GetBinCenter(projch->GetNbinsX()));
6628 projch->Draw();
6629 fLandauGaus->Draw("same");
6630 }
6631
6632 if(projch->GetFunction("fLandauGaus")->GetParameter(1) > 0){
6633
6634 //Calcul of "real" coef****************************************
6635 CalculChargeCoefMean(fcountdet[0],(Int_t) idect, kTRUE);
6636 fChargeCoef[0] = projch->GetFunction("fLandauGaus")->GetParameter(1);}
6637
6638 else {
6639
6640 //Calcul of "real" coef****************************************
6641 CalculChargeCoefMean(fcountdet[0],(Int_t) idect, kFALSE);
6642 fChargeCoef[0] = -TMath::Abs(fChargeCoef[3]);
6643 }
6644 if(fDebug == 2){
6645 AliInfo(Form("fChargeCoef[0]: %f", (Float_t) fChargeCoef[0]));
6646 AliInfo(Form("fChargeCoef[1]: %f",(Float_t) fChargeCoef[1]));
6647 }
6648
6649 if((fDebug == 1) || (fDebug == 4)) {
6650 if(fChargeCoef[0] > 0.0){
6651 fCoefCharge[0]->SetBinContent(idect+1,fChargeCoef[0]);
6652 fCoefCharge[1]->SetBinContent(idect+1,fChargeCoef[1]);
6653 fDeltaCharge[0]->SetBinContent(idect+1,fChargeCoef[0]);
6654 fDeltaCharge[1]->SetBinContent(idect+1,fChargeCoef[1]);
6655 }
6656 }
6657 fl3P0 = fLandauGaus->Integral(0.3*projch->GetMean(),3*projch->GetMean());
6658 fg3P2 = fLandauGaus->GetParameter(2);
6659 fl3P2 = fLandauGaus->GetParameter(4);
6660
6661 if(fDebug != 2) delete fLandauGaus;
6662}
6663//_________________________________________________________________________________
6664void AliTRDCalibra::FitBisCH( TH1* projch, Int_t idect)
6665{
6666 //
6667 // Fit methode for the gain factor more time consuming
6668 //
6669
6670
6671
6672 // Setting fit range and start values
6673 Double_t fr[2];
6674 //Double_t sv[4] = {l3P2,fChargeCoef[1],projch->Integral("width"),fg3P2};
6675 Double_t sv[4] = {fl3P2,fChargeCoef[1],fl3P0,fg3P2};
6676 Double_t pllo[4] = {0.001,0.001,0.001,0.001};
6677 Double_t plhi[4] = {300.0,300.0,100000000.0,300.0};
6678 Double_t fp[4] = {1.0,1.0,1.0,1.0};
6679 Double_t fpe[4] = {1.0,1.0,1.0,1.0};
6680 fr[0]=0.3*projch->GetMean();
6681 fr[1]=3.0*projch->GetMean();
6682 fChargeCoef[2] = 0.0;
6683
6684
6685 Double_t chisqr;
6686 Int_t ndf;
6687 TF1 *fitsnr = langaufit(projch,&fr[0],&sv[0],&pllo[0],&plhi[0],&fp[0],&fpe[0],&chisqr,&ndf);
6688
6689 Double_t projchPeak, projchFWHM;
6690 langaupro(fp,projchPeak,projchFWHM);
6691
6692 if(fp[1] > 0){
6693 fChargeCoef[2] = fp[1];}
6694 else fChargeCoef[2] = -TMath::Abs(fChargeCoef[3]);
6695
6696
6697 if(fDebug == 2){
6698 AliInfo(Form("fChargeCoef[2]: %f", (Float_t) fChargeCoef[2]));
6699 TCanvas *cpy = new TCanvas("cpy","cpy",50,50,600,800);
6700 cpy->cd();
6701 projch->Draw();
6702 fitsnr->Draw("same");
6703 }
6704
6705 if((fDebug == 1) || (fDebug ==4)) {
6706 if(fChargeCoef[2] > 0.0){
6707 fCoefCharge[2]->SetBinContent(idect+1,fChargeCoef[2]);
6708 fDeltaCharge[2]->SetBinContent(idect+1,fChargeCoef[2]);
6709 }
6710 }
6711
6712 if(fDebug != 2) delete fitsnr;
6713
6714}
6715//________________________________________________________________________________
6716void AliTRDCalibra::NormierungCharge()
6717{
6718 //
6719 // normalisation of the gain factor resulting for the fits
6720 //
6721
6722 //Calcul of the mean of the fit
6723 Double_t sum = 0.0;
6724 Float_t scalefactor = 1.0;
6725 for(Int_t k = 0; k < (Int_t) fVectorFitCH.size(); k++){
6726 Int_t total = 0;
6727 if(GetChamber(fVectorFitCH[k]->fDetector) == 2) total = 1728;
6728 if(GetChamber(fVectorFitCH[k]->fDetector) != 2) total = 2304;
6729 for(Int_t j = 0; j < total; j++){
6730 if(fVectorFitCH[k]->fcoef[j] >= 0){
6731 sum += (Double_t)fVectorFitCH[k]->fcoef[j];
6732 }
6733 }
6734 }
6735
6736 if(sum > 0){
6737 fScalefitfactor = fScalefitfactor/sum;
6738 }
6739 else fScalefitfactor = 1.0;
6740 //Scale the histo
6741 if((fDebug == 1) || (fDebug == 4)){
6742 if((fCoefCharge[0]->GetEntries() > 0.0) && (fCoefCharge[0]->GetSumOfWeights() > 0.0)){
6743 scalefactor = fCoefCharge[0]->GetEntries()/fCoefCharge[0]->GetSumOfWeights();
6744 fCoefCharge[0]->Scale(scalefactor);
6745 fDeltaCharge[0]->Scale(scalefactor);
6746 }
6747 if((fMeanChargeOn) && (fCoefCharge[1]->GetEntries() > 0.0) && (fCoefCharge[1]->GetSumOfWeights() > 0.0)){
6748 fCoefCharge[1]->Scale(fCoefCharge[1]->GetEntries()/fCoefCharge[1]->GetSumOfWeights());
6749 }
6750 if((fFitChargeBisOn) && (fCoefCharge[2]->GetEntries() > 0.0) && (fCoefCharge[2]->GetSumOfWeights() > 0.0)){
6751 fCoefCharge[2]->Scale(fCoefCharge[2]->GetEntries()/fCoefCharge[2]->GetSumOfWeights());
6752 }
6753 if((fMeanChargeOn) && (fDeltaCharge[1]->GetEntries() > 0.0) && (fDeltaCharge[1]->GetSumOfWeights() > 0.0)){
6754 fDeltaCharge[1]->Scale(fDeltaCharge[1]->GetEntries()/fDeltaCharge[1]->GetSumOfWeights());
6755 }
6756 if((fFitChargeBisOn) && (fDeltaCharge[2]->GetEntries() > 0.0) && (fDeltaCharge[2]->GetSumOfWeights() > 0.0)){
6757 fDeltaCharge[2]->Scale(fDeltaCharge[2]->GetEntries()/fDeltaCharge[2]->GetSumOfWeights());
6758 }
6759
6760 }
6761
6762 if((fDebug == 3) || (fDebug == 4)){
6763 fCoefChargeDB[0]->Scale(scalefactor);
6764 if((fMeanChargeOn) && (fCoefChargeDB[1]->GetEntries() > 0.0) && (fCoefChargeDB[1]->GetSumOfWeights() > 0.0))fCoefChargeDB[1]->Scale(fCoefChargeDB[1]->GetEntries()/fCoefChargeDB[1]->GetSumOfWeights());
6765 if((fFitChargeBisOn) && (fCoefChargeDB[2]->GetEntries() > 0.0) && (fCoefChargeDB[2]->GetSumOfWeights() > 0.0))fCoefChargeDB[2]->Scale(fCoefChargeDB[2]->GetEntries()/fCoefChargeDB[2]->GetSumOfWeights());
6766 }
6767
6768
6769
6770 if((fDebug == 1) || (fDebug == 4)){
6771 fDeltaCharge[0]->Add(fCoefCharge[3],-1);
6772 fDeltaCharge[0]->Divide(fCoefCharge[3]);
6773
6774 if(fMeanChargeOn) fDeltaCharge[1]->Add(fCoefCharge[3],-1);
6775 if(fMeanChargeOn) fDeltaCharge[1]->Divide(fCoefCharge[3]);
6776
6777 if(fFitChargeBisOn) fDeltaCharge[2]->Add(fCoefCharge[3],-1);
6778 if(fFitChargeBisOn) fDeltaCharge[2]->Divide(fCoefCharge[3]);
6779 }
6780
6781}
6782
6783//_______________________________________________________________________________________________
6784TH1I *AliTRDCalibra::ReBin(TH1I *hist)
6785{
6786 //
6787 // Rebin of the 1D histo for the gain calibration if needed.
6788 // you have to choose fRebin, divider of fNumberBinCharge
6789 //
6790
6791 TAxis *xhist = hist->GetXaxis();
6792 TH1I* rehist = new TH1I("projrebin","",(Int_t) xhist->GetNbins()/fRebin, xhist->GetBinLowEdge(1), xhist->GetBinUpEdge(xhist->GetNbins()));
6793 AliInfo(Form("fRebin: %d", fRebin));
6794 Int_t i = 1;
6795 for(Int_t k = 1; k <= (Int_t) xhist->GetNbins()/fRebin; k++){
6796 Double_t sum = 0.0;
6797 for(Int_t ji = i; ji < i+fRebin; ji++){
6798 sum += hist->GetBinContent(ji);
6799 }
6800 sum = sum/fRebin;
6801 rehist->SetBinContent(k,sum);
6802 i +=fRebin;
6803
6804
6805 }
6806 if(fDebug == 2){
6807 TCanvas *crebin = new TCanvas("crebin","",50,50,600,800);
6808 crebin->cd();
6809 rehist->Draw();
6810 }
6811
6812 return rehist;
6813
6814}
6815
6816//_______________________________________________________________________________________________
6817TH1F *AliTRDCalibra::ReBin(TH1F *hist)
6818{
6819 //
6820 // Rebin of the 1D histo for the gain calibration if needed
6821 // you have to choose fRebin divider of fNumberBinCharge
6822 //
6823
6824 TAxis *xhist = hist->GetXaxis();
6825 TH1F* rehist = new TH1F("projrebin","",(Int_t) xhist->GetNbins()/fRebin, xhist->GetBinLowEdge(1), xhist->GetBinUpEdge(xhist->GetNbins()));
6826 AliInfo(Form("fRebin: %d", fRebin));
6827 Int_t i = 1;
6828 for(Int_t k = 1; k <= (Int_t) xhist->GetNbins()/fRebin; k++){
6829 Double_t sum = 0.0;
6830 for(Int_t ji = i; ji < i+fRebin; ji++){
6831 sum += hist->GetBinContent(ji);
6832 }
6833 sum = sum/fRebin;
6834 rehist->SetBinContent(k,sum);
6835 i +=fRebin;
6836
6837
6838 }
6839 if(fDebug == 2){
6840 TCanvas *crebin = new TCanvas("crebin","",50,50,600,800);
6841 crebin->cd();
6842 rehist->Draw();
6843 }
6844
6845 return rehist;
6846
6847}
6848//_______________________________________________________________________________________________
6849TH1F *AliTRDCalibra::CorrectTheError(TGraphErrors *hist)
6850{
6851 //
6852 // In the case of the vectors method the trees contains TGraphErrors for PH and PRF
6853 // to be able to add them after
6854 // We convert it to a TH1F to be able to applied the same fit function method
6855 // After having called this function you can not add the statistics anymore
6856 //
6857
6858 TH1F* rehist = 0x0;
6859
6860 Int_t nbins = hist->GetN();
6861 Double_t *x = hist->GetX();
6862 Double_t *entries = hist->GetEX();
6863 Double_t *mean = hist->GetY();
6864 Double_t *square = hist->GetEY();
6865 fEntriesCurrent = 0;
6866
6867
6868 if(nbins < 2) return rehist;
6869 Double_t step = x[1]-x[0];
6870 Double_t minvalue = x[0]-step/2;
6871 Double_t maxvalue = x[(nbins-1)]+step/2;
6872
6873
6874 rehist = new TH1F("projcorrecterror","",nbins,minvalue,maxvalue);
6875
6876 for(Int_t k = 0; k < nbins; k++){
6877 rehist->SetBinContent(k+1,mean[k]);
6878 if(entries[k] > 0.0){
6879 fEntriesCurrent += (Int_t) entries[k];
6880 Double_t d = TMath::Abs(square[k]- (mean[k]*mean[k]));
6881 rehist->SetBinError(k+1,TMath::Sqrt(d/entries[k]));
6882 }
6883 else rehist->SetBinError(k+1,0.0);
6884
6885 }
6886 return rehist;
6887
6888}
6889//_______________________________________________________________________________________________
6890TGraphErrors *AliTRDCalibra::AddProfiles(TGraphErrors *hist1, TGraphErrors *hist2)
6891{
6892 //
6893 // In the case of the vectors method we use TGraphErrors for PH and PRF
6894 // to be able to add the them after
6895 // Here we add the TGraphErrors
6896 //
6897
6898
6899 //First TGraphErrors
6900 Int_t nbins1 = hist1->GetN();
6901 Double_t *x1 = hist1->GetX();
6902 Double_t *ex1 = hist1->GetEX();
6903 Double_t *y1 = hist1->GetY();
6904 Double_t *ey1 = hist1->GetEY();
6905
6906 TGraphErrors* rehist = new TGraphErrors(nbins1);
6907
6908
6909
6910 //Second TGraphErrors
6911 Double_t *ex2 = hist2->GetEX();
6912 Double_t *y2 = hist2->GetY();
6913 Double_t *ey2 = hist2->GetEY();
6914
6915 //Define the Variables for the new TGraphErrors
6916 Double_t x, ex, y, ey; // Xaxis
6917
6918
6919 for(Int_t k = 0; k < nbins1; k++){
6920 x = x1[k];
6921 Double_t nentries = 0.0;
6922 y = 0.0;
6923 ey = 0.0;
6924 ex = 0.0;
6925 if((ex2[k] == 0.0) && (ex1[k] == 0.0)) nentries = 0.0;
6926 if((ex2[k] == 0.0) && (ex1[k] > 0.0)) {
6927 nentries = ex1[k];
6928 y = y1[k];
6929 ey = ey1[k];
6930 ex = ex1[k];
6931 }
6932 if((ex2[k] > 0.0) && (ex1[k] == 0.0)) {
6933 nentries = ex2[k];
6934 y = y2[k];
6935 ey = ey2[k];
6936 ex = ex2[k];
6937 }
6938 if((ex2[k] > 0.0) && (ex1[k] > 0.0)){
6939 nentries = ex1[k]+ex2[k];
6940 y = (y1[k]*ex1[k]+y2[k]*ex2[k])/nentries;
6941 ey = (ey1[k]*ex1[k]+ey2[k]*ex2[k])/nentries;
6942 ex = nentries;
6943 }
6944 rehist->SetPoint(k,x,y);
6945 rehist->SetPointError(k,ex,ey);
6946
6947 }
6948
6949
6950 return rehist;
6951
6952}
6953
6954
6955//_________________Some basic geometry function______________________________________________________________________________________________________
6956
6957//_____________________________________________________________________________
6958Int_t AliTRDCalibra::GetPlane(Int_t d) const
6959{
6960 //
6961 //Reconstruct the plane number from the detector number
6962 //
6963
6964 return ((Int_t) (d % 6));
6965
6966}
6967
6968//_____________________________________________________________________________
6969Int_t AliTRDCalibra::GetChamber(Int_t d) const
6970{
6971 //
6972 //Reconstruct the chamber number from the detector number
6973 //
6974 Int_t fgkNplan = 6;
6975
6976 return ((Int_t) (d % 30) / fgkNplan);
6977
6978}
6979
6980//_____________________________________________________________________________
6981Int_t AliTRDCalibra::GetSector(Int_t d) const
6982{
6983 //
6984 //Reconstruct the sector number from the detector number
6985 //
6986 Int_t fg = 30;
6987
6988 return ((Int_t) (d / fg));
6989
6990}
6991
6992//____________________________Fill and Init tree Gain, PRF, Vdrift and T0__________________________________________________________________________________________________________________
6993
6994//_____________________________________________________________________________
6995void AliTRDCalibra::InittreePRF()
6996{
6997 //
6998 // Init the tree where the coefficients from the fit methods can be stored
6999 //
7000
7001 fPRFPad = new Float_t[2304];
7002 fPRF = new TTree("PRF","PRF");
7003 fPRF->Branch("detector",&fPRFDetector,"detector/I");
7004 fPRF->Branch("width",fPRFPad,"width[2304]/F");
7005 //Set to default value for the plane 0 supposed to be the first one
7006 for(Int_t k = 0; k < 2304; k++){
7007 fPRFPad[k] = 0.515;
7008 }
7009 fPRFDetector = -1;
7010
7011
7012
7013
7014}
7015//_____________________________________________________________________________
7016void AliTRDCalibra::FilltreePRF(Int_t countdet)
7017{
7018 //
7019 // Fill the tree with the sigma of the pad response function for the detector countdet
7020 //
7021
7022 Int_t numberofgroup = 0;
7023 fPRFDetector = countdet;
7024 fPRF->Fill();
7025 if(GetChamber((Int_t)(countdet+1)) == 2) numberofgroup = 1728;
7026 else numberofgroup = 2304;
7027 //Reset to default value for the next
7028 for(Int_t k = 0; k < numberofgroup; k++){
7029 if(GetPlane((Int_t) (countdet+1)) == 0) fPRFPad[k] = 0.515;
7030 if(GetPlane((Int_t) (countdet+1)) == 1) fPRFPad[k] = 0.502;
7031 if(GetPlane((Int_t) (countdet+1)) == 2) fPRFPad[k] = 0.491;
7032 if(GetPlane((Int_t) (countdet+1)) == 3) fPRFPad[k] = 0.481;
7033 if(GetPlane((Int_t) (countdet+1)) == 4) fPRFPad[k] = 0.471;
7034 if(GetPlane((Int_t) (countdet+1)) == 5) fPRFPad[k] = 0.463;
7035 }
7036 fPRFDetector = -1;
7037
7038}
7039
7040//_____________________________________________________________________________
7041void AliTRDCalibra::ConvertVectorFitCHTree()
7042{
7043 //
7044 // Convert the vector stuff to a tree of 1D histos if the user want to write it after the fill functions
7045 //
7046
7047 Int_t detector = -1;
7048 Int_t numberofgroup = 1;
7049 Float_t gainPad[2304];
7050 fGain = new TTree("Gain","Gain");
7051 fGain->Branch("detector",&detector,"detector/I");
7052 fGain->Branch("gainPad",gainPad,"gainPad[2304]/F");
7053 Int_t loop = (Int_t) fVectorFitCH.size();
7054 for(Int_t k = 0; k < loop; k++){
7055 detector = fVectorFitCH[k]->fDetector;
7056 if(GetChamber((Int_t)fVectorFitCH[k]->fDetector) == 2) numberofgroup = 1728;
7057 else numberofgroup = 2304;
7058 for(Int_t i = 0; i < numberofgroup; i++){
7059 if(fVectorFitCH[k]->fcoef[i] >= 0) gainPad[i] = fVectorFitCH[k]->fcoef[i]*fScalefitfactor;
7060 else {
7061 gainPad[i] = (Float_t) fVectorFitCH[k]->fcoef[i];
7062 }
7063 }
7064 fGain->Fill();
7065 }
7066
7067
7068
7069
7070
7071}
7072//_____________________________________________________________________________
7073void AliTRDCalibra::FilltreeVdrift(Int_t countdet)
7074{
7075 //
7076 // Fill the tree with the drift velocities for the detector countdet
7077 //
7078 Int_t numberofgroup = 0;
7079 fVdriftDetector = countdet;
7080 for(Int_t k = 0; k < 2304; k++){
7081 }
7082 fVdrift->Fill();
7083 if(GetChamber((Int_t)(countdet+1)) == 2) numberofgroup = 1728;
7084 else numberofgroup = 2304;
7085 //Reset to default value the gain coef
7086 for(Int_t k = 0; k < numberofgroup; k++){
7087 fVdriftPad[k] = -1.5;
7088 }
7089 fVdriftDetector = -1;
7090
7091}
7092
7093//_____________________________________________________________________________
7094void AliTRDCalibra::InittreePH()
7095{
7096 //
7097 // Init the tree where the coefficients from the fit methods can be stored
7098 //
7099
7100 fVdriftPad = new Float_t[2304];
7101 fVdrift = new TTree("Vdrift","Vdrift");
7102 fVdrift->Branch("detector",&fVdriftDetector,"detector/I");
7103 fVdrift->Branch("vdrift",fVdriftPad,"vdrift[2304]/F");
7104 //Set to default value for the plane 0 supposed to be the first one
7105 for(Int_t k = 0; k < 2304; k++){
7106 fVdriftPad[k] = -1.5;
7107 }
7108 fVdriftDetector = -1;
7109
7110}
7111//_____________________________________________________________________________
7112void AliTRDCalibra::FilltreeT0(Int_t countdet)
7113{
7114 //
7115 // Fill the tree with the t0 value for the detector countdet
7116 //
7117 Int_t numberofgroup = 0;
7118 fT0Detector = countdet;
7119 for(Int_t k = 0; k < 2304; k++){
7120 }
7121 fT0->Fill();
7122 if(GetChamber((Int_t)(countdet+1)) == 2) numberofgroup = 1728;
7123 else numberofgroup = 2304;
7124 //Reset to default value the gain coef
7125 for(Int_t k = 0; k < numberofgroup; k++){
7126 fT0Pad[k] = 0.0;
7127 }
7128 fT0Detector = -1;
7129
7130}
7131
7132//_____________________________________________________________________________
7133void AliTRDCalibra::InittreeT0()
7134{
7135 //
7136 // Init the tree where the coefficients from the fit methods can be stored
7137 //
7138
7139 fT0Pad = new Float_t[2304];
7140 fT0 = new TTree("T0","T0");
7141 fT0->Branch("detector",&fT0Detector,"detector/I");
7142 fT0->Branch("t0",fT0Pad,"t0[2304]/F");
7143 //Set to default value for the plane 0 supposed to be the first one
7144 for(Int_t k = 0; k < 2304; k++){
7145 fT0Pad[k] = 0.0;
7146 }
7147 fT0Detector = -1;
7148
7149}
7150
7151//________________private Functions______________________________________________________________________________________________________________
7152
7153
7154//_________________________________________________________________________________
7155
7156Double_t AliTRDCalibra::PH(Double_t* x, Double_t* par)
7157{
7158 //
7159 // Function for the fit
7160 //
7161
7162 //TF1 * fAsymmGauss = new TF1("fAsymmGauss",AsymmGauss,0,4,6);
7163
7164 //PARAMETERS FOR FIT PH
7165 // PASAv.4
7166 //fAsymmGauss->SetParameter(0, 0.113755);
7167 //fAsymmGauss->SetParameter(1, 0.350706);
7168 //fAsymmGauss->SetParameter(2, 0.0604244);
7169 //fAsymmGauss->SetParameter(3, 7.65596);
7170 //fAsymmGauss->SetParameter(4, 1.00124);
7171 //fAsymmGauss->SetParameter(5, 0.870597); //no tail cancelation
7172
7173 Double_t xx = x[0];
7174
7175 if (xx < par[1]) return par[5];
7176
7177 Double_t dx = 0.005;
7178 Double_t xs = par[1];
7179 Double_t ss = 0.0;
7180 Double_t paras[2] = {0.0,0.0};
7181 while (xs < xx) {
7182 if (xs >= par[1] && xs < (par[1]+par[2])) {
7183 //fAsymmGauss->SetParameter(0,par[0]);
7184 //fAsymmGauss->SetParameter(1,xs);
7185 //ss += fAsymmGauss->Eval(xx);
7186 paras[0] = par[0];
7187 paras[1] = xs;
7188 ss += AsymmGauss(&xx,paras);
7189 }
7190 if (xs >= (par[1]+par[2]) && xs < (par[1]+par[2]+par[3])) {
7191 //fAsymmGauss->SetParameter(0,par[0]*par[4]);
7192 //fAsymmGauss->SetParameter(1,xs);
7193 //ss += fAsymmGauss->Eval(xx);
7194 paras[0] = par[0]*par[4];
7195 paras[1] = xs;
7196 ss += AsymmGauss(&xx,paras);
7197 }
7198 xs += dx;
7199 }
7200
7201 return ss+par[5];
7202
7203}
7204
7205//_________________________________________________________________________________
7206
7207Double_t AliTRDCalibra::AsymmGauss(Double_t* x, Double_t* par)
7208{
7209 //
7210 // Function for the fit
7211 //
7212
7213 //par[0] = normalization
7214 //par[1] = mean
7215 //par[2] = sigma
7216 //norm0 = 1
7217 //par[3] = lambda0
7218 //par[4] = norm1
7219 //par[5] = lambda1
7220 //
7221
7222 Double_t par1save = par[1];
7223 //Double_t par2save = par[2];
7224 Double_t par2save = 0.0604244;
7225 //Double_t par3save = par[3];
7226 Double_t par3save = 7.65596;
7227 //Double_t par5save = par[5];
7228 Double_t par5save = 0.870597;
7229 Double_t dx = x[0]-par1save;
7230 //
7231 //
7232 Double_t sigma2 = par2save*par2save;
7233 Double_t sqrt2 = TMath::Sqrt(2.);
7234 Double_t exp1 = par3save*TMath::Exp(-par3save*(dx-0.5*par3save*sigma2))
7235 *(1-TMath::Erf((par3save*sigma2-dx)/(sqrt2*par2save)));
7236
7237 Double_t exp2 = par5save*TMath::Exp(-par5save*(dx-0.5*par5save*sigma2))
7238 *(1-TMath::Erf((par5save*sigma2-dx)/(sqrt2*par2save)));
7239
7240
7241 //return par[0]*(exp1+par[4]*exp2);
7242 return par[0]*(exp1+1.00124*exp2);
7243}
7244
7245//__________________________________________________________________________
7246
7247Double_t AliTRDCalibra::funcLandauGaus(Double_t* x, Double_t* par)
7248{
7249 //
7250 //sum landau + gaus with identical mean
7251 //
7252
7253 Double_t valLandau = par[0]*TMath::Landau(x[0],par[1],par[2]);
7254 //Double_t valGaus = par[3]*TMath::Gaus(x[0],par[4],par[5]);
7255 Double_t valGaus = par[3]*TMath::Gaus(x[0],par[1],par[4]);
7256
7257 Double_t val = valLandau+valGaus;
7258 return val;
7259}
7260//________________________________________________________________________
7261Double_t AliTRDCalibra::langaufun(Double_t *x, Double_t *par)
7262{
7263 //
7264 // Function for the fit
7265 //
7266
7267
7268
7269 //Fit parameters:
7270 //par[0]=Width (scale) parameter of Landau density
7271 //par[1]=Most Probable (MP, location) parameter of Landau density
7272 //par[2]=Total area (integral -inf to inf, normalization constant)
7273 //par[3]=Width (sigma) of convoluted Gaussian function
7274 //
7275 //In the Landau distribution (represented by the CERNLIB approximation),
7276 //the maximum is located at x=-0.22278298 with the location parameter=0.
7277 //This shift is corrected within this function, so that the actual
7278 //maximum is identical to the MP parameter.
7279
7280 // Numeric constants
7281 Double_t invsq2pi = 0.3989422804014; // (2 pi)^(-1/2)
7282 Double_t mpshift = -0.22278298; // Landau maximum location
7283
7284 // Control constants
7285 Double_t np = 100.0; // number of convolution steps
7286 Double_t sc = 5.0; // convolution extends to +-sc Gaussian sigmas
7287
7288 // Variables
7289 Double_t xx;
7290 Double_t mpc;
7291 Double_t fland;
7292 Double_t sum = 0.0;
7293 Double_t xlow,xupp;
7294 Double_t step;
7295 Double_t i;
7296
7297
7298 // MP shift correction
7299 mpc = par[1] - mpshift * par[0];
7300
7301 // Range of convolution integral
7302 xlow = x[0] - sc * par[3];
7303 xupp = x[0] + sc * par[3];
7304
7305 step = (xupp-xlow) / np;
7306
7307 // Convolution integral of Landau and Gaussian by sum
7308 for(i=1.0; i<=np/2; i++) {
7309 xx = xlow + (i-.5) * step;
7310 fland = TMath::Landau(xx,mpc,par[0]) / par[0];
7311 sum += fland * TMath::Gaus(x[0],xx,par[3]);
7312
7313 xx = xupp - (i-.5) * step;
7314 fland = TMath::Landau(xx,mpc,par[0]) / par[0];
7315 sum += fland * TMath::Gaus(x[0],xx,par[3]);
7316 }
7317
7318 return (par[2] * step * sum * invsq2pi / par[3]);
7319}
7320//______________________________________________________________________________________________
7321TF1 * AliTRDCalibra::langaufit(TH1 *his, Double_t *fitrange, Double_t *startvalues, Double_t *parlimitslo, Double_t *parlimitshi, Double_t *fitparams, Double_t *fiterrors, Double_t *ChiSqr, Int_t *NDF)
7322{
7323 //
7324 // Function for the fit
7325 //
7326
7327
7328 Int_t i;
7329 Char_t FunName[100];
7330
7331 AliInfo(Form(FunName,"Fitfcn_%s",his->GetName()));
7332
7333 TF1 *ffitold = (TF1*)gROOT->GetListOfFunctions()->FindObject(FunName);
7334 if (ffitold) delete ffitold;
7335
7336 TF1 *ffit = new TF1(FunName,langaufun,fitrange[0],fitrange[1],4);
7337 ffit->SetParameters(startvalues);
7338 ffit->SetParNames("Width","MP","Area","GSigma");
7339
7340 for (i=0; i<4; i++) {
7341 ffit->SetParLimits(i, parlimitslo[i], parlimitshi[i]);
7342 }
7343
7344 his->Fit(FunName,"RB0"); // fit within specified range, use ParLimits, do not plot
7345
7346 ffit->GetParameters(fitparams); // obtain fit parameters
7347 for (i=0; i<4; i++) {
7348 fiterrors[i] = ffit->GetParError(i); // obtain fit parameter errors
7349 }
7350 ChiSqr[0] = ffit->GetChisquare(); // obtain chi^2
7351 NDF[0] = ffit->GetNDF(); // obtain ndf
7352
7353 return (ffit); // return fit function
7354
7355}
7356//________________________________________________________________________________________
7357Int_t AliTRDCalibra::langaupro(Double_t *params, Double_t &maxx, Double_t &FWHM) {
7358 //
7359 // Function for the fit
7360 //
7361
7362
7363 Double_t p,x,fy,fxr,fxl;
7364 Double_t step;
7365 Double_t l,lold;
7366 Int_t i = 0;
7367 Int_t MAXCALLS = 10000;
7368
7369
7370 // Search for maximum
7371
7372 p = params[1] - 0.1 * params[0];
7373 step = 0.05 * params[0];
7374 lold = -2.0;
7375 l = -1.0;
7376
7377
7378 while ( (l != lold) && (i < MAXCALLS) ) {
7379 i++;
7380
7381 lold = l;
7382 x = p + step;
7383 l = langaufun(&x,params);
7384
7385 if (l < lold)
7386 step = -step/10;
7387
7388 p += step;
7389 }
7390
7391 if (i == MAXCALLS)
7392 return (-1);
7393
7394 maxx = x;
7395
7396 fy = l/2;
7397
7398
7399 // Search for right x location of fy
7400
7401 p = maxx + params[0];
7402 step = params[0];
7403 lold = -2.0;
7404 l = -1e300;
7405 i = 0;
7406
7407
7408 while ( (l != lold) && (i < MAXCALLS) ) {
7409 i++;
7410
7411 lold = l;
7412 x = p + step;
7413 l = TMath::Abs(langaufun(&x,params) - fy);
7414
7415 if (l > lold)
7416 step = -step/10;
7417
7418 p += step;
7419 }
7420
7421 if (i == MAXCALLS)
7422 return (-2);
7423
7424 fxr = x;
7425
7426
7427 // Search for left x location of fy
7428
7429 p = maxx - 0.5 * params[0];
7430 step = -params[0];
7431 lold = -2.0;
7432 l = -1e300;
7433 i = 0;
7434
7435 while ( (l != lold) && (i < MAXCALLS) ) {
7436 i++;
7437
7438 lold = l;
7439 x = p + step;
7440 l = TMath::Abs(langaufun(&x,params) - fy);
7441
7442 if (l > lold)
7443 step = -step/10;
7444
7445 p += step;
7446 }
7447
7448 if (i == MAXCALLS)
7449 return (-3);
7450
7451
7452 fxl = x;
7453
7454 FWHM = fxr - fxl;
7455 return (0);
7456}
7457
7458