ROOT logo
/**************************************************************************
 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
 *                                                                        *
 * Author: The ALICE Off-line Project.                                    *
 * Contributors are mentioned in the code where appropriate.              *
 *                                                                        *
 * Permission to use, copy, modify and distribute this software and its   *
 * documentation strictly for non-commercial purposes is hereby granted   *
 * without fee, provided that the above copyright notice appears in all   *
 * copies and that both the copyright notice and this permission notice   *
 * appear in the supporting documentation. The authors make no claims     *
 * about the suitability of this software for any purpose. It is          *
 * provided "as is" without express or implied warranty.                  *
 **************************************************************************/

/* $Id$ */

///////////////////////////////////////////////////////////////////////////////
//                                                                           //
//  Beam Condition Monitor BCM                                               //
//                                                                           //
//  andreas.morsch@cern.ch                                                   // 
///////////////////////////////////////////////////////////////////////////////
 
#include <TClonesArray.h>
#include <TGeoCompositeShape.h>
#include <TGeoGlobalMagField.h>
#include <TGeoManager.h>
#include <TGeoMaterial.h>
#include <TGeoMatrix.h>
#include <TGeoMedium.h>
#include <TGeoPgon.h>
#include <TGeoVolume.h>
#include <TGeoXtru.h>
#include <TVirtualMC.h>

#include "AliBCM.h"
#include "AliBCMHit.h"
#include "AliBCMLoader.h"
#include "AliMagF.h"
#include "AliRun.h"
#include "AliMC.h"
 
ClassImp(AliBCM)

 
//_____________________________________________________________________________
AliBCM::AliBCM():
    AliDetector(),
    fVolId(0)
{
  //
  // Default constructor for BCM
  //
}
 
//_____________________________________________________________________________
AliBCM::AliBCM(const char *name, const char *title): 
    AliDetector(name,title),
    fVolId(0)  
{
//
//  Constructor
    fHits  = new TClonesArray("AliBCMHit");
    fNhits = 0;    
    gAlice->GetMCApp()->AddHitList(fHits);
}
AliBCM::~AliBCM()
{  
    // Destructor
    if(fHits)      delete fHits;
}

void AliBCM::StepManager()
{
//
// Step Manager for ALICE Beam Condition Monitor
//    

    static Float_t edepT;    
    static Double_t xh[4] = {0., 0., 0., 0.};
    Float_t edep = 0.;
    Int_t   copy = -1; 
    
    
    if (TVirtualMC::GetMC()->TrackCharge() && 
	TVirtualMC::GetMC()->CurrentVolID(copy) == fVolId) {
	// Charged particle inside sensitive volume
	//
	// Entering
	if (TVirtualMC::GetMC()->IsTrackEntering()) {
	    edepT = 0.;
	    TVirtualMC::GetMC()->TrackPosition(xh[0],xh[1],xh[2]);
	    xh[3] = TVirtualMC::GetMC()->TrackTime();
	}
	
	//
	// Any step
	if ((edep = TVirtualMC::GetMC()->Edep()) > 0.) {
	    Double_t x[3];   
	    TVirtualMC::GetMC()->TrackPosition(x[0],x[1],x[2]); 
	    edepT += edep;
	}
	//
	// Exiting 
	if(TVirtualMC::GetMC()->IsTrackExiting()||TVirtualMC::GetMC()->IsTrackStop()||TVirtualMC::GetMC()->IsTrackDisappeared())
	{
	    Int_t track = gAlice->GetMCApp()->GetCurrentTrackNumber();
	    TClonesArray &lhits = *fHits;
	    Int_t ic = copy + 10;
	    if (xh[2] < 0.) ic+=10;
	    new(lhits[fNhits++]) AliBCMHit(1, track, xh, ic, edepT);
	}
    }

    
}

