]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EMCAL/AliEMCALPreprocessor.cxx
Effective c++, committed on behalf of �ystein Djuvsland
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALPreprocessor.cxx
CommitLineData
9e788b10 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/* History of cvs commits:
18 *
80c68391 19 * $Log$
76ba7c99 20 * Revision 1.6 2007/04/29 15:06:19 gustavo
21 * New return value, and some minor fixes
22 *
09744db4 23 * Revision 1.5 2007/02/01 15:02:42 gustavo
24 * Added log message in case there are no source files
25 *
57363a01 26 * Revision 1.4 2007/01/24 16:57:14 gustavo
27 * Calibratio file sources machines are now not hardcoded but retreived from shuttle
28 *
b3204f43 29 * Revision 1.3 2006/12/20 10:53:28 gustavo
30 * Change const char * by TString, change AliInfos per AliPreprocessor::Log or AliDebug
31 *
8e8e4fc8 32 * Revision 1.2 2006/12/12 17:16:09 gustavo
33 * Detector name hardcoded in Preprocesor with new detector name notation (3 letters). New way to take reference histogram to avoid problems in case of low number of entries or no existing histogram. Change return 0 by return 1
34 *
80c68391 35 * Revision 1.1 2006/12/07 16:32:16 gustavo
36 * First shuttle code, online calibration histograms producer, EMCAL preprocessor
37 *
9e788b10 38 *
39*/
40///////////////////////////////////////////////////////////////////////////////
41// EMCAL Preprocessor class. It runs by Shuttle at the end of the run,
42// calculates calibration coefficients and dead/bad channels
43// to be posted in OCDB
44//
45// Author: Boris Polichtchouk, 4 October 2006
46// Adapted for EMCAL by Gustavo Conesa Balbastre, October 2006
47///////////////////////////////////////////////////////////////////////////////
48
80c68391 49//Root
9e788b10 50#include "TFile.h"
51#include "TH1.h"
52#include "TMap.h"
53#include "TRandom.h"
80c68391 54#include "TKey.h"
55#include "TList.h"
8e8e4fc8 56#include "TString.h"
b3204f43 57#include "TObjString.h"
8e8e4fc8 58
80c68391 59//AliRoot
60#include "AliEMCALPreprocessor.h"
61#include "AliLog.h"
62#include "AliCDBMetaData.h"
63#include "AliEMCALCalibData.h"
9e788b10 64
65ClassImp(AliEMCALPreprocessor)
66
67//_______________________________________________________________________________________
68AliEMCALPreprocessor::AliEMCALPreprocessor() :
80c68391 69AliPreprocessor("EMC",0)
9e788b10 70{
71 //default constructor
72}
73
74//_______________________________________________________________________________________
80c68391 75AliEMCALPreprocessor::AliEMCALPreprocessor(AliShuttleInterface* shuttle):
76AliPreprocessor("EMC",shuttle)
9e788b10 77{
78 // Constructor
79}
80
81//_______________________________________________________________________________________
82UInt_t AliEMCALPreprocessor::Process(TMap* /*valueSet*/)
83{
84 // process data retrieved by the Shuttle
b3204f43 85
9e788b10 86 // The fileName with the histograms which have been produced by
87 // AliEMCALCalibHistoProducer.
88 // It is a responsibility of the SHUTTLE framework to form the fileName
09744db4 89
90 gRandom->SetSeed(0); //the seed is set to the current machine clock!
b3204f43 91 AliEMCALCalibData calibData;
80c68391 92
80c68391 93
b3204f43 94 TList* list = GetFileSources(kDAQ, "AMPLITUDES");
09744db4 95 if(!list) {
96 Log("Sources list not found, exit.");
97 return 1;
98 }
99
100 AliInfo("The following sources produced files with the id AMPLITUDES");
101 list->Print();
102
103 TIter iter(list);
104 TObjString *source;
105
106 while ((source = dynamic_cast<TObjString *> (iter.Next()))) {
107 AliInfo(Form("found source %s", source->String().Data()));
b3204f43 108
09744db4 109 TString fileName = GetFile(kDAQ, "AMPLITUDES", source->GetName());
110 Log(Form("Got filename: %s",fileName.Data()));
b3204f43 111
09744db4 112 TFile f(fileName);
b3204f43 113
09744db4 114 if(!f.IsOpen()) {
115 Log(Form("File %s is not opened, something goes wrong!",fileName.Data()));
116 return 0;
117 }
b3204f43 118
119
09744db4 120 const Int_t nMod=12; // 1:5 modules
121 const Int_t nCol=48; //1:56 columns in each module
122 Int_t nRow=24; //1:64 rows in each module
123 const Int_t nRowHalfSM = 12; //Supermodules 11 and 12 are half supermodules
b3204f43 124
09744db4 125 Double_t coeff;
126 char hnam[80];
127 TH1F* histo=0;
b3204f43 128
09744db4 129 //Get reference histogram
130 TList * keylist = f.GetListOfKeys();
131 Int_t nkeys = f.GetNkeys();
132 Bool_t ok = kFALSE;
133 TKey *key;
134 TString refHistoName= "";
135 Int_t ikey = 0;
136 Int_t counter = 0;
137 TH1F* hRef = new TH1F();
138
139 //Check if the file contains any histogram
140
141 if(nkeys< 2){
142 Log(Form("Not enough histograms for calibration, nhist = %d",nkeys));
143 return 1;
144 }
b3204f43 145
09744db4 146 while(!ok){
147 ikey = gRandom->Integer(nkeys);
148 key = (TKey*)keylist->At(ikey);
149 refHistoName = key->GetName();
150 hRef = (TH1F*)f.Get(refHistoName);
151 counter++;
152 // Check if the reference has too little statistics and
153 // if the histogram has the correct name (2 kinds, mod#col#row for
154 // reference here, and mod#, see AliEMCALHistoProducer.
155 if(refHistoName.Contains("col") && hRef->GetEntries()>2 && hRef->GetMean()>0)
156 ok=kTRUE;
157 if(!ok && counter >= nMod*nCol*nRow+nMod){
158 Log("No histogram with enough statistics for reference");
159 return 1;
160 }
161 }
b3204f43 162
09744db4 163 Double_t refMean=hRef->GetMean();
b3204f43 164
09744db4 165 // Calculates relative calibration coefficients for all non-zero channels
166
167 for(Int_t mod=0; mod<nMod; mod++) {
168 if(mod > 10) nRow = nRowHalfSM ;
169 for(Int_t col=0; col<nCol; col++) {
170 for(Int_t row=0; row<nRow; row++) {
171 sprintf(hnam,"mod%dcol%drow%d",mod,col,row);
172 histo = (TH1F*)f.Get(hnam);
173 //TODO: dead channels exclusion!
174 if(histo && histo->GetMean() > 0) {
175 coeff = histo->GetMean()/refMean;
176 calibData.SetADCchannel(mod+1,col+1,row+1,1./coeff);
177 AliDebug(1,Form("mod %d col %d row %d coeff %f\n",mod,col,row,coeff));
b3204f43 178 }
09744db4 179 else
180 calibData.SetADCchannel(mod+1,col+1,row+1,-111);
b3204f43 181 }
09744db4 182 }
183 }
184 f.Close();
185 }//while
b3204f43 186
09744db4 187 //Store EMCAL calibration data
188
189 AliCDBMetaData emcalMetaData;
76ba7c99 190 Bool_t emcalOK = Store("Calib", "Data", &calibData, &emcalMetaData);
b3204f43 191
09744db4 192 if(emcalOK) return 0;
193 else
194 return 1;
b3204f43 195
9e788b10 196}