]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PHOS/AliPHOSTriggerRawDigiProducer.cxx
Added functionality in AliPHOSTRURawReader to test if data 'Has Signal'
[u/mrichter/AliRoot.git] / PHOS / AliPHOSTriggerRawDigiProducer.cxx
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 "AliPHOSTriggerParameters.h"
22 #include "AliPHOSTriggerRawDigit.h"
23 #include "AliPHOSGeometry.h"
24 #include "AliRawReader.h"
25 #include "AliCaloRawStreamV3.h"
26
27 #include "TH1I.h"
28 #include "TH2I.h"
29
30 #include <iostream>
31 using namespace std;
32
33 ClassImp(AliPHOSTriggerRawDigiProducer)
34
35 AliPHOSTriggerRawDigiProducer::AliPHOSTriggerRawDigiProducer()
36   :fModules(kNMods, false),
37    fSaturationThreshold(950),
38    fParameters(0),
39    fRawReader(0),
40    fRawStream(0),
41    fTriggerReader(0)
42 {}
43
44 AliPHOSTriggerRawDigiProducer::AliPHOSTriggerRawDigiProducer(AliRawReader *rawReader)
45   :fModules(kNMods, false),
46    fSaturationThreshold(950),
47    fParameters(0),
48    fRawReader(rawReader),
49    fRawStream(0),
50    fTriggerReader(new AliPHOSTriggerRawReader)
51 {
52   SetAnalyseModule(2);
53   SetAnalyseModule(3);
54   SetAnalyseModule(4);
55
56   fRawStream = new AliCaloRawStreamV3(rawReader,"PHOS");
57 }
58
59 AliPHOSTriggerRawDigiProducer::~AliPHOSTriggerRawDigiProducer()
60 {
61   delete fRawStream;
62   delete fTriggerReader;
63 }
64
65 void AliPHOSTriggerRawDigiProducer::ProcessEvent(TClonesArray* tdigits)
66 {
67   
68   fTriggerReader->Reset();
69
70   tdigits->Clear();
71   Int_t iDigit=0 ;
72
73   while (fRawStream->NextDDL()) {
74     while (fRawStream->NextChannel()) {
75
76       if (fRawStream->IsTRUData()) {
77         fTriggerReader->ReadFromStream(fRawStream);
78       }// IsTRUData
79     }// NextChannel
80   }//NextDDL
81         
82   // Loop over modules
83   for(unsigned int mod = 0; mod < fModules.size(); ++mod) {
84     if( fModules[mod] ) {
85       
86       // Loop over 4x4 cells
87       for(int TRURow = 0; TRURow < kNTRURows; ++TRURow) {
88         for(int branch = 0; branch < kNBranches; ++branch) {
89           
90           AliPHOSTRURawReader* truReader = fTriggerReader->GetTRU(mod, TRURow, branch);
91           if( truReader->IsActive() ) {
92             
93             for(int xIdx = 0; xIdx < kN4x4XPrTRURow; ++xIdx) {
94               for(int zIdx = 0; zIdx < kN4x4ZPrBranch; ++zIdx) {
95               
96                 // Determin if Trigger is flagged for any timeBin
97                 bool triggered = false;
98
99                 for(int timeBin = 0; timeBin < kNTRUTimeBins; ++timeBin){
100                   if(truReader->IsActive(timeBin)) {
101                     if( fTriggerReader->GetTRU(mod, TRURow, branch)->GetTriggerFlag(xIdx, zIdx, timeBin) ){
102                       triggered = true;
103                     } // end "if TriggerBit"
104                   }
105                 }// end TimeBin loop
106                 
107                 if( triggered && truReader->HasSignal() ){
108                   // Get peak values
109                   const int TSmax = Get4x4Max(fTriggerReader, fParameters, mod, TRURow, branch, xIdx, zIdx);
110                   new((*tdigits)[iDigit]) AliPHOSTriggerRawDigit(mod,xIdx,zIdx,TRURow,branch,TSmax); 
111                   iDigit++;
112                 }// end  "if triggered"
113               
114               } // end zIdx loop
115             } // end xIdx loop
116           } // truReader->IsActive
117         } // end branch loop
118       } // end tru loop
119     } // end "if module"
120   } // end mod loop
121   
122 }
123
124 int AliPHOSTriggerRawDigiProducer::Get2x2Max(AliPHOSTriggerRawReader* reader, AliPHOSTriggerParameters* params, int mod, int xIdx, int zIdx)
125 {
126   int max = 0;
127   for(int timeBin = 0; timeBin < kNTRUTimeBins; ++timeBin) {
128     const int signal = Get2x2Signal(reader, params, mod, xIdx, zIdx, timeBin);
129     if( max < signal ){
130       max = signal;
131     }
132   }
133   return max;
134 }
135
136
137 int AliPHOSTriggerRawDigiProducer::Get2x2Signal(AliPHOSTriggerRawReader* reader, AliPHOSTriggerParameters* parameters, int mod, int xIdx, int zIdx, int timeBin)
138 {
139   const int TRURow = xIdx / kN2x2XPrTRURow;
140   const int branch = zIdx / kN2x2ZPrBranch;
141   const int TRUX = xIdx % kN2x2XPrTRURow; // 2x2 coordinates
142   const int TRUZ = zIdx % kN2x2ZPrBranch; // 2x2 coordinates
143
144   AliPHOSTRURawReader* truReader = reader->GetTRU(mod, TRURow, branch);
145   if( truReader->IsActive(timeBin) && truReader->HasSignal(timeBin)  ){
146     const int signal = reader->GetTRU(mod, TRURow, branch)->GetTriggerSignal( TRUX, TRUZ, timeBin);
147     if( parameters )
148       return signal - parameters->GetTRUPedestal(mod, TRURow, branch, TRUX, TRUZ);
149     else
150       return signal - AliPHOSTRURawReader::kDefaultSignalValue;
151   }
152   else
153     return 0;
154 }
155
156 int AliPHOSTriggerRawDigiProducer::Get4x4Max(AliPHOSTriggerRawReader* reader, AliPHOSTriggerParameters* params, int mod, int TRURow, int branch, int xIdx, int zIdx)
157 {
158   int max = 0;
159   for(int timeBin = 0; timeBin < kNTRUTimeBins; ++timeBin) {
160     const int signal = Get4x4Signal(reader, params, mod, TRURow, branch, xIdx, zIdx, timeBin);
161     if( max < signal ){
162       max = signal;
163     }
164   }
165   return max;
166 }
167
168
169 int AliPHOSTriggerRawDigiProducer::Get4x4Signal(AliPHOSTriggerRawReader* reader, AliPHOSTriggerParameters* params, int mod, int TRURow, int branch, int xIdx, int zIdx, int timeBin)
170 {
171   const int modX = xIdx + TRURow * kN2x2XPrTRURow;
172   const int modZ = zIdx + branch * kN2x2ZPrBranch;
173
174   const int signal
175     = Get2x2Signal(reader, params, mod, modX  , modZ  , timeBin)
176       + Get2x2Signal(reader, params, mod, modX+1, modZ  , timeBin)
177       + Get2x2Signal(reader, params, mod, modX  , modZ+1, timeBin)
178       + Get2x2Signal(reader, params, mod, modX+1, modZ+1, timeBin);
179   return signal;
180 }
181
182 bool AliPHOSTriggerRawDigiProducer::Is2x2Active(AliPHOSTriggerRawReader* reader, int mod, int xIdx, int zIdx)
183 {
184   const int TRURow = xIdx / kN2x2XPrTRURow;
185   const int branch = zIdx / kN2x2ZPrBranch;
186
187   return reader->GetTRU(mod, TRURow, branch)->IsActive();
188 }
189
190 bool AliPHOSTriggerRawDigiProducer::Is2x2Active(AliPHOSTriggerRawReader* reader, int mod, int xIdx, int zIdx, int timeBin)
191 {
192   const int TRURow = xIdx / kN2x2XPrTRURow;
193   const int branch = zIdx / kN2x2ZPrBranch;
194
195   return reader->GetTRU(mod, TRURow, branch)->IsActive(timeBin);
196 }
197
198