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

Functions

void AlignWithBeam (const float beam[4], EdbPattern &p1, EdbPattern &p2)
 
void LinkPlate (EdbID id, int from, int nfrag, TEnv &env)
 
int main (int argc, char *argv[])
 
void MergePlate (EdbID id, int from, int nfrag)
 
void print_help_message ()
 
void set_default_link (TEnv &cenv)
 

Function Documentation

◆ AlignWithBeam()

void AlignWithBeam ( const float  beam[4],
EdbPattern p1,
EdbPattern p2 
)
244 {
245  //int deb=gEDBDEBUGLEVEL;
246  //gEDBDEBUGLEVEL=3;
248  av.eNoScaleRot = 0; // calculate shift only
249  av.eOffsetMax = 10.;
250  av.eDZ = 0.;
251  av.eDPHI = 0.;
252  av.eDoFine = 1;
253  av.eSaveCouples = 1;
254  av.SetSigma( 1, 0.007 );
255  av.eDoublets[0] = av.eDoublets[1]=1;
256  av.eDoublets[2] = av.eDoublets[3]=0.005;
257 
258  av.eSaveCouples=1;
259  av.InitOutputFile( Form( "p%.3d/%d_%d.al.avb.root", p1.ScanID().ePlate, p1.ID(), p2.ID() ) );
260  av.Align( p1, p2, 0); //-190
261  EdbAffine2D *affXY = av.eCorrL[0].GetAffineXY();
262  EdbAffine2D *affTXTY = av.eCorrL[0].GetAffineTXTY();
263 // if(av.eNcoins > eMinPeak )
264 // {
265 // if(do_shift) p1.Transform( affXY );
266 // aff.Transform( affXY );
267 // }
268  av.CloseOutputFile();
269 // return av.eNcoins;
270  //gEDBDEBUGLEVEL=deb;
271 }
Definition: EdbAffine.h:17
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
Int_t ePlate
Definition: EdbID.h:11
EdbAffine2D * GetAffineXY()
Definition: EdbLayer.h:120
EdbAffine2D * GetAffineTXTY()
Definition: EdbLayer.h:121
EdbID ScanID() const
Definition: EdbPattern.h:339
int ID() const
Definition: EdbPattern.h:328
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
Bool_t eNoScaleRot
Definition: EdbPlateAlignment.h:18
Float_t eDoublets[4]
Definition: EdbPlateAlignment.h:16
Float_t eDPHI
Definition: EdbPlateAlignment.h:15
void Align(EdbPattern &p1, EdbPattern &p2, float dz, int flag=0)
Definition: EdbPlateAlignment.cxx:62

◆ LinkPlate()

void LinkPlate ( EdbID  id,
int  from,
int  nfrag,
TEnv &  env 
)
204 {
206  sproc.eProcDirClient="..";
207 
208  EdbID id0=id; id0.ePlate=0;
209  EdbScanSet *ss = sproc.ReadScanSet(id0);
210  EdbPlateP *plate = ss->GetPlate(id.ePlate);
211 
212  EdbMosaicIO mio;
213  mio.Init( Form("p%3.3d/%d.%d.%d.%d.mos.root",
214  id.ePlate, id.eBrick, id.ePlate, id.eMajor, id.eMinor) );
215 
216  EdbLayer *mapside = mio.GetCorrMap( id.ePlate, 1 );
217  int nc=mapside->Map().Ncell();
218  if(nfrag==0) nfrag=nc;
219 
220  for( int i=from; i<nfrag; i++ )
221  {
222  EdbPattern *p1 = mio.GetFragment( id.ePlate, 1, i, true); // (plate,side,id)
223  EdbPattern *p2 = mio.GetFragment( id.ePlate, 2, i, true);
224  Log(1,"moslink::LinkPlate","fragment %d (of %d) with %d & %d mt", i,nfrag, p1->N(), p2->N() );
225  if(p1&&p2)
226  {
227  p1->SetScanID(id);
228  p2->SetScanID(id);
229 
231  link.InitOutputFile( Form("p%3.3d/%d.%d.%d.%d.%d.cp.root",
232  id.ePlate, id.eBrick, id.ePlate, id.eMajor, id.eMinor, i) );
233  link.Link( *p1, *p2, *(plate->GetLayer(2)), *(plate->GetLayer(1)), cenv );
234  link.CloseOutputFile();
235  delete p1;
236  delete p2;
237  }
238  }
239 }
bool Log(int level, const char *location, const char *fmt,...)
Definition: EdbLog.cxx:75
int Ncell() const
Definition: EdbCell2.h:49
Definition: EdbID.h:7
Definition: EdbLayer.h:40
EdbCorrectionMap & Map()
Definition: EdbLayer.h:73
Definition: EdbLinking.h:11
Definition: EdbMosaicIO.h:15
EdbPattern * GetFragment(int plate, int side, int id, bool do_corr)
Definition: EdbMosaicIO.cxx:66
void Init(const char *file, Option_t *option="")
Definition: EdbMosaicIO.cxx:16
EdbLayer * GetCorrMap(int plate, int side)
Definition: EdbMosaicIO.cxx:121
Definition: EdbPattern.h:280
void SetScanID(EdbID id)
Definition: EdbPattern.h:303
Definition: EdbBrick.h:13
Definition: EdbScanProc.h:12
TString eProcDirClient
Definition: EdbScanProc.h:14
EdbScanSet * ReadScanSet(EdbID id)
Definition: EdbScanProc.cxx:1521
Definition: EdbScanSet.h:11
Int_t N() const
Definition: EdbPattern.h:89
EdbScanProc * sproc
Definition: comptonmap.cpp:29
TEnv cenv("emrec")
ss
Definition: energy.C:62
Int_t plate
Definition: merge_Energy_SytematicSources_Electron.C:1
UInt_t id
Definition: tlg2pattern.C:118

