]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PHOS/AliPHOSPreprocessor.cxx
bd90e1c54ed26debf2580b0c39cb5bf4fa6b8149
[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 #include "TList.h"
36 #include "TObjString.h"
37
38 ClassImp(AliPHOSPreprocessor)
39
40 //_______________________________________________________________________________________
41 AliPHOSPreprocessor::AliPHOSPreprocessor() :
42 AliPreprocessor("PHS",0)
43 {
44   //default constructor
45 }
46
47 //_______________________________________________________________________________________
48 AliPHOSPreprocessor::AliPHOSPreprocessor(AliShuttleInterface* shuttle):
49 AliPreprocessor("PHS",shuttle)
50 {
51   // Constructor
52 }
53
54 //_______________________________________________________________________________________
55 UInt_t AliPHOSPreprocessor::Process(TMap* /*valueSet*/)
56 {
57   // process data retrieved by the Shuttle
58
59   // The fileName with the histograms which have been produced by
60   // AliPHOSCalibHistoProducer.
61   // It is a responsibility of the SHUTTLE framework to form the fileName
62   
63   AliPHOSEmcCalibData calibData;
64   
65   TList* list = GetFileSources(kDAQ, "AMPLITUDES");
66   if(!list) {
67     Log("Sources list not found, exit.");
68     return 0;
69   }
70
71   TIter iter(list);
72   TObjString *source;
73
74   while ((source = dynamic_cast<TObjString *> (iter.Next()))) {
75     AliInfo(Form("found source %s", source->String().Data()));
76
77     TString fileName = GetFile(kDAQ, "AMPLITUDES", source->GetName());
78     AliInfo(Form("Got filename: %s",fileName.Data()));
79
80     TFile f(fileName);
81
82     if(!f.IsOpen()) {
83       Log(Form("File %s is not opened, something goes wrong!",fileName.Data()));
84       return 0;
85     }
86
87     const Int_t nMod=5; // 1:5 modules
88     const Int_t nCol=56; //1:56 columns in each module
89     const Int_t nRow=64; //1:64 rows in each module
90
91     Double_t coeff;
92     char hnam[80];
93     TH1F* histo=0;
94
95     //Get the reference histogram
96     //(author: Gustavo Conesa Balbastre)
97
98     TList * keylist = f.GetListOfKeys();
99     Int_t nkeys   = f.GetNkeys();
100     Bool_t ok = kFALSE;
101     TKey  *key;
102     TString refHistoName= "";
103     Int_t ikey = 0;
104     Int_t counter = 0;
105     TH1F* hRef = 0;
106
107     //Check if the file contains any histogram
108     
109     if(nkeys< 2){
110       Log(Form("Not enough histograms (%d) for calibration.",nkeys));
111       return 1;
112     }
113
114     while(!ok){
115       ikey = gRandom->Integer(nkeys);
116       key = (TKey*)keylist->At(ikey);
117       refHistoName = key->GetName();
118       hRef = (TH1F*)f.Get(refHistoName);
119       counter++;
120       // Check if the reference histogram has too little statistics
121       if(hRef->GetEntries()>2) ok=kTRUE;
122       if(!ok && counter >= nMod*nCol*nRow){
123         Log("No histogram with enough statistics for reference.");
124         return 1;
125       }
126     }
127
128     Log(Form("reference histogram %s, %.1f entries, mean=%.3f, rms=%.3f.",
129              hRef->GetName(),hRef->GetEntries(),
130              hRef->GetMean(),hRef->GetRMS()));
131
132     Double_t refMean=hRef->GetMean();
133
134     // Calculates relative calibration coefficients for all non-zero channels
135
136     for(Int_t mod=0; mod<nMod; mod++) {
137       for(Int_t col=0; col<nCol; col++) {
138         for(Int_t row=0; row<nRow; row++) {
139           sprintf(hnam,"mod%dcol%drow%d",mod,col,row);
140           histo = (TH1F*)f.Get(hnam);
141           //TODO: dead channels exclusion!
142           if(histo) {
143             coeff = histo->GetMean()/refMean;
144             calibData.SetADCchannelEmc(mod+1,col+1,row+1,0.001/coeff);
145             AliInfo(Form("mod %d col %d row %d  coeff %f\n",mod,col,row,coeff));
146           }
147           else
148             calibData.SetADCchannelEmc(mod+1,col+1,row+1,0.001); 
149         }
150       }
151     }
152     
153     f.Close();
154   }
155   
156   AliCDBMetaData metaData;
157   Int_t result = Store("Calib", "EmcData", &calibData, &metaData);
158
159   return result;
160
161 }