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