added method to read pedestal
authorbasanta <basanta@f7af4fe6-9843-0410-8265-dc069ae4e863>
Sun, 29 Jun 2008 17:49:34 +0000 (17:49 +0000)
committerbasanta <basanta@f7af4fe6-9843-0410-8265-dc069ae4e863>
Sun, 29 Jun 2008 17:49:34 +0000 (17:49 +0000)
PMD/AliPMDCalibGain.cxx
PMD/AliPMDCalibGain.h
PMD/PMDGAINda.cxx

index 02355e0..28a602d 100644 (file)
 
 ClassImp(AliPMDCalibGain)
 
-AliPMDCalibGain::AliPMDCalibGain(): TObject()
+AliPMDCalibGain::AliPMDCalibGain():
+  TObject(),
+  fpw(NULL)
 {
   // Standard Constructor
     for(Int_t idet = 0; idet < kDet; idet++)
     {
+     fDetCount[kDet] =0.;
        for(Int_t ismn = 0; ismn < kMaxSMN; ismn++)
        {
            fSMIso[idet][ismn]   = 0.;
@@ -52,18 +55,25 @@ AliPMDCalibGain::AliPMDCalibGain(): TObject()
                {
                    fCellIso[idet][ismn][jrow][kcol]   = 0.;
                    fCellCount[idet][ismn][jrow][kcol] = 0.;
+                   fPedMeanRMS[idet][ismn][jrow][kcol] = 0.;
+
                }
            }
        }
     }
 
+
+
 }
 // ------------------------------------------------------------------------ //
 AliPMDCalibGain::AliPMDCalibGain(const AliPMDCalibGain &pmdcalibgain):
