]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONReconstructor.cxx
Managed the 234 local boards inside the class & simplified the code
[u/mrichter/AliRoot.git] / MUON / AliMUONReconstructor.cxx
CommitLineData
cac2eb58 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 **************************************************************************/
cac2eb58 15/* $Id$ */
16
22899106 17/// \class AliMUONReconstructor
18///
19/// Implementation of AliReconstructor for MUON subsystem.
20///
21/// The behavior of the MUON reconstruction can be changed, besides
22/// the usual methods found in AliReconstruction (e.g. to disable tracking)
23/// by using AliReconstruction::SetOption("MUON",options)
24/// where options should be a space separated string.
25///
26/// Valid options are :
27///
28/// SAVEDIGITS : if you want to save in the TreeD the *calibrated* digits
29/// that are used for the clustering
30///
31/// SIMPLEFIT : use the AliMUONClusterFinderSimpleFit clusterizer
32///
33/// AZ : use the AliMUONClusterFinderAZ clusterizer (default)
34///
35/// PRECLUSTER : use only AliMUONPreClusterFinder. Only for debug as
36/// the produced clusters do not have a position, hence the tracking will not
37/// work
38///
39/// COG : use AliMUONClusterFinderCOG clusterizer. Not really a production
40/// option either, as center-of-gravity is generally not a good estimate
41/// of the cluster position...
42///
43/// NOCLUSTERING : bypass completely the clustering stage
44///
45/// NOSTATUSMAP : disable the computation and usage of the pad status map. Only
46/// for debug !
47///
48/// NOLOCALRECONSTRUCTION : for debug, to disable local reconstruction (and hence
49/// "recover" old behavior)
50///
51/// TRIGGERDISABLE : disable the treatment of MUON trigger
52///
53/// \author Laurent Aphecetche, Subatech
30178c30 54
cf464691 55#include "AliMUONReconstructor.h"
b2d7df0b 56
22899106 57#include "AliCDBManager.h"
58#include "AliLoader.h"
59#include "AliLog.h"
60#include "AliRunLoader.h"
b2d7df0b 61#include "AliMUONCalibrationData.h"
22899106 62#include "AliMUONClusterFinderCOG.h"
63#include "AliMUONClusterFinderMLEM.h"
64#include "AliMUONClusterFinderSimpleFit.h"
346fb008 65#include "AliMUONClusterFinderAZ.h"
b2d7df0b 66#include "AliMUONClusterReconstructor.h"
22899106 67#include "AliMUONClusterStoreV1.h"
68#include "AliMUONConstants.h"
b2d7df0b 69#include "AliMUONDigitCalibrator.h"
2cf44ef3 70#include "AliMUONDigitMaker.h"
22899106 71#include "AliMUONDigitStoreV1.h"
72#include "AliMUONGeometryTransformer.h"
73#include "AliMUONPreClusterFinder.h"
196471e9 74#include "AliMUONTracker.h"
22899106 75#include "AliMUONVTrackStore.h"
e1a10d41 76#include "AliMUONTriggerCircuit.h"
96fdfe9a 77#include "AliMUONTriggerCrateStore.h"
22899106 78#include "AliMUONTriggerStoreV1.h"
79#include "AliMUONVClusterFinder.h"
cf464691 80#include "AliRawReader.h"
22899106 81#include "AliMUONStopwatchGroup.h"
82#include "AliMUONStopwatchGroupElement.h"
83#include <Riostream.h>
84#include <TClonesArray.h>
85#include <TString.h>
86#include <TTree.h>
29f1b13a 87
9265505b 88/// \cond CLASSIMP
cac2eb58 89ClassImp(AliMUONReconstructor)
22899106 90/// \endcond
b2d7df0b 91
cac2eb58 92//_____________________________________________________________________________
22899106 93AliMUONReconstructor::AliMUONReconstructor() :
94AliReconstructor(),
95fCrateManager(0x0),
96fDigitMaker(0x0),
97fTransformer(new AliMUONGeometryTransformer(kTRUE)),
98fDigitStore(0x0),
99fTriggerCircuit(0x0),
100fCalibrationData(0x0),
101fDigitCalibrator(0x0),
102fClusterReconstructor(0x0),
103fClusterStore(0x0),
104fTriggerStore(0x0),
105fTrackStore(0x0),
106fTimers(new AliMUONStopwatchGroup)
8789635b 107{
22899106 108 /// normal ctor
109 fTransformer->ReadGeometryData("volpath.dat", "geometry.root");
110}
d19b6003 111
22899106 112//_____________________________________________________________________________
113AliMUONReconstructor::~AliMUONReconstructor()
114{
115 /// dtor
116 delete fDigitMaker;
117 delete fDigitStore;
118 delete fTransformer;
119 delete fCrateManager;
120 delete fTriggerCircuit;
121 delete fCalibrationData;
122 delete fDigitCalibrator;
123 delete fClusterReconstructor;
124 delete fClusterStore;
125 delete fTriggerStore;
126 delete fTrackStore;
127 AliInfo("Timers:");
128 fTimers->Print();
129 delete fTimers;
130}
96fdfe9a 131
22899106 132//_____________________________________________________________________________
133void
134AliMUONReconstructor::Calibrate(AliMUONVDigitStore& digitStore) const
135{
136 /// Calibrate the digitStore
137 if (!fDigitCalibrator)
138 {
139 CreateCalibrator();
140 }
141 AliMUONStopwatchGroupElement timer(fTimers,"MUON",Form("%s::Calibrate(AliMUONVDigitStore*)",fDigitCalibrator->ClassName()));
142 fDigitCalibrator->Calibrate(digitStore);
143}
96fdfe9a 144
22899106 145//_____________________________________________________________________________
146void
147AliMUONReconstructor::Clusterize(const AliMUONVDigitStore& digitStore,
148 AliMUONVClusterStore& clusterStore) const
149{
150 /// Creates clusters from digits.
9c4b1ee7 151
22899106 152 TString sopt(GetOption());
153 sopt.ToUpper();
154 if ( sopt.Contains("NOCLUSTERING") ) return;
155
156 if (!fClusterReconstructor)
157 {
158 CreateClusterReconstructor();
159 }
9c4b1ee7 160
22899106 161 AliMUONStopwatchGroupElement timer(fTimers,"MUON",Form("%s::Digits2Clusters(const AliMUONVDigitStore&,AliMUONVClusterStore&)",
162 fClusterReconstructor->ClassName()));
163 fClusterReconstructor->Digits2Clusters(digitStore,clusterStore);
8789635b 164}
94f6fba9 165
8789635b 166//_____________________________________________________________________________
22899106 167AliMUONVClusterStore*
168AliMUONReconstructor::ClusterStore() const
cac2eb58 169{
22899106 170 /// Return (and create if necessary) the cluster container
171 if (!fClusterStore)
172 {
173 fClusterStore = new AliMUONClusterStoreV1;
174 }
175 return fClusterStore;
176}
d19b6003 177
22899106 178//_____________________________________________________________________________
179void
180AliMUONReconstructor::ConvertDigits(AliRawReader* rawReader,
181 AliMUONVDigitStore* digitStore,
182 AliMUONVTriggerStore* triggerStore) const
183{
184 /// Convert raw data into digit and trigger stores
185 CreateDigitMaker();
186 AliMUONStopwatchGroupElement timer(fTimers,"MUON",Form("%s::Raw2Digits(AliRawReader*,AliMUONVDigitStore*,AliMUONVTriggerStore*)",
187 fDigitMaker->ClassName()));
188 fDigitMaker->Raw2Digits(rawReader,digitStore,triggerStore);
189 Calibrate(*digitStore);
cac2eb58 190}
b2d7df0b 191
192//_____________________________________________________________________________
22899106 193void
194AliMUONReconstructor::ConvertDigits(AliRawReader* rawReader, TTree* digitsTree) const
b2d7df0b 195{
22899106 196 /// convert raw data into a digit tree
197
198 Bool_t alone = ( TriggerStore() == 0 );
b2d7df0b 199
22899106 200 Bool_t ok = DigitStore()->Connect(*digitsTree,alone);
201 if ( TriggerStore() )
b476b122 202 {
22899106 203 ok = ok && TriggerStore()->Connect(*digitsTree,kFALSE);
b476b122 204 }
ee103e97 205
22899106 206 if (!ok)
207 {
208 AliError("Could not make branches on TreeD");
209 }
210 else
211 {
212 ConvertDigits(rawReader,DigitStore(),TriggerStore());
213 digitsTree->Fill();
214 DigitStore()->Clear();
215 }
216}
217
218//_____________________________________________________________________________
219AliMUONTriggerCrateStore*
220AliMUONReconstructor::CrateManager() const
221{
222 /// Return (and create if necessary) the trigger crate store
223 if (fCrateManager) return fCrateManager;
224 fCrateManager = new AliMUONTriggerCrateStore;
225 fCrateManager->ReadFromFile();
226 return fCrateManager;
227}
228
229//_____________________________________________________________________________
230void
231AliMUONReconstructor::CreateDigitMaker() const
232{
233 /// Create (and create if necessary) the digit maker
234 if (fDigitMaker) return;
235
236 AliMUONStopwatchGroupElement timer(fTimers,"MUON","AliMUONReconstructor::CreateDigitMaker()");
237
238 fDigitMaker = new AliMUONDigitMaker;
22899106 239}
240
241//_____________________________________________________________________________
242void
243AliMUONReconstructor::CreateTriggerCircuit() const
244{
245 /// Return (and create if necessary) the trigger circuit object
246 if (fTriggerCircuit) return;
247
248 AliMUONStopwatchGroupElement timer(fTimers,"MUON","AliMUONReconstructor::CreateTriggerCircuit()");
249
32ab62c9 250 fTriggerCircuit = new AliMUONTriggerCircuit(fTransformer);
22899106 251
32ab62c9 252}
22899106 253//_____________________________________________________________________________
254AliTracker*
255AliMUONReconstructor::CreateTracker(AliRunLoader* runLoader) const
256{
257 /// Create the MUONTracker object
258 /// The MUONTracker is passed the GetOption(), i.e. our own options
ee103e97 259
22899106 260 CreateTriggerCircuit();
261 CreateDigitMaker();
262
263 AliLoader* loader = runLoader->GetDetectorLoader("MUON");
264 if (!loader)
ee103e97 265 {
22899106 266 AliError("Cannot get MUONLoader, so cannot create MUONTracker");
267 return 0x0;
ee103e97 268 }
22899106 269 AliMUONTracker* tracker = new AliMUONTracker(loader,fDigitMaker,fTransformer,fTriggerCircuit);
270 tracker->SetOption(GetOption());
271
272 return tracker;
b2d7df0b 273}
274
f9247068 275//_____________________________________________________________________________
22899106 276void
196471e9 277AliMUONReconstructor::CreateClusterReconstructor() const
f9247068 278{
22899106 279 /// Create cluster reconstructor, depending on GetOption()
280
281 AliMUONStopwatchGroupElement timer(fTimers,"MUON","AliMUONReconstructor::CreateClusterReconstructor()");
06ca6d7b 282
22899106 283 AliDebug(1,"");
284
f9247068 285 AliMUONVClusterFinder* clusterFinder(0x0);
286
287 TString opt(GetOption());
288 opt.ToUpper();
289
290 if ( strstr(opt,"PRECLUSTER") )
291 {
292 clusterFinder = new AliMUONPreClusterFinder;
293 }
294 else if ( strstr(opt,"COG") )
295 {
296 clusterFinder = new AliMUONClusterFinderCOG;
297 }
298 else if ( strstr(opt,"SIMPLEFIT") )
299 {
300 clusterFinder = new AliMUONClusterFinderSimpleFit;
301 }
302 else if ( strstr(opt,"MLEM:DRAW") )
303 {
304 clusterFinder = new AliMUONClusterFinderMLEM(kTRUE);
305 }
306 else if ( strstr(opt,"MLEM") )
307 {
308 clusterFinder = new AliMUONClusterFinderMLEM(kFALSE);
309 }
22899106 310 else if ( strstr(opt,"AZ") )
311 {
312 clusterFinder = new AliMUONClusterFinderAZ;
313 }
314 else
315 {
316 clusterFinder = new AliMUONClusterFinderAZ;
317 }
f9247068 318
22899106 319 if ( clusterFinder )
f9247068 320 {
321 AliInfo(Form("Will use %s for clusterizing",clusterFinder->ClassName()));
322 }
323
22899106 324 fClusterReconstructor = new AliMUONClusterReconstructor(clusterFinder,fTransformer);
f9247068 325}
326
cac2eb58 327//_____________________________________________________________________________
22899106 328void
329AliMUONReconstructor::CreateCalibrator() const
cac2eb58 330{
22899106 331 /// Create the calibrator
2457f726 332
22899106 333 AliMUONStopwatchGroupElement timer(fTimers,"MUON","AliMUONReconstructor::CreateCalibrator()");
3bc8b580 334
22899106 335 Int_t runNumber = AliCDBManager::Instance()->GetRun();
3bc8b580 336
22899106 337 AliInfo("Calibration will occur.");
338
339 fCalibrationData = new AliMUONCalibrationData(runNumber);
340 if ( !fCalibrationData->IsValid() )
341 {
342 AliError("Could not retrieve calibrations !");
343 delete fCalibrationData;
344 fCalibrationData = 0x0;
345 return;
346 }
347
348 // Check that we get all the calibrations we'll need
349 if ( !fCalibrationData->Pedestals() ||
350 !fCalibrationData->Gains() ||
351 !fCalibrationData->HV() )
352 {
353 AliFatal("Could not access all required calibration data");
9ffe3ef4 354 }
cc87ebcd 355
22899106 356 TString opt(GetOption());
357 opt.ToUpper();
358 Bool_t statusMap(kTRUE);
b2d7df0b 359
22899106 360 if ( strstr(opt,"NOSTATUSMAP") )
361 {
362 AliWarning("Disconnecting status map : SHOULD BE USED FOR DEBUG ONLY. NOT FOR PRODUCTION !!!");
363 statusMap = kFALSE;
364 }
365 fDigitCalibrator = new AliMUONDigitCalibrator(*fCalibrationData,statusMap);
366}
9c4b1ee7 367
22899106 368//_____________________________________________________________________________
369AliMUONVDigitStore*
370AliMUONReconstructor::DigitStore() const
371{
372 /// Return (and create if necessary) the digit container
373 if (!fDigitStore)
374 {
375 fDigitStore = new AliMUONDigitStoreV1;
376 }
377 return fDigitStore;
378}
94f6fba9 379
22899106 380//_____________________________________________________________________________
381void
382AliMUONReconstructor::FillTreeR(AliMUONVTriggerStore* triggerStore,
383 AliMUONVClusterStore* clusterStore,
384 TTree& clustersTree) const
385{
386 /// Write the trigger and cluster information into TreeR
387
388 AliMUONStopwatchGroupElement timer(fTimers,"MUON","AliMUONReconstructor::FillTreeR()");
cc87ebcd 389
22899106 390 AliDebug(1,"");
391
392 Bool_t ok(kFALSE);
393 if ( triggerStore )
394 {
395 Bool_t alone = ( clusterStore ? kFALSE : kTRUE );
396 ok = triggerStore->Connect(clustersTree,alone);
397 if (!ok)
b2d7df0b 398 {
22899106 399 AliError("Could not create triggerStore branches in TreeR");
cc87ebcd 400 }
cac2eb58 401 }
22899106 402
403 if ( clusterStore )
404 {
405 Bool_t alone = ( triggerStore ? kFALSE : kTRUE );
406 ok = clusterStore->Connect(clustersTree,alone);
407 if (!ok)
408 {
409 AliError("Could not create triggerStore branches in TreeR");
410 }
411 }
412
413 if (ok) // at least one type of branches created successfully
414 {
415 clustersTree.Fill();
416 }
cac2eb58 417}
cf464691 418
419//_____________________________________________________________________________
22899106 420Bool_t
421AliMUONReconstructor::HasDigitConversion() const
cf464691 422{
22899106 423 /// We *do* have digit conversion, but we might advertise it only
424 /// if we want to save the digits.
425
426 TString opt(GetOption());
427 opt.ToUpper();
428 if ( opt.Contains("SAVEDIGITS" ) && !opt.Contains("NOLOCALRECONSTRUCTION") )
429 {
430 return kTRUE;
431 }
432 else
433 {
434 return kFALSE;
435 }
436}
f9247068 437
22899106 438//_____________________________________________________________________________
439Bool_t
440AliMUONReconstructor::HasLocalReconstruction() const
441{
442 /// Whether or not we have local reconstruction
443 TString opt(GetOption());
444 opt.ToUpper();
445 if ( opt.Contains("NOLOCALRECONSTRUCTION" ) )
94f6fba9 446 {
22899106 447 return kFALSE;
30eabfb8 448 }
22899106 449 else
450 {
451 return kTRUE;
452 }
453}
454
455//_____________________________________________________________________________
456void
457AliMUONReconstructor::Reconstruct(AliRawReader* rawReader, TTree* clustersTree) const
458{
459 /// This method is called by AliReconstruction if HasLocalReconstruction()==kTRUE AND
460 /// HasDigitConversion()==kFALSE
8cde4af5 461
22899106 462 if ( !clustersTree )
463 {
464 AliError("clustersTree is 0x0 !");
465 return;
466 }
b2d7df0b 467
22899106 468 if ( DigitStore() )
469 {
470 ConvertDigits(rawReader,DigitStore(),TriggerStore());
471 Clusterize(*(DigitStore()),*(ClusterStore()));
472 }
473
474 FillTreeR(TriggerStore(),ClusterStore(),*clustersTree);
475}
64b056bc 476
22899106 477//_____________________________________________________________________________
478void
479AliMUONReconstructor::Reconstruct(AliRunLoader* runLoader) const
480{
481 /// Reconstruct simulated data
94f6fba9 482
22899106 483 AliMUONStopwatchGroupElement timer(fTimers,"MUON","AliMUONReconstructor::Reconstruct(AliRunLoader*)");
94f6fba9 484
22899106 485 AliLoader* loader = runLoader->GetDetectorLoader("MUON");
486 if (!loader)
487 {
488 AliError("Could not get MUON loader");
489 return;
490 }
94f6fba9 491
22899106 492 Int_t nEvents = runLoader->GetNumberOfEvents();
493
494 for ( Int_t i = 0; i < nEvents; ++i )
94f6fba9 495 {
22899106 496 runLoader->GetEvent(i);
94f6fba9 497
22899106 498 loader->LoadRecPoints("update");
499 loader->CleanRecPoints();
500 loader->MakeRecPointsContainer();
501 TTree* clustersTree = loader->TreeR();
8cde4af5 502
22899106 503 loader->LoadDigits("read");
504 TTree* digitsTree = loader->TreeD();
94f6fba9 505
22899106 506 Reconstruct(digitsTree,clustersTree);
94f6fba9 507
22899106 508 loader->UnloadDigits();
cf464691 509 loader->WriteRecPoints("OVERWRITE");
22899106 510 loader->UnloadRecPoints();
cf464691 511 }
cf464691 512}
513
cac2eb58 514//_____________________________________________________________________________
22899106 515void
516AliMUONReconstructor::Reconstruct(AliRunLoader* runLoader, AliRawReader* rawReader) const
cac2eb58 517{
22899106 518 /// This method is called by AliReconstruction if HasLocalReconstruction()==kFALSE
519
520 AliMUONStopwatchGroupElement timer(fTimers,"MUON","AliMUONReconstructor::Reconstruct(AliRunLoader*, AliRawReader*)");
521
522 AliLoader* loader = runLoader->GetDetectorLoader("MUON");
523 if (!loader)
524 {
525 AliError("Could not get MUON loader");
526 return;
527 }
528
529 Int_t i(0);
530
531 while (rawReader->NextEvent())
532 {
533 runLoader->GetEvent(i++);
534
535 loader->LoadRecPoints("update");
536 loader->CleanRecPoints();
537 loader->MakeRecPointsContainer();
538 TTree* clustersTree = loader->TreeR();
8cde4af5 539
22899106 540 loader->LoadDigits("update");
541 loader->CleanDigits();
542 loader->MakeDigitsContainer();
543 TTree* digitsTree = loader->TreeD();
544 ConvertDigits(rawReader, digitsTree);
545 loader->WriteDigits("OVERWRITE");
22ccc301 546
22899106 547 Reconstruct(digitsTree,clustersTree);
22ccc301 548
22899106 549 loader->UnloadDigits();
550 loader->WriteRecPoints("OVERWRITE");
551 loader->UnloadRecPoints();
552 }
196471e9 553}
554
555//_____________________________________________________________________________
22899106 556void
557AliMUONReconstructor::Reconstruct(TTree* digitsTree, TTree* clustersTree) const
a2da7817 558{
22899106 559 /// This method is called by AliReconstruction if HasLocalReconstruction()==kTRUE
560 /// AND HasDigitConversion()==kTRUE
561
562 AliDebug(1,"");
563
564 if (!digitsTree || !clustersTree)
565 {
566 AliError(Form("Tree is null : digitsTree=%p clustersTree=%p",
567 digitsTree,clustersTree));
568 return;
569 }
d19b6003 570
22899106 571 if (!fDigitStore)
572 {
573 fDigitStore = AliMUONVDigitStore::Create(*digitsTree);
574 if (!fDigitStore)
575 {
576 AliError(Form("Could not get DigitStore from %s",digitsTree->GetName()));
577 }
578 else
579 {
580 AliInfo(Form("Created %s from %s",fDigitStore->ClassName(),digitsTree->GetName()));
581 }
582 }
583 if (!fTriggerStore)
584 {
585 fTriggerStore = AliMUONVTriggerStore::Create(*digitsTree);
586 if (!fTriggerStore)
587 {
588 AliError(Form("Could not get TriggerStore from %s",digitsTree->GetName()));
589 }
590 else
591 {
592 AliInfo(Form("Created %s from %s",fTriggerStore->ClassName(),digitsTree->GetName()));
593 }
594 }
595
596 if (!fTriggerStore && !fDigitStore)
597 {
598 AliError("No store at all. Nothing to do.");
599 return;
600 }
601
602 // insure we start with empty stores
603 if ( fDigitStore )
604 {
605 fDigitStore->Clear();
606 Bool_t alone = ( fTriggerStore ? kFALSE : kTRUE );
607 Bool_t ok = fDigitStore->Connect(*digitsTree,alone);
608 if (!ok)
609 {
610 AliError("Could not connect digitStore to digitsTree");
611 return;
612 }
613 }
614 if ( fTriggerStore )
615 {
616 fTriggerStore->Clear();
617 Bool_t alone = ( fDigitStore ? kFALSE : kTRUE );
618 Bool_t ok = fTriggerStore->Connect(*digitsTree,alone);
619 if (!ok)
620 {
621 AliError("Could not connect triggerStore to digitsTree");
622 return;
623 }
624 }
625
626 digitsTree->GetEvent(0);
627
628 if ( fDigitStore )
629 {
630 Clusterize(*fDigitStore,*(ClusterStore()));
631 }
632
633 FillTreeR(fTriggerStore,ClusterStore(),*clustersTree);
cac2eb58 634}
196471e9 635
636//_____________________________________________________________________________
22899106 637AliMUONVTriggerStore*
638AliMUONReconstructor::TriggerStore() const
196471e9 639{
22899106 640 /// Return (and create if necessary and allowed) the trigger container
641 TString sopt(GetOption());
642 sopt.ToUpper();
643
644 if (sopt.Contains("TRIGGERDISABLE"))
645 {
646 delete fTriggerStore;
647 fTriggerStore = 0x0;
648 }
649 else
650 {
651 if (!fTriggerStore)
652 {
653 fTriggerStore = new AliMUONTriggerStoreV1;
654 }
655 }
656 return fTriggerStore;
196471e9 657}