1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
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
23 // Author: Boris Polichtchouk, 4 October 2006
24 ///////////////////////////////////////////////////////////////////////////////
26 #include "AliPHOSPreprocessor.h"
28 #include "AliCDBMetaData.h"
29 #include "AliPHOSEmcCalibData.h"
38 #include "TObjString.h"
42 #include "AliPHOSEmcBadChannelsMap.h"
44 ClassImp(AliPHOSPreprocessor)
46 Double_t rgaus(Double_t *x, Double_t *par)
48 Double_t gaus = par[0] * TMath::Exp( -(x[0]-par[1])*(x[0]-par[1]) /
53 //_______________________________________________________________________________________
54 AliPHOSPreprocessor::AliPHOSPreprocessor() :
55 AliPreprocessor("PHS",0)
60 //_______________________________________________________________________________________
61 AliPHOSPreprocessor::AliPHOSPreprocessor(AliShuttleInterface* shuttle):
62 AliPreprocessor("PHS",shuttle)
67 //_______________________________________________________________________________________
68 UInt_t AliPHOSPreprocessor::Process(TMap* /*valueSet*/)
70 // process data retrieved by the Shuttle
72 TString runType = GetRunType();
73 Log(Form("Run type: %s",runType.Data()));
75 if(runType=="STANDALONE") {
76 Bool_t ledOK = ProcessLEDRun();
82 if(runType=="PHYSICS") {
84 Bool_t badmap_OK = FindBadChannelsEmc();
85 if(!badmap_OK) Log(Form("WARNING!! FindBadChannels() completed with BAD status!"));
87 Bool_t calibEmc_OK = CalibrateEmc();
89 if(calibEmc_OK && badmap_OK) return 0;
94 Log(Form("Unknown run type %s. Do nothing and return OK.",runType.Data()));
100 Bool_t AliPHOSPreprocessor::ProcessLEDRun()
102 //Process LED run, fill bad channels map.
104 AliPHOSEmcBadChannelsMap badMap;
106 TList* list = GetFileSources(kDAQ, "LED");
108 Log("Sources list for LED run not found, exit.");
117 while ((source = dynamic_cast<TObjString *> (iter.Next()))) {
119 AliInfo(Form("found source %s", source->String().Data()));
121 TString fileName = GetFile(kDAQ, "LED", source->GetName());
122 AliInfo(Form("Got filename: %s",fileName.Data()));
127 Log(Form("File %s is not opened, something goes wrong!",fileName.Data()));
131 const Int_t nMod=5; // 1:5 modules
132 const Int_t nCol=56; //1:56 columns in each module
133 const Int_t nRow=64; //1:64 rows in each module
135 // Check for dead channels
136 Log(Form("Begin check for dead channels."));
138 for(Int_t mod=0; mod<nMod; mod++) {
139 for(Int_t col=0; col<nCol; col++) {
140 for(Int_t row=0; row<nRow; row++) {
141 sprintf(hnam,"mod%dcol%drow%d",mod,col,row);
142 histo = (TH1F*)f.Get(hnam);
144 if (histo->GetMean()<1) {
145 Log(Form("Channel: [%d,%d,%d] seems dead, <E>=%.1f.",mod,col,row,histo->GetMean()));
146 badMap.SetBadChannel(mod,col,row);
154 //Store bad channels map
155 AliCDBMetaData badMapMetaData;
157 //Bad channels data valid from current run fRun until updated (validityInfinite=kTRUE)
158 Bool_t result = Store("Calib", "EmcBadChannels", &badMap, &badMapMetaData, fRun, kTRUE);
163 Float_t AliPHOSPreprocessor::HG2LG(Int_t mod, Int_t X, Int_t Z, TFile* f)
165 //Calculates High gain to Low gain ratio
166 //for crystal at the position (X,Z) in the PHOS module mod.
169 sprintf(hname,"%d_%d_%d",mod,X,Z);
171 TH1F* h1 = (TH1F*)f->Get(hname);
174 if(!h1->GetEntries()) return 16.;
175 if(h1->GetMaximum()<10.) return 16.;
177 Double_t max = h1->GetBinCenter(h1->GetMaximumBin()); // peak
178 Double_t xmin = max - (h1->GetRMS()/3);
179 Double_t xmax = max + (h1->GetRMS()/2);
180 // Double_t xmin = max - (h1->GetRMS());
181 // Double_t xmax = max + (h1->GetRMS());
183 TF1* gaus1 = new TF1("gaus1",rgaus,xmin,xmax,3);
184 gaus1->SetParNames("Constant","Mean","Sigma");
185 gaus1->SetParameter("Constant",h1->GetMaximum());
186 gaus1->SetParameter("Mean",max);
187 gaus1->SetParameter("Sigma",1.);
188 gaus1->SetLineColor(kBlue);
189 h1->Fit(gaus1,"LERQ+");
191 Log(Form("\t%s: %d entries, mean=%.3f, peak=%.3f, rms= %.3f. HG/LG = %.3f\n",
192 h1->GetTitle(),h1->GetEntries(),h1->GetMean(),max,h1->GetRMS(),
193 gaus1->GetParameter("Mean")));
195 return gaus1->GetParameter("Mean");
199 Bool_t AliPHOSPreprocessor::FindBadChannelsEmc()
201 //Creates the bad channels map for PHOS EMC.
203 // The file fileName contains histograms which have been produced by DA2 detector algorithm.
204 // It is a responsibility of the SHUTTLE framework to form the fileName.
206 AliPHOSEmcBadChannelsMap badMap;
208 TList* list = GetFileSources(kDAQ, "BAD_CHANNELS");
211 Log("Sources list for BAD_CHANNELS not found, exit.");
215 if(!list->GetEntries()) {
216 Log(Form("Got empty sources list. It seems DA2 did not produce any files!"));
225 const Float_t fQualityCut = 1.;
226 Int_t nGoods[5] = {0,0,0,0,0};
228 while ((source = dynamic_cast<TObjString *> (iter.Next()))) {
230 AliInfo(Form("found source %s", source->String().Data()));
232 TString fileName = GetFile(kDAQ, "BAD_CHANNELS", source->GetName());
233 AliInfo(Form("Got filename: %s",fileName.Data()));
238 Log(Form("File %s is not opened, something goes wrong!",fileName.Data()));
242 Log(Form("Begin check for bad channels."));
244 for(Int_t mod=0; mod<5; mod++) {
245 for(Int_t iX=0; iX<64; iX++) {
246 for(Int_t iZ=0; iZ<56; iZ++) {
248 sprintf(hnam,"%d_%d_%d_%d",mod,iX,iZ,1); // high gain
249 h1 = (TH1F*)f.Get(hnam);
252 Double_t mean = h1->GetMean();
255 Log(Form("iX=%d iZ=%d gain=%d mean=%.3f\n",iX,iZ,1,mean));
257 if( mean>0 && mean<fQualityCut ) {
261 badMap.SetBadChannel(mod+1,iZ+1,iX+1); //module, col,row
268 Log(Form("Module %d: %d good channels.",mod,nGoods[mod]));
272 } // end of loop over sources
274 // Store the bad channels map.
277 md.SetResponsible("Boris Polishchuk");
279 // Data valid from current run fRun until being updated (validityInfinite=kTRUE)
280 Bool_t result = Store("Calib", "EmcBadChannels", &badMap, &md, fRun, kTRUE);
285 Bool_t AliPHOSPreprocessor::CalibrateEmc()
287 // I. Calculates the set of calibration coefficients to equalyze the mean energies deposited at high gain.
288 // II. Extracts High_Gain/Low_Gain ratio for each channel.
290 // The file fileName contains histograms which have been produced by DA1 detector algorithm.
291 // It is a responsibility of the SHUTTLE framework to form the fileName.
293 gRandom->SetSeed(0); //the seed is set to the current machine clock!
294 AliPHOSEmcCalibData calibData;
296 TList* list = GetFileSources(kDAQ, "AMPLITUDES");
299 Log("Sources list not found, exit.");
303 if(!list->GetEntries()) {
304 Log(Form("Got empty sources list. It seems DA1 did not produce any files!"));
311 while ((source = dynamic_cast<TObjString *> (iter.Next()))) {
312 AliInfo(Form("found source %s", source->String().Data()));
314 TString fileName = GetFile(kDAQ, "AMPLITUDES", source->GetName());
315 AliInfo(Form("Got filename: %s",fileName.Data()));
320 Log(Form("File %s is not opened, something goes wrong!",fileName.Data()));
324 const Int_t nMod=5; // 1:5 modules
325 const Int_t nCol=56; //1:56 columns in each module
326 const Int_t nRow=64; //1:64 rows in each module
333 //Get the reference histogram
334 //(author: Gustavo Conesa Balbastre)
336 TList * keylist = f.GetListOfKeys();
337 Int_t nkeys = f.GetNkeys();
344 //Check if the file contains any histogram
347 Log(Form("Not enough histograms (%d) for calibration.",nkeys));
352 ikey = gRandom->Integer(nkeys);
353 key = (TKey*)keylist->At(ikey);
354 TObject* obj = f.Get(key->GetName());
355 TString cname(obj->ClassName());
356 if(cname == "TH2F") {
358 TString htitl = h2->GetTitle();
359 if(htitl.Contains("and gain 1")) {
360 hRef = h2->ProjectionX();
361 hRef->SetBins(1000,0.,1000.); // to cut off saturation peak at 1023
362 // Check if the reference histogram has too little statistics
363 if(hRef->GetEntries()>2) ok=kTRUE;
364 if(!ok && counter > nkeys){
365 Log("No histogram with enough statistics for reference.");
373 Log(Form("reference histogram %s, %.1f entries, mean=%.3f, rms=%.3f.",
374 hRef->GetName(),hRef->GetEntries(),
375 hRef->GetMean(),hRef->GetRMS()));
377 Double_t refMean=hRef->GetMean();
379 // Calculates relative calibration coefficients for all non-zero channels
381 for(Int_t mod=0; mod<nMod; mod++) {
382 for(Int_t col=0; col<nCol; col++) {
383 for(Int_t row=0; row<nRow; row++) {
385 //High Gain to Low Gain ratio
386 Float_t ratio = HG2LG(mod,row,col,&f);
387 calibData.SetHighLowRatioEmc(mod+1,col+1,row+1,ratio);
389 sprintf(hnam,"%d_%d_%d_1",mod,row,col); // high gain!
390 h2 = (TH2F*)f.Get(hnam);
392 //TODO: dead channels exclusion!
394 h1 = h2->ProjectionX();
395 h1->SetBins(1000,0.,1000.); // to cut off saturation peak at 1023
396 coeff = h1->GetMean()/refMean;
398 calibData.SetADCchannelEmc(mod+1,col+1,row+1,1./coeff);
400 calibData.SetADCchannelEmc(mod+1,col+1,row+1,1.);
401 AliInfo(Form("mod %d col %d row %d coeff %f\n",mod,col,row,coeff));
404 calibData.SetADCchannelEmc(mod+1,col+1,row+1,1.);
412 //Store EMC calibration data
414 AliCDBMetaData emcMetaData;
415 Bool_t result = Store("Calib", "EmcGainPedestals", &calibData, &emcMetaData, 0, kTRUE); // valid from 0 to infinity);