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