LCOV - code coverage report
Current view: top level - ITSMFT/MFT/MFTsim - AliMFTDigitizer.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 1 102 1.0 %
Date: 2016-06-14 17:26:59 Functions: 1 8 12.5 %

          Line data    Source code
       1             : /**************************************************************************
       2             :  * Copyright(c) 1998-2000, 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             : //====================================================================================================================================================
      17             : //
      18             : //      Digitizer class for the ALICE Muon Forward Tracker
      19             : //
      20             : //      Contact author: antonio.uras@cern.ch
      21             : //
      22             : //====================================================================================================================================================
      23             : 
      24             : #include "AliRun.h"
      25             : #include "AliRunLoader.h"
      26             : #include "AliDigitizationInput.h"
      27             : #include "AliLoader.h"
      28             : #include "AliLog.h"
      29             : #include "AliMFTDigitizer.h"
      30             : #include "AliMFTDigit.h"
      31             : #include "AliMFT.h"
      32             : #include "AliMFTSegmentation.h"
      33             : #include "AliMFTHalfSegmentation.h"
      34             : #include "AliMFTHalfDiskSegmentation.h"
      35             : #include "TObjArray.h"
      36             : #include "TClonesArray.h"
      37             : #include "TTree.h"
      38             : #include "AliDigitizer.h"
      39             : #include "AliMFTGeometry.h"
      40             : #include "AliCodeTimer.h"
      41             : 
      42             : 
      43          12 : ClassImp(AliMFTDigitizer)
      44             : 
      45             : //====================================================================================================================================================
      46             :     
      47             : AliMFTDigitizer::AliMFTDigitizer():
      48           0 :   AliDigitizer(),
      49           0 :   fNPlanes(0),
      50           0 :   fSegmentation(0)
      51           0 : {
      52             : 
      53             :   // default constructor 
      54             : 
      55           0 : }
      56             : 
      57             : //====================================================================================================================================================
      58             : 
      59             : AliMFTDigitizer::AliMFTDigitizer(AliDigitizationInput *digInp):
      60           0 :   AliDigitizer(digInp),
      61           0 :   fNPlanes(0),
      62           0 :   fSegmentation(0)
      63           0 : {
      64             : 
      65           0 : }
      66             : 
      67             : //====================================================================================================================================================
      68             : 
      69             : void AliMFTDigitizer::Digitize(Option_t*) {
      70           0 :   AliCodeTimerAuto("",0);
      71             : 
      72             :   // This method is responsible for merging sdigits to a list of digits
      73             : 
      74           0 :   AliDebug(1, "************************************************************************");
      75           0 :   AliDebug(1, "************************ AliMFTDigitizer::Digitize *********************");
      76           0 :   AliDebug(1, "************************************************************************");
      77             :   
      78             :   
      79           0 :   fNPlanes = AliMFTConstants::kNDisks;
      80             : 
      81           0 :   AliDebug(1, Form("nPlanes = %d",fNPlanes));
      82             : 
      83           0 :   AliDebug(1,Form("Start with %i input(s) for event %i", fDigInput->GetNinputs(), fDigInput->GetOutputEventNr()));
      84             :     
      85             :   AliRunLoader *pInRunLoader=0;
      86             :   AliLoader    *pInMFTLoader=0;
      87             :   
      88           0 :   TClonesArray sDigits[AliMFTConstants::kNDisks];
      89           0 :   for (Int_t iPlane=0; iPlane<AliMFTConstants::kNDisks; iPlane++) sDigits[iPlane].SetClass("AliMFTDigit");  // tmp storage for sdigits sum up from all input files
      90             :   
      91             :   // filling the arrays of sdigits...
      92             : 
      93           0 :   for (Int_t iFile=0; iFile<fDigInput->GetNinputs(); iFile++) {
      94             :     
      95           0 :     pInRunLoader = AliRunLoader::GetRunLoader(fDigInput->GetInputFolderName(iFile));
      96           0 :     pInMFTLoader = pInRunLoader->GetLoader("MFTLoader"); 
      97           0 :     if (!pInMFTLoader) {
      98           0 :       AliDebug(1,"no MFT loader, checking in the other input \n");
      99             :       continue;
     100             :     }
     101             :     
     102           0 :     if (!pInRunLoader->GetAliRun()) pInRunLoader->LoadgAlice();
     103           0 :     AliMFT *pInMFT = (AliMFT*) pInRunLoader->GetAliRun()->GetDetector("MFT"); 
     104             :     
     105           0 :     AliDebug(1, "pInMFTLoader->LoadSDigits()...");
     106           0 :     pInMFTLoader->LoadSDigits();
     107           0 :     AliDebug(1, "... done!");
     108           0 :     AliDebug(1, "    pInMFTLoader->TreeS()->GetEntry(0);");
     109           0 :     pInMFTLoader->TreeS()->GetEntry(0);
     110           0 :     AliDebug(1, "... done!");
     111             :     
     112           0 :     for (Int_t iPlane=0; iPlane<pInMFT->GetSDigitsList()->GetEntries(); iPlane++) {      
     113           0 :       for(Int_t iSDig=0; iSDig<((TClonesArray*)pInMFT->GetSDigitsList()->At(iPlane))->GetEntries(); iSDig++) {
     114           0 :         AliDebug(2, Form("Reading digit %03d of plane %02d (A)", iSDig, iPlane));
     115           0 :         AliMFTDigit *pSDig = (AliMFTDigit*) ((TClonesArray*)pInMFT->GetSDigitsList()->At(iPlane))->At(iSDig);
     116           0 :         AliDebug(2, Form("Reading digit %03d of plane %02d (B)", iSDig, iPlane));
     117           0 :         pSDig->AddOffset2TrackID(fDigInput->GetMask(iFile));   // -> To be introduced for merging (since all inputs count tracks independently from 0)
     118           0 :         AliDebug(2, Form("Reading digit %03d of plane %02d (C)", iSDig, iPlane));
     119           0 :         new ((sDigits[iPlane])[sDigits[iPlane].GetEntries()]) AliMFTDigit(*pSDig);  
     120           0 :         AliDebug(2, Form("Reading digit %03d of plane %02d (D)", iSDig, iPlane));
     121             :       }
     122             :     }
     123             :     
     124           0 :     pInMFTLoader->UnloadSDigits();   
     125           0 :     pInMFT->ResetSDigits();
     126             : 
     127           0 :   }
     128             :   
     129           0 :   AliRunLoader *pOutRunLoader = AliRunLoader::GetRunLoader(fDigInput->GetOutputFolderName());  // open output stream (only 1 possible)
     130           0 :   AliLoader    *pOutMFTLoader = pOutRunLoader->GetLoader("MFTLoader");                        
     131           0 :   AliRun       *pAliRun       = pOutRunLoader->GetAliRun();
     132           0 :   AliMFT       *pOutMFT       = (AliMFT*) pAliRun->GetDetector("MFT");      
     133           0 :   pOutMFTLoader->MakeTree("D");   
     134           0 :   pOutMFT->MakeBranch("D");
     135           0 :   pOutMFT->SetTreeAddress();
     136             :   
     137           0 :   SDigits2Digits(sDigits, pOutMFT->GetDigitsList());   // here the sdigits are merged into digits
     138             :   
     139           0 :   pOutMFTLoader->TreeD()->Fill();              // fill the output tree with the list of digits
     140           0 :   pOutMFTLoader->WriteDigits("OVERWRITE");     // serialize them to file
     141             :   
     142           0 :   for (Int_t iPlane=0; iPlane<AliMFTConstants::kNDisks; iPlane++) sDigits[iPlane].Clear();   // remove all tmp sdigits
     143           0 :   pOutMFTLoader->UnloadDigits();   
     144           0 :   pOutMFT->ResetDigits(); 
     145             : 
     146           0 : }
     147             : 
     148             : //====================================================================================================================================================
     149             : 
     150             : void AliMFTDigitizer::SDigits2Digits(TClonesArray *pSDigitList, TObjArray *pDigitList) {   
     151           0 :   AliMFTGeometry *mftGeo = AliMFTGeometry::Instance();
     152             : 
     153           0 :   TClonesArray *myDigitList[AliMFTConstants::kNDisks] = {0};
     154             :  
     155           0 :   for (Int_t iPlane=0; iPlane<AliMFTConstants::kNDisks; iPlane++) {
     156           0 :     myDigitList[iPlane] = (TClonesArray*)(*pDigitList)[iPlane];
     157           0 :     if (myDigitList[iPlane]->GetEntries()!=0) AliErrorClass("Some of digits lists is not empty");   // in principle those lists should be empty 
     158             :   }
     159             :    
     160           0 :   AliDebug(1,"starting loop over planes");
     161             :    
     162           0 :   for (Int_t iPlane=0; iPlane<AliMFTConstants::kNDisks; iPlane++) {
     163             :      
     164             :     AliMFTDigit *newDig=NULL;
     165             :     AliMFTDigit *oldDig=NULL;
     166           0 :     pSDigitList[iPlane].Sort();
     167             : 
     168           0 :     const Int_t nDetElem = mftGeo->GetDiskNSensors(iPlane);
     169           0 :     TClonesArray *digitsPerDetElem[nDetElem];
     170             : 
     171           0 :     for (Int_t iDetElem=0; iDetElem<nDetElem; iDetElem++) digitsPerDetElem[iDetElem] = new TClonesArray("AliMFTDigit");
     172             : 
     173           0 :     AliDebug(1,"starting loop over sdigits to create digits");
     174           0 :     AliDebug(1, Form("MFT plane #%02d has %d SDigits", iPlane, Int_t(pSDigitList[iPlane].GetEntries())));
     175             : 
     176           0 :     for (Int_t iSDig=0; iSDig<pSDigitList[iPlane].GetEntries(); iSDig++) {
     177             : 
     178           0 :       newDig = (AliMFTDigit*) (pSDigitList[iPlane].At(iSDig));
     179           0 :       Int_t localDetElemID = mftGeo->GetDetElemLocalID(newDig->GetDetElemID());
     180           0 :       AliDebug(1,Form("Unique ID = %d Local ID = %d  max = %d",newDig->GetDetElemID(),localDetElemID,nDetElem));
     181             :       Bool_t digitExists = kFALSE;
     182           0 :       Int_t nDigits = digitsPerDetElem[localDetElemID]->GetEntries();
     183             :       
     184           0 :       for (Int_t iDig=0; iDig<nDigits; iDig++) {
     185           0 :         oldDig = (AliMFTDigit*) (digitsPerDetElem[localDetElemID]->At(iDig));
     186           0 :         if (newDig->GetDetElemID()==oldDig->GetDetElemID() &&
     187           0 :             newDig->GetPixelX()==oldDig->GetPixelX() &&
     188           0 :             newDig->GetPixelY()==oldDig->GetPixelY() &&
     189           0 :             newDig->GetPixelZ()==oldDig->GetPixelZ()) {
     190             :           digitExists = kTRUE;
     191           0 :           MergeDigits(oldDig, newDig);
     192           0 :           break;
     193             :         }
     194             :       }
     195             :       
     196           0 :       if (!digitExists) new ((*digitsPerDetElem[localDetElemID])[digitsPerDetElem[localDetElemID]->GetEntries()]) AliMFTDigit(*newDig);
     197             : 
     198             :     }
     199             : 
     200             :     // Now we merge the digit lists coming from each detection element, to have an ordered final list
     201             : 
     202           0 :     for (Int_t iDetElem=0; iDetElem<nDetElem; iDetElem++) {
     203           0 :       for (Int_t iSDig=0; iSDig<digitsPerDetElem[iDetElem]->GetEntries(); iSDig++) {
     204           0 :         newDig = (AliMFTDigit*) (digitsPerDetElem[iDetElem]->At(iSDig));
     205           0 :         new ((*myDigitList[iPlane])[myDigitList[iPlane]->GetEntries()]) AliMFTDigit(*newDig);
     206             :       }
     207             :     }
     208             : 
     209           0 :     for (Int_t iDetElem=0; iDetElem<nDetElem; iDetElem++) delete digitsPerDetElem[iDetElem];
     210             :     
     211           0 :     AliDebug(1, Form("MFT plane #%02d has %d Digits", iPlane, Int_t(myDigitList[iPlane]->GetEntries())));
     212             :     
     213             : //     for (Int_t iDigit=0; iDigit<myDigitList[iPlane]->GetEntries(); iDigit++) {
     214             : //       AliDebug(1, Form("Digit %03d of MFT plane %02d has pixel coordinates (%05d, %05d)", 
     215             : //                     iDigit, iPlane, ((AliMFTDigit*) myDigitList[iPlane]->At(iDigit))->GetPixelX(), ((AliMFTDigit*) myDigitList[iPlane]->At(iDigit))->GetPixelY()) );
     216             : //     }
     217             : 
     218           0 :     AliDebug(1, "ending loop over sdigits to create digits");
     219             : 
     220           0 :   }
     221             : 
     222           0 :   AliDebug(1,"ending loop over layers");  
     223             : 
     224           0 : }
     225             : 
     226             : //====================================================================================================================================================
     227             : 
     228             : void AliMFTDigitizer::MergeDigits(AliMFTDigit *mainDig, AliMFTDigit *digToSum) {
     229             :   
     230           0 :   mainDig -> SetEloss(mainDig->GetEloss() + digToSum->GetEloss());
     231             :   
     232             :   Bool_t trackExists = kFALSE;
     233           0 :   for (Int_t iTrack=0; iTrack<mainDig->GetNMCTracks(); iTrack++) {
     234           0 :     if (digToSum->GetMCLabel(0) == mainDig->GetMCLabel(iTrack)) {
     235             :       trackExists = kTRUE;
     236           0 :       break;
     237             :     }
     238             :   }
     239             :   
     240           0 :   if (!trackExists) mainDig->AddMCLabel(digToSum->GetMCLabel(0));
     241             :   
     242           0 : }
     243             : 
     244             : //====================================================================================================================================================
     245             : 

Generated by: LCOV version 1.11