+ if(!list->GetEntries()) {
+ Log(Form("Got empty sources list. It seems %s DA2 did not produce any files!",sysn[i]));
+ result[i] = kFALSE;
+ continue;
+ }
+
+ Bool_t findBadOK = DoFindBadChannelsEmc(system[i],list,badMap);
+ result[i] *= findBadOK;
+
+ // Store the bad channels map.
+
+ AliCDBMetaData md;
+ md.SetResponsible("Boris Polishchuk");
+
+ if(system[i] == kDAQ)
+ path = "Calib";
+ else
+ path = "HLT";
+
+ // Data valid from current run until being updated (validityInfinite=kTRUE)
+ Bool_t storeOK = Store(path.Data(), "EmcBadChannels", &badMap, &md, 0, kTRUE);
+ result[i] *= storeOK;
+
+ }
+
+ if(result[0] || result[1]) return kTRUE;
+ else return kFALSE;
+}
+
+Bool_t AliPHOSPreprocessor::DoFindBadChannelsEmc(Int_t system, TList* list, AliPHOSEmcBadChannelsMap& badMap)
+{
+ //Creates the bad channels map for PHOS EMC.
+
+ // The file fileName contains histograms which have been produced by DA2 detector algorithm.
+ // It is a responsibility of the SHUTTLE framework to form the fileName.
+
+ TIter iter(list);
+ TObjString *source;
+ TH1F* h1=0;
+
+ const Float_t fQualityCut = 1.;
+ Int_t nGoods[5] = {0,0,0,0,0};
+
+ while ((source = dynamic_cast<TObjString *> (iter.Next()))) {
+
+ AliInfo(Form("found source %s", source->String().Data()));
+
+ TString fileName = GetFile(system, "BAD_CHANNELS", source->GetName());
+ AliInfo(Form("Got filename: %s",fileName.Data()));
+
+ TFile f(fileName);
+
+ if(!f.IsOpen()) {
+ Log(Form("File %s is not opened, something goes wrong!",fileName.Data()));
+ return kFALSE;
+ }
+
+ Log(Form("Begin check for bad channels."));
+
+ for(Int_t mod=0; mod<5; mod++) {
+ for(Int_t iX=0; iX<64; iX++) {
+ for(Int_t iZ=0; iZ<56; iZ++) {
+
+ TString hnam;
+ hnam += mod; hnam += "_"; hnam += iX; hnam += "_"; hnam += iZ; hnam += "_"; hnam += "1";
+ h1 = (TH1F*)f.Get(hnam);
+
+ if(h1) {
+ Double_t mean = h1->GetMean();
+
+ if(mean)
+ Log(Form("iX=%d iZ=%d gain=%d mean=%.3f\n",iX,iZ,1,mean));
+
+ if( mean>0 && mean<fQualityCut ) {
+ nGoods[mod]++;
+ }
+ else
+ badMap.SetBadChannel(mod+1,iZ+1,iX+1); //module, col,row
+ }
+
+ }
+ }
+
+ if(nGoods[mod])
+ Log(Form("Module %d: %d good channels.",mod,nGoods[mod]));
+ }
+
+
+ } // end of loop over sources
+
+ return kTRUE;
+}
+
+Bool_t AliPHOSPreprocessor::CalibrateEmc()
+{
+ //Loop over two systems: DAQ and HLT.
+ //For each system the same algorithm implemented in DoCalibrateEmc() invokes.
+
+ AliPHOSEmcCalibData* lastCalib=0;
+ const AliPHOSEmcBadChannelsMap* badMap=0;
+ AliCDBEntry* entryBCM=0;
+ AliCDBEntry* entryEmc=0;
+ TList* list=0;
+ TString path;
+
+ Int_t system[2] = { kDAQ, kHLT };
+ const char* sysn[] = { "DAQ","HLT" };
+ Bool_t result[2] = { kTRUE, kTRUE };
+
+ for (Int_t i=0; i<2; i++) {
+
+ if(system[i] == kHLT) continue;
+
+ AliPHOSEmcCalibData calibData;
+ list = GetFileSources(system[i], "AMPLITUDES");
+
+ if(!list) {
+ Log(Form("%s sources list not found!",sysn[i]));
+ result[i] = kFALSE;
+ continue;
+ }
+
+ if(!list->GetEntries()) {
+ Log(Form("Got empty sources list. It seems %s DA1 did not produce any files!",sysn[i]));
+ result[i] = kFALSE;
+ continue;
+ }
+
+ // Retrieve the Bad Channels Map (BCM)
+
+ if(system[i] == kDAQ)
+ path = "Calib";
+ else
+ path = "HLT";
+
+ entryBCM = GetFromOCDB(path.Data(), "EmcBadChannels");
+
+ if(!entryBCM)
+ Log(Form("WARNING!! Cannot find any AliCDBEntry for [%s, EmcBadChannels]!",path.Data()));
+ else
+ badMap = (AliPHOSEmcBadChannelsMap*)entryBCM->GetObject();
+
+ if(!badMap)
+ Log(Form("WARNING!! Nothing for %s in AliCDBEntry. All cells considered GOOD!",sysn[i]));
+
+ // Retrieve the last EMC calibration object
+
+ entryEmc = GetFromOCDB(path.Data(), "EmcGainPedestals");
+
+ if(!entryEmc)
+ Log(Form("Cannot find any EmcGainPedestals entry for this run and path %s",path.Data()));
+ else
+ lastCalib = (AliPHOSEmcCalibData*)entryEmc->GetObject();
+
+ if(lastCalib)
+ result[i] *= DoCalibrateEmc(system[i],list,badMap,*lastCalib);
+ else
+ result[i] *= DoCalibrateEmc(system[i],list,badMap,calibData);
+
+ //Store EMC calibration data
+ AliCDBMetaData emcMetaData;
+
+ // if(lastCalib)
+ // result[i] *= Store(path.Data(), "EmcGainPedestals", lastCalib, &emcMetaData, 0, kFALSE);
+ // else
+ // result[i] *= Store(path.Data(), "EmcGainPedestals", &calibData, &emcMetaData, 0, kFALSE);
+
+ //Store reference data
+ Bool_t refOK = StoreReferenceEmc(system[i],list);
+ if(refOK) Log(Form("Reference data for %s amplitudes successfully stored.",sysn[i]));
+
+ }
+
+ if(result[0] || result[1]) return kTRUE;
+ else return kFALSE;
+}
+
+Bool_t AliPHOSPreprocessor::StoreReferenceEmc(Int_t system, TList* list)
+{
+ //Put 2D calibration histograms (E vs Time) prepared by DAQ/HLT to the reference storage.
+ //system is DAQ or HLT, TList is the list of FES sources.
+
+ if(system!=kDAQ) return kFALSE;
+
+ TObjString *source = dynamic_cast<TObjString *> (list->First());
+ if(!source) return kFALSE;
+
+ TString fileName = GetFile(system, "AMPLITUDES", source->GetName());
+
+ Bool_t resultRef = StoreReferenceFile(fileName.Data(),"CalibRefPHOS.root");
+ return resultRef;
+
+}
+
+Bool_t AliPHOSPreprocessor::StoreReferenceLED(TList* list)
+{
+ //Put HG/LG histograms to the reference storage.
+
+ TObjString *source = dynamic_cast<TObjString *> (list->First());
+ if(!source) return kFALSE;
+
+ TString fileName = GetFile(kDAQ, "LED", source->GetName());
+
+ Bool_t resultRef = StoreReferenceFile(fileName.Data(),"LEDRefPHOS.root");
+ return resultRef;
+
+}
+
+
+Bool_t AliPHOSPreprocessor::DoCalibrateEmc(Int_t system, TList* list, const AliPHOSEmcBadChannelsMap* badMap, AliPHOSEmcCalibData& calibData)
+{
+ // Return kTRUE if OK.
+ // I. Calculates the set of calibration coefficients to equalyze the mean energies deposited at high gain.
+ // II. Extracts High_Gain/Low_Gain ratio for each channel.
+
+ // The file fileName contains histograms which have been produced by DA1 detector algorithm.
+ // It is a responsibility of the SHUTTLE framework to form the fileName.
+
+ gRandom->SetSeed(0); //the seed is set to the current machine clock!
+ Int_t minEntries=1000; // recalculate calibration coeff. if Nentries > minEntries.
+
+ TIter iter(list);
+ TObjString *source;
+
+ while ((source = dynamic_cast<TObjString *> (iter.Next()))) {
+ AliInfo(Form("found source %s", source->String().Data()));
+
+ TString fileName = GetFile(system, "AMPLITUDES", source->GetName());
+ AliInfo(Form("Got filename: %s",fileName.Data()));
+
+ TFile f(fileName);
+
+ if(!f.IsOpen()) {
+ Log(Form("File %s is not opened, something goes wrong!",fileName.Data()));
+ return kFALSE;
+ }
+