]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PMD/AliPMDCalibPedestal.cxx
Try to get correct calibration object - in meant time the TRD track written to the...
[u/mrichter/AliRoot.git] / PMD / AliPMDCalibPedestal.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 //Root includes
18 #include <TObjArray.h>
19 #include <TH1F.h>
20 #include <TString.h>
21 #include <TMath.h>
22 #include <TF1.h>
23 #include <TRandom.h>
24 #include <TDirectory.h>
25 #include <TFile.h>
26 #include "TTreeStream.h"
27
28 //AliRoot includes
29 #include "AliDAQ.h"
30 #include "AliLog.h"
31 #include "AliRawReader.h"
32 #include "AliPMDRawStream.h"
33 #include "AliPMDddldata.h"
34
35 //header file
36 #include "AliPMDCalibPedestal.h"
37
38
39 ClassImp(AliPMDCalibPedestal)
40
41
42 AliPMDCalibPedestal::AliPMDCalibPedestal() :
43   TObject()
44 {
45     //
46     // default constructor
47     //
48
49     for (int i = 0; i < kDet; i++)
50     {
51         for (int j = 0; j < kMaxSMN; j++)
52         {
53             for (int k = 0; k < kMaxRow; k++)
54             {
55                 for (int l = 0; l < kMaxCol; l++)
56                 {
57                     fPedVal[i][j][k][l]   = 0.;
58                     fPedValSq[i][j][k][l] = 0.;
59                     fPedCount[i][j][k][l] = 0.;
60                 }
61             }
62         }
63     }
64
65
66 }
67 //_____________________________________________________________________
68 AliPMDCalibPedestal::AliPMDCalibPedestal(const AliPMDCalibPedestal &ped) :
69   TObject(ped)
70 {
71     //
72     // copy constructor
73     //
74     for (int i = 0; i < kDet; i++)
75     {
76         for (int j = 0; j < kMaxSMN; j++)
77         {
78             for (int k = 0; k < kMaxRow; k++)
79             {
80                 for (int l = 0; l < kMaxCol; l++)
81                 {
82                     fPedVal[i][j][k][l]   = ped.fPedVal[i][j][k][l];
83                     fPedValSq[i][j][k][l] = ped.fPedValSq[i][j][k][l];
84                     fPedCount[i][j][k][l] = ped.fPedCount[i][j][k][l];
85                 }
86             }
87         }
88     }
89     
90 }
91 //_____________________________________________________________________
92 AliPMDCalibPedestal& AliPMDCalibPedestal::operator = (const  AliPMDCalibPedestal &source)
93 {
94   //
95   // assignment operator
96   //
97   if (&source == this) return *this;
98   new (this) AliPMDCalibPedestal(source);
99
100   return *this;
101 }
102 //_____________________________________________________________________
103 AliPMDCalibPedestal::~AliPMDCalibPedestal()
104 {
105     //
106     // destructor
107     //
108 }
109 //_____________________________________________________________________
110 Bool_t AliPMDCalibPedestal::ProcessEvent(AliRawReader *rawReader)
111 {
112   //
113   //  Event processing loop - AliRawReader
114   //
115
116     const Int_t kDDL = AliDAQ::NumberOfDdls("PMD");
117
118     AliPMDRawStream rawStream(rawReader);
119
120     TObjArray pmdddlcont;
121     Bool_t streamout = kTRUE;
122
123     for (Int_t iddl = 0; iddl < kDDL; iddl++)
124     {
125         rawReader->Select("PMD", iddl, iddl);
126         //cout << reader.GetDataSize() << endl;
127         streamout = rawStream.DdlData(iddl, &pmdddlcont);
128         Int_t ientries = pmdddlcont.GetEntries();
129         for (Int_t ient = 0; ient < ientries; ient++)
130         {
131             AliPMDddldata *pmdddl = (AliPMDddldata*)pmdddlcont.UncheckedAt(ient);
132             
133             Int_t det = pmdddl->GetDetector();
134             Int_t smn = pmdddl->GetSMN();
135             //Int_t mcm = pmdddl->GetMCM();
136             //Int_t chno = pmdddl->GetChannel();
137             Int_t row = pmdddl->GetRow();
138             Int_t col = pmdddl->GetColumn();
139             Float_t sig = (Float_t) pmdddl->GetSignal();
140
141             fPedVal[det][smn][row][col]   += sig;
142             fPedValSq[det][smn][row][col] += sig*sig;
143             fPedCount[det][smn][row][col]++;
144         }
145         pmdddlcont.Clear();
146     }
147     return streamout;
148 }
149 //_____________________________________________________________________
150
151 void AliPMDCalibPedestal::Analyse(TTree *pedtree)
152 {
153     //
154     //  Calculate pedestal Mean and RMS
155     //
156     Int_t   det, sm, row, col;
157     Float_t mean, rms;
158     Float_t meansq, diff;
159
160
161     pedtree->Branch("det",&det,"det/I");
162     pedtree->Branch("sm",&sm,"sm/I");
163     pedtree->Branch("row",&row,"row/I");
164     pedtree->Branch("col",&col,"col/I");
165     pedtree->Branch("mean",&mean,"mean/F");
166     pedtree->Branch("rms",&rms,"rms/F");
167
168     for (int idet = 0; idet < kDet; idet++)
169     {
170         for (int ism = 0; ism < kMaxSMN; ism++)
171         {
172             for (int irow = 0; irow < kMaxRow; irow++)
173             {
174                 for (int icol = 0; icol < kMaxCol; icol++)
175                 {
176                     det  = idet;
177                     sm   = ism;
178                     row  = irow;
179                     col  = icol;
180                     if (fPedCount[idet][ism][irow][icol] > 0)
181                     {
182                         mean = fPedVal[idet][ism][irow][icol]/fPedCount[idet][ism][irow][icol];
183
184                         meansq = fPedValSq[idet][ism][irow][icol]/fPedCount[idet][ism][irow][icol];
185
186                         diff = meansq - mean*mean;
187                         if (diff > 0.)
188                         {
189                             rms  = sqrt(diff);
190                         }
191                         else
192                         {
193                             rms = 0.;
194                         }
195                     }
196
197                     pedtree->Fill();
198                 }
199             }
200         }
201     }
202 }
203 //_____________________________________________________________________