]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PHOS/AliPHOSPreprocessor.cxx
09370c44557dd025ed4d25648a49007f81e9a368
[u/mrichter/AliRoot.git] / PHOS / AliPHOSPreprocessor.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 /* $Id$ */
17
18 ///////////////////////////////////////////////////////////////////////////////
19 // PHOS Preprocessor class. It runs by Shuttle at the end of the run,
20 // calculates calibration coefficients and dead/bad channels
21 // to be posted in OCDB
22 //
23 // Author: Boris Polichtchouk, 4 October 2006
24 ///////////////////////////////////////////////////////////////////////////////
25
26 #include "AliPHOSPreprocessor.h"
27 #include "AliLog.h"
28 #include "AliCDBMetaData.h"
29 #include "AliPHOSEmcCalibData.h"
30 #include "TFile.h"
31 #include "TH1.h"
32 #include "TMap.h"
33 #include "TRandom.h"
34 #include "TKey.h"
35
36 ClassImp(AliPHOSPreprocessor)
37
38 //_______________________________________________________________________________________
39 AliPHOSPreprocessor::AliPHOSPreprocessor() :
40 AliPreprocessor("PHS",0)
41 {
42   //default constructor
43 }
44
45 //_______________________________________________________________________________________
46 AliPHOSPreprocessor::AliPHOSPreprocessor(AliShuttleInterface* shuttle):
47 AliPreprocessor("PHS",shuttle)
48 {
49   // Constructor
50 }
51
52 //_______________________________________________________________________________________
53 UInt_t AliPHOSPreprocessor::Process(TMap* /*valueSet*/)
54 {
55   // process data retrieved by the Shuttle
56
57   // The fileName with the histograms which have been produced by
58   // AliPHOSCalibHistoProducer.
59   // It is a responsibility of the SHUTTLE framework to form the fileName
60
61   const char* fileName = GetFile(kDAQ, "AMPLITUDES", "GDC");
62   AliInfo(Form("Got filename: %s",fileName));
63
64   TFile f(fileName);
65
66   if(!f.IsOpen()) {
67     AliInfo(Form("File %s is not opened, something goes wrong!",fileName));
68     return 0;
69   }
70
71   const Int_t nMod=5; // 1:5 modules
72   const Int_t nCol=56; //1:56 columns in each module
73   const Int_t nRow=64; //1:64 rows in each module
74
75   Double_t coeff;
76   char hnam[80];
77   TH1F* histo=0;
78
79   //Get the reference histogram
80   //(author: Gustavo Conesa Balbastre)
81
82   TList * keylist = f.GetListOfKeys();
83   Int_t nkeys   = f.GetNkeys();
84   Bool_t ok = kFALSE;
85   TKey  *key;
86   TString refHistoName= "";
87   Int_t ikey = 0;
88   Int_t counter = 0;
89   TH1F* hRef = 0;
90
91   //Check if the file contains any histogram
92
93   if(nkeys< 2){
94     AliInfo(Form("Not enough histograms (%d) for calibration.",nkeys));
95     return 0;
96   }
97
98   while(!ok){
99     ikey = gRandom->Integer(nkeys);
100     key = (TKey*)keylist->At(ikey);
101     refHistoName = key->GetName();
102     hRef = (TH1F*)f.Get(refHistoName);
103     counter++;
104     // Check if the reference histogram has too little statistics
105     if(hRef->GetEntries()>2) ok=kTRUE;
106     if(!ok && counter >= nMod*nCol*nRow){
107       AliInfo("No histogram with enough statistics for reference.");
108       return 0;
109     }
110   }
111
112   AliInfo(Form("reference histogram %s, %.1f entries, mean=%.3f, rms=%.3f.",
113          hRef->GetName(),hRef->GetEntries(),
114          hRef->GetMean(),hRef->GetRMS()));
115
116   AliPHOSEmcCalibData calibData;
117   Double_t refMean=hRef->GetMean();
118
119   // Calculates relative calibration coefficients for all non-zero channels
120
121   for(Int_t mod=0; mod<nMod; mod++) {
122     for(Int_t col=0; col<nCol; col++) {
123       for(Int_t row=0; row<nRow; row++) {
124         sprintf(hnam,"mod%dcol%drow%d",mod,col,row);
125         histo = (TH1F*)f.Get(hnam);
126         //TODO: dead channels exclusion!
127         if(histo) {
128           coeff = histo->GetMean()/refMean;
129           calibData.SetADCchannelEmc(mod+1,col+1,row+1,0.001/coeff);
130           AliInfo(Form("mod %d col %d row %d  coeff %f\n",mod,col,row,coeff));
131         }
132         else
133           calibData.SetADCchannelEmc(mod+1,col+1,row+1,0.001); 
134       }
135     }
136   }
137
138   AliCDBMetaData metaData;
139   Int_t result = Store("Calib", "EmcData", &calibData, &metaData);
140
141   f.Close();
142   return result;
143
144 }