]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONSDigitizerV2.cxx
Fix related to change of data member name in the base class.
[u/mrichter/AliRoot.git] / MUON / AliMUONSDigitizerV2.cxx
CommitLineData
60d3a1d3 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
7ca4655f 18#include <TClonesArray.h>
9da52a4f 19#include <TParticle.h>
c93255fe 20#include <TTree.h>
7ca4655f 21
60d3a1d3 22#include "AliMUONSDigitizerV2.h"
23
60d3a1d3 24#include "AliMUON.h"
25#include "AliMUONChamber.h"
445096c0 26#include "AliMUONVDigit.h"
60d3a1d3 27#include "AliMUONHit.h"
5ee595ac 28#include "AliMUONVDigitStore.h"
445096c0 29#include "AliMUONVHitStore.h"
7d7d22a6 30#include "AliMUONResponseTrigger.h"
2a5f75ae 31#include "AliMUONConstants.h"
7d7d22a6 32
a55f49a0 33#include "AliMpCDB.h"
34#include "AliMpDEManager.h"
35
36#include "AliLog.h"
37#include "AliCDBManager.h"
38#include "AliLoader.h"
39#include "AliRun.h"
40#include "AliRunLoader.h"
e41d0a3c 41
42#include "AliHeader.h"
43#include "AliGenCocktailEventHeader.h"
a55f49a0 44
3d1463c8 45//-----------------------------------------------------------------------------
ae6eeca4 46/// The sdigitizer performs the transformation from hits (energy deposits by
47/// the transport code) to sdigits (equivalent of charges on pad).
48///
49/// It does so by converting the energy deposit into a charge and then spreading
50/// this charge over several pads, according to the response function (a
51/// Mathieson distribution, basically).
52///
53/// See also AliMUONResponseV0, which is doing the real job (in DisIntegrate
54/// method), while this sdigitizer is just "steering" the process.
55///
56/// Please note that we do *not* merge sdigits after creation, which means
57/// that after sdigitization, a given pad can have several sdigits. This
58/// merging is taken care of later on by the digitizer(V3).
3d1463c8 59//-----------------------------------------------------------------------------
ae6eeca4 60
60d3a1d3 61ClassImp(AliMUONSDigitizerV2)
62
2a5f75ae 63Float_t AliMUONSDigitizerV2::fgkMaxIntTime = 10.0;
64Float_t AliMUONSDigitizerV2::fgkMaxPosTimeDif = 1.22E-6;
65Float_t AliMUONSDigitizerV2::fgkMaxNegTimeDif = -3.5E-6;
66Float_t AliMUONSDigitizerV2::fgkMinTimeDif = 25E-9;
67
60d3a1d3 68//_____________________________________________________________________________
69AliMUONSDigitizerV2::AliMUONSDigitizerV2()
f21fc003 70: TNamed("AliMUONSDigitizerV2","From Hits to SDigits for MUON")
60d3a1d3 71{
71a2d3aa 72 ///
73 /// ctor.
74 ///
a55f49a0 75
76 // Load mapping
77 if ( ! AliMpCDB::LoadMpSegmentation() ) {
88544f7e 78 AliFatal("Could not access mapping from OCDB !");
79 }
60d3a1d3 80}
81
82//_____________________________________________________________________________
83AliMUONSDigitizerV2::~AliMUONSDigitizerV2()
84{
71a2d3aa 85 ///
86 /// dtor.
87 ///
60d3a1d3 88}
89
90//_____________________________________________________________________________
91void
f21fc003 92AliMUONSDigitizerV2::Digitize(Option_t*)
60d3a1d3 93{
71a2d3aa 94 ///
95 /// Go from hits to sdigits.
96 ///
97 /// In the code below, apart from the loop itself (which look complicated
98 /// but is really only a loop on each hit in the input file) the main
99 /// work is done in AliMUONResponse::DisIntegrate method, which converts
100 /// a single hit in (possibly) several sdigits.
101 ///
60d3a1d3 102
103 AliDebug(1,"");
104
33c3c91a 105 AliRunLoader* runLoader = AliRunLoader::Instance();
445096c0 106 AliLoader* loader = runLoader->GetDetectorLoader("MUON");
60d3a1d3 107
445096c0 108 loader->LoadHits("READ");
60d3a1d3 109
60d3a1d3 110 AliMUON* muon = static_cast<AliMUON*>(gAlice->GetModule("MUON"));
7d7d22a6 111
ae6eeca4 112 Int_t nofEvents(runLoader->GetNumberOfEvents());
445096c0 113
5ee595ac 114 TString classname = muon->DigitStoreClassName();
445096c0 115
5ee595ac 116 AliMUONVDigitStore* sDigitStore = AliMUONVDigitStore::Create(classname.Data());
117
118 if (!sDigitStore)
119 {
120 AliFatal(Form("Could not create digitstore of class %s",classname.Data()));
121 }
122
68cf1410 123 AliDebug(1,Form("Will use digitStore of type %s",sDigitStore->ClassName()));
5ee595ac 124
2a5f75ae 125 // average arrival time to chambers, for pileup studies
126
60d3a1d3 127 for ( Int_t iEvent = 0; iEvent < nofEvents; ++iEvent )
128 {
2c6e3e30 129 // Loop over events.
60d3a1d3 130 TObjArray tdlist;
131 tdlist.SetOwner(kTRUE);
132
133 AliDebug(1,Form("iEvent=%d",iEvent));
134 runLoader->GetEvent(iEvent);
445096c0 135
9da52a4f 136 // for pile up studies
9ee1d6ff 137 float t0=fgkMaxIntTime; int aa=0;
e41d0a3c 138 AliHeader* header = runLoader->GetHeader();
139 AliGenCocktailEventHeader* cocktailHeader =
140 dynamic_cast<AliGenCocktailEventHeader*>(header->GenEventHeader());
141 if (cocktailHeader) {
142 AliGenCocktailEventHeader* genEventHeader = (AliGenCocktailEventHeader*) (header->GenEventHeader());
143 TList* headers = genEventHeader->GetHeaders();
144 TIter nextH(headers);
145 AliGenEventHeader *entry;
146 while((entry = (AliGenEventHeader*)nextH())) {
147 float t = entry->InteractionTime();
9ee1d6ff 148 if (TMath::Abs(t)<TMath::Abs(t0)) t0 = t;
149 aa++;
e41d0a3c 150 }
151 } else {
152 AliGenEventHeader* evtHeader =
153 (AliGenEventHeader*)(header->GenEventHeader());
154 float t = evtHeader->InteractionTime();
9ee1d6ff 155 if (TMath::Abs(t)<TMath::Abs(t0)) t0 = t;
156 aa++;
9da52a4f 157 }
158
445096c0 159 loader->MakeSDigitsContainer();
160
161 TTree* treeS = loader->TreeS();
162
60d3a1d3 163 if ( !treeS )
164 {
445096c0 165 AliFatal("");
60d3a1d3 166 }
445096c0 167
168 sDigitStore->Connect(*treeS);
169
170 TTree* treeH = loader->TreeH();
171
172 AliMUONVHitStore* hitStore = AliMUONVHitStore::Create(*treeH);
173 hitStore->Connect(*treeH);
60d3a1d3 174
60d3a1d3 175 Long64_t nofTracks = treeH->GetEntries();
445096c0 176
60d3a1d3 177 for ( Long64_t iTrack = 0; iTrack < nofTracks; ++iTrack )
178 {
2c6e3e30 179 // Loop over the tracks of this event.
60d3a1d3 180 treeH->GetEvent(iTrack);
445096c0 181
182 AliMUONHit* hit;
183 TIter next(hitStore->CreateIterator());
184 Int_t ihit(0);
185
186 while ( ( hit = static_cast<AliMUONHit*>(next()) ) )
60d3a1d3 187 {
2a5f75ae 188 Int_t chamberId = hit->Chamber()-1;
9ee1d6ff 189 Float_t age = hit->Age()-t0;
ea232c10 190
60d3a1d3 191 AliMUONChamber& chamber = muon->Chamber(chamberId);
192 AliMUONResponse* response = chamber.ResponseModel();
2c6e3e30 193
194 // This is the heart of this method : the dis-integration
195 TList digits;
9ee1d6ff 196 if (aa>1){ // if there are pileup events
2a5f75ae 197 Float_t chamberTime = AliMUONConstants::AverageChamberT(chamberId);
198 Float_t timeDif=age-chamberTime;
199 if (timeDif>fgkMaxPosTimeDif || timeDif<fgkMaxNegTimeDif) {
200 continue;
201 }
202 if(TMath::Abs(timeDif)>fgkMinTimeDif){
203 response->DisIntegrate(*hit,digits,timeDif);
204 }
205 else{
206 response->DisIntegrate(*hit,digits,0.);
207 }
208 }
209 else{
210 response->DisIntegrate(*hit,digits,0.);
211 }
2c6e3e30 212
bf0d3528 213 TIter nextd(&digits);
445096c0 214 AliMUONVDigit* d;
bf0d3528 215 while ( ( d = (AliMUONVDigit*)nextd() ) )
60d3a1d3 216 {
2c6e3e30 217 // Update some sdigit information that could not be known
218 // by the DisIntegrate method
60d3a1d3 219 d->SetHit(ihit);
ea232c10 220 d->SetTime(age);
2e2d0c44 221 d->AddTrack(hit->GetTrack(),d->Charge());
60d3a1d3 222 tdlist.Add(d);
223 }
445096c0 224 ++ihit;
60d3a1d3 225 }
445096c0 226 hitStore->Clear();
2c6e3e30 227 } // end of loop on tracks within an event
228
445096c0 229 TIter next(&tdlist);
230 AliMUONVDigit* d;
231
232 while ( ( d = static_cast<AliMUONVDigit*>(next()) ) )
60d3a1d3 233 {
05315e71 234 d->ChargeInFC(kTRUE);
235
236 AliMUONVDigit* added = sDigitStore->Add(*d,AliMUONVDigitStore::kMerge);
237 if (!added)
60d3a1d3 238 {
05315e71 239 AliError("Could not add digit to digitStore");
60d3a1d3 240 }
241 }
05315e71 242
445096c0 243 treeS->Fill();
244
245 loader->WriteSDigits("OVERWRITE");
246
247 sDigitStore->Clear();
248
249 loader->UnloadSDigits();
250
251 delete hitStore;
2c6e3e30 252
60d3a1d3 253 } // loop on events
254
445096c0 255 loader->UnloadHits();
256
257 delete sDigitStore;
7d7d22a6 258
60d3a1d3 259}