First shuttle code, online calibration histograms producer, EMCAL preprocessor
[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 *
19 * $Log$
20 *
21*/
22///////////////////////////////////////////////////////////////////////////////
23// EMCAL Preprocessor class. It runs by Shuttle at the end of the run,
24// calculates calibration coefficients and dead/bad channels
25// to be posted in OCDB
26//
27// Author: Boris Polichtchouk, 4 October 2006
28// Adapted for EMCAL by Gustavo Conesa Balbastre, October 2006
29///////////////////////////////////////////////////////////////////////////////
30
31#include "AliEMCALPreprocessor.h"
32#include "AliLog.h"
33#include "AliCDBMetaData.h"
34#include "AliEMCALCalibData.h"
35#include "TFile.h"
36#include "TH1.h"
37#include "TMap.h"
38#include "TRandom.h"
39
40ClassImp(AliEMCALPreprocessor)
41
42//_______________________________________________________________________________________
43AliEMCALPreprocessor::AliEMCALPreprocessor() :
44AliPreprocessor("EMCAL",0)
45{
46 //default constructor
47}
48
49//_______________________________________________________________________________________
50AliEMCALPreprocessor::AliEMCALPreprocessor(const char* detector, AliShuttleInterface* shuttle):
51AliPreprocessor(detector,shuttle)
52{
53 // Constructor
54}
55
56//_______________________________________________________________________________________
57UInt_t AliEMCALPreprocessor::Process(TMap* /*valueSet*/)
58{
59 // process data retrieved by the Shuttle
60
61 // The fileName with the histograms which have been produced by
62 // AliEMCALCalibHistoProducer.
63 // It is a responsibility of the SHUTTLE framework to form the fileName
64
65 const char* fileName = GetFile(kDAQ, "AMPLITUDES", "GDC");
66 AliInfo(Form("Got filename: %s",fileName));
67
68 TFile f(fileName);
69
70 if(!f.IsOpen()) {
71 AliInfo(Form("File %s is not opened, something goes wrong!",fileName));
72 return 0;
73 }
74
75 const Int_t nMod=12; // 1:5 modules
76 const Int_t nCol=48; //1:56 columns in each module
77 Int_t nRow=24; //1:64 rows in each module
78 const Int_t nRowHalfSM = 12; //Supermodules 11 and 12 are half supermodules
79
80 Double_t coeff;
81 char hnam[80];
82 TH1F* histo=0;
83
84 // Generate name of the reference histogram
85 TString refHistoName = "mod";
86 refHistoName += gRandom->Integer(nMod)+1;
87 refHistoName += "col";
88 refHistoName += gRandom->Integer(nCol)+1;
89 refHistoName += "row";
90 refHistoName += gRandom->Integer(nRow)+1;
91 TH1F* hRef = (TH1F*)f.Get(refHistoName);
92
93 // If the reference histogram does not exist or has too little statistics,
94 // it is better to give up preprocessing
95 if(!hRef || hRef->GetEntries()<2) {
96 AliInfo(Form("Cannot get reference histogram %s",refHistoName.Data()));
97 return 0;
98 }
99
100 AliEMCALCalibData calibData;
101 Double_t refMean=hRef->GetMean();
102 // Calculates relative calibration coefficients for all non-zero channels
103
104 for(Int_t mod=0; mod<nMod; mod++) {
105 if(mod > 10) nRow = nRowHalfSM ;
106 for(Int_t col=0; col<nCol; col++) {
107 for(Int_t row=0; row<nRow; row++) {
108 sprintf(hnam,"mod%dcol%drow%d",mod,col,row);
109 histo = (TH1F*)f.Get(hnam);
110 //TODO: dead channels exclusion!
111 if(histo) {
112 coeff = histo->GetMean()/refMean;
113 calibData.SetADCchannel(mod+1,col+1,row+1,1./coeff);
114 AliInfo(Form("mod %d col %d row %d coeff %f\n",mod,col,row,coeff));
115 }
116 else
117 calibData.SetADCchannel(mod+1,col+1,row+1,-111);
118 }
119 }
120 }
121
122 AliCDBMetaData metaData;
123 Int_t result = Store("Calib", "Data", &calibData, &metaData);
124
125 f.Close();
126 return result;
127
128}