-    TObject(pmdcalibgain)
+  TObject(pmdcalibgain),
+  fpw(NULL)
 {
     for(Int_t idet = 0; idet < kDet; idet++)
     {
+     fDetCount[idet] = pmdcalibgain.fDetCount[idet];
+     fDetIso[idet] = pmdcalibgain.fDetIso[idet];
        for(Int_t ismn = 0; ismn < kMaxSMN; ismn++)
        {
            fSMIso[idet][ismn] = pmdcalibgain.fSMIso[idet][ismn] ;
@@ -72,8 +82,13 @@ AliPMDCalibGain::AliPMDCalibGain(const AliPMDCalibGain &pmdcalibgain):
            {
                for(Int_t kcol = 0; kcol < kMaxCol; kcol++)
                {
-                   fCellIso[idet][ismn][jrow][kcol]  = pmdcalibgain.fCellIso[idet][ismn][jrow][kcol];
-                   fCellCount[idet][ismn][jrow][kcol]  = pmdcalibgain.fCellCount[idet][ismn][jrow][kcol];
+                 fCellIso[idet][ismn][jrow][kcol]    =
+                   pmdcalibgain.fCellIso[idet][ismn][jrow][kcol];
+                 fCellCount[idet][ismn][jrow][kcol]  =
+                   pmdcalibgain.fCellCount[idet][ismn][jrow][kcol];
+                 fPedMeanRMS[idet][ismn][jrow][kcol] =
+                   pmdcalibgain.fPedMeanRMS[idet][ismn][jrow][kcol];
+
                }
            }
        }
@@ -85,6 +100,7 @@ AliPMDCalibGain &AliPMDCalibGain::operator=(const AliPMDCalibGain &pmdcalibgain)
 {
     if(this != &pmdcalibgain)
     {
+      this->fpw = pmdcalibgain.fpw;
        for(Int_t idet = 0; idet < kDet; idet++)
        {
            for(Int_t ismn = 0; ismn < kMaxSMN; ismn++)
@@ -94,11 +110,14 @@ AliPMDCalibGain &AliPMDCalibGain::operator=(const AliPMDCalibGain &pmdcalibgain)
                for(Int_t jrow = 0; jrow < kMaxRow;jrow++)
                {
                    for(Int_t kcol = 0; kcol < kMaxCol; kcol++)
-                   {
+                     {
                        fCellIso[idet][ismn][jrow][kcol]  =
-                           pmdcalibgain.fCellIso[idet][ismn][jrow][kcol];
+                         pmdcalibgain.fCellIso[idet][ismn][jrow][kcol];
                        fCellCount[idet][ismn][jrow][kcol]  =
-                           pmdcalibgain.fCellCount[idet][ismn][jrow][kcol];
+                         pmdcalibgain.fCellCount[idet][ismn][jrow][kcol];
+                       fPedMeanRMS[idet][ismn][jrow][kcol] = 
+                         pmdcalibgain.fPedMeanRMS[idet][ismn][jrow][kcol];
+
                    }
                }
            }
@@ -112,16 +131,161 @@ AliPMDCalibGain::~AliPMDCalibGain()
     // dtor
 
 }
+
+// ------------------------------------------------------------------------ //
+
+Int_t AliPMDCalibGain::ExtractPedestal()
+{
+  // Pedestal extraction from the PMD_PED.root file
+  // To be called once at the beginning
+
+  Int_t   det, sm, row, col;
+  Float_t mean, rms;
+
+  TFile *pedfile = new TFile("PMD_PED1.root");
+
+  if(!pedfile)
+    {
+      printf("ERROR --- NO PEDESTAL (PMD_PED1.root) FILE IS FOUND --- STOP GAIN DA\n");
+      return -3;
+    }
+
+
+  TTree *ped =(TTree*)pedfile->Get("ped");
+
+  ped->SetBranchAddress("det",&det);
+  ped->SetBranchAddress("sm",&sm);
+  ped->SetBranchAddress("row",&row);
+  ped->SetBranchAddress("col",&col);
+  ped->SetBranchAddress("mean",&mean);
+  ped->SetBranchAddress("rms",&rms);
+
+  Int_t nentries = (Int_t)ped->GetEntries();
+
+  for (Int_t ient = 0; ient < nentries; ient++)
+    {
+      ped->GetEntry(ient);
+      fPedMeanRMS[det][sm][row][col] = mean + 3.*rms;
+      //printf("Mean= %f, RMS= %f, PedMeanRMS=%f\n",mean,rms,fPedMeanRMS[det][sm][row][col]);
+
+    }
+
+  pedfile->Close();
+  delete pedfile;
+  pedfile = 0x0;
+
+  return 1;
+}
+// ------------------------------------------------------------------------ //
+
+void AliPMDCalibGain::ReadIntermediateFile()
+{
+  // Read the variables from the file
+  
+  fpw = fopen("interfile.dat","r");
+
+  Float_t detcount, detiso;
+  Float_t smcount, smiso;
+  Float_t cellcount, celliso;
+
+  for (Int_t idet = 0; idet < kDet; idet++)
+    {
+      fscanf(fpw,"%d %f %f",&idet,&detcount,&detiso);
+      fDetCount[idet] = detcount;
+      fDetIso[idet]   = detiso;
+    }
+
+  for (Int_t idet = 0; idet < kDet; idet++)
+    {
+      for (Int_t ism = 0; ism < kMaxSMN; ism++)
+       {
+         fscanf(fpw,"%d %d %f %f",&idet,&ism,&smcount,&smiso);
+
+         fSMCount[idet][ism] = smcount;
+         fSMIso[idet][ism]   = smiso;
+       }
+    }
+
+  for (Int_t idet = 0; idet < kDet; idet++)
+    {
+      for (Int_t ism = 0; ism < kMaxSMN; ism++)
+       {
+         for (Int_t irow = 0; irow < kMaxRow; irow++)
+           {
+             for (Int_t icol = 0; icol < kMaxCol; icol++)
+               {
+                 fscanf(fpw,"%d %d %d %d %f %f",&idet,&ism,&irow,&icol,
+                         &cellcount,&celliso);
+
+                 fCellCount[idet][ism][irow][icol] = cellcount;
+                 fCellIso[idet][ism][irow][icol]   = celliso;
+               }
+           }
+       }
+    }
+
+  fclose(fpw);
+
+}
 // ------------------------------------------------------------------------ //
+void AliPMDCalibGain::WriteIntermediateFile()
+{
+
+ //Following variables to be written
+
+  /*
+    fDetIso[idet] ;
+    fSMIso[idet][ismn]; 
+    fCellIso[idet][ismn][irow][icol]; 
+    
+    fDetCount[idet];
+    fSMCount[idet][ismn];
+    fCellCount[idet][ismn][irow][icol];
+  */                             
+
+  fpw = fopen("interfile.dat","w+");
+
+  for (Int_t idet = 0; idet < kDet; idet++)
+    {
+      fprintf(fpw,"%d %f %f\n",idet,fDetCount[idet],fDetIso[idet]);
+    }
+
+  for (Int_t idet = 0; idet < kDet; idet++)
+    {
+      for (Int_t ism = 0; ism < kMaxSMN; ism++)
+       {
+         fprintf(fpw,"%d %d %f %f\n",idet,ism, fSMCount[idet][ism],fSMIso[idet][ism]);
+       }
+    }
+
+  for (Int_t idet = 0; idet < kDet; idet++)
+    {
+      for (Int_t ism = 0; ism < kMaxSMN; ism++)
+       {
+         for (Int_t irow = 0; irow < kMaxRow; irow++)
+           {
+             for (Int_t icol = 0; icol < kMaxCol; icol++)
+               {
+                 fprintf(fpw,"%d %d %d %d %f %f\n",idet,ism,irow,icol,
+                         fCellCount[idet][ism][irow][icol],
+                         fCellIso[idet][ism][irow][icol]);
+               }
+           }
+       }
+    }
+
+  fclose(fpw);
+
+}
+
+// ------------------------------------------------------------------------ //
+
 Bool_t AliPMDCalibGain::ProcessEvent(AliRawReader *rawReader, TObjArray *pmdddlcont)
 {
   // Calculates the ADC of isolated cell
 
-  //TObjArray pmdddlcont;
-
   const Int_t kDDL           = AliDAQ::NumberOfDdls("PMD");
   const Int_t kCellNeighbour = 6;
-
   Int_t neibx[6] = {1,0,-1,-1,0,1};
   Int_t neiby[6] = {0,1,1,0,-1,-1};
   
@@ -146,7 +310,7 @@ Bool_t AliPMDCalibGain::ProcessEvent(AliRawReader *rawReader, TObjArray *pmdddlc
 
   AliPMDRawStream rawStream(rawReader);
 
-  Int_t iddl;
+  Int_t iddl = -1;
 
   Int_t numberofDDLs = 0;
 
@@ -154,6 +318,7 @@ Bool_t AliPMDCalibGain::ProcessEvent(AliRawReader *rawReader, TObjArray *pmdddlc
       numberofDDLs++;
 
       Int_t ientries = pmdddlcont->GetEntries();
+
       for (Int_t ient = 0; ient < ientries; ient++)
       {
          AliPMDddldata *pmdddl = (AliPMDddldata*)pmdddlcont->UncheckedAt(ient);
@@ -165,11 +330,16 @@ Bool_t AliPMDCalibGain::ProcessEvent(AliRawReader *rawReader, TObjArray *pmdddlc
          Int_t irow = pmdddl->GetRow();
          Int_t icol = pmdddl->GetColumn();
          Int_t isig = pmdddl->GetSignal();
-         
+
+
+         // Pedestal subtraction
+
          if (isig>0)
-         {
-             d1[idet][ismn][irow][icol] = (Float_t) isig;
-         }
+           {
+             d1[idet][ismn][irow][icol] =
+               (Float_t) isig - fPedMeanRMS[idet][ismn][irow][icol];
+//printf("Signal_ped_subtracted=%f, pedestal=%f\n",d1[idet][ismn][irow][icol]),fPedMeanRMS[idet][ismn][irow][icol];
+           }
       }
       pmdddlcont->Delete();
   }
@@ -194,10 +364,10 @@ Bool_t AliPMDCalibGain::ProcessEvent(AliRawReader *rawReader, TObjArray *pmdddlc
                              isocount++;
                              if(isocount == kCellNeighbour)
                              {
-
+                                  fDetIso[idet] += d1[idet][ismn][irow][icol];
                                  fSMIso[idet][ismn] += d1[idet][ismn][irow][icol];
                                  fCellIso[idet][ismn][irow][icol] += d1[idet][ismn][irow][icol];
-                                 
+                                 fDetCount[idet]++;
                                  fSMCount[idet][ismn]++;
                                  fCellCount[idet][ismn][irow][icol]++;
                                  
@@ -208,7 +378,6 @@ Bool_t AliPMDCalibGain::ProcessEvent(AliRawReader *rawReader, TObjArray *pmdddlc
              }
          }
       }
-      
   }
 
   if (numberofDDLs < kDDL)
@@ -224,6 +393,7 @@ void AliPMDCalibGain::Analyse(TTree *gaintree)
     Float_t gain;
     Float_t modmean  = 0.;
     Float_t cellmean = 0.;
+    Float_t detmean =0.;
 
     gaintree->Branch("det",&det,"det/I");
     gaintree->Branch("sm",&sm,"sm/I");
@@ -232,34 +402,40 @@ void AliPMDCalibGain::Analyse(TTree *gaintree)
     gaintree->Branch("gain",&gain,"gain/F");
 
     for(Int_t idet = 0; idet < kDet; idet++)
-    {
+      {
+       if (fDetCount[idet]>0 )
+         detmean=fDetIso[idet]/fDetCount[idet];
        for(Int_t ism = 0; ism < kMaxSMN; ism++)
-       {
+         {
            if (fSMCount[idet][ism] > 0)
-               modmean = fSMIso[idet][ism]/fSMCount[idet][ism];
+             modmean = fSMIso[idet][ism]/fSMCount[idet][ism];
            for(Int_t irow = 0; irow < kMaxRow; irow++)
-           {
+             {
                for(Int_t icol = 0; icol < kMaxCol; icol++)
-               {
-                   if (fCellCount[idet][ism][irow][icol] > 0)
-                       cellmean = fCellIso[idet][ism][irow][icol]/fCellCount[idet][ism][irow][icol];
-                   
+                 {
                    
+                   if (fCellCount[idet][ism][irow][icol] > 0.)
+                      {
+                       cellmean = fCellIso[idet][ism][irow][icol]/fCellCount[idet][ism][irow][icol];
+                     }
                    det      = idet;
                    sm       = ism;
                    row      = irow;
                    col      = icol;
-                   gain     = 1.;
-
-                   if(modmean > 0.0)
-                   {
-                       gain = cellmean/modmean;
-                   }
+                   if (cellmean > 0.0 && fCellCount[idet][ism][irow][icol]>0.)
+                     {
+                       gain = cellmean/detmean;
+                     }
+                    else
+                      {
+                        gain = -1.;
+                     }
+                    //if(fCellCount[idet][ism][irow][icol]>0.) printf("CellCount =%f, gain= %f\n",fCellCount[idet][ism][irow][icol],gain);
                    gaintree->Fill();
-               }
-           }
-       }
-    }
+                 }
+             }
+         }
+      }
     
 }
 // ------------------------------------------------------------------------ //
index db04abf..e2ae41f 100644 (file)
@@ -15,7 +15,11 @@ class AliPMDCalibGain : public TObject
   AliPMDCalibGain(const AliPMDCalibGain &pmdcalibgain);  // copy constructor
   AliPMDCalibGain &operator=(const AliPMDCalibGain &pmdcalibgain); // assignment op
 
-  virtual ~AliPMDCalibGain() ;     // dtor
+  virtual ~AliPMDCalibGain() ;           // dtor
+
+  Int_t ExtractPedestal();               // Assign the pedestal values
+  void  ReadIntermediateFile();          // reads the intermediate file
+  void  WriteIntermediateFile();         // writes the intermediate file
 
   Bool_t ProcessEvent(AliRawReader *rawReader, TObjArray *pmdddlcont);  //Looks for iso cells
 
@@ -31,11 +35,16 @@ class AliPMDCalibGain : public TObject
          kMaxCol = 96   // Number of Columns
       };
 
+  Float_t fDetCount[kDet];                             //counter detector wise
+  Float_t fDetIso[kDet];
   Float_t fSMIso[kDet][kMaxSMN];
-  Float_t fSMCount[kDet][kMaxSMN]; // counter
-  Float_t fCellIso[kDet][kMaxSMN][kMaxRow][kMaxCol]; // adc of iso cells
+  Float_t fSMCount[kDet][kMaxSMN];                     // counter
+  Float_t fCellIso[kDet][kMaxSMN][kMaxRow][kMaxCol];   // adc of iso cells
   Float_t fCellCount[kDet][kMaxSMN][kMaxRow][kMaxCol]; // counter
 
-ClassDef(AliPMDCalibGain,3)        // description 
+  Float_t fPedMeanRMS[kDet][kMaxSMN][kMaxRow][kMaxCol];// Pedestal Mean
+  FILE    *fpw;         // write the intermediate file
+
+ClassDef(AliPMDCalibGain,4)        // description 
 };
 #endif // ALIPMDCALIBGAIN_H
index 1c8ce60..0fe0d75 100644 (file)
@@ -7,8 +7,8 @@ Reference run:
 Run Type: PHYSICS
 DA Type: MON
 Number of events needed: 1 million for PB+PB, 200 milion for p+p
-Input Files: 
-Output Files: pmd_calib.root, to be exported to the DAQ FXS
+Input Files: PMD_PED.root, Configfile
+Output Files: PMDGAINS.root, to be exported to the DAQ FXS
 Trigger types used: PHYSICS_EVENT
 
 */
@@ -52,13 +52,43 @@ int main(int argc, char **argv) {
                                          "RIO",
                                          "TStreamerInfo()");
 
+    Int_t filestatus = -1, totevt = -1;
+    Int_t maxevt = -1;
+
+    // Reads the pedestal file and keep the values in memory for subtraction
+
     AliPMDCalibGain calibgain;
+    Int_t pstatus = calibgain.ExtractPedestal();
+
+    if(pstatus == -3) return -3;
 
     TTree *ic = NULL;
 
-    //TH1F::AddDirectory(0);
-  
+    FILE *fp1 = NULL;
+
+    fp1 = fopen("Configfile","r");
+
+    if (fp1 == NULL)
+      {
+       printf("**** Configfile doesn't exist, creating the file ****\n");
+       fp1 = fopen("Configfile","w");
+       filestatus = 0;
+       totevt     = 0;
+       maxevt     = 2000;
+       fprintf(fp1,"%d %d %d\n",filestatus, totevt,maxevt);
+      }
+    else
+      {
+       fscanf(fp1,"%d %d %d\n",&filestatus, &totevt,&maxevt);
+       //printf("%d %d %d\n",filestatus, totevt, maxevt);
+      }
+    fclose(fp1);
     
+    if (filestatus == 1)
+      {
+       calibgain.ReadIntermediateFile();
+      }
+
     // decoding the events
     
     int status;
@@ -68,13 +98,6 @@ int main(int argc, char **argv) {
        return -1;
     }
     
-    /* open result file */
-    FILE *fp=NULL;
-    fp=fopen("./result.txt","a");
-    if (fp==NULL) {
-       printf("Failed to open file\n");
-       return -1;
-    }
     
     /* define data source : this is argument 1 */  
     status=monitorSetDataSource( argv[1] );
@@ -95,7 +118,7 @@ int main(int argc, char **argv) {
     monitorSetNoWaitNetworkTimeout(1000);
     
     /* log start of process */
-    printf("DA example case2 monitoring program started\n");  
+    printf("PMD GAIN DA - strted generating the gain of a cell\n");  
     
     /* init some counters */
     int nevents_physics=0;
@@ -147,7 +170,7 @@ int main(int argc, char **argv) {
                
            case PHYSICS_EVENT:
                nevents_physics++;
-               if(nevents_physics%100 == 0)printf("Physis Events = %d\n",nevents_physics);
+               //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);
@@ -167,32 +190,52 @@ int main(int argc, char **argv) {
     /* exit when last event received, no need to wait for TERM signal */
 
     ic = new TTree("ic","PMD Gain tree");
-    if (eventT==END_OF_RUN) {
-      printf("EOR event detected\n");
-      calibgain.Analyse(ic);
-    }
-    
-    //write the Run level file   
-    TFile * fileRun = new TFile ("outPMDdaRun.root","RECREATE"); 
-    TBenchmark *bench = new TBenchmark();
-    bench->Start("PMD");
-    bench->Stop("PMD");
-    bench->Print("PMD");
-    fileRun->Close();
-    
-    /* write report */
-    fprintf(fp,"Run #%s, received %d physics events out of %d\n",getenv("DATE_RUN_NUMBER"),nevents_physics,nevents_total);
-    
 
-    TFile * gainRun = new TFile ("PMDGAINS.root","RECREATE"); 
-    ic->Write();
-    gainRun->Close();
+    totevt += nevents_physics++;
+
+    fp1 = fopen("Configfile","w+");
+
+    if (totevt < maxevt)
+      {
+       printf("Required Number of Events not reached\n");
+       printf("Number of Events processed = %d\n",totevt);
+       printf("Writing the intermediate ASCII file\n");
+       calibgain.WriteIntermediateFile();
+
+       filestatus = 1;
+       fprintf(fp1,"%d %d %d\n",filestatus,totevt,maxevt);
+      }
+    else if (totevt >= maxevt)
+      {
+       printf("Required Number of Events reached = %d\n",totevt);
+       calibgain.Analyse(ic);
+
+       TFile * gainRun = new TFile ("PMDGAINS.root","RECREATE"); 
+       ic->Write();
+       gainRun->Close();
+
+       filestatus = 0;
+       totevt     = 0;
+       fprintf(fp1,"%d %d %d\n",filestatus,totevt,maxevt);
+      }
+    fclose(fp1);
     
     delete ic;
     ic = 0;
+    
+
+    /* store the result file on FES */
+    if (filestatus == 0)
+      {
+       printf("root file is created and getting exported\n");
+       status = daqDA_FES_storeFile("PMDGAINS.root","gaincalib");
+      }
+
+    if (status) {
+      status = -2;
+    }
 
-    /* close result file */
-    fclose(fp);
 
     return status;
 }