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