]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - VZERO/VZEROTUNING1da.cxx
VZEROTUNING2da.cxx has been renamed VZEROINTEGRATIONGATETUNINGda.cxx
[u/mrichter/AliRoot.git] / VZERO / VZEROTUNING1da.cxx
index fe2e32d4a5989531cadcf2c61049c8fc4b3a4eb4..79b5917d23ef00d9a302a2a6793a55742f9291c9 100644 (file)
@@ -3,12 +3,12 @@
 - Link:       http
 - Raw data test file : 
 - Reference run number :             
-- Run Type:   STANDALONE
+- Run Type:   CHANNEL_DELAY_TUNING
 - DA Type:    LDC
 - Number of events needed: 500
 - Input Files:  argument list
-- Output Files: local file  V0_Tuning1.dat
-                FXS file    V0_Tuning1.dat
+- Output Files: local file  V0_ChannelDelayTuning.dat
+                FXS file    V0_ChannelDelayTuning.dat
 - Trigger types used: PHYSICS_EVENT
 **********************************************************************************/
 
@@ -18,8 +18,8 @@
 * VZERO Detector Algorithm used for tuning FEE parameters                         *
 *                                                                                 *
 * This program reads data on the LDC                                              *
-* It cumulates fBB and fBG flags, populates local "./V0_Tuning1.dat"              *            
-* file and exports it to the FES.                                                 *
+* It cumulates fBB and fBG flags, populates local "./V0_ChannelDelayTuning.dat"   *            
+* file, exports it to the FES, and stores it to DAQ DB                            *
 * We have 128 channels instead of 64 as expected for V0 due to the two sets of    *
 * charge integrators which are used by the FEE ...                                *
 * The program reports about its processing progress.                              *
@@ -60,16 +60,54 @@ int main(int argc, char **argv) {
                     "RIO",
                     "TStreamerInfo()");
   int status;
+  status = daqDA_DB_getFile("V00da_results","./V0_Ped_Width_Gain.dat");
+  if (status) {
+      printf("Failed to get Pedestal file (V0_Ped_Width_Gain.dat) from DAQ DB, status=%d\n", status);
+      return -1;   
+  }
+  
+  Float_t MeanPed[128], SigPed[128], fdump;
+  
+  /* open the pedestal file and retrieve pedestal mean and sigma */
+  FILE *fpPed = fopen("V0_Ped_Width_Gain.dat","r");
+  for(int i=0;i<128;i++){
+      fscanf(fpPed,"%f %f %f %f \n",&MeanPed[i],&SigPed[i],&fdump,&fdump);
+//      printf("%.3f %.3f \n",MeanPed[i],SigPed[i]);
+  }
+  fclose(fpPed);
+
+//______________________________________________________________________________
+// Get running parameters from V00_ChannelDelayTuning_DA.config file
+
+  Int_t    kNbEventSkipped;   // = 100;   number of events skipped - to be tuned
+  Float_t  kSigmaCut;         // = 3.0;   number of sigmas for threshold cut - to be tuned
+  
+  status = daqDA_DB_getFile("V00_ChannelDelayTuning_DA.config","./V00_ChannelDelayTuning_DA.config");
+  if (status) {
+      printf("Failed to get config file (V00_ChannelDelayTuning_DA.config) from DAQ DB, status=%d\n", status);
+      return -1;   
+  }
+  /* open the config file and retrieve running parameters */
+  FILE *fpConfig = fopen("V00_ChannelDelayTuning_DA.config","r");
+  fscanf(fpConfig,"%f %d",&kSigmaCut,&kNbEventSkipped);
+  fclose(fpConfig);
+  
+  printf("Number of events skipped = %d ; Number of sigmas for threshold cut = %f\n",kNbEventSkipped,kSigmaCut);
+//______________________________________________________________________________
 
