FEDRA emulsion software from the OPERA Collaboration
emalignraw.cpp File Reference
#include <string.h>
#include <iostream>
#include <TRint.h>
#include <TEnv.h>
#include "EdbLog.h"
#include "EdbScanProc.h"
#include "EdbPlateAlignment.h"
Include dependency graph for emalignraw.cpp:

Functions

int AlignRaw (EdbID id1, EdbID id2, TEnv &cenv, EdbAffine2D *applyAff)
 
void AlignRawSet (EdbID idset1, EdbID idset2, TEnv &cenv)
 
int main (int argc, char *argv[])
 
void print_help_message ()
 
void set_default (TEnv &cenv)
 

Function Documentation

◆ AlignRaw()

int AlignRaw ( EdbID  id1,
EdbID  id2,
TEnv &  cenv,
EdbAffine2D applyAff 
)
162 {
163  // Align raw segments patterns. Typical application: align 2 different scannings of the same emulsion plate.
164 
166  sproc.eProcDirClient=cenv.GetValue("emalignraw.outdir" , "..");
167 
168  int npat=0;
169  Log(1,"\nAlignRaw","%s_%s", id1.AsString(), id2.AsString() );
170  int side1 = cenv.GetValue("fedra.alignRaw.side1" , 1);
171  int side2 = cenv.GetValue("fedra.alignRaw.side2" , 1);
172  float z1 = cenv.GetValue("fedra.alignRaw.Z1" , 0);
173  float z2 = cenv.GetValue("fedra.alignRaw.Z2" , 0);
174  float sigmaR = cenv.GetValue("fedra.alignRaw.sigmaR" , 2.5 );
175  float sigmaT = cenv.GetValue("fedra.alignRaw.sigmaT" , 0.005 );
176  float offsetMax = cenv.GetValue("fedra.alignRaw.offsetMax" , 500. );
177  int path1 = cenv.GetValue("fedra.alignRaw.path1" , -1 );
178  int path2 = cenv.GetValue("fedra.alignRaw.path2" , -1 );
179 
180  float DZ = cenv.GetValue("fedra.alignRaw.DZ" , 25. );
181  float DPHI = cenv.GetValue("fedra.alignRaw.DPHI" , 0.02 );
182 
183  EdbID idset1 =id1; idset1.ePlate =0;
184  EdbID idset2 =id2; idset2.ePlate =0;
185  EdbRunAccess r1;
186  EdbRunAccess r2;
187  r1.eAFID = cenv.GetValue("fedra.alignRaw.AFID1" , 1);
188  r2.eAFID = cenv.GetValue("fedra.alignRaw.AFID2" , 1);
189  r1.eHeaderCut = cenv.GetValue("fedra.alignRaw.HeaderCut1" , "1");
190  r2.eHeaderCut = cenv.GetValue("fedra.alignRaw.HeaderCut2" , "1");
191 
192  if(!sproc.InitRunAccessNew(r1,idset1,id1.ePlate)) return 0;
193  if(!sproc.InitRunAccessNew(r2,idset2,id2.ePlate)) return 0;
194 
195  r1.AddSegmentCut(1,cenv.GetValue("fedra.alignRaw.ICUT1" , "-1") );
196  r2.AddSegmentCut(1,cenv.GetValue("fedra.alignRaw.ICUT2" , "-1") );
197 
198  EdbPattern p1, p2;
199 
200  r1.GetPatternDataForPrediction( path1, side1, p1 );
201  r2.GetPatternDataForPrediction( path2, side2, p2 );
202 
203  /*
204  EdbScanSet *set1 = sproc.ReadScanSet(idset1);
205  if(set1) {
206  EdbPlateP *plate1 = set1->GetPlate(id1.ePlate);
207  plate1->GetAffineXY()->Print();
208  if(plate1) p1.Transform( plate1->GetAffineXY() );
209  }
210  if(applyAff) p1.Transform(applyAff);
211 
212  EdbScanSet *set2 = sproc.ReadScanSet(idset2);
213  if(set2) {
214  EdbPlateP *plate2 = set2->GetPlate(id2.ePlate);
215  plate2->GetAffineXY()->Print();
216  if(plate2) p2.Transform( plate2->GetAffineXY() );
217  }
218  if(applyAff) p2.Transform(applyAff);
219  */
220 
221  /*
222  //r2.Print();
223  if(path2>=0) r2.GetPatternDataForPrediction( path2, side2, p2 );
224  else {
225  float xmin=p1.Xmin(), xmax=p1.Xmax();
226  float ymin=p1.Ymin(), ymax=p1.Ymax();
227  EdbSegP s(0, (xmin+xmax)/2., (ymin+ymax)/2., 0,0);
228  float dx=(xmax-xmin)/2., dy=(ymax-ymin)/2.;
229  float size = Sqrt( dx*dx+dy*dy ) + offsetMax+200.;
230  if(applyAff) s.Transform(applyAff);
231  r2.GetPatternXY(s, side2, p2, size);
232  }
233  */
235  av.SetSigma(sigmaR,sigmaT);
236  av.eOffsetMax = offsetMax;
237  av.eDZ = DZ;
238  av.eDPHI = DPHI;
239  av.eDoFine = cenv.GetValue("fedra.alignRaw.DoFine" , 1 );
240  av.eSaveCouples = cenv.GetValue("fedra.alignRaw.SaveCouples" , 1);
241  TString dataout; sproc.MakeAffName(dataout,id1,id2,"al.root");
242  av.InitOutputFile( dataout );
243 
244  av.Align( p1, p2, z2-z1);
245  av.CloseOutputFile();
246 
247  //av.eCorrL[0].Print();
248  sproc.UpdateAFFPar( id1, id2, av.eCorrL[0] );
249  return npat;
250 }
bool Log(int level, const char *location, const char *fmt,...)
Definition: EdbLog.cxx:75
Int_t npat
Definition: Xi2HatStartScript.C:33
EdbLayer eCorrL[2]
Definition: EdbAlignmentV.h:25
void InitOutputFile(const char *file="report_al.root", const char *option="RECREATE")
Definition: EdbAlignmentV.cxx:55
void CloseOutputFile()
Definition: EdbAlignmentV.cxx:64
Definition: EdbID.h:7
char * AsString() const
Definition: EdbID.cxx:24
Int_t ePlate
Definition: EdbID.h:11
Definition: EdbPattern.h:280
Definition: EdbPlateAlignment.h:8
Float_t eOffsetMax
Definition: EdbPlateAlignment.h:12
Bool_t eSaveCouples
Definition: EdbPlateAlignment.h:24
void SetSigma(float spos, float sang)
Definition: EdbPlateAlignment.h:56
Bool_t eDoFine
Definition: EdbPlateAlignment.h:22
Float_t eDZ
Definition: EdbPlateAlignment.h:14
Float_t eDPHI
Definition: EdbPlateAlignment.h:15
void Align(EdbPattern &p1, EdbPattern &p2, float dz, int flag=0)
Definition: EdbPlateAlignment.cxx:62
Definition: EdbRunAccess.h:22
void AddSegmentCut(int xi, const char *cutline)
Definition: EdbRunAccess.cxx:1317
Int_t eAFID
Definition: EdbRunAccess.h:25
TCut eHeaderCut
Definition: EdbRunAccess.h:45
int GetPatternDataForPrediction(int id, int side, EdbPattern &pat)
Definition: EdbRunAccess.cxx:576
Definition: EdbScanProc.h:12
bool UpdateAFFPar(EdbID id1, EdbID id2, EdbLayer &l, EdbAffine2D *aff0=0)
Definition: EdbScanProc.cxx:1026
void MakeAffName(TString &s, int id1[4], int id2[4], const char *suffix="aff.par")
Definition: EdbScanProc.cxx:1917
bool InitRunAccessNew(EdbRunAccess &ra, EdbID id, EdbPlateP &plate, bool do_update=false)
Definition: EdbScanProc.cxx:3182
TString eProcDirClient
Definition: EdbScanProc.h:14
EdbScanProc * sproc
Definition: comptonmap.cpp:29
TEnv cenv("emrec")
float DZ
Definition: hwinit.C:66

