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