]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EMCAL/AliEMCALPreprocessor.cxx
f4c13cacf49079b7cc9bbeb362a31bffe703bcd7
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALPreprocessor.cxx
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  * Revision 1.1  2006/12/07 16:32:16  gustavo
21  * First shuttle code, online calibration histograms producer, EMCAL preprocessor
22  * 
23  *
24 */
25 ///////////////////////////////////////////////////////////////////////////////
26 // EMCAL Preprocessor class. It runs by Shuttle at the end of the run,
27 // calculates calibration coefficients and dead/bad channels
28 // to be posted in OCDB
29 //
30 // Author: Boris Polichtchouk, 4 October 2006
31 // Adapted for EMCAL by Gustavo Conesa Balbastre, October 2006
32 ///////////////////////////////////////////////////////////////////////////////
33
34 //Root
35 #include "TFile.h"
36 #include "TH1.h"
37 #include "TMap.h"
38 #include "TRandom.h"
39 #include "TKey.h"
40 #include "TList.h"
41 #include "Riostream.h"
42 //AliRoot
43 #include "AliEMCALPreprocessor.h"
44 #include "AliLog.h"
45 #include "AliCDBMetaData.h"
46 #include "AliEMCALCalibData.h"
47
48 ClassImp(AliEMCALPreprocessor)
49
50 //_______________________________________________________________________________________
51 AliEMCALPreprocessor::AliEMCALPreprocessor() :
52 AliPreprocessor("EMC",0)
53 {
54   //default constructor
55 }
56
57 //_______________________________________________________________________________________
58 AliEMCALPreprocessor::AliEMCALPreprocessor(AliShuttleInterface* shuttle):
59 AliPreprocessor("EMC",shuttle)
60 {
61   // Constructor
62 }
63
64 //_______________________________________________________________________________________
65 UInt_t AliEMCALPreprocessor::Process(TMap* /*valueSet*/)
66 {
67   // process data retrieved by the Shuttle
68
69   // The fileName with the histograms which have been produced by
70   // AliEMCALCalibHistoProducer.
71   // It is a responsibility of the SHUTTLE framework to form the fileName
72
73   const char* fileName = GetFile(kDAQ, "AMPLITUDES", "GDC");
74   AliInfo(Form("Got filename: %s",fileName));
75
76   TFile f(fileName);
77
78   if(!f.IsOpen()) {
79     AliInfo(Form("File %s is not opened, something goes wrong!",fileName));
80     return 0;
81   }
82
83   const Int_t nMod=12; // 1:5 modules
84   const Int_t nCol=48; //1:56 columns in each module
85   Int_t nRow=24; //1:64 rows in each module
86   const Int_t nRowHalfSM = 12; //Supermodules 11 and 12 are half supermodules
87
88   Double_t coeff;
89   char hnam[80];
90   TH1F* histo=0;
91
92
93   //Get reference histogram
94   TList * keylist = f.GetListOfKeys();
95   Int_t nkeys   = f.GetNkeys();
96   Bool_t ok = kFALSE;
97   TKey  *key;
98   TString refHistoName= "";
99   Int_t ikey = 0;
100   Int_t counter = 0;
101   TH1F* hRef;
102   
103   //Check if the file contains any histogram
104   if(nkeys< 2){
105     AliInfo(Form("Not enough histograms for calibration, nhist = %d",nkeys));
106     return 1;
107   }
108   
109   while(!ok){
110     ikey = gRandom->Integer(nkeys);
111     key = (TKey*)keylist->At(ikey);
112     refHistoName = key->GetName();
113     hRef = (TH1F*)f.Get(refHistoName);
114     counter++;
115     // Check if the reference has too little statistics and 
116     // if the histogram has the correct name (2 kinds, mod#col#row for 
117     // reference here, and mod#, see AliEMCALHistoProducer.
118     if(refHistoName.Contains("col") && hRef->GetEntries()>2 && hRef->GetMean()>0) 
119       ok=kTRUE;
120     if(!ok && counter >= nMod*nCol*nRow+nMod){
121       AliInfo("No histogram with enough statistics for reference");
122       return 1;
123     }
124   }
125   
126   Double_t refMean=hRef->GetMean();
127
128   // Calculates relative calibration coefficients for all non-zero channels
129   AliEMCALCalibData calibData;
130
131   for(Int_t mod=0; mod<nMod; mod++) {
132     if(mod > 10) nRow = nRowHalfSM ;
133     for(Int_t col=0; col<nCol; col++) {
134       for(Int_t row=0; row<nRow; row++) {
135         sprintf(hnam,"mod%dcol%drow%d",mod,col,row);
136         histo = (TH1F*)f.Get(hnam);
137         //TODO: dead channels exclusion!
138         if(histo && histo->GetMean() > 0) {
139           coeff = histo->GetMean()/refMean;
140           calibData.SetADCchannel(mod+1,col+1,row+1,1./coeff);
141           AliInfo(Form("mod %d col %d row %d  coeff %f\n",mod,col,row,coeff));
142         }
143         else
144           calibData.SetADCchannel(mod+1,col+1,row+1,-111); 
145       }
146     }
147   }
148
149   AliCDBMetaData metaData;
150   Int_t result = Store("Calib", "Data", &calibData, &metaData);
151
152   f.Close();
153   return result;
154
155 }