◆ AlignRawSet()

void AlignRawSet ( EdbID  idset1,
EdbID  idset2,
TEnv &  cenv 
)
142 {
143  // assuming that exist the scan sets for idset1 and idset2
144  // for each plate do the alignment raw from 1 to 2 and write id1_id2.aff.par
146  sproc.eProcDirClient=cenv.GetValue("emalignraw.outdir" , "..");
147 
148  EdbAffine2D aff(cenv.GetValue("emalignRaw.applyAff" , "1 0 0 1 0 0") );
149 
150  EdbScanSet *ss1 = sproc.ReadScanSet(idset1); if(!ss1) return;
151  EdbScanSet *ss2 = sproc.ReadScanSet(idset2); if(!ss2) return;
152  int n = ss1->eIDS.GetEntries();
153  for(int i=0; i<n; i++) {
154  EdbID *id1 = ss1->GetID(i);
155  EdbID *id2 = ss2->FindPlateID(id1->ePlate);
156  if(id2) AlignRaw(*id1,*id2,cenv, &aff);
157  }
158 }
Definition: EdbAffine.h:17
EdbScanSet * ReadScanSet(EdbID id)
Definition: EdbScanProc.cxx:1521
Definition: EdbScanSet.h:11
TList eIDS
Definition: EdbScanSet.h:17
EdbID * FindPlateID(Int_t p)
Definition: EdbScanSet.cxx:482
EdbID * GetID(Int_t i)
Definition: EdbScanSet.h:47
int AlignRaw(EdbID id1, EdbID id2, TEnv &cenv, EdbAffine2D *applyAff)
Definition: emalignraw.cpp:161

