]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PMD/AliPMDCalibGain.cxx
07d8bc05edb50d670ee8abbc628bf441279a1ea7
[u/mrichter/AliRoot.git] / PMD / AliPMDCalibGain.cxx
1 //////////////////////////////////////////////////////////////////////////////
2 //
3 // * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 // *                                                                        *
5 // * Author: The ALICE Off-line Project.                                    *
6 // * Contributors are mentioned in the code where appropriate.              *
7 // *                                                                        *
8 // * Permission to use, copy, modify and distribute this software and its   *
9 // * documentation strictly for non-commercial purposes is hereby granted   *
10 // * without fee, provided that the above copyright notice appears in all   *
11 // * copies and that both the copyright notice and this permission notice   *
12 // * appear in the supporting documentation. The authors make no claims     *
13 // * about the suitability of this software for any purpose. It is          *
14 // * provided "as is" without express or implied warranty.                  *
15 // **************************************************************************/
16 //
17 //////////////////////////////////////////////////////////////////////////////
18
19 #include "TF1.h"
20 #include "TFile.h"
21 #include "TObjString.h"
22 #include "TROOT.h"
23 #include "TClonesArray.h"
24 #include "TH1F.h"
25 #include "TObjArray.h"
26 #include "TTree.h"
27
28 // --- Standard library ---
29
30 // --- AliRoot header files ---
31 #include "AliDAQ.h"
32 #include "AliLog.h"
33 #include "AliRawReader.h"
34 #include "AliPMDRawStream.h"
35 #include "AliPMDddldata.h"
36 #include "AliPMDCalibGain.h"
37
38 ClassImp(AliPMDCalibGain)
39
40 AliPMDCalibGain::AliPMDCalibGain(): TObject()
41 {
42   // Standard Constructor
43     for(Int_t idet = 0; idet < kDet; idet++)
44     {
45         for(Int_t ismn = 0; ismn < kMaxSMN; ismn++)
46         {
47             fSMIso[idet][ismn]   = 0.;
48             fSMCount[idet][ismn] = 0.;
49             for(Int_t jrow = 0; jrow < kMaxRow; jrow++)
50             {
51                 for(Int_t kcol = 0; kcol < kMaxCol; kcol++)
52                 {
53                     fCellIso[idet][ismn][jrow][kcol]   = 0.;
54                     fCellCount[idet][ismn][jrow][kcol] = 0.;
55                 }
56             }
57         }
58     }
59
60 }
61 // ------------------------------------------------------------------------ //
62 AliPMDCalibGain::AliPMDCalibGain(const AliPMDCalibGain &pmdcalibgain):
63     TObject(pmdcalibgain)
64 {
65     for(Int_t idet = 0; idet < kDet; idet++)
66     {
67         for(Int_t ismn = 0; ismn < kMaxSMN; ismn++)
68         {
69             fSMIso[idet][ismn] = pmdcalibgain.fSMIso[idet][ismn] ;
70             fSMCount[idet][ismn] = pmdcalibgain.fSMCount[idet][ismn] ;
71             for(Int_t jrow = 0; jrow < kMaxRow; jrow++)
72             {
73                 for(Int_t kcol = 0; kcol < kMaxCol; kcol++)
74                 {
75                     fCellIso[idet][ismn][jrow][kcol]  = pmdcalibgain.fCellIso[idet][ismn][jrow][kcol];
76                     fCellCount[idet][ismn][jrow][kcol]  = pmdcalibgain.fCellCount[idet][ismn][jrow][kcol];
77                 }
78             }
79         }
80     }
81     
82 }
83 // ------------------------------------------------------------------------ //
84 AliPMDCalibGain &AliPMDCalibGain::operator=(const AliPMDCalibGain &pmdcalibgain)
85 {
86     if(this != &pmdcalibgain)
87     {
88         for(Int_t idet = 0; idet < kDet; idet++)
89         {
90             for(Int_t ismn = 0; ismn < kMaxSMN; ismn++)
91             {
92                 fSMIso[idet][ismn] = pmdcalibgain.fSMIso[idet][ismn];
93                 fSMCount[idet][ismn] = pmdcalibgain.fSMCount[idet][ismn];
94                 for(Int_t jrow = 0; jrow < kMaxRow;jrow++)
95                 {
96                     for(Int_t kcol = 0; kcol < kMaxCol; kcol++)
97                     {
98                         fCellIso[idet][ismn][jrow][kcol]  =
99                             pmdcalibgain.fCellIso[idet][ismn][jrow][kcol];
100                         fCellCount[idet][ismn][jrow][kcol]  =
101                             pmdcalibgain.fCellCount[idet][ismn][jrow][kcol];
102                     }
103                 }
104             }
105         }
106     }
107     return *this;
108 }
109 // ------------------------------------------------------------------------ //
110 AliPMDCalibGain::~AliPMDCalibGain()
111 {
112     // dtor
113
114 }
115 // ------------------------------------------------------------------------ //
116 Bool_t AliPMDCalibGain::ProcessEvent(AliRawReader *rawReader)
117 {
118   // Calculates the ADC of isolated cell
119
120   TObjArray pmdddlcont;
121
122   const Int_t kDDL           = AliDAQ::NumberOfDdls("PMD");
123   const Int_t kCellNeighbour = 6;
124
125   Int_t neibx[6] = {1,0,-1,-1,0,1};
126   Int_t neiby[6] = {0,1,1,0,-1,-1};
127   
128   Int_t id1,jd1;  //neighbour row/col
129   Int_t isocount; //number of neighbours with 0 signal
130
131   Float_t d1[kDet][kMaxSMN][kMaxRow][kMaxCol];
132
133   for(Int_t idet = 0; idet < kDet; idet++)
134     {
135       for(Int_t ismn = 0; ismn < kMaxSMN; ismn++)
136         {
137           for(Int_t irow = 0; irow < kMaxRow; irow++)
138             {
139               for(Int_t icol = 0; icol < kMaxCol; icol++)
140                 {
141                   d1[idet][ismn][irow][icol] = 0.;
142                 }
143             }
144         }
145     }
146
147   AliPMDRawStream rawStream(rawReader);
148
149   Int_t iddl;
150
151   Int_t numberofDDLs = 0;
152
153     while ((iddl = rawStream.DdlData(&pmdddlcont)) >=0) {
154       numberofDDLs++;
155
156       Int_t ientries = pmdddlcont.GetEntries();
157       for (Int_t ient = 0; ient < ientries; ient++)
158       {
159           AliPMDddldata *pmdddl = (AliPMDddldata*)pmdddlcont.UncheckedAt(ient);
160           
161           Int_t idet = pmdddl->GetDetector();
162           Int_t ismn = pmdddl->GetSMN();
163           //Int_t mcm = pmdddl->GetMCM();
164           //Int_t ichno = pmdddl->GetChannel();
165           Int_t irow = pmdddl->GetRow();
166           Int_t icol = pmdddl->GetColumn();
167           Int_t isig = pmdddl->GetSignal();
168           
169           if (isig>0)
170           {
171               d1[idet][ismn][irow][icol] = (Float_t) isig;
172           }
173       }
174       pmdddlcont.Clear();
175   }
176   
177   for(Int_t idet=0; idet < kDet; idet++)
178   {
179       for(Int_t ismn = 0; ismn < kMaxSMN; ismn++)
180       {
181           for(Int_t irow = 0; irow < kMaxRow; irow++)
182           {
183               for(Int_t icol = 0; icol < kMaxCol; icol++)
184               {
185                   if(d1[idet][ismn][irow][icol] > 0)
186                   {
187                       isocount = 0;
188                       for(Int_t ii = 0; ii < kCellNeighbour; ii++)
189                       {
190                           id1 = irow + neibx[ii];
191                           jd1 = icol + neiby[ii];
192                           if(d1[idet][ismn][id1][jd1] == 0)
193                           {
194                               isocount++;
195                               if(isocount == kCellNeighbour)
196                               {
197
198                                   fSMIso[idet][ismn] += d1[idet][ismn][irow][icol];
199                                   fCellIso[idet][ismn][irow][icol] += d1[idet][ismn][irow][icol];
200                                   
201                                   fSMCount[idet][ismn]++;
202                                   fCellCount[idet][ismn][irow][icol]++;
203                                   
204                               }
205                           }
206                       }  // neigh cell cond.
207                   }     // d>0 cond.
208               }
209           }
210       }
211       
212   }
213
214   if (numberofDDLs < kDDL)
215       return kFALSE;
216   return kTRUE;
217
218 }
219 // ------------------------------------------------------------------------ //
220 void AliPMDCalibGain::Analyse(TTree *gaintree)
221 {
222     // Calculates the mean
223     Int_t   det, sm, row, col;
224     Float_t gain;
225     Float_t modmean  = 0.;
226     Float_t cellmean = 0.;
227
228     gaintree->Branch("det",&det,"det/I");
229     gaintree->Branch("sm",&sm,"sm/I");
230     gaintree->Branch("row",&row,"row/I");
231     gaintree->Branch("col",&col,"col/I");
232     gaintree->Branch("gain",&gain,"gain/F");
233
234     for(Int_t idet = 0; idet < kDet; idet++)
235     {
236         for(Int_t ism = 0; ism < kMaxSMN; ism++)
237         {
238
239             if (fSMCount[idet][ism] > 0)
240                 modmean = fSMIso[idet][ism]/fSMCount[idet][ism];
241
242             for(Int_t irow = 0; irow < kMaxRow; irow++)
243             {
244                 for(Int_t icol = 0; icol < kMaxCol; icol++)
245                 {
246                     if (fCellCount[idet][ism][irow][icol] > 0)
247                         cellmean = fCellIso[idet][ism][irow][icol]/fCellCount[idet][ism][irow][icol];
248                     
249                     
250                     det      = idet;
251                     sm       = ism;
252                     row      = irow;
253                     col      = icol;
254                     gain     = 1.;
255
256                     if(modmean > 0.0)
257                     {
258                         gain = cellmean/modmean;
259                     }
260                     gaintree->Fill();
261                 }
262             }
263         }
264     }
265     
266 }
267 // ------------------------------------------------------------------------ //