Separating run-dependent mapping data from data, which are not
[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>
19
60d3a1d3 20#include "AliMUONSDigitizerV2.h"
21
60d3a1d3 22#include "AliMUON.h"
23#include "AliMUONChamber.h"
445096c0 24#include "AliMUONVDigit.h"
60d3a1d3 25#include "AliMUONHit.h"
5ee595ac 26#include "AliMUONVDigitStore.h"
445096c0 27#include "AliMUONVHitStore.h"
7d7d22a6 28#include "AliMUONCalibrationData.h"
29#include "AliMUONResponseTrigger.h"
30
a55f49a0 31#include "AliMpCDB.h"
32#include "AliMpDEManager.h"
33
34#include "AliLog.h"
35#include "AliCDBManager.h"
36#include "AliLoader.h"
37#include "AliRun.h"
38#include "AliRunLoader.h"
39
3d1463c8 40//-----------------------------------------------------------------------------
ae6eeca4 41/// The sdigitizer performs the transformation from hits (energy deposits by
42/// the transport code) to sdigits (equivalent of charges on pad).
43///
44/// It does so by converting the energy deposit into a charge and then spreading
45/// this charge over several pads, according to the response function (a
46/// Mathieson distribution, basically).
47///
48/// See also AliMUONResponseV0, which is doing the real job (in DisIntegrate
49/// method), while this sdigitizer is just "steering" the process.
50///
51/// Please note that we do *not* merge sdigits after creation, which means
52/// that after sdigitization, a given pad can have several sdigits. This
53/// merging is taken care of later on by the digitizer(V3).
3d1463c8 54//-----------------------------------------------------------------------------
ae6eeca4 55
60d3a1d3 56ClassImp(AliMUONSDigitizerV2)
57
58//_____________________________________________________________________________
59AliMUONSDigitizerV2::AliMUONSDigitizerV2()
60: TTask("AliMUONSDigitizerV2","From Hits to SDigits for MUON")
61{
71a2d3aa 62 ///
63 /// ctor.
64 ///
a55f49a0 65
66 // Load mapping
67 if ( ! AliMpCDB::LoadMpSegmentation() ) {
88544f7e 68 AliFatal("Could not access mapping from OCDB !");
69 }
60d3a1d3 70}
71
72//_____________________________________________________________________________
73AliMUONSDigitizerV2::~AliMUONSDigitizerV2()
74{
71a2d3aa 75 ///
76 /// dtor.
77 ///
60d3a1d3 78}
79
80//_____________________________________________________________________________
81void
82AliMUONSDigitizerV2::Exec(Option_t*)
83{
71a2d3aa 84 ///
85 /// Go from hits to sdigits.
86 ///
87 /// In the code below, apart from the loop itself (which look complicated
88 /// but is really only a loop on each hit in the input file) the main
89 /// work is done in AliMUONResponse::DisIntegrate method, which converts
90 /// a single hit in (possibly) several sdigits.
91 ///
60d3a1d3 92
93 AliDebug(1,"");
94
95 AliRunLoader* runLoader = AliRunLoader::GetRunLoader();
445096c0 96 AliLoader* loader = runLoader->GetDetectorLoader("MUON");
60d3a1d3 97
445096c0 98 loader->LoadHits("READ");
60d3a1d3 99
60d3a1d3 100 AliMUON* muon = static_cast<AliMUON*>(gAlice->GetModule("MUON"));
7d7d22a6 101
102 AliMUONCalibrationData *calibrationData = 0x0;
103
104 if(muon->GetTriggerEffCells()){
105 Int_t runnumber = AliCDBManager::Instance()->GetRun();
106 calibrationData = new AliMUONCalibrationData(runnumber);
107 for (Int_t chamber = 10; chamber < 14; chamber++) {
108 ((AliMUONResponseTrigger *) (muon->Chamber(chamber).ResponseModel()))->InitTriggerEfficiency(calibrationData->TriggerEfficiency()); // Init trigger efficiency
109 }
110 }
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
123 AliInfo(Form("Will use digitStore of type %s",sDigitStore->ClassName()));
124
60d3a1d3 125 for ( Int_t iEvent = 0; iEvent < nofEvents; ++iEvent )
126 {
2c6e3e30 127 // Loop over events.
60d3a1d3 128 TObjArray tdlist;
129 tdlist.SetOwner(kTRUE);
130
131 AliDebug(1,Form("iEvent=%d",iEvent));
132 runLoader->GetEvent(iEvent);
445096c0 133
134 loader->MakeSDigitsContainer();
135
136 TTree* treeS = loader->TreeS();
137
60d3a1d3 138 if ( !treeS )
139 {
445096c0 140 AliFatal("");
60d3a1d3 141 }
445096c0 142
143 sDigitStore->Connect(*treeS);
144
145 TTree* treeH = loader->TreeH();
146
147 AliMUONVHitStore* hitStore = AliMUONVHitStore::Create(*treeH);
148 hitStore->Connect(*treeH);
60d3a1d3 149
60d3a1d3 150 Long64_t nofTracks = treeH->GetEntries();
445096c0 151
60d3a1d3 152 for ( Long64_t iTrack = 0; iTrack < nofTracks; ++iTrack )
153 {
2c6e3e30 154 // Loop over the tracks of this event.
60d3a1d3 155 treeH->GetEvent(iTrack);
445096c0 156
157 AliMUONHit* hit;
158 TIter next(hitStore->CreateIterator());
159 Int_t ihit(0);
160
161 while ( ( hit = static_cast<AliMUONHit*>(next()) ) )
60d3a1d3 162 {
60d3a1d3 163 Int_t chamberId = hit->Chamber()-1;
164 AliMUONChamber& chamber = muon->Chamber(chamberId);
165 AliMUONResponse* response = chamber.ResponseModel();
2c6e3e30 166
167 // This is the heart of this method : the dis-integration
168 TList digits;
60d3a1d3 169 response->DisIntegrate(*hit,digits);
2c6e3e30 170
bf0d3528 171 TIter nextd(&digits);
445096c0 172 AliMUONVDigit* d;
bf0d3528 173 while ( ( d = (AliMUONVDigit*)nextd() ) )
60d3a1d3 174 {
2c6e3e30 175 // Update some sdigit information that could not be known
176 // by the DisIntegrate method
60d3a1d3 177 d->SetHit(ihit);
445096c0 178 d->AddTrack(iTrack,d->Charge());
60d3a1d3 179 tdlist.Add(d);
180 }
445096c0 181 ++ihit;
60d3a1d3 182 }
445096c0 183 hitStore->Clear();
2c6e3e30 184 } // end of loop on tracks within an event
185
445096c0 186 TIter next(&tdlist);
187 AliMUONVDigit* d;
188
189 while ( ( d = static_cast<AliMUONVDigit*>(next()) ) )
60d3a1d3 190 {
445096c0 191 if ( d->Charge() > 0 ) // that check would be better in the disintegrate
60d3a1d3 192 // method, but to compare with old sdigitizer, it has to be there.
193 {
445096c0 194 AliMUONVDigit* added = sDigitStore->Add(*d,AliMUONVDigitStore::kMerge);
195 if (!added)
196 {
197 AliError("Could not add digit to digitStore");
198 }
60d3a1d3 199 }
200 }
445096c0 201
202 treeS->Fill();
203
204 loader->WriteSDigits("OVERWRITE");
205
206 sDigitStore->Clear();
207
208 loader->UnloadSDigits();
209
210 delete hitStore;
2c6e3e30 211
60d3a1d3 212 } // loop on events
213
445096c0 214 loader->UnloadHits();
215
216 delete sDigitStore;
7d7d22a6 217
218 if(calibrationData) delete calibrationData;
60d3a1d3 219}