//_____________________________________________________________________________
void AliBCM::CreateGeometry()
{
    //
    // Create geometry for BCM
    //
    
    //
    // Top volume 
    TGeoVolume* top      = gGeoManager->GetVolume("ALIC");
    // Media 
    TGeoMedium* medPCD   = gGeoManager->GetMedium("BCM_PCD");
    // Rotations
    TGeoRotation* rotxz   = new TGeoRotation("rotxz" ,  270.,   0., 90.,  90., 180., 0.);
    TGeoRotation* rot000  = new TGeoRotation("rot000",   90.,   0., 90.,  90.,   0., 0.);
    TGeoRotation* rot090  = new TGeoRotation("rot090",   90.,  90., 90., 180.,   0., 0.);
    TGeoRotation* rot180  = new TGeoRotation("rot180",   90., 180., 90., 270.,   0., 0.);
    TGeoRotation* rot270  = new TGeoRotation("rot270",   90., 270., 90.,   0.,   0., 0.);
    //
    const Float_t kWidth     = 1.00;
    const Float_t kThickness = 0.05;
    const Float_t rBCM       = 7.;
    
    
    TGeoBBox*   shBCMpcd = new TGeoBBox(kWidth/2., kWidth/2., kThickness/2.);
    TGeoVolume* voBCMpcd = new TGeoVolume("BCMpcd", shBCMpcd, medPCD);
    TGeoVolumeAssembly* voBCM = new TGeoVolumeAssembly("BCM");
    
    voBCM->AddNode(voBCMpcd, 1, new TGeoCombiTrans(+rBCM, 0.    , 0., rot000));
    voBCM->AddNode(voBCMpcd, 2, new TGeoCombiTrans(0.   , +rBCM , 0., rot090));
    voBCM->AddNode(voBCMpcd, 3, new TGeoCombiTrans(-rBCM, 0.,     0., rot180));
    voBCM->AddNode(voBCMpcd, 4, new TGeoCombiTrans(0.   , -rBCM , 0., rot270));
    
    top->AddNode(voBCM, 1, new TGeoTranslation(0., 0., 1561.));
    top->AddNode(voBCM, 2, new TGeoCombiTrans(0., 0., -1908., rotxz));
    
}

//_____________________________________________________________________________
void AliBCM::CreateMaterials()
{
  //
  // Create materials for BCM
  //
  // Polycristalline Diamond
    Float_t rho  = 3.53;
    Float_t absl = 86.3 / rho;
    Float_t radl = 42.7 / rho;
    //
    Float_t epsil  = .001;   // Tracking precision, 
    Float_t stemax = -1.;    // Maximum displacement for multiple scat 
    Float_t tmaxfd = -20. ;  // Maximum angle due to field deflection 
    Float_t deemax = -.01;   // Maximum fractional energy loss, DLS 
    Float_t stmin  = -.8;
    Int_t   isxfld = ((AliMagF*)TGeoGlobalMagField::Instance()->GetField())->Integ();
    Float_t sxmgmx = ((AliMagF*)TGeoGlobalMagField::Instance()->GetField())->Max();

    AliMaterial(1, "PCD", 12.011, 6., rho, radl, absl);
    //
    AliMedium(1, "PCD", 1, 0, isxfld, sxmgmx, tmaxfd, stemax, deemax, epsil, stmin);
}

//_____________________________________________________________________________
void AliBCM::Init()
{
    //
    // Initialise BCM magnet after it has been built
    //
  Int_t i;
  //
  if(AliLog::GetGlobalDebugLevel()>0) {
    printf("\n%s: ",ClassName());
    for(i=0;i<35;i++) printf("*");
    printf(" BCM_INIT ");
    for(i=0;i<35;i++) printf("*");
    printf("\n%s: ",ClassName());
    for(i=0;i<80;i++) printf("*");
    printf("\n");
  }

    //
    // Here the BCM initialisation code (if any!)
    fVolId =  TVirtualMC::GetMC()->VolId("BCMpcd");
}

void AliBCM::MakeBranch(Option_t* option)
{
//Create Tree branches for the BCM
    
  const Int_t kBufSize = 4000;
  const char *cH = strstr(option,"H");
//  const char *cD = strstr(option,"D");
//  const char *cR = strstr(option,"R");
//  const char *cS = strstr(option,"S");

  if(cH && fLoader->TreeH() && (fHits == 0x0)){
      fHits  = new TClonesArray("AliBCMHit");
      fNhits = 0;    
      MakeBranchInTree(fLoader->TreeH(), "BCM" ,&fHits ,kBufSize, 0);
  }
  AliDetector::MakeBranch(option);
}

