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 "AliCDBEntry.h"
30 #include "AliPHOSEmcCalibData.h"
39 #include "TObjString.h"
40 #include "TObjArray.h"
45 #include "AliPHOSEmcBadChannelsMap.h"
47 ClassImp(AliPHOSPreprocessor)
49 Double_t rgaus(Double_t *x, Double_t *par)
51 Double_t gaus = par[0] * TMath::Exp( -(x[0]-par[1])*(x[0]-par[1]) /
56 //_______________________________________________________________________________________
57 AliPHOSPreprocessor::AliPHOSPreprocessor() :
58 AliPreprocessor("PHS",0)
63 //_______________________________________________________________________________________
64 AliPHOSPreprocessor::AliPHOSPreprocessor(AliShuttleInterface* shuttle):
65 AliPreprocessor("PHS",shuttle)
69 AddRunType("PHYSICS");
70 AddRunType("STANDALONE");
73 //_______________________________________________________________________________________
74 UInt_t AliPHOSPreprocessor::Process(TMap* /*valueSet*/)
76 // process data retrieved by the Shuttle
78 TString runType = GetRunType();
79 Log(Form("Run type: %s",runType.Data()));
81 if(runType=="STANDALONE") {
82 Bool_t ledOK = ProcessLEDRun();
83 Bool_t badmap_OK = FindBadChannelsEmc();
84 if(!badmap_OK) Log(Form("WARNING! FindBadChannels() completed with BAD status!"));
90 if(runType=="PHYSICS") {
92 Bool_t calibEmc_OK = CalibrateEmc();
94 if(calibEmc_OK) return 0;
99 Log(Form("Unknown run type %s. Do nothing and return OK.",runType.Data()));
105 Bool_t AliPHOSPreprocessor::ProcessLEDRun()
107 //Process LED run, update High Gain/Low Gain ratios.
109 AliPHOSEmcCalibData calibData;
111 TList* list = GetFileSources(kDAQ, "LED");
113 Log("Sources list for LED run not found, exit.");
117 if(!list->GetEntries()) {
118 Log("Sources list for LED run is empty, exit.");
122 //Retrieve the last EMC calibration object
123 const AliPHOSEmcCalibData* clb=0;
124 AliCDBEntry* entryCalib = GetFromOCDB("Calib", "EmcGainPedestals");
127 Log(Form("Cannot find any AliCDBEntry for [Calib, EmcGainPedestals]!"));
129 clb = (AliPHOSEmcCalibData*)entryCalib->GetObject();
134 while ((source = dynamic_cast<TObjString *> (iter.Next()))) {
136 AliInfo(Form("found source %s", source->String().Data()));
138 TString fileName = GetFile(kDAQ, "LED", source->GetName());
139 AliInfo(Form("Got filename: %s",fileName.Data()));
144 Log(Form("File %s is not opened, something goes wrong!",fileName.Data()));
148 const Int_t nMod=5; // 1:5 modules
149 const Int_t nCol=56; //1:56 columns in each module
150 const Int_t nRow=64; //1:64 rows in each module
152 for(Int_t mod=0; mod<nMod; mod++) {
153 for(Int_t col=0; col<nCol; col++) {
154 for(Int_t row=0; row<nRow; row++) {
156 //High Gain to Low Gain ratio
157 Float_t ratio = HG2LG(mod,row,col,&f);
158 calibData.SetHighLowRatioEmc(mod+1,col+1,row+1,ratio);
160 AliInfo(Form("mod %d iX %d iZ %d ratio %.3f\n",mod,row,col,ratio));
163 Double_t coeff = clb->GetADCchannelEmc(mod+1,col+1,row+1);
164 calibData.SetADCchannelEmc(mod+1,col+1,row+1,coeff);
167 calibData.SetADCchannelEmc(mod+1,col+1,row+1,1.);
173 } // end of loop over files
175 //Store the updated High Gain/Low Gain ratios
176 AliCDBMetaData emcMetaData;
178 //Data valid from current run fRun until updated (validityInfinite=kTRUE)
179 Bool_t result = Store("Calib","EmcGainPedestals",&calibData,&emcMetaData,fRun,kTRUE);
184 Float_t AliPHOSPreprocessor::HG2LG(Int_t mod, Int_t X, Int_t Z, TFile* f)
186 //Calculates High gain to Low gain ratio
187 //for crystal at the position (X,Z) in the PHOS module mod.
190 sprintf(hname,"%d_%d_%d",mod,X,Z);
192 TH1F* h1 = (TH1F*)f->Get(hname);
195 if(!h1->GetEntries()) return 16.;
196 if(h1->GetMaximum()<10.) return 16.;
198 Double_t max = h1->GetBinCenter(h1->GetMaximumBin()); // peak
199 Double_t xmin = max - (h1->GetRMS()/3);
200 Double_t xmax = max + (h1->GetRMS()/2);
201 // Double_t xmin = max - (h1->GetRMS());
202 // Double_t xmax = max + (h1->GetRMS());
204 TF1* gaus1 = new TF1("gaus1",rgaus,xmin,xmax,3);
205 gaus1->SetParNames("Constant","Mean","Sigma");
206 gaus1->SetParameter("Constant",h1->GetMaximum());
207 gaus1->SetParameter("Mean",max);
208 gaus1->SetParameter("Sigma",1.);
209 gaus1->SetLineColor(kBlue);
210 h1->Fit(gaus1,"LERQ+");
212 AliInfo(Form("%s: %d entries, mean=%.3f, peak=%.3f, rms= %.3f. HG/LG = %.3f\n",
213 h1->GetTitle(),h1->GetEntries(),h1->GetMean(),max,h1->GetRMS(),
214 gaus1->GetParameter("Mean")));
216 return gaus1->GetParameter("Mean");
220 Bool_t AliPHOSPreprocessor::FindBadChannelsEmc()
222 //Loop over two systems: DAQ and HLT.
223 //For each system the same algorithm implemented in DoFindBadChannelsEmc() invokes.
228 Int_t system[2] = { kDAQ, kHLT };
229 const char* sysn[] = { "DAQ","HLT" };
230 Bool_t result[2] = { kTRUE, kTRUE };
232 for (Int_t i=0; i<2; i++) {
234 AliPHOSEmcBadChannelsMap badMap;
235 list = GetFileSources(system[i], "BAD_CHANNELS");
238 Log(Form("%s sources list for BAD_CHANNELS not found!",sysn[i]));
243 if(!list->GetEntries()) {
244 Log(Form("Got empty sources list. It seems %s DA2 did not produce any files!",sysn[i]));
249 result[i] *= DoFindBadChannelsEmc(system[i],list,badMap);
251 // Store the bad channels map.
254 md.SetResponsible("Boris Polishchuk");
256 if(system[i] == kDAQ)
261 // Data valid from current run fRun until being updated (validityInfinite=kTRUE)
262 result[i] *= Store(path.Data(), "EmcBadChannels", &badMap, &md, fRun, kTRUE);
266 if(result[0] || result[1]) return kTRUE;
270 Bool_t AliPHOSPreprocessor::DoFindBadChannelsEmc(Int_t system, TList* list, AliPHOSEmcBadChannelsMap& badMap)
272 //Creates the bad channels map for PHOS EMC.
274 // The file fileName contains histograms which have been produced by DA2 detector algorithm.
275 // It is a responsibility of the SHUTTLE framework to form the fileName.
282 const Float_t fQualityCut = 1.;
283 Int_t nGoods[5] = {0,0,0,0,0};
285 while ((source = dynamic_cast<TObjString *> (iter.Next()))) {
287 AliInfo(Form("found source %s", source->String().Data()));
289 TString fileName = GetFile(system, "BAD_CHANNELS", source->GetName());
290 AliInfo(Form("Got filename: %s",fileName.Data()));
295 Log(Form("File %s is not opened, something goes wrong!",fileName.Data()));
299 Log(Form("Begin check for bad channels."));
301 for(Int_t mod=0; mod<5; mod++) {
302 for(Int_t iX=0; iX<64; iX++) {
303 for(Int_t iZ=0; iZ<56; iZ++) {
305 sprintf(hnam,"%d_%d_%d_%d",mod,iX,iZ,1); // high gain
306 h1 = (TH1F*)f.Get(hnam);
309 Double_t mean = h1->GetMean();
312 Log(Form("iX=%d iZ=%d gain=%d mean=%.3f\n",iX,iZ,1,mean));
314 if( mean>0 && mean<fQualityCut ) {
318 badMap.SetBadChannel(mod+1,iZ+1,iX+1); //module, col,row
325 Log(Form("Module %d: %d good channels.",mod,nGoods[mod]));
329 } // end of loop over sources
334 Bool_t AliPHOSPreprocessor::CalibrateEmc()
336 //Loop over two systems: DAQ and HLT.
337 //For each system the same algorithm implemented in DoCalibrateEmc() invokes.
339 const AliPHOSEmcBadChannelsMap* badMap=0;
340 AliCDBEntry* entryBCM=0;
344 Int_t system[2] = { kDAQ, kHLT };
345 const char* sysn[] = { "DAQ","HLT" };
346 Bool_t result[2] = { kTRUE, kTRUE };
348 for (Int_t i=0; i<2; i++) {
350 AliPHOSEmcCalibData calibData;
351 list = GetFileSources(system[i], "AMPLITUDES");
354 Log(Form("%s sources list not found!",sysn[i]));
359 if(!list->GetEntries()) {
360 Log(Form("Got empty sources list. It seems %s DA1 did not produce any files!",sysn[i]));
365 // Retrieve the Bad Channels Map (BCM)
367 if(system[i] == kDAQ)
372 entryBCM = GetFromOCDB(path.Data(), "EmcBadChannels");
375 Log(Form("WARNING!! Cannot find any AliCDBEntry for [%s, EmcBadChannels]!",path.Data()));
377 badMap = (AliPHOSEmcBadChannelsMap*)entryBCM->GetObject();
380 Log(Form("WARNING!! Nothing for %s in AliCDBEntry. All cells considered GOOD!",sysn[i]));
382 result[i] *= DoCalibrateEmc(system[i],list,badMap,calibData);
384 //Store EMC calibration data
386 AliCDBMetaData emcMetaData;
387 result[i] *= Store(path.Data(), "EmcGainPedestals", &calibData, &emcMetaData, 0, kTRUE);
391 if(result[0] || result[1]) return kTRUE;
396 Bool_t AliPHOSPreprocessor::DoCalibrateEmc(Int_t system, TList* list, const AliPHOSEmcBadChannelsMap* badMap, AliPHOSEmcCalibData& calibData)
398 // Return kTRUE if OK.
399 // I. Calculates the set of calibration coefficients to equalyze the mean energies deposited at high gain.
400 // II. Extracts High_Gain/Low_Gain ratio for each channel.
402 // The file fileName contains histograms which have been produced by DA1 detector algorithm.
403 // It is a responsibility of the SHUTTLE framework to form the fileName.
405 gRandom->SetSeed(0); //the seed is set to the current machine clock!
410 while ((source = dynamic_cast<TObjString *> (iter.Next()))) {
411 AliInfo(Form("found source %s", source->String().Data()));
413 TString fileName = GetFile(system, "AMPLITUDES", source->GetName());
414 AliInfo(Form("Got filename: %s",fileName.Data()));
419 Log(Form("File %s is not opened, something goes wrong!",fileName.Data()));
423 const Int_t nMod=5; // 1:5 modules
424 const Int_t nCol=56; //1:56 columns in each module
425 const Int_t nRow=64; //1:64 rows in each module
432 //Get the reference histogram
433 //(author: Gustavo Conesa Balbastre)
435 TList * keylist = f.GetListOfKeys();
436 Int_t nkeys = f.GetNkeys();
443 //Check if the file contains any histogram
446 Log(Form("Not enough histograms (%d) for calibration.",nkeys));
447 return 1; // it's not fatal! May be short run..
451 ikey = gRandom->Integer(nkeys);
452 key = (TKey*)keylist->At(ikey);
453 TObject* obj = f.Get(key->GetName());
454 TString cname(obj->ClassName());
455 if(cname == "TH2F") {
457 TString htitl = h2->GetTitle();
458 if(htitl.Contains("and gain 1")) {
459 hRef = h2->ProjectionX();
460 hRef->GetXaxis()->SetRange(10,1000); // to cut off saturation peak and noise
461 // Check if the reference histogram has too little statistics
462 if(hRef->GetMean() && hRef->GetEntries()>2) ok=kTRUE;
464 const TString delim = "_";
465 TString str = hRef->GetName();
466 TObjArray* tks = str.Tokenize(delim);
467 const Int_t md = ((TObjString*)tks->At(0))->GetString().Atoi();
468 const Int_t X = ((TObjString*)tks->At(1))->GetString().Atoi();
469 const Int_t Z = ((TObjString*)tks->At(2))->GetString().Atoi();
472 if(badMap->IsBadChannel(md+1,Z+1,X+1)) {
473 AliInfo(Form("Cell mod=%d col=%d row=%d is bad. Histogram %s rejected.",
474 md+1,Z+1,X+1,hRef->GetName()));
484 if(!ok && counter > nkeys){
485 Log("No histogram with enough statistics for reference. Exit.");
486 return 1; // Not fatal, just wait..
490 Log(Form("reference histogram %s, %.1f entries, mean=%.3f, rms=%.3f.",
491 hRef->GetName(),hRef->GetEntries(),
492 hRef->GetMean(),hRef->GetRMS()));
494 Double_t refMean=hRef->GetMean();
496 // Calculates relative calibration coefficients for all non-zero channels
498 for(Int_t mod=0; mod<nMod; mod++) {
499 for(Int_t col=0; col<nCol; col++) {
500 for(Int_t row=0; row<nRow; row++) {
502 sprintf(hnam,"%d_%d_%d_1",mod,row,col); // high gain!
503 h2 = (TH2F*)f.Get(hnam);
505 //TODO: dead channels exclusion!
507 h1 = h2->ProjectionX();
508 h1->GetXaxis()->SetRange(10,1000); //to cut off saturation peak and noise
509 coeff = h1->GetMean()/refMean;
511 calibData.SetADCchannelEmc(mod+1,col+1,row+1,1./coeff);
513 calibData.SetADCchannelEmc(mod+1,col+1,row+1,1.);
514 AliInfo(Form("mod %d col %d row %d coeff %f\n",mod,col,row,coeff));
517 calibData.SetADCchannelEmc(mod+1,col+1,row+1,1.);