1 /**************************************************************************
2 * Copyright(c) 1998-2000, 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 **************************************************************************/
19 #include "AliRunDigitizer.h"
20 #include "AliRunLoader.h"
22 #include "AliMUONDigitizer.h"
23 #include "AliMUONConstants.h"
24 #include "AliMUONChamber.h"
25 #include "AliMUONHitMapA1.h"
27 #include "AliMUONLoader.h"
28 #include "AliMUONChamber.h"
29 #include "AliMUONConstants.h"
30 #include "AliMUONDigitizer.h"
31 #include "AliMUONTransientDigit.h"
32 #include "AliMUONHitMapA1.h"
35 /////////////////////////////////////////////////////////////////////////////////////
37 // AliMUONDigitizer should be base abstract class of all digitisers in the MUON
38 // module. It implements the common functionality of looping over input streams
39 // filling the fTDList and writing the fTDList to the output stream.
40 // Inheriting digitizers need to override certain methods to choose and initialize
41 // the correct input and output trees, apply the correct detector response if any
42 // and implement how the transient digits are generated from the input stream.
44 /////////////////////////////////////////////////////////////////////////////////////
46 ClassImp(AliMUONDigitizer)
48 //___________________________________________
49 AliMUONDigitizer::AliMUONDigitizer() :
58 // Default constructor.
59 // Initializes all pointers to NULL.
67 //___________________________________________
68 AliMUONDigitizer::AliMUONDigitizer(AliRunDigitizer* manager) :
69 AliDigitizer(manager),
77 // Constructor which should be used rather than the default constructor.
78 // Initializes all pointers to NULL.
86 //___________________________________________
87 AliMUONDigitizer::AliMUONDigitizer(const AliMUONDigitizer& rhs)
90 // Protected copy constructor
92 Fatal("AliMUONDigitizer", "Not implemented.");
95 //___________________________________________
96 AliMUONDigitizer::~AliMUONDigitizer()
101 //-------------------------------------------------------------------
103 AliMUONDigitizer::operator=(const AliMUONDigitizer& rhs)
105 // Protected assignement operator
107 if (this == &rhs) return *this;
109 Fatal("operator=", "Not implemented.");
114 //------------------------------------------------------------------------
115 Bool_t AliMUONDigitizer::Init()
121 //------------------------------------------------------------------------
122 void AliMUONDigitizer::Exec(Option_t* option)
124 // The main work loop starts here.
125 // The digitization process is broken up into two steps:
126 // 1) Loop over input streams and create transient digits from the input.
127 // Done in GenerateTransientDigits()
128 // 2) Loop over the generated transient digits and write them to the output
129 // stream. Done in CreateDigits()
131 if (GetDebug() > 0) Info("Exec", "Running digitiser.");
132 ParseOptions(option);
134 if (fManager->GetNinputs() == 0)
136 Warning("Exec", "No inputs set, nothing to do.");
140 if (! FetchLoaders(fManager->GetInputFolderName(0), fRunLoader, fGime) ) return;
141 if (! FetchGlobalPointers(fRunLoader) ) return;
145 if (GetDebug() > 1) Info("Exec", "Event Number is %d.", fManager->GetOutputEventNr());
147 // Loop over files to merge and to digitize
149 for (Int_t inputFile = 0; inputFile < fManager->GetNinputs(); inputFile++)
151 fMask = fManager->GetMask(inputFile);
153 Info("Exec", "Digitising folder %d, with fMask = %d: %s", inputFile, fMask,
154 (const char*)fManager->GetInputFolderName(inputFile));
157 // If this is the first file then we already have the loaders loaded.
158 if (! FetchLoaders(fManager->GetInputFolderName(inputFile), fRunLoader, fGime) )
161 // If this is not the first file then it is assumed to be background.
164 if (! InitInputData(fGime) ) continue;
165 GenerateTransientDigits();
166 CleanupInputData(fGime);
169 Bool_t ok = FetchLoaders(fManager->GetOutputFolderName(), fRunLoader, fGime);
170 if (ok) ok = InitOutputData(fGime);
171 if (ok) CreateDigits();
172 if (ok) CleanupOutputData(fGime);
177 //--------------------------------------------------------------------------
178 void AliMUONDigitizer::AddOrUpdateTransientDigit(AliMUONTransientDigit* mTD)
180 // Checks to see if the transient digit exists in the corresponding fHitMap.
181 // If it does then the digit is updated otherwise it is added.
183 if (ExistTransientDigit(mTD))
185 UpdateTransientDigit(mTD);
186 delete mTD; // The new digit can be deleted because it was not added.
189 AddTransientDigit(mTD);
192 //------------------------------------------------------------------------
193 void AliMUONDigitizer::UpdateTransientDigit(AliMUONTransientDigit* mTD)
195 // Update the transient digit that is already in the fTDList by adding the new
196 // transient digits charges and track lists to the existing one.
199 Info("UpdateTransientDigit", "Updating transient digit 0x%X", (void*)mTD);
200 // Choosing the maping of the cathode plane of the chamber:
201 Int_t iNchCpl= mTD->Chamber() + (mTD->Cathode()-1) * AliMUONConstants::NCh();
202 AliMUONTransientDigit *pdigit =
203 static_cast<AliMUONTransientDigit*>( fHitMap[iNchCpl]->GetHit(mTD->PadX(),mTD->PadY()) );
206 pdigit->AddSignal( mTD->Signal() );
207 pdigit->AddPhysicsSignal( mTD->Physics() );
209 // update list of tracks
210 Int_t ntracks = mTD->GetNTracks();
211 if (ntracks > kMAXTRACKS) // Truncate the number of tracks to kMAXTRACKS if we have to.
215 Warning("UpdateTransientDigit",
216 "TransientDigit returned the number of tracks to be %d, which is bigger than kMAXTRACKS.",
218 Warning("UpdateTransientDigit", "Reseting the number of tracks to be %d.", kMAXTRACKS);
220 ntracks = kMAXTRACKS;
223 for (Int_t i = 0; i < ntracks; i++)
225 pdigit->UpdateTrackList( mTD->GetTrack(i), mTD->GetCharge(i) );
229 //------------------------------------------------------------------------
230 void AliMUONDigitizer::AddTransientDigit(AliMUONTransientDigit* mTD)
232 // Adds the transient digit to the fTDList and sets the appropriate entry
233 // in the fHitMap arrays.
236 Info("AddTransientDigit", "Adding transient digit 0x%X", (void*)mTD);
237 // Choosing the maping of the cathode plane of the chamber:
238 Int_t iNchCpl= mTD->Chamber() + (mTD->Cathode()-1) * AliMUONConstants::NCh();
239 fTDList->AddAtAndExpand(mTD, fTDCounter);
240 fHitMap[iNchCpl]->SetHit( mTD->PadX(), mTD->PadY(), fTDCounter);
244 //------------------------------------------------------------------------
245 Bool_t AliMUONDigitizer::ExistTransientDigit(AliMUONTransientDigit* mTD)
247 // Checks if the transient digit already exists on the corresponding fHitMap.
248 // i.e. is there a transient digit on the same chamber, cathode and pad position
249 // as mTD. If yes then kTRUE is returned else kFASLE is returned.
251 // Choosing the maping of the cathode plane of the chamber:
252 Int_t iNchCpl= mTD->Chamber() + (mTD->Cathode()-1) * AliMUONConstants::NCh();
253 return( fHitMap[iNchCpl]->TestHit(mTD->PadX(), mTD->PadY()) );
256 //-----------------------------------------------------------------------
257 void AliMUONDigitizer::CreateDigits()
259 // Loops over the fTDList for each cathode, gets the correct signal for the
260 // digit and adds the new digit to the output stream.
262 if (GetDebug() > 1) Info("CreateDigits", "Creating digits...");
263 for (Int_t icat = 0; icat < 2; icat++)
266 // Filling Digit List
267 Int_t nentries = fTDList->GetEntriesFast();
268 for (Int_t nent = 0; nent < nentries; nent++)
270 AliMUONTransientDigit* td = (AliMUONTransientDigit*)fTDList->At(nent);
271 if (td == NULL) continue;
273 // Must be the same cathode, otherwise we will fill a mixture
274 // of digits from both cathodes.
275 if (icat != td->Cathode() - 1) continue;
278 Info("CreateDigits", "Creating digit from transient digit 0x%X", (void*)td);
280 Int_t q = GetSignalFrom(td);
281 if (q > 0) AddDigit(td, q);
287 //------------------------------------------------------------------------
288 void AliMUONDigitizer::AddDigit(AliMUONTransientDigit* td, Int_t responseCharge)
290 // Prepares the digits, track and charge arrays in preparation for a call to
291 // AddDigit(Int_t, Int_t[kMAXTRACKS], Int_t[kMAXTRACKS], Int_t[6])
292 // This method is called by CreateDigits() whenever a new digit needs to be added
293 // to the output stream trees.
294 // The responseCharge value is used as the Signal of the new digit.
295 // The OnWriteTransientDigit method is also called just before the adding the
296 // digit to allow inheriting digitizers to be able to do some specific processing
299 Int_t tracks[kMAXTRACKS];
300 Int_t charges[kMAXTRACKS];
303 digits[0] = td->PadX();
304 digits[1] = td->PadY();
305 digits[2] = td->Cathode() - 1;
306 digits[3] = responseCharge;
307 digits[4] = td->Physics();
308 digits[5] = td->Hit();
310 Int_t nptracks = td->GetNTracks();
311 if (nptracks > kMAXTRACKS)
316 "TransientDigit returned the number of tracks to be %d, which is bigger than kMAXTRACKS.",
318 Warning("AddDigit", "Reseting the number of tracks to be %d.", kMAXTRACKS);
320 nptracks = kMAXTRACKS;
323 for (Int_t i = 0; i < nptracks; i++)
325 tracks[i] = td->GetTrack(i);
326 charges[i] = td->GetCharge(i);
329 // Sort list of tracks according to charge
330 SortTracks(tracks,charges,nptracks);
332 if (nptracks < kMAXTRACKS )
334 for (Int_t i = nptracks; i < kMAXTRACKS; i++)
341 if (GetDebug() > 3) Info("AddDigit", "Adding digit with charge %d.", responseCharge);
343 OnWriteTransientDigit(td);
344 AddDigit(td->Chamber(), tracks, charges, digits);
347 //------------------------------------------------------------------------
348 void AliMUONDigitizer::OnCreateTransientDigit(AliMUONTransientDigit* /*digit*/, TObject* /*source_object*/)
352 // This is derived by Digitisers that want to trace which digits were made from
356 //------------------------------------------------------------------------
357 void AliMUONDigitizer::OnWriteTransientDigit(AliMUONTransientDigit* /*digit*/)
361 // This is derived by Digitisers that want to trace which digits were made from
365 //------------------------------------------------------------------------
366 Bool_t AliMUONDigitizer::FetchLoaders(const char* foldername, AliRunLoader*& runloader, AliMUONLoader*& muonloader)
368 // Fetches the run loader from the current folder, specified by 'foldername'.
369 // The muon loader is then loaded from the fetched run loader.
370 // kTRUE is returned if no error occurred otherwise kFALSE is returned.
373 Info("FetchLoaders", "Fetching run loader and muon loader from folder: %s", foldername);
375 runloader = AliRunLoader::GetRunLoader(foldername);
376 if (runloader == NULL)
378 Error("FetchLoaders", "RunLoader not found in folder: %s", foldername);
381 muonloader = (AliMUONLoader*) runloader->GetLoader("MUONLoader");
382 if (muonloader == NULL)
384 Error("FetchLoaders", "MUONLoader not found in folder: %s", foldername);
390 //------------------------------------------------------------------------
391 Bool_t AliMUONDigitizer::FetchGlobalPointers(AliRunLoader* runloader)
393 // Fetches the AliRun object into the global gAlice pointer from the specified
394 // run loader. The AliRun object is loaded into memory using the run loader if
395 // not yet loaded. The MUON module object is then loaded from gAlice and
396 // AliMUONData fetched from the MUON module.
397 // kTRUE is returned if no error occurred otherwise kFALSE is returned.
400 Info("FetchGlobalPointers", "Fetching gAlice, MUON module and AliMUONData from runloader 0x%X.",
404 if (runloader->GetAliRun() == NULL) runloader->LoadgAlice();
405 gAlice = runloader->GetAliRun();
408 Error("FetchGlobalPointers", "Could not find the AliRun object in runloader 0x%X.", (void*)runloader);
411 fMUON = (AliMUON*) gAlice->GetDetector("MUON");
414 Error("FetchGlobalPointers", "Could not find the MUON module in runloader 0x%X.", (void*)runloader);
417 fMUONData = fMUON->GetMUONData();
418 if (fMUONData == NULL)
420 Error("FetchGlobalPointers", "Could not find AliMUONData object in runloader 0x%X.", (void*)runloader);
426 //------------------------------------------------------------------------
427 void AliMUONDigitizer::ParseOptions(Option_t* options)
429 // Called by the Exec method. ParseOptions should parse the option string given to the Exec method.
431 // The following options are defined:
432 // "debug" - Sets the debug level to 99, which will show all debug messages.
433 // "deb" - Same as "debug", implemented for backward comparability.
435 // If an invalid option is specified it is simply ignored.
437 TString optionString = options;
438 if (optionString.Data() == "debug" ||
439 optionString.Data() == "deb" // maintained for compatability.
442 Info("ParseOptions", "Called with option \"debug\".");
447 //------------------------------------------------------------------------
448 void AliMUONDigitizer::InitArrays()
450 // Creates a new fTDList object.
451 // Also creates an array of 2 * chamber_number AliMUONHitMapA1 objects
452 // in the fHitMaps array. Each one is set to a chamber and cathode
453 // specific segmentation model.
455 // Note: the fTDList and fHitMap arrays must be NULL before calling this method.
457 if (GetDebug() > 1) Info("InitArrays", "Initialising internal arrays.");
458 if (GetDebug() > 3) Info("InitArrays", "Creating transient digits list.");
459 fTDList = new TObjArray;
461 // Array of pointer of the AliMUONHitMapA1:
462 // two HitMaps per chamber, or one HitMap per cahtode plane
463 fHitMap = new AliMUONHitMapA1* [2*AliMUONConstants::NCh()];
465 // Loop over chambers for the definition AliMUONHitMap
466 for (Int_t i = 0; i < AliMUONConstants::NCh(); i++)
468 if (GetDebug() > 3) Info("InitArrays", "Creating hit map for chamber %d, cathode 1.", i+1);
469 AliMUONChamber* chamber = &(fMUON->Chamber(i));
470 AliSegmentation* c1Segmentation = chamber->SegmentationModel(1); // Cathode plane 1
471 fHitMap[i] = new AliMUONHitMapA1(c1Segmentation, fTDList);
472 if (GetDebug() > 3) Info("InitArrays", "Creating hit map for chamber %d, cathode 2.", i+1);
473 AliSegmentation* c2Segmentation = chamber->SegmentationModel(2); // Cathode plane 2
474 fHitMap[i+AliMUONConstants::NCh()] = new AliMUONHitMapA1(c2Segmentation, fTDList);
478 //------------------------------------------------------------------------
479 void AliMUONDigitizer::CleanupArrays()
481 // The arrays fTDList and fHitMap are deleted and the pointers set to NULL.
483 if (GetDebug() > 1) Info("CleanupArrays", "Deleting internal arrays.");
484 for(Int_t i = 0; i < 2*AliMUONConstants::NCh(); i++)
486 if (GetDebug() > 3) Info("CleanupArrays", "Deleting hit map for chamber %d, cathode %d.",
487 i%AliMUONConstants::NCh()+1, i/AliMUONConstants::NCh()+1);
493 if (GetDebug() > 3) Info("CleanupArrays", "Deleting transient digits list.");
499 //------------------------------------------------------------------------
500 void AliMUONDigitizer::SortTracks(Int_t *tracks, Int_t *charges, Int_t ntr) const
503 // Sort the list of tracks contributing to a given digit
504 // Only the 3 most significant tracks are actually sorted
507 if (ntr <= 1) return;
510 // Loop over signals, only 3 times
515 Int_t idx[3] = {-2,-2,-2};
516 Int_t jch[3] = {-2,-2,-2};
517 Int_t jtr[3] = {-2,-2,-2};
520 if (ntr < 3) imax = ntr;
523 for(i = 0; i < imax; i++)
528 for(j = 0; j < ntr; j++)
530 if ( (i == 1 && j == idx[i-1]) ||
531 (i == 2 && (j == idx[i-1] || j == idx[i-2]))
535 if(charges[j] > qmax)
545 jch[i] = charges[jmax];
546 jtr[i] = tracks[jmax];
551 for(i = 0; i < 3; i++)