◆ main()

int main ( int  argc,
char *  argv[] 
)
92 {
93  if (argc < 2) { print_help_message(); return 0; }
94 
95  TEnv cenv("moslinkenv");
96  gEDBDEBUGLEVEL = cenv.GetValue("moslink.EdbDebugLevel" , 1);
97  const char *env = cenv.GetValue("moslink.env" , "moslink.rootrc");
98  const char *outdir = cenv.GetValue("moslink.outdir" , "..");
99 
100  bool do_single = false;
101  bool do_set = false;
102  bool do_merge = false;
103  EdbID id;
104  int from_fragment=0;
105  int n_fragments=0;
106 
107  for(int i=1; i<argc; i++ ) {
108  char *key = argv[i];
109 
110  if(!strncmp(key,"-set=",5))
111  {
112  if(strlen(key)>5) if(id.Set(key+5)) do_set=true;
113  }
114  else if(!strncmp(key,"-id=",4))
115  {
116  if(strlen(key)>4) if(id.Set(key+4)) do_single=true;
117  }
118  else if(!strncmp(key,"-from=",6))
119  {
120  if(strlen(key)>6) from_fragment = atoi(key+6);
121  }
122  else if(!strncmp(key,"-nfrag=",7))
123  {
124  if(strlen(key)>7) n_fragments = atoi(key+7);
125  }
126  else if(!strncmp(key,"-merge",6))
127  {
128  do_merge=true;
129  }
130  else if(!strncmp(key,"-v=",3))
131  {
132  if(strlen(key)>3) gEDBDEBUGLEVEL = atoi(key+3);
133  }
134  }
135 
136  if(!(do_single||do_set)) { print_help_message(); return 0; }
137  if( do_single&&do_set ) { print_help_message(); return 0; }
138 
140  cenv.SetValue("moslink.env" , env);
141  cenv.ReadFile( cenv.GetValue("moslink.env" , "moslink.rootrc") ,kEnvLocal);
142  cenv.SetValue("moslink.outdir" , outdir);
143 
145  sproc.eProcDirClient = cenv.GetValue("moslink.outdir","..");
146  cenv.WriteFile("moslink.save.rootrc");
147 
148  printf("\n----------------------------------------------------------------------------\n");
149  printf("moslink %s\n" ,id.AsString() );
150  printf( "----------------------------------------------------------------------------\n\n");
151 
152 
153  if(do_single)
154  {
155  if(do_merge) MergePlate( id, from_fragment, n_fragments );
157  }
158  else if(do_set)
159  {
161  if(ss) {
162  int n = ss->eIDS.GetSize();
163  for(int i=0; i<n; i++) {
164  EdbID *id_pl = ss->GetID(i);
165  if(id_pl)
166  {
167  if(do_merge) MergePlate( *id_pl, from_fragment, n_fragments );
168  else LinkPlate( *id_pl, from_fragment, n_fragments, cenv);
169  }
170  }
171  }
172  }
173 
174  cenv.WriteFile("moslink.save.rootrc");
175  return 1;
176 }
bool do_set
Definition: emrec.cpp:36
const char * outdir
Definition: emrec.cpp:37
gEDBDEBUGLEVEL
Definition: energy.C:7
int n_fragments
Definition: mosalignbeam.cpp:96
int from_fragment
Definition: mosalignbeam.cpp:95

◆ MergePlate()

void MergePlate ( EdbID  id,
int  from,
int  nfrag 
)
179 {
180  if(nfrag==0)
181  {
182  TString file;
183  file.Form("p%3.3d/%d.%d.%d.%d.mos.root",
184  id.ePlate, id.eBrick, id.ePlate, id.eMajor, id.eMinor);
185  EdbMosaicIO mio;
186  mio.Init( file.Data() );
187  EdbLayer *mapside = mio.GetCorrMap( id.ePlate, 1 );
188  nfrag=mapside->Map().Ncell();
189  }
190 
191  Log(2,"MergePlate", "%s %d:%d",id.AsString(), mfrom, mfrom+nfrag);
192  TChain allcp("couples");
193 
194  for( int mid=mfrom; mid<mfrom+nfrag; mid++ ) {
195  allcp.Add( Form("p%3.3d/%d.%d.%d.%d.%d.cp.root",
196  id.ePlate, id.eBrick, id.ePlate, id.eMajor, id.eMinor, mid));
197  }
198  allcp.Merge( Form("p%3.3d/%d.%d.%d.%d.cp.root",
199  id.ePlate, id.eBrick, id.ePlate, id.eMajor, id.eMinor));
200 }
TFile * file
Definition: write_pvr.C:3