-  Float_t BBFlag[128];
-  Float_t BGFlag[128];
-  for(Int_t i=0; i<128; i++) {
-      BBFlag[i] = 0.0;
-      BGFlag[i] = 0.0;
+  Int_t BBFlag[64];
+  Int_t BGFlag[64];
+  Int_t ChargeEoI = 0;
+  Bool_t Integrator = 0;
+  Int_t NHit[64];
+  for(Int_t i=0; i<64; i++) {
+      BBFlag[i] = 0;
+      BGFlag[i] = 0;
+      NHit[i] = 0;
   } 
       
   /* log start of process */
-  printf("VZERO DA program started - Tuning FEE parameters\n");  
+  printf("VZERO DA program started - Channel Delay Tuning \n");  
 
   /* check that we got some arguments  */
   if (argc<2)   {
@@ -78,14 +116,14 @@ int main(int argc, char **argv) {
 
   /* open result file to be exported to FES */
   FILE *fp=NULL;
-  fp=fopen("./V0_Tuning1.dat","a");
+  fp=fopen("./V0_ChannelDelayTuning.dat","a");
   if (fp==NULL) {
       printf("Failed to open result file\n");
       return -1;}
 
   /* open log file to inform user */
   FILE *flog=NULL;
-  flog=fopen("./V00log.txt","a");
+  flog=fopen("./V00log.txt","w");
   if (flog==NULL) {
       printf("Failed to open log file\n");
       return -1;  }
@@ -105,8 +143,8 @@ int main(int argc, char **argv) {
   /* read the data  */
     status=monitorSetDataSource( argv[n] );
     if (status!=0) {
-       printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
-       return -1; }
+        printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
+        return -1; }
 
   /* report progress */
     daqDA_progressReport(10+50*n/argc);
@@ -132,10 +170,11 @@ int main(int argc, char **argv) {
         switch (event->eventType){
       
         case START_OF_RUN:
+            printf("START Of Run detected\n");
              break;
       
         case END_OF_RUN:
-            printf("End Of Run detected\n");
+            printf("END Of Run detected\n");
              break;
       
         case PHYSICS_EVENT:
@@ -145,18 +184,19 @@ int main(int argc, char **argv) {
   
             AliVZERORawStream* rawStream  = new AliVZERORawStream(rawReader); 
             rawStream->Next(); 
-            for(Int_t i=0; i<64; i++) {
-               if(!rawStream->GetIntegratorFlag(i,10))
-               {
-                   if(rawStream->GetBBFlag(i,10)) BBFlag[i]++;       // even integrator - channel 0 to 63
-                  if(rawStream->GetBGFlag(i,10)) BGFlag[i]++;       // even integrator - channel 0 to 63
-               } 
-               else 
-               {                  
-                  if(rawStream->GetBBFlag(i,10)) BBFlag[i+64]++;    // odd integrator  - channel 64 to 123
-                  if(rawStream->GetBGFlag(i,10)) BGFlag[i+64]++;    // odd integrator  - channel 64 to 123
-               }
-             }    
+            if(nevents_physics > kNbEventSkipped){
+               for(Int_t i=0; i<64; i++) {
+                   ChargeEoI = rawStream->GetADC(i);
+                   Integrator = rawStream->GetIntegratorFlag(i,10);
+                   Float_t Threshold = MeanPed[i + 64 * Integrator] + kSigmaCut * SigPed[i + 64 * Integrator];
+
+                   if((float)ChargeEoI>Threshold) {
+                       NHit[i]+=1;
+                       if(rawStream->GetBBFlag(i,10)) BBFlag[i]+=1;       
+                       if(rawStream->GetBGFlag(i,10)) BGFlag[i]+=1; 
+                   }            
+               }    
+            }
              delete rawStream;
              rawStream = 0x0;      
              delete rawReader;
@@ -172,12 +212,16 @@ int main(int argc, char **argv) {
    
 //________________________________________________________________________
 //  Computes mean values, dumps them into the output text file
-       
-  for(Int_t i=0; i<128; i++) {
-      BBFlag[i] = BBFlag[i]/nevents_physics;
-      BGFlag[i] = BGFlag[i]/nevents_physics;
-      fprintf(fp," %d %d %f %f\n",iteration,i,BBFlag[i],BGFlag[i]);
-      fprintf(flog," %d %d %f %f\n",iteration,i,BBFlag[i],BGFlag[i]);
+  Float_t fBB, fBG;    
+  for(Int_t i=0; i<64; i++) {      
+      if(NHit[i] > 0) {
+         fBB = (float)BBFlag[i]/(float)NHit[i];
+         fBG = (float)BGFlag[i]/(float)NHit[i];
+       }else{
+        fBB = fBG = 0.;
+       }
+       fprintf(fp," %d %d %f %f\n",iteration,i,fBB,fBG);
+       fprintf(flog," it %d ch %d BB %f BG %f BBFlag %d BGFlag %d Hit %d\n",iteration,i,fBB,fBG,BBFlag[i],BGFlag[i],NHit[i]);
   } 
   
 //________________________________________________________________________
@@ -194,11 +238,17 @@ int main(int argc, char **argv) {
   daqDA_progressReport(90);
 
   /* export result file to FES */
-  status=daqDA_FES_storeFile("./V0_Tuning1.dat","V00da_results");
+  status=daqDA_FES_storeFile("./V0_ChannelDelayTuning.dat","V00da_ChannelDelayTuning");
   if (status)    {
       printf("Failed to export file : %d\n",status);
       return -1; }
-
+      
+  /* store result file on Online DB */
+//   status=daqDA_DB_storeFile("./V0_ChannelDelayTuning.dat","V00da_ChannelDelayTuning");
+//   if (status)    {
+//       printf("Failed to store file into Online DB: %d\n",status);
+//       return -1; }
+      
   /* report progress */
   daqDA_progressReport(100);