]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PMD/MakePMDFullMisAlignment.C
https://savannah.cern.ch/bugs/index.php?98544
[u/mrichter/AliRoot.git] / PMD / MakePMDFullMisAlignment.C
1 void MakePMDFullMisAlignment(){
2   // Create TClonesArray of full misalignment objects for PMD
3   //
4
5   // Macro to randomly displace the 4 sectors of the PMD
6   // in each plane. Each sector (to be misaligned) 
7   // of PMD houses the following :
8   // (a) 6 modules of preshower plane
9   // (b) 6 modules of veto plane
10   // (c) The FEE boards on back plane of each module
11   // (d) 6 modules of convertor plates
12   // The clustering is done module-wise
13   // The actual amount displacement will be provided
14   // by the survey data and has to be converted into
15   // displacement in x,y,z,theta, phi and psi 
16   
17   
18   // Now specify the path of the module to be misaligned
19   // as followed in the PMD geant
20   
21   /*
22      _____________
23     |    |        |
24     | 1  |   3    |
25     |    |________|
26     |____|___|    |
27     |        | 2  |
28     |   4    |    |
29     |________|____|
30     
31     // Misalignment Matrix is expected to be
32     // same for sectors 1 and 4 
33     // and for the sectors 2 and 3
34     // As these will be mounted on the same
35     // Steel plate 
36  */
37   
38   const char* macroname = "MakePMDFullMisAlignment.C";
39
40   // Activate CDB storage and load geometry from CDB
41   AliCDBManager* cdb = AliCDBManager::Instance();
42   if(!cdb->IsDefaultStorageSet()) cdb->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
43   cdb->SetRun(0);
44   
45   AliCDBStorage* storage;
46   
47   if( TString(gSystem->Getenv("TOCDB")) == TString("kTRUE") ){
48     TString Storage = gSystem->Getenv("STORAGE");
49     if(!Storage.BeginsWith("local://") && !Storage.BeginsWith("alien://")) {
50       Error(macroname,"STORAGE variable set to %s is not valid. Exiting\n",Storage.Data());
51       return;
52     }
53     storage = cdb->GetStorage(Storage.Data());
54     if(!storage){
55       Error(macroname,"Unable to open storage %s\n",Storage.Data());
56       return;
57     }
58     AliCDBPath path("GRP","Geometry","Data");
59     AliCDBEntry *entry = storage->Get(path.GetPath(),cdb->GetRun());
60     if(!entry) Fatal(macroname,"Could not get the specified CDB entry!");
61     entry->SetOwner(0);
62     TGeoManager* geom = (TGeoManager*) entry->GetObject();
63     AliGeomManager::SetGeometry(geom);
64   }else{
65     AliGeomManager::LoadGeometry(); //load geom from default CDB storage
66   }
67
68   Float_t max_trans=0.1;
69   Float_t max_rot=0.1;
70
71   const char *Sector1="PMD/Sector1"; 
72   const char *Sector2="PMD/Sector2"; 
73   const char *Sector3="PMD/Sector3"; 
74   const char *Sector4="PMD/Sector4"; 
75   
76   
77   //Sectors 1 and 4
78   Double_t dx14, dy14, dz14;          // Misalignment in X,Y and Z
79   Double_t dpsi14, dtheta14, dphi14; //  Angular displacements
80   //Sectors 2 and 3
81   Double_t dx23, dy23, dz23;          // Misalignment in X,Y and Z
82   Double_t dpsi23, dtheta23, dphi23; //  Angular displacements
83   
84   
85   
86   // At present give some random shifts
87   // generated by random numbers
88   // max_trans : Maximun shifts in X,Y,Z  in centimeters
89   // max_rot   : Maximum shifts in angles in degrees
90   // Double_t max_trans, max_rot;
91   
92   
93   TRandom *rnd   = new TRandom(4357);
94   
95   // For sectors 1 and 4
96   // Translation displacement
97   dx14     = (rnd->Uniform()-0.5)*max_trans;
98   dy14     = (rnd->Uniform()-0.5)*max_trans;
99   dz14     = (rnd->Uniform()-0.5)*max_trans;
100   //Rotation angles
101   dpsi14   = (rnd->Uniform()-0.5)*max_rot;
102   dtheta14 = (rnd->Uniform()-0.5)*max_rot;
103   dphi14   = (rnd->Uniform()-0.5)*max_rot;
104   
105   // For sectors 2 and 3
106   // Translation displacement
107   dx23     = (rnd->Uniform()-0.5)*max_trans;
108   dy23     = (rnd->Uniform()-0.5)*max_trans;
109   dz23     = (rnd->Uniform()-0.5)*max_trans;
110   //Rotation angles
111   dpsi23   = (rnd->Uniform()-0.5)*max_rot;
112   dtheta23 = (rnd->Uniform()-0.5)*max_rot;
113   dphi23   = (rnd->Uniform()-0.5)*max_rot;
114   
115   
116   //Create a TClonesArray of Align Object to store displacement Angles
117   TClonesArray *array = new TClonesArray("AliAlignObjParams",10);
118   TClonesArray &alobj = *array;
119   
120   Int_t iIndex=0; //let all modules have index=0 in a layer with no LUT
121   AliGeomManager::ELayerID iLayer = AliGeomManager::kInvalidLayer;
122   UShort_t volid = AliGeomManager::LayerToVolUID(iLayer,iIndex);
123
124   new(alobj[0]) AliAlignObjParams(Sector1, volid, dx14, dy14, dz14, dpsi14, dtheta14, dphi14, kFALSE);
125   new(alobj[1]) AliAlignObjParams(Sector2, volid, dx14, dy14, dz14, dpsi14, dtheta14, dphi14, kFALSE);
126   new(alobj[2]) AliAlignObjParams(Sector3, volid, dx23, dy23, dz23, dpsi23, dtheta23, dphi23, kFALSE);
127   new(alobj[3]) AliAlignObjParams(Sector4, volid, dx23, dy23, dz23, dpsi23, dtheta23, dphi23, kFALSE);
128   
129   if( TString(gSystem->Getenv("TOCDB")) != TString("kTRUE") ){
130     // Create a File to store the alignment data
131     const char* filename = "PMDfullMisalignment.root";
132     TFile f(filename,"RECREATE");
133     if(!f){
134       Error(macroname,"cannot open file for output\n");
135       return;
136     }
137     Info(macroname,"Saving alignment objects to the file %s", filename);
138     f.cd();
139     f.WriteObject(array,"PMDAlignObjs","kSingleKey");
140     f.Close();
141   }else{
142   // save in CDB storage
143     AliCDBMetaData* md = new AliCDBMetaData();
144     md->SetResponsible("");
145     md->SetComment("Full misalignment for PMD, produced with sigmatr=0.1 and sigmarot=0.1 in the local RS");
146     md->SetAliRootVersion(gSystem->Getenv("ARVERSION"));
147     AliCDBId id("PMD/Align/Data",0,AliCDBRunRange::Infinity());
148     storage->Put(array,id,md);
149   }
150   array->Delete();
151
152 }