1 /**************************************************************************
2 * Copyright(c) 1998-2008, 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 **************************************************************************/
17 ///////////////////////////////////////////////////////////////////////////////
18 // CPV Preprocessor class. It runs by Shuttle at the end of the run,
19 // calculates calibration coefficients and dead/bad channels
20 // to be posted in OCDB.
22 // Author: Boris Polichtchouk, 25 January 2008
23 ///////////////////////////////////////////////////////////////////////////////
25 #include "AliPHOSCpvPreprocessor.h"
27 #include "AliCDBMetaData.h"
28 #include "AliPHOSCpvCalibData.h"
35 #include "TObjString.h"
37 ClassImp(AliPHOSCpvPreprocessor)
39 //_______________________________________________________________________________________
40 AliPHOSCpvPreprocessor::AliPHOSCpvPreprocessor() :
41 AliPreprocessor("CPV",0)
46 //_______________________________________________________________________________________
47 AliPHOSCpvPreprocessor::AliPHOSCpvPreprocessor(AliShuttleInterface* shuttle):
48 AliPreprocessor("CPV",shuttle)
52 AddRunType("PHYSICS");
53 AddRunType("STANDALONE");
57 //_______________________________________________________________________________________
58 UInt_t AliPHOSCpvPreprocessor::Process(TMap* /*valueSet*/)
60 // process data retrieved by the Shuttle
62 // The fileName with the histograms which have been produced by
64 // It is a responsibility of the SHUTTLE framework to form the fileName.
66 TString runType = GetRunType();
67 Log(Form("Run type: %s",runType.Data()));
69 if(runType=="PHYSICS") {
71 gRandom->SetSeed(0); //the seed is set to the current machine clock!
72 AliPHOSCpvCalibData calibData;
74 TList* list = GetFileSources(kDAQ, "AMPLITUDES");
76 Log("Sources list not found, exit.");
83 while ((source = dynamic_cast<TObjString *> (iter.Next()))) {
84 AliInfo(Form("found source %s", source->String().Data()));
86 TString fileName = GetFile(kDAQ, "AMPLITUDES", source->GetName());
87 AliInfo(Form("Got filename: %s",fileName.Data()));
92 Log(Form("File %s is not opened, something goes wrong!",fileName.Data()));
96 const Int_t nMod=5; // 1:5 modules
97 const Int_t nCol=56; // 1:56 columns in each CPV module (along the global Z axis)
98 const Int_t nRow=128; // 1:128 rows in each CPV module
104 //Get the reference histogram
105 //(author: Gustavo Conesa Balbastre)
107 TList * keylist = f.GetListOfKeys();
108 Int_t nkeys = f.GetNkeys();
111 TString refHistoName= "";
116 //Check if the file contains any histogram
119 Log(Form("Not enough histograms (%d) for calibration.",nkeys));
124 ikey = gRandom->Integer(nkeys);
125 key = (TKey*)keylist->At(ikey);
126 refHistoName = key->GetName();
127 hRef = (TH1F*)f.Get(refHistoName);
129 // Check if the reference histogram has too little statistics
130 if(hRef->GetEntries()>2) ok=kTRUE;
131 if(!ok && counter >= nkeys){
132 Log("No histogram with enough statistics for reference.");
137 Log(Form("reference histogram %s, %.1f entries, mean=%.3f, rms=%.3f.",
138 hRef->GetName(),hRef->GetEntries(),
139 hRef->GetMean(),hRef->GetRMS()));
141 Double_t refMean=hRef->GetMean();
143 // Calculates relative calibration coefficients for all non-zero channels
145 for(Int_t mod=0; mod<nMod; mod++) {
146 for(Int_t col=0; col<nCol; col++) {
147 for(Int_t row=0; row<nRow; row++) {
148 snprintf(hnam,80,"%d_%d_%d",mod,row,col); // mod_X_Z
149 histo = (TH1F*)f.Get(hnam);
150 //TODO: dead channels exclusion!
152 coeff = histo->GetMean()/refMean;
154 calibData.SetADCchannelCpv(mod+1,col+1,row+1,1./coeff);
155 AliInfo(Form("mod %d col %d row %d coeff %f\n",mod,col,row,coeff));
164 //Store CPV calibration data
166 AliCDBMetaData cpvMetaData;
167 Bool_t cpvOK = Store("Calib", "CpvGainPedestals", &calibData, &cpvMetaData);
174 Log(Form("Unknown or unused run type %s. Do nothing and return OK.",runType.Data()));