1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
18 /////////////////////////////////////////////////////////////////////////////////
20 // AliTRDCalibraVector
22 // This class is for the vector methode of the TRD calibration.
25 // R. Bailhache (R.Bailhache@gsi.de)
27 //////////////////////////////////////////////////////////////////////////////////////
29 #include <TGraphErrors.h>
32 #include <TObjArray.h>
35 #include <TDirectory.h>
41 #include "AliTRDCalibraVector.h"
42 #include "AliTRDCommonParam.h"
44 ClassImp(AliTRDCalibraVector)
46 //______________________________________________________________________________________
47 AliTRDCalibraVector::AliTRDCalibraVector()
49 ,fVectorPH(new TObjArray())
50 ,fPlaPH(new TObjArray())
51 ,fVectorCH(new TObjArray())
52 ,fPlaCH(new TObjArray())
53 ,fVectorPRF(new TObjArray())
54 ,fPlaPRF(new TObjArray())
61 // Default constructor
66 //______________________________________________________________________________________
67 AliTRDCalibraVector::AliTRDCalibraVector(const AliTRDCalibraVector &c)
69 ,fVectorPH(new TObjArray())
70 ,fPlaPH(new TObjArray())
71 ,fVectorCH(new TObjArray())
72 ,fPlaCH(new TObjArray())
73 ,fVectorPRF(new TObjArray())
74 ,fPlaPRF(new TObjArray())
75 ,fNumberBinCharge(c.fNumberBinCharge)
76 ,fNumberBinPRF(c.fNumberBinPRF)
78 ,fPRFRange(c.fPRFRange)
83 for(Int_t k = 0; k < c.fVectorPH->GetEntriesFast(); k++){
84 AliTRDPInfo *obj = new AliTRDPInfo();
85 UShort_t *entries = new UShort_t[fTimeMax];
86 Float_t *sum = new Float_t[fTimeMax];
87 Float_t *sumsquare = new Float_t[fTimeMax];
88 for(Int_t i = 0; i < fTimeMax; i++){
89 entries[i] = ((AliTRDPInfo *)c.fVectorPH->UncheckedAt(k))->GetEntries()[i];
90 sum[i] = ((AliTRDPInfo *)c.fVectorPH->UncheckedAt(k))->GetSum()[i];
91 sumsquare[i] = ((AliTRDPInfo *)c.fVectorPH->UncheckedAt(k))->GetSumSquare()[i];
93 obj->SetEntries(entries);
95 obj->SetSumSquare(sumsquare);
96 fVectorPH->AddAt((TObject *)obj,k);
98 for(Int_t k = 0; k < c.fVectorPRF->GetEntriesFast(); k++){
99 AliTRDPInfo *obj = new AliTRDPInfo();
100 UShort_t *entries = new UShort_t[fNumberBinPRF];
101 Float_t *sum = new Float_t[fNumberBinPRF];
102 Float_t *sumsquare = new Float_t[fNumberBinPRF];
103 for(Int_t i = 0; i < fNumberBinPRF; i++){
104 entries[i] = ((AliTRDPInfo *)c.fVectorPRF->UncheckedAt(k))->GetEntries()[i];
105 sum[i] = ((AliTRDPInfo *)c.fVectorPRF->UncheckedAt(k))->GetSum()[i];
106 sumsquare[i] = ((AliTRDPInfo *)c.fVectorPRF->UncheckedAt(k))->GetSumSquare()[i];
108 obj->SetEntries(entries);
110 obj->SetSumSquare(sumsquare);
111 fVectorPRF->AddAt((TObject *)obj,k);
113 for(Int_t k = 0; k < c.fVectorCH->GetEntriesFast(); k++){
114 AliTRDCTInfo *obj = new AliTRDCTInfo();
115 UShort_t *entries = new UShort_t[fNumberBinCharge];
116 for(Int_t i = 0; i < fNumberBinCharge; i++){
117 entries[i] = ((AliTRDCTInfo *)c.fVectorCH->UncheckedAt(k))->GetEntries()[i];
119 obj->SetEntries(entries);
120 fVectorCH->AddAt((TObject *)obj,k);
122 for(Int_t k = 0; k < c.fPlaPH->GetEntriesFast(); k++){
123 AliTRDPlace *obj = new AliTRDPlace();
124 obj->SetPlace(((AliTRDPlace *)c.fPlaPH->UncheckedAt(k))->GetPlace());
125 fPlaPH->AddAt((TObject *)obj,k);
127 for(Int_t k = 0; k < c.fPlaCH->GetEntriesFast(); k++){
128 AliTRDPlace *obj = new AliTRDPlace();
129 obj->SetPlace(((AliTRDPlace *)c.fPlaCH->UncheckedAt(k))->GetPlace());
130 fPlaCH->AddAt((TObject *)obj,k);
132 for(Int_t k = 0; k < c.fPlaPRF->GetEntriesFast(); k++){
133 AliTRDPlace *obj = new AliTRDPlace();
134 obj->SetPlace(((AliTRDPlace *)c.fPlaPRF->UncheckedAt(k))->GetPlace());
135 fPlaPRF->AddAt((TObject *)obj,k);
139 //____________________________________________________________________________________
140 AliTRDCalibraVector::~AliTRDCalibraVector()
143 // AliTRDCalibraVector destructor
148 //_____________________________________________________________________________
149 Int_t AliTRDCalibraVector::SearchBin(Float_t value, Int_t i) const
157 Float_t fbinmax = value;
158 Int_t fNumberOfBin = -1;
164 fNumberOfBin = fNumberBinCharge;
169 fbinmax = TMath::Abs(fPRFRange);
170 fbinmin = -TMath::Abs(fPRFRange);
171 fNumberOfBin = fNumberBinPRF;
175 if ((value >= fbinmax) ||
181 reponse = (Int_t) ((fNumberOfBin*(value-fbinmin)) / (fbinmax-fbinmin));
188 //_____________________________________________________________________________
189 Int_t AliTRDCalibraVector::SearchInVector(Int_t group, Int_t i) const
192 // Search if the calibration group "group" has already been
193 // initialised by a previous track in the vector
197 for (Int_t k = 0; k < (Int_t) fPlaCH->GetEntriesFast(); k++) {
198 if (((AliTRDPlace *) fPlaCH->At(k))->GetPlace() == group) {
206 for (Int_t k = 0; k < (Int_t) fPlaPH->GetEntriesFast(); k++) {
207 if (((AliTRDPlace *) fPlaPH->At(k))->GetPlace() == group) {
215 for (Int_t k = 0; k < (Int_t) fPlaPRF->GetEntriesFast(); k++) {
216 if (((AliTRDPlace *) fPlaPRF->At(k))->GetPlace() == group) {
227 //_____________________________________________________________________________
228 Int_t AliTRDCalibraVector::SearchInTreeVector(TObjArray *vectorplace, Int_t group) const
231 // Search if the calibration group "group" is present in the tree
234 for (Int_t k = 0; k < (Int_t) vectorplace->GetEntriesFast(); k++) {
235 if (((AliTRDPlace *) vectorplace->At(k))->GetPlace() == group) {
244 //_____________________________________________________________________________
245 Bool_t AliTRDCalibraVector::UpdateVectorCH(Int_t group, Float_t value)
248 // Fill the vector if a new calibration group "group" or update the
249 // values of the calibration group "group" if already here
253 Int_t bin = SearchBin(value,0);
255 if ((bin < 0) || (bin >= fNumberBinCharge)) {
260 Int_t place = SearchInVector(group,0);
264 AliTRDPlace *placegroup = new AliTRDPlace();
265 placegroup->SetPlace(group);
266 fPlaCH->Add((TObject *) placegroup);
268 AliTRDCTInfo *fCHInfo = new AliTRDCTInfo();
269 UShort_t *entries = new UShort_t[fNumberBinCharge];
271 for(Int_t k = 0; k < fNumberBinCharge; k++) {
277 fCHInfo->SetEntries(entries);
279 fVectorCH->Add((TObject *) fCHInfo);
281 // Group already exits
284 AliTRDCTInfo *fCHInfo = new AliTRDCTInfo();
286 fCHInfo = ((AliTRDCTInfo *) fVectorCH->At(place));
287 UShort_t *entries = fCHInfo->GetEntries();
291 fCHInfo->SetEntries(entries);
293 fVectorCH->AddAt((TObject *) fCHInfo,place);
300 //_____________________________________________________________________________
301 Bool_t AliTRDCalibraVector::UpdateVectorPRF(Int_t group, Float_t x, Float_t y)
304 // Fill the vector if a new calibration group "group" or update the
305 // values of the calibration group "group" if already here
309 Int_t bin = SearchBin(x,2);
311 if ((bin < 0) || (bin >= fNumberBinPRF)) {
316 Int_t place = SearchInVector(group,2);
321 AliTRDPlace *placegroup = new AliTRDPlace();
322 placegroup->SetPlace(group);
323 fPlaPRF->Add((TObject *) placegroup);
324 AliTRDPInfo *fPRFInfo = new AliTRDPInfo();
326 Float_t *sum = new Float_t[fNumberBinPRF];
327 Float_t *sumsquare = new Float_t[fNumberBinPRF];
328 UShort_t *entries = new UShort_t[fNumberBinPRF];
331 for (Int_t k = 0; k < fNumberBinPRF; k++) {
339 sumsquare[bin] += y*y;
343 fPRFInfo->SetSum(sum);
344 fPRFInfo->SetSumSquare(sumsquare);
345 fPRFInfo->SetEntries(entries);
348 fVectorPRF->Add((TObject *) fPRFInfo);
351 // Group already exits
354 AliTRDPInfo *fPRFInfo = new AliTRDPInfo();
356 fPRFInfo = (AliTRDPInfo *) fVectorPRF->At(place);
358 Float_t *sum = fPRFInfo->GetSum();
359 Float_t *sumsquare = fPRFInfo->GetSumSquare();
360 UShort_t *entries = fPRFInfo->GetEntries();
363 Double_t calcul = (((Double_t) fPRFInfo->GetEntries()[bin])
364 * ((Double_t) fPRFInfo->GetSum()[bin]) + (Double_t) y)
365 / (((Double_t) fPRFInfo->GetEntries()[bin]) + 1);
366 sum[bin] = (Float_t) calcul;
367 Double_t calculsquare = (((Double_t) fPRFInfo->GetSumSquare()[bin])
368 * ((Double_t) fPRFInfo->GetEntries()[bin]) + ((Double_t) y)*((Double_t) y))
369 / (((Double_t) fPRFInfo->GetEntries()[bin]) + 1);
370 sumsquare[bin] = (Float_t) calculsquare;
374 fPRFInfo->SetSum(sum);
375 fPRFInfo->SetSumSquare(sumsquare);
376 fPRFInfo->SetEntries(entries);
379 fVectorPRF->AddAt((TObject *) fPRFInfo,place);
387 //_____________________________________________________________________________
388 Bool_t AliTRDCalibraVector::UpdateVectorPH(Int_t group, Int_t time, Float_t value)
391 // Fill the vector if a new calibration group "group" or update
392 // the values of the calibration group "group" if already here
404 Int_t place = SearchInVector(group,1);
409 AliTRDPlace *placegroup = new AliTRDPlace();
410 placegroup->SetPlace(group);
411 fPlaPH->Add((TObject *) placegroup);
412 AliTRDPInfo *fPHInfo = new AliTRDPInfo();
414 Float_t *sum = new Float_t[fTimeMax];
415 Float_t *sumsquare = new Float_t[fTimeMax];
416 UShort_t *entries = new UShort_t[fTimeMax];
419 for (Int_t k = 0; k < fTimeMax; k++) {
427 sumsquare[bin] += value*value;
431 fPHInfo->SetSum(sum);
432 fPHInfo->SetSumSquare(sumsquare);
433 fPHInfo->SetEntries(entries);
436 fVectorPH->Add((TObject *) fPHInfo);
439 // Group already exits
442 AliTRDPInfo *fPHInfo = new AliTRDPInfo();
444 fPHInfo = (AliTRDPInfo *) fVectorPH->At(place);
446 Float_t *sum = fPHInfo->GetSum();
447 Float_t *sumsquare = fPHInfo->GetSumSquare();
448 UShort_t *entries = fPHInfo->GetEntries();
451 Double_t calcul = (((Double_t) fPHInfo->GetEntries()[bin])
452 * ((Double_t) fPHInfo->GetSum()[bin]) + (Double_t) value)
453 / (((Double_t) fPHInfo->GetEntries()[bin]) + 1);
454 sum[bin] = (Float_t) calcul;
455 Double_t calculsquare = ((((Double_t) fPHInfo->GetSumSquare()[bin])
456 * ((Double_t) fPHInfo->GetEntries()[bin]))
457 + (((Double_t) value) * ((Double_t)value)))
458 / (((Double_t) fPHInfo->GetEntries()[bin]) + 1);
459 sumsquare[bin] = (Float_t) calculsquare;
463 fPHInfo->SetSum(sum);
464 fPHInfo->SetSumSquare(sumsquare);
465 fPHInfo->SetEntries(entries);
468 fVectorPH->AddAt((TObject *) fPHInfo,place);
476 //_____________________________________________________________________________
477 TGraphErrors *AliTRDCalibraVector::ConvertVectorPHisto(Int_t place
478 , const Char_t * name) const
481 // Convert the PInfo in a TGraphErrors
484 AliTRDPInfo *pInfo = new AliTRDPInfo();
486 pInfo = ((AliTRDPInfo *) fVectorPH->At(place));
488 histo = ConvertVectorPHistoI((AliTRDPInfo *)pInfo, name);
494 //_____________________________________________________________________________
495 TGraphErrors *AliTRDCalibraVector::ConvertVectorPHistoI(AliTRDPInfo *pInfo
496 , const Char_t *name) const
499 // Convert the PInfo in a 1D grapherror, name must contains "PRF"
500 // if PRF calibration and not "PRF" for Vdrift calibration
504 const Char_t *pattern1 = "PRF";
507 AliTRDCommonParam *parCom = AliTRDCommonParam::Instance();
509 AliInfo("Could not get CommonParam, take the default 10MHz");
512 sf = parCom->GetSamplingFrequency();
524 if (strstr(name,pattern1)) {
525 ntimes = fNumberBinPRF;
530 x = new Double_t[ntimes]; // Xaxis
531 y = new Double_t[ntimes]; // Sum
532 ex = new Double_t[ntimes]; // Nentries
533 ey = new Double_t[ntimes]; // Sum of square/nentries
536 if (!strstr(name,pattern1)) {
541 step = (2*TMath::Abs(fPRFRange)) / fNumberBinPRF;
542 min = -TMath::Abs(fPRFRange) + step / 2.0;
546 for (Int_t k = 0; k < ntimes; k++) {
551 // Fill only if there is more than 0 something
552 if (pInfo->GetEntries()[k] > 0) {
553 ex[k] = pInfo->GetEntries()[k];
554 y[k] = pInfo->GetSum()[k];
555 ey[k] = pInfo->GetSumSquare()[k];
559 // Define the TGraphErrors
560 histo = new TGraphErrors(ntimes,x,y,ex,ey);
561 histo->SetTitle(name);
566 //_____________________________________________________________________________
567 TH1F *AliTRDCalibraVector::ConvertVectorCTHisto(Int_t place
568 , const Char_t * name) const
571 // Convert the CTInfo in a 1D histo
574 AliTRDCTInfo *cHInfo = new AliTRDCTInfo();
576 cHInfo = ((AliTRDCTInfo *) fVectorCH->At(place));
578 histo = ConvertVectorCTHistoI((AliTRDCTInfo *)cHInfo,(const Char_t *) name);
584 //_____________________________________________________________________________
585 TH1F *AliTRDCalibraVector::ConvertVectorCTHistoI(AliTRDCTInfo *cTInfo
586 , const Char_t * name) const
589 // Convert the CTInfo in a 1D histo
594 Int_t ntimes = fNumberBinCharge;
595 UShort_t *entries = cTInfo->GetEntries();
598 histo = new TH1F(name,name,fNumberBinCharge,0,300);
601 for (Int_t k = 0; k < ntimes; k++) {
602 histo->SetBinContent(k+1,entries[k]);
603 histo->SetBinError(k+1,TMath::Sqrt(TMath::Abs(entries[k])));
610 //_____________________________________________________________________________
611 TTree *AliTRDCalibraVector::ConvertVectorCTTreeHisto(TObjArray *vVectorCT
614 , const Char_t *nametitle) const
617 // Convert the vector in a tree with two branchs: the group number
618 // and the TH1F histo reconstructed from the vector
621 // Size of the things
622 Int_t ntotal = (Int_t) pPlaCT->GetEntriesFast();
624 AliInfo("nothing to write!");
625 TTree *treeCT = new TTree(name,nametitle);
629 // Variable of the tree
630 Int_t groupnumber = -1; // Group calibration
632 TObjArray vectorCT = *vVectorCT;
633 TObjArray plaCT = *pPlaCT;
636 TTree *treeCT = new TTree(name,nametitle);
637 treeCT->Branch("groupnumber",&groupnumber,"groupnumber/I");
638 treeCT->Branch("histo","TH1F",&histo,32000,0);
644 groupnumber = ((AliTRDPlace *) plaCT.At(0))->GetPlace();
646 histo = ConvertVectorCTHistoI(((AliTRDCTInfo *) vectorCT.At(0)),nome);
648 vectorCT.RemoveAt(0);
659 //_____________________________________________________________________________
660 TTree *AliTRDCalibraVector::ConvertVectorPTreeHisto(TObjArray *vVectorP
663 , const Char_t *nametitle) const
666 // Convert the vector in a tree with two branchs: the group number
667 // and the TGraphErrors histo reconstructed from the vector.
668 // The name must contain "PRF" for PRF calibration and not "PRF"
669 // for Vdrift calibration
672 // Size of the things
673 Int_t ntotal = (Int_t) pPlaP->GetEntriesFast();
675 AliInfo("nothing to write!");
676 TTree *treeP = new TTree(name,nametitle);
680 // Variable of the tree
681 Int_t groupnumber = -1; // Group calibration
682 TGraphErrors *histo = 0x0;
683 TObjArray vectorP = *vVectorP;
684 TObjArray plaP = *pPlaP;
687 TTree *treeP = new TTree(name,nametitle);
688 treeP->Branch("groupnumber",&groupnumber,"groupnumber/I");
689 treeP->Branch("histo","TGraphErrors",&histo,32000,0);
695 groupnumber = ((AliTRDPlace *) plaP.At(0))->GetPlace();
697 histo = ConvertVectorPHistoI((AliTRDPInfo *) vectorP.At(0),nome);
710 //_____________________________________________________________________________
711 TObjArray *AliTRDCalibraVector::ConvertTreeVector(TTree *tree) const
714 // Convert the branch groupnumber of the tree taken from
715 // TRD.calibration.root in case of vector method in a std::vector
720 TObjArray *vectorplace = new TObjArray();
722 // Variable of the tree
723 Int_t groupnumber = -1; // Group calibration
726 tree->SetBranchAddress("groupnumber",&groupnumber);
729 Int_t ntotal = tree->GetEntries();
730 for (Int_t k = 0; k < ntotal; k++) {
732 AliTRDPlace *placegroupnumber = new AliTRDPlace();
733 placegroupnumber->SetPlace(groupnumber);
734 vectorplace->Add((TObject *) placegroupnumber);
741 //_____________________________________________________________________________
742 Bool_t AliTRDCalibraVector::MergeVectorCT(TObjArray *vVectorCT2, TObjArray *pPlaCT2)
745 // Add the two vectors and place the result in the first
748 if (((Int_t) pPlaCT2->GetEntriesFast()) != ((Int_t) vVectorCT2->GetEntriesFast())){
749 AliInfo("VectorCT2 doesn't correspond to PlaCT2!");
754 for (Int_t k = 0; k < (Int_t) fPlaCH->GetEntriesFast(); k++) {
756 // Look if PlaCT1[k] it is also in the second vector
758 for (Int_t j = 0; j < (Int_t) pPlaCT2->GetEntriesFast(); j++) {
759 if (((AliTRDPlace *) pPlaCT2->At(j))->GetPlace() ==
760 ((AliTRDPlace *) fPlaCH->At(k))->GetPlace()) {
766 // If not in the second vector nothing to do
768 // If in the second vector
771 AliTRDCTInfo *fCTInfo = new AliTRDCTInfo();
772 UShort_t *entries = new UShort_t[fNumberBinCharge];
774 for (Int_t nu = 0; nu < fNumberBinCharge; nu++) {
775 entries[nu] = ((AliTRDCTInfo *) fVectorCH->At(((AliTRDPlace *) fPlaCH->At(k))->GetPlace()))->GetEntries()[nu]
776 + ((AliTRDCTInfo *) vVectorCT2->At(((AliTRDPlace *) fPlaCH->At(k))->GetPlace()))->GetEntries()[nu];
780 fCTInfo->SetEntries(entries);
782 // Nothing to do on PlaCT1
785 fVectorCH->AddAt((TObject *) fCTInfo,((AliTRDPlace *) fPlaCH->At(k))->GetPlace());
791 // And at the end the vector in CT2 but not in CH1
792 for (Int_t k = 0; k < (Int_t) pPlaCT2->GetEntriesFast(); k++) {
794 // Look if pPlaCT2[k] it is also in the second vector
796 for (Int_t j = 0; j < (Int_t) fPlaCH->GetEntriesFast(); j++) {
797 if (((AliTRDPlace *) fPlaCH->At(j))->GetPlace() == ((AliTRDPlace *) pPlaCT2->At(k))->GetPlace()) {
803 // If not in the first vector
806 AliTRDCTInfo *fCTInfo = new AliTRDCTInfo();
807 fCTInfo = ((AliTRDCTInfo *) vVectorCT2->At(((AliTRDPlace *) pPlaCT2->At(k))->GetPlace()));
810 fPlaCH->Add((TObject *) (pPlaCT2->At(k)));
811 fVectorCH->Add((TObject *) fCTInfo);
821 //_____________________________________________________________________________
822 Bool_t AliTRDCalibraVector::MergeVectorP(TObjArray *vVectorP2
827 // Add the two vectors and place the result in the first
830 if (((Int_t) pPlaP2->GetEntriesFast()) != ((Int_t) vVectorP2->GetEntriesFast())) {
831 AliInfo("VectorP2 doesn't correspond to PlaP2!");
838 for (Int_t k = 0; k < (Int_t) fPlaPH->GetEntriesFast(); k++) {
840 // Look if fPlaPH[k] it is also in the second vector
842 for (Int_t j = 0; j < (Int_t) pPlaP2->GetEntriesFast(); j++) {
843 if (((AliTRDPlace *) pPlaP2->At(j))->GetPlace() == ((AliTRDPlace *) fPlaPH->At(k))->GetPlace()) {
849 // If not in the second vector nothing to do
851 // If in the second vector
854 AliTRDPInfo *fPInfo = new AliTRDPInfo();
855 UShort_t *entries = new UShort_t[fTimeMax];
856 Float_t *sum = new Float_t[fTimeMax];
857 Float_t *sumsquare = new Float_t[fTimeMax];
859 for (Int_t nu = 0; nu < fTimeMax; nu++) {
861 entries[nu] = ((AliTRDPInfo *) fVectorPH->At(((AliTRDPlace *) fPlaPH->At(k))->GetPlace()))->GetEntries()[nu]
862 + ((AliTRDPInfo *) vVectorP2->At(((AliTRDPlace *) fPlaPH->At(k))->GetPlace()))->GetEntries()[nu];
864 Double_t calcul = ((((Double_t) ((AliTRDPInfo *) fVectorPH->At(((AliTRDPlace *) fPlaPH->At(k))->GetPlace()))->GetSum()[nu])
865 * ((Double_t) ((AliTRDPInfo *) fVectorPH->At(((AliTRDPlace *) fPlaPH->At(k))->GetPlace()))->GetEntries()[nu]))
866 + (((Double_t) ((AliTRDPInfo *) vVectorP2->At(((AliTRDPlace *) fPlaPH->At(k))->GetPlace()))->GetSum()[nu])
867 * ((Double_t) ((AliTRDPInfo *) vVectorP2->At(((AliTRDPlace *) fPlaPH->At(k))->GetPlace()))->GetEntries()[nu])))
868 / ((Double_t) fPInfo->GetEntries()[nu]);
870 sum[nu] = (Float_t) calcul;
872 Double_t calculsquare = ((((Double_t) ((AliTRDPInfo *) fVectorPH->At(((AliTRDPlace *) fPlaPH->At(k))->GetPlace()))->GetSumSquare()[nu])
873 * ((Double_t) ((AliTRDPInfo *) fVectorPH->At(((AliTRDPlace *) fPlaPH->At(k))->GetPlace()))->GetEntries()[nu]))
874 + (((Double_t) ((AliTRDPInfo *) vVectorP2->At(((AliTRDPlace *) fPlaPH->At(k))->GetPlace()))->GetSumSquare()[nu])
875 * ((Double_t) ((AliTRDPInfo *) vVectorP2->At(((AliTRDPlace *) fPlaPH->At(k))->GetPlace()))->GetEntries()[nu])))
876 / ((Double_t) fPInfo->GetEntries()[nu]);
878 sumsquare[nu] = calculsquare;
884 fPInfo->SetSumSquare(sumsquare);
885 fPInfo->SetEntries(entries);
887 // Nothing to do on PlaCT1
889 // Update the vector VectorCT1
890 fVectorPH->AddAt((TObject *) fPInfo,((AliTRDPlace *) fPlaPH->At(k))->GetPlace());
896 // And at the end the vector in P2 but not in CH1
897 for (Int_t k = 0; k < (Int_t) pPlaP2->GetEntriesFast(); k++) {
899 // Look if PlaCT2[k] it is also in the second vector
901 for (Int_t j = 0; j < (Int_t) fPlaPH->GetEntriesFast(); j++) {
902 if (((AliTRDPlace *) fPlaPH->At(j))->GetPlace() == ((AliTRDPlace *) pPlaP2->At(k))->GetPlace()) {
908 // If not in the first vector
911 AliTRDPInfo *fPInfo = new AliTRDPInfo();
912 fPInfo = (AliTRDPInfo *) vVectorP2->At(((AliTRDPlace *) pPlaP2->At(k))->GetPlace());
914 // Add at the end of CH1
915 fPlaPH->Add(((TObject *) pPlaP2->At(k)));
916 fVectorPH->Add((TObject *) fPInfo);
927 for (Int_t k = 0; k < (Int_t) fPlaPRF->GetEntriesFast(); k++) {
929 // Look if fPlaPRF[k] it is also in the second vector
931 for (Int_t j = 0; j < (Int_t) pPlaP2->GetEntriesFast(); j++) {
932 if (((AliTRDPlace *) pPlaP2->At(j))->GetPlace() == ((AliTRDPlace *) fPlaPRF->At(k))->GetPlace()) {
938 // If not in the second vector nothing to do
940 // If in the second vector
943 AliTRDPInfo *fPInfo = new AliTRDPInfo();
944 UShort_t *entries = new UShort_t[fNumberBinPRF];
945 Float_t *sum = new Float_t[fNumberBinPRF];
946 Float_t *sumsquare = new Float_t[fNumberBinPRF];
948 for (Int_t nu = 0; nu < fNumberBinPRF; nu++) {
950 entries[nu] = ((AliTRDPInfo *) fVectorPRF->At(((AliTRDPlace *) fPlaPRF->At(k))->GetPlace()))->GetEntries()[nu]
951 + ((AliTRDPInfo *) vVectorP2->At(((AliTRDPlace *) fPlaPRF->At(k))->GetPlace()))->GetEntries()[nu];
953 Double_t calcul = ((((Double_t) ((AliTRDPInfo *) fVectorPRF->At(((AliTRDPlace *) fPlaPRF->At(k))->GetPlace()))->GetSum()[nu])
954 * ((Double_t) ((AliTRDPInfo *) fVectorPRF->At(((AliTRDPlace *) fPlaPRF->At(k))->GetPlace()))->GetEntries()[nu]))
955 + (((Double_t) ((AliTRDPInfo *) vVectorP2->At(((AliTRDPlace *) fPlaPRF->At(k))->GetPlace()))->GetSum()[nu])
956 * ((Double_t) ((AliTRDPInfo *) vVectorP2->At(((AliTRDPlace *) fPlaPRF->At(k))->GetPlace()))->GetEntries()[nu])))
957 / ((Double_t) fPInfo->GetEntries()[nu]);
959 sum[nu] = (Float_t) calcul;
961 Double_t calculsquare = ((((Double_t) ((AliTRDPInfo *) fVectorPRF->At(((AliTRDPlace *) fPlaPRF->At(k))->GetPlace()))->GetSumSquare()[nu])
962 * ((Double_t) ((AliTRDPInfo *) fVectorPRF->At(((AliTRDPlace *) fPlaPRF->At(k))->GetPlace()))->GetEntries()[nu]))
963 + (((Double_t) ((AliTRDPInfo *) vVectorP2->At(((AliTRDPlace *) fPlaPRF->At(k))->GetPlace()))->GetSumSquare()[nu])
964 * ((Double_t) ((AliTRDPInfo *) vVectorP2->At(((AliTRDPlace *) fPlaPRF->At(k))->GetPlace()))->GetEntries()[nu])))
965 / ((Double_t) fPInfo->GetEntries()[nu]);
967 sumsquare[nu] = calculsquare;
973 fPInfo->SetSumSquare(sumsquare);
974 fPInfo->SetEntries(entries);
976 // Nothing to do on PlaCT1
978 // Update the vector VectorCT1
979 fVectorPRF->AddAt((TObject *) fPInfo,((AliTRDPlace *) fPlaPRF->At(k))->GetPlace());
985 // And at the end the vector in P2 but not in CH1
986 for (Int_t k = 0; k < (Int_t) pPlaP2->GetEntriesFast(); k++) {
988 // Look if PlaCT2[k] it is also in the second vector
990 for (Int_t j = 0; j < (Int_t) fPlaPRF->GetEntriesFast(); j++) {
991 if (((AliTRDPlace *) fPlaPRF->At(j))->GetPlace() == ((AliTRDPlace *) pPlaP2->At(k))->GetPlace()) {
997 // If not in the first vector
1000 AliTRDPInfo *fPInfo = new AliTRDPInfo();
1001 fPInfo = (AliTRDPInfo *) vVectorP2->At(((AliTRDPlace *) pPlaP2->At(k))->GetPlace());
1003 // Add at the end of CH1
1004 fPlaPRF->Add(((TObject *) pPlaP2->At(k)));
1005 fVectorPRF->Add((TObject *) fPInfo);
1017 //_____________________________________________________________________________
1018 TTree *AliTRDCalibraVector::Sum2Trees(const Char_t *filename1
1019 , const Char_t *filename2
1020 , const Char_t *variablecali)
1023 // It returns the sum of two trees with the name variablecali
1024 // in the files filenam1 and filename2 equivalent of merging two 2D histos
1025 // The name of the resulting tree is the same as the two input trees
1026 // variablecali can be treeCH2d, treePH2d or treePRF2d
1030 TChain *treeChain = new TChain(variablecali);
1031 TObjArray *vectorplace = new TObjArray();
1032 TObjArray *where = new TObjArray();
1036 TFile *file1 = new TFile(filename1,"READ");
1037 TTree *tree1 = (TTree *) file1->Get(variablecali);
1042 vectorplace = ConvertTreeVector(tree1);
1044 // Say where it is in tree 1
1045 for (Int_t jui = 0; jui < (Int_t) vectorplace->GetEntriesFast(); jui++) {
1046 AliTRDPlace *placejui = new AliTRDPlace();
1047 placejui->SetPlace(jui);
1048 TObjArray *chainplace = new TObjArray();
1049 chainplace->Add((TObject *) placejui);
1050 where->Add((TObject *) chainplace);
1054 treeChain->Add(filename1);
1059 TFile *file2 = new TFile(filename2,"READ");
1060 TTree *tree2 = (TTree *) file2->Get(variablecali);
1065 TObjArray *vector2 = ConvertTreeVector(tree2);
1066 Int_t j = treeChain->GetEntries();
1068 for (Int_t jui = 0; jui < (Int_t) vector2->GetEntriesFast(); jui++) {
1069 // Search if already found
1070 Int_t place = SearchInTreeVector(vectorplace,((AliTRDPlace *) vector2->At(jui))->GetPlace());
1071 // Create a new element in the two std vectors
1073 AliTRDPlace *placejjui = new AliTRDPlace();
1074 placejjui->SetPlace((j+jui));
1075 TObjArray *chainplace = new TObjArray();
1076 chainplace->Add((TObject *) placejjui);
1077 vectorplace->Add((TObject *) (vector2->At(jui)));
1078 where->Add((TObject *) chainplace);
1080 // Update the element at the place "place" in the std vector whereinthechain
1082 AliTRDPlace *placejjui = new AliTRDPlace();
1083 placejjui->SetPlace((j+jui));
1084 TObjArray *chainplace = ((TObjArray *) where->At(place));
1085 chainplace->Add((TObject *) placejjui);
1086 where->AddAt((TObject *) chainplace,place);
1091 treeChain->Add(filename2);
1094 // Take care of the profile
1095 const Char_t *pattern = "P";
1098 if (!strstr(variablecali,pattern)) {
1100 // Ready to read the chain
1102 treeChain->SetBranchAddress("histo",&his);
1104 // Initialise the final tree
1106 TH1F *histsum = 0x0;
1108 tree = new TTree(variablecali,variablecali);
1109 tree->Branch("groupnumber",&group,"groupnumber/I");
1110 tree->Branch("histo","TH1F",&histsum,32000,0);
1113 if (treeChain->GetEntries() < 1) {
1117 for (Int_t h = 0; h < (Int_t) vectorplace->GetEntriesFast(); h++) {
1118 group = ((AliTRDPlace *) vectorplace->At(h))->GetPlace();
1119 TObjArray *chainplace = ((TObjArray *) where->At(h));
1120 treeChain->GetEntry(((AliTRDPlace *) chainplace->At(0))->GetPlace());
1121 //Init for the first time
1123 histsum = new TH1F("","",his->GetXaxis()->GetNbins()
1124 ,his->GetXaxis()->GetBinLowEdge(1)
1125 ,his->GetXaxis()->GetBinUpEdge(his->GetXaxis()->GetNbins()));
1128 // Reset for each new group
1129 histsum->SetEntries(0.0);
1130 for (Int_t l = 0; l <= histsum->GetXaxis()->GetNbins(); l++) {
1131 histsum->SetBinContent(l,0.0);
1132 histsum->SetBinError(l,0.0);
1134 histsum->Add(his,1);
1135 if ((Int_t) chainplace->GetEntriesFast() > 1) {
1136 for (Int_t s = 1; s < (Int_t) chainplace->GetEntriesFast(); s++) {
1137 treeChain->GetEntry(((AliTRDPlace *) chainplace->At(s))->GetPlace());
1138 histsum->Add(his,1);
1147 // Ready to read the chain
1148 TGraphErrors *his = 0x0;
1149 treeChain->SetBranchAddress("histo",&his);
1151 // Initialise the final tree
1153 TGraphErrors *histsum = 0x0;
1154 Double_t *xref = 0x0;
1156 tree = new TTree(variablecali,variablecali);
1157 tree->Branch("groupnumber",&group,"groupnumber/I");
1158 tree->Branch("histo","TGraphErrors",&histsum,32000,0);
1161 if (treeChain->GetEntries() < 1) {
1165 for (Int_t h = 0; h < (Int_t) vectorplace->GetEntriesFast(); h++) {
1167 group = ((AliTRDPlace *) vectorplace->At(h))->GetPlace();
1168 TObjArray *chainplace = ((TObjArray *) where->At(h));
1169 treeChain->GetEntry(((AliTRDPlace *) chainplace->At(0))->GetPlace());
1170 //Init or reset for a new group
1171 Int_t nbins = his->GetN();
1173 x = new Double_t[nbins];
1176 ex = new Double_t[nbins];
1178 y = new Double_t[nbins];
1180 ey = new Double_t[nbins];
1182 for (Int_t lo = 0; lo < nbins; lo++) {
1189 histsum = new TGraphErrors(nbins,x,y,ex,ey);
1192 histsum = AddProfiles(his,histsum);
1193 if ((Int_t) chainplace->GetEntriesFast() > 1) {
1194 for (Int_t s = 1; s < (Int_t) chainplace->GetEntriesFast(); s++) {
1195 treeChain->GetEntry(((AliTRDPlace *) chainplace->At(s))->GetPlace());
1196 histsum = AddProfiles(his,histsum);
1210 //_____________________________________________________________________________
1211 TGraphErrors *AliTRDCalibraVector::AddProfiles(TGraphErrors *hist1
1212 , TGraphErrors *hist2) const
1215 // In the case of the vectors method we use TGraphErrors for PH and PRF
1216 // to be able to add the them after
1217 // Here we add the TGraphErrors
1220 // First TGraphErrors
1221 Int_t nbins1 = hist1->GetN();
1222 Double_t *x1 = hist1->GetX();
1223 Double_t *ex1 = hist1->GetEX();
1224 Double_t *y1 = hist1->GetY();
1225 Double_t *ey1 = hist1->GetEY();
1227 TGraphErrors *rehist = new TGraphErrors(nbins1);
1229 // Second TGraphErrors
1230 Double_t *ex2 = hist2->GetEX();
1231 Double_t *y2 = hist2->GetY();
1232 Double_t *ey2 = hist2->GetEY();
1234 // Define the Variables for the new TGraphErrors
1240 for (Int_t k = 0; k < nbins1; k++) {
1241 Double_t nentries = 0.0;
1246 if ((ex2[k] == 0.0) &&
1250 if ((ex2[k] == 0.0) &&
1257 if ((ex2[k] > 0.0) &&
1264 if ((ex2[k] > 0.0) &&
1266 nentries = ex1[k] + ex2[k];
1267 y = ( y1[k]*ex1[k]+ y2[k]*ex2[k]) / nentries;
1268 ey = (ey1[k]*ex1[k]+ey2[k]*ex2[k]) / nentries;
1271 rehist->SetPoint(k,x,y);
1272 rehist->SetPointError(k,ex,ey);