Fixing warnings
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALTriggerElectronics.cxx
CommitLineData
916f1e76 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
16/*
17
18
19EMCal trigger electronics manager L0/L1
20can handle both simulated digits and raw data
21Author: R. GUERNANE LPSC Grenoble CNRS/IN2P3
22*/
23
24#include "AliEMCALTriggerElectronics.h"
25#include "AliEMCALTriggerTRU.h"
26#include "AliEMCALTriggerSTU.h"
27#include "AliEMCALGeometry.h"
28#include "AliRunLoader.h"
29#include "AliEMCAL.h"
30#include "AliRun.h"
fff39dd1 31#include "AliEMCALTriggerDCSConfig.h"
916f1e76 32#include "AliEMCALTriggerData.h"
33#include "AliEMCALDigit.h"
34#include "AliCaloRawStreamV3.h"
916f1e76 35#include "AliEMCALTriggerSTURawStream.h"
36#include "AliEMCALDigit.h"
37#include "AliEMCALRawDigit.h"
38
39#include <TVector2.h>
40#include <TClonesArray.h>
916f1e76 41
42namespace
43{
44 const Int_t kNTRU = 32;
45}
46
47ClassImp(AliEMCALTriggerElectronics)
48
49//__________________
fff39dd1 50AliEMCALTriggerElectronics::AliEMCALTriggerElectronics(const AliEMCALTriggerDCSConfig *dcsConf) : TObject(),
916f1e76 51fTRU(new TClonesArray("AliEMCALTriggerTRU",32)),
52fSTU(0x0)
53{
54 TVector2 rSize;
55
56 rSize.Set( 24., 4. );
57
58 // 32 TRUs
fff39dd1 59 for (Int_t i=0;i<kNTRU;i++)
60 {
61 AliEMCALTriggerTRUDCSConfig* truConf = dcsConf->GetTRUDCSConfig(i);
62 new ((*fTRU)[i]) AliEMCALTriggerTRU(truConf, rSize, int(i/3) % 2);
63 }
64
916f1e76 65 rSize.Set( 48., 64. );
66
67 // 1 STU
fff39dd1 68 AliEMCALTriggerSTUDCSConfig* stuConf = dcsConf->GetSTUDCSConfig();
69 fSTU = new AliEMCALTriggerSTU(stuConf, rSize);
916f1e76 70
71 for (Int_t i=0;i<kNTRU;i++) fSTU->BuildMap( i,
72 (static_cast<AliEMCALTriggerTRU*>(fTRU->At(i)))->Map(),
73 (static_cast<AliEMCALTriggerTRU*>(fTRU->At(i)))->RegionSize()
74 );
75}
76
77//________________
78AliEMCALTriggerElectronics::~AliEMCALTriggerElectronics()
79{
80 //
81 fTRU->Delete();
82 delete fSTU;
83}
84
85//__________________
fff39dd1 86void AliEMCALTriggerElectronics::Digits2Trigger(const TClonesArray* digits, const Int_t V0M[], AliEMCALTriggerData* data)
916f1e76 87{
88 //
89 AliEMCALGeometry* geom = 0x0;
90
91 AliRunLoader *rl = AliRunLoader::Instance();
92 if (rl->GetAliRun() && rl->GetAliRun()->GetDetector("EMCAL"))
93 geom = dynamic_cast<AliEMCAL*>(rl->GetAliRun()->GetDetector("EMCAL"))->GetGeometry();
94 else
95 geom = AliEMCALGeometry::GetInstance(AliEMCALGeometry::GetDefaultGeometryName());
96
97 if (!geom) AliError("Cannot access geometry!");
98
99 TIter NextDigit(digits);
100 while (AliEMCALRawDigit* digit = (AliEMCALRawDigit*)NextDigit())
101 {
102 if ( digit )
103 {
104 Int_t id = digit->GetId();
105
106// digit->Print();
107
108 Int_t iTRU, iADC;
109 Bool_t isOK1 = geom->GetTRUFromAbsFastORIndex(id, iTRU, iADC);
110
111 for (Int_t i = 0; i < digit->GetNSamples(); i++)
112 {
113 Int_t time, amp;
114 Bool_t isOK2 = digit->GetTimeSample(i, time, amp);
115
116 if (isOK1 && isOK2 && amp) (static_cast<AliEMCALTriggerTRU*>(fTRU->At(iTRU)))->SetADC(iADC, time, amp);
117 }
118 }
119 }
120 /*
121 for (Int_t i=0; i<kNTRU; i++)
122 {
123 printf("===========< TRU %2d >============\n",i);
124 (static_cast<AliEMCALTriggerTRU*>(fTRU->At(i)))->Scan();
125 }
126 */
127 Int_t iL0 = 0;
128
129 // At this point all FastOR are available for digitization
130 // digitization is done in the TRU and produces time samples
131 // Now run the trigger algo & consecutively write trigger outputs in TreeD dedicated branch
132
133 for (Int_t i=0; i<kNTRU; i++)
134 {
135 AliDebug(1,Form("===========< TRU %2d >============\n",i));
136
137 AliEMCALTriggerTRU *iTRU = static_cast<AliEMCALTriggerTRU*>(fTRU->At(i));
138
fff39dd1 139 iL0 += iTRU->L0();
916f1e76 140
fff39dd1 141// Int_t vL0Peaks[96][2]; iTRU->Peaks( vL0Peaks );
916f1e76 142
143 data->SetL0Patches( i , iTRU->Patches() );
fff39dd1 144// data->SetL0Peaks( i , vL0Peaks );
916f1e76 145
146 if ( !i ) // do it once since identical for all TRU
147 {
148 data->SetL0RegionSize( *iTRU->RegionSize() );
149 data->SetL0SubRegionSize( *iTRU->SubRegionSize() );
150 data->SetL0PatchSize( *iTRU->PatchSize() );
151 }
152
153 // if ( i == 31 ) i = 35;
154 //
155 // if ( ( i / 3 ) % 2 ) {
156 // TRU->Print( 15 - 2 + ( i - int( i / 3 ) * 3 ) - 3 * ( (i / 3) / 2 ) , runLoader->GetEventNumber() );
157 // printf("print data of TRU: from %2d to %2d\n",i,15 - 2 + ( i - int( i / 3 ) * 3 ) - 3 * ( (i / 3) / 2));
158 // }
159 // else
160 // {
161 // TRU->Print( 31 - i % 3 - 3 * ( (i / 3) / 2 ) , runLoader->GetEventNumber() );
162 // printf("print data of TRU: from %2d to %2d\n",i,31 - i % 3 - 3 * ( (i / 3) / 2 ));
163 // }
164 }
165
166 // A L0 has been issued, run L1
167 if ( iL0 )
168 {
169 for (Int_t i=0; i<kNTRU; i++) fSTU->FetchFOR( i,
170 (static_cast<AliEMCALTriggerTRU*>(fTRU->At(i)))->Region(),
171 (static_cast<AliEMCALTriggerTRU*>(fTRU->At(i)))->RegionSize()
172 );
916f1e76 173
fff39dd1 174 fSTU->SetV0Multiplicity( V0M , 2 ); // C/A
916f1e76 175
176 TVector2 size;
177
178 size.Set( 1. , 1. );
179 fSTU->SetSubRegionSize( size ); data->SetL1GammaSubRegionSize( size );
180
181 size.Set( 2. , 2. );
182 fSTU->SetPatchSize( size ); data->SetL1GammaPatchSize( size );
183
184 fSTU->L1( kGamma );
185
186 data->SetL1GammaPatches( fSTU->Patches() );
187
188 fSTU->Reset();
189
190 size.Set( 4. , 4. );
191 fSTU->SetSubRegionSize( size ); data->SetL1JetSubRegionSize( size );
192
193 size.Set( 2. , 2. );
194 fSTU->SetPatchSize( size ); data->SetL1JetPatchSize( size );
195
196 fSTU->L1( kJet );
197
198 data->SetL1JetPatches( fSTU->Patches() );
199 data->SetL1RegionSize( *fSTU->RegionSize() );
200
201 Int_t** region = fSTU->Region();
202 data->SetL1Region( region );
203 const Int_t* mv0 = fSTU->V0();
204 data->SetL1V0( mv0 );
205 }
206
39c05eac 207 if ( AliDebugLevel() ) data->Scan();
208
916f1e76 209 // Now reset the electronics for a fresh start with next event
210 Reset();
211}
212
213//__________________
214void AliEMCALTriggerElectronics::Reset()
215{
216 //
217 TIter NextTRU(fTRU);
218 while ( AliEMCALTriggerTRU *TRU = (AliEMCALTriggerTRU*)NextTRU() ) TRU->Reset();
219
220 fSTU->Reset();
221}