]>
Commit | Line | Data |
---|---|---|
1ab07e55 | 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 | ||
18 | /////////////////////////////////////////////////////////////////////////////// | |
19 | // PHOS Preprocessor class. It runs by Shuttle at the end of the run, | |
20 | // calculates calibration coefficients and dead/bad channels | |
21 | // to be posted in OCDB | |
22 | // | |
23 | // Author: Boris Polichtchouk, 4 October 2006 | |
24 | /////////////////////////////////////////////////////////////////////////////// | |
25 | ||
26 | #include "AliPHOSPreprocessor.h" | |
27 | #include "AliLog.h" | |
28 | #include "AliCDBMetaData.h" | |
29 | #include "AliPHOSEmcCalibData.h" | |
30 | #include "TFile.h" | |
31 | #include "TH1.h" | |
32 | #include "TMap.h" | |
33 | #include "TRandom.h" | |
f97eb136 | 34 | #include "TKey.h" |
516e7ab3 | 35 | #include "TList.h" |
36 | #include "TObjString.h" | |
3c0265c1 | 37 | #include "AliPHOSEmcBadChannelsMap.h" |
1ab07e55 | 38 | |
39 | ClassImp(AliPHOSPreprocessor) | |
40 | ||
41 | //_______________________________________________________________________________________ | |
42 | AliPHOSPreprocessor::AliPHOSPreprocessor() : | |
81587b1e | 43 | AliPreprocessor("PHS",0) |
1ab07e55 | 44 | { |
45 | //default constructor | |
46 | } | |
47 | ||
48 | //_______________________________________________________________________________________ | |
81587b1e | 49 | AliPHOSPreprocessor::AliPHOSPreprocessor(AliShuttleInterface* shuttle): |
50 | AliPreprocessor("PHS",shuttle) | |
1ab07e55 | 51 | { |
52 | // Constructor | |
53 | } | |
54 | ||
55 | //_______________________________________________________________________________________ | |
56 | UInt_t AliPHOSPreprocessor::Process(TMap* /*valueSet*/) | |
57 | { | |
58 | // process data retrieved by the Shuttle | |
59 | ||
60 | // The fileName with the histograms which have been produced by | |
61 | // AliPHOSCalibHistoProducer. | |
62 | // It is a responsibility of the SHUTTLE framework to form the fileName | |
516e7ab3 | 63 | |
3c0265c1 | 64 | TString runType = GetRunType(); |
65 | Log(Form("Run type: %s",runType.Data())); | |
66 | ||
c1274f4c | 67 | gRandom->SetSeed(0); //the seed is set to the current machine clock! |
516e7ab3 | 68 | AliPHOSEmcCalibData calibData; |
3c0265c1 | 69 | AliPHOSEmcBadChannelsMap badMap; |
70 | ||
516e7ab3 | 71 | TList* list = GetFileSources(kDAQ, "AMPLITUDES"); |
72 | if(!list) { | |
73 | Log("Sources list not found, exit."); | |
1ab07e55 | 74 | return 0; |
75 | } | |
76 | ||
516e7ab3 | 77 | TIter iter(list); |
78 | TObjString *source; | |
3c0265c1 | 79 | Int_t result=0; |
80 | ||
516e7ab3 | 81 | while ((source = dynamic_cast<TObjString *> (iter.Next()))) { |
82 | AliInfo(Form("found source %s", source->String().Data())); | |
f97eb136 | 83 | |
516e7ab3 | 84 | TString fileName = GetFile(kDAQ, "AMPLITUDES", source->GetName()); |
85 | AliInfo(Form("Got filename: %s",fileName.Data())); | |
f97eb136 | 86 | |
516e7ab3 | 87 | TFile f(fileName); |
f97eb136 | 88 | |
516e7ab3 | 89 | if(!f.IsOpen()) { |
90 | Log(Form("File %s is not opened, something goes wrong!",fileName.Data())); | |
91 | return 0; | |
92 | } | |
1ab07e55 | 93 | |
516e7ab3 | 94 | const Int_t nMod=5; // 1:5 modules |
95 | const Int_t nCol=56; //1:56 columns in each module | |
96 | const Int_t nRow=64; //1:64 rows in each module | |
97 | ||
98 | Double_t coeff; | |
99 | char hnam[80]; | |
100 | TH1F* histo=0; | |
3c0265c1 | 101 | |
516e7ab3 | 102 | //Get the reference histogram |
103 | //(author: Gustavo Conesa Balbastre) | |
104 | ||
105 | TList * keylist = f.GetListOfKeys(); | |
106 | Int_t nkeys = f.GetNkeys(); | |
107 | Bool_t ok = kFALSE; | |
108 | TKey *key; | |
109 | TString refHistoName= ""; | |
110 | Int_t ikey = 0; | |
111 | Int_t counter = 0; | |
112 | TH1F* hRef = 0; | |
113 | ||
3c0265c1 | 114 | // Check for dead channels |
115 | if (runType=="LED") { | |
116 | ||
117 | Log(Form("Begin check for dead channels.")); | |
118 | for(Int_t mod=0; mod<nMod; mod++) { | |
119 | for(Int_t col=0; col<nCol; col++) { | |
120 | for(Int_t row=0; row<nRow; row++) { | |
121 | sprintf(hnam,"mod%dcol%drow%d",mod,col,row); | |
122 | histo = (TH1F*)f.Get(hnam); | |
123 | if(histo) | |
124 | if (histo->GetMean()<1) { | |
125 | Log(Form("Channel: [%d,%d,%d] seems dead, <E>=%.1f.",mod,col,row,histo->GetMean())); | |
126 | badMap.SetBadChannel(mod,col,row); | |
127 | } | |
128 | } | |
129 | } | |
130 | } | |
131 | //Store bad channels map | |
132 | AliCDBMetaData badMapMetaData; | |
133 | result = Store("Bad", "EmcData", &badMap, &badMapMetaData); | |
134 | return result; | |
135 | } | |
136 | ||
516e7ab3 | 137 | //Check if the file contains any histogram |
138 | ||
139 | if(nkeys< 2){ | |
140 | Log(Form("Not enough histograms (%d) for calibration.",nkeys)); | |
4988b8ce | 141 | return 1; |
f97eb136 | 142 | } |
f97eb136 | 143 | |
516e7ab3 | 144 | while(!ok){ |
145 | ikey = gRandom->Integer(nkeys); | |
146 | key = (TKey*)keylist->At(ikey); | |
147 | refHistoName = key->GetName(); | |
148 | hRef = (TH1F*)f.Get(refHistoName); | |
149 | counter++; | |
150 | // Check if the reference histogram has too little statistics | |
151 | if(hRef->GetEntries()>2) ok=kTRUE; | |
152 | if(!ok && counter >= nMod*nCol*nRow){ | |
153 | Log("No histogram with enough statistics for reference."); | |
154 | return 1; | |
155 | } | |
156 | } | |
3c0265c1 | 157 | |
516e7ab3 | 158 | Log(Form("reference histogram %s, %.1f entries, mean=%.3f, rms=%.3f.", |
159 | hRef->GetName(),hRef->GetEntries(), | |
160 | hRef->GetMean(),hRef->GetRMS())); | |
161 | ||
162 | Double_t refMean=hRef->GetMean(); | |
3c0265c1 | 163 | |
516e7ab3 | 164 | // Calculates relative calibration coefficients for all non-zero channels |
3c0265c1 | 165 | |
516e7ab3 | 166 | for(Int_t mod=0; mod<nMod; mod++) { |
167 | for(Int_t col=0; col<nCol; col++) { | |
168 | for(Int_t row=0; row<nRow; row++) { | |
169 | sprintf(hnam,"mod%dcol%drow%d",mod,col,row); | |
170 | histo = (TH1F*)f.Get(hnam); | |
171 | //TODO: dead channels exclusion! | |
172 | if(histo) { | |
173 | coeff = histo->GetMean()/refMean; | |
64d8f3f1 | 174 | if(coeff>0) |
175 | calibData.SetADCchannelEmc(mod+1,col+1,row+1,0.001/coeff); | |
176 | else | |
177 | calibData.SetADCchannelEmc(mod+1,col+1,row+1,0.001); | |
516e7ab3 | 178 | AliInfo(Form("mod %d col %d row %d coeff %f\n",mod,col,row,coeff)); |
179 | } | |
180 | else | |
181 | calibData.SetADCchannelEmc(mod+1,col+1,row+1,0.001); | |
1ab07e55 | 182 | } |
1ab07e55 | 183 | } |
184 | } | |
516e7ab3 | 185 | |
186 | f.Close(); | |
1ab07e55 | 187 | } |
516e7ab3 | 188 | |
3c0265c1 | 189 | //Store EMC calibration data |
190 | ||
191 | AliCDBMetaData emcMetaData; | |
192 | result = Store("Calib", "EmcData", &calibData, &emcMetaData); | |
1ab07e55 | 193 | return result; |
194 | ||
195 | } |