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