]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - PMD/PMDGAINda.cxx
QA for simulation in AD
[u/mrichter/AliRoot.git] / PMD / PMDGAINda.cxx
index bb59e3d325a5a14bdf97e19f743b8f946df5adbe..2a925b116fdf7db6202a71873076a889c51c89a8 100644 (file)
@@ -1,13 +1,13 @@
 /*
 PMD DA for online calibration
 
-contact: basanta@phy.iitb.ac.in
-Link:
-Reference run:/afs/cern.ch/user/b/bnandi/public/gaindata/pythia100evts.date
+contact: basanta@iitb.ac.in, Satyajit.Jena@cern.ch
+Link: https://twiki.cern.ch/twiki/bin/view/ALICE/DA
+Reference run:/afs/cern.ch/user/s/sjena/public/run83496.raw
 Run Type: PHYSICS
 DA Type: MON
 Number of events needed: 1 million for PB+PB, 200 milion for p+p
-Input Files: PMD_PED.root, PMD_GAIN_CONFIGFILE, pmd_gain_tempfile.dat
+Input Files: PMD/Calib/Mapping/Run0_999999999_v0_s0.root, PMD_PED.root, PMD_GAIN_CONFIGFILE, pmd_gain_tempfile.dat
 Output Files: PMDGAINS.root, to be exported to the DAQ FES
 Trigger types used: PHYSICS_EVENT
 
@@ -27,6 +27,8 @@ extern "C" {
 #include "AliRawReaderDate.h"
 #include "AliPMDCalibPedestal.h"
 #include "AliPMDCalibGain.h"
+#include "AliLog.h"
+#include "AliCDBManager.h"
 
 //ROOT
 #include "TFile.h"
@@ -35,7 +37,7 @@ extern "C" {
 #include "TTree.h"
 #include "TROOT.h"
 #include "TPluginManager.h"
-
+#include "TSystem.h"
 
 
 /* Main routine
@@ -57,10 +59,12 @@ int main(int argc, char **argv) {
 
     Int_t filestatus = -1, xvar = 5;
     Int_t totevt = -1, maxevt = -1;
+    Int_t hotevtsize = -1;
+    Bool_t hotfilestatus = false;
 
     // Reads the pedestal file and keep the values in memory for subtraction
 
-    AliPMDCalibGain calibgain;
+    AliPMDCalibGain *calibgain = new AliPMDCalibGain();
 
     // Fetch the pedestal file - PMD_PED.root 
 
@@ -76,7 +80,7 @@ int main(int argc, char **argv) {
        return -1;
       }
     
-    Int_t pstatus = calibgain.ExtractPedestal("PMD_PED.root");
+    Int_t pstatus = calibgain->ExtractPedestal("PMD_PED.root");
 
     if(pstatus == -3) return -3;
 
@@ -97,8 +101,8 @@ int main(int argc, char **argv) {
       }
     else
       {
-       fscanf(fp1,"%d %d %d %d\n",&filestatus, &xvar, &totevt, &maxevt);
-       //printf("%d %d %d %d\n",filestatus, xvar, totevt, maxevt);
+       fscanf(fp1,"%d %d %d %d %d\n",&filestatus, &xvar, &totevt, &maxevt, &hotevtsize);
+       //printf("%d %d %d %d %d\n",filestatus, xvar, totevt, maxevt, hotevtsize);
       }
     fclose(fp1);
 
@@ -109,7 +113,7 @@ int main(int argc, char **argv) {
        status = daqDA_DB_getFile("pmd_gain_tempfile.dat","pmd_gain_tempfile.dat");
        if(!status)
          {
-           calibgain.ReadTempFile("pmd_gain_tempfile.dat");
+           calibgain->ReadTempFile("pmd_gain_tempfile.dat");
          }
        else
          {
@@ -119,7 +123,7 @@ int main(int argc, char **argv) {
        status = daqDA_DB_getFile("PMD_HOT.root","PMD_HOT.root");
        if(!status)
          {
-           calibgain.ExtractHotChannel("PMD_HOT.root");
+           calibgain->ExtractHotChannel("PMD_HOT.root");
          }
        else
          {
@@ -166,6 +170,42 @@ int main(int argc, char **argv) {
     eventTypeType eventT = 0;
 
     Int_t iev=0;
+
+    // Get run number
+
+    int runNr = 0;
+
+    if (getenv("DATE_RUN_NUMBER")==0) {
+      printf("DATE_RUN_NUMBER not properly set.\n");
+      printf("Run Number set to Zero \n");
+      //return -1;
+    }
+    else
+      {
+       runNr = atoi(getenv("DATE_RUN_NUMBER"));
+      }
+
+    if (gSystem->AccessPathName("localOCDB/PMD/Calib/Mapping",kFileExists))
+      {
+       if (gSystem->mkdir("localOCDB/PMD/Calib/Mapping",kTRUE) != 0)
+         {
+           printf("Failed to create directory: localOCDB/PMD/Calib/Mapping");
+           return -1;
+         }
+      }
+    status = daqDA_DB_getFile("PMD/Calib/Mapping/Run0_999999999_v0_s0.root","localOCDB/PMD/Calib/Mapping/Run0_999999999_v0_s0.root");
+    if (status)
+      {
+       printf("Failed to get PMD-Mapping file (PMD/Calib/Mapping/Run0_999999999_v0_s0.root) from DAQdetDB, status=%d\n", status);
+       return -1;
+      }
+
+    // Global initializations
+    AliLog::SetGlobalLogLevel(AliLog::kError);
+    AliCDBManager *man = AliCDBManager::Instance();
+    man->SetDefaultStorage("local://localOCDB");
+    man->SetRun(runNr);
+
     
     /* main loop (infinite) */
     for(;;) {
@@ -208,11 +248,13 @@ int main(int argc, char **argv) {
                
            case PHYSICS_EVENT:
                nevents_physics++;
+               totevt++;
                //if(nevents_physics%100 == 0)printf("Physis Events = %d\n",nevents_physics);
                AliRawReader *rawReader = new AliRawReaderDate((void*)event);
                TObjArray *pmdddlcont = new TObjArray();
-               calibgain.ProcessEvent(rawReader, pmdddlcont);
+               calibgain->ProcessEvent(rawReader, pmdddlcont);
 
+               if (totevt%hotevtsize == 0) hotfilestatus = true;
                delete pmdddlcont;
                pmdddlcont = 0x0;
                delete rawReader;
@@ -237,7 +279,7 @@ int main(int argc, char **argv) {
 
        TTree *hot = new TTree("hot","PMD Hot cell tree");
        
-       calibgain.FindHotCell(hot,xvar);
+       calibgain->FindHotCell(hot,xvar);
        
        hot->Write();
        hotRun->Close();
@@ -245,10 +287,34 @@ int main(int argc, char **argv) {
        // store the hot cell root file in the DB
 
        status = daqDA_DB_storeFile("PMD_HOT.root","PMD_HOT.root");
+
+       // store the hot cell root file in the file exchange server
+
+       printf("root file for hot cell is created and getting exported\n");
+       status = daqDA_FES_storeFile("PMD_HOT.root","PMD_HOT.root");
       }
 
+    if (hotfilestatus)
+      {
+       TFile *hotRun = new TFile ("PMD_HOT.root","RECREATE");
+
+       TTree *hot = new TTree("hot","PMD Hot cell tree");
+       
+       calibgain->FindHotCell(hot,xvar);
+       
+       hot->Write();
+       hotRun->Close();
+
+       // store the hot cell root file in the DB
+
+       status = daqDA_DB_storeFile("PMD_HOT.root","PMD_HOT.root");
+       
+       // store the hot cell root file in the file exchange server
+
+       printf("root file for hot cell is created and getting exported\n");
+       status = daqDA_FES_storeFile("PMD_HOT.root","PMD_HOT.root");
+      }
 
-    totevt += nevents_physics++;
 
     fp1 = fopen("PMD_GAIN_CONFIGFILE","w+");
 
@@ -260,13 +326,13 @@ int main(int argc, char **argv) {
        printf("***  Writing the intermediate ASCII file    ***\n");
        printf("-----------------------------------------------\n");
 
-       calibgain.WriteTempFile("pmd_gain_tempfile.dat");
+       calibgain->WriteTempFile("pmd_gain_tempfile.dat");
 
        // Store the Intermediate ascii file in the DB
        status = daqDA_DB_storeFile("pmd_gain_tempfile.dat","pmd_gain_tempfile.dat");
 
        filestatus = 1;
-       fprintf(fp1,"%d %d %d %d\n",filestatus,xvar,totevt,maxevt);
+       fprintf(fp1,"%d %d %d %d %d\n",filestatus,xvar,totevt,maxevt,hotevtsize);
        fclose(fp1);
 
        // Store the configfile in the DB
@@ -280,7 +346,7 @@ int main(int argc, char **argv) {
        printf("***  Writing the PMDGAINS.root file           ***\n");
        printf("-----------------------------------------------\n");
 
-       calibgain.Analyse(ic, meanc);
+       calibgain->Analyse(ic, meanc);
 
        TFile * gainRun = new TFile ("PMDGAINS.root","RECREATE"); 
        ic->Write();
@@ -293,7 +359,7 @@ int main(int argc, char **argv) {
 
        filestatus = 0;
        totevt     = 0;
-       fprintf(fp1,"%d %d %d %d\n",filestatus,xvar,totevt,maxevt);
+       fprintf(fp1,"%d %d %d %d %d\n",filestatus,xvar,totevt,maxevt,hotevtsize);
        fclose(fp1);
 
        // Store the configfile in the DB
@@ -306,6 +372,7 @@ int main(int argc, char **argv) {
     delete meanc;
     meanc = 0;
     
+    delete calibgain;
 
     /* store the result file on FES */
  
@@ -313,11 +380,14 @@ int main(int argc, char **argv) {
       {
        printf("root file for cell gain is created and getting exported\n");
        status = daqDA_FES_storeFile("PMDGAINS.root","PMDGAINS.root");
-       printf("root file for hot cell is created and getting exported\n");
-       status = daqDA_FES_storeFile("PMD_HOT.root","PMD_HOT.root");
        printf("root file for normalised means of different modules\n");
        status = daqDA_FES_storeFile("PMD_MEAN_SM.root","PMD_MEAN_SM.root");
       }
+
+    if (hotfilestatus)
+      {
+      }
+
     
     if (status) {
       status = -2;