]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PMD/AliPMDCalibrator.cxx
- Compute parameter covariances including absorber dispersion effects
[u/mrichter/AliRoot.git] / PMD / AliPMDCalibrator.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 // Author : Z. Ahamed
19
20 #include "TF1.h"
21 #include "TFile.h"
22 #include "TObjString.h"
23 #include "TROOT.h"
24 #include "TClonesArray.h"
25 #include "TH1F.h"
26 #include "TObjArray.h"
27
28 // --- Standard library ---
29
30 // --- AliRoot header files ---
31 #include "AliLog.h"
32 #include "AliRawReaderFile.h"
33 #include "AliPMDCalibrator.h"
34 #include "AliRawReaderDate.h"
35 #include "AliPMDRawStream.h"
36 #include "AliPMDCalibData.h"
37 #include "AliPMDddldata.h"
38 #include "AliCDBManager.h"
39 #include "AliCDBId.h"
40 #include "AliCDBMetaData.h"
41 #include "AliDAQ.h"
42
43 ClassImp(AliPMDCalibrator)
44
45 //const Int_t kDet    = 2;
46 //const Int_t kMaxSMN = 24;
47 //const Int_t kMaxRow = 48;
48 //const Int_t kMaxCol = 96;
49
50 AliPMDCalibrator::AliPMDCalibrator():
51   fCalibGain(new AliPMDCalibData())
52 {
53   // Standard Constructor
54   for(Int_t idet = 0; idet < kDet; idet++)
55     {
56       for(Int_t ismn = 0; ismn < kMaxSMN; ismn++)
57         {
58           fHsmIso[idet][ismn] = NULL ;
59           for(Int_t jrow = 0; jrow < kMaxRow; jrow++)
60             {
61               for(Int_t kcol = 0; kcol < kMaxCol; kcol++)
62                 {
63                   fGainFact[idet][ismn][jrow][kcol] = 0.0;
64                   fHadcIso[idet][ismn][jrow][kcol]  = NULL;
65                 }
66             }
67         }
68     }
69 }
70 // ------------------------------------------------------------------------ //
71 AliPMDCalibrator::AliPMDCalibrator(const AliPMDCalibrator &pmdcalibrator):
72   fCalibGain(new AliPMDCalibData())
73 {
74   for(Int_t idet = 0; idet < 2; idet++)
75     {
76       for(Int_t ismn = 0; ismn < kMaxSMN; ismn++)
77         {
78           fHsmIso[idet][ismn] = pmdcalibrator.fHsmIso[idet][ismn] ;
79           for(Int_t jrow = 0; jrow < kMaxRow; jrow++)
80             {
81               for(Int_t kcol = 0; kcol < kMaxCol; kcol++)
82                 {
83                   fGainFact[idet][ismn][jrow][kcol] = pmdcalibrator.fGainFact[idet][ismn][jrow][kcol];
84                   fHadcIso[idet][ismn][jrow][kcol]  = pmdcalibrator.fHadcIso[idet][ismn][jrow][kcol];
85                 }
86             }
87         }
88     }
89
90 }
91 // ------------------------------------------------------------------------ //
92 AliPMDCalibrator &AliPMDCalibrator::operator=(const AliPMDCalibrator &pmdcalibrator)
93 {
94   if(this != &pmdcalibrator)
95     {
96       for(Int_t idet = 0; idet < kDet; idet++)
97         {
98           for(Int_t ismn = 0; ismn < kMaxSMN; ismn++)
99             {
100               fHsmIso[idet][ismn] = pmdcalibrator.fHsmIso[idet][ismn] ;
101               for(Int_t jrow = 0; jrow < kMaxRow;jrow++)
102                 {
103                   for(Int_t kcol = 0; kcol < kMaxCol; kcol++)
104                     {
105                       fGainFact[idet][ismn][jrow][kcol] =
106                         pmdcalibrator.fGainFact[idet][ismn][jrow][kcol];
107                       fHadcIso[idet][ismn][jrow][kcol]  =
108                         pmdcalibrator.fHadcIso[idet][ismn][jrow][kcol];
109                     }
110                 }
111             }
112         }
113     }
114   return *this;
115 }
116 // ------------------------------------------------------------------------ //
117 AliPMDCalibrator::~AliPMDCalibrator()
118 {
119   // dtor
120   if(fHsmIso)  delete fHsmIso ;
121   if(fHadcIso) delete fHadcIso ;
122   delete fCalibGain;
123 }
124 // ------------------------------------------------------------------------ //
125
126 void AliPMDCalibrator::Exec()
127 {
128   // reads parameters and does the calibration
129   CalculateIsoCell() ;
130
131 }
132 // ------------------------------------------------------------------------ //
133
134 void AliPMDCalibrator::Init()
135 {
136   // intializes everything
137   char hname[kMaxSMN];
138   char hname24[kMaxSMN];
139   char hnameiso[120];
140   char htitle1[120];
141
142   for(Int_t d = 0; d < kDet; d++) {
143     for(Int_t i1 = 0; i1 < kMaxSMN; i1++) {
144       sprintf(hname,"det_%d_iso_sm_%2d",d,i1);
145       sprintf(hname24,"det_%d_iso_sm_%2d",d,i1);
146       fHsmIso[d][i1]= new TH1F(hname,hname24,100,0,1000);
147       for(Int_t j1 = 0; j1 < kMaxRow; j1++) {
148         for(Int_t k1 = 0; k1 < kMaxCol; k1++) {
149           sprintf(hnameiso,"Isolated Cell ADC for det_%d_cell_sm%d_row%d_col%d"
150                   ,d,i1,j1,k1);
151           sprintf(htitle1,"Isolated Cell ADC for det_%d_cell_sm%d_row%d_col%d"
152                   ,d,i1,j1,k1);
153           
154           TObject *old=gDirectory->GetList()->FindObject(hnameiso);
155           if (old) gDirectory->GetList()->Remove(old);
156           fHadcIso[d][i1][j1][k1] = new TH1F(hnameiso,htitle1,100,0.,4000.);
157         }
158       }
159     }
160   }
161   
162 }
163
164 // ------------------------------------------------------------------------ //
165
166 void AliPMDCalibrator::CalculateIsoCell()
167 {
168   // Calculates the ADC of isolated cell
169
170   TObjArray pmdddlcont;
171   const Int_t kDDL           = AliDAQ::NumberOfDdls("PMD");
172   const Int_t kMaxHit        = 60000;
173   const Int_t kCellNeighbour = 6;
174
175   Int_t neibx[6] = {1,0,-1,-1,0,1};
176   Int_t neiby[6] = {0,1,1,0,-1,-1};
177   
178   Int_t id1,jd1; //neighbour row/col
179   Int_t countisocell = 0 ;//number of isilated cell
180   Int_t isocount; //number of neighbours with 0 signal
181   Int_t d1[kDet][kMaxSMN][kMaxRow][kMaxCol];
182   Int_t ch[kDet][kMaxSMN][kMaxRow][kMaxCol];
183   Int_t maxhit;
184   
185   
186   Int_t det[kMaxHit],smn[kMaxHit];
187   Int_t row[kMaxHit],col[kMaxHit],sig[kMaxHit],chno[kMaxHit];
188
189   for(Int_t idet = 0; idet < kDet; idet++)
190     {
191       for(Int_t ismn = 0; ismn < kMaxSMN; ismn++)
192         {
193           for(Int_t irow = 0; irow < kMaxRow; irow++)
194             {
195               for(Int_t icol = 0; icol < kMaxCol; icol++)
196                 {
197                   d1[idet][ismn][irow][icol] = 0;
198                   ch[idet][ismn][irow][icol] = 0;
199                 }
200             }
201         }
202     }
203   //accessing raw data
204   AliRawReaderFile reader(".");
205   AliPMDRawStream stream(&reader);
206   while(reader.NextEvent())
207     {
208       // New PMD Reader is plugged in
209       
210       for (Int_t iddl = 0; iddl < kDDL; iddl++)
211         {
212           reader.Select("PMD", iddl, iddl);
213           stream.DdlData(iddl,&pmdddlcont);
214           
215           Int_t ientries = pmdddlcont.GetEntries();
216           for (Int_t ient = 0; ient < ientries; ient++)
217             {
218               AliPMDddldata *pmdddl = (AliPMDddldata*)pmdddlcont.UncheckedAt(ient);
219               
220               Int_t idet = pmdddl->GetDetector();
221               Int_t ismn = pmdddl->GetSMN();
222               //Int_t mcm = pmdddl->GetMCM();
223               Int_t ichno = pmdddl->GetChannel();
224               Int_t irow = pmdddl->GetRow();
225               Int_t icol = pmdddl->GetColumn();
226               Int_t isig = pmdddl->GetSignal();
227               
228               if (isig>0)
229                 {
230                   d1[idet][ismn][irow][icol] = isig;
231                   ch[idet][ismn][irow][icol] = ichno;
232                 }
233             }
234           pmdddlcont.Clear();
235         }
236
237
238       maxhit = 0;
239       
240       for(Int_t idet=0; idet < kDet; idet++)
241         {
242           for(Int_t ismn = 0; ismn < kMaxSMN; ismn++)
243             {
244               for(Int_t irow = 0; irow < kMaxRow; irow++)
245                 {
246                   for(Int_t icol = 0; icol < kMaxCol; icol++)
247                     {
248                       
249                       //printf("d1[%d][%d][%d][%d]=%d\n",
250                       //det,ksmn,irow,jcol, d1[det][ksmn][irow][jcol] ); 
251                       //printf("ch[%d][%d][%d][%d]=%d\n",
252                       //det,ksmn,irow,jcol, ch[det][ksmn][irow][jcol] ); 
253                       
254                       if(d1[idet][ismn][irow][icol] > 0)
255                         {
256                           isocount = 0;
257                           for(Int_t ii = 0; ii < kCellNeighbour; ii++)
258                             {
259                               id1 = irow + neibx[ii];
260                               jd1 = icol + neiby[ii];
261                               if(d1[idet][ismn][id1][jd1] == 0)
262                                 {
263                                   isocount++;
264                                   if(isocount == kCellNeighbour)
265                                     {
266                                       countisocell++;
267                                       det[maxhit]  = idet;
268                                       smn[maxhit]  = ismn;
269                                       row[maxhit]  = irow;
270                                       col[maxhit]  = icol;
271                                       sig[maxhit]  = d1[idet][ismn][irow][icol];
272                                       chno[maxhit] = ch[idet][ismn][irow][icol];
273                                       maxhit++;
274                                       fHsmIso[idet][ismn]->Fill(d1[idet][ismn][irow][icol]);
275                                       fHadcIso[idet][ismn][irow][icol]->Fill(d1[idet][ismn][irow][icol]);
276                                     }
277                                 }
278                             }  // neigh cell cond.
279                         }     // d>0 cond.
280                     }
281                 }
282             }
283         } //event loop
284     }
285   Double_t histMean[kDet][kMaxSMN];
286   Double_t isoMean[kDet][kMaxSMN][kMaxRow][kMaxCol];
287
288   for(Int_t d1 = 0; d1 < kDet; d1++)
289     {
290       for(Int_t i1 = 0; i1 < kMaxSMN; i1++)
291         {
292           histMean[d1][i1]= fHsmIso[d1][i1]->GetMean();
293           for(Int_t j1 = 0; j1 < kMaxRow; j1++)
294             {
295               for(Int_t k1 = 0; k1 < kMaxCol; k1++)
296                 {
297                   isoMean[d1][i1][j1][k1]=fHadcIso[d1][i1][j1][k1]->GetMean();
298                   if(isoMean[d1][i1][j1][k1]>0.0 && histMean[d1][i1]>0.0)
299                     {
300                       fGainFact[d1][i1][j1][k1]=isoMean[d1][i1][k1][j1]/histMean[d1][i1];
301                       Float_t gain = fGainFact[d1][i1][j1][k1];
302                       fCalibGain->SetGainFact(d1,i1,j1,k1,gain);
303                     }                              
304                 }
305             }
306         }
307     }
308   
309 }
310 // ------------------------------------------------------------------------ //
311 Bool_t AliPMDCalibrator::Store()
312 {
313   AliCDBManager *man = AliCDBManager::Instance();
314   //man->SetDefaultStorage("local://$ALICE_ROOT");
315   if(!man->IsDefaultStorageSet()) return kFALSE;
316   AliCDBId id("PMD/Calib/Data",0,0);
317   AliCDBMetaData md;
318   md.SetResponsible("Zubayer");
319   md.SetBeamPeriod(0);
320   md.SetAliRootVersion("28.02.2006");
321   md.SetComment("Test");
322   
323   printf("\n\n\n fCalibData\n");
324   //fCalibData->Print(0);
325   //printf("\n\n\n fCalibData\n");
326   
327   Bool_t result = man->Put(fCalibGain,id,&md);
328
329   return result;
330 }
331