]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONSimpleClusterServer.cxx
Add a protection against division by 0 (which may occur when a track exit from the...
[u/mrichter/AliRoot.git] / MUON / AliMUONSimpleClusterServer.cxx
CommitLineData
d08b5461 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#include "AliMUONSimpleClusterServer.h"
19
9bf6860b 20#include "AliCodeTimer.h"
21#include "AliLog.h"
d08b5461 22#include "AliMUONCluster.h"
9bf6860b 23#include "AliMUONConstants.h"
d08b5461 24#include "AliMUONGeometryTransformer.h"
25#include "AliMUONPad.h"
9bf6860b 26#include "AliMUONTriggerTrackToTrackerClusters.h"
d08b5461 27#include "AliMUONVCluster.h"
28#include "AliMUONVClusterFinder.h"
29#include "AliMUONVClusterStore.h"
30#include "AliMUONVDigitStore.h"
35be7ed7 31#include "AliMUONRecoParam.h"
d08b5461 32#include "AliMpArea.h"
33#include "AliMpDEIterator.h"
34#include "AliMpDEManager.h"
35#include "AliMpExMap.h"
9bf6860b 36#include "AliMpPad.h"
d08b5461 37#include "AliMpSegmentation.h"
38#include "AliMpVSegmentation.h"
d08b5461 39#include <Riostream.h>
40#include <TClonesArray.h>
41#include <TString.h>
9bf6860b 42#include <float.h>
7deb8eb0 43
d08b5461 44/// \class AliMUONSimpleClusterServer
45///
46/// Implementation of AliMUONVClusterServer interface
47///
48///
49/// \author Laurent Aphecetche, Subatech
50
51/// \cond CLASSIMP
52ClassImp(AliMUONSimpleClusterServer)
53/// \endcond
54
55namespace
56{
57 TString AsString(const AliMpArea& area)
58 {
59 return Form("(X,Y)=(%7.3f,%7.3f) (DX,DY)=(%7.3f,%7.3f)",
6e97fbb8 60 area.GetPositionX(),
61 area.GetPositionY(),
62 area.GetDimensionX(), /// TBCL was Y !!!
63 area.GetDimensionY());
d08b5461 64 }
65}
66
67//_____________________________________________________________________________
9bf6860b 68AliMUONSimpleClusterServer::AliMUONSimpleClusterServer(AliMUONVClusterFinder* clusterFinder,
d08b5461 69 const AliMUONGeometryTransformer& transformer)
2e2d0c44 70: AliMUONVClusterServer(),
71 fDigitStore(0x0),
d08b5461 72 fClusterFinder(clusterFinder),
72dae9ff 73 fkTransformer(transformer),
d08b5461 74 fPads(),
9bf6860b 75 fTriggerTrackStore(0x0),
76 fBypass(0x0)
d08b5461 77{
78 /// Ctor
9bf6860b 79 /// Note that we take ownership of the clusterFinder
d08b5461 80
630711ed 81 fPads[0] = new AliMpExMap;
82 fPads[1] = new AliMpExMap;
7deb8eb0 83
d08b5461 84}
85
86//_____________________________________________________________________________
87AliMUONSimpleClusterServer::~AliMUONSimpleClusterServer()
88{
89 /// Dtor
9bf6860b 90 delete fClusterFinder;
d08b5461 91 delete fPads[0];
92 delete fPads[1];
9bf6860b 93 delete fBypass;
d08b5461 94}
95
96//_____________________________________________________________________________
97Int_t
98AliMUONSimpleClusterServer::Clusterize(Int_t chamberId,
99 AliMUONVClusterStore& clusterStore,
35be7ed7 100 const AliMpArea& area,
101 const AliMUONRecoParam* recoParam)
d08b5461 102{
103 /// Area is in absolute coordinate. If not valid, means clusterize all
104 /// the chamber.
105 ///
106 /// We first find out the list of DE that have a non-zero overlap with area,
107 /// and then use the clusterfinder to find clusters in those areas (and DE).
108
99c136e1 109 AliCodeTimerAuto(Form("Chamber %d",chamberId),0);
9bf6860b 110
111 if ( fTriggerTrackStore && chamberId >= 6 )
112 {
113 return fBypass->GenerateClusters(chamberId,clusterStore);
114 }
115
35be7ed7 116 if (!recoParam) {
117 AliError("Reconstruction parameters are missing: unable to clusterize");
118 return 0;
119 }
120
d08b5461 121 AliMpDEIterator it;
122
123 it.First(chamberId);
124
125 Int_t nofAddedClusters(0);
126 Int_t fNCluster = clusterStore.GetSize();
127
128 AliDebug(1,Form("chamberId = %2d NofClusters before = %d searchArea=%s",
129 chamberId,fNCluster,AsString(area).Data()));
130
131 while ( !it.IsDone() )
132 {
133 Int_t detElemId = it.CurrentDEId();
134
135 TClonesArray* pads[2] =
136 {
137 static_cast<TClonesArray*>(fPads[0]->GetValue(detElemId)),
138 static_cast<TClonesArray*>(fPads[1]->GetValue(detElemId))
139 };
140
141 if ( ( pads[0] && pads[0]->GetLast()>=0 ) ||
142 ( pads[1] && pads[1]->GetLast()>=0 ) )
143 {
144 AliMpArea deArea; // area in DE-local-coordinates
145 Bool_t ok(kTRUE);
146
147 if ( area.IsValid() )
148 {
149 ok = Overlap(detElemId,area,deArea);
150 }
151
152 if ( ok )
153 {
2e2d0c44 154 const AliMpVSegmentation* seg[2] =
d08b5461 155 { AliMpSegmentation::Instance()->GetMpSegmentation(detElemId,AliMp::kCath0),
156 AliMpSegmentation::Instance()->GetMpSegmentation(detElemId,AliMp::kCath1)
157 };
110edb51 158
159 fClusterFinder->SetChargeHints(recoParam->LowestPadCharge(),
160 recoParam->LowestClusterCharge());
161
2e2d0c44 162 if ( fClusterFinder->NeedSegmentation() )
163 {
9bf6860b 164 fClusterFinder->Prepare(detElemId,pads,deArea,seg);
d08b5461 165 }
166 else
167 {
9bf6860b 168 fClusterFinder->Prepare(detElemId,pads,deArea);
d08b5461 169 }
170
171 AliDebug(1,Form("Clusterizing DE %04d with %3d pads (cath0) and %3d pads (cath1)",
172 detElemId,
173 (pads[0] ? pads[0]->GetLast()+1 : 0),
174 (pads[1] ? pads[1]->GetLast()+1 : 0)));
175
176 AliMUONCluster* cluster;
177
9bf6860b 178 while ( ( cluster = fClusterFinder->NextCluster() ) )
d08b5461 179 {
180 // add new cluster to the store with information to build its ID
181 // increment the number of clusters into the store
35be7ed7 182 AliMUONVCluster* rawCluster = clusterStore.Add(chamberId, detElemId, fNCluster++);
d08b5461 183
184 ++nofAddedClusters;
185
186 // fill array of Id of digits attached to this cluster
187 Int_t nPad = cluster->Multiplicity();
188 if (nPad < 1) AliWarning("no pad attached to the cluster");
189
190 for (Int_t iPad=0; iPad<nPad; iPad++)
191 {
192 AliMUONPad *pad = cluster->Pad(iPad);
89b4e052 193
194 // skip virtual pads
195 if (!pad->IsReal()) continue;
196
197 rawCluster->AddDigitId(pad->GetUniqueID());
d08b5461 198 }
199
200 // fill charge and other cluster informations
201 rawCluster->SetCharge(cluster->Charge());
89b4e052 202 rawCluster->SetChi2(cluster->Chi2());
d08b5461 203
204 Double_t xg, yg, zg;
72dae9ff 205 fkTransformer.Local2Global(detElemId,
d08b5461 206 cluster->Position().X(), cluster->Position().Y(),
207 0, xg, yg, zg);
208 rawCluster->SetXYZ(xg, yg, zg);
35be7ed7 209 rawCluster->SetErrXY(recoParam->GetDefaultNonBendingReso(chamberId),recoParam->GetDefaultBendingReso(chamberId));
d08b5461 210
91b67b6f 211 // Set MC label
212 if (fDigitStore && fDigitStore->HasMCInformation())
213 {
214 rawCluster->SetMCLabel(FindMCLabel(*cluster, detElemId, seg));
215 }
216
2e2d0c44 217 AliDebug(1,Form("Adding RawCluster detElemId %4d mult %2d charge %e (xl,yl,zl)=(%e,%e,%e) (xg,yg,zg)=(%e,%e,%e) label %d",
89b4e052 218 detElemId,rawCluster->GetNDigits(),rawCluster->GetCharge(),
d08b5461 219 cluster->Position().X(),cluster->Position().Y(),0.0,
2e2d0c44 220 xg,yg,zg,rawCluster->GetMCLabel()));
d08b5461 221 }
222 }
223 }
224 it.Next();
225 }
226
227 AliDebug(1,Form("chamberId = %2d NofClusters after = %d",chamberId,fNCluster));
91b67b6f 228
d08b5461 229 return nofAddedClusters;
230}
231
9bf6860b 232
d08b5461 233//_____________________________________________________________________________
234void
235AliMUONSimpleClusterServer::Global2Local(Int_t detElemId, const AliMpArea& globalArea,
236 AliMpArea& localArea) const
237{
238 /// Convert a global area in local area for a given DE
239
240 Double_t xl,yl,zl;
241
242 Double_t zg = AliMUONConstants::DefaultChamberZ(AliMpDEManager::GetChamberId(detElemId));
243
72dae9ff 244 fkTransformer.Global2Local(detElemId,
6e97fbb8 245 globalArea.GetPositionX(),globalArea.GetPositionY(),zg,
d08b5461 246 xl,yl,zl);
247
6e97fbb8 248 localArea = AliMpArea(xl,yl, globalArea.GetDimensionX(), globalArea.GetDimensionY());
d08b5461 249}
250
251//_____________________________________________________________________________
252Bool_t
253AliMUONSimpleClusterServer::Overlap(Int_t detElemId,
254 const AliMpArea& area,
255 AliMpArea& deArea) const
256{
257 /// Check whether (global) area overlaps with the given DE.
258 /// If it is, set deArea to the overlap region and convert it
259 /// in the local coordinate system of that DE.
260
261 Bool_t overlap(kFALSE);
262
72dae9ff 263 AliMpArea* globalDEArea = fkTransformer.GetDEArea(detElemId);
9bf6860b 264
265 if (!globalDEArea) return kFALSE;
d08b5461 266
267 AliMpArea overlapArea;
268
269 if ( area.Overlap(*globalDEArea) )
270 {
271 overlapArea = area.Intersect(*globalDEArea);
272 Global2Local(detElemId,overlapArea,deArea);
273 overlap = kTRUE;
274 }
275 else
276 {
277 deArea = AliMpArea();
278 }
279
280 AliDebug(1,Form("DE %04d area %s globalDEArea %s overlapArea %s deArea %s overlap=%d",
281 detElemId,
282 AsString(area).Data(),
283 AsString(*globalDEArea).Data(),
284 AsString(overlapArea).Data(),
285 AsString(deArea).Data(),
286 overlap));
287
288 return overlap;
289}
290
291//_____________________________________________________________________________
292TClonesArray*
293AliMUONSimpleClusterServer::PadArray(Int_t detElemId, Int_t cathode) const
294{
295 /// Return array for given cathode of given DE
296
297 return static_cast<TClonesArray*>(fPads[cathode]->GetValue(detElemId));
298}
299
9bf6860b 300//_____________________________________________________________________________
301Bool_t
302AliMUONSimpleClusterServer::UseTriggerTrackStore(AliMUONVTriggerTrackStore* trackStore)
303{
304 /// Tells us to use trigger track store, and thus to bypass St45 clusters
305 fTriggerTrackStore = trackStore; // not owner
306 delete fBypass;
72dae9ff 307 fBypass = new AliMUONTriggerTrackToTrackerClusters(fkTransformer,fTriggerTrackStore);
9bf6860b 308 return kTRUE;
309}
310
d08b5461 311//_____________________________________________________________________________
312void
2e2d0c44 313AliMUONSimpleClusterServer::UseDigits(TIter& next, AliMUONVDigitStore* digitStore)
d08b5461 314{
315 /// Convert digitStore into two arrays of AliMUONPads
2e2d0c44 316
317 fDigitStore = digitStore;
318
7deb8eb0 319 fPads[0]->Clear();
320 fPads[1]->Clear();
d08b5461 321
d08b5461 322 AliMUONVDigit* d;
d08b5461 323 while ( ( d = static_cast<AliMUONVDigit*>(next()) ) )
324 {
325 if ( ! d->Charge() > 0 ) continue; // skip void digits.
326 Int_t ix = d->PadX();
327 Int_t iy = d->PadY();
328 Int_t cathode = d->Cathode();
329 Int_t detElemId = d->DetElemId();
330 const AliMpVSegmentation* seg = AliMpSegmentation::Instance()->
331 GetMpSegmentation(detElemId,AliMp::GetCathodType(cathode));
168e9c4d 332 AliMpPad pad = seg->PadByIndices(ix,iy);
d08b5461 333
334 TClonesArray* padArray = PadArray(detElemId,cathode);
335 if (!padArray)
336 {
337 padArray = new TClonesArray("AliMUONPad",100);
338 fPads[cathode]->Add(detElemId,padArray);
339 }
340
341 AliMUONPad mpad(detElemId,cathode,
6e97fbb8 342 ix,iy,pad.GetPositionX(),pad.GetPositionY(),
343 pad.GetDimensionX(),pad.GetDimensionY(),
d08b5461 344 d->Charge());
345 if ( d->IsSaturated() ) mpad.SetSaturated(kTRUE);
346 mpad.SetUniqueID(d->GetUniqueID());
347 new ((*padArray)[padArray->GetLast()+1]) AliMUONPad(mpad);
348 }
349}
350
2e2d0c44 351//_____________________________________________________________________________
352Int_t
353AliMUONSimpleClusterServer::FindMCLabel(const AliMUONCluster& cluster, Int_t detElemId, const AliMpVSegmentation* seg[2]) const
354{
355 /// Find the label of the most contributing MC track (-1 in case of failure)
356 /// The data member fDigitStore must be set
357
358 // --- get the digit (if any) located at the cluster position on both cathods ---
359 Int_t nTracks[2] = {0, 0};
360 AliMUONVDigit* digit[2] = {0x0, 0x0};
361 for (Int_t iCath = 0; iCath < 2; iCath++) {
6e97fbb8 362 AliMpPad pad
363 = seg[AliMp::GetCathodType(iCath)]->PadByPosition(cluster.Position().X(), cluster.Position().Y(),kFALSE);
2e2d0c44 364 if (pad.IsValid()) {
168e9c4d 365 digit[iCath] = fDigitStore->FindObject(detElemId, pad.GetManuId(), pad.GetManuChannel(), iCath);
2e2d0c44 366 if (digit[iCath]) nTracks[iCath] = digit[iCath]->Ntracks();
367 }
368 }
369
370 if (nTracks[0] + nTracks[1] == 0) return -1;
371
372 // --- build the list of contributing tracks and of the associated charge ---
373 Int_t* trackId = new Int_t[nTracks[0] + nTracks[1]];
374 Float_t* trackCharge = new Float_t[nTracks[0] + nTracks[1]];
375 Int_t nTracksTot = 0;
376
377 // fill with contributing tracks on first cathod
378 for (Int_t iTrack1 = 0; iTrack1 < nTracks[0]; iTrack1++) {
379 trackId[iTrack1] = digit[0]->Track(iTrack1);
380 trackCharge[iTrack1] = digit[0]->TrackCharge(iTrack1);
381 }
382 nTracksTot = nTracks[0];
383
384 // complement with contributing tracks on second cathod
385 for (Int_t iTrack2 = 0; iTrack2 < nTracks[1]; iTrack2++) {
386 Int_t trackId2 = digit[1]->Track(iTrack2);
387 // check if track exist
388 Bool_t trackExist = kFALSE;
389 for (Int_t iTrack1 = 0; iTrack1 < nTracks[0]; iTrack1++) {
390 if (trackId2 == trackId[iTrack1]) {
391 // complement existing track
392 trackCharge[iTrack1] += digit[1]->TrackCharge(iTrack2);
393 trackExist = kTRUE;
394 break;
395 }
396 }
397 // add the new track
398 if (!trackExist) {
399 trackId[nTracksTot] = trackId2;
400 trackCharge[nTracksTot] = digit[1]->TrackCharge(iTrack2);
401 nTracksTot++;
402 }
403 }
404
405 // --- Find the most contributing track ---
406 Int_t mainTrackId = -1;
407 Float_t maxCharge = 0.;
408 for (Int_t iTrack = 0; iTrack < nTracksTot; iTrack++) {
409 if (trackCharge[iTrack] > maxCharge) {
410 mainTrackId = trackId[iTrack];
411 maxCharge = trackCharge[iTrack];
412 }
413 }
414
415 delete[] trackId;
416 delete[] trackCharge;
417
418 return mainTrackId;
419}
420
d08b5461 421//_____________________________________________________________________________
422void
423AliMUONSimpleClusterServer::Print(Option_t*) const
424{
425 /// Printout for debug only
426
427 AliMpDEIterator it;
428
429 it.First();
430
431 while ( !it.IsDone() )
432 {
433 Int_t detElemId = it.CurrentDEId();
434
435 // printout the number of pads / de, and number of used pads / de
436
437 if ( ( PadArray(detElemId,0) && PadArray(detElemId,0)->GetLast() >= 0 ) ||
438 ( PadArray(detElemId,1) && PadArray(detElemId,1)->GetLast() >= 0 ) )
439 {
440 cout << Form("---- DE %04d",detElemId) << endl;
441
442 for ( Int_t cathode = 0; cathode < 2; ++cathode )
443 {
444 cout << Form(" -- Cathode %1d",cathode) << endl;
445
446 TClonesArray* padArray = PadArray(detElemId,cathode);
447
448 if (!padArray)
449 {
450 cout << "no pad array" << endl;
451 }
452 else if ( padArray->GetLast() < 0 )
453 {
454 cout << "no pads" << endl;
455 }
456 else
457 {
458 TIter next(padArray);
459 AliMUONPad* pad;
460 while ( ( pad = static_cast<AliMUONPad*>(next()) ) )
461 {
462 pad->Print("full");
463 }
464 }
465 }
466 }
467 it.Next();
468 }
469}
470
471