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