◆ main()

int main ( int  argc,
char *  argv[] 
)
66 {
67  if (argc < 2) { print_help_message(); return 0; }
68 
69  TEnv cenv("alignrawenv");
71  gEDBDEBUGLEVEL = cenv.GetValue("emalignraw.EdbDebugLevel" , 1);
72  const char *env = cenv.GetValue("emalignraw.env" , "alignraw.rootrc");
73  const char *outdir = cenv.GetValue("emalignraw.outdir" , "..");
74 
75  bool do_single = false;
76  bool do_set = false;
77  EdbID idA,idB;
78 
79  for(int i=1; i<argc; i++ ) {
80  char *key = argv[i];
81 
82  if(!strncmp(key,"-setA=",6))
83  {
84  if(strlen(key)>6) if(idA.Set(key+6)) do_set=true;
85  }
86  else if(!strncmp(key,"-setB=",6))
87  {
88  if(strlen(key)>6) if(idB.Set(key+6)) do_set=true;
89  }
90  else if(!strncmp(key,"-A=",3))
91  {
92  if(strlen(key)>3) if(idA.Set(key+3)) do_single=true;
93  }
94  else if(!strncmp(key,"-B=",3))
95  {
96  if(strlen(key)>3) if(idB.Set(key+3)) do_single=true;
97  }
98  else if(!strncmp(key,"-env=",5))
99  {
100  if(strlen(key)>5) env=key+5;
101  }
102  else if(!strncmp(key,"-o=",3))
103  {
104  if(strlen(key)>3) outdir = key+3;
105  }
106  else if(!strncmp(key,"-v=",3))
107  {
108  if(strlen(key)>3) gEDBDEBUGLEVEL = atoi(key+3);
109  }
110  }
111 
112  if(!(do_single||do_set)) { print_help_message(); return 0; }
113  if( do_single&&do_set ) { print_help_message(); return 0; }
114 
115  cenv.SetValue("emalignraw.env" , env);
116  cenv.ReadFile( cenv.GetValue("emalignraw.env" , "alignraw.rootrc") ,kEnvLocal);
117  cenv.SetValue("emalignraw.outdir" , outdir);
118 
120  sproc.eProcDirClient = cenv.GetValue("emalignraw.outdir","..");
121  cenv.WriteFile("alignraw.save.rootrc");
122 
123  printf("\n----------------------------------------------------------------------------\n");
124  printf("alignraw %s and %s\n" ,idA.AsString(),idB.AsString() );
125  printf( "----------------------------------------------------------------------------\n\n");
126 
127  if(do_set)
128  {
129  AlignRawSet(idA,idB,cenv);
130  }
131  else if(do_single)
132  {
133  AlignRaw(idA,idB,cenv, 0);
134  }
135 
136  cenv.WriteFile("alignraw.save.rootrc");
137  return 1;
138 }
bool Set(const char *id_string)
Definition: EdbID.cxx:17
void set_default(TEnv &cenv)
Definition: emalignraw.cpp:33
void print_help_message()
Definition: emalignraw.cpp:17
void AlignRawSet(EdbID idset1, EdbID idset2, TEnv &cenv)
Definition: emalignraw.cpp:141
bool do_set
Definition: emrec.cpp:36
const char * outdir
Definition: emrec.cpp:37
gEDBDEBUGLEVEL
Definition: energy.C:7