◆ print_help_message()

void print_help_message ( )
24 {
25  cout<< "\nUsage: \n";
26  cout<< "\t moslink -id=ID [-from=frag0 -nfrag=N -merge -v=DEBUG] \n";
27  cout<< "\t moslink -set=ID [-from=frag0 -nfrag=N -merge -v=DEBUG] \n";
28 
29  cout<< "\t\t ID - id of the data piece or data set formed as BRICK.PLATE.MAJOR.MINOR \n";
30  cout<< "\t\t frag0 - the first fragment (default: 0) \n";
31  cout<< "\t\t N - number of fragments to be processed (default: upto 1000000, stop at first empty) \n";
32  cout<< "\t\t merge - merge all fragments into one cp file \n";
33 
34  cout<< "\n If the data location directory if not explicitly defined\n";
35  cout<< " the current directory will be assumed to be the brick directory \n";
36  cout<< "\n If the parameters file (moslink.rootrc) is not presented - the default \n";
37  cout<< " parameters will be used. After the execution them are saved into moslink.save.rootrc file\n";
38  cout<<endl;
39 }

◆ set_default_link()

void set_default_link ( TEnv &  cenv)
43 {
44  // default parameters for the new linking
45  cenv.SetValue("fedra.link.AFID" , 1 ); // 1 is usually fine for scanned data; for the db-read data use 0!
46  cenv.SetValue("fedra.link.DoImageCorr" , 0 );
47  cenv.SetValue("fedra.link.ImageCorrSide1" , "1. 1. 0.");
48  cenv.SetValue("fedra.link.ImageCorrSide2" , "1. 1. 0.");
49 
50  cenv.SetValue("fedra.link.DoImageMatrixCorr" , 0 );
51  cenv.SetValue("fedra.link.ImageMatrixCorrSide1" , "");
52  cenv.SetValue("fedra.link.ImageMatrixCorrSide2" , "");
53 
54  cenv.SetValue("fedra.link.CheckUpDownOffset" , 1 ); // check dXdY offsets between up and correspondent down views
55  cenv.SetValue("fedra.link.BinOK" , 6. );
56  cenv.SetValue("fedra.link.NcorrMin" , 100 );
57  cenv.SetValue("fedra.link.DoCorrectShrinkage" , false );
58  cenv.SetValue("fedra.link.read.InvertSides" , 0 );
59  cenv.SetValue("fedra.link.read.HeaderCut" , "1" );
60  cenv.SetValue("fedra.link.read.UseDensityAsW" , false );
61  cenv.SetValue("fedra.link.read.ICUT" , "-1 -500. 500. -500. 500. -1. 1. -1. 1. 0. 50.");
62  cenv.SetValue("fedra.link.RemoveDoublets" , "1 2. .01 1"); //yes/no dr dt checkview(0,1,2)
63  cenv.SetValue("fedra.link.DumpDoubletsTree" , true );
64  cenv.SetValue("fedra.link.shr.NsigmaEQ" , 7.5 );
65  cenv.SetValue("fedra.link.shr.Shr0" , .990 );
66  cenv.SetValue("fedra.link.shr.DShr" , .3 );
67  cenv.SetValue("fedra.link.shr.ThetaLimits" ,"0.0 1.");
68  cenv.SetValue("fedra.link.DoCorrectAngles" , true );
69  cenv.SetValue("fedra.link.ang.Chi2max" , 1.5 );
70  cenv.SetValue("fedra.link.DoFullLinking" , true );
71  cenv.SetValue("fedra.link.full.NsigmaEQ" , 5.5 );
72  cenv.SetValue("fedra.link.full.DR" , 20. );
73  cenv.SetValue("fedra.link.full.DT" , 0.1 );
74  cenv.SetValue("fedra.link.full.CHI2Pmax" , 3. );
75  cenv.SetValue("fedra.link.DoSaveCouples" , true );
76  cenv.SetValue("fedra.link.Sigma0" , "1 1 0.007 0.007");
77  cenv.SetValue("fedra.link.PulsRamp0" , "6 9");
78  cenv.SetValue("fedra.link.PulsRamp04" , "6 9");
79  cenv.SetValue("fedra.link.Degrad" , 5 );
80 
81  cenv.SetValue("fedra.link.LLfunction" , "0.256336-0.16489*x+2.11098*x*x" );
82  cenv.SetValue("fedra.link.CPRankingAlg" , 0 );
83 
84  cenv.SetValue("emlink.reportfileformat" , "pdf" );
85 
86  cenv.SetValue("emlink.outdir" , "..");
87  cenv.SetValue("emlink.env" , "link.rootrc");
88  cenv.SetValue("emlink.EdbDebugLevel" , 1);
89 }