LCOV - code coverage report
Current view: top level - ACORDE/ACORDEsim - AliACORDEDigitizer.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 77 123 62.6 %
Date: 2016-06-14 17:26:59 Functions: 10 14 71.4 %

          Line data    Source code
       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             :  **************************************************************************/
      15             : 
      16             : /* $Id$ */
      17             : 
      18             : ///_________________________________________________________________________
      19             : ///
      20             : /// This class constructs Digits out of Hits
      21             : ///
      22             : ///
      23             : 
      24             : // --- Standard library ---
      25             : 
      26             : // --- ROOT system ---
      27             : #include <TMath.h>
      28             : #include <TTree.h>
      29             : #include <TRandom.h>
      30             : 
      31             : // --- AliRoot header files ---
      32             : #include "AliRun.h"
      33             : #include "AliACORDE.h"
      34             : #include "AliACORDEhit.h"
      35             : #include "AliRunLoader.h"
      36             : #include "AliLoader.h"
      37             : #include "AliDigitizationInput.h"
      38             : #include "AliCDBManager.h"
      39             : #include "AliCDBStorage.h"
      40             : #include "AliCDBEntry.h"
      41             : #include "AliACORDECalibData.h"
      42             : #include "AliACORDEConstants.h"
      43             : 
      44             : #include "AliACORDEdigit.h"
      45             : #include "AliACORDEDigitizer.h"
      46             : 
      47          12 : ClassImp(AliACORDEDigitizer)
      48             : 
      49             : AliACORDEDigitizer::AliACORDEDigitizer()
      50           0 :   :AliDigitizer(),
      51           0 :    fCalibData(GetCalibData()),
      52           0 :    fNdigits(0),
      53           0 :    fDigits(0)
      54             :   
      55           0 : {
      56             :   // default constructor
      57           0 : }
      58             : 
      59             : AliACORDEDigitizer::AliACORDEDigitizer(AliDigitizationInput* digInput)
      60           1 :   :AliDigitizer(digInput),
      61           2 :    fCalibData(GetCalibData()),
      62           1 :    fNdigits(0),
      63           1 :    fDigits(0)
      64             : 
      65           5 : {
      66             :   // constructor
      67             : 
      68           2 : }
      69             : 
      70             : AliACORDEDigitizer::~AliACORDEDigitizer()
      71           6 : {
      72             :   // destructor
      73             :   
      74           1 :   if (fDigits) {
      75           1 :     fDigits->Delete();
      76           2 :     delete fDigits;
      77           1 :     fDigits=0;
      78           1 :   }
      79           3 : }
      80             : 
      81             : 
      82             : Bool_t AliACORDEDigitizer::Init()
      83             : {
      84             :   // Initialises the digitizer
      85             :   
      86             :   // Initialises the Digit array
      87           3 :   fDigits = new TClonesArray ("AliACORDEdigit", 1000);
      88             :   
      89           1 :   return kTRUE;
      90           0 : }
      91             : 
      92             : void AliACORDEDigitizer::Digitize(Option_t* /*option*/)
      93             : {
      94             : 
      95             :   // Creates digits from hits
      96             : 
      97             :   // 1.- create and initialize temporal variables
      98             :   // 2.- get loaders to access hots and digits
      99             :   // 3.- loop over all input. 
     100             :   //     3.1 for each input loop over all track
     101             :   //     3.2 for each track loop over all hits
     102             :   //     3.3 for each hit, check 
     103             :   //         if energy above threshold
     104             :   //         if survives efficiency
     105             :   //         then store the plastic, the time and track in temp arrays
     106             :   //         if a hit already survived for this plastic take the hit
     107             :   //         with the lowest time
     108             :   // 4.- loop over temporal array
     109             :   //     if both plastic have a surviving hit and the time
     110             :   //     difference is below the limit, add a new digit
     111             :   // 
     112             : 
     113             : 
     114             :   // 1.- temporal variables
     115           8 :   Float_t emin = AliACORDEConstants::Instance()->HitEnergyThreshold();
     116           4 :   Float_t td = AliACORDEConstants::Instance()->MaxHitTimeDifference();
     117           4 :   Int_t modules[60]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
     118           4 :   Int_t moduls[60]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; 
     119             :   Int_t mods;
     120           4 :   Float_t PlasticTimes[2][60]; 
     121           4 :   Int_t PlasticTracks[2][60];
     122         488 :   for (Int_t i=0;i<60;i++) {
     123         240 :     PlasticTimes[0][i]=-1.0;
     124         240 :     PlasticTimes[1][i]=-1.0;
     125         240 :     PlasticTracks[0][i]=-1;
     126         240 :     PlasticTracks[1][i]=-1;
     127             :   }
     128             : 
     129             :   // 2.- get loaders
     130             :   AliRunLoader* outRunLoader =
     131           4 :     AliRunLoader::GetRunLoader(fDigInput->GetOutputFolderName());
     132           4 :   if (!outRunLoader) {
     133           0 :     Error("Exec", "Can not get output Run Loader");
     134           0 :     return;}
     135             :   
     136           4 :   AliLoader* outLoader = outRunLoader->GetLoader("ACORDELoader");
     137           4 :   if (!outLoader) {
     138           0 :     Error("Exec", "Can not get output ACORDE Loader");
     139           0 :     return;}
     140             :   
     141           4 :   outLoader->LoadDigits("update");
     142           8 :   if (!outLoader->TreeD()) outLoader->MakeTree("D");
     143           4 :   outLoader->MakeDigitsContainer();
     144           4 :   TTree* treeD  = outLoader->TreeD();
     145             :   Int_t bufsize = 16000;
     146           4 :   treeD->Branch("ACORDEdigit", &fDigits, bufsize);
     147             :   
     148             :   // 3. loop over inputs
     149          16 :   for (Int_t iInput = 0; iInput < fDigInput->GetNinputs(); iInput++) {
     150             :     AliRunLoader* runLoader =
     151           4 :       AliRunLoader::GetRunLoader(fDigInput->GetInputFolderName(iInput));
     152           4 :     AliLoader* loader = runLoader->GetLoader("ACORDELoader");
     153           4 :     if (!loader) {
     154           0 :       Error("Exec", "Can not get ACORDE Loader for input %d", iInput);
     155           0 :       continue;}
     156             :     
     157           4 :     if (!runLoader->GetAliRun()) runLoader->LoadgAlice();
     158             :     
     159           4 :     AliACORDE* acorde = (AliACORDE*) runLoader->GetAliRun()->GetDetector("ACORDE");
     160           4 :     if (!acorde) {
     161           0 :       Error("Exec", "No ACORDE detector for input %d", iInput);
     162           0 :       continue;}
     163             :     
     164           4 :     loader->LoadHits();
     165           4 :     TTree* treeH = loader->TreeH();
     166           4 :     if (!treeH) {
     167           0 :       Error("Exec", "Cannot get TreeH for input %d", iInput);
     168           0 :       continue; }
     169             :     
     170           4 :     TClonesArray* hits = acorde->Hits();
     171             :     
     172             :     // 3.1 loop over all tracks
     173           4 :     Int_t nTracks = (Int_t) treeH->GetEntries();
     174         232 :     for (Int_t iTrack = 0; iTrack < nTracks; iTrack++) {
     175         112 :       acorde->ResetHits();
     176         112 :       treeH->GetEvent(iTrack);
     177         112 :       Int_t nHits = hits->GetEntriesFast();
     178             :       // 3.2 loop over hits
     179         224 :       for (Int_t iHit = 0; iHit < nHits; iHit++) {
     180           0 :         AliACORDEhit* hit = (AliACORDEhit *)hits->UncheckedAt(iHit);
     181             :         // 3.3 select hit
     182             :         // get hit info
     183           0 :         Float_t eloss_mev = hit->Eloss()*1000.0;
     184           0 :         Int_t module = hit->GetModule();
     185           0 :         modules[module]=1;
     186           0 :         Int_t plastic = hit->GetPlastic();
     187           0 :         Float_t time_ns = hit->GetTime()*1e9;
     188           0 :         Float_t eff = TMath::Sqrt(fCalibData->GetEfficiency(module));
     189             :         // if enough energy and efficiency
     190           0 :         if( eloss_mev > emin && gRandom->Uniform() < eff ) {
     191             :           // if first hit or earlier track
     192           0 :           if ((PlasticTimes[plastic-1][module-1] == -1.0) ||
     193           0 :               (PlasticTimes[plastic-1][module-1] > time_ns) ) {
     194           0 :             PlasticTimes[plastic-1][module-1]= time_ns;
     195           0 :             PlasticTracks[plastic-1][module-1]= hit->GetTrack();
     196           0 :           } 
     197             :         }
     198             :       } // end of hit   loop
     199             :     } // end of track loop
     200         488 :     for(Int_t i=0;i<60;i++){moduls[i]=modules[i];}
     201             :     
     202           4 :     loader->UnloadHits();
     203             :     
     204           4 :   }  // end of input loop
     205             : 
     206             :   // 4.- loop over temporal arrays to add hits
     207           4 :   Int_t tracks[3]={-1,-1,-1};
     208         488 :   for (Int_t i=0; i<60; i++) {
     209             :     // if both modules have a hit
     210             :     // if time diff small enough
     211         240 :     Float_t diff = TMath::Abs(PlasticTimes[0][i]-PlasticTimes[1][i]);
     212         240 :     if (diff < td) {
     213         240 :       tracks[0] = PlasticTracks[0][i];
     214         240 :       if (PlasticTracks[0][i] != PlasticTracks[1][i]) 
     215           0 :         tracks[1] = PlasticTracks[1][i];
     216         240 :       if(moduls[i]==1) {
     217             :         mods = i;
     218             :         //      Float_t module_time = (PlasticTimes[0][i] > PlasticTimes[1][i] ? 
     219             :         //                             PlasticTimes[0][i] : PlasticTimes[1][i]);
     220             :         //      AddDigit(tracks, mods, module_time);
     221           0 :         AddDigit(tracks, mods, 0);
     222           0 :       }
     223             :     }
     224             :   }
     225           4 :   treeD->Fill();
     226           4 :   outLoader->WriteDigits("OVERWRITE");
     227           4 :   outLoader->UnloadDigits();
     228           4 :   ResetDigit();
     229           8 : }
     230             : 
     231             : //____________________________________________________________________________
     232             : 
     233             : void AliACORDEDigitizer::AddDigit(Int_t* track, Int_t module, Float_t time)
     234             : {
     235             :   
     236             :   // Adds Digit
     237             :   
     238           0 :   TClonesArray &ldigits = *fDigits;
     239           0 :   new(ldigits[fNdigits++]) AliACORDEdigit(track,module,time);
     240           0 : }
     241             : 
     242             : void AliACORDEDigitizer::AddDigit(Int_t* modul,Float_t time)
     243             : {
     244             :         // MRC Adds Digit
     245           0 :   TClonesArray &ldigits = *fDigits;
     246           0 :   new(ldigits[fNdigits++]) AliACORDEdigit(modul,time);
     247             :   
     248             : 
     249           0 : }
     250             : void AliACORDEDigitizer::ResetDigit()
     251             : {
     252             : //
     253             : // Clears Digits
     254             : //
     255           8 :   fNdigits = 0;
     256           8 :   if (fDigits) fDigits->Delete();
     257           4 : }
     258             : 
     259             : 
     260             : AliACORDECalibData* AliACORDEDigitizer::GetCalibData() const
     261             : 
     262             : {
     263           2 :   AliCDBManager *man = AliCDBManager::Instance();
     264             : 
     265             :   AliCDBEntry *entry=0;
     266             : 
     267           2 :   entry = man->Get("ACORDE/Calib/Data");
     268             : 
     269           1 :   if(!entry){
     270           0 :     AliWarning("Load of calibration data from default storage failed!");
     271           0 :     AliWarning("Calibration data will be loaded from local storage ($ALICE_ROOT)");
     272           0 :     Int_t runNumber = man->GetRun();
     273           0 :     entry = man->GetStorage("local://$ALICE_ROOT/OCDB")
     274           0 :       ->Get("ACORDE/Calib/Data",runNumber);
     275             : 
     276           0 :   }
     277             : 
     278             :   // Retrieval of data in directory ACORDE/Calib/Data:
     279             : 
     280             : 
     281             :   AliACORDECalibData *calibdata = 0;
     282             : 
     283           2 :   if (entry) calibdata = (AliACORDECalibData*) entry->GetObject();
     284           1 :   if (!calibdata)  AliError("No calibration data from calibration database !");
     285             : 
     286             : 
     287           1 :   return calibdata;
     288             : 
     289           0 : }
     290             : 

Generated by: LCOV version 1.11