]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG4/CaloCalib/AliAnalysisTaskEMCALFastOR2Trigger.cxx
clusterize on fastor level. Still needs work on coding convention. Code should be...
[u/mrichter/AliRoot.git] / PWG4 / CaloCalib / AliAnalysisTaskEMCALFastOR2Trigger.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
16 /* $Id$ */
17
18 /* AliAnalysisTaskEMCALFastOR2Trigger.cxx
19  *
20  */
21
22 #include "AliAnalysisTaskEMCALFastOR2Trigger.h"
23
24 #include <Riostream.h>
25 #include <TChain.h>
26 #include <TTree.h>
27 #include <TFile.h>
28 #include <TList.h>
29
30 #include "AliAnalysisTaskSE.h"
31 #include "AliAnalysisManager.h"
32 #include "AliStack.h"
33 #include "AliESDEvent.h"
34 #include "AliESDInputHandler.h"
35 #include "AliAODEvent.h"
36 #include "AliMCEvent.h"
37 #include "AliEMCALGeometry.h"
38 #include "AliCaloCalibPedestal.h"
39
40 #include "AliEMCALFastORPatch.h"
41
42 ClassImp(AliAnalysisTaskEMCALFastOR2Trigger)
43
44 //________________________________________________________________________
45 AliAnalysisTaskEMCALFastOR2Trigger::AliAnalysisTaskEMCALFastOR2Trigger() // All data members should be initialised here
46 :AliAnalysisTaskSE(),
47 fMinL0Time(7),
48 fMaxL0Time(9),
49 fTimeCutOn(1),
50 fTriggerClustersName("triggerClusters"),
51 fPedestal(0),
52 fCheckDeadClusters(0),
53 nRow(2),
54 nCol(2),
55 shiftRow(1),
56 shiftCol(1) // The last in the above list should not have a comma after it
57 {
58   // Dummy constructor ALWAYS needed for I/O.
59 }
60
61 //________________________________________________________________________
62 AliAnalysisTaskEMCALFastOR2Trigger::AliAnalysisTaskEMCALFastOR2Trigger(const char *name) // All data members should be initialised here
63 :AliAnalysisTaskSE(name),
64 fMinL0Time(7),
65 fMaxL0Time(9),
66 fTimeCutOn(1),
67 fTriggerClustersName("triggerClusters"),
68 fPedestal(0),
69 fCheckDeadClusters(0),
70 nRow(2),
71 nCol(2),
72 shiftRow(1),
73 shiftCol(1) // The last in the above list should not have a comma after it
74 {
75   // Constructor
76
77 }
78
79 //________________________________________________________________________
80 AliAnalysisTaskEMCALFastOR2Trigger::~AliAnalysisTaskEMCALFastOR2Trigger()
81 {
82   // Destructor. 
83 }
84
85 //________________________________________________________________________
86 void AliAnalysisTaskEMCALFastOR2Trigger::UserCreateOutputObjects()
87 {
88   // Called once (on the worker node)
89 }
90
91 //________________________________________________________________________
92 void AliAnalysisTaskEMCALFastOR2Trigger::UserExec(Option_t *) 
93 {
94   // Main loop
95   // Called for each event
96         
97   // Create pointer to reconstructed event
98   AliVEvent *event = InputEvent();
99   if (!event) { Printf("ERROR: Could not retrieve event"); return; }
100     
101   // create pointer to event
102   AliESDEvent* esd = dynamic_cast<AliESDEvent*>(event);
103   if (!esd) 
104         {
105     AliError("Cannot get the ESD event");
106     return;
107   }  
108   
109   AliESDCaloTrigger *triggers = esd->GetCaloTrigger("EMCAL");
110   
111   if (!triggers || !(triggers->GetEntries() > 0))
112     return;
113   
114   AliEMCALGeometry *fGeom = AliEMCALGeometry::GetInstance(AliEMCALGeometry::GetDefaultGeometryName());
115         Int_t nSupMod = 0, nModule = 0, nIphi = 0, nIeta = 0, iphi = 0, ieta = 0;
116           
117   // -------------------------------
118   // Trigger clusterizer parameters
119   
120   Int_t totalCols = 48;
121   Int_t totalRows = 60;
122   Int_t nTRURow = 15;
123   Int_t nTRUCol = 2;
124   Int_t nColFastOR = totalCols / nTRUCol;
125   Int_t nRowFastOR = totalRows / nTRURow;
126   Int_t maxiShiftRow = nRow / shiftRow;
127   Int_t maxiShiftCol = nCol / shiftCol;
128   Int_t nFastORCluster = nCol * nRow;
129   Int_t nTriggerClusters = totalRows * totalCols / nCol / nRow;
130   Int_t nTotalClus = nTriggerClusters * maxiShiftCol * maxiShiftRow;
131   Int_t nClusRowNoShift = nRowFastOR / nRow;
132   Int_t nClusColNoShift = nColFastOR / nCol; 
133   
134   TClonesArray *triggers_array = dynamic_cast<TClonesArray*>(InputEvent()->FindListObject(fTriggerClustersName));
135   if(!triggers_array)
136   {
137     triggers_array = new TClonesArray("AliESDCaloTrigger", nTotalClus);
138     triggers_array->SetName(fTriggerClustersName);
139     InputEvent()->AddObject(triggers_array);
140   }
141   else 
142   {
143     triggers_array->Delete();
144   }
145   
146   Bool_t *dead_clusters = new Bool_t[nTotalClus];
147   for (Int_t i = 0; i < nTotalClus; i++)
148   {
149     dead_clusters[i] = kFALSE;
150   }
151   // -------------------------------
152   
153   triggers->Reset();
154   
155   while (triggers->Next()) 
156   {
157     Float_t L0FastORamp = 0;
158     
159     triggers->GetAmplitude(L0FastORamp);
160     
161     if (L0FastORamp < 0)
162       continue;
163     
164     if (fTimeCutOn)
165     {
166     
167       Int_t ntimes = 0;
168       triggers->GetNL0Times(ntimes);
169     
170       if (ntimes < 1)
171         continue;
172
173       Int_t trgtimes[25];
174       triggers->GetL0Times(trgtimes);
175       
176       Bool_t trgInTimeWindow = 0;
177       for (Int_t i = 0; i < ntimes; i++) 
178       {
179         if ((fMaxL0Time >= trgtimes[i]) && (fMinL0Time <= trgtimes[i]))
180           trgInTimeWindow = 1;
181       }
182
183       if (!trgInTimeWindow)
184         continue;
185     }
186
187     Int_t gCol = 0, gRow = 0;
188     
189     triggers->GetPosition(gCol, gRow);
190     
191     Int_t find = -1;
192     fGeom->GetAbsFastORIndexFromPositionInEMCAL(gCol, gRow, find);
193     
194     if (find<0)
195       continue;
196     
197     Int_t cidx[4] = {-1};
198     Bool_t ret = fGeom->GetCellIndexFromFastORIndex(find, cidx);
199     
200     if (!ret)
201       continue;
202     
203     Bool_t deadCluster = kFALSE;
204     
205     if (fCheckDeadClusters && fPedestal)
206     {
207       for (Int_t i = 0; i < 4; i++)
208       {
209         fGeom->GetCellIndex (cidx[i], nSupMod, nModule, nIphi, nIeta);
210         fGeom->GetCellPhiEtaIndexInSModule (nSupMod, nModule, nIphi, nIeta, iphi, ieta);
211         
212         Double_t d = fPedestal->GetDeadMap(nSupMod)->GetBinContent(ieta,iphi);
213         if (d == AliCaloCalibPedestal::kDead || d == AliCaloCalibPedestal::kHot)
214         {
215           deadCluster = kTRUE;
216         }
217       }
218     }
219     
220     // --------------------------
221     // Trigger clusterizer
222     
223     for (Int_t ishiftRow = 0; ishiftRow < maxiShiftRow; ishiftRow++)
224     {
225       Int_t nClusRow = (nRowFastOR - shiftRow * ishiftRow) / nRow;
226       
227       for (Int_t ishiftCol = 0; ishiftCol < maxiShiftCol; ishiftCol++)
228       {
229         Int_t iTotalClus = nTriggerClusters * (ishiftRow * maxiShiftCol + ishiftCol);
230
231         Int_t nClusCol = (nColFastOR - shiftCol * ishiftCol) / nCol; 
232         
233         Int_t irow_eff = gRow - shiftRow * ishiftRow; 
234         Int_t iTRUrow = irow_eff / nRowFastOR;
235         irow_eff -= iTRUrow * nRowFastOR;
236         Int_t iClusRow = irow_eff / nRow; 
237         
238         if (irow_eff < 0 || iClusRow >= nClusRow) 
239           continue;
240         
241         Int_t icol_eff = gCol - shiftCol * ishiftCol;
242         Int_t iTRUcol = icol_eff / nColFastOR;
243         icol_eff -= iTRUcol * nColFastOR;
244         Int_t iClusCol = icol_eff / nCol; 
245         
246         if (icol_eff < 0 || iClusCol >= nClusCol) 
247           continue;
248
249         irow_eff += iTRUrow * nRowFastOR;
250         iClusRow = irow_eff / nRow; 
251         
252         icol_eff += iTRUcol * nColFastOR;
253         iClusCol = icol_eff / nCol; 
254         
255         Int_t iTriggerCluster = iClusRow + iClusCol * nClusRowNoShift * nTRURow + iTotalClus;
256         Int_t iTriggerDigit = irow_eff % nRow + (icol_eff % nCol) * nRow;
257         
258         if (dead_clusters[iTriggerCluster] && fCheckDeadClusters) deadCluster = kTRUE;
259         
260         if (deadCluster)
261         {
262           dead_clusters[iTriggerCluster] = kTRUE;
263           if (triggers_array->At(iTriggerCluster))
264           {
265             triggers_array->RemoveAt(iTriggerCluster);
266           }
267           continue;
268         }
269         
270         if (!triggers_array->At(iTriggerCluster))
271         {
272           (*triggers_array)[iTriggerCluster] = new AliEMCALFastORPatch(iTriggerCluster, nFastORCluster);
273         }
274         
275         AliEMCALFastORPatch *triggerCluster = dynamic_cast<AliEMCALFastORPatch*>(triggers_array->At(iTriggerCluster));
276         
277         if (triggerCluster->GetFastORamplitude(iTriggerDigit) > -1)
278         {
279           AliFatal("ERROR: FastOR already added!");
280           return;
281         }
282         
283         triggerCluster->AddFastORat(L0FastORamp, gCol, gRow, iTriggerDigit);
284         
285       } // loop on col shift
286       
287     } // loop on row shift
288
289     // ------------------------------
290   } // loop on L0 FastOR triggers
291     
292   delete[] dead_clusters;
293   
294   triggers_array->Compress();
295 }
296
297
298 //________________________________________________________________________
299 void AliAnalysisTaskEMCALFastOR2Trigger::Terminate(Option_t *) 
300 {
301   // Called once at the end of the query
302   
303         
304 }