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 <TClonesArray.h>
45 /// \class AliMUONSimpleClusterServer
47 /// Implementation of AliMUONVClusterServer interface
50 /// \author Laurent Aphecetche, Subatech
53 ClassImp(AliMUONSimpleClusterServer)
58 TString AsString(const AliMpArea& area)
60 return Form("(X,Y)=(%7.3f,%7.3f) (DX,DY)=(%7.3f,%7.3f)",
63 area.GetDimensionX(), /// TBCL was Y !!!
64 area.GetDimensionY());
68 //_____________________________________________________________________________
69 AliMUONSimpleClusterServer::AliMUONSimpleClusterServer(AliMUONVClusterFinder* clusterFinder,
70 const AliMUONGeometryTransformer& transformer)
71 : AliMUONVClusterServer(),
73 fClusterFinder(clusterFinder),
74 fkTransformer(transformer),
76 fTriggerTrackStore(0x0),
80 /// Note that we take ownership of the clusterFinder
82 fPads[0] = new AliMpExMap;
83 fPads[1] = new AliMpExMap;
85 fPadsIterator[0] = fPads[0]->CreateIterator();
86 fPadsIterator[1] = fPads[1]->CreateIterator();
89 //_____________________________________________________________________________
90 AliMUONSimpleClusterServer::~AliMUONSimpleClusterServer()
93 delete fClusterFinder;
96 delete fPadsIterator[0];
97 delete fPadsIterator[1];
101 //_____________________________________________________________________________
103 AliMUONSimpleClusterServer::Clusterize(Int_t chamberId,
104 AliMUONVClusterStore& clusterStore,
105 const AliMpArea& area,
106 const AliMUONRecoParam* recoParam)
108 /// Area is in absolute coordinate. If not valid, means clusterize all
111 /// We first find out the list of DE that have a non-zero overlap with area,
112 /// and then use the clusterfinder to find clusters in those areas (and DE).
114 AliCodeTimerAuto(Form("Chamber %d",chamberId),0);
116 if ( fTriggerTrackStore && chamberId >= 6 )
118 return fBypass->GenerateClusters(chamberId,clusterStore);
122 AliError("Reconstruction parameters are missing: unable to clusterize");
130 Int_t nofAddedClusters(0);
131 Int_t fNCluster = clusterStore.GetSize();
133 AliDebug(1,Form("chamberId = %2d NofClusters before = %d searchArea=%s",
134 chamberId,fNCluster,AsString(area).Data()));
136 while ( !it.IsDone() )
138 Int_t detElemId = it.CurrentDEId();
140 TClonesArray* pads[2] =
142 static_cast<TClonesArray*>(fPads[0]->GetValue(detElemId)),
143 static_cast<TClonesArray*>(fPads[1]->GetValue(detElemId))
146 if ( ( pads[0] && pads[0]->GetLast()>=0 ) ||
147 ( pads[1] && pads[1]->GetLast()>=0 ) )
149 AliMpArea deArea; // area in DE-local-coordinates
152 if ( area.IsValid() )
154 ok = Overlap(detElemId,area,deArea);
159 const AliMpVSegmentation* seg[2] =
160 { AliMpSegmentation::Instance()->GetMpSegmentation(detElemId,AliMp::kCath0),
161 AliMpSegmentation::Instance()->GetMpSegmentation(detElemId,AliMp::kCath1)
164 fClusterFinder->SetChargeHints(recoParam->LowestPadCharge(),
165 recoParam->LowestClusterCharge());
167 if ( fClusterFinder->NeedSegmentation() )
169 fClusterFinder->Prepare(detElemId,pads,deArea,seg);
173 fClusterFinder->Prepare(detElemId,pads,deArea);
176 AliDebug(1,Form("Clusterizing DE %04d with %3d pads (cath0) and %3d pads (cath1)",
178 (pads[0] ? pads[0]->GetLast()+1 : 0),
179 (pads[1] ? pads[1]->GetLast()+1 : 0)));
181 AliMUONCluster* cluster;
183 while ( ( cluster = fClusterFinder->NextCluster() ) )
185 // add new cluster to the store with information to build its ID
186 // increment the number of clusters into the store
187 AliMUONVCluster* rawCluster = clusterStore.Add(chamberId, detElemId, fNCluster++);
191 // fill array of Id of digits attached to this cluster
192 Int_t nPad = cluster->Multiplicity();
193 if (nPad < 1) AliWarning("no pad attached to the cluster");
195 for (Int_t iPad=0; iPad<nPad; iPad++)
197 AliMUONPad *pad = cluster->Pad(iPad);
200 if (!pad->IsReal()) continue;
202 rawCluster->AddDigitId(pad->GetUniqueID());
205 // fill charge and other cluster informations
206 rawCluster->SetCharge(cluster->Charge());
207 rawCluster->SetChi2(cluster->Chi2());
210 fkTransformer.Local2Global(detElemId,
211 cluster->Position().X(), cluster->Position().Y(),
213 rawCluster->SetXYZ(xg, yg, zg);
214 rawCluster->SetErrXY(recoParam->GetDefaultNonBendingReso(chamberId),recoParam->GetDefaultBendingReso(chamberId));
217 if (fDigitStore && fDigitStore->HasMCInformation())
219 rawCluster->SetMCLabel(FindMCLabel(*cluster, detElemId, seg));
222 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",
223 detElemId,rawCluster->GetNDigits(),rawCluster->GetCharge(),
224 cluster->Position().X(),cluster->Position().Y(),0.0,
225 xg,yg,zg,rawCluster->GetMCLabel()));
232 AliDebug(1,Form("chamberId = %2d NofClusters after = %d",chamberId,fNCluster));
234 return nofAddedClusters;
238 //_____________________________________________________________________________
240 AliMUONSimpleClusterServer::Global2Local(Int_t detElemId, const AliMpArea& globalArea,
241 AliMpArea& localArea) const
243 /// Convert a global area in local area for a given DE
247 Double_t zg = AliMUONConstants::DefaultChamberZ(AliMpDEManager::GetChamberId(detElemId));
249 fkTransformer.Global2Local(detElemId,
250 globalArea.GetPositionX(),globalArea.GetPositionY(),zg,
253 localArea = AliMpArea(xl,yl, globalArea.GetDimensionX(), globalArea.GetDimensionY());
256 //_____________________________________________________________________________
258 AliMUONSimpleClusterServer::Overlap(Int_t detElemId,
259 const AliMpArea& area,
260 AliMpArea& deArea) const
262 /// Check whether (global) area overlaps with the given DE.
263 /// If it is, set deArea to the overlap region and convert it
264 /// in the local coordinate system of that DE.
266 Bool_t overlap(kFALSE);
268 AliMpArea* globalDEArea = fkTransformer.GetDEArea(detElemId);
270 if (!globalDEArea) return kFALSE;
272 AliMpArea overlapArea;
274 if ( area.Overlap(*globalDEArea) )
276 overlapArea = area.Intersect(*globalDEArea);
277 Global2Local(detElemId,overlapArea,deArea);
282 deArea = AliMpArea();
285 AliDebug(1,Form("DE %04d area %s globalDEArea %s overlapArea %s deArea %s overlap=%d",
287 AsString(area).Data(),
288 AsString(*globalDEArea).Data(),
289 AsString(overlapArea).Data(),
290 AsString(deArea).Data(),
296 //_____________________________________________________________________________
298 AliMUONSimpleClusterServer::PadArray(Int_t detElemId, Int_t cathode) const
300 /// Return array for given cathode of given DE
302 return static_cast<TClonesArray*>(fPads[cathode]->GetValue(detElemId));
305 //_____________________________________________________________________________
307 AliMUONSimpleClusterServer::UseTriggerTrackStore(AliMUONVTriggerTrackStore* trackStore)
309 /// Tells us to use trigger track store, and thus to bypass St45 clusters
310 fTriggerTrackStore = trackStore; // not owner
312 fBypass = new AliMUONTriggerTrackToTrackerClusters(fkTransformer,fTriggerTrackStore);
316 //_____________________________________________________________________________
318 AliMUONSimpleClusterServer::UseDigits(TIter& next, AliMUONVDigitStore* digitStore)
320 /// Convert digitStore into two arrays of AliMUONPads
322 fDigitStore = digitStore;
324 // Clear pads arrays in the maps
325 for ( Int_t i=0; i<2; i++ ) {
326 fPadsIterator[i]->Reset();
327 Int_t key; TObject* obj;
328 while ( ( obj = fPadsIterator[i]->Next(key) ) ) {
329 //cout << "clearing array for detElemId " << key << " ";
335 while ( ( d = static_cast<AliMUONVDigit*>(next()) ) )
337 if ( ! d->Charge() > 0 ) continue; // skip void digits.
338 if ( ! d->IsTracker() ) continue; // skip trigger digits
339 Int_t ix = d->PadX();
340 Int_t iy = d->PadY();
341 Int_t cathode = d->Cathode();
342 Int_t detElemId = d->DetElemId();
343 const AliMpVSegmentation* seg = AliMpSegmentation::Instance()->
344 GetMpSegmentation(detElemId,AliMp::GetCathodType(cathode));
345 AliMpPad pad = seg->PadByIndices(ix,iy);
347 TClonesArray* padArray = PadArray(detElemId,cathode);
350 padArray = new TClonesArray("AliMUONPad",100);
351 fPads[cathode]->Add(detElemId,padArray);
354 AliMUONPad mpad(detElemId,cathode,
355 ix,iy,pad.GetPositionX(),pad.GetPositionY(),
356 pad.GetDimensionX(),pad.GetDimensionY(),
358 if ( d->IsSaturated() ) mpad.SetSaturated(kTRUE);
359 mpad.SetUniqueID(d->GetUniqueID());
360 new ((*padArray)[padArray->GetLast()+1]) AliMUONPad(mpad);
364 //_____________________________________________________________________________
366 AliMUONSimpleClusterServer::FindMCLabel(const AliMUONCluster& cluster, Int_t detElemId, const AliMpVSegmentation* seg[2]) const
368 /// Find the label of the most contributing MC track (-1 in case of failure)
369 /// The data member fDigitStore must be set
371 // --- get the digit (if any) located at the cluster position on both cathods ---
372 Int_t nTracks[2] = {0, 0};
373 AliMUONVDigit* digit[2] = {0x0, 0x0};
374 for (Int_t iCath = 0; iCath < 2; iCath++) {
376 = seg[AliMp::GetCathodType(iCath)]->PadByPosition(cluster.Position().X(), cluster.Position().Y(),kFALSE);
378 digit[iCath] = fDigitStore->FindObject(detElemId, pad.GetManuId(), pad.GetManuChannel(), iCath);
379 if (digit[iCath]) nTracks[iCath] = digit[iCath]->Ntracks();
383 if (nTracks[0] + nTracks[1] == 0) return -1;
385 // --- build the list of contributing tracks and of the associated charge ---
386 Int_t* trackId = new Int_t[nTracks[0] + nTracks[1]];
387 Float_t* trackCharge = new Float_t[nTracks[0] + nTracks[1]];
388 Int_t nTracksTot = 0;
390 // fill with contributing tracks on first cathod
391 for (Int_t iTrack1 = 0; iTrack1 < nTracks[0]; iTrack1++) {
392 trackId[iTrack1] = digit[0]->Track(iTrack1);
393 trackCharge[iTrack1] = digit[0]->TrackCharge(iTrack1);
395 nTracksTot = nTracks[0];
397 // complement with contributing tracks on second cathod
398 for (Int_t iTrack2 = 0; iTrack2 < nTracks[1]; iTrack2++) {
399 Int_t trackId2 = digit[1]->Track(iTrack2);
400 // check if track exist
401 Bool_t trackExist = kFALSE;
402 for (Int_t iTrack1 = 0; iTrack1 < nTracks[0]; iTrack1++) {
403 if (trackId2 == trackId[iTrack1]) {
404 // complement existing track
405 trackCharge[iTrack1] += digit[1]->TrackCharge(iTrack2);
412 trackId[nTracksTot] = trackId2;
413 trackCharge[nTracksTot] = digit[1]->TrackCharge(iTrack2);
418 // --- Find the most contributing track ---
419 Int_t mainTrackId = -1;
420 Float_t maxCharge = 0.;
421 for (Int_t iTrack = 0; iTrack < nTracksTot; iTrack++) {
422 if (trackCharge[iTrack] > maxCharge) {
423 mainTrackId = trackId[iTrack];
424 maxCharge = trackCharge[iTrack];
429 delete[] trackCharge;
434 //_____________________________________________________________________________
436 AliMUONSimpleClusterServer::Print(Option_t*) const
438 /// Printout for debug only
444 while ( !it.IsDone() )
446 Int_t detElemId = it.CurrentDEId();
448 // printout the number of pads / de, and number of used pads / de
450 if ( ( PadArray(detElemId,0) && PadArray(detElemId,0)->GetLast() >= 0 ) ||
451 ( PadArray(detElemId,1) && PadArray(detElemId,1)->GetLast() >= 0 ) )
453 cout << Form("---- DE %04d",detElemId) << endl;
455 for ( Int_t cathode = 0; cathode < 2; ++cathode )
457 cout << Form(" -- Cathode %1d",cathode) << endl;
459 TClonesArray* padArray = PadArray(detElemId,cathode);
463 cout << "no pad array" << endl;
465 else if ( padArray->GetLast() < 0 )
467 cout << "no pads" << endl;
471 TIter next(padArray);
473 while ( ( pad = static_cast<AliMUONPad*>(next()) ) )