]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TPC/AliTPCCalROC.cxx
Bug fix
[u/mrichter/AliRoot.git] / TPC / AliTPCCalROC.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16
17 ///////////////////////////////////////////////////////////////////////////////
18 //                                                                           //
19 //  Calibration base class for a single ROC                                  //
20 //  Contains one float value per pad                                         //
21 //     mapping of the pads taken form AliTPCROC                              //
22 //                                                                           //
23 ///////////////////////////////////////////////////////////////////////////////
24
25 #include "AliTPCCalROC.h"
26 #include "TMath.h"
27 #include "TClass.h"
28 #include "TFile.h"
29 #include "TH2F.h"
30 ClassImp(AliTPCCalROC)
31
32
33 //_____________________________________________________________________________
34 AliTPCCalROC::AliTPCCalROC():TObject()
35 {
36   //
37   // Default constructor
38   //
39   fSector       =  0;
40   fNChannels    =  0;
41   fNRows        =  0;
42   fData         =  0;
43 }
44
45 //_____________________________________________________________________________
46 AliTPCCalROC::AliTPCCalROC(UInt_t  sector):TObject()
47 {
48   //
49   // Constructor that initializes a given sector
50   //
51   fSector = sector;
52   fNChannels    =  AliTPCROC::Instance()->GetNChannels(fSector);
53   fNRows        =  AliTPCROC::Instance()->GetNRows(fSector);
54   fIndexes      =  AliTPCROC::Instance()->GetRowIndexes(fSector);
55   fData = new Float_t[fNChannels];
56   for (UInt_t  idata = 0; idata< fNChannels; idata++) fData[idata] = 0.;
57 }
58
59 //_____________________________________________________________________________
60 AliTPCCalROC::AliTPCCalROC(const AliTPCCalROC &c):TObject(c)
61 {
62   //
63   // AliTPCCalROC copy constructor
64   //
65   fSector = c.fSector;
66   fNChannels    =  AliTPCROC::Instance()->GetNChannels(fSector);
67   fNRows        =  AliTPCROC::Instance()->GetNRows(fSector);
68   fIndexes      =  AliTPCROC::Instance()->GetRowIndexes(fSector);
69   //
70   fData   = new Float_t[fNChannels];
71   for (UInt_t  idata = 0; idata< fNChannels; idata++) fData[idata] = c.fData[idata];
72 }
73
74 //_____________________________________________________________________________
75 AliTPCCalROC::~AliTPCCalROC()
76 {
77   //
78   // AliTPCCalROC destructor
79   //
80   if (fData) {
81     delete [] fData;
82     fData = 0;
83   }
84 }
85
86
87
88 void AliTPCCalROC::Streamer(TBuffer &R__b)
89 {
90    // Stream an object of class AliTPCCalROC.
91    if (R__b.IsReading()) {
92       AliTPCCalROC::Class()->ReadBuffer(R__b, this);
93       fIndexes =  AliTPCROC::Instance()->GetRowIndexes(fSector);
94    } else {
95       AliTPCCalROC::Class()->WriteBuffer(R__b,this);
96    }
97 }
98
99
100
101 void AliTPCCalROC::Draw(Option_t* option){
102   //
103   // create histogram with values and draw it
104   //
105   UInt_t maxPad = 0;
106   for (UInt_t irow=0; irow<fNRows; irow++){
107     if (GetNPads(irow)>maxPad) maxPad = GetNPads(irow);
108   }
109   char  name[1000];
110   sprintf(name,"%s ROC%d",GetTitle(),fSector);
111   TH2F * his = new TH2F(name,name,fNRows+10,-5, fNRows+5, maxPad+10, -(Int_t(maxPad/2))-5, maxPad/2+5);
112   for (UInt_t irow=0; irow<fNRows; irow++){
113     UInt_t npads = (Int_t)GetNPads(irow);
114     for (UInt_t ipad=0; ipad<=npads; ipad++){
115       his->Fill(irow+0.5,Int_t(ipad)-Int_t(npads/2)+0.5,GetValue(irow,ipad));
116     }
117   }
118   his->Draw(option);
119 }
120
121
122 void AliTPCCalROC::Test(){
123   //
124   // example function to show functionality and tes AliTPCCalROC
125   //
126   AliTPCCalROC  roc0(0);  
127   for (UInt_t irow = 0; irow <roc0.GetNrows(); irow++){
128     for (UInt_t ipad = 0; ipad <roc0.GetNPads(irow); ipad++){
129       Float_t value  = irow+ipad/1000.;
130       roc0.SetValue(irow,ipad,value);
131     }
132   }
133   //
134   AliTPCCalROC roc1(roc0);
135   for (UInt_t irow = 0; irow <roc1.GetNrows(); irow++){
136     for (UInt_t ipad = 0; ipad <roc1.GetNPads(irow); ipad++){
137       Float_t value  = irow+ipad/1000.;
138       if (roc1.GetValue(irow,ipad)!=value){
139         printf("Read/Write error\trow=%d\tpad=%d\n",irow,ipad);
140       }
141     }
142   }  
143   TFile f("calcTest.root","recreate");
144   roc0.Write("Roc0");
145   AliTPCCalROC * roc2 = (AliTPCCalROC*)f.Get("Roc0");
146   f.Close();
147   //
148   for (UInt_t irow = 0; irow <roc0.GetNrows(); irow++){
149     if (roc0.GetNPads(irow)!=roc2->GetNPads(irow))
150       printf("NPads - Read/Write error\trow=%d\n",irow);
151     for (UInt_t ipad = 0; ipad <roc1.GetNPads(irow); ipad++){
152       Float_t value  = irow+ipad/1000.;
153       if (roc2->GetValue(irow,ipad)!=value){
154         printf("Read/Write error\trow=%d\tpad=%d\n",irow,ipad);
155       }
156     }
157   }   
158 }
159