◆ print_help_message()

void print_help_message ( )
18 {
19  cout<< "\nUsage: \n";
20  cout<< "\t emalignraw -A=idA -B=idB [-v=DEBUG] \n";
21  cout<< "\t emalignraw -setA=IDA -setB=IDB [-v=DEBUG] \n\n";
22 
23  cout<< "\t\t idA - id of the first piece formed as BRICK.PLATE.MAJOR.MINOR \n";
24  cout<< "\t\t idB - id of the second piece formed as BRICK.PLATE.MAJOR.MINOR \n";
25 
26  cout<< "\n If the data location directory if not explicitly defined\n";
27  cout<< " the current directory will be assumed to be the brick directory \n";
28  cout<< "\n If the parameters file (alignraw.rootrc) is not presented - the default \n";
29  cout<< " parameters will be used. After the execution them are saved into alignraw.save.rootrc file\n";
30  cout<<endl;
31 }

◆ set_default()

void set_default ( TEnv &  cenv)
34 {
35  // default parameters for the new alignrawment
36 
37  cenv.SetValue("fedra.alignRaw.offsetMax" , 500. );
38  cenv.SetValue("fedra.alignRaw.DZ" , 25. );
39  cenv.SetValue("fedra.alignRaw.DPHI" , 0.02 );
40  cenv.SetValue("fedra.alignRaw.AFID1" , 1);
41  cenv.SetValue("fedra.alignRaw.AFID2" , 1);
42  cenv.SetValue("fedra.alignRaw.side1" , 1);
43  cenv.SetValue("fedra.alignRaw.side2" , 1);
44  cenv.SetValue("fedra.alignRaw.HeaderCut1" , "1" );
45  cenv.SetValue("fedra.alignRaw.HeaderCut2" , "1" );
46  cenv.SetValue("fedra.alignRaw.Z1" , 0);
47  cenv.SetValue("fedra.alignRaw.Z2" , 0);
48  cenv.SetValue("fedra.alignRaw.sigmaR" , 2.5 );
49  cenv.SetValue("fedra.alignRaw.sigmaT" , 0.005 );
50 
51  cenv.SetValue("fedra.alignRaw.ICUT1" , "-1 -500. 500. -500. 500. -1. 1. -1. 1. 8. 50.");
52  cenv.SetValue("fedra.alignRaw.ICUT2" , "-1 -500. 500. -500. 500. -1. 1. -1. 1. 8. 50.");
53 
54  cenv.SetValue("fedra.alignRaw.path1" , -1 );
55  cenv.SetValue("fedra.alignRaw.path2" , -1 );
56 
57  cenv.SetValue("fedra.alignRaw.DoFine" , 1 );
58  cenv.SetValue("fedra.alignRaw.SaveCouples" , 1 );
59 
60  cenv.SetValue("emalignRaw.outdir" , ".." );
61  cenv.SetValue("emalignRaw.env" , "alignraw.rootrc");
62  cenv.SetValue("emalignRaw.EdbDebugLevel" , 1 );
63 }