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