LCOV - code coverage report
Current view: top level - PHOS/PHOSbase - AliPHOSTriggerRawDigiProducer.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 42 124 33.9 %
Date: 2016-06-14 17:26:59 Functions: 8 19 42.1 %

          Line data    Source code
       1             : /**************************************************************************
       2             :  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
       3             :  *                                                                        *
       4             :  * Author: The ALICE Off-line Project.                                    *
       5             :  * Contributors are mentioned in the code where appropriate.              *
       6             :  *                                                                        *
       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             :  **************************************************************************/
      15             : //This class produces PHOS trigger digits of one event.
      16             : //Authors: Henrik Qvigstad, Boris Polishchuk.
      17             : 
      18             : #include "AliPHOSTriggerRawDigiProducer.h"
      19             : #include "AliPHOSTriggerRawReader.h"
      20             : #include "AliPHOSTRURawReader.h"
      21             : #include "AliPHOSTriggerSTURawStream.h"
      22             : #include "AliPHOSTriggerParameters.h"
      23             : #include "AliPHOSTriggerRawDigit.h"
      24             : #include "AliPHOSGeometry.h"
      25             : #include "AliRawReader.h"
      26             : #include "AliCaloRawStreamV3.h"
      27             : #include "AliDAQ.h"
      28             : 
      29             : #include "TH1I.h"
      30             : #include "TH2I.h"
      31             : 
      32             : #include <iostream>
      33             : using namespace std;
      34             : 
      35          22 : ClassImp(AliPHOSTriggerRawDigiProducer)
      36             : 
      37             : AliPHOSTriggerRawDigiProducer::AliPHOSTriggerRawDigiProducer()
      38           0 :   :fModules(kNMods, false),
      39           0 :    fSaturationThreshold(950),
      40           0 :    fParameters(0),
      41           0 :    fRawReader(0),
      42           0 :    fRawStream(0),
      43           0 :    fTriggerReader(0)
      44           0 : {}
      45             : 
      46             : AliPHOSTriggerRawDigiProducer::AliPHOSTriggerRawDigiProducer(AliRawReader *rawReader)
      47           4 :   :fModules(kNMods, false),
      48           4 :    fSaturationThreshold(950),
      49           4 :    fParameters(0),
      50           4 :    fRawReader(rawReader),
      51           4 :    fRawStream(0),
      52          12 :    fTriggerReader(new AliPHOSTriggerRawReader)
      53          16 : {
      54           4 :   SetAnalyseModule(1);
      55           4 :   SetAnalyseModule(2);
      56           4 :   SetAnalyseModule(3);
      57           4 :   SetAnalyseModule(4);
      58             : 
      59          16 :   fRawStream = new AliCaloRawStreamV3(rawReader,"PHOS");
      60             :   // Select only data in ALTRO format and skip STU, the last PHOS DDL
      61           8 :   rawReader->Select("PHOS",0,AliDAQ::NumberOfDdls("PHOS")-2);
      62           8 : }
      63             : 
      64             : AliPHOSTriggerRawDigiProducer::~AliPHOSTriggerRawDigiProducer()
      65          16 : {
      66           8 :   delete fRawStream;
      67           8 :   delete fTriggerReader;
      68           8 : }
      69             : 
      70             : void AliPHOSTriggerRawDigiProducer::ProcessEvent(TClonesArray* tdigits)
      71             : {
      72           8 :   ProcessL0(tdigits);
      73           4 :   ProcessL1(tdigits);
      74           4 : }
      75             : 
      76             : void AliPHOSTriggerRawDigiProducer::ProcessL1(TClonesArray* tdigits)
      77             : {
      78           8 :   AliPHOSTriggerSTURawStream inPHOSSTU(fRawReader);
      79           4 :   Int_t iDigit = tdigits->GetEntries();
      80             :   
      81           4 :   fRawReader->Reset();
      82           4 :   fRawReader->Select("PHOS", 20,20);
      83             : 
      84           8 :   if(inPHOSSTU.ReadPayLoad()){
      85             :     
      86           0 :     for(Int_t iG = 0; iG<3; iG++) {// loop over trigger thresholds: high(0), medium(1), low(2).
      87           0 :       for(Int_t ith=0; ith<inPHOSSTU.GetNL1GammaPatch(iG); ith++){
      88             : 
      89           0 :         Int_t itru, ieta, iphi;
      90           0 :         inPHOSSTU.GetL1GammaPatch(ith,iG,itru,ieta,iphi);
      91             :         
      92           0 :         Int_t x=-1, y=-1;
      93           0 :         GetGammaPatchXY(itru,ieta,iphi,x,y);
      94             :         
      95           0 :         Int_t module,xloc,zloc;
      96           0 :         GetL1GammaPatchModuleXZ(itru,x,y,module,xloc,zloc);
      97             : 
      98           0 :         new((*tdigits)[iDigit]) AliPHOSTriggerRawDigit(module,xloc,zloc,iG,-1);
      99           0 :         iDigit++;
     100           0 :       }
     101             :     }
     102           0 :   }//if(inPHOSSTU.ReadPayLoad())
     103             :   
     104           4 : }
     105             : 
     106             : void AliPHOSTriggerRawDigiProducer::GetGammaPatchXY(Int_t itru, Int_t ieta, Int_t iphi, Int_t& x, Int_t& y)
     107             : {
     108           0 :   x =   ieta/*xpos in TRU*/ + (int)(itru%2) * 14/*xoff in Det*/ ;
     109           0 :   y =   iphi/*ypos in TRU*/ + (int)(itru/2) * 8 /*yoff in Det*/ ;
     110           0 : }
     111             : 
     112             : void AliPHOSTriggerRawDigiProducer::GetL1GammaPatchModuleXZ(Int_t itru, Int_t xglob, Int_t yglob, Int_t& module, Int_t& x, Int_t& z)
     113             : {
     114             :   //convert L1 gamma patch (xglob,yglob) in Detector Global system to local module (x,z).
     115             :   //Module numeration follows the "offline" agreement.
     116             :   
     117             :   // 0 <= xglob <= 27, 0 <= yglob <= 111.
     118             :   
     119           0 :   if(0<=itru && itru<4) module=1;
     120           0 :   if(4<=itru && itru<12 ) module=2;
     121           0 :   if(12<=itru && itru<20 ) module=3;
     122           0 :   if(20<=itru && itru<28 ) module=4;
     123             :   
     124           0 :   z = 56-2*(xglob+1);
     125             : 
     126             :   Int_t offset;
     127           0 :   Int_t mod = module; // online numeration
     128             :   
     129           0 :   if(mod==1) offset= -16;
     130           0 :   if(mod==2) offset = 16;
     131           0 :   if(mod==3) offset = 16+32;
     132           0 :   if(mod==4) offset = 16+32+32;
     133             :   
     134           0 :   x = (yglob - offset)*2; 
     135           0 : }
     136             : 
     137             : void AliPHOSTriggerRawDigiProducer::ProcessL0(TClonesArray* tdigits)
     138             : {
     139             :   
     140           8 :   fTriggerReader->Reset();
     141             : 
     142           4 :   tdigits->Clear();
     143             :   Int_t iDigit=0 ;
     144             : 
     145          35 :   while (fRawStream->NextDDL()) {
     146             :     // Skip STU DDL
     147          27 :     if (fRawStream->GetDDLNumber() == fgkSTUDDL) continue; 
     148         210 :     while (fRawStream->NextChannel()) {
     149         183 :       if (fRawStream->IsTRUData()) {
     150           0 :         fTriggerReader->ReadFromStream(fRawStream);
     151           0 :       }// IsTRUData
     152             :     }// NextChannel
     153             :   }//NextDDL
     154             :         
     155             :   // Loop over modules
     156          48 :   for(unsigned int mod = 0; mod < fModules.size(); ++mod) {
     157          20 :     if( fModules[mod] ) {
     158             :       
     159             :       // Loop over 4x4 cells
     160         160 :       for(int TRURow = 0; TRURow < kNTRURows; ++TRURow) {
     161         384 :         for(int branch = 0; branch < kNBranches; ++branch) {
     162             :           
     163         128 :           AliPHOSTRURawReader* truReader = fTriggerReader->GetTRU(mod, TRURow, branch);
     164         128 :           if( truReader->IsActive() ) {
     165             :             
     166           0 :             for(int xIdx = 0; xIdx < kN4x4XPrTRURow; ++xIdx) {
     167           0 :               for(int zIdx = 0; zIdx < kN4x4ZPrBranch; ++zIdx) {
     168             :               
     169             :                 // Determin if Trigger is flagged for any timeBin
     170             :                 bool triggered = false;
     171             : 
     172           0 :                 for(int timeBin = 0; timeBin < kNTRUTimeBins; ++timeBin){
     173           0 :                   if(truReader->IsActive(timeBin)) {
     174           0 :                     if( fTriggerReader->GetTRU(mod, TRURow, branch)->GetTriggerFlag(xIdx, zIdx, timeBin) ){
     175             :                       triggered = true;
     176           0 :                     } // end "if TriggerBit"
     177             :                   }
     178             :                 }// end TimeBin loop
     179             :                 
     180           0 :                 if( triggered ){
     181             :                   // Get peak values
     182           0 :                   const int TSmax = Get4x4Max(fTriggerReader, fParameters, mod, TRURow, branch, xIdx, zIdx);
     183           0 :                   new((*tdigits)[iDigit]) AliPHOSTriggerRawDigit(mod,xIdx,zIdx,TRURow,branch,TSmax);
     184           0 :                   iDigit++;
     185           0 :                 }// end  "if triggered"
     186             :               
     187             :               } // end zIdx loop
     188             :             } // end xIdx loop
     189           0 :           } // truReader->IsActive
     190             :         } // end branch loop
     191             :       } // end tru loop
     192          16 :     } // end "if module"
     193             :   } // end mod loop
     194             :   
     195           4 : }
     196             : 
     197             : int AliPHOSTriggerRawDigiProducer::Get2x2Max(AliPHOSTriggerRawReader* reader, AliPHOSTriggerParameters* params, int mod, int xIdx, int zIdx)
     198             : {
     199             :   int max = 0;
     200           0 :   for(int timeBin = 0; timeBin < kNTRUTimeBins; ++timeBin) {
     201           0 :     const int signal = Get2x2Signal(reader, params, mod, xIdx, zIdx, timeBin);
     202           0 :     if( max < signal ){
     203             :       max = signal;
     204           0 :     }
     205             :   }
     206           0 :   return max;
     207             : }
     208             : 
     209             : 
     210             : int AliPHOSTriggerRawDigiProducer::Get2x2Signal(AliPHOSTriggerRawReader* reader, AliPHOSTriggerParameters* parameters, int mod, int xIdx, int zIdx, int timeBin)
     211             : {
     212           0 :   const int TRURow = xIdx / kN2x2XPrTRURow;
     213           0 :   const int branch = zIdx / kN2x2ZPrBranch;
     214           0 :   const int TRUX = xIdx % kN2x2XPrTRURow; // 2x2 coordinates
     215           0 :   const int TRUZ = zIdx % kN2x2ZPrBranch; // 2x2 coordinates
     216             : 
     217           0 :   if( reader->GetTRU(mod, TRURow, branch)->IsActive() ){
     218           0 :     const int signal = reader->GetTRU(mod, TRURow, branch)->GetTriggerSignal( TRUX, TRUZ, timeBin);
     219           0 :     if( parameters )
     220           0 :       return signal - parameters->GetTRUPedestal(mod, TRURow, branch, TRUX, TRUZ);
     221             :     else
     222           0 :       return signal - AliPHOSTRURawReader::GetDefaultSignalValue();
     223             :   }
     224             :   else
     225           0 :     return 0;
     226           0 : }
     227             : 
     228             : int AliPHOSTriggerRawDigiProducer::Get4x4Max(AliPHOSTriggerRawReader* reader, AliPHOSTriggerParameters* params, int mod, int TRURow, int branch, int xIdx, int zIdx)
     229             : {
     230             :   int max = 0;
     231           0 :   for(int timeBin = 0; timeBin < kNTRUTimeBins; ++timeBin) {
     232           0 :     const int signal = Get4x4Signal(reader, params, mod, TRURow, branch, xIdx, zIdx, timeBin);
     233           0 :     if( max < signal ){
     234             :       max = signal;
     235           0 :     }
     236             :   }
     237           0 :   return max;
     238             : }
     239             : 
     240             : 
     241             : int AliPHOSTriggerRawDigiProducer::Get4x4Signal(AliPHOSTriggerRawReader* reader, AliPHOSTriggerParameters* params, int mod, int TRURow, int branch, int xIdx, int zIdx, int timeBin)
     242             : {
     243           0 :   const int modX = xIdx + TRURow * kN2x2XPrTRURow;
     244           0 :   const int modZ = zIdx + branch * kN2x2ZPrBranch;
     245             : 
     246             :   const int signal
     247           0 :     = Get2x2Signal(reader, params, mod, modX  , modZ  , timeBin)
     248           0 :       + Get2x2Signal(reader, params, mod, modX+1, modZ  , timeBin)
     249           0 :       + Get2x2Signal(reader, params, mod, modX  , modZ+1, timeBin)
     250           0 :       + Get2x2Signal(reader, params, mod, modX+1, modZ+1, timeBin);
     251           0 :   return signal;
     252             : }
     253             : 
     254             : bool AliPHOSTriggerRawDigiProducer::Is2x2Active(AliPHOSTriggerRawReader* reader, int mod, int xIdx, int zIdx)
     255             : {
     256           0 :   const int TRURow = xIdx / kN2x2XPrTRURow;
     257           0 :   const int branch = zIdx / kN2x2ZPrBranch;
     258             : 
     259           0 :   return reader->GetTRU(mod, TRURow, branch)->IsActive();
     260             : }
     261             : 
     262             : bool AliPHOSTriggerRawDigiProducer::Is2x2Active(AliPHOSTriggerRawReader* reader, int mod, int xIdx, int zIdx, int timeBin)
     263             : {
     264           0 :   const int TRURow = xIdx / kN2x2XPrTRURow;
     265           0 :   const int branch = zIdx / kN2x2ZPrBranch;
     266             : 
     267           0 :   return reader->GetTRU(mod, TRURow, branch)->IsActive(timeBin);
     268             : }
     269             : 
     270             : 

Generated by: LCOV version 1.11