void AliBCM::SetTreeAddress()
{
  // Set branch address

    if (fLoader->TreeH() && fHits==0x0)
	fHits   = new TClonesArray("AliBCMHit",  4000);
    AliDetector::SetTreeAddress();
}

//_____________________________________________________________________________
AliLoader* AliBCM::MakeLoader(const char* topfoldername)
{ 
  //
  // Builds BCM getter (AliLoader type)
  AliDebug(1,Form("Creating AliBCMLoader, Top folder is %s ",topfoldername));
  fLoader = new AliBCMLoader(GetName(),topfoldername);
  return fLoader;
}
 AliBCM.cxx:1
 AliBCM.cxx:2
 AliBCM.cxx:3
 AliBCM.cxx:4
 AliBCM.cxx:5
 AliBCM.cxx:6
 AliBCM.cxx:7
 AliBCM.cxx:8
 AliBCM.cxx:9
 AliBCM.cxx:10
 AliBCM.cxx:11
 AliBCM.cxx:12
 AliBCM.cxx:13
 AliBCM.cxx:14
 AliBCM.cxx:15
 AliBCM.cxx:16
 AliBCM.cxx:17
 AliBCM.cxx:18
 AliBCM.cxx:19
 AliBCM.cxx:20
 AliBCM.cxx:21
 AliBCM.cxx:22
 AliBCM.cxx:23
 AliBCM.cxx:24
 AliBCM.cxx:25
 AliBCM.cxx:26
 AliBCM.cxx:27
 AliBCM.cxx:28
 AliBCM.cxx:29
 AliBCM.cxx:30
 AliBCM.cxx:31
 AliBCM.cxx:32
 AliBCM.cxx:33
 AliBCM.cxx:34
 AliBCM.cxx:35
 AliBCM.cxx:36
 AliBCM.cxx:37
 AliBCM.cxx:38
 AliBCM.cxx:39
 AliBCM.cxx:40
 AliBCM.cxx:41
 AliBCM.cxx:42
 AliBCM.cxx:43
 AliBCM.cxx:44
 AliBCM.cxx:45
 AliBCM.cxx:46
 AliBCM.cxx:47
 AliBCM.cxx:48
 AliBCM.cxx:49
 AliBCM.cxx:50
 AliBCM.cxx:51
 AliBCM.cxx:52
 AliBCM.cxx:53
 AliBCM.cxx:54
 AliBCM.cxx:55
 AliBCM.cxx:56
 AliBCM.cxx:57
 AliBCM.cxx:58
 AliBCM.cxx:59
 AliBCM.cxx:60
 AliBCM.cxx:61
 AliBCM.cxx:62
 AliBCM.cxx:63
 AliBCM.cxx:64
 AliBCM.cxx:65
 AliBCM.cxx:66
 AliBCM.cxx:67
 AliBCM.cxx:68
 AliBCM.cxx:69
 AliBCM.cxx:70
 AliBCM.cxx:71
 AliBCM.cxx:72
 AliBCM.cxx:73
 AliBCM.cxx:74
 AliBCM.cxx:75
 AliBCM.cxx:76
 AliBCM.cxx:77
 AliBCM.cxx:78
 AliBCM.cxx:79
 AliBCM.cxx:80
 AliBCM.cxx:81
 AliBCM.cxx:82
 AliBCM.cxx:83
 AliBCM.cxx:84
 AliBCM.cxx:85
 AliBCM.cxx:86
 AliBCM.cxx:87
 AliBCM.cxx:88
 AliBCM.cxx:89
 AliBCM.cxx:90
 AliBCM.cxx:91
 AliBCM.cxx:92
 AliBCM.cxx:93
 AliBCM.cxx:94
 AliBCM.cxx:95
 AliBCM.cxx:96
 AliBCM.cxx:97
 AliBCM.cxx:98
 AliBCM.cxx:99
 AliBCM.cxx:100
 AliBCM.cxx:101
 AliBCM.cxx:102
 AliBCM.cxx:103
 AliBCM.cxx:104
 AliBCM.cxx:105
 AliBCM.cxx:106
 AliBCM.cxx:107
 AliBCM.cxx:108
 AliBCM.cxx:109
 AliBCM.cxx:110
 AliBCM.cxx:111
 AliBCM.cxx:112
 AliBCM.cxx:113
 AliBCM.cxx:114
 AliBCM.cxx:115
 AliBCM.cxx:116
 AliBCM.cxx:117
 AliBCM.cxx:118
 AliBCM.cxx:119
 AliBCM.cxx:120
 AliBCM.cxx:121
 AliBCM.cxx:122
 AliBCM.cxx:123
 AliBCM.cxx:124
 AliBCM.cxx:125
 AliBCM.cxx:126
 AliBCM.cxx:127
 AliBCM.cxx:128
 AliBCM.cxx:129
 AliBCM.cxx:130
 AliBCM.cxx:131
 AliBCM.cxx:132
 AliBCM.cxx:133
 AliBCM.cxx:134
 AliBCM.cxx:135
 AliBCM.cxx:136
 AliBCM.cxx:137
 AliBCM.cxx:138
 AliBCM.cxx:139
 AliBCM.cxx:140
 AliBCM.cxx:141
 AliBCM.cxx:142
 AliBCM.cxx:143
 AliBCM.cxx:144
 AliBCM.cxx:145
 AliBCM.cxx:146
 AliBCM.cxx:147
 AliBCM.cxx:148
 AliBCM.cxx:149
 AliBCM.cxx:150
 AliBCM.cxx:151
 AliBCM.cxx:152
 AliBCM.cxx:153
 AliBCM.cxx:154
 AliBCM.cxx:155
 AliBCM.cxx:156
 AliBCM.cxx:157
 AliBCM.cxx:158
 AliBCM.cxx:159
 AliBCM.cxx:160
 AliBCM.cxx:161
 AliBCM.cxx:162
 AliBCM.cxx:163
 AliBCM.cxx:164
 AliBCM.cxx:165
 AliBCM.cxx:166
 AliBCM.cxx:167
 AliBCM.cxx:168
 AliBCM.cxx:169
 AliBCM.cxx:170
 AliBCM.cxx:171
 AliBCM.cxx:172
 AliBCM.cxx:173
 AliBCM.cxx:174
 AliBCM.cxx:175
 AliBCM.cxx:176
 AliBCM.cxx:177
 AliBCM.cxx:178
 AliBCM.cxx:179
 AliBCM.cxx:180
 AliBCM.cxx:181
 AliBCM.cxx:182
 AliBCM.cxx:183
 AliBCM.cxx:184
 AliBCM.cxx:185
 AliBCM.cxx:186
 AliBCM.cxx:187
 AliBCM.cxx:188
 AliBCM.cxx:189
 AliBCM.cxx:190
 AliBCM.cxx:191
 AliBCM.cxx:192
 AliBCM.cxx:193
 AliBCM.cxx:194
 AliBCM.cxx:195
 AliBCM.cxx:196
 AliBCM.cxx:197
 AliBCM.cxx:198
 AliBCM.cxx:199
 AliBCM.cxx:200
 AliBCM.cxx:201
 AliBCM.cxx:202
 AliBCM.cxx:203
 AliBCM.cxx:204
 AliBCM.cxx:205
 AliBCM.cxx:206
 AliBCM.cxx:207
 AliBCM.cxx:208
 AliBCM.cxx:209
 AliBCM.cxx:210
 AliBCM.cxx:211
 AliBCM.cxx:212
 AliBCM.cxx:213
 AliBCM.cxx:214
 AliBCM.cxx:215
 AliBCM.cxx:216
 AliBCM.cxx:217
 AliBCM.cxx:218
 AliBCM.cxx:219
 AliBCM.cxx:220
 AliBCM.cxx:221
 AliBCM.cxx:222
 AliBCM.cxx:223
 AliBCM.cxx:224
 AliBCM.cxx:225
 AliBCM.cxx:226
 AliBCM.cxx:227
 AliBCM.cxx:228
 AliBCM.cxx:229
 AliBCM.cxx:230
 AliBCM.cxx:231
 AliBCM.cxx:232
 AliBCM.cxx:233
 AliBCM.cxx:234
 AliBCM.cxx:235
 AliBCM.cxx:236
 AliBCM.cxx:237
 AliBCM.cxx:238
 AliBCM.cxx:239