1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 #include "AliMUONSimpleClusterServer.h"
20 #include "AliCodeTimer.h"
22 #include "AliMUONCluster.h"
23 #include "AliMUONConstants.h"
24 #include "AliMUONGeometryTransformer.h"
25 #include "AliMUONPad.h"
26 #include "AliMUONTriggerTrackToTrackerClusters.h"
27 #include "AliMUONVCluster.h"
28 #include "AliMUONVClusterFinder.h"
29 #include "AliMUONVClusterStore.h"
30 #include "AliMUONVDigitStore.h"
31 #include "AliMUONRecoParam.h"
32 #include "AliMpArea.h"
33 #include "AliMpDEIterator.h"
34 #include "AliMpDEManager.h"
35 #include "AliMpExMap.h"
36 #include "AliMpExMapIterator.h"
38 #include "AliMpSegmentation.h"
39 #include "AliMpVSegmentation.h"
40 #include <Riostream.h>
41 #include <TObjArray.h>
45 /// \class AliMUONSimpleClusterServer
47 /// Implementation of AliMUONVClusterServer interface
50 /// \author Laurent Aphecetche, Subatech
55 ClassImp(AliMUONSimpleClusterServer)
60 TString AsString(const AliMpArea& area)
62 return Form("(X,Y)=(%7.3f,%7.3f) (DX,DY)=(%7.3f,%7.3f)",
65 area.GetDimensionX(), /// TBCL was Y !!!
66 area.GetDimensionY());
70 //_____________________________________________________________________________
71 AliMUONSimpleClusterServer::AliMUONSimpleClusterServer(AliMUONVClusterFinder* clusterFinder,
72 const AliMUONGeometryTransformer& transformer)
73 : AliMUONVClusterServer(),
75 fClusterFinder(clusterFinder),
76 fkTransformer(transformer),
78 fTriggerTrackStore(0x0),
82 /// Note that we take ownership of the clusterFinder
84 fPads[0] = new AliMpExMap;
85 fPads[1] = new AliMpExMap;
87 fPadsIterator[0] = fPads[0]->CreateIterator();
88 fPadsIterator[1] = fPads[1]->CreateIterator();
91 //_____________________________________________________________________________
92 AliMUONSimpleClusterServer::~AliMUONSimpleClusterServer()
95 delete fClusterFinder;
98 delete fPadsIterator[0];
99 delete fPadsIterator[1];
103 //_____________________________________________________________________________
105 AliMUONSimpleClusterServer::Clusterize(Int_t chamberId,
106 AliMUONVClusterStore& clusterStore,
107 const AliMpArea& area,
108 const AliMUONRecoParam* recoParam)
110 /// Area is in absolute coordinate. If not valid, means clusterize all
113 /// We first find out the list of DE that have a non-zero overlap with area,
114 /// and then use the clusterfinder to find clusters in those areas (and DE).
116 AliCodeTimerAuto(Form("Chamber %d",chamberId),0);
118 if ( fTriggerTrackStore && chamberId >= 6 )
120 return fBypass->GenerateClusters(chamberId,clusterStore);
124 AliError("Reconstruction parameters are missing: unable to clusterize");
132 Int_t nofAddedClusters(0);
133 Int_t fNCluster = clusterStore.GetSize();
135 AliDebug(1,Form("chamberId = %2d NofClusters before = %d searchArea=%s",
136 chamberId,fNCluster,AsString(area).Data()));
138 while ( !it.IsDone() )
140 Int_t detElemId = it.CurrentDEId();
144 static_cast<TObjArray*>(fPads[0]->GetValue(detElemId)),
145 static_cast<TObjArray*>(fPads[1]->GetValue(detElemId))
148 if ( ( pads[0] && pads[0]->GetLast()>=0 ) ||
149 ( pads[1] && pads[1]->GetLast()>=0 ) )
151 AliMpArea deArea; // area in DE-local-coordinates
154 if ( area.IsValid() )
156 ok = Overlap(detElemId,area,deArea);
161 const AliMpVSegmentation* seg[2] =
162 { AliMpSegmentation::Instance()->GetMpSegmentation(detElemId,AliMp::kCath0),
163 AliMpSegmentation::Instance()->GetMpSegmentation(detElemId,AliMp::kCath1)
166 fClusterFinder->SetChargeHints(recoParam->LowestPadCharge(),
167 recoParam->LowestClusterCharge());
169 if ( fClusterFinder->NeedSegmentation() )
171 fClusterFinder->Prepare(detElemId,pads,deArea,seg);
175 fClusterFinder->Prepare(detElemId,pads,deArea);
178 AliDebug(1,Form("Clusterizing DE %04d with %3d pads (cath0) and %3d pads (cath1)",
180 (pads[0] ? pads[0]->GetLast()+1 : 0),
181 (pads[1] ? pads[1]->GetLast()+1 : 0)));
183 AliMUONCluster* cluster;
185 while ( ( cluster = fClusterFinder->NextCluster() ) )
187 // add new cluster to the store with information to build its ID
188 // increment the number of clusters into the store
189 AliMUONVCluster* rawCluster = clusterStore.Add(chamberId, detElemId, fNCluster++);
193 // fill array of Id of digits attached to this cluster
194 Int_t nPad = cluster->Multiplicity();
195 if (nPad < 1) AliWarning("no pad attached to the cluster");
197 for (Int_t iPad=0; iPad<nPad; iPad++)
199 AliMUONPad *pad = cluster->Pad(iPad);
202 if (!pad->IsReal()) continue;
204 rawCluster->AddDigitId(pad->GetUniqueID());
207 // fill charge and other cluster informations
208 rawCluster->SetCharge(cluster->Charge());
209 rawCluster->SetChi2(cluster->Chi2());
212 fkTransformer.Local2Global(detElemId,
213 cluster->Position().X(), cluster->Position().Y(),
215 rawCluster->SetXYZ(xg, yg, zg);
216 rawCluster->SetErrXY(recoParam->GetDefaultNonBendingReso(chamberId),recoParam->GetDefaultBendingReso(chamberId));
219 if (fDigitStore && fDigitStore->HasMCInformation())
221 rawCluster->SetMCLabel(FindMCLabel(*cluster, detElemId, seg));
224 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",
225 detElemId,rawCluster->GetNDigits(),rawCluster->GetCharge(),
226 cluster->Position().X(),cluster->Position().Y(),0.0,
227 xg,yg,zg,rawCluster->GetMCLabel()));
234 AliDebug(1,Form("chamberId = %2d NofClusters after = %d",chamberId,fNCluster));
236 return nofAddedClusters;
240 //_____________________________________________________________________________
242 AliMUONSimpleClusterServer::Global2Local(Int_t detElemId, const AliMpArea& globalArea,
243 AliMpArea& localArea) const
245 /// Convert a global area in local area for a given DE
249 Int_t chamberId = AliMpDEManager::GetChamberId(detElemId);
250 if ( chamberId < 0 ) {
251 AliErrorStream() << "Cannot get chamberId from detElemId=" << detElemId << endl;
254 Double_t zg = AliMUONConstants::DefaultChamberZ(chamberId);
256 fkTransformer.Global2Local(detElemId,
257 globalArea.GetPositionX(),globalArea.GetPositionY(),zg,
260 localArea = AliMpArea(xl,yl, globalArea.GetDimensionX(), globalArea.GetDimensionY());
263 //_____________________________________________________________________________
265 AliMUONSimpleClusterServer::Overlap(Int_t detElemId,
266 const AliMpArea& area,
267 AliMpArea& deArea) const
269 /// Check whether (global) area overlaps with the given DE.
270 /// If it is, set deArea to the overlap region and convert it
271 /// in the local coordinate system of that DE.
273 Bool_t overlap(kFALSE);
275 AliMpArea* globalDEArea = fkTransformer.GetDEArea(detElemId);
277 if (!globalDEArea) return kFALSE;
279 AliMpArea overlapArea;
281 if ( area.Overlap(*globalDEArea) )
283 overlapArea = area.Intersect(*globalDEArea);
284 Global2Local(detElemId,overlapArea,deArea);
289 deArea = AliMpArea();
292 AliDebug(1,Form("DE %04d area %s globalDEArea %s overlapArea %s deArea %s overlap=%d",
294 AsString(area).Data(),
295 AsString(*globalDEArea).Data(),
296 AsString(overlapArea).Data(),
297 AsString(deArea).Data(),
303 //_____________________________________________________________________________
305 AliMUONSimpleClusterServer::PadArray(Int_t detElemId, Int_t cathode) const
307 /// Return array for given cathode of given DE
309 return static_cast<TObjArray*>(fPads[cathode]->GetValue(detElemId));
312 //_____________________________________________________________________________
314 AliMUONSimpleClusterServer::UseTriggerTrackStore(AliMUONVTriggerTrackStore* trackStore)
316 /// Tells us to use trigger track store, and thus to bypass St45 clusters
317 fTriggerTrackStore = trackStore; // not owner
319 fBypass = new AliMUONTriggerTrackToTrackerClusters(fkTransformer,fTriggerTrackStore);
323 //_____________________________________________________________________________
325 AliMUONSimpleClusterServer::UseDigits(TIter& next, AliMUONVDigitStore* digitStore)
327 /// Convert digitStore into two arrays of AliMUONPads
329 fDigitStore = digitStore;
331 // Clear pads arrays in the maps
332 for ( Int_t i=0; i<2; i++ ) {
333 fPadsIterator[i]->Reset();
334 Int_t key; TObject* obj;
335 while ( ( obj = fPadsIterator[i]->Next(key) ) ) {
336 //cout << "clearing array for detElemId " << key << " ";
342 while ( ( d = static_cast<AliMUONVDigit*>(next()) ) )
344 if ( ! d->Charge() > 0 ) continue; // skip void digits.
345 if ( ! d->IsTracker() ) continue; // skip trigger digits
346 Int_t ix = d->PadX();
347 Int_t iy = d->PadY();
348 Int_t cathode = d->Cathode();
349 Int_t detElemId = d->DetElemId();
350 const AliMpVSegmentation* seg = AliMpSegmentation::Instance()->
351 GetMpSegmentation(detElemId,AliMp::GetCathodType(cathode));
352 AliMpPad pad = seg->PadByIndices(ix,iy);
354 TObjArray* padArray = PadArray(detElemId,cathode);
357 padArray = new TObjArray(100);
358 padArray->SetOwner(kTRUE);
359 fPads[cathode]->Add(detElemId,padArray);
362 AliMUONPad* mpad = new AliMUONPad(detElemId,cathode,
363 ix,iy,pad.GetPositionX(),pad.GetPositionY(),
364 pad.GetDimensionX(),pad.GetDimensionY(),
366 if ( d->IsSaturated() ) mpad->SetSaturated(kTRUE);
367 mpad->SetUniqueID(d->GetUniqueID());
372 //_____________________________________________________________________________
374 AliMUONSimpleClusterServer::FindMCLabel(const AliMUONCluster& cluster, Int_t detElemId, const AliMpVSegmentation* seg[2]) const
376 /// Find the label of the most contributing MC track (-1 in case of failure)
377 /// The data member fDigitStore must be set
379 // --- get the digit (if any) located at the cluster position on both cathods ---
380 Int_t nTracks[2] = {0, 0};
381 AliMUONVDigit* digit[2] = {0x0, 0x0};
382 for (Int_t iCath = 0; iCath < 2; iCath++) {
384 = seg[AliMp::GetCathodType(iCath)]->PadByPosition(cluster.Position().X(), cluster.Position().Y(),kFALSE);
386 digit[iCath] = fDigitStore->FindObject(detElemId, pad.GetManuId(), pad.GetManuChannel(), iCath);
387 if (digit[iCath]) nTracks[iCath] = digit[iCath]->Ntracks();
391 if (nTracks[0] + nTracks[1] == 0) return -1;
393 // --- build the list of contributing tracks and of the associated charge ---
394 Int_t* trackId = new Int_t[nTracks[0] + nTracks[1]];
395 Float_t* trackCharge = new Float_t[nTracks[0] + nTracks[1]];
396 Int_t nTracksTot = 0;
398 // fill with contributing tracks on first cathod
399 for (Int_t iTrack1 = 0; iTrack1 < nTracks[0]; iTrack1++) {
400 trackId[iTrack1] = digit[0]->Track(iTrack1);
401 trackCharge[iTrack1] = digit[0]->TrackCharge(iTrack1);
403 nTracksTot = nTracks[0];
405 // complement with contributing tracks on second cathod
406 for (Int_t iTrack2 = 0; iTrack2 < nTracks[1]; iTrack2++) {
407 Int_t trackId2 = digit[1]->Track(iTrack2);
408 // check if track exist
409 Bool_t trackExist = kFALSE;
410 for (Int_t iTrack1 = 0; iTrack1 < nTracks[0]; iTrack1++) {
411 if (trackId2 == trackId[iTrack1]) {
412 // complement existing track
413 trackCharge[iTrack1] += digit[1]->TrackCharge(iTrack2);
420 trackId[nTracksTot] = trackId2;
421 trackCharge[nTracksTot] = digit[1]->TrackCharge(iTrack2);
426 // --- Find the most contributing track ---
427 Int_t mainTrackId = -1;
428 Float_t maxCharge = 0.;
429 for (Int_t iTrack = 0; iTrack < nTracksTot; iTrack++) {
430 if (trackCharge[iTrack] > maxCharge) {
431 mainTrackId = trackId[iTrack];
432 maxCharge = trackCharge[iTrack];
437 delete[] trackCharge;
442 //_____________________________________________________________________________
444 AliMUONSimpleClusterServer::Print(Option_t*) const
446 /// Printout for debug only
452 while ( !it.IsDone() )
454 Int_t detElemId = it.CurrentDEId();
456 // printout the number of pads / de, and number of used pads / de
458 if ( ( PadArray(detElemId,0) && PadArray(detElemId,0)->GetLast() >= 0 ) ||
459 ( PadArray(detElemId,1) && PadArray(detElemId,1)->GetLast() >= 0 ) )
461 cout << Form("---- DE %04d",detElemId) << endl;
463 for ( Int_t cathode = 0; cathode < 2; ++cathode )
465 cout << Form(" -- Cathode %1d",cathode) << endl;
467 TObjArray* padArray = PadArray(detElemId,cathode);
471 cout << "no pad array" << endl;
473 else if ( padArray->GetLast() < 0 )
475 cout << "no pads" << endl;
479 TIter next(padArray);
481 while ( ( pad = static_cast<AliMUONPad*>(next()) ) )