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