diff --git a/CMakeLists.txt b/CMakeLists.txt index f567192..099d4c5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -47,17 +47,17 @@ INCLUDE_DIRECTORIES( SYSTEM ${MarlinUtil_INCLUDE_DIRS} ) LINK_LIBRARIES( ${MarlinUtil_LIBRARIES} ) ADD_DEFINITIONS( ${MarlinUtil_DEFINITIONS} ) -FIND_PACKAGE( MarlinTrk REQUIRED ) +FIND_PACKAGE( MarlinTrk REQUIRED ) INCLUDE_DIRECTORIES( SYSTEM ${MarlinTrk_INCLUDE_DIRS} ) LINK_LIBRARIES( ${MarlinTrk_LIBRARIES} ) ADD_DEFINITIONS( ${MarlinTrk_DEFINITIONS} ) -FIND_PACKAGE( KiTrack REQUIRED ) +FIND_PACKAGE( KiTrack REQUIRED ) INCLUDE_DIRECTORIES( SYSTEM ${KiTrack_INCLUDE_DIRS} ) LINK_LIBRARIES( ${KiTrack_LIBRARIES} ) ADD_DEFINITIONS( ${KiTrack_DEFINITIONS} ) -FIND_PACKAGE( KiTrackMarlin REQUIRED ) +FIND_PACKAGE( KiTrackMarlin REQUIRED ) INCLUDE_DIRECTORIES( SYSTEM ${KiTrackMarlin_INCLUDE_DIRS} ) LINK_LIBRARIES( ${KiTrackMarlin_LIBRARIES} ) ADD_DEFINITIONS( ${KiTrackMarlin_DEFINITIONS} ) @@ -78,25 +78,25 @@ include(DD4hep_XML_setup) INCLUDE_DIRECTORIES( BEFORE SYSTEM ${DD4hep_INCLUDE_DIRS} ) LINK_LIBRARIES( ${DD4hep_LIBRARIES} ${DD4hep_COMPONENT_LIBRARIES} ) -#FIND_PACKAGE( ROOT REQUIRED ) +#FIND_PACKAGE( ROOT REQUIRED ) INCLUDE_DIRECTORIES( SYSTEM ${ROOT_INCLUDE_DIRS} ) LINK_LIBRARIES( ${ROOT_LIBRARIES} ) ADD_DEFINITIONS( ${ROOT_DEFINITIONS} ) -FIND_PACKAGE( GSL REQUIRED ) +FIND_PACKAGE( GSL REQUIRED ) INCLUDE_DIRECTORIES( SYSTEM ${GSL_INCLUDE_DIRS} ) LINK_LIBRARIES( ${GSL_LIBRARIES} ) ADD_DEFINITIONS( ${GSL_DEFINITIONS} ) -FIND_PACKAGE( RAIDA REQUIRED ) +FIND_PACKAGE( RAIDA REQUIRED ) INCLUDE_DIRECTORIES( SYSTEM ${RAIDA_INCLUDE_DIRS} ) LINK_LIBRARIES( ${RAIDA_LIBRARIES} ) ADD_DEFINITIONS( ${RAIDA_DEFINITIONS} ) -### FIXME: depedence from DDKalTest is here only for getting the cellIDEndcoding +### FIXME: depedence from DDKalTest is here only for getting the cellIDEndcoding ### if we move the implementation to LCIO it can go away FIND_PACKAGE( DDKalTest REQUIRED ) INCLUDE_DIRECTORIES( SYSTEM ${DDKalTest_INCLUDE_DIRS} ) @@ -134,7 +134,7 @@ IF(CMAKE_GENERATOR MATCHES "Xcode") ADD_SHARED_LIBRARY( ${PROJECT_NAME} ${library_sources} ${library_headers}) ELSE() ADD_SHARED_LIBRARY( ${PROJECT_NAME} ${library_sources} ) -ENDIF() +ENDIF() INSTALL_SHARED_LIBRARY( ${PROJECT_NAME} DESTINATION lib ) diff --git a/doc/CMakeLists.txt b/doc/CMakeLists.txt index 37e205b..57591e1 100644 --- a/doc/CMakeLists.txt +++ b/doc/CMakeLists.txt @@ -11,7 +11,7 @@ IF( DOXYGEN_FOUND ) # build documentation out-of-source SET( DOC_SRC_DIR "${PROJECT_SOURCE_DIR}/doc" ) SET( DOC_BIN_DIR "${PROJECT_BINARY_DIR}/docbuild" ) - + # directories to search for documentation SET( DOX_INPUT ../source ) diff --git a/doc/Doxyfile b/doc/Doxyfile index aeb05ae..4be7be4 100644 --- a/doc/Doxyfile +++ b/doc/Doxyfile @@ -14,207 +14,207 @@ # Project related configuration options #--------------------------------------------------------------------------- -# The PROJECT_NAME tag is a single word (or a sequence of words surrounded +# The PROJECT_NAME tag is a single word (or a sequence of words surrounded # by quotes) that should identify the project. PROJECT_NAME = $(DOX_PROJECT_NAME) -# The PROJECT_NUMBER tag can be used to enter a project or revision number. -# This could be handy for archiving the generated documentation or +# The PROJECT_NUMBER tag can be used to enter a project or revision number. +# This could be handy for archiving the generated documentation or # if some version control system is used. PROJECT_NUMBER = $(DOX_PROJECT_NUMBER) -# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) -# base path where the generated documentation will be put. -# If a relative path is entered, it will be relative to the location +# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) +# base path where the generated documentation will be put. +# If a relative path is entered, it will be relative to the location # where doxygen was started. If left blank the current directory will be used. OUTPUT_DIRECTORY = $(DOX_OUTPUT_DIRECTORY) -# If the CREATE_SUBDIRS tag is set to YES, then doxygen will create -# 4096 sub-directories (in 2 levels) under the output directory of each output -# format and will distribute the generated files over these directories. -# Enabling this option can be useful when feeding doxygen a huge amount of -# source files, where putting all generated files in the same directory would +# If the CREATE_SUBDIRS tag is set to YES, then doxygen will create +# 4096 sub-directories (in 2 levels) under the output directory of each output +# format and will distribute the generated files over these directories. +# Enabling this option can be useful when feeding doxygen a huge amount of +# source files, where putting all generated files in the same directory would # otherwise cause performance problems for the file system. CREATE_SUBDIRS = NO -# The OUTPUT_LANGUAGE tag is used to specify the language in which all -# documentation generated by doxygen is written. Doxygen will use this -# information to generate all constant output in the proper language. -# The default language is English, other supported languages are: -# Brazilian, Catalan, Chinese, Chinese-Traditional, Croatian, Czech, Danish, -# Dutch, Finnish, French, German, Greek, Hungarian, Italian, Japanese, -# Japanese-en (Japanese with English messages), Korean, Korean-en, Norwegian, -# Polish, Portuguese, Romanian, Russian, Serbian, Slovak, Slovene, Spanish, +# The OUTPUT_LANGUAGE tag is used to specify the language in which all +# documentation generated by doxygen is written. Doxygen will use this +# information to generate all constant output in the proper language. +# The default language is English, other supported languages are: +# Brazilian, Catalan, Chinese, Chinese-Traditional, Croatian, Czech, Danish, +# Dutch, Finnish, French, German, Greek, Hungarian, Italian, Japanese, +# Japanese-en (Japanese with English messages), Korean, Korean-en, Norwegian, +# Polish, Portuguese, Romanian, Russian, Serbian, Slovak, Slovene, Spanish, # Swedish, and Ukrainian. OUTPUT_LANGUAGE = English -# This tag can be used to specify the encoding used in the generated output. -# The encoding is not always determined by the language that is chosen, -# but also whether or not the output is meant for Windows or non-Windows users. -# In case there is a difference, setting the USE_WINDOWS_ENCODING tag to YES -# forces the Windows encoding (this is the default for the Windows binary), -# whereas setting the tag to NO uses a Unix-style encoding (the default for +# This tag can be used to specify the encoding used in the generated output. +# The encoding is not always determined by the language that is chosen, +# but also whether or not the output is meant for Windows or non-Windows users. +# In case there is a difference, setting the USE_WINDOWS_ENCODING tag to YES +# forces the Windows encoding (this is the default for the Windows binary), +# whereas setting the tag to NO uses a Unix-style encoding (the default for # all platforms other than Windows). USE_WINDOWS_ENCODING = NO -# If the BRIEF_MEMBER_DESC tag is set to YES (the default) Doxygen will -# include brief member descriptions after the members that are listed in -# the file and class documentation (similar to JavaDoc). +# If the BRIEF_MEMBER_DESC tag is set to YES (the default) Doxygen will +# include brief member descriptions after the members that are listed in +# the file and class documentation (similar to JavaDoc). # Set to NO to disable this. BRIEF_MEMBER_DESC = YES -# If the REPEAT_BRIEF tag is set to YES (the default) Doxygen will prepend -# the brief description of a member or function before the detailed description. -# Note: if both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the +# If the REPEAT_BRIEF tag is set to YES (the default) Doxygen will prepend +# the brief description of a member or function before the detailed description. +# Note: if both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the # brief descriptions will be completely suppressed. REPEAT_BRIEF = YES -# This tag implements a quasi-intelligent brief description abbreviator -# that is used to form the text in various listings. Each string -# in this list, if found as the leading text of the brief description, will be -# stripped from the text and the result after processing the whole list, is -# used as the annotated text. Otherwise, the brief description is used as-is. -# If left blank, the following values are used ("$name" is automatically -# replaced with the name of the entity): "The $name class" "The $name widget" -# "The $name file" "is" "provides" "specifies" "contains" +# This tag implements a quasi-intelligent brief description abbreviator +# that is used to form the text in various listings. Each string +# in this list, if found as the leading text of the brief description, will be +# stripped from the text and the result after processing the whole list, is +# used as the annotated text. Otherwise, the brief description is used as-is. +# If left blank, the following values are used ("$name" is automatically +# replaced with the name of the entity): "The $name class" "The $name widget" +# "The $name file" "is" "provides" "specifies" "contains" # "represents" "a" "an" "the" -ABBREVIATE_BRIEF = +ABBREVIATE_BRIEF = -# If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then -# Doxygen will generate a detailed section even if there is only a brief +# If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then +# Doxygen will generate a detailed section even if there is only a brief # description. ALWAYS_DETAILED_SEC = NO -# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all -# inherited members of a class in the documentation of that class as if those -# members were ordinary class members. Constructors, destructors and assignment +# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all +# inherited members of a class in the documentation of that class as if those +# members were ordinary class members. Constructors, destructors and assignment # operators of the base classes will not be shown. INLINE_INHERITED_MEMB = NO -# If the FULL_PATH_NAMES tag is set to YES then Doxygen will prepend the full -# path before files name in the file list and in the header files. If set +# If the FULL_PATH_NAMES tag is set to YES then Doxygen will prepend the full +# path before files name in the file list and in the header files. If set # to NO the shortest path that makes the file name unique will be used. FULL_PATH_NAMES = NO -# If the FULL_PATH_NAMES tag is set to YES then the STRIP_FROM_PATH tag -# can be used to strip a user-defined part of the path. Stripping is -# only done if one of the specified strings matches the left-hand part of -# the path. The tag can be used to show relative paths in the file list. -# If left blank the directory from which doxygen is run is used as the +# If the FULL_PATH_NAMES tag is set to YES then the STRIP_FROM_PATH tag +# can be used to strip a user-defined part of the path. Stripping is +# only done if one of the specified strings matches the left-hand part of +# the path. The tag can be used to show relative paths in the file list. +# If left blank the directory from which doxygen is run is used as the # path to strip. -STRIP_FROM_PATH = +STRIP_FROM_PATH = -# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of -# the path mentioned in the documentation of a class, which tells -# the reader which header file to include in order to use a class. -# If left blank only the name of the header file containing the class -# definition is used. Otherwise one should specify the include paths that +# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of +# the path mentioned in the documentation of a class, which tells +# the reader which header file to include in order to use a class. +# If left blank only the name of the header file containing the class +# definition is used. Otherwise one should specify the include paths that # are normally passed to the compiler using the -I flag. -STRIP_FROM_INC_PATH = +STRIP_FROM_INC_PATH = -# If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter -# (but less readable) file names. This can be useful is your file systems +# If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter +# (but less readable) file names. This can be useful is your file systems # doesn't support long names like on DOS, Mac, or CD-ROM. SHORT_NAMES = NO -# If the JAVADOC_AUTOBRIEF tag is set to YES then Doxygen -# will interpret the first line (until the first dot) of a JavaDoc-style -# comment as the brief description. If set to NO, the JavaDoc -# comments will behave just like the Qt-style comments (thus requiring an +# If the JAVADOC_AUTOBRIEF tag is set to YES then Doxygen +# will interpret the first line (until the first dot) of a JavaDoc-style +# comment as the brief description. If set to NO, the JavaDoc +# comments will behave just like the Qt-style comments (thus requiring an # explicit @brief command for a brief description. JAVADOC_AUTOBRIEF = YES -# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make Doxygen -# treat a multi-line C++ special comment block (i.e. a block of //! or /// -# comments) as a brief description. This used to be the default behaviour. -# The new default is to treat a multi-line C++ comment block as a detailed +# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make Doxygen +# treat a multi-line C++ special comment block (i.e. a block of //! or /// +# comments) as a brief description. This used to be the default behaviour. +# The new default is to treat a multi-line C++ comment block as a detailed # description. Set this tag to YES if you prefer the old behaviour instead. MULTILINE_CPP_IS_BRIEF = NO -# If the DETAILS_AT_TOP tag is set to YES then Doxygen +# If the DETAILS_AT_TOP tag is set to YES then Doxygen # will output the detailed description near the top, like JavaDoc. -# If set to NO, the detailed description appears after the member +# If set to NO, the detailed description appears after the member # documentation. DETAILS_AT_TOP = NO -# If the INHERIT_DOCS tag is set to YES (the default) then an undocumented -# member inherits the documentation from any documented member that it +# If the INHERIT_DOCS tag is set to YES (the default) then an undocumented +# member inherits the documentation from any documented member that it # re-implements. INHERIT_DOCS = YES -# If the SEPARATE_MEMBER_PAGES tag is set to YES, then doxygen will produce -# a new page for each member. If set to NO, the documentation of a member will +# If the SEPARATE_MEMBER_PAGES tag is set to YES, then doxygen will produce +# a new page for each member. If set to NO, the documentation of a member will # be part of the file/class/namespace that contains it. SEPARATE_MEMBER_PAGES = NO -# The TAB_SIZE tag can be used to set the number of spaces in a tab. +# The TAB_SIZE tag can be used to set the number of spaces in a tab. # Doxygen uses this value to replace tabs by spaces in code fragments. TAB_SIZE = 8 -# This tag can be used to specify a number of aliases that acts -# as commands in the documentation. An alias has the form "name=value". -# For example adding "sideeffect=\par Side Effects:\n" will allow you to -# put the command \sideeffect (or @sideeffect) in the documentation, which -# will result in a user-defined paragraph with heading "Side Effects:". +# This tag can be used to specify a number of aliases that acts +# as commands in the documentation. An alias has the form "name=value". +# For example adding "sideeffect=\par Side Effects:\n" will allow you to +# put the command \sideeffect (or @sideeffect) in the documentation, which +# will result in a user-defined paragraph with heading "Side Effects:". # You can put \n's in the value part of an alias to insert newlines. -ALIASES = +ALIASES = -# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C -# sources only. Doxygen will then generate output that is more tailored for C. -# For instance, some of the names that are used will be different. The list +# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C +# sources only. Doxygen will then generate output that is more tailored for C. +# For instance, some of the names that are used will be different. The list # of all members will be omitted, etc. OPTIMIZE_OUTPUT_FOR_C = NO -# Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java -# sources only. Doxygen will then generate output that is more tailored for Java. -# For instance, namespaces will be presented as packages, qualified scopes +# Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java +# sources only. Doxygen will then generate output that is more tailored for Java. +# For instance, namespaces will be presented as packages, qualified scopes # will look different, etc. OPTIMIZE_OUTPUT_JAVA = NO -# If you use STL classes (i.e. std::string, std::vector, etc.) but do not want to -# include (a tag file for) the STL sources as input, then you should -# set this tag to YES in order to let doxygen match functions declarations and -# definitions whose arguments contain STL classes (e.g. func(std::string); v.s. -# func(std::string) {}). This also make the inheritance and collaboration +# If you use STL classes (i.e. std::string, std::vector, etc.) but do not want to +# include (a tag file for) the STL sources as input, then you should +# set this tag to YES in order to let doxygen match functions declarations and +# definitions whose arguments contain STL classes (e.g. func(std::string); v.s. +# func(std::string) {}). This also make the inheritance and collaboration # diagrams that involve STL classes more complete and accurate. BUILTIN_STL_SUPPORT = NO -# If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC -# tag is set to YES, then doxygen will reuse the documentation of the first -# member in the group (if any) for the other members of the group. By default +# If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC +# tag is set to YES, then doxygen will reuse the documentation of the first +# member in the group (if any) for the other members of the group. By default # all members of a group must be documented explicitly. DISTRIBUTE_GROUP_DOC = NO -# Set the SUBGROUPING tag to YES (the default) to allow class member groups of -# the same type (for instance a group of public functions) to be put as a -# subgroup of that type (e.g. under the Public Functions section). Set it to -# NO to prevent subgrouping. Alternatively, this can be done per class using +# Set the SUBGROUPING tag to YES (the default) to allow class member groups of +# the same type (for instance a group of public functions) to be put as a +# subgroup of that type (e.g. under the Public Functions section). Set it to +# NO to prevent subgrouping. Alternatively, this can be done per class using # the \nosubgrouping command. SUBGROUPING = YES @@ -223,327 +223,327 @@ SUBGROUPING = YES # Build related configuration options #--------------------------------------------------------------------------- -# If the EXTRACT_ALL tag is set to YES doxygen will assume all entities in -# documentation are documented, even if no documentation was available. -# Private class members and static file members will be hidden unless +# If the EXTRACT_ALL tag is set to YES doxygen will assume all entities in +# documentation are documented, even if no documentation was available. +# Private class members and static file members will be hidden unless # the EXTRACT_PRIVATE and EXTRACT_STATIC tags are set to YES EXTRACT_ALL = NO -# If the EXTRACT_PRIVATE tag is set to YES all private members of a class +# If the EXTRACT_PRIVATE tag is set to YES all private members of a class # will be included in the documentation. EXTRACT_PRIVATE = NO -# If the EXTRACT_STATIC tag is set to YES all static members of a file +# If the EXTRACT_STATIC tag is set to YES all static members of a file # will be included in the documentation. EXTRACT_STATIC = YES -# If the EXTRACT_LOCAL_CLASSES tag is set to YES classes (and structs) -# defined locally in source files will be included in the documentation. +# If the EXTRACT_LOCAL_CLASSES tag is set to YES classes (and structs) +# defined locally in source files will be included in the documentation. # If set to NO only classes defined in header files are included. EXTRACT_LOCAL_CLASSES = YES -# This flag is only useful for Objective-C code. When set to YES local -# methods, which are defined in the implementation section but not in -# the interface are included in the documentation. +# This flag is only useful for Objective-C code. When set to YES local +# methods, which are defined in the implementation section but not in +# the interface are included in the documentation. # If set to NO (the default) only methods in the interface are included. EXTRACT_LOCAL_METHODS = NO -# If the HIDE_UNDOC_MEMBERS tag is set to YES, Doxygen will hide all -# undocumented members of documented classes, files or namespaces. -# If set to NO (the default) these members will be included in the -# various overviews, but no documentation section is generated. +# If the HIDE_UNDOC_MEMBERS tag is set to YES, Doxygen will hide all +# undocumented members of documented classes, files or namespaces. +# If set to NO (the default) these members will be included in the +# various overviews, but no documentation section is generated. # This option has no effect if EXTRACT_ALL is enabled. HIDE_UNDOC_MEMBERS = NO -# If the HIDE_UNDOC_CLASSES tag is set to YES, Doxygen will hide all -# undocumented classes that are normally visible in the class hierarchy. -# If set to NO (the default) these classes will be included in the various +# If the HIDE_UNDOC_CLASSES tag is set to YES, Doxygen will hide all +# undocumented classes that are normally visible in the class hierarchy. +# If set to NO (the default) these classes will be included in the various # overviews. This option has no effect if EXTRACT_ALL is enabled. HIDE_UNDOC_CLASSES = NO -# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, Doxygen will hide all -# friend (class|struct|union) declarations. -# If set to NO (the default) these declarations will be included in the +# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, Doxygen will hide all +# friend (class|struct|union) declarations. +# If set to NO (the default) these declarations will be included in the # documentation. HIDE_FRIEND_COMPOUNDS = NO -# If the HIDE_IN_BODY_DOCS tag is set to YES, Doxygen will hide any -# documentation blocks found inside the body of a function. -# If set to NO (the default) these blocks will be appended to the +# If the HIDE_IN_BODY_DOCS tag is set to YES, Doxygen will hide any +# documentation blocks found inside the body of a function. +# If set to NO (the default) these blocks will be appended to the # function's detailed documentation block. HIDE_IN_BODY_DOCS = NO -# The INTERNAL_DOCS tag determines if documentation -# that is typed after a \internal command is included. If the tag is set -# to NO (the default) then the documentation will be excluded. +# The INTERNAL_DOCS tag determines if documentation +# that is typed after a \internal command is included. If the tag is set +# to NO (the default) then the documentation will be excluded. # Set it to YES to include the internal documentation. INTERNAL_DOCS = NO -# If the CASE_SENSE_NAMES tag is set to NO then Doxygen will only generate -# file names in lower-case letters. If set to YES upper-case letters are also -# allowed. This is useful if you have classes or files whose names only differ -# in case and if your file system supports case sensitive file names. Windows +# If the CASE_SENSE_NAMES tag is set to NO then Doxygen will only generate +# file names in lower-case letters. If set to YES upper-case letters are also +# allowed. This is useful if you have classes or files whose names only differ +# in case and if your file system supports case sensitive file names. Windows # and Mac users are advised to set this option to NO. CASE_SENSE_NAMES = YES -# If the HIDE_SCOPE_NAMES tag is set to NO (the default) then Doxygen -# will show members with their full class and namespace scopes in the +# If the HIDE_SCOPE_NAMES tag is set to NO (the default) then Doxygen +# will show members with their full class and namespace scopes in the # documentation. If set to YES the scope will be hidden. HIDE_SCOPE_NAMES = NO -# If the SHOW_INCLUDE_FILES tag is set to YES (the default) then Doxygen -# will put a list of the files that are included by a file in the documentation +# If the SHOW_INCLUDE_FILES tag is set to YES (the default) then Doxygen +# will put a list of the files that are included by a file in the documentation # of that file. SHOW_INCLUDE_FILES = YES -# If the INLINE_INFO tag is set to YES (the default) then a tag [inline] +# If the INLINE_INFO tag is set to YES (the default) then a tag [inline] # is inserted in the documentation for inline members. INLINE_INFO = YES -# If the SORT_MEMBER_DOCS tag is set to YES (the default) then doxygen -# will sort the (detailed) documentation of file and class members -# alphabetically by member name. If set to NO the members will appear in +# If the SORT_MEMBER_DOCS tag is set to YES (the default) then doxygen +# will sort the (detailed) documentation of file and class members +# alphabetically by member name. If set to NO the members will appear in # declaration order. SORT_MEMBER_DOCS = YES -# If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the -# brief documentation of file, namespace and class members alphabetically -# by member name. If set to NO (the default) the members will appear in +# If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the +# brief documentation of file, namespace and class members alphabetically +# by member name. If set to NO (the default) the members will appear in # declaration order. SORT_BRIEF_DOCS = NO -# If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be -# sorted by fully-qualified names, including namespaces. If set to -# NO (the default), the class list will be sorted only by class name, -# not including the namespace part. +# If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be +# sorted by fully-qualified names, including namespaces. If set to +# NO (the default), the class list will be sorted only by class name, +# not including the namespace part. # Note: This option is not very useful if HIDE_SCOPE_NAMES is set to YES. -# Note: This option applies only to the class list, not to the +# Note: This option applies only to the class list, not to the # alphabetical list. SORT_BY_SCOPE_NAME = NO -# The GENERATE_TODOLIST tag can be used to enable (YES) or -# disable (NO) the todo list. This list is created by putting \todo +# The GENERATE_TODOLIST tag can be used to enable (YES) or +# disable (NO) the todo list. This list is created by putting \todo # commands in the documentation. GENERATE_TODOLIST = YES -# The GENERATE_TESTLIST tag can be used to enable (YES) or -# disable (NO) the test list. This list is created by putting \test +# The GENERATE_TESTLIST tag can be used to enable (YES) or +# disable (NO) the test list. This list is created by putting \test # commands in the documentation. GENERATE_TESTLIST = YES -# The GENERATE_BUGLIST tag can be used to enable (YES) or -# disable (NO) the bug list. This list is created by putting \bug +# The GENERATE_BUGLIST tag can be used to enable (YES) or +# disable (NO) the bug list. This list is created by putting \bug # commands in the documentation. GENERATE_BUGLIST = YES -# The GENERATE_DEPRECATEDLIST tag can be used to enable (YES) or -# disable (NO) the deprecated list. This list is created by putting +# The GENERATE_DEPRECATEDLIST tag can be used to enable (YES) or +# disable (NO) the deprecated list. This list is created by putting # \deprecated commands in the documentation. GENERATE_DEPRECATEDLIST= YES -# The ENABLED_SECTIONS tag can be used to enable conditional +# The ENABLED_SECTIONS tag can be used to enable conditional # documentation sections, marked by \if sectionname ... \endif. -ENABLED_SECTIONS = +ENABLED_SECTIONS = -# The MAX_INITIALIZER_LINES tag determines the maximum number of lines -# the initial value of a variable or define consists of for it to appear in -# the documentation. If the initializer consists of more lines than specified -# here it will be hidden. Use a value of 0 to hide initializers completely. -# The appearance of the initializer of individual variables and defines in the -# documentation can be controlled using \showinitializer or \hideinitializer +# The MAX_INITIALIZER_LINES tag determines the maximum number of lines +# the initial value of a variable or define consists of for it to appear in +# the documentation. If the initializer consists of more lines than specified +# here it will be hidden. Use a value of 0 to hide initializers completely. +# The appearance of the initializer of individual variables and defines in the +# documentation can be controlled using \showinitializer or \hideinitializer # command in the documentation regardless of this setting. MAX_INITIALIZER_LINES = 30 -# Set the SHOW_USED_FILES tag to NO to disable the list of files generated -# at the bottom of the documentation of classes and structs. If set to YES the +# Set the SHOW_USED_FILES tag to NO to disable the list of files generated +# at the bottom of the documentation of classes and structs. If set to YES the # list will mention the files that were used to generate the documentation. SHOW_USED_FILES = YES -# If the sources in your project are distributed over multiple directories -# then setting the SHOW_DIRECTORIES tag to YES will show the directory hierarchy +# If the sources in your project are distributed over multiple directories +# then setting the SHOW_DIRECTORIES tag to YES will show the directory hierarchy # in the documentation. The default is NO. SHOW_DIRECTORIES = NO -# The FILE_VERSION_FILTER tag can be used to specify a program or script that -# doxygen should invoke to get the current version for each file (typically from the -# version control system). Doxygen will invoke the program by executing (via -# popen()) the command , where is the value of -# the FILE_VERSION_FILTER tag, and is the name of an input file -# provided by doxygen. Whatever the program writes to standard output +# The FILE_VERSION_FILTER tag can be used to specify a program or script that +# doxygen should invoke to get the current version for each file (typically from the +# version control system). Doxygen will invoke the program by executing (via +# popen()) the command , where is the value of +# the FILE_VERSION_FILTER tag, and is the name of an input file +# provided by doxygen. Whatever the program writes to standard output # is used as the file version. See the manual for examples. -FILE_VERSION_FILTER = +FILE_VERSION_FILTER = #--------------------------------------------------------------------------- # configuration options related to warning and progress messages #--------------------------------------------------------------------------- -# The QUIET tag can be used to turn on/off the messages that are generated +# The QUIET tag can be used to turn on/off the messages that are generated # by doxygen. Possible values are YES and NO. If left blank NO is used. QUIET = NO -# The WARNINGS tag can be used to turn on/off the warning messages that are -# generated by doxygen. Possible values are YES and NO. If left blank +# The WARNINGS tag can be used to turn on/off the warning messages that are +# generated by doxygen. Possible values are YES and NO. If left blank # NO is used. WARNINGS = YES -# If WARN_IF_UNDOCUMENTED is set to YES, then doxygen will generate warnings -# for undocumented members. If EXTRACT_ALL is set to YES then this flag will +# If WARN_IF_UNDOCUMENTED is set to YES, then doxygen will generate warnings +# for undocumented members. If EXTRACT_ALL is set to YES then this flag will # automatically be disabled. WARN_IF_UNDOCUMENTED = YES -# If WARN_IF_DOC_ERROR is set to YES, doxygen will generate warnings for -# potential errors in the documentation, such as not documenting some -# parameters in a documented function, or documenting parameters that +# If WARN_IF_DOC_ERROR is set to YES, doxygen will generate warnings for +# potential errors in the documentation, such as not documenting some +# parameters in a documented function, or documenting parameters that # don't exist or using markup commands wrongly. WARN_IF_DOC_ERROR = YES -# This WARN_NO_PARAMDOC option can be abled to get warnings for -# functions that are documented, but have no documentation for their parameters -# or return value. If set to NO (the default) doxygen will only warn about -# wrong or incomplete parameter documentation, but not about the absence of +# This WARN_NO_PARAMDOC option can be abled to get warnings for +# functions that are documented, but have no documentation for their parameters +# or return value. If set to NO (the default) doxygen will only warn about +# wrong or incomplete parameter documentation, but not about the absence of # documentation. WARN_NO_PARAMDOC = NO -# The WARN_FORMAT tag determines the format of the warning messages that -# doxygen can produce. The string should contain the $file, $line, and $text -# tags, which will be replaced by the file and line number from which the -# warning originated and the warning text. Optionally the format may contain -# $version, which will be replaced by the version of the file (if it could +# The WARN_FORMAT tag determines the format of the warning messages that +# doxygen can produce. The string should contain the $file, $line, and $text +# tags, which will be replaced by the file and line number from which the +# warning originated and the warning text. Optionally the format may contain +# $version, which will be replaced by the version of the file (if it could # be obtained via FILE_VERSION_FILTER) WARN_FORMAT = "$file:$line: $text" -# The WARN_LOGFILE tag can be used to specify a file to which warning -# and error messages should be written. If left blank the output is written +# The WARN_LOGFILE tag can be used to specify a file to which warning +# and error messages should be written. If left blank the output is written # to stderr. -WARN_LOGFILE = +WARN_LOGFILE = #--------------------------------------------------------------------------- # configuration options related to the input files #--------------------------------------------------------------------------- -# The INPUT tag can be used to specify the files and/or directories that contain -# documented source files. You may enter file names like "myfile.cpp" or -# directories like "/usr/src/myproject". Separate the files or directories +# The INPUT tag can be used to specify the files and/or directories that contain +# documented source files. You may enter file names like "myfile.cpp" or +# directories like "/usr/src/myproject". Separate the files or directories # with spaces. INPUT = $(DOX_INPUT) -# If the value of the INPUT tag contains directories, you can use the -# FILE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp -# and *.h) to filter out the source-files in the directories. If left -# blank the following patterns are tested: -# *.c *.cc *.cxx *.cpp *.c++ *.java *.ii *.ixx *.ipp *.i++ *.inl *.h *.hh *.hxx +# If the value of the INPUT tag contains directories, you can use the +# FILE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp +# and *.h) to filter out the source-files in the directories. If left +# blank the following patterns are tested: +# *.c *.cc *.cxx *.cpp *.c++ *.java *.ii *.ixx *.ipp *.i++ *.inl *.h *.hh *.hxx # *.hpp *.h++ *.idl *.odl *.cs *.php *.php3 *.inc *.m *.mm *.py FILE_PATTERNS = *.h \ *.cc -# The RECURSIVE tag can be used to turn specify whether or not subdirectories -# should be searched for input files as well. Possible values are YES and NO. +# The RECURSIVE tag can be used to turn specify whether or not subdirectories +# should be searched for input files as well. Possible values are YES and NO. # If left blank NO is used. RECURSIVE = YES -# The EXCLUDE tag can be used to specify files and/or directories that should -# excluded from the INPUT source files. This way you can easily exclude a +# The EXCLUDE tag can be used to specify files and/or directories that should +# excluded from the INPUT source files. This way you can easily exclude a # subdirectory from a directory tree whose root is specified with the INPUT tag. -EXCLUDE = +EXCLUDE = -# The EXCLUDE_SYMLINKS tag can be used select whether or not files or -# directories that are symbolic links (a Unix filesystem feature) are excluded +# The EXCLUDE_SYMLINKS tag can be used select whether or not files or +# directories that are symbolic links (a Unix filesystem feature) are excluded # from the input. EXCLUDE_SYMLINKS = NO -# If the value of the INPUT tag contains directories, you can use the -# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude -# certain files from those directories. Note that the wildcards are matched -# against the file with absolute path, so to exclude all test directories +# If the value of the INPUT tag contains directories, you can use the +# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude +# certain files from those directories. Note that the wildcards are matched +# against the file with absolute path, so to exclude all test directories # for example use the pattern */test/* -EXCLUDE_PATTERNS = +EXCLUDE_PATTERNS = -# The EXAMPLE_PATH tag can be used to specify one or more files or -# directories that contain example code fragments that are included (see +# The EXAMPLE_PATH tag can be used to specify one or more files or +# directories that contain example code fragments that are included (see # the \include command). -EXAMPLE_PATH = +EXAMPLE_PATH = -# If the value of the EXAMPLE_PATH tag contains directories, you can use the -# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp -# and *.h) to filter out the source-files in the directories. If left +# If the value of the EXAMPLE_PATH tag contains directories, you can use the +# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp +# and *.h) to filter out the source-files in the directories. If left # blank all files are included. -EXAMPLE_PATTERNS = +EXAMPLE_PATTERNS = -# If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be -# searched for input files to be used with the \include or \dontinclude -# commands irrespective of the value of the RECURSIVE tag. +# If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be +# searched for input files to be used with the \include or \dontinclude +# commands irrespective of the value of the RECURSIVE tag. # Possible values are YES and NO. If left blank NO is used. EXAMPLE_RECURSIVE = NO -# The IMAGE_PATH tag can be used to specify one or more files or -# directories that contain image that are included in the documentation (see +# The IMAGE_PATH tag can be used to specify one or more files or +# directories that contain image that are included in the documentation (see # the \image command). -IMAGE_PATH = +IMAGE_PATH = -# The INPUT_FILTER tag can be used to specify a program that doxygen should -# invoke to filter for each input file. Doxygen will invoke the filter program -# by executing (via popen()) the command , where -# is the value of the INPUT_FILTER tag, and is the name of an -# input file. Doxygen will then use the output that the filter program writes -# to standard output. If FILTER_PATTERNS is specified, this tag will be +# The INPUT_FILTER tag can be used to specify a program that doxygen should +# invoke to filter for each input file. Doxygen will invoke the filter program +# by executing (via popen()) the command , where +# is the value of the INPUT_FILTER tag, and is the name of an +# input file. Doxygen will then use the output that the filter program writes +# to standard output. If FILTER_PATTERNS is specified, this tag will be # ignored. -INPUT_FILTER = +INPUT_FILTER = -# The FILTER_PATTERNS tag can be used to specify filters on a per file pattern -# basis. Doxygen will compare the file name with each pattern and apply the -# filter if there is a match. The filters are a list of the form: -# pattern=filter (like *.cpp=my_cpp_filter). See INPUT_FILTER for further -# info on how filters are used. If FILTER_PATTERNS is empty, INPUT_FILTER +# The FILTER_PATTERNS tag can be used to specify filters on a per file pattern +# basis. Doxygen will compare the file name with each pattern and apply the +# filter if there is a match. The filters are a list of the form: +# pattern=filter (like *.cpp=my_cpp_filter). See INPUT_FILTER for further +# info on how filters are used. If FILTER_PATTERNS is empty, INPUT_FILTER # is applied to all files. -FILTER_PATTERNS = +FILTER_PATTERNS = -# If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using -# INPUT_FILTER) will be used to filter the input files when producing source +# If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using +# INPUT_FILTER) will be used to filter the input files when producing source # files to browse (i.e. when SOURCE_BROWSER is set to YES). FILTER_SOURCE_FILES = NO @@ -552,32 +552,32 @@ FILTER_SOURCE_FILES = NO # configuration options related to source browsing #--------------------------------------------------------------------------- -# If the SOURCE_BROWSER tag is set to YES then a list of source files will -# be generated. Documented entities will be cross-referenced with these sources. -# Note: To get rid of all source code in the generated output, make sure also +# If the SOURCE_BROWSER tag is set to YES then a list of source files will +# be generated. Documented entities will be cross-referenced with these sources. +# Note: To get rid of all source code in the generated output, make sure also # VERBATIM_HEADERS is set to NO. SOURCE_BROWSER = NO -# Setting the INLINE_SOURCES tag to YES will include the body +# Setting the INLINE_SOURCES tag to YES will include the body # of functions and classes directly in the documentation. INLINE_SOURCES = NO -# Setting the STRIP_CODE_COMMENTS tag to YES (the default) will instruct -# doxygen to hide any special comment blocks from generated source code +# Setting the STRIP_CODE_COMMENTS tag to YES (the default) will instruct +# doxygen to hide any special comment blocks from generated source code # fragments. Normal C and C++ comments will always remain visible. STRIP_CODE_COMMENTS = YES -# If the REFERENCED_BY_RELATION tag is set to YES (the default) -# then for each documented function all documented +# If the REFERENCED_BY_RELATION tag is set to YES (the default) +# then for each documented function all documented # functions referencing it will be listed. REFERENCED_BY_RELATION = YES -# If the REFERENCES_RELATION tag is set to YES (the default) -# then for each documented function all documented entities +# If the REFERENCES_RELATION tag is set to YES (the default) +# then for each documented function all documented entities # called/used by that function will be listed. REFERENCES_RELATION = YES @@ -589,16 +589,16 @@ REFERENCES_RELATION = YES REFERENCES_LINK_SOURCE = YES -# If the USE_HTAGS tag is set to YES then the references to source code -# will point to the HTML generated by the htags(1) tool instead of doxygen -# built-in source browser. The htags tool is part of GNU's global source -# tagging system (see http://www.gnu.org/software/global/global.html). You +# If the USE_HTAGS tag is set to YES then the references to source code +# will point to the HTML generated by the htags(1) tool instead of doxygen +# built-in source browser. The htags tool is part of GNU's global source +# tagging system (see http://www.gnu.org/software/global/global.html). You # will need version 4.8.6 or higher. USE_HTAGS = NO -# If the VERBATIM_HEADERS tag is set to YES (the default) then Doxygen -# will generate a verbatim copy of the header file for each class for +# If the VERBATIM_HEADERS tag is set to YES (the default) then Doxygen +# will generate a verbatim copy of the header file for each class for # which an include is specified. Set to NO to disable this. VERBATIM_HEADERS = YES @@ -607,133 +607,133 @@ VERBATIM_HEADERS = YES # configuration options related to the alphabetical class index #--------------------------------------------------------------------------- -# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index -# of all compounds will be generated. Enable this if the project +# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index +# of all compounds will be generated. Enable this if the project # contains a lot of classes, structs, unions or interfaces. ALPHABETICAL_INDEX = NO -# If the alphabetical index is enabled (see ALPHABETICAL_INDEX) then -# the COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns +# If the alphabetical index is enabled (see ALPHABETICAL_INDEX) then +# the COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns # in which this list will be split (can be a number in the range [1..20]) COLS_IN_ALPHA_INDEX = 5 -# In case all classes in a project start with a common prefix, all -# classes will be put under the same header in the alphabetical index. -# The IGNORE_PREFIX tag can be used to specify one or more prefixes that +# In case all classes in a project start with a common prefix, all +# classes will be put under the same header in the alphabetical index. +# The IGNORE_PREFIX tag can be used to specify one or more prefixes that # should be ignored while generating the index headers. -IGNORE_PREFIX = +IGNORE_PREFIX = #--------------------------------------------------------------------------- # configuration options related to the HTML output #--------------------------------------------------------------------------- -# If the GENERATE_HTML tag is set to YES (the default) Doxygen will +# If the GENERATE_HTML tag is set to YES (the default) Doxygen will # generate HTML output. GENERATE_HTML = YES -# The HTML_OUTPUT tag is used to specify where the HTML docs will be put. -# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# The HTML_OUTPUT tag is used to specify where the HTML docs will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be # put in front of it. If left blank `html' will be used as the default path. HTML_OUTPUT = html -# The HTML_FILE_EXTENSION tag can be used to specify the file extension for -# each generated HTML page (for example: .htm,.php,.asp). If it is left blank +# The HTML_FILE_EXTENSION tag can be used to specify the file extension for +# each generated HTML page (for example: .htm,.php,.asp). If it is left blank # doxygen will generate files with .html extension. HTML_FILE_EXTENSION = .html -# The HTML_HEADER tag can be used to specify a personal HTML header for -# each generated HTML page. If it is left blank doxygen will generate a +# The HTML_HEADER tag can be used to specify a personal HTML header for +# each generated HTML page. If it is left blank doxygen will generate a # standard header. -HTML_HEADER = +HTML_HEADER = -# The HTML_FOOTER tag can be used to specify a personal HTML footer for -# each generated HTML page. If it is left blank doxygen will generate a +# The HTML_FOOTER tag can be used to specify a personal HTML footer for +# each generated HTML page. If it is left blank doxygen will generate a # standard footer. -HTML_FOOTER = +HTML_FOOTER = -# The HTML_STYLESHEET tag can be used to specify a user-defined cascading -# style sheet that is used by each HTML page. It can be used to -# fine-tune the look of the HTML output. If the tag is left blank doxygen -# will generate a default style sheet. Note that doxygen will try to copy -# the style sheet file to the HTML output directory, so don't put your own +# The HTML_STYLESHEET tag can be used to specify a user-defined cascading +# style sheet that is used by each HTML page. It can be used to +# fine-tune the look of the HTML output. If the tag is left blank doxygen +# will generate a default style sheet. Note that doxygen will try to copy +# the style sheet file to the HTML output directory, so don't put your own # stylesheet in the HTML output directory as well, or it will be erased! -HTML_STYLESHEET = +HTML_STYLESHEET = -# If the HTML_ALIGN_MEMBERS tag is set to YES, the members of classes, -# files or namespaces will be aligned in HTML using tables. If set to +# If the HTML_ALIGN_MEMBERS tag is set to YES, the members of classes, +# files or namespaces will be aligned in HTML using tables. If set to # NO a bullet list will be used. HTML_ALIGN_MEMBERS = YES -# If the GENERATE_HTMLHELP tag is set to YES, additional index files -# will be generated that can be used as input for tools like the -# Microsoft HTML help workshop to generate a compressed HTML help file (.chm) +# If the GENERATE_HTMLHELP tag is set to YES, additional index files +# will be generated that can be used as input for tools like the +# Microsoft HTML help workshop to generate a compressed HTML help file (.chm) # of the generated HTML documentation. GENERATE_HTMLHELP = NO -# If the GENERATE_HTMLHELP tag is set to YES, the CHM_FILE tag can -# be used to specify the file name of the resulting .chm file. You -# can add a path in front of the file if the result should not be +# If the GENERATE_HTMLHELP tag is set to YES, the CHM_FILE tag can +# be used to specify the file name of the resulting .chm file. You +# can add a path in front of the file if the result should not be # written to the html output directory. -CHM_FILE = +CHM_FILE = -# If the GENERATE_HTMLHELP tag is set to YES, the HHC_LOCATION tag can -# be used to specify the location (absolute path including file name) of -# the HTML help compiler (hhc.exe). If non-empty doxygen will try to run +# If the GENERATE_HTMLHELP tag is set to YES, the HHC_LOCATION tag can +# be used to specify the location (absolute path including file name) of +# the HTML help compiler (hhc.exe). If non-empty doxygen will try to run # the HTML help compiler on the generated index.hhp. -HHC_LOCATION = +HHC_LOCATION = -# If the GENERATE_HTMLHELP tag is set to YES, the GENERATE_CHI flag -# controls if a separate .chi index file is generated (YES) or that +# If the GENERATE_HTMLHELP tag is set to YES, the GENERATE_CHI flag +# controls if a separate .chi index file is generated (YES) or that # it should be included in the master .chm file (NO). GENERATE_CHI = NO -# If the GENERATE_HTMLHELP tag is set to YES, the BINARY_TOC flag -# controls whether a binary table of contents is generated (YES) or a +# If the GENERATE_HTMLHELP tag is set to YES, the BINARY_TOC flag +# controls whether a binary table of contents is generated (YES) or a # normal table of contents (NO) in the .chm file. BINARY_TOC = NO -# The TOC_EXPAND flag can be set to YES to add extra items for group members +# The TOC_EXPAND flag can be set to YES to add extra items for group members # to the contents of the HTML help documentation and to the tree view. TOC_EXPAND = NO -# The DISABLE_INDEX tag can be used to turn on/off the condensed index at -# top of each HTML page. The value NO (the default) enables the index and +# The DISABLE_INDEX tag can be used to turn on/off the condensed index at +# top of each HTML page. The value NO (the default) enables the index and # the value YES disables it. DISABLE_INDEX = NO -# This tag can be used to set the number of enum values (range [1..20]) +# This tag can be used to set the number of enum values (range [1..20]) # that doxygen will group on one line in the generated HTML documentation. ENUM_VALUES_PER_LINE = 4 # If the GENERATE_TREEVIEW tag is set to YES, a side panel will be -# generated containing a tree-like index structure (just like the one that -# is generated for HTML Help). For this to work a browser that supports -# JavaScript, DHTML, CSS and frames is required (for instance Mozilla 1.0+, -# Netscape 6.0+, Internet explorer 5.0+, or Konqueror). Windows users are +# generated containing a tree-like index structure (just like the one that +# is generated for HTML Help). For this to work a browser that supports +# JavaScript, DHTML, CSS and frames is required (for instance Mozilla 1.0+, +# Netscape 6.0+, Internet explorer 5.0+, or Konqueror). Windows users are # probably better off using the HTML help feature. GENERATE_TREEVIEW = NO -# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be -# used to set the initial width (in pixels) of the frame in which the tree +# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be +# used to set the initial width (in pixels) of the frame in which the tree # is shown. TREEVIEW_WIDTH = 250 @@ -742,74 +742,74 @@ TREEVIEW_WIDTH = 250 # configuration options related to the LaTeX output #--------------------------------------------------------------------------- -# If the GENERATE_LATEX tag is set to YES (the default) Doxygen will +# If the GENERATE_LATEX tag is set to YES (the default) Doxygen will # generate Latex output. GENERATE_LATEX = YES -# The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put. -# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be # put in front of it. If left blank `latex' will be used as the default path. LATEX_OUTPUT = latex -# The LATEX_CMD_NAME tag can be used to specify the LaTeX command name to be +# The LATEX_CMD_NAME tag can be used to specify the LaTeX command name to be # invoked. If left blank `latex' will be used as the default command name. LATEX_CMD_NAME = latex -# The MAKEINDEX_CMD_NAME tag can be used to specify the command name to -# generate index for LaTeX. If left blank `makeindex' will be used as the +# The MAKEINDEX_CMD_NAME tag can be used to specify the command name to +# generate index for LaTeX. If left blank `makeindex' will be used as the # default command name. MAKEINDEX_CMD_NAME = makeindex -# If the COMPACT_LATEX tag is set to YES Doxygen generates more compact -# LaTeX documents. This may be useful for small projects and may help to +# If the COMPACT_LATEX tag is set to YES Doxygen generates more compact +# LaTeX documents. This may be useful for small projects and may help to # save some trees in general. COMPACT_LATEX = NO -# The PAPER_TYPE tag can be used to set the paper type that is used -# by the printer. Possible values are: a4, a4wide, letter, legal and +# The PAPER_TYPE tag can be used to set the paper type that is used +# by the printer. Possible values are: a4, a4wide, letter, legal and # executive. If left blank a4wide will be used. PAPER_TYPE = a4wide -# The EXTRA_PACKAGES tag can be to specify one or more names of LaTeX +# The EXTRA_PACKAGES tag can be to specify one or more names of LaTeX # packages that should be included in the LaTeX output. -EXTRA_PACKAGES = +EXTRA_PACKAGES = -# The LATEX_HEADER tag can be used to specify a personal LaTeX header for -# the generated latex document. The header should contain everything until -# the first chapter. If it is left blank doxygen will generate a +# The LATEX_HEADER tag can be used to specify a personal LaTeX header for +# the generated latex document. The header should contain everything until +# the first chapter. If it is left blank doxygen will generate a # standard header. Notice: only use this tag if you know what you are doing! -LATEX_HEADER = +LATEX_HEADER = -# If the PDF_HYPERLINKS tag is set to YES, the LaTeX that is generated -# is prepared for conversion to pdf (using ps2pdf). The pdf file will -# contain links (just like the HTML output) instead of page references +# If the PDF_HYPERLINKS tag is set to YES, the LaTeX that is generated +# is prepared for conversion to pdf (using ps2pdf). The pdf file will +# contain links (just like the HTML output) instead of page references # This makes the output suitable for online browsing using a pdf viewer. PDF_HYPERLINKS = NO -# If the USE_PDFLATEX tag is set to YES, pdflatex will be used instead of -# plain latex in the generated Makefile. Set this option to YES to get a +# If the USE_PDFLATEX tag is set to YES, pdflatex will be used instead of +# plain latex in the generated Makefile. Set this option to YES to get a # higher quality PDF documentation. USE_PDFLATEX = NO -# If the LATEX_BATCHMODE tag is set to YES, doxygen will add the \\batchmode. -# command to the generated LaTeX files. This will instruct LaTeX to keep -# running if errors occur, instead of asking the user for help. +# If the LATEX_BATCHMODE tag is set to YES, doxygen will add the \\batchmode. +# command to the generated LaTeX files. This will instruct LaTeX to keep +# running if errors occur, instead of asking the user for help. # This option is also used when generating formulas in HTML. LATEX_BATCHMODE = NO -# If LATEX_HIDE_INDICES is set to YES then doxygen will not -# include the index chapters (such as File Index, Compound Index, etc.) +# If LATEX_HIDE_INDICES is set to YES then doxygen will not +# include the index chapters (such as File Index, Compound Index, etc.) # in the output. LATEX_HIDE_INDICES = NO @@ -818,68 +818,68 @@ LATEX_HIDE_INDICES = NO # configuration options related to the RTF output #--------------------------------------------------------------------------- -# If the GENERATE_RTF tag is set to YES Doxygen will generate RTF output -# The RTF output is optimized for Word 97 and may not look very pretty with +# If the GENERATE_RTF tag is set to YES Doxygen will generate RTF output +# The RTF output is optimized for Word 97 and may not look very pretty with # other RTF readers or editors. GENERATE_RTF = NO -# The RTF_OUTPUT tag is used to specify where the RTF docs will be put. -# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# The RTF_OUTPUT tag is used to specify where the RTF docs will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be # put in front of it. If left blank `rtf' will be used as the default path. RTF_OUTPUT = rtf -# If the COMPACT_RTF tag is set to YES Doxygen generates more compact -# RTF documents. This may be useful for small projects and may help to +# If the COMPACT_RTF tag is set to YES Doxygen generates more compact +# RTF documents. This may be useful for small projects and may help to # save some trees in general. COMPACT_RTF = NO -# If the RTF_HYPERLINKS tag is set to YES, the RTF that is generated -# will contain hyperlink fields. The RTF file will -# contain links (just like the HTML output) instead of page references. -# This makes the output suitable for online browsing using WORD or other -# programs which support those fields. +# If the RTF_HYPERLINKS tag is set to YES, the RTF that is generated +# will contain hyperlink fields. The RTF file will +# contain links (just like the HTML output) instead of page references. +# This makes the output suitable for online browsing using WORD or other +# programs which support those fields. # Note: wordpad (write) and others do not support links. RTF_HYPERLINKS = NO -# Load stylesheet definitions from file. Syntax is similar to doxygen's -# config file, i.e. a series of assignments. You only have to provide +# Load stylesheet definitions from file. Syntax is similar to doxygen's +# config file, i.e. a series of assignments. You only have to provide # replacements, missing definitions are set to their default value. -RTF_STYLESHEET_FILE = +RTF_STYLESHEET_FILE = -# Set optional variables used in the generation of an rtf document. +# Set optional variables used in the generation of an rtf document. # Syntax is similar to doxygen's config file. -RTF_EXTENSIONS_FILE = +RTF_EXTENSIONS_FILE = #--------------------------------------------------------------------------- # configuration options related to the man page output #--------------------------------------------------------------------------- -# If the GENERATE_MAN tag is set to YES (the default) Doxygen will +# If the GENERATE_MAN tag is set to YES (the default) Doxygen will # generate man pages GENERATE_MAN = NO -# The MAN_OUTPUT tag is used to specify where the man pages will be put. -# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# The MAN_OUTPUT tag is used to specify where the man pages will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be # put in front of it. If left blank `man' will be used as the default path. MAN_OUTPUT = man -# The MAN_EXTENSION tag determines the extension that is added to +# The MAN_EXTENSION tag determines the extension that is added to # the generated man pages (default is the subroutine's section .3) MAN_EXTENSION = .3 -# If the MAN_LINKS tag is set to YES and Doxygen generates man output, -# then it will generate one additional man file for each entity -# documented in the real man page(s). These additional files -# only source the real man page, but without them the man command +# If the MAN_LINKS tag is set to YES and Doxygen generates man output, +# then it will generate one additional man file for each entity +# documented in the real man page(s). These additional files +# only source the real man page, but without them the man command # would be unable to find the correct page. The default is NO. MAN_LINKS = NO @@ -888,33 +888,33 @@ MAN_LINKS = NO # configuration options related to the XML output #--------------------------------------------------------------------------- -# If the GENERATE_XML tag is set to YES Doxygen will -# generate an XML file that captures the structure of +# If the GENERATE_XML tag is set to YES Doxygen will +# generate an XML file that captures the structure of # the code including all documentation. GENERATE_XML = NO -# The XML_OUTPUT tag is used to specify where the XML pages will be put. -# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# The XML_OUTPUT tag is used to specify where the XML pages will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be # put in front of it. If left blank `xml' will be used as the default path. XML_OUTPUT = xml -# The XML_SCHEMA tag can be used to specify an XML schema, -# which can be used by a validating XML parser to check the +# The XML_SCHEMA tag can be used to specify an XML schema, +# which can be used by a validating XML parser to check the # syntax of the XML files. -XML_SCHEMA = +XML_SCHEMA = -# The XML_DTD tag can be used to specify an XML DTD, -# which can be used by a validating XML parser to check the +# The XML_DTD tag can be used to specify an XML DTD, +# which can be used by a validating XML parser to check the # syntax of the XML files. -XML_DTD = +XML_DTD = -# If the XML_PROGRAMLISTING tag is set to YES Doxygen will -# dump the program listings (including syntax highlighting -# and cross-referencing information) to the XML output. Note that +# If the XML_PROGRAMLISTING tag is set to YES Doxygen will +# dump the program listings (including syntax highlighting +# and cross-referencing information) to the XML output. Note that # enabling this will significantly increase the size of the XML output. XML_PROGRAMLISTING = YES @@ -923,10 +923,10 @@ XML_PROGRAMLISTING = YES # configuration options for the AutoGen Definitions output #--------------------------------------------------------------------------- -# If the GENERATE_AUTOGEN_DEF tag is set to YES Doxygen will -# generate an AutoGen Definitions (see autogen.sf.net) file -# that captures the structure of the code including all -# documentation. Note that this feature is still experimental +# If the GENERATE_AUTOGEN_DEF tag is set to YES Doxygen will +# generate an AutoGen Definitions (see autogen.sf.net) file +# that captures the structure of the code including all +# documentation. Note that this feature is still experimental # and incomplete at the moment. GENERATE_AUTOGEN_DEF = NO @@ -935,319 +935,319 @@ GENERATE_AUTOGEN_DEF = NO # configuration options related to the Perl module output #--------------------------------------------------------------------------- -# If the GENERATE_PERLMOD tag is set to YES Doxygen will -# generate a Perl module file that captures the structure of -# the code including all documentation. Note that this -# feature is still experimental and incomplete at the +# If the GENERATE_PERLMOD tag is set to YES Doxygen will +# generate a Perl module file that captures the structure of +# the code including all documentation. Note that this +# feature is still experimental and incomplete at the # moment. GENERATE_PERLMOD = NO -# If the PERLMOD_LATEX tag is set to YES Doxygen will generate -# the necessary Makefile rules, Perl scripts and LaTeX code to be able +# If the PERLMOD_LATEX tag is set to YES Doxygen will generate +# the necessary Makefile rules, Perl scripts and LaTeX code to be able # to generate PDF and DVI output from the Perl module output. PERLMOD_LATEX = NO -# If the PERLMOD_PRETTY tag is set to YES the Perl module output will be -# nicely formatted so it can be parsed by a human reader. This is useful -# if you want to understand what is going on. On the other hand, if this -# tag is set to NO the size of the Perl module output will be much smaller +# If the PERLMOD_PRETTY tag is set to YES the Perl module output will be +# nicely formatted so it can be parsed by a human reader. This is useful +# if you want to understand what is going on. On the other hand, if this +# tag is set to NO the size of the Perl module output will be much smaller # and Perl will parse it just the same. PERLMOD_PRETTY = YES -# The names of the make variables in the generated doxyrules.make file -# are prefixed with the string contained in PERLMOD_MAKEVAR_PREFIX. -# This is useful so different doxyrules.make files included by the same +# The names of the make variables in the generated doxyrules.make file +# are prefixed with the string contained in PERLMOD_MAKEVAR_PREFIX. +# This is useful so different doxyrules.make files included by the same # Makefile don't overwrite each other's variables. -PERLMOD_MAKEVAR_PREFIX = +PERLMOD_MAKEVAR_PREFIX = #--------------------------------------------------------------------------- -# Configuration options related to the preprocessor +# Configuration options related to the preprocessor #--------------------------------------------------------------------------- -# If the ENABLE_PREPROCESSING tag is set to YES (the default) Doxygen will -# evaluate all C-preprocessor directives found in the sources and include +# If the ENABLE_PREPROCESSING tag is set to YES (the default) Doxygen will +# evaluate all C-preprocessor directives found in the sources and include # files. ENABLE_PREPROCESSING = YES -# If the MACRO_EXPANSION tag is set to YES Doxygen will expand all macro -# names in the source code. If set to NO (the default) only conditional -# compilation will be performed. Macro expansion can be done in a controlled +# If the MACRO_EXPANSION tag is set to YES Doxygen will expand all macro +# names in the source code. If set to NO (the default) only conditional +# compilation will be performed. Macro expansion can be done in a controlled # way by setting EXPAND_ONLY_PREDEF to YES. MACRO_EXPANSION = NO -# If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES -# then the macro expansion is limited to the macros specified with the +# If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES +# then the macro expansion is limited to the macros specified with the # PREDEFINED and EXPAND_AS_DEFINED tags. EXPAND_ONLY_PREDEF = NO -# If the SEARCH_INCLUDES tag is set to YES (the default) the includes files +# If the SEARCH_INCLUDES tag is set to YES (the default) the includes files # in the INCLUDE_PATH (see below) will be search if a #include is found. SEARCH_INCLUDES = YES -# The INCLUDE_PATH tag can be used to specify one or more directories that -# contain include files that are not input files but should be processed by +# The INCLUDE_PATH tag can be used to specify one or more directories that +# contain include files that are not input files but should be processed by # the preprocessor. -INCLUDE_PATH = +INCLUDE_PATH = -# You can use the INCLUDE_FILE_PATTERNS tag to specify one or more wildcard -# patterns (like *.h and *.hpp) to filter out the header-files in the -# directories. If left blank, the patterns specified with FILE_PATTERNS will +# You can use the INCLUDE_FILE_PATTERNS tag to specify one or more wildcard +# patterns (like *.h and *.hpp) to filter out the header-files in the +# directories. If left blank, the patterns specified with FILE_PATTERNS will # be used. -INCLUDE_FILE_PATTERNS = +INCLUDE_FILE_PATTERNS = -# The PREDEFINED tag can be used to specify one or more macro names that -# are defined before the preprocessor is started (similar to the -D option of -# gcc). The argument of the tag is a list of macros of the form: name -# or name=definition (no spaces). If the definition and the = are -# omitted =1 is assumed. To prevent a macro definition from being -# undefined via #undef or recursively expanded use the := operator +# The PREDEFINED tag can be used to specify one or more macro names that +# are defined before the preprocessor is started (similar to the -D option of +# gcc). The argument of the tag is a list of macros of the form: name +# or name=definition (no spaces). If the definition and the = are +# omitted =1 is assumed. To prevent a macro definition from being +# undefined via #undef or recursively expanded use the := operator # instead of the = operator. -PREDEFINED = +PREDEFINED = -# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then -# this tag can be used to specify a list of macro names that should be expanded. -# The macro definition that is found in the sources will be used. +# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then +# this tag can be used to specify a list of macro names that should be expanded. +# The macro definition that is found in the sources will be used. # Use the PREDEFINED tag if you want to use a different macro definition. -EXPAND_AS_DEFINED = +EXPAND_AS_DEFINED = -# If the SKIP_FUNCTION_MACROS tag is set to YES (the default) then -# doxygen's preprocessor will remove all function-like macros that are alone -# on a line, have an all uppercase name, and do not end with a semicolon. Such -# function macros are typically used for boiler-plate code, and will confuse +# If the SKIP_FUNCTION_MACROS tag is set to YES (the default) then +# doxygen's preprocessor will remove all function-like macros that are alone +# on a line, have an all uppercase name, and do not end with a semicolon. Such +# function macros are typically used for boiler-plate code, and will confuse # the parser if not removed. SKIP_FUNCTION_MACROS = YES #--------------------------------------------------------------------------- -# Configuration::additions related to external references +# Configuration::additions related to external references #--------------------------------------------------------------------------- -# The TAGFILES option can be used to specify one or more tagfiles. -# Optionally an initial location of the external documentation -# can be added for each tagfile. The format of a tag file without -# this location is as follows: -# TAGFILES = file1 file2 ... -# Adding location for the tag files is done as follows: -# TAGFILES = file1=loc1 "file2 = loc2" ... -# where "loc1" and "loc2" can be relative or absolute paths or -# URLs. If a location is present for each tag, the installdox tool +# The TAGFILES option can be used to specify one or more tagfiles. +# Optionally an initial location of the external documentation +# can be added for each tagfile. The format of a tag file without +# this location is as follows: +# TAGFILES = file1 file2 ... +# Adding location for the tag files is done as follows: +# TAGFILES = file1=loc1 "file2 = loc2" ... +# where "loc1" and "loc2" can be relative or absolute paths or +# URLs. If a location is present for each tag, the installdox tool # does not have to be run to correct the links. # Note that each tag file must have a unique name # (where the name does NOT include the path) -# If a tag file is not located in the directory in which doxygen +# If a tag file is not located in the directory in which doxygen # is run, you must also specify the path to the tagfile here. -TAGFILES = +TAGFILES = -# When a file name is specified after GENERATE_TAGFILE, doxygen will create +# When a file name is specified after GENERATE_TAGFILE, doxygen will create # a tag file that is based on the input files it reads. -GENERATE_TAGFILE = +GENERATE_TAGFILE = -# If the ALLEXTERNALS tag is set to YES all external classes will be listed -# in the class index. If set to NO only the inherited external classes +# If the ALLEXTERNALS tag is set to YES all external classes will be listed +# in the class index. If set to NO only the inherited external classes # will be listed. ALLEXTERNALS = NO -# If the EXTERNAL_GROUPS tag is set to YES all external groups will be listed -# in the modules index. If set to NO, only the current project's groups will +# If the EXTERNAL_GROUPS tag is set to YES all external groups will be listed +# in the modules index. If set to NO, only the current project's groups will # be listed. EXTERNAL_GROUPS = YES -# The PERL_PATH should be the absolute path and name of the perl script +# The PERL_PATH should be the absolute path and name of the perl script # interpreter (i.e. the result of `which perl'). PERL_PATH = /usr/bin/perl #--------------------------------------------------------------------------- -# Configuration options related to the dot tool +# Configuration options related to the dot tool #--------------------------------------------------------------------------- -# If the CLASS_DIAGRAMS tag is set to YES (the default) Doxygen will -# generate a inheritance diagram (in HTML, RTF and LaTeX) for classes with base -# or super classes. Setting the tag to NO turns the diagrams off. Note that -# this option is superseded by the HAVE_DOT option below. This is only a -# fallback. It is recommended to install and use dot, since it yields more +# If the CLASS_DIAGRAMS tag is set to YES (the default) Doxygen will +# generate a inheritance diagram (in HTML, RTF and LaTeX) for classes with base +# or super classes. Setting the tag to NO turns the diagrams off. Note that +# this option is superseded by the HAVE_DOT option below. This is only a +# fallback. It is recommended to install and use dot, since it yields more # powerful graphs. CLASS_DIAGRAMS = YES -# If set to YES, the inheritance and collaboration graphs will hide -# inheritance and usage relations if the target is undocumented +# If set to YES, the inheritance and collaboration graphs will hide +# inheritance and usage relations if the target is undocumented # or is not a class. HIDE_UNDOC_RELATIONS = YES -# If you set the HAVE_DOT tag to YES then doxygen will assume the dot tool is -# available from the path. This tool is part of Graphviz, a graph visualization -# toolkit from AT&T and Lucent Bell Labs. The other options in this section +# If you set the HAVE_DOT tag to YES then doxygen will assume the dot tool is +# available from the path. This tool is part of Graphviz, a graph visualization +# toolkit from AT&T and Lucent Bell Labs. The other options in this section # have no effect if this option is set to NO (the default) HAVE_DOT = NO -# If the CLASS_GRAPH and HAVE_DOT tags are set to YES then doxygen -# will generate a graph for each documented class showing the direct and -# indirect inheritance relations. Setting this tag to YES will force the +# If the CLASS_GRAPH and HAVE_DOT tags are set to YES then doxygen +# will generate a graph for each documented class showing the direct and +# indirect inheritance relations. Setting this tag to YES will force the # the CLASS_DIAGRAMS tag to NO. CLASS_GRAPH = YES -# If the COLLABORATION_GRAPH and HAVE_DOT tags are set to YES then doxygen -# will generate a graph for each documented class showing the direct and -# indirect implementation dependencies (inheritance, containment, and +# If the COLLABORATION_GRAPH and HAVE_DOT tags are set to YES then doxygen +# will generate a graph for each documented class showing the direct and +# indirect implementation dependencies (inheritance, containment, and # class references variables) of the class with other documented classes. COLLABORATION_GRAPH = YES -# If the GROUP_GRAPHS and HAVE_DOT tags are set to YES then doxygen +# If the GROUP_GRAPHS and HAVE_DOT tags are set to YES then doxygen # will generate a graph for groups, showing the direct groups dependencies GROUP_GRAPHS = YES -# If the UML_LOOK tag is set to YES doxygen will generate inheritance and -# collaboration diagrams in a style similar to the OMG's Unified Modeling +# If the UML_LOOK tag is set to YES doxygen will generate inheritance and +# collaboration diagrams in a style similar to the OMG's Unified Modeling # Language. UML_LOOK = NO -# If set to YES, the inheritance and collaboration graphs will show the +# If set to YES, the inheritance and collaboration graphs will show the # relations between templates and their instances. TEMPLATE_RELATIONS = YES -# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDE_GRAPH, and HAVE_DOT -# tags are set to YES then doxygen will generate a graph for each documented -# file showing the direct and indirect include dependencies of the file with +# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDE_GRAPH, and HAVE_DOT +# tags are set to YES then doxygen will generate a graph for each documented +# file showing the direct and indirect include dependencies of the file with # other documented files. INCLUDE_GRAPH = YES -# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDED_BY_GRAPH, and -# HAVE_DOT tags are set to YES then doxygen will generate a graph for each -# documented header file showing the documented files that directly or +# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDED_BY_GRAPH, and +# HAVE_DOT tags are set to YES then doxygen will generate a graph for each +# documented header file showing the documented files that directly or # indirectly include this file. INCLUDED_BY_GRAPH = YES -# If the CALL_GRAPH and HAVE_DOT tags are set to YES then doxygen will -# generate a call dependency graph for every global function or class method. -# Note that enabling this option will significantly increase the time of a run. -# So in most cases it will be better to enable call graphs for selected +# If the CALL_GRAPH and HAVE_DOT tags are set to YES then doxygen will +# generate a call dependency graph for every global function or class method. +# Note that enabling this option will significantly increase the time of a run. +# So in most cases it will be better to enable call graphs for selected # functions only using the \callgraph command. CALL_GRAPH = NO -# If the CALLER_GRAPH and HAVE_DOT tags are set to YES then doxygen will -# generate a caller dependency graph for every global function or class method. -# Note that enabling this option will significantly increase the time of a run. -# So in most cases it will be better to enable caller graphs for selected +# If the CALLER_GRAPH and HAVE_DOT tags are set to YES then doxygen will +# generate a caller dependency graph for every global function or class method. +# Note that enabling this option will significantly increase the time of a run. +# So in most cases it will be better to enable caller graphs for selected # functions only using the \callergraph command. CALLER_GRAPH = NO -# If the GRAPHICAL_HIERARCHY and HAVE_DOT tags are set to YES then doxygen +# If the GRAPHICAL_HIERARCHY and HAVE_DOT tags are set to YES then doxygen # will graphical hierarchy of all classes instead of a textual one. GRAPHICAL_HIERARCHY = YES -# If the DIRECTORY_GRAPH, SHOW_DIRECTORIES and HAVE_DOT tags are set to YES -# then doxygen will show the dependencies a directory has on other directories +# If the DIRECTORY_GRAPH, SHOW_DIRECTORIES and HAVE_DOT tags are set to YES +# then doxygen will show the dependencies a directory has on other directories # in a graphical way. The dependency relations are determined by the #include # relations between the files in the directories. DIRECTORY_GRAPH = YES -# The DOT_IMAGE_FORMAT tag can be used to set the image format of the images +# The DOT_IMAGE_FORMAT tag can be used to set the image format of the images # generated by dot. Possible values are png, jpg, or gif # If left blank png will be used. DOT_IMAGE_FORMAT = png -# The tag DOT_PATH can be used to specify the path where the dot tool can be +# The tag DOT_PATH can be used to specify the path where the dot tool can be # found. If left blank, it is assumed the dot tool can be found in the path. -DOT_PATH = +DOT_PATH = -# The DOTFILE_DIRS tag can be used to specify one or more directories that -# contain dot files that are included in the documentation (see the +# The DOTFILE_DIRS tag can be used to specify one or more directories that +# contain dot files that are included in the documentation (see the # \dotfile command). -DOTFILE_DIRS = +DOTFILE_DIRS = -# The MAX_DOT_GRAPH_WIDTH tag can be used to set the maximum allowed width -# (in pixels) of the graphs generated by dot. If a graph becomes larger than -# this value, doxygen will try to truncate the graph, so that it fits within -# the specified constraint. Beware that most browsers cannot cope with very +# The MAX_DOT_GRAPH_WIDTH tag can be used to set the maximum allowed width +# (in pixels) of the graphs generated by dot. If a graph becomes larger than +# this value, doxygen will try to truncate the graph, so that it fits within +# the specified constraint. Beware that most browsers cannot cope with very # large images. MAX_DOT_GRAPH_WIDTH = 1024 -# The MAX_DOT_GRAPH_HEIGHT tag can be used to set the maximum allows height -# (in pixels) of the graphs generated by dot. If a graph becomes larger than -# this value, doxygen will try to truncate the graph, so that it fits within -# the specified constraint. Beware that most browsers cannot cope with very +# The MAX_DOT_GRAPH_HEIGHT tag can be used to set the maximum allows height +# (in pixels) of the graphs generated by dot. If a graph becomes larger than +# this value, doxygen will try to truncate the graph, so that it fits within +# the specified constraint. Beware that most browsers cannot cope with very # large images. MAX_DOT_GRAPH_HEIGHT = 1024 -# The MAX_DOT_GRAPH_DEPTH tag can be used to set the maximum depth of the -# graphs generated by dot. A depth value of 3 means that only nodes reachable -# from the root by following a path via at most 3 edges will be shown. Nodes -# that lay further from the root node will be omitted. Note that setting this -# option to 1 or 2 may greatly reduce the computation time needed for large -# code bases. Also note that a graph may be further truncated if the graph's -# image dimensions are not sufficient to fit the graph (see MAX_DOT_GRAPH_WIDTH -# and MAX_DOT_GRAPH_HEIGHT). If 0 is used for the depth value (the default), +# The MAX_DOT_GRAPH_DEPTH tag can be used to set the maximum depth of the +# graphs generated by dot. A depth value of 3 means that only nodes reachable +# from the root by following a path via at most 3 edges will be shown. Nodes +# that lay further from the root node will be omitted. Note that setting this +# option to 1 or 2 may greatly reduce the computation time needed for large +# code bases. Also note that a graph may be further truncated if the graph's +# image dimensions are not sufficient to fit the graph (see MAX_DOT_GRAPH_WIDTH +# and MAX_DOT_GRAPH_HEIGHT). If 0 is used for the depth value (the default), # the graph is not depth-constrained. MAX_DOT_GRAPH_DEPTH = 0 -# Set the DOT_TRANSPARENT tag to YES to generate images with a transparent -# background. This is disabled by default, which results in a white background. -# Warning: Depending on the platform used, enabling this option may lead to -# badly anti-aliased labels on the edges of a graph (i.e. they become hard to +# Set the DOT_TRANSPARENT tag to YES to generate images with a transparent +# background. This is disabled by default, which results in a white background. +# Warning: Depending on the platform used, enabling this option may lead to +# badly anti-aliased labels on the edges of a graph (i.e. they become hard to # read). DOT_TRANSPARENT = NO -# Set the DOT_MULTI_TARGETS tag to YES allow dot to generate multiple output -# files in one run (i.e. multiple -o and -T options on the command line). This -# makes dot run faster, but since only newer versions of dot (>1.8.10) +# Set the DOT_MULTI_TARGETS tag to YES allow dot to generate multiple output +# files in one run (i.e. multiple -o and -T options on the command line). This +# makes dot run faster, but since only newer versions of dot (>1.8.10) # support this, this feature is disabled by default. DOT_MULTI_TARGETS = NO -# If the GENERATE_LEGEND tag is set to YES (the default) Doxygen will -# generate a legend page explaining the meaning of the various boxes and +# If the GENERATE_LEGEND tag is set to YES (the default) Doxygen will +# generate a legend page explaining the meaning of the various boxes and # arrows in the dot generated graphs. GENERATE_LEGEND = YES -# If the DOT_CLEANUP tag is set to YES (the default) Doxygen will -# remove the intermediate dot files that are used to generate +# If the DOT_CLEANUP tag is set to YES (the default) Doxygen will +# remove the intermediate dot files that are used to generate # the various graphs. DOT_CLEANUP = YES #--------------------------------------------------------------------------- -# Configuration::additions related to the search engine +# Configuration::additions related to the search engine #--------------------------------------------------------------------------- -# The SEARCHENGINE tag specifies whether or not a search engine should be +# The SEARCHENGINE tag specifies whether or not a search engine should be # used. If set to NO the values of all tags below this one will be ignored. SEARCHENGINE = NO diff --git a/source/Digitisers/include/DDPlanarDigiProcessor.h b/source/Digitisers/include/DDPlanarDigiProcessor.h index c8254e4..d0d22e8 100644 --- a/source/Digitisers/include/DDPlanarDigiProcessor.h +++ b/source/Digitisers/include/DDPlanarDigiProcessor.h @@ -5,32 +5,31 @@ #include "lcio.h" +#include #include #include -#include -#include #include "DDRec/Surface.h" #include "DDRec/SurfaceManager.h" +#include #include -using namespace lcio ; -using namespace marlin ; +using namespace lcio; +using namespace marlin; namespace EVENT { - class SimTrackerHit; +class SimTrackerHit; } - /** ======= DDPlanarDigiProcessor ==========
- * Creates TrackerHits from SimTrackerHits, smearing them according to the input parameters. + * Creates TrackerHits from SimTrackerHits, smearing them according to the input parameters. * The positions of "digitized" TrackerHits are obtained by gaussian smearing positions - * of SimTrackerHits perpendicular and along the ladder according to the specified point resolutions. + * of SimTrackerHits perpendicular and along the ladder according to the specified point resolutions. * The geometry of the surface is retreived from DDRec::Surface associated to the hit via cellID. - * - * - *

Input collections and prerequisites

+ * + * + *

Input collections and prerequisites

* Processor requires a collection of SimTrackerHits
*

Output

* Processor produces collection of smeared TrackerHits
@@ -49,78 +48,66 @@ namespace EVENT { * @param Sub_Detector_ID ID of Sub-Detector using UTIL/ILDConf.h from lcio
* (default value lcio::ILDDetID::VXD)
*
- * + * * @author F.Gaede CERN/DESY, S. Aplin DESY * @date Dec 2014 */ class DDPlanarDigiProcessor : public Processor { - + public: - - virtual Processor* newProcessor() { return new DDPlanarDigiProcessor ; } - - - DDPlanarDigiProcessor() ; - + virtual Processor* newProcessor() { return new DDPlanarDigiProcessor; } + + DDPlanarDigiProcessor(); + /** Called at the begin of the job before anything is read. * Use to initialize the processor, e.g. book histograms. */ - virtual void init() ; - + virtual void init(); + /** Called for every run. */ - virtual void processRunHeader( LCRunHeader* run ) ; - + virtual void processRunHeader(LCRunHeader* run); + /** Called for every event - the working horse. */ - virtual void processEvent( LCEvent * evt ) ; - - - virtual void check( LCEvent * evt ) ; - - + virtual void processEvent(LCEvent* evt); + + virtual void check(LCEvent* evt); + /** Called after data processing for clean up. */ - virtual void end() ; - - + virtual void end(); - protected: - - std::string _inColName ; - - std::string _outColName ; - std::string _outRelColName ; - - std::string _subDetName ; - - int _nRun ; - int _nEvt ; - - FloatVec _resU ; - FloatVec _resV ; - FloatVec _resT ; - - bool _isStrip; - - gsl_rng* _rng ; - - const dd4hep::rec::SurfaceMap* _map ; + std::string _inColName; - bool _forceHitsOntoSurface ; - double _minEnergy ; + std::string _outColName; + std::string _outRelColName; - bool _useTimeWindow ; - bool _correctTimesForPropagation ; - FloatVec _timeWindow_min ; - FloatVec _timeWindow_max ; + std::string _subDetName; - std::vector _h ; - -} ; + int _nRun; + int _nEvt; -#endif + FloatVec _resU; + FloatVec _resV; + FloatVec _resT; + + bool _isStrip; + + gsl_rng* _rng; + + const dd4hep::rec::SurfaceMap* _map; + bool _forceHitsOntoSurface; + double _minEnergy; + bool _useTimeWindow; + bool _correctTimesForPropagation; + FloatVec _timeWindow_min; + FloatVec _timeWindow_max; + std::vector _h; +}; + +#endif diff --git a/source/Digitisers/include/DDSpacePointBuilder.h b/source/Digitisers/include/DDSpacePointBuilder.h index e856076..1bf5f61 100644 --- a/source/Digitisers/include/DDSpacePointBuilder.h +++ b/source/Digitisers/include/DDSpacePointBuilder.h @@ -1,131 +1,119 @@ #ifndef DDSpacePointBuilder_h #define DDSpacePointBuilder_h 1 -#include "marlin/Processor.h" #include "lcio.h" -#include -#include +#include "marlin/Processor.h" #include #include #include +#include +#include -#include "CLHEP/Vector/ThreeVector.h" #include "CLHEP/Vector/Rotation.h" +#include "CLHEP/Vector/ThreeVector.h" // DD4HEP classes -#include "DDRec/Vector2D.h" -#include "DDRec/Vector3D.h" -#include "DDRec/ISurface.h" +#include "DD4hep/DD4hepUnits.h" #include "DD4hep/Detector.h" -#include "DDRec/SurfaceManager.h" +#include "DDRec/ISurface.h" #include "DDRec/SurfaceHelper.h" -#include "DD4hep/DD4hepUnits.h" - -using namespace lcio ; -using namespace marlin ; - - - +#include "DDRec/SurfaceManager.h" +#include "DDRec/Vector2D.h" +#include "DDRec/Vector3D.h" +using namespace lcio; +using namespace marlin; /** ================= FTD Space Point Builder ================= - * - * Builds space points for pairs of silicon strip detectors. - * The digitisers create TrackerHitPlanars for the front and the back strips. - * In order to get a spacepoint (as is needed by track reconstruction) those strip measurements need to be combined into one space point. - * - * This is done by this processor. - * + * + * Builds space points for pairs of silicon strip detectors. + * The digitisers create TrackerHitPlanars for the front and the back strips. + * In order to get a spacepoint (as is needed by track reconstruction) those strip measurements need to be combined into + * one space point. + * + * This is done by this processor. + * *

Input - Prerequisites

- * - * The TrackerHitPlanars as created by the Digitisers of FTD, SET or SIT. + * + * The TrackerHitPlanars as created by the Digitisers of FTD, SET or SIT. * This could of course be used for other detectors as well, but as information about the detector * is acquired from DDRec, and as different detectors (at the moment) are stored differently * in DDRec, used detectors have to be taken care of in the code. * - *

Output

- * + *

Output

+ * * A collection of TrackerHits containing the constructed space points. - * The created hits will store the original strip hits in their rawHits. - * - * @param TrackerHitCollection The name of the input collection of TrackerHits coming from strip detectors on the FTD, SIT or SET
- * (default name FTDTrackerHits)
- * + * The created hits will store the original strip hits in their rawHits. + * + * @param TrackerHitCollection The name of the input collection of TrackerHits coming from strip detectors on the FTD, + * SIT or SET
(default name FTDTrackerHits)
+ * * @param SpacePointsCollection The name of the output collection of the created spacepoints
* (default name FTDSpacePoints)
- * - * @param TrackerHitSimHitRelCollection The name of the input collection of the relations of the TrackerHits to SimHits
- * (default name FTDTrackerHitRelations)
- * + * + * @param TrackerHitSimHitRelCollection The name of the input collection of the relations of the TrackerHits to + * SimHits
(default name FTDTrackerHitRelations)
+ * * @param SimHitSpacePointRelCollection The name of the SpacePoint SimTrackerHit relation output collection
* (default name VTXTrackerHitRelations)
- * + * * @author Robin Glattauer HEPHY, Vienna * */ class DDSpacePointBuilder : public Processor { - - public: - - virtual Processor* newProcessor() { return new DDSpacePointBuilder ; } - - - DDSpacePointBuilder() ; - + +public: + virtual Processor* newProcessor() { return new DDSpacePointBuilder; } + + DDSpacePointBuilder(); + /** Called at the begin of the job before anything is read. * Use to initialize the processor, e.g. book histograms. */ - virtual void init() ; - + virtual void init(); + /** Called for every run. */ - virtual void processRunHeader( LCRunHeader* run ) ; - + virtual void processRunHeader(LCRunHeader* run); + /** Called for every event - the working horse. */ - virtual void processEvent( LCEvent * evt ) ; - - - virtual void check( LCEvent * evt ) ; - - - /** Called after data processing for clean up. - */ - virtual void end() ; - - - - - protected: + virtual void processEvent(LCEvent* evt); + virtual void check(LCEvent* evt); + /** Called after data processing for clean up. + */ + virtual void end(); +protected: /** Input collection name. - */ + */ std::string _TrackerHitCollection; /** Input relation collection name. */ std::string _TrackerHitSimHitRelCollection; - + /** Output collection name. - */ + */ std::string _SpacePointsCollection; - + /** Output relations collection name. */ std::string _relColName; /** Calculates the 2 dimensional crossing point of two lines. * Each line is specified by a point (x,y) and a direction vector (ex,ey). - * + * * @return 0, if the calculation has been successful, another number if there was a problem. */ - static int calculateXingPoint( double x1, double y1, float ex1, float ey1, double x2, double y2, float ex2, float ey2, double& x, double& y ); - + static int calculateXingPoint(double x1, double y1, float ex1, float ey1, double x2, double y2, float ex2, float ey2, + double& x, double& y); + /** Calculates a point between two lines in a way that it is equidistant from both lines and as close to them as - * possible. - * So when you calculate the distance between two lines, and you actually draw this distance as a short connecting + * possible. + * So when you calculate the distance between two lines, and you actually draw this distance as a short connecting * line, the point in the middle of this line, is what this method finds. * \verbatim / @@ -135,69 +123,59 @@ class DDSpacePointBuilder : public Processor { ---------/-------------- (line a) / /(line b) - + \endverbatim * (If this sketch looks terrible, you probably read this in doxygen and it still needs to be formatted in a * way, that it still looks sensible in doxygen.) - * + * * @param P1 a point on the first line * @param V1 the direction vector of the first line - * + * * @param point the reference to a point where the result will be stored */ - static int calculatePointBetweenTwoLines( - const CLHEP::Hep3Vector& P1, - const CLHEP::Hep3Vector& V1, - const CLHEP::Hep3Vector& P2, - const CLHEP::Hep3Vector& V2, - CLHEP::Hep3Vector& point ); - - - - /** Calculates the intersection of a line L and line PAPB ( strip on the first sensor ). - * L is constrained to pass through the point "Vertex" and bisect both lines PAPB ( strip on the first sensor ) and PCPD ( strip on the second sensor ) + static int calculatePointBetweenTwoLines(const CLHEP::Hep3Vector& P1, const CLHEP::Hep3Vector& V1, + const CLHEP::Hep3Vector& P2, const CLHEP::Hep3Vector& V2, + CLHEP::Hep3Vector& point); + + /** Calculates the intersection of a line L and line PAPB ( strip on the first sensor ). + * L is constrained to pass through the point "Vertex" and bisect both lines PAPB ( strip on the first sensor ) and + * PCPD ( strip on the second sensor ) * @param PA start of the first line * @param PB end of the first line * @param PC start of the second line * @param PD end of the second line - * @param Vertex the position - * + * @param Vertex the position + * * @param point the reference to a point where the result will be stored */ - static int calculatePointBetweenTwoLines_UsingVertex( - const CLHEP::Hep3Vector& PA, - const CLHEP::Hep3Vector& PB, - const CLHEP::Hep3Vector& PC, - const CLHEP::Hep3Vector& PD, - const CLHEP::Hep3Vector& Vertex, - CLHEP::Hep3Vector& point); - - - /** @return a spacepoint (in the form of a TrackerHitImpl* ) created from two TrackerHitPlane* which stand for si-strips */ - - TrackerHitImpl* createSpacePoint( TrackerHitPlane* a , TrackerHitPlane* b, double stripLength ); - + static int calculatePointBetweenTwoLines_UsingVertex(const CLHEP::Hep3Vector& PA, const CLHEP::Hep3Vector& PB, + const CLHEP::Hep3Vector& PC, const CLHEP::Hep3Vector& PD, + const CLHEP::Hep3Vector& Vertex, CLHEP::Hep3Vector& point); + + /** @return a spacepoint (in the form of a TrackerHitImpl* ) created from two TrackerHitPlane* which stand for + * si-strips */ + + TrackerHitImpl* createSpacePoint(TrackerHitPlane* a, TrackerHitPlane* b, double stripLength); + /** @return the CellID0s of the sensors that are back to back to a given front sensor. If the given sensor * is in the back itself or has no corresponding sensor(s) on the back the vector will be empty. - * + * * @param cellID0 a CellID0 corresponding to a sensor */ - std::vector< int > getCellID0sAtBack( int cellID0 ); - - std::vector< int > getCellID0sAtBackOfFTD( int cellID0 ); - - std::vector< int > getCellID0sAtBackOfSET( int cellID0 ); - - std::vector< int > getCellID0sAtBackOfSIT( int cellID0 ); - - - /** @return information about the contents of the passed CellID0 */ - std::string getCellID0Info( int cellID0 ); - - - int _nRun ; - int _nEvt ; + std::vector getCellID0sAtBack(int cellID0); + + std::vector getCellID0sAtBackOfFTD(int cellID0); + + std::vector getCellID0sAtBackOfSET(int cellID0); + + std::vector getCellID0sAtBackOfSIT(int cellID0); + + /** @return information about the contents of the passed CellID0 */ + std::string getCellID0Info(int cellID0); + + int _nRun; + int _nEvt; unsigned _nOutOfBoundary; unsigned _nStripsTooParallel; @@ -211,15 +189,11 @@ class DDSpacePointBuilder : public Processor { float _striplength_tolerance; - double _striplength ; - std::string _subDetName ; + double _striplength; + std::string _subDetName; - //dd4hep::Detector& lcdd; - const dd4hep::rec::SurfaceMap* surfMap ; - -} ; + // dd4hep::Detector& lcdd; + const dd4hep::rec::SurfaceMap* surfMap; +}; #endif - - - diff --git a/source/Digitisers/include/DDTPCDigiProcessor.h b/source/Digitisers/include/DDTPCDigiProcessor.h index 88974a8..8650110 100644 --- a/source/Digitisers/include/DDTPCDigiProcessor.h +++ b/source/Digitisers/include/DDTPCDigiProcessor.h @@ -1,16 +1,24 @@ /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* -Evolved version of TPCDigi that provides additional functionality to deal with background. Couple to the Mokka Sensitive Detector Driver TPCSD03.cc +Evolved version of TPCDigi that provides additional functionality to deal with background. Couple to the Mokka Sensitive +Detector Driver TPCSD03.cc SJA:FIXME: Still needs to be tidied up for production release. Three cases can be consider in the treatment of SimTrackerHits -i) A clean isolated hit; this will be smeared according to the parametric point resolution and converted to a TrackerHit -ii) Two or Three hits which are considered to be closer than the double hit resolution and which therefore cannot be viewed as seperable hits. These will be merged and be assigned a large associated measurement error. -iii) A continuous set of hits within one pad row which cannot be resolved as single hits, these are condidered to be charaterisable as background hits created by extremely low pt charged particles (pt < 10MeV) and therefore are removed from the hit collection. - -The Driver has been modified to take an additional collection of SimTrackerHits which are produced by the Mokka TPC Sensitive Driver TPCSD03.cc. These hits are produced for particles which have very low pt and often do not move outside of the dimensions of a single pad row. These hits need to be treated differently as they do not cross any geometric boundaries in a Padrow based TPC Geometry. This negates the need to voxalise the TPC in Geant4 which has proved in the past to be prohibitive in terms of processing time due to the vastly increased number of geometric volumes. +i) A clean isolated hit; this will be smeared according to the parametric point resolution and converted to a +TrackerHit ii) Two or Three hits which are considered to be closer than the double hit resolution and which therefore +cannot be viewed as seperable hits. These will be merged and be assigned a large associated measurement error. iii) A +continuous set of hits within one pad row which cannot be resolved as single hits, these are condidered to be +charaterisable as background hits created by extremely low pt charged particles (pt < 10MeV) and therefore are removed +from the hit collection. + +The Driver has been modified to take an additional collection of SimTrackerHits which are produced by the Mokka TPC +Sensitive Driver TPCSD03.cc. These hits are produced for particles which have very low pt and often do not move outside +of the dimensions of a single pad row. These hits need to be treated differently as they do not cross any geometric +boundaries in a Padrow based TPC Geometry. This negates the need to voxalise the TPC in Geant4 which has proved in the +past to be prohibitive in terms of processing time due to the vastly increased number of geometric volumes. Steve Aplin 26 June 2009 (DESY) @@ -19,20 +27,19 @@ Steve Aplin 26 June 2009 (DESY) #ifndef DDTPCDigiProcessor_h #define DDTPCDigiProcessor_h 1 -#include #include +#include - -#include #include +#include #ifdef MARLIN_USE_AIDA -#include -#include #include +#include +#include -//#define DIGIPLOTS +// #define DIGIPLOTS #ifdef DIGIPLOTS // includes all AIDA header files #include @@ -40,13 +47,13 @@ Steve Aplin 26 June 2009 (DESY) #endif -#include #include +#include #include -#include #include #include +#include #include #include @@ -56,33 +63,33 @@ Steve Aplin 26 June 2009 (DESY) class Voxel_tpc; -class TPCModularEndplate ; +class TPCModularEndplate; namespace UTIL { - class LCRelationNavigator; +class LCRelationNavigator; } /** ====== DDTPCDigiProcessor ======
* * This Processor depends on Circle.h from MarlinUtil - * - * Caution: This digitiser presently does not process space-point like SimTrackerHits which have been flagged with CellIDs set to the negetive row number. This must be implemented in future. - *Produces TPC TrackerHit collection from SimTrackerHit collection, smeared in r-phi and z. - * Double hits are identified but are currently not added to the collection. This may be change - * at a later date when criteria for their seperation is defined. The resolutions are defined in - * the GEAR stearing file. + * + * Caution: This digitiser presently does not process space-point like SimTrackerHits which have been flagged with + *CellIDs set to the negetive row number. This must be implemented in future. Produces TPC TrackerHit collection from + *SimTrackerHit collection, smeared in r-phi and z. Double hits are identified but are currently not added to the + *collection. This may be change at a later date when criteria for their seperation is defined. The resolutions are + *defined in the GEAR stearing file. * * Resolution in r-phi is calculated according to the formular
* sigma_{point}^2 = sigma_0^2 + Cd^2/N_{eff} * L_{drift} * Cd^2/N_{eff}} = 25^2/(22/sin(theta)*h/6mm) * Cd = 25 ( microns / cm^(1/2) ) * (this is for B=4T, h is the pad height = pad-row pitch in mm, - * theta is the polar angle) + * theta is the polar angle) * * At the moment resolution in z assumed to be independent of drift length.
* * The type of TPC TrackerHit is set to 500 via method TrackerHitImpl::setType(int type)
- *

Input collections and prerequisites

+ *

Input collections and prerequisites

* Processor requires collections of SimTrackerHits in TPC
*

Output

* Processor produces collection of digitized TrackerHits in TPC
@@ -104,77 +111,73 @@ namespace UTIL { * 06/2017 FG: replace Gear with DDRec * FG: remove hits that are inside the module gaps on the endplate (see parameters TPCEndPlateModulexxxx) * (set TPCEndPlateModuleGapPhi=0 to not remove any hits) - * - * Changed 7/9/07 so that the const and diffusion resolution terms are taken as processor parameters rather than the gear file. - * The parameters _pixZ and pixRP were also changed from gear parameters to processor parameters + * + * Changed 7/9/07 so that the const and diffusion resolution terms are taken as processor parameters rather than the + *gear file. The parameters _pixZ and pixRP were also changed from gear parameters to processor parameters * clare.lynch@bristol.ac.uk * */ class DDTPCDigiProcessor : public marlin::Processor { - + public: - - virtual Processor* newProcessor() { return new DDTPCDigiProcessor ; } - - - DDTPCDigiProcessor() ; - - ~DDTPCDigiProcessor() ; - + virtual Processor* newProcessor() { return new DDTPCDigiProcessor; } + + DDTPCDigiProcessor(); + + ~DDTPCDigiProcessor(); + /** Called at the begin of the job before anything is read. * Use to initialize the processor, e.g. book histograms. */ - virtual void init() ; - + virtual void init(); + /** Called for every run. */ - virtual void processRunHeader( LCRunHeader* run ) ; - + virtual void processRunHeader(LCRunHeader* run); + /** Called for every event - the working horse. */ - virtual void processEvent( LCEvent * evt ) ; - - - virtual void check( LCEvent * evt ) ; - - + virtual void processEvent(LCEvent* evt); + + virtual void check(LCEvent* evt); + /** Called after data processing for clean up. */ - virtual void end() ; - - void writeVoxelToHit( Voxel_tpc* aVoxel, UTIL::LCRelationNavigator& hitSimHitNav) ; - void writeMergedVoxelsToHit( std::vector * hitList, UTIL::LCRelationNavigator& hitSimHitNav ) ; - void plotHelixHitResidual(MCParticle *mcp, CLHEP::Hep3Vector *thisPointRPhi); - double getPadPhi( CLHEP::Hep3Vector* thisPointRPhi, CLHEP::Hep3Vector* firstPointRPhi, CLHEP::Hep3Vector* middlePointRPhi, CLHEP::Hep3Vector* lastPointRPhi); - double getPadTheta( CLHEP::Hep3Vector* firstPointRPhi, CLHEP::Hep3Vector* middlePointRPhi, CLHEP::Hep3Vector* lastPointRPhi ); + virtual void end(); -protected: + void writeVoxelToHit(Voxel_tpc* aVoxel, UTIL::LCRelationNavigator& hitSimHitNav); + void writeMergedVoxelsToHit(std::vector* hitList, UTIL::LCRelationNavigator& hitSimHitNav); + void plotHelixHitResidual(MCParticle* mcp, CLHEP::Hep3Vector* thisPointRPhi); + double getPadPhi(CLHEP::Hep3Vector* thisPointRPhi, CLHEP::Hep3Vector* firstPointRPhi, + CLHEP::Hep3Vector* middlePointRPhi, CLHEP::Hep3Vector* lastPointRPhi); + double getPadTheta(CLHEP::Hep3Vector* firstPointRPhi, CLHEP::Hep3Vector* middlePointRPhi, + CLHEP::Hep3Vector* lastPointRPhi); +protected: /** Input collection name. */ - std::string _padRowHitColName {}; - std::string _spacePointColName {}; - std::string _lowPtHitscolName {}; + std::string _padRowHitColName{}; + std::string _spacePointColName{}; + std::string _lowPtHitscolName{}; - /** Output collection name. */ - std::string _TPCTrackerHitsCol {}; - std::string _outRelColName {}; + std::string _TPCTrackerHitsCol{}; + std::string _outRelColName{}; bool _use_raw_hits_to_store_simhit_pointer{}; - + int _rejectCellID0{}; float _padWidth{}; - int _nRun {}; - int _nEvt {}; + int _nRun{}; + int _nEvt{}; EVENT::MCParticle* _mcp{}; EVENT::MCParticle* _previousMCP{}; EVENT::MCParticle* _nextMCP{}; EVENT::MCParticle* _nMinus2MCP{}; - EVENT::MCParticle* _nPlus2MCP{}; + EVENT::MCParticle* _nPlus2MCP{}; SimTrackerHit* _SimTHit{}; SimTrackerHit* _previousSimTHit{}; @@ -183,16 +186,15 @@ class DDTPCDigiProcessor : public marlin::Processor { SimTrackerHit* _nMinus2SimHit{}; // gsl random number generator - gsl_rng * _random {}; - - float _pointResoRPhi0{}; // Coefficient for RPhi point res independant of drift length - float _pointResoPadPhi{}; // Coefficient for the point res dependance on relative phi angle to the pad verticle - float _diffRPhi{}; // Coefficient for the rphi point res dependance on diffusion - int _nEff{}; // number of effective electrons + gsl_rng* _random{}; + float _pointResoRPhi0{}; // Coefficient for RPhi point res independant of drift length + float _pointResoPadPhi{}; // Coefficient for the point res dependance on relative phi angle to the pad verticle + float _diffRPhi{}; // Coefficient for the rphi point res dependance on diffusion + int _nEff{}; // number of effective electrons - float _pointResoZ0{}; // Coefficient Z point res independant of drift length - float _diffZ{}; // Coefficient for the Z point res dependance on diffusion + float _pointResoZ0{}; // Coefficient Z point res independant of drift length + float _diffZ{}; // Coefficient for the Z point res dependance on diffusion float _binningZ{}; float _binningRPhi{}; @@ -202,84 +204,74 @@ class DDTPCDigiProcessor : public marlin::Processor { int _nRechits{}; - std::vector< std::vector > _tpcRowHits{}; - std::map< Voxel_tpc *,SimTrackerHit *> _tpcHitMap{}; + std::vector> _tpcRowHits{}; + std::map _tpcHitMap{}; std::vector _length{}; int lenpos{}; LCCollectionVec* _trkhitVec{}; - CellIDEncoder* _cellid_encoder {}; - - int _NSimTPCHits{}; - int _NBackgroundSimTPCHits{}; - int _NPhysicsSimTPCHits{}; - int _NPhysicsAbove02GeVSimTPCHits{}; - int _NPhysicsAbove1GeVSimTPCHits{}; - int _NRecTPCHits{}; - - int _NLostPhysicsTPCHits{}; - int _NLostPhysicsAbove02GeVPtTPCHits{}; - int _NLostPhysicsAbove1GeVPtTPCHits{}; - int _NRevomedHits{}; - - const dd4hep::rec::FixedPadSizeTPCData* _tpc{}; - double _bField{}; - - - IntVec _tpcEndPlateModuleNumbers{} ; - FloatVec _tpcEndPlateModulePhi0s{} ; - float _tpcEndPlateModuleGapPhi{} ; - float _tpcEndPlateModuleGapR{} ; + CellIDEncoder* _cellid_encoder{}; - TPCModularEndplate* _tpcEP{} ; + int _NSimTPCHits{}; + int _NBackgroundSimTPCHits{}; + int _NPhysicsSimTPCHits{}; + int _NPhysicsAbove02GeVSimTPCHits{}; + int _NPhysicsAbove1GeVSimTPCHits{}; + int _NRecTPCHits{}; + int _NLostPhysicsTPCHits{}; + int _NLostPhysicsAbove02GeVPtTPCHits{}; + int _NLostPhysicsAbove1GeVPtTPCHits{}; + int _NRevomedHits{}; -#ifdef DIGIPLOTS - IAnalysisFactory * _AF{}; - ITreeFactory * _TRF{}; - ITree * _TREE{}; - IHistogramFactory * _HF{}; - IHistogram1D * _phiDiffHisto{}; - IHistogram1D * _thetaDiffHisto{}; - IHistogram1D * _phiRelHisto{}; - IHistogram1D * _thetaRelHisto{}; - - IHistogram1D * _phiDistHisto{}; - IHistogram1D * _rPhiPullHisto{}; - IHistogram1D * _rPhiDiffHisto{}; - IHistogram1D * _zDiffHisto{}; - IHistogram1D * _zPullHisto{}; - IHistogram2D * _zSigmaVsZHisto{}; - IHistogram1D * _zSigmaHisto{}; - IHistogram1D * _rPhiSigmaHisto{}; - IHistogram1D * _radiusCheckHisto{}; - IHistogram1D * _ResidualsRPhiHisto{}; - - IHistogram1D * _NSimTPCHitsHisto{}; - IHistogram1D * _NBackgroundSimTPCHitsHisto{}; - IHistogram1D * _NPhysicsSimTPCHitsHisto{}; - IHistogram1D * _NPhysicsAbove02GeVSimTPCHitsHisto{}; - IHistogram1D * _NPhysicsAbove1GeVSimTPCHitsHisto{}; - IHistogram1D * _NRecTPCHitsHisto{}; - - IHistogram1D * _NLostPhysicsTPCHitsHisto{}; - IHistogram1D * _NLostPhysicsAbove02GeVPtTPCHitsHisto{}; - IHistogram1D * _NLostPhysicsAbove1GeVPtTPCHitsHisto{}; - IHistogram1D * _NRevomedHitsHisto{}; - - IHistogram1D * _NKeptPhysicsTPCHitsHistoPercent{}; - IHistogram1D * _NKeptPhysicsAbove02GeVPtTPCHitsHistoPercent{}; - IHistogram1D * _NKeptPhysicsAbove1GeVPtTPCHitsHistoPercent{}; - -#endif - - -} ; + const dd4hep::rec::FixedPadSizeTPCData* _tpc{}; + double _bField{}; + IntVec _tpcEndPlateModuleNumbers{}; + FloatVec _tpcEndPlateModulePhi0s{}; + float _tpcEndPlateModuleGapPhi{}; + float _tpcEndPlateModuleGapR{}; + TPCModularEndplate* _tpcEP{}; +#ifdef DIGIPLOTS + IAnalysisFactory* _AF{}; + ITreeFactory* _TRF{}; + ITree* _TREE{}; + IHistogramFactory* _HF{}; + IHistogram1D* _phiDiffHisto{}; + IHistogram1D* _thetaDiffHisto{}; + IHistogram1D* _phiRelHisto{}; + IHistogram1D* _thetaRelHisto{}; + + IHistogram1D* _phiDistHisto{}; + IHistogram1D* _rPhiPullHisto{}; + IHistogram1D* _rPhiDiffHisto{}; + IHistogram1D* _zDiffHisto{}; + IHistogram1D* _zPullHisto{}; + IHistogram2D* _zSigmaVsZHisto{}; + IHistogram1D* _zSigmaHisto{}; + IHistogram1D* _rPhiSigmaHisto{}; + IHistogram1D* _radiusCheckHisto{}; + IHistogram1D* _ResidualsRPhiHisto{}; + + IHistogram1D* _NSimTPCHitsHisto{}; + IHistogram1D* _NBackgroundSimTPCHitsHisto{}; + IHistogram1D* _NPhysicsSimTPCHitsHisto{}; + IHistogram1D* _NPhysicsAbove02GeVSimTPCHitsHisto{}; + IHistogram1D* _NPhysicsAbove1GeVSimTPCHitsHisto{}; + IHistogram1D* _NRecTPCHitsHisto{}; + + IHistogram1D* _NLostPhysicsTPCHitsHisto{}; + IHistogram1D* _NLostPhysicsAbove02GeVPtTPCHitsHisto{}; + IHistogram1D* _NLostPhysicsAbove1GeVPtTPCHitsHisto{}; + IHistogram1D* _NRevomedHitsHisto{}; + + IHistogram1D* _NKeptPhysicsTPCHitsHistoPercent{}; + IHistogram1D* _NKeptPhysicsAbove02GeVPtTPCHitsHistoPercent{}; + IHistogram1D* _NKeptPhysicsAbove1GeVPtTPCHitsHistoPercent{}; #endif +}; - - +#endif diff --git a/source/Digitisers/src/DDPlanarDigiProcessor.cc b/source/Digitisers/src/DDPlanarDigiProcessor.cc index 88346a7..bfdf929 100644 --- a/source/Digitisers/src/DDPlanarDigiProcessor.cc +++ b/source/Digitisers/src/DDPlanarDigiProcessor.cc @@ -2,578 +2,500 @@ #include "DDPlanarDigiProcessor.h" #include +#include +#include #include #include -#include #include -#include -#include #include "UTIL/LCTrackerConf.h" -#include #include +#include +#include #include - -#include "DD4hep/Detector.h" #include "DD4hep/DD4hepUnits.h" +#include "DD4hep/Detector.h" #include -#include #include +#include #include "AIDA/AIDA.h" -#include "marlin/ProcessorEventSeeder.h" #include "marlin/AIDAProcessor.h" #include "marlin/Global.h" +#include "marlin/ProcessorEventSeeder.h" #include "CLHEP/Vector/TwoVector.h" -#include #include -#include -#include -#include #include +#include +#include +#include +#include -using namespace lcio ; -using namespace marlin ; -using namespace std ; - +using namespace lcio; +using namespace marlin; +using namespace std; -DDPlanarDigiProcessor aDDPlanarDigiProcessor ; +DDPlanarDigiProcessor aDDPlanarDigiProcessor; DDPlanarDigiProcessor::DDPlanarDigiProcessor() : Processor("DDPlanarDigiProcessor") { - + // modify processor description - _description = "DDPlanarDigiProcessor creates TrackerHits from SimTrackerHits, smearing their position and time according to the input parameters." - "The geoemtry of the surface is taken from the DDRec::Surface associated to the hit via the cellID" ; - - + _description = "DDPlanarDigiProcessor creates TrackerHits from SimTrackerHits, smearing their position and time " + "according to the input parameters." + "The geoemtry of the surface is taken from the DDRec::Surface associated to the hit via the cellID"; + // register steering parameters: name, description, class-variable, default value - - FloatVec resUEx ; - resUEx.push_back( 0.0040 ) ; - - registerProcessorParameter( "ResolutionU" , - "resolution in direction of u - either one per layer or one for all layers " , - _resU , - resUEx) ; - - FloatVec resVEx ; - resVEx.push_back( 0.0040 ) ; - - registerProcessorParameter( "ResolutionV" , - "resolution in direction of v - either one per layer or one for all layers " , - _resV , - resVEx ); - - FloatVec resTEx ; - resTEx.push_back( -1 ) ; - - registerProcessorParameter( "ResolutionT" , - "resolution of time - either one per layer or one for all layers. if the single entry is negative, disable time smearing. " , - _resT , - resTEx ); - - registerProcessorParameter( "IsStrip", - "whether hits are 1D strip hits", - _isStrip, - bool(false) ); - - - registerProcessorParameter( "SubDetectorName" , - "Name of dub detector" , - _subDetName , - std::string("VXD") ); - + + FloatVec resUEx; + resUEx.push_back(0.0040); + + registerProcessorParameter( + "ResolutionU", "resolution in direction of u - either one per layer or one for all layers ", _resU, resUEx); + + FloatVec resVEx; + resVEx.push_back(0.0040); + + registerProcessorParameter( + "ResolutionV", "resolution in direction of v - either one per layer or one for all layers ", _resV, resVEx); + + FloatVec resTEx; + resTEx.push_back(-1); + + registerProcessorParameter("ResolutionT", + "resolution of time - either one per layer or one for all layers. if the single entry is " + "negative, disable time smearing. ", + _resT, resTEx); + + registerProcessorParameter("IsStrip", "whether hits are 1D strip hits", _isStrip, bool(false)); + + registerProcessorParameter("SubDetectorName", "Name of dub detector", _subDetName, std::string("VXD")); + // Input collections - registerInputCollection( LCIO::SIMTRACKERHIT, - "SimTrackHitCollectionName" , - "Name of the Input SimTrackerHit collection" , - _inColName , - std::string("VXDCollection") ) ; - - + registerInputCollection(LCIO::SIMTRACKERHIT, "SimTrackHitCollectionName", + "Name of the Input SimTrackerHit collection", _inColName, std::string("VXDCollection")); + // Output collections - registerOutputCollection( LCIO::TRACKERHITPLANE, - "TrackerHitCollectionName" , - "Name of the TrackerHit output collection" , - _outColName , - std::string("VTXTrackerHits") ) ; - - registerOutputCollection(LCIO::LCRELATION, - "SimTrkHitRelCollection", - "Name of TrackerHit SimTrackHit relation collection", - _outRelColName, + registerOutputCollection(LCIO::TRACKERHITPLANE, "TrackerHitCollectionName", + "Name of the TrackerHit output collection", _outColName, std::string("VTXTrackerHits")); + + registerOutputCollection(LCIO::LCRELATION, "SimTrkHitRelCollection", + "Name of TrackerHit SimTrackHit relation collection", _outRelColName, std::string("VTXTrackerHitRelations")); - - registerProcessorParameter( "ForceHitsOntoSurface" , - "Project hits onto the surface in case they are not yet on the surface (default: false)" , - _forceHitsOntoSurface , - bool(false) ); - - registerProcessorParameter( "MinimumEnergyPerHit" , - "Minimum Energy (in GeV!) to accept hits, other hits are ignored", - _minEnergy, - double(0.0) ); - - registerProcessorParameter( "CorrectTimesForPropagation" , - "Correct hit time for the propagation: radial distance/c (default: false)" , - _correctTimesForPropagation , - bool(false) ); - - registerProcessorParameter( "UseTimeWindow" , - "Only accept hits with time (after smearing) within the specified time window (default: false)" , - _useTimeWindow , - bool(false) ); - -FloatVec timeWindow_min; - timeWindow_min.push_back( -1e9 ); - registerProcessorParameter( "TimeWindowMin" , - "Minimum time a hit must have after smearing to be accepted [ns] - either one per layer or one for all layers", - _timeWindow_min, - timeWindow_min ); - -FloatVec timeWindow_max; - timeWindow_max.push_back( 1e9 ); - registerProcessorParameter( "TimeWindowMax" , - "Maximum time a hit must have after smearing to be accepted [ns] - either one per layer or one for all layers", - _timeWindow_max, - timeWindow_max ); - - + + registerProcessorParameter("ForceHitsOntoSurface", + "Project hits onto the surface in case they are not yet on the surface (default: false)", + _forceHitsOntoSurface, bool(false)); + + registerProcessorParameter("MinimumEnergyPerHit", "Minimum Energy (in GeV!) to accept hits, other hits are ignored", + _minEnergy, double(0.0)); + + registerProcessorParameter("CorrectTimesForPropagation", + "Correct hit time for the propagation: radial distance/c (default: false)", + _correctTimesForPropagation, bool(false)); + + registerProcessorParameter( + "UseTimeWindow", "Only accept hits with time (after smearing) within the specified time window (default: false)", + _useTimeWindow, bool(false)); + + FloatVec timeWindow_min; + timeWindow_min.push_back(-1e9); + registerProcessorParameter( + "TimeWindowMin", + "Minimum time a hit must have after smearing to be accepted [ns] - either one per layer or one for all layers", + _timeWindow_min, timeWindow_min); + + FloatVec timeWindow_max; + timeWindow_max.push_back(1e9); + registerProcessorParameter( + "TimeWindowMax", + "Maximum time a hit must have after smearing to be accepted [ns] - either one per layer or one for all layers", + _timeWindow_max, timeWindow_max); + // setup the list of supported detectors - - } -enum { - hu = 0, - hv, - hT, - hitE, - hitsAccepted, - diffu, - diffv, - diffT, - hSize -} ; - -void DDPlanarDigiProcessor::init() { - +enum { hu = 0, hv, hT, hitE, hitsAccepted, diffu, diffv, diffT, hSize }; + +void DDPlanarDigiProcessor::init() { + // usually a good idea to - printParameters() ; - - _nRun = 0 ; - _nEvt = 0 ; - + printParameters(); + + _nRun = 0; + _nEvt = 0; + // initialize gsl random generator _rng = gsl_rng_alloc(gsl_rng_ranlxs2); - - _h.resize( hSize ) ; + _h.resize(hSize); Global::EVENTSEEDER->registerProcessor(this); - - if( _resU.size() != _resV.size() ) { - - std::stringstream ss ; - ss << name() << "::init() - Inconsistent number of resolutions given for U and V coordinate: " - << "ResolutionU :" << _resU.size() << " != ResolutionV : " << _resV.size() ; + if (_resU.size() != _resV.size()) { - throw EVENT::Exception( ss.str() ) ; + std::stringstream ss; + ss << name() << "::init() - Inconsistent number of resolutions given for U and V coordinate: " + << "ResolutionU :" << _resU.size() << " != ResolutionV : " << _resV.size(); + + throw EVENT::Exception(ss.str()); } dd4hep::Detector& theDetector = dd4hep::Detector::getInstance(); - //=========== get the surface map from the SurfaceManager ================ - dd4hep::rec::SurfaceManager& surfMan = *theDetector.extension() ; + dd4hep::rec::SurfaceManager& surfMan = *theDetector.extension(); - dd4hep::DetElement det = theDetector.detector( _subDetName ) ; + dd4hep::DetElement det = theDetector.detector(_subDetName); - _map = surfMan.map( det.name() ) ; + _map = surfMan.map(det.name()); - if( ! _map ) { - std::stringstream err ; err << " Could not find surface map for detector: " - << _subDetName << " in SurfaceManager " ; - throw Exception( err.str() ) ; + if (!_map) { + std::stringstream err; + err << " Could not find surface map for detector: " << _subDetName << " in SurfaceManager "; + throw Exception(err.str()); } - streamlog_out( DEBUG3 ) << " DDPlanarDigiProcessor::init(): found " << _map->size() - << " surfaces for detector:" << _subDetName << std::endl ; + streamlog_out(DEBUG3) << " DDPlanarDigiProcessor::init(): found " << _map->size() + << " surfaces for detector:" << _subDetName << std::endl; - streamlog_out( MESSAGE ) << " *** DDPlanarDigiProcessor::init(): creating histograms" << std::endl ; + streamlog_out(MESSAGE) << " *** DDPlanarDigiProcessor::init(): creating histograms" << std::endl; - AIDAProcessor::histogramFactory(this) ; //->createHistogram1D( "hMCPEnergy", "energy of the MCParticles", 100 ) ; + AIDAProcessor::histogramFactory(this); //->createHistogram1D( "hMCPEnergy", "energy of the MCParticles", 100 ) ; - _h[ hu ] = new TH1F( "hu" , "smearing u" , 50, -5. , +5. ); - _h[ hv ] = new TH1F( "hv" , "smearing v" , 50, -5. , +5. ); - _h[ hT ] = new TH1F( "hT" , "smearing time" , 50, -5. , +5. ); + _h[hu] = new TH1F("hu", "smearing u", 50, -5., +5.); + _h[hv] = new TH1F("hv", "smearing v", 50, -5., +5.); + _h[hT] = new TH1F("hT", "smearing time", 50, -5., +5.); - _h[ diffu ] = new TH1F( "diffu" , "diff u" , 1000, -5. , +5. ); - _h[ diffv ] = new TH1F( "diffv" , "diff v" , 1000, -5. , +5. ); - _h[ diffT ] = new TH1F( "diffT" , "diff time" , 1000, -5. , +5. ); + _h[diffu] = new TH1F("diffu", "diff u", 1000, -5., +5.); + _h[diffv] = new TH1F("diffv", "diff v", 1000, -5., +5.); + _h[diffT] = new TH1F("diffT", "diff time", 1000, -5., +5.); - _h[ hitE ] = new TH1F( "hitE" , "hitEnergy in keV" , 1000, 0 , 200 ); - _h[ hitsAccepted ] = new TH1F( "hitsAccepted" , "Fraction of accepted hits [%]" , 201, 0 , 100.5 ); - + _h[hitE] = new TH1F("hitE", "hitEnergy in keV", 1000, 0, 200); + _h[hitsAccepted] = new TH1F("hitsAccepted", "Fraction of accepted hits [%]", 201, 0, 100.5); } +void DDPlanarDigiProcessor::processRunHeader(LCRunHeader*) { ++_nRun; } -void DDPlanarDigiProcessor::processRunHeader( LCRunHeader* ) { - ++_nRun ; -} - -void DDPlanarDigiProcessor::processEvent( LCEvent * evt ) { - - gsl_rng_set( _rng, Global::EVENTSEEDER->getSeed(this) ) ; - streamlog_out( DEBUG4 ) << "seed set to " << Global::EVENTSEEDER->getSeed(this) << std::endl; - +void DDPlanarDigiProcessor::processEvent(LCEvent* evt) { + gsl_rng_set(_rng, Global::EVENTSEEDER->getSeed(this)); + streamlog_out(DEBUG4) << "seed set to " << Global::EVENTSEEDER->getSeed(this) << std::endl; - - LCCollection* STHcol = 0 ; - try{ - STHcol = evt->getCollection( _inColName ) ; - } - catch(DataNotAvailableException &e){ + LCCollection* STHcol = 0; + try { + STHcol = evt->getCollection(_inColName); + } catch (DataNotAvailableException& e) { streamlog_out(DEBUG4) << "Collection " << _inColName.c_str() << " is unavailable in event " << _nEvt << std::endl; } - - if( STHcol != 0 ){ - + if (STHcol != 0) { + + unsigned nCreatedHits = 0; + unsigned nDismissedHits = 0; - unsigned nCreatedHits=0; - unsigned nDismissedHits=0; - - LCCollectionVec* trkhitVec = new LCCollectionVec( LCIO::TRACKERHITPLANE ) ; - - CellIDEncoder cellid_encoder( lcio::LCTrackerCellID::encoding_string() , trkhitVec ) ; + LCCollectionVec* trkhitVec = new LCCollectionVec(LCIO::TRACKERHITPLANE); + + CellIDEncoder cellid_encoder(lcio::LCTrackerCellID::encoding_string(), trkhitVec); // Relation collection TrackerHit, SimTrackerHit - LCCollection* thsthcol = 0; - UTIL::LCRelationNavigator thitNav = UTIL::LCRelationNavigator( LCIO::TRACKERHITPLANE, LCIO::SIMTRACKERHIT ); + LCCollection* thsthcol = 0; + UTIL::LCRelationNavigator thitNav = UTIL::LCRelationNavigator(LCIO::TRACKERHITPLANE, LCIO::SIMTRACKERHIT); + + CellIDDecoder cellid_decoder(STHcol); - CellIDDecoder cellid_decoder( STHcol) ; + int nSimHits = STHcol->getNumberOfElements(); - - int nSimHits = STHcol->getNumberOfElements() ; - - streamlog_out( DEBUG4 ) << " processing collection " << _inColName << " with " << nSimHits << " hits ... " << std::endl ; - - for(int i=0; i< nSimHits; ++i){ - + streamlog_out(DEBUG4) << " processing collection " << _inColName << " with " << nSimHits << " hits ... " + << std::endl; + for (int i = 0; i < nSimHits; ++i) { - SimTrackerHit* simTHit = dynamic_cast( STHcol->getElementAt( i ) ) ; + SimTrackerHit* simTHit = dynamic_cast(STHcol->getElementAt(i)); - _h[hitE]->Fill( simTHit->getEDep() * (dd4hep::GeV / dd4hep::keV) ); + _h[hitE]->Fill(simTHit->getEDep() * (dd4hep::GeV / dd4hep::keV)); - if( simTHit->getEDep() < _minEnergy ) { - streamlog_out( DEBUG ) << "Hit with insufficient energy " << simTHit->getEDep() * (dd4hep::GeV / dd4hep::keV) << " keV" << std::endl; + if (simTHit->getEDep() < _minEnergy) { + streamlog_out(DEBUG) << "Hit with insufficient energy " << simTHit->getEDep() * (dd4hep::GeV / dd4hep::keV) + << " keV" << std::endl; continue; } - - const int cellID0 = simTHit->getCellID0() ; - + + const int cellID0 = simTHit->getCellID0(); + //*********************************************************** // get the measurement surface for this hit using the CellID //*********************************************************** - - dd4hep::rec::SurfaceMap::const_iterator sI = _map->find( cellID0 ) ; - if( sI == _map->end() ){ + dd4hep::rec::SurfaceMap::const_iterator sI = _map->find(cellID0); - std::cout<< " DDPlanarDigiProcessor::processEvent(): no surface found for cellID : " - << cellid_decoder( simTHit ).valueString() <end()) { - - std::stringstream err ; err << " DDPlanarDigiProcessor::processEvent(): no surface found for cellID : " - << cellid_decoder( simTHit ).valueString() ; - throw Exception ( err.str() ) ; + std::cout << " DDPlanarDigiProcessor::processEvent(): no surface found for cellID : " + << cellid_decoder(simTHit).valueString() << std::endl; + + std::stringstream err; + err << " DDPlanarDigiProcessor::processEvent(): no surface found for cellID : " + << cellid_decoder(simTHit).valueString(); + throw Exception(err.str()); } + const dd4hep::rec::ISurface* surf = sI->second; + + int layer = cellid_decoder(simTHit)["layer"]; + + dd4hep::rec::Vector3D oldPos(simTHit->getPosition()[0], simTHit->getPosition()[1], simTHit->getPosition()[2]); + dd4hep::rec::Vector3D newPos; - const dd4hep::rec::ISurface* surf = sI->second ; + //************************************************************ + // Check if Hit is inside sensitive + //************************************************************ + if (!surf->insideBounds(dd4hep::mm * oldPos)) { - int layer = cellid_decoder( simTHit )["layer"]; + streamlog_out(DEBUG3) << " hit at " << oldPos << " " << cellid_decoder(simTHit).valueString() + << " is not on surface " << *surf << " distance: " << surf->distance(dd4hep::mm * oldPos) + << std::endl; + if (_forceHitsOntoSurface) { + dd4hep::rec::Vector2D lv = surf->globalToLocal(dd4hep::mm * oldPos); - dd4hep::rec::Vector3D oldPos( simTHit->getPosition()[0], simTHit->getPosition()[1], simTHit->getPosition()[2] ); - - dd4hep::rec::Vector3D newPos ; + dd4hep::rec::Vector3D oldPosOnSurf = (1. / dd4hep::mm) * surf->localToGlobal(lv); - //************************************************************ - // Check if Hit is inside sensitive - //************************************************************ - - if ( ! surf->insideBounds( dd4hep::mm * oldPos ) ) { - - streamlog_out( DEBUG3 ) << " hit at " << oldPos - << " " << cellid_decoder( simTHit).valueString() - << " is not on surface " - << *surf - << " distance: " << surf->distance( dd4hep::mm * oldPos ) - << std::endl; - - - - - if( _forceHitsOntoSurface ){ - - dd4hep::rec::Vector2D lv = surf->globalToLocal( dd4hep::mm * oldPos ) ; - - dd4hep::rec::Vector3D oldPosOnSurf = (1./dd4hep::mm) * surf->localToGlobal( lv ) ; - - streamlog_out( DEBUG3 ) << " moved to " << oldPosOnSurf << " distance " << (oldPosOnSurf-oldPos).r() - << std::endl; - - oldPos = oldPosOnSurf ; + streamlog_out(DEBUG3) << " moved to " << oldPosOnSurf << " distance " << (oldPosOnSurf - oldPos).r() + << std::endl; + + oldPos = oldPosOnSurf; } else { ++nDismissedHits; - - continue; + + continue; } } //*************************************************************** // Smear time of the hit and apply the time window cut if needed //*************************************************************** - + double hitT = simTHit->getTime(); - + // Smearing time of the hit if (_resT.size() and _resT[0] > 0.0) { float resT = _resT.size() > 1 ? _resT.at(layer) : _resT.at(0); - double tSmear = resT > 0.0 ? gsl_ran_gaussian( _rng, resT ) : 0.0; - _h[hT]->Fill( resT > 0.0 ? tSmear / resT : 0.0 ); - _h[diffT]->Fill( tSmear ); + double tSmear = resT > 0.0 ? gsl_ran_gaussian(_rng, resT) : 0.0; + _h[hT]->Fill(resT > 0.0 ? tSmear / resT : 0.0); + _h[diffT]->Fill(tSmear); hitT += tSmear; - streamlog_out(DEBUG3) << "smeared hit at T: " << simTHit->getTime() << " ns to T: " << hitT << " ns according to resolution: " << resT << " ns" << std::endl; + streamlog_out(DEBUG3) << "smeared hit at T: " << simTHit->getTime() << " ns to T: " << hitT + << " ns according to resolution: " << resT << " ns" << std::endl; } - + // Correcting for the propagation time if (_correctTimesForPropagation) { - double dt = oldPos.r() / ( TMath::C() / 1e6 ); + double dt = oldPos.r() / (TMath::C() / 1e6); hitT -= dt; - streamlog_out(DEBUG3) << "corrected hit at R: " << oldPos.r() << " mm by propagation time: " << dt << " ns to T: " << hitT << " ns" << std::endl; + streamlog_out(DEBUG3) << "corrected hit at R: " << oldPos.r() << " mm by propagation time: " << dt + << " ns to T: " << hitT << " ns" << std::endl; } - + // Skipping the hit if its time is outside the acceptance time window if (_useTimeWindow) { float timeWindow_min = _timeWindow_min.size() > 1 ? _timeWindow_min.at(layer) : _timeWindow_min.at(0); float timeWindow_max = _timeWindow_max.size() > 1 ? _timeWindow_max.at(layer) : _timeWindow_max.at(0); - if ( hitT < timeWindow_min || hitT > timeWindow_max ) { - streamlog_out(DEBUG4) << "hit at T: " << simTHit->getTime() << " smeared to: " << hitT << " is outside the time window: hit dropped" << std::endl; + if (hitT < timeWindow_min || hitT > timeWindow_max) { + streamlog_out(DEBUG4) << "hit at T: " << simTHit->getTime() << " smeared to: " << hitT + << " is outside the time window: hit dropped" << std::endl; ++nDismissedHits; continue; } } - //********************************************************************************* // Try to smear the hit position but ensure the hit is inside the sensitive region //********************************************************************************* - - dd4hep::rec::Vector3D u = surf->u() ; - dd4hep::rec::Vector3D v = surf->v() ; - + + dd4hep::rec::Vector3D u = surf->u(); + dd4hep::rec::Vector3D v = surf->v(); // get local coordinates on surface - dd4hep::rec::Vector2D lv = surf->globalToLocal( dd4hep::mm * oldPos ) ; - double uL = lv[0] / dd4hep::mm ; - double vL = lv[1] / dd4hep::mm ; - - bool accept_hit = false ; - unsigned tries = 0 ; - static const unsigned MaxTries = 10 ; - - float resU = ( _resU.size() > 1 ? _resU.at( layer ) : _resU.at(0) ) ; - float resV = ( _resV.size() > 1 ? _resV.at( layer ) : _resV.at(0) ) ; - - - while( tries < MaxTries ) { - - if( tries > 0 ) streamlog_out(DEBUG0) << "retry smearing for " << cellid_decoder( simTHit ).valueString() << " : retries " << tries << std::endl; - - double uSmear = gsl_ran_gaussian( _rng, resU ) ; - double vSmear = gsl_ran_gaussian( _rng, resV ) ; - - - // dd4hep::rec::Vector3D newPosTmp = oldPos + uSmear * u ; - // if( ! _isStrip ) newPosTmp = newPosTmp + vSmear * v ; - + dd4hep::rec::Vector2D lv = surf->globalToLocal(dd4hep::mm * oldPos); + double uL = lv[0] / dd4hep::mm; + double vL = lv[1] / dd4hep::mm; + + bool accept_hit = false; + unsigned tries = 0; + static const unsigned MaxTries = 10; + + float resU = (_resU.size() > 1 ? _resU.at(layer) : _resU.at(0)); + float resV = (_resV.size() > 1 ? _resV.at(layer) : _resV.at(0)); + + while (tries < MaxTries) { + + if (tries > 0) + streamlog_out(DEBUG0) << "retry smearing for " << cellid_decoder(simTHit).valueString() << " : retries " + << tries << std::endl; + + double uSmear = gsl_ran_gaussian(_rng, resU); + double vSmear = gsl_ran_gaussian(_rng, resV); + + // dd4hep::rec::Vector3D newPosTmp = oldPos + uSmear * u ; + // if( ! _isStrip ) newPosTmp = newPosTmp + vSmear * v ; + dd4hep::rec::Vector3D newPosTmp; - if (_isStrip){ - if (_subDetName == "SET"){ - double xStripPos, yStripPos, zStripPos; - //Find intersection of the strip with the z=centerOfSensor plane to set it as the center of the SET strip - dd4hep::rec::Vector3D simHitPosSmeared = (1./dd4hep::mm) * ( surf->localToGlobal( dd4hep::rec::Vector2D( (uL+uSmear)*dd4hep::mm, 0.) ) ); - zStripPos = surf->origin()[2] / dd4hep::mm ; - double lineParam = (zStripPos - simHitPosSmeared[2])/v[2]; - xStripPos = simHitPosSmeared[0] + lineParam*v[0]; - yStripPos = simHitPosSmeared[1] + lineParam*v[1]; - newPosTmp = dd4hep::rec::Vector3D(xStripPos, yStripPos, zStripPos); - } - else{ - newPosTmp = (1./dd4hep::mm) * ( surf->localToGlobal( dd4hep::rec::Vector2D( (uL+uSmear)*dd4hep::mm, 0. ) ) ); - } - } - else{ - newPosTmp = (1./dd4hep::mm) * ( surf->localToGlobal( dd4hep::rec::Vector2D( (uL+uSmear)*dd4hep::mm, (vL+vSmear)*dd4hep::mm ) ) ); + if (_isStrip) { + if (_subDetName == "SET") { + double xStripPos, yStripPos, zStripPos; + // Find intersection of the strip with the z=centerOfSensor plane to set it as the center of the SET strip + dd4hep::rec::Vector3D simHitPosSmeared = + (1. / dd4hep::mm) * (surf->localToGlobal(dd4hep::rec::Vector2D((uL + uSmear) * dd4hep::mm, 0.))); + zStripPos = surf->origin()[2] / dd4hep::mm; + double lineParam = (zStripPos - simHitPosSmeared[2]) / v[2]; + xStripPos = simHitPosSmeared[0] + lineParam * v[0]; + yStripPos = simHitPosSmeared[1] + lineParam * v[1]; + newPosTmp = dd4hep::rec::Vector3D(xStripPos, yStripPos, zStripPos); + } else { + newPosTmp = + (1. / dd4hep::mm) * (surf->localToGlobal(dd4hep::rec::Vector2D((uL + uSmear) * dd4hep::mm, 0.))); + } + } else { + newPosTmp = + (1. / dd4hep::mm) * + (surf->localToGlobal(dd4hep::rec::Vector2D((uL + uSmear) * dd4hep::mm, (vL + vSmear) * dd4hep::mm))); } - streamlog_out( DEBUG1 ) << " hit at : " << oldPos - << " smeared to: " << newPosTmp - << " uL: " << uL - << " vL: " << vL - << " uSmear: " << uSmear - << " vSmear: " << vSmear - << std::endl ; + streamlog_out(DEBUG1) << " hit at : " << oldPos << " smeared to: " << newPosTmp << " uL: " << uL + << " vL: " << vL << " uSmear: " << uSmear << " vSmear: " << vSmear << std::endl; + if (surf->insideBounds(dd4hep::mm * newPosTmp)) { - if ( surf->insideBounds( dd4hep::mm * newPosTmp ) ) { - - accept_hit = true ; - newPos = newPosTmp ; + accept_hit = true; + newPos = newPosTmp; - _h[hu]->Fill( uSmear / resU ) ; - _h[hv]->Fill( vSmear / resV ) ; + _h[hu]->Fill(uSmear / resU); + _h[hv]->Fill(vSmear / resV); - _h[diffu]->Fill( uSmear ); - _h[diffv]->Fill( vSmear ); + _h[diffu]->Fill(uSmear); + _h[diffv]->Fill(vSmear); - break; + break; - } else { - - streamlog_out( DEBUG1 ) << " hit at " << newPosTmp - << " " << cellid_decoder( simTHit).valueString() - << " is not on surface " - << " distance: " << surf->distance( dd4hep::mm * newPosTmp ) - << std::endl; + } else { + + streamlog_out(DEBUG1) << " hit at " << newPosTmp << " " << cellid_decoder(simTHit).valueString() + << " is not on surface " + << " distance: " << surf->distance(dd4hep::mm * newPosTmp) << std::endl; } - + ++tries; } - - if( accept_hit == false ) { - streamlog_out(DEBUG4) << "hit could not be smeared within ladder after " << MaxTries << " tries: hit dropped" << std::endl; + + if (accept_hit == false) { + streamlog_out(DEBUG4) << "hit could not be smeared within ladder after " << MaxTries << " tries: hit dropped" + << std::endl; ++nDismissedHits; - continue; - } - + continue; + } + //************************************************************************** // Store hit variables to TrackerHitPlaneImpl //************************************************************************** - - - TrackerHitPlaneImpl* trkHit = new TrackerHitPlaneImpl ; - - const int cellID1 = simTHit->getCellID1() ; - trkHit->setCellID0( cellID0 ) ; - trkHit->setCellID1( cellID1 ) ; - - trkHit->setPosition( newPos.const_array() ) ; - trkHit->setTime( hitT ) ; - trkHit->setEDep( simTHit->getEDep() ) ; - - float u_direction[2] ; + + TrackerHitPlaneImpl* trkHit = new TrackerHitPlaneImpl; + + const int cellID1 = simTHit->getCellID1(); + trkHit->setCellID0(cellID0); + trkHit->setCellID1(cellID1); + + trkHit->setPosition(newPos.const_array()); + trkHit->setTime(hitT); + trkHit->setEDep(simTHit->getEDep()); + + float u_direction[2]; u_direction[0] = u.theta(); u_direction[1] = u.phi(); - - float v_direction[2] ; + + float v_direction[2]; v_direction[0] = v.theta(); v_direction[1] = v.phi(); - - streamlog_out(DEBUG0) << " U[0] = "<< u_direction[0] << " U[1] = "<< u_direction[1] - << " V[0] = "<< v_direction[0] << " V[1] = "<< v_direction[1] - << std::endl ; - trkHit->setU( u_direction ) ; - trkHit->setV( v_direction ) ; - - trkHit->setdU( resU ) ; + streamlog_out(DEBUG0) << " U[0] = " << u_direction[0] << " U[1] = " << u_direction[1] + << " V[0] = " << v_direction[0] << " V[1] = " << v_direction[1] << std::endl; + + trkHit->setU(u_direction); + trkHit->setV(v_direction); + + trkHit->setdU(resU); - if( _isStrip ) { + if (_isStrip) { // store the resolution from the length of the wafer - in case a fitter might want to treat this as 2d hit .... - double stripRes = (surf->length_along_v() / dd4hep::mm ) / std::sqrt( 12. ) ; - trkHit->setdV( stripRes ); + double stripRes = (surf->length_along_v() / dd4hep::mm) / std::sqrt(12.); + trkHit->setdV(stripRes); } else { - trkHit->setdV( resV ) ; + trkHit->setdV(resV); } - if( _isStrip ){ - trkHit->setType( UTIL::set_bit( trkHit->getType() , UTIL::ILDTrkHitTypeBit::ONE_DIMENSIONAL ) ) ; + if (_isStrip) { + trkHit->setType(UTIL::set_bit(trkHit->getType(), UTIL::ILDTrkHitTypeBit::ONE_DIMENSIONAL)); } //************************************************************************** // Set Relation to SimTrackerHit - //************************************************************************** + //************************************************************************** // Set relation with LCRelationNavigator thitNav.addRelation(trkHit, simTHit); - + //************************************************************************** // Add hit to collection - //************************************************************************** - - trkhitVec->addElement( trkHit ) ; - + //************************************************************************** + + trkhitVec->addElement(trkHit); + ++nCreatedHits; - + streamlog_out(DEBUG3) << "-------------------------------------------------------" << std::endl; - - } + } // Create relation collection thsthcol = thitNav.createLCCollection(); - + // Filling the fraction of accepted hits in the event float accFraction = nSimHits > 0 ? float(nCreatedHits) / float(nSimHits) * 100.0 : 0.0; - _h[hitsAccepted]->Fill( accFraction ); - + _h[hitsAccepted]->Fill(accFraction); + //************************************************************************** // Add collection to event - //************************************************************************** - - evt->addCollection( trkhitVec , _outColName ) ; - evt->addCollection( thsthcol , _outRelColName ) ; - + //************************************************************************** + + evt->addCollection(trkhitVec, _outColName); + evt->addCollection(thsthcol, _outRelColName); + streamlog_out(DEBUG4) << "Created " << nCreatedHits << " hits, " << nDismissedHits << " hits dismissed\n"; - } - _nEvt ++ ; + _nEvt++; } - - -void DDPlanarDigiProcessor::check( LCEvent* ) { +void DDPlanarDigiProcessor::check(LCEvent*) { // nothing to check here - could be used to fill checkplots in reconstruction processor } +void DDPlanarDigiProcessor::end() { -void DDPlanarDigiProcessor::end(){ + gsl_rng_free(_rng); - gsl_rng_free( _rng ); - - streamlog_out(MESSAGE) << " end() " << name() - << " processed " << _nEvt << " events in " << _nRun << " runs " - << std::endl ; - + streamlog_out(MESSAGE) << " end() " << name() << " processed " << _nEvt << " events in " << _nRun << " runs " + << std::endl; } diff --git a/source/Digitisers/src/DDSpacePointBuilder.cc b/source/Digitisers/src/DDSpacePointBuilder.cc index 5bcb3b9..62a0cdc 100644 --- a/source/Digitisers/src/DDSpacePointBuilder.cc +++ b/source/Digitisers/src/DDSpacePointBuilder.cc @@ -1,406 +1,356 @@ #include "DDSpacePointBuilder.h" -#include "EVENT/TrackerHit.h" -#include "EVENT/TrackerHitPlane.h" #include "EVENT/LCCollection.h" #include "EVENT/SimTrackerHit.h" +#include "EVENT/TrackerHit.h" +#include "EVENT/TrackerHitPlane.h" #include "IMPL/LCCollectionVec.h" -#include "IMPL/TrackerHitImpl.h" -#include "IMPL/TrackerHitPlaneImpl.h" #include "IMPL/LCFlagImpl.h" #include "IMPL/LCRelationImpl.h" +#include "IMPL/TrackerHitImpl.h" +#include "IMPL/TrackerHitPlaneImpl.h" #include "UTIL/LCRelationNavigator.h" - -#include "marlin/VerbosityLevels.h" -#include "marlin/Global.h" #include "UTIL/LCTrackerConf.h" +#include "marlin/Global.h" +#include "marlin/VerbosityLevels.h" #include #include "DDRec/DetectorData.h" -//FIXME:SJA: if we want the surface store to be filled we need to create an instance of MarlinTrk implemented with KalTest/KalDet +// FIXME:SJA: if we want the surface store to be filled we need to create an instance of MarlinTrk implemented with +// KalTest/KalDet #include "MarlinTrk/Factory.h" -#include "CLHEP/Matrix/SymMatrix.h" #include "CLHEP/Matrix/Matrix.h" +#include "CLHEP/Matrix/SymMatrix.h" #include #include -using namespace lcio ; -using namespace marlin ; - -DDSpacePointBuilder aDDSpacePointBuilder ; +using namespace lcio; +using namespace marlin; +DDSpacePointBuilder aDDSpacePointBuilder; DDSpacePointBuilder::DDSpacePointBuilder() : Processor("DDSpacePointBuilder") { - // modify processor description - _description = "DDSpacePointBuilder combine si-strip measurements into 3D spacepoints (1TrackerHitPlanar+1TrackHitPlanar = 1 TrackerHit), that can be used by reconstruction" ; - - - // register steering parameters: name, description, class-variable, default value - registerInputCollection(LCIO::TRACKERHIT, - "TrackerHitCollection", - "TrackerHitCollection", - _TrackerHitCollection, - std::string("FTDTrackerHits")); - - registerInputCollection(LCIO::LCRELATION, - "TrackerHitSimHitRelCollection", - "The name of the input collection of the relations of the TrackerHits to SimHits", - _TrackerHitSimHitRelCollection, - std::string("FTDTrackerHitRelations")); - - registerOutputCollection(LCIO::TRACKERHIT, - "SpacePointsCollection", - "SpacePointsCollection", - _SpacePointsCollection, - std::string("FTDSpacePoints")); - - registerOutputCollection(LCIO::LCRELATION, - "SimHitSpacePointRelCollection", - "Name of the SpacePoint SimTrackerHit relation collection", - _relColName, - std::string("FTDSimHitSpacepointRelations")); - - + // modify processor description + _description = "DDSpacePointBuilder combine si-strip measurements into 3D spacepoints " + "(1TrackerHitPlanar+1TrackHitPlanar = 1 TrackerHit), that can be used by reconstruction"; + + // register steering parameters: name, description, class-variable, default value + registerInputCollection(LCIO::TRACKERHIT, "TrackerHitCollection", "TrackerHitCollection", _TrackerHitCollection, + std::string("FTDTrackerHits")); + + registerInputCollection(LCIO::LCRELATION, "TrackerHitSimHitRelCollection", + "The name of the input collection of the relations of the TrackerHits to SimHits", + _TrackerHitSimHitRelCollection, std::string("FTDTrackerHitRelations")); + + registerOutputCollection(LCIO::TRACKERHIT, "SpacePointsCollection", "SpacePointsCollection", _SpacePointsCollection, + std::string("FTDSpacePoints")); + + registerOutputCollection(LCIO::LCRELATION, "SimHitSpacePointRelCollection", + "Name of the SpacePoint SimTrackerHit relation collection", _relColName, + std::string("FTDSimHitSpacepointRelations")); + // YV added - registerProcessorParameter("StripLength", - "The length of the strips of the subdetector in mm", - _striplength, + registerProcessorParameter("StripLength", "The length of the strips of the subdetector in mm", _striplength, double(0.0)); - registerProcessorParameter("StriplengthTolerance", "Tolerance added to the strip length when calculating strip hit intersections", - _striplength_tolerance, - float(0.1)); - + _striplength_tolerance, float(0.1)); - registerProcessorParameter( "SubDetectorName" , - "Name of dub detector" , - _subDetName , - std::string("SIT") ); - + registerProcessorParameter("SubDetectorName", "Name of dub detector", _subDetName, std::string("SIT")); } +void DDSpacePointBuilder::init() { + streamlog_out(DEBUG) << " init called " << std::endl; + // usually a good idea to + printParameters(); -void DDSpacePointBuilder::init() { + _nRun = 0; + _nEvt = 0; - streamlog_out(DEBUG) << " init called " << std::endl ; + MarlinTrk::IMarlinTrkSystem* trksystem = MarlinTrk::Factory::createMarlinTrkSystem("DDKalTest", 0, ""); - // usually a good idea to - printParameters() ; - - _nRun = 0 ; - _nEvt = 0 ; - - MarlinTrk::IMarlinTrkSystem* trksystem = MarlinTrk::Factory::createMarlinTrkSystem( "DDKalTest" , 0, "" ) ; - - - if( trksystem == 0 ) { - - throw EVENT::Exception( std::string(" Cannot initialize MarlinTrkSystem of Type: ") + std::string("DDKalTest" ) ) ; - + if (trksystem == 0) { + + throw EVENT::Exception(std::string(" Cannot initialize MarlinTrkSystem of Type: ") + std::string("DDKalTest")); } - - trksystem->init() ; + + trksystem->init(); dd4hep::Detector& theDetector = dd4hep::Detector::getInstance(); - //theDetector = dd4hep::Detector::getInstance(); - + // theDetector = dd4hep::Detector::getInstance(); + //=========== get the surface map from the SurfaceManager ================ - - dd4hep::rec::SurfaceManager& surfMan = *theDetector.extension() ; - dd4hep::DetElement det = theDetector.detector( _subDetName ) ; - //const dd4hep::rec::SurfaceMap *surfMap ; - surfMap = surfMan.map( det.name() ) ; - - + + dd4hep::rec::SurfaceManager& surfMan = *theDetector.extension(); + dd4hep::DetElement det = theDetector.detector(_subDetName); + // const dd4hep::rec::SurfaceMap *surfMap ; + surfMap = surfMan.map(det.name()); + /* // alternative way to create a map of instances const dd4hep::rec::IGeometry& geom = dd4hep::rec::IGeometry::instance() ; const std::vector& surfaces = geom.getSurfaces() ; // create map of surfaces std::map< long, const dd4hep::rec::ISurface* > surfMap ; - for(std::vector::const_iterator surf = surfaces.begin() ; surf != surfaces.end() ; ++surf){ - surfMap[(*surf)->id() ] = (*surf) ; + for(std::vector::const_iterator surf = surfaces.begin() ; surf != surfaces.end() ; + ++surf){ surfMap[(*surf)->id() ] = (*surf) ; } */ - - - } +void DDSpacePointBuilder::processRunHeader(LCRunHeader*) { _nRun++; } -void DDSpacePointBuilder::processRunHeader( LCRunHeader* ) { - - _nRun++ ; -} - +void DDSpacePointBuilder::processEvent(LCEvent* evt) { + LCCollection* col = 0; + LCRelationNavigator* nav = 0; -void DDSpacePointBuilder::processEvent( LCEvent * evt ) { - - LCCollection* col = 0 ; - LCRelationNavigator* nav = 0 ; - - try{ - col = evt->getCollection( _TrackerHitCollection ) ; - } - catch(DataNotAvailableException &e){ - streamlog_out(DEBUG4) << "Collection " << _TrackerHitCollection.c_str() << " is unavailable in event " << _nEvt << std::endl; + try { + col = evt->getCollection(_TrackerHitCollection); + } catch (DataNotAvailableException& e) { + streamlog_out(DEBUG4) << "Collection " << _TrackerHitCollection.c_str() << " is unavailable in event " << _nEvt + << std::endl; } - try{ - nav = new LCRelationNavigator(evt->getCollection( _TrackerHitSimHitRelCollection )); - } - catch(DataNotAvailableException &e){ - streamlog_out(DEBUG4) << "Collection " << _TrackerHitSimHitRelCollection.c_str() << " is unavailable in event " << _nEvt << std::endl; + try { + nav = new LCRelationNavigator(evt->getCollection(_TrackerHitSimHitRelCollection)); + } catch (DataNotAvailableException& e) { + streamlog_out(DEBUG4) << "Collection " << _TrackerHitSimHitRelCollection.c_str() << " is unavailable in event " + << _nEvt << std::endl; } - - if( col != NULL && nav != NULL ){ - - + if (col != NULL && nav != NULL) { + unsigned createdSpacePoints = 0; unsigned rawStripHits = 0; unsigned possibleSpacePoints = 0; _nOutOfBoundary = 0; _nStripsTooParallel = 0; _nPlanesNotParallel = 0; - - - LCCollectionVec * spCol = new LCCollectionVec(LCIO::TRACKERHIT); // output spacepoint collection + + LCCollectionVec* spCol = new LCCollectionVec(LCIO::TRACKERHIT); // output spacepoint collection // Relation navigator for creating SpacePoint - SimTrackerHit relations auto spSimHitNav = UTIL::LCRelationNavigator(LCIO::TRACKERHIT, LCIO::SIMTRACKERHIT); - unsigned nHits = col->getNumberOfElements() ; - - streamlog_out(DEBUG3) << "Number of hits: " << nHits <<"\n"; - - //store hits in map according to their CellID0 - std::map< int , std::vector< TrackerHitPlane* > > map_cellID0_hits; - std::map< int , std::vector< TrackerHitPlane* > >::iterator it; - - for( unsigned i=0; i( col->getElementAt( i ) ); - - if( trkHit != NULL) { - streamlog_out(DEBUG3) << "Add hit with CellID0 = " << trkHit->getCellID0() << " " << getCellID0Info( trkHit->getCellID0() ) << "\n"; - map_cellID0_hits[ trkHit->getCellID0() ].push_back( trkHit ); + unsigned nHits = col->getNumberOfElements(); + + streamlog_out(DEBUG3) << "Number of hits: " << nHits << "\n"; + + // store hits in map according to their CellID0 + std::map> map_cellID0_hits; + std::map>::iterator it; + + for (unsigned i = 0; i < nHits; i++) { + + TrackerHitPlane* trkHit = dynamic_cast(col->getElementAt(i)); + + if (trkHit != NULL) { + streamlog_out(DEBUG3) << "Add hit with CellID0 = " << trkHit->getCellID0() << " " + << getCellID0Info(trkHit->getCellID0()) << "\n"; + map_cellID0_hits[trkHit->getCellID0()].push_back(trkHit); } } - UTIL::BitField64 cellID( LCTrackerCellID::encoding_string() ); - + UTIL::BitField64 cellID(LCTrackerCellID::encoding_string()); + // now loop over all CellID0s - for( it= map_cellID0_hits.begin(); it!= map_cellID0_hits.end(); it++ ){ - - + for (it = map_cellID0_hits.begin(); it != map_cellID0_hits.end(); it++) { + rawStripHits += it->second.size(); - - std::vector< TrackerHitPlane* > hitsFront = it->second; - + + std::vector hitsFront = it->second; + int cellID0 = it->first; - - //get the CellID0s at the back of this sensor - std::vector< int > cellID0sBack = getCellID0sAtBack( cellID0 ); - for( unsigned i=0; i< cellID0sBack.size(); i++ ){ - - + // get the CellID0s at the back of this sensor + std::vector cellID0sBack = getCellID0sAtBack(cellID0); + + for (unsigned i = 0; i < cellID0sBack.size(); i++) { + int cellID0Back = cellID0sBack[i]; - std::vector< TrackerHitPlane* > hitsBack = map_cellID0_hits[ cellID0Back ]; - - streamlog_out(DEBUG3) << "strips: CellID0 " << cellID0 << " " << getCellID0Info( cellID0 ) << "(" << hitsFront.size() - << " hits) <---> CellID0 " << cellID0Back << getCellID0Info( cellID0Back ) - << "(" << hitsBack.size() << " hits)\n" - << "--> " << hitsFront.size() * hitsBack.size() << " possible combinations\n"; - + std::vector hitsBack = map_cellID0_hits[cellID0Back]; + + streamlog_out(DEBUG3) << "strips: CellID0 " << cellID0 << " " << getCellID0Info(cellID0) << "(" + << hitsFront.size() << " hits) <---> CellID0 " << cellID0Back + << getCellID0Info(cellID0Back) << "(" << hitsBack.size() << " hits)\n" + << "--> " << hitsFront.size() * hitsBack.size() << " possible combinations\n"; + possibleSpacePoints += hitsFront.size() * hitsBack.size(); - - + // Now iterate over all combinations and store those that make sense - for( unsigned ifront=0; ifrontgetRelatedToObjects( hitFront ); - const LCObjectVec& simHitsBack = nav->getRelatedToObjects( hitBack ); + const LCObjectVec& simHitsFront = nav->getRelatedToObjects(hitFront); + const LCObjectVec& simHitsBack = nav->getRelatedToObjects(hitBack); streamlog_out(DEBUG3) << "attempt to create space point from:" << std::endl; - streamlog_out(DEBUG3) << " front hit: " << hitFront << " no. of simhit = " << simHitsFront.size() ; - if( simHitsFront.empty() == false ) { + streamlog_out(DEBUG3) << " front hit: " << hitFront << " no. of simhit = " << simHitsFront.size(); + if (simHitsFront.empty() == false) { SimTrackerHit* simhit = static_cast(simHitsFront.at(0)); - streamlog_out(DEBUG3) << " first simhit = " << simhit << " mcp = "<< simhit->getMCParticle() << " ( " << simhit->getPosition()[0] << " " << simhit->getPosition()[1] << " " << simhit->getPosition()[2] << " ) " ; + streamlog_out(DEBUG3) << " first simhit = " << simhit << " mcp = " << simhit->getMCParticle() << " ( " + << simhit->getPosition()[0] << " " << simhit->getPosition()[1] << " " + << simhit->getPosition()[2] << " ) "; } - streamlog_out(DEBUG3) << std::endl; - streamlog_out(DEBUG3) << " rear hit: " << hitBack << " no. of simhit = " << simHitsBack.size() ; - if( simHitsBack.empty() == false ) { + streamlog_out(DEBUG3) << std::endl; + streamlog_out(DEBUG3) << " rear hit: " << hitBack << " no. of simhit = " << simHitsBack.size(); + if (simHitsBack.empty() == false) { SimTrackerHit* simhit = static_cast(simHitsBack.at(0)); - streamlog_out(DEBUG3) << " first simhit = " << simhit << " mcp = "<< simhit->getMCParticle() << " ( " << simhit->getPosition()[0] << " " << simhit->getPosition()[1] << " " << simhit->getPosition()[2] << " ) " ; - } + streamlog_out(DEBUG3) << " first simhit = " << simhit << " mcp = " << simhit->getMCParticle() << " ( " + << simhit->getPosition()[0] << " " << simhit->getPosition()[1] << " " + << simhit->getPosition()[2] << " ) "; + } streamlog_out(DEBUG3) << std::endl; - + bool ghost_hit = true; - - if (simHitsFront.size()==1 && simHitsBack.size() == 1) { + + if (simHitsFront.size() == 1 && simHitsBack.size() == 1) { streamlog_out(DEBUG3) << "SpacePoint creation from two good hits:" << std::endl; - ghost_hit = static_cast(simHitsFront.at(0))->getMCParticle() != static_cast(simHitsBack.at(0))->getMCParticle(); - + ghost_hit = static_cast(simHitsFront.at(0))->getMCParticle() != + static_cast(simHitsBack.at(0))->getMCParticle(); } - - if ( ghost_hit == true ) { + + if (ghost_hit == true) { streamlog_out(DEBUG3) << "SpacePoint Ghosthit!" << std::endl; } - - cellID.setValue( cellID0 ); - - //int subdet = cellID[ LCTrackerCellID::subdet() ] ; + + cellID.setValue(cellID0); + + // int subdet = cellID[ LCTrackerCellID::subdet() ] ; double strip_length_mm = 0; - strip_length_mm = _striplength ; + strip_length_mm = _striplength; - // add tolerence + // add tolerence strip_length_mm = strip_length_mm * (1.0 + _striplength_tolerance); - - //TrackerHitImpl* spacePoint = createSpacePoint( hitFront, hitBack, strip_length_mm, surfMap); - TrackerHitImpl* spacePoint = createSpacePoint( hitFront, hitBack, strip_length_mm); - if ( spacePoint != NULL ) { + // TrackerHitImpl* spacePoint = createSpacePoint( hitFront, hitBack, strip_length_mm, surfMap); + TrackerHitImpl* spacePoint = createSpacePoint(hitFront, hitBack, strip_length_mm); + + if (spacePoint != NULL) { + + CellIDEncoder cellid_encoder(LCTrackerCellID::encoding_string(), spCol); + cellid_encoder.setValue(cellID0); // give the new hit, the CellID0 of the front hit + cellid_encoder.setCellID(spacePoint); - CellIDEncoder cellid_encoder( LCTrackerCellID::encoding_string() , spCol ); - cellid_encoder.setValue( cellID0 ); //give the new hit, the CellID0 of the front hit - cellid_encoder.setCellID( spacePoint ) ; - // store the hits it's composed of: - spacePoint->rawHits().push_back( hitFront ); - spacePoint->rawHits().push_back( hitBack ); - - spacePoint->setType( UTIL::set_bit( spacePoint->getType() , ILDTrkHitTypeBit::COMPOSITE_SPACEPOINT ) ) ; - - spCol->addElement( spacePoint ) ; - + spacePoint->rawHits().push_back(hitFront); + spacePoint->rawHits().push_back(hitBack); + + spacePoint->setType(UTIL::set_bit(spacePoint->getType(), ILDTrkHitTypeBit::COMPOSITE_SPACEPOINT)); + + spCol->addElement(spacePoint); + createdSpacePoints++; - - + /////////////////////////////// // make the relations - if( simHitsFront.size() == 1 ){ - - SimTrackerHit* simHit = dynamic_cast< SimTrackerHit* >( simHitsFront[0] ); - - if( simHit != NULL ){ + if (simHitsFront.size() == 1) { + + SimTrackerHit* simHit = dynamic_cast(simHitsFront[0]); + + if (simHit != NULL) { spSimHitNav.addRelation(spacePoint, simHit, 0.5); } } - if( simHitsBack.size() == 1 ){ - - SimTrackerHit* simHit = dynamic_cast< SimTrackerHit* >( simHitsBack[0] ); - - if( simHit != NULL ){ + if (simHitsBack.size() == 1) { + + SimTrackerHit* simHit = dynamic_cast(simHitsBack[0]); + + if (simHit != NULL) { spSimHitNav.addRelation(spacePoint, simHit, 0.5); } } } else { - - if ( ghost_hit == true ) { - streamlog_out( DEBUG3 ) << "Ghosthit correctly rejected" << std::endl; + + if (ghost_hit == true) { + streamlog_out(DEBUG3) << "Ghosthit correctly rejected" << std::endl; } else { - streamlog_out( DEBUG3 ) << "True hit rejected!" << std::endl; + streamlog_out(DEBUG3) << "True hit rejected!" << std::endl; } - - ////////////////////////////////// + + ////////////////////////////////// } - } - } - } - } - - evt->addCollection( spCol, _SpacePointsCollection); - auto* relCol = spSimHitNav.createLCCollection(); - evt->addCollection( relCol , _relColName ) ; - - streamlog_out(DEBUG3)<< "\nCreated " << createdSpacePoints - << " space points ( raw strip hits: " << rawStripHits << ")\n"; - - streamlog_out( DEBUG3 ) << " There were " << rawStripHits << " strip hits available, giving " - << possibleSpacePoints << " possible space points\n"; - - streamlog_out( DEBUG3 ) << " " << _nStripsTooParallel << " space points couldn't be created, because the strips were too parallel\n"; - streamlog_out( DEBUG3 ) << " " << _nPlanesNotParallel << " space points couldn't be created, because the planes of the measurement surfaces where not parallel enough\n"; - streamlog_out( DEBUG3 ) << " " << _nOutOfBoundary << " space points couldn't be created, because the result was outside the sensor boundary\n"; - - - streamlog_out(DEBUG3) << "\n"; - - } + evt->addCollection(spCol, _SpacePointsCollection); + auto* relCol = spSimHitNav.createLCCollection(); + evt->addCollection(relCol, _relColName); - _nEvt ++ ; - - delete nav; - -} + streamlog_out(DEBUG3) << "\nCreated " << createdSpacePoints << " space points ( raw strip hits: " << rawStripHits + << ")\n"; + streamlog_out(DEBUG3) << " There were " << rawStripHits << " strip hits available, giving " << possibleSpacePoints + << " possible space points\n"; + streamlog_out(DEBUG3) << " " << _nStripsTooParallel + << " space points couldn't be created, because the strips were too parallel\n"; + streamlog_out(DEBUG3) << " " << _nPlanesNotParallel + << " space points couldn't be created, because the planes of the measurement surfaces where " + "not parallel enough\n"; + streamlog_out(DEBUG3) << " " << _nOutOfBoundary + << " space points couldn't be created, because the result was outside the sensor boundary\n"; + streamlog_out(DEBUG3) << "\n"; + } + _nEvt++; -void DDSpacePointBuilder::check( LCEvent* ) {} + delete nav; +} +void DDSpacePointBuilder::check(LCEvent*) {} -void DDSpacePointBuilder::end(){ - - -} +void DDSpacePointBuilder::end() {} -//TrackerHitImpl* DDSpacePointBuilder::createSpacePoint( TrackerHitPlane* a , TrackerHitPlane* b, double stripLength, const dd4hep::rec::SurfaceMap* surfMap ){ -TrackerHitImpl* DDSpacePointBuilder::createSpacePoint( TrackerHitPlane* a , TrackerHitPlane* b, double stripLength ){ +// TrackerHitImpl* DDSpacePointBuilder::createSpacePoint( TrackerHitPlane* a , TrackerHitPlane* b, double stripLength, +// const dd4hep::rec::SurfaceMap* surfMap ){ +TrackerHitImpl* DDSpacePointBuilder::createSpacePoint(TrackerHitPlane* a, TrackerHitPlane* b, double stripLength) { const double* pa = a->getPosition(); double xa = pa[0]; double ya = pa[1]; double za = pa[2]; - CLHEP::Hep3Vector PA( xa,ya,za ); - dd4hep::rec::Vector3D ddPA( xa * dd4hep::mm, ya * dd4hep::mm, za * dd4hep::mm ); - double du_a = a->getdU(); - - //const dd4hep::rec::ISurface* msA = surfMap[a->getCellID0()]; + CLHEP::Hep3Vector PA(xa, ya, za); + dd4hep::rec::Vector3D ddPA(xa * dd4hep::mm, ya * dd4hep::mm, za * dd4hep::mm); + double du_a = a->getdU(); + + // const dd4hep::rec::ISurface* msA = surfMap[a->getCellID0()]; const dd4hep::rec::ISurface* msA = surfMap->find(a->getCellID0())->second; - streamlog_out (DEBUG2) << " do i find a surface " << *msA << std::endl ; + streamlog_out(DEBUG2) << " do i find a surface " << *msA << std::endl; dd4hep::rec::Vector3D ddWA = msA->normal(); dd4hep::rec::Vector3D ddUA = msA->u(); dd4hep::rec::Vector3D ddVA = msA->v(); CLHEP::Hep3Vector UA(ddUA.x() / dd4hep::mm, ddUA.y() / dd4hep::mm, ddUA.z() / dd4hep::mm); CLHEP::Hep3Vector VA(ddVA.x() / dd4hep::mm, ddVA.y() / dd4hep::mm, ddVA.z() / dd4hep::mm); - CLHEP::Hep3Vector WA(ddWA.x() / dd4hep::mm, ddWA.y() / dd4hep::mm, ddWA.z() / dd4hep::mm); - + CLHEP::Hep3Vector WA(ddWA.x() / dd4hep::mm, ddWA.y() / dd4hep::mm, ddWA.z() / dd4hep::mm); + const double* pb = b->getPosition(); double xb = pb[0]; double yb = pb[1]; double zb = pb[2]; - CLHEP::Hep3Vector PB( xb,yb,zb ); - dd4hep::rec::Vector3D ddPB( xb * dd4hep::mm,yb * dd4hep::mm,zb * dd4hep::mm ); - double du_b = b->getdU(); - + CLHEP::Hep3Vector PB(xb, yb, zb); + dd4hep::rec::Vector3D ddPB(xb * dd4hep::mm, yb * dd4hep::mm, zb * dd4hep::mm); + double du_b = b->getdU(); + const dd4hep::rec::ISurface* msB = surfMap->find(b->getCellID0())->second; dd4hep::rec::Vector3D ddWB = msB->normal(); dd4hep::rec::Vector3D ddUB = msB->u(); @@ -409,110 +359,109 @@ TrackerHitImpl* DDSpacePointBuilder::createSpacePoint( TrackerHitPlane* a , Trac CLHEP::Hep3Vector UB(ddUB.x() / dd4hep::mm, ddUB.y() / dd4hep::mm, ddUB.z() / dd4hep::mm); CLHEP::Hep3Vector VB(ddVB.x() / dd4hep::mm, ddVB.y() / dd4hep::mm, ddVB.z() / dd4hep::mm); CLHEP::Hep3Vector WB(ddWB.x() / dd4hep::mm, ddWB.y() / dd4hep::mm, ddWB.z() / dd4hep::mm); - - streamlog_out(DEBUG3) << "\t ( " << xa << " " << ya << " " << za << " ) <--> ( " << xb << " " << yb << " " << zb << " )\n"; + + streamlog_out(DEBUG3) << "\t ( " << xa << " " << ya << " " << za << " ) <--> ( " << xb << " " << yb << " " << zb + << " )\n"; ////////////////////////////////////////////////////////////////////////////////////////////////////// // First: check if the two measurement surfaces are parallel (i.e. the w are parallel or antiparallel) double angle = fabs(WB.angle(WA)); - double angleMax = 1.*M_PI/180.; - if(( angle > angleMax )&&( angle < M_PI-angleMax )){ - + double angleMax = 1. * M_PI / 180.; + if ((angle > angleMax) && (angle < M_PI - angleMax)) { + _nPlanesNotParallel++; - streamlog_out(DEBUG3) << "\tThe planes of the measurement surfaces are not parallel enough, the angle between the W vectors is " << angle - << " where the angle has to be smaller than " << angleMax << " or bigger than " << M_PI-angleMax << "\n\n"; - return NULL; //calculate the xing point and if that fails don't create a spacepoint - + streamlog_out(DEBUG3) + << "\tThe planes of the measurement surfaces are not parallel enough, the angle between the W vectors is " + << angle << " where the angle has to be smaller than " << angleMax << " or bigger than " << M_PI - angleMax + << "\n\n"; + return NULL; // calculate the xing point and if that fails don't create a spacepoint } ////////////////////////////////////////////////////////////////////////////////////////////////////// - ////////////////////////////////////////////////////////////////////////////////////////////////////// // Next: check if the angle between the strips is not 0 angle = fabs(VB.angle(VA)); - double angleMin= 1.*M_PI/180.; - if(( angle < angleMin )||( angle > M_PI-angleMin )){ - + double angleMin = 1. * M_PI / 180.; + if ((angle < angleMin) || (angle > M_PI - angleMin)) { + _nStripsTooParallel++; - streamlog_out(DEBUG3) << "\tThe strips (V vectors) of the measurement surfaces are too parallel, the angle between the V vectors is " << angle - << " where the angle has to be between " << angleMax << " or bigger than " << M_PI-angleMin << "\n\n"; - return NULL; //calculate the xing point and if that fails don't create a spacepoint - + streamlog_out(DEBUG3) + << "\tThe strips (V vectors) of the measurement surfaces are too parallel, the angle between the V vectors is " + << angle << " where the angle has to be between " << angleMax << " or bigger than " << M_PI - angleMin + << "\n\n"; + return NULL; // calculate the xing point and if that fails don't create a spacepoint } ////////////////////////////////////////////////////////////////////////////////////////////////////// - ////////////////////////////////////////////////////////////////////////////////////////////////////// // Next we want to calculate the crossing point. - + CLHEP::Hep3Vector point; -// calculatePointBetweenTwoLines( PA, VA, PB, VB, point ); -// -// // we want to set the space point on the surface of the hit closest to the IP -// if (PA.mag2() < PB.mag2()) { -// calculatePointBetweenTwoLines( PA, VA, PB, VB, point ); -// } else { -// calculatePointBetweenTwoLines( PB, VB, PA, VA, point ); -// } -// -// -// -// streamlog_out( DEBUG2 ) << "\tStandard: Position of space point (global) : ( " << point.x() << " " << point.y() << " " << point.z() << " )\n"; - - CLHEP::Hep3Vector vertex(0.,0.,0.); + // calculatePointBetweenTwoLines( PA, VA, PB, VB, point ); + // + // // we want to set the space point on the surface of the hit closest to the IP + // if (PA.mag2() < PB.mag2()) { + // calculatePointBetweenTwoLines( PA, VA, PB, VB, point ); + // } else { + // calculatePointBetweenTwoLines( PB, VB, PA, VA, point ); + // } + // + // + // + // streamlog_out( DEBUG2 ) << "\tStandard: Position of space point (global) : ( " << point.x() << " " << point.y() << + // " " << point.z() << " )\n"; + + CLHEP::Hep3Vector vertex(0., 0., 0.); dd4hep::rec::Vector2D L1 = msA->globalToLocal(ddPA); dd4hep::rec::Vector2D L2 = msB->globalToLocal(ddPB); - //CLHEP::Hep3Vector L1 = ccsA->getLocalPoint(PA); - //CLHEP::Hep3Vector L2 = ccsB->getLocalPoint(PB); + // CLHEP::Hep3Vector L1 = ccsA->getLocalPoint(PA); + // CLHEP::Hep3Vector L2 = ccsB->getLocalPoint(PB); - //msA->localToGlobal(PA); - //msA->localToGlobal(PB); + // msA->localToGlobal(PA); + // msA->localToGlobal(PB); - //streamlog_out(DEBUG3) << " L1 = " << L1 << std::endl; - //streamlog_out(DEBUG3) << " L2 = " << L2 << std::endl; + // streamlog_out(DEBUG3) << " L1 = " << L1 << std::endl; + // streamlog_out(DEBUG3) << " L2 = " << L2 << std::endl; dd4hep::rec::Vector2D ddSL1, ddEL1, ddSL2, ddEL2; - if (_subDetName == "SET"){ - ddSL1 = dd4hep::rec::Vector2D( L1.u(), L1.v() + (-stripLength * dd4hep::mm)/2.0 ); - ddEL1 = dd4hep::rec::Vector2D( L1.u(), L1.v() + (stripLength * dd4hep::mm)/2.0 ); - ddSL2 = dd4hep::rec::Vector2D( L2.u(), L2.v() + (-stripLength * dd4hep::mm)/2.0 ); - ddEL2 = dd4hep::rec::Vector2D( L2.u(), L2.v() + (stripLength * dd4hep::mm)/2.0 ); - } - else{ - ddSL1 = dd4hep::rec::Vector2D( L1.u(), (-stripLength * dd4hep::mm)/2.0 ); - ddEL1 = dd4hep::rec::Vector2D( L1.u(), (stripLength * dd4hep::mm)/2.0 ); - ddSL2 = dd4hep::rec::Vector2D( L2.u(), (-stripLength * dd4hep::mm)/2.0 ); - ddEL2 = dd4hep::rec::Vector2D( L2.u(), (stripLength * dd4hep::mm)/2.0 ); + if (_subDetName == "SET") { + ddSL1 = dd4hep::rec::Vector2D(L1.u(), L1.v() + (-stripLength * dd4hep::mm) / 2.0); + ddEL1 = dd4hep::rec::Vector2D(L1.u(), L1.v() + (stripLength * dd4hep::mm) / 2.0); + ddSL2 = dd4hep::rec::Vector2D(L2.u(), L2.v() + (-stripLength * dd4hep::mm) / 2.0); + ddEL2 = dd4hep::rec::Vector2D(L2.u(), L2.v() + (stripLength * dd4hep::mm) / 2.0); + } else { + ddSL1 = dd4hep::rec::Vector2D(L1.u(), (-stripLength * dd4hep::mm) / 2.0); + ddEL1 = dd4hep::rec::Vector2D(L1.u(), (stripLength * dd4hep::mm) / 2.0); + ddSL2 = dd4hep::rec::Vector2D(L2.u(), (-stripLength * dd4hep::mm) / 2.0); + ddEL2 = dd4hep::rec::Vector2D(L2.u(), (stripLength * dd4hep::mm) / 2.0); } - //L1.setY(-stripLength/2.0); - //CLHEP::Hep3Vector SL1 = L1; - //L1.setY( stripLength/2.0); - //CLHEP::Hep3Vector EL1 = L1; - //L2.setY(-stripLength/2.0); - //CLHEP::Hep3Vector SL2 = L2; - //L2.setY( stripLength/2.0); - //CLHEP::Hep3Vector EL2 = L2; - - + // L1.setY(-stripLength/2.0); + // CLHEP::Hep3Vector SL1 = L1; + // L1.setY( stripLength/2.0); + // CLHEP::Hep3Vector EL1 = L1; + // L2.setY(-stripLength/2.0); + // CLHEP::Hep3Vector SL2 = L2; + // L2.setY( stripLength/2.0); + // CLHEP::Hep3Vector EL2 = L2; dd4hep::rec::Vector3D ddS1 = msA->localToGlobal(ddSL1); dd4hep::rec::Vector3D ddE1 = msA->localToGlobal(ddEL1); dd4hep::rec::Vector3D ddS2 = msB->localToGlobal(ddSL2); dd4hep::rec::Vector3D ddE2 = msB->localToGlobal(ddEL2); - CLHEP::Hep3Vector S1 (ddS1.x() / dd4hep::mm, ddS1.y() / dd4hep::mm, ddS1.z() / dd4hep::mm); - CLHEP::Hep3Vector E1 (ddE1.x() / dd4hep::mm, ddE1.y() / dd4hep::mm, ddE1.z() / dd4hep::mm); - CLHEP::Hep3Vector S2 (ddS2.x() / dd4hep::mm, ddS2.y() / dd4hep::mm, ddS2.z() / dd4hep::mm); - CLHEP::Hep3Vector E2 (ddE2.x() / dd4hep::mm, ddE2.y() / dd4hep::mm, ddE2.z() / dd4hep::mm); - //CLHEP::Hep3Vector S1 = ccsA->getGlobalPoint(SL1); - //CLHEP::Hep3Vector E1 = ccsA->getGlobalPoint(EL1); - //CLHEP::Hep3Vector S2 = ccsB->getGlobalPoint(SL2); - //CLHEP::Hep3Vector E2 = ccsB->getGlobalPoint(EL2); + CLHEP::Hep3Vector S1(ddS1.x() / dd4hep::mm, ddS1.y() / dd4hep::mm, ddS1.z() / dd4hep::mm); + CLHEP::Hep3Vector E1(ddE1.x() / dd4hep::mm, ddE1.y() / dd4hep::mm, ddE1.z() / dd4hep::mm); + CLHEP::Hep3Vector S2(ddS2.x() / dd4hep::mm, ddS2.y() / dd4hep::mm, ddS2.z() / dd4hep::mm); + CLHEP::Hep3Vector E2(ddE2.x() / dd4hep::mm, ddE2.y() / dd4hep::mm, ddE2.z() / dd4hep::mm); + // CLHEP::Hep3Vector S1 = ccsA->getGlobalPoint(SL1); + // CLHEP::Hep3Vector E1 = ccsA->getGlobalPoint(EL1); + // CLHEP::Hep3Vector S2 = ccsB->getGlobalPoint(SL2); + // CLHEP::Hep3Vector E2 = ccsB->getGlobalPoint(EL2); streamlog_out(DEBUG3) << " stripLength = " << stripLength << std::endl; - + streamlog_out(DEBUG3) << " S1 = " << S1 << std::endl; streamlog_out(DEBUG3) << " E1 = " << E1 << std::endl; @@ -520,353 +469,331 @@ TrackerHitImpl* DDSpacePointBuilder::createSpacePoint( TrackerHitPlane* a , Trac streamlog_out(DEBUG3) << " E2 = " << E2 << std::endl; point.set(0.0, 0.0, 0.0); - - - int valid_intersection = calculatePointBetweenTwoLines_UsingVertex( S1, E1, S2, E2, vertex, point ); - + + int valid_intersection = calculatePointBetweenTwoLines_UsingVertex(S1, E1, S2, E2, vertex, point); + if (valid_intersection != 0) { streamlog_out(DEBUG3) << "\tNo valid intersection for lines" << std::endl; return NULL; } - - streamlog_out(DEBUG3) << "\tVertex: Position of space point (global) : ( " << point.x() << " " << point.y() << " " << point.z() << " )\n"; - + + streamlog_out(DEBUG3) << "\tVertex: Position of space point (global) : ( " << point.x() << " " << point.y() << " " + << point.z() << " )\n"; // using dd4hep to check if hit within boundaries - dd4hep::rec::Vector3D DDpoint( point.x() * dd4hep::mm, point.y() * dd4hep::mm, point.z() * dd4hep::mm ); + dd4hep::rec::Vector3D DDpoint(point.x() * dd4hep::mm, point.y() * dd4hep::mm, point.z() * dd4hep::mm); - if ( !msA->insideBounds(DDpoint)){ + if (!msA->insideBounds(DDpoint)) { _nOutOfBoundary++; - streamlog_out(DEBUG3) << " SpacePoint position lies outside the boundary of the layer " << std::endl ; - //streamlog_out(DEBUG3) << "\tSpacePoint position lies outside the boundary of the first layer: local coordinates are ( " << localPointA.x() << " " << localPointA.y() << " " << localPointA.z() << " )\n\n"; - + streamlog_out(DEBUG3) << " SpacePoint position lies outside the boundary of the layer " << std::endl; + // streamlog_out(DEBUG3) << "\tSpacePoint position lies outside the boundary of the first layer: local coordinates + // are ( " << localPointA.x() << " " << localPointA.y() << " " << localPointA.z() << " )\n\n"; + return NULL; } - /* // Check if the new hit is within the boundaries CLHEP::Hep3Vector localPointA = ccsA->getLocalPoint(point); - localPointA.setZ( 0. ); // we set w to 0 so it is in the plane ( we are only interested if u and v are in or out of range, to exclude w from the check it is set to 0) - + localPointA.setZ( 0. ); // we set w to 0 so it is in the plane ( we are only interested if u and v are in or out of + range, to exclude w from the check it is set to 0) + CLHEP::Hep3Vector localPointB = ccsB->getLocalPoint(point); - localPointB.setZ( 0. ); // we set w to 0 so it is in the plane ( we are only interested if u and v are in or out of range, to exclude w from the check it is set to 0) - - + localPointB.setZ( 0. ); // we set w to 0 so it is in the plane ( we are only interested if u and v are in or out of + range, to exclude w from the check it is set to 0) + + if( !msA->isLocalInBoundary( localPointA ) ){ - + _nOutOfBoundary++; - streamlog_out( DEBUG2 ) << "\tSpacePoint position lies outside the boundary of the first layer: local coordinates are ( " + streamlog_out( DEBUG2 ) << "\tSpacePoint position lies outside the boundary of the first layer: local coordinates + are ( " << localPointA.x() << " " << localPointA.y() << " " << localPointA.z() << " )\n\n"; - + return NULL; - + } if( !msB->isLocalInBoundary( localPointB ) ){ - + _nOutOfBoundary++; - streamlog_out( DEBUG2 ) << "\tSecond hit is out of boundary: local coordinates are ( " + streamlog_out( DEBUG2 ) << "\tSecond hit is out of boundary: local coordinates are ( " << localPointB.x() << " " << localPointB.y() << " " << localPointB.z() << " )\n\n"; - + return NULL; - + } */ - - //Create the new TrackerHit + + // Create the new TrackerHit TrackerHitImpl* spacePoint = new TrackerHitImpl(); - - double pos[3] = {point.x(), point.y(), point.z() }; - spacePoint->setPosition( pos ) ; - - - // set error treating the strips as stereo with equal and opposite rotation -- for reference see Karimaki NIM A 374 p367-370 - - // first calculate the covariance matrix in the cartisian coordinate system defined by the sensor + + double pos[3] = {point.x(), point.y(), point.z()}; + spacePoint->setPosition(pos); + + // set error treating the strips as stereo with equal and opposite rotation -- for reference see Karimaki NIM A 374 + // p367-370 + + // first calculate the covariance matrix in the cartisian coordinate system defined by the sensor // here we assume that du is the same for both sides - - if( fabs(du_a - du_b) > 1.0e-06 ){ - streamlog_out( ERROR ) << "\tThe measurement errors of the two 1D hits must be equal \n\n"; - assert( (fabs(du_a - du_b) > 1.0e-06) == false ); - return NULL; //measurement errors are not equal don't create a spacepoint + + if (fabs(du_a - du_b) > 1.0e-06) { + streamlog_out(ERROR) << "\tThe measurement errors of the two 1D hits must be equal \n\n"; + assert((fabs(du_a - du_b) > 1.0e-06) == false); + return NULL; // measurement errors are not equal don't create a spacepoint } - - - double du2 = du_a*du_a; - + + double du2 = du_a * du_a; + // rotate the strip system back to double-layer wafer system CLHEP::Hep3Vector u_sensor = UA + UB; CLHEP::Hep3Vector v_sensor = VA + VB; CLHEP::Hep3Vector w_sensor = WA + WB; - - CLHEP::HepRotation rot_sensor( u_sensor, v_sensor, w_sensor ); + + CLHEP::HepRotation rot_sensor(u_sensor, v_sensor, w_sensor); CLHEP::HepMatrix rot_sensor_matrix; rot_sensor_matrix = rot_sensor; - - double cos2_alpha = VA.cos2Theta(v_sensor) ; // alpha = strip angle - double sin2_alpha = 1 - cos2_alpha ; - - CLHEP::HepSymMatrix cov_plane(3,0); // u,v,w - - cov_plane(1,1) = (0.5 * du2) / cos2_alpha; - cov_plane(2,2) = (0.5 * du2) / sin2_alpha; - - streamlog_out(DEBUG3) << "\t cov_plane = " << cov_plane << "\n\n"; - streamlog_out(DEBUG3) << "\tstrip_angle = " << VA.angle(VB)/(M_PI/180) / 2.0 << " degrees \n\n"; - - CLHEP::HepSymMatrix cov_xyz= cov_plane.similarity(rot_sensor_matrix); - + + double cos2_alpha = VA.cos2Theta(v_sensor); // alpha = strip angle + double sin2_alpha = 1 - cos2_alpha; + + CLHEP::HepSymMatrix cov_plane(3, 0); // u,v,w + + cov_plane(1, 1) = (0.5 * du2) / cos2_alpha; + cov_plane(2, 2) = (0.5 * du2) / sin2_alpha; + + streamlog_out(DEBUG3) << "\t cov_plane = " << cov_plane << "\n\n"; + streamlog_out(DEBUG3) << "\tstrip_angle = " << VA.angle(VB) / (M_PI / 180) / 2.0 << " degrees \n\n"; + + CLHEP::HepSymMatrix cov_xyz = cov_plane.similarity(rot_sensor_matrix); + streamlog_out(DEBUG3) << "\t cov_xyz = " << cov_xyz << "\n\n"; - - EVENT::FloatVec cov( 9 ) ; - int icov = 0 ; - - for(int irow=0; irow<3; ++irow ){ - for(int jcol=0; jcol limit || m < -1. * limit) { + + streamlog_out(DEBUG1) << "m' = " << m << " \n"; + ok = false; - + } else { - - double n = (-(t*qs)/(VCD*qs)); // ratio for second line - if (n>limit || n<-1.*limit) { - - streamlog_out( DEBUG1 ) << "n' = " << n << " \n"; - - ok = false; + double n = (-(t * qs) / (VCD * qs)); // ratio for second line + + if (n > limit || n < -1. * limit) { + + streamlog_out(DEBUG1) << "n' = " << n << " \n"; + ok = false; } } - + if (ok) { - point = 0.5*(PA + PB + m*VAB); + point = 0.5 * (PA + PB + m * VAB); } - + return ok ? 0 : 1; - } +int DDSpacePointBuilder::calculatePointBetweenTwoLines(const CLHEP::Hep3Vector& P1, const CLHEP::Hep3Vector& V1, + const CLHEP::Hep3Vector& P2, const CLHEP::Hep3Vector& V2, + CLHEP::Hep3Vector& point) { - -int DDSpacePointBuilder::calculatePointBetweenTwoLines( const CLHEP::Hep3Vector& P1, const CLHEP::Hep3Vector& V1, const CLHEP::Hep3Vector& P2, const CLHEP::Hep3Vector& V2, CLHEP::Hep3Vector& point ){ - // Richgungsvektor normal auf die anderen beiden: - CLHEP::Hep3Vector n = V1.cross( V2 ); - + CLHEP::Hep3Vector n = V1.cross(V2); + // Now we want to rotate into a coordinate system, where n is parallel to the z axis // For this: first set phi to 0 // then: set theta to 0 (we set phi to 0 first, so we can then rotate arount the y axis) CLHEP::HepRotation rot; - rot.rotateZ( -n.phi() ); - CLHEP::Hep3Vector nPrime = rot * n; //now the phi of nPrime should be 0 - streamlog_out( DEBUG0 ) << "phi of n' = " << nPrime.phi() << " (it should be 0!!!)\n"; - rot.rotateY( -n.theta() ); + rot.rotateZ(-n.phi()); + CLHEP::Hep3Vector nPrime = rot * n; // now the phi of nPrime should be 0 + streamlog_out(DEBUG0) << "phi of n' = " << nPrime.phi() << " (it should be 0!!!)\n"; + rot.rotateY(-n.theta()); nPrime = rot * n; - streamlog_out( DEBUG0 ) << "phi of n'' = " << nPrime.phi() << " (it should be 0!!!)\n"; - streamlog_out( DEBUG0 ) << "theta of n'' = " << nPrime.theta() << " (it should be 0!!!)\n"; - + streamlog_out(DEBUG0) << "phi of n'' = " << nPrime.phi() << " (it should be 0!!!)\n"; + streamlog_out(DEBUG0) << "theta of n'' = " << nPrime.theta() << " (it should be 0!!!)\n"; + // Now rotate all the vectors and points into this coordinatesystem. CLHEP::Hep3Vector P1prime = rot * P1; CLHEP::Hep3Vector V1prime = rot * V1; CLHEP::Hep3Vector P2prime = rot * P2; CLHEP::Hep3Vector V2prime = rot * V2; - + // What is the gain of rotating into this system? - // A: + // A: double x; double y; - int res = calculateXingPoint( P1prime.x(), P1prime.y(), V1prime.x(), V1prime.y(), P2prime.x(), P2prime.y(), V2prime.x(), V2prime.y(), x, y ); - - if ( res != 0 ) return 1; - - point.setX( x ); - point.setY( y ); - point.setZ( (P1prime.z() + P2prime.z())/2. ); - + int res = calculateXingPoint(P1prime.x(), P1prime.y(), V1prime.x(), V1prime.y(), P2prime.x(), P2prime.y(), + V2prime.x(), V2prime.y(), x, y); + + if (res != 0) + return 1; + + point.setX(x); + point.setY(y); + point.setZ((P1prime.z() + P2prime.z()) / 2.); + // Now transform back to the global coordinates point = rot.inverse() * point; - - + return 0; - } +int DDSpacePointBuilder::calculateXingPoint(double x1, double y1, float ex1, float ey1, double x2, double y2, float ex2, + float ey2, double& x, double& y) { -int DDSpacePointBuilder::calculateXingPoint( double x1, double y1, float ex1, float ey1, double x2, double y2, float ex2, float ey2, double& x, double& y ){ - - - float a = (x1*ey1 - y1*ex1) - (x2*ey1 - y2*ex1); - float b = ex2*ey1 - ex1*ey2; + float a = (x1 * ey1 - y1 * ex1) - (x2 * ey1 - y2 * ex1); + float b = ex2 * ey1 - ex1 * ey2; const float epsilon = 0.00001; - if( fabs(b) < epsilon ) return 1; // if b==0 the two directions e1 and e2 are parallel and there is no crossing! + if (fabs(b) < epsilon) + return 1; // if b==0 the two directions e1 and e2 are parallel and there is no crossing! - float t = a/b; + float t = a / b; - x = x2 + t*ex2; - y = y2 + t*ey2; + x = x2 + t * ex2; + y = y2 + t * ey2; return 0; +} - +std::vector DDSpacePointBuilder::getCellID0sAtBack(int cellID0) { -} - -std::vector< int > DDSpacePointBuilder::getCellID0sAtBack( int cellID0 ){ - - std::vector< int > back; - - //find out detector, layer - UTIL::BitField64 cellID( LCTrackerCellID::encoding_string() ); - cellID.setValue( cellID0 ); - - - int subdet = cellID[ LCTrackerCellID::subdet() ] ; - int layer = cellID[ LCTrackerCellID::layer() ]; - - if (subdet != ILDDetID::FTD) { - - //check if sensor is in front - if( layer%2 == 0 ){ // even layers are front sensors - - cellID[ LCTrackerCellID::layer() ] = layer + 1; + std::vector back; + + // find out detector, layer + UTIL::BitField64 cellID(LCTrackerCellID::encoding_string()); + cellID.setValue(cellID0); + + int subdet = cellID[LCTrackerCellID::subdet()]; + int layer = cellID[LCTrackerCellID::layer()]; + + if (subdet != ILDDetID::FTD) { + + // check if sensor is in front + if (layer % 2 == 0) { // even layers are front sensors + + cellID[LCTrackerCellID::layer()] = layer + 1; // it is assumed that the even layers are the front layers // and the following odd ones the back layers - - back.push_back( cellID.lowWord() ); - + + back.push_back(cellID.lowWord()); } } - else{ + else { - dd4hep::Detector & theDetector2 = dd4hep::Detector::getInstance(); - dd4hep::DetElement ftdDE = theDetector2.detector( _subDetName); + dd4hep::Detector& theDetector2 = dd4hep::Detector::getInstance(); + dd4hep::DetElement ftdDE = theDetector2.detector(_subDetName); dd4hep::rec::ZDiskPetalsData* ft = ftdDE.extension(); - int sensor = cellID[ LCTrackerCellID::sensor() ]; - //int Nsensors = ft->layers.at(layer).petalNumber ; - int Nsensors = ft->layers.at(layer).sensorsPerPetal ; + int sensor = cellID[LCTrackerCellID::sensor()]; + // int Nsensors = ft->layers.at(layer).petalNumber ; + int Nsensors = ft->layers.at(layer).sensorsPerPetal; + + streamlog_out(DEBUG3) << " layer " << layer << " sensors " << Nsensors << std::endl; + streamlog_out(DEBUG3) << " so sensor " << sensor << " is connected with sensor " << sensor + Nsensors / 2 + << std::endl; - streamlog_out(DEBUG3) << " layer " << layer << " sensors " << Nsensors << std::endl; - streamlog_out(DEBUG3) << " so sensor " << sensor << " is connected with sensor " << sensor + Nsensors/2 << std::endl; + std::vector Sensors; - std::vector Sensors ; - - //check if sensor is in front - //if(( Sensors.at(layer).DoubleSided ) && ( sensor <= Nsensors / 2 ) ){ - if (sensor <= Nsensors / 2 ) { - - cellID[ LCTrackerCellID::sensor() ] = sensor + Nsensors / 2; + // check if sensor is in front + // if(( Sensors.at(layer).DoubleSided ) && ( sensor <= Nsensors / 2 ) ){ + if (sensor <= Nsensors / 2) { + + cellID[LCTrackerCellID::sensor()] = sensor + Nsensors / 2; // it is assumed, that sensors 1 until n/2 will be on front // and sensor n/2 + 1 until n are at the back // so the sensor x, will have sensor x+n/2 at the back - - back.push_back( cellID.lowWord() ); - - } + back.push_back(cellID.lowWord()); + } } return back; - - - } +std::string DDSpacePointBuilder::getCellID0Info(int cellID0) { + std::stringstream s; -std::string DDSpacePointBuilder::getCellID0Info( int cellID0 ){ + // find out layer, module, sensor + UTIL::BitField64 cellID(LCTrackerCellID::encoding_string()); + cellID.setValue(cellID0); + + int subdet = cellID[LCTrackerCellID::subdet()]; + int side = cellID[LCTrackerCellID::side()]; + int module = cellID[LCTrackerCellID::module()]; + int sensor = cellID[LCTrackerCellID::sensor()]; + int layer = cellID[LCTrackerCellID::layer()]; - std::stringstream s; - - //find out layer, module, sensor - UTIL::BitField64 cellID( LCTrackerCellID::encoding_string() ); - cellID.setValue( cellID0 ); - - int subdet = cellID[ LCTrackerCellID::subdet() ] ; - int side = cellID[ LCTrackerCellID::side() ]; - int module = cellID[ LCTrackerCellID::module() ]; - int sensor = cellID[ LCTrackerCellID::sensor() ]; - int layer = cellID[ LCTrackerCellID::layer() ]; - s << "(su" << subdet << ",si" << side << ",la" << layer << ",mo" << module << ",se" << sensor << ")"; - + return s.str(); - } diff --git a/source/Digitisers/src/DDTPCDigiProcessor.cc b/source/Digitisers/src/DDTPCDigiProcessor.cc index e9157d9..a08336f 100644 --- a/source/Digitisers/src/DDTPCDigiProcessor.cc +++ b/source/Digitisers/src/DDTPCDigiProcessor.cc @@ -5,29 +5,29 @@ #include "FixedPadSizeDiskLayout.h" #include "TPCModularEndplate.h" -#include +#include +#include #include -#include +#include #include -#include -#include +#include -#include -#include "marlin/VerbosityLevels.h" #include "marlin/Global.h" #include "marlin/ProcessorEventSeeder.h" +#include "marlin/VerbosityLevels.h" +#include #include "Circle.h" -#include "SimpleHelix.h" -#include"constants.h" #include "LCCylinder.h" +#include "SimpleHelix.h" +#include "constants.h" #include #include -//stl exception handler -#include +// stl exception handler #include "constants.h" #include "voxel.h" +#include // #include "UTIL/LCTrackerConf.h" @@ -35,244 +35,179 @@ #include // --- DD4hep --- +#include "DD4hep/DD4hepUnits.h" #include "DD4hep/Detector.h" #include "DDRec/Vector3D.h" -#include "DD4hep/DD4hepUnits.h" - -using namespace lcio ; -using namespace marlin ; -using namespace constants ; - +using namespace lcio; +using namespace marlin; +using namespace constants; #ifdef MARLIN_USE_AIDA -using namespace AIDA ; +using namespace AIDA; #endif +DDTPCDigiProcessor aDDTPCDigiProcessor; -DDTPCDigiProcessor aDDTPCDigiProcessor ; - -bool compare_phi( Voxel_tpc* a, Voxel_tpc* b) { - return ( a->getPhiIndex() < b->getPhiIndex() ) ; -} +bool compare_phi(Voxel_tpc* a, Voxel_tpc* b) { return (a->getPhiIndex() < b->getPhiIndex()); } -bool compare_z( Voxel_tpc* a, Voxel_tpc* b) { - return ( a->getZIndex() < b->getZIndex() ) ; -} +bool compare_z(Voxel_tpc* a, Voxel_tpc* b) { return (a->getZIndex() < b->getZIndex()); } +DDTPCDigiProcessor::~DDTPCDigiProcessor() { delete _tpcEP; } -DDTPCDigiProcessor::~DDTPCDigiProcessor(){ - - delete _tpcEP ; -} +DDTPCDigiProcessor::DDTPCDigiProcessor() : Processor("DDTPCDigiProcessor") { -DDTPCDigiProcessor::DDTPCDigiProcessor() : Processor("DDTPCDigiProcessor") -{ - // modify processor description - _description = "Produces TPC TrackerHit collection from SimTrackerHit collection, smeared in RPhi and Z. A search is made for adjacent hits on a pad row, if they are closer in z and r-phi than the steering parameters _doubleHitResRPhi (default value 2.0 mm) and _doubleHitResZ (default value 5.0 mm) they are considered to overlap. Clusters of hits smaller than _maxMerge (default value 3) are merged into a single tracker hit, with the position given as the average poision of the hits in phi and in z. Clusters which have _maxMerge hits or more are determined to be identifiable as multiple hits, and are not added to the tracker hit collection. This of course means that good hits caught up in a cluster of background hits will be lossed." ; - + _description = + "Produces TPC TrackerHit collection from SimTrackerHit collection, smeared in RPhi and Z. A search is made for " + "adjacent hits on a pad row, if they are closer in z and r-phi than the steering parameters _doubleHitResRPhi " + "(default value 2.0 mm) and _doubleHitResZ (default value 5.0 mm) they are considered to overlap. Clusters of " + "hits smaller than _maxMerge (default value 3) are merged into a single tracker hit, with the position given as " + "the average poision of the hits in phi and in z. Clusters which have _maxMerge hits or more are determined to " + "be identifiable as multiple hits, and are not added to the tracker hit collection. This of course means that " + "good hits caught up in a cluster of background hits will be lossed."; + // register steering parameters: name, description, class-variable, default value - - registerInputCollection( LCIO::SIMTRACKERHIT, - "TPCPadRowHitCollectionName" , - "Name of the default pad-row based SimTrackerHit collection" , - _padRowHitColName , - std::string("TPCCollection") ) ; - - registerInputCollection( LCIO::SIMTRACKERHIT, - "TPCSpacePointCollectionName" , - "Name of the additional space point collection which provides additional guide hits between pad row centers." , - _spacePointColName , - std::string("TPCSpacePointCollection") ) ; - - registerInputCollection( LCIO::SIMTRACKERHIT, - "TPCLowPtCollectionName" , - "Name of the LowPt SimTrackerHit collection Produced by Mokka TPC Driver TPC0X" , - _lowPtHitscolName , - std::string("TPCLowPtCollection") ) ; - - registerOutputCollection( LCIO::TRACKERHIT, - "TPCTrackerHitsCol" , - "Name of the Output TrackerHit collection" , - _TPCTrackerHitsCol , - std::string("TPCTrackerHits") ) ; - - registerOutputCollection(LCIO::LCRELATION, - "SimTrkHitRelCollection", - "Name of TrackerHit SimTrackHit relation collection", - _outRelColName, + + registerInputCollection(LCIO::SIMTRACKERHIT, "TPCPadRowHitCollectionName", + "Name of the default pad-row based SimTrackerHit collection", _padRowHitColName, + std::string("TPCCollection")); + + registerInputCollection( + LCIO::SIMTRACKERHIT, "TPCSpacePointCollectionName", + "Name of the additional space point collection which provides additional guide hits between pad row centers.", + _spacePointColName, std::string("TPCSpacePointCollection")); + + registerInputCollection(LCIO::SIMTRACKERHIT, "TPCLowPtCollectionName", + "Name of the LowPt SimTrackerHit collection Produced by Mokka TPC Driver TPC0X", + _lowPtHitscolName, std::string("TPCLowPtCollection")); + + registerOutputCollection(LCIO::TRACKERHIT, "TPCTrackerHitsCol", "Name of the Output TrackerHit collection", + _TPCTrackerHitsCol, std::string("TPCTrackerHits")); + + registerOutputCollection(LCIO::LCRELATION, "SimTrkHitRelCollection", + "Name of TrackerHit SimTrackHit relation collection", _outRelColName, std::string("TPCTrackerHitRelations")); - + registerProcessorParameter("UseRawHitsToStoreSimhitPointer", "Store the pointer to the SimTrackerHits in RawHits (deprecated) ", - _use_raw_hits_to_store_simhit_pointer, - bool(false)); - - registerProcessorParameter( "PointResolutionPadPhi" , - "Pad Phi Resolution constant in TPC" , - _pointResoPadPhi , - (float)0.900) ; - - registerProcessorParameter( "RejectCellID0" , - "whether or not to use hits without proper cell ID (pad row)" , - _rejectCellID0 , - (int)1) ; - - registerProcessorParameter( "PointResolutionRPhi" , - "R-Phi Resolution constant in TPC" , - _pointResoRPhi0 , - (float)0.050) ; - - registerProcessorParameter( "DiffusionCoeffRPhi" , - "R-Phi Diffusion Coefficent in TPC" , - _diffRPhi , - (float)0.025) ; - - registerProcessorParameter( "N_eff" , - "Number of Effective electrons per pad in TPC" , - _nEff , - (int)22) ; - - registerProcessorParameter( "PointResolutionZ" , - "TPC Z Resolution Coefficent independent of diffusion" , - _pointResoZ0 , - (float)0.4) ; - - registerProcessorParameter( "DiffusionCoeffZ" , - "Z Diffusion Coefficent in TPC" , - _diffZ , - (float)0.08) ; - - registerProcessorParameter( "HitSortingBinningZ" , - "Defines spatial slice in Z" , - _binningZ , - (float)5.0) ; - - registerProcessorParameter( "HitSortingBinningRPhi" , - "Defines spatial slice in RP" , - _binningRPhi , - (float)2.0) ; - - - registerProcessorParameter( "DoubleHitResolutionZ" , - "Defines the minimum distance for two seperable hits in Z" , - _doubleHitResZ , - (float)5.0) ; - - registerProcessorParameter( "DoubleHitResolutionRPhi" , - "Defines the minimum distance for two seperable hits in RPhi" , - _doubleHitResRPhi , - (float)2.0) ; - - registerProcessorParameter( "MaxClusterSizeForMerge" , - "Defines the maximum number of adjacent hits which can be merged" , - _maxMerge , - (int)3) ; - - - - //fg: these are the numbers for the large ILD TPC - IntVec tpcEPModNumExample = { 14, 18, 23, 28, 32, 37, 42, 46 } ; - - registerProcessorParameter( "TPCEndPlateModuleNumbers" , - "Number of modules in the rings of the TPC endplate" , - _tpcEndPlateModuleNumbers , - tpcEPModNumExample ) ; - - //fg: these are just guestimates - need to get correct phi0 values for the TPC modules - FloatVec tpcEPModPhi0Example = { 0, 0.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07 } ; - - registerProcessorParameter( "TPCEndPlateModulePhi0s" , - "Phi0s of modules in the rings of the TPC endplate" , - _tpcEndPlateModulePhi0s , - tpcEPModPhi0Example ) ; - - - registerProcessorParameter( "TPCEndPlateModuleGapPhi" , - "Gap size in mm of the gaps between the endplace modules in Phi" , - _tpcEndPlateModuleGapPhi , - (float) 1. ) ; - - - registerProcessorParameter( "TPCEndPlateModuleGapR" , - "Gap size in mm of the gaps between the endplace modules in R" , - _tpcEndPlateModuleGapR , - (float) 1. ) ; + _use_raw_hits_to_store_simhit_pointer, bool(false)); + + registerProcessorParameter("PointResolutionPadPhi", "Pad Phi Resolution constant in TPC", _pointResoPadPhi, + (float)0.900); + + registerProcessorParameter("RejectCellID0", "whether or not to use hits without proper cell ID (pad row)", + _rejectCellID0, (int)1); + + registerProcessorParameter("PointResolutionRPhi", "R-Phi Resolution constant in TPC", _pointResoRPhi0, (float)0.050); + + registerProcessorParameter("DiffusionCoeffRPhi", "R-Phi Diffusion Coefficent in TPC", _diffRPhi, (float)0.025); + + registerProcessorParameter("N_eff", "Number of Effective electrons per pad in TPC", _nEff, (int)22); + + registerProcessorParameter("PointResolutionZ", "TPC Z Resolution Coefficent independent of diffusion", _pointResoZ0, + (float)0.4); + + registerProcessorParameter("DiffusionCoeffZ", "Z Diffusion Coefficent in TPC", _diffZ, (float)0.08); + + registerProcessorParameter("HitSortingBinningZ", "Defines spatial slice in Z", _binningZ, (float)5.0); + + registerProcessorParameter("HitSortingBinningRPhi", "Defines spatial slice in RP", _binningRPhi, (float)2.0); + + registerProcessorParameter("DoubleHitResolutionZ", "Defines the minimum distance for two seperable hits in Z", + _doubleHitResZ, (float)5.0); + + registerProcessorParameter("DoubleHitResolutionRPhi", "Defines the minimum distance for two seperable hits in RPhi", + _doubleHitResRPhi, (float)2.0); + + registerProcessorParameter("MaxClusterSizeForMerge", + "Defines the maximum number of adjacent hits which can be merged", _maxMerge, (int)3); + + // fg: these are the numbers for the large ILD TPC + IntVec tpcEPModNumExample = {14, 18, 23, 28, 32, 37, 42, 46}; + + registerProcessorParameter("TPCEndPlateModuleNumbers", "Number of modules in the rings of the TPC endplate", + _tpcEndPlateModuleNumbers, tpcEPModNumExample); + // fg: these are just guestimates - need to get correct phi0 values for the TPC modules + FloatVec tpcEPModPhi0Example = {0, 0.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07}; + + registerProcessorParameter("TPCEndPlateModulePhi0s", "Phi0s of modules in the rings of the TPC endplate", + _tpcEndPlateModulePhi0s, tpcEPModPhi0Example); + + registerProcessorParameter("TPCEndPlateModuleGapPhi", + "Gap size in mm of the gaps between the endplace modules in Phi", _tpcEndPlateModuleGapPhi, + (float)1.); + + registerProcessorParameter("TPCEndPlateModuleGapR", "Gap size in mm of the gaps between the endplace modules in R", + _tpcEndPlateModuleGapR, (float)1.); } +void DDTPCDigiProcessor::init() { -void DDTPCDigiProcessor::init() -{ - - // From GNU documentation: - // A replacement for the standard terminate_handler which prints + // A replacement for the standard terminate_handler which prints // more information about the terminating exception (if any) on stderr. Call ... - //std::set_terminate (__gnu_cxx::__verbose_terminate_handler); - + // std::set_terminate (__gnu_cxx::__verbose_terminate_handler); + #ifdef DIGIPLOTS /// Hook an AIDA implementation ----------------------------------------------- - + // First create a pointer to the "IAnalysisFactory" of a specific AIDA - // implementation. This factory can then be used to produce all other + // implementation. This factory can then be used to produce all other // factories. _AF = AIDA_createAnalysisFactory(); - + // Create a ITreeFactory. ----------------------------------------------------- // A ITree can be used to store AIDA objects in memory or on disk. - + _TRF = _AF->createTreeFactory(); - + /// Create a ITree object which is bound to a file. --------------------------- // You must always create a "ITree" object to create any other factory. /* * Creates a new tree and associates it with a store. * The store is assumed to be read/write. * The store will be created if it does not exist. - * @param storeName The name of the store, if empty (""), the tree is - * created in memory and therefore will not be associated + * @param storeName The name of the store, if empty (""), the tree is + * created in memory and therefore will not be associated * with a file. * @param storeType Implementation specific string, may control store type - * @param readOnly If true the store is opened readonly, an exception if it + * @param readOnly If true the store is opened readonly, an exception if it * does not exist - * @param createNew If false the file must exist, if true the file will be + * @param createNew If false the file must exist, if true the file will be * created * @param options Other options, currently are not specified */ - // ITree * ITreeFactory::create(const std::string & storeName, - // const std::string & storeType = "", - // bool readOnly = false, - // bool createNew = false, + // ITree * ITreeFactory::create(const std::string & storeName, + // const std::string & storeType = "", + // bool readOnly = false, + // bool createNew = false, // const std::string & options = "") ; - - _TREE = _TRF->create("DDTPCDigi.root", - "root", - false, - true); - + + _TREE = _TRF->create("DDTPCDigi.root", "root", false, true); + /// Create an IHistogramFactory which is bound to the tree "*_TREE". ----------- - + /* * Create an IHistogramFactory. * @param tree The ITree which created histograms will be associated to. * @return The IHistogramFactory. */ // IHistogramFactory * IAnalysisFactory::createHistogramFactory(ITree & tree); - + _HF = _AF->createHistogramFactory(*_TREE); - + _TREE->mkdir("Histograms"); - + /* * Create a IHistogram1D. - * @param path The path of the created IHistogram. The path can either + * @param path The path of the created IHistogram. The path can either * be a relative or full path. - * ("/folder1/folder2/dataName" and + * ("/folder1/folder2/dataName" and * "../folder/dataName" are valid paths). - * All the directories in the path must exist. The - * characther `/` cannot be used in names; it is only + * All the directories in the path must exist. The + * characther `/` cannot be used in names; it is only * used to delimit directories within paths. * @param title The title of the IHistogram1D. * @param nBins The number of bins of the x axis. @@ -282,806 +217,755 @@ void DDTPCDigiProcessor::init() * "type=efficiency" for an efficiency IHistogram1D. * @return The newly created IHistogram1D. */ - - - - _phiDiffHisto = _HF->createHistogram1D("Histograms/phi_diff", - "Calculated Phi - Track Phi", - 201, -0.05, 0.05); - - _thetaDiffHisto = _HF->createHistogram1D("Histograms/theta_diff", - "Calculated Theta - Track Theta", - 201, -0.05, 0.05); - - _phiRelHisto = _HF->createHistogram1D("Histograms/padPhi", - "Phi Relative to the Pad", - 201, 0.0, 6.3); - - _thetaRelHisto = _HF->createHistogram1D("Histograms/padtheta", - "Theta Relative to the pad", - 201, 0.0, 6.3); - - _rPhiDiffHisto = _HF->createHistogram1D("Histograms/rPhiDiff", - "rPhi_rec - rPhi_sim", - 201, -1.0, 1.0); - - _zDiffHisto = _HF->createHistogram1D("Histograms/zDiff", - "Z_rec - Z_sim", - 201, -1.0, 1.0); - - _zPullHisto = _HF->createHistogram1D("Histograms/zPull", - "(z_rec - z_sim) / Sigma_z", - 201, -10.0, 10.0); - - _phiDistHisto = _HF->createHistogram1D("Histograms/phiDist", - "phi_rec - Phi_sim", - 201, -1.0, 1.0); - - _rPhiPullHisto = _HF->createHistogram1D("Histograms/rPhiPull", - "(rPhi_rec - rPhi_sim) / Sigma_rPhi", - 201, -10.0, 10.0); - - _zSigmaVsZHisto = _HF->createHistogram2D("Histograms/zSigmaVsZ", - "z Sigma vs Z ", - 3000, 0.0, 3000.0, - 201, -0.20, 5.20); - - _zSigmaHisto = _HF->createHistogram1D("Histograms/zSigma", - "z Sigma ", - 201, -0.20, 5.20); - - _rPhiSigmaHisto = _HF->createHistogram1D("Histograms/rPhiSigma", - "rPhi Sigma", - 201, -0.20, 0.20); - + + _phiDiffHisto = _HF->createHistogram1D("Histograms/phi_diff", "Calculated Phi - Track Phi", 201, -0.05, 0.05); + + _thetaDiffHisto = _HF->createHistogram1D("Histograms/theta_diff", "Calculated Theta - Track Theta", 201, -0.05, 0.05); + + _phiRelHisto = _HF->createHistogram1D("Histograms/padPhi", "Phi Relative to the Pad", 201, 0.0, 6.3); + + _thetaRelHisto = _HF->createHistogram1D("Histograms/padtheta", "Theta Relative to the pad", 201, 0.0, 6.3); + + _rPhiDiffHisto = _HF->createHistogram1D("Histograms/rPhiDiff", "rPhi_rec - rPhi_sim", 201, -1.0, 1.0); + + _zDiffHisto = _HF->createHistogram1D("Histograms/zDiff", "Z_rec - Z_sim", 201, -1.0, 1.0); + + _zPullHisto = _HF->createHistogram1D("Histograms/zPull", "(z_rec - z_sim) / Sigma_z", 201, -10.0, 10.0); + + _phiDistHisto = _HF->createHistogram1D("Histograms/phiDist", "phi_rec - Phi_sim", 201, -1.0, 1.0); + + _rPhiPullHisto = + _HF->createHistogram1D("Histograms/rPhiPull", "(rPhi_rec - rPhi_sim) / Sigma_rPhi", 201, -10.0, 10.0); + + _zSigmaVsZHisto = + _HF->createHistogram2D("Histograms/zSigmaVsZ", "z Sigma vs Z ", 3000, 0.0, 3000.0, 201, -0.20, 5.20); + + _zSigmaHisto = _HF->createHistogram1D("Histograms/zSigma", "z Sigma ", 201, -0.20, 5.20); + + _rPhiSigmaHisto = _HF->createHistogram1D("Histograms/rPhiSigma", "rPhi Sigma", 201, -0.20, 0.20); + _radiusCheckHisto = _HF->createHistogram1D("Histograms/radiusCheck", - "R_hit - TPC Rmin - ((RowIndex + 0.5 )* padheight)", - 201, -0.20, 0.20); - - _ResidualsRPhiHisto = _HF->createHistogram1D("Histograms/ResidualsRPhi", - "MC Track Phi - Hit Phi", - 50, -0.001, 0.001); - - _NSimTPCHitsHisto = _HF->createHistogram1D("Histograms/SimTPCHits", - "Number of SimTPC Hits", - 100, 0.0, 1000000.0); - + "R_hit - TPC Rmin - ((RowIndex + 0.5 )* padheight)", 201, -0.20, 0.20); + + _ResidualsRPhiHisto = _HF->createHistogram1D("Histograms/ResidualsRPhi", "MC Track Phi - Hit Phi", 50, -0.001, 0.001); + + _NSimTPCHitsHisto = _HF->createHistogram1D("Histograms/SimTPCHits", "Number of SimTPC Hits", 100, 0.0, 1000000.0); + _NBackgroundSimTPCHitsHisto = _HF->createHistogram1D("Histograms/NBackgroundSimTPCHits", - "Number of Background SimTPC Hits", - 100, 0.0, 1000000.0); - - _NPhysicsSimTPCHitsHisto = _HF->createHistogram1D("Histograms/NPhysicsSimTPCHits", - "Number of PhysicsSimTPC Hits", - 100, 0.0, 100000.0); - - _NPhysicsAbove02GeVSimTPCHitsHisto = _HF->createHistogram1D("Histograms/NPhysicsAbove02GeVTPCHits", - "Number of PhysicsSimTPC Hits above 0.2GeV pt", - 100, 0.0, 100000.0); - - _NPhysicsAbove1GeVSimTPCHitsHisto = _HF->createHistogram1D("Histograms/NPhysicsAbove1GeVPtTPCHits", - "Number of PhysicsSimTPC Hits above 1.0 GeV pt", - 100, 0.0, 100000.0); - - _NRecTPCHitsHisto = _HF->createHistogram1D("Histograms/NRecTPCHits", - "Number of Rec TPC Hits", - 50, 0.0, 100000.0); - - _NLostPhysicsTPCHitsHisto = _HF->createHistogram1D("Histograms/NLostPhysicsTPCHits", - "Number of PhysicsSimTPC Hits Lost", - 100, 0.0, 5000.0); - - _NLostPhysicsAbove02GeVPtTPCHitsHisto = _HF->createHistogram1D("Histograms/NLostPhysicsAbove02GeVPtTPCHits", - "Number of PhysicsSimTPC Hits Lost above 0.2 GeV pt", - 100, 0.0, 5000.0); - - _NLostPhysicsAbove1GeVPtTPCHitsHisto = _HF->createHistogram1D("Histograms/NLostPhysicsAbove1GeVPtTPCHits", - "Number of PhysicsSimTPC Hits Lost above 1.0 GeV pt", - 100, 0.0, 1000.0); - - _NRevomedHitsHisto = _HF->createHistogram1D("Histograms/NRevomedHits", - "Number of Removed TPC hits", - 100, 0.0, 1000000.0); - - + "Number of Background SimTPC Hits", 100, 0.0, 1000000.0); + + _NPhysicsSimTPCHitsHisto = + _HF->createHistogram1D("Histograms/NPhysicsSimTPCHits", "Number of PhysicsSimTPC Hits", 100, 0.0, 100000.0); + + _NPhysicsAbove02GeVSimTPCHitsHisto = _HF->createHistogram1D( + "Histograms/NPhysicsAbove02GeVTPCHits", "Number of PhysicsSimTPC Hits above 0.2GeV pt", 100, 0.0, 100000.0); + + _NPhysicsAbove1GeVSimTPCHitsHisto = _HF->createHistogram1D( + "Histograms/NPhysicsAbove1GeVPtTPCHits", "Number of PhysicsSimTPC Hits above 1.0 GeV pt", 100, 0.0, 100000.0); + + _NRecTPCHitsHisto = _HF->createHistogram1D("Histograms/NRecTPCHits", "Number of Rec TPC Hits", 50, 0.0, 100000.0); + + _NLostPhysicsTPCHitsHisto = + _HF->createHistogram1D("Histograms/NLostPhysicsTPCHits", "Number of PhysicsSimTPC Hits Lost", 100, 0.0, 5000.0); + + _NLostPhysicsAbove02GeVPtTPCHitsHisto = + _HF->createHistogram1D("Histograms/NLostPhysicsAbove02GeVPtTPCHits", + "Number of PhysicsSimTPC Hits Lost above 0.2 GeV pt", 100, 0.0, 5000.0); + + _NLostPhysicsAbove1GeVPtTPCHitsHisto = + _HF->createHistogram1D("Histograms/NLostPhysicsAbove1GeVPtTPCHits", + "Number of PhysicsSimTPC Hits Lost above 1.0 GeV pt", 100, 0.0, 1000.0); + + _NRevomedHitsHisto = + _HF->createHistogram1D("Histograms/NRevomedHits", "Number of Removed TPC hits", 100, 0.0, 1000000.0); + _NKeptPhysicsTPCHitsHistoPercent = _HF->createHistogram1D("Histograms/NKeptPhysicsTPCHitsPercent", - "Number of PhysicsSimTPC Hits Kept", - 303, 0.0, 1.01); - - _NKeptPhysicsAbove02GeVPtTPCHitsHistoPercent = _HF->createHistogram1D("Histograms/NKeptPhysicsAbove02GeVPtTPCHitsPercent", - "Number of PhysicsSimTPC Hits Kept above 0.2 GeV pt", - 303, 0.0, 1.01); - - _NKeptPhysicsAbove1GeVPtTPCHitsHistoPercent = _HF->createHistogram1D("Histograms/NKeptPhysicsAbove1GeVPtTPCHitsPercent", - "Number of PhysicsSimTPC Hits Kept above 1.0 GeV pt", - 303, 0.0, 1.01); - -#endif - - + "Number of PhysicsSimTPC Hits Kept", 303, 0.0, 1.01); + + _NKeptPhysicsAbove02GeVPtTPCHitsHistoPercent = + _HF->createHistogram1D("Histograms/NKeptPhysicsAbove02GeVPtTPCHitsPercent", + "Number of PhysicsSimTPC Hits Kept above 0.2 GeV pt", 303, 0.0, 1.01); + + _NKeptPhysicsAbove1GeVPtTPCHitsHistoPercent = + _HF->createHistogram1D("Histograms/NKeptPhysicsAbove1GeVPtTPCHitsPercent", + "Number of PhysicsSimTPC Hits Kept above 1.0 GeV pt", 303, 0.0, 1.01); + +#endif + //--- get the geometry data from dd4hep dd4hep::Detector& theDet = dd4hep::Detector::getInstance(); - dd4hep::DetElement tpcDE = theDet.detector("TPC") ; - _tpc = tpcDE.extension() ; - + dd4hep::DetElement tpcDE = theDet.detector("TPC"); + _tpc = tpcDE.extension(); // fill the data for the TPC endplate - _tpcEP = new TPCModularEndplate( _tpc ) ; + _tpcEP = new TPCModularEndplate(_tpc); - if( _tpcEndPlateModuleNumbers.size() != _tpcEndPlateModulePhi0s.size() ){ + if (_tpcEndPlateModuleNumbers.size() != _tpcEndPlateModulePhi0s.size()) { - throw Exception(" DDTPCDigiProcessor: parameters tpcEndPlateModuleNumbers and tpcEndPlateModulePhi0s dont have the same number of elements ( module rings ) !! " ) ; + throw Exception(" DDTPCDigiProcessor: parameters tpcEndPlateModuleNumbers and tpcEndPlateModulePhi0s dont have the " + "same number of elements ( module rings ) !! "); } - for(unsigned i=0,N=_tpcEndPlateModuleNumbers.size() ; iaddModuleRing( _tpcEndPlateModuleNumbers[i] , _tpcEndPlateModulePhi0s[i] ) ; + _tpcEP->addModuleRing(_tpcEndPlateModuleNumbers[i], _tpcEndPlateModulePhi0s[i]); } - _tpcEP->initialize() ; + _tpcEP->initialize(); // ----- + streamlog_out(DEBUG6) << " initialized TPC geometry from TPCData: " << *_tpc << std::endl; - - streamlog_out( DEBUG6 ) << " initialized TPC geometry from TPCData: " << *_tpc << std::endl ; - - double bfieldV[3] ; - theDet.field().magneticField( { 0., 0., 0. } , bfieldV ) ; - _bField = bfieldV[2]/dd4hep::tesla ; + double bfieldV[3]; + theDet.field().magneticField({0., 0., 0.}, bfieldV); + _bField = bfieldV[2] / dd4hep::tesla; //---- - - printParameters() ; - - //intialise random number generator + printParameters(); + + // intialise random number generator _random = gsl_rng_alloc(gsl_rng_ranlxs2); marlin::Global::EVENTSEEDER->registerProcessor(this); - - _cellid_encoder = 0 ; - _nRun = 0 ; - _nEvt = 0 ; - + + _cellid_encoder = 0; + _nRun = 0; + _nEvt = 0; } -void DDTPCDigiProcessor::processRunHeader( LCRunHeader* ) -{ - _nRun++ ; -} +void DDTPCDigiProcessor::processRunHeader(LCRunHeader*) { _nRun++; } + +void DDTPCDigiProcessor::processEvent(LCEvent* evt) { -void DDTPCDigiProcessor::processEvent( LCEvent * evt ) -{ - - gsl_rng_set( _random, marlin::Global::EVENTSEEDER->getSeed(this) ) ; - streamlog_out( DEBUG ) << "seed set to " << marlin::Global::EVENTSEEDER->getSeed(this) << " for event number "<< evt->getEventNumber() << std::endl; + gsl_rng_set(_random, marlin::Global::EVENTSEEDER->getSeed(this)); + streamlog_out(DEBUG) << "seed set to " << marlin::Global::EVENTSEEDER->getSeed(this) << " for event number " + << evt->getEventNumber() << std::endl; + + int numberOfVoxelsCreated(0); - int numberOfVoxelsCreated(0); - _NSimTPCHits = 0; _NBackgroundSimTPCHits = 0; _NPhysicsSimTPCHits = 0; _NPhysicsAbove02GeVSimTPCHits = 0; _NPhysicsAbove1GeVSimTPCHits = 0; _NRecTPCHits = 0; - + _NLostPhysicsTPCHits = 0; _NLostPhysicsAbove02GeVPtTPCHits = 0; _NLostPhysicsAbove1GeVPtTPCHits = 0; _NRevomedHits = 0; - + static bool firstEvent = true; _tpcHitMap.clear(); _tpcRowHits.clear(); - - streamlog_out(DEBUG8) << " ========= processing event " - << std::setw(9) << evt->getEventNumber() << " run " - << std::setw(9) << evt->getRunNumber() - << " ========= " << endl; + streamlog_out(DEBUG8) << " ========= processing event " << std::setw(9) << evt->getEventNumber() << " run " + << std::setw(9) << evt->getRunNumber() << " ========= " << endl; - if(firstEvent==true) { - if (! _use_raw_hits_to_store_simhit_pointer ) { + if (firstEvent == true) { + if (!_use_raw_hits_to_store_simhit_pointer) { - streamlog_out( DEBUG4 ) << "The relations to SimTrackerHits are now stored in relation collection " << _outRelColName << "\n SimTrackerHits are no longer stored in RawTrackerHits. Enable this deprecated feature by setting UseRawHitsToStoreSimhitPointer to true in steering file." << std::endl; + streamlog_out(DEBUG4) << "The relations to SimTrackerHits are now stored in relation collection " + << _outRelColName + << "\n SimTrackerHits are no longer stored in RawTrackerHits. Enable this deprecated " + "feature by setting UseRawHitsToStoreSimhitPointer to true in steering file." + << std::endl; - } - else{ - - streamlog_out( DEBUG4 ) << "SimTrackerHits will be stored in RawTrackerHits. This is a deprecated please use the relations stored in " << _outRelColName << std::endl; - - } - + } else { + streamlog_out(DEBUG4) + << "SimTrackerHits will be stored in RawTrackerHits. This is a deprecated please use the relations stored in " + << _outRelColName << std::endl; + } } - - firstEvent = false ; - - _padWidth = _tpc->padWidth/dd4hep::mm; + firstEvent = false; + + _padWidth = _tpc->padWidth / dd4hep::mm; // set size of row_hits to hold (n_rows) vectors - _tpcRowHits.resize( _tpc->maxRow ); - - // created the collection which will be written out - _trkhitVec = new LCCollectionVec( LCIO::TRACKERHIT ) ; + _tpcRowHits.resize(_tpc->maxRow); + + // created the collection which will be written out + _trkhitVec = new LCCollectionVec(LCIO::TRACKERHIT); // relations from created trackerhits to the SimTrackerHits that caused them auto hitSimHitNav = UTIL::LCRelationNavigator(LCIO::TRACKERHIT, LCIO::SIMTRACKERHIT); - _cellid_encoder = new CellIDEncoder( lcio::LCTrackerCellID::encoding_string() , _trkhitVec ) ; - - // first deal with the pad-row based hits from Mokka - LCCollection* STHcol = 0 ; - try{ - STHcol = evt->getCollection( _padRowHitColName ) ; - } - catch(DataNotAvailableException &e){ + _cellid_encoder = new CellIDEncoder(lcio::LCTrackerCellID::encoding_string(), _trkhitVec); + + // first deal with the pad-row based hits from Mokka + LCCollection* STHcol = 0; + try { + STHcol = evt->getCollection(_padRowHitColName); + } catch (DataNotAvailableException& e) { } - - float edep0=0.0; - if( STHcol != 0 ){ - - int n_sim_hits = STHcol->getNumberOfElements() ; - - LCFlagImpl colFlag( STHcol->getFlag() ) ; - + + float edep0 = 0.0; + if (STHcol != 0) { + + int n_sim_hits = STHcol->getNumberOfElements(); + + LCFlagImpl colFlag(STHcol->getFlag()); + _NSimTPCHits = n_sim_hits; - + streamlog_out(DEBUG4) << "number of Pad-Row based SimHits = " << n_sim_hits << std::endl; - - + // make sure that all the pointers are initialise to NULL - _mcp=NULL; - _previousMCP=NULL; - _nextMCP=NULL; - _nMinus2MCP=NULL; - _nPlus2MCP=NULL; - - _SimTHit=NULL; - _previousSimTHit=NULL; - _nextSimTHit=NULL; - _nMinus2SimHit=NULL; - _nPlus2SimHit=NULL; - + _mcp = NULL; + _previousMCP = NULL; + _nextMCP = NULL; + _nMinus2MCP = NULL; + _nPlus2MCP = NULL; + + _SimTHit = NULL; + _previousSimTHit = NULL; + _nextSimTHit = NULL; + _nMinus2SimHit = NULL; + _nPlus2SimHit = NULL; + // loop over all the pad row based sim hits - for(int i=0; i< n_sim_hits; i++){ - + for (int i = 0; i < n_sim_hits; i++) { + // this will used for nominaml smearing for very low pt rubish, so set it to zero initially double ptSqrdMC = 0; - - _SimTHit = dynamic_cast( STHcol->getElementAt( i ) ) ; - + + _SimTHit = dynamic_cast(STHcol->getElementAt(i)); + float edep; double padPhi(0.0); - double padTheta (0.0); - - + double padTheta(0.0); + streamlog_out(DEBUG3) << "processing hit " << i << std::endl; - streamlog_out(DEBUG3) << " address = " << _SimTHit - << " x = " << _SimTHit->getPosition()[0] - << " y = " << _SimTHit->getPosition()[1] - << " z = " << _SimTHit->getPosition()[2] - << std::endl ; - - - - CLHEP::Hep3Vector thisPoint(_SimTHit->getPosition()[0],_SimTHit->getPosition()[1],_SimTHit->getPosition()[2]); - double padheight = _tpc->padHeight/dd4hep::mm ; - + streamlog_out(DEBUG3) << " address = " << _SimTHit << " x = " << _SimTHit->getPosition()[0] + << " y = " << _SimTHit->getPosition()[1] << " z = " << _SimTHit->getPosition()[2] + << std::endl; + + CLHEP::Hep3Vector thisPoint(_SimTHit->getPosition()[0], _SimTHit->getPosition()[1], _SimTHit->getPosition()[2]); + double padheight = _tpc->padHeight / dd4hep::mm; + // conversion constant. r = pt / (FCT*_bField) const double FCT = 2.99792458E-4; - - _mcp = _SimTHit->getMCParticle() ; - + + _mcp = _SimTHit->getMCParticle(); + // increase the counters for the different classification of simhits - if(_mcp){ - + if (_mcp) { + // get the pt of the MCParticle, this will used later to uses nominal smearing for low momentum rubish - const double *momentumMC = _mcp->getMomentum(); - ptSqrdMC = momentumMC[0]*momentumMC[0]+momentumMC[1]*momentumMC[1] ; - - streamlog_out(DEBUG3) << " mcp address = " << _mcp - << " px = " << momentumMC[0] - << " py = " << momentumMC[1] - << " pz = " << momentumMC[2] - << std::endl ; - - // SJA:FIXME: the fact that it is a physics hit relies on the fact that for overlay + const double* momentumMC = _mcp->getMomentum(); + ptSqrdMC = momentumMC[0] * momentumMC[0] + momentumMC[1] * momentumMC[1]; + + streamlog_out(DEBUG3) << " mcp address = " << _mcp << " px = " << momentumMC[0] << " py = " << momentumMC[1] + << " pz = " << momentumMC[2] << std::endl; + + // SJA:FIXME: the fact that it is a physics hit relies on the fact that for overlay // the pointer to the mcp is set to NULL. This distinction may not always be true ... - ++_NPhysicsSimTPCHits ; - if( ptSqrdMC > (0.2*0.2) ) ++_NPhysicsAbove02GeVSimTPCHits ; - if( ptSqrdMC > 1.0 ) ++_NPhysicsAbove1GeVSimTPCHits ; - + ++_NPhysicsSimTPCHits; + if (ptSqrdMC > (0.2 * 0.2)) + ++_NPhysicsAbove02GeVSimTPCHits; + if (ptSqrdMC > 1.0) + ++_NPhysicsAbove1GeVSimTPCHits; + #ifdef DIGIPLOTS - if(_mcp) plotHelixHitResidual(_mcp, &thisPoint); -#endif + if (_mcp) + plotHelixHitResidual(_mcp, &thisPoint); +#endif } else { ++_NBackgroundSimTPCHits; } - - // if the hits contain the momentum of the particle use this to calculate the angles relative to the pad - if(colFlag.bitSet(LCIO::THBIT_MOMENTUM)) { - - const float * mcpMomentum = _SimTHit->getMomentum() ; - - CLHEP::Hep3Vector mom(mcpMomentum[0],mcpMomentum[1],mcpMomentum[2]); - + + // if the hits contain the momentum of the particle use this to calculate the angles relative to the pad + if (colFlag.bitSet(LCIO::THBIT_MOMENTUM)) { + + const float* mcpMomentum = _SimTHit->getMomentum(); + + CLHEP::Hep3Vector mom(mcpMomentum[0], mcpMomentum[1], mcpMomentum[2]); + // const double pt = mom.perp(); // const double radius = pt / (FCT*_bField); - + // const double tanLambda = mom.z()/pt; - + padPhi = fabs(thisPoint.deltaPhi(mom)); padTheta = mom.theta(); - - } - + + } + else { // LCIO::THBIT_MOMENTUM not set - - // as the momentum vector is not available from the hits use triplets of - // hits to fit a circle and calculate theta and phi relative to the pad - - if (!_mcp || (sqrt(ptSqrdMC) / (FCT*_bField)) < ( padheight / (0.1 * twopi))) { - // if the hit has no record of it MCParticle then there is no way to know if this hit has consecutive hits from the same MCParticle - // so just set nominal values theta=phi=90 - // here make a cut for particles which will suffer more than a 10 percent change in phi over the distance of the pad - // R > padheight/(0.1*2PI) - // in both cases set the angles to 90 degrees - padTheta = twopi/4.0 ; - padPhi = twopi/4.0 ; - } - else{ - + + // as the momentum vector is not available from the hits use triplets of + // hits to fit a circle and calculate theta and phi relative to the pad + + if (!_mcp || (sqrt(ptSqrdMC) / (FCT * _bField)) < (padheight / (0.1 * twopi))) { + // if the hit has no record of it MCParticle then there is no way to know if this hit has consecutive hits + // from the same MCParticle so just set nominal values theta=phi=90 here make a cut for particles which will + // suffer more than a 10 percent change in phi over the distance of the pad R > padheight/(0.1*2PI) in both + // cases set the angles to 90 degrees + padTheta = twopi / 4.0; + padPhi = twopi / 4.0; + } else { + // if there is at least one more hit after this one, set the pointer to the MCParticle for the next hit - if (i < (n_sim_hits-1) ) { - _nextSimTHit = dynamic_cast( STHcol->getElementAt( i+1 ) ) ; - _nextMCP = _nextSimTHit->getMCParticle() ; - } - else{ // set make sure that the pointers are set back to NULL so that the comparisons later hold + if (i < (n_sim_hits - 1)) { + _nextSimTHit = dynamic_cast(STHcol->getElementAt(i + 1)); + _nextMCP = _nextSimTHit->getMCParticle(); + } else { // set make sure that the pointers are set back to NULL so that the comparisons later hold _nextSimTHit = NULL; _nextMCP = NULL; } - // if there is at least two more hits after this one, set the pointer to the MCParticle for the next but one hit - if (i < (n_sim_hits-2) ) { - _nPlus2SimHit = dynamic_cast( STHcol->getElementAt( i+2 )); - _nPlus2MCP = _nPlus2SimHit->getMCParticle() ; - } - else{ // set make sure that the pointers are set back to NULL so that the comparisons later hold + // if there is at least two more hits after this one, set the pointer to the MCParticle for the next but one + // hit + if (i < (n_sim_hits - 2)) { + _nPlus2SimHit = dynamic_cast(STHcol->getElementAt(i + 2)); + _nPlus2MCP = _nPlus2SimHit->getMCParticle(); + } else { // set make sure that the pointers are set back to NULL so that the comparisons later hold _nPlus2SimHit = NULL; _nPlus2MCP = NULL; } - - if ( _mcp==_previousMCP && _mcp==_nextMCP ) { // middle hit of 3 from the same MCParticle - - CLHEP::Hep3Vector precedingPoint(_previousSimTHit->getPosition()[0],_previousSimTHit->getPosition()[1],_previousSimTHit->getPosition()[2]) ; - CLHEP::Hep3Vector followingPoint(_nextSimTHit->getPosition()[0],_nextSimTHit->getPosition()[1],_nextSimTHit->getPosition()[2]) ; - - streamlog_out(DEBUG3) << "address of _previousSimTHit = " << _previousSimTHit - << " x = " << _previousSimTHit->getPosition()[0] - << " y = " << _previousSimTHit->getPosition()[1] - << " z = " << _previousSimTHit->getPosition()[2] - << std::endl ; - - streamlog_out(DEBUG4) << "address of _nextSimTHit = " << _nextSimTHit - << " x = " << _nextSimTHit->getPosition()[0] - << " y = " << _nextSimTHit->getPosition()[1] - << " z = " << _nextSimTHit->getPosition()[2] - << std::endl ; - + + if (_mcp == _previousMCP && _mcp == _nextMCP) { // middle hit of 3 from the same MCParticle + + CLHEP::Hep3Vector precedingPoint(_previousSimTHit->getPosition()[0], _previousSimTHit->getPosition()[1], + _previousSimTHit->getPosition()[2]); + CLHEP::Hep3Vector followingPoint(_nextSimTHit->getPosition()[0], _nextSimTHit->getPosition()[1], + _nextSimTHit->getPosition()[2]); + + streamlog_out(DEBUG3) << "address of _previousSimTHit = " << _previousSimTHit + << " x = " << _previousSimTHit->getPosition()[0] + << " y = " << _previousSimTHit->getPosition()[1] + << " z = " << _previousSimTHit->getPosition()[2] << std::endl; + + streamlog_out(DEBUG4) << "address of _nextSimTHit = " << _nextSimTHit + << " x = " << _nextSimTHit->getPosition()[0] + << " y = " << _nextSimTHit->getPosition()[1] + << " z = " << _nextSimTHit->getPosition()[2] << std::endl; + // get phi and theta using functions defined below - padPhi = getPadPhi( &thisPoint, &precedingPoint, &thisPoint, &followingPoint); + padPhi = getPadPhi(&thisPoint, &precedingPoint, &thisPoint, &followingPoint); padTheta = getPadTheta(&precedingPoint, &thisPoint, &followingPoint); - - } - else if ( _mcp==_nextMCP && _mcp==_nPlus2MCP ) { // first hit of 3 from the same MCParticle - - CLHEP::Hep3Vector followingPoint(_nextSimTHit->getPosition()[0],_nextSimTHit->getPosition()[1],_nextSimTHit->getPosition()[2]) ; - CLHEP::Hep3Vector nPlus2Point(_nPlus2SimHit->getPosition()[0],_nPlus2SimHit->getPosition()[1],_nPlus2SimHit->getPosition()[2]) ; - + + } else if (_mcp == _nextMCP && _mcp == _nPlus2MCP) { // first hit of 3 from the same MCParticle + + CLHEP::Hep3Vector followingPoint(_nextSimTHit->getPosition()[0], _nextSimTHit->getPosition()[1], + _nextSimTHit->getPosition()[2]); + CLHEP::Hep3Vector nPlus2Point(_nPlus2SimHit->getPosition()[0], _nPlus2SimHit->getPosition()[1], + _nPlus2SimHit->getPosition()[2]); + // get phi and theta using functions defined below - padPhi = getPadPhi( &thisPoint, &thisPoint, &followingPoint, &nPlus2Point); + padPhi = getPadPhi(&thisPoint, &thisPoint, &followingPoint, &nPlus2Point); padTheta = getPadTheta(&thisPoint, &followingPoint, &nPlus2Point); - - } - else if ( _mcp==_previousMCP && _mcp==_nMinus2MCP ) { // last hit of 3 from the same MCParticle - - CLHEP::Hep3Vector nMinus2Point(_nMinus2SimHit->getPosition()[0],_nMinus2SimHit->getPosition()[1],_nMinus2SimHit->getPosition()[2]); - CLHEP::Hep3Vector precedingPoint(_previousSimTHit->getPosition()[0],_previousSimTHit->getPosition()[1],_previousSimTHit->getPosition()[2]); - + + } else if (_mcp == _previousMCP && _mcp == _nMinus2MCP) { // last hit of 3 from the same MCParticle + + CLHEP::Hep3Vector nMinus2Point(_nMinus2SimHit->getPosition()[0], _nMinus2SimHit->getPosition()[1], + _nMinus2SimHit->getPosition()[2]); + CLHEP::Hep3Vector precedingPoint(_previousSimTHit->getPosition()[0], _previousSimTHit->getPosition()[1], + _previousSimTHit->getPosition()[2]); + // get phi and theta using functions defined below - padPhi = getPadPhi( &thisPoint, &nMinus2Point, &precedingPoint, &thisPoint); + padPhi = getPadPhi(&thisPoint, &nMinus2Point, &precedingPoint, &thisPoint); padTheta = getPadTheta(&nMinus2Point, &precedingPoint, &thisPoint); - - } - else{ // the hit is isolated as either a single hit, or a pair of hits, from a single MCParticle - padTheta = twopi/4.0 ; - padPhi = twopi/4.0 ; + + } else { // the hit is isolated as either a single hit, or a pair of hits, from a single MCParticle + padTheta = twopi / 4.0; + padPhi = twopi / 4.0; } } - + #ifdef DIGIPLOTS - if(colFlag.bitSet(LCIO::THBIT_MOMENTUM)) { - - const float * mcpMomentum = _SimTHit->getMomentum() ; - - CLHEP::Hep3Vector mom(mcpMomentum[0],mcpMomentum[1],mcpMomentum[2]); - + if (colFlag.bitSet(LCIO::THBIT_MOMENTUM)) { + + const float* mcpMomentum = _SimTHit->getMomentum(); + + CLHEP::Hep3Vector mom(mcpMomentum[0], mcpMomentum[1], mcpMomentum[2]); + double trackPhi = mom.phi(); - - if(trackPhi<0.0) trackPhi=trackPhi+twopi; - if(trackPhi>twopi) trackPhi=trackPhi-twopi; - if(trackPhi>twopi/2.0) trackPhi = trackPhi - twopi/2.0 ; - + + if (trackPhi < 0.0) + trackPhi = trackPhi + twopi; + if (trackPhi > twopi) + trackPhi = trackPhi - twopi; + if (trackPhi > twopi / 2.0) + trackPhi = trackPhi - twopi / 2.0; + double localPhi = thisPoint.phi() - padPhi; - + _phiRelHisto->fill(padPhi); - _phiDiffHisto->fill((fabs(localPhi - trackPhi))/trackPhi); + _phiDiffHisto->fill((fabs(localPhi - trackPhi)) / trackPhi); _thetaRelHisto->fill(padTheta); - _thetaDiffHisto->fill( (sin(padTheta) - sin(mom.theta()))/sin(mom.theta()) ); - - streamlog_out(DEBUG3) << "track Phi = " << trackPhi * (360.0 / twopi) << endl; - streamlog_out(DEBUG3) << "localPhi = " << localPhi * (360.0 / twopi) << endl; - streamlog_out(DEBUG3) << "pad Phi = " << padPhi * (360.0 / twopi) << endl; - streamlog_out(DEBUG3) << "pad Phi from track mom = " << ( thisPoint.phi() - trackPhi ) * (360.0 / twopi) << endl; - streamlog_out(DEBUG3) << "padTheta = " << padTheta * (360.0 / twopi) << endl; - streamlog_out(DEBUG3) << "padTheta from track mom = " << mom.theta() * (360.0 / twopi) << endl; - + _thetaDiffHisto->fill((sin(padTheta) - sin(mom.theta())) / sin(mom.theta())); + + streamlog_out(DEBUG3) << "track Phi = " << trackPhi * (360.0 / twopi) << endl; + streamlog_out(DEBUG3) << "localPhi = " << localPhi * (360.0 / twopi) << endl; + streamlog_out(DEBUG3) << "pad Phi = " << padPhi * (360.0 / twopi) << endl; + streamlog_out(DEBUG3) << "pad Phi from track mom = " << (thisPoint.phi() - trackPhi) * (360.0 / twopi) + << endl; + streamlog_out(DEBUG3) << "padTheta = " << padTheta * (360.0 / twopi) << endl; + streamlog_out(DEBUG3) << "padTheta from track mom = " << mom.theta() * (360.0 / twopi) << endl; } -#endif - +#endif } - + // int pad = padLayout.getNearestPad(thisPoint.perp(),thisPoint.phi()); int layerNumber = _SimTHit->getCellID0(); - - if(_rejectCellID0 && (layerNumber<1)) { + + if (_rejectCellID0 && (layerNumber < 1)) { continue; } - + edep = _SimTHit->getEDep(); - - // Calculate Point Resolutions according to Ron's Formula - + + // Calculate Point Resolutions according to Ron's Formula + // sigma_{RPhi}^2 = sigma_0^2 + Cd^2/N_{eff} * L_{drift} - + // sigma_0^2 = (50micron)^2 + (900micron*sin(phi))^2 // Cd^2/N_{eff}} = 25^2/(22/sin(theta)*h/6mm) // Cd = 25 ( microns / cm^(1/2) ) // (this is for B=4T, h is the pad height = pad-row pitch in mm, - // theta is the polar angle) - - // sigma_{z}^2 = (400microns)^2 + L_{drift}cm * (80micron/sqrt(cm))^2 - - double aReso =_pointResoRPhi0*_pointResoRPhi0 + (_pointResoPadPhi*_pointResoPadPhi * sin(padPhi)*sin(padPhi)) ; - double driftLength = _tpc->driftLength/dd4hep::mm - (fabs(thisPoint.z())); - - if (driftLength <0) { - streamlog_out(DEBUG3) << " DDTPCDigiProcessor : Warning! driftLength < 0 " << driftLength << " --> wrong data in dd4hep::rec::FixedPadSizeTPCData ? " << std::endl; + // theta is the polar angle) + + // sigma_{z}^2 = (400microns)^2 + L_{drift}cm * (80micron/sqrt(cm))^2 + + double aReso = + _pointResoRPhi0 * _pointResoRPhi0 + (_pointResoPadPhi * _pointResoPadPhi * sin(padPhi) * sin(padPhi)); + double driftLength = _tpc->driftLength / dd4hep::mm - (fabs(thisPoint.z())); + + if (driftLength < 0) { + streamlog_out(DEBUG3) << " DDTPCDigiProcessor : Warning! driftLength < 0 " << driftLength + << " --> wrong data in dd4hep::rec::FixedPadSizeTPCData ? " << std::endl; streamlog_out(DEBUG3) << "Setting driftLength to 0.1" << std::endl; - streamlog_out(DEBUG3) << "_tpc->driftLength/dd4hep::mm = " << _tpc->driftLength/dd4hep::mm << std::endl; + streamlog_out(DEBUG3) << "_tpc->driftLength/dd4hep::mm = " << _tpc->driftLength / dd4hep::mm << std::endl; driftLength = 0.10; } - - padheight = _tpc->padHeight/dd4hep::mm ; - - //double bReso = ( (_diffRPhi * _diffRPhi) / _nEff ) * sin(padTheta) * ( 6.0 / (padheight) ) * ( 4.0 / _bField ) ; - // formula with new quadratic B-field correction term - double bReso = ( (_diffRPhi * _diffRPhi) / _nEff ) * sin(padTheta) * ( 6.0 / (padheight) ) * ( (4.0 * 4.0) / (_bField * _bField) ) ; - - double tpcRPhiRes = sqrt( aReso + bReso * (driftLength / 10.0) ); // driftLength in cm - - double tpcZRes = sqrt(( _pointResoZ0 * _pointResoZ0 ) - + - ( _diffZ * _diffZ ) * (driftLength / 10.0) ); // driftLength in cm - - FixedPadSizeDiskLayout padLayout( _tpc ); - int padIndex = padLayout.getNearestPad(thisPoint.perp(),thisPoint.phi()); - - double TPCPadPlaneRMin = _tpc->rMinReadout/dd4hep::mm ; - double TPCPadPlaneRMax = _tpc->rMaxReadout/dd4hep::mm ; - + + padheight = _tpc->padHeight / dd4hep::mm; + + // double bReso = ( (_diffRPhi * _diffRPhi) / _nEff ) * sin(padTheta) * ( 6.0 / (padheight) ) * ( 4.0 / _bField + // ) ; + // formula with new quadratic B-field correction term + double bReso = + ((_diffRPhi * _diffRPhi) / _nEff) * sin(padTheta) * (6.0 / (padheight)) * ((4.0 * 4.0) / (_bField * _bField)); + + double tpcRPhiRes = sqrt(aReso + bReso * (driftLength / 10.0)); // driftLength in cm + + double tpcZRes = + sqrt((_pointResoZ0 * _pointResoZ0) + (_diffZ * _diffZ) * (driftLength / 10.0)); // driftLength in cm + + FixedPadSizeDiskLayout padLayout(_tpc); + int padIndex = padLayout.getNearestPad(thisPoint.perp(), thisPoint.phi()); + + double TPCPadPlaneRMin = _tpc->rMinReadout / dd4hep::mm; + double TPCPadPlaneRMax = _tpc->rMaxReadout / dd4hep::mm; + int iRowHit = padLayout.getRowNumber(padIndex); int iPhiHit = padLayout.getPadNumber(padIndex); - int NBinsZ = (int) ((2.0 * _tpc->driftLength/dd4hep::mm) / _binningZ); - int iZHit = (int) ( (float) NBinsZ * ( _tpc->driftLength/dd4hep::mm + thisPoint.z() ) / ( 2.0 * _tpc->driftLength/dd4hep::mm ) ) ; - - if(iZHit<0) iZHit=0; - if(iZHit>NBinsZ) iZHit=NBinsZ; - + int NBinsZ = (int)((2.0 * _tpc->driftLength / dd4hep::mm) / _binningZ); + int iZHit = (int)((float)NBinsZ * (_tpc->driftLength / dd4hep::mm + thisPoint.z()) / + (2.0 * _tpc->driftLength / dd4hep::mm)); + + if (iZHit < 0) + iZHit = 0; + if (iZHit > NBinsZ) + iZHit = NBinsZ; + // make sure that the hit lies at the middle of the pad ring thisPoint.setPerp(padLayout.getPadCenter(padIndex)[0]); - - if( (thisPoint.perp() < TPCPadPlaneRMin) || (thisPoint.perp() > TPCPadPlaneRMax) ) { + + if ((thisPoint.perp() < TPCPadPlaneRMin) || (thisPoint.perp() > TPCPadPlaneRMax)) { streamlog_out(DEBUG3) << "Hit R not in TPC " << endl; - streamlog_out(DEBUG3) << "R = " << thisPoint.perp() << endl; + streamlog_out(DEBUG3) << "R = " << thisPoint.perp() << endl; streamlog_out(DEBUG3) << "the tpc InnerRadius = " << TPCPadPlaneRMin << endl; streamlog_out(DEBUG3) << "the tpc OuterRadius = " << TPCPadPlaneRMax << endl; streamlog_out(DEBUG3) << "Hit Dropped " << endl; continue; } - - if( (fabs(thisPoint.z()) > _tpc->driftLength/dd4hep::mm) ) { + + if ((fabs(thisPoint.z()) > _tpc->driftLength / dd4hep::mm)) { streamlog_out(DEBUG3) << "Hit Z not in TPC " << endl; - streamlog_out(DEBUG3) << "Z = " << thisPoint.z() << endl; - streamlog_out(DEBUG3) << "the tpc Max Z = " << _tpc->driftLength/dd4hep::mm << endl; + streamlog_out(DEBUG3) << "Z = " << thisPoint.z() << endl; + streamlog_out(DEBUG3) << "the tpc Max Z = " << _tpc->driftLength / dd4hep::mm << endl; streamlog_out(DEBUG3) << "Hit Dropped " << endl; - continue; + continue; } - - //get energy deposit of this row - edep=_SimTHit->getEDep(); + + // get energy deposit of this row + edep = _SimTHit->getEDep(); // create a tpc voxel hit and store it for this row - Voxel_tpc * atpcVoxel = new Voxel_tpc(iRowHit,iPhiHit,iZHit, thisPoint, edep, tpcRPhiRes, tpcZRes); - + Voxel_tpc* atpcVoxel = new Voxel_tpc(iRowHit, iPhiHit, iZHit, thisPoint, edep, tpcRPhiRes, tpcZRes); + _tpcRowHits.at(iRowHit).push_back(atpcVoxel); ++numberOfVoxelsCreated; - + // store the simhit pointer for this tpcvoxel hit in the hit map - _tpcHitMap[atpcVoxel] = _SimTHit; - - // move the pointers on + _tpcHitMap[atpcVoxel] = _SimTHit; + + // move the pointers on _nMinus2MCP = _previousMCP; - _previousMCP = _mcp ; + _previousMCP = _mcp; _nMinus2SimHit = _previousSimTHit; _previousSimTHit = _SimTHit; - } } - + // now process the LowPt collection - LCCollection* STHcolLowPt = 0 ; - try{ - STHcolLowPt = evt->getCollection( _lowPtHitscolName ) ; - } - catch(DataNotAvailableException &e){ + LCCollection* STHcolLowPt = 0; + try { + STHcolLowPt = evt->getCollection(_lowPtHitscolName); + } catch (DataNotAvailableException& e) { } - - if(STHcolLowPt!=NULL){ - - int n_sim_hitsLowPt = STHcolLowPt->getNumberOfElements() ; - + + if (STHcolLowPt != NULL) { + + int n_sim_hitsLowPt = STHcolLowPt->getNumberOfElements(); + _NBackgroundSimTPCHits += n_sim_hitsLowPt; _NSimTPCHits += n_sim_hitsLowPt; - + streamlog_out(DEBUG4) << "number of LowPt hits:" << n_sim_hitsLowPt << std::endl; - + // loop over the LowPt hit collection - for(int i=0; i< n_sim_hitsLowPt; i++){ - - _SimTHit = dynamic_cast( STHcolLowPt->getElementAt( i ) ) ; - - CLHEP::Hep3Vector thisPoint(_SimTHit->getPosition()[0],_SimTHit->getPosition()[1],_SimTHit->getPosition()[2]); - - FixedPadSizeDiskLayout padLayout( _tpc ); - const std::vector& planeExt = padLayout.getPlaneExtent() ; - double TPCPadPlaneRMin = planeExt[0] ; - double TPCPadPlaneRMax = planeExt[1] ; - - int NBinsZ = (int) ((2.0 * _tpc->driftLength/dd4hep::mm) / _binningZ); - - if( (thisPoint.perp() < TPCPadPlaneRMin) || (thisPoint.perp() > TPCPadPlaneRMax) ) { + for (int i = 0; i < n_sim_hitsLowPt; i++) { + + _SimTHit = dynamic_cast(STHcolLowPt->getElementAt(i)); + + CLHEP::Hep3Vector thisPoint(_SimTHit->getPosition()[0], _SimTHit->getPosition()[1], _SimTHit->getPosition()[2]); + + FixedPadSizeDiskLayout padLayout(_tpc); + const std::vector& planeExt = padLayout.getPlaneExtent(); + double TPCPadPlaneRMin = planeExt[0]; + double TPCPadPlaneRMax = planeExt[1]; + + int NBinsZ = (int)((2.0 * _tpc->driftLength / dd4hep::mm) / _binningZ); + + if ((thisPoint.perp() < TPCPadPlaneRMin) || (thisPoint.perp() > TPCPadPlaneRMax)) { streamlog_out(DEBUG3) << "Hit R not in TPC " << endl; - streamlog_out(DEBUG3) << "R = " << thisPoint.perp() << endl; + streamlog_out(DEBUG3) << "R = " << thisPoint.perp() << endl; streamlog_out(DEBUG3) << "the tpc InnerRadius = " << TPCPadPlaneRMin << endl; streamlog_out(DEBUG3) << "the tpc OuterRadius = " << TPCPadPlaneRMax << endl; streamlog_out(DEBUG3) << "Hit Dropped " << endl; continue; } - - if( (fabs(thisPoint.z()) > _tpc->driftLength/dd4hep::mm) ) { + + if ((fabs(thisPoint.z()) > _tpc->driftLength / dd4hep::mm)) { streamlog_out(DEBUG3) << "Hit Z not in TPC " << endl; - streamlog_out(DEBUG3) << "Z = " << thisPoint.z() << endl; - streamlog_out(DEBUG3) << "the tpc Max Z = " << _tpc->driftLength/dd4hep::mm << endl; + streamlog_out(DEBUG3) << "Z = " << thisPoint.z() << endl; + streamlog_out(DEBUG3) << "the tpc Max Z = " << _tpc->driftLength / dd4hep::mm << endl; streamlog_out(DEBUG3) << "Hit Dropped " << endl; - continue; + continue; } - - int padIndex = padLayout.getNearestPad(thisPoint.perp(),thisPoint.phi()); - + + int padIndex = padLayout.getNearestPad(thisPoint.perp(), thisPoint.phi()); + int iRowHit = padLayout.getRowNumber(padIndex); int iPhiHit = padLayout.getPadNumber(padIndex); - int iZHit = (int) ( (float) NBinsZ * - ( _tpc->driftLength/dd4hep::mm + thisPoint.z() ) / ( 2.0 * _tpc->driftLength/dd4hep::mm ) ) ; - - // shift the hit in r-phi to the nearest pad-row centre + int iZHit = (int)((float)NBinsZ * (_tpc->driftLength / dd4hep::mm + thisPoint.z()) / + (2.0 * _tpc->driftLength / dd4hep::mm)); + + // shift the hit in r-phi to the nearest pad-row centre thisPoint.setPerp(padLayout.getPadCenter(padIndex)[0]); - + // set the resolutions to the pads to digital like values double tpcRPhiRes = _padWidth; double tpcZRes = _binningZ; - - //get energy deposit of this hit - edep0 =_SimTHit->getEDep(); - // create a tpc voxel hit for this simhit and store it for this tpc pad row - Voxel_tpc * atpcVoxel = new Voxel_tpc(iRowHit,iPhiHit,iZHit, thisPoint, edep0, tpcRPhiRes, tpcZRes); - + // get energy deposit of this hit + edep0 = _SimTHit->getEDep(); + + // create a tpc voxel hit for this simhit and store it for this tpc pad row + Voxel_tpc* atpcVoxel = new Voxel_tpc(iRowHit, iPhiHit, iZHit, thisPoint, edep0, tpcRPhiRes, tpcZRes); + _tpcRowHits.at(iRowHit).push_back(atpcVoxel); - ++numberOfVoxelsCreated; - + ++numberOfVoxelsCreated; + // store the simhit pointer for this voxel hit in a map - _tpcHitMap[atpcVoxel] = _SimTHit; - + _tpcHitMap[atpcVoxel] = _SimTHit; } } - + int number_of_adjacent_hits(0); - + streamlog_out(DEBUG4) << "finished looping over simhits, number of voxels = " << numberOfVoxelsCreated << endl; - + int numberOfhitsTreated(0); - - vector row_hits; - + + vector row_hits; + // loop over the tpc rows containing hits and check for merged hits - for (unsigned int i = 0; i<_tpcRowHits.size(); ++i){ - + for (unsigned int i = 0; i < _tpcRowHits.size(); ++i) { + row_hits = _tpcRowHits.at(i); - std::sort(row_hits.begin(), row_hits.end(), compare_phi ); - - // double loop over the hits in this row - for (unsigned int j = 0; jgetPhiIndex() > (row_hits[j]->getPhiIndex())+2){ // SJA:FIXME: here we need an OR to catch the wrap around - break; // only compare hits in adjacent phi bins + std::sort(row_hits.begin(), row_hits.end(), compare_phi); + + // double loop over the hits in this row + for (unsigned int j = 0; j < row_hits.size(); ++j) { + + ++numberOfhitsTreated; + + for (unsigned int k = j + 1; k < row_hits.size(); ++k) { + + if (row_hits[k]->getPhiIndex() > + (row_hits[j]->getPhiIndex()) + 2) { // SJA:FIXME: here we need an OR to catch the wrap around + break; // only compare hits in adjacent phi bins } - - // look to see if the two hit occupy the same pad in phi or if not whether they are within the r-phi double hit resolution - else if( row_hits[k]->getPhiIndex()==row_hits[j]->getPhiIndex() - || - ( (fabs(row_hits[k]->getHep3Vector().deltaPhi(row_hits[j]->getHep3Vector()))) * row_hits[j]->getR()) < _doubleHitResRPhi ) { - + + // look to see if the two hit occupy the same pad in phi or if not whether they are within the r-phi double hit + // resolution + else if (row_hits[k]->getPhiIndex() == row_hits[j]->getPhiIndex() || + ((fabs(row_hits[k]->getHep3Vector().deltaPhi(row_hits[j]->getHep3Vector()))) * row_hits[j]->getR()) < + _doubleHitResRPhi) { + // if neighboring in phi then compare z - map ::iterator it; - + map::iterator it; + SimTrackerHit* Hit1 = NULL; SimTrackerHit* Hit2 = NULL; - + // search of the simhit pointers in the tpchit map - it=_tpcHitMap.find(row_hits[j]); - if(it!= _tpcHitMap.end()) { - Hit1 = it->second ; // hit found + it = _tpcHitMap.find(row_hits[j]); + if (it != _tpcHitMap.end()) { + Hit1 = it->second; // hit found } - - it=_tpcHitMap.find(row_hits[k]); - if(it!= _tpcHitMap.end()) { - Hit2 = it->second ; // hit found + + it = _tpcHitMap.find(row_hits[k]); + if (it != _tpcHitMap.end()) { + Hit2 = it->second; // hit found } - + double pathlengthZ1(0.0); double pathlengthZ2(0.0); - - if( Hit1 && Hit2 ){ // if both sim hits were found - + + if (Hit1 && Hit2) { // if both sim hits were found + // check if the track momentum has been stored for the hits bool momentum_set = true; - - if( STHcol != NULL ){ - LCFlagImpl colFlag( STHcol->getFlag() ) ; - momentum_set = momentum_set && colFlag.bitSet(LCIO::THBIT_MOMENTUM) ; - } - - if( STHcolLowPt != NULL ){ - LCFlagImpl colFlag( STHcolLowPt->getFlag() ) ; - momentum_set = momentum_set && colFlag.bitSet(LCIO::THBIT_MOMENTUM) ; - } - - if( momentum_set ){ - - const float * Momentum1 = Hit1->getMomentum() ; - const float * Momentum2 = Hit2->getMomentum() ; - - CLHEP::Hep3Vector mom1(Momentum1[0],Momentum1[1],Momentum1[2]); - CLHEP::Hep3Vector mom2(Momentum2[0],Momentum2[1],Momentum2[2]); - - pathlengthZ1 = fabs( Hit1->getPathLength() * mom1.cosTheta() ); - pathlengthZ2 = fabs( Hit2->getPathLength() * mom2.cosTheta() ); - } - else { - pathlengthZ1 = _doubleHitResZ ; // assume the worst i.e. that the track is moving in z - pathlengthZ2 = _doubleHitResZ ; // assume the worst i.e. that the track is moving in z + + if (STHcol != NULL) { + LCFlagImpl colFlag(STHcol->getFlag()); + momentum_set = momentum_set && colFlag.bitSet(LCIO::THBIT_MOMENTUM); + } + + if (STHcolLowPt != NULL) { + LCFlagImpl colFlag(STHcolLowPt->getFlag()); + momentum_set = momentum_set && colFlag.bitSet(LCIO::THBIT_MOMENTUM); } - + + if (momentum_set) { + + const float* Momentum1 = Hit1->getMomentum(); + const float* Momentum2 = Hit2->getMomentum(); + + CLHEP::Hep3Vector mom1(Momentum1[0], Momentum1[1], Momentum1[2]); + CLHEP::Hep3Vector mom2(Momentum2[0], Momentum2[1], Momentum2[2]); + + pathlengthZ1 = fabs(Hit1->getPathLength() * mom1.cosTheta()); + pathlengthZ2 = fabs(Hit2->getPathLength() * mom2.cosTheta()); + } else { + pathlengthZ1 = _doubleHitResZ; // assume the worst i.e. that the track is moving in z + pathlengthZ2 = _doubleHitResZ; // assume the worst i.e. that the track is moving in z + } + double dZ = fabs(row_hits[j]->getZ() - row_hits[k]->getZ()); - - double spacial_coverage = 0.5*(pathlengthZ1 + pathlengthZ2) + _binningZ; - - if( (dZ - spacial_coverage) < _doubleHitResZ ){ - + + double spacial_coverage = 0.5 * (pathlengthZ1 + pathlengthZ2) + _binningZ; + + if ((dZ - spacial_coverage) < _doubleHitResZ) { + row_hits[j]->setAdjacent(row_hits[k]); row_hits[k]->setAdjacent(row_hits[j]); ++number_of_adjacent_hits; - } } else { - streamlog_out(DEBUG3) << "Hit1=" << Hit1 << "Hit2=" << Hit2 << endl; + streamlog_out(DEBUG3) << "Hit1=" << Hit1 << "Hit2=" << Hit2 << endl; } } } } - - + // now all hits have been checked for adjacent hits, go throught and write out the hits or merge - - for (unsigned int j = 0; jIsMerged() || seed_hit->IsClusterHit()) { + + if (seed_hit->IsMerged() || seed_hit->IsClusterHit()) { continue; } - - if(seed_hit->getNumberOfAdjacent()==0){ // no adjacent hits so smear and write to hit collection + + if (seed_hit->getNumberOfAdjacent() == 0) { // no adjacent hits so smear and write to hit collection writeVoxelToHit(seed_hit, hitSimHitNav); } - - else if(seed_hit->getNumberOfAdjacent() < (_maxMerge)){ // potential 3-hit cluster, can use simple average merge. - - vector * hitsToMerge = new vector ; - + + else if (seed_hit->getNumberOfAdjacent() < + (_maxMerge)) { // potential 3-hit cluster, can use simple average merge. + + vector* hitsToMerge = new vector; + int clusterSize = seed_hit->clusterFind(hitsToMerge); - - if( clusterSize <= _maxMerge ){ // merge cluster + + if (clusterSize <= _maxMerge) { // merge cluster seed_hit->setIsMerged(); writeMergedVoxelsToHit(hitsToMerge, hitSimHitNav); } delete hitsToMerge; - } - } + } + } } - + int numberOfHits(0); // count up the number of hits merged or lost - for (unsigned int i = 0; i<_tpcRowHits.size(); ++i){ + for (unsigned int i = 0; i < _tpcRowHits.size(); ++i) { row_hits = _tpcRowHits.at(i); - for (unsigned int j = 0; jIsMerged() || seed_hit->IsClusterHit() || seed_hit->getNumberOfAdjacent() > _maxMerge ) { + if (seed_hit->IsMerged() || seed_hit->IsClusterHit() || seed_hit->getNumberOfAdjacent() > _maxMerge) { ++_NRevomedHits; - _mcp = (_tpcHitMap[ seed_hit ])->getMCParticle() ; - if(_mcp != NULL ) { - ++_NLostPhysicsTPCHits; - const double *mom= _mcp->getMomentum() ; - double ptSQRD = mom[0]*mom[0]+mom[1]*mom[1] ; - if( ptSQRD > (0.2*0.2) ) ++_NLostPhysicsAbove02GeVPtTPCHits ; - if( ptSQRD > 1.0 ) ++_NLostPhysicsAbove1GeVPtTPCHits ; + _mcp = (_tpcHitMap[seed_hit])->getMCParticle(); + if (_mcp != NULL) { + ++_NLostPhysicsTPCHits; + const double* mom = _mcp->getMomentum(); + double ptSQRD = mom[0] * mom[0] + mom[1] * mom[1]; + if (ptSQRD > (0.2 * 0.2)) + ++_NLostPhysicsAbove02GeVPtTPCHits; + if (ptSQRD > 1.0) + ++_NLostPhysicsAbove1GeVPtTPCHits; } } } } - - streamlog_out(DEBUG4) << "the number of adjacent hits is " << number_of_adjacent_hits << " _doubleHitResZ " << _doubleHitResZ << endl; - streamlog_out(DEBUG4) << "number of rec_hits = " << _NRecTPCHits << endl ; - streamlog_out(DEBUG4) << "finished row hits " << numberOfHits << " " << numberOfhitsTreated << endl; - + + streamlog_out(DEBUG4) << "the number of adjacent hits is " << number_of_adjacent_hits << " _doubleHitResZ " + << _doubleHitResZ << endl; + streamlog_out(DEBUG4) << "number of rec_hits = " << _NRecTPCHits << endl; + streamlog_out(DEBUG4) << "finished row hits " << numberOfHits << " " << numberOfhitsTreated << endl; + // set the parameters to decode the type information in the collection // for the time being this has to be done manually - // in the future we should provide a more convenient mechanism to + // in the future we should provide a more convenient mechanism to // decode this sort of meta information - - StringVec typeNames ; - IntVec typeValues ; - typeNames.push_back( LCIO::TPCHIT ) ; - typeValues.push_back( 1 ) ; - _trkhitVec->parameters().setValues("TrackerHitTypeNames" , typeNames ) ; - _trkhitVec->parameters().setValues("TrackerHitTypeValues" , typeValues ) ; - + + StringVec typeNames; + IntVec typeValues; + typeNames.push_back(LCIO::TPCHIT); + typeValues.push_back(1); + _trkhitVec->parameters().setValues("TrackerHitTypeNames", typeNames); + _trkhitVec->parameters().setValues("TrackerHitTypeValues", typeValues); + // add the collection to the event - evt->addCollection( _trkhitVec , _TPCTrackerHitsCol ) ; + evt->addCollection(_trkhitVec, _TPCTrackerHitsCol); auto relCol = hitSimHitNav.createLCCollection(); - evt->addCollection( relCol , _outRelColName ) ; + evt->addCollection(relCol, _outRelColName); // delete voxels - for (unsigned int i = 0; i<_tpcRowHits.size(); ++i){ - vector * current_row = &_tpcRowHits.at(i); - for (unsigned int j = 0; jsize(); ++j){ + for (unsigned int i = 0; i < _tpcRowHits.size(); ++i) { + vector* current_row = &_tpcRowHits.at(i); + for (unsigned int j = 0; j < current_row->size(); ++j) { delete current_row->at(j); } } - + #ifdef DIGIPLOTS _NSimTPCHitsHisto->fill(_NSimTPCHits); _NBackgroundSimTPCHitsHisto->fill(_NBackgroundSimTPCHits); @@ -1089,112 +973,109 @@ void DDTPCDigiProcessor::processEvent( LCEvent * evt ) _NPhysicsAbove02GeVSimTPCHitsHisto->fill(_NPhysicsAbove02GeVSimTPCHits); _NPhysicsAbove1GeVSimTPCHitsHisto->fill(_NPhysicsAbove1GeVSimTPCHits); _NRecTPCHitsHisto->fill(_NRecTPCHits); - + _NLostPhysicsTPCHitsHisto->fill(_NLostPhysicsTPCHits); _NLostPhysicsAbove02GeVPtTPCHitsHisto->fill(_NLostPhysicsAbove02GeVPtTPCHits); _NLostPhysicsAbove1GeVPtTPCHitsHisto->fill(_NLostPhysicsAbove1GeVPtTPCHits); _NRevomedHitsHisto->fill(_NRevomedHits); - - _NKeptPhysicsTPCHitsHistoPercent->fill( (float)(_NPhysicsSimTPCHits-_NLostPhysicsTPCHits) / (float)_NPhysicsSimTPCHits ); - _NKeptPhysicsAbove02GeVPtTPCHitsHistoPercent->fill( (float)(_NPhysicsAbove02GeVSimTPCHits-_NLostPhysicsAbove02GeVPtTPCHits) / (float)_NPhysicsAbove02GeVSimTPCHits ); - _NKeptPhysicsAbove1GeVPtTPCHitsHistoPercent->fill( (float)(_NPhysicsAbove1GeVSimTPCHits-_NLostPhysicsAbove1GeVPtTPCHits) / (float)_NPhysicsAbove1GeVSimTPCHits ); + + _NKeptPhysicsTPCHitsHistoPercent->fill((float)(_NPhysicsSimTPCHits - _NLostPhysicsTPCHits) / + (float)_NPhysicsSimTPCHits); + _NKeptPhysicsAbove02GeVPtTPCHitsHistoPercent->fill( + (float)(_NPhysicsAbove02GeVSimTPCHits - _NLostPhysicsAbove02GeVPtTPCHits) / (float)_NPhysicsAbove02GeVSimTPCHits); + _NKeptPhysicsAbove1GeVPtTPCHitsHistoPercent->fill( + (float)(_NPhysicsAbove1GeVSimTPCHits - _NLostPhysicsAbove1GeVPtTPCHits) / (float)_NPhysicsAbove1GeVSimTPCHits); #endif - + streamlog_out(DEBUG4) << "_NSimTPCHits = " << _NSimTPCHits << endl; streamlog_out(DEBUG4) << "_NBackgroundSimTPCHits = " << _NBackgroundSimTPCHits << endl; streamlog_out(DEBUG4) << "_NPhysicsSimTPCHits = " << _NPhysicsSimTPCHits << endl; streamlog_out(DEBUG4) << "_NPhysicsAbove02GeVSimTPCHits = " << _NPhysicsAbove02GeVSimTPCHits << endl; streamlog_out(DEBUG4) << "_NPhysicsAbove1GeVSimTPCHits = " << _NPhysicsAbove1GeVSimTPCHits << endl; - streamlog_out(DEBUG4) << "_NRecTPCHits = " << _NRecTPCHits<< endl; + streamlog_out(DEBUG4) << "_NRecTPCHits = " << _NRecTPCHits << endl; streamlog_out(DEBUG4) << "_NLostPhysicsTPCHits = " << _NLostPhysicsTPCHits << endl; streamlog_out(DEBUG4) << "_NLostPhysicsAbove02GeVPtTPCHits = " << _NLostPhysicsAbove02GeVPtTPCHits << endl; streamlog_out(DEBUG4) << "_NLostPhysicsAbove1GeVPtTPCHits = " << _NLostPhysicsAbove1GeVPtTPCHits << endl; streamlog_out(DEBUG4) << "_NRevomedHits = " << _NRevomedHits << endl; - - _nEvt++; - //Clear the maps and the end of the event. + + _nEvt++; + // Clear the maps and the end of the event. _tpcHitMap.clear(); _tpcRowHits.clear(); - - delete _cellid_encoder ; - -} - + delete _cellid_encoder; +} -void DDTPCDigiProcessor::check( LCEvent * ) -{ +void DDTPCDigiProcessor::check(LCEvent*) { // nothing to check here - could be used to fill checkplots in reconstruction processor } +void DDTPCDigiProcessor::end() { -void DDTPCDigiProcessor::end() -{ - #ifdef DIGIPLOTS _TREE->commit(); _TREE->cd("/Histograms"); _TREE->ls(".."); - - _TREE->close(); + + _TREE->close(); streamlog_out(MESSAGE) << "DIGICHECKPLOTS Finished" << endl; #endif - + gsl_rng_free(_random); - streamlog_out(MESSAGE) << "DDTPCDigiProcessor::end() " << name() - << " processed " << _nEvt << " events in " << _nRun << " runs " - << endl ; - // + streamlog_out(MESSAGE) << "DDTPCDigiProcessor::end() " << name() << " processed " << _nEvt << " events in " << _nRun + << " runs " << endl; + // } -void DDTPCDigiProcessor::writeVoxelToHit( Voxel_tpc* aVoxel, UTIL::LCRelationNavigator& hitSimHitNav){ - - - Voxel_tpc* seed_hit = aVoxel; - +void DDTPCDigiProcessor::writeVoxelToHit(Voxel_tpc* aVoxel, UTIL::LCRelationNavigator& hitSimHitNav) { + + Voxel_tpc* seed_hit = aVoxel; + // if( seed_hit->getRowIndex() > 5 ) return ; - - //store hit variables - TrackerHitImpl* trkHit = new TrackerHitImpl ; - //now the hit pos has to be smeared - + + // store hit variables + TrackerHitImpl* trkHit = new TrackerHitImpl; + // now the hit pos has to be smeared + double tpcRPhiRes = seed_hit->getRPhiRes(); double tpcZRes = seed_hit->getZRes(); - - CLHEP::Hep3Vector point(seed_hit->getX(),seed_hit->getY(),seed_hit->getZ()); - + + CLHEP::Hep3Vector point(seed_hit->getX(), seed_hit->getY(), seed_hit->getZ()); //-------- fg: remove the hit if it lies within a module boundary in phi -------- - dd4hep::rec::Vector3D hitPos( seed_hit->getX(),seed_hit->getY(),seed_hit->getZ()); + dd4hep::rec::Vector3D hitPos(seed_hit->getX(), seed_hit->getY(), seed_hit->getZ()); - double hitGapDist = _tpcEP->computeDistanceRPhi( hitPos ) ; + double hitGapDist = _tpcEP->computeDistanceRPhi(hitPos); - if( hitGapDist < _tpcEndPlateModuleGapPhi / 2. ){ + if (hitGapDist < _tpcEndPlateModuleGapPhi / 2.) { - streamlog_out( DEBUG2 ) << " removing hit in endplate module gap : " << hitPos << " - distance : " << hitGapDist << std::endl ; + streamlog_out(DEBUG2) << " removing hit in endplate module gap : " << hitPos << " - distance : " << hitGapDist + << std::endl; - return ; + return; } - //fg: here we could add additional effects, e.g larger smearing of hits in the - // vicinity of the gaps ( need extra parameters ) - // or larger smearing in the pad row next to a module ring boundary in r - // ... + // fg: here we could add additional effects, e.g larger smearing of hits in the + // vicinity of the gaps ( need extra parameters ) + // or larger smearing in the pad row next to a module ring boundary in r + // ... //------------------------------------------------------------------------------ double unsmearedPhi = point.phi(); - - double randrp = gsl_ran_gaussian(_random,tpcRPhiRes); - double randz = gsl_ran_gaussian(_random,tpcZRes); - - point.setPhi( point.phi() + randrp/ point.perp() ); - point.setZ( point.z() + randz ); + + double randrp = gsl_ran_gaussian(_random, tpcRPhiRes); + double randz = gsl_ran_gaussian(_random, tpcZRes); + + point.setPhi(point.phi() + randrp / point.perp()); + point.setZ(point.z() + randz); // make sure the hit is not smeared beyond the TPC Max DriftLength - if( fabs(point.z()) > _tpc->driftLength/dd4hep::mm ) point.setZ( (fabs(point.z()) / point.z() ) * _tpc->driftLength/dd4hep::mm ); + if (fabs(point.z()) > _tpc->driftLength / dd4hep::mm) + point.setZ((fabs(point.z()) / point.z()) * _tpc->driftLength / dd4hep::mm); -#if 0 // fg: it turns out that is more correct to allow reconstructed hits to be outside of the drift volume due to the large uncertainties +#if 0 // fg: it turns out that is more correct to allow reconstructed hits to be outside of the drift volume due to the + // large uncertainties // make sure the hit is not smeared beyond the cathode: double dzCathode = _tpc->zMinReadout/dd4hep::mm ; if( point.z() > 0. && hitPos.z() < 0. ){ @@ -1205,108 +1086,102 @@ void DDTPCDigiProcessor::writeVoxelToHit( Voxel_tpc* aVoxel, UTIL::LCRelationNav } #endif - double pos[3] = {point.x(),point.y(),point.z()}; + double pos[3] = {point.x(), point.y(), point.z()}; trkHit->setPosition(pos); trkHit->setEDep(seed_hit->getEDep()); // trkHit->setType( 500 ); - -// int side = lcio::ILDDetID::barrel ; -// -// if( pos[2] < 0.0 ) side = 1 ; - - (*_cellid_encoder)[ lcio::LCTrackerCellID::subdet() ] = lcio::ILDDetID::TPC ; - (*_cellid_encoder)[ lcio::LCTrackerCellID::layer() ] = seed_hit->getRowIndex() ; - (*_cellid_encoder)[ lcio::LCTrackerCellID::module() ] = 0 ; - (*_cellid_encoder)[ lcio::LCTrackerCellID::side() ] = ( pos[2] < 0 ? -1 : 1 ) ; - - _cellid_encoder->setCellID( trkHit ) ; - - + + // int side = lcio::ILDDetID::barrel ; + // + // if( pos[2] < 0.0 ) side = 1 ; + + (*_cellid_encoder)[lcio::LCTrackerCellID::subdet()] = lcio::ILDDetID::TPC; + (*_cellid_encoder)[lcio::LCTrackerCellID::layer()] = seed_hit->getRowIndex(); + (*_cellid_encoder)[lcio::LCTrackerCellID::module()] = 0; + (*_cellid_encoder)[lcio::LCTrackerCellID::side()] = (pos[2] < 0 ? -1 : 1); + + _cellid_encoder->setCellID(trkHit); + // check values for inf and nan - if( std::isnan(unsmearedPhi) || std::isinf(unsmearedPhi) || std::isnan(tpcRPhiRes) || std::isinf(tpcRPhiRes) ) { + if (std::isnan(unsmearedPhi) || std::isinf(unsmearedPhi) || std::isnan(tpcRPhiRes) || std::isinf(tpcRPhiRes)) { std::stringstream errorMsg; - errorMsg << "\nProcessor: DDTPCDigiProcessor \n" - << "unsmearedPhi = " - << unsmearedPhi - << " tpcRPhiRes = " - << tpcRPhiRes - << "\n" ; + errorMsg << "\nProcessor: DDTPCDigiProcessor \n" + << "unsmearedPhi = " << unsmearedPhi << " tpcRPhiRes = " << tpcRPhiRes << "\n"; throw Exception(errorMsg.str()); } - + // For no error in R - float covMat[TRKHITNCOVMATRIX]={float(sin(unsmearedPhi)*sin(unsmearedPhi)*tpcRPhiRes*tpcRPhiRes), - float(-cos(unsmearedPhi)*sin(unsmearedPhi)*tpcRPhiRes*tpcRPhiRes), - float(cos(unsmearedPhi)*cos(unsmearedPhi)*tpcRPhiRes*tpcRPhiRes), - float(0.), - float(0.), - float(tpcZRes*tpcZRes) }; - - trkHit->setCovMatrix(covMat); - - if( _tpcHitMap[seed_hit] == NULL ){ + float covMat[TRKHITNCOVMATRIX] = {float(sin(unsmearedPhi) * sin(unsmearedPhi) * tpcRPhiRes * tpcRPhiRes), + float(-cos(unsmearedPhi) * sin(unsmearedPhi) * tpcRPhiRes * tpcRPhiRes), + float(cos(unsmearedPhi) * cos(unsmearedPhi) * tpcRPhiRes * tpcRPhiRes), + float(0.), + float(0.), + float(tpcZRes * tpcZRes)}; + + trkHit->setCovMatrix(covMat); + + if (_tpcHitMap[seed_hit] == NULL) { std::stringstream errorMsg; - errorMsg << "\nProcessor: DDTPCDigiProcessor \n" - << "SimTracker Pointer is NULL throwing exception\n" - << "\n" ; + errorMsg << "\nProcessor: DDTPCDigiProcessor \n" + << "SimTracker Pointer is NULL throwing exception\n" + << "\n"; throw Exception(errorMsg.str()); } - - if(pos[0]*pos[0]+pos[1]*pos[1]>0.0){ + + if (pos[0] * pos[0] + pos[1] * pos[1] > 0.0) { // push back the SimTHit for this TrackerHit if (_use_raw_hits_to_store_simhit_pointer) { - trkHit->rawHits().push_back( _tpcHitMap[seed_hit] ); - } + trkHit->rawHits().push_back(_tpcHitMap[seed_hit]); + } hitSimHitNav.addRelation(trkHit, _tpcHitMap[seed_hit], 1.0); - _trkhitVec->addElement( trkHit ); + _trkhitVec->addElement(trkHit); _NRecTPCHits++; } - - + #ifdef DIGIPLOTS SimTrackerHit* theSimHit = _tpcHitMap[seed_hit]; - double rSimSqrd = theSimHit->getPosition()[0]*theSimHit->getPosition()[0] + theSimHit->getPosition()[1]*theSimHit->getPosition()[1]; - - double phiSim = atan2(theSimHit->getPosition()[1],theSimHit->getPosition()[0]); - - double rPhiDiff = (point.phi() - phiSim)*sqrt(rSimSqrd); - double rPhiPull = ((point.phi() - phiSim)*sqrt(rSimSqrd))/(sqrt((covMat[2])/(cos(point.phi())*cos(point.phi())))); - + double rSimSqrd = theSimHit->getPosition()[0] * theSimHit->getPosition()[0] + + theSimHit->getPosition()[1] * theSimHit->getPosition()[1]; + + double phiSim = atan2(theSimHit->getPosition()[1], theSimHit->getPosition()[0]); + + double rPhiDiff = (point.phi() - phiSim) * sqrt(rSimSqrd); + double rPhiPull = + ((point.phi() - phiSim) * sqrt(rSimSqrd)) / (sqrt((covMat[2]) / (cos(point.phi()) * cos(point.phi())))); + double zDiff = point.getZ() - theSimHit->getPosition()[2]; - double zPull = zDiff/sqrt(covMat[5]); - - + double zPull = zDiff / sqrt(covMat[5]); + _rPhiDiffHisto->fill(rPhiDiff); _rPhiPullHisto->fill(rPhiPull); _phiDistHisto->fill(point.phi() - phiSim); _zDiffHisto->fill(zDiff); _zPullHisto->fill(zPull); - - _zSigmaVsZHisto->fill(seed_hit->getZ(),sqrt(covMat[5])); - _rPhiSigmaHisto->fill(sqrt((covMat[2])/(cos(point.phi())*cos(point.phi())))); + + _zSigmaVsZHisto->fill(seed_hit->getZ(), sqrt(covMat[5])); + _rPhiSigmaHisto->fill(sqrt((covMat[2]) / (cos(point.phi()) * cos(point.phi())))); _zSigmaHisto->fill(sqrt(covMat[5])); #endif } -void DDTPCDigiProcessor::writeMergedVoxelsToHit( vector * hitsToMerge, UTIL::LCRelationNavigator& hitSimHitNav){ - - - TrackerHitImpl* trkHit = new TrackerHitImpl ; - +void DDTPCDigiProcessor::writeMergedVoxelsToHit(vector* hitsToMerge, + UTIL::LCRelationNavigator& hitSimHitNav) { + + TrackerHitImpl* trkHit = new TrackerHitImpl; + double sumZ = 0; double sumPhi = 0; double sumEDep = 0; // double R = 0; double lastR = 0; - + unsigned number_of_hits_to_merge = hitsToMerge->size(); - - for(unsigned int ihitCluster = 0; ihitCluster < number_of_hits_to_merge; ++ihitCluster){ - + for (unsigned int ihitCluster = 0; ihitCluster < number_of_hits_to_merge; ++ihitCluster) { + sumZ += hitsToMerge->at(ihitCluster)->getZ(); sumPhi += hitsToMerge->at(ihitCluster)->getPhi(); sumEDep += hitsToMerge->at(ihitCluster)->getEDep(); @@ -1314,48 +1189,48 @@ void DDTPCDigiProcessor::writeMergedVoxelsToHit( vector * hitsToMerg lastR = hitsToMerge->at(ihitCluster)->getR(); if (_use_raw_hits_to_store_simhit_pointer) { - trkHit->rawHits().push_back( _tpcHitMap[hitsToMerge->at(ihitCluster)] ); - } + trkHit->rawHits().push_back(_tpcHitMap[hitsToMerge->at(ihitCluster)]); + } - hitSimHitNav.addRelation(trkHit, - _tpcHitMap[hitsToMerge->at(ihitCluster)], - float(1.0/number_of_hits_to_merge)); + hitSimHitNav.addRelation(trkHit, _tpcHitMap[hitsToMerge->at(ihitCluster)], float(1.0 / number_of_hits_to_merge)); } - - double avgZ = sumZ/(hitsToMerge->size()); - double avgPhi = sumPhi/(hitsToMerge->size()); - - //set deposit energy as mean of merged hits - sumEDep=sumEDep/(double)number_of_hits_to_merge; - - CLHEP::Hep3Vector* mergedPoint = new CLHEP::Hep3Vector(1.0,1.0,1.0); + + double avgZ = sumZ / (hitsToMerge->size()); + double avgPhi = sumPhi / (hitsToMerge->size()); + + // set deposit energy as mean of merged hits + sumEDep = sumEDep / (double)number_of_hits_to_merge; + + CLHEP::Hep3Vector* mergedPoint = new CLHEP::Hep3Vector(1.0, 1.0, 1.0); mergedPoint->setPerp(lastR); mergedPoint->setPhi(avgPhi); mergedPoint->setZ(avgZ); - - //store hit variables + + // store hit variables // first the hit pos has to be smeared------------------------------------------------ - - //FIXME: which errors should we use for smearing the merged hits ? - // this might be a bit large .... + + // FIXME: which errors should we use for smearing the merged hits ? + // this might be a bit large .... double tpcRPhiRes = _padWidth; double tpcZRes = _binningZ; - - CLHEP::Hep3Vector point( mergedPoint->getX(), mergedPoint->getY(), mergedPoint->getZ() ) ; - -// double unsmearedPhi = point.phi(); - - double randrp = gsl_ran_gaussian(_random,tpcRPhiRes); - double randz = gsl_ran_gaussian(_random,tpcZRes); - - point.setPhi( point.phi() + randrp/ point.perp() ); - point.setZ( point.z() + randz ); - + + CLHEP::Hep3Vector point(mergedPoint->getX(), mergedPoint->getY(), mergedPoint->getZ()); + + // double unsmearedPhi = point.phi(); + + double randrp = gsl_ran_gaussian(_random, tpcRPhiRes); + double randz = gsl_ran_gaussian(_random, tpcZRes); + + point.setPhi(point.phi() + randrp / point.perp()); + point.setZ(point.z() + randz); + // make sure the hit is not smeared beyond the TPC Max DriftLength - if( fabs(point.z()) > _tpc->driftLength/dd4hep::mm ) point.setZ( (fabs(point.z()) / point.z() ) * _tpc->driftLength/dd4hep::mm ); + if (fabs(point.z()) > _tpc->driftLength / dd4hep::mm) + point.setZ((fabs(point.z()) / point.z()) * _tpc->driftLength / dd4hep::mm); -#if 0 // fg: it turns out that is more correct to allow reconstructed hits to be outside of the drift volume due to the large uncertainties +#if 0 // fg: it turns out that is more correct to allow reconstructed hits to be outside of the drift volume due to the + // large uncertainties // make sure the hit is not smeared onto the other side of the cathode: double dzCathode = _tpc->zMinReadout/dd4hep::mm ; if( point.z() > 0. && mergedPoint->getZ() < 0. ){ @@ -1366,125 +1241,107 @@ void DDTPCDigiProcessor::writeMergedVoxelsToHit( vector * hitsToMerg } #endif - double pos[3] = {point.x(),point.y(),point.z()}; + double pos[3] = {point.x(), point.y(), point.z()}; //--------------------------------------------------------------------------------- trkHit->setPosition(pos); trkHit->setEDep(sumEDep); // trkHit->setType( 500 ); - - FixedPadSizeDiskLayout padLayout( _tpc ); - int padIndex = padLayout.getNearestPad(mergedPoint->perp(),mergedPoint->phi()); - int row = padLayout.getRowNumber(padIndex); - - (*_cellid_encoder)[ lcio::LCTrackerCellID::subdet() ] = lcio::ILDDetID::TPC ; - (*_cellid_encoder)[ lcio::LCTrackerCellID::layer() ] = row ; - (*_cellid_encoder)[ lcio::LCTrackerCellID::module() ] = 0 ; - (*_cellid_encoder)[ lcio::LCTrackerCellID::side() ] = ( pos[2] < 0 ? -1 : 1 ) ; - - _cellid_encoder->setCellID( trkHit ) ; - - + + FixedPadSizeDiskLayout padLayout(_tpc); + int padIndex = padLayout.getNearestPad(mergedPoint->perp(), mergedPoint->phi()); + int row = padLayout.getRowNumber(padIndex); + + (*_cellid_encoder)[lcio::LCTrackerCellID::subdet()] = lcio::ILDDetID::TPC; + (*_cellid_encoder)[lcio::LCTrackerCellID::layer()] = row; + (*_cellid_encoder)[lcio::LCTrackerCellID::module()] = 0; + (*_cellid_encoder)[lcio::LCTrackerCellID::side()] = (pos[2] < 0 ? -1 : 1); + + _cellid_encoder->setCellID(trkHit); + double phi = mergedPoint->getPhi(); - + // check values for inf and nan - if( std::isnan(phi) || std::isinf(phi) || std::isnan(tpcRPhiRes) || std::isinf(tpcRPhiRes) ) { + if (std::isnan(phi) || std::isinf(phi) || std::isnan(tpcRPhiRes) || std::isinf(tpcRPhiRes)) { std::stringstream errorMsg; - errorMsg << "\nProcessor: DDTPCDigiProcessor \n" - << "phi = " - << phi - << " tpcRPhiRes = " - << tpcRPhiRes - << "\n" ; + errorMsg << "\nProcessor: DDTPCDigiProcessor \n" + << "phi = " << phi << " tpcRPhiRes = " << tpcRPhiRes << "\n"; throw Exception(errorMsg.str()); } - + // For no error in R - float covMat[TRKHITNCOVMATRIX]={float(sin(phi)*sin(phi)*tpcRPhiRes*tpcRPhiRes), - float(-cos(phi)*sin(phi)*tpcRPhiRes*tpcRPhiRes), - float(cos(phi)*cos(phi)*tpcRPhiRes*tpcRPhiRes), - float(0.), - float(0.), - float(tpcZRes*tpcZRes)}; - - trkHit->setCovMatrix(covMat); - - // if(pos[0]*pos[0]+pos[1]*pos[1]>0.0){ - _trkhitVec->addElement( trkHit ); + float covMat[TRKHITNCOVMATRIX] = {float(sin(phi) * sin(phi) * tpcRPhiRes * tpcRPhiRes), + float(-cos(phi) * sin(phi) * tpcRPhiRes * tpcRPhiRes), + float(cos(phi) * cos(phi) * tpcRPhiRes * tpcRPhiRes), + float(0.), + float(0.), + float(tpcZRes * tpcZRes)}; + + trkHit->setCovMatrix(covMat); + + // if(pos[0]*pos[0]+pos[1]*pos[1]>0.0){ + _trkhitVec->addElement(trkHit); ++_nRechits; // } else { // delete trkHit; // } - + delete mergedPoint; - } - #ifdef DIGIPLOTS -void DDTPCDigiProcessor::plotHelixHitResidual( MCParticle *mcp, CLHEP::Hep3Vector *thisPoint){ - +void DDTPCDigiProcessor::plotHelixHitResidual(MCParticle* mcp, CLHEP::Hep3Vector* thisPoint) { + const double FCT = 2.99792458E-4; double charge = mcp->getCharge(); - const double *mom = mcp->getMomentum(); - double pt = sqrt(mom[0]*mom[0]+mom[1]*mom[1]); - double radius = pt / (FCT*_bField); - double tanLambda = mom[2]/pt; + const double* mom = mcp->getMomentum(); + double pt = sqrt(mom[0] * mom[0] + mom[1] * mom[1]); + double radius = pt / (FCT * _bField); + double tanLambda = mom[2] / pt; double omega = charge / radius; - - if(pt>1.0) { - - //FIXME SJA: this is only valid for tracks from the IP and should be done correctly for non prompt tracks - double Z0 = 0.; - double D0 = 0.; - - LCVector3D refPoint(0.,0.,0); - - SimpleHelix* helix = new SimpleHelix(D0, - atan2(mom[1],mom[0]), - omega, - Z0, - tanLambda, - refPoint); - - - // an almost "infinite" cylinder in z - LCVector3D startCylinder(0.,0.,-1000000.0); - LCVector3D endCylinder(0.,0.,1000000.0); - bool endplane=true; - - LCCylinder cylinder(startCylinder,endCylinder,thisPoint->perp(),endplane); - + + if (pt > 1.0) { + + // FIXME SJA: this is only valid for tracks from the IP and should be done correctly for non prompt tracks + double Z0 = 0.; + double D0 = 0.; + + LCVector3D refPoint(0., 0., 0); + + SimpleHelix* helix = new SimpleHelix(D0, atan2(mom[1], mom[0]), omega, Z0, tanLambda, refPoint); + + // an almost "infinite" cylinder in z + LCVector3D startCylinder(0., 0., -1000000.0); + LCVector3D endCylinder(0., 0., 1000000.0); + bool endplane = true; + + LCCylinder cylinder(startCylinder, endCylinder, thisPoint->perp(), endplane); + bool pointExists = false; - - double pathlength = helix->getIntersectionWithCylinder( cylinder, pointExists); - + + double pathlength = helix->getIntersectionWithCylinder(cylinder, pointExists); + LCErrorMatrix* errors = new LCErrorMatrix(); - - if(pointExists){ - - LCVector3D intersection = helix->getPosition(pathlength, errors); - - double intersectionPhi = atan2(intersection[1],intersection[0]); - double residualRPhi = ((intersectionPhi-thisPoint->phi())) ; + + if (pointExists) { + + LCVector3D intersection = helix->getPosition(pathlength, errors); + + double intersectionPhi = atan2(intersection[1], intersection[0]); + double residualRPhi = ((intersectionPhi - thisPoint->phi())); _ResidualsRPhiHisto->fill(residualRPhi); - } - + delete errors; delete helix; - - - int row = padLayout.getRowNumber(padLayout.getNearestPad(thisPoint->perp(),thisPoint->phi())); - int pad = padLayout.getNearestPad(thisPoint->perp(),thisPoint->phi()); - - double rHit_diff = thisPoint->perp() - - padLayout.getPlaneExtent()[0] - - (( row + 0.5 ) - * _tpc->padHeight/dd4hep::mm ) ; - + + int row = padLayout.getRowNumber(padLayout.getNearestPad(thisPoint->perp(), thisPoint->phi())); + int pad = padLayout.getNearestPad(thisPoint->perp(), thisPoint->phi()); + + double rHit_diff = thisPoint->perp() - padLayout.getPlaneExtent()[0] - ((row + 0.5) * _tpc->padHeight / dd4hep::mm); + _radiusCheckHisto->fill(rHit_diff); - + // streamlog_out(MESSAGE) << "$#$#$#$#$#$#$#$#$#$#$#$#$#$#$#$#$#$#$#$#$#$#$" << endl; // streamlog_out(MESSAGE) << "thisPoint->perp() = " << thisPoint->perp() << endl; // streamlog_out(MESSAGE) << "TPC Sensitive rMin = " << padLayout.getPlaneExtent()[0] << endl; @@ -1492,147 +1349,138 @@ void DDTPCDigiProcessor::plotHelixHitResidual( MCParticle *mcp, CLHEP::Hep3Vecto // streamlog_out(MESSAGE) << "Pad Height = " << padLayout.getPadHeight(pad) << endl; // streamlog_out(MESSAGE) << "Row Height = " << padLayout.getRowHeight(row) << endl; // streamlog_out(MESSAGE) << "R_hit - TPC Rmin - ((RowIndex + 0.5 )* padheight) = " << rHit_diff << endl; - } return; } #endif - -double DDTPCDigiProcessor::getPadPhi( CLHEP::Hep3Vector *thisPoint, CLHEP::Hep3Vector* firstPoint, CLHEP::Hep3Vector* middlePoint, CLHEP::Hep3Vector* lastPoint){ - - CLHEP::Hep2Vector firstPointRPhi(firstPoint->x(),firstPoint->y()); - CLHEP::Hep2Vector middlePointRPhi(middlePoint->x(),middlePoint->y()); - CLHEP::Hep2Vector lastPointRPhi(lastPoint->x(),lastPoint->y()); - - // check that the points are not the same, at least at the level of a tenth of a micron - if( (fabs( firstPointRPhi.x() - middlePointRPhi.x() ) < 1.e-05 && fabs( firstPointRPhi.y() - middlePointRPhi.y() ) < 1.e-05) - || - (fabs( middlePointRPhi.x() - lastPointRPhi.x() ) < 1.e-05 && fabs( middlePointRPhi.y() - lastPointRPhi.y() ) < 1.e-05) - || - (fabs( firstPointRPhi.x() - lastPointRPhi.x() ) < 1.e-05 && fabs( firstPointRPhi.y() - lastPointRPhi.y() ) < 1.e-05) - ) { - - streamlog_out(WARNING) << " DDTPCDigiProcessor::getPadPhi " - << "2 of the 3 SimTracker hits passed to Circle Fit are the same hit taking pad phi as PI/2\n" - << " firstPoint->x() " << firstPoint->x() - << " firstPoint->y() " << firstPoint->y() - << " firstPoint->z() " << firstPoint->z() - << " middlePoint->x() " << middlePoint->x() - << " middlePoint->y() " << middlePoint->y() - << " middlePoint->z() " << middlePoint->z() - << " lastPoint->x() " << lastPoint->x() - << " lastPoint->y() " << lastPoint->y() - << " lastPoint.z() " << lastPoint->z() - << std::endl ; - - return twopi/4.0 ; - +double DDTPCDigiProcessor::getPadPhi(CLHEP::Hep3Vector* thisPoint, CLHEP::Hep3Vector* firstPoint, + CLHEP::Hep3Vector* middlePoint, CLHEP::Hep3Vector* lastPoint) { + + CLHEP::Hep2Vector firstPointRPhi(firstPoint->x(), firstPoint->y()); + CLHEP::Hep2Vector middlePointRPhi(middlePoint->x(), middlePoint->y()); + CLHEP::Hep2Vector lastPointRPhi(lastPoint->x(), lastPoint->y()); + + // check that the points are not the same, at least at the level of a tenth of a micron + if ((fabs(firstPointRPhi.x() - middlePointRPhi.x()) < 1.e-05 && + fabs(firstPointRPhi.y() - middlePointRPhi.y()) < 1.e-05) || + (fabs(middlePointRPhi.x() - lastPointRPhi.x()) < 1.e-05 && + fabs(middlePointRPhi.y() - lastPointRPhi.y()) < 1.e-05) || + (fabs(firstPointRPhi.x() - lastPointRPhi.x()) < 1.e-05 && + fabs(firstPointRPhi.y() - lastPointRPhi.y()) < 1.e-05)) { + + streamlog_out(WARNING) + << " DDTPCDigiProcessor::getPadPhi " + << "2 of the 3 SimTracker hits passed to Circle Fit are the same hit taking pad phi as PI/2\n" + << " firstPoint->x() " << firstPoint->x() << " firstPoint->y() " << firstPoint->y() << " firstPoint->z() " + << firstPoint->z() << " middlePoint->x() " << middlePoint->x() << " middlePoint->y() " << middlePoint->y() + << " middlePoint->z() " << middlePoint->z() << " lastPoint->x() " << lastPoint->x() << " lastPoint->y() " + << lastPoint->y() << " lastPoint.z() " << lastPoint->z() << std::endl; + + return twopi / 4.0; } - - - + Circle theCircle(&firstPointRPhi, &middlePointRPhi, &lastPointRPhi); - - double localPhi = atan2((thisPoint->y() - theCircle.GetCenter()->y()) ,(thisPoint->x() - theCircle.GetCenter()->x())) + (twopi/4.0) ; - - if(localPhi>twopi) localPhi=localPhi - twopi; - if(localPhi<0.0) localPhi=localPhi + twopi; - if(localPhi>twopi/2.0) localPhi = localPhi - twopi/2.0 ; - + + double localPhi = + atan2((thisPoint->y() - theCircle.GetCenter()->y()), (thisPoint->x() - theCircle.GetCenter()->x())) + + (twopi / 4.0); + + if (localPhi > twopi) + localPhi = localPhi - twopi; + if (localPhi < 0.0) + localPhi = localPhi + twopi; + if (localPhi > twopi / 2.0) + localPhi = localPhi - twopi / 2.0; + double pointPhi = thisPoint->phi(); - - if(pointPhi>twopi) pointPhi=pointPhi - twopi; - if(pointPhi<0.0) pointPhi=pointPhi + twopi; - if(pointPhi>twopi/2.0) pointPhi = pointPhi - twopi/2.0 ; - + + if (pointPhi > twopi) + pointPhi = pointPhi - twopi; + if (pointPhi < 0.0) + pointPhi = pointPhi + twopi; + if (pointPhi > twopi / 2.0) + pointPhi = pointPhi - twopi / 2.0; + double padPhi = fabs(pointPhi - localPhi); - - // check that the value returned is reasonable - if( std::isnan(padPhi) || std::isinf(padPhi) ) { + + // check that the value returned is reasonable + if (std::isnan(padPhi) || std::isinf(padPhi)) { std::stringstream errorMsg; - errorMsg << "\nProcessor: DDTPCDigiProcessor \n" - << "padPhi = " - << padPhi - << "\n" ; + errorMsg << "\nProcessor: DDTPCDigiProcessor \n" + << "padPhi = " << padPhi << "\n"; throw Exception(errorMsg.str()); } - + return padPhi; - } -double DDTPCDigiProcessor::getPadTheta(CLHEP::Hep3Vector* firstPoint, CLHEP::Hep3Vector* middlePoint, CLHEP::Hep3Vector* lastPoint){ - +double DDTPCDigiProcessor::getPadTheta(CLHEP::Hep3Vector* firstPoint, CLHEP::Hep3Vector* middlePoint, + CLHEP::Hep3Vector* lastPoint) { + // Calculate thetaPad for current hit - CLHEP::Hep2Vector firstPointRPhi(firstPoint->x(),firstPoint->y()) ; - CLHEP::Hep2Vector middlePointRPhi(middlePoint->x(),middlePoint->y()); - CLHEP::Hep2Vector lastPointRPhi(lastPoint->x(),lastPoint->y()); - - // check that the points are not the same, at least at the level of a tenth of a micron - if( (fabs( firstPointRPhi.x() - middlePointRPhi.x() ) < 1.e-05 && fabs( firstPointRPhi.y() - middlePointRPhi.y() ) < 1.e-05) - || - (fabs( middlePointRPhi.x() - lastPointRPhi.x() ) < 1.e-05 && fabs( middlePointRPhi.y() - lastPointRPhi.y() ) < 1.e-05) - || - (fabs( firstPointRPhi.x() - lastPointRPhi.x() ) < 1.e-05 && fabs( firstPointRPhi.y() - lastPointRPhi.y() ) < 1.e-05) - ) { - - streamlog_out(WARNING) << " DDTPCDigiProcessor::getPadTheta " - << "2 of the 3 SimTracker hits passed to Circle Fit are the same hit taking pad phi as PI/2\n" - << " firstPoint->x() " << firstPoint->x() - << " firstPoint->y() " << firstPoint->y() - << " firstPoint->z() " << firstPoint->z() - << " middlePoint->x() " << middlePoint->x() - << " middlePoint->y() " << middlePoint->y() - << " middlePoint->z() " << middlePoint->z() - << " lastPoint->x() " << lastPoint->x() - << " lastPoint->y() " << lastPoint->y() - << " lastPoint.z() " << lastPoint->z() - << std::endl ; - - return twopi/4.0 ; - + CLHEP::Hep2Vector firstPointRPhi(firstPoint->x(), firstPoint->y()); + CLHEP::Hep2Vector middlePointRPhi(middlePoint->x(), middlePoint->y()); + CLHEP::Hep2Vector lastPointRPhi(lastPoint->x(), lastPoint->y()); + + // check that the points are not the same, at least at the level of a tenth of a micron + if ((fabs(firstPointRPhi.x() - middlePointRPhi.x()) < 1.e-05 && + fabs(firstPointRPhi.y() - middlePointRPhi.y()) < 1.e-05) || + (fabs(middlePointRPhi.x() - lastPointRPhi.x()) < 1.e-05 && + fabs(middlePointRPhi.y() - lastPointRPhi.y()) < 1.e-05) || + (fabs(firstPointRPhi.x() - lastPointRPhi.x()) < 1.e-05 && + fabs(firstPointRPhi.y() - lastPointRPhi.y()) < 1.e-05)) { + + streamlog_out(WARNING) + << " DDTPCDigiProcessor::getPadTheta " + << "2 of the 3 SimTracker hits passed to Circle Fit are the same hit taking pad phi as PI/2\n" + << " firstPoint->x() " << firstPoint->x() << " firstPoint->y() " << firstPoint->y() << " firstPoint->z() " + << firstPoint->z() << " middlePoint->x() " << middlePoint->x() << " middlePoint->y() " << middlePoint->y() + << " middlePoint->z() " << middlePoint->z() << " lastPoint->x() " << lastPoint->x() << " lastPoint->y() " + << lastPoint->y() << " lastPoint.z() " << lastPoint->z() << std::endl; + + return twopi / 4.0; } - - + Circle theCircle(&firstPointRPhi, &middlePointRPhi, &lastPointRPhi); - + double deltaPhi = firstPoint->deltaPhi(*lastPoint); - - double pathlength = fabs(deltaPhi) * theCircle.GetRadius(); - - double padTheta = atan ( pathlength / fabs(lastPoint->z() - firstPoint->z()) ) ; - - double pathlength1 = 2.0 * asin( ( sqrt ( - (middlePointRPhi.x() - firstPointRPhi.x()) * (middlePointRPhi.x()-firstPointRPhi.x()) - + - (middlePointRPhi.y()-firstPointRPhi.y()) * (middlePointRPhi.y()-firstPointRPhi.y()) - ) / 2.0 ) / theCircle.GetRadius() ) * theCircle.GetRadius() ; - - - double pathlength2 = ( ( sqrt ( (lastPointRPhi.x()-middlePointRPhi.x()) * (lastPointRPhi.x()-middlePointRPhi.x()) - + (lastPointRPhi.y()-middlePointRPhi.y()) * (lastPointRPhi.y()-middlePointRPhi.y()) - ) / 2.0 ) / theCircle.GetRadius() >= 1.0 ) ? - ( 2.0 * asin( 1.0 ) * theCircle.GetRadius() ) - : - ( 2.0 * asin( ( sqrt ( - (lastPointRPhi.x()-middlePointRPhi.x()) * (lastPointRPhi.x()-middlePointRPhi.x()) - + - (lastPointRPhi.y()-middlePointRPhi.y()) * (lastPointRPhi.y()-middlePointRPhi.y()) - ) / 2.0 ) / theCircle.GetRadius() ) * theCircle.GetRadius() ) ; - - padTheta = atan ((fabs(pathlength1 + pathlength2)) / (fabs(lastPoint->z() - firstPoint->z())) ) ; - - // check that the value returned is reasonable - if( std::isnan(padTheta) || std::isinf(padTheta) ) { + + double pathlength = fabs(deltaPhi) * theCircle.GetRadius(); + + double padTheta = atan(pathlength / fabs(lastPoint->z() - firstPoint->z())); + + double pathlength1 = + 2.0 * + asin((sqrt((middlePointRPhi.x() - firstPointRPhi.x()) * (middlePointRPhi.x() - firstPointRPhi.x()) + + (middlePointRPhi.y() - firstPointRPhi.y()) * (middlePointRPhi.y() - firstPointRPhi.y())) / + 2.0) / + theCircle.GetRadius()) * + theCircle.GetRadius(); + + double pathlength2 = + ((sqrt((lastPointRPhi.x() - middlePointRPhi.x()) * (lastPointRPhi.x() - middlePointRPhi.x()) + + (lastPointRPhi.y() - middlePointRPhi.y()) * (lastPointRPhi.y() - middlePointRPhi.y())) / + 2.0) / + theCircle.GetRadius() >= + 1.0) + ? (2.0 * asin(1.0) * theCircle.GetRadius()) + : (2.0 * + asin((sqrt((lastPointRPhi.x() - middlePointRPhi.x()) * (lastPointRPhi.x() - middlePointRPhi.x()) + + (lastPointRPhi.y() - middlePointRPhi.y()) * (lastPointRPhi.y() - middlePointRPhi.y())) / + 2.0) / + theCircle.GetRadius()) * + theCircle.GetRadius()); + + padTheta = atan((fabs(pathlength1 + pathlength2)) / (fabs(lastPoint->z() - firstPoint->z()))); + + // check that the value returned is reasonable + if (std::isnan(padTheta) || std::isinf(padTheta)) { std::stringstream errorMsg; - errorMsg << "\nProcessor: DDTPCDigiProcessor \n" - << "padTheta = " - << padTheta - << "\n" ; + errorMsg << "\nProcessor: DDTPCDigiProcessor \n" + << "padTheta = " << padTheta << "\n"; throw Exception(errorMsg.str()); } - + return padTheta; - } diff --git a/source/Digitisers/src/FixedPadSizeDiskLayout.cc b/source/Digitisers/src/FixedPadSizeDiskLayout.cc index dbcb8eb..8fdfaa4 100644 --- a/source/Digitisers/src/FixedPadSizeDiskLayout.cc +++ b/source/Digitisers/src/FixedPadSizeDiskLayout.cc @@ -1,111 +1,90 @@ #include "FixedPadSizeDiskLayout.h" #include -#include #include +#include #include #include -#include "DDRec/DetectorData.h" #include "DD4hep/DD4hepUnits.h" +#include "DDRec/DetectorData.h" +FixedPadSizeDiskLayout::~FixedPadSizeDiskLayout() { cleanup(); } -FixedPadSizeDiskLayout::~FixedPadSizeDiskLayout() -{ - cleanup(); -} - -void FixedPadSizeDiskLayout::cleanup() -{ - for( unsigned i=0; i<_padIndices.size(); ++i ){ - delete _padIndices[i] ; +void FixedPadSizeDiskLayout::cleanup() { + for (unsigned i = 0; i < _padIndices.size(); ++i) { + delete _padIndices[i]; } } -FixedPadSizeDiskLayout::FixedPadSizeDiskLayout(const dd4hep::rec::FixedPadSizeTPCData* tpc) : - _rMin( tpc->rMinReadout/dd4hep::mm ), - _rMax( tpc->rMaxReadout/dd4hep::mm ), - _phiMax( 2.*M_PI ), - _padWidth( tpc->padWidth/dd4hep::mm ), - _padHeight(tpc->padHeight/dd4hep::mm), - _padGap( tpc->padGap/dd4hep::mm ), - _nRow( tpc->maxRow ) { - - _extent.resize(4) ; - _extent[0] = _rMin ; - _extent[1] = _rMax ; - _extent[2] = 0.0 ; - _extent[3] = _phiMax ; - - // compute the row properties +FixedPadSizeDiskLayout::FixedPadSizeDiskLayout(const dd4hep::rec::FixedPadSizeTPCData* tpc) + : _rMin(tpc->rMinReadout / dd4hep::mm), _rMax(tpc->rMaxReadout / dd4hep::mm), _phiMax(2. * M_PI), + _padWidth(tpc->padWidth / dd4hep::mm), _padHeight(tpc->padHeight / dd4hep::mm), _padGap(tpc->padGap / dd4hep::mm), + _nRow(tpc->maxRow) { - int nr = ( ( _rMax + 0.01 - _rMin ) / _padHeight ) ; + _extent.resize(4); + _extent[0] = _rMin; + _extent[1] = _rMax; + _extent[2] = 0.0; + _extent[3] = _phiMax; - _nRow = ( _nRow > 0 ) ? _nRow : nr ; + // compute the row properties - if( _nRow > nr ) { + int nr = ((_rMax + 0.01 - _rMin) / _padHeight); - std::cout << " WARNING: FixedPadSizeDiskLayout() : cannot place " << _nRow - << " rows of height " << _padHeight - << " mm between rMin = " << _rMin << " mm and rMax = " << _rMax - << " mm - will use nRow = " << nr << " !! " - << std::endl ; + _nRow = (_nRow > 0) ? _nRow : nr; - _nRow = nr ; + if (_nRow > nr) { + std::cout << " WARNING: FixedPadSizeDiskLayout() : cannot place " << _nRow << " rows of height " << _padHeight + << " mm between rMin = " << _rMin << " mm and rMax = " << _rMax << " mm - will use nRow = " << nr + << " !! " << std::endl; + _nRow = nr; } - _padIndices.resize( _nRow ) ; + _padIndices.resize(_nRow); // initialise all pointers to 0 // this thing is only filled when accessed by getPadsInRow() the first time // to allocate the memory only when needed - for (std::vector< std::vector* >::iterator rowIter = _padIndices.begin() ; - rowIter < _padIndices.end(); rowIter++) - { - *rowIter=0; - } + for (std::vector*>::iterator rowIter = _padIndices.begin(); rowIter < _padIndices.end(); rowIter++) { + *rowIter = 0; + } - _rowHeight = ( _rMax - _rMin ) / _nRow ; + _rowHeight = (_rMax - _rMin) / _nRow; - _nPad = 0 ; + _nPad = 0; - for( int i = 0 ; i < _nRow ; i++ ) { + for (int i = 0; i < _nRow; i++) { - Row row ; + Row row; - row.RCenter = _rMin + ( i * _rowHeight ) + .5 * _rowHeight ; + row.RCenter = _rMin + (i * _rowHeight) + .5 * _rowHeight; - double u = row.RCenter * _phiMax ; + double u = row.RCenter * _phiMax; - row.NPad = static_cast( std::floor( u / (_padWidth + _padGap ) ) ); + row.NPad = static_cast(std::floor(u / (_padWidth + _padGap))); - row.PhiPad = _phiMax / row.NPad ; + row.PhiPad = _phiMax / row.NPad; // std::cout << " row, row.NPad , row.PhiPad : " << i << " , " << row.NPad << " , " << row.PhiPad // << std::endl; - _nPad += row.NPad ; + _nPad += row.NPad; - _rows.push_back( row ) ; + _rows.push_back(row); } - } -FixedPadSizeDiskLayout::FixedPadSizeDiskLayout( const FixedPadSizeDiskLayout & right) -{ - copy_and_assign(right); -} +FixedPadSizeDiskLayout::FixedPadSizeDiskLayout(const FixedPadSizeDiskLayout& right) { copy_and_assign(right); } -FixedPadSizeDiskLayout & FixedPadSizeDiskLayout::operator = ( const FixedPadSizeDiskLayout & right) -{ +FixedPadSizeDiskLayout& FixedPadSizeDiskLayout::operator=(const FixedPadSizeDiskLayout& right) { cleanup(); copy_and_assign(right); return *this; } -void FixedPadSizeDiskLayout::copy_and_assign(const FixedPadSizeDiskLayout & right) -{ +void FixedPadSizeDiskLayout::copy_and_assign(const FixedPadSizeDiskLayout& right) { _rMin = right._rMin; _rMax = right._rMax; _phiMax = right._phiMax; @@ -122,112 +101,96 @@ void FixedPadSizeDiskLayout::copy_and_assign(const FixedPadSizeDiskLayout & rig // In every instance, also the copied ones, it is filled only at first // usage to save memory // just like in the constructor - _padIndices.resize( _nRow ) ; - for (std::vector< std::vector* >::iterator rowIter = _padIndices.begin() ; - rowIter < _padIndices.end(); rowIter++) - { - *rowIter=0; - } - - -} - -int FixedPadSizeDiskLayout::getNRows() const { - return _rows.size() ; + _padIndices.resize(_nRow); + for (std::vector*>::iterator rowIter = _padIndices.begin(); rowIter < _padIndices.end(); rowIter++) { + *rowIter = 0; + } } +int FixedPadSizeDiskLayout::getNRows() const { return _rows.size(); } double FixedPadSizeDiskLayout::getPadWidth(int padIndex) const { // phi of pad in row : - int rowNum = getRowNumber( padIndex ) ; + int rowNum = getRowNumber(padIndex); try { // need to return padWidth in radians !! - return _padWidth / _rows.at( rowNum ).RCenter ; + return _padWidth / _rows.at(rowNum).RCenter; - } - catch(std::out_of_range){ - return 0. ; + } catch (std::out_of_range) { + return 0.; } } double FixedPadSizeDiskLayout::getPadPitch(int padIndex) const { // phi of pad in row : - int rowNum = getRowNumber( padIndex ) ; + int rowNum = getRowNumber(padIndex); try { // need to return padPitch in radians !! - return _rows.at( rowNum ).PhiPad; + return _rows.at(rowNum).PhiPad; - } - catch(std::out_of_range){ - return 0. ; + } catch (std::out_of_range) { + return 0.; } } +dd4hep::rec::Vector2D FixedPadSizeDiskLayout::getPadCenter(int padIndex) const { + int rowNum = getRowNumber(padIndex); + int padNum = getPadNumber(padIndex); -dd4hep::rec::Vector2D FixedPadSizeDiskLayout::getPadCenter(int padIndex) const { - - int rowNum = getRowNumber( padIndex ) ; - int padNum = getPadNumber( padIndex ) ; + double r = _rows[rowNum].RCenter; - double r = _rows[ rowNum ].RCenter ; + double phi = (padNum + 0.5) * _rows[rowNum].PhiPad; - double phi = ( padNum + 0.5 ) * _rows[ rowNum ].PhiPad ; - - return dd4hep::rec::Vector2D( r , phi ) ; + return dd4hep::rec::Vector2D(r, phi); } const std::vector& FixedPadSizeDiskLayout::getPadsInRow(int rowNumber) const { - static std::vector empty ; + static std::vector empty; try { - if( _padIndices.at(rowNumber ) == 0 ) { + if (_padIndices.at(rowNumber) == 0) { - int nPad = _rows.at(rowNumber).NPad ; + int nPad = _rows.at(rowNumber).NPad; - _padIndices[ rowNumber ] = new std::vector( nPad ) ; + _padIndices[rowNumber] = new std::vector(nPad); - for(int i = 0 ; i < nPad ; i++){ + for (int i = 0; i < nPad; i++) { - _padIndices[rowNumber]->operator[](i) = getPadIndex( rowNumber , i ) ; + _padIndices[rowNumber]->operator[](i) = getPadIndex(rowNumber, i); } - } - } catch( std::out_of_range& r) { + } catch (std::out_of_range& r) { // std::cout << " FixedPadSizeDiskLayout::getPadsInRow : no row " << rowNumber << std::endl ; - return empty ; - + return empty; } - return *_padIndices[ rowNumber ] ; - + return *_padIndices[rowNumber]; } int FixedPadSizeDiskLayout::getPadIndex(int rowNum, int padNum) const { - if( (unsigned) rowNum > _rows.size() - 1 ) { + if ((unsigned)rowNum > _rows.size() - 1) { throw std::out_of_range(" FixedPadSizeDiskLayout::getPadIndex row number too large !"); } - if( padNum > _rows[rowNum].NPad - 1 ) { + if (padNum > _rows[rowNum].NPad - 1) { - std::stringstream sstr ; + std::stringstream sstr; - sstr << "FixedPadSizeDiskLayout::getPadIndex: pad number too large: " - << padNum << " only " << _rows[rowNum].NPad << " pads in row " << rowNum ; + sstr << "FixedPadSizeDiskLayout::getPadIndex: pad number too large: " << padNum << " only " << _rows[rowNum].NPad + << " pads in row " << rowNum; - throw std::out_of_range( sstr.str() ); + throw std::out_of_range(sstr.str()); } - return (rowNum << 16 ) | ( 0x0000ffff & padNum ) ; - - + return (rowNum << 16) | (0x0000ffff & padNum); } int FixedPadSizeDiskLayout::getNearestPad(double r, double phi) const { @@ -235,239 +198,238 @@ int FixedPadSizeDiskLayout::getNearestPad(double r, double phi) const { if (fabs(r) < 1e-6) throw std::runtime_error("FixedPadSizeDiskLayout::getNearestPad: r can't be zero !"); - // Initialise with the radius itself. In case of a full circle there is no + // Initialise with the radius itself. In case of a full circle there is no // phiMin or phiMax, just to avoid compiler warnings double rProjectedOnPhiMax = r; double rProjectedOnPhiMin = r; - - if (fabs(_phiMax - 2*M_PI) < 1e-6) { - + + if (fabs(_phiMax - 2 * M_PI) < 1e-6) { + // wrap phi to 0 < phi < 2*M_PI - while( phi < 0 ) { phi += 2. * M_PI ; } - while( phi > 2.*M_PI ) { phi -= 2. * M_PI ; } - + while (phi < 0) { + phi += 2. * M_PI; + } + while (phi > 2. * M_PI) { + phi -= 2. * M_PI; + } + } else { - - while( phi < -2*M_PI ) { phi += 2. * M_PI ; } - while( phi > 2.*M_PI ) { phi -= 2. * M_PI ; } - + + while (phi < -2 * M_PI) { + phi += 2. * M_PI; + } + while (phi > 2. * M_PI) { + phi -= 2. * M_PI; + } + rProjectedOnPhiMax = r * cos(phi - _phiMax); rProjectedOnPhiMin = r * cos(phi - 0.); - } - + // - + int rowNum = 0; int padNum = 0; // We make two distinct cases: // Area 1: The point (r, phi) is inside (r > 0, phiMin <= phi <= phiMax), // Area 2: Points outside Area 1. - + // Area 1 // This was the original code for the whole circle. (Modified a bit) - - if ( r > 0. && phi >= 0. && phi <= _phiMax) { - rowNum = r < _rMin ? 0 : (int) std::floor( ( r - _rMin ) / _rowHeight ) ; - - if( rowNum >= _nRow ) - rowNum = _nRow -1 ; - - padNum = (int) std::floor( phi / _rows[ rowNum ].PhiPad ) ; - - if( padNum >= _rows[ rowNum ].NPad ) - padNum = _rows[ rowNum ].NPad - 1 ; - + + if (r > 0. && phi >= 0. && phi <= _phiMax) { + rowNum = r < _rMin ? 0 : (int)std::floor((r - _rMin) / _rowHeight); + + if (rowNum >= _nRow) + rowNum = _nRow - 1; + + padNum = (int)std::floor(phi / _rows[rowNum].PhiPad); + + if (padNum >= _rows[rowNum].NPad) + padNum = _rows[rowNum].NPad - 1; + // std::cout << " FixedPadSizeDiskLayout::getNearestPad( " << r << " , " << phi << " ) " // << " _rows[ rowNum ].PhiPad : " << _rows[ rowNum ].PhiPad // << std::endl ; - - return getPadIndex( rowNum , padNum ) ; + + return getPadIndex(rowNum, padNum); } - + // Area 2 can be optimized by dividing it into more areas. // Then we don't need to calculate distances at all! // For best understanding you need to draw all the areas on paper by hand. // // Expensive condition checkings are moved towards the end. - - else if ( rProjectedOnPhiMin < _rMin && phi < 0 ) { - //std::cout << "r < _rMin && phi < 0" << std::endl; - + + else if (rProjectedOnPhiMin < _rMin && phi < 0) { + // std::cout << "r < _rMin && phi < 0" << std::endl; + rowNum = 0; padNum = 0; } - - else if ( rProjectedOnPhiMin > _rMax && phi < 0 ) { - //std::cout << "r > _rMax && phi < 0" << std::endl; - + + else if (rProjectedOnPhiMin > _rMax && phi < 0) { + // std::cout << "r > _rMax && phi < 0" << std::endl; + rowNum = _nRow - 1; padNum = 0; } - - else if ( rProjectedOnPhiMax < _rMin && phi > _phiMax ) { - //std::cout << "r < _rMin * cos(phi - _phiMax) && phi > _phiMax" << std::endl; - + + else if (rProjectedOnPhiMax < _rMin && phi > _phiMax) { + // std::cout << "r < _rMin * cos(phi - _phiMax) && phi > _phiMax" << std::endl; + rowNum = 0; - padNum = _rows[ rowNum ].NPad - 1 ; + padNum = _rows[rowNum].NPad - 1; } - else if ( rProjectedOnPhiMax > _rMax && phi > _phiMax ) { - //std::cout << "r > _rMax * cos(phi - _phiMax) && phi > _phiMax" << std::endl; - + else if (rProjectedOnPhiMax > _rMax && phi > _phiMax) { + // std::cout << "r > _rMax * cos(phi - _phiMax) && phi > _phiMax" << std::endl; + rowNum = _nRow - 1; - padNum = _rows[ rowNum ].NPad - 1 ; + padNum = _rows[rowNum].NPad - 1; } - else if ( rProjectedOnPhiMin >= _rMin && rProjectedOnPhiMin <= _rMax && phi < 0 ) { - //std::cout << "r >= _rMin && r <= _rMax && phi < 0" << std::endl; - + else if (rProjectedOnPhiMin >= _rMin && rProjectedOnPhiMin <= _rMax && phi < 0) { + // std::cout << "r >= _rMin && r <= _rMax && phi < 0" << std::endl; + r = rProjectedOnPhiMin; - - rowNum = (int) std::floor( ( r - _rMin ) / _rowHeight ) ; + + rowNum = (int)std::floor((r - _rMin) / _rowHeight); rowNum = rowNum < 0 ? 0 : rowNum; - rowNum = rowNum >= _nRow ? _nRow -1 : rowNum; - + rowNum = rowNum >= _nRow ? _nRow - 1 : rowNum; + padNum = 0; } - - else if ( rProjectedOnPhiMax >= _rMin && rProjectedOnPhiMax <= _rMax && phi > _phiMax ) { - //std::cout << "r >= _rMin * cos(phi - _phiMax) && r <= _rMax * cos(phi - _phiMax) && phi > _phiMax" << std::endl; - + + else if (rProjectedOnPhiMax >= _rMin && rProjectedOnPhiMax <= _rMax && phi > _phiMax) { + // std::cout << "r >= _rMin * cos(phi - _phiMax) && r <= _rMax * cos(phi - _phiMax) && phi > _phiMax" << std::endl; + r = rProjectedOnPhiMax; - - rowNum = (int) std::floor( ( r - _rMin ) / _rowHeight ) ; - + + rowNum = (int)std::floor((r - _rMin) / _rowHeight); + rowNum = rowNum < 0 ? 0 : rowNum; - rowNum = rowNum >= _nRow ? _nRow -1 : rowNum; - - padNum = _rows[ rowNum ].NPad - 1 ; + rowNum = rowNum >= _nRow ? _nRow - 1 : rowNum; + + padNum = _rows[rowNum].NPad - 1; } else { - std::cout - << "I have no idea where the nearest pad is for the point (" - << r << ", " - << phi << ")" - << std::endl; - + std::cout << "I have no idea where the nearest pad is for the point (" << r << ", " << phi << ")" << std::endl; + rowNum = 0; padNum = 0; } - return getPadIndex( rowNum , padNum ) ; - + return getPadIndex(rowNum, padNum); + // Another implementation that was implemented before the upper // implementation. - + // Area 2 // Check each pad that is on the border, except for the pads on the most // outer circle, since that one is in Area 1. - - //float r_pad, p_pad; - //float x_pad, y_pad; + + // float r_pad, p_pad; + // float x_pad, y_pad; // - //float minDistance = 0; - //float curDistance = 0.; + // float minDistance = 0; + // float curDistance = 0.; // - //float minR = 0.; - //float minPhi = 0.; + // float minR = 0.; + // float minPhi = 0.; // - //for ( - // std::vector::const_iterator it = _rows.begin(); - // it != _rows.end(); - // ++it + // for ( + // std::vector::const_iterator it = _rows.begin(); + // it != _rows.end(); + // ++it //) { - // - // for ( + // + // for ( // float checkPhi = 0.5 * it->PhiPad; // checkPhi < it->PhiPad * it->NPad; // checkPhi += it->PhiPad - // ) { - // + // ) { + // // r_pad = it->RCenter; // p_pad = checkPhi; - // + // // x_pad = r_pad * cos(p_pad); // y_pad = r_pad * sin(p_pad); - // + // // curDistance = pow(x_pad - r*cos(phi), 2) + pow(y_pad - r*sin(phi), 2); - // + // // if ( // (curDistance < minDistance) // || (it == _rows.begin() && checkPhi - 0.5 * it->PhiPad < 1e-6) // ) { // minDistance = curDistance; - // + // // minR = r_pad; // minPhi = p_pad; // } - // + // // // When it is not the row closest to the origin, // // jump to the second last pad in the row // // (the foreach loop will then jump to the last pad) - // + // // if (it != _rows.begin()) { // checkPhi += it->PhiPad * (it->NPad - 2); // } - // - // } - // - //} // - //rowNum = (int) std::floor( ( minR - _rMin ) / _rowHeight ) ; - // - //padNum = (int) std::floor( minPhi / _rows[ rowNum ].PhiPad ) ; + // } + // + // } + // + // rowNum = (int) std::floor( ( minR - _rMin ) / _rowHeight ) ; + // + // padNum = (int) std::floor( minPhi / _rows[ rowNum ].PhiPad ) ; - //return getPadIndex( rowNum , padNum ) ; + // return getPadIndex( rowNum , padNum ) ; } int FixedPadSizeDiskLayout::getLeftNeighbour(int padIndex) const { - int pn = getPadNumber( padIndex ) + 1 ; - int rn = getRowNumber( padIndex) ; + int pn = getPadNumber(padIndex) + 1; + int rn = getRowNumber(padIndex); + + int nPad = _rows.at(rn).NPad; - int nPad = _rows.at(rn).NPad ; + if (pn > nPad - 1) { - if( pn > nPad-1 ) { - // If it is a full circle, go back to the first one. - if (fabs(_phiMax - 2*M_PI) < 1e-6) + if (fabs(_phiMax - 2 * M_PI) < 1e-6) pn = 0; else throw std::runtime_error("FixedPadSizeDiskLayout::getLeftNeighbour: no left neighbour pad !"); - } - - return getPadIndex( rn , pn ) ; + return getPadIndex(rn, pn); } int FixedPadSizeDiskLayout::getRightNeighbour(int padIndex) const { - int pn = getPadNumber( padIndex ) - 1 ; - int rn = getRowNumber( padIndex) ; + int pn = getPadNumber(padIndex) - 1; + int rn = getRowNumber(padIndex); - int nPad = _rows.at(rn).NPad ; + int nPad = _rows.at(rn).NPad; - if( pn < 0 ){ + if (pn < 0) { // If it is a full circle, go back to the last one. - if (fabs(_phiMax - 2*M_PI) < 1e-6) + if (fabs(_phiMax - 2 * M_PI) < 1e-6) pn = nPad - 1; else throw std::runtime_error("FixedPadSizeDiskLayout::getRightNeighbour: no right neighbour pad !"); - } - return getPadIndex( rn , pn ) ; + return getPadIndex(rn, pn); } - bool FixedPadSizeDiskLayout::isInsidePad(double r, double phi, int padIndex) const { // double rCenter = 0. ; @@ -478,20 +440,23 @@ bool FixedPadSizeDiskLayout::isInsidePad(double r, double phi, int padIndex) con // return false ; // } - if( r < _rMin || r > _rMax ) - return false ; + if (r < _rMin || r > _rMax) + return false; // wrap phi to 0 < phi < 2*M_PI - - while( phi < 0 ) { phi += 2. * M_PI ; } - while( phi > 2.*M_PI ) { phi -= 2. * M_PI ; } - dd4hep::rec::Vector2D p = getPadCenter( padIndex ) ; + while (phi < 0) { + phi += 2. * M_PI; + } + while (phi > 2. * M_PI) { + phi -= 2. * M_PI; + } - // double phiPadHalf = 0.5 * _padWidth / rCenter ; + dd4hep::rec::Vector2D p = getPadCenter(padIndex); - double phiPadHalf = 0.5 * getPadWidth( padIndex ) ; + // double phiPadHalf = 0.5 * _padWidth / rCenter ; + double phiPadHalf = 0.5 * getPadWidth(padIndex); // std::cout << " isInsidePad( " << rowNumber << ", " << phiPadHalf << ", " << 0.5 * _padHeight // << " - ( " << p.first << ", " << p.second << " ) " @@ -502,21 +467,22 @@ bool FixedPadSizeDiskLayout::isInsidePad(double r, double phi, int padIndex) con // return ( std::abs( r - p.first ) <= 0.5 * _padHeight && // std::abs( phi - p.second ) <= phiPadHalf ) ; - return ( std::abs( r - p[0] ) <= 0.5 * _padHeight && - std::abs( phi - p[1] ) <= phiPadHalf ) ; - + return (std::abs(r - p[0]) <= 0.5 * _padHeight && std::abs(phi - p[1]) <= phiPadHalf); } bool FixedPadSizeDiskLayout::isInsidePad(double r, double phi) const { - if( r < _rMin || r > _rMax ) - return false ; + if (r < _rMin || r > _rMax) + return false; // wrap phi to 0 < phi < 2*M_PI - - while( phi < 0 ) { phi += 2. * M_PI ; } - while( phi > 2.*M_PI ) { phi -= 2. * M_PI ; } - return isInsidePad( r , phi , getNearestPad( r, phi ) ) ; + while (phi < 0) { + phi += 2. * M_PI; + } + while (phi > 2. * M_PI) { + phi -= 2. * M_PI; + } + return isInsidePad(r, phi, getNearestPad(r, phi)); } diff --git a/source/Digitisers/src/FixedPadSizeDiskLayout.h b/source/Digitisers/src/FixedPadSizeDiskLayout.h index fd8d0c7..22d9a48 100644 --- a/source/Digitisers/src/FixedPadSizeDiskLayout.h +++ b/source/Digitisers/src/FixedPadSizeDiskLayout.h @@ -1,14 +1,12 @@ #ifndef FixedPadSizeDiskLayout_h #define FixedPadSizeDiskLayout_h 1 -#include #include +#include #include "DDRec/DetectorData.h" #include "DDRec/Vector2D.h" - - /** Implementation of PadRowLayout2D for a disk with fixed sized keystone pads. * The pads with the given height and width are distributed in symmetrical rings * starting with the pad number 0 above the x-axis so that the pad 0 is fully contained @@ -19,36 +17,34 @@ * @author F. Gaede, DESY */ class FixedPadSizeDiskLayout { - + public: - /** Internal helper class for FixedPadSizeDiskLayout */ struct Row { - int NPad {}; - double RCenter {}; - double PhiPad {}; - } ; - - + int NPad{}; + double RCenter{}; + double PhiPad{}; + }; + protected: - double _rMin {}; - double _rMax {}; - double _phiMax {}; - double _rowHeight {}; - double _padWidth {}; - double _padHeight {}; - double _padGap {}; - int _nRow {}; - int _nPad {}; - std::vector _rows {}; - std::vector _extent {}; - mutable std::vector< std::vector* > _padIndices {}; - + double _rMin{}; + double _rMax{}; + double _phiMax{}; + double _rowHeight{}; + double _padWidth{}; + double _padHeight{}; + double _padGap{}; + int _nRow{}; + int _nPad{}; + std::vector _rows{}; + std::vector _extent{}; + mutable std::vector*> _padIndices{}; + /** function to copy all internal variables, incl. the objects * pointed to and owned by the FixedPadSizeDiskLayout. * Used by constructor and assigment operator to avoid code duplication */ - void copy_and_assign(const FixedPadSizeDiskLayout & ); + void copy_and_assign(const FixedPadSizeDiskLayout&); /** function to delete all the objects * pointed to and owned by the FixedPadSizeDiskLayout. @@ -56,110 +52,104 @@ class FixedPadSizeDiskLayout { */ void cleanup(); - public: - /** Construct the FixedPadSizeDiskLayout from the given parameters rMin, rMax, * padHeight and PadWidth where the maximum number of pads are fitted to the plane. * @param nRow : limits the number of rows - if given * @param padGap : additional gap between pads in r-phi in mm */ - FixedPadSizeDiskLayout( const dd4hep::rec::FixedPadSizeTPCData* tpc ) ; + FixedPadSizeDiskLayout(const dd4hep::rec::FixedPadSizeTPCData* tpc); - /** The copy constructor. * Needed because _padIndices allocates memory dynamically */ - FixedPadSizeDiskLayout( const FixedPadSizeDiskLayout &); + FixedPadSizeDiskLayout(const FixedPadSizeDiskLayout&); /// The assignment operator - FixedPadSizeDiskLayout & operator = ( const FixedPadSizeDiskLayout &); + FixedPadSizeDiskLayout& operator=(const FixedPadSizeDiskLayout&); /// Destructor. - ~FixedPadSizeDiskLayout() ; + ~FixedPadSizeDiskLayout(); /** The gap width in mm that was given in the C'tor. */ - double getPadGap() const { return _padGap ; } + double getPadGap() const { return _padGap; } /** The fixed width of the pads in mm. */ - double getFixedPadWidth() const { return _padWidth ; } - + double getFixedPadWidth() const { return _padWidth; } /** The total number of pads in the TPC. */ - int getNPads() const { return _nPad ; } + int getNPads() const { return _nPad; } /** The number of rows. */ - int getNRows() const ; + int getNRows() const; /** The row height in mm. */ - double getRowHeight(int /*rowNumber*/) const { return _rowHeight ; } + double getRowHeight(int /*rowNumber*/) const { return _rowHeight; } /** The height of the pad in mm. */ - double getPadHeight(int /*padIndex*/) const { return _padHeight ; } + double getPadHeight(int /*padIndex*/) const { return _padHeight; } /** The width of the pad in radians (only the metal) */ - double getPadWidth(int padIndex) const ; + double getPadWidth(int padIndex) const; /** The pitch of the pad in radians (metal + gap) */ - double getPadPitch(int padIndex) const ; + double getPadPitch(int padIndex) const; /** The center of the pad in 2d coordinates, (x,y) or (r,phi). */ - dd4hep::rec::Vector2D getPadCenter(int padIndex) const; - + dd4hep::rec::Vector2D getPadCenter(int padIndex) const; /** Indices of all pads in row rowNumber (row indices start from 0 at the * bottom (CARTESIAN) or at the center (POLAR)). */ - const std::vector& getPadsInRow(int rowNumber) const ; + const std::vector& getPadsInRow(int rowNumber) const; /** Extent of the sensitive plane - [xmin,xmax,ymin,ymax] CARTESIAN or * [rmin,rmax,phimin,phimax] POLAR. */ - const std::vector& getPlaneExtent() const { return _extent ; } + const std::vector& getPlaneExtent() const { return _extent; } /** The number of the row that contains the pad at padIndex - numbering starts at r/y==0. */ - int getRowNumber(int padIndex) const { return ( 0xffff0000 & padIndex ) >> 16 ; } + int getRowNumber(int padIndex) const { return (0xffff0000 & padIndex) >> 16; } /** The pad number (column) within the row - numbering starts at phi/x =. */ - int getPadNumber(int padIndex) const { return ( 0x0000ffff & padIndex ) ; } + int getPadNumber(int padIndex) const { return (0x0000ffff & padIndex); } /** Create a padIndex for the given row and pad ( column ) number */ - int getPadIndex(int rowNum, int padNum) const; + int getPadIndex(int rowNum, int padNum) const; /** The index of the pad nearest to the given point in 2d coordinates * (x,y,) or (r,phi). */ - int getNearestPad(double c0, double c1) const; + int getNearestPad(double c0, double c1) const; /** The index of the right neighbour pad. */ - int getRightNeighbour(int padIndex) const; + int getRightNeighbour(int padIndex) const; /** The index of the left neighbour pad. */ - int getLeftNeighbour(int padIndex) const; + int getLeftNeighbour(int padIndex) const; /** True if coordinate (c0,c1) is within the given pad. */ - bool isInsidePad(double c0, double c1, int padIndex) const; + bool isInsidePad(double c0, double c1, int padIndex) const; /** True if coordinate (c0,c1) is within any pad. */ - bool isInsidePad(double c0, double c1) const; + bool isInsidePad(double c0, double c1) const; }; // class - #endif // ifndef FixedPadSizeDiskLayout_h diff --git a/source/Digitisers/src/TPCModularEndplate.cc b/source/Digitisers/src/TPCModularEndplate.cc index ffcc673..3aab3ef 100644 --- a/source/Digitisers/src/TPCModularEndplate.cc +++ b/source/Digitisers/src/TPCModularEndplate.cc @@ -1,80 +1,72 @@ #include "TPCModularEndplate.h" -#include #include "marlin/VerbosityLevels.h" +#include #include +TPCModularEndplate::TPCModularEndplate(const dd4hep::rec::FixedPadSizeTPCData* tpc) : _tpc(tpc) {} -TPCModularEndplate::TPCModularEndplate( const dd4hep::rec::FixedPadSizeTPCData* tpc ) : _tpc( tpc) { } - +void TPCModularEndplate::addModuleRing(unsigned nModules, double phi0) { -void TPCModularEndplate::addModuleRing( unsigned nModules, double phi0 ){ - - if( isInitialized ){ - throw std::runtime_error("TPCModularEndplate: addModuleRing() called after initialize() ") ; + if (isInitialized) { + throw std::runtime_error("TPCModularEndplate: addModuleRing() called after initialize() "); } - - _moduleRings.push_back( { nModules, phi0, 0 , 0 , 0 } ) ; + + _moduleRings.push_back({nModules, phi0, 0, 0, 0}); } +void TPCModularEndplate::initialize() { -void TPCModularEndplate::initialize(){ + unsigned nRing = _moduleRings.size(); - unsigned nRing = _moduleRings.size() ; + double deltaR = (_tpc->rMaxReadout / dd4hep::mm - _tpc->rMinReadout / dd4hep::mm) / nRing; - double deltaR = ( _tpc->rMaxReadout/dd4hep::mm - _tpc->rMinReadout/dd4hep::mm ) / nRing ; + double rMin = _tpc->rMinReadout / dd4hep::mm; - double rMin = _tpc->rMinReadout/dd4hep::mm ; + double rMax = rMin + deltaR; - double rMax = rMin + deltaR ; + for (auto& modRing : _moduleRings) { - for( auto& modRing : _moduleRings){ + modRing.rMin = rMin; + modRing.rMax = rMax; - modRing.rMin = rMin ; - modRing.rMax = rMax ; + modRing.deltaPhi = 2. * M_PI / modRing.nModules; - modRing.deltaPhi = 2. * M_PI / modRing.nModules ; - - rMin += deltaR ; - rMax += deltaR ; + rMin += deltaR; + rMax += deltaR; } - isInitialized = true ; + isInitialized = true; } +double TPCModularEndplate::computeDistanceRPhi(const dd4hep::rec::Vector3D& hit) { - -double TPCModularEndplate::computeDistanceRPhi(const dd4hep::rec::Vector3D& hit){ - - if( !isInitialized ){ - throw std::runtime_error("TPCModularEndplate: computeDistanceRPhi() called before initialize() ") ; + if (!isInitialized) { + throw std::runtime_error("TPCModularEndplate: computeDistanceRPhi() called before initialize() "); } - - unsigned indexR = std::floor( _moduleRings.size() * ( hit.rho() - _tpc->rMinReadout/dd4hep::mm ) / ( _tpc->rMaxReadout/dd4hep::mm - _tpc->rMinReadout/dd4hep::mm ) ) ; - - if( indexR > _moduleRings.size() -1 ){ - streamlog_out( WARNING ) << " wrong index : " << indexR << " for point " << hit << std::endl ; + unsigned indexR = std::floor(_moduleRings.size() * (hit.rho() - _tpc->rMinReadout / dd4hep::mm) / + (_tpc->rMaxReadout / dd4hep::mm - _tpc->rMinReadout / dd4hep::mm)); - return 1e6 ; - } + if (indexR > _moduleRings.size() - 1) { + streamlog_out(WARNING) << " wrong index : " << indexR << " for point " << hit << std::endl; - auto modRing = _moduleRings.at( indexR ) ; + return 1e6; + } - double phi = hit.phi() - modRing.phi0 ; + auto modRing = _moduleRings.at(indexR); - double deltaPhi = std::fabs( std::fmod( phi , modRing.deltaPhi ) ); + double phi = hit.phi() - modRing.phi0; - if( deltaPhi > modRing.deltaPhi/2. ) { + double deltaPhi = std::fabs(std::fmod(phi, modRing.deltaPhi)); - deltaPhi = modRing.deltaPhi - deltaPhi ; - } + if (deltaPhi > modRing.deltaPhi / 2.) { - return hit.rho() * deltaPhi ; + deltaPhi = modRing.deltaPhi - deltaPhi; + } + return hit.rho() * deltaPhi; } - - diff --git a/source/Digitisers/src/TPCModularEndplate.h b/source/Digitisers/src/TPCModularEndplate.h index e4a28c8..940ff7e 100644 --- a/source/Digitisers/src/TPCModularEndplate.h +++ b/source/Digitisers/src/TPCModularEndplate.h @@ -8,53 +8,44 @@ /** Helper class for defining a modular TPC endplate with regular modules. * Computes the distance from a module boundary for hits. - * + * * @author F.Gaede, DESY - * @date June, 2017 + * @date June, 2017 */ class TPCModularEndplate { public: - /// internal helper struct - struct ModuleRing{ - unsigned nModules ; - double phi0 ; - double rMin ; - double rMax ; - double deltaPhi ; - } ; - + struct ModuleRing { + unsigned nModules; + double phi0; + double rMin; + double rMax; + double deltaPhi; + }; /// no default c'tor - TPCModularEndplate() = delete ; - + TPCModularEndplate() = delete; /// intitialize for the gice TPC data - TPCModularEndplate( const dd4hep::rec::FixedPadSizeTPCData* tpc ) ; - + TPCModularEndplate(const dd4hep::rec::FixedPadSizeTPCData* tpc); + /// add a module ring with the given number of modules and phi0 - modules are added inside out. - void addModuleRing( unsigned nModules, double phi0 ) ; + void addModuleRing(unsigned nModules, double phi0); - /// inititalize with the modules added so far - after this no more modules can be added. - void initialize() ; + void initialize(); + /// compute the distance in the rphi-plane from a module boundary in mm. + double computeDistanceRPhi(const dd4hep::rec::Vector3D& hit); - /// compute the distance in the rphi-plane from a module boundary in mm. - double computeDistanceRPhi( const dd4hep::rec::Vector3D& hit) ; - - protected: + std::vector _moduleRings{}; - std::vector _moduleRings{} ; - - const dd4hep::rec::FixedPadSizeTPCData* _tpc{} ; - - bool isInitialized{ false } ; - + const dd4hep::rec::FixedPadSizeTPCData* _tpc{}; -} ; + bool isInitialized{false}; +}; #endif diff --git a/source/Digitisers/src/voxel.cc b/source/Digitisers/src/voxel.cc index f32382b..6e73c5b 100644 --- a/source/Digitisers/src/voxel.cc +++ b/source/Digitisers/src/voxel.cc @@ -1,12 +1,11 @@ -#include #include "voxel.h" +#include using namespace std; -Voxel_tpc::Voxel_tpc(){ -} -Voxel_tpc::Voxel_tpc(int row, int phi, int z, double pos[3], double* /*posRPhi[2]*/, double edep, double RPhiRes, double ZRes) -{ +Voxel_tpc::Voxel_tpc() {} +Voxel_tpc::Voxel_tpc(int row, int phi, int z, double pos[3], double* /*posRPhi[2]*/, double edep, double RPhiRes, + double ZRes) { _row_index = row; _phi_index = phi; _z_index = z; @@ -20,12 +19,11 @@ Voxel_tpc::Voxel_tpc(int row, int phi, int z, double pos[3], double* /*posRPhi[2 _isClusterHit = false; } -Voxel_tpc::Voxel_tpc(int row, int phi, int z, CLHEP::Hep3Vector coord, double edep, double RPhiRes, double ZRes) -{ +Voxel_tpc::Voxel_tpc(int row, int phi, int z, CLHEP::Hep3Vector coord, double edep, double RPhiRes, double ZRes) { _row_index = row; _phi_index = phi; _z_index = z; - _coord=coord; + _coord = coord; _edep = edep; _rPhiRes = RPhiRes; _zRes = ZRes; @@ -33,26 +31,23 @@ Voxel_tpc::Voxel_tpc(int row, int phi, int z, CLHEP::Hep3Vector coord, double ed _isClusterHit = false; } -Voxel_tpc::~Voxel_tpc() -{ -} +Voxel_tpc::~Voxel_tpc() {} -//bool Voxel_tpc::compare_phi( Voxel_tpc * & a, Voxel_tpc * & b){ +// bool Voxel_tpc::compare_phi( Voxel_tpc * & a, Voxel_tpc * & b){ // return ( a->getPhiIndex() < b->getPhiIndex()); - + //} -int Voxel_tpc::clusterFind(vector * hitList){ - - if(!this->IsClusterHit()){ +int Voxel_tpc::clusterFind(vector* hitList) { + + if (!this->IsClusterHit()) { hitList->push_back(this); this->setIsClusterHit(); - for(int i=0; igetNumberOfAdjacent();++i){ + for (int i = 0; i < this->getNumberOfAdjacent(); ++i) { getAdjacent(i)->clusterFind(hitList); } } return hitList->size(); } - diff --git a/source/Digitisers/src/voxel.h b/source/Digitisers/src/voxel.h index dab954b..67f075e 100644 --- a/source/Digitisers/src/voxel.h +++ b/source/Digitisers/src/voxel.h @@ -3,15 +3,15 @@ // A header file which defines a voxel class for the TPC #include -//#include "ThreeVector.h" +// #include "ThreeVector.h" #include using namespace std; -class Voxel_tpc{ +class Voxel_tpc { - public: - Voxel_tpc(); +public: + Voxel_tpc(); // the intialation in the constructor here would be preferable though I don't know how to intialise // the array xyz[3] here with pos[3], for the mean time the constructor will be put in the .cc file // Voxel_tpc(int row, int phi, int z, double pos[3]) : row_index(row), phi_index(phi), z_index(z){} @@ -19,38 +19,35 @@ class Voxel_tpc{ Voxel_tpc(int row, int phi, int z, CLHEP::Hep3Vector coord, double edep, double rPhiRes, double zRes); ~Voxel_tpc(); - void setAdjacent(Voxel_tpc * p_voxel) { _adjacent_voxels.push_back(p_voxel);}; - void setIsClusterHit() { _isClusterHit = true;}; - void setIsMerged() { _isMerged = true;}; - bool IsClusterHit() { return _isClusterHit;}; - bool IsMerged() { return _isMerged;}; - int clusterFind(vector * hitList); - - - int getRowIndex() {return _row_index;}; - int getPhiIndex() {return _phi_index;}; - int getZIndex() {return _z_index;}; - Voxel_tpc * getFirstAdjacent() {return *(_adjacent_voxels.begin());}; - Voxel_tpc * getAdjacent(int i) {return _adjacent_voxels[i];}; - int getNumberOfAdjacent() {return _adjacent_voxels.size();}; - double getX() {return _coord.x();}; - double getY() {return _coord.y();}; - double getZ() {return _coord.z();}; - double getR() {return _coord.perp();}; - double getPhi() {return _coord.phi();}; - double getEDep() {return _edep;}; - double getRPhiRes() {return _rPhiRes;}; - double getZRes() {return _zRes;}; - const CLHEP::Hep3Vector getHep3Vector() {return _coord;}; + void setAdjacent(Voxel_tpc* p_voxel) { _adjacent_voxels.push_back(p_voxel); }; + void setIsClusterHit() { _isClusterHit = true; }; + void setIsMerged() { _isMerged = true; }; + bool IsClusterHit() { return _isClusterHit; }; + bool IsMerged() { return _isMerged; }; + int clusterFind(vector* hitList); + + int getRowIndex() { return _row_index; }; + int getPhiIndex() { return _phi_index; }; + int getZIndex() { return _z_index; }; + Voxel_tpc* getFirstAdjacent() { return *(_adjacent_voxels.begin()); }; + Voxel_tpc* getAdjacent(int i) { return _adjacent_voxels[i]; }; + int getNumberOfAdjacent() { return _adjacent_voxels.size(); }; + double getX() { return _coord.x(); }; + double getY() { return _coord.y(); }; + double getZ() { return _coord.z(); }; + double getR() { return _coord.perp(); }; + double getPhi() { return _coord.phi(); }; + double getEDep() { return _edep; }; + double getRPhiRes() { return _rPhiRes; }; + double getZRes() { return _zRes; }; + const CLHEP::Hep3Vector getHep3Vector() { return _coord; }; // bool compare_phi( Voxel_tpc * & a, Voxel_tpc * & b); - - - private: - int _row_index{}; +private: + int _row_index{}; int _phi_index{}; int _z_index{}; - vector _adjacent_voxels{}; + vector _adjacent_voxels{}; CLHEP::Hep3Vector _coord{}; double _edep{}; double _rPhiRes{}; diff --git a/source/Refitting/include/ClonesAndSplitTracksFinder.h b/source/Refitting/include/ClonesAndSplitTracksFinder.h index 9f29641..617ebf6 100644 --- a/source/Refitting/include/ClonesAndSplitTracksFinder.h +++ b/source/Refitting/include/ClonesAndSplitTracksFinder.h @@ -11,9 +11,9 @@ #include namespace MarlinTrk { - class IMarlinTrkSystem; - class IMarlinTrack; -} +class IMarlinTrkSystem; +class IMarlinTrack; +} // namespace MarlinTrk class ClonesAndSplitTracksFinder : public marlin::Processor { public: @@ -51,7 +51,8 @@ class ClonesAndSplitTracksFinder : public marlin::Processor { // Merges hits from two tracks in one and fits it void mergeAndFit(Track*, Track*, Track*&); - // Removes doubles (from clone treatments and track merging) and filters multiple connections (clones and mergeable tracks treated differently) + // Removes doubles (from clone treatments and track merging) and filters multiple connections (clones and mergeable + // tracks treated differently) void filterClonesAndMergedTracks(std::multimap>&, LCCollection*&, TrackVec&, bool); // Contains the whole merging procedure (calls filterClonesAndMergedTracks(bool false) and mergeAndFit) @@ -83,13 +84,13 @@ class ClonesAndSplitTracksFinder : public marlin::Processor { int _n_run = -1; int _n_evt = -1; - bool _MSOn = true; - bool _ElossOn = true; - bool _SmoothOn = false; - double _magneticField = 0.0; - bool _extrapolateForward = true; + bool _MSOn = true; + bool _ElossOn = true; + bool _SmoothOn = false; + double _magneticField = 0.0; + bool _extrapolateForward = true; - double _minPt = 1.0; + double _minPt = 1.0; double _maxSignificanceTheta = 0.0, _maxSignificancePhi = 0.0, _maxSignificancePt = 0.0; bool _mergeSplitTracks = false; diff --git a/source/Refitting/include/DDCellsAutomatonMV.h b/source/Refitting/include/DDCellsAutomatonMV.h index 8e3d6d8..8b83e85 100644 --- a/source/Refitting/include/DDCellsAutomatonMV.h +++ b/source/Refitting/include/DDCellsAutomatonMV.h @@ -1,13 +1,14 @@ #ifndef DDCellsAutomatonMV_h #define DDCellsAutomatonMV_h 1 -#include #include "Math/ProbFunc.h" +#include -#include -#include #include "marlin/VerbosityLevels.h" +#include +#include +#include "UTIL/LCTrackerConf.h" #include #include #include @@ -16,78 +17,66 @@ #include #include #include -#include "UTIL/LCTrackerConf.h" // KiTrack tools -#include "KiTrack/SubsetHopfieldNN.h" -#include "KiTrack/SubsetSimple.h" -#include "KiTrack/SegmentBuilder.h" #include "KiTrack/Automaton.h" #include "KiTrack/Segment.h" +#include "KiTrack/SegmentBuilder.h" +#include "KiTrack/SubsetHopfieldNN.h" +#include "KiTrack/SubsetSimple.h" // KiTrackMarlin toools -#include "ILDImpl/VXDTrack.h" +#include "Criteria/Criteria.h" +#include "ILDImpl/MiniVectorHit01.h" +#include "ILDImpl/SectorSystemVXD.h" #include "ILDImpl/VXDHit01.h" #include "ILDImpl/VXDSectorConnector.h" -#include "Tools/KiTrackMarlinTools.h" -#include "Tools/KiTrackMarlinCEDTools.h" +#include "ILDImpl/VXDTrack.h" #include "KiTrack/ITrack.h" -#include "Criteria/Criteria.h" -#include "ILDImpl/SectorSystemVXD.h" +#include "Tools/KiTrackMarlinCEDTools.h" +#include "Tools/KiTrackMarlinTools.h" #include "Tools/VXDHelixFitter.h" -#include "ILDImpl/MiniVectorHit01.h" - - - - // IMarlin tools -#include "MarlinTrk/IMarlinTrkSystem.h" #include "MarlinTrk/IMarlinTrack.h" +#include "MarlinTrk/IMarlinTrkSystem.h" /* #include "MarlinTrk/Factory.h" */ #include "MarlinTrk/MarlinTrkUtils.h" - -//DD4HEP +// DD4HEP /* #include "DDRec/Surface.h" */ /* #include "DD4hep/LCDD.h" */ /* #include "DD4hep/DD4hepUnits.h" */ /* #include "DDRec/SurfaceManager.h" */ - - ////// FOR TEST VXDFitter #include "EVENT/Track.h" #include "EVENT/TrackerHit.h" #include "lcio.h" - - using namespace lcio; -using namespace lcio ; -using namespace marlin ; -using namespace std ; +using namespace lcio; +using namespace marlin; +using namespace std; using namespace KiTrack; using namespace KiTrackMarlin; -namespace MarlinTrk{ - class IMarlinTrkSystem ; +namespace MarlinTrk { +class IMarlinTrkSystem; } /** a simple typedef, making writing shorter. And it makes sense: a track consists of hits. But as a real track * has more information, a vector of hits can be considered as a "raw track". */ -typedef std::vector< IHit* > RawTrack; +typedef std::vector RawTrack; class DDCellsAutomatonMV : public Processor { - - public: - - virtual Processor* newProcessor() { return new DDCellsAutomatonMV ; } - - - DDCellsAutomatonMV() ; - + +public: + virtual Processor* newProcessor() { return new DDCellsAutomatonMV; } + + DDCellsAutomatonMV(); + /** Called at the begin of the job before anything is read. * Use to initialize the processor, e.g. book histograms. */ @@ -95,25 +84,19 @@ class DDCellsAutomatonMV : public Processor { /** Called for every run. */ - virtual void processRunHeader( LCRunHeader* run ) ; - + virtual void processRunHeader(LCRunHeader* run); + /** Called for every event - the working horse. */ - virtual void processEvent( LCEvent * evt ) ; - - - virtual void check( LCEvent * evt ) ; - - - /** Called after data processing for clean up. - */ - virtual void end() ; - - + virtual void processEvent(LCEvent* evt); + virtual void check(LCEvent* evt); - protected: + /** Called after data processing for clean up. + */ + virtual void end(); +protected: int nEvt; int _nDivisionsInPhi; @@ -130,94 +113,106 @@ class DDCellsAutomatonMV : public Processor { double _dTheta; UTIL::BitField64* _encoder; - int getDetectorID(TrackerHit* hit) { _encoder->setValue(hit->getCellID0()); return (*_encoder)[lcio::LCTrackerCellID::subdet()]; } - int getSideID(TrackerHit* hit) { _encoder->setValue(hit->getCellID0()); return (*_encoder)[lcio::LCTrackerCellID::side()]; }; - int getLayerID(TrackerHit* hit) { _encoder->setValue(hit->getCellID0()); return (*_encoder)[lcio::LCTrackerCellID::layer()]; }; - int getModuleID(TrackerHit* hit) { _encoder->setValue(hit->getCellID0()); return (*_encoder)[lcio::LCTrackerCellID::module()]; }; - int getSensorID(TrackerHit* hit) { _encoder->setValue(hit->getCellID0()); return (*_encoder)[lcio::LCTrackerCellID::sensor()]; }; - - - void InitialiseVTX(LCEvent * evt, EVENT::TrackerHitVec HitsTemp); - void setupGeom() ; - bool setCriteria( unsigned round ); - void RawTrackFit( std::vector < MarlinTrk::IMarlinTrack* > candMarlinTracks, std::vector< IMPL::TrackImpl* > &finalTracks ) ; - void FitFunc2( std::vector < RawTrack > rawTracks, std::vector < MarlinTrk::IMarlinTrack* > &candMarlinTracks ) ; - void finaliseTrack( TrackImpl* trackImpl ) ; - void CreateMiniVectors( int sector ) ; - bool thetaAgreement( EVENT::TrackerHit *toHit, EVENT::TrackerHit *fromHit ) ; - bool thetaAgreementImproved( EVENT::TrackerHit *toHit, EVENT::TrackerHit *fromHit, int layer ) ; - double Dist( EVENT::TrackerHit *toHit, EVENT::TrackerHit *fromHit ) ; + int getDetectorID(TrackerHit* hit) { + _encoder->setValue(hit->getCellID0()); + return (*_encoder)[lcio::LCTrackerCellID::subdet()]; + } + int getSideID(TrackerHit* hit) { + _encoder->setValue(hit->getCellID0()); + return (*_encoder)[lcio::LCTrackerCellID::side()]; + }; + int getLayerID(TrackerHit* hit) { + _encoder->setValue(hit->getCellID0()); + return (*_encoder)[lcio::LCTrackerCellID::layer()]; + }; + int getModuleID(TrackerHit* hit) { + _encoder->setValue(hit->getCellID0()); + return (*_encoder)[lcio::LCTrackerCellID::module()]; + }; + int getSensorID(TrackerHit* hit) { + _encoder->setValue(hit->getCellID0()); + return (*_encoder)[lcio::LCTrackerCellID::sensor()]; + }; + + void InitialiseVTX(LCEvent* evt, EVENT::TrackerHitVec HitsTemp); + void setupGeom(); + bool setCriteria(unsigned round); + void RawTrackFit(std::vector candMarlinTracks, std::vector& finalTracks); + void FitFunc2(std::vector rawTracks, std::vector& candMarlinTracks); + void finaliseTrack(TrackImpl* trackImpl); + void CreateMiniVectors(int sector); + bool thetaAgreement(EVENT::TrackerHit* toHit, EVENT::TrackerHit* fromHit); + bool thetaAgreementImproved(EVENT::TrackerHit* toHit, EVENT::TrackerHit* fromHit, int layer); + double Dist(EVENT::TrackerHit* toHit, EVENT::TrackerHit* fromHit); unsigned int _nLayersVTX; unsigned int _nLayersSIT; - + /** A map to store the hits according to their sectors */ - std::map< int , EVENT::TrackerHitVec > _map_sector_spacepoints; - std::map< int , std::vector< IHit* > > _map_sector_hits; - + std::map _map_sector_spacepoints; + std::map> _map_sector_hits; + /** Names of the used criteria */ - std::vector< std::string > _criteriaNames; - + std::vector _criteriaNames; + /** Map containing the name of a criterion and a vector of the minimum cut offs for it */ - std::map< std::string , std::vector > _critMinima; - + std::map> _critMinima; + /** Map containing the name of a criterion and a vector of the maximum cut offs for it */ - std::map< std::string , std::vector > _critMaxima; - + std::map> _critMaxima; + /** Minimum number of hits a track has to have in order to be stored */ int _hitsPerTrackMin; - + /** A vector of criteria for 2 hits (2 1-hit segments) */ - std::vector _crit2Vec; - + std::vector _crit2Vec; + /** A vector of criteria for 3 hits (2 2-hit segments) */ - std::vector _crit3Vec; - + std::vector _crit3Vec; + /** A vector of criteria for 4 hits (2 3-hit segments) */ - std::vector _crit4Vec; + std::vector _crit4Vec; - std::vector< IHit* > MiniVectorsTemp; - std::vector< IHit* > TestMiniVectorsTemp; + std::vector MiniVectorsTemp; + std::vector TestMiniVectorsTemp; /** Cut for the Kalman Fit (the chi squared probability) */ - double _chi2ProbCut; + double _chi2ProbCut; - double _helixFitMax ; + double _helixFitMax; - double _chi2OverNdfCut ; + double _chi2OverNdfCut; + + const SectorSystemVXD* _sectorSystemVXD; - const SectorSystemVXD * _sectorSystemVXD; - /** the maximum number of connections that are allowed in the automaton, if this value is surpassed, rerun * the automaton with tighter cuts or stop it entirely. */ int _maxConnectionsAutomaton; - + MarlinTrk::IMarlinTrkSystem* _trkSystem; - - bool _MSOn, _ElossOn, _SmoothOn, _middleLayer ; - int _useSIT ; + bool _MSOn, _ElossOn, _SmoothOn, _middleLayer; - int _layerStepMax ; + int _useSIT; - int _lastLayerToIP ; + int _layerStepMax; - int _nHitsChi2 ; + int _lastLayerToIP; - int MiniVectors_sectors ; - int MiniVectors_CutSelection ; + int _nHitsChi2; - FloatVec _resU ; + int MiniVectors_sectors; + int MiniVectors_CutSelection; - double _maxDist ; - double _hitPairThDiff ; - double _hitPairThDiffInner ; - - //std::vector< MarlinTrk::IMarlinTrack* > GoodTracks; - //std::vector< MarlinTrk::IMarlinTrack* > RejectedTracks; + FloatVec _resU; + double _maxDist; + double _hitPairThDiff; + double _hitPairThDiffInner; + + // std::vector< MarlinTrk::IMarlinTrack* > GoodTracks; + // std::vector< MarlinTrk::IMarlinTrack* > RejectedTracks; - float _initialTrackError_d0; float _initialTrackError_phi0; float _initialTrackError_omega; @@ -225,8 +220,8 @@ class DDCellsAutomatonMV : public Processor { float _initialTrackError_tanL; float _maxChi2PerHit; - int _maxHitsPerSector ; - + int _maxHitsPerSector; + /** Input collection name. */ std::string _VTXHitCollection; @@ -237,160 +232,118 @@ class DDCellsAutomatonMV : public Processor { std::string _detElITName; std::string _detElOTName; - - std::map< LCCollection*, std::string > _colNamesTrackerHits; - - std::string _bestSubsetFinder; - - /** The quality of the output track collection */ - int _output_track_col_quality ; - - static const int _output_track_col_quality_GOOD; - static const int _output_track_col_quality_FAIR; - static const int _output_track_col_quality_POOR; - + std::map _colNamesTrackerHits; -} ; + std::string _bestSubsetFinder; + /** The quality of the output track collection */ + int _output_track_col_quality; + static const int _output_track_col_quality_GOOD; + static const int _output_track_col_quality_FAIR; + static const int _output_track_col_quality_POOR; +}; //**************************************************************************************************** // Quality - compatibility for ITrack version - /** A functor to return whether two tracks are compatible: The criterion is if they share a MiniVector or more */ -class TrackCompatibilityShare1_MV{ - +class TrackCompatibilityShare1_MV { + public: - - inline bool operator()( ITrack* trackA, ITrack* trackB ){ - - - std::vector< IHit* > hitsA = trackA->getHits(); - std::vector< IHit* > hitsB = trackB->getHits(); - - for( unsigned i=0; i < hitsA.size(); i++){ - - for( unsigned j=0; j < hitsB.size(); j++){ - - if ( hitsA[i] == hitsB[j] ) return false; // a hit is shared -> incompatible - - } - + inline bool operator()(ITrack* trackA, ITrack* trackB) { + + std::vector hitsA = trackA->getHits(); + std::vector hitsB = trackB->getHits(); + + for (unsigned i = 0; i < hitsA.size(); i++) { + + for (unsigned j = 0; j < hitsB.size(); j++) { + + if (hitsA[i] == hitsB[j]) + return false; // a hit is shared -> incompatible } - - return true; - - } - -}; + } + return true; + } +}; /** A functor to return the quality of a track, which is currently the chi2 probability. */ -class TrackQIChi2Prob_MV{ - +class TrackQIChi2Prob_MV { + public: - - inline double operator()( ITrack* track ){ return track->getChi2Prob(); } - - + inline double operator()(ITrack* track) { return track->getChi2Prob(); } }; /** A functor to return the quality of a track, which is the ratio chi2 over degrees of freedom, - weighted with the number of associated hits. + weighted with the number of associated hits. */ -class TrackQI{ - +class TrackQI { + public: - - inline double operator()( ITrack* track ){ - - float NoOfHits = 4.0*( track->getHits().size()); - - return (1.0*NoOfHits)/(track->getChi2()/track->getNdf()); } - - -}; + inline double operator()(ITrack* track) { + float NoOfHits = 4.0 * (track->getHits().size()); + return (1.0 * NoOfHits) / (track->getChi2() / track->getNdf()); + } +}; +/** A functor to return the quality of a track, which is the number of associated hits. + */ +class MaxHits { +public: + inline double operator()(ITrack* track) { return track->getHits().size(); } +}; +/** A functor to return the .... + */ +class Test { -/** A functor to return the quality of a track, which is the number of associated hits. -*/ -class MaxHits{ - public: - - inline double operator()( ITrack* track ){ - - return track->getHits().size(); - } - -}; + inline double operator()(ITrack* track) { + // std::cout<< " ----- track version with nhits = " << track->getHits().size() <getHits().size() > 2) { -/** A functor to return the .... -*/ -class Test{ - -public: - - inline double operator()( ITrack* track ){ - - //std::cout<< " ----- track version with nhits = " << track->getHits().size() <getHits().size() > 2 ){ - - //std::cout<< " -------- getChi2Prob() = " << track->getChi2Prob() <getChi2Prob()/2. +0.5 = " << track->getChi2Prob()/2. +0.5 <getChi2Prob()/2. +0.5; - - } - else{ - - //std::cout<< " -------- getChi2() = " << track->getChi2() <getChi2() ) ) = " << 1/( log( 7.3890561 + track->getChi2() ) ) <getChi2() ) ); //e^2 = 7.3890561 - - } + // std::cout<< " -------- getChi2Prob() = " << track->getChi2Prob() <getChi2Prob()/2. +0.5 = " << track->getChi2Prob()/2. +0.5 <getChi2Prob() / 2. + 0.5; + + } else { + // std::cout<< " -------- getChi2() = " << track->getChi2() <getChi2() ) ) = " << 1/( log( 7.3890561 + track->getChi2() + // ) ) <getChi2())); // e^2 = 7.3890561 + } } - }; - - /** A functor to return the quality of a track. For tracks with 4 hits or more the chi2prob is mapped to* 0.5-1, with x = prob/2 + 0.5. Tracks with 3 hits get the chi2 mapped to 0-0.5 by 1/(ln( e^2 + chi2 ); That gives 0 for an infinite chi2 and 0.5 for a chi2 of 0. - + Reason: now 3-hit-tracks can be compared as well */ -class TrackQISpecial_MV{ - +class TrackQISpecial_MV { + public: - - inline double operator()( ITrack* track ){ - - if( track->getHits().size() > 3 ){ - - return track->getChi2Prob()/2. +0.5; - - } - else{ - - return 1/( log( 7.3890561 + track->getChi2() ) ); //e^2 = 7.3890561 - - } - - } - - -}; + inline double operator()(ITrack* track) { + if (track->getHits().size() > 3) { + + return track->getChi2Prob() / 2. + 0.5; + + } else { + + return 1 / (log(7.3890561 + track->getChi2())); // e^2 = 7.3890561 + } + } +}; #endif diff --git a/source/Refitting/include/ExtrToSIT.h b/source/Refitting/include/ExtrToSIT.h index 8a13226..5ef5946 100644 --- a/source/Refitting/include/ExtrToSIT.h +++ b/source/Refitting/include/ExtrToSIT.h @@ -1,34 +1,34 @@ #ifndef ExtrToSIT_h #define ExtrToSIT_h 1 -#include -#include -#include #include -#include +#include #include -#include +#include +#include #include #include -#include +#include +#include +#include -#include -#include #include "UTIL/LCTrackerConf.h" +#include #include +#include -#include -#include -#include -#include #include #include +#include +#include +#include +#include #include #include #include -#include -#include #include +#include +#include #include "KiTrack/SubsetHopfieldNN.h" #include "KiTrack/SubsetSimple.h" @@ -37,145 +37,129 @@ #include "marlin/VerbosityLevels.h" #include "MarlinTrk/Factory.h" +#include "MarlinTrk/HelixTrack.h" #include "MarlinTrk/IMarlinTrack.h" #include "MarlinTrk/MarlinTrkUtils.h" -#include "MarlinTrk/HelixTrack.h" - - using namespace KiTrack; -namespace MarlinTrk{ - class IMarlinTrkSystem ; +namespace MarlinTrk { +class IMarlinTrkSystem; } - class ExtrToSIT : public marlin::Processor { - + public: + virtual marlin::Processor* newProcessor() { return new ExtrToSIT; } + ExtrToSIT(); - virtual marlin::Processor* newProcessor() { return new ExtrToSIT ; } - - ExtrToSIT() ; - /** Called at the begin of the job before anything is read. * Use to initialize the processor, e.g. book histograms. */ - virtual void init() ; - + virtual void init(); + /** Called for every run. */ - virtual void processRunHeader( lcio::LCRunHeader* run ) ; - + virtual void processRunHeader(lcio::LCRunHeader* run); + /** Called for every event - the working horse. */ - virtual void processEvent( lcio::LCEvent * evt ) ; - - - virtual void check( lcio::LCEvent * evt ) ; - - + virtual void processEvent(lcio::LCEvent* evt); + + virtual void check(lcio::LCEvent* evt); + /** Called after data processing for clean up. */ - virtual void end() ; - - void SelectBestCandidate(EVENT::TrackerHitVec &HitsInLayer, const float* &pivot, EVENT::TrackerHit* &BestHit, bool &BestHitFound, int &pointer) ; + virtual void end(); + + void SelectBestCandidate(EVENT::TrackerHitVec& HitsInLayer, const float*& pivot, EVENT::TrackerHit*& BestHit, + bool& BestHitFound, int& pointer); - void SelectBestCandidateLimited(EVENT::TrackerHitVec &HitsInLayer, const float* &pivot, EVENT::TrackerHit* &BestHit, const FloatVec& covLCIO, double& radius, bool &BestHitFound, double &sigma, int &pointer, int &PossibleHits, float &dU, float &dV, double &DimDist, TrackerHitVec &usedSiHits) ; - - int FitInit( std::vector < TrackerHit* > trackerHits , MarlinTrk::IMarlinTrack* _marlinTrk ) ; - int FitInit2( Track* track , MarlinTrk::IMarlinTrack* _marlinTrk ) ; + void SelectBestCandidateLimited(EVENT::TrackerHitVec& HitsInLayer, const float*& pivot, EVENT::TrackerHit*& BestHit, + const FloatVec& covLCIO, double& radius, bool& BestHitFound, double& sigma, + int& pointer, int& PossibleHits, float& dU, float& dV, double& DimDist, + TrackerHitVec& usedSiHits); + + int FitInit(std::vector trackerHits, MarlinTrk::IMarlinTrack* _marlinTrk); + int FitInit2(Track* track, MarlinTrk::IMarlinTrack* _marlinTrk); struct compare_r { - bool operator()( EVENT::TrackerHit* a, EVENT::TrackerHit* b) const { - double r_a_sqd = a->getPosition()[0] * a->getPosition()[0] + a->getPosition()[1] * a->getPosition()[1] ; - double r_b_sqd = b->getPosition()[0] * b->getPosition()[0] + b->getPosition()[1] * b->getPosition()[1] ; - return ( r_a_sqd < r_b_sqd ) ; + bool operator()(EVENT::TrackerHit* a, EVENT::TrackerHit* b) const { + double r_a_sqd = a->getPosition()[0] * a->getPosition()[0] + a->getPosition()[1] * a->getPosition()[1]; + double r_b_sqd = b->getPosition()[0] * b->getPosition()[0] + b->getPosition()[1] * b->getPosition()[1]; + return (r_a_sqd < r_b_sqd); } - } ; - - - + }; + protected: - /* helper function to get collection using try catch block */ - lcio::LCCollection* GetCollection( lcio::LCEvent * evt, std::string colName ) ; - + lcio::LCCollection* GetCollection(lcio::LCEvent* evt, std::string colName); + /* helper function to get relations using try catch block */ - lcio::LCRelationNavigator* GetRelations(lcio::LCEvent * evt, std::string RelName ) ; - + lcio::LCRelationNavigator* GetRelations(lcio::LCEvent* evt, std::string RelName); + /** Input track collection name for refitting. */ - std::string _input_track_col_name ; - + std::string _input_track_col_name; + /** Input track relations name for refitting. */ - std::string _input_track_rel_name ; + std::string _input_track_rel_name; /** Input SIT tracker summer hit collection. */ - std::string _sitColName ; + std::string _sitColName; /** Input VXD tracker summer hit collection. */ - std::string _vxdColName ; - + std::string _vxdColName; + /** refitted track collection name. */ - std::string _output_track_col_name ; - + std::string _output_track_col_name; + /** Output track relations name for refitting. */ - std::string _output_track_rel_name ; + std::string _output_track_rel_name; /** Output silicon track collection. */ - std::string _siTrkColName ; - - /** pointer to the IMarlinTrkSystem instance + std::string _siTrkColName; + + /** pointer to the IMarlinTrkSystem instance */ - MarlinTrk::IMarlinTrkSystem* _trksystem{} ; - std::string _trkSystemName{} ; - - std::string _mcParticleCollectionName{} ; - - bool _MSOn{} ; - bool _ElossOn{} ; - bool _SmoothOn{} ; - bool _dirInsideOut{} ; - - double _Max_Chi2_Incr {}; - int _tpcHitsCut{} ; - float _chi2NDoFCut{} ; - float _DoCut{} ; - float _ZoCut{} ; - double _searchSigma{} ; - bool _isSpacePoints{} ; - int _propToLayer{} ; - - int _n_run{} ; - int _n_evt{} ; - int SITHitsFitted{} ; - int SITHitsNonFitted {}; - int TotalSITHits{} ; - int _nHitsChi2{} ; + MarlinTrk::IMarlinTrkSystem* _trksystem{}; + std::string _trkSystemName{}; + + std::string _mcParticleCollectionName{}; + + bool _MSOn{}; + bool _ElossOn{}; + bool _SmoothOn{}; + bool _dirInsideOut{}; + + double _Max_Chi2_Incr{}; + int _tpcHitsCut{}; + float _chi2NDoFCut{}; + float _DoCut{}; + float _ZoCut{}; + double _searchSigma{}; + bool _isSpacePoints{}; + int _propToLayer{}; + + int _n_run{}; + int _n_evt{}; + int SITHitsFitted{}; + int SITHitsNonFitted{}; + int TotalSITHits{}; + int _nHitsChi2{}; float _maxChi2PerHit{}; float _bField{}; - unsigned int _nSITLayers{} ; - - StringVec _colNamesTrackerHitRelations{} ; - - - -} ; - - - + unsigned int _nSITLayers{}; + StringVec _colNamesTrackerHitRelations{}; +}; #endif - - - diff --git a/source/Refitting/include/ExtrToTracker.h b/source/Refitting/include/ExtrToTracker.h index c35a3bd..0e2f37d 100644 --- a/source/Refitting/include/ExtrToTracker.h +++ b/source/Refitting/include/ExtrToTracker.h @@ -1,211 +1,187 @@ #ifndef ExtrToTracker_h #define ExtrToTracker_h 1 -#include -#include -#include #include -#include +#include #include -#include +#include +#include #include #include -#include +#include +#include +#include -#include -#include #include "UTIL/LCTrackerConf.h" +#include #include +#include -#include -#include -#include -#include #include #include +#include +#include +#include +#include #include #include #include -#include -#include #include +#include +#include #include "KiTrack/SubsetHopfieldNN.h" #include "KiTrack/SubsetSimple.h" #include "marlin/Global.h" -#include "DDRec/Surface.h" -#include "DDRec/SurfaceManager.h" #include "DDRec/DetectorSurfaces.h" +#include "DDRec/Surface.h" #include "DDRec/SurfaceHelper.h" - +#include "DDRec/SurfaceManager.h" // ----- include for verbosity dependend logging --------- #include "marlin/VerbosityLevels.h" #include "MarlinTrk/Factory.h" +#include "MarlinTrk/HelixTrack.h" #include "MarlinTrk/IMarlinTrack.h" #include "MarlinTrk/MarlinTrkUtils.h" -#include "MarlinTrk/HelixTrack.h" - - - - - using namespace KiTrack; -namespace MarlinTrk{ - class IMarlinTrkSystem ; +namespace MarlinTrk { +class IMarlinTrkSystem; } - class ExtrToTracker : public marlin::Processor { - public: + virtual marlin::Processor* newProcessor() { return new ExtrToTracker; } - - virtual marlin::Processor* newProcessor() { return new ExtrToTracker ; } - - ExtrToTracker() ; + ExtrToTracker(); /** Called at the begin of the job before anything is read. * Use to initialize the processor, e.g. book histograms. */ - virtual void init() ; - + virtual void init(); + /** Called for every run. */ - virtual void processRunHeader( lcio::LCRunHeader* run ) ; - + virtual void processRunHeader(lcio::LCRunHeader* run); + /** Called for every event - the working horse. */ - virtual void processEvent( lcio::LCEvent * evt ) ; - - - virtual void check( lcio::LCEvent * evt ) ; - - + virtual void processEvent(lcio::LCEvent* evt); + + virtual void check(lcio::LCEvent* evt); + /** Called after data processing for clean up. */ - virtual void end() ; + virtual void end(); - int FitInit2( Track* track , MarlinTrk::IMarlinTrack* _marlinTrk ) ; + int FitInit2(Track* track, MarlinTrk::IMarlinTrack* _marlinTrk); struct compare_r { - bool operator()( EVENT::TrackerHit* a, EVENT::TrackerHit* b) const { - double r_a_sqd = a->getPosition()[0] * a->getPosition()[0] + a->getPosition()[1] * a->getPosition()[1] ; - double r_b_sqd = b->getPosition()[0] * b->getPosition()[0] + b->getPosition()[1] * b->getPosition()[1] ; - return ( r_a_sqd < r_b_sqd ) ; + bool operator()(EVENT::TrackerHit* a, EVENT::TrackerHit* b) const { + double r_a_sqd = a->getPosition()[0] * a->getPosition()[0] + a->getPosition()[1] * a->getPosition()[1]; + double r_b_sqd = b->getPosition()[0] * b->getPosition()[0] + b->getPosition()[1] * b->getPosition()[1]; + return (r_a_sqd < r_b_sqd); } - } ; - - - - //TrackerHitPlane* getSiHit(LCCollection*& sitHitsCol, int fitElID, MarlinTrk::IMarlinTrack*& marlin_trk, int& nHitsOnDetEl); - //TrackerHit* getSiHit(LCCollection*& sitHitsCol, int fitElID, MarlinTrk::IMarlinTrack*& marlin_trk, int& nHitsOnDetEl); - //bool getSiHit(LCCollection*& sitHitsCol, int fitElID, MarlinTrk::IMarlinTrack*& marlin_trk, TrackerHit*& selectedHit); - - - TrackerHitPlane* getSiHit(std::vector& hitsOnDetEl, MarlinTrk::IMarlinTrack*& marlin_trk); + }; - TrackerHitPlane* getSiHit(std::vector& vecElID, std::map >& mapElHits, MarlinTrk::IMarlinTrack*& marlin_trk); + // TrackerHitPlane* getSiHit(LCCollection*& sitHitsCol, int fitElID, MarlinTrk::IMarlinTrack*& marlin_trk, int& + // nHitsOnDetEl); TrackerHit* getSiHit(LCCollection*& sitHitsCol, int fitElID, MarlinTrk::IMarlinTrack*& marlin_trk, + // int& nHitsOnDetEl); bool getSiHit(LCCollection*& sitHitsCol, int fitElID, MarlinTrk::IMarlinTrack*& marlin_trk, + // TrackerHit*& selectedHit); - /* void getNeighbours(int elID, std::vector& vecIDs, std::string cellIDEcoding, std::map mapLayerNModules); */ + TrackerHitPlane* getSiHit(std::vector& hitsOnDetEl, MarlinTrk::IMarlinTrack*& marlin_trk); + TrackerHitPlane* getSiHit(std::vector& vecElID, + std::map>& mapElHits, + MarlinTrk::IMarlinTrack*& marlin_trk); - void fillMapElHits(std::vector& vecHitCol, std::vector > >& vecMaps); + /* void getNeighbours(int elID, std::vector& vecIDs, std::string cellIDEcoding, std::map + * mapLayerNModules); */ + void fillMapElHits(std::vector& vecHitCol, + std::vector>>& vecMaps); - /* void addHitOnNextElID(int elementID, MarlinTrk::IMarlinTrack*& marlin_trk, EVENT::TrackerHitVec& trkHits, LCCollection*& sitHitsCol, LCCollection*& otHitsCol, int& iL, int& nSITR, int& TotalSITHits, int& SITHitsPerTrk, int& SITHitsFitted, int& SITHitsNonFitted); */ - + /* void addHitOnNextElID(int elementID, MarlinTrk::IMarlinTrack*& marlin_trk, EVENT::TrackerHitVec& trkHits, + * LCCollection*& sitHitsCol, LCCollection*& otHitsCol, int& iL, int& nSITR, int& TotalSITHits, int& SITHitsPerTrk, + * int& SITHitsFitted, int& SITHitsNonFitted); */ void fillVecSubdet(lcio::LCEvent*& evt); void getGeoInfo(); - void FindAndAddHit(size_t& idet, int& elID, MarlinTrk::IMarlinTrack*& mtrk, EVENT::TrackerHitVec& trkHits, int& SITHitsPerTrk, int& layer); - - void getCellID0AndPositionInfo(LCCollection*& col ); + void FindAndAddHit(size_t& idet, int& elID, MarlinTrk::IMarlinTrack*& mtrk, EVENT::TrackerHitVec& trkHits, + int& SITHitsPerTrk, int& layer); + void getCellID0AndPositionInfo(LCCollection*& col); protected: - /* helper function to get collection using try catch block */ - lcio::LCCollection* GetCollection( lcio::LCEvent * evt, std::string colName ) ; - + lcio::LCCollection* GetCollection(lcio::LCEvent* evt, std::string colName); + /* /\* helper function to get relations using try catch block *\/ */ /* lcio::LCRelationNavigator* GetRelations(lcio::LCEvent * evt, std::string RelName ) ; */ - + /** Input track collection name for refitting. */ - std::string _input_track_col_name ; - + std::string _input_track_col_name; /** output collection name for the not used hits. */ - std::string _output_not_used_col_name ; - + std::string _output_not_used_col_name; + /** output track collection name. */ - std::string _output_track_col_name ; - + std::string _output_track_col_name; + /** Output track relations name for refitting. */ - std::string _output_track_rel_name ; - - /** pointer to the IMarlinTrkSystem instance + std::string _output_track_rel_name; + + /** pointer to the IMarlinTrkSystem instance */ - MarlinTrk::IMarlinTrkSystem* _trksystem ; - + MarlinTrk::IMarlinTrkSystem* _trksystem; + /* std::string _mcParticleCollectionName ; */ - bool _MSOn ; - bool _ElossOn ; - bool _SmoothOn ; - double _Max_Chi2_Incr ; - double _searchSigma ; - - int _n_run ; - int _n_evt ; - int SITHitsFitted ; - int SITHitsNonFitted ; - int TotalSITHits ; - int _nHitsChi2 ; + bool _MSOn; + bool _ElossOn; + bool _SmoothOn; + double _Max_Chi2_Incr; + double _searchSigma; + + int _n_run; + int _n_evt; + int SITHitsFitted; + int SITHitsNonFitted; + int TotalSITHits; + int _nHitsChi2; float _bField; - bool _performFinalRefit ; - - bool _extrapolateForward; + bool _performFinalRefit; - const dd4hep::rec::SurfaceMap* _map ; + bool _extrapolateForward; - + const dd4hep::rec::SurfaceMap* _map; - //processor parameters + // processor parameters StringVec _vecDigiHits; StringVec _vecSubdetName; - std::vector _vecSubdetIsBarrel; - std::vector _vecSubdetNLayers; - std::vector _vecSubdetID; - std::vector _vecDigiHitsCol; - std::vector >* > _vecMapNeighbours; - - std::vector > > _vecMapsElHits; - - std::vector > _vecvecHitsInCol; - - -} ; - - + std::vector _vecSubdetIsBarrel; + std::vector _vecSubdetNLayers; + std::vector _vecSubdetID; + std::vector _vecDigiHitsCol; + std::vector>*> _vecMapNeighbours; + std::vector>> _vecMapsElHits; + std::vector> _vecvecHitsInCol; +}; #endif - - - diff --git a/source/Refitting/include/FPCCDFullLDCTracking_MarlinTrk.h b/source/Refitting/include/FPCCDFullLDCTracking_MarlinTrk.h index 7569b24..aef4cd2 100644 --- a/source/Refitting/include/FPCCDFullLDCTracking_MarlinTrk.h +++ b/source/Refitting/include/FPCCDFullLDCTracking_MarlinTrk.h @@ -1,52 +1,46 @@ #ifndef FPCCDFULLLDCTRACKING_H #define FPCCDFULLLDCTRACKING_H 1 -#include "marlin/Processor.h" -#include -#include "lcio.h" -#include #include "ClusterExtended.h" -#include "TrackExtended.h" -#include "TrackerHitExtended.h" -#include "TrackHitPair.h" -#include "HelixClass.h" -#include "HelixClass_double.h" #include "ClusterShapes.h" #include "GroupTracks.h" +#include "HelixClass.h" +#include "HelixClass_double.h" +#include "TrackExtended.h" +#include "TrackHitPair.h" +#include "TrackerHitExtended.h" +#include "lcio.h" +#include "marlin/Processor.h" #include +#include #include +#include #include "MarlinTrk/IMarlinTrack.h" -#include #include "UTIL/LCTrackerConf.h" +#include - - -#include "TTree.h" -#include "TNtuple.h" +#include "../src/GetPurity.h" +#include "./MCPMap.h" #include "TFile.h" +#include "TNtuple.h" #include "TStopwatch.h" -#include +#include "TTree.h" #include +#include #include -#include "../src/GetPurity.h" -#include "./MCPMap.h" - - - -using namespace lcio ; -using namespace marlin ; +using namespace lcio; +using namespace marlin; namespace MarlinTrk { - class HelixFit; - class IMarlinTrkSystem ; -} - +class HelixFit; +class IMarlinTrkSystem; +} // namespace MarlinTrk -namespace dd4hep{ - class Detector; +namespace dd4hep { +class Detector; } /** === FPCCDFullLDCTracking_MarlinTrk Processor ===
@@ -54,8 +48,9 @@ namespace dd4hep{ * * This processor is based on FullLDCTracking_MarlinTrk Processor (author: Steve Apline).
* Please use this processor with FPCCDSiliconTracking_MarlinTrk, then tracking performance is improved.
- * As I said in FPCCDSiliconTracking_MarlinTrk.h, users can use CMOS VXD Simulator with these tracking code in spite of the name FPCCD~.
- * + * As I said in FPCCDSiliconTracking_MarlinTrk.h, users can use CMOS VXD Simulator with these tracking code in spite of + the name FPCCD~.
+ * * There are only two differences between FPCCDFullLDCTracking_MarlinTrk and FullLDCTracking_MarlinTrk.
* The one is the requirement of registering silicon tracks in this processor.
* If useMaxChi2RequirementForSiTrk : false, then the requirement requires
@@ -78,21 +73,21 @@ namespace dd4hep{ * * * - * Processor performing track finding procedure in + * Processor performing track finding procedure in * the entire LDC detector by linking track segments * found by the SiliconTracking module in the silicon detectors - * and by the LEPTracking module in TPC. - *

Input collections and prerequisites

- * Processor requires collection of digitized vertex, sit, ftd, set, etd & tpc tracker hits + * and by the LEPTracking module in TPC. + *

Input collections and prerequisites

+ * Processor requires collection of digitized vertex, sit, ftd, set, etd & tpc tracker hits * and also the collections of tracks found in the silicon detectors * and in TPC. *

Output

- * Processor produces an LCIO collection of the Tracks. Each track is characterised by + * Processor produces an LCIO collection of the Tracks. Each track is characterised by * five parameters : Omega (signed curvuture), Tan(lambda) where * lambda is the dip angle, Phi (azimuthal angle @ point of closest approach), D0 (signed impact parameter), - * Z0 (displacement along z axis at the point of closest approach to IP). + * Z0 (displacement along z axis at the point of closest approach to IP). * Covariance matrix for these parameters is also provided. - * Only lower left corner of the covariance matrix is stored. The sequence of the covariance matrix elements + * Only lower left corner of the covariance matrix is stored. The sequence of the covariance matrix elements * assigned to track is the following:
* (D0,D0)
* (Phi,D0), (Phi,Phi)
@@ -102,19 +97,19 @@ namespace dd4hep{ * The number of hits in the different subdetectors associated * with each track can be accessed via method Track::getSubdetectorHitNumbers(). * This method returns vector of integers :
- * number of VTX hits used in the track fit is the 1st element in this vector + * number of VTX hits used in the track fit is the 1st element in this vector * (Track::getSubdetectorHitNumbers()[0])
- * number of FTD hits used in the track fit is the 2nd element in this vector + * number of FTD hits used in the track fit is the 2nd element in this vector * (Track::getSubdetectorHitNumbers()[1])
- * number of SIT hits used in the track fit is the 3d element in this vector + * number of SIT hits used in the track fit is the 3d element in this vector * (Track::getSubdetectorHitNumbers()[2])
- * number of TPC hits used in the track fit is the 4th element in this vector + * number of TPC hits used in the track fit is the 4th element in this vector * (Track::getSubdetectorHitNumbers()[3])
- * number of SET hits used in the track fit is the 5th element in this vector + * number of SET hits used in the track fit is the 5th element in this vector * (Track::getSubdetectorHitNumbers()[4])
- * number of ETD hits used in the track fit is the 6th element in this vector + * number of ETD hits used in the track fit is the 6th element in this vector * (Track::getSubdetectorHitNumbers()[5])
- * total number of VTX hits in track is the 7th element in this vector + * total number of VTX hits in track is the 7th element in this vector * (Track::getSubdetectorHitNumbers()[6])
* total number of FTD hits in track is the 8th element in this vector * (Track::getSubdetectorHitNumbers()[7])
@@ -126,7 +121,7 @@ namespace dd4hep{ * (Track::getSubdetectorHitNumbers()[10])
* total number of ETD hits in track is the 12th element in this vector * (Track::getSubdetectorHitNumbers()[11])
- * Output track collection has by default a name "LDCTracks". + * Output track collection has by default a name "LDCTracks". * @param VTXHitCollection name of input VTX TrackerHit collection
* (default parameter value : "VTXTrackerHits")
* @param FTDPixelHitCollectionName name of input FTD Pixel TrackerHit collection
@@ -148,15 +143,15 @@ namespace dd4hep{ * @param SiTracks collection name of Si tracks
* (default parameter value : "SiTracks")
* @param SiTracksMCPRelColl Name of input Si track to MC particle relation collection
- * (default parameter value : "SiTracksMCP")
+ * (default parameter value : "SiTracksMCP")
* @param LDCTrackCollection name of the output LDC track collection
* (default parameter value : "LDCTracks")
* @param Chi2FitCut cut on the Chi2/Ndf of the track fit
* (default parameter value : 100.0)
- * @param Chi2PrefitCut cut on the prefit Chi2 of the track candidate, + * @param Chi2PrefitCut cut on the prefit Chi2 of the track candidate, * prefit is done with the simple helix hypothesis
* (default parameter value : 1e+5)
- * @param AngleCutForMerging cut on opening angle between + * @param AngleCutForMerging cut on opening angle between * particle momentum reconstructed with TPC and momentum reconstructed * with the Silicon detectors. If the opening angle is smaller that this cut * the track segment in Silicon trackers and in TPC are tested for their @@ -166,7 +161,7 @@ namespace dd4hep{ * parameter reconstructed with TPC and with Si detectors. If the relative difference is smaller * than this cut, the track segments in TPC and Si are tested for their compatibility
* (default parameter value : 0.25)
- * @param D0CutForMerging Upper cutoff on the difference in D0 [mm] to allow for merging + * @param D0CutForMerging Upper cutoff on the difference in D0 [mm] to allow for merging * of the Si and TPC segments
* (default parameter value : 500)
* @param Z0CutForMerging Upper cutoff on the difference in Z0 [mm] to allow for merging @@ -176,16 +171,16 @@ namespace dd4hep{ * if set to 1 debugging printout is activated * (default parameter value : 1)
* @param ForceSiTPCMerging This flag steers merging of Si and TPC track segments. If ForceMerging=1 - * Si and TPC track segments are forced to be merged if the opening angle between Si track + * Si and TPC track segments are forced to be merged if the opening angle between Si track * momentum and TPC track momentum - * is less than AngleCutForForcedMerging (see below) and difference in tracks + * is less than AngleCutForForcedMerging (see below) and difference in tracks * parameters Omega is less than OmegaCutForForcedMerging (see below)
* (default parameter value : 0) * @param AngleCutForForcedMerging cut on opening angle between Si track momentum and * TPC track momentum. Used to steer forced merging of Si and TPC track segments.
* (default parameter value : 0.05) * @param OmegaCutForForcedMerging cut on the difference between Si and TPC tracks parameter - * Omega. Used to steer forced merging of Si and TPC track segments. Relative + * Omega. Used to steer forced merging of Si and TPC track segments. Relative * errors are compared.
* (default parameter value : 0.15)
* @param D0CutForForcedMerging Upper cutoff on the difference in D0 to allow for forced @@ -194,7 +189,7 @@ namespace dd4hep{ * @param Z0CutForForcedMerging Upper cutoff on the difference in Z0 to allow for forced * merging of the Si and TPC segments
* (default parameter value : 200)
- * @param ForceTPCSegmentsMerging If this flag is set to 1, the code attempts to + * @param ForceTPCSegmentsMerging If this flag is set to 1, the code attempts to * merge TPC segments from the low pt splitted loopers
* (default parameter value : 1)
* @param D0CutToMergeTPCSegments cut on the difference in the track parameter @@ -202,35 +197,35 @@ namespace dd4hep{ * (default parameter value : 100)
* @param Z0CutToMergeTPCSegments cut on the difference in the track parameter * z0 [mm] to allow for merging TPC segments
- * (default parameter value : 5000)
+ * (default parameter value : 5000)
* @param DeltaPCutToMergeTPCSegments cut on the magnitude [GeV/c] of the vectorial difference * of the momentum vectors, associated with TPC segments, for the TPC segment's merging procedure
* (default parameter value : 0.1)
* @param PtCutToMergeTPCSegments lower cutoff on Pt of the TPC segments of the looping track for * the merging procedure. * If transverse momentum of the segments is less than cutoff the segments are allowed to be merged.
- * (default parameter value : 1.2)
- * @param AssignTPCHits If this flag is set to 1, the code attempts to assign left-over + * (default parameter value : 1.2)
+ * @param AssignTPCHits If this flag is set to 1, the code attempts to assign left-over * TPC hits to the accepted track candidates. No track refit is done in case when hit is assigned * to the existing track
* (default parameter value : 1)
- * @param AssignETDHits If this flag is set to 1, the code attempts to assign + * @param AssignETDHits If this flag is set to 1, the code attempts to assign * ETD hits to the accepted track candidates. No track refit is done in case when hit is assigned * to the existing track
* (default parameter value : 1)
- * @param AssignVTXHits If this flag is set to 1, the code attempts to assign left-over + * @param AssignVTXHits If this flag is set to 1, the code attempts to assign left-over * VTX hits to the accepted track candidates. Track refit is done in case when hit is assigned * to the existing track
* (default parameter value : 1)
- * @param AssignFTDHits If this flag is set to 1, the code attempts to assign left-over + * @param AssignFTDHits If this flag is set to 1, the code attempts to assign left-over * FTD hits to the accepted track candidates. Track refit is done in case when hit is assigned * to the existing track
* (default parameter value : 1)
- * @param AssignSITHits If this flag is set to 1, the code attempts to assign left-over + * @param AssignSITHits If this flag is set to 1, the code attempts to assign left-over * SIT hits to the accepted track candidates. Track refit is done in case when hit is assigned * to the existing track
* (default parameter value : 1)
- * @param AssignSETHits If this flag is set to 1, the code attempts to assign + * @param AssignSETHits If this flag is set to 1, the code attempts to assign * SET hits to the accepted track candidates. Track refit is done in case when hit is assigned * to the existing track
* (default parameter value : 1)
@@ -255,127 +250,118 @@ namespace dd4hep{ * @param NHitsExtrapolation Number of the last track hits for extrapolating helix * to the outer tracking detectors (SET, ETD)
* (default parameter value : 35)
- * @param CutOnTPCHits minimal number of TPC hits, used in the track fit, which is + * @param CutOnTPCHits minimal number of TPC hits, used in the track fit, which is * required for tracks which have no hits from the Si detectors
- * (default parameter value : 35)
- * @param CutOnTrackD0 cut on the d0 parameter of the track. If the d0 parameter is greater that + * (default parameter value : 35)
+ * @param CutOnTrackD0 cut on the d0 parameter of the track. If the d0 parameter is greater that * this cut, track is rejected
* (default parameter value : 500)
- * @param CutOnTrackZ0 cut on the z0 parameter of the track. If the z0 parameter is greater that + * @param CutOnTrackZ0 cut on the z0 parameter of the track. If the z0 parameter is greater that * this cut, track is rejected
* (default parameter value : 500)
- * @param ForbidOverlapInZTPC If this flag is set to 1 then merging of the TPC semiloops is + * @param ForbidOverlapInZTPC If this flag is set to 1 then merging of the TPC semiloops is * forbiden for segment overlapping in z
* (default parameter value : 0)
* @param ForbidOverlapInZComb If this flag is set to 1 then merging of left-over TPC semiloop and * combined Si-TPC track is their segments overlap in z
* (default parameter value : 0)
- * @param cosThetaCutHighPtMerge cut on cos theta between the two momentum vectors + * @param cosThetaCutHighPtMerge cut on cos theta between the two momentum vectors * when considering merger of high Pt tracks
* (default is 0.99)
- * @param cosThetaCutSoftHighPtMerge cut on the cos theta between the two momentum vectors + * @param cosThetaCutSoftHighPtMerge cut on the cos theta between the two momentum vectors * when considering merger of high Pt tracks for softer dp/p cut
* (default is 0.998)
- * @param momDiffCutHighPtMerge cut on dp/p + * @param momDiffCutHighPtMerge cut on dp/p * when considering merger of high Pt tracks
* (default is 0.01 [1/GeV])
- * @param momDiffCutSoftHighPtMerge softer cut on dp/p + * @param momDiffCutSoftHighPtMerge softer cut on dp/p * when considering merger of high Pt tracks
* (default is 0.25 [1/GeV])
- * @param hitDistanceCutHighPtMerge cut on 3D distance between hit + * @param hitDistanceCutHighPtMerge cut on 3D distance between hit * and helix extrapolation when considering merger of high Pt tracks
* (default is 25.0 [mm])
- * @param maxHitDistanceCutHighPtMerge cut for max 3D distance between any hit + * @param maxHitDistanceCutHighPtMerge cut for max 3D distance between any hit * and helix extrapolation when considering merger of high Pt tracks
* (default is 50.0 [mm])
- * @param maxFractionOfOutliersCutHighPtMerge cut on maximum fraction of outliers + * @param maxFractionOfOutliersCutHighPtMerge cut on maximum fraction of outliers * when considering merger of high Pt tracks
* (default is 0.95 )
- - + + * @author A. Raspereza (MPI Munich)
*/ class FPCCDFullLDCTracking_MarlinTrk : public Processor { - + public: - - virtual Processor* newProcessor() { return new FPCCDFullLDCTracking_MarlinTrk ; } - FPCCDFullLDCTracking_MarlinTrk() ; - virtual void init() ; - virtual void processRunHeader( LCRunHeader* run ) ; - virtual void processEvent( LCEvent * evt ) ; - virtual void check( LCEvent * evt ) ; - virtual void end() ; - + virtual Processor* newProcessor() { return new FPCCDFullLDCTracking_MarlinTrk; } + FPCCDFullLDCTracking_MarlinTrk(); + virtual void init(); + virtual void processRunHeader(LCRunHeader* run); + virtual void processEvent(LCEvent* evt); + virtual void check(LCEvent* evt); + virtual void end(); + protected: - - void prepareVectors( LCEvent * evt ); + void prepareVectors(LCEvent* evt); void CleanUp(); void MergeTPCandSiTracks(); void MergeTPCandSiTracksII(); - TrackExtended * CombineTracks(TrackExtended * tpcTrk, TrackExtended * siTrk, float maxAllowedOutliers ,bool testCombinationOnly ); + TrackExtended* CombineTracks(TrackExtended* tpcTrk, TrackExtended* siTrk, float maxAllowedOutliers, + bool testCombinationOnly); -// TrackExtended * TrialCombineTracks(TrackExtended * tpcTrk, TrackExtended * siTrk); + // TrackExtended * TrialCombineTracks(TrackExtended * tpcTrk, TrackExtended * siTrk); - void Sorting(TrackExtendedVec & trackVec); + void Sorting(TrackExtendedVec& trackVec); void SelectCombinedTracks(); void AddNotCombinedTracks(); void CheckTracks(); void AddNotAssignedHits(); void RemoveSplitTracks(); - void AddTrackColToEvt(LCEvent * evt, TrackExtendedVec & trkVec, - std::string TrkColName); - float CompareTrk(TrackExtended * first, TrackExtended * second, - float d0Cut, float z0Cut, int iopt); - - float CompareTrkII(TrackExtended * first, TrackExtended * second, - float d0Cut, float z0Cut, int iopt, float &Angle); - float CompareTrkIII(TrackExtended * first, TrackExtended * second, - float d0Cut, float z0Cut, int iopt, float &Angle); - - void SortingTrackHitPairs(TrackHitPairVec & trackHitPairVec); - - void AssignSiHitsToTracks(TrackerHitExtendedVec hitVec, - float dcut); - - void AssignTPCHitsToTracks(TrackerHitExtendedVec hitVec, - float dcut); - + void AddTrackColToEvt(LCEvent* evt, TrackExtendedVec& trkVec, std::string TrkColName); + float CompareTrk(TrackExtended* first, TrackExtended* second, float d0Cut, float z0Cut, int iopt); + + float CompareTrkII(TrackExtended* first, TrackExtended* second, float d0Cut, float z0Cut, int iopt, float& Angle); + float CompareTrkIII(TrackExtended* first, TrackExtended* second, float d0Cut, float z0Cut, int iopt, float& Angle); + + void SortingTrackHitPairs(TrackHitPairVec& trackHitPairVec); + + void AssignSiHitsToTracks(TrackerHitExtendedVec hitVec, float dcut); + + void AssignTPCHitsToTracks(TrackerHitExtendedVec hitVec, float dcut); + void AssignOuterHitsToTracks(TrackerHitExtendedVec hitVec, float dcut, int refit); - + void CreateExtrapolations(); - + void CleanUpExtrapolations(); - - HelixClass * GetExtrapolationHelix(TrackExtended * track); - - void PrintOutMerging(TrackExtended * firstTrackExt, TrackExtended * secondTrackExt, - int iopt); - - void GeneralSorting(int * index, float * val, int direct, int nVal); - + + HelixClass* GetExtrapolationHelix(TrackExtended* track); + + void PrintOutMerging(TrackExtended* firstTrackExt, TrackExtended* secondTrackExt, int iopt); + + void GeneralSorting(int* index, float* val, int direct, int nVal); + int SegmentRadialOverlap(TrackExtended* pTracki, TrackExtended* pTrackj); bool VetoMerge(TrackExtended* firstTrackExt, TrackExtended* secondTrackExt); - - - int _nRun ; - int _nEvt ; - + + int _nRun; + int _nEvt; + MarlinTrk::HelixFit* _fastfitter; - - /** pointer to the IMarlinTrkSystem instance + + /** pointer to the IMarlinTrkSystem instance */ - MarlinTrk::IMarlinTrkSystem* _trksystem ; - - bool _MSOn, _ElossOn, _SmoothOn ; - + MarlinTrk::IMarlinTrkSystem* _trksystem; + + bool _MSOn, _ElossOn, _SmoothOn; + std::string _TPCTrackCollection; std::string _SiTrackCollection; std::string _TPCTrackMCPCollName; std::string _SiTrackMCPCollName; - + std::string _VTXTrackerHitCollection; std::string _SITTrackerHitCollection; std::string _SETTrackerHitCollection; @@ -383,10 +369,9 @@ class FPCCDFullLDCTracking_MarlinTrk : public Processor { std::string _FTDSpacePointCollection; std::string _TPCTrackerHitCollection; std::string _ETDTrackerHitCollection; - + std::string _LDCTrackCollection; - - + TrackExtendedVec _allSiTracks; TrackExtendedVec _allTPCTracks; TrackExtendedVec _allCombinedTracks; @@ -399,36 +384,34 @@ class FPCCDFullLDCTracking_MarlinTrk : public Processor { TrackerHitExtendedVec _allSITHits; TrackerHitExtendedVec _allSETHits; TrackerHitExtendedVec _allETDHits; - + float PI, PIOVER2, TWOPI; - + float _bField; float _chi2PrefitCut; float _chi2FitCut; - + int _debug; - + float _dPCutForMerging; float _d0CutForMerging; float _z0CutForMerging; float _dOmegaForMerging; float _angleForMerging; - - - int _forceMerging; + + int _forceMerging; float _dPCutForForcedMerging; float _d0CutForForcedMerging; float _z0CutForForcedMerging; float _dOmegaForForcedMerging; float _angleForForcedMerging; - - + int _mergeTPCSegments; float _dPCutToMergeTPC; float _PtCutToMergeTPC; float _d0CutToMergeTPC; float _z0CutToMergeTPC; - + float _cosThetaCutHighPtMerge; float _cosThetaCutSoftHighPtMerge; float _momDiffCutHighPtMerge; @@ -436,158 +419,177 @@ class FPCCDFullLDCTracking_MarlinTrk : public Processor { float _hitDistanceCutHighPtMerge; float _maxHitDistanceCutHighPtMerge; float _maxFractionOfOutliersCutHighPtMerge; - + float _vetoMergeMomentumCut; - + float _initialTrackError_d0; float _initialTrackError_phi0; float _initialTrackError_omega; float _initialTrackError_z0; float _initialTrackError_tanL; - + double _maxChi2PerHit; double _minChi2ProbForSiliconTracks; double _maxChi2ForSiliconTracks; - bool _useMaxChi2ReqForSiTrk; - float _maxAllowedPercentageOfOutliersForTrackCombination; - int _maxAllowedSiHitRejectionsForTrackCombination; - + bool _useMaxChi2ReqForSiTrk; + float _maxAllowedPercentageOfOutliersForTrackCombination; + int _maxAllowedSiHitRejectionsForTrackCombination; + bool _runMarlinTrkDiagnostics; std::string _MarlinTrkDiagnosticsName; - + int _nHitsExtrapolation; - + int _cutOnTPCHits; int _cutOnSiHits; - - - int _assignVTXHits,_assignFTDHits,_assignSITHits,_assignTPCHits; - + + int _assignVTXHits, _assignFTDHits, _assignSITHits, _assignTPCHits; + int _assignSETHits, _assignETDHits; - - float _distCutForVTXHits,_distCutForFTDHits,_distCutForSITHits,_distCutForTPCHits; - + + float _distCutForVTXHits, _distCutForFTDHits, _distCutForSITHits, _distCutForTPCHits; + float _distCutForSETHits, _distCutForETDHits; - - - float _d0TrkCut,_z0TrkCut; - - int _forbidOverlapInZTPC,_forbidOverlapInZComb; - - LCEvent * _evt; - - std::map _trackExtrapolatedHelix; + + float _d0TrkCut, _z0TrkCut; + + int _forbidOverlapInZTPC, _forbidOverlapInZComb; + + LCEvent* _evt; + + std::map _trackExtrapolatedHelix; std::set _candidateCombinedTracks; - + UTIL::BitField64* _encoder; - int getDetectorID(TrackerHit* hit) { _encoder->setValue(hit->getCellID0()); return (*_encoder)[lcio::LCTrackerCellID::subdet()]; } - int getSideID(TrackerHit* hit) { _encoder->setValue(hit->getCellID0()); return (*_encoder)[lcio::LCTrackerCellID::side()]; }; - int getLayerID(TrackerHit* hit) { _encoder->setValue(hit->getCellID0()); return (*_encoder)[lcio::LCTrackerCellID::layer()]; }; - int getModuleID(TrackerHit* hit) { _encoder->setValue(hit->getCellID0()); return (*_encoder)[lcio::LCTrackerCellID::module()]; }; - int getSensorID(TrackerHit* hit) { _encoder->setValue(hit->getCellID0()); return (*_encoder)[lcio::LCTrackerCellID::sensor()]; }; - - int getDetectorID(SimTrackerHit* hit) { _encoder->setValue(hit->getCellID0()); return (*_encoder)[lcio::LCTrackerCellID::subdet()]; } - int getSideID(SimTrackerHit* hit) { _encoder->setValue(hit->getCellID0()); return (*_encoder)[lcio::LCTrackerCellID::side()]; }; - int getLayerID(SimTrackerHit* hit) { _encoder->setValue(hit->getCellID0()); return (*_encoder)[lcio::LCTrackerCellID::layer()]; }; - int getModuleID(SimTrackerHit* hit) { _encoder->setValue(hit->getCellID0()); return (*_encoder)[lcio::LCTrackerCellID::module()]; }; - int getSensorID(SimTrackerHit* hit) { _encoder->setValue(hit->getCellID0()); return (*_encoder)[lcio::LCTrackerCellID::sensor()]; }; - - - void setupGeom(const dd4hep::Detector& theDetector) ; - + int getDetectorID(TrackerHit* hit) { + _encoder->setValue(hit->getCellID0()); + return (*_encoder)[lcio::LCTrackerCellID::subdet()]; + } + int getSideID(TrackerHit* hit) { + _encoder->setValue(hit->getCellID0()); + return (*_encoder)[lcio::LCTrackerCellID::side()]; + }; + int getLayerID(TrackerHit* hit) { + _encoder->setValue(hit->getCellID0()); + return (*_encoder)[lcio::LCTrackerCellID::layer()]; + }; + int getModuleID(TrackerHit* hit) { + _encoder->setValue(hit->getCellID0()); + return (*_encoder)[lcio::LCTrackerCellID::module()]; + }; + int getSensorID(TrackerHit* hit) { + _encoder->setValue(hit->getCellID0()); + return (*_encoder)[lcio::LCTrackerCellID::sensor()]; + }; + + int getDetectorID(SimTrackerHit* hit) { + _encoder->setValue(hit->getCellID0()); + return (*_encoder)[lcio::LCTrackerCellID::subdet()]; + } + int getSideID(SimTrackerHit* hit) { + _encoder->setValue(hit->getCellID0()); + return (*_encoder)[lcio::LCTrackerCellID::side()]; + }; + int getLayerID(SimTrackerHit* hit) { + _encoder->setValue(hit->getCellID0()); + return (*_encoder)[lcio::LCTrackerCellID::layer()]; + }; + int getModuleID(SimTrackerHit* hit) { + _encoder->setValue(hit->getCellID0()); + return (*_encoder)[lcio::LCTrackerCellID::module()]; + }; + int getSensorID(SimTrackerHit* hit) { + _encoder->setValue(hit->getCellID0()); + return (*_encoder)[lcio::LCTrackerCellID::sensor()]; + }; + + void setupGeom(const dd4hep::Detector& theDetector); + double _tpc_inner_r; double _tpc_outer_r; double _tpc_pad_height; - int _tpc_nrows; - -// struct VXD_Layer { -// int nLadders; -// double phi0; -// double dphi; -// double senRMin; -// double supRMin; -// double length; -// double width; -// double offset; -// double senThickness; -// double supThickness; -// }; -// std::vector _VXDgeo; - - unsigned int _nLayersVTX; - -// struct SIT_Layer { -// int nLadders; -// double phi0; -// double dphi; -// double senRMin; -// double supRMin; -// double length; -// double width; -// double offset; -// double senThickness; -// double supThickness; -// }; -// std::vector _SITgeo; - - unsigned int _nLayersSIT; - - unsigned int _nLayersSET; - - -// struct FTD_Disk { -// int nPetals; -// double phi0; -// double dphi; -// -// double alpha; -// double rInner; -// double height; -// double innerBaseLength; -// double outerBaseLength; -// double senThickness; -// double supThickness; -// -// double senZPos_even_petal1; -// double senZPos_even_petal2; -// double senZPos_even_petal3; -// double senZPos_even_petal4; -// -// double supZPos_even_petal1; -// double supZPos_even_petal2; -// double supZPos_even_petal3; -// double supZPos_even_petal4; -// -// double senZPos_odd_petal1; -// double senZPos_odd_petal2; -// double senZPos_odd_petal3; -// double senZPos_odd_petal4; -// -// double supZPos_odd_petal1; -// double supZPos_odd_petal2; -// double supZPos_odd_petal3; -// double supZPos_odd_petal4; -// -// -// -// }; -// -// std::vector _FTDgeo; - std::vector _zLayerFTD; - - unsigned int _nLayersFTD; - int _nPhiFTD; - bool _petalBasedFTDWithOverlaps; + int _tpc_nrows; + + // struct VXD_Layer { + // int nLadders; + // double phi0; + // double dphi; + // double senRMin; + // double supRMin; + // double length; + // double width; + // double offset; + // double senThickness; + // double supThickness; + // }; + // std::vector _VXDgeo; + unsigned int _nLayersVTX; + // struct SIT_Layer { + // int nLadders; + // double phi0; + // double dphi; + // double senRMin; + // double supRMin; + // double length; + // double width; + // double offset; + // double senThickness; + // double supThickness; + // }; + // std::vector _SITgeo; + unsigned int _nLayersSIT; + unsigned int _nLayersSET; + // struct FTD_Disk { + // int nPetals; + // double phi0; + // double dphi; + // + // double alpha; + // double rInner; + // double height; + // double innerBaseLength; + // double outerBaseLength; + // double senThickness; + // double supThickness; + // + // double senZPos_even_petal1; + // double senZPos_even_petal2; + // double senZPos_even_petal3; + // double senZPos_even_petal4; + // + // double supZPos_even_petal1; + // double supZPos_even_petal2; + // double supZPos_even_petal3; + // double supZPos_even_petal4; + // + // double senZPos_odd_petal1; + // double senZPos_odd_petal2; + // double senZPos_odd_petal3; + // double senZPos_odd_petal4; + // + // double supZPos_odd_petal1; + // double supZPos_odd_petal2; + // double supZPos_odd_petal3; + // double supZPos_odd_petal4; + // + // + // + // }; + // + // std::vector _FTDgeo; + std::vector _zLayerFTD; + unsigned int _nLayersFTD; + int _nPhiFTD; + bool _petalBasedFTDWithOverlaps; + /////////////Addition by Mori////////////////// -/////////////Addition by Mori////////////////// - GetPurityUtil* _purityUtil; moriUTIL* _moriUtil; MCPMap _mcpMapSi; @@ -626,35 +628,31 @@ class FPCCDFullLDCTracking_MarlinTrk : public Processor { bool _FinalTrackCut_strategyA; /** helper function to get collection using try catch block */ - LCCollection* GetCollection( LCEvent * evt, std::string colName ) ; - + LCCollection* GetCollection(LCEvent* evt, std::string colName); + /** helper function to get relations using try catch block */ - LCRelationNavigator* GetRelations( LCEvent * evt, std::string RelName ) ; + LCRelationNavigator* GetRelations(LCEvent* evt, std::string RelName); MCPMap LoadMCPMap(int mode); - std::map< MCParticle*, SimTrackerHitVec > _mcpVXD; - std::map< MCParticle*, SimTrackerHitVec > _mcpVXDFTD; - std::map< MCParticle*, SimTrackerHitVec > _mcpVXDSIT; - std::map< MCParticle*, SimTrackerHitVec > _mcpVXDFTDSIT; - std::map< MCParticle*, SimTrackerHitVec > _mcpFTD; - std::map< MCParticle*, SimTrackerHitVec > _mcpFTDSIT; - std::map< MCParticle*, SimTrackerHitVec > _mcpSIT; - - enum MCPContributions{ - contVXD, - contFTD, - contSIT, - contVXDFTD, - contVXDSIT, - contFTDSIT, - contVXDFTDSIT, - contBG, - contSize + std::map _mcpVXD; + std::map _mcpVXDFTD; + std::map _mcpVXDSIT; + std::map _mcpVXDFTDSIT; + std::map _mcpFTD; + std::map _mcpFTDSIT; + std::map _mcpSIT; + + enum MCPContributions { + contVXD, + contFTD, + contSIT, + contVXDFTD, + contVXDSIT, + contFTDSIT, + contVXDFTDSIT, + contBG, + contSize }; - -} ; +}; #endif - - - diff --git a/source/Refitting/include/FPCCDSiliconTracking_MarlinTrk.h b/source/Refitting/include/FPCCDSiliconTracking_MarlinTrk.h index 2e63369..c8390fb 100644 --- a/source/Refitting/include/FPCCDSiliconTracking_MarlinTrk.h +++ b/source/Refitting/include/FPCCDSiliconTracking_MarlinTrk.h @@ -1,76 +1,73 @@ #ifndef FPCCDSILICONTRACKING_MarlinTrk_H #define FPCCDSILICONTRACKING_MarlinTrk_H 1 -#include "marlin/Processor.h" -#include -#include "lcio.h" -#include -#include -#include -#include -#include -#include #include "ClusterExtended.h" +#include "HelixClass_double.h" #include "TrackExtended.h" #include "TrackerHitExtended.h" -#include "HelixClass_double.h" -#include +#include "lcio.h" +#include "marlin/Processor.h" #include +#include #include +#include +#include +#include +#include +#include +#include #include "MarlinTrk/IMarlinTrack.h" -#include #include "UTIL/LCTrackerConf.h" +#include -#include "TTree.h" -#include "TNtupleD.h" +#include "../src/GetPurity.h" //by Mori +#include "./MCPMap.h" #include "TFile.h" -#include "TVector3.h" +#include "TNtupleD.h" #include "TStopwatch.h" -#include "./MCPMap.h" -#include "../src/GetPurity.h" //by Mori +#include "TTree.h" +#include "TVector3.h" namespace DiagnosticsHistograms { - class Histograms ; +class Histograms; } namespace DiagnosticsHistograms2D { - class Histograms ; +class Histograms; } -using namespace lcio ; -using namespace marlin ; - +using namespace lcio; +using namespace marlin; namespace MarlinTrk { - class HelixFit; - class IMarlinTrkSystem ; -} +class HelixFit; +class IMarlinTrkSystem; +} // namespace MarlinTrk -namespace UTIL{ - class LCRelationNavigator ; +namespace UTIL { +class LCRelationNavigator; } - -namespace dd4hep{ - class Detector; +namespace dd4hep { +class Detector; } - /** === FPCCDSiliconTracking_MarlinTrk Processor ===
* This processor is based on SiliconTracking_MarlinTrk Processor (author: Steve Apline).
* The major differences between FPCCDSiliconTracking_MarlinTrk and SiliconTracking_MarlinTrk are
* TestTriplet method and BuildTrack method, which is to say, making track seed process and extrapolation process.
* In more detail, please see my talk slide in LCWS 13.
- * https://agenda.linearcollider.org/getFile.py/access?contribId=313&sessionId=37&resId=0&materialId=slides&confId=6000
- * This slide explains the major differences and shows improvement in tracking efficiency by using FPCCDSiliconTracking_MarlinTrk and
- * FPCCDFullLDCTracking_MarlinTrk.
- * In more detail than this slide, now I am preparing to submit proceedings of LCWS 13. In the future, I will write the address here.
- * - * This processor is named FPCCD~, but if you don't use FPCCD VXD Simulator but CMOS with VXDPlanarDigiProcessor or something like that,
- * abailable, and improves tracking efficiency and flavor tagging and reduces CPU time down to 1/10 if you include pair-BG into your analysis.
- * The performance evaluation study of this processor in the case including pair-BG is shown in
+ * https://agenda.linearcollider.org/getFile.py/access?contribId=313&sessionId=37&resId=0&materialId=slides&confId=6000 + *
This slide explains the major differences and shows improvement in tracking efficiency by using + * FPCCDSiliconTracking_MarlinTrk and
FPCCDFullLDCTracking_MarlinTrk.
In more detail than this slide, now I am + * preparing to submit proceedings of LCWS 13. In the future, I will write the address here.
+ * + * This processor is named FPCCD~, but if you don't use FPCCD VXD Simulator but CMOS with VXDPlanarDigiProcessor or + * something like that,
abailable, and improves tracking efficiency and flavor tagging and reduces CPU time down to + * 1/10 if you include pair-BG into your analysis.
The performance evaluation study of this processor in the case + * including pair-BG is shown in
* https://agenda.linearcollider.org/getFile.py/access?contribId=5&resId=0&materialId=slides&confId=6294
* * @author Tatsuya Mori (Tohoku University)
@@ -81,51 +78,51 @@ namespace dd4hep{ * * Processor performing stand-alone pattern recognition * in the vertex detector (VXD), forward tracking disks and SIT.
- * The procedure consists of three steps :
+ * The procedure consists of three steps :
* 1) Tracking in VXD and SIT ;
* 2) Tracking in FTD ;
* 3) Merging compatible track segments reconstructed in VXD and FTD
* STEP 1 : TRACKING IN VXD and SIT
- * Algorithm starts with finding of hit triplets satisfying helix hypothesis
+ * Algorithm starts with finding of hit triplets satisfying helix hypothesis
* in three different layers. Two layers of SIT are effectively considered as outermost
* layers of the vertex detector. To accelerate procedure, the 4-pi solid angle - * is divided in NDivisionsInTheta and NDivisionsInPhi sectors in cosQ and Phi, - * respectively. Triplets are looked for in 2x2 window of adjacent sectors. - * Once triplet is found, attempt is made to associate additional hits to - * track. Combinatin of hits is accepted for further analysis if the Chi2 - * of the fit is less than certain predefined threshold. All accepted - * combinations are sorted in ascending order of their Chi2. First track candidate - * in the sorted array is automatically accepted. The hits belonging to this track are + * is divided in NDivisionsInTheta and NDivisionsInPhi sectors in cosQ and Phi, + * respectively. Triplets are looked for in 2x2 window of adjacent sectors. + * Once triplet is found, attempt is made to associate additional hits to + * track. Combinatin of hits is accepted for further analysis if the Chi2 + * of the fit is less than certain predefined threshold. All accepted + * combinations are sorted in ascending order of their Chi2. First track candidate + * in the sorted array is automatically accepted. The hits belonging to this track are * marked as used, and track candidates sharing these hits are discarded. - * The procedure proceeds with increasing index of track candidate in the sorted + * The procedure proceeds with increasing index of track candidate in the sorted * array until all track candidate have been output or discarded.
* STEP 2 : TRACKING IN FTD
- * In the next step tracking in FTD is performed. The strategy of tracking in the FTD + * In the next step tracking in FTD is performed. The strategy of tracking in the FTD * is the same as used for tracking in the VXD+SIT.
* STEP 3 : MERGING TRACK SEGMENTS FOUND IN FTD AND VXD+SIT
* In the last step, track segments reconstructed in the FTD and VXD+SIT, belonging to the - * same track are identified and merged into one track. All possible + * same track are identified and merged into one track. All possible * pairings are tested for their compatibility. - * The number of pairings considered is Ntrk_VXD_SIT*Ntrk_FTD, where Ntrk_VXD_SIT is the number of + * The number of pairings considered is Ntrk_VXD_SIT*Ntrk_FTD, where Ntrk_VXD_SIT is the number of * track segments reconstructed in the first step in VXD+SIT (segments containing solely VXD and SIT hits) and - * Ntrk_FTD is the number of track segments reconstructed in the second step + * Ntrk_FTD is the number of track segments reconstructed in the second step * (segments containing solely FTD hits). - * Pair of segments is accepted for further examination if the angle between track segments and + * Pair of segments is accepted for further examination if the angle between track segments and * than certain specified threshold. - * Pairing satisfying this condition is subjected for - * addtitional test. The fit is performed on unified array of hits belonging to both segments. - * If the chi2 of the fit does not exceed predefined cut value two segments are unified into - * one track. - *

Input collections and prerequisites

+ * Pairing satisfying this condition is subjected for + * addtitional test. The fit is performed on unified array of hits belonging to both segments. + * If the chi2 of the fit does not exceed predefined cut value two segments are unified into + * one track. + *

Input collections and prerequisites

* Processor requires collection of digitized vertex, sit and ftd tracker hits.
- * If such a collections with the user specified names do not exist + * If such a collections with the user specified names do not exist * processor takes no action.
*

Output

- * Processor produces an LCIO collection of the Tracks. Each track is characterised by + * Processor produces an LCIO collection of the Tracks. Each track is characterised by * five parameters : Omega (signed curvuture), Tan(lambda) where * lambda is the dip angle, Phi (azimuthal angle @ point of closest approach), D0 (signed impact parameter), - * Z0 (displacement along z axis at the point of closest approach to IP). Covariance matrix for these parameters is also provided. - * Only lower left corner of the covariance matrix is stored. The sequence of the covariance matrix elements + * Z0 (displacement along z axis at the point of closest approach to IP). Covariance matrix for these parameters is also + * provided. Only lower left corner of the covariance matrix is stored. The sequence of the covariance matrix elements * assigned to track is the following:
* (Omega,Omega)
* (Omega,TanLambda), (TanLambda,TanLambda)
@@ -135,11 +132,11 @@ namespace dd4hep{ * The number of hits in the different subdetectors associated * with each track can be accessed via method Track::getSubdetectorHitNumbers(). * This method returns vector of integers :
- * number of VXD hits in track is the first element in this vector + * number of VXD hits in track is the first element in this vector * (Track::getSubdetectorHitNumbers()[0])
- * number of FTD hits in track is the second element in this vector + * number of FTD hits in track is the second element in this vector * (Track::getSubdetectorHitNumbers()[1])
- * number of SIT hits in track is the third element in this vector + * number of SIT hits in track is the third element in this vector * (Track::getSubdetectorHitNumbers()[2])
* Output track collection has a name "SiTracks".
* @param VXDHitCollectionName name of input VXD TrackerHit collection
@@ -151,16 +148,16 @@ namespace dd4hep{ * @param SiTrackCollectionName name of the output Silicon track collection
* (default parameter value : "SiTracks")
* @param LayerCombinations combinations of layers used to search for hit triplets in VXD+SIT
- * (default parameters : 6 4 3 6 4 2 6 3 2 5 4 3 5 4 2 5 3 2 4 3 2 4 3 1 4 2 1 3 2 1)
- * Note that in the VXD+SIT system the first and the second layers of SIT have indicies nLayerVXD and nLayerVXD+1. - * Combination given above means that triplets are looked first in layers 6 4 3, and then + * (default parameters : 6 4 3 6 4 2 6 3 2 5 4 3 5 4 2 5 3 2 4 3 2 4 3 1 4 2 1 3 2 1)
+ * Note that in the VXD+SIT system the first and the second layers of SIT have indicies nLayerVXD and nLayerVXD+1. + * Combination given above means that triplets are looked first in layers 6 4 3, and then * in 6 4 2; 5 4 3; 6 3 2 etc. NOTE THAT LAYER INDEXING STARTS FROM 0. * LAYER 0 is the innermost layer
* @param LayerCombinationsFTD combinations of layers used to search for hit triplets in FTD
- * (default parameters 6 5 4 5 4 3 5 4 2 5 4 1 5 3 2 5 3 1 5 2 1 4 3 2 4 3 1 - * 4 3 0 4 2 1 4 2 0 4 1 0 3 2 1 3 2 0 3 1 0 2 1 0). - * NOTE THAT TRACKS IN FTD ARE SEARCHED ONLY IN ONE HEMISPHERE. TRACK IS NOT - * ALLOWED TO HAVE HITS BOTH IN BACKWARD AND FORWARD PARTS OF FTD SIMULTANEOUSLY. + * (default parameters 6 5 4 5 4 3 5 4 2 5 4 1 5 3 2 5 3 1 5 2 1 4 3 2 4 3 1 + * 4 3 0 4 2 1 4 2 0 4 1 0 3 2 1 3 2 0 3 1 0 2 1 0). + * NOTE THAT TRACKS IN FTD ARE SEARCHED ONLY IN ONE HEMISPHERE. TRACK IS NOT + * ALLOWED TO HAVE HITS BOTH IN BACKWARD AND FORWARD PARTS OF FTD SIMULTANEOUSLY. * @param NDivisionsInPhi Number of divisions in Phi for tracking in VXD+SIT
* (default value is 40)
* @param NDivisionsInTheta Number of divisions in cosQ for tracking in VXD+SIT
@@ -181,21 +178,21 @@ namespace dd4hep{ * (default value is 0.5)
* @param Chi2FitCut Cut on chi2/ndf to accept track candidate
* (default value is 100.)
- * @param AngleCutForMerging cut on the angle between two track segments. + * @param AngleCutForMerging cut on the angle between two track segments. * If the angle is greater than this cut, segments are not allowed to be merged.
* (default value is 0.1)
* @param MinDistCutAttach cut on the distance (in mm) from hit to the helix. This parameter is used - * to decide whether hit can be attached to the track. If the distance is less than - * cut value. The track is refitted with a given hit being added to the list of hits already + * to decide whether hit can be attached to the track. If the distance is less than + * cut value. The track is refitted with a given hit being added to the list of hits already * assigned for the track. Additional hit is assigned if chi2 of the new fit has good chi2.
* (default value is 2 )
* @param MinLayerToAttach the minimal layer index to attach VXD hits to the found hit triplets
* (default value is -1)
- * @param CutOnZ0 cut on Z0 parameter of track (in mm). If abs(Z0) is greater than the cut value, track is + * @param CutOnZ0 cut on Z0 parameter of track (in mm). If abs(Z0) is greater than the cut value, track is * discarded (used to suppress fake * track rate in the presence of beam induced background hits)
* (default value is 100)
- * @param CutOnD0 cut on D0 parameter of track (in mm). If abs(D0) is greater than the cut value, track is + * @param CutOnD0 cut on D0 parameter of track (in mm). If abs(D0) is greater than the cut value, track is * discarded (used to suppress fake * track rate in the presence of beam induced background hits)
* (default value is 100)
@@ -207,9 +204,8 @@ namespace dd4hep{ * @param NHitsChi2 Maximal number of hits for which a track with n hits is aways better than one with n-1 hits. * For tracks with equal or more than NHitsChi2 the track with the lower \f$\chi^2\f$ is better. * (default value is 5)
- * @param FastAttachment if this flag is set to 1, less accurate but fast procedure to merge additional hits to tracks is used
- * if set to 0, a more accurate, but slower procedure is invoked
- * (default value is 0)
+ * @param FastAttachment if this flag is set to 1, less accurate but fast procedure to merge additional hits to tracks + * is used
if set to 0, a more accurate, but slower procedure is invoked
(default value is 0)
* @param UseSIT When this flag is set to 1, SIT is included in pattern recognition. When this flag is set * to 0, SIT is excluded from the procedure of pattern recognition
* (default value is 1)
@@ -217,112 +213,102 @@ namespace dd4hep{ * @author A. Raspereza (MPI Munich)
*/ class FPCCDSiliconTracking_MarlinTrk : public Processor { - + public: - - virtual Processor* newProcessor() { return new FPCCDSiliconTracking_MarlinTrk ; } - - - FPCCDSiliconTracking_MarlinTrk() ; - - /** + virtual Processor* newProcessor() { return new FPCCDSiliconTracking_MarlinTrk; } + + FPCCDSiliconTracking_MarlinTrk(); + + /** * Initialization */ - virtual void init() ; - + virtual void init(); + /** Run header processor. */ - virtual void processRunHeader( LCRunHeader* run ) ; - + virtual void processRunHeader(LCRunHeader* run); + /** Event processor. */ - virtual void processEvent( LCEvent * evt ) ; + virtual void processEvent(LCEvent* evt); + virtual void check(LCEvent* evt); - virtual void check( LCEvent * evt ) ; - - /** Called after data processing for clean up. */ - virtual void end() ; - - + virtual void end(); + protected: - - int _nRun ; - int _nEvt ; + int _nRun; + int _nEvt; EVENT::LCEvent* _current_event; - + int _nDivisionsInPhi; int _nDivisionsInTheta; int _nLayers; - + MarlinTrk::HelixFit* _fastfitter; - - /** pointer to the IMarlinTrkSystem instance + + /** pointer to the IMarlinTrkSystem instance */ - MarlinTrk::IMarlinTrkSystem* _trksystem ; + MarlinTrk::IMarlinTrkSystem* _trksystem; bool _runMarlinTrkDiagnostics; std::string _MarlinTrkDiagnosticsName; - - bool _MSOn, _ElossOn, _SmoothOn ; - + + bool _MSOn, _ElossOn, _SmoothOn; + float _initialTrackError_d0; float _initialTrackError_phi0; float _initialTrackError_omega; float _initialTrackError_z0; float _initialTrackError_tanL; - - double _maxChi2PerHit; - double _maxChi2PerHit2nd; - - bool _UseEventDisplay; - std::vector _colours; - + + double _maxChi2PerHit; + double _maxChi2PerHit2nd; + + bool _UseEventDisplay; + std::vector _colours; + void drawEvent(); - - + // histogram member variables - - bool _createDiagnosticsHistograms; - DiagnosticsHistograms::Histograms* _histos ; - + bool _createDiagnosticsHistograms; + DiagnosticsHistograms::Histograms* _histos; + int _ntriplets, _ntriplets_good, _ntriplets_2MCP, _ntriplets_3MCP, _ntriplets_1MCP_Bad, _ntriplets_bad; - - + /** helper function to get collection using try catch block */ - LCCollection* GetCollection( LCEvent * evt, std::string colName ) ; - + LCCollection* GetCollection(LCEvent* evt, std::string colName); + /** helper function to get relations using try catch block */ - LCRelationNavigator* GetRelations( LCEvent * evt, std::string RelName ) ; - + LCRelationNavigator* GetRelations(LCEvent* evt, std::string RelName); + /** input MCParticle collection and threshold used for Drawing */ - std::string _colNameMCParticles; - - + std::string _colNameMCParticles; + /// Compare tracks according to their chi2/ndf - struct compare_TrackExtended{ + struct compare_TrackExtended { // n.b.: a and b should be TrackExtended const *, but the getters are not const :-( - bool operator()(TrackExtended *a, TrackExtended *b) const { - if ( a == b ) return false; - return (a->getChi2()/a->getNDF() < b->getChi2()/b->getNDF() ); + bool operator()(TrackExtended* a, TrackExtended* b) const { + if (a == b) + return false; + return (a->getChi2() / a->getNDF() < b->getChi2() / b->getNDF()); } }; - - + std::string _VTXHitCollection; std::string _FTDPixelHitCollection; std::string _FTDSpacePointCollection; std::string _SITHitCollection; std::string _siTrkCollection; - - std::vector< LCCollection* > _colTrackerHits; - std::map< LCCollection*, std::string > _colNamesTrackerHits; - + + std::vector _colTrackerHits; + std::map _colNamesTrackerHits; + std::vector _sectors; std::vector _sectorsFTD; - + /** * A helper class to allow good code readability by accessing tracks with N hits. * As the smalest valid track contains three hits, but the first index in a vector is 0, @@ -333,58 +319,51 @@ class FPCCDSiliconTracking_MarlinTrk : public Processor { public: /// Empty all the vectors and delete the tracks contained in it. void clear(); - + /// Set the size to allow a maximum of maxHit hits. inline void resize(size_t maxHits) { - _tracksNHits.resize(maxHits-2); - _maxIndex=(maxHits-3); + _tracksNHits.resize(maxHits - 2); + _maxIndex = (maxHits - 3); } - + // Sort all track vectors according to chi2/nDof // void sort(); - - /// Returns the TrackExtendedVec for track with n hits. + + /// Returns the TrackExtendedVec for track with n hits. /// In case n is larger than the maximal number the vector with the largest n ist returned. /// \attention The smallest valid number is three! For /// performance reasons there is no safety check! - inline TrackExtendedVec & getTracksWithNHitsVec( size_t nHits ) { - //return _tracksNHits[ std::min(nHits-3, _maxIndex) ]; - // for debugging: with boundary check - return _tracksNHits.at(std::min(nHits-3, _maxIndex)); + inline TrackExtendedVec& getTracksWithNHitsVec(size_t nHits) { + // return _tracksNHits[ std::min(nHits-3, _maxIndex) ]; + // for debugging: with boundary check + return _tracksNHits.at(std::min(nHits - 3, _maxIndex)); } - + protected: - std::vector< TrackExtendedVec > _tracksNHits; + std::vector _tracksNHits; size_t _maxIndex; /// local cache variable to avoid calculation overhead }; - + TracksWithNHitsContainer _tracksWithNHitsContainer; - - int InitialiseVTX(LCEvent * evt); - int InitialiseFTD(LCEvent * evt); + + int InitialiseVTX(LCEvent* evt); + int InitialiseFTD(LCEvent* evt); void ProcessOneSector(int iSectorPhi, int iSectorTheta); void ProcessOneSectorVer2(int iSectorPhi, int iSectorTheta); void CleanUp(); - TrackExtended * TestTriplet(TrackerHitExtended * outerHit, - TrackerHitExtended * middleHit, - TrackerHitExtended * innerHit, - HelixClass_double & helix, - int omegamode); - - int BuildTrack_KalFit(TrackerHitExtended * outerHit, - TrackerHitExtended * middleHit, - TrackerHitExtended * innerHit, - HelixClass_double & helix, - int innerlayer, - TrackExtended * trackAR); + TrackExtended* TestTriplet(TrackerHitExtended* outerHit, TrackerHitExtended* middleHit, TrackerHitExtended* innerHit, + HelixClass_double& helix, int omegamode); + + int BuildTrack_KalFit(TrackerHitExtended* outerHit, TrackerHitExtended* middleHit, TrackerHitExtended* innerHit, + HelixClass_double& helix, int innerlayer, TrackExtended* trackAR); int _useBuildTrackForHighPt; double _cosThetaRangeForBuildTrackForHighPt; double _phiRangeForBuildTrackForHighPt; - void getPhiThetaRegionForHighPt(int* boundaries,TrackExtended* trackAR); + void getPhiThetaRegionForHighPt(int* boundaries, TrackExtended* trackAR); - void Sorting( TrackExtendedVec & trackVec); - void CreateTrack(TrackExtended * trackAR ); + void Sorting(TrackExtendedVec& trackVec); + void CreateTrack(TrackExtended* trackAR); void AttachRemainingVTXHitsSlow(); void AttachRemainingFTDHitsSlow(); void AttachRemainingVTXHitsFast(); @@ -392,11 +371,11 @@ class FPCCDSiliconTracking_MarlinTrk : public Processor { void AttachRemainingVTXHitsVeryFast(); void TrackingInFTD(); int BuildTrackFTD(TrackExtended* trackAR, int* nLR, int iS); - int AttachHitToTrack(TrackExtended * trackAR, TrackerHitExtended * hit, int iopt); - int AttachHitToTrack_KalFit(TrackExtended * trackAR, TrackerHitExtended * hit); - + int AttachHitToTrack(TrackExtended* trackAR, TrackerHitExtended* hit, int iopt); + int AttachHitToTrack_KalFit(TrackExtended* trackAR, TrackerHitExtended* hit); + void FinalRefit(LCCollectionVec* trk_col, LCCollectionVec* rel_col); - + float _bField; float _chi2WRPhiTriplet; float _chi2WRPhiQuartet; @@ -408,191 +387,215 @@ class FPCCDSiliconTracking_MarlinTrk : public Processor { float _minDistCutAttachForVXD; int _minimalLayerToAttach; int _minMissAddition; - + // two pi is not a constant in cmath. Calculate it, once! static const double TWOPI; - + double _dPhi; double _dTheta; double _dPhiFTD; - - std::vector _Combinations; std::vector _CombinationsFTD; - + float _resolutionRPhiVTX; float _resolutionZVTX; - + float _resolutionRPhiFTD; float _resolutionZFTD; - + float _resolutionRPhiSIT; float _resolutionZSIT; - + float _phiCutForMerging; float _tanlambdaCutForMerging; float _angleCutForMerging; - //float _angleCutForMerging_highPt; - //float _angleCutForMerging_lowPt; - + // float _angleCutForMerging_highPt; + // float _angleCutForMerging_lowPt; + int _print; int _checkForDelta; float _minDistToDelta; - + float _distRPhi; float _distZ; float _chi2FitCut; float _chi2FitCut_lowPt; - - + TrackExtendedVec _trackImplVec; - - + float _cutOnD0, _cutOnZ0, _cutOnOmegaVXD, _cutOnOmegaFTD; - double _cutOnPtVXD,_cutOnPtFTD; - + double _cutOnPtVXD, _cutOnPtFTD; + int _minimalHits; int _nHitsChi2; int _attachVXD; int _attachFTD; - + int _max_hits_per_sector; - - int _nTotalVTXHits,_nTotalFTDHits,_nTotalSITHits; + + int _nTotalVTXHits, _nTotalFTDHits, _nTotalSITHits; int _useSIT; int _useFTD; - - + // int _createMap; - + UTIL::BitField64* _encoder; - int getDetectorID(TrackerHit* hit) { _encoder->setValue(hit->getCellID0()); return (*_encoder)[lcio::LCTrackerCellID::subdet()]; } - int getSideID(TrackerHit* hit) { _encoder->setValue(hit->getCellID0()); return (*_encoder)[lcio::LCTrackerCellID::side()]; }; - int getLayerID(TrackerHit* hit) { _encoder->setValue(hit->getCellID0()); return (*_encoder)[lcio::LCTrackerCellID::layer()]; }; - int getModuleID(TrackerHit* hit) { _encoder->setValue(hit->getCellID0()); return (*_encoder)[lcio::LCTrackerCellID::module()]; }; - int getSensorID(TrackerHit* hit) { _encoder->setValue(hit->getCellID0()); return (*_encoder)[lcio::LCTrackerCellID::sensor()]; }; - - int getDetectorID(SimTrackerHit* hit) { _encoder->setValue(hit->getCellID0()); return (*_encoder)[lcio::LCTrackerCellID::subdet()]; } - int getSideID(SimTrackerHit* hit) { _encoder->setValue(hit->getCellID0()); return (*_encoder)[lcio::LCTrackerCellID::side()]; }; - int getLayerID(SimTrackerHit* hit) { _encoder->setValue(hit->getCellID0()); return (*_encoder)[lcio::LCTrackerCellID::layer()]; }; - int getModuleID(SimTrackerHit* hit) { _encoder->setValue(hit->getCellID0()); return (*_encoder)[lcio::LCTrackerCellID::module()]; }; - int getSensorID(SimTrackerHit* hit) { _encoder->setValue(hit->getCellID0()); return (*_encoder)[lcio::LCTrackerCellID::sensor()]; }; - - void setupGeom(const dd4hep::Detector& theDetector) ; - - + int getDetectorID(TrackerHit* hit) { + _encoder->setValue(hit->getCellID0()); + return (*_encoder)[lcio::LCTrackerCellID::subdet()]; + } + int getSideID(TrackerHit* hit) { + _encoder->setValue(hit->getCellID0()); + return (*_encoder)[lcio::LCTrackerCellID::side()]; + }; + int getLayerID(TrackerHit* hit) { + _encoder->setValue(hit->getCellID0()); + return (*_encoder)[lcio::LCTrackerCellID::layer()]; + }; + int getModuleID(TrackerHit* hit) { + _encoder->setValue(hit->getCellID0()); + return (*_encoder)[lcio::LCTrackerCellID::module()]; + }; + int getSensorID(TrackerHit* hit) { + _encoder->setValue(hit->getCellID0()); + return (*_encoder)[lcio::LCTrackerCellID::sensor()]; + }; + + int getDetectorID(SimTrackerHit* hit) { + _encoder->setValue(hit->getCellID0()); + return (*_encoder)[lcio::LCTrackerCellID::subdet()]; + } + int getSideID(SimTrackerHit* hit) { + _encoder->setValue(hit->getCellID0()); + return (*_encoder)[lcio::LCTrackerCellID::side()]; + }; + int getLayerID(SimTrackerHit* hit) { + _encoder->setValue(hit->getCellID0()); + return (*_encoder)[lcio::LCTrackerCellID::layer()]; + }; + int getModuleID(SimTrackerHit* hit) { + _encoder->setValue(hit->getCellID0()); + return (*_encoder)[lcio::LCTrackerCellID::module()]; + }; + int getSensorID(SimTrackerHit* hit) { + _encoder->setValue(hit->getCellID0()); + return (*_encoder)[lcio::LCTrackerCellID::sensor()]; + }; + + void setupGeom(const dd4hep::Detector& theDetector); + unsigned int _nLayersVTX; - + unsigned int _nLayersSIT; - - + std::vector _zLayerFTD; - + unsigned int _nlayersFTD; bool _petalBasedFTDWithOverlaps; - int _nPhiFTD; + int _nPhiFTD; int _output_track_col_quality; static const int _output_track_col_quality_GOOD; static const int _output_track_col_quality_FAIR; static const int _output_track_col_quality_POOR; - int _sw_theta;//search window theta + int _sw_theta; // search window theta float _chi2FitCut_kalman; bool _useClusterRejection; float _minDotOf2Clusters; - int getIntersectionEasy(HelixClass_double& helix, TrackerHit* curInmos , int layer, double* isec, double* ref); - int getIntersectionEasyTest(HelixClass_double& helix, TrackerHit* basisTrkhit , int layer, std::vector &vec ); + int getIntersectionEasy(HelixClass_double& helix, TrackerHit* curInmos, int layer, double* isec, double* ref); + int getIntersectionEasyTest(HelixClass_double& helix, TrackerHit* basisTrkhit, int layer, std::vector& vec); int CheckTiltOf2Clusters(TrackerHit* A, TrackerHit* B, int level); float DotOf2Clusters(TrackerHit* A, TrackerHit* B); - int KalFit(int& ndf, float& Chi2, TrackerHitVec trkHits,TrackerHitVec& hits_in_fit, TrackerHitVec& outliers, float* par , float* epar, HelixClass_double& helix); + int KalFit(int& ndf, float& Chi2, TrackerHitVec trkHits, TrackerHitVec& hits_in_fit, TrackerHitVec& outliers, + float* par, float* epar, HelixClass_double& helix); int getPhiThetaRegion(TrackExtended* trackAR, int layer, int* Boundaries); struct GeoData_t { int nladder; - double rmin; // distance of inner surface of sensitive region from IP - double dphi; // azimuthal angle step of each ladder - double phi0; // aximuthal angle offset - std::vector cosphi; // cos[phi_ladder], cos_phi of each ladder - std::vector sinphi; // sin[phi_ladder], sin_phi of each ladder - std::vector phi; // phi of each ladder - std::vector phiAtXiMin; // phiAtXiMin of each ladder - std::vector phiAtXiMax; // phiAtXiMax of each ladder - std::vector ladder_incline;//the tilt of the line of the ladder expressed by phi - double sthick; // sensitive region thickness - double sximin; // minimum xi of sensitive region. - double sximax; // maximum xi of sensitive region - double hlength; // ladder's half length in z - int num_xi_pixel; // Number of xi pixel in this ladder - int num_zeta_pixel; // Number of zeta pixel in this ladder - double rmes; //distance in R of measurement surface + double rmin; // distance of inner surface of sensitive region from IP + double dphi; // azimuthal angle step of each ladder + double phi0; // aximuthal angle offset + std::vector cosphi; // cos[phi_ladder], cos_phi of each ladder + std::vector sinphi; // sin[phi_ladder], sin_phi of each ladder + std::vector phi; // phi of each ladder + std::vector phiAtXiMin; // phiAtXiMin of each ladder + std::vector phiAtXiMax; // phiAtXiMax of each ladder + std::vector ladder_incline; // the tilt of the line of the ladder expressed by phi + double sthick; // sensitive region thickness + double sximin; // minimum xi of sensitive region. + double sximax; // maximum xi of sensitive region + double hlength; // ladder's half length in z + int num_xi_pixel; // Number of xi pixel in this ladder + int num_zeta_pixel; // Number of zeta pixel in this ladder + double rmes; // distance in R of measurement surface }; - + struct vxdGeoData_t { - int nLayer; - int maxLadder; - std::vector geodata; - }_vxd,_sit; + int nLayer; + int maxLadder; + std::vector geodata; + } _vxd, _sit; void InitVXDGeometry(const dd4hep::Detector& theDetector); void InitSITGeometry(const dd4hep::Detector& theDetector); FloatVec _pixelSizeVec; float _pixelheight; - TVector3 LocalToGlobal(TVector3 local,int layer,int ladder); - //purityMCP CheckOriginOf2Clusters(TrackerHit* A, TrackerHit* B); + TVector3 LocalToGlobal(TVector3 local, int layer, int ladder); + // purityMCP CheckOriginOf2Clusters(TrackerHit* A, TrackerHit* B); void calcTrackParameterOfMCP(MCParticle* pmcp, double* par); - - class ClusterStatus{ - public : - int cellid0 ; - int cellid1; - unsigned int layer ; - unsigned int ladder; - unsigned int xiwidth ; - unsigned int zetawidth ; - unsigned int nPix ; - unsigned int tilt ; - unsigned int quality ; - - ClusterStatus(TrackerHit* hit){ - cellid0 = hit->getCellID0(); - cellid1 = hit->getCellID1(); - //layer = ( cellid0 >> 5 ) & 0x000001ff;//maybe bug. - //ladder = (cellid0 >> 15 ) & 0x000000ff; - xiwidth = cellid1 & 0x000001ff ; - zetawidth = ( cellid1 >> 9 ) & 0x000001ff; - nPix = ( cellid1 >> 18) & 0x000003ff; - tilt = ( cellid1 >> 28) & 0x00000003; - quality = ( cellid1 >> 30) & 0x00000003; - const int cellId_trk = hit->getCellID0(); - UTIL::BitField64 encoder_trk( lcio::LCTrackerCellID::encoding_string() ) ; - encoder_trk.setValue(cellId_trk) ; - layer = encoder_trk[lcio::LCTrackerCellID::layer()] ; - ladder = encoder_trk[lcio::LCTrackerCellID::module()] ; - } - ClusterStatus(){;} + + class ClusterStatus { + public: + int cellid0; + int cellid1; + unsigned int layer; + unsigned int ladder; + unsigned int xiwidth; + unsigned int zetawidth; + unsigned int nPix; + unsigned int tilt; + unsigned int quality; + + ClusterStatus(TrackerHit* hit) { + cellid0 = hit->getCellID0(); + cellid1 = hit->getCellID1(); + // layer = ( cellid0 >> 5 ) & 0x000001ff;//maybe bug. + // ladder = (cellid0 >> 15 ) & 0x000000ff; + xiwidth = cellid1 & 0x000001ff; + zetawidth = (cellid1 >> 9) & 0x000001ff; + nPix = (cellid1 >> 18) & 0x000003ff; + tilt = (cellid1 >> 28) & 0x00000003; + quality = (cellid1 >> 30) & 0x00000003; + const int cellId_trk = hit->getCellID0(); + UTIL::BitField64 encoder_trk(lcio::LCTrackerCellID::encoding_string()); + encoder_trk.setValue(cellId_trk); + layer = encoder_trk[lcio::LCTrackerCellID::layer()]; + ladder = encoder_trk[lcio::LCTrackerCellID::module()]; + } + ClusterStatus() { ; } }; - //Old Ver////////////////// - typedef std::map< std::pair< int, int >, int > RangeMap; + // Old Ver////////////////// + typedef std::map, int> RangeMap; RangeMap _phiRangeForTriplet; - double getNeededPhiSectors(double Pt, int outly , int inly); //Difference of radian is returned + double getNeededPhiSectors(double Pt, int outly, int inly); // Difference of radian is returned /////////////////////////// - //New Ver////////////////////==under construction==== - typedef std::map< std::vector , std::vector > RangeMapVer2; + // New Ver////////////////////==under construction==== + typedef std::map, std::vector> RangeMapVer2; RangeMapVer2 _phiRangeForTripletVer2; void getNeededPhiSectorsVer2(double Pt, std::vector layers, std::vector& phiDiff); /////////////////////////////======================== - float _safetyPhiRange_ratio;/** - Extra range in addition to main range used for triplet construction process and needed to find triplet - is calculated by getNeededPhiSectors, but safety range is not considered. - Value of _safetyRange is used such as Range = Range*(1 + _safetyRange); - */ + float _safetyPhiRange_ratio; /** + Extra range in addition to main range used for triplet construction process and needed to find triplet + is calculated by getNeededPhiSectors, but safety range is not considered. + Value of _safetyRange is used such as Range = Range*(1 + _safetyRange); + */ int _safetyPhiRange_fix; float _fudgeFactorForSITsr_rphi; float _fudgeFactorForSITsr_z; @@ -616,19 +619,17 @@ class FPCCDSiliconTracking_MarlinTrk : public Processor { LCCollection* _simFTDsp; LCCollection* _simFTDpix; - - double _nSigmaBuild_phi; double _nSigmaBuild_theta; - bool _keepCandidate;//used in AttachRemainingVTXHitsVeryFast <-- under construction for now + bool _keepCandidate; // used in AttachRemainingVTXHitsVeryFast <-- under construction for now moriUTIL* _moriUtil; GetPurityUtil* _purityUtil; -//////////////////////////////////////////////////////////////// -////from here, a lot of debug tools and variables for mori ///// -//////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////// + ////from here, a lot of debug tools and variables for mori ///// + //////////////////////////////////////////////////////////////// bool _mydebug; bool _mydebugKalFit; bool _mydebugIntersection; @@ -639,17 +640,17 @@ class FPCCDSiliconTracking_MarlinTrk : public Processor { bool _mydebugVXDHits; bool _mydebugSITHits; bool _mydebugTriplet; - int _mydebugTripletMode; + int _mydebugTripletMode; bool _mydebugTripletVXD; bool _mydebugTripletFTD; bool _mydebugTripletVXDFTD; bool _mydebugBuildTrack; - int _mydebugBuildTrackMode; + int _mydebugBuildTrackMode; bool _mydebugAttachVXD; bool _mydebugPrintMCP; bool _stopwatch; - class Timer{ - public: + class Timer { + public: TStopwatch inAnEvt; TStopwatch InitialiseVTX; TStopwatch InitialiseFTD; @@ -660,7 +661,7 @@ class FPCCDSiliconTracking_MarlinTrk : public Processor { TStopwatch AttachRemainingVXD; TStopwatch AttachRemainingFTD; TStopwatch FinalRefit; - void reset(){ + void reset() { inAnEvt.Reset(); InitialiseVTX.Reset(); InitialiseFTD.Reset(); @@ -672,193 +673,178 @@ class FPCCDSiliconTracking_MarlinTrk : public Processor { AttachRemainingFTD.Reset(); FinalRefit.Reset(); } - void cout(){ - printf("inAnEvt : RT=%.3f s, CPU=%.3f s \n",inAnEvt.RealTime(),inAnEvt.CpuTime()); - printf("InitialiseVTX : RT=%.3f s, CPU=%.3f s \n",InitialiseVTX.RealTime(),InitialiseVTX.CpuTime()); - printf("InitialiseFTD : RT=%.3f s, CPU=%.3f s \n",InitialiseFTD.RealTime(),InitialiseFTD.CpuTime()); - printf("ProcessOneSector : RT=%.3f s, CPU=%.3f s \n",ProcessOneSector.RealTime(),ProcessOneSector.CpuTime()); - printf("TrackingInFTD : RT=%.3f s, CPU=%.3f s \n",TrackingInFTD.RealTime(),TrackingInFTD.CpuTime()); - printf("Sorting : RT=%.3f s, CPU=%.3f s \n",Sorting.RealTime(),Sorting.CpuTime()); - printf("CreateTrack : RT=%.3f s, CPU=%.3f s \n",CreateTrack.RealTime(),CreateTrack.CpuTime()); - printf("AttachRemainingVXD: RT=%.3f s, CPU=%.3f s \n",AttachRemainingVXD.RealTime(),AttachRemainingVXD.CpuTime()); - printf("AttachRemainingFTD: RT=%.3f s, CPU=%.3f s \n",AttachRemainingFTD.RealTime(),AttachRemainingFTD.CpuTime()); - printf("FinalRefit : RT=%.3f s, CPU=%.3f s \n",FinalRefit.RealTime(),FinalRefit.CpuTime()); + void cout() { + printf("inAnEvt : RT=%.3f s, CPU=%.3f s \n", inAnEvt.RealTime(), inAnEvt.CpuTime()); + printf("InitialiseVTX : RT=%.3f s, CPU=%.3f s \n", InitialiseVTX.RealTime(), InitialiseVTX.CpuTime()); + printf("InitialiseFTD : RT=%.3f s, CPU=%.3f s \n", InitialiseFTD.RealTime(), InitialiseFTD.CpuTime()); + printf("ProcessOneSector : RT=%.3f s, CPU=%.3f s \n", ProcessOneSector.RealTime(), ProcessOneSector.CpuTime()); + printf("TrackingInFTD : RT=%.3f s, CPU=%.3f s \n", TrackingInFTD.RealTime(), TrackingInFTD.CpuTime()); + printf("Sorting : RT=%.3f s, CPU=%.3f s \n", Sorting.RealTime(), Sorting.CpuTime()); + printf("CreateTrack : RT=%.3f s, CPU=%.3f s \n", CreateTrack.RealTime(), CreateTrack.CpuTime()); + printf("AttachRemainingVXD: RT=%.3f s, CPU=%.3f s \n", AttachRemainingVXD.RealTime(), + AttachRemainingVXD.CpuTime()); + printf("AttachRemainingFTD: RT=%.3f s, CPU=%.3f s \n", AttachRemainingFTD.RealTime(), + AttachRemainingFTD.CpuTime()); + printf("FinalRefit : RT=%.3f s, CPU=%.3f s \n", FinalRefit.RealTime(), FinalRefit.CpuTime()); } - Timer(){reset();} - }_timer; + Timer() { reset(); } + } _timer; TStopwatch _timer2Triplet; TStopwatch _timer2Build; - bool _mydebugstopwatch2; + bool _mydebugstopwatch2; float _currentPurity; MCPMap LoadMCPMap(); - std::map< MCParticle*, SimTrackerHitVec > _mcpVXD; - std::map< MCParticle*, SimTrackerHitVec > _mcpVXDFTD; - std::map< MCParticle*, SimTrackerHitVec > _mcpVXDSIT; - std::map< MCParticle*, SimTrackerHitVec > _mcpVXDFTDSIT; - std::map< MCParticle*, SimTrackerHitVec > _mcpFTD; - std::map< MCParticle*, SimTrackerHitVec > _mcpFTDSIT; - std::map< MCParticle*, SimTrackerHitVec > _mcpSIT; - - - enum MCPContributions{ - contVXD, - contFTD, - contSIT, - contVXDFTD, - contVXDSIT, - contFTDSIT, - contVXDFTDSIT, - contBG, - contSize + std::map _mcpVXD; + std::map _mcpVXDFTD; + std::map _mcpVXDSIT; + std::map _mcpVXDFTDSIT; + std::map _mcpFTD; + std::map _mcpFTDSIT; + std::map _mcpSIT; + + enum MCPContributions { + contVXD, + contFTD, + contSIT, + contVXDFTD, + contVXDSIT, + contFTDSIT, + contVXDFTDSIT, + contBG, + contSize }; enum MCPContributions getMCPContribution(IntVec nsub); - class Triplet : public IMPL::TrackImpl{ - public : - static int numOfProcesses; - int id; - int quality_code; - int detID[3];//内側に近いところから詰める。 - int layer[3]; - float probability; - float purity; - SimTrackerHitVec simVecFromTrk;//TrackerHitVecに対応するもの - std::pair< MCParticle* , SimTrackerHitVec > mcTruth ;//Dominant MCPについての情報 - - //new (2013_08_10) - TrackerHitVec truthTrkHits ;//Dominant MCPのsimthitsに対応するTrackerHitVec. - enum MCPContributions mcpcont; - IntVec nsub;//vxd:0,sit:1,ftd:2 <--for Dominant MCP - - - float mcp_d0; - float mcp_z0; - float mcp_omega; - float mcp_phi0; - float mcp_tanL; - - //bool availableInBuildedTrack; - - Triplet(bool incrementID = true){ - id = numOfProcesses; - if(incrementID){ - numOfProcesses++; - } - quality_code = -1; - detID[0] = detID[1] = detID[2] = -1; - layer[0] = layer[1] = layer[2] = -1; - probability = 1e20; - purity = 1e20; - simVecFromTrk.clear(); - mcTruth.first = 0; mcTruth.second.clear(); - truthTrkHits.clear(); - mcpcont = contSize; - nsub.clear(); - mcp_d0 = mcp_z0 = mcp_omega = mcp_phi0 = mcp_tanL = 1e20; - } - Triplet(const Triplet& obj) : IMPL::TrackImpl(obj){ - *this = obj; - } + class Triplet : public IMPL::TrackImpl { + public: + static int numOfProcesses; + int id; + int quality_code; + int detID[3]; // 内側に近いところから詰める。 + int layer[3]; + float probability; + float purity; + SimTrackerHitVec simVecFromTrk; // TrackerHitVecに対応するもの + std::pair mcTruth; // Dominant MCPについての情報 + + // new (2013_08_10) + TrackerHitVec truthTrkHits; // Dominant MCPのsimthitsに対応するTrackerHitVec. + enum MCPContributions mcpcont; + IntVec nsub; // vxd:0,sit:1,ftd:2 <--for Dominant MCP + + float mcp_d0; + float mcp_z0; + float mcp_omega; + float mcp_phi0; + float mcp_tanL; + + // bool availableInBuildedTrack; + + Triplet(bool incrementID = true) { + id = numOfProcesses; + if (incrementID) { + numOfProcesses++; + } + quality_code = -1; + detID[0] = detID[1] = detID[2] = -1; + layer[0] = layer[1] = layer[2] = -1; + probability = 1e20; + purity = 1e20; + simVecFromTrk.clear(); + mcTruth.first = 0; + mcTruth.second.clear(); + truthTrkHits.clear(); + mcpcont = contSize; + nsub.clear(); + mcp_d0 = mcp_z0 = mcp_omega = mcp_phi0 = mcp_tanL = 1e20; + } + Triplet(const Triplet& obj) : IMPL::TrackImpl(obj) { *this = obj; } }; Triplet* _curtriplet; - - - enum BuildTrackResult{ - NormalEnd, - ManyMisAssignments, - ManyOutliers, - PhiThetaError, - BuildTrackResultSize - }; - class BuildedTrack : public IMPL::TrackImpl{ - public : - static int numOfProcesses; - int id; - - BuildTrackResult result; - int nMisAssign; - Triplet triplet; - const MCParticle* truthmcp; - SimTrackerHitVec simvec; - float probability; - float purity; - SimTrackerHitVec simVecFromTrk;//TrackerHitVecに対応するもの - BuildedTrack():triplet(false){ - id = numOfProcesses; - numOfProcesses++; - result = BuildTrackResultSize; - nMisAssign = -1; - truthmcp = 0; - simvec.clear(); - probability = 1e20; - purity = 1e20; - simVecFromTrk.clear(); - } - BuildedTrack(const BuildedTrack& obj) : IMPL::TrackImpl(obj){ - *this = obj; - } + + enum BuildTrackResult { NormalEnd, ManyMisAssignments, ManyOutliers, PhiThetaError, BuildTrackResultSize }; + class BuildedTrack : public IMPL::TrackImpl { + public: + static int numOfProcesses; + int id; + + BuildTrackResult result; + int nMisAssign; + Triplet triplet; + const MCParticle* truthmcp; + SimTrackerHitVec simvec; + float probability; + float purity; + SimTrackerHitVec simVecFromTrk; // TrackerHitVecに対応するもの + BuildedTrack() : triplet(false) { + id = numOfProcesses; + numOfProcesses++; + result = BuildTrackResultSize; + nMisAssign = -1; + truthmcp = 0; + simvec.clear(); + probability = 1e20; + purity = 1e20; + simVecFromTrk.clear(); + } + BuildedTrack(const BuildedTrack& obj) : IMPL::TrackImpl(obj) { *this = obj; } }; bool _availableInBuildedTrack; - typedef std::vector< BuildedTrack > BuildedTrackVec; + typedef std::vector BuildedTrackVec; BuildedTrackVec _buildedTrackContainer; void SetBuildedTrack(TrackExtended* trackAR, BuildedTrackVec& btrackvec); void BuildedTrackDebuger1(BuildedTrackVec::iterator begin, BuildedTrackVec::iterator end); - void BuildedTrackDebuger2(std::vector::iterator begin, std::vector::iterator end); - - //時間がアレばclass templateにしてみたい。 - class MCP_BuildedTrack{ - public : - std::pair pair; - IntVec nsub;//nhits in sub detectors. 0 VXD, 1 FTD, 2 SIT - std::vector BuildedTrackVec; - std::vector BuildedTrack2ndVec; - std::vector BuildedTrack3rdVec; + void BuildedTrackDebuger2(std::vector::iterator begin, + std::vector::iterator end); + + // 時間がアレばclass templateにしてみたい。 + class MCP_BuildedTrack { + public: + std::pair pair; + IntVec nsub; // nhits in sub detectors. 0 VXD, 1 FTD, 2 SIT + std::vector BuildedTrackVec; + std::vector BuildedTrack2ndVec; + std::vector BuildedTrack3rdVec; }; - typedef std::map BTMap; + typedef std::map BTMap; BTMap _mcpBuildedTrackContainer; - std::vector< std::map > _mcpRemainingBTContainerA; - //purity 100%のトリプレットが生成されなかった生成されなかったmcp - std::vector< std::map > _mcpRemainingBTContainerB; - //purity 100%のトリプレットが生成されたものの、quality_code != 0により結局再構成されなかったmcp - - + std::vector> _mcpRemainingBTContainerA; + // purity 100%のトリプレットが生成されなかった生成されなかったmcp + std::vector> _mcpRemainingBTContainerB; + // purity 100%のトリプレットが生成されたものの、quality_code != 0により結局再構成されなかったmcp + std::vector _tripletContainer; - std::vector< Triplet > _tripletContainer; - - class MCP_Triplet{ - public : - std::pair pair; - IntVec nsub;//nhits in sub detectors. 0 VXD, 1 FTD, 2 SIT - std::vector tripvec; - std::vector trip2ndvec; - std::vector trip3rdvec; + class MCP_Triplet { + public: + std::pair pair; + IntVec nsub; // nhits in sub detectors. 0 VXD, 1 FTD, 2 SIT + std::vector tripvec; + std::vector trip2ndvec; + std::vector trip3rdvec; }; - typedef std::map TripMap; + typedef std::map TripMap; TripMap _mcpTripletContainer; + std::vector> _mcpRemainingTRContainerA; + // purity 100%のトリプレットが生成されなかった生成されなかったmcp + std::vector> _mcpRemainingTRContainerB; + // purity 100%のトリプレットが生成されたものの、quality_code != 0により結局再構成されなかったmcp - std::vector< std::map > _mcpRemainingTRContainerA; - //purity 100%のトリプレットが生成されなかった生成されなかったmcp - std::vector< std::map > _mcpRemainingTRContainerB; - //purity 100%のトリプレットが生成されたものの、quality_code != 0により結局再構成されなかったmcp - - void TripletDebugerWithMCPRemain(int nth, std::vector< std::map > A); + void TripletDebugerWithMCPRemain(int nth, std::vector> A); MCPMap _mcpMap; std::vector _naviVec; IntVec getNHitsInSubDet(SimTrackerHitVec simvec); void TripletDebuger1(std::vector::iterator begin, std::vector::iterator end); void TripletDebuger2(std::vector::iterator begin, std::vector::iterator end); - - }; int FPCCDSiliconTracking_MarlinTrk::Triplet::numOfProcesses = 0; int FPCCDSiliconTracking_MarlinTrk::BuildedTrack::numOfProcesses = 0; -#endif +#endif diff --git a/source/Refitting/include/FullLDCTracking_MarlinTrk.h b/source/Refitting/include/FullLDCTracking_MarlinTrk.h index febb19f..58472dc 100644 --- a/source/Refitting/include/FullLDCTracking_MarlinTrk.h +++ b/source/Refitting/include/FullLDCTracking_MarlinTrk.h @@ -1,54 +1,53 @@ #ifndef FULLLDCTRACKING_H #define FULLLDCTRACKING_H 1 -#include "marlin/Processor.h" -#include -#include "lcio.h" -#include #include "ClusterExtended.h" -#include "TrackExtended.h" -#include "TrackerHitExtended.h" -#include "TrackHitPair.h" -#include "HelixClass.h" #include "ClusterShapes.h" #include "GroupTracks.h" +#include "HelixClass.h" +#include "TrackExtended.h" +#include "TrackHitPair.h" +#include "TrackerHitExtended.h" +#include "lcio.h" +#include "marlin/Processor.h" #include +#include #include +#include #include "MarlinTrk/IMarlinTrack.h" -#include #include "UTIL/LCTrackerConf.h" +#include -using namespace lcio ; -using namespace marlin ; - +using namespace lcio; +using namespace marlin; namespace MarlinTrk { - class HelixFit; - class IMarlinTrkSystem ; -} +class HelixFit; +class IMarlinTrkSystem; +} // namespace MarlinTrk -namespace dd4hep{ - class Detector ; +namespace dd4hep { +class Detector; } /** === FullLDCTracking_MarlinTrk Processor ===
- * Processor performing track finding procedure in + * Processor performing track finding procedure in * the entire LDC detector by linking track segments * found by the SiliconTracking module in the silicon detectors - * and by the LEPTracking module in TPC. - *

Input collections and prerequisites

- * Processor requires collection of digitized vertex, sit, ftd, set, etd & tpc tracker hits + * and by the LEPTracking module in TPC. + *

Input collections and prerequisites

+ * Processor requires collection of digitized vertex, sit, ftd, set, etd & tpc tracker hits * and also the collections of tracks found in the silicon detectors * and in TPC. *

Output

- * Processor produces an LCIO collection of the Tracks. Each track is characterised by + * Processor produces an LCIO collection of the Tracks. Each track is characterised by * five parameters : Omega (signed curvuture), Tan(lambda) where * lambda is the dip angle, Phi (azimuthal angle @ point of closest approach), D0 (signed impact parameter), - * Z0 (displacement along z axis at the point of closest approach to IP). + * Z0 (displacement along z axis at the point of closest approach to IP). * Covariance matrix for these parameters is also provided. - * Only lower left corner of the covariance matrix is stored. The sequence of the covariance matrix elements + * Only lower left corner of the covariance matrix is stored. The sequence of the covariance matrix elements * assigned to track is the following:
* (D0,D0)
* (Phi,D0), (Phi,Phi)
@@ -58,19 +57,19 @@ namespace dd4hep{ * The number of hits in the different subdetectors associated * with each track can be accessed via method Track::getSubdetectorHitNumbers(). * This method returns vector of integers :
- * number of VTX hits used in the track fit is the 1st element in this vector + * number of VTX hits used in the track fit is the 1st element in this vector * (Track::getSubdetectorHitNumbers()[0])
- * number of FTD hits used in the track fit is the 2nd element in this vector + * number of FTD hits used in the track fit is the 2nd element in this vector * (Track::getSubdetectorHitNumbers()[1])
- * number of SIT hits used in the track fit is the 3d element in this vector + * number of SIT hits used in the track fit is the 3d element in this vector * (Track::getSubdetectorHitNumbers()[2])
- * number of TPC hits used in the track fit is the 4th element in this vector + * number of TPC hits used in the track fit is the 4th element in this vector * (Track::getSubdetectorHitNumbers()[3])
- * number of SET hits used in the track fit is the 5th element in this vector + * number of SET hits used in the track fit is the 5th element in this vector * (Track::getSubdetectorHitNumbers()[4])
- * number of ETD hits used in the track fit is the 6th element in this vector + * number of ETD hits used in the track fit is the 6th element in this vector * (Track::getSubdetectorHitNumbers()[5])
- * total number of VTX hits in track is the 7th element in this vector + * total number of VTX hits in track is the 7th element in this vector * (Track::getSubdetectorHitNumbers()[6])
* total number of FTD hits in track is the 8th element in this vector * (Track::getSubdetectorHitNumbers()[7])
@@ -82,7 +81,7 @@ namespace dd4hep{ * (Track::getSubdetectorHitNumbers()[10])
* total number of ETD hits in track is the 12th element in this vector * (Track::getSubdetectorHitNumbers()[11])
- * Output track collection has by default a name "LDCTracks". + * Output track collection has by default a name "LDCTracks". * @param VTXHitCollection name of input VTX TrackerHit collection
* (default parameter value : "VTXTrackerHits")
* @param FTDPixelHitCollectionName name of input FTD Pixel TrackerHit collection
@@ -104,15 +103,15 @@ namespace dd4hep{ * @param SiTracks collection name of Si tracks
* (default parameter value : "SiTracks")
* @param SiTracksMCPRelColl Name of input Si track to MC particle relation collection
- * (default parameter value : "SiTracksMCP")
+ * (default parameter value : "SiTracksMCP")
* @param LDCTrackCollection name of the output LDC track collection
* (default parameter value : "LDCTracks")
* @param Chi2FitCut cut on the Chi2/Ndf of the track fit
* (default parameter value : 100.0)
- * @param Chi2PrefitCut cut on the prefit Chi2 of the track candidate, + * @param Chi2PrefitCut cut on the prefit Chi2 of the track candidate, * prefit is done with the simple helix hypothesis
* (default parameter value : 1e+5)
- * @param AngleCutForMerging cut on opening angle between + * @param AngleCutForMerging cut on opening angle between * particle momentum reconstructed with TPC and momentum reconstructed * with the Silicon detectors. If the opening angle is smaller that this cut * the track segment in Silicon trackers and in TPC are tested for their @@ -122,7 +121,7 @@ namespace dd4hep{ * parameter reconstructed with TPC and with Si detectors. If the relative difference is smaller * than this cut, the track segments in TPC and Si are tested for their compatibility
* (default parameter value : 0.25)
- * @param D0CutForMerging Upper cutoff on the difference in D0 [mm] to allow for merging + * @param D0CutForMerging Upper cutoff on the difference in D0 [mm] to allow for merging * of the Si and TPC segments
* (default parameter value : 500)
* @param Z0CutForMerging Upper cutoff on the difference in Z0 [mm] to allow for merging @@ -132,16 +131,16 @@ namespace dd4hep{ * if set to 1 debugging printout is activated * (default parameter value : 1)
* @param ForceSiTPCMerging This flag steers merging of Si and TPC track segments. If ForceMerging=1 - * Si and TPC track segments are forced to be merged if the opening angle between Si track + * Si and TPC track segments are forced to be merged if the opening angle between Si track * momentum and TPC track momentum - * is less than AngleCutForForcedMerging (see below) and difference in tracks + * is less than AngleCutForForcedMerging (see below) and difference in tracks * parameters Omega is less than OmegaCutForForcedMerging (see below)
* (default parameter value : 0) * @param AngleCutForForcedMerging cut on opening angle between Si track momentum and * TPC track momentum. Used to steer forced merging of Si and TPC track segments.
* (default parameter value : 0.05) * @param OmegaCutForForcedMerging cut on the difference between Si and TPC tracks parameter - * Omega. Used to steer forced merging of Si and TPC track segments. Relative + * Omega. Used to steer forced merging of Si and TPC track segments. Relative * errors are compared.
* (default parameter value : 0.15)
* @param D0CutForForcedMerging Upper cutoff on the difference in D0 to allow for forced @@ -150,7 +149,7 @@ namespace dd4hep{ * @param Z0CutForForcedMerging Upper cutoff on the difference in Z0 to allow for forced * merging of the Si and TPC segments
* (default parameter value : 200)
- * @param ForceTPCSegmentsMerging If this flag is set to 1, the code attempts to + * @param ForceTPCSegmentsMerging If this flag is set to 1, the code attempts to * merge TPC segments from the low pt splitted loopers
* (default parameter value : 1)
* @param D0CutToMergeTPCSegments cut on the difference in the track parameter @@ -158,35 +157,35 @@ namespace dd4hep{ * (default parameter value : 100)
* @param Z0CutToMergeTPCSegments cut on the difference in the track parameter * z0 [mm] to allow for merging TPC segments
- * (default parameter value : 5000)
+ * (default parameter value : 5000)
* @param DeltaPCutToMergeTPCSegments cut on the magnitude [GeV/c] of the vectorial difference * of the momentum vectors, associated with TPC segments, for the TPC segment's merging procedure
* (default parameter value : 0.1)
* @param PtCutToMergeTPCSegments lower cutoff on Pt of the TPC segments of the looping track for * the merging procedure. * If transverse momentum of the segments is less than cutoff the segments are allowed to be merged.
- * (default parameter value : 1.2)
- * @param AssignTPCHits If this flag is set to 1, the code attempts to assign left-over + * (default parameter value : 1.2)
+ * @param AssignTPCHits If this flag is set to 1, the code attempts to assign left-over * TPC hits to the accepted track candidates. No track refit is done in case when hit is assigned * to the existing track
* (default parameter value : 1)
- * @param AssignETDHits If this flag is set to 1, the code attempts to assign + * @param AssignETDHits If this flag is set to 1, the code attempts to assign * ETD hits to the accepted track candidates. No track refit is done in case when hit is assigned * to the existing track
* (default parameter value : 1)
- * @param AssignVTXHits If this flag is set to 1, the code attempts to assign left-over + * @param AssignVTXHits If this flag is set to 1, the code attempts to assign left-over * VTX hits to the accepted track candidates. Track refit is done in case when hit is assigned * to the existing track
* (default parameter value : 1)
- * @param AssignFTDHits If this flag is set to 1, the code attempts to assign left-over + * @param AssignFTDHits If this flag is set to 1, the code attempts to assign left-over * FTD hits to the accepted track candidates. Track refit is done in case when hit is assigned * to the existing track
* (default parameter value : 1)
- * @param AssignSITHits If this flag is set to 1, the code attempts to assign left-over + * @param AssignSITHits If this flag is set to 1, the code attempts to assign left-over * SIT hits to the accepted track candidates. Track refit is done in case when hit is assigned * to the existing track
* (default parameter value : 1)
- * @param AssignSETHits If this flag is set to 1, the code attempts to assign + * @param AssignSETHits If this flag is set to 1, the code attempts to assign * SET hits to the accepted track candidates. Track refit is done in case when hit is assigned * to the existing track
* (default parameter value : 1)
@@ -211,127 +210,119 @@ namespace dd4hep{ * @param NHitsExtrapolation Number of the last track hits for extrapolating helix * to the outer tracking detectors (SET, ETD)
* (default parameter value : 35)
- * @param CutOnTPCHits minimal number of TPC hits, used in the track fit, which is + * @param CutOnTPCHits minimal number of TPC hits, used in the track fit, which is * required for tracks which have no hits from the Si detectors
- * (default parameter value : 35)
- * @param CutOnTrackD0 cut on the d0 parameter of the track. If the d0 parameter is greater that + * (default parameter value : 35)
+ * @param CutOnTrackD0 cut on the d0 parameter of the track. If the d0 parameter is greater that * this cut, track is rejected
* (default parameter value : 500)
- * @param CutOnTrackZ0 cut on the z0 parameter of the track. If the z0 parameter is greater that + * @param CutOnTrackZ0 cut on the z0 parameter of the track. If the z0 parameter is greater that * this cut, track is rejected
* (default parameter value : 500)
- * @param ForbidOverlapInZTPC If this flag is set to 1 then merging of the TPC semiloops is + * @param ForbidOverlapInZTPC If this flag is set to 1 then merging of the TPC semiloops is * forbiden for segment overlapping in z
* (default parameter value : 0)
* @param ForbidOverlapInZComb If this flag is set to 1 then merging of left-over TPC semiloop and * combined Si-TPC track is their segments overlap in z
* (default parameter value : 0)
- * @param cosThetaCutHighPtMerge cut on cos theta between the two momentum vectors + * @param cosThetaCutHighPtMerge cut on cos theta between the two momentum vectors * when considering merger of high Pt tracks
* (default is 0.99)
- * @param cosThetaCutSoftHighPtMerge cut on the cos theta between the two momentum vectors + * @param cosThetaCutSoftHighPtMerge cut on the cos theta between the two momentum vectors * when considering merger of high Pt tracks for softer dp/p cut
* (default is 0.998)
- * @param momDiffCutHighPtMerge cut on dp/p + * @param momDiffCutHighPtMerge cut on dp/p * when considering merger of high Pt tracks
* (default is 0.01 [1/GeV])
- * @param momDiffCutSoftHighPtMerge softer cut on dp/p + * @param momDiffCutSoftHighPtMerge softer cut on dp/p * when considering merger of high Pt tracks
* (default is 0.25 [1/GeV])
- * @param hitDistanceCutHighPtMerge cut on 3D distance between hit + * @param hitDistanceCutHighPtMerge cut on 3D distance between hit * and helix extrapolation when considering merger of high Pt tracks
* (default is 25.0 [mm])
- * @param maxHitDistanceCutHighPtMerge cut for max 3D distance between any hit + * @param maxHitDistanceCutHighPtMerge cut for max 3D distance between any hit * and helix extrapolation when considering merger of high Pt tracks
* (default is 50.0 [mm])
- * @param maxFractionOfOutliersCutHighPtMerge cut on maximum fraction of outliers + * @param maxFractionOfOutliersCutHighPtMerge cut on maximum fraction of outliers * when considering merger of high Pt tracks
* (default is 0.95 )
- - + + * @author A. Raspereza (MPI Munich)
*/ class FullLDCTracking_MarlinTrk : public Processor { - + public: - - virtual Processor* newProcessor() { return new FullLDCTracking_MarlinTrk ; } - FullLDCTracking_MarlinTrk() ; - virtual void init() ; - virtual void processRunHeader( LCRunHeader* run ) ; - virtual void processEvent( LCEvent * evt ) ; - virtual void check( LCEvent * evt ) ; - virtual void end() ; - + virtual Processor* newProcessor() { return new FullLDCTracking_MarlinTrk; } + FullLDCTracking_MarlinTrk(); + virtual void init(); + virtual void processRunHeader(LCRunHeader* run); + virtual void processEvent(LCEvent* evt); + virtual void check(LCEvent* evt); + virtual void end(); + protected: - - void prepareVectors( LCEvent * evt ); + void prepareVectors(LCEvent* evt); void CleanUp(); void MergeTPCandSiTracks(); void MergeTPCandSiTracksII(); - TrackExtended * CombineTracks(TrackExtended * tpcTrk, TrackExtended * siTrk, float maxAllowedOutliers ,bool testCombinationOnly ); + TrackExtended* CombineTracks(TrackExtended* tpcTrk, TrackExtended* siTrk, float maxAllowedOutliers, + bool testCombinationOnly); -// TrackExtended * TrialCombineTracks(TrackExtended * tpcTrk, TrackExtended * siTrk); + // TrackExtended * TrialCombineTracks(TrackExtended * tpcTrk, TrackExtended * siTrk); - void Sorting(TrackExtendedVec & trackVec); + void Sorting(TrackExtendedVec& trackVec); void SelectCombinedTracks(); void AddNotCombinedTracks(); void CheckTracks(); void AddNotAssignedHits(); void RemoveSplitTracks(); - void AddTrackColToEvt(LCEvent * evt, TrackExtendedVec & trkVec, - std::string TrkColName); - float CompareTrk(TrackExtended * first, TrackExtended * second, - float d0Cut, float z0Cut, int iopt); - - float CompareTrkII(TrackExtended * first, TrackExtended * second, - float d0Cut, float z0Cut, int iopt, float &Angle); - float CompareTrkIII(TrackExtended * first, TrackExtended * second, - float d0Cut, float z0Cut, int iopt, float &Angle); - - void SortingTrackHitPairs(TrackHitPairVec & trackHitPairVec); - - void AssignSiHitsToTracks(TrackerHitExtendedVec hitVec, - float dcut); - - void AssignTPCHitsToTracks(TrackerHitExtendedVec hitVec, - float dcut); - + void AddTrackColToEvt(LCEvent* evt, TrackExtendedVec& trkVec, std::string TrkColName); + float CompareTrk(TrackExtended* first, TrackExtended* second, float d0Cut, float z0Cut, int iopt); + + float CompareTrkII(TrackExtended* first, TrackExtended* second, float d0Cut, float z0Cut, int iopt, float& Angle); + float CompareTrkIII(TrackExtended* first, TrackExtended* second, float d0Cut, float z0Cut, int iopt, float& Angle); + + void SortingTrackHitPairs(TrackHitPairVec& trackHitPairVec); + + void AssignSiHitsToTracks(TrackerHitExtendedVec hitVec, float dcut); + + void AssignTPCHitsToTracks(TrackerHitExtendedVec hitVec, float dcut); + void AssignOuterHitsToTracks(TrackerHitExtendedVec hitVec, float dcut, int refit); - + void CreateExtrapolations(); - + void CleanUpExtrapolations(); - - HelixClass * GetExtrapolationHelix(TrackExtended * track); - - void PrintOutMerging(TrackExtended * firstTrackExt, TrackExtended * secondTrackExt, - int iopt); - - void GeneralSorting(int * index, float * val, int direct, int nVal); - + + HelixClass* GetExtrapolationHelix(TrackExtended* track); + + void PrintOutMerging(TrackExtended* firstTrackExt, TrackExtended* secondTrackExt, int iopt); + + void GeneralSorting(int* index, float* val, int direct, int nVal); + int SegmentRadialOverlap(TrackExtended* pTracki, TrackExtended* pTrackj); bool VetoMerge(TrackExtended* firstTrackExt, TrackExtended* secondTrackExt); - - int _nRun ; - int _nEvt ; - + + int _nRun; + int _nEvt; + MarlinTrk::HelixFit* _fastfitter; - - /** pointer to the IMarlinTrkSystem instance + + /** pointer to the IMarlinTrkSystem instance */ - MarlinTrk::IMarlinTrkSystem* _trksystem ; - std::string _trkSystemName ; - - bool _MSOn, _ElossOn, _SmoothOn ; - + MarlinTrk::IMarlinTrkSystem* _trksystem; + std::string _trkSystemName; + + bool _MSOn, _ElossOn, _SmoothOn; + std::string _TPCTrackCollection; std::string _SiTrackCollection; std::string _TPCTrackMCPCollName; std::string _SiTrackMCPCollName; - + std::string _VTXTrackerHitCollection; std::string _SITTrackerHitCollection; std::string _SETTrackerHitCollection; @@ -339,10 +330,9 @@ class FullLDCTracking_MarlinTrk : public Processor { std::string _FTDSpacePointCollection; std::string _TPCTrackerHitCollection; std::string _ETDTrackerHitCollection; - + std::string _LDCTrackCollection; - - + TrackExtendedVec _allSiTracks; TrackExtendedVec _allTPCTracks; TrackExtendedVec _allCombinedTracks; @@ -355,36 +345,34 @@ class FullLDCTracking_MarlinTrk : public Processor { TrackerHitExtendedVec _allSITHits; TrackerHitExtendedVec _allSETHits; TrackerHitExtendedVec _allETDHits; - + float PI, PIOVER2, TWOPI; - + float _bField; float _chi2PrefitCut; float _chi2FitCut; - + int _debug; - + float _dPCutForMerging; float _d0CutForMerging; float _z0CutForMerging; float _dOmegaForMerging; float _angleForMerging; - - - int _forceMerging; + + int _forceMerging; float _dPCutForForcedMerging; float _d0CutForForcedMerging; float _z0CutForForcedMerging; float _dOmegaForForcedMerging; float _angleForForcedMerging; - - + int _mergeTPCSegments; float _dPCutToMergeTPC; float _PtCutToMergeTPC; float _d0CutToMergeTPC; float _z0CutToMergeTPC; - + float _cosThetaCutHighPtMerge; float _cosThetaCutSoftHighPtMerge; float _momDiffCutHighPtMerge; @@ -392,146 +380,153 @@ class FullLDCTracking_MarlinTrk : public Processor { float _hitDistanceCutHighPtMerge; float _maxHitDistanceCutHighPtMerge; float _maxFractionOfOutliersCutHighPtMerge; - + float _vetoMergeMomentumCut; - + float _initialTrackError_d0; float _initialTrackError_phi0; float _initialTrackError_omega; float _initialTrackError_z0; float _initialTrackError_tanL; - + double _maxChi2PerHit; double _minChi2ProbForSiliconTracks; - float _maxAllowedPercentageOfOutliersForTrackCombination; - int _maxAllowedSiHitRejectionsForTrackCombination; - + float _maxAllowedPercentageOfOutliersForTrackCombination; + int _maxAllowedSiHitRejectionsForTrackCombination; + bool _runMarlinTrkDiagnostics; std::string _MarlinTrkDiagnosticsName; - + int _nHitsExtrapolation; - + int _cutOnTPCHits; int _cutOnSiHits; - - - int _assignVTXHits,_assignFTDHits,_assignSITHits,_assignTPCHits; - + + int _assignVTXHits, _assignFTDHits, _assignSITHits, _assignTPCHits; + int _assignSETHits, _assignETDHits; - - float _distCutForVTXHits,_distCutForFTDHits,_distCutForSITHits,_distCutForTPCHits; - + + float _distCutForVTXHits, _distCutForFTDHits, _distCutForSITHits, _distCutForTPCHits; + float _distCutForSETHits, _distCutForETDHits; - - - float _d0TrkCut,_z0TrkCut; - - int _forbidOverlapInZTPC,_forbidOverlapInZComb; + + float _d0TrkCut, _z0TrkCut; + + int _forbidOverlapInZTPC, _forbidOverlapInZComb; float _energyLossErrorTPC; - - LCEvent * _evt; - - std::map _trackExtrapolatedHelix; + + LCEvent* _evt; + + std::map _trackExtrapolatedHelix; std::set _candidateCombinedTracks; - + UTIL::BitField64* _encoder; - int getDetectorID(TrackerHit* hit) { _encoder->setValue(hit->getCellID0()); return (*_encoder)[lcio::LCTrackerCellID::subdet()]; } - int getSideID(TrackerHit* hit) { _encoder->setValue(hit->getCellID0()); return (*_encoder)[lcio::LCTrackerCellID::side()]; }; - int getLayerID(TrackerHit* hit) { _encoder->setValue(hit->getCellID0()); return (*_encoder)[lcio::LCTrackerCellID::layer()]; }; - int getModuleID(TrackerHit* hit) { _encoder->setValue(hit->getCellID0()); return (*_encoder)[lcio::LCTrackerCellID::module()]; }; - int getSensorID(TrackerHit* hit) { _encoder->setValue(hit->getCellID0()); return (*_encoder)[lcio::LCTrackerCellID::sensor()]; }; + int getDetectorID(TrackerHit* hit) { + _encoder->setValue(hit->getCellID0()); + return (*_encoder)[lcio::LCTrackerCellID::subdet()]; + } + int getSideID(TrackerHit* hit) { + _encoder->setValue(hit->getCellID0()); + return (*_encoder)[lcio::LCTrackerCellID::side()]; + }; + int getLayerID(TrackerHit* hit) { + _encoder->setValue(hit->getCellID0()); + return (*_encoder)[lcio::LCTrackerCellID::layer()]; + }; + int getModuleID(TrackerHit* hit) { + _encoder->setValue(hit->getCellID0()); + return (*_encoder)[lcio::LCTrackerCellID::module()]; + }; + int getSensorID(TrackerHit* hit) { + _encoder->setValue(hit->getCellID0()); + return (*_encoder)[lcio::LCTrackerCellID::sensor()]; + }; - - void setupGeom(const dd4hep::Detector& lcdd) ; + void setupGeom(const dd4hep::Detector& lcdd); double _tpc_inner_r; double _tpc_outer_r; double _tpc_pad_height; - int _tpc_nrows; - -// struct VXD_Layer { -// int nLadders; -// double phi0; -// double dphi; -// double senRMin; -// double supRMin; -// double length; -// double width; -// double offset; -// double senThickness; -// double supThickness; -// }; -// std::vector _VXDgeo; - + int _tpc_nrows; + + // struct VXD_Layer { + // int nLadders; + // double phi0; + // double dphi; + // double senRMin; + // double supRMin; + // double length; + // double width; + // double offset; + // double senThickness; + // double supThickness; + // }; + // std::vector _VXDgeo; + unsigned int _nLayersVTX; - -// struct SIT_Layer { -// int nLadders; -// double phi0; -// double dphi; -// double senRMin; -// double supRMin; -// double length; -// double width; -// double offset; -// double senThickness; -// double supThickness; -// }; -// std::vector _SITgeo; - + + // struct SIT_Layer { + // int nLadders; + // double phi0; + // double dphi; + // double senRMin; + // double supRMin; + // double length; + // double width; + // double offset; + // double senThickness; + // double supThickness; + // }; + // std::vector _SITgeo; + unsigned int _nLayersSIT; - + unsigned int _nLayersSET; - -// struct FTD_Disk { -// int nPetals; -// double phi0; -// double dphi; -// -// double alpha; -// double rInner; -// double height; -// double innerBaseLength; -// double outerBaseLength; -// double senThickness; -// double supThickness; -// -// double senZPos_even_petal1; -// double senZPos_even_petal2; -// double senZPos_even_petal3; -// double senZPos_even_petal4; -// -// double supZPos_even_petal1; -// double supZPos_even_petal2; -// double supZPos_even_petal3; -// double supZPos_even_petal4; -// -// double senZPos_odd_petal1; -// double senZPos_odd_petal2; -// double senZPos_odd_petal3; -// double senZPos_odd_petal4; -// -// double supZPos_odd_petal1; -// double supZPos_odd_petal2; -// double supZPos_odd_petal3; -// double supZPos_odd_petal4; -// -// -// -// }; -// -// std::vector _FTDgeo; + // struct FTD_Disk { + // int nPetals; + // double phi0; + // double dphi; + // + // double alpha; + // double rInner; + // double height; + // double innerBaseLength; + // double outerBaseLength; + // double senThickness; + // double supThickness; + // + // double senZPos_even_petal1; + // double senZPos_even_petal2; + // double senZPos_even_petal3; + // double senZPos_even_petal4; + // + // double supZPos_even_petal1; + // double supZPos_even_petal2; + // double supZPos_even_petal3; + // double supZPos_even_petal4; + // + // double senZPos_odd_petal1; + // double senZPos_odd_petal2; + // double senZPos_odd_petal3; + // double senZPos_odd_petal4; + // + // double supZPos_odd_petal1; + // double supZPos_odd_petal2; + // double supZPos_odd_petal3; + // double supZPos_odd_petal4; + // + // + // + // }; + // + // std::vector _FTDgeo; std::vector _zLayerFTD; - + unsigned int _nLayersFTD; - int _nPhiFTD; - bool _petalBasedFTDWithOverlaps; - -} ; + int _nPhiFTD; + bool _petalBasedFTDWithOverlaps; +}; #endif - - - diff --git a/source/Refitting/include/LinkDef.h b/source/Refitting/include/LinkDef.h index 20dbd73..e013f85 100644 --- a/source/Refitting/include/LinkDef.h +++ b/source/Refitting/include/LinkDef.h @@ -5,12 +5,12 @@ #pragma link off all functions; #pragma link C++ nestedclasses; -#pragma link C++ class std::vector< std::vector >+; -#pragma link C++ class std::vector< double >+; +#pragma link C++ class std::vector < std::vector < double>> + ; +#pragma link C++ class std::vector < double> + ; -//#pragma link C++ class std::vector< std::vector >+; -//#pragma link C++ class std::vector< std::map< const std::string, int > >+; -//#pragma link C++ class std::vector< std::map< const std::string, unsigned > >+; -//#pragma link C++ class std::vector< std::map< const std::string, float > >+; +// #pragma link C++ class std::vector< std::vector >+; +// #pragma link C++ class std::vector< std::map< const std::string, int > >+; +// #pragma link C++ class std::vector< std::map< const std::string, unsigned > >+; +// #pragma link C++ class std::vector< std::map< const std::string, float > >+; #endif diff --git a/source/Refitting/include/MCPMap.h b/source/Refitting/include/MCPMap.h index 778c7fd..1af6ce8 100644 --- a/source/Refitting/include/MCPMap.h +++ b/source/Refitting/include/MCPMap.h @@ -2,102 +2,96 @@ #define __MCPMAP__h 1 #include "lcio.h" -#include -#include -#include #include +#include +#include +#include - typedef std::vector SimTrackerHitVec; - typedef std::multimap< MCParticle* , SimTrackerHit* > SegmentMap; - typedef SegmentMap::iterator segIter; - typedef std::map< MCParticle* , SimTrackerHitVec > MCPMap; - typedef std::pair< MCParticle* , SimTrackerHitVec > MCPMapPair; +typedef std::vector SimTrackerHitVec; +typedef std::multimap SegmentMap; +typedef SegmentMap::iterator segIter; +typedef std::map MCPMap; +typedef std::pair MCPMapPair; +// 以下のクラスはメソッドしかない。namespaceをクラス内で定義しちゃいけないらしく仕方なくこうした。 +// 主な使用用途は、MCParticleとSimTrackerHitのLCRelationを作りたい場合などに有効である。 +// +class moriUTIL { +public: + moriUTIL() { ; } + // もしこのクラスの外で以下のtypedefしてないならコメント外す - //以下のクラスはメソッドしかない。namespaceをクラス内で定義しちゃいけないらしく仕方なくこうした。 - //主な使用用途は、MCParticleとSimTrackerHitのLCRelationを作りたい場合などに有効である。 - // - class moriUTIL{ - public : - moriUTIL(){;} - //もしこのクラスの外で以下のtypedefしてないならコメント外す + /***以下は内部処理用の関数。ユーザーはMakeSegmentMap(Mが大文字なのに注意)を使えばそれで済む。*****/ + /***MakeSegmentMapの定義は一番下にある。**********************************************************/ + // 内部処理用 + SegmentMap makeSegmentMap(SimTrackerHitVec simthits) { + int nsth = simthits.size(); + SegmentMap map; + for (int i = 0; i < nsth; i++) { + SimTrackerHit* sth = simthits[i]; + map.insert(std::make_pair(sth->getMCParticle(), sth)); + } + return map; + } - /***以下は内部処理用の関数。ユーザーはMakeSegmentMap(Mが大文字なのに注意)を使えばそれで済む。*****/ - /***MakeSegmentMapの定義は一番下にある。**********************************************************/ - //内部処理用 - SegmentMap makeSegmentMap(SimTrackerHitVec simthits){ - int nsth = simthits.size(); - SegmentMap map; - for(int i = 0 ; i < nsth ; i++){ - SimTrackerHit* sth = simthits[i]; - map.insert( std::make_pair( sth->getMCParticle() , sth ) ); - } - return map; + // for inner process + MCParticleVec getMCParticlesFromSegmentMap(SegmentMap map) { + segIter it = map.begin(); + MCParticleVec mcps; + mcps.push_back(it->first); + it++; + while (it != map.end()) { + if (mcps.back() != it->first) { + mcps.push_back(it->first); } + it++; + } + return mcps; + } - //for inner process - MCParticleVec getMCParticlesFromSegmentMap(SegmentMap map){ - segIter it = map.begin(); - MCParticleVec mcps; - mcps.push_back(it->first); - it++; - while(it != map.end()){ - if(mcps.back() != it->first){ - mcps.push_back(it->first); - } - it++; - } - return mcps; - } + // for inner process + SimTrackerHitVec getSimTrackerHitVecFromSegmentMap(MCParticle* mcp, SegmentMap map) { + SimTrackerHitVec simthits; + simthits.reserve(10); // だいたい1MCPにつき10個以内のヒットがあると予想。 + // push_backによるcapacityの自動調整を少なくする目的でつけた。 + typedef std::pair EqualRange; + EqualRange ret = map.equal_range(mcp); + for (segIter it = ret.first; it != ret.second; it++) { + simthits.push_back(it->second); + } + return simthits; + } - //for inner process - SimTrackerHitVec getSimTrackerHitVecFromSegmentMap(MCParticle* mcp, SegmentMap map ){ - SimTrackerHitVec simthits; - simthits.reserve(10);//だいたい1MCPにつき10個以内のヒットがあると予想。 - //push_backによるcapacityの自動調整を少なくする目的でつけた。 - typedef std::pair EqualRange; - EqualRange ret = map.equal_range( mcp ); - for(segIter it = ret.first; it != ret.second; it++){ - simthits.push_back(it->second); - } - return simthits; - } + // for inner process + MCPMap makeMCPMap(SegmentMap map) { + MCParticleVec mcps = getMCParticlesFromSegmentMap(map); + int size = mcps.size(); + MCPMap mcpmap; + for (int i = 0; i < size; i++) { + SimTrackerHitVec simthits = getSimTrackerHitVecFromSegmentMap(mcps[i], map); + mcpmap.insert(std::make_pair(mcps[i], simthits)); + } + return mcpmap; + } - //for inner process - MCPMap makeMCPMap(SegmentMap map){ - MCParticleVec mcps = getMCParticlesFromSegmentMap(map); - int size = mcps.size(); - MCPMap mcpmap; - for(int i = 0; i < size; i++){ - SimTrackerHitVec simthits = getSimTrackerHitVecFromSegmentMap(mcps[i], map ); - mcpmap.insert( std::make_pair( mcps[i], simthits ) ); - } - return mcpmap; - } - - ////////////////////////////////////// - //This is the tool for users. - ////////////////////////////////////// - MCPMap MakeMCPMap(SimTrackerHitVec simthits){ - if(simthits.size() == 0){ - std::cout << "Fatal Error!! (MakeMCPMap cannot do with SimTrackerHitVec with size = 0 )" << std::endl; - MCPMap empty; - empty.clear(); - return empty; - } - SegmentMap segmap = makeSegmentMap(simthits); - MCPMap mcpmap = makeMCPMap(segmap); - return mcpmap; - } - //例えば、SimTrackerHit Collectionにある全ヒットをここにぶち込めばMCPMapができあがる。 - //あるいは、Trackにアサインされたヒットのsimtrackerhitだけをぶち込めばtrackのヒットpurityや - //picking efficiencyなんかも計算できるようになる。 - //あとは、LCRelationを作るのもいいし、ROOT解析のために使っても良い。 - };//moriUtil ends - - + ////////////////////////////////////// + // This is the tool for users. + ////////////////////////////////////// + MCPMap MakeMCPMap(SimTrackerHitVec simthits) { + if (simthits.size() == 0) { + std::cout << "Fatal Error!! (MakeMCPMap cannot do with SimTrackerHitVec with size = 0 )" << std::endl; + MCPMap empty; + empty.clear(); + return empty; + } + SegmentMap segmap = makeSegmentMap(simthits); + MCPMap mcpmap = makeMCPMap(segmap); + return mcpmap; + } + // 例えば、SimTrackerHit Collectionにある全ヒットをここにぶち込めばMCPMapができあがる。 + // あるいは、Trackにアサインされたヒットのsimtrackerhitだけをぶち込めばtrackのヒットpurityや + // picking efficiencyなんかも計算できるようになる。 + // あとは、LCRelationを作るのもいいし、ROOT解析のために使っても良い。 +}; // moriUtil ends #endif - - - diff --git a/source/Refitting/include/MyBranch_TestTriplet.h b/source/Refitting/include/MyBranch_TestTriplet.h index 86c7f07..b1b57b1 100644 --- a/source/Refitting/include/MyBranch_TestTriplet.h +++ b/source/Refitting/include/MyBranch_TestTriplet.h @@ -1,103 +1,102 @@ #ifndef MyBranch_TestTriplet_H #define MyBranch_TestTriplet_H 1 +#include +#include +#include -#include -#include -#include - -class MCPStatus{ - public: - //////BasicInitializeで初期化されるもの////// - int pdg; - double energy; - double mass; - float charge; - float time; - double vx; - double vy; - double vz; - double px; - double py; - double pz; - double Pt; - double Pabs; - int isCreatedInSimulation; - int isBackscatter; - int vertexIsNotEndpointOfParent; - int isDecayedInTracker; - int isDecayedInCalorimeter; - int hasLeftDetector; - int isStopped; - ///////BasicInitializeで初期化されないもの///////////////// - float d0; - float phi0; - float omega; - float z0; - float tanL; - int nhits; - int nvxdhits; - int nsithits; - int nftdhits; - int ntpchits; - int nsethits; - MCPStatus(){ - d0=0; phi0=0; omega=0; z0=0; tanL=0; - nhits=0; nvxdhits=0; nsithits=0; nftdhits=0; ntpchits=0; nsethits=0; - } - void BasicInitialize(MCParticle* mcp); +class MCPStatus { +public: + //////BasicInitializeで初期化されるもの////// + int pdg; + double energy; + double mass; + float charge; + float time; + double vx; + double vy; + double vz; + double px; + double py; + double pz; + double Pt; + double Pabs; + int isCreatedInSimulation; + int isBackscatter; + int vertexIsNotEndpointOfParent; + int isDecayedInTracker; + int isDecayedInCalorimeter; + int hasLeftDetector; + int isStopped; + ///////BasicInitializeで初期化されないもの///////////////// + float d0; + float phi0; + float omega; + float z0; + float tanL; + int nhits; + int nvxdhits; + int nsithits; + int nftdhits; + int ntpchits; + int nsethits; + MCPStatus() { + d0 = 0; + phi0 = 0; + omega = 0; + z0 = 0; + tanL = 0; + nhits = 0; + nvxdhits = 0; + nsithits = 0; + nftdhits = 0; + ntpchits = 0; + nsethits = 0; + } + void BasicInitialize(MCParticle* mcp); }; -void MCPStatus::BasicInitialize(MCParticle* mcp){ - pdg = mcp->getPDG(); - energy = mcp->getEnergy(); - charge = mcp->getCharge(); - mass = mcp->getMass(); - time = mcp->getTime(); - px = mcp->getMomentum()[0]; - py = mcp->getMomentum()[1]; - pz = mcp->getMomentum()[2]; - Pt = sqrt(pow(px,2) + pow(py,2) ); - Pabs = sqrt(pow(px,2) + pow(py,2) + pow(pz,2)); - vx = mcp->getVertex()[0]; - vy = mcp->getVertex()[1]; - vz = mcp->getVertex()[2]; - isCreatedInSimulation = mcp->isCreatedInSimulation(); - isBackscatter = mcp->isBackscatter(); - vertexIsNotEndpointOfParent = mcp->vertexIsNotEndpointOfParent(); - isDecayedInTracker = mcp->isDecayedInTracker(); - isDecayedInCalorimeter = mcp->isDecayedInCalorimeter(); - hasLeftDetector = mcp->hasLeftDetector(); - isStopped = mcp->isStopped(); +void MCPStatus::BasicInitialize(MCParticle* mcp) { + pdg = mcp->getPDG(); + energy = mcp->getEnergy(); + charge = mcp->getCharge(); + mass = mcp->getMass(); + time = mcp->getTime(); + px = mcp->getMomentum()[0]; + py = mcp->getMomentum()[1]; + pz = mcp->getMomentum()[2]; + Pt = sqrt(pow(px, 2) + pow(py, 2)); + Pabs = sqrt(pow(px, 2) + pow(py, 2) + pow(pz, 2)); + vx = mcp->getVertex()[0]; + vy = mcp->getVertex()[1]; + vz = mcp->getVertex()[2]; + isCreatedInSimulation = mcp->isCreatedInSimulation(); + isBackscatter = mcp->isBackscatter(); + vertexIsNotEndpointOfParent = mcp->vertexIsNotEndpointOfParent(); + isDecayedInTracker = mcp->isDecayedInTracker(); + isDecayedInCalorimeter = mcp->isDecayedInCalorimeter(); + hasLeftDetector = mcp->hasLeftDetector(); + isStopped = mcp->isStopped(); } - -class MyBranch_TestTriplet{ - public: - int id; - int quality_code; - int detID[3]; - int layer[3]; - int Comb; - float chi2; - int ndf; - float prob; - float purity; - float d0; - float z0; - float phi0; - float omega; - float tanL; - float cov[15];//lcioと同じ詰め方 - MCPStatus mcp; +class MyBranch_TestTriplet { +public: + int id; + int quality_code; + int detID[3]; + int layer[3]; + int Comb; + float chi2; + int ndf; + float prob; + float purity; + float d0; + float z0; + float phi0; + float omega; + float tanL; + float cov[15]; // lcioと同じ詰め方 + MCPStatus mcp; }; - - - - - - - - -#endif +#endif diff --git a/source/Refitting/include/RefitFinal.h b/source/Refitting/include/RefitFinal.h index c51453d..17fb07b 100644 --- a/source/Refitting/include/RefitFinal.h +++ b/source/Refitting/include/RefitFinal.h @@ -12,16 +12,16 @@ namespace MarlinTrk { class IMarlinTrkSystem; class IMarlinTrack; -} +} // namespace MarlinTrk class RefitFinal : public marlin::Processor { public: - virtual marlin::Processor *newProcessor() { return new RefitFinal; } + virtual marlin::Processor* newProcessor() { return new RefitFinal; } RefitFinal(); - RefitFinal(const RefitFinal &) = delete; - RefitFinal &operator=(const RefitFinal &) = delete; + RefitFinal(const RefitFinal&) = delete; + RefitFinal& operator=(const RefitFinal&) = delete; /** Called at the begin of the job before anything is read. * Use to initialize the processor, e.g. book histograms. @@ -30,23 +30,23 @@ class RefitFinal : public marlin::Processor { /** Called for every run. */ - virtual void processRunHeader(lcio::LCRunHeader *run); + virtual void processRunHeader(lcio::LCRunHeader* run); /** Called for every event - the working horse. */ - virtual void processEvent(lcio::LCEvent *evt); + virtual void processEvent(lcio::LCEvent* evt); - virtual void check(lcio::LCEvent *evt); + virtual void check(lcio::LCEvent* evt); /** Called after data processing for clean up. */ virtual void end(); protected: - int FitInit2(Track *track, MarlinTrk::IMarlinTrack *_marlinTrk); + int FitInit2(Track* track, MarlinTrk::IMarlinTrack* _marlinTrk); /* helper function to get collection using try catch block */ - lcio::LCCollection *GetCollection(lcio::LCEvent *evt, std::string colName); + lcio::LCCollection* GetCollection(lcio::LCEvent* evt, std::string colName); /** Input track collection name for refitting. */ @@ -66,7 +66,7 @@ class RefitFinal : public marlin::Processor { /** pointer to the IMarlinTrkSystem instance */ - MarlinTrk::IMarlinTrkSystem *_trksystem = nullptr; + MarlinTrk::IMarlinTrkSystem* _trksystem = nullptr; int _n_run = -1; int _n_evt = -1; diff --git a/source/Refitting/include/RefitProcessor.h b/source/Refitting/include/RefitProcessor.h index 4be228e..db7e55a 100644 --- a/source/Refitting/include/RefitProcessor.h +++ b/source/Refitting/include/RefitProcessor.h @@ -1,8 +1,8 @@ #ifndef RefitProcessor_h #define RefitProcessor_h 1 -#include "marlin/Processor.h" #include "lcio.h" +#include "marlin/Processor.h" #include #include @@ -11,123 +11,110 @@ #include -namespace MarlinTrk{ - class IMarlinTrkSystem ; +namespace MarlinTrk { +class IMarlinTrkSystem; } - /** Track Refitter processor for marlin. Refits an input track collection, producing a new collection of tracks - * - + * + *

Input - Prerequisites

- * Needs a collection of LCIO Tracks. + * Needs a collection of LCIO Tracks. * - *

Output

+ *

Output

* Refitted LCIO Track Collection - * + * * @param InputTrackCollectionName Name of the Track collection to be refitted * @param OutputTrackCollectionName Name of the refitted Track collection to be refitted * @param TrackSystemName name of the track fitting system to be used (KalTest, DDKalTest, aidaTT, ... ) - * + * * @author S. J. Aplin, DESY - * @history + * @history * Nov 2014 F.Gaede CERN/DESY added processor parameter to instantiate other implementations of IMarlinTrk */ class RefitProcessor : public marlin::Processor { - + public: - - virtual marlin::Processor* newProcessor() { return new RefitProcessor ; } - - RefitProcessor() ; - + virtual marlin::Processor* newProcessor() { return new RefitProcessor; } + + RefitProcessor(); + /** Called at the begin of the job before anything is read. * Use to initialize the processor, e.g. book histograms. */ - virtual void init() ; - + virtual void init(); + /** Called for every run. */ - virtual void processRunHeader( lcio::LCRunHeader* run ) ; - + virtual void processRunHeader(lcio::LCRunHeader* run); + /** Called for every event - the working horse. */ - virtual void processEvent( lcio::LCEvent * evt ) ; - - - virtual void check( lcio::LCEvent * evt ) ; - - + virtual void processEvent(lcio::LCEvent* evt); + + virtual void check(lcio::LCEvent* evt); + /** Called after data processing for clean up. */ - virtual void end() ; - - - + virtual void end(); + struct compare_r { - bool operator()( EVENT::TrackerHit* a, EVENT::TrackerHit* b) const { - double r_a_sqd = a->getPosition()[0] * a->getPosition()[0] + a->getPosition()[1] * a->getPosition()[1] ; - double r_b_sqd = b->getPosition()[0] * b->getPosition()[0] + b->getPosition()[1] * b->getPosition()[1] ; - return ( r_a_sqd < r_b_sqd ) ; + bool operator()(EVENT::TrackerHit* a, EVENT::TrackerHit* b) const { + double r_a_sqd = a->getPosition()[0] * a->getPosition()[0] + a->getPosition()[1] * a->getPosition()[1]; + double r_b_sqd = b->getPosition()[0] * b->getPosition()[0] + b->getPosition()[1] * b->getPosition()[1]; + return (r_a_sqd < r_b_sqd); } - } ; - - - + }; + protected: - /* helper function to get collection using try catch block */ - lcio::LCCollection* GetCollection( lcio::LCEvent * evt, std::string colName ) ; - + lcio::LCCollection* GetCollection(lcio::LCEvent* evt, std::string colName); + /* helper function to get relations using try catch block */ - std::unique_ptr GetRelations(lcio::LCEvent * evt, std::string RelName ) ; - + std::unique_ptr GetRelations(lcio::LCEvent* evt, std::string RelName); + /** Input track collection name for refitting. */ - std::string _input_track_col_name ; - + std::string _input_track_col_name; + /** Input track relations name for refitting. */ - std::string _input_track_rel_name ; - + std::string _input_track_rel_name; + /** refitted track collection name. */ - std::string _output_track_col_name ; - + std::string _output_track_col_name; + /** Output track relations name for refitting. */ - std::string _output_track_rel_name ; - - /** pointer to the IMarlinTrkSystem instance + std::string _output_track_rel_name; + + /** pointer to the IMarlinTrkSystem instance */ - MarlinTrk::IMarlinTrkSystem* _trksystem ; - - bool _MSOn ; - bool _ElossOn ; - bool _SmoothOn ; - + MarlinTrk::IMarlinTrkSystem* _trksystem; + + bool _MSOn; + bool _ElossOn; + bool _SmoothOn; + float _initialTrackError_d0; float _initialTrackError_phi0; float _initialTrackError_omega; float _initialTrackError_z0; float _initialTrackError_tanL; float _maxChi2PerHit; - double _mass ; + double _mass; - int _n_run ; - int _n_evt ; + int _n_run; + int _n_evt; int _initialTrackState; - int _fitDirection ; + int _fitDirection; + + std::string _trkSystemName; - std::string _trkSystemName ; - float _bField; - -} ; +}; #endif - - - diff --git a/source/Refitting/include/SiliconTracking_MarlinTrk.h b/source/Refitting/include/SiliconTracking_MarlinTrk.h index dae284c..3c96d50 100644 --- a/source/Refitting/include/SiliconTracking_MarlinTrk.h +++ b/source/Refitting/include/SiliconTracking_MarlinTrk.h @@ -1,97 +1,95 @@ #ifndef SILICONTRACKING_MarlinTrk_H #define SILICONTRACKING_MarlinTrk_H 1 +#include "ClusterExtended.h" +#include "HelixClass.h" +#include "TrackExtended.h" +#include "TrackerHitExtended.h" +#include "lcio.h" #include "marlin/Processor.h" +#include +#include #include -#include "lcio.h" #include #include -#include -#include -#include "ClusterExtended.h" -#include "TrackExtended.h" -#include "TrackerHitExtended.h" -#include "HelixClass.h" #include "MarlinTrk/IMarlinTrack.h" -#include #include "UTIL/LCTrackerConf.h" +#include namespace DiagnosticsHistograms { - class Histograms ; +class Histograms; } namespace DiagnosticsHistograms2D { - class Histograms ; +class Histograms; } -using namespace lcio ; -using namespace marlin ; - +using namespace lcio; +using namespace marlin; namespace MarlinTrk { - class HelixFit; - class IMarlinTrkSystem ; -} +class HelixFit; +class IMarlinTrkSystem; +} // namespace MarlinTrk -namespace dd4hep{ - class Detector ; +namespace dd4hep { +class Detector; } -namespace UTIL{ - class LCRelationNavigator ; +namespace UTIL { +class LCRelationNavigator; } - /** === Silicon Tracking Processor ===
* Processor performing stand-alone pattern recognition * in the vertex detector (VTX), forward tracking disks and SIT.
- * The procedure consists of three steps :
+ * The procedure consists of three steps :
* 1) Tracking in VTX and SIT ;
* 2) Tracking in FTD ;
* 3) Merging compatible track segments reconstructed in VTX and FTD
* STEP 1 : TRACKING IN VTX and SIT
- * Algorithm starts with finding of hit triplets satisfying helix hypothesis
+ * Algorithm starts with finding of hit triplets satisfying helix hypothesis
* in three different layers. Two layers of SIT are effectively considered as outermost
* layers of the vertex detector. To accelerate procedure, the 4-pi solid angle - * is divided in NDivisionsInTheta and NDivisionsInPhi sectors in cosQ and Phi, - * respectively. Triplets are looked for in 2x2 window of adjacent sectors. - * Once triplet is found, attempt is made to associate additional hits to - * track. Combinatin of hits is accepted for further analysis if the Chi2 - * of the fit is less than certain predefined threshold. All accepted - * combinations are sorted in ascending order of their Chi2. First track candidate - * in the sorted array is automatically accepted. The hits belonging to this track are + * is divided in NDivisionsInTheta and NDivisionsInPhi sectors in cosQ and Phi, + * respectively. Triplets are looked for in 2x2 window of adjacent sectors. + * Once triplet is found, attempt is made to associate additional hits to + * track. Combinatin of hits is accepted for further analysis if the Chi2 + * of the fit is less than certain predefined threshold. All accepted + * combinations are sorted in ascending order of their Chi2. First track candidate + * in the sorted array is automatically accepted. The hits belonging to this track are * marked as used, and track candidates sharing these hits are discarded. - * The procedure proceeds with increasing index of track candidate in the sorted + * The procedure proceeds with increasing index of track candidate in the sorted * array until all track candidate have been output or discarded.
* STEP 2 : TRACKING IN FTD
- * In the next step tracking in FTD is performed. The strategy of tracking in the FTD + * In the next step tracking in FTD is performed. The strategy of tracking in the FTD * is the same as used for tracking in the VTX+SIT.
* STEP 3 : MERGING TRACK SEGMENTS FOUND IN FTD AND VTX+SIT
* In the last step, track segments reconstructed in the FTD and VTX+SIT, belonging to the - * same track are identified and merged into one track. All possible + * same track are identified and merged into one track. All possible * pairings are tested for their compatibility. - * The number of pairings considered is Ntrk_VTX_SIT*Ntrk_FTD, where Ntrk_VTX_SIT is the number of + * The number of pairings considered is Ntrk_VTX_SIT*Ntrk_FTD, where Ntrk_VTX_SIT is the number of * track segments reconstructed in the first step in VTX+SIT (segments containing solely VTX and SIT hits) and - * Ntrk_FTD is the number of track segments reconstructed in the second step + * Ntrk_FTD is the number of track segments reconstructed in the second step * (segments containing solely FTD hits). - * Pair of segments is accepted for further examination if the angle between track segments and + * Pair of segments is accepted for further examination if the angle between track segments and * than certain specified threshold. - * Pairing satisfying this condition is subjected for - * addtitional test. The fit is performed on unified array of hits belonging to both segments. - * If the chi2 of the fit does not exceed predefined cut value two segments are unified into - * one track. - *

Input collections and prerequisites

+ * Pairing satisfying this condition is subjected for + * addtitional test. The fit is performed on unified array of hits belonging to both segments. + * If the chi2 of the fit does not exceed predefined cut value two segments are unified into + * one track. + *

Input collections and prerequisites

* Processor requires collection of digitized vertex, sit and ftd tracker hits.
- * If such a collections with the user specified names do not exist + * If such a collections with the user specified names do not exist * processor takes no action.
*

Output

- * Processor produces an LCIO collection of the Tracks. Each track is characterised by + * Processor produces an LCIO collection of the Tracks. Each track is characterised by * five parameters : Omega (signed curvuture), Tan(lambda) where * lambda is the dip angle, Phi (azimuthal angle @ point of closest approach), D0 (signed impact parameter), - * Z0 (displacement along z axis at the point of closest approach to IP). Covariance matrix for these parameters is also provided. - * Only lower left corner of the covariance matrix is stored. The sequence of the covariance matrix elements + * Z0 (displacement along z axis at the point of closest approach to IP). Covariance matrix for these parameters is also + * provided. Only lower left corner of the covariance matrix is stored. The sequence of the covariance matrix elements * assigned to track is the following:
* (Omega,Omega)
* (Omega,TanLambda), (TanLambda,TanLambda)
@@ -101,11 +99,11 @@ namespace UTIL{ * The number of hits in the different subdetectors associated * with each track can be accessed via method Track::getSubdetectorHitNumbers(). * This method returns vector of integers :
- * number of VTX hits in track is the first element in this vector + * number of VTX hits in track is the first element in this vector * (Track::getSubdetectorHitNumbers()[0])
- * number of FTD hits in track is the second element in this vector + * number of FTD hits in track is the second element in this vector * (Track::getSubdetectorHitNumbers()[1])
- * number of SIT hits in track is the third element in this vector + * number of SIT hits in track is the third element in this vector * (Track::getSubdetectorHitNumbers()[2])
* Output track collection has a name "SiTracks".
* @param VTXHitCollectionName name of input VTX TrackerHit collection
@@ -117,16 +115,16 @@ namespace UTIL{ * @param SiTrackCollectionName name of the output Silicon track collection
* (default parameter value : "SiTracks")
* @param LayerCombinations combinations of layers used to search for hit triplets in VTX+SIT
- * (default parameters : 6 4 3 6 4 2 6 3 2 5 4 3 5 4 2 5 3 2 4 3 2 4 3 1 4 2 1 3 2 1)
- * Note that in the VTX+SIT system the first and the second layers of SIT have indicies nLayerVTX and nLayerVTX+1. - * Combination given above means that triplets are looked first in layers 6 4 3, and then + * (default parameters : 6 4 3 6 4 2 6 3 2 5 4 3 5 4 2 5 3 2 4 3 2 4 3 1 4 2 1 3 2 1)
+ * Note that in the VTX+SIT system the first and the second layers of SIT have indicies nLayerVTX and nLayerVTX+1. + * Combination given above means that triplets are looked first in layers 6 4 3, and then * in 6 4 2; 5 4 3; 6 3 2 etc. NOTE THAT LAYER INDEXING STARTS FROM 0. * LAYER 0 is the innermost layer
* @param LayerCombinationsFTD combinations of layers used to search for hit triplets in FTD
- * (default parameters 6 5 4 5 4 3 5 4 2 5 4 1 5 3 2 5 3 1 5 2 1 4 3 2 4 3 1 - * 4 3 0 4 2 1 4 2 0 4 1 0 3 2 1 3 2 0 3 1 0 2 1 0). - * NOTE THAT TRACKS IN FTD ARE SEARCHED ONLY IN ONE HEMISPHERE. TRACK IS NOT - * ALLOWED TO HAVE HITS BOTH IN BACKWARD AND FORWARD PARTS OF FTD SIMULTANEOUSLY. + * (default parameters 6 5 4 5 4 3 5 4 2 5 4 1 5 3 2 5 3 1 5 2 1 4 3 2 4 3 1 + * 4 3 0 4 2 1 4 2 0 4 1 0 3 2 1 3 2 0 3 1 0 2 1 0). + * NOTE THAT TRACKS IN FTD ARE SEARCHED ONLY IN ONE HEMISPHERE. TRACK IS NOT + * ALLOWED TO HAVE HITS BOTH IN BACKWARD AND FORWARD PARTS OF FTD SIMULTANEOUSLY. * @param NDivisionsInPhi Number of divisions in Phi for tracking in VTX+SIT
* (default value is 40)
* @param NDivisionsInTheta Number of divisions in cosQ for tracking in VTX+SIT
@@ -147,21 +145,21 @@ namespace UTIL{ * (default value is 0.5)
* @param Chi2FitCut Cut on chi2/ndf to accept track candidate
* (default value is 100.)
- * @param AngleCutForMerging cut on the angle between two track segments. + * @param AngleCutForMerging cut on the angle between two track segments. * If the angle is greater than this cut, segments are not allowed to be merged.
* (default value is 0.1)
* @param MinDistCutAttach cut on the distance (in mm) from hit to the helix. This parameter is used - * to decide whether hit can be attached to the track. If the distance is less than - * cut value. The track is refitted with a given hit being added to the list of hits already + * to decide whether hit can be attached to the track. If the distance is less than + * cut value. The track is refitted with a given hit being added to the list of hits already * assigned for the track. Additional hit is assigned if chi2 of the new fit has good chi2.
* (default value is 2 )
* @param MinLayerToAttach the minimal layer index to attach VTX hits to the found hit triplets
* (default value is -1)
- * @param CutOnZ0 cut on Z0 parameter of track (in mm). If abs(Z0) is greater than the cut value, track is + * @param CutOnZ0 cut on Z0 parameter of track (in mm). If abs(Z0) is greater than the cut value, track is * discarded (used to suppress fake * track rate in the presence of beam induced background hits)
* (default value is 100)
- * @param CutOnD0 cut on D0 parameter of track (in mm). If abs(D0) is greater than the cut value, track is + * @param CutOnD0 cut on D0 parameter of track (in mm). If abs(D0) is greater than the cut value, track is * discarded (used to suppress fake * track rate in the presence of beam induced background hits)
* (default value is 100)
@@ -173,9 +171,8 @@ namespace UTIL{ * @param NHitsChi2 Maximal number of hits for which a track with n hits is aways better than one with n-1 hits. * For tracks with equal or more than NHitsChi2 the track with the lower \f$\chi^2\f$ is better. * (default value is 5)
- * @param FastAttachment if this flag is set to 1, less accurate but fast procedure to merge additional hits to tracks is used
- * if set to 0, a more accurate, but slower procedure is invoked
- * (default value is 0)
+ * @param FastAttachment if this flag is set to 1, less accurate but fast procedure to merge additional hits to tracks + * is used
if set to 0, a more accurate, but slower procedure is invoked
(default value is 0)
* @param UseSIT When this flag is set to 1, SIT is included in pattern recognition. When this flag is set * to 0, SIT is excluded from the procedure of pattern recognition
* (default value is 1)
@@ -183,55 +180,49 @@ namespace UTIL{ * @author A. Raspereza (MPI Munich)
*/ class SiliconTracking_MarlinTrk : public Processor { - + public: - - virtual Processor* newProcessor() { return new SiliconTracking_MarlinTrk ; } - - - SiliconTracking_MarlinTrk() ; - - /** + virtual Processor* newProcessor() { return new SiliconTracking_MarlinTrk; } + + SiliconTracking_MarlinTrk(); + + /** * Initialization */ - virtual void init() ; - + virtual void init(); + /** Run header processor. */ - virtual void processRunHeader( LCRunHeader* run ) ; - + virtual void processRunHeader(LCRunHeader* run); + /** Event processor. */ - virtual void processEvent( LCEvent * evt ) ; - - - virtual void check( LCEvent * evt ) ; - - + virtual void processEvent(LCEvent* evt); + + virtual void check(LCEvent* evt); + /** Called after data processing for clean up. */ - virtual void end() ; - - + virtual void end(); + protected: - - int _nRun ; - int _nEvt ; + int _nRun; + int _nEvt; EVENT::LCEvent* _current_event; - + int _nDivisionsInPhi; int _nDivisionsInTheta; int _nLayers; - + MarlinTrk::HelixFit* _fastfitter; - - /** pointer to the IMarlinTrkSystem instance + + /** pointer to the IMarlinTrkSystem instance */ - MarlinTrk::IMarlinTrkSystem* _trksystem ; + MarlinTrk::IMarlinTrkSystem* _trksystem; bool _runMarlinTrkDiagnostics; std::string _MarlinTrkDiagnosticsName; - - bool _MSOn, _ElossOn, _SmoothOn ; + + bool _MSOn, _ElossOn, _SmoothOn; /** switches: False for backward compatible (default). True to apply new methods. @@ -244,60 +235,56 @@ class SiliconTracking_MarlinTrk : public Processor { float _initialTrackError_omega; float _initialTrackError_z0; float _initialTrackError_tanL; - - double _maxChi2PerHit; - - bool _UseEventDisplay; + + double _maxChi2PerHit; + + bool _UseEventDisplay; int _detector_model_for_drawing; - std::vector _colours; - float _helix_max_r; - + std::vector _colours; + float _helix_max_r; + void drawEvent(); - - + // histogram member variables - - bool _createDiagnosticsHistograms; + + bool _createDiagnosticsHistograms; DiagnosticsHistograms::Histograms* _histos{nullptr}; - int _ntriplets, _ntriplets_good, _ntriplets_2MCP, _ntriplets_3MCP, _ntriplets_1MCP_Bad, _ntriplets_bad; - - + /** helper function to get collection using try catch block */ - LCCollection* GetCollection( LCEvent * evt, std::string colName ) ; - + LCCollection* GetCollection(LCEvent* evt, std::string colName); + /** helper function to get relations using try catch block */ - LCRelationNavigator* GetRelations( LCEvent * evt, std::string RelName ) ; - + LCRelationNavigator* GetRelations(LCEvent* evt, std::string RelName); + /** input MCParticle collection and threshold used for Drawing */ - std::string _colNameMCParticles; - float _MCpThreshold ; - - + std::string _colNameMCParticles; + float _MCpThreshold; + /// Compare tracks according to their chi2/ndf - struct compare_TrackExtended{ + struct compare_TrackExtended { // n.b.: a and b should be TrackExtended const *, but the getters are not const :-( - bool operator()(TrackExtended *a, TrackExtended *b) const { - if ( a == b ) return false; - return (a->getChi2()/a->getNDF() < b->getChi2()/b->getNDF() ); + bool operator()(TrackExtended* a, TrackExtended* b) const { + if (a == b) + return false; + return (a->getChi2() / a->getNDF() < b->getChi2() / b->getNDF()); } }; - - + std::string _VTXHitCollection; std::string _FTDPixelHitCollection; std::string _FTDSpacePointCollection; std::string _SITHitCollection; std::string _siTrkCollection; - - std::vector< LCCollection* > _colTrackerHits; - std::map< LCCollection*, std::string > _colNamesTrackerHits; - + + std::vector _colTrackerHits; + std::map _colNamesTrackerHits; + std::vector _sectors; std::vector _sectorsFTD; - + /** * A helper class to allow good code readability by accessing tracks with N hits. * As the smalest valid track contains three hits, but the first index in a vector is 0, @@ -308,63 +295,56 @@ class SiliconTracking_MarlinTrk : public Processor { public: /// Empty all the vectors and delete the tracks contained in it. void clear(); - + /// Set the size to allow a maximum of maxHit hits. inline void resize(size_t maxHits) { - _tracksNHits.resize(maxHits-2); - _maxIndex=(maxHits-3); + _tracksNHits.resize(maxHits - 2); + _maxIndex = (maxHits - 3); } - + // Sort all track vectors according to chi2/nDof // void sort(); - - /// Returns the TrackExtendedVec for track with n hits. + + /// Returns the TrackExtendedVec for track with n hits. /// In case n is larger than the maximal number the vector with the largest n ist returned. /// \attention The smallest valid number is three! For /// performance reasons there is no safety check! - inline TrackExtendedVec & getTracksWithNHitsVec( size_t nHits ) { - //return _tracksNHits[ std::min(nHits-3, _maxIndex) ]; - // for debugging: with boundary check - return _tracksNHits.at(std::min(nHits-3, _maxIndex)); + inline TrackExtendedVec& getTracksWithNHitsVec(size_t nHits) { + // return _tracksNHits[ std::min(nHits-3, _maxIndex) ]; + // for debugging: with boundary check + return _tracksNHits.at(std::min(nHits - 3, _maxIndex)); } - + protected: - std::vector< TrackExtendedVec > _tracksNHits; + std::vector _tracksNHits; size_t _maxIndex; /// local cache variable to avoid calculation overhead }; - + TracksWithNHitsContainer _tracksWithNHitsContainer; - - int InitialiseVTX(LCEvent * evt); - int InitialiseFTD(LCEvent * evt); + + int InitialiseVTX(LCEvent* evt); + int InitialiseFTD(LCEvent* evt); void ProcessOneSector(int iSectorPhi, int iSectorTheta); void CleanUp(); - TrackExtended * TestTriplet(TrackerHitExtended * outerHit, - TrackerHitExtended * middleHit, - TrackerHitExtended * innerHit, - HelixClass & helix); - - int BuildTrack(TrackerHitExtended * outerHit, - TrackerHitExtended * middleHit, - TrackerHitExtended * innerHit, - HelixClass & helix, - int innerlayer, - int iPhiLow, int iPhiUp, - int iTheta, int iThetaUp, - TrackExtended * trackAR); - - void Sorting( TrackExtendedVec & trackVec); - void CreateTrack(TrackExtended * trackAR ); + TrackExtended* TestTriplet(TrackerHitExtended* outerHit, TrackerHitExtended* middleHit, TrackerHitExtended* innerHit, + HelixClass& helix); + + int BuildTrack(TrackerHitExtended* outerHit, TrackerHitExtended* middleHit, TrackerHitExtended* innerHit, + HelixClass& helix, int innerlayer, int iPhiLow, int iPhiUp, int iTheta, int iThetaUp, + TrackExtended* trackAR); + + void Sorting(TrackExtendedVec& trackVec); + void CreateTrack(TrackExtended* trackAR); void AttachRemainingVTXHitsSlow(); void AttachRemainingFTDHitsSlow(); void AttachRemainingVTXHitsFast(); void AttachRemainingFTDHitsFast(); void TrackingInFTD(); int BuildTrackFTD(TrackExtended* trackAR, int* nLR, int iS); - int AttachHitToTrack(TrackExtended * trackAR, TrackerHitExtended * hit, int iopt); - + int AttachHitToTrack(TrackExtended* trackAR, TrackerHitExtended* hit, int iopt); + void FinalRefit(LCCollectionVec* trk_col, LCCollectionVec* rel_col); - + float _bField; float _chi2WRPhiTriplet; float _chi2WRPhiQuartet; @@ -374,89 +354,93 @@ class SiliconTracking_MarlinTrk : public Processor { float _chi2WZSeptet; float _minDistCutAttach; int _minimalLayerToAttach; - + // two pi is not a constant in cmath. Calculate it, once! static const double TWOPI; - + double _dPhi; double _dTheta; double _dPhiFTD; - - std::vector _Combinations; std::vector _CombinationsFTD; - + float _resolutionRPhiVTX; float _resolutionZVTX; - + float _resolutionRPhiFTD; float _resolutionZFTD; - + float _resolutionRPhiSIT; float _resolutionZSIT; - + float _phiCutForMerging; float _tanlambdaCutForMerging; float _angleCutForMerging; - + int _print; int _checkForDelta; float _minDistToDelta; - + float _distRPhi; float _distZ; float _chi2FitCut; - - + TrackExtendedVec _trackImplVec; - - + float _cutOnD0, _cutOnZ0, _cutOnOmega, _cutOnPt; - + int _minimalHits; int _nHitsChi2; int _attachFast; - + int _max_hits_per_sector; - - int _nTotalVTXHits,_nTotalFTDHits,_nTotalSITHits; + + int _nTotalVTXHits, _nTotalFTDHits, _nTotalSITHits; int _useSIT; - std::string _trkSystemName ; - + std::string _trkSystemName; + // int _createMap; - + UTIL::BitField64* _encoder; - int getDetectorID(TrackerHit* hit) { _encoder->setValue(hit->getCellID0()); return (*_encoder)[lcio::LCTrackerCellID::subdet()]; } - int getSideID(TrackerHit* hit) { _encoder->setValue(hit->getCellID0()); return (*_encoder)[lcio::LCTrackerCellID::side()]; }; - int getLayerID(TrackerHit* hit) { _encoder->setValue(hit->getCellID0()); return (*_encoder)[lcio::LCTrackerCellID::layer()]; }; - int getModuleID(TrackerHit* hit) { _encoder->setValue(hit->getCellID0()); return (*_encoder)[lcio::LCTrackerCellID::module()]; }; - int getSensorID(TrackerHit* hit) { _encoder->setValue(hit->getCellID0()); return (*_encoder)[lcio::LCTrackerCellID::sensor()]; }; - + int getDetectorID(TrackerHit* hit) { + _encoder->setValue(hit->getCellID0()); + return (*_encoder)[lcio::LCTrackerCellID::subdet()]; + } + int getSideID(TrackerHit* hit) { + _encoder->setValue(hit->getCellID0()); + return (*_encoder)[lcio::LCTrackerCellID::side()]; + }; + int getLayerID(TrackerHit* hit) { + _encoder->setValue(hit->getCellID0()); + return (*_encoder)[lcio::LCTrackerCellID::layer()]; + }; + int getModuleID(TrackerHit* hit) { + _encoder->setValue(hit->getCellID0()); + return (*_encoder)[lcio::LCTrackerCellID::module()]; + }; + int getSensorID(TrackerHit* hit) { + _encoder->setValue(hit->getCellID0()); + return (*_encoder)[lcio::LCTrackerCellID::sensor()]; + }; + void setupGeom(const dd4hep::Detector& theDetector); - - + unsigned int _nLayersVTX; - + unsigned int _nLayersSIT; - - + std::vector _zLayerFTD; - + unsigned int _nlayersFTD; bool _petalBasedFTDWithOverlaps; - int _nPhiFTD; + int _nPhiFTD; int _output_track_col_quality; static const int _output_track_col_quality_GOOD; static const int _output_track_col_quality_FAIR; static const int _output_track_col_quality_POOR; - - -} ; +}; #endif - - - diff --git a/source/Refitting/include/TrackSubsetProcessor.h b/source/Refitting/include/TrackSubsetProcessor.h index d967edf..cffba91 100644 --- a/source/Refitting/include/TrackSubsetProcessor.h +++ b/source/Refitting/include/TrackSubsetProcessor.h @@ -1,184 +1,142 @@ #ifndef TrackSubsetProcessor_h #define TrackSubsetProcessor_h 1 - -#include "marlin/Processor.h" -#include "lcio.h" #include "EVENT/Track.h" #include "MarlinTrk/IMarlinTrkSystem.h" +#include "lcio.h" +#include "marlin/Processor.h" #include "Math/ProbFunc.h" - - - -using namespace lcio ; -using namespace marlin ; - +using namespace lcio; +using namespace marlin; /** Processor that takes tracks from multiple sources and outputs them (or modified versions, or a subset of them) * as one track collection. - * + * *

Input - Prerequisites

* Track collections * - *

Output

+ *

Output

* A single track collection - * + * * @param TrackInputCollections A vector of the input track collections
* (default value ForwardTracks SiTracks ) - * + * * @param TrackOutputCollection Name of the output track collection
* (default value SubsetTracks ) - * + * * @param MultipleScatteringOn Whether to take multiple scattering into account when fitting the tracks
* (default value true ) - * + * * @param EnergyLossOn Whether to take energyloss into account when fitting the tracks
* (default value true ) - * + * * @param SmoothOn Whether to smooth all measurement sites in fit
* (default value false ) - * + * * @param Omega The parameter omega for the HNN. Controls the influence of the quality indicator. Between 0 and 1: - * 1 means high influence of quality indicator, 0 means no influence. - * + * 1 means high influence of quality indicator, 0 means no influence. + * * @author Robin Glattauer, HEPHY - * + * */ +class TrackSubsetProcessor : public Processor { +public: + virtual Processor* newProcessor() { return new TrackSubsetProcessor; } + + TrackSubsetProcessor(); -class TrackSubsetProcessor : public Processor { - - public: - - virtual Processor* newProcessor() { return new TrackSubsetProcessor ; } - - - TrackSubsetProcessor() ; - /** Called at the begin of the job before anything is read. * Use to initialize the processor, e.g. book histograms. */ - virtual void init() ; - + virtual void init(); + /** Called for every run. */ - virtual void processRunHeader( LCRunHeader* run ) ; - + virtual void processRunHeader(LCRunHeader* run); + /** Called for every event - the working horse. */ - virtual void processEvent( LCEvent * evt ) ; - - - virtual void check( LCEvent * evt ) ; - - + virtual void processEvent(LCEvent* evt); + + virtual void check(LCEvent* evt); + /** Called after data processing for clean up. */ - virtual void end() ; - - - protected: + virtual void end(); - /** helper method that removes short tracks from the list that have the same hits as another, longer track in the list +protected: + /** helper method that removes short tracks from the list that have the same hits as another, longer track in the list * by setting the corresponding pointer to NULL. */ - void removeShortTracks( std::vector< EVENT::Track*>& tracks ) ; - - + void removeShortTracks(std::vector& tracks); + /** Input collection names */ - std::vector< std::string > _trackInputColNames; - + std::vector _trackInputColNames; + /** Output collection name */ std::string _trackOutputColName; - + MarlinTrk::IMarlinTrkSystem* _trkSystem; - std::string _trkSystemName ; - - bool _MSOn ; - bool _ElossOn ; - bool _SmoothOn ; - bool _removeShortTracks ; + std::string _trkSystemName; + bool _MSOn; + bool _ElossOn; + bool _SmoothOn; + bool _removeShortTracks; float _initialTrackError_d0; float _initialTrackError_phi0; float _initialTrackError_omega; float _initialTrackError_z0; float _initialTrackError_tanL; - + double _maxChi2PerHit; - + float _bField; - - int _nRun ; - int _nEvt ; - - double _omega; - -} ; + int _nRun; + int _nEvt; + + double _omega; +}; /** A functor to return whether two tracks are compatible: The criterion is if the share a TrackerHit or more */ -class TrackCompatibility{ - - +class TrackCompatibility { + public: - - - inline bool operator()( Track* trackA, Track* trackB ){ - - - std::vector< TrackerHit* > hitsA = trackA->getTrackerHits(); - std::vector< TrackerHit* > hitsB = trackB->getTrackerHits(); - - - for( unsigned i=0; i < hitsA.size(); i++){ - - for( unsigned j=0; j < hitsB.size(); j++){ - - if ( hitsA[i] == hitsB[j] ) return false; // a hit is shared -> incompatible - + inline bool operator()(Track* trackA, Track* trackB) { + + std::vector hitsA = trackA->getTrackerHits(); + std::vector hitsB = trackB->getTrackerHits(); + + for (unsigned i = 0; i < hitsA.size(); i++) { + + for (unsigned j = 0; j < hitsB.size(); j++) { + + if (hitsA[i] == hitsB[j]) + return false; // a hit is shared -> incompatible } - } - - return true; - - + + return true; } - - }; - /** A functor to return the quality of a track, which is currently the chi2 probability. */ -class TrackQI{ - +class TrackQI { + public: - /** @param trkSystem a pointer to an IMarlinTrkSystem, needed for fitting of tracks */ - TrackQI( MarlinTrk::IMarlinTrkSystem* trkSystem ): _trkSystem(trkSystem){} - - inline double operator()( Track* track ){ - - return ROOT::Math::chisquared_cdf_c( track->getChi2() , track->getNdf() ); - - - } - + TrackQI(MarlinTrk::IMarlinTrkSystem* trkSystem) : _trkSystem(trkSystem) {} + + inline double operator()(Track* track) { return ROOT::Math::chisquared_cdf_c(track->getChi2(), track->getNdf()); } + protected: - MarlinTrk::IMarlinTrkSystem* _trkSystem; - }; - - - #endif - - - diff --git a/source/Refitting/include/TruthTrackFinder.h b/source/Refitting/include/TruthTrackFinder.h index 3348018..ffe30e0 100644 --- a/source/Refitting/include/TruthTrackFinder.h +++ b/source/Refitting/include/TruthTrackFinder.h @@ -5,80 +5,81 @@ #include "lcio.h" +#include #include #include -#include -#include #include "DDRec/Surface.h" -#include -#include "MarlinTrk/IMarlinTrkSystem.h" #include "EVENT/TrackerHit.h" -#include +#include "MarlinTrk/IMarlinTrkSystem.h" #include "UTIL/LCTrackerConf.h" #include +#include +#include +#include -using namespace lcio ; -using namespace marlin ; -using namespace AIDA ; +using namespace lcio; +using namespace marlin; +using namespace AIDA; class TruthTrackFinder : public Processor { - - public: - - virtual Processor* newProcessor() { return new TruthTrackFinder ; } - - TruthTrackFinder() ; - + +public: + virtual Processor* newProcessor() { return new TruthTrackFinder; } + + TruthTrackFinder(); + // Initialisation - run at the beginning to start histograms, etc. - virtual void init() ; - + virtual void init(); + // Called at the beginning of every run - virtual void processRunHeader( LCRunHeader* run ) ; - + virtual void processRunHeader(LCRunHeader* run); + // Run over each event - the main algorithm - virtual void processEvent( LCEvent * evt ) ; - + virtual void processEvent(LCEvent* evt); + // Run at the end of each event - virtual void check( LCEvent * evt ) ; - + virtual void check(LCEvent* evt); + // Called at the very end for cleanup, histogram saving, etc. - virtual void end() ; - + virtual void end(); + // Call to get collections void getCollection(LCCollection*&, std::string, LCEvent*); - - - protected: - + +protected: // Encoder UTIL::BitField64* m_encoder; // Get the subdetector ID from a hit - int getSubdetector(const TrackerHit* hit){ m_encoder->setValue(hit->getCellID0()); return (*m_encoder)[lcio::LCTrackerCellID::subdet()]; } + int getSubdetector(const TrackerHit* hit) { + m_encoder->setValue(hit->getCellID0()); + return (*m_encoder)[lcio::LCTrackerCellID::subdet()]; + } // Get the layer ID from a hit - int getLayer(const TrackerHit* hit){ m_encoder->setValue(hit->getCellID0()); return (*m_encoder)[lcio::LCTrackerCellID::layer()]; } + int getLayer(const TrackerHit* hit) { + m_encoder->setValue(hit->getCellID0()); + return (*m_encoder)[lcio::LCTrackerCellID::layer()]; + } // Remove hits in the same layer of the same subdetector - void removeHitsSameLayer(const std::vector &, std::vector &); - - + void removeHitsSameLayer(const std::vector&, std::vector&); // Collection names for (in/out)put - std::vector m_inputTrackerHitCollections ; - std::vector m_inputTrackerHitRelationCollections ; - std::string m_inputParticleCollection ; - std::string m_outputTrackCollection ; + std::vector m_inputTrackerHitCollections; + std::vector m_inputTrackerHitRelationCollections; + std::string m_inputParticleCollection; + std::string m_outputTrackCollection; std::string m_outputTrackRelationCollection; bool m_useTruthInPrefit; bool m_fitForward; - + // Run and event counters - int m_eventNumber ; - int m_runNumber ; - + int m_eventNumber; + int m_runNumber; + // Track fit factory MarlinTrk::IMarlinTrkSystem* trackFactory; @@ -91,11 +92,6 @@ class TruthTrackFinder : public Processor { double m_maxChi2perHit; double m_magneticField; int m_fitFails; - - -} ; +}; #endif - - - diff --git a/source/Refitting/include/TruthTracker.h b/source/Refitting/include/TruthTracker.h index 3a42c78..8931be2 100644 --- a/source/Refitting/include/TruthTracker.h +++ b/source/Refitting/include/TruthTracker.h @@ -1,212 +1,217 @@ #ifndef TruthTracker_h #define TruthTracker_h 1 -#include "marlin/Processor.h" #include "lcio.h" +#include "marlin/Processor.h" #include -#include #include +#include #include -#include #include "UTIL/LCTrackerConf.h" +#include -namespace EVENT{ - class MCParticle ; - class Track ; - class LCEvent; -} +namespace EVENT { +class MCParticle; +class Track; +class LCEvent; +} // namespace EVENT namespace IMPL { - class TrackImpl ; +class TrackImpl; } -namespace UTIL{ - class LCRelationNavigator ; +namespace UTIL { +class LCRelationNavigator; } - -namespace MarlinTrk{ - class IMarlinTrkSystem ; +namespace MarlinTrk { +class IMarlinTrkSystem; } -/** Track creation based on MC truth. - * - +/** Track creation based on MC truth. + * + *

Input - Prerequisites

- * Needs a collections of LCIO TrackerHits. + * Needs a collections of LCIO TrackerHits. * - *

Output

+ *

Output

* LCIO Track Collection - * + * * @param TrackerHitsInputCollections Name of the tracker hit input collections
* (default value: FTDTrackerHits SITTrackerHits TPCTrackerHits VXDTrackerHits ) - * - * @param TrackerHitsRelInputCollections Name of the lcrelation collections, that link the TrackerHits to their SimTrackerHits. + * + * @param TrackerHitsRelInputCollections Name of the lcrelation collections, that link the TrackerHits to their + SimTrackerHits. * Have to be in same order as TrackerHitsInputCollections!!!
* (default value: FTDTrackerHitRelations SITTrackerHitRelations TPCTrackerHitRelations VXDTrackerHitRelations ) - * + * * @param OutputTrackCollectionName Name of the output Track collection
* (default value: TruthTracks ) - * + * * @param OutputTrackRelCollection Name of the MCParticle-Track Relations collection for output tracks
* (default value: TruthTracksMCP ) - * + * * @param MCpThreshold Transverse Momentum Threshold MC particles which will produce tracks GeV
* (default value: 0.1 ) - * + * * @param FitTracksWithMarlinTrk Fit the Tracks with MarlinTrk, otherwise take track parameters from MCParticle
* (default value: true ) - * + * * @param MultipleScatteringOn Use MultipleScattering in Fit
* (default value: true ) - * + * * @param EnergyLossOn Use Energy Loss in Fit
* (default value: true ) - * + * * @param SmoothOn Smooth All Mesurement Sites in Fit
* (default value: false ) - * - * + * + * * @author S. J. Aplin, DESY ; R. Glattauer, HEPHY - * + * */ class TruthTracker : public marlin::Processor { - + public: - - virtual marlin::Processor* newProcessor() { return new TruthTracker ; } - - - TruthTracker() ; - + virtual marlin::Processor* newProcessor() { return new TruthTracker; } + + TruthTracker(); + /** Called at the begin of the job before anything is read. * Use to initialize the processor, e.g. book histograms. */ - virtual void init() ; - + virtual void init(); + /** Called for every run. */ - virtual void processRunHeader( LCRunHeader* run ) ; - + virtual void processRunHeader(LCRunHeader* run); + /** Called for every event - the working horse. */ - virtual void processEvent( LCEvent * evt ) ; - - - virtual void check( LCEvent * evt ) ; - - + virtual void processEvent(LCEvent* evt); + + virtual void check(LCEvent* evt); + /** Called after data processing for clean up. */ - virtual void end() ; - + virtual void end(); + struct SimTrackerHitSortPredicate { - bool operator()(std::pair p1, std::pair p2) { - + bool operator()(std::pair p1, std::pair p2) { + SimTrackerHit* simHit1 = p1.first; SimTrackerHit* simHit2 = p2.first; - - - if( simHit1->getMCParticle() == simHit2->getMCParticle() ) { - return simHit1->getTime() < simHit2->getTime() ; - } - else { - return simHit1->getMCParticle() < simHit2->getMCParticle() ; + + if (simHit1->getMCParticle() == simHit2->getMCParticle()) { + return simHit1->getTime() < simHit2->getTime(); + } else { + return simHit1->getMCParticle() < simHit2->getMCParticle(); } } }; - protected: - - - const LCObjectVec* getSimHits( TrackerHit* trkhit, const FloatVec* weights = NULL); - + const LCObjectVec* getSimHits(TrackerHit* trkhit, const FloatVec* weights = NULL); + UTIL::BitField64* _encoder; - int getDetectorID(TrackerHit* hit) { _encoder->setValue(hit->getCellID0()); return (*_encoder)[lcio::LCTrackerCellID::subdet()]; } - int getSideID(TrackerHit* hit) { _encoder->setValue(hit->getCellID0()); return (*_encoder)[lcio::LCTrackerCellID::side()]; }; - int getLayerID(TrackerHit* hit) { _encoder->setValue(hit->getCellID0()); return (*_encoder)[lcio::LCTrackerCellID::layer()]; }; - int getModuleID(TrackerHit* hit) { _encoder->setValue(hit->getCellID0()); return (*_encoder)[lcio::LCTrackerCellID::module()]; }; - int getSensorID(TrackerHit* hit) { _encoder->setValue(hit->getCellID0()); return (*_encoder)[lcio::LCTrackerCellID::sensor()]; }; + int getDetectorID(TrackerHit* hit) { + _encoder->setValue(hit->getCellID0()); + return (*_encoder)[lcio::LCTrackerCellID::subdet()]; + } + int getSideID(TrackerHit* hit) { + _encoder->setValue(hit->getCellID0()); + return (*_encoder)[lcio::LCTrackerCellID::side()]; + }; + int getLayerID(TrackerHit* hit) { + _encoder->setValue(hit->getCellID0()); + return (*_encoder)[lcio::LCTrackerCellID::layer()]; + }; + int getModuleID(TrackerHit* hit) { + _encoder->setValue(hit->getCellID0()); + return (*_encoder)[lcio::LCTrackerCellID::module()]; + }; + int getSensorID(TrackerHit* hit) { + _encoder->setValue(hit->getCellID0()); + return (*_encoder)[lcio::LCTrackerCellID::sensor()]; + }; - /** helper function to get collection using try catch block */ - LCCollection* GetCollection( LCEvent * evt, std::string colName ) ; - + LCCollection* GetCollection(LCEvent* evt, std::string colName); + /** helper function to get relations using try catch block */ - LCRelationNavigator* GetRelations( LCEvent * evt, std::string RelName ) ; - + LCRelationNavigator* GetRelations(LCEvent* evt, std::string RelName); + /** sets up the different collections */ - void SetupInputCollections( LCEvent * evt ) ; - - void createTrack( MCParticle* mcp, UTIL::BitField64& cellID_encoder, std::vector< std::pair >& hit_list ); - - void createTrack_old( MCParticle* mcp, UTIL::BitField64& cellID_encoder, std::vector& hit_list ); - - void createTrack_iterative( MCParticle* mcp, UTIL::BitField64& cellID_encoder, std::vector< std::pair >& hit_list ); - + void SetupInputCollections(LCEvent* evt); + + void createTrack(MCParticle* mcp, UTIL::BitField64& cellID_encoder, + std::vector>& hit_list); + + void createTrack_old(MCParticle* mcp, UTIL::BitField64& cellID_encoder, std::vector& hit_list); + + void createTrack_iterative(MCParticle* mcp, UTIL::BitField64& cellID_encoder, + std::vector>& hit_list); + void drawEvent(); - - + /** input MCParticle collection */ - std::string _colNameMCParticles; - + std::string _colNameMCParticles; + /** input TrackerHit collections */ - std::vector< std::string > _colNamesTrackerHits; - - /** input relation collections + std::vector _colNamesTrackerHits; + + /** input relation collections */ - std::vector< std::string > _colNamesTrackerHitRelations; + std::vector _colNamesTrackerHitRelations; + + std::vector _colTrackerHits; + std::vector _navTrackerHitRel; - std::vector< LCCollection* > _colTrackerHits; - std::vector< LCRelationNavigator* > _navTrackerHitRel; - - /** output track collection + /** output track collection */ - std::string _output_track_col_name ; + std::string _output_track_col_name; LCCollectionVec* _trackVec; - + /** Output track relations */ - std::string _output_track_rel_name ; + std::string _output_track_rel_name; LCCollectionVec* _trackRelVec; - - /** output track segments collection, used for tracks which cannot be formed from a single fit + /** output track segments collection, used for tracks which cannot be formed from a single fit */ - std::string _output_track_segments_col_name ; + std::string _output_track_segments_col_name; LCCollectionVec* _trackSegmentsVec; - + /** Output track segments relations, used for tracks which cannot be formed from a single fit */ - std::string _output_track_segment_rel_name ; + std::string _output_track_segment_rel_name; LCCollectionVec* _trackSegmentsRelVec; - + int _nMCP; - - int _n_run ; - int _n_evt ; - - float _MCpThreshold ; + + int _n_run; + int _n_evt; + + float _MCpThreshold; bool _useMCParticleParametersFotInitOfFit; - - /** pointer to the IMarlinTrkSystem instance + + /** pointer to the IMarlinTrkSystem instance */ - MarlinTrk::IMarlinTrkSystem* _trksystem ; + MarlinTrk::IMarlinTrkSystem* _trksystem; bool _runMarlinTrkDiagnostics; std::string _MarlinTrkDiagnosticsName; bool _FitTracksWithMarlinTrk; bool _create_prefit_using_MarlinTrk; - - bool _MSOn ; - bool _ElossOn ; - bool _SmoothOn ; + + bool _MSOn; + bool _ElossOn; + bool _SmoothOn; float _initialTrackError_d0; float _initialTrackError_phi0; @@ -214,27 +219,24 @@ class TruthTracker : public marlin::Processor { float _initialTrackError_z0; float _initialTrackError_tanL; - bool _UseIterativeFitting; - bool _UseEventDisplay; - + bool _UseIterativeFitting; + bool _UseEventDisplay; + double _maxChi2PerHit; - + double _Bz; unsigned _nCreatedTracks; - - EVENT::LCEvent* _current_event; - - int _detector_model_for_drawing; - std::vector _colours; - float _helix_max_r; - - std::string _trkSystemName ; - int _fitDirection ; -} ; + EVENT::LCEvent* _current_event; -#endif + int _detector_model_for_drawing; + std::vector _colours; + float _helix_max_r; + std::string _trkSystemName; + int _fitDirection; +}; +#endif diff --git a/source/Refitting/include/fpcompare.h b/source/Refitting/include/fpcompare.h index 66721c2..2c44b02 100644 --- a/source/Refitting/include/fpcompare.h +++ b/source/Refitting/include/fpcompare.h @@ -6,122 +6,87 @@ #ifndef CXXUTILS_FPCOMPARE_H #define CXXUTILS_FPCOMPARE_H - // Decide whether we need to use volatile or not. -#if defined(__FLT_EVAL_METHOD__) && \ - (__FLT_EVAL_METHOD__ == 2 || __FLT_EVAL_METHOD__ < 0) - // __FLT_EVAL_METHOD__ < 0 means unspecified. - // Be pessimistic in that case. -# define CXXUTILS_FPCOMPARE_VOLATILE volatile +#if defined(__FLT_EVAL_METHOD__) && (__FLT_EVAL_METHOD__ == 2 || __FLT_EVAL_METHOD__ < 0) +// __FLT_EVAL_METHOD__ < 0 means unspecified. +// Be pessimistic in that case. +#define CXXUTILS_FPCOMPARE_VOLATILE volatile #elif defined(__i386__) && !defined(__SSE2__) - // On x86, gcc -msse -mfpmath=sse is observed to _not_ generate - // sse fp instructions, but does set __FLT_EVAL_METHOD__ to 0. - // -msse2 -mfpmath=sse does seem to work as expected. - // Special-case this for now; should follow up with a gcc bug report - // if this still happens in current releases. -# define CXXUTILS_FPCOMPARE_VOLATILE volatile +// On x86, gcc -msse -mfpmath=sse is observed to _not_ generate +// sse fp instructions, but does set __FLT_EVAL_METHOD__ to 0. +// -msse2 -mfpmath=sse does seem to work as expected. +// Special-case this for now; should follow up with a gcc bug report +// if this still happens in current releases. +#define CXXUTILS_FPCOMPARE_VOLATILE volatile #else -# define CXXUTILS_FPCOMPARE_VOLATILE +#define CXXUTILS_FPCOMPARE_VOLATILE #endif - namespace CxxUtils { namespace fpcompare { - -inline -bool equal (double a, double b) -{ - CXXUTILS_FPCOMPARE_VOLATILE double va = a; - CXXUTILS_FPCOMPARE_VOLATILE double vb = b; - return va == vb; -} - - -inline -bool equal (float a, float b) -{ - CXXUTILS_FPCOMPARE_VOLATILE float va = a; - CXXUTILS_FPCOMPARE_VOLATILE float vb = b; - return va == vb; -} - - -inline -bool greater (double a, double b) -{ - CXXUTILS_FPCOMPARE_VOLATILE double va = a; - CXXUTILS_FPCOMPARE_VOLATILE double vb = b; - return va > vb; -} - - -inline -bool greater (float a, float b) -{ - CXXUTILS_FPCOMPARE_VOLATILE float va = a; - CXXUTILS_FPCOMPARE_VOLATILE float vb = b; - return va > vb; -} - - -inline -bool less (double a, double b) -{ - CXXUTILS_FPCOMPARE_VOLATILE double va = a; - CXXUTILS_FPCOMPARE_VOLATILE double vb = b; - return va < vb; -} - - -inline -bool less (float a, float b) -{ - CXXUTILS_FPCOMPARE_VOLATILE float va = a; - CXXUTILS_FPCOMPARE_VOLATILE float vb = b; - return va < vb; -} - - -inline -bool greater_equal (double a, double b) -{ - CXXUTILS_FPCOMPARE_VOLATILE double va = a; - CXXUTILS_FPCOMPARE_VOLATILE double vb = b; - return va >= vb; -} - - -inline -bool greater_equal (float a, float b) -{ - CXXUTILS_FPCOMPARE_VOLATILE float va = a; - CXXUTILS_FPCOMPARE_VOLATILE float vb = b; - return va >= vb; -} - - -inline -bool less_equal (double a, double b) -{ - CXXUTILS_FPCOMPARE_VOLATILE double va = a; - CXXUTILS_FPCOMPARE_VOLATILE double vb = b; - return va <= vb; -} - - -inline -bool less_equal (float a, float b) -{ - CXXUTILS_FPCOMPARE_VOLATILE float va = a; - CXXUTILS_FPCOMPARE_VOLATILE float vb = b; - return va <= vb; -} - + inline bool equal(double a, double b) { + CXXUTILS_FPCOMPARE_VOLATILE double va = a; + CXXUTILS_FPCOMPARE_VOLATILE double vb = b; + return va == vb; + } + + inline bool equal(float a, float b) { + CXXUTILS_FPCOMPARE_VOLATILE float va = a; + CXXUTILS_FPCOMPARE_VOLATILE float vb = b; + return va == vb; + } + + inline bool greater(double a, double b) { + CXXUTILS_FPCOMPARE_VOLATILE double va = a; + CXXUTILS_FPCOMPARE_VOLATILE double vb = b; + return va > vb; + } + + inline bool greater(float a, float b) { + CXXUTILS_FPCOMPARE_VOLATILE float va = a; + CXXUTILS_FPCOMPARE_VOLATILE float vb = b; + return va > vb; + } + + inline bool less(double a, double b) { + CXXUTILS_FPCOMPARE_VOLATILE double va = a; + CXXUTILS_FPCOMPARE_VOLATILE double vb = b; + return va < vb; + } + + inline bool less(float a, float b) { + CXXUTILS_FPCOMPARE_VOLATILE float va = a; + CXXUTILS_FPCOMPARE_VOLATILE float vb = b; + return va < vb; + } + + inline bool greater_equal(double a, double b) { + CXXUTILS_FPCOMPARE_VOLATILE double va = a; + CXXUTILS_FPCOMPARE_VOLATILE double vb = b; + return va >= vb; + } + + inline bool greater_equal(float a, float b) { + CXXUTILS_FPCOMPARE_VOLATILE float va = a; + CXXUTILS_FPCOMPARE_VOLATILE float vb = b; + return va >= vb; + } + + inline bool less_equal(double a, double b) { + CXXUTILS_FPCOMPARE_VOLATILE double va = a; + CXXUTILS_FPCOMPARE_VOLATILE double vb = b; + return va <= vb; + } + + inline bool less_equal(float a, float b) { + CXXUTILS_FPCOMPARE_VOLATILE float va = a; + CXXUTILS_FPCOMPARE_VOLATILE float vb = b; + return va <= vb; + } } // namespace fpcompare } // namespace CxxUtils - #endif // not CXXUTILS_FPCOMPARE_H diff --git a/source/Refitting/src/ClonesAndSplitTracksFinder.cc b/source/Refitting/src/ClonesAndSplitTracksFinder.cc index fd4fe3f..8c01ba4 100644 --- a/source/Refitting/src/ClonesAndSplitTracksFinder.cc +++ b/source/Refitting/src/ClonesAndSplitTracksFinder.cc @@ -5,11 +5,11 @@ #include #include +#include "MarlinTrk/IMarlinTrkSystem.h" +#include "MarlinTrk/MarlinTrkDiagnostics.h" #include #include #include -#include "MarlinTrk/IMarlinTrkSystem.h" -#include "MarlinTrk/MarlinTrkDiagnostics.h" #include @@ -64,13 +64,14 @@ ClonesAndSplitTracksFinder::ClonesAndSplitTracksFinder() : Processor("ClonesAndS registerProcessorParameter("minTrackPt", "minimum track pt for merging (in GeV/c)", _minPt, double(1.0)); - registerProcessorParameter("maxSignificanceTheta", "maximum significance separation in tanLambda", _maxSignificanceTheta, - double(3.0)); + registerProcessorParameter("maxSignificanceTheta", "maximum significance separation in tanLambda", + _maxSignificanceTheta, double(3.0)); registerProcessorParameter("maxSignificancePhi", "maximum significance separation in phi", _maxSignificancePhi, double(3.0)); - registerProcessorParameter("maxSignificancePt", "maximum significance separation in pt", _maxSignificancePt, double(2.0)); + registerProcessorParameter("maxSignificancePt", "maximum significance separation in pt", _maxSignificancePt, + double(2.0)); registerProcessorParameter("mergeSplitTracks", "if true, the merging of split tracks is performed", _mergeSplitTracks, bool(false)); @@ -97,12 +98,12 @@ void ClonesAndSplitTracksFinder::init() { _trksystem->init(); // Put default values for track fitting - _initialTrackError_d0 = 1.e6; - _initialTrackError_phi0 = 1.e2; + _initialTrackError_d0 = 1.e6; + _initialTrackError_phi0 = 1.e2; _initialTrackError_omega = 1.e-4; - _initialTrackError_z0 = 1.e6; - _initialTrackError_tanL = 1.e2; - _maxChi2perHit = 1.e2; + _initialTrackError_z0 = 1.e6; + _initialTrackError_tanL = 1.e2; + _maxChi2perHit = 1.e2; _n_run = 0; _n_evt = 0; @@ -112,8 +113,8 @@ void ClonesAndSplitTracksFinder::processRunHeader(LCRunHeader*) { ++_n_run; } void ClonesAndSplitTracksFinder::processEvent(LCEvent* evt) { // set the correct configuration for the tracking system for this event - MarlinTrk::TrkSysConfig mson(_trksystem, _MSOn); - MarlinTrk::TrkSysConfig elosson(_trksystem, _ElossOn); + MarlinTrk::TrkSysConfig mson(_trksystem, _MSOn); + MarlinTrk::TrkSysConfig elosson(_trksystem, _ElossOn); MarlinTrk::TrkSysConfig smoothon(_trksystem, _SmoothOn); ++_n_evt; @@ -184,9 +185,9 @@ LCCollection* ClonesAndSplitTracksFinder::GetCollection(LCEvent* evt, std::strin // Function to check if two KDtracks contain several hits in common int ClonesAndSplitTracksFinder::overlappingHits(const Track* track1, const Track* track2) { - int nHitsInCommon = 0; - const EVENT::TrackerHitVec trackVec1 = track1->getTrackerHits(); - const EVENT::TrackerHitVec trackVec2 = track2->getTrackerHits(); + int nHitsInCommon = 0; + const EVENT::TrackerHitVec trackVec1 = track1->getTrackerHits(); + const EVENT::TrackerHitVec trackVec2 = track2->getTrackerHits(); for (size_t hit = 0; hit < trackVec1.size(); hit++) { if (std::find(trackVec2.begin(), trackVec2.end(), trackVec1.at(hit)) != trackVec2.end()) nHitsInCommon++; @@ -196,31 +197,31 @@ int ClonesAndSplitTracksFinder::overlappingHits(const Track* track1, const Track void ClonesAndSplitTracksFinder::fromTrackToTrackImpl(const Track* track, TrackImpl*& trackFinal) { const TrackState* ts_atOther = 0; - ts_atOther = track->getTrackState(TrackState::AtOther); + ts_atOther = track->getTrackState(TrackState::AtOther); if (ts_atOther) trackFinal->addTrackState(new TrackStateImpl(*ts_atOther)); const TrackState* ts_atIP = 0; - ts_atIP = track->getTrackState(TrackState::AtIP); + ts_atIP = track->getTrackState(TrackState::AtIP); if (ts_atIP) trackFinal->addTrackState(new TrackStateImpl(*ts_atIP)); const TrackState* ts_atFirstHit = 0; - ts_atFirstHit = track->getTrackState(TrackState::AtFirstHit); + ts_atFirstHit = track->getTrackState(TrackState::AtFirstHit); if (ts_atFirstHit) trackFinal->addTrackState(new TrackStateImpl(*ts_atFirstHit)); const TrackState* ts_atLastHit = 0; - ts_atLastHit = track->getTrackState(TrackState::AtLastHit); + ts_atLastHit = track->getTrackState(TrackState::AtLastHit); if (ts_atLastHit) trackFinal->addTrackState(new TrackStateImpl(*ts_atLastHit)); const TrackState* ts_atCalorimeter = 0; - ts_atCalorimeter = track->getTrackState(TrackState::AtCalorimeter); + ts_atCalorimeter = track->getTrackState(TrackState::AtCalorimeter); if (ts_atCalorimeter) trackFinal->addTrackState(new TrackStateImpl(*ts_atCalorimeter)); const TrackState* ts_atVertex = 0; - ts_atVertex = track->getTrackState(TrackState::AtVertex); + ts_atVertex = track->getTrackState(TrackState::AtVertex); if (ts_atVertex) trackFinal->addTrackState(new TrackStateImpl(*ts_atVertex)); const TrackState* ts_atLastLocation = 0; - ts_atLastLocation = track->getTrackState(TrackState::LastLocation); + ts_atLastLocation = track->getTrackState(TrackState::LastLocation); if (ts_atLastLocation) trackFinal->addTrackState(new TrackStateImpl(*ts_atLastLocation)); @@ -242,17 +243,17 @@ void ClonesAndSplitTracksFinder::removeClones(EVENT::TrackVec& tracksWithoutClon std::multimap> candidateClones; - for (int iTrack = 0; iTrack < nTracks; ++iTrack) { // first loop over tracks - int countClones = 0; - Track* track_i = static_cast(input_track_col->getElementAt(iTrack)); + for (int iTrack = 0; iTrack < nTracks; ++iTrack) { // first loop over tracks + int countClones = 0; + Track* track_i = static_cast(input_track_col->getElementAt(iTrack)); - for (int jTrack = 0; jTrack < nTracks; ++jTrack) { // second loop over tracks + for (int jTrack = 0; jTrack < nTracks; ++jTrack) { // second loop over tracks Track* track_j = static_cast(input_track_col->getElementAt(jTrack)); - if (track_i != track_j) { // track1 != track2 + if (track_i != track_j) { // track1 != track2 const unsigned int nOverlappingHits = overlappingHits(track_i, track_j); - if (nOverlappingHits >= 2) { // clones + if (nOverlappingHits >= 2) { // clones countClones++; Track* bestTrack; bestInClones(track_i, track_j, nOverlappingHits, bestTrack); @@ -262,18 +263,19 @@ void ClonesAndSplitTracksFinder::removeClones(EVENT::TrackVec& tracksWithoutClon } } - } // end second track loop + } // end second track loop if (countClones == 0) { tracksWithoutClones.push_back(track_i); } - } // end first track loop + } // end first track loop filterClonesAndMergedTracks(candidateClones, input_track_col, tracksWithoutClones, true); } -void ClonesAndSplitTracksFinder::mergeSplitTracks(std::unique_ptr& trackVec, LCCollection*& input_track_col, +void ClonesAndSplitTracksFinder::mergeSplitTracks(std::unique_ptr& trackVec, + LCCollection*& input_track_col, EVENT::TrackVec& tracksWithoutClones) { streamlog_out(DEBUG8) << "ClonesAndSplitTracksFinder::mergeSplitTracks " << std::endl; @@ -281,19 +283,19 @@ void ClonesAndSplitTracksFinder::mergeSplitTracks(std::unique_ptr iter_duplicates; for (UInt_t iTrack = 0; iTrack < tracksWithoutClones.size(); ++iTrack) { - int countMergingPartners = 0; - bool toBeMerged = false; - Track* track_i = static_cast(tracksWithoutClones.at(iTrack)); + int countMergingPartners = 0; + bool toBeMerged = false; + Track* track_i = static_cast(tracksWithoutClones.at(iTrack)); - double pt_i = 0.3 * _magneticField / (fabs(track_i->getOmega()) * 1000.); + double pt_i = 0.3 * _magneticField / (fabs(track_i->getOmega()) * 1000.); double theta_i = (M_PI / 2 - atan(track_i->getTanLambda())) * 180. / M_PI; - double phi_i = track_i->getPhi() * 180. / M_PI; + double phi_i = track_i->getPhi() * 180. / M_PI; - //Merge only tracks with min pt - //Try to avoid merging loopers for now + // Merge only tracks with min pt + // Try to avoid merging loopers for now if (pt_i < _minPt) { - streamlog_out(DEBUG5) << " Track #" << iTrack << ": pt = " << pt_i << ", theta = " << theta_i << ", phi = " << phi_i - << std::endl; + streamlog_out(DEBUG5) << " Track #" << iTrack << ": pt = " << pt_i << ", theta = " << theta_i + << ", phi = " << phi_i << std::endl; streamlog_out(DEBUG5) << " Track #" << iTrack << " does not fulfil min pt requirement." << std::endl; streamlog_out(DEBUG5) << " TRACK STORED" << std::endl; @@ -304,17 +306,17 @@ void ClonesAndSplitTracksFinder::mergeSplitTracks(std::unique_ptr(tracksWithoutClones.at(jTrack)); - bool isCloseInTheta = false, isCloseInPhi = false, isCloseInPt = false; + Track* track_j = static_cast(tracksWithoutClones.at(jTrack)); + bool isCloseInTheta = false, isCloseInPhi = false, isCloseInPt = false; if (track_j != track_i) { - double pt_j = 0.3 * _magneticField / (fabs(track_j->getOmega() * 1000.)); + double pt_j = 0.3 * _magneticField / (fabs(track_j->getOmega() * 1000.)); double theta_j = (M_PI / 2 - atan(track_j->getTanLambda())) * 180. / M_PI; - double phi_j = track_j->getPhi() * 180. / M_PI; - streamlog_out(DEBUG5) << " Track #" << iTrack << ": pt = " << pt_i << ", theta = " << theta_i << ", phi = " << phi_i - << std::endl; - streamlog_out(DEBUG5) << " Track #" << jTrack << ": pt = " << pt_j << ", theta = " << theta_j << ", phi = " << phi_j - << std::endl; + double phi_j = track_j->getPhi() * 180. / M_PI; + streamlog_out(DEBUG5) << " Track #" << iTrack << ": pt = " << pt_i << ", theta = " << theta_i + << ", phi = " << phi_i << std::endl; + streamlog_out(DEBUG5) << " Track #" << jTrack << ": pt = " << pt_j << ", theta = " << theta_j + << ", phi = " << phi_j << std::endl; if (pt_j < _minPt) { streamlog_out(DEBUG5) << " Track #" << jTrack << " does not fulfil min pt requirement. Skip. " << std::endl; @@ -322,8 +324,8 @@ void ClonesAndSplitTracksFinder::mergeSplitTracks(std::unique_ptr tanLambda significance = " << significanceTanLambda << " with cut at " << _maxSignificanceTheta << std::endl; @@ -355,7 +357,8 @@ void ClonesAndSplitTracksFinder::mergeSplitTracks(std::unique_ptr>) + if (toBeMerged) { // merging, refitting, storing in a container of mergingCandidates (multimap <*track1, + // pair<*track2,*trackMerged>>) EVENT::Track* lcioTrkPtr = nullptr; mergeAndFit(track_i, track_j, lcioTrkPtr); if (not lcioTrkPtr) { @@ -365,16 +368,16 @@ void ClonesAndSplitTracksFinder::mergeSplitTracks(std::unique_ptr(_trksystem->createTrack()); // Make an initial covariance matrix with very broad default values - EVENT::FloatVec covMatrix(15, 0); // Size 15, filled with 0s - covMatrix[0] = (_initialTrackError_d0); //sigma_d0^2 - covMatrix[2] = (_initialTrackError_phi0); //sigma_phi0^2 - covMatrix[5] = (_initialTrackError_omega); //sigma_omega^2 - covMatrix[9] = (_initialTrackError_z0); //sigma_z0^2 - covMatrix[14] = (_initialTrackError_tanL); //sigma_tanl^2 + EVENT::FloatVec covMatrix(15, 0); // Size 15, filled with 0s + covMatrix[0] = (_initialTrackError_d0); // sigma_d0^2 + covMatrix[2] = (_initialTrackError_phi0); // sigma_phi0^2 + covMatrix[5] = (_initialTrackError_omega); // sigma_omega^2 + covMatrix[9] = (_initialTrackError_z0); // sigma_z0^2 + covMatrix[14] = (_initialTrackError_tanL); // sigma_tanl^2 const bool direction = _extrapolateForward ? MarlinTrk::IMarlinTrack::forward : MarlinTrk::IMarlinTrack::backward; - int fit_status = MarlinTrk::createFinalisedLCIOTrack(marlin_trk.get(), trkHits, mergedTrack.get(), direction, covMatrix, - _magneticField, _maxChi2perHit); + int fit_status = MarlinTrk::createFinalisedLCIOTrack(marlin_trk.get(), trkHits, mergedTrack.get(), direction, + covMatrix, _magneticField, _maxChi2perHit); if (fit_status != 0) { streamlog_out(DEBUG4) << "Fit failed with error status " << fit_status << std::endl; @@ -594,7 +600,8 @@ void ClonesAndSplitTracksFinder::mergeAndFit(Track* track_i, Track* track_j, Tra marlin_trk->getHitsInFit(hits_in_fit); if (hits_in_fit.size() < 3) { - streamlog_out(DEBUG4) << "Less than 3 hits in fit: Track discarded. Number of hits = " << trkHits.size() << std::endl; + streamlog_out(DEBUG4) << "Less than 3 hits in fit: Track discarded. Number of hits = " << trkHits.size() + << std::endl; return; } @@ -612,7 +619,7 @@ void ClonesAndSplitTracksFinder::mergeAndFit(Track* track_i, Track* track_j, Tra } UTIL::BitField64 encoder2(lcio::LCTrackerCellID::encoding_string()); - encoder2.reset(); // reset to 0 + encoder2.reset(); // reset to 0 MarlinTrk::addHitNumbersToTrack(mergedTrack.get(), all_hits, false, encoder2); MarlinTrk::addHitNumbersToTrack(mergedTrack.get(), hits_in_fit, true, encoder2); @@ -638,19 +645,19 @@ void ClonesAndSplitTracksFinder::bestInClones(Track* track_a, Track* track_b, in double b_chi2 = track_b->getChi2() / track_b->getNdf(); double a_chi2 = track_a->getChi2() / track_a->getNdf(); - if (nOverlappingHits == trackerHit_a_size) { // if the second track is the first track + segment + if (nOverlappingHits == trackerHit_a_size) { // if the second track is the first track + segment bestTrack = track_b; - } else if (nOverlappingHits == trackerHit_b_size) { // if the second track is a subtrack of the first track + } else if (nOverlappingHits == trackerHit_b_size) { // if the second track is a subtrack of the first track bestTrack = track_a; - } else if (trackerHit_b_size == trackerHit_a_size) { // if the two tracks have the same length + } else if (trackerHit_b_size == trackerHit_a_size) { // if the two tracks have the same length if (b_chi2 <= a_chi2) { bestTrack = track_b; } else { bestTrack = track_a; } - } else if (trackerHit_b_size > trackerHit_a_size) { // if the second track is longer + } else if (trackerHit_b_size > trackerHit_a_size) { // if the second track is longer bestTrack = track_b; - } else if (trackerHit_b_size < trackerHit_a_size) { // if the second track is shorter + } else if (trackerHit_b_size < trackerHit_a_size) { // if the second track is shorter bestTrack = track_a; } } diff --git a/source/Refitting/src/DDCellsAutomatonMV.cc b/source/Refitting/src/DDCellsAutomatonMV.cc index 82689e1..2378c05 100644 --- a/source/Refitting/src/DDCellsAutomatonMV.cc +++ b/source/Refitting/src/DDCellsAutomatonMV.cc @@ -1,1500 +1,1343 @@ #include "DDCellsAutomatonMV.h" -//using namespace MarlinTrk ; +// using namespace MarlinTrk ; -#include #include -#include #include +#include +#include #include // #include "UTIL/LCTrackerConf.h" #include // #include "MarlinTrk/Factory.h" -#include "MarlinTrk/IMarlinTrack.h" #include "MarlinTrk/HelixTrack.h" +#include "MarlinTrk/IMarlinTrack.h" #include "MarlinTrk/MarlinTrkUtils.h" - -#include "DD4hep/Detector.h" #include "DD4hep/DD4hepUnits.h" +#include "DD4hep/Detector.h" +#include "DDRec/DetectorData.h" #include "DDRec/Surface.h" #include "DDRec/SurfaceManager.h" -#include "DDRec/DetectorData.h" - - +using namespace lcio; +using namespace marlin; -using namespace lcio ; -using namespace marlin ; - -using namespace MarlinTrk ; +using namespace MarlinTrk; // Used to fedine the quality of the track output collection const int DDCellsAutomatonMV::_output_track_col_quality_GOOD = 1; const int DDCellsAutomatonMV::_output_track_col_quality_FAIR = 2; const int DDCellsAutomatonMV::_output_track_col_quality_POOR = 3; -const double DDCellsAutomatonMV::TWOPI = 2*M_PI; - -DDCellsAutomatonMV aDDCellsAutomatonMV ; - -DDCellsAutomatonMV::DDCellsAutomatonMV() : Processor("DDCellsAutomatonMV"){ - - registerProcessorParameter("NDivisionsInPhi", - "Number of divisions in Phi", - _nDivisionsInPhi, - int(80)); - - - registerProcessorParameter("NDivisionsInTheta", - "Number of divisions in Theta", - _nDivisionsInTheta, - int(80)); - - FloatVec resUEx ; - resUEx.push_back( 0.0040 ) ; - - registerProcessorParameter( "PixRes" , - "VXD pixels resolution" , - _resU , - resUEx) ; - - registerProcessorParameter("MultipleScatteringOn", - "Use MultipleScattering in Fit", - _MSOn, - bool(true)); - - registerProcessorParameter("EnergyLossOn", - "Use Energy Loss in Fit", - _ElossOn, - bool(true)); - - registerProcessorParameter("SmoothOn", - "Smooth All Mesurement Sites in Fit", - _SmoothOn, - bool(true)); +const double DDCellsAutomatonMV::TWOPI = 2 * M_PI; + +DDCellsAutomatonMV aDDCellsAutomatonMV; + +DDCellsAutomatonMV::DDCellsAutomatonMV() : Processor("DDCellsAutomatonMV") { + + registerProcessorParameter("NDivisionsInPhi", "Number of divisions in Phi", _nDivisionsInPhi, int(80)); + + registerProcessorParameter("NDivisionsInTheta", "Number of divisions in Theta", _nDivisionsInTheta, int(80)); + + FloatVec resUEx; + resUEx.push_back(0.0040); + + registerProcessorParameter("PixRes", "VXD pixels resolution", _resU, resUEx); + + registerProcessorParameter("MultipleScatteringOn", "Use MultipleScattering in Fit", _MSOn, bool(true)); + + registerProcessorParameter("EnergyLossOn", "Use Energy Loss in Fit", _ElossOn, bool(true)); + + registerProcessorParameter("SmoothOn", "Smooth All Mesurement Sites in Fit", _SmoothOn, bool(true)); /* registerProcessorParameter("UseMiddleLayer", "Use middle layer for the cellular automaton", _middleLayer, bool(true)); */ - registerProcessorParameter("UseSIT", - "Use SIT", - _useSIT, - int(1)); - - - registerProcessorParameter( "HitsPerTrackMin", - "The minimum number of hits to create a track", - _hitsPerTrackMin, - int( 4 ) ); - - registerProcessorParameter( "StepMax", - "The maximum step between layers", - _layerStepMax, - int( 2 ) ); - - registerProcessorParameter( "LastLayerToIP", - "The maximum step between layers", - _lastLayerToIP, - int( 3 ) ); - - registerProcessorParameter("HelixFitMax", - "The maximum chi2/Ndf that is allowed as result of a helix fit", - _helixFitMax, - double( 500 ) ); - - registerProcessorParameter("kalFitMax", - "The maximum chi2/Ndf that is allowed as result of a Kalman fit", - _chi2OverNdfCut, - double( 500 ) ); - - registerProcessorParameter("Chi2ProbCut", - "Tracks with a chi2 probability below this will get sorted out", - _chi2ProbCut, - double(0.005)); - - registerProcessorParameter( "InitialTrackErrorD0", - "Value used for the initial d0 variance of the trackfit", - _initialTrackError_d0, - float(1.e6)); - - registerProcessorParameter( "InitialTrackErrorPhi0", - "Value used for the initial phi0 variance of the trackfit", - _initialTrackError_phi0, - float(1.e2)); - - registerProcessorParameter( "InitialTrackErrorOmega", - "Value used for the initial omega variance of the trackfit", - _initialTrackError_omega, - float(1.e-4)); - - registerProcessorParameter( "InitialTrackErrorZ0", - "Value used for the initial z0 variance of the trackfit", - _initialTrackError_z0, - float(1.e6)); - - registerProcessorParameter( "InitialTrackErrorTanL", - "Value used for the initial tanL variance of the trackfit", - _initialTrackError_tanL, - float(1.e2)); - - registerProcessorParameter( "MaxChi2PerHit", - "Maximum Chi-squared value allowed when assigning a hit to a track", - _maxChi2PerHit, - float(1.e2)); - + registerProcessorParameter("UseSIT", "Use SIT", _useSIT, int(1)); + + registerProcessorParameter("HitsPerTrackMin", "The minimum number of hits to create a track", _hitsPerTrackMin, + int(4)); + + registerProcessorParameter("StepMax", "The maximum step between layers", _layerStepMax, int(2)); + + registerProcessorParameter("LastLayerToIP", "The maximum step between layers", _lastLayerToIP, int(3)); + + registerProcessorParameter("HelixFitMax", "The maximum chi2/Ndf that is allowed as result of a helix fit", + _helixFitMax, double(500)); + + registerProcessorParameter("kalFitMax", "The maximum chi2/Ndf that is allowed as result of a Kalman fit", + _chi2OverNdfCut, double(500)); + + registerProcessorParameter("Chi2ProbCut", "Tracks with a chi2 probability below this will get sorted out", + _chi2ProbCut, double(0.005)); + + registerProcessorParameter("InitialTrackErrorD0", "Value used for the initial d0 variance of the trackfit", + _initialTrackError_d0, float(1.e6)); + + registerProcessorParameter("InitialTrackErrorPhi0", "Value used for the initial phi0 variance of the trackfit", + _initialTrackError_phi0, float(1.e2)); + + registerProcessorParameter("InitialTrackErrorOmega", "Value used for the initial omega variance of the trackfit", + _initialTrackError_omega, float(1.e-4)); + + registerProcessorParameter("InitialTrackErrorZ0", "Value used for the initial z0 variance of the trackfit", + _initialTrackError_z0, float(1.e6)); + + registerProcessorParameter("InitialTrackErrorTanL", "Value used for the initial tanL variance of the trackfit", + _initialTrackError_tanL, float(1.e2)); + + registerProcessorParameter("MaxChi2PerHit", "Maximum Chi-squared value allowed when assigning a hit to a track", + _maxChi2PerHit, float(1.e2)); + registerProcessorParameter("MaxHitsPerSector", - "Maximal number of hits allowed on a sector. More will cause drop of hits in sector", - _maxHitsPerSector, - int(1000)); - - registerProcessorParameter( "BestSubsetFinder", - "The method used to find the best non overlapping subset of tracks. Available are: SubsetHopfieldNN, SubsetSimple and None", - _bestSubsetFinder, - std::string( "SubsetHopfieldNN" ) ); + "Maximal number of hits allowed on a sector. More will cause drop of hits in sector", + _maxHitsPerSector, int(1000)); - // Security checks to prevent combinatorial disasters - - registerProcessorParameter( "MaxConnectionsAutomaton", - "If the automaton has more connections than this it will be redone with the next set of cut off parameters", - _maxConnectionsAutomaton, - int( 100000 ) ); + registerProcessorParameter("BestSubsetFinder", + "The method used to find the best non overlapping subset of tracks. Available are: " + "SubsetHopfieldNN, SubsetSimple and None", + _bestSubsetFinder, std::string("SubsetHopfieldNN")); - registerProcessorParameter("MaxDistance", - "The maximum distance between two hits in adjacent layers in order to form a minivector", - _maxDist, - double(20) ); + // Security checks to prevent combinatorial disasters - registerProcessorParameter("MVHitsThetaDifference_Adjacent", - "The difference in polar angle (in degrees) between two hits in adjacent layers in order to form a minivector", - _hitPairThDiff, - double(0.5) ); + registerProcessorParameter( + "MaxConnectionsAutomaton", + "If the automaton has more connections than this it will be redone with the next set of cut off parameters", + _maxConnectionsAutomaton, int(100000)); - registerProcessorParameter("MVHitsThetaDifference", - "The difference in polar angle (in degrees) between two hits in the INNER layer in order to form a minivector", - _hitPairThDiffInner, - double(0.1) ); + registerProcessorParameter("MaxDistance", + "The maximum distance between two hits in adjacent layers in order to form a minivector", + _maxDist, double(20)); - registerProcessorParameter("NHitsChi2", - "Maximal number of hits for which a track with n hits is better than one with n-1hits. (defaut 5)", - _nHitsChi2, - int(5)); + registerProcessorParameter( + "MVHitsThetaDifference_Adjacent", + "The difference in polar angle (in degrees) between two hits in adjacent layers in order to form a minivector", + _hitPairThDiff, double(0.5)); + registerProcessorParameter( + "MVHitsThetaDifference", + "The difference in polar angle (in degrees) between two hits in the INNER layer in order to form a minivector", + _hitPairThDiffInner, double(0.1)); + registerProcessorParameter( + "NHitsChi2", "Maximal number of hits for which a track with n hits is better than one with n-1hits. (defaut 5)", + _nHitsChi2, int(5)); - - registerProcessorParameter("VXDName", - "Name of the vertex detector element", - _detElVXDName, - std::string("VertexBarrel")); + registerProcessorParameter("VXDName", "Name of the vertex detector element", _detElVXDName, + std::string("VertexBarrel")); - registerProcessorParameter("InnerTrackerName", - "Name of the inner tracker detector element", - _detElITName, - std::string("InnerTrackerBarrel")); + registerProcessorParameter("InnerTrackerName", "Name of the inner tracker detector element", _detElITName, + std::string("InnerTrackerBarrel")); - registerProcessorParameter("OuterTrackerName", - "Name of the outer tracker detector element", - _detElOTName, - std::string("OuterTrackerBarrel")); + registerProcessorParameter("OuterTrackerName", "Name of the outer tracker detector element", _detElOTName, + std::string("OuterTrackerBarrel")); - // Input Collections - - registerInputCollection(LCIO::TRACKERHITPLANE, - "VTXHitCollectionName", - "VTX Hit Collection Name", - _VTXHitCollection, + + registerInputCollection(LCIO::TRACKERHITPLANE, "VTXHitCollectionName", "VTX Hit Collection Name", _VTXHitCollection, std::string("VTXTrackerHits")); - registerInputCollection(LCIO::TRACKERHIT, - "SITHitCollectionName", - "SIT Hit Collection Name", - _SITHitCollection, + registerInputCollection(LCIO::TRACKERHIT, "SITHitCollectionName", "SIT Hit Collection Name", _SITHitCollection, std::string("SITSpacePoints")); - // Output Collections - - registerOutputCollection(LCIO::TRACK, - "CATrackCollection", - "Name of the Cellular Automaton Tracking output collection", - _CATrackCollection, - std::string("CATracks")); - + + registerOutputCollection(LCIO::TRACK, "CATrackCollection", + "Name of the Cellular Automaton Tracking output collection", _CATrackCollection, + std::string("CATracks")); + // The Criteria for the Cellular Automaton: - - std::vector< std::string > allCriteria = Criteria::getAllCriteriaNamesVec(); - - - registerProcessorParameter( "Criteria", - "A vector of the criteria that are going to be used. For every criterion a min and max needs to be set!!!", - _criteriaNames, - allCriteria); - - + + std::vector allCriteria = Criteria::getAllCriteriaNamesVec(); + + registerProcessorParameter( + "Criteria", + "A vector of the criteria that are going to be used. For every criterion a min and max needs to be set!!!", + _criteriaNames, allCriteria); + // Now set min and max values for all the criteria - for( unsigned i=0; i < _criteriaNames.size(); i++ ){ - - std::vector< float > emptyVec; - + for (unsigned i = 0; i < _criteriaNames.size(); i++) { + + std::vector emptyVec; + std::string critMinString = _criteriaNames[i] + "_min"; - - registerProcessorParameter( critMinString, - "The minimum of " + _criteriaNames[i], - _critMinima[ _criteriaNames[i] ], - emptyVec); - - + + registerProcessorParameter(critMinString, "The minimum of " + _criteriaNames[i], _critMinima[_criteriaNames[i]], + emptyVec); + std::string critMaxString = _criteriaNames[i] + "_max"; - - registerProcessorParameter( critMaxString, - "The maximum of " + _criteriaNames[i], - _critMaxima[ _criteriaNames[i] ], - emptyVec); - - + + registerProcessorParameter(critMaxString, "The maximum of " + _criteriaNames[i], _critMaxima[_criteriaNames[i]], + emptyVec); } - } void DDCellsAutomatonMV::init() { - this->setupGeom(); - + /**********************************************************************************************/ /* Make a SectorSystemVXD */ /**********************************************************************************************/ - + // The SectorSystemVXD is the object translating the sectors of the hits into layers, modules etc. and vice versa - MiniVectors_sectors = 0 ; - MiniVectors_CutSelection = 0 ; + MiniVectors_sectors = 0; + MiniVectors_CutSelection = 0; - int nDivisionsInPhi = _nDivisionsInPhi ; - int nDivisionsInTheta = _nDivisionsInTheta ; - if (_useSIT==1){ - _nLayers = _nLayersVTX + _nLayersSIT + 1 ; // + 1 adding a virtual layer for the IP - } - else - _nLayers = _nLayersVTX + 1 ; // + 1 adding a virtual layer for the IP - _sectorSystemVXD = new SectorSystemVXD( _nLayers, nDivisionsInPhi , nDivisionsInTheta ); - - - _dPhi = TWOPI/_nDivisionsInPhi; - _dTheta = 2.0/_nDivisionsInTheta; + int nDivisionsInPhi = _nDivisionsInPhi; + int nDivisionsInTheta = _nDivisionsInTheta; + if (_useSIT == 1) { + _nLayers = _nLayersVTX + _nLayersSIT + 1; // + 1 adding a virtual layer for the IP + } else + _nLayers = _nLayersVTX + 1; // + 1 adding a virtual layer for the IP + _sectorSystemVXD = new SectorSystemVXD(_nLayers, nDivisionsInPhi, nDivisionsInTheta); + + _dPhi = TWOPI / _nDivisionsInPhi; + _dTheta = 2.0 / _nDivisionsInTheta; /**********************************************************************************************/ /* Initialise the MarlinTrkSystem, needed by the tracks for fitting */ /**********************************************************************************************/ - - // set upt the geometry - - _trkSystem = MarlinTrk::Factory::createMarlinTrkSystem( "DDKalTest" , 0, "" ) ; - - - if( _trkSystem == 0 ) throw EVENT::Exception( std::string(" Cannot initialize MarlinTrkSystem of Type: ") + std::string("KalTest" ) ) ; - - - // set the options - _trkSystem->setOption( MarlinTrk::IMarlinTrkSystem::CFG::useQMS, _MSOn ) ; //multiple scattering - _trkSystem->setOption( MarlinTrk::IMarlinTrkSystem::CFG::usedEdx, _ElossOn) ; //energy loss - _trkSystem->setOption( MarlinTrk::IMarlinTrkSystem::CFG::useSmoothing, _SmoothOn) ; //smoothing - - // initialise the tracking system - _trkSystem->init() ; - -} + // set upt the geometry -void DDCellsAutomatonMV::processRunHeader( LCRunHeader* ) { - -} + _trkSystem = MarlinTrk::Factory::createMarlinTrkSystem("DDKalTest", 0, ""); + if (_trkSystem == 0) + throw EVENT::Exception(std::string(" Cannot initialize MarlinTrkSystem of Type: ") + std::string("KalTest")); + // set the options + _trkSystem->setOption(MarlinTrk::IMarlinTrkSystem::CFG::useQMS, _MSOn); // multiple scattering + _trkSystem->setOption(MarlinTrk::IMarlinTrkSystem::CFG::usedEdx, _ElossOn); // energy loss + _trkSystem->setOption(MarlinTrk::IMarlinTrkSystem::CFG::useSmoothing, _SmoothOn); // smoothing + // initialise the tracking system + _trkSystem->init(); +} -void DDCellsAutomatonMV::processEvent( LCEvent * evt ) { +void DDCellsAutomatonMV::processRunHeader(LCRunHeader*) {} - // set the correct configuration for the tracking system for this event - MarlinTrk::TrkSysConfig< MarlinTrk::IMarlinTrkSystem::CFG::useQMS> mson( _trkSystem, _MSOn ) ; - MarlinTrk::TrkSysConfig< MarlinTrk::IMarlinTrkSystem::CFG::usedEdx> elosson( _trkSystem,_ElossOn) ; - MarlinTrk::TrkSysConfig< MarlinTrk::IMarlinTrkSystem::CFG::useSmoothing> smoothon( _trkSystem,_SmoothOn) ; +void DDCellsAutomatonMV::processEvent(LCEvent* evt) { - TrackerHitVec HitsTemp; //Hits to be deleted at the end - std::vector< IHit* > hitsTBD; //Hits to be deleted at the end - //std::vector< IHit* > MiniVectorsTemp; + // set the correct configuration for the tracking system for this event + MarlinTrk::TrkSysConfig mson(_trkSystem, _MSOn); + MarlinTrk::TrkSysConfig elosson(_trkSystem, _ElossOn); + MarlinTrk::TrkSysConfig smoothon(_trkSystem, _SmoothOn); + + TrackerHitVec HitsTemp; // Hits to be deleted at the end + std::vector hitsTBD; // Hits to be deleted at the end + // std::vector< IHit* > MiniVectorsTemp; // reset the hit map _map_sector_spacepoints.clear(); _map_sector_hits.clear(); - InitialiseVTX( evt, HitsTemp ); + InitialiseVTX(evt, HitsTemp); unsigned round = 0; // the round we are in - std::vector < RawTrack > rawTracks; - - + std::vector rawTracks; /**********************************************************************************************/ /* Check if no sector is overflowing with hits */ /**********************************************************************************************/ - - - std::map< int , EVENT::TrackerHitVec >::iterator it; - - for( it=_map_sector_spacepoints.begin(); it != _map_sector_spacepoints.end(); it++ ){ - - + + std::map::iterator it; + + for (it = _map_sector_spacepoints.begin(); it != _map_sector_spacepoints.end(); it++) { + int nHits = it->second.size(); - streamlog_out( DEBUG2 ) << "Number of hits in sector " << it->first << " = " << nHits << "\n"; - - if( nHits > _maxHitsPerSector ){ - - it->second.clear(); //delete the hits in this sector, it will be dropped - - streamlog_out(ERROR) << " ### EVENT " << evt->getEventNumber() << " :: RUN " << evt->getRunNumber() << " \n ### Number of Hits in VXD Sector " << it->first << ": " << nHits << " > " << _maxHitsPerSector << " (MaxHitsPerSector)\n : This sector will be dropped from track search, and QualityCode set to \"Poor\" " << std::endl; - - _output_track_col_quality = _output_track_col_quality_POOR; // We had to drop hits, so the quality of the result is decreased - + streamlog_out(DEBUG2) << "Number of hits in sector " << it->first << " = " << nHits << "\n"; + + if (nHits > _maxHitsPerSector) { + + it->second.clear(); // delete the hits in this sector, it will be dropped + + streamlog_out(ERROR) + << " ### EVENT " << evt->getEventNumber() << " :: RUN " << evt->getRunNumber() + << " \n ### Number of Hits in VXD Sector " << it->first << ": " << nHits << " > " << _maxHitsPerSector + << " (MaxHitsPerSector)\n : This sector will be dropped from track search, and QualityCode set to \"Poor\" " + << std::endl; + + _output_track_col_quality = + _output_track_col_quality_POOR; // We had to drop hits, so the quality of the result is decreased } - } - /**********************************************************************************************/ /* Add the IP as a virtual hit */ /**********************************************************************************************/ - - IHit* virtualIPHitForward = createVirtualIPHit(_sectorSystemVXD ); - //HitsTemp.push_back( virtualIPHitForward ); - _map_sector_hits[0].push_back( virtualIPHitForward ); - streamlog_out(DEBUG4) << " sector of the IP hit = " << virtualIPHitForward->getSector() << std::endl ; - - //********************************************************************************************************************* + IHit* virtualIPHitForward = createVirtualIPHit(_sectorSystemVXD); + // HitsTemp.push_back( virtualIPHitForward ); + _map_sector_hits[0].push_back(virtualIPHitForward); + streamlog_out(DEBUG4) << " sector of the IP hit = " << virtualIPHitForward->getSector() << std::endl; + + //********************************************************************************************************************* /**********************************************************************************************/ /* Create Mini-Vectors */ /**********************************************************************************************/ + for (std::map::iterator itSecHit = _map_sector_spacepoints.begin(); + itSecHit != _map_sector_spacepoints.end(); itSecHit++) { // over all sectors - for ( std::map< int , EVENT::TrackerHitVec >::iterator itSecHit = _map_sector_spacepoints.begin(); itSecHit != _map_sector_spacepoints.end(); itSecHit++ ){ //over all sectors - int sector = itSecHit->first; - CreateMiniVectors( sector ); // Process one VXD sector - + CreateMiniVectors(sector); // Process one VXD sector } + while (setCriteria(round)) { + streamlog_out(DEBUG4) << " DO I ENTER IN THE GAME " << std::endl; - while( setCriteria( round ) ){ - - streamlog_out(DEBUG4) << " DO I ENTER IN THE GAME " << std::endl ; - - round++; // count up the round we are in - - SegmentBuilder segBuilder( _map_sector_hits ); - - segBuilder.addCriteria ( _crit2Vec ); // Add the criteria on when to connect two hits. The vector has been filled by the method setCriteria - - unsigned layerStepMax = _layerStepMax ; // how many layers to go at max - unsigned lastLayerToIP = _lastLayerToIP ; - //bool MiddleLayer = _middleLayer ; - //VXDSectorConnector secCon( _sectorSystemVXD , layerStepMax, lastLayerToIP, MiddleLayer ); - VXDSectorConnector secCon( _sectorSystemVXD , layerStepMax, lastLayerToIP ); - - - streamlog_out(DEBUG4) << " _layerStepMax = " << _layerStepMax << std::endl ; - streamlog_out(DEBUG4) << " _lastLayerToIP = " << _lastLayerToIP << std::endl ; - - segBuilder.addSectorConnector ( & secCon ); // Add the sector connector (so the SegmentBuilder knows what hits from different sectors it is allowed to look for connections) - - // And get out the Cellular Automaton with the 1-segments + + SegmentBuilder segBuilder(_map_sector_hits); + + segBuilder.addCriteria(_crit2Vec); // Add the criteria on when to connect two hits. The vector has been filled by + // the method setCriteria + + unsigned layerStepMax = _layerStepMax; // how many layers to go at max + unsigned lastLayerToIP = _lastLayerToIP; + // bool MiddleLayer = _middleLayer ; + // VXDSectorConnector secCon( _sectorSystemVXD , layerStepMax, lastLayerToIP, MiddleLayer ); + VXDSectorConnector secCon(_sectorSystemVXD, layerStepMax, lastLayerToIP); + + streamlog_out(DEBUG4) << " _layerStepMax = " << _layerStepMax << std::endl; + streamlog_out(DEBUG4) << " _lastLayerToIP = " << _lastLayerToIP << std::endl; + + segBuilder.addSectorConnector(&secCon); // Add the sector connector (so the SegmentBuilder knows what hits from + // different sectors it is allowed to look for connections) + + // And get out the Cellular Automaton with the 1-segments Automaton automaton = segBuilder.get1SegAutomaton(); - streamlog_out(DEBUG4) << " automaton.getNumberOfConnections() = " << automaton.getNumberOfConnections() << std::endl ; - + streamlog_out(DEBUG4) << " automaton.getNumberOfConnections() = " << automaton.getNumberOfConnections() + << std::endl; + // Check if there are not too many connections - if( automaton.getNumberOfConnections() > unsigned( _maxConnectionsAutomaton ) ){ - + if (automaton.getNumberOfConnections() > unsigned(_maxConnectionsAutomaton)) { + streamlog_out(DEBUG4) << "Redo the Automaton with different parameters, because there are too many connections:\n" - << "\tconnections( " << automaton.getNumberOfConnections() << " ) > MaxConnectionsAutomaton( " << _maxConnectionsAutomaton << " )\n"; + << "\tconnections( " << automaton.getNumberOfConnections() + << " ) > MaxConnectionsAutomaton( " << _maxConnectionsAutomaton << " )\n"; continue; - } - /**********************************************************************************************/ /* Automaton */ /**********************************************************************************************/ - - if( automaton.getNumberOfConnections() > 0){ - - streamlog_out( DEBUG4 ) << "\t\t---Automaton---\n" ; - - //if( _useCED ) KiTrackMarlin::drawAutomatonSegments( automaton ); // draws the 1-segments (i.e. hits) - - + + if (automaton.getNumberOfConnections() > 0) { + + streamlog_out(DEBUG4) << "\t\t---Automaton---\n"; + + // if( _useCED ) KiTrackMarlin::drawAutomatonSegments( automaton ); // draws the 1-segments (i.e. hits) + /*******************************/ /* 2-hit segments */ /*******************************/ - - streamlog_out( DEBUG4 ) << "\t\t--2-hit-Segments--\n" ; - - // streamlog_out(DEBUG4) << "Automaton has " << automaton.getTracks( 3 ).size() << " track candidates\n"; //should be commented out, because it takes time - + + streamlog_out(DEBUG4) << "\t\t--2-hit-Segments--\n"; + + // streamlog_out(DEBUG4) << "Automaton has " << automaton.getTracks( 3 ).size() << " track candidates\n"; + // //should be commented out, because it takes time + automaton.clearCriteria(); - automaton.addCriteria( _crit3Vec ); // Add the criteria for 3 hits (i.e. 2 2-hit segments ) - - + automaton.addCriteria(_crit3Vec); // Add the criteria for 3 hits (i.e. 2 2-hit segments ) + // Let the automaton lengthen its 1-hit-segments to 2-hit-segments automaton.lengthenSegments(); - - + // So now we have 2-hit-segments and are ready to perform the Cellular Automaton. - + // Perform the automaton automaton.doAutomaton(); - - + // Clean segments with bad states automaton.cleanBadStates(); - - + // Reset the states of all segments automaton.resetStates(); - - // streamlog_out(DEBUG4) << "Automaton has " << automaton.getTracks( 3 ).size() << " track candidates\n"; //should be commented out, because it takes time - - + + // streamlog_out(DEBUG4) << "Automaton has " << automaton.getTracks( 3 ).size() << " track candidates\n"; + // //should be commented out, because it takes time + // Check if there are not too many connections - if( automaton.getNumberOfConnections() > unsigned( _maxConnectionsAutomaton ) ){ - - streamlog_out( DEBUG4 ) << "Redo the Automaton with different parameters, because there are too many connections:\n" - << "\tconnections( " << automaton.getNumberOfConnections() << " ) > MaxConnectionsAutomaton( " << _maxConnectionsAutomaton << " )\n"; - continue; - + if (automaton.getNumberOfConnections() > unsigned(_maxConnectionsAutomaton)) { + + streamlog_out(DEBUG4) + << "Redo the Automaton with different parameters, because there are too many connections:\n" + << "\tconnections( " << automaton.getNumberOfConnections() << " ) > MaxConnectionsAutomaton( " + << _maxConnectionsAutomaton << " )\n"; + continue; } - - streamlog_out(DEBUG4) << " _hitsPerTrackMin = " << _hitsPerTrackMin << std::endl ; + + streamlog_out(DEBUG4) << " _hitsPerTrackMin = " << _hitsPerTrackMin << std::endl; // get the raw tracks (raw track = just a vector of hits, the most rudimentary form of a track) - rawTracks = automaton.getTracks( _hitsPerTrackMin ); - + rawTracks = automaton.getTracks(_hitsPerTrackMin); + break; // if we reached this place all went well and we don't need another round --> exit the loop } } streamlog_out(DEBUG4) << "Automaton returned " << rawTracks.size() << " raw tracks \n"; - - //************************************************************************************************************* // Track fitting similar to forward tracking //************************************************************************************************************* - std::vector trackCandidates; + std::vector trackCandidates; // for all raw tracks we got from the automaton - for( unsigned i=0; i < rawTracks.size(); i++){ + for (unsigned i = 0; i < rawTracks.size(); i++) { RawTrack rawTrack = rawTracks[i]; - if( rawTrack.size() < unsigned( _hitsPerTrackMin ) ){ - - streamlog_out(DEBUG4) << "Trackversion discarded, too few hits: only " << rawTrack.size() << " < " << _hitsPerTrackMin << "(hitsPerTrackMin)\n"; + if (rawTrack.size() < unsigned(_hitsPerTrackMin)) { + + streamlog_out(DEBUG4) << "Trackversion discarded, too few hits: only " << rawTrack.size() << " < " + << _hitsPerTrackMin << "(hitsPerTrackMin)\n"; continue; - } - - VXDTrack* trackCand = new VXDTrack( _trkSystem ); - + + VXDTrack* trackCand = new VXDTrack(_trkSystem); + // add the hits to the track - for( unsigned k=0; k( rawTrack[k] ); // cast to IMiniVectors, as needed for a VXDTrack - if( mvHit != NULL ) trackCand->addHit( mvHit ); - else streamlog_out( DEBUG4 ) << "Hit " << rawTrack[k] << " could not be casted to IMiniVector\n"; + for (unsigned k = 0; k < rawTrack.size(); k++) { + IMiniVector* mvHit = dynamic_cast(rawTrack[k]); // cast to IMiniVectors, as needed for a VXDTrack + if (mvHit != NULL) + trackCand->addHit(mvHit); + else + streamlog_out(DEBUG4) << "Hit " << rawTrack[k] << " could not be casted to IMiniVector\n"; } - /*-----------------------------------------------*/ /* Helix Fit */ /*-----------------------------------------------*/ - - streamlog_out( DEBUG2 ) << "Fitting with Helix Fit\n"; - try{ + streamlog_out(DEBUG2) << "Fitting with Helix Fit\n"; + try { - - VXDHelixFitter helixFitter( trackCand->getLcioTrack() ); + VXDHelixFitter helixFitter(trackCand->getLcioTrack()); - TrackerHitVec testVec = trackCand->getLcioTrack()->getTrackerHits() ; + TrackerHitVec testVec = trackCand->getLcioTrack()->getTrackerHits(); - streamlog_out( DEBUG2 ) << " $$$$ fitting track with " << testVec.size() << " hits " << std::endl ; + streamlog_out(DEBUG2) << " $$$$ fitting track with " << testVec.size() << " hits " << std::endl; - float chi2OverNdf = helixFitter.getChi2() / float( helixFitter.getNdf() ); - streamlog_out( DEBUG2 ) << "chi2OverNdf = " << chi2OverNdf << "\n"; + float chi2OverNdf = helixFitter.getChi2() / float(helixFitter.getNdf()); + streamlog_out(DEBUG2) << "chi2OverNdf = " << chi2OverNdf << "\n"; - - if( chi2OverNdf > _helixFitMax ){ - - - streamlog_out( DEBUG2 ) << "Discarding track because of bad helix fit: chi2/ndf = " << chi2OverNdf << "\n"; + if (chi2OverNdf > _helixFitMax) { - // debug - //streamlog_out(DEBUG4) << " pre-fitting: deleting track " << trackCand << std::endl ; - delete trackCand; - continue; - - } - else { - streamlog_out( DEBUG2 ) << "Keeping track because of good helix fit: chi2/ndf = " << chi2OverNdf << "\n"; + streamlog_out(DEBUG2) << "Discarding track because of bad helix fit: chi2/ndf = " << chi2OverNdf << "\n"; + + // debug + // streamlog_out(DEBUG4) << " pre-fitting: deleting track " << trackCand << std::endl ; + delete trackCand; + continue; + + } else { + streamlog_out(DEBUG2) << "Keeping track because of good helix fit: chi2/ndf = " << chi2OverNdf << "\n"; } - } - catch( VXDHelixFitterException e ){ - - - streamlog_out( DEBUG2 ) << "Track rejected, because fit failed: " << e.what() << "\n"; + } catch (VXDHelixFitterException e) { + + streamlog_out(DEBUG2) << "Track rejected, because fit failed: " << e.what() << "\n"; delete trackCand; continue; - } - + /*-----------------------------------------------*/ /* Kalman Fit */ /*-----------------------------------------------*/ - - streamlog_out( DEBUG3 ) << "Fitting with Kalman Filter\n"; - try{ - + + streamlog_out(DEBUG3) << "Fitting with Kalman Filter\n"; + try { + trackCand->fit(); - streamlog_out( DEBUG3 ) << " Track " << trackCand - << " chi2Prob = " << trackCand->getChi2Prob() - << "( chi2=" << trackCand->getChi2() - <<", Ndf=" << trackCand->getNdf() << " )\n"; + streamlog_out(DEBUG3) << " Track " << trackCand << " chi2Prob = " << trackCand->getChi2Prob() + << "( chi2=" << trackCand->getChi2() << ", Ndf=" << trackCand->getNdf() << " )\n"; - + double test = trackCand->getChi2() / (1.0 * trackCand->getNdf()); // FIXME: give a less dull name to this var. YV + float NoOfHitsTimes2 = 2.0 * (trackCand->getHits().size()); - double test = trackCand->getChi2() / (1.0*trackCand->getNdf()) ; // FIXME: give a less dull name to this var. YV - float NoOfHitsTimes2 = 2.0*( trackCand->getHits().size()); + // if ( trackCand->getChi2Prob() >= _chi2ProbCut ){ + if (test < _chi2OverNdfCut) { - - //if ( trackCand->getChi2Prob() >= _chi2ProbCut ){ - if ( test < _chi2OverNdfCut ){ - - streamlog_out( DEBUG2 ) << "Track accepted (chi2prob " << trackCand->getChi2Prob() << " >= " << _chi2ProbCut << " chi2 over ndf " << test << " No of hits (x4) " << NoOfHitsTimes2 << " Overall sorting variable " << NoOfHitsTimes2/test << "\n"; - - } - else{ - - streamlog_out( DEBUG2 ) << "Track rejected (chi2prob " << trackCand->getChi2Prob() << " < " << _chi2ProbCut << " chi2 over ndf " << test << "\n"; + streamlog_out(DEBUG2) << "Track accepted (chi2prob " << trackCand->getChi2Prob() << " >= " << _chi2ProbCut + << " chi2 over ndf " << test << " No of hits (x4) " << NoOfHitsTimes2 + << " Overall sorting variable " << NoOfHitsTimes2 / test << "\n"; + + } else { - // debug - //streamlog_out(DEBUG4) << " Kalman fitting: deleting track " << trackCand << std::endl ; + streamlog_out(DEBUG2) << "Track rejected (chi2prob " << trackCand->getChi2Prob() << " < " << _chi2ProbCut + << " chi2 over ndf " << test << "\n"; - delete trackCand; - - continue; - + // debug + // streamlog_out(DEBUG4) << " Kalman fitting: deleting track " << trackCand << std::endl ; + + delete trackCand; + + continue; } - - - } - catch( FitterException e ){ - - streamlog_out( DEBUG4 ) << "Track rejected, because fit failed: " << e.what() << "\n"; + + } catch (FitterException e) { + + streamlog_out(DEBUG4) << "Track rejected, because fit failed: " << e.what() << "\n"; delete trackCand; continue; - } - - // Kalman fitting over //____________________________________________________________________________________________________________ + streamlog_out(DEBUG1) << "------------ trackCand = " << trackCand << "\n"; - streamlog_out( DEBUG1 ) << "------------ trackCand = " << trackCand << "\n"; - - trackCandidates.push_back( trackCand ); - + trackCandidates.push_back(trackCand); } - - - - // FTD like track fitting over. + + // FTD like track fitting over. //_________________________________________________________________________________________________ - - // establish the track collection that will be created - LCCollectionVec* trackVec = new LCCollectionVec( LCIO::TRACK ) ; - + // establish the track collection that will be created + LCCollectionVec* trackVec = new LCCollectionVec(LCIO::TRACK); + // if we want to point back to the hits we need to set the flag - LCFlagImpl trkFlag(0) ; - trkFlag.setBit( LCIO::TRBIT_HITS ) ; - trackVec->setFlag( trkFlag.getFlag() ) ; - + LCFlagImpl trkFlag(0); + trkFlag.setBit(LCIO::TRBIT_HITS); + trackVec->setFlag(trkFlag.getFlag()); // Selection of best consistent track subsample //************************************************************************************************************* + std::vector GoodTracks; + std::vector RejectedTracks; - - - std::vector< ITrack* > GoodTracks; - std::vector< ITrack* > RejectedTracks; - TrackCompatibilityShare1_MV comp; // Various ways to define the quality of a track. They are defined in the header file - //TrackQIChi2Prob_MV whatever; - //TrackQISpecial_MV JustDoIt ; - //TrackQI trackQI; - //MaxHits MaxLength; + // TrackQIChi2Prob_MV whatever; + // TrackQISpecial_MV JustDoIt ; + // TrackQI trackQI; + // MaxHits MaxLength; Test test; + streamlog_out(DEBUG4) << " best subset finder = " << _bestSubsetFinder << " no of tracks fed to the nnets " + << trackCandidates.size() << std::endl; - streamlog_out(DEBUG4) << " best subset finder = " << _bestSubsetFinder << " no of tracks fed to the nnets " << trackCandidates.size() << std::endl ; - - //FIX ME: implement properly HopfieldNN also + // FIX ME: implement properly HopfieldNN also /* - if( _bestSubsetFinder == "SubsetHopfieldNN" ){ - + if( _bestSubsetFinder == "SubsetHopfieldNN" ){ + streamlog_out(DEBUG4) << "Use SubsetHopfieldNN for getting the best subset\n" << std::endl ; - + SubsetHopfieldNN< ITrack* > subset_tracks ; subset_tracks.add( trackCandidates ); subset_tracks.calculateBestSet( comp, trackQI ); GoodTracks = subset_tracks.getAccepted(); RejectedTracks = subset_tracks.getRejected(); - + } */ + if (_bestSubsetFinder == "SubsetSimple") { - if( _bestSubsetFinder == "SubsetSimple" ){ - - - SubsetSimple< ITrack* > subset_tracks; - subset_tracks.add( trackCandidates ); - //subset_tracks.calculateBestSet( comp, trackQI ); - //subset_tracks.calculateBestSet( comp, MaxLength ); - subset_tracks.calculateBestSet( comp, test ); + SubsetSimple subset_tracks; + subset_tracks.add(trackCandidates); + // subset_tracks.calculateBestSet( comp, trackQI ); + // subset_tracks.calculateBestSet( comp, MaxLength ); + subset_tracks.calculateBestSet(comp, test); GoodTracks = subset_tracks.getAccepted(); RejectedTracks = subset_tracks.getRejected(); - } - - if ( _bestSubsetFinder == "NoSelection") { // in any other case take all tracks - - streamlog_out( DEBUG3 ) << "Input for subset = \"" << _bestSubsetFinder << "\". All tracks are kept\n" ; - GoodTracks = trackCandidates ; - + if (_bestSubsetFinder == "NoSelection") { // in any other case take all tracks + + streamlog_out(DEBUG3) << "Input for subset = \"" << _bestSubsetFinder << "\". All tracks are kept\n"; + GoodTracks = trackCandidates; } - - streamlog_out(DEBUG4) << "End of Sorting, Good tracks number: " << GoodTracks.size() << std::endl; - - + streamlog_out(DEBUG4) << "End of Sorting, Good tracks number: " << GoodTracks.size() << std::endl; + //****************************************************************************************************************** // best consistent track subsample selection ends here - // Finalise the tracks - for (unsigned int i=0; i < GoodTracks.size(); i++){ - - VXDTrack* myTrack = dynamic_cast< VXDTrack* >( GoodTracks[i] ); - - if ( myTrack != NULL ){ - - - TrackImpl* trackImpl = new TrackImpl( *(myTrack->getLcioTrack()) ); // possible leak - - try{ - - finaliseTrack( trackImpl ); - - // Applying a x2/ndf cut on final tracks - - if ( ((1.0*trackImpl->getChi2()) / (1.0*trackImpl->getNdf())) < 10.0 ) { - - trackVec->addElement( trackImpl ); - - streamlog_out( DEBUG0 ) << "DDCellsAutomatonMV: trackImpl added to trackVec\n"; - - } - } - - catch( FitterException e ){ - - streamlog_out( DEBUG4 ) << "DDCellsAutomatonMV: track couldn't be finalized due to fitter error: " << e.what() << "\n"; - delete trackImpl; - } + for (unsigned int i = 0; i < GoodTracks.size(); i++) { + + VXDTrack* myTrack = dynamic_cast(GoodTracks[i]); + + if (myTrack != NULL) { + + TrackImpl* trackImpl = new TrackImpl(*(myTrack->getLcioTrack())); // possible leak + + try { + + finaliseTrack(trackImpl); + + // Applying a x2/ndf cut on final tracks + + if (((1.0 * trackImpl->getChi2()) / (1.0 * trackImpl->getNdf())) < 10.0) { + + trackVec->addElement(trackImpl); + + streamlog_out(DEBUG0) << "DDCellsAutomatonMV: trackImpl added to trackVec\n"; + } + } + + catch (FitterException e) { + + streamlog_out(DEBUG4) << "DDCellsAutomatonMV: track couldn't be finalized due to fitter error: " << e.what() + << "\n"; + delete trackImpl; + } } } // Finalisation ends - streamlog_out( DEBUG4 ) << "DDCellsAutomatonMV: _CATrackCollection = "<< _CATrackCollection <<" trackVec->getNumberOfElements() = " << trackVec->getNumberOfElements() << "\n"; - - evt->addCollection( trackVec , _CATrackCollection) ; - + streamlog_out(DEBUG4) << "DDCellsAutomatonMV: _CATrackCollection = " << _CATrackCollection + << " trackVec->getNumberOfElements() = " << trackVec->getNumberOfElements() << "\n"; + evt->addCollection(trackVec, _CATrackCollection); /**********************************************************************************************/ /* Clean up */ /**********************************************************************************************/ - + // delete all the created IHits - for ( unsigned i=0; i 0 ) { - for ( unsigned i=0; i 0) { + for (unsigned i = 0; i < MiniVectorsTemp.size(); i++) { + delete MiniVectorsTemp[i]; + MiniVectorsTemp[i] = NULL; } } - if ( TestMiniVectorsTemp.size() > 0 ) { - for ( unsigned i=0; i 0) { + for (unsigned i = 0; i < TestMiniVectorsTemp.size(); i++) { + delete TestMiniVectorsTemp[i]; + TestMiniVectorsTemp[i] = NULL; } } // cleanup of tracks - //if ( _bestSubsetFinder != "NoSelection") for (unsigned int i=0; i < GoodTracks.size(); i++){ delete GoodTracks[i]; } - //for ( unsigned i=0; igetCollection(_VTXHitCollection.c_str()); - + + LCCollection* hitCollection = evt->getCollection(_VTXHitCollection.c_str()); + int nelem = hitCollection->getNumberOfElements(); - + streamlog_out(DEBUG4) << "Number of VTX hits = " << nelem << std::endl; - - for (int ielem=0; ielem(hitCollection->getElementAt(ielem)); - - dd4hep::rec::Vector3D U(1.0,hit->getU()[1],hit->getU()[0],dd4hep::rec::Vector3D::spherical); - dd4hep::rec::Vector3D V(1.0,hit->getV()[1],hit->getV()[0],dd4hep::rec::Vector3D::spherical); - dd4hep::rec::Vector3D Z(0.0,0.0,1.0); - + + for (int ielem = 0; ielem < nelem; ++ielem) { + + TrackerHitPlane* hit = dynamic_cast(hitCollection->getElementAt(ielem)); + + dd4hep::rec::Vector3D U(1.0, hit->getU()[1], hit->getU()[0], dd4hep::rec::Vector3D::spherical); + dd4hep::rec::Vector3D V(1.0, hit->getV()[1], hit->getV()[0], dd4hep::rec::Vector3D::spherical); + dd4hep::rec::Vector3D Z(0.0, 0.0, 1.0); + const float eps = 1.0e-07; - // V must be the global z axis - if( fabs(1.0 - V.dot(Z)) > eps ) { - streamlog_out(ERROR) << "SiTrkHopfieldNN: VXD Hit measurment vectors V is not equal to the global Z axis. \n\n exit(1) called from file " << __FILE__ << " and line " << __LINE__ << std::endl; + // V must be the global z axis + if (fabs(1.0 - V.dot(Z)) > eps) { + streamlog_out(ERROR) << "SiTrkHopfieldNN: VXD Hit measurment vectors V is not equal to the global Z axis. \n\n " + " exit(1) called from file " + << __FILE__ << " and line " << __LINE__ << std::endl; exit(1); } - - if( fabs(U.dot(Z)) > eps ) { - streamlog_out(ERROR) << "SiTrkHopfieldNN: VXD Hit measurment vectors U is not in the global X-Y plane. \n\n exit(1) called from file " << __FILE__ << " and line " << __LINE__ << std::endl; + + if (fabs(U.dot(Z)) > eps) { + streamlog_out(ERROR) << "SiTrkHopfieldNN: VXD Hit measurment vectors U is not in the global X-Y plane. \n\n " + "exit(1) called from file " + << __FILE__ << " and line " << __LINE__ << std::endl; exit(1); } double pos[3]; double radius = 0; - for (int i=0; i<3; ++i) { + for (int i = 0; i < 3; ++i) { pos[i] = hit->getPosition()[i]; - radius += pos[i]*pos[i]; + radius += pos[i] * pos[i]; } - radius = sqrt(radius); - double cosTheta = pos[2]/radius; - double Phi = atan2(pos[1],pos[0]); - + double cosTheta = pos[2] / radius; + double Phi = atan2(pos[1], pos[0]); + + if (Phi < 0.) + Phi = Phi + TWOPI; - if (Phi < 0.) Phi = Phi + TWOPI; - // get the layer number - int celId = hit->getCellID0() ; + int celId = hit->getCellID0(); - UTIL::BitField64 encoder( lcio::LCTrackerCellID::encoding_string() ) ; - encoder.setValue(celId) ; - int layer = encoder[lcio::LCTrackerCellID::layer()] + 1 ; // +1 cause IP is considered layer 0 + UTIL::BitField64 encoder(lcio::LCTrackerCellID::encoding_string()); + encoder.setValue(celId); + int layer = encoder[lcio::LCTrackerCellID::layer()] + 1; // +1 cause IP is considered layer 0 - int iPhi = int(Phi/_dPhi); - int iTheta = int ((cosTheta + double(1.0))/_dTheta); - int iCode = layer + _nLayers*iPhi + _nLayers*_nDivisionsInPhi*iTheta; + int iPhi = int(Phi / _dPhi); + int iTheta = int((cosTheta + double(1.0)) / _dTheta); + int iCode = layer + _nLayers * iPhi + _nLayers * _nDivisionsInPhi * iTheta; - streamlog_out(DEBUG4) << " CA: making a VXD hit at layer " << layer << " phi sector " << iPhi << " theta sector " << iTheta << " theta angle " << acos(cosTheta)*(180.0/M_PI) << " sector code " << iCode << " total layers " << _nLayers << " no of phi sectors " << _nDivisionsInPhi << " no of theta sectors " << _nDivisionsInTheta << std::endl ; + streamlog_out(DEBUG4) << " CA: making a VXD hit at layer " << layer << " phi sector " << iPhi << " theta sector " + << iTheta << " theta angle " << acos(cosTheta) * (180.0 / M_PI) << " sector code " << iCode + << " total layers " << _nLayers << " no of phi sectors " << _nDivisionsInPhi + << " no of theta sectors " << _nDivisionsInTheta << std::endl; - - //Make an VXDHit01 from the TrackerHit - //VXDHit01* vxdHit = new VXDHit01 ( hit , _sectorSystemVXD ); // Don't need to create VXDHits, we stick to mini - vectors - HitsTemp.push_back(hit); //so we can easily delete every created hit afterwards - - _map_sector_spacepoints[ iCode ].push_back( hit ); + // Make an VXDHit01 from the TrackerHit + // VXDHit01* vxdHit = new VXDHit01 ( hit , _sectorSystemVXD ); // Don't need to create VXDHits, we stick to mini + // - vectors + HitsTemp.push_back(hit); // so we can easily delete every created hit afterwards + _map_sector_spacepoints[iCode].push_back(hit); } } - catch(DataNotAvailableException &e) { - streamlog_out( DEBUG4 ) << " collection not found : " << _VTXHitCollection.c_str() << std::endl ; + catch (DataNotAvailableException& e) { + streamlog_out(DEBUG4) << " collection not found : " << _VTXHitCollection.c_str() << std::endl; } - + //________________________________________________________________________________________________________________ - // readout of SIT collection | + // readout of SIT collection | //_______________________________________________________________________________________________________________| - - if ( _useSIT == 1 ){ - + + if (_useSIT == 1) { + try { - LCCollection *hitCollection = evt->getCollection(_SITHitCollection.c_str()); - + LCCollection* hitCollection = evt->getCollection(_SITHitCollection.c_str()); + int nelem = hitCollection->getNumberOfElements(); - + streamlog_out(DEBUG4) << "Number of SIT hits = " << nelem << std::endl; - - TrackerHit* trkhit = 0; - TrackerHitPlane* trkhit_P = 0; + + TrackerHit* trkhit = 0; + TrackerHitPlane* trkhit_P = 0; TrackerHitZCylinder* trkhit_C = 0; - - //double drphi(NAN); - //double dz(NAN); - - for (int ielem=0; ielem(hitCollection->getElementAt(ielem)); - - int celId_SIT = trkhit->getCellID0() ; - - UTIL::BitField64 encoder( lcio::LCTrackerCellID::encoding_string() ) ; - encoder.setValue(celId_SIT) ; - int layer = encoder[lcio::LCTrackerCellID::layer()] + 1 ; // + 1 cause IP is considered layer 0 - - // VXD and SIT are treated as one system so SIT layers start from _nLayersVTX - layer = layer + _nLayersVTX; - - if (layer < 0 || layer >= _nLayers) { - streamlog_out(ERROR) << "SiliconTracking_MarlinTrk => fatal error in SIT : layer is outside allowed range : " << layer << std::endl; + + // double drphi(NAN); + // double dz(NAN); + + for (int ielem = 0; ielem < nelem; ++ielem) { + + // hit could be of the following type + // 1) TrackerHit, either ILDTrkHitTypeBit::COMPOSITE_SPACEPOINT or just standard TrackerHit + // 2) TrackerHitPlane, either 1D or 2D + // 3) TrackerHitZCylinder, if coming from a simple cylinder design as in the LOI + + // Establish which of these it is in the following order of likelyhood + // i) ILDTrkHitTypeBit::ONE_DIMENSIONAL (TrackerHitPlane) Should Never Happen: SpacePoints Must be Used + // Instead ii) ILDTrkHitTypeBit::COMPOSITE_SPACEPOINT (TrackerHit) iii) TrackerHitPlane (Two dimentional) + // iv) TrackerHitZCylinder + // v) Must be standard TrackerHit + + trkhit = dynamic_cast(hitCollection->getElementAt(ielem)); + + int celId_SIT = trkhit->getCellID0(); + + UTIL::BitField64 encoder(lcio::LCTrackerCellID::encoding_string()); + encoder.setValue(celId_SIT); + int layer = encoder[lcio::LCTrackerCellID::layer()] + 1; // + 1 cause IP is considered layer 0 + + // VXD and SIT are treated as one system so SIT layers start from _nLayersVTX + layer = layer + _nLayersVTX; + + if (layer < 0 || layer >= _nLayers) { + streamlog_out(ERROR) << "SiliconTracking_MarlinTrk => fatal error in SIT : layer is outside allowed range : " + << layer << std::endl; exit(1); - } - - // first check that we have not been given 1D hits by mistake, as they won't work here - if ( BitSet32( trkhit->getType() )[ UTIL::ILDTrkHitTypeBit::ONE_DIMENSIONAL ] ) { - - streamlog_out(ERROR) << "SiliconTracking_MarlinTrk: SIT Hit cannot be of type UTIL::ILDTrkHitTypeBit::ONE_DIMENSIONAL COMPOSITE SPACEPOINTS must be use instead. \n\n exit(1) called from file " << __FILE__ << " and line " << __LINE__ << std::endl; - exit(1); - - } - // most likely case: COMPOSITE_SPACEPOINT hits formed from stereo strip hits - else if ( BitSet32( trkhit->getType() )[ UTIL::ILDTrkHitTypeBit::COMPOSITE_SPACEPOINT ] ) { - - streamlog_out(DEBUG1) << " We deal with composite spacepoints " << std::endl ; - - //drphi = 2 * sqrt(trkhit->getCovMatrix()[0] + trkhit->getCovMatrix()[2]); - //dz = sqrt(trkhit->getCovMatrix()[5]); - - } - // or a PIXEL based SIT, using 2D TrackerHitPlane like the VXD above - else if ( ( trkhit_P = dynamic_cast( hitCollection->getElementAt( ielem ) ) ) ) { - - // first we need to check if the measurement vectors are aligned with the global coordinates - dd4hep::rec::Vector3D U(1.0,trkhit_P->getU()[1],trkhit_P->getU()[0],dd4hep::rec::Vector3D::spherical); - dd4hep::rec::Vector3D V(1.0,trkhit_P->getV()[1],trkhit_P->getV()[0],dd4hep::rec::Vector3D::spherical); - dd4hep::rec::Vector3D Z(0.0,0.0,1.0); - - - const float eps = 1.0e-07; - // V must be the global z axis - if( fabs(1.0 - V.dot(Z)) > eps ) { - streamlog_out(ERROR) << "SiliconTracking_MarlinTrk: PIXEL SIT Hit measurment vectors V is not equal to the global Z axis. \n\n exit(1) called from file " << __FILE__ << " and line " << __LINE__ << std::endl; - exit(1); - } - - // U must be normal to the global z axis - if( fabs(U.dot(Z)) > eps ) { - streamlog_out(ERROR) << "SiliconTracking_MarlinTrk: PIXEL SIT Hit measurment vectors U is not in the global X-Y plane. \n\n exit(1) called from file " << __FILE__ << " and line " << __LINE__ << std::endl; - exit(1); - } - - //drphi = trkhit_P->getdU(); - //dz = trkhit_P->getdV(); - - } - // or a simple cylindrical design, as used in the LOI - else if ( ( trkhit_C = dynamic_cast( hitCollection->getElementAt( ielem ) ) ) ) { - - //drphi = trkhit_C->getdRPhi(); - //dz = trkhit_C->getdZ(); - - } - // this would be very unlikely, but who knows ... just an ordinary TrackerHit, which is not a COMPOSITE_SPACEPOINT - else { - - //drphi = 2 * sqrt(trkhit->getCovMatrix()[0] + trkhit->getCovMatrix()[2]); - //dz = sqrt(trkhit->getCovMatrix()[5]); - - } - - double pos[3]; - double radius = 0; - - - for (int i=0; i<3; ++i) { - pos[i] = trkhit->getPosition()[i]; - radius += pos[i]*pos[i]; - } - - radius = sqrt(radius); - - double cosTheta = pos[2]/radius; - double Phi = atan2(pos[1],pos[0]); - - if (Phi < 0.) Phi = Phi + TWOPI; - - int iPhi = int(Phi/_dPhi); - int iTheta = int ((cosTheta + double(1.0))/_dTheta); - int iCode = layer + _nLayers*iPhi + _nLayers*_nDivisionsInPhi*iTheta; - - - streamlog_out(DEBUG2) << " CA: making an SIT hit at layer " << layer << " phi sector " << iPhi << " theta sector " << iTheta << " sector code " << iCode << " total layers " << _nLayers << " no of phi sectors " << _nDivisionsInPhi << std::endl ; - - //Make an VXDHit01 from the TrackerHit - //VXDHit01* vxdHit = new VXDHit01 ( trkhit , _sectorSystemVXD ); // Don't need to create VXDHits, we stick to mini - vectors - HitsTemp.push_back(trkhit); //so we can easily delete every created hit afterwards - - _map_sector_spacepoints[ iCode ].push_back( trkhit ); - - } - - } catch(DataNotAvailableException &e) { - streamlog_out( DEBUG4 ) << " collection not found : " << _SITHitCollection.c_str() << std::endl ; - } - } - + } + // first check that we have not been given 1D hits by mistake, as they won't work here + if (BitSet32(trkhit->getType())[UTIL::ILDTrkHitTypeBit::ONE_DIMENSIONAL]) { -} + streamlog_out(ERROR) + << "SiliconTracking_MarlinTrk: SIT Hit cannot be of type UTIL::ILDTrkHitTypeBit::ONE_DIMENSIONAL " + "COMPOSITE SPACEPOINTS must be use instead. \n\n exit(1) called from file " + << __FILE__ << " and line " << __LINE__ << std::endl; + exit(1); + + } + // most likely case: COMPOSITE_SPACEPOINT hits formed from stereo strip hits + else if (BitSet32(trkhit->getType())[UTIL::ILDTrkHitTypeBit::COMPOSITE_SPACEPOINT]) { + + streamlog_out(DEBUG1) << " We deal with composite spacepoints " << std::endl; + + // drphi = 2 * sqrt(trkhit->getCovMatrix()[0] + trkhit->getCovMatrix()[2]); + // dz = sqrt(trkhit->getCovMatrix()[5]); + + } + // or a PIXEL based SIT, using 2D TrackerHitPlane like the VXD above + else if ((trkhit_P = dynamic_cast(hitCollection->getElementAt(ielem)))) { + + // first we need to check if the measurement vectors are aligned with the global coordinates + dd4hep::rec::Vector3D U(1.0, trkhit_P->getU()[1], trkhit_P->getU()[0], dd4hep::rec::Vector3D::spherical); + dd4hep::rec::Vector3D V(1.0, trkhit_P->getV()[1], trkhit_P->getV()[0], dd4hep::rec::Vector3D::spherical); + dd4hep::rec::Vector3D Z(0.0, 0.0, 1.0); + + const float eps = 1.0e-07; + // V must be the global z axis + if (fabs(1.0 - V.dot(Z)) > eps) { + streamlog_out(ERROR) << "SiliconTracking_MarlinTrk: PIXEL SIT Hit measurment vectors V is not equal to the " + "global Z axis. \n\n exit(1) called from file " + << __FILE__ << " and line " << __LINE__ << std::endl; + exit(1); + } + + // U must be normal to the global z axis + if (fabs(U.dot(Z)) > eps) { + streamlog_out(ERROR) << "SiliconTracking_MarlinTrk: PIXEL SIT Hit measurment vectors U is not in the " + "global X-Y plane. \n\n exit(1) called from file " + << __FILE__ << " and line " << __LINE__ << std::endl; + exit(1); + } + + // drphi = trkhit_P->getdU(); + // dz = trkhit_P->getdV(); + } + // or a simple cylindrical design, as used in the LOI + else if ((trkhit_C = dynamic_cast(hitCollection->getElementAt(ielem)))) { + // drphi = trkhit_C->getdRPhi(); + // dz = trkhit_C->getdZ(); + + } + // this would be very unlikely, but who knows ... just an ordinary TrackerHit, which is not a + // COMPOSITE_SPACEPOINT + else { + + // drphi = 2 * sqrt(trkhit->getCovMatrix()[0] + trkhit->getCovMatrix()[2]); + // dz = sqrt(trkhit->getCovMatrix()[5]); + } + + double pos[3]; + double radius = 0; + + for (int i = 0; i < 3; ++i) { + pos[i] = trkhit->getPosition()[i]; + radius += pos[i] * pos[i]; + } + + radius = sqrt(radius); + + double cosTheta = pos[2] / radius; + double Phi = atan2(pos[1], pos[0]); + + if (Phi < 0.) + Phi = Phi + TWOPI; + + int iPhi = int(Phi / _dPhi); + int iTheta = int((cosTheta + double(1.0)) / _dTheta); + int iCode = layer + _nLayers * iPhi + _nLayers * _nDivisionsInPhi * iTheta; + + streamlog_out(DEBUG2) << " CA: making an SIT hit at layer " << layer << " phi sector " << iPhi + << " theta sector " << iTheta << " sector code " << iCode << " total layers " << _nLayers + << " no of phi sectors " << _nDivisionsInPhi << std::endl; + + // Make an VXDHit01 from the TrackerHit + // VXDHit01* vxdHit = new VXDHit01 ( trkhit , _sectorSystemVXD ); // Don't need to create VXDHits, we stick to + // mini - vectors + HitsTemp.push_back(trkhit); // so we can easily delete every created hit afterwards + + _map_sector_spacepoints[iCode].push_back(trkhit); + } + + } catch (DataNotAvailableException& e) { + streamlog_out(DEBUG4) << " collection not found : " << _SITHitCollection.c_str() << std::endl; + } + } +} //________________________________________________________________________________________________________ // | -// Create all possible mini-vectors of the sector | +// Create all possible mini-vectors of the sector | // | //-------------------------------------------------------------------------------------------------------- // Taking the hits on the outer side of each VXD double layer we try to connect them with hits on the inner side. -// The connections considered valid if it satisfies a condition (for example the dtheta difference of the hits or their -// distance didvided with the distance of the two sides of the layer. The search is confined in a number of target sectors -// of the inner side of the VXD layer. +// The connections considered valid if it satisfies a condition (for example the dtheta difference of the hits or their +// distance didvided with the distance of the two sides of the layer. The search is confined in a number of target +// sectors of the inner side of the VXD layer. -void DDCellsAutomatonMV::CreateMiniVectors( int sector ) { +void DDCellsAutomatonMV::CreateMiniVectors(int sector) { - int thisTheta = sector/(_nLayers*_nDivisionsInPhi) ; - int thisPhi = ((sector - (thisTheta*_nLayers*_nDivisionsInPhi)) / _nLayers) ; - int layer = sector - (thisTheta*_nLayers*_nDivisionsInPhi) - (thisPhi*_nLayers) ; + int thisTheta = sector / (_nLayers * _nDivisionsInPhi); + int thisPhi = ((sector - (thisTheta * _nLayers * _nDivisionsInPhi)) / _nLayers); + int layer = sector - (thisTheta * _nLayers * _nDivisionsInPhi) - (thisPhi * _nLayers); - streamlog_out(DEBUG4) << " Taking sector " << sector << " of layer " << layer << " Phi sector " << thisPhi << " Theta sector " << thisTheta << std::endl ; + streamlog_out(DEBUG4) << " Taking sector " << sector << " of layer " << layer << " Phi sector " << thisPhi + << " Theta sector " << thisTheta << std::endl; - int iPhi_Up = thisPhi + 2; - int iPhi_Low = thisPhi - 2; - int iTheta_Up = thisTheta + 2; + int iPhi_Up = thisPhi + 2; + int iPhi_Low = thisPhi - 2; + int iTheta_Up = thisTheta + 2; int iTheta_Low = thisTheta - 2; - if (iTheta_Low < 0) iTheta_Low = 0; - if (iTheta_Up >= _nDivisionsInTheta) iTheta_Up = _nDivisionsInTheta-1; + if (iTheta_Low < 0) + iTheta_Low = 0; + if (iTheta_Up >= _nDivisionsInTheta) + iTheta_Up = _nDivisionsInTheta - 1; TrackerHitVec VXDHits = _map_sector_spacepoints[sector]; - - for (TrackerHitVec::iterator iter=VXDHits.begin(); iter!=VXDHits.end(); ++iter) { - - TrackerHit *fromHit = *iter ; // Starting hit - - streamlog_out(DEBUG2) << " hit to initiate a MV: " << fromHit << std::endl ; - - int celID = fromHit->getCellID0() ; - int detID = 0 ; - //int layerID = 0 ; - - UTIL::BitField64 encoder( lcio::LCTrackerCellID::encoding_string() ) ; - encoder.reset() ; // reset to 0 - encoder.setValue(celID) ; - - detID = encoder[lcio::LCTrackerCellID::subdet()] ; - - layer = encoder[lcio::LCTrackerCellID::layer()] + 1 ; // + 1 if we consider the IP hit - - if (detID==lcio::ILDDetID::VXD ){ - - //if (layer==5 || layer==3 || layer==1) { - if (layer==6 || layer==4 || layer==2) { // in case of considering an IP hit - - for (int iPhi = iPhi_Low ; iPhi < iPhi_Up ; iPhi++){ - - - // construct mini-vectors applying a delta theta cut - //*************************************************************************** - - int iTheta_Up_mod = thisTheta + 2; - int iTheta_Low_mod = thisTheta - 2; - if (iTheta_Low_mod < 0) iTheta_Low_mod = 0; - if (iTheta_Up_mod >= _nDivisionsInTheta) iTheta_Up_mod = _nDivisionsInTheta-1; - - - for (int iTheta = iTheta_Low_mod ; iTheta < iTheta_Up_mod ; iTheta++){ - - int target_sector = ( layer-1) + _nLayers*iPhi + _nLayers*_nDivisionsInPhi*iTheta ; - TrackerHitVec targetHitsMod = _map_sector_spacepoints[target_sector]; - - streamlog_out(DEBUG2) << " Checking with TARGET sector " << target_sector << " of layer " << layer-1 << " Phi sector " << iPhi << " Theta sector " << iTheta << std::endl ; - - streamlog_out(DEBUG2) << " No of hits in the sector " << targetHitsMod.size() << std::endl ; - - for (TrackerHitVec::iterator iterMod=targetHitsMod.begin(); iterMod!=targetHitsMod.end(); ++iterMod) { - - TrackerHit *toHitMod = *iterMod ; // Candidate hit to form a mini - vector with the starting hit - - if (thetaAgreementImproved(toHitMod,fromHit,layer) == true){ - - MiniVector *testMiniVectorMod = new MiniVector(fromHit,toHitMod) ; - MiniVectorHit01* miniVectorHitMod = new MiniVectorHit01( testMiniVectorMod , _sectorSystemVXD ); - MiniVectors_CutSelection++; - _map_sector_hits[ sector ].push_back( miniVectorHitMod ); - - streamlog_out(DEBUG2) << " making the VXD mini-vector hit " << miniVectorHitMod << " at sector " << sector << std::endl ; - - MiniVectorsTemp.push_back(miniVectorHitMod); - TestMiniVectorsTemp.push_back(testMiniVectorMod); - - } - } - - targetHitsMod.clear(); - - } - } - } - } // end of VXD hits - creation of mini-vectors + for (TrackerHitVec::iterator iter = VXDHits.begin(); iter != VXDHits.end(); ++iter) { + + TrackerHit* fromHit = *iter; // Starting hit + + streamlog_out(DEBUG2) << " hit to initiate a MV: " << fromHit << std::endl; + + int celID = fromHit->getCellID0(); + int detID = 0; + // int layerID = 0 ; + UTIL::BitField64 encoder(lcio::LCTrackerCellID::encoding_string()); + encoder.reset(); // reset to 0 + encoder.setValue(celID); + + detID = encoder[lcio::LCTrackerCellID::subdet()]; + + layer = encoder[lcio::LCTrackerCellID::layer()] + 1; // + 1 if we consider the IP hit + + if (detID == lcio::ILDDetID::VXD) { + + // if (layer==5 || layer==3 || layer==1) { + if (layer == 6 || layer == 4 || layer == 2) { // in case of considering an IP hit + + for (int iPhi = iPhi_Low; iPhi < iPhi_Up; iPhi++) { + + // construct mini-vectors applying a delta theta cut + //*************************************************************************** + + int iTheta_Up_mod = thisTheta + 2; + int iTheta_Low_mod = thisTheta - 2; + if (iTheta_Low_mod < 0) + iTheta_Low_mod = 0; + if (iTheta_Up_mod >= _nDivisionsInTheta) + iTheta_Up_mod = _nDivisionsInTheta - 1; + + for (int iTheta = iTheta_Low_mod; iTheta < iTheta_Up_mod; iTheta++) { + + int target_sector = (layer - 1) + _nLayers * iPhi + _nLayers * _nDivisionsInPhi * iTheta; + TrackerHitVec targetHitsMod = _map_sector_spacepoints[target_sector]; + + streamlog_out(DEBUG2) << " Checking with TARGET sector " << target_sector << " of layer " << layer - 1 + << " Phi sector " << iPhi << " Theta sector " << iTheta << std::endl; + + streamlog_out(DEBUG2) << " No of hits in the sector " << targetHitsMod.size() << std::endl; + + for (TrackerHitVec::iterator iterMod = targetHitsMod.begin(); iterMod != targetHitsMod.end(); ++iterMod) { + + TrackerHit* toHitMod = *iterMod; // Candidate hit to form a mini - vector with the starting hit + + if (thetaAgreementImproved(toHitMod, fromHit, layer) == true) { + + MiniVector* testMiniVectorMod = new MiniVector(fromHit, toHitMod); + MiniVectorHit01* miniVectorHitMod = new MiniVectorHit01(testMiniVectorMod, _sectorSystemVXD); + MiniVectors_CutSelection++; + _map_sector_hits[sector].push_back(miniVectorHitMod); + + streamlog_out(DEBUG2) << " making the VXD mini-vector hit " << miniVectorHitMod << " at sector " + << sector << std::endl; + + MiniVectorsTemp.push_back(miniVectorHitMod); + TestMiniVectorsTemp.push_back(testMiniVectorMod); + } + } + + targetHitsMod.clear(); + } + } + } + } // end of VXD hits - creation of mini-vectors - // **** SIT **** + // **** SIT **** // We don't use SIT for time being. FIX ME - if ( _useSIT == 1 ){ - if (detID==lcio::ILDDetID::SIT){ - - layer = layer + _nLayersVTX; - - //if (layer==8) { - if (layer==7 || layer==9) { - - - //double from_x = fromHit->getPosition()[0] ; - //double from_y = fromHit->getPosition()[1] ; - - for (int iPhi = iPhi_Low ; iPhi < iPhi_Up ; iPhi++){ - - int iTheta_Up_mod = thisTheta + 10; - int iTheta_Low_mod = thisTheta - 10; - if (iTheta_Low_mod < 0) iTheta_Low_mod = 0; - if (iTheta_Up_mod >= _nDivisionsInTheta) iTheta_Up_mod = _nDivisionsInTheta-1; - - for (int iTheta = iTheta_Low ; iTheta < iTheta_Up ; iTheta++){ - - int target_sector = ( layer-1) + _nLayers*iPhi + _nLayers*_nDivisionsInPhi*iTheta ; - - //double ThetaAngle = acos(((2*iTheta)/(_nDivisionsInTheta*1.0)) - 1); - - TrackerHitVec targetHits = _map_sector_spacepoints[target_sector]; - - streamlog_out(DEBUG3) << " How many hits on the target sector " << targetHits.size() << std::endl ; - - for (TrackerHitVec::iterator iter2=targetHits.begin(); iter2!=targetHits.end(); ++iter2) { - - TrackerHit *toHit = *iter2 ; - - if ( Dist(fromHit,toHit) < _maxDist ){ - - MiniVector *sitTestMiniVector = new MiniVector(fromHit,toHit) ; - MiniVectorHit01* sitMiniVectorHit = new MiniVectorHit01( sitTestMiniVector , _sectorSystemVXD ); - - streamlog_out(DEBUG4) << " making a SIT mini-vector hit at sector " << sector << std::endl ; - - //MiniVectors_sectors++; - - _map_sector_hits[ sector ].push_back( sitMiniVectorHit ); - } - } - - targetHits.clear(); - } - } - } - } - } - + if (_useSIT == 1) { + if (detID == lcio::ILDDetID::SIT) { - - } // end of looping on VXD - SIT trackerhits - - VXDHits.clear(); - -} + layer = layer + _nLayersVTX; + + // if (layer==8) { + if (layer == 7 || layer == 9) { + + // double from_x = fromHit->getPosition()[0] ; + // double from_y = fromHit->getPosition()[1] ; + + for (int iPhi = iPhi_Low; iPhi < iPhi_Up; iPhi++) { + + int iTheta_Up_mod = thisTheta + 10; + int iTheta_Low_mod = thisTheta - 10; + if (iTheta_Low_mod < 0) + iTheta_Low_mod = 0; + if (iTheta_Up_mod >= _nDivisionsInTheta) + iTheta_Up_mod = _nDivisionsInTheta - 1; + + for (int iTheta = iTheta_Low; iTheta < iTheta_Up; iTheta++) { + + int target_sector = (layer - 1) + _nLayers * iPhi + _nLayers * _nDivisionsInPhi * iTheta; + // double ThetaAngle = acos(((2*iTheta)/(_nDivisionsInTheta*1.0)) - 1); + TrackerHitVec targetHits = _map_sector_spacepoints[target_sector]; + streamlog_out(DEBUG3) << " How many hits on the target sector " << targetHits.size() << std::endl; + for (TrackerHitVec::iterator iter2 = targetHits.begin(); iter2 != targetHits.end(); ++iter2) { -void DDCellsAutomatonMV::setupGeom(){ + TrackerHit* toHit = *iter2; + + if (Dist(fromHit, toHit) < _maxDist) { + + MiniVector* sitTestMiniVector = new MiniVector(fromHit, toHit); + MiniVectorHit01* sitMiniVectorHit = new MiniVectorHit01(sitTestMiniVector, _sectorSystemVXD); + + streamlog_out(DEBUG4) << " making a SIT mini-vector hit at sector " << sector << std::endl; + + // MiniVectors_sectors++; + + _map_sector_hits[sector].push_back(sitMiniVectorHit); + } + } + + targetHits.clear(); + } + } + } + } + } + + } // end of looping on VXD - SIT trackerhits + + VXDHits.clear(); +} + +void DDCellsAutomatonMV::setupGeom() { dd4hep::Detector& theDetector = dd4hep::Detector::getInstance(); - const double pos[3]={0,0,0}; - double bFieldVec[3]={0,0,0}; - theDetector.field().magneticField(pos,bFieldVec); // get the magnetic field vector from DD4hep - _bField = bFieldVec[2]/dd4hep::tesla; // z component at (0,0,0) + const double pos[3] = {0, 0, 0}; + double bFieldVec[3] = {0, 0, 0}; + theDetector.field().magneticField(pos, bFieldVec); // get the magnetic field vector from DD4hep + _bField = bFieldVec[2] / dd4hep::tesla; // z component at (0,0,0) - _nLayersVTX = 0; + _nLayersVTX = 0; dd4hep::DetElement vtxDE = theDetector.detector(_detElVXDName); dd4hep::rec::ZPlanarData* vtx = vtxDE.extension(); - _nLayersVTX=vtx->layers.size(); - + _nLayersVTX = vtx->layers.size(); _nLayersSIT = 0; int nIT = 0; dd4hep::DetElement itDE = theDetector.detector(_detElITName); dd4hep::rec::ZPlanarData* it = itDE.extension(); - nIT=it->layers.size(); + nIT = it->layers.size(); int nOT = 0; dd4hep::DetElement otDE = theDetector.detector(_detElOTName); dd4hep::rec::ZPlanarData* ot = otDE.extension(); - nOT=ot->layers.size(); - - _nLayersSIT = nIT + nOT; - - streamlog_out( DEBUG0 ) << "###setupGeom: _bField = " << _bField << std::endl ; - streamlog_out( DEBUG0 ) << "###setupGeom: _nLayersVTX = " << _nLayersVTX << std::endl ; - streamlog_out( DEBUG0 ) << "###setupGeom: _nLayersSilicon (Inner + Outer) = " << _nLayersSIT << std::endl ; - - -} + nOT = ot->layers.size(); + _nLayersSIT = nIT + nOT; -bool DDCellsAutomatonMV::setCriteria( unsigned round ){ - - // delete the old ones - for ( unsigned i=0; i< _crit2Vec.size(); i++) delete _crit2Vec[i]; - for ( unsigned i=0; i< _crit3Vec.size(); i++) delete _crit3Vec[i]; - for ( unsigned i=0; i< _crit4Vec.size(); i++) delete _crit4Vec[i]; - _crit2Vec.clear(); - _crit3Vec.clear(); - _crit4Vec.clear(); - - streamlog_out(DEBUG4) << " Calling setCriteria function - criteria vector size = " << _criteriaNames.size() << std::endl ; - - bool newValuesGotUsed = false; // if new values are used - - for( unsigned i=0; i<_criteriaNames.size(); i++ ){ - - std::string critName = _criteriaNames[i]; - - - float min = _critMinima[critName].back(); - float max = _critMaxima[critName].back(); - - streamlog_out(DEBUG4) << " iterator " << i << " criterio " << critName << " min. value " << min << " max. value " << max << std::endl ; - - // use the value corresponding to the round, if there are no new ones for this criterion, just do nothing (the previous value stays in place) - if( round + 1 <= _critMinima[critName].size() ){ - - min = _critMinima[critName][round]; - newValuesGotUsed = true; - - } - - if( round + 1 <= _critMaxima[critName].size() ){ - - max = _critMaxima[critName][round]; - newValuesGotUsed = true; - - } - - ICriterion* crit = Criteria::createCriterion( critName, min , max ); - - // Some debug output about the created criterion - std::string type = crit->getType(); - - streamlog_out(DEBUG4) << "Added: Criterion " << critName << " (type = " << type - << " ). Min = " << min - << ", Max = " << max - << ", round " << round << "\n"; - - - // Add the new criterion to the corresponding vector - if( type == "2Hit" ){ - - _crit2Vec.push_back( crit ); - - } - else if( type == "3Hit" ){ - - _crit3Vec.push_back( crit ); - - } - else if( type == "4Hit" ){ - - _crit4Vec.push_back( crit ); - - } - else delete crit; - - - } - - return newValuesGotUsed; - - + streamlog_out(DEBUG0) << "###setupGeom: _bField = " << _bField << std::endl; + streamlog_out(DEBUG0) << "###setupGeom: _nLayersVTX = " << _nLayersVTX << std::endl; + streamlog_out(DEBUG0) << "###setupGeom: _nLayersSilicon (Inner + Outer) = " << _nLayersSIT << std::endl; } +bool DDCellsAutomatonMV::setCriteria(unsigned round) { + + // delete the old ones + for (unsigned i = 0; i < _crit2Vec.size(); i++) + delete _crit2Vec[i]; + for (unsigned i = 0; i < _crit3Vec.size(); i++) + delete _crit3Vec[i]; + for (unsigned i = 0; i < _crit4Vec.size(); i++) + delete _crit4Vec[i]; + _crit2Vec.clear(); + _crit3Vec.clear(); + _crit4Vec.clear(); + + streamlog_out(DEBUG4) << " Calling setCriteria function - criteria vector size = " << _criteriaNames.size() + << std::endl; + + bool newValuesGotUsed = false; // if new values are used + + for (unsigned i = 0; i < _criteriaNames.size(); i++) { + + std::string critName = _criteriaNames[i]; + + float min = _critMinima[critName].back(); + float max = _critMaxima[critName].back(); + + streamlog_out(DEBUG4) << " iterator " << i << " criterio " << critName << " min. value " << min << " max. value " + << max << std::endl; + + // use the value corresponding to the round, if there are no new ones for this criterion, just do nothing (the + // previous value stays in place) + if (round + 1 <= _critMinima[critName].size()) { -void DDCellsAutomatonMV::finaliseTrack( TrackImpl* trackImpl ){ - - - //Fitter fitter( trackImpl , _trkSystem ); //it gives problem at 90deg: sometimes the hits are taken in the inverse order resulting in a fitted track in the opposite quadrant of the hits - Fitter fitter( trackImpl , _trkSystem , 1); //it forces the hits ordering according to the radius (problem for very bent tracks that are coming back - TO STUDY) - - - trackImpl->trackStates().clear(); - - - TrackStateImpl* trkStateIP = new TrackStateImpl( *fitter.getTrackState( lcio::TrackState::AtIP ) ) ; - trkStateIP->setLocation( TrackState::AtIP ); - trackImpl->addTrackState( trkStateIP ); - - TrackStateImpl* trkStateFirstHit = new TrackStateImpl( *fitter.getTrackState( TrackState::AtFirstHit ) ) ; - trkStateFirstHit->setLocation( TrackState::AtFirstHit ); - trackImpl->addTrackState( trkStateFirstHit ); - - TrackStateImpl* trkStateLastHit = new TrackStateImpl( *fitter.getTrackState( TrackState::AtLastHit ) ) ; - trkStateLastHit->setLocation( TrackState::AtLastHit ); - trackImpl->addTrackState( trkStateLastHit ); - - - // TrackStateImpl* trkStateAtCalo = new TrackStateImpl( *fitter.getTrackState( TrackState::AtCalorimeter ) ) ; - // trkStateAtCalo->setLocation( TrackState::AtCalorimeter ); - // trackImpl->addTrackState( trkStateAtCalo ); - - - trackImpl->setChi2( fitter.getChi2( TrackState::AtIP ) ); - trackImpl->setNdf( fitter.getNdf ( TrackState::AtIP ) ); - - - const float* p = trkStateFirstHit->getReferencePoint(); - trackImpl->setRadiusOfInnermostHit( sqrt( p[0]*p[0] + p[1]*p[1] + p[2]*p[2] ) ); - - - - std::map hitNumbers; - - hitNumbers[lcio::ILDDetID::VXD] = 0; - hitNumbers[lcio::ILDDetID::SIT] = 0; - hitNumbers[lcio::ILDDetID::FTD] = 0; - hitNumbers[lcio::ILDDetID::TPC] = 0; - hitNumbers[lcio::ILDDetID::SET] = 0; - hitNumbers[lcio::ILDDetID::ETD] = 0; - - std::vector< TrackerHit* > trackerHits = trackImpl->getTrackerHits(); - - streamlog_out( DEBUG0 ) << "DDCellsAutomatonMV: finaliseTrack - trackerHits.size() = " << trackerHits.size() <<"\n"; - - - for( unsigned j=0; j < trackerHits.size(); j++ ){ - - UTIL::BitField64 encoder( LCTrackerCellID::encoding_string() ); - encoder.setValue( trackerHits[j]->getCellID0() ); - int subdet = encoder[lcio::LCTrackerCellID::subdet()]; - - streamlog_out( DEBUG0 ) << "DDCellsAutomatonMV: finaliseTrack - subdet = " << subdet <<"\n"; - - ++hitNumbers[ subdet ]; - - } - - - trackImpl->subdetectorHitNumbers().resize(2 * lcio::ILDDetID::ETD); - trackImpl->subdetectorHitNumbers()[ 2 * lcio::ILDDetID::VXD - 2 ] = hitNumbers[lcio::ILDDetID::VXD]; - trackImpl->subdetectorHitNumbers()[ 2 * lcio::ILDDetID::FTD - 2 ] = hitNumbers[lcio::ILDDetID::FTD]; - trackImpl->subdetectorHitNumbers()[ 2 * lcio::ILDDetID::SIT - 2 ] = hitNumbers[lcio::ILDDetID::SIT]; - trackImpl->subdetectorHitNumbers()[ 2 * lcio::ILDDetID::TPC - 2 ] = hitNumbers[lcio::ILDDetID::TPC]; - trackImpl->subdetectorHitNumbers()[ 2 * lcio::ILDDetID::SET - 2 ] = hitNumbers[lcio::ILDDetID::SET]; - trackImpl->subdetectorHitNumbers()[ 2 * lcio::ILDDetID::ETD - 2 ] = hitNumbers[lcio::ILDDetID::ETD]; - trackImpl->subdetectorHitNumbers()[ 2 * lcio::ILDDetID::VXD - 1 ] = hitNumbers[lcio::ILDDetID::VXD]; - trackImpl->subdetectorHitNumbers()[ 2 * lcio::ILDDetID::FTD - 1 ] = hitNumbers[lcio::ILDDetID::FTD]; - trackImpl->subdetectorHitNumbers()[ 2 * lcio::ILDDetID::SIT - 1 ] = hitNumbers[lcio::ILDDetID::SIT]; - trackImpl->subdetectorHitNumbers()[ 2 * lcio::ILDDetID::TPC - 1 ] = hitNumbers[lcio::ILDDetID::TPC]; - trackImpl->subdetectorHitNumbers()[ 2 * lcio::ILDDetID::SET - 1 ] = hitNumbers[lcio::ILDDetID::SET]; - trackImpl->subdetectorHitNumbers()[ 2 * lcio::ILDDetID::ETD - 1 ] = hitNumbers[lcio::ILDDetID::ETD]; - - - return; - - + min = _critMinima[critName][round]; + newValuesGotUsed = true; + } + + if (round + 1 <= _critMaxima[critName].size()) { + + max = _critMaxima[critName][round]; + newValuesGotUsed = true; + } + + ICriterion* crit = Criteria::createCriterion(critName, min, max); + + // Some debug output about the created criterion + std::string type = crit->getType(); + + streamlog_out(DEBUG4) << "Added: Criterion " << critName << " (type = " << type << " ). Min = " << min + << ", Max = " << max << ", round " << round << "\n"; + + // Add the new criterion to the corresponding vector + if (type == "2Hit") { + + _crit2Vec.push_back(crit); + + } else if (type == "3Hit") { + + _crit3Vec.push_back(crit); + + } else if (type == "4Hit") { + + _crit4Vec.push_back(crit); + + } else + delete crit; + } + + return newValuesGotUsed; } +void DDCellsAutomatonMV::finaliseTrack(TrackImpl* trackImpl) { -double DDCellsAutomatonMV::Dist( EVENT::TrackerHit *toHit, EVENT::TrackerHit *fromHit ) { + // Fitter fitter( trackImpl , _trkSystem ); //it gives problem at 90deg: sometimes the hits are taken in the inverse + // order resulting in a fitted track in the opposite quadrant of the hits + Fitter fitter(trackImpl, _trkSystem, 1); // it forces the hits ordering according to the radius (problem for very bent + // tracks that are coming back - TO STUDY) - const double *posOuter = fromHit->getPosition(); - const double *posInner = toHit->getPosition(); + trackImpl->trackStates().clear(); - double dist = sqrt( (posOuter[0] - posInner[0])*(posOuter[0] - posInner[0]) + (posOuter[1] - posInner[1])*(posOuter[1] - posInner[1]) + (posOuter[2] - posInner[2])*(posOuter[2] - posInner[2]) ) ; + TrackStateImpl* trkStateIP = new TrackStateImpl(*fitter.getTrackState(lcio::TrackState::AtIP)); + trkStateIP->setLocation(TrackState::AtIP); + trackImpl->addTrackState(trkStateIP); - //streamlog_out(DEBUG4) << " distance between minivectors = " << dist << std::endl ; + TrackStateImpl* trkStateFirstHit = new TrackStateImpl(*fitter.getTrackState(TrackState::AtFirstHit)); + trkStateFirstHit->setLocation(TrackState::AtFirstHit); + trackImpl->addTrackState(trkStateFirstHit); - return dist; + TrackStateImpl* trkStateLastHit = new TrackStateImpl(*fitter.getTrackState(TrackState::AtLastHit)); + trkStateLastHit->setLocation(TrackState::AtLastHit); + trackImpl->addTrackState(trkStateLastHit); + + // TrackStateImpl* trkStateAtCalo = new TrackStateImpl( *fitter.getTrackState( TrackState::AtCalorimeter ) ) ; + // trkStateAtCalo->setLocation( TrackState::AtCalorimeter ); + // trackImpl->addTrackState( trkStateAtCalo ); + + trackImpl->setChi2(fitter.getChi2(TrackState::AtIP)); + trackImpl->setNdf(fitter.getNdf(TrackState::AtIP)); + + const float* p = trkStateFirstHit->getReferencePoint(); + trackImpl->setRadiusOfInnermostHit(sqrt(p[0] * p[0] + p[1] * p[1] + p[2] * p[2])); + std::map hitNumbers; + + hitNumbers[lcio::ILDDetID::VXD] = 0; + hitNumbers[lcio::ILDDetID::SIT] = 0; + hitNumbers[lcio::ILDDetID::FTD] = 0; + hitNumbers[lcio::ILDDetID::TPC] = 0; + hitNumbers[lcio::ILDDetID::SET] = 0; + hitNumbers[lcio::ILDDetID::ETD] = 0; + + std::vector trackerHits = trackImpl->getTrackerHits(); + + streamlog_out(DEBUG0) << "DDCellsAutomatonMV: finaliseTrack - trackerHits.size() = " << trackerHits.size() << "\n"; + + for (unsigned j = 0; j < trackerHits.size(); j++) { + + UTIL::BitField64 encoder(LCTrackerCellID::encoding_string()); + encoder.setValue(trackerHits[j]->getCellID0()); + int subdet = encoder[lcio::LCTrackerCellID::subdet()]; + + streamlog_out(DEBUG0) << "DDCellsAutomatonMV: finaliseTrack - subdet = " << subdet << "\n"; + + ++hitNumbers[subdet]; + } + + trackImpl->subdetectorHitNumbers().resize(2 * lcio::ILDDetID::ETD); + trackImpl->subdetectorHitNumbers()[2 * lcio::ILDDetID::VXD - 2] = hitNumbers[lcio::ILDDetID::VXD]; + trackImpl->subdetectorHitNumbers()[2 * lcio::ILDDetID::FTD - 2] = hitNumbers[lcio::ILDDetID::FTD]; + trackImpl->subdetectorHitNumbers()[2 * lcio::ILDDetID::SIT - 2] = hitNumbers[lcio::ILDDetID::SIT]; + trackImpl->subdetectorHitNumbers()[2 * lcio::ILDDetID::TPC - 2] = hitNumbers[lcio::ILDDetID::TPC]; + trackImpl->subdetectorHitNumbers()[2 * lcio::ILDDetID::SET - 2] = hitNumbers[lcio::ILDDetID::SET]; + trackImpl->subdetectorHitNumbers()[2 * lcio::ILDDetID::ETD - 2] = hitNumbers[lcio::ILDDetID::ETD]; + trackImpl->subdetectorHitNumbers()[2 * lcio::ILDDetID::VXD - 1] = hitNumbers[lcio::ILDDetID::VXD]; + trackImpl->subdetectorHitNumbers()[2 * lcio::ILDDetID::FTD - 1] = hitNumbers[lcio::ILDDetID::FTD]; + trackImpl->subdetectorHitNumbers()[2 * lcio::ILDDetID::SIT - 1] = hitNumbers[lcio::ILDDetID::SIT]; + trackImpl->subdetectorHitNumbers()[2 * lcio::ILDDetID::TPC - 1] = hitNumbers[lcio::ILDDetID::TPC]; + trackImpl->subdetectorHitNumbers()[2 * lcio::ILDDetID::SET - 1] = hitNumbers[lcio::ILDDetID::SET]; + trackImpl->subdetectorHitNumbers()[2 * lcio::ILDDetID::ETD - 1] = hitNumbers[lcio::ILDDetID::ETD]; + + return; } +double DDCellsAutomatonMV::Dist(EVENT::TrackerHit* toHit, EVENT::TrackerHit* fromHit) { + + const double* posOuter = fromHit->getPosition(); + const double* posInner = toHit->getPosition(); -bool DDCellsAutomatonMV::thetaAgreementImproved( EVENT::TrackerHit *toHit, EVENT::TrackerHit *fromHit, int layer ) { + double dist = sqrt((posOuter[0] - posInner[0]) * (posOuter[0] - posInner[0]) + + (posOuter[1] - posInner[1]) * (posOuter[1] - posInner[1]) + + (posOuter[2] - posInner[2]) * (posOuter[2] - posInner[2])); + + // streamlog_out(DEBUG4) << " distance between minivectors = " << dist << std::endl ; + + return dist; +} + +bool DDCellsAutomatonMV::thetaAgreementImproved(EVENT::TrackerHit* toHit, EVENT::TrackerHit* fromHit, int layer) { // Improved error estimation of polar angle theta, taking into account the uncertainty of the radius as well... // also the single point resolution is not hard-coded any more - bool agreement = false ; + bool agreement = false; - //double resolution = 0.004 ; // just temporarily here - //double MPS_factor = 0.0 ; // just for test, and only for vertical muons of 4GeV + // double resolution = 0.004 ; // just temporarily here + // double MPS_factor = 0.0 ; // just for test, and only for vertical muons of 4GeV - double pos_outer[3]; - double pos_inner[3]; + double pos_outer[3]; + double pos_inner[3]; pos_outer[0] = fromHit->getPosition()[0]; pos_outer[1] = fromHit->getPosition()[1]; pos_outer[2] = fromHit->getPosition()[2]; - double radout = sqrt(pos_outer[0]*pos_outer[0]+pos_outer[1]*pos_outer[1]); + double radout = sqrt(pos_outer[0] * pos_outer[0] + pos_outer[1] * pos_outer[1]); // double theta_out = (180.0 * atan(radout/pos_outer[2])) / M_PI ; - //BEFORE BAD RANGE - at 90deg possible flip of sign -- fixed track ineff, still bad track - double theta_out = atan2(radout,pos_outer[2]); - theta_out = 2*M_PI-theta_out; - //theta_out = theta_out % (2*M_PI); - //theta_out = fmod(theta_out,2*M_PI); - while(theta_out>=2*M_PI){ - theta_out = theta_out - 2*M_PI; + // BEFORE BAD RANGE - at 90deg possible flip of sign -- fixed track ineff, still bad track + double theta_out = atan2(radout, pos_outer[2]); + theta_out = 2 * M_PI - theta_out; + // theta_out = theta_out % (2*M_PI); + // theta_out = fmod(theta_out,2*M_PI); + while (theta_out >= 2 * M_PI) { + theta_out = theta_out - 2 * M_PI; } - theta_out = theta_out*180./M_PI; + theta_out = theta_out * 180. / M_PI; pos_inner[0] = toHit->getPosition()[0]; pos_inner[1] = toHit->getPosition()[1]; pos_inner[2] = toHit->getPosition()[2]; - double radinn = sqrt(pos_inner[0]*pos_inner[0]+pos_inner[1]*pos_inner[1]); - //double theta_inn = (180.0 *atan(radinn/pos_inner[2])) / M_PI; - //BEFORE BAD RANGE - at 90deg possible flip of sign -- fixed track ineff, still bad track - double theta_inn = atan2(radinn,pos_inner[2]); - theta_inn = 2*M_PI-theta_inn; - while(theta_inn>=2*M_PI){ - theta_inn = theta_inn - 2*M_PI; + double radinn = sqrt(pos_inner[0] * pos_inner[0] + pos_inner[1] * pos_inner[1]); + // double theta_inn = (180.0 *atan(radinn/pos_inner[2])) / M_PI; + // BEFORE BAD RANGE - at 90deg possible flip of sign -- fixed track ineff, still bad track + double theta_inn = atan2(radinn, pos_inner[2]); + theta_inn = 2 * M_PI - theta_inn; + while (theta_inn >= 2 * M_PI) { + theta_inn = theta_inn - 2 * M_PI; } - theta_inn = theta_inn*180./M_PI; + theta_inn = theta_inn * 180. / M_PI; - double diff_theta = fabs ( theta_out - theta_inn ) ; + double diff_theta = fabs(theta_out - theta_inn); - streamlog_out(DEBUG4) << "Theta of outer hit " << theta_out << " Theta of inner hit " << theta_inn << " Theta diff between the adjacent hits " << diff_theta << " maximum value " << _hitPairThDiff << std::endl ; + streamlog_out(DEBUG4) << "Theta of outer hit " << theta_out << " Theta of inner hit " << theta_inn + << " Theta diff between the adjacent hits " << diff_theta << " maximum value " << _hitPairThDiff + << std::endl; - /* + /* int celId_inner = toHit->getCellID0() ; - UTIL::BitField64 encoder( lcio::LCTrackerCellID::encoding_string() ) ; + UTIL::BitField64 encoder( lcio::LCTrackerCellID::encoding_string() ) ; encoder.setValue(celId_inner) ; int inner_layer = encoder[lcio::LCTrackerCellID::layer()] ; - + double resolution = _resU[inner_layer] ; - //double deltaTheta = 3*resolution*sqrt( (radinn/((radinn*radinn) + (pos_inner[2]*pos_inner[2])))*(radinn/((radinn*radinn) + (pos_inner[2]*pos_inner[2]))) + ((pos_inner[0]*pos_inner[2])/(((radinn*radinn) + (pos_inner[2]*pos_inner[2]))*radinn))*((pos_inner[0]*pos_inner[2])/(((radinn*radinn) + (pos_inner[2]*pos_inner[2]))*radinn)) + ((pos_inner[1]*pos_inner[2])/(((radinn*radinn) + (pos_inner[2]*pos_inner[2]))*radinn))*((pos_inner[1]*pos_inner[2])/(((radinn*radinn) + (pos_inner[2]*pos_inner[2]))*radinn)) ) ; + //double deltaTheta = 3*resolution*sqrt( (radinn/((radinn*radinn) + + (pos_inner[2]*pos_inner[2])))*(radinn/((radinn*radinn) + (pos_inner[2]*pos_inner[2]))) + + ((pos_inner[0]*pos_inner[2])/(((radinn*radinn) + + (pos_inner[2]*pos_inner[2]))*radinn))*((pos_inner[0]*pos_inner[2])/(((radinn*radinn) + + (pos_inner[2]*pos_inner[2]))*radinn)) + ((pos_inner[1]*pos_inner[2])/(((radinn*radinn) + + (pos_inner[2]*pos_inner[2]))*radinn))*((pos_inner[1]*pos_inner[2])/(((radinn*radinn) + + (pos_inner[2]*pos_inner[2]))*radinn)) ) ; double deltazent = radinn/((radinn*radinn) + (pos_inner[2]*pos_inner[2])) ; double deltaxi = (pos_inner[0]*pos_inner[2])/(((radinn*radinn) + (pos_inner[2]*pos_inner[2]))*radinn) ; double deltapsi = (pos_inner[1]*pos_inner[2])/(((radinn*radinn) + (pos_inner[2]*pos_inner[2]))*radinn) ; - double deltaTheta = 5*resolution*sqrt((deltaxi*deltaxi) + (deltapsi*deltapsi) + (deltazent*deltazent)) ; + double deltaTheta = 5*resolution*sqrt((deltaxi*deltaxi) + (deltapsi*deltapsi) + (deltazent*deltazent)) ; if ( theta_inn < (theta_out + (deltaTheta + MPS_factor)) && theta_inn > (theta_out - (deltaTheta + MPS_factor)) ){ agreement = true ; } - streamlog_out(DEBUG3) << " outer radius " << radout << " inner radius " << radinn << " resolution " << _resU[inner_layer] << " outer theta " << theta_out*(180.0/M_PI) << " inner theta " << theta_inn*(180.0/M_PI) << " deltaTheta " << deltaTheta*(180.0/M_PI) << " Agreement " << agreement << " deltaxi = " << deltaxi << " deltapsi = " << deltapsi << " deltazent = " << deltazent << std::endl ; + streamlog_out(DEBUG3) << " outer radius " << radout << " inner radius " << radinn << " resolution " << + _resU[inner_layer] << " outer theta " << theta_out*(180.0/M_PI) << " inner theta " << theta_inn*(180.0/M_PI) << " + deltaTheta " << deltaTheta*(180.0/M_PI) << " Agreement " << agreement << " deltaxi = " << deltaxi << " deltapsi = " + << deltapsi << " deltazent = " << deltazent << std::endl ; */ - if ( layer == 6 || layer == 4 ){ + if (layer == 6 || layer == 4) { - if ( diff_theta < _hitPairThDiff ){ - agreement = true ; + if (diff_theta < _hitPairThDiff) { + agreement = true; } } - if ( layer == 2 ){ + if (layer == 2) { - if ( diff_theta < _hitPairThDiffInner ){ - agreement = true ; + if (diff_theta < _hitPairThDiffInner) { + agreement = true; } } - - return agreement ; - + return agreement; } diff --git a/source/Refitting/src/ExtrToSIT.cc b/source/Refitting/src/ExtrToSIT.cc index aba1eb0..6a14365 100644 --- a/source/Refitting/src/ExtrToSIT.cc +++ b/source/Refitting/src/ExtrToSIT.cc @@ -3,948 +3,855 @@ #include #include -#include "DD4hep/Detector.h" #include "DD4hep/DD4hepUnits.h" +#include "DD4hep/Detector.h" #include "DDRec/DetectorData.h" - -using namespace lcio ; -using namespace marlin ; -using namespace MarlinTrk ; - +using namespace lcio; +using namespace marlin; +using namespace MarlinTrk; //---------------------------------------------------------------- -struct Distance3D2{ - Vector3D _pos ; - Distance3D2( const Vector3D& pos) : _pos( pos ) {} +struct Distance3D2 { + Vector3D _pos; + Distance3D2(const Vector3D& pos) : _pos(pos) {} template - double operator()( const T* t) { - Vector3D p( t->getPosition() ) ; - return ( p - _pos ).r2() ; - + double operator()(const T* t) { + Vector3D p(t->getPosition()); + return (p - _pos).r2(); } }; //---------------------------------------------------------------- - //------------------------------------------------------------------------------------------ -struct PtSort { // sort tracks wtr to pt - largest first - inline bool operator()( const lcio::LCObject* l, const lcio::LCObject* r) { - return ( std::abs( ( (const lcio::Track*) l )->getOmega() ) < std::abs( ( (const lcio::Track*) r )->getOmega() ) ); // pt ~ 1./omega +struct PtSort { // sort tracks wtr to pt - largest first + inline bool operator()(const lcio::LCObject* l, const lcio::LCObject* r) { + return (std::abs(((const lcio::Track*)l)->getOmega()) < + std::abs(((const lcio::Track*)r)->getOmega())); // pt ~ 1./omega } }; //------------------------------------------------------------------------------------------ - //------------------------------------------------------------------------------------------ -struct ZSort { // sort TPC track segments wtr to Z - smallest first - inline bool operator()( const lcio::LCObject* l, const lcio::LCObject* r) { - return ( std::abs( ( (const lcio::Track*) l )->getZ0() ) < std::abs( ( (const lcio::Track*) r )->getZ0() ) ); // pt ~ 1./omega +struct ZSort { // sort TPC track segments wtr to Z - smallest first + inline bool operator()(const lcio::LCObject* l, const lcio::LCObject* r) { + return (std::abs(((const lcio::Track*)l)->getZ0()) < std::abs(((const lcio::Track*)r)->getZ0())); // pt ~ 1./omega } }; //------------------------------------------------------------------------------------------ - -ExtrToSIT aExtrToSIT ; - +ExtrToSIT aExtrToSIT; ExtrToSIT::ExtrToSIT() : Processor("ExtrToSIT") { - + // modify processor description - _description = "ExtrToSIT refits an input track collection (TPC or VXD), and used IMarlinTrk tools to propagate it to SIT" ; - - + _description = + "ExtrToSIT refits an input track collection (TPC or VXD), and used IMarlinTrk tools to propagate it to SIT"; + // register steering parameters: name, description, class-variable, default value - - registerInputCollection( LCIO::TRACK, - "InputTrackCollectionName" , - "Name of the input track collection" , - _input_track_col_name , - std::string("TruthTracks") ) ; - - registerInputCollection( LCIO::LCRELATION, - "InputTrackRelCollection" , - "Name of the MCParticle-Track Relations collection for input tracks" , - _input_track_rel_name , - std::string("TruthTracksMCP") ) ; - - registerInputCollection( LCIO::TRACKERHITPLANE, - "digitisedVXDHits" , - "Name of the VTXTrackerHit collection" , - _vxdColName , - std::string("VTXTrackerHits") ) ; - - registerInputCollection( LCIO::TRACKERHITPLANE, - "digitisedSITHits" , - "Name of the SITTrackerHit collection" , - _sitColName , - std::string("SITTrackerHits") ) ; - - registerOutputCollection( LCIO::TRACK, - "OutputTrackCollectionName" , - "Name of the output track collection" , - _output_track_col_name , - std::string("RefittedTracks") ) ; - - registerOutputCollection( LCIO::TRACK, - "SiliconCollectionName" , - "Name of the output silicon track collection" , - _siTrkColName , - std::string("SiliconTracks") ) ; - - registerOutputCollection( LCIO::LCRELATION, - "OutputTrackRelCollection" , - "Name of the MCParticle-Track Relations collection for output tracks" , - _output_track_rel_name , - std::string("RefittedTracksMCP") ) ; - - registerProcessorParameter("MultipleScatteringOn", - "Use MultipleScattering in Fit", - _MSOn, - bool(true)); - - registerProcessorParameter("EnergyLossOn", - "Use Energy Loss in Fit", - _ElossOn, - bool(true)); - - registerProcessorParameter("SmoothOn", - "Smooth All Mesurement Sites in Fit", - _SmoothOn, - bool(false)); - registerProcessorParameter( "TrackSystemName", - "Name of the track fitting system to be used (KalTest, DDKalTest, aidaTT, ... )", - _trkSystemName, - std::string("DDKalTest") ); - - registerProcessorParameter("DirInsideOut", - "direction for the extrapolation. if true it means we extrapolate from VXD, otherwise from TPC", - _dirInsideOut, - bool(true)); - - registerProcessorParameter("Max_Chi2_Incr", - "maximum allowable chi2 increment when moving from one site to another", - _Max_Chi2_Incr, - double(1000)); - - registerProcessorParameter("PropagateToLayer", - "Which layer should the seed be propagated to", - _propToLayer, - int(4)); - - - registerProcessorParameter("TPCHitsCut", - "minimum acceptable no of hits for the TPC tracks", - _tpcHitsCut, - int(6)); - - registerProcessorParameter("Chi2NDoFCut", - "maximum acceptable chi2/ndof for the TPC tracks", - _chi2NDoFCut, + registerInputCollection(LCIO::TRACK, "InputTrackCollectionName", "Name of the input track collection", + _input_track_col_name, std::string("TruthTracks")); + + registerInputCollection(LCIO::LCRELATION, "InputTrackRelCollection", + "Name of the MCParticle-Track Relations collection for input tracks", _input_track_rel_name, + std::string("TruthTracksMCP")); + + registerInputCollection(LCIO::TRACKERHITPLANE, "digitisedVXDHits", "Name of the VTXTrackerHit collection", + _vxdColName, std::string("VTXTrackerHits")); + + registerInputCollection(LCIO::TRACKERHITPLANE, "digitisedSITHits", "Name of the SITTrackerHit collection", + _sitColName, std::string("SITTrackerHits")); + + registerOutputCollection(LCIO::TRACK, "OutputTrackCollectionName", "Name of the output track collection", + _output_track_col_name, std::string("RefittedTracks")); + + registerOutputCollection(LCIO::TRACK, "SiliconCollectionName", "Name of the output silicon track collection", + _siTrkColName, std::string("SiliconTracks")); + + registerOutputCollection(LCIO::LCRELATION, "OutputTrackRelCollection", + "Name of the MCParticle-Track Relations collection for output tracks", + _output_track_rel_name, std::string("RefittedTracksMCP")); + + registerProcessorParameter("MultipleScatteringOn", "Use MultipleScattering in Fit", _MSOn, bool(true)); + + registerProcessorParameter("EnergyLossOn", "Use Energy Loss in Fit", _ElossOn, bool(true)); + + registerProcessorParameter("SmoothOn", "Smooth All Mesurement Sites in Fit", _SmoothOn, bool(false)); + + registerProcessorParameter("TrackSystemName", + "Name of the track fitting system to be used (KalTest, DDKalTest, aidaTT, ... )", + _trkSystemName, std::string("DDKalTest")); + + registerProcessorParameter( + "DirInsideOut", "direction for the extrapolation. if true it means we extrapolate from VXD, otherwise from TPC", + _dirInsideOut, bool(true)); + + registerProcessorParameter("Max_Chi2_Incr", "maximum allowable chi2 increment when moving from one site to another", + _Max_Chi2_Incr, double(1000)); + + registerProcessorParameter("PropagateToLayer", "Which layer should the seed be propagated to", _propToLayer, int(4)); + + registerProcessorParameter("TPCHitsCut", "minimum acceptable no of hits for the TPC tracks", _tpcHitsCut, int(6)); + + registerProcessorParameter("Chi2NDoFCut", "maximum acceptable chi2/ndof for the TPC tracks", _chi2NDoFCut, float(100)); - registerProcessorParameter("DoCut", - "maximum acceptable D0 at IP", - _DoCut, - float(2)); + registerProcessorParameter("DoCut", "maximum acceptable D0 at IP", _DoCut, float(2)); - registerProcessorParameter("ZoCut", - "maximum acceptable Z0 at IP", - _ZoCut, - float(5)); + registerProcessorParameter("ZoCut", "maximum acceptable Z0 at IP", _ZoCut, float(5)); - registerProcessorParameter("SearchSigma", - "times d0(Z0) acceptable from track extrapolation point", - _searchSigma, + registerProcessorParameter("SearchSigma", "times d0(Z0) acceptable from track extrapolation point", _searchSigma, double(3)); - registerProcessorParameter("IsSpacePoints", - "If we use space points rather than hits (SIT)", - _isSpacePoints, + registerProcessorParameter("IsSpacePoints", "If we use space points rather than hits (SIT)", _isSpacePoints, bool(false)); - registerProcessorParameter("NHitsChi2", - "Maximal number of hits for which a track with n hits is better than one with n-1hits. (defaut 5)", - _nHitsChi2, - int(5)); + registerProcessorParameter( + "NHitsChi2", "Maximal number of hits for which a track with n hits is better than one with n-1hits. (defaut 5)", + _nHitsChi2, int(5)); StringVec trackerHitsRelInputColNamesDefault; - trackerHitsRelInputColNamesDefault.push_back( "VXDTrackerHitRelations" ); - trackerHitsRelInputColNamesDefault.push_back( "SITTrackerHitRelations" ); + trackerHitsRelInputColNamesDefault.push_back("VXDTrackerHitRelations"); + trackerHitsRelInputColNamesDefault.push_back("SITTrackerHitRelations"); - registerInputCollections("LCRelation", - "TrackerHitsRelInputCollections", + registerInputCollections("LCRelation", "TrackerHitsRelInputCollections", "Name of the lcrelation collections, that link the TrackerHits to their SimTrackerHits.", - _colNamesTrackerHitRelations, - trackerHitsRelInputColNamesDefault ); - - registerInputCollection( LCIO::MCPARTICLE, - "MCParticleCollection" , - "Name of the MCParticle input collection" , - _mcParticleCollectionName , - std::string("MCParticle") ) ; + _colNamesTrackerHitRelations, trackerHitsRelInputColNamesDefault); + registerInputCollection(LCIO::MCPARTICLE, "MCParticleCollection", "Name of the MCParticle input collection", + _mcParticleCollectionName, std::string("MCParticle")); } +void ExtrToSIT::init() { + + streamlog_out(DEBUG) << " init called " << std::endl; -void ExtrToSIT::init() { - - streamlog_out(DEBUG) << " init called " - << std::endl ; - // usually a good idea to - printParameters() ; - + printParameters(); + // set up the geometery needed by DDKalTest - _trksystem = MarlinTrk::Factory::createMarlinTrkSystem( _trkSystemName , 0 , "" ) ; - - if( _trksystem == 0 ){ - - throw EVENT::Exception( std::string(" Cannot initialize MarlinTrkSystem of Type: ") + _trkSystemName ) ; - + _trksystem = MarlinTrk::Factory::createMarlinTrkSystem(_trkSystemName, 0, ""); + + if (_trksystem == 0) { + + throw EVENT::Exception(std::string(" Cannot initialize MarlinTrkSystem of Type: ") + _trkSystemName); } - - _trksystem->setOption( IMarlinTrkSystem::CFG::useQMS, _MSOn ) ; - _trksystem->setOption( IMarlinTrkSystem::CFG::usedEdx, _ElossOn) ; - _trksystem->setOption( IMarlinTrkSystem::CFG::useSmoothing, _SmoothOn) ; - _trksystem->init() ; - - - _n_run = 0 ; - _n_evt = 0 ; - SITHitsFitted = 0 ; - SITHitsNonFitted = 0 ; - TotalSITHits = 0 ; + + _trksystem->setOption(IMarlinTrkSystem::CFG::useQMS, _MSOn); + _trksystem->setOption(IMarlinTrkSystem::CFG::usedEdx, _ElossOn); + _trksystem->setOption(IMarlinTrkSystem::CFG::useSmoothing, _SmoothOn); + _trksystem->init(); + + _n_run = 0; + _n_evt = 0; + SITHitsFitted = 0; + SITHitsNonFitted = 0; + TotalSITHits = 0; dd4hep::Detector& theDetector = dd4hep::Detector::getInstance(); - double bFieldVec[3] ; - theDetector.field().magneticField( {0,0,0} , bFieldVec ); // get the magnetic field vector from DD4hep - _bField = bFieldVec[2]/dd4hep::tesla; // z component at (0,0,0) + double bFieldVec[3]; + theDetector.field().magneticField({0, 0, 0}, bFieldVec); // get the magnetic field vector from DD4hep + _bField = bFieldVec[2] / dd4hep::tesla; // z component at (0,0,0) dd4hep::DetElement sitDE = theDetector.detector("SIT"); dd4hep::rec::ZPlanarData* sit = sitDE.extension(); - _nSITLayers = sit->layers.size(); - + _nSITLayers = sit->layers.size(); + _maxChi2PerHit = 100; - } -void ExtrToSIT::processRunHeader( LCRunHeader* ) { - - ++_n_run ; -} - -void ExtrToSIT::processEvent( LCEvent * evt ) { +void ExtrToSIT::processRunHeader(LCRunHeader*) { ++_n_run; } +void ExtrToSIT::processEvent(LCEvent* evt) { - // set the correct configuration for the tracking system for this event - MarlinTrk::TrkSysConfig< MarlinTrk::IMarlinTrkSystem::CFG::useQMS> mson( _trksystem, _MSOn ) ; - MarlinTrk::TrkSysConfig< MarlinTrk::IMarlinTrkSystem::CFG::usedEdx> elosson( _trksystem,_ElossOn) ; - MarlinTrk::TrkSysConfig< MarlinTrk::IMarlinTrkSystem::CFG::useSmoothing> smoothon( _trksystem,_SmoothOn) ; + // set the correct configuration for the tracking system for this event + MarlinTrk::TrkSysConfig mson(_trksystem, _MSOn); + MarlinTrk::TrkSysConfig elosson(_trksystem, _ElossOn); + MarlinTrk::TrkSysConfig smoothon(_trksystem, _SmoothOn); //-- note: this will not be printed if compiled w/o MARLINDEBUG=1 ! - - streamlog_out(DEBUG1) << " processing event: " << _n_evt - << std::endl ; - - // get input collection and relations - LCCollection* input_track_col = this->GetCollection( evt, _input_track_col_name ) ; - LCCollection* sitHitsCol = this->GetCollection( evt, _sitColName ) ; - - if( input_track_col != 0 ){ - - // establish the track collection that will be created - LCCollectionVec* trackVec = new LCCollectionVec( LCIO::TRACK ) ; - //LCCollectionVec* SiTrkCol = new LCCollectionVec(LCIO::TRACK); + + streamlog_out(DEBUG1) << " processing event: " << _n_evt << std::endl; + + // get input collection and relations + LCCollection* input_track_col = this->GetCollection(evt, _input_track_col_name); + LCCollection* sitHitsCol = this->GetCollection(evt, _sitColName); + + if (input_track_col != 0) { + + // establish the track collection that will be created + LCCollectionVec* trackVec = new LCCollectionVec(LCIO::TRACK); + // LCCollectionVec* SiTrkCol = new LCCollectionVec(LCIO::TRACK); // relation collections - + // if we want to point back to the hits we need to set the flag - LCFlagImpl trkFlag(0) ; - trkFlag.setBit( LCIO::TRBIT_HITS ) ; - trackVec->setFlag( trkFlag.getFlag() ) ; - - int nTracks = input_track_col->getNumberOfElements() ; + LCFlagImpl trkFlag(0); + trkFlag.setBit(LCIO::TRBIT_HITS); + trackVec->setFlag(trkFlag.getFlag()); + + int nTracks = input_track_col->getNumberOfElements(); streamlog_out(DEBUG4) << " ######### NO OF TRACKS $$$$$$$$$$ " << nTracks << std::endl; - LCCollectionVec* inputTrackVec = new LCCollectionVec( LCIO::TRACK ) ; + LCCollectionVec* inputTrackVec = new LCCollectionVec(LCIO::TRACK); + + for (int n = 0; n < nTracks; ++n) { + Track* testTrack = dynamic_cast(input_track_col->getElementAt(n)); + inputTrackVec->addElement(testTrack); + } + std::sort(inputTrackVec->begin(), inputTrackVec->end(), PtSort()); - for( int n= 0 ; n < nTracks ; ++n ) { - Track* testTrack = dynamic_cast( input_track_col->getElementAt( n ) ) ; - inputTrackVec->addElement( testTrack ); + int sitHits = 0; + if (sitHitsCol != 0) { + sitHits = sitHitsCol->getNumberOfElements(); } - std::sort( inputTrackVec->begin() , inputTrackVec->end() , PtSort() ) ; + EVENT::TrackerHitVec usedSiHits; + std::vector trackCandidates; - int sitHits = 0 ; - if ( sitHitsCol != 0 ) { sitHits = sitHitsCol->getNumberOfElements(); } + // loop over the input tracks and refit using KalTest + for (int iTrack = 0; iTrack < nTracks; ++iTrack) { - EVENT::TrackerHitVec usedSiHits ; - std::vector< IMPL::TrackImpl* > trackCandidates ; + int SITHitsPerTrk = 0; - // loop over the input tracks and refit using KalTest - for(int iTrack=0; iTrack< nTracks ; ++iTrack) { + // Track* track = dynamic_cast( input_track_col->getElementAt( i ) ) ; + Track* track = static_cast(inputTrackVec->getElementAt(iTrack)); - int SITHitsPerTrk = 0 ; - - //Track* track = dynamic_cast( input_track_col->getElementAt( i ) ) ; - Track* track = static_cast( inputTrackVec->getElementAt( iTrack ) ) ; - MarlinTrk::IMarlinTrack* marlin_trk = _trksystem->createTrack(); - - EVENT::TrackerHitVec trkHits = track->getTrackerHits() ; - - //apply a chi2/ndf track sample selection - float chisquare = track->getChi2() ; - int ndof = track->getNdf() ; - + + EVENT::TrackerHitVec trkHits = track->getTrackerHits(); + + // apply a chi2/ndf track sample selection + float chisquare = track->getChi2(); + int ndof = track->getNdf(); + // d0, Z0 values of TPC tracks - - float chi2_ndf = chisquare / ( 1.0 * ndof ) ; - - //accept only tracks with > minimum hits at the TPC & chi2/ndf < maximum cut & Pt cut? - if (chi2_ndf < _chi2NDoFCut){ - - streamlog_out(DEBUG4) << "%%%% Checking track " << track->id() << " chi2/ndf " << chi2_ndf << " cut " << _chi2NDoFCut << " D0 " << track->getD0() << " Z0 " << track->getZ0() << std::endl ; - - - // sort the hits in R, so here we are assuming that the track came from the IP and that we want to fit out to in. - sort(trkHits.begin(), trkHits.end(), ExtrToSIT::compare_r() ); - - for(EVENT::TrackerHitVec::iterator it = trkHits.begin() ; it != trkHits.end() ; ++it ){ - marlin_trk->addHit(*it); - } - - //int init_status = marlin_trk->initialise( IMarlinTrack::backward ) ; - //int init_status = FitInit(trkHits, marlin_trk) ; // alternative way to initialise the marlin_trk object - int init_status = FitInit2(track, marlin_trk) ; - - if (init_status==0) { - - streamlog_out(DEBUG4) << "track initialised " << std::endl ; - - int fit_status = marlin_trk->fit() ; - - if ( fit_status == 0 ){ - - int testFlag=0; - - // some testing - TrackStateImpl testTS ; - double chi2_test = 0 ; - int ndf_test = 0 ; - int testTrackState = marlin_trk->getTrackState( testTS, chi2_test, ndf_test ) ; - if (testTrackState==0){ - const float* testpivot = testTS.getReferencePoint() ; - streamlog_out(DEBUG4) << "test pivot " << testpivot[0] << ", " << testpivot[1] << ", " << testpivot[2] << " - r: " << sqrt( testpivot[0]*testpivot[0]+testpivot[1]*testpivot[1] ) << std::endl; - } - - streamlog_out(DEBUG3) << "###########$$$$$$$$$$##############" << std::endl; - - - // now we have a track constisting only of TPC hits - - // 1) extrapolate to outer most SIT layer - - // 2) select best hit candidate - - // 3) marlin_trk->addAndFit(hit,max_chi2_increment); - - // 3a) select best hit candidate on n+1 layer - - // 3b) marlin_trk->addAndFit(hit,max_chi2_increment); - - // 4) loop and repeat for other layers, plus VXD - - // 5) all hits have been added, propogate to IP for instance - - //_________________________________________________________ - - - //marlin_trk->smooth(trkHits.back()); - - - double chi2 = 0 ; - int ndf = 0 ; - - Vector3D xing_point ; - - UTIL::BitField64 encoder( lcio::LCTrackerCellID::encoding_string() ) ; - - encoder.reset() ; // reset to 0 - - int layerID = encoder.lowWord() ; - int elementID = 0 ; - - - //________________________________________________________________________________________________________ - // - // starting loop to SIT layers - //________________________________________________________________________________________________________ - - - //for loop to all SIT layers - - for (unsigned int iL=0;iL<_nSITLayers;iL++){ - - if ( sitHitsCol != 0 ){ - - streamlog_out(DEBUG4) << " Do I come into the loop " << std::endl; - - streamlog_out(DEBUG4) << "LOOP" << iL << " begins "<< std::endl; - - - encoder[lcio::LCTrackerCellID::subdet()] = ILDDetID::SIT ; - - if ( _dirInsideOut ) - encoder[lcio::LCTrackerCellID::layer()] = iL ; // in case we propagate outwards from VXD - else - encoder[lcio::LCTrackerCellID::layer()] = 3 - iL ; // in case we propagate inwards from TPC - - layerID = encoder.lowWord() ; - - TrackStateImpl trkState; - - if ( marlin_trk->propagateToLayer( layerID, trkState, chi2, ndf, elementID, IMarlinTrack::modeClosest) == MarlinTrk::IMarlinTrack::success) { - - const FloatVec& covLCIO = trkState.getCovMatrix(); - const float* pivot = trkState.getReferencePoint(); - - streamlog_out( DEBUG4 ) << " kaltest track parameters: " - << " chi2/ndf " << chi2 / ndf - << " chi2 " << chi2 << std::endl - - << "\t D0 " << trkState.getD0() << "[+/-" << sqrt( covLCIO[0] ) << "] " - << "\t Phi :" << trkState.getPhi()<< "[+/-" << sqrt( covLCIO[2] ) << "] " - << "\t Omega " << trkState.getOmega() << "[+/-" << sqrt( covLCIO[5] ) << "] " - << "\t Z0 " << trkState.getZ0() << "[+/-" << sqrt( covLCIO[9] ) << "] " - << "\t tan(Lambda) " << trkState.getTanLambda() << "[+/-" << sqrt( covLCIO[14]) << "] " - - << "\t pivot : [" << pivot[0] << ", " << pivot[1] << ", " << pivot[2] - << " - r: " << sqrt( pivot[0]*pivot[0]+pivot[1]*pivot[1] ) << "]" - << std::endl ; - - double r = sqrt( pivot[0]*pivot[0]+pivot[1]*pivot[1] ) ; - - streamlog_out(DEBUG4) << " layer " << 3 - iL << " max search distances Z : Rphi " << _searchSigma*sqrt( covLCIO[9] ) << " : " << _searchSigma*sqrt( covLCIO[0] ) << std::endl ; - - - //_______________________________________________________________________________________ - // - //track - hit association (just for fun) - - streamlog_out(DEBUG2) << " element ID " << elementID << std::endl; - - if ( elementID != 0 ){ - - testFlag = 1; - - EVENT::TrackerHitVec HitsInLayer; - - float dU_spres = 0 ; - float dV_spres = 0 ; - - double chi2_increment = 0; - - for (int iSit=0;iSit( sitHitsCol->getElementAt( iSit ) ) ; - - streamlog_out(DEBUG2) << " type = " << hit->getType() << std::endl; - - const int celId = hit->getCellID0() ; - - streamlog_out(DEBUG1) << " hit cellid0 = " << celId << std::endl; - - int layerNumber = 0 ; - int ladderNumber = 0 ; - int sideTest = 0 ; - int sensorNumber = 0 ; - - //UTIL::BitField64 encoder( lcio::LCTrackerCellID::encoding_string() ) ; - encoder.setValue(celId) ; - layerNumber = encoder[lcio::LCTrackerCellID::layer()] ; - ladderNumber = encoder[lcio::LCTrackerCellID::module()] ; - sideTest = encoder[lcio::LCTrackerCellID::side()] ; - sensorNumber = encoder[lcio::LCTrackerCellID::sensor()] ; - encoder.reset() ; - - // Just to check the element matching between the hit (coming from the digitiser) and the track extrapolation element (coming from Mokka) - - // int mokkaLayerNumber = 0 ; - // int mokkaLadderNumber = 0 ; - // int mokkaSideTest = 0 ; - // int mokkaSensorNumber = 0 ; - - encoder.setValue(elementID) ; - // mokkaLayerNumber = encoder[lcio::LCTrackerCellID::layer()] ; - // mokkaLadderNumber = encoder[lcio::LCTrackerCellID::module()] ; - // mokkaSideTest = encoder[lcio::LCTrackerCellID::side()] ; - // mokkaSensorNumber = encoder[lcio::LCTrackerCellID::sensor()] ; - encoder.reset() ; - - streamlog_out(DEBUG2) << " checking hit : type = " << hit->getType() << " cell ID = " << celId << " side = " << sideTest << " layer = " << layerNumber << " ladder = " << ladderNumber << " sensor = " << sensorNumber << std::endl ; - - streamlog_out(DEBUG2) << " the element id where the hit is found " << celId << " the element id where the track is extrapolated " << elementID << std::endl; - - if (celId==elementID){ // cause elementID does not give sensor-side infos... - //if (mokkaLayerNumber==layerNumber && mokkaLadderNumber==ladderNumber){ - streamlog_out(DEBUG2) << " We found a hit at the right element with type : " << hit->getType() << " side = " << sideTest << " layer = " << layerNumber << " ladder = " << ladderNumber << " sensor = " << sensorNumber << std::endl; - streamlog_out(DEBUG3) << " We found a hit at the right element with type : " << hit->getType() << std::endl ; - HitsInLayer.push_back(hit); - } - } //end loop on hits - /* - // ------------------ in order to obtain sensors single point resolution --------------------- - if (_pixelSIT){ - for (int jj=0;jj( sitHitsCol->getElementAt( jj ) ) ; - if (hitplane){ - const int celId_spres = hitplane->getCellID0() ; - - if (celId_spres==elementID){ - dU_spres = hitplane->getdU(); - dV_spres = hitplane->getdV(); - //streamlog_out(DEBUG4) << " U resolution = " << dU_spres << " V resolution = " << dV_spres << std::endl ; - } - } - } - } - */ - //if (!_pixelSIT){ - // Alternative way to assign the sensor s.p. resolution until I understand what's going on with that - dU_spres = 0.007; - dV_spres = 0.05; - //} - // --------------------------------------------------------------------------------------------- - - if (HitsInLayer.size()!=0){ - - TrackerHit *BestHit; - bool BestHitFound = false; - - int pointer = 0 ; - int PossibleHits = 0 ; - double DimDist = 0 ; - - streamlog_out(DEBUG4) << " calling selectbestcandidatelimited with value for possible hits = " << PossibleHits << std::endl ; - - SelectBestCandidateLimited(HitsInLayer, pivot, BestHit, covLCIO, r, BestHitFound, _searchSigma, pointer, PossibleHits, dU_spres, dV_spres, DimDist, usedSiHits ); - - if ( BestHitFound ) { // when selection is restricted to an area maybe we will not find an appropriate hit - - bool isSuccessful2 = false; - - streamlog_out(DEBUG4) << " Best hit found: call add and fit " << std::endl ; - - - TrackerHitPlaneImpl *TestHitPlane = new TrackerHitPlaneImpl ; - - TestHitPlane->setCellID0(BestHit->getCellID0()) ; - TestHitPlane->setPosition(BestHit->getPosition()); - TestHitPlane->setdU(dU_spres); - TestHitPlane->setdV(dV_spres); - - - isSuccessful2 = marlin_trk->addAndFit( TestHitPlane, chi2_increment, _Max_Chi2_Incr ) == IMarlinTrack::success; - //isSuccessful2 = marlin_trk->addAndFit( BestHit, chi2_increment, _Max_Chi2_Incr ) == IMarlinTrack::success; - - TotalSITHits++; - - if ( isSuccessful2 ){ - - streamlog_out(DEBUG4) << " successful fit " << std::endl ; - - trkHits.push_back(BestHit) ; - - //usedSiHits.push_back(BestHit) ; - - streamlog_out(DEBUG4) << " hit added " << BestHit << std::endl ; - - SITHitsPerTrk++; - SITHitsFitted++; - - HitsInLayer.erase( HitsInLayer.begin() + pointer ) ; - - } - - else{ - - SITHitsNonFitted++; - - } - - delete TestHitPlane ; - - } // condition for found hit ends - HitsInLayer.clear(); - } // end of loop on layer i - - streamlog_out(DEBUG4) << "LOOP" << iL << " ends "<< std::endl; - streamlog_out(DEBUG4) << "###########$$$$$$$$$$##############" << std::endl; - } - //track - hit association fini - - } // successful propagation - - } // loop to all SIT layers - - - } // condition for SIT digitised hits collection - - streamlog_out(DEBUG4) << " no of hits in the track (after adding SIT hits) " << trkHits.size() << " SIT hits added " << SITHitsPerTrk << " event " << _n_evt<< std::endl; - - - // refitted track collection creation - - if (testFlag==1){ - - - TrackStateImpl* trkState = new TrackStateImpl() ; - double chi2_fin = 0 ; - int ndf_fin = 0 ; - - marlin_trk->getTrackState(*trkState, chi2_fin, ndf_fin); - - - const FloatVec& covMatrix = trkState->getCovMatrix(); - - - IMPL::TrackImpl* refittedTrack = new IMPL::TrackImpl(); - - - //----------------------------------------------------------------------------------------------------------------------- - // final refit of the track - std::vector< std::pair > r2_values; - r2_values.reserve(trkHits.size()); - - streamlog_out(DEBUG4) << " size of hits vector thats gonna be added to the output track " << trkHits.size() << std::endl ; - - for (TrackerHitVec::iterator it=trkHits.begin(); it!=trkHits.end(); ++it) { - EVENT::TrackerHit* h = *it; - float r2 = h->getPosition()[0]*h->getPosition()[0]+h->getPosition()[1]*h->getPosition()[1]; - r2_values.push_back(std::make_pair(r2, *it)); - } - - sort(r2_values.begin(),r2_values.end()); - - trkHits.clear(); - trkHits.reserve(r2_values.size()); - - for (std::vector< std::pair >::iterator it=r2_values.begin(); it!=r2_values.end(); ++it) { - trkHits.push_back(it->second); - } - - - // bool fit_backwards = IMarlinTrack::backward; - bool fit_forwards = IMarlinTrack::forward; - MarlinTrk::IMarlinTrack* marlinTrk = _trksystem->createTrack(); - // int error = 0; - - try { - - // int error = - MarlinTrk::createFinalisedLCIOTrack(marlinTrk, trkHits, refittedTrack, fit_forwards, covMatrix, _bField, _maxChi2PerHit); - - } catch (...) { - - delete refittedTrack; - delete marlinTrk; - - throw ; - - } - - - // fitting finished get hit in the fit - - std::vector > hits_in_fit; - std::vector > outliers ; - - // remember the hits are ordered in the order in which they were fitted - // here we are fitting inwards to the first is the last and vice verse - - marlinTrk->getHitsInFit(hits_in_fit); - - if( hits_in_fit.size() < 3 ) { - streamlog_out(DEBUG3) << "RefitProcessor: Less than 3 hits in fit: Track Discarded. Number of hits = " << trkHits.size() << std::endl; - delete marlinTrk ; - delete refittedTrack; - continue ; - } - - - std::vector all_hits; - all_hits.reserve(300); - - - for ( unsigned ihit = 0; ihit < hits_in_fit.size(); ++ihit) { - all_hits.push_back(hits_in_fit[ihit].first); - } - - UTIL::BitField64 cellID_encoder( lcio::LCTrackerCellID::encoding_string() ) ; - - MarlinTrk::addHitNumbersToTrack(refittedTrack, all_hits, true, cellID_encoder); - - marlinTrk->getOutliers(outliers); - - for ( unsigned ihit = 0; ihit < outliers.size(); ++ihit) { - all_hits.push_back(outliers[ihit].first); - } - - MarlinTrk::addHitNumbersToTrack(refittedTrack, all_hits, false, cellID_encoder); - - delete marlinTrk; - - int nhits_in_vxd = refittedTrack->subdetectorHitNumbers()[ 2 * lcio::ILDDetID::VXD - 2 ]; - int nhits_in_ftd = refittedTrack->subdetectorHitNumbers()[ 2 * lcio::ILDDetID::FTD - 2 ]; - int nhits_in_sit = refittedTrack->subdetectorHitNumbers()[ 2 * lcio::ILDDetID::SIT - 2 ]; - int nhits_in_tpc = refittedTrack->subdetectorHitNumbers()[ 2 * lcio::ILDDetID::TPC - 2 ]; - int nhits_in_set = refittedTrack->subdetectorHitNumbers()[ 2 * lcio::ILDDetID::SET - 2 ]; - - - streamlog_out( DEBUG4 ) << " Hit numbers for Track "<< refittedTrack->id() << ": " - << " vxd hits = " << nhits_in_vxd - << " ftd hits = " << nhits_in_ftd - << " sit hits = " << nhits_in_sit - << " tpc hits = " << nhits_in_tpc - << " set hits = " << nhits_in_set - << std::endl; - - - if (nhits_in_vxd > 0) refittedTrack->setTypeBit( lcio::ILDDetID::VXD ) ; - if (nhits_in_ftd > 0) refittedTrack->setTypeBit( lcio::ILDDetID::FTD ) ; - if (nhits_in_sit > 0) refittedTrack->setTypeBit( lcio::ILDDetID::SIT ) ; - if (nhits_in_tpc > 0) refittedTrack->setTypeBit( lcio::ILDDetID::TPC ) ; - if (nhits_in_set > 0) refittedTrack->setTypeBit( lcio::ILDDetID::SET ) ; - - trackCandidates.push_back(refittedTrack) ; // trackCandidates vector stores all the candidate tracks of the event - - }// end of the creation of the refitted track collection - } // good fit status - } // good initialisation status - } //minimum acceptable TPC hits - + + float chi2_ndf = chisquare / (1.0 * ndof); + + // accept only tracks with > minimum hits at the TPC & chi2/ndf < maximum cut & Pt cut? + if (chi2_ndf < _chi2NDoFCut) { + + streamlog_out(DEBUG4) << "%%%% Checking track " << track->id() << " chi2/ndf " << chi2_ndf << " cut " + << _chi2NDoFCut << " D0 " << track->getD0() << " Z0 " << track->getZ0() << std::endl; + + // sort the hits in R, so here we are assuming that the track came from the IP and that we want to fit out to + // in. + sort(trkHits.begin(), trkHits.end(), ExtrToSIT::compare_r()); + + for (EVENT::TrackerHitVec::iterator it = trkHits.begin(); it != trkHits.end(); ++it) { + marlin_trk->addHit(*it); + } + + // int init_status = marlin_trk->initialise( IMarlinTrack::backward ) ; + // int init_status = FitInit(trkHits, marlin_trk) ; // alternative way to initialise the + // marlin_trk object + int init_status = FitInit2(track, marlin_trk); + + if (init_status == 0) { + + streamlog_out(DEBUG4) << "track initialised " << std::endl; + + int fit_status = marlin_trk->fit(); + + if (fit_status == 0) { + + int testFlag = 0; + + // some testing + TrackStateImpl testTS; + double chi2_test = 0; + int ndf_test = 0; + int testTrackState = marlin_trk->getTrackState(testTS, chi2_test, ndf_test); + if (testTrackState == 0) { + const float* testpivot = testTS.getReferencePoint(); + streamlog_out(DEBUG4) << "test pivot " << testpivot[0] << ", " << testpivot[1] << ", " << testpivot[2] + << " - r: " << sqrt(testpivot[0] * testpivot[0] + testpivot[1] * testpivot[1]) + << std::endl; + } + + streamlog_out(DEBUG3) << "###########$$$$$$$$$$##############" << std::endl; + + // now we have a track constisting only of TPC hits + + // 1) extrapolate to outer most SIT layer + + // 2) select best hit candidate + + // 3) marlin_trk->addAndFit(hit,max_chi2_increment); + + // 3a) select best hit candidate on n+1 layer + + // 3b) marlin_trk->addAndFit(hit,max_chi2_increment); + + // 4) loop and repeat for other layers, plus VXD + + // 5) all hits have been added, propogate to IP for instance + + //_________________________________________________________ + + // marlin_trk->smooth(trkHits.back()); + + double chi2 = 0; + int ndf = 0; + + Vector3D xing_point; + + UTIL::BitField64 encoder(lcio::LCTrackerCellID::encoding_string()); + + encoder.reset(); // reset to 0 + + int layerID = encoder.lowWord(); + int elementID = 0; + + //________________________________________________________________________________________________________ + // + // starting loop to SIT layers + //________________________________________________________________________________________________________ + + // for loop to all SIT layers + + for (unsigned int iL = 0; iL < _nSITLayers; iL++) { + + if (sitHitsCol != 0) { + + streamlog_out(DEBUG4) << " Do I come into the loop " << std::endl; + + streamlog_out(DEBUG4) << "LOOP" << iL << " begins " << std::endl; + + encoder[lcio::LCTrackerCellID::subdet()] = ILDDetID::SIT; + + if (_dirInsideOut) + encoder[lcio::LCTrackerCellID::layer()] = iL; // in case we propagate outwards from VXD + else + encoder[lcio::LCTrackerCellID::layer()] = 3 - iL; // in case we propagate inwards from TPC + + layerID = encoder.lowWord(); + + TrackStateImpl trkState; + + if (marlin_trk->propagateToLayer(layerID, trkState, chi2, ndf, elementID, IMarlinTrack::modeClosest) == + MarlinTrk::IMarlinTrack::success) { + + const FloatVec& covLCIO = trkState.getCovMatrix(); + const float* pivot = trkState.getReferencePoint(); + + streamlog_out(DEBUG4) << " kaltest track parameters: " + << " chi2/ndf " << chi2 / ndf << " chi2 " << chi2 << std::endl + + << "\t D0 " << trkState.getD0() << "[+/-" << sqrt(covLCIO[0]) << "] " + << "\t Phi :" << trkState.getPhi() << "[+/-" << sqrt(covLCIO[2]) << "] " + << "\t Omega " << trkState.getOmega() << "[+/-" << sqrt(covLCIO[5]) << "] " + << "\t Z0 " << trkState.getZ0() << "[+/-" << sqrt(covLCIO[9]) << "] " + << "\t tan(Lambda) " << trkState.getTanLambda() << "[+/-" << sqrt(covLCIO[14]) + << "] " + + << "\t pivot : [" << pivot[0] << ", " << pivot[1] << ", " << pivot[2] + << " - r: " << sqrt(pivot[0] * pivot[0] + pivot[1] * pivot[1]) << "]" + << std::endl; + + double r = sqrt(pivot[0] * pivot[0] + pivot[1] * pivot[1]); + + streamlog_out(DEBUG4) << " layer " << 3 - iL << " max search distances Z : Rphi " + << _searchSigma * sqrt(covLCIO[9]) << " : " << _searchSigma * sqrt(covLCIO[0]) + << std::endl; + + //_______________________________________________________________________________________ + // + // track - hit association (just for fun) + + streamlog_out(DEBUG2) << " element ID " << elementID << std::endl; + + if (elementID != 0) { + + testFlag = 1; + + EVENT::TrackerHitVec HitsInLayer; + + float dU_spres = 0; + float dV_spres = 0; + + double chi2_increment = 0; + + for (int iSit = 0; iSit < sitHits; iSit++) { + + TrackerHit* hit = dynamic_cast(sitHitsCol->getElementAt(iSit)); + + streamlog_out(DEBUG2) << " type = " << hit->getType() << std::endl; + + const int celId = hit->getCellID0(); + + streamlog_out(DEBUG1) << " hit cellid0 = " << celId << std::endl; + + int layerNumber = 0; + int ladderNumber = 0; + int sideTest = 0; + int sensorNumber = 0; + + // UTIL::BitField64 encoder( lcio::LCTrackerCellID::encoding_string() ) ; + encoder.setValue(celId); + layerNumber = encoder[lcio::LCTrackerCellID::layer()]; + ladderNumber = encoder[lcio::LCTrackerCellID::module()]; + sideTest = encoder[lcio::LCTrackerCellID::side()]; + sensorNumber = encoder[lcio::LCTrackerCellID::sensor()]; + encoder.reset(); + + // Just to check the element matching between the hit (coming from the digitiser) and the track + // extrapolation element (coming from Mokka) + + // int mokkaLayerNumber = 0 ; + // int mokkaLadderNumber = 0 ; + // int mokkaSideTest = 0 ; + // int mokkaSensorNumber = 0 ; + + encoder.setValue(elementID); + // mokkaLayerNumber = encoder[lcio::LCTrackerCellID::layer()] ; + // mokkaLadderNumber = encoder[lcio::LCTrackerCellID::module()] ; + // mokkaSideTest = encoder[lcio::LCTrackerCellID::side()] ; + // mokkaSensorNumber = encoder[lcio::LCTrackerCellID::sensor()] ; + encoder.reset(); + + streamlog_out(DEBUG2) + << " checking hit : type = " << hit->getType() << " cell ID = " << celId + << " side = " << sideTest << " layer = " << layerNumber << " ladder = " << ladderNumber + << " sensor = " << sensorNumber << std::endl; + + streamlog_out(DEBUG2) + << " the element id where the hit is found " << celId + << " the element id where the track is extrapolated " << elementID << std::endl; + + if (celId == elementID) { // cause elementID does not give sensor-side infos... + // if (mokkaLayerNumber==layerNumber && mokkaLadderNumber==ladderNumber){ + streamlog_out(DEBUG2) + << " We found a hit at the right element with type : " << hit->getType() + << " side = " << sideTest << " layer = " << layerNumber << " ladder = " << ladderNumber + << " sensor = " << sensorNumber << std::endl; + streamlog_out(DEBUG3) + << " We found a hit at the right element with type : " << hit->getType() << std::endl; + HitsInLayer.push_back(hit); + } + } // end loop on hits + /* + // ------------------ in order to obtain sensors single point resolution --------------------- + if (_pixelSIT){ + for (int jj=0;jj( sitHitsCol->getElementAt( jj ) ) ; + if (hitplane){ + const int celId_spres = hitplane->getCellID0() ; + + if (celId_spres==elementID){ + dU_spres = hitplane->getdU(); + dV_spres = hitplane->getdV(); + //streamlog_out(DEBUG4) << " U resolution = " << dU_spres << " V resolution = " << dV_spres + << std::endl ; + } + } + } + } + */ + // if (!_pixelSIT){ + // Alternative way to assign the sensor s.p. resolution until I understand what's going on with + // that + dU_spres = 0.007; + dV_spres = 0.05; + //} + // --------------------------------------------------------------------------------------------- + + if (HitsInLayer.size() != 0) { + + TrackerHit* BestHit; + bool BestHitFound = false; + + int pointer = 0; + int PossibleHits = 0; + double DimDist = 0; + + streamlog_out(DEBUG4) + << " calling selectbestcandidatelimited with value for possible hits = " << PossibleHits + << std::endl; + + SelectBestCandidateLimited(HitsInLayer, pivot, BestHit, covLCIO, r, BestHitFound, _searchSigma, + pointer, PossibleHits, dU_spres, dV_spres, DimDist, usedSiHits); + + if (BestHitFound) { // when selection is restricted to an area maybe we will not find an + // appropriate hit + + bool isSuccessful2 = false; + + streamlog_out(DEBUG4) << " Best hit found: call add and fit " << std::endl; + + TrackerHitPlaneImpl* TestHitPlane = new TrackerHitPlaneImpl; + + TestHitPlane->setCellID0(BestHit->getCellID0()); + TestHitPlane->setPosition(BestHit->getPosition()); + TestHitPlane->setdU(dU_spres); + TestHitPlane->setdV(dV_spres); + + isSuccessful2 = marlin_trk->addAndFit(TestHitPlane, chi2_increment, _Max_Chi2_Incr) == + IMarlinTrack::success; + // isSuccessful2 = marlin_trk->addAndFit( BestHit, chi2_increment, _Max_Chi2_Incr ) == + // IMarlinTrack::success; + + TotalSITHits++; + + if (isSuccessful2) { + + streamlog_out(DEBUG4) << " successful fit " << std::endl; + + trkHits.push_back(BestHit); + + // usedSiHits.push_back(BestHit) ; + + streamlog_out(DEBUG4) << " hit added " << BestHit << std::endl; + + SITHitsPerTrk++; + SITHitsFitted++; + + HitsInLayer.erase(HitsInLayer.begin() + pointer); + + } + + else { + + SITHitsNonFitted++; + } + + delete TestHitPlane; + + } // condition for found hit ends + HitsInLayer.clear(); + } // end of loop on layer i + + streamlog_out(DEBUG4) << "LOOP" << iL << " ends " << std::endl; + streamlog_out(DEBUG4) << "###########$$$$$$$$$$##############" << std::endl; + } + // track - hit association fini + + } // successful propagation + + } // loop to all SIT layers + + } // condition for SIT digitised hits collection + + streamlog_out(DEBUG4) << " no of hits in the track (after adding SIT hits) " << trkHits.size() + << " SIT hits added " << SITHitsPerTrk << " event " << _n_evt << std::endl; + + // refitted track collection creation + + if (testFlag == 1) { + + TrackStateImpl* trkState = new TrackStateImpl(); + double chi2_fin = 0; + int ndf_fin = 0; + + marlin_trk->getTrackState(*trkState, chi2_fin, ndf_fin); + + const FloatVec& covMatrix = trkState->getCovMatrix(); + + IMPL::TrackImpl* refittedTrack = new IMPL::TrackImpl(); + + //----------------------------------------------------------------------------------------------------------------------- + // final refit of the track + std::vector> r2_values; + r2_values.reserve(trkHits.size()); + + streamlog_out(DEBUG4) << " size of hits vector thats gonna be added to the output track " + << trkHits.size() << std::endl; + + for (TrackerHitVec::iterator it = trkHits.begin(); it != trkHits.end(); ++it) { + EVENT::TrackerHit* h = *it; + float r2 = h->getPosition()[0] * h->getPosition()[0] + h->getPosition()[1] * h->getPosition()[1]; + r2_values.push_back(std::make_pair(r2, *it)); + } + + sort(r2_values.begin(), r2_values.end()); + + trkHits.clear(); + trkHits.reserve(r2_values.size()); + + for (std::vector>::iterator it = r2_values.begin(); + it != r2_values.end(); ++it) { + trkHits.push_back(it->second); + } + + // bool fit_backwards = IMarlinTrack::backward; + bool fit_forwards = IMarlinTrack::forward; + MarlinTrk::IMarlinTrack* marlinTrk = _trksystem->createTrack(); + // int error = 0; + + try { + + // int error = + MarlinTrk::createFinalisedLCIOTrack(marlinTrk, trkHits, refittedTrack, fit_forwards, covMatrix, _bField, + _maxChi2PerHit); + + } catch (...) { + + delete refittedTrack; + delete marlinTrk; + + throw; + } + + // fitting finished get hit in the fit + + std::vector> hits_in_fit; + std::vector> outliers; + + // remember the hits are ordered in the order in which they were fitted + // here we are fitting inwards to the first is the last and vice verse + + marlinTrk->getHitsInFit(hits_in_fit); + + if (hits_in_fit.size() < 3) { + streamlog_out(DEBUG3) << "RefitProcessor: Less than 3 hits in fit: Track Discarded. Number of hits = " + << trkHits.size() << std::endl; + delete marlinTrk; + delete refittedTrack; + continue; + } + + std::vector all_hits; + all_hits.reserve(300); + + for (unsigned ihit = 0; ihit < hits_in_fit.size(); ++ihit) { + all_hits.push_back(hits_in_fit[ihit].first); + } + + UTIL::BitField64 cellID_encoder(lcio::LCTrackerCellID::encoding_string()); + + MarlinTrk::addHitNumbersToTrack(refittedTrack, all_hits, true, cellID_encoder); + + marlinTrk->getOutliers(outliers); + + for (unsigned ihit = 0; ihit < outliers.size(); ++ihit) { + all_hits.push_back(outliers[ihit].first); + } + + MarlinTrk::addHitNumbersToTrack(refittedTrack, all_hits, false, cellID_encoder); + + delete marlinTrk; + + int nhits_in_vxd = refittedTrack->subdetectorHitNumbers()[2 * lcio::ILDDetID::VXD - 2]; + int nhits_in_ftd = refittedTrack->subdetectorHitNumbers()[2 * lcio::ILDDetID::FTD - 2]; + int nhits_in_sit = refittedTrack->subdetectorHitNumbers()[2 * lcio::ILDDetID::SIT - 2]; + int nhits_in_tpc = refittedTrack->subdetectorHitNumbers()[2 * lcio::ILDDetID::TPC - 2]; + int nhits_in_set = refittedTrack->subdetectorHitNumbers()[2 * lcio::ILDDetID::SET - 2]; + + streamlog_out(DEBUG4) << " Hit numbers for Track " << refittedTrack->id() << ": " + << " vxd hits = " << nhits_in_vxd << " ftd hits = " << nhits_in_ftd + << " sit hits = " << nhits_in_sit << " tpc hits = " << nhits_in_tpc + << " set hits = " << nhits_in_set << std::endl; + + if (nhits_in_vxd > 0) + refittedTrack->setTypeBit(lcio::ILDDetID::VXD); + if (nhits_in_ftd > 0) + refittedTrack->setTypeBit(lcio::ILDDetID::FTD); + if (nhits_in_sit > 0) + refittedTrack->setTypeBit(lcio::ILDDetID::SIT); + if (nhits_in_tpc > 0) + refittedTrack->setTypeBit(lcio::ILDDetID::TPC); + if (nhits_in_set > 0) + refittedTrack->setTypeBit(lcio::ILDDetID::SET); + + trackCandidates.push_back( + refittedTrack); // trackCandidates vector stores all the candidate tracks of the event + + } // end of the creation of the refitted track collection + } // good fit status + } // good initialisation status + } // minimum acceptable TPC hits + delete marlin_trk; - - } // for loop to the tracks - - //------------------------------------------------------------------------------------------------------- - - for (unsigned int i=0; i < trackCandidates.size(); i++){ - - TrackImpl* SiliconRefTrack = dynamic_cast< TrackImpl* >( trackCandidates[i] ); - - trackVec->addElement( SiliconRefTrack ); - + + } // for loop to the tracks + + //------------------------------------------------------------------------------------------------------- + + for (unsigned int i = 0; i < trackCandidates.size(); i++) { + + TrackImpl* SiliconRefTrack = dynamic_cast(trackCandidates[i]); + + trackVec->addElement(SiliconRefTrack); } - + // for debugging reasons /* for (int ii=0; iiclear(); - //evt->addCollection( SiTrkCol , _siTrkColName ) ; - evt->addCollection( trackVec , _output_track_col_name ) ; - //evt->addCollection( trackRelVec , _output_track_rel_name) ; - } // track collection no empty - - ++_n_evt ; - - //cout << " event " << _n_evt << std::endl ; - -} + // PtTest->clear(); + // evt->addCollection( SiTrkCol , _siTrkColName ) ; + evt->addCollection(trackVec, _output_track_col_name); + // evt->addCollection( trackRelVec , _output_track_rel_name) ; + } // track collection no empty + ++_n_evt; + // cout << " event " << _n_evt << std::endl ; +} -void ExtrToSIT::check( LCEvent* ) { +void ExtrToSIT::check(LCEvent*) { // nothing to check here - could be used to fill checkplots in reconstruction processor } +void ExtrToSIT::end() { -void ExtrToSIT::end(){ - - streamlog_out(DEBUG) << "ExtrToSIT::end() " << name() - << " processed " << _n_evt << " events in " << _n_run << " runs " - << std::endl ; + streamlog_out(DEBUG) << "ExtrToSIT::end() " << name() << " processed " << _n_evt << " events in " << _n_run + << " runs " << std::endl; - streamlog_out(DEBUG4) << " SIT hits considered for track-hit association " << TotalSITHits << " how many of them were matched and fitted successfully ? " << SITHitsFitted << " for how many the fit failed ? " << SITHitsNonFitted << std::endl ; - + streamlog_out(DEBUG4) << " SIT hits considered for track-hit association " << TotalSITHits + << " how many of them were matched and fitted successfully ? " << SITHitsFitted + << " for how many the fit failed ? " << SITHitsNonFitted << std::endl; } +void ExtrToSIT::SelectBestCandidateLimited(EVENT::TrackerHitVec& HitsInLayer, const float*& pivot, + EVENT::TrackerHit*& BestHit, const FloatVec& covLCIO, double& radius, + bool& BestHitFound, double& sigma, int& pointer, int& PossibleHits, + float& dU, float& dV, double& DimDist, TrackerHitVec& /*usedSiHits*/) { + BestHitFound = false; -void ExtrToSIT::SelectBestCandidateLimited(EVENT::TrackerHitVec &HitsInLayer, const float* &pivot, EVENT::TrackerHit* &BestHit, const FloatVec& covLCIO, double& radius, bool &BestHitFound, double &sigma, int &pointer, int &PossibleHits, float &dU, float &dV, double &DimDist, TrackerHitVec& /*usedSiHits*/) -{ + int NoOfHits = HitsInLayer.size(); - BestHitFound = false ; + double MaxDistZ = sigma * (sqrt(covLCIO[9] + dV * dV)); + double MaxDistRphi = sigma * (sqrt(covLCIO[0] + dU * dU)); + // double 3Ddist = 0; - int NoOfHits = HitsInLayer.size(); + streamlog_out(DEBUG4) << " sensor single point resolution Z : Rphi " << dV << " : " << dU << " at radius " << radius + << std::endl; - double MaxDistZ = sigma*(sqrt( covLCIO[9] + dV*dV)) ; - double MaxDistRphi = sigma*(sqrt( covLCIO[0] + dU*dU)) ; - //double 3Ddist = 0; + for (int i = 0; i < NoOfHits; i++) { - streamlog_out(DEBUG4) << " sensor single point resolution Z : Rphi " << dV << " : " << dU << " at radius " << radius << std::endl; + EVENT::TrackerHit* CandidateHit = HitsInLayer.at(i); - for (int i=0;igetPosition()[0]; double posY = CandidateHit->getPosition()[1]; double posZ = CandidateHit->getPosition()[2]; - - distZ = fabs(posZ-pivot[2]); - distRphi = sqrt( (posX-pivot[0])*(posX-pivot[0]) + (posY-pivot[1])*(posY-pivot[1]) ) ; - - streamlog_out(DEBUG2) << " maximum acceptable distances for track-hit matching Z : Rphi " << MaxDistZ << " : " << MaxDistRphi << " at radius " << radius << std::endl; - - if ( distZ < MaxDistZ && distRphi < MaxDistRphi ){ - PossibleHits++; + + distZ = fabs(posZ - pivot[2]); + distRphi = sqrt((posX - pivot[0]) * (posX - pivot[0]) + (posY - pivot[1]) * (posY - pivot[1])); + + streamlog_out(DEBUG2) << " maximum acceptable distances for track-hit matching Z : Rphi " << MaxDistZ << " : " + << MaxDistRphi << " at radius " << radius << std::endl; + + if (distZ < MaxDistZ && distRphi < MaxDistRphi) { + PossibleHits++; BestHit = CandidateHit; - BestHitFound = true ; - streamlog_out(DEBUG4) << " found appropriate hit at distance in Z : Rphi " << distZ << " : " << distRphi << std::endl; + BestHitFound = true; + streamlog_out(DEBUG4) << " found appropriate hit at distance in Z : Rphi " << distZ << " : " << distRphi + << std::endl; MaxDistZ = distZ; MaxDistRphi = distRphi; - pointer = i ; - DimDist = sqrt((distZ*distZ) + (distRphi*distRphi)); + pointer = i; + DimDist = sqrt((distZ * distZ) + (distRphi * distRphi)); } } - streamlog_out(DEBUG4) << " No of candidate hits to be associated to the track = " << PossibleHits << std::endl ; - + streamlog_out(DEBUG4) << " No of candidate hits to be associated to the track = " << PossibleHits << std::endl; } +LCCollection* ExtrToSIT::GetCollection(LCEvent* evt, std::string colName) { -LCCollection* ExtrToSIT::GetCollection( LCEvent * evt, std::string colName ){ - LCCollection* col = NULL; - - try{ - col = evt->getCollection( colName.c_str() ) ; - streamlog_out( DEBUG3 ) << " --> " << colName.c_str() << " track collection found in event = " << col << " number of elements " << col->getNumberOfElements() << std::endl; - } - catch(DataNotAvailableException &e){ - streamlog_out( DEBUG3 ) << " --> " << colName.c_str() << " collection absent in event" << std::endl; + + try { + col = evt->getCollection(colName.c_str()); + streamlog_out(DEBUG3) << " --> " << colName.c_str() << " track collection found in event = " << col + << " number of elements " << col->getNumberOfElements() << std::endl; + } catch (DataNotAvailableException& e) { + streamlog_out(DEBUG3) << " --> " << colName.c_str() << " collection absent in event" << std::endl; } - - return col; - + + return col; } -LCRelationNavigator* ExtrToSIT::GetRelations(LCEvent * evt , std::string RelName ) { - - LCRelationNavigator* nav = NULL ; - - try{ - nav = new LCRelationNavigator(evt->getCollection( RelName.c_str() )); - streamlog_out( DEBUG2 ) << "ExtrToSIT --> " << RelName << " track relation collection in event = " << nav << std::endl; - } - catch(DataNotAvailableException &e){ - streamlog_out( DEBUG2 ) << "ExtrToSIT --> " << RelName.c_str() << " track relation collection absent in event" << std::endl; +LCRelationNavigator* ExtrToSIT::GetRelations(LCEvent* evt, std::string RelName) { + + LCRelationNavigator* nav = NULL; + + try { + nav = new LCRelationNavigator(evt->getCollection(RelName.c_str())); + streamlog_out(DEBUG2) << "ExtrToSIT --> " << RelName << " track relation collection in event = " << nav + << std::endl; + } catch (DataNotAvailableException& e) { + streamlog_out(DEBUG2) << "ExtrToSIT --> " << RelName.c_str() << " track relation collection absent in event" + << std::endl; } - + return nav; - } +int ExtrToSIT::FitInit(std::vector trackerHits, MarlinTrk::IMarlinTrack* _marlinTrk) { + + if (trackerHits.size() < 3) { + streamlog_out(ERROR) << "<<<<<< FitInit: Shortage of Hits! nhits = " << trackerHits.size() << " >>>>>>>" + << std::endl; + return IMarlinTrack::error; + } + + // initialise with space-points not strips + // make a helix from 3 hits to get a trackstate + const double* x1 = trackerHits[0]->getPosition(); + const double* x2 = trackerHits[trackerHits.size() / 2]->getPosition(); + const double* x3 = trackerHits.back()->getPosition(); + + double r1 = sqrt(x1[0] * x1[0] + x1[1] * x1[1]); + double r2 = sqrt(x2[0] * x2[0] + x2[1] * x2[1]); + double r3 = sqrt(x3[0] * x3[0] + x3[1] * x3[1]); + streamlog_out(DEBUG4) << " Radii of hits used for initialisation: " << r1 << ", " << r2 << " and " << r3 << std::endl; + + HelixTrack helixTrack(x1, x2, x3, _bField, HelixTrack::forwards); -int ExtrToSIT::FitInit( std::vector < TrackerHit* > trackerHits , MarlinTrk::IMarlinTrack* _marlinTrk ){ + helixTrack.moveRefPoint(0.0, 0.0, 0.0); - - if ( trackerHits.size() < 3 ){ - streamlog_out( ERROR) << "<<<<<< FitInit: Shortage of Hits! nhits = " << trackerHits.size() << " >>>>>>>" << std::endl; - return IMarlinTrack::error ; + const float referencePoint[3] = {float(helixTrack.getRefPointX()), float(helixTrack.getRefPointY()), + float(helixTrack.getRefPointZ())}; + + EVENT::FloatVec covMatrix; + + covMatrix.resize(15); + + for (unsigned icov = 0; icov < covMatrix.size(); ++icov) { + covMatrix[icov] = 0; } - - // initialise with space-points not strips - // make a helix from 3 hits to get a trackstate - const double* x1 = trackerHits[0]->getPosition(); - const double* x2 = trackerHits[ trackerHits.size()/2 ]->getPosition(); - const double* x3 = trackerHits.back()->getPosition(); - - - double r1 = sqrt(x1[0]*x1[0]+x1[1]*x1[1]); - double r2 = sqrt(x2[0]*x2[0]+x2[1]*x2[1]); - double r3 = sqrt(x3[0]*x3[0]+x3[1]*x3[1]); - streamlog_out(DEBUG4) << " Radii of hits used for initialisation: " << r1 << ", " << r2 << " and " << r3 << std::endl ; - - - HelixTrack helixTrack( x1, x2, x3, _bField, HelixTrack::forwards ); - - helixTrack.moveRefPoint(0.0, 0.0, 0.0); - - const float referencePoint[3] = { float( helixTrack.getRefPointX()) , float(helixTrack.getRefPointY()) , float(helixTrack.getRefPointZ()) }; - - - - EVENT::FloatVec covMatrix; - - covMatrix.resize(15); - - for (unsigned icov = 0; icovinitialise( trackState, _bField, IMarlinTrack::backward ) ; - - return IMarlinTrack::success ; -} + covMatrix[0] = (1.e6); // sigma_d0^2 + covMatrix[2] = (1.e2); // sigma_phi0^2 + covMatrix[5] = (1.e-4); // sigma_omega^2 + covMatrix[9] = (1.e6); // sigma_z0^2 + covMatrix[14] = (1.e2); // sigma_tanl^2 + + TrackStateImpl trackState(TrackState::AtOther, helixTrack.getD0(), helixTrack.getPhi0(), helixTrack.getOmega(), + helixTrack.getZ0(), helixTrack.getTanLambda(), covMatrix, referencePoint); + _marlinTrk->initialise(trackState, _bField, IMarlinTrack::backward); + return IMarlinTrack::success; +} +int ExtrToSIT::FitInit2(Track* track, MarlinTrk::IMarlinTrack* _marlinTrk) { -int ExtrToSIT::FitInit2( Track* track, MarlinTrk::IMarlinTrack* _marlinTrk ){ + // EVENT::FloatVec covMatrix = track->getCovMatrix(); + TrackStateImpl trackState(TrackState::AtOther, track->getD0(), track->getPhi(), track->getOmega(), track->getZ0(), + track->getTanLambda(), track->getCovMatrix(), track->getReferencePoint()); - //EVENT::FloatVec covMatrix = track->getCovMatrix(); - - - TrackStateImpl trackState( TrackState::AtOther, - track->getD0(), - track->getPhi(), - track->getOmega(), - track->getZ0(), - track->getTanLambda(), - track->getCovMatrix(), - track->getReferencePoint() - ) ; - - _marlinTrk->initialise( trackState, _bField, IMarlinTrack::forward ) ; - - return IMarlinTrack::success ; - + _marlinTrk->initialise(trackState, _bField, IMarlinTrack::forward); + return IMarlinTrack::success; } diff --git a/source/Refitting/src/ExtrToTracker.cc b/source/Refitting/src/ExtrToTracker.cc index d8e9d90..2285198 100644 --- a/source/Refitting/src/ExtrToTracker.cc +++ b/source/Refitting/src/ExtrToTracker.cc @@ -6,229 +6,170 @@ #include "UTIL/Operators.h" -#include "DD4hep/Detector.h" #include "DD4hep/DD4hepUnits.h" -#include "DDRec/DetectorData.h" #include "DD4hep/DetType.h" +#include "DD4hep/Detector.h" #include "DD4hep/DetectorSelector.h" +#include "DDRec/DetectorData.h" +#include "UTIL/LCTrackerConf.h" #include #include -#include "UTIL/LCTrackerConf.h" #include #include -//CxxUtils/ +// CxxUtils/ #include "fpcompare.h" - - - -using namespace lcio ; -using namespace marlin ; -using namespace MarlinTrk ; +using namespace lcio; +using namespace marlin; +using namespace MarlinTrk; using namespace dd4hep::rec; //------------------------------------------------------------------------------------------ -struct PtSort { // sort tracks wtr to pt - largest first - inline bool operator()( const lcio::LCObject* l, const lcio::LCObject* r) { - return CxxUtils::fpcompare::less( std::abs( ( (const lcio::Track*) l )->getOmega() ), std::abs( ( (const lcio::Track*) r )->getOmega() ) ); +struct PtSort { // sort tracks wtr to pt - largest first + inline bool operator()(const lcio::LCObject* l, const lcio::LCObject* r) { + return CxxUtils::fpcompare::less(std::abs(((const lcio::Track*)l)->getOmega()), + std::abs(((const lcio::Track*)r)->getOmega())); } }; //------------------------------------------------------------------------------------------ -struct InversePtSort { // sort tracks wtr to pt - smallest first - inline bool operator()( const lcio::LCObject* l, const lcio::LCObject* r) { - return CxxUtils::fpcompare::greater( std::abs( ( (const lcio::Track*) l )->getOmega() ), std::abs( ( (const lcio::Track*) r )->getOmega() ) ); +struct InversePtSort { // sort tracks wtr to pt - smallest first + inline bool operator()(const lcio::LCObject* l, const lcio::LCObject* r) { + return CxxUtils::fpcompare::greater(std::abs(((const lcio::Track*)l)->getOmega()), + std::abs(((const lcio::Track*)r)->getOmega())); } }; //------------------------------------------------------------------------------------------ - //------------------------------------------------------------------------------------------ -struct ZSort { // sort track segments wtr to Z - smallest first - inline bool operator()( const lcio::LCObject* l, const lcio::LCObject* r) { - return CxxUtils::fpcompare::less( std::abs( ( (const lcio::Track*) l )->getZ0() ), std::abs( ( (const lcio::Track*) r )->getZ0() ) ); +struct ZSort { // sort track segments wtr to Z - smallest first + inline bool operator()(const lcio::LCObject* l, const lcio::LCObject* r) { + return CxxUtils::fpcompare::less(std::abs(((const lcio::Track*)l)->getZ0()), + std::abs(((const lcio::Track*)r)->getZ0())); } }; //------------------------------------------------------------------------------------------ - -ExtrToTracker aExtrToTracker ; - +ExtrToTracker aExtrToTracker; ExtrToTracker::ExtrToTracker() : Processor("ExtrToTracker") { - + // modify processor description - _description = "ExtrToTracker refits an input VXD track collection and uses IMarlinTrk tools to propagate it to the main tracker" ; - - + _description = "ExtrToTracker refits an input VXD track collection and uses IMarlinTrk tools to propagate it to the " + "main tracker"; + // register steering parameters: name, description, class-variable, default value - - registerInputCollection( LCIO::TRACK, - "InputTrackCollectionName" , - "Name of the input track collection" , - _input_track_col_name , - std::string("TruthTracks") ) ; + registerInputCollection(LCIO::TRACK, "InputTrackCollectionName", "Name of the input track collection", + _input_track_col_name, std::string("TruthTracks")); ///////////////////////// StringVec vecDigiHitsDefault; - vecDigiHitsDefault.push_back( "ITrackerHits" ); - vecDigiHitsDefault.push_back( "OTrackerHits" ); - vecDigiHitsDefault.push_back( "ITrackerEndcapHits" ); - vecDigiHitsDefault.push_back( "OTrackerEndcapHits" ); + vecDigiHitsDefault.push_back("ITrackerHits"); + vecDigiHitsDefault.push_back("OTrackerHits"); + vecDigiHitsDefault.push_back("ITrackerEndcapHits"); + vecDigiHitsDefault.push_back("OTrackerEndcapHits"); - registerInputCollections(LCIO::TRACKERHITPLANE, - "vecDigiHits", + registerInputCollections(LCIO::TRACKERHITPLANE, "vecDigiHits", "vector of name of the digi hits collection - need to be syncro with vecSubdetName!", - _vecDigiHits, - vecDigiHitsDefault ); - + _vecDigiHits, vecDigiHitsDefault); StringVec vecSubdetNameDefault; - vecSubdetNameDefault.push_back("InnerTrackerBarrel") ; - vecSubdetNameDefault.push_back("OuterTrackerBarrel") ; - vecSubdetNameDefault.push_back("InnerTrackerEndcap") ; - vecSubdetNameDefault.push_back("OuterTrackerEndcap") ; + vecSubdetNameDefault.push_back("InnerTrackerBarrel"); + vecSubdetNameDefault.push_back("OuterTrackerBarrel"); + vecSubdetNameDefault.push_back("InnerTrackerEndcap"); + vecSubdetNameDefault.push_back("OuterTrackerEndcap"); - registerProcessorParameter( "vecSubdetName" , - "vector of names of all subdetector to exrapolate to" , - _vecSubdetName , - vecSubdetNameDefault ); + registerProcessorParameter("vecSubdetName", "vector of names of all subdetector to exrapolate to", _vecSubdetName, + vecSubdetNameDefault); ///////////////////////// + registerOutputCollection(LCIO::TRACKERHITPLANE, "OutputNotUsedHitCollectionName", + "Name of the output collection with the not used hits", _output_not_used_col_name, + std::string("NotUsedHits")); - registerOutputCollection( LCIO::TRACKERHITPLANE, - "OutputNotUsedHitCollectionName" , - "Name of the output collection with the not used hits" , - _output_not_used_col_name , - std::string("NotUsedHits") ) ; - - - registerOutputCollection( LCIO::TRACK, - "OutputTrackCollectionName" , - "Name of the output track collection" , - _output_track_col_name , - std::string("ExtrTracks") ) ; - - - registerProcessorParameter("MultipleScatteringOn", - "Use MultipleScattering in Fit", - _MSOn, - bool(true)); - - registerProcessorParameter("EnergyLossOn", - "Use Energy Loss in Fit", - _ElossOn, - bool(true)); - - registerProcessorParameter("SmoothOn", - "Smooth All Mesurement Sites in Fit", - _SmoothOn, - bool(false)); - - registerProcessorParameter("Max_Chi2_Incr", - "maximum allowable chi2 increment when moving from one site to another", - _Max_Chi2_Incr, - double(1000)); - - registerProcessorParameter("SearchSigma", - "times d0(Z0) acceptable from track extrapolation point", - _searchSigma, + registerOutputCollection(LCIO::TRACK, "OutputTrackCollectionName", "Name of the output track collection", + _output_track_col_name, std::string("ExtrTracks")); + + registerProcessorParameter("MultipleScatteringOn", "Use MultipleScattering in Fit", _MSOn, bool(true)); + + registerProcessorParameter("EnergyLossOn", "Use Energy Loss in Fit", _ElossOn, bool(true)); + + registerProcessorParameter("SmoothOn", "Smooth All Mesurement Sites in Fit", _SmoothOn, bool(false)); + + registerProcessorParameter("Max_Chi2_Incr", "maximum allowable chi2 increment when moving from one site to another", + _Max_Chi2_Incr, double(1000)); + + registerProcessorParameter("SearchSigma", "times d0(Z0) acceptable from track extrapolation point", _searchSigma, double(3)); - registerProcessorParameter("PerformFinalRefit", - "perform a final refit of the extrapolated track", - _performFinalRefit, - bool(false)); + registerProcessorParameter("PerformFinalRefit", "perform a final refit of the extrapolated track", _performFinalRefit, + bool(false)); registerProcessorParameter("extrapolateForward", "if true extrapolation in the forward direction (in-out), otherwise backward (out-in)", - _extrapolateForward, - bool(true)); - + _extrapolateForward, bool(true)); } +void ExtrToTracker::init() { -void ExtrToTracker::init() { - + streamlog_out(DEBUG) << " init called " << std::endl; - streamlog_out(DEBUG) << " init called " - << std::endl ; - // usually a good idea to - printParameters() ; - - + printParameters(); + getGeoInfo(); + _trksystem = MarlinTrk::Factory::createMarlinTrkSystem("DDKalTest", 0, ""); - _trksystem = MarlinTrk::Factory::createMarlinTrkSystem( "DDKalTest" , 0 , "" ) ; + /////////////////////////////// + if (_trksystem == 0) { - /////////////////////////////// - - - if( _trksystem == 0 ){ - - throw EVENT::Exception( std::string(" Cannot initialize MarlinTrkSystem of Type: ") + std::string("DDKalTest" ) ) ; - + throw EVENT::Exception(std::string(" Cannot initialize MarlinTrkSystem of Type: ") + std::string("DDKalTest")); } - - _trksystem->setOption( IMarlinTrkSystem::CFG::useQMS, _MSOn ) ; - _trksystem->setOption( IMarlinTrkSystem::CFG::usedEdx, _ElossOn) ; - _trksystem->setOption( IMarlinTrkSystem::CFG::useSmoothing, _SmoothOn) ; - _trksystem->init() ; - - - _n_run = 0 ; - _n_evt = 0 ; - SITHitsFitted = 0 ; - SITHitsNonFitted = 0 ; - TotalSITHits = 0 ; + _trksystem->setOption(IMarlinTrkSystem::CFG::useQMS, _MSOn); + _trksystem->setOption(IMarlinTrkSystem::CFG::usedEdx, _ElossOn); + _trksystem->setOption(IMarlinTrkSystem::CFG::useSmoothing, _SmoothOn); + _trksystem->init(); + _n_run = 0; + _n_evt = 0; + SITHitsFitted = 0; + SITHitsNonFitted = 0; + TotalSITHits = 0; } +void ExtrToTracker::processRunHeader(LCRunHeader*) { ++_n_run; } -void ExtrToTracker::processRunHeader( LCRunHeader* ) { - - ++_n_run ; -} - -void ExtrToTracker::processEvent( LCEvent * evt ) { - +void ExtrToTracker::processEvent(LCEvent* evt) { - // set the correct configuration for the tracking system for this event - MarlinTrk::TrkSysConfig< MarlinTrk::IMarlinTrkSystem::CFG::useQMS> mson( _trksystem, _MSOn ) ; - MarlinTrk::TrkSysConfig< MarlinTrk::IMarlinTrkSystem::CFG::usedEdx> elosson( _trksystem,_ElossOn) ; - MarlinTrk::TrkSysConfig< MarlinTrk::IMarlinTrkSystem::CFG::useSmoothing> smoothon( _trksystem,_SmoothOn) ; - - //printParameters(); + // set the correct configuration for the tracking system for this event + MarlinTrk::TrkSysConfig mson(_trksystem, _MSOn); + MarlinTrk::TrkSysConfig elosson(_trksystem, _ElossOn); + MarlinTrk::TrkSysConfig smoothon(_trksystem, _SmoothOn); + // printParameters(); //-- note: this will not be printed if compiled w/o MARLINDEBUG=1 ! - - streamlog_out(DEBUG1) << " processing event: " << _n_evt - << std::endl ; - - - // get input collection and relations - LCCollection* input_track_col = this->GetCollection( evt, _input_track_col_name ) ; + streamlog_out(DEBUG1) << " processing event: " << _n_evt << std::endl; - if( input_track_col != 0 ){ - + // get input collection and relations + LCCollection* input_track_col = this->GetCollection(evt, _input_track_col_name); + if (input_track_col != 0) { //////////////////////// @@ -237,489 +178,426 @@ void ExtrToTracker::processEvent( LCEvent * evt ) { //////////////////////// + // establish the track collection that will be created + LCCollectionVec* trackVec = new LCCollectionVec(LCIO::TRACK); - // establish the track collection that will be created - LCCollectionVec* trackVec = new LCCollectionVec( LCIO::TRACK ) ; - - // if we want to point back to the hits we need to set the flag - LCFlagImpl trkFlag(0) ; - trkFlag.setBit( LCIO::TRBIT_HITS ) ; - trackVec->setFlag( trkFlag.getFlag() ) ; - - int nTracks = input_track_col->getNumberOfElements() ; + LCFlagImpl trkFlag(0); + trkFlag.setBit(LCIO::TRBIT_HITS); + trackVec->setFlag(trkFlag.getFlag()); + + int nTracks = input_track_col->getNumberOfElements(); streamlog_out(DEBUG4) << " ######### NO OF TRACKS $$$$$$$$$$ " << nTracks << std::endl; - LCCollectionVec* inputTrackVec = new LCCollectionVec( LCIO::TRACK ) ; - inputTrackVec->setSubset( true ); + LCCollectionVec* inputTrackVec = new LCCollectionVec(LCIO::TRACK); + inputTrackVec->setSubset(true); ////////////////////////////////////////////////////////////////////////////////////////////////////////////// - - for( int n= 0 ; n < nTracks ; ++n ) { - Track* testTrack = dynamic_cast( input_track_col->getElementAt( n ) ) ; - inputTrackVec->addElement( testTrack ); + for (int n = 0; n < nTracks; ++n) { + Track* testTrack = dynamic_cast(input_track_col->getElementAt(n)); + inputTrackVec->addElement(testTrack); } - std::sort( inputTrackVec->begin() , inputTrackVec->end() , PtSort() ) ; - //std::sort( inputTrackVec->begin() , inputTrackVec->end() , InversePtSort() ) ; + std::sort(inputTrackVec->begin(), inputTrackVec->end(), PtSort()); + // std::sort( inputTrackVec->begin() , inputTrackVec->end() , InversePtSort() ) ; + + // loop over the input tracks and refit using KalTest + for (int i = 0; i < nTracks; ++i) { + int SITHitsPerTrk = 0; - // loop over the input tracks and refit using KalTest - for(int i=0; i< nTracks ; ++i) { + Track* track = dynamic_cast(inputTrackVec->getElementAt(i)); - int SITHitsPerTrk = 0 ; - - Track* track = dynamic_cast( inputTrackVec->getElementAt( i ) ) ; - MarlinTrk::IMarlinTrack* marlin_trk = _trksystem->createTrack(); - - EVENT::TrackerHitVec trkHits = track->getTrackerHits() ; - - streamlog_out(DEBUG2) <<"---- tracks n = "<< i << " n VTX hits = "<< trkHits.size() << std::endl; - - // sort the hits in R, so here we are assuming that the track came from the IP - - sort(trkHits.begin(), trkHits.end(), ExtrToTracker::compare_r() ); - - double z_last_hit = (trkHits.back())->getPosition()[2]; //mm - + + EVENT::TrackerHitVec trkHits = track->getTrackerHits(); + + streamlog_out(DEBUG2) << "---- tracks n = " << i << " n VTX hits = " << trkHits.size() << std::endl; + + // sort the hits in R, so here we are assuming that the track came from the IP + + sort(trkHits.begin(), trkHits.end(), ExtrToTracker::compare_r()); + + double z_last_hit = (trkHits.back())->getPosition()[2]; // mm + EVENT::TrackerHitVec::iterator it = trkHits.begin(); - - for( it = trkHits.begin() ; it != trkHits.end() ; ++it ){ - marlin_trk->addHit(*it); + + for (it = trkHits.begin(); it != trkHits.end(); ++it) { + marlin_trk->addHit(*it); } - - int init_status = FitInit2(track, marlin_trk) ; - - if (init_status==0) { - - - - streamlog_out(DEBUG4) << "track initialised " << std::endl ; - - int fit_status = marlin_trk->fit(); - - if ( fit_status == 0 ){ - - - double chi2 = 0 ; - int ndf = 0 ; - TrackStateImpl trkState0; - - - UTIL::BitField64 encoder( lcio::LCTrackerCellID::encoding_string() ) ; - - encoder.reset() ; // reset to 0 - - int layerID = encoder.lowWord() ; - int elementID = 0 ; - - - //________________________________________________________________________________________________________ - // - // starting loop on subdetectors and loop on each subdetector layer - //________________________________________________________________________________________________________ - - - - - for (size_t idet=0; idet<_vecSubdetName.size(); idet++){ - streamlog_out(DEBUG4) << "LOOP - detID = " << _vecSubdetID.at(idet) << " begins "<< std::endl; - - if( _vecDigiHitsCol.at(idet) != 0 ){ - - - for (int iL=0; iL<_vecSubdetNLayers.at(idet); iL++){ - streamlog_out(DEBUG4) << "LOOP - layer = " << iL << " begins "<< std::endl; - - encoder[UTIL::LCTrackerCellID::subdet()] = _vecSubdetID.at(idet); - - int side = 0; - if ( _vecSubdetIsBarrel.at(idet) ) side = 0; //lcio::ILDDetID::barrel; - else { - // for disks: side +1 corresposds to positive z and -1 to negative z - // decide to go to either the left or right side according to the z position of the last hit in the track - if ( z_last_hit > 0. ) side = 1; - else side = -1; - } - encoder[UTIL::LCTrackerCellID::side()] = side; - - int layer = 0; - if ( _extrapolateForward ) layer = iL; - else layer = _vecSubdetNLayers.at(idet) - (iL +1); - encoder[UTIL::LCTrackerCellID::layer()] = layer; - - layerID = encoder.lowWord(); - streamlog_out(DEBUG4) << "layerID = " << layerID << std::endl; - - /////////////////////////////////////////////////////////// - - - - if ( marlin_trk->propagateToLayer( layerID, trkState0, chi2, ndf, elementID, IMarlinTrack::modeClosest) == MarlinTrk::IMarlinTrack::success) { - - const FloatVec& covLCIO = trkState0.getCovMatrix(); - const float* pivot = trkState0.getReferencePoint(); - double r = sqrt( pivot[0]*pivot[0]+pivot[1]*pivot[1] ) ; - - streamlog_out( DEBUG4 ) << " kaltest track parameters: " - << " chi2/ndf " << chi2 / ndf - << " chi2 " << chi2 << std::endl - - << "\t D0 " << trkState0.getD0() << "[+/-" << sqrt( covLCIO[0] ) << "] " - << "\t Phi :" << trkState0.getPhi()<< "[+/-" << sqrt( covLCIO[2] ) << "] " - << "\t Omega " << trkState0.getOmega() << "[+/-" << sqrt( covLCIO[5] ) << "] " - << "\t Z0 " << trkState0.getZ0() << "[+/-" << sqrt( covLCIO[9] ) << "] " - << "\t tan(Lambda) " << trkState0.getTanLambda() << "[+/-" << sqrt( covLCIO[14]) << "] " - - << "\t pivot : [" << pivot[0] << ", " << pivot[1] << ", " << pivot[2] - << " - r: " << r << "]" - << std::endl ; - - - streamlog_out(DEBUG4) << " layer " << iL << " max search distances Z : Rphi " << _searchSigma*sqrt( covLCIO[9] ) << " : " << _searchSigma*sqrt( covLCIO[0] ) << std::endl ; - - FindAndAddHit(idet, elementID, marlin_trk, trkHits, SITHitsPerTrk, iL); - - } // successful propagation to layer - - } // loop to all subdetector layers - - }//end colDigi not empty - - }//end loop on subdetectors - streamlog_out(DEBUG4) << " no of hits in the track (after adding SIT hits) " << trkHits.size() << " SIT hits added " << SITHitsPerTrk << " event " << _n_evt<< std::endl; - - - - //============================================================================================================== - - IMPL::TrackImpl* lcio_trk = new IMPL::TrackImpl(); - - IMarlinTrack* marlinTrk = 0 ; - - if( ! _performFinalRefit ) { - - //fg: ------ here we just create a final LCIO track from the extrapolation : - - marlinTrk = marlin_trk ; - - bool fit_direction = IMarlinTrack::forward ; - int return_code = finaliseLCIOTrack( marlin_trk, lcio_trk, trkHits, fit_direction ) ; - - streamlog_out( DEBUG ) << " *** created finalized LCIO track - return code " << return_code << std::endl - << *lcio_trk << std::endl ; - - - } else { //fg: ------- perform a final refit - does not work right now ... - - // refitted track collection creation - - TrackStateImpl* trkState = new TrackStateImpl() ; - double chi2_fin = 0. ; - int ndf_fin = 0 ; - - marlin_trk->getTrackState(*trkState, chi2_fin, ndf_fin); - //const FloatVec& covMatrix = trkState->getCovMatrix(); - - - ////////////////////////////////////////////////////////////////////////////////// - - - sort(trkHits.begin(), trkHits.end(), ExtrToTracker::compare_r() ); - - - - bool fit_backwards = IMarlinTrack::backward; - //bool fit_forwards = IMarlinTrack::forward; - - marlinTrk = _trksystem->createTrack(); - - - std::vector vec_hits; - vec_hits.clear(); - for(unsigned int ih=0; ihid() << ": " << std::endl; - int detID = 0; - for (size_t ip=0; ipsubdetectorHitNumbers().size(); ip=ip+2){ - detID++; - streamlog_out( DEBUG4 ) << " det id " << detID - << " , nhits in track = " << lcio_trk->subdetectorHitNumbers()[ip] - << " , nhits in fit = " << lcio_trk->subdetectorHitNumbers()[ip+1] - << std::endl; - if (lcio_trk->subdetectorHitNumbers()[ip] > 0) lcio_trk->setTypeBit( detID ) ; - } - - trackVec->addElement( lcio_trk ); - - - if( _performFinalRefit ) delete marlinTrk ; - - } // good fit status - } // good initialisation status + int init_status = FitInit2(track, marlin_trk); - delete marlin_trk; - - } // for loop to the tracks - + if (init_status == 0) { + streamlog_out(DEBUG4) << "track initialised " << std::endl; - //------------------------------------------------------------------------------------------------------- - + int fit_status = marlin_trk->fit(); - evt->addCollection( trackVec , _output_track_col_name ) ; + if (fit_status == 0) { - delete inputTrackVec; + double chi2 = 0; + int ndf = 0; + TrackStateImpl trkState0; + UTIL::BitField64 encoder(lcio::LCTrackerCellID::encoding_string()); + encoder.reset(); // reset to 0 - ///////////////////////////////////////////////////////////////// - // Save not used hits in a collection for possible further use // - ///////////////////////////////////////////////////////////////// + int layerID = encoder.lowWord(); + int elementID = 0; - LCCollectionVec* notUsedHitsVec = new LCCollectionVec( LCIO::TRACKERHITPLANE ); - CellIDEncoder cellid_encoder( lcio::LCTrackerCellID::encoding_string(), notUsedHitsVec ) ; //do not change it, code will not work with a different encoder - notUsedHitsVec->setSubset(true); + //________________________________________________________________________________________________________ + // + // starting loop on subdetectors and loop on each subdetector layer + //________________________________________________________________________________________________________ - for(size_t iDet=0; iDet<_vecMapsElHits.size(); iDet++){ - for(std::map >::iterator iterator = _vecMapsElHits.at(iDet).begin(); iterator != _vecMapsElHits.at(iDet).end(); iterator++) { - std::vector vecHits = iterator->second; - for(size_t iHitOnEl=0; iHitOnEladdElement( vecHits.at(iHitOnEl) ); - }//end loop on hits on each det element - }//end loop on map detEl <--> vector of hits on the detEl - }//end loops on vector of maps - one for each subdetector - - evt->addCollection( notUsedHitsVec , _output_not_used_col_name ) ; - - //delete notUsedHitsVec; + for (size_t idet = 0; idet < _vecSubdetName.size(); idet++) { + streamlog_out(DEBUG4) << "LOOP - detID = " << _vecSubdetID.at(idet) << " begins " << std::endl; - ///////////////////////////////////////////////////////////////// + if (_vecDigiHitsCol.at(idet) != 0) { - }// track collection no empty - - ++_n_evt ; - - //cout << " event " << _n_evt << std::endl ; + for (int iL = 0; iL < _vecSubdetNLayers.at(idet); iL++) { + streamlog_out(DEBUG4) << "LOOP - layer = " << iL << " begins " << std::endl; - -} + encoder[UTIL::LCTrackerCellID::subdet()] = _vecSubdetID.at(idet); + int side = 0; + if (_vecSubdetIsBarrel.at(idet)) + side = 0; // lcio::ILDDetID::barrel; + else { + // for disks: side +1 corresposds to positive z and -1 to negative z + // decide to go to either the left or right side according to the z position of the last hit in the + // track + if (z_last_hit > 0.) + side = 1; + else + side = -1; + } + encoder[UTIL::LCTrackerCellID::side()] = side; + int layer = 0; + if (_extrapolateForward) + layer = iL; + else + layer = _vecSubdetNLayers.at(idet) - (iL + 1); + encoder[UTIL::LCTrackerCellID::layer()] = layer; -void ExtrToTracker::check( LCEvent* ) { - // nothing to check here - could be used to fill checkplots in reconstruction processor -} + layerID = encoder.lowWord(); + streamlog_out(DEBUG4) << "layerID = " << layerID << std::endl; + /////////////////////////////////////////////////////////// -void ExtrToTracker::end(){ - - streamlog_out(DEBUG) << "ExtrToTracker::end() " << name() - << " processed " << _n_evt << " events in " << _n_run << " runs " - << std::endl ; + if (marlin_trk->propagateToLayer(layerID, trkState0, chi2, ndf, elementID, IMarlinTrack::modeClosest) == + MarlinTrk::IMarlinTrack::success) { - streamlog_out(DEBUG4) << " SIT hits considered for track-hit association " << TotalSITHits << " how many of them were matched and fitted successfully ? " << SITHitsFitted << " for how many the fit failed ? " << SITHitsNonFitted << std::endl ; + const FloatVec& covLCIO = trkState0.getCovMatrix(); + const float* pivot = trkState0.getReferencePoint(); + double r = sqrt(pivot[0] * pivot[0] + pivot[1] * pivot[1]); + streamlog_out(DEBUG4) << " kaltest track parameters: " + << " chi2/ndf " << chi2 / ndf << " chi2 " << chi2 << std::endl + << "\t D0 " << trkState0.getD0() << "[+/-" << sqrt(covLCIO[0]) << "] " + << "\t Phi :" << trkState0.getPhi() << "[+/-" << sqrt(covLCIO[2]) << "] " + << "\t Omega " << trkState0.getOmega() << "[+/-" << sqrt(covLCIO[5]) << "] " + << "\t Z0 " << trkState0.getZ0() << "[+/-" << sqrt(covLCIO[9]) << "] " + << "\t tan(Lambda) " << trkState0.getTanLambda() << "[+/-" << sqrt(covLCIO[14]) + << "] " - -} + << "\t pivot : [" << pivot[0] << ", " << pivot[1] << ", " << pivot[2] + << " - r: " << r << "]" << std::endl; + streamlog_out(DEBUG4) << " layer " << iL << " max search distances Z : Rphi " + << _searchSigma * sqrt(covLCIO[9]) << " : " << _searchSigma * sqrt(covLCIO[0]) + << std::endl; + FindAndAddHit(idet, elementID, marlin_trk, trkHits, SITHitsPerTrk, iL); + } // successful propagation to layer + } // loop to all subdetector layers + } // end colDigi not empty + } // end loop on subdetectors + streamlog_out(DEBUG4) << " no of hits in the track (after adding SIT hits) " << trkHits.size() + << " SIT hits added " << SITHitsPerTrk << " event " << _n_evt << std::endl; + //============================================================================================================== + IMPL::TrackImpl* lcio_trk = new IMPL::TrackImpl(); -LCCollection* ExtrToTracker::GetCollection( LCEvent * evt, std::string colName ){ - - LCCollection* col = NULL; + IMarlinTrack* marlinTrk = 0; - try{ - col = evt->getCollection( colName.c_str() ) ; - streamlog_out( DEBUG3 ) << " --> " << colName.c_str() << " track collection found in event = " << col << " number of elements " << col->getNumberOfElements() << std::endl; - } - catch(DataNotAvailableException &e){ - streamlog_out( DEBUG3 ) << " --> " << colName.c_str() << " collection absent in event" << std::endl; - } - - return col; - -} + if (!_performFinalRefit) { + // fg: ------ here we just create a final LCIO track from the extrapolation : + marlinTrk = marlin_trk; + bool fit_direction = IMarlinTrack::forward; + int return_code = finaliseLCIOTrack(marlin_trk, lcio_trk, trkHits, fit_direction); + streamlog_out(DEBUG) << " *** created finalized LCIO track - return code " << return_code << std::endl + << *lcio_trk << std::endl; -int ExtrToTracker::FitInit2( Track* track, MarlinTrk::IMarlinTrack* _marlinTrk ){ + } else { // fg: ------- perform a final refit - does not work right now ... + // refitted track collection creation - //EVENT::FloatVec covMatrix = track->getCovMatrix(); - - - TrackStateImpl trackState( TrackState::AtOther, - track->getD0(), - track->getPhi(), - track->getOmega(), - track->getZ0(), - track->getTanLambda(), - track->getCovMatrix(), - track->getReferencePoint() - ) ; - + TrackStateImpl* trkState = new TrackStateImpl(); + double chi2_fin = 0.; + int ndf_fin = 0; - bool direction; - if (_extrapolateForward) direction = IMarlinTrack::forward ; - else direction = IMarlinTrack::backward ; - _marlinTrk->initialise( trackState, _bField, direction ) ; - - return IMarlinTrack::success ; - + marlin_trk->getTrackState(*trkState, chi2_fin, ndf_fin); + // const FloatVec& covMatrix = trkState->getCovMatrix(); + + ////////////////////////////////////////////////////////////////////////////////// + + sort(trkHits.begin(), trkHits.end(), ExtrToTracker::compare_r()); + + bool fit_backwards = IMarlinTrack::backward; + // bool fit_forwards = IMarlinTrack::forward; + + marlinTrk = _trksystem->createTrack(); + + std::vector vec_hits; + vec_hits.clear(); + for (unsigned int ih = 0; ih < trkHits.size(); ih++) { + vec_hits.push_back(trkHits.at(ih)); + } // end loop on hits + streamlog_out(DEBUG1) << " --- vec_hits.size() = " << vec_hits.size() << std::endl; + + // int ndf_test_0; + // int return_error_0 = marlinTrk->getNDF(ndf_test_0); + // streamlog_out(DEBUG1) << "++++ 0 - getNDF returns " << return_error_0 << std::endl; + // streamlog_out(DEBUG1) << "++++ 0 - getNDF returns ndf = " << ndf_test_0 << std::endl; + + // Kalman filter smoothing - fit track from out to in + int error_fit = createFit(vec_hits, marlinTrk, trkState, _bField, fit_backwards, _Max_Chi2_Incr); + streamlog_out(DEBUG) << "---- createFit - error_fit = " << error_fit << std::endl; + + bool fit_direction = fit_backwards; + + if (error_fit == 0) { + int error = finaliseLCIOTrack(marlinTrk, lcio_trk, vec_hits, fit_direction); + streamlog_out(DEBUG) << "---- finalisedLCIOTrack - error = " << error << std::endl; + + // int ndf_test; + // int return_error = marlinTrk->getNDF(ndf_test); + // streamlog_out(DEBUG3) << "++++ getNDF returns " << return_error << std::endl; + // streamlog_out(DEBUG3) << "++++ getNDF returns ndf = " << ndf_test << std::endl; + + if (error != 0) { + + streamlog_out(DEBUG3) << "Error from finaliseLCIOTrack non zero! deleting tracks. error=" << error + << " noHits: " << trkHits.size() << " marlinTrk: " << marlinTrk + << " lcio_trk: " << lcio_trk << std::endl; + + delete lcio_trk; + delete marlinTrk; + continue; + } + } else { + streamlog_out(DEBUG3) << "Error from createFit non zero! deleting tracks. error_fit=" << error_fit + << std::endl; + + delete lcio_trk; + delete marlinTrk; + continue; + } + + delete trkState; + + } // !_perfomFinalRefit + + // fit finished - get hits in the fit + + std::vector> hits_in_fit; + std::vector> outliers; + + // remember the hits are ordered in the order in which they were fitted + + marlinTrk->getHitsInFit(hits_in_fit); + + if (hits_in_fit.size() < 3) { + streamlog_out(DEBUG3) << "RefitProcessor: Less than 3 hits in fit: Track Discarded. Number of hits = " + << trkHits.size() << std::endl; + delete marlinTrk; + delete lcio_trk; + continue; + } + + marlinTrk->getOutliers(outliers); + + std::vector all_hits; + all_hits.reserve(hits_in_fit.size() + outliers.size()); + + for (unsigned ihit = 0; ihit < hits_in_fit.size(); ++ihit) { + all_hits.push_back(hits_in_fit[ihit].first); + } + + for (unsigned ihit = 0; ihit < outliers.size(); ++ihit) { + all_hits.push_back(outliers[ihit].first); + } + + UTIL::BitField64 encoder2(lcio::LCTrackerCellID::encoding_string()); + encoder2.reset(); // reset to 0 + MarlinTrk::addHitNumbersToTrack(lcio_trk, all_hits, false, encoder2); + MarlinTrk::addHitNumbersToTrack(lcio_trk, hits_in_fit, true, encoder2); + + streamlog_out(DEBUG4) << "ExtrToTracker::processEvent - Hit numbers for track " << lcio_trk->id() << ": " + << std::endl; + int detID = 0; + for (size_t ip = 0; ip < lcio_trk->subdetectorHitNumbers().size(); ip = ip + 2) { + detID++; + streamlog_out(DEBUG4) << " det id " << detID + << " , nhits in track = " << lcio_trk->subdetectorHitNumbers()[ip] + << " , nhits in fit = " << lcio_trk->subdetectorHitNumbers()[ip + 1] << std::endl; + if (lcio_trk->subdetectorHitNumbers()[ip] > 0) + lcio_trk->setTypeBit(detID); + } + + trackVec->addElement(lcio_trk); + + if (_performFinalRefit) + delete marlinTrk; + + } // good fit status + } // good initialisation status + + delete marlin_trk; + + } // for loop to the tracks + + //------------------------------------------------------------------------------------------------------- + + evt->addCollection(trackVec, _output_track_col_name); + + delete inputTrackVec; + + ///////////////////////////////////////////////////////////////// + // Save not used hits in a collection for possible further use // + ///////////////////////////////////////////////////////////////// + + LCCollectionVec* notUsedHitsVec = new LCCollectionVec(LCIO::TRACKERHITPLANE); + CellIDEncoder cellid_encoder( + lcio::LCTrackerCellID::encoding_string(), + notUsedHitsVec); // do not change it, code will not work with a different encoder + notUsedHitsVec->setSubset(true); + + for (size_t iDet = 0; iDet < _vecMapsElHits.size(); iDet++) { + for (std::map>::iterator iterator = _vecMapsElHits.at(iDet).begin(); + iterator != _vecMapsElHits.at(iDet).end(); iterator++) { + std::vector vecHits = iterator->second; + for (size_t iHitOnEl = 0; iHitOnEl < vecHits.size(); iHitOnEl++) { + notUsedHitsVec->addElement(vecHits.at(iHitOnEl)); + } // end loop on hits on each det element + } // end loop on map detEl <--> vector of hits on the detEl + } // end loops on vector of maps - one for each subdetector + + evt->addCollection(notUsedHitsVec, _output_not_used_col_name); + + // delete notUsedHitsVec; + + ///////////////////////////////////////////////////////////////// + + } // track collection no empty + + ++_n_evt; + + // cout << " event " << _n_evt << std::endl ; +} + +void ExtrToTracker::check(LCEvent*) { + // nothing to check here - could be used to fill checkplots in reconstruction processor +} + +void ExtrToTracker::end() { + + streamlog_out(DEBUG) << "ExtrToTracker::end() " << name() << " processed " << _n_evt << " events in " << _n_run + << " runs " << std::endl; + + streamlog_out(DEBUG4) << " SIT hits considered for track-hit association " << TotalSITHits + << " how many of them were matched and fitted successfully ? " << SITHitsFitted + << " for how many the fit failed ? " << SITHitsNonFitted << std::endl; } +LCCollection* ExtrToTracker::GetCollection(LCEvent* evt, std::string colName) { + LCCollection* col = NULL; + + try { + col = evt->getCollection(colName.c_str()); + streamlog_out(DEBUG3) << " --> " << colName.c_str() << " track collection found in event = " << col + << " number of elements " << col->getNumberOfElements() << std::endl; + } catch (DataNotAvailableException& e) { + streamlog_out(DEBUG3) << " --> " << colName.c_str() << " collection absent in event" << std::endl; + } + return col; +} + +int ExtrToTracker::FitInit2(Track* track, MarlinTrk::IMarlinTrack* _marlinTrk) { + // EVENT::FloatVec covMatrix = track->getCovMatrix(); + TrackStateImpl trackState(TrackState::AtOther, track->getD0(), track->getPhi(), track->getOmega(), track->getZ0(), + track->getTanLambda(), track->getCovMatrix(), track->getReferencePoint()); + bool direction; + if (_extrapolateForward) + direction = IMarlinTrack::forward; + else + direction = IMarlinTrack::backward; + _marlinTrk->initialise(trackState, _bField, direction); -void ExtrToTracker::fillVecSubdet(lcio::LCEvent*& evt){ + return IMarlinTrack::success; +} +void ExtrToTracker::fillVecSubdet(lcio::LCEvent*& evt) { _vecDigiHitsCol.clear(); - for (size_t idet=0; idet<_vecSubdetName.size(); idet++){ - - streamlog_out(DEBUG4) << "idet = " << idet << std::endl; - - if ( _vecDigiHits.at(idet)!="" ){ - - LCCollection* colDigi = 0 ; - try{ - colDigi = evt->getCollection( _vecDigiHits.at(idet) ) ; - getCellID0AndPositionInfo(colDigi); - - }catch(DataNotAvailableException &e){ - streamlog_out(DEBUG4) << "Collection " << _vecDigiHits.at(idet).c_str() << " is unavailable " << std::endl; - } + for (size_t idet = 0; idet < _vecSubdetName.size(); idet++) { - _vecDigiHitsCol.push_back(colDigi); - - }// diginame !=0 + streamlog_out(DEBUG4) << "idet = " << idet << std::endl; + + if (_vecDigiHits.at(idet) != "") { + LCCollection* colDigi = 0; + try { + colDigi = evt->getCollection(_vecDigiHits.at(idet)); + getCellID0AndPositionInfo(colDigi); - else _vecDigiHitsCol.push_back(0); + } catch (DataNotAvailableException& e) { + streamlog_out(DEBUG4) << "Collection " << _vecDigiHits.at(idet).c_str() << " is unavailable " << std::endl; + } - }//end loop on subdetectors - -}//end + _vecDigiHitsCol.push_back(colDigi); + } // diginame !=0 + else + _vecDigiHitsCol.push_back(0); + } // end loop on subdetectors -void ExtrToTracker::getCellID0AndPositionInfo(LCCollection*& col ){ +} // end +void ExtrToTracker::getCellID0AndPositionInfo(LCCollection*& col) { - std::string cellIDEcoding0 = col->getParameters().getStringVal("CellIDEncoding") ; - UTIL::BitField64 cellid_decoder( cellIDEcoding0 ) ; + std::string cellIDEcoding0 = col->getParameters().getStringVal("CellIDEncoding"); + UTIL::BitField64 cellid_decoder(cellIDEcoding0); - for (int i=0; igetNumberOfElements(); i++){ - TrackerHitPlane* trackerHit = dynamic_cast( col->getElementAt(i) ) ; + for (int i = 0; i < col->getNumberOfElements(); i++) { + TrackerHitPlane* trackerHit = dynamic_cast(col->getElementAt(i)); - const dd4hep::CellID id = trackerHit->getCellID0() ; - cellid_decoder.setValue( id ) ; + const dd4hep::CellID id = trackerHit->getCellID0(); + cellid_decoder.setValue(id); int subdet = cellid_decoder[UTIL::LCTrackerCellID::subdet()]; int side = cellid_decoder[UTIL::LCTrackerCellID::side()]; @@ -727,370 +605,326 @@ void ExtrToTracker::getCellID0AndPositionInfo(LCCollection*& col ){ int module = cellid_decoder[UTIL::LCTrackerCellID::module()]; int sensor = cellid_decoder[UTIL::LCTrackerCellID::sensor()]; - - streamlog_out(DEBUG2) << " hit" << i - << " ( subdetector: " << subdet - <<", side: " << side - <<", layer: " << layer - <<", module: " << module - <<", sensor: " << sensor - <<" ) ( r: " << sqrt(pow(trackerHit->getPosition()[0],2)+pow(trackerHit->getPosition()[1],2)) - <<" , phi: " << atan(trackerHit->getPosition()[1]/trackerHit->getPosition()[0]) - <<" , z: " << trackerHit->getPosition()[2] - <<" ) \n"; + streamlog_out(DEBUG2) << " hit" << i << " ( subdetector: " << subdet << ", side: " << side << ", layer: " << layer + << ", module: " << module << ", sensor: " << sensor << " ) ( r: " + << sqrt(pow(trackerHit->getPosition()[0], 2) + pow(trackerHit->getPosition()[1], 2)) + << " , phi: " << atan(trackerHit->getPosition()[1] / trackerHit->getPosition()[0]) + << " , z: " << trackerHit->getPosition()[2] << " ) \n"; // SurfaceMap::const_iterator si = _surfMap.find(id); // if( si == _surfMap.end()) { // streamlog_out(MESSAGE2) << "----- IT IS A SURFACES PROBLEM " <second : 0); - + // streamlog_out(MESSAGE2) << " surf = " << surf <getPosition(); // DDSurfaces::Vector3D hit_global(hit_pos[0],hit_pos[1],hit_pos[2]); - // DDSurfaces::Vector2D hit_local = surf->globalToLocal( dd4hep::mm * hit_global ); + // DDSurfaces::Vector2D hit_local = surf->globalToLocal( dd4hep::mm * hit_global ); - // streamlog_out(MESSAGE2) << "----- hit global x, y, r = " << hit_global[0] <<" "<< hit_global[1] <<" "<< sqrt(pow(hit_global[0],2)+pow(hit_global[1],2)) <& hitsOnDetEl, + MarlinTrk::IMarlinTrack*& marlin_trk) { - - - - - - - - -TrackerHitPlane* ExtrToTracker::getSiHit(std::vector& hitsOnDetEl, MarlinTrk::IMarlinTrack*& marlin_trk){ - double min = 9999999.; - double testChi2=0.; + double testChi2 = 0.; size_t nHitsOnDetEl = hitsOnDetEl.size(); - int index = -1; //index of the selected hits + int index = -1; // index of the selected hits - streamlog_out(DEBUG2) << "-- number of hits on the same detector element: " << nHitsOnDetEl << std::endl ; + streamlog_out(DEBUG2) << "-- number of hits on the same detector element: " << nHitsOnDetEl << std::endl; - if (nHitsOnDetEl==0) return 0; + if (nHitsOnDetEl == 0) + return 0; - for(size_t i=0; itestChi2Increment(hitsOnDetEl.at(i), testChi2) == MarlinTrk::IMarlinTrack::success ) {..} // do not do this the testChi2 internally call the addandfir setting as max acceptable chi2 a very small number to be sure to never add the the hit to the fit (so it always fails) + for (size_t i = 0; i < nHitsOnDetEl; i++) { + // if ( marlin_trk->testChi2Increment(hitsOnDetEl.at(i), testChi2) == MarlinTrk::IMarlinTrack::success ) {..} // do + // not do this the testChi2 internally call the addandfir setting as max acceptable chi2 a very small number to be + // sure to never add the the hit to the fit (so it always fails) marlin_trk->testChi2Increment(hitsOnDetEl.at(i), testChi2); - streamlog_out(DEBUG2) << "-- testChi2: " << testChi2 << std::endl ; - if (min>testChi2 && testChi2>0) { + streamlog_out(DEBUG2) << "-- testChi2: " << testChi2 << std::endl; + if (min > testChi2 && testChi2 > 0) { min = testChi2; index = i; - } //end min chi2 - }//end loop on hits on same detector element + } // end min chi2 + } // end loop on hits on same detector element + + streamlog_out(DEBUG2) << "-- index of the selected hit: " << index << std::endl; - streamlog_out(DEBUG2) << "-- index of the selected hit: " << index << std::endl ; - - if (index == -1) return 0; + if (index == -1) + return 0; else { - TrackerHitPlane* selectedHit = dynamic_cast( hitsOnDetEl.at(index) ) ; + TrackerHitPlane* selectedHit = dynamic_cast(hitsOnDetEl.at(index)); - if (nHitsOnDetEl>1) std::iter_swap(hitsOnDetEl.begin()+index,hitsOnDetEl.begin()+nHitsOnDetEl-1); + if (nHitsOnDetEl > 1) + std::iter_swap(hitsOnDetEl.begin() + index, hitsOnDetEl.begin() + nHitsOnDetEl - 1); hitsOnDetEl.pop_back(); - //hitsOnDetEl.erase(hitsOnDetEl.begin()+index); - + // hitsOnDetEl.erase(hitsOnDetEl.begin()+index); return selectedHit; } -}//end getSiHit +} // end getSiHit +TrackerHitPlane* ExtrToTracker::getSiHit(std::vector& vecElID, + std::map>& mapElHits, + MarlinTrk::IMarlinTrack*& marlin_trk) { - - - - - -TrackerHitPlane* ExtrToTracker::getSiHit(std::vector< dd4hep::CellID >& vecElID, std::map >& mapElHits, MarlinTrk::IMarlinTrack*& marlin_trk){ - double min = 9999999.; - double testChi2=0.; + double testChi2 = 0.; size_t nElID = vecElID.size(); - int indexel = -1; //element index (in vecElID) of the selected hits - int index = -1; //index of the selected hits + int indexel = -1; // element index (in vecElID) of the selected hits + int index = -1; // index of the selected hits + + for (size_t ie = 0; ie < nElID; ie++) { - for(size_t ie=0; ie0) { + if (mapElHits.count(elID) > 0) { nHitsOnDetEl = mapElHits[elID].size(); } // streamlog_out(MESSAGE2) << "-- elID at index = "<< ie <<" / " << nElID << " : " << vecElID.at(ie) << std::endl ; - streamlog_out(DEBUG3) << "-- number of hits on the same detector element: " << nHitsOnDetEl << std::endl ; + streamlog_out(DEBUG3) << "-- number of hits on the same detector element: " << nHitsOnDetEl << std::endl; - - for(size_t i=0; itestChi2Increment(mapElHits[elID].at(i), testChi2); // streamlog_out(MESSAGE2) << "-- trackerhit at index = " << i << " / "<< nHitsOnDetEl << std::endl ; // streamlog_out(MESSAGE2) << "-- testChi2: " << testChi2 << std::endl ; - if (min>testChi2 && testChi2>0) { - min = testChi2; - indexel = elID; - index = i; + if (min > testChi2 && testChi2 > 0) { + min = testChi2; + indexel = elID; + index = i; } - }//end loop on hits on the same elID - - }//end loop on elIDs + } // end loop on hits on the same elID + } // end loop on elIDs - if (index == -1 || indexel == -1) return 0; + if (index == -1 || indexel == -1) + return 0; else { - streamlog_out(DEBUG3) << "-- hit added " << std::endl ; + streamlog_out(DEBUG3) << "-- hit added " << std::endl; // if ( vecElID.at(0) != indexel) streamlog_out(MESSAGE2) << "-- but not from the first elementID " << std::endl ; - - TrackerHitPlane* selectedHit = dynamic_cast( mapElHits[indexel].at(index) ) ; + TrackerHitPlane* selectedHit = dynamic_cast(mapElHits[indexel].at(index)); int nHitsOnSelectedEl = mapElHits[indexel].size(); - if (nHitsOnSelectedEl>1) std::iter_swap(mapElHits[indexel].begin()+index,mapElHits[indexel].begin()+nHitsOnSelectedEl-1); + if (nHitsOnSelectedEl > 1) + std::iter_swap(mapElHits[indexel].begin() + index, mapElHits[indexel].begin() + nHitsOnSelectedEl - 1); mapElHits[indexel].pop_back(); ////(mapElHits[indexel].erase((mapElHits[indexel].begin()+index); - + return selectedHit; } return 0; -}//end getSiHit - - +} // end getSiHit +void ExtrToTracker::fillMapElHits(std::vector& vecHitCol, + std::vector>>& vecMaps) { -void ExtrToTracker::fillMapElHits(std::vector& vecHitCol, std::vector > >& vecMaps){ - - - //fill map (el - vector of hits) for each subdtector + // fill map (el - vector of hits) for each subdtector vecMaps.clear(); _vecvecHitsInCol.clear(); - for(size_t icol=0; icol > map_el_hits; + std::map> map_el_hits; - std::vector vecHelper; + std::vector vecHelper; vecHelper.clear(); - - if(vecHitCol.at(icol)!=NULL){ + if (vecHitCol.at(icol) != NULL) { int nhits = vecHitCol.at(icol)->getNumberOfElements(); - streamlog_out(DEBUG2) << " nhits = "<< nhits << std::endl ; + streamlog_out(DEBUG2) << " nhits = " << nhits << std::endl; + for (int ihit = 0; ihit < nhits; ihit++) { - for(int ihit=0; ihit(vecHitCol.at(icol)->getElementAt(ihit)); - TrackerHitPlane* hit = dynamic_cast( vecHitCol.at(icol)->getElementAt(ihit) ); + vecHelper.push_back(hit); - vecHelper.push_back(hit); - - int cellID0 = hit->getCellID0(); - UTIL::BitField64 encoder0( lcio::LCTrackerCellID::encoding_string() ); //do not change it, code will not work with a different encoder - encoder0.reset(); // reset to 0 - encoder0.setValue(cellID0); - int hitElID = encoder0.lowWord(); + int cellID0 = hit->getCellID0(); + UTIL::BitField64 encoder0( + lcio::LCTrackerCellID::encoding_string()); // do not change it, code will not work with a different encoder + encoder0.reset(); // reset to 0 + encoder0.setValue(cellID0); + int hitElID = encoder0.lowWord(); - map_el_hits[hitElID].push_back(hit); - - }//end loop on hits + map_el_hits[hitElID].push_back(hit); - }//collection not empty + } // end loop on hits + + } // collection not empty vecMaps.push_back(map_el_hits); _vecvecHitsInCol.push_back(vecHelper); - }//end loop on collections of hits - - -}//end fillMapElHits + } // end loop on collections of hits +} // end fillMapElHits - - - - - - -void ExtrToTracker::getGeoInfo(){ - +void ExtrToTracker::getGeoInfo() { _vecSubdetID.clear(); _vecSubdetNLayers.clear(); _vecSubdetIsBarrel.clear(); _vecMapNeighbours.clear(); - dd4hep::Detector & mainDetector = dd4hep::Detector::getInstance(); - - //alternative way - // const std::vector< dd4hep::DetElement>& barrelDets = dd4hep::DetectorSelector(theDetector).detectors( ( DD4hep::DetType::TRACKER | DD4hep::DetType::BARREL )) ; - - // streamlog_out( MESSAGE2 ) << " --- flag = " << (DD4hep::DetType::TRACKER | DD4hep::DetType::BARREL) < vecIDs; + if (elID != 0) { + + bool isSuccessfulFit = false; + + std::vector vecIDs; vecIDs = _vecMapNeighbours.at(idet)->find(elID)->second; - vecIDs.insert( std::begin(vecIDs), elID ); + vecIDs.insert(std::begin(vecIDs), elID); TrackerHitPlane* BestHit; BestHit = getSiHit(vecIDs, _vecMapsElHits.at(idet), mtrk); // BestHit = getSiHit(_vecvecHitsInCol.at(idet), mtrk); - if (BestHit != 0){ - - streamlog_out(DEBUG2) << " --- Best hit found " << std::endl ; - - double chi2_increment = 0.; - // isSuccessfulFit = mtrk->addAndFit( BestHit, chi2_increment, _Max_Chi2_Incr*(layer+1) ) == IMarlinTrack::success ; - isSuccessfulFit = mtrk->addAndFit( BestHit, chi2_increment, _Max_Chi2_Incr ) == IMarlinTrack::success ; + if (BestHit != 0) { - streamlog_out(DEBUG4) << " --- layer+1 = " << layer+1 << std::endl; + streamlog_out(DEBUG2) << " --- Best hit found " << std::endl; + + double chi2_increment = 0.; + // isSuccessfulFit = mtrk->addAndFit( BestHit, chi2_increment, _Max_Chi2_Incr*(layer+1) ) == IMarlinTrack::success + // ; + isSuccessfulFit = mtrk->addAndFit(BestHit, chi2_increment, _Max_Chi2_Incr) == IMarlinTrack::success; + + streamlog_out(DEBUG4) << " --- layer+1 = " << layer + 1 << std::endl; streamlog_out(DEBUG4) << " --- _Max_Chi2_Incr = " << _Max_Chi2_Incr << std::endl; - streamlog_out(DEBUG4) << " --- increment in the chi2 = " << chi2_increment << " , max chi2 to accept the hit " << _Max_Chi2_Incr*(layer+1) << std::endl; - streamlog_out(DEBUG4) << " --- isSuccessfulFit = "<< isSuccessfulFit << std::endl ; - - + streamlog_out(DEBUG4) << " --- increment in the chi2 = " << chi2_increment << " , max chi2 to accept the hit " + << _Max_Chi2_Incr * (layer + 1) << std::endl; + streamlog_out(DEBUG4) << " --- isSuccessfulFit = " << isSuccessfulFit << std::endl; + // TotalSITHits++; - - if ( isSuccessfulFit ){ - - - trkHits.push_back(BestHit) ; - - - streamlog_out(DEBUG4) << " +++ hit added " << BestHit << std::endl ; - - - SITHitsPerTrk++; - // SITHitsFitted++; - - streamlog_out(DEBUG4) << " --- SITHitsPerTrk " << SITHitsPerTrk << std::endl ; - - } //end successful fit - else{ - - // SITHitsNonFitted++; - streamlog_out(DEBUG4) << " +++ HIT NOT ADDED "<< std::endl; - - } + if (isSuccessfulFit) { + + trkHits.push_back(BestHit); + + streamlog_out(DEBUG4) << " +++ hit added " << BestHit << std::endl; + + SITHitsPerTrk++; + // SITHitsFitted++; + + streamlog_out(DEBUG4) << " --- SITHitsPerTrk " << SITHitsPerTrk << std::endl; + + } // end successful fit + else { + + // SITHitsNonFitted++; + streamlog_out(DEBUG4) << " +++ HIT NOT ADDED " << std::endl; + } - }// besthit found + } // besthit found // streamlog_out(DEBUG4) << " -- SITHitsFitted = " << SITHitsFitted << std::endl; // streamlog_out(DEBUG4) << " -- SITHitsNonFitted = " << SITHitsNonFitted << std::endl; - - }//elID !=0 + } // elID !=0 return; } diff --git a/source/Refitting/src/FPCCDFullLDCTracking_MarlinTrk.cc b/source/Refitting/src/FPCCDFullLDCTracking_MarlinTrk.cc index 1d35c14..c22d058 100644 --- a/source/Refitting/src/FPCCDFullLDCTracking_MarlinTrk.cc +++ b/source/Refitting/src/FPCCDFullLDCTracking_MarlinTrk.cc @@ -1,36 +1,36 @@ #include "FPCCDFullLDCTracking_MarlinTrk.h" -#include #include +#include +#include +#include +#include #include #include -#include -#include -#include -#include #include -#include #include -#include +#include +#include #include +#include #include -#include +#include "ClusterShapes.h" #include #include -#include "ClusterShapes.h" +#include -#include "DD4hep/Detector.h" #include "DD4hep/DD4hepUnits.h" +#include "DD4hep/Detector.h" #include "DDRec/DetectorData.h" -#include #include +#include -#include "MarlinTrk/MarlinTrkUtils.h" -#include "MarlinTrk/HelixTrack.h" +#include "MarlinTrk/Factory.h" #include "MarlinTrk/HelixFit.h" +#include "MarlinTrk/HelixTrack.h" #include "MarlinTrk/IMarlinTrack.h" -#include "MarlinTrk/Factory.h" +#include "MarlinTrk/MarlinTrkUtils.h" #include "MarlinTrk/LCIOTrackPropagators.h" @@ -39,636 +39,411 @@ #include "MarlinTrk/DiagnosticsController.h" #endif -#include #include "UTIL/LCTrackerConf.h" +#include #include #include #include -#include "gsl/gsl_randist.h" #include "gsl/gsl_cdf.h" +#include "gsl/gsl_randist.h" +using namespace lcio; +using namespace marlin; +using namespace MarlinTrk; -using namespace lcio ; -using namespace marlin ; -using namespace MarlinTrk ; +FPCCDFullLDCTracking_MarlinTrk aFPCCDFullLDCTracking_MarlinTrk; -FPCCDFullLDCTracking_MarlinTrk aFPCCDFullLDCTracking_MarlinTrk ; +namespace FPCCDUtil { +/** debug printout helper method */ +std::string toString(int iTrk, Track* tpcTrack, float bField = 3.5) { + int nHits = int(tpcTrack->getTrackerHits().size()); + float d0TPC = tpcTrack->getD0(); + float z0TPC = tpcTrack->getZ0(); + float omegaTPC = tpcTrack->getOmega(); + float phi0TPC = tpcTrack->getPhi(); + float tanLTPC = tpcTrack->getTanLambda(); + float Chi2TPC = tpcTrack->getChi2() / float(tpcTrack->getNdf()); + int ndfTPC = tpcTrack->getNdf(); -namespace FPCCDUtil{ - /** debug printout helper method */ - std::string toString( int iTrk, Track * tpcTrack, float bField=3.5 ) { + int nlinkedTracks = tpcTrack->getTracks().size(); - int nHits = int( tpcTrack->getTrackerHits().size() ); - float d0TPC = tpcTrack->getD0(); - float z0TPC = tpcTrack->getZ0(); - float omegaTPC = tpcTrack->getOmega(); - float phi0TPC = tpcTrack->getPhi(); - float tanLTPC = tpcTrack->getTanLambda(); - float Chi2TPC = tpcTrack->getChi2()/float(tpcTrack->getNdf()); - int ndfTPC = tpcTrack->getNdf(); + HelixClass helixTPC; - int nlinkedTracks = tpcTrack->getTracks().size(); + helixTPC.Initialize_Canonical(phi0TPC, d0TPC, z0TPC, omegaTPC, tanLTPC, bField); + char strg[200]; - HelixClass helixTPC; + float pxTPC = helixTPC.getMomentum()[0]; + float pyTPC = helixTPC.getMomentum()[1]; + float pzTPC = helixTPC.getMomentum()[2]; + const float ptot = sqrt(pxTPC * pxTPC + pyTPC * pyTPC + pzTPC * pzTPC); - helixTPC.Initialize_Canonical(phi0TPC,d0TPC,z0TPC,omegaTPC,tanLTPC, bField); + sprintf(strg, "%3i %5i %9.3f %9.3f %9.3f %7.2f %7.2f %7.2f %4i %4i %8.3f %8i", iTrk, tpcTrack->id(), ptot, + d0TPC, z0TPC, pxTPC, pyTPC, pzTPC, nHits, ndfTPC, Chi2TPC, nlinkedTracks); - char strg[200]; + return std::string(strg); +} +} // namespace FPCCDUtil - float pxTPC = helixTPC.getMomentum()[0]; - float pyTPC = helixTPC.getMomentum()[1]; - float pzTPC = helixTPC.getMomentum()[2]; - const float ptot = sqrt(pxTPC*pxTPC+pyTPC*pyTPC+pzTPC*pzTPC); +FPCCDFullLDCTracking_MarlinTrk::FPCCDFullLDCTracking_MarlinTrk() : Processor("FPCCDFullLDCTracking_MarlinTrk") { + _description = "Performs full tracking in ILD detector"; - sprintf(strg,"%3i %5i %9.3f %9.3f %9.3f %7.2f %7.2f %7.2f %4i %4i %8.3f %8i",iTrk,tpcTrack->id(), - ptot, d0TPC,z0TPC,pxTPC,pyTPC,pzTPC,nHits,ndfTPC,Chi2TPC,nlinkedTracks); + // Input tracker hit collections - return std::string( strg ) ; - } -} + registerInputCollection(LCIO::TRACKERHITPLANE, "FTDPixelHitCollectionName", "FTD Pixel Hit Collection Name", + _FTDPixelHitCollection, std::string("FTDPixelTrackerHits")); + registerInputCollection(LCIO::TRACKERHIT, "FTDSpacePointCollectionName", "FTD FTDSpacePoint Collection Name", + _FTDSpacePointCollection, std::string("FTDSpacePoints")); + registerInputCollection(LCIO::TRACKERHITPLANE, "VTXHitCollection", "VTX Hit Collection Name", + _VTXTrackerHitCollection, std::string("VTXTrackerHits")); -FPCCDFullLDCTracking_MarlinTrk::FPCCDFullLDCTracking_MarlinTrk() : Processor("FPCCDFullLDCTracking_MarlinTrk") { - _description = "Performs full tracking in ILD detector" ; - - // Input tracker hit collections - - registerInputCollection(LCIO::TRACKERHITPLANE, - "FTDPixelHitCollectionName", - "FTD Pixel Hit Collection Name", - _FTDPixelHitCollection, - std::string("FTDPixelTrackerHits")); - - registerInputCollection(LCIO::TRACKERHIT, - "FTDSpacePointCollectionName", - "FTD FTDSpacePoint Collection Name", - _FTDSpacePointCollection, - std::string("FTDSpacePoints")); - - registerInputCollection(LCIO::TRACKERHITPLANE, - "VTXHitCollection", - "VTX Hit Collection Name", - _VTXTrackerHitCollection, - std::string("VTXTrackerHits")); - - registerInputCollection(LCIO::TRACKERHIT, - "SITHitCollection", - "SIT Hit Collection Name", - _SITTrackerHitCollection, + registerInputCollection(LCIO::TRACKERHIT, "SITHitCollection", "SIT Hit Collection Name", _SITTrackerHitCollection, std::string("SITTrackerHits")); - - registerInputCollection(LCIO::TRACKERHIT, - "SETHitCollection", - "SET Hit Collection Name", - _SETTrackerHitCollection, + + registerInputCollection(LCIO::TRACKERHIT, "SETHitCollection", "SET Hit Collection Name", _SETTrackerHitCollection, std::string("SETTrackerHits")); - - registerInputCollection(LCIO::TRACKERHIT, - "ETDHitCollection", - "ETD Hit Collection Name", - _ETDTrackerHitCollection, + + registerInputCollection(LCIO::TRACKERHIT, "ETDHitCollection", "ETD Hit Collection Name", _ETDTrackerHitCollection, std::string("ETDTrackerHits")); - - registerInputCollection(LCIO::TRACKERHIT, - "TPCHitCollection", - "TPC Hit Collection Name", - _TPCTrackerHitCollection, + + registerInputCollection(LCIO::TRACKERHIT, "TPCHitCollection", "TPC Hit Collection Name", _TPCTrackerHitCollection, std::string("TPCTrackerHits")); - - + // Input track collections - - registerInputCollection(LCIO::TRACK, - "TPCTracks", - "TPC Track Collection", - _TPCTrackCollection, + + registerInputCollection(LCIO::TRACK, "TPCTracks", "TPC Track Collection", _TPCTrackCollection, std::string("TPCTracks")); - - registerInputCollection(LCIO::TRACK, - "SiTracks", - "Si Track Collection", - _SiTrackCollection, - std::string("SiTracks")); - + + registerInputCollection(LCIO::TRACK, "SiTracks", "Si Track Collection", _SiTrackCollection, std::string("SiTracks")); + // Input relation collections - - registerInputCollection(LCIO::LCRELATION, - "TPCTracksMCPRelColl", - "TPC Track to MCP Relation Collection Name", - _TPCTrackMCPCollName, - std::string("TPCTracksMCP")); - - registerInputCollection(LCIO::LCRELATION, - "SiTracksMCPRelColl", - "Si Track to Collection", - _SiTrackMCPCollName, + + registerInputCollection(LCIO::LCRELATION, "TPCTracksMCPRelColl", "TPC Track to MCP Relation Collection Name", + _TPCTrackMCPCollName, std::string("TPCTracksMCP")); + + registerInputCollection(LCIO::LCRELATION, "SiTracksMCPRelColl", "Si Track to Collection", _SiTrackMCPCollName, std::string("SiTracksMCP")); - + // Output track collection - registerOutputCollection(LCIO::TRACK, - "LDCTrackCollection", - "LDC track collection name", - _LDCTrackCollection, + registerOutputCollection(LCIO::TRACK, "LDCTrackCollection", "LDC track collection name", _LDCTrackCollection, std::string("LDCTracks")); - - - + // steering parameters - - registerProcessorParameter("D0CutForMerging", - "Cut on D0 difference for merging of Si and TPC segments", - _d0CutForMerging, - float(500.0)); - - registerProcessorParameter("Z0CutForMerging", - "Cut on Z0 difference for merging of Si and TPC segments", - _z0CutForMerging, - float(1000.0)); - - registerProcessorParameter("OmegaCutForMerging", - "Cut on Omega difference for merging Si and TPC segments", - _dOmegaForMerging, - float(0.25)); - - registerProcessorParameter("AngleCutForMerging", - "Cut on Opening Angle for merging Si and TPC segments", - _angleForMerging, - float(0.10)); - - registerProcessorParameter("Chi2FitCut", - "Cut on fit Chi2", - _chi2FitCut, - float(100.0)); - - registerProcessorParameter("Debug", - "Activate debugging?", - _debug, - int(0)); - - - registerProcessorParameter("ForceSiTPCMerging", - "Force merging of Si and TPC segments?", - _forceMerging, - int(0)); - - registerProcessorParameter("D0CutForForcedMerging", - "Cut on D0 difference for forced merging of Si and TPC segments", - _d0CutForForcedMerging, - float(50.)); - - registerProcessorParameter("Z0CutForForcedMerging", - "Cut on Z0 difference for forced merging of Si and TPC segments", - _z0CutForForcedMerging, - float(200.)); - + + registerProcessorParameter("D0CutForMerging", "Cut on D0 difference for merging of Si and TPC segments", + _d0CutForMerging, float(500.0)); + + registerProcessorParameter("Z0CutForMerging", "Cut on Z0 difference for merging of Si and TPC segments", + _z0CutForMerging, float(1000.0)); + + registerProcessorParameter("OmegaCutForMerging", "Cut on Omega difference for merging Si and TPC segments", + _dOmegaForMerging, float(0.25)); + + registerProcessorParameter("AngleCutForMerging", "Cut on Opening Angle for merging Si and TPC segments", + _angleForMerging, float(0.10)); + + registerProcessorParameter("Chi2FitCut", "Cut on fit Chi2", _chi2FitCut, float(100.0)); + + registerProcessorParameter("Debug", "Activate debugging?", _debug, int(0)); + + registerProcessorParameter("ForceSiTPCMerging", "Force merging of Si and TPC segments?", _forceMerging, int(0)); + + registerProcessorParameter("D0CutForForcedMerging", "Cut on D0 difference for forced merging of Si and TPC segments", + _d0CutForForcedMerging, float(50.)); + + registerProcessorParameter("Z0CutForForcedMerging", "Cut on Z0 difference for forced merging of Si and TPC segments", + _z0CutForForcedMerging, float(200.)); + registerProcessorParameter("OmegaCutForForcedMerging", "Cut on Omega difference for forced merging of Si and TPC segments", - _dOmegaForForcedMerging, - float(0.15)); - + _dOmegaForForcedMerging, float(0.15)); + registerProcessorParameter("AngleCutForForcedMerging", - "Cut on Opening Angle for forced merging of Si and TPC segments", - _angleForForcedMerging, + "Cut on Opening Angle for forced merging of Si and TPC segments", _angleForForcedMerging, float(0.05)); - - registerProcessorParameter("ForceTPCSegmentsMerging", - "Force merging of TPC Segments?", - _mergeTPCSegments, - int(0)); - - registerProcessorParameter("D0CutToMergeTPCSegments", - "Cut on D0 difference for merging TPC segments", - _d0CutToMergeTPC, - float(100.)); - - registerProcessorParameter("Z0CutToMergeTPCSegments", - "Cut on Z0 difference for merging TPC segments", - _z0CutToMergeTPC, - float(5000.0)); - - registerProcessorParameter("DeltaPCutToMergeTPCSegments", - "Cut on dP/P difference for merging TPC segments", - _dPCutToMergeTPC, - float(0.1)); - - registerProcessorParameter("PtCutToMergeTPCSegments", - "Cut on Pt of tracks for merging TPC segments", - _PtCutToMergeTPC, - float(1.2)); - - - - registerProcessorParameter("cosThetaCutHighPtMerge", - "Cut on cos theta between the two momentum vectors when considering merger of high Pt tracks", - _cosThetaCutHighPtMerge, - float(0.99)); - - registerProcessorParameter("cosThetaCutSoftHighPtMerge", - "cut on cos theta between the two momentum vectors when considering merger of high Pt tracks for softer dp/p cut", - _cosThetaCutSoftHighPtMerge, - float(0.998)); - - registerProcessorParameter("momDiffCutHighPtMerge", - "cut on dp/p when considering merger of high Pt tracks", - _momDiffCutHighPtMerge, - float(0.01)); - + + registerProcessorParameter("ForceTPCSegmentsMerging", "Force merging of TPC Segments?", _mergeTPCSegments, int(0)); + + registerProcessorParameter("D0CutToMergeTPCSegments", "Cut on D0 difference for merging TPC segments", + _d0CutToMergeTPC, float(100.)); + + registerProcessorParameter("Z0CutToMergeTPCSegments", "Cut on Z0 difference for merging TPC segments", + _z0CutToMergeTPC, float(5000.0)); + + registerProcessorParameter("DeltaPCutToMergeTPCSegments", "Cut on dP/P difference for merging TPC segments", + _dPCutToMergeTPC, float(0.1)); + + registerProcessorParameter("PtCutToMergeTPCSegments", "Cut on Pt of tracks for merging TPC segments", + _PtCutToMergeTPC, float(1.2)); + + registerProcessorParameter( + "cosThetaCutHighPtMerge", + "Cut on cos theta between the two momentum vectors when considering merger of high Pt tracks", + _cosThetaCutHighPtMerge, float(0.99)); + + registerProcessorParameter( + "cosThetaCutSoftHighPtMerge", + "cut on cos theta between the two momentum vectors when considering merger of high Pt tracks for softer dp/p cut", + _cosThetaCutSoftHighPtMerge, float(0.998)); + + registerProcessorParameter("momDiffCutHighPtMerge", "cut on dp/p when considering merger of high Pt tracks", + _momDiffCutHighPtMerge, float(0.01)); + registerProcessorParameter("momDiffCutSoftHighPtMerge", - "softer cut on dp/p when considering merger of high Pt tracks", - _momDiffCutSoftHighPtMerge, + "softer cut on dp/p when considering merger of high Pt tracks", _momDiffCutSoftHighPtMerge, float(0.25)); - - registerProcessorParameter("hitDistanceCutHighPtMerge", - "cut on 3D distance between hit and helix extrapolation when considering merger of high Pt tracks", - _hitDistanceCutHighPtMerge, - float(25.0)); - - registerProcessorParameter("maxHitDistanceCutHighPtMerge", - "cut for max 3D distance between any hit and helix extrapolation when considering merger of high Pt tracks", - _maxHitDistanceCutHighPtMerge, - float(50.0)); - + + registerProcessorParameter( + "hitDistanceCutHighPtMerge", + "cut on 3D distance between hit and helix extrapolation when considering merger of high Pt tracks", + _hitDistanceCutHighPtMerge, float(25.0)); + + registerProcessorParameter( + "maxHitDistanceCutHighPtMerge", + "cut for max 3D distance between any hit and helix extrapolation when considering merger of high Pt tracks", + _maxHitDistanceCutHighPtMerge, float(50.0)); + registerProcessorParameter("maxFractionOfOutliersCutHighPtMerge", "cut on maximum fraction of outliers when considering merger of high Pt tracks", - _maxFractionOfOutliersCutHighPtMerge, - float(0.95)); - - - - - - registerProcessorParameter("CutOnTPCHits", - "Cut on the number of the TPC hits for tracks with no Si hits", - _cutOnTPCHits, - int(35)); + _maxFractionOfOutliersCutHighPtMerge, float(0.95)); + + registerProcessorParameter("CutOnTPCHits", "Cut on the number of the TPC hits for tracks with no Si hits", + _cutOnTPCHits, int(35)); + + registerProcessorParameter("CutOnSiHits", "Cut on the number of the Si hits for tracks with no TPC hits", + _cutOnSiHits, int(4)); + + registerProcessorParameter("AssignVTXHits", "Assign left over VTX hits", _assignVTXHits, int(1)); + + registerProcessorParameter("AssignFTDHits", "Assign left over FTD hits", _assignFTDHits, int(1)); - registerProcessorParameter("CutOnSiHits", - "Cut on the number of the Si hits for tracks with no TPC hits", - _cutOnSiHits, - int(4)); - - - registerProcessorParameter("AssignVTXHits", - "Assign left over VTX hits", - _assignVTXHits, - int(1)); - - registerProcessorParameter("AssignFTDHits", - "Assign left over FTD hits", - _assignFTDHits, - int(1)); - - registerProcessorParameter("AssignSITHits", - "Assign left over SIT hits", - _assignSITHits, - int(1)); - - registerProcessorParameter("AssignTPCHits", - "Assign left over TPC hits", - _assignTPCHits, - int(1)); - - registerProcessorParameter("AssignSETHits", - "Assign SET Hits", - _assignSETHits, - int(1)); - - - registerProcessorParameter("AssignETDHits", - "Assign ETD Hits", - _assignETDHits, - int(1)); - - registerProcessorParameter("NHitsExtrapolation", - "number of hits for outward extrapolation", - _nHitsExtrapolation, + registerProcessorParameter("AssignSITHits", "Assign left over SIT hits", _assignSITHits, int(1)); + + registerProcessorParameter("AssignTPCHits", "Assign left over TPC hits", _assignTPCHits, int(1)); + + registerProcessorParameter("AssignSETHits", "Assign SET Hits", _assignSETHits, int(1)); + + registerProcessorParameter("AssignETDHits", "Assign ETD Hits", _assignETDHits, int(1)); + + registerProcessorParameter("NHitsExtrapolation", "number of hits for outward extrapolation", _nHitsExtrapolation, int(35)); - - - registerProcessorParameter("VTXHitToTrackDistance", - "Cut on distance between track and VTX hits", - _distCutForVTXHits, + + registerProcessorParameter("VTXHitToTrackDistance", "Cut on distance between track and VTX hits", _distCutForVTXHits, float(1.5)); - - - registerProcessorParameter("FTDHitToTrackDistance", - "Cut on distance between track and FTD hits", - _distCutForFTDHits, + + registerProcessorParameter("FTDHitToTrackDistance", "Cut on distance between track and FTD hits", _distCutForFTDHits, float(2.0)); - - - registerProcessorParameter("SITHitToTrackDistance", - "Cut on distance between track and SIT hits", - _distCutForSITHits, + + registerProcessorParameter("SITHitToTrackDistance", "Cut on distance between track and SIT hits", _distCutForSITHits, float(2.0)); - - registerProcessorParameter("SETHitToTrackDistance", - "Cut on distance between track and SET hits", - _distCutForSETHits, + + registerProcessorParameter("SETHitToTrackDistance", "Cut on distance between track and SET hits", _distCutForSETHits, float(2.0)); - - - registerProcessorParameter("ETDHitToTrackDistance", - "Cut on distance between track and ETD hits", - _distCutForETDHits, + + registerProcessorParameter("ETDHitToTrackDistance", "Cut on distance between track and ETD hits", _distCutForETDHits, float(10.0)); - - - registerProcessorParameter("TPCHitToTrackDistance", - "Cut on distance between track and TPC hits", - _distCutForTPCHits, + + registerProcessorParameter("TPCHitToTrackDistance", "Cut on distance between track and TPC hits", _distCutForTPCHits, float(15.0)); - - - registerProcessorParameter("CutOnTrackD0", - "Cut on the track parameter D0", - _d0TrkCut, - float(500.)); - - - registerProcessorParameter("CutOnTrackZ0", - "Cut on the track parameter Z0", - _z0TrkCut, - float(500.)); - - - registerProcessorParameter("ForbidOverlapInZTPC", - "Forbid overlap in Z for the merged TPC segments", - _forbidOverlapInZTPC, - int(0)); - + + registerProcessorParameter("CutOnTrackD0", "Cut on the track parameter D0", _d0TrkCut, float(500.)); + + registerProcessorParameter("CutOnTrackZ0", "Cut on the track parameter Z0", _z0TrkCut, float(500.)); + + registerProcessorParameter("ForbidOverlapInZTPC", "Forbid overlap in Z for the merged TPC segments", + _forbidOverlapInZTPC, int(0)); + registerProcessorParameter("ForbidOverlapInZComb", "Forbid overlap in Z for combining TPC segments with tracks having Si hits", - _forbidOverlapInZComb, - int(0)); - - registerProcessorParameter("MultipleScatteringOn", - "Use MultipleScattering in Fit", - _MSOn, - bool(true)); - - registerProcessorParameter("EnergyLossOn", - "Use Energy Loss in Fit", - _ElossOn, - bool(true)); - - registerProcessorParameter("SmoothOn", - "Smooth All Mesurement Sites in Fit", - _SmoothOn, - bool(true)); - - - registerProcessorParameter( "InitialTrackErrorD0", - "Value used for the initial d0 variance of the trackfit", - _initialTrackError_d0, - float(1.e6)); - - registerProcessorParameter( "InitialTrackErrorPhi0", - "Value used for the initial phi0 variance of the trackfit", - _initialTrackError_phi0, - float(1.e2)); - - registerProcessorParameter( "InitialTrackErrorOmega", - "Value used for the initial omega variance of the trackfit", - _initialTrackError_omega, - float(1.e-4)); - - registerProcessorParameter( "InitialTrackErrorZ0", - "Value used for the initial z0 variance of the trackfit", - _initialTrackError_z0, - float(1.e6)); - - registerProcessorParameter( "InitialTrackErrorTanL", - "Value used for the initial tanL variance of the trackfit", - _initialTrackError_tanL, - float(1.e2)); - - - registerProcessorParameter( "MaxChi2PerHit", - "Maximum Chi-squared value allowed when assigning a hit to a track", - _maxChi2PerHit, - double(1.e2)); - - - registerProcessorParameter( "MinChi2ProbForSiliconTracks", - "Minimum Chi-squared P value allowed for Silicon Tracks.", - _minChi2ProbForSiliconTracks, - double(1.e-03)); - - registerProcessorParameter( "MaxChi2ForSiliconTracks", - "Max Chi2/ndf value allowed for Silicon Tracks.", - _maxChi2ForSiliconTracks, - double(15)); - - registerProcessorParameter( "useMaxChi2RequirementForSiTrk", + _forbidOverlapInZComb, int(0)); + + registerProcessorParameter("MultipleScatteringOn", "Use MultipleScattering in Fit", _MSOn, bool(true)); + + registerProcessorParameter("EnergyLossOn", "Use Energy Loss in Fit", _ElossOn, bool(true)); + + registerProcessorParameter("SmoothOn", "Smooth All Mesurement Sites in Fit", _SmoothOn, bool(true)); + + registerProcessorParameter("InitialTrackErrorD0", "Value used for the initial d0 variance of the trackfit", + _initialTrackError_d0, float(1.e6)); + + registerProcessorParameter("InitialTrackErrorPhi0", "Value used for the initial phi0 variance of the trackfit", + _initialTrackError_phi0, float(1.e2)); + + registerProcessorParameter("InitialTrackErrorOmega", "Value used for the initial omega variance of the trackfit", + _initialTrackError_omega, float(1.e-4)); + + registerProcessorParameter("InitialTrackErrorZ0", "Value used for the initial z0 variance of the trackfit", + _initialTrackError_z0, float(1.e6)); + + registerProcessorParameter("InitialTrackErrorTanL", "Value used for the initial tanL variance of the trackfit", + _initialTrackError_tanL, float(1.e2)); + + registerProcessorParameter("MaxChi2PerHit", "Maximum Chi-squared value allowed when assigning a hit to a track", + _maxChi2PerHit, double(1.e2)); + + registerProcessorParameter("MinChi2ProbForSiliconTracks", "Minimum Chi-squared P value allowed for Silicon Tracks.", + _minChi2ProbForSiliconTracks, double(1.e-03)); + + registerProcessorParameter("MaxChi2ForSiliconTracks", "Max Chi2/ndf value allowed for Silicon Tracks.", + _maxChi2ForSiliconTracks, double(15)); + + registerProcessorParameter("useMaxChi2RequirementForSiTrk", "true : MaxChi2ForSiliconTracks is used. false : MinChi2ProbForSiliconTracks is used ", - _useMaxChi2ReqForSiTrk, - bool(true)); - - registerProcessorParameter( "VetoMergeMomentumCut", - "Minimum momentum for which Veto is applicable", - _vetoMergeMomentumCut, - float(2.5)); - - registerProcessorParameter( "MaxAllowedPercentageOfOutliersForTrackCombination", + _useMaxChi2ReqForSiTrk, bool(true)); + + registerProcessorParameter("VetoMergeMomentumCut", "Minimum momentum for which Veto is applicable", + _vetoMergeMomentumCut, float(2.5)); + + registerProcessorParameter("MaxAllowedPercentageOfOutliersForTrackCombination", "Maximum number of outliers allowed before track combination is vetoed", - _maxAllowedPercentageOfOutliersForTrackCombination, - float(0.3)); + _maxAllowedPercentageOfOutliersForTrackCombination, float(0.3)); - registerProcessorParameter( "MaxAllowedSiHitRejectionsForTrackCombination", + registerProcessorParameter("MaxAllowedSiHitRejectionsForTrackCombination", "Maximum number of outliers allowed before track combination is vetoed", - _maxAllowedSiHitRejectionsForTrackCombination, - int(2)); + _maxAllowedSiHitRejectionsForTrackCombination, int(2)); - - #ifdef MARLINTRK_DIAGNOSTICS_ON - - registerOptionalParameter("RunMarlinTrkDiagnostics", "Run MarlinTrk Diagnostics. MarlinTrk must be compiled with MARLINTRK_DIAGNOSTICS_ON defined", _runMarlinTrkDiagnostics, bool(false)); - - registerOptionalParameter("DiagnosticsName", "Name of the root file and root tree if running Diagnostics", _MarlinTrkDiagnosticsName, std::string("FullLDCTrackingDiagnostics")); - + + registerOptionalParameter( + "RunMarlinTrkDiagnostics", + "Run MarlinTrk Diagnostics. MarlinTrk must be compiled with MARLINTRK_DIAGNOSTICS_ON defined", + _runMarlinTrkDiagnostics, bool(false)); + + registerOptionalParameter("DiagnosticsName", "Name of the root file and root tree if running Diagnostics", + _MarlinTrkDiagnosticsName, std::string("FullLDCTrackingDiagnostics")); + #endif + /// Addition by Mori////////////////////////////// - ///Addition by Mori////////////////////////////// - - registerInputCollection(LCIO::SIMTRACKERHIT, - "SimTrackerHit of VXD (VXDCollection)", - "This is used to calculate picking efficiency of a track.", - _colNameVXDSimHit, - std::string("VXDCollection")); - - registerInputCollection(LCIO::SIMTRACKERHIT, - "SimTrackerHit of SIT (SITCollection)", - "This is used to calculate picking efficiency of a track.", - _colNameSITSimHit, - std::string("SITCollection")); - - registerInputCollection(LCIO::SIMTRACKERHIT, - "SimTrackerHit of FTD_STRIP (FTD_STRIPCollection)", - "This is used to calculate picking efficiency of a track.", - _colNameFTDspSimHit, - std::string("FTD_STRIPCollection")); - - registerInputCollection(LCIO::SIMTRACKERHIT, - "SimTrackerHit of FTD_PIXEL (FTD_PIXELCollection)", - "This is used to calculate picking efficiency of a track.", - _colNameFTDpixSimHit, - std::string("FTD_PIXELCollection")); - - registerInputCollection(LCIO::SIMTRACKERHIT, - "SimTrackerHit of TPC (TPCCollection)", - "This is used to calculate picking efficiency of a track.", - _colNameTPCSimHit, - std::string("TPCCollection")); - - registerInputCollection(LCIO::SIMTRACKERHIT, - "SimTrackerHit of SET (SETCollection)", - "This is used to calculate picking efficiency of a track.", - _colNameSETSimHit, - std::string("SETCollection")); - - registerInputCollection("LCRelation", - "VXDTrackerHitRelations", - "Name of the LCRelation input collection", - _colNameVXDTrackerHitRelations, - std::string("VXDTrackerHitRelations")); - - registerInputCollection("LCRelation", - "SITSpacePointRelations", - "Name of the LCRelation input collection", - _colNameSITSpacePointRelations, - std::string("SITSpacePointRelations")); - - registerInputCollection("LCRelation", - "FTDSpacePointRelations", - "Name of the LCRelation input collection", - _colNameFTDSpacePointRelations, - std::string("FTDSpacePointRelations")); - - registerInputCollection("LCRelation", - "FTDPixelTrackerHitRelations", - "Name of the LCRelation input collection", - _colNameFTDPixelTrackerHitRelations, - std::string("FTDPixelTrackerHitRelations")); - - registerInputCollection("LCRelation", - "TPCTrackerHitRelations", - "Name of the LCRelation input collection", - _colNameTPCTrackerHitRelations, - std::string("TPCTrackerHitRelations")); - - registerInputCollection("LCRelation", - "SETSpacePointRelations", - "Name of the LCRelation input collection", - _colNameSETSpacePointRelations, - std::string("SETSpacePointRelations")); - - registerProcessorParameter( "mydebug" , - "mydebug", - _mydebug, - bool(false)); - - registerProcessorParameter( "mydebugPrintMCP" , - "mydebugPrintMCP", - _mydebugPrintMCP, - bool(false)); - - registerProcessorParameter( "FinalTrackCut_strategyA" , - "Tracks which have SIT hit, TPC hit, or |costheta < 0.9| are stored. The others are discarded in the end of this processor. This is for reducing pair BG tracks.", - _FinalTrackCut_strategyA, - bool(false)); - - - - - -} + registerInputCollection(LCIO::SIMTRACKERHIT, "SimTrackerHit of VXD (VXDCollection)", + "This is used to calculate picking efficiency of a track.", _colNameVXDSimHit, + std::string("VXDCollection")); + + registerInputCollection(LCIO::SIMTRACKERHIT, "SimTrackerHit of SIT (SITCollection)", + "This is used to calculate picking efficiency of a track.", _colNameSITSimHit, + std::string("SITCollection")); + + registerInputCollection(LCIO::SIMTRACKERHIT, "SimTrackerHit of FTD_STRIP (FTD_STRIPCollection)", + "This is used to calculate picking efficiency of a track.", _colNameFTDspSimHit, + std::string("FTD_STRIPCollection")); + + registerInputCollection(LCIO::SIMTRACKERHIT, "SimTrackerHit of FTD_PIXEL (FTD_PIXELCollection)", + "This is used to calculate picking efficiency of a track.", _colNameFTDpixSimHit, + std::string("FTD_PIXELCollection")); + + registerInputCollection(LCIO::SIMTRACKERHIT, "SimTrackerHit of TPC (TPCCollection)", + "This is used to calculate picking efficiency of a track.", _colNameTPCSimHit, + std::string("TPCCollection")); + + registerInputCollection(LCIO::SIMTRACKERHIT, "SimTrackerHit of SET (SETCollection)", + "This is used to calculate picking efficiency of a track.", _colNameSETSimHit, + std::string("SETCollection")); + + registerInputCollection("LCRelation", "VXDTrackerHitRelations", "Name of the LCRelation input collection", + _colNameVXDTrackerHitRelations, std::string("VXDTrackerHitRelations")); + + registerInputCollection("LCRelation", "SITSpacePointRelations", "Name of the LCRelation input collection", + _colNameSITSpacePointRelations, std::string("SITSpacePointRelations")); + + registerInputCollection("LCRelation", "FTDSpacePointRelations", "Name of the LCRelation input collection", + _colNameFTDSpacePointRelations, std::string("FTDSpacePointRelations")); + + registerInputCollection("LCRelation", "FTDPixelTrackerHitRelations", "Name of the LCRelation input collection", + _colNameFTDPixelTrackerHitRelations, std::string("FTDPixelTrackerHitRelations")); + registerInputCollection("LCRelation", "TPCTrackerHitRelations", "Name of the LCRelation input collection", + _colNameTPCTrackerHitRelations, std::string("TPCTrackerHitRelations")); + registerInputCollection("LCRelation", "SETSpacePointRelations", "Name of the LCRelation input collection", + _colNameSETSpacePointRelations, std::string("SETSpacePointRelations")); -void FPCCDFullLDCTracking_MarlinTrk::init() { - - printParameters(); - _nRun = -1 ; - _nEvt = 0 ; + registerProcessorParameter("mydebug", "mydebug", _mydebug, bool(false)); + + registerProcessorParameter("mydebugPrintMCP", "mydebugPrintMCP", _mydebugPrintMCP, bool(false)); + + registerProcessorParameter("FinalTrackCut_strategyA", + "Tracks which have SIT hit, TPC hit, or |costheta < 0.9| are stored. The others are " + "discarded in the end of this processor. This is for reducing pair BG tracks.", + _FinalTrackCut_strategyA, bool(false)); +} + +void FPCCDFullLDCTracking_MarlinTrk::init() { + + printParameters(); + _nRun = -1; + _nEvt = 0; PI = acos(-1.); - PIOVER2 = 0.5*PI; - TWOPI = 2*PI; + PIOVER2 = 0.5 * PI; + TWOPI = 2 * PI; _encoder = new UTIL::BitField64(lcio::LCTrackerCellID::encoding_string()); _moriUtil = new moriUTIL(); _purityUtil = new GetPurityUtil(); - // set up the geometery needed by KalTest - //FIXME: for now do KalTest only - make this a steering parameter to use other fitters - _trksystem = MarlinTrk::Factory::createMarlinTrkSystem( "DDKalTest" , 0 , "" ) ; - - if( _trksystem == 0 ){ - - throw EVENT::Exception( std::string(" Cannot initialize MarlinTrkSystem of Type: ") + std::string("KalTest" ) ) ; - + // FIXME: for now do KalTest only - make this a steering parameter to use other fitters + _trksystem = MarlinTrk::Factory::createMarlinTrkSystem("DDKalTest", 0, ""); + + if (_trksystem == 0) { + + throw EVENT::Exception(std::string(" Cannot initialize MarlinTrkSystem of Type: ") + std::string("KalTest")); } - - - _trksystem->setOption( IMarlinTrkSystem::CFG::useQMS, _MSOn ) ; - _trksystem->setOption( IMarlinTrkSystem::CFG::usedEdx, _ElossOn) ; - _trksystem->setOption( IMarlinTrkSystem::CFG::useSmoothing, _SmoothOn) ; - _trksystem->init() ; - + + _trksystem->setOption(IMarlinTrkSystem::CFG::useQMS, _MSOn); + _trksystem->setOption(IMarlinTrkSystem::CFG::usedEdx, _ElossOn); + _trksystem->setOption(IMarlinTrkSystem::CFG::useSmoothing, _SmoothOn); + _trksystem->init(); + #ifdef MARLINTRK_DIAGNOSTICS_ON - - void * dcv = _trksystem->getDiagnositicsPointer(); + + void* dcv = _trksystem->getDiagnositicsPointer(); DiagnosticsController* dc = static_cast(dcv); - dc->init(_MarlinTrkDiagnosticsName,_MarlinTrkDiagnosticsName, _runMarlinTrkDiagnostics); - + dc->init(_MarlinTrkDiagnosticsName, _MarlinTrkDiagnosticsName, _runMarlinTrkDiagnostics); + #endif - + dd4hep::Detector& theDetector = dd4hep::Detector::getInstance(); - - this->setupGeom( theDetector ); - + + this->setupGeom(theDetector); } -void FPCCDFullLDCTracking_MarlinTrk::processRunHeader( LCRunHeader* run) { - - _nRun++ ; +void FPCCDFullLDCTracking_MarlinTrk::processRunHeader(LCRunHeader* run) { + + _nRun++; _nEvt = 0; streamlog_out(DEBUG5) << std::endl; - streamlog_out(DEBUG5) << "FPCCDFullLDCTracking_MarlinTrk ---> new run : run number = " << run->getRunNumber() << std::endl; - -} + streamlog_out(DEBUG5) << "FPCCDFullLDCTracking_MarlinTrk ---> new run : run number = " << run->getRunNumber() + << std::endl; +} + +void FPCCDFullLDCTracking_MarlinTrk::processEvent(LCEvent* evt) { -void FPCCDFullLDCTracking_MarlinTrk::processEvent( LCEvent * evt ) { - - // set the correct configuration for the tracking system for this event - MarlinTrk::TrkSysConfig< MarlinTrk::IMarlinTrkSystem::CFG::useQMS> mson( _trksystem, _MSOn ) ; - MarlinTrk::TrkSysConfig< MarlinTrk::IMarlinTrkSystem::CFG::usedEdx> elosson( _trksystem,_ElossOn) ; - MarlinTrk::TrkSysConfig< MarlinTrk::IMarlinTrkSystem::CFG::useSmoothing> smoothon( _trksystem,_SmoothOn) ; + // set the correct configuration for the tracking system for this event + MarlinTrk::TrkSysConfig mson(_trksystem, _MSOn); + MarlinTrk::TrkSysConfig elosson(_trksystem, _ElossOn); + MarlinTrk::TrkSysConfig smoothon(_trksystem, _SmoothOn); _evt = evt; - - if(_mydebug || _mydebugPrintMCP){ + if (_mydebug || _mydebugPrintMCP) { _naviVecSi.clear(); _naviVecFull.clear(); _mcpMapSi.clear(); _mcpMapFull.clear(); - _navVXD = GetRelations(_evt, _colNameVXDTrackerHitRelations); - _navSIT = GetRelations(_evt, _colNameSITSpacePointRelations); + _navVXD = GetRelations(_evt, _colNameVXDTrackerHitRelations); + _navSIT = GetRelations(_evt, _colNameSITSpacePointRelations); _navFTDpix = GetRelations(_evt, _colNameFTDPixelTrackerHitRelations); - _navFTDsp = GetRelations(_evt, _colNameFTDSpacePointRelations); - _navTPC = GetRelations(_evt, _colNameVXDTrackerHitRelations); - _navSET = GetRelations(_evt, _colNameSETSpacePointRelations); + _navFTDsp = GetRelations(_evt, _colNameFTDSpacePointRelations); + _navTPC = GetRelations(_evt, _colNameVXDTrackerHitRelations); + _navSET = GetRelations(_evt, _colNameSETSpacePointRelations); _naviVecSi.push_back(_navVXD); _naviVecSi.push_back(_navSIT); _naviVecSi.push_back(_navFTDpix); @@ -676,18 +451,16 @@ void FPCCDFullLDCTracking_MarlinTrk::processEvent( LCEvent * evt ) { _naviVecFull = _naviVecSi; _naviVecFull.push_back(_navTPC); _naviVecFull.push_back(_navSET); - _mcpMapSi = LoadMCPMap(0); + _mcpMapSi = LoadMCPMap(0); _mcpMapFull = LoadMCPMap(1); } - streamlog_out(DEBUG5) << std::endl; streamlog_out(DEBUG5) << "FPCCDFullLDCTracking_MarlinTrk -> run = " << evt->getRunNumber() - << " event = " << evt->getEventNumber() << std::endl; + << " event = " << evt->getEventNumber() << std::endl; streamlog_out(DEBUG5) << std::endl; - - - prepareVectors( evt ); + + prepareVectors(evt); streamlog_out(DEBUG5) << "************************************PrepareVectors done..." << std::endl; streamlog_out(DEBUG5) << "************************************Merge TPC/Si ..." << std::endl; @@ -701,21 +474,22 @@ void FPCCDFullLDCTracking_MarlinTrk::processEvent( LCEvent * evt ) { Sorting(_allCombinedTracks); streamlog_out(DEBUG5) << "************************************Sorting by Chi2/NDF done ..." << std::endl; - streamlog_out(DEBUG5) << "************************************Selection of all 2 track combininations ..." << std::endl; + streamlog_out(DEBUG5) << "************************************Selection of all 2 track combininations ..." + << std::endl; SelectCombinedTracks(); - streamlog_out(DEBUG5) << "************************************Selection of all 2 track combininations done ..." << std::endl; + streamlog_out(DEBUG5) << "************************************Selection of all 2 track combininations done ..." + << std::endl; streamlog_out(DEBUG5) << "************************************Trying non combined tracks ..." << std::endl; - AddNotCombinedTracks( ); + AddNotCombinedTracks(); streamlog_out(DEBUG5) << "************************************Non combined tracks added ..." << std::endl; - //CheckTracks( ); + // CheckTracks( ); streamlog_out(DEBUG5) << "************************************Add Non assigned hits ..." << std::endl; AddNotAssignedHits(); streamlog_out(DEBUG5) << "************************************Non assigned hits added ..." << std::endl; - AddTrackColToEvt(evt,_trkImplVec, - _LDCTrackCollection); + AddTrackColToEvt(evt, _trkImplVec, _LDCTrackCollection); streamlog_out(DEBUG5) << "Collections added to event ..." << std::endl; CleanUp(); streamlog_out(DEBUG5) << "Cleanup is done." << std::endl; @@ -723,309 +497,298 @@ void FPCCDFullLDCTracking_MarlinTrk::processEvent( LCEvent * evt ) { // getchar(); streamlog_out(DEBUG5) << std::endl; streamlog_out(DEBUG5) << std::endl; - } -void FPCCDFullLDCTracking_MarlinTrk::AddTrackColToEvt(LCEvent * evt, TrackExtendedVec & trkVec, - std::string TrkColName) { - - LCCollectionVec * colTRK = new LCCollectionVec(LCIO::TRACK); +void FPCCDFullLDCTracking_MarlinTrk::AddTrackColToEvt(LCEvent* evt, TrackExtendedVec& trkVec, std::string TrkColName) { + + LCCollectionVec* colTRK = new LCCollectionVec(LCIO::TRACK); // if we want to point back to the hits we need to set the flag - LCFlagImpl trkFlag(0) ; - trkFlag.setBit( LCIO::TRBIT_HITS ) ; - colTRK->setFlag( trkFlag.getFlag() ) ; - - streamlog_out(DEBUG5)<< "AddTrackColToEvt: Collection " << TrkColName << " is being added to event " << std::endl; - + LCFlagImpl trkFlag(0); + trkFlag.setBit(LCIO::TRBIT_HITS); + colTRK->setFlag(trkFlag.getFlag()); + + streamlog_out(DEBUG5) << "AddTrackColToEvt: Collection " << TrkColName << " is being added to event " << std::endl; + // LCCollectionVec * colRel = NULL; - - + int nTrkCand = int(trkVec.size()); - + int nTotTracks = 0; - float eTot = 0.0; + float eTot = 0.0; float pxTot = 0.0; float pyTot = 0.0; float pzTot = 0.0; - - //SJA:FIXME: So here we are going to do one final refit. This can certainly be optimised, but rather than worry about the mememory management right now lets make it work, and optimise it later ... - - - for (int iTRK=0;iTRKgetTrackerHitExtendedVec(); - + EVENT::TrackerHitVec trkHits; - + streamlog_out(DEBUG2) << " Trying to add track " << trkCand << " to final lcio collection " << std::endl; - - + int nHits = int(hitVec.size()); - - streamlog_out(DEBUG2) << " Trying to add track " << trkCand << " to final lcio collection nHits = " << nHits << std::endl; - - for (int ihit=0;ihitgetUsedInFit() == false ) { - streamlog_out(DEBUG2) << "rejecting hit for track " << trkCand << " at zhit " << hitVec[ihit]->getTrackerHit()->getPosition()[2] << std::endl; + + streamlog_out(DEBUG2) << " Trying to add track " << trkCand << " to final lcio collection nHits = " << nHits + << std::endl; + + for (int ihit = 0; ihit < nHits; ++ihit) { + + if (hitVec[ihit]->getUsedInFit() == false) { + streamlog_out(DEBUG2) << "rejecting hit for track " << trkCand << " at zhit " + << hitVec[ihit]->getTrackerHit()->getPosition()[2] << std::endl; continue; } EVENT::TrackerHit* trkHit = hitVec[ihit]->getTrackerHit(); - - if(trkHit) { - trkHits.push_back(trkHit); - } - else{ - throw EVENT::Exception( std::string("FPCCDFullLDCTracking_MarlinTrk::AddTrackColToEvt: TrackerHit pointer == NULL ") ) ; + + if (trkHit) { + trkHits.push_back(trkHit); + } else { + throw EVENT::Exception( + std::string("FPCCDFullLDCTracking_MarlinTrk::AddTrackColToEvt: TrackerHit pointer == NULL ")); } - } - - - if( trkHits.size() < 3 ) { - streamlog_out(DEBUG3) << "FPCCDFullLDCTracking_MarlinTrk::AddTrackColToEvt: Cannot fit less than 3 hits. Number of hits = " << trkHits.size() << std::endl; - continue ; + + if (trkHits.size() < 3) { + streamlog_out(DEBUG3) + << "FPCCDFullLDCTracking_MarlinTrk::AddTrackColToEvt: Cannot fit less than 3 hits. Number of hits = " + << trkHits.size() << std::endl; + continue; } - - - TrackImpl* Track = new TrackImpl ; - + + TrackImpl* Track = new TrackImpl; + // setup initial dummy covariance matrix EVENT::FloatVec covMatrix; covMatrix.resize(15); - - for (unsigned icov = 0; icovgetGroupTracks(); + + GroupTracks* group = trkCand->getGroupTracks(); TrackStateImpl ts_initial; - + bool prefit_set = false; - + streamlog_out(DEBUG2) << "Track Group = " << group << std::endl; - - if( group ) streamlog_out(DEBUG2) << "Track Group size = " << group->getTrackExtendedVec().size() << std::endl; + + if (group) + streamlog_out(DEBUG2) << "Track Group size = " << group->getTrackExtendedVec().size() << std::endl; if (group != NULL && group->getTrackExtendedVec().size() > 0) { - + // get the second track as this must be the one furthest from the IP TrackExtended* te = 0; - - if(group->getTrackExtendedVec().size()==1) { + + if (group->getTrackExtendedVec().size() == 1) { te = group->getTrackExtendedVec()[0]; } else { te = group->getTrackExtendedVec()[1]; } - - if(te->getTrack()->getTrackState(lcio::TrackState::AtLastHit)){ + + if (te->getTrack()->getTrackState(lcio::TrackState::AtLastHit)) { streamlog_out(DEBUG2) << "Initialise Fit with trackstate from last hit" << group << std::endl; ts_initial = *(te->getTrack()->getTrackState(lcio::TrackState::AtLastHit)); - - - prefit_set = true; + prefit_set = true; } - } - - if( !prefit_set ) { // use parameters at IP - + + if (!prefit_set) { // use parameters at IP + streamlog_out(DEBUG2) << "Initialise Fit with trackstate from IP " << group << std::endl; - + ts_initial.setD0(trkCand->getD0()); ts_initial.setPhi(trkCand->getPhi()); ts_initial.setZ0(trkCand->getZ0()); ts_initial.setOmega(trkCand->getOmega()); ts_initial.setTanLambda(trkCand->getTanLambda()); - + float ref[3]; - ref[0]=ref[1]=ref[2]=0.0; - + ref[0] = ref[1] = ref[2] = 0.0; + ts_initial.setReferencePoint(ref); - - ts_initial.setLocation(lcio::TrackStateImpl::AtIP); - + ts_initial.setLocation(lcio::TrackStateImpl::AtIP); } - + ts_initial.setCovMatrix(covMatrix); - + // sort hits in R - std::vector< std::pair > r2_values; + std::vector> r2_values; r2_values.reserve(trkHits.size()); - - for (TrackerHitVec::iterator it=trkHits.begin(); it!=trkHits.end(); ++it) { + + for (TrackerHitVec::iterator it = trkHits.begin(); it != trkHits.end(); ++it) { EVENT::TrackerHit* h = *it; - float r2 = h->getPosition()[0]*h->getPosition()[0]+h->getPosition()[1]*h->getPosition()[1]; + float r2 = h->getPosition()[0] * h->getPosition()[0] + h->getPosition()[1] * h->getPosition()[1]; r2_values.push_back(std::make_pair(r2, *it)); } - - sort(r2_values.begin(),r2_values.end()); - + + sort(r2_values.begin(), r2_values.end()); + trkHits.clear(); trkHits.reserve(r2_values.size()); - - for (std::vector< std::pair >::iterator it=r2_values.begin(); it!=r2_values.end(); ++it) { + + for (std::vector>::iterator it = r2_values.begin(); it != r2_values.end(); + ++it) { trkHits.push_back(it->second); } - + bool fit_backwards = IMarlinTrack::backward; - + MarlinTrk::IMarlinTrack* marlinTrk = _trksystem->createTrack(); - - + int error = 0; - + try { - - error = MarlinTrk::createFinalisedLCIOTrack(marlinTrk, trkHits, Track, fit_backwards, &ts_initial, _bField, _maxChi2PerHit); - + + error = MarlinTrk::createFinalisedLCIOTrack(marlinTrk, trkHits, Track, fit_backwards, &ts_initial, _bField, + _maxChi2PerHit); + } catch (...) { - + // delete Track; // delete marlinTrk; - - throw ; - + + throw; } - - + #ifdef MARLINTRK_DIAGNOSTICS_ON - if ( error != IMarlinTrack::success && _runMarlinTrkDiagnostics ) { - void * dcv = _trksystem->getDiagnositicsPointer(); + if (error != IMarlinTrack::success && _runMarlinTrkDiagnostics) { + void* dcv = _trksystem->getDiagnositicsPointer(); DiagnosticsController* dc = static_cast(dcv); dc->skip_current_track(); - } + } #endif - - - std::vector > hits_in_fit ; - std::vector > outliers ; - std::vector all_hits; + + std::vector> hits_in_fit; + std::vector> outliers; + std::vector all_hits; all_hits.reserve(300); - + marlinTrk->getHitsInFit(hits_in_fit); - - for ( unsigned ihit = 0; ihit < hits_in_fit.size(); ++ihit) { + + for (unsigned ihit = 0; ihit < hits_in_fit.size(); ++ihit) { all_hits.push_back(hits_in_fit[ihit].first); } - - UTIL::BitField64 cellID_encoder( lcio::LCTrackerCellID::encoding_string() ) ; - + + UTIL::BitField64 cellID_encoder(lcio::LCTrackerCellID::encoding_string()); + MarlinTrk::addHitNumbersToTrack(Track, all_hits, true, cellID_encoder); - + marlinTrk->getOutliers(outliers); - - for ( unsigned ihit = 0; ihit < outliers.size(); ++ihit) { + + for (unsigned ihit = 0; ihit < outliers.size(); ++ihit) { all_hits.push_back(outliers[ihit].first); } - + MarlinTrk::addHitNumbersToTrack(Track, all_hits, false, cellID_encoder); - - + delete marlinTrk; - - if( error != IMarlinTrack::success ) { - - streamlog_out(DEBUG3) << "FPCCDFullLDCTracking_MarlinTrk::AddTrackColToEvt: Track fit failed with error code " << error << " track dropped. Number of hits = "<< trkHits.size() << std::endl; - - delete Track; - continue ; + + if (error != IMarlinTrack::success) { + + streamlog_out(DEBUG3) << "FPCCDFullLDCTracking_MarlinTrk::AddTrackColToEvt: Track fit failed with error code " + << error << " track dropped. Number of hits = " << trkHits.size() << std::endl; + + delete Track; + continue; } - - if( Track->getNdf() < 0) { - streamlog_out(DEBUG3) << "FPCCDFullLDCTracking_MarlinTrk::AddTrackColToEvt: Track fit returns " << Track->getNdf() << " degress of freedom track dropped. Number of hits = "<< trkHits.size() << std::endl; - + + if (Track->getNdf() < 0) { + streamlog_out(DEBUG3) << "FPCCDFullLDCTracking_MarlinTrk::AddTrackColToEvt: Track fit returns " << Track->getNdf() + << " degress of freedom track dropped. Number of hits = " << trkHits.size() << std::endl; + delete Track; - continue ; + continue; } - + const TrackState* trkStateIP = Track->getTrackState(lcio::TrackState::AtIP); - + if (trkStateIP == 0) { - streamlog_out(DEBUG3) << "FPCCDFullLDCTracking_MarlinTrk::AddTrackColToEvt: Track fit returns " << Track->getNdf() << " degress of freedom track dropped. Number of hits = "<< trkHits.size() << std::endl; - throw EVENT::Exception( std::string("FPCCDFullLDCTracking_MarlinTrk::AddTrackColToEvt: trkStateIP pointer == NULL ") ) ; + streamlog_out(DEBUG3) << "FPCCDFullLDCTracking_MarlinTrk::AddTrackColToEvt: Track fit returns " << Track->getNdf() + << " degress of freedom track dropped. Number of hits = " << trkHits.size() << std::endl; + throw EVENT::Exception( + std::string("FPCCDFullLDCTracking_MarlinTrk::AddTrackColToEvt: trkStateIP pointer == NULL ")); } - - - - + if (group != NULL) { TrackExtendedVec trkVecGrp = group->getTrackExtendedVec(); int nGrTRK = int(trkVecGrp.size()); - for (int iGr=0;iGraddTrack(subTrack->getTrack()); // check if it is a tpc looper ... - if( BitSet32( subTrack->getTrack()->getType() )[ lcio::ILDDetID::TPC ] ) { - + if (BitSet32(subTrack->getTrack()->getType())[lcio::ILDDetID::TPC]) { + const TrackVec segments = subTrack->getTrack()->getTracks(); - if ( segments.empty() == false ) { - - for (unsigned iSeg=0;iSegaddTrack(segments[iSeg]); } - } - } } } - + float d0TrkCand = trkCand->getD0(); float z0TrkCand = trkCand->getZ0(); // float phi0TrkCand = trkCand->getPhi(); - - - int nhits_in_vxd = Track->subdetectorHitNumbers()[ 2 * lcio::ILDDetID::VXD - 2 ]; - int nhits_in_ftd = Track->subdetectorHitNumbers()[ 2 * lcio::ILDDetID::FTD - 2 ]; - int nhits_in_sit = Track->subdetectorHitNumbers()[ 2 * lcio::ILDDetID::SIT - 2 ]; - int nhits_in_tpc = Track->subdetectorHitNumbers()[ 2 * lcio::ILDDetID::TPC - 2 ]; - int nhits_in_set = Track->subdetectorHitNumbers()[ 2 * lcio::ILDDetID::SET - 2 ]; - + + int nhits_in_vxd = Track->subdetectorHitNumbers()[2 * lcio::ILDDetID::VXD - 2]; + int nhits_in_ftd = Track->subdetectorHitNumbers()[2 * lcio::ILDDetID::FTD - 2]; + int nhits_in_sit = Track->subdetectorHitNumbers()[2 * lcio::ILDDetID::SIT - 2]; + int nhits_in_tpc = Track->subdetectorHitNumbers()[2 * lcio::ILDDetID::TPC - 2]; + int nhits_in_set = Track->subdetectorHitNumbers()[2 * lcio::ILDDetID::SET - 2]; + int nHitsSi = nhits_in_vxd + nhits_in_ftd + nhits_in_sit; - - streamlog_out( DEBUG3 ) << " Hit numbers for Track "<< Track->id() << ": " - << " vxd hits = " << nhits_in_vxd - << " ftd hits = " << nhits_in_ftd - << " sit hits = " << nhits_in_sit - << " tpc hits = " << nhits_in_tpc - << " set hits = " << nhits_in_set - << std::endl; - - if (nhits_in_vxd > 0) Track->setTypeBit( lcio::ILDDetID::VXD ) ; - if (nhits_in_ftd > 0) Track->setTypeBit( lcio::ILDDetID::FTD ) ; - if (nhits_in_sit > 0) Track->setTypeBit( lcio::ILDDetID::SIT ) ; - if (nhits_in_tpc > 0) Track->setTypeBit( lcio::ILDDetID::TPC ) ; - if (nhits_in_set > 0) Track->setTypeBit( lcio::ILDDetID::SET ) ; - - bool rejectTrack_onTPCHits = (nhits_in_tpc < _cutOnTPCHits) && (nHitsSi<=0); - - bool rejectTrackonSiliconHits = ( (nhits_in_tpc<=0) && (nHitsSi<_cutOnSiHits) ); - bool rejectTrackonImpactParameters = ( fabs(d0TrkCand) > _d0TrkCut ) || ( fabs(z0TrkCand) > _z0TrkCut ); - - - //mori added - //The following cut option will reduce most of pair BG tracks while keeping non-pair BG tracks - bool rejectTrack_on_strategyA = false; - if(_FinalTrackCut_strategyA){ + + streamlog_out(DEBUG3) << " Hit numbers for Track " << Track->id() << ": " + << " vxd hits = " << nhits_in_vxd << " ftd hits = " << nhits_in_ftd + << " sit hits = " << nhits_in_sit << " tpc hits = " << nhits_in_tpc + << " set hits = " << nhits_in_set << std::endl; + + if (nhits_in_vxd > 0) + Track->setTypeBit(lcio::ILDDetID::VXD); + if (nhits_in_ftd > 0) + Track->setTypeBit(lcio::ILDDetID::FTD); + if (nhits_in_sit > 0) + Track->setTypeBit(lcio::ILDDetID::SIT); + if (nhits_in_tpc > 0) + Track->setTypeBit(lcio::ILDDetID::TPC); + if (nhits_in_set > 0) + Track->setTypeBit(lcio::ILDDetID::SET); + + bool rejectTrack_onTPCHits = (nhits_in_tpc < _cutOnTPCHits) && (nHitsSi <= 0); + + bool rejectTrackonSiliconHits = ((nhits_in_tpc <= 0) && (nHitsSi < _cutOnSiHits)); + bool rejectTrackonImpactParameters = (fabs(d0TrkCand) > _d0TrkCut) || (fabs(z0TrkCand) > _z0TrkCut); + + // mori added + // The following cut option will reduce most of pair BG tracks while keeping non-pair BG tracks + bool rejectTrack_on_strategyA = false; + if (_FinalTrackCut_strategyA) { bool has_SIT_hits = (nhits_in_sit > 0); bool has_TPC_hits = (nhits_in_tpc > 0); @@ -1033,77 +796,66 @@ void FPCCDFullLDCTracking_MarlinTrk::AddTrackColToEvt(LCEvent * evt, TrackExtend double tanL = trkStateIP->getTanLambda(); double alpha = 2.99792458E-4; bool is_outside_SIT_coverage = false; - if( std::isnormal(omega) && std::isnormal(tanL) ){ - double Pt = alpha * std::abs( _bField / omega ); - double Pz = Pt * tanL; - double Pabs = Pt * sqrt( 1.0 + tanL * tanL ); - double costheta = Pz/Pabs; - is_outside_SIT_coverage = (std::abs(costheta) > 0.9); + if (std::isnormal(omega) && std::isnormal(tanL)) { + double Pt = alpha * std::abs(_bField / omega); + double Pz = Pt * tanL; + double Pabs = Pt * sqrt(1.0 + tanL * tanL); + double costheta = Pz / Pabs; + is_outside_SIT_coverage = (std::abs(costheta) > 0.9); } - if( !has_SIT_hits && !has_TPC_hits && !is_outside_SIT_coverage ){ + if (!has_SIT_hits && !has_TPC_hits && !is_outside_SIT_coverage) { rejectTrack_on_strategyA = true; } } - if ( rejectTrack_onTPCHits || rejectTrackonSiliconHits || rejectTrackonImpactParameters || rejectTrack_on_strategyA ) { - - - streamlog_out( DEBUG3 ) << " Track " << trkCand - << " rejected : rejectTrack_onTPCHits = " << rejectTrack_onTPCHits - << " rejectTrackonSiliconHits " << rejectTrackonSiliconHits - << " rejectTrackonImpactParameters " << rejectTrackonImpactParameters - << std::endl; - + if (rejectTrack_onTPCHits || rejectTrackonSiliconHits || rejectTrackonImpactParameters || + rejectTrack_on_strategyA) { + + streamlog_out(DEBUG3) << " Track " << trkCand << " rejected : rejectTrack_onTPCHits = " << rejectTrack_onTPCHits + << " rejectTrackonSiliconHits " << rejectTrackonSiliconHits + << " rejectTrackonImpactParameters " << rejectTrackonImpactParameters << std::endl; + delete Track; - + } else { - + float omega = trkStateIP->getOmega(); float tanLambda = trkStateIP->getTanLambda(); float phi0 = trkStateIP->getPhi(); float d0 = trkStateIP->getD0(); float z0 = trkStateIP->getZ0(); - + HelixClass helix; - helix.Initialize_Canonical(phi0,d0,z0,omega,tanLambda,_bField); - + helix.Initialize_Canonical(phi0, d0, z0, omega, tanLambda, _bField); + float trkPx = helix.getMomentum()[0]; float trkPy = helix.getMomentum()[1]; float trkPz = helix.getMomentum()[2]; - float trkP = sqrt(trkPx*trkPx+trkPy*trkPy+trkPz*trkPz); - + float trkP = sqrt(trkPx * trkPx + trkPy * trkPy + trkPz * trkPz); + eTot += trkP; pxTot += trkPx; pyTot += trkPy; - pzTot += trkPz; + pzTot += trkPz; nTotTracks++; - - streamlog_out(DEBUG3) << " Add Track to final Collection: ID = " << Track->id() << " for trkCand "<< trkCand << std::endl; - + + streamlog_out(DEBUG3) << " Add Track to final Collection: ID = " << Track->id() << " for trkCand " << trkCand + << std::endl; + colTRK->addElement(Track); - } } - + streamlog_out(DEBUG5) << std::endl; - streamlog_out(DEBUG5) << "Number of accepted " << TrkColName << " = " - << nTotTracks << std::endl; - streamlog_out(DEBUG5) << "Total 4-momentum of " << TrkColName << " : E = " << eTot - << " Px = " << pxTot - << " Py = " << pyTot - << " Pz = " << pzTot << std::endl; + streamlog_out(DEBUG5) << "Number of accepted " << TrkColName << " = " << nTotTracks << std::endl; + streamlog_out(DEBUG5) << "Total 4-momentum of " << TrkColName << " : E = " << eTot << " Px = " << pxTot + << " Py = " << pyTot << " Pz = " << pzTot << std::endl; streamlog_out(DEBUG5) << std::endl; - - evt->addCollection(colTRK,TrkColName.c_str()); - - + + evt->addCollection(colTRK, TrkColName.c_str()); } +void FPCCDFullLDCTracking_MarlinTrk::prepareVectors(LCEvent* event) { -void FPCCDFullLDCTracking_MarlinTrk::prepareVectors(LCEvent * event ) { - - - - _allTPCHits.clear(); _allVTXHits.clear(); _allFTDHits.clear(); @@ -1117,507 +869,511 @@ void FPCCDFullLDCTracking_MarlinTrk::prepareVectors(LCEvent * event ) { _allNonCombinedSiTracks.clear(); _trkImplVec.clear(); _candidateCombinedTracks.clear(); - - - std::map mapTrackerHits; - + + std::map mapTrackerHits; + // Reading TPC hits try { - - LCCollection * col = event->getCollection(_TPCTrackerHitCollection.c_str()); - + + LCCollection* col = event->getCollection(_TPCTrackerHitCollection.c_str()); + int nelem = col->getNumberOfElements(); - + streamlog_out(DEBUG5) << "Number of TPC hits = " << nelem << std::endl; - - for (int ielem=0;ielem(col->getElementAt(ielem)); - TrackerHitExtended * hitExt = new TrackerHitExtended(hit); - + + for (int ielem = 0; ielem < nelem; ++ielem) { + + TrackerHit* hit = dynamic_cast(col->getElementAt(ielem)); + TrackerHitExtended* hitExt = new TrackerHitExtended(hit); + // Covariance Matrix in LCIO is defined in XYZ convert to R-Phi-Z // For no error in r - + double tpcRPhiRes = sqrt(hit->getCovMatrix()[0] + hit->getCovMatrix()[2]); double tpcZRes = sqrt(hit->getCovMatrix()[5]); - + hitExt->setResolutionRPhi(float(tpcRPhiRes)); hitExt->setResolutionZ(float(tpcZRes)); - + // type and det are no longer used, set to INT_MAX to try and catch any missuse hitExt->setType(int(INT_MAX)); hitExt->setDet(int(INT_MAX)); - _allTPCHits.push_back( hitExt ); + _allTPCHits.push_back(hitExt); mapTrackerHits[hit] = hitExt; double pos[3]; - - for (int i=0; i<3; ++i) { + + for (int i = 0; i < 3; ++i) { pos[i] = hit->getPosition()[i]; } - + unsigned int layer = static_cast(getLayerID(hit)); - - streamlog_out( DEBUG1 ) << " TPC Hit added : @ " << pos[0] << " " << pos[1] << " " << pos[2] << " drphi " << tpcRPhiRes << " dz " << tpcZRes << " layer = " << layer << std::endl; - + + streamlog_out(DEBUG1) << " TPC Hit added : @ " << pos[0] << " " << pos[1] << " " << pos[2] << " drphi " + << tpcRPhiRes << " dz " << tpcZRes << " layer = " << layer << std::endl; } - } - catch( DataNotAvailableException &e ) { + } catch (DataNotAvailableException& e) { streamlog_out(DEBUG4) << _TPCTrackerHitCollection.c_str() << " collection is unavailable" << std::endl; }; - - + // Reading in FTD Pixel Hits Collection //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ try { - - LCCollection * hitCollection = event->getCollection(_FTDPixelHitCollection.c_str()); - + + LCCollection* hitCollection = event->getCollection(_FTDPixelHitCollection.c_str()); + int nelem = hitCollection->getNumberOfElements(); - + streamlog_out(DEBUG5) << "Number of FTD Pixel hits = " << nelem << std::endl; - - for (int ielem=0; ielem(hitCollection->getElementAt(ielem)); - - TrackerHitExtended * hitExt = new TrackerHitExtended( hit ); - - double point_res_rphi = sqrt( hit->getdU()*hit->getdU() + hit->getdV()*hit->getdV() ); - hitExt->setResolutionRPhi( point_res_rphi ); - - // SJA:FIXME why is this needed? + + for (int ielem = 0; ielem < nelem; ++ielem) { + TrackerHitPlane* hit = dynamic_cast(hitCollection->getElementAt(ielem)); + + TrackerHitExtended* hitExt = new TrackerHitExtended(hit); + + double point_res_rphi = sqrt(hit->getdU() * hit->getdU() + hit->getdV() * hit->getdV()); + hitExt->setResolutionRPhi(point_res_rphi); + + // SJA:FIXME why is this needed? hitExt->setResolutionZ(0.1); - + // type and det are no longer used, set to INT_MAX to try and catch any missuse - hitExt->setType(int(INT_MAX)); + hitExt->setType(int(INT_MAX)); hitExt->setDet(int(INT_MAX)); - - _allFTDHits.push_back( hitExt ); + + _allFTDHits.push_back(hitExt); mapTrackerHits[hit] = hitExt; - + // get the layer number unsigned int layer = static_cast(getLayerID(hit)); unsigned int petalIndex = static_cast(getModuleID(hit)); - - if ( _petalBasedFTDWithOverlaps == true ) { - + + if (_petalBasedFTDWithOverlaps == true) { + // as we are dealing with staggered petals we will use 2*nlayers in each directions +/- z - // the layers will follow the even odd numbering of the petals - if ( petalIndex % 2 == 0 ) { - layer = 2*layer; - } - else { - layer = 2*layer + 1; + // the layers will follow the even odd numbering of the petals + if (petalIndex % 2 == 0) { + layer = 2 * layer; + } else { + layer = 2 * layer + 1; } - } - + if (layer >= _nLayersFTD) { - streamlog_out(ERROR) << "FPCCDFullLDCTracking_MarlinTrk => fatal error in FTD : layer is outside allowed range : " << layer << " number of layers = " << _nLayersFTD << std::endl; + streamlog_out(ERROR) + << "FPCCDFullLDCTracking_MarlinTrk => fatal error in FTD : layer is outside allowed range : " << layer + << " number of layers = " << _nLayersFTD << std::endl; exit(1); } - + double pos[3]; - - for (int i=0; i<3; ++i) { + + for (int i = 0; i < 3; ++i) { pos[i] = hit->getPosition()[i]; - } - - streamlog_out( DEBUG1 ) << " FTD Pixel Hit added : @ " << pos[0] << " " << pos[1] << " " << pos[2] << " drphi " << hitExt->getResolutionRPhi() << " dz " << hitExt->getResolutionZ() << " layer = " << layer << std::endl; - + } + + streamlog_out(DEBUG1) << " FTD Pixel Hit added : @ " << pos[0] << " " << pos[1] << " " << pos[2] << " drphi " + << hitExt->getResolutionRPhi() << " dz " << hitExt->getResolutionZ() + << " layer = " << layer << std::endl; } - } - catch(DataNotAvailableException &e ) { + } catch (DataNotAvailableException& e) { streamlog_out(DEBUG4) << _FTDPixelHitCollection.c_str() << " collection is unavailable" << std::endl; } - + // Reading in FTD SpacePoint Collection //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ try { - - LCCollection * hitCollection = event->getCollection(_FTDSpacePointCollection.c_str()); - + + LCCollection* hitCollection = event->getCollection(_FTDSpacePointCollection.c_str()); + int nelem = hitCollection->getNumberOfElements(); - + streamlog_out(DEBUG5) << "Number of FTD SpacePoints hits = " << nelem << std::endl; - - for (int ielem=0; ielem(hitCollection->getElementAt(ielem)); - - TrackerHitExtended * hitExt = new TrackerHitExtended( hit ); - + + for (int ielem = 0; ielem < nelem; ++ielem) { + + TrackerHit* hit = dynamic_cast(hitCollection->getElementAt(ielem)); + + TrackerHitExtended* hitExt = new TrackerHitExtended(hit); + // SJA:FIXME: fudge for now by a factor of two and ignore covariance - double point_res_rphi = 2 * sqrt( hit->getCovMatrix()[0] + hit->getCovMatrix()[2] ); - - hitExt->setResolutionRPhi( point_res_rphi ); - - // SJA:FIXME why is this needed? + double point_res_rphi = 2 * sqrt(hit->getCovMatrix()[0] + hit->getCovMatrix()[2]); + + hitExt->setResolutionRPhi(point_res_rphi); + + // SJA:FIXME why is this needed? hitExt->setResolutionZ(0.1); - - // type is now only used in one place where it is set to 0 to reject hits from a fit, set to INT_MAX to try and catch any missuse + + // type is now only used in one place where it is set to 0 to reject hits from a fit, set to INT_MAX to try and + // catch any missuse hitExt->setType(int(INT_MAX)); // det is no longer used set to INT_MAX to try and catch any missuse hitExt->setDet(int(INT_MAX)); - - _allFTDHits.push_back( hitExt ); + + _allFTDHits.push_back(hitExt); mapTrackerHits[hit] = hitExt; - - + // get the layer number unsigned int layer = static_cast(getLayerID(hit)); unsigned int petalIndex = static_cast(getModuleID(hit)); - - if ( _petalBasedFTDWithOverlaps == true ) { - + + if (_petalBasedFTDWithOverlaps == true) { + // as we are dealing with staggered petals we will use 2*nlayers in each directions +/- z - // the layers will follow the even odd numbering of the petals - if ( petalIndex % 2 == 0 ) { - layer = 2*layer; - } - else { - layer = 2*layer + 1; + // the layers will follow the even odd numbering of the petals + if (petalIndex % 2 == 0) { + layer = 2 * layer; + } else { + layer = 2 * layer + 1; } - } - + if (layer >= _nLayersFTD) { - streamlog_out(ERROR) << "FPCCDFullLDCTracking_MarlinTrk => fatal error in FTD : layer is outside allowed range : " << layer << " number of layers = " << _nLayersFTD << std::endl; + streamlog_out(ERROR) + << "FPCCDFullLDCTracking_MarlinTrk => fatal error in FTD : layer is outside allowed range : " << layer + << " number of layers = " << _nLayersFTD << std::endl; exit(1); } - + double pos[3]; - - for (int i=0; i<3; ++i) { + + for (int i = 0; i < 3; ++i) { pos[i] = hit->getPosition()[i]; - } - - streamlog_out( DEBUG1 ) << " FTD SpacePoint Hit added : @ " << pos[0] << " " << pos[1] << " " << pos[2] << " drphi " << hitExt->getResolutionRPhi() << " dz " << hitExt->getResolutionZ() << " layer = " << layer << std::endl; - - + } + + streamlog_out(DEBUG1) << " FTD SpacePoint Hit added : @ " << pos[0] << " " << pos[1] << " " << pos[2] << " drphi " + << hitExt->getResolutionRPhi() << " dz " << hitExt->getResolutionZ() + << " layer = " << layer << std::endl; } - } - catch(DataNotAvailableException &e ) { + } catch (DataNotAvailableException& e) { streamlog_out(DEBUG4) << _FTDSpacePointCollection.c_str() << " collection is unavailable" << std::endl; } - - - - + try { - - LCCollection *hitCollection = event->getCollection(_SITTrackerHitCollection.c_str()); - + + LCCollection* hitCollection = event->getCollection(_SITTrackerHitCollection.c_str()); + int nelem = hitCollection->getNumberOfElements(); - + streamlog_out(DEBUG5) << "Number of SIT hits = " << nelem << std::endl; - - TrackerHit* trkhit = 0; - TrackerHitPlane* trkhit_P = 0; + + TrackerHit* trkhit = 0; + TrackerHitPlane* trkhit_P = 0; TrackerHitZCylinder* trkhit_C = 0; - + double drphi(NAN); double dz(NAN); - - for (int ielem=0; ielem(hitCollection->getElementAt(ielem)); - + int layer = getLayerID(trkhit); - + if (layer < 0 || (unsigned)layer >= _nLayersSIT) { - streamlog_out(ERROR) << "FPCCDFullLDCTracking_MarlinTrk => fatal error in SIT : layer is outside allowed range : " << layer << std::endl; + streamlog_out(ERROR) + << "FPCCDFullLDCTracking_MarlinTrk => fatal error in SIT : layer is outside allowed range : " << layer + << std::endl; exit(1); } - + // first check that we have not been given 1D hits by mistake, as they won't work here - if ( BitSet32( trkhit->getType() )[ UTIL::ILDTrkHitTypeBit::ONE_DIMENSIONAL ] ) { - - streamlog_out(ERROR) << "FPCCDFullLDCTracking_MarlinTrk: SIT Hit cannot be of type UTIL::ILDTrkHitTypeBit::ONE_DIMENSIONAL COMPOSITE SPACEPOINTS must be use instead. \n\n exit(1) called from file " << __FILE__ << " and line " << __LINE__ << std::endl; + if (BitSet32(trkhit->getType())[UTIL::ILDTrkHitTypeBit::ONE_DIMENSIONAL]) { + + streamlog_out(ERROR) + << "FPCCDFullLDCTracking_MarlinTrk: SIT Hit cannot be of type UTIL::ILDTrkHitTypeBit::ONE_DIMENSIONAL " + "COMPOSITE SPACEPOINTS must be use instead. \n\n exit(1) called from file " + << __FILE__ << " and line " << __LINE__ << std::endl; exit(1); - - } + + } // most likely case: COMPOSITE_SPACEPOINT hits formed from stereo strip hits - else if ( BitSet32( trkhit->getType() )[ UTIL::ILDTrkHitTypeBit::COMPOSITE_SPACEPOINT ] ) { - + else if (BitSet32(trkhit->getType())[UTIL::ILDTrkHitTypeBit::COMPOSITE_SPACEPOINT]) { + // SJA:FIXME: fudge for now by a factor of two and ignore covariance - drphi = 2 * sqrt(trkhit->getCovMatrix()[0] + trkhit->getCovMatrix()[2]); - dz = sqrt(trkhit->getCovMatrix()[5]); - - } + drphi = 2 * sqrt(trkhit->getCovMatrix()[0] + trkhit->getCovMatrix()[2]); + dz = sqrt(trkhit->getCovMatrix()[5]); + + } // or a PIXEL based SIT, using 2D TrackerHitPlane like the VXD above - else if ( ( trkhit_P = dynamic_cast( hitCollection->getElementAt( ielem ) ) ) ) { - - // first we need to check if the measurement vectors are aligned with the global coordinates - Vector3D U(1.0,trkhit_P->getU()[1],trkhit_P->getU()[0],Vector3D::spherical); - Vector3D V(1.0,trkhit_P->getV()[1],trkhit_P->getV()[0],Vector3D::spherical); - Vector3D Z(0.0,0.0,1.0); - + else if ((trkhit_P = dynamic_cast(hitCollection->getElementAt(ielem)))) { + + // first we need to check if the measurement vectors are aligned with the global coordinates + Vector3D U(1.0, trkhit_P->getU()[1], trkhit_P->getU()[0], Vector3D::spherical); + Vector3D V(1.0, trkhit_P->getV()[1], trkhit_P->getV()[0], Vector3D::spherical); + Vector3D Z(0.0, 0.0, 1.0); + const float eps = 1.0e-07; - // V must be the global z axis - if( fabs(1.0 - V.dot(Z)) > eps ) { - streamlog_out(ERROR) << "FPCCDFullLDCTracking_MarlinTrk: PIXEL SIT Hit measurment vectors V is not equal to the global Z axis. \n\n exit(1) called from file " << __FILE__ << " and line " << __LINE__ << std::endl; + // V must be the global z axis + if (fabs(1.0 - V.dot(Z)) > eps) { + streamlog_out(ERROR) << "FPCCDFullLDCTracking_MarlinTrk: PIXEL SIT Hit measurment vectors V is not equal to " + "the global Z axis. \n\n exit(1) called from file " + << __FILE__ << " and line " << __LINE__ << std::endl; exit(1); } - + // U must be normal to the global z axis - if( fabs(U.dot(Z)) > eps ) { - streamlog_out(ERROR) << "FPCCDFullLDCTracking_MarlinTrk: PIXEL SIT Hit measurment vectors U is not in the global X-Y plane. \n\n exit(1) called from file " << __FILE__ << " and line " << __LINE__ << std::endl; + if (fabs(U.dot(Z)) > eps) { + streamlog_out(ERROR) << "FPCCDFullLDCTracking_MarlinTrk: PIXEL SIT Hit measurment vectors U is not in the " + "global X-Y plane. \n\n exit(1) called from file " + << __FILE__ << " and line " << __LINE__ << std::endl; exit(1); } - + drphi = trkhit_P->getdU(); - dz = trkhit_P->getdV(); - - } - // or a simple cylindrical design, as used in the LOI - else if ( ( trkhit_C = dynamic_cast( hitCollection->getElementAt( ielem ) ) ) ) { - + dz = trkhit_P->getdV(); + + } + // or a simple cylindrical design, as used in the LOI + else if ((trkhit_C = dynamic_cast(hitCollection->getElementAt(ielem)))) { + drphi = trkhit_C->getdRPhi(); - dz = trkhit_C->getdZ(); - - } + dz = trkhit_C->getdZ(); + + } // this would be very unlikely, but who knows ... just an ordinary TrackerHit, which is not a COMPOSITE_SPACEPOINT else { - + // SJA:FIXME: fudge for now by a factor of two and ignore covariance - drphi = 2 * sqrt(trkhit->getCovMatrix()[0] + trkhit->getCovMatrix()[2]); - dz = sqrt(trkhit->getCovMatrix()[5]); - + drphi = 2 * sqrt(trkhit->getCovMatrix()[0] + trkhit->getCovMatrix()[2]); + dz = sqrt(trkhit->getCovMatrix()[5]); } - - // now that the hit type has been established carry on and create a - - TrackerHitExtended * hitExt = new TrackerHitExtended( trkhit ); - + + // now that the hit type has been established carry on and create a + + TrackerHitExtended* hitExt = new TrackerHitExtended(trkhit); + // SJA:FIXME: just use planar res for now hitExt->setResolutionRPhi(drphi); hitExt->setResolutionZ(dz); - - // set type is now only used in one place where it is set to 0 to reject hits from a fit, set to INT_MAX to try and catch any missuse + + // set type is now only used in one place where it is set to 0 to reject hits from a fit, set to INT_MAX to try + // and catch any missuse hitExt->setType(int(INT_MAX)); // det is no longer used set to INT_MAX to try and catch any missuse hitExt->setDet(int(INT_MAX)); - - _allSITHits.push_back( hitExt ); + + _allSITHits.push_back(hitExt); mapTrackerHits[trkhit] = hitExt; - - + double pos[3]; - - for (int i=0; i<3; ++i) { + + for (int i = 0; i < 3; ++i) { pos[i] = trkhit->getPosition()[i]; } - - streamlog_out( DEBUG1 ) << " SIT Hit " << trkhit->id() << " added : @ " << pos[0] << " " << pos[1] << " " << pos[2] << " drphi " << hitExt->getResolutionRPhi() << " dz " << hitExt->getResolutionZ() << " layer = " << layer << std::endl; - + + streamlog_out(DEBUG1) << " SIT Hit " << trkhit->id() << " added : @ " << pos[0] << " " << pos[1] << " " << pos[2] + << " drphi " << hitExt->getResolutionRPhi() << " dz " << hitExt->getResolutionZ() + << " layer = " << layer << std::endl; } - - } catch(DataNotAvailableException &e) { - streamlog_out( DEBUG4 ) << " collection not found : " << _SITTrackerHitCollection.c_str() << std::endl ; + + } catch (DataNotAvailableException& e) { + streamlog_out(DEBUG4) << " collection not found : " << _SITTrackerHitCollection.c_str() << std::endl; } - - + try { - - LCCollection *hitCollection = event->getCollection(_SETTrackerHitCollection.c_str()); - + + LCCollection* hitCollection = event->getCollection(_SETTrackerHitCollection.c_str()); + int nelem = hitCollection->getNumberOfElements(); - + streamlog_out(DEBUG5) << "Number of SET hits = " << nelem << std::endl; - - TrackerHit* trkhit = 0; - TrackerHitPlane* trkhit_P = 0; + + TrackerHit* trkhit = 0; + TrackerHitPlane* trkhit_P = 0; TrackerHitZCylinder* trkhit_C = 0; - + double drphi(NAN); double dz(NAN); - - for (int ielem=0; ielem(hitCollection->getElementAt(ielem)); - + int layer = getLayerID(trkhit); - + if (layer < 0 || (unsigned)layer >= _nLayersSET) { - streamlog_out(ERROR) << "FPCCDFullLDCTracking_MarlinTrk => fatal error in SET : layer is outside allowed range : " << layer << std::endl; + streamlog_out(ERROR) + << "FPCCDFullLDCTracking_MarlinTrk => fatal error in SET : layer is outside allowed range : " << layer + << std::endl; exit(1); } - + // first check that we have not been given 1D hits by mistake, as they won't work here - if ( BitSet32( trkhit->getType() )[ UTIL::ILDTrkHitTypeBit::ONE_DIMENSIONAL ] ) { - - streamlog_out(ERROR) << "FPCCDFullLDCTracking_MarlinTrk: SET Hit cannot be of type UTIL::ILDTrkHitTypeBit::ONE_DIMENSIONAL COMPOSITE SPACEPOINTS must be use instead. \n\n exit(1) called from file " << __FILE__ << " and line " << __LINE__ << std::endl; + if (BitSet32(trkhit->getType())[UTIL::ILDTrkHitTypeBit::ONE_DIMENSIONAL]) { + + streamlog_out(ERROR) + << "FPCCDFullLDCTracking_MarlinTrk: SET Hit cannot be of type UTIL::ILDTrkHitTypeBit::ONE_DIMENSIONAL " + "COMPOSITE SPACEPOINTS must be use instead. \n\n exit(1) called from file " + << __FILE__ << " and line " << __LINE__ << std::endl; exit(1); - + } // most likely case: COMPOSITE_SPACEPOINT hits formed from stereo strip hits - else if ( BitSet32( trkhit->getType() )[ UTIL::ILDTrkHitTypeBit::COMPOSITE_SPACEPOINT ] ) { - + else if (BitSet32(trkhit->getType())[UTIL::ILDTrkHitTypeBit::COMPOSITE_SPACEPOINT]) { + // SJA:FIXME: fudge for now by a factor of two and ignore covariance - drphi = 2 * sqrt(trkhit->getCovMatrix()[0] + trkhit->getCovMatrix()[2]); - dz = sqrt(trkhit->getCovMatrix()[5]); - + drphi = 2 * sqrt(trkhit->getCovMatrix()[0] + trkhit->getCovMatrix()[2]); + dz = sqrt(trkhit->getCovMatrix()[5]); + } // or a PIXEL based SET, using 2D TrackerHitPlane like the VXD above - else if ( ( trkhit_P = dynamic_cast( hitCollection->getElementAt( ielem ) ) ) ) { - + else if ((trkhit_P = dynamic_cast(hitCollection->getElementAt(ielem)))) { + // first we need to check if the measurement vectors are aligned with the global coordinates - Vector3D U(1.0,trkhit_P->getU()[1],trkhit_P->getU()[0],Vector3D::spherical); - Vector3D V(1.0,trkhit_P->getV()[1],trkhit_P->getV()[0],Vector3D::spherical); - Vector3D Z(0.0,0.0,1.0); - + Vector3D U(1.0, trkhit_P->getU()[1], trkhit_P->getU()[0], Vector3D::spherical); + Vector3D V(1.0, trkhit_P->getV()[1], trkhit_P->getV()[0], Vector3D::spherical); + Vector3D Z(0.0, 0.0, 1.0); + const float eps = 1.0e-07; // V must be the global z axis - if( fabs(1.0 - V.dot(Z)) > eps ) { - streamlog_out(ERROR) << "FPCCDFullLDCTracking_MarlinTrk: PIXEL SET Hit measurment vectors V is not equal to the global Z axis. \n\n exit(1) called from file " << __FILE__ << " and line " << __LINE__ << std::endl; + if (fabs(1.0 - V.dot(Z)) > eps) { + streamlog_out(ERROR) << "FPCCDFullLDCTracking_MarlinTrk: PIXEL SET Hit measurment vectors V is not equal to " + "the global Z axis. \n\n exit(1) called from file " + << __FILE__ << " and line " << __LINE__ << std::endl; exit(1); } - + // U must be normal to the global z axis - if( fabs(U.dot(Z)) > eps ) { - streamlog_out(ERROR) << "FPCCDFullLDCTracking_MarlinTrk: PIXEL SET Hit measurment vectors U is not in the global X-Y plane. \n\n exit(1) called from file " << __FILE__ << " and line " << __LINE__ << std::endl; + if (fabs(U.dot(Z)) > eps) { + streamlog_out(ERROR) << "FPCCDFullLDCTracking_MarlinTrk: PIXEL SET Hit measurment vectors U is not in the " + "global X-Y plane. \n\n exit(1) called from file " + << __FILE__ << " and line " << __LINE__ << std::endl; exit(1); } - + drphi = trkhit_P->getdU(); - dz = trkhit_P->getdV(); - + dz = trkhit_P->getdV(); + } // or a simple cylindrical design, as used in the LOI - else if ( ( trkhit_C = dynamic_cast( hitCollection->getElementAt( ielem ) ) ) ) { - + else if ((trkhit_C = dynamic_cast(hitCollection->getElementAt(ielem)))) { + drphi = trkhit_C->getdRPhi(); - dz = trkhit_C->getdZ(); - + dz = trkhit_C->getdZ(); + } // this would be very unlikely, but who knows ... just an ordinary TrackerHit, which is not a COMPOSITE_SPACEPOINT else { - + // SJA:FIXME: fudge for now by a factor of two and ignore covariance - drphi = 2 * sqrt(trkhit->getCovMatrix()[0] + trkhit->getCovMatrix()[2]); - dz = sqrt(trkhit->getCovMatrix()[5]); - + drphi = 2 * sqrt(trkhit->getCovMatrix()[0] + trkhit->getCovMatrix()[2]); + dz = sqrt(trkhit->getCovMatrix()[5]); } - + // now that the hit type has been established carry on and create a - - TrackerHitExtended * hitExt = new TrackerHitExtended( trkhit ); - + + TrackerHitExtended* hitExt = new TrackerHitExtended(trkhit); + // SJA:FIXME: just use planar res for now hitExt->setResolutionRPhi(drphi); hitExt->setResolutionZ(dz); - - // set type is now only used in one place where it is set to 0 to reject hits from a fit, set to INT_MAX to try and catch any missuse + + // set type is now only used in one place where it is set to 0 to reject hits from a fit, set to INT_MAX to try + // and catch any missuse hitExt->setType(int(INT_MAX)); // det is no longer used set to INT_MAX to try and catch any missuse hitExt->setDet(int(INT_MAX)); - - _allSETHits.push_back( hitExt ); + + _allSETHits.push_back(hitExt); mapTrackerHits[trkhit] = hitExt; - - + double pos[3]; - - for (int i=0; i<3; ++i) { + + for (int i = 0; i < 3; ++i) { pos[i] = trkhit->getPosition()[i]; } - - streamlog_out( DEBUG1 ) << " SET Hit " << trkhit->id() << " added : @ " << pos[0] << " " << pos[1] << " " << pos[2] << " drphi " << hitExt->getResolutionRPhi() << " dz " << hitExt->getResolutionZ() << " layer = " << layer << std::endl; - + + streamlog_out(DEBUG1) << " SET Hit " << trkhit->id() << " added : @ " << pos[0] << " " << pos[1] << " " << pos[2] + << " drphi " << hitExt->getResolutionRPhi() << " dz " << hitExt->getResolutionZ() + << " layer = " << layer << std::endl; } - - } catch(DataNotAvailableException &e) { - streamlog_out( DEBUG4 ) << " collection not found : " << _SETTrackerHitCollection.c_str() << std::endl ; + + } catch (DataNotAvailableException& e) { + streamlog_out(DEBUG4) << " collection not found : " << _SETTrackerHitCollection.c_str() << std::endl; } - // Reading VTX Hits try { - LCCollection * col = event->getCollection(_VTXTrackerHitCollection.c_str()); - + LCCollection* col = event->getCollection(_VTXTrackerHitCollection.c_str()); + int nelem = col->getNumberOfElements(); - + streamlog_out(DEBUG5) << "Number of VXD hits = " << nelem << std::endl; - - for (int ielem=0;ielem(col->getElementAt(ielem)); - TrackerHitExtended * hitExt = new TrackerHitExtended(trkhit); - + + for (int ielem = 0; ielem < nelem; ++ielem) { + TrackerHitPlane* trkhit = dynamic_cast(col->getElementAt(ielem)); + TrackerHitExtended* hitExt = new TrackerHitExtended(trkhit); + // SJA:FIXME: just use planar res for now hitExt->setResolutionRPhi(trkhit->getdU()); hitExt->setResolutionZ(trkhit->getdV()); - + // type and det are no longer used, set to INT_MAX to try and catch any missuse - hitExt->setType(int(INT_MAX)); + hitExt->setType(int(INT_MAX)); hitExt->setDet(int(INT_MAX)); - _allVTXHits.push_back( hitExt ); + _allVTXHits.push_back(hitExt); mapTrackerHits[trkhit] = hitExt; - + double pos[3]; - - for (int i=0; i<3; ++i) { + + for (int i = 0; i < 3; ++i) { pos[i] = trkhit->getPosition()[i]; } - + int layer = getLayerID(trkhit); - - streamlog_out( DEBUG1 ) << " VXD Hit " << trkhit->id() << " added : @ " << pos[0] << " " << pos[1] << " " << pos[2] << " drphi " << hitExt->getResolutionRPhi() << " dz " << hitExt->getResolutionZ() << " layer = " << layer << std::endl; - - + + streamlog_out(DEBUG1) << " VXD Hit " << trkhit->id() << " added : @ " << pos[0] << " " << pos[1] << " " << pos[2] + << " drphi " << hitExt->getResolutionRPhi() << " dz " << hitExt->getResolutionZ() + << " layer = " << layer << std::endl; } - - - } - catch( DataNotAvailableException &e ) { + + } catch (DataNotAvailableException& e) { streamlog_out(DEBUG4) << _VTXTrackerHitCollection.c_str() << " collection is unavailable" << std::endl; } - - + // Reading TPC Tracks try { - LCCollection * col = event->getCollection(_TPCTrackCollection.c_str()); + LCCollection* col = event->getCollection(_TPCTrackCollection.c_str()); int nelem = col->getNumberOfElements(); streamlog_out(DEBUG5) << std::endl; streamlog_out(DEBUG5) << "Number of TPC Tracks = " << nelem << " in " << _TPCTrackCollection.c_str() << std::endl; - streamlog_out(DEBUG5) << " Trk ID p D0 Z0 Px Py Pz ntpc ndf Chi2/ndf nlinkedTracks" << std::endl; + streamlog_out(DEBUG5) + << " Trk ID p D0 Z0 Px Py Pz ntpc ndf Chi2/ndf nlinkedTracks" + << std::endl; // " 0 1.111 0.059 0.022 -0.54 0.61 -0.45 0.185 - - for (int iTrk=0; iTrk(col->getElementAt(iTrk) ); - + + for (int iTrk = 0; iTrk < nelem; ++iTrk) { + + Track* tpcTrack = dynamic_cast(col->getElementAt(iTrk)); + TrackerHitVec hitVec = tpcTrack->getTrackerHits(); int nHits = int(hitVec.size()); - - streamlog_out(DEBUG5) << FPCCDUtil::toString( iTrk, tpcTrack , _bField ) << std::endl; - - TrackExtended * trackExt = new TrackExtended( tpcTrack ); - + + streamlog_out(DEBUG5) << FPCCDUtil::toString(iTrk, tpcTrack, _bField) << std::endl; + + TrackExtended* trackExt = new TrackExtended(tpcTrack); + trackExt->setOmega(tpcTrack->getOmega()); trackExt->setTanLambda(tpcTrack->getTanLambda()); trackExt->setPhi(tpcTrack->getPhi()); @@ -1631,63 +1387,58 @@ void FPCCDFullLDCTracking_MarlinTrk::prepareVectors(LCEvent * event ) { // param[2] = tpcTrack->getPhi(); // param[3] = tpcTrack->getD0(); // param[4] = tpcTrack->getZ0(); - - + const FloatVec Cov = tpcTrack->getCovMatrix(); int NC = int(Cov.size()); - for (int ic=0;icsetCovMatrix(cov); trackExt->setNDF(tpcTrack->getNdf()); - trackExt->setChi2(tpcTrack->getChi2()); - - - - for (int iHit=0;iHitsetTrackExtended( trackExt ); - trackExt->addTrackerHitExtended( hitExt ); - } - - - - _allTPCTracks.push_back( trackExt ); - } - } - catch ( DataNotAvailableException &e) { + trackExt->setChi2(tpcTrack->getChi2()); + + for (int iHit = 0; iHit < nHits; ++iHit) { + TrackerHit* hit = hitVec[iHit]; + TrackerHitExtended* hitExt = mapTrackerHits[hit]; + hitExt->setTrackExtended(trackExt); + trackExt->addTrackerHitExtended(hitExt); + } + + _allTPCTracks.push_back(trackExt); + } + } catch (DataNotAvailableException& e) { streamlog_out(DEBUG5) << _TPCTrackCollection.c_str() << " collection is unavailable" << std::endl; } - + // Reading Si Tracks try { - LCCollection * col = event->getCollection(_SiTrackCollection.c_str()); + LCCollection* col = event->getCollection(_SiTrackCollection.c_str()); int nelem = col->getNumberOfElements(); streamlog_out(DEBUG5) << std::endl; streamlog_out(DEBUG5) << "Number of Si Tracks = " << nelem << std::endl; - streamlog_out(DEBUG5) << " Trk ID p D0 Z0 Px Py Pz hitsSi ndf Chi2/ndf" << std::endl; - - for (int iTrk=0; iTrk(col->getElementAt(iTrk)); - - double prob = ( siTrack->getNdf() > 0 ? gsl_cdf_chisq_Q( siTrack->getChi2() , (double) siTrack->getNdf() ) : 0. ) ; - if(_useMaxChi2ReqForSiTrk){ - if( siTrack->getChi2()/double(siTrack->getNdf()) > _maxChi2ForSiliconTracks){ - streamlog_out(DEBUG5) << "Si Tracks " << siTrack << " id : " << siTrack->id() << " rejected with prob " << prob << " < " << _minChi2ProbForSiliconTracks << std::endl; - continue; + streamlog_out(DEBUG5) + << " Trk ID p D0 Z0 Px Py Pz hitsSi ndf Chi2/ndf" << std::endl; + + for (int iTrk = 0; iTrk < nelem; ++iTrk) { + Track* siTrack = dynamic_cast(col->getElementAt(iTrk)); + + double prob = (siTrack->getNdf() > 0 ? gsl_cdf_chisq_Q(siTrack->getChi2(), (double)siTrack->getNdf()) : 0.); + if (_useMaxChi2ReqForSiTrk) { + if (siTrack->getChi2() / double(siTrack->getNdf()) > _maxChi2ForSiliconTracks) { + streamlog_out(DEBUG5) << "Si Tracks " << siTrack << " id : " << siTrack->id() << " rejected with prob " + << prob << " < " << _minChi2ProbForSiliconTracks << std::endl; + continue; } - } - else{ - if( prob < _minChi2ProbForSiliconTracks ) { - streamlog_out(DEBUG5) << "Si Tracks " << siTrack << " id : " << siTrack->id() << " rejected with prob " << prob << " < " << _minChi2ProbForSiliconTracks << std::endl; + } else { + if (prob < _minChi2ProbForSiliconTracks) { + streamlog_out(DEBUG5) << "Si Tracks " << siTrack << " id : " << siTrack->id() << " rejected with prob " + << prob << " < " << _minChi2ProbForSiliconTracks << std::endl; continue; } } - - TrackExtended * trackExt = new TrackExtended( siTrack ); + + TrackExtended* trackExt = new TrackExtended(siTrack); TrackerHitVec hitVec = siTrack->getTrackerHits(); int nHits = int(hitVec.size()); trackExt->setOmega(siTrack->getOmega()); @@ -1702,503 +1453,503 @@ void FPCCDFullLDCTracking_MarlinTrk::prepareVectors(LCEvent * event ) { // param[2] = siTrack->getPhi(); // param[3] = siTrack->getD0(); // param[4] = siTrack->getZ0(); - - - + const FloatVec Cov = siTrack->getCovMatrix(); int NC = int(Cov.size()); - for (int ic=0;icsetCovMatrix(cov); trackExt->setNDF(siTrack->getNdf()); - trackExt->setChi2(siTrack->getChi2()); + trackExt->setChi2(siTrack->getChi2()); char strg[200]; HelixClass helixSi; - for (int iHit=0;iHitsetTrackExtended( trackExt ); - trackExt->addTrackerHitExtended( hitExt ); + for (int iHit = 0; iHit < nHits; ++iHit) { + TrackerHit* hit = hitVec[iHit]; + TrackerHitExtended* hitExt = mapTrackerHits[hit]; + hitExt->setTrackExtended(trackExt); + trackExt->addTrackerHitExtended(hitExt); } - - + float d0Si = trackExt->getD0(); float z0Si = trackExt->getZ0(); float omegaSi = trackExt->getOmega(); float phi0Si = trackExt->getPhi(); float tanLSi = trackExt->getTanLambda(); - helixSi.Initialize_Canonical(phi0Si,d0Si,z0Si,omegaSi,tanLSi,_bField); + helixSi.Initialize_Canonical(phi0Si, d0Si, z0Si, omegaSi, tanLSi, _bField); float pxSi = helixSi.getMomentum()[0]; float pySi = helixSi.getMomentum()[1]; float pzSi = helixSi.getMomentum()[2]; - const float pTot = sqrt(pxSi*pxSi+pySi*pySi+pzSi*pzSi); + const float pTot = sqrt(pxSi * pxSi + pySi * pySi + pzSi * pzSi); const int ndfSi = trackExt->getNDF(); - float Chi2Si = trackExt->getChi2()/float(trackExt->getNDF()); - sprintf(strg,"%3i %5i %9.3f %9.3f %9.3f %7.2f %7.2f %7.2f %4i %4i %8.3f",iTrk, siTrack->id(), - pTot, d0Si,z0Si,pxSi,pySi,pzSi,nHits, ndfSi, Chi2Si); + float Chi2Si = trackExt->getChi2() / float(trackExt->getNDF()); + sprintf(strg, "%3i %5i %9.3f %9.3f %9.3f %7.2f %7.2f %7.2f %4i %4i %8.3f", iTrk, siTrack->id(), pTot, d0Si, + z0Si, pxSi, pySi, pzSi, nHits, ndfSi, Chi2Si); streamlog_out(DEBUG5) << strg << std::endl; - if(_mydebug){ - purityMCP purimcp = _purityUtil->GetPurity(hitVec,_naviVecSi); - printf("Prob:%f, Purity:%f, Pt:%f \n",prob,purimcp.purity,sqrt(pxSi*pxSi+pySi*pySi)); + if (_mydebug) { + purityMCP purimcp = _purityUtil->GetPurity(hitVec, _naviVecSi); + printf("Prob:%f, Purity:%f, Pt:%f \n", prob, purimcp.purity, sqrt(pxSi * pxSi + pySi * pySi)); + } + + if (nHits > 0) { + _allSiTracks.push_back(trackExt); + } else { + delete trackExt; } - - if(nHits>0){ _allSiTracks.push_back( trackExt ); } - else{ delete trackExt; } } - + streamlog_out(DEBUG5) << std::endl; - } - catch ( DataNotAvailableException &e) { + } catch (DataNotAvailableException& e) { streamlog_out(DEBUG5) << _SiTrackCollection.c_str() << " collection is unavailable" << std::endl; } - - - } -void FPCCDFullLDCTracking_MarlinTrk::CleanUp(){ - - int nNonCombTpc = int(_allNonCombinedTPCTracks.size()); - for (int i=0;igetGroupTracks(); +void FPCCDFullLDCTracking_MarlinTrk::CleanUp() { + + int nNonCombTpc = int(_allNonCombinedTPCTracks.size()); + for (int i = 0; i < nNonCombTpc; ++i) { + TrackExtended* trkExt = _allNonCombinedTPCTracks[i]; + GroupTracks* group = trkExt->getGroupTracks(); delete group; } _allNonCombinedTPCTracks.clear(); - - int nNonCombSi = int(_allNonCombinedSiTracks.size()); - for (int i=0;igetGroupTracks(); + + int nNonCombSi = int(_allNonCombinedSiTracks.size()); + for (int i = 0; i < nNonCombSi; ++i) { + TrackExtended* trkExt = _allNonCombinedSiTracks[i]; + GroupTracks* group = trkExt->getGroupTracks(); delete group; } _allNonCombinedSiTracks.clear(); - + int nSITHits = int(_allSITHits.size()); - for (int i=0;igetGroupTracks(); + for (int i = 0; i < nCombTrk; ++i) { + TrackExtended* trkExt = _allCombinedTracks[i]; + GroupTracks* group = trkExt->getGroupTracks(); delete group; - delete trkExt; + delete trkExt; } _allCombinedTracks.clear(); - + // int nImplTrk = int(_trkImplVec.size()); // for (int i=0;igetTrack(), _bField ) << std::endl ; - streamlog_out(DEBUG2) << " to si trk " << FPCCDUtil::toString( iSi, siTrackExt->getTrack(), _bField ) << std::endl ; - - float dOmega = CompareTrkII(siTrackExt,tpcTrackExt,_d0CutForMerging,_z0CutForMerging,iComp,angle); - - if ( (dOmega<_dOmegaForMerging) && (angle<_angleForMerging) && !VetoMerge(tpcTrackExt,siTrackExt)) { - - streamlog_out(DEBUG2) << " call CombineTracks for tpc trk " << tpcTrackExt << " si trk " << siTrackExt << std::endl; - - TrackExtended *combinedTrack = CombineTracks(tpcTrackExt,siTrackExt,_maxAllowedPercentageOfOutliersForTrackCombination, false); - + streamlog_out(DEBUG2) << " compare tpc trk " << FPCCDUtil::toString(iTPC, tpcTrackExt->getTrack(), _bField) + << std::endl; + streamlog_out(DEBUG2) << " to si trk " << FPCCDUtil::toString(iSi, siTrackExt->getTrack(), _bField) + << std::endl; + + float dOmega = CompareTrkII(siTrackExt, tpcTrackExt, _d0CutForMerging, _z0CutForMerging, iComp, angle); + + if ((dOmega < _dOmegaForMerging) && (angle < _angleForMerging) && !VetoMerge(tpcTrackExt, siTrackExt)) { + + streamlog_out(DEBUG2) << " call CombineTracks for tpc trk " << tpcTrackExt << " si trk " << siTrackExt + << std::endl; + + TrackExtended* combinedTrack = + CombineTracks(tpcTrackExt, siTrackExt, _maxAllowedPercentageOfOutliersForTrackCombination, false); + streamlog_out(DEBUG2) << " combinedTrack returns " << combinedTrack << std::endl; - - if (combinedTrack != NULL) { + if (combinedTrack != NULL) { - _allCombinedTracks.push_back( combinedTrack ); + _allCombinedTracks.push_back(combinedTrack); _candidateCombinedTracks.insert(tpcTrackExt); _candidateCombinedTracks.insert(siTrackExt); - // streamlog_out(DEBUG3) << " combinedTrack successfully added to _allCombinedTracks : " << FPCCDUtil::toString( 0,combinedTrack->getTrack(), _bField ) << std::endl; - streamlog_out(DEBUG3) << " *** combinedTrack successfully added to _allCombinedTracks : tpc " << iTPC << " si " << iSi << std::endl; - - if (_debug >= 3 ) { + // streamlog_out(DEBUG3) << " combinedTrack successfully added to _allCombinedTracks : " << + // FPCCDUtil::toString( 0,combinedTrack->getTrack(), _bField ) << std::endl; + streamlog_out(DEBUG3) << " *** combinedTrack successfully added to _allCombinedTracks : tpc " << iTPC + << " si " << iSi << std::endl; + + if (_debug >= 3) { int iopt = 1; - PrintOutMerging(tpcTrackExt,siTrackExt,iopt); + PrintOutMerging(tpcTrackExt, siTrackExt, iopt); } - }else{ - if (_debug >= 3 ) { + } else { + if (_debug >= 3) { int iopt = 6; - PrintOutMerging(tpcTrackExt,siTrackExt,iopt); + PrintOutMerging(tpcTrackExt, siTrackExt, iopt); } } - } - else { - if (_debug >= 3 ) { + } else { + if (_debug >= 3) { int iopt = 6; - PrintOutMerging(tpcTrackExt,siTrackExt,iopt); + PrintOutMerging(tpcTrackExt, siTrackExt, iopt); } } } } - - } - /* - + All Si and TPC tracks which have been merged using MergeTPCandSiTracks are excluded from this search. - - The remaining TPC tracks and Silicon tracks will be tested using CompareTrkIII - CompareTrkIII does the following - + The remaining TPC tracks and Silicon tracks will be tested using CompareTrkIII + + CompareTrkIII does the following + i) significance d0 < d0Cut ii) significance z0 < z0Cut iii) pdot > 0.999 - + if above three cuts are passed return: - + the significance dAngle (return by reference) and the significance dOmega - if CompareTrkIII and the cuts on the significance of dOmega and angle succecede try and full fit of the hits using CombineTracks - assuming that the merger was not vetoed VetoMerge - i.e. if the momentum of either track is less than 2.5 GeV - and there is no overlapping of the segments - - if this is successful the track is added to _allCombinedTracks and the TPC and Si Segements are added to _candidateCombinedTracks - + if CompareTrkIII and the cuts on the significance of dOmega and angle succecede try and full fit of the hits using + CombineTracks assuming that the merger was not vetoed VetoMerge i.e. if the momentum of either track is less than 2.5 + GeV and there is no overlapping of the segments + + if this is successful the track is added to _allCombinedTracks and the TPC and Si Segements are added to + _candidateCombinedTracks + */ void FPCCDFullLDCTracking_MarlinTrk::MergeTPCandSiTracksII() { - + int nTPCTracks = int(_allTPCTracks.size()); - int nSiTracks = int(_allSiTracks.size()); - - streamlog_out( DEBUG3 ) << " MergeTPCandSiTracksII called nTPC tracks " << nTPCTracks << " - nSiTracks " << nSiTracks << std::endl ; + int nSiTracks = int(_allSiTracks.size()); + + streamlog_out(DEBUG3) << " MergeTPCandSiTracksII called nTPC tracks " << nTPCTracks << " - nSiTracks " << nSiTracks + << std::endl; + + for (int iTPC = 0; iTPC < nTPCTracks; ++iTPC) { - for (int iTPC=0;iTPC= 3 ) { + streamlog_out(DEBUG2) << " combinedTrack returns " << combinedTrack << std::endl; + + if (combinedTrack != NULL) { + + _allCombinedTracks.push_back(combinedTrack); + streamlog_out(DEBUG3) << " *** combinedTrack successfully added to _allCombinedTracks : tpc " << iTPC + << " si " << iSi << std::endl; + + if (_debug >= 3) { int iopt = 1; - PrintOutMerging(tpcTrackExt,siTrackExt,iopt); + PrintOutMerging(tpcTrackExt, siTrackExt, iopt); } - }else{ - if (_debug >= 3 ) { + } else { + if (_debug >= 3) { int iopt = 6; - PrintOutMerging(tpcTrackExt,siTrackExt,iopt); + PrintOutMerging(tpcTrackExt, siTrackExt, iopt); } } - } - else { - if (_debug >= 3 ) { + } else { + if (_debug >= 3) { int iopt = 6; - PrintOutMerging(tpcTrackExt,siTrackExt,iopt); + PrintOutMerging(tpcTrackExt, siTrackExt, iopt); } } } } } +// if testCombinationOnly is true then hits will not be assigned to the tracks +TrackExtended* FPCCDFullLDCTracking_MarlinTrk::CombineTracks(TrackExtended* tpcTrack, TrackExtended* siTrack, + float maxAllowedOutliers, bool testCombinationOnly) { + + TrackExtended* OutputTrack = NULL; -// if testCombinationOnly is true then hits will not be assigned to the tracks -TrackExtended * FPCCDFullLDCTracking_MarlinTrk::CombineTracks(TrackExtended * tpcTrack, TrackExtended * siTrack, float maxAllowedOutliers, bool testCombinationOnly) { - - TrackExtended * OutputTrack = NULL; - TrackerHitExtendedVec siHitVec = siTrack->getTrackerHitExtendedVec(); TrackerHitExtendedVec tpcHitVec = tpcTrack->getTrackerHitExtendedVec(); - + int nSiHits = int(siHitVec.size()); int nTPCHits = int(tpcHitVec.size()); int nHits = nTPCHits + nSiHits; - - //std::cout << "FPCCDFullLDCTracking_MarlinTrk::CombineTracks nSiHits = " << nSiHits << std::endl; - //std::cout << "FPCCDFullLDCTracking_MarlinTrk::CombineTracks nTPCHits = " << nTPCHits << std::endl; - + + // std::cout << "FPCCDFullLDCTracking_MarlinTrk::CombineTracks nSiHits = " << nSiHits << std::endl; + // std::cout << "FPCCDFullLDCTracking_MarlinTrk::CombineTracks nTPCHits = " << nTPCHits << std::endl; + EVENT::TrackerHitVec trkHits; trkHits.reserve(nHits); - - for (int ih=0;ihgetTrackerHit(); - if(trkHit) { - trkHits.push_back(trkHit); - } - else{ - throw EVENT::Exception( std::string("FPCCDFullLDCTracking_MarlinTrk::CombineTracks: TrackerHit pointer == NULL ") ) ; - } - } - - for (int ih=0;ihgetTrackerHit(); - if(trkHit) { - trkHits.push_back(trkHit); + + for (int ih = 0; ih < nSiHits; ++ih) { + TrackerHit* trkHit = siHitVec[ih]->getTrackerHit(); + if (trkHit) { + trkHits.push_back(trkHit); + } else { + throw EVENT::Exception(std::string("FPCCDFullLDCTracking_MarlinTrk::CombineTracks: TrackerHit pointer == NULL ")); } - else{ - throw EVENT::Exception( std::string("FPCCDFullLDCTracking_MarlinTrk::CombineTracks: TrackerHit pointer == NULL ") ) ; + } + + for (int ih = 0; ih < nTPCHits; ++ih) { + + TrackerHit* trkHit = tpcHitVec[ih]->getTrackerHit(); + if (trkHit) { + trkHits.push_back(trkHit); + } else { + throw EVENT::Exception(std::string("FPCCDFullLDCTracking_MarlinTrk::CombineTracks: TrackerHit pointer == NULL ")); } - } - + } + double chi2_D; int ndf; - - if( trkHits.size() < 3 ) { - - return 0 ; - + + if (trkHits.size() < 3) { + + return 0; } - - streamlog_out(DEBUG2) << "FPCCDFullLDCTracking_MarlinTrk::CombineTracks: Sorting Hits " << trkHits.size() << std::endl; - - std::vector< std::pair > r2_values; + + streamlog_out(DEBUG2) << "FPCCDFullLDCTracking_MarlinTrk::CombineTracks: Sorting Hits " << trkHits.size() + << std::endl; + + std::vector> r2_values; r2_values.reserve(trkHits.size()); - - for (TrackerHitVec::iterator it=trkHits.begin(); it!=trkHits.end(); ++it) { + + for (TrackerHitVec::iterator it = trkHits.begin(); it != trkHits.end(); ++it) { EVENT::TrackerHit* h = *it; - float r2 = h->getPosition()[0]*h->getPosition()[0]+h->getPosition()[1]*h->getPosition()[1]; + float r2 = h->getPosition()[0] * h->getPosition()[0] + h->getPosition()[1] * h->getPosition()[1]; r2_values.push_back(std::make_pair(r2, *it)); } - - sort(r2_values.begin(),r2_values.end()); - + + sort(r2_values.begin(), r2_values.end()); + trkHits.clear(); trkHits.reserve(r2_values.size()); - - for (std::vector< std::pair >::iterator it=r2_values.begin(); it!=r2_values.end(); ++it) { + + for (std::vector>::iterator it = r2_values.begin(); it != r2_values.end(); + ++it) { trkHits.push_back(it->second); } - - streamlog_out(DEBUG2) << "FPCCDFullLDCTracking_MarlinTrk::CombineTracks: Start Fitting: AddHits: number of hits to fit " << trkHits.size() << std::endl; - + streamlog_out(DEBUG2) + << "FPCCDFullLDCTracking_MarlinTrk::CombineTracks: Start Fitting: AddHits: number of hits to fit " + << trkHits.size() << std::endl; + std::unique_ptr marlin_trk_autop(_trksystem->createTrack()); MarlinTrk::IMarlinTrack& marlin_trk = *marlin_trk_autop.get(); - - IMPL::TrackStateImpl pre_fit ; + + IMPL::TrackStateImpl pre_fit; int error = IMarlinTrack::success; - + pre_fit = *(tpcTrack->getTrack()->getTrackState(EVENT::TrackState::AtLastHit)); - - + // setup initial dummy covariance matrix EVENT::FloatVec covMatrix; covMatrix.resize(15); - - for (unsigned icov = 0; icov _chi2FitCut ) { - - streamlog_out(DEBUG2) << "FPCCDFullLDCTracking_MarlinTrk::CombineTracks: track fail Chi2 cut of " << _chi2FitCut << " chi2 of track = " << chi2Fit << std::endl; + + float chi2Fit = chi2_D / float(ndf); + + if (chi2Fit > _chi2FitCut) { + + streamlog_out(DEBUG2) << "FPCCDFullLDCTracking_MarlinTrk::CombineTracks: track fail Chi2 cut of " << _chi2FitCut + << " chi2 of track = " << chi2Fit << std::endl; return 0; - } - - + streamlog_out(DEBUG2) << "FPCCDFullLDCTracking_MarlinTrk::CombineTracks: Check for outliers " << std::endl; - - std::vector > outliers ; + + std::vector> outliers; marlin_trk.getOutliers(outliers); - - float outlier_pct = outliers.size()/float(trkHits.size()) ; - - - if ( outlier_pct > maxAllowedOutliers) { - - streamlog_out(DEBUG2) << "FPCCDFullLDCTracking_MarlinTrk::CombineTracks: percentage of outliers " << outlier_pct << " is greater than cut maximum: " << maxAllowedOutliers << std::endl; - return 0; + float outlier_pct = outliers.size() / float(trkHits.size()); + + if (outlier_pct > maxAllowedOutliers) { + + streamlog_out(DEBUG2) << "FPCCDFullLDCTracking_MarlinTrk::CombineTracks: percentage of outliers " << outlier_pct + << " is greater than cut maximum: " << maxAllowedOutliers << std::endl; + return 0; } - // sort the hits into outliers from TPC and Silicon as we will reject the combination if more that 2 Si hits get rejected ... - + // sort the hits into outliers from TPC and Silicon as we will reject the combination if more that 2 Si hits get + // rejected ... + std::vector siHitInFit; std::vector siOutliers; std::vector tpcHitInFit; std::vector tpcOutliers; - - for (int i=0;igetTrackerHit()); - + // add the raw hits ... const LCObjectVec rawHits = siHitVec[i]->getTrackerHit()->getRawHits(); - - if ( rawHits.empty() == false) { - for (unsigned ihit=0; ihit < rawHits.size(); ++ihit) { + + if (rawHits.empty() == false) { + for (unsigned ihit = 0; ihit < rawHits.size(); ++ihit) { hits.push_back(rawHits[ihit]); } } - + // now double loop over the outliers and the hits assosiated with this TrackerHitExtended and compare - for ( unsigned ohit = 0; ohit < outliers.size(); ++ohit) { + for (unsigned ohit = 0; ohit < outliers.size(); ++ohit) { for (unsigned ihit = 0; ihit < hits.size(); ++ihit) { - + // compare outlier pointer to TrackerHit pointer - if( outliers[ohit].first == hits[ihit] ){ + if (outliers[ohit].first == hits[ihit]) { // silicon outlier found so add the TrackerHitExtended to the list of outliers hit_is_outlier = true; siOutliers.push_back(siHitVec[i]); @@ -2209,62 +1960,60 @@ TrackExtended * FPCCDFullLDCTracking_MarlinTrk::CombineTracks(TrackExtended * tp } } } - - if( hit_is_outlier == false ){ + + if (hit_is_outlier == false) { // add the TrackerHitExtended to the list of silicon hits used in the fit siHitInFit.push_back(siHitVec[i]); } - } - + // more simple as TPC hits are never composite - for (int i=0;igetTrackerHit() ){ + if (outliers[ihit].first == tpcHitVec[i]->getTrackerHit()) { // tpc outlier found so add the TrackerHitExtended to the list of outliers hit_is_outlier = true; tpcOutliers.push_back(tpcHitVec[i]); break; } } - - if( hit_is_outlier == false ){ + + if (hit_is_outlier == false) { // add the TrackerHitExtended to the list of tpc hits used in the fit tpcHitInFit.push_back(tpcHitVec[i]); } - } - - streamlog_out(DEBUG2) << "FPCCDFullLDCTracking_MarlinTrk::CombineTracks: Check for Silicon Hit rejections ... " << std::endl; - - if ( (int)siOutliers.size() > _maxAllowedSiHitRejectionsForTrackCombination ) { - - streamlog_out(DEBUG2) << "FPCCDFullLDCTracking_MarlinTrk::CombineTracks: Fit rejects " << siOutliers.size() << " silicon hits : max allowed rejections = " << _maxAllowedSiHitRejectionsForTrackCombination << " : Combination rejected " << std::endl; + streamlog_out(DEBUG2) << "FPCCDFullLDCTracking_MarlinTrk::CombineTracks: Check for Silicon Hit rejections ... " + << std::endl; + + if ((int)siOutliers.size() > _maxAllowedSiHitRejectionsForTrackCombination) { + + streamlog_out(DEBUG2) << "FPCCDFullLDCTracking_MarlinTrk::CombineTracks: Fit rejects " << siOutliers.size() + << " silicon hits : max allowed rejections = " + << _maxAllowedSiHitRejectionsForTrackCombination << " : Combination rejected " << std::endl; return 0; - } - float omega = trkState.getOmega(); float tanlambda = trkState.getTanLambda(); float phi0 = trkState.getPhi(); float d0 = trkState.getD0(); float z0 = trkState.getZ0(); - + OutputTrack = new TrackExtended(); - GroupTracks * group = new GroupTracks(); + GroupTracks* group = new GroupTracks(); OutputTrack->setGroupTracks(group); - + group->addTrackExtended(siTrack); group->addTrackExtended(tpcTrack); - + // note OutputTrack which is of type TrackExtended, only takes fits set for ref point = 0,0,0 OutputTrack->setOmega(omega); OutputTrack->setTanLambda(tanlambda); @@ -2273,141 +2022,136 @@ TrackExtended * FPCCDFullLDCTracking_MarlinTrk::CombineTracks(TrackExtended * tp OutputTrack->setD0(d0); OutputTrack->setChi2(chi2_D); OutputTrack->setNDF(ndf); - + float cov[15]; - - for (int i = 0 ; i<15 ; ++i) { + + for (int i = 0; i < 15; ++i) { cov[i] = trkState.getCovMatrix().operator[](i); } - + OutputTrack->setCovMatrix(cov); - + // if this is not just a test of the combination add the hits to the combined track - if ( testCombinationOnly == false ) { + if (testCombinationOnly == false) { - for (unsigned ihit=0; ihitaddTrackerHitExtended(hitExt); hitExt->setUsedInFit(true); } - - for (unsigned ihit=0; ihitaddTrackerHitExtended(hitExt); hitExt->setUsedInFit(false); } - for (unsigned ihit=0; ihitaddTrackerHitExtended(hitExt); hitExt->setUsedInFit(true); } - - for (unsigned ihit=0; ihitaddTrackerHitExtended(hitExt); hitExt->setUsedInFit(false); } - } - - - streamlog_out(DEBUG2) << "FPCCDFullLDCTracking_MarlinTrk::CombineTracks: merged track created " << OutputTrack << " with " << OutputTrack->getTrackerHitExtendedVec().size() << " hits, nhits tpc " << nTPCHits << " nSiHits " << nSiHits << ", testCombinationOnly = " << testCombinationOnly << std::endl; - + + streamlog_out(DEBUG2) << "FPCCDFullLDCTracking_MarlinTrk::CombineTracks: merged track created " << OutputTrack + << " with " << OutputTrack->getTrackerHitExtendedVec().size() << " hits, nhits tpc " << nTPCHits + << " nSiHits " << nSiHits << ", testCombinationOnly = " << testCombinationOnly << std::endl; + return OutputTrack; - } +void FPCCDFullLDCTracking_MarlinTrk::SortingTrackHitPairs(TrackHitPairVec& trackHitPairVec) { - -void FPCCDFullLDCTracking_MarlinTrk::SortingTrackHitPairs(TrackHitPairVec & trackHitPairVec) { - int sizeOfVector = int(trackHitPairVec.size()); - TrackHitPair *one,*two,*Temp; - - for (int i = 0 ; i < sizeOfVector-1; i++) - for (int j = 0; j < sizeOfVector-i-1; j++) { + TrackHitPair *one, *two, *Temp; + + for (int i = 0; i < sizeOfVector - 1; i++) + for (int j = 0; j < sizeOfVector - i - 1; j++) { one = trackHitPairVec[j]; - two = trackHitPairVec[j+1]; + two = trackHitPairVec[j + 1]; float oneQ = one->getDistance(); float twoQ = two->getDistance(); - if( oneQ > twoQ ) { + if (oneQ > twoQ) { Temp = trackHitPairVec[j]; - trackHitPairVec[j] = trackHitPairVec[j+1]; - trackHitPairVec[j+1] = Temp; + trackHitPairVec[j] = trackHitPairVec[j + 1]; + trackHitPairVec[j + 1] = Temp; } - } - - + } } /* - + Sorts all tracks in the vector by Chi2/NDF - + */ -void FPCCDFullLDCTracking_MarlinTrk::Sorting(TrackExtendedVec & trackVec) { - +void FPCCDFullLDCTracking_MarlinTrk::Sorting(TrackExtendedVec& trackVec) { + int sizeOfVector = int(trackVec.size()); - TrackExtended *one,*two,*Temp; - - for (int i = 0 ; i < sizeOfVector-1; i++) - for (int j = 0; j < sizeOfVector-i-1; j++) { + TrackExtended *one, *two, *Temp; + + for (int i = 0; i < sizeOfVector - 1; i++) + for (int j = 0; j < sizeOfVector - i - 1; j++) { one = trackVec[j]; - two = trackVec[j+1]; - float oneQ = one->getChi2()/float(one->getNDF()); - float twoQ = two->getChi2()/float(two->getNDF()); - if( oneQ > twoQ ) { + two = trackVec[j + 1]; + float oneQ = one->getChi2() / float(one->getNDF()); + float twoQ = two->getChi2() / float(two->getNDF()); + if (oneQ > twoQ) { Temp = trackVec[j]; - trackVec[j] = trackVec[j+1]; - trackVec[j+1] = Temp; + trackVec[j] = trackVec[j + 1]; + trackVec[j + 1] = Temp; } - } + } } /* - - this function is used to select only the combined tracks which have been formed from excatly 2 sub tracks which themselves are not formed from any other tracks. - + + this function is used to select only the combined tracks which have been formed from excatly 2 sub tracks which + themselves are not formed from any other tracks. + */ void FPCCDFullLDCTracking_MarlinTrk::SelectCombinedTracks() { - + int nCombTrk = int(_allCombinedTracks.size()); - - streamlog_out(DEBUG3) << " **SelectCombinedTracks - check " << nCombTrk << " comb. tracks " << std::endl ; + + streamlog_out(DEBUG3) << " **SelectCombinedTracks - check " << nCombTrk << " comb. tracks " << std::endl; // loop over all combined tracks ... - for (int i=0; igetGroupTracks(); + GroupTracks* group = trkExt->getGroupTracks(); TrackExtendedVec tracks = group->getTrackExtendedVec(); // check that there are only 2 sub tracks, as we are after Si <-> TPC mergers only int nTracks = int(tracks.size()); - streamlog_out(DEBUG1) << " **SelectCombinedTracks - nTracks = " << nTracks << std::endl ; - + streamlog_out(DEBUG1) << " **SelectCombinedTracks - nTracks = " << nTracks << std::endl; + if (nTracks == 2) { - - TrackExtended * firstTrack = tracks[0]; - TrackExtended * secondTrack = tracks[1]; + + TrackExtended* firstTrack = tracks[0]; + TrackExtended* secondTrack = tracks[1]; // check that the two sub tracks in question are not themselves a merger of tracks - if ((firstTrack->getGroupTracks() == NULL) && - (secondTrack->getGroupTracks() == NULL) ) { + if ((firstTrack->getGroupTracks() == NULL) && (secondTrack->getGroupTracks() == NULL)) { - streamlog_out(DEBUG1) << " **SelectCombinedTracks - firstTrack->getGroupTracks() == NULL ... " << std::endl ; + streamlog_out(DEBUG1) << " **SelectCombinedTracks - firstTrack->getGroupTracks() == NULL ... " << std::endl; - // associate the current group to the two sub tracks + // associate the current group to the two sub tracks firstTrack->setGroupTracks(group); - secondTrack->setGroupTracks(group); + secondTrack->setGroupTracks(group); // get the tracker hits ... TrackerHitExtendedVec firstVec = firstTrack->getTrackerHitExtendedVec(); @@ -2423,24 +2167,24 @@ void FPCCDFullLDCTracking_MarlinTrk::SelectCombinedTracks() { edges[1] = -1.0e+20; // get min and max z for the first sub track - for (int iF=0;iFgetTrackerHit(); + for (int iF = 0; iF < nFirst; ++iF) { + TrackerHitExtended* trkHitExt = firstVec[iF]; + TrackerHit* trkHit = trkHitExt->getTrackerHit(); float zpos = float(trkHit->getPosition()[2]); - if (zpos>edges[1]) + if (zpos > edges[1]) edges[1] = zpos; - if (zposgetTrackerHit(); + for (int iS = 0; iS < nSecond; ++iS) { + TrackerHitExtended* trkHitExt = secondVec[iS]; + TrackerHit* trkHit = trkHitExt->getTrackerHit(); float zpos = float(trkHit->getPosition()[2]); - if (zpos>edges[1]) + if (zpos > edges[1]) edges[1] = zpos; - if (zpos= 2) { int iopt = 1; - + // here it is assumed that the tpc tracks is the secondTrack ... - PrintOutMerging(secondTrack,firstTrack,iopt); - } + PrintOutMerging(secondTrack, firstTrack, iopt); + } } - } else { // if(nTracks>2) + } else { // if(nTracks>2) - streamlog_out(DEBUG2) << " ***************** SelectCombinedTracks: MORE THAN TWO TRACKS " << nCombTrk << std::endl; + streamlog_out(DEBUG2) << " ***************** SelectCombinedTracks: MORE THAN TWO TRACKS " << nCombTrk + << std::endl; } } - - } -void FPCCDFullLDCTracking_MarlinTrk::AddNotCombinedTracks() { - +void FPCCDFullLDCTracking_MarlinTrk::AddNotCombinedTracks() { + int nTPCTrk = int(_allTPCTracks.size()); int nSiTrk = int(_allSiTracks.size()); - + // we need some buffer vector TrackExtendedVec allMergedTracks; allMergedTracks.clear(); - + // forcing merging of Si and TPC track segments - if (_forceMerging==1) { + if (_forceMerging == 1) { // loop over all TPC tracks - for (int i=0;igetGroupTracks(); + TrackExtended* trkExtTPC = _allTPCTracks[i]; + GroupTracks* groupTPC = trkExtTPC->getGroupTracks(); // if no tracks have been grouped with this TPC track if (groupTPC == NULL) { float diffMin = 1.0e+20; - TrackExtended * siTrkToAttach = NULL; + TrackExtended* siTrkToAttach = NULL; // loop over all Silicon Tracks - for (int j=0;jgetGroupTracks(); + for (int j = 0; j < nSiTrk; ++j) { + TrackExtended* trkExtSi = _allSiTracks[j]; + GroupTracks* groupSi = trkExtSi->getGroupTracks(); // only consider ungrouped Silicon Tracks if (groupSi == NULL) { @@ -2506,49 +2248,50 @@ void FPCCDFullLDCTracking_MarlinTrk::AddNotCombinedTracks() { // float deltaP = CompareTrk(trkExtSi,trkExtTPC,_d0CutForForcedMerging,_z0CutForForcedMerging,iComp); float angle(0.); float angleSignificance(0.); - + // try to merge tracks using looser cuts - float dOmega = CompareTrkII(trkExtSi,trkExtTPC,_d0CutForForcedMerging,_z0CutForForcedMerging,iComp,angle); + float dOmega = + CompareTrkII(trkExtSi, trkExtTPC, _d0CutForForcedMerging, _z0CutForForcedMerging, iComp, angle); - float significance = CompareTrkIII(trkExtSi,trkExtTPC,_d0CutForForcedMerging,_z0CutForForcedMerging,iComp,angleSignificance); + float significance = CompareTrkIII(trkExtSi, trkExtTPC, _d0CutForForcedMerging, _z0CutForForcedMerging, + iComp, angleSignificance); // if (deltaP < _dPCutForForcedMerging) { - if ( ((dOmega<_dOmegaForForcedMerging) && (angle<_angleForForcedMerging)) || - ((significance<5) && (angleSignificance<5)) - ) { + if (((dOmega < _dOmegaForForcedMerging) && (angle < _angleForForcedMerging)) || + ((significance < 5) && (angleSignificance < 5))) { - float chi2O = dOmega/_dOmegaForForcedMerging; - float chi2A = angle/_angleForForcedMerging; - float deltaP = chi2O*chi2O + chi2A*chi2A; + float chi2O = dOmega / _dOmegaForForcedMerging; + float chi2A = angle / _angleForForcedMerging; + float deltaP = chi2O * chi2O + chi2A * chi2A; - // if this is the best match (diffMin) set the possible merger - if (deltaP= 3) { - int iopt = 7; + int iopt = 7; streamlog_out(DEBUG2) << significance << " " << angleSignificance << std::endl; - PrintOutMerging(trkExtTPC,trkExtSi,iopt); + PrintOutMerging(trkExtTPC, trkExtSi, iopt); } } } } - - if (siTrkToAttach!=NULL) { - TrackExtended * trkExtSi = siTrkToAttach; - TrackExtended * OutputTrack = new TrackExtended(); - GroupTracks * group = new GroupTracks(); + if (siTrkToAttach != NULL) { + + TrackExtended* trkExtSi = siTrkToAttach; + TrackExtended* OutputTrack = new TrackExtended(); + GroupTracks* group = new GroupTracks(); group->addTrackExtended(trkExtSi); group->addTrackExtended(trkExtTPC); OutputTrack->setGroupTracks(group); // trkExtSi->setGroupTracks(group); - // trkExtTPC->setGroupTracks(group); + // trkExtTPC->setGroupTracks(group); OutputTrack->setOmega(trkExtTPC->getOmega()); OutputTrack->setTanLambda(trkExtSi->getTanLambda()); @@ -2559,51 +2302,51 @@ void FPCCDFullLDCTracking_MarlinTrk::AddNotCombinedTracks() { float covMatTPC[15]; float covMatSi[15]; float covMat[15]; - for (int iCov=0;iCov<15;++iCov) { + for (int iCov = 0; iCov < 15; ++iCov) { covMatTPC[iCov] = trkExtTPC->getCovMatrix()[iCov]; - covMatSi[iCov] = trkExtSi->getCovMatrix()[iCov]; + covMatSi[iCov] = trkExtSi->getCovMatrix()[iCov]; covMat[iCov] = covMatSi[iCov]; } - float scaling = sqrt(covMatTPC[5]/covMatSi[5]); - covMat[5] = covMatTPC[5]; - covMat[3] = scaling*covMatSi[3]; - covMat[4] = scaling*covMatSi[4]; - covMat[8] = scaling*covMatSi[8]; - covMat[12] = scaling*covMatSi[12]; + float scaling = sqrt(covMatTPC[5] / covMatSi[5]); + covMat[5] = covMatTPC[5]; + covMat[3] = scaling * covMatSi[3]; + covMat[4] = scaling * covMatSi[4]; + covMat[8] = scaling * covMatSi[8]; + covMat[12] = scaling * covMatSi[12]; OutputTrack->setCovMatrix(covMat); TrackerHitExtendedVec tpcHitVec = trkExtTPC->getTrackerHitExtendedVec(); - TrackerHitExtendedVec siHitVec = trkExtSi->getTrackerHitExtendedVec(); + TrackerHitExtendedVec siHitVec = trkExtSi->getTrackerHitExtendedVec(); - int nTPCHits = int( tpcHitVec.size()); - int nSiHits = int( siHitVec.size()); + int nTPCHits = int(tpcHitVec.size()); + int nSiHits = int(siHitVec.size()); float edges[2]; edges[0] = 1.0e+20; edges[1] = -1.0e+20; // find the max and min z extents from hits - for (int iH=0;iHaddTrackerHitExtended(hitExt); hitExt->setUsedInFit(true); - TrackerHit * hit = hitExt->getTrackerHit(); + TrackerHit* hit = hitExt->getTrackerHit(); float zpos = float(hit->getPosition()[2]); - if (zposedges[1]) + if (zpos > edges[1]) edges[1] = zpos; - } - for (int iH=0;iHaddTrackerHitExtended(hitExt); - hitExt->setUsedInFit(true); - TrackerHit * hit = hitExt->getTrackerHit(); + hitExt->setUsedInFit(true); + TrackerHit* hit = hitExt->getTrackerHit(); float zpos = float(hit->getPosition()[2]); - if (zposedges[1]) + if (zpos > edges[1]) edges[1] = zpos; } @@ -2611,20 +2354,18 @@ void FPCCDFullLDCTracking_MarlinTrk::AddNotCombinedTracks() { OutputTrack->setChi2(diffMin); // will be replaced if necessary OutputTrack->setNDF(int(1)); // will be replaced if necessary - _allCombinedTracks.push_back( OutputTrack ); - allMergedTracks.push_back( OutputTrack ); - + _allCombinedTracks.push_back(OutputTrack); + allMergedTracks.push_back(OutputTrack); } } - + } // end of loop over TPC tracks - - + // check that there are some merged tracks to process int nMerged = int(allMergedTracks.size()); - if (nMerged>0) { - + if (nMerged > 0) { + // sort all merged tracks by Chi2/NDF // although due to the fact that NDF for these tracks is set to the value 1 above, // it is really only a sort on Chi2 which was really the weighted difference in angle and omega @@ -2632,60 +2373,57 @@ void FPCCDFullLDCTracking_MarlinTrk::AddNotCombinedTracks() { Sorting(allMergedTracks); // loop over all merged tracks - for (int iM=0;iMgetGroupTracks(); - - TrackExtended * mergedTrack = allMergedTracks[iM]; - GroupTracks * grpTrk = mergedTrack->getGroupTracks(); - TrackExtendedVec trkVec = grpTrk->getTrackExtendedVec(); - TrackExtended * trkTPC = NULL; - TrackExtended * trkSi = NULL; + TrackExtended* trkTPC = NULL; + TrackExtended* trkSi = NULL; int nT = int(trkVec.size()); // only consider tracks which have been composed of excactly 2 sub tracks - if (nT==2) { + if (nT == 2) { trkTPC = trkVec[0]; trkSi = trkVec[1]; - GroupTracks * groupTPC = trkTPC->getGroupTracks(); - GroupTracks * groupSi = trkSi->getGroupTracks(); + GroupTracks* groupTPC = trkTPC->getGroupTracks(); + GroupTracks* groupSi = trkSi->getGroupTracks(); // check that both the TPC and SI track have not already been combined with other tracks ... if (groupTPC == NULL && groupSi == NULL) { // set the grouping, meaning that these tracks will not be considered further - trkTPC->setGroupTracks( grpTrk ); - trkSi->setGroupTracks( grpTrk ); + trkTPC->setGroupTracks(grpTrk); + trkSi->setGroupTracks(grpTrk); TrackerHitExtendedVec hitVec = mergedTrack->getTrackerHitExtendedVec(); - + int nhits = int(hitVec.size()); - int totNdf = 2*nhits - 5; + int totNdf = 2 * nhits - 5; float totChi2 = trkTPC->getChi2() + trkSi->getChi2(); - mergedTrack->setNDF( totNdf ); - mergedTrack->setChi2( totChi2 ); + mergedTrack->setNDF(totNdf); + mergedTrack->setChi2(totChi2); if (_debug >= 2) { int iopt = 2; - PrintOutMerging(trkTPC,trkSi,iopt); + PrintOutMerging(trkTPC, trkSi, iopt); } - _trkImplVec.push_back( mergedTrack ); + _trkImplVec.push_back(mergedTrack); } } } } } // end of _forceMerging - - - + // clear buffer vector allMergedTracks.clear(); - + // merging split up TPC segments if (_mergeTPCSegments) { @@ -2695,13 +2433,14 @@ void FPCCDFullLDCTracking_MarlinTrk::AddNotCombinedTracks() { int nNonAssignedTPCSeg = 0; // loop over all TPC Tracks - for (int i=0;igetGroupTracks(); + TrackExtended* trkExt = _allTPCTracks[i]; + GroupTracks* group = trkExt->getGroupTracks(); + + streamlog_out(DEBUG2) << " ***************** AddNotCombinedTracks: Check track " << trkExt + << " id = " << trkExt->getTrack()->id() << std::endl; - streamlog_out(DEBUG2) << " ***************** AddNotCombinedTracks: Check track " << trkExt << " id = " << trkExt->getTrack()->id() << std::endl; - // only consider those tracks which have not yet been combined if (group == NULL) { @@ -2711,9 +2450,9 @@ void FPCCDFullLDCTracking_MarlinTrk::AddNotCombinedTracks() { float zmin = 1e+20; float zmax = -1e+20; - for (int iCur=0;iCurgetTrackerHit(); + for (int iCur = 0; iCur < nCur; ++iCur) { + TrackerHitExtended* curTrkHitExt = currentVec[iCur]; + TrackerHit* curTrkHit = curTrkHitExt->getTrackerHit(); float zpos = float(curTrkHit->getPosition()[2]); if (zpos < zmin) zmin = zpos; @@ -2721,46 +2460,44 @@ void FPCCDFullLDCTracking_MarlinTrk::AddNotCombinedTracks() { zmax = zpos; } - nNonAssignedTPCSeg++; // current number of TPC segment groupings int nGroups = int(TPCSegments.size()); float dPtMin = 1.0e+10; - GroupTracks * groupToAttach = NULL; - TrackExtended * trkToAttach = NULL; + GroupTracks* groupToAttach = NULL; + TrackExtended* trkToAttach = NULL; // loop over the current TPC segment groupings - for (int iG=0;iGgetTrackExtendedVec(); // number of segments with the candidate group int nTrk = int(segVec.size()); bool consider = true; - - if (_forbidOverlapInZTPC==1) { // if overlap in Z of the two segments is forbidden + if (_forbidOverlapInZTPC == 1) { // if overlap in Z of the two segments is forbidden // loop over all tracks in the current grouping - for (int iTrk=0;iTrkgetTrackerHitExtendedVec(); int nHitsInGrp = int(hitInGroupVec.size()); // loop over the hits and make sure that there is no overlap in z - for (int iHitInGrp=0;iHitInGrpgetTrackerHit(); + TrackerHitExtended* xTrkExt = hitInGroupVec[iHitInGrp]; + TrackerHit* xTrk = xTrkExt->getTrackerHit(); float xZ = float(xTrk->getPosition()[2]); - if (xZ>zmin&&xZ zmin && xZ < zmax) { consider = false; break; } @@ -2773,42 +2510,41 @@ void FPCCDFullLDCTracking_MarlinTrk::AddNotCombinedTracks() { if (consider) { // again loop over the tracks in the current group - for (int iTrk=0;iTrk=3) { + if (_debug >= 3) { int iopt = 5; - PrintOutMerging(trkExt,trkInGroup,iopt); + PrintOutMerging(trkExt, trkInGroup, iopt); } - } - else { - if (_debug>=3) { + } else { + if (_debug >= 3) { int iopt = 9; - PrintOutMerging(trkExt,trkInGroup,iopt); + PrintOutMerging(trkExt, trkInGroup, iopt); } } } - } - else { + } else { if (_debug >= 3) { int iopt = 9; - for (int iTrk=0;iTrk= dPtMin) { - PrintOutMerging(trkExt,trkInGroup,iopt); + float dPt = CompareTrk(trkExt, trkInGroup, _d0CutToMergeTPC, _z0CutToMergeTPC, iComp); + if (dPt >= dPtMin) { + PrintOutMerging(trkExt, trkInGroup, iopt); } } } @@ -2817,7 +2553,7 @@ void FPCCDFullLDCTracking_MarlinTrk::AddNotCombinedTracks() { // check the pt cut for merging and that a group has been found to match .. if (dPtMin < _dPCutToMergeTPC && groupToAttach != NULL) { - + // add the track to the group groupToAttach->addTrackExtended(trkExt); trkExt->setGroupTracks(groupToAttach); @@ -2828,23 +2564,24 @@ void FPCCDFullLDCTracking_MarlinTrk::AddNotCombinedTracks() { float edges[2]; edges[0] = zmin; - if (zminGroupzmax) + if (zmaxGroup > zmax) edges[1] = zmaxGroup; groupToAttach->setEdges(edges); - if (_debug>=3) { + if (_debug >= 3) { int iopt = 3; - PrintOutMerging(trkExt,trkToAttach,iopt); + PrintOutMerging(trkExt, trkToAttach, iopt); } } else { - - // create a new group of segments - GroupTracks * newSegment = new GroupTracks(trkExt); + + // create a new group of segments + GroupTracks* newSegment = new GroupTracks(trkExt); trkExt->setGroupTracks(newSegment); - streamlog_out(DEBUG2) << " ***************** AddNotCombinedTracks: Create new TPC Segment Group for track " << trkExt << " id = " << trkExt->getTrack()->id() << std::endl; - + streamlog_out(DEBUG2) << " ***************** AddNotCombinedTracks: Create new TPC Segment Group for track " + << trkExt << " id = " << trkExt->getTrack()->id() << std::endl; + TPCSegments.push_back(newSegment); float edges[2]; edges[0] = zmin; @@ -2855,11 +2592,11 @@ void FPCCDFullLDCTracking_MarlinTrk::AddNotCombinedTracks() { } // At this stage all tpc segements will have been grouped. - + // Now try to combine the groups of TPC segments with the // reconstructed tracks which have already been combined into full tracks // containing both Si and TPC segments - + int nCombTrk = int(_trkImplVec.size()); int nSegments = int(TPCSegments.size()); @@ -2867,156 +2604,152 @@ void FPCCDFullLDCTracking_MarlinTrk::AddNotCombinedTracks() { // std::cout << "nSegments = " << nSegments << std::endl; // loop over all the TPC segment collections - for (int iS=0;iSgetTrackExtendedVec(); float zminTPCSeg = segments->getEdges()[0]; float zmaxTPCSeg = segments->getEdges()[1]; int nTrk = int(segVec.size()); - TrackExtended * CombTrkToAttach = NULL; - TrackExtended * keyTrack = NULL; + TrackExtended* CombTrkToAttach = NULL; + TrackExtended* keyTrack = NULL; float deltaPtMin = _dPCutToMergeTPC; // search over the combined (good) tracks - for (int iCTrk=0;iCTrkgetGroupTracks(); + TrackExtended* combTrk = _trkImplVec[iCTrk]; + GroupTracks* groupComb = combTrk->getGroupTracks(); bool consider = true; - if (_forbidOverlapInZComb==1) { // if overlap in Z of the two segments is forbidden + if (_forbidOverlapInZComb == 1) { // if overlap in Z of the two segments is forbidden float zminComb = groupComb->getEdges()[0]; float zmaxComb = groupComb->getEdges()[1]; - consider = (zminTPCSeg>zmaxComb) || (zmaxTPCSeg zmaxComb) || (zmaxTPCSeg < zminComb); } - + // if there are not overlaps in z, if _forbidOverlapInZComb is set above if (consider) { // loop over the TPC segments in the group - for (int iTrk=0;iTrk=3) { - GroupTracks * groupCur = combTrk->getGroupTracks(); - TrackExtended * dummySi = groupCur->getTrackExtendedVec()[0]; + } else { + if (_debug >= 3) { + GroupTracks* groupCur = combTrk->getGroupTracks(); + TrackExtended* dummySi = groupCur->getTrackExtendedVec()[0]; int iopt_temp = 8; - PrintOutMerging(trk,dummySi,iopt_temp); + PrintOutMerging(trk, dummySi, iopt_temp); } } } - } - else { - if (_debug>=3) { - for (int iTrk=0;iTrk= 3) { + for (int iTrk = 0; iTrk < nTrk; ++iTrk) { + TrackExtended* trk = segVec[iTrk]; int iopt = 0; - float dPt = CompareTrk(trk,combTrk,_d0CutToMergeTPC,_z0CutToMergeTPC,iopt); - if (dPt>deltaPtMin) { - GroupTracks * groupCur = combTrk->getGroupTracks(); - TrackExtended * dummySi = groupCur->getTrackExtendedVec()[0]; + float dPt = CompareTrk(trk, combTrk, _d0CutToMergeTPC, _z0CutToMergeTPC, iopt); + if (dPt > deltaPtMin) { + GroupTracks* groupCur = combTrk->getGroupTracks(); + TrackExtended* dummySi = groupCur->getTrackExtendedVec()[0]; int iopt_temp = 8; - PrintOutMerging(trk,dummySi,iopt_temp); + PrintOutMerging(trk, dummySi, iopt_temp); } } } } } - + if (CombTrkToAttach != NULL) { // attach TPC segment to existing Comb Track - GroupTracks * groupToAttach = CombTrkToAttach->getGroupTracks(); - TrackExtended * SiCombTrk = groupToAttach->getTrackExtendedVec()[0]; - TrackExtended * TpcCombTrk = groupToAttach->getTrackExtendedVec()[1]; + GroupTracks* groupToAttach = CombTrkToAttach->getGroupTracks(); + TrackExtended* SiCombTrk = groupToAttach->getTrackExtendedVec()[0]; + TrackExtended* TpcCombTrk = groupToAttach->getTrackExtendedVec()[1]; - if (_debug>=3) { + if (_debug >= 3) { int iopt = 4; - PrintOutMerging(keyTrack,SiCombTrk,iopt); + PrintOutMerging(keyTrack, SiCombTrk, iopt); iopt = 5; - PrintOutMerging(keyTrack,TpcCombTrk,iopt); + PrintOutMerging(keyTrack, TpcCombTrk, iopt); } - for (int iTrk=0;iTrkaddTrackExtended( segmentTrack ); - segmentTrack->setGroupTracks( groupToAttach ); + TrackExtended* segmentTrack = segVec[iTrk]; + groupToAttach->addTrackExtended(segmentTrack); + segmentTrack->setGroupTracks(groupToAttach); TrackerHitExtendedVec hitVec = segmentTrack->getTrackerHitExtendedVec(); int nHitSeg = int(hitVec.size()); - for (int iHS=0;iHSsetUsedInFit(false); - CombTrkToAttach->addTrackerHitExtended( hitExt ); - + CombTrkToAttach->addTrackerHitExtended(hitExt); } } - } - else { - if (nTrk==1) { // create a new group - GroupTracks * newGrp = new GroupTracks(); + } else { + if (nTrk == 1) { // create a new group + GroupTracks* newGrp = new GroupTracks(); segVec[0]->setGroupTracks(newGrp); newGrp->addTrackExtended(segVec[0]); TrackerHitExtendedVec TpcHitVec = segVec[0]->getTrackerHitExtendedVec(); int nTpcH = int(TpcHitVec.size()); - for (int iTpcH=0;iTpcHsetUsedInFit( true ); + for (int iTpcH = 0; iTpcH < nTpcH; ++iTpcH) { + TpcHitVec[iTpcH]->setUsedInFit(true); } _trkImplVec.push_back(segVec[0]); _allNonCombinedTPCTracks.push_back(segVec[0]); - } - else { // several segments - + } else { // several segments + float zMin = 1.0e+20; - TrackExtended * chosenTrack = NULL; + TrackExtended* chosenTrack = NULL; // loop over the segments - for (int iTrk=0;iTrkgetTrack(); + Track* track = segment->getTrack(); TrackerHitVec hitVec = track->getTrackerHits(); streamlog_out(DEBUG1) << "Group of orphaned TPC tracks: trying track " << track->id() << std::endl; - + int nHits = int(hitVec.size()); // loop over it's hits - for (int iH=0;iHgetPosition()[2]); // if this segment has the hit closest to the IP so far - if (zPosigetTrack()->id() << std::endl; - streamlog_out(DEBUG2) << "Group of orphaned TPC tracks: chosen track taken as " << chosenTrack->getTrack()->id() << std::endl; - // create a new group of tracks - GroupTracks * newGroup = new GroupTracks(); + GroupTracks* newGroup = new GroupTracks(); // first add the chosen track - chosenTrack->setGroupTracks( newGroup ); - newGroup->addTrackExtended( chosenTrack ); - + chosenTrack->setGroupTracks(newGroup); + newGroup->addTrackExtended(chosenTrack); + // loop over the segments ... - for (int iTrk=0;iTrkgetTrackerHitExtendedVec(); - int nHitS = int(hitVecS.size()); + int nHitS = int(hitVecS.size()); // loop over the hits for the current segment - for (int iH=0;iHsetGroupTracks( newGroup ); - newGroup->addTrackExtended( segment ); - trkHitExt->setUsedInFit( false ); - chosenTrack->addTrackerHitExtended( trkHitExt ); - } - else { - trkHitExt->setUsedInFit( true ); + segment->setGroupTracks(newGroup); + newGroup->addTrackExtended(segment); + trkHitExt->setUsedInFit(false); + chosenTrack->addTrackerHitExtended(trkHitExt); + } else { + trkHitExt->setUsedInFit(true); } } } @@ -3067,136 +2799,144 @@ void FPCCDFullLDCTracking_MarlinTrk::AddNotCombinedTracks() { } } } - for (int iS=0;iSgetTrack(); - GroupTracks * group = trkExt->getGroupTracks(); + } else { // adding all TPC segments to the list of tracks (track splitting is allowed) + for (int i = 0; i < nTPCTrk; ++i) { + TrackExtended* trkExt = _allTPCTracks[i]; + Track* track = trkExt->getTrack(); + GroupTracks* group = trkExt->getGroupTracks(); if (group == NULL) { - streamlog_out(DEBUG2) << " ***************** AddNotCombinedTracks: _mergeTPCSegments = " << _mergeTPCSegments << " : Add non combined TPC track " << trkExt << " id = " << track->id() << std::endl; + streamlog_out(DEBUG2) << " ***************** AddNotCombinedTracks: _mergeTPCSegments = " << _mergeTPCSegments + << " : Add non combined TPC track " << trkExt << " id = " << track->id() << std::endl; TrackerHitExtendedVec hitVec = trkExt->getTrackerHitExtendedVec(); int nHTPC = int(hitVec.size()); - for (int iHTPC=0;iHTPCsetUsedInFit(true); } _trkImplVec.push_back(trkExt); - _allNonCombinedTPCTracks.push_back( trkExt ); - - GroupTracks * newGrp = new GroupTracks(); - newGrp->addTrackExtended( trkExt ); - trkExt->setGroupTracks( newGrp ); + _allNonCombinedTPCTracks.push_back(trkExt); + GroupTracks* newGrp = new GroupTracks(); + newGrp->addTrackExtended(trkExt); + trkExt->setGroupTracks(newGrp); } - } + } } - - for (int i=0;igetTrack(); - GroupTracks * group = trkExt->getGroupTracks(); + + for (int i = 0; i < nSiTrk; ++i) { // adding left-over Si segments to the list of tracks + TrackExtended* trkExt = _allSiTracks[i]; + Track* track = trkExt->getTrack(); + GroupTracks* group = trkExt->getGroupTracks(); if (group == NULL) { - - streamlog_out(DEBUG2) << " ***************** AddNotCombinedTracks: Add non combined Silicon Track : " << trkExt << " id = " << track->id() << std::endl; - + + streamlog_out(DEBUG2) << " ***************** AddNotCombinedTracks: Add non combined Silicon Track : " << trkExt + << " id = " << track->id() << std::endl; + TrackerHitExtendedVec hitVec = trkExt->getTrackerHitExtendedVec(); int nHSi = int(hitVec.size()); - for (int iHSi=0;iHSisetUsedInFit(true); } _trkImplVec.push_back(trkExt); - _allNonCombinedSiTracks.push_back( trkExt ); - - GroupTracks * newGrp = new GroupTracks(); - newGrp->addTrackExtended( trkExt ); - trkExt->setGroupTracks( newGrp ); + _allNonCombinedSiTracks.push_back(trkExt); + GroupTracks* newGrp = new GroupTracks(); + newGrp->addTrackExtended(trkExt); + trkExt->setGroupTracks(newGrp); } } - } -void FPCCDFullLDCTracking_MarlinTrk::CheckTracks() { - - for(unsigned int i = 0; i< _trkImplVec.size();i++){ - TrackExtended *first = _trkImplVec[i]; - if(first==NULL)continue; +void FPCCDFullLDCTracking_MarlinTrk::CheckTracks() { + + for (unsigned int i = 0; i < _trkImplVec.size(); i++) { + TrackExtended* first = _trkImplVec[i]; + if (first == NULL) + continue; float d0First = first->getD0(); float z0First = first->getZ0(); float omegaFirst = first->getOmega(); float tanLFirst = first->getTanLambda(); float phiFirst = first->getPhi(); HelixClass helixFirst; - helixFirst.Initialize_Canonical(phiFirst,d0First,z0First,omegaFirst,tanLFirst,_bField); + helixFirst.Initialize_Canonical(phiFirst, d0First, z0First, omegaFirst, tanLFirst, _bField); float momFirst[3]; - momFirst[0]= helixFirst.getMomentum()[0]; - momFirst[1]= helixFirst.getMomentum()[1]; - momFirst[2]= helixFirst.getMomentum()[2]; - float pFirst = sqrt(momFirst[0]*momFirst[0]+momFirst[1]*momFirst[1]+momFirst[2]*momFirst[2]); - if(std::isnan(pFirst))continue; - TrackerHitExtendedVec firstHitVec = first->getTrackerHitExtendedVec(); - if(firstHitVec.size()<1)continue; - - for(unsigned int j = i+1; j<_trkImplVec.size();j++){ - TrackExtended *second = _trkImplVec[j]; - if(second==NULL)continue; + momFirst[0] = helixFirst.getMomentum()[0]; + momFirst[1] = helixFirst.getMomentum()[1]; + momFirst[2] = helixFirst.getMomentum()[2]; + float pFirst = sqrt(momFirst[0] * momFirst[0] + momFirst[1] * momFirst[1] + momFirst[2] * momFirst[2]); + if (std::isnan(pFirst)) + continue; + TrackerHitExtendedVec firstHitVec = first->getTrackerHitExtendedVec(); + if (firstHitVec.size() < 1) + continue; + + for (unsigned int j = i + 1; j < _trkImplVec.size(); j++) { + TrackExtended* second = _trkImplVec[j]; + if (second == NULL) + continue; float d0Second = second->getD0(); float z0Second = second->getZ0(); float omegaSecond = second->getOmega(); float tanLSecond = second->getTanLambda(); float phiSecond = second->getPhi(); HelixClass helixSecond; - helixSecond.Initialize_Canonical(phiSecond,d0Second,z0Second,omegaSecond,tanLSecond,_bField); + helixSecond.Initialize_Canonical(phiSecond, d0Second, z0Second, omegaSecond, tanLSecond, _bField); float momSecond[3]; momSecond[0] = helixSecond.getMomentum()[0]; momSecond[1] = helixSecond.getMomentum()[1]; momSecond[2] = helixSecond.getMomentum()[2]; - float pSecond = sqrt(momSecond[0]*momSecond[0]+momSecond[1]*momSecond[1]+momSecond[2]*momSecond[2]); - if(std::isnan(pSecond))continue; - TrackerHitExtendedVec secondHitVec = second->getTrackerHitExtendedVec(); - if(secondHitVec.size()<1)continue; - if(firstHitVec.size()+secondHitVec.size()<10)continue; - - - float pdot = (momFirst[0]*momSecond[0]+momFirst[1]*momSecond[1]+momFirst[2]*momSecond[2])/pFirst/pSecond; - if(pdot<0.999)continue; + float pSecond = sqrt(momSecond[0] * momSecond[0] + momSecond[1] * momSecond[1] + momSecond[2] * momSecond[2]); + if (std::isnan(pSecond)) + continue; + TrackerHitExtendedVec secondHitVec = second->getTrackerHitExtendedVec(); + if (secondHitVec.size() < 1) + continue; + if (firstHitVec.size() + secondHitVec.size() < 10) + continue; + + float pdot = + (momFirst[0] * momSecond[0] + momFirst[1] * momSecond[1] + momFirst[2] * momSecond[2]) / pFirst / pSecond; + if (pdot < 0.999) + continue; // const float sigmaPOverPFirst = sqrt(first->getCovMatrix()[5])/fabs(omegaFirst); // const float sigmaPOverPSecond = sqrt(second->getCovMatrix()[5])/fabs(omegaSecond); // const float deltaP = fabs(pFirst-pSecond); - // const float sigmaDeltaP = sqrt(pFirst*sigmaPOverPFirst*pFirst*sigmaPOverPFirst+pSecond*sigmaPOverPSecond*pSecond*sigmaPOverPSecond); + // const float sigmaDeltaP = + // sqrt(pFirst*sigmaPOverPFirst*pFirst*sigmaPOverPFirst+pSecond*sigmaPOverPSecond*pSecond*sigmaPOverPSecond); // const float significance = deltaP/sigmaDeltaP; - - TrackExtended * combinedTrack = CombineTracks(first,second, _maxAllowedPercentageOfOutliersForTrackCombination, true); - if(combinedTrack != NULL){ - const int minHits = std::min(firstHitVec.size(),secondHitVec.size()); - const int maxHits = std::max(firstHitVec.size(),secondHitVec.size()); - - if( combinedTrack->getNDF() <= 2*maxHits+minHits-5){ + + TrackExtended* combinedTrack = + CombineTracks(first, second, _maxAllowedPercentageOfOutliersForTrackCombination, true); + if (combinedTrack != NULL) { + const int minHits = std::min(firstHitVec.size(), secondHitVec.size()); + const int maxHits = std::max(firstHitVec.size(), secondHitVec.size()); + + if (combinedTrack->getNDF() <= 2 * maxHits + minHits - 5) { delete combinedTrack->getGroupTracks(); delete combinedTrack; continue; } - - float d0 = combinedTrack->getD0(); - float z0 = combinedTrack->getZ0(); + + float d0 = combinedTrack->getD0(); + float z0 = combinedTrack->getZ0(); float omega = combinedTrack->getOmega(); - float tanL = combinedTrack->getTanLambda(); - float phi = combinedTrack->getPhi(); - + float tanL = combinedTrack->getTanLambda(); + float phi = combinedTrack->getPhi(); + HelixClass helix; - helix.Initialize_Canonical(phi,d0,z0,omega,tanL,_bField); + helix.Initialize_Canonical(phi, d0, z0, omega, tanL, _bField); // float mom[3]; // mom[0] = helix.getMomentum()[0]; // mom[1] = helix.getMomentum()[1]; @@ -3204,95 +2944,89 @@ void FPCCDFullLDCTracking_MarlinTrk::CheckTracks() { // float p = sqrt(mom[0]*mom[0]+mom[1]*mom[1]+mom[2]*mom[2]); // float chi2Sig = (combinedTrack->getChi2() - combinedTrack->getNDF()); // chi2Sig = chi2Sig/sqrt(combinedTrack->getNDF()*2); - - - + int nTpcFirst(0); int nUsedFirst(0); - for(unsigned int ihit = 0;ihitgetTrackerHit()) == lcio::ILDDetID::TPC) nTpcFirst++; - - if( firstHitVec[ihit]->getUsedInFit()==true ) nUsedFirst++; + for (unsigned int ihit = 0; ihit < firstHitVec.size(); ihit++) { + + if (getDetectorID(firstHitVec[ihit]->getTrackerHit()) == lcio::ILDDetID::TPC) + nTpcFirst++; + + if (firstHitVec[ihit]->getUsedInFit() == true) + nUsedFirst++; } - - + int nTpcSecond(0); int nUsedSecond(0); - for(unsigned int ihit = 0;ihitgetTrackerHit()) == lcio::ILDDetID::TPC) ++nTpcSecond; - if( secondHitVec[ihit]->getUsedInFit()==true ) ++nUsedSecond; + for (unsigned int ihit = 0; ihit < secondHitVec.size(); ihit++) { + if (getDetectorID(secondHitVec[ihit]->getTrackerHit()) == lcio::ILDDetID::TPC) + ++nTpcSecond; + if (secondHitVec[ihit]->getUsedInFit() == true) + ++nUsedSecond; } delete combinedTrack->getGroupTracks(); delete combinedTrack; } } } - - } - /* - + compare the following: - + i) delta omega < 2 * _dOmegaForMerging ii) delta d0 < d0Cut iii) delta z0 < z0Cut if above three cuts are passed return: - + the angle between the two tracks (return by reference) and the difference in omega - + */ +float FPCCDFullLDCTracking_MarlinTrk::CompareTrkII(TrackExtended* first, TrackExtended* second, float d0Cut, + float z0Cut, int /*iopt*/, float& Angle) { -float FPCCDFullLDCTracking_MarlinTrk::CompareTrkII(TrackExtended * first, TrackExtended * second, - float d0Cut, float z0Cut,int /*iopt*/,float & Angle) { - - float result = 1.0e+20; - Angle = 1.0e+20; + Angle = 1.0e+20; float omegaFirst = first->getOmega(); float omegaSecond = second->getOmega(); - float deltaOmega = fabs((omegaFirst-omegaSecond)/omegaSecond); - if(deltaOmega> 2*_dOmegaForMerging)return result; - - + float deltaOmega = fabs((omegaFirst - omegaSecond) / omegaSecond); + if (deltaOmega > 2 * _dOmegaForMerging) + return result; + float d0First = first->getD0(); float z0First = first->getZ0(); float d0Second = second->getD0(); float z0Second = second->getZ0(); - - bool isCloseInIP = (fabs(d0First-d0Second)getTanLambda(); float phiFirst = first->getPhi(); float tanLSecond = second->getTanLambda(); float phiSecond = second->getPhi(); float qFirst = PIOVER2 - atan(tanLFirst); float qSecond = PIOVER2 - atan(tanLSecond); - - Angle = (cos(phiFirst)*cos(phiSecond)+sin(phiFirst)*sin(phiSecond))* - sin(qFirst)*sin(qSecond)+cos(qFirst)*cos(qSecond); + + Angle = (cos(phiFirst) * cos(phiSecond) + sin(phiFirst) * sin(phiSecond)) * sin(qFirst) * sin(qSecond) + + cos(qFirst) * cos(qSecond); Angle = acos(Angle); - + result = deltaOmega; - + return result; - } - /* - + compare the following: i) significance d0 < d0Cut @@ -3300,180 +3034,181 @@ float FPCCDFullLDCTracking_MarlinTrk::CompareTrkII(TrackExtended * first, TrackE iii) pdot > 0.999 if above three cuts are passed return: - + the significance dAngle (return by reference) and the significance dOmega - + */ -float FPCCDFullLDCTracking_MarlinTrk::CompareTrkIII(TrackExtended * first, TrackExtended * second, - float d0Cut, float z0Cut,int /*iopt*/, float & AngleSignificance) { - - +float FPCCDFullLDCTracking_MarlinTrk::CompareTrkIII(TrackExtended* first, TrackExtended* second, float d0Cut, + float z0Cut, int /*iopt*/, float& AngleSignificance) { + float result = 1.0e+20; - + float d0First = first->getD0(); float z0First = first->getZ0(); float omegaFirst = first->getOmega(); float tanLFirst = first->getTanLambda(); float phiFirst = first->getPhi(); float qFirst = PIOVER2 - atan(tanLFirst); - - + float d0Second = second->getD0(); float z0Second = second->getZ0(); float omegaSecond = second->getOmega(); float tanLSecond = second->getTanLambda(); float phiSecond = second->getPhi(); float qSecond = PIOVER2 - atan(tanLSecond); - - - //MB 2010 03 + + // MB 2010 03 float d0ErrFirst = sqrt(first->getCovMatrix()[0]); float z0ErrFirst = sqrt(first->getCovMatrix()[9]); // float omegaErrFirst = sqrt(first->getCovMatrix()[5]); float phiErrFirst = sqrt(first->getCovMatrix()[2]); - float qErrFirst = sqrt(cos(qFirst)*cos(qFirst)*first->getCovMatrix()[14]); - //MB END - //MB 2010 03 + float qErrFirst = sqrt(cos(qFirst) * cos(qFirst) * first->getCovMatrix()[14]); + // MB END + // MB 2010 03 float d0ErrSecond = sqrt(second->getCovMatrix()[0]); float z0ErrSecond = sqrt(second->getCovMatrix()[9]); // float omegaErrSecond = sqrt(second->getCovMatrix()[5]); float phiErrSecond = sqrt(second->getCovMatrix()[2]); - float qErrSecond = sqrt(cos(qSecond)*cos(qSecond)*second->getCovMatrix()[14]); - //MB END - - + float qErrSecond = sqrt(cos(qSecond) * cos(qSecond) * second->getCovMatrix()[14]); + // MB END + // bool isCloseInIP = (fabs(d0First-d0Second)getCovMatrix()[5])/fabs(omegaFirst); - const float sigmaPOverPSecond = sqrt(second->getCovMatrix()[5])/fabs(omegaSecond); - const float deltaP = fabs(momFirst-momSecond); - const float sigmaPFirst = momFirst*sigmaPOverPFirst; - const float sigmaPSecond = momSecond*sigmaPOverPSecond; - const float sigmaDeltaP = sqrt(sigmaPFirst*sigmaPFirst+sigmaPSecond*sigmaPSecond); - const float significance = deltaP/sigmaDeltaP; - - //MB 2010 03 - float errorAngle =sin(phiFirst)*sin(phiFirst)*phiErrFirst*phiErrFirst*cos(phiSecond)*cos(phiSecond)+ - sin(phiSecond)*sin(phiSecond)*phiErrSecond*phiErrSecond*cos(phiFirst)*cos(phiFirst)+ - sin(qFirst)*sin(qFirst)*qErrFirst*qErrFirst*cos(qSecond)*cos(qSecond)+ - sin(qSecond)*sin(qSecond)*qErrSecond*qErrSecond*cos(qFirst)*cos(qFirst)+ - cos(phiFirst)*cos(phiFirst)*phiErrFirst*phiErrFirst*(sin(phiSecond)*sin(qFirst)*sin(qSecond))*(sin(phiSecond)*sin(qFirst)*sin(qSecond))+ - cos(phiSecond)*cos(phiSecond)*phiErrSecond*phiErrSecond*(sin(phiFirst)*sin(qFirst)*sin(qSecond))*(sin(phiFirst)*sin(qFirst)*sin(qSecond))+ - cos(qFirst)*cos(qFirst)*qErrFirst*qErrFirst*(sin(phiFirst)*sin(phiSecond)*sin(qSecond))*(sin(phiFirst)*sin(phiSecond)*sin(qSecond))+ - cos(qSecond)*cos(qSecond)*qErrSecond*qErrSecond*(sin(phiFirst)*sin(phiSecond)*sin(qFirst))*(sin(phiFirst)*sin(phiSecond)*sin(qFirst)); - - if(Angle<1.){ - errorAngle = sqrt(1./(1.-Angle*Angle)*errorAngle); - }else{ + + float pdot = (pFirst[0] * pSecond[0] + pFirst[1] * pSecond[1] + pFirst[2] * pSecond[2]) / momFirst / momSecond; + if (pdot < 0.999) + return result; + + const float sigmaPOverPFirst = sqrt(first->getCovMatrix()[5]) / fabs(omegaFirst); + const float sigmaPOverPSecond = sqrt(second->getCovMatrix()[5]) / fabs(omegaSecond); + const float deltaP = fabs(momFirst - momSecond); + const float sigmaPFirst = momFirst * sigmaPOverPFirst; + const float sigmaPSecond = momSecond * sigmaPOverPSecond; + const float sigmaDeltaP = sqrt(sigmaPFirst * sigmaPFirst + sigmaPSecond * sigmaPSecond); + const float significance = deltaP / sigmaDeltaP; + + // MB 2010 03 + float errorAngle = + sin(phiFirst) * sin(phiFirst) * phiErrFirst * phiErrFirst * cos(phiSecond) * cos(phiSecond) + + sin(phiSecond) * sin(phiSecond) * phiErrSecond * phiErrSecond * cos(phiFirst) * cos(phiFirst) + + sin(qFirst) * sin(qFirst) * qErrFirst * qErrFirst * cos(qSecond) * cos(qSecond) + + sin(qSecond) * sin(qSecond) * qErrSecond * qErrSecond * cos(qFirst) * cos(qFirst) + + cos(phiFirst) * cos(phiFirst) * phiErrFirst * phiErrFirst * (sin(phiSecond) * sin(qFirst) * sin(qSecond)) * + (sin(phiSecond) * sin(qFirst) * sin(qSecond)) + + cos(phiSecond) * cos(phiSecond) * phiErrSecond * phiErrSecond * (sin(phiFirst) * sin(qFirst) * sin(qSecond)) * + (sin(phiFirst) * sin(qFirst) * sin(qSecond)) + + cos(qFirst) * cos(qFirst) * qErrFirst * qErrFirst * (sin(phiFirst) * sin(phiSecond) * sin(qSecond)) * + (sin(phiFirst) * sin(phiSecond) * sin(qSecond)) + + cos(qSecond) * cos(qSecond) * qErrSecond * qErrSecond * (sin(phiFirst) * sin(phiSecond) * sin(qFirst)) * + (sin(phiFirst) * sin(phiSecond) * sin(qFirst)); + + if (Angle < 1.) { + errorAngle = sqrt(1. / (1. - Angle * Angle) * errorAngle); + } else { errorAngle = sqrt(errorAngle); } - - if(errorAngle<1.e-6)errorAngle=1.e-6; - - AngleSignificance = fabs(acos(Angle)/errorAngle); - + + if (errorAngle < 1.e-6) + errorAngle = 1.e-6; + + AngleSignificance = fabs(acos(Angle) / errorAngle); + return significance; - } - /* - + compare the following: - + i) delta d0 < d0Cut and optionally (d0_1 + d0_2) < d0cut ii) delta z0 < z0Cut - + if above two cuts are passed then: - + if ( (ptFirst<_PtCutToMergeTPC) && (ptSecond<_PtCutToMergeTPC) ) { - - then check the difference in momentum - - else - + + then check the difference in momentum + + else + check for cases where PatRec splits non-looping TPC tracks look for two tracks where total tpc hits are not more than total number of pad rows and that the hits on one track are close to the helix of the other track. - + Check that the angular and momentum difference meets the cuts for either hight or low pt - also check if the angle is very small between the tracks and that the significance of the difference in pt is less than 10 - - - .... - + also check if the angle is very small between the tracks and that the significance of the difference in pt is less + than 10 + + + .... + note currently this is only used in AddNotCombinedTracks - + */ +float FPCCDFullLDCTracking_MarlinTrk::CompareTrk(TrackExtended* first, TrackExtended* second, float d0Cut, float z0Cut, + int iopt) { -float FPCCDFullLDCTracking_MarlinTrk::CompareTrk(TrackExtended * first, TrackExtended * second, - float d0Cut, float z0Cut,int iopt) { - float result = 1.0e+20; - + float d0First = first->getD0(); float z0First = first->getZ0(); float omegaFirst = first->getOmega(); float tanLFirst = first->getTanLambda(); float phiFirst = first->getPhi(); - + float d0Second = second->getD0(); float z0Second = second->getZ0(); float omegaSecond = second->getOmega(); float tanLSecond = second->getTanLambda(); float phiSecond = second->getPhi(); - - bool isCloseInIP = (fabs(d0First-d0Second)0) isCloseInIP = isCloseInIP || (fabs(d0First+d0Second) 0) + isCloseInIP = isCloseInIP || (fabs(d0First + d0Second) < d0Cut); + + isCloseInIP = isCloseInIP && (fabs(z0Second - z0First) < z0Cut); + HelixClass helixFirst; - helixFirst.Initialize_Canonical(phiFirst,d0First,z0First,omegaFirst,tanLFirst,_bField); + helixFirst.Initialize_Canonical(phiFirst, d0First, z0First, omegaFirst, tanLFirst, _bField); HelixClass helixSecond; - helixSecond.Initialize_Canonical(phiSecond,d0Second,z0Second,omegaSecond,tanLSecond,_bField); - + helixSecond.Initialize_Canonical(phiSecond, d0Second, z0Second, omegaSecond, tanLSecond, _bField); + float pFirst[3]; float pSecond[3]; float dPminus[3]; @@ -3482,133 +3217,126 @@ float FPCCDFullLDCTracking_MarlinTrk::CompareTrk(TrackExtended * first, TrackExt float momSecond = 0; float momMinus = 0; float momPlus = 0; - - if ( isCloseInIP ) { - - for (int iC=0;iC<3;++iC) { + + if (isCloseInIP) { + + for (int iC = 0; iC < 3; ++iC) { pFirst[iC] = helixFirst.getMomentum()[iC]; pSecond[iC] = helixSecond.getMomentum()[iC]; - momFirst += pFirst[iC]* pFirst[iC]; - momSecond += pSecond[iC]*pSecond[iC]; + momFirst += pFirst[iC] * pFirst[iC]; + momSecond += pSecond[iC] * pSecond[iC]; dPminus[iC] = pFirst[iC] - pSecond[iC]; dPplus[iC] = pFirst[iC] + pSecond[iC]; - momMinus += dPminus[iC]*dPminus[iC]; - momPlus += dPplus[iC]*dPplus[iC]; + momMinus += dPminus[iC] * dPminus[iC]; + momPlus += dPplus[iC] * dPplus[iC]; } momFirst = sqrt(momFirst); momSecond = sqrt(momSecond); - - float ptFirst = sqrt(pFirst[0]*pFirst[0]+pFirst[1]*pFirst[1]); - float ptSecond = sqrt(pSecond[0]*pSecond[0]+pSecond[1]*pSecond[1]); - + + float ptFirst = sqrt(pFirst[0] * pFirst[0] + pFirst[1] * pFirst[1]); + float ptSecond = sqrt(pSecond[0] * pSecond[0] + pSecond[1] * pSecond[1]); + // if both track's pt are lower than _PtCutToMergeTPC - if ( (ptFirst<_PtCutToMergeTPC) && (ptSecond<_PtCutToMergeTPC) ) { - + if ((ptFirst < _PtCutToMergeTPC) && (ptSecond < _PtCutToMergeTPC)) { + momMinus = sqrt(momMinus); momPlus = sqrt(momPlus); float nom = momMinus; // get the smaller difference for the nominator - if (momPlus0) + if (momPlus < nom && iopt > 0) nom = momPlus; float den = momFirst; // get the smallest momentum for the denominator - if (momSecondgetCovMatrix()[5])/fabs(omegaFirst); - const float sigmaPOverPSecond = sqrt(second->getCovMatrix()[5])/fabs(omegaSecond); - const float deltaP = fabs(momFirst-momSecond); - const float sigmaPFirst = momFirst*sigmaPOverPFirst; - const float sigmaPSecond = momSecond*sigmaPOverPSecond; - const float sigmaDeltaP = sqrt(sigmaPFirst*sigmaPFirst+sigmaPSecond*sigmaPSecond); - const float significance = deltaP/sigmaDeltaP; - - - //compare angle between the two vectors (cos theta) and their momentum - // if( ( pdot>0.99 && dpOverP<0.01 ) || ( pdot>0.998 && dpOverP<0.25 ) ){ - if( (pdot>_cosThetaCutHighPtMerge && dpOverP<_momDiffCutHighPtMerge) - || - (pdot>_cosThetaCutSoftHighPtMerge && dpOverP<_momDiffCutSoftHighPtMerge) - || (pdot > 0.9999 && significance <10) - ){ - - + + float dpOverP = 2.0 * fabs(momFirst - momSecond) / (momFirst + momSecond); + const float pdot = + (pFirst[0] * pSecond[0] + pFirst[1] * pSecond[1] + pFirst[2] * pSecond[2]) / momFirst / momSecond; + const float sigmaPOverPFirst = sqrt(first->getCovMatrix()[5]) / fabs(omegaFirst); + const float sigmaPOverPSecond = sqrt(second->getCovMatrix()[5]) / fabs(omegaSecond); + const float deltaP = fabs(momFirst - momSecond); + const float sigmaPFirst = momFirst * sigmaPOverPFirst; + const float sigmaPSecond = momSecond * sigmaPOverPSecond; + const float sigmaDeltaP = sqrt(sigmaPFirst * sigmaPFirst + sigmaPSecond * sigmaPSecond); + const float significance = deltaP / sigmaDeltaP; + + // compare angle between the two vectors (cos theta) and their momentum + // if( ( pdot>0.99 && dpOverP<0.01 ) || ( pdot>0.998 && dpOverP<0.25 ) ){ + if ((pdot > _cosThetaCutHighPtMerge && dpOverP < _momDiffCutHighPtMerge) || + (pdot > _cosThetaCutSoftHighPtMerge && dpOverP < _momDiffCutSoftHighPtMerge) || + (pdot > 0.9999 && significance < 10)) { + int nTrkGrpFirst = 0; int nTrkGrpSecond = 0; TrackerHitVec hitvecFirst; TrackerHitVec hitvecSecond; - GroupTracks * groupFirst = first->getGroupTracks(); - GroupTracks * groupSecond = second->getGroupTracks(); + GroupTracks* groupFirst = first->getGroupTracks(); + GroupTracks* groupSecond = second->getGroupTracks(); // does the first track belong to a group ... // if it does then get all the hits from the group - if(groupFirst!=NULL){ - + if (groupFirst != NULL) { + TrackExtendedVec tracksInGroupFirst = groupFirst->getTrackExtendedVec(); nTrkGrpFirst = int(tracksInGroupFirst.size()); - - for (int iTrkGrp=0;iTrkGrpgetTrackerHitExtendedVec(); - - for(unsigned int i =0; igetTrackerHit()); + + for (unsigned int i = 0; i < hitVec.size(); ++i) { + hitvecFirst.push_back(hitVec[i]->getTrackerHit()); } } } // does the second track belong to a group ... // if it does then get all the hits from the group - if(groupSecond!=NULL){ - + if (groupSecond != NULL) { + TrackExtendedVec tracksInGroupSecond = groupSecond->getTrackExtendedVec(); nTrkGrpSecond = int(tracksInGroupSecond.size()); - - for (int iTrkGrp=0;iTrkGrpgetTrackerHitExtendedVec(); - - for(unsigned int i=0;igetTrackerHitExtendedVec(); + + for (unsigned int i = 0; i < hitVec.size(); ++i) { hitvecSecond.push_back(hitVec[i]->getTrackerHit()); } } } - - - - // for non-looping tracks - int nhitsFirst = (int)hitvecFirst.size(); + + // for non-looping tracks + int nhitsFirst = (int)hitvecFirst.size(); int nhitsSecond = (int)hitvecSecond.size(); - int ntpcFirst = 0; - int ntpcSecond = 0; + int ntpcFirst = 0; + int ntpcSecond = 0; float hitxyz[3]; float dist[3]; - float maxdistFirst=0; - float maxdistSecond=0; + float maxdistFirst = 0; + float maxdistSecond = 0; int ncloseFirst = 0; int ncloseSecond = 0; float zminFirst = 99999; @@ -3616,355 +3344,344 @@ float FPCCDFullLDCTracking_MarlinTrk::CompareTrk(TrackExtended * first, TrackExt float zmaxFirst = -99999; float zmaxSecond = -99999; - - for(int ih =0;ihgetPosition()[0]; - float y = (float) hitvecFirst[ih]->getPosition()[1]; - float z = (float) hitvecFirst[ih]->getPosition()[2]; - - if(fabs(z)zmaxFirst) zmaxFirst=fabs(z); - - float r = sqrt(x*x+y*y); - + for (int ih = 0; ih < nhitsFirst; ++ih) { + + float x = (float)hitvecFirst[ih]->getPosition()[0]; + float y = (float)hitvecFirst[ih]->getPosition()[1]; + float z = (float)hitvecFirst[ih]->getPosition()[2]; + + if (fabs(z) < zminFirst) + zminFirst = fabs(z); + if (fabs(z) > zmaxFirst) + zmaxFirst = fabs(z); + + float r = sqrt(x * x + y * y); + // count the number of hits in the TPC for the first Track - if(r>_tpc_inner_r) ntpcFirst++; - - hitxyz[0]=x; - hitxyz[1]=y; - hitxyz[2]=z; + if (r > _tpc_inner_r) + ntpcFirst++; + + hitxyz[0] = x; + hitxyz[1] = y; + hitxyz[2] = z; helixSecond.getDistanceToPoint(hitxyz, dist); - + // compare 3D distance between hit and extrapolation - if(dist[2]>maxdistFirst) maxdistFirst=dist[2]; + if (dist[2] > maxdistFirst) + maxdistFirst = dist[2]; - // count the number of hits from the first track which are closer than _hitDistanceCutHighPtMerge to the second track - if(dist[2]<_hitDistanceCutHighPtMerge) ncloseFirst++; + // count the number of hits from the first track which are closer than _hitDistanceCutHighPtMerge to the + // second track + if (dist[2] < _hitDistanceCutHighPtMerge) + ncloseFirst++; } - - for(int ih =0;ihgetPosition()[0]; float y = (float)hitvecSecond[ih]->getPosition()[1]; float z = (float)hitvecSecond[ih]->getPosition()[2]; - - if(fabs(z)zmaxSecond) zmaxSecond=fabs(z); - - float r = sqrt(x*x+y*y); - + + if (fabs(z) < zminSecond) + zminSecond = fabs(z); + if (fabs(z) > zmaxSecond) + zmaxSecond = fabs(z); + + float r = sqrt(x * x + y * y); + // count the number of hits in the TPC for the second Track - if(r>_tpc_inner_r) ntpcSecond++; - - hitxyz[0]=x; - hitxyz[1]=y; - hitxyz[2]=z; + if (r > _tpc_inner_r) + ntpcSecond++; + + hitxyz[0] = x; + hitxyz[1] = y; + hitxyz[2] = z; helixFirst.getDistanceToPoint(hitxyz, dist); - - // compare 3D distance between hit and extrapolation - if(dist[2]>maxdistSecond) maxdistSecond=dist[2]; - // count the number of hits from the second track which are closer than _hitDistanceCutHighPtMerge to the first track - if(dist[2]<_hitDistanceCutHighPtMerge) ncloseSecond++; + // compare 3D distance between hit and extrapolation + if (dist[2] > maxdistSecond) + maxdistSecond = dist[2]; + // count the number of hits from the second track which are closer than _hitDistanceCutHighPtMerge to the + // first track + if (dist[2] < _hitDistanceCutHighPtMerge) + ncloseSecond++; } - - + // calculate the fraction of hits which are closer than _hitDistanceCutHighPtMerge - float fcloseFirst = (float)ncloseFirst/(float)nhitsFirst; - float fcloseSecond = (float)ncloseSecond/(float)nhitsSecond; - - - + float fcloseFirst = (float)ncloseFirst / (float)nhitsFirst; + float fcloseSecond = (float)ncloseSecond / (float)nhitsSecond; + bool split = false; - //std::cout << "Momenta = " << momFirst << " " << momSecond << std::endl; - //std::cout << "MaxDist = " << maxdistSecond << " " << maxdistFirst << " " << _maxHitDistanceCutHighPtMerge << std::endl; - //std::cout << "close = " << fcloseSecond << " " << fcloseFirst << " " << _maxFractionOfOutliersCutHighPtMerge << std::endl; - //std::cout << "ntpc = " << ntpcFirst << " " << ntpcSecond << " " << _tpc_pad_height+10 << std::endl; - //std::cout << "pdot = " << pdot << " significance " << significance << std::endl; - - + // std::cout << "Momenta = " << momFirst << " " << momSecond << std::endl; + // std::cout << "MaxDist = " << maxdistSecond << " " << maxdistFirst << " " << _maxHitDistanceCutHighPtMerge << + // std::endl; std::cout << "close = " << fcloseSecond << " " << fcloseFirst << " " << + // _maxFractionOfOutliersCutHighPtMerge << std::endl; std::cout << "ntpc = " << ntpcFirst << " " << + // ntpcSecond << " " << _tpc_pad_height+10 << std::endl; std::cout << "pdot = " << pdot << " significance " + // << significance << std::endl; + // SJA:FIXME: try to fit the two tracks, without checking the number of hits which are close !!!!!!!!!!! - TrackExtended * combinedTrack = CombineTracks(first,second, _maxAllowedPercentageOfOutliersForTrackCombination, true); + TrackExtended* combinedTrack = + CombineTracks(first, second, _maxAllowedPercentageOfOutliersForTrackCombination, true); // check that no more than 5 hits have been discared in the fit of the combined track - if(combinedTrack != NULL){ - //std::cout << "CombinedTrack " << combinedTrack->getNDF() << " c.f. " << first->getNDF()+second->getNDF()+5 << std::endl; - if(combinedTrack->getNDF()+10>first->getNDF()+second->getNDF()+5){ + if (combinedTrack != NULL) { + // std::cout << "CombinedTrack " << combinedTrack->getNDF() << " c.f. " << first->getNDF()+second->getNDF()+5 + // << std::endl; + if (combinedTrack->getNDF() + 10 > first->getNDF() + second->getNDF() + 5) { split = true; dpOverP = 0; - //std::cout << " Forcing MERGE " << std::endl; + // std::cout << " Forcing MERGE " << std::endl; } delete combinedTrack->getGroupTracks(); delete combinedTrack; - } - else { - //std::cout << "Could not combine track " << std::endl; - // if close in pt and the fraction of hits matching the helix extraolations is greater than _maxFractionOfOutliersCutHighPtMerge - if(significance<5 && fcloseFirst>_maxFractionOfOutliersCutHighPtMerge){ + } else { + // std::cout << "Could not combine track " << std::endl; + // if close in pt and the fraction of hits matching the helix extraolations is greater than + // _maxFractionOfOutliersCutHighPtMerge + if (significance < 5 && fcloseFirst > _maxFractionOfOutliersCutHighPtMerge) { split = true; dpOverP = 0; // int overlap = SegmentRadialOverlap(first,second); - //std::cout << " Forcing MERGE " << overlap << std::endl; + // std::cout << " Forcing MERGE " << overlap << std::endl; } } - + // criteria for split track // old criterion - // check the maximum deviation of the hits from the helix extrapolations, and fraction of hits matching the extrapolation based on a distance cut - if( maxdistSecond < _maxHitDistanceCutHighPtMerge && maxdistFirst < _maxHitDistanceCutHighPtMerge - && - (fcloseSecond > _maxFractionOfOutliersCutHighPtMerge || fcloseFirst > _maxFractionOfOutliersCutHighPtMerge) - ){ -// && -// ntpcFirst+ntpcSecond < _tpc_pad_height+10.) { // SJA:FIXME: this must be a bug, first it is a double, and second this value is never initialised ... - - split = true; - + // check the maximum deviation of the hits from the helix extrapolations, and fraction of hits matching the + // extrapolation based on a distance cut + if (maxdistSecond < _maxHitDistanceCutHighPtMerge && maxdistFirst < _maxHitDistanceCutHighPtMerge && + (fcloseSecond > _maxFractionOfOutliersCutHighPtMerge || + fcloseFirst > _maxFractionOfOutliersCutHighPtMerge)) { + // && + // ntpcFirst+ntpcSecond < _tpc_pad_height+10.) { // SJA:FIXME: this must be a bug, first it is a + // double, and second this value is never initialised ... + + split = true; } - - if(split){ + + if (split) { result = dpOverP; } - } } } - + return result; - } void FPCCDFullLDCTracking_MarlinTrk::AddNotAssignedHits() { - - - // currently any non-combined Silicon or TPC tracks are added to the list of tracks meaning their hits will not be available to be picked up. - // it might be preferable to drop these tracks, at least for track in Silicon with very bad Chi2 probabilities, and allow their hits to be re-used here ... - - - - - if (_assignSETHits>0) { // Assignment of SET Hits - - streamlog_out(DEBUG4) << "Assign SET hits *********************************" << std::endl; - - // Creating helix extrapolations - CreateExtrapolations(); - - int nSETHits = _allSETHits.size(); - std::vector SETHits; - - SETHits.resize(_nLayersSET); - - for (int iSET=0;iSETgetTrackerHit(); - int layer = getLayerID(trkHit); - if (layer>=0 && (unsigned)layer < _nLayersSET) - SETHits[layer].push_back(trkHitExt); - } - for (unsigned iL=0; iL< _nLayersSET; ++iL) { // loop over SET layers - TrackerHitExtendedVec hitVec = SETHits[iL]; - int refit = 1; - if(hitVec.empty() == false) AssignOuterHitsToTracks(hitVec,_distCutForSETHits,refit); - } - } - - + + // currently any non-combined Silicon or TPC tracks are added to the list of tracks meaning their hits will not be + // available to be picked up. it might be preferable to drop these tracks, at least for track in Silicon with very bad + // Chi2 probabilities, and allow their hits to be re-used here ... + + if (_assignSETHits > 0) { // Assignment of SET Hits + + streamlog_out(DEBUG4) << "Assign SET hits *********************************" << std::endl; + + // Creating helix extrapolations + CreateExtrapolations(); + + int nSETHits = _allSETHits.size(); + std::vector SETHits; + + SETHits.resize(_nLayersSET); + + for (int iSET = 0; iSET < nSETHits; ++iSET) { + TrackerHitExtended* trkHitExt = _allSETHits[iSET]; + TrackerHit* trkHit = trkHitExt->getTrackerHit(); + int layer = getLayerID(trkHit); + if (layer >= 0 && (unsigned)layer < _nLayersSET) + SETHits[layer].push_back(trkHitExt); + } + for (unsigned iL = 0; iL < _nLayersSET; ++iL) { // loop over SET layers + TrackerHitExtendedVec hitVec = SETHits[iL]; + int refit = 1; + if (hitVec.empty() == false) + AssignOuterHitsToTracks(hitVec, _distCutForSETHits, refit); + } + } + CleanUpExtrapolations(); - - - if (_assignSITHits>0) { // Treatment of left-over SIT hits - + + if (_assignSITHits > 0) { // Treatment of left-over SIT hits + streamlog_out(DEBUG4) << "Assign SIT hits *********************************" << std::endl; - - std::vector nonAssignedSITHits; + + std::vector nonAssignedSITHits; nonAssignedSITHits.resize(_nLayersSIT); - - int nSITHits = int(_allSITHits.size()); - + + int nSITHits = int(_allSITHits.size()); + // loop over all SIT hits ... - for (int iH=0;iHgetTrackExtended(); - + for (int iH = 0; iH < nSITHits; ++iH) { + + TrackerHitExtended* trkHitExt = _allSITHits[iH]; + TrackExtended* trkExt = trkHitExt->getTrackExtended(); + // check if this hit has not already been assigned to a track if (trkExt == NULL) { - TrackerHit * trkHit = trkHitExt->getTrackerHit(); - + TrackerHit* trkHit = trkHitExt->getTrackerHit(); + int layer = getLayerID(trkHit); - - if (layer >=0 && (unsigned)layer < _nLayersSIT) { + + if (layer >= 0 && (unsigned)layer < _nLayersSIT) { nonAssignedSITHits[layer].push_back(trkHitExt); } } - } - - for (int iL=_nLayersSIT-1;iL>=0;--iL) { // reverse loop over layers in Si - + } + + for (int iL = _nLayersSIT - 1; iL >= 0; --iL) { // reverse loop over layers in Si + TrackerHitExtendedVec hitVec = nonAssignedSITHits[iL]; - - if ( hitVec.empty() == false ) { - streamlog_out(DEBUG3) << "AddNotAssignedHits : Try to assign hits from layer " << iL << " : Number of hits = " << hitVec.size() << std::endl; - AssignSiHitsToTracks(hitVec, - _distCutForSITHits); - + + if (hitVec.empty() == false) { + streamlog_out(DEBUG3) << "AddNotAssignedHits : Try to assign hits from layer " << iL + << " : Number of hits = " << hitVec.size() << std::endl; + AssignSiHitsToTracks(hitVec, _distCutForSITHits); } - } } - - if (_assignFTDHits>0) { // Treatment of left-over FTD hits - + + if (_assignFTDHits > 0) { // Treatment of left-over FTD hits + streamlog_out(DEBUG4) << "Assign FTD hits *********************************" << std::endl; - + std::vector nonAssignedFTDHits; nonAssignedFTDHits.resize(_nLayersFTD); - + int nFTDHits = int(_allFTDHits.size()); - + // loop over all FTD hits ... - for (int iH=0;iHgetTrackExtended(); - + for (int iH = 0; iH < nFTDHits; ++iH) { + + TrackerHitExtended* trkHitExt = _allFTDHits[iH]; + TrackExtended* trkExt = trkHitExt->getTrackExtended(); + // check if this hit has not already been assigned to a track if (trkExt == NULL) { - TrackerHit * trkHit = trkHitExt->getTrackerHit(); - - + TrackerHit* trkHit = trkHitExt->getTrackerHit(); + // get the layer number int layer = getLayerID(trkHit); int petalIndex = getModuleID(trkHit); - - if ( _petalBasedFTDWithOverlaps == true ) { - + + if (_petalBasedFTDWithOverlaps == true) { + // as we are dealing with staggered petals we will use 2*nlayers in each directions +/- z - // the layers will follow the even odd numbering of the petals - if ( petalIndex % 2 == 0 ) { - layer = 2*layer; - } - else { - layer = 2*layer + 1; + // the layers will follow the even odd numbering of the petals + if (petalIndex % 2 == 0) { + layer = 2 * layer; + } else { + layer = 2 * layer + 1; } - } - - if (layer >=0 && layer < (int)_nLayersFTD) + + if (layer >= 0 && layer < (int)_nLayersFTD) nonAssignedFTDHits[layer].push_back(trkHitExt); } } - for (int iL=_nLayersFTD-1;iL>=0;--iL) { - if ( nonAssignedFTDHits[iL].empty() == false ) { - + for (int iL = _nLayersFTD - 1; iL >= 0; --iL) { + if (nonAssignedFTDHits[iL].empty() == false) { + TrackerHitExtendedVec hitVec = nonAssignedFTDHits[iL]; - streamlog_out(DEBUG3) << "AddNotAssignedHits : Try to assign hits from layer " << iL << " : Number of hits = " << hitVec.size() << std::endl; - AssignSiHitsToTracks(hitVec, - _distCutForFTDHits); - + streamlog_out(DEBUG3) << "AddNotAssignedHits : Try to assign hits from layer " << iL + << " : Number of hits = " << hitVec.size() << std::endl; + AssignSiHitsToTracks(hitVec, _distCutForFTDHits); } } } - - - - if (_assignVTXHits>0) { // Treatment of left-over VTX hits - + + if (_assignVTXHits > 0) { // Treatment of left-over VTX hits + streamlog_out(DEBUG4) << "Assign VXD hits *********************************" << std::endl; - + std::vector nonAssignedVTXHits; nonAssignedVTXHits.resize(_nLayersVTX); - + int nVTXHits = int(_allVTXHits.size()); - + // loop over all VXD hits ... - for (int iH=0;iHgetTrackExtended(); - + for (int iH = 0; iH < nVTXHits; ++iH) { + + TrackerHitExtended* trkHitExt = _allVTXHits[iH]; + TrackExtended* trkExt = trkHitExt->getTrackExtended(); + // check if this hit has not already been assigned to a track if (trkExt == NULL) { - TrackerHit * trkHit = trkHitExt->getTrackerHit(); - + TrackerHit* trkHit = trkHitExt->getTrackerHit(); + int layer = getLayerID(trkHit); - - if (layer >=0 && layer < (int)_nLayersVTX) + + if (layer >= 0 && layer < (int)_nLayersVTX) nonAssignedVTXHits[layer].push_back(trkHitExt); } } - for (int iL=_nLayersVTX-1;iL>=0;--iL) { - if ( nonAssignedVTXHits[iL].empty() == false ) { - + for (int iL = _nLayersVTX - 1; iL >= 0; --iL) { + if (nonAssignedVTXHits[iL].empty() == false) { + TrackerHitExtendedVec hitVec = nonAssignedVTXHits[iL]; - streamlog_out(DEBUG3) << "AddNotAssignedHits : Try to assign hits from layer " << iL << " : Number of hits = " << hitVec.size() << std::endl; - AssignSiHitsToTracks(hitVec, - _distCutForVTXHits); + streamlog_out(DEBUG3) << "AddNotAssignedHits : Try to assign hits from layer " << iL + << " : Number of hits = " << hitVec.size() << std::endl; + AssignSiHitsToTracks(hitVec, _distCutForVTXHits); } } } - + streamlog_out(DEBUG4) << "Assign TPC hits *********************************" << std::endl; - - if (_assignTPCHits) {// Treatment of left-over TPC hits + + if (_assignTPCHits) { // Treatment of left-over TPC hits TrackerHitExtendedVec nonAssignedTPCHits; int nTPCHits = int(_allTPCHits.size()); - for (int iH=0;iHgetTrackExtended(); + for (int iH = 0; iH < nTPCHits; ++iH) { + TrackerHitExtended* trkHitExt = _allTPCHits[iH]; + TrackExtended* trkExt = trkHitExt->getTrackExtended(); if (trkExt == NULL) { nonAssignedTPCHits.push_back(trkHitExt); } } - streamlog_out(DEBUG4) << "AddNotAssignedHits : Number of Non Assigned TPC hits = " << nonAssignedTPCHits.size() << std::endl; - AssignTPCHitsToTracks(nonAssignedTPCHits, - _distCutForTPCHits); + streamlog_out(DEBUG4) << "AddNotAssignedHits : Number of Non Assigned TPC hits = " << nonAssignedTPCHits.size() + << std::endl; + AssignTPCHitsToTracks(nonAssignedTPCHits, _distCutForTPCHits); } - - } - void FPCCDFullLDCTracking_MarlinTrk::CreateExtrapolations() { - + _trackExtrapolatedHelix.clear(); - + int nTrk = int(_trkImplVec.size()); - for (int iTrk=0; iTrkgetDistanceToPoint(pos,dcut); - + + float distance = helix->getDistanceToPoint(pos, dcut); + streamlog_out(DEBUG1) << "for helix extrapolation " << helix << " distance = " << distance << std::endl; - + // check the distance is less than the steerable cut ... - if (distancegetTrackerHit(); + TrackerHit* remainHit = trkHitExt->getTrackerHit(); iHitInFit++; trkHits.push_back(remainHit); - - + double chi2_D; int ndf; - - - if( trkHits.size() < 3 ) return ; - + + if (trkHits.size() < 3) + return; + // sort the hits in R - std::vector< std::pair > r2_values; + std::vector> r2_values; r2_values.reserve(trkHits.size()); - - for (TrackerHitVec::iterator it=trkHits.begin(); it!=trkHits.end(); ++it) { + + for (TrackerHitVec::iterator it = trkHits.begin(); it != trkHits.end(); ++it) { EVENT::TrackerHit* h = *it; - float r2 = h->getPosition()[0]*h->getPosition()[0]+h->getPosition()[1]*h->getPosition()[1]; + float r2 = h->getPosition()[0] * h->getPosition()[0] + h->getPosition()[1] * h->getPosition()[1]; r2_values.push_back(std::make_pair(r2, *it)); } - - sort(r2_values.begin(),r2_values.end()); - + + sort(r2_values.begin(), r2_values.end()); + trkHits.clear(); trkHits.reserve(r2_values.size()); - - for (std::vector< std::pair >::iterator it=r2_values.begin(); it!=r2_values.end(); ++it) { + + for (std::vector>::iterator it = r2_values.begin(); + it != r2_values.end(); ++it) { trkHits.push_back(it->second); } - - - streamlog_out(DEBUG3) << "AssignOuterHitsToTracks: Start Fitting: AddHits: number of hits to fit " << trkHits.size() << std::endl; - - + + streamlog_out(DEBUG3) << "AssignOuterHitsToTracks: Start Fitting: AddHits: number of hits to fit " + << trkHits.size() << std::endl; + MarlinTrk::IMarlinTrack* marlin_trk = _trksystem->createTrack(); - - IMPL::TrackStateImpl pre_fit ; - - + + IMPL::TrackStateImpl pre_fit; + pre_fit.setD0(trkExt->getD0()); pre_fit.setPhi(trkExt->getPhi()); pre_fit.setZ0(trkExt->getZ0()); pre_fit.setOmega(trkExt->getOmega()); pre_fit.setTanLambda(trkExt->getTanLambda()); - + float ref[3]; - ref[0]=ref[1]=ref[2]=0.0; - + ref[0] = ref[1] = ref[2] = 0.0; + pre_fit.setReferencePoint(ref); - - pre_fit.setLocation(lcio::TrackStateImpl::AtIP); + + pre_fit.setLocation(lcio::TrackStateImpl::AtIP); // setup initial dummy covariance matrix EVENT::FloatVec covMatrix; covMatrix.resize(15); - - for (unsigned icov = 0; icov > outliers ; + + std::vector> outliers; marlin_trk->getOutliers(outliers); - - float outlier_pct = outliers.size()/float(trkHits.size()) ; - - streamlog_out(DEBUG1) << "FPCCDFullLDCTracking_MarlinTrk::AssignOuterHitsToTracks: percentage of outliers " << outlier_pct << std::endl; - - if ( outlier_pct > _maxAllowedPercentageOfOutliersForTrackCombination) { - - streamlog_out(DEBUG2) << "FPCCDFullLDCTracking_MarlinTrk::AssignOuterHitsToTracks: percentage of outliers " << outlier_pct << " is greater than cut maximum: " << _maxAllowedPercentageOfOutliersForTrackCombination << std::endl; - delete marlin_trk ; - continue ; + float outlier_pct = outliers.size() / float(trkHits.size()); + + streamlog_out(DEBUG1) << "FPCCDFullLDCTracking_MarlinTrk::AssignOuterHitsToTracks: percentage of outliers " + << outlier_pct << std::endl; + + if (outlier_pct > _maxAllowedPercentageOfOutliersForTrackCombination) { + + streamlog_out(DEBUG2) << "FPCCDFullLDCTracking_MarlinTrk::AssignOuterHitsToTracks: percentage of outliers " + << outlier_pct << " is greater than cut maximum: " + << _maxAllowedPercentageOfOutliersForTrackCombination << std::endl; + delete marlin_trk; + continue; } - - const Vector3D point(0.,0.,0.); // nominal IP - - TrackStateImpl trkState ; + + const Vector3D point(0., 0., 0.); // nominal IP + + TrackStateImpl trkState; // int return_code = - marlin_trk->propagate(point, trkState, chi2_D, ndf ) ; - - delete marlin_trk ; - - if ( error != IMarlinTrack::success ) { - - streamlog_out(DEBUG3) << "FPCCDFullLDCTracking_MarlinTrk::AssignOuterHitsToTracks: propagate to IP fails with error " << error << std::endl; - - continue ; - + marlin_trk->propagate(point, trkState, chi2_D, ndf); + + delete marlin_trk; + + if (error != IMarlinTrack::success) { + + streamlog_out(DEBUG3) + << "FPCCDFullLDCTracking_MarlinTrk::AssignOuterHitsToTracks: propagate to IP fails with error " << error + << std::endl; + + continue; } - - if ( ndf < 0 ) { - - streamlog_out(DEBUG2) << "FPCCDFullLDCTracking_MarlinTrk::AssignOuterHitsToTracks: Fit failed : NDF is less that zero " << ndf << std::endl; - - continue ; - + + if (ndf < 0) { + + streamlog_out(DEBUG2) + << "FPCCDFullLDCTracking_MarlinTrk::AssignOuterHitsToTracks: Fit failed : NDF is less that zero " + << ndf << std::endl; + + continue; } - - - float chi2Fit = chi2_D/float(ndf); - - if ( chi2Fit > _chi2FitCut ) { - - streamlog_out(DEBUG2) << "FPCCDFullLDCTracking_MarlinTrk::AssignOuterHitsToTracks: track fail Chi2 cut of " << _chi2FitCut << " chi2 of track = " << chi2Fit << std::endl; - - return ; - + + float chi2Fit = chi2_D / float(ndf); + + if (chi2Fit > _chi2FitCut) { + + streamlog_out(DEBUG2) << "FPCCDFullLDCTracking_MarlinTrk::AssignOuterHitsToTracks: track fail Chi2 cut of " + << _chi2FitCut << " chi2 of track = " << chi2Fit << std::endl; + + return; } - - - + // note trackAR which is of type TrackExtended, only takes fits with ref point = 0,0,0 trkExt->setOmega(trkState.getOmega()); trkExt->setTanLambda(trkState.getTanLambda()); trkExt->setPhi(trkState.getPhi()); trkExt->setD0(trkState.getD0()); trkExt->setZ0(trkState.getZ0()); - - + float cov[15]; - - for (int i = 0 ; i<15 ; ++i) { + + for (int i = 0; i < 15; ++i) { cov[i] = trkState.getCovMatrix().operator[](i); } - + trkExt->setCovMatrix(cov); trkExt->setChi2(chi2_D); trkExt->setNDF(ndf); - - trkExt->addTrackerHitExtended( trkHitExt ); - trkHitExt->setTrackExtended( trkExt ); - trkHitExt->setUsedInFit( true ); + + trkExt->addTrackerHitExtended(trkHitExt); + trkHitExt->setTrackExtended(trkExt); + trkHitExt->setUsedInFit(true); flagTrack[trkExt] = false; flagHit[trkHitExt] = false; - - - streamlog_out(DEBUG2) << "AssignOuterHitsToTracks: Hit " << trkHitExt << " successfully assigned to track " << trkExt << std::endl; - - + streamlog_out(DEBUG2) << "AssignOuterHitsToTracks: Hit " << trkHitExt << " successfully assigned to track " + << trkExt << std::endl; } } } - - for (int iP=0;iPgetGroupTracks(); - + TrackExtendedVec trk_vec = group->getTrackExtendedVec(); - + const EVENT::TrackState* ts_at_calo = 0; float z_ref_max = 0; - - streamlog_out(DEBUG3) << "FPCCDFullLDCTracking_MarlinTrk::GetExtrapolationHelix number of tracks associated = " << trk_vec.size() << std::endl; - - for (unsigned itrk=0; itrkInitialize_Canonical(ts_at_calo_forIP.getPhi(), ts_at_calo_forIP.getD0(), ts_at_calo_forIP.getZ0(), + ts_at_calo_forIP.getOmega(), ts_at_calo_forIP.getTanLambda(), _bField); + + streamlog_out(DEBUG3) << "FPCCDFullLDCTracking_MarlinTrk::GetExtrapolationHelix helix created at IP" << std::endl; } - + return helix; - } +void FPCCDFullLDCTracking_MarlinTrk::AssignTPCHitsToTracks(TrackerHitExtendedVec hitVec, float dcut) { -void FPCCDFullLDCTracking_MarlinTrk::AssignTPCHitsToTracks(TrackerHitExtendedVec hitVec, - float dcut) { - int nHits = int(hitVec.size()); int nTrk = int(_trkImplVec.size()); - - for (int iT=0;iTgetGroupTracks(); + + for (int iT = 0; iT < nTrk; ++iT) { // loop over all tracks + TrackExtended* foundTrack = _trkImplVec[iT]; + GroupTracks* group = foundTrack->getGroupTracks(); TrackExtendedVec tracksInGroup = group->getTrackExtendedVec(); int nTrkGrp = int(tracksInGroup.size()); - for (int iTrkGrp=0;iTrkGrpgetTrackerHitExtendedVec(); int nHits_Grp = int(hitVecGrp.size()); float zMin = 1.0e+20; float zMax = -1.0e+20; - float startPoint[3] = {0.,0.,0.}; - float endPoint[3] = {0.,0.,0.}; - for (int iH=0;iHgetTrackerHit()->getPosition()[iC]); - if (pos[2]>zMax) { + float startPoint[3] = {0., 0., 0.}; + float endPoint[3] = {0., 0., 0.}; + for (int iH = 0; iH < nHits_Grp; ++iH) { + TrackerHitExtended* trkHitExt = hitVecGrp[iH]; + float pos[3] = {0., 0., 0.}; + for (int iC = 0; iC < 3; ++iC) + pos[iC] = float(trkHitExt->getTrackerHit()->getPosition()[iC]); + if (pos[2] > zMax) { zMax = pos[2]; - for (int iC=0;iC<3;++iC) - endPoint[iC] = pos[iC]; + for (int iC = 0; iC < 3; ++iC) + endPoint[iC] = pos[iC]; } - if (pos[2]setEnd(endPoint); } } - - + // replace previous version with faster loop ordering - + std::vector minDistances(nHits, dcut); std::vector tracksToAttach(nHits); - std::vector< std::vector > HitPositions(nHits); - std::vector HitSign(nHits);//Positive or Negative side - for (int iH=0;iH> HitPositions(nHits); + std::vector HitSign(nHits); // Positive or Negative side + for (int iH = 0; iH < nHits; ++iH) { // loop over leftover TPC hits + tracksToAttach[iH] = NULL; + // Get all TrackerHit positions, so we only have to get them once TrackerHit* temphit = hitVec[iH]->getTrackerHit(); - const double *temppos = temphit->getPosition(); + const double* temppos = temphit->getPosition(); HitPositions[iH].push_back(float(temppos[0])); HitPositions[iH].push_back(float(temppos[1])); HitPositions[iH].push_back(float(temppos[2])); - HitSign[iH]=std::signbit(temppos[2]); - } - - streamlog_out(DEBUG3) << "AssignTPCHitsToTracks: Starting loop " << nTrk << " tracks and " << nHits << " hits" << std::endl; - - for (int iT=0;iTgetTanLambda());//we only care about positive or negative - GroupTracks * group = foundTrack->getGroupTracks(); + HitSign[iH] = std::signbit(temppos[2]); + } + + streamlog_out(DEBUG3) << "AssignTPCHitsToTracks: Starting loop " << nTrk << " tracks and " << nHits << " hits" + << std::endl; + + for (int iT = 0; iT < nTrk; ++iT) { // loop over all tracks + TrackExtended* foundTrack = _trkImplVec[iT]; + int tanlambdaSign = std::signbit(foundTrack->getTanLambda()); // we only care about positive or negative + GroupTracks* group = foundTrack->getGroupTracks(); TrackExtendedVec tracksInGroup = group->getTrackExtendedVec(); int nTrkGrp = int(tracksInGroup.size()); - - for (int iTrkGrp=0;iTrkGrpgetTanLambda(); float omega = trkGrp->getOmega(); float d0 = trkGrp->getD0(); float z0 = trkGrp->getZ0(); float phi0 = trkGrp->getPhi(); float startPointZ = trkGrp->getStart()[2]; - float endPointZ = trkGrp->getEnd()[2]; + float endPointZ = trkGrp->getEnd()[2]; HelixClass helix; - helix.Initialize_Canonical(phi0,d0,z0,omega,tanLambda,_bField); - float OnePFivehalfPeriodZ = 1.5*fabs(acos(-1.)*tanLambda/omega); - - for (int iH=0;iH=startPointZ) && (HitPositions[iH][2]<=endPointZ) ); - - if(consider){ + consider = consider || ((HitPositions[iH][2] >= startPointZ) && (HitPositions[iH][2] <= endPointZ)); + + if (consider) { float distance = helix.getDistanceToPoint(HitPositions[iH], minDistances[iH]); if (distance < minDistances[iH]) { minDistances[iH] = distance; @@ -4436,25 +4137,24 @@ void FPCCDFullLDCTracking_MarlinTrk::AssignTPCHitsToTracks(TrackerHitExtendedVec } } } // loop over leftover TPC hits - } //groups in tracks - } // loop over all tracks - - for (int iH=0;iHaddTrackerHitExtended(trkHitExt); - trkHitExt->setTrackExtended( tracksToAttach[iH] ); - trkHitExt->setUsedInFit( false ); + trkHitExt->setTrackExtended(tracksToAttach[iH]); + trkHitExt->setUsedInFit(false); } } - + streamlog_out(DEBUG3) << " Fast loop done " << std::endl; - - + // for (int iH=0;iHgetTrackerHit()->getPosition()[ip]); // float minDist = 1.0e+20; // TrackExtended * trackToAttach = NULL; @@ -4499,74 +4199,72 @@ void FPCCDFullLDCTracking_MarlinTrk::AssignTPCHitsToTracks(TrackerHitExtendedVec // } // } // } - + // if (trackToAttach!=NULL) { // trackToAttach->addTrackerHitExtended(hitExt); // hitExt->setTrackExtended( trackToAttach ); // hitExt->setUsedInFit( false ); - // if(trackToAttach!=tracksToAttach[iH])std::cout << " Check Failed" << trackToAttach << " " << tracksToAttach[iH] << std::endl; + // if(trackToAttach!=tracksToAttach[iH])std::cout << " Check Failed" << trackToAttach << " " << tracksToAttach[iH] + // << std::endl; // //} - //else { + // else { /// std::cout << iH << " hit is not assigned : distance to closest track = " << minDist << std::endl; ///} //} - //std::cout << " Slow loop done " << std::endl; - + // std::cout << " Slow loop done " << std::endl; } -void FPCCDFullLDCTracking_MarlinTrk::AssignSiHitsToTracks(TrackerHitExtendedVec hitVec, - float dcut) { - +void FPCCDFullLDCTracking_MarlinTrk::AssignSiHitsToTracks(TrackerHitExtendedVec hitVec, float dcut) { + int nHits = int(hitVec.size()); int nTrk = int(_allNonCombinedTPCTracks.size()); - - streamlog_out(DEBUG3) << "AssignSiHitsToTracks : Number of hits to assign " << hitVec.size() << " : Number of available tracks = " << nTrk << std::endl; - - std::map flagTrack; - std::map flagHit; + + streamlog_out(DEBUG3) << "AssignSiHitsToTracks : Number of hits to assign " << hitVec.size() + << " : Number of available tracks = " << nTrk << std::endl; + + std::map flagTrack; + std::map flagHit; TrackHitPairVec pairs; flagTrack.clear(); flagHit.clear(); pairs.clear(); - - for (int iH=0;iHgetTrackerHit(); - - for (int ip=0;ip<3;++ip) { + TrackerHitExtended* trkHitExt = hitVec[iH]; + TrackerHit* hit = trkHitExt->getTrackerHit(); + + for (int ip = 0; ip < 3; ++ip) { pos[ip] = float(hit->getPosition()[ip]); } - - for (int iT=0;iTgetTanLambda(); - float product = pos[2]*tanLambda; - - streamlog_out(DEBUG0) << "AssignSiHitsToTracks : product = " << product << " z hit = " << pos[2] << std::endl; - - - if (product>0) { - + + for (int iT = 0; iT < nTrk; ++iT) { + + TrackExtended* trkExt = _allNonCombinedTPCTracks[iT]; + + float tanLambda = trkExt->getTanLambda(); + float product = pos[2] * tanLambda; + + streamlog_out(DEBUG0) << "AssignSiHitsToTracks : product = " << product << " z hit = " << pos[2] << std::endl; + + if (product > 0) { + float d0 = trkExt->getD0(); float z0 = trkExt->getZ0(); float phi0 = trkExt->getPhi(); float omega = trkExt->getOmega(); tanLambda = trkExt->getTanLambda(); - + HelixClass helix; - helix.Initialize_Canonical(phi0,d0,z0,omega,tanLambda,_bField); - float distance = helix.getDistanceToPoint(pos,dcut); - + helix.Initialize_Canonical(phi0, d0, z0, omega, tanLambda, _bField); + float distance = helix.getDistanceToPoint(pos, dcut); + streamlog_out(DEBUG0) << "AssignSiHitsToTracks : distance = " << distance << " cut = " << dcut << std::endl; - - if (distancegetTrackerHit(); + + // add the hit to be attached to the vectors + TrackerHit* remainHit = trkHitExt->getTrackerHit(); iHitInFit++; trkHits.push_back(remainHit); - - + double chi2_D; int ndf; - - if( trkHits.size() < 3 ) return ; - + + if (trkHits.size() < 3) + return; + // sort the hits in R - std::vector< std::pair > r2_values; + std::vector> r2_values; r2_values.reserve(trkHits.size()); - - for (TrackerHitVec::iterator it=trkHits.begin(); it!=trkHits.end(); ++it) { + + for (TrackerHitVec::iterator it = trkHits.begin(); it != trkHits.end(); ++it) { EVENT::TrackerHit* h = *it; - float r2 = h->getPosition()[0]*h->getPosition()[0]+h->getPosition()[1]*h->getPosition()[1]; + float r2 = h->getPosition()[0] * h->getPosition()[0] + h->getPosition()[1] * h->getPosition()[1]; r2_values.push_back(std::make_pair(r2, *it)); } - - sort(r2_values.begin(),r2_values.end()); - + + sort(r2_values.begin(), r2_values.end()); + trkHits.clear(); trkHits.reserve(r2_values.size()); - - for (std::vector< std::pair >::iterator it=r2_values.begin(); it!=r2_values.end(); ++it) { + + for (std::vector>::iterator it = r2_values.begin(); it != r2_values.end(); + ++it) { trkHits.push_back(it->second); } - - - streamlog_out(DEBUG2) << "AssignSiHitsToTracks: Start Fitting: AddHits: number of hits to fit " << trkHits.size() << std::endl; - - + + streamlog_out(DEBUG2) << "AssignSiHitsToTracks: Start Fitting: AddHits: number of hits to fit " + << trkHits.size() << std::endl; + MarlinTrk::IMarlinTrack* marlin_trk = _trksystem->createTrack(); - - IMPL::TrackStateImpl pre_fit ; - - + + IMPL::TrackStateImpl pre_fit; + pre_fit.setD0(trkExt->getD0()); pre_fit.setPhi(trkExt->getPhi()); pre_fit.setZ0(trkExt->getZ0()); pre_fit.setOmega(trkExt->getOmega()); pre_fit.setTanLambda(trkExt->getTanLambda()); - + float ref[3]; - ref[0]=ref[1]=ref[2]=0.0; - + ref[0] = ref[1] = ref[2] = 0.0; + pre_fit.setReferencePoint(ref); - + pre_fit.setLocation(lcio::TrackStateImpl::AtIP); - + // setup initial dummy covariance matrix EVENT::FloatVec covMatrix; covMatrix.resize(15); - - for (unsigned icov = 0; icov > outliers ; + + std::vector> outliers; marlin_trk->getOutliers(outliers); - - float outlier_pct = outliers.size()/float(trkHits.size()); - - streamlog_out(DEBUG1) << "FPCCDFullLDCTracking_MarlinTrk::AssignSiHitsToTracks: percentage of outliers " << outlier_pct << std::endl; - - if ( outlier_pct > _maxAllowedPercentageOfOutliersForTrackCombination) { - - streamlog_out(DEBUG2) << "FPCCDFullLDCTracking_MarlinTrk::AssignSiHitsToTracks: percentage of outliers " << outlier_pct << " is greater than cut maximum: " << _maxAllowedPercentageOfOutliersForTrackCombination << std::endl; - delete marlin_trk ; - continue ; - + + float outlier_pct = outliers.size() / float(trkHits.size()); + + streamlog_out(DEBUG1) << "FPCCDFullLDCTracking_MarlinTrk::AssignSiHitsToTracks: percentage of outliers " + << outlier_pct << std::endl; + + if (outlier_pct > _maxAllowedPercentageOfOutliersForTrackCombination) { + + streamlog_out(DEBUG2) << "FPCCDFullLDCTracking_MarlinTrk::AssignSiHitsToTracks: percentage of outliers " + << outlier_pct << " is greater than cut maximum: " + << _maxAllowedPercentageOfOutliersForTrackCombination << std::endl; + delete marlin_trk; + continue; } - - const Vector3D point(0.,0.,0.); // nominal IP - - TrackStateImpl trkState ; + + const Vector3D point(0., 0., 0.); // nominal IP + + TrackStateImpl trkState; // int return_code = - marlin_trk->propagate(point, trkState, chi2_D, ndf ) ; - - delete marlin_trk ; - - if ( error != IMarlinTrack::success ) { - - streamlog_out(DEBUG3) << "FPCCDFullLDCTracking_MarlinTrk::AssignSiHitsToTracks: propagate to IP fails with error " << error << std::endl; - - continue ; - + marlin_trk->propagate(point, trkState, chi2_D, ndf); + + delete marlin_trk; + + if (error != IMarlinTrack::success) { + + streamlog_out(DEBUG3) + << "FPCCDFullLDCTracking_MarlinTrk::AssignSiHitsToTracks: propagate to IP fails with error " << error + << std::endl; + + continue; } - - if ( ndf < 0 ) { - - streamlog_out(DEBUG2) << "FPCCDFullLDCTracking_MarlinTrk::AssignSiHitsToTracks: Fit failed : NDF is less that zero " << ndf << std::endl; - - continue ; - + + if (ndf < 0) { + + streamlog_out(DEBUG2) + << "FPCCDFullLDCTracking_MarlinTrk::AssignSiHitsToTracks: Fit failed : NDF is less that zero " << ndf + << std::endl; + + continue; } - - - float chi2Fit = chi2_D/float(ndf); - - if ( chi2Fit > _chi2FitCut ) { - - streamlog_out(DEBUG2) << "FPCCDFullLDCTracking_MarlinTrk::AssignSiHitsToTracks: track fail Chi2 cut of " << _chi2FitCut << " chi2 of track = " << chi2Fit << std::endl; - - continue ; - + + float chi2Fit = chi2_D / float(ndf); + + if (chi2Fit > _chi2FitCut) { + + streamlog_out(DEBUG2) << "FPCCDFullLDCTracking_MarlinTrk::AssignSiHitsToTracks: track fail Chi2 cut of " + << _chi2FitCut << " chi2 of track = " << chi2Fit << std::endl; + + continue; } - - - - // note trackAR which is of type TrackExtended, only takes fits with ref point = 0,0,0 + + // note trackAR which is of type TrackExtended, only takes fits with ref point = 0,0,0 trkExt->setOmega(trkState.getOmega()); trkExt->setTanLambda(trkState.getTanLambda()); trkExt->setPhi(trkState.getPhi()); trkExt->setD0(trkState.getD0()); trkExt->setZ0(trkState.getZ0()); - - + float cov[15]; - - for (int i = 0 ; i<15 ; ++i) { + + for (int i = 0; i < 15; ++i) { cov[i] = trkState.getCovMatrix().operator[](i); } - + trkExt->setCovMatrix(cov); trkExt->setChi2(chi2_D); trkExt->setNDF(ndf); - - trkExt->addTrackerHitExtended( trkHitExt ); - trkHitExt->setTrackExtended( trkExt ); - trkHitExt->setUsedInFit( true ); + + trkExt->addTrackerHitExtended(trkHitExt); + trkHitExt->setTrackExtended(trkExt); + trkHitExt->setUsedInFit(true); flagTrack[trkExt] = false; flagHit[trkHitExt] = false; - - - streamlog_out(DEBUG2) << "AssignSiHitsToTracks: Hit " << trkHitExt << " successfully assigned to track " << trkExt << std::endl; - + + streamlog_out(DEBUG2) << "AssignSiHitsToTracks: Hit " << trkHitExt << " successfully assigned to track " + << trkExt << std::endl; } } - - for (int iP=0;iPgetTrack(); - Track * secondTrack = secondTrackExt->getTrack(); - - std::string firstColName = _TPCTrackMCPCollName; + + Track* firstTrack = firstTrackExt->getTrack(); + Track* secondTrack = secondTrackExt->getTrack(); + + std::string firstColName = _TPCTrackMCPCollName; std::string secondColName = _TPCTrackMCPCollName; - - if (iopt==1) { + + if (iopt == 1) { secondColName = _SiTrackMCPCollName; - } - else if (iopt==2) { + } else if (iopt == 2) { secondColName = _SiTrackMCPCollName; - } - else if (iopt==3) { + } else if (iopt == 3) { secondColName = _TPCTrackMCPCollName; - } - else if (iopt==4) { + } else if (iopt == 4) { secondColName = _SiTrackMCPCollName; - } - else if (iopt==5) { + } else if (iopt == 5) { secondColName = _TPCTrackMCPCollName; - } - else if (iopt==6) { + } else if (iopt == 6) { secondColName = _SiTrackMCPCollName; - } - else if (iopt==7) { + } else if (iopt == 7) { secondColName = _SiTrackMCPCollName; - } - else if (iopt==8) { + } else if (iopt == 8) { secondColName = _SiTrackMCPCollName; - } - else { + } else { secondColName = _TPCTrackMCPCollName; } - - + // get the relation collections, this should be done only once for each event ... - LCCollection * firstCol = _evt->getCollection(firstColName.c_str()); - LCCollection * secondCol = _evt->getCollection(secondColName.c_str()); - + LCCollection* firstCol = _evt->getCollection(firstColName.c_str()); + LCCollection* secondCol = _evt->getCollection(secondColName.c_str()); + // get navigators LCRelationNavigator firstNav(firstCol); LCRelationNavigator secondNav(secondCol); - // get the MCParticles with the greatest weight for the first track LCObjectVec firstVec = firstNav.getRelatedToObjects(firstTrack); FloatVec firstWeights = firstNav.getRelatedToWeights(firstTrack); - LCObject * firstMCP = NULL; + LCObject* firstMCP = NULL; float firstWght = 0; int nObj = firstVec.size(); - for (int iObj=0;iObjfirstWght) { + for (int iObj = 0; iObj < nObj; ++iObj) { + if (firstWeights[iObj] > firstWght) { firstWght = firstWeights[iObj]; firstMCP = firstVec[iObj]; } } - - + // get the MCParticles with the greatest weight for the second track LCObjectVec secondVec = secondNav.getRelatedToObjects(secondTrack); FloatVec secondWeights = secondNav.getRelatedToWeights(secondTrack); - LCObject * secondMCP = NULL; + LCObject* secondMCP = NULL; float secondWght = 0; nObj = secondVec.size(); - for (int iObj=0;iObjsecondWght) { + for (int iObj = 0; iObj < nObj; ++iObj) { + if (secondWeights[iObj] > secondWght) { secondWght = secondWeights[iObj]; secondMCP = secondVec[iObj]; } } - // get the track parameters for both tracks and get the 3-momentum using the HelixClass float d0First = firstTrackExt->getD0(); @@ -4898,690 +4584,681 @@ void FPCCDFullLDCTracking_MarlinTrk::PrintOutMerging(TrackExtended * firstTrackE float omegaFirst = firstTrackExt->getOmega(); float tanLFirst = firstTrackExt->getTanLambda(); float phi0First = firstTrackExt->getPhi(); - + float d0Second = secondTrackExt->getD0(); float z0Second = secondTrackExt->getZ0(); float omegaSecond = secondTrackExt->getOmega(); float tanLSecond = secondTrackExt->getTanLambda(); - float phi0Second = secondTrackExt->getPhi(); - + float phi0Second = secondTrackExt->getPhi(); + HelixClass firstHelix; - firstHelix.Initialize_Canonical(phi0First,d0First,z0First,omegaFirst,tanLFirst,_bField); + firstHelix.Initialize_Canonical(phi0First, d0First, z0First, omegaFirst, tanLFirst, _bField); float pxFirst = firstHelix.getMomentum()[0]; float pyFirst = firstHelix.getMomentum()[1]; - float pzFirst = firstHelix.getMomentum()[2]; - + float pzFirst = firstHelix.getMomentum()[2]; + HelixClass secondHelix; - secondHelix.Initialize_Canonical(phi0Second,d0Second,z0Second,omegaSecond,tanLSecond,_bField); + secondHelix.Initialize_Canonical(phi0Second, d0Second, z0Second, omegaSecond, tanLSecond, _bField); float pxSecond = secondHelix.getMomentum()[0]; float pySecond = secondHelix.getMomentum()[1]; - float pzSecond = secondHelix.getMomentum()[2]; + float pzSecond = secondHelix.getMomentum()[2]; - // get the momentum differences float dPx = pxFirst + pxSecond; float dPy = pyFirst + pySecond; float dPz = pzFirst + pzSecond; - - float dPplus = sqrt(dPx*dPx+dPy*dPy+dPz*dPz); - + + float dPplus = sqrt(dPx * dPx + dPy * dPy + dPz * dPz); + dPx = pxFirst - pxSecond; dPy = pyFirst - pySecond; dPz = pzFirst - pzSecond; - - float dPminus = sqrt(dPx*dPx+dPy*dPy+dPz*dPz); - + + float dPminus = sqrt(dPx * dPx + dPy * dPy + dPz * dPz); + // get momentum for each track - float pFirst = sqrt(pxFirst * pxFirst+ pyFirst* pyFirst+ pzFirst*pzFirst); - float pSecond = sqrt(pxSecond*pxSecond+pySecond*pySecond+pzSecond*pzSecond); - - float ptFirst = sqrt(pxFirst * pxFirst+ pyFirst* pyFirst); - float ptSecond = sqrt(pxSecond*pxSecond+pySecond*pySecond); - - - const float sigmaPOverPFirst = sqrt( firstTrackExt->getCovMatrix()[5])/fabs(omegaFirst); - const float sigmaPOverPSecond = sqrt(secondTrackExt->getCovMatrix()[5])/fabs(omegaSecond); - - const float sigmaPFirst = pFirst*sigmaPOverPFirst; - const float sigmaPSecond = pSecond*sigmaPOverPSecond; - - + float pFirst = sqrt(pxFirst * pxFirst + pyFirst * pyFirst + pzFirst * pzFirst); + float pSecond = sqrt(pxSecond * pxSecond + pySecond * pySecond + pzSecond * pzSecond); + + float ptFirst = sqrt(pxFirst * pxFirst + pyFirst * pyFirst); + float ptSecond = sqrt(pxSecond * pxSecond + pySecond * pySecond); + + const float sigmaPOverPFirst = sqrt(firstTrackExt->getCovMatrix()[5]) / fabs(omegaFirst); + const float sigmaPOverPSecond = sqrt(secondTrackExt->getCovMatrix()[5]) / fabs(omegaSecond); + + const float sigmaPFirst = pFirst * sigmaPOverPFirst; + const float sigmaPSecond = pSecond * sigmaPOverPSecond; + float den = pFirst; - if (pSecond" << std::endl; - } - else if (iopt==2) { - streamlog_out(DEBUG4) << "Erroneous merging of Si and TPC segments (iopt=2) mcp first = " << firstMCP << " mcp second = " << secondMCP << " --->" << std::endl; - } - else if (iopt==3) { - streamlog_out(DEBUG4) << "Erroneous merging of TPC segments (iopt=3) mcp first = " << firstMCP << " mcp second = " << secondMCP << " ---> " << std::endl; - } - else if (iopt==4) { - streamlog_out(DEBUG4) << "Erroneous merging of combSi segment with uncombTPC segment (iopt=4) mcp first = " << firstMCP << " mcp second = " << secondMCP << " ---> " << std::endl; - } - else { - streamlog_out(DEBUG4) << "Erroneous merging of combTPC segment with uncombTPC segment (iopt=5) mcp first = " << firstMCP << " mcp second = " << secondMCP << " --->" << std::endl; + if (firstMCP != secondMCP && iopt < 6) { + + if (iopt == 1) { + streamlog_out(DEBUG4) << "Erroneous merging of Si and TPC segments (iopt=1) mcp first = " << firstMCP + << " mcp second = " << secondMCP << " --->" << std::endl; + } else if (iopt == 2) { + streamlog_out(DEBUG4) << "Erroneous merging of Si and TPC segments (iopt=2) mcp first = " << firstMCP + << " mcp second = " << secondMCP << " --->" << std::endl; + } else if (iopt == 3) { + streamlog_out(DEBUG4) << "Erroneous merging of TPC segments (iopt=3) mcp first = " << firstMCP + << " mcp second = " << secondMCP << " ---> " << std::endl; + } else if (iopt == 4) { + streamlog_out(DEBUG4) << "Erroneous merging of combSi segment with uncombTPC segment (iopt=4) mcp first = " + << firstMCP << " mcp second = " << secondMCP << " ---> " << std::endl; + } else { + streamlog_out(DEBUG4) << "Erroneous merging of combTPC segment with uncombTPC segment (iopt=5) mcp first = " + << firstMCP << " mcp second = " << secondMCP << " --->" << std::endl; } - - - streamlog_out(DEBUG4) << " p error pt D0 Z0 Px Py Pz wieght" << std::endl; - - sprintf(strg,"%7.2f +- %7.2f %7.2f %7.1f %7.1f %7.2f %7.2f %7.2f ", - pFirst, sigmaPFirst, ptFirst, d0First,z0First,pxFirst,pyFirst,pzFirst); + + streamlog_out(DEBUG4) << " p error pt D0 Z0 Px Py Pz wieght" + << std::endl; + + sprintf(strg, "%7.2f +- %7.2f %7.2f %7.1f %7.1f %7.2f %7.2f %7.2f ", pFirst, sigmaPFirst, ptFirst, d0First, + z0First, pxFirst, pyFirst, pzFirst); streamlog_out(DEBUG4) << strg; - - sprintf(strg," %5.3f\n",firstWght); + + sprintf(strg, " %5.3f\n", firstWght); streamlog_out(DEBUG4) << strg; - - - sprintf(strg,"%7.2f +- %7.2f %7.2f %7.1f %7.1f %7.2f %7.2f %7.2f ", - pSecond, sigmaPSecond, ptSecond, d0Second,z0Second,pxSecond,pySecond,pzSecond); + + sprintf(strg, "%7.2f +- %7.2f %7.2f %7.1f %7.1f %7.2f %7.2f %7.2f ", pSecond, sigmaPSecond, ptSecond, + d0Second, z0Second, pxSecond, pySecond, pzSecond); streamlog_out(DEBUG4) << strg; - sprintf(strg," %5.3f\n",secondWght); + sprintf(strg, " %5.3f\n", secondWght); streamlog_out(DEBUG4) << strg; - + streamlog_out(DEBUG4) << "Difference in +P = " << dPplus << " -P = " << dPminus << std::endl; - - TrackExtended * combinedTrack = CombineTracks(firstTrackExt,secondTrackExt, _maxAllowedPercentageOfOutliersForTrackCombination, true); - - if(combinedTrack != NULL){ - streamlog_out(DEBUG4) << "CombinedTrack " << combinedTrack->getNDF() << " c.f. " << firstTrackExt->getNDF()+secondTrackExt->getNDF()+5 << std::endl; + + TrackExtended* combinedTrack = + CombineTracks(firstTrackExt, secondTrackExt, _maxAllowedPercentageOfOutliersForTrackCombination, true); + + if (combinedTrack != NULL) { + streamlog_out(DEBUG4) << "CombinedTrack " << combinedTrack->getNDF() << " c.f. " + << firstTrackExt->getNDF() + secondTrackExt->getNDF() + 5 << std::endl; delete combinedTrack->getGroupTracks(); delete combinedTrack; - }else{ + } else { streamlog_out(DEBUG4) << "Could not combine track " << std::endl; } - streamlog_out(DEBUG4) << " Overlap = " << SegmentRadialOverlap(firstTrackExt, secondTrackExt) << " veto = " << VetoMerge(firstTrackExt, secondTrackExt) << std::endl; - + streamlog_out(DEBUG4) << " Overlap = " << SegmentRadialOverlap(firstTrackExt, secondTrackExt) + << " veto = " << VetoMerge(firstTrackExt, secondTrackExt) << std::endl; + streamlog_out(DEBUG4) << std::endl; - + } - + // ... or if it was an incorrect TPC to TPC rejection ... - else if (firstMCP==secondMCP && ( (iopt==8) || (iopt==9) ) ) { - + else if (firstMCP == secondMCP && ((iopt == 8) || (iopt == 9))) { + float deltaOmega = _dOmegaForMerging; float deltaAngle = _angleForMerging; - if (iopt==8) { + if (iopt == 8) { streamlog_out(DEBUG4) << "Unmerged TPC and Comb segments (iopt=8) --->" << std::endl; - } - else { + } else { streamlog_out(DEBUG4) << "Unmerged TPC segments (iopt=9) --->" << std::endl; } - + float qFirst = PIOVER2 - atan(tanLFirst); float qSecond = PIOVER2 - atan(tanLSecond); - float dOmega = fabs((omegaFirst-omegaSecond)/omegaSecond); - float angle = (cos(phi0First)*cos(phi0Second)+sin(phi0First)*sin(phi0Second))* - sin(qFirst)*sin(qSecond)+cos(qFirst)*cos(qSecond); + float dOmega = fabs((omegaFirst - omegaSecond) / omegaSecond); + float angle = (cos(phi0First) * cos(phi0Second) + sin(phi0First) * sin(phi0Second)) * sin(qFirst) * sin(qSecond) + + cos(qFirst) * cos(qSecond); angle = acos(angle); - - - streamlog_out(DEBUG4) << " dOmegaCut = " << deltaOmega - << " AngleCut = " << deltaAngle - << " dOmega = " << dOmega - << " angle = " << angle << std::endl; - - - streamlog_out(DEBUG4) << " p error pt D0 Z0 Px Py Pz wieght" << std::endl; - - sprintf(strg,"%7.2f +- %7.2f %7.2f %7.1f %7.1f %7.2f %7.2f %7.2f ", - pFirst, sigmaPFirst, ptFirst, d0First,z0First,pxFirst,pyFirst,pzFirst); + + streamlog_out(DEBUG4) << " dOmegaCut = " << deltaOmega << " AngleCut = " << deltaAngle << " dOmega = " << dOmega + << " angle = " << angle << std::endl; + + streamlog_out(DEBUG4) << " p error pt D0 Z0 Px Py Pz wieght" + << std::endl; + + sprintf(strg, "%7.2f +- %7.2f %7.2f %7.1f %7.1f %7.2f %7.2f %7.2f ", pFirst, sigmaPFirst, ptFirst, d0First, + z0First, pxFirst, pyFirst, pzFirst); streamlog_out(DEBUG4) << strg; - sprintf(strg," %5.3f\n",firstWght); + sprintf(strg, " %5.3f\n", firstWght); streamlog_out(DEBUG4) << strg; - - sprintf(strg,"%7.2f +- %7.2f %7.2f %7.1f %7.1f %7.2f %7.2f %7.2f ", - pSecond, sigmaPSecond, ptSecond, d0Second,z0Second,pxSecond,pySecond,pzSecond); + sprintf(strg, "%7.2f +- %7.2f %7.2f %7.1f %7.1f %7.2f %7.2f %7.2f ", pSecond, sigmaPSecond, ptSecond, + d0Second, z0Second, pxSecond, pySecond, pzSecond); streamlog_out(DEBUG4) << strg; - sprintf(strg," %5.3f\n",secondWght); + sprintf(strg, " %5.3f\n", secondWght); streamlog_out(DEBUG4) << strg; - + streamlog_out(DEBUG4) << "Difference in +P = " << dPplus << " -P = " << dPminus << std::endl; - - TrackExtended * combinedTrack = CombineTracks(firstTrackExt,secondTrackExt, _maxAllowedPercentageOfOutliersForTrackCombination, true); - if(combinedTrack != NULL){ - streamlog_out(DEBUG4) << "CombinedTrack " << combinedTrack->getNDF() << " c.f. " << firstTrackExt->getNDF()+secondTrackExt->getNDF()+5 << std::endl; + + TrackExtended* combinedTrack = + CombineTracks(firstTrackExt, secondTrackExt, _maxAllowedPercentageOfOutliersForTrackCombination, true); + if (combinedTrack != NULL) { + streamlog_out(DEBUG4) << "CombinedTrack " << combinedTrack->getNDF() << " c.f. " + << firstTrackExt->getNDF() + secondTrackExt->getNDF() + 5 << std::endl; delete combinedTrack->getGroupTracks(); delete combinedTrack; - }else{ + } else { streamlog_out(DEBUG4) << "Could not combine track " << std::endl; } - streamlog_out(DEBUG4) << " Overlap = " << SegmentRadialOverlap(firstTrackExt, secondTrackExt) << " veto = " << VetoMerge(firstTrackExt, secondTrackExt) << std::endl; - + streamlog_out(DEBUG4) << " Overlap = " << SegmentRadialOverlap(firstTrackExt, secondTrackExt) + << " veto = " << VetoMerge(firstTrackExt, secondTrackExt) << std::endl; + streamlog_out(DEBUG4) << std::endl; - - } + + } // ... or if it was an incorrect TPC to Si rejection ... - else if (firstMCP==secondMCP && ( (iopt == 6) || (iopt == 7) ) ) { - + else if (firstMCP == secondMCP && ((iopt == 6) || (iopt == 7))) { + float deltaOmega = _dOmegaForMerging; float deltaAngle = _angleForMerging; - - if (iopt ==6) { - streamlog_out(DEBUG4) << "Unmerged TPC and Si segments (iopt=6) mcp first = " << firstMCP << " mcp second = " << secondMCP << " --->" << std::endl; - } - else { - streamlog_out(DEBUG4) << "Unmerged TPC and Si segments (iopt=7) mcp first = " << firstMCP << " mcp second = " << secondMCP << " --->" << std::endl; + + if (iopt == 6) { + streamlog_out(DEBUG4) << "Unmerged TPC and Si segments (iopt=6) mcp first = " << firstMCP + << " mcp second = " << secondMCP << " --->" << std::endl; + } else { + streamlog_out(DEBUG4) << "Unmerged TPC and Si segments (iopt=7) mcp first = " << firstMCP + << " mcp second = " << secondMCP << " --->" << std::endl; deltaOmega = _dOmegaForForcedMerging; deltaAngle = _angleForForcedMerging; } - + float qFirst = PIOVER2 - atan(tanLFirst); float qSecond = PIOVER2 - atan(tanLSecond); - - float dOmega = fabs((omegaFirst-omegaSecond)/omegaSecond); - float angle = (cos(phi0First)*cos(phi0Second)+sin(phi0First)*sin(phi0Second))* - sin(qFirst)*sin(qSecond)+cos(qFirst)*cos(qSecond); + + float dOmega = fabs((omegaFirst - omegaSecond) / omegaSecond); + float angle = (cos(phi0First) * cos(phi0Second) + sin(phi0First) * sin(phi0Second)) * sin(qFirst) * sin(qSecond) + + cos(qFirst) * cos(qSecond); angle = acos(angle); - - - streamlog_out(DEBUG4) << " dOmegaCut = " << deltaOmega - << " AngleCut = " << deltaAngle - << " dOmega = " << dOmega - << " angle = " << angle << std::endl; - - streamlog_out(DEBUG4) << " p error pt D0 Z0 Px Py Pz wieght" << std::endl; - - sprintf(strg,"%7.2f +- %7.2f %7.2f %7.1f %7.1f %7.2f %7.2f %7.2f ", - pFirst, sigmaPFirst, ptFirst, d0First,z0First,pxFirst,pyFirst,pzFirst); + + streamlog_out(DEBUG4) << " dOmegaCut = " << deltaOmega << " AngleCut = " << deltaAngle << " dOmega = " << dOmega + << " angle = " << angle << std::endl; + + streamlog_out(DEBUG4) << " p error pt D0 Z0 Px Py Pz wieght" + << std::endl; + + sprintf(strg, "%7.2f +- %7.2f %7.2f %7.1f %7.1f %7.2f %7.2f %7.2f ", pFirst, sigmaPFirst, ptFirst, d0First, + z0First, pxFirst, pyFirst, pzFirst); streamlog_out(DEBUG4) << strg; - sprintf(strg," %5.3f\n",firstWght); + sprintf(strg, " %5.3f\n", firstWght); streamlog_out(DEBUG4) << strg; - sprintf(strg,"%7.2f +- %7.2f %7.2f %7.1f %7.1f %7.2f %7.2f %7.2f ", - pSecond, sigmaPSecond, ptSecond, d0Second,z0Second,pxSecond,pySecond,pzSecond); + sprintf(strg, "%7.2f +- %7.2f %7.2f %7.1f %7.1f %7.2f %7.2f %7.2f ", pSecond, sigmaPSecond, ptSecond, + d0Second, z0Second, pxSecond, pySecond, pzSecond); streamlog_out(DEBUG4) << strg; - sprintf(strg," %5.3f\n",secondWght); + sprintf(strg, " %5.3f\n", secondWght); streamlog_out(DEBUG4) << strg; - - streamlog_out(DEBUG4) << "Difference in +P = " << dPplus << " -P = " << dPminus << std::endl; - - TrackExtended * combinedTrack = CombineTracks(firstTrackExt,secondTrackExt, _maxAllowedPercentageOfOutliersForTrackCombination, true); - - if(combinedTrack != NULL){ - streamlog_out(DEBUG4) << "CombinedTrack " << combinedTrack->getNDF() << " c.f. " << firstTrackExt->getNDF()+secondTrackExt->getNDF()+5 << std::endl; + + streamlog_out(DEBUG4) << "Difference in +P = " << dPplus << " -P = " << dPminus << std::endl; + + TrackExtended* combinedTrack = + CombineTracks(firstTrackExt, secondTrackExt, _maxAllowedPercentageOfOutliersForTrackCombination, true); + + if (combinedTrack != NULL) { + streamlog_out(DEBUG4) << "CombinedTrack " << combinedTrack->getNDF() << " c.f. " + << firstTrackExt->getNDF() + secondTrackExt->getNDF() + 5 << std::endl; delete combinedTrack->getGroupTracks(); delete combinedTrack; - }else{ + } else { streamlog_out(DEBUG4) << "Could not combine track " << std::endl; } - streamlog_out(DEBUG4) << " Overlap = " << SegmentRadialOverlap(firstTrackExt, secondTrackExt) << " veto = " << VetoMerge(firstTrackExt, secondTrackExt) << std::endl; - streamlog_out(DEBUG4) << std::endl; - + streamlog_out(DEBUG4) << " Overlap = " << SegmentRadialOverlap(firstTrackExt, secondTrackExt) + << " veto = " << VetoMerge(firstTrackExt, secondTrackExt) << std::endl; + streamlog_out(DEBUG4) << std::endl; + } // ... or if it was an correct merger ... - else if (firstMCP==secondMCP && iopt < 6 && _debug > 3) { + else if (firstMCP == secondMCP && iopt < 6 && _debug > 3) { // return; - if (iopt==1) { - streamlog_out(DEBUG4) << "Correctly combining Si and TPC segments (iopt=1) mcp first = " << firstMCP << " mcp second = " << secondMCP << " --->" << std::endl; - } - else if (iopt==2) { - streamlog_out(DEBUG4) << "Correctly merging of Si and TPC segments (iopt=2) mcp first = " << firstMCP << " mcp second = " << secondMCP << " --->" << std::endl; - } - else if (iopt==3) { - streamlog_out(DEBUG4) << "Correctly merging of TPC segments (iopt=3) mcp first = " << firstMCP << " mcp second = " << secondMCP << " ---> " << std::endl; - } - else if (iopt==4) { - streamlog_out(DEBUG4) << "Correctly merging of combSi segment with uncombTPC segment (iopt=4) mcp first = " << firstMCP << " mcp second = " << secondMCP << " ---> " << std::endl; - } - else { - streamlog_out(DEBUG4) << "Correctly merging of combTPC segment with uncombTPC segment (iopt=5) mcp first = " << firstMCP << " mcp second = " << secondMCP << " --->" << std::endl; + if (iopt == 1) { + streamlog_out(DEBUG4) << "Correctly combining Si and TPC segments (iopt=1) mcp first = " << firstMCP + << " mcp second = " << secondMCP << " --->" << std::endl; + } else if (iopt == 2) { + streamlog_out(DEBUG4) << "Correctly merging of Si and TPC segments (iopt=2) mcp first = " << firstMCP + << " mcp second = " << secondMCP << " --->" << std::endl; + } else if (iopt == 3) { + streamlog_out(DEBUG4) << "Correctly merging of TPC segments (iopt=3) mcp first = " << firstMCP + << " mcp second = " << secondMCP << " ---> " << std::endl; + } else if (iopt == 4) { + streamlog_out(DEBUG4) << "Correctly merging of combSi segment with uncombTPC segment (iopt=4) mcp first = " + << firstMCP << " mcp second = " << secondMCP << " ---> " << std::endl; + } else { + streamlog_out(DEBUG4) << "Correctly merging of combTPC segment with uncombTPC segment (iopt=5) mcp first = " + << firstMCP << " mcp second = " << secondMCP << " --->" << std::endl; } - streamlog_out(DEBUG4) << " p error pt D0 Z0 Px Py Pz wieght" << std::endl; - - sprintf(strg,"%7.2f +- %7.2f %7.2f %7.1f %7.1f %7.2f %7.2f %7.2f ", - pFirst, sigmaPFirst, ptFirst, d0First,z0First,pxFirst,pyFirst,pzFirst); + streamlog_out(DEBUG4) << " p error pt D0 Z0 Px Py Pz wieght" + << std::endl; + + sprintf(strg, "%7.2f +- %7.2f %7.2f %7.1f %7.1f %7.2f %7.2f %7.2f ", pFirst, sigmaPFirst, ptFirst, d0First, + z0First, pxFirst, pyFirst, pzFirst); streamlog_out(DEBUG4) << strg; - sprintf(strg," %5.3f\n",firstWght); + sprintf(strg, " %5.3f\n", firstWght); streamlog_out(DEBUG4) << strg; - - sprintf(strg,"%7.2f +- %7.2f %7.2f %7.1f %7.1f %7.2f %7.2f %7.2f ", - pSecond, sigmaPSecond, ptSecond, d0Second,z0Second,pxSecond,pySecond,pzSecond); + + sprintf(strg, "%7.2f +- %7.2f %7.2f %7.1f %7.1f %7.2f %7.2f %7.2f ", pSecond, sigmaPSecond, ptSecond, + d0Second, z0Second, pxSecond, pySecond, pzSecond); streamlog_out(DEBUG4) << strg; - sprintf(strg," %5.3f\n",secondWght); + sprintf(strg, " %5.3f\n", secondWght); streamlog_out(DEBUG4) << strg; - + streamlog_out(DEBUG4) << "Difference in +P = " << dPplus << " -P = " << dPminus << std::endl; - TrackExtended * combinedTrack = CombineTracks(firstTrackExt,secondTrackExt, _maxAllowedPercentageOfOutliersForTrackCombination, true); - - if(combinedTrack != NULL){ - streamlog_out(DEBUG4) << "CombinedTrack " << combinedTrack->getNDF() << " c.f. " << firstTrackExt->getNDF()+secondTrackExt->getNDF()+5 << std::endl; - }else{ + TrackExtended* combinedTrack = + CombineTracks(firstTrackExt, secondTrackExt, _maxAllowedPercentageOfOutliersForTrackCombination, true); + + if (combinedTrack != NULL) { + streamlog_out(DEBUG4) << "CombinedTrack " << combinedTrack->getNDF() << " c.f. " + << firstTrackExt->getNDF() + secondTrackExt->getNDF() + 5 << std::endl; + } else { streamlog_out(DEBUG4) << "Could not combine track " << std::endl; } delete combinedTrack->getGroupTracks(); delete combinedTrack; - streamlog_out(DEBUG4) << " Overlap = " << SegmentRadialOverlap(firstTrackExt, secondTrackExt) << " veto = " << VetoMerge(firstTrackExt, secondTrackExt) << std::endl; - + streamlog_out(DEBUG4) << " Overlap = " << SegmentRadialOverlap(firstTrackExt, secondTrackExt) + << " veto = " << VetoMerge(firstTrackExt, secondTrackExt) << std::endl; + streamlog_out(DEBUG4) << std::endl; - } } - - catch(DataNotAvailableException &e){}; - -} -void FPCCDFullLDCTracking_MarlinTrk::GeneralSorting(int * index, float * val, int direct, int nVal) { + catch (DataNotAvailableException& e) { + }; +} + +void FPCCDFullLDCTracking_MarlinTrk::GeneralSorting(int* index, float* val, int direct, int nVal) { /** Sorting of index vector in ascending (0) /descending (!=0) order of val */ - + float valOne, valTwo, valTemp; - int indTemp; - for (int i=0; i valTwo; - if (direct>0) + if (direct > 0) order = valOne <= valTwo; - if( order ) - { + if (order) { valTemp = val[j]; - val[j] = val[j+1]; - val[j+1] = valTemp; + val[j] = val[j + 1]; + val[j + 1] = valTemp; indTemp = index[j]; - index[j] = index[j+1]; - index[j+1] = indTemp; + index[j] = index[j + 1]; + index[j + 1] = indTemp; } - } + } } - - } -int FPCCDFullLDCTracking_MarlinTrk::SegmentRadialOverlap(TrackExtended* first, TrackExtended* second){ - - +int FPCCDFullLDCTracking_MarlinTrk::SegmentRadialOverlap(TrackExtended* first, TrackExtended* second) { + int nTrkGrpFirst = 0; int nTrkGrpSecond = 0; TrackerHitVec hitvecFirst; TrackerHitVec hitvecSecond; - GroupTracks * groupFirst = first->getGroupTracks(); - GroupTracks * groupSecond = second->getGroupTracks(); - - if(groupFirst!=NULL){ - + GroupTracks* groupFirst = first->getGroupTracks(); + GroupTracks* groupSecond = second->getGroupTracks(); + + if (groupFirst != NULL) { + TrackExtendedVec tracksInGroupFirst = groupFirst->getTrackExtendedVec(); nTrkGrpFirst = int(tracksInGroupFirst.size()); - - for (int iTrkGrp=0;iTrkGrpgetTrackerHitExtendedVec(); - - for(unsigned int i =0; igetTrackerHit()); + + for (unsigned int i = 0; i < hitVec.size(); ++i) { + hitvecFirst.push_back(hitVec[i]->getTrackerHit()); } } } - if(groupSecond!=NULL){ - + if (groupSecond != NULL) { + TrackExtendedVec tracksInGroupSecond = groupSecond->getTrackExtendedVec(); nTrkGrpSecond = int(tracksInGroupSecond.size()); - - for (int iTrkGrp=0;iTrkGrpgetTrackerHitExtendedVec(); - - for(unsigned int i=0;igetTrackerHitExtendedVec(); + + for (unsigned int i = 0; i < hitVec.size(); ++i) { hitvecSecond.push_back(hitVec[i]->getTrackerHit()); } } } - - + int nhitsFirst = (int)hitvecFirst.size(); int nhitsSecond = (int)hitvecSecond.size(); int count = 0; - for(int i =0;igetPosition()[0]; float yi = (float)hitvecFirst[i]->getPosition()[1]; - float ri = sqrt(xi*xi+yi*yi); - if(ri < _tpc_inner_r || ri > _tpc_pad_height)continue; - for(int j =0;j _tpc_pad_height) + continue; + for (int j = 0; j < nhitsSecond; ++j) { float xj = (float)hitvecSecond[j]->getPosition()[0]; float yj = (float)hitvecSecond[j]->getPosition()[1]; - float rj = sqrt(xj*xj+yj*yj); - if(fabs(ri-rj)<_tpc_pad_height/2.0)count++; + float rj = sqrt(xj * xj + yj * yj); + if (fabs(ri - rj) < _tpc_pad_height / 2.0) + count++; } - } + } return count; } /* - + veto merger if the momentum of either track is less than 2.5 GeV or if following a full fit the NDF+10 of the combined tracks is less than the NDF_first + NDF_second - - NOTE: This function will try a full fit using CombineTracks if the momentum of both tracks is greater than VetoMergeMomentumCut - + + NOTE: This function will try a full fit using CombineTracks if the momentum of both tracks is greater than + VetoMergeMomentumCut + */ -bool FPCCDFullLDCTracking_MarlinTrk::VetoMerge(TrackExtended* firstTrackExt, TrackExtended* secondTrackExt){ - - - streamlog_out(DEBUG1) << "FPCCDFullLDCTracking_MarlinTrk::VetoMerge called for " << firstTrackExt << " and " << secondTrackExt << std::endl; - +bool FPCCDFullLDCTracking_MarlinTrk::VetoMerge(TrackExtended* firstTrackExt, TrackExtended* secondTrackExt) { + + streamlog_out(DEBUG1) << "FPCCDFullLDCTracking_MarlinTrk::VetoMerge called for " << firstTrackExt << " and " + << secondTrackExt << std::endl; + const float d0First = firstTrackExt->getD0(); const float z0First = firstTrackExt->getZ0(); const float omegaFirst = firstTrackExt->getOmega(); const float tanLFirst = firstTrackExt->getTanLambda(); const float phi0First = firstTrackExt->getPhi(); - + const float d0Second = secondTrackExt->getD0(); const float z0Second = secondTrackExt->getZ0(); const float omegaSecond = secondTrackExt->getOmega(); const float tanLSecond = secondTrackExt->getTanLambda(); - const float phi0Second = secondTrackExt->getPhi(); - + const float phi0Second = secondTrackExt->getPhi(); + HelixClass firstHelix; - firstHelix.Initialize_Canonical(phi0First,d0First,z0First,omegaFirst,tanLFirst,_bField); + firstHelix.Initialize_Canonical(phi0First, d0First, z0First, omegaFirst, tanLFirst, _bField); const float pxFirst = firstHelix.getMomentum()[0]; const float pyFirst = firstHelix.getMomentum()[1]; - const float pzFirst = firstHelix.getMomentum()[2]; - + const float pzFirst = firstHelix.getMomentum()[2]; + HelixClass secondHelix; - secondHelix.Initialize_Canonical(phi0Second,d0Second,z0Second,omegaSecond,tanLSecond,_bField); + secondHelix.Initialize_Canonical(phi0Second, d0Second, z0Second, omegaSecond, tanLSecond, _bField); const float pxSecond = secondHelix.getMomentum()[0]; const float pySecond = secondHelix.getMomentum()[1]; - const float pzSecond = secondHelix.getMomentum()[2]; - const float pFirst = sqrt(pxFirst*pxFirst+pyFirst*pyFirst+pzFirst*pzFirst); - const float pSecond = sqrt(pxSecond*pxSecond+pySecond*pySecond+pzSecond*pzSecond); - - if(pFirst<_vetoMergeMomentumCut || pSecond<_vetoMergeMomentumCut) { - streamlog_out(DEBUG1) << "FPCCDFullLDCTracking_MarlinTrk::VetoMerge do not veto as below momentum cut of 2.5 : pFirst = " << pFirst << " pSecond = " << pSecond << std::endl; + const float pzSecond = secondHelix.getMomentum()[2]; + const float pFirst = sqrt(pxFirst * pxFirst + pyFirst * pyFirst + pzFirst * pzFirst); + const float pSecond = sqrt(pxSecond * pxSecond + pySecond * pySecond + pzSecond * pzSecond); + + if (pFirst < _vetoMergeMomentumCut || pSecond < _vetoMergeMomentumCut) { + streamlog_out(DEBUG1) + << "FPCCDFullLDCTracking_MarlinTrk::VetoMerge do not veto as below momentum cut of 2.5 : pFirst = " << pFirst + << " pSecond = " << pSecond << std::endl; return false; } bool veto = false; - - bool testCombinationOnly=true; - TrackExtended * combinedTrack = CombineTracks(firstTrackExt,secondTrackExt,_maxAllowedPercentageOfOutliersForTrackCombination,testCombinationOnly); + bool testCombinationOnly = true; + TrackExtended* combinedTrack = CombineTracks(firstTrackExt, secondTrackExt, + _maxAllowedPercentageOfOutliersForTrackCombination, testCombinationOnly); - - if(combinedTrack!=NULL){ - - //SJA:FIXME hardcoded cut: here the check is that no more than 7 hits have been rejected in the combined fit. - if( combinedTrack->getNDF()+15 < firstTrackExt->getNDF() + secondTrackExt->getNDF()+5 ) { - streamlog_out(DEBUG1) << "FPCCDFullLDCTracking_MarlinTrk::VetoMerge fails NDF cut " << std::endl; - veto=true ; + if (combinedTrack != NULL) { + // SJA:FIXME hardcoded cut: here the check is that no more than 7 hits have been rejected in the combined fit. + if (combinedTrack->getNDF() + 15 < firstTrackExt->getNDF() + secondTrackExt->getNDF() + 5) { + streamlog_out(DEBUG1) << "FPCCDFullLDCTracking_MarlinTrk::VetoMerge fails NDF cut " << std::endl; + veto = true; } - + delete combinedTrack->getGroupTracks(); delete combinedTrack; } else { - streamlog_out(DEBUG1) << "FPCCDFullLDCTracking_MarlinTrk::VetoMerge fails CombineTracks(firstTrackExt,secondTrackExt,true) test" << std::endl; + streamlog_out(DEBUG1) + << "FPCCDFullLDCTracking_MarlinTrk::VetoMerge fails CombineTracks(firstTrackExt,secondTrackExt,true) test" + << std::endl; veto = true; } - - if(SegmentRadialOverlap(firstTrackExt,secondTrackExt)>10) { + + if (SegmentRadialOverlap(firstTrackExt, secondTrackExt) > 10) { streamlog_out(DEBUG1) << "FPCCDFullLDCTracking_MarlinTrk::VetoMerge fails SegmentRadialOverlap test " << std::endl; - veto=true; + veto = true; } return veto; - } +void FPCCDFullLDCTracking_MarlinTrk::check(LCEvent*) {} -void FPCCDFullLDCTracking_MarlinTrk::check(LCEvent* ) { } - -void FPCCDFullLDCTracking_MarlinTrk::end() { - +void FPCCDFullLDCTracking_MarlinTrk::end() { delete _moriUtil; delete _purityUtil; - delete _encoder ; - + delete _encoder; } -void FPCCDFullLDCTracking_MarlinTrk::setupGeom( const dd4hep::Detector& theDetector){ - - double bFieldVec[3]; - theDetector.field().magneticField({0,0,0},bFieldVec); // get the magnetic field vector from DD4hep - _bField = bFieldVec[2]/dd4hep::tesla; // z component at (0,0,0) - +void FPCCDFullLDCTracking_MarlinTrk::setupGeom(const dd4hep::Detector& theDetector) { + + double bFieldVec[3]; + theDetector.field().magneticField({0, 0, 0}, bFieldVec); // get the magnetic field vector from DD4hep + _bField = bFieldVec[2] / dd4hep::tesla; // z component at (0,0,0) + //-- VXD Parameters-- - _nLayersVTX = 0 ; - - try{ - - streamlog_out( DEBUG9 ) << " filling VXD parameters " << std::endl ; - + _nLayersVTX = 0; + + try { + + streamlog_out(DEBUG9) << " filling VXD parameters " << std::endl; + dd4hep::DetElement vtxDE = theDetector.detector("VXD"); dd4hep::rec::ZPlanarData* vtx = vtxDE.extension(); - _nLayersVTX=vtx->layers.size(); - - } - catch( std::runtime_error& e){ - - streamlog_out( DEBUG9 ) << " ### VXD detector Not Present in Compact File" << std::endl ; + _nLayersVTX = vtx->layers.size(); + + } catch (std::runtime_error& e) { + + streamlog_out(DEBUG9) << " ### VXD detector Not Present in Compact File" << std::endl; } - - //-- SIT Parameters-- - _nLayersSIT = 0 ; + _nLayersSIT = 0; - try{ + try { - streamlog_out( DEBUG9 ) << " filling SIT parameters " << std::endl ; + streamlog_out(DEBUG9) << " filling SIT parameters " << std::endl; dd4hep::DetElement sitDE = theDetector.detector("SIT"); dd4hep::rec::ZPlanarData* sit = sitDE.extension(); - _nLayersSIT=sit->layers.size(); - } - catch( std::runtime_error& e){ - - streamlog_out( DEBUG9 ) << " ### SIT detector Not Present in Compact File " << std::endl ; + _nLayersSIT = sit->layers.size(); + } catch (std::runtime_error& e) { + streamlog_out(DEBUG9) << " ### SIT detector Not Present in Compact File " << std::endl; } //-- SET Parameters-- - _nLayersSET = 0 ; + _nLayersSET = 0; - try{ + try { - streamlog_out( DEBUG9 ) << " filling SET parameters " << std::endl ; + streamlog_out(DEBUG9) << " filling SET parameters " << std::endl; dd4hep::DetElement setDE = theDetector.detector("SET"); dd4hep::rec::ZPlanarData* set = setDE.extension(); - _nLayersSET=set->layers.size(); - } - catch( std::runtime_error& e){ - - streamlog_out( DEBUG9 ) << " ### SET detector Not Present in Compact File " << std::endl ; + _nLayersSET = set->layers.size(); + } catch (std::runtime_error& e) { + streamlog_out(DEBUG9) << " ### SET detector Not Present in Compact File " << std::endl; } - //-- FTD Parameters-- - _petalBasedFTDWithOverlaps = false; + _petalBasedFTDWithOverlaps = false; _nLayersFTD = 0; - try{ + try { - streamlog_out( DEBUG9 ) << " filling FTD parameters " << std::endl ; + streamlog_out(DEBUG9) << " filling FTD parameters " << std::endl; dd4hep::DetElement ftdDE = theDetector.detector("FTD"); dd4hep::rec::ZDiskPetalsData* ftd = ftdDE.extension(); _nLayersFTD = ftd->layers.size(); - for (unsigned int disk=0; disk < _nLayersFTD; ++disk) { + for (unsigned int disk = 0; disk < _nLayersFTD; ++disk) { - _zLayerFTD.push_back( ftd->layers[ disk ].zPosition + ftd->layers[ disk ].zOffsetSensitive ) ; - _zLayerFTD.push_back( ftd->layers[ disk ].zPosition - ftd->layers[ disk ].zOffsetSensitive ) ; + _zLayerFTD.push_back(ftd->layers[disk].zPosition + ftd->layers[disk].zOffsetSensitive); + _zLayerFTD.push_back(ftd->layers[disk].zPosition - ftd->layers[disk].zOffsetSensitive); _petalBasedFTDWithOverlaps = true; - } - // SJA: Here we increase the size of _nLayersFTD as we are treating the - _nLayersFTD =_zLayerFTD.size() ; - - } - catch( std::runtime_error& e){ + // SJA: Here we increase the size of _nLayersFTD as we are treating the + _nLayersFTD = _zLayerFTD.size(); - streamlog_out( DEBUG9 ) << " ### FTD detector Not Present in Compact File" << std::endl ; + } catch (std::runtime_error& e) { - } - - + streamlog_out(DEBUG9) << " ### FTD detector Not Present in Compact File" << std::endl; + } } +LCRelationNavigator* FPCCDFullLDCTracking_MarlinTrk::GetRelations(LCEvent* evt, std::string RelName) { -LCRelationNavigator* FPCCDFullLDCTracking_MarlinTrk::GetRelations(LCEvent * evt , std::string RelName ) { - - LCRelationNavigator* nav = NULL ; + LCRelationNavigator* nav = NULL; LCCollection* col = NULL; - try{ + try { - col = evt->getCollection( RelName.c_str() ); - nav = new LCRelationNavigator( col ); - streamlog_out( DEBUG4 ) << " --> " << RelName << " track relation collection found, number of elements = " << col->getNumberOfElements() << std::endl; - } - catch(DataNotAvailableException &e){ - streamlog_out( ERROR ) << " --> " << RelName.c_str() << " track relation collection absent" << std::endl; + col = evt->getCollection(RelName.c_str()); + nav = new LCRelationNavigator(col); + streamlog_out(DEBUG4) << " --> " << RelName + << " track relation collection found, number of elements = " << col->getNumberOfElements() + << std::endl; + } catch (DataNotAvailableException& e) { + streamlog_out(ERROR) << " --> " << RelName.c_str() << " track relation collection absent" << std::endl; } return nav; - } - - - - -LCCollection* FPCCDFullLDCTracking_MarlinTrk::GetCollection( LCEvent * evt, std::string colName ){ +LCCollection* FPCCDFullLDCTracking_MarlinTrk::GetCollection(LCEvent* evt, std::string colName) { LCCollection* col = NULL; try { - col = evt->getCollection( colName.c_str() ) ; - streamlog_out( DEBUG4 ) << " --> " << colName.c_str() << " collection found, number of elements = " << col->getNumberOfElements() << std::endl; + col = evt->getCollection(colName.c_str()); + streamlog_out(DEBUG4) << " --> " << colName.c_str() + << " collection found, number of elements = " << col->getNumberOfElements() << std::endl; + } catch (DataNotAvailableException& e) { + streamlog_out(DEBUG4) << " --> " << colName.c_str() << " collection absent" << std::endl; } - catch(DataNotAvailableException &e) { - streamlog_out( DEBUG4 ) << " --> " << colName.c_str() << " collection absent" << std::endl; - } - - return col; + return col; } +MCPMap FPCCDFullLDCTracking_MarlinTrk::LoadMCPMap(int mode = 0) { - - -MCPMap FPCCDFullLDCTracking_MarlinTrk::LoadMCPMap(int mode = 0){ - - if(mode == 0){ - _mcpVXD.clear(); - _mcpSIT.clear(); + if (mode == 0) { + _mcpVXD.clear(); + _mcpSIT.clear(); _mcpVXDSIT.clear(); - _mcpFTD.clear(); - _mcpFTDSIT.clear(); - _mcpVXDFTD.clear(); - _mcpVXDFTDSIT.clear(); + _mcpFTD.clear(); + _mcpFTDSIT.clear(); + _mcpVXDFTD.clear(); + _mcpVXDFTDSIT.clear(); } //_colMCP = GetCollection(_current_event, _colNameMCParticles); - _simVXD = GetCollection(_evt, _colNameVXDSimHit); - _simSIT = GetCollection(_evt, _colNameSITSimHit); + _simVXD = GetCollection(_evt, _colNameVXDSimHit); + _simSIT = GetCollection(_evt, _colNameSITSimHit); _simFTDpix = GetCollection(_evt, _colNameFTDpixSimHit); - _simFTDsp = GetCollection(_evt, _colNameFTDspSimHit); - if(mode == 1){ - _simTPC = GetCollection(_evt, _colNameTPCSimHit); - _simSET = GetCollection(_evt, _colNameSETSimHit); + _simFTDsp = GetCollection(_evt, _colNameFTDspSimHit); + if (mode == 1) { + _simTPC = GetCollection(_evt, _colNameTPCSimHit); + _simSET = GetCollection(_evt, _colNameSETSimHit); } SimTrackerHitVec simVec; int nvxd = 0, nsit = 0, nftdpix = 0, nftdsp = 0, ntpc = 0, nset = 0; - if(_simVXD != NULL){ + if (_simVXD != NULL) { nvxd = _simVXD->getNumberOfElements(); - for(int i = 0; i < nvxd; i++) simVec.push_back(dynamic_cast(_simVXD->getElementAt(i))); + for (int i = 0; i < nvxd; i++) + simVec.push_back(dynamic_cast(_simVXD->getElementAt(i))); } - if(_simSIT != NULL){ + if (_simSIT != NULL) { nsit = _simSIT->getNumberOfElements(); - for(int i = 0; i < nsit; i++) simVec.push_back(dynamic_cast(_simSIT->getElementAt(i))); + for (int i = 0; i < nsit; i++) + simVec.push_back(dynamic_cast(_simSIT->getElementAt(i))); } - if(_simFTDpix != NULL){ + if (_simFTDpix != NULL) { nftdpix = _simFTDpix->getNumberOfElements(); - for(int i = 0; i < nftdpix; i++) simVec.push_back(dynamic_cast(_simFTDpix->getElementAt(i))); + for (int i = 0; i < nftdpix; i++) + simVec.push_back(dynamic_cast(_simFTDpix->getElementAt(i))); } - if(_simFTDsp != NULL){ + if (_simFTDsp != NULL) { nftdsp = _simFTDsp->getNumberOfElements(); - for(int i = 0; i < nftdsp; i++) simVec.push_back(dynamic_cast(_simFTDsp->getElementAt(i))); + for (int i = 0; i < nftdsp; i++) + simVec.push_back(dynamic_cast(_simFTDsp->getElementAt(i))); } - if(mode == 1){ - if(_simTPC != NULL){ + if (mode == 1) { + if (_simTPC != NULL) { ntpc = _simTPC->getNumberOfElements(); - for(int i = 0; i < ntpc; i++) simVec.push_back(dynamic_cast(_simTPC->getElementAt(i))); + for (int i = 0; i < ntpc; i++) + simVec.push_back(dynamic_cast(_simTPC->getElementAt(i))); } - if(_simSET != NULL){ + if (_simSET != NULL) { nset = _simSET->getNumberOfElements(); - for(int i = 0; i < nset; i++) simVec.push_back(dynamic_cast(_simSET->getElementAt(i))); + for (int i = 0; i < nset; i++) + simVec.push_back(dynamic_cast(_simSET->getElementAt(i))); } } - MCPMap mymap = _moriUtil->MakeMCPMap(simVec); - if(mode == 0){ - for(MCPMap::iterator it = mymap.begin(); it != mymap.end(); it++){ - if(it->first == NULL) continue; - IntVec ivec = getNHitsInSubDet(it->second);//ivec[0] : VXD, ivec[1] : SIT, ivec[2] : FTD - if(ivec[2] == 0){ - if(ivec[1] == 0){ _mcpVXD.insert(*it); } - else{ - if(ivec[0] == 0){ _mcpSIT.insert(*it); } - else{ _mcpVXDSIT.insert(*it); } - } - } - else{ - if(ivec[0] == 0){ - if(ivec[1] == 0){ _mcpFTD.insert(*it); } - else{ _mcpFTDSIT.insert(*it); } + if (mode == 0) { + for (MCPMap::iterator it = mymap.begin(); it != mymap.end(); it++) { + if (it->first == NULL) + continue; + IntVec ivec = getNHitsInSubDet(it->second); // ivec[0] : VXD, ivec[1] : SIT, ivec[2] : FTD + if (ivec[2] == 0) { + if (ivec[1] == 0) { + _mcpVXD.insert(*it); + } else { + if (ivec[0] == 0) { + _mcpSIT.insert(*it); + } else { + _mcpVXDSIT.insert(*it); + } } - else{ - if(ivec[1] == 0){ _mcpVXDFTD.insert(*it); } - else{ _mcpVXDFTDSIT.insert(*it); } + } else { + if (ivec[0] == 0) { + if (ivec[1] == 0) { + _mcpFTD.insert(*it); + } else { + _mcpFTDSIT.insert(*it); + } + } else { + if (ivec[1] == 0) { + _mcpVXDFTD.insert(*it); + } else { + _mcpVXDFTDSIT.insert(*it); + } } } } - if(1){ + if (1) { std::cout << "nvxd : " << nvxd << std::endl; std::cout << "nsit : " << nsit << std::endl; std::cout << "nftdpix : " << nftdpix << std::endl; @@ -5597,22 +5274,24 @@ MCPMap FPCCDFullLDCTracking_MarlinTrk::LoadMCPMap(int mode = 0){ } } - return mymap; + return mymap; } - - -IntVec FPCCDFullLDCTracking_MarlinTrk::getNHitsInSubDet(SimTrackerHitVec simvec){ +IntVec FPCCDFullLDCTracking_MarlinTrk::getNHitsInSubDet(SimTrackerHitVec simvec) { IntVec ivec(5); - for(int i = 0; i < int(simvec.size()); i++){ + for (int i = 0; i < int(simvec.size()); i++) { int detid = getDetectorID(simvec[i]); - if(detid == lcio::ILDDetID::VXD ){ ivec[lcio::ILDDetID::VXD]++; } - else if(detid == lcio::ILDDetID::SIT){ ivec[lcio::ILDDetID::SIT]++; } - else if(detid == lcio::ILDDetID::FTD){ ivec[lcio::ILDDetID::FTD]++; } - else if(detid == lcio::ILDDetID::TPC){ ivec[lcio::ILDDetID::TPC]++; } - else if(detid == lcio::ILDDetID::SET){ ivec[lcio::ILDDetID::SET]++; } + if (detid == lcio::ILDDetID::VXD) { + ivec[lcio::ILDDetID::VXD]++; + } else if (detid == lcio::ILDDetID::SIT) { + ivec[lcio::ILDDetID::SIT]++; + } else if (detid == lcio::ILDDetID::FTD) { + ivec[lcio::ILDDetID::FTD]++; + } else if (detid == lcio::ILDDetID::TPC) { + ivec[lcio::ILDDetID::TPC]++; + } else if (detid == lcio::ILDDetID::SET) { + ivec[lcio::ILDDetID::SET]++; + } } return ivec; } - - diff --git a/source/Refitting/src/FPCCDSiliconTracking_MarlinTrk.cc b/source/Refitting/src/FPCCDSiliconTracking_MarlinTrk.cc index 5e85b82..0c6c323 100644 --- a/source/Refitting/src/FPCCDSiliconTracking_MarlinTrk.cc +++ b/source/Refitting/src/FPCCDSiliconTracking_MarlinTrk.cc @@ -1,46 +1,43 @@ #include "FPCCDSiliconTracking_MarlinTrk.h" - -#include -#include #include #include #include #include #include #include -#include #include +#include +#include +#include -#include -#include #include -#include -#include +#include #include -#include #include -#include +#include +#include +#include +#include +#include -#include #include +#include - -#include #include "UTIL/LCTrackerConf.h" +#include #include -#include "MarlinTrk/MarlinTrkUtils.h" -#include "MarlinTrk/HelixTrack.h" +#include "MarlinTrk/Factory.h" #include "MarlinTrk/HelixFit.h" +#include "MarlinTrk/HelixTrack.h" #include "MarlinTrk/IMarlinTrack.h" -#include "MarlinTrk/Factory.h" +#include "MarlinTrk/MarlinTrkUtils.h" -#include "DD4hep/Detector.h" #include "DD4hep/DD4hepUnits.h" +#include "DD4hep/Detector.h" #include "DDRec/DetectorData.h" - #include "marlin/AIDAProcessor.h" //---- ROOT ----- @@ -49,510 +46,410 @@ #include "TMath.h" #include "TStopwatch.h" +using namespace lcio; +using namespace marlin; +using namespace MarlinTrk; - - - - - - -using namespace lcio ; -using namespace marlin ; -using namespace MarlinTrk ; - -using std::min; -using std::max; using std::abs; +using std::max; +using std::min; const int FPCCDSiliconTracking_MarlinTrk::_output_track_col_quality_GOOD = 1; const int FPCCDSiliconTracking_MarlinTrk::_output_track_col_quality_FAIR = 2; const int FPCCDSiliconTracking_MarlinTrk::_output_track_col_quality_POOR = 3; -const double FPCCDSiliconTracking_MarlinTrk::TWOPI = 2*M_PI; - -FPCCDSiliconTracking_MarlinTrk aFPCCDSiliconTracking_MarlinTrk ; - - +const double FPCCDSiliconTracking_MarlinTrk::TWOPI = 2 * M_PI; +FPCCDSiliconTracking_MarlinTrk aFPCCDSiliconTracking_MarlinTrk; FPCCDSiliconTracking_MarlinTrk::FPCCDSiliconTracking_MarlinTrk() : Processor("FPCCDSiliconTracking_MarlinTrk") { _description = "Pattern recognition in silicon trackers"; - _petalBasedFTDWithOverlaps = false; // zero triplet counters _ntriplets = _ntriplets_good = _ntriplets_2MCP = _ntriplets_3MCP = _ntriplets_1MCP_Bad = _ntriplets_bad = 0; - std::vector comb; - comb.push_back(8); comb.push_back(6); comb.push_back(5); - comb.push_back(8); comb.push_back(6); comb.push_back(4); - comb.push_back(8); comb.push_back(5); comb.push_back(4); - comb.push_back(6); comb.push_back(5); comb.push_back(4); - - - registerProcessorParameter("LayerCombinations", - "Combinations of Hits in Layers", - _Combinations, - comb); + comb.push_back(8); + comb.push_back(6); + comb.push_back(5); + comb.push_back(8); + comb.push_back(6); + comb.push_back(4); + comb.push_back(8); + comb.push_back(5); + comb.push_back(4); + comb.push_back(6); + comb.push_back(5); + comb.push_back(4); + + registerProcessorParameter("LayerCombinations", "Combinations of Hits in Layers", _Combinations, comb); std::vector combFTD; - combFTD.push_back(13); combFTD.push_back(11); combFTD.push_back(9); - combFTD.push_back(13); combFTD.push_back(11); combFTD.push_back(8); - combFTD.push_back(13); combFTD.push_back(10); combFTD.push_back(9); - combFTD.push_back(13); combFTD.push_back(10); combFTD.push_back(8); - combFTD.push_back(12); combFTD.push_back(11); combFTD.push_back(9); - combFTD.push_back(12); combFTD.push_back(11); combFTD.push_back(8); - combFTD.push_back(12); combFTD.push_back(10); combFTD.push_back(9); - combFTD.push_back(12); combFTD.push_back(10); combFTD.push_back(8); - combFTD.push_back(11); combFTD.push_back(9); combFTD.push_back(7); - combFTD.push_back(11); combFTD.push_back(9); combFTD.push_back(6); - combFTD.push_back(11); combFTD.push_back(8); combFTD.push_back(7); - combFTD.push_back(11); combFTD.push_back(8); combFTD.push_back(6); - combFTD.push_back(10); combFTD.push_back(9); combFTD.push_back(7); - combFTD.push_back(10); combFTD.push_back(9); combFTD.push_back(6); - combFTD.push_back(10); combFTD.push_back(8); combFTD.push_back(7); - combFTD.push_back(9); combFTD.push_back(7); combFTD.push_back(5); - combFTD.push_back(9); combFTD.push_back(7); combFTD.push_back(4); - combFTD.push_back(9); combFTD.push_back(6); combFTD.push_back(5); - combFTD.push_back(9); combFTD.push_back(6); combFTD.push_back(4); - combFTD.push_back(8); combFTD.push_back(7); combFTD.push_back(5); - combFTD.push_back(8); combFTD.push_back(7); combFTD.push_back(4); - combFTD.push_back(8); combFTD.push_back(6); combFTD.push_back(5); - combFTD.push_back(8); combFTD.push_back(6); combFTD.push_back(4); - combFTD.push_back(7); combFTD.push_back(5); combFTD.push_back(3); - combFTD.push_back(7); combFTD.push_back(5); combFTD.push_back(2); - combFTD.push_back(7); combFTD.push_back(4); combFTD.push_back(3); - combFTD.push_back(7); combFTD.push_back(4); combFTD.push_back(2); - combFTD.push_back(6); combFTD.push_back(5); combFTD.push_back(3); - combFTD.push_back(6); combFTD.push_back(5); combFTD.push_back(2); - combFTD.push_back(6); combFTD.push_back(4); combFTD.push_back(3); - combFTD.push_back(6); combFTD.push_back(4); combFTD.push_back(2); - combFTD.push_back(5); combFTD.push_back(3); combFTD.push_back(1); - combFTD.push_back(5); combFTD.push_back(3); combFTD.push_back(0); - combFTD.push_back(5); combFTD.push_back(2); combFTD.push_back(1); - combFTD.push_back(5); combFTD.push_back(2); combFTD.push_back(0); - combFTD.push_back(4); combFTD.push_back(3); combFTD.push_back(1); - combFTD.push_back(4); combFTD.push_back(3); combFTD.push_back(0); - combFTD.push_back(4); combFTD.push_back(2); combFTD.push_back(1); - combFTD.push_back(4); combFTD.push_back(2); combFTD.push_back(0); - - - registerProcessorParameter("LayerCombinationsFTD", - "Combinations of Hits in FTD", - _CombinationsFTD, - combFTD); - - - registerProcessorParameter("NDivisionsInPhiFTD", - "Number of divisions in Phi for FTD", - _nPhiFTD, - int(30)); - - registerProcessorParameter("NDivisionsInPhi", - "Number of divisions in Phi", - _nDivisionsInPhi, - int(1440));//1 sector is equivalent to 0.25 deg. - - registerProcessorParameter("NDivisionsInTheta", - "Number of divisions in Theta", - _nDivisionsInTheta, - int(640));//1 sector, delta(cosTheta), is equivalent to 2/640. - - - registerProcessorParameter("SearchWindowForTripletInTheta", - "num of theta-sectors used in making triplets", - _sw_theta, - int(16)); - - + combFTD.push_back(13); + combFTD.push_back(11); + combFTD.push_back(9); + combFTD.push_back(13); + combFTD.push_back(11); + combFTD.push_back(8); + combFTD.push_back(13); + combFTD.push_back(10); + combFTD.push_back(9); + combFTD.push_back(13); + combFTD.push_back(10); + combFTD.push_back(8); + combFTD.push_back(12); + combFTD.push_back(11); + combFTD.push_back(9); + combFTD.push_back(12); + combFTD.push_back(11); + combFTD.push_back(8); + combFTD.push_back(12); + combFTD.push_back(10); + combFTD.push_back(9); + combFTD.push_back(12); + combFTD.push_back(10); + combFTD.push_back(8); + combFTD.push_back(11); + combFTD.push_back(9); + combFTD.push_back(7); + combFTD.push_back(11); + combFTD.push_back(9); + combFTD.push_back(6); + combFTD.push_back(11); + combFTD.push_back(8); + combFTD.push_back(7); + combFTD.push_back(11); + combFTD.push_back(8); + combFTD.push_back(6); + combFTD.push_back(10); + combFTD.push_back(9); + combFTD.push_back(7); + combFTD.push_back(10); + combFTD.push_back(9); + combFTD.push_back(6); + combFTD.push_back(10); + combFTD.push_back(8); + combFTD.push_back(7); + combFTD.push_back(9); + combFTD.push_back(7); + combFTD.push_back(5); + combFTD.push_back(9); + combFTD.push_back(7); + combFTD.push_back(4); + combFTD.push_back(9); + combFTD.push_back(6); + combFTD.push_back(5); + combFTD.push_back(9); + combFTD.push_back(6); + combFTD.push_back(4); + combFTD.push_back(8); + combFTD.push_back(7); + combFTD.push_back(5); + combFTD.push_back(8); + combFTD.push_back(7); + combFTD.push_back(4); + combFTD.push_back(8); + combFTD.push_back(6); + combFTD.push_back(5); + combFTD.push_back(8); + combFTD.push_back(6); + combFTD.push_back(4); + combFTD.push_back(7); + combFTD.push_back(5); + combFTD.push_back(3); + combFTD.push_back(7); + combFTD.push_back(5); + combFTD.push_back(2); + combFTD.push_back(7); + combFTD.push_back(4); + combFTD.push_back(3); + combFTD.push_back(7); + combFTD.push_back(4); + combFTD.push_back(2); + combFTD.push_back(6); + combFTD.push_back(5); + combFTD.push_back(3); + combFTD.push_back(6); + combFTD.push_back(5); + combFTD.push_back(2); + combFTD.push_back(6); + combFTD.push_back(4); + combFTD.push_back(3); + combFTD.push_back(6); + combFTD.push_back(4); + combFTD.push_back(2); + combFTD.push_back(5); + combFTD.push_back(3); + combFTD.push_back(1); + combFTD.push_back(5); + combFTD.push_back(3); + combFTD.push_back(0); + combFTD.push_back(5); + combFTD.push_back(2); + combFTD.push_back(1); + combFTD.push_back(5); + combFTD.push_back(2); + combFTD.push_back(0); + combFTD.push_back(4); + combFTD.push_back(3); + combFTD.push_back(1); + combFTD.push_back(4); + combFTD.push_back(3); + combFTD.push_back(0); + combFTD.push_back(4); + combFTD.push_back(2); + combFTD.push_back(1); + combFTD.push_back(4); + combFTD.push_back(2); + combFTD.push_back(0); + + registerProcessorParameter("LayerCombinationsFTD", "Combinations of Hits in FTD", _CombinationsFTD, combFTD); + + registerProcessorParameter("NDivisionsInPhiFTD", "Number of divisions in Phi for FTD", _nPhiFTD, int(30)); + + registerProcessorParameter("NDivisionsInPhi", "Number of divisions in Phi", _nDivisionsInPhi, + int(1440)); // 1 sector is equivalent to 0.25 deg. + + registerProcessorParameter("NDivisionsInTheta", "Number of divisions in Theta", _nDivisionsInTheta, + int(640)); // 1 sector, delta(cosTheta), is equivalent to 2/640. + + registerProcessorParameter("SearchWindowForTripletInTheta", "num of theta-sectors used in making triplets", _sw_theta, + int(16)); // Input Collections for debug // ^^^^^^^^^^^^^^^^^ - registerInputCollection(LCIO::SIMTRACKERHIT, - "SimTrackerHit of VXD (VXDCollection)", - "This is used to calculate picking efficiency of a track.", - _colNameVXDSimHit, - std::string("VXDCollection")); - - registerInputCollection(LCIO::SIMTRACKERHIT, - "SimTrackerHit of SIT (SITCollection)", - "This is used to calculate picking efficiency of a track.", - _colNameSITSimHit, - std::string("SITCollection")); - - registerInputCollection(LCIO::SIMTRACKERHIT, - "SimTrackerHit of FTD_STRIP (FTD_STRIPCollection)", - "This is used to calculate picking efficiency of a track.", - _colNameFTDspSimHit, - std::string("FTD_STRIPCollection")); - - registerInputCollection(LCIO::SIMTRACKERHIT, - "SimTrackerHit of FTD_PIXEL (FTD_PIXELCollection)", - "This is used to calculate picking efficiency of a track.", - _colNameFTDpixSimHit, - std::string("FTD_PIXELCollection")); + registerInputCollection(LCIO::SIMTRACKERHIT, "SimTrackerHit of VXD (VXDCollection)", + "This is used to calculate picking efficiency of a track.", _colNameVXDSimHit, + std::string("VXDCollection")); + registerInputCollection(LCIO::SIMTRACKERHIT, "SimTrackerHit of SIT (SITCollection)", + "This is used to calculate picking efficiency of a track.", _colNameSITSimHit, + std::string("SITCollection")); - // Input Collections - registerInputCollection(LCIO::TRACKERHITPLANE, - "VTXHitCollectionName", - "VTX Hit Collection Name", - _VTXHitCollection, - std::string("VXDTrackerHits")); + registerInputCollection(LCIO::SIMTRACKERHIT, "SimTrackerHit of FTD_STRIP (FTD_STRIPCollection)", + "This is used to calculate picking efficiency of a track.", _colNameFTDspSimHit, + std::string("FTD_STRIPCollection")); + registerInputCollection(LCIO::SIMTRACKERHIT, "SimTrackerHit of FTD_PIXEL (FTD_PIXELCollection)", + "This is used to calculate picking efficiency of a track.", _colNameFTDpixSimHit, + std::string("FTD_PIXELCollection")); - registerInputCollection(LCIO::TRACKERHITPLANE, - "FTDPixelHitCollectionName", - "FTD Pixel Hit Collection Name", - _FTDPixelHitCollection, - std::string("FTDPixelTrackerHits")); + // Input Collections + registerInputCollection(LCIO::TRACKERHITPLANE, "VTXHitCollectionName", "VTX Hit Collection Name", _VTXHitCollection, + std::string("VXDTrackerHits")); - registerInputCollection(LCIO::TRACKERHIT, - "FTDSpacePointCollectionName", - "FTD FTDSpacePoint Collection Name", - _FTDSpacePointCollection, - std::string("FTDSpacePoints")); + registerInputCollection(LCIO::TRACKERHITPLANE, "FTDPixelHitCollectionName", "FTD Pixel Hit Collection Name", + _FTDPixelHitCollection, std::string("FTDPixelTrackerHits")); + registerInputCollection(LCIO::TRACKERHIT, "FTDSpacePointCollectionName", "FTD FTDSpacePoint Collection Name", + _FTDSpacePointCollection, std::string("FTDSpacePoints")); - registerInputCollection(LCIO::TRACKERHIT, - "SITHitCollectionName", - "SIT Hit Collection Name", - _SITHitCollection, - std::string("SITSpacePoints")); + registerInputCollection(LCIO::TRACKERHIT, "SITHitCollectionName", "SIT Hit Collection Name", _SITHitCollection, + std::string("SITSpacePoints")); // Output Collections // ^^^^^^^^^^^^^^^^^^ - registerOutputCollection(LCIO::TRACK, - "SiTrackCollectionName", "Silicon track Collection Name", - _siTrkCollection, - std::string("SiTracks")); - - + registerOutputCollection(LCIO::TRACK, "SiTrackCollectionName", "Silicon track Collection Name", _siTrkCollection, + std::string("SiTracks")); // Steering parameters // ^^^^^^^^^^^^^^^^^^^ - registerProcessorParameter("Chi2WRphiTriplet", - "Chi2WRphiTriplet", - _chi2WRPhiTriplet, - float(1.)); - - registerProcessorParameter("Chi2WZTriplet", - "Chi2WZTriplet", - _chi2WZTriplet, - float(0.5)); - - registerProcessorParameter("Chi2FitCut", - "Chi2 Fit Cut", - _chi2FitCut, - float(120.0)); - - registerProcessorParameter("Chi2FitCut_kalman", - "Chi2 Fit Cut for BuildTrack_KalFit", - _chi2FitCut_kalman, - float(120.0)); - - registerProcessorParameter("AngleCutForMerging", - "Angle Cut For Merging", - _angleCutForMerging, - float(0.1)); - - registerProcessorParameter("MinDistCutAttachForFTD", - "MinDistCutAttachForFTD", - _minDistCutAttachForFTD, - float(2.5)); - - registerProcessorParameter("MinDistCutAttachForVXD", - "MinDistCutAttachForVXD", - _minDistCutAttachForVXD, - float(0.5));//unit: mm - - registerProcessorParameter("MinMissAddition", - "Allowed max number of MinMissAdditions in BuildTrack", - _minMissAddition, - int(2)); + registerProcessorParameter("Chi2WRphiTriplet", "Chi2WRphiTriplet", _chi2WRPhiTriplet, float(1.)); - registerProcessorParameter("FudgeFactorForSIT_rphi_SpatialResolution", - "SIT's spatial resolution is not calculated precisely. (default : 2.0)", - _fudgeFactorForSITsr_rphi, - float(2.0)); + registerProcessorParameter("Chi2WZTriplet", "Chi2WZTriplet", _chi2WZTriplet, float(0.5)); - registerProcessorParameter("FudgeFactorForSIT_z_SpatialResolution", - "SIT's spatial resolution is not calculated precisely. (default : 1.0)", - _fudgeFactorForSITsr_z, - float(1.0)); + registerProcessorParameter("Chi2FitCut", "Chi2 Fit Cut", _chi2FitCut, float(120.0)); + + registerProcessorParameter("Chi2FitCut_kalman", "Chi2 Fit Cut for BuildTrack_KalFit", _chi2FitCut_kalman, + float(120.0)); + registerProcessorParameter("AngleCutForMerging", "Angle Cut For Merging", _angleCutForMerging, float(0.1)); + registerProcessorParameter("MinDistCutAttachForFTD", "MinDistCutAttachForFTD", _minDistCutAttachForFTD, float(2.5)); - registerProcessorParameter("MinLayerToAttach", - "MinLayerToAttach", - _minimalLayerToAttach, - int(-1)); + registerProcessorParameter("MinDistCutAttachForVXD", "MinDistCutAttachForVXD", _minDistCutAttachForVXD, + float(0.5)); // unit: mm - registerProcessorParameter("CutOnD0", - "cut on D0 for tracks", - _cutOnD0, - float(60.0)); + registerProcessorParameter("MinMissAddition", "Allowed max number of MinMissAdditions in BuildTrack", + _minMissAddition, int(2)); - registerProcessorParameter("CutOnZ0", - "cut on Z0 for tracks", - _cutOnZ0, - float(100.0)); + registerProcessorParameter("FudgeFactorForSIT_rphi_SpatialResolution", + "SIT's spatial resolution is not calculated precisely. (default : 2.0)", + _fudgeFactorForSITsr_rphi, float(2.0)); + + registerProcessorParameter("FudgeFactorForSIT_z_SpatialResolution", + "SIT's spatial resolution is not calculated precisely. (default : 1.0)", + _fudgeFactorForSITsr_z, float(1.0)); + + registerProcessorParameter("MinLayerToAttach", "MinLayerToAttach", _minimalLayerToAttach, int(-1)); + + registerProcessorParameter("CutOnD0", "cut on D0 for tracks", _cutOnD0, float(60.0)); - registerProcessorParameter("CutOnPt_For_VXD+SIT_section", - "cut on Pt for TestTriplet in VXD+SIT section", - _cutOnPtVXD, - double(0.18)); + registerProcessorParameter("CutOnZ0", "cut on Z0 for tracks", _cutOnZ0, float(100.0)); - registerProcessorParameter("CutOnPt_For_FTD_section ", - "cut on Pt for TestTriplet in FTD section", - _cutOnPtFTD, - double(0.05)); + registerProcessorParameter("CutOnPt_For_VXD+SIT_section", "cut on Pt for TestTriplet in VXD+SIT section", _cutOnPtVXD, + double(0.18)); - registerProcessorParameter("MinimalHits", - "minimal hits (default 3)", - _minimalHits, - int(3)); + registerProcessorParameter("CutOnPt_For_FTD_section ", "cut on Pt for TestTriplet in FTD section", _cutOnPtFTD, + double(0.05)); - registerProcessorParameter("NHitsChi2", - "Maximal number of hits for which a track with n hits is better than one with n-1hits. (defaut 8)", - _nHitsChi2, - int(8)); + registerProcessorParameter("MinimalHits", "minimal hits (default 3)", _minimalHits, int(3)); - registerProcessorParameter("MaxHitsPerSector", + registerProcessorParameter( + "NHitsChi2", "Maximal number of hits for which a track with n hits is better than one with n-1hits. (defaut 8)", + _nHitsChi2, int(8)); + + registerProcessorParameter( + "MaxHitsPerSector", "Maximal number of hits allowed in one theta-phi sector in FTD (In VXD and SIT, this is not implemented)", - _max_hits_per_sector, - int(100)); + _max_hits_per_sector, int(100)); - registerProcessorParameter("AttachRemainingHitsForVXD", - "1:Fast, 2:Slow, 3:VeryFast, 0:skip this process", - _attachVXD, - int(2));//Very Fast is underconstruction. + registerProcessorParameter("AttachRemainingHitsForVXD", "1:Fast, 2:Slow, 3:VeryFast, 0:skip this process", _attachVXD, + int(2)); // Very Fast is underconstruction. - registerProcessorParameter("AttachRemainingHitsForFTD", - "1:Fast, 2:Slow, 0:skip this process", - _attachFTD, - int(2)); + registerProcessorParameter("AttachRemainingHitsForFTD", "1:Fast, 2:Slow, 0:skip this process", _attachFTD, int(2)); - registerProcessorParameter("UseSIT", - "Use SIT", - _useSIT, - int(1)); + registerProcessorParameter("UseSIT", "Use SIT", _useSIT, int(1)); - registerProcessorParameter("UseFTD", - "Use FTD", - _useFTD, - int(1)); + registerProcessorParameter("UseFTD", "Use FTD", _useFTD, int(1)); registerProcessorParameter("NDivisions_phiRangeForBuildTrackForHighPt", - "set width of phi(deg) value [0,360].ex: 360deg/80 = 4.5 (This value emulates original SiliconTracking_MarlinTrk by default) ", - _phiRangeForBuildTrackForHighPt, - double(4.5)); + "set width of phi(deg) value [0,360].ex: 360deg/80 = 4.5 (This value emulates original " + "SiliconTracking_MarlinTrk by default) ", + _phiRangeForBuildTrackForHighPt, double(4.5)); registerProcessorParameter("NDivisions_cosThetaRangeForBuildTrackForHighPt", - "set width of cosTheta value [0,2].ex: 2/80 = 0.025 (This value emulates original SiliconTracking_MarlinTrk by default)", - _cosThetaRangeForBuildTrackForHighPt, - double(0.025)); + "set width of cosTheta value [0,2].ex: 2/80 = 0.025 (This value emulates original " + "SiliconTracking_MarlinTrk by default)", + _cosThetaRangeForBuildTrackForHighPt, double(0.025)); registerProcessorParameter("UseClusterRejection", - "Use Cluster Rejection (for FPCCD VXD in dense pair-BG env. option)", - _useClusterRejection, - bool(false)); + "Use Cluster Rejection (for FPCCD VXD in dense pair-BG env. option)", _useClusterRejection, + bool(false)); registerProcessorParameter("minDotOf2Clusters", - "minimum dot of 2Clusters (for FPCCD VXD in dense pair-BG env. option)", - _minDotOf2Clusters, - float(0.4)); - - registerProcessorParameter( "InitialTrackErrorD0", - "Value used for the initial d0 variance of the trackfit", - _initialTrackError_d0, - float(1.e6)); - - registerProcessorParameter( "InitialTrackErrorPhi0", - "Value used for the initial phi0 variance of the trackfit", - _initialTrackError_phi0, - float(1.e2)); - - registerProcessorParameter( "InitialTrackErrorOmega", - "Value used for the initial omega variance of the trackfit", - _initialTrackError_omega, - float(1.e-4)); - - registerProcessorParameter( "InitialTrackErrorZ0", - "Value used for the initial z0 variance of the trackfit", - _initialTrackError_z0, - float(1.e6)); - - registerProcessorParameter( "InitialTrackErrorTanL", - "Value used for the initial tanL variance of the trackfit", - _initialTrackError_tanL, - float(1.e2)); - - registerProcessorParameter( "MaxChi2PerHit", - "Maximum Chi-squared value allowed when assigning a hit to a track (for KalTest)", - _maxChi2PerHit, - double(1.e2)); - - registerProcessorParameter( "MaxChi2PerHit2nd", + "minimum dot of 2Clusters (for FPCCD VXD in dense pair-BG env. option)", + _minDotOf2Clusters, float(0.4)); + + registerProcessorParameter("InitialTrackErrorD0", "Value used for the initial d0 variance of the trackfit", + _initialTrackError_d0, float(1.e6)); + + registerProcessorParameter("InitialTrackErrorPhi0", "Value used for the initial phi0 variance of the trackfit", + _initialTrackError_phi0, float(1.e2)); + + registerProcessorParameter("InitialTrackErrorOmega", "Value used for the initial omega variance of the trackfit", + _initialTrackError_omega, float(1.e-4)); + + registerProcessorParameter("InitialTrackErrorZ0", "Value used for the initial z0 variance of the trackfit", + _initialTrackError_z0, float(1.e6)); + + registerProcessorParameter("InitialTrackErrorTanL", "Value used for the initial tanL variance of the trackfit", + _initialTrackError_tanL, float(1.e2)); + + registerProcessorParameter("MaxChi2PerHit", + "Maximum Chi-squared value allowed when assigning a hit to a track (for KalTest)", + _maxChi2PerHit, double(1.e2)); + + registerProcessorParameter( + "MaxChi2PerHit2nd", "Maximum Chi-squared value allowed when assigning a hit to a track (especially for KalFit in this code)", - _maxChi2PerHit2nd, - double(1.e2)); + _maxChi2PerHit2nd, double(1.e2)); - registerProcessorParameter("CheckForDelta", - "Check for Delta rays hits in hit-to-track assignment", - _checkForDelta, - int(1)); + registerProcessorParameter("CheckForDelta", "Check for Delta rays hits in hit-to-track assignment", _checkForDelta, + int(1)); - registerProcessorParameter("MinDistToDelta", - "Minimal distance of track hit to the delta electron hit", - _minDistToDelta, - float(0.25)); + registerProcessorParameter("MinDistToDelta", "Minimal distance of track hit to the delta electron hit", + _minDistToDelta, float(0.25)); - registerProcessorParameter("MultipleScatteringOn", - "Use MultipleScattering in Fit", - _MSOn, - bool(true)); + registerProcessorParameter("MultipleScatteringOn", "Use MultipleScattering in Fit", _MSOn, bool(true)); registerProcessorParameter("nSigma_for_Build_phiTrack", - "In extrapolation, search area in phi is determined by using sigma of d0, so you can enlarge this area by this value. ", - _nSigmaBuild_phi, - double(5.0)); + "In extrapolation, search area in phi is determined by using sigma of d0, so you can " + "enlarge this area by this value. ", + _nSigmaBuild_phi, double(5.0)); registerProcessorParameter("nSigma_for_Build_thetaTrack", - "In extrapolation, search area in phi is determined by using sigma of d0, so you can enlarge this area by this value. ", - _nSigmaBuild_theta, - double(5.0)); - - registerProcessorParameter("EnergyLossOn", - "Use Energy Loss in Fit", - _ElossOn, - bool(true)); - - registerProcessorParameter("SmoothOn", - "Smooth All Mesurement Sites in Fit", - _SmoothOn, - bool(false)); - - registerProcessorParameter("SafetyPhi-Range_ratio_ForTripletSearchAndExtrapolation", - "Range <= (1 + this)*Range", - _safetyPhiRange_ratio, - float(0.10));//old 0.3 - - registerProcessorParameter("SafetyPhi-Range_fix_ForTripletSearchAndExtrapolation", - "Range += this", - _safetyPhiRange_fix, - int(1));//old 0.1 - - registerInputCollection("MCParticle", - "MCParticleCollectionName", - "Name of the MCParticle input collection", - _colNameMCParticles, - std::string("MCParticle")); - - registerInputCollection("LCRelation", - "VXDTrackerHitRelations", - "Name of the LCRelation input collection", - _colNameVXDTrackerHitRelations, - std::string("VXDTrackerHitRelations")); - - registerInputCollection("LCRelation", - "SITSpacePointRelations", - "Name of the LCRelation input collection", - _colNameSITSpacePointRelations, - std::string("SITSpacePointRelations")); - - registerInputCollection("LCRelation", - "FTDSpacePointRelations", - "Name of the LCRelation input collection", - _colNameFTDSpacePointRelations, - std::string("FTDSpacePointRelations")); - - registerInputCollection("LCRelation", - "FTDPixelTrackerHitRelations", - "Name of the LCRelation input collection", - _colNameFTDPixelTrackerHitRelations, - std::string("FTDPixelTrackerHitRelations")); - - - FloatVec PixelSizeVec; //for FPCCD VXD - PixelSizeVec.push_back(0.005); - PixelSizeVec.push_back(0.005); - PixelSizeVec.push_back(0.010); - PixelSizeVec.push_back(0.010); - PixelSizeVec.push_back(0.010); - PixelSizeVec.push_back(0.010); + "In extrapolation, search area in phi is determined by using sigma of d0, so you can " + "enlarge this area by this value. ", + _nSigmaBuild_theta, double(5.0)); - registerProcessorParameter( "FPCCD: Each_FPCCD_pixelSize(mm)", - "Each ladder's FPCCD Pixel size(unit:mm) (for cluster rejection for FPCCD)", - _pixelSizeVec, - PixelSizeVec ); + registerProcessorParameter("EnergyLossOn", "Use Energy Loss in Fit", _ElossOn, bool(true)); - registerProcessorParameter( "FPCCD: PixelHeight" , - "Pixel Height(mm) (for cluster rejection for FPCCD)", - _pixelheight , - float(0.015)); + registerProcessorParameter("SmoothOn", "Smooth All Mesurement Sites in Fit", _SmoothOn, bool(false)); + registerProcessorParameter("SafetyPhi-Range_ratio_ForTripletSearchAndExtrapolation", "Range <= (1 + this)*Range", + _safetyPhiRange_ratio, + float(0.10)); // old 0.3 - registerProcessorParameter( "fudgePhiRange" , - "fudgePhiRange for the iterative determination of search range in the extrapolation", - _fudgePhiRange, - int(2)); + registerProcessorParameter("SafetyPhi-Range_fix_ForTripletSearchAndExtrapolation", "Range += this", + _safetyPhiRange_fix, + int(1)); // old 0.1 - registerProcessorParameter( "fudgeThetaRange" , - "fudgeThetaRange for the iterative determination of search range in the extrapolation", - _fudgeThetaRange, - int(2)); + registerInputCollection("MCParticle", "MCParticleCollectionName", "Name of the MCParticle input collection", + _colNameMCParticles, std::string("MCParticle")); - registerProcessorParameter( "mydebug" , - "mydebug (code debuger for Mori)", - _mydebug, - bool(false)); + registerInputCollection("LCRelation", "VXDTrackerHitRelations", "Name of the LCRelation input collection", + _colNameVXDTrackerHitRelations, std::string("VXDTrackerHitRelations")); - registerProcessorParameter( "mydebugKalFit" , - "mydebugKalFit (code debuger for Mori)", - _mydebugKalFit, - bool(false)); + registerInputCollection("LCRelation", "SITSpacePointRelations", "Name of the LCRelation input collection", + _colNameSITSpacePointRelations, std::string("SITSpacePointRelations")); + registerInputCollection("LCRelation", "FTDSpacePointRelations", "Name of the LCRelation input collection", + _colNameFTDSpacePointRelations, std::string("FTDSpacePointRelations")); - registerProcessorParameter( "mydebugIntersection" , - "mydebugIntersection (code debuger for Mori)", - _mydebugIntersection, - bool(false)); + registerInputCollection("LCRelation", "FTDPixelTrackerHitRelations", "Name of the LCRelation input collection", + _colNameFTDPixelTrackerHitRelations, std::string("FTDPixelTrackerHitRelations")); - registerProcessorParameter( "stopwatch" , - "stopwatch (code debuger for Mori)", - _stopwatch, - bool(false)); + FloatVec PixelSizeVec; // for FPCCD VXD + PixelSizeVec.push_back(0.005); + PixelSizeVec.push_back(0.005); + PixelSizeVec.push_back(0.010); + PixelSizeVec.push_back(0.010); + PixelSizeVec.push_back(0.010); + PixelSizeVec.push_back(0.010); - registerProcessorParameter( "mydebugstopwatch2" , - "mydebugstopwatch2 (code debuger for Mori)", - _mydebugstopwatch2, - bool(false)); + registerProcessorParameter("FPCCD: Each_FPCCD_pixelSize(mm)", + "Each ladder's FPCCD Pixel size(unit:mm) (for cluster rejection for FPCCD)", _pixelSizeVec, + PixelSizeVec); - registerProcessorParameter( "keepCandidate" , - "Option for AttachRemainingVTXHitsVeryFast (please fix false for now)", - _keepCandidate, - bool(false)); + registerProcessorParameter("FPCCD: PixelHeight", "Pixel Height(mm) (for cluster rejection for FPCCD)", _pixelheight, + float(0.015)); + registerProcessorParameter("fudgePhiRange", + "fudgePhiRange for the iterative determination of search range in the extrapolation", + _fudgePhiRange, int(2)); + registerProcessorParameter("fudgeThetaRange", + "fudgeThetaRange for the iterative determination of search range in the extrapolation", + _fudgeThetaRange, int(2)); + registerProcessorParameter("mydebug", "mydebug (code debuger for Mori)", _mydebug, bool(false)); - _output_track_col_quality = _output_track_col_quality_GOOD; + registerProcessorParameter("mydebugKalFit", "mydebugKalFit (code debuger for Mori)", _mydebugKalFit, bool(false)); + registerProcessorParameter("mydebugIntersection", "mydebugIntersection (code debuger for Mori)", _mydebugIntersection, + bool(false)); -} + registerProcessorParameter("stopwatch", "stopwatch (code debuger for Mori)", _stopwatch, bool(false)); + + registerProcessorParameter("mydebugstopwatch2", "mydebugstopwatch2 (code debuger for Mori)", _mydebugstopwatch2, + bool(false)); + registerProcessorParameter("keepCandidate", "Option for AttachRemainingVTXHitsVeryFast (please fix false for now)", + _keepCandidate, bool(false)); + _output_track_col_quality = _output_track_col_quality_GOOD; +} -void FPCCDSiliconTracking_MarlinTrk::init() { +void FPCCDSiliconTracking_MarlinTrk::init() { - _nRun = -1 ; - _nEvt = 0 ; + _nRun = -1; + _nEvt = 0; _encoder = new UTIL::BitField64(lcio::LCTrackerCellID::encoding_string()); @@ -560,50 +457,49 @@ void FPCCDSiliconTracking_MarlinTrk::init() { _moriUtil = new moriUTIL(); _purityUtil = new GetPurityUtil(); - printParameters() ; + printParameters(); // this creates a directory for this processor .... - _trksystem = MarlinTrk::Factory::createMarlinTrkSystem( "DDKalTest" , 0 , "" ) ; + _trksystem = MarlinTrk::Factory::createMarlinTrkSystem("DDKalTest", 0, ""); - if( _trksystem == 0 ){ - throw EVENT::Exception( std::string(" Cannot initialize MarlinTrkSystem of Type: ") + std::string("KalTest" ) ) ; + if (_trksystem == 0) { + throw EVENT::Exception(std::string(" Cannot initialize MarlinTrkSystem of Type: ") + std::string("KalTest")); } - _trksystem->setOption( IMarlinTrkSystem::CFG::useQMS, _MSOn ) ; - _trksystem->setOption( IMarlinTrkSystem::CFG::usedEdx, _ElossOn) ; - _trksystem->setOption( IMarlinTrkSystem::CFG::useSmoothing, _SmoothOn) ; - _trksystem->init() ; - + _trksystem->setOption(IMarlinTrkSystem::CFG::useQMS, _MSOn); + _trksystem->setOption(IMarlinTrkSystem::CFG::usedEdx, _ElossOn); + _trksystem->setOption(IMarlinTrkSystem::CFG::useSmoothing, _SmoothOn); + _trksystem->init(); dd4hep::Detector& theDetector = dd4hep::Detector::getInstance(); - - this->setupGeom( theDetector ); + + this->setupGeom(theDetector); if (_useSIT == 0) _nLayers = _nLayersVTX; - else + else _nLayers = _nLayersVTX + _nLayersSIT; // initialise the container to have separate vectors for up to _nHitsChi2 hits. _tracksWithNHitsContainer.resize(_nHitsChi2); - _dPhi = TWOPI/_nDivisionsInPhi; - _dTheta = 2.0/_nDivisionsInTheta; - _dPhiFTD = TWOPI/_nPhiFTD; - double cutOnR_VXD = _cutOnPtVXD/(0.299792458*_bField); - cutOnR_VXD = 1000.*cutOnR_VXD; - _cutOnOmegaVXD = 1/cutOnR_VXD; - double cutOnR_FTD = _cutOnPtFTD/(0.299792458*_bField); - cutOnR_FTD = 1000.*cutOnR_FTD; - _cutOnOmegaFTD = 1/cutOnR_FTD; + _dPhi = TWOPI / _nDivisionsInPhi; + _dTheta = 2.0 / _nDivisionsInTheta; + _dPhiFTD = TWOPI / _nPhiFTD; + double cutOnR_VXD = _cutOnPtVXD / (0.299792458 * _bField); + cutOnR_VXD = 1000. * cutOnR_VXD; + _cutOnOmegaVXD = 1 / cutOnR_VXD; + double cutOnR_FTD = _cutOnPtFTD / (0.299792458 * _bField); + cutOnR_FTD = 1000. * cutOnR_FTD; + _cutOnOmegaFTD = 1 / cutOnR_FTD; - InitVXDGeometry( theDetector ); - if(_useSIT == 1) InitSITGeometry( theDetector ); + InitVXDGeometry(theDetector); + if (_useSIT == 1) + InitSITGeometry(theDetector); _output_track_col_quality = 0; - -//Range determination for TestTriplet +// Range determination for TestTriplet #if 0 //new version (under construction) int ncomb = _Combinations.size(); @@ -619,54 +515,46 @@ void FPCCDSiliconTracking_MarlinTrk::init() { phiRange[1] = int(std::abs(phiDiff[1]/_dPhi)*(1.0 + _safetyPhiRange_ratio)) + _safetyPhiRange_fix; _phiRangeForTripletVer2.insert(std::make_pair(layers,phiRange)); } -#else - //old version (for now, please use this) +#else + // old version (for now, please use this) int ncomb = _Combinations.size(); - for(int i = 0; i < ncomb; i += 3 ){ - std::pair lyp(_Combinations[i],_Combinations[i+2]); - double phiDiff = getNeededPhiSectors(_cutOnPtVXD, _Combinations[i] , _Combinations[i+2]); - int phiRange = int(std::abs(phiDiff/_dPhi)*(1.0 + _safetyPhiRange_ratio)) + _safetyPhiRange_fix; - //check - if(_mydebug) std::cout << "phiRange for Triplet (layer " << _Combinations[i] << " " << _Combinations[i+2] <<" ) : " << phiRange << std::endl; - _phiRangeForTriplet.insert(std::make_pair(lyp,phiRange)); + for (int i = 0; i < ncomb; i += 3) { + std::pair lyp(_Combinations[i], _Combinations[i + 2]); + double phiDiff = getNeededPhiSectors(_cutOnPtVXD, _Combinations[i], _Combinations[i + 2]); + int phiRange = int(std::abs(phiDiff / _dPhi) * (1.0 + _safetyPhiRange_ratio)) + _safetyPhiRange_fix; + // check + if (_mydebug) + std::cout << "phiRange for Triplet (layer " << _Combinations[i] << " " << _Combinations[i + 2] + << " ) : " << phiRange << std::endl; + _phiRangeForTriplet.insert(std::make_pair(lyp, phiRange)); } #endif - - - - - - } +void FPCCDSiliconTracking_MarlinTrk::processRunHeader(LCRunHeader*) { -void FPCCDSiliconTracking_MarlinTrk::processRunHeader( LCRunHeader* ) { - - _nRun++ ; + _nRun++; _nEvt = 0; streamlog_out(MESSAGE) << "FPCCDSiliconTracking_MarlinTrk ---> new run : run number = " << _nRun << std::endl; +} -} - - -void FPCCDSiliconTracking_MarlinTrk::processEvent( LCEvent * evt ) { +void FPCCDSiliconTracking_MarlinTrk::processEvent(LCEvent* evt) { - if(_stopwatch){ + if (_stopwatch) { _timer.reset(); _timer.inAnEvt.Start(); } - // set the correct configuration for the tracking system for this event - MarlinTrk::TrkSysConfig< MarlinTrk::IMarlinTrkSystem::CFG::useQMS> mson( _trksystem, _MSOn ) ; - MarlinTrk::TrkSysConfig< MarlinTrk::IMarlinTrkSystem::CFG::usedEdx> elosson( _trksystem,_ElossOn) ; - MarlinTrk::TrkSysConfig< MarlinTrk::IMarlinTrkSystem::CFG::useSmoothing> smoothon( _trksystem,_SmoothOn) ; + // set the correct configuration for the tracking system for this event + MarlinTrk::TrkSysConfig mson(_trksystem, _MSOn); + MarlinTrk::TrkSysConfig elosson(_trksystem, _ElossOn); + MarlinTrk::TrkSysConfig smoothon(_trksystem, _SmoothOn); - //check + // check std::cout << "=========== evt num : " << _nEvt << " =================" << std::endl; - _current_event = evt; _output_track_col_quality = _output_track_col_quality_GOOD; @@ -682,208 +570,202 @@ void FPCCDSiliconTracking_MarlinTrk::processEvent( LCEvent * evt ) { _colTrackerHits.clear(); _colNamesTrackerHits.clear(); + streamlog_out(DEBUG4) << "FPCCDSiliconTracking_MarlinTrk -> run = " << _nRun << " event = " << _nEvt << std::endl; + if (_stopwatch) + _timer.InitialiseVTX.Start(); + int successVTX = InitialiseVTX(evt); + if (_stopwatch) + _timer.InitialiseVTX.Stop(); + if (_stopwatch) + _timer.InitialiseFTD.Start(); + int successFTD = InitialiseFTD(evt); + if (_stopwatch) + _timer.InitialiseFTD.Stop(); - streamlog_out(DEBUG4) << "FPCCDSiliconTracking_MarlinTrk -> run = " << _nRun - << " event = " << _nEvt << std::endl; - - if(_stopwatch) _timer.InitialiseVTX.Start(); - int successVTX = InitialiseVTX( evt ); - if(_stopwatch) _timer.InitialiseVTX.Stop(); - - if(_stopwatch) _timer.InitialiseFTD.Start(); - int successFTD = InitialiseFTD( evt ); - if(_stopwatch) _timer.InitialiseFTD.Stop(); - - - - - if(_stopwatch) _timer.ProcessOneSector.Start(); + if (_stopwatch) + _timer.ProcessOneSector.Start(); if (successVTX == 1) { - streamlog_out(DEBUG1) << " phi theta layer nh o : m : i :: o*m*i " << std::endl; - for (int iPhi=0; iPhi<_nDivisionsInPhi; ++iPhi) { - for (int iTheta=0; iTheta<_nDivisionsInTheta;++iTheta) { - ProcessOneSector(iPhi,iTheta); // Process one VXD sector + streamlog_out(DEBUG1) << " phi theta layer nh o : m : i :: o*m*i " << std::endl; + for (int iPhi = 0; iPhi < _nDivisionsInPhi; ++iPhi) { + for (int iTheta = 0; iTheta < _nDivisionsInTheta; ++iTheta) { + ProcessOneSector(iPhi, iTheta); // Process one VXD sector } } streamlog_out(DEBUG4) << "End of Processing VXD and SIT sectors" << std::endl; - if(_mydebugstopwatch2){ - printf("_timer2Triplet : RT=%.3f s, CPU=%.3f s, count=%d \n",_timer2Triplet.RealTime(),_timer2Triplet.CpuTime(),_timer2Triplet.Counter()); - printf("_timer2Build : RT=%.3f s, CPU=%.3f s, count=%d \n",_timer2Build.RealTime(),_timer2Build.CpuTime(),_timer2Build.Counter()); + if (_mydebugstopwatch2) { + printf("_timer2Triplet : RT=%.3f s, CPU=%.3f s, count=%d \n", _timer2Triplet.RealTime(), + _timer2Triplet.CpuTime(), _timer2Triplet.Counter()); + printf("_timer2Build : RT=%.3f s, CPU=%.3f s, count=%d \n", _timer2Build.RealTime(), _timer2Build.CpuTime(), + _timer2Build.Counter()); } } - if(_stopwatch) _timer.ProcessOneSector.Stop(); - - - - + if (_stopwatch) + _timer.ProcessOneSector.Stop(); - - if(_stopwatch) _timer.TrackingInFTD.Start(); + if (_stopwatch) + _timer.TrackingInFTD.Start(); if (successFTD == 1) { streamlog_out(DEBUG1) << " phi side layer nh o : m : i :: o*m*i " << std::endl; TrackingInFTD(); // Perform tracking in the FTD streamlog_out(DEBUG4) << "End of Processing FTD sectors" << std::endl; } - if(_stopwatch) _timer.TrackingInFTD.Stop(); - + if (_stopwatch) + _timer.TrackingInFTD.Stop(); if (successVTX == 1 || successFTD == 1) { - if(_stopwatch) _timer.Sorting.Start(); + if (_stopwatch) + _timer.Sorting.Start(); for (int nHits = _nHitsChi2; nHits >= _minimalHits; nHits--) { - Sorting( _tracksWithNHitsContainer.getTracksWithNHitsVec( nHits ) ); + Sorting(_tracksWithNHitsContainer.getTracksWithNHitsVec(nHits)); } - streamlog_out(DEBUG4) << "End of Sorting " << std::endl; - if(_stopwatch) _timer.Sorting.Stop(); + streamlog_out(DEBUG4) << "End of Sorting " << std::endl; + if (_stopwatch) + _timer.Sorting.Stop(); - if(_stopwatch) _timer.CreateTrack.Start(); - for (int nHits = _nHitsChi2; nHits >= _minimalHits ; nHits--) { - TrackExtendedVec &tracksWithNHits = _tracksWithNHitsContainer.getTracksWithNHitsVec( nHits ); - for (TrackExtendedVec::iterator trackIter = tracksWithNHits.begin(); trackIter < tracksWithNHits.end(); trackIter++) { + if (_stopwatch) + _timer.CreateTrack.Start(); + for (int nHits = _nHitsChi2; nHits >= _minimalHits; nHits--) { + TrackExtendedVec& tracksWithNHits = _tracksWithNHitsContainer.getTracksWithNHitsVec(nHits); + for (TrackExtendedVec::iterator trackIter = tracksWithNHits.begin(); trackIter < tracksWithNHits.end(); + trackIter++) { - CreateTrack( *trackIter); + CreateTrack(*trackIter); } - streamlog_out(DEBUG4) << "End of creating "<< nHits << " hits tracks " << std::endl; + streamlog_out(DEBUG4) << "End of creating " << nHits << " hits tracks " << std::endl; } - if(_stopwatch) _timer.CreateTrack.Stop(); - - - if(_stopwatch) _timer.AttachRemainingVXD.Start(); - if (_attachVXD == 1) AttachRemainingVTXHitsFast(); - else if(_attachVXD == 2) AttachRemainingVTXHitsSlow(); - else if (_attachVXD == 3) AttachRemainingVTXHitsVeryFast(); - if(_stopwatch) _timer.AttachRemainingVXD.Stop(); - - if(_stopwatch) _timer.AttachRemainingFTD.Start(); - if (_attachFTD == 1) AttachRemainingFTDHitsFast(); - else if (_attachFTD == 2) AttachRemainingFTDHitsSlow(); - if(_stopwatch) _timer.AttachRemainingFTD.Stop(); - - - streamlog_out(DEBUG4) << "End of picking up remaining hits " << std::endl; - - LCCollectionVec * trkCol = new LCCollectionVec(LCIO::TRACK); + if (_stopwatch) + _timer.CreateTrack.Stop(); + + if (_stopwatch) + _timer.AttachRemainingVXD.Start(); + if (_attachVXD == 1) + AttachRemainingVTXHitsFast(); + else if (_attachVXD == 2) + AttachRemainingVTXHitsSlow(); + else if (_attachVXD == 3) + AttachRemainingVTXHitsVeryFast(); + if (_stopwatch) + _timer.AttachRemainingVXD.Stop(); + + if (_stopwatch) + _timer.AttachRemainingFTD.Start(); + if (_attachFTD == 1) + AttachRemainingFTDHitsFast(); + else if (_attachFTD == 2) + AttachRemainingFTDHitsSlow(); + if (_stopwatch) + _timer.AttachRemainingFTD.Stop(); + + streamlog_out(DEBUG4) << "End of picking up remaining hits " << std::endl; + + LCCollectionVec* trkCol = new LCCollectionVec(LCIO::TRACK); // if we want to point back to the hits we need to set the flag - LCFlagImpl trkFlag(0) ; - trkFlag.setBit( LCIO::TRBIT_HITS ) ; - trkCol->setFlag( trkFlag.getFlag() ) ; + LCFlagImpl trkFlag(0); + trkFlag.setBit(LCIO::TRBIT_HITS); + trkCol->setFlag(trkFlag.getFlag()); - LCCollectionVec * relCol = NULL; + LCCollectionVec* relCol = NULL; - if(_stopwatch) _timer.FinalRefit.Start(); + if (_stopwatch) + _timer.FinalRefit.Start(); FinalRefit(trkCol, relCol); - if(_stopwatch) _timer.FinalRefit.Stop(); - + if (_stopwatch) + _timer.FinalRefit.Stop(); // set the quality of the output collection switch (_output_track_col_quality) { - case _output_track_col_quality_FAIR: - trkCol->parameters().setValue( "QualityCode" , "Fair" ) ; - break; + case _output_track_col_quality_FAIR: + trkCol->parameters().setValue("QualityCode", "Fair"); + break; - case _output_track_col_quality_POOR: - trkCol->parameters().setValue( "QualityCode" , "Poor" ) ; - break; + case _output_track_col_quality_POOR: + trkCol->parameters().setValue("QualityCode", "Poor"); + break; - default: - trkCol->parameters().setValue( "QualityCode" , "Good" ) ; - break; + default: + trkCol->parameters().setValue("QualityCode", "Good"); + break; } - - evt->addCollection(trkCol,_siTrkCollection.c_str()); - - - + evt->addCollection(trkCol, _siTrkCollection.c_str()); } - - CleanUp(); streamlog_out(DEBUG4) << "Event is done " << std::endl; - - if(_stopwatch){ + if (_stopwatch) { _timer.inAnEvt.Stop(); _timer.cout(); } - - - - - - _nEvt++; - } - void FPCCDSiliconTracking_MarlinTrk::CleanUp() { _tracksWithNHitsContainer.clear(); - for (int il=0;il<_nLayers;++il) { - for (int ip=0;ip<_nDivisionsInPhi;++ip) { - for (int it=0;it<_nDivisionsInTheta; ++it) { - unsigned int iCode = il + _nLayers*ip + _nLayers*_nDivisionsInPhi*it; + for (int il = 0; il < _nLayers; ++il) { + for (int ip = 0; ip < _nDivisionsInPhi; ++ip) { + for (int it = 0; it < _nDivisionsInTheta; ++it) { + unsigned int iCode = il + _nLayers * ip + _nLayers * _nDivisionsInPhi * it; - if( iCode >= _sectors.size()){ - std::cout<< "iCode index out of range: iCode = " << iCode << " _sectors.size() = " << _sectors.size() << " exit(1) called from file " << __FILE__ << " line " << __LINE__<< std::endl; + if (iCode >= _sectors.size()) { + std::cout << "iCode index out of range: iCode = " << iCode << " _sectors.size() = " << _sectors.size() + << " exit(1) called from file " << __FILE__ << " line " << __LINE__ << std::endl; exit(1); } - TrackerHitExtendedVec& hitVec = _sectors[iCode]; int nH = int(hitVec.size()); - for (int iH=0; iH= _sectorsFTD.size()){ - std::cout<< "iCode index out of range: iCode = " << iCode << " _sectorsFTD.size() = " << _sectorsFTD.size() << " exit(1) called from file " << __FILE__ << " line " << __LINE__<< std::endl; + if (iCode >= _sectorsFTD.size()) { + std::cout << "iCode index out of range: iCode = " << iCode << " _sectorsFTD.size() = " << _sectorsFTD.size() + << " exit(1) called from file " << __FILE__ << " line " << __LINE__ << std::endl; exit(1); } - TrackerHitExtendedVec& hitVec = _sectorsFTD[iCode]; int nH = int(hitVec.size()); - for (int iH=0; iHgetCollection(_FTDPixelHitCollection.c_str()); + LCCollection* hitCollection = evt->getCollection(_FTDPixelHitCollection.c_str()); - _colNamesTrackerHits[hitCollection] = _FTDPixelHitCollection; + _colNamesTrackerHits[hitCollection] = _FTDPixelHitCollection; _colTrackerHits.push_back(hitCollection); int nelem = hitCollection->getNumberOfElements(); @@ -891,100 +773,103 @@ int FPCCDSiliconTracking_MarlinTrk::InitialiseFTD(LCEvent * evt) { streamlog_out(DEBUG4) << "Number of FTD Pixel Hits = " << nelem << std::endl; _nTotalFTDHits = nelem; - for (int ielem=0; ielem(hitCollection->getElementAt(ielem)); + TrackerHitPlane* hit = dynamic_cast(hitCollection->getElementAt(ielem)); - TrackerHitExtended * hitExt = new TrackerHitExtended( hit ); + TrackerHitExtended* hitExt = new TrackerHitExtended(hit); - Vector3D U(1.0,hit->getU()[1],hit->getU()[0],Vector3D::spherical); - Vector3D V(1.0,hit->getV()[1],hit->getV()[0],Vector3D::spherical); - Vector3D Z(0.0,0.0,1.0); + Vector3D U(1.0, hit->getU()[1], hit->getU()[0], Vector3D::spherical); + Vector3D V(1.0, hit->getV()[1], hit->getV()[0], Vector3D::spherical); + Vector3D Z(0.0, 0.0, 1.0); const float eps = 1.0e-07; - // V must be the global z axis - if( fabs(V.dot(Z)) > eps ) { - streamlog_out(ERROR) << "FPCCDSiliconTracking_MarlinTrk: VXD Hit measurment vectors V is not in the global X-Y plane. \n\n exit(1) called from file " << __FILE__ << " and line " << __LINE__ << std::endl; + // V must be the global z axis + if (fabs(V.dot(Z)) > eps) { + streamlog_out(ERROR) << "FPCCDSiliconTracking_MarlinTrk: VXD Hit measurment vectors V is not in the global X-Y " + "plane. \n\n exit(1) called from file " + << __FILE__ << " and line " << __LINE__ << std::endl; exit(1); } - if( fabs(U.dot(Z)) > eps ) { - streamlog_out(ERROR) << "FPCCDSiliconTracking_MarlinTrk: VXD Hit measurment vectors U is not in the global X-Y plane. \n\n exit(1) called from file " << __FILE__ << " and line " << __LINE__ << std::endl; + if (fabs(U.dot(Z)) > eps) { + streamlog_out(ERROR) << "FPCCDSiliconTracking_MarlinTrk: VXD Hit measurment vectors U is not in the global X-Y " + "plane. \n\n exit(1) called from file " + << __FILE__ << " and line " << __LINE__ << std::endl; exit(1); } - - // SJA:FIXME Here dU and dV are almost certainly dX and dY ... should test ... - double point_res_rphi = sqrt( hit->getdU()*hit->getdU() + hit->getdV()*hit->getdV() ); + double point_res_rphi = sqrt(hit->getdU() * hit->getdU() + hit->getdV() * hit->getdV()); - hitExt->setResolutionRPhi( point_res_rphi ); + hitExt->setResolutionRPhi(point_res_rphi); - // SJA:FIXME why is this needed? + // SJA:FIXME why is this needed? hitExt->setResolutionZ(0.1); - // type is now only used in one place where it is set to 0 to reject hits from a fit, set to INT_MAX to try and catch any missuse + // type is now only used in one place where it is set to 0 to reject hits from a fit, set to INT_MAX to try and + // catch any missuse hitExt->setType(int(INT_MAX)); // det is no longer used set to INT_MAX to try and catch any missuse hitExt->setDet(int(INT_MAX)); double pos[3]; - for (int i=0; i<3; ++i) { + for (int i = 0; i < 3; ++i) { pos[i] = hit->getPosition()[i]; } - double Phi = atan2(pos[1],pos[0]); - if (Phi < 0.) Phi = Phi + TWOPI; + double Phi = atan2(pos[1], pos[0]); + if (Phi < 0.) + Phi = Phi + TWOPI; // get the layer number unsigned int layer = static_cast(getLayerID(hit)); unsigned int petalIndex = static_cast(getModuleID(hit)); - if ( _petalBasedFTDWithOverlaps == true ) { + if (_petalBasedFTDWithOverlaps == true) { // as we are dealing with staggered petals we will use 2*nlayers in each directions +/- z - // the layers will follow the even odd numbering of the petals - if ( petalIndex % 2 == 0 ) { - layer = 2*layer; - } - else { - layer = 2*layer + 1; + // the layers will follow the even odd numbering of the petals + if (petalIndex % 2 == 0) { + layer = 2 * layer; + } else { + layer = 2 * layer + 1; } - } if (layer >= _nlayersFTD) { - streamlog_out(ERROR) << "FPCCDSiliconTracking_MarlinTrk => fatal error in FTD : layer is outside allowed range : " << layer << " number of layers = " << _nlayersFTD << std::endl; + streamlog_out(ERROR) + << "FPCCDSiliconTracking_MarlinTrk => fatal error in FTD : layer is outside allowed range : " << layer + << " number of layers = " << _nlayersFTD << std::endl; exit(1); } - int iPhi = int(Phi/_dPhiFTD); + int iPhi = int(Phi / _dPhiFTD); int side = getSideID(hit); int iSemiSphere = 0; - if (side > 0) + if (side > 0) iSemiSphere = 1; - int iCode = iSemiSphere + 2*layer + 2*_nlayersFTD*iPhi; - _sectorsFTD[iCode].push_back( hitExt ); - - streamlog_out( DEBUG1 ) << " FTD Pixel Hit added : @ " << pos[0] << " " << pos[1] << " " << pos[2] << " drphi " << hitExt->getResolutionRPhi() << " dz " << hitExt->getResolutionZ() << " iPhi = " << iPhi << " iSemiSphere " << iSemiSphere << " iCode = " << iCode << " layer = " << layer << std::endl; - + int iCode = iSemiSphere + 2 * layer + 2 * _nlayersFTD * iPhi; + _sectorsFTD[iCode].push_back(hitExt); + streamlog_out(DEBUG1) << " FTD Pixel Hit added : @ " << pos[0] << " " << pos[1] << " " << pos[2] << " drphi " + << hitExt->getResolutionRPhi() << " dz " << hitExt->getResolutionZ() << " iPhi = " << iPhi + << " iSemiSphere " << iSemiSphere << " iCode = " << iCode << " layer = " << layer + << std::endl; } - } - catch(DataNotAvailableException &e ) { + } catch (DataNotAvailableException& e) { success = 0; } - // Reading out FTD SpacePoint Collection //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ try { - LCCollection * hitCollection = evt->getCollection(_FTDSpacePointCollection.c_str()); + LCCollection* hitCollection = evt->getCollection(_FTDSpacePointCollection.c_str()); _colNamesTrackerHits[hitCollection] = _FTDSpacePointCollection; _colTrackerHits.push_back(hitCollection); @@ -994,110 +879,113 @@ int FPCCDSiliconTracking_MarlinTrk::InitialiseFTD(LCEvent * evt) { streamlog_out(DEBUG4) << "Number of FTD SpacePoints = " << nelem << std::endl; _nTotalFTDHits += nelem; - for (int ielem=0; ielem(hitCollection->getElementAt(ielem)); + TrackerHit* hit = dynamic_cast(hitCollection->getElementAt(ielem)); - TrackerHitExtended * hitExt = new TrackerHitExtended( hit ); + TrackerHitExtended* hitExt = new TrackerHitExtended(hit); // SJA:FIXME: fudge for now by a factor of two and ignore covariance - double point_res_rphi = 2 * sqrt( hit->getCovMatrix()[0] + hit->getCovMatrix()[2] ); + double point_res_rphi = 2 * sqrt(hit->getCovMatrix()[0] + hit->getCovMatrix()[2]); - hitExt->setResolutionRPhi( point_res_rphi ); + hitExt->setResolutionRPhi(point_res_rphi); - // SJA:FIXME why is this needed? + // SJA:FIXME why is this needed? hitExt->setResolutionZ(0.1); - // type is now only used in one place where it is set to 0 to reject hits from a fit, set to INT_MAX to try and catch any missuse + // type is now only used in one place where it is set to 0 to reject hits from a fit, set to INT_MAX to try and + // catch any missuse hitExt->setType(int(INT_MAX)); // det is no longer used set to INT_MAX to try and catch any missuse hitExt->setDet(int(INT_MAX)); double pos[3]; - for (int i=0; i<3; ++i) { + for (int i = 0; i < 3; ++i) { pos[i] = hit->getPosition()[i]; } - double Phi = atan2(pos[1],pos[0]); - if (Phi < 0.) Phi = Phi + TWOPI; + double Phi = atan2(pos[1], pos[0]); + if (Phi < 0.) + Phi = Phi + TWOPI; // get the layer number unsigned int layer = static_cast(getLayerID(hit)); unsigned int petalIndex = static_cast(getModuleID(hit)); - if ( _petalBasedFTDWithOverlaps == true ) { + if (_petalBasedFTDWithOverlaps == true) { // as we are dealing with staggered petals we will use 2*nlayers in each directions +/- z - // the layers will follow the even odd numbering of the petals - if ( petalIndex % 2 == 0 ) { - layer = 2*layer; + // the layers will follow the even odd numbering of the petals + if (petalIndex % 2 == 0) { + layer = 2 * layer; + } else { + layer = 2 * layer + 1; } - else { - layer = 2*layer + 1; - } - } if (layer >= _nlayersFTD) { - streamlog_out(ERROR) << "FPCCDSiliconTracking_MarlinTrk => fatal error in FTD : layer is outside allowed range : " << layer << " number of layers = " << _nlayersFTD << std::endl; + streamlog_out(ERROR) + << "FPCCDSiliconTracking_MarlinTrk => fatal error in FTD : layer is outside allowed range : " << layer + << " number of layers = " << _nlayersFTD << std::endl; exit(1); } - int iPhi = int(Phi/_dPhiFTD); + int iPhi = int(Phi / _dPhiFTD); int side = getSideID(hit); int iSemiSphere = 0; - if (side > 0) + if (side > 0) iSemiSphere = 1; - int iCode = iSemiSphere + 2*layer + 2*_nlayersFTD*iPhi; - _sectorsFTD[iCode].push_back( hitExt ); - - streamlog_out( DEBUG1 ) << " FTD SpacePoint Hit added : @ " << pos[0] << " " << pos[1] << " " << pos[2] << " drphi " << hitExt->getResolutionRPhi() << " dz " << hitExt->getResolutionZ() << " iPhi = " << iPhi << " iSemiSphere " << iSemiSphere << " iCode = " << iCode << " layer = " << layer << std::endl; + int iCode = iSemiSphere + 2 * layer + 2 * _nlayersFTD * iPhi; + _sectorsFTD[iCode].push_back(hitExt); + streamlog_out(DEBUG1) << " FTD SpacePoint Hit added : @ " << pos[0] << " " << pos[1] << " " << pos[2] << " drphi " + << hitExt->getResolutionRPhi() << " dz " << hitExt->getResolutionZ() << " iPhi = " << iPhi + << " iSemiSphere " << iSemiSphere << " iCode = " << iCode << " layer = " << layer + << std::endl; } - } - catch(DataNotAvailableException &e ) { + } catch (DataNotAvailableException& e) { success = 0; } - for (unsigned i=0; i<_sectorsFTD.size(); ++i) { + for (unsigned i = 0; i < _sectorsFTD.size(); ++i) { int nhits = _sectorsFTD[i].size(); - if( nhits != 0 ) streamlog_out(DEBUG1) << " Number of Hits in FTD Sector " << i << " = " << _sectorsFTD[i].size() << std::endl; + if (nhits != 0) + streamlog_out(DEBUG1) << " Number of Hits in FTD Sector " << i << " = " << _sectorsFTD[i].size() << std::endl; if (nhits > _max_hits_per_sector) { - for (unsigned ihit=0; ihit<_sectorsFTD[i].size(); ++ihit) { + for (unsigned ihit = 0; ihit < _sectorsFTD[i].size(); ++ihit) { delete _sectorsFTD[i][ihit]; - } + } _sectorsFTD[i].clear(); - if( nhits != 0 ) streamlog_out(ERROR) << " ### EVENT " << evt->getEventNumber() << " :: RUN " << evt->getRunNumber() << " \n ### Number of Hits in FTD Sector " << i << " = " << nhits << " : Limit is set to " << _max_hits_per_sector << " : This sector will be dropped from track search, and QualityCode set to \"Poor\" " << std::endl; + if (nhits != 0) + streamlog_out(ERROR) << " ### EVENT " << evt->getEventNumber() << " :: RUN " << evt->getRunNumber() + << " \n ### Number of Hits in FTD Sector " << i << " = " << nhits << " : Limit is set to " + << _max_hits_per_sector + << " : This sector will be dropped from track search, and QualityCode set to \"Poor\" " + << std::endl; _output_track_col_quality = _output_track_col_quality_POOR; - } - } return success; - } -int FPCCDSiliconTracking_MarlinTrk::InitialiseVTX(LCEvent * evt) { - - +int FPCCDSiliconTracking_MarlinTrk::InitialiseVTX(LCEvent* evt) { _nTotalVTXHits = 0; _nTotalSITHits = 0; _sectors.clear(); - _sectors.resize(_nLayers*_nDivisionsInPhi*_nDivisionsInTheta); - + _sectors.resize(_nLayers * _nDivisionsInPhi * _nDivisionsInTheta); // Reading out VTX Hits Collection - //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ try { - LCCollection * hitCollection = evt->getCollection(_VTXHitCollection.c_str()); + LCCollection* hitCollection = evt->getCollection(_VTXHitCollection.c_str()); _colNamesTrackerHits[hitCollection] = _VTXHitCollection; _colTrackerHits.push_back(hitCollection); @@ -1107,35 +995,38 @@ int FPCCDSiliconTracking_MarlinTrk::InitialiseVTX(LCEvent * evt) { streamlog_out(DEBUG4) << "Number of VTX hits = " << nelem << std::endl; _nTotalVTXHits = nelem; - for (int ielem=0; ielem(hitCollection->getElementAt(ielem)); + TrackerHitPlane* hit = dynamic_cast(hitCollection->getElementAt(ielem)); - Vector3D U(1.0,hit->getU()[1],hit->getU()[0],Vector3D::spherical); - Vector3D V(1.0,hit->getV()[1],hit->getV()[0],Vector3D::spherical); - Vector3D Z(0.0,0.0,1.0); + Vector3D U(1.0, hit->getU()[1], hit->getU()[0], Vector3D::spherical); + Vector3D V(1.0, hit->getV()[1], hit->getV()[0], Vector3D::spherical); + Vector3D Z(0.0, 0.0, 1.0); const float eps = 1.0e-07; - // V must be the global z axis - if( fabs(1.0 - V.dot(Z)) > eps ) { - streamlog_out(ERROR) << "FPCCDSiliconTracking_MarlinTrk: VXD Hit measurment vectors V is not equal to the global Z axis. \n\n exit(1) called from file " << __FILE__ << " and line " << __LINE__ << std::endl; + // V must be the global z axis + if (fabs(1.0 - V.dot(Z)) > eps) { + streamlog_out(ERROR) << "FPCCDSiliconTracking_MarlinTrk: VXD Hit measurment vectors V is not equal to the " + "global Z axis. \n\n exit(1) called from file " + << __FILE__ << " and line " << __LINE__ << std::endl; exit(1); } - if( fabs(U.dot(Z)) > eps ) { - streamlog_out(ERROR) << "FPCCDSiliconTracking_MarlinTrk: VXD Hit measurment vectors U is not in the global X-Y plane. \n\n exit(1) called from file " << __FILE__ << " and line " << __LINE__ << std::endl; + if (fabs(U.dot(Z)) > eps) { + streamlog_out(ERROR) << "FPCCDSiliconTracking_MarlinTrk: VXD Hit measurment vectors U is not in the global X-Y " + "plane. \n\n exit(1) called from file " + << __FILE__ << " and line " << __LINE__ << std::endl; exit(1); } - - TrackerHitExtended * hitExt = new TrackerHitExtended( hit ); - + TrackerHitExtended* hitExt = new TrackerHitExtended(hit); // SJA:FIXME: just use planar res for now hitExt->setResolutionRPhi(hit->getdU()); hitExt->setResolutionZ(hit->getdV()); - // set type is now only used in one place where it is set to 0 to reject hits from a fit, set to INT_MAX to try and catch any missuse + // set type is now only used in one place where it is set to 0 to reject hits from a fit, set to INT_MAX to try + // and catch any missuse hitExt->setType(int(INT_MAX)); // det is no longer used set to INT_MAX to try and catch any missuse hitExt->setDet(int(INT_MAX)); @@ -1143,45 +1034,47 @@ int FPCCDSiliconTracking_MarlinTrk::InitialiseVTX(LCEvent * evt) { double pos[3]; double radius = 0; - for (int i=0; i<3; ++i) { + for (int i = 0; i < 3; ++i) { pos[i] = hit->getPosition()[i]; - radius += pos[i]*pos[i]; + radius += pos[i] * pos[i]; } radius = sqrt(radius); - double cosTheta = pos[2]/radius; - double Phi = atan2(pos[1],pos[0]); + double cosTheta = pos[2] / radius; + double Phi = atan2(pos[1], pos[0]); - if (Phi < 0.) Phi = Phi + TWOPI; + if (Phi < 0.) + Phi = Phi + TWOPI; // get the layer number int layer = getLayerID(hit); if (layer < 0 || layer >= _nLayers) { - streamlog_out(ERROR) << "FPCCDSiliconTracking_MarlinTrk => fatal error in VTX : layer is outside allowed range : " << layer << std::endl; + streamlog_out(ERROR) + << "FPCCDSiliconTracking_MarlinTrk => fatal error in VTX : layer is outside allowed range : " << layer + << std::endl; exit(1); } - int iPhi = int(Phi/_dPhi); - int iTheta = int ((cosTheta + double(1.0))/_dTheta); - int iCode = layer + _nLayers*iPhi + _nLayers*_nDivisionsInPhi*iTheta; - _sectors[iCode].push_back( hitExt ); - - streamlog_out( DEBUG1 ) << " VXD Hit " << hit->id() << " added : @ " << pos[0] << " " << pos[1] << " " << pos[2] << " drphi " << hitExt->getResolutionRPhi() << " dz " << hitExt->getResolutionZ() << " iPhi = " << iPhi << " iTheta " << iTheta << " iCode = " << iCode << " layer = " << layer << std::endl; - + int iPhi = int(Phi / _dPhi); + int iTheta = int((cosTheta + double(1.0)) / _dTheta); + int iCode = layer + _nLayers * iPhi + _nLayers * _nDivisionsInPhi * iTheta; + _sectors[iCode].push_back(hitExt); + streamlog_out(DEBUG1) << " VXD Hit " << hit->id() << " added : @ " << pos[0] << " " << pos[1] << " " << pos[2] + << " drphi " << hitExt->getResolutionRPhi() << " dz " << hitExt->getResolutionZ() + << " iPhi = " << iPhi << " iTheta " << iTheta << " iCode = " << iCode + << " layer = " << layer << std::endl; } - } - catch(DataNotAvailableException &e) { - streamlog_out( DEBUG4 ) << " collection not found : " << _VTXHitCollection.c_str() << std::endl ; + } catch (DataNotAvailableException& e) { + streamlog_out(DEBUG4) << " collection not found : " << _VTXHitCollection.c_str() << std::endl; } - if (_useSIT > 0 ) { - + if (_useSIT > 0) { try { - LCCollection *hitCollection = evt->getCollection(_SITHitCollection.c_str()); + LCCollection* hitCollection = evt->getCollection(_SITHitCollection.c_str()); _colNamesTrackerHits[hitCollection] = _SITHitCollection; _colTrackerHits.push_back(hitCollection); @@ -1191,14 +1084,14 @@ int FPCCDSiliconTracking_MarlinTrk::InitialiseVTX(LCEvent * evt) { streamlog_out(DEBUG4) << "Number of SIT hits = " << nelem << std::endl; _nTotalSITHits = nelem; - TrackerHit* trkhit = 0; - TrackerHitPlane* trkhit_P = 0; + TrackerHit* trkhit = 0; + TrackerHitPlane* trkhit_P = 0; TrackerHitZCylinder* trkhit_C = 0; double drphi(NAN); double dz(NAN); - for (int ielem=0; ielem(hitCollection->getElementAt(ielem)); @@ -1220,76 +1112,86 @@ int FPCCDSiliconTracking_MarlinTrk::InitialiseVTX(LCEvent * evt) { layer = layer + _nLayersVTX; if (layer < 0 || layer >= _nLayers) { - streamlog_out(ERROR) << "FPCCDSiliconTracking_MarlinTrk => fatal error in SIT : layer is outside allowed range : " << layer << std::endl; + streamlog_out(ERROR) + << "FPCCDSiliconTracking_MarlinTrk => fatal error in SIT : layer is outside allowed range : " << layer + << std::endl; exit(1); } // first check that we have not been given 1D hits by mistake, as they won't work here - if ( BitSet32( trkhit->getType() )[ UTIL::ILDTrkHitTypeBit::ONE_DIMENSIONAL ] ) { + if (BitSet32(trkhit->getType())[UTIL::ILDTrkHitTypeBit::ONE_DIMENSIONAL]) { - streamlog_out(ERROR) << "FPCCDSiliconTracking_MarlinTrk: SIT Hit cannot be of type UTIL::ILDTrkHitTypeBit::ONE_DIMENSIONAL COMPOSITE SPACEPOINTS must be use instead. \n\n exit(1) called from file " << __FILE__ << " and line " << __LINE__ << std::endl; + streamlog_out(ERROR) + << "FPCCDSiliconTracking_MarlinTrk: SIT Hit cannot be of type UTIL::ILDTrkHitTypeBit::ONE_DIMENSIONAL " + "COMPOSITE SPACEPOINTS must be use instead. \n\n exit(1) called from file " + << __FILE__ << " and line " << __LINE__ << std::endl; exit(1); - } + } // most likely case: COMPOSITE_SPACEPOINT hits formed from stereo strip hits - else if ( BitSet32( trkhit->getType() )[ UTIL::ILDTrkHitTypeBit::COMPOSITE_SPACEPOINT ] ) { + else if (BitSet32(trkhit->getType())[UTIL::ILDTrkHitTypeBit::COMPOSITE_SPACEPOINT]) { // SJA:FIXME: fudge for now by a factor of two and ignore covariance // MORI:FIXME: fudge factor is now changeable in steering file. - drphi = _fudgeFactorForSITsr_rphi * sqrt(trkhit->getCovMatrix()[0] + trkhit->getCovMatrix()[2]); - dz = _fudgeFactorForSITsr_z * sqrt(trkhit->getCovMatrix()[5]); + drphi = _fudgeFactorForSITsr_rphi * sqrt(trkhit->getCovMatrix()[0] + trkhit->getCovMatrix()[2]); + dz = _fudgeFactorForSITsr_z * sqrt(trkhit->getCovMatrix()[5]); - } + } // or a PIXEL based SIT, using 2D TrackerHitPlane like the VXD above - else if ( ( trkhit_P = dynamic_cast( hitCollection->getElementAt( ielem ) ) ) ) { + else if ((trkhit_P = dynamic_cast(hitCollection->getElementAt(ielem)))) { - // first we need to check if the measurement vectors are aligned with the global coordinates - Vector3D U(1.0,trkhit_P->getU()[1],trkhit_P->getU()[0],Vector3D::spherical); - Vector3D V(1.0,trkhit_P->getV()[1],trkhit_P->getV()[0],Vector3D::spherical); - Vector3D Z(0.0,0.0,1.0); + // first we need to check if the measurement vectors are aligned with the global coordinates + Vector3D U(1.0, trkhit_P->getU()[1], trkhit_P->getU()[0], Vector3D::spherical); + Vector3D V(1.0, trkhit_P->getV()[1], trkhit_P->getV()[0], Vector3D::spherical); + Vector3D Z(0.0, 0.0, 1.0); const float eps = 1.0e-07; - // V must be the global z axis - if( fabs(1.0 - V.dot(Z)) > eps ) { - streamlog_out(ERROR) << "FPCCDSiliconTracking_MarlinTrk: PIXEL SIT Hit measurment vectors V is not equal to the global Z axis. \n\n exit(1) called from file " << __FILE__ << " and line " << __LINE__ << std::endl; + // V must be the global z axis + if (fabs(1.0 - V.dot(Z)) > eps) { + streamlog_out(ERROR) << "FPCCDSiliconTracking_MarlinTrk: PIXEL SIT Hit measurment vectors V is not equal " + "to the global Z axis. \n\n exit(1) called from file " + << __FILE__ << " and line " << __LINE__ << std::endl; exit(1); } // U must be normal to the global z axis - if( fabs(U.dot(Z)) > eps ) { - streamlog_out(ERROR) << "FPCCDSiliconTracking_MarlinTrk: PIXEL SIT Hit measurment vectors U is not in the global X-Y plane. \n\n exit(1) called from file " << __FILE__ << " and line " << __LINE__ << std::endl; + if (fabs(U.dot(Z)) > eps) { + streamlog_out(ERROR) << "FPCCDSiliconTracking_MarlinTrk: PIXEL SIT Hit measurment vectors U is not in the " + "global X-Y plane. \n\n exit(1) called from file " + << __FILE__ << " and line " << __LINE__ << std::endl; exit(1); } drphi = trkhit_P->getdU(); - dz = trkhit_P->getdV(); + dz = trkhit_P->getdV(); - } - // or a simple cylindrical design, as used in the LOI - else if ( ( trkhit_C = dynamic_cast( hitCollection->getElementAt( ielem ) ) ) ) { + } + // or a simple cylindrical design, as used in the LOI + else if ((trkhit_C = dynamic_cast(hitCollection->getElementAt(ielem)))) { drphi = trkhit_C->getdRPhi(); - dz = trkhit_C->getdZ(); + dz = trkhit_C->getdZ(); - } - // this would be very unlikely, but who knows ... just an ordinary TrackerHit, which is not a COMPOSITE_SPACEPOINT + } + // this would be very unlikely, but who knows ... just an ordinary TrackerHit, which is not a + // COMPOSITE_SPACEPOINT else { // SJA:FIXME: fudge for now by a factor of two and ignore covariance - drphi = 2 * sqrt(trkhit->getCovMatrix()[0] + trkhit->getCovMatrix()[2]); - dz = sqrt(trkhit->getCovMatrix()[5]); - + drphi = 2 * sqrt(trkhit->getCovMatrix()[0] + trkhit->getCovMatrix()[2]); + dz = sqrt(trkhit->getCovMatrix()[5]); } - // now that the hit type has been established carry on and create a + // now that the hit type has been established carry on and create a - TrackerHitExtended * hitExt = new TrackerHitExtended( trkhit ); + TrackerHitExtended* hitExt = new TrackerHitExtended(trkhit); // SJA:FIXME: just use planar res for now hitExt->setResolutionRPhi(drphi); hitExt->setResolutionZ(dz); - // set type is now only used in one place where it is set to 0 to reject hits from a fit, set to INT_MAX to try and catch any missuse + // set type is now only used in one place where it is set to 0 to reject hits from a fit, set to INT_MAX to try + // and catch any missuse hitExt->setType(int(INT_MAX)); // det is no longer used set to INT_MAX to try and catch any missuse hitExt->setDet(int(INT_MAX)); @@ -1297,147 +1199,145 @@ int FPCCDSiliconTracking_MarlinTrk::InitialiseVTX(LCEvent * evt) { double pos[3]; double radius = 0; - for (int i=0; i<3; ++i) { + for (int i = 0; i < 3; ++i) { pos[i] = trkhit->getPosition()[i]; - radius += pos[i]*pos[i]; + radius += pos[i] * pos[i]; } radius = sqrt(radius); - double cosTheta = pos[2]/radius; - double Phi = atan2(pos[1],pos[0]); - - if (Phi < 0.) Phi = Phi + TWOPI; - - int iPhi = int(Phi/_dPhi); - int iTheta = int ((cosTheta + double(1.0))/_dTheta); - int iCode = layer + _nLayers*iPhi + _nLayers*_nDivisionsInPhi*iTheta; - _sectors[iCode].push_back( hitExt ); - - streamlog_out( DEBUG1 ) << " SIT Hit " << trkhit->id() << " added : @ " << pos[0] << " " << pos[1] << " " << pos[2] << " drphi " << hitExt->getResolutionRPhi() << " dz " << hitExt->getResolutionZ() << " iPhi = " << iPhi << " iTheta " << iTheta << " iCode = " << iCode << " layer = " << layer << std::endl; + double cosTheta = pos[2] / radius; + double Phi = atan2(pos[1], pos[0]); + if (Phi < 0.) + Phi = Phi + TWOPI; + int iPhi = int(Phi / _dPhi); + int iTheta = int((cosTheta + double(1.0)) / _dTheta); + int iCode = layer + _nLayers * iPhi + _nLayers * _nDivisionsInPhi * iTheta; + _sectors[iCode].push_back(hitExt); + streamlog_out(DEBUG1) << " SIT Hit " << trkhit->id() << " added : @ " << pos[0] << " " << pos[1] << " " + << pos[2] << " drphi " << hitExt->getResolutionRPhi() << " dz " + << hitExt->getResolutionZ() << " iPhi = " << iPhi << " iTheta " << iTheta + << " iCode = " << iCode << " layer = " << layer << std::endl; } - } catch(DataNotAvailableException &e) { - streamlog_out( DEBUG4 ) << " collection not found : " << _SITHitCollection.c_str() << std::endl ; + } catch (DataNotAvailableException& e) { + streamlog_out(DEBUG4) << " collection not found : " << _SITHitCollection.c_str() << std::endl; } - } - - return 1; // success - + return 1; // success } -void FPCCDSiliconTracking_MarlinTrk::check(LCEvent* ) { - -} +void FPCCDSiliconTracking_MarlinTrk::check(LCEvent*) {} void FPCCDSiliconTracking_MarlinTrk::end() { - delete _fastfitter ; _fastfitter = 0; - delete _encoder ; _encoder = 0; - // delete _trksystem ; _trksystem = 0; + delete _fastfitter; + _fastfitter = 0; + delete _encoder; + _encoder = 0; + // delete _trksystem ; _trksystem = 0; delete _moriUtil; delete _purityUtil; - - } - void FPCCDSiliconTracking_MarlinTrk::ProcessOneSector(int iPhi, int iTheta) { - int counter = 0 ; + int counter = 0; - - - int nComb = int( _Combinations.size() / 3 ); // number of triplet combinations + int nComb = int(_Combinations.size() / 3); // number of triplet combinations // std::cout << iPhi << " " << iTheta << " " << _nEvt << std::endl; int iNC = 0; - for (int iComb=0; iComb < nComb; ++iComb) { // loop over triplets + for (int iComb = 0; iComb < nComb; ++iComb) { // loop over triplets int nLR[3]; - for (int iS=0; iS<3; ++iS) { + for (int iS = 0; iS < 3; ++iS) { nLR[iS] = _Combinations[iNC]; iNC++; - } + } - RangeMap::iterator rmit = _phiRangeForTriplet.find(std::make_pair(nLR[0],nLR[2])); - if(rmit == _phiRangeForTriplet.end()){ + RangeMap::iterator rmit = _phiRangeForTriplet.find(std::make_pair(nLR[0], nLR[2])); + if (rmit == _phiRangeForTriplet.end()) { std::cout << "Combinations of 3 layers for triplet may be wrong. exit." << std::endl; exit(1); } - int iPhi_Up = iPhi + rmit->second; - int iPhi_Low = iPhi - rmit->second; - int iTheta_Up = iTheta + _sw_theta; + int iPhi_Up = iPhi + rmit->second; + int iPhi_Low = iPhi - rmit->second; + int iTheta_Up = iTheta + _sw_theta; int iTheta_Low = iTheta - _sw_theta; - if (iTheta_Low < 0) iTheta_Low = 0; - if (iTheta_Up >= _nDivisionsInTheta) iTheta_Up = _nDivisionsInTheta-1; - - + if (iTheta_Low < 0) + iTheta_Low = 0; + if (iTheta_Up >= _nDivisionsInTheta) + iTheta_Up = _nDivisionsInTheta - 1; // index of theta-phi bin of outer most layer - int iCode = nLR[0] + _nLayers*iPhi + _nLayers*_nDivisionsInPhi*iTheta; + int iCode = nLR[0] + _nLayers * iPhi + _nLayers * _nDivisionsInPhi * iTheta; + // get the all the hits in the outer most theta-phi bin - // get the all the hits in the outer most theta-phi bin - - TrackerHitExtendedVec& hitVecOuter = _sectors[iCode]; + TrackerHitExtendedVec& hitVecOuter = _sectors[iCode]; int nHitsOuter = int(hitVecOuter.size()); if (nHitsOuter > 0) { - - for (int ipMiddle=iPhi_Low; ipMiddle <= iPhi_Up; ipMiddle++) { // loop over phi in the Middle - for (int itMiddle=iTheta_Low; itMiddle <= iTheta_Up; itMiddle++) { // loop over theta in the Middle + for (int ipMiddle = iPhi_Low; ipMiddle <= iPhi_Up; ipMiddle++) { // loop over phi in the Middle + for (int itMiddle = iTheta_Low; itMiddle <= iTheta_Up; itMiddle++) { // loop over theta in the Middle int iPhiMiddle = ipMiddle; // catch wrap-around - if (ipMiddle < 0) iPhiMiddle = _nDivisionsInPhi + ipMiddle; - if (ipMiddle >= _nDivisionsInPhi) iPhiMiddle = ipMiddle - _nDivisionsInPhi; + if (ipMiddle < 0) + iPhiMiddle = _nDivisionsInPhi + ipMiddle; + if (ipMiddle >= _nDivisionsInPhi) + iPhiMiddle = ipMiddle - _nDivisionsInPhi; // index of current theta-phi bin of middle layer - iCode = nLR[1] + _nLayers*iPhiMiddle + _nLayers*_nDivisionsInPhi*itMiddle; + iCode = nLR[1] + _nLayers * iPhiMiddle + _nLayers * _nDivisionsInPhi * itMiddle; - // get the all the hits in the current middle theta-phi bin + // get the all the hits in the current middle theta-phi bin TrackerHitExtendedVec& hitVecMiddle = _sectors[iCode]; int nHitsMiddle = int(hitVecMiddle.size()); // determine which inner theta-phi bins to look in - if (nHitsMiddle > 0) { // look into inner bins int iPhiLowInner = iPhi_Low; int iPhiUpInner = iPhi_Up; int iThetaLowInner = iTheta_Low; - int iThetaUpInner = iTheta_Up; - - int difP = ipMiddle-iPhi; - if(difP > 0) iPhiLowInner = iPhi_Low + difP; - else if(difP < 0) iPhiUpInner = iPhi_Up + difP; - - int difT = itMiddle-iTheta; - if(difT > 0) iThetaLowInner = iTheta_Low + difT; - else if(difT < 0) iThetaUpInner = iTheta_Up + difT; - - for (int ipInner = iPhiLowInner; ipInner <= iPhiUpInner; ipInner++) { // loop over phi in the Inner - for (int itInner = iThetaLowInner; itInner <= iThetaUpInner; itInner++) { // loop over theta in the Inner + int iThetaUpInner = iTheta_Up; + + int difP = ipMiddle - iPhi; + if (difP > 0) + iPhiLowInner = iPhi_Low + difP; + else if (difP < 0) + iPhiUpInner = iPhi_Up + difP; + + int difT = itMiddle - iTheta; + if (difT > 0) + iThetaLowInner = iTheta_Low + difT; + else if (difT < 0) + iThetaUpInner = iTheta_Up + difT; + + for (int ipInner = iPhiLowInner; ipInner <= iPhiUpInner; ipInner++) { // loop over phi in the Inner + for (int itInner = iThetaLowInner; itInner <= iThetaUpInner; itInner++) { // loop over theta in the Inner int iPhiInner = ipInner; // catch wrap-around - if (ipInner < 0) iPhiInner = ipInner + _nDivisionsInPhi; - if (ipInner >= _nDivisionsInPhi) iPhiInner = ipInner - _nDivisionsInPhi; + if (ipInner < 0) + iPhiInner = ipInner + _nDivisionsInPhi; + if (ipInner >= _nDivisionsInPhi) + iPhiInner = ipInner - _nDivisionsInPhi; - iCode = nLR[2] + _nLayers*iPhiInner + _nLayers*_nDivisionsInPhi*itInner; + iCode = nLR[2] + _nLayers * iPhiInner + _nLayers * _nDivisionsInPhi * itInner; // get hit for inner bin TrackerHitExtendedVec& hitVecInner = _sectors[iCode]; @@ -1446,111 +1346,105 @@ void FPCCDSiliconTracking_MarlinTrk::ProcessOneSector(int iPhi, int iTheta) { if (nHitsInner > 0) { - streamlog_out(DEBUG1) << " " - << std::setw(3) << iPhi << " " << std::setw(3) << ipMiddle << " " << std::setw(3) << ipInner << " " - << std::setw(3) << iTheta << " " << std::setw(3) << itMiddle << " " << std::setw(3) << itInner << " " - << std::setw(3) << nLR[0] << " " << std::setw(3) << nLR[1] << " " << std::setw(3) << nLR[2] << " " - << std::setw(3) << nHitsOuter << " : " << std::setw(3) << nHitsMiddle << " : " << std::setw(3) << nHitsInner << " :: " - << std::setw(3) << nHitsOuter*nHitsMiddle* nHitsInner << std::endl; - // test all triplets + streamlog_out(DEBUG1) << " " << std::setw(3) << iPhi << " " << std::setw(3) << ipMiddle << " " + << std::setw(3) << ipInner << " " << std::setw(3) << iTheta << " " + << std::setw(3) << itMiddle << " " << std::setw(3) << itInner << " " + << std::setw(3) << nLR[0] << " " << std::setw(3) << nLR[1] << " " + << std::setw(3) << nLR[2] << " " << std::setw(3) << nHitsOuter << " : " + << std::setw(3) << nHitsMiddle << " : " << std::setw(3) << nHitsInner + << " :: " << std::setw(3) << nHitsOuter * nHitsMiddle * nHitsInner + << std::endl; + // test all triplets for (int iOuter = 0; iOuter < nHitsOuter; ++iOuter) { // loop over hits in the outer sector - TrackerHitExtended * outerHit = hitVecOuter[iOuter]; + TrackerHitExtended* outerHit = hitVecOuter[iOuter]; for (int iMiddle = 0; iMiddle < nHitsMiddle; iMiddle++) { // loop over hits in the middle sector - TrackerHitExtended * middleHit = hitVecMiddle[iMiddle]; - for (int iInner = 0; iInner 0 - } // endloop over theta in the Inner - } // endloop over phi in the Inner - } // endif nHitsMiddle > 0 - } // endloop over theta in the Middle - } // endloop over phi in the Middle - } // endif nHitsOuter > 0 - } // endloop over triplets - + } // endloop over hits in the middle sector + } // endloop over hits in the outer sector + } // endif nHitsInner > 0 + } // endloop over theta in the Inner + } // endloop over phi in the Inner + } // endif nHitsMiddle > 0 + } // endloop over theta in the Middle + } // endloop over phi in the Middle + } // endif nHitsOuter > 0 + } // endloop over triplets // streamlog_out( DEBUG2 ) << " process one sectector theta,phi " << iTheta << ", " << iPhi << // " number of loops : " << counter << std::endl ; } - -TrackExtended * FPCCDSiliconTracking_MarlinTrk::TestTriplet(TrackerHitExtended * outerHit, - TrackerHitExtended * middleHit, - TrackerHitExtended * innerHit, - HelixClass_double & helix, - int omegamode = 0) { +TrackExtended* FPCCDSiliconTracking_MarlinTrk::TestTriplet(TrackerHitExtended* outerHit, TrackerHitExtended* middleHit, + TrackerHitExtended* innerHit, HelixClass_double& helix, + int omegamode = 0) { /* Methods checks if the triplet of hits satisfies helix hypothesis */ // get the tracks already associated with the triplet - TrackExtendedVec& trackOuterVec = outerHit->getTrackExtendedVec(); + TrackExtendedVec& trackOuterVec = outerHit->getTrackExtendedVec(); TrackExtendedVec& trackMiddleVec = middleHit->getTrackExtendedVec(); - TrackExtendedVec& trackInnerVec = innerHit->getTrackExtendedVec(); + TrackExtendedVec& trackInnerVec = innerHit->getTrackExtendedVec(); - // check if all the hits are already assigned to a track - if ( ( !trackOuterVec.empty() ) && ( !trackMiddleVec.empty() ) && ( !trackInnerVec.empty() ) ) { + // check if all the hits are already assigned to a track + if ((!trackOuterVec.empty()) && (!trackMiddleVec.empty()) && (!trackInnerVec.empty())) { TrackExtendedVec::const_iterator middleEndIter = trackMiddleVec.end(); - TrackExtendedVec::const_iterator outerEndIter = trackOuterVec.end(); - TrackExtendedVec::const_iterator innerEndIter = trackInnerVec.end(); - TrackExtendedVec::const_iterator outerBeginIter = trackOuterVec.begin(); - TrackExtendedVec::const_iterator innerBeginIter = trackInnerVec.begin(); + TrackExtendedVec::const_iterator outerEndIter = trackOuterVec.end(); + TrackExtendedVec::const_iterator innerEndIter = trackInnerVec.end(); + TrackExtendedVec::const_iterator outerBeginIter = trackOuterVec.begin(); + TrackExtendedVec::const_iterator innerBeginIter = trackInnerVec.begin(); // loop over the tracks from the middle hit - for (TrackExtendedVec::const_iterator middleIter = trackMiddleVec.begin(); - middleIter < middleEndIter; - ++middleIter) { + for (TrackExtendedVec::const_iterator middleIter = trackMiddleVec.begin(); middleIter < middleEndIter; + ++middleIter) { // loop over the track from the outer hit - for (TrackExtendedVec::const_iterator outerIter = outerBeginIter; - outerIter < outerEndIter; - ++outerIter) { + for (TrackExtendedVec::const_iterator outerIter = outerBeginIter; outerIter < outerEndIter; ++outerIter) { - // if track from the outer and middle are not the same progress - if ( *outerIter != *middleIter ) continue; + // if track from the outer and middle are not the same progress + if (*outerIter != *middleIter) + continue; // loop over the tracks from the inner hit - for (TrackExtendedVec::const_iterator innerIter = innerBeginIter; - innerIter < innerEndIter; - ++innerIter) { + for (TrackExtendedVec::const_iterator innerIter = innerBeginIter; innerIter < innerEndIter; ++innerIter) { // no need to check against middle, it is idendical to outer here - if ( *outerIter == *innerIter ) { + if (*outerIter == *innerIter) { // an existing track already contains all three hits // return a null pointer - streamlog_out( DEBUG2 ) << " TestTriplet: track " << *outerIter << " already contains all three hits: Do not create new track from these hits " << std::endl ; - - + streamlog_out(DEBUG2) << " TestTriplet: track " << *outerIter + << " already contains all three hits: Do not create new track from these hits " + << std::endl; } - }// for inner - }// for outer - }// for middle - }// if all vectors are not empty - + } // for inner + } // for outer + } // for middle + } // if all vectors are not empty // increase triplet count ++_ntriplets; @@ -1558,44 +1452,42 @@ TrackExtended * FPCCDSiliconTracking_MarlinTrk::TestTriplet(TrackerHitExtended * // get the hit coordinates and errors double xh[3]; double yh[3]; - float zh[3]; + float zh[3]; double wrh[3]; - float wzh[3]; - float rh[3]; - float ph[3]; + float wzh[3]; + float rh[3]; + float ph[3]; float par[5]; float epar[15]; - - // first hit xh[0] = outerHit->getTrackerHit()->getPosition()[0]; yh[0] = outerHit->getTrackerHit()->getPosition()[1]; zh[0] = float(outerHit->getTrackerHit()->getPosition()[2]); - wrh[0] = double(1.0/(outerHit->getResolutionRPhi()*outerHit->getResolutionRPhi())); - wzh[0] = 1.0/(outerHit->getResolutionZ()*outerHit->getResolutionZ()); + wrh[0] = double(1.0 / (outerHit->getResolutionRPhi() * outerHit->getResolutionRPhi())); + wzh[0] = 1.0 / (outerHit->getResolutionZ() * outerHit->getResolutionZ()); // second hit xh[1] = middleHit->getTrackerHit()->getPosition()[0]; yh[1] = middleHit->getTrackerHit()->getPosition()[1]; zh[1] = float(middleHit->getTrackerHit()->getPosition()[2]); - wrh[1] = double(1.0/(middleHit->getResolutionRPhi()*middleHit->getResolutionRPhi())); - wzh[1] = 1.0/(middleHit->getResolutionZ()*middleHit->getResolutionZ()); + wrh[1] = double(1.0 / (middleHit->getResolutionRPhi() * middleHit->getResolutionRPhi())); + wzh[1] = 1.0 / (middleHit->getResolutionZ() * middleHit->getResolutionZ()); // third hit xh[2] = innerHit->getTrackerHit()->getPosition()[0]; yh[2] = innerHit->getTrackerHit()->getPosition()[1]; zh[2] = float(innerHit->getTrackerHit()->getPosition()[2]); - wrh[2] = double(1.0/(innerHit->getResolutionRPhi()*innerHit->getResolutionRPhi())); - wzh[2] = 1.0/(innerHit->getResolutionZ()*innerHit->getResolutionZ()); - + wrh[2] = double(1.0 / (innerHit->getResolutionRPhi() * innerHit->getResolutionRPhi())); + wzh[2] = 1.0 / (innerHit->getResolutionZ() * innerHit->getResolutionZ()); // calculate r and phi for all hits - for (int ih=0; ih<3; ih++) { - rh[ih] = float(sqrt(xh[ih]*xh[ih]+yh[ih]*yh[ih])); - ph[ih] = atan2(yh[ih],xh[ih]); - if (ph[ih] < 0.) ph[ih] = TWOPI + ph[ih]; + for (int ih = 0; ih < 3; ih++) { + rh[ih] = float(sqrt(xh[ih] * xh[ih] + yh[ih] * yh[ih])); + ph[ih] = atan2(yh[ih], xh[ih]); + if (ph[ih] < 0.) + ph[ih] = TWOPI + ph[ih]; } int NPT = 3; @@ -1603,14 +1495,10 @@ TrackExtended * FPCCDSiliconTracking_MarlinTrk::TestTriplet(TrackerHitExtended * float chi2RPhi; float chi2Z; - streamlog_out( DEBUG2 ) << " TestTriplet: Use fastHelixFit " << std::endl ; - - - _fastfitter->fastHelixFit(NPT, xh, yh, rh, ph, wrh, zh, wzh,iopt, par, epar, chi2RPhi, chi2Z); - par[3] = par[3]*par[0]/fabs(par[0]); - - + streamlog_out(DEBUG2) << " TestTriplet: Use fastHelixFit " << std::endl; + _fastfitter->fastHelixFit(NPT, xh, yh, rh, ph, wrh, zh, wzh, iopt, par, epar, chi2RPhi, chi2Z); + par[3] = par[3] * par[0] / fabs(par[0]); // get helix parameters float omega = par[0]; @@ -1620,9 +1508,8 @@ TrackExtended * FPCCDSiliconTracking_MarlinTrk::TestTriplet(TrackerHitExtended * float z0 = par[4]; // chi2 is weighted here by a factor for both rphi and z - float Chi2 = chi2RPhi*_chi2WRPhiTriplet+chi2Z*_chi2WZTriplet; - int ndf = 2*NPT-5; - + float Chi2 = chi2RPhi * _chi2WRPhiTriplet + chi2Z * _chi2WZTriplet; + int ndf = 2 * NPT - 5; // check the truth information for the triplet @@ -1634,75 +1521,86 @@ TrackExtended * FPCCDSiliconTracking_MarlinTrk::TestTriplet(TrackerHitExtended * // int nbadHits = 0; int triplet_code = 0; - - // Check if track satisfies all conditions - bool failed = false; - int quality_code = triplet_code * 10 ; + int quality_code = triplet_code * 10; - - if(std::isnormal(d0) == false){ - if( std::isinf(d0) == true ){ streamlog_out(DEBUG1) << "d0 is inf" << std::endl; } - else if( std::isnan(d0) == true ){ streamlog_out(DEBUG1) << "d0 is nan" << std::endl; } - else{ streamlog_out(DEBUG1) << "Something is wrong with d0" << std::endl; } + if (std::isnormal(d0) == false) { + if (std::isinf(d0) == true) { + streamlog_out(DEBUG1) << "d0 is inf" << std::endl; + } else if (std::isnan(d0) == true) { + streamlog_out(DEBUG1) << "d0 is nan" << std::endl; + } else { + streamlog_out(DEBUG1) << "Something is wrong with d0" << std::endl; + } failed = true; quality_code += 10; - } - else if(std::isnormal(z0) == false){ - if(std::isinf(z0)){streamlog_out(DEBUG1) << "z0 is inf" << std::endl;} - else if(std::isnan(z0)){streamlog_out(DEBUG1) << "z0 is nan" << std::endl;} - else{ streamlog_out(DEBUG1) << "Something is wrong with z0" << std::endl;} + } else if (std::isnormal(z0) == false) { + if (std::isinf(z0)) { + streamlog_out(DEBUG1) << "z0 is inf" << std::endl; + } else if (std::isnan(z0)) { + streamlog_out(DEBUG1) << "z0 is nan" << std::endl; + } else { + streamlog_out(DEBUG1) << "Something is wrong with z0" << std::endl; + } failed = true; quality_code += 100; - } - else if(std::isnormal(omega) == false){ - if(std::isinf(omega)){streamlog_out(DEBUG1) << "omega is inf" << std::endl;} - else if(std::isnan(omega)){streamlog_out(DEBUG1) << "omega is nan" << std::endl;} - else{streamlog_out(DEBUG1) << "Something is wrong with omega" << std::endl;} + } else if (std::isnormal(omega) == false) { + if (std::isinf(omega)) { + streamlog_out(DEBUG1) << "omega is inf" << std::endl; + } else if (std::isnan(omega)) { + streamlog_out(DEBUG1) << "omega is nan" << std::endl; + } else { + streamlog_out(DEBUG1) << "Something is wrong with omega" << std::endl; + } failed = true; quality_code += 1000; - } - else if(std::isnormal(phi0) == false){ - if(std::isinf(phi0)){streamlog_out(DEBUG1) << "phi0 is inf" << std::endl;} - else if(std::isnan(phi0)){streamlog_out(DEBUG1) << "phi0 is nan" << std::endl;} - else{streamlog_out(DEBUG1) << "Something is wrong with phi0" << std::endl;} + } else if (std::isnormal(phi0) == false) { + if (std::isinf(phi0)) { + streamlog_out(DEBUG1) << "phi0 is inf" << std::endl; + } else if (std::isnan(phi0)) { + streamlog_out(DEBUG1) << "phi0 is nan" << std::endl; + } else { + streamlog_out(DEBUG1) << "Something is wrong with phi0" << std::endl; + } failed = true; quality_code += 10000; - } - else if(std::isnormal(tanlambda) == false){ - if(std::isinf(tanlambda)){streamlog_out(DEBUG1) << "tanlambda is inf" << std::endl;} - else if(std::isnan(tanlambda)){streamlog_out(DEBUG1) << "tanlambda is nan" << std::endl;} - else{streamlog_out(DEBUG1) << "Something is wrong with tanlambda" << std::endl;} + } else if (std::isnormal(tanlambda) == false) { + if (std::isinf(tanlambda)) { + streamlog_out(DEBUG1) << "tanlambda is inf" << std::endl; + } else if (std::isnan(tanlambda)) { + streamlog_out(DEBUG1) << "tanlambda is nan" << std::endl; + } else { + streamlog_out(DEBUG1) << "Something is wrong with tanlambda" << std::endl; + } failed = true; quality_code += 100000; } - - if(failed == false){ - if ( Chi2/float(ndf) > _chi2FitCut ) { - streamlog_out(DEBUG1) << "Chi2/ndf = " << Chi2/float(ndf) << " , cut = " << _chi2FitCut << std::endl; + if (failed == false) { + if (Chi2 / float(ndf) > _chi2FitCut) { + streamlog_out(DEBUG1) << "Chi2/ndf = " << Chi2 / float(ndf) << " , cut = " << _chi2FitCut << std::endl; failed = true; quality_code += 1; - }else if ( Chi2/float(ndf) < 0 ){ - streamlog_out(DEBUG1) << "Chi2/ndf = " << Chi2/float(ndf) << " , cut = " << _chi2FitCut << std::endl; + } else if (Chi2 / float(ndf) < 0) { + streamlog_out(DEBUG1) << "Chi2/ndf = " << Chi2 / float(ndf) << " , cut = " << _chi2FitCut << std::endl; failed = true; quality_code += 5; - }else if (fabs(d0) > _cutOnD0 ) { - streamlog_out(DEBUG1) << "d0 = " << d0 << " , cut = " << _cutOnD0 << std::endl; + } else if (fabs(d0) > _cutOnD0) { + streamlog_out(DEBUG1) << "d0 = " << d0 << " , cut = " << _cutOnD0 << std::endl; failed = true; quality_code += 2; - } else if (fabs(z0) > _cutOnZ0 ) { - streamlog_out(DEBUG1) << "z0 = " << z0 << " , cut = " << _cutOnZ0 << std::endl; + } else if (fabs(z0) > _cutOnZ0) { + streamlog_out(DEBUG1) << "z0 = " << z0 << " , cut = " << _cutOnZ0 << std::endl; failed = true; quality_code += 3; - } else if ( omegamode == 0 && fabs(omega)>_cutOnOmegaVXD) { + } else if (omegamode == 0 && fabs(omega) > _cutOnOmegaVXD) { streamlog_out(DEBUG1) << "omega = " << omega << " , cut = " << _cutOnOmegaVXD << std::endl; failed = true; quality_code += 4; - } else if ( omegamode == 1 && fabs(omega)>_cutOnOmegaFTD) { + } else if (omegamode == 1 && fabs(omega) > _cutOnOmegaFTD) { streamlog_out(DEBUG1) << "omega = " << omega << " , cut = " << _cutOnOmegaFTD << std::endl; failed = true; quality_code += 4; @@ -1711,119 +1609,105 @@ TrackExtended * FPCCDSiliconTracking_MarlinTrk::TestTriplet(TrackerHitExtended * } } - - - - - - if( failed ) { + if (failed) { // return a null pointer return 0; } + helix.Initialize_Canonical(phi0, d0, z0, omega, tanlambda, _bField); - helix.Initialize_Canonical(phi0,d0,z0,omega,tanlambda,_bField); - - TrackExtended * trackAR = new TrackExtended(); + TrackExtended* trackAR = new TrackExtended(); trackAR->addTrackerHitExtended(outerHit); trackAR->addTrackerHitExtended(middleHit); trackAR->addTrackerHitExtended(innerHit); outerHit->addTrackExtended(trackAR); middleHit->addTrackExtended(trackAR); - innerHit->addTrackExtended(trackAR); + innerHit->addTrackExtended(trackAR); trackAR->setD0(d0); trackAR->setZ0(z0); trackAR->setPhi(phi0); trackAR->setTanLambda(tanlambda); trackAR->setOmega(omega); - trackAR->setChi2( Chi2 ); - trackAR->setNDF( ndf ); + trackAR->setChi2(Chi2); + trackAR->setNDF(ndf); trackAR->setCovMatrix(epar); - - return trackAR; } - - - - -int FPCCDSiliconTracking_MarlinTrk::BuildTrack_KalFit(TrackerHitExtended * /*outerHit*/, - TrackerHitExtended * /*middleHit*/, - TrackerHitExtended * /*innerHit*/, - HelixClass_double & helix, - int innerLayer, - TrackExtended * trackAR) { - - - +int FPCCDSiliconTracking_MarlinTrk::BuildTrack_KalFit(TrackerHitExtended* /*outerHit*/, + TrackerHitExtended* /*middleHit*/, + TrackerHitExtended* /*innerHit*/, HelixClass_double& helix, + int innerLayer, TrackExtended* trackAR) { int nMisAssign = 0; - for (int layer = innerLayer-1; layer>=0; layer--) { // loop over remaining layers - if(nMisAssign > _minMissAddition){ + for (int layer = innerLayer - 1; layer >= 0; layer--) { // loop over remaining layers + if (nMisAssign > _minMissAddition) { return int(trackAR->getTrackerHitExtendedVec().size()); } int Boundaries[4]; - int pterr = getPhiThetaRegion(trackAR,layer,Boundaries); - //When the number different from 0 comes, then it is the number of hits as the - //last result of buildTrack - if(pterr != 0){ + int pterr = getPhiThetaRegion(trackAR, layer, Boundaries); + // When the number different from 0 comes, then it is the number of hits as the + // last result of buildTrack + if (pterr != 0) { return pterr; } - - float distMin = 1.0e+20; - TrackerHitExtended * assignedhit = NULL; + TrackerHitExtended* assignedhit = NULL; - if(Boundaries[2] < 0) Boundaries[2] = 0; - if(Boundaries[3] >= _nDivisionsInTheta) Boundaries[3] = _nDivisionsInTheta - 1; + if (Boundaries[2] < 0) + Boundaries[2] = 0; + if (Boundaries[3] >= _nDivisionsInTheta) + Boundaries[3] = _nDivisionsInTheta - 1; - - for (int ipInner = Boundaries[0]; ipInner <= Boundaries[1]; ipInner++) { - for (int itInner = Boundaries[2]; itInner <= Boundaries[3]; itInner++) { + for (int ipInner = Boundaries[0]; ipInner <= Boundaries[1]; ipInner++) { + for (int itInner = Boundaries[2]; itInner <= Boundaries[3]; itInner++) { int iPhiInner = ipInner; - while(iPhiInner < 0) iPhiInner -= _nDivisionsInPhi; - while(iPhiInner >= _nDivisionsInPhi) iPhiInner -= _nDivisionsInPhi; - int iCode = layer + _nLayers*iPhiInner + _nLayers*_nDivisionsInPhi*itInner; + while (iPhiInner < 0) + iPhiInner -= _nDivisionsInPhi; + while (iPhiInner >= _nDivisionsInPhi) + iPhiInner -= _nDivisionsInPhi; + int iCode = layer + _nLayers * iPhiInner + _nLayers * _nDivisionsInPhi * itInner; TrackerHitExtendedVec& hitVecInner = _sectors[iCode]; int nHitsInner = int(hitVecInner.size()); - for (int iInner=0;iInnergetTrackerHit()->getPosition()[i]); } + for (int iInner = 0; iInner < nHitsInner; iInner++) { + TrackerHitExtended* currentHit = hitVecInner[iInner]; + double pos[3]; + double distance[3]; + for (int i = 0; i < 3; ++i) { + pos[i] = double(currentHit->getTrackerHit()->getPosition()[i]); + } int tiltStatus = 0; double dot = 0; - if(_useClusterRejection == true){ + if (_useClusterRejection == true) { TrackerHit* curInMostHit = trackAR->getTrackerHitExtendedVec().back()->getTrackerHit(); tiltStatus = CheckTiltOf2Clusters(curInMostHit, currentHit->getTrackerHit(), 1); - //In BuildTrack, in this case the first and second arguments are - //always VXD, so needless to check which it is VXD or SIT hit. - dot = DotOf2Clusters(curInMostHit,currentHit->getTrackerHit()); + // In BuildTrack, in this case the first and second arguments are + // always VXD, so needless to check which it is VXD or SIT hit. + dot = DotOf2Clusters(curInMostHit, currentHit->getTrackerHit()); } - bool goodDot = (dot > _minDotOf2Clusters) ? true : false ; - if( _useClusterRejection == false || (tiltStatus >= 0 && goodDot == true) ){ - double time = helix.getDistanceToPoint(pos,distance); + bool goodDot = (dot > _minDotOf2Clusters) ? true : false; + if (_useClusterRejection == false || (tiltStatus >= 0 && goodDot == true)) { + double time = helix.getDistanceToPoint(pos, distance); if (time < 1.0e+10) { - if (distance[2] < distMin) { // distance[2] = sqrt( d0*d0 + z0*z0 ) - distMin = distance[2]; + if (distance[2] < distMin) { // distance[2] = sqrt( d0*d0 + z0*z0 ) + distMin = distance[2]; assignedhit = currentHit; } } - }//end of if statement of tiltStatus //MORI - } // endloop over hits in the Inner sector - } // endloop over theta in the Inner region - } // endloop over phi in the Inner region + } // end of if statement of tiltStatus //MORI + } // endloop over hits in the Inner sector + } // endloop over theta in the Inner region + } // endloop over phi in the Inner region - if (distMin > _minDistCutAttachForVXD ) { + if (distMin > _minDistCutAttachForVXD) { nMisAssign++; continue; - } - else{ + } else { float par[5]; float epar[15]; int ndf; @@ -1833,81 +1717,83 @@ int FPCCDSiliconTracking_MarlinTrk::BuildTrack_KalFit(TrackerHitExtended * /*out TrackerHitVec trkHits; trkHits.reserve(hvec.size() + 1); - trkHits.push_back( assignedhit->getTrackerHit() ); - for(int ij = int(hvec.size()) - 1 ; ij >= 0 ; ij--){ + trkHits.push_back(assignedhit->getTrackerHit()); + for (int ij = int(hvec.size()) - 1; ij >= 0; ij--) { trkHits.push_back(hvec[ij]->getTrackerHit()); } TrackerHitVec hits_in_fit; TrackerHitVec outliers; - int error_KalFit = KalFit(ndf,Chi2,trkHits,hits_in_fit,outliers,par,epar,helix); + int error_KalFit = KalFit(ndf, Chi2, trkHits, hits_in_fit, outliers, par, epar, helix); - if(error_KalFit != 0){ + if (error_KalFit != 0) { validCombination = 0; streamlog_out(DEBUG2) << "ERROR! error_KalFit = " << error_KalFit << std::endl; - } - else if(outliers.size() == 0){ - validCombination = Chi2/float(ndf) < _chi2FitCut_kalman; - } - else{ - validCombination = Chi2/float(ndf) < _chi2FitCut_kalman; + } else if (outliers.size() == 0) { + validCombination = Chi2 / float(ndf) < _chi2FitCut_kalman; + } else { + validCombination = Chi2 / float(ndf) < _chi2FitCut_kalman; nMisAssign += int(outliers.size()); - if( int(outliers.size()) > _minMissAddition ){ - return int(trackAR->getTrackerHitExtendedVec().size()); + if (int(outliers.size()) > _minMissAddition) { + return int(trackAR->getTrackerHitExtendedVec().size()); } - TrackerHitExtendedVec oldhvec = hvec; + TrackerHitExtendedVec oldhvec = hvec; trackAR->ClearTrackerHitExtendedVec(); - for(int hi=0;higetTrackerHit()); - if(iter == outliers.end()){ trackAR->addTrackerHitExtended(oldhvec[hi]); } - else{ outliers.erase(iter); }//"found" = "oldhvec[hi] is outlier" + for (int hi = 0; hi < int(oldhvec.size()); hi++) { + TrackerHitVec::iterator iter = std::find(outliers.begin(), outliers.end(), oldhvec[hi]->getTrackerHit()); + if (iter == outliers.end()) { + trackAR->addTrackerHitExtended(oldhvec[hi]); + } else { + outliers.erase(iter); + } //"found" = "oldhvec[hi] is outlier" } - if(outliers.size() != 0){ - TrackerHitVec::iterator iter = std::find(outliers.begin(),outliers.end(),assignedhit->getTrackerHit()); - if(iter != outliers.end()){ - outliers.erase(iter); + if (outliers.size() != 0) { + TrackerHitVec::iterator iter = std::find(outliers.begin(), outliers.end(), assignedhit->getTrackerHit()); + if (iter != outliers.end()) { + outliers.erase(iter); validCombination = 0; - nMisAssign -= 1;//Unless this is here, nMisAssign will be double-counted. + nMisAssign -= 1; // Unless this is here, nMisAssign will be double-counted. } } } - - if ( validCombination == 0 ) nMisAssign++; - else{ + if (validCombination == 0) + nMisAssign++; + else { // assign hit to track and track to hit, update the track parameters trackAR->addTrackerHitExtended(assignedhit); assignedhit->addTrackExtended(trackAR); - //Mori:two conventions of fastFit and KalFit are different. - //I made KalFit's convention match that of lcio's covMatrix. + // Mori:two conventions of fastFit and KalFit are different. + // I made KalFit's convention match that of lcio's covMatrix. float parD0 = par[0]; float parPhi0 = par[1]; float parOmega = par[2]; float parZ0 = par[3]; float parTanlambda = par[4]; - helix.Initialize_Canonical(parPhi0,parD0,parZ0,parOmega,parTanlambda,_bField); + helix.Initialize_Canonical(parPhi0, parD0, parZ0, parOmega, parTanlambda, _bField); trackAR->setD0(parD0); trackAR->setZ0(parZ0); trackAR->setPhi(parPhi0); trackAR->setTanLambda(parTanlambda); trackAR->setOmega(parOmega); - trackAR->setChi2( Chi2 ); + trackAR->setChi2(Chi2); trackAR->setCovMatrix(epar); - trackAR->setNDF( ndf ); + trackAR->setNDF(ndf); } } } // endloop over remaining layers - TrackerHitExtendedVec& hvec = trackAR->getTrackerHitExtendedVec(); + TrackerHitExtendedVec& hvec = trackAR->getTrackerHitExtendedVec(); int nTotalHits = int(hvec.size()); - + return nTotalHits; } +int FPCCDSiliconTracking_MarlinTrk::getIntersectionEasy(HelixClass_double& helix, TrackerHit* curInmos, int layer, + double* isec, double* ref) { + // int FPCCDSiliconTracking_MarlinTrk::getIntersectionEasy(HelixClass_double& helix, TrackerHit* curInmos , int layer, + // double* isec, double* ref){ -int FPCCDSiliconTracking_MarlinTrk::getIntersectionEasy(HelixClass_double& helix, TrackerHit* curInmos , int layer, double* isec, double* ref){ -//int FPCCDSiliconTracking_MarlinTrk::getIntersectionEasy(HelixClass_double& helix, TrackerHit* curInmos , int layer, double* isec, double* ref){ - - if(layer > 5){ + if (layer > 5) { std::cout << "getIntersectionEasy used non-VXD layer by mistake. Check source code." << std::endl; exit(1); } @@ -1917,38 +1803,34 @@ int FPCCDSiliconTracking_MarlinTrk::getIntersectionEasy(HelixClass_double& helix isec[2] = 0; double hlwidth = _vxd.geodata[layer].sximax; double Rmin = _vxd.geodata[layer].rmes; - double Rmax = sqrt(Rmin*Rmin + hlwidth*hlwidth); - double Rmean = (Rmin + Rmax)/2.0; + double Rmax = sqrt(Rmin * Rmin + hlwidth * hlwidth); + double Rmean = (Rmin + Rmax) / 2.0; double point[6]; - double time = helix.getPointOnCircle(Rmean,ref,point); - if(time < 0){ + double time = helix.getPointOnCircle(Rmean, ref, point); + if (time < 0) { return -1; } - double phiX = atan2(curInmos->getPosition()[1],curInmos->getPosition()[0]); - double diffA = atan2(point[1],point[0]) - phiX; - double diffB = atan2(point[4],point[3]) - phiX; + double phiX = atan2(curInmos->getPosition()[1], curInmos->getPosition()[0]); + double diffA = atan2(point[1], point[0]) - phiX; + double diffB = atan2(point[4], point[3]) - phiX; - if(std::abs(diffA) < std::abs(diffB)){ + if (std::abs(diffA) < std::abs(diffB)) { isec[0] = point[0]; isec[1] = point[1]; isec[2] = point[2]; - } - else{ + } else { isec[0] = point[3]; isec[1] = point[4]; isec[2] = point[5]; } return 0; - } +int FPCCDSiliconTracking_MarlinTrk::getIntersectionEasyTest(HelixClass_double& helix, TrackerHit* basis, int layer, + std::vector& isec) { - - -int FPCCDSiliconTracking_MarlinTrk::getIntersectionEasyTest(HelixClass_double& helix, TrackerHit* basis, int layer, std::vector &isec){ - - if(layer > 8){ + if (layer > 8) { std::cout << "getIntersectionEasyTest uses only VXD or SIT layer. Check source code." << std::endl; exit(1); } @@ -1958,7 +1840,8 @@ int FPCCDSiliconTracking_MarlinTrk::getIntersectionEasyTest(HelixClass_double& h long double tanL = helix.getTanLambda(); long double omega = helix.getOmega(); - if(std::isnormal(d0) == false || std::isnormal(z0) == false || std::isnormal(omega) == false || std::isnormal(phi0) == false || std::isnormal(tanL) == false){ + if (std::isnormal(d0) == false || std::isnormal(z0) == false || std::isnormal(omega) == false || + std::isnormal(phi0) == false || std::isnormal(tanL) == false) { return -3; } @@ -1966,49 +1849,62 @@ int FPCCDSiliconTracking_MarlinTrk::getIntersectionEasyTest(HelixClass_double& h isec.resize(3); long double Rmean; - if(layer >= int(_nLayersVTX)){ - Rmean = (_sit.geodata[layer - 6].rmin + _sit.geodata[layer - 5].rmin)/2.0; - } - else{ + if (layer >= int(_nLayersVTX)) { + Rmean = (_sit.geodata[layer - 6].rmin + _sit.geodata[layer - 5].rmin) / 2.0; + } else { long double hlwidth = _vxd.geodata[layer].sximax; long double Rmin = _vxd.geodata[layer].rmes; - long double Rmax = sqrt(Rmin*Rmin + hlwidth*hlwidth); - Rmean = (Rmin + Rmax)/2.0; + long double Rmax = sqrt(Rmin * Rmin + hlwidth * hlwidth); + Rmean = (Rmin + Rmax) / 2.0; } - long double A = 1.0 - 0.5*(Rmean*Rmean - d0*d0)/(1./omega/omega - d0/omega); - if(_mydebugIntersection){ + long double A = 1.0 - 0.5 * (Rmean * Rmean - d0 * d0) / (1. / omega / omega - d0 / omega); + if (_mydebugIntersection) { std::cout << " == getIntersectionEasyTest check ===" << std::endl; std::cout << "A : " << A << std::endl; } - if(-1.0 > A || A > 1.0){ return -1; } - else if( std::isnormal(A) == false){ return -2;} + if (-1.0 > A || A > 1.0) { + return -1; + } else if (std::isnormal(A) == false) { + return -2; + } long double phi1 = phi0 - acos(A); long double phi2 = phi0 + acos(A); long double* point = new long double[6]; - point[0] = -d0*sin(phi0) + 1.0/omega*(sin(phi0) - sin(phi1)); - point[1] = d0*cos(phi0) - 1.0/omega*(cos(phi0) - cos(phi1)); - point[2] = z0 + 1.0/omega*(phi0 - phi1)*tanL; - point[3] = -d0*sin(phi0) + 1.0/omega*(sin(phi0) - sin(phi2)); - point[4] = d0*cos(phi0) - 1.0/omega*(cos(phi0) - cos(phi2)); - point[5] = z0 + 1.0/omega*(phi0 - phi2)*tanL; - long double phiX = atan2(basis->getPosition()[1],basis->getPosition()[0]);if(phiX < 0) phiX += 2.0*M_PI; - long double p1 = atan2(point[1],point[0]);if(p1 < 0) p1 += 2.0*M_PI; - long double p2 = atan2(point[4],point[3]);if(p2 < 0) p2 += 2.0*M_PI; - long double diff1 = std::abs(p1 - phiX);if(diff1 > M_PI) diff1 = 2.0*M_PI - diff1; - long double diff2 = std::abs(p2 - phiX);if(diff2 > M_PI) diff2 = 2.0*M_PI - diff2; + point[0] = -d0 * sin(phi0) + 1.0 / omega * (sin(phi0) - sin(phi1)); + point[1] = d0 * cos(phi0) - 1.0 / omega * (cos(phi0) - cos(phi1)); + point[2] = z0 + 1.0 / omega * (phi0 - phi1) * tanL; + point[3] = -d0 * sin(phi0) + 1.0 / omega * (sin(phi0) - sin(phi2)); + point[4] = d0 * cos(phi0) - 1.0 / omega * (cos(phi0) - cos(phi2)); + point[5] = z0 + 1.0 / omega * (phi0 - phi2) * tanL; + long double phiX = atan2(basis->getPosition()[1], basis->getPosition()[0]); + if (phiX < 0) + phiX += 2.0 * M_PI; + long double p1 = atan2(point[1], point[0]); + if (p1 < 0) + p1 += 2.0 * M_PI; + long double p2 = atan2(point[4], point[3]); + if (p2 < 0) + p2 += 2.0 * M_PI; + long double diff1 = std::abs(p1 - phiX); + if (diff1 > M_PI) + diff1 = 2.0 * M_PI - diff1; + long double diff2 = std::abs(p2 - phiX); + if (diff2 > M_PI) + diff2 = 2.0 * M_PI - diff2; isec[0] = (diff1 < diff2) ? point[0] : point[3]; isec[1] = (diff1 < diff2) ? point[1] : point[4]; long double tmpZ = (diff1 < diff2) ? point[2] : point[5]; long double curZ = basis->getPosition()[2]; - long double dist = curZ - tmpZ; - long double distOne = std::abs(1.0/omega*tanL*2.0*M_PI); - long double nCircle = dist/distOne; - tmpZ += distOne*static_cast(static_cast(nCircle)); + long double dist = curZ - tmpZ; + long double distOne = std::abs(1.0 / omega * tanL * 2.0 * M_PI); + long double nCircle = dist / distOne; + tmpZ += distOne * static_cast(static_cast(nCircle)); long double decimal = std::abs(nCircle - int(nCircle)); - if(decimal > 0.5) tmpZ += distOne*nCircle/std::abs(nCircle); + if (decimal > 0.5) + tmpZ += distOne * nCircle / std::abs(nCircle); isec[2] = tmpZ; #if 0 @@ -2037,202 +1933,179 @@ int FPCCDSiliconTracking_MarlinTrk::getIntersectionEasyTest(HelixClass_double& h delete[] point; return 0; - } - - - - - - - -double FPCCDSiliconTracking_MarlinTrk::getNeededPhiSectors(double Pt, int outly , int inly){ - double R = Pt/(0.299792458*_bField); - R = 1000.0*R; - double omega = 1.0/R; +double FPCCDSiliconTracking_MarlinTrk::getNeededPhiSectors(double Pt, int outly, int inly) { + double R = Pt / (0.299792458 * _bField); + R = 1000.0 * R; + double omega = 1.0 / R; HelixClass_double helix; - //helix.Initialize_Canonical(phi0,d0,z0,omega,tanlambda,_bField); - helix.Initialize_Canonical(0,0,0,omega,0.001,_bField); - double Ro; + // helix.Initialize_Canonical(phi0,d0,z0,omega,tanlambda,_bField); + helix.Initialize_Canonical(0, 0, 0, omega, 0.001, _bField); + double Ro; double Ri; - if(outly >= 6){ - Ro = (_sit.geodata[outly - 6].rmin + _sit.geodata[outly - 5].rmin)/2.0; - } - else{ + if (outly >= 6) { + Ro = (_sit.geodata[outly - 6].rmin + _sit.geodata[outly - 5].rmin) / 2.0; + } else { double hlwidth = _vxd.geodata[outly].sximax; double Rmin = _vxd.geodata[outly].rmes; - double Rmax = sqrt(Rmin*Rmin + hlwidth*hlwidth); - Ro = (Rmin + Rmax)/2.0; + double Rmax = sqrt(Rmin * Rmin + hlwidth * hlwidth); + Ro = (Rmin + Rmax) / 2.0; } - //For now, I assume that inly always corresponds to VXD layer due to the - //current geometry. + // For now, I assume that inly always corresponds to VXD layer due to the + // current geometry. double hlwidth = _vxd.geodata[inly].sximax; double Rmin = _vxd.geodata[inly].rmes; - double Rmax = sqrt(Rmin*Rmin + hlwidth*hlwidth); - Ri = (Rmin + Rmax)/2.0; - + double Rmax = sqrt(Rmin * Rmin + hlwidth * hlwidth); + Ri = (Rmin + Rmax) / 2.0; - double ref[3] = {0,0,0}; + double ref[3] = {0, 0, 0}; double point[6]; - double time = helix.getPointOnCircle(Ro,ref,point); - if(time < 0){ - std::cout << "_cutOnPtVXD is too small to calculate range of phi-sectors needed to find triplet with Pt more than _cutOnPtVXD." << std::endl; + double time = helix.getPointOnCircle(Ro, ref, point); + if (time < 0) { + std::cout << "_cutOnPtVXD is too small to calculate range of phi-sectors needed to find triplet with Pt more than " + "_cutOnPtVXD." + << std::endl; std::cout << "Please set larger value." << std::endl; exit(1); } - double phiO = atan2(point[1],point[0]); + double phiO = atan2(point[1], point[0]); std::cout << "==Ro==" << std::endl; std::cout << " time : " << time << std::endl; std::cout << " phi : " << phiO << std::endl; - printf("point : %f,%f,%f %f,%f,%f \n ",point[0],point[1],point[2],point[3],point[4],point[5]); + printf("point : %f,%f,%f %f,%f,%f \n ", point[0], point[1], point[2], point[3], point[4], point[5]); - time = helix.getPointOnCircle(Ri,ref,point); - if(time < 0){ - std::cout << "_cutOnPtVXD is too small to calculate range of phi-sectors needed to find triplet with Pt more than _cutOnPtVXD." << std::endl; + time = helix.getPointOnCircle(Ri, ref, point); + if (time < 0) { + std::cout << "_cutOnPtVXD is too small to calculate range of phi-sectors needed to find triplet with Pt more than " + "_cutOnPtVXD." + << std::endl; std::cout << "Please set larger value." << std::endl; exit(1); } - double phiI = atan2(point[1],point[0]); + double phiI = atan2(point[1], point[0]); std::cout << "==Ri==" << std::endl; std::cout << " time : " << time << std::endl; std::cout << " phi : " << phiI << std::endl; - printf("point : %f,%f,%f %f,%f,%f \n ",point[0],point[1],point[2],point[3],point[4],point[5]); - printf("phiRange : %f \n ",phiI - phiO); + printf("point : %f,%f,%f %f,%f,%f \n ", point[0], point[1], point[2], point[3], point[4], point[5]); + printf("phiRange : %f \n ", phiI - phiO); return phiI - phiO; - } - - - -//This is under construction -void FPCCDSiliconTracking_MarlinTrk::getNeededPhiSectorsVer2(double Pt, std::vector layers, std::vector& phiRange){ - double R = Pt/(0.299792458*_bField); - R = 1000.0*R; - double omega = 1.0/R; +// This is under construction +void FPCCDSiliconTracking_MarlinTrk::getNeededPhiSectorsVer2(double Pt, std::vector layers, + std::vector& phiRange) { + double R = Pt / (0.299792458 * _bField); + R = 1000.0 * R; + double omega = 1.0 / R; HelixClass_double helix; - //helix.Initialize_Canonical(phi0,d0,z0,omega,tanlambda,_bField); - helix.Initialize_Canonical(0,0,0,omega,0.001,_bField); - double Ro,Rm,Ri; - if(layers[0] >= 6){//outer layer - Ro = (_sit.geodata[layers[0] - 6].rmin + _sit.geodata[layers[0] - 5].rmin)/2.0; - } - else{ - double hlwidth = _vxd.geodata[ layers[0] ].sximax; - double Rmin = _vxd.geodata[ layers[0] ].rmes; - double Rmax = sqrt(Rmin*Rmin + hlwidth*hlwidth); - Ro = (Rmin + Rmax)/2.0; - } - if(layers[1] >= 6){//middle layer - Rm = (_sit.geodata[layers[1] - 6].rmin + _sit.geodata[layers[1] - 5].rmin)/2.0; + // helix.Initialize_Canonical(phi0,d0,z0,omega,tanlambda,_bField); + helix.Initialize_Canonical(0, 0, 0, omega, 0.001, _bField); + double Ro, Rm, Ri; + if (layers[0] >= 6) { // outer layer + Ro = (_sit.geodata[layers[0] - 6].rmin + _sit.geodata[layers[0] - 5].rmin) / 2.0; + } else { + double hlwidth = _vxd.geodata[layers[0]].sximax; + double Rmin = _vxd.geodata[layers[0]].rmes; + double Rmax = sqrt(Rmin * Rmin + hlwidth * hlwidth); + Ro = (Rmin + Rmax) / 2.0; } - else{ - double hlwidth = _vxd.geodata[ layers[1] ].sximax; - double Rmin = _vxd.geodata[ layers[1] ].rmes; - double Rmax = sqrt(Rmin*Rmin + hlwidth*hlwidth); - Rm = (Rmin + Rmax)/2.0; + if (layers[1] >= 6) { // middle layer + Rm = (_sit.geodata[layers[1] - 6].rmin + _sit.geodata[layers[1] - 5].rmin) / 2.0; + } else { + double hlwidth = _vxd.geodata[layers[1]].sximax; + double Rmin = _vxd.geodata[layers[1]].rmes; + double Rmax = sqrt(Rmin * Rmin + hlwidth * hlwidth); + Rm = (Rmin + Rmax) / 2.0; } - double hlwidth = _vxd.geodata[ layers[2] ].sximax; - double Rmin = _vxd.geodata[ layers[2] ].rmes; - double Rmax = sqrt(Rmin*Rmin + hlwidth*hlwidth); - Ri = (Rmin + Rmax)/2.0; + double hlwidth = _vxd.geodata[layers[2]].sximax; + double Rmin = _vxd.geodata[layers[2]].rmes; + double Rmax = sqrt(Rmin * Rmin + hlwidth * hlwidth); + Ri = (Rmin + Rmax) / 2.0; - - double ref[3] = {0,0,0}; + double ref[3] = {0, 0, 0}; double point[6]; - //outer phi - double time = helix.getPointOnCircle(Ro,ref,point); - if(time < 0){ - std::cout << "_cutOnPtVXD is too small to calculate range of phi-sectors needed to find triplet with Pt more than _cutOnPtVXD." << std::endl; exit(1); + // outer phi + double time = helix.getPointOnCircle(Ro, ref, point); + if (time < 0) { + std::cout << "_cutOnPtVXD is too small to calculate range of phi-sectors needed to find triplet with Pt more than " + "_cutOnPtVXD." + << std::endl; + exit(1); } - double phiO = atan2(point[1],point[0]); + double phiO = atan2(point[1], point[0]); std::cout << "Ro phi :" << phiO << std::endl; - //middle phi - time = helix.getPointOnCircle(Rm,ref,point); - if(time < 0){ - std::cout << "_cutOnPtVXD is too small to calculate range of phi-sectors needed to find triplet with Pt more than _cutOnPtVXD." << std::endl; exit(1); + // middle phi + time = helix.getPointOnCircle(Rm, ref, point); + if (time < 0) { + std::cout << "_cutOnPtVXD is too small to calculate range of phi-sectors needed to find triplet with Pt more than " + "_cutOnPtVXD." + << std::endl; + exit(1); } - double phiM = atan2(point[1],point[0]); + double phiM = atan2(point[1], point[0]); std::cout << "Rm phi :" << phiM << std::endl; - //inner phi - time = helix.getPointOnCircle(Ri,ref,point); - if(time < 0){ - std::cout << "_cutOnPtVXD is too small to calculate range of phi-sectors needed to find triplet with Pt more than _cutOnPtVXD." << std::endl; exit(1); + // inner phi + time = helix.getPointOnCircle(Ri, ref, point); + if (time < 0) { + std::cout << "_cutOnPtVXD is too small to calculate range of phi-sectors needed to find triplet with Pt more than " + "_cutOnPtVXD." + << std::endl; + exit(1); } - double phiI = atan2(point[1],point[0]); + double phiI = atan2(point[1], point[0]); std::cout << "Ri phi :" << phiI << std::endl; - //Check - printf("phiRange[0] (for middle layer) : %f \n ",phiM - phiO); - printf("phiRange[1] (for inner layer) : %f \n ",phiI - phiO); - - //storing - phiRange.clear(); - phiRange.push_back(std::abs(phiM - phiO)); - phiRange.push_back(std::abs(phiI - phiO)); - - return; - -} - - - - - - - - - - - - + // Check + printf("phiRange[0] (for middle layer) : %f \n ", phiM - phiO); + printf("phiRange[1] (for inner layer) : %f \n ", phiI - phiO); + // storing + phiRange.clear(); + phiRange.push_back(std::abs(phiM - phiO)); + phiRange.push_back(std::abs(phiI - phiO)); + return; +} -void FPCCDSiliconTracking_MarlinTrk::Sorting(TrackExtendedVec & trackVec) { +void FPCCDSiliconTracking_MarlinTrk::Sorting(TrackExtendedVec& trackVec) { /** Sorting of Track Vector in ascending order of chi2/ndf */ - std::sort(trackVec.begin(), trackVec.end(), compare_TrackExtended() ); + std::sort(trackVec.begin(), trackVec.end(), compare_TrackExtended()); // also clean up? what does this do here? - for (size_t i=0, sizeOfVector=trackVec.size(); igetTrackerHitExtendedVec(); int nHits = int(hitVec.size()); - for (int ih=0;ihclearTrackVec(); } } - } - - - - -void FPCCDSiliconTracking_MarlinTrk::CreateTrack(TrackExtended * trackAR ) { +void FPCCDSiliconTracking_MarlinTrk::CreateTrack(TrackExtended* trackAR) { /** Method which creates Track out of TrackExtended objects. Checks for possible track splitting (separate track segments in VXD and FTD). */ - TrackerHitExtendedVec& hitVec = trackAR->getTrackerHitExtendedVec(); int nHits = int(hitVec.size()); - for (int i=0; igetTrackExtendedVec(); - if (trackVec.size() != 0) return ; + if (trackVec.size() != 0) + return; } // First check if the current track is piece of the split one @@ -2242,8 +2115,8 @@ void FPCCDSiliconTracking_MarlinTrk::CreateTrack(TrackExtended * trackAR ) { int nTrk = int(_trackImplVec.size()); - for (int itrk=0; itrkgetTrackerHitExtendedVec(); float phiNew = trackAR->getPhi(); @@ -2251,27 +2124,25 @@ void FPCCDSiliconTracking_MarlinTrk::CreateTrack(TrackExtended * trackAR ) { float thetaNew = M_PI_2 - atan(trackAR->getTanLambda()); float thetaOld = M_PI_2 - atan(trackOld->getTanLambda()); - float angle = (cos(phiNew)*cos(phiOld)+sin(phiNew)*sin(phiOld))*sin(thetaNew)*sin(thetaOld)+cos(thetaNew)*cos(thetaOld); + float angle = (cos(phiNew) * cos(phiOld) + sin(phiNew) * sin(phiOld)) * sin(thetaNew) * sin(thetaOld) + + cos(thetaNew) * cos(thetaOld); angle = acos(angle); - - - if (angle < _angleCutForMerging) { int nHitsOld = int(hitVecOld.size()); int nTotHits = nHits + nHitsOld; - double * xh = new double[nTotHits]; - double * yh = new double[nTotHits]; - float * zh = new float[nTotHits]; - double * wrh = new double[nTotHits]; - float * wzh = new float[nTotHits]; - float * rh = new float[nTotHits]; - float * ph = new float[nTotHits]; + double* xh = new double[nTotHits]; + double* yh = new double[nTotHits]; + float* zh = new float[nTotHits]; + double* wrh = new double[nTotHits]; + float* wzh = new float[nTotHits]; + float* rh = new float[nTotHits]; + float* ph = new float[nTotHits]; float par[5]; float epar[15]; - //float refPoint[3] = {0.,0.,0.}; - for (int ih=0;ihgetTrackerHit(); + // float refPoint[3] = {0.,0.,0.}; + for (int ih = 0; ih < nHits; ++ih) { + TrackerHit* trkHit = hitVec[ih]->getTrackerHit(); float rR = hitVec[ih]->getResolutionRPhi(); float rZ = hitVec[ih]->getResolutionZ(); if (int(hitVec[ih]->getTrackExtendedVec().size()) != 0) @@ -2279,32 +2150,31 @@ void FPCCDSiliconTracking_MarlinTrk::CreateTrack(TrackExtended * trackAR ) { xh[ih] = trkHit->getPosition()[0]; yh[ih] = trkHit->getPosition()[1]; zh[ih] = float(trkHit->getPosition()[2]); - wrh[ih] = double(1.0/(rR*rR)); - wzh[ih] = 1.0/(rZ*rZ); - rh[ih] = float(sqrt(xh[ih]*xh[ih]+yh[ih]*yh[ih])); - ph[ih] = float(atan2(yh[ih],xh[ih])); - } - for (int ih=0;ihgetTrackerHit(); - xh[ih+nHits] = trkHit->getPosition()[0]; - yh[ih+nHits] = trkHit->getPosition()[1]; - zh[ih+nHits] = float(trkHit->getPosition()[2]); + wrh[ih] = double(1.0 / (rR * rR)); + wzh[ih] = 1.0 / (rZ * rZ); + rh[ih] = float(sqrt(xh[ih] * xh[ih] + yh[ih] * yh[ih])); + ph[ih] = float(atan2(yh[ih], xh[ih])); + } + for (int ih = 0; ih < nHitsOld; ++ih) { + TrackerHit* trkHit = hitVecOld[ih]->getTrackerHit(); + xh[ih + nHits] = trkHit->getPosition()[0]; + yh[ih + nHits] = trkHit->getPosition()[1]; + zh[ih + nHits] = float(trkHit->getPosition()[2]); float rR = hitVecOld[ih]->getResolutionRPhi(); - float rZ = hitVecOld[ih]->getResolutionZ(); - wrh[ih+nHits] = double(1.0/(rR*rR)); - wzh[ih+nHits] = 1.0/(rZ*rZ); - rh[ih+nHits] = float(sqrt(xh[ih+nHits]*xh[ih+nHits]+yh[ih+nHits]*yh[ih+nHits])); - ph[ih+nHits] = float(atan2(yh[ih+nHits],xh[ih+nHits])); - + float rZ = hitVecOld[ih]->getResolutionZ(); + wrh[ih + nHits] = double(1.0 / (rR * rR)); + wzh[ih + nHits] = 1.0 / (rZ * rZ); + rh[ih + nHits] = float(sqrt(xh[ih + nHits] * xh[ih + nHits] + yh[ih + nHits] * yh[ih + nHits])); + ph[ih + nHits] = float(atan2(yh[ih + nHits], xh[ih + nHits])); } int NPT = nTotHits; int iopt = 2; float chi2RPhi; float chi2Z; - int ndf = 2*NPT - 5; + int ndf = 2 * NPT - 5; - _fastfitter->fastHelixFit(NPT, xh, yh, rh, ph, wrh, zh, wzh,iopt, par, epar, chi2RPhi, chi2Z); - par[3] = par[3]*par[0]/fabs(par[0]); + _fastfitter->fastHelixFit(NPT, xh, yh, rh, ph, wrh, zh, wzh, iopt, par, epar, chi2RPhi, chi2Z); + par[3] = par[3] * par[0] / fabs(par[0]); float omega = par[0]; float tanlambda = par[1]; @@ -2313,61 +2183,58 @@ void FPCCDSiliconTracking_MarlinTrk::CreateTrack(TrackExtended * trackAR ) { float z0 = par[4]; float eparmin[15]; - for (int iparam=0;iparam<15;++iparam) - eparmin[iparam] = epar[iparam]; + for (int iparam = 0; iparam < 15; ++iparam) + eparmin[iparam] = epar[iparam]; // float refPointMin[3]; // for (int ipp=0;ipp<3;++ipp) // refPointMin[ipp] = refPoint[ipp]; - float chi2Min = chi2RPhi*_chi2WRPhiSeptet+chi2Z*_chi2WZSeptet; - chi2Min = chi2Min/float(ndf); - - //float chi2MinRPhi = chi2RPhi; - //float chi2MinZ = chi2Z; + float chi2Min = chi2RPhi * _chi2WRPhiSeptet + chi2Z * _chi2WZSeptet; + chi2Min = chi2Min / float(ndf); + // float chi2MinRPhi = chi2RPhi; + // float chi2MinZ = chi2Z; int iBad = -1; if (chi2Min < _chi2FitCut && std::isnormal(chi2Min) == true && chi2Min > 0) { - //Mori added new requirement that chi2Min be normal value on September 1, 2013. + // Mori added new requirement that chi2Min be normal value on September 1, 2013. found = 1; - } - else { // SJA:FIXME: UH What is going on here? setting weights to 0 and refitting? - float * wzhOld = new float[nTotHits]; - double * wrhOld = new double[nTotHits]; - for (int i=0;ifastHelixFit(NPT, xh, yh, rh, ph, wrh, zh, wzh,iopt, par, epar, chi2RPhi, chi2Z); - par[3] = par[3]*par[0]/fabs(par[0]); + _fastfitter->fastHelixFit(NPT, xh, yh, rh, ph, wrh, zh, wzh, iopt, par, epar, chi2RPhi, chi2Z); + par[3] = par[3] * par[0] / fabs(par[0]); - float chi2Cur = chi2RPhi*_chi2WRPhiSeptet+chi2Z*_chi2WZSeptet; - chi2Cur = chi2Cur/float(ndf); + float chi2Cur = chi2RPhi * _chi2WRPhiSeptet + chi2Z * _chi2WZSeptet; + chi2Cur = chi2Cur / float(ndf); if (chi2Cur < chi2Min && std::isnormal(chi2Min) == 1 && chi2Min > 0) { - //Mori added new requirement that chi2Min be normal value on September 1, 2013. + // Mori added new requirement that chi2Min be normal value on September 1, 2013. chi2Min = chi2Cur; - //chi2MinRPhi = chi2RPhi; - //chi2MinZ = chi2Z; + // chi2MinRPhi = chi2RPhi; + // chi2MinZ = chi2Z; omega = par[0]; tanlambda = par[1]; phi0 = par[2]; d0 = par[3]; z0 = par[4]; - for (int iparam=0;iparam<15;++iparam) + for (int iparam = 0; iparam < 15; ++iparam) eparmin[iparam] = epar[iparam]; // for (int ipp=0;ipp<3;++ipp) // refPointMin[ipp] = refPoint[ipp]; @@ -2375,9 +2242,8 @@ void FPCCDSiliconTracking_MarlinTrk::CreateTrack(TrackExtended * trackAR ) { } } - - if(chi2Min < _chi2FitCut && std::isnormal(chi2Min) == 1 && chi2Min > 0){ - //Mori added new requirement that chi2Min be normal value on September 1, 2013. + if (chi2Min < _chi2FitCut && std::isnormal(chi2Min) == 1 && chi2Min > 0) { + // Mori added new requirement that chi2Min be normal value on September 1, 2013. found = 1; } delete[] wzhOld; @@ -2385,29 +2251,27 @@ void FPCCDSiliconTracking_MarlinTrk::CreateTrack(TrackExtended * trackAR ) { } // Split track is found. - // Attach hits belonging to the current track segment to + // Attach hits belonging to the current track segment to // the track already created if (found == 1) { trackOld->ClearTrackerHitExtendedVec(); - for (int i=0;iclearTrackVec(); - if (i == iBad) { - } - else { + if (i == iBad) { + } else { trackOld->addTrackerHitExtended(trkHit); - trkHit->addTrackExtended( trackOld ); + trkHit->addTrackExtended(trackOld); } - } - for (int i=0;iclearTrackVec(); if (icur == iBad) { - } - else { + } else { trackOld->addTrackerHitExtended(trkHit); - trkHit->addTrackExtended( trackOld ); + trkHit->addTrackExtended(trackOld); } } trackOld->setOmega(omega); @@ -2423,7 +2287,7 @@ void FPCCDSiliconTracking_MarlinTrk::CreateTrack(TrackExtended * trackAR ) { // In fact it has never been initialised or used anywhere. I think this line should not be executed. // ndf = ndf_D; - trackOld->setChi2(chi2Min*float(ndf)); + trackOld->setChi2(chi2Min * float(ndf)); trackOld->setNDF(ndf); trackOld->setCovMatrix(eparmin); // trackOld->setReferencePoint(refPointMin); @@ -2436,159 +2300,173 @@ void FPCCDSiliconTracking_MarlinTrk::CreateTrack(TrackExtended * trackAR ) { delete[] wzh; delete[] rh; delete[] ph; - } - if(found == 1) break; + if (found == 1) + break; } // Candidate is a unique track // No other segments are found - if(found == 0 ){ + if (found == 0) { _trackImplVec.push_back(trackAR); - for (int i=0;iaddTrackExtended( trackAR ); + for (int i = 0; i < nHits; ++i) { + TrackerHitExtended* hit = hitVec[i]; + hit->addTrackExtended(trackAR); } } - return ; + return; } - - - void FPCCDSiliconTracking_MarlinTrk::AttachRemainingVTXHitsVeryFast() { int nTracks = int(_trackImplVec.size()); - for (int iTrk=0;iTrkgetTrackExtendedVec(); - for(unsigned int itrack = 0; itrack < trackVec.size(); itrack++){ + for (unsigned int itrack = 0; itrack < trackVec.size(); itrack++) { TrackerHitExtendedVec hitVec_tmp = trackVec[itrack]->getTrackerHitExtendedVec(); - if( hitVec_tmp.size() > maxTrackSize) maxTrackSize = hitVec_tmp.size(); - if(maxTrackSize > 3) break; - } + if (hitVec_tmp.size() > maxTrackSize) + maxTrackSize = hitVec_tmp.size(); + if (maxTrackSize > 3) + break; + } } - if (maxTrackSize<=3) { + if (maxTrackSize <= 3) { bool consider = true; - if (_checkForDelta) {//I use this without any modification. + if (_checkForDelta) { // I use this without any modification. TrackerHitExtendedVec& hitVector = trackAR->getTrackerHitExtendedVec(); int NHITS = int(hitVector.size()); - for (int IHIT=0;IHITgetTrackerHit(); - TrackerHit* trkhit2 = hitVector[IHIT]->getTrackerHit(); - if ( trkhit1->getCellID0() == trkhit2->getCellID0() ){ // i.e. they are in the same sensor + TrackerHit* trkhit2 = hitVector[IHIT]->getTrackerHit(); + if (trkhit1->getCellID0() == trkhit2->getCellID0()) { // i.e. they are in the same sensor float distance = 0.; - for (int iC=0;iC<3;++iC) { + for (int iC = 0; iC < 3; ++iC) { float posFirst = float(hit->getTrackerHit()->getPosition()[iC]); float posSecond = float(hitVector[IHIT]->getTrackerHit()->getPosition()[iC]); float deltaPos = posFirst - posSecond; - distance += deltaPos*deltaPos; + distance += deltaPos * deltaPos; } distance = sqrt(distance); - if (distance<_minDistToDelta) { consider = false; break; } + if (distance < _minDistToDelta) { + consider = false; + break; + } } } } - if (consider) { - double phi0 = trackAR->getPhi(); double d0 = trackAR->getD0(); double z0 = trackAR->getZ0(); - double omega = trackAR->getOmega(); double tanlambda = trackAR->getTanLambda(); - HelixClass_double helix; helix.Initialize_Canonical(phi0,d0,z0,omega,tanlambda,_bField); - double pos[3]; double distance[3]; - for (int i=0; i<3; ++i) pos[i] = hit->getTrackerHit()->getPosition()[i]; - float time = helix.getDistanceToPoint(pos,distance); - if (time < 1.0e+10 && distance[2] < minDist) { minDist = distance[2]; trkhitToAttach = hit; } + if (consider) { + double phi0 = trackAR->getPhi(); + double d0 = trackAR->getD0(); + double z0 = trackAR->getZ0(); + double omega = trackAR->getOmega(); + double tanlambda = trackAR->getTanLambda(); + HelixClass_double helix; + helix.Initialize_Canonical(phi0, d0, z0, omega, tanlambda, _bField); + double pos[3]; + double distance[3]; + for (int i = 0; i < 3; ++i) + pos[i] = hit->getTrackerHit()->getPosition()[i]; + float time = helix.getDistanceToPoint(pos, distance); + if (time < 1.0e+10 && distance[2] < minDist) { + minDist = distance[2]; + trkhitToAttach = hit; + } } } } } } if (minDist < _minDistCutAttachForVXD && trkhitToAttach != NULL) { - //int attachment_status = AttachHitToTrack_KalFit(trackAR,trkhitToAttach);//1 means attachment is done. - AttachHitToTrack_KalFit(trackAR,trkhitToAttach);//1 means attachment is done. - } + // int attachment_status = AttachHitToTrack_KalFit(trackAR,trkhitToAttach);//1 means attachment is done. + AttachHitToTrack_KalFit(trackAR, trkhitToAttach); // 1 means attachment is done. + } } - }//end of nTrack mori + } // end of nTrack mori return; } - - void FPCCDSiliconTracking_MarlinTrk::AttachRemainingVTXHitsFast() { std::vector nonAttachedHits; - nonAttachedHits.resize(_nDivisionsInPhi*_nDivisionsInTheta); + nonAttachedHits.resize(_nDivisionsInPhi * _nDivisionsInTheta); std::vector trackVector; - trackVector.resize(_nDivisionsInPhi*_nDivisionsInTheta); + trackVector.resize(_nDivisionsInPhi * _nDivisionsInTheta); int nTracks = int(_trackImplVec.size()); - for (int iTrk=0;iTrkgetPhi()); if (Phi < 0) Phi = Phi + TWOPI; float tanlambda = track->getTanLambda(); - double cosTheta = double(tanlambda/sqrt(1+tanlambda*tanlambda)); - int iPhi = int(Phi/_dPhi);//This way does hardly attach hits to low Pt tracks. - int iTheta = int ((cosTheta + double(1.0))/_dTheta); - int iCode = iPhi + _nDivisionsInPhi*iTheta; - trackVector[iCode].push_back( track ); + double cosTheta = double(tanlambda / sqrt(1 + tanlambda * tanlambda)); + int iPhi = int(Phi / _dPhi); // This way does hardly attach hits to low Pt tracks. + int iTheta = int((cosTheta + double(1.0)) / _dTheta); + int iCode = iPhi + _nDivisionsInPhi * iTheta; + trackVector[iCode].push_back(track); } - for (int il=0;il<_nLayers;++il) { - for (int ip=0;ip<_nDivisionsInPhi;++ip) { - for (int it=0;it<_nDivisionsInTheta; ++it) { - int iCode = il + _nLayers*ip + _nLayers*_nDivisionsInPhi*it; + for (int il = 0; il < _nLayers; ++il) { + for (int ip = 0; ip < _nDivisionsInPhi; ++ip) { + for (int it = 0; it < _nDivisionsInTheta; ++it) { + int iCode = il + _nLayers * ip + _nLayers * _nDivisionsInPhi * it; TrackerHitExtendedVec& hitVec = _sectors[iCode]; int nH = int(hitVec.size()); - for (int iH=0; iHgetTrackExtendedVec(); - if (trackVec.size()==0) { - TrackerHit * hit = hitExt->getTrackerHit(); + if (trackVec.size() == 0) { + TrackerHit* hit = hitExt->getTrackerHit(); double pos[3]; double radius = 0; - for (int i=0; i<3; ++i) { + for (int i = 0; i < 3; ++i) { pos[i] = hit->getPosition()[i]; - radius += pos[i]*pos[i]; + radius += pos[i] * pos[i]; } radius = sqrt(radius); - double cosTheta = pos[2]/radius; - double Phi = atan2(pos[1],pos[0]); - if (Phi < 0.) Phi = Phi + TWOPI; - int iPhi = int(Phi/_dPhi); - int iTheta = int ((cosTheta + double(1.0))/_dTheta); - iCode = iPhi + _nDivisionsInPhi*iTheta; - nonAttachedHits[iCode].push_back( hitExt ); + double cosTheta = pos[2] / radius; + double Phi = atan2(pos[1], pos[0]); + if (Phi < 0.) + Phi = Phi + TWOPI; + int iPhi = int(Phi / _dPhi); + int iTheta = int((cosTheta + double(1.0)) / _dTheta); + iCode = iPhi + _nDivisionsInPhi * iTheta; + nonAttachedHits[iCode].push_back(hitExt); } } } } } - for (int iT=0; iT<_nDivisionsInTheta; ++iT) { - for (int iP=0; iP<_nDivisionsInPhi; ++iP) { - int iCode = iP + _nDivisionsInPhi*iT; + for (int iT = 0; iT < _nDivisionsInTheta; ++iT) { + for (int iP = 0; iP < _nDivisionsInPhi; ++iP) { + int iCode = iP + _nDivisionsInPhi * iT; int nHits = int(nonAttachedHits[iCode].size()); int iT1 = iT - 1; - int iT2 = iT + 1; + int iT2 = iT + 1; if (iT == 0) { iT1 = iT; iT2 = iT1 + 1; @@ -2601,71 +2479,71 @@ void FPCCDSiliconTracking_MarlinTrk::AttachRemainingVTXHitsFast() { iPHI[0] = iP - 1; iPHI[1] = iP; iPHI[2] = iP + 1; - if (iP == 0) + if (iP == 0) iPHI[0] = _nDivisionsInPhi - 1; - if (iP == _nDivisionsInPhi - 1 ) + if (iP == _nDivisionsInPhi - 1) iPHI[2] = 0; - for (int ihit = 0; ihitgetTrackerHitExtendedVec(); int NHITS = int(hitVector.size()); - for (int IHIT=0;IHITgetTrackerHit(); - TrackerHit* trkhit2 = hitVector[IHIT]->getTrackerHit(); + TrackerHit* trkhit2 = hitVector[IHIT]->getTrackerHit(); - if ( trkhit1->getCellID0() == trkhit2->getCellID0() ){ // i.e. they are in the same sensor + if (trkhit1->getCellID0() == trkhit2->getCellID0()) { // i.e. they are in the same sensor float distance = 0.; - for (int iC=0;iC<3;++iC) { + for (int iC = 0; iC < 3; ++iC) { float posFirst = float(hit->getTrackerHit()->getPosition()[iC]); float posSecond = float(hitVector[IHIT]->getTrackerHit()->getPosition()[iC]); float deltaPos = posFirst - posSecond; - distance += deltaPos*deltaPos; + distance += deltaPos * deltaPos; } distance = sqrt(distance); - if (distance<_minDistToDelta) { + if (distance < _minDistToDelta) { consider = false; break; } } } } - if (consider) { + if (consider) { double phi0 = trackAR->getPhi(); double d0 = trackAR->getD0(); double z0 = trackAR->getZ0(); double omega = trackAR->getOmega(); double tanlambda = trackAR->getTanLambda(); HelixClass_double helix; - helix.Initialize_Canonical(phi0,d0,z0,omega,tanlambda,_bField); + helix.Initialize_Canonical(phi0, d0, z0, omega, tanlambda, _bField); int layer = getLayerID(hit->getTrackerHit()); if (layer > _minimalLayerToAttach) { double pos[3]; - for (int i=0; i<3; ++i) - pos[i] = hit->getTrackerHit()->getPosition()[i]; + for (int i = 0; i < 3; ++i) + pos[i] = hit->getTrackerHit()->getPosition()[i]; double distance[3]; - double time = helix.getDistanceToPoint(pos,distance); + double time = helix.getDistanceToPoint(pos, distance); if (time < 1.0e+10) { if (distance[2] < minDist) { minDist = distance[2]; trackToAttach = trackAR; - } - } + } + } } } } @@ -2673,8 +2551,8 @@ void FPCCDSiliconTracking_MarlinTrk::AttachRemainingVTXHitsFast() { } if (minDist < _minDistCutAttachForVXD && trackToAttach != NULL) { int iopt = 2; - AttachHitToTrack(trackToAttach,hit,iopt); - } + AttachHitToTrack(trackToAttach, hit, iopt); + } } } } @@ -2685,30 +2563,29 @@ void FPCCDSiliconTracking_MarlinTrk::AttachRemainingVTXHitsSlow() { TrackerHitExtendedVec nonAttachedHits; nonAttachedHits.clear(); - for (int il=0;il<_nLayers;++il) { - for (int ip=0;ip<_nDivisionsInPhi;++ip) { - for (int it=0;it<_nDivisionsInTheta; ++it) { - int iCode = il + _nLayers*ip + _nLayers*_nDivisionsInPhi*it; + for (int il = 0; il < _nLayers; ++il) { + for (int ip = 0; ip < _nDivisionsInPhi; ++ip) { + for (int it = 0; it < _nDivisionsInTheta; ++it) { + int iCode = il + _nLayers * ip + _nLayers * _nDivisionsInPhi * it; TrackerHitExtendedVec& hitVec = _sectors[iCode]; int nH = int(hitVec.size()); - for (int iH=0; iHgetTrackExtendedVec(); // if (trackVec.size()==0) // nonAttachedHits.push_back( hit ); - //-- allow hits that are only used in triplets to be re-attached + //-- allow hits that are only used in triplets to be re-attached unsigned int maxTrackSize = 0; - for(unsigned int itrack = 0; itrack < trackVec.size(); itrack++){ - TrackerHitExtendedVec hitVec_tmp= trackVec[itrack]->getTrackerHitExtendedVec(); + for (unsigned int itrack = 0; itrack < trackVec.size(); itrack++) { + TrackerHitExtendedVec hitVec_tmp = trackVec[itrack]->getTrackerHitExtendedVec(); unsigned int isize = hitVec_tmp.size(); - if(isize>maxTrackSize)maxTrackSize = isize; - } - if (maxTrackSize<=3) { + if (isize > maxTrackSize) + maxTrackSize = isize; + } + if (maxTrackSize <= 3) { streamlog_out(DEBUG1) << " Add non attached hit to list: id = " << hit->getTrackerHit()->id() << std::endl; - nonAttachedHits.push_back( hit ); - } - - + nonAttachedHits.push_back(hit); + } } } } @@ -2716,45 +2593,46 @@ void FPCCDSiliconTracking_MarlinTrk::AttachRemainingVTXHitsSlow() { int nNotAttached = int(nonAttachedHits.size()); - int nTrk = int(_trackImplVec.size()); - for (int iHit=0; iHitid() << std::endl; + streamlog_out(DEBUG1) << " hit: id = " << hit->getTrackerHit()->id() + << " condsidered delta together with hit " << trkhit2->id() << std::endl; break; } - } + } } } if (consider) { @@ -2764,9 +2642,9 @@ void FPCCDSiliconTracking_MarlinTrk::AttachRemainingVTXHitsSlow() { double z0 = trackAR->getZ0(); double omega = trackAR->getOmega(); double tanlambda = trackAR->getTanLambda(); - helix.Initialize_Canonical(phi0,d0,z0,omega,tanlambda,_bField); + helix.Initialize_Canonical(phi0, d0, z0, omega, tanlambda, _bField); double distance[3]; - double time = helix.getDistanceToPoint(pos,distance); + double time = helix.getDistanceToPoint(pos, distance); if (time < 1.0e+10) { if (distance[2] < minDist) { minDist = distance[2]; @@ -2777,30 +2655,31 @@ void FPCCDSiliconTracking_MarlinTrk::AttachRemainingVTXHitsSlow() { } if (minDist < _minDistCutAttachForVXD && trackToAttach != NULL) { int iopt = 2; - streamlog_out(DEBUG1) << " Hit: id = " << hit->getTrackerHit()->id() << " : try attachement"<< std::endl; - AttachHitToTrack(trackToAttach,hit,iopt); + streamlog_out(DEBUG1) << " Hit: id = " << hit->getTrackerHit()->id() << " : try attachement" << std::endl; + AttachHitToTrack(trackToAttach, hit, iopt); } else { - streamlog_out(DEBUG1) << " Hit: id = " << hit->getTrackerHit()->id() << " rejected due to distance cut of " <<_minDistCutAttachForVXD<< " min distance = " << minDist << std::endl; - } + streamlog_out(DEBUG1) << " Hit: id = " << hit->getTrackerHit()->id() << " rejected due to distance cut of " + << _minDistCutAttachForVXD << " min distance = " << minDist << std::endl; + } } - } + } } void FPCCDSiliconTracking_MarlinTrk::AttachRemainingFTDHitsSlow() { TrackerHitExtendedVec nonAttachedHits; nonAttachedHits.clear(); - for (int iS=0;iS<2;++iS) { - for (unsigned int layer=0;layer<_nlayersFTD;++layer) { - for (int ip=0;ip<_nPhiFTD;++ip) { - int iCode = iS + 2*layer + 2*_nlayersFTD*ip; + for (int iS = 0; iS < 2; ++iS) { + for (unsigned int layer = 0; layer < _nlayersFTD; ++layer) { + for (int ip = 0; ip < _nPhiFTD; ++ip) { + int iCode = iS + 2 * layer + 2 * _nlayersFTD * ip; TrackerHitExtendedVec& hitVec = _sectorsFTD[iCode]; int nH = int(hitVec.size()); - for (int iH=0; iHgetTrackExtendedVec(); - if (trackVec.size()==0) - nonAttachedHits.push_back( hit ); + if (trackVec.size() == 0) + nonAttachedHits.push_back(hit); } } } @@ -2808,24 +2687,24 @@ void FPCCDSiliconTracking_MarlinTrk::AttachRemainingFTDHitsSlow() { int nNotAttached = int(nonAttachedHits.size()); - int nTrk = int(_trackImplVec.size()); - for (int iHit=0; iHitgetTrackerHit()->getPosition()[i]; + for (int i = 0; i < 3; ++i) + pos[i] = hit->getTrackerHit()->getPosition()[i]; double minDist = 1e+10; - TrackExtended * trackToAttach = NULL; - for (int iTrk=0; iTrkgetTrackerHitExtendedVec(); int NHITS = int(hitVector.size()); - for (int IHIT=0;IHITgetTrackerHit()->getType() == hitVector[IHIT]->getTrackerHit()->getType()) + // SJA:FIXME: check to see if allowing no hits in the same sensor vs no hits in the same layer works + // if (hit->getTrackerHit()->getType() == hitVector[IHIT]->getTrackerHit()->getType()) if (hit->getTrackerHit()->getCellID0() == hitVector[IHIT]->getTrackerHit()->getCellID0()) { consider = false; @@ -2833,7 +2712,6 @@ void FPCCDSiliconTracking_MarlinTrk::AttachRemainingFTDHitsSlow() { } } - if (consider) { HelixClass_double helix; double phi0 = trackAR->getPhi(); @@ -2841,10 +2719,10 @@ void FPCCDSiliconTracking_MarlinTrk::AttachRemainingFTDHitsSlow() { double z0 = trackAR->getZ0(); double omega = trackAR->getOmega(); double tanlambda = trackAR->getTanLambda(); - if (tanlambda*double(getSideID(hit->getTrackerHit())) > 0) { - helix.Initialize_Canonical(phi0,d0,z0,omega,tanlambda,_bField); + if (tanlambda * double(getSideID(hit->getTrackerHit())) > 0) { + helix.Initialize_Canonical(phi0, d0, z0, omega, tanlambda, _bField); double distance[3]; - double time = helix.getDistanceToPoint(pos,distance); + double time = helix.getDistanceToPoint(pos, distance); if (time < 1.0e+10) { if (distance[2] < minDist) { minDist = distance[2]; @@ -2856,74 +2734,72 @@ void FPCCDSiliconTracking_MarlinTrk::AttachRemainingFTDHitsSlow() { } if (minDist < _minDistCutAttachForFTD && trackToAttach != NULL) { int iopt = 2; - AttachHitToTrack(trackToAttach,hit,iopt); - } - } + AttachHitToTrack(trackToAttach, hit, iopt); + } + } } - void FPCCDSiliconTracking_MarlinTrk::AttachRemainingFTDHitsFast() { int nTrk = _trackImplVec.size(); - for (int iTrk=0; iTrkgetPhi(); double d0 = trackAR->getD0(); double z0 = trackAR->getZ0(); double omega = trackAR->getOmega(); double tanlambda = trackAR->getTanLambda(); - helix.Initialize_Canonical(phi0,d0,z0,omega,tanlambda,_bField); + helix.Initialize_Canonical(phi0, d0, z0, omega, tanlambda, _bField); int iSemiSphere = 0; - if (tanlambda > 0) + if (tanlambda > 0) iSemiSphere = 1; double ref[3]; - for (int i=0;i<3;++i) + for (int i = 0; i < 3; ++i) ref[i] = helix.getReferencePoint()[i]; // Start loop over FTD layers - for (unsigned int layer=0;layer<_nlayersFTD;layer++) { + for (unsigned int layer = 0; layer < _nlayersFTD; layer++) { double ZL = _zLayerFTD[layer]; if (iSemiSphere == 0) - ZL = - ZL; + ZL = -ZL; double point[3]; - helix.getPointInZ(ZL,ref,point); - double Phi = atan2(point[1],point[0]); - if (Phi < 0) + helix.getPointInZ(ZL, ref, point); + double Phi = atan2(point[1], point[0]); + if (Phi < 0) Phi = Phi + TWOPI; - int iPhi = int(Phi/_dPhiFTD); + int iPhi = int(Phi / _dPhiFTD); double distMin = 1e+10; - TrackerHitExtended * attachedHit = NULL; - for (int iP=iPhi-1;iP<=iPhi+1;++iP) { + TrackerHitExtended* attachedHit = NULL; + for (int iP = iPhi - 1; iP <= iPhi + 1; ++iP) { int iPP = iP; - if (iP < 0) + if (iP < 0) iPP = iP + _nPhiFTD; if (iP >= _nPhiFTD) - iPP = iP - _nPhiFTD; - int iCode = iSemiSphere + 2*layer + 2*_nlayersFTD*iPP; + iPP = iP - _nPhiFTD; + int iCode = iSemiSphere + 2 * layer + 2 * _nlayersFTD * iPP; int nHits = int(_sectorsFTD[iCode].size()); - for (int iHit=0;iHitgetTrackerHitExtendedVec(); int NHITS = int(hitVector.size()); - // SJA:FIXME: check to see if allowing no hits in the same sensor vs no hits in the same layer works - for (int IHIT=0;IHITgetTrackerHit()->getType() == hitVector[IHIT]->getTrackerHit()->getType()) + // SJA:FIXME: check to see if allowing no hits in the same sensor vs no hits in the same layer works + for (int IHIT = 0; IHIT < NHITS; ++IHIT) { + // if (hit->getTrackerHit()->getType() == hitVector[IHIT]->getTrackerHit()->getType()) if (hit->getTrackerHit()->getCellID0() == hitVector[IHIT]->getTrackerHit()->getCellID0()) { consider = false; break; } } - if (consider) { double pos[3]; - for (int i=0;i<3;++i) { + for (int i = 0; i < 3; ++i) { pos[i] = hit->getTrackerHit()->getPosition()[i]; } double distance[3]; - double time = helix.getDistanceToPoint(pos,distance); + double time = helix.getDistanceToPoint(pos, distance); if (time < 1.0e+10) { if (distance[2] < distMin) { distMin = distance[2]; @@ -2935,7 +2811,7 @@ void FPCCDSiliconTracking_MarlinTrk::AttachRemainingFTDHitsFast() { } if (distMin < _minDistCutAttachForFTD && attachedHit != NULL) { int iopt = 2; - AttachHitToTrack(trackAR,attachedHit, iopt); + AttachHitToTrack(trackAR, attachedHit, iopt); } } } @@ -2945,14 +2821,14 @@ void FPCCDSiliconTracking_MarlinTrk::TrackingInFTD() { int nComb = int(_CombinationsFTD.size()) / 3; - for (int iComb=0;iComb= _sectorsFTD.size()){ - streamlog_out(ERROR) << "iCodeOuter index out of range: iCodeOuter = " << iCodeOuter << " _sectorsFTD.size() = " << _sectorsFTD.size() << " exit(1) called from file " << __FILE__ << " line " << __LINE__<< std::endl; + if (iCodeOuter >= _sectorsFTD.size()) { + streamlog_out(ERROR) << "iCodeOuter index out of range: iCodeOuter = " << iCodeOuter + << " _sectorsFTD.size() = " << _sectorsFTD.size() << " exit(1) called from file " + << __FILE__ << " line " << __LINE__ << std::endl; exit(1); } @@ -2982,76 +2860,77 @@ void FPCCDSiliconTracking_MarlinTrk::TrackingInFTD() { int nOuter = int(hitVecOuter.size()); - for (int iOuter=0;iOuter= _nPhiFTD) ipM = ipMiddle - _nPhiFTD; - int iCodeMiddle = iS + 2*nLS[1] + 2*_nlayersFTD*ipM; + int iCodeMiddle = iS + 2 * nLS[1] + 2 * _nlayersFTD * ipM; TrackerHitExtendedVec& hitVecMiddle = _sectorsFTD[iCodeMiddle]; - int ipInnerLow,ipInnerUp; + int ipInnerLow, ipInnerUp; ipInnerLow = ipMiddle - 1; - ipInnerUp = ipMiddle + 1; + ipInnerUp = ipMiddle + 1; int nMiddle = int(hitVecMiddle.size()); - for (int iMiddle=0;iMiddle= _nPhiFTD) + if (ipI >= _nPhiFTD) ipI = ipInner - _nPhiFTD; - int iCodeInner = iS + 2*nLS[2] + 2*_nlayersFTD*ipI; + int iCodeInner = iS + 2 * nLS[2] + 2 * _nlayersFTD * ipI; TrackerHitExtendedVec& hitVecInner = _sectorsFTD[iCodeInner]; int nInner = int(hitVecInner.size()); - for (int iInner=0;iInnergetTrackerHit()->getType() << " z = " << hitOuter->getTrackerHit()->getPosition()[2] - // << "\nMiddle Hit Type "<< hitMiddle->getTrackerHit()->getType() << " z = " << hitMiddle->getTrackerHit()->getPosition()[2] - // << "\nInner Hit Type "<< hitInner->getTrackerHit()->getType() << " z = " << hitInner->getTrackerHit()->getPosition()[2] << std::endl; - - streamlog_out(DEBUG1) << " " - << std::setw(3) << ipOuter << " " << std::setw(3) << ipMiddle << " " << std::setw(3) << ipInner << " " - << std::setw(3) << iS << " " - << std::setw(3) << nLS[0] << " " << std::setw(3) << nLS[1] << " " << std::setw(3) << nLS[2] << " " - << std::setw(3) << nOuter << " : " << std::setw(3) << nMiddle << " : " << std::setw(3) << nInner << " :: " - << std::setw(3) << nOuter*nMiddle* nInner << std::endl; - - - TrackExtended * trackAR = TestTriplet(hitOuter,hitMiddle,hitInner,helix,1); + // std::cout << "Outer Hit Type " << hitOuter->getTrackerHit()->getType() << " z = " + // << hitOuter->getTrackerHit()->getPosition()[2] + // << "\nMiddle Hit Type "<< hitMiddle->getTrackerHit()->getType() << " z = " << + // hitMiddle->getTrackerHit()->getPosition()[2] + // << "\nInner Hit Type "<< hitInner->getTrackerHit()->getType() << " z = " << + // hitInner->getTrackerHit()->getPosition()[2] << std::endl; + + streamlog_out(DEBUG1) << " " << std::setw(3) << ipOuter << " " << std::setw(3) << ipMiddle << " " + << std::setw(3) << ipInner << " " << std::setw(3) << iS << " " + << std::setw(3) << nLS[0] << " " << std::setw(3) << nLS[1] << " " + << std::setw(3) << nLS[2] << " " << std::setw(3) << nOuter << " : " + << std::setw(3) << nMiddle << " : " << std::setw(3) << nInner + << " :: " << std::setw(3) << nOuter * nMiddle * nInner << std::endl; + + TrackExtended* trackAR = TestTriplet(hitOuter, hitMiddle, hitInner, helix, 1); if (trackAR != NULL) { // std::cout << "FTD triplet found" << std::endl; - int nHits = BuildTrackFTD(trackAR,nLS,iS); + int nHits = BuildTrackFTD(trackAR, nLS, iS); - _tracksWithNHitsContainer.getTracksWithNHitsVec( nHits ).push_back( trackAR ); + _tracksWithNHitsContainer.getTracksWithNHitsVec(nHits).push_back(trackAR); } } } } - } + } } } } } } - -int FPCCDSiliconTracking_MarlinTrk::BuildTrackFTD(TrackExtended * trackAR, int * nLR, int iS) { +int FPCCDSiliconTracking_MarlinTrk::BuildTrackFTD(TrackExtended* trackAR, int* nLR, int iS) { // std::cout << "BuildTrackFTD: Layers = " << nLR[0] << " " << nLR[1] << " " << nLR[2] << std::endl; // initialise a helix from the track @@ -3061,39 +2940,37 @@ int FPCCDSiliconTracking_MarlinTrk::BuildTrackFTD(TrackExtended * trackAR, int * const double phi0 = trackAR->getPhi(); const double tanlambda = trackAR->getTanLambda(); const double omega = trackAR->getOmega(); - helix.Initialize_Canonical(phi0,d0,z0,omega,tanlambda,_bField); - double ref[3] = {helix.getReferencePoint()[0], - helix.getReferencePoint()[1], - helix.getReferencePoint()[2]}; + helix.Initialize_Canonical(phi0, d0, z0, omega, tanlambda, _bField); + double ref[3] = {helix.getReferencePoint()[0], helix.getReferencePoint()[1], helix.getReferencePoint()[2]}; - for (int iL=0; iL < static_cast(_nlayersFTD); ++iL) { + for (int iL = 0; iL < static_cast(_nlayersFTD); ++iL) { if (iL != nLR[0] && iL != nLR[1] && iL != nLR[2]) { double point[3]; double ZL = _zLayerFTD[iL]; - if (iS == 0) - ZL = - ZL; - helix.getPointInZ(ZL,ref,point); + if (iS == 0) + ZL = -ZL; + helix.getPointInZ(ZL, ref, point); // double Phi = atan2(point[1],point[0]); // int iPhi = int(Phi/_dPhiFTD); double distMin = 1e+6; - TrackerHitExtended * attachedHit = NULL; - for (int ip=0;ip<=_nPhiFTD;++ip) { + TrackerHitExtended* attachedHit = NULL; + for (int ip = 0; ip <= _nPhiFTD; ++ip) { int iP = ip; if (iP < 0) iP = ip + _nPhiFTD; if (iP >= _nPhiFTD) - iP = ip - _nPhiFTD; - int iCode = iS + 2*iL + 2*_nlayersFTD*iP; + iP = ip - _nPhiFTD; + int iCode = iS + 2 * iL + 2 * _nlayersFTD * iP; TrackerHitExtendedVec& hitVec = _sectorsFTD[iCode]; int nH = int(hitVec.size()); - for (int iH=0; iHgetTrackerHit(); + for (int iH = 0; iH < nH; ++iH) { + TrackerHitExtended* hit = hitVec[iH]; + TrackerHit* trkHit = hit->getTrackerHit(); double pos[3]; - for (int i=0;i<3;++i) + for (int i = 0; i < 3; ++i) pos[i] = double(trkHit->getPosition()[i]); double distance[3]; - double time = helix.getDistanceToPoint(pos,distance); + double time = helix.getDistanceToPoint(pos, distance); if (time < 1.0e+10) { if (distance[2] < distMin) { distMin = distance[2]; @@ -3105,46 +2982,49 @@ int FPCCDSiliconTracking_MarlinTrk::BuildTrackFTD(TrackExtended * trackAR, int * // std::cout << "Layer = " << iL << " distMin = " << distMin << std::endl; if (distMin < _minDistCutAttachForFTD && attachedHit != NULL) { int iopt = 2; - AttachHitToTrack( trackAR, attachedHit, iopt); + AttachHitToTrack(trackAR, attachedHit, iopt); } } } TrackerHitExtendedVec& hitVec = trackAR->getTrackerHitExtendedVec(); - int nH = int (hitVec.size()); + int nH = int(hitVec.size()); return nH; } - - - - #if 1 -//Here will be used in AttachRemainingVTXVeryFast which is under construction. +// Here will be used in AttachRemainingVTXVeryFast which is under construction. -int FPCCDSiliconTracking_MarlinTrk::AttachHitToTrack_KalFit(TrackExtended * trackAR, TrackerHitExtended * hit) { +int FPCCDSiliconTracking_MarlinTrk::AttachHitToTrack_KalFit(TrackExtended* trackAR, TrackerHitExtended* hit) { TrackerHitExtendedVec& hitVec = trackAR->getTrackerHitExtendedVec(); - std::vector< std::pair > r2_values; + std::vector> r2_values; r2_values.reserve(hitVec.size() + 1); for (TrackerHitExtendedVec::iterator it = hitVec.begin(); it != hitVec.end(); ++it) { EVENT::TrackerHit* h = (*it)->getTrackerHit(); - double r2 = pow(h->getPosition()[0],2) + pow(h->getPosition()[1],2); + double r2 = pow(h->getPosition()[0], 2) + pow(h->getPosition()[1], 2); r2_values.push_back(std::make_pair(r2, h)); } - std::sort(r2_values.begin(),r2_values.end()); + std::sort(r2_values.begin(), r2_values.end()); - TrackerHitVec trkHits; trkHits.reserve(r2_values.size()); - for (std::vector< std::pair >::iterator it=r2_values.begin(); it!=r2_values.end(); ++it) { + TrackerHitVec trkHits; + trkHits.reserve(r2_values.size()); + for (std::vector>::iterator it = r2_values.begin(); it != r2_values.end(); + ++it) { trkHits.push_back(it->second); } - int attached = 0; - float par[5]; float epar[15]; int ndf; float Chi2; - TrackerHitVec hits_in_fit; TrackerHitVec outliers; HelixClass_double helix; - int error = KalFit(ndf,Chi2,trkHits,hits_in_fit,outliers,par,epar,helix);//0 means the fit succeed + int attached = 0; + float par[5]; + float epar[15]; + int ndf; + float Chi2; + TrackerHitVec hits_in_fit; + TrackerHitVec outliers; + HelixClass_double helix; + int error = KalFit(ndf, Chi2, trkHits, hits_in_fit, outliers, par, epar, helix); // 0 means the fit succeed float d0 = par[0]; float phi0 = par[1]; @@ -3152,88 +3032,81 @@ int FPCCDSiliconTracking_MarlinTrk::AttachHitToTrack_KalFit(TrackExtended * trac float z0 = par[3]; float tanL = par[4]; - if ( error == 0 && Chi2/float(ndf) < _chi2FitCut_kalman ) { + if (error == 0 && Chi2 / float(ndf) < _chi2FitCut_kalman) { trackAR->addTrackerHitExtended(hit); - if(_keepCandidate != true) hit->addTrackExtended( trackAR ); + if (_keepCandidate != true) + hit->addTrackExtended(trackAR); /* After AttachRemainingVTXHits, we don't use this information. * If keepCandidate != true, the above hit is not remaining hit any more. */ - trackAR->setChi2( Chi2 ); - trackAR->setOmega( omega ); - trackAR->setTanLambda( tanL ); - trackAR->setD0( d0 ); - trackAR->setZ0( z0 ); - trackAR->setPhi( phi0 ); - trackAR->setNDF( ndf ); - trackAR->setCovMatrix( epar ); + trackAR->setChi2(Chi2); + trackAR->setOmega(omega); + trackAR->setTanLambda(tanL); + trackAR->setD0(d0); + trackAR->setZ0(z0); + trackAR->setPhi(phi0); + trackAR->setNDF(ndf); + trackAR->setCovMatrix(epar); attached = 1; - } + } return attached; } - - #endif - - - -int FPCCDSiliconTracking_MarlinTrk::AttachHitToTrack(TrackExtended * trackAR, TrackerHitExtended * hit, int iopt) { +int FPCCDSiliconTracking_MarlinTrk::AttachHitToTrack(TrackExtended* trackAR, TrackerHitExtended* hit, int iopt) { int attached = 0; TrackerHitExtendedVec& hitVec = trackAR->getTrackerHitExtendedVec(); int nHits = int(hitVec.size()); - double * xh = new double[nHits+1]; - double * yh = new double[nHits+1]; - float * zh = new float[nHits+1]; - double * wrh = new double[nHits+1]; - float * wzh = new float[nHits+1]; - float * rh = new float[nHits+1]; - float * ph = new float[nHits+1]; + double* xh = new double[nHits + 1]; + double* yh = new double[nHits + 1]; + float* zh = new float[nHits + 1]; + double* wrh = new double[nHits + 1]; + float* wzh = new float[nHits + 1]; + float* rh = new float[nHits + 1]; + float* ph = new float[nHits + 1]; float par[5]; float epar[15]; - for (int i=0; igetTrackerHit(); + for (int i = 0; i < nHits; ++i) { + TrackerHit* trkHit = hitVec[i]->getTrackerHit(); xh[i] = double(trkHit->getPosition()[0]); yh[i] = double(trkHit->getPosition()[1]); zh[i] = float(trkHit->getPosition()[2]); - ph[i] = float(atan2(yh[i],xh[i])); - rh[i] = float(sqrt(xh[i]*xh[i]+yh[i]*yh[i])); + ph[i] = float(atan2(yh[i], xh[i])); + rh[i] = float(sqrt(xh[i] * xh[i] + yh[i] * yh[i])); float rR = hitVec[i]->getResolutionRPhi(); float rZ = hitVec[i]->getResolutionZ(); - wrh[i] = double(1.0/(rR*rR)); - wzh[i] = 1.0/(rZ*rZ); + wrh[i] = double(1.0 / (rR * rR)); + wzh[i] = 1.0 / (rZ * rZ); } - TrackerHit * trkHit = hit->getTrackerHit(); + TrackerHit* trkHit = hit->getTrackerHit(); xh[nHits] = double(trkHit->getPosition()[0]); yh[nHits] = double(trkHit->getPosition()[1]); zh[nHits] = float(trkHit->getPosition()[2]); - ph[nHits] = float(atan2(yh[nHits],xh[nHits])); - rh[nHits] = float(sqrt(xh[nHits]*xh[nHits]+yh[nHits]*yh[nHits])); + ph[nHits] = float(atan2(yh[nHits], xh[nHits])); + rh[nHits] = float(sqrt(xh[nHits] * xh[nHits] + yh[nHits] * yh[nHits])); float rR = hit->getResolutionRPhi(); float rZ = hit->getResolutionZ(); - wrh[nHits] = double(1.0/(rR*rR)); - wzh[nHits] = 1.0/(rZ*rZ); - + wrh[nHits] = double(1.0 / (rR * rR)); + wzh[nHits] = 1.0 / (rZ * rZ); int NPT = nHits + 1; - // SJA:FIXME the newtonian part is giving crazy results for FTD so just use iopt 2 for simply attaching hits + // SJA:FIXME the newtonian part is giving crazy results for FTD so just use iopt 2 for simply attaching hits // using SIT and VXD doesn't seem to give any problems, so make it a function parameter and let the caller decide // int iopt = 3; - float chi2RPhi = 0 ; - float chi2Z = 0 ; - - - int error = _fastfitter->fastHelixFit(NPT, xh, yh, rh, ph, wrh, zh, wzh,iopt, par, epar, chi2RPhi, chi2Z); - par[3] = par[3]*par[0]/fabs(par[0]); + float chi2RPhi = 0; + float chi2Z = 0; + int error = _fastfitter->fastHelixFit(NPT, xh, yh, rh, ph, wrh, zh, wzh, iopt, par, epar, chi2RPhi, chi2Z); + par[3] = par[3] * par[0] / fabs(par[0]); float omega = par[0]; float tanlambda = par[1]; @@ -3244,36 +3117,38 @@ int FPCCDSiliconTracking_MarlinTrk::AttachHitToTrack(TrackExtended * trackAR, Tr int ndf = INT_MAX; if (NPT == 3) { - chi2 = chi2RPhi*_chi2WRPhiTriplet+chi2Z*_chi2WZTriplet; + chi2 = chi2RPhi * _chi2WRPhiTriplet + chi2Z * _chi2WZTriplet; } if (NPT == 4) { - chi2 = chi2RPhi*_chi2WRPhiQuartet+chi2Z*_chi2WZQuartet; + chi2 = chi2RPhi * _chi2WRPhiQuartet + chi2Z * _chi2WZQuartet; } if (NPT > 4) { - chi2 = chi2RPhi*_chi2WRPhiSeptet+chi2Z*_chi2WZSeptet; + chi2 = chi2RPhi * _chi2WRPhiSeptet + chi2Z * _chi2WZSeptet; } - ndf = 2*NPT-5; + ndf = 2 * NPT - 5; - - bool normalcase = false; - if(std::isnormal(chi2) && std::isnormal(ndf) && chi2 > 0 && ndf > 0){ + bool normalcase = false; + if (std::isnormal(chi2) && std::isnormal(ndf) && chi2 > 0 && ndf > 0) { normalcase = true; - }//Mori added new requirement that chi2Min be normal value on September 1, 2013. - if ( error == 0 && chi2/float(ndf) < _chi2FitCut && normalcase == true ) { + } // Mori added new requirement that chi2Min be normal value on September 1, 2013. + if (error == 0 && chi2 / float(ndf) < _chi2FitCut && normalcase == true) { trackAR->addTrackerHitExtended(hit); - hit->addTrackExtended( trackAR ); - trackAR->setChi2( chi2 ); - trackAR->setOmega( omega ); - trackAR->setTanLambda( tanlambda ); - trackAR->setD0( d0 ); - trackAR->setZ0( z0 ); - trackAR->setPhi( phi0 ); - trackAR->setNDF( ndf ); - trackAR->setCovMatrix( epar ); + hit->addTrackExtended(trackAR); + trackAR->setChi2(chi2); + trackAR->setOmega(omega); + trackAR->setTanLambda(tanlambda); + trackAR->setD0(d0); + trackAR->setZ0(z0); + trackAR->setPhi(phi0); + trackAR->setNDF(ndf); + trackAR->setCovMatrix(epar); attached = 1; - streamlog_out(DEBUG1) << "Attachement succeeded chi2/float(ndf) = " << chi2/float(ndf) << " cut = " << _chi2FitCut << " chi2RPhi = " << chi2RPhi << " chi2Z = " << chi2Z << " error = " << error << std::endl; + streamlog_out(DEBUG1) << "Attachement succeeded chi2/float(ndf) = " << chi2 / float(ndf) + << " cut = " << _chi2FitCut << " chi2RPhi = " << chi2RPhi << " chi2Z = " << chi2Z + << " error = " << error << std::endl; } else { - streamlog_out(DEBUG1) << "Attachement failed chi2/float(ndf) = " << chi2/float(ndf) << " cut = " << _chi2FitCut << " chi2RPhi = " << chi2RPhi << " chi2Z = " << chi2Z << " error = " << error << std::endl; + streamlog_out(DEBUG1) << "Attachement failed chi2/float(ndf) = " << chi2 / float(ndf) << " cut = " << _chi2FitCut + << " chi2RPhi = " << chi2RPhi << " chi2Z = " << chi2Z << " error = " << error << std::endl; } delete[] xh; @@ -3285,34 +3160,32 @@ int FPCCDSiliconTracking_MarlinTrk::AttachHitToTrack(TrackExtended * trackAR, Tr delete[] ph; return attached; - - } void FPCCDSiliconTracking_MarlinTrk::FinalRefit(LCCollectionVec* trk_col, LCCollectionVec* /*rel_col*/) { int nTracks = int(_trackImplVec.size()); - int nSiSegments = 0; + int nSiSegments = 0; double eTot = 0.; double pxTot = 0.; double pyTot = 0.; double pzTot = 0.; - for (int iTrk=0;iTrkgetTrackerHitExtendedVec(); int nHits = int(hitVec.size()); - if( nHits >= _minimalHits) { + if (nHits >= _minimalHits) { // int * lh = new int[nHits]; std::vector lh; lh.resize(nHits); - for (int i=0; igetD0(); @@ -3321,61 +3194,57 @@ void FPCCDSiliconTracking_MarlinTrk::FinalRefit(LCCollectionVec* trk_col, LCColl double tanlambda = trackAR->getTanLambda(); double phi0 = trackAR->getPhi(); - HelixClass_double * helix = new HelixClass_double(); - helix->Initialize_Canonical(phi0, d0, z0, omega, - tanlambda, _bField); - + HelixClass_double* helix = new HelixClass_double(); + helix->Initialize_Canonical(phi0, d0, z0, omega, tanlambda, _bField); // get the point of closest approach to the reference point - // here it is implicitly assumed that the reference point is the origin + // here it is implicitly assumed that the reference point is the origin double Pos[3]; - Pos[0] = -d0*sin(phi0); - Pos[1] = d0*cos(phi0); + Pos[0] = -d0 * sin(phi0); + Pos[1] = d0 * cos(phi0); Pos[2] = z0; - // at this point is is possible to have hits from the same layer ... - // so a check is made to ensure that the hit with the smallest distance to the - // current helix hypothosis is used, the other hit has lh set to 0 + // so a check is made to ensure that the hit with the smallest distance to the + // current helix hypothosis is used, the other hit has lh set to 0 // start loop over the hits to - for (int ihit=0;ihitgetTrackerHit(); + TrackerHit* trkHit = hitVec[ihit]->getTrackerHit(); int det = getDetectorID(trkHit); - if (det == lcio::ILDDetID::VXD || det == lcio::ILDDetID::FTD || det == lcio::ILDDetID::SIT) { // only accept VXD, FTD or SIT - + if (det == lcio::ILDDetID::VXD || det == lcio::ILDDetID::FTD || + det == lcio::ILDDetID::SIT) { // only accept VXD, FTD or SIT // int layer = getLayerID(trkHit); // int moduleIndex = getModuleID(trkHit); - // start a double loop over the hits which have already been checked - for (int lhit=0;lhitgetTrackerHit(); - + TrackerHit* trkHitS = hitVec[lhit]->getTrackerHit(); // int layerS = getLayerID(trkHitS); // int moduleIndexS = getModuleID(trkHitS); - // SJA:FIXME: check to see if allowing no hits in the same sensor vs no hits in the same layer works + // SJA:FIXME: check to see if allowing no hits in the same sensor vs no hits in the same layer works // if they are on the same layer and the previously checked hits has been declared good for fitting - // if ((trkHitS->getType() == trkHit->getType()) && (lh[lhit] == 1)) + // if ((trkHitS->getType() == trkHit->getType()) && (lh[lhit] == 1)) // check if the hits have the same layer and petal number // hitVec[ihit]-> - // if ((layer == layerS) && (moduleIndex==moduleIndexS) && (lh[lhit] == 1)) - if ( (trkHit->getCellID0() == trkHitS->getCellID0()) && (lh[lhit] == 1)) { + // if ((layer == layerS) && (moduleIndex==moduleIndexS) && (lh[lhit] == 1)) + if ((trkHit->getCellID0() == trkHitS->getCellID0()) && (lh[lhit] == 1)) { - // get the position of the hits + // get the position of the hits double xP[3]; double xPS[3]; - for (int iC=0;iC<3;++iC) { + for (int iC = 0; iC < 3; ++iC) { xP[iC] = double(trkHit->getPosition()[iC]); xPS[iC] = double(trkHitS->getPosition()[iC]); } @@ -3387,33 +3256,31 @@ void FPCCDSiliconTracking_MarlinTrk::FinalRefit(LCCollectionVec* trk_col, LCColl if (det == lcio::ILDDetID::FTD) { // double time = - helix->getPointInZ(xP[2],Pos,Point); + helix->getPointInZ(xP[2], Pos, Point); // double time = - helix->getPointInZ(xPS[2],Pos,PointS); + helix->getPointInZ(xPS[2], Pos, PointS); } else { - double RAD = sqrt(xP[0]*xP[0]+xP[1]*xP[1]); - double RADS = sqrt(xPS[0]*xPS[0]+xPS[1]*xPS[1]); + double RAD = sqrt(xP[0] * xP[0] + xP[1] * xP[1]); + double RADS = sqrt(xPS[0] * xPS[0] + xPS[1] * xPS[1]); // double time = - helix->getPointOnCircle(RAD,Pos,Point); + helix->getPointOnCircle(RAD, Pos, Point); // double time = - helix->getPointOnCircle(RADS,Pos,PointS); - + helix->getPointOnCircle(RADS, Pos, PointS); } double DIST = 0; double DISTS = 0; // get the euclidean distance between the hit and the point of intersection - for (int iC=0;iC<3;++iC) { - DIST += (Point[iC]-xP[iC])*(Point[iC]-xP[iC]); - DISTS += (PointS[iC]-xPS[iC])*(PointS[iC]-xPS[iC]); + for (int iC = 0; iC < 3; ++iC) { + DIST += (Point[iC] - xP[iC]) * (Point[iC] - xP[iC]); + DISTS += (PointS[iC] - xPS[iC]) * (PointS[iC] - xPS[iC]); } if (DIST < DISTS) { lh[lhit] = 0; - } - else { + } else { lh[ihit] = 0; } break; @@ -3428,63 +3295,62 @@ void FPCCDSiliconTracking_MarlinTrk::FinalRefit(LCCollectionVec* trk_col, LCColl EVENT::TrackerHitVec trkHits_used_inFit; int nFit = 0; - for (int i=0; igetTrackerHit(); + TrackerHit* trkHit = hitVec[i]->getTrackerHit(); nFit++; - if(trkHit) { - trkHits.push_back(trkHit); - } - else{ - throw EVENT::Exception( std::string("FPCCDSiliconTracking_MarlinTrk::FinalRefit: TrackerHit pointer == NULL ") ) ; + if (trkHit) { + trkHits.push_back(trkHit); + } else { + throw EVENT::Exception( + std::string("FPCCDSiliconTracking_MarlinTrk::FinalRefit: TrackerHit pointer == NULL ")); } - } - else { // reject hit + } else { // reject hit // SJA:FIXME missuse of type find a better way to signal rejected hits hitVec[i]->setType(int(0)); } } - - - if( trkHits.size() < 3 ) { - streamlog_out(DEBUG3) << "FPCCDSiliconTracking_MarlinTrk::FinalRefit: Cannot fit less than 3 hits. Number of hits = " << trkHits.size() << std::endl; - continue ; + if (trkHits.size() < 3) { + streamlog_out(DEBUG3) + << "FPCCDSiliconTracking_MarlinTrk::FinalRefit: Cannot fit less than 3 hits. Number of hits = " + << trkHits.size() << std::endl; + continue; } - TrackImpl* Track = new TrackImpl ; + TrackImpl* Track = new TrackImpl; // setup initial dummy covariance matrix EVENT::FloatVec covMatrix; covMatrix.resize(15); - for (unsigned icov = 0; icov > r2_values; + std::vector> r2_values; r2_values.reserve(trkHits.size()); - for (TrackerHitVec::iterator it=trkHits.begin(); it!=trkHits.end(); ++it) { + for (TrackerHitVec::iterator it = trkHits.begin(); it != trkHits.end(); ++it) { EVENT::TrackerHit* h = *it; - float r2 = h->getPosition()[0]*h->getPosition()[0]+h->getPosition()[1]*h->getPosition()[1]; + float r2 = h->getPosition()[0] * h->getPosition()[0] + h->getPosition()[1] * h->getPosition()[1]; r2_values.push_back(std::make_pair(r2, *it)); } - sort(r2_values.begin(),r2_values.end()); + sort(r2_values.begin(), r2_values.end()); trkHits.clear(); trkHits.reserve(r2_values.size()); - for (std::vector< std::pair >::iterator it=r2_values.begin(); it!=r2_values.end(); ++it) { + for (std::vector>::iterator it = r2_values.begin(); it != r2_values.end(); + ++it) { trkHits.push_back(it->second); } @@ -3492,48 +3358,43 @@ void FPCCDSiliconTracking_MarlinTrk::FinalRefit(LCCollectionVec* trk_col, LCColl // std::cout << " trk hit " << *trkHits[ihit_indx] << std::endl; // } - bool fit_backwards = IMarlinTrack::backward; MarlinTrk::IMarlinTrack* marlinTrk = _trksystem->createTrack(); - int error = 0; try { - error = MarlinTrk::createFinalisedLCIOTrack(marlinTrk, trkHits, Track, fit_backwards, covMatrix, _bField, _maxChi2PerHit); + error = MarlinTrk::createFinalisedLCIOTrack(marlinTrk, trkHits, Track, fit_backwards, covMatrix, _bField, + _maxChi2PerHit); } catch (...) { // delete Track; // delete marlinTrk; - throw ; - + throw; } - - - - std::vector > hits_in_fit ; - std::vector > outliers ; - std::vector all_hits; + std::vector> hits_in_fit; + std::vector> outliers; + std::vector all_hits; all_hits.reserve(300); marlinTrk->getHitsInFit(hits_in_fit); - for ( unsigned ihit = 0; ihit < hits_in_fit.size(); ++ihit) { + for (unsigned ihit = 0; ihit < hits_in_fit.size(); ++ihit) { all_hits.push_back(hits_in_fit[ihit].first); } - UTIL::BitField64 cellID_encoder( lcio::LCTrackerCellID::encoding_string() ) ; + UTIL::BitField64 cellID_encoder(lcio::LCTrackerCellID::encoding_string()); MarlinTrk::addHitNumbersToTrack(Track, all_hits, true, cellID_encoder); marlinTrk->getOutliers(outliers); - for ( unsigned ihit = 0; ihit < outliers.size(); ++ihit) { + for (unsigned ihit = 0; ihit < outliers.size(); ++ihit) { all_hits.push_back(outliers[ihit].first); } @@ -3541,49 +3402,47 @@ void FPCCDSiliconTracking_MarlinTrk::FinalRefit(LCCollectionVec* trk_col, LCColl delete marlinTrk; + int nhits_in_vxd = Track->subdetectorHitNumbers()[2 * lcio::ILDDetID::VXD - 2]; + int nhits_in_ftd = Track->subdetectorHitNumbers()[2 * lcio::ILDDetID::FTD - 2]; + int nhits_in_sit = Track->subdetectorHitNumbers()[2 * lcio::ILDDetID::SIT - 2]; - int nhits_in_vxd = Track->subdetectorHitNumbers()[ 2 * lcio::ILDDetID::VXD - 2 ]; - int nhits_in_ftd = Track->subdetectorHitNumbers()[ 2 * lcio::ILDDetID::FTD - 2 ]; - int nhits_in_sit = Track->subdetectorHitNumbers()[ 2 * lcio::ILDDetID::SIT - 2 ]; + streamlog_out(DEBUG2) << " Hit numbers for Track " << Track->id() << ": " + << " vxd hits = " << nhits_in_vxd << " ftd hits = " << nhits_in_ftd + << " sit hits = " << nhits_in_sit << std::endl; - streamlog_out( DEBUG2 ) << " Hit numbers for Track "<< Track->id() << ": " - << " vxd hits = " << nhits_in_vxd - << " ftd hits = " << nhits_in_ftd - << " sit hits = " << nhits_in_sit - << std::endl; + if (nhits_in_vxd > 0) + Track->setTypeBit(lcio::ILDDetID::VXD); + if (nhits_in_ftd > 0) + Track->setTypeBit(lcio::ILDDetID::FTD); + if (nhits_in_sit > 0) + Track->setTypeBit(lcio::ILDDetID::SIT); - if (nhits_in_vxd > 0) Track->setTypeBit( lcio::ILDDetID::VXD ) ; - if (nhits_in_ftd > 0) Track->setTypeBit( lcio::ILDDetID::FTD ) ; - if (nhits_in_sit > 0) Track->setTypeBit( lcio::ILDDetID::SIT ) ; - - - - if( error != IMarlinTrack::success ) { + if (error != IMarlinTrack::success) { delete Track; - streamlog_out(DEBUG3) << "FPCCDSiliconTracking_MarlinTrk::FinalRefit: Track fit failed with error code " << error << " track dropped. Number of hits = "<< trkHits.size() << std::endl; - continue ; + streamlog_out(DEBUG3) << "FPCCDSiliconTracking_MarlinTrk::FinalRefit: Track fit failed with error code " + << error << " track dropped. Number of hits = " << trkHits.size() << std::endl; + continue; } - if( Track->getNdf() <= 0) { + if (Track->getNdf() <= 0) { delete Track; - streamlog_out(DEBUG3) << "FPCCDSiliconTracking_MarlinTrk::FinalRefit: Track fit returns " << Track->getNdf() << " degress of freedom track dropped. Number of hits = "<< trkHits.size() << std::endl; - continue ; + streamlog_out(DEBUG3) << "FPCCDSiliconTracking_MarlinTrk::FinalRefit: Track fit returns " << Track->getNdf() + << " degress of freedom track dropped. Number of hits = " << trkHits.size() << std::endl; + continue; } - - const TrackState* trkStateIP = Track->getTrackState(lcio::TrackState::AtIP); if (trkStateIP == 0) { - streamlog_out(DEBUG3) << "FPCCDSiliconTracking_MarlinTrk::FinalRefit: Track fit returns " << Track->getNdf() << " degress of freedom track dropped. Number of hits = "<< trkHits.size() << std::endl; - throw EVENT::Exception( std::string("FPCCDSiliconTracking_MarlinTrk::FinalRefit: trkStateIP pointer == NULL ") ) ; + streamlog_out(DEBUG3) << "FPCCDSiliconTracking_MarlinTrk::FinalRefit: Track fit returns " << Track->getNdf() + << " degress of freedom track dropped. Number of hits = " << trkHits.size() << std::endl; + throw EVENT::Exception(std::string("FPCCDSiliconTracking_MarlinTrk::FinalRefit: trkStateIP pointer == NULL ")); delete Track; - continue ; + continue; } - - trk_col->addElement(Track); + trk_col->addElement(Track); // note trackAR which is of type TrackExtended, only takes fits set for ref point = 0,0,0 trackAR->setOmega(trkStateIP->getOmega()); @@ -3594,7 +3453,7 @@ void FPCCDSiliconTracking_MarlinTrk::FinalRefit(LCCollectionVec* trk_col, LCColl float cov[15]; - for (int i = 0 ; i<15 ; ++i) { + for (int i = 0; i < 15; ++i) { cov[i] = trkStateIP->getCovMatrix().operator[](i); } @@ -3606,121 +3465,96 @@ void FPCCDSiliconTracking_MarlinTrk::FinalRefit(LCCollectionVec* trk_col, LCColl HelixClass_double helix_final; - helix_final.Initialize_Canonical(trkStateIP->getPhi(),trkStateIP->getD0(),trkStateIP->getZ0(),trkStateIP->getOmega(),trkStateIP->getTanLambda(),_bField); + helix_final.Initialize_Canonical(trkStateIP->getPhi(), trkStateIP->getD0(), trkStateIP->getZ0(), + trkStateIP->getOmega(), trkStateIP->getTanLambda(), _bField); double trkPx = helix_final.getMomentum()[0]; double trkPy = helix_final.getMomentum()[1]; double trkPz = helix_final.getMomentum()[2]; - double trkP = sqrt(trkPx*trkPx+trkPy*trkPy+trkPz*trkPz); + double trkP = sqrt(trkPx * trkPx + trkPy * trkPy + trkPz * trkPz); eTot += trkP; pxTot += trkPx; pyTot += trkPy; pzTot += trkPz; - - - - } } - streamlog_out(DEBUG4) << "FPCCDSiliconTracking_MarlinTrk -> run " << _nRun - << " event " << _nEvt << std::endl; + streamlog_out(DEBUG4) << "FPCCDSiliconTracking_MarlinTrk -> run " << _nRun << " event " << _nEvt << std::endl; streamlog_out(DEBUG4) << "Number of Si tracks = " << nSiSegments << std::endl; - streamlog_out(DEBUG4) << "Total 4-momentum of Si tracks : E = " << eTot - << " Px = " << pxTot - << " Py = " << pyTot - << " Pz = " << pzTot << std::endl; - - + streamlog_out(DEBUG4) << "Total 4-momentum of Si tracks : E = " << eTot << " Px = " << pxTot << " Py = " << pyTot + << " Pz = " << pzTot << std::endl; } +void FPCCDSiliconTracking_MarlinTrk::setupGeom(const dd4hep::Detector& theDetector) { -void FPCCDSiliconTracking_MarlinTrk::setupGeom( const dd4hep::Detector& theDetector ){ + double bFieldVec[3]; + theDetector.field().magneticField({0, 0, 0}, bFieldVec); // get the magnetic field vector from DD4hep + _bField = bFieldVec[2] / dd4hep::tesla; // z component at (0,0,0) - double bFieldVec[3]; - theDetector.field().magneticField({0,0,0},bFieldVec); // get the magnetic field vector from DD4hep - _bField = bFieldVec[2]/dd4hep::tesla; // z component at (0,0,0) - - //-- VXD Parameters-- - _nLayersVTX = 0 ; - - try{ - - streamlog_out( DEBUG9 ) << " filling VXD parameters " << std::endl ; - + _nLayersVTX = 0; + + try { + + streamlog_out(DEBUG9) << " filling VXD parameters " << std::endl; + dd4hep::DetElement vtxDE = theDetector.detector("VXD"); dd4hep::rec::ZPlanarData* vtx = vtxDE.extension(); - _nLayersVTX=vtx->layers.size(); - - } - catch( std::runtime_error& e){ - - streamlog_out( DEBUG9 ) << " ### VXD detector Not Present in Detector" << std::endl ; + _nLayersVTX = vtx->layers.size(); + + } catch (std::runtime_error& e) { + + streamlog_out(DEBUG9) << " ### VXD detector Not Present in Detector" << std::endl; } - - //-- SIT Parameters-- - _nLayersSIT = 0 ; + _nLayersSIT = 0; - try{ + try { - streamlog_out( DEBUG9 ) << " filling SIT parameters " << std::endl ; + streamlog_out(DEBUG9) << " filling SIT parameters " << std::endl; dd4hep::DetElement sitDE = theDetector.detector("SIT"); dd4hep::rec::ZPlanarData* sit = sitDE.extension(); - _nLayersSIT=sit->layers.size(); - } - catch( std::runtime_error& e){ - - streamlog_out( DEBUG9 ) << " ### SIT detector Not Present in Detector " << std::endl ; + _nLayersSIT = sit->layers.size(); + } catch (std::runtime_error& e) { + streamlog_out(DEBUG9) << " ### SIT detector Not Present in Detector " << std::endl; } - //-- FTD Parameters-- - _petalBasedFTDWithOverlaps = false; + _petalBasedFTDWithOverlaps = false; _nlayersFTD = 0; - try{ + try { - streamlog_out( DEBUG9 ) << " filling FTD parameters " << std::endl ; + streamlog_out(DEBUG9) << " filling FTD parameters " << std::endl; dd4hep::DetElement ftdDE = theDetector.detector("FTD"); dd4hep::rec::ZDiskPetalsData* ftd = ftdDE.extension(); _nlayersFTD = ftd->layers.size(); - for (unsigned int disk=0; disk < _nlayersFTD; ++disk) { + for (unsigned int disk = 0; disk < _nlayersFTD; ++disk) { - _zLayerFTD.push_back( ftd->layers[ disk ].zPosition + ftd->layers[ disk ].zOffsetSensitive ) ; - _zLayerFTD.push_back( ftd->layers[ disk ].zPosition - ftd->layers[ disk ].zOffsetSensitive ) ; + _zLayerFTD.push_back(ftd->layers[disk].zPosition + ftd->layers[disk].zOffsetSensitive); + _zLayerFTD.push_back(ftd->layers[disk].zPosition - ftd->layers[disk].zOffsetSensitive); _petalBasedFTDWithOverlaps = true; - } - // SJA: Here we increase the size of _nlayersFTD as we are treating the - _nlayersFTD =_zLayerFTD.size() ; - - } - catch( std::runtime_error& e){ - - streamlog_out( DEBUG9 ) << " ### FTD detector Not Present in Detector" << std::endl ; - - } + // SJA: Here we increase the size of _nlayersFTD as we are treating the + _nlayersFTD = _zLayerFTD.size(); + } catch (std::runtime_error& e) { + streamlog_out(DEBUG9) << " ### FTD detector Not Present in Detector" << std::endl; + } } -void FPCCDSiliconTracking_MarlinTrk::TracksWithNHitsContainer::clear() -{ - for (std::vector< TrackExtendedVec >::iterator trackVecIter = _tracksNHits.begin(); - trackVecIter < _tracksNHits.end(); trackVecIter++) - { - for (TrackExtendedVec::iterator trackIter = trackVecIter->begin(); - trackIter < trackVecIter->end(); trackIter++) - { +void FPCCDSiliconTracking_MarlinTrk::TracksWithNHitsContainer::clear() { + for (std::vector::iterator trackVecIter = _tracksNHits.begin(); trackVecIter < _tracksNHits.end(); + trackVecIter++) { + for (TrackExtendedVec::iterator trackIter = trackVecIter->begin(); trackIter < trackVecIter->end(); trackIter++) { delete *trackIter; } @@ -3728,170 +3562,168 @@ void FPCCDSiliconTracking_MarlinTrk::TracksWithNHitsContainer::clear() } } - - - -LCCollection* FPCCDSiliconTracking_MarlinTrk::GetCollection( LCEvent * evt, std::string colName ){ +LCCollection* FPCCDSiliconTracking_MarlinTrk::GetCollection(LCEvent* evt, std::string colName) { LCCollection* col = NULL; - try { - col = evt->getCollection( colName.c_str() ) ; - streamlog_out( DEBUG4 ) << " --> " << colName.c_str() << " collection found, number of elements = " << col->getNumberOfElements() << std::endl; - } - catch(DataNotAvailableException &e) { - streamlog_out( DEBUG4 ) << " --> " << colName.c_str() << " collection absent" << std::endl; + col = evt->getCollection(colName.c_str()); + streamlog_out(DEBUG4) << " --> " << colName.c_str() + << " collection found, number of elements = " << col->getNumberOfElements() << std::endl; + } catch (DataNotAvailableException& e) { + streamlog_out(DEBUG4) << " --> " << colName.c_str() << " collection absent" << std::endl; } - return col; - + return col; } -LCRelationNavigator* FPCCDSiliconTracking_MarlinTrk::GetRelations(LCEvent * evt , std::string RelName ) { +LCRelationNavigator* FPCCDSiliconTracking_MarlinTrk::GetRelations(LCEvent* evt, std::string RelName) { - LCRelationNavigator* nav = NULL ; + LCRelationNavigator* nav = NULL; LCCollection* col = NULL; - try{ + try { - col = evt->getCollection( RelName.c_str() ); - nav = new LCRelationNavigator( col ); - streamlog_out( DEBUG4 ) << " --> " << RelName << " track relation collection found, number of elements = " << col->getNumberOfElements() << std::endl; - } - catch(DataNotAvailableException &e){ - streamlog_out( ERROR ) << " --> " << RelName.c_str() << " track relation collection absent" << std::endl; + col = evt->getCollection(RelName.c_str()); + nav = new LCRelationNavigator(col); + streamlog_out(DEBUG4) << " --> " << RelName + << " track relation collection found, number of elements = " << col->getNumberOfElements() + << std::endl; + } catch (DataNotAvailableException& e) { + streamlog_out(ERROR) << " --> " << RelName.c_str() << " track relation collection absent" << std::endl; } return nav; - } - - -void FPCCDSiliconTracking_MarlinTrk::InitVXDGeometry(const dd4hep::Detector& theDetector){ +void FPCCDSiliconTracking_MarlinTrk::InitVXDGeometry(const dd4hep::Detector& theDetector) { // Save frequently used parameters. dd4hep::DetElement vtxDE = theDetector.detector("VXD"); dd4hep::rec::ZPlanarData* vtx = vtxDE.extension(); - - _vxd.nLayer = vtx->layers.size(); + + _vxd.nLayer = vtx->layers.size(); _vxd.geodata.resize(_vxd.nLayer); _vxd.maxLadder = 0; - for(int ly=0;ly < _vxd.nLayer; ly++){ + for (int ly = 0; ly < _vxd.nLayer; ly++) { - const dd4hep::rec::ZPlanarData::LayerLayout layerVXD = vtx->layers[ly] ; + const dd4hep::rec::ZPlanarData::LayerLayout layerVXD = vtx->layers[ly]; - _vxd.geodata[ly].nladder = layerVXD.ladderNumber ; // Number of ladders in this layer - if( _vxd.maxLadder < _vxd.geodata[ly].nladder ) { _vxd.maxLadder = _vxd.geodata[ly].nladder; } + _vxd.geodata[ly].nladder = layerVXD.ladderNumber; // Number of ladders in this layer + if (_vxd.maxLadder < _vxd.geodata[ly].nladder) { + _vxd.maxLadder = _vxd.geodata[ly].nladder; + } _vxd.geodata[ly].rmin = layerVXD.distanceSensitive; // Distance of sensitive area from IP - _vxd.geodata[ly].dphi = (2*M_PI)/(double)_vxd.geodata[ly].nladder; - _vxd.geodata[ly].phi0 = layerVXD.phi0; // phi offset. + _vxd.geodata[ly].dphi = (2 * M_PI) / (double)_vxd.geodata[ly].nladder; + _vxd.geodata[ly].phi0 = layerVXD.phi0; // phi offset. _vxd.geodata[ly].sthick = layerVXD.thicknessSensitive; - _vxd.geodata[ly].sximin = -layerVXD.offsetSensitive - layerVXD.widthSensitive/2.0; - _vxd.geodata[ly].sximax = -layerVXD.offsetSensitive + layerVXD.widthSensitive/2.0; - //CAUTION: plus direction of xi-axis in ld = 0, ly = 0 is equal to minus direction of global x-axis and longer than minus direction of xi-axis. - _vxd.geodata[ly].hlength = layerVXD.zHalfSensitive ; - _vxd.geodata[ly].cosphi.resize( _vxd.geodata[ly].nladder ) ; - _vxd.geodata[ly].sinphi.resize( _vxd.geodata[ly].nladder ) ; - _vxd.geodata[ly].phi.resize( _vxd.geodata[ly].nladder ) ; - _vxd.geodata[ly].phiAtXiMin.resize( _vxd.geodata[ly].nladder ) ; - _vxd.geodata[ly].phiAtXiMax.resize( _vxd.geodata[ly].nladder ) ; - _vxd.geodata[ly].ladder_incline.resize( _vxd.geodata[ly].nladder ) ; - _vxd.geodata[ly].num_xi_pixel = (int)(layerVXD.widthSensitive/_pixelSizeVec[ly]); - _vxd.geodata[ly].num_zeta_pixel = (int)(2*layerVXD.zHalfSensitive/_pixelSizeVec[ly]); - - if(ly % 2 == 0){ _vxd.geodata[ly].rmes = _vxd.geodata[ly].rmin + _vxd.geodata[ly].sthick*(15.0/50.0)*0.5; } - else{ _vxd.geodata[ly].rmes = _vxd.geodata[ly].rmin + _vxd.geodata[ly].sthick*(1.0 - (15.0/50.0)*0.5); } - - for(int ld=0;ld<_vxd.geodata[ly].nladder;ld++) { - double phi = _vxd.geodata[ly].phi0 + _vxd.geodata[ly].dphi*ld; + _vxd.geodata[ly].sximin = -layerVXD.offsetSensitive - layerVXD.widthSensitive / 2.0; + _vxd.geodata[ly].sximax = -layerVXD.offsetSensitive + layerVXD.widthSensitive / 2.0; + // CAUTION: plus direction of xi-axis in ld = 0, ly = 0 is equal to minus direction of global x-axis and longer than + // minus direction of xi-axis. + _vxd.geodata[ly].hlength = layerVXD.zHalfSensitive; + _vxd.geodata[ly].cosphi.resize(_vxd.geodata[ly].nladder); + _vxd.geodata[ly].sinphi.resize(_vxd.geodata[ly].nladder); + _vxd.geodata[ly].phi.resize(_vxd.geodata[ly].nladder); + _vxd.geodata[ly].phiAtXiMin.resize(_vxd.geodata[ly].nladder); + _vxd.geodata[ly].phiAtXiMax.resize(_vxd.geodata[ly].nladder); + _vxd.geodata[ly].ladder_incline.resize(_vxd.geodata[ly].nladder); + _vxd.geodata[ly].num_xi_pixel = (int)(layerVXD.widthSensitive / _pixelSizeVec[ly]); + _vxd.geodata[ly].num_zeta_pixel = (int)(2 * layerVXD.zHalfSensitive / _pixelSizeVec[ly]); + + if (ly % 2 == 0) { + _vxd.geodata[ly].rmes = _vxd.geodata[ly].rmin + _vxd.geodata[ly].sthick * (15.0 / 50.0) * 0.5; + } else { + _vxd.geodata[ly].rmes = _vxd.geodata[ly].rmin + _vxd.geodata[ly].sthick * (1.0 - (15.0 / 50.0) * 0.5); + } + + for (int ld = 0; ld < _vxd.geodata[ly].nladder; ld++) { + double phi = _vxd.geodata[ly].phi0 + _vxd.geodata[ly].dphi * ld; _vxd.geodata[ly].cosphi[ld] = cos(phi); _vxd.geodata[ly].sinphi[ld] = sin(phi); _vxd.geodata[ly].phi[ld] = phi; - double incline = phi - (M_PI/2.0); - while( incline > 1.0*M_PI || incline < -1.0*M_PI ){ incline > 1.0*M_PI ? incline -= 2.0*M_PI : incline += 2.0*M_PI ;} - _vxd.geodata[ly].ladder_incline[ld] = incline; //this expresses the tilt of the ladder by phi. - //I adjusted the range between [-180deg, 180deg] - - - _vxd.geodata[ly].phiAtXiMin[ld] = _vxd.geodata[ly].phi[ld] + atan2(-_vxd.geodata[ly].sximin, _vxd.geodata[ly].rmes); - _vxd.geodata[ly].phiAtXiMax[ld] = _vxd.geodata[ly].phi[ld] - atan2( _vxd.geodata[ly].sximax, _vxd.geodata[ly].rmes); + double incline = phi - (M_PI / 2.0); + while (incline > 1.0 * M_PI || incline < -1.0 * M_PI) { + incline > 1.0 * M_PI ? incline -= 2.0 * M_PI : incline += 2.0 * M_PI; + } + _vxd.geodata[ly].ladder_incline[ld] = incline; // this expresses the tilt of the ladder by phi. + // I adjusted the range between [-180deg, 180deg] + _vxd.geodata[ly].phiAtXiMin[ld] = + _vxd.geodata[ly].phi[ld] + atan2(-_vxd.geodata[ly].sximin, _vxd.geodata[ly].rmes); + _vxd.geodata[ly].phiAtXiMax[ld] = + _vxd.geodata[ly].phi[ld] - atan2(_vxd.geodata[ly].sximax, _vxd.geodata[ly].rmes); } - } -} +} -void FPCCDSiliconTracking_MarlinTrk::InitSITGeometry(const dd4hep::Detector& theDetector){ +void FPCCDSiliconTracking_MarlinTrk::InitSITGeometry(const dd4hep::Detector& theDetector) { // Save frequently used parameters. dd4hep::DetElement sitDE = theDetector.detector("SIT"); dd4hep::rec::ZPlanarData* sit = sitDE.extension(); - - _sit.nLayer = sit->layers.size(); + _sit.nLayer = sit->layers.size(); _sit.geodata.resize(_sit.nLayer); _sit.maxLadder = 0; - for(int ly=0;ly < _sit.nLayer; ly++){ + for (int ly = 0; ly < _sit.nLayer; ly++) { - const dd4hep::rec::ZPlanarData::LayerLayout layerSIT = sit->layers[ly] ; + const dd4hep::rec::ZPlanarData::LayerLayout layerSIT = sit->layers[ly]; - _sit.geodata[ly].nladder = layerSIT.ladderNumber; // Number of ladders in this layer - if( _sit.maxLadder < _sit.geodata[ly].nladder ) { _sit.maxLadder = _sit.geodata[ly].nladder; } + _sit.geodata[ly].nladder = layerSIT.ladderNumber; // Number of ladders in this layer + if (_sit.maxLadder < _sit.geodata[ly].nladder) { + _sit.maxLadder = _sit.geodata[ly].nladder; + } _sit.geodata[ly].rmin = layerSIT.distanceSensitive; // Distance of sensitive area from IP - _sit.geodata[ly].phi0 = layerSIT.phi0; // phi offset. + _sit.geodata[ly].phi0 = layerSIT.phi0; // phi offset. _sit.geodata[ly].hlength = layerSIT.zHalfSensitive; - _sit.geodata[ly].cosphi.resize( _sit.geodata[ly].nladder ) ; - _sit.geodata[ly].sinphi.resize( _sit.geodata[ly].nladder ) ; - _sit.geodata[ly].phi.resize( _sit.geodata[ly].nladder ) ; - _sit.geodata[ly].phiAtXiMin.resize( _sit.geodata[ly].nladder ) ; - _sit.geodata[ly].phiAtXiMax.resize( _sit.geodata[ly].nladder ) ; - _sit.geodata[ly].ladder_incline.resize( _sit.geodata[ly].nladder ) ; - - for(int ld=0;ld<_sit.geodata[ly].nladder;ld++) { - double phi = _sit.geodata[ly].phi0 + _sit.geodata[ly].dphi*ld; + _sit.geodata[ly].cosphi.resize(_sit.geodata[ly].nladder); + _sit.geodata[ly].sinphi.resize(_sit.geodata[ly].nladder); + _sit.geodata[ly].phi.resize(_sit.geodata[ly].nladder); + _sit.geodata[ly].phiAtXiMin.resize(_sit.geodata[ly].nladder); + _sit.geodata[ly].phiAtXiMax.resize(_sit.geodata[ly].nladder); + _sit.geodata[ly].ladder_incline.resize(_sit.geodata[ly].nladder); + + for (int ld = 0; ld < _sit.geodata[ly].nladder; ld++) { + double phi = _sit.geodata[ly].phi0 + _sit.geodata[ly].dphi * ld; _sit.geodata[ly].cosphi[ld] = cos(phi); _sit.geodata[ly].sinphi[ld] = sin(phi); _sit.geodata[ly].phi[ld] = phi; - double incline = phi - (M_PI/2.0); - while( incline > 1.0*M_PI || incline < -1.0*M_PI ){ - incline += (incline > 1.0*M_PI) ? -2.0*M_PI : 2.0*M_PI ; + double incline = phi - (M_PI / 2.0); + while (incline > 1.0 * M_PI || incline < -1.0 * M_PI) { + incline += (incline > 1.0 * M_PI) ? -2.0 * M_PI : 2.0 * M_PI; } - _sit.geodata[ly].ladder_incline[ld] = incline; - + _sit.geodata[ly].ladder_incline[ld] = incline; } - } -} - - - - +} -int FPCCDSiliconTracking_MarlinTrk::KalFit(int& ndf, float& Chi2, TrackerHitVec trkHits,TrackerHitVec& Hits_in_fit, TrackerHitVec& Outliers, float* par , float* epar, HelixClass_double& helix){ +int FPCCDSiliconTracking_MarlinTrk::KalFit(int& ndf, float& Chi2, TrackerHitVec trkHits, TrackerHitVec& Hits_in_fit, + TrackerHitVec& Outliers, float* par, float* epar, HelixClass_double& helix) { TrackImpl* Track = new TrackImpl; EVENT::FloatVec covMatrix; covMatrix.resize(15); - covMatrix[0] = ( _initialTrackError_d0 ); //sigma_d0^2 - covMatrix[2] = ( _initialTrackError_phi0 ); //sigma_phi0^2 - covMatrix[5] = ( _initialTrackError_omega ); //sigma_omega^2 - covMatrix[9] = ( _initialTrackError_z0 ); //sigma_z0^2 - covMatrix[14] = ( _initialTrackError_tanL ); //sigma_tanl^2 + covMatrix[0] = (_initialTrackError_d0); // sigma_d0^2 + covMatrix[2] = (_initialTrackError_phi0); // sigma_phi0^2 + covMatrix[5] = (_initialTrackError_omega); // sigma_omega^2 + covMatrix[9] = (_initialTrackError_z0); // sigma_z0^2 + covMatrix[14] = (_initialTrackError_tanL); // sigma_tanl^2 bool fit_backwards = IMarlinTrack::backward; MarlinTrk::IMarlinTrack* marlinTrk = _trksystem->createTrack(); int error = 0; - error = MarlinTrk::createFinalisedLCIOTrack(marlinTrk, trkHits, Track, fit_backwards, covMatrix, _bField, _maxChi2PerHit2nd); - if(error != 0){ - if(_mydebugKalFit) std::cout << "KalFit error code : " << error << std::endl; + error = MarlinTrk::createFinalisedLCIOTrack(marlinTrk, trkHits, Track, fit_backwards, covMatrix, _bField, + _maxChi2PerHit2nd); + if (error != 0) { + if (_mydebugKalFit) + std::cout << "KalFit error code : " << error << std::endl; delete Track; delete marlinTrk; return error; @@ -3907,24 +3739,27 @@ int FPCCDSiliconTracking_MarlinTrk::KalFit(int& ndf, float& Chi2, TrackerHitVec } ndf = Track->getNdf(); - if(std::isnormal(ndf) == false || ndf <= 0){ - if(_mydebugKalFit)std::cout << "ERROR = 8!! ndf is " << ndf << " at KalFit" << std::endl; - delete Track; + if (std::isnormal(ndf) == false || ndf <= 0) { + if (_mydebugKalFit) + std::cout << "ERROR = 8!! ndf is " << ndf << " at KalFit" << std::endl; + delete Track; delete marlinTrk; return 8; } Chi2 = Track->getChi2(); - if(std::isnormal(Chi2) == false || Chi2 < 0.0 ){ - if(_mydebugKalFit)std::cout << "ERROR = 9!! Chi2 is " << Chi2 << " at KalFit" << std::endl; - delete Track; + if (std::isnormal(Chi2) == false || Chi2 < 0.0) { + if (_mydebugKalFit) + std::cout << "ERROR = 9!! Chi2 is " << Chi2 << " at KalFit" << std::endl; + delete Track; delete marlinTrk; return 9; } const TrackState* trkStateIP = Track->getTrackState(lcio::TrackState::AtIP); if (trkStateIP == 0) { - if(_mydebugKalFit)std::cout << "ERROR = 2!! trkStateIP is NULL! : KalFit" << std::endl; + if (_mydebugKalFit) + std::cout << "ERROR = 2!! trkStateIP is NULL! : KalFit" << std::endl; delete Track; delete marlinTrk; return 2; @@ -3935,10 +3770,12 @@ int FPCCDSiliconTracking_MarlinTrk::KalFit(int& ndf, float& Chi2, TrackerHitVec par[3] = trkStateIP->getZ0(); par[4] = trkStateIP->getTanLambda(); - if(std::isnormal(par[0]) == false || std::isnormal(par[1]) == false || std::isnormal(par[2]) == false || std::isnormal(par[3]) == false || std::isnormal(par[4]) == false){ - if(_mydebugKalFit){ + if (std::isnormal(par[0]) == false || std::isnormal(par[1]) == false || std::isnormal(par[2]) == false || + std::isnormal(par[3]) == false || std::isnormal(par[4]) == false) { + if (_mydebugKalFit) { std::cout << "ERROR = 10!! Some of track parameters output from Kalman Filter are nan or inf. " << std::endl; - std::cout << "d0,phi0,omega,z0,tanlambda : " <getCovMatrix(); - for(int i = 0 ; i < 15; i++) epar[i] = covM[i]; - helix.Initialize_Canonical(par[1],par[0],par[3],par[2],par[4],_bField); + for (int i = 0; i < 15; i++) + epar[i] = covM[i]; + helix.Initialize_Canonical(par[1], par[0], par[3], par[2], par[4], _bField); - - std::vector > hits_in_fit ; - std::vector > outliers ; + std::vector> hits_in_fit; + std::vector> outliers; marlinTrk->getHitsInFit(hits_in_fit); Hits_in_fit.clear(); Hits_in_fit.reserve(hits_in_fit.size()); - for ( unsigned ihit = 0; ihit < hits_in_fit.size(); ++ihit) { Hits_in_fit.push_back(hits_in_fit[ihit].first); } + for (unsigned ihit = 0; ihit < hits_in_fit.size(); ++ihit) { + Hits_in_fit.push_back(hits_in_fit[ihit].first); + } marlinTrk->getOutliers(outliers); - if(_mydebugKalFit){ + if (_mydebugKalFit) { std::cout << "outliers.size() : " << outliers.size() << std::endl; - for(int i = 0; i < int(outliers.size()); i++){ - std::cout << outliers[i].first << std::endl; + for (int i = 0; i < int(outliers.size()); i++) { + std::cout << outliers[i].first << std::endl; } } Outliers.clear(); Outliers.reserve(outliers.size()); - for ( unsigned ihit = 0; ihit < outliers.size(); ++ihit) {Outliers.push_back(outliers[ihit].first); } - + for (unsigned ihit = 0; ihit < outliers.size(); ++ihit) { + Outliers.push_back(outliers[ihit].first); + } delete Track; delete marlinTrk; - return error; //0 - + return error; // 0 } - -float FPCCDSiliconTracking_MarlinTrk::DotOf2Clusters(TrackerHit* A, TrackerHit* B){ +float FPCCDSiliconTracking_MarlinTrk::DotOf2Clusters(TrackerHit* A, TrackerHit* B) { ClusterStatus ca(A); ClusterStatus cb(B); @@ -4000,27 +3838,29 @@ float FPCCDSiliconTracking_MarlinTrk::DotOf2Clusters(TrackerHit* A, TrackerHit* std::cout << "zetawidth : " << cb.zetawidth << std::endl; std::cout << "nPix : " << cb.nPix << std::endl; std::cout << "tilt : " << cb.tilt << std::endl; -#endif - +#endif double signA = 1; - if(ca.tilt>1) signA = -1; + if (ca.tilt > 1) + signA = -1; double signB = 1; - if(cb.tilt>1) signB = -1; - TVector3 ldirA(_pixelSizeVec[ca.layer]*(ca.xiwidth-1),signA*_pixelSizeVec[ca.layer]*(ca.zetawidth-1),_pixelheight); - TVector3 revldirA(-ldirA.X(),-ldirA.Y(),ldirA.Z()); - TVector3 ldirB(_pixelSizeVec[cb.layer]*(cb.xiwidth-1),signB*_pixelSizeVec[cb.layer]*(cb.zetawidth-1),_pixelheight); - TVector3 gdirA = LocalToGlobal(ldirA,ca.layer,ca.ladder); - TVector3 revgdirA = LocalToGlobal(revldirA,ca.layer,ca.ladder); - TVector3 gdirB = LocalToGlobal(ldirB,cb.layer,cb.ladder); - float dot1 = ( revgdirA.Unit().Dot(gdirB.Unit()) > gdirA.Unit().Dot(gdirB.Unit()) ) ? revgdirA.Unit().Dot(gdirB.Unit()) : gdirA.Unit().Dot(gdirB.Unit()); + if (cb.tilt > 1) + signB = -1; + TVector3 ldirA(_pixelSizeVec[ca.layer] * (ca.xiwidth - 1), signA * _pixelSizeVec[ca.layer] * (ca.zetawidth - 1), + _pixelheight); + TVector3 revldirA(-ldirA.X(), -ldirA.Y(), ldirA.Z()); + TVector3 ldirB(_pixelSizeVec[cb.layer] * (cb.xiwidth - 1), signB * _pixelSizeVec[cb.layer] * (cb.zetawidth - 1), + _pixelheight); + TVector3 gdirA = LocalToGlobal(ldirA, ca.layer, ca.ladder); + TVector3 revgdirA = LocalToGlobal(revldirA, ca.layer, ca.ladder); + TVector3 gdirB = LocalToGlobal(ldirB, cb.layer, cb.ladder); + float dot1 = (revgdirA.Unit().Dot(gdirB.Unit()) > gdirA.Unit().Dot(gdirB.Unit())) ? revgdirA.Unit().Dot(gdirB.Unit()) + : gdirA.Unit().Dot(gdirB.Unit()); return dot1; - } - -TVector3 FPCCDSiliconTracking_MarlinTrk::LocalToGlobal(TVector3 local,int layer,int ladder){ +TVector3 FPCCDSiliconTracking_MarlinTrk::LocalToGlobal(TVector3 local, int layer, int ladder) { #if 0 std::cout << "========CHECK LocalToGlobal===========" << std::endl; std::cout << "check. x " << local.X() << std::endl; @@ -4032,37 +3872,32 @@ TVector3 FPCCDSiliconTracking_MarlinTrk::LocalToGlobal(TVector3 local,int layer, std::cout << "hlength = " << _vxd.geodata[layer].hlength << std::endl << std::endl; #endif + TVector3 gdir(local.X() * _vxd.geodata[layer].sinphi[ladder] + local.Z() * _vxd.geodata[layer].cosphi[ladder], + -local.X() * _vxd.geodata[layer].cosphi[ladder] + local.Z() * _vxd.geodata[layer].sinphi[ladder], + local.Y()); + return gdir; +} - TVector3 gdir( - local.X()*_vxd.geodata[layer].sinphi[ladder] + local.Z()*_vxd.geodata[layer].cosphi[ladder] , - -local.X()*_vxd.geodata[layer].cosphi[ladder] + local.Z()*_vxd.geodata[layer].sinphi[ladder] , - local.Y() - ); - return gdir ; -} - - -void FPCCDSiliconTracking_MarlinTrk::calcTrackParameterOfMCP(MCParticle* pmcp, double* par){ +void FPCCDSiliconTracking_MarlinTrk::calcTrackParameterOfMCP(MCParticle* pmcp, double* par) { - HelixTrack helixMC( pmcp->getVertex(), pmcp->getMomentum(), pmcp->getCharge(), _bField ) ; + HelixTrack helixMC(pmcp->getVertex(), pmcp->getMomentum(), pmcp->getCharge(), _bField); double oldphi0 = double(helixMC.getPhi0()); double omega = double(helixMC.getOmega()); double tanL = double(helixMC.getTanLambda()); double oldsinphi0 = std::sin(oldphi0); double oldcosphi0 = std::cos(oldphi0); - double centx = pmcp->getVertex()[0] + 1/omega * oldcosphi0; - double centy = pmcp->getVertex()[1] + 1/omega * oldsinphi0; + double centx = pmcp->getVertex()[0] + 1 / omega * oldcosphi0; + double centy = pmcp->getVertex()[1] + 1 / omega * oldsinphi0; double newphi0; - if(omega > 0){ - newphi0 = std::atan2(centy,centx); - } - else{ - newphi0 = std::atan2(-centy,-centx); + if (omega > 0) { + newphi0 = std::atan2(centy, centx); + } else { + newphi0 = std::atan2(-centy, -centx); } double sinphi0 = std::sin(newphi0); double cosphi0 = std::cos(newphi0); - double d0 = centx * cosphi0 + centy * sinphi0 - 1.0/omega ; - double z0 = pmcp->getVertex()[2] - 1.0/omega *(newphi0 - oldphi0)*tanL; + double d0 = centx * cosphi0 + centy * sinphi0 - 1.0 / omega; + double z0 = pmcp->getVertex()[2] - 1.0 / omega * (newphi0 - oldphi0) * tanL; #if 0 std::cout << "Test Pivot Transformation " << std::endl; @@ -4071,19 +3906,17 @@ void FPCCDSiliconTracking_MarlinTrk::calcTrackParameterOfMCP(MCParticle* pmcp, d std::cout << "omega : " << omega << std::endl; std::cout << "phi0 : " << newphi0 << std::endl; std::cout << "tanL : " << tanL << std::endl; -#endif +#endif par[0] = d0; par[1] = z0; par[2] = omega; par[3] = newphi0; par[4] = tanL; - } - -int FPCCDSiliconTracking_MarlinTrk::CheckTiltOf2Clusters(TrackerHit* A, TrackerHit* B, int /*level*/){ - //level is set for the future where users choose the level of requirement hardness. - //For now, this level is not alive. +int FPCCDSiliconTracking_MarlinTrk::CheckTiltOf2Clusters(TrackerHit* A, TrackerHit* B, int /*level*/) { + // level is set for the future where users choose the level of requirement hardness. + // For now, this level is not alive. ClusterStatus ca(A); ClusterStatus cb(B); @@ -4099,118 +3932,129 @@ int FPCCDSiliconTracking_MarlinTrk::CheckTiltOf2Clusters(TrackerHit* A, TrackerH std::cout << "zetawidth : " << cb.zetawidth << std::endl; std::cout << "nPix : " << cb.nPix << std::endl; std::cout << "tilt : " << cb.tilt << std::endl; -#endif +#endif - //tilt check. - //tilt : 0 --> straight line shape - //tilt : 1 --> zig-zag line going from left bottom to right top - //tilt : 2 --> zig-zag line going from right bottom to left top - //tilt : 3 --> the others shape + // tilt check. + // tilt : 0 --> straight line shape + // tilt : 1 --> zig-zag line going from left bottom to right top + // tilt : 2 --> zig-zag line going from right bottom to left top + // tilt : 3 --> the others shape - int status = 0; - if( (ca.tilt == 1 && cb.tilt == 2) || (ca.tilt == 2 && cb.tilt == 1) ){ + int status = 0; + if ((ca.tilt == 1 && cb.tilt == 2) || (ca.tilt == 2 && cb.tilt == 1)) { status = -1; - } - else if(ca.tilt == 1 && cb.tilt == 1){ + } else if (ca.tilt == 1 && cb.tilt == 1) { status = 1; - } - else if(ca.tilt == 2 && cb.tilt == 2){ + } else if (ca.tilt == 2 && cb.tilt == 2) { status = 2; - } - else if(ca.tilt == 0 && cb.tilt == 0){ - if(ca.nPix < 3 && cb.nPix < 3) status = 0; - else if( ca.xiwidth == cb.xiwidth || ca.zetawidth == cb.zetawidth){ + } else if (ca.tilt == 0 && cb.tilt == 0) { + if (ca.nPix < 3 && cb.nPix < 3) + status = 0; + else if (ca.xiwidth == cb.xiwidth || ca.zetawidth == cb.zetawidth) { status = 4; - } - else status = -2; + } else + status = -2; } return status; - //EXPLANATION - //status : 0 --> anything passing through all if statement. - // : 1 --> matched in tilt == 1 - // : 2 --> matched in tilt == 2 - // : 4 --> matched in tilt == 0 - // : -1 --> mismatched because 2 tilts are different. - // : -2 --> mismatched because 2 tilts are different in the meaning of tilt == 0. + // EXPLANATION + // status : 0 --> anything passing through all if statement. + // : 1 --> matched in tilt == 1 + // : 2 --> matched in tilt == 2 + // : 4 --> matched in tilt == 0 + // : -1 --> mismatched because 2 tilts are different. + // : -2 --> mismatched because 2 tilts are different in the meaning of tilt == 0. } - -IntVec FPCCDSiliconTracking_MarlinTrk::getNHitsInSubDet(SimTrackerHitVec simvec){ +IntVec FPCCDSiliconTracking_MarlinTrk::getNHitsInSubDet(SimTrackerHitVec simvec) { IntVec ivec(3); - for(int i = 0; i < int(simvec.size()); i++){ + for (int i = 0; i < int(simvec.size()); i++) { int detid = getDetectorID(simvec[i]); - if(detid == lcio::ILDDetID::VXD ){ ivec[0]++; } - else if(detid == lcio::ILDDetID::SIT){ ivec[1]++; } - else if(detid == lcio::ILDDetID::FTD){ ivec[2]++; } + if (detid == lcio::ILDDetID::VXD) { + ivec[0]++; + } else if (detid == lcio::ILDDetID::SIT) { + ivec[1]++; + } else if (detid == lcio::ILDDetID::FTD) { + ivec[2]++; + } } return ivec; } +// This is a debug tool for debug by mori. +MCPMap FPCCDSiliconTracking_MarlinTrk::LoadMCPMap() { -//This is a debug tool for debug by mori. -MCPMap FPCCDSiliconTracking_MarlinTrk::LoadMCPMap(){ - - - _mcpVXD.clear(); - _mcpSIT.clear(); + _mcpVXD.clear(); + _mcpSIT.clear(); _mcpVXDSIT.clear(); - _mcpFTD.clear(); - _mcpFTDSIT.clear(); - _mcpVXDFTD.clear(); - _mcpVXDFTDSIT.clear(); + _mcpFTD.clear(); + _mcpFTDSIT.clear(); + _mcpVXDFTD.clear(); + _mcpVXDFTDSIT.clear(); //_colMCP = GetCollection(_current_event, _colNameMCParticles); - _simVXD = GetCollection(_current_event, _colNameVXDSimHit); - _simSIT = GetCollection(_current_event, _colNameSITSimHit); + _simVXD = GetCollection(_current_event, _colNameVXDSimHit); + _simSIT = GetCollection(_current_event, _colNameSITSimHit); _simFTDpix = GetCollection(_current_event, _colNameFTDpixSimHit); - _simFTDsp = GetCollection(_current_event, _colNameFTDspSimHit); + _simFTDsp = GetCollection(_current_event, _colNameFTDspSimHit); SimTrackerHitVec simVec; int nvxd = 0, nsit = 0, nftdpix = 0, nftdsp = 0; - if(_simVXD != NULL){ + if (_simVXD != NULL) { nvxd = _simVXD->getNumberOfElements(); - for(int i = 0; i < nvxd; i++) simVec.push_back(dynamic_cast(_simVXD->getElementAt(i))); + for (int i = 0; i < nvxd; i++) + simVec.push_back(dynamic_cast(_simVXD->getElementAt(i))); } - if(_simSIT != NULL){ + if (_simSIT != NULL) { nsit = _simSIT->getNumberOfElements(); - for(int i = 0; i < nsit; i++) simVec.push_back(dynamic_cast(_simSIT->getElementAt(i))); + for (int i = 0; i < nsit; i++) + simVec.push_back(dynamic_cast(_simSIT->getElementAt(i))); } - if(_simFTDpix != NULL){ + if (_simFTDpix != NULL) { nftdpix = _simFTDpix->getNumberOfElements(); - for(int i = 0; i < nftdpix; i++) simVec.push_back(dynamic_cast(_simFTDpix->getElementAt(i))); + for (int i = 0; i < nftdpix; i++) + simVec.push_back(dynamic_cast(_simFTDpix->getElementAt(i))); } - if(_simFTDsp != NULL){ + if (_simFTDsp != NULL) { nftdsp = _simFTDsp->getNumberOfElements(); - for(int i = 0; i < nftdsp; i++) simVec.push_back(dynamic_cast(_simFTDsp->getElementAt(i))); + for (int i = 0; i < nftdsp; i++) + simVec.push_back(dynamic_cast(_simFTDsp->getElementAt(i))); } - MCPMap mymap = _moriUtil->MakeMCPMap(simVec); - for(MCPMap::iterator it = mymap.begin(); it != mymap.end(); it++){ - if(it->first == NULL) continue; - IntVec ivec = getNHitsInSubDet(it->second);//ivec[0] : VXD, ivec[1] : SIT, ivec[2] : FTD - if(ivec[2] == 0){ - if(ivec[1] == 0){ _mcpVXD.insert(*it); } - else{ - if(ivec[0] == 0){ _mcpSIT.insert(*it); } - else{ _mcpVXDSIT.insert(*it); } - } - } - else{ - if(ivec[0] == 0){ - if(ivec[1] == 0){ _mcpFTD.insert(*it); } - else{ _mcpFTDSIT.insert(*it); } + for (MCPMap::iterator it = mymap.begin(); it != mymap.end(); it++) { + if (it->first == NULL) + continue; + IntVec ivec = getNHitsInSubDet(it->second); // ivec[0] : VXD, ivec[1] : SIT, ivec[2] : FTD + if (ivec[2] == 0) { + if (ivec[1] == 0) { + _mcpVXD.insert(*it); + } else { + if (ivec[0] == 0) { + _mcpSIT.insert(*it); + } else { + _mcpVXDSIT.insert(*it); + } } - else{ - if(ivec[1] == 0){ _mcpVXDFTD.insert(*it); } - else{ _mcpVXDFTDSIT.insert(*it); } + } else { + if (ivec[0] == 0) { + if (ivec[1] == 0) { + _mcpFTD.insert(*it); + } else { + _mcpFTDSIT.insert(*it); + } + } else { + if (ivec[1] == 0) { + _mcpVXDFTD.insert(*it); + } else { + _mcpVXDFTDSIT.insert(*it); + } } } } - if(1){ + if (1) { std::cout << "nvxd : " << nvxd << std::endl; std::cout << "nsit : " << nsit << std::endl; std::cout << "nftdpix : " << nftdpix << std::endl; @@ -4225,19 +4069,18 @@ MCPMap FPCCDSiliconTracking_MarlinTrk::LoadMCPMap(){ std::cout << "nmcp contributing VXD + FTD + SIT: " << _mcpVXDFTDSIT.size() << std::endl; } - return mymap; + return mymap; } - - - - -int FPCCDSiliconTracking_MarlinTrk::getPhiThetaRegion(TrackExtended* trackAR, int layer, int* Boundaries){ +int FPCCDSiliconTracking_MarlinTrk::getPhiThetaRegion(TrackExtended* trackAR, int layer, int* Boundaries) { TrackerHit* currentInnermostHit = trackAR->getTrackerHitExtendedVec().back()->getTrackerHit(); - double d0error = (trackAR->getTrackerHitExtendedVec().size() == 3) ? 1.0/sqrt(trackAR->getCovMatrix()[9]) : sqrt(trackAR->getCovMatrix()[0]) ; - double omegaerror = (trackAR->getTrackerHitExtendedVec().size() == 3) ? 1.0/sqrt(trackAR->getCovMatrix()[0]) : sqrt(trackAR->getCovMatrix()[5]) ; - double z0error = (trackAR->getTrackerHitExtendedVec().size() == 3) ? 1.0/sqrt(trackAR->getCovMatrix()[14]) : sqrt(trackAR->getCovMatrix()[9]) ; + double d0error = (trackAR->getTrackerHitExtendedVec().size() == 3) ? 1.0 / sqrt(trackAR->getCovMatrix()[9]) + : sqrt(trackAR->getCovMatrix()[0]); + double omegaerror = (trackAR->getTrackerHitExtendedVec().size() == 3) ? 1.0 / sqrt(trackAR->getCovMatrix()[0]) + : sqrt(trackAR->getCovMatrix()[5]); + double z0error = (trackAR->getTrackerHitExtendedVec().size() == 3) ? 1.0 / sqrt(trackAR->getCovMatrix()[14]) + : sqrt(trackAR->getCovMatrix()[9]); double phi0 = trackAR->getPhi(); double d0 = trackAR->getD0(); @@ -4245,98 +4088,145 @@ int FPCCDSiliconTracking_MarlinTrk::getPhiThetaRegion(TrackExtended* trackAR, in double omega = trackAR->getOmega(); double tanL = trackAR->getTanLambda(); - //check - if(_mydebugIntersection){ + // check + if (_mydebugIntersection) { std::cout << "========layer : " << layer << " ====================" << std::endl; - printf("d0error,omegaerror,z0error : %f, %f, %f \n",d0error,omegaerror,z0error); - printf("d0,omega,z0,phi0,tanlambda : %f, %f, %f, %f, %f \n",d0,omega,z0,phi0,tanL); + printf("d0error,omegaerror,z0error : %f, %f, %f \n", d0error, omegaerror, z0error); + printf("d0,omega,z0,phi0,tanlambda : %f, %f, %f, %f, %f \n", d0, omega, z0, phi0, tanL); } - - if( std::isnormal(d0error) == false || (d0error < 1e-6) ){ - if(_mydebugIntersection) std::cout << "FATAL ERROR of d0error: nan check MORI " << std::endl; - if(trackAR->getTrackerHitExtendedVec().size() == 3){ if(_mydebugIntersection) printf("d0error cov[9] : %f \n",trackAR->getCovMatrix()[9]); d0error = -1.0; } - else{ if(_mydebugIntersection) printf("d0error cov[0] : %f \n",trackAR->getCovMatrix()[0]); d0error = -1.0; } + if (std::isnormal(d0error) == false || (d0error < 1e-6)) { + if (_mydebugIntersection) + std::cout << "FATAL ERROR of d0error: nan check MORI " << std::endl; + if (trackAR->getTrackerHitExtendedVec().size() == 3) { + if (_mydebugIntersection) + printf("d0error cov[9] : %f \n", trackAR->getCovMatrix()[9]); + d0error = -1.0; + } else { + if (_mydebugIntersection) + printf("d0error cov[0] : %f \n", trackAR->getCovMatrix()[0]); + d0error = -1.0; + } } - if( std::isnormal(omegaerror) == false || (omegaerror < 1e-6) ){ - if(_mydebugIntersection) std::cout << "FATAL ERROR of omegaerror: nan check MORI " << std::endl; - if(trackAR->getTrackerHitExtendedVec().size() == 3){ if(_mydebugIntersection) printf("omegaerror cov[0] : %f \n",trackAR->getCovMatrix()[0]); omegaerror = -1.0; } - else{ if(_mydebugIntersection) printf("omegaerror cov[5] : %f \n",trackAR->getCovMatrix()[5]); omegaerror = -1.0; } + if (std::isnormal(omegaerror) == false || (omegaerror < 1e-6)) { + if (_mydebugIntersection) + std::cout << "FATAL ERROR of omegaerror: nan check MORI " << std::endl; + if (trackAR->getTrackerHitExtendedVec().size() == 3) { + if (_mydebugIntersection) + printf("omegaerror cov[0] : %f \n", trackAR->getCovMatrix()[0]); + omegaerror = -1.0; + } else { + if (_mydebugIntersection) + printf("omegaerror cov[5] : %f \n", trackAR->getCovMatrix()[5]); + omegaerror = -1.0; + } } - if( std::isnormal(z0error) == false || (z0error < 1e-6) ){ - if(_mydebugIntersection) std::cout << "FATAL ERROR of z0error: nan check MORI " << std::endl; - if(trackAR->getTrackerHitExtendedVec().size() == 3){ if(_mydebugIntersection) printf("z0error cov[14] : %f \n",trackAR->getCovMatrix()[14]); z0error = -1.0; } - else{ if(_mydebugIntersection) printf("z0error cov[9] : %f \n",trackAR->getCovMatrix()[9]); z0error = -1.0; } + if (std::isnormal(z0error) == false || (z0error < 1e-6)) { + if (_mydebugIntersection) + std::cout << "FATAL ERROR of z0error: nan check MORI " << std::endl; + if (trackAR->getTrackerHitExtendedVec().size() == 3) { + if (_mydebugIntersection) + printf("z0error cov[14] : %f \n", trackAR->getCovMatrix()[14]); + z0error = -1.0; + } else { + if (_mydebugIntersection) + printf("z0error cov[9] : %f \n", trackAR->getCovMatrix()[9]); + z0error = -1.0; + } } - DoubleVec phiSectsTest(5); DoubleVec thetaSectsTest(3); + for (int i = 0; i < 5; i++) { + std::vector iSec; + HelixClass_double tmpHelix; + if (i == 1 && (d0error < 0)) { + phiSectsTest[1] = phiSectsTest[0]; + phiSectsTest[2] = phiSectsTest[0]; + i = 2; + continue; + } + if (i >= 3 && (omegaerror < 0)) { + phiSectsTest[3] = phiSectsTest[0]; + phiSectsTest[4] = phiSectsTest[0]; + break; + } - for(int i = 0; i < 5; i++){ - std::vector iSec; HelixClass_double tmpHelix; - if(i == 1 && (d0error < 0) ){ phiSectsTest[1] = phiSectsTest[0]; phiSectsTest[2] = phiSectsTest[0]; i=2; continue; } - if(i >= 3 && (omegaerror < 0)){ phiSectsTest[3] = phiSectsTest[0]; phiSectsTest[4] = phiSectsTest[0];break; } - - if(i == 0) tmpHelix.Initialize_Canonical(phi0, d0, z0, omega, tanL, _bField); - else if(i == 1) tmpHelix.Initialize_Canonical(phi0, d0 + d0error*_nSigmaBuild_phi, z0, omega, tanL, _bField); - else if(i == 2) tmpHelix.Initialize_Canonical(phi0, d0 - d0error*_nSigmaBuild_phi, z0, omega, tanL, _bField); - else if(i == 3) tmpHelix.Initialize_Canonical(phi0, d0, z0, omega + omegaerror*_nSigmaBuild_phi, tanL, _bField); - else if(i == 4) tmpHelix.Initialize_Canonical(phi0, d0, z0, omega - omegaerror*_nSigmaBuild_phi, tanL, _bField); + if (i == 0) + tmpHelix.Initialize_Canonical(phi0, d0, z0, omega, tanL, _bField); + else if (i == 1) + tmpHelix.Initialize_Canonical(phi0, d0 + d0error * _nSigmaBuild_phi, z0, omega, tanL, _bField); + else if (i == 2) + tmpHelix.Initialize_Canonical(phi0, d0 - d0error * _nSigmaBuild_phi, z0, omega, tanL, _bField); + else if (i == 3) + tmpHelix.Initialize_Canonical(phi0, d0, z0, omega + omegaerror * _nSigmaBuild_phi, tanL, _bField); + else if (i == 4) + tmpHelix.Initialize_Canonical(phi0, d0, z0, omega - omegaerror * _nSigmaBuild_phi, tanL, _bField); int error = getIntersectionEasyTest(tmpHelix, currentInnermostHit, layer, iSec); - if(error == -1){ - //std::cout << "getIntersectionEasyTest for phi-sector couldn't find intersection. loop : " << i << std::endl; - return int(trackAR->getTrackerHitExtendedVec().size()); + if (error == -1) { + // std::cout << "getIntersectionEasyTest for phi-sector couldn't find intersection. loop : " << i << std::endl; + return int(trackAR->getTrackerHitExtendedVec().size()); } - if(layer < int(_nLayersVTX)){ - if(std::abs(iSec[2]) > _vxd.geodata[layer].hlength ){ - if(_mydebugIntersection) std::cout << "Z length is too long. VXD at 1" << std::endl; - return int(trackAR->getTrackerHitExtendedVec().size()); + if (layer < int(_nLayersVTX)) { + if (std::abs(iSec[2]) > _vxd.geodata[layer].hlength) { + if (_mydebugIntersection) + std::cout << "Z length is too long. VXD at 1" << std::endl; + return int(trackAR->getTrackerHitExtendedVec().size()); } - } - else if(layer >= int(_nLayersVTX)){ - if(std::abs(iSec[2]) > _sit.geodata[layer - _nLayersVTX].hlength ){ - if(_mydebugIntersection) std::cout << "Z length is too long. SIT at 1" << std::endl; - return int(trackAR->getTrackerHitExtendedVec().size()); + } else if (layer >= int(_nLayersVTX)) { + if (std::abs(iSec[2]) > _sit.geodata[layer - _nLayersVTX].hlength) { + if (_mydebugIntersection) + std::cout << "Z length is too long. SIT at 1" << std::endl; + return int(trackAR->getTrackerHitExtendedVec().size()); } } - double tmpphi = atan2( iSec[1], iSec[0] ) ; - if(tmpphi < 0.0) tmpphi += 2.0*M_PI; - phiSectsTest[i] = tmpphi/(2.0*M_PI/_nDivisionsInPhi); + double tmpphi = atan2(iSec[1], iSec[0]); + if (tmpphi < 0.0) + tmpphi += 2.0 * M_PI; + phiSectsTest[i] = tmpphi / (2.0 * M_PI / _nDivisionsInPhi); } - - for(int i = 0; i < 3; i++){ - std::vector iSec; HelixClass_double tmpHelix; - if(i == 1 && (z0error < 0) ){ thetaSectsTest[1] = thetaSectsTest[0]; thetaSectsTest[2] = thetaSectsTest[0]; break; } - if(i == 0) tmpHelix.Initialize_Canonical(phi0, d0, z0, omega, tanL, _bField); - else if(i == 1){ tmpHelix.Initialize_Canonical(phi0, d0, z0 + z0error*_nSigmaBuild_theta, omega, tanL, _bField); } - else if(i == 2){ tmpHelix.Initialize_Canonical(phi0, d0, z0 - z0error*_nSigmaBuild_theta, omega, tanL, _bField); } + for (int i = 0; i < 3; i++) { + std::vector iSec; + HelixClass_double tmpHelix; + if (i == 1 && (z0error < 0)) { + thetaSectsTest[1] = thetaSectsTest[0]; + thetaSectsTest[2] = thetaSectsTest[0]; + break; + } + if (i == 0) + tmpHelix.Initialize_Canonical(phi0, d0, z0, omega, tanL, _bField); + else if (i == 1) { + tmpHelix.Initialize_Canonical(phi0, d0, z0 + z0error * _nSigmaBuild_theta, omega, tanL, _bField); + } else if (i == 2) { + tmpHelix.Initialize_Canonical(phi0, d0, z0 - z0error * _nSigmaBuild_theta, omega, tanL, _bField); + } int error = getIntersectionEasyTest(tmpHelix, currentInnermostHit, layer, iSec); - if(error == -1){ - //std::cout << "getIntersectionEasyTest for phi-theta couldn't find intersection. loop : " << i << std::endl; - return int(trackAR->getTrackerHitExtendedVec().size()); + if (error == -1) { + // std::cout << "getIntersectionEasyTest for phi-theta couldn't find intersection. loop : " << i << std::endl; + return int(trackAR->getTrackerHitExtendedVec().size()); } - if(layer < int(_nLayersVTX)){ - if(std::abs(iSec[2]) > _vxd.geodata[layer].hlength ){ - if(_mydebugIntersection) std::cout << "Z length is too long. VXD at 2" << std::endl; - return int(trackAR->getTrackerHitExtendedVec().size()); + if (layer < int(_nLayersVTX)) { + if (std::abs(iSec[2]) > _vxd.geodata[layer].hlength) { + if (_mydebugIntersection) + std::cout << "Z length is too long. VXD at 2" << std::endl; + return int(trackAR->getTrackerHitExtendedVec().size()); } - } - else if(layer >= int(_nLayersVTX)){ - if(std::abs(iSec[2]) > _sit.geodata[layer - _nLayersVTX].hlength ){ - if(_mydebugIntersection) std::cout << "Z length is too long. SIT at 2" << std::endl; - return int(trackAR->getTrackerHitExtendedVec().size()); + } else if (layer >= int(_nLayersVTX)) { + if (std::abs(iSec[2]) > _sit.geodata[layer - _nLayersVTX].hlength) { + if (_mydebugIntersection) + std::cout << "Z length is too long. SIT at 2" << std::endl; + return int(trackAR->getTrackerHitExtendedVec().size()); } } - double tmpcostheta = iSec[2]/sqrt(iSec[0]*iSec[0] + iSec[1]*iSec[1] + iSec[2]*iSec[2]); - thetaSectsTest[i] = (tmpcostheta + 1.0)/_dTheta; + double tmpcostheta = iSec[2] / sqrt(iSec[0] * iSec[0] + iSec[1] * iSec[1] + iSec[2] * iSec[2]); + thetaSectsTest[i] = (tmpcostheta + 1.0) / _dTheta; } - //check + // check /* std::cout << "phiSectsTest[0] : " << phiSectsTest[0] << std::endl; std::cout << "phiSectsTest[1] : " << phiSectsTest[1] << std::endl; @@ -4348,72 +4238,85 @@ int FPCCDSiliconTracking_MarlinTrk::getPhiThetaRegion(TrackExtended* trackAR, in std::cout << "thetaSectsTest[2] : " << thetaSectsTest[2] << std::endl; */ - - int iPhiUpTest = int(std::max(phiSectsTest[0],std::max(phiSectsTest[1],std::max(phiSectsTest[2],std::max(phiSectsTest[3],phiSectsTest[4]))))) + 1 + _fudgePhiRange; - int iPhiLowTest = int(std::min(phiSectsTest[0],std::min(phiSectsTest[1],std::min(phiSectsTest[2],std::min(phiSectsTest[3],phiSectsTest[4]))))) - 1 - _fudgePhiRange; - int iThetaUpTest = int(std::max(thetaSectsTest[0],std::max(thetaSectsTest[1],thetaSectsTest[2]))) + 1 + _fudgeThetaRange; - int iThetaLowTest = int(std::min(thetaSectsTest[0],std::min(thetaSectsTest[1],thetaSectsTest[2]))) - 1 - _fudgeThetaRange; - - if(iPhiLowTest + _nDivisionsInPhi - iPhiUpTest < iPhiUpTest - iPhiLowTest ) { + int iPhiUpTest = + int(std::max(phiSectsTest[0], + std::max(phiSectsTest[1], std::max(phiSectsTest[2], std::max(phiSectsTest[3], phiSectsTest[4]))))) + + 1 + _fudgePhiRange; + int iPhiLowTest = + int(std::min(phiSectsTest[0], + std::min(phiSectsTest[1], std::min(phiSectsTest[2], std::min(phiSectsTest[3], phiSectsTest[4]))))) - + 1 - _fudgePhiRange; + int iThetaUpTest = + int(std::max(thetaSectsTest[0], std::max(thetaSectsTest[1], thetaSectsTest[2]))) + 1 + _fudgeThetaRange; + int iThetaLowTest = + int(std::min(thetaSectsTest[0], std::min(thetaSectsTest[1], thetaSectsTest[2]))) - 1 - _fudgeThetaRange; + + if (iPhiLowTest + _nDivisionsInPhi - iPhiUpTest < iPhiUpTest - iPhiLowTest) { int swap1 = iPhiUpTest; int swap2 = iPhiLowTest + _nDivisionsInPhi; - iPhiUpTest = std::max(swap1,swap2); - iPhiLowTest = std::min(swap1,swap2); + iPhiUpTest = std::max(swap1, swap2); + iPhiLowTest = std::min(swap1, swap2); } - + int bugCheck = 0; - if(iThetaLowTest < 0){ iThetaLowTest = 0; bugCheck++;} - if(iThetaUpTest >= _nDivisionsInTheta){ iThetaUpTest = _nDivisionsInTheta - 1; bugCheck++;} - if(bugCheck == 2){ - std::cout << "FATAL ERROR. Check code!!; however, process isn't stopped. iThetaLow,Up = 0,0 is returned.) " << std::endl; + if (iThetaLowTest < 0) { + iThetaLowTest = 0; + bugCheck++; + } + if (iThetaUpTest >= _nDivisionsInTheta) { + iThetaUpTest = _nDivisionsInTheta - 1; + bugCheck++; + } + if (bugCheck == 2) { + std::cout << "FATAL ERROR. Check code!!; however, process isn't stopped. iThetaLow,Up = 0,0 is returned.) " + << std::endl; iThetaLowTest = 0; iThetaUpTest = 0; } - - //check - if(_mydebugIntersection){ + // check + if (_mydebugIntersection) { std::cout << "iPhiLowTest, UpTest = " << iPhiLowTest << " , " << iPhiUpTest << std::endl; std::cout << "iThetaLowTest, UpTest = " << iThetaLowTest << " , " << iThetaUpTest << std::endl; } - Boundaries[0] = iPhiLowTest; Boundaries[1] = iPhiUpTest; Boundaries[2] = iThetaLowTest; Boundaries[3] = iThetaUpTest; return 0; - } - -FPCCDSiliconTracking_MarlinTrk::MCPContributions FPCCDSiliconTracking_MarlinTrk::getMCPContribution(IntVec nsub){ - if(nsub[0] == 0){ - if(nsub[1] == 0){ - if(nsub[2] == 0){ std::cout << "In MCPContributionChecker: No Tracker Hit!! Fatal Error. exit" << std::endl; exit(1); } - else{ return contFTD; } - } - else{ - if(nsub[2] == 0 ){ return contSIT; } - else{ return contFTDSIT; } - } - } - else{ - if(nsub[1] == 0){ - if(nsub[2] == 0){ return contVXD; } - else{ return contVXDFTD; } +FPCCDSiliconTracking_MarlinTrk::MCPContributions FPCCDSiliconTracking_MarlinTrk::getMCPContribution(IntVec nsub) { + if (nsub[0] == 0) { + if (nsub[1] == 0) { + if (nsub[2] == 0) { + std::cout << "In MCPContributionChecker: No Tracker Hit!! Fatal Error. exit" << std::endl; + exit(1); + } else { + return contFTD; + } + } else { + if (nsub[2] == 0) { + return contSIT; + } else { + return contFTDSIT; + } } - else{ - if(nsub[2] == 0){ return contVXDSIT; } - else{ return contVXDFTDSIT; } + } else { + if (nsub[1] == 0) { + if (nsub[2] == 0) { + return contVXD; + } else { + return contVXDFTD; + } + } else { + if (nsub[2] == 0) { + return contVXDSIT; + } else { + return contVXDFTDSIT; + } } } } - - - - - - - diff --git a/source/Refitting/src/FullLDCTracking_MarlinTrk.cc b/source/Refitting/src/FullLDCTracking_MarlinTrk.cc index dc028c7..3f9cb39 100644 --- a/source/Refitting/src/FullLDCTracking_MarlinTrk.cc +++ b/source/Refitting/src/FullLDCTracking_MarlinTrk.cc @@ -1,573 +1,384 @@ #include "FullLDCTracking_MarlinTrk.h" -#include #include +#include +#include +#include +#include #include #include -#include -#include -#include -#include #include -#include #include -#include +#include +#include #include +#include #include -#include +#include "ClusterShapes.h" #include #include -#include "ClusterShapes.h" +#include -#include "DD4hep/Detector.h" #include "DD4hep/DD4hepUnits.h" +#include "DD4hep/Detector.h" #include "DDRec/DetectorData.h" -#include #include +#include -#include "MarlinTrk/MarlinTrkUtils.h" -#include "MarlinTrk/HelixTrack.h" +#include "MarlinTrk/Factory.h" #include "MarlinTrk/HelixFit.h" +#include "MarlinTrk/HelixTrack.h" #include "MarlinTrk/IMarlinTrack.h" -#include "MarlinTrk/Factory.h" +#include "MarlinTrk/MarlinTrkUtils.h" #include "MarlinTrk/LCIOTrackPropagators.h" #include "MarlinTrk/MarlinTrkDiagnostics.h" #ifdef MARLINTRK_DIAGNOSTICS_ON - #include "MarlinTrk/DiagnosticsController.h" +#include "MarlinTrk/DiagnosticsController.h" #endif -#include #include "UTIL/LCTrackerConf.h" +#include #include #include #include -#include "gsl/gsl_randist.h" #include "gsl/gsl_cdf.h" +#include "gsl/gsl_randist.h" +using namespace lcio; +using namespace marlin; +using namespace MarlinTrk; -using namespace lcio ; -using namespace marlin ; -using namespace MarlinTrk ; - -FullLDCTracking_MarlinTrk aFullLDCTracking_MarlinTrk ; - +FullLDCTracking_MarlinTrk aFullLDCTracking_MarlinTrk; /** debug printout helper method */ -std::string toString( int iTrk, Track * tpcTrack, float bField=3.5 ) { - - int nHits = int( tpcTrack->getTrackerHits().size() ); - float d0TPC = tpcTrack->getD0(); - float z0TPC = tpcTrack->getZ0(); +std::string toString(int iTrk, Track* tpcTrack, float bField = 3.5) { + + int nHits = int(tpcTrack->getTrackerHits().size()); + float d0TPC = tpcTrack->getD0(); + float z0TPC = tpcTrack->getZ0(); float omegaTPC = tpcTrack->getOmega(); - float phi0TPC = tpcTrack->getPhi(); - float tanLTPC = tpcTrack->getTanLambda(); - float Chi2TPC = tpcTrack->getChi2()/float(tpcTrack->getNdf()); - int ndfTPC = tpcTrack->getNdf(); + float phi0TPC = tpcTrack->getPhi(); + float tanLTPC = tpcTrack->getTanLambda(); + float Chi2TPC = tpcTrack->getChi2() / float(tpcTrack->getNdf()); + int ndfTPC = tpcTrack->getNdf(); int nlinkedTracks = tpcTrack->getTracks().size(); - - + HelixClass helixTPC; - - helixTPC.Initialize_Canonical(phi0TPC,d0TPC,z0TPC,omegaTPC,tanLTPC, bField); - + + helixTPC.Initialize_Canonical(phi0TPC, d0TPC, z0TPC, omegaTPC, tanLTPC, bField); + char strg[200]; - + float pxTPC = helixTPC.getMomentum()[0]; float pyTPC = helixTPC.getMomentum()[1]; float pzTPC = helixTPC.getMomentum()[2]; - const float ptot = sqrt(pxTPC*pxTPC+pyTPC*pyTPC+pzTPC*pzTPC); + const float ptot = sqrt(pxTPC * pxTPC + pyTPC * pyTPC + pzTPC * pzTPC); - sprintf(strg,"%3i %5i %9.3f %9.3f %9.3f %7.2f %7.2f %7.2f %4i %4i %8.3f %8i",iTrk,tpcTrack->id(), - ptot, d0TPC,z0TPC,pxTPC,pyTPC,pzTPC,nHits,ndfTPC,Chi2TPC,nlinkedTracks); + sprintf(strg, "%3i %5i %9.3f %9.3f %9.3f %7.2f %7.2f %7.2f %4i %4i %8.3f %8i", iTrk, tpcTrack->id(), ptot, + d0TPC, z0TPC, pxTPC, pyTPC, pzTPC, nHits, ndfTPC, Chi2TPC, nlinkedTracks); - return std::string( strg ) ; + return std::string(strg); } +FullLDCTracking_MarlinTrk::FullLDCTracking_MarlinTrk() : Processor("FullLDCTracking_MarlinTrk") { + _description = "Performs full tracking in ILD detector"; - -FullLDCTracking_MarlinTrk::FullLDCTracking_MarlinTrk() : Processor("FullLDCTracking_MarlinTrk") { - _description = "Performs full tracking in ILD detector" ; - - // Input tracker hit collections - - registerInputCollection(LCIO::TRACKERHITPLANE, - "FTDPixelHitCollectionName", - "FTD Pixel Hit Collection Name", - _FTDPixelHitCollection, - std::string("FTDPixelTrackerHits")); - - registerInputCollection(LCIO::TRACKERHIT, - "FTDSpacePointCollectionName", - "FTD FTDSpacePoint Collection Name", - _FTDSpacePointCollection, - std::string("FTDSpacePoints")); - - registerInputCollection(LCIO::TRACKERHITPLANE, - "VTXHitCollection", - "VTX Hit Collection Name", - _VTXTrackerHitCollection, - std::string("VTXTrackerHits")); - - registerInputCollection(LCIO::TRACKERHIT, - "SITHitCollection", - "SIT Hit Collection Name", - _SITTrackerHitCollection, + + registerInputCollection(LCIO::TRACKERHITPLANE, "FTDPixelHitCollectionName", "FTD Pixel Hit Collection Name", + _FTDPixelHitCollection, std::string("FTDPixelTrackerHits")); + + registerInputCollection(LCIO::TRACKERHIT, "FTDSpacePointCollectionName", "FTD FTDSpacePoint Collection Name", + _FTDSpacePointCollection, std::string("FTDSpacePoints")); + + registerInputCollection(LCIO::TRACKERHITPLANE, "VTXHitCollection", "VTX Hit Collection Name", + _VTXTrackerHitCollection, std::string("VTXTrackerHits")); + + registerInputCollection(LCIO::TRACKERHIT, "SITHitCollection", "SIT Hit Collection Name", _SITTrackerHitCollection, std::string("SITTrackerHits")); - - registerInputCollection(LCIO::TRACKERHIT, - "SETHitCollection", - "SET Hit Collection Name", - _SETTrackerHitCollection, + + registerInputCollection(LCIO::TRACKERHIT, "SETHitCollection", "SET Hit Collection Name", _SETTrackerHitCollection, std::string("SETTrackerHits")); - - registerInputCollection(LCIO::TRACKERHIT, - "ETDHitCollection", - "ETD Hit Collection Name", - _ETDTrackerHitCollection, + + registerInputCollection(LCIO::TRACKERHIT, "ETDHitCollection", "ETD Hit Collection Name", _ETDTrackerHitCollection, std::string("ETDTrackerHits")); - - registerInputCollection(LCIO::TRACKERHIT, - "TPCHitCollection", - "TPC Hit Collection Name", - _TPCTrackerHitCollection, + + registerInputCollection(LCIO::TRACKERHIT, "TPCHitCollection", "TPC Hit Collection Name", _TPCTrackerHitCollection, std::string("TPCTrackerHits")); - - + // Input track collections - - registerInputCollection(LCIO::TRACK, - "TPCTracks", - "TPC Track Collection", - _TPCTrackCollection, + + registerInputCollection(LCIO::TRACK, "TPCTracks", "TPC Track Collection", _TPCTrackCollection, std::string("TPCTracks")); - - registerInputCollection(LCIO::TRACK, - "SiTracks", - "Si Track Collection", - _SiTrackCollection, - std::string("SiTracks")); - + + registerInputCollection(LCIO::TRACK, "SiTracks", "Si Track Collection", _SiTrackCollection, std::string("SiTracks")); + // Input relation collections - - registerInputCollection(LCIO::LCRELATION, - "TPCTracksMCPRelColl", - "TPC Track to MCP Relation Collection Name", - _TPCTrackMCPCollName, - std::string("TPCTracksMCP")); - - registerInputCollection(LCIO::LCRELATION, - "SiTracksMCPRelColl", - "Si Track to Collection", - _SiTrackMCPCollName, + + registerInputCollection(LCIO::LCRELATION, "TPCTracksMCPRelColl", "TPC Track to MCP Relation Collection Name", + _TPCTrackMCPCollName, std::string("TPCTracksMCP")); + + registerInputCollection(LCIO::LCRELATION, "SiTracksMCPRelColl", "Si Track to Collection", _SiTrackMCPCollName, std::string("SiTracksMCP")); - + // Output track collection - registerOutputCollection(LCIO::TRACK, - "LDCTrackCollection", - "LDC track collection name", - _LDCTrackCollection, + registerOutputCollection(LCIO::TRACK, "LDCTrackCollection", "LDC track collection name", _LDCTrackCollection, std::string("LDCTracks")); - - - + // steering parameters - - registerProcessorParameter("D0CutForMerging", - "Cut on D0 difference for merging of Si and TPC segments", - _d0CutForMerging, - float(500.0)); - - registerProcessorParameter("Z0CutForMerging", - "Cut on Z0 difference for merging of Si and TPC segments", - _z0CutForMerging, - float(1000.0)); - - registerProcessorParameter("OmegaCutForMerging", - "Cut on Omega difference for merging Si and TPC segments", - _dOmegaForMerging, - float(0.25)); - - registerProcessorParameter("AngleCutForMerging", - "Cut on Opening Angle for merging Si and TPC segments", - _angleForMerging, - float(0.10)); - - registerProcessorParameter("Chi2FitCut", - "Cut on fit Chi2", - _chi2FitCut, - float(100.0)); - - registerProcessorParameter("Debug", - "Activate debugging?", - _debug, - int(0)); - - - registerProcessorParameter("ForceSiTPCMerging", - "Force merging of Si and TPC segments?", - _forceMerging, - int(0)); - - registerProcessorParameter("D0CutForForcedMerging", - "Cut on D0 difference for forced merging of Si and TPC segments", - _d0CutForForcedMerging, - float(50.)); - - registerProcessorParameter("Z0CutForForcedMerging", - "Cut on Z0 difference for forced merging of Si and TPC segments", - _z0CutForForcedMerging, - float(200.)); - + + registerProcessorParameter("D0CutForMerging", "Cut on D0 difference for merging of Si and TPC segments", + _d0CutForMerging, float(500.0)); + + registerProcessorParameter("Z0CutForMerging", "Cut on Z0 difference for merging of Si and TPC segments", + _z0CutForMerging, float(1000.0)); + + registerProcessorParameter("OmegaCutForMerging", "Cut on Omega difference for merging Si and TPC segments", + _dOmegaForMerging, float(0.25)); + + registerProcessorParameter("AngleCutForMerging", "Cut on Opening Angle for merging Si and TPC segments", + _angleForMerging, float(0.10)); + + registerProcessorParameter("Chi2FitCut", "Cut on fit Chi2", _chi2FitCut, float(100.0)); + + registerProcessorParameter("Debug", "Activate debugging?", _debug, int(0)); + + registerProcessorParameter("ForceSiTPCMerging", "Force merging of Si and TPC segments?", _forceMerging, int(0)); + + registerProcessorParameter("D0CutForForcedMerging", "Cut on D0 difference for forced merging of Si and TPC segments", + _d0CutForForcedMerging, float(50.)); + + registerProcessorParameter("Z0CutForForcedMerging", "Cut on Z0 difference for forced merging of Si and TPC segments", + _z0CutForForcedMerging, float(200.)); + registerProcessorParameter("OmegaCutForForcedMerging", "Cut on Omega difference for forced merging of Si and TPC segments", - _dOmegaForForcedMerging, - float(0.15)); - + _dOmegaForForcedMerging, float(0.15)); + registerProcessorParameter("AngleCutForForcedMerging", - "Cut on Opening Angle for forced merging of Si and TPC segments", - _angleForForcedMerging, + "Cut on Opening Angle for forced merging of Si and TPC segments", _angleForForcedMerging, float(0.05)); - - registerProcessorParameter("ForceTPCSegmentsMerging", - "Force merging of TPC Segments?", - _mergeTPCSegments, - int(0)); - - registerProcessorParameter("D0CutToMergeTPCSegments", - "Cut on D0 difference for merging TPC segments", - _d0CutToMergeTPC, - float(100.)); - - registerProcessorParameter("Z0CutToMergeTPCSegments", - "Cut on Z0 difference for merging TPC segments", - _z0CutToMergeTPC, - float(5000.0)); - - registerProcessorParameter("DeltaPCutToMergeTPCSegments", - "Cut on dP/P difference for merging TPC segments", - _dPCutToMergeTPC, - float(0.1)); - - registerProcessorParameter("PtCutToMergeTPCSegments", - "Cut on Pt of tracks for merging TPC segments", - _PtCutToMergeTPC, - float(1.2)); - - - - registerProcessorParameter("cosThetaCutHighPtMerge", - "Cut on cos theta between the two momentum vectors when considering merger of high Pt tracks", - _cosThetaCutHighPtMerge, - float(0.99)); - - registerProcessorParameter("cosThetaCutSoftHighPtMerge", - "cut on cos theta between the two momentum vectors when considering merger of high Pt tracks for softer dp/p cut", - _cosThetaCutSoftHighPtMerge, - float(0.998)); - - registerProcessorParameter("momDiffCutHighPtMerge", - "cut on dp/p when considering merger of high Pt tracks", - _momDiffCutHighPtMerge, - float(0.01)); - + + registerProcessorParameter("ForceTPCSegmentsMerging", "Force merging of TPC Segments?", _mergeTPCSegments, int(0)); + + registerProcessorParameter("D0CutToMergeTPCSegments", "Cut on D0 difference for merging TPC segments", + _d0CutToMergeTPC, float(100.)); + + registerProcessorParameter("Z0CutToMergeTPCSegments", "Cut on Z0 difference for merging TPC segments", + _z0CutToMergeTPC, float(5000.0)); + + registerProcessorParameter("DeltaPCutToMergeTPCSegments", "Cut on dP/P difference for merging TPC segments", + _dPCutToMergeTPC, float(0.1)); + + registerProcessorParameter("PtCutToMergeTPCSegments", "Cut on Pt of tracks for merging TPC segments", + _PtCutToMergeTPC, float(1.2)); + + registerProcessorParameter( + "cosThetaCutHighPtMerge", + "Cut on cos theta between the two momentum vectors when considering merger of high Pt tracks", + _cosThetaCutHighPtMerge, float(0.99)); + + registerProcessorParameter( + "cosThetaCutSoftHighPtMerge", + "cut on cos theta between the two momentum vectors when considering merger of high Pt tracks for softer dp/p cut", + _cosThetaCutSoftHighPtMerge, float(0.998)); + + registerProcessorParameter("momDiffCutHighPtMerge", "cut on dp/p when considering merger of high Pt tracks", + _momDiffCutHighPtMerge, float(0.01)); + registerProcessorParameter("momDiffCutSoftHighPtMerge", - "softer cut on dp/p when considering merger of high Pt tracks", - _momDiffCutSoftHighPtMerge, + "softer cut on dp/p when considering merger of high Pt tracks", _momDiffCutSoftHighPtMerge, float(0.25)); - - registerProcessorParameter("hitDistanceCutHighPtMerge", - "cut on 3D distance between hit and helix extrapolation when considering merger of high Pt tracks", - _hitDistanceCutHighPtMerge, - float(25.0)); - - registerProcessorParameter("maxHitDistanceCutHighPtMerge", - "cut for max 3D distance between any hit and helix extrapolation when considering merger of high Pt tracks", - _maxHitDistanceCutHighPtMerge, - float(50.0)); - + + registerProcessorParameter( + "hitDistanceCutHighPtMerge", + "cut on 3D distance between hit and helix extrapolation when considering merger of high Pt tracks", + _hitDistanceCutHighPtMerge, float(25.0)); + + registerProcessorParameter( + "maxHitDistanceCutHighPtMerge", + "cut for max 3D distance between any hit and helix extrapolation when considering merger of high Pt tracks", + _maxHitDistanceCutHighPtMerge, float(50.0)); + registerProcessorParameter("maxFractionOfOutliersCutHighPtMerge", "cut on maximum fraction of outliers when considering merger of high Pt tracks", - _maxFractionOfOutliersCutHighPtMerge, - float(0.95)); - - - - - - registerProcessorParameter("CutOnTPCHits", - "Cut on the number of the TPC hits for tracks with no Si hits", - _cutOnTPCHits, - int(35)); + _maxFractionOfOutliersCutHighPtMerge, float(0.95)); + + registerProcessorParameter("CutOnTPCHits", "Cut on the number of the TPC hits for tracks with no Si hits", + _cutOnTPCHits, int(35)); + + registerProcessorParameter("CutOnSiHits", "Cut on the number of the Si hits for tracks with no TPC hits", + _cutOnSiHits, int(4)); + + registerProcessorParameter("AssignVTXHits", "Assign left over VTX hits", _assignVTXHits, int(1)); + + registerProcessorParameter("AssignFTDHits", "Assign left over FTD hits", _assignFTDHits, int(1)); + + registerProcessorParameter("AssignSITHits", "Assign left over SIT hits", _assignSITHits, int(1)); - registerProcessorParameter("CutOnSiHits", - "Cut on the number of the Si hits for tracks with no TPC hits", - _cutOnSiHits, - int(4)); - - - registerProcessorParameter("AssignVTXHits", - "Assign left over VTX hits", - _assignVTXHits, - int(1)); - - registerProcessorParameter("AssignFTDHits", - "Assign left over FTD hits", - _assignFTDHits, - int(1)); - - registerProcessorParameter("AssignSITHits", - "Assign left over SIT hits", - _assignSITHits, - int(1)); - - registerProcessorParameter("AssignTPCHits", - "Assign left over TPC hits", - _assignTPCHits, - int(1)); - - registerProcessorParameter("AssignSETHits", - "Assign SET Hits", - _assignSETHits, - int(1)); - - - registerProcessorParameter("AssignETDHits", - "Assign ETD Hits", - _assignETDHits, - int(1)); - - registerProcessorParameter("NHitsExtrapolation", - "number of hits for outward extrapolation", - _nHitsExtrapolation, + registerProcessorParameter("AssignTPCHits", "Assign left over TPC hits", _assignTPCHits, int(1)); + + registerProcessorParameter("AssignSETHits", "Assign SET Hits", _assignSETHits, int(1)); + + registerProcessorParameter("AssignETDHits", "Assign ETD Hits", _assignETDHits, int(1)); + + registerProcessorParameter("NHitsExtrapolation", "number of hits for outward extrapolation", _nHitsExtrapolation, int(35)); - - - registerProcessorParameter("VTXHitToTrackDistance", - "Cut on distance between track and VTX hits", - _distCutForVTXHits, + + registerProcessorParameter("VTXHitToTrackDistance", "Cut on distance between track and VTX hits", _distCutForVTXHits, float(1.5)); - - - registerProcessorParameter("FTDHitToTrackDistance", - "Cut on distance between track and FTD hits", - _distCutForFTDHits, + + registerProcessorParameter("FTDHitToTrackDistance", "Cut on distance between track and FTD hits", _distCutForFTDHits, float(2.0)); - - - registerProcessorParameter("SITHitToTrackDistance", - "Cut on distance between track and SIT hits", - _distCutForSITHits, + + registerProcessorParameter("SITHitToTrackDistance", "Cut on distance between track and SIT hits", _distCutForSITHits, float(2.0)); - - registerProcessorParameter("SETHitToTrackDistance", - "Cut on distance between track and SET hits", - _distCutForSETHits, + + registerProcessorParameter("SETHitToTrackDistance", "Cut on distance between track and SET hits", _distCutForSETHits, float(2.0)); - - - registerProcessorParameter("ETDHitToTrackDistance", - "Cut on distance between track and ETD hits", - _distCutForETDHits, + + registerProcessorParameter("ETDHitToTrackDistance", "Cut on distance between track and ETD hits", _distCutForETDHits, float(10.0)); - - - registerProcessorParameter("TPCHitToTrackDistance", - "Cut on distance between track and TPC hits", - _distCutForTPCHits, + + registerProcessorParameter("TPCHitToTrackDistance", "Cut on distance between track and TPC hits", _distCutForTPCHits, float(15.0)); - - - registerProcessorParameter("CutOnTrackD0", - "Cut on the track parameter D0", - _d0TrkCut, - float(500.)); - - - registerProcessorParameter("CutOnTrackZ0", - "Cut on the track parameter Z0", - _z0TrkCut, - float(500.)); - - - registerProcessorParameter("ForbidOverlapInZTPC", - "Forbid overlap in Z for the merged TPC segments", - _forbidOverlapInZTPC, - int(0)); - + + registerProcessorParameter("CutOnTrackD0", "Cut on the track parameter D0", _d0TrkCut, float(500.)); + + registerProcessorParameter("CutOnTrackZ0", "Cut on the track parameter Z0", _z0TrkCut, float(500.)); + + registerProcessorParameter("ForbidOverlapInZTPC", "Forbid overlap in Z for the merged TPC segments", + _forbidOverlapInZTPC, int(0)); + registerProcessorParameter("ForbidOverlapInZComb", "Forbid overlap in Z for combining TPC segments with tracks having Si hits", - _forbidOverlapInZComb, - int(0)); - - registerProcessorParameter("MultipleScatteringOn", - "Use MultipleScattering in Fit", - _MSOn, - bool(true)); - - registerProcessorParameter("EnergyLossOn", - "Use Energy Loss in Fit", - _ElossOn, - bool(true)); - - registerProcessorParameter("SmoothOn", - "Smooth All Mesurement Sites in Fit", - _SmoothOn, - bool(true)); - - - registerProcessorParameter( "InitialTrackErrorD0", - "Value used for the initial d0 variance of the trackfit", - _initialTrackError_d0, - float(1.e6)); - - registerProcessorParameter( "InitialTrackErrorPhi0", - "Value used for the initial phi0 variance of the trackfit", - _initialTrackError_phi0, - float(1.e2)); - - registerProcessorParameter( "InitialTrackErrorOmega", - "Value used for the initial omega variance of the trackfit", - _initialTrackError_omega, - float(1.e-4)); - - registerProcessorParameter( "InitialTrackErrorZ0", - "Value used for the initial z0 variance of the trackfit", - _initialTrackError_z0, - float(1.e6)); - - registerProcessorParameter( "InitialTrackErrorTanL", - "Value used for the initial tanL variance of the trackfit", - _initialTrackError_tanL, - float(1.e2)); - - - registerProcessorParameter( "MaxChi2PerHit", - "Maximum Chi-squared value allowed when assigning a hit to a track", - _maxChi2PerHit, - double(1.e2)); - - - registerProcessorParameter( "MinChi2ProbForSiliconTracks", - "Minimum Chi-squared P value allowed for Silicon Tracks.", - _minChi2ProbForSiliconTracks, - double(1.e-03)); - - - registerProcessorParameter( "VetoMergeMomentumCut", - "Minimum momentum for which Veto is applicable", - _vetoMergeMomentumCut, - float(2.5)); - - registerProcessorParameter( "MaxAllowedPercentageOfOutliersForTrackCombination", + _forbidOverlapInZComb, int(0)); + + registerProcessorParameter("MultipleScatteringOn", "Use MultipleScattering in Fit", _MSOn, bool(true)); + + registerProcessorParameter("EnergyLossOn", "Use Energy Loss in Fit", _ElossOn, bool(true)); + + registerProcessorParameter("SmoothOn", "Smooth All Mesurement Sites in Fit", _SmoothOn, bool(true)); + + registerProcessorParameter("InitialTrackErrorD0", "Value used for the initial d0 variance of the trackfit", + _initialTrackError_d0, float(1.e6)); + + registerProcessorParameter("InitialTrackErrorPhi0", "Value used for the initial phi0 variance of the trackfit", + _initialTrackError_phi0, float(1.e2)); + + registerProcessorParameter("InitialTrackErrorOmega", "Value used for the initial omega variance of the trackfit", + _initialTrackError_omega, float(1.e-4)); + + registerProcessorParameter("InitialTrackErrorZ0", "Value used for the initial z0 variance of the trackfit", + _initialTrackError_z0, float(1.e6)); + + registerProcessorParameter("InitialTrackErrorTanL", "Value used for the initial tanL variance of the trackfit", + _initialTrackError_tanL, float(1.e2)); + + registerProcessorParameter("MaxChi2PerHit", "Maximum Chi-squared value allowed when assigning a hit to a track", + _maxChi2PerHit, double(1.e2)); + + registerProcessorParameter("MinChi2ProbForSiliconTracks", "Minimum Chi-squared P value allowed for Silicon Tracks.", + _minChi2ProbForSiliconTracks, double(1.e-03)); + + registerProcessorParameter("VetoMergeMomentumCut", "Minimum momentum for which Veto is applicable", + _vetoMergeMomentumCut, float(2.5)); + + registerProcessorParameter("MaxAllowedPercentageOfOutliersForTrackCombination", "Maximum number of outliers allowed before track combination is vetoed", - _maxAllowedPercentageOfOutliersForTrackCombination, - float(0.3)); + _maxAllowedPercentageOfOutliersForTrackCombination, float(0.3)); - registerProcessorParameter( "MaxAllowedSiHitRejectionsForTrackCombination", + registerProcessorParameter("MaxAllowedSiHitRejectionsForTrackCombination", "Maximum number of outliers allowed before track combination is vetoed", - _maxAllowedSiHitRejectionsForTrackCombination, - int(2)); + _maxAllowedSiHitRejectionsForTrackCombination, int(2)); - registerProcessorParameter( "EnergyLossErrorTPC", - "Fractional error of dEdx in the TPC", - _energyLossErrorTPC, + registerProcessorParameter("EnergyLossErrorTPC", "Fractional error of dEdx in the TPC", _energyLossErrorTPC, float(0.05)); - - - registerProcessorParameter( "TrackSystemName", - "Name of the track fitting system to be used (KalTest, DDKalTest, aidaTT, ... )", - _trkSystemName, - std::string("KalTest") ); - + registerProcessorParameter("TrackSystemName", + "Name of the track fitting system to be used (KalTest, DDKalTest, aidaTT, ... )", + _trkSystemName, std::string("KalTest")); #ifdef MARLINTRK_DIAGNOSTICS_ON - - registerOptionalParameter("RunMarlinTrkDiagnostics", "Run MarlinTrk Diagnostics. MarlinTrk must be compiled with MARLINTRK_DIAGNOSTICS_ON defined", _runMarlinTrkDiagnostics, bool(false)); - - registerOptionalParameter("DiagnosticsName", "Name of the root file and root tree if running Diagnostics", _MarlinTrkDiagnosticsName, std::string("FullLDCTrackingDiagnostics")); - + + registerOptionalParameter( + "RunMarlinTrkDiagnostics", + "Run MarlinTrk Diagnostics. MarlinTrk must be compiled with MARLINTRK_DIAGNOSTICS_ON defined", + _runMarlinTrkDiagnostics, bool(false)); + + registerOptionalParameter("DiagnosticsName", "Name of the root file and root tree if running Diagnostics", + _MarlinTrkDiagnosticsName, std::string("FullLDCTrackingDiagnostics")); + #endif - } +void FullLDCTracking_MarlinTrk::init() { - -void FullLDCTracking_MarlinTrk::init() { - - printParameters(); - _nRun = -1 ; - _nEvt = 0 ; + printParameters(); + _nRun = -1; + _nEvt = 0; PI = acos(-1.); - PIOVER2 = 0.5*PI; - TWOPI = 2*PI; - + PIOVER2 = 0.5 * PI; + TWOPI = 2 * PI; + _encoder = new UTIL::BitField64(lcio::LCTrackerCellID::encoding_string()); // set upt the geometry - _trksystem = MarlinTrk::Factory::createMarlinTrkSystem( _trkSystemName , 0 , "" ) ; - - - if( _trksystem == 0 ){ - - throw EVENT::Exception( std::string(" Cannot initialize MarlinTrkSystem of Type: ") + _trkSystemName ) ; + _trksystem = MarlinTrk::Factory::createMarlinTrkSystem(_trkSystemName, 0, ""); + + if (_trksystem == 0) { + + throw EVENT::Exception(std::string(" Cannot initialize MarlinTrkSystem of Type: ") + _trkSystemName); } - - _trksystem->setOption( IMarlinTrkSystem::CFG::useQMS, _MSOn ) ; - _trksystem->setOption( IMarlinTrkSystem::CFG::usedEdx, _ElossOn) ; - _trksystem->setOption( IMarlinTrkSystem::CFG::useSmoothing, _SmoothOn) ; - _trksystem->init() ; - + _trksystem->setOption(IMarlinTrkSystem::CFG::useQMS, _MSOn); + _trksystem->setOption(IMarlinTrkSystem::CFG::usedEdx, _ElossOn); + _trksystem->setOption(IMarlinTrkSystem::CFG::useSmoothing, _SmoothOn); + _trksystem->init(); + #ifdef MARLINTRK_DIAGNOSTICS_ON - - void * dcv = _trksystem->getDiagnositicsPointer(); + + void* dcv = _trksystem->getDiagnositicsPointer(); DiagnosticsController* dc = static_cast(dcv); - dc->init(_MarlinTrkDiagnosticsName,_MarlinTrkDiagnosticsName, _runMarlinTrkDiagnostics); - + dc->init(_MarlinTrkDiagnosticsName, _MarlinTrkDiagnosticsName, _runMarlinTrkDiagnostics); + #endif - dd4hep::Detector& theDetector = dd4hep::Detector::getInstance(); - - this->setupGeom( theDetector ); - + + this->setupGeom(theDetector); } -void FullLDCTracking_MarlinTrk::processRunHeader( LCRunHeader* run) { - - _nRun++ ; +void FullLDCTracking_MarlinTrk::processRunHeader(LCRunHeader* run) { + + _nRun++; _nEvt = 0; streamlog_out(DEBUG5) << std::endl; streamlog_out(DEBUG5) << "FullLDCTracking_MarlinTrk ---> new run : run number = " << run->getRunNumber() << std::endl; - -} +} + +void FullLDCTracking_MarlinTrk::processEvent(LCEvent* evt) { -void FullLDCTracking_MarlinTrk::processEvent( LCEvent * evt ) { - - // set the correct configuration for the tracking system for this event - MarlinTrk::TrkSysConfig< MarlinTrk::IMarlinTrkSystem::CFG::useQMS> mson( _trksystem, _MSOn ) ; - MarlinTrk::TrkSysConfig< MarlinTrk::IMarlinTrkSystem::CFG::usedEdx> elosson( _trksystem,_ElossOn) ; - MarlinTrk::TrkSysConfig< MarlinTrk::IMarlinTrkSystem::CFG::useSmoothing> smoothon( _trksystem,_SmoothOn) ; + // set the correct configuration for the tracking system for this event + MarlinTrk::TrkSysConfig mson(_trksystem, _MSOn); + MarlinTrk::TrkSysConfig elosson(_trksystem, _ElossOn); + MarlinTrk::TrkSysConfig smoothon(_trksystem, _SmoothOn); _evt = evt; - - + streamlog_out(DEBUG5) << std::endl; streamlog_out(DEBUG5) << "FullLDCTracking_MarlinTrk -> run = " << evt->getRunNumber() - << " event = " << evt->getEventNumber() << std::endl; + << " event = " << evt->getEventNumber() << std::endl; streamlog_out(DEBUG5) << std::endl; - - - prepareVectors( evt ); + + prepareVectors(evt); streamlog_out(DEBUG5) << "************************************PrepareVectors done..." << std::endl; streamlog_out(DEBUG5) << "************************************Merge TPC/Si ..." << std::endl; @@ -581,21 +392,22 @@ void FullLDCTracking_MarlinTrk::processEvent( LCEvent * evt ) { Sorting(_allCombinedTracks); streamlog_out(DEBUG5) << "************************************Sorting by Chi2/NDF done ..." << std::endl; - streamlog_out(DEBUG5) << "************************************Selection of all 2 track combininations ..." << std::endl; + streamlog_out(DEBUG5) << "************************************Selection of all 2 track combininations ..." + << std::endl; SelectCombinedTracks(); - streamlog_out(DEBUG5) << "************************************Selection of all 2 track combininations done ..." << std::endl; + streamlog_out(DEBUG5) << "************************************Selection of all 2 track combininations done ..." + << std::endl; streamlog_out(DEBUG5) << "************************************Trying non combined tracks ..." << std::endl; - AddNotCombinedTracks( ); + AddNotCombinedTracks(); streamlog_out(DEBUG5) << "************************************Non combined tracks added ..." << std::endl; - //CheckTracks( ); + // CheckTracks( ); streamlog_out(DEBUG5) << "************************************Add Non assigned hits ..." << std::endl; AddNotAssignedHits(); streamlog_out(DEBUG5) << "************************************Non assigned hits added ..." << std::endl; - AddTrackColToEvt(evt,_trkImplVec, - _LDCTrackCollection); + AddTrackColToEvt(evt, _trkImplVec, _LDCTrackCollection); streamlog_out(DEBUG5) << "Collections added to event ..." << std::endl; CleanUp(); streamlog_out(DEBUG5) << "Cleanup is done." << std::endl; @@ -603,361 +415,338 @@ void FullLDCTracking_MarlinTrk::processEvent( LCEvent * evt ) { // getchar(); streamlog_out(DEBUG5) << std::endl; streamlog_out(DEBUG5) << std::endl; - } -void FullLDCTracking_MarlinTrk::AddTrackColToEvt(LCEvent * evt, TrackExtendedVec & trkVec, - std::string TrkColName) { - - LCCollectionVec * colTRK = new LCCollectionVec(LCIO::TRACK); +void FullLDCTracking_MarlinTrk::AddTrackColToEvt(LCEvent* evt, TrackExtendedVec& trkVec, std::string TrkColName) { + + LCCollectionVec* colTRK = new LCCollectionVec(LCIO::TRACK); // if we want to point back to the hits we need to set the flag - LCFlagImpl trkFlag(0) ; - trkFlag.setBit( LCIO::TRBIT_HITS ) ; - colTRK->setFlag( trkFlag.getFlag() ) ; - - streamlog_out(DEBUG5)<< "AddTrackColToEvt: Collection " << TrkColName << " is being added to event " << std::endl; - + LCFlagImpl trkFlag(0); + trkFlag.setBit(LCIO::TRBIT_HITS); + colTRK->setFlag(trkFlag.getFlag()); + + streamlog_out(DEBUG5) << "AddTrackColToEvt: Collection " << TrkColName << " is being added to event " << std::endl; + // LCCollectionVec * colRel = NULL; - - + int nTrkCand = int(trkVec.size()); - + int nTotTracks = 0; - float eTot = 0.0; + float eTot = 0.0; float pxTot = 0.0; float pyTot = 0.0; float pzTot = 0.0; - - //SJA:FIXME: So here we are going to do one final refit. This can certainly be optimised, but rather than worry about the mememory management right now lets make it work, and optimise it later ... - - - for (int iTRK=0;iTRKgetTrackerHitExtendedVec(); EVENT::TrackerHitVec trkHits; - + streamlog_out(DEBUG2) << " Trying to add track " << trkCand << " to final lcio collection " << std::endl; - - + int nHits = int(hitVec.size()); - - streamlog_out(DEBUG2) << " Trying to add track " << trkCand << " to final lcio collection nHits = " << nHits << std::endl; - - for (int ihit=0;ihitgetUsedInFit() == false ) { - streamlog_out(DEBUG2) << "rejecting hit for track " << trkCand << " at zhit " << hitVec[ihit]->getTrackerHit()->getPosition()[2] << std::endl; + + streamlog_out(DEBUG2) << " Trying to add track " << trkCand << " to final lcio collection nHits = " << nHits + << std::endl; + + for (int ihit = 0; ihit < nHits; ++ihit) { + + if (hitVec[ihit]->getUsedInFit() == false) { + streamlog_out(DEBUG2) << "rejecting hit for track " << trkCand << " at zhit " + << hitVec[ihit]->getTrackerHit()->getPosition()[2] << std::endl; continue; } EVENT::TrackerHit* trkHit = hitVec[ihit]->getTrackerHit(); - - if(trkHit) { - trkHits.push_back(trkHit); - } - else{ - throw EVENT::Exception( std::string("FullLDCTracking_MarlinTrk::AddTrackColToEvt: TrackerHit pointer == NULL ") ) ; + + if (trkHit) { + trkHits.push_back(trkHit); + } else { + throw EVENT::Exception(std::string("FullLDCTracking_MarlinTrk::AddTrackColToEvt: TrackerHit pointer == NULL ")); } - } - - - if( trkHits.size() < 3 ) { - streamlog_out(DEBUG3) << "FullLDCTracking_MarlinTrk::AddTrackColToEvt: Cannot fit less than 3 hits. Number of hits = " << trkHits.size() << std::endl; - continue ; + + if (trkHits.size() < 3) { + streamlog_out(DEBUG3) + << "FullLDCTracking_MarlinTrk::AddTrackColToEvt: Cannot fit less than 3 hits. Number of hits = " + << trkHits.size() << std::endl; + continue; } - - - TrackImpl* Track = new TrackImpl ; - + + TrackImpl* Track = new TrackImpl; + // setup initial dummy covariance matrix EVENT::FloatVec covMatrix; covMatrix.resize(15); - - for (unsigned icov = 0; icovgetGroupTracks(); + + GroupTracks* group = trkCand->getGroupTracks(); TrackStateImpl ts_initial; - + bool prefit_set = false; - + streamlog_out(DEBUG2) << "Track Group = " << group << std::endl; - - if( group ) streamlog_out(DEBUG2) << "Track Group size = " << group->getTrackExtendedVec().size() << std::endl; + + if (group) + streamlog_out(DEBUG2) << "Track Group size = " << group->getTrackExtendedVec().size() << std::endl; if (group != NULL && group->getTrackExtendedVec().size() > 0) { - + // get the second track as this must be the one furthest from the IP TrackExtended* te = 0; - - if(group->getTrackExtendedVec().size()==1) { + + if (group->getTrackExtendedVec().size() == 1) { te = group->getTrackExtendedVec()[0]; } else { te = group->getTrackExtendedVec()[1]; } - - if(te->getTrack()->getTrackState(lcio::TrackState::AtLastHit)){ + + if (te->getTrack()->getTrackState(lcio::TrackState::AtLastHit)) { streamlog_out(DEBUG2) << "Initialise Fit with trackstate from last hit" << group << std::endl; ts_initial = *(te->getTrack()->getTrackState(lcio::TrackState::AtLastHit)); - - - prefit_set = true; + prefit_set = true; } - } - - if( !prefit_set ) { // use parameters at IP - + + if (!prefit_set) { // use parameters at IP + streamlog_out(DEBUG2) << "Initialise Fit with trackstate from IP " << group << std::endl; - + ts_initial.setD0(trkCand->getD0()); ts_initial.setPhi(trkCand->getPhi()); ts_initial.setZ0(trkCand->getZ0()); ts_initial.setOmega(trkCand->getOmega()); ts_initial.setTanLambda(trkCand->getTanLambda()); - + float ref[3]; - ref[0]=ref[1]=ref[2]=0.0; - + ref[0] = ref[1] = ref[2] = 0.0; + ts_initial.setReferencePoint(ref); - - ts_initial.setLocation(lcio::TrackStateImpl::AtIP); - + ts_initial.setLocation(lcio::TrackStateImpl::AtIP); } - + ts_initial.setCovMatrix(covMatrix); - + // sort hits in R - std::vector< std::pair > r2_values; + std::vector> r2_values; r2_values.reserve(trkHits.size()); - - for (TrackerHitVec::iterator it=trkHits.begin(); it!=trkHits.end(); ++it) { + + for (TrackerHitVec::iterator it = trkHits.begin(); it != trkHits.end(); ++it) { EVENT::TrackerHit* h = *it; - float r2 = h->getPosition()[0]*h->getPosition()[0]+h->getPosition()[1]*h->getPosition()[1]; + float r2 = h->getPosition()[0] * h->getPosition()[0] + h->getPosition()[1] * h->getPosition()[1]; r2_values.push_back(std::make_pair(r2, *it)); } - - sort(r2_values.begin(),r2_values.end()); - + + sort(r2_values.begin(), r2_values.end()); + trkHits.clear(); trkHits.reserve(r2_values.size()); - - for (std::vector< std::pair >::iterator it=r2_values.begin(); it!=r2_values.end(); ++it) { + + for (std::vector>::iterator it = r2_values.begin(); it != r2_values.end(); + ++it) { trkHits.push_back(it->second); } - + bool fit_backwards = IMarlinTrack::backward; - + MarlinTrk::IMarlinTrack* marlinTrk = _trksystem->createTrack(); - - + int error = 0; - + try { - - error = MarlinTrk::createFinalisedLCIOTrack(marlinTrk, trkHits, Track, fit_backwards, &ts_initial, _bField, _maxChi2PerHit); - + + error = MarlinTrk::createFinalisedLCIOTrack(marlinTrk, trkHits, Track, fit_backwards, &ts_initial, _bField, + _maxChi2PerHit); + } catch (...) { - + // delete Track; // delete marlinTrk; - - throw ; - + + throw; } - - + #ifdef MARLINTRK_DIAGNOSTICS_ON - if ( error != IMarlinTrack::success && _runMarlinTrkDiagnostics ) { - void * dcv = _trksystem->getDiagnositicsPointer(); + if (error != IMarlinTrack::success && _runMarlinTrkDiagnostics) { + void* dcv = _trksystem->getDiagnositicsPointer(); DiagnosticsController* dc = static_cast(dcv); dc->skip_current_track(); - } + } #endif - - - std::vector > hits_in_fit ; - std::vector > outliers ; - std::vector all_hits; + + std::vector> hits_in_fit; + std::vector> outliers; + std::vector all_hits; all_hits.reserve(300); - + marlinTrk->getHitsInFit(hits_in_fit); - - for ( unsigned ihit = 0; ihit < hits_in_fit.size(); ++ihit) { + + for (unsigned ihit = 0; ihit < hits_in_fit.size(); ++ihit) { all_hits.push_back(hits_in_fit[ihit].first); } - - UTIL::BitField64 cellID_encoder( lcio::LCTrackerCellID::encoding_string() ) ; - + + UTIL::BitField64 cellID_encoder(lcio::LCTrackerCellID::encoding_string()); + MarlinTrk::addHitNumbersToTrack(Track, all_hits, true, cellID_encoder); - + marlinTrk->getOutliers(outliers); - - for ( unsigned ihit = 0; ihit < outliers.size(); ++ihit) { + + for (unsigned ihit = 0; ihit < outliers.size(); ++ihit) { all_hits.push_back(outliers[ihit].first); } - + MarlinTrk::addHitNumbersToTrack(Track, all_hits, false, cellID_encoder); - - + delete marlinTrk; - - if( error != IMarlinTrack::success ) { - - streamlog_out(DEBUG3) << "FullLDCTracking_MarlinTrk::AddTrackColToEvt: Track fit failed with error code " << error << " track dropped. Number of hits = "<< trkHits.size() << std::endl; - - delete Track; - continue ; + + if (error != IMarlinTrack::success) { + + streamlog_out(DEBUG3) << "FullLDCTracking_MarlinTrk::AddTrackColToEvt: Track fit failed with error code " << error + << " track dropped. Number of hits = " << trkHits.size() << std::endl; + + delete Track; + continue; } - - if( Track->getNdf() < 0) { - streamlog_out(DEBUG3) << "FullLDCTracking_MarlinTrk::AddTrackColToEvt: Track fit returns " << Track->getNdf() << " degress of freedom track dropped. Number of hits = "<< trkHits.size() << std::endl; - + + if (Track->getNdf() < 0) { + streamlog_out(DEBUG3) << "FullLDCTracking_MarlinTrk::AddTrackColToEvt: Track fit returns " << Track->getNdf() + << " degress of freedom track dropped. Number of hits = " << trkHits.size() << std::endl; + delete Track; - continue ; + continue; } - + const TrackState* trkStateIP = Track->getTrackState(lcio::TrackState::AtIP); - + if (trkStateIP == 0) { - streamlog_out(DEBUG3) << "FullLDCTracking_MarlinTrk::AddTrackColToEvt: Track fit returns " << Track->getNdf() << " degress of freedom track dropped. Number of hits = "<< trkHits.size() << std::endl; - throw EVENT::Exception( std::string("FullLDCTracking_MarlinTrk::AddTrackColToEvt: trkStateIP pointer == NULL ") ) ; + streamlog_out(DEBUG3) << "FullLDCTracking_MarlinTrk::AddTrackColToEvt: Track fit returns " << Track->getNdf() + << " degress of freedom track dropped. Number of hits = " << trkHits.size() << std::endl; + throw EVENT::Exception(std::string("FullLDCTracking_MarlinTrk::AddTrackColToEvt: trkStateIP pointer == NULL ")); } - - - - + if (group != NULL) { TrackExtendedVec trkVecGrp = group->getTrackExtendedVec(); int nGrTRK = int(trkVecGrp.size()); - for (int iGr=0;iGraddTrack(subTrack->getTrack()); // check if it is a tpc looper ... - if( BitSet32( subTrack->getTrack()->getType() )[ lcio::ILDDetID::TPC ] ) { - + if (BitSet32(subTrack->getTrack()->getType())[lcio::ILDDetID::TPC]) { + const TrackVec segments = subTrack->getTrack()->getTracks(); - if ( segments.empty() == false ) { - - for (unsigned iSeg=0;iSegaddTrack(segments[iSeg]); } - } - } } } - + float d0TrkCand = trkCand->getD0(); float z0TrkCand = trkCand->getZ0(); // float phi0TrkCand = trkCand->getPhi(); - - - int nhits_in_vxd = Track->subdetectorHitNumbers()[ 2 * lcio::ILDDetID::VXD - 2 ]; - int nhits_in_ftd = Track->subdetectorHitNumbers()[ 2 * lcio::ILDDetID::FTD - 2 ]; - int nhits_in_sit = Track->subdetectorHitNumbers()[ 2 * lcio::ILDDetID::SIT - 2 ]; - int nhits_in_tpc = Track->subdetectorHitNumbers()[ 2 * lcio::ILDDetID::TPC - 2 ]; - int nhits_in_set = Track->subdetectorHitNumbers()[ 2 * lcio::ILDDetID::SET - 2 ]; - + + int nhits_in_vxd = Track->subdetectorHitNumbers()[2 * lcio::ILDDetID::VXD - 2]; + int nhits_in_ftd = Track->subdetectorHitNumbers()[2 * lcio::ILDDetID::FTD - 2]; + int nhits_in_sit = Track->subdetectorHitNumbers()[2 * lcio::ILDDetID::SIT - 2]; + int nhits_in_tpc = Track->subdetectorHitNumbers()[2 * lcio::ILDDetID::TPC - 2]; + int nhits_in_set = Track->subdetectorHitNumbers()[2 * lcio::ILDDetID::SET - 2]; + int nHitsSi = nhits_in_vxd + nhits_in_ftd + nhits_in_sit; - - streamlog_out( DEBUG3 ) << " Hit numbers for Track "<< Track->id() << ": " - << " vxd hits = " << nhits_in_vxd - << " ftd hits = " << nhits_in_ftd - << " sit hits = " << nhits_in_sit - << " tpc hits = " << nhits_in_tpc - << " set hits = " << nhits_in_set - << std::endl; - - if (nhits_in_vxd > 0) Track->setTypeBit( lcio::ILDDetID::VXD ) ; - if (nhits_in_ftd > 0) Track->setTypeBit( lcio::ILDDetID::FTD ) ; - if (nhits_in_sit > 0) Track->setTypeBit( lcio::ILDDetID::SIT ) ; - if (nhits_in_tpc > 0) Track->setTypeBit( lcio::ILDDetID::TPC ) ; - if (nhits_in_set > 0) Track->setTypeBit( lcio::ILDDetID::SET ) ; - - bool rejectTrack_onTPCHits = (nhits_in_tpc < _cutOnTPCHits) && (nHitsSi<=0); - - bool rejectTrackonSiliconHits = ( (nhits_in_tpc<=0) && (nHitsSi<_cutOnSiHits) ); - bool rejectTrackonImpactParameters = ( fabs(d0TrkCand) > _d0TrkCut ) || ( fabs(z0TrkCand) > _z0TrkCut ); - - if ( rejectTrack_onTPCHits || rejectTrackonSiliconHits || rejectTrackonImpactParameters) { - - streamlog_out( DEBUG3 ) << " Track " << trkCand - << " rejected : rejectTrack_onTPCHits = " << rejectTrack_onTPCHits - << " rejectTrackonSiliconHits " << rejectTrackonSiliconHits - << " rejectTrackonImpactParameters " << rejectTrackonImpactParameters - << std::endl; - + + streamlog_out(DEBUG3) << " Hit numbers for Track " << Track->id() << ": " + << " vxd hits = " << nhits_in_vxd << " ftd hits = " << nhits_in_ftd + << " sit hits = " << nhits_in_sit << " tpc hits = " << nhits_in_tpc + << " set hits = " << nhits_in_set << std::endl; + + if (nhits_in_vxd > 0) + Track->setTypeBit(lcio::ILDDetID::VXD); + if (nhits_in_ftd > 0) + Track->setTypeBit(lcio::ILDDetID::FTD); + if (nhits_in_sit > 0) + Track->setTypeBit(lcio::ILDDetID::SIT); + if (nhits_in_tpc > 0) + Track->setTypeBit(lcio::ILDDetID::TPC); + if (nhits_in_set > 0) + Track->setTypeBit(lcio::ILDDetID::SET); + + bool rejectTrack_onTPCHits = (nhits_in_tpc < _cutOnTPCHits) && (nHitsSi <= 0); + + bool rejectTrackonSiliconHits = ((nhits_in_tpc <= 0) && (nHitsSi < _cutOnSiHits)); + bool rejectTrackonImpactParameters = (fabs(d0TrkCand) > _d0TrkCut) || (fabs(z0TrkCand) > _z0TrkCut); + + if (rejectTrack_onTPCHits || rejectTrackonSiliconHits || rejectTrackonImpactParameters) { + + streamlog_out(DEBUG3) << " Track " << trkCand << " rejected : rejectTrack_onTPCHits = " << rejectTrack_onTPCHits + << " rejectTrackonSiliconHits " << rejectTrackonSiliconHits + << " rejectTrackonImpactParameters " << rejectTrackonImpactParameters << std::endl; + delete Track; - + } else { - + float omega = trkStateIP->getOmega(); float tanLambda = trkStateIP->getTanLambda(); float phi0 = trkStateIP->getPhi(); float d0 = trkStateIP->getD0(); float z0 = trkStateIP->getZ0(); - + HelixClass helix; - helix.Initialize_Canonical(phi0,d0,z0,omega,tanLambda,_bField); - + helix.Initialize_Canonical(phi0, d0, z0, omega, tanLambda, _bField); + float trkPx = helix.getMomentum()[0]; float trkPy = helix.getMomentum()[1]; float trkPz = helix.getMomentum()[2]; - float trkP = sqrt(trkPx*trkPx+trkPy*trkPy+trkPz*trkPz); - + float trkP = sqrt(trkPx * trkPx + trkPy * trkPy + trkPz * trkPz); + eTot += trkP; pxTot += trkPx; pyTot += trkPy; - pzTot += trkPz; + pzTot += trkPz; nTotTracks++; - - streamlog_out(DEBUG3) << " Add Track to final Collection: ID = " << Track->id() << " for trkCand "<< trkCand << std::endl; + + streamlog_out(DEBUG3) << " Add Track to final Collection: ID = " << Track->id() << " for trkCand " << trkCand + << std::endl; colTRK->addElement(Track); - } } - + streamlog_out(DEBUG5) << std::endl; - streamlog_out(DEBUG5) << "Number of accepted " << TrkColName << " = " - << nTotTracks << std::endl; - streamlog_out(DEBUG5) << "Total 4-momentum of " << TrkColName << " : E = " << eTot - << " Px = " << pxTot - << " Py = " << pyTot - << " Pz = " << pzTot << std::endl; + streamlog_out(DEBUG5) << "Number of accepted " << TrkColName << " = " << nTotTracks << std::endl; + streamlog_out(DEBUG5) << "Total 4-momentum of " << TrkColName << " : E = " << eTot << " Px = " << pxTot + << " Py = " << pyTot << " Pz = " << pzTot << std::endl; streamlog_out(DEBUG5) << std::endl; - - evt->addCollection(colTRK,TrkColName.c_str()); - - + + evt->addCollection(colTRK, TrkColName.c_str()); } +void FullLDCTracking_MarlinTrk::prepareVectors(LCEvent* event) { -void FullLDCTracking_MarlinTrk::prepareVectors(LCEvent * event ) { - - - - _allTPCHits.clear(); _allVTXHits.clear(); _allFTDHits.clear(); @@ -971,507 +760,507 @@ void FullLDCTracking_MarlinTrk::prepareVectors(LCEvent * event ) { _allNonCombinedSiTracks.clear(); _trkImplVec.clear(); _candidateCombinedTracks.clear(); - - - std::map mapTrackerHits; - + + std::map mapTrackerHits; + // Reading TPC hits try { - - LCCollection * col = event->getCollection(_TPCTrackerHitCollection.c_str()); - + + LCCollection* col = event->getCollection(_TPCTrackerHitCollection.c_str()); + int nelem = col->getNumberOfElements(); - + streamlog_out(DEBUG5) << "Number of TPC hits = " << nelem << std::endl; - - for (int ielem=0;ielem(col->getElementAt(ielem)); - TrackerHitExtended * hitExt = new TrackerHitExtended(hit); - + + for (int ielem = 0; ielem < nelem; ++ielem) { + + TrackerHit* hit = dynamic_cast(col->getElementAt(ielem)); + TrackerHitExtended* hitExt = new TrackerHitExtended(hit); + // Covariance Matrix in LCIO is defined in XYZ convert to R-Phi-Z // For no error in r - + double tpcRPhiRes = sqrt(hit->getCovMatrix()[0] + hit->getCovMatrix()[2]); double tpcZRes = sqrt(hit->getCovMatrix()[5]); - + hitExt->setResolutionRPhi(float(tpcRPhiRes)); hitExt->setResolutionZ(float(tpcZRes)); - + // type and det are no longer used, set to INT_MAX to try and catch any missuse hitExt->setType(int(INT_MAX)); hitExt->setDet(int(INT_MAX)); - _allTPCHits.push_back( hitExt ); + _allTPCHits.push_back(hitExt); mapTrackerHits[hit] = hitExt; double pos[3]; - - for (int i=0; i<3; ++i) { + + for (int i = 0; i < 3; ++i) { pos[i] = hit->getPosition()[i]; } - + unsigned int layer = static_cast(getLayerID(hit)); - - streamlog_out( DEBUG1 ) << " TPC Hit added : @ " << pos[0] << " " << pos[1] << " " << pos[2] << " drphi " << tpcRPhiRes << " dz " << tpcZRes << " layer = " << layer << std::endl; - + + streamlog_out(DEBUG1) << " TPC Hit added : @ " << pos[0] << " " << pos[1] << " " << pos[2] << " drphi " + << tpcRPhiRes << " dz " << tpcZRes << " layer = " << layer << std::endl; } - } - catch( DataNotAvailableException &e ) { + } catch (DataNotAvailableException& e) { streamlog_out(DEBUG4) << _TPCTrackerHitCollection.c_str() << " collection is unavailable" << std::endl; }; - - + // Reading in FTD Pixel Hits Collection //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ try { - - LCCollection * hitCollection = event->getCollection(_FTDPixelHitCollection.c_str()); - + + LCCollection* hitCollection = event->getCollection(_FTDPixelHitCollection.c_str()); + int nelem = hitCollection->getNumberOfElements(); - + streamlog_out(DEBUG5) << "Number of FTD Pixel hits = " << nelem << std::endl; - - for (int ielem=0; ielem(hitCollection->getElementAt(ielem)); - - TrackerHitExtended * hitExt = new TrackerHitExtended( hit ); - - double point_res_rphi = sqrt( hit->getdU()*hit->getdU() + hit->getdV()*hit->getdV() ); - hitExt->setResolutionRPhi( point_res_rphi ); - - // SJA:FIXME why is this needed? + + for (int ielem = 0; ielem < nelem; ++ielem) { + TrackerHitPlane* hit = dynamic_cast(hitCollection->getElementAt(ielem)); + + TrackerHitExtended* hitExt = new TrackerHitExtended(hit); + + double point_res_rphi = sqrt(hit->getdU() * hit->getdU() + hit->getdV() * hit->getdV()); + hitExt->setResolutionRPhi(point_res_rphi); + + // SJA:FIXME why is this needed? hitExt->setResolutionZ(0.1); - + // type and det are no longer used, set to INT_MAX to try and catch any missuse - hitExt->setType(int(INT_MAX)); + hitExt->setType(int(INT_MAX)); hitExt->setDet(int(INT_MAX)); - - _allFTDHits.push_back( hitExt ); + + _allFTDHits.push_back(hitExt); mapTrackerHits[hit] = hitExt; - + // get the layer number unsigned int layer = static_cast(getLayerID(hit)); unsigned int petalIndex = static_cast(getModuleID(hit)); - - if ( _petalBasedFTDWithOverlaps == true ) { - + + if (_petalBasedFTDWithOverlaps == true) { + // as we are dealing with staggered petals we will use 2*nlayers in each directions +/- z - // the layers will follow the even odd numbering of the petals - if ( petalIndex % 2 == 0 ) { - layer = 2*layer; - } - else { - layer = 2*layer + 1; + // the layers will follow the even odd numbering of the petals + if (petalIndex % 2 == 0) { + layer = 2 * layer; + } else { + layer = 2 * layer + 1; } - } - + if (layer >= _nLayersFTD) { - streamlog_out(ERROR) << "FullLDCTracking_MarlinTrk => fatal error in FTD : layer is outside allowed range : " << layer << " number of layers = " << _nLayersFTD << std::endl; + streamlog_out(ERROR) << "FullLDCTracking_MarlinTrk => fatal error in FTD : layer is outside allowed range : " + << layer << " number of layers = " << _nLayersFTD << std::endl; exit(1); } - + double pos[3]; - - for (int i=0; i<3; ++i) { + + for (int i = 0; i < 3; ++i) { pos[i] = hit->getPosition()[i]; - } - - streamlog_out( DEBUG1 ) << " FTD Pixel Hit added : @ " << pos[0] << " " << pos[1] << " " << pos[2] << " drphi " << hitExt->getResolutionRPhi() << " dz " << hitExt->getResolutionZ() << " layer = " << layer << std::endl; - + } + + streamlog_out(DEBUG1) << " FTD Pixel Hit added : @ " << pos[0] << " " << pos[1] << " " << pos[2] << " drphi " + << hitExt->getResolutionRPhi() << " dz " << hitExt->getResolutionZ() + << " layer = " << layer << std::endl; } - } - catch(DataNotAvailableException &e ) { + } catch (DataNotAvailableException& e) { streamlog_out(DEBUG4) << _FTDPixelHitCollection.c_str() << " collection is unavailable" << std::endl; } - + // Reading in FTD SpacePoint Collection //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ try { - - LCCollection * hitCollection = event->getCollection(_FTDSpacePointCollection.c_str()); - + + LCCollection* hitCollection = event->getCollection(_FTDSpacePointCollection.c_str()); + int nelem = hitCollection->getNumberOfElements(); - + streamlog_out(DEBUG5) << "Number of FTD SpacePoints hits = " << nelem << std::endl; - - for (int ielem=0; ielem(hitCollection->getElementAt(ielem)); - - TrackerHitExtended * hitExt = new TrackerHitExtended( hit ); - + + for (int ielem = 0; ielem < nelem; ++ielem) { + + TrackerHit* hit = dynamic_cast(hitCollection->getElementAt(ielem)); + + TrackerHitExtended* hitExt = new TrackerHitExtended(hit); + // SJA:FIXME: fudge for now by a factor of two and ignore covariance - double point_res_rphi = 2 * sqrt( hit->getCovMatrix()[0] + hit->getCovMatrix()[2] ); - - hitExt->setResolutionRPhi( point_res_rphi ); - - // SJA:FIXME why is this needed? + double point_res_rphi = 2 * sqrt(hit->getCovMatrix()[0] + hit->getCovMatrix()[2]); + + hitExt->setResolutionRPhi(point_res_rphi); + + // SJA:FIXME why is this needed? hitExt->setResolutionZ(0.1); - - // type is now only used in one place where it is set to 0 to reject hits from a fit, set to INT_MAX to try and catch any missuse + + // type is now only used in one place where it is set to 0 to reject hits from a fit, set to INT_MAX to try and + // catch any missuse hitExt->setType(int(INT_MAX)); // det is no longer used set to INT_MAX to try and catch any missuse hitExt->setDet(int(INT_MAX)); - - _allFTDHits.push_back( hitExt ); + + _allFTDHits.push_back(hitExt); mapTrackerHits[hit] = hitExt; - - + // get the layer number unsigned int layer = static_cast(getLayerID(hit)); unsigned int petalIndex = static_cast(getModuleID(hit)); - - if ( _petalBasedFTDWithOverlaps == true ) { - + + if (_petalBasedFTDWithOverlaps == true) { + // as we are dealing with staggered petals we will use 2*nlayers in each directions +/- z - // the layers will follow the even odd numbering of the petals - if ( petalIndex % 2 == 0 ) { - layer = 2*layer; - } - else { - layer = 2*layer + 1; + // the layers will follow the even odd numbering of the petals + if (petalIndex % 2 == 0) { + layer = 2 * layer; + } else { + layer = 2 * layer + 1; } - } - + if (layer >= _nLayersFTD) { - streamlog_out(ERROR) << "FullLDCTracking_MarlinTrk => fatal error in FTD : layer is outside allowed range : " << layer << " number of layers = " << _nLayersFTD << std::endl; + streamlog_out(ERROR) << "FullLDCTracking_MarlinTrk => fatal error in FTD : layer is outside allowed range : " + << layer << " number of layers = " << _nLayersFTD << std::endl; exit(1); } - + double pos[3]; - - for (int i=0; i<3; ++i) { + + for (int i = 0; i < 3; ++i) { pos[i] = hit->getPosition()[i]; - } - - streamlog_out( DEBUG1 ) << " FTD SpacePoint Hit added : @ " << pos[0] << " " << pos[1] << " " << pos[2] << " drphi " << hitExt->getResolutionRPhi() << " dz " << hitExt->getResolutionZ() << " layer = " << layer << std::endl; - - + } + + streamlog_out(DEBUG1) << " FTD SpacePoint Hit added : @ " << pos[0] << " " << pos[1] << " " << pos[2] << " drphi " + << hitExt->getResolutionRPhi() << " dz " << hitExt->getResolutionZ() + << " layer = " << layer << std::endl; } - } - catch(DataNotAvailableException &e ) { + } catch (DataNotAvailableException& e) { streamlog_out(DEBUG4) << _FTDSpacePointCollection.c_str() << " collection is unavailable" << std::endl; } - - - - + try { - - LCCollection *hitCollection = event->getCollection(_SITTrackerHitCollection.c_str()); - + + LCCollection* hitCollection = event->getCollection(_SITTrackerHitCollection.c_str()); + int nelem = hitCollection->getNumberOfElements(); - + streamlog_out(DEBUG5) << "Number of SIT hits = " << nelem << std::endl; - - TrackerHit* trkhit = 0; - TrackerHitPlane* trkhit_P = 0; + + TrackerHit* trkhit = 0; + TrackerHitPlane* trkhit_P = 0; TrackerHitZCylinder* trkhit_C = 0; - + double drphi(NAN); double dz(NAN); - - for (int ielem=0; ielem(hitCollection->getElementAt(ielem)); - + int layer = getLayerID(trkhit); - + if (layer < 0 || (unsigned)layer >= _nLayersSIT) { - streamlog_out(ERROR) << "FullLDCTracking_MarlinTrk => fatal error in SIT : layer is outside allowed range : " << layer << std::endl; + streamlog_out(ERROR) << "FullLDCTracking_MarlinTrk => fatal error in SIT : layer is outside allowed range : " + << layer << std::endl; exit(1); } - + // first check that we have not been given 1D hits by mistake, as they won't work here - if ( BitSet32( trkhit->getType() )[ UTIL::ILDTrkHitTypeBit::ONE_DIMENSIONAL ] ) { - - streamlog_out(ERROR) << "FullLDCTracking_MarlinTrk: SIT Hit cannot be of type UTIL::ILDTrkHitTypeBit::ONE_DIMENSIONAL COMPOSITE SPACEPOINTS must be use instead. \n\n exit(1) called from file " << __FILE__ << " and line " << __LINE__ << std::endl; + if (BitSet32(trkhit->getType())[UTIL::ILDTrkHitTypeBit::ONE_DIMENSIONAL]) { + + streamlog_out(ERROR) + << "FullLDCTracking_MarlinTrk: SIT Hit cannot be of type UTIL::ILDTrkHitTypeBit::ONE_DIMENSIONAL COMPOSITE " + "SPACEPOINTS must be use instead. \n\n exit(1) called from file " + << __FILE__ << " and line " << __LINE__ << std::endl; exit(1); - - } + + } // most likely case: COMPOSITE_SPACEPOINT hits formed from stereo strip hits - else if ( BitSet32( trkhit->getType() )[ UTIL::ILDTrkHitTypeBit::COMPOSITE_SPACEPOINT ] ) { - + else if (BitSet32(trkhit->getType())[UTIL::ILDTrkHitTypeBit::COMPOSITE_SPACEPOINT]) { + // SJA:FIXME: fudge for now by a factor of two and ignore covariance - drphi = 2 * sqrt(trkhit->getCovMatrix()[0] + trkhit->getCovMatrix()[2]); - dz = sqrt(trkhit->getCovMatrix()[5]); - - } + drphi = 2 * sqrt(trkhit->getCovMatrix()[0] + trkhit->getCovMatrix()[2]); + dz = sqrt(trkhit->getCovMatrix()[5]); + + } // or a PIXEL based SIT, using 2D TrackerHitPlane like the VXD above - else if ( ( trkhit_P = dynamic_cast( hitCollection->getElementAt( ielem ) ) ) ) { - - // first we need to check if the measurement vectors are aligned with the global coordinates - Vector3D U(1.0,trkhit_P->getU()[1],trkhit_P->getU()[0],Vector3D::spherical); - Vector3D V(1.0,trkhit_P->getV()[1],trkhit_P->getV()[0],Vector3D::spherical); - Vector3D Z(0.0,0.0,1.0); - + else if ((trkhit_P = dynamic_cast(hitCollection->getElementAt(ielem)))) { + + // first we need to check if the measurement vectors are aligned with the global coordinates + Vector3D U(1.0, trkhit_P->getU()[1], trkhit_P->getU()[0], Vector3D::spherical); + Vector3D V(1.0, trkhit_P->getV()[1], trkhit_P->getV()[0], Vector3D::spherical); + Vector3D Z(0.0, 0.0, 1.0); + const float eps = 1.0e-07; - // V must be the global z axis - if( fabs(1.0 - V.dot(Z)) > eps ) { - streamlog_out(ERROR) << "FullLDCTracking_MarlinTrk: PIXEL SIT Hit measurment vectors V is not equal to the global Z axis. \n\n exit(1) called from file " << __FILE__ << " and line " << __LINE__ << std::endl; + // V must be the global z axis + if (fabs(1.0 - V.dot(Z)) > eps) { + streamlog_out(ERROR) << "FullLDCTracking_MarlinTrk: PIXEL SIT Hit measurment vectors V is not equal to the " + "global Z axis. \n\n exit(1) called from file " + << __FILE__ << " and line " << __LINE__ << std::endl; exit(1); } - + // U must be normal to the global z axis - if( fabs(U.dot(Z)) > eps ) { - streamlog_out(ERROR) << "FullLDCTracking_MarlinTrk: PIXEL SIT Hit measurment vectors U is not in the global X-Y plane. \n\n exit(1) called from file " << __FILE__ << " and line " << __LINE__ << std::endl; + if (fabs(U.dot(Z)) > eps) { + streamlog_out(ERROR) << "FullLDCTracking_MarlinTrk: PIXEL SIT Hit measurment vectors U is not in the global " + "X-Y plane. \n\n exit(1) called from file " + << __FILE__ << " and line " << __LINE__ << std::endl; exit(1); } - + drphi = trkhit_P->getdU(); - dz = trkhit_P->getdV(); - - } - // or a simple cylindrical design, as used in the LOI - else if ( ( trkhit_C = dynamic_cast( hitCollection->getElementAt( ielem ) ) ) ) { - + dz = trkhit_P->getdV(); + + } + // or a simple cylindrical design, as used in the LOI + else if ((trkhit_C = dynamic_cast(hitCollection->getElementAt(ielem)))) { + drphi = trkhit_C->getdRPhi(); - dz = trkhit_C->getdZ(); - - } + dz = trkhit_C->getdZ(); + + } // this would be very unlikely, but who knows ... just an ordinary TrackerHit, which is not a COMPOSITE_SPACEPOINT else { - + // SJA:FIXME: fudge for now by a factor of two and ignore covariance - drphi = 2 * sqrt(trkhit->getCovMatrix()[0] + trkhit->getCovMatrix()[2]); - dz = sqrt(trkhit->getCovMatrix()[5]); - + drphi = 2 * sqrt(trkhit->getCovMatrix()[0] + trkhit->getCovMatrix()[2]); + dz = sqrt(trkhit->getCovMatrix()[5]); } - - // now that the hit type has been established carry on and create a - - TrackerHitExtended * hitExt = new TrackerHitExtended( trkhit ); - + + // now that the hit type has been established carry on and create a + + TrackerHitExtended* hitExt = new TrackerHitExtended(trkhit); + // SJA:FIXME: just use planar res for now hitExt->setResolutionRPhi(drphi); hitExt->setResolutionZ(dz); - - // set type is now only used in one place where it is set to 0 to reject hits from a fit, set to INT_MAX to try and catch any missuse + + // set type is now only used in one place where it is set to 0 to reject hits from a fit, set to INT_MAX to try + // and catch any missuse hitExt->setType(int(INT_MAX)); // det is no longer used set to INT_MAX to try and catch any missuse hitExt->setDet(int(INT_MAX)); - - _allSITHits.push_back( hitExt ); + + _allSITHits.push_back(hitExt); mapTrackerHits[trkhit] = hitExt; - - + double pos[3]; - - for (int i=0; i<3; ++i) { + + for (int i = 0; i < 3; ++i) { pos[i] = trkhit->getPosition()[i]; } - - streamlog_out( DEBUG1 ) << " SIT Hit " << trkhit->id() << " added : @ " << pos[0] << " " << pos[1] << " " << pos[2] << " drphi " << hitExt->getResolutionRPhi() << " dz " << hitExt->getResolutionZ() << " layer = " << layer << std::endl; - + + streamlog_out(DEBUG1) << " SIT Hit " << trkhit->id() << " added : @ " << pos[0] << " " << pos[1] << " " << pos[2] + << " drphi " << hitExt->getResolutionRPhi() << " dz " << hitExt->getResolutionZ() + << " layer = " << layer << std::endl; } - - } catch(DataNotAvailableException &e) { - streamlog_out( DEBUG4 ) << " collection not found : " << _SITTrackerHitCollection.c_str() << std::endl ; + + } catch (DataNotAvailableException& e) { + streamlog_out(DEBUG4) << " collection not found : " << _SITTrackerHitCollection.c_str() << std::endl; } - - + try { - - LCCollection *hitCollection = event->getCollection(_SETTrackerHitCollection.c_str()); - + + LCCollection* hitCollection = event->getCollection(_SETTrackerHitCollection.c_str()); + int nelem = hitCollection->getNumberOfElements(); - + streamlog_out(DEBUG5) << "Number of SET hits = " << nelem << std::endl; - - TrackerHit* trkhit = 0; - TrackerHitPlane* trkhit_P = 0; + + TrackerHit* trkhit = 0; + TrackerHitPlane* trkhit_P = 0; TrackerHitZCylinder* trkhit_C = 0; - + double drphi(NAN); double dz(NAN); - - for (int ielem=0; ielem(hitCollection->getElementAt(ielem)); - + int layer = getLayerID(trkhit); - + if (layer < 0 || (unsigned)layer >= _nLayersSET) { - streamlog_out(ERROR) << "FullLDCTracking_MarlinTrk => fatal error in SET : layer is outside allowed range : " << layer << std::endl; + streamlog_out(ERROR) << "FullLDCTracking_MarlinTrk => fatal error in SET : layer is outside allowed range : " + << layer << std::endl; exit(1); } - + // first check that we have not been given 1D hits by mistake, as they won't work here - if ( BitSet32( trkhit->getType() )[ UTIL::ILDTrkHitTypeBit::ONE_DIMENSIONAL ] ) { - - streamlog_out(ERROR) << "FullLDCTracking_MarlinTrk: SET Hit cannot be of type UTIL::ILDTrkHitTypeBit::ONE_DIMENSIONAL COMPOSITE SPACEPOINTS must be use instead. \n\n exit(1) called from file " << __FILE__ << " and line " << __LINE__ << std::endl; + if (BitSet32(trkhit->getType())[UTIL::ILDTrkHitTypeBit::ONE_DIMENSIONAL]) { + + streamlog_out(ERROR) + << "FullLDCTracking_MarlinTrk: SET Hit cannot be of type UTIL::ILDTrkHitTypeBit::ONE_DIMENSIONAL COMPOSITE " + "SPACEPOINTS must be use instead. \n\n exit(1) called from file " + << __FILE__ << " and line " << __LINE__ << std::endl; exit(1); - + } // most likely case: COMPOSITE_SPACEPOINT hits formed from stereo strip hits - else if ( BitSet32( trkhit->getType() )[ UTIL::ILDTrkHitTypeBit::COMPOSITE_SPACEPOINT ] ) { - + else if (BitSet32(trkhit->getType())[UTIL::ILDTrkHitTypeBit::COMPOSITE_SPACEPOINT]) { + // SJA:FIXME: fudge for now by a factor of two and ignore covariance - drphi = 2 * sqrt(trkhit->getCovMatrix()[0] + trkhit->getCovMatrix()[2]); - dz = sqrt(trkhit->getCovMatrix()[5]); - + drphi = 2 * sqrt(trkhit->getCovMatrix()[0] + trkhit->getCovMatrix()[2]); + dz = sqrt(trkhit->getCovMatrix()[5]); + } // or a PIXEL based SET, using 2D TrackerHitPlane like the VXD above - else if ( ( trkhit_P = dynamic_cast( hitCollection->getElementAt( ielem ) ) ) ) { - + else if ((trkhit_P = dynamic_cast(hitCollection->getElementAt(ielem)))) { + // first we need to check if the measurement vectors are aligned with the global coordinates - Vector3D U(1.0,trkhit_P->getU()[1],trkhit_P->getU()[0],Vector3D::spherical); - Vector3D V(1.0,trkhit_P->getV()[1],trkhit_P->getV()[0],Vector3D::spherical); - Vector3D Z(0.0,0.0,1.0); - + Vector3D U(1.0, trkhit_P->getU()[1], trkhit_P->getU()[0], Vector3D::spherical); + Vector3D V(1.0, trkhit_P->getV()[1], trkhit_P->getV()[0], Vector3D::spherical); + Vector3D Z(0.0, 0.0, 1.0); + const float eps = 1.0e-07; // V must be the global z axis - if( fabs(1.0 - V.dot(Z)) > eps ) { - streamlog_out(ERROR) << "FullLDCTracking_MarlinTrk: PIXEL SET Hit measurment vectors V is not equal to the global Z axis. \n\n exit(1) called from file " << __FILE__ << " and line " << __LINE__ << std::endl; + if (fabs(1.0 - V.dot(Z)) > eps) { + streamlog_out(ERROR) << "FullLDCTracking_MarlinTrk: PIXEL SET Hit measurment vectors V is not equal to the " + "global Z axis. \n\n exit(1) called from file " + << __FILE__ << " and line " << __LINE__ << std::endl; exit(1); } - + // U must be normal to the global z axis - if( fabs(U.dot(Z)) > eps ) { - streamlog_out(ERROR) << "FullLDCTracking_MarlinTrk: PIXEL SET Hit measurment vectors U is not in the global X-Y plane. \n\n exit(1) called from file " << __FILE__ << " and line " << __LINE__ << std::endl; + if (fabs(U.dot(Z)) > eps) { + streamlog_out(ERROR) << "FullLDCTracking_MarlinTrk: PIXEL SET Hit measurment vectors U is not in the global " + "X-Y plane. \n\n exit(1) called from file " + << __FILE__ << " and line " << __LINE__ << std::endl; exit(1); } - + drphi = trkhit_P->getdU(); - dz = trkhit_P->getdV(); - + dz = trkhit_P->getdV(); + } // or a simple cylindrical design, as used in the LOI - else if ( ( trkhit_C = dynamic_cast( hitCollection->getElementAt( ielem ) ) ) ) { - + else if ((trkhit_C = dynamic_cast(hitCollection->getElementAt(ielem)))) { + drphi = trkhit_C->getdRPhi(); - dz = trkhit_C->getdZ(); - + dz = trkhit_C->getdZ(); + } // this would be very unlikely, but who knows ... just an ordinary TrackerHit, which is not a COMPOSITE_SPACEPOINT else { - + // SJA:FIXME: fudge for now by a factor of two and ignore covariance - drphi = 2 * sqrt(trkhit->getCovMatrix()[0] + trkhit->getCovMatrix()[2]); - dz = sqrt(trkhit->getCovMatrix()[5]); - + drphi = 2 * sqrt(trkhit->getCovMatrix()[0] + trkhit->getCovMatrix()[2]); + dz = sqrt(trkhit->getCovMatrix()[5]); } - + // now that the hit type has been established carry on and create a - - TrackerHitExtended * hitExt = new TrackerHitExtended( trkhit ); - + + TrackerHitExtended* hitExt = new TrackerHitExtended(trkhit); + // SJA:FIXME: just use planar res for now hitExt->setResolutionRPhi(drphi); hitExt->setResolutionZ(dz); - - // set type is now only used in one place where it is set to 0 to reject hits from a fit, set to INT_MAX to try and catch any missuse + + // set type is now only used in one place where it is set to 0 to reject hits from a fit, set to INT_MAX to try + // and catch any missuse hitExt->setType(int(INT_MAX)); // det is no longer used set to INT_MAX to try and catch any missuse hitExt->setDet(int(INT_MAX)); - - _allSETHits.push_back( hitExt ); + + _allSETHits.push_back(hitExt); mapTrackerHits[trkhit] = hitExt; - - + double pos[3]; - - for (int i=0; i<3; ++i) { + + for (int i = 0; i < 3; ++i) { pos[i] = trkhit->getPosition()[i]; } - - streamlog_out( DEBUG1 ) << " SET Hit " << trkhit->id() << " added : @ " << pos[0] << " " << pos[1] << " " << pos[2] << " drphi " << hitExt->getResolutionRPhi() << " dz " << hitExt->getResolutionZ() << " layer = " << layer << std::endl; - + + streamlog_out(DEBUG1) << " SET Hit " << trkhit->id() << " added : @ " << pos[0] << " " << pos[1] << " " << pos[2] + << " drphi " << hitExt->getResolutionRPhi() << " dz " << hitExt->getResolutionZ() + << " layer = " << layer << std::endl; } - - } catch(DataNotAvailableException &e) { - streamlog_out( DEBUG4 ) << " collection not found : " << _SETTrackerHitCollection.c_str() << std::endl ; + + } catch (DataNotAvailableException& e) { + streamlog_out(DEBUG4) << " collection not found : " << _SETTrackerHitCollection.c_str() << std::endl; } - // Reading VTX Hits try { - LCCollection * col = event->getCollection(_VTXTrackerHitCollection.c_str()); - + LCCollection* col = event->getCollection(_VTXTrackerHitCollection.c_str()); + int nelem = col->getNumberOfElements(); - + streamlog_out(DEBUG5) << "Number of VXD hits = " << nelem << std::endl; - - for (int ielem=0;ielem(col->getElementAt(ielem)); - TrackerHitExtended * hitExt = new TrackerHitExtended(trkhit); - + + for (int ielem = 0; ielem < nelem; ++ielem) { + TrackerHitPlane* trkhit = dynamic_cast(col->getElementAt(ielem)); + TrackerHitExtended* hitExt = new TrackerHitExtended(trkhit); + // SJA:FIXME: just use planar res for now hitExt->setResolutionRPhi(trkhit->getdU()); hitExt->setResolutionZ(trkhit->getdV()); - + // type and det are no longer used, set to INT_MAX to try and catch any missuse - hitExt->setType(int(INT_MAX)); + hitExt->setType(int(INT_MAX)); hitExt->setDet(int(INT_MAX)); - _allVTXHits.push_back( hitExt ); + _allVTXHits.push_back(hitExt); mapTrackerHits[trkhit] = hitExt; - + double pos[3]; - - for (int i=0; i<3; ++i) { + + for (int i = 0; i < 3; ++i) { pos[i] = trkhit->getPosition()[i]; } - + int layer = getLayerID(trkhit); - - streamlog_out( DEBUG1 ) << " VXD Hit " << trkhit->id() << " added : @ " << pos[0] << " " << pos[1] << " " << pos[2] << " drphi " << hitExt->getResolutionRPhi() << " dz " << hitExt->getResolutionZ() << " layer = " << layer << std::endl; - - + + streamlog_out(DEBUG1) << " VXD Hit " << trkhit->id() << " added : @ " << pos[0] << " " << pos[1] << " " << pos[2] + << " drphi " << hitExt->getResolutionRPhi() << " dz " << hitExt->getResolutionZ() + << " layer = " << layer << std::endl; } - - - } - catch( DataNotAvailableException &e ) { + + } catch (DataNotAvailableException& e) { streamlog_out(DEBUG4) << _VTXTrackerHitCollection.c_str() << " collection is unavailable" << std::endl; } - - + // Reading TPC Tracks try { - LCCollection * col = event->getCollection(_TPCTrackCollection.c_str()); + LCCollection* col = event->getCollection(_TPCTrackCollection.c_str()); int nelem = col->getNumberOfElements(); streamlog_out(DEBUG5) << std::endl; streamlog_out(DEBUG5) << "Number of TPC Tracks = " << nelem << " in " << _TPCTrackCollection.c_str() << std::endl; - streamlog_out(DEBUG5) << " Trk ID p D0 Z0 Px Py Pz ntpc ndf Chi2/ndf nlinkedTracks" << std::endl; + streamlog_out(DEBUG5) + << " Trk ID p D0 Z0 Px Py Pz ntpc ndf Chi2/ndf nlinkedTracks" + << std::endl; // " 0 1.111 0.059 0.022 -0.54 0.61 -0.45 0.185 - - for (int iTrk=0; iTrk(col->getElementAt(iTrk) ); - + + for (int iTrk = 0; iTrk < nelem; ++iTrk) { + + Track* tpcTrack = dynamic_cast(col->getElementAt(iTrk)); + TrackerHitVec hitVec = tpcTrack->getTrackerHits(); int nHits = int(hitVec.size()); - - streamlog_out(DEBUG5) << toString( iTrk, tpcTrack , _bField ) << std::endl; - - TrackExtended * trackExt = new TrackExtended( tpcTrack ); - + + streamlog_out(DEBUG5) << toString(iTrk, tpcTrack, _bField) << std::endl; + + TrackExtended* trackExt = new TrackExtended(tpcTrack); + trackExt->setOmega(tpcTrack->getOmega()); trackExt->setTanLambda(tpcTrack->getTanLambda()); trackExt->setPhi(tpcTrack->getPhi()); @@ -1485,56 +1274,51 @@ void FullLDCTracking_MarlinTrk::prepareVectors(LCEvent * event ) { // param[2] = tpcTrack->getPhi(); // param[3] = tpcTrack->getD0(); // param[4] = tpcTrack->getZ0(); - - + const FloatVec Cov = tpcTrack->getCovMatrix(); int NC = int(Cov.size()); - for (int ic=0;icsetCovMatrix(cov); trackExt->setNDF(tpcTrack->getNdf()); - trackExt->setChi2(tpcTrack->getChi2()); - - - - for (int iHit=0;iHitsetTrackExtended( trackExt ); - trackExt->addTrackerHitExtended( hitExt ); - } - - - - _allTPCTracks.push_back( trackExt ); - } - } - catch ( DataNotAvailableException &e) { + trackExt->setChi2(tpcTrack->getChi2()); + + for (int iHit = 0; iHit < nHits; ++iHit) { + TrackerHit* hit = hitVec[iHit]; + TrackerHitExtended* hitExt = mapTrackerHits[hit]; + hitExt->setTrackExtended(trackExt); + trackExt->addTrackerHitExtended(hitExt); + } + + _allTPCTracks.push_back(trackExt); + } + } catch (DataNotAvailableException& e) { streamlog_out(DEBUG5) << _TPCTrackCollection.c_str() << " collection is unavailable" << std::endl; } - + // Reading Si Tracks try { - LCCollection * col = event->getCollection(_SiTrackCollection.c_str()); + LCCollection* col = event->getCollection(_SiTrackCollection.c_str()); int nelem = col->getNumberOfElements(); streamlog_out(DEBUG5) << std::endl; streamlog_out(DEBUG5) << "Number of Si Tracks = " << nelem << std::endl; - streamlog_out(DEBUG5) << " Trk ID p D0 Z0 Px Py Pz hitsSi ndf Chi2/ndf" << std::endl; - - for (int iTrk=0; iTrk(col->getElementAt(iTrk)); - - double prob = ( siTrack->getNdf() > 0 ? gsl_cdf_chisq_Q( siTrack->getChi2() , (double) siTrack->getNdf() ) : 0. ) ; - - if( prob < _minChi2ProbForSiliconTracks ) { - streamlog_out(DEBUG5) << "Si Tracks " << siTrack << " id : " << siTrack->id() << " rejected with prob " << prob << " < " << _minChi2ProbForSiliconTracks << std::endl; + streamlog_out(DEBUG5) + << " Trk ID p D0 Z0 Px Py Pz hitsSi ndf Chi2/ndf" << std::endl; + + for (int iTrk = 0; iTrk < nelem; ++iTrk) { + Track* siTrack = dynamic_cast(col->getElementAt(iTrk)); + + double prob = (siTrack->getNdf() > 0 ? gsl_cdf_chisq_Q(siTrack->getChi2(), (double)siTrack->getNdf()) : 0.); + + if (prob < _minChi2ProbForSiliconTracks) { + streamlog_out(DEBUG5) << "Si Tracks " << siTrack << " id : " << siTrack->id() << " rejected with prob " << prob + << " < " << _minChi2ProbForSiliconTracks << std::endl; continue; } - - TrackExtended * trackExt = new TrackExtended( siTrack ); + + TrackExtended* trackExt = new TrackExtended(siTrack); TrackerHitVec hitVec = siTrack->getTrackerHits(); int nHits = int(hitVec.size()); trackExt->setOmega(siTrack->getOmega()); @@ -1549,506 +1333,497 @@ void FullLDCTracking_MarlinTrk::prepareVectors(LCEvent * event ) { // param[2] = siTrack->getPhi(); // param[3] = siTrack->getD0(); // param[4] = siTrack->getZ0(); - - - + const FloatVec Cov = siTrack->getCovMatrix(); int NC = int(Cov.size()); - for (int ic=0;icsetCovMatrix(cov); trackExt->setNDF(siTrack->getNdf()); - trackExt->setChi2(siTrack->getChi2()); + trackExt->setChi2(siTrack->getChi2()); char strg[200]; HelixClass helixSi; - for (int iHit=0;iHitsetTrackExtended( trackExt ); - - trackExt->addTrackerHitExtended( hitExt ); + for (int iHit = 0; iHit < nHits; ++iHit) { + TrackerHit* hit = hitVec[iHit]; + TrackerHitExtended* hitExt = mapTrackerHits[hit]; + hitExt->setTrackExtended(trackExt); + + trackExt->addTrackerHitExtended(hitExt); } - - + float d0Si = trackExt->getD0(); float z0Si = trackExt->getZ0(); float omegaSi = trackExt->getOmega(); float phi0Si = trackExt->getPhi(); float tanLSi = trackExt->getTanLambda(); - helixSi.Initialize_Canonical(phi0Si,d0Si,z0Si,omegaSi,tanLSi,_bField); + helixSi.Initialize_Canonical(phi0Si, d0Si, z0Si, omegaSi, tanLSi, _bField); float pxSi = helixSi.getMomentum()[0]; float pySi = helixSi.getMomentum()[1]; float pzSi = helixSi.getMomentum()[2]; - const float pTot = sqrt(pxSi*pxSi+pySi*pySi+pzSi*pzSi); + const float pTot = sqrt(pxSi * pxSi + pySi * pySi + pzSi * pzSi); const int ndfSi = trackExt->getNDF(); - float Chi2Si = trackExt->getChi2()/float(trackExt->getNDF()); - sprintf(strg,"%3i %5i %9.3f %9.3f %9.3f %7.2f %7.2f %7.2f %4i %4i %8.3f",iTrk, siTrack->id(), - pTot, d0Si,z0Si,pxSi,pySi,pzSi,nHits, ndfSi, Chi2Si); + float Chi2Si = trackExt->getChi2() / float(trackExt->getNDF()); + sprintf(strg, "%3i %5i %9.3f %9.3f %9.3f %7.2f %7.2f %7.2f %4i %4i %8.3f", iTrk, siTrack->id(), pTot, d0Si, + z0Si, pxSi, pySi, pzSi, nHits, ndfSi, Chi2Si); streamlog_out(DEBUG5) << strg << std::endl; - - if(nHits>0){ - _allSiTracks.push_back( trackExt ); - }else{ + + if (nHits > 0) { + _allSiTracks.push_back(trackExt); + } else { delete trackExt; } } - + streamlog_out(DEBUG5) << std::endl; - } - catch ( DataNotAvailableException &e) { + } catch (DataNotAvailableException& e) { streamlog_out(DEBUG5) << _SiTrackCollection.c_str() << " collection is unavailable" << std::endl; } - - - } -void FullLDCTracking_MarlinTrk::CleanUp(){ - - int nNonCombTpc = int(_allNonCombinedTPCTracks.size()); - for (int i=0;igetGroupTracks(); +void FullLDCTracking_MarlinTrk::CleanUp() { + + int nNonCombTpc = int(_allNonCombinedTPCTracks.size()); + for (int i = 0; i < nNonCombTpc; ++i) { + TrackExtended* trkExt = _allNonCombinedTPCTracks[i]; + GroupTracks* group = trkExt->getGroupTracks(); delete group; } _allNonCombinedTPCTracks.clear(); - - int nNonCombSi = int(_allNonCombinedSiTracks.size()); - for (int i=0;igetGroupTracks(); + + int nNonCombSi = int(_allNonCombinedSiTracks.size()); + for (int i = 0; i < nNonCombSi; ++i) { + TrackExtended* trkExt = _allNonCombinedSiTracks[i]; + GroupTracks* group = trkExt->getGroupTracks(); delete group; } _allNonCombinedSiTracks.clear(); - + int nSITHits = int(_allSITHits.size()); - for (int i=0;igetGroupTracks(); + for (int i = 0; i < nCombTrk; ++i) { + TrackExtended* trkExt = _allCombinedTracks[i]; + GroupTracks* group = trkExt->getGroupTracks(); delete group; - delete trkExt; + delete trkExt; } _allCombinedTracks.clear(); - + // int nImplTrk = int(_trkImplVec.size()); // for (int i=0;igetTrack(), _bField ) << std::endl ; - streamlog_out(DEBUG2) << " to si trk " << toString( iSi, siTrackExt->getTrack(), _bField ) << std::endl ; - - float dOmega = CompareTrkII(siTrackExt,tpcTrackExt,_d0CutForMerging,_z0CutForMerging,iComp,angle); - - if ( (dOmega<_dOmegaForMerging) && (angle<_angleForMerging) && !VetoMerge(tpcTrackExt,siTrackExt)) { - - streamlog_out(DEBUG2) << " call CombineTracks for tpc trk " << tpcTrackExt << " si trk " << siTrackExt << std::endl; - - TrackExtended *combinedTrack = CombineTracks(tpcTrackExt,siTrackExt,_maxAllowedPercentageOfOutliersForTrackCombination, false); - + streamlog_out(DEBUG2) << " compare tpc trk " << toString(iTPC, tpcTrackExt->getTrack(), _bField) << std::endl; + streamlog_out(DEBUG2) << " to si trk " << toString(iSi, siTrackExt->getTrack(), _bField) << std::endl; + + float dOmega = CompareTrkII(siTrackExt, tpcTrackExt, _d0CutForMerging, _z0CutForMerging, iComp, angle); + + if ((dOmega < _dOmegaForMerging) && (angle < _angleForMerging) && !VetoMerge(tpcTrackExt, siTrackExt)) { + + streamlog_out(DEBUG2) << " call CombineTracks for tpc trk " << tpcTrackExt << " si trk " << siTrackExt + << std::endl; + + TrackExtended* combinedTrack = + CombineTracks(tpcTrackExt, siTrackExt, _maxAllowedPercentageOfOutliersForTrackCombination, false); + streamlog_out(DEBUG2) << " combinedTrack returns " << combinedTrack << std::endl; - - if (combinedTrack != NULL) { + if (combinedTrack != NULL) { - _allCombinedTracks.push_back( combinedTrack ); + _allCombinedTracks.push_back(combinedTrack); _candidateCombinedTracks.insert(tpcTrackExt); _candidateCombinedTracks.insert(siTrackExt); - // streamlog_out(DEBUG3) << " combinedTrack successfully added to _allCombinedTracks : " << toString( 0,combinedTrack->getTrack(), _bField ) << std::endl; - streamlog_out(DEBUG3) << " *** combinedTrack successfully added to _allCombinedTracks : tpc " << iTPC << " si " << iSi << std::endl; - - if (_debug >= 3 ) { + // streamlog_out(DEBUG3) << " combinedTrack successfully added to _allCombinedTracks : " << toString( + // 0,combinedTrack->getTrack(), _bField ) << std::endl; + streamlog_out(DEBUG3) << " *** combinedTrack successfully added to _allCombinedTracks : tpc " << iTPC + << " si " << iSi << std::endl; + + if (_debug >= 3) { int iopt = 1; - PrintOutMerging(tpcTrackExt,siTrackExt,iopt); + PrintOutMerging(tpcTrackExt, siTrackExt, iopt); } - }else{ - if (_debug >= 3 ) { + } else { + if (_debug >= 3) { int iopt = 6; - PrintOutMerging(tpcTrackExt,siTrackExt,iopt); + PrintOutMerging(tpcTrackExt, siTrackExt, iopt); } } - } - else { - if (_debug >= 3 ) { + } else { + if (_debug >= 3) { int iopt = 6; - PrintOutMerging(tpcTrackExt,siTrackExt,iopt); + PrintOutMerging(tpcTrackExt, siTrackExt, iopt); } } } } - - } - /* - + All Si and TPC tracks which have been merged using MergeTPCandSiTracks are excluded from this search. - - The remaining TPC tracks and Silicon tracks will be tested using CompareTrkIII - CompareTrkIII does the following - + The remaining TPC tracks and Silicon tracks will be tested using CompareTrkIII + + CompareTrkIII does the following + i) significance d0 < d0Cut ii) significance z0 < z0Cut iii) pdot > 0.999 - + if above three cuts are passed return: - + the significance dAngle (return by reference) and the significance dOmega - if CompareTrkIII and the cuts on the significance of dOmega and angle succecede try and full fit of the hits using CombineTracks - assuming that the merger was not vetoed VetoMerge - i.e. if the momentum of either track is less than 2.5 GeV - and there is no overlapping of the segments - - if this is successful the track is added to _allCombinedTracks and the TPC and Si Segements are added to _candidateCombinedTracks - + if CompareTrkIII and the cuts on the significance of dOmega and angle succecede try and full fit of the hits using + CombineTracks assuming that the merger was not vetoed VetoMerge i.e. if the momentum of either track is less than 2.5 + GeV and there is no overlapping of the segments + + if this is successful the track is added to _allCombinedTracks and the TPC and Si Segements are added to + _candidateCombinedTracks + */ void FullLDCTracking_MarlinTrk::MergeTPCandSiTracksII() { - + int nTPCTracks = int(_allTPCTracks.size()); - int nSiTracks = int(_allSiTracks.size()); - - streamlog_out( DEBUG3 ) << " MergeTPCandSiTracksII called nTPC tracks " << nTPCTracks << " - nSiTracks " << nSiTracks << std::endl ; + int nSiTracks = int(_allSiTracks.size()); + + streamlog_out(DEBUG3) << " MergeTPCandSiTracksII called nTPC tracks " << nTPCTracks << " - nSiTracks " << nSiTracks + << std::endl; + + for (int iTPC = 0; iTPC < nTPCTracks; ++iTPC) { - for (int iTPC=0;iTPC= 3 ) { + if (_debug >= 3) { int iopt = 1; - PrintOutMerging(tpcTrackExt,siTrackExt,iopt); + PrintOutMerging(tpcTrackExt, siTrackExt, iopt); } - }else{ - if (_debug >= 3 ) { + } else { + if (_debug >= 3) { int iopt = 6; - PrintOutMerging(tpcTrackExt,siTrackExt,iopt); + PrintOutMerging(tpcTrackExt, siTrackExt, iopt); } } - } - else { - if (_debug >= 3 ) { + } else { + if (_debug >= 3) { int iopt = 6; - PrintOutMerging(tpcTrackExt,siTrackExt,iopt); + PrintOutMerging(tpcTrackExt, siTrackExt, iopt); } } } } } +// if testCombinationOnly is true then hits will not be assigned to the tracks +TrackExtended* FullLDCTracking_MarlinTrk::CombineTracks(TrackExtended* tpcTrack, TrackExtended* siTrack, + float maxAllowedOutliers, bool testCombinationOnly) { + + TrackExtended* OutputTrack = NULL; -// if testCombinationOnly is true then hits will not be assigned to the tracks -TrackExtended * FullLDCTracking_MarlinTrk::CombineTracks(TrackExtended * tpcTrack, TrackExtended * siTrack, float maxAllowedOutliers, bool testCombinationOnly) { - - TrackExtended * OutputTrack = NULL; - TrackerHitExtendedVec siHitVec = siTrack->getTrackerHitExtendedVec(); TrackerHitExtendedVec tpcHitVec = tpcTrack->getTrackerHitExtendedVec(); - + int nSiHits = int(siHitVec.size()); int nTPCHits = int(tpcHitVec.size()); int nHits = nTPCHits + nSiHits; - - //std::cout << "FullLDCTracking_MarlinTrk::CombineTracks nSiHits = " << nSiHits << std::endl; - //std::cout << "FullLDCTracking_MarlinTrk::CombineTracks nTPCHits = " << nTPCHits << std::endl; - + + // std::cout << "FullLDCTracking_MarlinTrk::CombineTracks nSiHits = " << nSiHits << std::endl; + // std::cout << "FullLDCTracking_MarlinTrk::CombineTracks nTPCHits = " << nTPCHits << std::endl; + EVENT::TrackerHitVec trkHits; trkHits.reserve(nHits); - - for (int ih=0;ihgetTrackerHit(); - if(trkHit) { - trkHits.push_back(trkHit); - } - else{ - throw EVENT::Exception( std::string("FullLDCTracking_MarlinTrk::CombineTracks: TrackerHit pointer == NULL ") ) ; - } - } - - for (int ih=0;ihgetTrackerHit(); - if(trkHit) { - trkHits.push_back(trkHit); + + for (int ih = 0; ih < nSiHits; ++ih) { + TrackerHit* trkHit = siHitVec[ih]->getTrackerHit(); + if (trkHit) { + trkHits.push_back(trkHit); + } else { + throw EVENT::Exception(std::string("FullLDCTracking_MarlinTrk::CombineTracks: TrackerHit pointer == NULL ")); } - else{ - throw EVENT::Exception( std::string("FullLDCTracking_MarlinTrk::CombineTracks: TrackerHit pointer == NULL ") ) ; + } + + for (int ih = 0; ih < nTPCHits; ++ih) { + + TrackerHit* trkHit = tpcHitVec[ih]->getTrackerHit(); + if (trkHit) { + trkHits.push_back(trkHit); + } else { + throw EVENT::Exception(std::string("FullLDCTracking_MarlinTrk::CombineTracks: TrackerHit pointer == NULL ")); } - } - + } + double chi2_D; int ndf; - - if( trkHits.size() < 3 ) { - - return 0 ; - + + if (trkHits.size() < 3) { + + return 0; } - + streamlog_out(DEBUG2) << "FullLDCTracking_MarlinTrk::CombineTracks: Sorting Hits " << trkHits.size() << std::endl; - - std::vector< std::pair > r2_values; + + std::vector> r2_values; r2_values.reserve(trkHits.size()); - - for (TrackerHitVec::iterator it=trkHits.begin(); it!=trkHits.end(); ++it) { + + for (TrackerHitVec::iterator it = trkHits.begin(); it != trkHits.end(); ++it) { EVENT::TrackerHit* h = *it; - float r2 = h->getPosition()[0]*h->getPosition()[0]+h->getPosition()[1]*h->getPosition()[1]; + float r2 = h->getPosition()[0] * h->getPosition()[0] + h->getPosition()[1] * h->getPosition()[1]; r2_values.push_back(std::make_pair(r2, *it)); } - - sort(r2_values.begin(),r2_values.end()); - + + sort(r2_values.begin(), r2_values.end()); + trkHits.clear(); trkHits.reserve(r2_values.size()); - - for (std::vector< std::pair >::iterator it=r2_values.begin(); it!=r2_values.end(); ++it) { + + for (std::vector>::iterator it = r2_values.begin(); it != r2_values.end(); + ++it) { trkHits.push_back(it->second); } - - streamlog_out(DEBUG2) << "FullLDCTracking_MarlinTrk::CombineTracks: Start Fitting: AddHits: number of hits to fit " << trkHits.size() << std::endl; - + streamlog_out(DEBUG2) << "FullLDCTracking_MarlinTrk::CombineTracks: Start Fitting: AddHits: number of hits to fit " + << trkHits.size() << std::endl; + std::unique_ptr marlin_trk_autop(_trksystem->createTrack()); MarlinTrk::IMarlinTrack& marlin_trk = *marlin_trk_autop.get(); - - IMPL::TrackStateImpl pre_fit ; + + IMPL::TrackStateImpl pre_fit; int error = IMarlinTrack::success; - + pre_fit = *(tpcTrack->getTrack()->getTrackState(EVENT::TrackState::AtLastHit)); - - + // setup initial dummy covariance matrix EVENT::FloatVec covMatrix; covMatrix.resize(15); - - for (unsigned icov = 0; icov _chi2FitCut ) { - - streamlog_out(DEBUG2) << "FullLDCTracking_MarlinTrk::CombineTracks: track fail Chi2 cut of " << _chi2FitCut << " chi2 of track = " << chi2Fit << std::endl; + + float chi2Fit = chi2_D / float(ndf); + + if (chi2Fit > _chi2FitCut) { + + streamlog_out(DEBUG2) << "FullLDCTracking_MarlinTrk::CombineTracks: track fail Chi2 cut of " << _chi2FitCut + << " chi2 of track = " << chi2Fit << std::endl; return 0; - } - - + streamlog_out(DEBUG2) << "FullLDCTracking_MarlinTrk::CombineTracks: Check for outliers " << std::endl; - - std::vector > outliers ; + + std::vector> outliers; marlin_trk.getOutliers(outliers); - - float outlier_pct = outliers.size()/float(trkHits.size()) ; - - - if ( outlier_pct > maxAllowedOutliers) { - - streamlog_out(DEBUG2) << "FullLDCTracking_MarlinTrk::CombineTracks: percentage of outliers " << outlier_pct << " is greater than cut maximum: " << maxAllowedOutliers << std::endl; - return 0; + float outlier_pct = outliers.size() / float(trkHits.size()); + + if (outlier_pct > maxAllowedOutliers) { + + streamlog_out(DEBUG2) << "FullLDCTracking_MarlinTrk::CombineTracks: percentage of outliers " << outlier_pct + << " is greater than cut maximum: " << maxAllowedOutliers << std::endl; + return 0; } - // sort the hits into outliers from TPC and Silicon as we will reject the combination if more that 2 Si hits get rejected ... - + // sort the hits into outliers from TPC and Silicon as we will reject the combination if more that 2 Si hits get + // rejected ... + std::vector siHitInFit; std::vector siOutliers; std::vector tpcHitInFit; std::vector tpcOutliers; - - for (int i=0;igetTrackerHit()); - + // add the raw hits ... const LCObjectVec rawHits = siHitVec[i]->getTrackerHit()->getRawHits(); - - if ( rawHits.empty() == false) { - for (unsigned ihit=0; ihit < rawHits.size(); ++ihit) { + + if (rawHits.empty() == false) { + for (unsigned ihit = 0; ihit < rawHits.size(); ++ihit) { hits.push_back(rawHits[ihit]); } } - + // now double loop over the outliers and the hits assosiated with this TrackerHitExtended and compare - for ( unsigned ohit = 0; ohit < outliers.size(); ++ohit) { + for (unsigned ohit = 0; ohit < outliers.size(); ++ohit) { for (unsigned ihit = 0; ihit < hits.size(); ++ihit) { - + // compare outlier pointer to TrackerHit pointer - if( outliers[ohit].first == hits[ihit] ){ + if (outliers[ohit].first == hits[ihit]) { // silicon outlier found so add the TrackerHitExtended to the list of outliers hit_is_outlier = true; siOutliers.push_back(siHitVec[i]); @@ -2059,62 +1834,60 @@ TrackExtended * FullLDCTracking_MarlinTrk::CombineTracks(TrackExtended * tpcTrac } } } - - if( hit_is_outlier == false ){ + + if (hit_is_outlier == false) { // add the TrackerHitExtended to the list of silicon hits used in the fit siHitInFit.push_back(siHitVec[i]); } - } - + // more simple as TPC hits are never composite - for (int i=0;igetTrackerHit() ){ + if (outliers[ihit].first == tpcHitVec[i]->getTrackerHit()) { // tpc outlier found so add the TrackerHitExtended to the list of outliers hit_is_outlier = true; tpcOutliers.push_back(tpcHitVec[i]); break; } } - - if( hit_is_outlier == false ){ + + if (hit_is_outlier == false) { // add the TrackerHitExtended to the list of tpc hits used in the fit tpcHitInFit.push_back(tpcHitVec[i]); } - } - - streamlog_out(DEBUG2) << "FullLDCTracking_MarlinTrk::CombineTracks: Check for Silicon Hit rejections ... " << std::endl; - - if ( (int)siOutliers.size() > _maxAllowedSiHitRejectionsForTrackCombination ) { - - streamlog_out(DEBUG2) << "FullLDCTracking_MarlinTrk::CombineTracks: Fit rejects " << siOutliers.size() << " silicon hits : max allowed rejections = " << _maxAllowedSiHitRejectionsForTrackCombination << " : Combination rejected " << std::endl; + streamlog_out(DEBUG2) << "FullLDCTracking_MarlinTrk::CombineTracks: Check for Silicon Hit rejections ... " + << std::endl; + + if ((int)siOutliers.size() > _maxAllowedSiHitRejectionsForTrackCombination) { + + streamlog_out(DEBUG2) << "FullLDCTracking_MarlinTrk::CombineTracks: Fit rejects " << siOutliers.size() + << " silicon hits : max allowed rejections = " + << _maxAllowedSiHitRejectionsForTrackCombination << " : Combination rejected " << std::endl; return 0; - } - float omega = trkState.getOmega(); float tanlambda = trkState.getTanLambda(); float phi0 = trkState.getPhi(); float d0 = trkState.getD0(); float z0 = trkState.getZ0(); - + OutputTrack = new TrackExtended(); - GroupTracks * group = new GroupTracks(); + GroupTracks* group = new GroupTracks(); OutputTrack->setGroupTracks(group); - + group->addTrackExtended(siTrack); group->addTrackExtended(tpcTrack); - + // note OutputTrack which is of type TrackExtended, only takes fits set for ref point = 0,0,0 OutputTrack->setOmega(omega); OutputTrack->setTanLambda(tanlambda); @@ -2123,141 +1896,136 @@ TrackExtended * FullLDCTracking_MarlinTrk::CombineTracks(TrackExtended * tpcTrac OutputTrack->setD0(d0); OutputTrack->setChi2(chi2_D); OutputTrack->setNDF(ndf); - + float cov[15]; - - for (int i = 0 ; i<15 ; ++i) { + + for (int i = 0; i < 15; ++i) { cov[i] = trkState.getCovMatrix().operator[](i); } - + OutputTrack->setCovMatrix(cov); - + // if this is not just a test of the combination add the hits to the combined track - if ( testCombinationOnly == false ) { + if (testCombinationOnly == false) { - for (unsigned ihit=0; ihitaddTrackerHitExtended(hitExt); hitExt->setUsedInFit(true); } - - for (unsigned ihit=0; ihitaddTrackerHitExtended(hitExt); hitExt->setUsedInFit(false); } - for (unsigned ihit=0; ihitaddTrackerHitExtended(hitExt); hitExt->setUsedInFit(true); } - - for (unsigned ihit=0; ihitaddTrackerHitExtended(hitExt); hitExt->setUsedInFit(false); } - } - - - streamlog_out(DEBUG2) << "FullLDCTracking_MarlinTrk::CombineTracks: merged track created " << OutputTrack << " with " << OutputTrack->getTrackerHitExtendedVec().size() << " hits, nhits tpc " << nTPCHits << " nSiHits " << nSiHits << ", testCombinationOnly = " << testCombinationOnly << std::endl; - + + streamlog_out(DEBUG2) << "FullLDCTracking_MarlinTrk::CombineTracks: merged track created " << OutputTrack << " with " + << OutputTrack->getTrackerHitExtendedVec().size() << " hits, nhits tpc " << nTPCHits + << " nSiHits " << nSiHits << ", testCombinationOnly = " << testCombinationOnly << std::endl; + return OutputTrack; - } +void FullLDCTracking_MarlinTrk::SortingTrackHitPairs(TrackHitPairVec& trackHitPairVec) { - -void FullLDCTracking_MarlinTrk::SortingTrackHitPairs(TrackHitPairVec & trackHitPairVec) { - int sizeOfVector = int(trackHitPairVec.size()); - TrackHitPair *one,*two,*Temp; - - for (int i = 0 ; i < sizeOfVector-1; i++) - for (int j = 0; j < sizeOfVector-i-1; j++) { + TrackHitPair *one, *two, *Temp; + + for (int i = 0; i < sizeOfVector - 1; i++) + for (int j = 0; j < sizeOfVector - i - 1; j++) { one = trackHitPairVec[j]; - two = trackHitPairVec[j+1]; + two = trackHitPairVec[j + 1]; float oneQ = one->getDistance(); float twoQ = two->getDistance(); - if( oneQ > twoQ ) { + if (oneQ > twoQ) { Temp = trackHitPairVec[j]; - trackHitPairVec[j] = trackHitPairVec[j+1]; - trackHitPairVec[j+1] = Temp; + trackHitPairVec[j] = trackHitPairVec[j + 1]; + trackHitPairVec[j + 1] = Temp; } - } - - + } } /* - + Sorts all tracks in the vector by Chi2/NDF - + */ -void FullLDCTracking_MarlinTrk::Sorting(TrackExtendedVec & trackVec) { - +void FullLDCTracking_MarlinTrk::Sorting(TrackExtendedVec& trackVec) { + int sizeOfVector = int(trackVec.size()); - TrackExtended *one,*two,*Temp; - - for (int i = 0 ; i < sizeOfVector-1; i++) - for (int j = 0; j < sizeOfVector-i-1; j++) { + TrackExtended *one, *two, *Temp; + + for (int i = 0; i < sizeOfVector - 1; i++) + for (int j = 0; j < sizeOfVector - i - 1; j++) { one = trackVec[j]; - two = trackVec[j+1]; - float oneQ = one->getChi2()/float(one->getNDF()); - float twoQ = two->getChi2()/float(two->getNDF()); - if( oneQ > twoQ ) { + two = trackVec[j + 1]; + float oneQ = one->getChi2() / float(one->getNDF()); + float twoQ = two->getChi2() / float(two->getNDF()); + if (oneQ > twoQ) { Temp = trackVec[j]; - trackVec[j] = trackVec[j+1]; - trackVec[j+1] = Temp; + trackVec[j] = trackVec[j + 1]; + trackVec[j + 1] = Temp; } - } + } } /* - - this function is used to select only the combined tracks which have been formed from excatly 2 sub tracks which themselves are not formed from any other tracks. - + + this function is used to select only the combined tracks which have been formed from excatly 2 sub tracks which + themselves are not formed from any other tracks. + */ void FullLDCTracking_MarlinTrk::SelectCombinedTracks() { - + int nCombTrk = int(_allCombinedTracks.size()); - - streamlog_out(DEBUG3) << " **SelectCombinedTracks - check " << nCombTrk << " comb. tracks " << std::endl ; + + streamlog_out(DEBUG3) << " **SelectCombinedTracks - check " << nCombTrk << " comb. tracks " << std::endl; // loop over all combined tracks ... - for (int i=0; igetGroupTracks(); + GroupTracks* group = trkExt->getGroupTracks(); TrackExtendedVec tracks = group->getTrackExtendedVec(); // check that there are only 2 sub tracks, as we are after Si <-> TPC mergers only int nTracks = int(tracks.size()); - streamlog_out(DEBUG1) << " **SelectCombinedTracks - nTracks = " << nTracks << std::endl ; - + streamlog_out(DEBUG1) << " **SelectCombinedTracks - nTracks = " << nTracks << std::endl; + if (nTracks == 2) { - - TrackExtended * firstTrack = tracks[0]; - TrackExtended * secondTrack = tracks[1]; + + TrackExtended* firstTrack = tracks[0]; + TrackExtended* secondTrack = tracks[1]; // check that the two sub tracks in question are not themselves a merger of tracks - if ((firstTrack->getGroupTracks() == NULL) && - (secondTrack->getGroupTracks() == NULL) ) { + if ((firstTrack->getGroupTracks() == NULL) && (secondTrack->getGroupTracks() == NULL)) { - streamlog_out(DEBUG1) << " **SelectCombinedTracks - firstTrack->getGroupTracks() == NULL ... " << std::endl ; + streamlog_out(DEBUG1) << " **SelectCombinedTracks - firstTrack->getGroupTracks() == NULL ... " << std::endl; - // associate the current group to the two sub tracks + // associate the current group to the two sub tracks firstTrack->setGroupTracks(group); - secondTrack->setGroupTracks(group); + secondTrack->setGroupTracks(group); // get the tracker hits ... TrackerHitExtendedVec firstVec = firstTrack->getTrackerHitExtendedVec(); @@ -2273,24 +2041,24 @@ void FullLDCTracking_MarlinTrk::SelectCombinedTracks() { edges[1] = -1.0e+20; // get min and max z for the first sub track - for (int iF=0;iFgetTrackerHit(); + for (int iF = 0; iF < nFirst; ++iF) { + TrackerHitExtended* trkHitExt = firstVec[iF]; + TrackerHit* trkHit = trkHitExt->getTrackerHit(); float zpos = float(trkHit->getPosition()[2]); - if (zpos>edges[1]) + if (zpos > edges[1]) edges[1] = zpos; - if (zposgetTrackerHit(); + for (int iS = 0; iS < nSecond; ++iS) { + TrackerHitExtended* trkHitExt = secondVec[iS]; + TrackerHit* trkHit = trkHitExt->getTrackerHit(); float zpos = float(trkHit->getPosition()[2]); - if (zpos>edges[1]) + if (zpos > edges[1]) edges[1] = zpos; - if (zpos= 2) { int iopt = 1; - + // here it is assumed that the tpc tracks is the secondTrack ... - PrintOutMerging(secondTrack,firstTrack,iopt); - } + PrintOutMerging(secondTrack, firstTrack, iopt); + } } - } else { // if(nTracks>2) + } else { // if(nTracks>2) - streamlog_out(DEBUG2) << " ***************** SelectCombinedTracks: MORE THAN TWO TRACKS " << nCombTrk << std::endl; + streamlog_out(DEBUG2) << " ***************** SelectCombinedTracks: MORE THAN TWO TRACKS " << nCombTrk + << std::endl; } } - - } -void FullLDCTracking_MarlinTrk::AddNotCombinedTracks() { - +void FullLDCTracking_MarlinTrk::AddNotCombinedTracks() { + int nTPCTrk = int(_allTPCTracks.size()); int nSiTrk = int(_allSiTracks.size()); - + // we need some buffer vector TrackExtendedVec allMergedTracks; allMergedTracks.clear(); - + // forcing merging of Si and TPC track segments - if (_forceMerging==1) { + if (_forceMerging == 1) { // loop over all TPC tracks - for (int i=0;igetGroupTracks(); + TrackExtended* trkExtTPC = _allTPCTracks[i]; + GroupTracks* groupTPC = trkExtTPC->getGroupTracks(); // if no tracks have been grouped with this TPC track if (groupTPC == NULL) { float diffMin = 1.0e+20; - TrackExtended * siTrkToAttach = NULL; + TrackExtended* siTrkToAttach = NULL; // loop over all Silicon Tracks - for (int j=0;jgetGroupTracks(); + for (int j = 0; j < nSiTrk; ++j) { + TrackExtended* trkExtSi = _allSiTracks[j]; + GroupTracks* groupSi = trkExtSi->getGroupTracks(); // only consider ungrouped Silicon Tracks if (groupSi == NULL) { @@ -2356,49 +2122,50 @@ void FullLDCTracking_MarlinTrk::AddNotCombinedTracks() { // float deltaP = CompareTrk(trkExtSi,trkExtTPC,_d0CutForForcedMerging,_z0CutForForcedMerging,iComp); float angle(0.); float angleSignificance(0.); - + // try to merge tracks using looser cuts - float dOmega = CompareTrkII(trkExtSi,trkExtTPC,_d0CutForForcedMerging,_z0CutForForcedMerging,iComp,angle); + float dOmega = + CompareTrkII(trkExtSi, trkExtTPC, _d0CutForForcedMerging, _z0CutForForcedMerging, iComp, angle); - float significance = CompareTrkIII(trkExtSi,trkExtTPC,_d0CutForForcedMerging,_z0CutForForcedMerging,iComp,angleSignificance); + float significance = CompareTrkIII(trkExtSi, trkExtTPC, _d0CutForForcedMerging, _z0CutForForcedMerging, + iComp, angleSignificance); // if (deltaP < _dPCutForForcedMerging) { - if ( ((dOmega<_dOmegaForForcedMerging) && (angle<_angleForForcedMerging)) || - ((significance<5) && (angleSignificance<5)) - ) { + if (((dOmega < _dOmegaForForcedMerging) && (angle < _angleForForcedMerging)) || + ((significance < 5) && (angleSignificance < 5))) { - float chi2O = dOmega/_dOmegaForForcedMerging; - float chi2A = angle/_angleForForcedMerging; - float deltaP = chi2O*chi2O + chi2A*chi2A; + float chi2O = dOmega / _dOmegaForForcedMerging; + float chi2A = angle / _angleForForcedMerging; + float deltaP = chi2O * chi2O + chi2A * chi2A; - // if this is the best match (diffMin) set the possible merger - if (deltaP= 3) { - int iopt = 7; + int iopt = 7; streamlog_out(DEBUG2) << significance << " " << angleSignificance << std::endl; - PrintOutMerging(trkExtTPC,trkExtSi,iopt); + PrintOutMerging(trkExtTPC, trkExtSi, iopt); } } } } - - if (siTrkToAttach!=NULL) { - TrackExtended * trkExtSi = siTrkToAttach; - TrackExtended * OutputTrack = new TrackExtended(); - GroupTracks * group = new GroupTracks(); + if (siTrkToAttach != NULL) { + + TrackExtended* trkExtSi = siTrkToAttach; + TrackExtended* OutputTrack = new TrackExtended(); + GroupTracks* group = new GroupTracks(); group->addTrackExtended(trkExtSi); group->addTrackExtended(trkExtTPC); OutputTrack->setGroupTracks(group); // trkExtSi->setGroupTracks(group); - // trkExtTPC->setGroupTracks(group); + // trkExtTPC->setGroupTracks(group); OutputTrack->setOmega(trkExtTPC->getOmega()); OutputTrack->setTanLambda(trkExtSi->getTanLambda()); @@ -2409,51 +2176,51 @@ void FullLDCTracking_MarlinTrk::AddNotCombinedTracks() { float covMatTPC[15]; float covMatSi[15]; float covMat[15]; - for (int iCov=0;iCov<15;++iCov) { + for (int iCov = 0; iCov < 15; ++iCov) { covMatTPC[iCov] = trkExtTPC->getCovMatrix()[iCov]; - covMatSi[iCov] = trkExtSi->getCovMatrix()[iCov]; + covMatSi[iCov] = trkExtSi->getCovMatrix()[iCov]; covMat[iCov] = covMatSi[iCov]; } - float scaling = sqrt(covMatTPC[5]/covMatSi[5]); - covMat[5] = covMatTPC[5]; - covMat[3] = scaling*covMatSi[3]; - covMat[4] = scaling*covMatSi[4]; - covMat[8] = scaling*covMatSi[8]; - covMat[12] = scaling*covMatSi[12]; + float scaling = sqrt(covMatTPC[5] / covMatSi[5]); + covMat[5] = covMatTPC[5]; + covMat[3] = scaling * covMatSi[3]; + covMat[4] = scaling * covMatSi[4]; + covMat[8] = scaling * covMatSi[8]; + covMat[12] = scaling * covMatSi[12]; OutputTrack->setCovMatrix(covMat); TrackerHitExtendedVec tpcHitVec = trkExtTPC->getTrackerHitExtendedVec(); - TrackerHitExtendedVec siHitVec = trkExtSi->getTrackerHitExtendedVec(); + TrackerHitExtendedVec siHitVec = trkExtSi->getTrackerHitExtendedVec(); - int nTPCHits = int( tpcHitVec.size()); - int nSiHits = int( siHitVec.size()); + int nTPCHits = int(tpcHitVec.size()); + int nSiHits = int(siHitVec.size()); float edges[2]; edges[0] = 1.0e+20; edges[1] = -1.0e+20; // find the max and min z extents from hits - for (int iH=0;iHaddTrackerHitExtended(hitExt); hitExt->setUsedInFit(true); - TrackerHit * hit = hitExt->getTrackerHit(); + TrackerHit* hit = hitExt->getTrackerHit(); float zpos = float(hit->getPosition()[2]); - if (zposedges[1]) + if (zpos > edges[1]) edges[1] = zpos; - } - for (int iH=0;iHaddTrackerHitExtended(hitExt); - hitExt->setUsedInFit(true); - TrackerHit * hit = hitExt->getTrackerHit(); + hitExt->setUsedInFit(true); + TrackerHit* hit = hitExt->getTrackerHit(); float zpos = float(hit->getPosition()[2]); - if (zposedges[1]) + if (zpos > edges[1]) edges[1] = zpos; } @@ -2461,20 +2228,18 @@ void FullLDCTracking_MarlinTrk::AddNotCombinedTracks() { OutputTrack->setChi2(diffMin); // will be replaced if necessary OutputTrack->setNDF(int(1)); // will be replaced if necessary - _allCombinedTracks.push_back( OutputTrack ); - allMergedTracks.push_back( OutputTrack ); - + _allCombinedTracks.push_back(OutputTrack); + allMergedTracks.push_back(OutputTrack); } } - + } // end of loop over TPC tracks - - + // check that there are some merged tracks to process int nMerged = int(allMergedTracks.size()); - if (nMerged>0) { - + if (nMerged > 0) { + // sort all merged tracks by Chi2/NDF // although due to the fact that NDF for these tracks is set to the value 1 above, // it is really only a sort on Chi2 which was really the weighted difference in angle and omega @@ -2482,60 +2247,57 @@ void FullLDCTracking_MarlinTrk::AddNotCombinedTracks() { Sorting(allMergedTracks); // loop over all merged tracks - for (int iM=0;iMgetGroupTracks(); - - TrackExtended * mergedTrack = allMergedTracks[iM]; - GroupTracks * grpTrk = mergedTrack->getGroupTracks(); - TrackExtendedVec trkVec = grpTrk->getTrackExtendedVec(); - TrackExtended * trkTPC = NULL; - TrackExtended * trkSi = NULL; + TrackExtended* trkTPC = NULL; + TrackExtended* trkSi = NULL; int nT = int(trkVec.size()); // only consider tracks which have been composed of excactly 2 sub tracks - if (nT==2) { + if (nT == 2) { trkTPC = trkVec[0]; trkSi = trkVec[1]; - GroupTracks * groupTPC = trkTPC->getGroupTracks(); - GroupTracks * groupSi = trkSi->getGroupTracks(); + GroupTracks* groupTPC = trkTPC->getGroupTracks(); + GroupTracks* groupSi = trkSi->getGroupTracks(); // check that both the TPC and SI track have not already been combined with other tracks ... if (groupTPC == NULL && groupSi == NULL) { // set the grouping, meaning that these tracks will not be considered further - trkTPC->setGroupTracks( grpTrk ); - trkSi->setGroupTracks( grpTrk ); + trkTPC->setGroupTracks(grpTrk); + trkSi->setGroupTracks(grpTrk); TrackerHitExtendedVec hitVec = mergedTrack->getTrackerHitExtendedVec(); - + int nhits = int(hitVec.size()); - int totNdf = 2*nhits - 5; + int totNdf = 2 * nhits - 5; float totChi2 = trkTPC->getChi2() + trkSi->getChi2(); - mergedTrack->setNDF( totNdf ); - mergedTrack->setChi2( totChi2 ); + mergedTrack->setNDF(totNdf); + mergedTrack->setChi2(totChi2); if (_debug >= 2) { int iopt = 2; - PrintOutMerging(trkTPC,trkSi,iopt); + PrintOutMerging(trkTPC, trkSi, iopt); } - _trkImplVec.push_back( mergedTrack ); + _trkImplVec.push_back(mergedTrack); } } } } } // end of _forceMerging - - - + // clear buffer vector allMergedTracks.clear(); - + // merging split up TPC segments if (_mergeTPCSegments) { @@ -2545,13 +2307,14 @@ void FullLDCTracking_MarlinTrk::AddNotCombinedTracks() { int nNonAssignedTPCSeg = 0; // loop over all TPC Tracks - for (int i=0;igetGroupTracks(); - TrackExtended * trkExt = _allTPCTracks[i]; - GroupTracks * group = trkExt->getGroupTracks(); + streamlog_out(DEBUG2) << " ***************** AddNotCombinedTracks: Check track " << trkExt + << " id = " << trkExt->getTrack()->id() << std::endl; - streamlog_out(DEBUG2) << " ***************** AddNotCombinedTracks: Check track " << trkExt << " id = " << trkExt->getTrack()->id() << std::endl; - // only consider those tracks which have not yet been combined if (group == NULL) { @@ -2561,9 +2324,9 @@ void FullLDCTracking_MarlinTrk::AddNotCombinedTracks() { float zmin = 1e+20; float zmax = -1e+20; - for (int iCur=0;iCurgetTrackerHit(); + for (int iCur = 0; iCur < nCur; ++iCur) { + TrackerHitExtended* curTrkHitExt = currentVec[iCur]; + TrackerHit* curTrkHit = curTrkHitExt->getTrackerHit(); float zpos = float(curTrkHit->getPosition()[2]); if (zpos < zmin) zmin = zpos; @@ -2571,46 +2334,44 @@ void FullLDCTracking_MarlinTrk::AddNotCombinedTracks() { zmax = zpos; } - nNonAssignedTPCSeg++; // current number of TPC segment groupings int nGroups = int(TPCSegments.size()); float dPtMin = 1.0e+10; - GroupTracks * groupToAttach = NULL; - TrackExtended * trkToAttach = NULL; + GroupTracks* groupToAttach = NULL; + TrackExtended* trkToAttach = NULL; // loop over the current TPC segment groupings - for (int iG=0;iGgetTrackExtendedVec(); // number of segments with the candidate group int nTrk = int(segVec.size()); bool consider = true; - - if (_forbidOverlapInZTPC==1) { // if overlap in Z of the two segments is forbidden + if (_forbidOverlapInZTPC == 1) { // if overlap in Z of the two segments is forbidden // loop over all tracks in the current grouping - for (int iTrk=0;iTrkgetTrackerHitExtendedVec(); int nHitsInGrp = int(hitInGroupVec.size()); // loop over the hits and make sure that there is no overlap in z - for (int iHitInGrp=0;iHitInGrpgetTrackerHit(); + TrackerHitExtended* xTrkExt = hitInGroupVec[iHitInGrp]; + TrackerHit* xTrk = xTrkExt->getTrackerHit(); float xZ = float(xTrk->getPosition()[2]); - if (xZ>zmin&&xZ zmin && xZ < zmax) { consider = false; break; } @@ -2623,42 +2384,41 @@ void FullLDCTracking_MarlinTrk::AddNotCombinedTracks() { if (consider) { // again loop over the tracks in the current group - for (int iTrk=0;iTrk=3) { + if (_debug >= 3) { int iopt = 5; - PrintOutMerging(trkExt,trkInGroup,iopt); + PrintOutMerging(trkExt, trkInGroup, iopt); } - } - else { - if (_debug>=3) { + } else { + if (_debug >= 3) { int iopt = 9; - PrintOutMerging(trkExt,trkInGroup,iopt); + PrintOutMerging(trkExt, trkInGroup, iopt); } } } - } - else { + } else { if (_debug >= 3) { int iopt = 9; - for (int iTrk=0;iTrk= dPtMin) { - PrintOutMerging(trkExt,trkInGroup,iopt); + float dPt = CompareTrk(trkExt, trkInGroup, _d0CutToMergeTPC, _z0CutToMergeTPC, iComp); + if (dPt >= dPtMin) { + PrintOutMerging(trkExt, trkInGroup, iopt); } } } @@ -2667,7 +2427,7 @@ void FullLDCTracking_MarlinTrk::AddNotCombinedTracks() { // check the pt cut for merging and that a group has been found to match .. if (dPtMin < _dPCutToMergeTPC && groupToAttach != NULL) { - + // add the track to the group groupToAttach->addTrackExtended(trkExt); trkExt->setGroupTracks(groupToAttach); @@ -2678,23 +2438,24 @@ void FullLDCTracking_MarlinTrk::AddNotCombinedTracks() { float edges[2]; edges[0] = zmin; - if (zminGroupzmax) + if (zmaxGroup > zmax) edges[1] = zmaxGroup; groupToAttach->setEdges(edges); - if (_debug>=3) { + if (_debug >= 3) { int iopt = 3; - PrintOutMerging(trkExt,trkToAttach,iopt); + PrintOutMerging(trkExt, trkToAttach, iopt); } } else { - - // create a new group of segments - GroupTracks * newSegment = new GroupTracks(trkExt); + + // create a new group of segments + GroupTracks* newSegment = new GroupTracks(trkExt); trkExt->setGroupTracks(newSegment); - streamlog_out(DEBUG2) << " ***************** AddNotCombinedTracks: Create new TPC Segment Group for track " << trkExt << " id = " << trkExt->getTrack()->id() << std::endl; - + streamlog_out(DEBUG2) << " ***************** AddNotCombinedTracks: Create new TPC Segment Group for track " + << trkExt << " id = " << trkExt->getTrack()->id() << std::endl; + TPCSegments.push_back(newSegment); float edges[2]; edges[0] = zmin; @@ -2705,11 +2466,11 @@ void FullLDCTracking_MarlinTrk::AddNotCombinedTracks() { } // At this stage all tpc segements will have been grouped. - + // Now try to combine the groups of TPC segments with the // reconstructed tracks which have already been combined into full tracks // containing both Si and TPC segments - + int nCombTrk = int(_trkImplVec.size()); int nSegments = int(TPCSegments.size()); @@ -2717,156 +2478,152 @@ void FullLDCTracking_MarlinTrk::AddNotCombinedTracks() { // std::cout << "nSegments = " << nSegments << std::endl; // loop over all the TPC segment collections - for (int iS=0;iSgetTrackExtendedVec(); float zminTPCSeg = segments->getEdges()[0]; float zmaxTPCSeg = segments->getEdges()[1]; int nTrk = int(segVec.size()); - TrackExtended * CombTrkToAttach = NULL; - TrackExtended * keyTrack = NULL; + TrackExtended* CombTrkToAttach = NULL; + TrackExtended* keyTrack = NULL; float deltaPtMin = _dPCutToMergeTPC; // search over the combined (good) tracks - for (int iCTrk=0;iCTrkgetGroupTracks(); + TrackExtended* combTrk = _trkImplVec[iCTrk]; + GroupTracks* groupComb = combTrk->getGroupTracks(); bool consider = true; - if (_forbidOverlapInZComb==1) { // if overlap in Z of the two segments is forbidden + if (_forbidOverlapInZComb == 1) { // if overlap in Z of the two segments is forbidden float zminComb = groupComb->getEdges()[0]; float zmaxComb = groupComb->getEdges()[1]; - consider = (zminTPCSeg>zmaxComb) || (zmaxTPCSeg zmaxComb) || (zmaxTPCSeg < zminComb); } - + // if there are not overlaps in z, if _forbidOverlapInZComb is set above if (consider) { // loop over the TPC segments in the group - for (int iTrk=0;iTrk=3) { - GroupTracks * groupCur = combTrk->getGroupTracks(); - TrackExtended * dummySi = groupCur->getTrackExtendedVec()[0]; + } else { + if (_debug >= 3) { + GroupTracks* groupCur = combTrk->getGroupTracks(); + TrackExtended* dummySi = groupCur->getTrackExtendedVec()[0]; int iopt_temp = 8; - PrintOutMerging(trk,dummySi,iopt_temp); + PrintOutMerging(trk, dummySi, iopt_temp); } } } - } - else { - if (_debug>=3) { - for (int iTrk=0;iTrk= 3) { + for (int iTrk = 0; iTrk < nTrk; ++iTrk) { + TrackExtended* trk = segVec[iTrk]; int iopt = 0; - float dPt = CompareTrk(trk,combTrk,_d0CutToMergeTPC,_z0CutToMergeTPC,iopt); - if (dPt>deltaPtMin) { - GroupTracks * groupCur = combTrk->getGroupTracks(); - TrackExtended * dummySi = groupCur->getTrackExtendedVec()[0]; + float dPt = CompareTrk(trk, combTrk, _d0CutToMergeTPC, _z0CutToMergeTPC, iopt); + if (dPt > deltaPtMin) { + GroupTracks* groupCur = combTrk->getGroupTracks(); + TrackExtended* dummySi = groupCur->getTrackExtendedVec()[0]; int iopt_temp = 8; - PrintOutMerging(trk,dummySi,iopt_temp); + PrintOutMerging(trk, dummySi, iopt_temp); } } } } } - + if (CombTrkToAttach != NULL) { // attach TPC segment to existing Comb Track - GroupTracks * groupToAttach = CombTrkToAttach->getGroupTracks(); - TrackExtended * SiCombTrk = groupToAttach->getTrackExtendedVec()[0]; - TrackExtended * TpcCombTrk = groupToAttach->getTrackExtendedVec()[1]; + GroupTracks* groupToAttach = CombTrkToAttach->getGroupTracks(); + TrackExtended* SiCombTrk = groupToAttach->getTrackExtendedVec()[0]; + TrackExtended* TpcCombTrk = groupToAttach->getTrackExtendedVec()[1]; - if (_debug>=3) { + if (_debug >= 3) { int iopt = 4; - PrintOutMerging(keyTrack,SiCombTrk,iopt); + PrintOutMerging(keyTrack, SiCombTrk, iopt); iopt = 5; - PrintOutMerging(keyTrack,TpcCombTrk,iopt); + PrintOutMerging(keyTrack, TpcCombTrk, iopt); } - for (int iTrk=0;iTrkaddTrackExtended( segmentTrack ); - segmentTrack->setGroupTracks( groupToAttach ); + TrackExtended* segmentTrack = segVec[iTrk]; + groupToAttach->addTrackExtended(segmentTrack); + segmentTrack->setGroupTracks(groupToAttach); TrackerHitExtendedVec hitVec = segmentTrack->getTrackerHitExtendedVec(); int nHitSeg = int(hitVec.size()); - for (int iHS=0;iHSsetUsedInFit(false); - CombTrkToAttach->addTrackerHitExtended( hitExt ); - + CombTrkToAttach->addTrackerHitExtended(hitExt); } } - } - else { - if (nTrk==1) { // create a new group - GroupTracks * newGrp = new GroupTracks(); + } else { + if (nTrk == 1) { // create a new group + GroupTracks* newGrp = new GroupTracks(); segVec[0]->setGroupTracks(newGrp); newGrp->addTrackExtended(segVec[0]); TrackerHitExtendedVec TpcHitVec = segVec[0]->getTrackerHitExtendedVec(); int nTpcH = int(TpcHitVec.size()); - for (int iTpcH=0;iTpcHsetUsedInFit( true ); + for (int iTpcH = 0; iTpcH < nTpcH; ++iTpcH) { + TpcHitVec[iTpcH]->setUsedInFit(true); } _trkImplVec.push_back(segVec[0]); _allNonCombinedTPCTracks.push_back(segVec[0]); - } - else { // several segments - + } else { // several segments + float zMin = 1.0e+20; - TrackExtended * chosenTrack = NULL; + TrackExtended* chosenTrack = NULL; // loop over the segments - for (int iTrk=0;iTrkgetTrack(); + Track* track = segment->getTrack(); TrackerHitVec hitVec = track->getTrackerHits(); streamlog_out(DEBUG1) << "Group of orphaned TPC tracks: trying track " << track->id() << std::endl; - + int nHits = int(hitVec.size()); // loop over it's hits - for (int iH=0;iHgetPosition()[2]); // if this segment has the hit closest to the IP so far - if (zPosigetTrack()->id() << std::endl; - streamlog_out(DEBUG2) << "Group of orphaned TPC tracks: chosen track taken as " << chosenTrack->getTrack()->id() << std::endl; - // create a new group of tracks - GroupTracks * newGroup = new GroupTracks(); + GroupTracks* newGroup = new GroupTracks(); // first add the chosen track - chosenTrack->setGroupTracks( newGroup ); - newGroup->addTrackExtended( chosenTrack ); - + chosenTrack->setGroupTracks(newGroup); + newGroup->addTrackExtended(chosenTrack); + // loop over the segments ... - for (int iTrk=0;iTrkgetTrackerHitExtendedVec(); - int nHitS = int(hitVecS.size()); + int nHitS = int(hitVecS.size()); // loop over the hits for the current segment - for (int iH=0;iHsetGroupTracks( newGroup ); - newGroup->addTrackExtended( segment ); - trkHitExt->setUsedInFit( false ); - chosenTrack->addTrackerHitExtended( trkHitExt ); - } - else { - trkHitExt->setUsedInFit( true ); + segment->setGroupTracks(newGroup); + newGroup->addTrackExtended(segment); + trkHitExt->setUsedInFit(false); + chosenTrack->addTrackerHitExtended(trkHitExt); + } else { + trkHitExt->setUsedInFit(true); } } } @@ -2917,136 +2673,144 @@ void FullLDCTracking_MarlinTrk::AddNotCombinedTracks() { } } } - for (int iS=0;iSgetTrack(); - GroupTracks * group = trkExt->getGroupTracks(); + } else { // adding all TPC segments to the list of tracks (track splitting is allowed) + for (int i = 0; i < nTPCTrk; ++i) { + TrackExtended* trkExt = _allTPCTracks[i]; + Track* track = trkExt->getTrack(); + GroupTracks* group = trkExt->getGroupTracks(); if (group == NULL) { - streamlog_out(DEBUG2) << " ***************** AddNotCombinedTracks: _mergeTPCSegments = " << _mergeTPCSegments << " : Add non combined TPC track " << trkExt << " id = " << track->id() << std::endl; + streamlog_out(DEBUG2) << " ***************** AddNotCombinedTracks: _mergeTPCSegments = " << _mergeTPCSegments + << " : Add non combined TPC track " << trkExt << " id = " << track->id() << std::endl; TrackerHitExtendedVec hitVec = trkExt->getTrackerHitExtendedVec(); int nHTPC = int(hitVec.size()); - for (int iHTPC=0;iHTPCsetUsedInFit(true); } _trkImplVec.push_back(trkExt); - _allNonCombinedTPCTracks.push_back( trkExt ); - - GroupTracks * newGrp = new GroupTracks(); - newGrp->addTrackExtended( trkExt ); - trkExt->setGroupTracks( newGrp ); + _allNonCombinedTPCTracks.push_back(trkExt); + GroupTracks* newGrp = new GroupTracks(); + newGrp->addTrackExtended(trkExt); + trkExt->setGroupTracks(newGrp); } - } + } } - - for (int i=0;igetTrack(); - GroupTracks * group = trkExt->getGroupTracks(); + + for (int i = 0; i < nSiTrk; ++i) { // adding left-over Si segments to the list of tracks + TrackExtended* trkExt = _allSiTracks[i]; + Track* track = trkExt->getTrack(); + GroupTracks* group = trkExt->getGroupTracks(); if (group == NULL) { - - streamlog_out(DEBUG2) << " ***************** AddNotCombinedTracks: Add non combined Silicon Track : " << trkExt << " id = " << track->id() << std::endl; - + + streamlog_out(DEBUG2) << " ***************** AddNotCombinedTracks: Add non combined Silicon Track : " << trkExt + << " id = " << track->id() << std::endl; + TrackerHitExtendedVec hitVec = trkExt->getTrackerHitExtendedVec(); int nHSi = int(hitVec.size()); - for (int iHSi=0;iHSisetUsedInFit(true); } _trkImplVec.push_back(trkExt); - _allNonCombinedSiTracks.push_back( trkExt ); - - GroupTracks * newGrp = new GroupTracks(); - newGrp->addTrackExtended( trkExt ); - trkExt->setGroupTracks( newGrp ); + _allNonCombinedSiTracks.push_back(trkExt); + GroupTracks* newGrp = new GroupTracks(); + newGrp->addTrackExtended(trkExt); + trkExt->setGroupTracks(newGrp); } } - } -void FullLDCTracking_MarlinTrk::CheckTracks() { - - for(unsigned int i = 0; i< _trkImplVec.size();i++){ - TrackExtended *first = _trkImplVec[i]; - if(first==NULL)continue; +void FullLDCTracking_MarlinTrk::CheckTracks() { + + for (unsigned int i = 0; i < _trkImplVec.size(); i++) { + TrackExtended* first = _trkImplVec[i]; + if (first == NULL) + continue; float d0First = first->getD0(); float z0First = first->getZ0(); float omegaFirst = first->getOmega(); float tanLFirst = first->getTanLambda(); float phiFirst = first->getPhi(); HelixClass helixFirst; - helixFirst.Initialize_Canonical(phiFirst,d0First,z0First,omegaFirst,tanLFirst,_bField); + helixFirst.Initialize_Canonical(phiFirst, d0First, z0First, omegaFirst, tanLFirst, _bField); float momFirst[3]; - momFirst[0]= helixFirst.getMomentum()[0]; - momFirst[1]= helixFirst.getMomentum()[1]; - momFirst[2]= helixFirst.getMomentum()[2]; - float pFirst = sqrt(momFirst[0]*momFirst[0]+momFirst[1]*momFirst[1]+momFirst[2]*momFirst[2]); - if(std::isnan(pFirst))continue; - TrackerHitExtendedVec firstHitVec = first->getTrackerHitExtendedVec(); - if(firstHitVec.size()<1)continue; - - for(unsigned int j = i+1; j<_trkImplVec.size();j++){ - TrackExtended *second = _trkImplVec[j]; - if(second==NULL)continue; + momFirst[0] = helixFirst.getMomentum()[0]; + momFirst[1] = helixFirst.getMomentum()[1]; + momFirst[2] = helixFirst.getMomentum()[2]; + float pFirst = sqrt(momFirst[0] * momFirst[0] + momFirst[1] * momFirst[1] + momFirst[2] * momFirst[2]); + if (std::isnan(pFirst)) + continue; + TrackerHitExtendedVec firstHitVec = first->getTrackerHitExtendedVec(); + if (firstHitVec.size() < 1) + continue; + + for (unsigned int j = i + 1; j < _trkImplVec.size(); j++) { + TrackExtended* second = _trkImplVec[j]; + if (second == NULL) + continue; float d0Second = second->getD0(); float z0Second = second->getZ0(); float omegaSecond = second->getOmega(); float tanLSecond = second->getTanLambda(); float phiSecond = second->getPhi(); HelixClass helixSecond; - helixSecond.Initialize_Canonical(phiSecond,d0Second,z0Second,omegaSecond,tanLSecond,_bField); + helixSecond.Initialize_Canonical(phiSecond, d0Second, z0Second, omegaSecond, tanLSecond, _bField); float momSecond[3]; momSecond[0] = helixSecond.getMomentum()[0]; momSecond[1] = helixSecond.getMomentum()[1]; momSecond[2] = helixSecond.getMomentum()[2]; - float pSecond = sqrt(momSecond[0]*momSecond[0]+momSecond[1]*momSecond[1]+momSecond[2]*momSecond[2]); - if(std::isnan(pSecond))continue; - TrackerHitExtendedVec secondHitVec = second->getTrackerHitExtendedVec(); - if(secondHitVec.size()<1)continue; - if(firstHitVec.size()+secondHitVec.size()<10)continue; - - - float pdot = (momFirst[0]*momSecond[0]+momFirst[1]*momSecond[1]+momFirst[2]*momSecond[2])/pFirst/pSecond; - if(pdot<0.999)continue; + float pSecond = sqrt(momSecond[0] * momSecond[0] + momSecond[1] * momSecond[1] + momSecond[2] * momSecond[2]); + if (std::isnan(pSecond)) + continue; + TrackerHitExtendedVec secondHitVec = second->getTrackerHitExtendedVec(); + if (secondHitVec.size() < 1) + continue; + if (firstHitVec.size() + secondHitVec.size() < 10) + continue; + + float pdot = + (momFirst[0] * momSecond[0] + momFirst[1] * momSecond[1] + momFirst[2] * momSecond[2]) / pFirst / pSecond; + if (pdot < 0.999) + continue; // const float sigmaPOverPFirst = sqrt(first->getCovMatrix()[5])/fabs(omegaFirst); // const float sigmaPOverPSecond = sqrt(second->getCovMatrix()[5])/fabs(omegaSecond); // const float deltaP = fabs(pFirst-pSecond); - // const float sigmaDeltaP = sqrt(pFirst*sigmaPOverPFirst*pFirst*sigmaPOverPFirst+pSecond*sigmaPOverPSecond*pSecond*sigmaPOverPSecond); + // const float sigmaDeltaP = + // sqrt(pFirst*sigmaPOverPFirst*pFirst*sigmaPOverPFirst+pSecond*sigmaPOverPSecond*pSecond*sigmaPOverPSecond); // const float significance = deltaP/sigmaDeltaP; - - TrackExtended * combinedTrack = CombineTracks(first,second, _maxAllowedPercentageOfOutliersForTrackCombination, true); - if(combinedTrack != NULL){ - const int minHits = std::min(firstHitVec.size(),secondHitVec.size()); - const int maxHits = std::max(firstHitVec.size(),secondHitVec.size()); - - if( combinedTrack->getNDF() <= 2*maxHits+minHits-5){ + + TrackExtended* combinedTrack = + CombineTracks(first, second, _maxAllowedPercentageOfOutliersForTrackCombination, true); + if (combinedTrack != NULL) { + const int minHits = std::min(firstHitVec.size(), secondHitVec.size()); + const int maxHits = std::max(firstHitVec.size(), secondHitVec.size()); + + if (combinedTrack->getNDF() <= 2 * maxHits + minHits - 5) { delete combinedTrack->getGroupTracks(); delete combinedTrack; continue; } - - float d0 = combinedTrack->getD0(); - float z0 = combinedTrack->getZ0(); + + float d0 = combinedTrack->getD0(); + float z0 = combinedTrack->getZ0(); float omega = combinedTrack->getOmega(); - float tanL = combinedTrack->getTanLambda(); - float phi = combinedTrack->getPhi(); - + float tanL = combinedTrack->getTanLambda(); + float phi = combinedTrack->getPhi(); + HelixClass helix; - helix.Initialize_Canonical(phi,d0,z0,omega,tanL,_bField); + helix.Initialize_Canonical(phi, d0, z0, omega, tanL, _bField); // float mom[3]; // mom[0] = helix.getMomentum()[0]; // mom[1] = helix.getMomentum()[1]; @@ -3054,95 +2818,89 @@ void FullLDCTracking_MarlinTrk::CheckTracks() { // float p = sqrt(mom[0]*mom[0]+mom[1]*mom[1]+mom[2]*mom[2]); // float chi2Sig = (combinedTrack->getChi2() - combinedTrack->getNDF()); // chi2Sig = chi2Sig/sqrt(combinedTrack->getNDF()*2); - - - + int nTpcFirst(0); int nUsedFirst(0); - for(unsigned int ihit = 0;ihitgetTrackerHit()) == lcio::ILDDetID::TPC) nTpcFirst++; - - if( firstHitVec[ihit]->getUsedInFit()==true ) nUsedFirst++; + for (unsigned int ihit = 0; ihit < firstHitVec.size(); ihit++) { + + if (getDetectorID(firstHitVec[ihit]->getTrackerHit()) == lcio::ILDDetID::TPC) + nTpcFirst++; + + if (firstHitVec[ihit]->getUsedInFit() == true) + nUsedFirst++; } - - + int nTpcSecond(0); int nUsedSecond(0); - for(unsigned int ihit = 0;ihitgetTrackerHit()) == lcio::ILDDetID::TPC) ++nTpcSecond; - if( secondHitVec[ihit]->getUsedInFit()==true ) ++nUsedSecond; + for (unsigned int ihit = 0; ihit < secondHitVec.size(); ihit++) { + if (getDetectorID(secondHitVec[ihit]->getTrackerHit()) == lcio::ILDDetID::TPC) + ++nTpcSecond; + if (secondHitVec[ihit]->getUsedInFit() == true) + ++nUsedSecond; } delete combinedTrack->getGroupTracks(); delete combinedTrack; } } } - - } - /* - + compare the following: - + i) delta omega < 2 * _dOmegaForMerging ii) delta d0 < d0Cut iii) delta z0 < z0Cut if above three cuts are passed return: - + the angle between the two tracks (return by reference) and the difference in omega - + */ +float FullLDCTracking_MarlinTrk::CompareTrkII(TrackExtended* first, TrackExtended* second, float d0Cut, float z0Cut, + int /*iopt*/, float& Angle) { -float FullLDCTracking_MarlinTrk::CompareTrkII(TrackExtended * first, TrackExtended * second, - float d0Cut, float z0Cut,int /*iopt*/,float & Angle) { - - float result = 1.0e+20; - Angle = 1.0e+20; + Angle = 1.0e+20; float omegaFirst = first->getOmega(); float omegaSecond = second->getOmega(); - float deltaOmega = fabs((omegaFirst-omegaSecond)/omegaSecond); - if(deltaOmega> 2*_dOmegaForMerging)return result; - - + float deltaOmega = fabs((omegaFirst - omegaSecond) / omegaSecond); + if (deltaOmega > 2 * _dOmegaForMerging) + return result; + float d0First = first->getD0(); float z0First = first->getZ0(); float d0Second = second->getD0(); float z0Second = second->getZ0(); - - bool isCloseInIP = (fabs(d0First-d0Second)getTanLambda(); float phiFirst = first->getPhi(); float tanLSecond = second->getTanLambda(); float phiSecond = second->getPhi(); float qFirst = PIOVER2 - atan(tanLFirst); float qSecond = PIOVER2 - atan(tanLSecond); - - Angle = (cos(phiFirst)*cos(phiSecond)+sin(phiFirst)*sin(phiSecond))* - sin(qFirst)*sin(qSecond)+cos(qFirst)*cos(qSecond); + + Angle = (cos(phiFirst) * cos(phiSecond) + sin(phiFirst) * sin(phiSecond)) * sin(qFirst) * sin(qSecond) + + cos(qFirst) * cos(qSecond); Angle = acos(Angle); - + result = deltaOmega; - + return result; - } - /* - + compare the following: i) significance d0 < d0Cut @@ -3150,180 +2908,181 @@ float FullLDCTracking_MarlinTrk::CompareTrkII(TrackExtended * first, TrackExtend iii) pdot > 0.999 if above three cuts are passed return: - + the significance dAngle (return by reference) and the significance dOmega - + */ -float FullLDCTracking_MarlinTrk::CompareTrkIII(TrackExtended * first, TrackExtended * second, - float d0Cut, float z0Cut,int /*iopt*/, float & AngleSignificance) { - - +float FullLDCTracking_MarlinTrk::CompareTrkIII(TrackExtended* first, TrackExtended* second, float d0Cut, float z0Cut, + int /*iopt*/, float& AngleSignificance) { + float result = 1.0e+20; - + float d0First = first->getD0(); float z0First = first->getZ0(); float omegaFirst = first->getOmega(); float tanLFirst = first->getTanLambda(); float phiFirst = first->getPhi(); float qFirst = PIOVER2 - atan(tanLFirst); - - + float d0Second = second->getD0(); float z0Second = second->getZ0(); float omegaSecond = second->getOmega(); float tanLSecond = second->getTanLambda(); float phiSecond = second->getPhi(); float qSecond = PIOVER2 - atan(tanLSecond); - - - //MB 2010 03 + + // MB 2010 03 float d0ErrFirst = sqrt(first->getCovMatrix()[0]); float z0ErrFirst = sqrt(first->getCovMatrix()[9]); // float omegaErrFirst = sqrt(first->getCovMatrix()[5]); float phiErrFirst = sqrt(first->getCovMatrix()[2]); - float qErrFirst = sqrt(cos(qFirst)*cos(qFirst)*first->getCovMatrix()[14]); - //MB END - //MB 2010 03 + float qErrFirst = sqrt(cos(qFirst) * cos(qFirst) * first->getCovMatrix()[14]); + // MB END + // MB 2010 03 float d0ErrSecond = sqrt(second->getCovMatrix()[0]); float z0ErrSecond = sqrt(second->getCovMatrix()[9]); // float omegaErrSecond = sqrt(second->getCovMatrix()[5]); float phiErrSecond = sqrt(second->getCovMatrix()[2]); - float qErrSecond = sqrt(cos(qSecond)*cos(qSecond)*second->getCovMatrix()[14]); - //MB END - - + float qErrSecond = sqrt(cos(qSecond) * cos(qSecond) * second->getCovMatrix()[14]); + // MB END + // bool isCloseInIP = (fabs(d0First-d0Second)getCovMatrix()[5])/fabs(omegaFirst); - const float sigmaPOverPSecond = sqrt(second->getCovMatrix()[5])/fabs(omegaSecond); - const float deltaP = fabs(momFirst-momSecond); - const float sigmaPFirst = momFirst*sigmaPOverPFirst; - const float sigmaPSecond = momSecond*sigmaPOverPSecond; - const float sigmaDeltaP = sqrt(sigmaPFirst*sigmaPFirst+sigmaPSecond*sigmaPSecond); - const float significance = deltaP/sigmaDeltaP; - - //MB 2010 03 - float errorAngle =sin(phiFirst)*sin(phiFirst)*phiErrFirst*phiErrFirst*cos(phiSecond)*cos(phiSecond)+ - sin(phiSecond)*sin(phiSecond)*phiErrSecond*phiErrSecond*cos(phiFirst)*cos(phiFirst)+ - sin(qFirst)*sin(qFirst)*qErrFirst*qErrFirst*cos(qSecond)*cos(qSecond)+ - sin(qSecond)*sin(qSecond)*qErrSecond*qErrSecond*cos(qFirst)*cos(qFirst)+ - cos(phiFirst)*cos(phiFirst)*phiErrFirst*phiErrFirst*(sin(phiSecond)*sin(qFirst)*sin(qSecond))*(sin(phiSecond)*sin(qFirst)*sin(qSecond))+ - cos(phiSecond)*cos(phiSecond)*phiErrSecond*phiErrSecond*(sin(phiFirst)*sin(qFirst)*sin(qSecond))*(sin(phiFirst)*sin(qFirst)*sin(qSecond))+ - cos(qFirst)*cos(qFirst)*qErrFirst*qErrFirst*(sin(phiFirst)*sin(phiSecond)*sin(qSecond))*(sin(phiFirst)*sin(phiSecond)*sin(qSecond))+ - cos(qSecond)*cos(qSecond)*qErrSecond*qErrSecond*(sin(phiFirst)*sin(phiSecond)*sin(qFirst))*(sin(phiFirst)*sin(phiSecond)*sin(qFirst)); - - if(Angle<1.){ - errorAngle = sqrt(1./(1.-Angle*Angle)*errorAngle); - }else{ + + float pdot = (pFirst[0] * pSecond[0] + pFirst[1] * pSecond[1] + pFirst[2] * pSecond[2]) / momFirst / momSecond; + if (pdot < 0.999) + return result; + + const float sigmaPOverPFirst = sqrt(first->getCovMatrix()[5]) / fabs(omegaFirst); + const float sigmaPOverPSecond = sqrt(second->getCovMatrix()[5]) / fabs(omegaSecond); + const float deltaP = fabs(momFirst - momSecond); + const float sigmaPFirst = momFirst * sigmaPOverPFirst; + const float sigmaPSecond = momSecond * sigmaPOverPSecond; + const float sigmaDeltaP = sqrt(sigmaPFirst * sigmaPFirst + sigmaPSecond * sigmaPSecond); + const float significance = deltaP / sigmaDeltaP; + + // MB 2010 03 + float errorAngle = + sin(phiFirst) * sin(phiFirst) * phiErrFirst * phiErrFirst * cos(phiSecond) * cos(phiSecond) + + sin(phiSecond) * sin(phiSecond) * phiErrSecond * phiErrSecond * cos(phiFirst) * cos(phiFirst) + + sin(qFirst) * sin(qFirst) * qErrFirst * qErrFirst * cos(qSecond) * cos(qSecond) + + sin(qSecond) * sin(qSecond) * qErrSecond * qErrSecond * cos(qFirst) * cos(qFirst) + + cos(phiFirst) * cos(phiFirst) * phiErrFirst * phiErrFirst * (sin(phiSecond) * sin(qFirst) * sin(qSecond)) * + (sin(phiSecond) * sin(qFirst) * sin(qSecond)) + + cos(phiSecond) * cos(phiSecond) * phiErrSecond * phiErrSecond * (sin(phiFirst) * sin(qFirst) * sin(qSecond)) * + (sin(phiFirst) * sin(qFirst) * sin(qSecond)) + + cos(qFirst) * cos(qFirst) * qErrFirst * qErrFirst * (sin(phiFirst) * sin(phiSecond) * sin(qSecond)) * + (sin(phiFirst) * sin(phiSecond) * sin(qSecond)) + + cos(qSecond) * cos(qSecond) * qErrSecond * qErrSecond * (sin(phiFirst) * sin(phiSecond) * sin(qFirst)) * + (sin(phiFirst) * sin(phiSecond) * sin(qFirst)); + + if (Angle < 1.) { + errorAngle = sqrt(1. / (1. - Angle * Angle) * errorAngle); + } else { errorAngle = sqrt(errorAngle); } - - if(errorAngle<1.e-6)errorAngle=1.e-6; - - AngleSignificance = fabs(acos(Angle)/errorAngle); - + + if (errorAngle < 1.e-6) + errorAngle = 1.e-6; + + AngleSignificance = fabs(acos(Angle) / errorAngle); + return significance; - } - /* - + compare the following: - + i) delta d0 < d0Cut and optionally (d0_1 + d0_2) < d0cut ii) delta z0 < z0Cut - + if above two cuts are passed then: - + if ( (ptFirst<_PtCutToMergeTPC) && (ptSecond<_PtCutToMergeTPC) ) { - - then check the difference in momentum - - else - + + then check the difference in momentum + + else + check for cases where PatRec splits non-looping TPC tracks look for two tracks where total tpc hits are not more than total number of pad rows and that the hits on one track are close to the helix of the other track. - + Check that the angular and momentum difference meets the cuts for either hight or low pt - also check if the angle is very small between the tracks and that the significance of the difference in pt is less than 10 - - - .... - + also check if the angle is very small between the tracks and that the significance of the difference in pt is less + than 10 + + + .... + note currently this is only used in AddNotCombinedTracks - + */ +float FullLDCTracking_MarlinTrk::CompareTrk(TrackExtended* first, TrackExtended* second, float d0Cut, float z0Cut, + int iopt) { -float FullLDCTracking_MarlinTrk::CompareTrk(TrackExtended * first, TrackExtended * second, - float d0Cut, float z0Cut,int iopt) { - float result = 1.0e+20; - + float d0First = first->getD0(); float z0First = first->getZ0(); float omegaFirst = first->getOmega(); float tanLFirst = first->getTanLambda(); float phiFirst = first->getPhi(); - + float d0Second = second->getD0(); float z0Second = second->getZ0(); float omegaSecond = second->getOmega(); float tanLSecond = second->getTanLambda(); float phiSecond = second->getPhi(); - - bool isCloseInIP = (fabs(d0First-d0Second)0) isCloseInIP = isCloseInIP || (fabs(d0First+d0Second) 0) + isCloseInIP = isCloseInIP || (fabs(d0First + d0Second) < d0Cut); + + isCloseInIP = isCloseInIP && (fabs(z0Second - z0First) < z0Cut); + HelixClass helixFirst; - helixFirst.Initialize_Canonical(phiFirst,d0First,z0First,omegaFirst,tanLFirst,_bField); + helixFirst.Initialize_Canonical(phiFirst, d0First, z0First, omegaFirst, tanLFirst, _bField); HelixClass helixSecond; - helixSecond.Initialize_Canonical(phiSecond,d0Second,z0Second,omegaSecond,tanLSecond,_bField); - + helixSecond.Initialize_Canonical(phiSecond, d0Second, z0Second, omegaSecond, tanLSecond, _bField); + float pFirst[3]; float pSecond[3]; float dPminus[3]; @@ -3332,133 +3091,126 @@ float FullLDCTracking_MarlinTrk::CompareTrk(TrackExtended * first, TrackExtended float momSecond = 0; float momMinus = 0; float momPlus = 0; - - if ( isCloseInIP ) { - - for (int iC=0;iC<3;++iC) { + + if (isCloseInIP) { + + for (int iC = 0; iC < 3; ++iC) { pFirst[iC] = helixFirst.getMomentum()[iC]; pSecond[iC] = helixSecond.getMomentum()[iC]; - momFirst += pFirst[iC]* pFirst[iC]; - momSecond += pSecond[iC]*pSecond[iC]; + momFirst += pFirst[iC] * pFirst[iC]; + momSecond += pSecond[iC] * pSecond[iC]; dPminus[iC] = pFirst[iC] - pSecond[iC]; dPplus[iC] = pFirst[iC] + pSecond[iC]; - momMinus += dPminus[iC]*dPminus[iC]; - momPlus += dPplus[iC]*dPplus[iC]; + momMinus += dPminus[iC] * dPminus[iC]; + momPlus += dPplus[iC] * dPplus[iC]; } momFirst = sqrt(momFirst); momSecond = sqrt(momSecond); - - float ptFirst = sqrt(pFirst[0]*pFirst[0]+pFirst[1]*pFirst[1]); - float ptSecond = sqrt(pSecond[0]*pSecond[0]+pSecond[1]*pSecond[1]); - + + float ptFirst = sqrt(pFirst[0] * pFirst[0] + pFirst[1] * pFirst[1]); + float ptSecond = sqrt(pSecond[0] * pSecond[0] + pSecond[1] * pSecond[1]); + // if both track's pt are lower than _PtCutToMergeTPC - if ( (ptFirst<_PtCutToMergeTPC) && (ptSecond<_PtCutToMergeTPC) ) { - + if ((ptFirst < _PtCutToMergeTPC) && (ptSecond < _PtCutToMergeTPC)) { + momMinus = sqrt(momMinus); momPlus = sqrt(momPlus); float nom = momMinus; // get the smaller difference for the nominator - if (momPlus0) + if (momPlus < nom && iopt > 0) nom = momPlus; float den = momFirst; // get the smallest momentum for the denominator - if (momSecondgetCovMatrix()[5])/fabs(omegaFirst); - const float sigmaPOverPSecond = sqrt(second->getCovMatrix()[5])/fabs(omegaSecond); - const float deltaP = fabs(momFirst-momSecond); - const float sigmaPFirst = momFirst*sigmaPOverPFirst; - const float sigmaPSecond = momSecond*sigmaPOverPSecond; - const float sigmaDeltaP = sqrt(sigmaPFirst*sigmaPFirst+sigmaPSecond*sigmaPSecond); - const float significance = deltaP/sigmaDeltaP; - - - //compare angle between the two vectors (cos theta) and their momentum - // if( ( pdot>0.99 && dpOverP<0.01 ) || ( pdot>0.998 && dpOverP<0.25 ) ){ - if( (pdot>_cosThetaCutHighPtMerge && dpOverP<_momDiffCutHighPtMerge) - || - (pdot>_cosThetaCutSoftHighPtMerge && dpOverP<_momDiffCutSoftHighPtMerge) - || (pdot > 0.9999 && significance <10) - ){ - - + + float dpOverP = 2.0 * fabs(momFirst - momSecond) / (momFirst + momSecond); + const float pdot = + (pFirst[0] * pSecond[0] + pFirst[1] * pSecond[1] + pFirst[2] * pSecond[2]) / momFirst / momSecond; + const float sigmaPOverPFirst = sqrt(first->getCovMatrix()[5]) / fabs(omegaFirst); + const float sigmaPOverPSecond = sqrt(second->getCovMatrix()[5]) / fabs(omegaSecond); + const float deltaP = fabs(momFirst - momSecond); + const float sigmaPFirst = momFirst * sigmaPOverPFirst; + const float sigmaPSecond = momSecond * sigmaPOverPSecond; + const float sigmaDeltaP = sqrt(sigmaPFirst * sigmaPFirst + sigmaPSecond * sigmaPSecond); + const float significance = deltaP / sigmaDeltaP; + + // compare angle between the two vectors (cos theta) and their momentum + // if( ( pdot>0.99 && dpOverP<0.01 ) || ( pdot>0.998 && dpOverP<0.25 ) ){ + if ((pdot > _cosThetaCutHighPtMerge && dpOverP < _momDiffCutHighPtMerge) || + (pdot > _cosThetaCutSoftHighPtMerge && dpOverP < _momDiffCutSoftHighPtMerge) || + (pdot > 0.9999 && significance < 10)) { + int nTrkGrpFirst = 0; int nTrkGrpSecond = 0; TrackerHitVec hitvecFirst; TrackerHitVec hitvecSecond; - GroupTracks * groupFirst = first->getGroupTracks(); - GroupTracks * groupSecond = second->getGroupTracks(); + GroupTracks* groupFirst = first->getGroupTracks(); + GroupTracks* groupSecond = second->getGroupTracks(); // does the first track belong to a group ... // if it does then get all the hits from the group - if(groupFirst!=NULL){ - + if (groupFirst != NULL) { + TrackExtendedVec tracksInGroupFirst = groupFirst->getTrackExtendedVec(); nTrkGrpFirst = int(tracksInGroupFirst.size()); - - for (int iTrkGrp=0;iTrkGrpgetTrackerHitExtendedVec(); - - for(unsigned int i =0; igetTrackerHit()); + + for (unsigned int i = 0; i < hitVec.size(); ++i) { + hitvecFirst.push_back(hitVec[i]->getTrackerHit()); } } } // does the second track belong to a group ... // if it does then get all the hits from the group - if(groupSecond!=NULL){ - + if (groupSecond != NULL) { + TrackExtendedVec tracksInGroupSecond = groupSecond->getTrackExtendedVec(); nTrkGrpSecond = int(tracksInGroupSecond.size()); - - for (int iTrkGrp=0;iTrkGrpgetTrackerHitExtendedVec(); - - for(unsigned int i=0;igetTrackerHitExtendedVec(); + + for (unsigned int i = 0; i < hitVec.size(); ++i) { hitvecSecond.push_back(hitVec[i]->getTrackerHit()); } } } - - - - // for non-looping tracks - int nhitsFirst = (int)hitvecFirst.size(); + + // for non-looping tracks + int nhitsFirst = (int)hitvecFirst.size(); int nhitsSecond = (int)hitvecSecond.size(); - int ntpcFirst = 0; - int ntpcSecond = 0; + int ntpcFirst = 0; + int ntpcSecond = 0; float hitxyz[3]; float dist[3]; - float maxdistFirst=0; - float maxdistSecond=0; + float maxdistFirst = 0; + float maxdistSecond = 0; int ncloseFirst = 0; int ncloseSecond = 0; float zminFirst = 99999; @@ -3466,354 +3218,344 @@ float FullLDCTracking_MarlinTrk::CompareTrk(TrackExtended * first, TrackExtended float zmaxFirst = -99999; float zmaxSecond = -99999; - - for(int ih =0;ihgetPosition()[0]; - float y = (float) hitvecFirst[ih]->getPosition()[1]; - float z = (float) hitvecFirst[ih]->getPosition()[2]; - - if(fabs(z)zmaxFirst) zmaxFirst=fabs(z); - - float r = sqrt(x*x+y*y); - + for (int ih = 0; ih < nhitsFirst; ++ih) { + + float x = (float)hitvecFirst[ih]->getPosition()[0]; + float y = (float)hitvecFirst[ih]->getPosition()[1]; + float z = (float)hitvecFirst[ih]->getPosition()[2]; + + if (fabs(z) < zminFirst) + zminFirst = fabs(z); + if (fabs(z) > zmaxFirst) + zmaxFirst = fabs(z); + + float r = sqrt(x * x + y * y); + // count the number of hits in the TPC for the first Track - if(r>_tpc_inner_r) ntpcFirst++; - - hitxyz[0]=x; - hitxyz[1]=y; - hitxyz[2]=z; + if (r > _tpc_inner_r) + ntpcFirst++; + + hitxyz[0] = x; + hitxyz[1] = y; + hitxyz[2] = z; helixSecond.getDistanceToPoint(hitxyz, dist); - + // compare 3D distance between hit and extrapolation - if(dist[2]>maxdistFirst) maxdistFirst=dist[2]; + if (dist[2] > maxdistFirst) + maxdistFirst = dist[2]; - // count the number of hits from the first track which are closer than _hitDistanceCutHighPtMerge to the second track - if(dist[2]<_hitDistanceCutHighPtMerge) ncloseFirst++; + // count the number of hits from the first track which are closer than _hitDistanceCutHighPtMerge to the + // second track + if (dist[2] < _hitDistanceCutHighPtMerge) + ncloseFirst++; } - - for(int ih =0;ihgetPosition()[0]; float y = (float)hitvecSecond[ih]->getPosition()[1]; float z = (float)hitvecSecond[ih]->getPosition()[2]; - - if(fabs(z)zmaxSecond) zmaxSecond=fabs(z); - - float r = sqrt(x*x+y*y); - + + if (fabs(z) < zminSecond) + zminSecond = fabs(z); + if (fabs(z) > zmaxSecond) + zmaxSecond = fabs(z); + + float r = sqrt(x * x + y * y); + // count the number of hits in the TPC for the second Track - if(r>_tpc_inner_r) ntpcSecond++; - - hitxyz[0]=x; - hitxyz[1]=y; - hitxyz[2]=z; + if (r > _tpc_inner_r) + ntpcSecond++; + + hitxyz[0] = x; + hitxyz[1] = y; + hitxyz[2] = z; helixFirst.getDistanceToPoint(hitxyz, dist); - - // compare 3D distance between hit and extrapolation - if(dist[2]>maxdistSecond) maxdistSecond=dist[2]; - // count the number of hits from the second track which are closer than _hitDistanceCutHighPtMerge to the first track - if(dist[2]<_hitDistanceCutHighPtMerge) ncloseSecond++; + // compare 3D distance between hit and extrapolation + if (dist[2] > maxdistSecond) + maxdistSecond = dist[2]; + // count the number of hits from the second track which are closer than _hitDistanceCutHighPtMerge to the + // first track + if (dist[2] < _hitDistanceCutHighPtMerge) + ncloseSecond++; } - - + // calculate the fraction of hits which are closer than _hitDistanceCutHighPtMerge - float fcloseFirst = (float)ncloseFirst/(float)nhitsFirst; - float fcloseSecond = (float)ncloseSecond/(float)nhitsSecond; - - - + float fcloseFirst = (float)ncloseFirst / (float)nhitsFirst; + float fcloseSecond = (float)ncloseSecond / (float)nhitsSecond; + bool split = false; - //std::cout << "Momenta = " << momFirst << " " << momSecond << std::endl; - //std::cout << "MaxDist = " << maxdistSecond << " " << maxdistFirst << " " << _maxHitDistanceCutHighPtMerge << std::endl; - //std::cout << "close = " << fcloseSecond << " " << fcloseFirst << " " << _maxFractionOfOutliersCutHighPtMerge << std::endl; - //std::cout << "ntpc = " << ntpcFirst << " " << ntpcSecond << " " << _tpc_pad_height+10 << std::endl; - //std::cout << "pdot = " << pdot << " significance " << significance << std::endl; - - + // std::cout << "Momenta = " << momFirst << " " << momSecond << std::endl; + // std::cout << "MaxDist = " << maxdistSecond << " " << maxdistFirst << " " << _maxHitDistanceCutHighPtMerge << + // std::endl; std::cout << "close = " << fcloseSecond << " " << fcloseFirst << " " << + // _maxFractionOfOutliersCutHighPtMerge << std::endl; std::cout << "ntpc = " << ntpcFirst << " " << + // ntpcSecond << " " << _tpc_pad_height+10 << std::endl; std::cout << "pdot = " << pdot << " significance " + // << significance << std::endl; + // SJA:FIXME: try to fit the two tracks, without checking the number of hits which are close !!!!!!!!!!! - TrackExtended * combinedTrack = CombineTracks(first,second, _maxAllowedPercentageOfOutliersForTrackCombination, true); + TrackExtended* combinedTrack = + CombineTracks(first, second, _maxAllowedPercentageOfOutliersForTrackCombination, true); // check that no more than 5 hits have been discared in the fit of the combined track - if(combinedTrack != NULL){ - //std::cout << "CombinedTrack " << combinedTrack->getNDF() << " c.f. " << first->getNDF()+second->getNDF()+5 << std::endl; - if(combinedTrack->getNDF()+10>first->getNDF()+second->getNDF()+5){ + if (combinedTrack != NULL) { + // std::cout << "CombinedTrack " << combinedTrack->getNDF() << " c.f. " << first->getNDF()+second->getNDF()+5 + // << std::endl; + if (combinedTrack->getNDF() + 10 > first->getNDF() + second->getNDF() + 5) { split = true; dpOverP = 0; - //std::cout << " Forcing MERGE " << std::endl; + // std::cout << " Forcing MERGE " << std::endl; } delete combinedTrack->getGroupTracks(); delete combinedTrack; - } - else { - //std::cout << "Could not combine track " << std::endl; - // if close in pt and the fraction of hits matching the helix extraolations is greater than _maxFractionOfOutliersCutHighPtMerge - if(significance<5 && fcloseFirst>_maxFractionOfOutliersCutHighPtMerge){ + } else { + // std::cout << "Could not combine track " << std::endl; + // if close in pt and the fraction of hits matching the helix extraolations is greater than + // _maxFractionOfOutliersCutHighPtMerge + if (significance < 5 && fcloseFirst > _maxFractionOfOutliersCutHighPtMerge) { split = true; dpOverP = 0; // int overlap = SegmentRadialOverlap(first,second); - //std::cout << " Forcing MERGE " << overlap << std::endl; + // std::cout << " Forcing MERGE " << overlap << std::endl; } } - + // criteria for split track // old criterion - // check the maximum deviation of the hits from the helix extrapolations, and fraction of hits matching the extrapolation based on a distance cut - if( maxdistSecond < _maxHitDistanceCutHighPtMerge && maxdistFirst < _maxHitDistanceCutHighPtMerge - && - (fcloseSecond > _maxFractionOfOutliersCutHighPtMerge || fcloseFirst > _maxFractionOfOutliersCutHighPtMerge) - ){ -// && -// ntpcFirst+ntpcSecond < _tpc_pad_height+10.) { // SJA:FIXME: this must be a bug, first it is a double, and second this value is never initialised ... - - split = true; - + // check the maximum deviation of the hits from the helix extrapolations, and fraction of hits matching the + // extrapolation based on a distance cut + if (maxdistSecond < _maxHitDistanceCutHighPtMerge && maxdistFirst < _maxHitDistanceCutHighPtMerge && + (fcloseSecond > _maxFractionOfOutliersCutHighPtMerge || + fcloseFirst > _maxFractionOfOutliersCutHighPtMerge)) { + // && + // ntpcFirst+ntpcSecond < _tpc_pad_height+10.) { // SJA:FIXME: this must be a bug, first it is a + // double, and second this value is never initialised ... + + split = true; } - - if(split){ + + if (split) { result = dpOverP; } - } } } - + return result; - } void FullLDCTracking_MarlinTrk::AddNotAssignedHits() { - - - // currently any non-combined Silicon or TPC tracks are added to the list of tracks meaning their hits will not be available to be picked up. - // it might be preferable to drop these tracks, at least for track in Silicon with very bad Chi2 probabilities, and allow their hits to be re-used here ... - - - - if (_assignSETHits>0) { // Assignment of SET Hits - - streamlog_out(DEBUG4) << "Assign SET hits *********************************" << std::endl; - - // Creating helix extrapolations - CreateExtrapolations(); - - int nSETHits = _allSETHits.size(); - std::vector SETHits; - - SETHits.resize(_nLayersSET); - - for (int iSET=0;iSETgetTrackerHit(); - int layer = getLayerID(trkHit); - if (layer>=0 && (unsigned)layer < _nLayersSET) - SETHits[layer].push_back(trkHitExt); - } - for (unsigned iL=0; iL< _nLayersSET; ++iL) { // loop over SET layers - TrackerHitExtendedVec hitVec = SETHits[iL]; - int refit = 1; - if(hitVec.empty() == false) AssignOuterHitsToTracks(hitVec,_distCutForSETHits,refit); - } - } - - + + // currently any non-combined Silicon or TPC tracks are added to the list of tracks meaning their hits will not be + // available to be picked up. it might be preferable to drop these tracks, at least for track in Silicon with very bad + // Chi2 probabilities, and allow their hits to be re-used here ... + + if (_assignSETHits > 0) { // Assignment of SET Hits + + streamlog_out(DEBUG4) << "Assign SET hits *********************************" << std::endl; + + // Creating helix extrapolations + CreateExtrapolations(); + + int nSETHits = _allSETHits.size(); + std::vector SETHits; + + SETHits.resize(_nLayersSET); + + for (int iSET = 0; iSET < nSETHits; ++iSET) { + TrackerHitExtended* trkHitExt = _allSETHits[iSET]; + TrackerHit* trkHit = trkHitExt->getTrackerHit(); + int layer = getLayerID(trkHit); + if (layer >= 0 && (unsigned)layer < _nLayersSET) + SETHits[layer].push_back(trkHitExt); + } + for (unsigned iL = 0; iL < _nLayersSET; ++iL) { // loop over SET layers + TrackerHitExtendedVec hitVec = SETHits[iL]; + int refit = 1; + if (hitVec.empty() == false) + AssignOuterHitsToTracks(hitVec, _distCutForSETHits, refit); + } + } + CleanUpExtrapolations(); - - - if (_assignSITHits>0) { // Treatment of left-over SIT hits - + + if (_assignSITHits > 0) { // Treatment of left-over SIT hits + streamlog_out(DEBUG4) << "Assign SIT hits *********************************" << std::endl; - - std::vector nonAssignedSITHits; + + std::vector nonAssignedSITHits; nonAssignedSITHits.resize(_nLayersSIT); - - int nSITHits = int(_allSITHits.size()); - + + int nSITHits = int(_allSITHits.size()); + // loop over all SIT hits ... - for (int iH=0;iHgetTrackExtended(); - + for (int iH = 0; iH < nSITHits; ++iH) { + + TrackerHitExtended* trkHitExt = _allSITHits[iH]; + TrackExtended* trkExt = trkHitExt->getTrackExtended(); + // check if this hit has not already been assigned to a track if (trkExt == NULL) { - TrackerHit * trkHit = trkHitExt->getTrackerHit(); - + TrackerHit* trkHit = trkHitExt->getTrackerHit(); + int layer = getLayerID(trkHit); - - if (layer >=0 && (unsigned)layer < _nLayersSIT) { + + if (layer >= 0 && (unsigned)layer < _nLayersSIT) { nonAssignedSITHits[layer].push_back(trkHitExt); } } - } - - for (int iL=_nLayersSIT-1;iL>=0;--iL) { // reverse loop over layers in Si - + } + + for (int iL = _nLayersSIT - 1; iL >= 0; --iL) { // reverse loop over layers in Si + TrackerHitExtendedVec hitVec = nonAssignedSITHits[iL]; - - if ( hitVec.empty() == false ) { - streamlog_out(DEBUG3) << "AddNotAssignedHits : Try to assign hits from layer " << iL << " : Number of hits = " << hitVec.size() << std::endl; - AssignSiHitsToTracks(hitVec, - _distCutForSITHits); - + + if (hitVec.empty() == false) { + streamlog_out(DEBUG3) << "AddNotAssignedHits : Try to assign hits from layer " << iL + << " : Number of hits = " << hitVec.size() << std::endl; + AssignSiHitsToTracks(hitVec, _distCutForSITHits); } - } } - - if (_assignFTDHits>0) { // Treatment of left-over FTD hits - + + if (_assignFTDHits > 0) { // Treatment of left-over FTD hits + streamlog_out(DEBUG4) << "Assign FTD hits *********************************" << std::endl; - + std::vector nonAssignedFTDHits; nonAssignedFTDHits.resize(_nLayersFTD); - + int nFTDHits = int(_allFTDHits.size()); - + // loop over all FTD hits ... - for (int iH=0;iHgetTrackExtended(); - + for (int iH = 0; iH < nFTDHits; ++iH) { + + TrackerHitExtended* trkHitExt = _allFTDHits[iH]; + TrackExtended* trkExt = trkHitExt->getTrackExtended(); + // check if this hit has not already been assigned to a track if (trkExt == NULL) { - TrackerHit * trkHit = trkHitExt->getTrackerHit(); - - + TrackerHit* trkHit = trkHitExt->getTrackerHit(); + // get the layer number int layer = getLayerID(trkHit); int petalIndex = getModuleID(trkHit); - - if ( _petalBasedFTDWithOverlaps == true ) { - + + if (_petalBasedFTDWithOverlaps == true) { + // as we are dealing with staggered petals we will use 2*nlayers in each directions +/- z - // the layers will follow the even odd numbering of the petals - if ( petalIndex % 2 == 0 ) { - layer = 2*layer; + // the layers will follow the even odd numbering of the petals + if (petalIndex % 2 == 0) { + layer = 2 * layer; + } else { + layer = 2 * layer + 1; } - else { - layer = 2*layer + 1; - } - } - - if (layer >=0 && layer < (int)_nLayersFTD) + + if (layer >= 0 && layer < (int)_nLayersFTD) nonAssignedFTDHits[layer].push_back(trkHitExt); } } - for (int iL=_nLayersFTD-1;iL>=0;--iL) { - if ( nonAssignedFTDHits[iL].empty() == false ) { - + for (int iL = _nLayersFTD - 1; iL >= 0; --iL) { + if (nonAssignedFTDHits[iL].empty() == false) { + TrackerHitExtendedVec hitVec = nonAssignedFTDHits[iL]; - streamlog_out(DEBUG3) << "AddNotAssignedHits : Try to assign hits from layer " << iL << " : Number of hits = " << hitVec.size() << std::endl; - AssignSiHitsToTracks(hitVec, - _distCutForFTDHits); - + streamlog_out(DEBUG3) << "AddNotAssignedHits : Try to assign hits from layer " << iL + << " : Number of hits = " << hitVec.size() << std::endl; + AssignSiHitsToTracks(hitVec, _distCutForFTDHits); } } } - - - - if (_assignVTXHits>0) { // Treatment of left-over VTX hits - + + if (_assignVTXHits > 0) { // Treatment of left-over VTX hits + streamlog_out(DEBUG4) << "Assign VXD hits *********************************" << std::endl; - + std::vector nonAssignedVTXHits; nonAssignedVTXHits.resize(_nLayersVTX); - + int nVTXHits = int(_allVTXHits.size()); - + // loop over all VXD hits ... - for (int iH=0;iHgetTrackExtended(); - + for (int iH = 0; iH < nVTXHits; ++iH) { + + TrackerHitExtended* trkHitExt = _allVTXHits[iH]; + TrackExtended* trkExt = trkHitExt->getTrackExtended(); + // check if this hit has not already been assigned to a track if (trkExt == NULL) { - TrackerHit * trkHit = trkHitExt->getTrackerHit(); - + TrackerHit* trkHit = trkHitExt->getTrackerHit(); + int layer = getLayerID(trkHit); - - if (layer >=0 && layer < (int)_nLayersVTX) + + if (layer >= 0 && layer < (int)_nLayersVTX) nonAssignedVTXHits[layer].push_back(trkHitExt); } } - for (int iL=_nLayersVTX-1;iL>=0;--iL) { - if ( nonAssignedVTXHits[iL].empty() == false ) { - + for (int iL = _nLayersVTX - 1; iL >= 0; --iL) { + if (nonAssignedVTXHits[iL].empty() == false) { + TrackerHitExtendedVec hitVec = nonAssignedVTXHits[iL]; - streamlog_out(DEBUG3) << "AddNotAssignedHits : Try to assign hits from layer " << iL << " : Number of hits = " << hitVec.size() << std::endl; - AssignSiHitsToTracks(hitVec, - _distCutForVTXHits); + streamlog_out(DEBUG3) << "AddNotAssignedHits : Try to assign hits from layer " << iL + << " : Number of hits = " << hitVec.size() << std::endl; + AssignSiHitsToTracks(hitVec, _distCutForVTXHits); } } } - + streamlog_out(DEBUG4) << "Assign TPC hits *********************************" << std::endl; - - if (_assignTPCHits) {// Treatment of left-over TPC hits + + if (_assignTPCHits) { // Treatment of left-over TPC hits TrackerHitExtendedVec nonAssignedTPCHits; int nTPCHits = int(_allTPCHits.size()); - for (int iH=0;iHgetTrackExtended(); + for (int iH = 0; iH < nTPCHits; ++iH) { + TrackerHitExtended* trkHitExt = _allTPCHits[iH]; + TrackExtended* trkExt = trkHitExt->getTrackExtended(); if (trkExt == NULL) { nonAssignedTPCHits.push_back(trkHitExt); } } - streamlog_out(DEBUG4) << "AddNotAssignedHits : Number of Non Assigned TPC hits = " << nonAssignedTPCHits.size() << std::endl; - AssignTPCHitsToTracks(nonAssignedTPCHits, - _distCutForTPCHits); + streamlog_out(DEBUG4) << "AddNotAssignedHits : Number of Non Assigned TPC hits = " << nonAssignedTPCHits.size() + << std::endl; + AssignTPCHitsToTracks(nonAssignedTPCHits, _distCutForTPCHits); } - - } - void FullLDCTracking_MarlinTrk::CreateExtrapolations() { - + _trackExtrapolatedHelix.clear(); - + int nTrk = int(_trkImplVec.size()); - for (int iTrk=0; iTrkgetDistanceToPoint(pos,dcut); - + + float distance = helix->getDistanceToPoint(pos, dcut); + streamlog_out(DEBUG1) << "for helix extrapolation " << helix << " distance = " << distance << std::endl; - + // check the distance is less than the steerable cut ... - if (distancegetTrackerHit(); + TrackerHit* remainHit = trkHitExt->getTrackerHit(); iHitInFit++; trkHits.push_back(remainHit); - - + double chi2_D; int ndf; - - - if( trkHits.size() < 3 ) return ; - + + if (trkHits.size() < 3) + return; + // sort the hits in R - std::vector< std::pair > r2_values; + std::vector> r2_values; r2_values.reserve(trkHits.size()); - - for (TrackerHitVec::iterator it=trkHits.begin(); it!=trkHits.end(); ++it) { + + for (TrackerHitVec::iterator it = trkHits.begin(); it != trkHits.end(); ++it) { EVENT::TrackerHit* h = *it; - float r2 = h->getPosition()[0]*h->getPosition()[0]+h->getPosition()[1]*h->getPosition()[1]; + float r2 = h->getPosition()[0] * h->getPosition()[0] + h->getPosition()[1] * h->getPosition()[1]; r2_values.push_back(std::make_pair(r2, *it)); } - - sort(r2_values.begin(),r2_values.end()); - + + sort(r2_values.begin(), r2_values.end()); + trkHits.clear(); trkHits.reserve(r2_values.size()); - - for (std::vector< std::pair >::iterator it=r2_values.begin(); it!=r2_values.end(); ++it) { + + for (std::vector>::iterator it = r2_values.begin(); + it != r2_values.end(); ++it) { trkHits.push_back(it->second); } - - - streamlog_out(DEBUG3) << "AssignOuterHitsToTracks: Start Fitting: AddHits: number of hits to fit " << trkHits.size() << std::endl; - - + + streamlog_out(DEBUG3) << "AssignOuterHitsToTracks: Start Fitting: AddHits: number of hits to fit " + << trkHits.size() << std::endl; + MarlinTrk::IMarlinTrack* marlin_trk = _trksystem->createTrack(); - - IMPL::TrackStateImpl pre_fit ; - - + + IMPL::TrackStateImpl pre_fit; + pre_fit.setD0(trkExt->getD0()); pre_fit.setPhi(trkExt->getPhi()); pre_fit.setZ0(trkExt->getZ0()); pre_fit.setOmega(trkExt->getOmega()); pre_fit.setTanLambda(trkExt->getTanLambda()); - + float ref[3]; - ref[0]=ref[1]=ref[2]=0.0; - + ref[0] = ref[1] = ref[2] = 0.0; + pre_fit.setReferencePoint(ref); - - pre_fit.setLocation(lcio::TrackStateImpl::AtIP); + + pre_fit.setLocation(lcio::TrackStateImpl::AtIP); // setup initial dummy covariance matrix EVENT::FloatVec covMatrix; covMatrix.resize(15); - - for (unsigned icov = 0; icov > outliers ; + + std::vector> outliers; marlin_trk->getOutliers(outliers); - - float outlier_pct = outliers.size()/float(trkHits.size()) ; - - streamlog_out(DEBUG1) << "FullLDCTracking_MarlinTrk::AssignOuterHitsToTracks: percentage of outliers " << outlier_pct << std::endl; - - if ( outlier_pct > _maxAllowedPercentageOfOutliersForTrackCombination) { - - streamlog_out(DEBUG2) << "FullLDCTracking_MarlinTrk::AssignOuterHitsToTracks: percentage of outliers " << outlier_pct << " is greater than cut maximum: " << _maxAllowedPercentageOfOutliersForTrackCombination << std::endl; - delete marlin_trk ; - continue ; + float outlier_pct = outliers.size() / float(trkHits.size()); + + streamlog_out(DEBUG1) << "FullLDCTracking_MarlinTrk::AssignOuterHitsToTracks: percentage of outliers " + << outlier_pct << std::endl; + + if (outlier_pct > _maxAllowedPercentageOfOutliersForTrackCombination) { + + streamlog_out(DEBUG2) << "FullLDCTracking_MarlinTrk::AssignOuterHitsToTracks: percentage of outliers " + << outlier_pct << " is greater than cut maximum: " + << _maxAllowedPercentageOfOutliersForTrackCombination << std::endl; + delete marlin_trk; + continue; } - - const Vector3D point(0.,0.,0.); // nominal IP - TrackStateImpl trkState ; + + const Vector3D point(0., 0., 0.); // nominal IP + TrackStateImpl trkState; // int return_code = - marlin_trk->propagate(point, trkState, chi2_D, ndf ) ; - - delete marlin_trk ; - - if ( error != IMarlinTrack::success ) { - - streamlog_out(DEBUG3) << "FullLDCTracking_MarlinTrk::AssignOuterHitsToTracks: propagate to IP fails with error " << error << std::endl; - - continue ; - + marlin_trk->propagate(point, trkState, chi2_D, ndf); + + delete marlin_trk; + + if (error != IMarlinTrack::success) { + + streamlog_out(DEBUG3) + << "FullLDCTracking_MarlinTrk::AssignOuterHitsToTracks: propagate to IP fails with error " << error + << std::endl; + + continue; } - - if ( ndf < 0 ) { - - streamlog_out(DEBUG2) << "FullLDCTracking_MarlinTrk::AssignOuterHitsToTracks: Fit failed : NDF is less that zero " << ndf << std::endl; - - continue ; - + + if (ndf < 0) { + + streamlog_out(DEBUG2) + << "FullLDCTracking_MarlinTrk::AssignOuterHitsToTracks: Fit failed : NDF is less that zero " << ndf + << std::endl; + + continue; } - - - float chi2Fit = chi2_D/float(ndf); - - if ( chi2Fit > _chi2FitCut ) { - - streamlog_out(DEBUG2) << "FullLDCTracking_MarlinTrk::AssignOuterHitsToTracks: track fail Chi2 cut of " << _chi2FitCut << " chi2 of track = " << chi2Fit << std::endl; - - return ; - + + float chi2Fit = chi2_D / float(ndf); + + if (chi2Fit > _chi2FitCut) { + + streamlog_out(DEBUG2) << "FullLDCTracking_MarlinTrk::AssignOuterHitsToTracks: track fail Chi2 cut of " + << _chi2FitCut << " chi2 of track = " << chi2Fit << std::endl; + + return; } - - - + // note trackAR which is of type TrackExtended, only takes fits with ref point = 0,0,0 trkExt->setOmega(trkState.getOmega()); trkExt->setTanLambda(trkState.getTanLambda()); trkExt->setPhi(trkState.getPhi()); trkExt->setD0(trkState.getD0()); trkExt->setZ0(trkState.getZ0()); - - + float cov[15]; - - for (int i = 0 ; i<15 ; ++i) { + + for (int i = 0; i < 15; ++i) { cov[i] = trkState.getCovMatrix().operator[](i); } - + trkExt->setCovMatrix(cov); trkExt->setChi2(chi2_D); trkExt->setNDF(ndf); - - trkExt->addTrackerHitExtended( trkHitExt ); - trkHitExt->setTrackExtended( trkExt ); - trkHitExt->setUsedInFit( true ); + + trkExt->addTrackerHitExtended(trkHitExt); + trkHitExt->setTrackExtended(trkExt); + trkHitExt->setUsedInFit(true); flagTrack[trkExt] = false; flagHit[trkHitExt] = false; - - - streamlog_out(DEBUG2) << "AssignOuterHitsToTracks: Hit " << trkHitExt << " successfully assigned to track " << trkExt << std::endl; - - + streamlog_out(DEBUG2) << "AssignOuterHitsToTracks: Hit " << trkHitExt << " successfully assigned to track " + << trkExt << std::endl; } } } - - for (int iP=0;iPgetGroupTracks(); - + TrackExtendedVec trk_vec = group->getTrackExtendedVec(); - + const EVENT::TrackState* ts_at_calo = 0; float z_ref_max = 0; - - streamlog_out(DEBUG3) << "FullLDCTracking_MarlinTrk::GetExtrapolationHelix number of tracks associated = " << trk_vec.size() << std::endl; - - for (unsigned itrk=0; itrkInitialize_Canonical(ts_at_calo_forIP.getPhi(), ts_at_calo_forIP.getD0(), ts_at_calo_forIP.getZ0(), + ts_at_calo_forIP.getOmega(), ts_at_calo_forIP.getTanLambda(), _bField); + + streamlog_out(DEBUG3) << "FullLDCTracking_MarlinTrk::GetExtrapolationHelix helix created at IP" << std::endl; } - + return helix; - } +void FullLDCTracking_MarlinTrk::AssignTPCHitsToTracks(TrackerHitExtendedVec hitVec, float dcut) { -void FullLDCTracking_MarlinTrk::AssignTPCHitsToTracks(TrackerHitExtendedVec hitVec, - float dcut) { - int nHits = int(hitVec.size()); int nTrk = int(_trkImplVec.size()); - - for (int iT=0;iTgetGroupTracks(); + + for (int iT = 0; iT < nTrk; ++iT) { // loop over all tracks + TrackExtended* foundTrack = _trkImplVec[iT]; + GroupTracks* group = foundTrack->getGroupTracks(); TrackExtendedVec tracksInGroup = group->getTrackExtendedVec(); int nTrkGrp = int(tracksInGroup.size()); - for (int iTrkGrp=0;iTrkGrpgetTrackerHitExtendedVec(); int nHits_Grp = int(hitVecGrp.size()); float zMin = 1.0e+20; float zMax = -1.0e+20; - float startPoint[3] = {0.,0.,0.}; - float endPoint[3] = {0.,0.,0.}; - for (int iH=0;iHgetTrackerHit()->getPosition()[iC]); - if (pos[2]>zMax) { + float startPoint[3] = {0., 0., 0.}; + float endPoint[3] = {0., 0., 0.}; + for (int iH = 0; iH < nHits_Grp; ++iH) { + TrackerHitExtended* trkHitExt = hitVecGrp[iH]; + float pos[3] = {0., 0., 0.}; + for (int iC = 0; iC < 3; ++iC) + pos[iC] = float(trkHitExt->getTrackerHit()->getPosition()[iC]); + if (pos[2] > zMax) { zMax = pos[2]; - for (int iC=0;iC<3;++iC) - endPoint[iC] = pos[iC]; + for (int iC = 0; iC < 3; ++iC) + endPoint[iC] = pos[iC]; } - if (pos[2]setEnd(endPoint); } } - - + // replace previous version with faster loop ordering - + std::vector minDistances(nHits, dcut); std::vector tracksToAttach(nHits); - std::vector< std::vector > HitPositions(nHits); - std::vector HitSign(nHits);//Positive or Negative side - for (int iH=0;iH> HitPositions(nHits); + std::vector HitSign(nHits); // Positive or Negative side + for (int iH = 0; iH < nHits; ++iH) { // loop over leftover TPC hits + tracksToAttach[iH] = NULL; + // Get all TrackerHit positions, so we only have to get them once TrackerHit* temphit = hitVec[iH]->getTrackerHit(); - const double *temppos = temphit->getPosition(); + const double* temppos = temphit->getPosition(); HitPositions[iH].push_back(float(temppos[0])); HitPositions[iH].push_back(float(temppos[1])); HitPositions[iH].push_back(float(temppos[2])); - HitSign[iH]=std::signbit(temppos[2]); - } - - streamlog_out(DEBUG3) << "AssignTPCHitsToTracks: Starting loop " << nTrk << " tracks and " << nHits << " hits" << std::endl; - - for (int iT=0;iTgetTanLambda());//we only care about positive or negative - GroupTracks * group = foundTrack->getGroupTracks(); + HitSign[iH] = std::signbit(temppos[2]); + } + + streamlog_out(DEBUG3) << "AssignTPCHitsToTracks: Starting loop " << nTrk << " tracks and " << nHits << " hits" + << std::endl; + + for (int iT = 0; iT < nTrk; ++iT) { // loop over all tracks + TrackExtended* foundTrack = _trkImplVec[iT]; + int tanlambdaSign = std::signbit(foundTrack->getTanLambda()); // we only care about positive or negative + GroupTracks* group = foundTrack->getGroupTracks(); TrackExtendedVec tracksInGroup = group->getTrackExtendedVec(); int nTrkGrp = int(tracksInGroup.size()); - - for (int iTrkGrp=0;iTrkGrpgetTanLambda(); float omega = trkGrp->getOmega(); float d0 = trkGrp->getD0(); float z0 = trkGrp->getZ0(); float phi0 = trkGrp->getPhi(); float startPointZ = trkGrp->getStart()[2]; - float endPointZ = trkGrp->getEnd()[2]; + float endPointZ = trkGrp->getEnd()[2]; HelixClass helix; - helix.Initialize_Canonical(phi0,d0,z0,omega,tanLambda,_bField); - float OnePFivehalfPeriodZ = 1.5*fabs(acos(-1.)*tanLambda/omega); - - for (int iH=0;iH=startPointZ) && (HitPositions[iH][2]<=endPointZ) ); - - if(consider){ + consider = consider || ((HitPositions[iH][2] >= startPointZ) && (HitPositions[iH][2] <= endPointZ)); + + if (consider) { float distance = helix.getDistanceToPoint(HitPositions[iH], minDistances[iH]); if (distance < minDistances[iH]) { minDistances[iH] = distance; @@ -4284,25 +4009,24 @@ void FullLDCTracking_MarlinTrk::AssignTPCHitsToTracks(TrackerHitExtendedVec hitV } } } // loop over leftover TPC hits - } //groups in tracks - } // loop over all tracks - - for (int iH=0;iHaddTrackerHitExtended(trkHitExt); - trkHitExt->setTrackExtended( tracksToAttach[iH] ); - trkHitExt->setUsedInFit( false ); + trkHitExt->setTrackExtended(tracksToAttach[iH]); + trkHitExt->setUsedInFit(false); } } - + streamlog_out(DEBUG3) << " Fast loop done " << std::endl; - - + // for (int iH=0;iHgetTrackerHit()->getPosition()[ip]); // float minDist = 1.0e+20; // TrackExtended * trackToAttach = NULL; @@ -4347,74 +4071,72 @@ void FullLDCTracking_MarlinTrk::AssignTPCHitsToTracks(TrackerHitExtendedVec hitV // } // } // } - + // if (trackToAttach!=NULL) { // trackToAttach->addTrackerHitExtended(hitExt); // hitExt->setTrackExtended( trackToAttach ); // hitExt->setUsedInFit( false ); - // if(trackToAttach!=tracksToAttach[iH])std::cout << " Check Failed" << trackToAttach << " " << tracksToAttach[iH] << std::endl; + // if(trackToAttach!=tracksToAttach[iH])std::cout << " Check Failed" << trackToAttach << " " << tracksToAttach[iH] + // << std::endl; // //} - //else { + // else { /// std::cout << iH << " hit is not assigned : distance to closest track = " << minDist << std::endl; ///} //} - //std::cout << " Slow loop done " << std::endl; - + // std::cout << " Slow loop done " << std::endl; } -void FullLDCTracking_MarlinTrk::AssignSiHitsToTracks(TrackerHitExtendedVec hitVec, - float dcut) { - +void FullLDCTracking_MarlinTrk::AssignSiHitsToTracks(TrackerHitExtendedVec hitVec, float dcut) { + int nHits = int(hitVec.size()); int nTrk = int(_allNonCombinedTPCTracks.size()); - - streamlog_out(DEBUG3) << "AssignSiHitsToTracks : Number of hits to assign " << hitVec.size() << " : Number of available tracks = " << nTrk << std::endl; - - std::map flagTrack; - std::map flagHit; + + streamlog_out(DEBUG3) << "AssignSiHitsToTracks : Number of hits to assign " << hitVec.size() + << " : Number of available tracks = " << nTrk << std::endl; + + std::map flagTrack; + std::map flagHit; TrackHitPairVec pairs; flagTrack.clear(); flagHit.clear(); pairs.clear(); - - for (int iH=0;iHgetTrackerHit(); - - for (int ip=0;ip<3;++ip) { + TrackerHitExtended* trkHitExt = hitVec[iH]; + TrackerHit* hit = trkHitExt->getTrackerHit(); + + for (int ip = 0; ip < 3; ++ip) { pos[ip] = float(hit->getPosition()[ip]); } - - for (int iT=0;iTgetTanLambda(); - float product = pos[2]*tanLambda; - - streamlog_out(DEBUG0) << "AssignSiHitsToTracks : product = " << product << " z hit = " << pos[2] << std::endl; - - - if (product>0) { - + + for (int iT = 0; iT < nTrk; ++iT) { + + TrackExtended* trkExt = _allNonCombinedTPCTracks[iT]; + + float tanLambda = trkExt->getTanLambda(); + float product = pos[2] * tanLambda; + + streamlog_out(DEBUG0) << "AssignSiHitsToTracks : product = " << product << " z hit = " << pos[2] << std::endl; + + if (product > 0) { + float d0 = trkExt->getD0(); float z0 = trkExt->getZ0(); float phi0 = trkExt->getPhi(); float omega = trkExt->getOmega(); tanLambda = trkExt->getTanLambda(); - + HelixClass helix; - helix.Initialize_Canonical(phi0,d0,z0,omega,tanLambda,_bField); - float distance = helix.getDistanceToPoint(pos,dcut); - + helix.Initialize_Canonical(phi0, d0, z0, omega, tanLambda, _bField); + float distance = helix.getDistanceToPoint(pos, dcut); + streamlog_out(DEBUG0) << "AssignSiHitsToTracks : distance = " << distance << " cut = " << dcut << std::endl; - - if (distancegetTrackerHit(); + + // add the hit to be attached to the vectors + TrackerHit* remainHit = trkHitExt->getTrackerHit(); iHitInFit++; trkHits.push_back(remainHit); - - + double chi2_D; int ndf; - - if( trkHits.size() < 3 ) return ; - + + if (trkHits.size() < 3) + return; + // sort the hits in R - std::vector< std::pair > r2_values; + std::vector> r2_values; r2_values.reserve(trkHits.size()); - - for (TrackerHitVec::iterator it=trkHits.begin(); it!=trkHits.end(); ++it) { + + for (TrackerHitVec::iterator it = trkHits.begin(); it != trkHits.end(); ++it) { EVENT::TrackerHit* h = *it; - float r2 = h->getPosition()[0]*h->getPosition()[0]+h->getPosition()[1]*h->getPosition()[1]; + float r2 = h->getPosition()[0] * h->getPosition()[0] + h->getPosition()[1] * h->getPosition()[1]; r2_values.push_back(std::make_pair(r2, *it)); } - - sort(r2_values.begin(),r2_values.end()); - + + sort(r2_values.begin(), r2_values.end()); + trkHits.clear(); trkHits.reserve(r2_values.size()); - - for (std::vector< std::pair >::iterator it=r2_values.begin(); it!=r2_values.end(); ++it) { + + for (std::vector>::iterator it = r2_values.begin(); it != r2_values.end(); + ++it) { trkHits.push_back(it->second); } - - - streamlog_out(DEBUG2) << "AssignSiHitsToTracks: Start Fitting: AddHits: number of hits to fit " << trkHits.size() << std::endl; - - + + streamlog_out(DEBUG2) << "AssignSiHitsToTracks: Start Fitting: AddHits: number of hits to fit " + << trkHits.size() << std::endl; + MarlinTrk::IMarlinTrack* marlin_trk = _trksystem->createTrack(); - - IMPL::TrackStateImpl pre_fit ; - - + + IMPL::TrackStateImpl pre_fit; + pre_fit.setD0(trkExt->getD0()); pre_fit.setPhi(trkExt->getPhi()); pre_fit.setZ0(trkExt->getZ0()); pre_fit.setOmega(trkExt->getOmega()); pre_fit.setTanLambda(trkExt->getTanLambda()); - + float ref[3]; - ref[0]=ref[1]=ref[2]=0.0; - + ref[0] = ref[1] = ref[2] = 0.0; + pre_fit.setReferencePoint(ref); - + pre_fit.setLocation(lcio::TrackStateImpl::AtIP); - + // setup initial dummy covariance matrix EVENT::FloatVec covMatrix; covMatrix.resize(15); - - for (unsigned icov = 0; icov > outliers ; + + std::vector> outliers; marlin_trk->getOutliers(outliers); - - float outlier_pct = outliers.size()/float(trkHits.size()); - - streamlog_out(DEBUG1) << "FullLDCTracking_MarlinTrk::AssignSiHitsToTracks: percentage of outliers " << outlier_pct << std::endl; - - if ( outlier_pct > _maxAllowedPercentageOfOutliersForTrackCombination) { - - streamlog_out(DEBUG2) << "FullLDCTracking_MarlinTrk::AssignSiHitsToTracks: percentage of outliers " << outlier_pct << " is greater than cut maximum: " << _maxAllowedPercentageOfOutliersForTrackCombination << std::endl; - delete marlin_trk ; - continue ; - + + float outlier_pct = outliers.size() / float(trkHits.size()); + + streamlog_out(DEBUG1) << "FullLDCTracking_MarlinTrk::AssignSiHitsToTracks: percentage of outliers " + << outlier_pct << std::endl; + + if (outlier_pct > _maxAllowedPercentageOfOutliersForTrackCombination) { + + streamlog_out(DEBUG2) << "FullLDCTracking_MarlinTrk::AssignSiHitsToTracks: percentage of outliers " + << outlier_pct << " is greater than cut maximum: " + << _maxAllowedPercentageOfOutliersForTrackCombination << std::endl; + delete marlin_trk; + continue; } - - const Vector3D point(0.,0.,0.); // nominal IP - - TrackStateImpl trkState ; + + const Vector3D point(0., 0., 0.); // nominal IP + + TrackStateImpl trkState; // int return_code = - marlin_trk->propagate(point, trkState, chi2_D, ndf ) ; - - delete marlin_trk ; - - if ( error != IMarlinTrack::success ) { - - streamlog_out(DEBUG3) << "FullLDCTracking_MarlinTrk::AssignSiHitsToTracks: propagate to IP fails with error " << error << std::endl; - - continue ; - + marlin_trk->propagate(point, trkState, chi2_D, ndf); + + delete marlin_trk; + + if (error != IMarlinTrack::success) { + + streamlog_out(DEBUG3) << "FullLDCTracking_MarlinTrk::AssignSiHitsToTracks: propagate to IP fails with error " + << error << std::endl; + + continue; } - - if ( ndf < 0 ) { - - streamlog_out(DEBUG2) << "FullLDCTracking_MarlinTrk::AssignSiHitsToTracks: Fit failed : NDF is less that zero " << ndf << std::endl; - - continue ; - + + if (ndf < 0) { + + streamlog_out(DEBUG2) + << "FullLDCTracking_MarlinTrk::AssignSiHitsToTracks: Fit failed : NDF is less that zero " << ndf + << std::endl; + + continue; } - - - float chi2Fit = chi2_D/float(ndf); - - if ( chi2Fit > _chi2FitCut ) { - - streamlog_out(DEBUG2) << "FullLDCTracking_MarlinTrk::AssignSiHitsToTracks: track fail Chi2 cut of " << _chi2FitCut << " chi2 of track = " << chi2Fit << std::endl; - - continue ; - + + float chi2Fit = chi2_D / float(ndf); + + if (chi2Fit > _chi2FitCut) { + + streamlog_out(DEBUG2) << "FullLDCTracking_MarlinTrk::AssignSiHitsToTracks: track fail Chi2 cut of " + << _chi2FitCut << " chi2 of track = " << chi2Fit << std::endl; + + continue; } - - - - // note trackAR which is of type TrackExtended, only takes fits with ref point = 0,0,0 + + // note trackAR which is of type TrackExtended, only takes fits with ref point = 0,0,0 trkExt->setOmega(trkState.getOmega()); trkExt->setTanLambda(trkState.getTanLambda()); trkExt->setPhi(trkState.getPhi()); trkExt->setD0(trkState.getD0()); trkExt->setZ0(trkState.getZ0()); - - + float cov[15]; - - for (int i = 0 ; i<15 ; ++i) { + + for (int i = 0; i < 15; ++i) { cov[i] = trkState.getCovMatrix().operator[](i); } - + trkExt->setCovMatrix(cov); trkExt->setChi2(chi2_D); trkExt->setNDF(ndf); - - trkExt->addTrackerHitExtended( trkHitExt ); - trkHitExt->setTrackExtended( trkExt ); - trkHitExt->setUsedInFit( true ); + + trkExt->addTrackerHitExtended(trkHitExt); + trkHitExt->setTrackExtended(trkExt); + trkHitExt->setUsedInFit(true); flagTrack[trkExt] = false; flagHit[trkHitExt] = false; - - - streamlog_out(DEBUG2) << "AssignSiHitsToTracks: Hit " << trkHitExt << " successfully assigned to track " << trkExt << std::endl; - + + streamlog_out(DEBUG2) << "AssignSiHitsToTracks: Hit " << trkHitExt << " successfully assigned to track " + << trkExt << std::endl; } } - - for (int iP=0;iPgetTrack(); - Track * secondTrack = secondTrackExt->getTrack(); - - std::string firstColName = _TPCTrackMCPCollName; + + Track* firstTrack = firstTrackExt->getTrack(); + Track* secondTrack = secondTrackExt->getTrack(); + + std::string firstColName = _TPCTrackMCPCollName; std::string secondColName = _TPCTrackMCPCollName; - - if (iopt==1) { + + if (iopt == 1) { secondColName = _SiTrackMCPCollName; - } - else if (iopt==2) { + } else if (iopt == 2) { secondColName = _SiTrackMCPCollName; - } - else if (iopt==3) { + } else if (iopt == 3) { secondColName = _TPCTrackMCPCollName; - } - else if (iopt==4) { + } else if (iopt == 4) { secondColName = _SiTrackMCPCollName; - } - else if (iopt==5) { + } else if (iopt == 5) { secondColName = _TPCTrackMCPCollName; - } - else if (iopt==6) { + } else if (iopt == 6) { secondColName = _SiTrackMCPCollName; - } - else if (iopt==7) { + } else if (iopt == 7) { secondColName = _SiTrackMCPCollName; - } - else if (iopt==8) { + } else if (iopt == 8) { secondColName = _SiTrackMCPCollName; - } - else { + } else { secondColName = _TPCTrackMCPCollName; } - - + // get the relation collections, this should be done only once for each event ... - LCCollection * firstCol = _evt->getCollection(firstColName.c_str()); - LCCollection * secondCol = _evt->getCollection(secondColName.c_str()); - + LCCollection* firstCol = _evt->getCollection(firstColName.c_str()); + LCCollection* secondCol = _evt->getCollection(secondColName.c_str()); + // get navigators LCRelationNavigator firstNav(firstCol); LCRelationNavigator secondNav(secondCol); - // get the MCParticles with the greatest weight for the first track LCObjectVec firstVec = firstNav.getRelatedToObjects(firstTrack); FloatVec firstWeights = firstNav.getRelatedToWeights(firstTrack); - LCObject * firstMCP = NULL; + LCObject* firstMCP = NULL; float firstWght = 0; int nObj = firstVec.size(); - for (int iObj=0;iObjfirstWght) { + for (int iObj = 0; iObj < nObj; ++iObj) { + if (firstWeights[iObj] > firstWght) { firstWght = firstWeights[iObj]; firstMCP = firstVec[iObj]; } } - - + // get the MCParticles with the greatest weight for the second track LCObjectVec secondVec = secondNav.getRelatedToObjects(secondTrack); FloatVec secondWeights = secondNav.getRelatedToWeights(secondTrack); - LCObject * secondMCP = NULL; + LCObject* secondMCP = NULL; float secondWght = 0; nObj = secondVec.size(); - for (int iObj=0;iObjsecondWght) { + for (int iObj = 0; iObj < nObj; ++iObj) { + if (secondWeights[iObj] > secondWght) { secondWght = secondWeights[iObj]; secondMCP = secondVec[iObj]; } } - // get the track parameters for both tracks and get the 3-momentum using the HelixClass float d0First = firstTrackExt->getD0(); @@ -4746,562 +4453,544 @@ void FullLDCTracking_MarlinTrk::PrintOutMerging(TrackExtended * firstTrackExt, T float omegaFirst = firstTrackExt->getOmega(); float tanLFirst = firstTrackExt->getTanLambda(); float phi0First = firstTrackExt->getPhi(); - + float d0Second = secondTrackExt->getD0(); float z0Second = secondTrackExt->getZ0(); float omegaSecond = secondTrackExt->getOmega(); float tanLSecond = secondTrackExt->getTanLambda(); - float phi0Second = secondTrackExt->getPhi(); - + float phi0Second = secondTrackExt->getPhi(); + HelixClass firstHelix; - firstHelix.Initialize_Canonical(phi0First,d0First,z0First,omegaFirst,tanLFirst,_bField); + firstHelix.Initialize_Canonical(phi0First, d0First, z0First, omegaFirst, tanLFirst, _bField); float pxFirst = firstHelix.getMomentum()[0]; float pyFirst = firstHelix.getMomentum()[1]; - float pzFirst = firstHelix.getMomentum()[2]; - + float pzFirst = firstHelix.getMomentum()[2]; + HelixClass secondHelix; - secondHelix.Initialize_Canonical(phi0Second,d0Second,z0Second,omegaSecond,tanLSecond,_bField); + secondHelix.Initialize_Canonical(phi0Second, d0Second, z0Second, omegaSecond, tanLSecond, _bField); float pxSecond = secondHelix.getMomentum()[0]; float pySecond = secondHelix.getMomentum()[1]; - float pzSecond = secondHelix.getMomentum()[2]; + float pzSecond = secondHelix.getMomentum()[2]; - // get the momentum differences float dPx = pxFirst + pxSecond; float dPy = pyFirst + pySecond; float dPz = pzFirst + pzSecond; - - float dPplus = sqrt(dPx*dPx+dPy*dPy+dPz*dPz); - + + float dPplus = sqrt(dPx * dPx + dPy * dPy + dPz * dPz); + dPx = pxFirst - pxSecond; dPy = pyFirst - pySecond; dPz = pzFirst - pzSecond; - - float dPminus = sqrt(dPx*dPx+dPy*dPy+dPz*dPz); - + + float dPminus = sqrt(dPx * dPx + dPy * dPy + dPz * dPz); + // get momentum for each track - float pFirst = sqrt(pxFirst * pxFirst+ pyFirst* pyFirst+ pzFirst*pzFirst); - float pSecond = sqrt(pxSecond*pxSecond+pySecond*pySecond+pzSecond*pzSecond); - - float ptFirst = sqrt(pxFirst * pxFirst+ pyFirst* pyFirst); - float ptSecond = sqrt(pxSecond*pxSecond+pySecond*pySecond); - - - const float sigmaPOverPFirst = sqrt( firstTrackExt->getCovMatrix()[5])/fabs(omegaFirst); - const float sigmaPOverPSecond = sqrt(secondTrackExt->getCovMatrix()[5])/fabs(omegaSecond); - - const float sigmaPFirst = pFirst*sigmaPOverPFirst; - const float sigmaPSecond = pSecond*sigmaPOverPSecond; - - + float pFirst = sqrt(pxFirst * pxFirst + pyFirst * pyFirst + pzFirst * pzFirst); + float pSecond = sqrt(pxSecond * pxSecond + pySecond * pySecond + pzSecond * pzSecond); + + float ptFirst = sqrt(pxFirst * pxFirst + pyFirst * pyFirst); + float ptSecond = sqrt(pxSecond * pxSecond + pySecond * pySecond); + + const float sigmaPOverPFirst = sqrt(firstTrackExt->getCovMatrix()[5]) / fabs(omegaFirst); + const float sigmaPOverPSecond = sqrt(secondTrackExt->getCovMatrix()[5]) / fabs(omegaSecond); + + const float sigmaPFirst = pFirst * sigmaPOverPFirst; + const float sigmaPSecond = pSecond * sigmaPOverPSecond; + float den = pFirst; - if (pSecond" << std::endl; - } - else if (iopt==2) { - streamlog_out(DEBUG4) << "Erroneous merging of Si and TPC segments (iopt=2) mcp first = " << firstMCP << " mcp second = " << secondMCP << " --->" << std::endl; - } - else if (iopt==3) { - streamlog_out(DEBUG4) << "Erroneous merging of TPC segments (iopt=3) mcp first = " << firstMCP << " mcp second = " << secondMCP << " ---> " << std::endl; - } - else if (iopt==4) { - streamlog_out(DEBUG4) << "Erroneous merging of combSi segment with uncombTPC segment (iopt=4) mcp first = " << firstMCP << " mcp second = " << secondMCP << " ---> " << std::endl; - } - else { - streamlog_out(DEBUG4) << "Erroneous merging of combTPC segment with uncombTPC segment (iopt=5) mcp first = " << firstMCP << " mcp second = " << secondMCP << " --->" << std::endl; + if (firstMCP != secondMCP && iopt < 6) { + + if (iopt == 1) { + streamlog_out(DEBUG4) << "Erroneous merging of Si and TPC segments (iopt=1) mcp first = " << firstMCP + << " mcp second = " << secondMCP << " --->" << std::endl; + } else if (iopt == 2) { + streamlog_out(DEBUG4) << "Erroneous merging of Si and TPC segments (iopt=2) mcp first = " << firstMCP + << " mcp second = " << secondMCP << " --->" << std::endl; + } else if (iopt == 3) { + streamlog_out(DEBUG4) << "Erroneous merging of TPC segments (iopt=3) mcp first = " << firstMCP + << " mcp second = " << secondMCP << " ---> " << std::endl; + } else if (iopt == 4) { + streamlog_out(DEBUG4) << "Erroneous merging of combSi segment with uncombTPC segment (iopt=4) mcp first = " + << firstMCP << " mcp second = " << secondMCP << " ---> " << std::endl; + } else { + streamlog_out(DEBUG4) << "Erroneous merging of combTPC segment with uncombTPC segment (iopt=5) mcp first = " + << firstMCP << " mcp second = " << secondMCP << " --->" << std::endl; } - - - streamlog_out(DEBUG4) << " p error pt D0 Z0 Px Py Pz wieght" << std::endl; - - sprintf(strg,"%7.2f +- %7.2f %7.2f %7.1f %7.1f %7.2f %7.2f %7.2f ", - pFirst, sigmaPFirst, ptFirst, d0First,z0First,pxFirst,pyFirst,pzFirst); + + streamlog_out(DEBUG4) << " p error pt D0 Z0 Px Py Pz wieght" + << std::endl; + + sprintf(strg, "%7.2f +- %7.2f %7.2f %7.1f %7.1f %7.2f %7.2f %7.2f ", pFirst, sigmaPFirst, ptFirst, d0First, + z0First, pxFirst, pyFirst, pzFirst); streamlog_out(DEBUG4) << strg; - - sprintf(strg," %5.3f\n",firstWght); + + sprintf(strg, " %5.3f\n", firstWght); streamlog_out(DEBUG4) << strg; - - - sprintf(strg,"%7.2f +- %7.2f %7.2f %7.1f %7.1f %7.2f %7.2f %7.2f ", - pSecond, sigmaPSecond, ptSecond, d0Second,z0Second,pxSecond,pySecond,pzSecond); + + sprintf(strg, "%7.2f +- %7.2f %7.2f %7.1f %7.1f %7.2f %7.2f %7.2f ", pSecond, sigmaPSecond, ptSecond, + d0Second, z0Second, pxSecond, pySecond, pzSecond); streamlog_out(DEBUG4) << strg; - sprintf(strg," %5.3f\n",secondWght); + sprintf(strg, " %5.3f\n", secondWght); streamlog_out(DEBUG4) << strg; - + streamlog_out(DEBUG4) << "Difference in +P = " << dPplus << " -P = " << dPminus << std::endl; - - TrackExtended * combinedTrack = CombineTracks(firstTrackExt,secondTrackExt, _maxAllowedPercentageOfOutliersForTrackCombination, true); - - if(combinedTrack != NULL){ - streamlog_out(DEBUG4) << "CombinedTrack " << combinedTrack->getNDF() << " c.f. " << firstTrackExt->getNDF()+secondTrackExt->getNDF()+5 << std::endl; + + TrackExtended* combinedTrack = + CombineTracks(firstTrackExt, secondTrackExt, _maxAllowedPercentageOfOutliersForTrackCombination, true); + + if (combinedTrack != NULL) { + streamlog_out(DEBUG4) << "CombinedTrack " << combinedTrack->getNDF() << " c.f. " + << firstTrackExt->getNDF() + secondTrackExt->getNDF() + 5 << std::endl; delete combinedTrack->getGroupTracks(); delete combinedTrack; - }else{ + } else { streamlog_out(DEBUG4) << "Could not combine track " << std::endl; } - streamlog_out(DEBUG4) << " Overlap = " << SegmentRadialOverlap(firstTrackExt, secondTrackExt) << " veto = " << VetoMerge(firstTrackExt, secondTrackExt) << std::endl; - + streamlog_out(DEBUG4) << " Overlap = " << SegmentRadialOverlap(firstTrackExt, secondTrackExt) + << " veto = " << VetoMerge(firstTrackExt, secondTrackExt) << std::endl; + streamlog_out(DEBUG4) << std::endl; - + } - + // ... or if it was an incorrect TPC to TPC rejection ... - else if (firstMCP==secondMCP && ( (iopt==8) || (iopt==9) ) ) { - + else if (firstMCP == secondMCP && ((iopt == 8) || (iopt == 9))) { + float deltaOmega = _dOmegaForMerging; float deltaAngle = _angleForMerging; - if (iopt==8) { + if (iopt == 8) { streamlog_out(DEBUG4) << "Unmerged TPC and Comb segments (iopt=8) --->" << std::endl; - } - else { + } else { streamlog_out(DEBUG4) << "Unmerged TPC segments (iopt=9) --->" << std::endl; } - + float qFirst = PIOVER2 - atan(tanLFirst); float qSecond = PIOVER2 - atan(tanLSecond); - float dOmega = fabs((omegaFirst-omegaSecond)/omegaSecond); - float angle = (cos(phi0First)*cos(phi0Second)+sin(phi0First)*sin(phi0Second))* - sin(qFirst)*sin(qSecond)+cos(qFirst)*cos(qSecond); + float dOmega = fabs((omegaFirst - omegaSecond) / omegaSecond); + float angle = (cos(phi0First) * cos(phi0Second) + sin(phi0First) * sin(phi0Second)) * sin(qFirst) * sin(qSecond) + + cos(qFirst) * cos(qSecond); angle = acos(angle); - - - streamlog_out(DEBUG4) << " dOmegaCut = " << deltaOmega - << " AngleCut = " << deltaAngle - << " dOmega = " << dOmega - << " angle = " << angle << std::endl; - - - streamlog_out(DEBUG4) << " p error pt D0 Z0 Px Py Pz wieght" << std::endl; - - sprintf(strg,"%7.2f +- %7.2f %7.2f %7.1f %7.1f %7.2f %7.2f %7.2f ", - pFirst, sigmaPFirst, ptFirst, d0First,z0First,pxFirst,pyFirst,pzFirst); + + streamlog_out(DEBUG4) << " dOmegaCut = " << deltaOmega << " AngleCut = " << deltaAngle << " dOmega = " << dOmega + << " angle = " << angle << std::endl; + + streamlog_out(DEBUG4) << " p error pt D0 Z0 Px Py Pz wieght" + << std::endl; + + sprintf(strg, "%7.2f +- %7.2f %7.2f %7.1f %7.1f %7.2f %7.2f %7.2f ", pFirst, sigmaPFirst, ptFirst, d0First, + z0First, pxFirst, pyFirst, pzFirst); streamlog_out(DEBUG4) << strg; - sprintf(strg," %5.3f\n",firstWght); + sprintf(strg, " %5.3f\n", firstWght); streamlog_out(DEBUG4) << strg; - - sprintf(strg,"%7.2f +- %7.2f %7.2f %7.1f %7.1f %7.2f %7.2f %7.2f ", - pSecond, sigmaPSecond, ptSecond, d0Second,z0Second,pxSecond,pySecond,pzSecond); + sprintf(strg, "%7.2f +- %7.2f %7.2f %7.1f %7.1f %7.2f %7.2f %7.2f ", pSecond, sigmaPSecond, ptSecond, + d0Second, z0Second, pxSecond, pySecond, pzSecond); streamlog_out(DEBUG4) << strg; - sprintf(strg," %5.3f\n",secondWght); + sprintf(strg, " %5.3f\n", secondWght); streamlog_out(DEBUG4) << strg; - + streamlog_out(DEBUG4) << "Difference in +P = " << dPplus << " -P = " << dPminus << std::endl; - - TrackExtended * combinedTrack = CombineTracks(firstTrackExt,secondTrackExt, _maxAllowedPercentageOfOutliersForTrackCombination, true); - if(combinedTrack != NULL){ - streamlog_out(DEBUG4) << "CombinedTrack " << combinedTrack->getNDF() << " c.f. " << firstTrackExt->getNDF()+secondTrackExt->getNDF()+5 << std::endl; + + TrackExtended* combinedTrack = + CombineTracks(firstTrackExt, secondTrackExt, _maxAllowedPercentageOfOutliersForTrackCombination, true); + if (combinedTrack != NULL) { + streamlog_out(DEBUG4) << "CombinedTrack " << combinedTrack->getNDF() << " c.f. " + << firstTrackExt->getNDF() + secondTrackExt->getNDF() + 5 << std::endl; delete combinedTrack->getGroupTracks(); delete combinedTrack; - }else{ + } else { streamlog_out(DEBUG4) << "Could not combine track " << std::endl; } - streamlog_out(DEBUG4) << " Overlap = " << SegmentRadialOverlap(firstTrackExt, secondTrackExt) << " veto = " << VetoMerge(firstTrackExt, secondTrackExt) << std::endl; - + streamlog_out(DEBUG4) << " Overlap = " << SegmentRadialOverlap(firstTrackExt, secondTrackExt) + << " veto = " << VetoMerge(firstTrackExt, secondTrackExt) << std::endl; + streamlog_out(DEBUG4) << std::endl; - - } + + } // ... or if it was an incorrect TPC to Si rejection ... - else if (firstMCP==secondMCP && ( (iopt == 6) || (iopt == 7) ) ) { - + else if (firstMCP == secondMCP && ((iopt == 6) || (iopt == 7))) { + float deltaOmega = _dOmegaForMerging; float deltaAngle = _angleForMerging; - - if (iopt ==6) { - streamlog_out(DEBUG4) << "Unmerged TPC and Si segments (iopt=6) mcp first = " << firstMCP << " mcp second = " << secondMCP << " --->" << std::endl; - } - else { - streamlog_out(DEBUG4) << "Unmerged TPC and Si segments (iopt=7) mcp first = " << firstMCP << " mcp second = " << secondMCP << " --->" << std::endl; + + if (iopt == 6) { + streamlog_out(DEBUG4) << "Unmerged TPC and Si segments (iopt=6) mcp first = " << firstMCP + << " mcp second = " << secondMCP << " --->" << std::endl; + } else { + streamlog_out(DEBUG4) << "Unmerged TPC and Si segments (iopt=7) mcp first = " << firstMCP + << " mcp second = " << secondMCP << " --->" << std::endl; deltaOmega = _dOmegaForForcedMerging; deltaAngle = _angleForForcedMerging; } - + float qFirst = PIOVER2 - atan(tanLFirst); float qSecond = PIOVER2 - atan(tanLSecond); - - float dOmega = fabs((omegaFirst-omegaSecond)/omegaSecond); - float angle = (cos(phi0First)*cos(phi0Second)+sin(phi0First)*sin(phi0Second))* - sin(qFirst)*sin(qSecond)+cos(qFirst)*cos(qSecond); + + float dOmega = fabs((omegaFirst - omegaSecond) / omegaSecond); + float angle = (cos(phi0First) * cos(phi0Second) + sin(phi0First) * sin(phi0Second)) * sin(qFirst) * sin(qSecond) + + cos(qFirst) * cos(qSecond); angle = acos(angle); - - - streamlog_out(DEBUG4) << " dOmegaCut = " << deltaOmega - << " AngleCut = " << deltaAngle - << " dOmega = " << dOmega - << " angle = " << angle << std::endl; - - streamlog_out(DEBUG4) << " p error pt D0 Z0 Px Py Pz wieght" << std::endl; - - sprintf(strg,"%7.2f +- %7.2f %7.2f %7.1f %7.1f %7.2f %7.2f %7.2f ", - pFirst, sigmaPFirst, ptFirst, d0First,z0First,pxFirst,pyFirst,pzFirst); + + streamlog_out(DEBUG4) << " dOmegaCut = " << deltaOmega << " AngleCut = " << deltaAngle << " dOmega = " << dOmega + << " angle = " << angle << std::endl; + + streamlog_out(DEBUG4) << " p error pt D0 Z0 Px Py Pz wieght" + << std::endl; + + sprintf(strg, "%7.2f +- %7.2f %7.2f %7.1f %7.1f %7.2f %7.2f %7.2f ", pFirst, sigmaPFirst, ptFirst, d0First, + z0First, pxFirst, pyFirst, pzFirst); streamlog_out(DEBUG4) << strg; - sprintf(strg," %5.3f\n",firstWght); + sprintf(strg, " %5.3f\n", firstWght); streamlog_out(DEBUG4) << strg; - sprintf(strg,"%7.2f +- %7.2f %7.2f %7.1f %7.1f %7.2f %7.2f %7.2f ", - pSecond, sigmaPSecond, ptSecond, d0Second,z0Second,pxSecond,pySecond,pzSecond); + sprintf(strg, "%7.2f +- %7.2f %7.2f %7.1f %7.1f %7.2f %7.2f %7.2f ", pSecond, sigmaPSecond, ptSecond, + d0Second, z0Second, pxSecond, pySecond, pzSecond); streamlog_out(DEBUG4) << strg; - sprintf(strg," %5.3f\n",secondWght); + sprintf(strg, " %5.3f\n", secondWght); streamlog_out(DEBUG4) << strg; - - streamlog_out(DEBUG4) << "Difference in +P = " << dPplus << " -P = " << dPminus << std::endl; - - TrackExtended * combinedTrack = CombineTracks(firstTrackExt,secondTrackExt, _maxAllowedPercentageOfOutliersForTrackCombination, true); - - if(combinedTrack != NULL){ - streamlog_out(DEBUG4) << "CombinedTrack " << combinedTrack->getNDF() << " c.f. " << firstTrackExt->getNDF()+secondTrackExt->getNDF()+5 << std::endl; + + streamlog_out(DEBUG4) << "Difference in +P = " << dPplus << " -P = " << dPminus << std::endl; + + TrackExtended* combinedTrack = + CombineTracks(firstTrackExt, secondTrackExt, _maxAllowedPercentageOfOutliersForTrackCombination, true); + + if (combinedTrack != NULL) { + streamlog_out(DEBUG4) << "CombinedTrack " << combinedTrack->getNDF() << " c.f. " + << firstTrackExt->getNDF() + secondTrackExt->getNDF() + 5 << std::endl; delete combinedTrack->getGroupTracks(); delete combinedTrack; - }else{ + } else { streamlog_out(DEBUG4) << "Could not combine track " << std::endl; } - streamlog_out(DEBUG4) << " Overlap = " << SegmentRadialOverlap(firstTrackExt, secondTrackExt) << " veto = " << VetoMerge(firstTrackExt, secondTrackExt) << std::endl; - streamlog_out(DEBUG4) << std::endl; - + streamlog_out(DEBUG4) << " Overlap = " << SegmentRadialOverlap(firstTrackExt, secondTrackExt) + << " veto = " << VetoMerge(firstTrackExt, secondTrackExt) << std::endl; + streamlog_out(DEBUG4) << std::endl; + } // ... or if it was an correct merger ... - else if (firstMCP==secondMCP && iopt < 6 && _debug > 3) { + else if (firstMCP == secondMCP && iopt < 6 && _debug > 3) { // return; - if (iopt==1) { - streamlog_out(DEBUG4) << "Correctly combining Si and TPC segments (iopt=1) mcp first = " << firstMCP << " mcp second = " << secondMCP << " --->" << std::endl; - } - else if (iopt==2) { - streamlog_out(DEBUG4) << "Correctly merging of Si and TPC segments (iopt=2) mcp first = " << firstMCP << " mcp second = " << secondMCP << " --->" << std::endl; - } - else if (iopt==3) { - streamlog_out(DEBUG4) << "Correctly merging of TPC segments (iopt=3) mcp first = " << firstMCP << " mcp second = " << secondMCP << " ---> " << std::endl; - } - else if (iopt==4) { - streamlog_out(DEBUG4) << "Correctly merging of combSi segment with uncombTPC segment (iopt=4) mcp first = " << firstMCP << " mcp second = " << secondMCP << " ---> " << std::endl; - } - else { - streamlog_out(DEBUG4) << "Correctly merging of combTPC segment with uncombTPC segment (iopt=5) mcp first = " << firstMCP << " mcp second = " << secondMCP << " --->" << std::endl; + if (iopt == 1) { + streamlog_out(DEBUG4) << "Correctly combining Si and TPC segments (iopt=1) mcp first = " << firstMCP + << " mcp second = " << secondMCP << " --->" << std::endl; + } else if (iopt == 2) { + streamlog_out(DEBUG4) << "Correctly merging of Si and TPC segments (iopt=2) mcp first = " << firstMCP + << " mcp second = " << secondMCP << " --->" << std::endl; + } else if (iopt == 3) { + streamlog_out(DEBUG4) << "Correctly merging of TPC segments (iopt=3) mcp first = " << firstMCP + << " mcp second = " << secondMCP << " ---> " << std::endl; + } else if (iopt == 4) { + streamlog_out(DEBUG4) << "Correctly merging of combSi segment with uncombTPC segment (iopt=4) mcp first = " + << firstMCP << " mcp second = " << secondMCP << " ---> " << std::endl; + } else { + streamlog_out(DEBUG4) << "Correctly merging of combTPC segment with uncombTPC segment (iopt=5) mcp first = " + << firstMCP << " mcp second = " << secondMCP << " --->" << std::endl; } - streamlog_out(DEBUG4) << " p error pt D0 Z0 Px Py Pz wieght" << std::endl; - - sprintf(strg,"%7.2f +- %7.2f %7.2f %7.1f %7.1f %7.2f %7.2f %7.2f ", - pFirst, sigmaPFirst, ptFirst, d0First,z0First,pxFirst,pyFirst,pzFirst); + streamlog_out(DEBUG4) << " p error pt D0 Z0 Px Py Pz wieght" + << std::endl; + + sprintf(strg, "%7.2f +- %7.2f %7.2f %7.1f %7.1f %7.2f %7.2f %7.2f ", pFirst, sigmaPFirst, ptFirst, d0First, + z0First, pxFirst, pyFirst, pzFirst); streamlog_out(DEBUG4) << strg; - sprintf(strg," %5.3f\n",firstWght); + sprintf(strg, " %5.3f\n", firstWght); streamlog_out(DEBUG4) << strg; - - sprintf(strg,"%7.2f +- %7.2f %7.2f %7.1f %7.1f %7.2f %7.2f %7.2f ", - pSecond, sigmaPSecond, ptSecond, d0Second,z0Second,pxSecond,pySecond,pzSecond); + + sprintf(strg, "%7.2f +- %7.2f %7.2f %7.1f %7.1f %7.2f %7.2f %7.2f ", pSecond, sigmaPSecond, ptSecond, + d0Second, z0Second, pxSecond, pySecond, pzSecond); streamlog_out(DEBUG4) << strg; - sprintf(strg," %5.3f\n",secondWght); + sprintf(strg, " %5.3f\n", secondWght); streamlog_out(DEBUG4) << strg; - + streamlog_out(DEBUG4) << "Difference in +P = " << dPplus << " -P = " << dPminus << std::endl; - TrackExtended * combinedTrack = CombineTracks(firstTrackExt,secondTrackExt, _maxAllowedPercentageOfOutliersForTrackCombination, true); - - if(combinedTrack != NULL){ - streamlog_out(DEBUG4) << "CombinedTrack " << combinedTrack->getNDF() << " c.f. " << firstTrackExt->getNDF()+secondTrackExt->getNDF()+5 << std::endl; - }else{ + TrackExtended* combinedTrack = + CombineTracks(firstTrackExt, secondTrackExt, _maxAllowedPercentageOfOutliersForTrackCombination, true); + + if (combinedTrack != NULL) { + streamlog_out(DEBUG4) << "CombinedTrack " << combinedTrack->getNDF() << " c.f. " + << firstTrackExt->getNDF() + secondTrackExt->getNDF() + 5 << std::endl; + } else { streamlog_out(DEBUG4) << "Could not combine track " << std::endl; } delete combinedTrack->getGroupTracks(); delete combinedTrack; - streamlog_out(DEBUG4) << " Overlap = " << SegmentRadialOverlap(firstTrackExt, secondTrackExt) << " veto = " << VetoMerge(firstTrackExt, secondTrackExt) << std::endl; - + streamlog_out(DEBUG4) << " Overlap = " << SegmentRadialOverlap(firstTrackExt, secondTrackExt) + << " veto = " << VetoMerge(firstTrackExt, secondTrackExt) << std::endl; + streamlog_out(DEBUG4) << std::endl; - } } - - catch(DataNotAvailableException &e){}; - -} -void FullLDCTracking_MarlinTrk::GeneralSorting(int * index, float * val, int direct, int nVal) { + catch (DataNotAvailableException& e) { + }; +} + +void FullLDCTracking_MarlinTrk::GeneralSorting(int* index, float* val, int direct, int nVal) { /** Sorting of index vector in ascending (0) /descending (!=0) order of val */ - + float valOne, valTwo, valTemp; - int indTemp; - for (int i=0; i valTwo; - if (direct>0) + if (direct > 0) order = valOne <= valTwo; - if( order ) - { + if (order) { valTemp = val[j]; - val[j] = val[j+1]; - val[j+1] = valTemp; + val[j] = val[j + 1]; + val[j + 1] = valTemp; indTemp = index[j]; - index[j] = index[j+1]; - index[j+1] = indTemp; + index[j] = index[j + 1]; + index[j + 1] = indTemp; } - } + } } - - } -int FullLDCTracking_MarlinTrk::SegmentRadialOverlap(TrackExtended* first, TrackExtended* second){ - - +int FullLDCTracking_MarlinTrk::SegmentRadialOverlap(TrackExtended* first, TrackExtended* second) { + int nTrkGrpFirst = 0; int nTrkGrpSecond = 0; TrackerHitVec hitvecFirst; TrackerHitVec hitvecSecond; - GroupTracks * groupFirst = first->getGroupTracks(); - GroupTracks * groupSecond = second->getGroupTracks(); - - if(groupFirst!=NULL){ - + GroupTracks* groupFirst = first->getGroupTracks(); + GroupTracks* groupSecond = second->getGroupTracks(); + + if (groupFirst != NULL) { + TrackExtendedVec tracksInGroupFirst = groupFirst->getTrackExtendedVec(); nTrkGrpFirst = int(tracksInGroupFirst.size()); - - for (int iTrkGrp=0;iTrkGrpgetTrackerHitExtendedVec(); - - for(unsigned int i =0; igetTrackerHit()); + + for (unsigned int i = 0; i < hitVec.size(); ++i) { + hitvecFirst.push_back(hitVec[i]->getTrackerHit()); } } } - if(groupSecond!=NULL){ - + if (groupSecond != NULL) { + TrackExtendedVec tracksInGroupSecond = groupSecond->getTrackExtendedVec(); nTrkGrpSecond = int(tracksInGroupSecond.size()); - - for (int iTrkGrp=0;iTrkGrpgetTrackerHitExtendedVec(); - - for(unsigned int i=0;igetTrackerHitExtendedVec(); + + for (unsigned int i = 0; i < hitVec.size(); ++i) { hitvecSecond.push_back(hitVec[i]->getTrackerHit()); } } } - - + int nhitsFirst = (int)hitvecFirst.size(); int nhitsSecond = (int)hitvecSecond.size(); int count = 0; - for(int i =0;igetPosition()[0]; float yi = (float)hitvecFirst[i]->getPosition()[1]; - float ri = sqrt(xi*xi+yi*yi); - if(ri < _tpc_inner_r || ri > _tpc_pad_height)continue; - for(int j =0;j _tpc_pad_height) + continue; + for (int j = 0; j < nhitsSecond; ++j) { float xj = (float)hitvecSecond[j]->getPosition()[0]; float yj = (float)hitvecSecond[j]->getPosition()[1]; - float rj = sqrt(xj*xj+yj*yj); - if(fabs(ri-rj)<_tpc_pad_height/2.0)count++; + float rj = sqrt(xj * xj + yj * yj); + if (fabs(ri - rj) < _tpc_pad_height / 2.0) + count++; } - } + } return count; } /* - + veto merger if the momentum of either track is less than 2.5 GeV or if following a full fit the NDF+10 of the combined tracks is less than the NDF_first + NDF_second - - NOTE: This function will try a full fit using CombineTracks if the momentum of both tracks is greater than VetoMergeMomentumCut - + + NOTE: This function will try a full fit using CombineTracks if the momentum of both tracks is greater than + VetoMergeMomentumCut + */ -bool FullLDCTracking_MarlinTrk::VetoMerge(TrackExtended* firstTrackExt, TrackExtended* secondTrackExt){ - - - streamlog_out(DEBUG1) << "FullLDCTracking_MarlinTrk::VetoMerge called for " << firstTrackExt << " and " << secondTrackExt << std::endl; - +bool FullLDCTracking_MarlinTrk::VetoMerge(TrackExtended* firstTrackExt, TrackExtended* secondTrackExt) { + + streamlog_out(DEBUG1) << "FullLDCTracking_MarlinTrk::VetoMerge called for " << firstTrackExt << " and " + << secondTrackExt << std::endl; + const float d0First = firstTrackExt->getD0(); const float z0First = firstTrackExt->getZ0(); const float omegaFirst = firstTrackExt->getOmega(); const float tanLFirst = firstTrackExt->getTanLambda(); const float phi0First = firstTrackExt->getPhi(); - + const float d0Second = secondTrackExt->getD0(); const float z0Second = secondTrackExt->getZ0(); const float omegaSecond = secondTrackExt->getOmega(); const float tanLSecond = secondTrackExt->getTanLambda(); - const float phi0Second = secondTrackExt->getPhi(); - + const float phi0Second = secondTrackExt->getPhi(); + HelixClass firstHelix; - firstHelix.Initialize_Canonical(phi0First,d0First,z0First,omegaFirst,tanLFirst,_bField); + firstHelix.Initialize_Canonical(phi0First, d0First, z0First, omegaFirst, tanLFirst, _bField); const float pxFirst = firstHelix.getMomentum()[0]; const float pyFirst = firstHelix.getMomentum()[1]; - const float pzFirst = firstHelix.getMomentum()[2]; - + const float pzFirst = firstHelix.getMomentum()[2]; + HelixClass secondHelix; - secondHelix.Initialize_Canonical(phi0Second,d0Second,z0Second,omegaSecond,tanLSecond,_bField); + secondHelix.Initialize_Canonical(phi0Second, d0Second, z0Second, omegaSecond, tanLSecond, _bField); const float pxSecond = secondHelix.getMomentum()[0]; const float pySecond = secondHelix.getMomentum()[1]; - const float pzSecond = secondHelix.getMomentum()[2]; - const float pFirst = sqrt(pxFirst*pxFirst+pyFirst*pyFirst+pzFirst*pzFirst); - const float pSecond = sqrt(pxSecond*pxSecond+pySecond*pySecond+pzSecond*pzSecond); - - if(pFirst<_vetoMergeMomentumCut || pSecond<_vetoMergeMomentumCut) { - streamlog_out(DEBUG1) << "FullLDCTracking_MarlinTrk::VetoMerge do not veto as below momentum cut of 2.5 : pFirst = " << pFirst << " pSecond = " << pSecond << std::endl; + const float pzSecond = secondHelix.getMomentum()[2]; + const float pFirst = sqrt(pxFirst * pxFirst + pyFirst * pyFirst + pzFirst * pzFirst); + const float pSecond = sqrt(pxSecond * pxSecond + pySecond * pySecond + pzSecond * pzSecond); + + if (pFirst < _vetoMergeMomentumCut || pSecond < _vetoMergeMomentumCut) { + streamlog_out(DEBUG1) << "FullLDCTracking_MarlinTrk::VetoMerge do not veto as below momentum cut of 2.5 : pFirst = " + << pFirst << " pSecond = " << pSecond << std::endl; return false; } bool veto = false; - - bool testCombinationOnly=true; - TrackExtended * combinedTrack = CombineTracks(firstTrackExt,secondTrackExt,_maxAllowedPercentageOfOutliersForTrackCombination,testCombinationOnly); + bool testCombinationOnly = true; + TrackExtended* combinedTrack = CombineTracks(firstTrackExt, secondTrackExt, + _maxAllowedPercentageOfOutliersForTrackCombination, testCombinationOnly); - - if(combinedTrack!=NULL){ - - //SJA:FIXME hardcoded cut: here the check is that no more than 7 hits have been rejected in the combined fit. - if( combinedTrack->getNDF()+15 < firstTrackExt->getNDF() + secondTrackExt->getNDF()+5 ) { - streamlog_out(DEBUG1) << "FullLDCTracking_MarlinTrk::VetoMerge fails NDF cut " << std::endl; - veto=true ; + if (combinedTrack != NULL) { + // SJA:FIXME hardcoded cut: here the check is that no more than 7 hits have been rejected in the combined fit. + if (combinedTrack->getNDF() + 15 < firstTrackExt->getNDF() + secondTrackExt->getNDF() + 5) { + streamlog_out(DEBUG1) << "FullLDCTracking_MarlinTrk::VetoMerge fails NDF cut " << std::endl; + veto = true; } - + delete combinedTrack->getGroupTracks(); delete combinedTrack; } else { - streamlog_out(DEBUG1) << "FullLDCTracking_MarlinTrk::VetoMerge fails CombineTracks(firstTrackExt,secondTrackExt,true) test" << std::endl; + streamlog_out(DEBUG1) + << "FullLDCTracking_MarlinTrk::VetoMerge fails CombineTracks(firstTrackExt,secondTrackExt,true) test" + << std::endl; veto = true; } - - if(SegmentRadialOverlap(firstTrackExt,secondTrackExt)>10) { + + if (SegmentRadialOverlap(firstTrackExt, secondTrackExt) > 10) { streamlog_out(DEBUG1) << "FullLDCTracking_MarlinTrk::VetoMerge fails SegmentRadialOverlap test " << std::endl; - veto=true; + veto = true; } return veto; - } +void FullLDCTracking_MarlinTrk::check(LCEvent*) {} -void FullLDCTracking_MarlinTrk::check( LCEvent* ) { } +void FullLDCTracking_MarlinTrk::end() { delete _encoder; } -void FullLDCTracking_MarlinTrk::end() { - - delete _encoder ; - -} +void FullLDCTracking_MarlinTrk::setupGeom(const dd4hep::Detector& theDetector) { + + double bFieldVec[3]; + theDetector.field().magneticField({0, 0, 0}, bFieldVec); // get the magnetic field vector from DD4hep + _bField = bFieldVec[2] / dd4hep::tesla; // z component at (0,0,0) -void FullLDCTracking_MarlinTrk::setupGeom( const dd4hep::Detector& theDetector){ - - double bFieldVec[3]; - theDetector.field().magneticField({0,0,0},bFieldVec); // get the magnetic field vector from DD4hep - _bField = bFieldVec[2]/dd4hep::tesla; // z component at (0,0,0) - //-- VXD Parameters-- - _nLayersVTX = 0 ; - - try{ - - streamlog_out( DEBUG9 ) << " filling VXD parameters " << std::endl ; - + _nLayersVTX = 0; + + try { + + streamlog_out(DEBUG9) << " filling VXD parameters " << std::endl; + dd4hep::DetElement vtxDE = theDetector.detector("VXD"); dd4hep::rec::ZPlanarData* vtx = vtxDE.extension(); - _nLayersVTX=vtx->layers.size(); - - } - catch( std::runtime_error& e){ - - streamlog_out( DEBUG9 ) << " ### VXD detector Not Present in Compact File" << std::endl ; + _nLayersVTX = vtx->layers.size(); + + } catch (std::runtime_error& e) { + + streamlog_out(DEBUG9) << " ### VXD detector Not Present in Compact File" << std::endl; } - - //-- SIT Parameters-- - _nLayersSIT = 0 ; + _nLayersSIT = 0; - try{ + try { - streamlog_out( DEBUG9 ) << " filling SIT parameters " << std::endl ; + streamlog_out(DEBUG9) << " filling SIT parameters " << std::endl; dd4hep::DetElement sitDE = theDetector.detector("SIT"); dd4hep::rec::ZPlanarData* sit = sitDE.extension(); - _nLayersSIT=sit->layers.size(); - } - catch( std::runtime_error& e){ - - streamlog_out( DEBUG9 ) << " ### SIT detector Not Present in Compact File " << std::endl ; + _nLayersSIT = sit->layers.size(); + } catch (std::runtime_error& e) { + streamlog_out(DEBUG9) << " ### SIT detector Not Present in Compact File " << std::endl; } //-- SET Parameters-- - _nLayersSET = 0 ; + _nLayersSET = 0; - try{ + try { - streamlog_out( DEBUG9 ) << " filling SET parameters " << std::endl ; + streamlog_out(DEBUG9) << " filling SET parameters " << std::endl; dd4hep::DetElement setDE = theDetector.detector("SET"); dd4hep::rec::ZPlanarData* set = setDE.extension(); - _nLayersSET=set->layers.size(); - } - catch( std::runtime_error& e){ - - streamlog_out( DEBUG9 ) << " ### SET detector Not Present in Compact File " << std::endl ; + _nLayersSET = set->layers.size(); + } catch (std::runtime_error& e) { + streamlog_out(DEBUG9) << " ### SET detector Not Present in Compact File " << std::endl; } - //-- FTD Parameters-- - _petalBasedFTDWithOverlaps = false; + _petalBasedFTDWithOverlaps = false; _nLayersFTD = 0; - try{ + try { - streamlog_out( DEBUG9 ) << " filling FTD parameters " << std::endl ; + streamlog_out(DEBUG9) << " filling FTD parameters " << std::endl; dd4hep::DetElement ftdDE = theDetector.detector("FTD"); dd4hep::rec::ZDiskPetalsData* ftd = ftdDE.extension(); _nLayersFTD = ftd->layers.size(); - for (unsigned int disk=0; disk < _nLayersFTD; ++disk) { + for (unsigned int disk = 0; disk < _nLayersFTD; ++disk) { - _zLayerFTD.push_back( ftd->layers[ disk ].zPosition + ftd->layers[ disk ].zOffsetSensitive ) ; - _zLayerFTD.push_back( ftd->layers[ disk ].zPosition - ftd->layers[ disk ].zOffsetSensitive ) ; + _zLayerFTD.push_back(ftd->layers[disk].zPosition + ftd->layers[disk].zOffsetSensitive); + _zLayerFTD.push_back(ftd->layers[disk].zPosition - ftd->layers[disk].zOffsetSensitive); _petalBasedFTDWithOverlaps = true; - } - // SJA: Here we increase the size of _nLayersFTD as we are treating the - _nLayersFTD =_zLayerFTD.size() ; + // SJA: Here we increase the size of _nLayersFTD as we are treating the + _nLayersFTD = _zLayerFTD.size(); - } - catch( std::runtime_error& e){ - - streamlog_out( DEBUG9 ) << " ### FTD detector Not Present in Compact File" << std::endl ; + } catch (std::runtime_error& e) { - } - - + streamlog_out(DEBUG9) << " ### FTD detector Not Present in Compact File" << std::endl; + } } - diff --git a/source/Refitting/src/GetPurity.h b/source/Refitting/src/GetPurity.h index e60cb2f..f30c78f 100644 --- a/source/Refitting/src/GetPurity.h +++ b/source/Refitting/src/GetPurity.h @@ -1,118 +1,107 @@ -#ifndef GETPURITY_h +#ifndef GETPURITY_h #define GETPURITY_h 1 - +#include "UTIL/LCTrackerConf.h" #include -#include +#include #include +#include #include -#include #include -#include "UTIL/LCTrackerConf.h" -#include #include +#include +#include #include +#include #include #include -#include -#include - -#include #include "UTIL/LCTrackerConf.h" +#include +using namespace lcio; +using namespace marlin; -using namespace lcio ; -using namespace marlin ; - - -class purityMCP{ - public: - float purity; - MCParticle* mcp; +class purityMCP { +public: + float purity; + MCParticle* mcp; }; -class GetPurityUtil{ - public: - GetPurityUtil(){;} - typedef std::vector< LCRelationNavigator* > Navec; - typedef std::vector< SimTrackerHit* > SimTrackerHitVec; - typedef std::map< MCParticle* , int > mymap; - typedef mymap::iterator myIter; - typedef std::multimap< int , MCParticle*> revMCPMap; - typedef revMCPMap::iterator revIter; - //navecはsimtrackerhit,trackerhitの奴を使いそうなやつだけpush_backしてからGetPurityの引数に入れる。 - - - - purityMCP GetPurity(TrackerHitVec tvec, Navec navec){ - //pMCPにはdominantMCPのアドレスを指した状態で返ってくる。 - int ntrkhits = tvec.size(); - SimTrackerHitVec simvec; - int bkgcount = 0; - for(int i = 0; i < ntrkhits; i++){ - LCObject* trk = dynamic_cast(tvec[i]); - const LCObjectVec* lcoVec = NULL; - int navsize = navec.size(); - for(int j = 0; i < navsize; j++){ - if(navec[j] != NULL){ - lcoVec = &navec[j]->getRelatedToObjects(trk);//見つからない場合はNULLを返すわけじゃないので、sizeが0かどうかで判定する。 - if(lcoVec->size() != 0){ - break; - } - } - } - int size = lcoVec->size(); - simvec.reserve(size); - if(size == 0){ - bkgcount++; - } - else{ - for(int jlc = 0; jlc < size; jlc++) simvec.push_back( dynamic_cast( lcoVec->at(jlc) ) ); - } - } - mymap map; - myIter it; - for(int i = 0; i < int(simvec.size()); i++ ){ - it = map.find(simvec[i]->getMCParticle()); - //( it != map.end() ) ? ( it->second++ ) : ( map.insert(std::make_pair(simvec[i]->getMCParticle(),1)) ); - //上の表記は何故かできない模様。 - if(it != map.end()){ it->second++; } - else map.insert(std::make_pair(simvec[i]->getMCParticle(),1)); +class GetPurityUtil { +public: + GetPurityUtil() { ; } + typedef std::vector Navec; + typedef std::vector SimTrackerHitVec; + typedef std::map mymap; + typedef mymap::iterator myIter; + typedef std::multimap revMCPMap; + typedef revMCPMap::iterator revIter; + // navecはsimtrackerhit,trackerhitの奴を使いそうなやつだけpush_backしてからGetPurityの引数に入れる。 + + purityMCP GetPurity(TrackerHitVec tvec, Navec navec) { + // pMCPにはdominantMCPのアドレスを指した状態で返ってくる。 + int ntrkhits = tvec.size(); + SimTrackerHitVec simvec; + int bkgcount = 0; + for (int i = 0; i < ntrkhits; i++) { + LCObject* trk = dynamic_cast(tvec[i]); + const LCObjectVec* lcoVec = NULL; + int navsize = navec.size(); + for (int j = 0; i < navsize; j++) { + if (navec[j] != NULL) { + lcoVec = &navec[j]->getRelatedToObjects( + trk); // 見つからない場合はNULLを返すわけじゃないので、sizeが0かどうかで判定する。 + if (lcoVec->size() != 0) { + break; + } + } } - - - float purity = 0 ; - revMCPMap revmap; - for(myIter itm = map.begin(); itm != map.end(); itm++){ - revmap.insert(std::make_pair(itm->second,itm->first)); + int size = lcoVec->size(); + simvec.reserve(size); + if (size == 0) { + bkgcount++; + } else { + for (int jlc = 0; jlc < size; jlc++) + simvec.push_back(dynamic_cast(lcoVec->at(jlc))); } - MCParticle* dominantmcp = NULL; + } + mymap map; + myIter it; + for (int i = 0; i < int(simvec.size()); i++) { + it = map.find(simvec[i]->getMCParticle()); + //( it != map.end() ) ? ( it->second++ ) : ( map.insert(std::make_pair(simvec[i]->getMCParticle(),1)) ); + // 上の表記は何故かできない模様。 + if (it != map.end()) { + it->second++; + } else + map.insert(std::make_pair(simvec[i]->getMCParticle(), 1)); + } + + float purity = 0; + revMCPMap revmap; + for (myIter itm = map.begin(); itm != map.end(); itm++) { + revmap.insert(std::make_pair(itm->second, itm->first)); + } + MCParticle* dominantmcp = NULL; #if 0 std::cout << "revmap.size() : " << revmap.size() << std::endl; #endif - if(revmap.size() != 0){ - revIter maxit = std::max_element(revmap.begin(),revmap.end()); - dominantmcp = maxit->second; + if (revmap.size() != 0) { + revIter maxit = std::max_element(revmap.begin(), revmap.end()); + dominantmcp = maxit->second; #if 0 std::cout << "dominantmcp->getPDG() : " << dominantmcp->getPDG() << std::endl; #endif - float ndmcp = float(maxit->first); - purity = ndmcp/(float(simvec.size()) + float(bkgcount) ); - } - purityMCP pack; - pack.mcp = dominantmcp; - pack.purity = purity; - return pack; - } + float ndmcp = float(maxit->first); + purity = ndmcp / (float(simvec.size()) + float(bkgcount)); + } + purityMCP pack; + pack.mcp = dominantmcp; + pack.purity = purity; + return pack; + } }; - - - - - - - #endif diff --git a/source/Refitting/src/RefitFinal.cc b/source/Refitting/src/RefitFinal.cc index 4899311..448a754 100644 --- a/source/Refitting/src/RefitFinal.cc +++ b/source/Refitting/src/RefitFinal.cc @@ -36,37 +36,28 @@ RefitFinal::RefitFinal() : Processor("RefitFinal") { // register steering parameters: name, description, class-variable, default // value - registerInputCollection(LCIO::TRACK, "InputTrackCollectionName", - "Name of the input track collection", + registerInputCollection(LCIO::TRACK, "InputTrackCollectionName", "Name of the input track collection", _input_track_col_name, _input_track_col_name); - registerInputCollection( - LCIO::LCRELATION, "InputRelationCollectionName", - "Name of the input track to MCParticle relation collection", - _input_track_rel_name, _input_track_rel_name); + registerInputCollection(LCIO::LCRELATION, "InputRelationCollectionName", + "Name of the input track to MCParticle relation collection", _input_track_rel_name, + _input_track_rel_name); - registerOutputCollection(LCIO::TRACK, "OutputTrackCollectionName", - "Name of the output track collection", + registerOutputCollection(LCIO::TRACK, "OutputTrackCollectionName", "Name of the output track collection", _output_track_col_name, _output_track_col_name); registerOutputCollection(LCIO::LCRELATION, "OutputRelationCollectionName", - "Refit Track to MCParticle relation collection Name", - _output_track_rel_name, _output_track_rel_name); + "Refit Track to MCParticle relation collection Name", _output_track_rel_name, + _output_track_rel_name); - registerProcessorParameter("MultipleScatteringOn", - "Use MultipleScattering in Fit", _MSOn, - bool(true)); + registerProcessorParameter("MultipleScatteringOn", "Use MultipleScattering in Fit", _MSOn, bool(true)); - registerProcessorParameter("EnergyLossOn", "Use Energy Loss in Fit", _ElossOn, - bool(true)); + registerProcessorParameter("EnergyLossOn", "Use Energy Loss in Fit", _ElossOn, bool(true)); - registerProcessorParameter("SmoothOn", "Smooth All Mesurement Sites in Fit", - _SmoothOn, bool(false)); + registerProcessorParameter("SmoothOn", "Smooth All Mesurement Sites in Fit", _SmoothOn, bool(false)); - registerProcessorParameter( - "Max_Chi2_Incr", - "maximum allowable chi2 increment when moving from one site to another", - _Max_Chi2_Incr, _Max_Chi2_Incr); + registerProcessorParameter("Max_Chi2_Incr", "maximum allowable chi2 increment when moving from one site to another", + _Max_Chi2_Incr, _Max_Chi2_Incr); registerProcessorParameter("ReferencePoint", "Identifier of the reference point to use for the " @@ -80,7 +71,6 @@ RefitFinal::RefitFinal() : Processor("RefitFinal") { registerProcessorParameter("MinClustersOnTrackAfterFit", "Final minimum number of track clusters", _minClustersOnTrackAfterFit, int(4)); - } void RefitFinal::init() { @@ -88,62 +78,56 @@ void RefitFinal::init() { // usually a good idea to printParameters(); - _trksystem = - MarlinTrk::Factory::createMarlinTrkSystem("DDKalTest", nullptr, ""); + _trksystem = MarlinTrk::Factory::createMarlinTrkSystem("DDKalTest", nullptr, ""); /////////////////////////////// - _encoder = std::make_shared( - lcio::LCTrackerCellID::encoding_string()); + _encoder = std::make_shared(lcio::LCTrackerCellID::encoding_string()); if (not _trksystem) { - throw EVENT::Exception( - "Cannot initialize MarlinTrkSystem of Type: DDKalTest"); + throw EVENT::Exception("Cannot initialize MarlinTrkSystem of Type: DDKalTest"); } _trksystem->setOption(MarlinTrk::IMarlinTrkSystem::CFG::useQMS, _MSOn); _trksystem->setOption(MarlinTrk::IMarlinTrkSystem::CFG::usedEdx, _ElossOn); - _trksystem->setOption(MarlinTrk::IMarlinTrkSystem::CFG::useSmoothing, - _SmoothOn); + _trksystem->setOption(MarlinTrk::IMarlinTrkSystem::CFG::useSmoothing, _SmoothOn); _trksystem->init(); _n_run = 0; _n_evt = 0; } -void RefitFinal::processRunHeader(LCRunHeader *) { ++_n_run; } +void RefitFinal::processRunHeader(LCRunHeader*) { ++_n_run; } -void RefitFinal::processEvent(LCEvent *evt) { +void RefitFinal::processEvent(LCEvent* evt) { - // set the correct configuration for the tracking system for this event - MarlinTrk::TrkSysConfig< MarlinTrk::IMarlinTrkSystem::CFG::useQMS> mson( _trksystem, _MSOn ) ; - MarlinTrk::TrkSysConfig< MarlinTrk::IMarlinTrkSystem::CFG::usedEdx> elosson( _trksystem,_ElossOn) ; - MarlinTrk::TrkSysConfig< MarlinTrk::IMarlinTrkSystem::CFG::useSmoothing> smoothon( _trksystem,_SmoothOn) ; + // set the correct configuration for the tracking system for this event + MarlinTrk::TrkSysConfig mson(_trksystem, _MSOn); + MarlinTrk::TrkSysConfig elosson(_trksystem, _ElossOn); + MarlinTrk::TrkSysConfig smoothon(_trksystem, _SmoothOn); ++_n_evt; // get input collection and relations - LCCollection *input_track_col = - this->GetCollection(evt, _input_track_col_name); + LCCollection* input_track_col = this->GetCollection(evt, _input_track_col_name); if (not input_track_col) { return; } // establish the track collection that will be created - LCCollectionVec *trackVec = new LCCollectionVec(LCIO::TRACK); + LCCollectionVec* trackVec = new LCCollectionVec(LCIO::TRACK); _encoder->reset(); // if we want to point back to the hits we need to set the flag LCFlagImpl trkFlag(0); trkFlag.setBit(LCIO::TRBIT_HITS); trackVec->setFlag(trkFlag.getFlag()); - LCCollection *input_rel_col = this->GetCollection(evt, _input_track_rel_name); - LCCollectionVec *trackRelationCollection = nullptr; + LCCollection* input_rel_col = this->GetCollection(evt, _input_track_rel_name); + LCCollectionVec* trackRelationCollection = nullptr; std::shared_ptr relation; if (not input_rel_col) { - streamlog_out(DEBUG9) - << "No input relation collection, not creating one either" << std::endl; + streamlog_out(DEBUG9) << "No input relation collection, not creating one either" << std::endl; } else { trackRelationCollection = new LCCollectionVec(LCIO::LCRELATION); relation = std::make_shared(input_rel_col); @@ -156,14 +140,12 @@ void RefitFinal::processEvent(LCEvent *evt) { // loop over the input tracks and refit for (int iTrack = 0; iTrack < nTracks; ++iTrack) { - Track *track = static_cast(input_track_col->getElementAt(iTrack)); + Track* track = static_cast(input_track_col->getElementAt(iTrack)); - auto marlin_trk = - std::unique_ptr(_trksystem->createTrack()); + auto marlin_trk = std::unique_ptr(_trksystem->createTrack()); EVENT::TrackerHitVec trkHits = track->getTrackerHits(); - streamlog_out(DEBUG5) << "---- track n = " << iTrack - << " n hits = " << trkHits.size() << std::endl; + streamlog_out(DEBUG5) << "---- track n = " << iTrack << " n hits = " << trkHits.size() << std::endl; const int nHitsTrack = trkHits.size(); @@ -177,15 +159,13 @@ void RefitFinal::processEvent(LCEvent *evt) { continue; } - streamlog_out(DEBUG4) << "Refit: Trackstate after initialisation\n" - << marlin_trk->toString() << std::endl; + streamlog_out(DEBUG4) << "Refit: Trackstate after initialisation\n" << marlin_trk->toString() << std::endl; streamlog_out(DEBUG5) << "track initialised " << std::endl; int fit_status = marlin_trk->fit(); - streamlog_out(DEBUG4) << "RefitHit: Trackstate after fit()\n" - << marlin_trk->toString() << std::endl; + streamlog_out(DEBUG4) << "RefitHit: Trackstate after fit()\n" << marlin_trk->toString() << std::endl; if (fit_status != 0) { continue; @@ -194,28 +174,27 @@ void RefitFinal::processEvent(LCEvent *evt) { auto lcio_trk = std::unique_ptr(new IMPL::TrackImpl()); const bool fit_direction = MarlinTrk::IMarlinTrack::forward; - int return_code = finaliseLCIOTrack(marlin_trk.get(), lcio_trk.get(), - trkHits, fit_direction); + int return_code = finaliseLCIOTrack(marlin_trk.get(), lcio_trk.get(), trkHits, fit_direction); - if ( return_code != MarlinTrk::IMarlinTrack::success ) { + if (return_code != MarlinTrk::IMarlinTrack::success) { streamlog_out(DEBUG3) << "finaliseLCIOTrack failed" << std::endl; continue; } - streamlog_out(DEBUG5) << " *** created finalized LCIO track - return code " - << return_code << std::endl + streamlog_out(DEBUG5) << " *** created finalized LCIO track - return code " << return_code << std::endl << *lcio_trk << std::endl; // fit finished - get hits in the fit - std::vector> hits_in_fit; - std::vector> outliers; + std::vector> hits_in_fit; + std::vector> outliers; // remember the hits are ordered in the order in which they were fitted marlin_trk->getHitsInFit(hits_in_fit); if (int(hits_in_fit.size()) < _minClustersOnTrackAfterFit) { - streamlog_out(DEBUG3) << "Less than " << _minClustersOnTrackAfterFit << " hits in fit: Track " + streamlog_out(DEBUG3) << "Less than " << _minClustersOnTrackAfterFit + << " hits in fit: Track " "Discarded. Number of hits = " << trkHits.size() << std::endl; continue; @@ -223,7 +202,7 @@ void RefitFinal::processEvent(LCEvent *evt) { marlin_trk->getOutliers(outliers); - std::vector all_hits; + std::vector all_hits; all_hits.reserve(hits_in_fit.size() + outliers.size()); for (unsigned ihit = 0; ihit < hits_in_fit.size(); ++ihit) { @@ -237,20 +216,14 @@ void RefitFinal::processEvent(LCEvent *evt) { UTIL::BitField64 encoder2(lcio::LCTrackerCellID::encoding_string()); encoder2.reset(); // reset to 0 MarlinTrk::addHitNumbersToTrack(lcio_trk.get(), all_hits, false, encoder2); - MarlinTrk::addHitNumbersToTrack(lcio_trk.get(), hits_in_fit, true, - encoder2); + MarlinTrk::addHitNumbersToTrack(lcio_trk.get(), hits_in_fit, true, encoder2); - streamlog_out(DEBUG4) << "processEvent: Hit numbers for track " - << lcio_trk->id() << ": " << std::endl; + streamlog_out(DEBUG4) << "processEvent: Hit numbers for track " << lcio_trk->id() << ": " << std::endl; int detID = 0; - for (size_t ip = 0; ip < lcio_trk->subdetectorHitNumbers().size(); - ip = ip + 2) { + for (size_t ip = 0; ip < lcio_trk->subdetectorHitNumbers().size(); ip = ip + 2) { detID++; - streamlog_out(DEBUG4) - << " det id " << detID - << " , nhits in track = " << lcio_trk->subdetectorHitNumbers()[ip] - << " , nhits in fit = " << lcio_trk->subdetectorHitNumbers()[ip + 1] - << std::endl; + streamlog_out(DEBUG4) << " det id " << detID << " , nhits in track = " << lcio_trk->subdetectorHitNumbers()[ip] + << " , nhits in fit = " << lcio_trk->subdetectorHitNumbers()[ip + 1] << std::endl; if (lcio_trk->subdetectorHitNumbers()[ip] > 0) lcio_trk->setTypeBit(detID); } @@ -262,8 +235,7 @@ void RefitFinal::processEvent(LCEvent *evt) { auto mcParticleVec = relation->getRelatedToObjects(track); auto weightVec = relation->getRelatedToWeights(track); for (size_t i = 0; i < mcParticleVec.size(); ++i) { - LCRelationImpl *relationTrack = - new LCRelationImpl(lcioTrkPtr, mcParticleVec[i], weightVec[i]); + LCRelationImpl* relationTrack = new LCRelationImpl(lcioTrkPtr, mcParticleVec[i], weightVec[i]); trackRelationCollection->addElement(relationTrack); } } @@ -276,50 +248,42 @@ void RefitFinal::processEvent(LCEvent *evt) { } } -void RefitFinal::check(LCEvent *) {} +void RefitFinal::check(LCEvent*) {} void RefitFinal::end() {} -LCCollection *RefitFinal::GetCollection(LCEvent *evt, std::string colName) { +LCCollection* RefitFinal::GetCollection(LCEvent* evt, std::string colName) { - LCCollection *col = nullptr; + LCCollection* col = nullptr; try { col = evt->getCollection(colName.c_str()); - streamlog_out(DEBUG3) << " --> " << colName.c_str() - << " track collection found in event = " << col - << " number of elements " - << col->getNumberOfElements() << std::endl; - } catch (DataNotAvailableException &e) { - streamlog_out(DEBUG3) << " --> " << colName.c_str() - << " collection absent in event" << std::endl; + streamlog_out(DEBUG3) << " --> " << colName.c_str() << " track collection found in event = " << col + << " number of elements " << col->getNumberOfElements() << std::endl; + } catch (DataNotAvailableException& e) { + streamlog_out(DEBUG3) << " --> " << colName.c_str() << " collection absent in event" << std::endl; } return col; } -int RefitFinal::FitInit2(Track *track, MarlinTrk::IMarlinTrack *marlinTrk) { +int RefitFinal::FitInit2(Track* track, MarlinTrk::IMarlinTrack* marlinTrk) { TrackStateImpl trackState; if (_refPoint == -1) { - trackState = - TrackStateImpl(TrackState::AtOther, track->getD0(), track->getPhi(), - track->getOmega(), track->getZ0(), track->getTanLambda(), - track->getCovMatrix(), track->getReferencePoint()); + trackState = TrackStateImpl(TrackState::AtOther, track->getD0(), track->getPhi(), track->getOmega(), track->getZ0(), + track->getTanLambda(), track->getCovMatrix(), track->getReferencePoint()); } else { - const TrackState *trackAtHit = track->getTrackState(_refPoint); + const TrackState* trackAtHit = track->getTrackState(_refPoint); if (not trackAtHit) { - streamlog_out(ERROR) << "Cannot find trackstate for " << _refPoint - << std::endl; + streamlog_out(ERROR) << "Cannot find trackstate for " << _refPoint << std::endl; return MarlinTrk::IMarlinTrack::error; } trackState = TrackStateImpl(*trackAtHit); } - const bool direction = _extrapolateForward - ? MarlinTrk::IMarlinTrack::forward - : MarlinTrk::IMarlinTrack::backward; + const bool direction = _extrapolateForward ? MarlinTrk::IMarlinTrack::forward : MarlinTrk::IMarlinTrack::backward; marlinTrk->initialise(trackState, _bField, direction); return MarlinTrk::IMarlinTrack::success; diff --git a/source/Refitting/src/RefitProcessor.cc b/source/Refitting/src/RefitProcessor.cc index 3ef22b9..b18a06c 100644 --- a/source/Refitting/src/RefitProcessor.cc +++ b/source/Refitting/src/RefitProcessor.cc @@ -3,458 +3,386 @@ #include #include +#include #include #include -#include -#include #include +#include #include #include -#include #include "UTIL/LCTrackerConf.h" +#include #include #include - -#include "DD4hep/Detector.h" #include "DD4hep/DD4hepUnits.h" +#include "DD4hep/Detector.h" // ----- include for verbosity dependend logging --------- #include "marlin/VerbosityLevels.h" - #include "MarlinTrk/Factory.h" -#include "MarlinTrk/IMarlinTrack.h" #include "MarlinTrk/HelixTrack.h" +#include "MarlinTrk/IMarlinTrack.h" #include "MarlinTrk/MarlinTrkUtils.h" -using namespace lcio ; -using namespace marlin ; +using namespace lcio; +using namespace marlin; -using namespace MarlinTrk ; - - -RefitProcessor aRefitProcessor ; +using namespace MarlinTrk; +RefitProcessor aRefitProcessor; RefitProcessor::RefitProcessor() : Processor("RefitProcessor") { - + // modify processor description - _description = "RefitProcessor refits an input track collection, producing a new collection of tracks." ; - - + _description = "RefitProcessor refits an input track collection, producing a new collection of tracks."; + // register steering parameters: name, description, class-variable, default value - - registerInputCollection( LCIO::TRACK, - "InputTrackCollectionName" , - "Name of the input track collection" , - _input_track_col_name , - std::string("TruthTracks") ) ; - - registerInputCollection( LCIO::LCRELATION, - "InputTrackRelCollection" , - "Name of the MCParticle-Track Relations collection for input tracks" , - _input_track_rel_name , - std::string("TruthTracksMCP") ) ; - - registerOutputCollection( LCIO::TRACK, - "OutputTrackCollectionName" , - "Name of the output track collection" , - _output_track_col_name , - std::string("RefittedTracks") ) ; - - registerOutputCollection( LCIO::LCRELATION, - "OutputTrackRelCollection" , - "Name of the MCParticle-Track Relations collection for output tracks" , - _output_track_rel_name , - std::string("RefittedTracksMCP") ) ; - - registerProcessorParameter("MultipleScatteringOn", - "Use MultipleScattering in Fit", - _MSOn, - bool(true)); - - registerProcessorParameter("EnergyLossOn", - "Use Energy Loss in Fit", - _ElossOn, - bool(true)); - - registerProcessorParameter("SmoothOn", - "Smooth All Mesurement Sites in Fit", - _SmoothOn, - bool(false)); - - registerProcessorParameter( "InitialTrackErrorD0", - "Value used for the initial d0 variance of the trackfit", - _initialTrackError_d0, - float(1.e6)); - - registerProcessorParameter( "InitialTrackErrorPhi0", - "Value used for the initial phi0 variance of the trackfit", - _initialTrackError_phi0, - float(1.e2)); - - registerProcessorParameter( "InitialTrackErrorOmega", - "Value used for the initial omega variance of the trackfit", - _initialTrackError_omega, - float(1.e-4)); - - registerProcessorParameter( "InitialTrackErrorZ0", - "Value used for the initial z0 variance of the trackfit", - _initialTrackError_z0, - float(1.e6)); - - registerProcessorParameter( "InitialTrackErrorTanL", - "Value used for the initial tanL variance of the trackfit", - _initialTrackError_tanL, - float(1.e2)); - - registerProcessorParameter( "MaxChi2PerHit", - "Maximum Chi-squared value allowed when assigning a hit to a track", - _maxChi2PerHit, - float(1.e2)); - - registerProcessorParameter( "TrackSystemName", - "Name of the track fitting system to be used (KalTest, DDKalTest, aidaTT, ... )", - _trkSystemName, - std::string("KalTest") ); - - registerProcessorParameter( "InitialTrackState", - "TrackState to use for initialization of the fit: -1: refit from hits [default], 1: AtIP, 2: AtFirstHit, 3: AtLastHit, 4:AtCalo" , - _initialTrackState, - int(-1) ); - - registerProcessorParameter( "FitDirection", - "Fit direction: -1: backward [default], +1: forward", - _fitDirection, - int(-1) ); - - registerProcessorParameter( "ParticleMass", - "particle mass that is used in the fit - default is the pion mass: 0.13957018 )", - _mass , - double(0.13957018) ) ; + registerInputCollection(LCIO::TRACK, "InputTrackCollectionName", "Name of the input track collection", + _input_track_col_name, std::string("TruthTracks")); + + registerInputCollection(LCIO::LCRELATION, "InputTrackRelCollection", + "Name of the MCParticle-Track Relations collection for input tracks", _input_track_rel_name, + std::string("TruthTracksMCP")); + + registerOutputCollection(LCIO::TRACK, "OutputTrackCollectionName", "Name of the output track collection", + _output_track_col_name, std::string("RefittedTracks")); + + registerOutputCollection(LCIO::LCRELATION, "OutputTrackRelCollection", + "Name of the MCParticle-Track Relations collection for output tracks", + _output_track_rel_name, std::string("RefittedTracksMCP")); + + registerProcessorParameter("MultipleScatteringOn", "Use MultipleScattering in Fit", _MSOn, bool(true)); + + registerProcessorParameter("EnergyLossOn", "Use Energy Loss in Fit", _ElossOn, bool(true)); + + registerProcessorParameter("SmoothOn", "Smooth All Mesurement Sites in Fit", _SmoothOn, bool(false)); + + registerProcessorParameter("InitialTrackErrorD0", "Value used for the initial d0 variance of the trackfit", + _initialTrackError_d0, float(1.e6)); + + registerProcessorParameter("InitialTrackErrorPhi0", "Value used for the initial phi0 variance of the trackfit", + _initialTrackError_phi0, float(1.e2)); + + registerProcessorParameter("InitialTrackErrorOmega", "Value used for the initial omega variance of the trackfit", + _initialTrackError_omega, float(1.e-4)); + + registerProcessorParameter("InitialTrackErrorZ0", "Value used for the initial z0 variance of the trackfit", + _initialTrackError_z0, float(1.e6)); + + registerProcessorParameter("InitialTrackErrorTanL", "Value used for the initial tanL variance of the trackfit", + _initialTrackError_tanL, float(1.e2)); + + registerProcessorParameter("MaxChi2PerHit", "Maximum Chi-squared value allowed when assigning a hit to a track", + _maxChi2PerHit, float(1.e2)); + + registerProcessorParameter("TrackSystemName", + "Name of the track fitting system to be used (KalTest, DDKalTest, aidaTT, ... )", + _trkSystemName, std::string("KalTest")); + + registerProcessorParameter("InitialTrackState", + "TrackState to use for initialization of the fit: -1: refit from hits [default], 1: AtIP, " + "2: AtFirstHit, 3: AtLastHit, 4:AtCalo", + _initialTrackState, int(-1)); + + registerProcessorParameter("FitDirection", "Fit direction: -1: backward [default], +1: forward", _fitDirection, + int(-1)); + + registerProcessorParameter("ParticleMass", + "particle mass that is used in the fit - default is the pion mass: 0.13957018 )", _mass, + double(0.13957018)); } +void RefitProcessor::init() { + + streamlog_out(DEBUG) << " init called " << std::endl; -void RefitProcessor::init() { - - streamlog_out(DEBUG) << " init called " << std::endl ; - // usually a good idea to - printParameters() ; - - + printParameters(); + dd4hep::Detector& theDetector = dd4hep::Detector::getInstance(); - double bFieldVec[3]; - theDetector.field().magneticField({0,0,0},bFieldVec); // get the magnetic field vector from DD4hep - _bField = bFieldVec[2]/dd4hep::tesla; // z component at (0,0,0) + double bFieldVec[3]; + theDetector.field().magneticField({0, 0, 0}, bFieldVec); // get the magnetic field vector from DD4hep + _bField = bFieldVec[2] / dd4hep::tesla; // z component at (0,0,0) - //---- + //---- // set up the geometery needed for tracking - _trksystem = MarlinTrk::Factory::createMarlinTrkSystem( _trkSystemName , 0 , "" ) ; - - - if( _trksystem == 0 ){ - - throw EVENT::Exception( std::string(" Cannot initialize MarlinTrkSystem of Type: ") + _trkSystemName ) ; + _trksystem = MarlinTrk::Factory::createMarlinTrkSystem(_trkSystemName, 0, ""); + + if (_trksystem == 0) { + + throw EVENT::Exception(std::string(" Cannot initialize MarlinTrkSystem of Type: ") + _trkSystemName); } - - _trksystem->setOption( IMarlinTrkSystem::CFG::useQMS, _MSOn ) ; - _trksystem->setOption( IMarlinTrkSystem::CFG::usedEdx, _ElossOn) ; - _trksystem->setOption( IMarlinTrkSystem::CFG::useSmoothing, _SmoothOn) ; - _trksystem->init() ; - - - _n_run = 0 ; - _n_evt = 0 ; - + + _trksystem->setOption(IMarlinTrkSystem::CFG::useQMS, _MSOn); + _trksystem->setOption(IMarlinTrkSystem::CFG::usedEdx, _ElossOn); + _trksystem->setOption(IMarlinTrkSystem::CFG::useSmoothing, _SmoothOn); + _trksystem->init(); + + _n_run = 0; + _n_evt = 0; } -void RefitProcessor::processRunHeader( LCRunHeader* ) { - - ++_n_run ; -} +void RefitProcessor::processRunHeader(LCRunHeader*) { ++_n_run; } + +void RefitProcessor::processEvent(LCEvent* evt) { -void RefitProcessor::processEvent( LCEvent * evt ) { - - - // set the correct configuration for the tracking system for this event - MarlinTrk::TrkSysConfig< MarlinTrk::IMarlinTrkSystem::CFG::useQMS> mson( _trksystem, _MSOn ) ; - MarlinTrk::TrkSysConfig< MarlinTrk::IMarlinTrkSystem::CFG::usedEdx> elosson( _trksystem,_ElossOn) ; - MarlinTrk::TrkSysConfig< MarlinTrk::IMarlinTrkSystem::CFG::useSmoothing> smoothon( _trksystem,_SmoothOn) ; + // set the correct configuration for the tracking system for this event + MarlinTrk::TrkSysConfig mson(_trksystem, _MSOn); + MarlinTrk::TrkSysConfig elosson(_trksystem, _ElossOn); + MarlinTrk::TrkSysConfig smoothon(_trksystem, _SmoothOn); //-- note: this will not be printed if compiled w/o MARLINDEBUG=1 ! - - streamlog_out(DEBUG4) << " processing event: " << _n_evt - << std::endl ; - - // get input collection and relations - LCCollection* input_track_col = this->GetCollection( evt, _input_track_col_name ) ; - - auto input_track_rels = this->GetRelations( evt, _input_track_rel_name ) ; - - if( input_track_col != 0 ){ - - - // establish the track collection that will be created - LCCollectionVec* trackVec = new LCCollectionVec( LCIO::TRACK ) ; - + + streamlog_out(DEBUG4) << " processing event: " << _n_evt << std::endl; + + // get input collection and relations + LCCollection* input_track_col = this->GetCollection(evt, _input_track_col_name); + + auto input_track_rels = this->GetRelations(evt, _input_track_rel_name); + + if (input_track_col != 0) { + + // establish the track collection that will be created + LCCollectionVec* trackVec = new LCCollectionVec(LCIO::TRACK); + // if we want to point back to the hits we need to set the flag - LCFlagImpl trkFlag(0) ; - trkFlag.setBit( LCIO::TRBIT_HITS ) ; - trackVec->setFlag( trkFlag.getFlag() ) ; + LCFlagImpl trkFlag(0); + trkFlag.setBit(LCIO::TRBIT_HITS); + trackVec->setFlag(trkFlag.getFlag()); // establish the track relations collection that will be created auto trackRelNav = UTIL::LCRelationNavigator(LCIO::TRACK, LCIO::MCPARTICLE); - int nTracks = input_track_col->getNumberOfElements() ; - streamlog_out(DEBUG4) << "Processing input collection " << _input_track_col_name << " with " << nTracks << " tracks\n"; - - // loop over the input tacks and refit using KalTest - for(int i=0; i< nTracks ; ++i){ - - Track* track_to_refit = dynamic_cast( input_track_col->getElementAt( i ) ) ; - - EVENT::TrackerHitVec trkHits = track_to_refit->getTrackerHits() ; - - - std::vector< std::pair > r2_values; + int nTracks = input_track_col->getNumberOfElements(); + streamlog_out(DEBUG4) << "Processing input collection " << _input_track_col_name << " with " << nTracks + << " tracks\n"; + + // loop over the input tacks and refit using KalTest + for (int i = 0; i < nTracks; ++i) { + + Track* track_to_refit = dynamic_cast(input_track_col->getElementAt(i)); + + EVENT::TrackerHitVec trkHits = track_to_refit->getTrackerHits(); + + std::vector> r2_values; r2_values.reserve(trkHits.size()); - - for (TrackerHitVec::iterator it=trkHits.begin(); it!=trkHits.end(); ++it) { + + for (TrackerHitVec::iterator it = trkHits.begin(); it != trkHits.end(); ++it) { EVENT::TrackerHit* h = *it; - float r2 = h->getPosition()[0]*h->getPosition()[0]+h->getPosition()[1]*h->getPosition()[1]; + float r2 = h->getPosition()[0] * h->getPosition()[0] + h->getPosition()[1] * h->getPosition()[1]; r2_values.push_back(std::make_pair(r2, *it)); } - - sort(r2_values.begin(),r2_values.end()); - + + sort(r2_values.begin(), r2_values.end()); + trkHits.clear(); trkHits.reserve(r2_values.size()); - - UTIL::BitField64 cellID_encoder( lcio::LCTrackerCellID::encoding_string() ) ; - for (std::vector< std::pair >::iterator it=r2_values.begin(); it!=r2_values.end(); ++it) { + UTIL::BitField64 cellID_encoder(lcio::LCTrackerCellID::encoding_string()); + + for (std::vector>::iterator it = r2_values.begin(); it != r2_values.end(); + ++it) { + + streamlog_out(DEBUG0) << " -- added tracker hit : " << *it->second << std::endl; - streamlog_out( DEBUG0 ) << " -- added tracker hit : " << *it->second << std::endl ; - - trkHits.push_back(it->second); - + trkHits.push_back(it->second); } - - - + // setup initial dummy covariance matrix EVENT::FloatVec covMatrix; covMatrix.resize(15); - - for (unsigned icov = 0; icovcreateTrack(); - - marlinTrk->setMass( _mass ) ; + marlinTrk->setMass(_mass); + + TrackImpl* refittedTrack = new TrackImpl; - TrackImpl* refittedTrack = new TrackImpl ; - try { - + int error = 0; - - if( _initialTrackState < 0 ) { // initialize the track from three hits - // error = MarlinTrk::createFinalisedLCIOTrack(marlinTrk, trkHits, refittedTrack, fit_direction, covMatrix, _bField, _maxChi2PerHit); - - // call with empty pre_fit -> should use default initialisation of the implementation, e.g. - // use an internal pre fit in aidaTT - error = MarlinTrk::createFinalisedLCIOTrack(marlinTrk, trkHits, refittedTrack, fit_direction, 0 , _bField, _maxChi2PerHit); + if (_initialTrackState < 0) { // initialize the track from three hits + + // error = MarlinTrk::createFinalisedLCIOTrack(marlinTrk, trkHits, refittedTrack, fit_direction, covMatrix, + // _bField, _maxChi2PerHit); + // call with empty pre_fit -> should use default initialisation of the implementation, e.g. + // use an internal pre fit in aidaTT + error = MarlinTrk::createFinalisedLCIOTrack(marlinTrk, trkHits, refittedTrack, fit_direction, 0, _bField, + _maxChi2PerHit); + } else { // use the specified track state - } else { // use the specified track state - - EVENT::TrackState* ts = const_cast ( track_to_refit->getTrackState( _initialTrackState ) ) ; - - if( !ts ){ + EVENT::TrackState* ts = const_cast(track_to_refit->getTrackState(_initialTrackState)); - std::stringstream ess ; ess << " Could not get track state at " << _initialTrackState << " from track to refit " ; - throw EVENT::Exception( ess.str() ) ; - } + if (!ts) { - IMPL::TrackStateImpl pre_fit( *ts ) ; - pre_fit.setCovMatrix( covMatrix ) ; - - error = MarlinTrk::createFinalisedLCIOTrack(marlinTrk, trkHits, refittedTrack, fit_direction, &pre_fit , _bField, _maxChi2PerHit); - } - + std::stringstream ess; + ess << " Could not get track state at " << _initialTrackState << " from track to refit "; + throw EVENT::Exception(ess.str()); + } - if( error != IMarlinTrack::success || refittedTrack->getNdf() < 0 ) { + IMPL::TrackStateImpl pre_fit(*ts); + pre_fit.setCovMatrix(covMatrix); - streamlog_out(DEBUG6) << "in event << " << evt->getEventNumber() - << " >> track refit returns error code " << error << "; NDF = " << refittedTrack->getNdf() - << ". Number of hits = "<< trkHits.size() << std::endl ; + error = MarlinTrk::createFinalisedLCIOTrack(marlinTrk, trkHits, refittedTrack, fit_direction, &pre_fit, + _bField, _maxChi2PerHit); + } + + if (error != IMarlinTrack::success || refittedTrack->getNdf() < 0) { + streamlog_out(DEBUG6) << "in event << " << evt->getEventNumber() << " >> track refit returns error code " + << error << "; NDF = " << refittedTrack->getNdf() + << ". Number of hits = " << trkHits.size() << std::endl; } - - + } catch (...) { - - streamlog_out(ERROR) << "RefitProcessor::processEvent: EVENT: << " << evt->getEventNumber() << " >> exception caught and rethown. Track = " - << track_to_refit << std::endl; + + streamlog_out(ERROR) << "RefitProcessor::processEvent: EVENT: << " << evt->getEventNumber() + << " >> exception caught and rethown. Track = " << track_to_refit << std::endl; delete refittedTrack; - - throw ; - + + throw; } - - - + // fitting finished get hit in the fit - - std::vector > hits_in_fit; - std::vector > outliers ; - + + std::vector> hits_in_fit; + std::vector> outliers; + // remember the hits are ordered in the order in which they were fitted // here we are fitting inwards to the first is the last and vice verse - + marlinTrk->getHitsInFit(hits_in_fit); - - if( hits_in_fit.size() < 3 ) { - streamlog_out(DEBUG6) << "RefitProcessor: Less than 3 hits in fit: number of hits = " << trkHits.size() << std::endl; + + if (hits_in_fit.size() < 3) { + streamlog_out(DEBUG6) << "RefitProcessor: Less than 3 hits in fit: number of hits = " << trkHits.size() + << std::endl; } - - + std::vector all_hits; all_hits.reserve(300); - - - for ( unsigned ihit = 0; ihit < hits_in_fit.size(); ++ihit) { + + for (unsigned ihit = 0; ihit < hits_in_fit.size(); ++ihit) { all_hits.push_back(hits_in_fit[ihit].first); } - + // UTIL::BitField64 cellID_encoder( lcio::LCTrackerCellID::encoding_string() ) ; - + MarlinTrk::addHitNumbersToTrack(refittedTrack, all_hits, true, cellID_encoder); - + marlinTrk->getOutliers(outliers); - - for ( unsigned ihit = 0; ihit < outliers.size(); ++ihit) { + + for (unsigned ihit = 0; ihit < outliers.size(); ++ihit) { all_hits.push_back(outliers[ihit].first); } - + MarlinTrk::addHitNumbersToTrack(refittedTrack, all_hits, false, cellID_encoder); - + delete marlinTrk; - - - int nhits_in_vxd = refittedTrack->subdetectorHitNumbers()[ 2 * lcio::ILDDetID::VXD - 1 ]; - int nhits_in_ftd = refittedTrack->subdetectorHitNumbers()[ 2 * lcio::ILDDetID::FTD - 1 ]; - int nhits_in_sit = refittedTrack->subdetectorHitNumbers()[ 2 * lcio::ILDDetID::SIT - 1 ]; - int nhits_in_tpc = refittedTrack->subdetectorHitNumbers()[ 2 * lcio::ILDDetID::TPC - 1 ]; - int nhits_in_set = refittedTrack->subdetectorHitNumbers()[ 2 * lcio::ILDDetID::SET - 1 ]; - - - streamlog_out( DEBUG3 ) << " Hit numbers for Track "<< refittedTrack->id() << ": " - << " vxd hits = " << nhits_in_vxd - << " ftd hits = " << nhits_in_ftd - << " sit hits = " << nhits_in_sit - << " tpc hits = " << nhits_in_tpc - << " set hits = " << nhits_in_set - << std::endl; - - - if (nhits_in_vxd > 0) refittedTrack->setTypeBit( lcio::ILDDetID::VXD ) ; - if (nhits_in_ftd > 0) refittedTrack->setTypeBit( lcio::ILDDetID::FTD ) ; - if (nhits_in_sit > 0) refittedTrack->setTypeBit( lcio::ILDDetID::SIT ) ; - if (nhits_in_tpc > 0) refittedTrack->setTypeBit( lcio::ILDDetID::TPC ) ; - if (nhits_in_set > 0) refittedTrack->setTypeBit( lcio::ILDDetID::SET ) ; - - + + int nhits_in_vxd = refittedTrack->subdetectorHitNumbers()[2 * lcio::ILDDetID::VXD - 1]; + int nhits_in_ftd = refittedTrack->subdetectorHitNumbers()[2 * lcio::ILDDetID::FTD - 1]; + int nhits_in_sit = refittedTrack->subdetectorHitNumbers()[2 * lcio::ILDDetID::SIT - 1]; + int nhits_in_tpc = refittedTrack->subdetectorHitNumbers()[2 * lcio::ILDDetID::TPC - 1]; + int nhits_in_set = refittedTrack->subdetectorHitNumbers()[2 * lcio::ILDDetID::SET - 1]; + + streamlog_out(DEBUG3) << " Hit numbers for Track " << refittedTrack->id() << ": " + << " vxd hits = " << nhits_in_vxd << " ftd hits = " << nhits_in_ftd + << " sit hits = " << nhits_in_sit << " tpc hits = " << nhits_in_tpc + << " set hits = " << nhits_in_set << std::endl; + + if (nhits_in_vxd > 0) + refittedTrack->setTypeBit(lcio::ILDDetID::VXD); + if (nhits_in_ftd > 0) + refittedTrack->setTypeBit(lcio::ILDDetID::FTD); + if (nhits_in_sit > 0) + refittedTrack->setTypeBit(lcio::ILDDetID::SIT); + if (nhits_in_tpc > 0) + refittedTrack->setTypeBit(lcio::ILDDetID::TPC); + if (nhits_in_set > 0) + refittedTrack->setTypeBit(lcio::ILDDetID::SET); + trackVec->addElement(refittedTrack); - - // assign the relations previously assigned to the input tracks - if(input_track_rels){ - const auto& objVec = input_track_rels->getRelatedToObjects( track_to_refit ); - const auto& weights = input_track_rels->getRelatedToWeights( track_to_refit ); - - for( unsigned int irel=0 ; irel < objVec.size() ; ++irel ){ + + // assign the relations previously assigned to the input tracks + if (input_track_rels) { + const auto& objVec = input_track_rels->getRelatedToObjects(track_to_refit); + const auto& weights = input_track_rels->getRelatedToWeights(track_to_refit); + + for (unsigned int irel = 0; irel < objVec.size(); ++irel) { trackRelNav.addRelation(refittedTrack, objVec[irel], weights[irel]); } } } - - evt->addCollection( trackVec , _output_track_col_name) ; + + evt->addCollection(trackVec, _output_track_col_name); auto trackRelVec = trackRelNav.createLCCollection(); - evt->addCollection( trackRelVec , _output_track_rel_name) ; + evt->addCollection(trackRelVec, _output_track_rel_name); } - ++_n_evt ; + ++_n_evt; } - - -void RefitProcessor::check( LCEvent * ) { +void RefitProcessor::check(LCEvent*) { // nothing to check here - could be used to fill checkplots in reconstruction processor } +void RefitProcessor::end() { -void RefitProcessor::end(){ - - streamlog_out(DEBUG) << "RefitProcessor::end() " << name() - << " processed " << _n_evt << " events in " << _n_run << " runs " - << std::endl ; - + streamlog_out(DEBUG) << "RefitProcessor::end() " << name() << " processed " << _n_evt << " events in " << _n_run + << " runs " << std::endl; } -LCCollection* RefitProcessor::GetCollection( LCEvent * evt, std::string colName ){ - +LCCollection* RefitProcessor::GetCollection(LCEvent* evt, std::string colName) { + LCCollection* col = NULL; - - - try{ - col = evt->getCollection( colName.c_str() ) ; - streamlog_out( DEBUG4 ) << " --> " << colName.c_str() << " track collection found in event = " << col << " number of elements " << col->getNumberOfElements() << std::endl; - } - catch(DataNotAvailableException &e){ - streamlog_out( DEBUG4 ) << " --> " << colName.c_str() << " collection absent in event" << std::endl; + + try { + col = evt->getCollection(colName.c_str()); + streamlog_out(DEBUG4) << " --> " << colName.c_str() << " track collection found in event = " << col + << " number of elements " << col->getNumberOfElements() << std::endl; + } catch (DataNotAvailableException& e) { + streamlog_out(DEBUG4) << " --> " << colName.c_str() << " collection absent in event" << std::endl; } - - return col; - + + return col; } -std::unique_ptr RefitProcessor::GetRelations(LCEvent * evt , std::string RelName ) { - +std::unique_ptr RefitProcessor::GetRelations(LCEvent* evt, std::string RelName) { + std::unique_ptr nav = nullptr; - - try{ - nav.reset(new LCRelationNavigator(evt->getCollection( RelName.c_str() ))); - streamlog_out( DEBUG2 ) << "RefitProcessor --> " << RelName << " track relation collection in event = " << nav.get() << std::endl; - } - catch(DataNotAvailableException &e){ - streamlog_out( DEBUG2 ) << "RefitProcessor --> " << RelName.c_str() << " track relation collection absent in event" << std::endl; + + try { + nav.reset(new LCRelationNavigator(evt->getCollection(RelName.c_str()))); + streamlog_out(DEBUG2) << "RefitProcessor --> " << RelName << " track relation collection in event = " << nav.get() + << std::endl; + } catch (DataNotAvailableException& e) { + streamlog_out(DEBUG2) << "RefitProcessor --> " << RelName.c_str() << " track relation collection absent in event" + << std::endl; } - + return nav; - } - - diff --git a/source/Refitting/src/SiliconTracking_MarlinTrk.cc b/source/Refitting/src/SiliconTracking_MarlinTrk.cc index 7fc1bec..7640dce 100644 --- a/source/Refitting/src/SiliconTracking_MarlinTrk.cc +++ b/source/Refitting/src/SiliconTracking_MarlinTrk.cc @@ -1,39 +1,38 @@ #include "SiliconTracking_MarlinTrk.h" - -#include -#include #include #include #include #include #include #include -#include #include +#include +#include +#include -#include #include -#include #include +#include +#include -#include #include +#include -#include "DD4hep/Detector.h" #include "DD4hep/DD4hepUnits.h" +#include "DD4hep/Detector.h" #include "DDRec/DetectorData.h" -#include #include "UTIL/LCTrackerConf.h" +#include #include -#include "MarlinTrk/MarlinTrkUtils.h" -#include "MarlinTrk/HelixTrack.h" +#include "MarlinTrk/Factory.h" #include "MarlinTrk/HelixFit.h" +#include "MarlinTrk/HelixTrack.h" #include "MarlinTrk/IMarlinTrack.h" -#include "MarlinTrk/Factory.h" +#include "MarlinTrk/MarlinTrkUtils.h" #include "MarlinTrk/MarlinTrkDiagnostics.h" #ifdef MARLINTRK_DIAGNOSTICS_ON @@ -48,793 +47,650 @@ #include "TH1F.h" #include "TH2F.h" -using namespace lcio ; -using namespace marlin ; -using namespace MarlinTrk ; +using namespace lcio; +using namespace marlin; +using namespace MarlinTrk; -using std::min; -using std::max; using std::abs; +using std::max; +using std::min; const int SiliconTracking_MarlinTrk::_output_track_col_quality_GOOD = 1; const int SiliconTracking_MarlinTrk::_output_track_col_quality_FAIR = 2; const int SiliconTracking_MarlinTrk::_output_track_col_quality_POOR = 3; -const double SiliconTracking_MarlinTrk::TWOPI = 2*M_PI; +const double SiliconTracking_MarlinTrk::TWOPI = 2 * M_PI; -SiliconTracking_MarlinTrk aSiliconTracking_MarlinTrk ; +SiliconTracking_MarlinTrk aSiliconTracking_MarlinTrk; // Use Frank's histogram handling // helper enum defining histogram index in vector namespace DiagnosticsHistograms { - enum index1D{ - //----- histogram "names" - htriplets, hntriplets, hntriplets_good, hntriplets_2MCP, hntriplets_3MCP, hntriplets_1MCP_Bad, hntriplets_bad, htriplets_chi2_good, htriplets_chi2_bad, htriplets_pt_good, htriplets_pt_bad, - //----- keep Size as last : - Size1D - }; - - enum index2D{ - //----- histogram "names" - htripletChi2vPt_good, htripletChi2vPt_bad, - //----- keep Size as last : - Size2D - }; - - - class Histograms{ - public: - Histograms(int nhistos1D, int nhistos2D) { - _h1D.resize(nhistos1D); - _h2D.resize(nhistos2D); - } - - // 1 Dimentional Histos - - void create1D(int idx, const char* n, int nBin, double min, double max ){ - create1D( idx , n , n , nBin, min , max ) ; - } - - void create1D(int idx, const char* n, const char* t, int nBin, double min, double max ){ +enum index1D { + //----- histogram "names" + htriplets, + hntriplets, + hntriplets_good, + hntriplets_2MCP, + hntriplets_3MCP, + hntriplets_1MCP_Bad, + hntriplets_bad, + htriplets_chi2_good, + htriplets_chi2_bad, + htriplets_pt_good, + htriplets_pt_bad, + //----- keep Size as last : + Size1D +}; + +enum index2D { + //----- histogram "names" + htripletChi2vPt_good, + htripletChi2vPt_bad, + //----- keep Size as last : + Size2D +}; + +class Histograms { +public: + Histograms(int nhistos1D, int nhistos2D) { + _h1D.resize(nhistos1D); + _h2D.resize(nhistos2D); + } - if( _h1D.at( idx ) ){ - streamlog_out( ERROR ) << "create1D: Histogram already created ERROR exit(1) called from File" << __FILE__ << " line " << __LINE__ << std::endl; - exit(1); - } - _h1D.at( idx ) = new TH1D( n, t , nBin , min, max ) ; - - streamlog_out( DEBUG ) << " create 1D histo " << n << " at index " << idx << std::endl ; - } - - void create1D(int idx, const char* n, const char* t, int nBin , double* bins ){ - - if( _h1D.at( idx ) ){ - streamlog_out( ERROR ) << "create1D: Histogram already created ERROR exit(1) called from File" << __FILE__ << " line " << __LINE__ << std::endl; - exit(1); - } - _h1D.at( idx ) = new TH1D( n, t , nBin , bins ) ; - - streamlog_out( DEBUG ) << " create 1D histo " << n << " at index " << idx << std::endl ; + // 1 Dimentional Histos + + void create1D(int idx, const char* n, int nBin, double min, double max) { create1D(idx, n, n, nBin, min, max); } + + void create1D(int idx, const char* n, const char* t, int nBin, double min, double max) { + + if (_h1D.at(idx)) { + streamlog_out(ERROR) << "create1D: Histogram already created ERROR exit(1) called from File" << __FILE__ + << " line " << __LINE__ << std::endl; + exit(1); } - - void fill1D( int idx , double val, double weight=1.0 ){ _h1D.at( idx )->Fill( val , weight ) ; } - - - // 2 Dimentional Histos - - void create2D(int idx, const char* n, int nBinX, double minX, double maxX, int nBinY, double minY, double maxY ){ - create2D( idx , n , n , nBinX, minX , maxX, nBinY, minY , maxY ) ; + _h1D.at(idx) = new TH1D(n, t, nBin, min, max); + + streamlog_out(DEBUG) << " create 1D histo " << n << " at index " << idx << std::endl; + } + + void create1D(int idx, const char* n, const char* t, int nBin, double* bins) { + + if (_h1D.at(idx)) { + streamlog_out(ERROR) << "create1D: Histogram already created ERROR exit(1) called from File" << __FILE__ + << " line " << __LINE__ << std::endl; + exit(1); } - - void create2D(int idx, const char* n, const char* t, int nBinX, double minX, double maxX, int nBinY, double minY, double maxY ){ + _h1D.at(idx) = new TH1D(n, t, nBin, bins); - if( _h2D.at( idx ) ){ - streamlog_out( ERROR ) << "create2D: Histogram already created ERROR exit(1) called from File" << __FILE__ << " line " << __LINE__ << std::endl; - exit(1); - } - - _h2D.at( idx ) = new TH2F(n, t, nBinX, minX, maxX, nBinY, minY, maxY) ; - - streamlog_out( DEBUG ) << " create 2D histo " << n << " at index " << idx << std::endl ; + streamlog_out(DEBUG) << " create 1D histo " << n << " at index " << idx << std::endl; + } + + void fill1D(int idx, double val, double weight = 1.0) { _h1D.at(idx)->Fill(val, weight); } + // 2 Dimentional Histos + + void create2D(int idx, const char* n, int nBinX, double minX, double maxX, int nBinY, double minY, double maxY) { + create2D(idx, n, n, nBinX, minX, maxX, nBinY, minY, maxY); + } + + void create2D(int idx, const char* n, const char* t, int nBinX, double minX, double maxX, int nBinY, double minY, + double maxY) { + + if (_h2D.at(idx)) { + streamlog_out(ERROR) << "create2D: Histogram already created ERROR exit(1) called from File" << __FILE__ + << " line " << __LINE__ << std::endl; + exit(1); } - - void fill2D( int idx , double valx, double valy, double weight=1.0 ){ _h2D.at( idx )->Fill(valx, valy, weight) ; } - - - protected: - - std::vector _h1D; - std::vector _h2D; - - }; - - - -} + _h2D.at(idx) = new TH2F(n, t, nBinX, minX, maxX, nBinY, minY, maxY); + + streamlog_out(DEBUG) << " create 2D histo " << n << " at index " << idx << std::endl; + } + void fill2D(int idx, double valx, double valy, double weight = 1.0) { _h2D.at(idx)->Fill(valx, valy, weight); } +protected: + std::vector _h1D; + std::vector _h2D; +}; +} // namespace DiagnosticsHistograms SiliconTracking_MarlinTrk::SiliconTracking_MarlinTrk() : Processor("SiliconTracking_MarlinTrk") { - + _description = "Pattern recognition in silicon trackers"; - + _petalBasedFTDWithOverlaps = false; - + // zero triplet counters _ntriplets = _ntriplets_good = _ntriplets_2MCP = _ntriplets_3MCP = _ntriplets_1MCP_Bad = _ntriplets_bad = 0; - std::vector combinations; - + combinations.push_back(6); combinations.push_back(4); combinations.push_back(3); - + combinations.push_back(6); combinations.push_back(4); combinations.push_back(2); - + combinations.push_back(6); combinations.push_back(3); combinations.push_back(2); - + combinations.push_back(5); combinations.push_back(4); combinations.push_back(3); - + combinations.push_back(5); combinations.push_back(4); combinations.push_back(2); - + combinations.push_back(5); combinations.push_back(3); combinations.push_back(2); - + combinations.push_back(5); combinations.push_back(3); combinations.push_back(1); - + combinations.push_back(5); combinations.push_back(2); combinations.push_back(1); - + combinations.push_back(4); combinations.push_back(3); combinations.push_back(2); - + combinations.push_back(4); combinations.push_back(3); combinations.push_back(1); - + combinations.push_back(4); combinations.push_back(2); combinations.push_back(1); - + combinations.push_back(3); combinations.push_back(2); combinations.push_back(1); - - - registerProcessorParameter("LayerCombinations", - "Combinations of Hits in Layers", - _Combinations, - combinations); - + + registerProcessorParameter("LayerCombinations", "Combinations of Hits in Layers", _Combinations, combinations); + std::vector combinationsFTD; - + combinationsFTD.push_back(6); combinationsFTD.push_back(5); combinationsFTD.push_back(4); - + combinationsFTD.push_back(6); combinationsFTD.push_back(5); combinationsFTD.push_back(3); - + combinationsFTD.push_back(5); combinationsFTD.push_back(4); combinationsFTD.push_back(3); - + combinationsFTD.push_back(5); combinationsFTD.push_back(4); combinationsFTD.push_back(2); - + combinationsFTD.push_back(5); combinationsFTD.push_back(4); combinationsFTD.push_back(1); - + combinationsFTD.push_back(5); combinationsFTD.push_back(3); combinationsFTD.push_back(2); - + combinationsFTD.push_back(5); combinationsFTD.push_back(3); combinationsFTD.push_back(1); - + combinationsFTD.push_back(5); combinationsFTD.push_back(2); combinationsFTD.push_back(1); - + combinationsFTD.push_back(4); combinationsFTD.push_back(3); combinationsFTD.push_back(2); - + combinationsFTD.push_back(4); combinationsFTD.push_back(3); combinationsFTD.push_back(1); - + combinationsFTD.push_back(4); combinationsFTD.push_back(3); combinationsFTD.push_back(0); - + combinationsFTD.push_back(4); combinationsFTD.push_back(2); combinationsFTD.push_back(1); - + combinationsFTD.push_back(4); combinationsFTD.push_back(2); combinationsFTD.push_back(0); - + combinationsFTD.push_back(4); combinationsFTD.push_back(1); combinationsFTD.push_back(0); - + combinationsFTD.push_back(3); combinationsFTD.push_back(2); combinationsFTD.push_back(1); - + combinationsFTD.push_back(3); combinationsFTD.push_back(2); combinationsFTD.push_back(0); - + combinationsFTD.push_back(3); combinationsFTD.push_back(1); combinationsFTD.push_back(0); - + combinationsFTD.push_back(2); combinationsFTD.push_back(1); combinationsFTD.push_back(0); - - - registerProcessorParameter("LayerCombinationsFTD", - "Combinations of Hits in FTD", - _CombinationsFTD, - combinationsFTD); - - registerProcessorParameter("NDivisionsInPhi", - "Number of divisions in Phi", - _nDivisionsInPhi, - int(80)); - - registerProcessorParameter("NDivisionsInPhiFTD", - "Number of divisions in Phi for FTD", - _nPhiFTD, - int(30)); - - registerProcessorParameter("NDivisionsInTheta", - "Number of divisions in Theta", - _nDivisionsInTheta, - int(80)); - + + registerProcessorParameter("LayerCombinationsFTD", "Combinations of Hits in FTD", _CombinationsFTD, combinationsFTD); + + registerProcessorParameter("NDivisionsInPhi", "Number of divisions in Phi", _nDivisionsInPhi, int(80)); + + registerProcessorParameter("NDivisionsInPhiFTD", "Number of divisions in Phi for FTD", _nPhiFTD, int(30)); + + registerProcessorParameter("NDivisionsInTheta", "Number of divisions in Theta", _nDivisionsInTheta, int(80)); + // Input Collections // ^^^^^^^^^^^^^^^^^ - registerInputCollection(LCIO::TRACKERHITPLANE, - "VTXHitCollectionName", - "VTX Hit Collection Name", - _VTXHitCollection, + registerInputCollection(LCIO::TRACKERHITPLANE, "VTXHitCollectionName", "VTX Hit Collection Name", _VTXHitCollection, std::string("VTXTrackerHits")); - - - registerInputCollection(LCIO::TRACKERHITPLANE, - "FTDPixelHitCollectionName", - "FTD Pixel Hit Collection Name", - _FTDPixelHitCollection, - std::string("FTDPixelTrackerHits")); - - registerInputCollection(LCIO::TRACKERHIT, - "FTDSpacePointCollectionName", - "FTD FTDSpacePoint Collection Name", - _FTDSpacePointCollection, - std::string("FTDSpacePoints")); - - - registerInputCollection(LCIO::TRACKERHIT, - "SITHitCollectionName", - "SIT Hit Collection Name", - _SITHitCollection, - std::string("SITTrackerHits")); - + + registerInputCollection(LCIO::TRACKERHITPLANE, "FTDPixelHitCollectionName", "FTD Pixel Hit Collection Name", + _FTDPixelHitCollection, std::string("FTDPixelTrackerHits")); + + registerInputCollection(LCIO::TRACKERHIT, "FTDSpacePointCollectionName", "FTD FTDSpacePoint Collection Name", + _FTDSpacePointCollection, std::string("FTDSpacePoints")); + + registerInputCollection(LCIO::TRACKERHIT, "SITHitCollectionName", "SIT Hit Collection Name", _SITHitCollection, + std::string("SITTrackerHits")); + // Output Collections // ^^^^^^^^^^^^^^^^^^ - registerOutputCollection(LCIO::TRACK, - "SiTrackCollectionName", - "Silicon track Collection Name", - _siTrkCollection, + registerOutputCollection(LCIO::TRACK, "SiTrackCollectionName", "Silicon track Collection Name", _siTrkCollection, std::string("SiTracks")); - - - + // Steering parameters // ^^^^^^^^^^^^^^^^^^^ - registerProcessorParameter("Chi2WRphiTriplet", - "Chi2WRphiTriplet", - _chi2WRPhiTriplet, - float(1.)); - - registerProcessorParameter("Chi2WRphiQuartet", - "Chi2WRphiQuartet", - _chi2WRPhiQuartet, - float(1.)); - - registerProcessorParameter("Chi2WRphiSeptet", - "Chi2WRphiSeptet", - _chi2WRPhiSeptet, - float(1.)); - - registerProcessorParameter("Chi2WZTriplet", - "Chi2WZTriplet", - _chi2WZTriplet, - float(0.5)); - - registerProcessorParameter("Chi2WZQuartet", - "Chi2WZQuartet", - _chi2WZQuartet, - float(0.5)); - - registerProcessorParameter("Chi2WZSeptet", - "Chi2WZSeptet", - _chi2WZSeptet, - float(0.5)); - - registerProcessorParameter("Chi2FitCut", - "Chi2 Fit Cut", - _chi2FitCut, - float(120.0)); - - registerProcessorParameter("AngleCutForMerging", - "Angle Cut For Merging", - _angleCutForMerging, - float(0.1)); - - registerProcessorParameter("MinDistCutAttach", - "MinDistCutAttach", - _minDistCutAttach, - float(2.5)); - - registerProcessorParameter("MinLayerToAttach", - "MinLayerToAttach", - _minimalLayerToAttach, - int(-1)); - - registerProcessorParameter("CutOnD0", - "cut on D0 for tracks", - _cutOnD0, - float(100.0)); - - registerProcessorParameter("CutOnZ0", - "cut on Z0 for tracks", - _cutOnZ0, - float(100.0)); - - registerProcessorParameter("CutOnPt", - "cut on Pt", - _cutOnPt, - float(0.05)); - - registerProcessorParameter("MinimalHits", - "minimal hits (default 3)", - _minimalHits, - int(3)); - - registerProcessorParameter("NHitsChi2", - "Maximal number of hits for which a track with n hits is better than one with n-1hits. (defaut 5)", - _nHitsChi2, - int(5)); - + registerProcessorParameter("Chi2WRphiTriplet", "Chi2WRphiTriplet", _chi2WRPhiTriplet, float(1.)); + + registerProcessorParameter("Chi2WRphiQuartet", "Chi2WRphiQuartet", _chi2WRPhiQuartet, float(1.)); + + registerProcessorParameter("Chi2WRphiSeptet", "Chi2WRphiSeptet", _chi2WRPhiSeptet, float(1.)); + + registerProcessorParameter("Chi2WZTriplet", "Chi2WZTriplet", _chi2WZTriplet, float(0.5)); + + registerProcessorParameter("Chi2WZQuartet", "Chi2WZQuartet", _chi2WZQuartet, float(0.5)); + + registerProcessorParameter("Chi2WZSeptet", "Chi2WZSeptet", _chi2WZSeptet, float(0.5)); + + registerProcessorParameter("Chi2FitCut", "Chi2 Fit Cut", _chi2FitCut, float(120.0)); + + registerProcessorParameter("AngleCutForMerging", "Angle Cut For Merging", _angleCutForMerging, float(0.1)); + + registerProcessorParameter("MinDistCutAttach", "MinDistCutAttach", _minDistCutAttach, float(2.5)); + + registerProcessorParameter("MinLayerToAttach", "MinLayerToAttach", _minimalLayerToAttach, int(-1)); + + registerProcessorParameter("CutOnD0", "cut on D0 for tracks", _cutOnD0, float(100.0)); + + registerProcessorParameter("CutOnZ0", "cut on Z0 for tracks", _cutOnZ0, float(100.0)); + + registerProcessorParameter("CutOnPt", "cut on Pt", _cutOnPt, float(0.05)); + + registerProcessorParameter("MinimalHits", "minimal hits (default 3)", _minimalHits, int(3)); + + registerProcessorParameter( + "NHitsChi2", "Maximal number of hits for which a track with n hits is better than one with n-1hits. (defaut 5)", + _nHitsChi2, int(5)); + registerProcessorParameter("MaxHitsPerSector", "Maximal number of hits allowed in one theta-phi sector in VXD/SIT and FTD", - _max_hits_per_sector, - int(100)); - - registerProcessorParameter("FastAttachment", - "Fast attachment", - _attachFast, - int(0)); - - registerProcessorParameter("UseSIT", - "Use SIT", - _useSIT, - int(1)); - - - registerProcessorParameter( "InitialTrackErrorD0", - "Value used for the initial d0 variance of the trackfit", - _initialTrackError_d0, - float(1.e6)); - - registerProcessorParameter( "InitialTrackErrorPhi0", - "Value used for the initial phi0 variance of the trackfit", - _initialTrackError_phi0, - float(1.e2)); - - registerProcessorParameter( "InitialTrackErrorOmega", - "Value used for the initial omega variance of the trackfit", - _initialTrackError_omega, - float(1.e-4)); - - registerProcessorParameter( "InitialTrackErrorZ0", - "Value used for the initial z0 variance of the trackfit", - _initialTrackError_z0, - float(1.e6)); - - registerProcessorParameter( "InitialTrackErrorTanL", - "Value used for the initial tanL variance of the trackfit", - _initialTrackError_tanL, - float(1.e2)); - - - registerProcessorParameter( "MaxChi2PerHit", - "Maximum Chi-squared value allowed when assigning a hit to a track", - _maxChi2PerHit, - double(1.e2)); - - - registerProcessorParameter("CheckForDelta", - "Check for Delta rays hits in hit-to-track assignment", - _checkForDelta, + _max_hits_per_sector, int(100)); + + registerProcessorParameter("FastAttachment", "Fast attachment", _attachFast, int(0)); + + registerProcessorParameter("UseSIT", "Use SIT", _useSIT, int(1)); + + registerProcessorParameter("InitialTrackErrorD0", "Value used for the initial d0 variance of the trackfit", + _initialTrackError_d0, float(1.e6)); + + registerProcessorParameter("InitialTrackErrorPhi0", "Value used for the initial phi0 variance of the trackfit", + _initialTrackError_phi0, float(1.e2)); + + registerProcessorParameter("InitialTrackErrorOmega", "Value used for the initial omega variance of the trackfit", + _initialTrackError_omega, float(1.e-4)); + + registerProcessorParameter("InitialTrackErrorZ0", "Value used for the initial z0 variance of the trackfit", + _initialTrackError_z0, float(1.e6)); + + registerProcessorParameter("InitialTrackErrorTanL", "Value used for the initial tanL variance of the trackfit", + _initialTrackError_tanL, float(1.e2)); + + registerProcessorParameter("MaxChi2PerHit", "Maximum Chi-squared value allowed when assigning a hit to a track", + _maxChi2PerHit, double(1.e2)); + + registerProcessorParameter("CheckForDelta", "Check for Delta rays hits in hit-to-track assignment", _checkForDelta, int(1)); - - registerProcessorParameter("MinDistToDelta", - "Minimal distance of track hit to the delta electron hit", - _minDistToDelta, - float(0.25)); - - registerProcessorParameter("MultipleScatteringOn", - "Use MultipleScattering in Fit", - _MSOn, - bool(true)); - - registerProcessorParameter("EnergyLossOn", - "Use Energy Loss in Fit", - _ElossOn, - bool(true)); - - registerProcessorParameter("SmoothOn", - "Smooth All Mesurement Sites in Fit", - _SmoothOn, - bool(true)); - - registerProcessorParameter( "UseEventDisplay", + + registerProcessorParameter("MinDistToDelta", "Minimal distance of track hit to the delta electron hit", + _minDistToDelta, float(0.25)); + + registerProcessorParameter("MultipleScatteringOn", "Use MultipleScattering in Fit", _MSOn, bool(true)); + + registerProcessorParameter("EnergyLossOn", "Use Energy Loss in Fit", _ElossOn, bool(true)); + + registerProcessorParameter("SmoothOn", "Smooth All Mesurement Sites in Fit", _SmoothOn, bool(true)); + + registerProcessorParameter("UseEventDisplay", "When using UseIterativeFitting show status of each track fit using CED event display.", - _UseEventDisplay, - bool(false)); - - registerProcessorParameter("DetectorTypeForDraw", - "Detector type sent to MarlinCED for drawing", - _detector_model_for_drawing, - int(0)); - - registerProcessorParameter( "HelixMaxR" , - "Max R (mm) Extent for drawing Helix if UseTPCForLimitsOfHelix false", - _helix_max_r , - float(2000.0) ) ; - - registerProcessorParameter( "MCpThreshold", - "Transverse Momentum Threshold MC particles which will produce tracks GeV", - _MCpThreshold, - float(0.1)); - - registerInputCollection("MCParticle", - "MCParticleCollectionName", - "Name of the MCParticle input collection", - _colNameMCParticles, - std::string("MCParticle")); - - - registerProcessorParameter( "CreateDiagnosticsHistograms", - "Create diagnostics histograms for internal analysis.", - _createDiagnosticsHistograms, - bool(false)); - - registerProcessorParameter( "TrackSystemName", - "Name of the track fitting system to be used (KalTest, DDKalTest, aidaTT, ... )", - _trkSystemName, - std::string("KalTest") ); - - - registerProcessorParameter("AplySimpleUpdatedCoreBin", - "Use simple updated triplets searching core bin. (default is false for backward compatible)", - _useSimpleUpdatedCoreBin, - bool(false)); - - - registerProcessorParameter("UseSimpleAttachHitToTrack", - "Use simple AttachHitToTrack for merging split track segments. (default is false for backward compatible)", - _useSimpleAttachHitToTrack, - bool(false)); - + _UseEventDisplay, bool(false)); + + registerProcessorParameter("DetectorTypeForDraw", "Detector type sent to MarlinCED for drawing", + _detector_model_for_drawing, int(0)); + + registerProcessorParameter("HelixMaxR", "Max R (mm) Extent for drawing Helix if UseTPCForLimitsOfHelix false", + _helix_max_r, float(2000.0)); + + registerProcessorParameter("MCpThreshold", "Transverse Momentum Threshold MC particles which will produce tracks GeV", + _MCpThreshold, float(0.1)); + + registerInputCollection("MCParticle", "MCParticleCollectionName", "Name of the MCParticle input collection", + _colNameMCParticles, std::string("MCParticle")); + + registerProcessorParameter("CreateDiagnosticsHistograms", "Create diagnostics histograms for internal analysis.", + _createDiagnosticsHistograms, bool(false)); + + registerProcessorParameter("TrackSystemName", + "Name of the track fitting system to be used (KalTest, DDKalTest, aidaTT, ... )", + _trkSystemName, std::string("KalTest")); + + registerProcessorParameter( + "AplySimpleUpdatedCoreBin", + "Use simple updated triplets searching core bin. (default is false for backward compatible)", + _useSimpleUpdatedCoreBin, bool(false)); + + registerProcessorParameter( + "UseSimpleAttachHitToTrack", + "Use simple AttachHitToTrack for merging split track segments. (default is false for backward compatible)", + _useSimpleAttachHitToTrack, bool(false)); + #ifdef MARLINTRK_DIAGNOSTICS_ON - - registerOptionalParameter("RunMarlinTrkDiagnostics", "Run MarlinTrk Diagnostics. MarlinTrk must be compiled with MARLINTRK_DIAGNOSTICS_ON defined", _runMarlinTrkDiagnostics, bool(false)); - - registerOptionalParameter("DiagnosticsName", "Name of the root file and root tree if running Diagnostics", _MarlinTrkDiagnosticsName, std::string("SiliconTrackingDiagnostics")); - + + registerOptionalParameter( + "RunMarlinTrkDiagnostics", + "Run MarlinTrk Diagnostics. MarlinTrk must be compiled with MARLINTRK_DIAGNOSTICS_ON defined", + _runMarlinTrkDiagnostics, bool(false)); + + registerOptionalParameter("DiagnosticsName", "Name of the root file and root tree if running Diagnostics", + _MarlinTrkDiagnosticsName, std::string("SiliconTrackingDiagnostics")); + #endif - + _output_track_col_quality = _output_track_col_quality_GOOD; - - } +void SiliconTracking_MarlinTrk::init() { - -void SiliconTracking_MarlinTrk::init() { - - _nRun = -1 ; - _nEvt = 0 ; + _nRun = -1; + _nEvt = 0; _encoder = new UTIL::BitField64(lcio::LCTrackerCellID::encoding_string()); _fastfitter = new MarlinTrk::HelixFit(); - printParameters() ; - + printParameters(); + // this creates a directory for this processor .... - AIDAProcessor::histogramFactory( this ) ; - + AIDAProcessor::histogramFactory(this); + if (_UseEventDisplay) { - MarlinCED::init(this) ; + MarlinCED::init(this); } - + if (_createDiagnosticsHistograms) { - - _histos = new DiagnosticsHistograms::Histograms(DiagnosticsHistograms::Size1D,DiagnosticsHistograms::Size2D); - + _histos = new DiagnosticsHistograms::Histograms(DiagnosticsHistograms::Size1D, DiagnosticsHistograms::Size2D); + // now create the 1D histos - _histos->create1D( DiagnosticsHistograms::htriplets, "htriplets", "triplets for inspection", 100, 0.0, 100.0 ) ; + _histos->create1D(DiagnosticsHistograms::htriplets, "htriplets", "triplets for inspection", 100, 0.0, 100.0); - _histos->create1D( DiagnosticsHistograms::hntriplets, "hntriplets", "total number of triplets created per event", 100, 0.0, 1000.0 ) ; - - _histos->create1D( DiagnosticsHistograms::hntriplets_good, "hntriplets_good", "triplets created from 1 MCP", 100, 0.0, 2000.0 ) ; + _histos->create1D(DiagnosticsHistograms::hntriplets, "hntriplets", "total number of triplets created per event", + 100, 0.0, 1000.0); - _histos->create1D( DiagnosticsHistograms::hntriplets_2MCP, "hntriplets_2MCP", "triplets created from 2 MCPs", 100, 0.0, 2000.0 ) ; + _histos->create1D(DiagnosticsHistograms::hntriplets_good, "hntriplets_good", "triplets created from 1 MCP", 100, + 0.0, 2000.0); - _histos->create1D( DiagnosticsHistograms::hntriplets_3MCP, "hntriplets_3MCP", "triplets created from 3 MCPs", 100, 0.0, 2000.0 ) ; + _histos->create1D(DiagnosticsHistograms::hntriplets_2MCP, "hntriplets_2MCP", "triplets created from 2 MCPs", 100, + 0.0, 2000.0); - _histos->create1D( DiagnosticsHistograms::hntriplets_1MCP_Bad, "hntriplets_1MCP_Bad", "triplets created from 1 MCP and one bad hit", 100, 0.0, 2000.0 ) ; + _histos->create1D(DiagnosticsHistograms::hntriplets_3MCP, "hntriplets_3MCP", "triplets created from 3 MCPs", 100, + 0.0, 2000.0); - _histos->create1D( DiagnosticsHistograms::hntriplets_bad, "hntriplets_bad", "triplets created from a mix of MCPs and bad hits", 100, 0.0, 10000.0 ) ; + _histos->create1D(DiagnosticsHistograms::hntriplets_1MCP_Bad, "hntriplets_1MCP_Bad", + "triplets created from 1 MCP and one bad hit", 100, 0.0, 2000.0); - _histos->create1D( DiagnosticsHistograms::htriplets_chi2_good, "htriplets_chi2_good", "chi2 of good triplets", 100, 0.0, 100.0) ; + _histos->create1D(DiagnosticsHistograms::hntriplets_bad, "hntriplets_bad", + "triplets created from a mix of MCPs and bad hits", 100, 0.0, 10000.0); - _histos->create1D( DiagnosticsHistograms::htriplets_chi2_bad, "htriplets_chi2_bad", "chi2 of bad triplets", 100, 0.0, 100.0) ; + _histos->create1D(DiagnosticsHistograms::htriplets_chi2_good, "htriplets_chi2_good", "chi2 of good triplets", 100, + 0.0, 100.0); - _histos->create1D( DiagnosticsHistograms::htriplets_pt_good, "htriplets_pt_good", "pt of good triplets", 100, 0.0, 100.0) ; - - _histos->create1D( DiagnosticsHistograms::htriplets_pt_bad, "htriplets_pt_bad", "pt of bad triplets", 100, 0.0, 100.0) ; + _histos->create1D(DiagnosticsHistograms::htriplets_chi2_bad, "htriplets_chi2_bad", "chi2 of bad triplets", 100, 0.0, + 100.0); - - // now create the 2D histos - _histos->create2D( DiagnosticsHistograms::htripletChi2vPt_good, "htripletChi2vPt_good", "chi2 of good triplets vs pt", 100, 0.0, 100.0, 100, 0.0, 100.0 ) ; - _histos->create2D( DiagnosticsHistograms::htripletChi2vPt_bad, "htripletChi2vPt_bad", "chi2 of bad triplets vs pt", 100, 0.0, 100.0, 100, 0.0, 100.0 ) ; + _histos->create1D(DiagnosticsHistograms::htriplets_pt_good, "htriplets_pt_good", "pt of good triplets", 100, 0.0, + 100.0); - - + _histos->create1D(DiagnosticsHistograms::htriplets_pt_bad, "htriplets_pt_bad", "pt of bad triplets", 100, 0.0, + 100.0); + + // now create the 2D histos + _histos->create2D(DiagnosticsHistograms::htripletChi2vPt_good, "htripletChi2vPt_good", + "chi2 of good triplets vs pt", 100, 0.0, 100.0, 100, 0.0, 100.0); + _histos->create2D(DiagnosticsHistograms::htripletChi2vPt_bad, "htripletChi2vPt_bad", "chi2 of bad triplets vs pt", + 100, 0.0, 100.0, 100, 0.0, 100.0); } - - _colours.push_back( 0xff00ff ); - _colours.push_back( 0xffff00 ); - _colours.push_back( 0x0000ff ); - _colours.push_back( 0xff00ff ); - _colours.push_back( 0x00ffff ); - _colours.push_back( 0xffffff ); - - _colours.push_back( 0xff88ff ); - _colours.push_back( 0xffff88 ); - _colours.push_back( 0x8888ff ); - _colours.push_back( 0xff88ff ); - _colours.push_back( 0x88ffff ); - _colours.push_back( 0xffffff ); - - - + + _colours.push_back(0xff00ff); + _colours.push_back(0xffff00); + _colours.push_back(0x0000ff); + _colours.push_back(0xff00ff); + _colours.push_back(0x00ffff); + _colours.push_back(0xffffff); + + _colours.push_back(0xff88ff); + _colours.push_back(0xffff88); + _colours.push_back(0x8888ff); + _colours.push_back(0xff88ff); + _colours.push_back(0x88ffff); + _colours.push_back(0xffffff); + // set up the geometery needed by KalTest - _trksystem = MarlinTrk::Factory::createMarlinTrkSystem( _trkSystemName , 0 , "" ) ; - - if( _trksystem == 0 ){ - - throw EVENT::Exception( std::string(" Cannot initialize MarlinTrkSystem of Type: ") + _trkSystemName ) ; - + _trksystem = MarlinTrk::Factory::createMarlinTrkSystem(_trkSystemName, 0, ""); + + if (_trksystem == 0) { + + throw EVENT::Exception(std::string(" Cannot initialize MarlinTrkSystem of Type: ") + _trkSystemName); } - - _trksystem->setOption( IMarlinTrkSystem::CFG::useQMS, _MSOn ) ; - _trksystem->setOption( IMarlinTrkSystem::CFG::usedEdx, _ElossOn) ; - _trksystem->setOption( IMarlinTrkSystem::CFG::useSmoothing, _SmoothOn) ; - _trksystem->init() ; - + + _trksystem->setOption(IMarlinTrkSystem::CFG::useQMS, _MSOn); + _trksystem->setOption(IMarlinTrkSystem::CFG::usedEdx, _ElossOn); + _trksystem->setOption(IMarlinTrkSystem::CFG::useSmoothing, _SmoothOn); + _trksystem->init(); + #ifdef MARLINTRK_DIAGNOSTICS_ON - - void * dcv = _trksystem->getDiagnositicsPointer(); + + void* dcv = _trksystem->getDiagnositicsPointer(); DiagnosticsController* dc = static_cast(dcv); - dc->init(_MarlinTrkDiagnosticsName,_MarlinTrkDiagnosticsName, _runMarlinTrkDiagnostics); - + dc->init(_MarlinTrkDiagnosticsName, _MarlinTrkDiagnosticsName, _runMarlinTrkDiagnostics); + #endif - + dd4hep::Detector& theDetector = dd4hep::Detector::getInstance(); - - this->setupGeom( theDetector ); - + + this->setupGeom(theDetector); if (_useSIT == 0) _nLayers = _nLayersVTX; - else + else _nLayers = _nLayersVTX + _nLayersSIT; - + // initialise the container to have separate vectors for up to _nHitsChi2 hits. _tracksWithNHitsContainer.resize(_nHitsChi2); - - _dPhi = TWOPI/_nDivisionsInPhi; - _dTheta = 2.0/_nDivisionsInTheta; - _dPhiFTD = TWOPI/_nPhiFTD; + + _dPhi = TWOPI / _nDivisionsInPhi; + _dTheta = 2.0 / _nDivisionsInTheta; + _dPhiFTD = TWOPI / _nPhiFTD; // I leave this for the moment, but 0.3 is c/1e9. // For the cut it does not make too much of a difference - double cutOnR = _cutOnPt/(0.3*_bField); - cutOnR = 1000.*cutOnR; - _cutOnOmega = 1/cutOnR; - + double cutOnR = _cutOnPt / (0.3 * _bField); + cutOnR = 1000. * cutOnR; + _cutOnOmega = 1 / cutOnR; + _output_track_col_quality = 0; - } +void SiliconTracking_MarlinTrk::processRunHeader(LCRunHeader*) { -void SiliconTracking_MarlinTrk::processRunHeader( LCRunHeader* ) { - - _nRun++ ; + _nRun++; _nEvt = 0; - + streamlog_out(MESSAGE) << "SiliconTracking_MarlinTrk ---> new run : run number = " << _nRun << std::endl; - -} +} + +void SiliconTracking_MarlinTrk::processEvent(LCEvent* evt) { -void SiliconTracking_MarlinTrk::processEvent( LCEvent * evt ) { - - // set the correct configuration for the tracking system for this event - MarlinTrk::TrkSysConfig< MarlinTrk::IMarlinTrkSystem::CFG::useQMS> mson( _trksystem, _MSOn ) ; - MarlinTrk::TrkSysConfig< MarlinTrk::IMarlinTrkSystem::CFG::usedEdx> elosson( _trksystem,_ElossOn) ; - MarlinTrk::TrkSysConfig< MarlinTrk::IMarlinTrkSystem::CFG::useSmoothing> smoothon( _trksystem,_SmoothOn) ; + // set the correct configuration for the tracking system for this event + MarlinTrk::TrkSysConfig mson(_trksystem, _MSOn); + MarlinTrk::TrkSysConfig elosson(_trksystem, _ElossOn); + MarlinTrk::TrkSysConfig smoothon(_trksystem, _SmoothOn); _current_event = evt; - + _output_track_col_quality = _output_track_col_quality_GOOD; - + // zero triplet counters _ntriplets = _ntriplets_good = _ntriplets_2MCP = _ntriplets_3MCP = _ntriplets_1MCP_Bad = _ntriplets_bad = 0; - + // Clearing the working containers from the previous event // FIXME: partly done at the end of the event, in CleanUp. Make it consistent. _tracksWithNHitsContainer.clear(); _trackImplVec.clear(); - + _colTrackerHits.clear(); _colNamesTrackerHits.clear(); - - streamlog_out(DEBUG4) << "SiliconTracking_MarlinTrk -> run = " << _nRun - << " event = " << _nEvt << std::endl; - - int successVTX = InitialiseVTX( evt ); - int successFTD = InitialiseFTD( evt ); - + + streamlog_out(DEBUG4) << "SiliconTracking_MarlinTrk -> run = " << _nRun << " event = " << _nEvt << std::endl; + + int successVTX = InitialiseVTX(evt); + int successFTD = InitialiseFTD(evt); + if (_UseEventDisplay) { - - MarlinCED::newEvent(this , _detector_model_for_drawing ) ; - + + MarlinCED::newEvent(this, _detector_model_for_drawing); } - + if (_UseEventDisplay) { this->drawEvent(); } - + if (successVTX == 1) { - - streamlog_out(DEBUG1) << " phi theta layer nh o : m : i :: o*m*i " << std::endl; - - for (int iPhi=0; iPhi<_nDivisionsInPhi; ++iPhi) { - for (int iTheta=0; iTheta<_nDivisionsInTheta;++iTheta) { - ProcessOneSector(iPhi,iTheta); // Process one VXD sector + + streamlog_out(DEBUG1) << " phi theta layer nh o : m : i :: o*m*i " << std::endl; + + for (int iPhi = 0; iPhi < _nDivisionsInPhi; ++iPhi) { + for (int iTheta = 0; iTheta < _nDivisionsInTheta; ++iTheta) { + ProcessOneSector(iPhi, iTheta); // Process one VXD sector } } - + streamlog_out(DEBUG4) << "End of Processing VXD and SIT sectors" << std::endl; - } - + if (successFTD == 1) { streamlog_out(DEBUG1) << " phi side layer nh o : m : i :: o*m*i " << std::endl; TrackingInFTD(); // Perform tracking in the FTD streamlog_out(DEBUG4) << "End of Processing FTD sectors" << std::endl; } - - - + if (successVTX == 1 || successFTD == 1) { - //if (successVTX == 1 ) { - - for (int nHits = _nHitsChi2; nHits >= 3 ;// the three is hard coded, sorry. - // It's the minimal number to form a track + // if (successVTX == 1 ) { + + for (int nHits = _nHitsChi2; nHits >= 3; // the three is hard coded, sorry. + // It's the minimal number to form a track nHits--) { - Sorting( _tracksWithNHitsContainer.getTracksWithNHitsVec( nHits ) ); - + Sorting(_tracksWithNHitsContainer.getTracksWithNHitsVec(nHits)); } - - - streamlog_out(DEBUG4) << "End of Sorting " << std::endl; - - - for (int nHits = _nHitsChi2; nHits >= 3 ;// the three is hard coded, sorry. - // It's the minimal number to form a track + + streamlog_out(DEBUG4) << "End of Sorting " << std::endl; + + for (int nHits = _nHitsChi2; nHits >= 3; // the three is hard coded, sorry. + // It's the minimal number to form a track nHits--) { - - TrackExtendedVec &tracksWithNHits = _tracksWithNHitsContainer.getTracksWithNHitsVec( nHits ); - - for (TrackExtendedVec::iterator trackIter = tracksWithNHits.begin(); - trackIter < tracksWithNHits.end(); trackIter++) { - CreateTrack( *trackIter ); + + TrackExtendedVec& tracksWithNHits = _tracksWithNHitsContainer.getTracksWithNHitsVec(nHits); + + for (TrackExtendedVec::iterator trackIter = tracksWithNHits.begin(); trackIter < tracksWithNHits.end(); + trackIter++) { + CreateTrack(*trackIter); } - streamlog_out(DEBUG4) << "End of creating "<< nHits << " hits tracks " << std::endl; + streamlog_out(DEBUG4) << "End of creating " << nHits << " hits tracks " << std::endl; } - + if (_attachFast == 0) { AttachRemainingVTXHitsSlow(); AttachRemainingFTDHitsSlow(); - } - else { + } else { AttachRemainingVTXHitsFast(); AttachRemainingFTDHitsFast(); } - - streamlog_out(DEBUG4) << "End of picking up remaining hits " << std::endl; - - LCCollectionVec * trkCol = new LCCollectionVec(LCIO::TRACK); + + streamlog_out(DEBUG4) << "End of picking up remaining hits " << std::endl; + + LCCollectionVec* trkCol = new LCCollectionVec(LCIO::TRACK); // if we want to point back to the hits we need to set the flag - LCFlagImpl trkFlag(0) ; - trkFlag.setBit( LCIO::TRBIT_HITS ) ; - trkCol->setFlag( trkFlag.getFlag() ) ; - - LCCollectionVec * relCol = NULL; - - + LCFlagImpl trkFlag(0); + trkFlag.setBit(LCIO::TRBIT_HITS); + trkCol->setFlag(trkFlag.getFlag()); + + LCCollectionVec* relCol = NULL; + FinalRefit(trkCol, relCol); - + // set the quality of the output collection switch (_output_track_col_quality) { - case _output_track_col_quality_FAIR: - trkCol->parameters().setValue( "QualityCode" , "Fair" ) ; - break; - - case _output_track_col_quality_POOR: - trkCol->parameters().setValue( "QualityCode" , "Poor" ) ; - break; - - default: - trkCol->parameters().setValue( "QualityCode" , "Good" ) ; - break; + case _output_track_col_quality_FAIR: + trkCol->parameters().setValue("QualityCode", "Fair"); + break; + + case _output_track_col_quality_POOR: + trkCol->parameters().setValue("QualityCode", "Poor"); + break; + + default: + trkCol->parameters().setValue("QualityCode", "Good"); + break; } - - - evt->addCollection(trkCol,_siTrkCollection.c_str()); - + + evt->addCollection(trkCol, _siTrkCollection.c_str()); + if (_UseEventDisplay) { this->drawEvent(); } - - } - + // fill event based histogram if (_createDiagnosticsHistograms) { @@ -845,845 +701,863 @@ void SiliconTracking_MarlinTrk::processEvent( LCEvent * evt ) { _histos->fill1D(DiagnosticsHistograms::hntriplets_3MCP, _ntriplets_3MCP); _histos->fill1D(DiagnosticsHistograms::hntriplets_1MCP_Bad, _ntriplets_1MCP_Bad); _histos->fill1D(DiagnosticsHistograms::hntriplets_bad, _ntriplets_bad); - } - + CleanUp(); streamlog_out(DEBUG4) << "Event is done " << std::endl; _nEvt++; - } - void SiliconTracking_MarlinTrk::CleanUp() { - + _tracksWithNHitsContainer.clear(); - - for (int il=0;il<_nLayers;++il) { - for (int ip=0;ip<_nDivisionsInPhi;++ip) { - for (int it=0;it<_nDivisionsInTheta; ++it) { - unsigned int iCode = il + _nLayers*ip + _nLayers*_nDivisionsInPhi*it; - - if( iCode >= _sectors.size()){ - std::cerr<< "iCode index out of range: iCode = " << iCode << " _sectors.size() = " << _sectors.size() << " exit(1) called from file " << __FILE__ << " line " << __LINE__<< std::endl; + + for (int il = 0; il < _nLayers; ++il) { + for (int ip = 0; ip < _nDivisionsInPhi; ++ip) { + for (int it = 0; it < _nDivisionsInTheta; ++it) { + unsigned int iCode = il + _nLayers * ip + _nLayers * _nDivisionsInPhi * it; + + if (iCode >= _sectors.size()) { + std::cerr << "iCode index out of range: iCode = " << iCode << " _sectors.size() = " << _sectors.size() + << " exit(1) called from file " << __FILE__ << " line " << __LINE__ << std::endl; exit(1); } - - + TrackerHitExtendedVec& hitVec = _sectors[iCode]; int nH = int(hitVec.size()); - for (int iH=0; iH= _sectorsFTD.size()){ - std::cerr<< "iCode index out of range: iCode = " << iCode << " _sectorsFTD.size() = " << _sectorsFTD.size() << " exit(1) called from file " << __FILE__ << " line " << __LINE__<< std::endl; + + for (int iS = 0; iS < 2; ++iS) { + for (unsigned int layer = 0; layer < _nlayersFTD; ++layer) { + for (int ip = 0; ip < _nPhiFTD; ++ip) { + unsigned int iCode = iS + 2 * layer + 2 * _nlayersFTD * ip; + + if (iCode >= _sectorsFTD.size()) { + std::cerr << "iCode index out of range: iCode = " << iCode << " _sectorsFTD.size() = " << _sectorsFTD.size() + << " exit(1) called from file " << __FILE__ << " line " << __LINE__ << std::endl; exit(1); } - - + TrackerHitExtendedVec& hitVec = _sectorsFTD[iCode]; int nH = int(hitVec.size()); - for (int iH=0; iHgetCollection(_FTDPixelHitCollection.c_str()); - - _colNamesTrackerHits[hitCollection] = _FTDPixelHitCollection; + + LCCollection* hitCollection = evt->getCollection(_FTDPixelHitCollection.c_str()); + + _colNamesTrackerHits[hitCollection] = _FTDPixelHitCollection; _colTrackerHits.push_back(hitCollection); - + int nelem = hitCollection->getNumberOfElements(); - + streamlog_out(DEBUG4) << "Number of FTD Pixel Hits = " << nelem << std::endl; _nTotalFTDHits = nelem; - - for (int ielem=0; ielem(hitCollection->getElementAt(ielem)); - - TrackerHitExtended * hitExt = new TrackerHitExtended( hit ); - - Vector3D U(1.0,hit->getU()[1],hit->getU()[0],Vector3D::spherical); - Vector3D V(1.0,hit->getV()[1],hit->getV()[0],Vector3D::spherical); - Vector3D Z(0.0,0.0,1.0); - + + for (int ielem = 0; ielem < nelem; ++ielem) { + + TrackerHitPlane* hit = dynamic_cast(hitCollection->getElementAt(ielem)); + + TrackerHitExtended* hitExt = new TrackerHitExtended(hit); + + Vector3D U(1.0, hit->getU()[1], hit->getU()[0], Vector3D::spherical); + Vector3D V(1.0, hit->getV()[1], hit->getV()[0], Vector3D::spherical); + Vector3D Z(0.0, 0.0, 1.0); + const float eps = 1.0e-07; - // V must be the global z axis - if( fabs(V.dot(Z)) > eps ) { - streamlog_out(ERROR) << "SiliconTracking_MarlinTrk: VXD Hit measurment vectors V is not in the global X-Y plane. \n\n exit(1) called from file " << __FILE__ << " and line " << __LINE__ << std::endl; + // V must be the global z axis + if (fabs(V.dot(Z)) > eps) { + streamlog_out(ERROR) << "SiliconTracking_MarlinTrk: VXD Hit measurment vectors V is not in the global X-Y " + "plane. \n\n exit(1) called from file " + << __FILE__ << " and line " << __LINE__ << std::endl; exit(1); } - - if( fabs(U.dot(Z)) > eps ) { - streamlog_out(ERROR) << "SiliconTracking_MarlinTrk: VXD Hit measurment vectors U is not in the global X-Y plane. \n\n exit(1) called from file " << __FILE__ << " and line " << __LINE__ << std::endl; + + if (fabs(U.dot(Z)) > eps) { + streamlog_out(ERROR) << "SiliconTracking_MarlinTrk: VXD Hit measurment vectors U is not in the global X-Y " + "plane. \n\n exit(1) called from file " + << __FILE__ << " and line " << __LINE__ << std::endl; exit(1); } - - - + // SJA:FIXME Here dU and dV are almost certainly dX and dY ... should test ... - double point_res_rphi = sqrt( hit->getdU()*hit->getdU() + hit->getdV()*hit->getdV() ); - - hitExt->setResolutionRPhi( point_res_rphi ); - - // SJA:FIXME why is this needed? + double point_res_rphi = sqrt(hit->getdU() * hit->getdU() + hit->getdV() * hit->getdV()); + + hitExt->setResolutionRPhi(point_res_rphi); + + // SJA:FIXME why is this needed? hitExt->setResolutionZ(0.1); - - // type is now only used in one place where it is set to 0 to reject hits from a fit, set to INT_MAX to try and catch any missuse + + // type is now only used in one place where it is set to 0 to reject hits from a fit, set to INT_MAX to try and + // catch any missuse hitExt->setType(int(INT_MAX)); // det is no longer used set to INT_MAX to try and catch any missuse hitExt->setDet(int(INT_MAX)); - + double pos[3]; - - for (int i=0; i<3; ++i) { + + for (int i = 0; i < 3; ++i) { pos[i] = hit->getPosition()[i]; } - - double Phi = atan2(pos[1],pos[0]); - if (Phi < 0.) Phi = Phi + TWOPI; - + + double Phi = atan2(pos[1], pos[0]); + if (Phi < 0.) + Phi = Phi + TWOPI; + // get the layer number unsigned int layer = static_cast(getLayerID(hit)); unsigned int petalIndex = static_cast(getModuleID(hit)); - - if ( _petalBasedFTDWithOverlaps == true ) { - + + if (_petalBasedFTDWithOverlaps == true) { + // as we are dealing with staggered petals we will use 2*nlayers in each directions +/- z - // the layers will follow the even odd numbering of the petals - if ( petalIndex % 2 == 0 ) { - layer = 2*layer; - } - else { - layer = 2*layer + 1; + // the layers will follow the even odd numbering of the petals + if (petalIndex % 2 == 0) { + layer = 2 * layer; + } else { + layer = 2 * layer + 1; } - } - + if (layer >= _nlayersFTD) { - streamlog_out(ERROR) << "SiliconTracking_MarlinTrk => fatal error in FTD : layer is outside allowed range : " << layer << " number of layers = " << _nlayersFTD << std::endl; + streamlog_out(ERROR) << "SiliconTracking_MarlinTrk => fatal error in FTD : layer is outside allowed range : " + << layer << " number of layers = " << _nlayersFTD << std::endl; exit(1); } - - int iPhi = int(Phi/_dPhiFTD); - + + int iPhi = int(Phi / _dPhiFTD); + int side = getSideID(hit); int iSemiSphere = 0; - - if (side > 0) + + if (side > 0) iSemiSphere = 1; - - int iCode = iSemiSphere + 2*layer + 2*_nlayersFTD*iPhi; - _sectorsFTD[iCode].push_back( hitExt ); - - streamlog_out( DEBUG1 ) << " FTD Pixel Hit added : @ " << pos[0] << " " << pos[1] << " " << pos[2] << " drphi " << hitExt->getResolutionRPhi() << " dz " << hitExt->getResolutionZ() << " iPhi = " << iPhi << " iSemiSphere " << iSemiSphere << " iCode = " << iCode << " layer = " << layer << std::endl; - - + + int iCode = iSemiSphere + 2 * layer + 2 * _nlayersFTD * iPhi; + _sectorsFTD[iCode].push_back(hitExt); + + streamlog_out(DEBUG1) << " FTD Pixel Hit added : @ " << pos[0] << " " << pos[1] << " " << pos[2] << " drphi " + << hitExt->getResolutionRPhi() << " dz " << hitExt->getResolutionZ() << " iPhi = " << iPhi + << " iSemiSphere " << iSemiSphere << " iCode = " << iCode << " layer = " << layer + << std::endl; } - } - catch(DataNotAvailableException &e ) { + } catch (DataNotAvailableException& e) { success = 0; } - - + // Reading out FTD SpacePoint Collection //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ try { - - LCCollection * hitCollection = evt->getCollection(_FTDSpacePointCollection.c_str()); - + + LCCollection* hitCollection = evt->getCollection(_FTDSpacePointCollection.c_str()); + _colNamesTrackerHits[hitCollection] = _FTDSpacePointCollection; _colTrackerHits.push_back(hitCollection); - + int nelem = hitCollection->getNumberOfElements(); - + streamlog_out(DEBUG4) << "Number of FTD SpacePoints = " << nelem << std::endl; _nTotalFTDHits += nelem; - - for (int ielem=0; ielem(hitCollection->getElementAt(ielem)); - - TrackerHitExtended * hitExt = new TrackerHitExtended( hit ); - + + for (int ielem = 0; ielem < nelem; ++ielem) { + + TrackerHit* hit = dynamic_cast(hitCollection->getElementAt(ielem)); + + TrackerHitExtended* hitExt = new TrackerHitExtended(hit); + // SJA:FIXME: fudge for now by a factor of two and ignore covariance - double point_res_rphi = 2 * sqrt( hit->getCovMatrix()[0] + hit->getCovMatrix()[2] ); - - hitExt->setResolutionRPhi( point_res_rphi ); - - // SJA:FIXME why is this needed? + double point_res_rphi = 2 * sqrt(hit->getCovMatrix()[0] + hit->getCovMatrix()[2]); + + hitExt->setResolutionRPhi(point_res_rphi); + + // SJA:FIXME why is this needed? hitExt->setResolutionZ(0.1); - - // type is now only used in one place where it is set to 0 to reject hits from a fit, set to INT_MAX to try and catch any missuse + + // type is now only used in one place where it is set to 0 to reject hits from a fit, set to INT_MAX to try and + // catch any missuse hitExt->setType(int(INT_MAX)); // det is no longer used set to INT_MAX to try and catch any missuse hitExt->setDet(int(INT_MAX)); - + double pos[3]; - - for (int i=0; i<3; ++i) { + + for (int i = 0; i < 3; ++i) { pos[i] = hit->getPosition()[i]; } - - double Phi = atan2(pos[1],pos[0]); - if (Phi < 0.) Phi = Phi + TWOPI; - + + double Phi = atan2(pos[1], pos[0]); + if (Phi < 0.) + Phi = Phi + TWOPI; + // get the layer number unsigned int layer = static_cast(getLayerID(hit)); unsigned int petalIndex = static_cast(getModuleID(hit)); - - if ( _petalBasedFTDWithOverlaps == true ) { - + + if (_petalBasedFTDWithOverlaps == true) { + // as we are dealing with staggered petals we will use 2*nlayers in each directions +/- z - // the layers will follow the even odd numbering of the petals - if ( petalIndex % 2 == 0 ) { - layer = 2*layer; - } - else { - layer = 2*layer + 1; + // the layers will follow the even odd numbering of the petals + if (petalIndex % 2 == 0) { + layer = 2 * layer; + } else { + layer = 2 * layer + 1; } - } - + if (layer >= _nlayersFTD) { - streamlog_out(ERROR) << "SiliconTracking_MarlinTrk => fatal error in FTD : layer is outside allowed range : " << layer << " number of layers = " << _nlayersFTD << std::endl; + streamlog_out(ERROR) << "SiliconTracking_MarlinTrk => fatal error in FTD : layer is outside allowed range : " + << layer << " number of layers = " << _nlayersFTD << std::endl; exit(1); } - - int iPhi = int(Phi/_dPhiFTD); - + + int iPhi = int(Phi / _dPhiFTD); + int side = getSideID(hit); int iSemiSphere = 0; - - if (side > 0) + + if (side > 0) iSemiSphere = 1; - - int iCode = iSemiSphere + 2*layer + 2*_nlayersFTD*iPhi; - _sectorsFTD[iCode].push_back( hitExt ); - - streamlog_out( DEBUG1 ) << " FTD SpacePoint Hit added : @ " << pos[0] << " " << pos[1] << " " << pos[2] << " drphi " << hitExt->getResolutionRPhi() << " dz " << hitExt->getResolutionZ() << " iPhi = " << iPhi << " iSemiSphere " << iSemiSphere << " iCode = " << iCode << " layer = " << layer << std::endl; - + + int iCode = iSemiSphere + 2 * layer + 2 * _nlayersFTD * iPhi; + _sectorsFTD[iCode].push_back(hitExt); + + streamlog_out(DEBUG1) << " FTD SpacePoint Hit added : @ " << pos[0] << " " << pos[1] << " " << pos[2] << " drphi " + << hitExt->getResolutionRPhi() << " dz " << hitExt->getResolutionZ() << " iPhi = " << iPhi + << " iSemiSphere " << iSemiSphere << " iCode = " << iCode << " layer = " << layer + << std::endl; } - } - catch(DataNotAvailableException &e ) { + } catch (DataNotAvailableException& e) { success = 0; } - - for (unsigned i=0; i<_sectorsFTD.size(); ++i) { + + for (unsigned i = 0; i < _sectorsFTD.size(); ++i) { int nhits = _sectorsFTD[i].size(); - if( nhits != 0 ) streamlog_out(DEBUG1) << " Number of Hits in FTD Sector " << i << " = " << _sectorsFTD[i].size() << std::endl; + if (nhits != 0) + streamlog_out(DEBUG1) << " Number of Hits in FTD Sector " << i << " = " << _sectorsFTD[i].size() << std::endl; if (nhits > _max_hits_per_sector) { - for (unsigned ihit=0; ihit<_sectorsFTD[i].size(); ++ihit) { + for (unsigned ihit = 0; ihit < _sectorsFTD[i].size(); ++ihit) { delete _sectorsFTD[i][ihit]; - } + } _sectorsFTD[i].clear(); - if( nhits != 0 ) streamlog_out(ERROR) << " ### EVENT " << evt->getEventNumber() << " :: RUN " << evt->getRunNumber() << " \n ### Number of Hits in FTD Sector " << i << " = " << nhits << " : Limit is set to " << _max_hits_per_sector << " : This sector will be dropped from track search, and QualityCode set to \"Poor\" " << std::endl; + if (nhits != 0) + streamlog_out(ERROR) << " ### EVENT " << evt->getEventNumber() << " :: RUN " << evt->getRunNumber() + << " \n ### Number of Hits in FTD Sector " << i << " = " << nhits << " : Limit is set to " + << _max_hits_per_sector + << " : This sector will be dropped from track search, and QualityCode set to \"Poor\" " + << std::endl; _output_track_col_quality = _output_track_col_quality_POOR; - } - } - + return success; - } -int SiliconTracking_MarlinTrk::InitialiseVTX(LCEvent * evt) { - +int SiliconTracking_MarlinTrk::InitialiseVTX(LCEvent* evt) { + _nTotalVTXHits = 0; _nTotalSITHits = 0; _sectors.clear(); - _sectors.resize(_nLayers+_nLayers*_nDivisionsInPhi*_nDivisionsInTheta); - - + _sectors.resize(_nLayers + _nLayers * _nDivisionsInPhi * _nDivisionsInTheta); + // Reading out VTX Hits Collection - //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ try { - - LCCollection * hitCollection = evt->getCollection(_VTXHitCollection.c_str()); - + + LCCollection* hitCollection = evt->getCollection(_VTXHitCollection.c_str()); + _colNamesTrackerHits[hitCollection] = _VTXHitCollection; _colTrackerHits.push_back(hitCollection); - + int nelem = hitCollection->getNumberOfElements(); - + streamlog_out(DEBUG4) << "Number of VTX hits = " << nelem << std::endl; _nTotalVTXHits = nelem; - - for (int ielem=0; ielem(hitCollection->getElementAt(ielem)); - - Vector3D U(1.0,hit->getU()[1],hit->getU()[0],Vector3D::spherical); - Vector3D V(1.0,hit->getV()[1],hit->getV()[0],Vector3D::spherical); - Vector3D Z(0.0,0.0,1.0); - + + for (int ielem = 0; ielem < nelem; ++ielem) { + + TrackerHitPlane* hit = dynamic_cast(hitCollection->getElementAt(ielem)); + + Vector3D U(1.0, hit->getU()[1], hit->getU()[0], Vector3D::spherical); + Vector3D V(1.0, hit->getV()[1], hit->getV()[0], Vector3D::spherical); + Vector3D Z(0.0, 0.0, 1.0); + const float eps = 1.0e-07; - // V must be the global z axis - if( fabs(1.0 - V.dot(Z)) > eps ) { - streamlog_out(ERROR) << "SiliconTracking_MarlinTrk: VXD Hit measurment vectors V is not equal to the global Z axis. \n\n exit(1) called from file " << __FILE__ << " and line " << __LINE__ << std::endl; + // V must be the global z axis + if (fabs(1.0 - V.dot(Z)) > eps) { + streamlog_out(ERROR) << "SiliconTracking_MarlinTrk: VXD Hit measurment vectors V is not equal to the global Z " + "axis. \n\n exit(1) called from file " + << __FILE__ << " and line " << __LINE__ << std::endl; exit(1); } - - if( fabs(U.dot(Z)) > eps ) { - streamlog_out(ERROR) << "SiliconTracking_MarlinTrk: VXD Hit measurment vectors U is not in the global X-Y plane. \n\n exit(1) called from file " << __FILE__ << " and line " << __LINE__ << std::endl; + + if (fabs(U.dot(Z)) > eps) { + streamlog_out(ERROR) << "SiliconTracking_MarlinTrk: VXD Hit measurment vectors U is not in the global X-Y " + "plane. \n\n exit(1) called from file " + << __FILE__ << " and line " << __LINE__ << std::endl; exit(1); } - - - TrackerHitExtended * hitExt = new TrackerHitExtended( hit ); - - + + TrackerHitExtended* hitExt = new TrackerHitExtended(hit); + // SJA:FIXME: just use planar res for now hitExt->setResolutionRPhi(hit->getdU()); hitExt->setResolutionZ(hit->getdV()); - - // set type is now only used in one place where it is set to 0 to reject hits from a fit, set to INT_MAX to try and catch any missuse + + // set type is now only used in one place where it is set to 0 to reject hits from a fit, set to INT_MAX to try + // and catch any missuse hitExt->setType(int(INT_MAX)); // det is no longer used set to INT_MAX to try and catch any missuse hitExt->setDet(int(INT_MAX)); - + double pos[3]; double radius = 0; - - for (int i=0; i<3; ++i) { + + for (int i = 0; i < 3; ++i) { pos[i] = hit->getPosition()[i]; - radius += pos[i]*pos[i]; + radius += pos[i] * pos[i]; } - + radius = sqrt(radius); - - double cosTheta = pos[2]/radius; - double Phi = atan2(pos[1],pos[0]); - - if (Phi < 0.) Phi = Phi + TWOPI; - + + double cosTheta = pos[2] / radius; + double Phi = atan2(pos[1], pos[0]); + + if (Phi < 0.) + Phi = Phi + TWOPI; + // get the layer number int layer = getLayerID(hit); - + if (layer < 0 || layer >= _nLayers) { - streamlog_out(ERROR) << "SiliconTracking_MarlinTrk => fatal error in VTX : layer is outside allowed range : " << layer << std::endl; + streamlog_out(ERROR) << "SiliconTracking_MarlinTrk => fatal error in VTX : layer is outside allowed range : " + << layer << std::endl; exit(1); } - - int iPhi = int(Phi/_dPhi); - int iTheta = int ((cosTheta + double(1.0))/_dTheta); - int iCode = layer + _nLayers*iPhi + _nLayers*_nDivisionsInPhi*iTheta; - _sectors[iCode].push_back( hitExt ); - - streamlog_out( DEBUG1 ) << " VXD Hit " << hit->id() << " added : @ " << pos[0] << " " << pos[1] << " " << pos[2] << " drphi " << hitExt->getResolutionRPhi() << " dz " << hitExt->getResolutionZ() << " iPhi = " << iPhi << " iTheta " << iTheta << " iCode = " << iCode << " layer = " << layer << std::endl; - + + int iPhi = int(Phi / _dPhi); + int iTheta = int((cosTheta + double(1.0)) / _dTheta); + int iCode = layer + _nLayers * iPhi + _nLayers * _nDivisionsInPhi * iTheta; + _sectors[iCode].push_back(hitExt); + + streamlog_out(DEBUG1) << " VXD Hit " << hit->id() << " added : @ " << pos[0] << " " << pos[1] << " " << pos[2] + << " drphi " << hitExt->getResolutionRPhi() << " dz " << hitExt->getResolutionZ() + << " iPhi = " << iPhi << " iTheta " << iTheta << " iCode = " << iCode + << " layer = " << layer << std::endl; } + } catch (DataNotAvailableException& e) { + streamlog_out(DEBUG4) << " collection not found : " << _VTXHitCollection.c_str() << std::endl; } - catch(DataNotAvailableException &e) { - streamlog_out( DEBUG4 ) << " collection not found : " << _VTXHitCollection.c_str() << std::endl ; - } - - if (_useSIT > 0 ) { - - + + if (_useSIT > 0) { + try { - LCCollection *hitCollection = evt->getCollection(_SITHitCollection.c_str()); - + LCCollection* hitCollection = evt->getCollection(_SITHitCollection.c_str()); + _colNamesTrackerHits[hitCollection] = _SITHitCollection; _colTrackerHits.push_back(hitCollection); - + int nelem = hitCollection->getNumberOfElements(); - + streamlog_out(DEBUG4) << "Number of SIT hits = " << nelem << std::endl; _nTotalSITHits = nelem; - - TrackerHit* trkhit = 0; - TrackerHitPlane* trkhit_P = 0; + + TrackerHit* trkhit = 0; + TrackerHitPlane* trkhit_P = 0; TrackerHitZCylinder* trkhit_C = 0; - + double drphi(NAN); double dz(NAN); - - for (int ielem=0; ielem(hitCollection->getElementAt(ielem)); - + int layer = getLayerID(trkhit); - + // VXD and SIT are treated as one system so SIT layers start from _nLayersVTX layer = layer + _nLayersVTX; - + if (layer < 0 || layer >= _nLayers) { - streamlog_out(ERROR) << "SiliconTracking_MarlinTrk => fatal error in SIT : layer is outside allowed range : " << layer << std::endl; + streamlog_out(ERROR) << "SiliconTracking_MarlinTrk => fatal error in SIT : layer is outside allowed range : " + << layer << std::endl; exit(1); } - + // first check that we have not been given 1D hits by mistake, as they won't work here - if ( BitSet32( trkhit->getType() )[ UTIL::ILDTrkHitTypeBit::ONE_DIMENSIONAL ] ) { - - streamlog_out(ERROR) << "SiliconTracking_MarlinTrk: SIT Hit cannot be of type UTIL::ILDTrkHitTypeBit::ONE_DIMENSIONAL COMPOSITE SPACEPOINTS must be use instead. \n\n exit(1) called from file " << __FILE__ << " and line " << __LINE__ << std::endl; + if (BitSet32(trkhit->getType())[UTIL::ILDTrkHitTypeBit::ONE_DIMENSIONAL]) { + + streamlog_out(ERROR) + << "SiliconTracking_MarlinTrk: SIT Hit cannot be of type UTIL::ILDTrkHitTypeBit::ONE_DIMENSIONAL " + "COMPOSITE SPACEPOINTS must be use instead. \n\n exit(1) called from file " + << __FILE__ << " and line " << __LINE__ << std::endl; exit(1); - - } + + } // most likely case: COMPOSITE_SPACEPOINT hits formed from stereo strip hits - else if ( BitSet32( trkhit->getType() )[ UTIL::ILDTrkHitTypeBit::COMPOSITE_SPACEPOINT ] ) { - + else if (BitSet32(trkhit->getType())[UTIL::ILDTrkHitTypeBit::COMPOSITE_SPACEPOINT]) { + // SJA:FIXME: fudge for now by a factor of two and ignore covariance - drphi = 2 * sqrt(trkhit->getCovMatrix()[0] + trkhit->getCovMatrix()[2]); - dz = sqrt(trkhit->getCovMatrix()[5]); - - } + drphi = 2 * sqrt(trkhit->getCovMatrix()[0] + trkhit->getCovMatrix()[2]); + dz = sqrt(trkhit->getCovMatrix()[5]); + + } // or a PIXEL based SIT, using 2D TrackerHitPlane like the VXD above - else if ( ( trkhit_P = dynamic_cast( hitCollection->getElementAt( ielem ) ) ) ) { - - // first we need to check if the measurement vectors are aligned with the global coordinates - Vector3D U(1.0,trkhit_P->getU()[1],trkhit_P->getU()[0],Vector3D::spherical); - Vector3D V(1.0,trkhit_P->getV()[1],trkhit_P->getV()[0],Vector3D::spherical); - Vector3D Z(0.0,0.0,1.0); - + else if ((trkhit_P = dynamic_cast(hitCollection->getElementAt(ielem)))) { + + // first we need to check if the measurement vectors are aligned with the global coordinates + Vector3D U(1.0, trkhit_P->getU()[1], trkhit_P->getU()[0], Vector3D::spherical); + Vector3D V(1.0, trkhit_P->getV()[1], trkhit_P->getV()[0], Vector3D::spherical); + Vector3D Z(0.0, 0.0, 1.0); + const float eps = 1.0e-07; - // V must be the global z axis - if( fabs(1.0 - V.dot(Z)) > eps ) { - streamlog_out(ERROR) << "SiliconTracking_MarlinTrk: PIXEL SIT Hit measurment vectors V is not equal to the global Z axis. \n\n exit(1) called from file " << __FILE__ << " and line " << __LINE__ << std::endl; + // V must be the global z axis + if (fabs(1.0 - V.dot(Z)) > eps) { + streamlog_out(ERROR) << "SiliconTracking_MarlinTrk: PIXEL SIT Hit measurment vectors V is not equal to the " + "global Z axis. \n\n exit(1) called from file " + << __FILE__ << " and line " << __LINE__ << std::endl; exit(1); } - + // U must be normal to the global z axis - if( fabs(U.dot(Z)) > eps ) { - streamlog_out(ERROR) << "SiliconTracking_MarlinTrk: PIXEL SIT Hit measurment vectors U is not in the global X-Y plane. \n\n exit(1) called from file " << __FILE__ << " and line " << __LINE__ << std::endl; + if (fabs(U.dot(Z)) > eps) { + streamlog_out(ERROR) << "SiliconTracking_MarlinTrk: PIXEL SIT Hit measurment vectors U is not in the " + "global X-Y plane. \n\n exit(1) called from file " + << __FILE__ << " and line " << __LINE__ << std::endl; exit(1); } - + drphi = trkhit_P->getdU(); - dz = trkhit_P->getdV(); - - } - // or a simple cylindrical design, as used in the LOI - else if ( ( trkhit_C = dynamic_cast( hitCollection->getElementAt( ielem ) ) ) ) { - + dz = trkhit_P->getdV(); + + } + // or a simple cylindrical design, as used in the LOI + else if ((trkhit_C = dynamic_cast(hitCollection->getElementAt(ielem)))) { + drphi = trkhit_C->getdRPhi(); - dz = trkhit_C->getdZ(); - - } - // this would be very unlikely, but who knows ... just an ordinary TrackerHit, which is not a COMPOSITE_SPACEPOINT + dz = trkhit_C->getdZ(); + + } + // this would be very unlikely, but who knows ... just an ordinary TrackerHit, which is not a + // COMPOSITE_SPACEPOINT else { - + // SJA:FIXME: fudge for now by a factor of two and ignore covariance - drphi = 2 * sqrt(trkhit->getCovMatrix()[0] + trkhit->getCovMatrix()[2]); - dz = sqrt(trkhit->getCovMatrix()[5]); - + drphi = 2 * sqrt(trkhit->getCovMatrix()[0] + trkhit->getCovMatrix()[2]); + dz = sqrt(trkhit->getCovMatrix()[5]); } - - // now that the hit type has been established carry on and create a - - TrackerHitExtended * hitExt = new TrackerHitExtended( trkhit ); - + + // now that the hit type has been established carry on and create a + + TrackerHitExtended* hitExt = new TrackerHitExtended(trkhit); + // SJA:FIXME: just use planar res for now hitExt->setResolutionRPhi(drphi); hitExt->setResolutionZ(dz); - - // set type is now only used in one place where it is set to 0 to reject hits from a fit, set to INT_MAX to try and catch any missuse + + // set type is now only used in one place where it is set to 0 to reject hits from a fit, set to INT_MAX to try + // and catch any missuse hitExt->setType(int(INT_MAX)); // det is no longer used set to INT_MAX to try and catch any missuse hitExt->setDet(int(INT_MAX)); - + double pos[3]; double radius = 0; - - for (int i=0; i<3; ++i) { + + for (int i = 0; i < 3; ++i) { pos[i] = trkhit->getPosition()[i]; - radius += pos[i]*pos[i]; + radius += pos[i] * pos[i]; } - + radius = sqrt(radius); - - double cosTheta = pos[2]/radius; - double Phi = atan2(pos[1],pos[0]); - - if (Phi < 0.) Phi = Phi + TWOPI; - - int iPhi = int(Phi/_dPhi); - int iTheta = int ((cosTheta + double(1.0))/_dTheta); - int iCode = layer + _nLayers*iPhi + _nLayers*_nDivisionsInPhi*iTheta; - _sectors[iCode].push_back( hitExt ); - - streamlog_out( DEBUG1 ) << " SIT Hit " << trkhit->id() << " added : @ " << pos[0] << " " << pos[1] << " " << pos[2] << " drphi " << hitExt->getResolutionRPhi() << " dz " << hitExt->getResolutionZ() << " iPhi = " << iPhi << " iTheta " << iTheta << " iCode = " << iCode << " layer = " << layer << std::endl; - + + double cosTheta = pos[2] / radius; + double Phi = atan2(pos[1], pos[0]); + + if (Phi < 0.) + Phi = Phi + TWOPI; + + int iPhi = int(Phi / _dPhi); + int iTheta = int((cosTheta + double(1.0)) / _dTheta); + int iCode = layer + _nLayers * iPhi + _nLayers * _nDivisionsInPhi * iTheta; + _sectors[iCode].push_back(hitExt); + + streamlog_out(DEBUG1) << " SIT Hit " << trkhit->id() << " added : @ " << pos[0] << " " << pos[1] << " " + << pos[2] << " drphi " << hitExt->getResolutionRPhi() << " dz " + << hitExt->getResolutionZ() << " iPhi = " << iPhi << " iTheta " << iTheta + << " iCode = " << iCode << " layer = " << layer << std::endl; } - - } catch(DataNotAvailableException &e) { - streamlog_out( DEBUG4 ) << " collection not found : " << _SITHitCollection.c_str() << std::endl ; + + } catch (DataNotAvailableException& e) { + streamlog_out(DEBUG4) << " collection not found : " << _SITHitCollection.c_str() << std::endl; } - } - - - for (unsigned i=0; i<_sectors.size(); ++i) { + + for (unsigned i = 0; i < _sectors.size(); ++i) { int nhits = _sectors[i].size(); - if( nhits != 0 ) streamlog_out(DEBUG1) << " Number of Hits in VXD/SIT Sector " << i << " = " << _sectors[i].size() << std::endl; + if (nhits != 0) + streamlog_out(DEBUG1) << " Number of Hits in VXD/SIT Sector " << i << " = " << _sectors[i].size() << std::endl; if (nhits > _max_hits_per_sector) { - for (unsigned ihit=0; ihit<_sectors[i].size(); ++ihit) { + for (unsigned ihit = 0; ihit < _sectors[i].size(); ++ihit) { delete _sectors[i][ihit]; } _sectors[i].clear(); - if( nhits != 0 ) streamlog_out(ERROR) << " ### EVENT " << evt->getEventNumber() << " :: RUN " << evt->getRunNumber() << " \n ### Number of Hits in VXD/SIT Sector " << i << " = " << nhits << " : Limit is set to " << _max_hits_per_sector << " : This sector will be dropped from track search, and QualityCode set to \"Poor\" " << std::endl; - + if (nhits != 0) + streamlog_out(ERROR) << " ### EVENT " << evt->getEventNumber() << " :: RUN " << evt->getRunNumber() + << " \n ### Number of Hits in VXD/SIT Sector " << i << " = " << nhits + << " : Limit is set to " << _max_hits_per_sector + << " : This sector will be dropped from track search, and QualityCode set to \"Poor\" " + << std::endl; + _output_track_col_quality = _output_track_col_quality_POOR; - } - } - - return 1; // success - -} -void SiliconTracking_MarlinTrk::check( LCEvent* ) { - + return 1; // success } +void SiliconTracking_MarlinTrk::check(LCEvent*) {} + void SiliconTracking_MarlinTrk::end() { - - delete _fastfitter ; _fastfitter = 0; - delete _encoder ; _encoder = 0; + + delete _fastfitter; + _fastfitter = 0; + delete _encoder; + _encoder = 0; // delete _trksystem ; _trksystem = 0; - delete _histos ; _histos = 0; - + delete _histos; + _histos = 0; } - void SiliconTracking_MarlinTrk::ProcessOneSector(int iPhi, int iTheta) { - - int counter = 0 ; - - int iPhi_Up = iPhi + 1; - int iPhi_Low = iPhi - 1; - int iTheta_Up = iTheta + 1; + + int counter = 0; + + int iPhi_Up = iPhi + 1; + int iPhi_Low = iPhi - 1; + int iTheta_Up = iTheta + 1; int iTheta_Low = iTheta - 1; - if (iTheta_Low < 0) iTheta_Low = 0; - if (iTheta_Up >= _nDivisionsInTheta) iTheta_Up = _nDivisionsInTheta-1; - - int nComb = int( _Combinations.size() / 3 ); // number of triplet combinations - // std::cout << iPhi << " " << iTheta << " " << _nEvt << std::endl; + if (iTheta_Low < 0) + iTheta_Low = 0; + if (iTheta_Up >= _nDivisionsInTheta) + iTheta_Up = _nDivisionsInTheta - 1; + + int nComb = int(_Combinations.size() / 3); // number of triplet combinations + // std::cout << iPhi << " " << iTheta << " " << _nEvt << std::endl; int iNC = 0; - - for (int iComb=0; iComb < nComb; ++iComb) { // loop over triplets - + + for (int iComb = 0; iComb < nComb; ++iComb) { // loop over triplets + int nLR[3]; - - for (int iS=0; iS<3; ++iS) { + + for (int iS = 0; iS < 3; ++iS) { nLR[iS] = _Combinations[iNC]; iNC++; - } - + } + // std::cout << iPhi << " " << iTheta << " " << nLR[0] << " " << nLR[1] << " " << nLR[2] << " " << std::endl; - + // index of theta-phi bin of outer most layer - int iCode = nLR[0] + _nLayers*iPhi + _nLayers*_nDivisionsInPhi*iTheta; - + int iCode = nLR[0] + _nLayers * iPhi + _nLayers * _nDivisionsInPhi * iTheta; + // std::cout << "size of vector = " << _sectors.size() << " iCode = " << iCode << std::endl; - - // get the all the hits in the outer most theta-phi bin - - TrackerHitExtendedVec& hitVecOuter = _sectors.at( iCode ) ; - + + // get the all the hits in the outer most theta-phi bin + + TrackerHitExtendedVec& hitVecOuter = _sectors.at(iCode); + int nHitsOuter = int(hitVecOuter.size()); if (nHitsOuter > 0) { - - // std::cout << " " << iPhi << " " << iTheta << " " << nLR[0] << " " << nLR[1] << " " << nLR[2] << " size of vector = " << hitVecOuter.size() << std::endl; - - for (int ipMiddle=iPhi_Low; ipMiddle 0 - } // endloop over theta in the Inner - } // endloop over phi in the Inner - } // endif nHitsMiddle > 0 - } // endloop over theta in the Middle - } // endloop over phi in the Middle - } // endif nHitsOuter > 0 + } // endloop over hits in the middle sector + } // endloop over hits in the outer sector + } // endif nHitsInner > 0 + } // endloop over theta in the Inner + } // endloop over phi in the Inner + } // endif nHitsMiddle > 0 + } // endloop over theta in the Middle + } // endloop over phi in the Middle + } // endif nHitsOuter > 0 } // endloop over triplets - - + // streamlog_out( DEBUG2 ) << " process one sectector theta,phi " << iTheta << ", " << iPhi << // " number of loops : " << counter << std::endl ; } -TrackExtended * SiliconTracking_MarlinTrk::TestTriplet(TrackerHitExtended * outerHit, - TrackerHitExtended * middleHit, - TrackerHitExtended * innerHit, - HelixClass & helix) { +TrackExtended* SiliconTracking_MarlinTrk::TestTriplet(TrackerHitExtended* outerHit, TrackerHitExtended* middleHit, + TrackerHitExtended* innerHit, HelixClass& helix) { /* Methods checks if the triplet of hits satisfies helix hypothesis */ - - - - + // get the tracks already associated with the triplet - TrackExtendedVec& trackOuterVec = outerHit->getTrackExtendedVec(); + TrackExtendedVec& trackOuterVec = outerHit->getTrackExtendedVec(); TrackExtendedVec& trackMiddleVec = middleHit->getTrackExtendedVec(); - TrackExtendedVec& trackInnerVec = innerHit->getTrackExtendedVec(); - - - // check if all the hits are already assigned to a track - if ( (!trackOuterVec.empty()) && (!trackMiddleVec.empty()) && (!trackInnerVec.empty())) { - + TrackExtendedVec& trackInnerVec = innerHit->getTrackExtendedVec(); + + // check if all the hits are already assigned to a track + if ((!trackOuterVec.empty()) && (!trackMiddleVec.empty()) && (!trackInnerVec.empty())) { + TrackExtendedVec::const_iterator middleEndIter = trackMiddleVec.end(); - TrackExtendedVec::const_iterator outerEndIter = trackOuterVec.end(); - TrackExtendedVec::const_iterator innerEndIter = trackInnerVec.end(); - TrackExtendedVec::const_iterator outerBeginIter = trackOuterVec.begin(); - TrackExtendedVec::const_iterator innerBeginIter = trackInnerVec.begin(); - + TrackExtendedVec::const_iterator outerEndIter = trackOuterVec.end(); + TrackExtendedVec::const_iterator innerEndIter = trackInnerVec.end(); + TrackExtendedVec::const_iterator outerBeginIter = trackOuterVec.begin(); + TrackExtendedVec::const_iterator innerBeginIter = trackInnerVec.begin(); + // loop over the tracks from the middle hit - for (TrackExtendedVec::const_iterator middleIter = trackMiddleVec.begin(); - middleIter < middleEndIter; + for (TrackExtendedVec::const_iterator middleIter = trackMiddleVec.begin(); middleIter < middleEndIter; ++middleIter) { - + // loop over the track from the outer hit - for (TrackExtendedVec::const_iterator outerIter = outerBeginIter; - outerIter < outerEndIter; - ++outerIter) { - - // if track from the outer and middle are not the same progress - if ( *outerIter != *middleIter ) continue; - + for (TrackExtendedVec::const_iterator outerIter = outerBeginIter; outerIter < outerEndIter; ++outerIter) { + + // if track from the outer and middle are not the same progress + if (*outerIter != *middleIter) + continue; + // loop over the tracks from the inner hit - for (TrackExtendedVec::const_iterator innerIter = innerBeginIter; - innerIter < innerEndIter; - ++innerIter) { - + for (TrackExtendedVec::const_iterator innerIter = innerBeginIter; innerIter < innerEndIter; ++innerIter) { + // no need to check against middle, it is idendical to outer here - if ( *outerIter == *innerIter ) { + if (*outerIter == *innerIter) { // an existing track already contains all three hits // return a null pointer - streamlog_out( DEBUG2 ) << " TestTriplet: track " << *outerIter << " already contains all three hits: Do not create new track from these hits " << std::endl ; - return 0; + streamlog_out(DEBUG2) << " TestTriplet: track " << *outerIter + << " already contains all three hits: Do not create new track from these hits " + << std::endl; + return 0; } - - }// for inner - }// for outer - }// for middle - }// if all vectors are not empty - - + + } // for inner + } // for outer + } // for middle + } // if all vectors are not empty + // float dZ = FastTripletCheck(innerHit, middleHit, outerHit); - + // if (fabs(dZ) > _minDistCutAttach) - // return trackAR; + // return trackAR; - // increase triplet count ++_ntriplets; // get the hit coordinates and errors double xh[3]; double yh[3]; - float zh[3]; + float zh[3]; double wrh[3]; - float wzh[3]; - float rh[3]; - float ph[3]; - + float wzh[3]; + float rh[3]; + float ph[3]; + float par[5]; float epar[15]; - + // first hit xh[0] = outerHit->getTrackerHit()->getPosition()[0]; yh[0] = outerHit->getTrackerHit()->getPosition()[1]; zh[0] = float(outerHit->getTrackerHit()->getPosition()[2]); - wrh[0] = double(1.0/(outerHit->getResolutionRPhi()*outerHit->getResolutionRPhi())); - wzh[0] = 1.0/(outerHit->getResolutionZ()*outerHit->getResolutionZ()); - + wrh[0] = double(1.0 / (outerHit->getResolutionRPhi() * outerHit->getResolutionRPhi())); + wzh[0] = 1.0 / (outerHit->getResolutionZ() * outerHit->getResolutionZ()); + // second hit xh[1] = middleHit->getTrackerHit()->getPosition()[0]; yh[1] = middleHit->getTrackerHit()->getPosition()[1]; zh[1] = float(middleHit->getTrackerHit()->getPosition()[2]); - wrh[1] = double(1.0/(middleHit->getResolutionRPhi()*middleHit->getResolutionRPhi())); - wzh[1] = 1.0/(middleHit->getResolutionZ()*middleHit->getResolutionZ()); - + wrh[1] = double(1.0 / (middleHit->getResolutionRPhi() * middleHit->getResolutionRPhi())); + wzh[1] = 1.0 / (middleHit->getResolutionZ() * middleHit->getResolutionZ()); + // third hit xh[2] = innerHit->getTrackerHit()->getPosition()[0]; yh[2] = innerHit->getTrackerHit()->getPosition()[1]; zh[2] = float(innerHit->getTrackerHit()->getPosition()[2]); - wrh[2] = double(1.0/(innerHit->getResolutionRPhi()*innerHit->getResolutionRPhi())); - wzh[2] = 1.0/(innerHit->getResolutionZ()*innerHit->getResolutionZ()); + wrh[2] = double(1.0 / (innerHit->getResolutionRPhi() * innerHit->getResolutionRPhi())); + wzh[2] = 1.0 / (innerHit->getResolutionZ() * innerHit->getResolutionZ()); // calculate r and phi for all hits - for (int ih=0; ih<3; ih++) { - rh[ih] = float(sqrt(xh[ih]*xh[ih]+yh[ih]*yh[ih])); - ph[ih] = atan2(yh[ih],xh[ih]); - if (ph[ih] < 0.) - ph[ih] = TWOPI + ph[ih]; + for (int ih = 0; ih < 3; ih++) { + rh[ih] = float(sqrt(xh[ih] * xh[ih] + yh[ih] * yh[ih])); + ph[ih] = atan2(yh[ih], xh[ih]); + if (ph[ih] < 0.) + ph[ih] = TWOPI + ph[ih]; } - + int NPT = 3; int iopt = 2; float chi2RPhi; float chi2Z; - - streamlog_out( DEBUG2 ) << " TestTriplet: Use fastHelixFit " << std::endl ; - - _fastfitter->fastHelixFit(NPT, xh, yh, rh, ph, wrh, zh, wzh,iopt, par, epar, chi2RPhi, chi2Z); - par[3] = par[3]*par[0]/fabs(par[0]); + + streamlog_out(DEBUG2) << " TestTriplet: Use fastHelixFit " << std::endl; + + _fastfitter->fastHelixFit(NPT, xh, yh, rh, ph, wrh, zh, wzh, iopt, par, epar, chi2RPhi, chi2Z); + par[3] = par[3] * par[0] / fabs(par[0]); // get helix parameters float omega = par[0]; @@ -1693,33 +1567,32 @@ TrackExtended * SiliconTracking_MarlinTrk::TestTriplet(TrackerHitExtended * oute float z0 = par[4]; // chi2 is weighted here by a factor for both rphi and z - float Chi2 = chi2RPhi*_chi2WRPhiTriplet+chi2Z*_chi2WZTriplet; - int ndf = 2*NPT-5; + float Chi2 = chi2RPhi * _chi2WRPhiTriplet + chi2Z * _chi2WZTriplet; + int ndf = 2 * NPT - 5; - // check the truth information for the triplet - + // define these outside of the ifdef so that we don't need to keep repeating it. std::vector hit_list; std::vector mcps_imo; std::vector mcp_s; int triplet_code = 0; - + #ifdef MARLINTRK_DIAGNOSTICS_ON - int nmcps = 0; + int nmcps = 0; int nbadHits = 0; - - int layer = 9 ; - int size = 3 ; - int marker = 1 ; - int ml = 0 ; + + int layer = 9; + int size = 3; + int marker = 1; + int ml = 0; // float helix_max_r = 0; float helix_max_z = 0; int color = 0; // use the MCTruth4HitExt to get the MCPs - + hit_list.push_back(innerHit->getTrackerHit()); hit_list.push_back(middleHit->getTrackerHit()); hit_list.push_back(outerHit->getTrackerHit()); @@ -1727,14 +1600,14 @@ TrackExtended * SiliconTracking_MarlinTrk::TestTriplet(TrackerHitExtended * oute EVENT::MCParticle* mcp_i = 0; EVENT::MCParticle* mcp_m = 0; EVENT::MCParticle* mcp_o = 0; - + for (unsigned ihit = 0; ihit < hit_list.size(); ++ihit) { EVENT::TrackerHit* trkhit = hit_list[ihit]; std::vector mcps; MarlinTrk::getMCParticlesForTrackerHit(trkhit, mcps); - + if (mcps.size() == 1) { mcps_imo.push_back(mcps[0]); ++nmcps; @@ -1742,107 +1615,94 @@ TrackExtended * SiliconTracking_MarlinTrk::TestTriplet(TrackerHitExtended * oute mcps_imo.push_back(0); ++nbadHits; } - } - + mcp_i = mcps_imo[0]; mcp_m = mcps_imo[1]; mcp_o = mcps_imo[2]; - - streamlog_out(DEBUG2) - << "\n mcp_i = " << mcp_i - << "\n mcp_m = " << mcp_m - << "\n mcp_o = " << mcp_o - << std::endl; - - if( mcp_i ) { - mcp_s.push_back(mcp_i) ; + + streamlog_out(DEBUG2) << "\n mcp_i = " << mcp_i << "\n mcp_m = " << mcp_m << "\n mcp_o = " << mcp_o << std::endl; + + if (mcp_i) { + mcp_s.push_back(mcp_i); } - - if( mcp_m && mcp_m != mcp_i ) { + + if (mcp_m && mcp_m != mcp_i) { mcp_s.push_back(mcp_m); } - - if( mcp_o && mcp_o != mcp_m && mcp_o != mcp_i ){ + + if (mcp_o && mcp_o != mcp_m && mcp_o != mcp_i) { mcp_s.push_back(mcp_o); } nmcps = mcp_s.size(); - if (_UseEventDisplay) { // display this triplet and the MCPs from which it is formed - - MarlinCED::newEvent(this , _detector_model_for_drawing ) ; - + + MarlinCED::newEvent(this, _detector_model_for_drawing); + // CEDPickingHandler &pHandler=CEDPickingHandler::getInstance(); // // pHandler.update(_current_event); - + for (unsigned imcp = 0; imcp < mcp_s.size(); ++imcp) { - + MCParticle* mcp = mcp_s[imcp]; - + helix_max_z = fabs(mcp->getEndpoint()[2]); - - - streamlog_out(MESSAGE) << "Draw MCParticle : " << *mcp <getCharge(), mcp->getVertex()[0], mcp->getVertex()[1], mcp->getVertex()[2], - mcp->getMomentum()[0], mcp->getMomentum()[1], mcp->getMomentum()[2], layer , size , 0x7af774 , - 0.0, _helix_max_r , - helix_max_z, mcp->id() ) ; - + + MarlinCED::drawHelix(_bField, mcp->getCharge(), mcp->getVertex()[0], mcp->getVertex()[1], mcp->getVertex()[2], + mcp->getMomentum()[0], mcp->getMomentum()[1], mcp->getMomentum()[2], layer, size, 0x7af774, + 0.0, _helix_max_r, helix_max_z, mcp->id()); } - - const std::string colName = "Hits_For_Fit"; - - - size = 10 ; - layer = 11 ; + + const std::string colName = "Hits_For_Fit"; + + size = 10; + layer = 11; // ml = marker | ( layer << CED_LAYER_SHIFT ) ; - - //ced_describe_layer( colName.c_str() ,layer); + + // ced_describe_layer( colName.c_str() ,layer); MarlinCED::add_layer_description(colName, layer); - - - color = 0xFFFFFF; - - for( std::vector::const_iterator it = hit_list.begin(); it != hit_list.end() ; it++ ) { - + + color = 0xFFFFFF; + + for (std::vector::const_iterator it = hit_list.begin(); it != hit_list.end(); it++) { + TrackerHit* trkhit = *it; - - ced_hit_ID(trkhit->getPosition()[0], - trkhit->getPosition()[1], - trkhit->getPosition()[2], - marker, layer, size , color, trkhit->id() ) ; - + + ced_hit_ID(trkhit->getPosition()[0], trkhit->getPosition()[1], trkhit->getPosition()[2], marker, layer, size, + color, trkhit->id()); + } // hits } - + if (_createDiagnosticsHistograms) { - + // if no bad hits are present triplet_code = nmcps; - triplet_code = nmcps + nbadHits * 3 ; - + triplet_code = nmcps + nbadHits * 3; + _histos->fill1D(DiagnosticsHistograms::htriplets, triplet_code); - - double pt = (2.99792458E-4*_bField) / omega ; // for r in mm, p in GeV and Bz in Tesla - + + double pt = (2.99792458E-4 * _bField) / omega; // for r in mm, p in GeV and Bz in Tesla + if (triplet_code == 1) { ++_ntriplets_good; - _histos->fill2D(DiagnosticsHistograms::htripletChi2vPt_good, pt, Chi2 ); - _histos->fill1D(DiagnosticsHistograms::htriplets_chi2_good, Chi2 ); - _histos->fill1D(DiagnosticsHistograms::htriplets_pt_good, pt ); + _histos->fill2D(DiagnosticsHistograms::htripletChi2vPt_good, pt, Chi2); + _histos->fill1D(DiagnosticsHistograms::htriplets_chi2_good, Chi2); + _histos->fill1D(DiagnosticsHistograms::htriplets_pt_good, pt); } else { _histos->fill2D(DiagnosticsHistograms::htripletChi2vPt_bad, pt, Chi2); - _histos->fill1D(DiagnosticsHistograms::htriplets_chi2_bad, Chi2 ); - _histos->fill1D(DiagnosticsHistograms::htriplets_pt_bad, pt ); + _histos->fill1D(DiagnosticsHistograms::htriplets_chi2_bad, Chi2); + _histos->fill1D(DiagnosticsHistograms::htriplets_pt_bad, pt); - if(triplet_code == 2) { + if (triplet_code == 2) { ++_ntriplets_2MCP; } else if (triplet_code == 3) { ++_ntriplets_3MCP; @@ -1853,209 +1713,200 @@ TrackExtended * SiliconTracking_MarlinTrk::TestTriplet(TrackerHitExtended * oute } } } - + #endif - - + // Check if track satisfies all conditions - - + // std::cout << "Chi2/ndf = " << Chi2/float(ndf) << " , cut = " << _chi2FitCut << std::endl; // std::cout << "d0 = " << d0 << " , cut = " << _cutOnD0 << std::endl; // std::cout << "z0 = " << z0 << " , cut = " << _cutOnZ0 << std::endl; // std::cout << "omega = " << omega << " , cut = " << _cutOnOmega << std::endl; - + // if ( Chi2/float(ndf) > _chi2FitCut || fabs(d0) > _cutOnD0 || fabs(z0) > _cutOnZ0 || fabs(omega)>_cutOnOmega) // return a null pointer // return 0; - + bool failed = false; - int quality_code = triplet_code * 10 ; + int quality_code = triplet_code * 10; - if ( Chi2/float(ndf) > _chi2FitCut ) { - streamlog_out(DEBUG1) << "Chi2/ndf = " << Chi2/float(ndf) << " , cut = " << _chi2FitCut << std::endl; + if (Chi2 / float(ndf) > _chi2FitCut) { + streamlog_out(DEBUG1) << "Chi2/ndf = " << Chi2 / float(ndf) << " , cut = " << _chi2FitCut << std::endl; failed = true; quality_code += 1; - } else if (fabs(d0) > _cutOnD0 ) { - streamlog_out(DEBUG1) << "d0 = " << d0 << " , cut = " << _cutOnD0 << std::endl; + } else if (fabs(d0) > _cutOnD0) { + streamlog_out(DEBUG1) << "d0 = " << d0 << " , cut = " << _cutOnD0 << std::endl; failed = true; quality_code += 2; - } else if (fabs(z0) > _cutOnZ0 ) { - streamlog_out(DEBUG1) << "z0 = " << z0 << " , cut = " << _cutOnZ0 << std::endl; + } else if (fabs(z0) > _cutOnZ0) { + streamlog_out(DEBUG1) << "z0 = " << z0 << " , cut = " << _cutOnZ0 << std::endl; failed = true; quality_code += 3; - } else if ( fabs(omega)>_cutOnOmega) { + } else if (fabs(omega) > _cutOnOmega) { streamlog_out(DEBUG1) << "omega = " << omega << " , cut = " << _cutOnOmega << std::endl; failed = true; quality_code += 4; } else { streamlog_out(DEBUG1) << "Success !!!!!!!" << std::endl; } - - if (_createDiagnosticsHistograms) _histos->fill1D(DiagnosticsHistograms::htriplets, quality_code); - + if (_createDiagnosticsHistograms) + _histos->fill1D(DiagnosticsHistograms::htriplets, quality_code); + if (_UseEventDisplay) { drawEvent(); } - - - if( failed ) { + + if (failed) { // return a null pointer return 0; } - - - helix.Initialize_Canonical(phi0,d0,z0,omega,tanlambda,_bField); - - TrackExtended * trackAR = new TrackExtended(); + + helix.Initialize_Canonical(phi0, d0, z0, omega, tanlambda, _bField); + + TrackExtended* trackAR = new TrackExtended(); trackAR->addTrackerHitExtended(outerHit); trackAR->addTrackerHitExtended(middleHit); trackAR->addTrackerHitExtended(innerHit); outerHit->addTrackExtended(trackAR); middleHit->addTrackExtended(trackAR); - innerHit->addTrackExtended(trackAR); + innerHit->addTrackExtended(trackAR); trackAR->setD0(d0); trackAR->setZ0(z0); trackAR->setPhi(phi0); trackAR->setTanLambda(tanlambda); trackAR->setOmega(omega); - trackAR->setChi2( Chi2 ); - trackAR->setNDF( ndf ); + trackAR->setChi2(Chi2); + trackAR->setNDF(ndf); trackAR->setCovMatrix(epar); - - + return trackAR; - } -int SiliconTracking_MarlinTrk::BuildTrack(TrackerHitExtended * /*outerHit*/, - TrackerHitExtended * /*middleHit*/, - TrackerHitExtended * /*innerHit*/, - HelixClass & helix, - int innerLayer, - int iPhiLow, int iPhiUp, - int iThetaLow, int iThetaUp, - TrackExtended * trackAR) { +int SiliconTracking_MarlinTrk::BuildTrack(TrackerHitExtended* /*outerHit*/, TrackerHitExtended* /*middleHit*/, + TrackerHitExtended* /*innerHit*/, HelixClass& helix, int innerLayer, + int iPhiLow, int iPhiUp, int iThetaLow, int iThetaUp, + TrackExtended* trackAR) { /** Method for building up track in the VXD. Method starts from the found triplet and performs sequential attachment of hits in other layers, which have hits within the search window. Only searches inwards. - Given that we know we are now jumping over layers due to the doublet nature of the VXD, we - could optimise this to look for the hits in interleaving layers as well. + Given that we know we are now jumping over layers due to the doublet nature of the VXD, we + could optimise this to look for the hits in interleaving layers as well. Currently a fast fit is being done for each additional hit, it could be more efficient to try and use kaltest? - + */ - + streamlog_out(DEBUG1) << " BuildTrack starting " << std::endl; - - for (int layer = innerLayer-1; layer>=0; layer--) { // loop over remaining layers + + for (int layer = innerLayer - 1; layer >= 0; layer--) { // loop over remaining layers float distMin = 1.0e+20; - TrackerHitExtended * assignedhit = NULL; - + TrackerHitExtended* assignedhit = NULL; + // loop over phi in the Inner region - for (int ipInner=iPhiLow; ipInner= _nDivisionsInPhi) iPhiInner = ipInner - _nDivisionsInPhi; - + if (ipInner < 0) + iPhiInner = _nDivisionsInPhi - 1; + if (ipInner >= _nDivisionsInPhi) + iPhiInner = ipInner - _nDivisionsInPhi; + // get the index of the theta-phi bin to search - int iCode = layer + _nLayers*iPhiInner + _nLayers*_nDivisionsInPhi*itInner; - + int iCode = layer + _nLayers * iPhiInner + _nLayers * _nDivisionsInPhi * itInner; + // get the hits from this bin TrackerHitExtendedVec& hitVecInner = _sectors[iCode]; - + int nHitsInner = int(hitVecInner.size()); - + // loop over hits in the Inner sector - for (int iInner=0;iInnergetTrackerHit()->getPosition()[i]); } - - // get the distance of closest approach and distance s traversed to the POCA - float time = helix.getDistanceToPoint(pos,distance); - - // sanity check on s + + // get the distance of closest approach and distance s traversed to the POCA + float time = helix.getDistanceToPoint(pos, distance); + + // sanity check on s if (time < 1.0e+10) { - + // check if this is the closest hit yet - if (distance[2] < distMin) { // distance[2] = sqrt( d0*d0 + z0*z0 ) - - // if yes store hit and distance - distMin = distance[2]; + if (distance[2] < distMin) { // distance[2] = sqrt( d0*d0 + z0*z0 ) + + // if yes store hit and distance + distMin = distance[2]; assignedhit = currentHit; } } } // endloop over hits in the Inner sector - } // endloop over theta in the Inner region - } // endloop over phi in the Inner region - + } // endloop over theta in the Inner region + } // endloop over phi in the Inner region + // check if closest hit fulfills the min distance cut if (distMin < _minDistCutAttach) { - - // if yes try to include it in the fit - + + // if yes try to include it in the fit + TrackerHitExtendedVec& hvec = trackAR->getTrackerHitExtendedVec(); - int nHits = int(hvec.size()); - double * xh = new double[nHits+1]; - double * yh = new double[nHits+1]; - float * zh = new float[nHits+1]; - double * wrh = new double[nHits+1]; - float * wzh = new float[nHits+1]; - float * rh = new float[nHits+1]; - float * ph = new float[nHits+1]; + int nHits = int(hvec.size()); + double* xh = new double[nHits + 1]; + double* yh = new double[nHits + 1]; + float* zh = new float[nHits + 1]; + double* wrh = new double[nHits + 1]; + float* wzh = new float[nHits + 1]; + float* rh = new float[nHits + 1]; + float* ph = new float[nHits + 1]; float par[5]; float epar[15]; - - for (int ih=0;ihgetTrackerHit(); + + for (int ih = 0; ih < nHits; ++ih) { + TrackerHit* trkHit = hvec[ih]->getTrackerHit(); xh[ih] = trkHit->getPosition()[0]; yh[ih] = trkHit->getPosition()[1]; zh[ih] = float(trkHit->getPosition()[2]); - wrh[ih] = double(1.0/(hvec[ih]->getResolutionRPhi()*hvec[ih]->getResolutionRPhi())); - wzh[ih] = 1.0/(hvec[ih]->getResolutionZ()*hvec[ih]->getResolutionZ()); - rh[ih] = float(sqrt(xh[ih]*xh[ih]+yh[ih]*yh[ih])); - ph[ih] = float(atan2(yh[ih],xh[ih])); - if (ph[ih] < 0.) - ph[ih] = TWOPI + ph[ih]; - } - TrackerHit * assignedTrkHit = assignedhit->getTrackerHit(); + wrh[ih] = double(1.0 / (hvec[ih]->getResolutionRPhi() * hvec[ih]->getResolutionRPhi())); + wzh[ih] = 1.0 / (hvec[ih]->getResolutionZ() * hvec[ih]->getResolutionZ()); + rh[ih] = float(sqrt(xh[ih] * xh[ih] + yh[ih] * yh[ih])); + ph[ih] = float(atan2(yh[ih], xh[ih])); + if (ph[ih] < 0.) + ph[ih] = TWOPI + ph[ih]; + } + TrackerHit* assignedTrkHit = assignedhit->getTrackerHit(); xh[nHits] = assignedTrkHit->getPosition()[0]; yh[nHits] = assignedTrkHit->getPosition()[1]; zh[nHits] = float(assignedTrkHit->getPosition()[2]); - rh[nHits] = float(sqrt(xh[nHits]*xh[nHits]+yh[nHits]*yh[nHits])); - ph[nHits] = float(atan2(yh[nHits],xh[nHits])); - if (ph[nHits] < 0.) - ph[nHits] = TWOPI + ph[nHits]; - wrh[nHits] = double(1.0/(assignedhit->getResolutionRPhi()*assignedhit->getResolutionRPhi())); - wzh[nHits] = 1.0/(assignedhit->getResolutionZ()*assignedhit->getResolutionZ()); - + rh[nHits] = float(sqrt(xh[nHits] * xh[nHits] + yh[nHits] * yh[nHits])); + ph[nHits] = float(atan2(yh[nHits], xh[nHits])); + if (ph[nHits] < 0.) + ph[nHits] = TWOPI + ph[nHits]; + wrh[nHits] = double(1.0 / (assignedhit->getResolutionRPhi() * assignedhit->getResolutionRPhi())); + wzh[nHits] = 1.0 / (assignedhit->getResolutionZ() * assignedhit->getResolutionZ()); + int NPT = nHits + 1; int iopt = 2; float chi2RPhi; float chi2Z; - -// std::cout << "######## number of hits to fit with _fastfitter = " << NPT << std::endl; - - _fastfitter->fastHelixFit(NPT, xh, yh, rh, ph, wrh, zh, wzh,iopt, par, epar, chi2RPhi, chi2Z); - par[3] = par[3]*par[0]/fabs(par[0]); - - + + // std::cout << "######## number of hits to fit with _fastfitter = " << NPT << std::endl; + + _fastfitter->fastHelixFit(NPT, xh, yh, rh, ph, wrh, zh, wzh, iopt, par, epar, chi2RPhi, chi2Z); + par[3] = par[3] * par[0] / fabs(par[0]); + delete[] xh; delete[] yh; delete[] zh; @@ -2063,22 +1914,22 @@ int SiliconTracking_MarlinTrk::BuildTrack(TrackerHitExtended * /*outerHit*/, delete[] wzh; delete[] rh; delete[] ph; - + bool validCombination = 0; float Chi2 = FLT_MAX; - - if ((nHits+1) == 4) { - Chi2 = chi2RPhi*_chi2WRPhiQuartet+chi2Z*_chi2WZQuartet; - } - if ((nHits+1) >= 5) { - Chi2 = chi2RPhi*_chi2WRPhiSeptet+chi2Z*_chi2WZSeptet; + + if ((nHits + 1) == 4) { + Chi2 = chi2RPhi * _chi2WRPhiQuartet + chi2Z * _chi2WZQuartet; + } + if ((nHits + 1) >= 5) { + Chi2 = chi2RPhi * _chi2WRPhiSeptet + chi2Z * _chi2WZSeptet; } - int ndf = 2*NPT-5; - + int ndf = 2 * NPT - 5; + // check if this is valid combination based on the chi2/ndf - validCombination = Chi2/float(ndf) < _chi2FitCut; - - if ( validCombination ) { + validCombination = Chi2 / float(ndf) < _chi2FitCut; + + if (validCombination) { // assign hit to track and track to hit, update the track parameters trackAR->addTrackerHitExtended(assignedhit); assignedhit->addTrackExtended(trackAR); @@ -2087,101 +1938,97 @@ int SiliconTracking_MarlinTrk::BuildTrack(TrackerHitExtended * /*outerHit*/, float phi0 = par[2]; float d0 = par[3]; float z0 = par[4]; - helix.Initialize_Canonical(phi0,d0,z0,omega,tanlambda,_bField); + helix.Initialize_Canonical(phi0, d0, z0, omega, tanlambda, _bField); trackAR->setD0(d0); trackAR->setZ0(z0); trackAR->setPhi(phi0); trackAR->setTanLambda(tanlambda); trackAR->setOmega(omega); - trackAR->setChi2( Chi2 ); + trackAR->setChi2(Chi2); trackAR->setCovMatrix(epar); - trackAR->setNDF( ndf ); + trackAR->setNDF(ndf); } - } } // endloop over remaining layers - - TrackerHitExtendedVec& hvec = trackAR->getTrackerHitExtendedVec(); + + TrackerHitExtendedVec& hvec = trackAR->getTrackerHitExtendedVec(); int nTotalHits = int(hvec.size()); - -// std::cout << "######## number of hits to return = " << nTotalHits << std::endl; - + + // std::cout << "######## number of hits to return = " << nTotalHits << std::endl; + return nTotalHits; - } - -void SiliconTracking_MarlinTrk::Sorting(TrackExtendedVec & trackVec) { +void SiliconTracking_MarlinTrk::Sorting(TrackExtendedVec& trackVec) { /** Sorting of Track Vector in ascending order of chi2/ndf */ - - std::sort(trackVec.begin(), trackVec.end(), compare_TrackExtended() ); - + + std::sort(trackVec.begin(), trackVec.end(), compare_TrackExtended()); + // also clean up? what does this do here? - for (size_t i=0, sizeOfVector=trackVec.size(); igetTrackerHitExtendedVec(); int nHits = int(hitVec.size()); - - for (int ih=0;ihclearTrackVec(); } } - } -void SiliconTracking_MarlinTrk::CreateTrack(TrackExtended * trackAR ) { - +void SiliconTracking_MarlinTrk::CreateTrack(TrackExtended* trackAR) { + /** Method which creates Track out of TrackExtended objects. Checks for possible track splitting (separate track segments in VXD and FTD). */ - - + TrackerHitExtendedVec& hitVec = trackAR->getTrackerHitExtendedVec(); int nHits = int(hitVec.size()); - - for (int i=0; igetTrackExtendedVec(); - if (trackVec.size() != 0) - return ; + if (trackVec.size() != 0) + return; } - + // First check if the current track is piece of the split one // look for matching track segment - + int found = 0; - + int nTrk = int(_trackImplVec.size()); - - for (int itrk=0; itrkgetTrackerHitExtendedVec(); - + float phiNew = trackAR->getPhi(); float phiOld = trackOld->getPhi(); float thetaNew = M_PI_2 - atan(trackAR->getTanLambda()); float thetaOld = M_PI_2 - atan(trackOld->getTanLambda()); - - float angle = (cos(phiNew)*cos(phiOld)+sin(phiNew)*sin(phiOld))*sin(thetaNew)*sin(thetaOld)+cos(thetaNew)*cos(thetaOld); + + float angle = (cos(phiNew) * cos(phiOld) + sin(phiNew) * sin(phiOld)) * sin(thetaNew) * sin(thetaOld) + + cos(thetaNew) * cos(thetaOld); angle = acos(angle); - + if (angle < _angleCutForMerging) { int nHitsOld = int(hitVecOld.size()); int nTotHits = nHits + nHitsOld; - double * xh = new double[nTotHits]; - double * yh = new double[nTotHits]; - float * zh = new float[nTotHits]; - double * wrh = new double[nTotHits]; - float * wzh = new float[nTotHits]; - float * rh = new float[nTotHits]; - float * ph = new float[nTotHits]; + double* xh = new double[nTotHits]; + double* yh = new double[nTotHits]; + float* zh = new float[nTotHits]; + double* wrh = new double[nTotHits]; + float* wzh = new float[nTotHits]; + float* rh = new float[nTotHits]; + float* ph = new float[nTotHits]; float par[5]; float epar[15]; - //float refPoint[3] = {0.,0.,0.}; - for (int ih=0;ihgetTrackerHit(); + // float refPoint[3] = {0.,0.,0.}; + for (int ih = 0; ih < nHits; ++ih) { + TrackerHit* trkHit = hitVec[ih]->getTrackerHit(); float rR = hitVec[ih]->getResolutionRPhi(); float rZ = hitVec[ih]->getResolutionZ(); if (int(hitVec[ih]->getTrackExtendedVec().size()) != 0) @@ -2189,92 +2036,89 @@ void SiliconTracking_MarlinTrk::CreateTrack(TrackExtended * trackAR ) { xh[ih] = trkHit->getPosition()[0]; yh[ih] = trkHit->getPosition()[1]; zh[ih] = float(trkHit->getPosition()[2]); - wrh[ih] = double(1.0/(rR*rR)); - wzh[ih] = 1.0/(rZ*rZ); - rh[ih] = float(sqrt(xh[ih]*xh[ih]+yh[ih]*yh[ih])); - ph[ih] = float(atan2(yh[ih],xh[ih])); - } - for (int ih=0;ihgetTrackerHit(); - xh[ih+nHits] = trkHit->getPosition()[0]; - yh[ih+nHits] = trkHit->getPosition()[1]; - zh[ih+nHits] = float(trkHit->getPosition()[2]); + wrh[ih] = double(1.0 / (rR * rR)); + wzh[ih] = 1.0 / (rZ * rZ); + rh[ih] = float(sqrt(xh[ih] * xh[ih] + yh[ih] * yh[ih])); + ph[ih] = float(atan2(yh[ih], xh[ih])); + } + for (int ih = 0; ih < nHitsOld; ++ih) { + TrackerHit* trkHit = hitVecOld[ih]->getTrackerHit(); + xh[ih + nHits] = trkHit->getPosition()[0]; + yh[ih + nHits] = trkHit->getPosition()[1]; + zh[ih + nHits] = float(trkHit->getPosition()[2]); float rR = hitVecOld[ih]->getResolutionRPhi(); - float rZ = hitVecOld[ih]->getResolutionZ(); - wrh[ih+nHits] = double(1.0/(rR*rR)); - wzh[ih+nHits] = 1.0/(rZ*rZ); - rh[ih+nHits] = float(sqrt(xh[ih+nHits]*xh[ih+nHits]+yh[ih+nHits]*yh[ih+nHits])); - ph[ih+nHits] = float(atan2(yh[ih+nHits],xh[ih+nHits])); - + float rZ = hitVecOld[ih]->getResolutionZ(); + wrh[ih + nHits] = double(1.0 / (rR * rR)); + wzh[ih + nHits] = 1.0 / (rZ * rZ); + rh[ih + nHits] = float(sqrt(xh[ih + nHits] * xh[ih + nHits] + yh[ih + nHits] * yh[ih + nHits])); + ph[ih + nHits] = float(atan2(yh[ih + nHits], xh[ih + nHits])); } int NPT = nTotHits; int iopt = 2; float chi2RPhi; float chi2Z; - int ndf = 2*NPT - 5; - - _fastfitter->fastHelixFit(NPT, xh, yh, rh, ph, wrh, zh, wzh,iopt, par, epar, chi2RPhi, chi2Z); - par[3] = par[3]*par[0]/fabs(par[0]); - + int ndf = 2 * NPT - 5; + + _fastfitter->fastHelixFit(NPT, xh, yh, rh, ph, wrh, zh, wzh, iopt, par, epar, chi2RPhi, chi2Z); + par[3] = par[3] * par[0] / fabs(par[0]); + float omega = par[0]; float tanlambda = par[1]; float phi0 = par[2]; float d0 = par[3]; float z0 = par[4]; - + float eparmin[15]; - for (int iparam=0;iparam<15;++iparam) - eparmin[iparam] = epar[iparam]; - + for (int iparam = 0; iparam < 15; ++iparam) + eparmin[iparam] = epar[iparam]; + // float refPointMin[3]; // for (int ipp=0;ipp<3;++ipp) // refPointMin[ipp] = refPoint[ipp]; - - float chi2Min = chi2RPhi*_chi2WRPhiSeptet+chi2Z*_chi2WZSeptet; - chi2Min = chi2Min/float(ndf); - - //float chi2MinRPhi = chi2RPhi; - //float chi2MinZ = chi2Z; - + + float chi2Min = chi2RPhi * _chi2WRPhiSeptet + chi2Z * _chi2WZSeptet; + chi2Min = chi2Min / float(ndf); + + // float chi2MinRPhi = chi2RPhi; + // float chi2MinZ = chi2Z; + int iBad = -1; if (chi2Min < _chi2FitCut) { found = 1; - } - else { // SJA:FIXME: UH What is going on here? setting weights to 0 and refitting? - float * wzhOld = new float[nTotHits]; - double * wrhOld = new double[nTotHits]; - for (int i=0;ifastHelixFit(NPT, xh, yh, rh, ph, wrh, zh, wzh,iopt, par, epar, chi2RPhi, chi2Z); - par[3] = par[3]*par[0]/fabs(par[0]); - - float chi2Cur = chi2RPhi*_chi2WRPhiSeptet+chi2Z*_chi2WZSeptet; - chi2Cur = chi2Cur/float(ndf); - + + _fastfitter->fastHelixFit(NPT, xh, yh, rh, ph, wrh, zh, wzh, iopt, par, epar, chi2RPhi, chi2Z); + par[3] = par[3] * par[0] / fabs(par[0]); + + float chi2Cur = chi2RPhi * _chi2WRPhiSeptet + chi2Z * _chi2WZSeptet; + chi2Cur = chi2Cur / float(ndf); + if (chi2Cur < chi2Min) { chi2Min = chi2Cur; - //chi2MinRPhi = chi2RPhi; - //chi2MinZ = chi2Z; + // chi2MinRPhi = chi2RPhi; + // chi2MinZ = chi2Z; omega = par[0]; tanlambda = par[1]; phi0 = par[2]; d0 = par[3]; z0 = par[4]; - for (int iparam=0;iparam<15;++iparam) + for (int iparam = 0; iparam < 15; ++iparam) eparmin[iparam] = epar[iparam]; // for (int ipp=0;ipp<3;++ipp) // refPointMin[ipp] = refPoint[ipp]; @@ -2287,64 +2131,62 @@ void SiliconTracking_MarlinTrk::CreateTrack(TrackExtended * trackAR ) { delete[] wzhOld; delete[] wrhOld; } - + // Split track is found. - // Attach hits belonging to the current track segment to + // Attach hits belonging to the current track segment to // the track already created if (found == 1) { - if(_useSimpleAttachHitToTrack) { // improvement for the fitting - - trackAR->ClearTrackerHitExtendedVec(); - for (int i=0;iClearTrackerHitExtendedVec(); - for (int i=0;iclearTrackVec(); - if (i == iBad) { - } - else { - trackOld->addTrackerHitExtended(trkHit); - trkHit->addTrackExtended( trackOld ); - } - } - for (int i=0;iclearTrackVec(); - if (icur == iBad) { - } - else { - trackOld->addTrackerHitExtended(trkHit); - trkHit->addTrackExtended( trackOld ); - } - } - } + if (_useSimpleAttachHitToTrack) { // improvement for the fitting + + trackAR->ClearTrackerHitExtendedVec(); + for (int i = 0; i < nHits; ++i) { + int iopt = 2; + TrackerHitExtended* trkHit = hitVec[i]; + AttachHitToTrack(trackOld, trkHit, iopt); + } + + } else { // backward compatible + + trackOld->ClearTrackerHitExtendedVec(); + for (int i = 0; i < nHits; ++i) { + TrackerHitExtended* trkHit = hitVec[i]; + trkHit->clearTrackVec(); + if (i == iBad) { + } else { + trackOld->addTrackerHitExtended(trkHit); + trkHit->addTrackExtended(trackOld); + } + } + for (int i = 0; i < nHitsOld; ++i) { + int icur = i + nHits; + TrackerHitExtended* trkHit = hitVecOld[i]; + trkHit->clearTrackVec(); + if (icur == iBad) { + } else { + trackOld->addTrackerHitExtended(trkHit); + trkHit->addTrackExtended(trackOld); + } + } + } trackOld->setOmega(omega); trackOld->setTanLambda(tanlambda); trackOld->setPhi(phi0); trackOld->setD0(d0); trackOld->setZ0(z0); - + // std::cout << "Split track found " << d0 << " " << z0 << std::endl; - + // killeb: In the original SiliconTracking this was in the NOT simple helix branch. // The rest of the code uses the simple helix branch, where ndf_D is never set. // In fact it has never been initialised or used anywhere. I think this line should not be executed. // ndf = ndf_D; - - trackOld->setChi2(chi2Min*float(ndf)); + + trackOld->setChi2(chi2Min * float(ndf)); trackOld->setNDF(ndf); trackOld->setCovMatrix(eparmin); // trackOld->setReferencePoint(refPointMin); } - + delete[] xh; delete[] yh; delete[] zh; @@ -2352,83 +2194,81 @@ void SiliconTracking_MarlinTrk::CreateTrack(TrackExtended * trackAR ) { delete[] wzh; delete[] rh; delete[] ph; - } if (found == 1) break; } - + // Candidate is a unique track // No other segments are found - if (found == 0 ) { + if (found == 0) { _trackImplVec.push_back(trackAR); - for (int i=0;iaddTrackExtended( trackAR ); + for (int i = 0; i < nHits; ++i) { + TrackerHitExtended* hit = hitVec[i]; + hit->addTrackExtended(trackAR); } } - - } void SiliconTracking_MarlinTrk::AttachRemainingVTXHitsFast() { - + std::vector nonAttachedHits; - nonAttachedHits.resize(_nDivisionsInPhi*_nDivisionsInTheta); + nonAttachedHits.resize(_nDivisionsInPhi * _nDivisionsInTheta); std::vector trackVector; - trackVector.resize(_nDivisionsInPhi*_nDivisionsInTheta); + trackVector.resize(_nDivisionsInPhi * _nDivisionsInTheta); int nTracks = int(_trackImplVec.size()); - - for (int iTrk=0;iTrkgetPhi()); if (Phi < 0) Phi = Phi + TWOPI; float tanlambda = track->getTanLambda(); - double cosTheta = double(tanlambda/sqrt(1+tanlambda*tanlambda)); - int iPhi = int(Phi/_dPhi); - int iTheta = int ((cosTheta + double(1.0))/_dTheta); - int iCode = iPhi + _nDivisionsInPhi*iTheta; - trackVector[iCode].push_back( track ); + double cosTheta = double(tanlambda / sqrt(1 + tanlambda * tanlambda)); + int iPhi = int(Phi / _dPhi); + int iTheta = int((cosTheta + double(1.0)) / _dTheta); + int iCode = iPhi + _nDivisionsInPhi * iTheta; + trackVector[iCode].push_back(track); } - - for (int il=0;il<_nLayers;++il) { - for (int ip=0;ip<_nDivisionsInPhi;++ip) { - for (int it=0;it<_nDivisionsInTheta; ++it) { - int iCode = il + _nLayers*ip + _nLayers*_nDivisionsInPhi*it; + + for (int il = 0; il < _nLayers; ++il) { + for (int ip = 0; ip < _nDivisionsInPhi; ++ip) { + for (int it = 0; it < _nDivisionsInTheta; ++it) { + int iCode = il + _nLayers * ip + _nLayers * _nDivisionsInPhi * it; TrackerHitExtendedVec& hitVec = _sectors[iCode]; int nH = int(hitVec.size()); - for (int iH=0; iHgetTrackExtendedVec(); - if (trackVec.size()==0) { - TrackerHit * hit = hitExt->getTrackerHit(); + if (trackVec.size() == 0) { + TrackerHit* hit = hitExt->getTrackerHit(); double pos[3]; double radius = 0; - for (int i=0; i<3; ++i) { + for (int i = 0; i < 3; ++i) { pos[i] = hit->getPosition()[i]; - radius += pos[i]*pos[i]; + radius += pos[i] * pos[i]; } radius = sqrt(radius); - double cosTheta = pos[2]/radius; - double Phi = atan2(pos[1],pos[0]); - if (Phi < 0.) Phi = Phi + TWOPI; - int iPhi = int(Phi/_dPhi); - int iTheta = int ((cosTheta + double(1.0))/_dTheta); - iCode = iPhi + _nDivisionsInPhi*iTheta; - nonAttachedHits[iCode].push_back( hitExt ); + double cosTheta = pos[2] / radius; + double Phi = atan2(pos[1], pos[0]); + if (Phi < 0.) + Phi = Phi + TWOPI; + int iPhi = int(Phi / _dPhi); + int iTheta = int((cosTheta + double(1.0)) / _dTheta); + iCode = iPhi + _nDivisionsInPhi * iTheta; + nonAttachedHits[iCode].push_back(hitExt); } } } } } - - for (int iT=0; iT<_nDivisionsInTheta; ++iT) { - for (int iP=0; iP<_nDivisionsInPhi; ++iP) { - int iCode = iP + _nDivisionsInPhi*iT; + + for (int iT = 0; iT < _nDivisionsInTheta; ++iT) { + for (int iP = 0; iP < _nDivisionsInPhi; ++iP) { + int iCode = iP + _nDivisionsInPhi * iT; int nHits = int(nonAttachedHits[iCode].size()); int iT1 = iT - 1; - int iT2 = iT + 1; + int iT2 = iT + 1; if (iT == 0) { iT1 = iT; iT2 = iT1 + 1; @@ -2441,71 +2281,71 @@ void SiliconTracking_MarlinTrk::AttachRemainingVTXHitsFast() { iPHI[0] = iP - 1; iPHI[1] = iP; iPHI[2] = iP + 1; - if (iP == 0) + if (iP == 0) iPHI[0] = _nDivisionsInPhi - 1; - if (iP == _nDivisionsInPhi - 1 ) + if (iP == _nDivisionsInPhi - 1) iPHI[2] = 0; - - for (int ihit = 0; ihitgetTrackerHitExtendedVec(); int NHITS = int(hitVector.size()); - for (int IHIT=0;IHITgetTrackerHit(); - TrackerHit* trkhit2 = hitVector[IHIT]->getTrackerHit(); - - if ( trkhit1->getCellID0() == trkhit2->getCellID0() ){ // i.e. they are in the same sensor + TrackerHit* trkhit2 = hitVector[IHIT]->getTrackerHit(); + + if (trkhit1->getCellID0() == trkhit2->getCellID0()) { // i.e. they are in the same sensor float distance = 0.; - for (int iC=0;iC<3;++iC) { + for (int iC = 0; iC < 3; ++iC) { float posFirst = float(hit->getTrackerHit()->getPosition()[iC]); float posSecond = float(hitVector[IHIT]->getTrackerHit()->getPosition()[iC]); float deltaPos = posFirst - posSecond; - distance += deltaPos*deltaPos; + distance += deltaPos * deltaPos; } distance = sqrt(distance); - if (distance<_minDistToDelta) { + if (distance < _minDistToDelta) { consider = false; break; } } } } - if (consider) { + if (consider) { float phi0 = trackAR->getPhi(); float d0 = trackAR->getD0(); float z0 = trackAR->getZ0(); float omega = trackAR->getOmega(); float tanlambda = trackAR->getTanLambda(); HelixClass helix; - helix.Initialize_Canonical(phi0,d0,z0,omega,tanlambda,_bField); + helix.Initialize_Canonical(phi0, d0, z0, omega, tanlambda, _bField); int layer = getLayerID(hit->getTrackerHit()); if (layer > _minimalLayerToAttach) { float pos[3]; - for (int i=0; i<3; ++i) - pos[i] = hit->getTrackerHit()->getPosition()[i]; + for (int i = 0; i < 3; ++i) + pos[i] = hit->getTrackerHit()->getPosition()[i]; float distance[3]; - float time = helix.getDistanceToPoint(pos,distance); + float time = helix.getDistanceToPoint(pos, distance); if (time < 1.0e+10) { if (distance[2] < minDist) { minDist = distance[2]; trackToAttach = trackAR; - } - } + } + } } } } @@ -2513,88 +2353,88 @@ void SiliconTracking_MarlinTrk::AttachRemainingVTXHitsFast() { } if (minDist < _minDistCutAttach && trackToAttach != NULL) { int iopt = 2; - AttachHitToTrack(trackToAttach,hit,iopt); - } + AttachHitToTrack(trackToAttach, hit, iopt); + } } } } } void SiliconTracking_MarlinTrk::AttachRemainingVTXHitsSlow() { - + TrackerHitExtendedVec nonAttachedHits; nonAttachedHits.clear(); - - for (int il=0;il<_nLayers;++il) { - for (int ip=0;ip<_nDivisionsInPhi;++ip) { - for (int it=0;it<_nDivisionsInTheta; ++it) { - int iCode = il + _nLayers*ip + _nLayers*_nDivisionsInPhi*it; + + for (int il = 0; il < _nLayers; ++il) { + for (int ip = 0; ip < _nDivisionsInPhi; ++ip) { + for (int it = 0; it < _nDivisionsInTheta; ++it) { + int iCode = il + _nLayers * ip + _nLayers * _nDivisionsInPhi * it; TrackerHitExtendedVec& hitVec = _sectors[iCode]; int nH = int(hitVec.size()); - for (int iH=0; iHgetTrackExtendedVec(); // if (trackVec.size()==0) // nonAttachedHits.push_back( hit ); - //-- allow hits that are only used in triplets to be re-attached + //-- allow hits that are only used in triplets to be re-attached unsigned int maxTrackSize = 0; - for(unsigned int itrack = 0;itrack < trackVec.size();itrack++){ - TrackerHitExtendedVec hitVec_tmp= trackVec[itrack]->getTrackerHitExtendedVec(); + for (unsigned int itrack = 0; itrack < trackVec.size(); itrack++) { + TrackerHitExtendedVec hitVec_tmp = trackVec[itrack]->getTrackerHitExtendedVec(); unsigned int isize = hitVec_tmp.size(); - if(isize>maxTrackSize)maxTrackSize = isize; - } - if (maxTrackSize<=3) { + if (isize > maxTrackSize) + maxTrackSize = isize; + } + if (maxTrackSize <= 3) { streamlog_out(DEBUG1) << " Add non attached hit to list: id = " << hit->getTrackerHit()->id() << std::endl; - nonAttachedHits.push_back( hit ); - } - - + nonAttachedHits.push_back(hit); + } } } } } - + int nNotAttached = int(nonAttachedHits.size()); - - int nTrk = int(_trackImplVec.size()); - for (int iHit=0; iHitid() << std::endl; + streamlog_out(DEBUG1) << " hit: id = " << hit->getTrackerHit()->id() + << " condsidered delta together with hit " << trkhit2->id() << std::endl; break; } - } + } } } if (consider) { @@ -2604,9 +2444,9 @@ void SiliconTracking_MarlinTrk::AttachRemainingVTXHitsSlow() { float z0 = trackAR->getZ0(); float omega = trackAR->getOmega(); float tanlambda = trackAR->getTanLambda(); - helix.Initialize_Canonical(phi0,d0,z0,omega,tanlambda,_bField); + helix.Initialize_Canonical(phi0, d0, z0, omega, tanlambda, _bField); float distance[3]; - float time = helix.getDistanceToPoint(pos,distance); + float time = helix.getDistanceToPoint(pos, distance); if (time < 1.0e+10) { if (distance[2] < minDist) { minDist = distance[2]; @@ -2617,63 +2457,63 @@ void SiliconTracking_MarlinTrk::AttachRemainingVTXHitsSlow() { } if (minDist < _minDistCutAttach && trackToAttach != NULL) { int iopt = 2; - streamlog_out(DEBUG1) << " Hit: id = " << hit->getTrackerHit()->id() << " : try attachement"<< std::endl; - AttachHitToTrack(trackToAttach,hit,iopt); + streamlog_out(DEBUG1) << " Hit: id = " << hit->getTrackerHit()->id() << " : try attachement" << std::endl; + AttachHitToTrack(trackToAttach, hit, iopt); } else { - streamlog_out(DEBUG1) << " Hit: id = " << hit->getTrackerHit()->id() << " rejected due to distance cut of " <<_minDistCutAttach<< " min distance = " << minDist << std::endl; - } + streamlog_out(DEBUG1) << " Hit: id = " << hit->getTrackerHit()->id() << " rejected due to distance cut of " + << _minDistCutAttach << " min distance = " << minDist << std::endl; + } } - } + } } void SiliconTracking_MarlinTrk::AttachRemainingFTDHitsSlow() { TrackerHitExtendedVec nonAttachedHits; nonAttachedHits.clear(); - - for (int iS=0;iS<2;++iS) { - for (unsigned int layer=0;layer<_nlayersFTD;++layer) { - for (int ip=0;ip<_nPhiFTD;++ip) { - int iCode = iS + 2*layer + 2*_nlayersFTD*ip; + + for (int iS = 0; iS < 2; ++iS) { + for (unsigned int layer = 0; layer < _nlayersFTD; ++layer) { + for (int ip = 0; ip < _nPhiFTD; ++ip) { + int iCode = iS + 2 * layer + 2 * _nlayersFTD * ip; TrackerHitExtendedVec& hitVec = _sectorsFTD[iCode]; int nH = int(hitVec.size()); - for (int iH=0; iHgetTrackExtendedVec(); - if (trackVec.size()==0) - nonAttachedHits.push_back( hit ); + if (trackVec.size() == 0) + nonAttachedHits.push_back(hit); } } } } - + int nNotAttached = int(nonAttachedHits.size()); - - int nTrk = int(_trackImplVec.size()); - for (int iHit=0; iHitgetTrackerHit()->getPosition()[i]; + for (int i = 0; i < 3; ++i) + pos[i] = hit->getTrackerHit()->getPosition()[i]; float minDist = 1e+10; - TrackExtended * trackToAttach = NULL; - for (int iTrk=0; iTrkgetTrackerHitExtendedVec(); int NHITS = int(hitVector.size()); - - for (int IHIT=0;IHITgetTrackerHit()->getType() == hitVector[IHIT]->getTrackerHit()->getType()) { if (hit->getTrackerHit()->getCellID0() == hitVector[IHIT]->getTrackerHit()->getCellID0()) { - + consider = false; break; } } - - + if (consider) { HelixClass helix; float phi0 = trackAR->getPhi(); @@ -2681,10 +2521,10 @@ void SiliconTracking_MarlinTrk::AttachRemainingFTDHitsSlow() { float z0 = trackAR->getZ0(); float omega = trackAR->getOmega(); float tanlambda = trackAR->getTanLambda(); - if (tanlambda*float(getSideID(hit->getTrackerHit())) > 0) { - helix.Initialize_Canonical(phi0,d0,z0,omega,tanlambda,_bField); + if (tanlambda * float(getSideID(hit->getTrackerHit())) > 0) { + helix.Initialize_Canonical(phi0, d0, z0, omega, tanlambda, _bField); float distance[3]; - float time = helix.getDistanceToPoint(pos,distance); + float time = helix.getDistanceToPoint(pos, distance); if (time < 1.0e+10) { if (distance[2] < minDist) { minDist = distance[2]; @@ -2696,74 +2536,72 @@ void SiliconTracking_MarlinTrk::AttachRemainingFTDHitsSlow() { } if (minDist < _minDistCutAttach && trackToAttach != NULL) { int iopt = 2; - AttachHitToTrack(trackToAttach,hit,iopt); - } - } + AttachHitToTrack(trackToAttach, hit, iopt); + } + } } - void SiliconTracking_MarlinTrk::AttachRemainingFTDHitsFast() { int nTrk = _trackImplVec.size(); - - for (int iTrk=0; iTrkgetPhi(); float d0 = trackAR->getD0(); float z0 = trackAR->getZ0(); float omega = trackAR->getOmega(); float tanlambda = trackAR->getTanLambda(); - helix.Initialize_Canonical(phi0,d0,z0,omega,tanlambda,_bField); + helix.Initialize_Canonical(phi0, d0, z0, omega, tanlambda, _bField); int iSemiSphere = 0; - if (tanlambda > 0) + if (tanlambda > 0) iSemiSphere = 1; float ref[3]; - for (int i=0;i<3;++i) + for (int i = 0; i < 3; ++i) ref[i] = helix.getReferencePoint()[i]; // Start loop over FTD layers - for (unsigned int layer=0;layer<_nlayersFTD;layer++) { + for (unsigned int layer = 0; layer < _nlayersFTD; layer++) { float ZL = _zLayerFTD[layer]; if (iSemiSphere == 0) - ZL = - ZL; + ZL = -ZL; float point[3]; - helix.getPointInZ(ZL,ref,point); - float Phi = atan2(point[1],point[0]); - if (Phi < 0) + helix.getPointInZ(ZL, ref, point); + float Phi = atan2(point[1], point[0]); + if (Phi < 0) Phi = Phi + TWOPI; - int iPhi = int(Phi/_dPhiFTD); + int iPhi = int(Phi / _dPhiFTD); float distMin = 1e+10; - TrackerHitExtended * attachedHit = NULL; - for (int iP=iPhi-1;iP<=iPhi+1;++iP) { + TrackerHitExtended* attachedHit = NULL; + for (int iP = iPhi - 1; iP <= iPhi + 1; ++iP) { int iPP = iP; - if (iP < 0) + if (iP < 0) iPP = iP + _nPhiFTD; if (iP >= _nPhiFTD) - iPP = iP - _nPhiFTD; - int iCode = iSemiSphere + 2*layer + 2*_nlayersFTD*iPP; + iPP = iP - _nPhiFTD; + int iCode = iSemiSphere + 2 * layer + 2 * _nlayersFTD * iPP; int nHits = int(_sectorsFTD[iCode].size()); - for (int iHit=0;iHitgetTrackerHitExtendedVec(); int NHITS = int(hitVector.size()); - - // SJA:FIXME: check to see if allowing no hits in the same sensor vs no hits in the same layer works - for (int IHIT=0;IHITgetTrackerHit()->getType() == hitVector[IHIT]->getTrackerHit()->getType()) { if (hit->getTrackerHit()->getCellID0() == hitVector[IHIT]->getTrackerHit()->getCellID0()) { consider = false; break; } } - - + if (consider) { float pos[3]; - for (int i=0;i<3;++i) { + for (int i = 0; i < 3; ++i) { pos[i] = hit->getTrackerHit()->getPosition()[i]; } float distance[3]; - float time = helix.getDistanceToPoint(pos,distance); + float time = helix.getDistanceToPoint(pos, distance); if (time < 1.0e+10) { if (distance[2] < distMin) { distMin = distance[2]; @@ -2775,7 +2613,7 @@ void SiliconTracking_MarlinTrk::AttachRemainingFTDHitsFast() { } if (distMin < _minDistCutAttach && attachedHit != NULL) { int iopt = 2; - AttachHitToTrack(trackAR,attachedHit, iopt); + AttachHitToTrack(trackAR, attachedHit, iopt); } } } @@ -2785,15 +2623,15 @@ void SiliconTracking_MarlinTrk::TrackingInFTD() { int nComb = int(_CombinationsFTD.size()) / 3; - for (int iComb=0;iComb= _sectorsFTD.size()){ - streamlog_out(ERROR) << "iCodeOuter index out of range: iCodeOuter = " << iCodeOuter << " _sectorsFTD.size() = " << _sectorsFTD.size() << " exit(1) called from file " << __FILE__ << " line " << __LINE__<< std::endl; + int ipMiddleUp = ipOuter + 1; + + unsigned int iCodeOuter = iS + 2 * nLS[0] + 2 * _nlayersFTD * ipOuter; + + if (iCodeOuter >= _sectorsFTD.size()) { + streamlog_out(ERROR) << "iCodeOuter index out of range: iCodeOuter = " << iCodeOuter + << " _sectorsFTD.size() = " << _sectorsFTD.size() << " exit(1) called from file " + << __FILE__ << " line " << __LINE__ << std::endl; exit(1); } - + TrackerHitExtendedVec& hitVecOuter = _sectorsFTD[iCodeOuter]; - + int nOuter = int(hitVecOuter.size()); - for (int iOuter=0;iOuter= _nPhiFTD) ipM = ipMiddle - _nPhiFTD; - int iCodeMiddle = iS + 2*nLS[1] + 2*_nlayersFTD*ipM; - + int iCodeMiddle = iS + 2 * nLS[1] + 2 * _nlayersFTD * ipM; + TrackerHitExtendedVec& hitVecMiddle = _sectorsFTD[iCodeMiddle]; - int ipInnerLow,ipInnerUp; + int ipInnerLow, ipInnerUp; ipInnerLow = ipMiddle - 1; - ipInnerUp = ipMiddle + 1; - + ipInnerUp = ipMiddle + 1; + int nMiddle = int(hitVecMiddle.size()); - - for (int iMiddle=0;iMiddle= _nPhiFTD) + if (ipI >= _nPhiFTD) ipI = ipInner - _nPhiFTD; - int iCodeInner = iS + 2*nLS[2] + 2*_nlayersFTD*ipI; + int iCodeInner = iS + 2 * nLS[2] + 2 * _nlayersFTD * ipI; TrackerHitExtendedVec& hitVecInner = _sectorsFTD[iCodeInner]; - + int nInner = int(hitVecInner.size()); - - for (int iInner=0;iInnergetTrackerHit()->getType() << " z = " << hitOuter->getTrackerHit()->getPosition()[2] - // << "\nMiddle Hit Type "<< hitMiddle->getTrackerHit()->getType() << " z = " << hitMiddle->getTrackerHit()->getPosition()[2] - // << "\nInner Hit Type "<< hitInner->getTrackerHit()->getType() << " z = " << hitInner->getTrackerHit()->getPosition()[2] << std::endl; - - streamlog_out(DEBUG1) << " " - << std::setw(3) << ipOuter << " " << std::setw(3) << ipMiddle << " " << std::setw(3) << ipInner << " " - << std::setw(3) << iS << " " - << std::setw(3) << nLS[0] << " " << std::setw(3) << nLS[1] << " " << std::setw(3) << nLS[2] << " " - << std::setw(3) << nOuter << " : " << std::setw(3) << nMiddle << " : " << std::setw(3) << nInner << " :: " - << std::setw(3) << nOuter*nMiddle* nInner << std::endl; - - - TrackExtended * trackAR = TestTriplet(hitOuter,hitMiddle,hitInner,helix); + // std::cout << "Outer Hit Type " << hitOuter->getTrackerHit()->getType() << " z = " + // << hitOuter->getTrackerHit()->getPosition()[2] + // << "\nMiddle Hit Type "<< hitMiddle->getTrackerHit()->getType() << " z = " << + // hitMiddle->getTrackerHit()->getPosition()[2] + // << "\nInner Hit Type "<< hitInner->getTrackerHit()->getType() << " z = " << + // hitInner->getTrackerHit()->getPosition()[2] << std::endl; + + streamlog_out(DEBUG1) << " " << std::setw(3) << ipOuter << " " << std::setw(3) << ipMiddle << " " + << std::setw(3) << ipInner << " " << std::setw(3) << iS << " " + << std::setw(3) << nLS[0] << " " << std::setw(3) << nLS[1] << " " + << std::setw(3) << nLS[2] << " " << std::setw(3) << nOuter << " : " + << std::setw(3) << nMiddle << " : " << std::setw(3) << nInner + << " :: " << std::setw(3) << nOuter * nMiddle * nInner << std::endl; + + TrackExtended* trackAR = TestTriplet(hitOuter, hitMiddle, hitInner, helix); if (trackAR != NULL) { // std::cout << "FTD triplet found" << std::endl; - int nHits = BuildTrackFTD(trackAR,nLS,iS); - - _tracksWithNHitsContainer.getTracksWithNHitsVec( nHits ).push_back( trackAR ); + int nHits = BuildTrackFTD(trackAR, nLS, iS); + + _tracksWithNHitsContainer.getTracksWithNHitsVec(nHits).push_back(trackAR); } } } } - } + } } } } } } - -int SiliconTracking_MarlinTrk::BuildTrackFTD(TrackExtended * trackAR, int * nLR, int iS) { +int SiliconTracking_MarlinTrk::BuildTrackFTD(TrackExtended* trackAR, int* nLR, int iS) { // std::cout << "BuildTrackFTD: Layers = " << nLR[0] << " " << nLR[1] << " " << nLR[2] << std::endl; - + // initialise a helix from the track HelixClass helix; const float d0 = trackAR->getD0(); @@ -2901,39 +2742,37 @@ int SiliconTracking_MarlinTrk::BuildTrackFTD(TrackExtended * trackAR, int * nLR, const float phi0 = trackAR->getPhi(); const float tanlambda = trackAR->getTanLambda(); const float omega = trackAR->getOmega(); - helix.Initialize_Canonical(phi0,d0,z0,omega,tanlambda,_bField); - float ref[3] = {helix.getReferencePoint()[0], - helix.getReferencePoint()[1], - helix.getReferencePoint()[2]}; - - for (int iL=0; iL < static_cast(_nlayersFTD); ++iL) { + helix.Initialize_Canonical(phi0, d0, z0, omega, tanlambda, _bField); + float ref[3] = {helix.getReferencePoint()[0], helix.getReferencePoint()[1], helix.getReferencePoint()[2]}; + + for (int iL = 0; iL < static_cast(_nlayersFTD); ++iL) { if (iL != nLR[0] && iL != nLR[1] && iL != nLR[2]) { float point[3]; float ZL = _zLayerFTD[iL]; - if (iS == 0) - ZL = - ZL; - helix.getPointInZ(ZL,ref,point); + if (iS == 0) + ZL = -ZL; + helix.getPointInZ(ZL, ref, point); // float Phi = atan2(point[1],point[0]); // int iPhi = int(Phi/_dPhiFTD); float distMin = 1e+6; - TrackerHitExtended * attachedHit = NULL; - for (int ip=0;ip<=_nPhiFTD;++ip) { + TrackerHitExtended* attachedHit = NULL; + for (int ip = 0; ip <= _nPhiFTD; ++ip) { int iP = ip; if (iP < 0) iP = ip + _nPhiFTD; if (iP >= _nPhiFTD) - iP = ip - _nPhiFTD; - int iCode = iS + 2*iL + 2*_nlayersFTD*iP; + iP = ip - _nPhiFTD; + int iCode = iS + 2 * iL + 2 * _nlayersFTD * iP; TrackerHitExtendedVec& hitVec = _sectorsFTD[iCode]; int nH = int(hitVec.size()); - for (int iH=0; iHgetTrackerHit(); + for (int iH = 0; iH < nH; ++iH) { + TrackerHitExtended* hit = hitVec[iH]; + TrackerHit* trkHit = hit->getTrackerHit(); float pos[3]; - for (int i=0;i<3;++i) + for (int i = 0; i < 3; ++i) pos[i] = float(trkHit->getPosition()[i]); float distance[3]; - float time = helix.getDistanceToPoint(pos,distance); + float time = helix.getDistanceToPoint(pos, distance); if (time < 1.0e+10) { if (distance[2] < distMin) { distMin = distance[2]; @@ -2945,71 +2784,68 @@ int SiliconTracking_MarlinTrk::BuildTrackFTD(TrackExtended * trackAR, int * nLR, // std::cout << "Layer = " << iL << " distMin = " << distMin << std::endl; if (distMin < _minDistCutAttach && attachedHit != NULL) { int iopt = 2; - AttachHitToTrack( trackAR, attachedHit, iopt); + AttachHitToTrack(trackAR, attachedHit, iopt); } } } TrackerHitExtendedVec& hitVec = trackAR->getTrackerHitExtendedVec(); - int nH = int (hitVec.size()); + int nH = int(hitVec.size()); return nH; } -int SiliconTracking_MarlinTrk::AttachHitToTrack(TrackExtended * trackAR, TrackerHitExtended * hit, int iopt) { - +int SiliconTracking_MarlinTrk::AttachHitToTrack(TrackExtended* trackAR, TrackerHitExtended* hit, int iopt) { + int attached = 0; TrackerHitExtendedVec& hitVec = trackAR->getTrackerHitExtendedVec(); int nHits = int(hitVec.size()); - - double * xh = new double[nHits+1]; - double * yh = new double[nHits+1]; - float * zh = new float[nHits+1]; - double * wrh = new double[nHits+1]; - float * wzh = new float[nHits+1]; - float * rh = new float[nHits+1]; - float * ph = new float[nHits+1]; + + double* xh = new double[nHits + 1]; + double* yh = new double[nHits + 1]; + float* zh = new float[nHits + 1]; + double* wrh = new double[nHits + 1]; + float* wzh = new float[nHits + 1]; + float* rh = new float[nHits + 1]; + float* ph = new float[nHits + 1]; float par[5]; float epar[15]; - - for (int i=0; igetTrackerHit(); + + for (int i = 0; i < nHits; ++i) { + TrackerHit* trkHit = hitVec[i]->getTrackerHit(); xh[i] = double(trkHit->getPosition()[0]); yh[i] = double(trkHit->getPosition()[1]); zh[i] = float(trkHit->getPosition()[2]); - ph[i] = float(atan2(yh[i],xh[i])); - rh[i] = float(sqrt(xh[i]*xh[i]+yh[i]*yh[i])); + ph[i] = float(atan2(yh[i], xh[i])); + rh[i] = float(sqrt(xh[i] * xh[i] + yh[i] * yh[i])); float rR = hitVec[i]->getResolutionRPhi(); float rZ = hitVec[i]->getResolutionZ(); - wrh[i] = double(1.0/(rR*rR)); - wzh[i] = 1.0/(rZ*rZ); + wrh[i] = double(1.0 / (rR * rR)); + wzh[i] = 1.0 / (rZ * rZ); } - - TrackerHit * trkHit = hit->getTrackerHit(); + + TrackerHit* trkHit = hit->getTrackerHit(); xh[nHits] = double(trkHit->getPosition()[0]); yh[nHits] = double(trkHit->getPosition()[1]); zh[nHits] = float(trkHit->getPosition()[2]); - ph[nHits] = float(atan2(yh[nHits],xh[nHits])); - rh[nHits] = float(sqrt(xh[nHits]*xh[nHits]+yh[nHits]*yh[nHits])); - + ph[nHits] = float(atan2(yh[nHits], xh[nHits])); + rh[nHits] = float(sqrt(xh[nHits] * xh[nHits] + yh[nHits] * yh[nHits])); + float rR = hit->getResolutionRPhi(); float rZ = hit->getResolutionZ(); - wrh[nHits] = double(1.0/(rR*rR)); - wzh[nHits] = 1.0/(rZ*rZ); - - + wrh[nHits] = double(1.0 / (rR * rR)); + wzh[nHits] = 1.0 / (rZ * rZ); + int NPT = nHits + 1; - - // SJA:FIXME the newtonian part is giving crazy results for FTD so just use iopt 2 for simply attaching hits + + // SJA:FIXME the newtonian part is giving crazy results for FTD so just use iopt 2 for simply attaching hits // using SIT and VXD doesn't seem to give any problems, so make it a function parameter and let the caller decide // int iopt = 3; - - float chi2RPhi = 0 ; - float chi2Z = 0 ; - - - int error = _fastfitter->fastHelixFit(NPT, xh, yh, rh, ph, wrh, zh, wzh,iopt, par, epar, chi2RPhi, chi2Z); - par[3] = par[3]*par[0]/fabs(par[0]); - - + + float chi2RPhi = 0; + float chi2Z = 0; + + int error = _fastfitter->fastHelixFit(NPT, xh, yh, rh, ph, wrh, zh, wzh, iopt, par, epar, chi2RPhi, chi2Z); + par[3] = par[3] * par[0] / fabs(par[0]); + float omega = par[0]; float tanlambda = par[1]; float phi0 = par[2]; @@ -3017,36 +2853,38 @@ int SiliconTracking_MarlinTrk::AttachHitToTrack(TrackExtended * trackAR, Tracker float z0 = par[4]; float chi2 = FLT_MAX; int ndf = INT_MAX; - + if (NPT == 3) { - chi2 = chi2RPhi*_chi2WRPhiTriplet+chi2Z*_chi2WZTriplet; + chi2 = chi2RPhi * _chi2WRPhiTriplet + chi2Z * _chi2WZTriplet; } if (NPT == 4) { - chi2 = chi2RPhi*_chi2WRPhiQuartet+chi2Z*_chi2WZQuartet; + chi2 = chi2RPhi * _chi2WRPhiQuartet + chi2Z * _chi2WZQuartet; } if (NPT > 4) { - chi2 = chi2RPhi*_chi2WRPhiSeptet+chi2Z*_chi2WZSeptet; + chi2 = chi2RPhi * _chi2WRPhiSeptet + chi2Z * _chi2WZSeptet; } - ndf = 2*NPT-5; - - - if ( error == 0 && chi2/float(ndf) < _chi2FitCut ) { + ndf = 2 * NPT - 5; + + if (error == 0 && chi2 / float(ndf) < _chi2FitCut) { trackAR->addTrackerHitExtended(hit); - hit->addTrackExtended( trackAR ); - trackAR->setChi2( chi2 ); - trackAR->setOmega( omega ); - trackAR->setTanLambda( tanlambda ); - trackAR->setD0( d0 ); - trackAR->setZ0( z0 ); - trackAR->setPhi( phi0 ); - trackAR->setNDF( ndf ); - trackAR->setCovMatrix( epar ); + hit->addTrackExtended(trackAR); + trackAR->setChi2(chi2); + trackAR->setOmega(omega); + trackAR->setTanLambda(tanlambda); + trackAR->setD0(d0); + trackAR->setZ0(z0); + trackAR->setPhi(phi0); + trackAR->setNDF(ndf); + trackAR->setCovMatrix(epar); attached = 1; - streamlog_out(DEBUG1) << "Attachement succeeded chi2/float(ndf) = " << chi2/float(ndf) << " cut = " << _chi2FitCut << " chi2RPhi = " << chi2RPhi << " chi2Z = " << chi2Z << " error = " << error << std::endl; + streamlog_out(DEBUG1) << "Attachement succeeded chi2/float(ndf) = " << chi2 / float(ndf) + << " cut = " << _chi2FitCut << " chi2RPhi = " << chi2RPhi << " chi2Z = " << chi2Z + << " error = " << error << std::endl; } else { - streamlog_out(DEBUG1) << "Attachement failed chi2/float(ndf) = " << chi2/float(ndf) << " cut = " << _chi2FitCut << " chi2RPhi = " << chi2RPhi << " chi2Z = " << chi2Z << " error = " << error << std::endl; + streamlog_out(DEBUG1) << "Attachement failed chi2/float(ndf) = " << chi2 / float(ndf) << " cut = " << _chi2FitCut + << " chi2RPhi = " << chi2RPhi << " chi2Z = " << chi2Z << " error = " << error << std::endl; } - + delete[] xh; delete[] yh; delete[] zh; @@ -3054,137 +2892,129 @@ int SiliconTracking_MarlinTrk::AttachHitToTrack(TrackExtended * trackAR, Tracker delete[] wzh; delete[] rh; delete[] ph; - + return attached; - - } void SiliconTracking_MarlinTrk::FinalRefit(LCCollectionVec* trk_col, LCCollectionVec* /*rel_col*/) { - + int nTracks = int(_trackImplVec.size()); - - int nSiSegments = 0; + + int nSiSegments = 0; float eTot = 0.; float pxTot = 0.; float pyTot = 0.; float pzTot = 0.; - - for (int iTrk=0;iTrkgetTrackerHitExtendedVec(); - + int nHits = int(hitVec.size()); - - if( nHits >= _minimalHits) { + + if (nHits >= _minimalHits) { // int * lh = new int[nHits]; std::vector lh; lh.resize(nHits); - - for (int i=0; igetD0(); float z0 = trackAR->getZ0(); float omega = trackAR->getOmega(); float tanlambda = trackAR->getTanLambda(); float phi0 = trackAR->getPhi(); - - HelixClass * helix = new HelixClass(); - helix->Initialize_Canonical(phi0, d0, z0, omega, - tanlambda, _bField); - - + + HelixClass* helix = new HelixClass(); + helix->Initialize_Canonical(phi0, d0, z0, omega, tanlambda, _bField); + // get the point of closest approach to the reference point - // here it is implicitly assumed that the reference point is the origin + // here it is implicitly assumed that the reference point is the origin float Pos[3]; - Pos[0] = -d0*sin(phi0); - Pos[1] = d0*cos(phi0); + Pos[0] = -d0 * sin(phi0); + Pos[1] = d0 * cos(phi0); Pos[2] = z0; - - + // at this point is is possible to have hits from the same layer ... - // so a check is made to ensure that the hit with the smallest distance to the - // current helix hypothosis is used, the other hit has lh set to 0 - + // so a check is made to ensure that the hit with the smallest distance to the + // current helix hypothosis is used, the other hit has lh set to 0 + // start loop over the hits to - for (int ihit=0;ihitgetTrackerHit(); - + TrackerHit* trkHit = hitVec[ihit]->getTrackerHit(); + int det = getDetectorID(trkHit); - - if (det == lcio::ILDDetID::VXD || det == lcio::ILDDetID::FTD || det == lcio::ILDDetID::SIT) { // only accept VXD, FTD or SIT - - + + if (det == lcio::ILDDetID::VXD || det == lcio::ILDDetID::FTD || + det == lcio::ILDDetID::SIT) { // only accept VXD, FTD or SIT + // int layer = getLayerID(trkHit); // int moduleIndex = getModuleID(trkHit); - - // start a double loop over the hits which have already been checked - for (int lhit=0;lhitgetTrackerHit(); - - + TrackerHit* trkHitS = hitVec[lhit]->getTrackerHit(); + // int layerS = getLayerID(trkHitS); // int moduleIndexS = getModuleID(trkHitS); - - // SJA:FIXME: check to see if allowing no hits in the same sensor vs no hits in the same layer works + + // SJA:FIXME: check to see if allowing no hits in the same sensor vs no hits in the same layer works // if they are on the same layer and the previously checked hits has been declared good for fitting // if ((trkHitS->getType() == trkHit->getType()) && (lh[lhit] == 1)) { // check if the hits have the same layer and petal number // hitVec[ihit]-> // if ((layer == layerS) && (moduleIndex==moduleIndexS) && (lh[lhit] == 1)) { - if ( (trkHit->getCellID0() == trkHitS->getCellID0()) && (lh[lhit] == 1)) { - - // get the position of the hits + if ((trkHit->getCellID0() == trkHitS->getCellID0()) && (lh[lhit] == 1)) { + + // get the position of the hits float xP[3]; float xPS[3]; - for (int iC=0;iC<3;++iC) { + for (int iC = 0; iC < 3; ++iC) { xP[iC] = float(trkHit->getPosition()[iC]); xPS[iC] = float(trkHitS->getPosition()[iC]); } - + // get the intersection of the helix with the either the cylinder or plane containing the hit float Point[6]; float PointS[6]; - + if (det == lcio::ILDDetID::FTD) { // float time = - helix->getPointInZ(xP[2],Pos,Point); + helix->getPointInZ(xP[2], Pos, Point); // float time = - helix->getPointInZ(xPS[2],Pos,PointS); + helix->getPointInZ(xPS[2], Pos, PointS); } else { - float RAD = sqrt(xP[0]*xP[0]+xP[1]*xP[1]); - float RADS = sqrt(xPS[0]*xPS[0]+xPS[1]*xPS[1]); + float RAD = sqrt(xP[0] * xP[0] + xP[1] * xP[1]); + float RADS = sqrt(xPS[0] * xPS[0] + xPS[1] * xPS[1]); // float time = - helix->getPointOnCircle(RAD,Pos,Point); + helix->getPointOnCircle(RAD, Pos, Point); // float time = - helix->getPointOnCircle(RADS,Pos,PointS); - + helix->getPointOnCircle(RADS, Pos, PointS); } - + float DIST = 0; float DISTS = 0; - + // get the euclidean distance between the hit and the point of intersection - for (int iC=0;iC<3;++iC) { - DIST += (Point[iC]-xP[iC])*(Point[iC]-xP[iC]); - DISTS += (PointS[iC]-xPS[iC])*(PointS[iC]-xPS[iC]); + for (int iC = 0; iC < 3; ++iC) { + DIST += (Point[iC] - xP[iC]) * (Point[iC] - xP[iC]); + DISTS += (PointS[iC] - xPS[iC]) * (PointS[iC] - xPS[iC]); } if (DIST < DISTS) { lh[lhit] = 0; - } - else { + } else { lh[ihit] = 0; } break; @@ -3192,426 +3022,383 @@ void SiliconTracking_MarlinTrk::FinalRefit(LCCollectionVec* trk_col, LCCollectio } } } - + delete helix; - + EVENT::TrackerHitVec trkHits; EVENT::TrackerHitVec trkHits_used_inFit; - + int nFit = 0; - for (int i=0; igetTrackerHit(); + TrackerHit* trkHit = hitVec[i]->getTrackerHit(); nFit++; - if(trkHit) { - trkHits.push_back(trkHit); - } - else{ - throw EVENT::Exception( std::string("SiliconTracking_MarlinTrk::FinalRefit: TrackerHit pointer == NULL ") ) ; + if (trkHit) { + trkHits.push_back(trkHit); + } else { + throw EVENT::Exception(std::string("SiliconTracking_MarlinTrk::FinalRefit: TrackerHit pointer == NULL ")); } - } - else { // reject hit - // SJA:FIXME missuse of type find a better way to signal rejected hits + } else { // reject hit + // SJA:FIXME missuse of type find a better way to signal rejected hits hitVec[i]->setType(int(0)); } } - - - - if( trkHits.size() < 3 ) { - streamlog_out(DEBUG3) << "SiliconTracking_MarlinTrk::FinalRefit: Cannot fit less than 3 hits. Number of hits = " << trkHits.size() << std::endl; - continue ; + + if (trkHits.size() < 3) { + streamlog_out(DEBUG3) + << "SiliconTracking_MarlinTrk::FinalRefit: Cannot fit less than 3 hits. Number of hits = " + << trkHits.size() << std::endl; + continue; } - - TrackImpl* Track = new TrackImpl ; - + + TrackImpl* Track = new TrackImpl; + // setup initial dummy covariance matrix EVENT::FloatVec covMatrix; covMatrix.resize(15); - - for (unsigned icov = 0; icov > r2_values; + + covMatrix[0] = (_initialTrackError_d0); // sigma_d0^2 + covMatrix[2] = (_initialTrackError_phi0); // sigma_phi0^2 + covMatrix[5] = (_initialTrackError_omega); // sigma_omega^2 + covMatrix[9] = (_initialTrackError_z0); // sigma_z0^2 + covMatrix[14] = (_initialTrackError_tanL); // sigma_tanl^2 + + std::vector> r2_values; r2_values.reserve(trkHits.size()); - - for (TrackerHitVec::iterator it=trkHits.begin(); it!=trkHits.end(); ++it) { + + for (TrackerHitVec::iterator it = trkHits.begin(); it != trkHits.end(); ++it) { EVENT::TrackerHit* h = *it; - float r2 = h->getPosition()[0]*h->getPosition()[0]+h->getPosition()[1]*h->getPosition()[1]; + float r2 = h->getPosition()[0] * h->getPosition()[0] + h->getPosition()[1] * h->getPosition()[1]; r2_values.push_back(std::make_pair(r2, *it)); } - - sort(r2_values.begin(),r2_values.end()); - + + sort(r2_values.begin(), r2_values.end()); + trkHits.clear(); trkHits.reserve(r2_values.size()); - - for (std::vector< std::pair >::iterator it=r2_values.begin(); it!=r2_values.end(); ++it) { + + for (std::vector>::iterator it = r2_values.begin(); it != r2_values.end(); + ++it) { trkHits.push_back(it->second); } - -// for (unsigned ihit_indx=0 ; ihit_indx < trkHits.size(); ++ihit_indx) { -// std::cout << " trk hit " << *trkHits[ihit_indx] << std::endl; -// } - - + + // for (unsigned ihit_indx=0 ; ihit_indx < trkHits.size(); ++ihit_indx) { + // std::cout << " trk hit " << *trkHits[ihit_indx] << std::endl; + // } + bool fit_backwards = IMarlinTrack::backward; - + MarlinTrk::IMarlinTrack* marlinTrk = _trksystem->createTrack(); - - + int error = 0; - + try { - - error = MarlinTrk::createFinalisedLCIOTrack(marlinTrk, trkHits, Track, fit_backwards, covMatrix, _bField, _maxChi2PerHit); - + + error = MarlinTrk::createFinalisedLCIOTrack(marlinTrk, trkHits, Track, fit_backwards, covMatrix, _bField, + _maxChi2PerHit); + } catch (...) { - + // delete Track; // delete marlinTrk; - - throw ; - + + throw; } - - + #ifdef MARLINTRK_DIAGNOSTICS_ON - if ( error != IMarlinTrack::success && _runMarlinTrkDiagnostics ) { - void * dcv = _trksystem->getDiagnositicsPointer(); + if (error != IMarlinTrack::success && _runMarlinTrkDiagnostics) { + void* dcv = _trksystem->getDiagnositicsPointer(); DiagnosticsController* dc = static_cast(dcv); dc->skip_current_track(); - } + } #endif - - - std::vector > hits_in_fit ; - std::vector > outliers ; - std::vector all_hits; + + std::vector> hits_in_fit; + std::vector> outliers; + std::vector all_hits; all_hits.reserve(300); - + marlinTrk->getHitsInFit(hits_in_fit); - - for ( unsigned ihit = 0; ihit < hits_in_fit.size(); ++ihit) { + + for (unsigned ihit = 0; ihit < hits_in_fit.size(); ++ihit) { all_hits.push_back(hits_in_fit[ihit].first); } - - UTIL::BitField64 cellID_encoder( lcio::LCTrackerCellID::encoding_string() ) ; - + + UTIL::BitField64 cellID_encoder(lcio::LCTrackerCellID::encoding_string()); + MarlinTrk::addHitNumbersToTrack(Track, all_hits, true, cellID_encoder); - + marlinTrk->getOutliers(outliers); - - for ( unsigned ihit = 0; ihit < outliers.size(); ++ihit) { + + for (unsigned ihit = 0; ihit < outliers.size(); ++ihit) { all_hits.push_back(outliers[ihit].first); } - + MarlinTrk::addHitNumbersToTrack(Track, all_hits, false, cellID_encoder); - + delete marlinTrk; - - - int nhits_in_vxd = Track->subdetectorHitNumbers()[ 2 * lcio::ILDDetID::VXD - 2 ]; - int nhits_in_ftd = Track->subdetectorHitNumbers()[ 2 * lcio::ILDDetID::FTD - 2 ]; - int nhits_in_sit = Track->subdetectorHitNumbers()[ 2 * lcio::ILDDetID::SIT - 2 ]; - - streamlog_out( DEBUG2 ) << " Hit numbers for Track "<< Track->id() << ": " - << " vxd hits = " << nhits_in_vxd - << " ftd hits = " << nhits_in_ftd - << " sit hits = " << nhits_in_sit - << std::endl; - - if (nhits_in_vxd > 0) Track->setTypeBit( lcio::ILDDetID::VXD ) ; - if (nhits_in_ftd > 0) Track->setTypeBit( lcio::ILDDetID::FTD ) ; - if (nhits_in_sit > 0) Track->setTypeBit( lcio::ILDDetID::SIT ) ; - - - - if( error != IMarlinTrack::success ) { - + + int nhits_in_vxd = Track->subdetectorHitNumbers()[2 * lcio::ILDDetID::VXD - 2]; + int nhits_in_ftd = Track->subdetectorHitNumbers()[2 * lcio::ILDDetID::FTD - 2]; + int nhits_in_sit = Track->subdetectorHitNumbers()[2 * lcio::ILDDetID::SIT - 2]; + + streamlog_out(DEBUG2) << " Hit numbers for Track " << Track->id() << ": " + << " vxd hits = " << nhits_in_vxd << " ftd hits = " << nhits_in_ftd + << " sit hits = " << nhits_in_sit << std::endl; + + if (nhits_in_vxd > 0) + Track->setTypeBit(lcio::ILDDetID::VXD); + if (nhits_in_ftd > 0) + Track->setTypeBit(lcio::ILDDetID::FTD); + if (nhits_in_sit > 0) + Track->setTypeBit(lcio::ILDDetID::SIT); + + if (error != IMarlinTrack::success) { + delete Track; - streamlog_out(DEBUG3) << "SiliconTracking_MarlinTrk::FinalRefit: Track fit failed with error code " << error << " track dropped. Number of hits = "<< trkHits.size() << std::endl; - continue ; + streamlog_out(DEBUG3) << "SiliconTracking_MarlinTrk::FinalRefit: Track fit failed with error code " << error + << " track dropped. Number of hits = " << trkHits.size() << std::endl; + continue; } - - if( Track->getNdf() < 0) { + + if (Track->getNdf() < 0) { delete Track; - streamlog_out(DEBUG3) << "SiliconTracking_MarlinTrk::FinalRefit: Track fit returns " << Track->getNdf() << " degress of freedom track dropped. Number of hits = "<< trkHits.size() << std::endl; - continue ; + streamlog_out(DEBUG3) << "SiliconTracking_MarlinTrk::FinalRefit: Track fit returns " << Track->getNdf() + << " degress of freedom track dropped. Number of hits = " << trkHits.size() << std::endl; + continue; } - - trk_col->addElement(Track); - + + trk_col->addElement(Track); + const TrackState* trkStateIP = Track->getTrackState(lcio::TrackState::AtIP); - + if (trkStateIP == 0) { - streamlog_out(DEBUG3) << "SiliconTracking_MarlinTrk::FinalRefit: Track fit returns " << Track->getNdf() << " degress of freedom track dropped. Number of hits = "<< trkHits.size() << std::endl; - throw EVENT::Exception( std::string("SiliconTracking_MarlinTrk::FinalRefit: trkStateIP pointer == NULL ") ) ; + streamlog_out(DEBUG3) << "SiliconTracking_MarlinTrk::FinalRefit: Track fit returns " << Track->getNdf() + << " degress of freedom track dropped. Number of hits = " << trkHits.size() << std::endl; + throw EVENT::Exception(std::string("SiliconTracking_MarlinTrk::FinalRefit: trkStateIP pointer == NULL ")); } - + // note trackAR which is of type TrackExtended, only takes fits set for ref point = 0,0,0 trackAR->setOmega(trkStateIP->getOmega()); trackAR->setTanLambda(trkStateIP->getTanLambda()); trackAR->setPhi(trkStateIP->getPhi()); trackAR->setD0(trkStateIP->getD0()); trackAR->setZ0(trkStateIP->getZ0()); - + float cov[15]; - - for (int i = 0 ; i<15 ; ++i) { + + for (int i = 0; i < 15; ++i) { cov[i] = trkStateIP->getCovMatrix().operator[](i); } - + trackAR->setCovMatrix(cov); trackAR->setChi2(Track->getChi2()); trackAR->setNDF(Track->getNdf()); - + nSiSegments++; - + HelixClass helix_final; - - helix_final.Initialize_Canonical(trkStateIP->getPhi(),trkStateIP->getD0(),trkStateIP->getZ0(),trkStateIP->getOmega(),trkStateIP->getTanLambda(),_bField); - + + helix_final.Initialize_Canonical(trkStateIP->getPhi(), trkStateIP->getD0(), trkStateIP->getZ0(), + trkStateIP->getOmega(), trkStateIP->getTanLambda(), _bField); + float trkPx = helix_final.getMomentum()[0]; float trkPy = helix_final.getMomentum()[1]; float trkPz = helix_final.getMomentum()[2]; - float trkP = sqrt(trkPx*trkPx+trkPy*trkPy+trkPz*trkPz); + float trkP = sqrt(trkPx * trkPx + trkPy * trkPy + trkPz * trkPz); eTot += trkP; pxTot += trkPx; pyTot += trkPy; pzTot += trkPz; - } } - - streamlog_out(DEBUG4) << "SiliconTracking_MarlinTrk -> run " << _nRun - << " event " << _nEvt << std::endl; + + streamlog_out(DEBUG4) << "SiliconTracking_MarlinTrk -> run " << _nRun << " event " << _nEvt << std::endl; streamlog_out(DEBUG4) << "Number of Si tracks = " << nSiSegments << std::endl; - streamlog_out(DEBUG4) << "Total 4-momentum of Si tracks : E = " << eTot - << " Px = " << pxTot - << " Py = " << pyTot - << " Pz = " << pzTot << std::endl; - - + streamlog_out(DEBUG4) << "Total 4-momentum of Si tracks : E = " << eTot << " Px = " << pxTot << " Py = " << pyTot + << " Pz = " << pzTot << std::endl; } +void SiliconTracking_MarlinTrk::setupGeom(const dd4hep::Detector& theDetector) { + + double bFieldVec[3]; + theDetector.field().magneticField({0, 0, 0}, bFieldVec); // get the magnetic field vector from DD4hep + _bField = bFieldVec[2] / dd4hep::tesla; // z component at (0,0,0) -void SiliconTracking_MarlinTrk::setupGeom( const dd4hep::Detector& theDetector){ - - double bFieldVec[3]; - theDetector.field().magneticField({0,0,0},bFieldVec); // get the magnetic field vector from DD4hep - _bField = bFieldVec[2]/dd4hep::tesla; // z component at (0,0,0) - //-- VXD Parameters-- - _nLayersVTX = 0 ; - - try{ - - streamlog_out( DEBUG9 ) << " filling VXD parameters " << std::endl ; - + _nLayersVTX = 0; + + try { + + streamlog_out(DEBUG9) << " filling VXD parameters " << std::endl; + dd4hep::DetElement vtxDE = theDetector.detector("VXD"); dd4hep::rec::ZPlanarData* vtx = vtxDE.extension(); - _nLayersVTX=vtx->layers.size(); - - } - catch( std::runtime_error& e){ - - streamlog_out( DEBUG9 ) << " ### VXD detector Not Present in Compact File" << std::endl ; + _nLayersVTX = vtx->layers.size(); + + } catch (std::runtime_error& e) { + + streamlog_out(DEBUG9) << " ### VXD detector Not Present in Compact File" << std::endl; } - - //-- SIT Parameters-- - _nLayersSIT = 0 ; + _nLayersSIT = 0; - try{ + try { - streamlog_out( DEBUG9 ) << " filling SIT parameters " << std::endl ; + streamlog_out(DEBUG9) << " filling SIT parameters " << std::endl; dd4hep::DetElement sitDE = theDetector.detector("SIT"); dd4hep::rec::ZPlanarData* sit = sitDE.extension(); - _nLayersSIT=sit->layers.size(); - } - catch( std::runtime_error& e){ - - streamlog_out( DEBUG9 ) << " ### SIT detector Not Present in Compact File " << std::endl ; + _nLayersSIT = sit->layers.size(); + } catch (std::runtime_error& e) { + streamlog_out(DEBUG9) << " ### SIT detector Not Present in Compact File " << std::endl; } - //-- FTD Parameters-- - _petalBasedFTDWithOverlaps = false; + _petalBasedFTDWithOverlaps = false; _nlayersFTD = 0; - try{ + try { - streamlog_out( DEBUG9 ) << " filling FTD parameters " << std::endl ; + streamlog_out(DEBUG9) << " filling FTD parameters " << std::endl; dd4hep::DetElement ftdDE = theDetector.detector("FTD"); dd4hep::rec::ZDiskPetalsData* ftd = ftdDE.extension(); _nlayersFTD = ftd->layers.size(); - for (unsigned int disk=0; disk < _nlayersFTD; ++disk) { + for (unsigned int disk = 0; disk < _nlayersFTD; ++disk) { - _zLayerFTD.push_back( ftd->layers[ disk ].zPosition + ftd->layers[ disk ].zOffsetSensitive ) ; - _zLayerFTD.push_back( ftd->layers[ disk ].zPosition - ftd->layers[ disk ].zOffsetSensitive ) ; + _zLayerFTD.push_back(ftd->layers[disk].zPosition + ftd->layers[disk].zOffsetSensitive); + _zLayerFTD.push_back(ftd->layers[disk].zPosition - ftd->layers[disk].zOffsetSensitive); _petalBasedFTDWithOverlaps = true; - } - // SJA: Here we increase the size of _nlayersFTD as we are treating the - _nlayersFTD =_zLayerFTD.size() ; + // SJA: Here we increase the size of _nlayersFTD as we are treating the + _nlayersFTD = _zLayerFTD.size(); - } - catch( std::runtime_error& e){ - - streamlog_out( DEBUG9 ) << " ### FTD detector Not Present in Compact File" << std::endl ; + } catch (std::runtime_error& e) { - } - - + streamlog_out(DEBUG9) << " ### FTD detector Not Present in Compact File" << std::endl; + } } -void SiliconTracking_MarlinTrk::TracksWithNHitsContainer::clear() -{ - for (std::vector< TrackExtendedVec >::iterator trackVecIter = _tracksNHits.begin(); - trackVecIter < _tracksNHits.end(); trackVecIter++) - { - for (TrackExtendedVec::iterator trackIter = trackVecIter->begin(); - trackIter < trackVecIter->end(); trackIter++) - { +void SiliconTracking_MarlinTrk::TracksWithNHitsContainer::clear() { + for (std::vector::iterator trackVecIter = _tracksNHits.begin(); trackVecIter < _tracksNHits.end(); + trackVecIter++) { + for (TrackExtendedVec::iterator trackIter = trackVecIter->begin(); trackIter < trackVecIter->end(); trackIter++) { delete *trackIter; } - + trackVecIter->clear(); } } +void SiliconTracking_MarlinTrk::drawEvent() { -void SiliconTracking_MarlinTrk::drawEvent(){ - LCCollection* colMCP = GetCollection(_current_event, _colNameMCParticles); - - if ( colMCP ) { - - for (int iMCP=0; iMCPgetNumberOfElements() ; ++iMCP) { - - MCParticle* mcp = dynamic_cast(colMCP->getElementAt(iMCP)) ; - - float pmag2 = mcp->getMomentum()[0]*mcp->getMomentum()[0] - + mcp->getMomentum()[1]*mcp->getMomentum()[1] + mcp->getMomentum()[2]*mcp->getMomentum()[2]; - - if ( fabs(mcp->getCharge())>0.01 && pmag2 > _MCpThreshold*_MCpThreshold) { - - + + if (colMCP) { + + for (int iMCP = 0; iMCP < colMCP->getNumberOfElements(); ++iMCP) { + + MCParticle* mcp = dynamic_cast(colMCP->getElementAt(iMCP)); + + float pmag2 = mcp->getMomentum()[0] * mcp->getMomentum()[0] + mcp->getMomentum()[1] * mcp->getMomentum()[1] + + mcp->getMomentum()[2] * mcp->getMomentum()[2]; + + if (fabs(mcp->getCharge()) > 0.01 && pmag2 > _MCpThreshold * _MCpThreshold) { + int layer = 0; - int size = 1 ; - - float helix_max_r = sqrt( mcp->getEndpoint()[0]*mcp->getEndpoint()[0] + mcp->getEndpoint()[1]*mcp->getEndpoint()[1]); - + int size = 1; + + float helix_max_r = + sqrt(mcp->getEndpoint()[0] * mcp->getEndpoint()[0] + mcp->getEndpoint()[1] * mcp->getEndpoint()[1]); + helix_max_r = _helix_max_r; - + float helix_max_z = fabs(mcp->getEndpoint()[2]); - + MarlinCED::add_layer_description(_colNameMCParticles, layer); - - MarlinCED::drawHelix( _bField , mcp->getCharge(), mcp->getVertex()[0], mcp->getVertex()[1], mcp->getVertex()[2], - mcp->getMomentum()[0], mcp->getMomentum()[1], mcp->getMomentum()[2], layer , size , _colours[iMCP%_colours.size()] , - 0.0, helix_max_r , - helix_max_z, mcp->id() ) ; - - } - + + MarlinCED::drawHelix(_bField, mcp->getCharge(), mcp->getVertex()[0], mcp->getVertex()[1], mcp->getVertex()[2], + mcp->getMomentum()[0], mcp->getMomentum()[1], mcp->getMomentum()[2], layer, size, + _colours[iMCP % _colours.size()], 0.0, helix_max_r, helix_max_z, mcp->id()); + } } - - } - - - - for( unsigned iCol=0; iCol<_colTrackerHits.size(); iCol++){ - + + for (unsigned iCol = 0; iCol < _colTrackerHits.size(); iCol++) { + LCCollection* trackerHitCol = _colTrackerHits[iCol]; - - - int color = 0xee0044 ; - - int layer = iCol+1; + + int color = 0xee0044; + + int layer = iCol + 1; int marker = 1; - int size = 10; - - if( _colNamesTrackerHits.find(trackerHitCol) == _colNamesTrackerHits.end()) { - - throw EVENT::Exception( std::string(" Tracker Hit Collection does not have its name registered in _colNamesTrackerHits") ) ; - + int size = 10; + + if (_colNamesTrackerHits.find(trackerHitCol) == _colNamesTrackerHits.end()) { + + throw EVENT::Exception( + std::string(" Tracker Hit Collection does not have its name registered in _colNamesTrackerHits")); } - + const std::string& colName = _colNamesTrackerHits[trackerHitCol]; - - - //ced_describe_layer( colName.c_str() ,layer); - MarlinCED::add_layer_description(colName, layer); - - if(trackerHitCol){ - // draw a marker at hit position - LCTypedVector v( trackerHitCol ) ; - MarlinCED::drawObjectsWithPosition( v.begin(), v.end() , marker, size , color, layer) ; - } - + + // ced_describe_layer( colName.c_str() ,layer); + MarlinCED::add_layer_description(colName, layer); + + if (trackerHitCol) { + // draw a marker at hit position + LCTypedVector v(trackerHitCol); + MarlinCED::drawObjectsWithPosition(v.begin(), v.end(), marker, size, color, layer); + } } - + int wait_for_keyboard = 1; //++++++++++++++++++++++++++++++++++++ - MarlinCED::draw(this, wait_for_keyboard ); + MarlinCED::draw(this, wait_for_keyboard); //++++++++++++++++++++++++++++++++++++ - } +LCCollection* SiliconTracking_MarlinTrk::GetCollection(LCEvent* evt, std::string colName) { -LCCollection* SiliconTracking_MarlinTrk::GetCollection( LCEvent * evt, std::string colName ){ - LCCollection* col = NULL; - + try { - col = evt->getCollection( colName.c_str() ) ; - streamlog_out( DEBUG4 ) << " --> " << colName.c_str() << " collection found, number of elements = " << col->getNumberOfElements() << std::endl; - } - catch(DataNotAvailableException &e) { - streamlog_out( DEBUG4 ) << " --> " << colName.c_str() << " collection absent" << std::endl; + col = evt->getCollection(colName.c_str()); + streamlog_out(DEBUG4) << " --> " << colName.c_str() + << " collection found, number of elements = " << col->getNumberOfElements() << std::endl; + } catch (DataNotAvailableException& e) { + streamlog_out(DEBUG4) << " --> " << colName.c_str() << " collection absent" << std::endl; } - - return col; - + + return col; } -LCRelationNavigator* SiliconTracking_MarlinTrk::GetRelations(LCEvent * evt , std::string RelName ) { - - LCRelationNavigator* nav = NULL ; +LCRelationNavigator* SiliconTracking_MarlinTrk::GetRelations(LCEvent* evt, std::string RelName) { + + LCRelationNavigator* nav = NULL; LCCollection* col = NULL; - - try{ - - col = evt->getCollection( RelName.c_str() ); - nav = new LCRelationNavigator( col ); - streamlog_out( DEBUG4 ) << " --> " << RelName << " track relation collection found, number of elements = " << col->getNumberOfElements() << std::endl; - } - catch(DataNotAvailableException &e){ - streamlog_out( ERROR ) << " --> " << RelName.c_str() << " track relation collection absent" << std::endl; - } - - return nav; - -} + try { + col = evt->getCollection(RelName.c_str()); + nav = new LCRelationNavigator(col); + streamlog_out(DEBUG4) << " --> " << RelName + << " track relation collection found, number of elements = " << col->getNumberOfElements() + << std::endl; + } catch (DataNotAvailableException& e) { + streamlog_out(ERROR) << " --> " << RelName.c_str() << " track relation collection absent" << std::endl; + } + return nav; +} diff --git a/source/Refitting/src/TrackSubsetProcessor.cc b/source/Refitting/src/TrackSubsetProcessor.cc index 7953611..1d894c9 100644 --- a/source/Refitting/src/TrackSubsetProcessor.cc +++ b/source/Refitting/src/TrackSubsetProcessor.cc @@ -1,564 +1,473 @@ #include "TrackSubsetProcessor.h" - -#include -#include "EVENT/TrackerHit.h" #include "EVENT/Track.h" +#include "EVENT/TrackerHit.h" #include "IMPL/LCCollectionVec.h" #include "IMPL/LCFlagImpl.h" #include "IMPL/TrackImpl.h" +#include #include "UTIL/LCTrackerConf.h" #include - -#include "marlin/VerbosityLevels.h" #include "marlin/Global.h" +#include "marlin/VerbosityLevels.h" -#include "KiTrack/SubsetSimple.h" #include "KiTrack/SubsetHopfieldNN.h" +#include "KiTrack/SubsetSimple.h" #include "Tools/Fitter.h" #include "Tools/KiTrackMarlinTools.h" #include "MarlinTrk/MarlinTrkUtils.h" -#include "DD4hep/Detector.h" #include "DD4hep/DD4hepUnits.h" +#include "DD4hep/Detector.h" - -using namespace lcio ; -using namespace marlin ; +using namespace lcio; +using namespace marlin; using namespace KiTrack; +TrackSubsetProcessor aTrackSubsetProcessor; +TrackSubsetProcessor::TrackSubsetProcessor() : Processor("TrackSubsetProcessor") { -TrackSubsetProcessor aTrackSubsetProcessor ; + // modify processor description + _description = "TrackSubsetProcessor takes tracks from multiple sources and outputs them (or modified versions, or a " + "subset of them) as one track collection."; + // register steering parameters: name, description, class-variable, default value -TrackSubsetProcessor::TrackSubsetProcessor() : Processor("TrackSubsetProcessor") { + std::vector trackInputColNamesDefault; + trackInputColNamesDefault.push_back("ForwardTracks"); + trackInputColNamesDefault.push_back("SiTracks"); - // modify processor description - _description = "TrackSubsetProcessor takes tracks from multiple sources and outputs them (or modified versions, or a subset of them) as one track collection." ; + registerProcessorParameter("TrackInputCollections", "A vector of the input track collections", _trackInputColNames, + trackInputColNamesDefault); + registerOutputCollection(LCIO::TRACK, "TrackOutputCollection", "Name of the output track collection", + _trackOutputColName, std::string("SubsetTracks")); + + // For fitting: + + registerProcessorParameter("MultipleScatteringOn", "Use MultipleScattering in Fit", _MSOn, bool(true)); + + registerProcessorParameter("EnergyLossOn", "Use Energy Loss in Fit", _ElossOn, bool(true)); - // register steering parameters: name, description, class-variable, default value - - - std::vector< std::string > trackInputColNamesDefault; - trackInputColNamesDefault.push_back( "ForwardTracks" ); - trackInputColNamesDefault.push_back( "SiTracks" ); - - registerProcessorParameter( "TrackInputCollections" , - "A vector of the input track collections" , - _trackInputColNames , - trackInputColNamesDefault ); - - - registerOutputCollection(LCIO::TRACK, - "TrackOutputCollection", - "Name of the output track collection", - _trackOutputColName, - std::string("SubsetTracks")); - - - //For fitting: - - registerProcessorParameter("MultipleScatteringOn", - "Use MultipleScattering in Fit", - _MSOn, - bool(true)); - - registerProcessorParameter("EnergyLossOn", - "Use Energy Loss in Fit", - _ElossOn, - bool(true)); - registerProcessorParameter("RemoveShortTracks", "Remove short tracks from the list that have a longer track sharing the same hits", - _removeShortTracks, - bool(false)); - - registerProcessorParameter("SmoothOn", - "Smooth All Measurement Sites in Fit", - _SmoothOn, - bool(false)); - registerProcessorParameter( "InitialTrackErrorD0", - "Value used for the initial d0 variance of the trackfit", - _initialTrackError_d0, - float(1.e6)); - - registerProcessorParameter( "InitialTrackErrorPhi0", - "Value used for the initial phi0 variance of the trackfit", - _initialTrackError_phi0, - float(1.e2)); - - registerProcessorParameter( "InitialTrackErrorOmega", - "Value used for the initial omega variance of the trackfit", - _initialTrackError_omega, - float(1.e-4)); - - registerProcessorParameter( "InitialTrackErrorZ0", - "Value used for the initial z0 variance of the trackfit", - _initialTrackError_z0, - float(1.e6)); - - registerProcessorParameter( "InitialTrackErrorTanL", - "Value used for the initial tanL variance of the trackfit", - _initialTrackError_tanL, - float(1.e2)); - - - registerProcessorParameter( "MaxChi2PerHit", - "Maximum Chi-squared value allowed when assigning a hit to a track", - _maxChi2PerHit, - double(1.e2)); + _removeShortTracks, bool(false)); + + registerProcessorParameter("SmoothOn", "Smooth All Measurement Sites in Fit", _SmoothOn, bool(false)); + registerProcessorParameter("InitialTrackErrorD0", "Value used for the initial d0 variance of the trackfit", + _initialTrackError_d0, float(1.e6)); + + registerProcessorParameter("InitialTrackErrorPhi0", "Value used for the initial phi0 variance of the trackfit", + _initialTrackError_phi0, float(1.e2)); + + registerProcessorParameter("InitialTrackErrorOmega", "Value used for the initial omega variance of the trackfit", + _initialTrackError_omega, float(1.e-4)); + + registerProcessorParameter("InitialTrackErrorZ0", "Value used for the initial z0 variance of the trackfit", + _initialTrackError_z0, float(1.e6)); + + registerProcessorParameter("InitialTrackErrorTanL", "Value used for the initial tanL variance of the trackfit", + _initialTrackError_tanL, float(1.e2)); + + registerProcessorParameter("MaxChi2PerHit", "Maximum Chi-squared value allowed when assigning a hit to a track", + _maxChi2PerHit, double(1.e2)); ///////////////////////////////////////////////////////////////////////////////// - - + registerProcessorParameter("Omega", "The parameter omega for the HNN. Controls the influence of the quality indicator.", - _omega, - double( 0.75 ) ); - - - registerProcessorParameter( "TrackSystemName", - "Name of the track fitting system to be used (KalTest, DDKalTest, aidaTT, ... )", - _trkSystemName, - std::string("KalTest") ); + _omega, double(0.75)); + registerProcessorParameter("TrackSystemName", + "Name of the track fitting system to be used (KalTest, DDKalTest, aidaTT, ... )", + _trkSystemName, std::string("KalTest")); } +void TrackSubsetProcessor::init() { - -void TrackSubsetProcessor::init() { - - streamlog_out(DEBUG) << " init called " << std::endl ; + streamlog_out(DEBUG) << " init called " << std::endl; // usually a good idea to - printParameters() ; + printParameters(); + + _nRun = 0; + _nEvt = 0; - _nRun = 0 ; - _nEvt = 0 ; - - /**********************************************************************************************/ /* Initialise the MarlinTrkSystem, needed by the tracks for fitting */ /**********************************************************************************************/ - + dd4hep::Detector& theDetector = dd4hep::Detector::getInstance(); - double bFieldVec[3]; - theDetector.field().magneticField({0,0,0},bFieldVec); // get the magnetic field vector from DD4hep - _bField = bFieldVec[2]/dd4hep::tesla; // z component at (0,0,0) - + double bFieldVec[3]; + theDetector.field().magneticField({0, 0, 0}, bFieldVec); // get the magnetic field vector from DD4hep + _bField = bFieldVec[2] / dd4hep::tesla; // z component at (0,0,0) + // set upt the geometry - _trkSystem = MarlinTrk::Factory::createMarlinTrkSystem( _trkSystemName , 0 , "" ) ; - - - if( _trkSystem == 0 ){ - - throw EVENT::Exception( std::string(" Cannot initialize MarlinTrkSystem of Type: ") + _trkSystemName ) ; - } + _trkSystem = MarlinTrk::Factory::createMarlinTrkSystem(_trkSystemName, 0, ""); - - // set the options - _trkSystem->setOption( MarlinTrk::IMarlinTrkSystem::CFG::useQMS, _MSOn ) ; //multiple scattering - _trkSystem->setOption( MarlinTrk::IMarlinTrkSystem::CFG::usedEdx, _ElossOn) ; //energy loss - _trkSystem->setOption( MarlinTrk::IMarlinTrkSystem::CFG::useSmoothing, _SmoothOn) ; //smoothing - - // initialise the tracking system - _trkSystem->init() ; - + if (_trkSystem == 0) { -} + throw EVENT::Exception(std::string(" Cannot initialize MarlinTrkSystem of Type: ") + _trkSystemName); + } + // set the options + _trkSystem->setOption(MarlinTrk::IMarlinTrkSystem::CFG::useQMS, _MSOn); // multiple scattering + _trkSystem->setOption(MarlinTrk::IMarlinTrkSystem::CFG::usedEdx, _ElossOn); // energy loss + _trkSystem->setOption(MarlinTrk::IMarlinTrkSystem::CFG::useSmoothing, _SmoothOn); // smoothing -void TrackSubsetProcessor::processRunHeader( LCRunHeader* ) { + // initialise the tracking system + _trkSystem->init(); +} - _nRun++ ; -} +void TrackSubsetProcessor::processRunHeader(LCRunHeader*) { _nRun++; } +void TrackSubsetProcessor::processEvent(LCEvent* evt) { + // set the correct configuration for the tracking system for this event + MarlinTrk::TrkSysConfig mson(_trkSystem, _MSOn); + MarlinTrk::TrkSysConfig elosson(_trkSystem, _ElossOn); + MarlinTrk::TrkSysConfig smoothon(_trkSystem, _SmoothOn); -void TrackSubsetProcessor::processEvent( LCEvent * evt ) { + std::vector tracks; - - // set the correct configuration for the tracking system for this event - MarlinTrk::TrkSysConfig< MarlinTrk::IMarlinTrkSystem::CFG::useQMS> mson( _trkSystem, _MSOn ) ; - MarlinTrk::TrkSysConfig< MarlinTrk::IMarlinTrkSystem::CFG::usedEdx> elosson( _trkSystem,_ElossOn) ; - MarlinTrk::TrkSysConfig< MarlinTrk::IMarlinTrkSystem::CFG::useSmoothing> smoothon( _trkSystem,_SmoothOn) ; - - std::vector< Track* > tracks; - /**********************************************************************************************/ /* Read in the collections */ /**********************************************************************************************/ - - streamlog_out( DEBUG4 ) << "Try to load " << _trackInputColNames.size() << " input track collections\n"; - + + streamlog_out(DEBUG4) << "Try to load " << _trackInputColNames.size() << " input track collections\n"; + unsigned nTrackLoaded = 0; - - for( unsigned i=0; i < _trackInputColNames.size(); i++ ){ - - + + for (unsigned i = 0; i < _trackInputColNames.size(); i++) { + LCCollection* col = NULL; - + try { - - col = evt->getCollection( _trackInputColNames[i] ) ; - - } - catch(DataNotAvailableException &e) { - - streamlog_out( DEBUG7 ) << "Collection " << _trackInputColNames[i] << " is not available!\n"; + + col = evt->getCollection(_trackInputColNames[i]); + + } catch (DataNotAvailableException& e) { + + streamlog_out(DEBUG7) << "Collection " << _trackInputColNames[i] << " is not available!\n"; continue; - } - - - if( col != NULL ){ - + + if (col != NULL) { + int nTracks = col->getNumberOfElements(); - streamlog_out( DEBUG4 ) << "Load track input collection " << _trackInputColNames[i] << " with " << nTracks << " tracks\n"; - - - for(int j=0; j< nTracks ; j++){ - - Track* track = dynamic_cast( col->getElementAt( j ) ) ; - - if( track == NULL ){ - - streamlog_out( ERROR ) << "Entry " << j << " from collection " << _trackInputColNames[i] << " couldn't get casted to a Track*\n"; - - } - else{ - - tracks.push_back( track ); + streamlog_out(DEBUG4) << "Load track input collection " << _trackInputColNames[i] << " with " << nTracks + << " tracks\n"; + + for (int j = 0; j < nTracks; j++) { + + Track* track = dynamic_cast(col->getElementAt(j)); + + if (track == NULL) { + + streamlog_out(ERROR) << "Entry " << j << " from collection " << _trackInputColNames[i] + << " couldn't get casted to a Track*\n"; + + } else { + + tracks.push_back(track); nTrackLoaded++; - - } - - } - - } - else streamlog_out( ERROR ) << "track input collection " << _trackInputColNames[i] << " could not be found!!!\n"; - + } + } + + } else + streamlog_out(ERROR) << "track input collection " << _trackInputColNames[i] << " could not be found!!!\n"; } - - - streamlog_out( DEBUG4 ) << "Loaded all in all " << nTrackLoaded << " tracks, which will now get further processed\n"; - - - - - - + + streamlog_out(DEBUG4) << "Loaded all in all " << nTrackLoaded << " tracks, which will now get further processed\n"; + /**********************************************************************************************/ /* Make sure that all tracks are compatible: find the best subset */ /**********************************************************************************************/ - streamlog_out( DEBUG4 ) << "Find the best subset of tracks using the Hopfield Neural Network \n"; - - TrackQI trackQI( _trkSystem ); - - streamlog_out( DEBUG3 ) << "The tracks and their qualities (and their hits ): \n"; - - for( unsigned i=0; i < tracks.size(); i++ ){ - - double qi = trackQI( tracks[i] ); - streamlog_out( DEBUG3 ) << tracks[i] << "\t" << qi << "( "; - std::vector< TrackerHit* > hits = tracks[i]->getTrackerHits(); - - std::sort( hits.begin(), hits.end(), KiTrackMarlin::compare_TrackerHit_z ); - - for( unsigned j=0; j hits = tracks[i]->getTrackerHits(); + + std::sort(hits.begin(), hits.end(), KiTrackMarlin::compare_TrackerHit_z); + + for (unsigned j = 0; j < hits.size(); j++) { + + streamlog_out(DEBUG3) << hits[j] << " "; double x = hits[j]->getPosition()[0]; double y = hits[j]->getPosition()[1]; double z = hits[j]->getPosition()[2]; - - streamlog_out(DEBUG2)<< "[" << x << "," << y << "," << z << "]"; - + + streamlog_out(DEBUG2) << "[" << x << "," << y << "," << z << "]"; } - - streamlog_out( DEBUG3 ) << ")\n"; - + + streamlog_out(DEBUG3) << ")\n"; } - - std::vector< EVENT::Track*> finalTracks ; - finalTracks.reserve( tracks.size() ) ; - if( _removeShortTracks ){ - - removeShortTracks( tracks ) ; - } + std::vector finalTracks; + finalTracks.reserve(tracks.size()); + + if (_removeShortTracks) { + + removeShortTracks(tracks); + } // copy all non-zero track pointers to final tracks list - for( unsigned i=0,N=tracks.size() ; i subset; -// SubsetSimple< Track* > subset; - - subset.add( finalTracks ); - subset.setOmega( _omega ); - subset.calculateBestSet( comp, trackQI ); - - std::vector< Track* > accepted = subset.getAccepted(); - std::vector< Track* > rejected = subset.getRejected(); - - streamlog_out( DEBUG3 ) << "\tThe accepted tracks: \n"; - for( unsigned i=0; i < accepted.size(); i++ ){ - - streamlog_out( DEBUG3 ) << accepted[i] << "\n"; - + SubsetHopfieldNN subset; + // SubsetSimple< Track* > subset; + + subset.add(finalTracks); + subset.setOmega(_omega); + subset.calculateBestSet(comp, trackQI); + + std::vector accepted = subset.getAccepted(); + std::vector rejected = subset.getRejected(); + + streamlog_out(DEBUG3) << "\tThe accepted tracks: \n"; + for (unsigned i = 0; i < accepted.size(); i++) { + + streamlog_out(DEBUG3) << accepted[i] << "\n"; } - - streamlog_out( DEBUG3 ) << "\tThe rejected tracks: \n"; - for( unsigned i=0; i < rejected.size(); i++ ){ - - streamlog_out( DEBUG3 ) << rejected[i] << "\n"; - + + streamlog_out(DEBUG3) << "\tThe rejected tracks: \n"; + for (unsigned i = 0; i < rejected.size(); i++) { + + streamlog_out(DEBUG3) << rejected[i] << "\n"; } - + /**********************************************************************************************/ /* Save the tracks to a collection (make new TrackImpls from them) */ /**********************************************************************************************/ - streamlog_out( DEBUG4 ) << "Fitting and saving of the tracks\n"; - - LCCollectionVec* trackVec = new LCCollectionVec( LCIO::TRACK ) ; - + streamlog_out(DEBUG4) << "Fitting and saving of the tracks\n"; + + LCCollectionVec* trackVec = new LCCollectionVec(LCIO::TRACK); + // if we want to point back to the hits we need to set the flag - LCFlagImpl trkFlag(0) ; - trkFlag.setBit( LCIO::TRBIT_HITS ) ; - trackVec->setFlag( trkFlag.getFlag() ) ; - - for( unsigned i=0; i < accepted.size(); i++ ){ - - + LCFlagImpl trkFlag(0); + trkFlag.setBit(LCIO::TRBIT_HITS); + trackVec->setFlag(trkFlag.getFlag()); + + for (unsigned i = 0; i < accepted.size(); i++) { + TrackImpl* trackImpl = new TrackImpl(); - - Track* track = accepted[i]; - std::vector< TrackerHit* > trackerHits = track->getTrackerHits(); + Track* track = accepted[i]; + std::vector trackerHits = track->getTrackerHits(); // setup initial dummy covariance matrix EVENT::FloatVec covMatrix; covMatrix.resize(15); - - for (unsigned icov = 0; icov > r2_values; + + covMatrix[0] = (_initialTrackError_d0); // sigma_d0^2 + covMatrix[2] = (_initialTrackError_phi0); // sigma_phi0^2 + covMatrix[5] = (_initialTrackError_omega); // sigma_omega^2 + covMatrix[9] = (_initialTrackError_z0); // sigma_z0^2 + covMatrix[14] = (_initialTrackError_tanL); // sigma_tanl^2 + + std::vector> r2_values; r2_values.reserve(trackerHits.size()); - - for (TrackerHitVec::iterator it=trackerHits.begin(); it!=trackerHits.end(); ++it) { + + for (TrackerHitVec::iterator it = trackerHits.begin(); it != trackerHits.end(); ++it) { EVENT::TrackerHit* h = *it; - float r2 = h->getPosition()[0]*h->getPosition()[0]+h->getPosition()[1]*h->getPosition()[1]; + float r2 = h->getPosition()[0] * h->getPosition()[0] + h->getPosition()[1] * h->getPosition()[1]; r2_values.push_back(std::make_pair(r2, *it)); } - - sort(r2_values.begin(),r2_values.end()); - + + sort(r2_values.begin(), r2_values.end()); + trackerHits.clear(); trackerHits.reserve(r2_values.size()); - - for (std::vector< std::pair >::iterator it=r2_values.begin(); it!=r2_values.end(); ++it) { + + for (std::vector>::iterator it = r2_values.begin(); it != r2_values.end(); + ++it) { trackerHits.push_back(it->second); } bool fit_backwards = MarlinTrk::IMarlinTrack::backward; - + MarlinTrk::IMarlinTrack* marlinTrk = _trkSystem->createTrack(); - - + int error = 0; - + try { - - error = MarlinTrk::createFinalisedLCIOTrack(marlinTrk, trackerHits, trackImpl, fit_backwards, covMatrix, _bField, _maxChi2PerHit); - + + error = MarlinTrk::createFinalisedLCIOTrack(marlinTrk, trackerHits, trackImpl, fit_backwards, covMatrix, _bField, + _maxChi2PerHit); + } catch (...) { - + // delete Track; // delete marlinTrk; - - throw ; - + + throw; } - - // Add hit numbers - - std::vector > hits_in_fit ; - std::vector > outliers ; + + // Add hit numbers + + std::vector> hits_in_fit; + std::vector> outliers; std::vector all_hits; all_hits.reserve(300); - + marlinTrk->getHitsInFit(hits_in_fit); - - for ( unsigned ihit = 0; ihit < hits_in_fit.size(); ++ihit) { + + for (unsigned ihit = 0; ihit < hits_in_fit.size(); ++ihit) { all_hits.push_back(hits_in_fit[ihit].first); } - - UTIL::BitField64 cellID_encoder( lcio::LCTrackerCellID::encoding_string() ) ; - + + UTIL::BitField64 cellID_encoder(lcio::LCTrackerCellID::encoding_string()); + MarlinTrk::addHitNumbersToTrack(trackImpl, all_hits, true, cellID_encoder); - + marlinTrk->getOutliers(outliers); - - for ( unsigned ihit = 0; ihit < outliers.size(); ++ihit) { + + for (unsigned ihit = 0; ihit < outliers.size(); ++ihit) { all_hits.push_back(outliers[ihit].first); } - + MarlinTrk::addHitNumbersToTrack(trackImpl, all_hits, false, cellID_encoder); - + delete marlinTrk; - - - - if( error != MarlinTrk::IMarlinTrack::success ) { + + if (error != MarlinTrk::IMarlinTrack::success) { delete trackImpl; - streamlog_out(DEBUG3) << "TrackSubsetProcessor:: Track fit failed with error code " << error << " track dropped. Number of hits = "<< trackerHits.size() << std::endl; - continue ; + streamlog_out(DEBUG3) << "TrackSubsetProcessor:: Track fit failed with error code " << error + << " track dropped. Number of hits = " << trackerHits.size() << std::endl; + continue; } - - if( trackImpl->getNdf() < 0) { + + if (trackImpl->getNdf() < 0) { delete trackImpl; - streamlog_out(DEBUG3) << "TrackSubsetProcessor:: Track fit returns " << trackImpl->getNdf() << " degress of freedom track dropped. Number of hits = "<< trackerHits.size() << std::endl; - continue ; + streamlog_out(DEBUG3) << "TrackSubsetProcessor:: Track fit returns " << trackImpl->getNdf() + << " degress of freedom track dropped. Number of hits = " << trackerHits.size() + << std::endl; + continue; } - - trackVec->addElement(trackImpl); - - - -// try{ -// -// Fitter fitter( trackImpl , _trkSystem ); -// -// TrackStateImpl* trkStateIP = new TrackStateImpl( fitter.getTrackState( lcio::TrackState::AtIP ) ) ; -// trackImpl->setChi2( fitter.getChi2( lcio::TrackState::AtIP ) ); -// trackImpl->setNdf( fitter.getNdf( lcio::TrackState::AtIP ) ); -// trkStateIP->setLocation( TrackState::AtIP ); -// trackImpl->addTrackState( trkStateIP ); -// -// trackVec->addElement(trackImpl); -// -// } -// catch( FitterException e ){ -// -// delete trackImpl; -// -// streamlog_out( ERROR ) << "TrackImpl nr " << i << " rejected, because fit failed: " << e.what() << "\n"; -// continue; -// -// } - - - } + trackVec->addElement(trackImpl); -streamlog_out( DEBUG4 ) << "Saving " << trackVec->getNumberOfElements() << " tracks\n"; + // try{ + // + // Fitter fitter( trackImpl , _trkSystem ); + // + // TrackStateImpl* trkStateIP = new TrackStateImpl( fitter.getTrackState( lcio::TrackState::AtIP ) ) ; + // trackImpl->setChi2( fitter.getChi2( lcio::TrackState::AtIP ) ); + // trackImpl->setNdf( fitter.getNdf( lcio::TrackState::AtIP ) ); + // trkStateIP->setLocation( TrackState::AtIP ); + // trackImpl->addTrackState( trkStateIP ); + // + // trackVec->addElement(trackImpl); + // + // } + // catch( FitterException e ){ + // + // delete trackImpl; + // + // streamlog_out( ERROR ) << "TrackImpl nr " << i << " rejected, because fit failed: " << e.what() << "\n"; + // continue; + // + // } + } - evt->addCollection( trackVec , _trackOutputColName) ; + streamlog_out(DEBUG4) << "Saving " << trackVec->getNumberOfElements() << " tracks\n"; + evt->addCollection(trackVec, _trackOutputColName); - _nEvt ++ ; - -} - -namespace{ - struct TrackLength{ - bool operator()(const Track* trk0, const Track* trk1 ){ - return trk0->getTrackerHits().size() > trk1->getTrackerHits().size() ; - } - } ; + _nEvt++; } +namespace { +struct TrackLength { + bool operator()(const Track* trk0, const Track* trk1) { + return trk0->getTrackerHits().size() > trk1->getTrackerHits().size(); + } +}; +} // namespace -void TrackSubsetProcessor::removeShortTracks( std::vector< EVENT::Track*>& tracks ){ - +void TrackSubsetProcessor::removeShortTracks(std::vector& tracks) { - std::sort( tracks.begin() , tracks.end() , ::TrackLength() ) ; + std::sort(tracks.begin(), tracks.end(), ::TrackLength()); - unsigned nRemovedTracks = 0 ; + unsigned nRemovedTracks = 0; - for( unsigned i=0,N=tracks.size() ; igetTrackerHits() ; + const TrackerHitVec& hits0 = trk0->getTrackerHits(); - streamlog_out( DEBUG3 ) << " removeShortTracs() compare track0 with " << hits0.size() << " hits " << std::endl ; - streamlog_out( DEBUG ) << *trk0 << std::endl ; + streamlog_out(DEBUG3) << " removeShortTracs() compare track0 with " << hits0.size() << " hits " << std::endl; + streamlog_out(DEBUG) << *trk0 << std::endl; - for( unsigned j=i+1,M=tracks.size() ; jgetTrackerHits() ; + if (trk1 == 0) + continue; - streamlog_out( DEBUG3 ) << " to track1 with " << hits1.size() << " hits " << std::endl ; - streamlog_out( DEBUG ) << *trk1 << std::endl ; + const TrackerHitVec& hits1 = trk1->getTrackerHits(); - unsigned nShared = 0 ; - for( unsigned k=0,L=hits0.size() ; kgetTrackerHits().size() << " hits from list !!! " << std::endl ; - tracks[j] = 0 ; + if (nShared == hits1.size()) { + ++nRemovedTracks; + streamlog_out(DEBUG3) << " removing track1 with " << tracks[j]->getTrackerHits().size() + << " hits from list !!! " << std::endl; + tracks[j] = 0; } } } - streamlog_out( DEBUG4 ) << " removeShortTracks() removed " << nRemovedTracks << " tracks from " << tracks.size() << std::endl ; + streamlog_out(DEBUG4) << " removeShortTracks() removed " << nRemovedTracks << " tracks from " << tracks.size() + << std::endl; } - -void TrackSubsetProcessor::check( LCEvent* ) { - // nothing to check here - could be used to fill checkplots in reconstruction processor +void TrackSubsetProcessor::check(LCEvent*) { + // nothing to check here - could be used to fill checkplots in reconstruction processor } +void TrackSubsetProcessor::end() { -void TrackSubsetProcessor::end(){ - - // std::cout << "TrackSubsetProcessor::end() " << name() - // << " processed " << _nEvt << " events in " << _nRun << " runs " - // << std::endl ; - + // std::cout << "TrackSubsetProcessor::end() " << name() + // << " processed " << _nEvt << " events in " << _nRun << " runs " + // << std::endl ; } - - - - - diff --git a/source/Refitting/src/TruthTrackFinder.cc b/source/Refitting/src/TruthTrackFinder.cc index ed0fbb4..c4d4cdf 100644 --- a/source/Refitting/src/TruthTrackFinder.cc +++ b/source/Refitting/src/TruthTrackFinder.cc @@ -4,56 +4,55 @@ #include -#include "MarlinTrk/MarlinTrkUtils.h" -#include "MarlinTrk/HelixTrack.h" +#include "MarlinTrk/Factory.h" #include "MarlinTrk/HelixFit.h" +#include "MarlinTrk/HelixTrack.h" #include "MarlinTrk/IMarlinTrack.h" -#include "MarlinTrk/Factory.h" -#include "MarlinTrk/MarlinTrkDiagnostics.h" #include "MarlinTrk/IMarlinTrkSystem.h" +#include "MarlinTrk/MarlinTrkDiagnostics.h" +#include "MarlinTrk/MarlinTrkUtils.h" #include +#include +#include #include +#include #include -#include -#include -#include #include -#include +#include -#include #include "UTIL/LCTrackerConf.h" #include +#include #include -#include "DD4hep/Detector.h" #include "DD4hep/DD4hepUnits.h" +#include "DD4hep/Detector.h" #include "DDRec/SurfaceManager.h" -#include #include +#include -#include "marlin/ProcessorEventSeeder.h" #include "marlin/Global.h" +#include "marlin/ProcessorEventSeeder.h" #include "CLHEP/Vector/TwoVector.h" #include #include -#include #include -#include -#include -#include #include +#include +#include +#include +#include -using namespace lcio ; -using namespace marlin ; -using namespace std ; -using namespace dd4hep ; -using namespace AIDA ; - +using namespace lcio; +using namespace marlin; +using namespace std; +using namespace dd4hep; +using namespace AIDA; TruthTrackFinder aTruthTrackFinder; @@ -61,85 +60,70 @@ TruthTrackFinder aTruthTrackFinder; This code performs a true pattern recognition by looping over all MC particles and adding all hits associated to them onto a track. This is then fitted and output. - + */ TruthTrackFinder::TruthTrackFinder() : Processor("TruthTrackFinder") { - - // modify processor description - _description = "TruthTrackFinder builds tracks out of all hits associated to an MC particle" ; - + // modify processor description + _description = "TruthTrackFinder builds tracks out of all hits associated to an MC particle"; + // Input collections - mc particles, tracker hits and the relationships between them - - std::vector inputTrackerHitCollections; - inputTrackerHitCollections.push_back(std::string("VXDTrackerHits")); - - registerInputCollections( LCIO::TRACKERHITPLANE, - "TrackerHitCollectionNames" , - "Name of the TrackerHit input collections" , - m_inputTrackerHitCollections , - inputTrackerHitCollections ) ; - - std::vector inputTrackerHitRelationCollections; - inputTrackerHitRelationCollections.push_back(std::string("VXDTrackerHitRelations")); - - registerInputCollections( LCIO::LCRELATION, - "SimTrackerHitRelCollectionNames", - "Name of TrackerHit SimTrackHit relation collections", - m_inputTrackerHitRelationCollections, - inputTrackerHitRelationCollections ); - - registerInputCollection( LCIO::MCPARTICLE, - "MCParticleCollectionName", - "Name of the MCParticle input collection", - m_inputParticleCollection, - std::string("MCParticle")); + + std::vector inputTrackerHitCollections; + inputTrackerHitCollections.push_back(std::string("VXDTrackerHits")); + + registerInputCollections(LCIO::TRACKERHITPLANE, "TrackerHitCollectionNames", + "Name of the TrackerHit input collections", m_inputTrackerHitCollections, + inputTrackerHitCollections); + + std::vector inputTrackerHitRelationCollections; + inputTrackerHitRelationCollections.push_back(std::string("VXDTrackerHitRelations")); + + registerInputCollections(LCIO::LCRELATION, "SimTrackerHitRelCollectionNames", + "Name of TrackerHit SimTrackHit relation collections", m_inputTrackerHitRelationCollections, + inputTrackerHitRelationCollections); + + registerInputCollection(LCIO::MCPARTICLE, "MCParticleCollectionName", "Name of the MCParticle input collection", + m_inputParticleCollection, std::string("MCParticle")); // Output collections - tracks and relations - registerOutputCollection( LCIO::TRACK, - "SiTrackCollectionName", - "Silicon track Collection Name", - m_outputTrackCollection, - std::string("SiTracks")); - - registerOutputCollection( LCIO::LCRELATION, - "SiTrackRelationCollectionName", - "Silicon track particle relation Collection Name", - m_outputTrackRelationCollection, + registerOutputCollection(LCIO::TRACK, "SiTrackCollectionName", "Silicon track Collection Name", + m_outputTrackCollection, std::string("SiTracks")); + + registerOutputCollection(LCIO::LCRELATION, "SiTrackRelationCollectionName", + "Silicon track particle relation Collection Name", m_outputTrackRelationCollection, std::string("SiTrackRelations")); - + // Flag parameters - registerProcessorParameter( "UseTruthInPrefit", - "If true use the truth information to initialise the helical prefit, otherwise use prefit by fitting 3 hits", - m_useTruthInPrefit, - bool(false)); - - registerProcessorParameter( "FitForward", - "If true fit 'forward' (go forward + smooth back adding last two hits with Kalman FIlter steps), otherwise fit backward ", - m_fitForward, - bool(false)); - - + registerProcessorParameter( + "UseTruthInPrefit", + "If true use the truth information to initialise the helical prefit, otherwise use prefit by fitting 3 hits", + m_useTruthInPrefit, bool(false)); + + registerProcessorParameter("FitForward", + "If true fit 'forward' (go forward + smooth back adding last two hits with Kalman FIlter " + "steps), otherwise fit backward ", + m_fitForward, bool(false)); } void TruthTrackFinder::init() { - - // Print the initial parameters - printParameters() ; - - // Reset counters - m_runNumber = 0 ; - m_eventNumber = 0 ; - m_fitFails = 0; - + + // Print the initial parameters + printParameters(); + + // Reset counters + m_runNumber = 0; + m_eventNumber = 0; + m_fitFails = 0; + // Set up the track fit factory - trackFactory = MarlinTrk::Factory::createMarlinTrkSystem( "DDKalTest" , nullptr , "" ) ; - trackFactory->setOption( MarlinTrk::IMarlinTrkSystem::CFG::useQMS, true) ; - trackFactory->setOption( MarlinTrk::IMarlinTrkSystem::CFG::usedEdx, true) ; - trackFactory->setOption( MarlinTrk::IMarlinTrkSystem::CFG::useSmoothing, false) ; - trackFactory->init() ; + trackFactory = MarlinTrk::Factory::createMarlinTrkSystem("DDKalTest", nullptr, ""); + trackFactory->setOption(MarlinTrk::IMarlinTrkSystem::CFG::useQMS, true); + trackFactory->setOption(MarlinTrk::IMarlinTrkSystem::CFG::usedEdx, true); + trackFactory->setOption(MarlinTrk::IMarlinTrkSystem::CFG::useSmoothing, false); + trackFactory->init(); // Put default values for track fitting m_initialTrackError_d0 = 1.e6; @@ -148,343 +132,354 @@ void TruthTrackFinder::init() { m_initialTrackError_z0 = 1.e6; m_initialTrackError_tanL = 1.e2; m_maxChi2perHit = 1.e2; - + // Get the magnetic field dd4hep::Detector& lcdd = dd4hep::Detector::getInstance(); - const double position[3]={0,0,0}; // position to calculate magnetic field at (the origin in this case) - double magneticFieldVector[3]={0,0,0}; // initialise object to hold magnetic field - lcdd.field().magneticField(position,magneticFieldVector); // get the magnetic field vector from DD4hep - m_magneticField = magneticFieldVector[2]/dd4hep::tesla; // z component at (0,0,0) - - // Register this process - Global::EVENTSEEDER->registerProcessor(this); - - //Initialize CellID encoder - m_encoder = new UTIL::BitField64(lcio::LCTrackerCellID::encoding_string()); - -} + const double position[3] = {0, 0, 0}; // position to calculate magnetic field at (the origin in this case) + double magneticFieldVector[3] = {0, 0, 0}; // initialise object to hold magnetic field + lcdd.field().magneticField(position, magneticFieldVector); // get the magnetic field vector from DD4hep + m_magneticField = magneticFieldVector[2] / dd4hep::tesla; // z component at (0,0,0) + // Register this process + Global::EVENTSEEDER->registerProcessor(this); -void TruthTrackFinder::processRunHeader( LCRunHeader* ) { - m_runNumber++ ; + // Initialize CellID encoder + m_encoder = new UTIL::BitField64(lcio::LCTrackerCellID::encoding_string()); } -void TruthTrackFinder::processEvent( LCEvent* evt ) { +void TruthTrackFinder::processRunHeader(LCRunHeader*) { m_runNumber++; } - // set the correct configuration for the tracking system for this event - MarlinTrk::TrkSysConfig< MarlinTrk::IMarlinTrkSystem::CFG::useQMS> mson( trackFactory, true ) ; - MarlinTrk::TrkSysConfig< MarlinTrk::IMarlinTrkSystem::CFG::usedEdx> elosson( trackFactory, true ) ; - MarlinTrk::TrkSysConfig< MarlinTrk::IMarlinTrkSystem::CFG::useSmoothing> smoothon( trackFactory, false ) ; +void TruthTrackFinder::processEvent(LCEvent* evt) { + + // set the correct configuration for the tracking system for this event + MarlinTrk::TrkSysConfig mson(trackFactory, true); + MarlinTrk::TrkSysConfig elosson(trackFactory, true); + MarlinTrk::TrkSysConfig smoothon(trackFactory, false); // Get the collection of MC particles - LCCollection* particleCollection = 0 ; - getCollection(particleCollection, m_inputParticleCollection, evt); if(particleCollection == 0) return; - - // Make objects to hold all of the tracker hit, simulated hit and relation collections - std::vector trackerHitCollections; - std::vector trackerHitRelationCollections; - std::vector relations; - - // Loop over each input collection and get the data - for(unsigned int collection=0; collection trackerHitCollections; + std::vector trackerHitRelationCollections; + std::vector relations; + + // Loop over each input collection and get the data + for (unsigned int collection = 0; collection < m_inputTrackerHitCollections.size(); collection++) { + + // Get the collection of tracker hits + LCCollection* trackerHitCollection = 0; + getCollection(trackerHitCollection, m_inputTrackerHitCollections[collection], evt); + if (trackerHitCollection == 0) + continue; + trackerHitCollections.push_back(trackerHitCollection); + + // Get the collection of tracker hit relations + LCCollection* trackerHitRelationCollection = 0; + getCollection(trackerHitRelationCollection, m_inputTrackerHitRelationCollections[collection], evt); + trackerHitRelationCollections.push_back(trackerHitRelationCollection); + + // Create the relations navigator + LCRelationNavigator* relation = new LCRelationNavigator(trackerHitRelationCollection); + relations.push_back(relation); + } + // Make the output track collection - LCCollectionVec* trackCollection = new LCCollectionVec( LCIO::TRACK ) ; - + LCCollectionVec* trackCollection = new LCCollectionVec(LCIO::TRACK); + // Enable the track collection to point back to hits - LCFlagImpl trkFlag(0) ; - trkFlag.setBit( LCIO::TRBIT_HITS ) ; - trackCollection->setFlag( trkFlag.getFlag() ) ; - + LCFlagImpl trkFlag(0); + trkFlag.setBit(LCIO::TRBIT_HITS); + trackCollection->setFlag(trkFlag.getFlag()); + // Make the output particle to track relation collection - LCCollectionVec* trackRelationCollection = new LCCollectionVec( LCIO::LCRELATION ) ; - - /* - Now for each MC particle we want the list of hits belonging to it. The most - efficient way is to loop over all hits once, and store the pointers in a - map, with the key a pointer to the MC particle. We can then loop over each - MC particle at the end and get all of the hits, before making a track. - */ - + LCCollectionVec* trackRelationCollection = new LCCollectionVec(LCIO::LCRELATION); + + /* +Now for each MC particle we want the list of hits belonging to it. The most +efficient way is to loop over all hits once, and store the pointers in a +map, with the key a pointer to the MC particle. We can then loop over each +MC particle at the end and get all of the hits, before making a track. +*/ + // Make the container - std::map > particleHits; - - // Loop over all input collections - for(unsigned int collection=0; collectiongetNumberOfElements(); - for(int itHit=0;itHit( trackerHitCollections[collection]->getElementAt(itHit) ) ; - - // Get the related simulated hit(s) - const LCObjectVec& simHitVector = relations[collection]->getRelatedToObjects( hit ); - - // Take the first hit only (this should be changed? Yes - loop over all related simHits and add an entry for each mcparticle so that this hit is in each fit) - SimTrackerHit* simHit = dynamic_cast(simHitVector.at(0)); - - // If the hit was produced by a secondary which was not saved to the MCParticle collection - if(simHit->isProducedBySecondary()) - continue; - - // Get the particle belonging to that hit - MCParticle* particle = simHit->getMCParticle(); - - // Push back the element into the container - particleHits[particle].push_back(hit); - - } - } - + std::map> particleHits; + + // Loop over all input collections + for (unsigned int collection = 0; collection < trackerHitCollections.size(); collection++) { + // Loop over tracker hits + int nHits = trackerHitCollections[collection]->getNumberOfElements(); + for (int itHit = 0; itHit < nHits; itHit++) { + + // Get the hit + TrackerHitPlane* hit = dynamic_cast(trackerHitCollections[collection]->getElementAt(itHit)); + + // Get the related simulated hit(s) + const LCObjectVec& simHitVector = relations[collection]->getRelatedToObjects(hit); + + // Take the first hit only (this should be changed? Yes - loop over all related simHits and add an entry for each + // mcparticle so that this hit is in each fit) + SimTrackerHit* simHit = dynamic_cast(simHitVector.at(0)); + + // If the hit was produced by a secondary which was not saved to the MCParticle collection + if (simHit->isProducedBySecondary()) + continue; + + // Get the particle belonging to that hit + MCParticle* particle = simHit->getMCParticle(); + + // Push back the element into the container + particleHits[particle].push_back(hit); + } + } + // Now loop over all particles and get the list of hits int nParticles = particleCollection->getNumberOfElements(); - for(int itP=0;itP( particleCollection->getElementAt(itP) ) ; - + MCParticle* mcParticle = static_cast(particleCollection->getElementAt(itP)); + // Get the vector of hits from the container - if(particleHits.count(mcParticle) == 0) continue; + if (particleHits.count(mcParticle) == 0) + continue; std::vector trackHits = particleHits[mcParticle]; // Only make tracks with 3 or more hits - if(trackHits.size() < 3) continue; - - // Sort the hits from smaller to larger radius - std::sort(trackHits.begin(),trackHits.end(),sort_by_radius); + if (trackHits.size() < 3) + continue; + + // Sort the hits from smaller to larger radius + std::sort(trackHits.begin(), trackHits.end(), sort_by_radius); // Remove the hits on the same layers (removing those with higher R) EVENT::TrackerHitVec trackFilteredByRHits; removeHitsSameLayer(trackHits, trackFilteredByRHits); - if(trackFilteredByRHits.size() < 3) continue; + if (trackFilteredByRHits.size() < 3) + continue; /* - Fit - this gets complicated. + Fit - this gets complicated. Need to pass a series of objects, including some initial states, covariance matrix etc. Set these up, then call the fit. */ - - // Make the track object and relations object - LCRelationImpl* relationTrack = new LCRelationImpl; - TrackImpl* track = new TrackImpl ; + + // Make the track object and relations object + LCRelationImpl* relationTrack = new LCRelationImpl; + TrackImpl* track = new TrackImpl; // IMarlinTrk used to fit track - IMarlinTrk interface to separete pattern recogition from fit implementation MarlinTrk::IMarlinTrack* marlinTrack = trackFactory->createTrack(); MarlinTrk::IMarlinTrack* marlinTrackZSort = trackFactory->createTrack(); - // Save a vector of the hits to be used (why is this not attached to the track directly?? MarlinTrkUtils to be updated?) + // Save a vector of the hits to be used (why is this not attached to the track directly?? MarlinTrkUtils to be + // updated?) EVENT::TrackerHitVec trackfitHits; - for(unsigned int itTrackHit=0;itTrackHitgetVertex(), mcParticle->getMomentum(), mcParticle->getCharge(), m_magneticField); - - double trueD0 = helix.getD0() ; - double truePhi = helix.getPhi0() ; - double trueOmega = helix.getOmega() ; - double trueZ0 = helix.getZ0() ; - double trueTanLambda = helix.getTanLambda() ; + double trueD0 = helix.getD0(); + double truePhi = helix.getPhi0(); + double trueOmega = helix.getOmega(); + double trueZ0 = helix.getZ0(); + double trueTanLambda = helix.getTanLambda(); - //float ref_point[3] = { 0., 0., 0. }; - helix.moveRefPoint(trackfitHits.at(0)->getPosition()[0], trackfitHits.at(0)->getPosition()[1], trackfitHits.at(0)->getPosition()[2]); - float ref_point[3] = {float(helix.getRefPointX()),float(helix.getRefPointY()),float(helix.getRefPointZ())} ; - TrackStateImpl* trkState = new TrackStateImpl(TrackState::AtIP, trueD0, truePhi, trueOmega, trueZ0, trueTanLambda, covMatrix, ref_point); + // float ref_point[3] = { 0., 0., 0. }; + helix.moveRefPoint(trackfitHits.at(0)->getPosition()[0], trackfitHits.at(0)->getPosition()[1], + trackfitHits.at(0)->getPosition()[2]); + float ref_point[3] = {float(helix.getRefPointX()), float(helix.getRefPointY()), float(helix.getRefPointZ())}; + TrackStateImpl* trkState = + new TrackStateImpl(TrackState::AtIP, trueD0, truePhi, trueOmega, trueZ0, trueTanLambda, covMatrix, ref_point); - // int prefitError = createFit(trackfitHits, marlinTrack, trkState, m_magneticField, direction, m_maxChi2perHit); - // streamlog_out(DEBUG2) << "---- createFit - error_fit = " << error_fit << std::endl; + // int prefitError = createFit(trackfitHits, marlinTrack, trkState, m_magneticField, direction, + // m_maxChi2perHit); streamlog_out(DEBUG2) << "---- createFit - error_fit = " << error_fit << std::endl; // if (prefitError == 0) { // fitError = finaliseLCIOTrack(marlinTrack, track, trackfitHits, direction ); // streamlog_out(DEBUG2) << "---- finalisedLCIOTrack - error = " << error << std::endl; // } - fitError = MarlinTrk::createFinalisedLCIOTrack(marlinTrack, trackfitHits, track, direction, trkState, m_magneticField, m_maxChi2perHit); + fitError = MarlinTrk::createFinalisedLCIOTrack(marlinTrack, trackfitHits, track, direction, trkState, + m_magneticField, m_maxChi2perHit); + // If first fit attempt fails, try a new fit with hits ordered by z + + if (fitError != 0) { - //If first fit attempt fails, try a new fit with hits ordered by z - - if (fitError!=0) { - // Sort the hits from smaller to larger z - std::sort(trackfitHits.begin(),trackfitHits.end(),sort_by_z); + std::sort(trackfitHits.begin(), trackfitHits.end(), sort_by_z); // Removing the hits on the same layers (remove those with higher z) EVENT::TrackerHitVec trackFilteredByZHits; removeHitsSameLayer(trackfitHits, trackFilteredByZHits); - if(trackFilteredByZHits.size() < 3) continue; + if (trackFilteredByZHits.size() < 3) + continue; - // If fit with hits ordered by radius has failed, the track is probably a 'spiral' track. + // If fit with hits ordered by radius has failed, the track is probably a 'spiral' track. // Fitting 'backward' is very difficult for spiral track, so the default direction here is set as 'forward' - fitError = MarlinTrk::createFinalisedLCIOTrack(marlinTrackZSort, trackFilteredByZHits, track, MarlinTrk::IMarlinTrack::forward, trkState, m_magneticField, m_maxChi2perHit); + fitError = MarlinTrk::createFinalisedLCIOTrack(marlinTrackZSort, trackFilteredByZHits, track, + MarlinTrk::IMarlinTrack::forward, trkState, m_magneticField, + m_maxChi2perHit); } - delete trkState; - //////////////////////// + //////////////////////// - } // end: helical prefit initialised with info from truth and then track fitted and saved as a lcio track + } // end: helical prefit initialised with info from truth and then track fitted and saved as a lcio track else { // DEFAULT procedure: Try to fit - fitError = MarlinTrk::createFinalisedLCIOTrack(marlinTrack, trackfitHits, track, direction, covMatrix, m_magneticField, m_maxChi2perHit); + fitError = MarlinTrk::createFinalisedLCIOTrack(marlinTrack, trackfitHits, track, direction, covMatrix, + m_magneticField, m_maxChi2perHit); + // If first fit attempt fails, try a new fit with hits ordered by z - //If first fit attempt fails, try a new fit with hits ordered by z - - if (fitError!=0) { + if (fitError != 0) { // we need to clean the track object delete track; track = new TrackImpl; // Sort the hits from smaller to larger z - std::sort(trackfitHits.begin(),trackfitHits.end(),sort_by_z); + std::sort(trackfitHits.begin(), trackfitHits.end(), sort_by_z); // Removing the hits on the same layers (remove those with higher z) EVENT::TrackerHitVec trackFilteredByZHits; removeHitsSameLayer(trackfitHits, trackFilteredByZHits); - if(trackFilteredByZHits.size() < 3) continue; + if (trackFilteredByZHits.size() < 3) + continue; - // If fit with hits ordered by radius has failed, the track is probably a 'spiral' track. + // If fit with hits ordered by radius has failed, the track is probably a 'spiral' track. // Fitting 'backward' is very difficult for spiral track, so the default directiin here is set as 'forward' - fitError = MarlinTrk::createFinalisedLCIOTrack(marlinTrackZSort, trackFilteredByZHits, track, MarlinTrk::IMarlinTrack::forward, covMatrix, m_magneticField, m_maxChi2perHit); - + fitError = MarlinTrk::createFinalisedLCIOTrack(marlinTrackZSort, trackFilteredByZHits, track, + MarlinTrk::IMarlinTrack::forward, covMatrix, m_magneticField, + m_maxChi2perHit); } - } // end: track fitted (prefit from fit from 3 hits) and saved as a lcio track ///////////////////////////////////////////// + streamlog_out(DEBUG2) << "TruthTrackFinder: fitError " << fitError << std::endl; - streamlog_out( DEBUG2 )<<"TruthTrackFinder: fitError "<< fitError << std::endl; - - // Check track quality - if fit fails chi2 will be 0 - if(fitError!=0){ delete track; delete relationTrack; delete marlinTrack; delete marlinTrackZSort; m_fitFails++; continue;} - if(track->getChi2() <= 0.){ delete track; delete relationTrack; delete marlinTrack; delete marlinTrackZSort; m_fitFails++; continue;} - if(track->getNdf() <= 0.){ delete track; delete relationTrack; delete marlinTrack; delete marlinTrackZSort; m_fitFails++; continue;} - + // Check track quality - if fit fails chi2 will be 0 + if (fitError != 0) { + delete track; + delete relationTrack; + delete marlinTrack; + delete marlinTrackZSort; + m_fitFails++; + continue; + } + if (track->getChi2() <= 0.) { + delete track; + delete relationTrack; + delete marlinTrack; + delete marlinTrackZSort; + m_fitFails++; + continue; + } + if (track->getNdf() <= 0.) { + delete track; + delete relationTrack; + delete marlinTrack; + delete marlinTrackZSort; + m_fitFails++; + continue; + } - std::vector > hits_in_fit; - hits_in_fit.reserve(trackHits.size()); //Reserve at most the total number of hits + std::vector> hits_in_fit; + hits_in_fit.reserve(trackHits.size()); // Reserve at most the total number of hits marlinTrack->getHitsInFit(hits_in_fit); - - ///Fill hits associated to the track by pattern recognition and hits in fit - m_encoder->reset() ; // reset to 0 + /// Fill hits associated to the track by pattern recognition and hits in fit + m_encoder->reset(); // reset to 0 MarlinTrk::addHitNumbersToTrack(track, trackHits, false, *m_encoder); MarlinTrk::addHitNumbersToTrack(track, hits_in_fit, true, *m_encoder); - streamlog_out( DEBUG5 )<<"TruthTrackFinder: trackHits.size(): "<addElement(track); - + // Make the particle to track link relationTrack->setFrom(track); relationTrack->setTo(mcParticle); relationTrack->setWeight(1.0); trackRelationCollection->addElement(relationTrack); - delete marlinTrack; - delete marlinTrackZSort; + delete marlinTrack; + delete marlinTrackZSort; } - + // Save the output track collection - evt->addCollection( trackCollection , m_outputTrackCollection ) ; + evt->addCollection(trackCollection, m_outputTrackCollection); // Save the output particle to track relation collection - evt->addCollection( trackRelationCollection , m_outputTrackRelationCollection ) ; + evt->addCollection(trackRelationCollection, m_outputTrackRelationCollection); - // Increment the event number - m_eventNumber++ ; - for(unsigned int collection=0; collectiongetCollection( collectionName ) ; - } - catch(DataNotAvailableException &e){ - streamlog_out( DEBUG5 )<<"- cannot get collection. Collection " << collectionName.c_str() << " is unavailable" << std::endl; +void TruthTrackFinder::getCollection(LCCollection*& collection, std::string collectionName, LCEvent* evt) { + try { + collection = evt->getCollection(collectionName); + } catch (DataNotAvailableException& e) { + streamlog_out(DEBUG5) << "- cannot get collection. Collection " << collectionName.c_str() << " is unavailable" + << std::endl; return; } return; } - -void TruthTrackFinder::removeHitsSameLayer(const std::vector &trackHits, std::vector &trackFilteredHits){ + +void TruthTrackFinder::removeHitsSameLayer(const std::vector& trackHits, + std::vector& trackFilteredHits) { trackFilteredHits.push_back(*(trackHits.begin())); - for(std::vector::const_iterator it = trackHits.begin()+1; it != trackHits.end(); ++it){ + for (std::vector::const_iterator it = trackHits.begin() + 1; it != trackHits.end(); ++it) { int subdet = getSubdetector(*it); int layer = getLayer(*it); - if( subdet != getSubdetector(*(it-1)) ){ + if (subdet != getSubdetector(*(it - 1))) { trackFilteredHits.push_back(*it); - } - else if( layer != getLayer(*(it-1)) ){ + } else if (layer != getLayer(*(it - 1))) { trackFilteredHits.push_back(*it); } } - } - - diff --git a/source/Refitting/src/TruthTracker.cc b/source/Refitting/src/TruthTracker.cc index 386eaa5..0313ac4 100644 --- a/source/Refitting/src/TruthTracker.cc +++ b/source/Refitting/src/TruthTracker.cc @@ -1,20 +1,18 @@ #include "TruthTracker.h" #include -#include #include +#include #include #include #include -#include +#include +#include #include #include -#include -#include - - +#include #include #include @@ -22,1438 +20,1294 @@ // ----- include for verbosity dependend logging --------- #include "marlin/VerbosityLevels.h" -#include "DD4hep/Detector.h" #include "DD4hep/DD4hepUnits.h" +#include "DD4hep/Detector.h" #include "MarlinTrk/Factory.h" #include "MarlinTrk/IMarlinTrack.h" - #include "MarlinTrk/MarlinTrkDiagnostics.h" #ifdef MARLINTRK_DIAGNOSTICS_ON #include "MarlinTrk/DiagnosticsController.h" #endif - #include "MarlinTrk/HelixTrack.h" #include "MarlinTrk/LCIOTrackPropagators.h" #include "MarlinTrk/MarlinTrkUtils.h" -#include #include "UTIL/LCTrackerConf.h" -#include +#include #include +#include -#include #include "MarlinCED.h" +#include -using namespace lcio ; -using namespace marlin ; - -using namespace MarlinTrk ; - +using namespace lcio; +using namespace marlin; +using namespace MarlinTrk; -TruthTracker aTruthTracker ; +TruthTracker aTruthTracker; TruthTracker::TruthTracker() : Processor("TruthTracker") { - + // modify processor description - _description = "Creates Track Collection from MC Truth. Can handle composite spacepoints as long as they consist of two TrackerHits" ; - - + _description = "Creates Track Collection from MC Truth. Can handle composite spacepoints as long as they consist of " + "two TrackerHits"; + // register steering parameters: name, description, class-variable, default value - - registerInputCollection("MCParticle", - "MCParticleCollectionName", - "Name of the MCParticle input collection", - _colNameMCParticles, - std::string("MCParticle")); - - + + registerInputCollection("MCParticle", "MCParticleCollectionName", "Name of the MCParticle input collection", + _colNameMCParticles, std::string("MCParticle")); + StringVec trackerHitsRelInputColNamesDefault; - trackerHitsRelInputColNamesDefault.push_back( "VXDTrackerHitRelations" ); - trackerHitsRelInputColNamesDefault.push_back( "SITTrackerHitRelations" ); - trackerHitsRelInputColNamesDefault.push_back( "FTDPixelTrackerHitRelations" ); - trackerHitsRelInputColNamesDefault.push_back( "FTDSpacePointRelations" ); - trackerHitsRelInputColNamesDefault.push_back( "TPCTrackerHitRelations" ); - trackerHitsRelInputColNamesDefault.push_back( "SETTrackerHitRelations" ); - - - registerInputCollections("LCRelation", - "TrackerHitsRelInputCollections", - "Name of the lcrelation collections, that link the TrackerHits to their SimTrackerHits. Have to be in same order as TrackerHitsInputCollections!!!", - _colNamesTrackerHitRelations, - trackerHitsRelInputColNamesDefault ); - - + trackerHitsRelInputColNamesDefault.push_back("VXDTrackerHitRelations"); + trackerHitsRelInputColNamesDefault.push_back("SITTrackerHitRelations"); + trackerHitsRelInputColNamesDefault.push_back("FTDPixelTrackerHitRelations"); + trackerHitsRelInputColNamesDefault.push_back("FTDSpacePointRelations"); + trackerHitsRelInputColNamesDefault.push_back("TPCTrackerHitRelations"); + trackerHitsRelInputColNamesDefault.push_back("SETTrackerHitRelations"); + + registerInputCollections("LCRelation", "TrackerHitsRelInputCollections", + "Name of the lcrelation collections, that link the TrackerHits to their SimTrackerHits. " + "Have to be in same order as TrackerHitsInputCollections!!!", + _colNamesTrackerHitRelations, trackerHitsRelInputColNamesDefault); + StringVec trackerHitsInputColNamesDefault; - - trackerHitsInputColNamesDefault.push_back( "VXDTrackerHits" ); - trackerHitsInputColNamesDefault.push_back( "SITTrackerHits" ); - trackerHitsInputColNamesDefault.push_back( "FTDPixelTrackerHits" ); - trackerHitsInputColNamesDefault.push_back( "FTDSpacePointRelations" ); - trackerHitsInputColNamesDefault.push_back( "TPCTrackerHits" ); - trackerHitsInputColNamesDefault.push_back( "SETTrackerHits" ); - - registerInputCollections("TrackerHit", - "TrackerHitsInputCollections", - "Name of the tracker hit input collections", - _colNamesTrackerHits, - trackerHitsInputColNamesDefault); - - - registerOutputCollection( LCIO::TRACK, - "OutputTrackCollectionName" , - "Name of the output track collection" , - _output_track_col_name , - std::string("TruthTracks") ) ; - - registerOutputCollection( LCIO::LCRELATION, - "OutputTrackRelCollection" , - "Name of the MCParticle-Track Relations collection for output tracks" , - _output_track_rel_name , - std::string("TruthTracksMCP") ) ; - - - registerOutputCollection( LCIO::TRACK, - "OutputTrackSegmentCollectionName" , - "Name of the output track segment collection" , - _output_track_segments_col_name , - std::string("TruthTrackSegments") ) ; - - registerOutputCollection( LCIO::LCRELATION, - "OutputTrackSegmentRelCollection" , - "Name of the MCParticle-Track Relations collection for output track segments" , - _output_track_segment_rel_name , - std::string("TruthTrackSegmentsMCP") ) ; - - + + trackerHitsInputColNamesDefault.push_back("VXDTrackerHits"); + trackerHitsInputColNamesDefault.push_back("SITTrackerHits"); + trackerHitsInputColNamesDefault.push_back("FTDPixelTrackerHits"); + trackerHitsInputColNamesDefault.push_back("FTDSpacePointRelations"); + trackerHitsInputColNamesDefault.push_back("TPCTrackerHits"); + trackerHitsInputColNamesDefault.push_back("SETTrackerHits"); + + registerInputCollections("TrackerHit", "TrackerHitsInputCollections", "Name of the tracker hit input collections", + _colNamesTrackerHits, trackerHitsInputColNamesDefault); + + registerOutputCollection(LCIO::TRACK, "OutputTrackCollectionName", "Name of the output track collection", + _output_track_col_name, std::string("TruthTracks")); + + registerOutputCollection(LCIO::LCRELATION, "OutputTrackRelCollection", + "Name of the MCParticle-Track Relations collection for output tracks", + _output_track_rel_name, std::string("TruthTracksMCP")); + + registerOutputCollection(LCIO::TRACK, "OutputTrackSegmentCollectionName", + "Name of the output track segment collection", _output_track_segments_col_name, + std::string("TruthTrackSegments")); + + registerOutputCollection(LCIO::LCRELATION, "OutputTrackSegmentRelCollection", + "Name of the MCParticle-Track Relations collection for output track segments", + _output_track_segment_rel_name, std::string("TruthTrackSegmentsMCP")); + // registerProcessorParameter( "nEventPrintout", // "Print out progress every N events ", // _nEventPrintout, // int(1000)); - - registerProcessorParameter( "MCpThreshold", - "Transverse Momentum Threshold MC particles which will produce tracks GeV", - _MCpThreshold, - float(0.1)); - - registerProcessorParameter( "FitTracksWithMarlinTrk", + + registerProcessorParameter("MCpThreshold", "Transverse Momentum Threshold MC particles which will produce tracks GeV", + _MCpThreshold, float(0.1)); + + registerProcessorParameter("FitTracksWithMarlinTrk", "Fit the Tracks with MarlinTrk, otherwise take track parameters from MCParticle", - _FitTracksWithMarlinTrk, - bool(true)); - - registerProcessorParameter("MultipleScatteringOn", - "Use MultipleScattering in Fit", - _MSOn, - bool(true)); - - registerProcessorParameter("EnergyLossOn", - "Use Energy Loss in Fit", - _ElossOn, - bool(true)); - - registerProcessorParameter("SmoothOn", - "Smooth All Mesurement Sites in Fit", - _SmoothOn, - bool(false)); - - registerProcessorParameter( "UseMCParticleParametersFotInitOfFit", - "When fitting take track parameters from MCParticle for the initialisation of the Track Fit", - _useMCParticleParametersFotInitOfFit, - bool(false)); - - - registerProcessorParameter( "CreatePrefitUsingMarlinTrk", - "When fitting take track parameters a full pre-fit for the initialisation of the Track Fit", - _create_prefit_using_MarlinTrk, - bool(false)); - - - registerProcessorParameter( "InitialTrackErrorD0", - "Value used for the initial d0 variance of the trackfit", - _initialTrackError_d0, - float(1.e6)); - - registerProcessorParameter( "InitialTrackErrorPhi0", - "Value used for the initial phi0 variance of the trackfit", - _initialTrackError_phi0, - float(1.e2)); - - registerProcessorParameter( "InitialTrackErrorOmega", - "Value used for the initial omega variance of the trackfit", - _initialTrackError_omega, - float(1.e-4)); - - registerProcessorParameter( "InitialTrackErrorZ0", - "Value used for the initial z0 variance of the trackfit", - _initialTrackError_z0, - float(1.e6)); - - registerProcessorParameter( "InitialTrackErrorTanL", - "Value used for the initial tanL variance of the trackfit", - _initialTrackError_tanL, - float(1.e2)); - - registerProcessorParameter( "MaxChi2PerHit", - "Maximum Chi-squared value allowed when assigning a hit to a track", - _maxChi2PerHit, - double(1.e2)); - - registerProcessorParameter( "UseIterativeFitting", - "Fit the Tracks with MarlinTrk using iterative approach. If 3 consecutive hits fail to be included then the current fit is written out and a new fit started. Use instead of FitTracksWithMarlinTrk.", - _UseIterativeFitting, - bool(false)); - - - registerProcessorParameter( "UseEventDisplay", + _FitTracksWithMarlinTrk, bool(true)); + + registerProcessorParameter("MultipleScatteringOn", "Use MultipleScattering in Fit", _MSOn, bool(true)); + + registerProcessorParameter("EnergyLossOn", "Use Energy Loss in Fit", _ElossOn, bool(true)); + + registerProcessorParameter("SmoothOn", "Smooth All Mesurement Sites in Fit", _SmoothOn, bool(false)); + + registerProcessorParameter( + "UseMCParticleParametersFotInitOfFit", + "When fitting take track parameters from MCParticle for the initialisation of the Track Fit", + _useMCParticleParametersFotInitOfFit, bool(false)); + + registerProcessorParameter( + "CreatePrefitUsingMarlinTrk", + "When fitting take track parameters a full pre-fit for the initialisation of the Track Fit", + _create_prefit_using_MarlinTrk, bool(false)); + + registerProcessorParameter("InitialTrackErrorD0", "Value used for the initial d0 variance of the trackfit", + _initialTrackError_d0, float(1.e6)); + + registerProcessorParameter("InitialTrackErrorPhi0", "Value used for the initial phi0 variance of the trackfit", + _initialTrackError_phi0, float(1.e2)); + + registerProcessorParameter("InitialTrackErrorOmega", "Value used for the initial omega variance of the trackfit", + _initialTrackError_omega, float(1.e-4)); + + registerProcessorParameter("InitialTrackErrorZ0", "Value used for the initial z0 variance of the trackfit", + _initialTrackError_z0, float(1.e6)); + + registerProcessorParameter("InitialTrackErrorTanL", "Value used for the initial tanL variance of the trackfit", + _initialTrackError_tanL, float(1.e2)); + + registerProcessorParameter("MaxChi2PerHit", "Maximum Chi-squared value allowed when assigning a hit to a track", + _maxChi2PerHit, double(1.e2)); + + registerProcessorParameter( + "UseIterativeFitting", + "Fit the Tracks with MarlinTrk using iterative approach. If 3 consecutive hits fail to be included then the " + "current fit is written out and a new fit started. Use instead of FitTracksWithMarlinTrk.", + _UseIterativeFitting, bool(false)); + + registerProcessorParameter("UseEventDisplay", "When using UseIterativeFitting show status of each track fit using CED event display.", - _UseEventDisplay, - bool(false)); - - registerProcessorParameter("DetectorTypeForDraw", - "Detector type sent to MarlinCED for drawing", - _detector_model_for_drawing, - int(0)); - - registerProcessorParameter( "HelixMaxR" , - "Max R (mm) Extent for drawing Helix if UseTPCForLimitsOfHelix false", - _helix_max_r , - float(2000.0) ) ; - - - registerProcessorParameter( "TrackSystemName", - "Name of the track fitting system to be used (KalTest, DDKalTest, aidaTT, ... )", - _trkSystemName, - std::string("KalTest") ); - - registerProcessorParameter( "FitDirection", - "Fit direction: -1: backward [default], +1: forward", - _fitDirection, - int(-1) ); + _UseEventDisplay, bool(false)); + + registerProcessorParameter("DetectorTypeForDraw", "Detector type sent to MarlinCED for drawing", + _detector_model_for_drawing, int(0)); + + registerProcessorParameter("HelixMaxR", "Max R (mm) Extent for drawing Helix if UseTPCForLimitsOfHelix false", + _helix_max_r, float(2000.0)); + + registerProcessorParameter("TrackSystemName", + "Name of the track fitting system to be used (KalTest, DDKalTest, aidaTT, ... )", + _trkSystemName, std::string("KalTest")); + registerProcessorParameter("FitDirection", "Fit direction: -1: backward [default], +1: forward", _fitDirection, + int(-1)); #ifdef MARLINTRK_DIAGNOSTICS_ON - - registerOptionalParameter("RunMarlinTrkDiagnostics", "Run MarlinTrk Diagnostics. MarlinTrk must be compiled with MARLINTRK_DIAGNOSTICS_ON defined", _runMarlinTrkDiagnostics, bool(false)); - - registerOptionalParameter("DiagnosticsName", "Name of the root file and root tree if running Diagnostics", _MarlinTrkDiagnosticsName, std::string("TruthTrackerDiagnostics")); - + + registerOptionalParameter( + "RunMarlinTrkDiagnostics", + "Run MarlinTrk Diagnostics. MarlinTrk must be compiled with MARLINTRK_DIAGNOSTICS_ON defined", + _runMarlinTrkDiagnostics, bool(false)); + + registerOptionalParameter("DiagnosticsName", "Name of the root file and root tree if running Diagnostics", + _MarlinTrkDiagnosticsName, std::string("TruthTrackerDiagnostics")); + #endif - - _n_run = 0 ; - _n_evt = 0 ; - - _current_event=0 ; - - - + + _n_run = 0; + _n_evt = 0; + + _current_event = 0; } +void TruthTracker::init() { -void TruthTracker::init() { - - streamlog_out(DEBUG) << " init called " - << std::endl ; + streamlog_out(DEBUG) << " init called " << std::endl; _encoder = new UTIL::BitField64(lcio::LCTrackerCellID::encoding_string()); - + // usually a good idea to - printParameters() ; - + printParameters(); + if (_UseEventDisplay) { - MarlinCED::init(this) ; + MarlinCED::init(this); } - - _colours.push_back( 0xff00ff ); - _colours.push_back( 0xffff00 ); - _colours.push_back( 0x0000ff ); - _colours.push_back( 0xff00ff ); - _colours.push_back( 0x00ffff ); - _colours.push_back( 0xffffff ); - - _colours.push_back( 0xff88ff ); - _colours.push_back( 0xffff88 ); - _colours.push_back( 0x8888ff ); - _colours.push_back( 0xff88ff ); - _colours.push_back( 0x88ffff ); - _colours.push_back( 0xffffff ); - - + _colours.push_back(0xff00ff); + _colours.push_back(0xffff00); + _colours.push_back(0x0000ff); + _colours.push_back(0xff00ff); + _colours.push_back(0x00ffff); + _colours.push_back(0xffffff); + + _colours.push_back(0xff88ff); + _colours.push_back(0xffff88); + _colours.push_back(0x8888ff); + _colours.push_back(0xff88ff); + _colours.push_back(0x88ffff); + _colours.push_back(0xffffff); + // set up the trk system - _trksystem = MarlinTrk::Factory::createMarlinTrkSystem( _trkSystemName , 0 , "" ) ; - - if( _trksystem == 0 ){ - - throw EVENT::Exception( std::string(" Cannot initialize MarlinTrkSystem of Type: ") + _trkSystemName ) ; - + _trksystem = MarlinTrk::Factory::createMarlinTrkSystem(_trkSystemName, 0, ""); + + if (_trksystem == 0) { + + throw EVENT::Exception(std::string(" Cannot initialize MarlinTrkSystem of Type: ") + _trkSystemName); } - - _trksystem->setOption( IMarlinTrkSystem::CFG::useQMS, _MSOn ) ; - _trksystem->setOption( IMarlinTrkSystem::CFG::usedEdx, _ElossOn) ; - _trksystem->setOption( IMarlinTrkSystem::CFG::useSmoothing, _SmoothOn) ; - _trksystem->init() ; - - + + _trksystem->setOption(IMarlinTrkSystem::CFG::useQMS, _MSOn); + _trksystem->setOption(IMarlinTrkSystem::CFG::usedEdx, _ElossOn); + _trksystem->setOption(IMarlinTrkSystem::CFG::useSmoothing, _SmoothOn); + _trksystem->init(); + #ifdef MARLINTRK_DIAGNOSTICS_ON - - void * dcv = _trksystem->getDiagnositicsPointer(); + + void* dcv = _trksystem->getDiagnositicsPointer(); DiagnosticsController* dc = static_cast(dcv); - dc->init(_MarlinTrkDiagnosticsName,_MarlinTrkDiagnosticsName, _runMarlinTrkDiagnostics); - + dc->init(_MarlinTrkDiagnosticsName, _MarlinTrkDiagnosticsName, _runMarlinTrkDiagnostics); + #endif - + dd4hep::Detector& lcdd = dd4hep::Detector::getInstance(); - double bFieldVec[3]; - lcdd.field().magneticField({0,0,0},bFieldVec); // get the magnetic field vector from DD4hep - _Bz = bFieldVec[2]/dd4hep::tesla; // z component at (0,0,0) - - + double bFieldVec[3]; + lcdd.field().magneticField({0, 0, 0}, bFieldVec); // get the magnetic field vector from DD4hep + _Bz = bFieldVec[2] / dd4hep::tesla; // z component at (0,0,0) } -void TruthTracker::processRunHeader( LCRunHeader* ) { - - ++_n_run ; -} +void TruthTracker::processRunHeader(LCRunHeader*) { ++_n_run; } -void TruthTracker::processEvent( LCEvent * evt ) { - - // set the correct configuration for the tracking system for this event - MarlinTrk::TrkSysConfig< MarlinTrk::IMarlinTrkSystem::CFG::useQMS> mson( _trksystem, _MSOn ) ; - MarlinTrk::TrkSysConfig< MarlinTrk::IMarlinTrkSystem::CFG::usedEdx> elosson( _trksystem,_ElossOn) ; - MarlinTrk::TrkSysConfig< MarlinTrk::IMarlinTrkSystem::CFG::useSmoothing> smoothon( _trksystem,_SmoothOn) ; +void TruthTracker::processEvent(LCEvent* evt) { + + // set the correct configuration for the tracking system for this event + MarlinTrk::TrkSysConfig mson(_trksystem, _MSOn); + MarlinTrk::TrkSysConfig elosson(_trksystem, _ElossOn); + MarlinTrk::TrkSysConfig smoothon(_trksystem, _SmoothOn); _current_event = evt; - - streamlog_out(DEBUG3) << " processing event: " << _n_evt << std::endl ; - - - _nMCP = 0 ; - + + streamlog_out(DEBUG3) << " processing event: " << _n_evt << std::endl; + + _nMCP = 0; + _colTrackerHits.clear(); _navTrackerHitRel.clear(); _nCreatedTracks = 0; - + /**********************************************************************************************/ /* Prepare the collections */ /**********************************************************************************************/ - + // get the input collections and fill the vectors - this->SetupInputCollections(evt) ; - - // establish the track collection that will be created - _trackVec = new LCCollectionVec( LCIO::TRACK ) ; - + this->SetupInputCollections(evt); + + // establish the track collection that will be created + _trackVec = new LCCollectionVec(LCIO::TRACK); + // if we want to point back to the hits we need to set the flag - LCFlagImpl trkFlag(0) ; - trkFlag.setBit( LCIO::TRBIT_HITS ) ; - _trackVec->setFlag( trkFlag.getFlag() ) ; - - // establish the track relations collection that will be created - _trackRelVec = new LCCollectionVec( LCIO::LCRELATION ) ; - - - // track segments - - _trackSegmentsVec = new LCCollectionVec( LCIO::TRACK ) ; - + LCFlagImpl trkFlag(0); + trkFlag.setBit(LCIO::TRBIT_HITS); + _trackVec->setFlag(trkFlag.getFlag()); + + // establish the track relations collection that will be created + _trackRelVec = new LCCollectionVec(LCIO::LCRELATION); + + // track segments + + _trackSegmentsVec = new LCCollectionVec(LCIO::TRACK); + // if we want to point back to the hits we need to set the flag - LCFlagImpl trkSegFlag(0) ; - trkSegFlag.setBit( LCIO::TRBIT_HITS ) ; - _trackSegmentsVec->setFlag( trkSegFlag.getFlag() ) ; - - // establish the track relations collection that will be created - _trackSegmentsRelVec = new LCCollectionVec( LCIO::LCRELATION ) ; - - + LCFlagImpl trkSegFlag(0); + trkSegFlag.setBit(LCIO::TRBIT_HITS); + _trackSegmentsVec->setFlag(trkSegFlag.getFlag()); + + // establish the track relations collection that will be created + _trackSegmentsRelVec = new LCCollectionVec(LCIO::LCRELATION); + // create the encoder to decode cellID0 - UTIL::BitField64 cellID_encoder( LCTrackerCellID::encoding_string() ) ; - - - + UTIL::BitField64 cellID_encoder(LCTrackerCellID::encoding_string()); + /**********************************************************************************************/ /* Store the TrackerHits and SimTrackerHits as pairs */ /**********************************************************************************************/ - - std::vector< std::pair > simHitTrkHit; - - - for( unsigned iCol=0; iCol<_colTrackerHits.size(); iCol++){ - + + std::vector> simHitTrkHit; + + for (unsigned iCol = 0; iCol < _colTrackerHits.size(); iCol++) { + LCCollection* trackerHitCol = _colTrackerHits[iCol]; int nHits = trackerHitCol->getNumberOfElements(); - + LCRelationNavigator* nav = _navTrackerHitRel[iCol]; - - for( int j=0; jgetElementAt( j ) == 0 ) { - streamlog_out( DEBUG0 ) << "Pointer to TrackerHit" << j << " is NULL " << std::endl; + + for (int j = 0; j < nHits; j++) { + + if (trackerHitCol->getElementAt(j) == 0) { + streamlog_out(DEBUG0) << "Pointer to TrackerHit" << j << " is NULL " << std::endl; } - - TrackerHit * trkhit = dynamic_cast( trackerHitCol->getElementAt( j )); - - if ( trkhit == 0 ) { - - std::stringstream errorMsg; - errorMsg << "dynamic_cast to TrackerHit for hit " << j << " failed. Pointer = " << trackerHitCol->getElementAt( j ) << std::endl; - + + TrackerHit* trkhit = dynamic_cast(trackerHitCol->getElementAt(j)); + + if (trkhit == 0) { + + std::stringstream errorMsg; + errorMsg << "dynamic_cast to TrackerHit for hit " << j + << " failed. Pointer = " << trackerHitCol->getElementAt(j) << std::endl; + throw lcio::Exception(errorMsg.str()); - } - - const LCObjectVec& to = nav->getRelatedToObjects( trkhit ); - - if( BitSet32( trkhit->getType() )[ UTIL::ILDTrkHitTypeBit::COMPOSITE_SPACEPOINT ] ){ //it is a composite spacepoint - - if( to.size() == 2 ){ - + + const LCObjectVec& to = nav->getRelatedToObjects(trkhit); + + if (BitSet32(trkhit->getType())[UTIL::ILDTrkHitTypeBit::COMPOSITE_SPACEPOINT]) { // it is a composite spacepoint + + if (to.size() == 2) { + SimTrackerHit* simhitA = dynamic_cast(to.at(0)); SimTrackerHit* simhitB = dynamic_cast(to.at(1)); - + MCParticle* mcpA = simhitA->getMCParticle(); MCParticle* mcpB = simhitB->getMCParticle(); - - if ( mcpA == 0 || mcpB == 0) { - streamlog_out( DEBUG5 ) << "spacepoint discarded, because MCParticle from simHit is NULL: mcpA = " << mcpA << " mcpB = " << mcpB << "\n"; + + if (mcpA == 0 || mcpB == 0) { + streamlog_out(DEBUG5) << "spacepoint discarded, because MCParticle from simHit is NULL: mcpA = " << mcpA + << " mcpB = " << mcpB << "\n"; } - + // Check if the simHits are from the same particel in order to avoid ghost hits - if( mcpA == mcpB ) simHitTrkHit.push_back(std::make_pair(simhitA, trkhit)); - else streamlog_out( DEBUG0 ) << "spacepoint discarded, because simHits are not equal " << mcpA << " != " - << mcpB << "\n"; - - -//#ifdef MARLINTRK_DIAGNOSTICS_ON -// -// // set the pointer to the simhit via lcio extention MCTruth4HitExt -// -// //Split it up and add both hits to the MarlinTrk -// const LCObjectVec rawObjects = trkhit->getRawHits(); -// -// for( unsigned k=0; k< rawObjects.size(); k++ ){ -// -// TrackerHit* rawHit = dynamic_cast< TrackerHit* >( rawObjects[k] ); -// if( rawHit ){ -// -// if( rawHit->getCellID0() == simhitA->getCellID0() ) { -// streamlog_out( DEBUG4 ) << "link simhit = " << simhitA << " Cell ID = " << simhitA->getCellID0() << " with trkhit = " << rawHit << " Cell ID = " << rawHit->getCellID0() << std::endl; -// rawHit->ext() = new MarlinTrk::MCTruth4HitExtStruct; -// rawHit->ext()->simhit = simhitA; -// } -// if( rawHit->getCellID0() == simhitB->getCellID0() ) { -// streamlog_out( DEBUG4 ) << "link simhit = " << simhitB << " Cell ID = " << simhitB->getCellID0() << " with trkhit = " << rawHit << " Cell ID = " << rawHit->getCellID0() << std::endl; -// rawHit->ext() = new MarlinTrk::MCTruth4HitExtStruct; -// rawHit->ext()->simhit = simhitB; -// } -// -// } -// } -//#endif - - - - } - else{ streamlog_out( DEBUG0 ) << "spacepoint discarded, because it is related to " << to.size() << "SimTrackerHits. It should be 2!\n"; } - - } - else{ // no composite spacepoint - - if( to.size() == 1){ // only take trackerHits, that have only one related SimHit - + if (mcpA == mcpB) + simHitTrkHit.push_back(std::make_pair(simhitA, trkhit)); + else + streamlog_out(DEBUG0) << "spacepoint discarded, because simHits are not equal " << mcpA << " != " << mcpB + << "\n"; + + // #ifdef MARLINTRK_DIAGNOSTICS_ON + // + // // set the pointer to the simhit via lcio extention MCTruth4HitExt + // + // //Split it up and add both hits to the MarlinTrk + // const LCObjectVec rawObjects = trkhit->getRawHits(); + // + // for( unsigned k=0; k< rawObjects.size(); k++ ){ + // + // TrackerHit* rawHit = dynamic_cast< TrackerHit* >( rawObjects[k] ); + // if( rawHit ){ + // + // if( rawHit->getCellID0() == simhitA->getCellID0() ) { + // streamlog_out( DEBUG4 ) << "link simhit = " << simhitA << " Cell ID = " << + // simhitA->getCellID0() << " with trkhit = " << rawHit << " Cell ID = " << + // rawHit->getCellID0() << std::endl; rawHit->ext() = new + // MarlinTrk::MCTruth4HitExtStruct; rawHit->ext()->simhit = + // simhitA; + // } + // if( rawHit->getCellID0() == simhitB->getCellID0() ) { + // streamlog_out( DEBUG4 ) << "link simhit = " << simhitB << " Cell ID = " << + // simhitB->getCellID0() << " with trkhit = " << rawHit << " Cell ID = " << + // rawHit->getCellID0() << std::endl; rawHit->ext() = new + // MarlinTrk::MCTruth4HitExtStruct; rawHit->ext()->simhit = + // simhitB; + // } + // + // } + // } + // #endif + + } else { + streamlog_out(DEBUG0) << "spacepoint discarded, because it is related to " << to.size() + << "SimTrackerHits. It should be 2!\n"; + } + + } else { // no composite spacepoint + + if (to.size() == 1) { // only take trackerHits, that have only one related SimHit + SimTrackerHit* simhit = dynamic_cast(to.at(0)); simHitTrkHit.push_back(std::make_pair(simhit, trkhit)); - -//#ifdef MARLINTRK_DIAGNOSTICS_ON -// trkhit->ext() = new MarlinTrk::MCTruth4HitExtStruct; -// trkhit->ext()->simhit = simhit; -//#endif + + // #ifdef MARLINTRK_DIAGNOSTICS_ON + // trkhit->ext() = new MarlinTrk::MCTruth4HitExtStruct; + // trkhit->ext()->simhit = simhit; + // #endif + } else { + streamlog_out(DEBUG0) << "TrackerHit discarded, because it is related to " << to.size() + << "SimTrackerHits. It should be 1!\n"; } - else{ streamlog_out( DEBUG0 ) << "TrackerHit discarded, because it is related to " << to.size() << "SimTrackerHits. It should be 1!\n"; } - } - - } - } - streamlog_out( DEBUG4 ) << "Number of Tracker hits = " << simHitTrkHit.size() << std::endl; - - // now order the hits by MCParticle and then in time - std::sort( simHitTrkHit.begin(),simHitTrkHit.end(), SimTrackerHitSortPredicate() ); - - - - + streamlog_out(DEBUG4) << "Number of Tracker hits = " << simHitTrkHit.size() << std::endl; + + // now order the hits by MCParticle and then in time + std::sort(simHitTrkHit.begin(), simHitTrkHit.end(), SimTrackerHitSortPredicate()); + // some information output - for(unsigned int i=0; i< simHitTrkHit.size() ; ++i ) { - - SimTrackerHit * simHit = simHitTrkHit[i].first; + for (unsigned int i = 0; i < simHitTrkHit.size(); ++i) { + + SimTrackerHit* simHit = simHitTrkHit[i].first; TrackerHit* trackerHit = simHitTrkHit[i].second; - - - - streamlog_out( DEBUG2 ) << "Tracker hit: [" << i << "] = " << trackerHit << " mcp = " << simHit->getMCParticle() << " time = " << simHit->getTime() << " cellid (trkHit) = " << trackerHit->getCellID0() - << " (de" << getDetectorID( trackerHit ) - << ",si" << getSideID( trackerHit ) - << ",la" << getLayerID( trackerHit ) - << ",mo"<< getModuleID( trackerHit ) - << ",se"<< getSensorID( trackerHit ) - << ")" << std::endl; - - + + streamlog_out(DEBUG2) << "Tracker hit: [" << i << "] = " << trackerHit << " mcp = " << simHit->getMCParticle() + << " time = " << simHit->getTime() << " cellid (trkHit) = " << trackerHit->getCellID0() + << " (de" << getDetectorID(trackerHit) << ",si" << getSideID(trackerHit) << ",la" + << getLayerID(trackerHit) << ",mo" << getModuleID(trackerHit) << ",se" + << getSensorID(trackerHit) << ")" << std::endl; } - + /**********************************************************************************************/ /* Take hits with the same MCP and create tracks from them */ /**********************************************************************************************/ - - streamlog_out( DEBUG4 ) << "Add Tracker hits to Tracks" << std::endl; - + + streamlog_out(DEBUG4) << "Add Tracker hits to Tracks" << std::endl; + // std::vector hit_list; - std::vector< std::pair > hit_list; - - if( simHitTrkHit.size() > 0) { - + std::vector> hit_list; + + if (simHitTrkHit.size() > 0) { + MCParticle* mcplast = NULL; - - - for(unsigned int i=0; i< simHitTrkHit.size() ; ++i) { - - + + for (unsigned int i = 0; i < simHitTrkHit.size(); ++i) { + SimTrackerHit* simhit = simHitTrkHit[i].first; - + MCParticle* mcp = simhit->getMCParticle(); - - if ( mcp == 0 ) { - streamlog_out( DEBUG5 ) << "hit discarded, because MCParticle from simHit is NULL: mcp = " << mcp << "\n"; + + if (mcp == 0) { + streamlog_out(DEBUG5) << "hit discarded, because MCParticle from simHit is NULL: mcp = " << mcp << "\n"; continue; } - - - double const* p = mcp->getMomentum() ; - float const pmag2 = p[0]*p[0] + p[1]*p[1] + p[2]*p[2] ; -// float const pt2 = p[0]*p[0] + p[1]*p[1] ; - - if ( i == 0 ) { - mcplast = mcp ; + + double const* p = mcp->getMomentum(); + float const pmag2 = p[0] * p[0] + p[1] * p[1] + p[2] * p[2]; + // float const pt2 = p[0]*p[0] + p[1]*p[1] ; + + if (i == 0) { + mcplast = mcp; } - - if( mcp != mcplast ) { + + if (mcp != mcplast) { // new MCParticle - - if ( hit_list.size() >= 3) { - // create track from vector of hits - streamlog_out( DEBUG2 ) << "Create New Track for MCParticle " << mcplast << std::endl; + + if (hit_list.size() >= 3) { + // create track from vector of hits + streamlog_out(DEBUG2) << "Create New Track for MCParticle " << mcplast << std::endl; if (_UseIterativeFitting) { - this->createTrack_iterative(mcplast, cellID_encoder, hit_list ); + this->createTrack_iterative(mcplast, cellID_encoder, hit_list); } else { - this->createTrack(mcplast, cellID_encoder, hit_list ); + this->createTrack(mcplast, cellID_encoder, hit_list); } - - - } - - hit_list.clear(); // clear the list for the new mcp - + + hit_list.clear(); // clear the list for the new mcp } - - if( pmag2 > (_MCpThreshold*_MCpThreshold) ) { // if momentum is greater than cut add hit to list - - streamlog_out( DEBUG2 ) << "Add hit from det " << simhit->getCellID0() << " to track from MCParticle " << mcp << " : current number of hits = " << hit_list.size() << std::endl; + + if (pmag2 > (_MCpThreshold * _MCpThreshold)) { // if momentum is greater than cut add hit to list + + streamlog_out(DEBUG2) << "Add hit from det " << simhit->getCellID0() << " to track from MCParticle " << mcp + << " : current number of hits = " << hit_list.size() << std::endl; std::pair pair(simHitTrkHit[i]); - hit_list.push_back( pair ) ; + hit_list.push_back(pair); } - - // set last mcparticle + + // set last mcparticle mcplast = mcp; - + } // end of loop over hits - - // check if there is still a track to be created - if( hit_list.size() >= 3 ) { + + // check if there is still a track to be created + if (hit_list.size() >= 3) { // then create a new track - streamlog_out( DEBUG3 ) << "Create New Track for Last MCParticle " << mcplast << std::endl; + streamlog_out(DEBUG3) << "Create New Track for Last MCParticle " << mcplast << std::endl; if (_UseIterativeFitting) { - this->createTrack_iterative(mcplast, cellID_encoder, hit_list ); + this->createTrack_iterative(mcplast, cellID_encoder, hit_list); } else { - this->createTrack(mcplast, cellID_encoder, hit_list ); + this->createTrack(mcplast, cellID_encoder, hit_list); } - - hit_list.clear(); - + + hit_list.clear(); } - - } - - evt->addCollection( _trackVec , _output_track_col_name) ; - evt->addCollection( _trackRelVec , _output_track_rel_name) ; - evt->addCollection( _trackSegmentsVec , _output_track_segments_col_name) ; - evt->addCollection( _trackSegmentsRelVec , _output_track_segment_rel_name) ; - - streamlog_out( DEBUG4 ) << "Created " << _nCreatedTracks << " truth tracks\n"; - + } + + evt->addCollection(_trackVec, _output_track_col_name); + evt->addCollection(_trackRelVec, _output_track_rel_name); + evt->addCollection(_trackSegmentsVec, _output_track_segments_col_name); + evt->addCollection(_trackSegmentsRelVec, _output_track_segment_rel_name); + + streamlog_out(DEBUG4) << "Created " << _nCreatedTracks << " truth tracks\n"; + // clear the navigator relations - for (unsigned i = 0 ; i < _navTrackerHitRel.size(); ++i) { + for (unsigned i = 0; i < _navTrackerHitRel.size(); ++i) { delete _navTrackerHitRel[i]; } - - ++_n_evt ; - -} - + ++_n_evt; +} -void TruthTracker::check( LCEvent* ) { +void TruthTracker::check(LCEvent*) { // nothing to check here - could be used to fill checkplots in reconstruction processor } +void TruthTracker::end() { -void TruthTracker::end() { - - streamlog_out(DEBUG4) << "TruthTracker::end() " << name() - << " processed " << _n_evt << " events in " << _n_run << " runs " - << std::endl ; - - delete _encoder ; - -// delete _trksystem ; - -} - + streamlog_out(DEBUG4) << "TruthTracker::end() " << name() << " processed " << _n_evt << " events in " << _n_run + << " runs " << std::endl; + delete _encoder; + // delete _trksystem ; +} +void TruthTracker::SetupInputCollections(LCEvent* evt) { -void TruthTracker::SetupInputCollections( LCEvent * evt ) { - - - // Check if there are as many tracker hit input collections as relation collections - if( _colNamesTrackerHits.size() != _colNamesTrackerHitRelations.size() ){ - - streamlog_out( ERROR ) << "There must be as many input collections of tracker Hits as of relations. At the moment, there are " - << _colNamesTrackerHits.size() << " tracker hit collections and " << _colNamesTrackerHitRelations.size() << " relation collections passed as steering paremeters!\n"; - + if (_colNamesTrackerHits.size() != _colNamesTrackerHitRelations.size()) { + + streamlog_out(ERROR) + << "There must be as many input collections of tracker Hits as of relations. At the moment, there are " + << _colNamesTrackerHits.size() << " tracker hit collections and " << _colNamesTrackerHitRelations.size() + << " relation collections passed as steering paremeters!\n"; + exit(1); } - - for( unsigned i=0; i< _colNamesTrackerHits.size(); i++ ){ - - + + for (unsigned i = 0; i < _colNamesTrackerHits.size(); i++) { + // the tracker hits - LCCollection* colTrkHits = GetCollection( evt, _colNamesTrackerHits[i] ); - if( colTrkHits == NULL ) continue; - + LCCollection* colTrkHits = GetCollection(evt, _colNamesTrackerHits[i]); + if (colTrkHits == NULL) + continue; + // the relations of them - LCRelationNavigator* nav = GetRelations( evt, _colNamesTrackerHitRelations[i] ); - if( nav == NULL ) continue; - - - _colTrackerHits.push_back( colTrkHits ); - _navTrackerHitRel.push_back( nav ); - - + LCRelationNavigator* nav = GetRelations(evt, _colNamesTrackerHitRelations[i]); + if (nav == NULL) + continue; + + _colTrackerHits.push_back(colTrkHits); + _navTrackerHitRel.push_back(nav); } - - } -void TruthTracker::createTrack( MCParticle* mcp, UTIL::BitField64& cellID_encoder, std::vector< std::pair >& hit_list ) { - +void TruthTracker::createTrack(MCParticle* mcp, UTIL::BitField64& cellID_encoder, + std::vector>& hit_list) { + /////////////////////////////////////////////////////// - // check inputs + // check inputs /////////////////////////////////////////////////////// - - if( mcp == 0 ){ - throw EVENT::Exception( std::string("TruthTracker::createTrack: MCParticle == NULL ") ) ; + + if (mcp == 0) { + throw EVENT::Exception(std::string("TruthTracker::createTrack: MCParticle == NULL ")); } - - if ( hit_list.empty() ) return; - - HelixTrack hel(mcp->getVertex(), mcp->getMomentum(), mcp->getCharge(), _Bz ); - streamlog_out( DEBUG3 ) << "\n MCParticle paramters: " - << " d0 " << hel.getD0() - << " phi0 " << hel.getPhi0() - << " omega "<< hel.getOmega() - << " z0 "<< hel.getZ0() - << " tanl "<< hel.getTanLambda() - << " total number of hits = " << hit_list.size() - << "\n" << std::endl; + + if (hit_list.empty()) + return; + + HelixTrack hel(mcp->getVertex(), mcp->getMomentum(), mcp->getCharge(), _Bz); + streamlog_out(DEBUG3) << "\n MCParticle paramters: " + << " d0 " << hel.getD0() << " phi0 " << hel.getPhi0() << " omega " << hel.getOmega() << " z0 " + << hel.getZ0() << " tanl " << hel.getTanLambda() + << " total number of hits = " << hit_list.size() << "\n" + << std::endl; ////////////////////////////////////////////////////////////////////////////////////// // Only fit the hits before looping over SJA:FIXME: FTD may need special treatment ////////////////////////////////////////////////////////////////////////////////////// - + std::vector hit_list_inner_r; - + hit_list_inner_r.reserve(300); - + float delta_phi = 0.0; - - HelixTrack hel_copy(mcp->getVertex(), mcp->getMomentum(), mcp->getCharge(), _Bz ); - - for( unsigned ihit = 0; ihit < hit_list.size(); ++ihit){ - + + HelixTrack hel_copy(mcp->getVertex(), mcp->getMomentum(), mcp->getCharge(), _Bz); + + for (unsigned ihit = 0; ihit < hit_list.size(); ++ihit) { + float x = hit_list[ihit].second->getPosition()[0]; float y = hit_list[ihit].second->getPosition()[1]; float z = hit_list[ihit].second->getPosition()[2]; - - delta_phi += fabs(hel_copy.moveRefPoint(x, y, z)); - - if ( delta_phi < M_PI ) { + + delta_phi += fabs(hel_copy.moveRefPoint(x, y, z)); + + if (delta_phi < M_PI) { hit_list_inner_r.push_back(hit_list[ihit].second); } - } - + if (hit_list_inner_r.size() < 3) { - streamlog_out( DEBUG2 ) << " Reject Track as the number of hits before the turn " << hit_list_inner_r.size() << " is less than 3 hits. Total delta phi before last hit = " << delta_phi << " . Total number of hits = " << hit_list.size() << std::endl; + streamlog_out(DEBUG2) << " Reject Track as the number of hits before the turn " << hit_list_inner_r.size() + << " is less than 3 hits. Total delta phi before last hit = " << delta_phi + << " . Total number of hits = " << hit_list.size() << std::endl; return; } - - TrackImpl* Track = new TrackImpl ; - - - if( _FitTracksWithMarlinTrk ) { - + TrackImpl* Track = new TrackImpl; + + if (_FitTracksWithMarlinTrk) { + // setup initial dummy covariance matrix EVENT::FloatVec covMatrix; covMatrix.resize(15); - - for (unsigned icov = 0; icov > r2_values; + + covMatrix[0] = (_initialTrackError_d0); // sigma_d0^2 + covMatrix[2] = (_initialTrackError_phi0); // sigma_phi0^2 + covMatrix[5] = (_initialTrackError_omega); // sigma_omega^2 + covMatrix[9] = (_initialTrackError_z0); // sigma_z0^2 + covMatrix[14] = (_initialTrackError_tanL); // sigma_tanl^2 + + streamlog_out(DEBUG3) << "Create track with " << hit_list_inner_r.size() << " hits" << std::endl; + + std::vector> r2_values; r2_values.reserve(hit_list_inner_r.size()); - - for (TrackerHitVec::iterator it=hit_list_inner_r.begin(); it!=hit_list_inner_r.end(); ++it) { + + for (TrackerHitVec::iterator it = hit_list_inner_r.begin(); it != hit_list_inner_r.end(); ++it) { EVENT::TrackerHit* h = *it; - float r2 = h->getPosition()[0]*h->getPosition()[0]+h->getPosition()[1]*h->getPosition()[1]; + float r2 = h->getPosition()[0] * h->getPosition()[0] + h->getPosition()[1] * h->getPosition()[1]; r2_values.push_back(std::make_pair(r2, *it)); } - - sort(r2_values.begin(),r2_values.end()); - + + sort(r2_values.begin(), r2_values.end()); + hit_list_inner_r.clear(); hit_list_inner_r.reserve(r2_values.size()); - - for (std::vector< std::pair >::iterator it=r2_values.begin(); it!=r2_values.end(); ++it) { + + for (std::vector>::iterator it = r2_values.begin(); it != r2_values.end(); + ++it) { hit_list_inner_r.push_back(it->second); } - + TrackStateImpl* prefit_trackState = 0; - - //bool fit_backwards = IMarlinTrack::backward; - - bool fit_direction = ( (_fitDirection < 0 ) ? IMarlinTrack::backward : IMarlinTrack::forward ) ; - - streamlog_out( DEBUG1 ) << "TruthTracker::createTrack: fit direction used for fit (-1:backward,+1forward) : " << _fitDirection << std::endl ; + // bool fit_backwards = IMarlinTrack::backward; + + bool fit_direction = ((_fitDirection < 0) ? IMarlinTrack::backward : IMarlinTrack::forward); + + streamlog_out(DEBUG1) << "TruthTracker::createTrack: fit direction used for fit (-1:backward,+1forward) : " + << _fitDirection << std::endl; MarlinTrk::IMarlinTrack* marlinTrk = _trksystem->createTrack(); - + try { - + int error = 0; - - if( _useMCParticleParametersFotInitOfFit ){ - - hel.moveRefPoint(hit_list_inner_r.front()->getPosition()[0], hit_list_inner_r.front()->getPosition()[1], hit_list_inner_r.front()->getPosition()[2]); - - const float referencePoint[3] = { float(hel.getRefPointX()) , float(hel.getRefPointY()) , float(hel.getRefPointZ()) }; - - prefit_trackState = new TrackStateImpl( lcio::TrackState::AtIP, - hel.getD0(), - hel.getPhi0(), - hel.getOmega(), - hel.getZ0(), - hel.getTanLambda(), - covMatrix, - referencePoint) ; - - - - error = MarlinTrk::createFinalisedLCIOTrack(marlinTrk, hit_list_inner_r, Track, fit_direction, prefit_trackState, _Bz, _maxChi2PerHit); - + + if (_useMCParticleParametersFotInitOfFit) { + + hel.moveRefPoint(hit_list_inner_r.front()->getPosition()[0], hit_list_inner_r.front()->getPosition()[1], + hit_list_inner_r.front()->getPosition()[2]); + + const float referencePoint[3] = {float(hel.getRefPointX()), float(hel.getRefPointY()), + float(hel.getRefPointZ())}; + + prefit_trackState = new TrackStateImpl(lcio::TrackState::AtIP, hel.getD0(), hel.getPhi0(), hel.getOmega(), + hel.getZ0(), hel.getTanLambda(), covMatrix, referencePoint); + + error = MarlinTrk::createFinalisedLCIOTrack(marlinTrk, hit_list_inner_r, Track, fit_direction, + prefit_trackState, _Bz, _maxChi2PerHit); + } else { - - error = MarlinTrk::createFinalisedLCIOTrack(marlinTrk, hit_list_inner_r, Track, fit_direction, covMatrix, _Bz, _maxChi2PerHit); - - } - - if( error != IMarlinTrack::success || Track->getNdf() < 0 ) { - streamlog_out(DEBUG2) << "TruthTracker::createTrack: EVENT: << " << _current_event->getEventNumber() << " >> Track fit returns error code " << error << " NDF = " << Track->getNdf() << ". Number of hits = "<< hit_list_inner_r.size() << std::endl; - return ; + + error = MarlinTrk::createFinalisedLCIOTrack(marlinTrk, hit_list_inner_r, Track, fit_direction, covMatrix, _Bz, + _maxChi2PerHit); + } + + if (error != IMarlinTrack::success || Track->getNdf() < 0) { + streamlog_out(DEBUG2) << "TruthTracker::createTrack: EVENT: << " << _current_event->getEventNumber() + << " >> Track fit returns error code " << error << " NDF = " << Track->getNdf() + << ". Number of hits = " << hit_list_inner_r.size() << std::endl; + return; } - + #ifdef MARLINTRK_DIAGNOSTICS_ON - if (error != IMarlinTrack::success) { - void * dcv = _trksystem->getDiagnositicsPointer(); + if (error != IMarlinTrack::success) { + void* dcv = _trksystem->getDiagnositicsPointer(); DiagnosticsController* dc = static_cast(dcv); dc->skip_current_track(); - } + } #endif - - } catch (...) { - - streamlog_out(ERROR) << "TruthTracker::createTrack: EVENT: << " << _current_event->getEventNumber() << " >> exception caught and rethown. MCParticle = " << mcp << std::endl; - -// delete Track; -// delete marlinTrk; - - throw ; - + + streamlog_out(ERROR) << "TruthTracker::createTrack: EVENT: << " << _current_event->getEventNumber() + << " >> exception caught and rethown. MCParticle = " << mcp << std::endl; + + // delete Track; + // delete marlinTrk; + + throw; } - - std::vector > hits_in_fit ; - std::vector > outliers ; - std::vector all_hits; + std::vector> hits_in_fit; + std::vector> outliers; + std::vector all_hits; all_hits.reserve(300); marlinTrk->getHitsInFit(hits_in_fit); - - for ( unsigned ihit = 0; ihit < hits_in_fit.size(); ++ihit) { + + for (unsigned ihit = 0; ihit < hits_in_fit.size(); ++ihit) { all_hits.push_back(hits_in_fit[ihit].first); } - + MarlinTrk::addHitNumbersToTrack(Track, all_hits, true, cellID_encoder); - + marlinTrk->getOutliers(outliers); - - for ( unsigned ihit = 0; ihit < outliers.size(); ++ihit) { + + for (unsigned ihit = 0; ihit < outliers.size(); ++ihit) { all_hits.push_back(outliers[ihit].first); } - + MarlinTrk::addHitNumbersToTrack(Track, all_hits, false, cellID_encoder); - + delete marlinTrk; - - + } else { - + // use mcp pos and mom to set the track parameters - HelixTrack hel_tmp(mcp->getVertex(), mcp->getMomentum(), mcp->getCharge(), _Bz ); - + HelixTrack hel_tmp(mcp->getVertex(), mcp->getMomentum(), mcp->getCharge(), _Bz); + hel_tmp.moveRefPoint(0.0, 0.0, 0.0); - + TrackStateImpl* ts = new TrackStateImpl(); - + ts->setD0(hel_tmp.getD0()); ts->setPhi(hel_tmp.getPhi0()); ts->setOmega(hel_tmp.getOmega()); ts->setZ0(hel_tmp.getZ0()); ts->setTanLambda(hel_tmp.getTanLambda()); - + float ref[3]; - - ref[0] = hel_tmp.getRefPointX() ; - ref[1] = hel_tmp.getRefPointY() ; - ref[2] = hel_tmp.getRefPointZ() ; - - ts->setReferencePoint(ref); - + + ref[0] = hel_tmp.getRefPointX(); + ref[1] = hel_tmp.getRefPointY(); + ref[2] = hel_tmp.getRefPointZ(); + + ts->setReferencePoint(ref); + ts->setLocation(lcio::TrackState::AtIP); - + Track->addTrackState(ts); - + std::vector added_hits; - - for (unsigned i=0; iaddHit( hit_list[i].second ); - + + for (unsigned i = 0; i < hit_list.size(); i++) { + + Track->addHit(hit_list[i].second); } - - } - - streamlog_out( DEBUG3 ) << "Add Track " << Track << " to collection related to mcp -> " << mcp << std::endl; - + + streamlog_out(DEBUG3) << "Add Track " << Track << " to collection related to mcp -> " << mcp << std::endl; + _trackVec->addElement(Track); - + LCRelationImpl* rel = new LCRelationImpl; - rel->setFrom (Track); - rel->setTo (mcp); + rel->setFrom(Track); + rel->setTo(mcp); rel->setWeight(1.0); _trackRelVec->addElement(rel); - + _nCreatedTracks++; - - } +void TruthTracker::createTrack_iterative(MCParticle* mcp, UTIL::BitField64& cellID_encoder, + std::vector>& hit_list) { -void TruthTracker::createTrack_iterative( MCParticle* mcp, UTIL::BitField64& cellID_encoder, std::vector< std::pair >& hit_list ) { - - /////////////////////////////////////////////////////// - // check inputs + // check inputs /////////////////////////////////////////////////////// - - if( mcp == 0 ){ - throw EVENT::Exception( std::string("TruthTracker::createTrack: MCParticle == NULL ") ) ; + + if (mcp == 0) { + throw EVENT::Exception(std::string("TruthTracker::createTrack: MCParticle == NULL ")); } - - if ( hit_list.empty() ) { - throw EVENT::Exception( std::string("TruthTracker::createTrack: Hitlist is empty") ) ; + + if (hit_list.empty()) { + throw EVENT::Exception(std::string("TruthTracker::createTrack: Hitlist is empty")); } - int layer = 9 ; - int size = 3 ; - int marker = 1 ; - //int ml = 0 ; + int layer = 9; + int size = 3; + int marker = 1; + // int ml = 0 ; float helix_max_r = 0; float helix_max_z = 0; int color = 0; - + if (_UseEventDisplay) { - MarlinCED::newEvent(this , _detector_model_for_drawing ) ; - -// CEDPickingHandler &pHandler=CEDPickingHandler::getInstance(); -// -// pHandler.update(_current_event); - + MarlinCED::newEvent(this, _detector_model_for_drawing); + + // CEDPickingHandler &pHandler=CEDPickingHandler::getInstance(); + // + // pHandler.update(_current_event); helix_max_z = fabs(mcp->getEndpoint()[2]); - - streamlog_out(MESSAGE) << "Draw MCParticle : " << *mcp <getCharge(), mcp->getVertex()[0], mcp->getVertex()[1], mcp->getVertex()[2], - mcp->getMomentum()[0], mcp->getMomentum()[1], mcp->getMomentum()[2], layer , size , 0x7af774 , - 0.0, _helix_max_r , - helix_max_z, mcp->id() ) ; - - - - const std::string colName = "Hits_For_Fit"; - - - size = 10 ; - layer = 11 ; + + MarlinCED::drawHelix(_Bz, mcp->getCharge(), mcp->getVertex()[0], mcp->getVertex()[1], mcp->getVertex()[2], + mcp->getMomentum()[0], mcp->getMomentum()[1], mcp->getMomentum()[2], layer, size, 0x7af774, + 0.0, _helix_max_r, helix_max_z, mcp->id()); + + const std::string colName = "Hits_For_Fit"; + + size = 10; + layer = 11; // ml = marker | ( layer << CED_LAYER_SHIFT ) ; - - //ced_describe_layer( colName.c_str() ,layer); - MarlinCED::add_layer_description(colName, layer); - - - color = 0xFFFFFF; - - for( std::vector< std::pair >::const_iterator it = hit_list.begin(); it != hit_list.end() ; it++ ) { - - + + // ced_describe_layer( colName.c_str() ,layer); + MarlinCED::add_layer_description(colName, layer); + + color = 0xFFFFFF; + + for (std::vector>::const_iterator it = hit_list.begin(); + it != hit_list.end(); it++) { + TrackerHit* trkhit = (*it).second; - ced_hit_ID(trkhit->getPosition()[0], - trkhit->getPosition()[1], - trkhit->getPosition()[2], - marker, layer , size , color, trkhit->id() ) ; - + ced_hit_ID(trkhit->getPosition()[0], trkhit->getPosition()[1], trkhit->getPosition()[2], marker, layer, size, + color, trkhit->id()); + } // hits } - + std::vector track_segments; std::vector track_segments_rels; - + track_segments.reserve(10); - + TrackStateImpl* prefit_trackState = 0; - + // setup initial dummy covariance matrix EVENT::FloatVec initial_cov_matrix; initial_cov_matrix.resize(15); - - for (unsigned icov = 0; icov= 0; --j) { - + for (int j = hit_list.size() - 1; j >= 0; --j) { + TrackerHit* trkHit = hit_list[j].second; - + if (fit_running == false) { // try to start fit - + marlinTrk = _trksystem->createTrack(); - + running_number_of_rejected_hits = 0; - + // Check for spacepoints - if( BitSet32( trkHit->getType() )[ UTIL::ILDTrkHitTypeBit::COMPOSITE_SPACEPOINT ] ){ //it is a composite spacepoint - - //Split it up and add both hits to the MarlinTrk + if (BitSet32(trkHit->getType())[UTIL::ILDTrkHitTypeBit::COMPOSITE_SPACEPOINT]) { // it is a composite spacepoint + + // Split it up and add both hits to the MarlinTrk const LCObjectVec rawObjects = trkHit->getRawHits(); - - for( unsigned k=0; k< rawObjects.size(); k++ ){ - - TrackerHit* rawHit = dynamic_cast< TrackerHit* >( rawObjects[k] ); - if( marlinTrk->addHit( rawHit ) == IMarlinTrack::success ){ - - isSuccessful = true; //if at least one hit from the spacepoint gets added - - } - } - } - else { // normal non-composite tracker hit - - isSuccessful = marlinTrk->addHit( trkHit ) == IMarlinTrack::success; - - } - - if ( isSuccessful ) { - - added_hits.push_back( trkHit ); - // at this point one hit added successfully so break the for loop + + for (unsigned k = 0; k < rawObjects.size(); k++) { + + TrackerHit* rawHit = dynamic_cast(rawObjects[k]); + if (marlinTrk->addHit(rawHit) == IMarlinTrack::success) { + + isSuccessful = true; // if at least one hit from the spacepoint gets added + } + } + } else { // normal non-composite tracker hit + + isSuccessful = marlinTrk->addHit(trkHit) == IMarlinTrack::success; + } + + if (isSuccessful) { + + added_hits.push_back(trkHit); + // at this point one hit added successfully so break the for loop fit_running = true; - - // use the simhit to get the track parameters - + + // use the simhit to get the track parameters + SimTrackerHit* simhit_last = hit_list[j].first; - + double mcp_p_last[3]; - + mcp_p_last[0] = simhit_last->getMomentum()[0]; mcp_p_last[1] = simhit_last->getMomentum()[1]; mcp_p_last[2] = simhit_last->getMomentum()[2]; - - HelixTrack hel_at_end(simhit_last->getPosition(), mcp_p_last, mcp->getCharge(), _Bz ); - + + HelixTrack hel_at_end(simhit_last->getPosition(), mcp_p_last, mcp->getCharge(), _Bz); + // set up the initial track and fit parameters - - const float referencePoint[3] = { float(hel_at_end.getRefPointX()) , float(hel_at_end.getRefPointY()) , float(hel_at_end.getRefPointZ()) }; - - prefit_trackState = new TrackStateImpl( lcio::TrackState::AtLastHit, - hel_at_end.getD0(), - hel_at_end.getPhi0(), - hel_at_end.getOmega(), - hel_at_end.getZ0(), - hel_at_end.getTanLambda(), - initial_cov_matrix, - referencePoint) ; - - - // We now have either one 2-D hit or two 1-D hits added. + + const float referencePoint[3] = {float(hel_at_end.getRefPointX()), float(hel_at_end.getRefPointY()), + float(hel_at_end.getRefPointZ())}; + + prefit_trackState = new TrackStateImpl(lcio::TrackState::AtLastHit, hel_at_end.getD0(), hel_at_end.getPhi0(), + hel_at_end.getOmega(), hel_at_end.getZ0(), hel_at_end.getTanLambda(), + initial_cov_matrix, referencePoint); + + // We now have either one 2-D hit or two 1-D hits added. // So proceed with initialisation. - - streamlog_out( DEBUG3 ) << "\n Helix for prefit: " - << " d0 = " << prefit_trackState->getD0() - << " phi0 = " << prefit_trackState->getPhi() - << " omega = " << prefit_trackState->getOmega() - << " z0 = " << prefit_trackState->getZ0() - << " tanl = " << prefit_trackState->getTanLambda() - << " ref = " << prefit_trackState->getReferencePoint()[0] << " " << prefit_trackState->getReferencePoint()[1] << " " << prefit_trackState->getReferencePoint()[2] - << "\n" << std::endl; - - // set the initial track state for the track - marlinTrk->initialise( *prefit_trackState, _Bz, IMarlinTrack::backward ) ; - + + streamlog_out(DEBUG3) << "\n Helix for prefit: " + << " d0 = " << prefit_trackState->getD0() << " phi0 = " << prefit_trackState->getPhi() + << " omega = " << prefit_trackState->getOmega() + << " z0 = " << prefit_trackState->getZ0() + << " tanl = " << prefit_trackState->getTanLambda() + << " ref = " << prefit_trackState->getReferencePoint()[0] << " " + << prefit_trackState->getReferencePoint()[1] << " " + << prefit_trackState->getReferencePoint()[2] << "\n" + << std::endl; + + // set the initial track state for the track + marlinTrk->initialise(*prefit_trackState, _Bz, IMarlinTrack::backward); + if (_UseEventDisplay) { - - double pt = _Bz * 3e-4 / std::abs( prefit_trackState->getOmega() ) ; - double charge = ( prefit_trackState->getOmega() > 0. ? 1. : -1. ) ; - - double px = pt * std::cos( prefit_trackState->getPhi() ) ; - double py = pt * std::sin( prefit_trackState->getPhi() ) ; - double pz = pt * prefit_trackState->getTanLambda() ; - + + double pt = _Bz * 3e-4 / std::abs(prefit_trackState->getOmega()); + double charge = (prefit_trackState->getOmega() > 0. ? 1. : -1.); + + double px = pt * std::cos(prefit_trackState->getPhi()); + double py = pt * std::sin(prefit_trackState->getPhi()); + double pz = pt * prefit_trackState->getTanLambda(); + // start point for drawing ( PCA to reference point ) - - double xs = prefit_trackState->getReferencePoint()[0] - prefit_trackState->getD0() * sin( prefit_trackState->getPhi() ) ; - double ys = prefit_trackState->getReferencePoint()[1] + prefit_trackState->getD0() * cos( prefit_trackState->getPhi() ) ; - double zs = prefit_trackState->getReferencePoint()[2] + prefit_trackState->getZ0() ; - + + double xs = + prefit_trackState->getReferencePoint()[0] - prefit_trackState->getD0() * sin(prefit_trackState->getPhi()); + double ys = + prefit_trackState->getReferencePoint()[1] + prefit_trackState->getD0() * cos(prefit_trackState->getPhi()); + double zs = prefit_trackState->getReferencePoint()[2] + prefit_trackState->getZ0(); + helix_max_z = 2500.0; - - streamlog_out(MESSAGE) << " Draw TrackState for Prefit : " << *prefit_trackState <id() ) ; - + + MarlinCED::drawHelix(_Bz, charge, xs, ys, zs, px, py, pz, layer, size, 0xFFFFFF, 0.0, _helix_max_r, + helix_max_z, prefit_trackState->id()); } - + delete prefit_trackState; - - // filter the first 1 or 2 hits - int fit_status = marlinTrk->fit(_maxChi2PerHit) ; - - streamlog_out(DEBUG4) << "fit_status = " << fit_status << std::endl ; - - // check that first hit is accepted by the fit, if this fails we bail here as there is little chance of recovering. - - if ( fit_status != IMarlinTrack::success ) { // no chance to initialise print warning and return - streamlog_out(WARNING) << "TruthTracker::createTrack Initial Hit not accepted by the fit, track droped." << std::endl; + + // filter the first 1 or 2 hits + int fit_status = marlinTrk->fit(_maxChi2PerHit); + + streamlog_out(DEBUG4) << "fit_status = " << fit_status << std::endl; + + // check that first hit is accepted by the fit, if this fails we bail here as there is little chance of + // recovering. + + if (fit_status != IMarlinTrack::success) { // no chance to initialise print warning and return + streamlog_out(WARNING) << "TruthTracker::createTrack Initial Hit not accepted by the fit, track droped." + << std::endl; delete marlinTrk; return; - } - + } + else { index_of_last_added_hit = j; } - } + } } // continue to loop over the hits adding them to the fit - else { - + else { + isSuccessful = false; - + // Check for spacepoints - if( BitSet32( trkHit->getType() )[ UTIL::ILDTrkHitTypeBit::COMPOSITE_SPACEPOINT ] ){ //it is a composite spacepoint - - //Split it up and add both hits to the MarlinTrk - const LCObjectVec rawObjects = trkHit->getRawHits(); - - for( int k=rawObjects.size()-1 ; k >= 0; --k ){ - - TrackerHit* rawHit = dynamic_cast< TrackerHit* >( rawObjects[k] ); - + if (BitSet32(trkHit->getType())[UTIL::ILDTrkHitTypeBit::COMPOSITE_SPACEPOINT]) { // it is a composite spacepoint + + // Split it up and add both hits to the MarlinTrk + const LCObjectVec rawObjects = trkHit->getRawHits(); + + for (int k = rawObjects.size() - 1; k >= 0; --k) { + + TrackerHit* rawHit = dynamic_cast(rawObjects[k]); + double chi2inc = 0; - - if( marlinTrk->addAndFit(rawHit,chi2inc,_maxChi2PerHit) == IMarlinTrack::success ){ - - isSuccessful = true; //if at least one hit from the spacepoint gets added - + + if (marlinTrk->addAndFit(rawHit, chi2inc, _maxChi2PerHit) == IMarlinTrack::success) { + + isSuccessful = true; // if at least one hit from the spacepoint gets added } - } + } } // normal non composite tracker hit - else { - + else { + double chi2inc = 0; - - isSuccessful = marlinTrk->addAndFit(trkHit,chi2inc,_maxChi2PerHit) == IMarlinTrack::success ; - + + isSuccessful = marlinTrk->addAndFit(trkHit, chi2inc, _maxChi2PerHit) == IMarlinTrack::success; } - - if ( isSuccessful ) { - added_hits.push_back( trkHit ); + + if (isSuccessful) { + added_hits.push_back(trkHit); index_of_last_added_hit = j; running_number_of_rejected_hits = 0; - } - else { + } else { ++running_number_of_rejected_hits; - + // if the running number of rejected hits reaches 3 try to save current track and start a new one if (running_number_of_rejected_hits > 3) { - - if (added_hits.size()>3) { - - if(_SmoothOn) marlinTrk->smooth(); - + + if (added_hits.size() > 3) { + + if (_SmoothOn) + marlinTrk->smooth(); + IMPL::TrackImpl* Track = new IMPL::TrackImpl(); - int error = MarlinTrk::finaliseLCIOTrack(marlinTrk, Track, added_hits, IMarlinTrack::backward); - - std::vector > hits_in_fit ; - std::vector > outliers ; - std::vector all_hits; + int error = MarlinTrk::finaliseLCIOTrack(marlinTrk, Track, added_hits, IMarlinTrack::backward); + + std::vector> hits_in_fit; + std::vector> outliers; + std::vector all_hits; all_hits.reserve(300); - + marlinTrk->getHitsInFit(hits_in_fit); - - for ( unsigned ihit = 0; ihit < hits_in_fit.size(); ++ihit) { + + for (unsigned ihit = 0; ihit < hits_in_fit.size(); ++ihit) { all_hits.push_back(hits_in_fit[ihit].first); } - + MarlinTrk::addHitNumbersToTrack(Track, all_hits, true, cellID_encoder); - + marlinTrk->getOutliers(outliers); - - for ( unsigned ihit = 0; ihit < outliers.size(); ++ihit) { + + for (unsigned ihit = 0; ihit < outliers.size(); ++ihit) { all_hits.push_back(outliers[ihit].first); } - + MarlinTrk::addHitNumbersToTrack(Track, all_hits, false, cellID_encoder); - delete marlinTrk; marlinTrk=0; - + delete marlinTrk; + marlinTrk = 0; + fit_running = false; - + if (error == IMarlinTrack::success) { - streamlog_out( DEBUG3 ) << "Add Track " << Track << " to collection related to mcp -> " << mcp << std::endl; - + streamlog_out(DEBUG3) << "Add Track " << Track << " to collection related to mcp -> " << mcp << std::endl; + track_segments.push_back(Track); -// _trackVec->addElement(Track); - + // _trackVec->addElement(Track); + LCRelationImpl* rel = new LCRelationImpl; - rel->setFrom (Track); - rel->setTo (mcp); + rel->setFrom(Track); + rel->setTo(mcp); rel->setWeight(1.0); - + track_segments_rels.push_back(rel); -// _trackRelVec->addElement(rel); - + // _trackRelVec->addElement(rel); + _nCreatedTracks++; if (_UseEventDisplay) { const EVENT::TrackState* trkStateIP = Track->getTrackState(EVENT::TrackState::AtIP); - - double pt = _Bz * 3e-4 / std::abs( trkStateIP->getOmega() ) ; - double charge = ( trkStateIP->getOmega() > 0. ? 1. : -1. ) ; - - double px = pt * std::cos( trkStateIP->getPhi() ) ; - double py = pt * std::sin( trkStateIP->getPhi() ) ; - double pz = pt * trkStateIP->getTanLambda() ; - + + double pt = _Bz * 3e-4 / std::abs(trkStateIP->getOmega()); + double charge = (trkStateIP->getOmega() > 0. ? 1. : -1.); + + double px = pt * std::cos(trkStateIP->getPhi()); + double py = pt * std::sin(trkStateIP->getPhi()); + double pz = pt * trkStateIP->getTanLambda(); + // start point for drawing ( PCA to reference point ) - - double xs = trkStateIP->getReferencePoint()[0] - trkStateIP->getD0() * sin( trkStateIP->getPhi() ) ; - double ys = trkStateIP->getReferencePoint()[1] + trkStateIP->getD0() * cos( trkStateIP->getPhi() ) ; - double zs = trkStateIP->getReferencePoint()[2] + trkStateIP->getZ0() ; - + + double xs = trkStateIP->getReferencePoint()[0] - trkStateIP->getD0() * sin(trkStateIP->getPhi()); + double ys = trkStateIP->getReferencePoint()[1] + trkStateIP->getD0() * cos(trkStateIP->getPhi()); + double zs = trkStateIP->getReferencePoint()[2] + trkStateIP->getZ0(); + helix_max_z = fabs(hit_list.back().second->getPosition()[2]); - - streamlog_out(MESSAGE) << "Draw Partial TrackState : " << *trkStateIP <id() ) ; - - // ml = marker | ( layer+10 << CED_LAYER_SHIFT ) ; - - for( std::vector::const_iterator it = added_hits.begin(); it != added_hits.end() ; it++ ) { - - ced_hit_ID((*it)->getPosition()[0], - (*it)->getPosition()[1], - (*it)->getPosition()[2], - marker, layer+10 , 4 , color, (*it)->id() ) ; - + size = 4; + + // MarlinCED::add_layer_description("TrackState_From_Fit", layer); + + color = _colours[j % _colours.size()]; + + MarlinCED::drawHelix(_Bz, charge, xs, ys, zs, px, py, pz, layer, size, color, 0.0, helix_max_r, + helix_max_z, trkStateIP->id()); + + // ml = marker | ( layer+10 << CED_LAYER_SHIFT ) ; + + for (std::vector::const_iterator it = added_hits.begin(); it != added_hits.end(); it++) { + + ced_hit_ID((*it)->getPosition()[0], (*it)->getPosition()[1], (*it)->getPosition()[2], marker, + layer + 10, 4, color, (*it)->id()); + } // hits - } + } } } // reject track else { - - streamlog_out( DEBUG3 ) << "Reject Track : number of hits = " << added_hits.size() << " for MCParticle -> " << mcp << std::endl; - + + streamlog_out(DEBUG3) << "Reject Track : number of hits = " << added_hits.size() << " for MCParticle -> " + << mcp << std::endl; + #ifdef MARLINTRK_DIAGNOSTICS_ON - void * dcv = _trksystem->getDiagnositicsPointer(); + void* dcv = _trksystem->getDiagnositicsPointer(); DiagnosticsController* dc = static_cast(dcv); dc->skip_current_track(); - -#endif - delete marlinTrk; marlinTrk=0; +#endif + delete marlinTrk; + marlinTrk = 0; } - - // set the counter back to the one after the last hit added + + // set the counter back to the one after the last hit added j = index_of_last_added_hit; running_number_of_rejected_hits = 0; added_hits.clear(); fit_running = false; - } } - } - + } + if (j == 0) { - if (added_hits.size()>3) { + if (added_hits.size() > 3) { + + if (_SmoothOn) + marlinTrk->smooth(); - if(_SmoothOn) marlinTrk->smooth(); - IMPL::TrackImpl* Track = new IMPL::TrackImpl(); - int error = MarlinTrk::finaliseLCIOTrack(marlinTrk, Track, added_hits, IMarlinTrack::backward); + int error = MarlinTrk::finaliseLCIOTrack(marlinTrk, Track, added_hits, IMarlinTrack::backward); - std::vector > hits_in_fit ; - std::vector > outliers ; - std::vector all_hits; + std::vector> hits_in_fit; + std::vector> outliers; + std::vector all_hits; all_hits.reserve(300); - + marlinTrk->getHitsInFit(hits_in_fit); - - for ( unsigned ihit = 0; ihit < hits_in_fit.size(); ++ihit) { + + for (unsigned ihit = 0; ihit < hits_in_fit.size(); ++ihit) { all_hits.push_back(hits_in_fit[ihit].first); } - + MarlinTrk::addHitNumbersToTrack(Track, all_hits, true, cellID_encoder); - + marlinTrk->getOutliers(outliers); - - for ( unsigned ihit = 0; ihit < outliers.size(); ++ihit) { + + for (unsigned ihit = 0; ihit < outliers.size(); ++ihit) { all_hits.push_back(outliers[ihit].first); } - + MarlinTrk::addHitNumbersToTrack(Track, all_hits, false, cellID_encoder); - delete marlinTrk; marlinTrk=0; - + delete marlinTrk; + marlinTrk = 0; + if (error == IMarlinTrack::success) { - streamlog_out( DEBUG3 ) << "Add Track " << Track << " to collection related to mcp -> " << mcp << std::endl; - + streamlog_out(DEBUG3) << "Add Track " << Track << " to collection related to mcp -> " << mcp << std::endl; + track_segments.push_back(Track); -// _trackVec->addElement(Track); - + // _trackVec->addElement(Track); + LCRelationImpl* rel = new LCRelationImpl; - rel->setFrom (Track); - rel->setTo (mcp); + rel->setFrom(Track); + rel->setTo(mcp); rel->setWeight(1.0); -// _trackRelVec->addElement(rel); - track_segments_rels.push_back(rel); - + // _trackRelVec->addElement(rel); + track_segments_rels.push_back(rel); + _nCreatedTracks++; - if(_UseEventDisplay){ - + if (_UseEventDisplay) { + const EVENT::TrackState* trkStateIP = Track->getTrackState(EVENT::TrackState::AtIP); - - double pt = _Bz * 3e-4 / std::abs( trkStateIP->getOmega() ) ; - double charge = ( trkStateIP->getOmega() > 0. ? 1. : -1. ) ; - - double px = pt * std::cos( trkStateIP->getPhi() ) ; - double py = pt * std::sin( trkStateIP->getPhi() ) ; - double pz = pt * trkStateIP->getTanLambda() ; - + + double pt = _Bz * 3e-4 / std::abs(trkStateIP->getOmega()); + double charge = (trkStateIP->getOmega() > 0. ? 1. : -1.); + + double px = pt * std::cos(trkStateIP->getPhi()); + double py = pt * std::sin(trkStateIP->getPhi()); + double pz = pt * trkStateIP->getTanLambda(); + // start point for drawing ( PCA to reference point ) - - double xs = trkStateIP->getReferencePoint()[0] - trkStateIP->getD0() * sin( trkStateIP->getPhi() ) ; - double ys = trkStateIP->getReferencePoint()[1] + trkStateIP->getD0() * cos( trkStateIP->getPhi() ) ; - double zs = trkStateIP->getReferencePoint()[2] + trkStateIP->getZ0() ; - + + double xs = trkStateIP->getReferencePoint()[0] - trkStateIP->getD0() * sin(trkStateIP->getPhi()); + double ys = trkStateIP->getReferencePoint()[1] + trkStateIP->getD0() * cos(trkStateIP->getPhi()); + double zs = trkStateIP->getReferencePoint()[2] + trkStateIP->getZ0(); + helix_max_z = fabs(hit_list.back().second->getPosition()[2]); - - streamlog_out(MESSAGE) << " Draw Single TrackState : " << *trkStateIP <id() ) ; - - //ml = marker | ( layer+10 << CED_LAYER_SHIFT ) ; - - for( std::vector::const_iterator it = added_hits.begin(); it != added_hits.end() ; it++ ) { - - ced_hit_ID((*it)->getPosition()[0], - (*it)->getPosition()[1], - (*it)->getPosition()[2], - marker, layer+10 , 4 , color, (*it)->id() ) ; - + + MarlinCED::drawHelix(_Bz, charge, xs, ys, zs, px, py, pz, layer, size, color, 0.0, _helix_max_r, + helix_max_z, trkStateIP->id()); + + // ml = marker | ( layer+10 << CED_LAYER_SHIFT ) ; + + for (std::vector::const_iterator it = added_hits.begin(); it != added_hits.end(); it++) { + + ced_hit_ID((*it)->getPosition()[0], (*it)->getPosition()[1], (*it)->getPosition()[2], marker, layer + 10, + 4, color, (*it)->id()); + } // hits - } - } + } + } } // reject track else { - - streamlog_out( DEBUG3 ) << "Reject Track : number of hits = " << added_hits.size() << " for MCParticle -> " << mcp << std::endl; + + streamlog_out(DEBUG3) << "Reject Track : number of hits = " << added_hits.size() << " for MCParticle -> " << mcp + << std::endl; #ifdef MARLINTRK_DIAGNOSTICS_ON - - void * dcv = _trksystem->getDiagnositicsPointer(); + + void* dcv = _trksystem->getDiagnositicsPointer(); DiagnosticsController* dc = static_cast(dcv); dc->skip_current_track(); - -#endif - delete marlinTrk; marlinTrk=0; +#endif + delete marlinTrk; + marlinTrk = 0; } } - - } // end reverse loop over trakerhits - - + + } // end reverse loop over trakerhits + // now check how many track segments were created if (track_segments.size() != track_segments_rels.size()) { - throw EVENT::Exception( std::string("TruthTracker::createTrack_iterative: missmatch in size of track_segments and track_segments_rels") ) ; + throw EVENT::Exception(std::string( + "TruthTracker::createTrack_iterative: missmatch in size of track_segments and track_segments_rels")); } - + if (track_segments.size() == 1) { // only 1 track element so just add it to the collection _trackVec->addElement(track_segments[0]); _trackRelVec->addElement(track_segments_rels[0]); - } else if(track_segments.size() != 0 ){ - // as the hits are looped over in reverse then the first track segment will be the one which should + } else if (track_segments.size() != 0) { + // as the hits are looped over in reverse then the first track segment will be the one which should // be used for the fit at the calo face, the last will be the one used for the IP // create a track which will be composed from the segements IMPL::TrackImpl* Track = new IMPL::TrackImpl(); - - for (unsigned itrkseg=0; itrksegaddElement(rel); Track->addTrack(seg); - - EVENT::TrackerHitVec hits = seg->getTrackerHits(); - - for (unsigned ihit=0; ihitgetTrackerHits(); + + for (unsigned ihit = 0; ihit < hits.size(); ++ihit) { Track->addHit(hits[ihit]); } - + EVENT::IntVec hitNums = seg->getSubdetectorHitNumbers(); Track->subdetectorHitNumbers().resize(hitNums.size()); - - for (unsigned index=0; indexsubdetectorHitNumbers()[index] += hitNums[index]; } - - } - + EVENT::Track* innerMostSegment = track_segments.back(); EVENT::Track* outerMostSegment = track_segments.front(); Track->setNdf(innerMostSegment->getNdf()); Track->setChi2(innerMostSegment->getChi2()); - + IMPL::TrackStateImpl* atIP = new IMPL::TrackStateImpl(*innerMostSegment->getTrackState(EVENT::TrackState::AtIP)); Track->addTrackState(atIP); - IMPL::TrackStateImpl* atFirstHit = new IMPL::TrackStateImpl(*innerMostSegment->getTrackState(EVENT::TrackState::AtFirstHit)); + IMPL::TrackStateImpl* atFirstHit = + new IMPL::TrackStateImpl(*innerMostSegment->getTrackState(EVENT::TrackState::AtFirstHit)); Track->addTrackState(atFirstHit); Track->setRadiusOfInnermostHit(innerMostSegment->getRadiusOfInnermostHit()); - - IMPL::TrackStateImpl* atLastHit = new IMPL::TrackStateImpl(*outerMostSegment->getTrackState(EVENT::TrackState::AtLastHit)); - + + IMPL::TrackStateImpl* atLastHit = + new IMPL::TrackStateImpl(*outerMostSegment->getTrackState(EVENT::TrackState::AtLastHit)); + Track->addTrackState(atLastHit); - IMPL::TrackStateImpl* atCalo = new IMPL::TrackStateImpl(*outerMostSegment->getTrackState(EVENT::TrackState::AtCalorimeter)); - - Track->addTrackState(atCalo); - - + IMPL::TrackStateImpl* atCalo = + new IMPL::TrackStateImpl(*outerMostSegment->getTrackState(EVENT::TrackState::AtCalorimeter)); + + Track->addTrackState(atCalo); + _trackVec->addElement(Track); - + LCRelationImpl* rel = new LCRelationImpl; - rel->setFrom (Track); - rel->setTo (mcp); + rel->setFrom(Track); + rel->setTo(mcp); rel->setWeight(1.0); _trackRelVec->addElement(rel); - } - - - + if (_UseEventDisplay) { this->drawEvent(); } delete marlinTrk; // just to be sure - } -void TruthTracker::createTrack_old( MCParticle* mcp, UTIL::BitField64& cellID_encoder, std::vector& hit_list ) { - - - TrackImpl* Track = new TrackImpl ; - - streamlog_out( DEBUG3 ) << "Create track with " << hit_list.size() << " hits" << std::endl; - +void TruthTracker::createTrack_old(MCParticle* mcp, UTIL::BitField64& cellID_encoder, + std::vector& hit_list) { + + TrackImpl* Track = new TrackImpl; + + streamlog_out(DEBUG3) << "Create track with " << hit_list.size() << " hits" << std::endl; + // check that there are actually hits to fit - if ( hit_list.empty() ) return; - - HelixTrack hel(mcp->getVertex(), mcp->getMomentum(), mcp->getCharge(), _Bz ); - streamlog_out( DEBUG3 ) << "\n MCParticle paramters: " - << " d0 " << hel.getD0() - << " phi0 " << hel.getPhi0() - << " omega "<< hel.getOmega() - << " z0 "<< hel.getZ0() - << " tanl "<< hel.getTanLambda() - << "\n" << std::endl; - + if (hit_list.empty()) + return; + + HelixTrack hel(mcp->getVertex(), mcp->getMomentum(), mcp->getCharge(), _Bz); + streamlog_out(DEBUG3) << "\n MCParticle paramters: " + << " d0 " << hel.getD0() << " phi0 " << hel.getPhi0() << " omega " << hel.getOmega() << " z0 " + << hel.getZ0() << " tanl " << hel.getTanLambda() << "\n" + << std::endl; + double d0; double phi0; double omega; double z0; double tanL; - - double chi2 = 0 ; - int ndf = 0 ; - + + double chi2 = 0; + int ndf = 0; + float ref[3]; - + TrackerHitVec added_hits; - - if( _FitTracksWithMarlinTrk ) { - + + if (_FitTracksWithMarlinTrk) { + TrackStateImpl* prefit_trackState = 0; - - + // setup initial dummy covariance matrix EVENT::FloatVec covMatrix; covMatrix.resize(15); - - for (unsigned icov = 0; icov > r2_values; - - for (TrackerHitVec::iterator it=hit_list.begin(); it!=hit_list.end(); ++it) { + + covMatrix[0] = (_initialTrackError_d0); // sigma_d0^2 + covMatrix[2] = (_initialTrackError_phi0); // sigma_phi0^2 + covMatrix[5] = (_initialTrackError_omega); // sigma_omega^2 + covMatrix[9] = (_initialTrackError_z0); // sigma_z0^2 + covMatrix[14] = (_initialTrackError_tanL); // sigma_tanl^2 + + // First sort the hits in R, so here we are assuming that the track came from the IP and that we want to fit out to + // in. + std::vector> r2_values; + + for (TrackerHitVec::iterator it = hit_list.begin(); it != hit_list.end(); ++it) { EVENT::TrackerHit* h = *it; - float r2 = h->getPosition()[0]*h->getPosition()[0]+h->getPosition()[1]*h->getPosition()[1]; + float r2 = h->getPosition()[0] * h->getPosition()[0] + h->getPosition()[1] * h->getPosition()[1]; r2_values.push_back(std::make_pair(r2, *it)); } - - sort(r2_values.begin(),r2_values.end()); - + + sort(r2_values.begin(), r2_values.end()); + hit_list.clear(); hit_list.resize(r2_values.size()); - - for (std::vector< std::pair >::iterator it=r2_values.begin(); it!=r2_values.end(); ++it) { + + for (std::vector>::iterator it = r2_values.begin(); it != r2_values.end(); + ++it) { hit_list.push_back(it->second); } - - // loop over all the hits and create a list consisting only 2D hits - + + // loop over all the hits and create a list consisting only 2D hits + TrackerHitVec twoD_hits; - - for (unsigned ihit=0; ihit < hit_list.size(); ++ihit) { - - // check if this a space point or 2D hit - if(BitSet32( hit_list[ihit]->getType() )[ UTIL::ILDTrkHitTypeBit::ONE_DIMENSIONAL ] == false ){ - // then add to the list + + for (unsigned ihit = 0; ihit < hit_list.size(); ++ihit) { + + // check if this a space point or 2D hit + if (BitSet32(hit_list[ihit]->getType())[UTIL::ILDTrkHitTypeBit::ONE_DIMENSIONAL] == false) { + // then add to the list twoD_hits.push_back(hit_list[ihit]); - } } - - + // now either take the MCParticle parameters directly, use a full prefit or create a helix from 3 2-D hits - - if( _useMCParticleParametersFotInitOfFit ){ - - hel.moveRefPoint(hit_list.front()->getPosition()[0], hit_list.front()->getPosition()[1], hit_list.front()->getPosition()[2]); - - const float referencePoint[3] = { float(hel.getRefPointX()) , float(hel.getRefPointY()) , float(hel.getRefPointZ()) }; - - prefit_trackState = new TrackStateImpl( lcio::TrackState::AtIP, - hel.getD0(), - hel.getPhi0(), - hel.getOmega(), - hel.getZ0(), - hel.getTanLambda(), - covMatrix, - referencePoint) ; - - } - else { // use 2-D hits to start fit either simple helix construction or full prefit - - // check that there are enough 2-D hits to create a helix + + if (_useMCParticleParametersFotInitOfFit) { + + hel.moveRefPoint(hit_list.front()->getPosition()[0], hit_list.front()->getPosition()[1], + hit_list.front()->getPosition()[2]); + + const float referencePoint[3] = {float(hel.getRefPointX()), float(hel.getRefPointY()), float(hel.getRefPointZ())}; + + prefit_trackState = new TrackStateImpl(lcio::TrackState::AtIP, hel.getD0(), hel.getPhi0(), hel.getOmega(), + hel.getZ0(), hel.getTanLambda(), covMatrix, referencePoint); + + } else { // use 2-D hits to start fit either simple helix construction or full prefit + + // check that there are enough 2-D hits to create a helix if (twoD_hits.size() < 3) { // no chance to initialise print warning and return - streamlog_out(WARNING) << "TruthTracker::createTrack Cannot create helix from less than 3 2-D hits" << std::endl; + streamlog_out(WARNING) << "TruthTracker::createTrack Cannot create helix from less than 3 2-D hits" + << std::endl; delete Track; return; } - + // make a helix from 3 hits to get a trackstate - // SJA:FIXME: this may not be the optimal 3 hits to take in certain cases where the 3 hits are not well spread over the track length + // SJA:FIXME: this may not be the optimal 3 hits to take in certain cases where the 3 hits are not well spread + // over the track length const double* x1 = twoD_hits[0]->getPosition(); - const double* x2 = twoD_hits[ twoD_hits.size()/2 ]->getPosition(); + const double* x2 = twoD_hits[twoD_hits.size() / 2]->getPosition(); const double* x3 = twoD_hits.back()->getPosition(); - - HelixTrack helixTrack( x1, x2, x3, _Bz, HelixTrack::forwards ); - - helixTrack.moveRefPoint(hit_list.back()->getPosition()[0], hit_list.back()->getPosition()[1], hit_list.back()->getPosition()[2]); - - const float referencePoint[3] = { float(helixTrack.getRefPointX()) , float(helixTrack.getRefPointY()) , float(helixTrack.getRefPointZ()) }; - - prefit_trackState = new TrackStateImpl( lcio::TrackState::AtIP, - helixTrack.getD0(), - helixTrack.getPhi0(), - helixTrack.getOmega(), - helixTrack.getZ0(), - helixTrack.getTanLambda(), - covMatrix, - referencePoint) ; - - + + HelixTrack helixTrack(x1, x2, x3, _Bz, HelixTrack::forwards); + + helixTrack.moveRefPoint(hit_list.back()->getPosition()[0], hit_list.back()->getPosition()[1], + hit_list.back()->getPosition()[2]); + + const float referencePoint[3] = {float(helixTrack.getRefPointX()), float(helixTrack.getRefPointY()), + float(helixTrack.getRefPointZ())}; + + prefit_trackState = + new TrackStateImpl(lcio::TrackState::AtIP, helixTrack.getD0(), helixTrack.getPhi0(), helixTrack.getOmega(), + helixTrack.getZ0(), helixTrack.getTanLambda(), covMatrix, referencePoint); + // if performing full pre fit use prefit_trackState and improve with full fit - - if ( _create_prefit_using_MarlinTrk){ - - - + + if (_create_prefit_using_MarlinTrk) { + MarlinTrk::IMarlinTrack* prefit_trk = _trksystem->createTrack(); - + #ifdef MARLINTRK_DIAGNOSTICS_ON - - void * dcv = _trksystem->getDiagnositicsPointer(); + + void* dcv = _trksystem->getDiagnositicsPointer(); DiagnosticsController* dc = static_cast(dcv); dc->skip_current_track(); - + #endif - - + EVENT::TrackerHitVec::iterator it = hit_list.begin(); - + streamlog_out(DEBUG2) << "Start Pre Fit: AddHits: number of hits to fit " << hit_list.size() << std::endl; - + int pre_fit_ndof_added = 0; TrackerHitVec pre_fit_added_hits; - - for( it = hit_list.begin() ; it != hit_list.end() ; ++it ) { - + + for (it = hit_list.begin(); it != hit_list.end(); ++it) { + TrackerHit* trkHit = *it; - bool isSuccessful = false; - - if( BitSet32( trkHit->getType() )[ UTIL::ILDTrkHitTypeBit::COMPOSITE_SPACEPOINT ] ){ //it is a composite spacepoint - - //Split it up and add both hits to the MarlinTrk - const LCObjectVec rawObjects = trkHit->getRawHits(); - - for( unsigned k=0; k< rawObjects.size(); k++ ){ - - TrackerHit* rawHit = dynamic_cast< TrackerHit* >( rawObjects[k] ); - - if( prefit_trk->addHit( rawHit ) == IMarlinTrack::success ){ - - isSuccessful = true; //if at least one hit from the spacepoint gets added + bool isSuccessful = false; + + if (BitSet32( + trkHit->getType())[UTIL::ILDTrkHitTypeBit::COMPOSITE_SPACEPOINT]) { // it is a composite spacepoint + + // Split it up and add both hits to the MarlinTrk + const LCObjectVec rawObjects = trkHit->getRawHits(); + + for (unsigned k = 0; k < rawObjects.size(); k++) { + + TrackerHit* rawHit = dynamic_cast(rawObjects[k]); + + if (prefit_trk->addHit(rawHit) == IMarlinTrack::success) { + + isSuccessful = true; // if at least one hit from the spacepoint gets added ++pre_fit_ndof_added; } } - } - else { // normal non composite hit - - if (prefit_trk->addHit( trkHit ) == IMarlinTrack::success ) { + } else { // normal non composite hit + + if (prefit_trk->addHit(trkHit) == IMarlinTrack::success) { isSuccessful = true; pre_fit_ndof_added += 2; } } - + if (isSuccessful) { pre_fit_added_hits.push_back(trkHit); } - - - else{ - streamlog_out(DEBUG4) << "Hit " << it - hit_list.begin() << " Dropped " << std::endl; + + else { + streamlog_out(DEBUG4) << "Hit " << it - hit_list.begin() << " Dropped " << std::endl; } - } - - if( pre_fit_ndof_added < 8 ) { - streamlog_out(DEBUG3) << "TruthTracker::Prefit failed: Cannot fit less with less than 8 degrees of freedom. Number of hits = " << pre_fit_added_hits.size() << " ndof = " << pre_fit_ndof_added << std::endl; - delete prefit_trk ; + + if (pre_fit_ndof_added < 8) { + streamlog_out(DEBUG3) + << "TruthTracker::Prefit failed: Cannot fit less with less than 8 degrees of freedom. Number of hits = " + << pre_fit_added_hits.size() << " ndof = " << pre_fit_ndof_added << std::endl; + delete prefit_trk; delete prefit_trackState; return; } - - prefit_trk->initialise( *prefit_trackState, _Bz, IMarlinTrack::backward ) ; - + + prefit_trk->initialise(*prefit_trackState, _Bz, IMarlinTrack::backward); + delete prefit_trackState; - - int fit_status = prefit_trk->fit() ; - - if( fit_status != 0 ){ - streamlog_out(DEBUG3) << "TruthTracker::Prefit failed: fit_status = " << fit_status << std::endl; - delete prefit_trk ; + + int fit_status = prefit_trk->fit(); + + if (fit_status != 0) { + streamlog_out(DEBUG3) << "TruthTracker::Prefit failed: fit_status = " << fit_status << std::endl; + delete prefit_trk; return; } else { - - prefit_trackState = new TrackStateImpl() ; - - const Vector3D point(hit_list.back()->getPosition()[0],hit_list.back()->getPosition()[1],hit_list.back()->getPosition()[2]); // position of outermost hit - - int return_code = prefit_trk->propagate(point, *prefit_trackState, chi2, ndf ) ; - + + prefit_trackState = new TrackStateImpl(); + + const Vector3D point(hit_list.back()->getPosition()[0], hit_list.back()->getPosition()[1], + hit_list.back()->getPosition()[2]); // position of outermost hit + + int return_code = prefit_trk->propagate(point, *prefit_trackState, chi2, ndf); + // make sure that the track state can be propagated to the IP and that the NDF is not less than 0 - if ( return_code != 0 || ndf < 0 ) { - streamlog_out(WARNING) << "TruthTracker::createTrack Prefit: Track droped return_code for prefit propagation = " << return_code << " NDF = " << ndf << std::endl; + if (return_code != 0 || ndf < 0) { + streamlog_out(WARNING) + << "TruthTracker::createTrack Prefit: Track droped return_code for prefit propagation = " << return_code + << " NDF = " << ndf << std::endl; delete prefit_trackState; delete prefit_trk; return; } - - prefit_trackState->setLocation( lcio::TrackState::AtLastHit ) ; - + + prefit_trackState->setLocation(lcio::TrackState::AtLastHit); + // blow up covariance matrix - + prefit_trackState->setCovMatrix(covMatrix); - } - + delete prefit_trk; - } - } - + MarlinTrk::IMarlinTrack* marlin_trk = _trksystem->createTrack(); - - + // used to keep track of whether hits are accepted by the fitter before fitting - bool isSuccessful = false; - + bool isSuccessful = false; + // needed to keep track of which hit should used for the first addandfit call - int index_of_next_hit_to_fit = hit_list.size() - 1; - - - // to initialise we need to add at least one hit. + int index_of_next_hit_to_fit = hit_list.size() - 1; + + // to initialise we need to add at least one hit. // given that we need to also work with COMPOSITE_SPACEPOINT hits we will simply added both strip hits in this case. - // fit will then be called on the hits added and then addandFit will be used for the remaining hits to provide more feedback and control - - + // fit will then be called on the hits added and then addandFit will be used for the remaining hits to provide more + // feedback and control + // start by trying to add the last hit and break at the first accepted hit - for(int j=index_of_next_hit_to_fit; j >= 0; --j) { - + for (int j = index_of_next_hit_to_fit; j >= 0; --j) { + TrackerHit* trkHit = hit_list[j]; - + --index_of_next_hit_to_fit; // first decrement the index of the next hit to fit - + // Check for spacepoints - if( BitSet32( trkHit->getType() )[ UTIL::ILDTrkHitTypeBit::COMPOSITE_SPACEPOINT ] ){ //it is a composite spacepoint - - //Split it up and add both hits to the MarlinTrk + if (BitSet32(trkHit->getType())[UTIL::ILDTrkHitTypeBit::COMPOSITE_SPACEPOINT]) { // it is a composite spacepoint + + // Split it up and add both hits to the MarlinTrk const LCObjectVec rawObjects = trkHit->getRawHits(); - - for( unsigned k=0; k< rawObjects.size(); k++ ){ - - TrackerHit* rawHit = dynamic_cast< TrackerHit* >( rawObjects[k] ); - if( marlin_trk->addHit( rawHit ) == IMarlinTrack::success ){ - - isSuccessful = true; //if at least one hit from the spacepoint gets added - - } + + for (unsigned k = 0; k < rawObjects.size(); k++) { + + TrackerHit* rawHit = dynamic_cast(rawObjects[k]); + if (marlin_trk->addHit(rawHit) == IMarlinTrack::success) { + + isSuccessful = true; // if at least one hit from the spacepoint gets added + } } - } - else { // normal non-composite tracker hit - - isSuccessful = marlin_trk->addHit( trkHit ) == IMarlinTrack::success; - + } else { // normal non-composite tracker hit + + isSuccessful = marlin_trk->addHit(trkHit) == IMarlinTrack::success; } - - if ( isSuccessful ) { - added_hits.push_back( trkHit ); + + if (isSuccessful) { + added_hits.push_back(trkHit); // at this point one hit added successfully so break the for loop - break; - } - - } // end of reverse loop over hits - - // We now have either one 2-D hit or two 1-D hits added. - // So proceed with initialisation. - - - streamlog_out( DEBUG3 ) << "\n Helix for prefit: " - << " d0 = " << prefit_trackState->getD0() - << " phi0 = " << prefit_trackState->getPhi() - << " omega = " << prefit_trackState->getOmega() - << " z0 = " << prefit_trackState->getZ0() - << " tanl = " << prefit_trackState->getTanLambda() - << " ref = " << prefit_trackState->getReferencePoint()[0] << " " << prefit_trackState->getReferencePoint()[1] << " " << prefit_trackState->getReferencePoint()[2] - << "\n" << std::endl; - - - // set the initial track state for the track - marlin_trk->initialise( *prefit_trackState, _Bz, IMarlinTrack::backward ) ; - + break; + } + + } // end of reverse loop over hits + + // We now have either one 2-D hit or two 1-D hits added. + // So proceed with initialisation. + + streamlog_out(DEBUG3) << "\n Helix for prefit: " + << " d0 = " << prefit_trackState->getD0() << " phi0 = " << prefit_trackState->getPhi() + << " omega = " << prefit_trackState->getOmega() << " z0 = " << prefit_trackState->getZ0() + << " tanl = " << prefit_trackState->getTanLambda() + << " ref = " << prefit_trackState->getReferencePoint()[0] << " " + << prefit_trackState->getReferencePoint()[1] << " " + << prefit_trackState->getReferencePoint()[2] << "\n" + << std::endl; + + // set the initial track state for the track + marlin_trk->initialise(*prefit_trackState, _Bz, IMarlinTrack::backward); + delete prefit_trackState; - - // filter the first 1 or 2 hits - int fit_status = marlin_trk->fit() ; - - streamlog_out(DEBUG4) << "fit_status = " << fit_status << std::endl ; - - // check that first hit is accepted by the fit, if this fails we bail here as there is little chance of recovering. - - if ( fit_status != IMarlinTrack::success ) { // no chance to initialise print warning and return - streamlog_out(WARNING) << "TruthTracker::createTrack Initial Hit not accepted by the fit, track droped." << std::endl; + + // filter the first 1 or 2 hits + int fit_status = marlin_trk->fit(); + + streamlog_out(DEBUG4) << "fit_status = " << fit_status << std::endl; + + // check that first hit is accepted by the fit, if this fails we bail here as there is little chance of recovering. + + if (fit_status != IMarlinTrack::success) { // no chance to initialise print warning and return + streamlog_out(WARNING) << "TruthTracker::createTrack Initial Hit not accepted by the fit, track droped." + << std::endl; delete Track; delete marlin_trk; return; } - - - // now used addAndFit to add the remaining hits - for(int j=index_of_next_hit_to_fit; j >= 0; --j) { - + + // now used addAndFit to add the remaining hits + for (int j = index_of_next_hit_to_fit; j >= 0; --j) { + TrackerHit* trkHit = hit_list[j]; - + isSuccessful = false; - + // Check for spacepoints - if( BitSet32( trkHit->getType() )[ UTIL::ILDTrkHitTypeBit::COMPOSITE_SPACEPOINT ] ){ //it is a composite spacepoint - - //Split it up and add both hits to the MarlinTrk - const LCObjectVec rawObjects = trkHit->getRawHits(); - - for( int k=rawObjects.size()-1 ; k >= 0; --k ){ - - TrackerHit* rawHit = dynamic_cast< TrackerHit* >( rawObjects[k] ); - - double chi_incr=DBL_MAX; - - if( marlin_trk->addAndFit(rawHit,chi_incr) == IMarlinTrack::success ){ - - isSuccessful = true; //if at least one hit from the spacepoint gets added - + if (BitSet32(trkHit->getType())[UTIL::ILDTrkHitTypeBit::COMPOSITE_SPACEPOINT]) { // it is a composite spacepoint + + // Split it up and add both hits to the MarlinTrk + const LCObjectVec rawObjects = trkHit->getRawHits(); + + for (int k = rawObjects.size() - 1; k >= 0; --k) { + + TrackerHit* rawHit = dynamic_cast(rawObjects[k]); + + double chi_incr = DBL_MAX; + + if (marlin_trk->addAndFit(rawHit, chi_incr) == IMarlinTrack::success) { + + isSuccessful = true; // if at least one hit from the spacepoint gets added } - } - } - else { // normal non composite tracker hit - - double chi_incr=DBL_MAX; - - isSuccessful = marlin_trk->addAndFit(trkHit,chi_incr) == IMarlinTrack::success ; - + } + } else { // normal non composite tracker hit + + double chi_incr = DBL_MAX; + + isSuccessful = marlin_trk->addAndFit(trkHit, chi_incr) == IMarlinTrack::success; } - if ( isSuccessful ) added_hits.push_back( trkHit ); - } - - - const Vector3D point(0.,0.,0.); // nominal IP - - TrackStateImpl* trkStateIP = new TrackStateImpl() ; - - int return_code = marlin_trk->propagate(point, *trkStateIP, chi2, ndf ) ; - + if (isSuccessful) + added_hits.push_back(trkHit); + } + + const Vector3D point(0., 0., 0.); // nominal IP + + TrackStateImpl* trkStateIP = new TrackStateImpl(); + + int return_code = marlin_trk->propagate(point, *trkStateIP, chi2, ndf); + // make sure that the track state can be propagated to the IP and that the NDF is not less than 0 - if ( return_code != 0 || ndf < 0 ) { - streamlog_out(WARNING) << "TruthTracker::createTrack: Track droped return_code for propagation = " << return_code << " NDF = " << ndf << std::endl; + if (return_code != 0 || ndf < 0) { + streamlog_out(WARNING) << "TruthTracker::createTrack: Track droped return_code for propagation = " << return_code + << " NDF = " << ndf << std::endl; delete trkStateIP; delete marlin_trk; return; } - - trkStateIP->setLocation( lcio::TrackState::AtIP ) ; + + trkStateIP->setLocation(lcio::TrackState::AtIP); Track->trackStates().push_back(trkStateIP); Track->setChi2(chi2); Track->setNdf(ndf); - - std::vector > hits_in_fit; - + + std::vector> hits_in_fit; + marlin_trk->getHitsInFit(hits_in_fit); - - + EVENT::TrackerHit* first_trkhit = hits_in_fit.front().first; EVENT::TrackerHit* last_trkhit = hits_in_fit.back().first; - - // now loop over the hits and get the track State there - + + // now loop over the hits and get the track State there + for (unsigned ihit = 0; ihit < hits_in_fit.size(); ++ihit) { - + EVENT::TrackerHit* trkhit = hits_in_fit[ihit].first; - - if ( trkhit == 0 ) { - throw EVENT::Exception( std::string("TruthTracker::createTrack: TrackerHit pointer == NULL ") ) ; + + if (trkhit == 0) { + throw EVENT::Exception(std::string("TruthTracker::createTrack: TrackerHit pointer == NULL ")); } - + TrackStateImpl* ts = new TrackStateImpl; - return_code = marlin_trk->getTrackState(trkhit, *ts, chi2, ndf ) ; - - if(return_code !=MarlinTrk::IMarlinTrack::success){ - streamlog_out( DEBUG5 ) << " >>>>>>>>>>> TruthTracker::createTrack: could not get TrackState at Hit index " << ihit << std::endl ; + return_code = marlin_trk->getTrackState(trkhit, *ts, chi2, ndf); + + if (return_code != MarlinTrk::IMarlinTrack::success) { + streamlog_out(DEBUG5) << " >>>>>>>>>>> TruthTracker::createTrack: could not get TrackState at Hit index " + << ihit << std::endl; + } + + // SJA:FIXME: if the hit is 1D then the pivot will be set to 0,0,0 : what should we do? Probably propagate to the + // Space Point if there is one .... set the location for the first hit + if (trkhit == first_trkhit) { + ts->setLocation(lcio::TrackState::AtFirstHit); + } + // set the location for the last hit + else if (trkhit == last_trkhit) { + ts->setLocation(lcio::TrackState::AtLastHit); } - - // SJA:FIXME: if the hit is 1D then the pivot will be set to 0,0,0 : what should we do? Probably propagate to the Space Point if there is one .... - // set the location for the first hit - if ( trkhit == first_trkhit ) { - ts->setLocation( lcio::TrackState::AtFirstHit ) ; - } - // set the location for the last hit - else if( trkhit == last_trkhit ) { - ts->setLocation( lcio::TrackState::AtLastHit ) ; - } // set the location for the ihit'th hit with an offset of lcio::TrackState::AtFirstHit + 1000 else { - ts->setLocation( lcio::TrackState::AtFirstHit + 1000 + ihit ) ; + ts->setLocation(lcio::TrackState::AtFirstHit + 1000 + ihit); } - + Track->trackStates().push_back(ts); - } - - + // now get the state at the calo face - + TrackStateImpl* trkStateCalo = new TrackStateImpl; - - UTIL::BitField64 encoder( lcio::LCTrackerCellID::encoding_string() ) ; - encoder.reset() ; // reset to 0 - - encoder[lcio::LCTrackerCellID::subdet()] = lcio::ILDDetID::ECAL ; + + UTIL::BitField64 encoder(lcio::LCTrackerCellID::encoding_string()); + encoder.reset(); // reset to 0 + + encoder[lcio::LCTrackerCellID::subdet()] = lcio::ILDDetID::ECAL; encoder[lcio::LCTrackerCellID::side()] = lcio::ILDDetID::barrel; - encoder[lcio::LCTrackerCellID::layer()] = 0 ; - + encoder[lcio::LCTrackerCellID::layer()] = 0; + int detElementID = 0; - return_code = marlin_trk->propagateToLayer(encoder.lowWord(), last_trkhit, *trkStateCalo, chi2, ndf, detElementID, IMarlinTrack::modeForward ) ; - - if (return_code == MarlinTrk::IMarlinTrack::no_intersection ) { // try forward or backward - if (trkStateIP->getTanLambda()>0) { + return_code = marlin_trk->propagateToLayer(encoder.lowWord(), last_trkhit, *trkStateCalo, chi2, ndf, detElementID, + IMarlinTrack::modeForward); + + if (return_code == MarlinTrk::IMarlinTrack::no_intersection) { // try forward or backward + if (trkStateIP->getTanLambda() > 0) { encoder[lcio::LCTrackerCellID::side()] = lcio::ILDDetID::fwd; - } - else{ + } else { encoder[lcio::LCTrackerCellID::side()] = lcio::ILDDetID::bwd; } - return_code = marlin_trk->propagateToLayer(encoder.lowWord(), last_trkhit, *trkStateCalo, chi2, ndf, detElementID, IMarlinTrack::modeForward ) ; + return_code = marlin_trk->propagateToLayer(encoder.lowWord(), last_trkhit, *trkStateCalo, chi2, ndf, detElementID, + IMarlinTrack::modeForward); } - - if (return_code !=MarlinTrk::IMarlinTrack::success ) { - streamlog_out( DEBUG5 ) << " >>>>>>>>>>> FinalRefit : could not get TrackState at Calo Face: return_code = " << return_code << std::endl ; + + if (return_code != MarlinTrk::IMarlinTrack::success) { + streamlog_out(DEBUG5) << " >>>>>>>>>>> FinalRefit : could not get TrackState at Calo Face: return_code = " + << return_code << std::endl; } - - - trkStateCalo->setLocation( lcio::TrackState::AtCalorimeter ) ; + + trkStateCalo->setLocation(lcio::TrackState::AtCalorimeter); Track->trackStates().push_back(trkStateCalo); - - delete marlin_trk; - - - } - else { - - + + delete marlin_trk; + + } else { + // use mcp pos and mom to set the track parameters - HelixTrack hel_tmp(mcp->getVertex(), mcp->getMomentum(), mcp->getCharge(), _Bz ); - d0 = hel_tmp.getD0(); - phi0 = hel_tmp.getPhi0(); + HelixTrack hel_tmp(mcp->getVertex(), mcp->getMomentum(), mcp->getCharge(), _Bz); + d0 = hel_tmp.getD0(); + phi0 = hel_tmp.getPhi0(); omega = hel_tmp.getOmega(); - z0 = hel_tmp.getZ0(); - tanL = hel_tmp.getTanLambda(); - - ref[0] = hel_tmp.getRefPointX() ; - ref[1] = hel_tmp.getRefPointY() ; - ref[2] = hel_tmp.getRefPointZ() ; - + z0 = hel_tmp.getZ0(); + tanL = hel_tmp.getTanLambda(); + + ref[0] = hel_tmp.getRefPointX(); + ref[1] = hel_tmp.getRefPointY(); + ref[2] = hel_tmp.getRefPointZ(); + Track->setD0(d0); Track->setPhi(phi0); Track->setOmega(omega); Track->setZ0(z0); Track->setTanLambda(tanL); - - Track->setReferencePoint(ref) ; - - + + Track->setReferencePoint(ref); + added_hits = hit_list; - } - - - - std::map hitNumbers; - + + std::map hitNumbers; + hitNumbers[lcio::ILDDetID::VXD] = 0; hitNumbers[lcio::ILDDetID::SIT] = 0; hitNumbers[lcio::ILDDetID::FTD] = 0; hitNumbers[lcio::ILDDetID::TPC] = 0; hitNumbers[lcio::ILDDetID::SET] = 0; hitNumbers[lcio::ILDDetID::ETD] = 0; - - for(unsigned int j=0; jaddHit(added_hits.at(j)) ; - - cellID_encoder.setValue(added_hits.at(j)->getCellID0()) ; + + for (unsigned int j = 0; j < added_hits.size(); ++j) { + + Track->addHit(added_hits.at(j)); + + cellID_encoder.setValue(added_hits.at(j)->getCellID0()); int detID = cellID_encoder[LCTrackerCellID::subdet()]; ++hitNumbers[detID]; - // streamlog_out( DEBUG1 ) << "Hit from Detector " << detID << std::endl; + // streamlog_out( DEBUG1 ) << "Hit from Detector " << detID << std::endl; } - - //SJA:FIXME no distiction made for hits in fit or not + + // SJA:FIXME no distiction made for hits in fit or not Track->subdetectorHitNumbers().resize(2 * lcio::ILDDetID::ETD); - Track->subdetectorHitNumbers()[ 2 * lcio::ILDDetID::VXD - 2 ] = hitNumbers[lcio::ILDDetID::VXD]; - Track->subdetectorHitNumbers()[ 2 * lcio::ILDDetID::FTD - 2 ] = hitNumbers[lcio::ILDDetID::FTD]; - Track->subdetectorHitNumbers()[ 2 * lcio::ILDDetID::SIT - 2 ] = hitNumbers[lcio::ILDDetID::SIT]; - Track->subdetectorHitNumbers()[ 2 * lcio::ILDDetID::TPC - 2 ] = hitNumbers[lcio::ILDDetID::TPC]; - Track->subdetectorHitNumbers()[ 2 * lcio::ILDDetID::SET - 2 ] = hitNumbers[lcio::ILDDetID::SET]; - Track->subdetectorHitNumbers()[ 2 * lcio::ILDDetID::ETD - 2 ] = hitNumbers[lcio::ILDDetID::ETD]; - Track->subdetectorHitNumbers()[ 2 * lcio::ILDDetID::VXD - 1 ] = hitNumbers[lcio::ILDDetID::VXD]; - Track->subdetectorHitNumbers()[ 2 * lcio::ILDDetID::FTD - 1 ] = hitNumbers[lcio::ILDDetID::FTD]; - Track->subdetectorHitNumbers()[ 2 * lcio::ILDDetID::SIT - 1 ] = hitNumbers[lcio::ILDDetID::SIT]; - Track->subdetectorHitNumbers()[ 2 * lcio::ILDDetID::TPC - 1 ] = hitNumbers[lcio::ILDDetID::TPC]; - Track->subdetectorHitNumbers()[ 2 * lcio::ILDDetID::SET - 1 ] = hitNumbers[lcio::ILDDetID::SET]; - Track->subdetectorHitNumbers()[ 2 * lcio::ILDDetID::ETD - 1 ] = hitNumbers[lcio::ILDDetID::ETD]; - + Track->subdetectorHitNumbers()[2 * lcio::ILDDetID::VXD - 2] = hitNumbers[lcio::ILDDetID::VXD]; + Track->subdetectorHitNumbers()[2 * lcio::ILDDetID::FTD - 2] = hitNumbers[lcio::ILDDetID::FTD]; + Track->subdetectorHitNumbers()[2 * lcio::ILDDetID::SIT - 2] = hitNumbers[lcio::ILDDetID::SIT]; + Track->subdetectorHitNumbers()[2 * lcio::ILDDetID::TPC - 2] = hitNumbers[lcio::ILDDetID::TPC]; + Track->subdetectorHitNumbers()[2 * lcio::ILDDetID::SET - 2] = hitNumbers[lcio::ILDDetID::SET]; + Track->subdetectorHitNumbers()[2 * lcio::ILDDetID::ETD - 2] = hitNumbers[lcio::ILDDetID::ETD]; + Track->subdetectorHitNumbers()[2 * lcio::ILDDetID::VXD - 1] = hitNumbers[lcio::ILDDetID::VXD]; + Track->subdetectorHitNumbers()[2 * lcio::ILDDetID::FTD - 1] = hitNumbers[lcio::ILDDetID::FTD]; + Track->subdetectorHitNumbers()[2 * lcio::ILDDetID::SIT - 1] = hitNumbers[lcio::ILDDetID::SIT]; + Track->subdetectorHitNumbers()[2 * lcio::ILDDetID::TPC - 1] = hitNumbers[lcio::ILDDetID::TPC]; + Track->subdetectorHitNumbers()[2 * lcio::ILDDetID::SET - 1] = hitNumbers[lcio::ILDDetID::SET]; + Track->subdetectorHitNumbers()[2 * lcio::ILDDetID::ETD - 1] = hitNumbers[lcio::ILDDetID::ETD]; + _trackVec->addElement(Track); - + LCRelationImpl* rel = new LCRelationImpl; - rel->setFrom (Track); - rel->setTo (mcp); + rel->setFrom(Track); + rel->setTo(mcp); rel->setWeight(1.0); _trackRelVec->addElement(rel); - + _nCreatedTracks++; - } -LCCollection* TruthTracker::GetCollection( LCEvent * evt, std::string colName ){ - +LCCollection* TruthTracker::GetCollection(LCEvent* evt, std::string colName) { + LCCollection* col = NULL; - + try { - col = evt->getCollection( colName.c_str() ) ; - streamlog_out( DEBUG4 ) << " --> " << colName.c_str() << " collection found, number of elements = " << col->getNumberOfElements() << std::endl; + col = evt->getCollection(colName.c_str()); + streamlog_out(DEBUG4) << " --> " << colName.c_str() + << " collection found, number of elements = " << col->getNumberOfElements() << std::endl; + } catch (DataNotAvailableException& e) { + streamlog_out(DEBUG4) << " --> " << colName.c_str() << " collection absent" << std::endl; } - catch(DataNotAvailableException &e) { - streamlog_out( DEBUG4 ) << " --> " << colName.c_str() << " collection absent" << std::endl; - } - - return col; - + + return col; } -LCRelationNavigator* TruthTracker::GetRelations(LCEvent * evt , std::string RelName ) { - - LCRelationNavigator* nav = NULL ; +LCRelationNavigator* TruthTracker::GetRelations(LCEvent* evt, std::string RelName) { + + LCRelationNavigator* nav = NULL; LCCollection* col = NULL; - - try{ - - col = evt->getCollection( RelName.c_str() ); - nav = new LCRelationNavigator( col ); - streamlog_out( DEBUG4 ) << " --> " << RelName << " track relation collection found, number of elements = " << col->getNumberOfElements() << std::endl; - } - catch(DataNotAvailableException &e){ - streamlog_out( ERROR ) << " --> " << RelName.c_str() << " track relation collection absent" << std::endl; + + try { + + col = evt->getCollection(RelName.c_str()); + nav = new LCRelationNavigator(col); + streamlog_out(DEBUG4) << " --> " << RelName + << " track relation collection found, number of elements = " << col->getNumberOfElements() + << std::endl; + } catch (DataNotAvailableException& e) { + streamlog_out(ERROR) << " --> " << RelName.c_str() << " track relation collection absent" << std::endl; } - + return nav; - } +void TruthTracker::drawEvent() { -void TruthTracker::drawEvent(){ - - LCCollection* colMCP = GetCollection(_current_event, _colNameMCParticles); - - if ( colMCP ) { - - for (int iMCP=0; iMCPgetNumberOfElements() ; ++iMCP) { - - MCParticle* mcp = dynamic_cast(colMCP->getElementAt(iMCP)) ; - - float pmag2 = mcp->getMomentum()[0]*mcp->getMomentum()[0] - + mcp->getMomentum()[1]*mcp->getMomentum()[1] + mcp->getMomentum()[2]*mcp->getMomentum()[2]; - - if ( fabs(mcp->getCharge())>0.01 && pmag2 > _MCpThreshold*_MCpThreshold) { - - - int layer = 0; - int size = 1 ; - - float helix_max_r = sqrt( mcp->getEndpoint()[0]*mcp->getEndpoint()[0] + mcp->getEndpoint()[1]*mcp->getEndpoint()[1]); - - helix_max_r = _helix_max_r; - - float helix_max_z = fabs(mcp->getEndpoint()[2]); - - MarlinCED::add_layer_description(_colNameMCParticles, layer); - - MarlinCED::drawHelix( _Bz , mcp->getCharge(), mcp->getVertex()[0], mcp->getVertex()[1], mcp->getVertex()[2], - mcp->getMomentum()[0], mcp->getMomentum()[1], mcp->getMomentum()[2], layer , size , _colours[iMCP%_colours.size()] , - 0.0, helix_max_r , - helix_max_z, mcp->id() ) ; - - } - - } + LCCollection* colMCP = GetCollection(_current_event, _colNameMCParticles); + + if (colMCP) { + + for (int iMCP = 0; iMCP < colMCP->getNumberOfElements(); ++iMCP) { + + MCParticle* mcp = dynamic_cast(colMCP->getElementAt(iMCP)); + + float pmag2 = mcp->getMomentum()[0] * mcp->getMomentum()[0] + mcp->getMomentum()[1] * mcp->getMomentum()[1] + + mcp->getMomentum()[2] * mcp->getMomentum()[2]; + + if (fabs(mcp->getCharge()) > 0.01 && pmag2 > _MCpThreshold * _MCpThreshold) { + + int layer = 0; + int size = 1; - + float helix_max_r = + sqrt(mcp->getEndpoint()[0] * mcp->getEndpoint()[0] + mcp->getEndpoint()[1] * mcp->getEndpoint()[1]); + + helix_max_r = _helix_max_r; + + float helix_max_z = fabs(mcp->getEndpoint()[2]); + + MarlinCED::add_layer_description(_colNameMCParticles, layer); + + MarlinCED::drawHelix(_Bz, mcp->getCharge(), mcp->getVertex()[0], mcp->getVertex()[1], mcp->getVertex()[2], + mcp->getMomentum()[0], mcp->getMomentum()[1], mcp->getMomentum()[2], layer, size, + _colours[iMCP % _colours.size()], 0.0, helix_max_r, helix_max_z, mcp->id()); + } + } } - - - - for( unsigned iCol=0; iCol<_colTrackerHits.size(); iCol++){ - - LCCollection* trackerHitCol = _colTrackerHits[iCol]; - - - int color = 0xee0044 ; - - int layer = iCol+1; + + for (unsigned iCol = 0; iCol < _colTrackerHits.size(); iCol++) { + + LCCollection* trackerHitCol = _colTrackerHits[iCol]; + + int color = 0xee0044; + + int layer = iCol + 1; int marker = 1; - int size = 10; + int size = 10; const std::string& colName = _colNamesTrackerHits[iCol]; - - //ced_describe_layer( colName.c_str() ,layer); - MarlinCED::add_layer_description(colName, layer); - - // draw a marker at hit position - LCTypedVector v( trackerHitCol ) ; - MarlinCED::drawObjectsWithPosition( v.begin(), v.end() , marker, size , color, layer) ; - - + + // ced_describe_layer( colName.c_str() ,layer); + MarlinCED::add_layer_description(colName, layer); + + // draw a marker at hit position + LCTypedVector v(trackerHitCol); + MarlinCED::drawObjectsWithPosition(v.begin(), v.end(), marker, size, color, layer); } - + int wait_for_keyboard = 1; //++++++++++++++++++++++++++++++++++++ - MarlinCED::draw(this, wait_for_keyboard ); + MarlinCED::draw(this, wait_for_keyboard); //++++++++++++++++++++++++++++++++++++ - } - - - - - diff --git a/source/Utils/include/CalcTrackerHitResiduals.h b/source/Utils/include/CalcTrackerHitResiduals.h index 357bf75..8521188 100644 --- a/source/Utils/include/CalcTrackerHitResiduals.h +++ b/source/Utils/include/CalcTrackerHitResiduals.h @@ -1,36 +1,35 @@ #ifndef CalcTrackerHitResiduals_h #define CalcTrackerHitResiduals_h 1 -#include "marlin/Processor.h" #include "lcio.h" +#include "marlin/Processor.h" #include -#include #include +#include #include -#include #include "UTIL/LCTrackerConf.h" +#include #include "DDRec/SurfaceManager.h" -//#include "DDRec/SurfaceHelper.h" +// #include "DDRec/SurfaceHelper.h" -namespace EVENT{ - class MCParticle ; - class Track ; -} +namespace EVENT { +class MCParticle; +class Track; +} // namespace EVENT namespace IMPL { - class TrackImpl ; +class TrackImpl; } -namespace UTIL{ - class LCRelationNavigator ; +namespace UTIL { +class LCRelationNavigator; } - -namespace MarlinTrk{ - class IMarlinTrkSystem ; +namespace MarlinTrk { +class IMarlinTrkSystem; } class TFile; @@ -38,118 +37,117 @@ class TH1F; #define MAXBUFFERSIZE 100 -/** Set the LCIO Extensions to relate SimTrackerHits to TrackerHits via a pointer. - * - +/** Set the LCIO Extensions to relate SimTrackerHits to TrackerHits via a pointer. + * + *

Input - Prerequisites

- * Needs a collections of LCIO TrackerHits. + * Needs a collections of LCIO TrackerHits. * * @param TrackerHitsInputCollections Name of the tracker hit input collections
* (default value: FTDTrackerHits SITTrackerHits TPCTrackerHits VXDTrackerHits ) - * - * @param TrackerHitsRelInputCollections Name of the lcrelation collections, that link the TrackerHits to their SimTrackerHits. + * + * @param TrackerHitsRelInputCollections Name of the lcrelation collections, that link the TrackerHits to their + SimTrackerHits. * Have to be in same order as TrackerHitsInputCollections!!!
* (default value: FTDTrackerHitRelations SITTrackerHitRelations TPCTrackerHitRelations VXDTrackerHitRelations ) - * - * - * - * @author S. J. Aplin, DESY - * + * + * + * + * @author S. J. Aplin, DESY + * */ class CalcTrackerHitResiduals : public marlin::Processor { - + public: - - virtual marlin::Processor* newProcessor() { return new CalcTrackerHitResiduals ; } - - - CalcTrackerHitResiduals() ; - + virtual marlin::Processor* newProcessor() { return new CalcTrackerHitResiduals; } + + CalcTrackerHitResiduals(); + /** Called at the begin of the job before anything is read. * Use to initialize the processor, e.g. book histograms. */ - virtual void init() ; - + virtual void init(); + /** Called for every run. */ - virtual void processRunHeader( LCRunHeader* run ) ; - + virtual void processRunHeader(LCRunHeader* run); + /** Called for every event - the working horse. */ - virtual void processEvent( LCEvent * evt ) ; - - - virtual void check( LCEvent * evt ) ; - - + virtual void processEvent(LCEvent* evt); + + virtual void check(LCEvent* evt); + /** Called after data processing for clean up. */ - virtual void end() ; - + virtual void end(); + protected: - -// void bookHistograms(); - + // void bookHistograms(); + void createHistogramBuffers(); - + void fill_histo(const std::string& name, float value); - - void write_buffer_to_histo( std::map*>::iterator it_buffer ); - - const LCObjectVec* getSimHits( TrackerHit* trkhit, const FloatVec* weights = NULL); - - + void write_buffer_to_histo(std::map*>::iterator it_buffer); + + const LCObjectVec* getSimHits(TrackerHit* trkhit, const FloatVec* weights = NULL); + UTIL::BitField64* _encoder; - int getDetectorID(TrackerHit* hit) { _encoder->setValue(hit->getCellID0()); return (*_encoder)[lcio::LCTrackerCellID::subdet()]; } - int getSideID(TrackerHit* hit) { _encoder->setValue(hit->getCellID0()); return (*_encoder)[lcio::LCTrackerCellID::side()]; }; - int getLayerID(TrackerHit* hit) { _encoder->setValue(hit->getCellID0()); return (*_encoder)[lcio::LCTrackerCellID::layer()]; }; - int getModuleID(TrackerHit* hit) { _encoder->setValue(hit->getCellID0()); return (*_encoder)[lcio::LCTrackerCellID::module()]; }; - int getSensorID(TrackerHit* hit) { _encoder->setValue(hit->getCellID0()); return (*_encoder)[lcio::LCTrackerCellID::sensor()]; }; + int getDetectorID(TrackerHit* hit) { + _encoder->setValue(hit->getCellID0()); + return (*_encoder)[lcio::LCTrackerCellID::subdet()]; + } + int getSideID(TrackerHit* hit) { + _encoder->setValue(hit->getCellID0()); + return (*_encoder)[lcio::LCTrackerCellID::side()]; + }; + int getLayerID(TrackerHit* hit) { + _encoder->setValue(hit->getCellID0()); + return (*_encoder)[lcio::LCTrackerCellID::layer()]; + }; + int getModuleID(TrackerHit* hit) { + _encoder->setValue(hit->getCellID0()); + return (*_encoder)[lcio::LCTrackerCellID::module()]; + }; + int getSensorID(TrackerHit* hit) { + _encoder->setValue(hit->getCellID0()); + return (*_encoder)[lcio::LCTrackerCellID::sensor()]; + }; - /** helper function to get collection using try catch block */ - LCCollection* GetCollection( LCEvent * evt, std::string colName ) ; - + LCCollection* GetCollection(LCEvent* evt, std::string colName); + /** helper function to get relations using try catch block */ - LCRelationNavigator* GetRelations( LCEvent * evt, std::string RelName ) ; - + LCRelationNavigator* GetRelations(LCEvent* evt, std::string RelName); + /** sets up the different collections */ - void SetupInputCollections( LCEvent * evt ) ; - - + void SetupInputCollections(LCEvent* evt); + /** input TrackerHit collections */ - std::vector< std::string > _colNamesTrackerHits; - - /** input relation collections + std::vector _colNamesTrackerHits; + + /** input relation collections */ - std::vector< std::string > _colNamesTrackerHitRelations; - - -// int _nEventPrintout ; - int _n_run ; - int _n_evt ; - int _current_evt_number ; - - - std::vector< LCCollection* > _colTrackerHits; - std::vector< LCRelationNavigator* > _navTrackerHitRel; - - + std::vector _colNamesTrackerHitRelations; + + // int _nEventPrintout ; + int _n_run; + int _n_evt; + int _current_evt_number; + + std::vector _colTrackerHits; + std::vector _navTrackerHitRel; + TFile* _root_file; - + std::map _histo_map; std::map::iterator _histo_map_it; - + std::map*> _histo_buffer_map; - - - dd4hep::rec::SurfaceMap _surfMap{} ; -} ; + dd4hep::rec::SurfaceMap _surfMap{}; +}; #endif - - - diff --git a/source/Utils/include/HitsSorterAndDebugger.h b/source/Utils/include/HitsSorterAndDebugger.h index 4d8a571..dc0f7b3 100644 --- a/source/Utils/include/HitsSorterAndDebugger.h +++ b/source/Utils/include/HitsSorterAndDebugger.h @@ -5,7 +5,7 @@ #include #include -//CxxUtils +// CxxUtils #include "fpcompare.h" // sorting by value of R(=x^2+y^2) in global coordinated so the hits are always @@ -32,8 +32,8 @@ inline void printHits(const TrackerHitVec& hitVector) { for (int itHit = 0; itHit < nHits; itHit++) { // Get the tracker hit and print global coordinates of the hit TrackerHitPlane* hit = static_cast(hitVector.at(itHit)); - streamlog_out(DEBUG5) << " Hit #" << itHit << ", (x,y,z) = (" << hit->getPosition()[0] << "," << hit->getPosition()[1] - << "," << hit->getPosition()[2] << ")" << std::endl; + streamlog_out(DEBUG5) << " Hit #" << itHit << ", (x,y,z) = (" << hit->getPosition()[0] << "," + << hit->getPosition()[1] << "," << hit->getPosition()[2] << ")" << std::endl; } return; } diff --git a/source/Utils/include/SetTrackerHitExtensions.h b/source/Utils/include/SetTrackerHitExtensions.h index 187bf8b..b8d5b3b 100644 --- a/source/Utils/include/SetTrackerHitExtensions.h +++ b/source/Utils/include/SetTrackerHitExtensions.h @@ -1,129 +1,128 @@ #ifndef SetTrackerHitExtensions_h #define SetTrackerHitExtensions_h 1 -#include "marlin/Processor.h" #include "lcio.h" +#include "marlin/Processor.h" #include -#include #include +#include #include -#include #include "UTIL/LCTrackerConf.h" +#include -namespace EVENT{ - class MCParticle ; - class Track ; -} +namespace EVENT { +class MCParticle; +class Track; +} // namespace EVENT namespace IMPL { - class TrackImpl ; +class TrackImpl; } -namespace UTIL{ - class LCRelationNavigator ; +namespace UTIL { +class LCRelationNavigator; } - -namespace MarlinTrk{ - class IMarlinTrkSystem ; +namespace MarlinTrk { +class IMarlinTrkSystem; } -/** Set the LCIO Extensions to relate SimTrackerHits to TrackerHits via a pointer. - * - +/** Set the LCIO Extensions to relate SimTrackerHits to TrackerHits via a pointer. + * + *

Input - Prerequisites

- * Needs a collections of LCIO TrackerHits. + * Needs a collections of LCIO TrackerHits. * * @param TrackerHitsInputCollections Name of the tracker hit input collections
* (default value: FTDTrackerHits SITTrackerHits TPCTrackerHits VXDTrackerHits ) - * - * @param TrackerHitsRelInputCollections Name of the lcrelation collections, that link the TrackerHits to their SimTrackerHits. + * + * @param TrackerHitsRelInputCollections Name of the lcrelation collections, that link the TrackerHits to their + SimTrackerHits. * Have to be in same order as TrackerHitsInputCollections!!!
* (default value: FTDTrackerHitRelations SITTrackerHitRelations TPCTrackerHitRelations VXDTrackerHitRelations ) - * - * - * - * @author S. J. Aplin, DESY - * + * + * + * + * @author S. J. Aplin, DESY + * */ class SetTrackerHitExtensions : public marlin::Processor { - + public: - - virtual marlin::Processor* newProcessor() { return new SetTrackerHitExtensions ; } - - - SetTrackerHitExtensions() ; - + virtual marlin::Processor* newProcessor() { return new SetTrackerHitExtensions; } + + SetTrackerHitExtensions(); + /** Called at the begin of the job before anything is read. * Use to initialize the processor, e.g. book histograms. */ - virtual void init() ; - + virtual void init(); + /** Called for every run. */ - virtual void processRunHeader( LCRunHeader* run ) ; - + virtual void processRunHeader(LCRunHeader* run); + /** Called for every event - the working horse. */ - virtual void processEvent( LCEvent * evt ) ; - - - virtual void check( LCEvent * evt ) ; - - + virtual void processEvent(LCEvent* evt); + + virtual void check(LCEvent* evt); + /** Called after data processing for clean up. */ - virtual void end() ; - + virtual void end(); + protected: - - - const LCObjectVec* getSimHits( TrackerHit* trkhit, const FloatVec* weights = NULL); - + const LCObjectVec* getSimHits(TrackerHit* trkhit, const FloatVec* weights = NULL); + UTIL::BitField64* _encoder; - int getDetectorID(TrackerHit* hit) { _encoder->setValue(hit->getCellID0()); return (*_encoder)[lcio::LCTrackerCellID::subdet()]; } - int getSideID(TrackerHit* hit) { _encoder->setValue(hit->getCellID0()); return (*_encoder)[lcio::LCTrackerCellID::side()]; }; - int getLayerID(TrackerHit* hit) { _encoder->setValue(hit->getCellID0()); return (*_encoder)[lcio::LCTrackerCellID::layer()]; }; - int getModuleID(TrackerHit* hit) { _encoder->setValue(hit->getCellID0()); return (*_encoder)[lcio::LCTrackerCellID::module()]; }; - int getSensorID(TrackerHit* hit) { _encoder->setValue(hit->getCellID0()); return (*_encoder)[lcio::LCTrackerCellID::sensor()]; }; + int getDetectorID(TrackerHit* hit) { + _encoder->setValue(hit->getCellID0()); + return (*_encoder)[lcio::LCTrackerCellID::subdet()]; + } + int getSideID(TrackerHit* hit) { + _encoder->setValue(hit->getCellID0()); + return (*_encoder)[lcio::LCTrackerCellID::side()]; + }; + int getLayerID(TrackerHit* hit) { + _encoder->setValue(hit->getCellID0()); + return (*_encoder)[lcio::LCTrackerCellID::layer()]; + }; + int getModuleID(TrackerHit* hit) { + _encoder->setValue(hit->getCellID0()); + return (*_encoder)[lcio::LCTrackerCellID::module()]; + }; + int getSensorID(TrackerHit* hit) { + _encoder->setValue(hit->getCellID0()); + return (*_encoder)[lcio::LCTrackerCellID::sensor()]; + }; - /** helper function to get collection using try catch block */ - LCCollection* GetCollection( LCEvent * evt, std::string colName ) ; - + LCCollection* GetCollection(LCEvent* evt, std::string colName); + /** helper function to get relations using try catch block */ - LCRelationNavigator* GetRelations( LCEvent * evt, std::string RelName ) ; - + LCRelationNavigator* GetRelations(LCEvent* evt, std::string RelName); + /** sets up the different collections */ - void SetupInputCollections( LCEvent * evt ) ; - - - + void SetupInputCollections(LCEvent* evt); + /** input TrackerHit collections */ - std::vector< std::string > _colNamesTrackerHits; - - /** input relation collections - */ - std::vector< std::string > _colNamesTrackerHitRelations; - - -// int _nEventPrintout ; - int _n_run ; - int _n_evt ; - int _current_evt_number ; - - - std::vector< LCCollection* > _colTrackerHits; - std::vector< LCRelationNavigator* > _navTrackerHitRel; - - -} ; + std::vector _colNamesTrackerHits; -#endif + /** input relation collections + */ + std::vector _colNamesTrackerHitRelations; + // int _nEventPrintout ; + int _n_run; + int _n_evt; + int _current_evt_number; + std::vector _colTrackerHits; + std::vector _navTrackerHitRel; +}; +#endif diff --git a/source/Utils/include/SplitCollectionByLayer.h b/source/Utils/include/SplitCollectionByLayer.h index e366677..3dcff6e 100644 --- a/source/Utils/include/SplitCollectionByLayer.h +++ b/source/Utils/include/SplitCollectionByLayer.h @@ -1,98 +1,80 @@ #ifndef SplitCollectionByLayer_h #define SplitCollectionByLayer_h 1 -#include "marlin/Processor.h" #include "marlin/EventModifier.h" +#include "marlin/Processor.h" #include "lcio.h" #include +using namespace lcio; +using namespace marlin; -using namespace lcio ; -using namespace marlin ; - - -/** Utility processor that allows to split a collection of Hits into +/** Utility processor that allows to split a collection of Hits into * several collections based on the layer information in the cellID word. * Works for all four lcio hit classes. * * @parameter InputCollection name of the hit collection with (Sim)TrackerHits/(Sim)CalorimeterHits - * @parameter OutputCollections ( ColName StartLayer EndLayer ) - * + * @parameter OutputCollections ( ColName StartLayer EndLayer ) + * * @author F. Gaede, CERN/DESY * @date 30 Oct 2014 * @version $Id: $ */ class SplitCollectionByLayer : public Processor { - -protected: - ///helper struct - struct OutColInfo{ - std::string name ; - unsigned layer0 ; - unsigned layer1 ; - LCCollection* collection ; +protected: + /// helper struct + struct OutColInfo { + std::string name; + unsigned layer0; + unsigned layer1; + LCCollection* collection; }; - + /// Enum used for hit types - enum HitType{ - SimTrackerHitType = 1, - TrackerHitType, - SimCalorimeterHitType, - CalorimeterHitType, - UnkownType - }; + enum HitType { SimTrackerHitType = 1, TrackerHitType, SimCalorimeterHitType, CalorimeterHitType, UnkownType }; + +public: + virtual Processor* newProcessor() { return new SplitCollectionByLayer; } + + SplitCollectionByLayer(); + + virtual const std::string& name() const { return Processor::name(); } - public: - - virtual Processor* newProcessor() { return new SplitCollectionByLayer ; } - - - SplitCollectionByLayer() ; - - virtual const std::string & name() const { return Processor::name() ; } - /** Called at the begin of the job before anything is read. * Use to initialize the processor, e.g. book histograms. */ - virtual void init() ; - + virtual void init(); + /** Called for every run. */ - virtual void processRunHeader( LCRunHeader* run ) ; - + virtual void processRunHeader(LCRunHeader* run); + /** Called for every event - the working horse. */ - virtual void processEvent( LCEvent * evt ) ; - - - virtual void check( LCEvent * evt ) ; - - + virtual void processEvent(LCEvent* evt); + + virtual void check(LCEvent* evt); + /** Called after data processing for clean up. */ - virtual void end() ; - - - protected: + virtual void end(); +protected: ////Input collection name. - std::string _colName ; + std::string _colName; /// Output collections and layers: - StringVec _outColAndLayers ; + StringVec _outColAndLayers; - std::vector _outCols ; + std::vector _outCols; - HitType _type ; + HitType _type; - int _nRun ; - int _nEvt ; -} ; + int _nRun; + int _nEvt; +}; #endif - - - diff --git a/source/Utils/src/CalcTrackerHitResiduals.cc b/source/Utils/src/CalcTrackerHitResiduals.cc index be364b4..36965bf 100644 --- a/source/Utils/src/CalcTrackerHitResiduals.cc +++ b/source/Utils/src/CalcTrackerHitResiduals.cc @@ -1,692 +1,598 @@ #include "CalcTrackerHitResiduals.h" #include -#include #include +#include #include #include +#include #include #include -#include #include -#include #include +#include // ----- include for verbosity dependend logging --------- #include "marlin/VerbosityLevels.h" #include "MarlinTrk/Factory.h" -#include "DD4hep/Detector.h" #include "DD4hep/DD4hepUnits.h" +#include "DD4hep/Detector.h" #include "DDRec/DetectorData.h" - - /// root headers #include #include +using namespace lcio; +using namespace marlin; -using namespace lcio ; -using namespace marlin ; - -using namespace MarlinTrk ; -using namespace dd4hep::rec ; +using namespace MarlinTrk; +using namespace dd4hep::rec; - - -CalcTrackerHitResiduals aCalcTrackerHitResiduals ; +CalcTrackerHitResiduals aCalcTrackerHitResiduals; CalcTrackerHitResiduals::CalcTrackerHitResiduals() : Processor("CalcTrackerHitResiduals") { - + // modify processor description - _description = "Creates Track Collection from MC Truth. Can handle composite spacepoints as long as they consist of two TrackerHits" ; - - + _description = "Creates Track Collection from MC Truth. Can handle composite spacepoints as long as they consist of " + "two TrackerHits"; + // register steering parameters: name, description, class-variable, default value - - + StringVec trackerHitsRelInputColNamesDefault; - trackerHitsRelInputColNamesDefault.push_back( "VXDTrackerHitRelations" ); - trackerHitsRelInputColNamesDefault.push_back( "SITTrackerHitRelations" ); - trackerHitsRelInputColNamesDefault.push_back( "FTDPixelTrackerHitRelations" ); - trackerHitsRelInputColNamesDefault.push_back( "FTDSpacePointRelations" ); - trackerHitsRelInputColNamesDefault.push_back( "TPCTrackerHitRelations" ); - trackerHitsRelInputColNamesDefault.push_back( "SETTrackerHitRelations" ); - - - registerInputCollections("LCRelation", - "TrackerHitsRelInputCollections", - "Name of the lcrelation collections, that link the TrackerHits to their SimTrackerHits. Have to be in same order as TrackerHitsInputCollections!!!", - _colNamesTrackerHitRelations, - trackerHitsRelInputColNamesDefault ); - - + trackerHitsRelInputColNamesDefault.push_back("VXDTrackerHitRelations"); + trackerHitsRelInputColNamesDefault.push_back("SITTrackerHitRelations"); + trackerHitsRelInputColNamesDefault.push_back("FTDPixelTrackerHitRelations"); + trackerHitsRelInputColNamesDefault.push_back("FTDSpacePointRelations"); + trackerHitsRelInputColNamesDefault.push_back("TPCTrackerHitRelations"); + trackerHitsRelInputColNamesDefault.push_back("SETTrackerHitRelations"); + + registerInputCollections("LCRelation", "TrackerHitsRelInputCollections", + "Name of the lcrelation collections, that link the TrackerHits to their SimTrackerHits. " + "Have to be in same order as TrackerHitsInputCollections!!!", + _colNamesTrackerHitRelations, trackerHitsRelInputColNamesDefault); + StringVec trackerHitsInputColNamesDefault; - - trackerHitsInputColNamesDefault.push_back( "VXDTrackerHits" ); - trackerHitsInputColNamesDefault.push_back( "SITTrackerHits" ); - trackerHitsInputColNamesDefault.push_back( "FTDPixelTrackerHits" ); - trackerHitsInputColNamesDefault.push_back( "FTDSpacePointRelations" ); - trackerHitsInputColNamesDefault.push_back( "TPCTrackerHits" ); - trackerHitsInputColNamesDefault.push_back( "SETTrackerHits" ); - - registerInputCollections("TrackerHit", - "TrackerHitsInputCollections", - "Name of the tracker hit input collections", - _colNamesTrackerHits, - trackerHitsInputColNamesDefault); - - - _n_run = 0 ; - _n_evt = 0 ; - + + trackerHitsInputColNamesDefault.push_back("VXDTrackerHits"); + trackerHitsInputColNamesDefault.push_back("SITTrackerHits"); + trackerHitsInputColNamesDefault.push_back("FTDPixelTrackerHits"); + trackerHitsInputColNamesDefault.push_back("FTDSpacePointRelations"); + trackerHitsInputColNamesDefault.push_back("TPCTrackerHits"); + trackerHitsInputColNamesDefault.push_back("SETTrackerHits"); + + registerInputCollections("TrackerHit", "TrackerHitsInputCollections", "Name of the tracker hit input collections", + _colNamesTrackerHits, trackerHitsInputColNamesDefault); + + _n_run = 0; + _n_evt = 0; + _root_file = 0; - + _histo_map.clear(); _histo_map_it = _histo_map.begin(); - } +void CalcTrackerHitResiduals::init() { -void CalcTrackerHitResiduals::init() { - - streamlog_out(DEBUG) << " init called " - << std::endl ; + streamlog_out(DEBUG) << " init called " << std::endl; _encoder = new UTIL::BitField64(lcio::LCTrackerCellID::encoding_string()); // usually a good idea to - printParameters() ; - - //FIXME:SJA: if we want the surface store to be filled we need to create an instance of MarlinTrk implemented with KalTest/KalDet - MarlinTrk::IMarlinTrkSystem* trksystem = MarlinTrk::Factory::createMarlinTrkSystem( "DDKalTest" , 0 , "" ) ; - - if( trksystem == 0 ) { - - throw EVENT::Exception( std::string(" Cannot initialize MarlinTrkSystem of Type: ") + std::string("DDKalTest" ) ) ; - + printParameters(); + + // FIXME:SJA: if we want the surface store to be filled we need to create an instance of MarlinTrk implemented with + // KalTest/KalDet + MarlinTrk::IMarlinTrkSystem* trksystem = MarlinTrk::Factory::createMarlinTrkSystem("DDKalTest", 0, ""); + + if (trksystem == 0) { + + throw EVENT::Exception(std::string(" Cannot initialize MarlinTrkSystem of Type: ") + std::string("DDKalTest")); } - - trksystem->init() ; - - /// Write histogram to file + + trksystem->init(); + + /// Write histogram to file _root_file = new TFile("CalcTrackerHitResiduals.root", "RECREATE"); this->createHistogramBuffers(); - dd4hep::Detector& theDetector = dd4hep::Detector::getInstance(); - streamlog_out(DEBUG9) << " get the surface manager from theDetector ... " << std::endl ; - - const dd4hep::rec::SurfaceManager* surfMan = theDetector.extension< dd4hep::rec::SurfaceManager >() ; + streamlog_out(DEBUG9) << " get the surface manager from theDetector ... " << std::endl; - _surfMap = *surfMan->map( "world" ) ; + const dd4hep::rec::SurfaceManager* surfMan = theDetector.extension(); + _surfMap = *surfMan->map("world"); } -void CalcTrackerHitResiduals::processRunHeader( LCRunHeader* ) { - - ++_n_run ; -} - -void CalcTrackerHitResiduals::processEvent( LCEvent * evt ) { - - - - streamlog_out(DEBUG3) << " processing event: " << _n_evt << std::endl ; - +void CalcTrackerHitResiduals::processRunHeader(LCRunHeader*) { ++_n_run; } + +void CalcTrackerHitResiduals::processEvent(LCEvent* evt) { + + streamlog_out(DEBUG3) << " processing event: " << _n_evt << std::endl; + _current_evt_number = evt->getEventNumber(); - - + _colTrackerHits.clear(); _navTrackerHitRel.clear(); - + /**********************************************************************************************/ /* Prepare the collections */ /**********************************************************************************************/ - + // get the input collections and fill the vectors - this->SetupInputCollections(evt) ; - + this->SetupInputCollections(evt); + // create the encoder to decode cellID0 - UTIL::BitField64 cellID_encoder( LCTrackerCellID::encoding_string() ) ; - - - + UTIL::BitField64 cellID_encoder(LCTrackerCellID::encoding_string()); + /**********************************************************************************************/ /* Loop over the tracker hit collections */ /**********************************************************************************************/ - - std::vector< std::pair > simHitTrkHit; - - - for( unsigned iCol=0; iCol<_colTrackerHits.size(); iCol++){ - + + std::vector> simHitTrkHit; + + for (unsigned iCol = 0; iCol < _colTrackerHits.size(); iCol++) { + LCCollection* trackerHitCol = _colTrackerHits[iCol]; int nHits = trackerHitCol->getNumberOfElements(); - streamlog_out( DEBUG1 ) << "Process " << _colNamesTrackerHits[iCol] << " collection with " << nHits << " hits \n"; - - + streamlog_out(DEBUG1) << "Process " << _colNamesTrackerHits[iCol] << " collection with " << nHits << " hits \n"; + double rec_pos[3]; double sim_pos[3]; - + LCRelationNavigator* nav = _navTrackerHitRel[iCol]; - /**********************************************************************************************/ /* Loop over the tracker hits in this collection */ /**********************************************************************************************/ - - for( int j=0; jgetElementAt( j ) == 0 ) { - streamlog_out( DEBUG1 ) << "Pointer to TrackerHit" << j << " is NULL " << std::endl; + + for (int j = 0; j < nHits; j++) { + + if (trackerHitCol->getElementAt(j) == 0) { + streamlog_out(DEBUG1) << "Pointer to TrackerHit" << j << " is NULL " << std::endl; } - - TrackerHit * trkhit = dynamic_cast( trackerHitCol->getElementAt( j )); - - if ( trkhit == 0 ) { - - std::stringstream errorMsg; - errorMsg << "dynamic_cast to TrackerHit for hit " << j << " failed. Pointer = " << trackerHitCol->getElementAt( j ) << std::endl; - + + TrackerHit* trkhit = dynamic_cast(trackerHitCol->getElementAt(j)); + + if (trkhit == 0) { + + std::stringstream errorMsg; + errorMsg << "dynamic_cast to TrackerHit for hit " << j + << " failed. Pointer = " << trackerHitCol->getElementAt(j) << std::endl; + throw lcio::Exception(errorMsg.str()); - } - - const LCObjectVec& to = nav->getRelatedToObjects( trkhit ); - - - const int celId = trkhit->getCellID0() ; - - UTIL::BitField64 encoder( lcio::LCTrackerCellID::encoding_string() ) ; - - encoder.setValue(celId) ; - int side = encoder[lcio::LCTrackerCellID::side()]; - int layer = encoder[lcio::LCTrackerCellID::layer()]; + + const LCObjectVec& to = nav->getRelatedToObjects(trkhit); + + const int celId = trkhit->getCellID0(); + + UTIL::BitField64 encoder(lcio::LCTrackerCellID::encoding_string()); + + encoder.setValue(celId); + int side = encoder[lcio::LCTrackerCellID::side()]; + int layer = encoder[lcio::LCTrackerCellID::layer()]; int module = encoder[lcio::LCTrackerCellID::module()]; int sensor = encoder[lcio::LCTrackerCellID::sensor()]; - - streamlog_out( DEBUG3 ) << "Hit = "<< j << " has celId " << celId << std::endl; - streamlog_out( DEBUG3 ) << "side = " << side << std::endl; - streamlog_out( DEBUG3 ) << "layerNumber = " << layer << std::endl; - streamlog_out( DEBUG3 ) << "moduleNumber = " << module << std::endl; - streamlog_out( DEBUG3 ) << "sensorNumber = " << sensor << std::endl ; + + streamlog_out(DEBUG3) << "Hit = " << j << " has celId " << celId << std::endl; + streamlog_out(DEBUG3) << "side = " << side << std::endl; + streamlog_out(DEBUG3) << "layerNumber = " << layer << std::endl; + streamlog_out(DEBUG3) << "moduleNumber = " << module << std::endl; + streamlog_out(DEBUG3) << "sensorNumber = " << sensor << std::endl; rec_pos[0] = trkhit->getPosition()[0]; rec_pos[1] = trkhit->getPosition()[1]; - rec_pos[2] = trkhit->getPosition()[2]; - - dd4hep::rec::SurfaceMap::const_iterator si = _surfMap.find( celId) ; - ISurface* ms = ( si != _surfMap.end() ? si->second : 0 ) ; - - if( ms == NULL ){ - streamlog_out( DEBUG3 ) << " no surface found for hit id: " << celId << std::endl ; - continue ; + rec_pos[2] = trkhit->getPosition()[2]; + + dd4hep::rec::SurfaceMap::const_iterator si = _surfMap.find(celId); + ISurface* ms = (si != _surfMap.end() ? si->second : 0); + + if (ms == NULL) { + streamlog_out(DEBUG3) << " no surface found for hit id: " << celId << std::endl; + continue; } - Vector3D globalPointRec(rec_pos[0],rec_pos[1],rec_pos[2]); - Vector2D localPointRec = ms->globalToLocal( globalPointRec ) ; + Vector3D globalPointRec(rec_pos[0], rec_pos[1], rec_pos[2]); + Vector2D localPointRec = ms->globalToLocal(globalPointRec); - if( UTIL::BitSet32( trkhit->getType() )[ UTIL::ILDTrkHitTypeBit::COMPOSITE_SPACEPOINT ] ){ + if (UTIL::BitSet32(trkhit->getType())[UTIL::ILDTrkHitTypeBit::COMPOSITE_SPACEPOINT]) { /**********************************************************************************************/ /* Treat Composite Spacepoints */ /**********************************************************************************************/ - + // Check that the space point is only created from 2 strip hits - if( to.size() == 2 ){ - + if (to.size() == 2) { + SimTrackerHit* simhitA = dynamic_cast(to.at(0)); SimTrackerHit* simhitB = dynamic_cast(to.at(1)); - + // Check if the simHits are from the same particle in order to avoid problems - if( simhitA->getMCParticle() == simhitB->getMCParticle() ) { + if (simhitA->getMCParticle() == simhitB->getMCParticle()) { + + sim_pos[0] = simhitA->getPosition()[0]; + sim_pos[1] = simhitA->getPosition()[1]; + sim_pos[2] = simhitA->getPosition()[2]; - sim_pos[0] = simhitA->getPosition()[0] ; - sim_pos[1] = simhitA->getPosition()[1] ; - sim_pos[2] = simhitA->getPosition()[2] ; + Vector3D globalPointSim(sim_pos[0], sim_pos[1], sim_pos[2]); - - Vector3D globalPointSim(sim_pos[0],sim_pos[1],sim_pos[2]); - double dx = globalPointRec.x() - globalPointSim.x(); double dy = globalPointRec.y() - globalPointSim.y(); double dz = globalPointRec.z() - globalPointSim.z(); - - double dr = globalPointRec.trans() - globalPointSim.trans(); - double drphi = globalPointRec.phi()*globalPointRec.trans() - globalPointSim.phi()*globalPointSim.trans(); - - - streamlog_out( DEBUG1 ) << "Spacepoint Residuals dx " << dx - << " dy " << dy - << " dz " << dz - << "\n"; + + double dr = globalPointRec.trans() - globalPointSim.trans(); + double drphi = + globalPointRec.phi() * globalPointRec.trans() - globalPointSim.phi() * globalPointSim.trans(); + + streamlog_out(DEBUG1) << "Spacepoint Residuals dx " << dx << " dy " << dy << " dz " << dz << "\n"; fill_histo(_colNamesTrackerHits[iCol] + "_res_x", dx); fill_histo(_colNamesTrackerHits[iCol] + "_res_y", dy); fill_histo(_colNamesTrackerHits[iCol] + "_res_z", dz); - + fill_histo(_colNamesTrackerHits[iCol] + "_res_r", dr); fill_histo(_colNamesTrackerHits[iCol] + "_res_rphi", drphi); - - - } else { streamlog_out( DEBUG1 ) << "spacepoint discarded, because simHits are not equal " << simhitA->getMCParticle() << " != " - << simhitB->getMCParticle() << "\n"; + + } else { + streamlog_out(DEBUG1) << "spacepoint discarded, because simHits are not equal " << simhitA->getMCParticle() + << " != " << simhitB->getMCParticle() << "\n"; } - - } - else { streamlog_out( DEBUG1 ) << "spacepoint discarded, because it is related to " << to.size() << "SimTrackerHits. It should be 2!\n"; } - - } else { - + + } else { + streamlog_out(DEBUG1) << "spacepoint discarded, because it is related to " << to.size() + << "SimTrackerHits. It should be 2!\n"; + } + + } else { + /**********************************************************************************************/ /* Treat Normal Hits */ /**********************************************************************************************/ - - if( to.size() == 1 ){ // only take trackerHits, that have only one related SimHit + + if (to.size() == 1) { // only take trackerHits, that have only one related SimHit SimTrackerHit* simhit = dynamic_cast(to.at(0)); - + sim_pos[0] = simhit->getPosition()[0]; sim_pos[1] = simhit->getPosition()[1]; sim_pos[2] = simhit->getPosition()[2]; - Vector3D globalPointSim(sim_pos[0],sim_pos[1],sim_pos[2]); + Vector3D globalPointSim(sim_pos[0], sim_pos[1], sim_pos[2]); Vector2D localPointSim = ms->globalToLocal(globalPointSim); - + double dx = globalPointRec.x() - globalPointSim.x(); double dy = globalPointRec.y() - globalPointSim.y(); double dz = globalPointRec.z() - globalPointSim.z(); - + double du = localPointRec.u() - localPointSim.u(); double dv = localPointRec.v() - localPointSim.v(); - double dw = 0 ; // by construction - - streamlog_out( DEBUG1 ) << "TrackerHit Residuals dx " << dx - << " dy " << dy - << " dz " << dz - << " du " << du - << " dv " << dv - << " dw " << dw - << "\n"; - - + double dw = 0; // by construction + + streamlog_out(DEBUG1) << "TrackerHit Residuals dx " << dx << " dy " << dy << " dz " << dz << " du " << du + << " dv " << dv << " dw " << dw << "\n"; + fill_histo(_colNamesTrackerHits[iCol] + "_res_x", dx); fill_histo(_colNamesTrackerHits[iCol] + "_res_y", dy); fill_histo(_colNamesTrackerHits[iCol] + "_res_z", dz); fill_histo(_colNamesTrackerHits[iCol] + "_res_du", du); fill_histo(_colNamesTrackerHits[iCol] + "_res_dv", dv); fill_histo(_colNamesTrackerHits[iCol] + "_res_dw", dw); - + } - else{ streamlog_out( DEBUG1 ) << "TrackerHit discarded, because it is related to " << to.size() << "SimTrackerHits. It should be 1!\n"; } - + else { + streamlog_out(DEBUG1) << "TrackerHit discarded, because it is related to " << to.size() + << "SimTrackerHits. It should be 1!\n"; + } } - - - // calculate residual - - - - + + // calculate residual } - } - streamlog_out( DEBUG4 ) << "Number of SimTracker hits = " << simHitTrkHit.size() << std::endl; - - - - - + streamlog_out(DEBUG4) << "Number of SimTracker hits = " << simHitTrkHit.size() << std::endl; + // some information output - for(unsigned int i=0; i< simHitTrkHit.size() ; ++i ) { - - SimTrackerHit * simHit = simHitTrkHit[i].first; + for (unsigned int i = 0; i < simHitTrkHit.size(); ++i) { + + SimTrackerHit* simHit = simHitTrkHit[i].first; TrackerHit* trackerHit = simHitTrkHit[i].second; - - streamlog_out( DEBUG2 ) << "Tracker hit: [" << i << "] = " << trackerHit << " mcp = " << simHit->getMCParticle() << " time = " << simHit->getTime() << " cellid (trkHit) = " << trackerHit->getCellID0() - << " (de" << getDetectorID( trackerHit ) - << ",si" << getSideID( trackerHit ) - << ",la" << getLayerID( trackerHit ) - << ",mo"<< getModuleID( trackerHit ) - << ",se"<< getSensorID( trackerHit ) - << ")" << std::endl; - - } - - ++_n_evt ; - -} + streamlog_out(DEBUG2) << "Tracker hit: [" << i << "] = " << trackerHit << " mcp = " << simHit->getMCParticle() + << " time = " << simHit->getTime() << " cellid (trkHit) = " << trackerHit->getCellID0() + << " (de" << getDetectorID(trackerHit) << ",si" << getSideID(trackerHit) << ",la" + << getLayerID(trackerHit) << ",mo" << getModuleID(trackerHit) << ",se" + << getSensorID(trackerHit) << ")" << std::endl; + } + ++_n_evt; +} -void CalcTrackerHitResiduals::check( LCEvent* ) { +void CalcTrackerHitResiduals::check(LCEvent*) { // nothing to check here - could be used to fill checkplots in reconstruction processor } +void CalcTrackerHitResiduals::end() { + + streamlog_out(DEBUG4) << "CalcTrackerHitResiduals::end() " << name() << " processed " << _n_evt << " events in " + << _n_run << " runs " << std::endl; -void CalcTrackerHitResiduals::end() { - - streamlog_out(DEBUG4) << "CalcTrackerHitResiduals::end() " << name() - << " processed " << _n_evt << " events in " << _n_run << " runs " - << std::endl ; - // convert any remaining buffers to histograms - + std::map*>::iterator it = _histo_buffer_map.begin(); - - streamlog_out(DEBUG4) << "Number of remaining buffers = " << _histo_buffer_map.size() << std::endl ; - + + streamlog_out(DEBUG4) << "Number of remaining buffers = " << _histo_buffer_map.size() << std::endl; + for (it = _histo_buffer_map.begin(); it != _histo_buffer_map.end(); ++it) { - streamlog_out(DEBUG4) << "Write remaining buffer " << it->first - << std::endl ; - + streamlog_out(DEBUG4) << "Write remaining buffer " << it->first << std::endl; + this->write_buffer_to_histo(it); - streamlog_out(DEBUG4) << "Write remaining buffer: done " << it->first - << std::endl ; - + streamlog_out(DEBUG4) << "Write remaining buffer: done " << it->first << std::endl; } - + _root_file->Write(); _root_file->Close(); delete _root_file; _root_file = 0; - - delete _encoder ; - -} + delete _encoder; +} +void CalcTrackerHitResiduals::SetupInputCollections(LCEvent* evt) { -void CalcTrackerHitResiduals::SetupInputCollections( LCEvent * evt ) { - - - // Check if there are as many tracker hit input collections as relation collections - if( _colNamesTrackerHits.size() != _colNamesTrackerHitRelations.size() ){ - - streamlog_out( ERROR ) << "There must be as many input collections of tracker Hits as of relations. At the moment, there are " - << _colNamesTrackerHits.size() << " tracker hit collections and " << _colNamesTrackerHitRelations.size() << " relation collections passed as steering paremeters!\n"; - + if (_colNamesTrackerHits.size() != _colNamesTrackerHitRelations.size()) { + + streamlog_out(ERROR) + << "There must be as many input collections of tracker Hits as of relations. At the moment, there are " + << _colNamesTrackerHits.size() << " tracker hit collections and " << _colNamesTrackerHitRelations.size() + << " relation collections passed as steering paremeters!\n"; + exit(1); } - - for( unsigned i=0; i< _colNamesTrackerHits.size(); i++ ){ - - + + for (unsigned i = 0; i < _colNamesTrackerHits.size(); i++) { + // the tracker hits - LCCollection* colTrkHits = GetCollection( evt, _colNamesTrackerHits[i] ); - if( colTrkHits == NULL ) continue; - + LCCollection* colTrkHits = GetCollection(evt, _colNamesTrackerHits[i]); + if (colTrkHits == NULL) + continue; + // the relations of them - LCRelationNavigator* nav = GetRelations( evt, _colNamesTrackerHitRelations[i] ); - if( nav == NULL ) continue; - - - _colTrackerHits.push_back( colTrkHits ); - _navTrackerHitRel.push_back( nav ); - - + LCRelationNavigator* nav = GetRelations(evt, _colNamesTrackerHitRelations[i]); + if (nav == NULL) + continue; + + _colTrackerHits.push_back(colTrkHits); + _navTrackerHitRel.push_back(nav); } - - } +LCCollection* CalcTrackerHitResiduals::GetCollection(LCEvent* evt, std::string colName) { -LCCollection* CalcTrackerHitResiduals::GetCollection( LCEvent * evt, std::string colName ){ - LCCollection* col = NULL; - + try { - col = evt->getCollection( colName.c_str() ) ; - streamlog_out( DEBUG4 ) << " --> " << colName.c_str() << " collection found, number of elements = " << col->getNumberOfElements() << std::endl; - } - catch(DataNotAvailableException &e) { - streamlog_out( DEBUG4 ) << " --> " << colName.c_str() << " collection absent" << std::endl; + col = evt->getCollection(colName.c_str()); + streamlog_out(DEBUG4) << " --> " << colName.c_str() + << " collection found, number of elements = " << col->getNumberOfElements() << std::endl; + } catch (DataNotAvailableException& e) { + streamlog_out(DEBUG4) << " --> " << colName.c_str() << " collection absent" << std::endl; } - - return col; - + + return col; } -LCRelationNavigator* CalcTrackerHitResiduals::GetRelations(LCEvent * evt , std::string RelName ) { - - LCRelationNavigator* nav = NULL ; +LCRelationNavigator* CalcTrackerHitResiduals::GetRelations(LCEvent* evt, std::string RelName) { + + LCRelationNavigator* nav = NULL; LCCollection* col = NULL; - - try{ - - col = evt->getCollection( RelName.c_str() ); - nav = new LCRelationNavigator( col ); - streamlog_out( DEBUG4 ) << " --> " << RelName << " track relation collection found, number of elements = " << col->getNumberOfElements() << std::endl; - } - catch(DataNotAvailableException &e){ - streamlog_out( ERROR ) << " --> " << RelName.c_str() << " track relation collection absent" << std::endl; + + try { + + col = evt->getCollection(RelName.c_str()); + nav = new LCRelationNavigator(col); + streamlog_out(DEBUG4) << " --> " << RelName + << " track relation collection found, number of elements = " << col->getNumberOfElements() + << std::endl; + } catch (DataNotAvailableException& e) { + streamlog_out(ERROR) << " --> " << RelName.c_str() << " track relation collection absent" << std::endl; } - + return nav; - } - -//void CalcTrackerHitResiduals::bookHistograms(){ -// -// _root_file->cd(); -// -// for( unsigned iCol=0; iCol<_colNamesTrackerHits.size(); iCol++){ -// -// int nbinsx = 100; -// float xlow = 0.0; -// float xup = 10.0; +// void CalcTrackerHitResiduals::bookHistograms(){ // -// TH1F* h = 0; -// std::string name; -// -// name = _colNamesTrackerHits[iCol] + "_res_x"; -// h = new TH1F(name.c_str(), name.c_str(), nbinsx, xlow, xup); -// _histo_map[name] = h; +// _root_file->cd(); // -// name = _colNamesTrackerHits[iCol] + "_res_y"; -// h = new TH1F(name.c_str(), name.c_str(), nbinsx, xlow, xup); -// _histo_map[name] = h; +// for( unsigned iCol=0; iCol<_colNamesTrackerHits.size(); iCol++){ // -// name = _colNamesTrackerHits[iCol] + "_res_z"; -// h = new TH1F(name.c_str(), name.c_str(), nbinsx, xlow, xup); -// _histo_map[name] = h; +// int nbinsx = 100; +// float xlow = 0.0; +// float xup = 10.0; // -// -// -// -// } -// -// -//} - -void CalcTrackerHitResiduals::createHistogramBuffers(){ - - for( unsigned iCol=0; iCol<_colNamesTrackerHits.size(); iCol++){ - - std::list* buffer = 0; - - std::string name; - - name = _colNamesTrackerHits[iCol] + "_res_x"; - buffer = new std::list; - _histo_buffer_map[name] = buffer; - - name = _colNamesTrackerHits[iCol] + "_res_y"; - buffer = new std::list; - _histo_buffer_map[name] = buffer; - - name = _colNamesTrackerHits[iCol] + "_res_z"; - buffer = new std::list; - _histo_buffer_map[name] = buffer; - - name = _colNamesTrackerHits[iCol] + "_res_r"; - buffer = new std::list; - _histo_buffer_map[name] = buffer; - - name = _colNamesTrackerHits[iCol] + "_res_rphi"; - buffer = new std::list; - _histo_buffer_map[name] = buffer; - - name = _colNamesTrackerHits[iCol] + "_res_du"; - buffer = new std::list; - _histo_buffer_map[name] = buffer; - - name = _colNamesTrackerHits[iCol] + "_res_dv"; - buffer = new std::list; - _histo_buffer_map[name] = buffer; - - name = _colNamesTrackerHits[iCol] + "_res_dw"; - buffer = new std::list; - _histo_buffer_map[name] = buffer; - - - } +// TH1F* h = 0; +// std::string name; +// +// name = _colNamesTrackerHits[iCol] + "_res_x"; +// h = new TH1F(name.c_str(), name.c_str(), nbinsx, xlow, xup); +// _histo_map[name] = h; +// +// name = _colNamesTrackerHits[iCol] + "_res_y"; +// h = new TH1F(name.c_str(), name.c_str(), nbinsx, xlow, xup); +// _histo_map[name] = h; +// +// name = _colNamesTrackerHits[iCol] + "_res_z"; +// h = new TH1F(name.c_str(), name.c_str(), nbinsx, xlow, xup); +// _histo_map[name] = h; +// +// +// +// +// } +// +// +// } + +void CalcTrackerHitResiduals::createHistogramBuffers() { + + for (unsigned iCol = 0; iCol < _colNamesTrackerHits.size(); iCol++) { + + std::list* buffer = 0; + + std::string name; + + name = _colNamesTrackerHits[iCol] + "_res_x"; + buffer = new std::list; + _histo_buffer_map[name] = buffer; + + name = _colNamesTrackerHits[iCol] + "_res_y"; + buffer = new std::list; + _histo_buffer_map[name] = buffer; + + name = _colNamesTrackerHits[iCol] + "_res_z"; + buffer = new std::list; + _histo_buffer_map[name] = buffer; + name = _colNamesTrackerHits[iCol] + "_res_r"; + buffer = new std::list; + _histo_buffer_map[name] = buffer; + + name = _colNamesTrackerHits[iCol] + "_res_rphi"; + buffer = new std::list; + _histo_buffer_map[name] = buffer; + + name = _colNamesTrackerHits[iCol] + "_res_du"; + buffer = new std::list; + _histo_buffer_map[name] = buffer; + + name = _colNamesTrackerHits[iCol] + "_res_dv"; + buffer = new std::list; + _histo_buffer_map[name] = buffer; + + name = _colNamesTrackerHits[iCol] + "_res_dw"; + buffer = new std::list; + _histo_buffer_map[name] = buffer; + } } -void CalcTrackerHitResiduals::write_buffer_to_histo(std::map*>::iterator it_buffer){ - - +void CalcTrackerHitResiduals::write_buffer_to_histo(std::map*>::iterator it_buffer) { + // to avoid outliers we will discard the top and bottom 10 percent of values and calculate the rms from that - + std::string name = it_buffer->first; std::list* buffer = it_buffer->second; - + if (buffer->empty()) { return; } - + buffer->sort(); - + std::list::iterator it; std::list::iterator it_first_10pc = buffer->begin(); std::list::iterator it_last_10pc = buffer->end(); - int ten_percent = buffer->size() * 0.1; - - for (int i = 0 ; i* buffer = it->second; - + buffer->push_back(value); // now check if the buffer is full - + if (buffer->size() == MAXBUFFERSIZE) { write_buffer_to_histo(it); - + delete buffer; _histo_buffer_map.erase(it); - } - - - // else just fill the historgram directly - + + // else just fill the historgram directly + } else { streamlog_out(DEBUG1) << "fill_histo: Use Histo" << std::endl; - + _histo_map_it = _histo_map.find(name); - + if (_histo_map_it == _histo_map.end()) { - - for (_histo_map_it = _histo_map.begin(); _histo_map_it!=_histo_map.end(); ++_histo_map_it ) { - streamlog_out(ERROR) << " Histo Name = " << _histo_map_it->first << " Pointer = " << _histo_map_it->second << std::endl; + + for (_histo_map_it = _histo_map.begin(); _histo_map_it != _histo_map.end(); ++_histo_map_it) { + streamlog_out(ERROR) << " Histo Name = " << _histo_map_it->first << " Pointer = " << _histo_map_it->second + << std::endl; } - - throw EVENT::Exception( std::string(" Histogram ") + name + std::string(" does not exist in the _histo_map")) ; - - } - - + + throw EVENT::Exception(std::string(" Histogram ") + name + std::string(" does not exist in the _histo_map")); + } + TH1F* histo = _histo_map_it->second; - histo->Fill(value); - } - - - - } - - - diff --git a/source/Utils/src/SetTrackerHitExtensions.cc b/source/Utils/src/SetTrackerHitExtensions.cc index 9008285..64433c5 100644 --- a/source/Utils/src/SetTrackerHitExtensions.cc +++ b/source/Utils/src/SetTrackerHitExtensions.cc @@ -1,20 +1,19 @@ #include "SetTrackerHitExtensions.h" #include -#include #include +#include #include #include +#include #include #include -#include -#include #include -#include #include +#include // ----- include for verbosity dependend logging --------- #include "marlin/VerbosityLevels.h" @@ -24,292 +23,245 @@ #include "MarlinTrk/DiagnosticsController.h" #endif -using namespace lcio ; -using namespace marlin ; - -using namespace MarlinTrk ; +using namespace lcio; +using namespace marlin; +using namespace MarlinTrk; - -SetTrackerHitExtensions aSetTrackerHitExtensions ; +SetTrackerHitExtensions aSetTrackerHitExtensions; SetTrackerHitExtensions::SetTrackerHitExtensions() : Processor("SetTrackerHitExtensions") { - + // modify processor description - _description = "Creates Track Collection from MC Truth. Can handle composite spacepoints as long as they consist of two TrackerHits" ; - - + _description = "Creates Track Collection from MC Truth. Can handle composite spacepoints as long as they consist of " + "two TrackerHits"; + // register steering parameters: name, description, class-variable, default value - - + StringVec trackerHitsRelInputColNamesDefault; - trackerHitsRelInputColNamesDefault.push_back( "VXDTrackerHitRelations" ); - trackerHitsRelInputColNamesDefault.push_back( "SITTrackerHitRelations" ); - trackerHitsRelInputColNamesDefault.push_back( "FTDPixelTrackerHitRelations" ); - trackerHitsRelInputColNamesDefault.push_back( "FTDSpacePointRelations" ); - trackerHitsRelInputColNamesDefault.push_back( "TPCTrackerHitRelations" ); - trackerHitsRelInputColNamesDefault.push_back( "SETTrackerHitRelations" ); - - - registerInputCollections("LCRelation", - "TrackerHitsRelInputCollections", - "Name of the lcrelation collections, that link the TrackerHits to their SimTrackerHits. Have to be in same order as TrackerHitsInputCollections!!!", - _colNamesTrackerHitRelations, - trackerHitsRelInputColNamesDefault ); - - + trackerHitsRelInputColNamesDefault.push_back("VXDTrackerHitRelations"); + trackerHitsRelInputColNamesDefault.push_back("SITTrackerHitRelations"); + trackerHitsRelInputColNamesDefault.push_back("FTDPixelTrackerHitRelations"); + trackerHitsRelInputColNamesDefault.push_back("FTDSpacePointRelations"); + trackerHitsRelInputColNamesDefault.push_back("TPCTrackerHitRelations"); + trackerHitsRelInputColNamesDefault.push_back("SETTrackerHitRelations"); + + registerInputCollections("LCRelation", "TrackerHitsRelInputCollections", + "Name of the lcrelation collections, that link the TrackerHits to their SimTrackerHits. " + "Have to be in same order as TrackerHitsInputCollections!!!", + _colNamesTrackerHitRelations, trackerHitsRelInputColNamesDefault); + StringVec trackerHitsInputColNamesDefault; - - trackerHitsInputColNamesDefault.push_back( "VXDTrackerHits" ); - trackerHitsInputColNamesDefault.push_back( "SITTrackerHits" ); - trackerHitsInputColNamesDefault.push_back( "FTDPixelTrackerHits" ); - trackerHitsInputColNamesDefault.push_back( "FTDSpacePointRelations" ); - trackerHitsInputColNamesDefault.push_back( "TPCTrackerHits" ); - trackerHitsInputColNamesDefault.push_back( "SETTrackerHits" ); - - registerInputCollections("TrackerHit", - "TrackerHitsInputCollections", - "Name of the tracker hit input collections", - _colNamesTrackerHits, - trackerHitsInputColNamesDefault); - - - _n_run = 0 ; - _n_evt = 0 ; - - - - - + + trackerHitsInputColNamesDefault.push_back("VXDTrackerHits"); + trackerHitsInputColNamesDefault.push_back("SITTrackerHits"); + trackerHitsInputColNamesDefault.push_back("FTDPixelTrackerHits"); + trackerHitsInputColNamesDefault.push_back("FTDSpacePointRelations"); + trackerHitsInputColNamesDefault.push_back("TPCTrackerHits"); + trackerHitsInputColNamesDefault.push_back("SETTrackerHits"); + + registerInputCollections("TrackerHit", "TrackerHitsInputCollections", "Name of the tracker hit input collections", + _colNamesTrackerHits, trackerHitsInputColNamesDefault); + + _n_run = 0; + _n_evt = 0; } +void SetTrackerHitExtensions::init() { -void SetTrackerHitExtensions::init() { - - streamlog_out(DEBUG) << " init called " - << std::endl ; + streamlog_out(DEBUG) << " init called " << std::endl; _encoder = new UTIL::BitField64(lcio::LCTrackerCellID::encoding_string()); // usually a good idea to - printParameters() ; - + printParameters(); } -void SetTrackerHitExtensions::processRunHeader( LCRunHeader* ) { - - ++_n_run ; -} - -void SetTrackerHitExtensions::processEvent( LCEvent * evt ) { - - - - streamlog_out(DEBUG3) << " processing event: " << _n_evt << std::endl ; - +void SetTrackerHitExtensions::processRunHeader(LCRunHeader*) { ++_n_run; } + +void SetTrackerHitExtensions::processEvent(LCEvent* evt) { + + streamlog_out(DEBUG3) << " processing event: " << _n_evt << std::endl; + _current_evt_number = evt->getEventNumber(); - - + _colTrackerHits.clear(); _navTrackerHitRel.clear(); - + /**********************************************************************************************/ /* Prepare the collections */ /**********************************************************************************************/ - + // get the input collections and fill the vectors - this->SetupInputCollections(evt) ; - + this->SetupInputCollections(evt); + // create the encoder to decode cellID0 - UTIL::BitField64 cellID_encoder( LCTrackerCellID::encoding_string() ) ; - - - + UTIL::BitField64 cellID_encoder(LCTrackerCellID::encoding_string()); + + for (unsigned iCol = 0; iCol < _colTrackerHits.size(); iCol++) { - for( unsigned iCol=0; iCol<_colTrackerHits.size(); iCol++){ - LCCollection* trackerHitCol = _colTrackerHits[iCol]; int nHits = trackerHitCol->getNumberOfElements(); - + LCRelationNavigator* nav = _navTrackerHitRel[iCol]; - - for( int j=0; jgetElementAt( j ) == 0 ) { - streamlog_out( DEBUG0 ) << "Pointer to TrackerHit" << j << " is NULL " << std::endl; + + for (int j = 0; j < nHits; j++) { + + if (trackerHitCol->getElementAt(j) == 0) { + streamlog_out(DEBUG0) << "Pointer to TrackerHit" << j << " is NULL " << std::endl; } - - TrackerHit * trkhit = dynamic_cast( trackerHitCol->getElementAt( j )); - - if ( trkhit == 0 ) { - - std::stringstream errorMsg; - errorMsg << "dynamic_cast to TrackerHit for hit " << j << " failed. Pointer = " << trackerHitCol->getElementAt( j ) << std::endl; - + + TrackerHit* trkhit = dynamic_cast(trackerHitCol->getElementAt(j)); + + if (trkhit == 0) { + + std::stringstream errorMsg; + errorMsg << "dynamic_cast to TrackerHit for hit " << j + << " failed. Pointer = " << trackerHitCol->getElementAt(j) << std::endl; + throw lcio::Exception(errorMsg.str()); - } - - const LCObjectVec& to = nav->getRelatedToObjects( trkhit ); - - if( BitSet32( trkhit->getType() )[ UTIL::ILDTrkHitTypeBit::COMPOSITE_SPACEPOINT ] ){ //it is a composite spacepoint - - if( to.size() == 2 ){ - + + const LCObjectVec& to = nav->getRelatedToObjects(trkhit); + + if (BitSet32(trkhit->getType())[UTIL::ILDTrkHitTypeBit::COMPOSITE_SPACEPOINT]) { // it is a composite spacepoint + + if (to.size() == 2) { + #ifdef MARLINTRK_DIAGNOSTICS_ON SimTrackerHit* simhitA = dynamic_cast(to.at(0)); SimTrackerHit* simhitB = dynamic_cast(to.at(1)); - + // set the pointer to the simhit via lcio extention MCTruth4HitExt - + const LCObjectVec rawObjects = trkhit->getRawHits(); - - for( unsigned k=0; k< rawObjects.size(); k++ ){ - - TrackerHit* rawHit = dynamic_cast< TrackerHit* >( rawObjects[k] ); - if( rawHit ){ - - if( rawHit->getCellID0() == simhitA->getCellID0() ) { - streamlog_out( DEBUG4 ) << "link simhit = " << simhitA << " Cell ID = " << simhitA->getCellID0() << " with trkhit = " << rawHit << " Cell ID = " << rawHit->getCellID0() << std::endl; - rawHit->ext() = new MarlinTrk::MCTruth4HitExtStruct; - rawHit->ext()->simhit = simhitA; + + for (unsigned k = 0; k < rawObjects.size(); k++) { + + TrackerHit* rawHit = dynamic_cast(rawObjects[k]); + if (rawHit) { + + if (rawHit->getCellID0() == simhitA->getCellID0()) { + streamlog_out(DEBUG4) << "link simhit = " << simhitA << " Cell ID = " << simhitA->getCellID0() + << " with trkhit = " << rawHit << " Cell ID = " << rawHit->getCellID0() + << std::endl; + rawHit->ext() = new MarlinTrk::MCTruth4HitExtStruct; + rawHit->ext()->simhit = simhitA; } - if( rawHit->getCellID0() == simhitB->getCellID0() ) { - streamlog_out( DEBUG4 ) << "link simhit = " << simhitB << " Cell ID = " << simhitB->getCellID0() << " with trkhit = " << rawHit << " Cell ID = " << rawHit->getCellID0() << std::endl; - rawHit->ext() = new MarlinTrk::MCTruth4HitExtStruct; - rawHit->ext()->simhit = simhitB; + if (rawHit->getCellID0() == simhitB->getCellID0()) { + streamlog_out(DEBUG4) << "link simhit = " << simhitB << " Cell ID = " << simhitB->getCellID0() + << " with trkhit = " << rawHit << " Cell ID = " << rawHit->getCellID0() + << std::endl; + rawHit->ext() = new MarlinTrk::MCTruth4HitExtStruct; + rawHit->ext()->simhit = simhitB; } - - } - } -#endif - - - - } - else{ streamlog_out( DEBUG1 ) << "spacepoint discarded, because it is related to " << to.size() << "SimTrackerHits. It should be 2!\n"; } - - } - else{ // no composite spacepoint - - if( to.size() == 1){ // only take trackerHits, that have only one related SimHit - + } + } +#endif + + } else { + streamlog_out(DEBUG1) << "spacepoint discarded, because it is related to " << to.size() + << "SimTrackerHits. It should be 2!\n"; + } + + } else { // no composite spacepoint + + if (to.size() == 1) { // only take trackerHits, that have only one related SimHit + #ifdef MARLINTRK_DIAGNOSTICS_ON SimTrackerHit* simhit = dynamic_cast(to.at(0)); - - trkhit->ext() = new MarlinTrk::MCTruth4HitExtStruct; - trkhit->ext()->simhit = simhit; - - streamlog_out( DEBUG4 ) << "link simhit = " << simhit << " Cell ID = " << simhit->getCellID0() << " with trkhit = " << trkhit << " Cell ID = " << trkhit->getCellID0() << std::endl; -#endif + trkhit->ext() = new MarlinTrk::MCTruth4HitExtStruct; + trkhit->ext()->simhit = simhit; + + streamlog_out(DEBUG4) << "link simhit = " << simhit << " Cell ID = " << simhit->getCellID0() + << " with trkhit = " << trkhit << " Cell ID = " << trkhit->getCellID0() << std::endl; + +#endif + } else { + streamlog_out(DEBUG1) << "TrackerHit discarded, because it is related to " << to.size() + << "SimTrackerHits. It should be 1!\n"; } - else{ streamlog_out( DEBUG1 ) << "TrackerHit discarded, because it is related to " << to.size() << "SimTrackerHits. It should be 1!\n"; } - } - - } - } - - ++_n_evt ; - -} - + ++_n_evt; +} -void SetTrackerHitExtensions::check( LCEvent* ) { +void SetTrackerHitExtensions::check(LCEvent*) { // nothing to check here - could be used to fill checkplots in reconstruction processor } +void SetTrackerHitExtensions::end() { -void SetTrackerHitExtensions::end() { - - streamlog_out(DEBUG4) << "SetTrackerHitExtensions::end() " << name() - << " processed " << _n_evt << " events in " << _n_run << " runs " - << std::endl ; - - delete _encoder ; - -} + streamlog_out(DEBUG4) << "SetTrackerHitExtensions::end() " << name() << " processed " << _n_evt << " events in " + << _n_run << " runs " << std::endl; + delete _encoder; +} +void SetTrackerHitExtensions::SetupInputCollections(LCEvent* evt) { -void SetTrackerHitExtensions::SetupInputCollections( LCEvent * evt ) { - - - // Check if there are as many tracker hit input collections as relation collections - if( _colNamesTrackerHits.size() != _colNamesTrackerHitRelations.size() ){ - - streamlog_out( ERROR ) << "There must be as many input collections of tracker Hits as of relations. At the moment, there are " - << _colNamesTrackerHits.size() << " tracker hit collections and " << _colNamesTrackerHitRelations.size() << " relation collections passed as steering paremeters!\n"; - + if (_colNamesTrackerHits.size() != _colNamesTrackerHitRelations.size()) { + + streamlog_out(ERROR) + << "There must be as many input collections of tracker Hits as of relations. At the moment, there are " + << _colNamesTrackerHits.size() << " tracker hit collections and " << _colNamesTrackerHitRelations.size() + << " relation collections passed as steering paremeters!\n"; + exit(1); } - - for( unsigned i=0; i< _colNamesTrackerHits.size(); i++ ){ - - + + for (unsigned i = 0; i < _colNamesTrackerHits.size(); i++) { + // the tracker hits - LCCollection* colTrkHits = GetCollection( evt, _colNamesTrackerHits[i] ); - if( colTrkHits == NULL ) continue; - + LCCollection* colTrkHits = GetCollection(evt, _colNamesTrackerHits[i]); + if (colTrkHits == NULL) + continue; + // the relations of them - LCRelationNavigator* nav = GetRelations( evt, _colNamesTrackerHitRelations[i] ); - if( nav == NULL ) continue; - - - _colTrackerHits.push_back( colTrkHits ); - _navTrackerHitRel.push_back( nav ); - - + LCRelationNavigator* nav = GetRelations(evt, _colNamesTrackerHitRelations[i]); + if (nav == NULL) + continue; + + _colTrackerHits.push_back(colTrkHits); + _navTrackerHitRel.push_back(nav); } - - } +LCCollection* SetTrackerHitExtensions::GetCollection(LCEvent* evt, std::string colName) { -LCCollection* SetTrackerHitExtensions::GetCollection( LCEvent * evt, std::string colName ){ - LCCollection* col = NULL; - + try { - col = evt->getCollection( colName.c_str() ) ; - streamlog_out( DEBUG4 ) << " --> " << colName.c_str() << " collection found, number of elements = " << col->getNumberOfElements() << std::endl; + col = evt->getCollection(colName.c_str()); + streamlog_out(DEBUG4) << " --> " << colName.c_str() + << " collection found, number of elements = " << col->getNumberOfElements() << std::endl; + } catch (DataNotAvailableException& e) { + streamlog_out(DEBUG4) << " --> " << colName.c_str() << " collection absent" << std::endl; } - catch(DataNotAvailableException &e) { - streamlog_out( DEBUG4 ) << " --> " << colName.c_str() << " collection absent" << std::endl; - } - - return col; - -} -LCRelationNavigator* SetTrackerHitExtensions::GetRelations(LCEvent * evt , std::string RelName ) { - - LCRelationNavigator* nav = NULL ; - LCCollection* col = NULL; - - try{ - - col = evt->getCollection( RelName.c_str() ); - nav = new LCRelationNavigator( col ); - streamlog_out( DEBUG4 ) << " --> " << RelName << " track relation collection found, number of elements = " << col->getNumberOfElements() << std::endl; - } - catch(DataNotAvailableException &e){ - streamlog_out( ERROR ) << " --> " << RelName.c_str() << " track relation collection absent" << std::endl; - } - - return nav; - + return col; } +LCRelationNavigator* SetTrackerHitExtensions::GetRelations(LCEvent* evt, std::string RelName) { + LCRelationNavigator* nav = NULL; + LCCollection* col = NULL; + try { + col = evt->getCollection(RelName.c_str()); + nav = new LCRelationNavigator(col); + streamlog_out(DEBUG4) << " --> " << RelName + << " track relation collection found, number of elements = " << col->getNumberOfElements() + << std::endl; + } catch (DataNotAvailableException& e) { + streamlog_out(ERROR) << " --> " << RelName.c_str() << " track relation collection absent" << std::endl; + } - - + return nav; +} diff --git a/source/Utils/src/SplitCollectionByLayer.cc b/source/Utils/src/SplitCollectionByLayer.cc index cb9ce87..16d8dce 100644 --- a/source/Utils/src/SplitCollectionByLayer.cc +++ b/source/Utils/src/SplitCollectionByLayer.cc @@ -1,238 +1,200 @@ #include "SplitCollectionByLayer.h" -#include #include +#include -#include +#include +#include #include #include -#include -#include +#include #include // #include "UTIL/LCTrackerConf.h" // #include +using namespace lcio; +using namespace marlin; -using namespace lcio ; -using namespace marlin ; - - -SplitCollectionByLayer aSplitCollectionByLayer ; +SplitCollectionByLayer aSplitCollectionByLayer; +SplitCollectionByLayer::SplitCollectionByLayer() : Processor("SplitCollectionByLayer"), _nRun(0), _nEvt(0) { - -SplitCollectionByLayer::SplitCollectionByLayer() : Processor("SplitCollectionByLayer") , - _nRun(0), _nEvt(0) { - // modify processor description - _description = "split a hit collection based on the layer number of the hits " ; - - + _description = "split a hit collection based on the layer number of the hits "; + // register steering parameters: name, description, class-variable, default value - registerProcessorParameter("InputCollection" , - "Name of the input collection with hits" , - _colName , - std::string("FTDCollection") - ); - - StringVec outColEx ; - outColEx.push_back("FTD_PIXELCollection") ; - outColEx.push_back("0") ; - outColEx.push_back("1") ; - outColEx.push_back("FTD_STRIPCollection") ; - outColEx.push_back("2") ; - outColEx.push_back("6") ; - - registerProcessorParameter("OutputCollections" , - "Name of the output collection with start and end layer number" , - _outColAndLayers , - outColEx - ); - - + registerProcessorParameter("InputCollection", "Name of the input collection with hits", _colName, + std::string("FTDCollection")); + + StringVec outColEx; + outColEx.push_back("FTD_PIXELCollection"); + outColEx.push_back("0"); + outColEx.push_back("1"); + outColEx.push_back("FTD_STRIPCollection"); + outColEx.push_back("2"); + outColEx.push_back("6"); + + registerProcessorParameter("OutputCollections", "Name of the output collection with start and end layer number", + _outColAndLayers, outColEx); } - template -long cellIDFromHit( const LCObject* o){ - long id = -1 ; - const T* h = dynamic_cast( o ) ; - if( h ) id = ( h->getCellID0() & 0xffffffff ) | ( ( long(h->getCellID1()) << 32 ) & 0xffffffff00000000 ) ; - return id ; +long cellIDFromHit(const LCObject* o) { + long id = -1; + const T* h = dynamic_cast(o); + if (h) + id = (h->getCellID0() & 0xffffffff) | ((long(h->getCellID1()) << 32) & 0xffffffff00000000); + return id; } +void SplitCollectionByLayer::init() { + streamlog_out(DEBUG) << " init called " << std::endl; -void SplitCollectionByLayer::init() { - - streamlog_out(DEBUG) << " init called " << std::endl ; - // usually a good idea to - printParameters() ; - - - _outCols.resize( _outColAndLayers.size() / 3 ) ; - - unsigned i=0,index=0 ; - while( i < _outColAndLayers.size() ){ - - _outCols[index].name = _outColAndLayers[ i++ ] ; - _outCols[index].layer0 = std::atoi( _outColAndLayers[ i++ ].c_str() ) ; - _outCols[index].layer1 = std::atoi( _outColAndLayers[ i++ ].c_str() ) ; - _outCols[index].collection = 0 ; - - ++index ; - } + printParameters(); - _nRun = 0 ; - _nEvt = 0 ; - -} + _outCols.resize(_outColAndLayers.size() / 3); + unsigned i = 0, index = 0; + while (i < _outColAndLayers.size()) { -void SplitCollectionByLayer::processRunHeader( LCRunHeader* ) { - - _nRun++ ; -} + _outCols[index].name = _outColAndLayers[i++]; + _outCols[index].layer0 = std::atoi(_outColAndLayers[i++].c_str()); + _outCols[index].layer1 = std::atoi(_outColAndLayers[i++].c_str()); + _outCols[index].collection = 0; + ++index; + } + _nRun = 0; + _nEvt = 0; +} +void SplitCollectionByLayer::processRunHeader(LCRunHeader*) { _nRun++; } -void SplitCollectionByLayer::processEvent( LCEvent * evt ) { +void SplitCollectionByLayer::processEvent(LCEvent* evt) { + LCCollection* col = 0; - LCCollection* col = 0 ; + try { + col = evt->getCollection(_colName); - try{ col = evt->getCollection( _colName ) ; + } catch (lcio::DataNotAvailableException& e) { + + streamlog_out(DEBUG5) << " input collection not in event : " << _colName << " - nothing to do !!! " + << std::endl; + return; + } - } catch( lcio::DataNotAvailableException& e) { - - streamlog_out( DEBUG5 ) << " input collection not in event : " << _colName << " - nothing to do !!! " << std::endl ; - return ; - } - // remember the type of the hit collection - if( col->getTypeName() == lcio::LCIO::SIMTRACKERHIT ) - _type = SimTrackerHitType ; - else if( col->getTypeName() == lcio::LCIO::TRACKERHIT ) - _type = TrackerHitType ; - else if( col->getTypeName() == lcio::LCIO::SIMCALORIMETERHIT ) - _type = SimCalorimeterHitType ; - else if( col->getTypeName() == lcio::LCIO::CALORIMETERHIT ) - _type = CalorimeterHitType ; - else - _type = UnkownType ; - - - std::string encoderString = col->getParameters().getStringVal( "CellIDEncoding" ) ; + if (col->getTypeName() == lcio::LCIO::SIMTRACKERHIT) + _type = SimTrackerHitType; + else if (col->getTypeName() == lcio::LCIO::TRACKERHIT) + _type = TrackerHitType; + else if (col->getTypeName() == lcio::LCIO::SIMCALORIMETERHIT) + _type = SimCalorimeterHitType; + else if (col->getTypeName() == lcio::LCIO::CALORIMETERHIT) + _type = CalorimeterHitType; + else + _type = UnkownType; - UTIL::BitField64 encoder( encoderString ) ; + std::string encoderString = col->getParameters().getStringVal("CellIDEncoding"); - unsigned layerIndex = encoder.index("layer") ; + UTIL::BitField64 encoder(encoderString); + unsigned layerIndex = encoder.index("layer"); //---- create output collections - for(unsigned i=0, N= _outCols.size() ; igetTypeName() ) ; + for (unsigned i = 0, N = _outCols.size(); i < N; ++i) { - newCol->setSubset( true ) ; + LCCollectionVec* newCol = new LCCollectionVec(col->getTypeName()); - newCol->parameters().setValue( "CellIDEncoding", encoderString ) ; + newCol->setSubset(true); - // evt->addCollection( newCol , _outCols[i].name ) ; + newCol->parameters().setValue("CellIDEncoding", encoderString); - _outCols[i].collection = newCol ; + // evt->addCollection( newCol , _outCols[i].name ) ; - streamlog_out( DEBUG5 ) << " create new output collection " << _outCols[i].name << " of type " << col->getTypeName() << std::endl ; - streamlog_out( DEBUG5 ) << " create new output collection " << _outCols[i].name << " of type " << col->getTypeName() << " to the event " << std::endl ; - } + _outCols[i].collection = newCol; + streamlog_out(DEBUG5) << " create new output collection " << _outCols[i].name << " of type " << col->getTypeName() + << std::endl; + streamlog_out(DEBUG5) << " create new output collection " << _outCols[i].name << " of type " << col->getTypeName() + << " to the event " << std::endl; + } //---- loop over hits - int nHit = col->getNumberOfElements() ; - - for(int iHit=0; iHit< nHit ; iHit++){ - - lcio::LCObject* h = col->getElementAt( iHit ) ; - - long id = -1 ; - - switch( _type ){ - - case SimTrackerHitType: - id = cellIDFromHit( h ) ; - break ; - case TrackerHitType: - id = cellIDFromHit( h ) ; - break ; - case SimCalorimeterHitType: - id = cellIDFromHit( h ) ; - break ; - case CalorimeterHitType: - id = cellIDFromHit( h ) ; - break ; - case UnkownType: - continue ; - } - - encoder.setValue( id ) ; + int nHit = col->getNumberOfElements(); - unsigned int layerID = encoder[ layerIndex ] ; + for (int iHit = 0; iHit < nHit; iHit++) { + lcio::LCObject* h = col->getElementAt(iHit); - // check if we have an output collection for this layer - for(int i=0, N=_outCols.size() ; iaddElement( h ) ; + long id = -1; - streamlog_out( DEBUG0 ) << " adding hit for layer " << layerID << " to collection : " << _outCols[i].name << std::endl ; + switch (_type) { - } + case SimTrackerHitType: + id = cellIDFromHit(h); + break; + case TrackerHitType: + id = cellIDFromHit(h); + break; + case SimCalorimeterHitType: + id = cellIDFromHit(h); + break; + case CalorimeterHitType: + id = cellIDFromHit(h); + break; + case UnkownType: + continue; } - } + encoder.setValue(id); - // add non empty collections to the event - for(unsigned i=0, N= _outCols.size() ; igetNumberOfElements() > 0 ) { + if ((_outCols[i].layer0 <= layerID) && (layerID <= _outCols[i].layer1)) { - evt->addCollection( newCol , _outCols[i].name ) ; + _outCols[i].collection->addElement(h); - streamlog_out( DEBUG5 ) << " output collection " << _outCols[i].name << " of type " << col->getTypeName() << " added to the event " << std::endl ; + streamlog_out(DEBUG0) << " adding hit for layer " << layerID << " to collection : " << _outCols[i].name + << std::endl; + } } } + // add non empty collections to the event + for (unsigned i = 0, N = _outCols.size(); i < N; ++i) { + LCCollection* newCol = _outCols[i].collection; + if (newCol->getNumberOfElements() > 0) { + evt->addCollection(newCol, _outCols[i].name); - streamlog_out( DEBUG3 ) << " processing event: " << evt->getEventNumber() - << " in run: " << evt->getRunNumber() << std::endl ; + streamlog_out(DEBUG5) << " output collection " << _outCols[i].name << " of type " << col->getTypeName() + << " added to the event " << std::endl; + } + } + streamlog_out(DEBUG3) << " processing event: " << evt->getEventNumber() << " in run: " << evt->getRunNumber() + << std::endl; - _nEvt ++ ; + _nEvt++; } - - -void SplitCollectionByLayer::check( LCEvent* ) { +void SplitCollectionByLayer::check(LCEvent*) { // nothing to check here - could be used to fill checkplots in reconstruction processor } +void SplitCollectionByLayer::end() { -void SplitCollectionByLayer::end(){ - - streamlog_out( MESSAGE ) << "SplitCollectionByLayer::end() " << name() - << " processed " << _nEvt << " events in " << _nRun << " runs " - << std::endl ; - + streamlog_out(MESSAGE) << "SplitCollectionByLayer::end() " << name() << " processed " << _nEvt << " events in " + << _nRun << " runs " << std::endl; } - -