]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ITS/ITSsim/AliITS.cxx
FindDATE + ITS module
[u/mrichter/AliRoot.git] / ITS / ITSsim / AliITS.cxx
CommitLineData
4c039060 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
88cb7938 16/* $Id$ */
2ab0c725 17
4c039060 18
fe4da5cc 19///////////////////////////////////////////////////////////////////////////////
04366a57 20// //
21// An overview of the basic philosophy of the ITS code development //
22// and analysis is show in the figure below. //
23//Begin_Html //
24/*
a92b2b7d 25<img src="picts/ITS/ITS_Analysis_schema.gif">
fe4da5cc 26</pre>
27<br clear=left>
28<font size=+2 color=red>
58005f18 29<p>Roberto Barbera is in charge of the ITS Offline code (1999).
fe4da5cc 30<a href="mailto:roberto.barbera@ct.infn.it">Roberto Barbera</a>.
31</font>
32<pre>
33*/
34//End_Html
58005f18 35//
36// AliITS. Inner Traking System base class.
37// This class contains the base procedures for the Inner Tracking System
38//
39//Begin_Html
40/*
a92b2b7d 41<img src="picts/ITS/AliITS_Class_Diagram.gif">
58005f18 42</pre>
43<br clear=left>
44<font size=+2 color=red>
45<p>This show the class diagram of the different elements that are part of
46the AliITS class.
47</font>
48<pre>
49*/
50//End_Html
51//
52// Version: 0
53// Written by Rene Brun, Federico Carminati, and Roberto Barbera
54//
55// Version: 1
56// Modified and documented by Bjorn S. Nilsen
57// July 11 1999
58//
3bd79107 59// Version: 2
60// Modified and documented by A. Bologna
61// October 18 1999
62//
58005f18 63// AliITS is the general base class for the ITS. Also see AliDetector for
64// futher information.
65//
fe4da5cc 66///////////////////////////////////////////////////////////////////////////////
88cb7938 67
143d1056 68#include <stdlib.h>
caf37aec 69#include <TClonesArray.h>
9c74c52b 70#include <TFile.h>
7d62fb64 71#include <TParticle.h>
d5da1ecf 72#include <TString.h>
88cb7938 73#include <TTree.h>
88cb7938 74#include <TVirtualMC.h>
6c8e94cf 75#include <TArrayI.h>
7d62fb64 76#include "AliDetector.h"
3bd79107 77#include "AliITS.h"
7d62fb64 78#include "AliITSDetTypeSim.h"
f77f13c8 79#include "AliITSDDLRawData.h"
88cb7938 80#include "AliITSLoader.h"
88cb7938 81#include "AliITShit.h"
82#include "AliITSmodule.h"
7d62fb64 83#include "AliITSpListItem.h"
84#include "AliITSsimulation.h"
85#include "AliITSsimulationFastPoints.h"
5d12ce38 86#include "AliMC.h"
679379e8 87#include "AliITSDigitizer.h"
7d62fb64 88#include "AliITSRecPoint.h"
0b5bf101 89#include "AliITSsegmentationSPD.h"
90#include "AliITSsegmentationSDD.h"
dee45d79 91#include "AliITSsimulationSDD.h"
92#include "AliITSCalibrationSDD.h"
8b3448d3 93#include "AliITSCalibrationSSD.h"
0b5bf101 94#include "AliITSsegmentationSSD.h"
95#include "AliITSRawStreamSPD.h"
96#include "AliITSRawStreamSSD.h"
97#include "AliITSRawStreamSDD.h"
0b5bf101 98#include "AliRawReader.h"
f77f13c8 99#include "AliRun.h"
7d62fb64 100#include "AliLog.h"
ef7ff1f9 101#include "AliITSInitGeometry.h"
ad7f2bfa 102#include "AliITSFOSignalsSPD.h"
828e06c7 103
3bd79107 104ClassImp(AliITS)
3bd79107 105
2aea926d 106//______________________________________________________________________
ed9289c8 107AliITS::AliITS() : AliDetector(),
108fDetTypeSim(0),
109fEuclidOut(0),
110fOpt("All"),
111fIdN(0),
112fIdSens(0),
113fIdName(0),
012f0f4c 114fITSmodules(0),
c8af5b8f 115fTiming(kFALSE),
afbc83e9 116fSimuParam(0),
117fModA(0),
118fpSDigits(0)
ed9289c8 119{
7d62fb64 120 // Default initializer for ITS
121 // The default constructor of the AliITS class. In addition to
122 // creating the AliITS class it zeros the variables fIshunt (a member
123 // of AliDetector class), fEuclidOut, and fIdN, and zeros the pointers
124 // fIdSens, and fIdName. The AliDetector default constructor
125 // is also called.
126
aa044888 127// SetDetectors(); // default to fOpt="All". This variable not written out.
e939a978 128//PH SetMarkerColor(kRed);
65dc605a 129 for (int i=fgkNTYPES;i--;) fkRawID2ClusID[i] = 0;
fe4da5cc 130}
2aea926d 131//______________________________________________________________________
c8af5b8f 132AliITS::AliITS(const Char_t *title):
133 AliDetector("ITS",title),
134 fDetTypeSim(0),
135 fEuclidOut(0),
136 fOpt("All"),
137 fIdN(0),
138 fIdSens(0),
139 fIdName(0),
140 fITSmodules(0),
141 fTiming(kFALSE),
afbc83e9 142 fSimuParam(0),
143 fModA(0),
144 fpSDigits(0)
012f0f4c 145{
146 // The standard Constructor for the ITS class.
147 // It also zeros the variables
148 // fIshunt (a member of AliDetector class), fEuclidOut, and zeros
149 // the pointers fIdSens and fIdName. To help in displaying hits via the
150 // ROOT macro display.C AliITS also sets the marker color to red. The
151 // variables passes with this constructor, const char *name and *title,
152 // are used by the constructor of AliDetector class. See AliDetector
153 // class for a description of these parameters and its constructor
154 // functions.
155 // Inputs:
156 // Char_t *title Simulation title for the ITS
157 // Outputs:
158 // none.
159 // Return:
160 // none.
161
162 fHits = new TClonesArray("AliITShit",1560); // from AliDetector
163 if(gAlice->GetMCApp()) gAlice->GetMCApp()->AddHitList(fHits);
164 //fNhits=0; //done in AliDetector(name,title)
165 SetDetectors(); // default to fOpt="All". This variable not written out.
166 fDetTypeSim = new AliITSDetTypeSim();
167 //PH SetMarkerColor(kRed);
168 if(!fLoader) MakeLoader(AliConfig::GetDefaultEventFolderName());
169 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
65dc605a 170 for (int i=fgkNTYPES;i--;) fkRawID2ClusID[i] = 0;
012f0f4c 171}
172//______________________________________________________________________
c8af5b8f 173AliITS::AliITS(const char *name, const char *title):
174 AliDetector(name,title),
175 fDetTypeSim(0),
176 fEuclidOut(0),
177 fOpt("All"),
178 fIdN(0),
179 fIdSens(0),
180 fIdName(0),
181 fITSmodules(0),
182 fTiming(kFALSE),
afbc83e9 183 fSimuParam(0),
184 fModA(0),
185 fpSDigits(0)
ed9289c8 186{
7d62fb64 187 // The standard Constructor for the ITS class.
188 // It also zeros the variables
189 // fIshunt (a member of AliDetector class), fEuclidOut, and zeros
190 // the pointers fIdSens and fIdName. To help in displaying hits via the
191 // ROOT macro display.C AliITS also sets the marker color to red. The
192 // variables passes with this constructor, const char *name and *title,
193 // are used by the constructor of AliDetector class. See AliDetector
194 // class for a description of these parameters and its constructor
195 // functions.
196
7d62fb64 197 fHits = new TClonesArray("AliITShit",1560);
198 if(gAlice->GetMCApp()) gAlice->GetMCApp()->AddHitList(fHits);
ed9289c8 199 //fNhits=0; //done in AliDetector(name,title)
7d62fb64 200
7d62fb64 201 SetDetectors(); // default to fOpt="All". This variable not written out.
ed9289c8 202
7d62fb64 203 fDetTypeSim = new AliITSDetTypeSim();
e939a978 204 //PH SetMarkerColor(kRed);
023ae34b 205 if(!fLoader) MakeLoader(AliConfig::GetDefaultEventFolderName());
206 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
65dc605a 207 for (int i=fgkNTYPES;i--;) fkRawID2ClusID[i] = 0;
3bd79107 208}
2aea926d 209//______________________________________________________________________
58005f18 210AliITS::~AliITS(){
4a5bebc2 211 // Default destructor for ITS.
2aea926d 212 // The default destructor of the AliITS class. In addition to deleting
7d62fb64 213 // the AliITS class it deletes the memory pointed to by
214 // fIdSens, fIdName, fDetTypeSim and it's contents.
4a5bebc2 215 // Inputs:
216 // none.
217 // Outputs:
218 // none.
219 // Return:
220 // none.
023ae34b 221
88cb7938 222 if (fHits) {
223 fHits->Delete();
224 delete fHits;
225 fHits=0;
226 }
88cb7938 227 if(fITSmodules) {
228 this->ClearModules();
229 delete fITSmodules;
279a35d7 230 fITSmodules = 0;
88cb7938 231 }// end if fITSmodules!=0
232
7d62fb64 233 delete[] fIdName; // Array of TStrings
234 delete[] fIdSens;
773af0c4 235 Int_t size = AliITSgeomTGeo::GetNModules();
7d62fb64 236 if (fDetTypeSim){
237 delete fDetTypeSim;
238 fDetTypeSim = 0;
c8af5b8f 239 }
240 if(fSimuParam){
241 delete fSimuParam;
242 fSimuParam=0;
243 }
afbc83e9 244 if(fModA){
245 if(size>0){
246 for(Int_t j=0; j<size; j++){
247 fModA[j]->Delete();
248 delete fModA[j];
249 }
250 }
251 delete []fModA;
252 }
253 if(fpSDigits){
254 fpSDigits->Delete();
255 delete fpSDigits;
256 }
3bd79107 257}
3bd79107 258
679379e8 259//______________________________________________________________________
f21fc003 260AliDigitizer* AliITS::CreateDigitizer(AliDigitizationInput* digInput)const{
679379e8 261 // Creates the AliITSDigitizer in a standard way for use via AliModule.
262 // This function can not be included in the .h file because of problems
263 // with the order of inclusion (recursive).
264 // Inputs:
f21fc003 265 // AliDigitizationInput* digInput The Manger class for Digitization
679379e8 266 // Output:
267 // none.
268 // Return:
269 // A new AliITSRunDigitizer (cast as a AliDigitizer).
270
f21fc003 271 return new AliITSDigitizer(digInput);
679379e8 272}
2aea926d 273//______________________________________________________________________
274void AliITS::Init(){
4a5bebc2 275 // Initializer ITS after it has been built
2aea926d 276 // This routine initializes the AliITS class. It is intended to be
277 // called from the Init function in AliITSv?. Besides displaying a banner
278 // indicating that it has been called it initializes the array fIdSens
279 // and sets the default segmentation, response, digit and raw cluster
280 // classes therefore it should be called after a call to CreateGeometry.
4a5bebc2 281 // Inputs:
282 // none.
283 // Outputs:
284 // none.
285 // Return:
286 // none.
3bd79107 287 Int_t i;
2aea926d 288 // Array of TStrings
2942f542 289 if(TVirtualMC::GetMC()) for(i=0;i<fIdN;i++) fIdSens[i] = TVirtualMC::GetMC()->VolId(fIdName[i]);
7d62fb64 290
7d62fb64 291}
2aea926d 292//______________________________________________________________________
293void AliITS::SetDefaults(){
4a5bebc2 294 // sets the default segmentation, response, digit and raw cluster classes.
295 // Inputs:
296 // none.
297 // Outputs:
298 // none.
299 // Return:
300 // none.
023ae34b 301 AliInfoClass("AliITS::Setting Defaults");
7d62fb64 302 if(!fDetTypeSim) {
303 Error("SetDefaults()","fDetTypeSim is 0!");
304 return;
305 }
306
307 fDetTypeSim->SetDefaults();
c8af5b8f 308 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
7d62fb64 309
3bd79107 310}
2aea926d 311//______________________________________________________________________
312void AliITS::SetDefaultSimulation(){
4a5bebc2 313 // sets the default simulation.
314 // Inputs:
315 // none.
316 // Outputs:
317 // none.
318 // Return:
319 // none.
7d62fb64 320 if(!fDetTypeSim) {
321 Error("SetDefaultSimulation()","fDetTypeSim is 0!");
322 return;
323 }
324
325 fDetTypeSim->SetDefaultSimulation();
c8af5b8f 326 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
04366a57 327
04366a57 328}
329
330
2aea926d 331//______________________________________________________________________
88cb7938 332void AliITS::MakeBranch(Option_t* option){
2aea926d 333 // Creates Tree branches for the ITS.
4a5bebc2 334 // Inputs:
335 // Option_t *option String of Tree types S,D, and/or R.
336 // const char *file String of the file name where these branches
337 // are to be stored. If blank then these branches
338 // are written to the same tree as the Hits were
339 // read from.
340 // Outputs:
341 // none.
342 // Return:
343 // none.
7d62fb64 344 if(!fDetTypeSim) {
345 Error("MakeBranch","fDetTypeSim is 0!");
346 return;
347 }
04366a57 348
7d62fb64 349 Bool_t cH = (strstr(option,"H")!=0);
350 Bool_t cS = (strstr(option,"S")!=0);
351 Bool_t cD = (strstr(option,"D")!=0);
352
353 if(cH && (fHits == 0x0)) fHits = new TClonesArray("AliITShit", 1560);
354 AliDetector::MakeBranch(option);
355
356 if(cS) MakeBranchS(0);
357 if(cD) MakeBranchD(0);
358
359
360}
361//___________________________________________________________________
362void AliITS::MakeBranchS(const char* fl){
363
364 // Creates Tree Branch for the ITS summable digits.
365 // Inputs:
366 // cont char *fl File name where SDigits branch is to be written
367 // to. If blank it write the SDigits to the same
368 // file in which the Hits were found.
369
370
371 if(!fDetTypeSim){
372 Error("MakeBranchS","fDetTypeSim is 0!");
373 }
374 Int_t buffersize = 4000;
0f812aa0 375 char branchname[31];
7d62fb64 376
377 // only one branch for SDigits.
0f812aa0 378 snprintf(branchname,30,"%s",GetName());
7d62fb64 379
380 if(fLoader->TreeS()){
7d62fb64 381 TClonesArray* sdig = (TClonesArray*)fDetTypeSim->GetSDigits();
382 MakeBranchInTree(fLoader->TreeS(),branchname,&sdig,buffersize,fl);
383 }
384}
385//______________________________________________________________________
386void AliITS::MakeBranchD(const char* file){
387
388 //Make branch for digits
389 if(!fDetTypeSim) {
390 Warning("MakeBranchD","fDetTypeSim is 0!");
391 return;
392 }
023ae34b 393 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
c8af5b8f 394 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
7d62fb64 395 MakeBranchInTreeD(fLoader->TreeD(),file);
396}
397
398//___________________________________________________________________
399void AliITS:: MakeBranchInTreeD(TTree* treeD, const char* file){
400 // Creates Tree branches for the ITS.
401
402 if(!fDetTypeSim){
403 Error("MakeBranchS","fDetTypeSim is 0!");
404 }
023ae34b 405 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
c8af5b8f 406 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
7d62fb64 407
408 const Char_t *det[3] = {"SPD","SDD","SSD"};
a6e0ebfe 409 const Char_t* digclass;
7d62fb64 410 Int_t buffersize = 4000;
0f812aa0 411 Char_t branchname[31];
7d62fb64 412
413 if(!fDetTypeSim->GetDigits()){
414 fDetTypeSim->SetDigits(new TObjArray(fgkNTYPES));
415 }
416 for(Int_t i=0;i<fgkNTYPES;i++){
417 digclass = fDetTypeSim->GetDigitClassName(i);
418 TString classn = digclass;
419 if(!((fDetTypeSim->GetDigits())->At(i))){
420 (fDetTypeSim->GetDigits())->AddAt(new TClonesArray(classn.Data(),1000),i);
421 }
422 else ResetDigits(i);
0f812aa0 423 if(fgkNTYPES==3) snprintf(branchname,30,"%sDigits%s",GetName(),det[i]);
7d62fb64 424 else sprintf(branchname,"%sDigits%d",GetName(),i+1);
425 TObjArray* dig = DigitsAddress(i);
426 if(GetDigits() && treeD) AliDetector::MakeBranchInTree(treeD,branchname, &dig,buffersize,file);
427 }
2aea926d 428
fe4da5cc 429}
2aea926d 430//______________________________________________________________________
431void AliITS::SetTreeAddress(){
432 // Set branch address for the Trees.
4a5bebc2 433 // Inputs:
434 // none.
435 // Outputs:
436 // none.
437 // Return:
438 // none.
023ae34b 439
7d62fb64 440 if(!fDetTypeSim) {
441 Error("SetTreeAddress","fDetTypeSim is 0!");
442 return;
443 }
444
023ae34b 445 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
c8af5b8f 446 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
7d62fb64 447
448 TTree *treeS = fLoader->TreeS();
449 TTree *treeD = fLoader->TreeD();
450 if (fLoader->TreeH() && (fHits == 0x0)) {
451 fHits = new TClonesArray("AliITShit", 1560);
452 }
453 AliDetector::SetTreeAddress();
454
455 fDetTypeSim->SetTreeAddressS(treeS, (Char_t*)GetName());
456 fDetTypeSim->SetTreeAddressD(treeD, (Char_t*)GetName());
fe4da5cc 457}
2aea926d 458//______________________________________________________________________
2aea926d 459void AliITS::AddHit(Int_t track, Int_t *vol, Float_t *hits){
460 // Add an ITS hit
461 // The function to add information to the AliITShit class. See the
462 // AliITShit class for a full description. This function allocates the
463 // necessary new space for the hit information and passes the variable
464 // track, and the pointers *vol and *hits to the AliITShit constructor
465 // function.
4a5bebc2 466 // Inputs:
467 // Int_t track Track number which produced this hit.
468 // Int_t *vol Array of Integer Hit information. See AliITShit.h
469 // Float_t *hits Array of Floating Hit information. see AliITShit.h
470 // Outputs:
471 // none.
472 // Return:
473 // none.
7d62fb64 474 TClonesArray &lhits = *fHits;
475 new(lhits[fNhits++]) AliITShit(fIshunt,track,vol,hits);
3bd79107 476}
9c74c52b 477
2aea926d 478//______________________________________________________________________
755bb5cb 479void AliITS::FillModules(Int_t /* evnt */,Int_t bgrev,Int_t /* nmodules */,
8e8eae84 480 Option_t *option, const char *filename){
7d62fb64 481 // fill the modules with the sorted by module hits; add hits from
482 // background if option=Add.
483
484 static TTree *trH1; //Tree with background hits
485 static Bool_t first=kTRUE;
486 static TFile *file;
487 const char *addBgr = strstr(option,"Add");
488
7d62fb64 489 if (addBgr ) {
490 if(first) {
491 file=new TFile(filename);
492 } // end if first
493 first=kFALSE;
494 file->cd();
495 file->ls();
496 // Get Hits Tree header from file
497 if(trH1) delete trH1;
498 trH1=0;
499
0f812aa0 500 char treeName[21];
501 snprintf(treeName,20,"TreeH%d",bgrev);
7d62fb64 502 trH1 = (TTree*)gDirectory->Get(treeName);
503 if (!trH1) {
504 Error("FillModules","cannot find Hits Tree for event:%d",bgrev);
505 } // end if !trH1
506 // Set branch addresses
507 } // end if addBgr
508
509 FillModules(fLoader->TreeH(),0); // fill from this file's tree.
3bd79107 510
7d62fb64 511 if (addBgr ) {
512 FillModules(trH1,10000000); // Default mask 10M.
513 TTree *fAli=fLoader->GetRunLoader()->TreeK();
514 TFile *fileAli=0;
0f812aa0 515 if (fAli) {
516 fileAli =fAli->GetCurrentFile();
517 fileAli->cd();
518 }
7d62fb64 519 } // end if add
520
521
3bd79107 522}
2aea926d 523//______________________________________________________________________
b4012daf 524void AliITS::FillModules(TTree *treeH, Int_t mask) {
525 // fill the modules with the sorted by module hits;
526 // can be called many times to do a merging
527 // Inputs:
528 // TTree *treeH The tree containing the hits to be copied into
529 // the modules.
530 // Int_t mask The track number mask to indecate which file
531 // this hits came from.
532 // Outputs:
533 // none.
534 // Return:
535 // none.
536
88cb7938 537 if (treeH == 0x0)
538 {
0f812aa0 539 AliError("Tree H is NULL");
540 return;
88cb7938 541 }
b4012daf 542 Int_t lay,lad,det,index;
543 AliITShit *itsHit=0;
544 AliITSmodule *mod=0;
0f812aa0 545 char branchname[21];
546 snprintf(branchname,20,"%s",GetName());
b4012daf 547 TBranch *branch = treeH->GetBranch(branchname);
548 if (!branch) {
88cb7938 549 Error("FillModules","%s branch in TreeH not found",branchname);
550 return;
b4012daf 551 } // end if !branch
552 branch->SetAddress(&fHits);
553 Int_t nTracks =(Int_t) treeH->GetEntries();
554 Int_t iPrimTrack,h;
555 for(iPrimTrack=0; iPrimTrack<nTracks; iPrimTrack++){
88cb7938 556 ResetHits();
557 Int_t nBytes = treeH->GetEvent(iPrimTrack);
558 if (nBytes <= 0) continue;
559 Int_t nHits = fHits->GetEntriesFast();
560 for(h=0; h<nHits; h++){
561 itsHit = (AliITShit *)fHits->UncheckedAt(h);
562 itsHit->GetDetectorID(lay,lad,det);
7d62fb64 563 if (GetITSgeom()) {
564 index = GetITSgeom()->GetModuleIndex(lay,lad,det);
88cb7938 565 } else {
566 index=det-1; // This should not be used.
567 } // end if [You must have fITSgeom for this to work!]
568 mod = GetModule(index);
569 itsHit->SetTrack(itsHit->GetTrack()+mask); // Set track mask.
570 mod->AddHit(itsHit,iPrimTrack,h);
571 } // end loop over hits
b4012daf 572 } // end loop over tracks
573}
7d62fb64 574
b4012daf 575//______________________________________________________________________
6f5308d9 576Bool_t AliITS::InitModules(Int_t size,Int_t &nmodules){
7d62fb64 577 // Initialize the modules array.
4a5bebc2 578 // Inputs:
7d62fb64 579 // Int_t size Size of array of the number of modules to be
580 // created. If size <=0 then the number of modules
581 // is gotten from AliITSgeom class kept in fITSgeom.
4a5bebc2 582 // Outputs:
7d62fb64 583 // Int_t &nmodules The number of modules existing.
4a5bebc2 584 // Return:
585 // none.
2ab0c725 586
7d62fb64 587 if(fITSmodules){
588 fITSmodules->Delete();
589 delete fITSmodules;
590 } // end fir fITSmoudles
88cb7938 591
7d62fb64 592 if(!fDetTypeSim) {
593 Error("InitModules","fDetTypeSim is null!");
6f5308d9 594 return kFALSE;
7d62fb64 595 }
c8af5b8f 596 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
828e06c7 597
7d62fb64 598 Int_t nl,indexMAX,index;
599
600 if(size<=0){ // default to using data stored in AliITSgeom
601 if(fDetTypeSim->GetITSgeom()==0) {
602 Error("InitModules","fITSgeom not defined");
6f5308d9 603 return kFALSE;
7d62fb64 604 } // end if fITSgeom==0
605 nl = fDetTypeSim->GetITSgeom()->GetNlayers();
606 indexMAX = fDetTypeSim->GetITSgeom()->GetIndexMax();
607 nmodules = indexMAX;
608 fITSmodules = new TObjArray(indexMAX);
609 for(index=0;index<indexMAX;index++){
610 fITSmodules->AddAt( new AliITSmodule(index),index);
611 } // end for index
612 }else{
613 fITSmodules = new TObjArray(size);
614 for(index=0;index<size;index++) {
615 fITSmodules->AddAt( new AliITSmodule(index),index);
616 } // end for index
617
618 nmodules = size;
619 } // end i size<=0
6f5308d9 620 return kTRUE;
2aea926d 621}
622//______________________________________________________________________
623void AliITS::Hits2SDigits(){
624 // Standard Hits to summable Digits function.
4a5bebc2 625 // Inputs:
626 // none.
627 // Outputs:
628 // none.
7d62fb64 629
2aea926d 630
7d62fb64 631 if(!fDetTypeSim) {
632 Error("Hits2SDigits","fDetTypeSim is null!");
ad7f2bfa 633 return;
7d62fb64 634 }
635
636 SetDefaults();
637 fLoader->LoadHits("read");
638 fLoader->LoadSDigits("recreate");
639 AliRunLoader* rl = fLoader->GetRunLoader();
023ae34b 640 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
c8af5b8f 641 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
642
7d62fb64 643 for (Int_t iEvent = 0; iEvent < rl->GetNumberOfEvents(); iEvent++) {
aacedc3e 644 // Do the Hits to Digits operation. Use Standard input values.
645 // Event number from file, no background hit merging , use size from
646 // AliITSgeom class, option="All", input from this file only.
7d62fb64 647 rl->GetEvent(iEvent);
648 if (!fLoader->TreeS()) fLoader->MakeTree("S");
649 MakeBranch("S");
650 SetTreeAddress();
651 HitsToPreDigits(iEvent,0,-1," ",fOpt," ");
652 } // end for iEvent
e0fc0305 653
7d62fb64 654 fLoader->UnloadHits();
655 fLoader->UnloadSDigits();
656
2aea926d 657}
658//______________________________________________________________________
659void AliITS::Hits2Digits(){
2aea926d 660
7d62fb64 661 //Conversion from hits to digits
662 if(!fDetTypeSim) {
663 Error("Hits2SDigits","fDetTypeSim is 0!");
664 return;
665 }
666
023ae34b 667 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
c8af5b8f 668 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
7d62fb64 669 SetDefaults();
670
671 fLoader->LoadHits("read");
672 fLoader->LoadDigits("recreate");
673 AliRunLoader* rl = fLoader->GetRunLoader();
674 for (Int_t iEvent = 0; iEvent < rl->GetNumberOfEvents(); iEvent++) {
675 rl->GetEvent(iEvent);
676 if (!fLoader->TreeD()) fLoader->MakeTree("D");
677 MakeBranch("D");
678 SetTreeAddress();
679 HitsToDigits(iEvent,0,-1," ",fOpt," ");
680 }
681
682 fLoader->UnloadHits();
683 fLoader->UnloadDigits();
684
2aea926d 685}
7d62fb64 686
2aea926d 687//______________________________________________________________________
7d62fb64 688void AliITS::HitsToDigits(Int_t evNumber,Int_t bgrev,Int_t size,
689 Option_t *option,Option_t *opt,
690 const char *filename){
4a5bebc2 691 // Keep galice.root for signal and name differently the file for
2aea926d 692 // background when add! otherwise the track info for signal will be lost !
693 // the condition below will disappear when the geom class will be
4a5bebc2 694 // initialized for all versions - for the moment it is only for v5 !
695 // 7 is the SDD beam test version.
696 // Inputs:
697 // Int_t evnt Event to be processed.
698 // Int_t bgrev Background Hit tree number.
699 // Int_t nmodules Not used.
700 // Option_t *option String indicating if merging hits or not. To
701 // merge hits set equal to "Add". Otherwise no
702 // background hits are considered.
703 // Test_t *filename File name containing the background hits..
704 // Outputs:
705 // none.
706 // Return:
707 // none.
2aea926d 708
7d62fb64 709 if(!fDetTypeSim) {
710 Error("HitsToDigits","fDetTypeSim is null!");
711 return;
712 }
023ae34b 713 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
c8af5b8f 714 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
7d62fb64 715 if(!GetITSgeom()) return; // need transformations to do digitization.
716 AliITSgeom *geom = GetITSgeom();
717
718 const char *all = strstr(opt,"All");
719 const char *det[3] = {strstr(opt,"SPD"),strstr(opt,"SDD"),
720 strstr(opt,"SSD")};
721 static Bool_t setDef=kTRUE;
722 if (setDef) SetDefaultSimulation();
723 setDef=kFALSE;
724
725 Int_t nmodules;
726 InitModules(size,nmodules);
727 FillModules(evNumber,bgrev,nmodules,option,filename);
ad7f2bfa 728
729 // Reset Fast-OR signals for this event
730 fDetTypeSim->ResetFOSignals();
7d62fb64 731
732 AliITSsimulation *sim = 0;
733 AliITSmodule *mod = 0;
734 Int_t id;
735 for(Int_t module=0;module<geom->GetIndexMax();module++){
736 id = geom->GetModuleType(module);
737 if (!all && !det[id]) continue;
738 sim = (AliITSsimulation*)fDetTypeSim->GetSimulationModel(id);
739 if (!sim) {
740 Error("HitsToDigits","The simulation class was not "
741 "instanciated for module %d type %s!",module,
742 geom->GetModuleTypeName(module));
743 exit(1);
744 } // end if !sim
745 mod = (AliITSmodule *)fITSmodules->At(module);
746 sim->DigitiseModule(mod,module,evNumber);
747 // fills all branches - wasted disk space
748 fLoader->TreeD()->Fill();
749 ResetDigits();
750 } // end for module
751
752 ClearModules();
a0d76912 753
ad7f2bfa 754 // Add Fast-OR signals to event (only one object per event)
755 if (all || det[0]) { // SPD present
662026ab 756 WriteFOSignals();
ad7f2bfa 757 }
ad7f2bfa 758
7d62fb64 759 fLoader->TreeD()->GetEntries();
760 fLoader->TreeD()->AutoSave();
761 // reset tree
762 fLoader->TreeD()->Reset();
2aea926d 763}
7d62fb64 764//_____________________________________________________________________
765void AliITS::Hits2PreDigits(){
766 // Turn hits into SDigits
767
768 if(!fDetTypeSim) {
769 Error("Hits2SDigits","fDetTypeSim is 0!");
770 return;
771 }
772
023ae34b 773 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
c8af5b8f 774 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
7d62fb64 775 SetDefaults();
776
777 HitsToPreDigits(fLoader->GetRunLoader()->GetEventNumber(),
778 0,-1," ",fOpt," ");
779}
780
2aea926d 781//______________________________________________________________________
7d62fb64 782void AliITS::HitsToPreDigits(Int_t evNumber,Int_t bgrev,Int_t size,
783 Option_t *option,Option_t *opt,
784 const char *filename){
4a5bebc2 785 // Keep galice.root for signal and name differently the file for
2aea926d 786 // background when add! otherwise the track info for signal will be lost !
787 // the condition below will disappear when the geom class will be
4a5bebc2 788 // initialized for all versions - for the moment it is only for v5 !
789 // 7 is the SDD beam test version.
790 // Inputs:
791 // Int_t evnt Event to be processed.
792 // Int_t bgrev Background Hit tree number.
793 // Int_t nmodules Not used.
794 // Option_t *option String indicating if merging hits or not. To
795 // merge hits set equal to "Add". Otherwise no
796 // background hits are considered.
797 // Test_t *filename File name containing the background hits..
798 // Outputs:
799 // none.
800 // Return:
801 // none.
802
7d62fb64 803
804 if(!fDetTypeSim) {
805 Error("HitsToPreDigits","fDetTypeSim is null!");
806 return;
807 }
023ae34b 808 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
c8af5b8f 809 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
7d62fb64 810
811 if(!GetITSgeom()){
812 Error("HitsToPreDigits","fGeom is null!");
813 return; // need transformations to do digitization.
814 }
815 AliITSgeom *geom = GetITSgeom();
816
817 const char *all = strstr(opt,"All");
818 const char *det[3] = {strstr(opt,"SPD"),strstr(opt,"SDD"),
819 strstr(opt,"SSD")};
820 static Bool_t setDef=kTRUE;
821 if (setDef) SetDefaultSimulation();
822 setDef=kFALSE;
823
824 Int_t nmodules;
825 InitModules(size,nmodules);
826 FillModules(evNumber,bgrev,nmodules,option,filename);
827
828
829 AliITSsimulation *sim = 0;
830 AliITSmodule *mod = 0;
831 Int_t id,module;
832 for(module=0;module<geom->GetIndexMax();module++){
833 id = geom->GetModuleType(module);
834 if (!all && !det[id]) continue;
835 sim = (AliITSsimulation*)GetSimulationModel(id);
836 if (!sim) {
837 Error("HitsToPreDigits","The simulation class was not "
838 "instanciated for module %d type %s!",module,
839 geom->GetModuleTypeName(module));
840 exit(1);
841 } // end if !sim
842 mod = (AliITSmodule *)fITSmodules->At(module);
843 sim->SDigitiseModule(mod,module,evNumber);
844 // fills all branches - wasted disk space
845 fLoader->TreeS()->Fill();
846 fDetTypeSim->ResetSDigits();
847 } // end for module
04366a57 848
7d62fb64 849 ClearModules();
850
851
852 fLoader->TreeS()->GetEntries();
853 fLoader->TreeS()->AutoSave();
854 fLoader->WriteSDigits("OVERWRITE");
855 // reset tree
856 fLoader->TreeS()->Reset();
2aea926d 857}
7d62fb64 858
859//_____________________________________________________________________
860void AliITS::HitsToFastRecPoints(Int_t evNumber,Int_t bgrev,Int_t size,
861 Option_t *opt0,Option_t *opt1,
862 const char *flnm){
863 // keep galice.root for signal and name differently the file for
864 // background when add! otherwise the track info for signal will be lost !
865 // the condition below will disappear when the geom class will be
866 // initialized for all versions - for the moment it is only for v5 !
867 // Inputs:
868 // Int_t evnt Event to be processed.
869 // Int_t bgrev Background Hit tree number.
870 // Int_t size Size used by InitModules. See InitModules.
871 // Option_t *opt0 Option passed to FillModules. See FillModules.
872 // Option_t *opt1 String indicating if merging hits or not. To
873 // merge hits set equal to "Add". Otherwise no
874 // background hits are considered.
875 // Test_t *flnm File name containing the background hits..
876 // Outputs:
877 // none.
878 // Return:
879 // none.
880
881
00a7cc50 882
7d62fb64 883 if(!GetITSgeom()){
884 Error("HitsToPreDigits","fGeom is null!");
885 return; // need transformations to do digitization.
886 }
887 AliITSgeom *geom = GetITSgeom();
888
889 AliITSLoader *pITSloader = (AliITSLoader*)fLoader;
890
891 const char *all = strstr(opt1,"All");
892 const char *det[3] ={strstr(opt1,"SPD"),strstr(opt1,"SDD"),
893 strstr(opt1,"SSD")};
894 Int_t nmodules;
895 InitModules(size,nmodules);
896 FillModules(evNumber,bgrev,nmodules,opt0,flnm);
897
898 AliITSsimulation *sim = 0;
899 AliITSmodule *mod = 0;
900 Int_t id,module;
901
902 TTree *lTR = pITSloader->TreeR();
00a7cc50 903 if(!lTR) {
904 pITSloader->MakeTree("R");
905 lTR = pITSloader->TreeR();
906 }
907
7d62fb64 908 TClonesArray* ptarray = new TClonesArray("AliITSRecPoint",1000);
00a7cc50 909 TBranch* branch = (TBranch*)lTR->Branch("ITSRecPointsF",&ptarray);
910 branch->SetAddress(&ptarray);
7d62fb64 911 //m.b. : this change is nothing but a nice way to make sure
023ae34b 912 //the CPU goes up !
7d62fb64 913 for(module=0;module<geom->GetIndexMax();module++){
914 id = geom->GetModuleType(module);
915 if (!all && !det[id]) continue;
916 sim = (AliITSsimulation*)GetSimulationModel(id);
917 if (!sim) {
918 Error("HitsToFastPoints","The simulation class was not "
a5a317a9 919 "instantiated for module %d type %s!",module,
7d62fb64 920 geom->GetModuleTypeName(module));
921 exit(1);
922 } // end if !sim
923 mod = (AliITSmodule *)fITSmodules->At(module);
924 sim->CreateFastRecPoints(mod,module,gRandom,ptarray);
925 lTR->Fill();
f1bfe73f 926 ptarray->Clear();
7d62fb64 927 } // end for module
928
929 ClearModules();
930 fLoader->WriteRecPoints("OVERWRITE");
931 delete ptarray;
932}
933//_____________________________________________________________________
934Int_t AliITS::Hits2Clusters(TTree *hTree, TTree *cTree) {
935 //------------------------------------------------------------
936 // This function creates ITS clusters
937 //------------------------------------------------------------
938 if(!GetITSgeom()){
939 Error("HitsToPreDigits","fGeom is null!");
940 return 1; // need transformations to do digitization.
941 }
942 AliITSgeom *geom=GetITSgeom();
943 Int_t mmax=geom->GetIndexMax();
944
945 InitModules(-1,mmax);
946 FillModules(hTree,0);
947
7d62fb64 948 TClonesArray *points = new TClonesArray("AliITSRecPoint",1000);
00a7cc50 949 TBranch *branch=cTree->GetBranch("ITSRecPoints");
950 if (!branch) cTree->Branch("ITSRecPoints",&points);
951 else branch->SetAddress(&points);
7d62fb64 952
953 AliITSsimulationFastPoints sim;
954 Int_t ncl=0;
955 for (Int_t m=0; m<mmax; m++) {
956 AliITSmodule *mod=GetModule(m);
957 sim.CreateFastRecPoints(mod,m,gRandom,points);
00a7cc50 958 ncl+=points->GetEntriesFast();
7d62fb64 959 cTree->Fill();
7d62fb64 960 points->Clear();
961 }
962
15e6a32c 963 AliDebug(1,Form("Number of found fast clusters : %d",ncl));
7d62fb64 964
965 //cTree->Write();
966
7d62fb64 967 delete points;
968 return 0;
969}
7d62fb64 970
7d62fb64 971//_____________________________________________________________________
972void AliITS::CheckLabels(Int_t lab[3]) const {
973 //------------------------------------------------------------
974 // Tries to find mother's labels
975 //------------------------------------------------------------
976
977 if(lab[0]<0 && lab[1]<0 && lab[2]<0) return; // In case of no labels just exit
978
979 Int_t ntracks = gAlice->GetMCApp()->GetNtrack();
980 for (Int_t i=0;i<3;i++){
981 Int_t label = lab[i];
982 if (label>=0 && label<ntracks) {
983 TParticle *part=(TParticle*)gAlice->GetMCApp()->Particle(label);
984 if (part->P() < 0.005) {
985 Int_t m=part->GetFirstMother();
986 if (m<0) {
987 continue;
988 }
989 if (part->GetStatusCode()>0) {
990 continue;
991 }
992 lab[i]=m;
993 }
994 }
995 }
996
997}
998
999//______________________________________________________________________
1000void AliITS::SDigitsToDigits(Option_t *opt){
ad7f2bfa 1001 // Standard Summable digits to Digits function.
1002 // Inputs:
1003 // none.
1004 // Outputs:
1005 // none.
1006 if (!fDetTypeSim) {
1007 AliError("fDetTypeSim is 0!");
1008 return;
1009 }
ad7f2bfa 1010 const char *all = strstr(opt,"All");
1011 const char *det[3] ={strstr(opt,"SPD"),strstr(opt,"SDD"),
1012 strstr(opt,"SSD")};
1013
1014 // Reset Fast-OR signals for this event
1015 fDetTypeSim->ResetFOSignals();
1016
1017 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
1018 SetDefaults();
c8af5b8f 1019 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
ad7f2bfa 1020 fDetTypeSim->SDigitsToDigits(opt,(Char_t*)GetName());
1021
ad7f2bfa 1022 // Add Fast-OR signals to event (only one object per event)
1023 if (all || det[0]) { // SPD present
662026ab 1024 WriteFOSignals();
ad7f2bfa 1025 }
7d62fb64 1026}
1027
2aea926d 1028//______________________________________________________________________
2aea926d 1029void AliITS::ResetDigits(){
4a5bebc2 1030 // Reset number of digits and the digits array for the ITS detector.
1031 // Inputs:
1032 // none.
1033 // Outputs:
1034 // none.
7d62fb64 1035 if(!fDetTypeSim) {
1036 Error("ResetDigits","fDetTypeSim is 0!");
1037 return;
1038 }
1039
1040 fDetTypeSim->ResetDigits();
3bd79107 1041
1042
2aea926d 1043}
1044//______________________________________________________________________
7d62fb64 1045void AliITS::ResetDigits(Int_t branch){
4a5bebc2 1046 // Reset number of digits and the digits array for this branch.
1047 // Inputs:
1048 // none.
1049 // Outputs:
1050 // none.
828e06c7 1051
7d62fb64 1052 if(!fDetTypeSim) {
1053 Error("ResetDigits","fDetTypeSim is 0!");
1054 return;
1055 }
1056
1057 fDetTypeSim->ResetDigits(branch);
1058
2aea926d 1059}
1060//______________________________________________________________________
1061void AliITS::AddSumDigit(AliITSpListItem &sdig){
4a5bebc2 1062 // Adds the a module full of summable digits to the summable digits tree.
1063 // Inputs:
1064 // AliITSpListItem &sdig SDigit to be added to SDigits tree.
1065 // Outputs:
1066 // none.
1067 // Return:
1068 // none.
828e06c7 1069
7d62fb64 1070 if(!fDetTypeSim) {
1071 Error("AddSumDigit","fDetTypeSim is 0!");
1072 return;
1073 }
1074 fDetTypeSim->AddSumDigit(sdig);
1075
2aea926d 1076}
1077//______________________________________________________________________
7d62fb64 1078void AliITS::AddSimDigit(Int_t branch, AliITSdigit *d){
4a5bebc2 1079 // Add a simulated digit.
1080 // Inputs:
1081 // Int_t id Detector type number.
1082 // AliITSdigit *d Digit to be added to the Digits Tree. See
1083 // AliITSdigit.h
1084 // Outputs:
1085 // none.
1086 // Return:
1087 // none.
2aea926d 1088
7d62fb64 1089 if(!fDetTypeSim) {
1090 Error("AddSimDigit","fDetTypeSim is 0!");
1091 return;
1092 }
1093 fDetTypeSim->AddSimDigit(branch,d);
1094
2aea926d 1095}
1096//______________________________________________________________________
7d62fb64 1097void AliITS::AddSimDigit(Int_t branch,Float_t phys,Int_t *digits,Int_t *tracks,
83ec5e27 1098 Int_t *hits,Float_t *charges, Int_t sigexpanded){
7f1a504b 1099 // Add a simulated digit to the list.
1100 // Inputs:
1101 // Int_t id Detector type number.
1102 // Float_t phys Physics indicator. See AliITSdigits.h
1103 // Int_t *digits Integer array containing the digits info. See
1104 // AliITSdigit.h
1105 // Int_t *tracks Integer array [AliITSdigitS?D::GetNTracks()]
1106 // containing the track numbers that contributed to
1107 // this digit.
1108 // Int_t *hits Integer array [AliITSdigitS?D::GetNTracks()]
1109 // containing the hit numbers, from AliITSmodule, that
1110 // contributed to this digit.
1111 // Float_t *charge Floating point array of the signals contributed
1112 // to this digit by each track.
1113 // Outputs:
1114 // none.
1115 // Return:
1116 // none.
2aea926d 1117
7d62fb64 1118 if(!fDetTypeSim) {
1119 Error("AddSimDigit","fDetTypeSim is 0!");
1120 return;
1121 }
83ec5e27 1122 fDetTypeSim->AddSimDigit(branch,phys,digits,tracks,hits,charges,sigexpanded);
7d62fb64 1123
2aea926d 1124}
0421c3d1 1125//______________________________________________________________________
aacedc3e 1126void AliITS::Digits2Raw(){
1127 // convert digits of the current event to raw data
0421c3d1 1128
7d62fb64 1129 if(!fDetTypeSim) {
1130 Error("Digits2Raw","fDetTypeSim is 0!");
1131 return;
1132 }
023ae34b 1133 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
7d62fb64 1134 SetDefaults();
c8af5b8f 1135 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
7d62fb64 1136 fDetTypeSim->GetLoader()->LoadDigits();
1137 TTree* digits = fDetTypeSim->GetLoader()->TreeD();
0421c3d1 1138 if (!digits) {
aacedc3e 1139 Error("Digits2Raw", "no digits tree");
1140 return;
0421c3d1 1141 }
7d62fb64 1142 fDetTypeSim->SetTreeAddressD(digits,(Char_t*)GetName());
ad7f2bfa 1143
1144 // Get the FO signals for this event
1145 AliITSFOSignalsSPD* foSignals = NULL;
1146 AliRunLoader* runLoader = AliRunLoader::Instance();
1147 AliITSLoader* itsLoader = (AliITSLoader*) runLoader->GetLoader("ITSLoader");
1148 if (!itsLoader) {
1149 AliError("ITS loader is NULL.");
1150 }
a0d76912 1151 else {
1152 if(!itsLoader->TreeD()) AliError(" !!! No TreeD available !!!");
1153 foSignals = (AliITSFOSignalsSPD*)itsLoader->TreeD()->GetUserInfo()->FindObject("AliITSFOSignalsSPD");
1154 if(!foSignals) AliError("FO signals not retrieved");
1155 }
1156
ad7f2bfa 1157 Bool_t deleteFOsignalsLater = kFALSE;
1158 if (!foSignals) {
1159 AliError("FO signals not available. No FO bits will be written.");
1160 foSignals = new AliITSFOSignalsSPD(); // make a temporary dummy signals object
1161 deleteFOsignalsLater = kTRUE;
1162 }
1163
1164
979b5a5f 1165 AliITSDDLModuleMapSDD* ddlsdd=fDetTypeSim->GetDDLModuleMapSDD();
d9ed1779 1166 Char_t rawSDD=fDetTypeSim->GetSimuParam()->GetSDDRawDataFormat();
0421c3d1 1167 AliITSDDLRawData rawWriter;
d9ed1779 1168
1169 rawWriter.SetSDDRawFormat(rawSDD);
0421c3d1 1170 //Verbose level
1171 // 0: Silent
1172 // 1: cout messages
1173 // 2: txt files with digits
1174 //BE CAREFUL, verbose level 2 MUST be used only for debugging and
1175 //it is highly suggested to use this mode only for debugging digits files
1176 //reasonably small, because otherwise the size of the txt files can reach
1177 //quickly several MB wasting time and disk space.
1178 rawWriter.SetVerbose(0);
1179
1180 //SILICON PIXEL DETECTOR
15e6a32c 1181 AliDebug(1,"Formatting raw data for SPD");
ad7f2bfa 1182 rawWriter.RawDataSPD(digits->GetBranch("ITSDigitsSPD"),foSignals);
1183 if(deleteFOsignalsLater) delete foSignals;
0421c3d1 1184
1185 //SILICON DRIFT DETECTOR
d9ed1779 1186 AliDebug(1,Form("Formatting raw data for SDD - Format code =%d",rawSDD));
979b5a5f 1187 rawWriter.RawDataSDD(digits->GetBranch("ITSDigitsSDD"),ddlsdd);
0421c3d1 1188
1189 //SILICON STRIP DETECTOR
15e6a32c 1190 AliDebug(1,"Formatting raw data for SSD");
0421c3d1 1191 rawWriter.RawDataSSD(digits->GetBranch("ITSDigitsSSD"));
1192
1193 fLoader->UnloadDigits();
2aea926d 1194}
2aea926d 1195//______________________________________________________________________
aacedc3e 1196AliLoader* AliITS::MakeLoader(const char* topfoldername){
1197 //builds ITSgetter (AliLoader type)
1198 //if detector wants to use castomized getter, it must overload this method
1199
64f311fe 1200 AliDebug(1,Form("Creating AliITSLoader. Top folder is %s.",
1201 topfoldername));
aacedc3e 1202 fLoader = new AliITSLoader(GetName(),topfoldername);
1203 return fLoader;
2aea926d 1204}
ad7f2bfa 1205//______________________________________________________________________
0b5bf101 1206Bool_t AliITS::Raw2SDigits(AliRawReader* rawReader)
1207{
1208 //
1209 // Converts RAW data to SDigits
1210 //
1211 // Get TreeS
1212 //
afbc83e9 1213 Int_t last = -1;
773af0c4 1214 Int_t size = AliITSgeomTGeo::GetNModules();
afbc83e9 1215 if(!fModA) {
1216 fModA = new TClonesArray*[size];
1217 for (Int_t mod = 0; mod < size; mod++) fModA[mod] = new TClonesArray("AliITSpListItem", 10000);
1218 }
1219 AliLoader* loader = (AliRunLoader::Instance())->GetLoader("ITSLoader");
1220 if (!loader){
1221 Error("Open","Can not get ITS loader from Run Loader");
1222 return kFALSE;
1223 }
0b5bf101 1224
afbc83e9 1225 TTree* tree = 0;
1226 tree = loader->TreeS();
1227 if (!tree){
1228 loader->MakeTree("S");
0b5bf101 1229 tree = loader->TreeS();
afbc83e9 1230 }
1231 //
1232 // Array for SDigits
1233 //
1234 if(!fpSDigits){
1235 fpSDigits = new TClonesArray("AliITSpListItem",10000);
1236 }
1237 TClonesArray& aSDigits = *fpSDigits;
1238 Int_t bufsize = 32000;
1239 tree->Branch("ITS", &fpSDigits, bufsize);
1240 Int_t npx = 0;
1241 //
1242 // SPD
1243 //
1244 AliITSsegmentationSPD* segSPD = (AliITSsegmentationSPD*) fDetTypeSim->GetSegmentationModel(0);
1245 if(!segSPD){
1246 AliWarning("Set AliITS defaults");
1247 SetDefaults();
1248 segSPD = (AliITSsegmentationSPD*) fDetTypeSim->GetSegmentationModel(0);
1249 }
1250 npx = segSPD->Npx();
1251 Double_t thr, sigma;
6c8e94cf 1252
1253 Int_t countRW = -1; // RS counter for raw -> cluster ID's (used in embedding)
65dc605a 1254 const TArrayI* rawID2clusID = fkRawID2ClusID[kSPD];
afbc83e9 1255 AliITSRawStreamSPD inputSPD(rawReader);
1256 while(1){
1257 Bool_t next = inputSPD.Next();
1258 if (!next) break;
0b5bf101 1259
6c8e94cf 1260 countRW++; // RS
afbc83e9 1261 Int_t module = inputSPD.GetModuleID();
1262 Int_t column = inputSPD.GetColumn();
1263 Int_t row = inputSPD.GetRow();
1264 Int_t index = npx * column + row;
0b5bf101 1265
afbc83e9 1266 if (module >= size) continue;
0b5bf101 1267
afbc83e9 1268 last = (fModA[module])->GetEntries();
1269 TClonesArray& dum = *fModA[module];
1270 fDetTypeSim->GetSimuParam()->SPDThresholds(module,thr,sigma);
1271 thr += 1.;
afa93859 1272 int label = kMaxLabel;
6c8e94cf 1273 if (rawID2clusID) { // RS If the raw->cluster ID is set (filled by cluster finder) store cluster ID's in SDigits
1274 if (rawID2clusID->GetSize()<=countRW) {AliError(Form("The buffer of rawSPD to clusSPD ID's is shorter than current rawSPD ID=%d",countRW));}
1275 else label = (*rawID2clusID)[countRW];
1276 }
1277 new (dum[last]) AliITSpListItem(label, -1, module, index, thr);
afbc83e9 1278 }
1279 rawReader->Reset();
1280
1281 //
1282 // SDD
1283 //
1284 AliITSsegmentationSDD* segSDD = (AliITSsegmentationSDD*) fDetTypeSim->GetSegmentationModel(1);
1285 npx = segSDD->Npx();
1286 Int_t scalef=AliITSsimulationSDD::ScaleFourier(segSDD);
1287 Int_t firstSDD=AliITSgeomTGeo::GetModuleIndex(3,1,1);
1288 Int_t firstSSD=AliITSgeomTGeo::GetModuleIndex(5,1,1);
6c8e94cf 1289 //
1290 countRW = -1; // RS
65dc605a 1291 rawID2clusID = fkRawID2ClusID[kSDD];
afbc83e9 1292 AliITSRawStream* inputSDD=AliITSRawStreamSDD::CreateRawStreamSDD(rawReader);
1293 for(Int_t iMod=firstSDD; iMod<firstSSD; iMod++){
1294 AliITSCalibrationSDD* cal = (AliITSCalibrationSDD*)fDetTypeSim->GetCalibrationModel(iMod);
1295 Bool_t isZeroSupp=cal->GetZeroSupp();
1296 if(isZeroSupp){
1297 for(Int_t iSid=0; iSid<2; iSid++) inputSDD->SetZeroSuppLowThreshold(iMod-firstSDD,iSid,cal->GetZSLowThreshold(iSid));
1298 }else{
1299 for(Int_t iSid=0; iSid<2; iSid++) inputSDD->SetZeroSuppLowThreshold(iMod-firstSDD,iSid,0);
dee45d79 1300 }
afbc83e9 1301 }
dee45d79 1302
afbc83e9 1303 AliITSDDLModuleMapSDD* ddlmap=fDetTypeSim->GetDDLModuleMapSDD();
1304 inputSDD->SetDDLModuleMap(ddlmap);
1305 while(inputSDD->Next()){
6c8e94cf 1306 countRW++; // RS
afbc83e9 1307 if(inputSDD->IsCompletedModule()==kFALSE &&
1308 inputSDD->IsCompletedDDL()==kFALSE){
1309
1310 Int_t module = inputSDD->GetModuleID();
1311 Int_t anode = inputSDD->GetCoord1()+segSDD->NpzHalf()*inputSDD->GetChannel();
1312 Int_t time = inputSDD->GetCoord2();
1313 Int_t signal10 = inputSDD->GetSignal();
1314 Int_t index = AliITSpList::GetIndex(anode,time,scalef*npx);
1315
1316 if (module >= size) continue;
1317 last = fModA[module]->GetEntries();
1318 TClonesArray& dum = *fModA[module];
afa93859 1319 int label = kMaxLabel;
6c8e94cf 1320 if (rawID2clusID) { // RS If the raw->cluster ID is set (filled by cluster finder) store cluster ID's in SDigits
1321 if (rawID2clusID->GetSize()<=countRW) {AliError(Form("The buffer of rawSDD to clusSDD ID's is shorter than current rawSDD ID=%d",countRW));}
1322 else label = (*rawID2clusID)[countRW];
1323 }
1324 new (dum[last]) AliITSpListItem(label, -1, module, index, Double_t(signal10));
afbc83e9 1325 ((AliITSpListItem*) dum.At(last))->AddSignalAfterElect(module, index, Double_t(signal10));
0b5bf101 1326 }
afbc83e9 1327 }
1328 delete inputSDD;
1329 rawReader->Reset();
a4998655 1330
afbc83e9 1331 //
1332 // SSD
1333 //
1334 AliITSsegmentationSSD* segSSD = (AliITSsegmentationSSD*) fDetTypeSim->GetSegmentationModel(2);
1335 npx = segSSD->Npx();
1336 AliITSRawStreamSSD inputSSD(rawReader);
6c8e94cf 1337 countRW = -1;
65dc605a 1338 rawID2clusID = fkRawID2ClusID[kSSD];
afbc83e9 1339 while(1){
1340 Bool_t next = inputSSD.Next();
1341 if (!next) break;
6c8e94cf 1342 countRW++; // RS
afbc83e9 1343 Int_t module = inputSSD.GetModuleID();
773af0c4 1344 if(module<0)AliError(Form("Invalid SSD module %d \n",module));
1345 if(module<0)continue;
afbc83e9 1346 Int_t side = inputSSD.GetSideFlag();
1347 Int_t strip = inputSSD.GetStrip();
1348 Int_t signal = inputSSD.GetSignal();
1349 Int_t index = npx * side + strip;
1350
1351 if (module >= size) continue;
0b5bf101 1352
afbc83e9 1353 last = fModA[module]->GetEntries();
1354 TClonesArray& dum = *fModA[module];
afa93859 1355 int label = kMaxLabel;
6c8e94cf 1356 if (rawID2clusID) { // RS If the raw->cluster ID is set (filled by cluster finder) store cluster ID's in SDigits
1357 if (rawID2clusID->GetSize()<=countRW) {AliError(Form("The buffer of rawSSD to clusSSD ID's is shorter than current rawSSD ID=%d",countRW));}
1358 else label = (*rawID2clusID)[countRW];
1359 }
1360 new (dum[last]) AliITSpListItem(label, -1, module, index, Double_t(signal));
afbc83e9 1361 }
1362 rawReader->Reset();
1363 AliITSpListItem* sdig = 0;
0b5bf101 1364
afbc83e9 1365 Int_t firstssd = GetITSgeom()->GetStartDet(kSSD);
1366 Double_t adcToEv = 1.;
1367 for (Int_t mod = 0; mod < size; mod++)
1368 {
8b3448d3 1369 if(mod>=firstssd) {
1370 AliITSCalibrationSSD* calssd = (AliITSCalibrationSSD*)fDetTypeSim->GetCalibrationModel(mod);
1371 adcToEv = 1./calssd->GetSSDDEvToADC(1.);
1372 }
afbc83e9 1373 Int_t nsdig = fModA[mod]->GetEntries();
8b3448d3 1374 for (Int_t ie = 0; ie < nsdig; ie++) {
afbc83e9 1375 sdig = (AliITSpListItem*) (fModA[mod]->At(ie));
463ae357 1376 Double_t digsig = sdig->GetSignal();
8b3448d3 1377 if(mod>=firstssd) digsig*=adcToEv; // for SSD: convert back charge from ADC to electron
6c8e94cf 1378 new (aSDigits[ie]) AliITSpListItem(sdig->GetTrack(0), -1, mod, sdig->GetIndex(), digsig);
afbc83e9 1379 Float_t sig = sdig->GetSignalAfterElect();
1380 if(mod>=firstssd) sig*=adcToEv;
1381 if (sig > 0.) {
1382 sdig = (AliITSpListItem*)aSDigits[ie];
1383 sdig->AddSignalAfterElect(mod, sdig->GetIndex(), Double_t(sig));
0b5bf101 1384 }
afbc83e9 1385 }
0b5bf101 1386
afbc83e9 1387 tree->Fill();
1388 aSDigits.Clear();
1389 fModA[mod]->Clear();
0b5bf101 1390 }
afbc83e9 1391 loader->WriteSDigits("OVERWRITE");
1392 return kTRUE;
0b5bf101 1393}
1394
ef7ff1f9 1395//______________________________________________________________________
1396void AliITS::UpdateInternalGeometry(){
ed9289c8 1397 //reads new geometry from TGeo
012f0f4c 1398// AliDebug(1,"Delete ITSgeom and create a new one reading TGeo");
1399
108bd0fe 1400 AliITSVersion_t version = (AliITSVersion_t)IsVersion();
012f0f4c 1401 AliITSInitGeometry initgeom;
d583ec69 1402 AliITSgeom* geom = initgeom.CreateAliITSgeom(version);
ef7ff1f9 1403 SetITSgeom(geom);
ef7ff1f9 1404}
ad7f2bfa 1405//______________________________________________________________________
1406AliTriggerDetector* AliITS::CreateTriggerDetector() const {
1407 // create an AliITSTrigger object (and set trigger conditions as input)
1408 return new AliITSTrigger(fDetTypeSim->GetTriggerConditions());
1409}
662026ab 1410//______________________________________________________________________
1411void AliITS::WriteFOSignals(){
1412// This method write FO signals in Digits tree both in Hits2Digits
1413// or SDigits2Digits
1414
1415 fDetTypeSim->ProcessNoiseForFastOr();
1416 fDetTypeSim->WriteFOSignals();
1417}
afa93859 1418
1419