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